@code-yeongyu/senpi-ai 2026.9.30 → 2026.10.1
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 +189 -19
- package/dist/api/anthropic-messages.js +168 -32
- package/dist/api/azure-openai-responses.js +23 -10
- package/dist/api/bedrock-converse-stream.js +12 -4
- package/dist/api/cloudflare-workers-ai-system-one.d.ts +4 -0
- package/dist/api/cloudflare-workers-ai-system-one.js +43 -0
- package/dist/api/cloudflare-workers-ai-system-one.lazy.d.ts +3 -0
- package/dist/api/cloudflare-workers-ai-system-one.lazy.js +4 -0
- package/dist/api/cloudflare.d.ts +2 -0
- package/dist/api/cloudflare.js +2 -0
- package/dist/api/context-room.d.ts +2 -2
- package/dist/api/cursor-agent.js +19 -10
- package/dist/api/devin-agent/request.d.ts +9 -9
- package/dist/api/devin-agent/request.js +14 -10
- package/dist/api/google-generative-ai.js +20 -80
- package/dist/api/google-shared.d.ts +13 -4
- package/dist/api/google-shared.js +54 -4
- package/dist/api/google-vertex.js +19 -62
- package/dist/api/llama-cpp-classify.d.ts +33 -0
- package/dist/api/llama-cpp-classify.js +365 -0
- package/dist/api/llama-cpp-classify.lazy.d.ts +3 -0
- package/dist/api/llama-cpp-classify.lazy.js +4 -0
- package/dist/api/mistral-conversations.d.ts +1 -1
- package/dist/api/mistral-conversations.js +36 -29
- package/dist/api/openai-codex-responses.d.ts +1 -1
- package/dist/api/openai-codex-responses.js +72 -37
- package/dist/api/openai-completions.d.ts +3 -2
- package/dist/api/openai-completions.js +76 -50
- package/dist/api/openai-images-params.d.ts +2 -2
- package/dist/api/openai-images.d.ts +1 -1
- package/dist/api/openai-responses-shared.d.ts +31 -8
- package/dist/api/openai-responses-shared.js +115 -27
- package/dist/api/openai-responses.d.ts +1 -1
- package/dist/api/openai-responses.js +38 -33
- package/dist/api/openrouter-images.d.ts +2 -1
- package/dist/api/openrouter-images.js +1 -0
- package/dist/api/pi-messages.d.ts +3 -3
- package/dist/api/pi-messages.js +3 -2
- package/dist/api/simple-options.d.ts +2 -2
- package/dist/api/simple-options.js +1 -0
- package/dist/api/system-one-shared.d.ts +23 -0
- package/dist/api/system-one-shared.js +183 -0
- package/dist/api/transform-messages.js +5 -2
- package/dist/api/typesafe-system-one.d.ts +4 -0
- package/dist/api/typesafe-system-one.js +19 -0
- package/dist/api/typesafe-system-one.lazy.d.ts +3 -0
- package/dist/api/typesafe-system-one.lazy.js +4 -0
- package/dist/api-registry.d.ts +3 -3
- package/dist/auth/helpers.js +1 -1
- package/dist/auth/oauth/anthropic-callback-listener.js +1 -1
- package/dist/auth/oauth/callback-server.d.ts +55 -0
- package/dist/auth/oauth/callback-server.js +146 -0
- package/dist/auth/oauth/chatgpt-subscription.d.ts +1 -1
- package/dist/auth/oauth/chatgpt-subscription.js +20 -124
- package/dist/auth/oauth/devin-callback.js +1 -1
- package/dist/auth/oauth/load.d.ts +4 -0
- package/dist/auth/oauth/load.js +10 -0
- package/dist/auth/oauth/meta.d.ts +17 -0
- package/dist/auth/oauth/meta.js +190 -0
- package/dist/auth/oauth/openai-chatgpt.d.ts +9 -0
- package/dist/auth/oauth/openai-chatgpt.js +266 -0
- package/dist/auth/oauth/openrouter.d.ts +1 -1
- package/dist/auth/oauth/openrouter.js +19 -138
- package/dist/auth/oauth/radius.d.ts +1 -1
- package/dist/auth/oauth/radius.js +21 -89
- package/dist/auth/resolve.d.ts +3 -8
- package/dist/auth/resolve.js +3 -18
- package/dist/auth/types.d.ts +10 -1
- package/dist/bun-oauth.js +4 -0
- package/dist/cli.js +3 -1
- package/dist/compat.js +17 -14
- package/dist/env-api-keys.js +2 -0
- package/dist/image-models.d.ts +19 -8
- package/dist/image-models.js +14 -13
- package/dist/images-api-registry.d.ts +8 -8
- package/dist/images.d.ts +7 -2
- package/dist/images.js +5 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/model-catalog.d.ts +27 -9
- package/dist/model-catalog.js +24 -2
- package/dist/model.d.ts +13 -13
- package/dist/models-store.d.ts +3 -2
- package/dist/models.d.ts +106 -36
- package/dist/models.generated.d.ts +142 -42
- package/dist/models.generated.js +142 -42
- package/dist/models.js +174 -36
- package/dist/providers/alibaba-token-plan.models.d.ts +4 -2
- package/dist/providers/alibaba-token-plan.models.js +4 -2
- package/dist/providers/all.d.ts +72 -19
- package/dist/providers/all.js +28 -22
- package/dist/providers/amazon-bedrock.models.d.ts +4 -2
- package/dist/providers/amazon-bedrock.models.js +4 -2
- package/dist/providers/ant-ling.models.d.ts +4 -2
- package/dist/providers/ant-ling.models.js +4 -2
- package/dist/providers/anthropic.models.d.ts +4 -2
- package/dist/providers/anthropic.models.js +4 -2
- package/dist/providers/azure-openai-responses.models.d.ts +4 -2
- package/dist/providers/azure-openai-responses.models.js +4 -2
- package/dist/providers/bai.models.d.ts +4 -2
- package/dist/providers/bai.models.js +4 -2
- package/dist/providers/baseten.models.d.ts +4 -2
- package/dist/providers/baseten.models.js +4 -2
- package/dist/providers/cerebras.models.d.ts +4 -2
- package/dist/providers/cerebras.models.js +4 -2
- package/dist/providers/chatgpt-subscription.models.d.ts +4 -2
- package/dist/providers/chatgpt-subscription.models.js +4 -2
- package/dist/providers/cloudflare-ai-gateway.models.d.ts +4 -2
- package/dist/providers/cloudflare-ai-gateway.models.js +4 -2
- package/dist/providers/cloudflare-stream.d.ts +6 -2
- package/dist/providers/cloudflare-stream.js +6 -0
- package/dist/providers/cloudflare-workers-ai.js +10 -3
- package/dist/providers/cloudflare-workers-ai.models.d.ts +4 -2
- package/dist/providers/cloudflare-workers-ai.models.js +4 -2
- package/dist/providers/data/.manifest.json +1 -1
- package/dist/providers/data/alibaba-token-plan.json +1 -1
- package/dist/providers/data/amazon-bedrock.json +1 -1
- package/dist/providers/data/ant-ling.json +1 -1
- package/dist/providers/data/anthropic.json +1 -1
- package/dist/providers/data/azure-openai-responses.json +1 -1
- package/dist/providers/data/bai.json +1 -1
- package/dist/providers/data/baseten.json +1 -1
- package/dist/providers/data/cerebras.json +1 -1
- package/dist/providers/data/chatgpt-subscription.json +1 -1
- package/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/dist/providers/data/cloudflare-workers-ai.json +1 -1
- package/dist/providers/data/deepseek.json +1 -1
- package/dist/providers/data/fireworks.json +1 -1
- package/dist/providers/data/github-copilot.json +1 -1
- package/dist/providers/data/google-vertex.json +1 -1
- package/dist/providers/data/google.json +1 -1
- package/dist/providers/data/groq.json +1 -1
- package/dist/providers/data/huggingface.json +1 -1
- package/dist/providers/data/meta.json +1 -0
- package/dist/providers/data/minimax-cn.json +1 -1
- package/dist/providers/data/minimax.json +1 -1
- package/dist/providers/data/mistral.json +1 -1
- package/dist/providers/data/moonshotai-cn.json +1 -1
- package/dist/providers/data/moonshotai.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/opengateway.json +1 -1
- package/dist/providers/data/openrouter.json +1 -1
- package/dist/providers/data/qwen-token-plan-cn.json +1 -1
- package/dist/providers/data/qwen-token-plan-individual.json +1 -1
- package/dist/providers/data/qwen-token-plan.json +1 -1
- package/dist/providers/data/radius.json +1 -0
- package/dist/providers/data/together.json +1 -1
- package/dist/providers/data/typesafe.json +1 -0
- package/dist/providers/data/venice.json +1 -1
- package/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/providers/data/xai.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/data/zai.json +1 -1
- package/dist/providers/deepseek.models.d.ts +4 -2
- package/dist/providers/deepseek.models.js +4 -2
- package/dist/providers/faux.d.ts +7 -2
- package/dist/providers/faux.js +31 -22
- package/dist/providers/fireworks.models.d.ts +4 -2
- package/dist/providers/fireworks.models.js +4 -2
- package/dist/providers/github-copilot.models.d.ts +4 -2
- package/dist/providers/github-copilot.models.js +4 -2
- package/dist/providers/google-vertex.models.d.ts +4 -2
- package/dist/providers/google-vertex.models.js +4 -2
- package/dist/providers/google.models.d.ts +4 -2
- package/dist/providers/google.models.js +4 -2
- package/dist/providers/groq.models.d.ts +4 -2
- package/dist/providers/groq.models.js +4 -2
- package/dist/providers/huggingface.models.d.ts +4 -2
- package/dist/providers/huggingface.models.js +4 -2
- package/dist/providers/images/register-builtins.d.ts +2 -2
- package/dist/providers/kimi-coding.models.d.ts +54 -7
- package/dist/providers/kimi-coding.models.js +34 -7
- package/dist/providers/meta.d.ts +3 -0
- package/dist/providers/meta.js +24 -0
- package/dist/providers/meta.models.d.ts +6 -0
- package/dist/providers/meta.models.js +8 -0
- package/dist/providers/minimax-cn.models.d.ts +4 -2
- package/dist/providers/minimax-cn.models.js +4 -2
- package/dist/providers/minimax.models.d.ts +4 -2
- package/dist/providers/minimax.models.js +4 -2
- package/dist/providers/mistral.models.d.ts +4 -2
- package/dist/providers/mistral.models.js +4 -2
- package/dist/providers/moonshotai-cn.models.d.ts +4 -2
- package/dist/providers/moonshotai-cn.models.js +4 -2
- package/dist/providers/moonshotai.models.d.ts +4 -2
- package/dist/providers/moonshotai.models.js +4 -2
- package/dist/providers/nvidia.models.d.ts +4 -2
- package/dist/providers/nvidia.models.js +4 -2
- package/dist/providers/openai.js +4 -2
- package/dist/providers/openai.models.d.ts +4 -2
- package/dist/providers/openai.models.js +4 -2
- package/dist/providers/opencode-go.models.d.ts +4 -2
- package/dist/providers/opencode-go.models.js +4 -2
- package/dist/providers/opencode.d.ts +3 -1
- package/dist/providers/opencode.js +5 -2
- package/dist/providers/opencode.models.d.ts +4 -2
- package/dist/providers/opencode.models.js +4 -2
- package/dist/providers/opengateway.models.d.ts +4 -2
- package/dist/providers/opengateway.models.js +4 -2
- package/dist/providers/openrouter.js +11 -2
- package/dist/providers/openrouter.models.d.ts +4 -2
- package/dist/providers/openrouter.models.js +4 -2
- package/dist/providers/qwen-token-plan-cn.models.d.ts +4 -2
- package/dist/providers/qwen-token-plan-cn.models.js +4 -2
- package/dist/providers/qwen-token-plan-individual.models.d.ts +4 -2
- package/dist/providers/qwen-token-plan-individual.models.js +4 -2
- package/dist/providers/qwen-token-plan.models.d.ts +4 -2
- package/dist/providers/qwen-token-plan.models.js +4 -2
- package/dist/providers/radius.js +19 -5
- package/dist/providers/radius.models.d.ts +6 -0
- package/dist/providers/radius.models.js +8 -0
- package/dist/providers/together.models.d.ts +4 -2
- package/dist/providers/together.models.js +4 -2
- package/dist/providers/typesafe.d.ts +3 -0
- package/dist/providers/typesafe.js +18 -0
- package/dist/providers/typesafe.models.d.ts +6 -0
- package/dist/providers/typesafe.models.js +8 -0
- package/dist/providers/venice.models.d.ts +4 -2
- package/dist/providers/venice.models.js +4 -2
- package/dist/providers/vercel-ai-gateway.js +5 -2
- package/dist/providers/vercel-ai-gateway.models.d.ts +4 -2
- package/dist/providers/vercel-ai-gateway.models.js +4 -2
- package/dist/providers/xai.models.d.ts +4 -2
- package/dist/providers/xai.models.js +4 -2
- package/dist/providers/xiaomi-token-plan-ams.models.d.ts +4 -2
- package/dist/providers/xiaomi-token-plan-ams.models.js +4 -2
- package/dist/providers/xiaomi-token-plan-cn.models.d.ts +4 -2
- package/dist/providers/xiaomi-token-plan-cn.models.js +4 -2
- package/dist/providers/xiaomi-token-plan-sgp.models.d.ts +4 -2
- package/dist/providers/xiaomi-token-plan-sgp.models.js +4 -2
- package/dist/providers/xiaomi.models.d.ts +4 -2
- package/dist/providers/xiaomi.models.js +4 -2
- package/dist/providers/zai-coding-cn.models.d.ts +4 -2
- package/dist/providers/zai-coding-cn.models.js +4 -2
- package/dist/providers/zai.models.d.ts +4 -2
- package/dist/providers/zai.models.js +4 -2
- package/dist/tool-call-middleware/context-transformer.d.ts +8 -5
- package/dist/tool-call-middleware/context-transformer.js +44 -15
- package/dist/types.d.ts +262 -28
- package/dist/utils/diagnostics.d.ts +3 -2
- package/dist/utils/estimate.d.ts +2 -2
- package/dist/utils/estimate.js +22 -30
- package/dist/utils/headers.d.ts +1 -1
- package/dist/utils/headers.js +10 -8
- package/dist/utils/model-operations.d.ts +11 -0
- package/dist/utils/model-operations.js +47 -0
- package/dist/utils/models-error.d.ts +8 -0
- package/dist/utils/models-error.js +18 -0
- package/dist/utils/overflow.d.ts +1 -0
- package/dist/utils/overflow.js +11 -5
- package/dist/utils/prompt-cache-ttl.js +10 -3
- package/dist/utils/retry.js +9 -0
- package/dist/utils/text.d.ts +9 -1
- package/dist/utils/text.js +26 -0
- package/dist/utils/transcript.d.ts +85 -0
- package/dist/utils/transcript.js +205 -0
- package/package.json +3 -4
- package/dist/image-models.generated.d.ts +0 -925
- package/dist/image-models.generated.js +0 -927
- package/dist/images-models.d.ts +0 -95
- package/dist/images-models.js +0 -141
- package/dist/providers/openai-images.d.ts +0 -3
- package/dist/providers/openai-images.js +0 -16
- package/dist/providers/openrouter-images.d.ts +0 -3
- package/dist/providers/openrouter-images.js +0 -22
- /package/dist/{auth/oauth → utils}/oauth-page.d.ts +0 -0
- /package/dist/{auth/oauth → utils}/oauth-page.js +0 -0
package/dist/providers/radius.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { piMessagesApi } from "../api/pi-messages.lazy.js";
|
|
2
2
|
import { envApiKeyAuth, lazyOAuth } from "../auth/helpers.js";
|
|
3
3
|
import { loadRadiusOAuth } from "../auth/oauth/load.js";
|
|
4
|
+
import { RADIUS_MODELS } from "./radius.models.js";
|
|
4
5
|
import { DEFAULT_RADIUS_GATEWAY, getRadiusModels, getRadiusModelsFromConfig, loadRadiusGatewayConfig, normalizeRadiusGatewayUrl, } from "./radius-config.js";
|
|
5
6
|
/** Radius gateway provider with a persisted, dynamically refreshed catalog. */
|
|
6
7
|
export function radiusProvider(options = {}) {
|
|
7
8
|
const id = options.id ?? "radius";
|
|
8
9
|
const name = options.name ?? "Radius";
|
|
9
10
|
const gateway = normalizeRadiusGatewayUrl(options.gateway ?? DEFAULT_RADIUS_GATEWAY);
|
|
10
|
-
|
|
11
|
+
const baselineModels = gateway === normalizeRadiusGatewayUrl(DEFAULT_RADIUS_GATEWAY)
|
|
12
|
+
? Object.values(RADIUS_MODELS).map((model) => ({ ...model, provider: id }))
|
|
13
|
+
: [];
|
|
14
|
+
let dynamicModels = getRadiusModels(id, undefined);
|
|
11
15
|
const streams = piMessagesApi();
|
|
12
16
|
return {
|
|
13
17
|
id,
|
|
@@ -16,14 +20,24 @@ export function radiusProvider(options = {}) {
|
|
|
16
20
|
apiKey: envApiKeyAuth("Radius API key", ["RADIUS_API_KEY"]),
|
|
17
21
|
oauth: lazyOAuth({ name, load: () => loadRadiusOAuth({ name, gateway }) }),
|
|
18
22
|
},
|
|
19
|
-
getModels: () =>
|
|
23
|
+
getModels: () => {
|
|
24
|
+
const merged = [...baselineModels];
|
|
25
|
+
for (const model of dynamicModels) {
|
|
26
|
+
const index = merged.findIndex((entry) => entry.id === model.id);
|
|
27
|
+
if (index >= 0)
|
|
28
|
+
merged[index] = model;
|
|
29
|
+
else
|
|
30
|
+
merged.push(model);
|
|
31
|
+
}
|
|
32
|
+
return merged;
|
|
33
|
+
},
|
|
20
34
|
refreshModels: async (context) => {
|
|
21
35
|
const stored = context.stored;
|
|
22
36
|
if (stored) {
|
|
23
37
|
const restored = stored.models.filter((model) => model.provider === id);
|
|
24
38
|
if (!(await context.publish({
|
|
25
39
|
update: () => {
|
|
26
|
-
|
|
40
|
+
dynamicModels = restored;
|
|
27
41
|
},
|
|
28
42
|
}))) {
|
|
29
43
|
return;
|
|
@@ -36,7 +50,7 @@ export function radiusProvider(options = {}) {
|
|
|
36
50
|
if (!(await context.publish({
|
|
37
51
|
persist: { models: legacy, checkedAt: Date.now() },
|
|
38
52
|
update: () => {
|
|
39
|
-
|
|
53
|
+
dynamicModels = legacy;
|
|
40
54
|
},
|
|
41
55
|
}))) {
|
|
42
56
|
return;
|
|
@@ -53,7 +67,7 @@ export function radiusProvider(options = {}) {
|
|
|
53
67
|
await context.publish({
|
|
54
68
|
persist: { models: refreshed, checkedAt: Date.now() },
|
|
55
69
|
update: () => {
|
|
56
|
-
|
|
70
|
+
dynamicModels = refreshed;
|
|
57
71
|
},
|
|
58
72
|
});
|
|
59
73
|
},
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import values from "./data/radius.json";
|
|
2
|
+
import { type ChatModelCatalog, type ClassifierModelCatalog, type ImageModelCatalog } from "../model-catalog.ts";
|
|
3
|
+
export declare const RADIUS_MODELS: ChatModelCatalog<typeof values, "radius">;
|
|
4
|
+
export declare const RADIUS_IMAGE_MODELS: ImageModelCatalog<typeof values, "radius">;
|
|
5
|
+
export declare const RADIUS_CLASSIFIER_MODELS: ClassifierModelCatalog<typeof values, "radius">;
|
|
6
|
+
//# sourceMappingURL=radius.models.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// This file is auto-generated by scripts/generate-models.ts
|
|
2
|
+
// Do not edit manually - run 'npm run generate-models' to update
|
|
3
|
+
import values from "./data/radius.json" with { type: "json" };
|
|
4
|
+
import { flattenChatModelCatalog, flattenClassifierModelCatalog, flattenImageModelCatalog } from "../model-catalog.js";
|
|
5
|
+
export const RADIUS_MODELS = flattenChatModelCatalog("radius", values);
|
|
6
|
+
export const RADIUS_IMAGE_MODELS = flattenImageModelCatalog("radius", values);
|
|
7
|
+
export const RADIUS_CLASSIFIER_MODELS = flattenClassifierModelCatalog("radius", values);
|
|
8
|
+
//# sourceMappingURL=radius.models.js.map
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import values from "./data/together.json";
|
|
2
|
-
import { type
|
|
3
|
-
export declare const TOGETHER_MODELS:
|
|
2
|
+
import { type ChatModelCatalog, type ClassifierModelCatalog, type ImageModelCatalog } from "../model-catalog.ts";
|
|
3
|
+
export declare const TOGETHER_MODELS: ChatModelCatalog<typeof values, "together">;
|
|
4
|
+
export declare const TOGETHER_IMAGE_MODELS: ImageModelCatalog<typeof values, "together">;
|
|
5
|
+
export declare const TOGETHER_CLASSIFIER_MODELS: ClassifierModelCatalog<typeof values, "together">;
|
|
4
6
|
//# sourceMappingURL=together.models.d.ts.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// This file is auto-generated by scripts/generate-models.ts
|
|
2
2
|
// Do not edit manually - run 'npm run generate-models' to update
|
|
3
3
|
import values from "./data/together.json" with { type: "json" };
|
|
4
|
-
import {
|
|
5
|
-
export const TOGETHER_MODELS =
|
|
4
|
+
import { flattenChatModelCatalog, flattenClassifierModelCatalog, flattenImageModelCatalog } from "../model-catalog.js";
|
|
5
|
+
export const TOGETHER_MODELS = flattenChatModelCatalog("together", values);
|
|
6
|
+
export const TOGETHER_IMAGE_MODELS = flattenImageModelCatalog("together", values);
|
|
7
|
+
export const TOGETHER_CLASSIFIER_MODELS = flattenClassifierModelCatalog("together", values);
|
|
6
8
|
//# sourceMappingURL=together.models.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { typesafeSystemOneApi } from "../api/typesafe-system-one.lazy.js";
|
|
2
|
+
import { envApiKeyAuth } from "../auth/helpers.js";
|
|
3
|
+
import { createProvider } from "../models.js";
|
|
4
|
+
import { TYPESAFE_CLASSIFIER_MODELS } from "./typesafe.models.js";
|
|
5
|
+
export function typesafeProvider() {
|
|
6
|
+
return createProvider({
|
|
7
|
+
id: "typesafe",
|
|
8
|
+
name: "TypeSafe",
|
|
9
|
+
auth: {
|
|
10
|
+
apiKey: envApiKeyAuth("TypeSafe API key", ["TYPESAFE_API_KEY"]),
|
|
11
|
+
},
|
|
12
|
+
models: Object.values(TYPESAFE_CLASSIFIER_MODELS),
|
|
13
|
+
classifiers: {
|
|
14
|
+
"typesafe-system-one": typesafeSystemOneApi(),
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=typesafe.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import values from "./data/typesafe.json";
|
|
2
|
+
import { type ChatModelCatalog, type ClassifierModelCatalog, type ImageModelCatalog } from "../model-catalog.ts";
|
|
3
|
+
export declare const TYPESAFE_MODELS: ChatModelCatalog<typeof values, "typesafe">;
|
|
4
|
+
export declare const TYPESAFE_IMAGE_MODELS: ImageModelCatalog<typeof values, "typesafe">;
|
|
5
|
+
export declare const TYPESAFE_CLASSIFIER_MODELS: ClassifierModelCatalog<typeof values, "typesafe">;
|
|
6
|
+
//# sourceMappingURL=typesafe.models.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// This file is auto-generated by scripts/generate-models.ts
|
|
2
|
+
// Do not edit manually - run 'npm run generate-models' to update
|
|
3
|
+
import values from "./data/typesafe.json" with { type: "json" };
|
|
4
|
+
import { flattenChatModelCatalog, flattenClassifierModelCatalog, flattenImageModelCatalog } from "../model-catalog.js";
|
|
5
|
+
export const TYPESAFE_MODELS = flattenChatModelCatalog("typesafe", values);
|
|
6
|
+
export const TYPESAFE_IMAGE_MODELS = flattenImageModelCatalog("typesafe", values);
|
|
7
|
+
export const TYPESAFE_CLASSIFIER_MODELS = flattenClassifierModelCatalog("typesafe", values);
|
|
8
|
+
//# sourceMappingURL=typesafe.models.js.map
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import values from "./data/venice.json";
|
|
2
|
-
import { type
|
|
3
|
-
export declare const VENICE_MODELS:
|
|
2
|
+
import { type ChatModelCatalog, type ClassifierModelCatalog, type ImageModelCatalog } from "../model-catalog.ts";
|
|
3
|
+
export declare const VENICE_MODELS: ChatModelCatalog<typeof values, "venice">;
|
|
4
|
+
export declare const VENICE_IMAGE_MODELS: ImageModelCatalog<typeof values, "venice">;
|
|
5
|
+
export declare const VENICE_CLASSIFIER_MODELS: ClassifierModelCatalog<typeof values, "venice">;
|
|
4
6
|
//# sourceMappingURL=venice.models.d.ts.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// This file is auto-generated by scripts/generate-models.ts
|
|
2
2
|
// Do not edit manually - run 'npm run generate-models' to update
|
|
3
3
|
import values from "./data/venice.json" with { type: "json" };
|
|
4
|
-
import {
|
|
5
|
-
export const VENICE_MODELS =
|
|
4
|
+
import { flattenChatModelCatalog, flattenClassifierModelCatalog, flattenImageModelCatalog } from "../model-catalog.js";
|
|
5
|
+
export const VENICE_MODELS = flattenChatModelCatalog("venice", values);
|
|
6
|
+
export const VENICE_IMAGE_MODELS = flattenImageModelCatalog("venice", values);
|
|
7
|
+
export const VENICE_CLASSIFIER_MODELS = flattenClassifierModelCatalog("venice", values);
|
|
6
8
|
//# sourceMappingURL=venice.models.js.map
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { anthropicMessagesApi } from "../api/anthropic-messages.lazy.js";
|
|
2
|
+
import { typesafeSystemOneApi } from "../api/typesafe-system-one.lazy.js";
|
|
2
3
|
import { envApiKeyAuth } from "../auth/helpers.js";
|
|
3
4
|
import { createProvider } from "../models.js";
|
|
4
|
-
import { VERCEL_AI_GATEWAY_MODELS } from "./vercel-ai-gateway.models.js";
|
|
5
|
+
import { VERCEL_AI_GATEWAY_CLASSIFIER_MODELS, VERCEL_AI_GATEWAY_MODELS } from "./vercel-ai-gateway.models.js";
|
|
5
6
|
export function vercelAIGatewayProvider() {
|
|
6
7
|
return createProvider({
|
|
7
8
|
id: "vercel-ai-gateway",
|
|
8
9
|
name: "Vercel AI Gateway",
|
|
9
10
|
baseUrl: "https://ai-gateway.vercel.sh",
|
|
10
11
|
auth: { apiKey: envApiKeyAuth("Vercel AI Gateway API key", ["AI_GATEWAY_API_KEY"]) },
|
|
11
|
-
models: Object.values(VERCEL_AI_GATEWAY_MODELS),
|
|
12
|
+
models: [...Object.values(VERCEL_AI_GATEWAY_MODELS), ...Object.values(VERCEL_AI_GATEWAY_CLASSIFIER_MODELS)],
|
|
12
13
|
api: anthropicMessagesApi(),
|
|
14
|
+
// AI Gateway serves TypeSafe's System One protocol at /typesafe/v1/systemone.
|
|
15
|
+
classifiers: { "typesafe-system-one": typesafeSystemOneApi() },
|
|
13
16
|
});
|
|
14
17
|
}
|
|
15
18
|
//# sourceMappingURL=vercel-ai-gateway.js.map
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import values from "./data/vercel-ai-gateway.json";
|
|
2
|
-
import { type
|
|
3
|
-
export declare const VERCEL_AI_GATEWAY_MODELS:
|
|
2
|
+
import { type ChatModelCatalog, type ClassifierModelCatalog, type ImageModelCatalog } from "../model-catalog.ts";
|
|
3
|
+
export declare const VERCEL_AI_GATEWAY_MODELS: ChatModelCatalog<typeof values, "vercel-ai-gateway">;
|
|
4
|
+
export declare const VERCEL_AI_GATEWAY_IMAGE_MODELS: ImageModelCatalog<typeof values, "vercel-ai-gateway">;
|
|
5
|
+
export declare const VERCEL_AI_GATEWAY_CLASSIFIER_MODELS: ClassifierModelCatalog<typeof values, "vercel-ai-gateway">;
|
|
4
6
|
//# sourceMappingURL=vercel-ai-gateway.models.d.ts.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// This file is auto-generated by scripts/generate-models.ts
|
|
2
2
|
// Do not edit manually - run 'npm run generate-models' to update
|
|
3
3
|
import values from "./data/vercel-ai-gateway.json" with { type: "json" };
|
|
4
|
-
import {
|
|
5
|
-
export const VERCEL_AI_GATEWAY_MODELS =
|
|
4
|
+
import { flattenChatModelCatalog, flattenClassifierModelCatalog, flattenImageModelCatalog } from "../model-catalog.js";
|
|
5
|
+
export const VERCEL_AI_GATEWAY_MODELS = flattenChatModelCatalog("vercel-ai-gateway", values);
|
|
6
|
+
export const VERCEL_AI_GATEWAY_IMAGE_MODELS = flattenImageModelCatalog("vercel-ai-gateway", values);
|
|
7
|
+
export const VERCEL_AI_GATEWAY_CLASSIFIER_MODELS = flattenClassifierModelCatalog("vercel-ai-gateway", values);
|
|
6
8
|
//# sourceMappingURL=vercel-ai-gateway.models.js.map
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import values from "./data/xai.json";
|
|
2
|
-
import { type
|
|
3
|
-
export declare const XAI_MODELS:
|
|
2
|
+
import { type ChatModelCatalog, type ClassifierModelCatalog, type ImageModelCatalog } from "../model-catalog.ts";
|
|
3
|
+
export declare const XAI_MODELS: ChatModelCatalog<typeof values, "xai">;
|
|
4
|
+
export declare const XAI_IMAGE_MODELS: ImageModelCatalog<typeof values, "xai">;
|
|
5
|
+
export declare const XAI_CLASSIFIER_MODELS: ClassifierModelCatalog<typeof values, "xai">;
|
|
4
6
|
//# sourceMappingURL=xai.models.d.ts.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// This file is auto-generated by scripts/generate-models.ts
|
|
2
2
|
// Do not edit manually - run 'npm run generate-models' to update
|
|
3
3
|
import values from "./data/xai.json" with { type: "json" };
|
|
4
|
-
import {
|
|
5
|
-
export const XAI_MODELS =
|
|
4
|
+
import { flattenChatModelCatalog, flattenClassifierModelCatalog, flattenImageModelCatalog } from "../model-catalog.js";
|
|
5
|
+
export const XAI_MODELS = flattenChatModelCatalog("xai", values);
|
|
6
|
+
export const XAI_IMAGE_MODELS = flattenImageModelCatalog("xai", values);
|
|
7
|
+
export const XAI_CLASSIFIER_MODELS = flattenClassifierModelCatalog("xai", values);
|
|
6
8
|
//# sourceMappingURL=xai.models.js.map
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import values from "./data/xiaomi-token-plan-ams.json";
|
|
2
|
-
import { type
|
|
3
|
-
export declare const XIAOMI_TOKEN_PLAN_AMS_MODELS:
|
|
2
|
+
import { type ChatModelCatalog, type ClassifierModelCatalog, type ImageModelCatalog } from "../model-catalog.ts";
|
|
3
|
+
export declare const XIAOMI_TOKEN_PLAN_AMS_MODELS: ChatModelCatalog<typeof values, "xiaomi-token-plan-ams">;
|
|
4
|
+
export declare const XIAOMI_TOKEN_PLAN_AMS_IMAGE_MODELS: ImageModelCatalog<typeof values, "xiaomi-token-plan-ams">;
|
|
5
|
+
export declare const XIAOMI_TOKEN_PLAN_AMS_CLASSIFIER_MODELS: ClassifierModelCatalog<typeof values, "xiaomi-token-plan-ams">;
|
|
4
6
|
//# sourceMappingURL=xiaomi-token-plan-ams.models.d.ts.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// This file is auto-generated by scripts/generate-models.ts
|
|
2
2
|
// Do not edit manually - run 'npm run generate-models' to update
|
|
3
3
|
import values from "./data/xiaomi-token-plan-ams.json" with { type: "json" };
|
|
4
|
-
import {
|
|
5
|
-
export const XIAOMI_TOKEN_PLAN_AMS_MODELS =
|
|
4
|
+
import { flattenChatModelCatalog, flattenClassifierModelCatalog, flattenImageModelCatalog } from "../model-catalog.js";
|
|
5
|
+
export const XIAOMI_TOKEN_PLAN_AMS_MODELS = flattenChatModelCatalog("xiaomi-token-plan-ams", values);
|
|
6
|
+
export const XIAOMI_TOKEN_PLAN_AMS_IMAGE_MODELS = flattenImageModelCatalog("xiaomi-token-plan-ams", values);
|
|
7
|
+
export const XIAOMI_TOKEN_PLAN_AMS_CLASSIFIER_MODELS = flattenClassifierModelCatalog("xiaomi-token-plan-ams", values);
|
|
6
8
|
//# sourceMappingURL=xiaomi-token-plan-ams.models.js.map
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import values from "./data/xiaomi-token-plan-cn.json";
|
|
2
|
-
import { type
|
|
3
|
-
export declare const XIAOMI_TOKEN_PLAN_CN_MODELS:
|
|
2
|
+
import { type ChatModelCatalog, type ClassifierModelCatalog, type ImageModelCatalog } from "../model-catalog.ts";
|
|
3
|
+
export declare const XIAOMI_TOKEN_PLAN_CN_MODELS: ChatModelCatalog<typeof values, "xiaomi-token-plan-cn">;
|
|
4
|
+
export declare const XIAOMI_TOKEN_PLAN_CN_IMAGE_MODELS: ImageModelCatalog<typeof values, "xiaomi-token-plan-cn">;
|
|
5
|
+
export declare const XIAOMI_TOKEN_PLAN_CN_CLASSIFIER_MODELS: ClassifierModelCatalog<typeof values, "xiaomi-token-plan-cn">;
|
|
4
6
|
//# sourceMappingURL=xiaomi-token-plan-cn.models.d.ts.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// This file is auto-generated by scripts/generate-models.ts
|
|
2
2
|
// Do not edit manually - run 'npm run generate-models' to update
|
|
3
3
|
import values from "./data/xiaomi-token-plan-cn.json" with { type: "json" };
|
|
4
|
-
import {
|
|
5
|
-
export const XIAOMI_TOKEN_PLAN_CN_MODELS =
|
|
4
|
+
import { flattenChatModelCatalog, flattenClassifierModelCatalog, flattenImageModelCatalog } from "../model-catalog.js";
|
|
5
|
+
export const XIAOMI_TOKEN_PLAN_CN_MODELS = flattenChatModelCatalog("xiaomi-token-plan-cn", values);
|
|
6
|
+
export const XIAOMI_TOKEN_PLAN_CN_IMAGE_MODELS = flattenImageModelCatalog("xiaomi-token-plan-cn", values);
|
|
7
|
+
export const XIAOMI_TOKEN_PLAN_CN_CLASSIFIER_MODELS = flattenClassifierModelCatalog("xiaomi-token-plan-cn", values);
|
|
6
8
|
//# sourceMappingURL=xiaomi-token-plan-cn.models.js.map
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import values from "./data/xiaomi-token-plan-sgp.json";
|
|
2
|
-
import { type
|
|
3
|
-
export declare const XIAOMI_TOKEN_PLAN_SGP_MODELS:
|
|
2
|
+
import { type ChatModelCatalog, type ClassifierModelCatalog, type ImageModelCatalog } from "../model-catalog.ts";
|
|
3
|
+
export declare const XIAOMI_TOKEN_PLAN_SGP_MODELS: ChatModelCatalog<typeof values, "xiaomi-token-plan-sgp">;
|
|
4
|
+
export declare const XIAOMI_TOKEN_PLAN_SGP_IMAGE_MODELS: ImageModelCatalog<typeof values, "xiaomi-token-plan-sgp">;
|
|
5
|
+
export declare const XIAOMI_TOKEN_PLAN_SGP_CLASSIFIER_MODELS: ClassifierModelCatalog<typeof values, "xiaomi-token-plan-sgp">;
|
|
4
6
|
//# sourceMappingURL=xiaomi-token-plan-sgp.models.d.ts.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// This file is auto-generated by scripts/generate-models.ts
|
|
2
2
|
// Do not edit manually - run 'npm run generate-models' to update
|
|
3
3
|
import values from "./data/xiaomi-token-plan-sgp.json" with { type: "json" };
|
|
4
|
-
import {
|
|
5
|
-
export const XIAOMI_TOKEN_PLAN_SGP_MODELS =
|
|
4
|
+
import { flattenChatModelCatalog, flattenClassifierModelCatalog, flattenImageModelCatalog } from "../model-catalog.js";
|
|
5
|
+
export const XIAOMI_TOKEN_PLAN_SGP_MODELS = flattenChatModelCatalog("xiaomi-token-plan-sgp", values);
|
|
6
|
+
export const XIAOMI_TOKEN_PLAN_SGP_IMAGE_MODELS = flattenImageModelCatalog("xiaomi-token-plan-sgp", values);
|
|
7
|
+
export const XIAOMI_TOKEN_PLAN_SGP_CLASSIFIER_MODELS = flattenClassifierModelCatalog("xiaomi-token-plan-sgp", values);
|
|
6
8
|
//# sourceMappingURL=xiaomi-token-plan-sgp.models.js.map
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import values from "./data/xiaomi.json";
|
|
2
|
-
import { type
|
|
3
|
-
export declare const XIAOMI_MODELS:
|
|
2
|
+
import { type ChatModelCatalog, type ClassifierModelCatalog, type ImageModelCatalog } from "../model-catalog.ts";
|
|
3
|
+
export declare const XIAOMI_MODELS: ChatModelCatalog<typeof values, "xiaomi">;
|
|
4
|
+
export declare const XIAOMI_IMAGE_MODELS: ImageModelCatalog<typeof values, "xiaomi">;
|
|
5
|
+
export declare const XIAOMI_CLASSIFIER_MODELS: ClassifierModelCatalog<typeof values, "xiaomi">;
|
|
4
6
|
//# sourceMappingURL=xiaomi.models.d.ts.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// This file is auto-generated by scripts/generate-models.ts
|
|
2
2
|
// Do not edit manually - run 'npm run generate-models' to update
|
|
3
3
|
import values from "./data/xiaomi.json" with { type: "json" };
|
|
4
|
-
import {
|
|
5
|
-
export const XIAOMI_MODELS =
|
|
4
|
+
import { flattenChatModelCatalog, flattenClassifierModelCatalog, flattenImageModelCatalog } from "../model-catalog.js";
|
|
5
|
+
export const XIAOMI_MODELS = flattenChatModelCatalog("xiaomi", values);
|
|
6
|
+
export const XIAOMI_IMAGE_MODELS = flattenImageModelCatalog("xiaomi", values);
|
|
7
|
+
export const XIAOMI_CLASSIFIER_MODELS = flattenClassifierModelCatalog("xiaomi", values);
|
|
6
8
|
//# sourceMappingURL=xiaomi.models.js.map
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import values from "./data/zai-coding-cn.json";
|
|
2
|
-
import { type
|
|
3
|
-
export declare const ZAI_CODING_CN_MODELS:
|
|
2
|
+
import { type ChatModelCatalog, type ClassifierModelCatalog, type ImageModelCatalog } from "../model-catalog.ts";
|
|
3
|
+
export declare const ZAI_CODING_CN_MODELS: ChatModelCatalog<typeof values, "zai-coding-cn">;
|
|
4
|
+
export declare const ZAI_CODING_CN_IMAGE_MODELS: ImageModelCatalog<typeof values, "zai-coding-cn">;
|
|
5
|
+
export declare const ZAI_CODING_CN_CLASSIFIER_MODELS: ClassifierModelCatalog<typeof values, "zai-coding-cn">;
|
|
4
6
|
//# sourceMappingURL=zai-coding-cn.models.d.ts.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// This file is auto-generated by scripts/generate-models.ts
|
|
2
2
|
// Do not edit manually - run 'npm run generate-models' to update
|
|
3
3
|
import values from "./data/zai-coding-cn.json" with { type: "json" };
|
|
4
|
-
import {
|
|
5
|
-
export const ZAI_CODING_CN_MODELS =
|
|
4
|
+
import { flattenChatModelCatalog, flattenClassifierModelCatalog, flattenImageModelCatalog } from "../model-catalog.js";
|
|
5
|
+
export const ZAI_CODING_CN_MODELS = flattenChatModelCatalog("zai-coding-cn", values);
|
|
6
|
+
export const ZAI_CODING_CN_IMAGE_MODELS = flattenImageModelCatalog("zai-coding-cn", values);
|
|
7
|
+
export const ZAI_CODING_CN_CLASSIFIER_MODELS = flattenClassifierModelCatalog("zai-coding-cn", values);
|
|
6
8
|
//# sourceMappingURL=zai-coding-cn.models.js.map
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import values from "./data/zai.json";
|
|
2
|
-
import { type
|
|
3
|
-
export declare const ZAI_MODELS:
|
|
2
|
+
import { type ChatModelCatalog, type ClassifierModelCatalog, type ImageModelCatalog } from "../model-catalog.ts";
|
|
3
|
+
export declare const ZAI_MODELS: ChatModelCatalog<typeof values, "zai">;
|
|
4
|
+
export declare const ZAI_IMAGE_MODELS: ImageModelCatalog<typeof values, "zai">;
|
|
5
|
+
export declare const ZAI_CLASSIFIER_MODELS: ClassifierModelCatalog<typeof values, "zai">;
|
|
4
6
|
//# sourceMappingURL=zai.models.d.ts.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// This file is auto-generated by scripts/generate-models.ts
|
|
2
2
|
// Do not edit manually - run 'npm run generate-models' to update
|
|
3
3
|
import values from "./data/zai.json" with { type: "json" };
|
|
4
|
-
import {
|
|
5
|
-
export const ZAI_MODELS =
|
|
4
|
+
import { flattenChatModelCatalog, flattenClassifierModelCatalog, flattenImageModelCatalog } from "../model-catalog.js";
|
|
5
|
+
export const ZAI_MODELS = flattenChatModelCatalog("zai", values);
|
|
6
|
+
export const ZAI_IMAGE_MODELS = flattenImageModelCatalog("zai", values);
|
|
7
|
+
export const ZAI_CLASSIFIER_MODELS = flattenClassifierModelCatalog("zai", values);
|
|
6
8
|
//# sourceMappingURL=zai.models.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Context } from "../types.ts";
|
|
1
|
+
import type { Context, TranscriptContext } from "../types.ts";
|
|
2
2
|
import type { ToolCallFormat, ToolCallProtocol } from "./types.ts";
|
|
3
3
|
/**
|
|
4
4
|
* Gets the protocol implementation for a given tool call format.
|
|
@@ -9,14 +9,17 @@ import type { ToolCallFormat, ToolCallProtocol } from "./types.ts";
|
|
|
9
9
|
export declare function getProtocol(format: ToolCallFormat): ToolCallProtocol;
|
|
10
10
|
/**
|
|
11
11
|
* Transforms a context for text-based tool calling.
|
|
12
|
-
* - Strips
|
|
13
|
-
* - Injects tool definitions into system prompt
|
|
12
|
+
* - Strips tool declarations from every system message (provider sees a tool-free request)
|
|
13
|
+
* - Injects the current tool definitions into the leading system prompt
|
|
14
14
|
* - Converts tool call messages in history to text format
|
|
15
15
|
* - Converts tool result messages to user messages with text content
|
|
16
16
|
*
|
|
17
|
+
* Accepts a raw `Context` or a normalized `TranscriptContext`; both are read through
|
|
18
|
+
* the transcript, so the prompt and tools come from its system messages.
|
|
19
|
+
*
|
|
17
20
|
* @param context - The original context
|
|
18
21
|
* @param protocol - The protocol to use for formatting
|
|
19
|
-
* @returns A new transformed
|
|
22
|
+
* @returns A new transformed transcript (original is not mutated)
|
|
20
23
|
*/
|
|
21
|
-
export declare function transformContext(context: Context, protocol: ToolCallProtocol):
|
|
24
|
+
export declare function transformContext(context: Context, protocol: ToolCallProtocol): TranscriptContext;
|
|
22
25
|
//# sourceMappingURL=context-transformer.d.ts.map
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { contentText } from "../utils/text.js";
|
|
2
|
+
import { getCurrentTools, getInitialSystemMessage, normalizeContext } from "../utils/transcript.js";
|
|
1
3
|
import { anthropicXmlFormatToolCall, anthropicXmlFormatToolResponse, anthropicXmlFormatToolsSystemPrompt, createAnthropicXmlStreamParser, parseAnthropicXmlGeneratedText, } from "./protocols/anthropic-xml/index.js";
|
|
2
4
|
import { antmlFormatToolCall, antmlFormatToolResponse, antmlFormatToolsSystemPrompt, createAntmlStreamParser, parseAntmlGeneratedText, } from "./protocols/antml/index.js";
|
|
3
5
|
import { gemma4CreateStreamParser, gemma4FormatToolCall, gemma4FormatToolResponse, gemma4FormatToolsSystemPrompt, gemma4ParseGeneratedText, } from "./protocols/gemma4.js";
|
|
@@ -91,30 +93,57 @@ export function getProtocol(format) {
|
|
|
91
93
|
}
|
|
92
94
|
/**
|
|
93
95
|
* Transforms a context for text-based tool calling.
|
|
94
|
-
* - Strips
|
|
95
|
-
* - Injects tool definitions into system prompt
|
|
96
|
+
* - Strips tool declarations from every system message (provider sees a tool-free request)
|
|
97
|
+
* - Injects the current tool definitions into the leading system prompt
|
|
96
98
|
* - Converts tool call messages in history to text format
|
|
97
99
|
* - Converts tool result messages to user messages with text content
|
|
98
100
|
*
|
|
101
|
+
* Accepts a raw `Context` or a normalized `TranscriptContext`; both are read through
|
|
102
|
+
* the transcript, so the prompt and tools come from its system messages.
|
|
103
|
+
*
|
|
99
104
|
* @param context - The original context
|
|
100
105
|
* @param protocol - The protocol to use for formatting
|
|
101
|
-
* @returns A new transformed
|
|
106
|
+
* @returns A new transformed transcript (original is not mutated)
|
|
102
107
|
*/
|
|
103
108
|
export function transformContext(context, protocol) {
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
// Inject tool definitions into system prompt if tools exist
|
|
111
|
-
if (
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
109
|
+
const transcript = normalizeContext(context);
|
|
110
|
+
const tools = getCurrentTools(transcript.messages);
|
|
111
|
+
const toolPrompt = tools.length > 0 ? protocol.formatToolsSystemPrompt(tools) : "";
|
|
112
|
+
const initial = getInitialSystemMessage(transcript.messages);
|
|
113
|
+
const head = initial ? withoutToolDeclarations(initial) : undefined;
|
|
114
|
+
const messages = [];
|
|
115
|
+
// Inject tool definitions into the leading system prompt if tools exist
|
|
116
|
+
if (toolPrompt) {
|
|
117
|
+
const leading = head ?? { role: "system", content: "", timestamp: 0 };
|
|
118
|
+
const basePrompt = contentText(leading.content);
|
|
119
|
+
messages.push({ ...leading, content: basePrompt ? `${toolPrompt}\n\n${basePrompt}` : toolPrompt });
|
|
120
|
+
}
|
|
121
|
+
else if (head && hasSystemContent(head)) {
|
|
122
|
+
messages.push(head);
|
|
123
|
+
}
|
|
124
|
+
for (const message of initial ? transcript.messages.slice(1) : transcript.messages) {
|
|
125
|
+
if (message.role === "system") {
|
|
126
|
+
const stripped = withoutToolDeclarations(message);
|
|
127
|
+
if (hasSystemContent(stripped))
|
|
128
|
+
messages.push(stripped);
|
|
129
|
+
continue;
|
|
115
130
|
}
|
|
131
|
+
messages.push(transformMessage(message, protocol));
|
|
116
132
|
}
|
|
117
|
-
return
|
|
133
|
+
return { messages };
|
|
134
|
+
}
|
|
135
|
+
/** Copy a system message without its tool deltas; text-protocol requests declare no native tools. */
|
|
136
|
+
function withoutToolDeclarations(message) {
|
|
137
|
+
return {
|
|
138
|
+
role: "system",
|
|
139
|
+
content: message.content,
|
|
140
|
+
...(message.sections ? { sections: message.sections } : {}),
|
|
141
|
+
timestamp: message.timestamp,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/** Whether a system message still carries prompt text or sections once its tool deltas are gone. */
|
|
145
|
+
function hasSystemContent(message) {
|
|
146
|
+
return contentText(message.content).length > 0 || Object.keys(message.sections ?? {}).length > 0;
|
|
118
147
|
}
|
|
119
148
|
/**
|
|
120
149
|
* Transforms a single message for text-based tool calling.
|