Răsfoiți Sursa

Fixed ACP to respect user's default model config. (#4006)

Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: rekram1-node <[email protected]>
Co-authored-by: GitHub Action <[email protected]>
Co-authored-by: Aiden Cline <[email protected]>
opencode-agent[bot] 3 luni în urmă
părinte
comite
9f603e39a6
2 a modificat fișierele cu 31 adăugiri și 10 ștergeri
  1. 29 9
      packages/opencode/src/acp/agent.ts
  2. 2 1
      packages/opencode/src/cli/cmd/acp.ts

+ 29 - 9
packages/opencode/src/acp/agent.ts

@@ -32,7 +32,7 @@ import { Command } from "@/command"
 import { Agent as Agents } from "@/agent/agent"
 import { Permission } from "@/permission"
 import { SessionCompaction } from "@/session/compaction"
-import type { Config } from "@/config/config"
+import { Config } from "@/config/config"
 import { MCP } from "@/mcp"
 import { Todo } from "@/session/todo"
 import { z } from "zod"
@@ -41,6 +41,18 @@ import { LoadAPIKeyError } from "ai"
 export namespace ACP {
   const log = Log.create({ service: "acp-agent" })
 
+  export async function init() {
+    const model = await defaultModel({})
+    return {
+      create: (connection: AgentSideConnection, config: ACPConfig) => {
+        if (!config.defaultModel) {
+          config.defaultModel = model
+        }
+        return new Agent(connection, config)
+      },
+    }
+  }
+
   export class Agent implements ACPAgent {
     private sessionManager = new ACPSessionManager()
     private connection: AgentSideConnection
@@ -48,13 +60,6 @@ export namespace ACP {
 
     constructor(connection: AgentSideConnection, config: ACPConfig = {}) {
       this.connection = connection
-      if (!config.defaultModel) {
-        // default to big pickle
-        config.defaultModel = {
-          providerID: "opencode",
-          modelID: "big-pickle",
-        }
-      }
       this.config = config
       this.setupEventSubscriptions()
     }
@@ -685,7 +690,22 @@ export namespace ACP {
   async function defaultModel(config: ACPConfig) {
     const configured = config.defaultModel
     if (configured) return configured
-    return Provider.defaultModel()
+
+    const model = await Config.get()
+      .then((cfg) => {
+        if (!cfg.model) return undefined
+        const parsed = Provider.parseModel(cfg.model)
+        return {
+          providerID: parsed.providerID,
+          modelID: parsed.modelID,
+        }
+      })
+      .catch((error) => {
+        log.error("failed to load user config for default model", { error })
+        return undefined
+      })
+
+    return model ?? { providerID: "opencode", modelID: "big-pickle" }
   }
 
   function parseUri(

+ 2 - 1
packages/opencode/src/cli/cmd/acp.ts

@@ -50,9 +50,10 @@ export const AcpCommand = cmd({
       })
 
       const stream = ndJsonStream(input, output)
+      const agent = await ACP.init()
 
       new AgentSideConnection((conn) => {
-        return new ACP.Agent(conn)
+        return agent.create(conn, {})
       }, stream)
 
       log.info("setup connection")