@shareai-lab/kode-sdk 1.0.0-beta.8 → 2.7.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 +115 -273
- package/README.zh-CN.md +114 -0
- package/dist/core/agent/breakpoint-manager.d.ts +16 -0
- package/dist/core/agent/breakpoint-manager.js +36 -0
- package/dist/core/agent/message-queue.d.ts +26 -0
- package/dist/core/agent/message-queue.js +57 -0
- package/dist/core/agent/permission-manager.d.ts +9 -0
- package/dist/core/agent/permission-manager.js +32 -0
- package/dist/core/agent/todo-manager.d.ts +26 -0
- package/dist/core/agent/todo-manager.js +91 -0
- package/dist/core/agent/tool-runner.d.ts +9 -0
- package/dist/core/agent/tool-runner.js +45 -0
- package/dist/core/agent.d.ts +228 -62
- package/dist/core/agent.js +1890 -615
- package/dist/core/config.d.ts +10 -0
- package/dist/core/config.js +2 -0
- package/dist/core/context-manager.d.ts +82 -0
- package/dist/core/context-manager.js +241 -0
- package/dist/core/errors.d.ts +22 -0
- package/dist/core/errors.js +49 -0
- package/dist/core/events.d.ts +41 -10
- package/dist/core/events.js +270 -68
- package/dist/core/file-pool.d.ts +41 -0
- package/dist/core/file-pool.js +102 -0
- package/dist/core/hooks.d.ts +3 -3
- package/dist/core/hooks.js +1 -1
- package/dist/core/permission-modes.d.ts +31 -0
- package/dist/core/permission-modes.js +61 -0
- package/dist/core/pool.d.ts +56 -13
- package/dist/core/pool.js +244 -34
- package/dist/core/room.d.ts +2 -2
- package/dist/core/room.js +10 -10
- package/dist/core/scheduler.d.ts +30 -23
- package/dist/core/scheduler.js +42 -168
- package/dist/core/skills/index.d.ts +10 -0
- package/dist/core/skills/index.js +20 -0
- package/dist/core/skills/management-manager.d.ts +130 -0
- package/dist/core/skills/management-manager.js +557 -0
- package/dist/core/skills/manager.d.ts +47 -0
- package/dist/core/skills/manager.js +243 -0
- package/dist/core/skills/operation-queue.d.ts +87 -0
- package/dist/core/skills/operation-queue.js +113 -0
- package/dist/core/skills/sandbox-file-manager.d.ts +82 -0
- package/dist/core/skills/sandbox-file-manager.js +183 -0
- package/dist/core/skills/types.d.ts +120 -0
- package/dist/core/skills/types.js +9 -0
- package/dist/core/skills/xml-generator.d.ts +13 -0
- package/dist/core/skills/xml-generator.js +70 -0
- package/dist/core/template.d.ts +57 -0
- package/dist/core/template.js +35 -0
- package/dist/core/time-bridge.d.ts +18 -0
- package/dist/core/time-bridge.js +100 -0
- package/dist/core/todo.d.ts +34 -0
- package/dist/core/todo.js +89 -0
- package/dist/core/types.d.ts +311 -114
- package/dist/core/types.js +1 -12
- package/dist/index.d.ts +47 -9
- package/dist/index.js +108 -15
- package/dist/infra/db/postgres/postgres-store.d.ts +97 -0
- package/dist/infra/db/postgres/postgres-store.js +1073 -0
- package/dist/infra/db/sqlite/sqlite-store.d.ts +84 -0
- package/dist/infra/db/sqlite/sqlite-store.js +800 -0
- package/dist/infra/e2b/e2b-fs.d.ts +29 -0
- package/dist/infra/e2b/e2b-fs.js +128 -0
- package/dist/infra/e2b/e2b-sandbox.d.ts +37 -0
- package/dist/infra/e2b/e2b-sandbox.js +156 -0
- package/dist/infra/e2b/e2b-template.d.ts +24 -0
- package/dist/infra/e2b/e2b-template.js +105 -0
- package/dist/infra/e2b/index.d.ts +4 -0
- package/dist/infra/e2b/index.js +9 -0
- package/dist/infra/e2b/types.d.ts +46 -0
- package/dist/infra/e2b/types.js +2 -0
- package/dist/infra/provider.d.ts +17 -58
- package/dist/infra/provider.js +65 -116
- package/dist/infra/providers/anthropic.d.ts +42 -0
- package/dist/infra/providers/anthropic.js +308 -0
- package/dist/infra/providers/core/errors.d.ts +230 -0
- package/dist/infra/providers/core/errors.js +353 -0
- package/dist/infra/providers/core/fork.d.ts +106 -0
- package/dist/infra/providers/core/fork.js +418 -0
- package/dist/infra/providers/core/index.d.ts +10 -0
- package/dist/infra/providers/core/index.js +76 -0
- package/dist/infra/providers/core/logger.d.ts +186 -0
- package/dist/infra/providers/core/logger.js +191 -0
- package/dist/infra/providers/core/retry.d.ts +62 -0
- package/dist/infra/providers/core/retry.js +189 -0
- package/dist/infra/providers/core/usage.d.ts +151 -0
- package/dist/infra/providers/core/usage.js +376 -0
- package/dist/infra/providers/gemini.d.ts +49 -0
- package/dist/infra/providers/gemini.js +493 -0
- package/dist/infra/providers/index.d.ts +25 -0
- package/dist/infra/providers/index.js +83 -0
- package/dist/infra/providers/openai.d.ts +123 -0
- package/dist/infra/providers/openai.js +662 -0
- package/dist/infra/providers/types.d.ts +334 -0
- package/dist/infra/providers/types.js +20 -0
- package/dist/infra/providers/utils.d.ts +53 -0
- package/dist/infra/providers/utils.js +400 -0
- package/dist/infra/sandbox-factory.d.ts +13 -0
- package/dist/infra/sandbox-factory.js +30 -0
- package/dist/infra/sandbox.d.ts +35 -6
- package/dist/infra/sandbox.js +174 -8
- package/dist/infra/store/factory.d.ts +45 -0
- package/dist/infra/store/factory.js +80 -0
- package/dist/infra/store/index.d.ts +3 -0
- package/dist/infra/store/index.js +26 -0
- package/dist/infra/store/json-store.d.ts +67 -0
- package/dist/infra/store/json-store.js +606 -0
- package/dist/infra/store/types.d.ts +342 -0
- package/dist/infra/store/types.js +2 -0
- package/dist/infra/store.d.ts +12 -32
- package/dist/infra/store.js +27 -130
- package/dist/tools/bash_kill/index.d.ts +1 -0
- package/dist/tools/bash_kill/index.js +35 -0
- package/dist/tools/bash_kill/prompt.d.ts +2 -0
- package/dist/tools/bash_kill/prompt.js +14 -0
- package/dist/tools/bash_logs/index.d.ts +1 -0
- package/dist/tools/bash_logs/index.js +40 -0
- package/dist/tools/bash_logs/prompt.d.ts +2 -0
- package/dist/tools/bash_logs/prompt.js +14 -0
- package/dist/tools/bash_run/index.d.ts +16 -0
- package/dist/tools/bash_run/index.js +61 -0
- package/dist/tools/bash_run/prompt.d.ts +2 -0
- package/dist/tools/bash_run/prompt.js +18 -0
- package/dist/tools/builtin.d.ts +7 -13
- package/dist/tools/builtin.js +19 -90
- package/dist/tools/define.d.ts +101 -0
- package/dist/tools/define.js +214 -0
- package/dist/tools/fs_edit/index.d.ts +1 -0
- package/dist/tools/fs_edit/index.js +62 -0
- package/dist/tools/fs_edit/prompt.d.ts +2 -0
- package/dist/tools/fs_edit/prompt.js +15 -0
- package/dist/tools/fs_glob/index.d.ts +1 -0
- package/dist/tools/fs_glob/index.js +40 -0
- package/dist/tools/fs_glob/prompt.d.ts +2 -0
- package/dist/tools/fs_glob/prompt.js +15 -0
- package/dist/tools/fs_grep/index.d.ts +1 -0
- package/dist/tools/fs_grep/index.js +66 -0
- package/dist/tools/fs_grep/prompt.d.ts +2 -0
- package/dist/tools/fs_grep/prompt.js +16 -0
- package/dist/tools/fs_multi_edit/index.d.ts +1 -0
- package/dist/tools/fs_multi_edit/index.js +106 -0
- package/dist/tools/fs_multi_edit/prompt.d.ts +2 -0
- package/dist/tools/fs_multi_edit/prompt.js +16 -0
- package/dist/tools/fs_read/index.d.ts +1 -0
- package/dist/tools/fs_read/index.js +40 -0
- package/dist/tools/fs_read/prompt.d.ts +2 -0
- package/dist/tools/fs_read/prompt.js +16 -0
- package/dist/tools/fs_write/index.d.ts +1 -0
- package/dist/tools/fs_write/index.js +40 -0
- package/dist/tools/fs_write/prompt.d.ts +2 -0
- package/dist/tools/fs_write/prompt.js +15 -0
- package/dist/tools/index.d.ts +11 -0
- package/dist/tools/index.js +61 -0
- package/dist/tools/mcp.d.ts +69 -0
- package/dist/tools/mcp.js +185 -0
- package/dist/tools/registry.d.ts +29 -0
- package/dist/tools/registry.js +26 -0
- package/dist/tools/scripts.d.ts +22 -0
- package/dist/tools/scripts.js +205 -0
- package/dist/tools/skills.d.ts +20 -0
- package/dist/tools/skills.js +115 -0
- package/dist/tools/task_run/index.d.ts +7 -0
- package/dist/tools/task_run/index.js +58 -0
- package/dist/tools/task_run/prompt.d.ts +5 -0
- package/dist/tools/task_run/prompt.js +25 -0
- package/dist/tools/todo_read/index.d.ts +1 -0
- package/dist/tools/todo_read/index.js +29 -0
- package/dist/tools/todo_read/prompt.d.ts +2 -0
- package/dist/tools/todo_read/prompt.js +18 -0
- package/dist/tools/todo_write/index.d.ts +1 -0
- package/dist/tools/todo_write/index.js +42 -0
- package/dist/tools/todo_write/prompt.d.ts +2 -0
- package/dist/tools/todo_write/prompt.js +23 -0
- package/dist/tools/tool.d.ts +43 -0
- package/dist/tools/tool.js +211 -0
- package/dist/tools/toolkit.d.ts +69 -0
- package/dist/tools/toolkit.js +98 -0
- package/dist/tools/type-inference.d.ts +127 -0
- package/dist/tools/type-inference.js +207 -0
- package/dist/utils/agent-id.d.ts +1 -0
- package/dist/utils/agent-id.js +28 -0
- package/dist/utils/logger.d.ts +15 -0
- package/dist/utils/logger.js +44 -0
- package/dist/utils/session-id.js +16 -16
- package/package.json +35 -11
- package/dist/tools/bash.d.ts +0 -63
- package/dist/tools/bash.js +0 -92
- package/dist/tools/fs.d.ts +0 -96
- package/dist/tools/fs.js +0 -100
- package/dist/tools/task.d.ts +0 -38
- package/dist/tools/task.js +0 -45
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider Adapter Types
|
|
3
|
+
*
|
|
4
|
+
* KODE Agent SDK uses Anthropic-style messages as the internal canonical format.
|
|
5
|
+
* All providers act as adapters that convert to/from this format.
|
|
6
|
+
*
|
|
7
|
+
* Internal Flow:
|
|
8
|
+
* Internal Message[] (Anthropic-style ContentBlocks)
|
|
9
|
+
* -> Provider.formatMessages() -> External API format
|
|
10
|
+
* -> API call
|
|
11
|
+
* -> Response -> normalizeContent() -> Internal ContentBlock[]
|
|
12
|
+
*
|
|
13
|
+
* Provider-Specific Requirements:
|
|
14
|
+
* - Anthropic: Preserve thinking signatures for multi-turn
|
|
15
|
+
* - OpenAI Responses: Use previous_response_id for state
|
|
16
|
+
* - DeepSeek/Qwen: Must NOT include reasoning_content in history
|
|
17
|
+
* - Gemini: Use thinkingLevel (not thinkingBudget) for 3.x
|
|
18
|
+
*/
|
|
19
|
+
import { Message, ContentBlock } from '../../core/types';
|
|
20
|
+
import { Configurable } from '../../core/config';
|
|
21
|
+
import { UsageStatistics } from './core/usage';
|
|
22
|
+
/**
|
|
23
|
+
* Standard model response in Anthropic-style format.
|
|
24
|
+
* All providers convert their responses to this format.
|
|
25
|
+
*/
|
|
26
|
+
export interface ModelResponse {
|
|
27
|
+
role: 'assistant';
|
|
28
|
+
content: ContentBlock[];
|
|
29
|
+
usage?: {
|
|
30
|
+
input_tokens: number;
|
|
31
|
+
output_tokens: number;
|
|
32
|
+
cache_creation_input_tokens?: number;
|
|
33
|
+
cache_read_input_tokens?: number;
|
|
34
|
+
};
|
|
35
|
+
stop_reason?: string;
|
|
36
|
+
extendedUsage?: UsageStatistics;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Streaming chunk in Anthropic-style format.
|
|
40
|
+
* All providers emit chunks in this format.
|
|
41
|
+
*/
|
|
42
|
+
export interface ModelStreamChunk {
|
|
43
|
+
type: 'content_block_start' | 'content_block_delta' | 'content_block_stop' | 'message_delta' | 'message_stop';
|
|
44
|
+
index?: number;
|
|
45
|
+
content_block?: ContentBlock;
|
|
46
|
+
delta?: {
|
|
47
|
+
type: 'text_delta' | 'input_json_delta' | 'reasoning_delta';
|
|
48
|
+
text?: string;
|
|
49
|
+
partial_json?: string;
|
|
50
|
+
};
|
|
51
|
+
usage?: {
|
|
52
|
+
input_tokens?: number;
|
|
53
|
+
output_tokens: number;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* File upload input.
|
|
58
|
+
*/
|
|
59
|
+
export interface UploadFileInput {
|
|
60
|
+
data: Buffer;
|
|
61
|
+
mimeType: string;
|
|
62
|
+
filename?: string;
|
|
63
|
+
kind: 'image' | 'file';
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* File upload result.
|
|
67
|
+
*/
|
|
68
|
+
export interface UploadFileResult {
|
|
69
|
+
fileId?: string;
|
|
70
|
+
fileUri?: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Thinking/reasoning configuration options.
|
|
74
|
+
* Each provider interprets these options according to their API:
|
|
75
|
+
*
|
|
76
|
+
* - Anthropic: thinking.budget_tokens, interleaved-thinking-2025-05-14 beta
|
|
77
|
+
* - OpenAI: reasoning_effort for Responses API (none/minimal/low/medium/high/xhigh)
|
|
78
|
+
* - Gemini: thinkingBudget (2.5 models) or thinkingLevel (3.x models)
|
|
79
|
+
*/
|
|
80
|
+
export interface ThinkingOptions {
|
|
81
|
+
/** Enable thinking/reasoning mode */
|
|
82
|
+
enabled?: boolean;
|
|
83
|
+
/** Budget tokens for reasoning (Anthropic: budget_tokens, Gemini: thinkingBudget) */
|
|
84
|
+
budgetTokens?: number;
|
|
85
|
+
/** Reasoning effort level (OpenAI: reasoning_effort) */
|
|
86
|
+
effort?: 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
87
|
+
/** Thinking level preset (Gemini 3.x: thinkingLevel) */
|
|
88
|
+
level?: 'minimal' | 'low' | 'medium' | 'high';
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* How reasoning/thinking content is transported in messages.
|
|
92
|
+
* - 'provider': Native provider format (Anthropic thinking blocks, OpenAI reasoning tokens)
|
|
93
|
+
* - 'text': Wrapped in <think></think> tags as text
|
|
94
|
+
* - 'omit': Excluded from message history
|
|
95
|
+
*/
|
|
96
|
+
export type ReasoningTransport = 'omit' | 'text' | 'provider';
|
|
97
|
+
/**
|
|
98
|
+
* Multimodal content handling options.
|
|
99
|
+
*/
|
|
100
|
+
export interface MultimodalOptions {
|
|
101
|
+
/** URL handling mode */
|
|
102
|
+
mode?: 'url' | 'url+base64';
|
|
103
|
+
/** Maximum size for base64 encoded content */
|
|
104
|
+
maxBase64Bytes?: number;
|
|
105
|
+
/** Allowed MIME types */
|
|
106
|
+
allowMimeTypes?: string[];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Core model configuration.
|
|
110
|
+
* Provider implementations extend this with provider-specific options.
|
|
111
|
+
*/
|
|
112
|
+
export interface ModelConfig {
|
|
113
|
+
provider: 'anthropic' | 'openai' | 'gemini' | string;
|
|
114
|
+
model: string;
|
|
115
|
+
baseUrl?: string;
|
|
116
|
+
apiKey?: string;
|
|
117
|
+
proxyUrl?: string;
|
|
118
|
+
maxTokens?: number;
|
|
119
|
+
temperature?: number;
|
|
120
|
+
reasoningTransport?: ReasoningTransport;
|
|
121
|
+
extraHeaders?: Record<string, string>;
|
|
122
|
+
extraBody?: Record<string, any>;
|
|
123
|
+
providerOptions?: Record<string, any>;
|
|
124
|
+
multimodal?: MultimodalOptions;
|
|
125
|
+
thinking?: ThinkingOptions;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Options for model completion requests.
|
|
129
|
+
*/
|
|
130
|
+
export interface CompletionOptions {
|
|
131
|
+
tools?: any[];
|
|
132
|
+
maxTokens?: number;
|
|
133
|
+
temperature?: number;
|
|
134
|
+
system?: string;
|
|
135
|
+
stream?: boolean;
|
|
136
|
+
thinking?: ThinkingOptions;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Core model provider interface.
|
|
140
|
+
* All provider implementations must conform to this interface.
|
|
141
|
+
*
|
|
142
|
+
* The adapter pattern:
|
|
143
|
+
* 1. Input: SDK internal Message[] (Anthropic-style ContentBlocks)
|
|
144
|
+
* 2. Provider converts to external API format
|
|
145
|
+
* 3. Provider calls external API
|
|
146
|
+
* 4. Provider converts response back to internal format
|
|
147
|
+
* 5. Output: ModelResponse with Anthropic-style ContentBlocks
|
|
148
|
+
*/
|
|
149
|
+
export interface ModelProvider extends Configurable<ModelConfig> {
|
|
150
|
+
/** Model identifier */
|
|
151
|
+
readonly model: string;
|
|
152
|
+
/** Maximum context window size in tokens */
|
|
153
|
+
readonly maxWindowSize: number;
|
|
154
|
+
/** Maximum output tokens */
|
|
155
|
+
readonly maxOutputTokens: number;
|
|
156
|
+
/** Default temperature */
|
|
157
|
+
readonly temperature: number;
|
|
158
|
+
/**
|
|
159
|
+
* Complete a message sequence.
|
|
160
|
+
* @param messages - Messages in internal Anthropic-style format
|
|
161
|
+
* @param opts - Completion options
|
|
162
|
+
* @returns Response in internal format
|
|
163
|
+
*/
|
|
164
|
+
complete(messages: Message[], opts?: CompletionOptions): Promise<ModelResponse>;
|
|
165
|
+
/**
|
|
166
|
+
* Stream a completion.
|
|
167
|
+
* @param messages - Messages in internal Anthropic-style format
|
|
168
|
+
* @param opts - Completion options
|
|
169
|
+
* @returns Async iterable of chunks in internal format
|
|
170
|
+
*/
|
|
171
|
+
stream(messages: Message[], opts?: CompletionOptions): AsyncIterable<ModelStreamChunk>;
|
|
172
|
+
/**
|
|
173
|
+
* Upload a file to the provider (optional).
|
|
174
|
+
* @param input - File upload input
|
|
175
|
+
* @returns Upload result or null if not supported
|
|
176
|
+
*/
|
|
177
|
+
uploadFile?(input: UploadFileInput): Promise<UploadFileResult | null>;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Provider capabilities declaration.
|
|
181
|
+
* Used to check feature support before making requests.
|
|
182
|
+
*/
|
|
183
|
+
export interface ProviderCapabilities {
|
|
184
|
+
supportsThinking: boolean;
|
|
185
|
+
supportsInterleavedThinking: boolean;
|
|
186
|
+
supportsImages: boolean;
|
|
187
|
+
supportsAudio: boolean;
|
|
188
|
+
supportsFiles: boolean;
|
|
189
|
+
supportsTools: boolean;
|
|
190
|
+
supportsStreaming: boolean;
|
|
191
|
+
supportsCache: boolean;
|
|
192
|
+
maxContextTokens: number;
|
|
193
|
+
maxOutputTokens: number;
|
|
194
|
+
minCacheableTokens?: number;
|
|
195
|
+
maxCacheBreakpoints?: number;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Cache control options.
|
|
199
|
+
*/
|
|
200
|
+
export interface CacheControl {
|
|
201
|
+
type: 'ephemeral';
|
|
202
|
+
ttl?: '5m' | '1h';
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Provider-specific Anthropic options.
|
|
206
|
+
*/
|
|
207
|
+
export interface AnthropicProviderOptions {
|
|
208
|
+
reasoningTransport?: ReasoningTransport;
|
|
209
|
+
extraHeaders?: Record<string, string>;
|
|
210
|
+
extraBody?: Record<string, any>;
|
|
211
|
+
providerOptions?: Record<string, any>;
|
|
212
|
+
multimodal?: MultimodalOptions;
|
|
213
|
+
thinking?: {
|
|
214
|
+
enabled: boolean;
|
|
215
|
+
budgetTokens?: number;
|
|
216
|
+
};
|
|
217
|
+
beta?: {
|
|
218
|
+
interleavedThinking?: boolean;
|
|
219
|
+
filesApi?: boolean;
|
|
220
|
+
extendedCacheTtl?: boolean;
|
|
221
|
+
};
|
|
222
|
+
cache?: {
|
|
223
|
+
breakpoints?: number;
|
|
224
|
+
defaultTtl?: '5m' | '1h';
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Provider-specific OpenAI options.
|
|
229
|
+
* For detailed configuration, see openai.ts ReasoningConfig and ResponsesApiConfig.
|
|
230
|
+
*/
|
|
231
|
+
export interface OpenAIProviderOptions {
|
|
232
|
+
/** API type: 'chat' for Chat Completions, 'responses' for Responses API */
|
|
233
|
+
api?: 'chat' | 'responses';
|
|
234
|
+
reasoningTransport?: ReasoningTransport;
|
|
235
|
+
extraHeaders?: Record<string, string>;
|
|
236
|
+
extraBody?: Record<string, any>;
|
|
237
|
+
providerOptions?: Record<string, any>;
|
|
238
|
+
multimodal?: MultimodalOptions;
|
|
239
|
+
/**
|
|
240
|
+
* Reasoning configuration for OpenAI-compatible providers.
|
|
241
|
+
* Configure field names and request parameters for DeepSeek, GLM, Minimax, Qwen, etc.
|
|
242
|
+
*/
|
|
243
|
+
reasoning?: {
|
|
244
|
+
/** Field name: 'reasoning_content' (DeepSeek/GLM/Qwen) or 'reasoning_details' (Minimax) */
|
|
245
|
+
fieldName?: 'reasoning_content' | 'reasoning_details';
|
|
246
|
+
/** Request parameters to enable reasoning (e.g., { thinking: { type: 'enabled' } }) */
|
|
247
|
+
requestParams?: Record<string, any>;
|
|
248
|
+
/** Strip reasoning from history (required for DeepSeek) */
|
|
249
|
+
stripFromHistory?: boolean;
|
|
250
|
+
};
|
|
251
|
+
/** Responses API specific options */
|
|
252
|
+
responses?: {
|
|
253
|
+
reasoning?: {
|
|
254
|
+
effort: 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
255
|
+
};
|
|
256
|
+
store?: boolean;
|
|
257
|
+
previousResponseId?: string;
|
|
258
|
+
};
|
|
259
|
+
/** Streaming options */
|
|
260
|
+
streamOptions?: {
|
|
261
|
+
includeUsage?: boolean;
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Provider-specific Gemini options.
|
|
266
|
+
*/
|
|
267
|
+
export interface GeminiProviderOptions {
|
|
268
|
+
reasoningTransport?: ReasoningTransport;
|
|
269
|
+
extraHeaders?: Record<string, string>;
|
|
270
|
+
extraBody?: Record<string, any>;
|
|
271
|
+
providerOptions?: Record<string, any>;
|
|
272
|
+
multimodal?: MultimodalOptions;
|
|
273
|
+
thinking?: {
|
|
274
|
+
level: 'minimal' | 'low' | 'medium' | 'high';
|
|
275
|
+
includeThoughts?: boolean;
|
|
276
|
+
};
|
|
277
|
+
cache?: {
|
|
278
|
+
cachedContentName?: string;
|
|
279
|
+
createCache?: {
|
|
280
|
+
displayName: string;
|
|
281
|
+
ttlSeconds: number;
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
mediaResolution?: 'low' | 'medium' | 'high';
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Provider-specific DeepSeek options.
|
|
288
|
+
*/
|
|
289
|
+
export interface DeepSeekProviderOptions {
|
|
290
|
+
reasoningTransport?: ReasoningTransport;
|
|
291
|
+
extraHeaders?: Record<string, string>;
|
|
292
|
+
extraBody?: Record<string, any>;
|
|
293
|
+
providerOptions?: Record<string, any>;
|
|
294
|
+
thinking?: {
|
|
295
|
+
enabled: boolean;
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Provider-specific Qwen options.
|
|
300
|
+
*/
|
|
301
|
+
export interface QwenProviderOptions {
|
|
302
|
+
reasoningTransport?: ReasoningTransport;
|
|
303
|
+
extraHeaders?: Record<string, string>;
|
|
304
|
+
extraBody?: Record<string, any>;
|
|
305
|
+
providerOptions?: Record<string, any>;
|
|
306
|
+
thinking?: {
|
|
307
|
+
enabled: boolean;
|
|
308
|
+
budget?: number;
|
|
309
|
+
};
|
|
310
|
+
region?: 'beijing' | 'singapore' | 'virginia';
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Provider-specific GLM options.
|
|
314
|
+
*/
|
|
315
|
+
export interface GLMProviderOptions {
|
|
316
|
+
reasoningTransport?: ReasoningTransport;
|
|
317
|
+
extraHeaders?: Record<string, string>;
|
|
318
|
+
extraBody?: Record<string, any>;
|
|
319
|
+
providerOptions?: Record<string, any>;
|
|
320
|
+
thinking?: {
|
|
321
|
+
enabled: boolean;
|
|
322
|
+
};
|
|
323
|
+
maxFunctions?: number;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Provider-specific Minimax options.
|
|
327
|
+
*/
|
|
328
|
+
export interface MinimaxProviderOptions {
|
|
329
|
+
reasoningTransport?: ReasoningTransport;
|
|
330
|
+
extraHeaders?: Record<string, string>;
|
|
331
|
+
extraBody?: Record<string, any>;
|
|
332
|
+
providerOptions?: Record<string, any>;
|
|
333
|
+
reasoningSplit?: boolean;
|
|
334
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Provider Adapter Types
|
|
4
|
+
*
|
|
5
|
+
* KODE Agent SDK uses Anthropic-style messages as the internal canonical format.
|
|
6
|
+
* All providers act as adapters that convert to/from this format.
|
|
7
|
+
*
|
|
8
|
+
* Internal Flow:
|
|
9
|
+
* Internal Message[] (Anthropic-style ContentBlocks)
|
|
10
|
+
* -> Provider.formatMessages() -> External API format
|
|
11
|
+
* -> API call
|
|
12
|
+
* -> Response -> normalizeContent() -> Internal ContentBlock[]
|
|
13
|
+
*
|
|
14
|
+
* Provider-Specific Requirements:
|
|
15
|
+
* - Anthropic: Preserve thinking signatures for multi-turn
|
|
16
|
+
* - OpenAI Responses: Use previous_response_id for state
|
|
17
|
+
* - DeepSeek/Qwen: Must NOT include reasoning_content in history
|
|
18
|
+
* - Gemini: Use thinkingLevel (not thinkingBudget) for 3.x
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities for provider implementations.
|
|
3
|
+
*/
|
|
4
|
+
import { ContentBlock, Message, ImageContentBlock, FileContentBlock } from '../../core/types';
|
|
5
|
+
import { ReasoningTransport } from './types';
|
|
6
|
+
export declare function resolveProxyUrl(explicit?: string): string | undefined;
|
|
7
|
+
export declare function getProxyDispatcher(proxyUrl?: string): any | undefined;
|
|
8
|
+
export declare function withProxy(init: RequestInit, dispatcher?: any): RequestInit;
|
|
9
|
+
export declare function normalizeBaseUrl(url: string): string;
|
|
10
|
+
export declare function normalizeOpenAIBaseUrl(url: string): string;
|
|
11
|
+
export declare function normalizeAnthropicBaseUrl(url: string): string;
|
|
12
|
+
export declare function normalizeGeminiBaseUrl(url: string): string;
|
|
13
|
+
export declare function getMessageBlocks(message: Message): ContentBlock[];
|
|
14
|
+
export declare function markTransportIfDegraded(message: Message, blocks: ContentBlock[]): void;
|
|
15
|
+
export declare function joinTextBlocks(blocks: ContentBlock[]): string;
|
|
16
|
+
export declare function formatToolResult(content: any): string;
|
|
17
|
+
export declare function safeJsonStringify(value: any): string;
|
|
18
|
+
export declare const FILE_UNSUPPORTED_TEXT = "[file unsupported] This model does not support PDF input. Please extract text or images first.";
|
|
19
|
+
export declare const IMAGE_UNSUPPORTED_TEXT = "[image unsupported] This model does not support image URLs; please provide base64 data if supported.";
|
|
20
|
+
export declare const AUDIO_UNSUPPORTED_TEXT = "[audio unsupported] This model does not support audio input; please provide a text transcript instead.";
|
|
21
|
+
export declare function concatTextWithReasoning(blocks: ContentBlock[], reasoningTransport?: ReasoningTransport): string;
|
|
22
|
+
export declare function joinReasoningBlocks(blocks: ContentBlock[]): string;
|
|
23
|
+
/**
|
|
24
|
+
* Parse <think> tags in text blocks and convert to reasoning blocks.
|
|
25
|
+
*/
|
|
26
|
+
export declare function normalizeThinkBlocks(blocks: ContentBlock[], reasoningTransport?: ReasoningTransport): ContentBlock[];
|
|
27
|
+
export declare function splitThinkText(text: string): ContentBlock[];
|
|
28
|
+
/**
|
|
29
|
+
* Extract reasoning details from OpenAI response (for reasoning models).
|
|
30
|
+
*/
|
|
31
|
+
export declare function extractReasoningDetails(message: any): ContentBlock[];
|
|
32
|
+
export declare function buildGeminiImagePart(block: ImageContentBlock): any | null;
|
|
33
|
+
export declare function buildGeminiFilePart(block: FileContentBlock): any | null;
|
|
34
|
+
export declare function sanitizeGeminiSchema(schema: any): any;
|
|
35
|
+
export declare function hasAnthropicFileBlocks(messages: Message[]): boolean;
|
|
36
|
+
export declare function mergeAnthropicBetaHeader(existing: string | undefined, entries: string[]): string | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Normalize Anthropic response content to internal format.
|
|
39
|
+
*/
|
|
40
|
+
export declare function normalizeAnthropicContent(content: any[], reasoningTransport?: ReasoningTransport): ContentBlock[];
|
|
41
|
+
/**
|
|
42
|
+
* Normalize a single Anthropic content block.
|
|
43
|
+
* Handles thinking blocks with signature preservation.
|
|
44
|
+
*/
|
|
45
|
+
export declare function normalizeAnthropicContentBlock(block: any, reasoningTransport?: ReasoningTransport): ContentBlock | null;
|
|
46
|
+
/**
|
|
47
|
+
* Normalize Anthropic streaming delta.
|
|
48
|
+
*/
|
|
49
|
+
export declare function normalizeAnthropicDelta(delta: any): {
|
|
50
|
+
type: 'text_delta' | 'input_json_delta' | 'reasoning_delta';
|
|
51
|
+
text?: string;
|
|
52
|
+
partial_json?: string;
|
|
53
|
+
};
|