import type { McpServerConfig, McpServersStandardFormat } from '../../core/mcp/index.js'; import type { McpServerConfigStandardEntry } from '../../core/mcp/types.js'; import { DatabaseService } from '../database/database.service.js'; import { WorkspaceService } from '../workspace/workspace.service.js'; /** 缺省智能体 ID / 工作空间名,不可删除;对应目录 ~/.openbot/workspace/default */ export declare const DEFAULT_AGENT_ID = "default"; /** 执行器类型:local=本机,coze/openclawx/opencode=远程代理,claude_code=本机 Claude Code CLI */ export type AgentRunnerType = 'local' | 'coze' | 'openclawx' | 'opencode' | 'claude_code'; /** Coze 站点:cn=国内 api.coze.cn,com=国际 api.coze.com,凭证不通用 */ export type CozeRegion = 'cn' | 'com'; /** 某站点的 Bot 凭证 */ export interface CozeRegionCredentials { botId: string; apiKey: string; } /** Coze 代理配置(存储):按站点分别存凭证,请求时用 region 对应的一套 */ export interface AgentCozeConfig { region?: CozeRegion; cn?: CozeRegionCredentials; com?: CozeRegionCredentials; endpoint?: string; } export interface AgentOpenClawXConfig { baseUrl: string; apiKey?: string; } /** OpenCode 启动模式:local=本应用启动本机服务;remote=连接已运行的服务 */ export type OpenCodeServerMode = "local" | "remote"; /** OpenCode 代理配置:按官方 Server API 或 OpenAI 兼容端点 */ export interface AgentOpenCodeConfig { /** 启动模式:local=本应用按需启动;remote=连接已有服务 */ mode?: OpenCodeServerMode; /** 地址(仅 remote 必填;local 时由适配器使用 127.0.0.1) */ address?: string; port: number; password?: string; /** Basic 认证用户名(默认 opencode) */ username?: string; /** @deprecated 仅保留向后兼容,产品仅支持官方 Server API */ apiStyle?: "server" | "openai"; path?: string; streamPath?: string; /** 默认模型(local 时写入启动配置;remote 时作为请求 model) */ model?: string; /** 工作目录(仅 local 模式):启动 opencode serve 时的 cwd,留空则使用进程当前目录 */ workingDirectory?: string; } /** * 智能体列表与配置使用文件存储(~/.openbot/desktop/agents.json),不使用 SQLite。 * 会话与消息历史使用 SQLite;Skills、工作空间文档为目录文件管理。 */ export interface AgentConfigItem { id: string; name: string; workspace: string; provider?: string; model?: string; /** 匹配 config.configuredModels 中的 modelItemCode,优先于 provider/model */ modelItemCode?: string; /** 是否为系统缺省智能体(主智能体),不可删除 */ isDefault?: boolean; /** MCP 配置:数组(含 transport)或标准 JSON 对象(key 为服务器名称),创建 Session 时归一化使用 */ mcpServers?: McpServerConfig[] | McpServersStandardFormat; /** MCP 单次返回最大 token;不配置则不限制 */ mcpMaxResultTokens?: number; /** 自定义系统提示词,会与技能等一起组成最终 systemPrompt */ systemPrompt?: string; /** 智能体图标标识(前端预设图标 id,如 default、star、code 等) */ icon?: string; /** 执行器类型:local=本机,coze/openclawx/opencode=远程代理 */ runnerType?: AgentRunnerType; /** Coze 代理配置(runnerType 为 coze 时使用) */ coze?: AgentCozeConfig; /** OpenBot 代理配置(runnerType 为 openclawx 时使用) */ openclawx?: AgentOpenClawXConfig; /** OpenCode 代理配置(runnerType 为 opencode 时使用) */ opencode?: AgentOpenCodeConfig; /** Claude Code 代理配置(runnerType 为 claude_code 时使用):工作目录等 */ claudeCode?: { workingDirectory?: string; }; /** 是否使用经验(长记忆):memory_recall / save_experience;默认 true */ useLongMemory?: boolean; /** 在线搜索:启用后该智能体拥有 web_search 工具;可选默认 provider、maxResultTokens(前端默认 64K) */ webSearch?: { enabled?: boolean; provider?: 'brave' | 'duck-duck-scrape'; maxResultTokens?: number; }; /** 本地模型上下文长度(token 数),仅 runnerType 为 local 时生效;默认 32768(32K) */ contextSize?: number; } export interface DeleteAgentOptions { /** 是否同时删除该工作区在磁盘上的目录及文件;默认 false(仅删数据库中的工作区相关数据,保留目录) */ deleteWorkspaceDir?: boolean; } export declare class AgentConfigService { private readonly db; private readonly workspaceService; private configDir; private agentsPath; constructor(db: DatabaseService, workspaceService: WorkspaceService); private ensureConfigDir; private readAgentsFile; private writeAgentsFile; /** 确保 default 工作空间目录存在 */ private ensureDefaultWorkspace; private defaultAgent; listAgents(): Promise; getAgent(id: string): Promise; createAgent(params: { name: string; workspace: string; provider?: string; model?: string; modelItemCode?: string; /** 自定义系统提示词;可由用户描述生成,创建后可在详情页修改 */ systemPrompt?: string; /** 智能体图标标识 */ icon?: string; }): Promise; updateAgent(id: string, updates: Partial>): Promise; deleteAgent(id: string, options?: DeleteAgentOptions): Promise; /** 仅删除数据库中与该工作区相关的数据(会话、定时任务、收藏等),不删磁盘目录 */ private deleteWorkspaceDataFromDb; /** * 根据 config 的 defaultProvider / defaultModel / defaultModelItemCode 及 configuredModels 同步 agents.json 中缺省智能体的 provider、model、modelItemCode。 * 在桌面保存配置(如修改默认模型)后调用,保证 agents 与 config 一致。 */ syncDefaultAgentFromConfig(config: { defaultProvider?: string; defaultModel?: string; defaultModelItemCode?: string; configuredModels?: Array<{ provider: string; modelId: string; modelItemCode?: string; }>; }): Promise; /** * 测试单条 MCP 配置是否可用(连接并拉取工具列表后断开)。 * 用于配置界面「测试」按钮,可提前触发 uvx/npx 依赖安装。 */ testMcpServer(entry: McpServerConfigStandardEntry): Promise<{ success: boolean; error?: string; toolsCount?: number; }>; }