@huyooo/ai-chat-core 0.2.45 → 0.3.3
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/dist/adapter/index.d.ts +11 -0
- package/dist/adapter/index.d.ts.map +1 -0
- package/dist/adapter/model-adapter.d.ts +25 -0
- package/dist/adapter/model-adapter.d.ts.map +1 -0
- package/dist/adapter/model-options.d.ts +53 -0
- package/dist/adapter/model-options.d.ts.map +1 -0
- package/dist/adapter/types.d.ts +28 -0
- package/dist/adapter/types.d.ts.map +1 -0
- package/dist/chat-runtime.d.ts +96 -0
- package/dist/chat-runtime.d.ts.map +1 -0
- package/dist/constants.d.ts +12 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/events.d.ts +605 -1
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +1 -1
- package/dist/extension/index.d.ts +9 -0
- package/dist/extension/index.d.ts.map +1 -0
- package/dist/extension/types.d.ts +46 -0
- package/dist/extension/types.d.ts.map +1 -0
- package/dist/families/index.d.ts +11 -0
- package/dist/families/index.d.ts.map +1 -0
- package/dist/families/presets.d.ts +31 -0
- package/dist/families/presets.d.ts.map +1 -0
- package/dist/families/resolver.d.ts +11 -0
- package/dist/families/resolver.d.ts.map +1 -0
- package/dist/families/types.d.ts +29 -0
- package/dist/families/types.d.ts.map +1 -0
- package/dist/governance/command-safety.d.ts +34 -0
- package/dist/governance/command-safety.d.ts.map +1 -0
- package/dist/governance/governance.d.ts +19 -0
- package/dist/governance/governance.d.ts.map +1 -0
- package/dist/governance/index.d.ts +12 -0
- package/dist/governance/index.d.ts.map +1 -0
- package/dist/governance/types.d.ts +29 -0
- package/dist/governance/types.d.ts.map +1 -0
- package/dist/index.d.ts +72 -804
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -1
- package/dist/internal/management-args.d.ts +13 -0
- package/dist/internal/management-args.d.ts.map +1 -0
- package/dist/internal/management-results.d.ts +21 -0
- package/dist/internal/management-results.d.ts.map +1 -0
- package/dist/llm-config.d.ts +108 -0
- package/dist/llm-config.d.ts.map +1 -0
- package/dist/logger/core.d.ts +31 -0
- package/dist/logger/core.d.ts.map +1 -0
- package/dist/logger/index.d.ts +9 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/orchestrator/compression-handler.d.ts +29 -0
- package/dist/orchestrator/compression-handler.d.ts.map +1 -0
- package/dist/orchestrator/context-compressor.d.ts +51 -0
- package/dist/orchestrator/context-compressor.d.ts.map +1 -0
- package/dist/orchestrator/context-summarizer.d.ts +41 -0
- package/dist/orchestrator/context-summarizer.d.ts.map +1 -0
- package/dist/orchestrator/index.d.ts +12 -0
- package/dist/orchestrator/index.d.ts.map +1 -0
- package/dist/orchestrator/orchestrator.d.ts +46 -0
- package/dist/orchestrator/orchestrator.d.ts.map +1 -0
- package/dist/orchestrator/types.d.ts +58 -0
- package/dist/orchestrator/types.d.ts.map +1 -0
- package/dist/parts/index.d.ts +13 -0
- package/dist/parts/index.d.ts.map +1 -0
- package/dist/parts/registry.d.ts +11 -0
- package/dist/parts/registry.d.ts.map +1 -0
- package/dist/parts/summaries.d.ts +9 -0
- package/dist/parts/summaries.d.ts.map +1 -0
- package/dist/parts/types.d.ts +61 -0
- package/dist/parts/types.d.ts.map +1 -0
- package/dist/platform.d.ts +17 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +1 -0
- package/dist/protocols/anthropic.d.ts +20 -0
- package/dist/protocols/anthropic.d.ts.map +1 -0
- package/dist/protocols/ark.d.ts +36 -0
- package/dist/protocols/ark.d.ts.map +1 -0
- package/dist/protocols/deepseek.d.ts +24 -0
- package/dist/protocols/deepseek.d.ts.map +1 -0
- package/dist/protocols/error-utils.d.ts +14 -0
- package/dist/protocols/error-utils.d.ts.map +1 -0
- package/dist/protocols/gemini.d.ts +24 -0
- package/dist/protocols/gemini.d.ts.map +1 -0
- package/dist/protocols/glm.d.ts +20 -0
- package/dist/protocols/glm.d.ts.map +1 -0
- package/dist/protocols/grok.d.ts +20 -0
- package/dist/protocols/grok.d.ts.map +1 -0
- package/dist/protocols/index.d.ts +31 -0
- package/dist/protocols/index.d.ts.map +1 -0
- package/dist/protocols/minimax.d.ts +38 -0
- package/dist/protocols/minimax.d.ts.map +1 -0
- package/dist/protocols/moonshot.d.ts +20 -0
- package/dist/protocols/moonshot.d.ts.map +1 -0
- package/dist/protocols/openai-sse.d.ts +33 -0
- package/dist/protocols/openai-sse.d.ts.map +1 -0
- package/dist/protocols/openai.d.ts +19 -0
- package/dist/protocols/openai.d.ts.map +1 -0
- package/dist/protocols/qwen.d.ts +26 -0
- package/dist/protocols/qwen.d.ts.map +1 -0
- package/dist/protocols/responses-sse.d.ts +30 -0
- package/dist/protocols/responses-sse.d.ts.map +1 -0
- package/dist/protocols/sse-reader.d.ts +23 -0
- package/dist/protocols/sse-reader.d.ts.map +1 -0
- package/dist/protocols/tool-arguments.d.ts +8 -0
- package/dist/protocols/tool-arguments.d.ts.map +1 -0
- package/dist/protocols/types.d.ts +148 -0
- package/dist/protocols/types.d.ts.map +1 -0
- package/dist/protocols/vercel-gateway.d.ts +15 -0
- package/dist/protocols/vercel-gateway.d.ts.map +1 -0
- package/dist/runtime.d.ts +151 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/skills/index.d.ts +14 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/management/admin.d.ts +10 -0
- package/dist/skills/management/admin.d.ts.map +1 -0
- package/dist/skills/management/index.d.ts +11 -0
- package/dist/skills/management/index.d.ts.map +1 -0
- package/dist/skills/management/inputs.d.ts +44 -0
- package/dist/skills/management/inputs.d.ts.map +1 -0
- package/dist/skills/management/operations.d.ts +78 -0
- package/dist/skills/management/operations.d.ts.map +1 -0
- package/dist/skills/management/types.d.ts +70 -0
- package/dist/skills/management/types.d.ts.map +1 -0
- package/dist/skills/registry.d.ts +37 -0
- package/dist/skills/registry.d.ts.map +1 -0
- package/dist/skills/summaries.d.ts +9 -0
- package/dist/skills/summaries.d.ts.map +1 -0
- package/dist/skills/types.d.ts +61 -0
- package/dist/skills/types.d.ts.map +1 -0
- package/dist/test-utils/mock-sse.d.ts +13 -0
- package/dist/test-utils/mock-sse.d.ts.map +1 -0
- package/dist/tool-manager/define-tool.d.ts +35 -0
- package/dist/tool-manager/define-tool.d.ts.map +1 -0
- package/dist/tool-manager/formats.d.ts +46 -0
- package/dist/tool-manager/formats.d.ts.map +1 -0
- package/dist/tool-manager/identity.d.ts +18 -0
- package/dist/tool-manager/identity.d.ts.map +1 -0
- package/dist/tool-manager/in-process-provider.d.ts +15 -0
- package/dist/tool-manager/in-process-provider.d.ts.map +1 -0
- package/dist/tool-manager/index.d.ts +18 -0
- package/dist/tool-manager/index.d.ts.map +1 -0
- package/dist/tool-manager/manager.d.ts +18 -0
- package/dist/tool-manager/manager.d.ts.map +1 -0
- package/dist/tool-manager/mcp-provider.d.ts +21 -0
- package/dist/tool-manager/mcp-provider.d.ts.map +1 -0
- package/dist/tool-manager/summaries.d.ts +39 -0
- package/dist/tool-manager/summaries.d.ts.map +1 -0
- package/dist/tool-manager/types.d.ts +314 -0
- package/dist/tool-manager/types.d.ts.map +1 -0
- package/dist/types.d.ts +663 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +26 -15
- package/src/adapter/index.ts +25 -0
- package/src/adapter/model-adapter.ts +196 -0
- package/src/adapter/model-options.ts +143 -0
- package/src/adapter/types.ts +41 -0
- package/src/chat-runtime.ts +515 -0
- package/src/constants.ts +9 -102
- package/src/events.ts +364 -150
- package/src/extension/index.ts +24 -0
- package/src/extension/types.ts +49 -0
- package/src/families/index.ts +28 -0
- package/src/families/presets.ts +124 -0
- package/src/families/resolver.ts +22 -0
- package/src/families/types.ts +55 -0
- package/src/governance/command-safety.ts +224 -0
- package/src/governance/governance.ts +125 -0
- package/src/governance/index.ts +38 -0
- package/src/governance/types.ts +44 -0
- package/src/index.ts +250 -145
- package/src/internal/management-args.ts +39 -0
- package/src/internal/management-results.ts +60 -0
- package/src/llm-config.ts +137 -0
- package/src/logger/core.ts +96 -0
- package/src/logger/index.ts +8 -0
- package/src/orchestrator/compression-handler.ts +137 -0
- package/src/{providers → orchestrator}/context-compressor.ts +79 -47
- package/src/orchestrator/context-summarizer.ts +123 -0
- package/src/orchestrator/index.ts +20 -0
- package/src/orchestrator/orchestrator.ts +1002 -0
- package/src/orchestrator/types.ts +70 -0
- package/src/parts/index.ts +20 -0
- package/src/parts/registry.ts +95 -0
- package/src/parts/summaries.ts +40 -0
- package/src/parts/types.ts +63 -0
- package/src/platform.ts +73 -0
- package/src/protocols/anthropic.ts +377 -0
- package/src/protocols/ark.ts +300 -0
- package/src/protocols/deepseek.ts +192 -0
- package/src/{providers/protocols → protocols}/error-utils.ts +17 -20
- package/src/protocols/gemini.ts +352 -0
- package/src/protocols/glm.ts +212 -0
- package/src/protocols/grok.ts +98 -0
- package/src/protocols/index.ts +48 -0
- package/src/protocols/minimax.ts +308 -0
- package/src/protocols/moonshot.ts +186 -0
- package/src/protocols/openai-sse.ts +156 -0
- package/src/protocols/openai.ts +97 -0
- package/src/protocols/qwen.ts +358 -0
- package/src/protocols/responses-sse.ts +224 -0
- package/src/protocols/sse-reader.ts +54 -0
- package/src/protocols/tool-arguments.ts +32 -0
- package/src/{providers/protocols → protocols}/types.ts +46 -37
- package/src/protocols/vercel-gateway.ts +391 -0
- package/src/runtime.ts +167 -0
- package/src/skills/index.ts +29 -0
- package/src/skills/management/admin.ts +170 -0
- package/src/skills/management/index.ts +27 -0
- package/src/skills/management/inputs.ts +79 -0
- package/src/skills/management/operations.ts +256 -0
- package/src/skills/management/types.ts +57 -0
- package/src/skills/registry.ts +120 -0
- package/src/skills/summaries.ts +48 -0
- package/src/skills/types.ts +65 -0
- package/src/test-utils/mock-sse.ts +3 -3
- package/src/tool-manager/define-tool.ts +201 -0
- package/src/tool-manager/formats.ts +146 -0
- package/src/tool-manager/identity.ts +80 -0
- package/src/tool-manager/in-process-provider.ts +164 -0
- package/src/tool-manager/index.ts +63 -0
- package/src/tool-manager/manager.ts +562 -0
- package/src/tool-manager/mcp-provider.ts +509 -0
- package/src/tool-manager/summaries.ts +136 -0
- package/src/tool-manager/types.ts +389 -0
- package/src/types.ts +750 -191
- package/dist/events-CU5D5ray.d.ts +0 -1128
- package/src/agent.ts +0 -409
- package/src/internal/update-plan.ts +0 -2
- package/src/internal/web-search.ts +0 -77
- package/src/mcp/client-manager.ts +0 -302
- package/src/mcp/index.ts +0 -2
- package/src/mcp/types.ts +0 -43
- package/src/providers/context-summarizer.ts +0 -70
- package/src/providers/index.ts +0 -125
- package/src/providers/model-registry.ts +0 -466
- package/src/providers/orchestrator.ts +0 -839
- package/src/providers/protocols/anthropic.ts +0 -406
- package/src/providers/protocols/ark.ts +0 -362
- package/src/providers/protocols/deepseek.ts +0 -344
- package/src/providers/protocols/gemini.ts +0 -350
- package/src/providers/protocols/index.ts +0 -36
- package/src/providers/protocols/openai.ts +0 -420
- package/src/providers/protocols/qwen.ts +0 -315
- package/src/providers/types.ts +0 -264
- package/src/providers/unified-adapter.ts +0 -367
- package/src/router.ts +0 -72
- package/src/tools.ts +0 -162
- package/src/utils.ts +0 -86
package/dist/index.d.ts
CHANGED
|
@@ -1,805 +1,73 @@
|
|
|
1
|
-
import { A as AgentConfig, T as ToolExecutor$1, M as ModelFamilyConfig, R as RouteResult, C as ChatOptions, a as ChatEvent, b as ModelOption, c as McpConnectionInfo, J as JsonSchemaObject, d as Tool, e as ChatMessage } from './events-CU5D5ray.js';
|
|
2
|
-
export { ax as AbortEvent, N as ActionType, B as AutoRunConfig, z as AutoRunMode, b5 as CHAT_EVENT_TYPES, i as CLAUDE_FAMILY, aC as ChatEventType, x as ChatMode, g as DEEPSEEK_FAMILY, D as DOUBAO_FAMILY, av as DoneEvent, aa as ErrorCategory, ab as ErrorDetails, aw as ErrorEvent, O as ExecResult, G as GEMINI_FAMILY, h as GPT_FAMILY, Z as MODELS, f as MODEL_FAMILIES, j as MODEL_REGISTRY, bb as McpConnectionStatus, ba as McpServerConfig, t as ModelFamilyId, w as ModelRegistryEntry, at as PlanStep, au as PlanStepStatus, P as ProtocolId, H as ProviderType, Q as QWEN_FAMILY, L as RenderType, F as ResponsesApiTool, aj as SearchEndEvent, ak as SearchEvent, a6 as SearchResult, ai as SearchResultEvent, ah as SearchStartEvent, S as SearchStrategy, ay as StatusEvent, aA as StepEndEvent, aB as StepEvent, az as StepStartEvent, ar as TextDeltaEvent, as as TextEvent, ae as ThinkingDeltaEvent, af as ThinkingEndEvent, ag as ThinkingEvent, u as ThinkingFormat, y as ThinkingMode, ad as ThinkingStartEvent, a9 as TokenUsage, ao as ToolApprovalRequestEvent, v as ToolCallFormat, a8 as ToolCallInfo, an as ToolCallOutputEvent, ap as ToolCallRequestEvent, am as ToolCallResultEvent, al as ToolCallStartEvent, a7 as ToolCallStatus, X as ToolConfigItem, I as ToolContext, E as ToolDefinition, U as ToolError, V as ToolErrorCode, U as ToolErrorShape, aq as ToolEvent, W as ToolPlugin, K as ToolUI, ac as ToolUIShape, Y as UserToolDefinition, aV as createAbort, aQ as createApiError, aO as createDone, aP as createError, aU as createParseError, aR as createRateLimitError, aI as createSearchEnd, aH as createSearchResult, aG as createSearchStart, aX as createStepEnd, aW as createStepStart, aN as createTextDelta, aE as createThinkingDelta, aF as createThinkingEnd, aD as createThinkingStart, aT as createTimeoutError, aL as createToolCallOutput, aM as createToolCallRequest, aK as createToolCallResult, aJ as createToolCallStart, aS as createToolError, a5 as getArg, b8 as getDefaultProvider, _ as getModelByModelId, k as getModelEntry, l as getModelFamily, m as getModelProtocol, s as getModelSearchStrategy, o as getModelsByFamily, p as getModelsByProtocol, n as getVisibleModels, b2 as isAbortEvent, b1 as isErrorEvent, b9 as isModelForProvider, b4 as isRetryableError, aZ as isSearchEvent, b0 as isStatusEvent, b3 as isStepEvent, a$ as isTextEvent, aY as isThinkingEvent, a4 as isThrowableToolError, a4 as isToolError, a_ as isToolEvent, r as modelSupportsNativeSearch, q as modelSupportsThinking, $ as resolveTools, a3 as rethrowToolError, b6 as routeModelToProvider, b7 as routeModelWithDetails, a2 as throwToolError, a0 as tool, a1 as tools } from './events-CU5D5ray.js';
|
|
3
|
-
|
|
4
|
-
/** 运行时配置(API Keys 和 URLs) */
|
|
5
|
-
interface RuntimeConfig {
|
|
6
|
-
arkApiKey: string;
|
|
7
|
-
arkApiUrl: string;
|
|
8
|
-
qwenApiKey: string;
|
|
9
|
-
qwenApiUrl: string;
|
|
10
|
-
openrouterApiKey: string;
|
|
11
|
-
openrouterApiUrl: string;
|
|
12
|
-
vercelApiKey: string;
|
|
13
|
-
tavilyApiKey: string;
|
|
14
|
-
geminiApiKey: string;
|
|
15
|
-
cwd: string;
|
|
16
|
-
}
|
|
17
1
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
*/
|
|
91
|
-
destroy(): Promise<void>;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Provider 统一类型定义
|
|
96
|
-
*
|
|
97
|
-
* 核心设计原则:
|
|
98
|
-
* 1. Adapter 只负责 API 格式转换,不处理业务逻辑
|
|
99
|
-
* 2. Orchestrator 统一处理工具调用循环、消息历史、事件发射
|
|
100
|
-
* 3. 所有 Adapter 返回标准化的 StreamChunk
|
|
101
|
-
*/
|
|
102
|
-
|
|
103
|
-
interface SimpleToolDefinition {
|
|
104
|
-
name: string;
|
|
105
|
-
description: string;
|
|
106
|
-
parameters: JsonSchemaObject;
|
|
107
|
-
}
|
|
108
|
-
/** 流式响应块类型 */
|
|
109
|
-
type StreamChunkType = 'text' | 'thinking' | 'thinking_done' | 'tool_call' | 'search_result' | 'done' | 'error';
|
|
110
|
-
/** 工具调用请求 */
|
|
111
|
-
interface ToolCallRequest {
|
|
112
|
-
id: string;
|
|
113
|
-
name: string;
|
|
114
|
-
arguments: string;
|
|
115
|
-
/** Gemini 模型需要的 thought_signature(用于工具调用循环) */
|
|
116
|
-
thought_signature?: string;
|
|
117
|
-
}
|
|
118
|
-
/** 搜索结果项 */
|
|
119
|
-
interface SearchResultItem {
|
|
120
|
-
title: string;
|
|
121
|
-
url: string;
|
|
122
|
-
snippet: string;
|
|
123
|
-
}
|
|
124
|
-
/** 流式响应块 - 所有 Adapter 必须返回此格式 */
|
|
125
|
-
/** Token 使用统计 */
|
|
126
|
-
interface StreamTokenUsage {
|
|
127
|
-
promptTokens?: number;
|
|
128
|
-
completionTokens?: number;
|
|
129
|
-
totalTokens?: number;
|
|
130
|
-
reasoningTokens?: number;
|
|
131
|
-
cachedTokens?: number;
|
|
132
|
-
}
|
|
133
|
-
interface StreamChunk {
|
|
134
|
-
type: StreamChunkType;
|
|
135
|
-
text?: string;
|
|
136
|
-
thinking?: string;
|
|
137
|
-
toolCall?: ToolCallRequest;
|
|
138
|
-
searchResults?: SearchResultItem[];
|
|
139
|
-
finishReason?: 'stop' | 'tool_calls' | 'length' | 'error';
|
|
140
|
-
/** Token 使用统计(done 事件携带) */
|
|
141
|
-
usage?: StreamTokenUsage;
|
|
142
|
-
error?: string;
|
|
143
|
-
}
|
|
144
|
-
/** 标准化消息 - Orchestrator 内部使用 */
|
|
145
|
-
interface StandardMessage {
|
|
146
|
-
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
147
|
-
content: string;
|
|
148
|
-
images?: string[];
|
|
149
|
-
toolCalls?: ToolCallRequest[];
|
|
150
|
-
toolCallId?: string;
|
|
151
|
-
toolName?: string;
|
|
152
|
-
}
|
|
153
|
-
/** Adapter 配置 */
|
|
154
|
-
interface AdapterConfig {
|
|
155
|
-
apiKey: string;
|
|
156
|
-
apiUrl?: string;
|
|
157
|
-
/** Tavily API Key(用于统一 Web Search) */
|
|
158
|
-
tavilyApiKey?: string;
|
|
159
|
-
}
|
|
160
|
-
/** 单次调用选项 */
|
|
161
|
-
interface StreamOnceOptions {
|
|
162
|
-
/** 模型 ID */
|
|
163
|
-
model: string;
|
|
164
|
-
/** 是否启用思考 */
|
|
165
|
-
enableThinking?: boolean;
|
|
166
|
-
/** 是否启用搜索 */
|
|
167
|
-
enableSearch?: boolean;
|
|
168
|
-
/** 中断信号 */
|
|
169
|
-
signal: AbortSignal;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Provider Adapter 接口
|
|
173
|
-
*
|
|
174
|
-
* 职责:
|
|
175
|
-
* - 将标准消息转换为 API 特定格式
|
|
176
|
-
* - 调用 API 并返回标准化的 StreamChunk
|
|
177
|
-
* - 不处理工具执行、消息历史维护
|
|
178
|
-
*/
|
|
179
|
-
interface ProviderAdapter {
|
|
180
|
-
/** 适配器名称 */
|
|
181
|
-
readonly name: string;
|
|
182
|
-
/** 支持的模型列表 */
|
|
183
|
-
readonly supportedModels: string[];
|
|
184
|
-
/**
|
|
185
|
-
* 单次流式调用
|
|
186
|
-
*
|
|
187
|
-
* @param messages 标准化消息列表
|
|
188
|
-
* @param tools 工具定义列表
|
|
189
|
-
* @param options 调用选项
|
|
190
|
-
* @returns 标准化的流式响应
|
|
191
|
-
*/
|
|
192
|
-
streamOnce(messages: StandardMessage[], tools: SimpleToolDefinition[], options: StreamOnceOptions): AsyncGenerator<StreamChunk>;
|
|
193
|
-
/**
|
|
194
|
-
* 检查是否支持指定模型
|
|
195
|
-
*/
|
|
196
|
-
supportsModel(model: string): boolean;
|
|
197
|
-
}
|
|
198
|
-
interface ToolExecutionHooks {
|
|
199
|
-
/** 工具调用 ID(用于把输出归属到具体 tool_call 卡片) */
|
|
200
|
-
toolCallId: string;
|
|
201
|
-
/** 工具名称 */
|
|
202
|
-
toolName: string;
|
|
203
|
-
/** stdout 增量 */
|
|
204
|
-
onStdout?: (chunk: string) => void;
|
|
205
|
-
/** stderr 增量 */
|
|
206
|
-
onStderr?: (chunk: string) => void;
|
|
207
|
-
}
|
|
208
|
-
type ToolExecutor = (name: string, args: Record<string, unknown>, signal?: AbortSignal, hooks?: ToolExecutionHooks) => Promise<object>;
|
|
209
|
-
/** 自动运行配置 */
|
|
210
|
-
interface AutoRunConfig {
|
|
211
|
-
/**
|
|
212
|
-
* 自动运行模式
|
|
213
|
-
* - 'run-everything': 运行所有内容(自动执行)
|
|
214
|
-
* - 'manual': 手动批准(每次执行前询问)
|
|
215
|
-
*/
|
|
216
|
-
mode?: 'run-everything' | 'manual';
|
|
217
|
-
}
|
|
218
|
-
/** 工具批准回调函数 */
|
|
219
|
-
type ToolApprovalCallback = (toolCall: {
|
|
220
|
-
id: string;
|
|
221
|
-
name: string;
|
|
222
|
-
args: Record<string, unknown>;
|
|
223
|
-
}) => Promise<boolean>;
|
|
224
|
-
/** 获取自动运行配置回调 */
|
|
225
|
-
type GetAutoRunConfigCallback = () => Promise<AutoRunConfig | undefined>;
|
|
226
|
-
/** Orchestrator 配置 */
|
|
227
|
-
interface OrchestratorConfig {
|
|
228
|
-
/** 最大迭代次数 */
|
|
229
|
-
maxIterations?: number;
|
|
230
|
-
/** 工具执行器 */
|
|
231
|
-
executeTool: ToolExecutor;
|
|
232
|
-
/** 完整的工具列表(用于获取 ui/requiresApproval/timeout),key: 工具名称 */
|
|
233
|
-
tools?: Map<string, Tool>;
|
|
234
|
-
/** 自动运行配置(静态配置,优先使用 getAutoRunConfig) */
|
|
235
|
-
autoRunConfig?: AutoRunConfig;
|
|
236
|
-
/**
|
|
237
|
-
* 动态获取自动运行配置回调
|
|
238
|
-
* 每次检查工具批准时调用,获取最新配置
|
|
239
|
-
*/
|
|
240
|
-
getAutoRunConfig?: GetAutoRunConfigCallback;
|
|
241
|
-
/**
|
|
242
|
-
* 工具批准回调(manual 模式使用)
|
|
243
|
-
* 返回 true 表示批准执行,false 表示跳过
|
|
244
|
-
*/
|
|
245
|
-
onToolApprovalRequest?: ToolApprovalCallback;
|
|
246
|
-
/**
|
|
247
|
-
* 客户端工具名称集合(透传模式)
|
|
248
|
-
*
|
|
249
|
-
* 这些工具不在服务端执行,而是:
|
|
250
|
-
* 1. 发送 tool_call_request 事件给客户端
|
|
251
|
-
* 2. 结束本轮对话
|
|
252
|
-
* 3. 客户端执行后,发新请求继续对话
|
|
253
|
-
*/
|
|
254
|
-
clientToolNames?: Set<string>;
|
|
255
|
-
/** 上下文总结回调(走 ai-server 等外部服务) */
|
|
256
|
-
summarize?: (systemPrompt: string, userPrompt: string) => Promise<string>;
|
|
257
|
-
}
|
|
258
|
-
/** Orchestrator 上下文 */
|
|
259
|
-
interface OrchestratorContext {
|
|
260
|
-
/** 系统提示 */
|
|
261
|
-
systemPrompt: string;
|
|
262
|
-
/** 对话历史(会被修改) */
|
|
263
|
-
history: ChatMessage[];
|
|
264
|
-
/** 工具定义 */
|
|
265
|
-
tools: SimpleToolDefinition[];
|
|
266
|
-
/** 中断信号 */
|
|
267
|
-
signal: AbortSignal;
|
|
268
|
-
/** 图片列表 */
|
|
269
|
-
images?: string[];
|
|
270
|
-
/**
|
|
271
|
-
* 客户端工具名称集合(透传模式)
|
|
272
|
-
*
|
|
273
|
-
* 这些工具不在服务端执行,而是发送 tool_call_request 事件给客户端
|
|
274
|
-
*/
|
|
275
|
-
clientToolNames?: Set<string>;
|
|
276
|
-
}
|
|
277
|
-
/** Orchestrator 选项 */
|
|
278
|
-
interface OrchestratorOptions {
|
|
279
|
-
/** 模型 ID */
|
|
280
|
-
model: string;
|
|
281
|
-
/** 是否启用思考 */
|
|
282
|
-
enableThinking?: boolean;
|
|
283
|
-
/** 是否启用搜索 */
|
|
284
|
-
enableSearch?: boolean;
|
|
285
|
-
/** 自动运行配置 */
|
|
286
|
-
autoRunConfig?: AutoRunConfig;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* UnifiedAdapter - 统一适配器
|
|
291
|
-
*
|
|
292
|
-
* 组合 Protocol + FamilyConfig,产出标准 StreamChunk
|
|
293
|
-
*
|
|
294
|
-
* 设计原则:
|
|
295
|
-
* 1. Protocol 只负责 HTTP/SSE 通信,产出 RawEvent
|
|
296
|
-
* 2. UnifiedAdapter 根据 FamilyConfig 将 RawEvent 转换为 StreamChunk
|
|
297
|
-
* 3. 所有模型都使用同一个 UnifiedAdapter,行为差异由 FamilyConfig 决定
|
|
298
|
-
* 4. 实现 ProviderAdapter 接口,可与现有 Orchestrator 无缝集成
|
|
299
|
-
*/
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* UnifiedAdapter 配置
|
|
303
|
-
*/
|
|
304
|
-
interface UnifiedAdapterConfig {
|
|
305
|
-
/** ARK API Key(豆包/DeepSeek) */
|
|
306
|
-
arkApiKey?: string;
|
|
307
|
-
arkApiUrl?: string;
|
|
308
|
-
/** Qwen API Key(通义千问) */
|
|
309
|
-
qwenApiKey?: string;
|
|
310
|
-
qwenApiUrl?: string;
|
|
311
|
-
/** Gemini API Key */
|
|
312
|
-
geminiApiKey?: string;
|
|
313
|
-
geminiApiUrl?: string;
|
|
314
|
-
/** OpenRouter API Key */
|
|
315
|
-
openrouterApiKey?: string;
|
|
316
|
-
openrouterApiUrl?: string;
|
|
317
|
-
/** Vercel API Key(用于 Vercel AI Gateway 访问 Claude) */
|
|
318
|
-
vercelApiKey?: string;
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* 流式调用选项
|
|
322
|
-
*/
|
|
323
|
-
interface StreamOptions {
|
|
324
|
-
/** 模型 ID */
|
|
325
|
-
model: string;
|
|
326
|
-
/** 是否启用 thinking */
|
|
327
|
-
enableThinking?: boolean;
|
|
328
|
-
/** 是否启用搜索 */
|
|
329
|
-
enableSearch?: boolean;
|
|
330
|
-
/** 中断信号 */
|
|
331
|
-
signal: AbortSignal;
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* 统一适配器
|
|
335
|
-
*
|
|
336
|
-
* 实现 ProviderAdapter 接口,根据模型自动选择 Protocol,并根据 FamilyConfig 转换事件
|
|
337
|
-
*/
|
|
338
|
-
declare class UnifiedAdapter implements ProviderAdapter {
|
|
339
|
-
readonly name = "unified";
|
|
340
|
-
/** 支持的模型列表(从 Registry 获取) */
|
|
341
|
-
get supportedModels(): string[];
|
|
342
|
-
private protocols;
|
|
343
|
-
constructor(config: UnifiedAdapterConfig);
|
|
344
|
-
/**
|
|
345
|
-
* 检查是否支持指定模型
|
|
346
|
-
*/
|
|
347
|
-
supportsModel(model: string): boolean;
|
|
348
|
-
/**
|
|
349
|
-
* 获取模型的家族配置
|
|
350
|
-
*/
|
|
351
|
-
getModelFamilyConfig(model: string): ModelFamilyConfig | undefined;
|
|
352
|
-
/**
|
|
353
|
-
* 实现 ProviderAdapter.streamOnce 接口
|
|
354
|
-
*
|
|
355
|
-
* @param messages 标准消息列表
|
|
356
|
-
* @param tools 工具定义
|
|
357
|
-
* @param options 调用选项
|
|
358
|
-
* @returns 标准 StreamChunk 流
|
|
359
|
-
*/
|
|
360
|
-
streamOnce(messages: StandardMessage[], tools: SimpleToolDefinition[], options: StreamOnceOptions): AsyncGenerator<StreamChunk>;
|
|
361
|
-
/**
|
|
362
|
-
* 流式调用(内部方法)
|
|
363
|
-
*/
|
|
364
|
-
private stream;
|
|
365
|
-
/**
|
|
366
|
-
* 将 RawEvent 转换为 StreamChunk
|
|
367
|
-
*
|
|
368
|
-
* 根据 FamilyConfig 处理行为差异
|
|
369
|
-
*/
|
|
370
|
-
private transformEvents;
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* 创建 UnifiedAdapter
|
|
374
|
-
*/
|
|
375
|
-
declare function createUnifiedAdapter(config: UnifiedAdapterConfig): UnifiedAdapter;
|
|
376
|
-
|
|
377
|
-
/**
|
|
378
|
-
* Protocol Layer 类型定义
|
|
379
|
-
*
|
|
380
|
-
* Protocol 只负责:
|
|
381
|
-
* 1. HTTP 请求发送
|
|
382
|
-
* 2. SSE 流解析
|
|
383
|
-
* 3. 认证处理
|
|
384
|
-
*
|
|
385
|
-
* 不负责:
|
|
386
|
-
* - thinking 格式转换(由 Family 处理)
|
|
387
|
-
* - 搜索行为差异(由 Family 处理)
|
|
388
|
-
* - 工具调用格式差异(由 Family 处理)
|
|
389
|
-
*/
|
|
390
|
-
|
|
391
|
-
/**
|
|
392
|
-
* Protocol 原始事件类型
|
|
393
|
-
*
|
|
394
|
-
* 这是 Protocol 层产出的"原始"事件,
|
|
395
|
-
* 后续由 FamilyBehavior 转换为标准 StreamChunk
|
|
396
|
-
*/
|
|
397
|
-
type RawEventType = 'text_delta' | 'thinking_delta' | 'thinking_done' | 'tool_call_start' | 'tool_call_delta' | 'tool_call_done' | 'search_query' | 'search_result' | 'done' | 'error';
|
|
398
|
-
/**
|
|
399
|
-
* 原始工具调用
|
|
400
|
-
*/
|
|
401
|
-
interface RawToolCall {
|
|
402
|
-
id: string;
|
|
403
|
-
name: string;
|
|
404
|
-
arguments: string;
|
|
405
|
-
/** Gemini 需要的 thoughtSignature(用于工具调用循环) */
|
|
406
|
-
thoughtSignature?: string;
|
|
407
|
-
}
|
|
408
|
-
/**
|
|
409
|
-
* Protocol 消息中的工具调用
|
|
410
|
-
*/
|
|
411
|
-
interface ProtocolToolCall {
|
|
412
|
-
id: string;
|
|
413
|
-
name: string;
|
|
414
|
-
arguments: string;
|
|
415
|
-
/** Gemini 需要的 thoughtSignature */
|
|
416
|
-
thoughtSignature?: string;
|
|
417
|
-
}
|
|
418
|
-
/**
|
|
419
|
-
* 原始搜索结果
|
|
420
|
-
*/
|
|
421
|
-
interface RawSearchResult {
|
|
422
|
-
title: string;
|
|
423
|
-
url: string;
|
|
424
|
-
snippet: string;
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Protocol 原始事件
|
|
428
|
-
*/
|
|
429
|
-
/** Token 使用统计(Protocol 层) */
|
|
430
|
-
interface RawTokenUsage {
|
|
431
|
-
promptTokens?: number;
|
|
432
|
-
completionTokens?: number;
|
|
433
|
-
totalTokens?: number;
|
|
434
|
-
reasoningTokens?: number;
|
|
435
|
-
cachedTokens?: number;
|
|
436
|
-
}
|
|
437
|
-
interface RawEvent {
|
|
438
|
-
type: RawEventType;
|
|
439
|
-
delta?: string;
|
|
440
|
-
toolCall?: Partial<RawToolCall>;
|
|
441
|
-
searchQuery?: string;
|
|
442
|
-
searchResults?: RawSearchResult[];
|
|
443
|
-
finishReason?: 'stop' | 'tool_calls' | 'length' | 'error';
|
|
444
|
-
/** Token 使用统计(done 事件携带) */
|
|
445
|
-
usage?: RawTokenUsage;
|
|
446
|
-
error?: string;
|
|
447
|
-
}
|
|
448
|
-
/**
|
|
449
|
-
* Protocol 请求消息(标准化格式)
|
|
450
|
-
*/
|
|
451
|
-
interface ProtocolMessage {
|
|
452
|
-
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
453
|
-
content: string;
|
|
454
|
-
/** 图片列表(base64 或 URL) */
|
|
455
|
-
images?: string[];
|
|
456
|
-
/** 工具调用(assistant 消息) */
|
|
457
|
-
toolCalls?: ProtocolToolCall[];
|
|
458
|
-
/** 工具调用 ID(tool 消息) */
|
|
459
|
-
toolCallId?: string;
|
|
460
|
-
/** 工具名称(tool 消息,Gemini 需要) */
|
|
461
|
-
toolName?: string;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
interface ProtocolToolDefinition {
|
|
465
|
-
name: string;
|
|
466
|
-
description: string;
|
|
467
|
-
parameters: JsonSchemaObject;
|
|
468
|
-
}
|
|
469
|
-
/**
|
|
470
|
-
* Protocol 请求选项
|
|
471
|
-
*/
|
|
472
|
-
interface ProtocolRequestOptions {
|
|
473
|
-
/** 模型 ID */
|
|
474
|
-
model: string;
|
|
475
|
-
/** 模型家族配置 */
|
|
476
|
-
familyConfig: ModelFamilyConfig;
|
|
477
|
-
/** 是否启用 thinking */
|
|
478
|
-
enableThinking: boolean;
|
|
479
|
-
/** 是否启用搜索 */
|
|
480
|
-
enableSearch: boolean;
|
|
481
|
-
/** 中断信号 */
|
|
482
|
-
signal: AbortSignal;
|
|
483
|
-
}
|
|
484
|
-
/**
|
|
485
|
-
* Protocol 配置
|
|
486
|
-
*/
|
|
487
|
-
interface ProtocolConfig {
|
|
488
|
-
apiKey: string;
|
|
489
|
-
apiUrl?: string;
|
|
490
|
-
}
|
|
491
|
-
/**
|
|
492
|
-
* Protocol 接口
|
|
493
|
-
*
|
|
494
|
-
* 只负责 HTTP/SSE 通信,不处理任何业务逻辑
|
|
495
|
-
*/
|
|
496
|
-
interface Protocol {
|
|
497
|
-
/** 协议名称 */
|
|
498
|
-
readonly name: string;
|
|
499
|
-
/**
|
|
500
|
-
* 发送请求并返回原始事件流
|
|
501
|
-
*
|
|
502
|
-
* @param messages 消息列表
|
|
503
|
-
* @param tools 工具定义
|
|
504
|
-
* @param options 请求选项
|
|
505
|
-
* @returns 原始事件流
|
|
506
|
-
*/
|
|
507
|
-
stream(messages: ProtocolMessage[], tools: ProtocolToolDefinition[], options: ProtocolRequestOptions): AsyncGenerator<RawEvent>;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
/**
|
|
511
|
-
* ARK Protocol(火山引擎 Responses API)
|
|
512
|
-
*
|
|
513
|
-
* 只负责:
|
|
514
|
-
* - HTTP 请求发送
|
|
515
|
-
* - SSE 流解析
|
|
516
|
-
* - 原始事件产出
|
|
517
|
-
*/
|
|
518
|
-
|
|
519
|
-
/**
|
|
520
|
-
* ARK Protocol 实现
|
|
521
|
-
*/
|
|
522
|
-
declare class ArkProtocol implements Protocol {
|
|
523
|
-
readonly name = "ark";
|
|
524
|
-
private apiKey;
|
|
525
|
-
private apiUrl;
|
|
526
|
-
constructor(config: ProtocolConfig);
|
|
527
|
-
/**
|
|
528
|
-
* 发送请求并返回原始事件流
|
|
529
|
-
*/
|
|
530
|
-
stream(messages: ProtocolMessage[], tools: ProtocolToolDefinition[], options: ProtocolRequestOptions): AsyncGenerator<RawEvent>;
|
|
531
|
-
/**
|
|
532
|
-
* 构建请求体
|
|
533
|
-
*/
|
|
534
|
-
private buildRequestBody;
|
|
535
|
-
/**
|
|
536
|
-
* 转换消息格式
|
|
537
|
-
*/
|
|
538
|
-
private convertMessages;
|
|
539
|
-
/**
|
|
540
|
-
* 解析 SSE 流
|
|
541
|
-
*/
|
|
542
|
-
private parseSSE;
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* 创建 ARK Protocol
|
|
546
|
-
*/
|
|
547
|
-
declare function createArkProtocol(config: ProtocolConfig): ArkProtocol;
|
|
548
|
-
|
|
549
|
-
/**
|
|
550
|
-
* DeepSeek Protocol(通过火山引擎 ARK API 访问)
|
|
551
|
-
*
|
|
552
|
-
* 特点:
|
|
553
|
-
* - 支持 reasoning(深度思考)
|
|
554
|
-
* - 支持 web_search 原生搜索
|
|
555
|
-
* - 与豆包共用 ARK API,但行为可能有差异
|
|
556
|
-
*/
|
|
557
|
-
|
|
558
|
-
/**
|
|
559
|
-
* DeepSeek Protocol 实现
|
|
560
|
-
*/
|
|
561
|
-
declare class DeepSeekProtocol implements Protocol {
|
|
562
|
-
readonly name = "deepseek";
|
|
563
|
-
private apiKey;
|
|
564
|
-
private apiUrl;
|
|
565
|
-
constructor(config: ProtocolConfig);
|
|
566
|
-
stream(messages: ProtocolMessage[], tools: ProtocolToolDefinition[], options: ProtocolRequestOptions): AsyncGenerator<RawEvent>;
|
|
567
|
-
/**
|
|
568
|
-
* 构建请求体(DeepSeek 专用)
|
|
569
|
-
*/
|
|
570
|
-
private buildRequestBody;
|
|
571
|
-
private convertMessages;
|
|
572
|
-
/**
|
|
573
|
-
* 解析 SSE 流(DeepSeek 专用)
|
|
574
|
-
*/
|
|
575
|
-
private parseSSE;
|
|
576
|
-
}
|
|
577
|
-
declare function createDeepSeekProtocol(config: ProtocolConfig): DeepSeekProtocol;
|
|
578
|
-
|
|
579
|
-
/**
|
|
580
|
-
* Qwen Protocol(通义千问 OpenAI 兼容模式 API)
|
|
581
|
-
*
|
|
582
|
-
* 使用 OpenAI 兼容端点以支持工具调用:
|
|
583
|
-
* https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions
|
|
584
|
-
*/
|
|
585
|
-
|
|
586
|
-
/**
|
|
587
|
-
* Qwen Protocol 实现(OpenAI 兼容模式)
|
|
588
|
-
*/
|
|
589
|
-
declare class QwenProtocol implements Protocol {
|
|
590
|
-
readonly name = "qwen";
|
|
591
|
-
private apiKey;
|
|
592
|
-
private apiUrl;
|
|
593
|
-
constructor(config: ProtocolConfig);
|
|
594
|
-
/**
|
|
595
|
-
* 发送请求并返回原始事件流
|
|
596
|
-
*/
|
|
597
|
-
stream(messages: ProtocolMessage[], tools: ProtocolToolDefinition[], options: ProtocolRequestOptions): AsyncGenerator<RawEvent>;
|
|
598
|
-
/**
|
|
599
|
-
* 构建请求体(OpenAI 格式)
|
|
600
|
-
*/
|
|
601
|
-
private buildRequestBody;
|
|
602
|
-
/**
|
|
603
|
-
* 转换消息格式(OpenAI 标准格式)
|
|
604
|
-
*/
|
|
605
|
-
private convertMessages;
|
|
606
|
-
/**
|
|
607
|
-
* 解析 SSE 流(OpenAI 格式)
|
|
608
|
-
*/
|
|
609
|
-
private parseSSE;
|
|
610
|
-
}
|
|
611
|
-
/**
|
|
612
|
-
* 创建 Qwen Protocol
|
|
613
|
-
*/
|
|
614
|
-
declare function createQwenProtocol(config: ProtocolConfig): QwenProtocol;
|
|
615
|
-
|
|
616
|
-
/**
|
|
617
|
-
* Gemini Protocol(Google Gemini API)
|
|
618
|
-
*
|
|
619
|
-
* 只负责:
|
|
620
|
-
* - HTTP 请求发送
|
|
621
|
-
* - SSE 流解析
|
|
622
|
-
* - 原始事件产出
|
|
623
|
-
*/
|
|
624
|
-
|
|
625
|
-
/**
|
|
626
|
-
* Gemini Protocol 实现
|
|
627
|
-
*/
|
|
628
|
-
declare class GeminiProtocol implements Protocol {
|
|
629
|
-
readonly name = "gemini";
|
|
630
|
-
private apiKey;
|
|
631
|
-
private apiUrl;
|
|
632
|
-
constructor(config: ProtocolConfig);
|
|
633
|
-
/**
|
|
634
|
-
* 发送请求并返回原始事件流
|
|
635
|
-
*/
|
|
636
|
-
stream(messages: ProtocolMessage[], tools: ProtocolToolDefinition[], options: ProtocolRequestOptions): AsyncGenerator<RawEvent>;
|
|
637
|
-
/**
|
|
638
|
-
* 构建请求体
|
|
639
|
-
*/
|
|
640
|
-
private buildRequestBody;
|
|
641
|
-
/**
|
|
642
|
-
* 转换消息格式
|
|
643
|
-
*/
|
|
644
|
-
private convertMessages;
|
|
645
|
-
/**
|
|
646
|
-
* 解析 SSE 流
|
|
647
|
-
*/
|
|
648
|
-
private parseSSE;
|
|
649
|
-
}
|
|
650
|
-
/**
|
|
651
|
-
* 创建 Gemini Protocol
|
|
652
|
-
*/
|
|
653
|
-
declare function createGeminiProtocol(config: ProtocolConfig): GeminiProtocol;
|
|
654
|
-
|
|
655
|
-
/**
|
|
656
|
-
* OpenAI Protocol(通过 OpenRouter 访问 OpenAI/GPT 模型)
|
|
657
|
-
*
|
|
658
|
-
* 特点:
|
|
659
|
-
* - GPT-5.x 支持 reasoning(思考模式)
|
|
660
|
-
* - 支持工具调用
|
|
661
|
-
*/
|
|
662
|
-
|
|
663
|
-
/**
|
|
664
|
-
* OpenAI Protocol 实现(通过 OpenRouter)
|
|
665
|
-
*/
|
|
666
|
-
declare class OpenAIProtocol implements Protocol {
|
|
667
|
-
readonly name = "openai";
|
|
668
|
-
private apiKey;
|
|
669
|
-
private apiUrl;
|
|
670
|
-
constructor(config: ProtocolConfig);
|
|
671
|
-
stream(messages: ProtocolMessage[], tools: ProtocolToolDefinition[], options: ProtocolRequestOptions): AsyncGenerator<RawEvent>;
|
|
672
|
-
/**
|
|
673
|
-
* 构建请求体(OpenAI/GPT 专用)
|
|
674
|
-
*/
|
|
675
|
-
private buildRequestBody;
|
|
676
|
-
private convertMessages;
|
|
677
|
-
/**
|
|
678
|
-
* 解析 SSE 流(OpenAI/GPT 专用)
|
|
679
|
-
*/
|
|
680
|
-
private parseSSE;
|
|
681
|
-
}
|
|
682
|
-
declare function createOpenAIProtocol(config: ProtocolConfig): OpenAIProtocol;
|
|
683
|
-
|
|
684
|
-
/**
|
|
685
|
-
* Anthropic Protocol(通过 Vercel AI Gateway)
|
|
686
|
-
*
|
|
687
|
-
* 特点:
|
|
688
|
-
* - 使用 Vercel AI SDK 的 createGateway
|
|
689
|
-
* - 支持 extended thinking
|
|
690
|
-
* - 支持工具调用
|
|
691
|
-
* - 自动处理流式输出
|
|
692
|
-
*
|
|
693
|
-
* 参考: https://vercel.com/docs/ai-gateway
|
|
694
|
-
*/
|
|
695
|
-
|
|
696
|
-
/**
|
|
697
|
-
* Anthropic Protocol 实现(通过 Vercel AI Gateway)
|
|
698
|
-
*/
|
|
699
|
-
declare class AnthropicProtocol implements Protocol {
|
|
700
|
-
readonly name = "anthropic";
|
|
701
|
-
private gateway;
|
|
702
|
-
constructor(config: ProtocolConfig);
|
|
703
|
-
stream(messages: ProtocolMessage[], tools: ProtocolToolDefinition[], options: ProtocolRequestOptions): AsyncGenerator<RawEvent>;
|
|
704
|
-
/**
|
|
705
|
-
* 转换消息格式(ProtocolMessage → AI SDK CoreMessage)
|
|
706
|
-
* 简化版:主要处理文本消息,工具调用通过历史上下文传递
|
|
707
|
-
*/
|
|
708
|
-
private convertMessages;
|
|
709
|
-
/**
|
|
710
|
-
* 转换工具格式(ProtocolToolDefinition → AI SDK tools)
|
|
711
|
-
* 注意:Vercel Gateway 对工具格式有特殊要求,这里使用标准格式
|
|
712
|
-
*/
|
|
713
|
-
private convertTools;
|
|
714
|
-
/**
|
|
715
|
-
* 将 JSON Schema 转换为 Zod Schema
|
|
716
|
-
*/
|
|
717
|
-
private jsonSchemaToZod;
|
|
718
|
-
/**
|
|
719
|
-
* 解析 AI SDK 流式响应
|
|
720
|
-
*/
|
|
721
|
-
private parseStream;
|
|
722
|
-
}
|
|
723
|
-
declare function createAnthropicProtocol(config: ProtocolConfig): AnthropicProtocol;
|
|
724
|
-
|
|
725
|
-
/**
|
|
726
|
-
* Chat Orchestrator
|
|
727
|
-
*
|
|
728
|
-
* 统一处理:
|
|
729
|
-
* 1. 工具调用循环 (while iterations < MAX)
|
|
730
|
-
* 2. 消息历史维护 (assistant + tool 消息)
|
|
731
|
-
* 3. 事件发射 (ChatEvent)
|
|
732
|
-
* 4. 错误处理
|
|
733
|
-
*
|
|
734
|
-
* 所有 Provider 通过此类执行,确保行为一致
|
|
735
|
-
*/
|
|
736
|
-
|
|
737
|
-
/**
|
|
738
|
-
* Chat Orchestrator
|
|
739
|
-
*
|
|
740
|
-
* 核心职责:统一处理工具调用循环,所有 Provider 共享相同的逻辑
|
|
741
|
-
*/
|
|
742
|
-
declare class ChatOrchestrator {
|
|
743
|
-
private config;
|
|
744
|
-
constructor(config: OrchestratorConfig);
|
|
745
|
-
/**
|
|
746
|
-
* 执行聊天
|
|
747
|
-
*
|
|
748
|
-
* @param adapter Provider 适配器
|
|
749
|
-
* @param message 用户消息
|
|
750
|
-
* @param context Orchestrator 上下文
|
|
751
|
-
* @param options 选项
|
|
752
|
-
*/
|
|
753
|
-
chat(adapter: ProviderAdapter, message: string, context: OrchestratorContext, options: OrchestratorOptions): AsyncGenerator<ChatEvent>;
|
|
754
|
-
/**
|
|
755
|
-
* 构建标准化消息列表
|
|
756
|
-
*/
|
|
757
|
-
private buildMessages;
|
|
758
|
-
/** 检测并执行上下文压缩,通过注入的 summarize 回调走 ai-server */
|
|
759
|
-
private compactIfNeeded;
|
|
760
|
-
}
|
|
761
|
-
/**
|
|
762
|
-
* 创建 Orchestrator 实例
|
|
763
|
-
*/
|
|
764
|
-
declare function createOrchestrator(config: OrchestratorConfig): ChatOrchestrator;
|
|
765
|
-
|
|
766
|
-
declare const DEFAULT_MODEL: string;
|
|
767
|
-
|
|
768
|
-
/**
|
|
769
|
-
* 工具执行器
|
|
770
|
-
*/
|
|
771
|
-
|
|
772
|
-
/**
|
|
773
|
-
* 创建默认工具执行器(Node.js 环境)
|
|
774
|
-
*
|
|
775
|
-
* 用于执行 shell 命令,包含基本安全检查
|
|
776
|
-
* 支持通过 AbortSignal 取消命令执行
|
|
777
|
-
*/
|
|
778
|
-
declare function createDefaultToolExecutor(defaultCwd?: string): ToolExecutor$1;
|
|
779
|
-
|
|
780
|
-
/**
|
|
781
|
-
* 调试日志工具
|
|
782
|
-
*
|
|
783
|
-
* 通过 DebugLogger.enable(true) 全局开启,
|
|
784
|
-
* 通过 DebugLogger.setLogFile(path) 同时写入 JSONL 文件,
|
|
785
|
-
* 各模块通过 DebugLogger.module('Name') 创建带前缀的 logger。
|
|
786
|
-
*/
|
|
787
|
-
declare class DebugLogger {
|
|
788
|
-
private prefix;
|
|
789
|
-
private constructor();
|
|
790
|
-
/** 全局启停调试日志 */
|
|
791
|
-
static enable(value: boolean): void;
|
|
792
|
-
/** 查询是否已启用 */
|
|
793
|
-
static isEnabled(): boolean;
|
|
794
|
-
/** 设置日志文件路径(JSONL 格式,追加写入) */
|
|
795
|
-
static setLogFile(filePath: string): void;
|
|
796
|
-
/** 创建模块专用 logger */
|
|
797
|
-
static module(name: string): DebugLogger;
|
|
798
|
-
debug(...args: unknown[]): void;
|
|
799
|
-
info(...args: unknown[]): void;
|
|
800
|
-
warn(...args: unknown[]): void;
|
|
801
|
-
error(...args: unknown[]): void;
|
|
802
|
-
private writeToFile;
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
export { type AdapterConfig, AgentConfig, AnthropicProtocol, ArkProtocol, ChatEvent, ChatMessage, ChatOptions, ChatOrchestrator, DEFAULT_MODEL, DebugLogger, DeepSeekProtocol, GeminiProtocol, HybridAgent, McpConnectionInfo, ModelFamilyConfig, ModelOption, OpenAIProtocol, type OrchestratorConfig, type OrchestratorContext, type OrchestratorOptions, type ToolExecutor as OrchestratorToolExecutor, type Protocol, type ProtocolConfig, type ProtocolMessage, type ProtocolToolCall, type ProtocolToolDefinition, type ProviderAdapter, QwenProtocol, type RawEvent, type RawEventType, type RawSearchResult, type RawToolCall, RouteResult, type RuntimeConfig, type SearchResultItem, type SimpleToolDefinition, type StandardMessage, type StreamChunk, type StreamChunkType, type StreamOnceOptions, type StreamOptions, Tool, type ToolCallRequest, ToolExecutor$1 as ToolExecutor, UnifiedAdapter, type UnifiedAdapterConfig, createAnthropicProtocol, createArkProtocol, createDeepSeekProtocol, createDefaultToolExecutor, createGeminiProtocol, createOpenAIProtocol, createOrchestrator, createQwenProtocol, createUnifiedAdapter };
|
|
2
|
+
* @huyooo/ai-chat-core
|
|
3
|
+
*
|
|
4
|
+
* AI Chat 核心包 — 环境无关,浏览器安全
|
|
5
|
+
*
|
|
6
|
+
* 分层架构:
|
|
7
|
+
* ┌─────────────────────────────────────────────────┐
|
|
8
|
+
* │ families/ 模型行为差异(thinking/工具格式) │
|
|
9
|
+
* │ protocols/ HTTP/SSE 通信 + 协议标识 │
|
|
10
|
+
* ├─────────────────────────────────────────────────┤
|
|
11
|
+
* │ adapter/ 协议路由 + 模型列表构建 │
|
|
12
|
+
* │ orchestrator/ 工具调用循环 + 上下文压缩 + 类型 │
|
|
13
|
+
* ├─────────────────────────────────────────────────┤
|
|
14
|
+
* │ tool-manager/ 统一工具管理(Provider + Manager) │
|
|
15
|
+
* │ skills/ 技能注册表 + 管理 API │
|
|
16
|
+
* │ parts/ UI 组件注册表 + 管理 API │
|
|
17
|
+
* ├─────────────────────────────────────────────────┤
|
|
18
|
+
* │ governance/ 资产治理策略(审批/副作用/命令安全)│
|
|
19
|
+
* │ extension/ 扩展元数据类型 + 构建常量 │
|
|
20
|
+
* └─────────────────────────────────────────────────┘
|
|
21
|
+
*
|
|
22
|
+
* Node.js 宿主能力(文件操作 / 工具执行器 / LLM 配置加载)
|
|
23
|
+
* 均在 @huyooo/ai-chat-host-node 中提供。
|
|
24
|
+
*/
|
|
25
|
+
export { ChatRuntime, type RuntimeConfig } from './chat-runtime';
|
|
26
|
+
export { MODEL_FAMILIES, DOUBAO_FAMILY, DEEPSEEK_FAMILY, QWEN_FAMILY, GEMINI_FAMILY, GPT_FAMILY, CLAUDE_FAMILY, resolveModelFamilyConfig, } from './families';
|
|
27
|
+
export type { ModelFamilyId, ThinkingFormat, ToolCallFormat, ModelFamilyConfig, } from './families';
|
|
28
|
+
export type { ProtocolId } from './protocols';
|
|
29
|
+
export { getBaseProtocol } from './protocols';
|
|
30
|
+
export { ModelAdapter } from './adapter';
|
|
31
|
+
export { buildModelOptions, getModelContextConfigFromLLM, formatContextWindow, formatPricing, } from './adapter';
|
|
32
|
+
export type { ModelOption, ModelContextConfig, } from './adapter';
|
|
33
|
+
export type { ProviderAdapter, AdapterConfig, StreamOnceOptions, } from './adapter';
|
|
34
|
+
export type { OrchestratorConfig, OrchestratorContext, OrchestratorOptions, OrchestratorToolExecutor, ToolExecutionHooks, GetAutoRunConfigCallback, } from './orchestrator';
|
|
35
|
+
export { ArkProtocol, createArkProtocol, DeepSeekProtocol, createDeepSeekProtocol, QwenProtocol, createQwenProtocol, createVercelGatewayProtocol, AnthropicProtocol, createAnthropicProtocol, } from './protocols';
|
|
36
|
+
export type { Protocol, ProtocolConfig, ProtocolAttachment, ProtocolMessage, ProtocolToolDefinition, RawEvent, RawEventType, RawOutputPart, RawToolCall, RawTokenUsage, } from './protocols';
|
|
37
|
+
export { ChatOrchestrator, createOrchestrator } from './orchestrator';
|
|
38
|
+
export type { AgentConfig, ChatOptions, ChatMode, ThinkingMode, AutoRunMode, AutoRunConfig, ToolExecutor, ToolDefinition, ChatMessage, ResponsesApiTool, Tool, ToolContext, DataEngineContext, ToolUI, RenderType, ActionType, ExecResult, ExecOptions, ToolResult, ToolSuccess, ToolExecuteResult, ToolError, ToolErrorCode, ToolErrorCategory, ToolPlugin, ToolConfigItem, ToolExecutionAuditHooks, UserToolDefinition, JsonSchemaObject, } from './types';
|
|
39
|
+
export { resolveTools, tool, tools, ToolException, normalizeToolResult, serializeToolResult, isToolResult, toolOk, createResolvedOutputSchema, STANDARD_TOOL_ERROR_SCHEMA, resolveToolResultUi, mergeToolGovernance, resolveToolGovernanceSnapshot, throwToolError, isToolError, } from './types';
|
|
40
|
+
export { DEFAULT_MODEL } from './constants';
|
|
41
|
+
export type { ToolCallStatus, ToolCallInfo, TokenUsage, ErrorCategory, ErrorDetails, FinishReason, ToolFailureReason, } from './events';
|
|
42
|
+
export type { ThinkingStartEvent, ThinkingDeltaEvent, ThinkingEndEvent, ThinkingEvent } from './events';
|
|
43
|
+
export type { ToolCallStartEvent, ToolCallResultEvent, ToolCallOutputEvent, ToolApprovalRequestEvent, ToolCallRequestEvent, ToolEvent } from './events';
|
|
44
|
+
export type { TextStartEvent, TextDeltaEvent, TextEndEvent, TextEvent } from './events';
|
|
45
|
+
export type { DataEvent, } from './events';
|
|
46
|
+
export type { PlanStep, PlanStepStatus, } from './events';
|
|
47
|
+
export type { DoneEvent, ErrorEvent, AbortEvent, StatusEvent } from './events';
|
|
48
|
+
export type { StepStartEvent, StepEndEvent, StepEvent } from './events';
|
|
49
|
+
export type { ChatEvent, ChatEventType, AssistantSegmentReason, AssistantSegmentStartEvent, AssistantSegmentEvent, } from './events';
|
|
50
|
+
export { createThinkingStart, createThinkingDelta, createThinkingEnd, createToolCallStart, createToolCallResult, createToolCallOutput, createToolCallRequest, createTextDelta, createDone, createError, createApiError, createRateLimitError, createToolError, createTimeoutError, createParseError, createAbort, createStepStart, createStepEnd, createAssistantSegmentStart, isThinkingEvent, isToolEvent, isTextEvent, isStatusEvent, isErrorEvent, isAbortEvent, isStepEvent, isAssistantSegmentEvent, isRetryableError, CHAT_EVENT_TYPES } from './events';
|
|
51
|
+
export { Type } from '@sinclair/typebox';
|
|
52
|
+
export type { Static, TSchema, TObject } from '@sinclair/typebox';
|
|
53
|
+
export { createToolRuntimeManager, createInProcessProvider, createMcpProvider, createManagedToolSummary, createManagedToolDetail, createManagedMcpServerSummary, createManagedMcpServerDetail, defineTool, TOOL_FORMATS, validateJsonSchemaArgs, validateTypeBoxArgs, registerToolFormats, registerToolFormat, hasToolFormat, } from './tool-manager';
|
|
54
|
+
export type { ToolDescriptor, ToolChangeEvent, ToolChangeListener, SessionToolsChangeEvent, SessionToolsChangeListener, ToolProvider, InProcessProvider, McpProviderExtended, McpServerConfig, McpConnectionStatus, McpConnectionInfo, ManagedToolSummary, ManagedToolDetail, ManagedMcpServerSummary, ManagedMcpServerDetail, ToolSearchQuery, CategorySummary, ProviderInfo, ToolRuntimeManager, TypeBoxToolConfig, ToolFormat, } from './tool-manager';
|
|
55
|
+
export { skillRegistry } from './skills';
|
|
56
|
+
export type { SkillRegistry } from './skills';
|
|
57
|
+
export type { SkillMeta, SkillSearchQuery, ManagedSkillSummary, ManagedSkillDetail, } from './skills';
|
|
58
|
+
export { skillManagementPlugin } from './skills';
|
|
59
|
+
export { createManagedSkillSummary, createManagedSkillDetail } from './skills';
|
|
60
|
+
export type { SkillManagementOptions, OnSkillCreate, OnSkillUpdate, OnSkillDelete, OnSkillSetEnabled, OnSkillLoadContent, OnSkillLoadReference, } from './skills';
|
|
61
|
+
export { getRouteChain, resolveRouteUrl, findRouteByProtocol, } from './llm-config';
|
|
62
|
+
export type { LLMConfig, ModelRoute, ModelConfig, ModelPricing, CompressionConfig, } from './llm-config';
|
|
63
|
+
export { partRegistry } from './parts';
|
|
64
|
+
export type { PartMeta, PartSearchQuery, PartRegistry, ManagedPartSummary, ManagedPartDetail, } from './parts';
|
|
65
|
+
export { createManagedPartSummary, createManagedPartDetail } from './parts';
|
|
66
|
+
export { analyzeCommandRisk, createAssetSummaryBase, createCommandGovernanceSnapshot, createCommandToolMetadata, createLocalMcpServerGovernance, createLocalToolGovernance, createPartAssetGovernance, readAssetGovernanceOverrides, toAssetGovernanceOverrides, } from './governance';
|
|
67
|
+
export type { AssetApprovalPolicy, AssetExecutionIsolation, AssetGovernance, AssetGovernanceOverrides, AssetHostDependency, AssetKind, AssetRuntime, AssetScope, AssetSideEffectLevel, AssetSource, CommandRiskAssessment, CommandRiskTag, CommandSafetyPolicy, CommandToolMetadata, ManagedAssetSummaryBase, } from './governance';
|
|
68
|
+
export type { AssetType, AssetMeta, AssetToolMeta, } from './extension';
|
|
69
|
+
export { getRequiredString, getOptionalString, getBooleanWithDefault, getStringArray, getStringRecord, splitCommaSeparatedStrings, } from './internal/management-args';
|
|
70
|
+
export { createCollectionResult, createInspectResult, createActionResult, createToggleResult, } from './internal/management-results';
|
|
71
|
+
export { initLogger, getLogger, createModuleLogger } from './logger';
|
|
72
|
+
export type { LogLevel, LoggerConfig } from './logger';
|
|
73
|
+
//# sourceMappingURL=index.d.ts.map
|