agentdev 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +384 -0
- package/dist/BasicAgent-UDSHJE5H.js +12 -0
- package/dist/BasicAgent-UDSHJE5H.js.map +1 -0
- package/dist/ExplorerAgent-X6QECX65.js +12 -0
- package/dist/ExplorerAgent-X6QECX65.js.map +1 -0
- package/dist/chunk-3BPSNNK3.js +926 -0
- package/dist/chunk-3BPSNNK3.js.map +1 -0
- package/dist/chunk-BDS2QGZ5.js +22 -0
- package/dist/chunk-BDS2QGZ5.js.map +1 -0
- package/dist/chunk-BVF7RUXV.js +136 -0
- package/dist/chunk-BVF7RUXV.js.map +1 -0
- package/dist/chunk-DI5EGMGG.js +87 -0
- package/dist/chunk-DI5EGMGG.js.map +1 -0
- package/dist/chunk-FZGM6EMW.js +7578 -0
- package/dist/chunk-FZGM6EMW.js.map +1 -0
- package/dist/chunk-N7J76R5P.js +7659 -0
- package/dist/chunk-N7J76R5P.js.map +1 -0
- package/dist/chunk-TSASFMRF.js +12 -0
- package/dist/chunk-TSASFMRF.js.map +1 -0
- package/dist/chunk-XAJ6L4GA.js +98 -0
- package/dist/chunk-XAJ6L4GA.js.map +1 -0
- package/dist/cli/server.cmd +2 -0
- package/dist/cli/server.d.ts +1 -0
- package/dist/cli/server.js +46 -0
- package/dist/cli/server.js.map +1 -0
- package/dist/cli/viewer.cmd +2 -0
- package/dist/cli/viewer.d.ts +1 -0
- package/dist/cli/viewer.js +45 -0
- package/dist/cli/viewer.js.map +1 -0
- package/dist/index.d.ts +3836 -0
- package/dist/index.js +273 -0
- package/dist/index.js.map +1 -0
- package/dist/notification-3VEAP7YF.js +89 -0
- package/dist/notification-3VEAP7YF.js.map +1 -0
- package/dist/resolver-5H6QIGVA.js +8 -0
- package/dist/resolver-5H6QIGVA.js.map +1 -0
- package/package.json +74 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/core/types.ts
|
|
2
|
+
function getDefaultUDSPath() {
|
|
3
|
+
if (process.platform === "win32") {
|
|
4
|
+
return "\\\\.\\pipe\\agentdev-viewer";
|
|
5
|
+
}
|
|
6
|
+
return "/tmp/agentdev-viewer.sock";
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
getDefaultUDSPath
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=chunk-TSASFMRF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/types.ts"],"sourcesContent":["/**\r\n * 基础类型定义\r\n * 所有类型集中在这里,简单直观\r\n */\r\n\r\n// ========== 通知系统类型 ==========\r\n\r\n/**\r\n * 通知分类\r\n * - state: 覆盖式更新(如 LLM 字符计数)\r\n * - event: 追加式记录(如工具开始/完成)\r\n */\r\nexport type NotificationCategory = 'state' | 'event';\r\n\r\n/**\r\n * LLM 生成阶段\r\n */\r\nexport type LLMPhase = 'thinking' | 'content' | 'tool_calling';\r\n\r\n/**\r\n * 通知基础接口\r\n */\r\nexport interface Notification {\r\n type: string;\r\n category: NotificationCategory;\r\n timestamp: number;\r\n data: unknown;\r\n}\r\n\r\nexport type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error';\r\n\r\nexport type DebugLogDeliveryReason =\r\n | 'hub'\r\n | 'hub-unavailable'\r\n | 'no-agent-context';\r\n\r\nexport interface DebugLogDelivery {\r\n hub: boolean;\r\n console: boolean;\r\n reason: DebugLogDeliveryReason;\r\n}\r\n\r\nexport interface LogContextRef {\r\n agentId?: string;\r\n agentName?: string;\r\n parentAgentId?: string;\r\n callIndex?: number;\r\n step?: number;\r\n toolName?: string;\r\n toolCallId?: string;\r\n feature?: string;\r\n lifecycle?: string;\r\n hookMethod?: string;\r\n hookKind?: 'forward' | 'reverse';\r\n sourceFile?: string;\r\n sourceLine?: number;\r\n tags?: string[];\r\n [key: string]: unknown;\r\n}\r\n\r\nexport interface DebugLogEntry {\r\n id: string;\r\n timestamp: number;\r\n level: LogLevel;\r\n message: string;\r\n namespace: string;\r\n context: LogContextRef;\r\n data?: unknown;\r\n delivery: DebugLogDelivery;\r\n}\r\n\r\n/**\r\n * LLM 字符计数通知数据\r\n */\r\nexport interface LLMCharCountData {\r\n charCount: number;\r\n phase: LLMPhase;\r\n}\r\n\r\n/**\r\n * LLM 完成通知数据\r\n */\r\nexport interface LLMCompleteData {\r\n totalChars: number;\r\n}\r\n\r\n/**\r\n * 工具开始通知数据\r\n */\r\nexport interface ToolStartData {\r\n toolName: string;\r\n}\r\n\r\n/**\r\n * 工具完成通知数据\r\n */\r\nexport interface ToolCompleteData {\r\n toolName: string;\r\n success: boolean;\r\n duration: number;\r\n}\r\n\r\n/**\r\n * 通知状态响应(GET /api/agents/:id/notification)\r\n */\r\nexport interface NotificationStateResponse {\r\n state: Notification | null;\r\n hasNewEvents: boolean;\r\n}\r\n\r\nexport interface AgentLogsResponse {\r\n scope: 'current' | 'all';\r\n currentAgentId: string | null;\r\n selectedAgentId: string | null;\r\n total: number;\r\n logs: DebugLogEntry[];\r\n truncation?: {\r\n truncated: boolean;\r\n appliedLimit?: number;\r\n returnedCount: number;\r\n availableCount: number;\r\n nextOffset?: number;\r\n reason?: string;\r\n guidance?: string;\r\n };\r\n collectionPolicy: {\r\n hubConnected: boolean;\r\n includesOnlyHubDeliveredLogs: boolean;\r\n fallbackBehavior: string;\r\n };\r\n}\r\n\r\n/**\r\n * Agent 连接状态响应(GET /api/agents/:id/connection)\r\n */\r\nexport interface AgentConnectionResponse {\r\n connected: boolean;\r\n}\r\n\r\n// ========== 消息类型 ==========\r\n\r\n// 消息角色(支持子代理 ID 作为消息来源)\r\nexport type MessageRole = 'system' | 'user' | 'assistant' | 'tool' | string;\r\n\r\n// 消息结构\r\nexport interface Message {\r\n role: MessageRole;\r\n content: string;\r\n turn?: number;\r\n toolCallId?: string;\r\n toolCalls?: ToolCall[];\r\n reasoning?: string; // 思考内容(GLM-4.7等模型的扩展字段)\r\n thinkingBlocks?: ThinkingBlock[];\r\n}\r\n\r\nexport interface ThinkingBlock {\r\n signature: string;\r\n thinking: string;\r\n}\r\n\r\n// 工具调用\r\nexport interface ToolCall {\r\n id: string;\r\n name: string;\r\n arguments: Record<string, any>;\r\n}\r\n\r\n/**\r\n * 统一用量格式(兼容 Anthropic 和 OpenAI)\r\n */\r\nexport interface UsageInfo {\r\n /** 输入 token 数 */\r\n inputTokens: number;\r\n /** 输出 token 数 */\r\n outputTokens: number;\r\n /** 总 token 数 */\r\n totalTokens: number;\r\n\r\n // ========== Anthropic 特有(可选)==========\r\n /** 创建缓存消耗的 token 数 */\r\n cacheCreationTokens?: number;\r\n /** 从缓存读取的 token 数 */\r\n cacheReadTokens?: number;\r\n\r\n // ========== OpenAI 特有(可选)==========\r\n /** 推理 token 数 */\r\n reasoningTokens?: number;\r\n /** 音频 token 数 */\r\n audioTokens?: number;\r\n}\r\n\r\n// LLM 响应\r\nexport interface LLMResponse {\r\n content: string;\r\n toolCalls?: ToolCall[];\r\n reasoning?: string; // 思考内容(GLM-4.7等模型的扩展字段)\r\n thinkingBlocks?: ThinkingBlock[];\r\n /** 用量统计(可选) */\r\n usage?: UsageInfo;\r\n}\r\n\r\n// ============= 渲染模板类型 =============\r\n/**\r\n * 渲染模板项\r\n * 可以是字符串模板或函数模板\r\n */\r\nexport type RenderTemplateItem =\r\n | string // 字符串模板,使用 {{key}} 插值\r\n | RenderTemplateFn; // 函数模板,处理复杂逻辑\r\n\r\n/**\r\n * 渲染模板函数类型\r\n */\r\nexport type RenderTemplateFn = (data: Record<string, any>, success?: boolean) => string;\r\n\r\n/**\r\n * 内联渲染模板\r\n * 直接定义在工具中的渲染模板(无需引用预设模板)\r\n */\r\nexport interface InlineRenderTemplate {\r\n call: RenderTemplateItem;\r\n result: RenderTemplateItem;\r\n}\r\n\r\n// 工具渲染配置\r\nexport interface ToolRenderConfig {\r\n /** 调用时的渲染模板(字符串引用或内联模板) */\r\n call?: string | InlineRenderTemplate;\r\n /** 结果时的渲染模板(字符串引用或内联模板) */\r\n result?: string | InlineRenderTemplate;\r\n}\r\n\r\n// 工具定义\r\nexport interface Tool {\r\n name: string;\r\n description: string;\r\n parameters?: Record<string, any>;\r\n execute: (args: any, context?: any) => Promise<any>;\r\n /** 可选:渲染配置 */\r\n render?: ToolRenderConfig;\r\n}\r\n\r\n// LLM 接口 - 所有 LLM 适配器都需要实现这个\r\nexport interface LLMClient {\r\n chat(messages: Message[], tools: Tool[]): Promise<LLMResponse>;\r\n}\r\n\r\n// 占位符上下文类型\r\nimport type { PlaceholderContext, TemplateSource } from '../template/types.js';\n\n// MCP 类型导入\nimport type { MCPConfig } from '../mcp/types.js';\nimport type { UsageStatsSnapshot } from './usage.js';\n\r\n// Agent 配置\r\nexport interface AgentConfig {\r\n llm: LLMClient;\r\n tools?: Tool[];\r\n maxTurns?: number;\r\n systemMessage?: string | TemplateSource;\r\n name?: string; // Agent 显示名称(用于调试)\r\n\r\n // ========== Feature 系统 ==========\r\n /**\r\n * Feature 配置\r\n *\r\n * 新的声明式 Feature 注册方式\r\n */\r\n features?: {\r\n /** 启用的 Feature 列表 */\r\n enabled?: string[];\r\n /** Feature 特定配置 */\r\n [key: string]: unknown;\r\n };\r\n}\r\n\r\n// 上下文中间件 - 用于处理消息数组\r\nexport type ContextMiddleware = (messages: Message[]) => Message[];\r\n\r\n// ============= 多 Agent 调试支持 =============\r\n\r\n/**\r\n * Agent 注册信息(Hub 端)\r\n */\r\nexport interface AgentInfo {\r\n id: string; // 唯一标识,如 \"agent-1\"\r\n name: string; // 显示名称\r\n registeredAt: number; // 注册时间戳\r\n}\r\n\r\n/**\r\n * 工具元数据(用于前端渲染)\r\n */\r\nexport interface ToolMetadata {\r\n name: string;\r\n description: string;\r\n render: {\r\n call: string | InlineRenderTemplate; // 模板名称或内联模板\r\n result: string | InlineRenderTemplate; // 模板名称或内联模板\r\n // 内联模板的可选直接存储(用于前端特殊标记)\r\n inlineCall?: InlineRenderTemplate;\r\n inlineResult?: InlineRenderTemplate;\r\n };\r\n}\r\n\r\nexport interface HookSourceLocation {\r\n file?: string;\r\n line?: number;\r\n column?: number;\r\n display: string;\r\n}\r\n\r\nexport interface HookEntryMetadata {\r\n order: number;\r\n featureName: string;\r\n methodName: string;\r\n lifecycle: string;\r\n kind: 'decision' | 'notify';\r\n source?: HookSourceLocation;\r\n description?: string;\r\n}\r\n\r\nexport interface HookLifecycleSnapshot {\r\n lifecycle: string;\r\n kind: 'decision' | 'notify';\r\n entries: HookEntryMetadata[];\r\n}\r\n\r\nexport interface FeatureInspectorSnapshot {\r\n name: string;\r\n enabled: boolean;\r\n status: 'enabled' | 'disabled' | 'partial';\r\n hookCount: number;\r\n toolCount: number;\r\n enabledToolCount: number;\r\n source?: string;\r\n description?: string;\r\n tools: Array<{\r\n name: string;\r\n description: string;\r\n enabled: boolean;\r\n renderCall?: string;\r\n renderResult?: string;\r\n }>;\r\n}\r\n\r\nexport interface HookInspectorSnapshot {\n lifecycleOrder: string[];\n features: FeatureInspectorSnapshot[];\n hooks: HookLifecycleSnapshot[];\n}\n\nexport interface AgentContextMetrics {\n messageCount: number;\n charCount: number;\n toolCallCount: number;\n turnCount: number;\n}\n\nexport interface AgentOverviewSnapshot {\n updatedAt: number;\n context: AgentContextMetrics;\n usageStats: UsageStatsSnapshot;\n}\n\r\n/**\r\n * Agent 会话数据(Worker 端)\r\n */\r\nexport interface AgentSession {\n id: string;\n name: string;\n messages: Message[];\n tools: ToolMetadata[];\n createdAt: number;\r\n lastActive: number;\r\n // 项目根目录(用于定位模板文件)\r\n projectRoot?: string;\r\n // 通知系统扩展\r\n currentState: Notification | null;\r\n events: Notification[];\r\n lastEventCount: number;\r\n logs: DebugLogEntry[];\r\n // 所属 UDS 客户端连接 ID(用于多进程输入响应路由)\r\n clientId?: string;\r\n // 内部:上次最后一条消息的签名(用于推送去重)\n _lastMessageSig?: string;\n hookInspector?: HookInspectorSnapshot;\n overview?: AgentOverviewSnapshot;\n}\n\r\n/**\r\n * DebugHub IPC 消息类型(主进程 → Worker)\r\n * 使用 discriminated union 确保类型安全\r\n */\r\nexport type DebugHubIPCMessage =\n | RegisterAgentMsg\n | UpdateAgentInspectorMsg\n | UpdateAgentOverviewMsg\n | PushMessagesMsg\n | RegisterToolsMsg\n | SetCurrentAgentMsg\n | UnregisterAgentMsg\n | PushNotificationMsg\n | RequestInputMsg\r\n | StopMsg;\r\n\r\n/**\r\n * 注册新 Agent\r\n */\r\nexport interface RegisterAgentMsg {\n type: 'register-agent';\n agentId: string;\n name: string;\n createdAt: number;\n projectRoot?: string; // 项目根目录,用于模板文件加载\r\n featureTemplates?: Record<string, string>; // Feature 模板路径映射\n hookInspector?: HookInspectorSnapshot;\n overview?: AgentOverviewSnapshot;\n activeInputRequest?: ActiveInputRequest; // 活跃的输入请求(用于重连后恢复)\n}\n\nexport interface UpdateAgentInspectorMsg {\n type: 'update-agent-inspector';\n agentId: string;\n hookInspector: HookInspectorSnapshot;\n}\n\nexport interface UpdateAgentOverviewMsg {\n type: 'update-agent-overview';\n agentId: string;\n overview: AgentOverviewSnapshot;\n}\n\r\n/**\r\n * 推送 Agent 消息\r\n */\r\nexport interface PushMessagesMsg {\r\n type: 'push-messages';\r\n agentId: string;\r\n messages: Message[];\r\n}\r\n\r\n/**\r\n * 注册 Agent 工具\r\n */\r\nexport interface RegisterToolsMsg {\r\n type: 'register-tools';\r\n agentId: string;\r\n tools: Tool[];\r\n}\r\n\r\n/**\r\n * 切换当前选中的 Agent\r\n */\r\nexport interface SetCurrentAgentMsg {\r\n type: 'set-current-agent';\r\n agentId: string;\r\n}\r\n\r\n/**\r\n * 活跃的输入请求(用于重连后恢复)\r\n */\r\nexport interface ActiveInputRequest {\r\n requestId: string;\r\n prompt: string;\r\n placeholder?: string;\r\n initialValue?: string;\r\n actions?: UserInputAction[];\r\n timestamp: number;\r\n}\r\n\r\n/**\r\n * 注销 Agent\r\n */\r\nexport interface UnregisterAgentMsg {\r\n type: 'unregister-agent';\r\n agentId: string;\r\n}\r\n\r\n/**\r\n * 停止 Worker\r\n */\r\nexport interface StopMsg {\r\n type: 'stop';\r\n}\r\n\r\n/**\r\n * 推送通知\r\n */\r\nexport interface PushNotificationMsg {\r\n type: 'push-notification';\r\n agentId: string;\r\n notification: Notification;\r\n}\r\n\r\n/**\r\n * 请求用户输入\r\n */\r\nexport interface RequestInputMsg {\r\n type: 'request-input';\r\n agentId: string;\r\n requestId: string;\r\n prompt: string;\r\n timeout?: number;\r\n placeholder?: string;\r\n initialValue?: string;\r\n actions?: UserInputAction[];\r\n}\r\n\r\n/**\r\n * 用户输入响应(Worker → Agent,通过 UDS)\r\n */\r\nexport interface InputResponseMsg {\r\n type: 'input-response';\r\n agentId: string;\r\n requestId: string;\r\n input: string;\r\n response?: UserInputResponse;\r\n}\r\n\r\nexport interface UserInputAction {\r\n id: string;\r\n label: string;\r\n kind?: 'rollback' | 'custom';\r\n variant?: 'primary' | 'secondary' | 'danger';\r\n payload?: Record<string, unknown>;\r\n}\r\n\r\nexport interface UserInputRequest {\r\n prompt: string;\r\n placeholder?: string;\r\n initialValue?: string;\r\n actions?: UserInputAction[];\r\n}\r\n\r\nexport interface UserInputResponse {\r\n kind: 'text' | 'action';\r\n text?: string;\r\n actionId?: string;\r\n payload?: Record<string, unknown>;\r\n}\r\n\r\n/**\r\n * Worker → 主进程 消息\r\n */\r\nexport type WorkerIPCMessage =\r\n | ReadyMsg\r\n | AgentSwitchedMsg\r\n | InputResponseMsg;\r\n\r\n/**\r\n * Worker 就绪\r\n */\r\nexport interface ReadyMsg {\r\n type: 'ready';\r\n}\r\n\r\n/**\r\n * Agent 切换确认\r\n */\r\nexport interface AgentSwitchedMsg {\r\n type: 'agent-switched';\r\n agentId: string;\r\n}\r\n\r\n// ========== 上下文管理类型 ==========\r\n/**\r\n * 消息标签枚举\r\n *\r\n * 用于快速分类和过滤消息,一条消息可能有多个标签\r\n */\r\nexport type MessageTag =\r\n | 'user' // 用户输入消息\r\n | 'system' // 系统消息\r\n | 'assistant' // LLM 响应消息\r\n | 'tool-call' // assistant 消息且包含 toolCalls\r\n | 'tool-result' // role === 'tool' 的工具执行结果\r\n | 'sub-agent' // 来自子代理的消息(与 assistant/tool-result 组合使用)\r\n | 'reminder'; // Feature 注入的提醒消息(与 system 组合使用)\r\n\r\n/**\r\n * 解析结果结构\r\n *\r\n * 从消息 content 中提取的结构化信息\r\n */\r\nexport interface ParsedContent {\r\n /** 从 content 提取的任务 ID(正则匹配 \"taskId\":\"xxx\") */\r\n taskIds: string[];\r\n /** 从 content 提取的工具调用名称(从 toolCalls 或 content 解析) */\r\n toolCalls: string[];\r\n /** @ 提及的内容 */\r\n mentions: string[];\r\n /** 用户可继承扩展更多字段 */\r\n [key: string]: any;\r\n}\r\n\r\n/**\r\n * 消息元数据\r\n *\r\n * 用于 addMessage() 的元数据参数\r\n */\r\nexport interface MessageMeta {\r\n /** ReAct 循环轮次 */\r\n turn: number;\r\n /** 子代理 ID(子代理消息时填写) */\r\n agentId?: string;\r\n /** 来源 Feature(reminder 等消息时填写) */\r\n source?: string;\r\n}\r\n\r\n/**\r\n * 扩展的消息结构\r\n *\r\n * 在原始 Message 基础上添加元数据\r\n * 不破坏现有 Message 类型,保证 LLM 调用兼容性\r\n */\r\nexport interface EnrichedMessage extends Message {\r\n // === 元数据字段 ===\r\n\r\n /** 唯一标识(用于索引关联) */\r\n id: string;\r\n /** 消息产生时间戳(毫秒) */\r\n timestamp: number;\r\n /** 所属 ReAct 循环轮次(从 0 开始) */\r\n turn: number;\r\n /** 全局消息序号(从 0 开始递增) */\r\n sequence: number;\r\n /** 来源 Agent ID(子代理消息) */\r\n agentId?: string;\r\n /** 来源 Feature(如 'todo-feature',仅 reminder 等) */\r\n source?: string;\r\n\r\n // === 分类标签 ===\r\n\r\n /** 消息分类标签(用于快速查询) */\r\n tags: MessageTag[];\r\n\r\n // === 解析结果 ===\r\n\r\n /** 从 content 中提取的结构化信息 */\r\n parsed: ParsedContent;\r\n}\r\n\r\n// ========== 生命周期类型 re-export ==========\r\n// 生命周期类型从 lifecycle.ts 导出,保持类型定义集中管理\r\nexport type {\r\n AgentInitiateContext,\r\n AgentDestroyContext,\r\n CallStartContext,\r\n CallFinishContext,\r\n StepStartContext,\r\n StepFinishedContext,\r\n HookResult,\r\n ToolContext,\r\n ToolResult,\r\n} from './lifecycle.js';\r\n\r\n// ========== 决策上下文类型 ==========\r\n/**\r\n * 决策上下文(反向钩子参数)\r\n *\r\n * 所有决策上下文的联合类型\r\n */\r\nexport type DecisionContext =\r\n | import('./lifecycle.js').AgentInitiateContext\r\n | import('./lifecycle.js').AgentDestroyContext\r\n | import('./lifecycle.js').CallStartContext\r\n | import('./lifecycle.js').CallFinishContext\r\n | import('./lifecycle.js').StepStartContext\r\n | import('./lifecycle.js').StepFinishedContext\r\n | import('./lifecycle.js').ToolContext\r\n | import('./lifecycle.js').ToolResult\r\n | import('./lifecycle.js').StepFinishDecisionContext\r\n | import('./lifecycle.js').ToolFinishedDecisionContext;\r\n\r\n// ========== UDS 通信类型 ==========\r\n\r\n/**\r\n * UDS 配置\r\n */\r\nexport interface UDSConfig {\r\n /** UDS 路径(默认自动检测平台) */\r\n path?: string;\r\n /** HTTP 端口(Web 界面) */\r\n httpPort?: number;\r\n /** 是否自动打开浏览器 */\r\n openBrowser?: boolean;\r\n}\r\n\r\n/**\r\n * 平台检测后的 UDS 路径\r\n */\r\nexport function getDefaultUDSPath(): string {\r\n if (process.platform === 'win32') {\r\n return '\\\\\\\\.\\\\pipe\\\\agentdev-viewer';\r\n }\r\n return '/tmp/agentdev-viewer.sock';\r\n}\r\n"],"mappings":";AAorBO,SAAS,oBAA4B;AAC1C,MAAI,QAAQ,aAAa,SAAS;AAChC,WAAO;AAAA,EACT;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AgentBase,
|
|
3
|
+
MCPFeature,
|
|
4
|
+
OpencodeBasicFeature,
|
|
5
|
+
SkillFeature,
|
|
6
|
+
SubAgentFeature,
|
|
7
|
+
createLLM,
|
|
8
|
+
getDefaultMCPConfigDir,
|
|
9
|
+
loadConfigSync
|
|
10
|
+
} from "./chunk-N7J76R5P.js";
|
|
11
|
+
|
|
12
|
+
// src/agents/system/BasicAgent.ts
|
|
13
|
+
import { existsSync } from "fs";
|
|
14
|
+
import { cwd, platform } from "process";
|
|
15
|
+
var BasicAgent = class extends AgentBase {
|
|
16
|
+
_systemContext;
|
|
17
|
+
_mcpServer;
|
|
18
|
+
_mcpContext;
|
|
19
|
+
_config;
|
|
20
|
+
_skillsDir;
|
|
21
|
+
_mcpFeature;
|
|
22
|
+
/**
|
|
23
|
+
* 构造函数
|
|
24
|
+
*
|
|
25
|
+
* @param config 基础配置(全部可选,不传则使用默认配置)
|
|
26
|
+
*/
|
|
27
|
+
constructor(config = {}) {
|
|
28
|
+
const systemContext = {
|
|
29
|
+
SYSTEM_WORKING_DIR: cwd(),
|
|
30
|
+
SYSTEM_IS_GIT_REPOSITORY: existsSync(cwd() + "/.git"),
|
|
31
|
+
SYSTEM_PLATFORM: platform,
|
|
32
|
+
SYSTEM_DATE: (/* @__PURE__ */ new Date()).toISOString().split("T")[0],
|
|
33
|
+
// YYYY-MM-DD
|
|
34
|
+
SYSTEM_CURRENT_MODEL: "unknown"
|
|
35
|
+
// 稍后更新
|
|
36
|
+
};
|
|
37
|
+
let llm = config.llm;
|
|
38
|
+
let fileConfig;
|
|
39
|
+
if (!llm) {
|
|
40
|
+
const configName = config.configName ?? "default";
|
|
41
|
+
fileConfig = loadConfigSync(configName);
|
|
42
|
+
llm = createLLM(fileConfig);
|
|
43
|
+
systemContext.SYSTEM_CURRENT_MODEL = fileConfig.defaultModel.model;
|
|
44
|
+
console.log(`[BasicAgent] \u5DF2\u52A0\u8F7D\u914D\u7F6E: ${configName}, \u6A21\u578B: ${fileConfig.defaultModel.model}`);
|
|
45
|
+
}
|
|
46
|
+
const agentConfig = {
|
|
47
|
+
llm,
|
|
48
|
+
tools: config.tools ?? [],
|
|
49
|
+
maxTurns: Infinity,
|
|
50
|
+
systemMessage: config.systemMessage,
|
|
51
|
+
name: config.name
|
|
52
|
+
};
|
|
53
|
+
super(agentConfig);
|
|
54
|
+
this._systemContext = systemContext;
|
|
55
|
+
this._config = fileConfig;
|
|
56
|
+
this._mcpServer = config.mcpServer;
|
|
57
|
+
this._mcpContext = config.mcpContext;
|
|
58
|
+
this._skillsDir = config.skillsDir;
|
|
59
|
+
this.setSystemContext(systemContext);
|
|
60
|
+
const hasDefaultMCPConfigs = existsSync(getDefaultMCPConfigDir());
|
|
61
|
+
const shouldEnableMCP = config.mcpServer !== false && (typeof config.mcpServer === "string" || hasDefaultMCPConfigs);
|
|
62
|
+
if (shouldEnableMCP) {
|
|
63
|
+
this._mcpFeature = typeof config.mcpServer === "string" ? new MCPFeature(config.mcpServer) : new MCPFeature(void 0, { excludeServers: config.excludeMcpServers });
|
|
64
|
+
if (config.mcpContext) {
|
|
65
|
+
this._mcpFeature.setMCPContext(config.mcpContext);
|
|
66
|
+
}
|
|
67
|
+
this.use(this._mcpFeature);
|
|
68
|
+
}
|
|
69
|
+
this.use(new OpencodeBasicFeature());
|
|
70
|
+
this.use(new SkillFeature(config.skillsDir));
|
|
71
|
+
this.use(new SubAgentFeature());
|
|
72
|
+
this.getTools().disable("list_agents");
|
|
73
|
+
this.getTools().disable("close_agent");
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 获取系统环境信息
|
|
77
|
+
*/
|
|
78
|
+
getSystemContext() {
|
|
79
|
+
return this._systemContext;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 获取 MCP 服务器配置
|
|
83
|
+
*/
|
|
84
|
+
getMcpServer() {
|
|
85
|
+
return this._mcpServer;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 获取 MCP 上下文
|
|
89
|
+
*/
|
|
90
|
+
getMcpContext() {
|
|
91
|
+
return this._mcpContext;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export {
|
|
96
|
+
BasicAgent
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=chunk-XAJ6L4GA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/agents/system/BasicAgent.ts"],"sourcesContent":["/**\r\n * BasicAgent - 基础 Agent 类\r\n *\r\n * 集成了常用 Feature 和系统环境信息\r\n * 适用于大多数 Agent 场景\r\n *\r\n * 默认自动加载配置文件,开箱即用\r\n */\r\n\r\nimport { Agent } from '../../core/agent.js';\r\nimport { MCPFeature, SkillFeature, SubAgentFeature, OpencodeBasicFeature } from '../../features/index.js';\r\nimport type { AgentConfig, LLMClient, Tool } from '../../core/types.js';\r\nimport type { AgentConfigFile } from '../../core/config.js';\r\nimport { loadConfigSync } from '../../core/config.js';\r\nimport { createLLM } from '../../llm/index.js';\r\nimport { existsSync } from 'fs';\r\nimport { cwd, platform } from 'process';\r\nimport { getDefaultMCPConfigDir } from '../../mcp/config.js';\r\n\r\n/**\r\n * 系统环境信息上下文\r\n */\r\nexport interface SystemContext {\r\n /** 当前工作目录 */\r\n SYSTEM_WORKING_DIR: string;\r\n /** 是否是 Git 仓库 */\r\n SYSTEM_IS_GIT_REPOSITORY: boolean;\r\n /** 操作系统平台 */\r\n SYSTEM_PLATFORM: NodeJS.Platform;\r\n /** 当前日期 (YYYY-MM-DD) */\r\n SYSTEM_DATE: string;\r\n /** 当前使用的模型名称 */\r\n SYSTEM_CURRENT_MODEL: string;\r\n /** 索引签名,允许作为 PlaceholderContext 使用 */\r\n [key: string]: any;\r\n}\r\n\r\n/**\r\n * BasicAgent 配置选项\r\n *\r\n * 所有参数都是可选的,默认会自动同步加载配置文件\r\n */\r\nexport interface BasicAgentConfig {\r\n /** LLM 客户端(可选,不传则自动同步加载配置创建) */\r\n llm?: LLMClient;\r\n /** 配置文件名(可选,默认 'default') */\r\n configName?: string;\r\n /** Agent 显示名称(可选) */\r\n name?: string;\r\n /** 系统提示词(可选,后续可通过 setPrompt() 设置) */\r\n systemMessage?: string;\r\n /** MCP 配置:传字符串时加载指定配置;传 false 时禁用自动加载;不传时若 .agentdev/mcps 存在则自动加载全部 */\r\n mcpServer?: string | false;\r\n /** MCP 运行时上下文(可选,如 GitHub Token) */\r\n mcpContext?: Record<string, unknown>;\r\n /** 自动扫描 MCP 时排除的 serverId 列表 */\r\n excludeMcpServers?: string[];\r\n /** 自定义工具集(可选,默认使用 Feature 提供的工具) */\r\n tools?: Tool[];\r\n /** Skills 目录(可选,默认使用 .agentdev/skills) */\r\n skillsDir?: string;\r\n}\r\n\r\n/**\r\n * 基础 Agent 类\r\n *\r\n * 集成常用 Feature 和系统环境信息,开箱即用\r\n * 构造函数不传任何参数时,会自动同步加载配置文件创建 LLM\r\n */\r\nexport class BasicAgent extends Agent {\r\n protected _systemContext: SystemContext;\r\n protected _mcpServer?: string | false;\r\n protected _mcpContext?: Record<string, unknown>;\r\n protected _config?: AgentConfigFile;\r\n protected _skillsDir?: string;\r\n protected _mcpFeature?: MCPFeature;\r\n\r\n /**\r\n * 构造函数\r\n *\r\n * @param config 基础配置(全部可选,不传则使用默认配置)\r\n */\r\n constructor(config: BasicAgentConfig = {}) {\r\n // 建立系统环境信息\r\n const systemContext: SystemContext = {\r\n SYSTEM_WORKING_DIR: cwd(),\r\n SYSTEM_IS_GIT_REPOSITORY: existsSync(cwd() + '/.git'),\r\n SYSTEM_PLATFORM: platform,\r\n SYSTEM_DATE: new Date().toISOString().split('T')[0], // YYYY-MM-DD\r\n SYSTEM_CURRENT_MODEL: 'unknown', // 稍后更新\r\n };\r\n\r\n // 准备 LLM:如果没传入,同步加载配置\r\n let llm = config.llm;\r\n let fileConfig: AgentConfigFile | undefined;\r\n if (!llm) {\r\n const configName = config.configName ?? 'default';\r\n fileConfig = loadConfigSync(configName);\r\n llm = createLLM(fileConfig);\r\n systemContext.SYSTEM_CURRENT_MODEL = fileConfig.defaultModel.model;\r\n console.log(`[BasicAgent] 已加载配置: ${configName}, 模型: ${fileConfig.defaultModel.model}`);\r\n }\r\n\r\n // 构建完整的 Agent 配置\r\n const agentConfig: AgentConfig = {\r\n llm: llm!,\r\n tools: config.tools ?? [],\r\n maxTurns: Infinity,\r\n systemMessage: config.systemMessage,\r\n name: config.name,\r\n };\r\n\r\n super(agentConfig);\r\n\r\n // 保存配置(必须在 super() 之后)\r\n this._systemContext = systemContext;\r\n this._config = fileConfig;\r\n this._mcpServer = config.mcpServer;\r\n this._mcpContext = config.mcpContext;\r\n this._skillsDir = config.skillsDir;\r\n this.setSystemContext(systemContext);\r\n\r\n const hasDefaultMCPConfigs = existsSync(getDefaultMCPConfigDir());\r\n const shouldEnableMCP = config.mcpServer !== false && (typeof config.mcpServer === 'string' || hasDefaultMCPConfigs);\r\n if (shouldEnableMCP) {\r\n this._mcpFeature = typeof config.mcpServer === 'string'\r\n ? new MCPFeature(config.mcpServer)\r\n : new MCPFeature(undefined, { excludeServers: config.excludeMcpServers });\r\n if (config.mcpContext) {\r\n this._mcpFeature.setMCPContext(config.mcpContext);\r\n }\r\n this.use(this._mcpFeature);\r\n }\r\n\r\n // 注册 OpencodeBasicFeature(文件操作工具集)\r\n this.use(new OpencodeBasicFeature());\r\n\r\n // 注册 SkillFeature(invokeSkill 工具和 skills 上下文注入)\r\n this.use(new SkillFeature(config.skillsDir));\r\n\r\n // 注册 SubAgentFeature(子代理工具和消息处理)\r\n this.use(new SubAgentFeature());\r\n\r\n // 预禁用不需要的子代理工具,确保首次快照与运行时一致\r\n this.getTools().disable('list_agents');\r\n this.getTools().disable('close_agent');\r\n }\r\n\r\n /**\r\n * 获取系统环境信息\r\n */\r\n getSystemContext(): SystemContext {\r\n return this._systemContext;\r\n }\r\n\r\n /**\r\n * 获取 MCP 服务器配置\r\n */\r\n getMcpServer(): string | false | undefined {\r\n return this._mcpServer;\r\n }\r\n\r\n /**\r\n * 获取 MCP 上下文\r\n */\r\n getMcpContext(): Record<string, unknown> | undefined {\r\n return this._mcpContext;\r\n }\r\n}\r\n"],"mappings":";;;;;;;;;;;;AAeA,SAAS,kBAAkB;AAC3B,SAAS,KAAK,gBAAgB;AAqDvB,IAAM,aAAN,cAAyB,UAAM;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOV,YAAY,SAA2B,CAAC,GAAG;AAEzC,UAAM,gBAA+B;AAAA,MACnC,oBAAoB,IAAI;AAAA,MACxB,0BAA0B,WAAW,IAAI,IAAI,OAAO;AAAA,MACpD,iBAAiB;AAAA,MACjB,cAAa,oBAAI,KAAK,GAAE,YAAY,EAAE,MAAM,GAAG,EAAE,CAAC;AAAA;AAAA,MAClD,sBAAsB;AAAA;AAAA,IACxB;AAGA,QAAI,MAAM,OAAO;AACjB,QAAI;AACJ,QAAI,CAAC,KAAK;AACR,YAAM,aAAa,OAAO,cAAc;AACxC,mBAAa,eAAe,UAAU;AACtC,YAAM,UAAU,UAAU;AAC1B,oBAAc,uBAAuB,WAAW,aAAa;AAC7D,cAAQ,IAAI,gDAAuB,UAAU,mBAAS,WAAW,aAAa,KAAK,EAAE;AAAA,IACvF;AAGA,UAAM,cAA2B;AAAA,MAC/B;AAAA,MACA,OAAO,OAAO,SAAS,CAAC;AAAA,MACxB,UAAU;AAAA,MACV,eAAe,OAAO;AAAA,MACtB,MAAM,OAAO;AAAA,IACf;AAEA,UAAM,WAAW;AAGjB,SAAK,iBAAiB;AACtB,SAAK,UAAU;AACf,SAAK,aAAa,OAAO;AACzB,SAAK,cAAc,OAAO;AAC1B,SAAK,aAAa,OAAO;AACzB,SAAK,iBAAiB,aAAa;AAEnC,UAAM,uBAAuB,WAAW,uBAAuB,CAAC;AAChE,UAAM,kBAAkB,OAAO,cAAc,UAAU,OAAO,OAAO,cAAc,YAAY;AAC/F,QAAI,iBAAiB;AACnB,WAAK,cAAc,OAAO,OAAO,cAAc,WAC3C,IAAI,WAAW,OAAO,SAAS,IAC/B,IAAI,WAAW,QAAW,EAAE,gBAAgB,OAAO,kBAAkB,CAAC;AAC1E,UAAI,OAAO,YAAY;AACrB,aAAK,YAAY,cAAc,OAAO,UAAU;AAAA,MAClD;AACA,WAAK,IAAI,KAAK,WAAW;AAAA,IAC3B;AAGA,SAAK,IAAI,IAAI,qBAAqB,CAAC;AAGnC,SAAK,IAAI,IAAI,aAAa,OAAO,SAAS,CAAC;AAG3C,SAAK,IAAI,IAAI,gBAAgB,CAAC;AAG9B,SAAK,SAAS,EAAE,QAAQ,aAAa;AACrC,SAAK,SAAS,EAAE,QAAQ,aAAa;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA,EAKA,mBAAkC;AAChC,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,eAA2C;AACzC,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,gBAAqD;AACnD,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
ViewerWorker
|
|
4
|
+
} from "../chunk-FZGM6EMW.js";
|
|
5
|
+
import {
|
|
6
|
+
getDefaultUDSPath
|
|
7
|
+
} from "../chunk-TSASFMRF.js";
|
|
8
|
+
import "../chunk-BDS2QGZ5.js";
|
|
9
|
+
|
|
10
|
+
// src/cli/server.ts
|
|
11
|
+
var DEFAULT_PORT = 2026;
|
|
12
|
+
async function main() {
|
|
13
|
+
const port = parseInt(process.env.AGENTDEV_PORT || process.argv[2] || String(DEFAULT_PORT), 10);
|
|
14
|
+
const openBrowser = process.env.AGENTDEV_OPEN_BROWSER !== "false" && process.argv[3] !== "false";
|
|
15
|
+
const udsPath = process.env.AGENTDEV_UDS_PATH || process.argv[4];
|
|
16
|
+
console.log("=".repeat(50));
|
|
17
|
+
console.log("ViewerWorker \u670D\u52A1\u5668\u542F\u52A8\u4E2D...");
|
|
18
|
+
console.log(` HTTP \u7AEF\u53E3: ${port}`);
|
|
19
|
+
console.log(` UDS \u8DEF\u5F84: ${udsPath || getDefaultUDSPath()}`);
|
|
20
|
+
console.log(` \u81EA\u52A8\u6253\u5F00\u6D4F\u89C8\u5668: ${openBrowser ? "\u662F" : "\u5426"}`);
|
|
21
|
+
console.log("=".repeat(50));
|
|
22
|
+
const worker = new ViewerWorker(port, openBrowser, udsPath);
|
|
23
|
+
try {
|
|
24
|
+
await worker.start();
|
|
25
|
+
console.log("\n\u2713 \u670D\u52A1\u5668\u5DF2\u542F\u52A8!");
|
|
26
|
+
console.log(`
|
|
27
|
+
\u8C03\u8BD5\u9875\u9762: http://localhost:${port}`);
|
|
28
|
+
console.log("\n\u6309 Ctrl+C \u505C\u6B62\u670D\u52A1\u5668\n");
|
|
29
|
+
} catch (err) {
|
|
30
|
+
console.error("\n\u2717 \u670D\u52A1\u5668\u542F\u52A8\u5931\u8D25:", err);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
process.on("SIGINT", () => {
|
|
35
|
+
console.log("\n\n[Server] \u6B63\u5728\u505C\u6B62\u670D\u52A1\u5668...");
|
|
36
|
+
process.exit(0);
|
|
37
|
+
});
|
|
38
|
+
process.on("SIGTERM", () => {
|
|
39
|
+
console.log("\n\n[Server] \u6B63\u5728\u505C\u6B62\u670D\u52A1\u5668...");
|
|
40
|
+
process.exit(0);
|
|
41
|
+
});
|
|
42
|
+
main().catch((err) => {
|
|
43
|
+
console.error("[Server] \u672A\u5904\u7406\u7684\u9519\u8BEF:", err);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/cli/server.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * ViewerWorker 服务器启动程序\n *\n * 用途:独立启动调试查看器服务器\n * 运行:npm run server [port] [no-browser] [uds-path]\n *\n * 功能:\n * - 启动 ViewerWorker 独立进程\n * - 服务器运行期间可以被多个 Agent 连接\n * - Ctrl+C 关闭服务器\n *\n * 参数:\n * port - HTTP 端口(默认 2026)\n * no-browser - 不自动打开浏览器(传递字符串 \"false\")\n * uds-path - 自定义 UDS 路径(可选)\n *\n * 环境变量:\n * AGENTDEV_PORT - HTTP 端口(默认 2026)\n * AGENTDEV_OPEN_BROWSER - 是否打开浏览器(默认 true)\n * AGENTDEV_UDS_PATH - UDS 路径(默认自动检测平台)\n */\n\nimport { ViewerWorker } from '../core/viewer-worker.js';\nimport { getDefaultUDSPath } from '../core/types.js';\n\nconst DEFAULT_PORT = 2026;\n\nasync function main() {\n const port = parseInt(process.env.AGENTDEV_PORT || process.argv[2] || String(DEFAULT_PORT), 10);\n const openBrowser = process.env.AGENTDEV_OPEN_BROWSER !== 'false' && process.argv[3] !== 'false';\n const udsPath = process.env.AGENTDEV_UDS_PATH || process.argv[4];\n\n console.log('='.repeat(50));\n console.log('ViewerWorker 服务器启动中...');\n console.log(` HTTP 端口: ${port}`);\n console.log(` UDS 路径: ${udsPath || getDefaultUDSPath()}`);\n console.log(` 自动打开浏览器: ${openBrowser ? '是' : '否'}`);\n console.log('='.repeat(50));\n\n const worker = new ViewerWorker(port, openBrowser, udsPath);\n\n try {\n await worker.start();\n\n console.log('\\n✓ 服务器已启动!');\n console.log(`\\n调试页面: http://localhost:${port}`);\n console.log('\\n按 Ctrl+C 停止服务器\\n');\n\n // 保持运行,直到用户中断\n } catch (err) {\n console.error('\\n✗ 服务器启动失败:', err);\n process.exit(1);\n }\n}\n\n// 优雅退出\nprocess.on('SIGINT', () => {\n console.log('\\n\\n[Server] 正在停止服务器...');\n process.exit(0);\n});\n\nprocess.on('SIGTERM', () => {\n console.log('\\n\\n[Server] 正在停止服务器...');\n process.exit(0);\n});\n\nmain().catch((err) => {\n console.error('[Server] 未处理的错误:', err);\n process.exit(1);\n});\n"],"mappings":";;;;;;;;;;AA0BA,IAAM,eAAe;AAErB,eAAe,OAAO;AACpB,QAAM,OAAO,SAAS,QAAQ,IAAI,iBAAiB,QAAQ,KAAK,CAAC,KAAK,OAAO,YAAY,GAAG,EAAE;AAC9F,QAAM,cAAc,QAAQ,IAAI,0BAA0B,WAAW,QAAQ,KAAK,CAAC,MAAM;AACzF,QAAM,UAAU,QAAQ,IAAI,qBAAqB,QAAQ,KAAK,CAAC;AAE/D,UAAQ,IAAI,IAAI,OAAO,EAAE,CAAC;AAC1B,UAAQ,IAAI,sDAAwB;AACpC,UAAQ,IAAI,wBAAc,IAAI,EAAE;AAChC,UAAQ,IAAI,uBAAa,WAAW,kBAAkB,CAAC,EAAE;AACzD,UAAQ,IAAI,iDAAc,cAAc,WAAM,QAAG,EAAE;AACnD,UAAQ,IAAI,IAAI,OAAO,EAAE,CAAC;AAE1B,QAAM,SAAS,IAAI,aAAa,MAAM,aAAa,OAAO;AAE1D,MAAI;AACF,UAAM,OAAO,MAAM;AAEnB,YAAQ,IAAI,gDAAa;AACzB,YAAQ,IAAI;AAAA,6CAA4B,IAAI,EAAE;AAC9C,YAAQ,IAAI,kDAAoB;AAAA,EAGlC,SAAS,KAAK;AACZ,YAAQ,MAAM,wDAAgB,GAAG;AACjC,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;AAGA,QAAQ,GAAG,UAAU,MAAM;AACzB,UAAQ,IAAI,4DAAyB;AACrC,UAAQ,KAAK,CAAC;AAChB,CAAC;AAED,QAAQ,GAAG,WAAW,MAAM;AAC1B,UAAQ,IAAI,4DAAyB;AACrC,UAAQ,KAAK,CAAC;AAChB,CAAC;AAED,KAAK,EAAE,MAAM,CAAC,QAAQ;AACpB,UAAQ,MAAM,kDAAoB,GAAG;AACrC,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
ViewerWorker
|
|
4
|
+
} from "../chunk-FZGM6EMW.js";
|
|
5
|
+
import {
|
|
6
|
+
getDefaultUDSPath
|
|
7
|
+
} from "../chunk-TSASFMRF.js";
|
|
8
|
+
import "../chunk-BDS2QGZ5.js";
|
|
9
|
+
|
|
10
|
+
// src/cli/viewer.ts
|
|
11
|
+
var DEFAULT_PORT = 2026;
|
|
12
|
+
async function main() {
|
|
13
|
+
const udsPath = process.env.AGENTDEV_UDS_PATH || process.argv[4] || getDefaultUDSPath();
|
|
14
|
+
const port = parseInt(process.env.AGENTDEV_PORT || process.argv[2] || String(DEFAULT_PORT), 10);
|
|
15
|
+
const openBrowser = process.env.AGENTDEV_OPEN_BROWSER !== "false" && process.argv[3] !== "false";
|
|
16
|
+
console.log(`[Viewer Worker] \u6B63\u5728\u542F\u52A8...`);
|
|
17
|
+
console.log(`[Viewer Worker] UDS: ${udsPath}`);
|
|
18
|
+
console.log(`[Viewer Worker] HTTP: http://localhost:${port}`);
|
|
19
|
+
const worker = new ViewerWorker(port, openBrowser, udsPath);
|
|
20
|
+
try {
|
|
21
|
+
await worker.start();
|
|
22
|
+
console.log("[Viewer Worker] \u542F\u52A8\u6210\u529F");
|
|
23
|
+
} catch (err) {
|
|
24
|
+
console.error("[Viewer Worker] \u542F\u52A8\u5931\u8D25:", err);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
process.on("SIGINT", () => {
|
|
28
|
+
console.log("[Viewer Worker] \u6536\u5230\u9000\u51FA\u4FE1\u53F7\uFF0C\u6B63\u5728\u5173\u95ED...");
|
|
29
|
+
process.exit(0);
|
|
30
|
+
});
|
|
31
|
+
process.on("SIGTERM", () => {
|
|
32
|
+
console.log("[Viewer Worker] \u6536\u5230\u7EC8\u6B62\u4FE1\u53F7\uFF0C\u6B63\u5728\u5173\u95ED...");
|
|
33
|
+
process.exit(0);
|
|
34
|
+
});
|
|
35
|
+
process.on("uncaughtException", (err) => {
|
|
36
|
+
console.error("[Viewer Worker] \u672A\u6355\u83B7\u5F02\u5E38:", err);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
});
|
|
39
|
+
process.on("unhandledRejection", (reason) => {
|
|
40
|
+
console.error("[Viewer Worker] \u672A\u5904\u7406\u7684 Promise \u62D2\u7EDD:", reason);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
main();
|
|
45
|
+
//# sourceMappingURL=viewer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/cli/viewer.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * Viewer Worker Standalone CLI\n *\n * 独立启动 ViewerWorker 服务器的命令行工具\n *\n * 使用方法:\n * agentdev-viewer [port] [no-browser] [uds-path]\n *\n * 参数:\n * port - HTTP 端口(默认 2026)\n * no-browser - 不自动打开浏览器(传递 \"false\")\n * uds-path - 自定义 UDS 路径(可选)\n *\n * 环境变量:\n * AGENTDEV_UDS_PATH - UDS 路径(默认自动检测平台)\n * AGENTDEV_PORT - HTTP 端口(默认 2026)\n * AGENTDEV_OPEN_BROWSER - 是否打开浏览器(默认 true)\n */\n\nimport { ViewerWorker } from '../core/viewer-worker.js';\nimport { getDefaultUDSPath } from '../core/types.js';\n\nconst DEFAULT_PORT = 2026;\n\nasync function main() {\n const udsPath = process.env.AGENTDEV_UDS_PATH || process.argv[4] || getDefaultUDSPath();\n const port = parseInt(process.env.AGENTDEV_PORT || process.argv[2] || String(DEFAULT_PORT), 10);\n const openBrowser = process.env.AGENTDEV_OPEN_BROWSER !== 'false' && process.argv[3] !== 'false';\n\n console.log(`[Viewer Worker] 正在启动...`);\n console.log(`[Viewer Worker] UDS: ${udsPath}`);\n console.log(`[Viewer Worker] HTTP: http://localhost:${port}`);\n\n const worker = new ViewerWorker(port, openBrowser, udsPath);\n\n try {\n await worker.start();\n console.log('[Viewer Worker] 启动成功');\n } catch (err) {\n console.error('[Viewer Worker] 启动失败:', err);\n process.exit(1);\n }\n\n // 防止进程退出(保持运行)\n process.on('SIGINT', () => {\n console.log('[Viewer Worker] 收到退出信号,正在关闭...');\n process.exit(0);\n });\n\n process.on('SIGTERM', () => {\n console.log('[Viewer Worker] 收到终止信号,正在关闭...');\n process.exit(0);\n });\n\n // 添加未捕获异常处理\n process.on('uncaughtException', (err) => {\n console.error('[Viewer Worker] 未捕获异常:', err);\n process.exit(1);\n });\n\n process.on('unhandledRejection', (reason) => {\n console.error('[Viewer Worker] 未处理的 Promise 拒绝:', reason);\n process.exit(1);\n });\n}\n\nmain();\n"],"mappings":";;;;;;;;;;AAuBA,IAAM,eAAe;AAErB,eAAe,OAAO;AACpB,QAAM,UAAU,QAAQ,IAAI,qBAAqB,QAAQ,KAAK,CAAC,KAAK,kBAAkB;AACtF,QAAM,OAAO,SAAS,QAAQ,IAAI,iBAAiB,QAAQ,KAAK,CAAC,KAAK,OAAO,YAAY,GAAG,EAAE;AAC9F,QAAM,cAAc,QAAQ,IAAI,0BAA0B,WAAW,QAAQ,KAAK,CAAC,MAAM;AAEzF,UAAQ,IAAI,6CAAyB;AACrC,UAAQ,IAAI,wBAAwB,OAAO,EAAE;AAC7C,UAAQ,IAAI,0CAA0C,IAAI,EAAE;AAE5D,QAAM,SAAS,IAAI,aAAa,MAAM,aAAa,OAAO;AAE1D,MAAI;AACF,UAAM,OAAO,MAAM;AACnB,YAAQ,IAAI,0CAAsB;AAAA,EACpC,SAAS,KAAK;AACZ,YAAQ,MAAM,6CAAyB,GAAG;AAC1C,YAAQ,KAAK,CAAC;AAAA,EAChB;AAGA,UAAQ,GAAG,UAAU,MAAM;AACzB,YAAQ,IAAI,uFAAgC;AAC5C,YAAQ,KAAK,CAAC;AAAA,EAChB,CAAC;AAED,UAAQ,GAAG,WAAW,MAAM;AAC1B,YAAQ,IAAI,uFAAgC;AAC5C,YAAQ,KAAK,CAAC;AAAA,EAChB,CAAC;AAGD,UAAQ,GAAG,qBAAqB,CAAC,QAAQ;AACvC,YAAQ,MAAM,mDAA0B,GAAG;AAC3C,YAAQ,KAAK,CAAC;AAAA,EAChB,CAAC;AAED,UAAQ,GAAG,sBAAsB,CAAC,WAAW;AAC3C,YAAQ,MAAM,kEAAoC,MAAM;AACxD,YAAQ,KAAK,CAAC;AAAA,EAChB,CAAC;AACH;AAEA,KAAK;","names":[]}
|