mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-24 19:24:22 +01:00
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 <rekram1-node@users.noreply.github.com> Co-authored-by: GitHub Action <action@github.com> Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
This commit is contained in:
committed by
GitHub
parent
da51c9dfac
commit
9f603e39a6
@@ -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(
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user