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.
Files changed (44) hide show
  1. package/README.md +567 -17
  2. package/dist/index.d.mts +1750 -3
  3. package/dist/index.d.ts +1750 -3
  4. package/dist/index.js +2317 -161
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +2292 -160
  7. package/dist/index.mjs.map +1 -1
  8. package/package.json +1 -1
  9. package/src/__tests__/auto-detect.test.ts +140 -0
  10. package/src/__tests__/code-validation.test.ts +267 -0
  11. package/src/__tests__/ensemble.test.ts +242 -0
  12. package/src/__tests__/file-cache.test.ts +310 -0
  13. package/src/__tests__/model-config.test.ts +120 -0
  14. package/src/__tests__/multi-agent.test.ts +201 -0
  15. package/src/__tests__/project-tools.test.ts +181 -0
  16. package/src/__tests__/reasoning-utils.test.ts +164 -0
  17. package/src/__tests__/tools.test.ts +76 -8
  18. package/src/chat/kimi-chat-language-model.ts +21 -2
  19. package/src/chat/kimi-chat-settings.ts +15 -1
  20. package/src/code-validation/detector.ts +319 -0
  21. package/src/code-validation/index.ts +31 -0
  22. package/src/code-validation/types.ts +291 -0
  23. package/src/code-validation/validator.ts +547 -0
  24. package/src/core/errors.ts +91 -0
  25. package/src/core/index.ts +15 -3
  26. package/src/core/types.ts +57 -2
  27. package/src/core/utils.ts +138 -0
  28. package/src/ensemble/index.ts +17 -0
  29. package/src/ensemble/multi-sampler.ts +433 -0
  30. package/src/ensemble/types.ts +279 -0
  31. package/src/files/attachment-processor.ts +51 -4
  32. package/src/files/file-cache.ts +260 -0
  33. package/src/files/index.ts +16 -1
  34. package/src/index.ts +102 -3
  35. package/src/kimi-provider.ts +354 -1
  36. package/src/multi-agent/index.ts +21 -0
  37. package/src/multi-agent/types.ts +312 -0
  38. package/src/multi-agent/workflows.ts +539 -0
  39. package/src/project-tools/index.ts +16 -0
  40. package/src/project-tools/scaffolder.ts +494 -0
  41. package/src/project-tools/types.ts +244 -0
  42. package/src/tools/auto-detect.ts +276 -0
  43. package/src/tools/index.ts +6 -2
  44. 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;