summaryrefslogtreecommitdiffhomepage
path: root/js/src
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-05-26 23:04:40 -0400
committerDax Raad <[email protected]>2025-05-26 23:04:40 -0400
commit754cc667411cc1d652acd0a811c530dcc35f5927 (patch)
tree16e6d36d78e6d4ad96438fb95fae68adf2d6ec1a /js/src
parent6ef0b991ecf8031ada69db02ad5be4b585f66bea (diff)
downloadopencode-754cc667411cc1d652acd0a811c530dcc35f5927.tar.gz
opencode-754cc667411cc1d652acd0a811c530dcc35f5927.zip
Add automatic CONTEXT.md loading and improve share sync reliability
🤖 Generated with opencode Co-Authored-By: opencode <[email protected]>
Diffstat (limited to 'js/src')
-rw-r--r--js/src/session/session.ts9
-rw-r--r--js/src/share/share.ts30
2 files changed, 29 insertions, 10 deletions
diff --git a/js/src/session/session.ts b/js/src/session/session.ts
index d911270a7..cbe6cd89c 100644
--- a/js/src/session/session.ts
+++ b/js/src/session/session.ts
@@ -141,6 +141,7 @@ export namespace Session {
msg,
);
}
+ const app = await App.use();
if (msgs.length === 0) {
const system: Message = {
id: Identifier.ascending("message"),
@@ -159,6 +160,14 @@ export namespace Session {
tool: {},
},
};
+ const contextFile = Bun.file(path.join(app.root, "CONTEXT.md"));
+ if (await contextFile.exists()) {
+ const context = await contextFile.text();
+ system.parts.push({
+ type: "text",
+ text: context,
+ });
+ }
msgs.push(system);
state().messages.set(sessionID, msgs);
generateText({
diff --git a/js/src/share/share.ts b/js/src/share/share.ts
index a9b5ed8fd..db204ab97 100644
--- a/js/src/share/share.ts
+++ b/js/src/share/share.ts
@@ -8,6 +8,7 @@ export namespace Share {
const log = Log.create({ service: "share" });
let queue: Promise<void> = Promise.resolve();
+ const pending = new Map<string, any>();
const state = App.state("share", async () => {
Bus.subscribe(Storage.Event.Write, async (payload) => {
@@ -17,23 +18,32 @@ export namespace Share {
const session = await Session.get(sessionID);
if (!session.shareID) return;
+ const key = payload.properties.key;
+ pending.set(key, payload.properties.content);
+
queue = queue
- .then(() =>
- fetch(`${URL}/share_sync`, {
+ .then(async () => {
+ const content = pending.get(key);
+ if (content === undefined) return;
+ pending.delete(key);
+
+ return fetch(`${URL}/share_sync`, {
method: "POST",
body: JSON.stringify({
sessionID: sessionID,
shareID: session.shareID,
- key: payload.properties.key,
- content: JSON.stringify(payload.properties.content),
+ key: key,
+ content: JSON.stringify(content),
}),
- }),
- )
- .then((x) => {
- log.info("synced", {
- key: payload.properties.key,
- status: x.status,
});
+ })
+ .then((x) => {
+ if (x) {
+ log.info("synced", {
+ key: key,
+ status: x.status,
+ });
+ }
});
});
});