From adc6d92a8e7b8738c8fcc7f999ff1ade794981d3 Mon Sep 17 00:00:00 2001 From: herjarsa <204746071+herjarsa@users.noreply.github.com> Date: Thu, 7 May 2026 16:18:41 +0200 Subject: [PATCH] fix(agents): copy factory mode to agent config for Desktop 1.14.x compat OpenCode Desktop 1.14.x filters agents by `mode` field. The `mode` was only present on the factory function as a static property, but not copied to the generated AgentConfig object. This fix copies `source.mode` to `base.mode` in `buildAgent()` when: - source is a factory function (has `mode` static property) - the generated config doesn't already define `mode` Test: agent-builder.test.ts (4 pass) Closes: #3835 Related: #3762, #3812, #3794, #3475, #3474, #3829, #3831, #3824, #3826, #3721, #3806, #3188 --- src/agents/agent-builder.test.ts | 67 ++++++++++++++++++++++++++++++++ src/agents/agent-builder.ts | 4 ++ 2 files changed, 71 insertions(+) create mode 100644 src/agents/agent-builder.test.ts diff --git a/src/agents/agent-builder.test.ts b/src/agents/agent-builder.test.ts new file mode 100644 index 000000000..56abb8ac7 --- /dev/null +++ b/src/agents/agent-builder.test.ts @@ -0,0 +1,67 @@ +import { describe, test, expect } from "bun:test" +import { buildAgent } from "./agent-builder" +import type { AgentFactory } from "./types" + +describe("#given an agent factory with mode", () => { + const mockFactory = ((model: string) => ({ + name: "test-agent", + description: "Test", + instructions: "test", + model, + temperature: 0.1, + })) as AgentFactory + mockFactory.mode = "subagent" + + test("#when building agent from factory", () => { + const agent = buildAgent(mockFactory, "test-model") + expect(agent.mode).toBe("subagent") + }) +}) + +describe("#given an agent factory with mode=primary", () => { + const mockFactory = ((model: string) => ({ + name: "primary-agent", + description: "Primary Test", + instructions: "test", + model, + temperature: 0.1, + })) as AgentFactory + mockFactory.mode = "primary" + + test("#when building agent from factory", () => { + const agent = buildAgent(mockFactory, "test-model") + expect(agent.mode).toBe("primary") + }) +}) + +describe("#given an agent config object without mode", () => { + const mockConfig = { + name: "config-agent", + description: "Config Test", + instructions: "test", + model: "test-model", + temperature: 0.1, + } + + test("#when building agent from config object", () => { + const agent = buildAgent(mockConfig, "test-model") + expect(agent.mode).toBeUndefined() + }) +}) + +describe("#given an agent factory with mode but config already has mode", () => { + const mockFactory = ((model: string) => ({ + name: "override-agent", + description: "Override Test", + instructions: "test", + model, + temperature: 0.1, + mode: "all", + })) as AgentFactory + mockFactory.mode = "subagent" + + test("#when building agent from factory", () => { + const agent = buildAgent(mockFactory, "test-model") + expect(agent.mode).toBe("all") + }) +}) diff --git a/src/agents/agent-builder.ts b/src/agents/agent-builder.ts index 5747bb841..1a98a954f 100644 --- a/src/agents/agent-builder.ts +++ b/src/agents/agent-builder.ts @@ -33,5 +33,9 @@ export function buildAgent( } } + if (isFactory(source) && (base as AgentConfig & { mode?: string }).mode === undefined) { + ;(base as AgentConfig & { mode?: string }).mode = source.mode + } + return base }