@cicctencent/agent-core 0.1.1

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.
Files changed (134) hide show
  1. package/README.md +952 -0
  2. package/dist/agent/engine.d.ts +113 -0
  3. package/dist/agent/engine.d.ts.map +1 -0
  4. package/dist/agent/history-manager.d.ts +78 -0
  5. package/dist/agent/history-manager.d.ts.map +1 -0
  6. package/dist/agent/llm-caller.d.ts +58 -0
  7. package/dist/agent/llm-caller.d.ts.map +1 -0
  8. package/dist/agent/tool-executor.d.ts +95 -0
  9. package/dist/agent/tool-executor.d.ts.map +1 -0
  10. package/dist/agent/types.d.ts +128 -0
  11. package/dist/agent/types.d.ts.map +1 -0
  12. package/dist/agent/workflow.d.ts +74 -0
  13. package/dist/agent/workflow.d.ts.map +1 -0
  14. package/dist/context/collector.d.ts +12 -0
  15. package/dist/context/collector.d.ts.map +1 -0
  16. package/dist/context/manager.d.ts +16 -0
  17. package/dist/context/manager.d.ts.map +1 -0
  18. package/dist/context/types.d.ts +39 -0
  19. package/dist/context/types.d.ts.map +1 -0
  20. package/dist/hooks/types.d.ts +47 -0
  21. package/dist/hooks/types.d.ts.map +1 -0
  22. package/dist/index.d.ts +53 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/llm/anthropic-provider.d.ts +28 -0
  25. package/dist/llm/anthropic-provider.d.ts.map +1 -0
  26. package/dist/llm/factory.d.ts +19 -0
  27. package/dist/llm/factory.d.ts.map +1 -0
  28. package/dist/llm/ollama-provider.d.ts +13 -0
  29. package/dist/llm/ollama-provider.d.ts.map +1 -0
  30. package/dist/llm/openai-provider.d.ts +18 -0
  31. package/dist/llm/openai-provider.d.ts.map +1 -0
  32. package/dist/llm/provider.d.ts +7 -0
  33. package/dist/llm/provider.d.ts.map +1 -0
  34. package/dist/llm/types.d.ts +78 -0
  35. package/dist/llm/types.d.ts.map +1 -0
  36. package/dist/mcp/base-client.d.ts +50 -0
  37. package/dist/mcp/base-client.d.ts.map +1 -0
  38. package/dist/mcp/client.d.ts +27 -0
  39. package/dist/mcp/client.d.ts.map +1 -0
  40. package/dist/mcp/factory.d.ts +16 -0
  41. package/dist/mcp/factory.d.ts.map +1 -0
  42. package/dist/mcp/http-client.d.ts +24 -0
  43. package/dist/mcp/http-client.d.ts.map +1 -0
  44. package/dist/mcp/proxy-agent.d.ts +49 -0
  45. package/dist/mcp/proxy-agent.d.ts.map +1 -0
  46. package/dist/mcp/stdio-client.d.ts +16 -0
  47. package/dist/mcp/stdio-client.d.ts.map +1 -0
  48. package/dist/mcp/types.d.ts +60 -0
  49. package/dist/mcp/types.d.ts.map +1 -0
  50. package/dist/memory/checkpoint.d.ts +62 -0
  51. package/dist/memory/checkpoint.d.ts.map +1 -0
  52. package/dist/memory/extractor.d.ts +59 -0
  53. package/dist/memory/extractor.d.ts.map +1 -0
  54. package/dist/memory/persona.d.ts +38 -0
  55. package/dist/memory/persona.d.ts.map +1 -0
  56. package/dist/memory/pipeline.d.ts +50 -0
  57. package/dist/memory/pipeline.d.ts.map +1 -0
  58. package/dist/memory/prompts.d.ts +9 -0
  59. package/dist/memory/prompts.d.ts.map +1 -0
  60. package/dist/memory/recall.d.ts +66 -0
  61. package/dist/memory/recall.d.ts.map +1 -0
  62. package/dist/memory/scene.d.ts +49 -0
  63. package/dist/memory/scene.d.ts.map +1 -0
  64. package/dist/memory/types.d.ts +43 -0
  65. package/dist/memory/types.d.ts.map +1 -0
  66. package/dist/middleware/types.d.ts +52 -0
  67. package/dist/middleware/types.d.ts.map +1 -0
  68. package/dist/sandbox/types.d.ts +59 -0
  69. package/dist/sandbox/types.d.ts.map +1 -0
  70. package/dist/security/guard.d.ts +41 -0
  71. package/dist/security/guard.d.ts.map +1 -0
  72. package/dist/security/types.d.ts +36 -0
  73. package/dist/security/types.d.ts.map +1 -0
  74. package/dist/skill/manager.d.ts +95 -0
  75. package/dist/skill/manager.d.ts.map +1 -0
  76. package/dist/skill/router.d.ts +26 -0
  77. package/dist/skill/router.d.ts.map +1 -0
  78. package/dist/skill/types.d.ts +55 -0
  79. package/dist/skill/types.d.ts.map +1 -0
  80. package/dist/tool/delegate.d.ts +34 -0
  81. package/dist/tool/delegate.d.ts.map +1 -0
  82. package/dist/tool/registry.d.ts +24 -0
  83. package/dist/tool/registry.d.ts.map +1 -0
  84. package/dist/tool/types.d.ts +101 -0
  85. package/dist/tool/types.d.ts.map +1 -0
  86. package/dist/types.d.ts +150 -0
  87. package/dist/types.d.ts.map +1 -0
  88. package/dist/utils/token-counter.d.ts +22 -0
  89. package/dist/utils/token-counter.d.ts.map +1 -0
  90. package/package.json +42 -0
  91. package/src/agent/engine.ts +875 -0
  92. package/src/agent/history-manager.ts +323 -0
  93. package/src/agent/llm-caller.ts +383 -0
  94. package/src/agent/tool-executor.ts +713 -0
  95. package/src/agent/types.ts +136 -0
  96. package/src/agent/workflow.ts +339 -0
  97. package/src/context/collector.ts +59 -0
  98. package/src/context/manager.ts +40 -0
  99. package/src/context/types.ts +51 -0
  100. package/src/hooks/types.ts +77 -0
  101. package/src/index.ts +178 -0
  102. package/src/llm/anthropic-provider.ts +412 -0
  103. package/src/llm/factory.ts +34 -0
  104. package/src/llm/ollama-provider.ts +39 -0
  105. package/src/llm/openai-provider.ts +200 -0
  106. package/src/llm/provider.ts +15 -0
  107. package/src/llm/types.ts +91 -0
  108. package/src/mcp/base-client.ts +159 -0
  109. package/src/mcp/client.ts +81 -0
  110. package/src/mcp/factory.ts +45 -0
  111. package/src/mcp/http-client.ts +149 -0
  112. package/src/mcp/proxy-agent.ts +227 -0
  113. package/src/mcp/stdio-client.ts +104 -0
  114. package/src/mcp/types.ts +65 -0
  115. package/src/memory/checkpoint.ts +146 -0
  116. package/src/memory/extractor.ts +164 -0
  117. package/src/memory/persona.ts +106 -0
  118. package/src/memory/pipeline.ts +192 -0
  119. package/src/memory/prompts.ts +73 -0
  120. package/src/memory/recall.ts +217 -0
  121. package/src/memory/scene.ts +137 -0
  122. package/src/memory/types.ts +54 -0
  123. package/src/middleware/types.ts +62 -0
  124. package/src/sandbox/types.ts +185 -0
  125. package/src/security/guard.ts +249 -0
  126. package/src/security/types.ts +46 -0
  127. package/src/skill/manager.ts +420 -0
  128. package/src/skill/router.ts +158 -0
  129. package/src/skill/types.ts +67 -0
  130. package/src/tool/delegate.ts +105 -0
  131. package/src/tool/registry.ts +64 -0
  132. package/src/tool/types.ts +124 -0
  133. package/src/types.ts +188 -0
  134. package/src/utils/token-counter.ts +108 -0
@@ -0,0 +1,39 @@
1
+ import type { Message } from '../types.ts';
2
+ export interface EnvInfo {
3
+ /** 操作系统信息,e.g. "Linux 5.15.0 x86_64" */
4
+ os: string;
5
+ /** 平台标识 */
6
+ platform: string;
7
+ /** CPU 核心数 */
8
+ cpuCores: number;
9
+ /** 内存信息,e.g. "16G total, 8G available" */
10
+ memory: string;
11
+ /** 磁盘信息,e.g. "/dev/sda1 50G 80%" */
12
+ disk: string;
13
+ /** Shell 路径,e.g. "/bin/bash" */
14
+ shell: string;
15
+ /** 主机名 */
16
+ hostname?: string;
17
+ /** 当前用户 */
18
+ user?: string;
19
+ /** 自定义扩展(如 Docker 版本、K8s 版本等) */
20
+ custom?: Record<string, string>;
21
+ }
22
+ export interface BuildContextOptions {
23
+ /** 完整的系统提示词(由上层组装完成,core 不关心内容来源) */
24
+ systemPrompt: string;
25
+ /** 对话历史(由上层管理,core 仅负责插入到消息列表中) */
26
+ history?: Message[];
27
+ /** 用户当前输入 */
28
+ userMessage: string;
29
+ /** 额外系统提示片段(上层注入,追加到 systemPrompt 之后) */
30
+ extraSystemPrompt?: string;
31
+ }
32
+ /** 环境采集器接口(上层实现本地/远程采集) */
33
+ export interface EnvCollector {
34
+ /** 采集当前环境信息 */
35
+ collect(): Promise<EnvInfo>;
36
+ /** 将 EnvInfo 格式化为可注入 system prompt 的文本 */
37
+ format(info: EnvInfo): string;
38
+ }
39
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/context/types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAI3C,MAAM,WAAW,OAAO;IACtB,wCAAwC;IACxC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,oCAAoC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,UAAU;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iCAAiC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAID,MAAM,WAAW,mBAAmB;IAClC,qCAAqC;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,mCAAmC;IACnC,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;IACpB,aAAa;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,yCAAyC;IACzC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAID,2BAA2B;AAC3B,MAAM,WAAW,YAAY;IAC3B,eAAe;IACf,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5B,0CAA0C;IAC1C,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC;CAC/B"}
@@ -0,0 +1,47 @@
1
+ import type { Message, TokenUsage } from '../types.ts';
2
+ import type { ToolDefinition } from '../tool/types.ts';
3
+ export type HookEvent = 'before_tool' | 'after_tool' | 'before_ll_call' | 'after_ll_call' | 'on_iteration_start' | 'on_error' | 'on_complete';
4
+ /**
5
+ * Hook 处理器接收的上下文信息
6
+ * 不同事件携带不同的字段组合
7
+ */
8
+ export interface HookContext {
9
+ sessionId: string;
10
+ iteration: number;
11
+ traceId?: string;
12
+ tool?: string;
13
+ args?: Record<string, unknown>;
14
+ result?: string;
15
+ isError?: boolean;
16
+ duration?: number;
17
+ messages?: Message[];
18
+ tools?: ToolDefinition[];
19
+ response?: Message;
20
+ error?: string;
21
+ recoverable?: boolean;
22
+ totalIterations?: number;
23
+ usage?: TokenUsage;
24
+ }
25
+ /**
26
+ * Hook 处理器的返回值
27
+ * 仅 before_tool 和 after_tool 的返回值有实际效果
28
+ */
29
+ export interface HookResult {
30
+ /** before_tool: 阻止工具执行 */
31
+ block?: boolean;
32
+ /** block 时的原因(返回给 LLM) */
33
+ reason?: string;
34
+ /** before_tool: 修改工具参数(与原始 args 合并) */
35
+ modify?: Record<string, unknown>;
36
+ /** after_tool: 追加到工具结果末尾 */
37
+ inject?: string;
38
+ }
39
+ export interface Hook {
40
+ /** Hook 名称(用于日志和调试) */
41
+ name: string;
42
+ /** 监听的事件类型 */
43
+ event: HookEvent;
44
+ /** 处理器函数 */
45
+ handler: (ctx: HookContext) => Promise<HookResult | void>;
46
+ }
47
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/hooks/types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIvD,MAAM,MAAM,SAAS,GACjB,aAAa,GACb,YAAY,GACZ,gBAAgB,GAChB,eAAe,GACf,oBAAoB,GACpB,UAAU,GACV,aAAa,CAAC;AAIlB;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IAGjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAGnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,OAAO,CAAC;IAGtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB;AAID;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,0BAA0B;IAC1B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,0BAA0B;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAID,MAAM,WAAW,IAAI;IACnB,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,cAAc;IACd,KAAK,EAAE,SAAS,CAAC;IACjB,YAAY;IACZ,OAAO,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;CAC3D"}
@@ -0,0 +1,53 @@
1
+ export type { Message, MessageRole, ToolCall, AgentEvent, BaseEvent, ThinkingEvent, ToolCallEvent, ToolResultEvent, MessageEvent, DoneEvent, ErrorEvent, SteeringEvent, RetryEvent, AgentResult, AgentStatus, SessionContext, TokenUsage, ToolCallRecord, } from './types.ts';
2
+ export { AgentEngine } from './agent/engine.ts';
3
+ export { DEFAULT_COMPLEX_WORKFLOW_TEMPLATE, buildDebateInstructions, buildStructuredOutputInstruction, buildWorkflowDecisionMemory, formatDebateOutput, formatStructuredAgentOutput, formatWorkflowTemplateForPrompt, getWorkflowRoleStage, getWorkflowTemplate, parseDebateOutput, parseStructuredAgentOutput, wrapTaskWithWorkflowInstructions, } from './agent/workflow.ts';
4
+ export type { StructuredAgentOutput, WorkflowCheckpoint, WorkflowDecisionLog, WorkflowRole, WorkflowStageTemplate, WorkflowTemplate, DebateOutput } from './agent/workflow.ts';
5
+ export { HistoryManager } from './agent/history-manager.ts';
6
+ export { LLMCaller } from './agent/llm-caller.ts';
7
+ export { AgentToolExecutor } from './agent/tool-executor.ts';
8
+ export type { AgentConfig, RunOptions, RetryPolicy, ToolResultStore, OffloadEntry } from './agent/types.ts';
9
+ export type { LLMProvider, ModelConfig, ModelInfo, ChatParams, ChatResponse, ChatChunk, } from './llm/types.ts';
10
+ export { OpenAIProvider } from './llm/openai-provider.ts';
11
+ export { AnthropicProvider } from './llm/anthropic-provider.ts';
12
+ export { OllamaProvider } from './llm/ollama-provider.ts';
13
+ export { createLLMProvider, BUILTIN_PROVIDERS } from './llm/factory.ts';
14
+ export type { BuiltinProvider } from './llm/factory.ts';
15
+ export { ContextManager } from './context/manager.ts';
16
+ export { LocalEnvCollector } from './context/collector.ts';
17
+ export type { BuildContextOptions, EnvInfo, EnvCollector, } from './context/types.ts';
18
+ export { SkillManager } from './skill/manager.ts';
19
+ export { SkillRouter } from './skill/router.ts';
20
+ export type { Skill, SkillManifest, SkillSource, RouteResult, RouteStrategy, MatchType, } from './skill/types.ts';
21
+ export { ToolRegistry } from './tool/registry.ts';
22
+ export { createDelegateTool } from './tool/delegate.ts';
23
+ export type { SubAgentRunner } from './tool/delegate.ts';
24
+ export type { ToolDefinition, ToolExecutor, ToolContext, SubAgentEventEmitter, WidgetEventEmitter, ArtifactEventEmitter, ArtifactData, RegisteredTool, ToolCategory, ShellExecutor, FileSystemExecutor, } from './tool/types.ts';
25
+ export { registerMCPTools, MCP_TOOL_PREFIX, buildMCPToolName, sanitizeForToolName } from './mcp/client.ts';
26
+ export { createMCPClient, registerTransport } from './mcp/factory.ts';
27
+ export type { TransportFactory } from './mcp/factory.ts';
28
+ export { MCPClientBase } from './mcp/base-client.ts';
29
+ export { StdioMCPClient } from './mcp/stdio-client.ts';
30
+ export { HttpMCPClient } from './mcp/http-client.ts';
31
+ export { resolveProxyAgentForCategory, resolveProxyUrlForCategory, getSystemProxyUrl, clearSystemProxyCache, getWindowsSystemProxy, DEFAULT_PROXY_SETTINGS, } from './mcp/proxy-agent.ts';
32
+ export type { ProxyMode, ProxyCategoryConfig, ProxySettings, } from './mcp/proxy-agent.ts';
33
+ export type { MCPClient, MCPServerConfig, MCPTransport, } from './mcp/types.ts';
34
+ export { SecurityGuard } from './security/guard.ts';
35
+ export type { SanitizeResult, SecurityRule, SecurityPolicy, Severity, } from './security/types.ts';
36
+ export type { Sandbox, SandboxConfig, SandboxManager, ScriptLanguage, } from './sandbox/types.ts';
37
+ export { SANDBOX_BLOCKED_COMMANDS, SANDBOX_SAFE_ENV_KEYS, DEFAULT_SANDBOX_CONFIG } from './sandbox/types.ts';
38
+ export type { Hook, HookEvent, HookContext, HookResult, } from './hooks/types.ts';
39
+ export type { Middleware, MiddlewareContext, } from './middleware/types.ts';
40
+ export type { MemoryEntry, MemoryLayer, MemoryServiceLike, } from './memory/types.ts';
41
+ export { MemoryExtractor } from './memory/extractor.ts';
42
+ export type { AtomFact, ExtractorOptions } from './memory/extractor.ts';
43
+ export { SceneAggregator } from './memory/scene.ts';
44
+ export type { SceneBlock, SceneAggregatorOptions } from './memory/scene.ts';
45
+ export { PersonaGenerator } from './memory/persona.ts';
46
+ export type { PersonaFacet, PersonaGeneratorOptions } from './memory/persona.ts';
47
+ export { MemoryCheckpoint, getMemoryCheckpoint, resetMemoryCheckpoint } from './memory/checkpoint.ts';
48
+ export type { CheckpointData } from './memory/checkpoint.ts';
49
+ export { MemoryRecallEngine, formatRecallForPrompt } from './memory/recall.ts';
50
+ export type { RecallResult, ScoredMemoryEntry, RecallOptions } from './memory/recall.ts';
51
+ export { MemoryPipeline } from './memory/pipeline.ts';
52
+ export type { PipelineOptions, PipelineResult } from './memory/pipeline.ts';
53
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,YAAY,EACV,OAAO,EACP,WAAW,EACX,QAAQ,EACR,UAAU,EACV,SAAS,EACT,aAAa,EACb,aAAa,EACb,eAAe,EACf,YAAY,EACZ,SAAS,EACT,UAAU,EACV,aAAa,EACb,UAAU,EACV,WAAW,EACX,WAAW,EACX,cAAc,EACd,UAAU,EACV,cAAc,GACf,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EACL,iCAAiC,EACjC,uBAAuB,EACvB,gCAAgC,EAChC,2BAA2B,EAC3B,kBAAkB,EAClB,2BAA2B,EAC3B,+BAA+B,EAC/B,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,0BAA0B,EAC1B,gCAAgC,GACjC,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,YAAY,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC/K,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAG5G,YAAY,EACV,WAAW,EACX,WAAW,EACX,SAAS,EACT,UAAU,EACV,YAAY,EACZ,SAAS,GACV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,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O,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AACtG,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC/E,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACzF,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @file Anthropic Claude LLM Provider
3
+ * @description 实现 Anthropic Messages API,支持 Claude 系列模型,
4
+ * 内部自动完成 OpenAI 格式 ↔ Anthropic 格式的双向转换
5
+ */
6
+ import type { LLMProvider, ModelConfig, ModelInfo, ChatParams, ChatResponse, ChatChunk } from './types.ts';
7
+ export declare class AnthropicProvider implements LLMProvider {
8
+ private config;
9
+ constructor(config: ModelConfig);
10
+ getModel(): ModelInfo;
11
+ ping(): Promise<boolean>;
12
+ chat(params: ChatParams): Promise<ChatResponse>;
13
+ chatStream(params: ChatParams): AsyncGenerator<ChatChunk>;
14
+ /** 更新配置 */
15
+ updateConfig(updates: Partial<ModelConfig>): void;
16
+ /**
17
+ * 将 OpenAI 格式消息转换为 Anthropic 格式
18
+ * - system 消息提取为单独的 system 字段
19
+ * - tool 消息转换为 user 消息中的 tool_result 块
20
+ * - assistant 的 tool_calls 转换为 tool_use 块
21
+ */
22
+ private convertMessages;
23
+ private convertTools;
24
+ private buildRequestBody;
25
+ private parseResponse;
26
+ private doRequest;
27
+ }
28
+ //# sourceMappingURL=anthropic-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-provider.d.ts","sourceRoot":"","sources":["../../src/llm/anthropic-provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AA+C3G,qBAAa,iBAAkB,YAAW,WAAW;IACnD,OAAO,CAAC,MAAM,CAAkE;gBAEpE,MAAM,EAAE,WAAW;IAY/B,QAAQ,IAAI,SAAS;IAUf,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAexB,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;IAa9C,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,cAAc,CAAC,SAAS,CAAC;IAkIhE,WAAW;IACX,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI;IAMjD;;;;;OAKG;IACH,OAAO,CAAC,eAAe;IAiEvB,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,gBAAgB;IAqBxB,OAAO,CAAC,aAAa;YAwCP,SAAS;CA2BxB"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @file LLM Provider 工厂
3
+ * @description 根据 ModelConfig.provider 自动创建对应的 LLMProvider 实例
4
+ * 支持 'openai' | 'anthropic' | 'ollama' 及任意 OpenAI 兼容供应商
5
+ */
6
+ import type { ModelConfig, LLMProvider } from './types.ts';
7
+ /** 已注册的供应商名称集合 */
8
+ export declare const BUILTIN_PROVIDERS: readonly ["openai", "anthropic", "ollama"];
9
+ export type BuiltinProvider = (typeof BUILTIN_PROVIDERS)[number];
10
+ /**
11
+ * 根据 config.provider 创建对应的 LLMProvider
12
+ *
13
+ * - 'openai' → OpenAIProvider
14
+ * - 'anthropic' → AnthropicProvider
15
+ * - 'ollama' → OllamaProvider
16
+ * - 其他任意字符串 → OpenAIProvider(OpenAI 兼容端点,如 DeepSeek / vLLM / Together 等)
17
+ */
18
+ export declare function createLLMProvider(config: ModelConfig): LLMProvider;
19
+ //# sourceMappingURL=factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/llm/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAK3D,kBAAkB;AAClB,eAAO,MAAM,iBAAiB,4CAA6C,CAAC;AAC5E,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAUlE"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @file Ollama LLM Provider
3
+ * @description 继承 OpenAIProvider,对接 Ollama 本地推理服务
4
+ * Ollama 原生支持 OpenAI 兼容接口(/v1/chat/completions)
5
+ * 默认地址 http://localhost:11434/v1
6
+ */
7
+ import type { ModelConfig, ModelInfo } from './types.ts';
8
+ import { OpenAIProvider } from './openai-provider.ts';
9
+ export declare class OllamaProvider extends OpenAIProvider {
10
+ constructor(config: ModelConfig);
11
+ getModel(): ModelInfo;
12
+ }
13
+ //# sourceMappingURL=ollama-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ollama-provider.d.ts","sourceRoot":"","sources":["../../src/llm/ollama-provider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,qBAAa,cAAe,SAAQ,cAAc;gBAEpC,MAAM,EAAE,WAAW;IAW/B,QAAQ,IAAI,SAAS;CAetB"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @file OpenAI 兼容 LLM Provider
3
+ * @description 使用原生 fetch 实现,支持任意 OpenAI 兼容端点(OpenAI / DeepSeek / Ollama / vLLM 等)
4
+ */
5
+ import type { LLMProvider, ModelConfig, ModelInfo, ChatParams, ChatResponse, ChatChunk } from './types.ts';
6
+ export declare class OpenAIProvider implements LLMProvider {
7
+ protected config: Required<Pick<ModelConfig, 'provider' | 'model'>> & ModelConfig;
8
+ constructor(config: ModelConfig);
9
+ getModel(): ModelInfo;
10
+ ping(): Promise<boolean>;
11
+ chat(params: ChatParams): Promise<ChatResponse>;
12
+ chatStream(params: ChatParams): AsyncGenerator<ChatChunk>;
13
+ /** 更新配置(如 API Key 变更后) */
14
+ updateConfig(updates: Partial<ModelConfig>): void;
15
+ protected buildRequestBody(params: ChatParams, stream: boolean): Record<string, any>;
16
+ protected doRequest(body: Record<string, any>, signal?: AbortSignal): Promise<Response>;
17
+ }
18
+ //# sourceMappingURL=openai-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-provider.d.ts","sourceRoot":"","sources":["../../src/llm/openai-provider.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG3G,qBAAa,cAAe,YAAW,WAAW;IAChD,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,GAAG,OAAO,CAAC,CAAC,GAAG,WAAW,CAAC;gBAEtE,MAAM,EAAE,WAAW;IAY/B,QAAQ,IAAI,SAAS;IAUf,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAaxB,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;IAyB9C,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,cAAc,CAAC,SAAS,CAAC;IAqEhE,0BAA0B;IAC1B,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI;IAMjD,SAAS,CAAC,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;cAyBpE,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;CA2B9F"}
@@ -0,0 +1,7 @@
1
+ export type { LLMProvider, ModelConfig, ModelInfo, ChatParams, ChatResponse, ChatChunk } from './types.ts';
2
+ export { OpenAIProvider } from './openai-provider.ts';
3
+ export { AnthropicProvider } from './anthropic-provider.ts';
4
+ export { OllamaProvider } from './ollama-provider.ts';
5
+ export { createLLMProvider, BUILTIN_PROVIDERS } from './factory.ts';
6
+ export type { BuiltinProvider } from './factory.ts';
7
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/llm/provider.ts"],"names":[],"mappings":"AAKA,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG3G,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGtD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACpE,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,78 @@
1
+ import type { Message, TokenUsage } from '../types.ts';
2
+ import type { ToolDefinition } from '../tool/types.ts';
3
+ import type { Dispatcher } from 'undici';
4
+ export interface ModelConfig {
5
+ /** 供应商标识:'openai' | 'anthropic' | 'azure' | 'ollama' | 自定义 */
6
+ provider: string;
7
+ /** 模型名称 */
8
+ model: string;
9
+ /** API Key */
10
+ apiKey?: string;
11
+ /** API Base URL(自定义端点) */
12
+ baseUrl?: string;
13
+ /** 温度参数,默认 0.7 */
14
+ temperature?: number;
15
+ /** 最大输出 token 数 */
16
+ maxTokens?: number;
17
+ /** 请求超时(毫秒) */
18
+ timeout?: number;
19
+ /** 供应商特定参数透传 */
20
+ extra?: Record<string, unknown>;
21
+ /** 网络代理 dispatcher(运行时注入,不持久化) */
22
+ proxy?: Dispatcher;
23
+ }
24
+ export interface ModelInfo {
25
+ provider: string;
26
+ model: string;
27
+ contextWindow: number;
28
+ supportsTools: boolean;
29
+ supportsStreaming: boolean;
30
+ }
31
+ /** LLM 推理请求参数 */
32
+ export interface ChatParams {
33
+ messages: Message[];
34
+ /** 可用工具列表(OpenAI Function Calling 格式) */
35
+ tools?: ToolDefinition[];
36
+ /** 工具调用策略 */
37
+ toolChoice?: 'auto' | 'none' | {
38
+ type: 'function';
39
+ function: {
40
+ name: string;
41
+ };
42
+ };
43
+ /** 覆盖 ModelConfig 中的 temperature */
44
+ temperature?: number;
45
+ /** 覆盖 ModelConfig 中的 maxTokens */
46
+ maxTokens?: number;
47
+ /** 中止信号 */
48
+ abortSignal?: AbortSignal;
49
+ }
50
+ /** LLM 推理响应 */
51
+ export interface ChatResponse {
52
+ choices: Array<{
53
+ message: Message;
54
+ /** 结束原因:'stop' | 'tool_calls' | 'length' | 'content_filter' */
55
+ finish_reason: string;
56
+ }>;
57
+ usage?: TokenUsage;
58
+ }
59
+ /** 流式响应片段 */
60
+ export interface ChatChunk {
61
+ /** 增量内容 */
62
+ delta: Partial<Message>;
63
+ finish_reason?: string;
64
+ /** Token 使用统计(仅最后一个 chunk 可能包含) */
65
+ usage?: TokenUsage;
66
+ }
67
+ /** LLM 供应商统一接口 */
68
+ export interface LLMProvider {
69
+ /** 非流式推理 */
70
+ chat(params: ChatParams): Promise<ChatResponse>;
71
+ /** 流式推理(返回 AsyncGenerator 逐片段推送) */
72
+ chatStream(params: ChatParams): AsyncGenerator<ChatChunk>;
73
+ /** 获取当前模型信息 */
74
+ getModel(): ModelInfo;
75
+ /** 测试连接是否正常 */
76
+ ping(): Promise<boolean>;
77
+ }
78
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/llm/types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAIzC,MAAM,WAAW,WAAW;IAC1B,8DAA8D;IAC9D,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW;IACX,KAAK,EAAE,MAAM,CAAC;IACd,cAAc;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0BAA0B;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kBAAkB;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mBAAmB;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,kCAAkC;IAClC,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,OAAO,CAAC;IACvB,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAID,iBAAiB;AACjB,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,yCAAyC;IACzC,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;IACzB,aAAa;IACb,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG;QAAE,IAAI,EAAE,UAAU,CAAC;QAAC,QAAQ,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;IAChF,oCAAoC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW;IACX,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED,eAAe;AACf,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,KAAK,CAAC;QACb,OAAO,EAAE,OAAO,CAAC;QACjB,+DAA+D;QAC/D,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC,CAAC;IACH,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB;AAED,aAAa;AACb,MAAM,WAAW,SAAS;IACxB,WAAW;IACX,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mCAAmC;IACnC,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB;AAID,kBAAkB;AAClB,MAAM,WAAW,WAAW;IAC1B,YAAY;IACZ,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAEhD,oCAAoC;IACpC,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC;IAE1D,eAAe;IACf,QAAQ,IAAI,SAAS,CAAC;IAEtB,eAAe;IACf,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1B"}
@@ -0,0 +1,50 @@
1
+ import type { MCPClient, MCPServerConfig } from './types.ts';
2
+ import type { ToolDefinition } from '../tool/types.ts';
3
+ /** JSON-RPC 请求 */
4
+ interface JsonRpcRequest {
5
+ jsonrpc: '2.0';
6
+ id: number;
7
+ method: string;
8
+ params?: Record<string, unknown>;
9
+ }
10
+ /** JSON-RPC 响应 */
11
+ interface JsonRpcResponse {
12
+ jsonrpc: '2.0';
13
+ id: number;
14
+ result?: unknown;
15
+ error?: {
16
+ code: number;
17
+ message: string;
18
+ data?: unknown;
19
+ };
20
+ }
21
+ /**
22
+ * MCPClient 抽象基类
23
+ * 子类只需实现 send() 和 doConnect() / doDisconnect()
24
+ */
25
+ export declare abstract class MCPClientBase implements MCPClient {
26
+ protected config: MCPServerConfig;
27
+ protected connected: boolean;
28
+ private requestId;
29
+ /** 等待响应的 Promise 队列:id → { resolve, reject, timer } */
30
+ private pending;
31
+ /** 建立物理连接 */
32
+ protected abstract doConnect(config: MCPServerConfig): Promise<void>;
33
+ /** 断开物理连接 */
34
+ protected abstract doDisconnect(): void;
35
+ /** 发送 JSON-RPC 消息到 MCP 服务端 */
36
+ protected abstract send(request: JsonRpcRequest): void;
37
+ connect(config: MCPServerConfig): Promise<void>;
38
+ listTools(): Promise<ToolDefinition[]>;
39
+ callTool(name: string, args: Record<string, unknown>): Promise<string>;
40
+ disconnect(): void;
41
+ isConnected(): boolean;
42
+ /** 发送 JSON-RPC 请求并等待响应 */
43
+ protected call(method: string, params?: Record<string, unknown>): Promise<unknown>;
44
+ /** 发送 JSON-RPC 通知(无 id,无响应) */
45
+ protected notify(method: string, params?: Record<string, unknown>): void;
46
+ /** 子类收到 JSON-RPC 响应时调用此方法 */
47
+ protected handleResponse(data: JsonRpcResponse): void;
48
+ }
49
+ export {};
50
+ //# sourceMappingURL=base-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-client.d.ts","sourceRoot":"","sources":["../../src/mcp/base-client.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,kBAAkB;AAClB,UAAU,cAAc;IACtB,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CA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AM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAQxE,6BAA6B;IAC7B,SAAS,CAAC,cAAc,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI;CAatD"}
@@ -0,0 +1,27 @@
1
+ import type { MCPClient } from './types.ts';
2
+ import type { ToolRegistry } from '../tool/registry.ts';
3
+ /** MCP 工具名前缀,用于与 builtin/skill 等工具区分 */
4
+ export declare const MCP_TOOL_PREFIX = "mcp_";
5
+ /**
6
+ * 将名称中的非安全字符替换为下划线,确保可安全用于工具名拼接
7
+ */
8
+ export declare function sanitizeForToolName(name: string): string;
9
+ /**
10
+ * 构建带命名空间的 MCP 工具名
11
+ *
12
+ * - 连接器工具:`mcp_{connectorId}_{serverName}_{toolName}`
13
+ * - 独立工具:`mcp_{serverName}_{toolName}`
14
+ *
15
+ * 命名空间从根源上解决多 MCP 服务器工具名冲突问题。
16
+ */
17
+ export declare function buildMCPToolName(toolName: string, serverName: string, connectorId?: string): string;
18
+ /**
19
+ * 将 MCP 服务的远程工具批量注册到 ToolRegistry
20
+ *
21
+ * 工具名自动添加命名空间前缀 `mcp_[{connectorId}_]{serverName}_{toolName}`,
22
+ * 避免多 MCP 服务器间工具名冲突。调用 MCP 服务时使用原始名字。
23
+ *
24
+ * @param connectorId 连接器 ID(公有 MCP 服务器传 undefined,连接器私有传连接器 ID)
25
+ */
26
+ export declare function registerMCPTools(registry: ToolRegistry, mcpClient: MCPClient, serverName: string, connectorId?: string, serverId?: number | string): Promise<void>;
27
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/mcp/client.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,wCAAwC;AACxC,eAAO,MAAM,eAAe,SAAS,CAAC;AAEtC;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKxD;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAQnG;AAED;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,MAAM,EAClB,WAAW,CAAC,EAAE,MAAM,EACpB,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GACzB,OAAO,CAAC,IAAI,CAAC,CA4Bf"}
@@ -0,0 +1,16 @@
1
+ import type { MCPClient, MCPServerConfig } from './types.ts';
2
+ /** 自定义 transport 工厂函数签名 */
3
+ export type TransportFactory = () => MCPClient;
4
+ /**
5
+ * 注册自定义 transport 工厂
6
+ * 上层应用通过此方法扩展 core 层不内置的 transport 类型(如 api-bridge)
7
+ */
8
+ export declare function registerTransport(transport: string, factory: TransportFactory): void;
9
+ /**
10
+ * 根据 MCPServerConfig.transport 创建对应的 MCPClient 实例
11
+ *
12
+ * 内置支持:stdio / http / sse
13
+ * 自定义 transport:通过 registerTransport 注册后支持
14
+ */
15
+ export declare function createMCPClient(config: MCPServerConfig): MCPClient;
16
+ //# sourceMappingURL=factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/mcp/factory.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAI7D,2BAA2B;AAC3B,MAAM,MAAM,gBAAgB,GAAG,MAAM,SAAS,CAAC;AAK/C;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAGpF;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS,CAclE"}
@@ -0,0 +1,24 @@
1
+ import { MCPClientBase } from './base-client.ts';
2
+ import type { MCPServerConfig } from './types.ts';
3
+ export declare class HttpMCPClient extends MCPClientBase {
4
+ private endpoint;
5
+ private sessionId?;
6
+ private dispatcher?;
7
+ /** 用户自定义请求头(如 Authorization) */
8
+ private customHeaders?;
9
+ /** 结构化鉴权配置 */
10
+ private authConfig?;
11
+ protected doConnect(config: MCPServerConfig): Promise<void>;
12
+ protected doDisconnect(): void;
13
+ /** 根据 auth 配置生成鉴权请求头 */
14
+ private buildAuthHeaders;
15
+ protected send(request: {
16
+ jsonrpc: string;
17
+ id: number;
18
+ method: string;
19
+ params?: Record<string, unknown>;
20
+ }): void;
21
+ /** 解析 SSE 文本块中的 JSON-RPC 响应 */
22
+ private parseSSE;
23
+ }
24
+ //# sourceMappingURL=http-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../src/mcp/http-client.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAIlD,qBAAa,aAAc,SAAQ,aAAa;IAC9C,OAAO,CAAC,QAAQ,CAAM;IACtB,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,UAAU,CAAC,CAAa;IAChC,gCAAgC;IAChC,OAAO,CAAC,aAAa,CAAC,CAAyB;IAC/C,cAAc;IACd,OAAO,CAAC,UAAU,CAAC,CAAiD;cAEpD,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAUjE,SAAS,CAAC,YAAY,IAAI,IAAI;IAW9B,wBAAwB;IACxB,OAAO,CAAC,gBAAgB;IAkBxB,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,GAAG,IAAI;IAuEhH,+BAA+B;IAC/B,OAAO,CAAC,QAAQ;CAkBjB"}
@@ -0,0 +1,49 @@
1
+ import { type Dispatcher } from 'undici';
2
+ /** 代理模式:system=系统代理, custom=自定义, direct=直连 */
3
+ export type ProxyMode = 'system' | 'custom' | 'direct';
4
+ /** 单分类代理配置 */
5
+ export interface ProxyCategoryConfig {
6
+ mode: ProxyMode;
7
+ /** mode='custom' 时的代理 URL */
8
+ url?: string;
9
+ }
10
+ /** 分类代理设置(LLM / MCP / Fetch 各自独立) */
11
+ export interface ProxySettings {
12
+ llm: ProxyCategoryConfig;
13
+ mcp: ProxyCategoryConfig;
14
+ fetch: ProxyCategoryConfig;
15
+ }
16
+ /** 默认代理设置:全部分类走系统代理 */
17
+ export declare const DEFAULT_PROXY_SETTINGS: ProxySettings;
18
+ /**
19
+ * 从 Windows 注册表读取系统代理配置
20
+ * 仅 Windows 平台生效,其他平台返回 undefined
21
+ * 结果缓存,避免重复查询注册表
22
+ */
23
+ export declare function getWindowsSystemProxy(): string | undefined;
24
+ /** 清除系统代理缓存(设置变更时可调用) */
25
+ export declare function clearSystemProxyCache(): void;
26
+ /**
27
+ * 获取系统代理 URL
28
+ * 优先级:环境变量 HTTPS_PROXY / HTTP_PROXY / ALL_PROXY > macOS scutil > Windows 注册表
29
+ */
30
+ export declare function getSystemProxyUrl(): string | undefined;
31
+ /**
32
+ * 根据分类代理配置创建 dispatcher
33
+ *
34
+ * - `mode='system'`:自动检测系统代理(环境变量 + Windows 注册表)
35
+ * - `mode='custom'`:使用用户指定的代理 URL
36
+ * - `mode='direct'`:不走代理,返回 undefined
37
+ *
38
+ * @param category 分类代理配置
39
+ * @param label 日志标签(如 'LLM', 'MCP', 'Fetch')
40
+ * @returns dispatcher 实例,无代理时返回 undefined
41
+ */
42
+ export declare function resolveProxyAgentForCategory(category?: ProxyCategoryConfig, label?: string): Dispatcher | undefined;
43
+ /**
44
+ * 获取分类代理的有效 URL(用于 axios 等不支持 undici Dispatcher 的场景)
45
+ *
46
+ * @returns 代理 URL 字符串,无代理时返回 undefined
47
+ */
48
+ export declare function resolveProxyUrlForCategory(category?: ProxyCategoryConfig): string | undefined;
49
+ //# sourceMappingURL=proxy-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy-agent.d.ts","sourceRoot":"","sources":["../../src/mcp/proxy-agent.ts"],"names":[],"mappings":"AAIA,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,QAAQ,CAAC;AAMrD,8CAA8C;AAC9C,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEvD,cAAc;AACd,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,SAAS,CAAC;IAChB,6BAA6B;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,qCAAqC;AACrC,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,mBAAmB,CAAC;IACzB,GAAG,EAAE,mBAAmB,CAAC;IACzB,KAAK,EAAE,mBAAmB,CAAC;CAC5B;AAED,uBAAuB;AACvB,eAAO,MAAM,sBAAsB,EAAE,aAIpC,CAAC;AAkDF;;;;GAIG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,GAAG,SAAS,CAkC1D;AAED,yBAAyB;AACzB,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,GAAG,SAAS,CAStD;AA2BD;;;;;;;;;;GAUG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,CAAC,EAAE,mBAAmB,EAC9B,KAAK,SAAU,GACd,UAAU,GAAG,SAAS,CAyBxB;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,QAAQ,CAAC,EAAE,mBAAmB,GAAG,MAAM,GAAG,SAAS,CAY7F"}
@@ -0,0 +1,16 @@
1
+ import { MCPClientBase } from './base-client.ts';
2
+ import type { MCPServerConfig } from './types.ts';
3
+ export declare class StdioMCPClient extends MCPClientBase {
4
+ private process;
5
+ private buffer;
6
+ protected doConnect(config: MCPServerConfig): Promise<void>;
7
+ protected doDisconnect(): void;
8
+ protected send(request: {
9
+ jsonrpc: string;
10
+ id: number;
11
+ method: string;
12
+ params?: Record<string, unknown>;
13
+ }): void;
14
+ private flushBuffer;
15
+ }
16
+ //# sourceMappingURL=stdio-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stdio-client.d.ts","sourceRoot":"","sources":["../../src/mcp/stdio-client.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,qBAAa,cAAe,SAAQ,aAAa;IAC/C,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,MAAM,CAAM;cAEJ,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAiDjE,SAAS,CAAC,YAAY,IAAI,IAAI;IAQ9B,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,GAAG,IAAI;IAgBhH,OAAO,CAAC,WAAW;CAkBpB"}
@@ -0,0 +1,60 @@
1
+ import type { ToolDefinition } from '../tool/types.ts';
2
+ import type { ProxyCategoryConfig } from './proxy-agent.ts';
3
+ export type MCPTransport = 'stdio' | 'http' | 'sse' | 'streamableHttp' | (string & {});
4
+ export interface MCPServerConfig {
5
+ name: string;
6
+ transport: MCPTransport;
7
+ /** stdio 模式:启动命令 */
8
+ command?: string;
9
+ /** stdio 模式:命令参数 */
10
+ args?: string[];
11
+ /** stdio 模式:环境变量 */
12
+ env?: Record<string, string>;
13
+ /** HTTP/SSE/StreamableHTTP 模式:服务端点 */
14
+ endpoint?: string;
15
+ /** HTTP/SSE/StreamableHTTP 模式:自定义请求头(如 Authorization) */
16
+ headers?: Record<string, string>;
17
+ /** HTTP/SSE/StreamableHTTP 模式:结构化鉴权配置(bearer/basic/apiKey/custom) */
18
+ auth?: {
19
+ type: 'bearer' | 'basic' | 'apiKey' | 'custom';
20
+ value: string;
21
+ name?: string;
22
+ };
23
+ /** 请求超时(毫秒) */
24
+ timeout?: number;
25
+ /** 自动重连配置 */
26
+ autoReconnect?: boolean | {
27
+ maxRetries?: number;
28
+ interval?: number;
29
+ };
30
+ /**
31
+ * 分类代理配置(支持 system / custom / direct 三种模式)
32
+ *
33
+ * 由上层应用(如 workspace settings)传入对应的 ProxyCategoryConfig,
34
+ * 客户端根据 mode 自动创建 dispatcher。
35
+ */
36
+ proxyCategory?: ProxyCategoryConfig;
37
+ /** 扩展配置(自定义 transport 的专属数据统一放在此处) */
38
+ extra?: Record<string, unknown>;
39
+ }
40
+ export interface MCPClient {
41
+ /** 连接 MCP 服务 */
42
+ connect(config: MCPServerConfig): Promise<void>;
43
+ /** 发现远程工具列表 */
44
+ listTools(): Promise<ToolDefinition[]>;
45
+ /** 调用远程工具 */
46
+ callTool(name: string, args: Record<string, unknown>): Promise<string>;
47
+ /** 发现远程资源列表(可选能力) */
48
+ listResources?(): Promise<Array<{
49
+ uri: string;
50
+ name: string;
51
+ description?: string;
52
+ }>>;
53
+ /** 读取远程资源(可选能力) */
54
+ readResource?(uri: string): Promise<string>;
55
+ /** 断开连接 */
56
+ disconnect(): void;
57
+ /** 连接状态 */
58
+ isConnected(): boolean;
59
+ }
60
+ //# sourceMappingURL=types.d.ts.map