fix(headless): compose the one-shot agent from the preset roster again

The agent-default-model refactor moved the headless runner off the
api-proxy create path onto a direct agents.create, which silently dropped
the preset composition the stack had put on every dsh run session: the
header lost its agentPreset and the agent ran on the host composition
alone. Resolve the default preset up front (optional service — a roster-
less composition keeps the pre-preset behavior), record it on the header,
and mount it in setup where a broken composition still fails the run.
This commit is contained in:
Yichen Jiang
2026-08-09 21:05:49 +08:00
parent 4cd15909ac
commit 14bd07fd90
4 changed files with 24 additions and 3 deletions
+15 -2
View File
@@ -13,6 +13,8 @@ import z from 'schemastery'
import { installModelSelection } from '@deepseek-ai/dsh-agent'
import type { ModelSelectionRef } from '@deepseek-ai/dsh-agent'
import type {} from '@deepseek-ai/dsh-agent-default-model'
// Empty type import carries the agentPresets Context merge for the optional roster read.
import type {} from '@deepseek-ai/dsh-agent-presets'
import { createUserMessage } from '@deepseek-ai/dsh-llm'
import { SessionId } from '@deepseek-ai/dsh-session'
import type { SessionEvent } from '@deepseek-ai/dsh-session'
@@ -106,13 +108,24 @@ async function run(ctx: Context, task: string, io: HeadlessIo): Promise<void> {
if (agents === undefined || defaultModel === undefined || sessions === undefined) return
const selection = defaultModel.currentSelection()
// A one-shot run composes its agent from the same preset roster `dsh web`
// offers: the default preset both lands on the header (the log states what
// the agent ran) and mounts in setup, where a broken composition still
// fails the creation. A composition with no roster keeps the pre-preset
// behavior — the agent runs on the host composition alone.
const presets = ctx.get('agentPresets')
const presetId = presets === undefined ? undefined : (await presets.resolve()).id
const { agent } = await agents.create({
sessionId: SessionId(`session-${randomUUID()}`),
meta: { cwd: process.cwd() },
meta: {
cwd: process.cwd(),
...presetId === undefined ? {} : { agentPreset: presetId },
},
agentOptions: { provider: selection.provider, model: selection.model },
setup: (agentCtx) => {
setup: async (agentCtx) => {
const selected: ModelSelectionRef = { current: selection, assembled: undefined }
installModelSelection(agentCtx, selected)
if (presets !== undefined) await presets.mount(agentCtx, presetId)
},
})
await agent.whenIdle()