Browse Source

use new share url

Dax Raad 2 months ago
parent
commit
578072bb8e
2 changed files with 9 additions and 31 deletions
  1. 2 23
      packages/opencode/src/session/index.ts
  2. 7 8
      packages/opencode/src/share/share-next.ts

+ 2 - 23
packages/opencode/src/session/index.ts

@@ -223,34 +223,13 @@ export namespace Session {
     if (cfg.share === "disabled") {
       throw new Error("Sharing is disabled in configuration")
     }
-
-    if (cfg.enterprise?.url) {
-      const { ShareNext } = await import("@/share/share-next")
-      const share = await ShareNext.create(id)
-      await update(id, (draft) => {
-        draft.share = {
-          url: share.url,
-        }
-      })
-    }
-
-    const session = await get(id)
-    if (session.share) return session.share
-    const { Share } = await import("../share/share")
-    const share = await Share.create(id)
+    const { ShareNext } = await import("@/share/share-next")
+    const share = await ShareNext.create(id)
     await update(id, (draft) => {
       draft.share = {
         url: share.url,
       }
     })
-    await Storage.write(["share", id], share)
-    await Share.sync("session/info/" + id, session)
-    for (const msg of await messages({ sessionID: id })) {
-      await Share.sync("session/message/" + id + "/" + msg.info.id, msg.info)
-      for (const part of msg.parts) {
-        await Share.sync("session/part/" + id + "/" + msg.info.id + "/" + part.id, part)
-      }
-    }
     return share
   })
 

+ 7 - 8
packages/opencode/src/share/share-next.ts

@@ -11,9 +11,11 @@ import type * as SDK from "@opencode-ai/sdk/v2"
 export namespace ShareNext {
   const log = Log.create({ service: "share-next" })
 
+  async function url() {
+    return Config.get().then((x) => x.enterprise?.url ?? "https://opncd.ai")
+  }
+
   export async function init() {
-    const config = await Config.get()
-    if (!config.enterprise) return
     Bus.subscribe(Session.Event.Updated, async (evt) => {
       await sync(evt.properties.info.id, [
         {
@@ -62,8 +64,7 @@ export namespace ShareNext {
 
   export async function create(sessionID: string) {
     log.info("creating share", { sessionID })
-    const url = await Config.get().then((x) => x.enterprise!.url)
-    const result = await fetch(`${url}/api/share`, {
+    const result = await fetch(`${await url()}/api/share`, {
       method: "POST",
       headers: {
         "Content-Type": "application/json",
@@ -126,11 +127,10 @@ export namespace ShareNext {
       const queued = queue.get(sessionID)
       if (!queued) return
       queue.delete(sessionID)
-      const url = await Config.get().then((x) => x.enterprise!.url)
       const share = await get(sessionID)
       if (!share) return
 
-      await fetch(`${url}/api/share/${share.id}/sync`, {
+      await fetch(`${await url()}/api/share/${share.id}/sync`, {
         method: "POST",
         headers: {
           "Content-Type": "application/json",
@@ -146,10 +146,9 @@ export namespace ShareNext {
 
   export async function remove(sessionID: string) {
     log.info("removing share", { sessionID })
-    const url = await Config.get().then((x) => x.enterprise!.url)
     const share = await get(sessionID)
     if (!share) return
-    await fetch(`${url}/api/share/${share.id}`, {
+    await fetch(`${await url()}/api/share/${share.id}`, {
       method: "DELETE",
       headers: {
         "Content-Type": "application/json",