(item: unknown)
| 403 | } |
| 404 | |
| 405 | function toModelInfo(item: unknown): ManagedKimiCodeModelInfo | undefined { |
| 406 | if (!isRecord(item) || typeof item['id'] !== 'string' || item['id'].length === 0) { |
| 407 | return undefined; |
| 408 | } |
| 409 | const contextLength = Number(item['context_length']); |
| 410 | if (!Number.isInteger(contextLength) || contextLength <= 0) { |
| 411 | throw new Error(`Kimi Code model "${item['id']}" must include a positive context_length.`); |
| 412 | } |
| 413 | const displayName = item['display_name']; |
| 414 | const normalizedDisplayName = |
| 415 | typeof displayName === 'string' && displayName.length > 0 ? displayName : undefined; |
| 416 | const supportsToolUse = Object.hasOwn(item, 'supports_tool_use') |
| 417 | ? Boolean(item['supports_tool_use']) |
| 418 | : true; |
| 419 | // Effort levels come from the nested `think_efforts` object |
| 420 | // ({ support, valid_efforts, default_effort }) returned by /models. |
| 421 | const thinkEfforts = parseThinkEfforts(item['think_efforts']); |
| 422 | return { |
| 423 | id: item['id'], |
| 424 | contextLength, |
| 425 | supportsReasoning: Boolean(item['supports_reasoning']), |
| 426 | supportsImageIn: Boolean(item['supports_image_in']), |
| 427 | supportsVideoIn: Boolean(item['supports_video_in']), |
| 428 | supportsToolUse, |
| 429 | supportsThinkingType: parseSupportsThinkingType(item['supports_thinking_type']), |
| 430 | supportEfforts: thinkEfforts.supportEfforts, |
| 431 | defaultEffort: thinkEfforts.defaultEffort, |
| 432 | displayName: normalizedDisplayName, |
| 433 | protocol: parseModelProtocol(item['protocol']), |
| 434 | }; |
| 435 | } |
| 436 | |
| 437 | export function parseStringArray(value: unknown): readonly string[] | undefined { |
| 438 | if (!Array.isArray(value)) return undefined; |
no test coverage detected