( options: FetchManagedKimiCodeModelsOptions, )
| 475 | } |
| 476 | |
| 477 | export async function fetchManagedKimiCodeModels( |
| 478 | options: FetchManagedKimiCodeModelsOptions, |
| 479 | ): Promise<ManagedKimiCodeModelInfo[]> { |
| 480 | const fetchImpl = options.fetchImpl ?? fetch; |
| 481 | const baseUrl = defaultBaseUrl(options.baseUrl); |
| 482 | const response = await fetchImpl(`${baseUrl}/models`, { |
| 483 | headers: { |
| 484 | ...parseKimiCodeCustomHeaders(), |
| 485 | ...options.headers, |
| 486 | Authorization: `Bearer ${options.accessToken}`, |
| 487 | Accept: 'application/json', |
| 488 | }, |
| 489 | }); |
| 490 | if (!response.ok) { |
| 491 | const message = await readApiErrorMessage( |
| 492 | response, |
| 493 | `Failed to list Kimi Code models (HTTP ${response.status}).`, |
| 494 | ); |
| 495 | if (response.status === 401 || response.status === 402 || response.status === 403) { |
| 496 | throw new ManagedKimiCodeModelsAuthError({ |
| 497 | status: response.status, |
| 498 | baseUrl, |
| 499 | message, |
| 500 | }); |
| 501 | } |
| 502 | throw new Error(message); |
| 503 | } |
| 504 | const payload: unknown = await response.json(); |
| 505 | if (!isRecord(payload) || !Array.isArray(payload['data'])) { |
| 506 | throw new Error(`Unexpected models response for ${baseUrl}.`); |
| 507 | } |
| 508 | return payload['data'] |
| 509 | .map((item) => toModelInfo(item)) |
| 510 | .filter((item): item is ManagedKimiCodeModelInfo => item !== undefined); |
| 511 | } |
| 512 | |
| 513 | export function applyManagedKimiCodeConfig( |
| 514 | config: ManagedKimiConfigShape, |
no test coverage detected