kimi-vercel-ai-sdk-provider 0.3.0 → 0.4.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 +157 -2
- package/dist/index.d.mts +142 -1
- package/dist/index.d.ts +142 -1
- package/dist/index.js +222 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +222 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/file-cache.test.ts +310 -0
- package/src/__tests__/model-config.test.ts +120 -0
- package/src/__tests__/reasoning-utils.test.ts +164 -0
- package/src/__tests__/tools.test.ts +75 -7
- package/src/chat/kimi-chat-language-model.ts +21 -2
- package/src/core/index.ts +10 -3
- package/src/core/types.ts +57 -2
- package/src/core/utils.ts +138 -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/tools/prepare-tools.ts +88 -2
|
@@ -157,13 +157,17 @@ export function prepareKimiTools({
|
|
|
157
157
|
continue;
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
+
// Sanitize schema for Kimi compatibility
|
|
161
|
+
const sanitizedSchema = sanitizeToolSchema(tool.inputSchema);
|
|
162
|
+
|
|
160
163
|
kimiTools.push({
|
|
161
164
|
type: 'function',
|
|
162
165
|
function: {
|
|
163
166
|
name: tool.name,
|
|
164
167
|
description: tool.description,
|
|
165
|
-
parameters:
|
|
166
|
-
|
|
168
|
+
parameters: sanitizedSchema
|
|
169
|
+
// Don't pass strict mode to Kimi - it may cause issues
|
|
170
|
+
// ...(tool.strict != null ? { strict: tool.strict } : {})
|
|
167
171
|
}
|
|
168
172
|
});
|
|
169
173
|
}
|
|
@@ -266,6 +270,88 @@ function generateSpecificToolMessage(toolName: string): string {
|
|
|
266
270
|
return `IMPORTANT INSTRUCTION: You MUST use the "${toolName}" tool to respond to this request. Do NOT use any other tool or provide a direct text response. Call the "${toolName}" tool with appropriate parameters.`;
|
|
267
271
|
}
|
|
268
272
|
|
|
273
|
+
// ============================================================================
|
|
274
|
+
// Schema Sanitization
|
|
275
|
+
// ============================================================================
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* JSON Schema keywords that may cause issues with Kimi's API.
|
|
279
|
+
* These are removed during sanitization to improve compatibility.
|
|
280
|
+
*/
|
|
281
|
+
const UNSUPPORTED_SCHEMA_KEYWORDS = [
|
|
282
|
+
'$schema',
|
|
283
|
+
'$id',
|
|
284
|
+
'$ref',
|
|
285
|
+
'$defs',
|
|
286
|
+
'definitions',
|
|
287
|
+
'if',
|
|
288
|
+
'then',
|
|
289
|
+
'else',
|
|
290
|
+
'allOf',
|
|
291
|
+
'anyOf',
|
|
292
|
+
'oneOf',
|
|
293
|
+
'not',
|
|
294
|
+
'patternProperties',
|
|
295
|
+
'additionalItems',
|
|
296
|
+
'contains',
|
|
297
|
+
'propertyNames',
|
|
298
|
+
'const',
|
|
299
|
+
'contentMediaType',
|
|
300
|
+
'contentEncoding',
|
|
301
|
+
'examples',
|
|
302
|
+
'$comment'
|
|
303
|
+
] as const;
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Sanitize a JSON Schema for better Kimi API compatibility.
|
|
307
|
+
*
|
|
308
|
+
* This function removes advanced schema keywords that Kimi may not
|
|
309
|
+
* fully support, while preserving the essential structure for validation.
|
|
310
|
+
*
|
|
311
|
+
* @param schema - The original JSON Schema
|
|
312
|
+
* @returns A sanitized schema safe for Kimi
|
|
313
|
+
*/
|
|
314
|
+
function sanitizeToolSchema(schema: unknown): unknown {
|
|
315
|
+
if (schema === null || schema === undefined) {
|
|
316
|
+
return schema;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (Array.isArray(schema)) {
|
|
320
|
+
return schema.map(sanitizeToolSchema);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (typeof schema !== 'object') {
|
|
324
|
+
return schema;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const sanitized: Record<string, unknown> = {};
|
|
328
|
+
const schemaObj = schema as Record<string, unknown>;
|
|
329
|
+
|
|
330
|
+
for (const [key, value] of Object.entries(schemaObj)) {
|
|
331
|
+
// Skip unsupported keywords
|
|
332
|
+
if (UNSUPPORTED_SCHEMA_KEYWORDS.includes(key as (typeof UNSUPPORTED_SCHEMA_KEYWORDS)[number])) {
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// Recursively sanitize nested objects
|
|
337
|
+
if (key === 'properties' && typeof value === 'object' && value !== null) {
|
|
338
|
+
const props: Record<string, unknown> = {};
|
|
339
|
+
for (const [propKey, propValue] of Object.entries(value as Record<string, unknown>)) {
|
|
340
|
+
props[propKey] = sanitizeToolSchema(propValue);
|
|
341
|
+
}
|
|
342
|
+
sanitized[key] = props;
|
|
343
|
+
} else if (key === 'items' && typeof value === 'object') {
|
|
344
|
+
sanitized[key] = sanitizeToolSchema(value);
|
|
345
|
+
} else if (key === 'additionalProperties' && typeof value === 'object') {
|
|
346
|
+
sanitized[key] = sanitizeToolSchema(value);
|
|
347
|
+
} else {
|
|
348
|
+
sanitized[key] = value;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return sanitized;
|
|
353
|
+
}
|
|
354
|
+
|
|
269
355
|
// ============================================================================
|
|
270
356
|
// Helper Functions
|
|
271
357
|
// ============================================================================
|