Dax Raad 9 months ago
parent
commit
5c491758f5
3 changed files with 9 additions and 9 deletions
  1. 2 1
      js/src/index.ts
  2. 6 7
      js/src/share/share.ts
  3. 1 1
      js/src/util/log.ts

+ 2 - 1
js/src/index.ts

@@ -40,7 +40,8 @@ cli
       await Share.init();
       await Share.init();
       const session = await Session.create();
       const session = await Session.create();
       const shareID = await Session.share(session.id);
       const shareID = await Session.share(session.id);
-      if (shareID) console.log("Share ID:", shareID);
+      if (shareID)
+        console.log("Share ID: https://dev.opencode.ai/share/" + shareID);
       const result = await Session.chat(session.id, {
       const result = await Session.chat(session.id, {
         type: "text",
         type: "text",
         text: message.join(" "),
         text: message.join(" "),

+ 6 - 7
js/src/share/share.ts

@@ -2,8 +2,11 @@ import { App } from "../app";
 import { Bus } from "../bus";
 import { Bus } from "../bus";
 import { Session } from "../session/session";
 import { Session } from "../session/session";
 import { Storage } from "../storage/storage";
 import { Storage } from "../storage/storage";
+import { Log } from "../util/log";
 
 
 export namespace Share {
 export namespace Share {
+  const log = Log.create({ service: "share" });
+
   const state = App.state("share", async () => {
   const state = App.state("share", async () => {
     Bus.subscribe(Storage.Event.Write, async (payload) => {
     Bus.subscribe(Storage.Event.Write, async (payload) => {
       const [root, ...splits] = payload.properties.key.split("/");
       const [root, ...splits] = payload.properties.key.split("/");
@@ -11,12 +14,6 @@ export namespace Share {
       const [type, sessionID] = splits;
       const [type, sessionID] = splits;
       const session = await Session.get(sessionID);
       const session = await Session.get(sessionID);
       if (!session.shareID) return;
       if (!session.shareID) return;
-      console.log({
-        sessionID: sessionID,
-        shareID: session.shareID,
-        key: payload.properties.key,
-        content: payload.properties.content,
-      });
       await fetch(`${URL}/share_sync`, {
       await fetch(`${URL}/share_sync`, {
         method: "POST",
         method: "POST",
         body: JSON.stringify({
         body: JSON.stringify({
@@ -25,7 +22,9 @@ export namespace Share {
           key: payload.properties.key,
           key: payload.properties.key,
           content: payload.properties.content,
           content: payload.properties.content,
         }),
         }),
-      }).then(console.log);
+      })
+        .then((x) => x.text())
+        .then(console.log);
     });
     });
   });
   });
 
 

+ 1 - 1
js/src/util/log.ts

@@ -39,7 +39,7 @@ export namespace Log {
       })
       })
         .map(([key, value]) => `${key}=${value}`)
         .map(([key, value]) => `${key}=${value}`)
         .join(" ");
         .join(" ");
-      return [prefix, message].join(" ") + "\n";
+      return [new Date().toISOString(), prefix, message].join(" ") + "\n";
     }
     }
     const result = {
     const result = {
       info(message?: any, extra?: Record<string, any>) {
       info(message?: any, extra?: Record<string, any>) {