@bastani/pi-ai 0.9.37 → 0.9.38-alpha.10
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/CHANGELOG.md +47 -0
- package/README.md +6 -6
- package/dist/api/anthropic-messages.d.ts.map +1 -1
- package/dist/api/anthropic-messages.js +35 -21
- package/dist/api/anthropic-messages.js.map +1 -1
- package/dist/api/bedrock-converse-stream.js +16 -18
- package/dist/api/bedrock-converse-stream.js.map +1 -1
- package/dist/api/google-shared.d.ts.map +1 -1
- package/dist/api/google-shared.js +2 -1
- package/dist/api/google-shared.js.map +1 -1
- package/dist/api/mistral-conversations.js +2 -2
- package/dist/api/mistral-conversations.js.map +1 -1
- package/dist/api/openai-codex-responses.d.ts +1 -0
- package/dist/api/openai-codex-responses.d.ts.map +1 -1
- package/dist/api/openai-codex-responses.js +7 -2
- package/dist/api/openai-codex-responses.js.map +1 -1
- package/dist/api/openai-completions.d.ts +1 -1
- package/dist/api/openai-completions.d.ts.map +1 -1
- package/dist/api/openai-completions.js +32 -30
- package/dist/api/openai-completions.js.map +1 -1
- package/dist/api/openai-responses-shared.d.ts +10 -0
- package/dist/api/openai-responses-shared.d.ts.map +1 -1
- package/dist/api/openai-responses-shared.js +16 -3
- package/dist/api/openai-responses-shared.js.map +1 -1
- package/dist/api/openai-responses.d.ts.map +1 -1
- package/dist/api/openai-responses.js +25 -6
- package/dist/api/openai-responses.js.map +1 -1
- package/dist/api/openai-retry-hint-client.d.ts +10 -0
- package/dist/api/openai-retry-hint-client.d.ts.map +1 -0
- package/dist/api/openai-retry-hint-client.js +17 -0
- package/dist/api/openai-retry-hint-client.js.map +1 -0
- package/dist/api/transform-messages.d.ts +16 -1
- package/dist/api/transform-messages.d.ts.map +1 -1
- package/dist/api/transform-messages.js +28 -15
- package/dist/api/transform-messages.js.map +1 -1
- package/dist/auth/oauth/kimi-coding.d.ts +1 -1
- package/dist/auth/oauth/kimi-coding.js +1 -1
- package/dist/auth/oauth/kimi-coding.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/model-catalog.d.ts +1 -1
- package/dist/model-catalog.d.ts.map +1 -1
- package/dist/model-catalog.js +32 -2
- package/dist/model-catalog.js.map +1 -1
- package/dist/providers/compat-schema.d.ts +159 -0
- package/dist/providers/compat-schema.d.ts.map +1 -1
- package/dist/providers/compat-schema.js +12 -2
- package/dist/providers/compat-schema.js.map +1 -1
- package/dist/providers/data/.manifest.json +1 -1
- package/dist/providers/data/anthropic.json +1 -1
- package/dist/providers/data/baseten.json +1 -1
- package/dist/providers/data/fireworks.json +1 -1
- package/dist/providers/data/kimi-coding.json +1 -1
- package/dist/providers/data/nvidia.json +1 -1
- package/dist/providers/data/openai.json +1 -1
- package/dist/providers/data/opencode-go.json +1 -1
- package/dist/providers/data/opencode.json +1 -1
- package/dist/providers/data/openrouter.json +1 -1
- package/dist/providers/data/radius.json +1 -1
- package/dist/providers/data/together.json +1 -1
- package/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/providers/data/xiaomi-token-plan-ams.json +1 -1
- package/dist/providers/data/xiaomi-token-plan-cn.json +1 -1
- package/dist/providers/data/xiaomi-token-plan-sgp.json +1 -1
- package/dist/providers/data/xiaomi.json +1 -1
- package/dist/providers/data/zai-coding-cn.json +1 -1
- package/dist/providers/kimi-coding.d.ts +1 -1
- package/dist/providers/kimi-coding.js +3 -3
- package/dist/providers/kimi-coding.js.map +1 -1
- package/dist/providers/model-schema.d.ts.map +1 -1
- package/dist/providers/model-schema.js +4 -2
- package/dist/providers/model-schema.js.map +1 -1
- package/dist/providers/openai-codex.js.map +1 -1
- package/dist/providers/openai-mid-convo-effort.d.ts +2 -0
- package/dist/providers/openai-mid-convo-effort.d.ts.map +1 -0
- package/dist/providers/openai-mid-convo-effort.js +7 -0
- package/dist/providers/openai-mid-convo-effort.js.map +1 -0
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +11 -2
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/opencode-go.d.ts +3 -1
- package/dist/providers/opencode-go.d.ts.map +1 -1
- package/dist/providers/opencode-go.js +2 -0
- package/dist/providers/opencode-go.js.map +1 -1
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/json-parse.d.ts +2 -0
- package/dist/utils/json-parse.d.ts.map +1 -1
- package/dist/utils/json-parse.js +57 -3
- package/dist/utils/json-parse.js.map +1 -1
- package/dist/utils/retry-hints.d.ts +12 -0
- package/dist/utils/retry-hints.d.ts.map +1 -0
- package/dist/utils/retry-hints.js +50 -0
- package/dist/utils/retry-hints.js.map +1 -0
- package/dist/utils/retry.d.ts +20 -2
- package/dist/utils/retry.d.ts.map +1 -1
- package/dist/utils/retry.js +35 -4
- package/dist/utils/retry.js.map +1 -1
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +3 -0
- package/dist/utils/validation.js.map +1 -1
- package/package.json +2 -2
- package/dist/utils/assistant-message-frame.d.ts +0 -77
- package/dist/utils/assistant-message-frame.d.ts.map +0 -1
- package/dist/utils/assistant-message-frame.js +0 -439
- package/dist/utils/assistant-message-frame.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kimi-coding.js","sourceRoot":"","sources":["../../../src/auth/oauth/kimi-coding.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE7C,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,MAAM,SAAS,GAAG,sCAAsC,CAAC;AACzD,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AACnD,MAAM,2BAA2B,GAAG,EAAE,GAAG,EAAE,CAAC;AAC5C,MA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) OAuth flow\n *\n * RFC 8628 device authorization grant against https://auth.kimi.com with JSON\n * responses. The access token authenticates requests to\n * https://api.kimi.com/coding as an `Authorization: Bearer` header.\n */\n\nimport { getProviderEnvValue } from \"../../utils/provider-env.ts\";\nimport { sleep } from \"../../utils/sleep.ts\";\nimport type { OAuthAuth, OAuthCredential, ProviderAuthInteraction } from \"../types.ts\";\nimport { pollOAuthDeviceCodeFlow } from \"./device-code.ts\";\n\nconst CLIENT_ID = \"17e5f671-d194-4dfb-9706-5516cb48c098\";\nconst DEFAULT_OAUTH_HOST = \"https://auth.kimi.com\";\nconst DEVICE_CODE_TIMEOUT_SECONDS = 15 * 60;\nconst DEFAULT_POLL_INTERVAL_SECONDS = 5;\nconst REQUEST_TIMEOUT_MS = 30 * 1000;\nconst REFRESH_MAX_RETRIES = 3;\n\ntype DeviceAuthorization = {\n\tdeviceCode: string;\n\tuserCode: string;\n\tverificationUri: string;\n\tverificationUriComplete: string;\n\tintervalSeconds: number;\n\texpiresInSeconds: number;\n};\n\ntype TokenResponse = {\n\taccess: string;\n\trefresh: string;\n\texpires: number;\n};\n\nfunction getOauthHost(): string {\n\tconst override = getProviderEnvValue(\"KIMI_CODE_OAUTH_HOST\") || getProviderEnvValue(\"KIMI_OAUTH_HOST\");\n\treturn (override || DEFAULT_OAUTH_HOST).replace(/\\/+$/, \"\");\n}\n\nfunction requestSignal(signal: AbortSignal): AbortSignal {\n\treturn AbortSignal.any([AbortSignal.timeout(REQUEST_TIMEOUT_MS), signal]);\n}\n\nfunction formUrlEncode(fields: Record<string, string>): string {\n\treturn new URLSearchParams(fields).toString();\n}\n\nasync function readJson(response: Response): Promise<Record<string, unknown> | null> {\n\ttry {\n\t\tconst json = await response.json();\n\t\treturn json && typeof json === \"object\" ? (json as Record<string, unknown>) : null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/** The verification URI is opened in the user's browser; only http(s) URLs are trusted. */\nfunction trustedHttpUrl(value: unknown): string | null {\n\tif (typeof value !== \"string\" || !value) return null;\n\ttry {\n\t\tconst url = new URL(value);\n\t\tif (url.protocol !== \"https:\" && url.protocol !== \"http:\") return null;\n\t\treturn url.href;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nasync function startDeviceAuthorization(oauthHost: string, signal: AbortSignal): Promise<DeviceAuthorization> {\n\tconst response = await fetch(`${oauthHost}/api/oauth/device_authorization`, {\n\t\tmethod: \"POST\",\n\t\theaders: {\n\t\t\t\"Content-Type\": \"application/x-www-form-urlencoded\",\n\t\t\tAccept: \"application/json\",\n\t\t},\n\t\tbody: formUrlEncode({ client_id: CLIENT_ID }),\n\t\tsignal: requestSignal(signal),\n\t});\n\n\tif (!response.ok) {\n\t\tconst text = await response.text().catch(() => \"\");\n\t\tthrow new Error(`Kimi Code device authorization failed with status ${response.status}${text ? `: ${text}` : \"\"}`);\n\t}\n\n\tconst json = await readJson(response);\n\tconst deviceCode = json?.device_code;\n\tconst userCode = json?.user_code;\n\tconst verificationUri = json?.verification_uri;\n\tconst verificationUriComplete = json?.verification_uri_complete;\n\tif (\n\t\ttypeof deviceCode !== \"string\" ||\n\t\ttypeof userCode !== \"string\" ||\n\t\ttypeof verificationUri !== \"string\" ||\n\t\ttypeof verificationUriComplete !== \"string\" ||\n\t\t!trustedHttpUrl(verificationUriComplete) ||\n\t\t!trustedHttpUrl(verificationUri)\n\t) {\n\t\tthrow new Error(`Invalid Kimi Code device authorization response: ${JSON.stringify(json)}`);\n\t}\n\n\tconst interval = json?.interval;\n\tconst expiresIn = json?.expires_in;\n\treturn {\n\t\tdeviceCode,\n\t\tuserCode,\n\t\tverificationUri,\n\t\tverificationUriComplete,\n\t\tintervalSeconds:\n\t\t\ttypeof interval === \"number\" && Number.isFinite(interval) && interval > 0\n\t\t\t\t? interval\n\t\t\t\t: DEFAULT_POLL_INTERVAL_SECONDS,\n\t\texpiresInSeconds:\n\t\t\ttypeof expiresIn === \"number\" && Number.isFinite(expiresIn) && expiresIn > 0\n\t\t\t\t? expiresIn\n\t\t\t\t: DEVICE_CODE_TIMEOUT_SECONDS,\n\t};\n}\n\nfunction parseTokenResponse(json: Record<string, unknown> | null, operation: string): TokenResponse {\n\tconst accessToken = json?.access_token;\n\tconst refreshToken = json?.refresh_token;\n\tconst expiresIn = json?.expires_in;\n\tif (\n\t\ttypeof accessToken !== \"string\" ||\n\t\t!accessToken ||\n\t\ttypeof refreshToken !== \"string\" ||\n\t\t!refreshToken ||\n\t\ttypeof expiresIn !== \"number\" ||\n\t\t!Number.isFinite(expiresIn) ||\n\t\texpiresIn <= 0\n\t) {\n\t\tthrow new Error(`Kimi Code token ${operation} response missing fields: ${JSON.stringify(json)}`);\n\t}\n\treturn {\n\t\taccess: accessToken,\n\t\trefresh: refreshToken,\n\t\texpires: Date.now() + expiresIn * 1000,\n\t};\n}\n\nasync function pollForToken(\n\toauthHost: string,\n\tdevice: DeviceAuthorization,\n\tsignal: AbortSignal,\n): Promise<TokenResponse> {\n\treturn pollOAuthDeviceCodeFlow<TokenResponse>({\n\t\tintervalSeconds: device.intervalSeconds,\n\t\texpiresInSeconds: device.expiresInSeconds,\n\t\twaitBeforeFirstPoll: true,\n\t\tsignal,\n\t\tpoll: async () => {\n\t\t\tconst response = await fetch(`${oauthHost}/api/oauth/token`, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\t\"Content-Type\": \"application/x-www-form-urlencoded\",\n\t\t\t\t\tAccept: \"application/json\",\n\t\t\t\t},\n\t\t\t\tbody: formUrlEncode({\n\t\t\t\t\tclient_id: CLIENT_ID,\n\t\t\t\t\tdevice_code: device.deviceCode,\n\t\t\t\t\tgrant_type: \"urn:ietf:params:oauth:grant-type:device_code\",\n\t\t\t\t}),\n\t\t\t\tsignal: requestSignal(signal),\n\t\t\t});\n\n\t\t\tif (response.status >= 500) {\n\t\t\t\tconst text = await response.text().catch(() => \"\");\n\t\t\t\treturn {\n\t\t\t\t\tstatus: \"failed\",\n\t\t\t\t\tmessage: `Kimi Code device token request failed with status ${response.status}${text ? `: ${text}` : \"\"}`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst json = await readJson(response);\n\t\t\tif (response.ok && typeof json?.access_token === \"string\") {\n\t\t\t\ttry {\n\t\t\t\t\treturn { status: \"complete\", value: parseTokenResponse(json, \"poll\") };\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn { status: \"failed\", message: error instanceof Error ? error.message : String(error) };\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst error = json?.error;\n\t\t\tconst description = typeof json?.error_description === \"string\" ? `: ${json.error_description}` : \"\";\n\t\t\tif (error === \"authorization_pending\") {\n\t\t\t\treturn { status: \"pending\" };\n\t\t\t}\n\t\t\tif (error === \"slow_down\") {\n\t\t\t\tconst interval = json?.interval;\n\t\t\t\treturn {\n\t\t\t\t\tstatus: \"slow_down\",\n\t\t\t\t\tintervalSeconds: typeof interval === \"number\" && interval > 0 ? interval : undefined,\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (error === \"expired_token\") {\n\t\t\t\treturn { status: \"failed\", message: \"Kimi Code device authorization expired. Please restart login.\" };\n\t\t\t}\n\t\t\tif (error === \"access_denied\") {\n\t\t\t\treturn { status: \"failed\", message: \"Kimi Code login was denied.\" };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tstatus: \"failed\",\n\t\t\t\tmessage: `Kimi Code device token request failed (status ${response.status})${typeof error === \"string\" ? `: ${error}${description}` : \"\"}`,\n\t\t\t};\n\t\t},\n\t});\n}\n\nfunction isRetryableRefreshFailure(response: Response): boolean {\n\treturn response.status === 429 || response.status >= 500;\n}\n\nasync function refreshToken(oauthHost: string, refreshTokenValue: string, signal: AbortSignal): Promise<TokenResponse> {\n\tlet lastError: Error | undefined;\n\tfor (let attempt = 0; attempt <= REFRESH_MAX_RETRIES; attempt++) {\n\t\tif (attempt > 0) {\n\t\t\tawait sleep(1000 * 2 ** (attempt - 1), signal);\n\t\t}\n\t\tif (signal.aborted) {\n\t\t\tthrow new Error(\"Kimi Code token refresh aborted\");\n\t\t}\n\n\t\tlet response: Response;\n\t\ttry {\n\t\t\tresponse = await fetch(`${oauthHost}/api/oauth/token`, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\t\"Content-Type\": \"application/x-www-form-urlencoded\",\n\t\t\t\t\tAccept: \"application/json\",\n\t\t\t\t},\n\t\t\t\tbody: formUrlEncode({\n\t\t\t\t\tclient_id: CLIENT_ID,\n\t\t\t\t\tgrant_type: \"refresh_token\",\n\t\t\t\t\trefresh_token: refreshTokenValue,\n\t\t\t\t}),\n\t\t\t\tsignal: requestSignal(signal),\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tlastError = error instanceof Error ? error : new Error(String(error));\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst json = await readJson(response);\n\t\tif (response.ok) {\n\t\t\treturn parseTokenResponse(json, \"refresh\");\n\t\t}\n\n\t\t// Unauthorized: the stored credential is dead; Models clears it and prompts re-login.\n\t\tif (response.status === 401 || response.status === 403 || json?.error === \"invalid_grant\") {\n\t\t\tconst description = typeof json?.error_description === \"string\" ? `: ${json.error_description}` : \"\";\n\t\t\tthrow new Error(`Kimi Code token refresh unauthorized (status ${response.status})${description}`);\n\t\t}\n\n\t\tif (isRetryableRefreshFailure(response) && attempt < REFRESH_MAX_RETRIES) {\n\t\t\tlastError = new Error(`Kimi Code token refresh failed with status ${response.status}`);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst text = JSON.stringify(json);\n\t\tthrow new Error(`Kimi Code token refresh failed with status ${response.status}${text ? `: ${text}` : \"\"}`);\n\t}\n\n\tthrow lastError ?? new Error(\"Kimi Code token refresh failed\");\n}\n\nasync function loginKimiCoding(interaction: ProviderAuthInteraction): Promise<OAuthCredential> {\n\tconst oauthHost = getOauthHost();\n\tconst device = await startDeviceAuthorization(oauthHost, interaction.signal);\n\tinteraction.notify({\n\t\ttype: \"device_code\",\n\t\tuserCode: device.userCode,\n\t\tverificationUri: device.verificationUriComplete,\n\t\tintervalSeconds: device.intervalSeconds,\n\t\texpiresInSeconds: device.expiresInSeconds,\n\t});\n\tconst token = await pollForToken(oauthHost, device, interaction.signal);\n\treturn { type: \"oauth\", access: token.access, refresh: token.refresh, expires: token.expires };\n}\n\nexport const kimiCodingOAuth: OAuthAuth = {\n\tname: \"Kimi Code (subscription)\",\n\tisSubscription: true,\n\tloginLabel: \"Sign in with Kimi Code\",\n\n\tlogin: loginKimiCoding,\n\n\trefresh: async (credential, signal) => {\n\t\tconst token = await refreshToken(getOauthHost(), credential.refresh, signal);\n\t\treturn { type: \"oauth\", access: token.access, refresh: token.refresh, expires: token.expires };\n\t},\n\n\tasync toAuth(credential) {\n\t\treturn { headers: { Authorization: `Bearer ${credential.access}` } };\n\t},\n};\n"]}
|
|
1
|
+
{"version":3,"file":"kimi-coding.js","sourceRoot":"","sources":["../../../src/auth/oauth/kimi-coding.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE7C,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,MAAM,SAAS,GAAG,sCAAsC,CAAC;AACzD,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AACnD,MAAM,2BAA2B,GAAG,EAAE,GAAG,EAAE,CAAC;AAC5C,MAAM,6BAA6B,GAAG,CAAC,CAAC;AACxC,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,CAAC;AACrC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAiB9B,SAAS,YAAY;IACpB,MAAM,QAAQ,GAAG,mBAAmB,CAAC,sBAAsB,CAAC,IAAI,mBAAmB,CAAC,iBAAiB,CAAC,CAAC;IACvG,OAAO,CAAC,QAAQ,IAAI,kBAAkB,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED,S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AY,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACxE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;AAChG,CAAC;AAED,MAAM,CAAC,MAAM,eAAe,GAAc;IACzC,IAAI,EAAE,0BAA0B;IAChC,cAAc,EAAE,IAAI;IACpB,UAAU,EAAE,wBAAwB;IAEpC,KAAK,EAAE,eAAe;IAEtB,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,YAAY,EAAE,EAAE,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC7E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;IAChG,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,UAAU;QACtB,OAAO,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,UAAU,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC;IACtE,CAAC;CACD,CAAC","sourcesContent":["/**\n * Kimi Code (subscription) OAuth flow\n *\n * RFC 8628 device authorization grant against https://auth.kimi.com with JSON\n * responses. The access token authenticates requests to\n * https://api.kimi.com/coding/v1 as an `Authorization: Bearer` header.\n */\n\nimport { getProviderEnvValue } from \"../../utils/provider-env.ts\";\nimport { sleep } from \"../../utils/sleep.ts\";\nimport type { OAuthAuth, OAuthCredential, ProviderAuthInteraction } from \"../types.ts\";\nimport { pollOAuthDeviceCodeFlow } from \"./device-code.ts\";\n\nconst CLIENT_ID = \"17e5f671-d194-4dfb-9706-5516cb48c098\";\nconst DEFAULT_OAUTH_HOST = \"https://auth.kimi.com\";\nconst DEVICE_CODE_TIMEOUT_SECONDS = 15 * 60;\nconst DEFAULT_POLL_INTERVAL_SECONDS = 5;\nconst REQUEST_TIMEOUT_MS = 30 * 1000;\nconst REFRESH_MAX_RETRIES = 3;\n\ntype DeviceAuthorization = {\n\tdeviceCode: string;\n\tuserCode: string;\n\tverificationUri: string;\n\tverificationUriComplete: string;\n\tintervalSeconds: number;\n\texpiresInSeconds: number;\n};\n\ntype TokenResponse = {\n\taccess: string;\n\trefresh: string;\n\texpires: number;\n};\n\nfunction getOauthHost(): string {\n\tconst override = getProviderEnvValue(\"KIMI_CODE_OAUTH_HOST\") || getProviderEnvValue(\"KIMI_OAUTH_HOST\");\n\treturn (override || DEFAULT_OAUTH_HOST).replace(/\\/+$/, \"\");\n}\n\nfunction requestSignal(signal: AbortSignal): AbortSignal {\n\treturn AbortSignal.any([AbortSignal.timeout(REQUEST_TIMEOUT_MS), signal]);\n}\n\nfunction formUrlEncode(fields: Record<string, string>): string {\n\treturn new URLSearchParams(fields).toString();\n}\n\nasync function readJson(response: Response): Promise<Record<string, unknown> | null> {\n\ttry {\n\t\tconst json = await response.json();\n\t\treturn json && typeof json === \"object\" ? (json as Record<string, unknown>) : null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/** The verification URI is opened in the user's browser; only http(s) URLs are trusted. */\nfunction trustedHttpUrl(value: unknown): string | null {\n\tif (typeof value !== \"string\" || !value) return null;\n\ttry {\n\t\tconst url = new URL(value);\n\t\tif (url.protocol !== \"https:\" && url.protocol !== \"http:\") return null;\n\t\treturn url.href;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nasync function startDeviceAuthorization(oauthHost: string, signal: AbortSignal): Promise<DeviceAuthorization> {\n\tconst response = await fetch(`${oauthHost}/api/oauth/device_authorization`, {\n\t\tmethod: \"POST\",\n\t\theaders: {\n\t\t\t\"Content-Type\": \"application/x-www-form-urlencoded\",\n\t\t\tAccept: \"application/json\",\n\t\t},\n\t\tbody: formUrlEncode({ client_id: CLIENT_ID }),\n\t\tsignal: requestSignal(signal),\n\t});\n\n\tif (!response.ok) {\n\t\tconst text = await response.text().catch(() => \"\");\n\t\tthrow new Error(`Kimi Code device authorization failed with status ${response.status}${text ? `: ${text}` : \"\"}`);\n\t}\n\n\tconst json = await readJson(response);\n\tconst deviceCode = json?.device_code;\n\tconst userCode = json?.user_code;\n\tconst verificationUri = json?.verification_uri;\n\tconst verificationUriComplete = json?.verification_uri_complete;\n\tif (\n\t\ttypeof deviceCode !== \"string\" ||\n\t\ttypeof userCode !== \"string\" ||\n\t\ttypeof verificationUri !== \"string\" ||\n\t\ttypeof verificationUriComplete !== \"string\" ||\n\t\t!trustedHttpUrl(verificationUriComplete) ||\n\t\t!trustedHttpUrl(verificationUri)\n\t) {\n\t\tthrow new Error(`Invalid Kimi Code device authorization response: ${JSON.stringify(json)}`);\n\t}\n\n\tconst interval = json?.interval;\n\tconst expiresIn = json?.expires_in;\n\treturn {\n\t\tdeviceCode,\n\t\tuserCode,\n\t\tverificationUri,\n\t\tverificationUriComplete,\n\t\tintervalSeconds:\n\t\t\ttypeof interval === \"number\" && Number.isFinite(interval) && interval > 0\n\t\t\t\t? interval\n\t\t\t\t: DEFAULT_POLL_INTERVAL_SECONDS,\n\t\texpiresInSeconds:\n\t\t\ttypeof expiresIn === \"number\" && Number.isFinite(expiresIn) && expiresIn > 0\n\t\t\t\t? expiresIn\n\t\t\t\t: DEVICE_CODE_TIMEOUT_SECONDS,\n\t};\n}\n\nfunction parseTokenResponse(json: Record<string, unknown> | null, operation: string): TokenResponse {\n\tconst accessToken = json?.access_token;\n\tconst refreshToken = json?.refresh_token;\n\tconst expiresIn = json?.expires_in;\n\tif (\n\t\ttypeof accessToken !== \"string\" ||\n\t\t!accessToken ||\n\t\ttypeof refreshToken !== \"string\" ||\n\t\t!refreshToken ||\n\t\ttypeof expiresIn !== \"number\" ||\n\t\t!Number.isFinite(expiresIn) ||\n\t\texpiresIn <= 0\n\t) {\n\t\tthrow new Error(`Kimi Code token ${operation} response missing fields: ${JSON.stringify(json)}`);\n\t}\n\treturn {\n\t\taccess: accessToken,\n\t\trefresh: refreshToken,\n\t\texpires: Date.now() + expiresIn * 1000,\n\t};\n}\n\nasync function pollForToken(\n\toauthHost: string,\n\tdevice: DeviceAuthorization,\n\tsignal: AbortSignal,\n): Promise<TokenResponse> {\n\treturn pollOAuthDeviceCodeFlow<TokenResponse>({\n\t\tintervalSeconds: device.intervalSeconds,\n\t\texpiresInSeconds: device.expiresInSeconds,\n\t\twaitBeforeFirstPoll: true,\n\t\tsignal,\n\t\tpoll: async () => {\n\t\t\tconst response = await fetch(`${oauthHost}/api/oauth/token`, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\t\"Content-Type\": \"application/x-www-form-urlencoded\",\n\t\t\t\t\tAccept: \"application/json\",\n\t\t\t\t},\n\t\t\t\tbody: formUrlEncode({\n\t\t\t\t\tclient_id: CLIENT_ID,\n\t\t\t\t\tdevice_code: device.deviceCode,\n\t\t\t\t\tgrant_type: \"urn:ietf:params:oauth:grant-type:device_code\",\n\t\t\t\t}),\n\t\t\t\tsignal: requestSignal(signal),\n\t\t\t});\n\n\t\t\tif (response.status >= 500) {\n\t\t\t\tconst text = await response.text().catch(() => \"\");\n\t\t\t\treturn {\n\t\t\t\t\tstatus: \"failed\",\n\t\t\t\t\tmessage: `Kimi Code device token request failed with status ${response.status}${text ? `: ${text}` : \"\"}`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst json = await readJson(response);\n\t\t\tif (response.ok && typeof json?.access_token === \"string\") {\n\t\t\t\ttry {\n\t\t\t\t\treturn { status: \"complete\", value: parseTokenResponse(json, \"poll\") };\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn { status: \"failed\", message: error instanceof Error ? error.message : String(error) };\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst error = json?.error;\n\t\t\tconst description = typeof json?.error_description === \"string\" ? `: ${json.error_description}` : \"\";\n\t\t\tif (error === \"authorization_pending\") {\n\t\t\t\treturn { status: \"pending\" };\n\t\t\t}\n\t\t\tif (error === \"slow_down\") {\n\t\t\t\tconst interval = json?.interval;\n\t\t\t\treturn {\n\t\t\t\t\tstatus: \"slow_down\",\n\t\t\t\t\tintervalSeconds: typeof interval === \"number\" && interval > 0 ? interval : undefined,\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (error === \"expired_token\") {\n\t\t\t\treturn { status: \"failed\", message: \"Kimi Code device authorization expired. Please restart login.\" };\n\t\t\t}\n\t\t\tif (error === \"access_denied\") {\n\t\t\t\treturn { status: \"failed\", message: \"Kimi Code login was denied.\" };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tstatus: \"failed\",\n\t\t\t\tmessage: `Kimi Code device token request failed (status ${response.status})${typeof error === \"string\" ? `: ${error}${description}` : \"\"}`,\n\t\t\t};\n\t\t},\n\t});\n}\n\nfunction isRetryableRefreshFailure(response: Response): boolean {\n\treturn response.status === 429 || response.status >= 500;\n}\n\nasync function refreshToken(oauthHost: string, refreshTokenValue: string, signal: AbortSignal): Promise<TokenResponse> {\n\tlet lastError: Error | undefined;\n\tfor (let attempt = 0; attempt <= REFRESH_MAX_RETRIES; attempt++) {\n\t\tif (attempt > 0) {\n\t\t\tawait sleep(1000 * 2 ** (attempt - 1), signal);\n\t\t}\n\t\tif (signal.aborted) {\n\t\t\tthrow new Error(\"Kimi Code token refresh aborted\");\n\t\t}\n\n\t\tlet response: Response;\n\t\ttry {\n\t\t\tresponse = await fetch(`${oauthHost}/api/oauth/token`, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\t\"Content-Type\": \"application/x-www-form-urlencoded\",\n\t\t\t\t\tAccept: \"application/json\",\n\t\t\t\t},\n\t\t\t\tbody: formUrlEncode({\n\t\t\t\t\tclient_id: CLIENT_ID,\n\t\t\t\t\tgrant_type: \"refresh_token\",\n\t\t\t\t\trefresh_token: refreshTokenValue,\n\t\t\t\t}),\n\t\t\t\tsignal: requestSignal(signal),\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tlastError = error instanceof Error ? error : new Error(String(error));\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst json = await readJson(response);\n\t\tif (response.ok) {\n\t\t\treturn parseTokenResponse(json, \"refresh\");\n\t\t}\n\n\t\t// Unauthorized: the stored credential is dead; Models clears it and prompts re-login.\n\t\tif (response.status === 401 || response.status === 403 || json?.error === \"invalid_grant\") {\n\t\t\tconst description = typeof json?.error_description === \"string\" ? `: ${json.error_description}` : \"\";\n\t\t\tthrow new Error(`Kimi Code token refresh unauthorized (status ${response.status})${description}`);\n\t\t}\n\n\t\tif (isRetryableRefreshFailure(response) && attempt < REFRESH_MAX_RETRIES) {\n\t\t\tlastError = new Error(`Kimi Code token refresh failed with status ${response.status}`);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst text = JSON.stringify(json);\n\t\tthrow new Error(`Kimi Code token refresh failed with status ${response.status}${text ? `: ${text}` : \"\"}`);\n\t}\n\n\tthrow lastError ?? new Error(\"Kimi Code token refresh failed\");\n}\n\nasync function loginKimiCoding(interaction: ProviderAuthInteraction): Promise<OAuthCredential> {\n\tconst oauthHost = getOauthHost();\n\tconst device = await startDeviceAuthorization(oauthHost, interaction.signal);\n\tinteraction.notify({\n\t\ttype: \"device_code\",\n\t\tuserCode: device.userCode,\n\t\tverificationUri: device.verificationUriComplete,\n\t\tintervalSeconds: device.intervalSeconds,\n\t\texpiresInSeconds: device.expiresInSeconds,\n\t});\n\tconst token = await pollForToken(oauthHost, device, interaction.signal);\n\treturn { type: \"oauth\", access: token.access, refresh: token.refresh, expires: token.expires };\n}\n\nexport const kimiCodingOAuth: OAuthAuth = {\n\tname: \"Kimi Code (subscription)\",\n\tisSubscription: true,\n\tloginLabel: \"Sign in with Kimi Code\",\n\n\tlogin: loginKimiCoding,\n\n\trefresh: async (credential, signal) => {\n\t\tconst token = await refreshToken(getOauthHost(), credential.refresh, signal);\n\t\treturn { type: \"oauth\", access: token.access, refresh: token.refresh, expires: token.expires };\n\t},\n\n\tasync toAuth(credential) {\n\t\treturn { headers: { Authorization: `Bearer ${credential.access}` } };\n\t},\n};\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -26,9 +26,9 @@ export { normalizeProviderId } from "./provider-id.ts";
|
|
|
26
26
|
export * from "./providers/faux.ts";
|
|
27
27
|
export * from "./session-resources.ts";
|
|
28
28
|
export * from "./types.ts";
|
|
29
|
-
export * from "./utils/assistant-message-frame.ts";
|
|
30
29
|
export * from "./utils/diagnostics.ts";
|
|
31
30
|
export * from "./utils/event-stream.ts";
|
|
31
|
+
export { AssistantMessageEventStream } from "./utils/event-stream.ts";
|
|
32
32
|
export * from "./utils/json-parse.ts";
|
|
33
33
|
export * from "./utils/overflow.ts";
|
|
34
34
|
export * from "./utils/retry.ts";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAO/B,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAC/G,YAAY,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AACnF,YAAY,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC/F,YAAY,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,YAAY,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAClG,YAAY,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAClE,cAAc,eAAe,CAAC;AAC9B,YAAY,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,YAAY,EAAE,2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,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC/F,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,cAAc,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -12,9 +12,9 @@ export { normalizeProviderId } from "./provider-id.js";
|
|
|
12
12
|
export * from "./providers/faux.js";
|
|
13
13
|
export * from "./session-resources.js";
|
|
14
14
|
export * from "./types.js";
|
|
15
|
-
export * from "./utils/assistant-message-frame.js";
|
|
16
15
|
export * from "./utils/diagnostics.js";
|
|
17
16
|
export * from "./utils/event-stream.js";
|
|
17
|
+
export { AssistantMessageEventStream } from "./utils/event-stream.js";
|
|
18
18
|
export * from "./utils/json-parse.js";
|
|
19
19
|
export * from "./utils/overflow.js";
|
|
20
20
|
export * from "./utils/retry.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAa/B,cAAc,eAAe,CAAC;AAO9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAShC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAC/D,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC;AAC3B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAa/B,cAAc,eAAe,CAAC;AAO9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAShC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAC/D,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AACtE,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC/F,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,cAAc,uBAAuB,CAAC","sourcesContent":["export type { Static, TSchema } from \"typebox\";\nexport { Type } from \"typebox\";\n\n// Core only, side-effect free: no generated catalogs, no provider factories,\n// no api-registry, no OAuth implementations, no compat. Provider factories\n// live under \"@bastani/pi-ai/providers/*\", API implementations under\n// \"@bastani/pi-ai/api/*\", the old global API under\n// \"@bastani/pi-ai/compat\".\nexport type { AnthropicEffort, AnthropicOptions, AnthropicThinkingDisplay } from \"./api/anthropic-messages.ts\";\nexport type { AzureOpenAIResponsesOptions } from \"./api/azure-openai-responses.ts\";\nexport type { BedrockOptions, BedrockThinkingDisplay } from \"./api/bedrock-converse-stream.ts\";\nexport type { GoogleOptions } from \"./api/google-generative-ai.ts\";\nexport type { GoogleApiThinkingLevel, ResolvedGoogleThinkingLevel } from \"./api/google-shared.ts\";\nexport type { GoogleVertexOptions } from \"./api/google-vertex.ts\";\nexport * from \"./api/lazy.ts\";\nexport type { MistralOptions } from \"./api/mistral-conversations.ts\";\nexport type { OpenAICodexResponsesOptions, OpenAICodexWebSocketDebugStats } from \"./api/openai-codex-responses.ts\";\nexport type { OpenAICompletionsOptions } from \"./api/openai-completions.ts\";\nexport type { OpenAIImagesOptions } from \"./api/openai-images.ts\";\nexport type { OpenAIResponsesOptions } from \"./api/openai-responses.ts\";\nexport type { PiMessagesEvent, PiMessagesOptions, PiMessagesRewriteImpact } from \"./api/pi-messages.ts\";\nexport * from \"./auth/context.ts\";\nexport * from \"./auth/credential-store.ts\";\nexport * from \"./auth/helpers.ts\";\nexport * from \"./auth/types.ts\";\nexport type {\n\tOAuthAuthInfo,\n\tOAuthDeviceCodeInfo,\n\tOAuthLoginCallbacks,\n\tOAuthPrompt,\n\tOAuthSelectOption,\n\tOAuthSelectPrompt,\n} from \"./compat/extension-oauth-types.ts\";\nexport * from \"./decision-models.ts\";\nexport { containsKnownEnvCredential } from \"./env-api-keys.ts\";\nexport * from \"./models.ts\";\nexport * from \"./models-store.ts\";\nexport { normalizeProviderId } from \"./provider-id.ts\";\nexport * from \"./providers/faux.ts\";\nexport * from \"./session-resources.ts\";\nexport * from \"./types.ts\";\nexport * from \"./utils/diagnostics.ts\";\nexport * from \"./utils/event-stream.ts\";\nexport { AssistantMessageEventStream } from \"./utils/event-stream.ts\";\nexport * from \"./utils/json-parse.ts\";\nexport * from \"./utils/overflow.ts\";\nexport * from \"./utils/retry.ts\";\nexport * from \"./utils/stream-deadline.ts\";\nexport { contentText, getSystemMessageText, renderSystemMessageUpdate } from \"./utils/text.ts\";\nexport * from \"./utils/transcript.ts\";\nexport * from \"./utils/typebox-helpers.ts\";\nexport { uuidv7 } from \"./utils/uuid.ts\";\nexport * from \"./utils/validation.ts\";\n"]}
|
package/dist/model-catalog.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export type ClassifierModelCatalog<TGroups extends ModelGroups, TProvider extend
|
|
|
26
26
|
provider: TProvider;
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
|
-
export declare function flattenChatModelCatalog<const TProvider extends ProviderId, const TGroups extends ModelGroups>(
|
|
29
|
+
export declare function flattenChatModelCatalog<const TProvider extends ProviderId, const TGroups extends ModelGroups>(provider: TProvider, groups: TGroups): ChatModelCatalog<TGroups, TProvider>;
|
|
30
30
|
export declare function flattenImageModelCatalog<const TProvider extends ProviderId, const TGroups extends ModelGroups>(_provider: TProvider, groups: TGroups): ImageModelCatalog<TGroups, TProvider>;
|
|
31
31
|
export declare function flattenClassifierModelCatalog<const TProvider extends ProviderId, const TGroups extends ModelGroups>(_provider: TProvider, groups: TGroups): ClassifierModelCatalog<TGroups, TProvider>;
|
|
32
32
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-catalog.d.ts","sourceRoot":"","sources":["../src/model-catalog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,GAAG,EACH,aAAa,EACb,eAAe,EACf,QAAQ,EACR,UAAU,EACV,KAAK,EACL,SAAS,EACT,UAAU,EACV,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEjE,KAAK,QAAQ,CAAC,OAAO,SAAS,WAAW,IAAI;KAC3C,IAAI,IAAI,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;CAC5C,CAAC,MAAM,OAAO,CAAC,GACf,MAAM,CAAC;AAER,KAAK,UAAU,CAAC,OAAO,SAAS,WAAW,EAAE,KAAK,SAAS,SAAS,IAAI,OAAO,CAC9E,QAAQ,CAAC,OAAO,CAAC,EACjB,GAAG,KAAK,IAAI,MAAM,EAAE,CACp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AS,CAAC,CAiCtC;AAED,wBAAgB,wBAAwB,CAAC,KAAK,CAAC,SAAS,SAAS,UAAU,EAAE,KAAK,CAAC,OAAO,SAAS,WAAW,EAC7G,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,OAAO,GACb,iBAAiB,CAAC,OAAO,EAAE,SAAS,CAAC,CAEvC;AAED,wBAAgB,6BAA6B,CAAC,KAAK,CAAC,SAAS,SAAS,UAAU,EAAE,KAAK,CAAC,OAAO,SAAS,WAAW,EAClH,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,OAAO,GACb,sBAAsB,CAAC,OAAO,EAAE,SAAS,CAAC,CAE5C"}
|
package/dist/model-catalog.js
CHANGED
|
@@ -4,8 +4,38 @@ function flattenModelCatalog(groups, type) {
|
|
|
4
4
|
.filter((model) => model.type === type)
|
|
5
5
|
.map((model) => [model.id, model]));
|
|
6
6
|
}
|
|
7
|
-
export function flattenChatModelCatalog(
|
|
8
|
-
|
|
7
|
+
export function flattenChatModelCatalog(provider, groups) {
|
|
8
|
+
const catalog = flattenModelCatalog(groups, "chat");
|
|
9
|
+
if (provider === "xiaomi" ||
|
|
10
|
+
provider === "xiaomi-token-plan-cn" ||
|
|
11
|
+
provider === "xiaomi-token-plan-ams" ||
|
|
12
|
+
provider === "xiaomi-token-plan-sgp") {
|
|
13
|
+
for (const [id, entry] of Object.entries(catalog)) {
|
|
14
|
+
const model = entry;
|
|
15
|
+
if (model.api !== "openai-completions")
|
|
16
|
+
continue;
|
|
17
|
+
Object.assign(catalog, {
|
|
18
|
+
[id]: {
|
|
19
|
+
...model,
|
|
20
|
+
compat: { ...model.compat, supportsReasoningEffort: false },
|
|
21
|
+
...(model.reasoning
|
|
22
|
+
? {
|
|
23
|
+
thinkingLevelMap: {
|
|
24
|
+
off: "off",
|
|
25
|
+
minimal: null,
|
|
26
|
+
low: null,
|
|
27
|
+
medium: null,
|
|
28
|
+
high: "high",
|
|
29
|
+
xhigh: null,
|
|
30
|
+
max: null,
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
: {}),
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return catalog;
|
|
9
39
|
}
|
|
10
40
|
export function flattenImageModelCatalog(_provider, groups) {
|
|
11
41
|
return flattenModelCatalog(groups, "image");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-catalog.js","sourceRoot":"","sources":["../src/model-catalog.ts"],"names":[],"mappings":"AAoDA,SAAS,mBAAmB,CAAC,MAAmB,EAAE,IAAe;IAChE,OAAO,MAAM,CAAC,WAAW,CACxB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;SACnB,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;SAC1C,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAE,KAA4B,CAAC,IAAI,KAAK,IAAI,CAAC;SAC9D,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAE,KAAwB,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CACvD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,uBAAuB,CACtC,
|
|
1
|
+
{"version":3,"file":"model-catalog.js","sourceRoot":"","sources":["../src/model-catalog.ts"],"names":[],"mappings":"AAoDA,SAAS,mBAAmB,CAAC,MAAmB,EAAE,IAAe;IAChE,OAAO,MAAM,CAAC,WAAW,CACxB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;SACnB,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;SAC1C,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAE,KAA4B,CAAC,IAAI,KAAK,IAAI,CAAC;SAC9D,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAE,KAAwB,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CACv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CAAC;AAChG,CAAC","sourcesContent":["import type {\n\tApi,\n\tClassifierApi,\n\tClassifierModel,\n\tImageApi,\n\tImageModel,\n\tModel,\n\tModelType,\n\tProviderId,\n} from \"./types.ts\";\n\nexport type ModelGroups = Record<string, Record<string, object>>;\n\ntype ModelKey<TGroups extends ModelGroups> = {\n\t[TApi in keyof TGroups]: keyof TGroups[TApi];\n}[keyof TGroups] &\n\tstring;\n\ntype KeyForType<TGroups extends ModelGroups, TType extends ModelType> = Extract<\n\tModelKey<TGroups>,\n\t`${TType}:${string}`\n>;\n\ntype ModelId<TKey extends string> = TKey extends `${ModelType}:${infer TModelId}` ? TModelId : never;\n\ntype ApiForKey<TGroups extends ModelGroups, TKey extends ModelKey<TGroups>> = {\n\t[TApi in keyof TGroups]: TKey extends keyof TGroups[TApi] ? TApi : never;\n}[keyof TGroups];\n\nexport type ChatModelCatalog<TGroups extends ModelGroups, TProvider extends ProviderId> = {\n\t[TKey in KeyForType<TGroups, \"chat\"> as ModelId<TKey>]: Model<ApiForKey<TGroups, TKey> & Api> & {\n\t\tid: ModelId<TKey>;\n\t\tprovider: TProvider;\n\t};\n};\n\nexport type ImageModelCatalog<TGroups extends ModelGroups, TProvider extends ProviderId> = {\n\t[TKey in KeyForType<TGroups, \"image\"> as ModelId<TKey>]: ImageModel<ApiForKey<TGroups, TKey> & ImageApi> & {\n\t\tid: ModelId<TKey>;\n\t\tprovider: TProvider;\n\t};\n};\n\nexport type ClassifierModelCatalog<TGroups extends ModelGroups, TProvider extends ProviderId> = {\n\t[TKey in KeyForType<TGroups, \"classifier\"> as ModelId<TKey>]: ClassifierModel<\n\t\tApiForKey<TGroups, TKey> & ClassifierApi\n\t> & {\n\t\tid: ModelId<TKey>;\n\t\tprovider: TProvider;\n\t};\n};\n\nfunction flattenModelCatalog(groups: ModelGroups, type: ModelType): Record<string, object> {\n\treturn Object.fromEntries(\n\t\tObject.values(groups)\n\t\t\t.flatMap((models) => Object.values(models))\n\t\t\t.filter((model) => (model as { type?: unknown }).type === type)\n\t\t\t.map((model) => [(model as { id: string }).id, model]),\n\t);\n}\n\nexport function flattenChatModelCatalog<const TProvider extends ProviderId, const TGroups extends ModelGroups>(\n\tprovider: TProvider,\n\tgroups: TGroups,\n): ChatModelCatalog<TGroups, TProvider> {\n\tconst catalog = flattenModelCatalog(groups, \"chat\") as ChatModelCatalog<TGroups, TProvider>;\n\tif (\n\t\tprovider === \"xiaomi\" ||\n\t\tprovider === \"xiaomi-token-plan-cn\" ||\n\t\tprovider === \"xiaomi-token-plan-ams\" ||\n\t\tprovider === \"xiaomi-token-plan-sgp\"\n\t) {\n\t\tfor (const [id, entry] of Object.entries(catalog)) {\n\t\t\tconst model = entry as Model<Api>;\n\t\t\tif (model.api !== \"openai-completions\") continue;\n\t\t\tObject.assign(catalog, {\n\t\t\t\t[id]: {\n\t\t\t\t\t...model,\n\t\t\t\t\tcompat: { ...model.compat, supportsReasoningEffort: false },\n\t\t\t\t\t...(model.reasoning\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tthinkingLevelMap: {\n\t\t\t\t\t\t\t\t\toff: \"off\",\n\t\t\t\t\t\t\t\t\tminimal: null,\n\t\t\t\t\t\t\t\t\tlow: null,\n\t\t\t\t\t\t\t\t\tmedium: null,\n\t\t\t\t\t\t\t\t\thigh: \"high\",\n\t\t\t\t\t\t\t\t\txhigh: null,\n\t\t\t\t\t\t\t\t\tmax: null,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: {}),\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t}\n\treturn catalog;\n}\n\nexport function flattenImageModelCatalog<const TProvider extends ProviderId, const TGroups extends ModelGroups>(\n\t_provider: TProvider,\n\tgroups: TGroups,\n): ImageModelCatalog<TGroups, TProvider> {\n\treturn flattenModelCatalog(groups, \"image\") as ImageModelCatalog<TGroups, TProvider>;\n}\n\nexport function flattenClassifierModelCatalog<const TProvider extends ProviderId, const TGroups extends ModelGroups>(\n\t_provider: TProvider,\n\tgroups: TGroups,\n): ClassifierModelCatalog<TGroups, TProvider> {\n\treturn flattenModelCatalog(groups, \"classifier\") as ClassifierModelCatalog<TGroups, TProvider>;\n}\n"]}
|
|
@@ -143,6 +143,7 @@ export declare const OpenAIResponsesCompatSchema: Type.TObject<{
|
|
|
143
143
|
supportsAdditionalTools: Type.TOptional<Type.TBoolean>;
|
|
144
144
|
supportsToolSearch: Type.TOptional<Type.TBoolean>;
|
|
145
145
|
supportsExplicitPromptCacheMode: Type.TOptional<Type.TBoolean>;
|
|
146
|
+
supportsMidConvoEffort: Type.TOptional<Type.TBoolean>;
|
|
146
147
|
supportsMaxOutputTokens: Type.TOptional<Type.TBoolean>;
|
|
147
148
|
}>;
|
|
148
149
|
export declare const AnthropicMessagesCompatSchema: Type.TObject<{
|
|
@@ -189,6 +190,162 @@ export declare const MistralConversationsCompatSchema: Type.TObject<{
|
|
|
189
190
|
}>;
|
|
190
191
|
type UnionToIntersection<Union> = (Union extends unknown ? (value: Union) => void : never) extends (value: infer Intersection) => void ? Intersection : never;
|
|
191
192
|
type MergedCompatProperties<PropertyGroups extends readonly TProperties[], Overrides extends TProperties> = Omit<UnionToIntersection<PropertyGroups[number]>, keyof Overrides> & Overrides;
|
|
193
|
+
export declare const CompatSchemasByApi: {
|
|
194
|
+
readonly "openai-completions": Type.TObject<{
|
|
195
|
+
supportsStore: Type.TOptional<Type.TBoolean>;
|
|
196
|
+
supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
|
|
197
|
+
supportsReasoningEffort: Type.TOptional<Type.TBoolean>;
|
|
198
|
+
supportsTemperature: Type.TOptional<Type.TBoolean>;
|
|
199
|
+
supportsForcedToolChoice: Type.TOptional<Type.TBoolean>;
|
|
200
|
+
supportsUsageInStreaming: Type.TOptional<Type.TBoolean>;
|
|
201
|
+
supportsFinishReason: Type.TOptional<Type.TBoolean>;
|
|
202
|
+
maxTokensField: Type.TOptional<Type.TUnion<[Type.TLiteral<"max_completion_tokens">, Type.TLiteral<"max_tokens">]>>;
|
|
203
|
+
requiresToolResultName: Type.TOptional<Type.TBoolean>;
|
|
204
|
+
requiresAssistantAfterToolResult: Type.TOptional<Type.TBoolean>;
|
|
205
|
+
requiresThinkingAsText: Type.TOptional<Type.TBoolean>;
|
|
206
|
+
requiresReasoningContentOnAssistantMessages: Type.TOptional<Type.TBoolean>;
|
|
207
|
+
thinkingFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openrouter">, Type.TLiteral<"deepseek">, Type.TLiteral<"together">, Type.TLiteral<"baseten">, Type.TLiteral<"zai">, Type.TLiteral<"qwen">, Type.TLiteral<"chat-template">, Type.TLiteral<"qwen-chat-template">, Type.TLiteral<"string-thinking">, Type.TLiteral<"ant-ling">]>>;
|
|
208
|
+
chatTemplateKwargs: Type.TOptional<Type.TRecord<"^.*$", Type.TUnion<[Type.TString, Type.TNumber, Type.TBoolean, Type.TNull, Type.TObject<{
|
|
209
|
+
$var: Type.TUnion<[Type.TLiteral<"thinking.enabled">, Type.TLiteral<"thinking.effort">, Type.TLiteral<"thinking.budget">]>;
|
|
210
|
+
omitWhenOff: Type.TOptional<Type.TBoolean>;
|
|
211
|
+
}>]>>>;
|
|
212
|
+
chatTemplateArgs: Type.TOptional<Type.TRecord<"^.*$", Type.TUnion<[Type.TString, Type.TNumber, Type.TBoolean, Type.TNull, Type.TObject<{
|
|
213
|
+
$var: Type.TUnion<[Type.TLiteral<"thinking.enabled">, Type.TLiteral<"thinking.effort">, Type.TLiteral<"thinking.budget">]>;
|
|
214
|
+
omitWhenOff: Type.TOptional<Type.TBoolean>;
|
|
215
|
+
}>]>>>;
|
|
216
|
+
openRouterRouting: Type.TOptional<Type.TObject<{
|
|
217
|
+
allow_fallbacks: Type.TOptional<Type.TBoolean>;
|
|
218
|
+
require_parameters: Type.TOptional<Type.TBoolean>;
|
|
219
|
+
data_collection: Type.TOptional<Type.TUnion<[Type.TLiteral<"deny">, Type.TLiteral<"allow">]>>;
|
|
220
|
+
zdr: Type.TOptional<Type.TBoolean>;
|
|
221
|
+
enforce_distillable_text: Type.TOptional<Type.TBoolean>;
|
|
222
|
+
order: Type.TOptional<Type.TArray<Type.TString>>;
|
|
223
|
+
only: Type.TOptional<Type.TArray<Type.TString>>;
|
|
224
|
+
ignore: Type.TOptional<Type.TArray<Type.TString>>;
|
|
225
|
+
quantizations: Type.TOptional<Type.TArray<Type.TString>>;
|
|
226
|
+
sort: Type.TOptional<Type.TUnion<[Type.TString, Type.TObject<{
|
|
227
|
+
by: Type.TOptional<Type.TString>;
|
|
228
|
+
partition: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
|
|
229
|
+
}>]>>;
|
|
230
|
+
max_price: Type.TOptional<Type.TObject<{
|
|
231
|
+
prompt: Type.TOptional<Type.TUnion<[Type.TNumber, Type.TString]>>;
|
|
232
|
+
completion: Type.TOptional<Type.TUnion<[Type.TNumber, Type.TString]>>;
|
|
233
|
+
image: Type.TOptional<Type.TUnion<[Type.TNumber, Type.TString]>>;
|
|
234
|
+
audio: Type.TOptional<Type.TUnion<[Type.TNumber, Type.TString]>>;
|
|
235
|
+
request: Type.TOptional<Type.TUnion<[Type.TNumber, Type.TString]>>;
|
|
236
|
+
}>>;
|
|
237
|
+
preferred_min_throughput: Type.TOptional<Type.TUnion<[Type.TNumber, Type.TObject<{
|
|
238
|
+
p50: Type.TOptional<Type.TNumber>;
|
|
239
|
+
p75: Type.TOptional<Type.TNumber>;
|
|
240
|
+
p90: Type.TOptional<Type.TNumber>;
|
|
241
|
+
p99: Type.TOptional<Type.TNumber>;
|
|
242
|
+
}>]>>;
|
|
243
|
+
preferred_max_latency: Type.TOptional<Type.TUnion<[Type.TNumber, Type.TObject<{
|
|
244
|
+
p50: Type.TOptional<Type.TNumber>;
|
|
245
|
+
p75: Type.TOptional<Type.TNumber>;
|
|
246
|
+
p90: Type.TOptional<Type.TNumber>;
|
|
247
|
+
p99: Type.TOptional<Type.TNumber>;
|
|
248
|
+
}>]>>;
|
|
249
|
+
}>>;
|
|
250
|
+
vercelGatewayRouting: Type.TOptional<Type.TObject<{
|
|
251
|
+
only: Type.TOptional<Type.TArray<Type.TString>>;
|
|
252
|
+
order: Type.TOptional<Type.TArray<Type.TString>>;
|
|
253
|
+
}>>;
|
|
254
|
+
zaiToolStream: Type.TOptional<Type.TBoolean>;
|
|
255
|
+
thinkingTokenBudgetField: Type.TOptional<Type.TUnion<[Type.TLiteral<"thinking_token_budget">, Type.TLiteral<"thinking_budget">, Type.TLiteral<"thinking_budget_tokens">]>>;
|
|
256
|
+
supportsThinkingTokenBudget: Type.TOptional<Type.TBoolean>;
|
|
257
|
+
supportsOpenAIGrammarTools: Type.TOptional<Type.TBoolean>;
|
|
258
|
+
supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
|
|
259
|
+
supportsMidConvoToolAdditions: Type.TOptional<Type.TBoolean>;
|
|
260
|
+
supportsStrictMode: Type.TOptional<Type.TBoolean>;
|
|
261
|
+
cacheControlFormat: Type.TOptional<Type.TLiteral<"anthropic">>;
|
|
262
|
+
sendSessionAffinityHeaders: Type.TOptional<Type.TBoolean>;
|
|
263
|
+
sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
|
|
264
|
+
supportsLongCacheRetention: Type.TOptional<Type.TBoolean>;
|
|
265
|
+
vllmPriority: Type.TOptional<Type.TNumber>;
|
|
266
|
+
}>;
|
|
267
|
+
readonly "openai-responses": Type.TObject<{
|
|
268
|
+
supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
|
|
269
|
+
supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
|
|
270
|
+
sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
|
|
271
|
+
supportsLongCacheRetention: Type.TOptional<Type.TBoolean>;
|
|
272
|
+
supportsStrictMode: Type.TOptional<Type.TBoolean>;
|
|
273
|
+
supportsOpenAIGrammarTools: Type.TOptional<Type.TBoolean>;
|
|
274
|
+
supportsAdditionalTools: Type.TOptional<Type.TBoolean>;
|
|
275
|
+
supportsToolSearch: Type.TOptional<Type.TBoolean>;
|
|
276
|
+
supportsExplicitPromptCacheMode: Type.TOptional<Type.TBoolean>;
|
|
277
|
+
supportsMidConvoEffort: Type.TOptional<Type.TBoolean>;
|
|
278
|
+
supportsMaxOutputTokens: Type.TOptional<Type.TBoolean>;
|
|
279
|
+
}>;
|
|
280
|
+
readonly "azure-openai-responses": Type.TObject<{
|
|
281
|
+
supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
|
|
282
|
+
supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
|
|
283
|
+
sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
|
|
284
|
+
supportsLongCacheRetention: Type.TOptional<Type.TBoolean>;
|
|
285
|
+
supportsStrictMode: Type.TOptional<Type.TBoolean>;
|
|
286
|
+
supportsOpenAIGrammarTools: Type.TOptional<Type.TBoolean>;
|
|
287
|
+
supportsAdditionalTools: Type.TOptional<Type.TBoolean>;
|
|
288
|
+
supportsToolSearch: Type.TOptional<Type.TBoolean>;
|
|
289
|
+
supportsExplicitPromptCacheMode: Type.TOptional<Type.TBoolean>;
|
|
290
|
+
supportsMidConvoEffort: Type.TOptional<Type.TBoolean>;
|
|
291
|
+
supportsMaxOutputTokens: Type.TOptional<Type.TBoolean>;
|
|
292
|
+
}>;
|
|
293
|
+
readonly "openai-codex-responses": Type.TObject<{
|
|
294
|
+
supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
|
|
295
|
+
supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
|
|
296
|
+
sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
|
|
297
|
+
supportsLongCacheRetention: Type.TOptional<Type.TBoolean>;
|
|
298
|
+
supportsStrictMode: Type.TOptional<Type.TBoolean>;
|
|
299
|
+
supportsOpenAIGrammarTools: Type.TOptional<Type.TBoolean>;
|
|
300
|
+
supportsAdditionalTools: Type.TOptional<Type.TBoolean>;
|
|
301
|
+
supportsToolSearch: Type.TOptional<Type.TBoolean>;
|
|
302
|
+
supportsExplicitPromptCacheMode: Type.TOptional<Type.TBoolean>;
|
|
303
|
+
supportsMidConvoEffort: Type.TOptional<Type.TBoolean>;
|
|
304
|
+
supportsMaxOutputTokens: Type.TOptional<Type.TBoolean>;
|
|
305
|
+
}>;
|
|
306
|
+
readonly "anthropic-messages": Type.TObject<{
|
|
307
|
+
supportsEagerToolInputStreaming: Type.TOptional<Type.TBoolean>;
|
|
308
|
+
supportsLongCacheRetention: Type.TOptional<Type.TBoolean>;
|
|
309
|
+
sendSessionAffinityHeaders: Type.TOptional<Type.TBoolean>;
|
|
310
|
+
sessionAffinityFormat: Type.TOptional<Type.TLiteral<"openrouter">>;
|
|
311
|
+
supportsCacheControlOnTools: Type.TOptional<Type.TBoolean>;
|
|
312
|
+
supportsTemperature: Type.TOptional<Type.TBoolean>;
|
|
313
|
+
forceAdaptiveThinking: Type.TOptional<Type.TBoolean>;
|
|
314
|
+
allowEmptySignature: Type.TOptional<Type.TBoolean>;
|
|
315
|
+
supportsStrictTools: Type.TOptional<Type.TBoolean>;
|
|
316
|
+
supportsMidConvoEffort: Type.TOptional<Type.TBoolean>;
|
|
317
|
+
supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
|
|
318
|
+
supportsMidConvoToolChanges: Type.TOptional<Type.TBoolean>;
|
|
319
|
+
allowedFallbackModels: Type.TOptional<Type.TArray<Type.TObject<{
|
|
320
|
+
provider: Type.TString;
|
|
321
|
+
model: Type.TString;
|
|
322
|
+
cost: Type.TObject<{
|
|
323
|
+
input: Type.TNumber;
|
|
324
|
+
output: Type.TNumber;
|
|
325
|
+
cacheRead: Type.TNumber;
|
|
326
|
+
cacheWrite: Type.TNumber;
|
|
327
|
+
tiers: Type.TOptional<Type.TArray<Type.TObject<{
|
|
328
|
+
input: Type.TNumber;
|
|
329
|
+
output: Type.TNumber;
|
|
330
|
+
cacheRead: Type.TNumber;
|
|
331
|
+
cacheWrite: Type.TNumber;
|
|
332
|
+
inputTokensAbove: Type.TNumber;
|
|
333
|
+
}>>>;
|
|
334
|
+
}>;
|
|
335
|
+
}>>>;
|
|
336
|
+
enforcesPreservedThinkingBinding: Type.TOptional<Type.TBoolean>;
|
|
337
|
+
delegatesThinkingModelBinding: Type.TOptional<Type.TBoolean>;
|
|
338
|
+
supportsForcedToolChoice: Type.TOptional<Type.TBoolean>;
|
|
339
|
+
}>;
|
|
340
|
+
readonly "bedrock-converse-stream": Type.TObject<{
|
|
341
|
+
supportsStrictMode: Type.TOptional<Type.TBoolean>;
|
|
342
|
+
supportsForcedToolChoice: Type.TOptional<Type.TBoolean>;
|
|
343
|
+
supportsTemperature: Type.TOptional<Type.TBoolean>;
|
|
344
|
+
}>;
|
|
345
|
+
readonly "mistral-conversations": Type.TObject<{
|
|
346
|
+
supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
|
|
347
|
+
}>;
|
|
348
|
+
};
|
|
192
349
|
export declare const ProviderCompatSchema: Type.TObject<MergedCompatProperties<({
|
|
193
350
|
supportsStore: Type.TOptional<Type.TBoolean>;
|
|
194
351
|
supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
|
|
@@ -271,6 +428,7 @@ export declare const ProviderCompatSchema: Type.TObject<MergedCompatProperties<(
|
|
|
271
428
|
supportsAdditionalTools: Type.TOptional<Type.TBoolean>;
|
|
272
429
|
supportsToolSearch: Type.TOptional<Type.TBoolean>;
|
|
273
430
|
supportsExplicitPromptCacheMode: Type.TOptional<Type.TBoolean>;
|
|
431
|
+
supportsMidConvoEffort: Type.TOptional<Type.TBoolean>;
|
|
274
432
|
supportsMaxOutputTokens: Type.TOptional<Type.TBoolean>;
|
|
275
433
|
} | {
|
|
276
434
|
supportsEagerToolInputStreaming: Type.TOptional<Type.TBoolean>;
|
|
@@ -315,6 +473,7 @@ export declare const ProviderCompatSchema: Type.TObject<MergedCompatProperties<(
|
|
|
315
473
|
supportsDeveloperRole: Type.TOptional<Type.TBoolean>;
|
|
316
474
|
supportsMidConvoSystemMessages: Type.TOptional<Type.TBoolean>;
|
|
317
475
|
sessionAffinityFormat: Type.TOptional<Type.TUnion<[Type.TLiteral<"openai">, Type.TLiteral<"openai-nosession">, Type.TLiteral<"openrouter">]>>;
|
|
476
|
+
supportsMidConvoEffort: Type.TOptional<Type.TBoolean>;
|
|
318
477
|
supportsLongCacheRetention: Type.TOptional<Type.TBoolean>;
|
|
319
478
|
supportsStrictMode: Type.TOptional<Type.TBoolean>;
|
|
320
479
|
supportsOpenAIGrammarTools: Type.TOptional<Type.TBoolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compat-schema.d.ts","sourceRoot":"","sources":["../../src/providers/compat-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,WAAW,EAAuB,IAAI,EAAE,MAAM,SAAS,CAAC;AAOnF,eAAO,MAAM,2BAA2B,wGAEtC,CAAC;AASH,eAAO,MAAM,8BAA8B,kIAGzC,CAAC;AAEH,eAAO,MAAM,4BAA4B;;;IAavC,CAAC;AAWH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqGnC,CAAC;AAEF,eAAO,MAAM,0BAA0B;;;EAkBtC,CAAC;AAEF,eAAO,MAAM,mCAAmC;;;;;;;;;;;;;;;;EAO/C,CAAC;AAUF,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4KzC,CAAC;AAEF,eAAO,M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OAAO,6BAA6B,CAAC;CAAG;AAChG,wDAAwD;AACxD,MAAM,WAAW,aAAc,SAAQ,MAAM,CAAC,OAAO,mBAAmB,CAAC;CAAG;AAC5E,uDAAuD;AACvD,MAAM,WAAW,0BAA2B,SAAQ,MAAM,CAAC,OAAO,gCAAgC,CAAC;CAAG"}
|
|
@@ -248,6 +248,10 @@ export const OpenAIResponsesCompatSchema = Type.Object({
|
|
|
248
248
|
description: "Whether the model accepts prompt_cache_options. Older OpenAI models reject the parameter.",
|
|
249
249
|
default: false,
|
|
250
250
|
})),
|
|
251
|
+
supportsMidConvoEffort: Type.Optional(Type.Boolean({
|
|
252
|
+
description: "Whether thinking level changes are sent as configuration_update input items instead of changing reasoning.effort, so a change keeps the prompt cache. Only used by the openai-responses API, and ignored with Sign in with ChatGPT on the openai provider.",
|
|
253
|
+
default: false,
|
|
254
|
+
})),
|
|
251
255
|
supportsMaxOutputTokens: Type.Optional(Type.Boolean({
|
|
252
256
|
description: "Whether the provider accepts max_output_tokens. Some Codex-protocol gateways reject it.",
|
|
253
257
|
default: true,
|
|
@@ -348,6 +352,10 @@ const ProviderCompatPropertyOverrides = {
|
|
|
348
352
|
sessionAffinityFormat: optionalSessionAffinityFormat({
|
|
349
353
|
description: "Session-affinity header format. Defaults are API-specific or auto-detected.",
|
|
350
354
|
}),
|
|
355
|
+
supportsMidConvoEffort: optionalCompatBoolean({
|
|
356
|
+
description: "Whether thinking level changes are sent inside the conversation instead of changing the request's effort, so a change keeps the prompt cache. Used by the anthropic-messages and openai-responses APIs.",
|
|
357
|
+
default: false,
|
|
358
|
+
}),
|
|
351
359
|
supportsLongCacheRetention: optionalCompatBoolean({
|
|
352
360
|
description: "Whether the provider supports long prompt cache retention. Defaults are API-specific or auto-detected.",
|
|
353
361
|
}),
|
|
@@ -396,14 +404,16 @@ function mergeCompatProperties(propertyGroups, overrides) {
|
|
|
396
404
|
}
|
|
397
405
|
return { ...merged, ...overrides };
|
|
398
406
|
}
|
|
399
|
-
const CompatSchemasByApi = {
|
|
407
|
+
export const CompatSchemasByApi = {
|
|
400
408
|
"openai-completions": OpenAICompletionsCompatSchema,
|
|
401
409
|
"openai-responses": OpenAIResponsesCompatSchema,
|
|
410
|
+
"azure-openai-responses": OpenAIResponsesCompatSchema,
|
|
411
|
+
"openai-codex-responses": OpenAIResponsesCompatSchema,
|
|
402
412
|
"anthropic-messages": AnthropicMessagesCompatSchema,
|
|
403
413
|
"bedrock-converse-stream": BedrockCompatSchema,
|
|
404
414
|
"mistral-conversations": MistralConversationsCompatSchema,
|
|
405
415
|
};
|
|
406
|
-
const ProviderCompatProperties = mergeCompatProperties(Object.values(CompatSchemasByApi).map((schema) => schema.properties), ProviderCompatPropertyOverrides);
|
|
416
|
+
const ProviderCompatProperties = mergeCompatProperties([...new Set(Object.values(CompatSchemasByApi))].map((schema) => schema.properties), ProviderCompatPropertyOverrides);
|
|
407
417
|
export const ProviderCompatSchema = Type.Object(ProviderCompatProperties, {
|
|
408
418
|
description: "Provider and model compatibility overrides.",
|
|
409
419
|
additionalProperties: true,
|