fix: complete per-bot agent preset lifecycle

This commit is contained in:
xmanrui 2026-08-22 00:20:23 +08:00
parent 8ab4b9e7de
commit 01576f65c6
27 changed files with 721 additions and 208 deletions

View file

@ -60,7 +60,9 @@ export async function createTokenProductionController(ctx, config, internals, de
?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace }).load();
const configuredBots = configStore.list();
await workspaces.reconcile(configuredBots.map((bot) => bot.botId));
await Promise.all(configuredBots.map((bot) => workspaces.ensure(bot.botId)));
await Promise.all(configuredBots.map((bot) => workspaces.ensure(bot.botId, {
defaultAgentPreset: config.agentPreset,
})));
const observedConfigStore = typeof configStore.remove === 'function'
? observeBotWorkspaceRemovals(configStore, { workspaces })
: configStore;
@ -82,7 +84,6 @@ export async function createTokenProductionController(ctx, config, internals, de
const harness = new ResolvedHarness({
baseUrl: harnessOrigin(ctx.webServer, config.harnessBaseUrl),
workspace: defaultWorkspace,
...(config.agentPreset == null ? {} : { agentPreset: config.agentPreset }),
autostart: false,
dshBin: config.dshBin ?? 'dsh',
...(commandExecutor ? { commandExecutor } : {}),
@ -96,7 +97,7 @@ export async function createTokenProductionController(ctx, config, internals, de
...(internals.inspectToken ? { inspectToken: internals.inspectToken } : {}),
createRuntime: async ({ botId, config: botConfig, token }) => {
const state = await stateFor(botId);
await workspaces.ensure(botId);
await workspaces.ensure(botId, { defaultAgentPreset: config.agentPreset });
const workspaceScope = createBotWorkspaceScope(harness, { botId, workspaces, state });
return new ResolvedRuntime({
...channelRuntimeOptions,
@ -131,7 +132,7 @@ export async function createTokenProductionController(ctx, config, internals, de
const controller = createWorkspaceAwareController(coreController, {
workspaces,
stateFor,
agentPresetCatalog: await listAgentPresetCatalog(ctx),
agentPresetCatalog: () => listAgentPresetCatalog(ctx),
});
const supervisor = createSupervisor({
channel,