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
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for multi-agent collaboration functionality.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Simple usage type compatible with common AI SDK patterns.
|
|
8
|
+
* This is independent from the provider-specific V3Usage type.
|
|
9
|
+
*/
|
|
10
|
+
export interface LanguageModelUsage {
|
|
11
|
+
promptTokens: number;
|
|
12
|
+
completionTokens: number;
|
|
13
|
+
totalTokens: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// ============================================================================
|
|
17
|
+
// Configuration Types
|
|
18
|
+
// ============================================================================
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Available multi-agent workflow types.
|
|
22
|
+
*/
|
|
23
|
+
export type WorkflowType = 'planner-executor' | 'proposer-critic' | 'debate' | 'custom';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Configuration for multi-agent collaboration.
|
|
27
|
+
*/
|
|
28
|
+
export interface MultiAgentConfig {
|
|
29
|
+
/**
|
|
30
|
+
* Multi-agent workflow type.
|
|
31
|
+
* - 'planner-executor': One agent plans, another executes
|
|
32
|
+
* - 'proposer-critic': One proposes, another critiques and refines
|
|
33
|
+
* - 'debate': Multiple agents debate and converge on answer
|
|
34
|
+
* - 'custom': Use custom workflow
|
|
35
|
+
* @default 'planner-executor'
|
|
36
|
+
*/
|
|
37
|
+
workflow: WorkflowType;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Model for the first agent (typically thinking/planning).
|
|
41
|
+
* @default 'kimi-k2.5-thinking'
|
|
42
|
+
*/
|
|
43
|
+
modelA?: string;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Model for the second agent (typically coding/action).
|
|
47
|
+
* @default 'kimi-k2.5'
|
|
48
|
+
*/
|
|
49
|
+
modelB?: string;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Number of refinement iterations for proposer-critic.
|
|
53
|
+
* @default 2
|
|
54
|
+
*/
|
|
55
|
+
iterations?: number;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Include code validation in the workflow.
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
61
|
+
validateCode?: boolean;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Maximum time for the entire workflow (ms).
|
|
65
|
+
* @default 120000
|
|
66
|
+
*/
|
|
67
|
+
timeoutMs?: number;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Custom workflow function.
|
|
71
|
+
*/
|
|
72
|
+
customWorkflow?: (prompt: string, context: WorkflowContext) => Promise<MultiAgentResult>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Enable verbose logging of intermediate steps.
|
|
76
|
+
* @default false
|
|
77
|
+
*/
|
|
78
|
+
verbose?: boolean;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* System prompts for agents.
|
|
82
|
+
*/
|
|
83
|
+
systemPrompts?: {
|
|
84
|
+
planner?: string;
|
|
85
|
+
executor?: string;
|
|
86
|
+
proposer?: string;
|
|
87
|
+
critic?: string;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ============================================================================
|
|
92
|
+
// Result Types
|
|
93
|
+
// ============================================================================
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* A single step in the multi-agent workflow.
|
|
97
|
+
*/
|
|
98
|
+
export interface AgentStep {
|
|
99
|
+
/**
|
|
100
|
+
* Agent identifier (A, B, or custom name).
|
|
101
|
+
*/
|
|
102
|
+
agent: string;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Role of the agent in this step.
|
|
106
|
+
*/
|
|
107
|
+
role: 'planner' | 'executor' | 'proposer' | 'critic' | 'validator' | 'custom';
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Action performed.
|
|
111
|
+
*/
|
|
112
|
+
action: string;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Input provided to the agent.
|
|
116
|
+
*/
|
|
117
|
+
input?: string;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Output from the agent.
|
|
121
|
+
*/
|
|
122
|
+
output: string;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Timestamp when this step completed.
|
|
126
|
+
*/
|
|
127
|
+
timestamp: number;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Duration of this step (ms).
|
|
131
|
+
*/
|
|
132
|
+
durationMs: number;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Token usage for this step.
|
|
136
|
+
*/
|
|
137
|
+
usage?: LanguageModelUsage;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Model used for this step.
|
|
141
|
+
*/
|
|
142
|
+
model?: string;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Metadata about the multi-agent execution.
|
|
147
|
+
*/
|
|
148
|
+
export interface MultiAgentMetadata {
|
|
149
|
+
/**
|
|
150
|
+
* Workflow type used.
|
|
151
|
+
*/
|
|
152
|
+
workflow: WorkflowType;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Total number of iterations/steps.
|
|
156
|
+
*/
|
|
157
|
+
iterations: number;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Total duration (ms).
|
|
161
|
+
*/
|
|
162
|
+
durationMs: number;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Models used in the workflow.
|
|
166
|
+
*/
|
|
167
|
+
models: string[];
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Whether code validation was enabled.
|
|
171
|
+
*/
|
|
172
|
+
validationEnabled: boolean;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Whether the workflow completed successfully.
|
|
176
|
+
*/
|
|
177
|
+
success: boolean;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Error message if workflow failed.
|
|
181
|
+
*/
|
|
182
|
+
error?: string;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Result of a multi-agent collaboration.
|
|
187
|
+
*/
|
|
188
|
+
export interface MultiAgentResult {
|
|
189
|
+
/**
|
|
190
|
+
* The final generated text.
|
|
191
|
+
*/
|
|
192
|
+
text: string;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Reasoning/plan from the planning phase.
|
|
196
|
+
*/
|
|
197
|
+
reasoning?: string;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* All intermediate steps in the workflow.
|
|
201
|
+
*/
|
|
202
|
+
intermediateSteps: AgentStep[];
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Aggregated token usage.
|
|
206
|
+
*/
|
|
207
|
+
usage: LanguageModelUsage;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Metadata about the execution.
|
|
211
|
+
*/
|
|
212
|
+
metadata: MultiAgentMetadata;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Code validation result (if enabled).
|
|
216
|
+
*/
|
|
217
|
+
validation?: {
|
|
218
|
+
valid: boolean;
|
|
219
|
+
errors: string[];
|
|
220
|
+
finalCode?: string;
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// ============================================================================
|
|
225
|
+
// Context Types
|
|
226
|
+
// ============================================================================
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Context passed to workflow functions.
|
|
230
|
+
*/
|
|
231
|
+
export interface WorkflowContext {
|
|
232
|
+
/**
|
|
233
|
+
* Function to generate text with model A.
|
|
234
|
+
*/
|
|
235
|
+
generateWithModelA: (prompt: string) => Promise<GenerateResult>;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Function to generate text with model B.
|
|
239
|
+
*/
|
|
240
|
+
generateWithModelB: (prompt: string) => Promise<GenerateResult>;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Function to validate code.
|
|
244
|
+
*/
|
|
245
|
+
validateCode?: (code: string) => Promise<{
|
|
246
|
+
valid: boolean;
|
|
247
|
+
errors: string[];
|
|
248
|
+
fixedCode?: string;
|
|
249
|
+
}>;
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Configuration for the workflow.
|
|
253
|
+
*/
|
|
254
|
+
config: MultiAgentConfig;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Add a step to the history.
|
|
258
|
+
*/
|
|
259
|
+
addStep: (step: Omit<AgentStep, 'timestamp' | 'durationMs'>) => void;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Result of a generation call.
|
|
264
|
+
*/
|
|
265
|
+
export interface GenerateResult {
|
|
266
|
+
text: string;
|
|
267
|
+
reasoning?: string;
|
|
268
|
+
usage?: LanguageModelUsage;
|
|
269
|
+
toolCalls?: unknown[];
|
|
270
|
+
toolResults?: unknown[];
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// ============================================================================
|
|
274
|
+
// Prompt Templates
|
|
275
|
+
// ============================================================================
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Default system prompts for different agent roles.
|
|
279
|
+
*/
|
|
280
|
+
export const DEFAULT_SYSTEM_PROMPTS = {
|
|
281
|
+
planner: `You are a system architect and planner. Your role is to:
|
|
282
|
+
1. Analyze the problem thoroughly
|
|
283
|
+
2. Break it down into clear, actionable steps
|
|
284
|
+
3. Consider edge cases and potential issues
|
|
285
|
+
4. Provide a detailed implementation plan
|
|
286
|
+
|
|
287
|
+
Format your response as a numbered list of steps that can be followed to implement the solution.`,
|
|
288
|
+
|
|
289
|
+
executor: `You are an expert implementer. Your role is to:
|
|
290
|
+
1. Follow the provided plan precisely
|
|
291
|
+
2. Write clean, well-documented code
|
|
292
|
+
3. Handle edge cases mentioned in the plan
|
|
293
|
+
4. Ensure the implementation is complete and functional
|
|
294
|
+
|
|
295
|
+
Provide only the implementation code with necessary comments.`,
|
|
296
|
+
|
|
297
|
+
proposer: `You are a solution architect. Your role is to:
|
|
298
|
+
1. Analyze the problem carefully
|
|
299
|
+
2. Propose a complete solution
|
|
300
|
+
3. Consider best practices and patterns
|
|
301
|
+
4. Write clean, maintainable code
|
|
302
|
+
|
|
303
|
+
Provide your solution with explanations for key design decisions.`,
|
|
304
|
+
|
|
305
|
+
critic: `You are a code reviewer and critic. Your role is to:
|
|
306
|
+
1. Review the proposed solution critically
|
|
307
|
+
2. Identify any bugs, errors, or issues
|
|
308
|
+
3. Suggest improvements for performance and readability
|
|
309
|
+
4. Verify edge cases are handled
|
|
310
|
+
|
|
311
|
+
Provide specific, actionable feedback. Be thorough but constructive.`
|
|
312
|
+
} as const;
|