mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-10 09:03:17 +08:00
feat: 按机器人选择 Agent Preset
在九个渠道的设置页卡片上选择 Host 已有预设;未选则跟随默认,只影响之后新建的会话。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
c3b3a29f27
commit
3161816cc4
51 changed files with 2227 additions and 740 deletions
21
plugin-src/host/channels/shared/agent-preset-rpc.mjs
Normal file
21
plugin-src/host/channels/shared/agent-preset-rpc.mjs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { AGENT_PRESET_ID } from '../../../../src/channels/shared/agent-preset.mjs';
|
||||
|
||||
export const SET_AGENT_PRESET_ENDPOINT = 'bot.preset.set';
|
||||
|
||||
function isRecord(value) {
|
||||
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
||||
}
|
||||
|
||||
export function validAgentPresetPayload(payload) {
|
||||
return isRecord(payload)
|
||||
&& Object.keys(payload).every((key) => ['botId', 'agentPreset'].includes(key))
|
||||
&& typeof payload.botId === 'string'
|
||||
&& /^[A-Za-z0-9_-]{1,128}$/.test(payload.botId)
|
||||
&& (payload.agentPreset === null
|
||||
|| (typeof payload.agentPreset === 'string' && AGENT_PRESET_ID.test(payload.agentPreset)));
|
||||
}
|
||||
|
||||
export function publicAgentPresetError(error) {
|
||||
if (!['agent-preset-invalid', 'workspace-bot-not-found'].includes(error?.code)) return null;
|
||||
return { code: error.code, message: error.message };
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@ import {
|
|||
createWorkspaceAwareController,
|
||||
observeBotWorkspaceRemovals,
|
||||
} from '../../../../src/channels/shared/bot-workspace-store.mjs';
|
||||
import { listAgentPresetCatalog } from '../../../../src/channels/shared/agent-preset.mjs';
|
||||
|
||||
export function harnessOrigin(webServer, configured) {
|
||||
if (configured !== undefined) return new URL(configured);
|
||||
|
|
@ -127,7 +128,11 @@ export async function createTokenProductionController(ctx, config, internals, de
|
|||
}
|
||||
},
|
||||
});
|
||||
const controller = createWorkspaceAwareController(coreController, { workspaces, stateFor });
|
||||
const controller = createWorkspaceAwareController(coreController, {
|
||||
workspaces,
|
||||
stateFor,
|
||||
agentPresetCatalog: await listAgentPresetCatalog(ctx),
|
||||
});
|
||||
const supervisor = createSupervisor({
|
||||
channel,
|
||||
controller,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,10 @@ import {
|
|||
SET_WORKSPACE_ENDPOINT,
|
||||
validWorkspacePayload,
|
||||
} from './workspace-rpc.mjs';
|
||||
import {
|
||||
SET_AGENT_PRESET_ENDPOINT,
|
||||
validAgentPresetPayload,
|
||||
} from './agent-preset-rpc.mjs';
|
||||
|
||||
export const TOKEN_BOT_ENDPOINTS = Object.freeze({
|
||||
status: 'connection.status',
|
||||
|
|
@ -12,6 +16,7 @@ export const TOKEN_BOT_ENDPOINTS = Object.freeze({
|
|||
reconnectBot: 'bot.reconnect',
|
||||
deleteBot: 'bot.delete',
|
||||
setWorkspace: SET_WORKSPACE_ENDPOINT,
|
||||
setAgentPreset: SET_AGENT_PRESET_ENDPOINT,
|
||||
});
|
||||
|
||||
const ENDPOINTS = Object.freeze(Object.values(TOKEN_BOT_ENDPOINTS));
|
||||
|
|
@ -57,6 +62,10 @@ function payloadFailure(endpoint, payload) {
|
|||
return validWorkspacePayload(payload)
|
||||
? null : '请输入工作区绝对路径。';
|
||||
}
|
||||
if (endpoint === TOKEN_BOT_ENDPOINTS.setAgentPreset) {
|
||||
return validAgentPresetPayload(payload)
|
||||
? null : '请选择 Agent Preset。';
|
||||
}
|
||||
return 'Unknown bot endpoint.';
|
||||
}
|
||||
|
||||
|
|
@ -132,6 +141,9 @@ export function createTokenBotRpcHandler(controller, { channel }) {
|
|||
} else if (endpoint === TOKEN_BOT_ENDPOINTS.setWorkspace) {
|
||||
if (typeof controller.updateWorkspace !== 'function') throw new Error('Workspace update is unavailable');
|
||||
value = await controller.updateWorkspace(payload.botId, payload.workspace);
|
||||
} else if (endpoint === TOKEN_BOT_ENDPOINTS.setAgentPreset) {
|
||||
if (typeof controller.updateAgentPreset !== 'function') throw new Error('Agent preset update is unavailable');
|
||||
value = await controller.updateAgentPreset(payload.botId, payload.agentPreset);
|
||||
} else {
|
||||
value = await controller.deleteBot(payload.botId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ export function publicWorkspaceError(error) {
|
|||
'workspace-not-found',
|
||||
'workspace-not-directory',
|
||||
'workspace-bot-not-found',
|
||||
'agent-preset-invalid',
|
||||
].includes(error?.code)) return null;
|
||||
return { code: error.code, message: error.message };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue