Преглед изворни кода

fix: resolve compiled binary crashes from circular dep and Bun CJS splitting bug

LukeParkerDev пре 3 месеци
родитељ
комит
2b3d027e3b

+ 3 - 1
packages/opencode/src/cli/cmd/serve.ts

@@ -13,7 +13,8 @@ import { Installation } from "../../installation"
 import { PushRelay } from "../../server/push-relay"
 import { Log } from "../../util"
 import { Global } from "../../global"
-import * as QRCode from "qrcode"
+// dynamic import: static `import * as` of CJS package triggers Bun bundler splitting bug
+import type * as QRCodeType from "qrcode"
 
 const log = Log.create({ service: "serve" })
 
@@ -184,6 +185,7 @@ async function printPairQR(pair: PairPayload) {
     linkLength: link.length,
     qr: qrConfig,
   })
+  const QRCode: typeof QRCodeType = await import("qrcode")
   const code = await QRCode.toString(link, {
     ...qrConfig,
   })

+ 3 - 1
packages/opencode/src/server/routes/instance/experimental.ts

@@ -17,7 +17,8 @@ import { errors } from "../../error"
 import { lazy } from "@/util/lazy"
 import { Effect, Option } from "effect"
 import { PushRelay } from "../../push-relay"
-import * as QRCode from "qrcode"
+// dynamic import: static `import * as` of CJS package triggers Bun bundler splitting bug
+import type * as QRCodeType from "qrcode"
 import { Agent } from "@/agent/agent"
 import { jsonRequest, runRequest } from "./trace"
 
@@ -60,6 +61,7 @@ function pushPairLink(input: { relaySecret: string; hosts: string[] }) {
 }
 
 async function pushPairQRCode(input: { relaySecret: string; hosts: string[] }) {
+  const QRCode: typeof QRCodeType = await import("qrcode")
   return QRCode.toDataURL(pushPairLink(input), pushPairQROptions)
 }
 

+ 2 - 1
packages/opencode/src/session/session.ts

@@ -246,7 +246,8 @@ export const Event = {
     "session.error",
     z.object({
       sessionID: SessionID.zod.optional(),
-      error: MessageV2.Assistant.shape.error,
+      // z.lazy defers access to break circular dep: session → message-v2 → provider → plugin → session
+      error: z.lazy(() => MessageV2.Assistant.shape.error),
     }),
   ),
 }