dsh-im-ops/plugin-src/host/channels/shared/agent-preset-rpc.mjs
iamyaojie 3161816cc4 feat: 按机器人选择 Agent Preset
在九个渠道的设置页卡片上选择 Host 已有预设;未选则跟随默认,只影响之后新建的会话。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-21 19:19:45 +08:00

21 lines
846 B
JavaScript

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 };
}