Просмотр исходного кода

fix: model not being passed correctly to tool

Aiden Cline 2 месяцев назад
Родитель
Сommit
350a32274a
2 измененных файлов с 5 добавлено и 10 удалено
  1. 3 2
      packages/opencode/src/session/prompt.ts
  2. 2 8
      packages/opencode/src/tool/read.ts

+ 3 - 2
packages/opencode/src/session/prompt.ts

@@ -690,7 +690,7 @@ export namespace SessionPrompt {
             abort: options.abortSignal!,
             messageID: input.processor.message.id,
             callID: options.toolCallId,
-            extra: input.model,
+            extra: { model: input.model },
             agent: input.agent.name,
             metadata: async (val) => {
               const match = input.processor.partFromToolCall(options.toolCallId)
@@ -907,12 +907,13 @@ export namespace SessionPrompt {
 
                 await ReadTool.init()
                   .then(async (t) => {
+                    const model = await Provider.getModel(info.model.providerID, info.model.modelID)
                     const result = await t.execute(args, {
                       sessionID: input.sessionID,
                       abort: new AbortController().signal,
                       agent: input.agent!,
                       messageID: info.id,
-                      extra: { bypassCwdCheck: true, ...info.model },
+                      extra: { bypassCwdCheck: true, model },
                       metadata: async () => {},
                     })
                     pieces.push({

+ 2 - 8
packages/opencode/src/tool/read.ts

@@ -95,14 +95,8 @@ export const ReadTool = Tool.define("read", {
     }
 
     const isImage = isImageFile(filepath)
-    const supportsImages = await (async () => {
-      if (!ctx.extra?.["providerID"] || !ctx.extra?.["modelID"]) return false
-      const providerID = ctx.extra["providerID"] as string
-      const modelID = ctx.extra["modelID"] as string
-      const model = await Provider.getModel(providerID, modelID).catch(() => undefined)
-      if (!model) return false
-      return model.capabilities.input.image
-    })()
+    const model = ctx.extra?.model as Provider.Model | undefined
+    const supportsImages = model?.capabilities.input.image ?? false
     if (isImage) {
       if (!supportsImages) {
         throw new Error(`Failed to read image: ${filepath}, model may not be able to read images`)