kimi-vercel-ai-sdk-provider 0.3.0 → 0.5.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/README.md +567 -17
- package/dist/index.d.mts +1750 -3
- package/dist/index.d.ts +1750 -3
- package/dist/index.js +2317 -161
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2292 -160
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/auto-detect.test.ts +140 -0
- package/src/__tests__/code-validation.test.ts +267 -0
- package/src/__tests__/ensemble.test.ts +242 -0
- package/src/__tests__/file-cache.test.ts +310 -0
- package/src/__tests__/model-config.test.ts +120 -0
- package/src/__tests__/multi-agent.test.ts +201 -0
- package/src/__tests__/project-tools.test.ts +181 -0
- package/src/__tests__/reasoning-utils.test.ts +164 -0
- package/src/__tests__/tools.test.ts +76 -8
- package/src/chat/kimi-chat-language-model.ts +21 -2
- package/src/chat/kimi-chat-settings.ts +15 -1
- package/src/code-validation/detector.ts +319 -0
- package/src/code-validation/index.ts +31 -0
- package/src/code-validation/types.ts +291 -0
- package/src/code-validation/validator.ts +547 -0
- package/src/core/errors.ts +91 -0
- package/src/core/index.ts +15 -3
- package/src/core/types.ts +57 -2
- package/src/core/utils.ts +138 -0
- package/src/ensemble/index.ts +17 -0
- package/src/ensemble/multi-sampler.ts +433 -0
- package/src/ensemble/types.ts +279 -0
- package/src/files/attachment-processor.ts +51 -4
- package/src/files/file-cache.ts +260 -0
- package/src/files/index.ts +16 -1
- package/src/index.ts +102 -3
- package/src/kimi-provider.ts +354 -1
- package/src/multi-agent/index.ts +21 -0
- package/src/multi-agent/types.ts +312 -0
- package/src/multi-agent/workflows.ts +539 -0
- package/src/project-tools/index.ts +16 -0
- package/src/project-tools/scaffolder.ts +494 -0
- package/src/project-tools/types.ts +244 -0
- package/src/tools/auto-detect.ts +276 -0
- package/src/tools/index.ts +6 -2
- package/src/tools/prepare-tools.ts +179 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,1238 @@
|
|
|
1
|
-
import { LanguageModelV3, LanguageModelV3Usage, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, ProviderV3 } from '@ai-sdk/provider';
|
|
1
|
+
import { LanguageModelV3ToolCall, LanguageModelV3ToolResult, LanguageModelV3, LanguageModelV3Usage, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, ProviderV3 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
3
|
import { z } from 'zod/v4';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Types for code validation functionality.
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Supported programming languages for code validation.
|
|
11
|
+
*/
|
|
12
|
+
type SupportedLanguage = 'javascript' | 'typescript' | 'python' | 'java' | 'cpp' | 'go' | 'rust' | 'ruby' | 'php' | 'auto';
|
|
13
|
+
/**
|
|
14
|
+
* Validation strictness levels.
|
|
15
|
+
*/
|
|
16
|
+
type ValidationStrictness = 'lenient' | 'strict' | 'maximum';
|
|
17
|
+
/**
|
|
18
|
+
* Configuration for code validation.
|
|
19
|
+
*/
|
|
20
|
+
interface CodeValidationConfig {
|
|
21
|
+
/**
|
|
22
|
+
* Enable automatic code validation.
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
enabled: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Maximum number of attempts to fix errors.
|
|
28
|
+
* @default 3
|
|
29
|
+
*/
|
|
30
|
+
maxAttempts?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Language to validate (auto-detected if not specified).
|
|
33
|
+
* @default 'auto'
|
|
34
|
+
*/
|
|
35
|
+
language?: SupportedLanguage;
|
|
36
|
+
/**
|
|
37
|
+
* Timeout for each code execution attempt (ms).
|
|
38
|
+
* @default 30000
|
|
39
|
+
*/
|
|
40
|
+
executionTimeoutMs?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Whether to include test cases in validation.
|
|
43
|
+
* If true, the provider will look for test patterns in the prompt.
|
|
44
|
+
* @default true
|
|
45
|
+
*/
|
|
46
|
+
includeTests?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Validation strictness.
|
|
49
|
+
* - 'lenient': Check for runtime errors only
|
|
50
|
+
* - 'strict': Check syntax + runtime + style
|
|
51
|
+
* - 'maximum': Also verify output correctness
|
|
52
|
+
* @default 'strict'
|
|
53
|
+
*/
|
|
54
|
+
strictness?: ValidationStrictness;
|
|
55
|
+
/**
|
|
56
|
+
* Custom validation function for specialized needs.
|
|
57
|
+
*/
|
|
58
|
+
customValidator?: (code: string, language: string) => Promise<ValidationResult>;
|
|
59
|
+
/**
|
|
60
|
+
* Whether to return the fixed code even if validation fails.
|
|
61
|
+
* @default true
|
|
62
|
+
*/
|
|
63
|
+
returnPartialFix?: boolean;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Types of validation errors.
|
|
67
|
+
*/
|
|
68
|
+
type ValidationErrorType = 'syntax' | 'runtime' | 'timeout' | 'test' | 'style' | 'logic';
|
|
69
|
+
/**
|
|
70
|
+
* Severity of validation errors.
|
|
71
|
+
*/
|
|
72
|
+
type ValidationSeverity = 'error' | 'warning' | 'info';
|
|
73
|
+
/**
|
|
74
|
+
* A single validation error.
|
|
75
|
+
*/
|
|
76
|
+
interface ValidationError {
|
|
77
|
+
/**
|
|
78
|
+
* Type of the error.
|
|
79
|
+
*/
|
|
80
|
+
type: ValidationErrorType;
|
|
81
|
+
/**
|
|
82
|
+
* Error message.
|
|
83
|
+
*/
|
|
84
|
+
message: string;
|
|
85
|
+
/**
|
|
86
|
+
* Line number where the error occurred (1-indexed).
|
|
87
|
+
*/
|
|
88
|
+
line?: number;
|
|
89
|
+
/**
|
|
90
|
+
* Column number where the error occurred (1-indexed).
|
|
91
|
+
*/
|
|
92
|
+
column?: number;
|
|
93
|
+
/**
|
|
94
|
+
* Severity of the error.
|
|
95
|
+
*/
|
|
96
|
+
severity: ValidationSeverity;
|
|
97
|
+
/**
|
|
98
|
+
* The problematic code snippet.
|
|
99
|
+
*/
|
|
100
|
+
snippet?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Suggested fix (if available).
|
|
103
|
+
*/
|
|
104
|
+
suggestion?: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Result of validating and potentially fixing code.
|
|
108
|
+
*/
|
|
109
|
+
interface ValidationResult {
|
|
110
|
+
/**
|
|
111
|
+
* Whether the final code is valid.
|
|
112
|
+
*/
|
|
113
|
+
valid: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* All errors encountered during validation.
|
|
116
|
+
*/
|
|
117
|
+
errors: ValidationError[];
|
|
118
|
+
/**
|
|
119
|
+
* Warnings that don't prevent execution.
|
|
120
|
+
*/
|
|
121
|
+
warnings: ValidationError[];
|
|
122
|
+
/**
|
|
123
|
+
* Output from successful execution (if any).
|
|
124
|
+
*/
|
|
125
|
+
output?: string;
|
|
126
|
+
/**
|
|
127
|
+
* Time taken for execution (ms).
|
|
128
|
+
*/
|
|
129
|
+
executionTimeMs?: number;
|
|
130
|
+
/**
|
|
131
|
+
* Number of validation/fix attempts made.
|
|
132
|
+
*/
|
|
133
|
+
attempts: number;
|
|
134
|
+
/**
|
|
135
|
+
* The final code after any fixes.
|
|
136
|
+
*/
|
|
137
|
+
finalCode: string;
|
|
138
|
+
/**
|
|
139
|
+
* The original code before any fixes.
|
|
140
|
+
*/
|
|
141
|
+
originalCode: string;
|
|
142
|
+
/**
|
|
143
|
+
* Language that was detected/used.
|
|
144
|
+
*/
|
|
145
|
+
language: string;
|
|
146
|
+
/**
|
|
147
|
+
* History of code changes during fix attempts.
|
|
148
|
+
*/
|
|
149
|
+
fixHistory?: FixAttempt[];
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* A single fix attempt.
|
|
153
|
+
*/
|
|
154
|
+
interface FixAttempt {
|
|
155
|
+
/**
|
|
156
|
+
* Attempt number (1-indexed).
|
|
157
|
+
*/
|
|
158
|
+
attempt: number;
|
|
159
|
+
/**
|
|
160
|
+
* The code before this fix.
|
|
161
|
+
*/
|
|
162
|
+
codeBefore: string;
|
|
163
|
+
/**
|
|
164
|
+
* The code after this fix.
|
|
165
|
+
*/
|
|
166
|
+
codeAfter: string;
|
|
167
|
+
/**
|
|
168
|
+
* Errors that were addressed.
|
|
169
|
+
*/
|
|
170
|
+
errorsAddressed: ValidationError[];
|
|
171
|
+
/**
|
|
172
|
+
* Whether this fix resolved all errors.
|
|
173
|
+
*/
|
|
174
|
+
success: boolean;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Result of language detection.
|
|
178
|
+
*/
|
|
179
|
+
interface LanguageDetectionResult {
|
|
180
|
+
/**
|
|
181
|
+
* Detected language.
|
|
182
|
+
*/
|
|
183
|
+
language: SupportedLanguage;
|
|
184
|
+
/**
|
|
185
|
+
* Confidence score (0-1).
|
|
186
|
+
*/
|
|
187
|
+
confidence: number;
|
|
188
|
+
/**
|
|
189
|
+
* Indicators that led to this detection.
|
|
190
|
+
*/
|
|
191
|
+
indicators: string[];
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Result of code extraction from text.
|
|
195
|
+
*/
|
|
196
|
+
interface CodeExtractionResult {
|
|
197
|
+
/**
|
|
198
|
+
* Extracted code blocks.
|
|
199
|
+
*/
|
|
200
|
+
blocks: CodeBlock[];
|
|
201
|
+
/**
|
|
202
|
+
* Whether any code was found.
|
|
203
|
+
*/
|
|
204
|
+
hasCode: boolean;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* A code block extracted from text.
|
|
208
|
+
*/
|
|
209
|
+
interface CodeBlock {
|
|
210
|
+
/**
|
|
211
|
+
* The code content.
|
|
212
|
+
*/
|
|
213
|
+
code: string;
|
|
214
|
+
/**
|
|
215
|
+
* Language annotation (if provided).
|
|
216
|
+
*/
|
|
217
|
+
language?: string;
|
|
218
|
+
/**
|
|
219
|
+
* Start position in the original text.
|
|
220
|
+
*/
|
|
221
|
+
startIndex: number;
|
|
222
|
+
/**
|
|
223
|
+
* End position in the original text.
|
|
224
|
+
*/
|
|
225
|
+
endIndex: number;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Code validator implementation.
|
|
230
|
+
* @module
|
|
231
|
+
*/
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Function to generate text from a model.
|
|
235
|
+
*/
|
|
236
|
+
type GenerateTextFunction$2 = (prompt: string) => Promise<{
|
|
237
|
+
text: string;
|
|
238
|
+
toolCalls?: unknown[];
|
|
239
|
+
toolResults?: unknown[];
|
|
240
|
+
}>;
|
|
241
|
+
/**
|
|
242
|
+
* Options for creating a code validator.
|
|
243
|
+
*/
|
|
244
|
+
interface CodeValidatorOptions {
|
|
245
|
+
/**
|
|
246
|
+
* Function to generate text (for fix attempts).
|
|
247
|
+
*/
|
|
248
|
+
generateText: GenerateTextFunction$2;
|
|
249
|
+
/**
|
|
250
|
+
* Function to execute code using the code interpreter.
|
|
251
|
+
* Should return output or throw on error.
|
|
252
|
+
*/
|
|
253
|
+
executeCode?: (code: string, language: string) => Promise<string>;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Validates code and attempts to fix errors automatically.
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```ts
|
|
260
|
+
* const validator = new CodeValidator({
|
|
261
|
+
* generateText: async (prompt) => {
|
|
262
|
+
* const result = await generateText({ model, prompt });
|
|
263
|
+
* return { text: result.text };
|
|
264
|
+
* },
|
|
265
|
+
* });
|
|
266
|
+
*
|
|
267
|
+
* const result = await validator.validate(code, {
|
|
268
|
+
* enabled: true,
|
|
269
|
+
* maxAttempts: 3,
|
|
270
|
+
* language: 'javascript',
|
|
271
|
+
* });
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
declare class CodeValidator {
|
|
275
|
+
private generateText;
|
|
276
|
+
private executeCode?;
|
|
277
|
+
constructor(options: CodeValidatorOptions);
|
|
278
|
+
/**
|
|
279
|
+
* Validate code and optionally fix errors.
|
|
280
|
+
*
|
|
281
|
+
* @param code - The code to validate
|
|
282
|
+
* @param config - Validation configuration
|
|
283
|
+
* @param originalPrompt - The original user prompt (for context in fixes)
|
|
284
|
+
* @returns Validation result
|
|
285
|
+
*/
|
|
286
|
+
validate(code: string, config: CodeValidationConfig, originalPrompt?: string): Promise<ValidationResult>;
|
|
287
|
+
/**
|
|
288
|
+
* Validate code without attempting fixes.
|
|
289
|
+
*/
|
|
290
|
+
private validateCode;
|
|
291
|
+
/**
|
|
292
|
+
* Perform static analysis on code.
|
|
293
|
+
*/
|
|
294
|
+
private performStaticAnalysis;
|
|
295
|
+
/**
|
|
296
|
+
* Analyze JavaScript/TypeScript code.
|
|
297
|
+
*/
|
|
298
|
+
private analyzeJavaScript;
|
|
299
|
+
/**
|
|
300
|
+
* Analyze Python code.
|
|
301
|
+
*/
|
|
302
|
+
private analyzePython;
|
|
303
|
+
/**
|
|
304
|
+
* Generic code analysis.
|
|
305
|
+
*/
|
|
306
|
+
private analyzeGeneric;
|
|
307
|
+
/**
|
|
308
|
+
* Check bracket balance in code.
|
|
309
|
+
*/
|
|
310
|
+
private checkBracketBalance;
|
|
311
|
+
/**
|
|
312
|
+
* Detect runtime errors from execution output.
|
|
313
|
+
*/
|
|
314
|
+
private detectRuntimeErrors;
|
|
315
|
+
/**
|
|
316
|
+
* Use LLM to validate code.
|
|
317
|
+
*/
|
|
318
|
+
private validateWithLLM;
|
|
319
|
+
/**
|
|
320
|
+
* Attempt to fix errors in code.
|
|
321
|
+
*/
|
|
322
|
+
private attemptFix;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Create a simple validation result for code that passed without issues.
|
|
326
|
+
*/
|
|
327
|
+
declare function createPassedValidationResult(code: string, language: string, output?: string): ValidationResult;
|
|
328
|
+
/**
|
|
329
|
+
* Create a validation result for code that failed.
|
|
330
|
+
*/
|
|
331
|
+
declare function createFailedValidationResult(code: string, language: string, errors: ValidationError[]): ValidationResult;
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Language detection and code extraction utilities.
|
|
335
|
+
* @module
|
|
336
|
+
*/
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Detect the programming language of a code snippet.
|
|
340
|
+
*
|
|
341
|
+
* @param code - The code to analyze
|
|
342
|
+
* @returns Detection result with language, confidence, and indicators
|
|
343
|
+
*/
|
|
344
|
+
declare function detectLanguage(code: string): LanguageDetectionResult;
|
|
345
|
+
/**
|
|
346
|
+
* Extract code blocks from text (including markdown code fences).
|
|
347
|
+
*
|
|
348
|
+
* @param text - Text that may contain code blocks
|
|
349
|
+
* @returns Extraction result with code blocks
|
|
350
|
+
*/
|
|
351
|
+
declare function extractCodeBlocks(text: string): CodeExtractionResult;
|
|
352
|
+
/**
|
|
353
|
+
* Extract the primary code block from text.
|
|
354
|
+
* Returns the largest/most significant code block.
|
|
355
|
+
*
|
|
356
|
+
* @param text - Text that may contain code blocks
|
|
357
|
+
* @returns The primary code or undefined if no code found
|
|
358
|
+
*/
|
|
359
|
+
declare function extractPrimaryCode(text: string): string | undefined;
|
|
360
|
+
/**
|
|
361
|
+
* Check if text contains code.
|
|
362
|
+
*
|
|
363
|
+
* @param text - Text to check
|
|
364
|
+
* @returns True if text contains code
|
|
365
|
+
*/
|
|
366
|
+
declare function containsCode(text: string): boolean;
|
|
367
|
+
/**
|
|
368
|
+
* Get file extension for a language.
|
|
369
|
+
*
|
|
370
|
+
* @param language - The programming language
|
|
371
|
+
* @returns File extension (without dot)
|
|
372
|
+
*/
|
|
373
|
+
declare function getFileExtension(language: SupportedLanguage): string;
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Types for ensemble/multi-sampling functionality.
|
|
377
|
+
* @module
|
|
378
|
+
*/
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Simple usage type compatible with common AI SDK patterns.
|
|
382
|
+
* This is independent from the provider-specific V3Usage type.
|
|
383
|
+
*/
|
|
384
|
+
interface LanguageModelUsage$1 {
|
|
385
|
+
promptTokens: number;
|
|
386
|
+
completionTokens: number;
|
|
387
|
+
totalTokens: number;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Re-export types for convenience.
|
|
391
|
+
*/
|
|
392
|
+
type ToolCall = LanguageModelV3ToolCall;
|
|
393
|
+
type ToolResult = LanguageModelV3ToolResult;
|
|
394
|
+
/**
|
|
395
|
+
* Selection strategy for choosing the best response from multiple samples.
|
|
396
|
+
*/
|
|
397
|
+
type SelectionStrategy = 'first' | 'vote' | 'best' | 'all';
|
|
398
|
+
/**
|
|
399
|
+
* Scoring heuristic for the 'best' selection strategy.
|
|
400
|
+
*/
|
|
401
|
+
type ScoringHeuristic = 'length' | 'confidence' | 'code' | 'custom';
|
|
402
|
+
/**
|
|
403
|
+
* Configuration for ensemble/multi-sampling.
|
|
404
|
+
*/
|
|
405
|
+
interface EnsembleConfig {
|
|
406
|
+
/**
|
|
407
|
+
* Number of parallel samples to generate.
|
|
408
|
+
* @default 3
|
|
409
|
+
*/
|
|
410
|
+
n: number;
|
|
411
|
+
/**
|
|
412
|
+
* Strategy for selecting the best result.
|
|
413
|
+
* - 'first': Return the first successful response
|
|
414
|
+
* - 'vote': Return the most common answer (majority voting)
|
|
415
|
+
* - 'best': Use heuristic scoring to pick the best
|
|
416
|
+
* - 'all': Return all responses (for manual selection)
|
|
417
|
+
* @default 'best'
|
|
418
|
+
*/
|
|
419
|
+
selectionStrategy?: SelectionStrategy;
|
|
420
|
+
/**
|
|
421
|
+
* Temperature variation for diversity.
|
|
422
|
+
* Each sample gets temperature = baseTemp + (i * variance)
|
|
423
|
+
* @default 0.1
|
|
424
|
+
*/
|
|
425
|
+
temperatureVariance?: number;
|
|
426
|
+
/**
|
|
427
|
+
* For 'best' strategy, the scoring heuristic.
|
|
428
|
+
* - 'length': Prefer shorter responses
|
|
429
|
+
* - 'confidence': Prefer responses with higher token count
|
|
430
|
+
* - 'code': Prefer responses with fewer error patterns
|
|
431
|
+
* - 'custom': Use custom scorer function
|
|
432
|
+
* @default 'confidence'
|
|
433
|
+
*/
|
|
434
|
+
scoringHeuristic?: ScoringHeuristic;
|
|
435
|
+
/**
|
|
436
|
+
* Custom scoring function for 'custom' heuristic.
|
|
437
|
+
* Higher scores are better.
|
|
438
|
+
*/
|
|
439
|
+
customScorer?: (response: EnsembleResponse) => number;
|
|
440
|
+
/**
|
|
441
|
+
* Maximum time to wait for all samples (ms).
|
|
442
|
+
* @default 60000
|
|
443
|
+
*/
|
|
444
|
+
timeoutMs?: number;
|
|
445
|
+
/**
|
|
446
|
+
* Whether to continue if some samples fail.
|
|
447
|
+
* @default true
|
|
448
|
+
*/
|
|
449
|
+
allowPartialFailure?: boolean;
|
|
450
|
+
/**
|
|
451
|
+
* Minimum number of successful samples required.
|
|
452
|
+
* Only relevant when allowPartialFailure is true.
|
|
453
|
+
* @default 1
|
|
454
|
+
*/
|
|
455
|
+
minSuccessfulSamples?: number;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* A single response from the ensemble.
|
|
459
|
+
*/
|
|
460
|
+
interface EnsembleResponse {
|
|
461
|
+
/**
|
|
462
|
+
* The generated text.
|
|
463
|
+
*/
|
|
464
|
+
text: string;
|
|
465
|
+
/**
|
|
466
|
+
* Reasoning content (for thinking models).
|
|
467
|
+
*/
|
|
468
|
+
reasoning?: string;
|
|
469
|
+
/**
|
|
470
|
+
* Tool calls made during generation.
|
|
471
|
+
*/
|
|
472
|
+
toolCalls?: ToolCall[];
|
|
473
|
+
/**
|
|
474
|
+
* Results of tool executions.
|
|
475
|
+
*/
|
|
476
|
+
toolResults?: ToolResult[];
|
|
477
|
+
/**
|
|
478
|
+
* Token usage for this response.
|
|
479
|
+
*/
|
|
480
|
+
usage?: LanguageModelUsage$1;
|
|
481
|
+
/**
|
|
482
|
+
* Score assigned to this response (if scoring was applied).
|
|
483
|
+
*/
|
|
484
|
+
score?: number;
|
|
485
|
+
/**
|
|
486
|
+
* Index of this sample in the ensemble.
|
|
487
|
+
*/
|
|
488
|
+
sampleIndex: number;
|
|
489
|
+
/**
|
|
490
|
+
* Temperature used for this sample.
|
|
491
|
+
*/
|
|
492
|
+
temperature: number;
|
|
493
|
+
/**
|
|
494
|
+
* Reason the generation finished.
|
|
495
|
+
*/
|
|
496
|
+
finishReason: string;
|
|
497
|
+
/**
|
|
498
|
+
* Whether this sample completed successfully.
|
|
499
|
+
*/
|
|
500
|
+
success: boolean;
|
|
501
|
+
/**
|
|
502
|
+
* Error message if the sample failed.
|
|
503
|
+
*/
|
|
504
|
+
error?: string;
|
|
505
|
+
/**
|
|
506
|
+
* Time taken to generate this response (ms).
|
|
507
|
+
*/
|
|
508
|
+
durationMs?: number;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Metadata about the ensemble execution.
|
|
512
|
+
*/
|
|
513
|
+
interface EnsembleMetadata {
|
|
514
|
+
/**
|
|
515
|
+
* Number of samples requested.
|
|
516
|
+
*/
|
|
517
|
+
nRequested: number;
|
|
518
|
+
/**
|
|
519
|
+
* Number of samples that completed successfully.
|
|
520
|
+
*/
|
|
521
|
+
nCompleted: number;
|
|
522
|
+
/**
|
|
523
|
+
* Number of samples that failed.
|
|
524
|
+
*/
|
|
525
|
+
nFailed: number;
|
|
526
|
+
/**
|
|
527
|
+
* Selection strategy used.
|
|
528
|
+
*/
|
|
529
|
+
selectionStrategy: SelectionStrategy;
|
|
530
|
+
/**
|
|
531
|
+
* Index of the winning sample.
|
|
532
|
+
*/
|
|
533
|
+
winningIndex: number;
|
|
534
|
+
/**
|
|
535
|
+
* Scores of all samples (if scoring was applied).
|
|
536
|
+
*/
|
|
537
|
+
scores?: number[];
|
|
538
|
+
/**
|
|
539
|
+
* Total time for ensemble execution (ms).
|
|
540
|
+
*/
|
|
541
|
+
durationMs: number;
|
|
542
|
+
/**
|
|
543
|
+
* Model ID used.
|
|
544
|
+
*/
|
|
545
|
+
modelId: string;
|
|
546
|
+
/**
|
|
547
|
+
* Aggregated token usage across all samples.
|
|
548
|
+
*/
|
|
549
|
+
totalUsage: LanguageModelUsage$1;
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Result of an ensemble generation.
|
|
553
|
+
*/
|
|
554
|
+
interface EnsembleResult {
|
|
555
|
+
/**
|
|
556
|
+
* The selected best response text.
|
|
557
|
+
*/
|
|
558
|
+
text: string;
|
|
559
|
+
/**
|
|
560
|
+
* Reasoning content from the best response.
|
|
561
|
+
*/
|
|
562
|
+
reasoning?: string;
|
|
563
|
+
/**
|
|
564
|
+
* Tool calls from the best response.
|
|
565
|
+
*/
|
|
566
|
+
toolCalls?: ToolCall[];
|
|
567
|
+
/**
|
|
568
|
+
* Tool results from the best response.
|
|
569
|
+
*/
|
|
570
|
+
toolResults?: ToolResult[];
|
|
571
|
+
/**
|
|
572
|
+
* Token usage from the best response.
|
|
573
|
+
*/
|
|
574
|
+
usage: LanguageModelUsage$1;
|
|
575
|
+
/**
|
|
576
|
+
* All generated responses (populated for 'all' strategy).
|
|
577
|
+
*/
|
|
578
|
+
alternatives?: EnsembleResponse[];
|
|
579
|
+
/**
|
|
580
|
+
* Metadata about the ensemble execution.
|
|
581
|
+
*/
|
|
582
|
+
metadata: EnsembleMetadata;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Multi-sampler implementation for ensemble generation.
|
|
587
|
+
* @module
|
|
588
|
+
*/
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* A function that generates a single response.
|
|
592
|
+
*/
|
|
593
|
+
type GenerateFunction = (options: {
|
|
594
|
+
temperature: number;
|
|
595
|
+
sampleIndex: number;
|
|
596
|
+
}) => Promise<{
|
|
597
|
+
text: string;
|
|
598
|
+
reasoning?: string;
|
|
599
|
+
toolCalls?: unknown[];
|
|
600
|
+
toolResults?: unknown[];
|
|
601
|
+
usage?: LanguageModelUsage$1;
|
|
602
|
+
finishReason: string;
|
|
603
|
+
}>;
|
|
604
|
+
/**
|
|
605
|
+
* Options for creating a multi-sampler.
|
|
606
|
+
*/
|
|
607
|
+
interface MultiSamplerOptions {
|
|
608
|
+
/**
|
|
609
|
+
* The model ID being used.
|
|
610
|
+
*/
|
|
611
|
+
modelId: string;
|
|
612
|
+
/**
|
|
613
|
+
* Base temperature for generation.
|
|
614
|
+
*/
|
|
615
|
+
baseTemperature?: number;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Multi-sampler for generating multiple responses and selecting the best one.
|
|
619
|
+
*
|
|
620
|
+
* @example
|
|
621
|
+
* ```ts
|
|
622
|
+
* const sampler = new MultiSampler({ modelId: 'kimi-k2.5' });
|
|
623
|
+
* const result = await sampler.generate(generateFn, {
|
|
624
|
+
* n: 3,
|
|
625
|
+
* selectionStrategy: 'best',
|
|
626
|
+
* scoringHeuristic: 'code',
|
|
627
|
+
* });
|
|
628
|
+
* ```
|
|
629
|
+
*/
|
|
630
|
+
declare class MultiSampler {
|
|
631
|
+
private modelId;
|
|
632
|
+
private baseTemperature;
|
|
633
|
+
constructor(options: MultiSamplerOptions);
|
|
634
|
+
/**
|
|
635
|
+
* Generate multiple samples and select the best one.
|
|
636
|
+
*
|
|
637
|
+
* @param generateFn - Function to generate a single response
|
|
638
|
+
* @param config - Ensemble configuration
|
|
639
|
+
* @returns The ensemble result
|
|
640
|
+
*/
|
|
641
|
+
generate(generateFn: GenerateFunction, config: EnsembleConfig): Promise<EnsembleResult>;
|
|
642
|
+
/**
|
|
643
|
+
* Select the best response based on the strategy.
|
|
644
|
+
*/
|
|
645
|
+
private selectBest;
|
|
646
|
+
/**
|
|
647
|
+
* Calculate score for a response based on the heuristic.
|
|
648
|
+
*/
|
|
649
|
+
private calculateScore;
|
|
650
|
+
/**
|
|
651
|
+
* Score code quality based on heuristics.
|
|
652
|
+
*/
|
|
653
|
+
private scoreCodeQuality;
|
|
654
|
+
/**
|
|
655
|
+
* Select the most common response (majority voting).
|
|
656
|
+
*/
|
|
657
|
+
private majorityVote;
|
|
658
|
+
/**
|
|
659
|
+
* Aggregate usage across all responses.
|
|
660
|
+
*/
|
|
661
|
+
private aggregateUsage;
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Create a simple ensemble result from a single response.
|
|
665
|
+
* Useful for when ensemble is disabled but consistent return types are needed.
|
|
666
|
+
*/
|
|
667
|
+
declare function createSingletonEnsembleResult(response: {
|
|
668
|
+
text: string;
|
|
669
|
+
reasoning?: string;
|
|
670
|
+
toolCalls?: unknown[];
|
|
671
|
+
toolResults?: unknown[];
|
|
672
|
+
usage?: LanguageModelUsage$1;
|
|
673
|
+
finishReason: string;
|
|
674
|
+
}, modelId: string, durationMs: number): EnsembleResult;
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* Types for multi-agent collaboration functionality.
|
|
678
|
+
* @module
|
|
679
|
+
*/
|
|
680
|
+
/**
|
|
681
|
+
* Simple usage type compatible with common AI SDK patterns.
|
|
682
|
+
* This is independent from the provider-specific V3Usage type.
|
|
683
|
+
*/
|
|
684
|
+
interface LanguageModelUsage {
|
|
685
|
+
promptTokens: number;
|
|
686
|
+
completionTokens: number;
|
|
687
|
+
totalTokens: number;
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Available multi-agent workflow types.
|
|
691
|
+
*/
|
|
692
|
+
type WorkflowType = 'planner-executor' | 'proposer-critic' | 'debate' | 'custom';
|
|
693
|
+
/**
|
|
694
|
+
* Configuration for multi-agent collaboration.
|
|
695
|
+
*/
|
|
696
|
+
interface MultiAgentConfig {
|
|
697
|
+
/**
|
|
698
|
+
* Multi-agent workflow type.
|
|
699
|
+
* - 'planner-executor': One agent plans, another executes
|
|
700
|
+
* - 'proposer-critic': One proposes, another critiques and refines
|
|
701
|
+
* - 'debate': Multiple agents debate and converge on answer
|
|
702
|
+
* - 'custom': Use custom workflow
|
|
703
|
+
* @default 'planner-executor'
|
|
704
|
+
*/
|
|
705
|
+
workflow: WorkflowType;
|
|
706
|
+
/**
|
|
707
|
+
* Model for the first agent (typically thinking/planning).
|
|
708
|
+
* @default 'kimi-k2.5-thinking'
|
|
709
|
+
*/
|
|
710
|
+
modelA?: string;
|
|
711
|
+
/**
|
|
712
|
+
* Model for the second agent (typically coding/action).
|
|
713
|
+
* @default 'kimi-k2.5'
|
|
714
|
+
*/
|
|
715
|
+
modelB?: string;
|
|
716
|
+
/**
|
|
717
|
+
* Number of refinement iterations for proposer-critic.
|
|
718
|
+
* @default 2
|
|
719
|
+
*/
|
|
720
|
+
iterations?: number;
|
|
721
|
+
/**
|
|
722
|
+
* Include code validation in the workflow.
|
|
723
|
+
* @default false
|
|
724
|
+
*/
|
|
725
|
+
validateCode?: boolean;
|
|
726
|
+
/**
|
|
727
|
+
* Maximum time for the entire workflow (ms).
|
|
728
|
+
* @default 120000
|
|
729
|
+
*/
|
|
730
|
+
timeoutMs?: number;
|
|
731
|
+
/**
|
|
732
|
+
* Custom workflow function.
|
|
733
|
+
*/
|
|
734
|
+
customWorkflow?: (prompt: string, context: WorkflowContext) => Promise<MultiAgentResult>;
|
|
735
|
+
/**
|
|
736
|
+
* Enable verbose logging of intermediate steps.
|
|
737
|
+
* @default false
|
|
738
|
+
*/
|
|
739
|
+
verbose?: boolean;
|
|
740
|
+
/**
|
|
741
|
+
* System prompts for agents.
|
|
742
|
+
*/
|
|
743
|
+
systemPrompts?: {
|
|
744
|
+
planner?: string;
|
|
745
|
+
executor?: string;
|
|
746
|
+
proposer?: string;
|
|
747
|
+
critic?: string;
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* A single step in the multi-agent workflow.
|
|
752
|
+
*/
|
|
753
|
+
interface AgentStep {
|
|
754
|
+
/**
|
|
755
|
+
* Agent identifier (A, B, or custom name).
|
|
756
|
+
*/
|
|
757
|
+
agent: string;
|
|
758
|
+
/**
|
|
759
|
+
* Role of the agent in this step.
|
|
760
|
+
*/
|
|
761
|
+
role: 'planner' | 'executor' | 'proposer' | 'critic' | 'validator' | 'custom';
|
|
762
|
+
/**
|
|
763
|
+
* Action performed.
|
|
764
|
+
*/
|
|
765
|
+
action: string;
|
|
766
|
+
/**
|
|
767
|
+
* Input provided to the agent.
|
|
768
|
+
*/
|
|
769
|
+
input?: string;
|
|
770
|
+
/**
|
|
771
|
+
* Output from the agent.
|
|
772
|
+
*/
|
|
773
|
+
output: string;
|
|
774
|
+
/**
|
|
775
|
+
* Timestamp when this step completed.
|
|
776
|
+
*/
|
|
777
|
+
timestamp: number;
|
|
778
|
+
/**
|
|
779
|
+
* Duration of this step (ms).
|
|
780
|
+
*/
|
|
781
|
+
durationMs: number;
|
|
782
|
+
/**
|
|
783
|
+
* Token usage for this step.
|
|
784
|
+
*/
|
|
785
|
+
usage?: LanguageModelUsage;
|
|
786
|
+
/**
|
|
787
|
+
* Model used for this step.
|
|
788
|
+
*/
|
|
789
|
+
model?: string;
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Metadata about the multi-agent execution.
|
|
793
|
+
*/
|
|
794
|
+
interface MultiAgentMetadata {
|
|
795
|
+
/**
|
|
796
|
+
* Workflow type used.
|
|
797
|
+
*/
|
|
798
|
+
workflow: WorkflowType;
|
|
799
|
+
/**
|
|
800
|
+
* Total number of iterations/steps.
|
|
801
|
+
*/
|
|
802
|
+
iterations: number;
|
|
803
|
+
/**
|
|
804
|
+
* Total duration (ms).
|
|
805
|
+
*/
|
|
806
|
+
durationMs: number;
|
|
807
|
+
/**
|
|
808
|
+
* Models used in the workflow.
|
|
809
|
+
*/
|
|
810
|
+
models: string[];
|
|
811
|
+
/**
|
|
812
|
+
* Whether code validation was enabled.
|
|
813
|
+
*/
|
|
814
|
+
validationEnabled: boolean;
|
|
815
|
+
/**
|
|
816
|
+
* Whether the workflow completed successfully.
|
|
817
|
+
*/
|
|
818
|
+
success: boolean;
|
|
819
|
+
/**
|
|
820
|
+
* Error message if workflow failed.
|
|
821
|
+
*/
|
|
822
|
+
error?: string;
|
|
823
|
+
}
|
|
824
|
+
/**
|
|
825
|
+
* Result of a multi-agent collaboration.
|
|
826
|
+
*/
|
|
827
|
+
interface MultiAgentResult {
|
|
828
|
+
/**
|
|
829
|
+
* The final generated text.
|
|
830
|
+
*/
|
|
831
|
+
text: string;
|
|
832
|
+
/**
|
|
833
|
+
* Reasoning/plan from the planning phase.
|
|
834
|
+
*/
|
|
835
|
+
reasoning?: string;
|
|
836
|
+
/**
|
|
837
|
+
* All intermediate steps in the workflow.
|
|
838
|
+
*/
|
|
839
|
+
intermediateSteps: AgentStep[];
|
|
840
|
+
/**
|
|
841
|
+
* Aggregated token usage.
|
|
842
|
+
*/
|
|
843
|
+
usage: LanguageModelUsage;
|
|
844
|
+
/**
|
|
845
|
+
* Metadata about the execution.
|
|
846
|
+
*/
|
|
847
|
+
metadata: MultiAgentMetadata;
|
|
848
|
+
/**
|
|
849
|
+
* Code validation result (if enabled).
|
|
850
|
+
*/
|
|
851
|
+
validation?: {
|
|
852
|
+
valid: boolean;
|
|
853
|
+
errors: string[];
|
|
854
|
+
finalCode?: string;
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
/**
|
|
858
|
+
* Context passed to workflow functions.
|
|
859
|
+
*/
|
|
860
|
+
interface WorkflowContext {
|
|
861
|
+
/**
|
|
862
|
+
* Function to generate text with model A.
|
|
863
|
+
*/
|
|
864
|
+
generateWithModelA: (prompt: string) => Promise<GenerateResult>;
|
|
865
|
+
/**
|
|
866
|
+
* Function to generate text with model B.
|
|
867
|
+
*/
|
|
868
|
+
generateWithModelB: (prompt: string) => Promise<GenerateResult>;
|
|
869
|
+
/**
|
|
870
|
+
* Function to validate code.
|
|
871
|
+
*/
|
|
872
|
+
validateCode?: (code: string) => Promise<{
|
|
873
|
+
valid: boolean;
|
|
874
|
+
errors: string[];
|
|
875
|
+
fixedCode?: string;
|
|
876
|
+
}>;
|
|
877
|
+
/**
|
|
878
|
+
* Configuration for the workflow.
|
|
879
|
+
*/
|
|
880
|
+
config: MultiAgentConfig;
|
|
881
|
+
/**
|
|
882
|
+
* Add a step to the history.
|
|
883
|
+
*/
|
|
884
|
+
addStep: (step: Omit<AgentStep, 'timestamp' | 'durationMs'>) => void;
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* Result of a generation call.
|
|
888
|
+
*/
|
|
889
|
+
interface GenerateResult {
|
|
890
|
+
text: string;
|
|
891
|
+
reasoning?: string;
|
|
892
|
+
usage?: LanguageModelUsage;
|
|
893
|
+
toolCalls?: unknown[];
|
|
894
|
+
toolResults?: unknown[];
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* Default system prompts for different agent roles.
|
|
898
|
+
*/
|
|
899
|
+
declare const DEFAULT_SYSTEM_PROMPTS: {
|
|
900
|
+
readonly planner: "You are a system architect and planner. Your role is to:\n1. Analyze the problem thoroughly\n2. Break it down into clear, actionable steps\n3. Consider edge cases and potential issues\n4. Provide a detailed implementation plan\n\nFormat your response as a numbered list of steps that can be followed to implement the solution.";
|
|
901
|
+
readonly executor: "You are an expert implementer. Your role is to:\n1. Follow the provided plan precisely\n2. Write clean, well-documented code\n3. Handle edge cases mentioned in the plan\n4. Ensure the implementation is complete and functional\n\nProvide only the implementation code with necessary comments.";
|
|
902
|
+
readonly proposer: "You are a solution architect. Your role is to:\n1. Analyze the problem carefully\n2. Propose a complete solution\n3. Consider best practices and patterns\n4. Write clean, maintainable code\n\nProvide your solution with explanations for key design decisions.";
|
|
903
|
+
readonly critic: "You are a code reviewer and critic. Your role is to:\n1. Review the proposed solution critically\n2. Identify any bugs, errors, or issues\n3. Suggest improvements for performance and readability\n4. Verify edge cases are handled\n\nProvide specific, actionable feedback. Be thorough but constructive.";
|
|
904
|
+
};
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
* Multi-agent workflow implementations.
|
|
908
|
+
* @module
|
|
909
|
+
*/
|
|
910
|
+
|
|
911
|
+
/**
|
|
912
|
+
* Function type for generating text.
|
|
913
|
+
*/
|
|
914
|
+
type GenerateTextFunction$1 = (modelId: string, prompt: string, systemPrompt?: string) => Promise<GenerateResult>;
|
|
915
|
+
/**
|
|
916
|
+
* Function type for validating code.
|
|
917
|
+
*/
|
|
918
|
+
type ValidateCodeFunction = (code: string) => Promise<{
|
|
919
|
+
valid: boolean;
|
|
920
|
+
errors: string[];
|
|
921
|
+
fixedCode?: string;
|
|
922
|
+
}>;
|
|
923
|
+
/**
|
|
924
|
+
* Runner for multi-agent workflows.
|
|
925
|
+
*/
|
|
926
|
+
declare class WorkflowRunner {
|
|
927
|
+
private generateText;
|
|
928
|
+
private validateCode?;
|
|
929
|
+
constructor(generateText: GenerateTextFunction$1, validateCode?: ValidateCodeFunction);
|
|
930
|
+
/**
|
|
931
|
+
* Run a multi-agent workflow.
|
|
932
|
+
*/
|
|
933
|
+
run(prompt: string, config: MultiAgentConfig): Promise<MultiAgentResult>;
|
|
934
|
+
/**
|
|
935
|
+
* Planner-Executor workflow.
|
|
936
|
+
*/
|
|
937
|
+
private runPlannerExecutor;
|
|
938
|
+
/**
|
|
939
|
+
* Proposer-Critic workflow.
|
|
940
|
+
*/
|
|
941
|
+
private runProposerCritic;
|
|
942
|
+
/**
|
|
943
|
+
* Debate workflow.
|
|
944
|
+
*/
|
|
945
|
+
private runDebate;
|
|
946
|
+
/**
|
|
947
|
+
* Custom workflow.
|
|
948
|
+
*/
|
|
949
|
+
private runCustom;
|
|
950
|
+
/**
|
|
951
|
+
* Build metadata for result.
|
|
952
|
+
*/
|
|
953
|
+
private buildMetadata;
|
|
954
|
+
/**
|
|
955
|
+
* Add usage stats.
|
|
956
|
+
*/
|
|
957
|
+
private addUsage;
|
|
958
|
+
}
|
|
959
|
+
/**
|
|
960
|
+
* Create an empty multi-agent result.
|
|
961
|
+
*/
|
|
962
|
+
declare function createEmptyMultiAgentResult(workflow: MultiAgentConfig['workflow'], error: string): MultiAgentResult;
|
|
963
|
+
|
|
964
|
+
/**
|
|
965
|
+
* Types for project scaffolding functionality.
|
|
966
|
+
* @module
|
|
967
|
+
*/
|
|
968
|
+
/**
|
|
969
|
+
* Supported project types/frameworks.
|
|
970
|
+
*/
|
|
971
|
+
type ProjectType = 'nextjs' | 'react' | 'vue' | 'node' | 'express' | 'fastify' | 'python' | 'fastapi' | 'flask' | 'go' | 'rust' | 'auto';
|
|
972
|
+
/**
|
|
973
|
+
* Output format for scaffolded projects.
|
|
974
|
+
*/
|
|
975
|
+
type OutputFormat = 'files' | 'json' | 'instructions';
|
|
976
|
+
/**
|
|
977
|
+
* Configuration for project scaffolding.
|
|
978
|
+
*/
|
|
979
|
+
interface ScaffoldConfig {
|
|
980
|
+
/**
|
|
981
|
+
* Project type/framework.
|
|
982
|
+
* @default 'auto'
|
|
983
|
+
*/
|
|
984
|
+
type?: ProjectType;
|
|
985
|
+
/**
|
|
986
|
+
* Include testing setup.
|
|
987
|
+
* @default true
|
|
988
|
+
*/
|
|
989
|
+
includeTests?: boolean;
|
|
990
|
+
/**
|
|
991
|
+
* Include CI/CD configuration (e.g., GitHub Actions).
|
|
992
|
+
* @default false
|
|
993
|
+
*/
|
|
994
|
+
includeCI?: boolean;
|
|
995
|
+
/**
|
|
996
|
+
* Include documentation (README, API docs).
|
|
997
|
+
* @default true
|
|
998
|
+
*/
|
|
999
|
+
includeDocs?: boolean;
|
|
1000
|
+
/**
|
|
1001
|
+
* Include Docker configuration.
|
|
1002
|
+
* @default false
|
|
1003
|
+
*/
|
|
1004
|
+
includeDocker?: boolean;
|
|
1005
|
+
/**
|
|
1006
|
+
* Include ESLint/Prettier configuration.
|
|
1007
|
+
* @default true
|
|
1008
|
+
*/
|
|
1009
|
+
includeLinting?: boolean;
|
|
1010
|
+
/**
|
|
1011
|
+
* Output format.
|
|
1012
|
+
* @default 'files'
|
|
1013
|
+
*/
|
|
1014
|
+
outputFormat?: OutputFormat;
|
|
1015
|
+
/**
|
|
1016
|
+
* TypeScript vs JavaScript (for applicable frameworks).
|
|
1017
|
+
* @default true
|
|
1018
|
+
*/
|
|
1019
|
+
useTypeScript?: boolean;
|
|
1020
|
+
/**
|
|
1021
|
+
* Additional features to include.
|
|
1022
|
+
*/
|
|
1023
|
+
features?: string[];
|
|
1024
|
+
/**
|
|
1025
|
+
* Custom template or instructions to include.
|
|
1026
|
+
*/
|
|
1027
|
+
customTemplate?: string;
|
|
1028
|
+
}
|
|
1029
|
+
/**
|
|
1030
|
+
* A single file in the scaffolded project.
|
|
1031
|
+
*/
|
|
1032
|
+
interface ProjectFile {
|
|
1033
|
+
/**
|
|
1034
|
+
* Relative path from project root.
|
|
1035
|
+
*/
|
|
1036
|
+
path: string;
|
|
1037
|
+
/**
|
|
1038
|
+
* File contents.
|
|
1039
|
+
*/
|
|
1040
|
+
content: string;
|
|
1041
|
+
/**
|
|
1042
|
+
* Description of the file's purpose.
|
|
1043
|
+
*/
|
|
1044
|
+
description?: string;
|
|
1045
|
+
/**
|
|
1046
|
+
* Whether this is a binary file (base64 encoded).
|
|
1047
|
+
*/
|
|
1048
|
+
binary?: boolean;
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* Metadata about the scaffolded project.
|
|
1052
|
+
*/
|
|
1053
|
+
interface ProjectMetadata {
|
|
1054
|
+
/**
|
|
1055
|
+
* Detected or specified project type.
|
|
1056
|
+
*/
|
|
1057
|
+
projectType: ProjectType;
|
|
1058
|
+
/**
|
|
1059
|
+
* Project name (derived from description).
|
|
1060
|
+
*/
|
|
1061
|
+
projectName: string;
|
|
1062
|
+
/**
|
|
1063
|
+
* Number of files generated.
|
|
1064
|
+
*/
|
|
1065
|
+
fileCount: number;
|
|
1066
|
+
/**
|
|
1067
|
+
* Total size of all files (bytes).
|
|
1068
|
+
*/
|
|
1069
|
+
totalSize: number;
|
|
1070
|
+
/**
|
|
1071
|
+
* Estimated setup time.
|
|
1072
|
+
*/
|
|
1073
|
+
estimatedSetupTime: string;
|
|
1074
|
+
/**
|
|
1075
|
+
* Main technologies/dependencies used.
|
|
1076
|
+
*/
|
|
1077
|
+
technologies: string[];
|
|
1078
|
+
/**
|
|
1079
|
+
* Features included in the project.
|
|
1080
|
+
*/
|
|
1081
|
+
features: string[];
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* Result of scaffolding a project.
|
|
1085
|
+
*/
|
|
1086
|
+
interface ScaffoldResult {
|
|
1087
|
+
/**
|
|
1088
|
+
* Generated project files.
|
|
1089
|
+
*/
|
|
1090
|
+
files: ProjectFile[];
|
|
1091
|
+
/**
|
|
1092
|
+
* Setup instructions for the user.
|
|
1093
|
+
*/
|
|
1094
|
+
instructions: string;
|
|
1095
|
+
/**
|
|
1096
|
+
* Commands to run for setup.
|
|
1097
|
+
*/
|
|
1098
|
+
setupCommands: string[];
|
|
1099
|
+
/**
|
|
1100
|
+
* Project metadata.
|
|
1101
|
+
*/
|
|
1102
|
+
metadata: ProjectMetadata;
|
|
1103
|
+
/**
|
|
1104
|
+
* Raw response from the model (for debugging).
|
|
1105
|
+
*/
|
|
1106
|
+
rawResponse?: string;
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
* A project template definition.
|
|
1110
|
+
*/
|
|
1111
|
+
interface ProjectTemplate {
|
|
1112
|
+
/**
|
|
1113
|
+
* Template identifier.
|
|
1114
|
+
*/
|
|
1115
|
+
id: string;
|
|
1116
|
+
/**
|
|
1117
|
+
* Human-readable name.
|
|
1118
|
+
*/
|
|
1119
|
+
name: string;
|
|
1120
|
+
/**
|
|
1121
|
+
* Template description.
|
|
1122
|
+
*/
|
|
1123
|
+
description: string;
|
|
1124
|
+
/**
|
|
1125
|
+
* Project type this template is for.
|
|
1126
|
+
*/
|
|
1127
|
+
projectType: ProjectType;
|
|
1128
|
+
/**
|
|
1129
|
+
* Base files that are always included.
|
|
1130
|
+
*/
|
|
1131
|
+
baseFiles: ProjectFile[];
|
|
1132
|
+
/**
|
|
1133
|
+
* Optional files based on configuration.
|
|
1134
|
+
*/
|
|
1135
|
+
optionalFiles?: {
|
|
1136
|
+
condition: keyof ScaffoldConfig;
|
|
1137
|
+
files: ProjectFile[];
|
|
1138
|
+
}[];
|
|
1139
|
+
/**
|
|
1140
|
+
* Default setup commands.
|
|
1141
|
+
*/
|
|
1142
|
+
setupCommands: string[];
|
|
1143
|
+
/**
|
|
1144
|
+
* Technologies used.
|
|
1145
|
+
*/
|
|
1146
|
+
technologies: string[];
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
/**
|
|
1150
|
+
* Project scaffolder implementation.
|
|
1151
|
+
* @module
|
|
1152
|
+
*/
|
|
1153
|
+
|
|
1154
|
+
/**
|
|
1155
|
+
* Function type for generating text.
|
|
1156
|
+
*/
|
|
1157
|
+
type GenerateTextFunction = (prompt: string) => Promise<{
|
|
1158
|
+
text: string;
|
|
1159
|
+
}>;
|
|
1160
|
+
/**
|
|
1161
|
+
* Options for creating a scaffolder.
|
|
1162
|
+
*/
|
|
1163
|
+
interface ScaffolderOptions {
|
|
1164
|
+
/**
|
|
1165
|
+
* Function to generate text from the model.
|
|
1166
|
+
*/
|
|
1167
|
+
generateText: GenerateTextFunction;
|
|
1168
|
+
/**
|
|
1169
|
+
* Default model ID to use.
|
|
1170
|
+
*/
|
|
1171
|
+
modelId?: string;
|
|
1172
|
+
}
|
|
1173
|
+
/**
|
|
1174
|
+
* Scaffolder for generating project structures.
|
|
1175
|
+
*
|
|
1176
|
+
* @example
|
|
1177
|
+
* ```ts
|
|
1178
|
+
* const scaffolder = new ProjectScaffolder({
|
|
1179
|
+
* generateText: async (prompt) => {
|
|
1180
|
+
* const result = await generateText({ model, prompt });
|
|
1181
|
+
* return { text: result.text };
|
|
1182
|
+
* },
|
|
1183
|
+
* });
|
|
1184
|
+
*
|
|
1185
|
+
* const project = await scaffolder.scaffold(
|
|
1186
|
+
* 'A REST API for todo management',
|
|
1187
|
+
* { type: 'express', includeTests: true }
|
|
1188
|
+
* );
|
|
1189
|
+
* ```
|
|
1190
|
+
*/
|
|
1191
|
+
declare class ProjectScaffolder {
|
|
1192
|
+
private generateText;
|
|
1193
|
+
constructor(options: ScaffolderOptions);
|
|
1194
|
+
/**
|
|
1195
|
+
* Scaffold a new project based on a description.
|
|
1196
|
+
*
|
|
1197
|
+
* @param description - Description of the project to create
|
|
1198
|
+
* @param config - Scaffold configuration
|
|
1199
|
+
* @returns Scaffold result with files and instructions
|
|
1200
|
+
*/
|
|
1201
|
+
scaffold(description: string, config?: ScaffoldConfig): Promise<ScaffoldResult>;
|
|
1202
|
+
/**
|
|
1203
|
+
* Build the scaffold prompt.
|
|
1204
|
+
*/
|
|
1205
|
+
private buildScaffoldPrompt;
|
|
1206
|
+
/**
|
|
1207
|
+
* Parse the model response into structured data.
|
|
1208
|
+
*/
|
|
1209
|
+
private parseResponse;
|
|
1210
|
+
/**
|
|
1211
|
+
* Parse files from markdown code blocks.
|
|
1212
|
+
*/
|
|
1213
|
+
private parseFromCodeBlocks;
|
|
1214
|
+
/**
|
|
1215
|
+
* Detect project type from files.
|
|
1216
|
+
*/
|
|
1217
|
+
private detectProjectType;
|
|
1218
|
+
/**
|
|
1219
|
+
* Get file extension for a language.
|
|
1220
|
+
*/
|
|
1221
|
+
private getExtensionForLanguage;
|
|
1222
|
+
/**
|
|
1223
|
+
* Format the result based on output format.
|
|
1224
|
+
*/
|
|
1225
|
+
private formatResult;
|
|
1226
|
+
/**
|
|
1227
|
+
* Generate setup instructions.
|
|
1228
|
+
*/
|
|
1229
|
+
private generateInstructions;
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* Create an empty scaffold result.
|
|
1233
|
+
*/
|
|
1234
|
+
declare function createEmptyScaffoldResult(error: string): ScaffoldResult;
|
|
1235
|
+
|
|
5
1236
|
/**
|
|
6
1237
|
* Base error class for Kimi provider errors.
|
|
7
1238
|
*/
|
|
@@ -48,6 +1279,46 @@ declare class KimiContentFilterError extends KimiError {
|
|
|
48
1279
|
declare class KimiContextLengthError extends KimiError {
|
|
49
1280
|
constructor(message?: string);
|
|
50
1281
|
}
|
|
1282
|
+
/**
|
|
1283
|
+
* Error thrown when ensemble configuration is invalid.
|
|
1284
|
+
*/
|
|
1285
|
+
declare class KimiEnsembleValidationError extends KimiError {
|
|
1286
|
+
readonly config: unknown;
|
|
1287
|
+
readonly modelId: string;
|
|
1288
|
+
constructor(message: string, config: unknown, modelId: string);
|
|
1289
|
+
}
|
|
1290
|
+
/**
|
|
1291
|
+
* Error thrown when ensemble generation times out.
|
|
1292
|
+
*/
|
|
1293
|
+
declare class KimiEnsembleTimeoutError extends KimiError {
|
|
1294
|
+
readonly completedSamples: number;
|
|
1295
|
+
readonly requestedSamples: number;
|
|
1296
|
+
constructor(message: string, completedSamples: number, requestedSamples: number);
|
|
1297
|
+
}
|
|
1298
|
+
/**
|
|
1299
|
+
* Error thrown when a multi-agent workflow fails.
|
|
1300
|
+
*/
|
|
1301
|
+
declare class KimiMultiAgentError extends KimiError {
|
|
1302
|
+
readonly workflow: string;
|
|
1303
|
+
readonly step: number;
|
|
1304
|
+
readonly stepError?: Error;
|
|
1305
|
+
constructor(message: string, workflow: string, step: number, stepError?: Error);
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Error thrown when code validation fails.
|
|
1309
|
+
*/
|
|
1310
|
+
declare class KimiCodeValidationError extends KimiError {
|
|
1311
|
+
readonly validationErrors: string[];
|
|
1312
|
+
readonly attempts: number;
|
|
1313
|
+
constructor(message: string, validationErrors: string[], attempts: number);
|
|
1314
|
+
}
|
|
1315
|
+
/**
|
|
1316
|
+
* Error thrown when project scaffolding fails.
|
|
1317
|
+
*/
|
|
1318
|
+
declare class KimiScaffoldError extends KimiError {
|
|
1319
|
+
readonly projectType?: string;
|
|
1320
|
+
constructor(message: string, projectType?: string);
|
|
1321
|
+
}
|
|
51
1322
|
|
|
52
1323
|
/**
|
|
53
1324
|
* Core types for the Kimi provider.
|
|
@@ -103,6 +1374,21 @@ interface KimiModelCapabilities {
|
|
|
103
1374
|
* Whether the model supports structured outputs.
|
|
104
1375
|
*/
|
|
105
1376
|
structuredOutputs?: boolean;
|
|
1377
|
+
/**
|
|
1378
|
+
* Default temperature for the model.
|
|
1379
|
+
* Thinking models require temperature=1.0 for optimal reasoning.
|
|
1380
|
+
*/
|
|
1381
|
+
defaultTemperature?: number;
|
|
1382
|
+
/**
|
|
1383
|
+
* Whether temperature is locked (cannot be changed).
|
|
1384
|
+
* Thinking models have this set to true.
|
|
1385
|
+
*/
|
|
1386
|
+
temperatureLocked?: boolean;
|
|
1387
|
+
/**
|
|
1388
|
+
* Default max output tokens for the model.
|
|
1389
|
+
* Thinking models need higher limits to avoid truncated reasoning.
|
|
1390
|
+
*/
|
|
1391
|
+
defaultMaxOutputTokens?: number;
|
|
106
1392
|
}
|
|
107
1393
|
/**
|
|
108
1394
|
* Infer model capabilities from the model ID.
|
|
@@ -110,10 +1396,25 @@ interface KimiModelCapabilities {
|
|
|
110
1396
|
* @param modelId - The model identifier
|
|
111
1397
|
* @returns Inferred capabilities based on model name patterns
|
|
112
1398
|
*
|
|
1399
|
+
* @remarks
|
|
1400
|
+
* This function automatically detects model capabilities and sets
|
|
1401
|
+
* appropriate defaults:
|
|
1402
|
+
* - Thinking models (`-thinking` suffix) get temperature=1.0 locked
|
|
1403
|
+
* - Thinking models get 32k default max_tokens to avoid truncation
|
|
1404
|
+
* - K2.5 models get video input support
|
|
1405
|
+
*
|
|
113
1406
|
* @example
|
|
114
1407
|
* ```ts
|
|
115
1408
|
* const caps = inferModelCapabilities('kimi-k2.5-thinking');
|
|
116
|
-
* // {
|
|
1409
|
+
* // {
|
|
1410
|
+
* // thinking: true,
|
|
1411
|
+
* // alwaysThinking: true,
|
|
1412
|
+
* // videoInput: true,
|
|
1413
|
+
* // temperatureLocked: true,
|
|
1414
|
+
* // defaultTemperature: 1.0,
|
|
1415
|
+
* // defaultMaxOutputTokens: 32768,
|
|
1416
|
+
* // ...
|
|
1417
|
+
* // }
|
|
117
1418
|
* ```
|
|
118
1419
|
*/
|
|
119
1420
|
declare function inferModelCapabilities(modelId: string): KimiModelCapabilities;
|
|
@@ -151,6 +1452,89 @@ interface KimiExtendedUsage extends LanguageModelV3Usage {
|
|
|
151
1452
|
codeInterpreterTokens?: number;
|
|
152
1453
|
}
|
|
153
1454
|
|
|
1455
|
+
/**
|
|
1456
|
+
* Auto-detection utilities for enabling tools based on prompt content.
|
|
1457
|
+
* @module
|
|
1458
|
+
*/
|
|
1459
|
+
/**
|
|
1460
|
+
* Result of auto-detecting which tools should be enabled.
|
|
1461
|
+
*/
|
|
1462
|
+
interface AutoDetectToolsResult {
|
|
1463
|
+
/**
|
|
1464
|
+
* Whether web search should be enabled.
|
|
1465
|
+
*/
|
|
1466
|
+
webSearch: boolean;
|
|
1467
|
+
/**
|
|
1468
|
+
* Whether code interpreter should be enabled.
|
|
1469
|
+
*/
|
|
1470
|
+
codeInterpreter: boolean;
|
|
1471
|
+
/**
|
|
1472
|
+
* Confidence score (0-1) for web search detection.
|
|
1473
|
+
*/
|
|
1474
|
+
webSearchConfidence: number;
|
|
1475
|
+
/**
|
|
1476
|
+
* Confidence score (0-1) for code interpreter detection.
|
|
1477
|
+
*/
|
|
1478
|
+
codeInterpreterConfidence: number;
|
|
1479
|
+
/**
|
|
1480
|
+
* Patterns that matched for web search.
|
|
1481
|
+
*/
|
|
1482
|
+
webSearchMatches: string[];
|
|
1483
|
+
/**
|
|
1484
|
+
* Patterns that matched for code interpreter.
|
|
1485
|
+
*/
|
|
1486
|
+
codeInterpreterMatches: string[];
|
|
1487
|
+
}
|
|
1488
|
+
/**
|
|
1489
|
+
* Configuration for auto-detect behavior.
|
|
1490
|
+
*/
|
|
1491
|
+
interface AutoDetectConfig {
|
|
1492
|
+
/**
|
|
1493
|
+
* Minimum confidence threshold to enable a tool.
|
|
1494
|
+
* @default 0.3
|
|
1495
|
+
*/
|
|
1496
|
+
confidenceThreshold?: number;
|
|
1497
|
+
/**
|
|
1498
|
+
* Whether to include partial matches in detection.
|
|
1499
|
+
* @default true
|
|
1500
|
+
*/
|
|
1501
|
+
includePartialMatches?: boolean;
|
|
1502
|
+
}
|
|
1503
|
+
/**
|
|
1504
|
+
* Automatically detect which tools should be enabled based on prompt content.
|
|
1505
|
+
*
|
|
1506
|
+
* @param prompt - The user's prompt text
|
|
1507
|
+
* @param config - Optional detection configuration
|
|
1508
|
+
* @returns Detection result with tool recommendations
|
|
1509
|
+
*
|
|
1510
|
+
* @example
|
|
1511
|
+
* ```ts
|
|
1512
|
+
* const result = detectToolsFromPrompt('What is the current price of Bitcoin?');
|
|
1513
|
+
* // result.webSearch === true
|
|
1514
|
+
* // result.webSearchConfidence === 0.95
|
|
1515
|
+
* ```
|
|
1516
|
+
*/
|
|
1517
|
+
declare function detectToolsFromPrompt(prompt: string, config?: AutoDetectConfig): AutoDetectToolsResult;
|
|
1518
|
+
/**
|
|
1519
|
+
* Simple version that just returns boolean flags.
|
|
1520
|
+
* Useful for quick checks without detailed confidence info.
|
|
1521
|
+
*
|
|
1522
|
+
* @param prompt - The user's prompt text
|
|
1523
|
+
* @returns Object with boolean flags for each tool
|
|
1524
|
+
*/
|
|
1525
|
+
declare function shouldAutoEnableTools(prompt: string): {
|
|
1526
|
+
webSearch: boolean;
|
|
1527
|
+
codeInterpreter: boolean;
|
|
1528
|
+
};
|
|
1529
|
+
/**
|
|
1530
|
+
* Check if a prompt explicitly mentions not wanting tool usage.
|
|
1531
|
+
* Useful for respecting user preferences.
|
|
1532
|
+
*/
|
|
1533
|
+
declare function hasToolOptOut(prompt: string): {
|
|
1534
|
+
webSearch: boolean;
|
|
1535
|
+
codeInterpreter: boolean;
|
|
1536
|
+
};
|
|
1537
|
+
|
|
154
1538
|
/**
|
|
155
1539
|
* Built-in tools for Kimi API.
|
|
156
1540
|
*
|
|
@@ -331,6 +1715,45 @@ declare const kimiTools: {
|
|
|
331
1715
|
};
|
|
332
1716
|
};
|
|
333
1717
|
|
|
1718
|
+
/**
|
|
1719
|
+
* Tool preparation utilities for Kimi API.
|
|
1720
|
+
* @module
|
|
1721
|
+
*/
|
|
1722
|
+
|
|
1723
|
+
/**
|
|
1724
|
+
* Options for generating tool guidance messages.
|
|
1725
|
+
*/
|
|
1726
|
+
interface ToolGuidanceOptions {
|
|
1727
|
+
/**
|
|
1728
|
+
* The tool names available.
|
|
1729
|
+
*/
|
|
1730
|
+
toolNames: string[];
|
|
1731
|
+
/**
|
|
1732
|
+
* The type of tool choice.
|
|
1733
|
+
*/
|
|
1734
|
+
choiceType: 'required' | 'tool';
|
|
1735
|
+
/**
|
|
1736
|
+
* The specific tool name if choiceType is 'tool'.
|
|
1737
|
+
*/
|
|
1738
|
+
targetTool?: string;
|
|
1739
|
+
/**
|
|
1740
|
+
* Optional context from the user's prompt to include.
|
|
1741
|
+
*/
|
|
1742
|
+
promptContext?: string;
|
|
1743
|
+
/**
|
|
1744
|
+
* Whether to include detailed tool descriptions.
|
|
1745
|
+
* @default true
|
|
1746
|
+
*/
|
|
1747
|
+
includeDescriptions?: boolean;
|
|
1748
|
+
}
|
|
1749
|
+
/**
|
|
1750
|
+
* Generate a comprehensive tool guidance message.
|
|
1751
|
+
*
|
|
1752
|
+
* @param options - Options for generating the message
|
|
1753
|
+
* @returns The generated system message
|
|
1754
|
+
*/
|
|
1755
|
+
declare function generateToolGuidanceMessage(options: ToolGuidanceOptions): string;
|
|
1756
|
+
|
|
334
1757
|
/**
|
|
335
1758
|
* Chat model settings and provider options schema.
|
|
336
1759
|
* @module
|
|
@@ -413,6 +1836,14 @@ interface KimiChatSettings {
|
|
|
413
1836
|
* Reduces costs by up to 90% for repeated long prompts.
|
|
414
1837
|
*/
|
|
415
1838
|
caching?: boolean | KimiCachingConfig;
|
|
1839
|
+
/**
|
|
1840
|
+
* Auto-enable tools based on prompt content analysis.
|
|
1841
|
+
* When true, the provider will analyze the prompt and automatically
|
|
1842
|
+
* enable webSearch or codeInterpreter if patterns match.
|
|
1843
|
+
*
|
|
1844
|
+
* @default false
|
|
1845
|
+
*/
|
|
1846
|
+
autoEnableTools?: boolean;
|
|
416
1847
|
}
|
|
417
1848
|
/**
|
|
418
1849
|
* Zod schema for caching configuration.
|
|
@@ -452,6 +1883,7 @@ declare const kimiProviderOptionsSchema: z.ZodObject<{
|
|
|
452
1883
|
resetCache: z.ZodOptional<z.ZodBoolean>;
|
|
453
1884
|
}, z.core.$strip>]>>;
|
|
454
1885
|
toolChoicePolyfill: z.ZodOptional<z.ZodBoolean>;
|
|
1886
|
+
autoEnableTools: z.ZodOptional<z.ZodBoolean>;
|
|
455
1887
|
}, z.core.$strip>;
|
|
456
1888
|
/**
|
|
457
1889
|
* Type for provider options passed to individual calls.
|
|
@@ -488,6 +1920,9 @@ declare class KimiChatLanguageModel implements LanguageModelV3 {
|
|
|
488
1920
|
toolCalling?: boolean;
|
|
489
1921
|
jsonMode?: boolean;
|
|
490
1922
|
structuredOutputs?: boolean;
|
|
1923
|
+
defaultTemperature?: number;
|
|
1924
|
+
temperatureLocked?: boolean;
|
|
1925
|
+
defaultMaxOutputTokens?: number;
|
|
491
1926
|
};
|
|
492
1927
|
get supportedUrls(): Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
|
|
493
1928
|
private getArgs;
|
|
@@ -495,6 +1930,107 @@ declare class KimiChatLanguageModel implements LanguageModelV3 {
|
|
|
495
1930
|
doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
|
|
496
1931
|
}
|
|
497
1932
|
|
|
1933
|
+
/**
|
|
1934
|
+
* File content caching for efficient re-use of uploaded files.
|
|
1935
|
+
* @module
|
|
1936
|
+
*/
|
|
1937
|
+
/**
|
|
1938
|
+
* Entry in the file cache.
|
|
1939
|
+
*/
|
|
1940
|
+
interface FileCacheEntry {
|
|
1941
|
+
/** The Kimi file ID */
|
|
1942
|
+
fileId: string;
|
|
1943
|
+
/** Extracted text content (for documents) */
|
|
1944
|
+
content?: string;
|
|
1945
|
+
/** Unix timestamp of creation */
|
|
1946
|
+
createdAt: number;
|
|
1947
|
+
/** File purpose */
|
|
1948
|
+
purpose: 'file-extract' | 'image' | 'video';
|
|
1949
|
+
}
|
|
1950
|
+
/**
|
|
1951
|
+
* Options for configuring the file cache.
|
|
1952
|
+
*/
|
|
1953
|
+
interface FileCacheOptions {
|
|
1954
|
+
/**
|
|
1955
|
+
* Maximum number of entries in the cache.
|
|
1956
|
+
* When exceeded, least recently used entries are evicted.
|
|
1957
|
+
* @default 100
|
|
1958
|
+
*/
|
|
1959
|
+
maxSize?: number;
|
|
1960
|
+
/**
|
|
1961
|
+
* Time-to-live for cache entries in milliseconds.
|
|
1962
|
+
* Entries older than this are considered stale.
|
|
1963
|
+
* @default 3600000 (1 hour)
|
|
1964
|
+
*/
|
|
1965
|
+
ttlMs?: number;
|
|
1966
|
+
}
|
|
1967
|
+
/**
|
|
1968
|
+
* A simple LRU (Least Recently Used) cache for file content.
|
|
1969
|
+
*
|
|
1970
|
+
* This cache helps avoid re-uploading the same files multiple times
|
|
1971
|
+
* by storing the mapping between content hashes and Kimi file IDs.
|
|
1972
|
+
*
|
|
1973
|
+
* @example
|
|
1974
|
+
* ```ts
|
|
1975
|
+
* const cache = new FileCache({ maxSize: 50, ttlMs: 30 * 60 * 1000 });
|
|
1976
|
+
*
|
|
1977
|
+
* // Check if we have this file cached
|
|
1978
|
+
* const cached = cache.get(contentHash);
|
|
1979
|
+
* if (cached) {
|
|
1980
|
+
* console.log('Using cached file:', cached.fileId);
|
|
1981
|
+
* }
|
|
1982
|
+
*
|
|
1983
|
+
* // Store a new file
|
|
1984
|
+
* cache.set(contentHash, {
|
|
1985
|
+
* fileId: 'file_abc123',
|
|
1986
|
+
* content: 'extracted text...',
|
|
1987
|
+
* purpose: 'file-extract',
|
|
1988
|
+
* createdAt: Date.now()
|
|
1989
|
+
* });
|
|
1990
|
+
* ```
|
|
1991
|
+
*/
|
|
1992
|
+
declare class FileCache {
|
|
1993
|
+
private readonly maxSize;
|
|
1994
|
+
private readonly ttlMs;
|
|
1995
|
+
private readonly cache;
|
|
1996
|
+
constructor(options?: FileCacheOptions);
|
|
1997
|
+
/**
|
|
1998
|
+
* Get a cached entry by content hash.
|
|
1999
|
+
* Returns undefined if not found or expired.
|
|
2000
|
+
* Moves the entry to the end (most recently used).
|
|
2001
|
+
*/
|
|
2002
|
+
get(contentHash: string): FileCacheEntry | undefined;
|
|
2003
|
+
/**
|
|
2004
|
+
* Set a cache entry.
|
|
2005
|
+
* Evicts the least recently used entry if cache is full.
|
|
2006
|
+
*/
|
|
2007
|
+
set(contentHash: string, entry: FileCacheEntry): void;
|
|
2008
|
+
/**
|
|
2009
|
+
* Check if an entry exists and is not expired.
|
|
2010
|
+
*/
|
|
2011
|
+
has(contentHash: string): boolean;
|
|
2012
|
+
/**
|
|
2013
|
+
* Delete a specific entry.
|
|
2014
|
+
*/
|
|
2015
|
+
delete(contentHash: string): boolean;
|
|
2016
|
+
/**
|
|
2017
|
+
* Clear all entries.
|
|
2018
|
+
*/
|
|
2019
|
+
clear(): void;
|
|
2020
|
+
/**
|
|
2021
|
+
* Get the current cache size.
|
|
2022
|
+
*/
|
|
2023
|
+
get size(): number;
|
|
2024
|
+
/**
|
|
2025
|
+
* Remove all expired entries.
|
|
2026
|
+
*/
|
|
2027
|
+
prune(): number;
|
|
2028
|
+
/**
|
|
2029
|
+
* Check if an entry is expired.
|
|
2030
|
+
*/
|
|
2031
|
+
private isExpired;
|
|
2032
|
+
}
|
|
2033
|
+
|
|
498
2034
|
/**
|
|
499
2035
|
* Kimi File API client for uploading and managing files.
|
|
500
2036
|
* @module
|
|
@@ -659,6 +2195,13 @@ interface ProcessAttachmentsOptions {
|
|
|
659
2195
|
uploadImages?: boolean;
|
|
660
2196
|
/** Whether to delete files after extraction (cleanup) */
|
|
661
2197
|
cleanupAfterExtract?: boolean;
|
|
2198
|
+
/**
|
|
2199
|
+
* Enable caching of uploaded files.
|
|
2200
|
+
* When true, uses the default global cache.
|
|
2201
|
+
* When a FileCache instance, uses that cache.
|
|
2202
|
+
* @default false
|
|
2203
|
+
*/
|
|
2204
|
+
cache?: boolean | FileCache;
|
|
662
2205
|
}
|
|
663
2206
|
/**
|
|
664
2207
|
* Process experimental_attachments for Kimi.
|
|
@@ -812,6 +2355,99 @@ interface KimiProviderSettings {
|
|
|
812
2355
|
*/
|
|
813
2356
|
supportedUrls?: LanguageModelV3['supportedUrls'];
|
|
814
2357
|
}
|
|
2358
|
+
/**
|
|
2359
|
+
* Generate function signature for ensemble and convenience methods.
|
|
2360
|
+
* Takes a model and prompt and returns generation results.
|
|
2361
|
+
*/
|
|
2362
|
+
type ProviderGenerateFunction = (model: LanguageModelV3, prompt: string, options?: {
|
|
2363
|
+
temperature?: number;
|
|
2364
|
+
}) => Promise<{
|
|
2365
|
+
text: string;
|
|
2366
|
+
reasoning?: string;
|
|
2367
|
+
toolCalls?: unknown[];
|
|
2368
|
+
toolResults?: unknown[];
|
|
2369
|
+
usage?: LanguageModelUsage$1;
|
|
2370
|
+
finishReason?: string;
|
|
2371
|
+
}>;
|
|
2372
|
+
/**
|
|
2373
|
+
* Options for ensemble generation.
|
|
2374
|
+
*/
|
|
2375
|
+
interface EnsembleOptions extends Partial<EnsembleConfig> {
|
|
2376
|
+
/**
|
|
2377
|
+
* Model to use for generation. Defaults to 'kimi-k2.5'.
|
|
2378
|
+
*/
|
|
2379
|
+
model?: KimiChatModelId;
|
|
2380
|
+
/**
|
|
2381
|
+
* Base temperature for generation.
|
|
2382
|
+
* @default 0.7
|
|
2383
|
+
*/
|
|
2384
|
+
baseTemperature?: number;
|
|
2385
|
+
}
|
|
2386
|
+
/**
|
|
2387
|
+
* Options for multi-agent workflows.
|
|
2388
|
+
*/
|
|
2389
|
+
interface MultiAgentOptions extends Partial<MultiAgentConfig> {
|
|
2390
|
+
/**
|
|
2391
|
+
* Default model settings to apply.
|
|
2392
|
+
*/
|
|
2393
|
+
modelSettings?: KimiChatSettings;
|
|
2394
|
+
}
|
|
2395
|
+
/**
|
|
2396
|
+
* Options for code validation.
|
|
2397
|
+
*/
|
|
2398
|
+
interface ValidateCodeOptions {
|
|
2399
|
+
/**
|
|
2400
|
+
* Model to use for LLM-based validation. Defaults to 'kimi-k2.5'.
|
|
2401
|
+
*/
|
|
2402
|
+
model?: KimiChatModelId;
|
|
2403
|
+
/**
|
|
2404
|
+
* Model settings to apply.
|
|
2405
|
+
*/
|
|
2406
|
+
modelSettings?: KimiChatSettings;
|
|
2407
|
+
/**
|
|
2408
|
+
* Maximum number of attempts to fix errors.
|
|
2409
|
+
* @default 3
|
|
2410
|
+
*/
|
|
2411
|
+
maxAttempts?: number;
|
|
2412
|
+
/**
|
|
2413
|
+
* Language to validate (auto-detected if not specified).
|
|
2414
|
+
* @default 'auto'
|
|
2415
|
+
*/
|
|
2416
|
+
language?: 'javascript' | 'typescript' | 'python' | 'java' | 'cpp' | 'go' | 'rust' | 'ruby' | 'php' | 'auto';
|
|
2417
|
+
/**
|
|
2418
|
+
* Validation strictness level.
|
|
2419
|
+
* @default 'strict'
|
|
2420
|
+
*/
|
|
2421
|
+
strictness?: 'lenient' | 'strict' | 'maximum';
|
|
2422
|
+
/**
|
|
2423
|
+
* Timeout for each code execution attempt (ms).
|
|
2424
|
+
* @default 30000
|
|
2425
|
+
*/
|
|
2426
|
+
executionTimeoutMs?: number;
|
|
2427
|
+
/**
|
|
2428
|
+
* Whether to include test cases in validation.
|
|
2429
|
+
* @default true
|
|
2430
|
+
*/
|
|
2431
|
+
includeTests?: boolean;
|
|
2432
|
+
/**
|
|
2433
|
+
* Whether to return the fixed code even if validation fails.
|
|
2434
|
+
* @default true
|
|
2435
|
+
*/
|
|
2436
|
+
returnPartialFix?: boolean;
|
|
2437
|
+
}
|
|
2438
|
+
/**
|
|
2439
|
+
* Options for project scaffolding.
|
|
2440
|
+
*/
|
|
2441
|
+
interface ScaffoldProjectOptions extends ScaffoldConfig {
|
|
2442
|
+
/**
|
|
2443
|
+
* Model to use for generation. Defaults to 'kimi-k2.5'.
|
|
2444
|
+
*/
|
|
2445
|
+
model?: KimiChatModelId;
|
|
2446
|
+
/**
|
|
2447
|
+
* Model settings to apply.
|
|
2448
|
+
*/
|
|
2449
|
+
modelSettings?: KimiChatSettings;
|
|
2450
|
+
}
|
|
815
2451
|
/**
|
|
816
2452
|
* The Kimi provider interface.
|
|
817
2453
|
*/
|
|
@@ -854,6 +2490,117 @@ interface KimiProvider extends Omit<ProviderV3, 'specificationVersion'> {
|
|
|
854
2490
|
* ```
|
|
855
2491
|
*/
|
|
856
2492
|
files: KimiFileClient;
|
|
2493
|
+
/**
|
|
2494
|
+
* Generate multiple samples and select the best one using ensemble techniques.
|
|
2495
|
+
*
|
|
2496
|
+
* @param prompt - The prompt to generate from
|
|
2497
|
+
* @param generateFn - Function that generates text (from AI SDK)
|
|
2498
|
+
* @param options - Ensemble configuration options
|
|
2499
|
+
* @returns The best response based on the selection strategy
|
|
2500
|
+
*
|
|
2501
|
+
* @example
|
|
2502
|
+
* ```ts
|
|
2503
|
+
* import { generateText } from 'ai';
|
|
2504
|
+
*
|
|
2505
|
+
* const result = await kimi.ensemble(
|
|
2506
|
+
* 'Write a function to sort an array',
|
|
2507
|
+
* async (model, prompt, opts) => {
|
|
2508
|
+
* const result = await generateText({ model, prompt, temperature: opts?.temperature });
|
|
2509
|
+
* return { text: result.text, usage: result.usage };
|
|
2510
|
+
* },
|
|
2511
|
+
* { n: 3, selectionStrategy: 'best', scoringHeuristic: 'code' }
|
|
2512
|
+
* );
|
|
2513
|
+
* ```
|
|
2514
|
+
*/
|
|
2515
|
+
ensemble(prompt: string, generateFn: ProviderGenerateFunction, options?: EnsembleOptions): Promise<EnsembleResult>;
|
|
2516
|
+
/**
|
|
2517
|
+
* Run a multi-agent workflow for complex tasks.
|
|
2518
|
+
*
|
|
2519
|
+
* @param prompt - The task description
|
|
2520
|
+
* @param generateFn - Function that generates text (from AI SDK)
|
|
2521
|
+
* @param options - Multi-agent workflow configuration
|
|
2522
|
+
* @returns The result of the multi-agent collaboration
|
|
2523
|
+
*
|
|
2524
|
+
* @example
|
|
2525
|
+
* ```ts
|
|
2526
|
+
* const result = await kimi.multiAgent(
|
|
2527
|
+
* 'Build a REST API for user authentication',
|
|
2528
|
+
* async (modelId, prompt) => {
|
|
2529
|
+
* const result = await generateText({ model: kimi(modelId), prompt });
|
|
2530
|
+
* return { text: result.text };
|
|
2531
|
+
* },
|
|
2532
|
+
* { workflow: 'planner-executor' }
|
|
2533
|
+
* );
|
|
2534
|
+
* ```
|
|
2535
|
+
*/
|
|
2536
|
+
multiAgent(prompt: string, generateFn: GenerateTextFunction$1, options?: MultiAgentOptions): Promise<MultiAgentResult>;
|
|
2537
|
+
/**
|
|
2538
|
+
* Validate code for syntax errors and common issues.
|
|
2539
|
+
*
|
|
2540
|
+
* @param code - The code to validate
|
|
2541
|
+
* @param generateFn - Optional function for LLM-based validation
|
|
2542
|
+
* @param options - Validation configuration
|
|
2543
|
+
* @returns Validation result with errors and optionally fixed code
|
|
2544
|
+
*
|
|
2545
|
+
* @example
|
|
2546
|
+
* ```ts
|
|
2547
|
+
* const result = await kimi.validateCode(
|
|
2548
|
+
* 'function test() { return 42 }',
|
|
2549
|
+
* async (model, prompt) => {
|
|
2550
|
+
* const result = await generateText({ model, prompt });
|
|
2551
|
+
* return { text: result.text };
|
|
2552
|
+
* },
|
|
2553
|
+
* { language: 'javascript', strictness: 'strict' }
|
|
2554
|
+
* );
|
|
2555
|
+
* ```
|
|
2556
|
+
*/
|
|
2557
|
+
validateCode(code: string, generateFn?: (model: LanguageModelV3, prompt: string) => Promise<{
|
|
2558
|
+
text: string;
|
|
2559
|
+
}>, options?: ValidateCodeOptions): Promise<ValidationResult>;
|
|
2560
|
+
/**
|
|
2561
|
+
* Generate a complete project scaffold from a description.
|
|
2562
|
+
*
|
|
2563
|
+
* @param description - Description of the project to create
|
|
2564
|
+
* @param generateFn - Function that generates text (from AI SDK)
|
|
2565
|
+
* @param options - Scaffold configuration
|
|
2566
|
+
* @returns Generated project files and setup instructions
|
|
2567
|
+
*
|
|
2568
|
+
* @example
|
|
2569
|
+
* ```ts
|
|
2570
|
+
* const result = await kimi.scaffoldProject(
|
|
2571
|
+
* 'A Next.js app with authentication and database',
|
|
2572
|
+
* async (prompt) => {
|
|
2573
|
+
* const result = await generateText({ model: kimi('kimi-k2.5'), prompt });
|
|
2574
|
+
* return { text: result.text };
|
|
2575
|
+
* },
|
|
2576
|
+
* { type: 'nextjs', includeTests: true, includeDocker: true }
|
|
2577
|
+
* );
|
|
2578
|
+
* ```
|
|
2579
|
+
*/
|
|
2580
|
+
scaffoldProject(description: string, generateFn: (prompt: string) => Promise<{
|
|
2581
|
+
text: string;
|
|
2582
|
+
}>, options?: ScaffoldProjectOptions): Promise<ScaffoldResult>;
|
|
2583
|
+
/**
|
|
2584
|
+
* Auto-detect which tools should be enabled based on prompt content.
|
|
2585
|
+
*
|
|
2586
|
+
* @param prompt - The user's prompt
|
|
2587
|
+
* @returns Object with webSearch and codeInterpreter booleans
|
|
2588
|
+
*
|
|
2589
|
+
* @example
|
|
2590
|
+
* ```ts
|
|
2591
|
+
* const tools = kimi.detectTools('What is the current Bitcoin price?');
|
|
2592
|
+
* // { webSearch: true, codeInterpreter: false }
|
|
2593
|
+
*
|
|
2594
|
+
* const model = kimi('kimi-k2.5', {
|
|
2595
|
+
* webSearch: tools.webSearch,
|
|
2596
|
+
* codeInterpreter: tools.codeInterpreter
|
|
2597
|
+
* });
|
|
2598
|
+
* ```
|
|
2599
|
+
*/
|
|
2600
|
+
detectTools(prompt: string): {
|
|
2601
|
+
webSearch: boolean;
|
|
2602
|
+
codeInterpreter: boolean;
|
|
2603
|
+
};
|
|
857
2604
|
}
|
|
858
2605
|
/**
|
|
859
2606
|
* Create a Kimi provider instance.
|
|
@@ -1320,4 +3067,4 @@ declare class KimiCodeLanguageModel implements LanguageModelV3 {
|
|
|
1320
3067
|
doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
|
|
1321
3068
|
}
|
|
1322
3069
|
|
|
1323
|
-
export { type Attachment, type ExtendedThinkingConfig, type FileUploadOptions, type FileUploadResult, KIMI_CODE_BASE_URL, KIMI_CODE_DEFAULT_MODEL, KIMI_CODE_INTERPRETER_TOOL_NAME, KIMI_CODE_THINKING_MODEL, KIMI_WEB_SEARCH_TOOL_NAME, KimiAuthenticationError, type KimiBuiltinTool, type KimiCachingConfig, KimiChatLanguageModel, type KimiChatModelId, type KimiChatSettings, type KimiCodeCapabilities, type KimiCodeInterpreterConfig, type KimiCodeInterpreterToolOptions, KimiCodeLanguageModel, type KimiCodeModelId, type KimiCodeProvider, type KimiCodeProviderOptions, type KimiCodeProviderSettings, type KimiCodeSettings, KimiContentFilterError, KimiContextLengthError, KimiError, type KimiExtendedUsage, type KimiFile, KimiFileClient, type KimiFileClientConfig, type KimiModelCapabilities, KimiModelNotFoundError, type KimiProvider, type KimiProviderOptions, type KimiProviderSettings, KimiRateLimitError, KimiValidationError, type KimiWebSearchConfig, type KimiWebSearchToolConfig, type KimiWebSearchToolOptions, type ProcessedAttachment, type ReasoningEffort, SUPPORTED_FILE_EXTENSIONS, SUPPORTED_MIME_TYPES, createCodeInterpreterTool, createKimi, createKimiCode, createKimiWebSearchTool, createWebSearchTool, getMediaTypeFromExtension, getPurposeFromMediaType, inferKimiCodeCapabilities, inferModelCapabilities, isDocumentMediaType, isFileExtractMediaType, isImageMediaType, isVideoMediaType, kimi, kimiCachingConfigSchema, kimiCode, kimiCodeProviderOptionsSchema, kimiProviderOptionsSchema, kimiTools, processAttachments };
|
|
3070
|
+
export { type AgentStep, type Attachment, type AutoDetectConfig, type AutoDetectToolsResult, type CodeBlock, type CodeExtractionResult, type CodeValidationConfig, CodeValidator, type CodeValidatorOptions, DEFAULT_SYSTEM_PROMPTS, type EnsembleConfig, type EnsembleMetadata, type EnsembleOptions, type EnsembleResponse, type EnsembleResult, type ExtendedThinkingConfig, type FileUploadOptions, type FileUploadResult, type FixAttempt, type GenerateFunction, type GenerateResult, KIMI_CODE_BASE_URL, KIMI_CODE_DEFAULT_MODEL, KIMI_CODE_INTERPRETER_TOOL_NAME, KIMI_CODE_THINKING_MODEL, KIMI_WEB_SEARCH_TOOL_NAME, KimiAuthenticationError, type KimiBuiltinTool, type KimiCachingConfig, KimiChatLanguageModel, type KimiChatModelId, type KimiChatSettings, type KimiCodeCapabilities, type KimiCodeInterpreterConfig, type KimiCodeInterpreterToolOptions, KimiCodeLanguageModel, type KimiCodeModelId, type KimiCodeProvider, type KimiCodeProviderOptions, type KimiCodeProviderSettings, type KimiCodeSettings, KimiCodeValidationError, KimiContentFilterError, KimiContextLengthError, KimiEnsembleTimeoutError, KimiEnsembleValidationError, KimiError, type KimiExtendedUsage, type KimiFile, KimiFileClient, type KimiFileClientConfig, type KimiModelCapabilities, KimiModelNotFoundError, KimiMultiAgentError, type KimiProvider, type KimiProviderOptions, type KimiProviderSettings, KimiRateLimitError, KimiScaffoldError, KimiValidationError, type KimiWebSearchConfig, type KimiWebSearchToolConfig, type KimiWebSearchToolOptions, type LanguageDetectionResult, type MultiAgentConfig, type MultiAgentMetadata, type MultiAgentOptions, type MultiAgentResult, MultiSampler, type MultiSamplerOptions, type OutputFormat, type ProcessedAttachment, type ProjectFile, type ProjectMetadata, ProjectScaffolder, type ProjectTemplate, type ProjectType, type ProviderGenerateFunction, type ReasoningEffort, SUPPORTED_FILE_EXTENSIONS, SUPPORTED_MIME_TYPES, type ScaffoldConfig, type ScaffoldProjectOptions, type ScaffoldResult, type ScoringHeuristic, type SelectionStrategy, type SupportedLanguage, type ToolGuidanceOptions, type ValidateCodeOptions, type ValidationError, type ValidationErrorType, type ValidationResult, type ValidationSeverity, type ValidationStrictness, type WorkflowContext, WorkflowRunner, type WorkflowType, containsCode, createCodeInterpreterTool, createEmptyMultiAgentResult, createEmptyScaffoldResult, createFailedValidationResult, createKimi, createKimiCode, createKimiWebSearchTool, createPassedValidationResult, createSingletonEnsembleResult, createWebSearchTool, detectLanguage, detectToolsFromPrompt, extractCodeBlocks, extractPrimaryCode, generateToolGuidanceMessage, getFileExtension, getMediaTypeFromExtension, getPurposeFromMediaType, hasToolOptOut, inferKimiCodeCapabilities, inferModelCapabilities, isDocumentMediaType, isFileExtractMediaType, isImageMediaType, isVideoMediaType, kimi, kimiCachingConfigSchema, kimiCode, kimiCodeProviderOptionsSchema, kimiProviderOptionsSchema, kimiTools, processAttachments, shouldAutoEnableTools };
|