@ashx-j/lunr-ai 0.2.27 → 0.2.28
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/dist/api/anthropic-claude-code-bridge.d.ts.map +1 -1
- package/dist/api/anthropic-claude-code-bridge.js +21 -3
- package/dist/api/anthropic-claude-code-bridge.js.map +1 -1
- package/dist/api/anthropic-messages.d.ts.map +1 -1
- package/dist/api/anthropic-messages.js +3 -0
- package/dist/api/anthropic-messages.js.map +1 -1
- package/dist/api/azure-openai-responses.d.ts.map +1 -1
- package/dist/api/azure-openai-responses.js +1 -0
- package/dist/api/azure-openai-responses.js.map +1 -1
- package/dist/api/bedrock-converse-stream.d.ts.map +1 -1
- package/dist/api/bedrock-converse-stream.js +8 -1
- package/dist/api/bedrock-converse-stream.js.map +1 -1
- package/dist/api/google-generative-ai.d.ts.map +1 -1
- package/dist/api/google-generative-ai.js +7 -2
- package/dist/api/google-generative-ai.js.map +1 -1
- package/dist/api/google-vertex.d.ts.map +1 -1
- package/dist/api/google-vertex.js +7 -2
- package/dist/api/google-vertex.js.map +1 -1
- package/dist/api/lazy.d.ts.map +1 -1
- package/dist/api/lazy.js +1 -0
- package/dist/api/lazy.js.map +1 -1
- package/dist/api/mistral-conversations.d.ts.map +1 -1
- package/dist/api/mistral-conversations.js +2 -0
- package/dist/api/mistral-conversations.js.map +1 -1
- package/dist/api/openai-codex-responses.d.ts.map +1 -1
- package/dist/api/openai-codex-responses.js +13 -3
- package/dist/api/openai-codex-responses.js.map +1 -1
- package/dist/api/openai-completions.d.ts.map +1 -1
- package/dist/api/openai-completions.js +9 -1
- package/dist/api/openai-completions.js.map +1 -1
- package/dist/api/openai-responses-shared.d.ts.map +1 -1
- package/dist/api/openai-responses-shared.js +7 -4
- 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 +1 -0
- package/dist/api/openai-responses.js.map +1 -1
- package/dist/api/openrouter-images.d.ts.map +1 -1
- package/dist/api/openrouter-images.js +8 -2
- package/dist/api/openrouter-images.js.map +1 -1
- package/dist/api/pi-messages.d.ts.map +1 -1
- package/dist/api/pi-messages.js +19 -3
- package/dist/api/pi-messages.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/models.d.ts +1 -1
- package/dist/models.d.ts.map +1 -1
- package/dist/models.generated.d.ts +42 -0
- package/dist/models.generated.d.ts.map +1 -1
- package/dist/models.js +5 -2
- package/dist/models.js.map +1 -1
- package/dist/providers/faux.d.ts.map +1 -1
- package/dist/providers/faux.js +5 -1
- package/dist/providers/faux.js.map +1 -1
- package/dist/providers/google-vertex.models.d.ts +21 -0
- package/dist/providers/google-vertex.models.d.ts.map +1 -1
- package/dist/providers/google-vertex.models.js +3 -0
- package/dist/providers/google-vertex.models.js.map +1 -1
- package/dist/providers/google.models.d.ts +21 -0
- package/dist/providers/google.models.d.ts.map +1 -1
- package/dist/providers/google.models.js +3 -0
- package/dist/providers/google.models.js.map +1 -1
- package/dist/types.d.ts +10 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/estimate.d.ts +3 -0
- package/dist/utils/estimate.d.ts.map +1 -1
- package/dist/utils/estimate.js +35 -30
- package/dist/utils/estimate.js.map +1 -1
- package/package.json +1 -1
|
@@ -5834,6 +5834,13 @@ export declare const MODELS: {
|
|
|
5834
5834
|
output: number;
|
|
5835
5835
|
cacheRead: number;
|
|
5836
5836
|
cacheWrite: number;
|
|
5837
|
+
tiers: {
|
|
5838
|
+
inputTokensAbove: number;
|
|
5839
|
+
input: number;
|
|
5840
|
+
output: number;
|
|
5841
|
+
cacheRead: number;
|
|
5842
|
+
cacheWrite: number;
|
|
5843
|
+
}[];
|
|
5837
5844
|
};
|
|
5838
5845
|
contextWindow: number;
|
|
5839
5846
|
maxTokens: number;
|
|
@@ -5942,6 +5949,13 @@ export declare const MODELS: {
|
|
|
5942
5949
|
output: number;
|
|
5943
5950
|
cacheRead: number;
|
|
5944
5951
|
cacheWrite: number;
|
|
5952
|
+
tiers: {
|
|
5953
|
+
inputTokensAbove: number;
|
|
5954
|
+
input: number;
|
|
5955
|
+
output: number;
|
|
5956
|
+
cacheRead: number;
|
|
5957
|
+
cacheWrite: number;
|
|
5958
|
+
}[];
|
|
5945
5959
|
};
|
|
5946
5960
|
contextWindow: number;
|
|
5947
5961
|
maxTokens: number;
|
|
@@ -5966,6 +5980,13 @@ export declare const MODELS: {
|
|
|
5966
5980
|
output: number;
|
|
5967
5981
|
cacheRead: number;
|
|
5968
5982
|
cacheWrite: number;
|
|
5983
|
+
tiers: {
|
|
5984
|
+
inputTokensAbove: number;
|
|
5985
|
+
input: number;
|
|
5986
|
+
output: number;
|
|
5987
|
+
cacheRead: number;
|
|
5988
|
+
cacheWrite: number;
|
|
5989
|
+
}[];
|
|
5969
5990
|
};
|
|
5970
5991
|
contextWindow: number;
|
|
5971
5992
|
maxTokens: number;
|
|
@@ -6127,6 +6148,13 @@ export declare const MODELS: {
|
|
|
6127
6148
|
output: number;
|
|
6128
6149
|
cacheRead: number;
|
|
6129
6150
|
cacheWrite: number;
|
|
6151
|
+
tiers: {
|
|
6152
|
+
inputTokensAbove: number;
|
|
6153
|
+
input: number;
|
|
6154
|
+
output: number;
|
|
6155
|
+
cacheRead: number;
|
|
6156
|
+
cacheWrite: number;
|
|
6157
|
+
}[];
|
|
6130
6158
|
};
|
|
6131
6159
|
contextWindow: number;
|
|
6132
6160
|
maxTokens: number;
|
|
@@ -6191,6 +6219,13 @@ export declare const MODELS: {
|
|
|
6191
6219
|
output: number;
|
|
6192
6220
|
cacheRead: number;
|
|
6193
6221
|
cacheWrite: number;
|
|
6222
|
+
tiers: {
|
|
6223
|
+
inputTokensAbove: number;
|
|
6224
|
+
input: number;
|
|
6225
|
+
output: number;
|
|
6226
|
+
cacheRead: number;
|
|
6227
|
+
cacheWrite: number;
|
|
6228
|
+
}[];
|
|
6194
6229
|
};
|
|
6195
6230
|
contextWindow: number;
|
|
6196
6231
|
maxTokens: number;
|
|
@@ -6215,6 +6250,13 @@ export declare const MODELS: {
|
|
|
6215
6250
|
output: number;
|
|
6216
6251
|
cacheRead: number;
|
|
6217
6252
|
cacheWrite: number;
|
|
6253
|
+
tiers: {
|
|
6254
|
+
inputTokensAbove: number;
|
|
6255
|
+
input: number;
|
|
6256
|
+
output: number;
|
|
6257
|
+
cacheRead: number;
|
|
6258
|
+
cacheWrite: number;
|
|
6259
|
+
}[];
|
|
6218
6260
|
};
|
|
6219
6261
|
contextWindow: number;
|
|
6220
6262
|
maxTokens: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.generated.d.ts","sourceRoot":"","sources":["../src/models.generated.ts"],"names":[],"mappings":"AA2CA,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwCT,CAAC","sourcesContent":["// This file is auto-generated by scripts/generate-models.ts\n// Do not edit manually - run 'npm run generate-models' to update\n\nimport { AMAZON_BEDROCK_MODELS } from \"./providers/amazon-bedrock.models.ts\";\nimport { ANT_LING_MODELS } from \"./providers/ant-ling.models.ts\";\nimport { ANTHROPIC_MODELS } from \"./providers/anthropic.models.ts\";\nimport { AZURE_OPENAI_RESPONSES_MODELS } from \"./providers/azure-openai-responses.models.ts\";\nimport { CEREBRAS_MODELS } from \"./providers/cerebras.models.ts\";\nimport { CLOUDFLARE_AI_GATEWAY_MODELS } from \"./providers/cloudflare-ai-gateway.models.ts\";\nimport { CLOUDFLARE_WORKERS_AI_MODELS } from \"./providers/cloudflare-workers-ai.models.ts\";\nimport { DEEPSEEK_MODELS } from \"./providers/deepseek.models.ts\";\nimport { FIREWORKS_MODELS } from \"./providers/fireworks.models.ts\";\nimport { GITHUB_COPILOT_MODELS } from \"./providers/github-copilot.models.ts\";\nimport { GOOGLE_MODELS } from \"./providers/google.models.ts\";\nimport { GOOGLE_VERTEX_MODELS } from \"./providers/google-vertex.models.ts\";\nimport { GROQ_MODELS } from \"./providers/groq.models.ts\";\nimport { HUGGINGFACE_MODELS } from \"./providers/huggingface.models.ts\";\nimport { KIMI_CODING_MODELS } from \"./providers/kimi-coding.models.ts\";\nimport { MINIMAX_MODELS } from \"./providers/minimax.models.ts\";\nimport { MINIMAX_CN_MODELS } from \"./providers/minimax-cn.models.ts\";\nimport { MISTRAL_MODELS } from \"./providers/mistral.models.ts\";\nimport { MOONSHOTAI_MODELS } from \"./providers/moonshotai.models.ts\";\nimport { MOONSHOTAI_CN_MODELS } from \"./providers/moonshotai-cn.models.ts\";\nimport { NVIDIA_MODELS } from \"./providers/nvidia.models.ts\";\nimport { OPENAI_MODELS } from \"./providers/openai.models.ts\";\nimport { OPENAI_CODEX_MODELS } from \"./providers/openai-codex.models.ts\";\nimport { OPENCODE_MODELS } from \"./providers/opencode.models.ts\";\nimport { OPENCODE_GO_MODELS } from \"./providers/opencode-go.models.ts\";\nimport { OPENROUTER_MODELS } from \"./providers/openrouter.models.ts\";\nimport { QWEN_TOKEN_PLAN_MODELS } from \"./providers/qwen-token-plan.models.ts\";\nimport { QWEN_TOKEN_PLAN_CN_MODELS } from \"./providers/qwen-token-plan-cn.models.ts\";\nimport { QWEN_CLOUD_MODELS } from \"./providers/qwen-cloud.models.ts\";\nimport { QWEN_CLOUD_CN_MODELS } from \"./providers/qwen-cloud-cn.models.ts\";\nimport { TOGETHER_MODELS } from \"./providers/together.models.ts\";\nimport { VERCEL_AI_GATEWAY_MODELS } from \"./providers/vercel-ai-gateway.models.ts\";\nimport { XAI_MODELS } from \"./providers/xai.models.ts\";\nimport { XIAOMI_MODELS } from \"./providers/xiaomi.models.ts\";\nimport { XIAOMI_TOKEN_PLAN_AMS_MODELS } from \"./providers/xiaomi-token-plan-ams.models.ts\";\nimport { XIAOMI_TOKEN_PLAN_CN_MODELS } from \"./providers/xiaomi-token-plan-cn.models.ts\";\nimport { XIAOMI_TOKEN_PLAN_SGP_MODELS } from \"./providers/xiaomi-token-plan-sgp.models.ts\";\nimport { ZAI_MODELS } from \"./providers/zai.models.ts\";\nimport { ZAI_CODING_CN_MODELS } from \"./providers/zai-coding-cn.models.ts\";\n\nexport const MODELS = {\n\t\"amazon-bedrock\": AMAZON_BEDROCK_MODELS,\n\t\"ant-ling\": ANT_LING_MODELS,\n\t\"anthropic\": ANTHROPIC_MODELS,\n\t\"azure-openai-responses\": AZURE_OPENAI_RESPONSES_MODELS,\n\t\"cerebras\": CEREBRAS_MODELS,\n\t\"cloudflare-ai-gateway\": CLOUDFLARE_AI_GATEWAY_MODELS,\n\t\"cloudflare-workers-ai\": CLOUDFLARE_WORKERS_AI_MODELS,\n\t\"deepseek\": DEEPSEEK_MODELS,\n\t\"fireworks\": FIREWORKS_MODELS,\n\t\"github-copilot\": GITHUB_COPILOT_MODELS,\n\t\"google\": GOOGLE_MODELS,\n\t\"google-vertex\": GOOGLE_VERTEX_MODELS,\n\t\"groq\": GROQ_MODELS,\n\t\"huggingface\": HUGGINGFACE_MODELS,\n\t\"kimi-coding\": KIMI_CODING_MODELS,\n\t\"minimax\": MINIMAX_MODELS,\n\t\"minimax-cn\": MINIMAX_CN_MODELS,\n\t\"mistral\": MISTRAL_MODELS,\n\t\"moonshotai\": MOONSHOTAI_MODELS,\n\t\"moonshotai-cn\": MOONSHOTAI_CN_MODELS,\n\t\"nvidia\": NVIDIA_MODELS,\n\t\"openai\": OPENAI_MODELS,\n\t\"openai-codex\": OPENAI_CODEX_MODELS,\n\t\"opencode\": OPENCODE_MODELS,\n\t\"opencode-go\": OPENCODE_GO_MODELS,\n\t\"openrouter\": OPENROUTER_MODELS,\n\t\"qwen-token-plan\": QWEN_TOKEN_PLAN_MODELS,\n\t\"qwen-token-plan-cn\": QWEN_TOKEN_PLAN_CN_MODELS,\n\t\"qwen-cloud\": QWEN_CLOUD_MODELS,\n\t\"qwen-cloud-cn\": QWEN_CLOUD_CN_MODELS,\n\t\"together\": TOGETHER_MODELS,\n\t\"vercel-ai-gateway\": VERCEL_AI_GATEWAY_MODELS,\n\t\"xai\": XAI_MODELS,\n\t\"xiaomi\": XIAOMI_MODELS,\n\t\"xiaomi-token-plan-ams\": XIAOMI_TOKEN_PLAN_AMS_MODELS,\n\t\"xiaomi-token-plan-cn\": XIAOMI_TOKEN_PLAN_CN_MODELS,\n\t\"xiaomi-token-plan-sgp\": XIAOMI_TOKEN_PLAN_SGP_MODELS,\n\t\"zai\": ZAI_MODELS,\n\t\"zai-coding-cn\": ZAI_CODING_CN_MODELS,\n} as const;\n"]}
|
|
1
|
+
{"version":3,"file":"models.generated.d.ts","sourceRoot":"","sources":["../src/models.generated.ts"],"names":[],"mappings":"AA2CA,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwCT,CAAC","sourcesContent":["// This file is auto-generated by scripts/generate-models.ts\n// Do not edit manually - run 'npm run generate-models' to update\n\nimport { AMAZON_BEDROCK_MODELS } from \"./providers/amazon-bedrock.models.ts\";\nimport { ANT_LING_MODELS } from \"./providers/ant-ling.models.ts\";\nimport { ANTHROPIC_MODELS } from \"./providers/anthropic.models.ts\";\nimport { AZURE_OPENAI_RESPONSES_MODELS } from \"./providers/azure-openai-responses.models.ts\";\nimport { CEREBRAS_MODELS } from \"./providers/cerebras.models.ts\";\nimport { CLOUDFLARE_AI_GATEWAY_MODELS } from \"./providers/cloudflare-ai-gateway.models.ts\";\nimport { CLOUDFLARE_WORKERS_AI_MODELS } from \"./providers/cloudflare-workers-ai.models.ts\";\nimport { DEEPSEEK_MODELS } from \"./providers/deepseek.models.ts\";\nimport { FIREWORKS_MODELS } from \"./providers/fireworks.models.ts\";\nimport { GITHUB_COPILOT_MODELS } from \"./providers/github-copilot.models.ts\";\nimport { GOOGLE_MODELS } from \"./providers/google.models.ts\";\nimport { GOOGLE_VERTEX_MODELS } from \"./providers/google-vertex.models.ts\";\nimport { GROQ_MODELS } from \"./providers/groq.models.ts\";\nimport { HUGGINGFACE_MODELS } from \"./providers/huggingface.models.ts\";\nimport { KIMI_CODING_MODELS } from \"./providers/kimi-coding.models.ts\";\nimport { MINIMAX_MODELS } from \"./providers/minimax.models.ts\";\nimport { MINIMAX_CN_MODELS } from \"./providers/minimax-cn.models.ts\";\nimport { MISTRAL_MODELS } from \"./providers/mistral.models.ts\";\nimport { MOONSHOTAI_MODELS } from \"./providers/moonshotai.models.ts\";\nimport { MOONSHOTAI_CN_MODELS } from \"./providers/moonshotai-cn.models.ts\";\nimport { NVIDIA_MODELS } from \"./providers/nvidia.models.ts\";\nimport { OPENAI_MODELS } from \"./providers/openai.models.ts\";\nimport { OPENAI_CODEX_MODELS } from \"./providers/openai-codex.models.ts\";\nimport { OPENCODE_MODELS } from \"./providers/opencode.models.ts\";\nimport { OPENCODE_GO_MODELS } from \"./providers/opencode-go.models.ts\";\nimport { OPENROUTER_MODELS } from \"./providers/openrouter.models.ts\";\nimport { QWEN_TOKEN_PLAN_MODELS } from \"./providers/qwen-token-plan.models.ts\";\nimport { QWEN_TOKEN_PLAN_CN_MODELS } from \"./providers/qwen-token-plan-cn.models.ts\";\nimport { QWEN_CLOUD_MODELS } from \"./providers/qwen-cloud.models.ts\";\nimport { QWEN_CLOUD_CN_MODELS } from \"./providers/qwen-cloud-cn.models.ts\";\nimport { TOGETHER_MODELS } from \"./providers/together.models.ts\";\nimport { VERCEL_AI_GATEWAY_MODELS } from \"./providers/vercel-ai-gateway.models.ts\";\nimport { XAI_MODELS } from \"./providers/xai.models.ts\";\nimport { XIAOMI_MODELS } from \"./providers/xiaomi.models.ts\";\nimport { XIAOMI_TOKEN_PLAN_AMS_MODELS } from \"./providers/xiaomi-token-plan-ams.models.ts\";\nimport { XIAOMI_TOKEN_PLAN_CN_MODELS } from \"./providers/xiaomi-token-plan-cn.models.ts\";\nimport { XIAOMI_TOKEN_PLAN_SGP_MODELS } from \"./providers/xiaomi-token-plan-sgp.models.ts\";\nimport { ZAI_MODELS } from \"./providers/zai.models.ts\";\nimport { ZAI_CODING_CN_MODELS } from \"./providers/zai-coding-cn.models.ts\";\n\nexport const MODELS = {\n\t\"amazon-bedrock\": AMAZON_BEDROCK_MODELS,\n\t\"ant-ling\": ANT_LING_MODELS,\n\t\"anthropic\": ANTHROPIC_MODELS,\n\t\"azure-openai-responses\": AZURE_OPENAI_RESPONSES_MODELS,\n\t\"cerebras\": CEREBRAS_MODELS,\n\t\"cloudflare-ai-gateway\": CLOUDFLARE_AI_GATEWAY_MODELS,\n\t\"cloudflare-workers-ai\": CLOUDFLARE_WORKERS_AI_MODELS,\n\t\"deepseek\": DEEPSEEK_MODELS,\n\t\"fireworks\": FIREWORKS_MODELS,\n\t\"github-copilot\": GITHUB_COPILOT_MODELS,\n\t\"google\": GOOGLE_MODELS,\n\t\"google-vertex\": GOOGLE_VERTEX_MODELS,\n\t\"groq\": GROQ_MODELS,\n\t\"huggingface\": HUGGINGFACE_MODELS,\n\t\"kimi-coding\": KIMI_CODING_MODELS,\n\t\"minimax\": MINIMAX_MODELS,\n\t\"minimax-cn\": MINIMAX_CN_MODELS,\n\t\"mistral\": MISTRAL_MODELS,\n\t\"moonshotai\": MOONSHOTAI_MODELS,\n\t\"moonshotai-cn\": MOONSHOTAI_CN_MODELS,\n\t\"nvidia\": NVIDIA_MODELS,\n\t\"openai\": OPENAI_MODELS,\n\t\"openai-codex\": OPENAI_CODEX_MODELS,\n\t\"opencode\": OPENCODE_MODELS,\n\t\"opencode-go\": OPENCODE_GO_MODELS,\n\t\"openrouter\": OPENROUTER_MODELS,\n\t\"qwen-token-plan\": QWEN_TOKEN_PLAN_MODELS,\n\t\"qwen-token-plan-cn\": QWEN_TOKEN_PLAN_CN_MODELS,\n\t\"qwen-cloud\": QWEN_CLOUD_MODELS,\n\t\"qwen-cloud-cn\": QWEN_CLOUD_CN_MODELS,\n\t\"together\": TOGETHER_MODELS,\n\t\"vercel-ai-gateway\": VERCEL_AI_GATEWAY_MODELS,\n\t\"xai\": XAI_MODELS,\n\t\"xiaomi\": XIAOMI_MODELS,\n\t\"xiaomi-token-plan-ams\": XIAOMI_TOKEN_PLAN_AMS_MODELS,\n\t\"xiaomi-token-plan-cn\": XIAOMI_TOKEN_PLAN_CN_MODELS,\n\t\"xiaomi-token-plan-sgp\": XIAOMI_TOKEN_PLAN_SGP_MODELS,\n\t\"zai\": ZAI_MODELS,\n\t\"zai-coding-cn\": ZAI_CODING_CN_MODELS,\n} as const;\n"]}
|
package/dist/models.js
CHANGED
|
@@ -395,13 +395,16 @@ export function calculateCost(model, usage) {
|
|
|
395
395
|
}
|
|
396
396
|
}
|
|
397
397
|
// Anthropic charges 2x base input for 1h cache writes.
|
|
398
|
-
const longWrite = usage.cacheWrite1h ?? 0;
|
|
398
|
+
const longWrite = Math.min(usage.cacheWrite, Math.max(0, usage.cacheWrite1h ?? 0));
|
|
399
399
|
const shortWrite = usage.cacheWrite - longWrite;
|
|
400
400
|
usage.cost.input = (rates.input / 1000000) * usage.input;
|
|
401
401
|
usage.cost.output = (rates.output / 1000000) * usage.output;
|
|
402
402
|
usage.cost.cacheRead = (rates.cacheRead / 1000000) * usage.cacheRead;
|
|
403
403
|
usage.cost.cacheWrite = (rates.cacheWrite * shortWrite + rates.input * 2 * longWrite) / 1000000;
|
|
404
|
-
usage.cost.total =
|
|
404
|
+
usage.cost.total =
|
|
405
|
+
usage.reportedCost ?? usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
|
|
406
|
+
usage.costSource =
|
|
407
|
+
usage.reportedCost !== undefined ? "reported" : model.catalog?.pricing === "unknown" ? "unknown" : "estimated";
|
|
405
408
|
return usage.cost;
|
|
406
409
|
}
|
|
407
410
|
const EXTENDED_THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
package/dist/models.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAC5F,OAAO,EAAE,0BAA0B,IAAI,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACrF,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAgC,WAAW,EAAE,mBAAmB,EAAE,MAAM,mBAAm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Content":["import { lazyStream } from \"./api/lazy.ts\";\nimport { ANTHROPIC_SETUP_REQUIRED, anthropicRequestRoute } from \"./auth/anthropic-route.ts\";\nimport { defaultProviderAuthContext as defaultAuthContext } from \"./auth/context.ts\";\nimport { InMemoryCredentialStore } from \"./auth/credential-store.ts\";\nimport { type AuthResolutionOverrides, ModelsError, resolveProviderAuth } from \"./auth/resolve.ts\";\nimport type {\n\tAuthCheck,\n\tAuthContext,\n\tAuthInteraction,\n\tAuthResult,\n\tAuthType,\n\tCredential,\n\tCredentialStore,\n\tProviderAuth,\n} from \"./auth/types.ts\";\nimport { InMemoryModelsStore, type ModelsStore, type ProviderModelsStore } from \"./models-store.ts\";\nimport type {\n\tApi,\n\tApiStreamOptions,\n\tAssistantMessage,\n\tAssistantMessageEventStream,\n\tContext,\n\tModel,\n\tModelCostRates,\n\tModelThinkingLevel,\n\tProviderHeaders,\n\tProviderStreams,\n\tSimpleStreamOptions,\n\tStreamOptions,\n\tUsage,\n} from \"./types.ts\";\n\nexport { ModelsError, type ModelsErrorCode } from \"./auth/resolve.ts\";\n\nexport interface RefreshModelsContext {\n\t/** Effective configured credential. OAuth credentials are refreshed before network access. */\n\tcredential?: Credential;\n\t/** Persistent model storage scoped to this provider ID. */\n\tstore: ProviderModelsStore;\n\t/** False during offline/cache-only initialization. */\n\tallowNetwork: boolean;\n\t/** Bypass provider freshness checks and fetch immediately when network access is allowed. */\n\tforce?: boolean;\n\tsignal?: AbortSignal;\n}\n\nexport interface ModelsRefreshOptions {\n\tallowNetwork?: boolean;\n\t/** Bypass provider freshness checks and fetch immediately when network access is allowed. */\n\tforce?: boolean;\n\tsignal?: AbortSignal;\n}\n\nexport interface ModelsRefreshResult {\n\taborted: boolean;\n\terrors: ReadonlyMap<string, Error>;\n}\n\nexport interface ModelsStreamTransforms {\n\t/** Transform fully assembled model/auth/request headers before provider dispatch. */\n\ttransformHeaders?: (headers: ProviderHeaders) => ProviderHeaders | Promise<ProviderHeaders>;\n}\n\nexport type ModelsApiStreamOptions<TApi extends Api> = ApiStreamOptions<TApi> & ModelsStreamTransforms;\nexport type ModelsSimpleStreamOptions = SimpleStreamOptions & ModelsStreamTransforms;\n\n/**\n * A provider is the concrete runtime unit. It owns id/name/base metadata,\n * auth methods, model listing, and stream behavior.\n *\n * `TApi` lets concrete provider factories declare which APIs their models\n * use (e.g. `openaiProvider(): Provider<\"openai-responses\" | \"openai-completions\">`),\n * giving typed model lists to direct factory users. Inside a `Models`\n * collection providers are held as `Provider<Api>`.\n */\nexport interface Provider<TApi extends Api = Api> {\n\treadonly id: string;\n\treadonly name: string;\n\n\treadonly baseUrl?: string;\n\treadonly headers?: ProviderHeaders;\n\n\t/**\n\t * Required: at least one of `apiKey`/`oauth`. Every provider has auth\n\t * semantics — even providers with only ambient credentials (env vars, AWS\n\t * profiles, ADC files) and keyless local servers provide `apiKey` auth\n\t * whose `resolve()` reports whether the provider is configured.\n\t * `Models.getAuth()` returns undefined when the provider is unconfigured.\n\t */\n\treadonly auth: ProviderAuth;\n\n\t/**\n\t * Current known models, sync. Static providers return their catalog;\n\t * dynamic providers return the list as of the last `refreshModels()`\n\t * (empty before the first). Must not throw; `Models` treats a throwing\n\t * implementation as having no models.\n\t */\n\tgetModels(): readonly Model<TApi>[];\n\n\t/**\n\t * Dynamic providers only: restore the provider-scoped stored catalog and optionally fetch\n\t * a newer list using the effective credential. Implementations must retain their previous\n\t * list on failure and honor the shared abort signal for network requests.\n\t */\n\trefreshModels?(context: RefreshModelsContext): Promise<void>;\n\n\t/**\n\t * Optional provider policy for credential-specific model availability.\n\t * `getModels()` remains the complete synchronous catalog; `Models.getAvailable()`\n\t * applies this filter after confirming that provider auth is configured.\n\t */\n\tfilterModels?(models: readonly Model<TApi>[], credential: Credential | undefined): readonly Model<TApi>[];\n\n\tstream<T extends TApi>(\n\t\tmodel: Model<T>,\n\t\tcontext: Context,\n\t\toptions?: ApiStreamOptions<T>,\n\t): AssistantMessageEventStream;\n\n\tstreamSimple(model: Model<TApi>, context: Context, options?: SimpleStreamOptions): AssistantMessageEventStream;\n}\n\n/**\n * Runtime collection of providers plus auth application and stream\n * convenience. Providers own stream behavior; `Models` resolves auth and\n * delegates each request to the provider that owns the model.\n */\nexport interface Models {\n\tgetProviders(): readonly Provider[];\n\tgetProvider(id: string): Provider | undefined;\n\n\t/**\n\t * Sync read of last-known models from one provider or all providers.\n\t * Best-effort: a provider whose `getModels()` throws yields no models.\n\t */\n\tgetModels(provider?: string): readonly Model<Api>[];\n\n\t/**\n\t * Sync runtime model lookup against last-known lists. Dynamic model lists\n\t * are typed as `Model<Api>`; narrow with the `hasApi()` type guard.\n\t */\n\tgetModel(provider: string, id: string): Model<Api> | undefined;\n\n\t/**\n\t * Refresh every configured dynamic provider concurrently. Provider errors and cancellation\n\t * are returned without rejecting; static and unconfigured providers are skipped.\n\t */\n\trefresh(options?: ModelsRefreshOptions): Promise<ModelsRefreshResult>;\n\n\t/** Check whether a provider has complete auth configuration without refreshing OAuth. */\n\tcheckAuth(providerId: string): Promise<AuthCheck | undefined>;\n\n\t/** Return models whose providers have complete auth configuration. */\n\tgetAvailable(providerId?: string): Promise<readonly Model<Api>[]>;\n\n\t/**\n\t * Resolve provider-scoped auth by provider id, or provider auth plus static\n\t * model headers when passed a model. Includes a source label for status UI.\n\t * Resolves `undefined` when the provider is unknown or unconfigured.\n\t * Rejects with `ModelsError`: code \"oauth\" when a token refresh fails (the\n\t * stored credential is preserved for retry; re-login fixes it), code \"auth\"\n\t * when api-key resolution or the credential store fails. Request paths\n\t * surface rejections as stream errors.\n\t */\n\tgetAuth(providerId: string, overrides?: AuthResolutionOverrides): Promise<AuthResult | undefined>;\n\tgetAuth(model: Model<Api>, overrides?: AuthResolutionOverrides): Promise<AuthResult | undefined>;\n\n\t/** Run a provider-owned login flow and persist its returned credential. */\n\tlogin(providerId: string, type: AuthType, interaction: AuthInteraction): Promise<Credential>;\n\n\t/** Remove the stored credential for a provider. */\n\tlogout(providerId: string): Promise<void>;\n\n\tstream<TApi extends Api>(\n\t\tmodel: Model<TApi>,\n\t\tcontext: Context,\n\t\toptions?: ModelsApiStreamOptions<TApi>,\n\t): AssistantMessageEventStream;\n\n\tcomplete<TApi extends Api>(\n\t\tmodel: Model<TApi>,\n\t\tcontext: Context,\n\t\toptions?: ModelsApiStreamOptions<TApi>,\n\t): Promise<AssistantMessage>;\n\n\tstreamSimple(model: Model<Api>, context: Context, options?: ModelsSimpleStreamOptions): AssistantMessageEventStream;\n\tcompleteSimple(model: Model<Api>, context: Context, options?: ModelsSimpleStreamOptions): Promise<AssistantMessage>;\n}\n\nexport interface MutableModels extends Models {\n\t/** Upsert/replace by provider.id. Provider ids are unique. */\n\tsetProvider(provider: Provider): void;\n\tdeleteProvider(id: string): void;\n\tclearProviders(): void;\n}\n\nexport interface CreateModelsOptions {\n\tcredentials?: CredentialStore;\n\tmodelsStore?: ModelsStore;\n\tauthContext?: AuthContext;\n}\n\nfunction mergeHeaders(\n\tbase: ProviderHeaders | undefined,\n\toverride: ProviderHeaders | undefined,\n): ProviderHeaders | undefined {\n\tif (!base && !override) return undefined;\n\tconst merged = { ...base };\n\tfor (const [name, value] of Object.entries(override ?? {})) {\n\t\tconst lowerName = name.toLowerCase();\n\t\tfor (const existingName of Object.keys(merged)) {\n\t\t\tif (existingName.toLowerCase() === lowerName) delete merged[existingName];\n\t\t}\n\t\tmerged[name] = value;\n\t}\n\treturn merged;\n}\n\nclass ModelsImpl implements MutableModels {\n\tprivate providers = new Map<string, Provider>();\n\tprivate credentials: CredentialStore;\n\tprivate modelsStore: ModelsStore;\n\tprivate authContext: AuthContext;\n\n\tconstructor(options?: CreateModelsOptions) {\n\t\tthis.credentials = options?.credentials ?? new InMemoryCredentialStore();\n\t\tthis.modelsStore = options?.modelsStore ?? new InMemoryModelsStore();\n\t\tthis.authContext = options?.authContext ?? defaultAuthContext();\n\t}\n\n\tsetProvider(provider: Provider): void {\n\t\tthis.providers.set(provider.id, provider);\n\t}\n\n\tdeleteProvider(id: string): void {\n\t\tthis.providers.delete(id);\n\t}\n\n\tclearProviders(): void {\n\t\tthis.providers.clear();\n\t}\n\n\tgetProviders(): readonly Provider[] {\n\t\treturn Array.from(this.providers.values());\n\t}\n\n\tgetProvider(id: string): Provider | undefined {\n\t\treturn this.providers.get(id);\n\t}\n\n\tgetModels(provider?: string): readonly Model<Api>[] {\n\t\tif (provider !== undefined) {\n\t\t\tconst entry = this.providers.get(provider);\n\t\t\tif (!entry) return [];\n\t\t\ttry {\n\t\t\t\treturn entry.getModels();\n\t\t\t} catch {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t}\n\n\t\tconst models: Model<Api>[] = [];\n\t\tfor (const entry of this.providers.values()) {\n\t\t\ttry {\n\t\t\t\tmodels.push(...entry.getModels());\n\t\t\t} catch {\n\t\t\t\t// Best-effort: ill-behaved providers yield no models.\n\t\t\t}\n\t\t}\n\t\treturn models;\n\t}\n\n\tgetModel(provider: string, id: string): Model<Api> | undefined {\n\t\treturn this.getModels(provider).find((model) => model.id === id);\n\t}\n\n\tasync refresh(options: ModelsRefreshOptions = {}): Promise<ModelsRefreshResult> {\n\t\tconst allowNetwork = options.allowNetwork ?? true;\n\t\tconst errors = new Map<string, Error>();\n\t\tconst refreshable = Array.from(this.providers.values()).filter(\n\t\t\t(provider): provider is Provider & Required<Pick<Provider, \"refreshModels\">> =>\n\t\t\t\tprovider.refreshModels !== undefined,\n\t\t);\n\n\t\tawait Promise.all(\n\t\t\trefreshable.map(async (provider) => {\n\t\t\t\tif (options.signal?.aborted) return;\n\t\t\t\tconst store: ProviderModelsStore = {\n\t\t\t\t\tread: () => this.modelsStore.read(provider.id),\n\t\t\t\t\twrite: (entry) => this.modelsStore.write(provider.id, entry),\n\t\t\t\t\tdelete: () => this.modelsStore.delete(provider.id),\n\t\t\t\t};\n\t\t\t\tlet stored: Credential | undefined;\n\t\t\t\ttry {\n\t\t\t\t\tstored = await this.readCredential(provider.id);\n\t\t\t\t\tconst credential = await this.resolveRefreshCredential(provider, stored, allowNetwork, options.signal);\n\t\t\t\t\tif (!credential) return;\n\t\t\t\t\tawait provider.refreshModels({\n\t\t\t\t\t\tcredential,\n\t\t\t\t\t\tstore,\n\t\t\t\t\t\tallowNetwork,\n\t\t\t\t\t\tforce: options.force,\n\t\t\t\t\t\tsignal: options.signal,\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!options.signal?.aborted) {\n\t\t\t\t\t\terrors.set(\n\t\t\t\t\t\t\tprovider.id,\n\t\t\t\t\t\t\terror instanceof Error\n\t\t\t\t\t\t\t\t? error\n\t\t\t\t\t\t\t\t: new ModelsError(\"model_source\", `Model refresh failed for ${provider.id}`, { cause: error }),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait provider.refreshModels({\n\t\t\t\t\t\t\tcredential: stored,\n\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\tallowNetwork: false,\n\t\t\t\t\t\t\tsignal: options.signal,\n\t\t\t\t\t\t});\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Preserve the original auth/network error; cache restoration is best-effort here.\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\n\t\treturn { aborted: options.signal?.aborted ?? false, errors };\n\t}\n\n\tprivate async resolveRefreshCredential(\n\t\tprovider: Provider,\n\t\tstored: Credential | undefined,\n\t\tallowNetwork: boolean,\n\t\tsignal?: AbortSignal,\n\t): Promise<Credential | undefined> {\n\t\tif (provider.id === \"anthropic\" && stored?.type === \"oauth\") {\n\t\t\tthrow new ModelsError(\"auth\", ANTHROPIC_SETUP_REQUIRED);\n\t\t}\n\t\tif (provider.id === \"anthropic\" && stored?.type === \"external_claude_code\") return stored;\n\t\tif (stored?.type === \"oauth\") {\n\t\t\tconst oauth = provider.auth.oauth;\n\t\t\tif (!oauth) return undefined;\n\t\t\tif (!allowNetwork || Date.now() < stored.expires) return stored;\n\t\t\tif (signal?.aborted) return undefined;\n\t\t\tconst post = await this.credentials.modify(provider.id, async (current) => {\n\t\t\t\tif (current?.type !== \"oauth\" || Date.now() < current.expires) return undefined;\n\t\t\t\treturn oauth.refresh(current, signal);\n\t\t\t});\n\t\t\treturn post?.type === \"oauth\" ? post : undefined;\n\t\t}\n\n\t\tconst apiKey = provider.auth.apiKey;\n\t\tif (!apiKey) return undefined;\n\t\tconst credential = stored?.type === \"api_key\" ? stored : undefined;\n\t\tconst result = await apiKey.resolve({ ctx: this.authContext, credential });\n\t\tif (!result) return undefined;\n\t\treturn { type: \"api_key\", key: result.auth.apiKey, env: result.env };\n\t}\n\n\tprivate async readCredential(providerId: string): Promise<Credential | undefined> {\n\t\ttry {\n\t\t\treturn await this.credentials.read(providerId);\n\t\t} catch (error) {\n\t\t\tthrow new ModelsError(\"auth\", `Credential store read failed for ${providerId}`, { cause: error });\n\t\t}\n\t}\n\n\tprivate async checkProviderAuth(\n\t\tprovider: Provider,\n\t\tcredential: Credential | undefined,\n\t): Promise<AuthCheck | undefined> {\n\t\tif (provider.id === \"anthropic\" && credential?.type === \"oauth\") return undefined;\n\t\tif (provider.id === \"anthropic\" && credential?.type === \"external_claude_code\") {\n\t\t\treturn (await this.authContext.env(\"ANTHROPIC_API_KEY\"))\n\t\t\t\t? { source: \"ANTHROPIC_API_KEY\", type: \"api_key\" }\n\t\t\t\t: { source: \"Claude Code subscription\", type: \"oauth\" };\n\t\t}\n\t\tif (credential?.type === \"oauth\") {\n\t\t\treturn provider.auth.oauth ? { source: \"OAuth\", type: \"oauth\" } : undefined;\n\t\t}\n\t\tconst apiKey = provider.auth.apiKey;\n\t\tif (!apiKey) return undefined;\n\t\tif (apiKey.check) {\n\t\t\ttry {\n\t\t\t\treturn await apiKey.check({\n\t\t\t\t\tctx: this.authContext,\n\t\t\t\t\tcredential: credential?.type === \"api_key\" ? credential : undefined,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tthrow new ModelsError(\"auth\", `API key auth check failed for provider ${provider.id}`, { cause: error });\n\t\t\t}\n\t\t}\n\n\t\tconst resolution = await resolveProviderAuth(provider, this.credentials, this.authContext);\n\t\treturn resolution ? { source: resolution.source, type: \"api_key\" } : undefined;\n\t}\n\n\tasync checkAuth(providerId: string): Promise<AuthCheck | undefined> {\n\t\tconst provider = this.providers.get(providerId);\n\t\tif (!provider) return undefined;\n\t\treturn this.checkProviderAuth(provider, await this.readCredential(providerId));\n\t}\n\n\tasync getAvailable(providerId?: string): Promise<readonly Model<Api>[]> {\n\t\tconst providers = providerId\n\t\t\t? [this.providers.get(providerId)].filter((entry) => entry !== undefined)\n\t\t\t: this.getProviders();\n\t\tconst checks = await Promise.all(\n\t\t\tproviders.map(async (provider) => {\n\t\t\t\tconst credential = await this.readCredential(provider.id);\n\t\t\t\treturn { provider, credential, auth: await this.checkProviderAuth(provider, credential) };\n\t\t\t}),\n\t\t);\n\t\treturn checks.flatMap(({ provider, credential, auth }) => {\n\t\t\tif (!auth) return [];\n\t\t\tconst models = provider.getModels();\n\t\t\tconst effectiveCredential =\n\t\t\t\tprovider.id === \"anthropic\" && auth.type === \"api_key\" && credential?.type === \"external_claude_code\"\n\t\t\t\t\t? undefined\n\t\t\t\t\t: credential;\n\t\t\treturn provider.filterModels?.(models, effectiveCredential) ?? models;\n\t\t});\n\t}\n\n\tgetAuth(providerId: string, overrides?: AuthResolutionOverrides): Promise<AuthResult | undefined>;\n\tgetAuth(model: Model<Api>, overrides?: AuthResolutionOverrides): Promise<AuthResult | undefined>;\n\tasync getAuth(\n\t\tproviderOrModel: string | Model<Api>,\n\t\toverrides?: AuthResolutionOverrides,\n\t): Promise<AuthResult | undefined> {\n\t\tconst providerId = typeof providerOrModel === \"string\" ? providerOrModel : providerOrModel.provider;\n\t\tconst provider = this.providers.get(providerId);\n\t\tif (!provider) return undefined;\n\t\tconst result = await resolveProviderAuth(provider, this.credentials, this.authContext, overrides);\n\t\tif (!result || typeof providerOrModel === \"string\" || !providerOrModel.headers) return result;\n\t\treturn {\n\t\t\t...result,\n\t\t\tauth: {\n\t\t\t\t...result.auth,\n\t\t\t\theaders: mergeHeaders(result.auth.headers, providerOrModel.headers),\n\t\t\t},\n\t\t};\n\t}\n\n\tasync login(providerId: string, type: AuthType, interaction: AuthInteraction): Promise<Credential> {\n\t\tconst provider = this.providers.get(providerId);\n\t\tif (!provider) throw new ModelsError(\"provider\", `Unknown provider: ${providerId}`);\n\t\tconst method = type === \"oauth\" ? provider.auth.oauth : provider.auth.apiKey;\n\t\tif (!method?.login) {\n\t\t\tthrow new ModelsError(\"auth\", `${provider.name} does not support ${type} login`);\n\t\t}\n\t\tconst credential = await method.login(interaction);\n\t\ttry {\n\t\t\tawait this.credentials.modify(providerId, async () => credential);\n\t\t} catch (error) {\n\t\t\tthrow new ModelsError(\"auth\", `Credential store modify failed for ${providerId}`, { cause: error });\n\t\t}\n\t\treturn credential;\n\t}\n\n\tasync logout(providerId: string): Promise<void> {\n\t\ttry {\n\t\t\tawait this.credentials.delete(providerId);\n\t\t} catch (error) {\n\t\t\tthrow new ModelsError(\"auth\", `Credential store delete failed for ${providerId}`, { cause: error });\n\t\t}\n\t}\n\n\tprivate requireProvider(model: Model<Api>): Provider {\n\t\tconst provider = this.providers.get(model.provider);\n\t\tif (!provider) {\n\t\t\tthrow new ModelsError(\"provider\", `Unknown provider: ${model.provider}`);\n\t\t}\n\t\treturn provider;\n\t}\n\n\tprivate async applyAuth<TOptions extends StreamOptions & ModelsStreamTransforms>(\n\t\tmodel: Model<Api>,\n\t\toptions: TOptions | undefined,\n\t): Promise<{ requestModel: Model<Api>; requestOptions: StreamOptions | undefined }> {\n\t\tthis.requireProvider(model);\n\t\tconst resolution = await this.getAuth(model, {\n\t\t\tapiKey: options?.apiKey,\n\t\t\tenv: options?.env,\n\t\t});\n\t\tif (!resolution) {\n\t\t\tthrow new ModelsError(\"auth\", `Provider is not configured: ${model.provider}`);\n\t\t}\n\t\tconst auth = resolution.auth;\n\n\t\t// Explicit request options win per-field; the Models-only transform runs last.\n\t\tconst route = anthropicRequestRoute(model.provider, resolution, options);\n\t\tlet headers = mergeHeaders(auth.headers, options?.headers);\n\t\tif (options?.transformHeaders) headers = await options.transformHeaders(headers ?? {});\n\t\tconst env = resolution.env || options?.env ? { ...(resolution.env ?? {}), ...(options?.env ?? {}) } : undefined;\n\t\tconst requestModel = auth.baseUrl ? { ...model, baseUrl: auth.baseUrl } : model;\n\t\tconst { transformHeaders: _transformHeaders, ...providerOptions } = options ?? {};\n\t\tconst requestOptions = { ...providerOptions, ...route, headers, env } as StreamOptions;\n\n\t\treturn { requestModel, requestOptions };\n\t}\n\n\tstream<TApi extends Api>(\n\t\tmodel: Model<TApi>,\n\t\tcontext: Context,\n\t\toptions?: ModelsApiStreamOptions<TApi>,\n\t): AssistantMessageEventStream {\n\t\treturn lazyStream(model, async () => {\n\t\t\tconst provider = this.requireProvider(model);\n\t\t\tconst { requestModel, requestOptions } = await this.applyAuth(\n\t\t\t\tmodel,\n\t\t\t\toptions as ModelsApiStreamOptions<Api> | undefined,\n\t\t\t);\n\t\t\treturn provider.stream(requestModel as Model<TApi>, context, requestOptions as ApiStreamOptions<TApi>);\n\t\t});\n\t}\n\n\tasync complete<TApi extends Api>(\n\t\tmodel: Model<TApi>,\n\t\tcontext: Context,\n\t\toptions?: ModelsApiStreamOptions<TApi>,\n\t): Promise<AssistantMessage> {\n\t\treturn this.stream(model, context, options).result();\n\t}\n\n\tstreamSimple(model: Model<Api>, context: Context, options?: ModelsSimpleStreamOptions): AssistantMessageEventStream {\n\t\treturn lazyStream(model, async () => {\n\t\t\tconst provider = this.requireProvider(model);\n\t\t\tconst { requestModel, requestOptions } = await this.applyAuth(model, options);\n\t\t\treturn provider.streamSimple(requestModel, context, requestOptions as SimpleStreamOptions);\n\t\t});\n\t}\n\n\tasync completeSimple(\n\t\tmodel: Model<Api>,\n\t\tcontext: Context,\n\t\toptions?: ModelsSimpleStreamOptions,\n\t): Promise<AssistantMessage> {\n\t\treturn this.streamSimple(model, context, options).result();\n\t}\n}\n\nexport function createModels(options?: CreateModelsOptions): MutableModels {\n\treturn new ModelsImpl(options);\n}\n\nexport interface CreateProviderOptions<TApi extends Api = Api> {\n\tid: string;\n\t/** Display name. Default: `id`. */\n\tname?: string;\n\tbaseUrl?: string;\n\theaders?: ProviderHeaders;\n\t/** Required — every provider has auth semantics, even ambient/keyless ones. */\n\tauth: ProviderAuth;\n\t/** Static baseline model list (empty for purely dynamic providers). */\n\tmodels: readonly Model<TApi>[];\n\t/** Fetch a dynamic model overlay. createProvider restores/persists it through ModelsStore. */\n\tfetchModels?: (context: RefreshModelsContext) => Promise<readonly Model<TApi>[]>;\n\tfilterModels?: (models: readonly Model<TApi>[], credential: Credential | undefined) => readonly Model<TApi>[];\n\t/** Single implementation, or map keyed by `model.api` for mixed-API providers. */\n\tapi: ProviderStreams | Partial<Record<TApi, ProviderStreams>>;\n}\n\n/**\n * Builds a provider from parts. Built-in provider factories and models.json\n * custom providers both go through this. A single `api` streams all models;\n * an `api` map dispatches on `model.api`, and a model whose api has no entry\n * produces a stream error.\n */\nexport function createProvider<TApi extends Api = Api>(input: CreateProviderOptions<TApi>): Provider<TApi> {\n\tconst baselineModels = input.models;\n\tlet dynamicModels: readonly Model<TApi>[] = [];\n\tlet inflightRefresh: Promise<void> | undefined;\n\tconst fetchModels = input.fetchModels;\n\tconst currentModels = (): readonly Model<TApi>[] => {\n\t\tconst merged = [...baselineModels];\n\t\tfor (const model of dynamicModels) {\n\t\t\tconst index = merged.findIndex((entry) => entry.id === model.id);\n\t\t\tif (index >= 0) merged[index] = model;\n\t\t\telse merged.push(model);\n\t\t}\n\t\treturn merged;\n\t};\n\tconst single =\n\t\ttypeof (input.api as ProviderStreams).stream === \"function\" ? (input.api as ProviderStreams) : undefined;\n\tconst byApi = single ? undefined : (input.api as Partial<Record<string, ProviderStreams>>);\n\n\tconst apiFor = (model: Model<Api>): ProviderStreams | undefined => single ?? byApi?.[model.api];\n\n\tconst dispatch = (\n\t\tmodel: Model<Api>,\n\t\trun: (streams: ProviderStreams) => AssistantMessageEventStream,\n\t): AssistantMessageEventStream => {\n\t\tconst streams = apiFor(model);\n\t\tif (!streams) {\n\t\t\treturn lazyStream(model, async () => {\n\t\t\t\tthrow new ModelsError(\"stream\", `Provider ${input.id} has no API implementation for \"${model.api}\"`);\n\t\t\t});\n\t\t}\n\t\treturn run(streams);\n\t};\n\n\treturn {\n\t\tid: input.id,\n\t\tname: input.name ?? input.id,\n\t\tbaseUrl: input.baseUrl,\n\t\theaders: input.headers,\n\t\tauth: input.auth,\n\t\tgetModels: currentModels,\n\t\trefreshModels: fetchModels\n\t\t\t? (context) => {\n\t\t\t\t\tinflightRefresh ??= (async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst stored = await context.store.read();\n\t\t\t\t\t\t\tif (stored) {\n\t\t\t\t\t\t\t\tdynamicModels = stored.models\n\t\t\t\t\t\t\t\t\t.filter((model) => model.provider === input.id)\n\t\t\t\t\t\t\t\t\t.map((model) => model as Model<TApi>);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (!context.allowNetwork || context.signal?.aborted) return;\n\t\t\t\t\t\t\tconst refreshed = await fetchModels(context);\n\t\t\t\t\t\t\tif (context.signal?.aborted) return;\n\t\t\t\t\t\t\tdynamicModels = refreshed;\n\t\t\t\t\t\t\tawait context.store.write({ models: refreshed, checkedAt: Date.now() });\n\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\tinflightRefresh = undefined;\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t\treturn inflightRefresh;\n\t\t\t\t}\n\t\t\t: undefined,\n\t\tfilterModels: input.filterModels,\n\t\tstream: (model, context, options) => dispatch(model, (streams) => streams.stream(model, context, options)),\n\t\tstreamSimple: (model, context, options) =>\n\t\t\tdispatch(model, (streams) => streams.streamSimple(model, context, options)),\n\t};\n}\n\n/**\n * Runtime-checked narrowing for dynamically looked-up models:\n *\n * ```ts\n * const model = models.getModel(\"anthropic\", \"claude-opus-4-7\");\n * if (model && hasApi(model, \"anthropic-messages\")) {\n * // model: Model<\"anthropic-messages\">, stream options fully typed\n * }\n * ```\n */\nexport function hasApi<TApi extends Api>(model: Model<Api>, api: TApi): model is Model<TApi> {\n\treturn model.api === api;\n}\n\nexport function calculateCost<TApi extends Api>(model: Model<TApi>, usage: Usage): Usage[\"cost\"] {\n\tconst inputTokens = usage.input + usage.cacheRead + usage.cacheWrite;\n\tlet rates: ModelCostRates = model.cost;\n\tlet matchedThreshold = -1;\n\tfor (const tier of model.cost.tiers ?? []) {\n\t\tif (inputTokens > tier.inputTokensAbove && tier.inputTokensAbove > matchedThreshold) {\n\t\t\trates = tier;\n\t\t\tmatchedThreshold = tier.inputTokensAbove;\n\t\t}\n\t}\n\n\t// Anthropic charges 2x base input for 1h cache writes.\n\tconst longWrite = usage.cacheWrite1h ?? 0;\n\tconst shortWrite = usage.cacheWrite - longWrite;\n\tusage.cost.input = (rates.input / 1000000) * usage.input;\n\tusage.cost.output = (rates.output / 1000000) * usage.output;\n\tusage.cost.cacheRead = (rates.cacheRead / 1000000) * usage.cacheRead;\n\tusage.cost.cacheWrite = (rates.cacheWrite * shortWrite + rates.input * 2 * longWrite) / 1000000;\n\tusage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;\n\treturn usage.cost;\n}\n\nconst EXTENDED_THINKING_LEVELS: ModelThinkingLevel[] = [\"off\", \"minimal\", \"low\", \"medium\", \"high\", \"xhigh\", \"max\"];\n\nexport function getSupportedThinkingLevels<TApi extends Api>(model: Model<TApi>): ModelThinkingLevel[] {\n\tif (!model.reasoning) return [\"off\"];\n\n\treturn EXTENDED_THINKING_LEVELS.filter((level) => {\n\t\tconst mapped = model.thinkingLevelMap?.[level];\n\t\tif (mapped === null) return false;\n\t\tif (level === \"xhigh\" || level === \"max\") return mapped !== undefined;\n\t\treturn true;\n\t});\n}\n\nexport function clampThinkingLevel<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tlevel: ModelThinkingLevel,\n): ModelThinkingLevel {\n\tconst availableLevels = getSupportedThinkingLevels(model);\n\tif (availableLevels.includes(level)) return level;\n\n\tconst requestedIndex = EXTENDED_THINKING_LEVELS.indexOf(level);\n\tif (requestedIndex === -1) return availableLevels[0] ?? \"off\";\n\n\tfor (let i = requestedIndex; i < EXTENDED_THINKING_LEVELS.length; i++) {\n\t\tconst candidate = EXTENDED_THINKING_LEVELS[i];\n\t\tif (availableLevels.includes(candidate)) return candidate;\n\t}\n\tfor (let i = requestedIndex - 1; i >= 0; i--) {\n\t\tconst candidate = EXTENDED_THINKING_LEVELS[i];\n\t\tif (availableLevels.includes(candidate)) return candidate;\n\t}\n\treturn availableLevels[0] ?? \"off\";\n}\n\n/**\n * Check if two models are equal by comparing both their id and provider.\n * Returns false if either model is null or undefined.\n */\nexport function modelsAreEqual<TApi extends Api>(\n\ta: Model<TApi> | null | undefined,\n\tb: Model<TApi> | null | undefined,\n): boolean {\n\tif (!a || !b) return false;\n\treturn a.id === b.id && a.provider === b.provider;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAC5F,OAAO,EAAE,0BAA0B,IAAI,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACrF,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAgC,WAAW,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAWnG,OAAO,EAAE,mBAAmB,EAA8C,MAAM,mBAAmB,CAAC;AAiBpG,OAAO,EAAE,WAAW,EAAwB,MAAM,mBAAmB,CAAC;AA0KtE,SAAS,YAAY,CACpB,IAAiC,EACjC,QAAqC,EACP;IAC9B,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ;QAAE,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AK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,QAAQ,CAAC;AAAA,CAClD","sourcesContent":["import { lazyStream } from \"./api/lazy.ts\";\nimport { ANTHROPIC_SETUP_REQUIRED, anthropicRequestRoute } from \"./auth/anthropic-route.ts\";\nimport { defaultProviderAuthContext as defaultAuthContext } from \"./auth/context.ts\";\nimport { InMemoryCredentialStore } from \"./auth/credential-store.ts\";\nimport { type AuthResolutionOverrides, ModelsError, resolveProviderAuth } from \"./auth/resolve.ts\";\nimport type {\n\tAuthCheck,\n\tAuthContext,\n\tAuthInteraction,\n\tAuthResult,\n\tAuthType,\n\tCredential,\n\tCredentialStore,\n\tProviderAuth,\n} from \"./auth/types.ts\";\nimport { InMemoryModelsStore, type ModelsStore, type ProviderModelsStore } from \"./models-store.ts\";\nimport type {\n\tApi,\n\tApiStreamOptions,\n\tAssistantMessage,\n\tAssistantMessageEventStream,\n\tContext,\n\tModel,\n\tModelCostRates,\n\tModelThinkingLevel,\n\tProviderHeaders,\n\tProviderStreams,\n\tSimpleStreamOptions,\n\tStreamOptions,\n\tUsage,\n} from \"./types.ts\";\n\nexport { ModelsError, type ModelsErrorCode } from \"./auth/resolve.ts\";\n\nexport interface RefreshModelsContext {\n\t/** Effective configured credential. OAuth credentials are refreshed before network access. */\n\tcredential?: Credential;\n\t/** Persistent model storage scoped to this provider ID. */\n\tstore: ProviderModelsStore;\n\t/** False during offline/cache-only initialization. */\n\tallowNetwork: boolean;\n\t/** Bypass provider freshness checks and fetch immediately when network access is allowed. */\n\tforce?: boolean;\n\tsignal?: AbortSignal;\n}\n\nexport interface ModelsRefreshOptions {\n\tallowNetwork?: boolean;\n\t/** Bypass provider freshness checks and fetch immediately when network access is allowed. */\n\tforce?: boolean;\n\tsignal?: AbortSignal;\n}\n\nexport interface ModelsRefreshResult {\n\taborted: boolean;\n\terrors: ReadonlyMap<string, Error>;\n}\n\nexport interface ModelsStreamTransforms {\n\t/** Transform fully assembled model/auth/request headers before provider dispatch. */\n\ttransformHeaders?: (headers: ProviderHeaders) => ProviderHeaders | Promise<ProviderHeaders>;\n}\n\nexport type ModelsApiStreamOptions<TApi extends Api> = ApiStreamOptions<TApi> & ModelsStreamTransforms;\nexport type ModelsSimpleStreamOptions = SimpleStreamOptions & ModelsStreamTransforms;\n\n/**\n * A provider is the concrete runtime unit. It owns id/name/base metadata,\n * auth methods, model listing, and stream behavior.\n *\n * `TApi` lets concrete provider factories declare which APIs their models\n * use (e.g. `openaiProvider(): Provider<\"openai-responses\" | \"openai-completions\">`),\n * giving typed model lists to direct factory users. Inside a `Models`\n * collection providers are held as `Provider<Api>`.\n */\nexport interface Provider<TApi extends Api = Api> {\n\treadonly id: string;\n\treadonly name: string;\n\n\treadonly baseUrl?: string;\n\treadonly headers?: ProviderHeaders;\n\n\t/**\n\t * Required: at least one of `apiKey`/`oauth`. Every provider has auth\n\t * semantics — even providers with only ambient credentials (env vars, AWS\n\t * profiles, ADC files) and keyless local servers provide `apiKey` auth\n\t * whose `resolve()` reports whether the provider is configured.\n\t * `Models.getAuth()` returns undefined when the provider is unconfigured.\n\t */\n\treadonly auth: ProviderAuth;\n\n\t/**\n\t * Current known models, sync. Static providers return their catalog;\n\t * dynamic providers return the list as of the last `refreshModels()`\n\t * (empty before the first). Must not throw; `Models` treats a throwing\n\t * implementation as having no models.\n\t */\n\tgetModels(): readonly Model<TApi>[];\n\n\t/**\n\t * Dynamic providers only: restore the provider-scoped stored catalog and optionally fetch\n\t * a newer list using the effective credential. Implementations must retain their previous\n\t * list on failure and honor the shared abort signal for network requests.\n\t */\n\trefreshModels?(context: RefreshModelsContext): Promise<void>;\n\n\t/**\n\t * Optional provider policy for credential-specific model availability.\n\t * `getModels()` remains the complete synchronous catalog; `Models.getAvailable()`\n\t * applies this filter after confirming that provider auth is configured.\n\t */\n\tfilterModels?(models: readonly Model<TApi>[], credential: Credential | undefined): readonly Model<TApi>[];\n\n\tstream<T extends TApi>(\n\t\tmodel: Model<T>,\n\t\tcontext: Context,\n\t\toptions?: ApiStreamOptions<T>,\n\t): AssistantMessageEventStream;\n\n\tstreamSimple(model: Model<TApi>, context: Context, options?: SimpleStreamOptions): AssistantMessageEventStream;\n}\n\n/**\n * Runtime collection of providers plus auth application and stream\n * convenience. Providers own stream behavior; `Models` resolves auth and\n * delegates each request to the provider that owns the model.\n */\nexport interface Models {\n\tgetProviders(): readonly Provider[];\n\tgetProvider(id: string): Provider | undefined;\n\n\t/**\n\t * Sync read of last-known models from one provider or all providers.\n\t * Best-effort: a provider whose `getModels()` throws yields no models.\n\t */\n\tgetModels(provider?: string): readonly Model<Api>[];\n\n\t/**\n\t * Sync runtime model lookup against last-known lists. Dynamic model lists\n\t * are typed as `Model<Api>`; narrow with the `hasApi()` type guard.\n\t */\n\tgetModel(provider: string, id: string): Model<Api> | undefined;\n\n\t/**\n\t * Refresh every configured dynamic provider concurrently. Provider errors and cancellation\n\t * are returned without rejecting; static and unconfigured providers are skipped.\n\t */\n\trefresh(options?: ModelsRefreshOptions): Promise<ModelsRefreshResult>;\n\n\t/** Check whether a provider has complete auth configuration without refreshing OAuth. */\n\tcheckAuth(providerId: string): Promise<AuthCheck | undefined>;\n\n\t/** Return models whose providers have complete auth configuration. */\n\tgetAvailable(providerId?: string): Promise<readonly Model<Api>[]>;\n\n\t/**\n\t * Resolve provider-scoped auth by provider id, or provider auth plus static\n\t * model headers when passed a model. Includes a source label for status UI.\n\t * Resolves `undefined` when the provider is unknown or unconfigured.\n\t * Rejects with `ModelsError`: code \"oauth\" when a token refresh fails (the\n\t * stored credential is preserved for retry; re-login fixes it), code \"auth\"\n\t * when api-key resolution or the credential store fails. Request paths\n\t * surface rejections as stream errors.\n\t */\n\tgetAuth(providerId: string, overrides?: AuthResolutionOverrides): Promise<AuthResult | undefined>;\n\tgetAuth(model: Model<Api>, overrides?: AuthResolutionOverrides): Promise<AuthResult | undefined>;\n\n\t/** Run a provider-owned login flow and persist its returned credential. */\n\tlogin(providerId: string, type: AuthType, interaction: AuthInteraction): Promise<Credential>;\n\n\t/** Remove the stored credential for a provider. */\n\tlogout(providerId: string): Promise<void>;\n\n\tstream<TApi extends Api>(\n\t\tmodel: Model<TApi>,\n\t\tcontext: Context,\n\t\toptions?: ModelsApiStreamOptions<TApi>,\n\t): AssistantMessageEventStream;\n\n\tcomplete<TApi extends Api>(\n\t\tmodel: Model<TApi>,\n\t\tcontext: Context,\n\t\toptions?: ModelsApiStreamOptions<TApi>,\n\t): Promise<AssistantMessage>;\n\n\tstreamSimple(model: Model<Api>, context: Context, options?: ModelsSimpleStreamOptions): AssistantMessageEventStream;\n\tcompleteSimple(model: Model<Api>, context: Context, options?: ModelsSimpleStreamOptions): Promise<AssistantMessage>;\n}\n\nexport interface MutableModels extends Models {\n\t/** Upsert/replace by provider.id. Provider ids are unique. */\n\tsetProvider(provider: Provider): void;\n\tdeleteProvider(id: string): void;\n\tclearProviders(): void;\n}\n\nexport interface CreateModelsOptions {\n\tcredentials?: CredentialStore;\n\tmodelsStore?: ModelsStore;\n\tauthContext?: AuthContext;\n}\n\nfunction mergeHeaders(\n\tbase: ProviderHeaders | undefined,\n\toverride: ProviderHeaders | undefined,\n): ProviderHeaders | undefined {\n\tif (!base && !override) return undefined;\n\tconst merged = { ...base };\n\tfor (const [name, value] of Object.entries(override ?? {})) {\n\t\tconst lowerName = name.toLowerCase();\n\t\tfor (const existingName of Object.keys(merged)) {\n\t\t\tif (existingName.toLowerCase() === lowerName) delete merged[existingName];\n\t\t}\n\t\tmerged[name] = value;\n\t}\n\treturn merged;\n}\n\nclass ModelsImpl implements MutableModels {\n\tprivate providers = new Map<string, Provider>();\n\tprivate credentials: CredentialStore;\n\tprivate modelsStore: ModelsStore;\n\tprivate authContext: AuthContext;\n\n\tconstructor(options?: CreateModelsOptions) {\n\t\tthis.credentials = options?.credentials ?? new InMemoryCredentialStore();\n\t\tthis.modelsStore = options?.modelsStore ?? new InMemoryModelsStore();\n\t\tthis.authContext = options?.authContext ?? defaultAuthContext();\n\t}\n\n\tsetProvider(provider: Provider): void {\n\t\tthis.providers.set(provider.id, provider);\n\t}\n\n\tdeleteProvider(id: string): void {\n\t\tthis.providers.delete(id);\n\t}\n\n\tclearProviders(): void {\n\t\tthis.providers.clear();\n\t}\n\n\tgetProviders(): readonly Provider[] {\n\t\treturn Array.from(this.providers.values());\n\t}\n\n\tgetProvider(id: string): Provider | undefined {\n\t\treturn this.providers.get(id);\n\t}\n\n\tgetModels(provider?: string): readonly Model<Api>[] {\n\t\tif (provider !== undefined) {\n\t\t\tconst entry = this.providers.get(provider);\n\t\t\tif (!entry) return [];\n\t\t\ttry {\n\t\t\t\treturn entry.getModels();\n\t\t\t} catch {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t}\n\n\t\tconst models: Model<Api>[] = [];\n\t\tfor (const entry of this.providers.values()) {\n\t\t\ttry {\n\t\t\t\tmodels.push(...entry.getModels());\n\t\t\t} catch {\n\t\t\t\t// Best-effort: ill-behaved providers yield no models.\n\t\t\t}\n\t\t}\n\t\treturn models;\n\t}\n\n\tgetModel(provider: string, id: string): Model<Api> | undefined {\n\t\treturn this.getModels(provider).find((model) => model.id === id);\n\t}\n\n\tasync refresh(options: ModelsRefreshOptions = {}): Promise<ModelsRefreshResult> {\n\t\tconst allowNetwork = options.allowNetwork ?? true;\n\t\tconst errors = new Map<string, Error>();\n\t\tconst refreshable = Array.from(this.providers.values()).filter(\n\t\t\t(provider): provider is Provider & Required<Pick<Provider, \"refreshModels\">> =>\n\t\t\t\tprovider.refreshModels !== undefined,\n\t\t);\n\n\t\tawait Promise.all(\n\t\t\trefreshable.map(async (provider) => {\n\t\t\t\tif (options.signal?.aborted) return;\n\t\t\t\tconst store: ProviderModelsStore = {\n\t\t\t\t\tread: () => this.modelsStore.read(provider.id),\n\t\t\t\t\twrite: (entry) => this.modelsStore.write(provider.id, entry),\n\t\t\t\t\tdelete: () => this.modelsStore.delete(provider.id),\n\t\t\t\t};\n\t\t\t\tlet stored: Credential | undefined;\n\t\t\t\ttry {\n\t\t\t\t\tstored = await this.readCredential(provider.id);\n\t\t\t\t\tconst credential = await this.resolveRefreshCredential(provider, stored, allowNetwork, options.signal);\n\t\t\t\t\tif (!credential) return;\n\t\t\t\t\tawait provider.refreshModels({\n\t\t\t\t\t\tcredential,\n\t\t\t\t\t\tstore,\n\t\t\t\t\t\tallowNetwork,\n\t\t\t\t\t\tforce: options.force,\n\t\t\t\t\t\tsignal: options.signal,\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!options.signal?.aborted) {\n\t\t\t\t\t\terrors.set(\n\t\t\t\t\t\t\tprovider.id,\n\t\t\t\t\t\t\terror instanceof Error\n\t\t\t\t\t\t\t\t? error\n\t\t\t\t\t\t\t\t: new ModelsError(\"model_source\", `Model refresh failed for ${provider.id}`, { cause: error }),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait provider.refreshModels({\n\t\t\t\t\t\t\tcredential: stored,\n\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\tallowNetwork: false,\n\t\t\t\t\t\t\tsignal: options.signal,\n\t\t\t\t\t\t});\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Preserve the original auth/network error; cache restoration is best-effort here.\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\n\t\treturn { aborted: options.signal?.aborted ?? false, errors };\n\t}\n\n\tprivate async resolveRefreshCredential(\n\t\tprovider: Provider,\n\t\tstored: Credential | undefined,\n\t\tallowNetwork: boolean,\n\t\tsignal?: AbortSignal,\n\t): Promise<Credential | undefined> {\n\t\tif (provider.id === \"anthropic\" && stored?.type === \"oauth\") {\n\t\t\tthrow new ModelsError(\"auth\", ANTHROPIC_SETUP_REQUIRED);\n\t\t}\n\t\tif (provider.id === \"anthropic\" && stored?.type === \"external_claude_code\") return stored;\n\t\tif (stored?.type === \"oauth\") {\n\t\t\tconst oauth = provider.auth.oauth;\n\t\t\tif (!oauth) return undefined;\n\t\t\tif (!allowNetwork || Date.now() < stored.expires) return stored;\n\t\t\tif (signal?.aborted) return undefined;\n\t\t\tconst post = await this.credentials.modify(provider.id, async (current) => {\n\t\t\t\tif (current?.type !== \"oauth\" || Date.now() < current.expires) return undefined;\n\t\t\t\treturn oauth.refresh(current, signal);\n\t\t\t});\n\t\t\treturn post?.type === \"oauth\" ? post : undefined;\n\t\t}\n\n\t\tconst apiKey = provider.auth.apiKey;\n\t\tif (!apiKey) return undefined;\n\t\tconst credential = stored?.type === \"api_key\" ? stored : undefined;\n\t\tconst result = await apiKey.resolve({ ctx: this.authContext, credential });\n\t\tif (!result) return undefined;\n\t\treturn { type: \"api_key\", key: result.auth.apiKey, env: result.env };\n\t}\n\n\tprivate async readCredential(providerId: string): Promise<Credential | undefined> {\n\t\ttry {\n\t\t\treturn await this.credentials.read(providerId);\n\t\t} catch (error) {\n\t\t\tthrow new ModelsError(\"auth\", `Credential store read failed for ${providerId}`, { cause: error });\n\t\t}\n\t}\n\n\tprivate async checkProviderAuth(\n\t\tprovider: Provider,\n\t\tcredential: Credential | undefined,\n\t): Promise<AuthCheck | undefined> {\n\t\tif (provider.id === \"anthropic\" && credential?.type === \"oauth\") return undefined;\n\t\tif (provider.id === \"anthropic\" && credential?.type === \"external_claude_code\") {\n\t\t\treturn (await this.authContext.env(\"ANTHROPIC_API_KEY\"))\n\t\t\t\t? { source: \"ANTHROPIC_API_KEY\", type: \"api_key\" }\n\t\t\t\t: { source: \"Claude Code subscription\", type: \"oauth\" };\n\t\t}\n\t\tif (credential?.type === \"oauth\") {\n\t\t\treturn provider.auth.oauth ? { source: \"OAuth\", type: \"oauth\" } : undefined;\n\t\t}\n\t\tconst apiKey = provider.auth.apiKey;\n\t\tif (!apiKey) return undefined;\n\t\tif (apiKey.check) {\n\t\t\ttry {\n\t\t\t\treturn await apiKey.check({\n\t\t\t\t\tctx: this.authContext,\n\t\t\t\t\tcredential: credential?.type === \"api_key\" ? credential : undefined,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tthrow new ModelsError(\"auth\", `API key auth check failed for provider ${provider.id}`, { cause: error });\n\t\t\t}\n\t\t}\n\n\t\tconst resolution = await resolveProviderAuth(provider, this.credentials, this.authContext);\n\t\treturn resolution ? { source: resolution.source, type: \"api_key\" } : undefined;\n\t}\n\n\tasync checkAuth(providerId: string): Promise<AuthCheck | undefined> {\n\t\tconst provider = this.providers.get(providerId);\n\t\tif (!provider) return undefined;\n\t\treturn this.checkProviderAuth(provider, await this.readCredential(providerId));\n\t}\n\n\tasync getAvailable(providerId?: string): Promise<readonly Model<Api>[]> {\n\t\tconst providers = providerId\n\t\t\t? [this.providers.get(providerId)].filter((entry) => entry !== undefined)\n\t\t\t: this.getProviders();\n\t\tconst checks = await Promise.all(\n\t\t\tproviders.map(async (provider) => {\n\t\t\t\tconst credential = await this.readCredential(provider.id);\n\t\t\t\treturn { provider, credential, auth: await this.checkProviderAuth(provider, credential) };\n\t\t\t}),\n\t\t);\n\t\treturn checks.flatMap(({ provider, credential, auth }) => {\n\t\t\tif (!auth) return [];\n\t\t\tconst models = provider.getModels();\n\t\t\tconst effectiveCredential =\n\t\t\t\tprovider.id === \"anthropic\" && auth.type === \"api_key\" && credential?.type === \"external_claude_code\"\n\t\t\t\t\t? undefined\n\t\t\t\t\t: credential;\n\t\t\treturn provider.filterModels?.(models, effectiveCredential) ?? models;\n\t\t});\n\t}\n\n\tgetAuth(providerId: string, overrides?: AuthResolutionOverrides): Promise<AuthResult | undefined>;\n\tgetAuth(model: Model<Api>, overrides?: AuthResolutionOverrides): Promise<AuthResult | undefined>;\n\tasync getAuth(\n\t\tproviderOrModel: string | Model<Api>,\n\t\toverrides?: AuthResolutionOverrides,\n\t): Promise<AuthResult | undefined> {\n\t\tconst providerId = typeof providerOrModel === \"string\" ? providerOrModel : providerOrModel.provider;\n\t\tconst provider = this.providers.get(providerId);\n\t\tif (!provider) return undefined;\n\t\tconst result = await resolveProviderAuth(provider, this.credentials, this.authContext, overrides);\n\t\tif (!result || typeof providerOrModel === \"string\" || !providerOrModel.headers) return result;\n\t\treturn {\n\t\t\t...result,\n\t\t\tauth: {\n\t\t\t\t...result.auth,\n\t\t\t\theaders: mergeHeaders(result.auth.headers, providerOrModel.headers),\n\t\t\t},\n\t\t};\n\t}\n\n\tasync login(providerId: string, type: AuthType, interaction: AuthInteraction): Promise<Credential> {\n\t\tconst provider = this.providers.get(providerId);\n\t\tif (!provider) throw new ModelsError(\"provider\", `Unknown provider: ${providerId}`);\n\t\tconst method = type === \"oauth\" ? provider.auth.oauth : provider.auth.apiKey;\n\t\tif (!method?.login) {\n\t\t\tthrow new ModelsError(\"auth\", `${provider.name} does not support ${type} login`);\n\t\t}\n\t\tconst credential = await method.login(interaction);\n\t\ttry {\n\t\t\tawait this.credentials.modify(providerId, async () => credential);\n\t\t} catch (error) {\n\t\t\tthrow new ModelsError(\"auth\", `Credential store modify failed for ${providerId}`, { cause: error });\n\t\t}\n\t\treturn credential;\n\t}\n\n\tasync logout(providerId: string): Promise<void> {\n\t\ttry {\n\t\t\tawait this.credentials.delete(providerId);\n\t\t} catch (error) {\n\t\t\tthrow new ModelsError(\"auth\", `Credential store delete failed for ${providerId}`, { cause: error });\n\t\t}\n\t}\n\n\tprivate requireProvider(model: Model<Api>): Provider {\n\t\tconst provider = this.providers.get(model.provider);\n\t\tif (!provider) {\n\t\t\tthrow new ModelsError(\"provider\", `Unknown provider: ${model.provider}`);\n\t\t}\n\t\treturn provider;\n\t}\n\n\tprivate async applyAuth<TOptions extends StreamOptions & ModelsStreamTransforms>(\n\t\tmodel: Model<Api>,\n\t\toptions: TOptions | undefined,\n\t): Promise<{ requestModel: Model<Api>; requestOptions: StreamOptions | undefined }> {\n\t\tthis.requireProvider(model);\n\t\tconst resolution = await this.getAuth(model, {\n\t\t\tapiKey: options?.apiKey,\n\t\t\tenv: options?.env,\n\t\t});\n\t\tif (!resolution) {\n\t\t\tthrow new ModelsError(\"auth\", `Provider is not configured: ${model.provider}`);\n\t\t}\n\t\tconst auth = resolution.auth;\n\n\t\t// Explicit request options win per-field; the Models-only transform runs last.\n\t\tconst route = anthropicRequestRoute(model.provider, resolution, options);\n\t\tlet headers = mergeHeaders(auth.headers, options?.headers);\n\t\tif (options?.transformHeaders) headers = await options.transformHeaders(headers ?? {});\n\t\tconst env = resolution.env || options?.env ? { ...(resolution.env ?? {}), ...(options?.env ?? {}) } : undefined;\n\t\tconst requestModel = auth.baseUrl ? { ...model, baseUrl: auth.baseUrl } : model;\n\t\tconst { transformHeaders: _transformHeaders, ...providerOptions } = options ?? {};\n\t\tconst requestOptions = { ...providerOptions, ...route, headers, env } as StreamOptions;\n\n\t\treturn { requestModel, requestOptions };\n\t}\n\n\tstream<TApi extends Api>(\n\t\tmodel: Model<TApi>,\n\t\tcontext: Context,\n\t\toptions?: ModelsApiStreamOptions<TApi>,\n\t): AssistantMessageEventStream {\n\t\treturn lazyStream(model, async () => {\n\t\t\tconst provider = this.requireProvider(model);\n\t\t\tconst { requestModel, requestOptions } = await this.applyAuth(\n\t\t\t\tmodel,\n\t\t\t\toptions as ModelsApiStreamOptions<Api> | undefined,\n\t\t\t);\n\t\t\treturn provider.stream(requestModel as Model<TApi>, context, requestOptions as ApiStreamOptions<TApi>);\n\t\t});\n\t}\n\n\tasync complete<TApi extends Api>(\n\t\tmodel: Model<TApi>,\n\t\tcontext: Context,\n\t\toptions?: ModelsApiStreamOptions<TApi>,\n\t): Promise<AssistantMessage> {\n\t\treturn this.stream(model, context, options).result();\n\t}\n\n\tstreamSimple(model: Model<Api>, context: Context, options?: ModelsSimpleStreamOptions): AssistantMessageEventStream {\n\t\treturn lazyStream(model, async () => {\n\t\t\tconst provider = this.requireProvider(model);\n\t\t\tconst { requestModel, requestOptions } = await this.applyAuth(model, options);\n\t\t\treturn provider.streamSimple(requestModel, context, requestOptions as SimpleStreamOptions);\n\t\t});\n\t}\n\n\tasync completeSimple(\n\t\tmodel: Model<Api>,\n\t\tcontext: Context,\n\t\toptions?: ModelsSimpleStreamOptions,\n\t): Promise<AssistantMessage> {\n\t\treturn this.streamSimple(model, context, options).result();\n\t}\n}\n\nexport function createModels(options?: CreateModelsOptions): MutableModels {\n\treturn new ModelsImpl(options);\n}\n\nexport interface CreateProviderOptions<TApi extends Api = Api> {\n\tid: string;\n\t/** Display name. Default: `id`. */\n\tname?: string;\n\tbaseUrl?: string;\n\theaders?: ProviderHeaders;\n\t/** Required — every provider has auth semantics, even ambient/keyless ones. */\n\tauth: ProviderAuth;\n\t/** Static baseline model list (empty for purely dynamic providers). */\n\tmodels: readonly Model<TApi>[];\n\t/** Fetch a dynamic model overlay. createProvider restores/persists it through ModelsStore. */\n\tfetchModels?: (context: RefreshModelsContext) => Promise<readonly Model<TApi>[]>;\n\tfilterModels?: (models: readonly Model<TApi>[], credential: Credential | undefined) => readonly Model<TApi>[];\n\t/** Single implementation, or map keyed by `model.api` for mixed-API providers. */\n\tapi: ProviderStreams | Partial<Record<TApi, ProviderStreams>>;\n}\n\n/**\n * Builds a provider from parts. Built-in provider factories and models.json\n * custom providers both go through this. A single `api` streams all models;\n * an `api` map dispatches on `model.api`, and a model whose api has no entry\n * produces a stream error.\n */\nexport function createProvider<TApi extends Api = Api>(input: CreateProviderOptions<TApi>): Provider<TApi> {\n\tconst baselineModels = input.models;\n\tlet dynamicModels: readonly Model<TApi>[] = [];\n\tlet inflightRefresh: Promise<void> | undefined;\n\tconst fetchModels = input.fetchModels;\n\tconst currentModels = (): readonly Model<TApi>[] => {\n\t\tconst merged = [...baselineModels];\n\t\tfor (const model of dynamicModels) {\n\t\t\tconst index = merged.findIndex((entry) => entry.id === model.id);\n\t\t\tif (index >= 0) merged[index] = model;\n\t\t\telse merged.push(model);\n\t\t}\n\t\treturn merged;\n\t};\n\tconst single =\n\t\ttypeof (input.api as ProviderStreams).stream === \"function\" ? (input.api as ProviderStreams) : undefined;\n\tconst byApi = single ? undefined : (input.api as Partial<Record<string, ProviderStreams>>);\n\n\tconst apiFor = (model: Model<Api>): ProviderStreams | undefined => single ?? byApi?.[model.api];\n\n\tconst dispatch = (\n\t\tmodel: Model<Api>,\n\t\trun: (streams: ProviderStreams) => AssistantMessageEventStream,\n\t): AssistantMessageEventStream => {\n\t\tconst streams = apiFor(model);\n\t\tif (!streams) {\n\t\t\treturn lazyStream(model, async () => {\n\t\t\t\tthrow new ModelsError(\"stream\", `Provider ${input.id} has no API implementation for \"${model.api}\"`);\n\t\t\t});\n\t\t}\n\t\treturn run(streams);\n\t};\n\n\treturn {\n\t\tid: input.id,\n\t\tname: input.name ?? input.id,\n\t\tbaseUrl: input.baseUrl,\n\t\theaders: input.headers,\n\t\tauth: input.auth,\n\t\tgetModels: currentModels,\n\t\trefreshModels: fetchModels\n\t\t\t? (context) => {\n\t\t\t\t\tinflightRefresh ??= (async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst stored = await context.store.read();\n\t\t\t\t\t\t\tif (stored) {\n\t\t\t\t\t\t\t\tdynamicModels = stored.models\n\t\t\t\t\t\t\t\t\t.filter((model) => model.provider === input.id)\n\t\t\t\t\t\t\t\t\t.map((model) => model as Model<TApi>);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (!context.allowNetwork || context.signal?.aborted) return;\n\t\t\t\t\t\t\tconst refreshed = await fetchModels(context);\n\t\t\t\t\t\t\tif (context.signal?.aborted) return;\n\t\t\t\t\t\t\tdynamicModels = refreshed;\n\t\t\t\t\t\t\tawait context.store.write({ models: refreshed, checkedAt: Date.now() });\n\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\tinflightRefresh = undefined;\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t\treturn inflightRefresh;\n\t\t\t\t}\n\t\t\t: undefined,\n\t\tfilterModels: input.filterModels,\n\t\tstream: (model, context, options) => dispatch(model, (streams) => streams.stream(model, context, options)),\n\t\tstreamSimple: (model, context, options) =>\n\t\t\tdispatch(model, (streams) => streams.streamSimple(model, context, options)),\n\t};\n}\n\n/**\n * Runtime-checked narrowing for dynamically looked-up models:\n *\n * ```ts\n * const model = models.getModel(\"anthropic\", \"claude-opus-4-7\");\n * if (model && hasApi(model, \"anthropic-messages\")) {\n * // model: Model<\"anthropic-messages\">, stream options fully typed\n * }\n * ```\n */\nexport function hasApi<TApi extends Api>(model: Model<Api>, api: TApi): model is Model<TApi> {\n\treturn model.api === api;\n}\n\nexport function calculateCost<TApi extends Api>(\n\tmodel: Pick<Model<TApi>, \"cost\" | \"catalog\">,\n\tusage: Usage,\n): Usage[\"cost\"] {\n\tconst inputTokens = usage.input + usage.cacheRead + usage.cacheWrite;\n\tlet rates: ModelCostRates = model.cost;\n\tlet matchedThreshold = -1;\n\tfor (const tier of model.cost.tiers ?? []) {\n\t\tif (inputTokens > tier.inputTokensAbove && tier.inputTokensAbove > matchedThreshold) {\n\t\t\trates = tier;\n\t\t\tmatchedThreshold = tier.inputTokensAbove;\n\t\t}\n\t}\n\n\t// Anthropic charges 2x base input for 1h cache writes.\n\tconst longWrite = Math.min(usage.cacheWrite, Math.max(0, usage.cacheWrite1h ?? 0));\n\tconst shortWrite = usage.cacheWrite - longWrite;\n\tusage.cost.input = (rates.input / 1000000) * usage.input;\n\tusage.cost.output = (rates.output / 1000000) * usage.output;\n\tusage.cost.cacheRead = (rates.cacheRead / 1000000) * usage.cacheRead;\n\tusage.cost.cacheWrite = (rates.cacheWrite * shortWrite + rates.input * 2 * longWrite) / 1000000;\n\tusage.cost.total =\n\t\tusage.reportedCost ?? usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;\n\tusage.costSource =\n\t\tusage.reportedCost !== undefined ? \"reported\" : model.catalog?.pricing === \"unknown\" ? \"unknown\" : \"estimated\";\n\treturn usage.cost;\n}\n\nconst EXTENDED_THINKING_LEVELS: ModelThinkingLevel[] = [\"off\", \"minimal\", \"low\", \"medium\", \"high\", \"xhigh\", \"max\"];\n\nexport function getSupportedThinkingLevels<TApi extends Api>(model: Model<TApi>): ModelThinkingLevel[] {\n\tif (!model.reasoning) return [\"off\"];\n\n\treturn EXTENDED_THINKING_LEVELS.filter((level) => {\n\t\tconst mapped = model.thinkingLevelMap?.[level];\n\t\tif (mapped === null) return false;\n\t\tif (level === \"xhigh\" || level === \"max\") return mapped !== undefined;\n\t\treturn true;\n\t});\n}\n\nexport function clampThinkingLevel<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tlevel: ModelThinkingLevel,\n): ModelThinkingLevel {\n\tconst availableLevels = getSupportedThinkingLevels(model);\n\tif (availableLevels.includes(level)) return level;\n\n\tconst requestedIndex = EXTENDED_THINKING_LEVELS.indexOf(level);\n\tif (requestedIndex === -1) return availableLevels[0] ?? \"off\";\n\n\tfor (let i = requestedIndex; i < EXTENDED_THINKING_LEVELS.length; i++) {\n\t\tconst candidate = EXTENDED_THINKING_LEVELS[i];\n\t\tif (availableLevels.includes(candidate)) return candidate;\n\t}\n\tfor (let i = requestedIndex - 1; i >= 0; i--) {\n\t\tconst candidate = EXTENDED_THINKING_LEVELS[i];\n\t\tif (availableLevels.includes(candidate)) return candidate;\n\t}\n\treturn availableLevels[0] ?? \"off\";\n}\n\n/**\n * Check if two models are equal by comparing both their id and provider.\n * Returns false if either model is null or undefined.\n */\nexport function modelsAreEqual<TApi extends Api>(\n\ta: Model<TApi> | null | undefined,\n\tb: Model<TApi> | null | undefined,\n): boolean {\n\tif (!a || !b) return false;\n\treturn a.id === b.id && a.provider === b.provider;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"faux.d.ts","sourceRoot":"","sources":["../../src/providers/faux.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,KAAK,EACX,gBAAgB,EAEhB,OAAO,EAGP,KAAK,EACL,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,WAAW,EACX,eAAe,EACf,QAAQ,EAGR,MAAM,aAAa,CAAC;AAoBr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AAC,MAAM,CAAC,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IACrD,KAAK,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7B,YAAY,EAAE,CAAC,SAAS,EAAE,gBAAgB,EAAE,KAAK,IAAI,CAAC;IACtD,eAAe,EAAE,CAAC,SAAS,EAAE,gBAAgB,EAAE,KAAK,IAAI,CAAC;IACzD,uBAAuB,EAAE,MAAM,MAAM,CAAC;CACtC;AAyQD,wBAAgB,cAAc,CAAC,OAAO,EAAE,2BAA2B;;;;;;;;;;;;;;;;EAyGlE;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,2BAAgC,GAAG,kBAAkB,CAkB1F","sourcesContent":["import { createProvider, type Provider } from \"../models.ts\";\nimport type {\n\tAssistantMessage,\n\tAssistantMessageEventStream,\n\tContext,\n\tImageContent,\n\tMessage,\n\tModel,\n\tSimpleStreamOptions,\n\tStreamFunction,\n\tStreamOptions,\n\tTextContent,\n\tThinkingContent,\n\tToolCall,\n\tToolResultMessage,\n\tUsage,\n} from \"../types.ts\";\nimport { createAssistantMessageEventStream } from \"../utils/event-stream.ts\";\n\nconst DEFAULT_API = \"faux\";\nconst DEFAULT_PROVIDER = \"faux\";\nconst DEFAULT_MODEL_ID = \"faux-1\";\nconst DEFAULT_MODEL_NAME = \"Faux Model\";\nconst DEFAULT_BASE_URL = \"http://localhost:0\";\nconst DEFAULT_MIN_TOKEN_SIZE = 3;\nconst DEFAULT_MAX_TOKEN_SIZE = 5;\n\nconst DEFAULT_USAGE: Usage = {\n\tinput: 0,\n\toutput: 0,\n\tcacheRead: 0,\n\tcacheWrite: 0,\n\ttotalTokens: 0,\n\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n};\n\nexport interface FauxModelDefinition {\n\tid: string;\n\tname?: string;\n\treasoning?: boolean;\n\tinput?: (\"text\" | \"image\")[];\n\tcost?: { input: number; output: number; cacheRead: number; cacheWrite: number };\n\tcontextWindow?: number;\n\tmaxTokens?: number;\n}\n\nexport type FauxContentBlock = TextContent | ThinkingContent | ToolCall;\n\nexport function fauxText(text: string): TextContent {\n\treturn { type: \"text\", text };\n}\n\nexport function fauxThinking(thinking: string): ThinkingContent {\n\treturn { type: \"thinking\", thinking };\n}\n\nexport function fauxToolCall(name: string, arguments_: ToolCall[\"arguments\"], options: { id?: string } = {}): ToolCall {\n\treturn {\n\t\ttype: \"toolCall\",\n\t\tid: options.id ?? randomId(\"tool\"),\n\t\tname,\n\t\targuments: arguments_,\n\t};\n}\n\nfunction normalizeFauxAssistantContent(content: string | FauxContentBlock | FauxContentBlock[]): FauxContentBlock[] {\n\tif (typeof content === \"string\") {\n\t\treturn [fauxText(content)];\n\t}\n\treturn Array.isArray(content) ? content : [content];\n}\n\nexport function fauxAssistantMessage(\n\tcontent: string | FauxContentBlock | FauxContentBlock[],\n\toptions: {\n\t\tstopReason?: AssistantMessage[\"stopReason\"];\n\t\terrorMessage?: string;\n\t\tresponseId?: string;\n\t\ttimestamp?: number;\n\t} = {},\n): AssistantMessage {\n\treturn {\n\t\trole: \"assistant\",\n\t\tcontent: normalizeFauxAssistantContent(content),\n\t\tapi: DEFAULT_API,\n\t\tprovider: DEFAULT_PROVIDER,\n\t\tmodel: DEFAULT_MODEL_ID,\n\t\tusage: DEFAULT_USAGE,\n\t\tstopReason: options.stopReason ?? \"stop\",\n\t\terrorMessage: options.errorMessage,\n\t\tresponseId: options.responseId,\n\t\ttimestamp: options.timestamp ?? Date.now(),\n\t};\n}\n\nexport type FauxResponseFactory = (\n\tcontext: Context,\n\toptions: StreamOptions | undefined,\n\tstate: { callCount: number },\n\tmodel: Model<string>,\n) => AssistantMessage | Promise<AssistantMessage>;\n\nexport type FauxResponseStep = AssistantMessage | FauxResponseFactory;\n\nexport interface RegisterFauxProviderOptions {\n\tapi?: string;\n\tprovider?: string;\n\tmodels?: FauxModelDefinition[];\n\ttokensPerSecond?: number;\n\ttokenSize?: {\n\t\tmin?: number;\n\t\tmax?: number;\n\t};\n}\n\nexport interface FauxProviderRegistration {\n\tapi: string;\n\tmodels: [Model<string>, ...Model<string>[]];\n\tgetModel(): Model<string>;\n\tgetModel(modelId: string): Model<string> | undefined;\n\tstate: { callCount: number };\n\tsetResponses: (responses: FauxResponseStep[]) => void;\n\tappendResponses: (responses: FauxResponseStep[]) => void;\n\tgetPendingResponseCount: () => number;\n\tunregister: () => void;\n}\n\nexport interface FauxProviderHandle {\n\tprovider: Provider;\n\tapi: string;\n\tmodels: [Model<string>, ...Model<string>[]];\n\tgetModel(): Model<string>;\n\tgetModel(modelId: string): Model<string> | undefined;\n\tstate: { callCount: number };\n\tsetResponses: (responses: FauxResponseStep[]) => void;\n\tappendResponses: (responses: FauxResponseStep[]) => void;\n\tgetPendingResponseCount: () => number;\n}\n\nfunction estimateTokens(text: string): number {\n\treturn Math.ceil(text.length / 4);\n}\n\nfunction randomId(prefix: string): string {\n\treturn `${prefix}:${Date.now()}:${Math.random().toString(36).slice(2)}`;\n}\n\nfunction contentToText(content: string | Array<TextContent | ImageContent>): string {\n\tif (typeof content === \"string\") {\n\t\treturn content;\n\t}\n\treturn content\n\t\t.map((block) => {\n\t\t\tif (block.type === \"text\") {\n\t\t\t\treturn block.text;\n\t\t\t}\n\t\t\treturn `[image:${block.mimeType}:${block.data.length}]`;\n\t\t})\n\t\t.join(\"\\n\");\n}\n\nfunction assistantContentToText(content: Array<TextContent | ThinkingContent | ToolCall>): string {\n\treturn content\n\t\t.map((block) => {\n\t\t\tif (block.type === \"text\") {\n\t\t\t\treturn block.text;\n\t\t\t}\n\t\t\tif (block.type === \"thinking\") {\n\t\t\t\treturn block.thinking;\n\t\t\t}\n\t\t\treturn `${block.name}:${JSON.stringify(block.arguments)}`;\n\t\t})\n\t\t.join(\"\\n\");\n}\n\nfunction toolResultToText(message: ToolResultMessage): string {\n\treturn [message.toolName, ...message.content.map((block) => contentToText([block]))].join(\"\\n\");\n}\n\nfunction messageToText(message: Message): string {\n\tif (message.role === \"user\") {\n\t\treturn contentToText(message.content);\n\t}\n\tif (message.role === \"assistant\") {\n\t\treturn assistantContentToText(message.content);\n\t}\n\treturn toolResultToText(message);\n}\n\nfunction serializeContext(context: Context): string {\n\tconst parts: string[] = [];\n\tif (context.systemPrompt) {\n\t\tparts.push(`system:${context.systemPrompt}`);\n\t}\n\tfor (const message of context.messages) {\n\t\tparts.push(`${message.role}:${messageToText(message)}`);\n\t}\n\tif (context.tools?.length) {\n\t\tparts.push(`tools:${JSON.stringify(context.tools)}`);\n\t}\n\treturn parts.join(\"\\n\\n\");\n}\n\nfunction commonPrefixLength(a: string, b: string): number {\n\tconst length = Math.min(a.length, b.length);\n\tlet index = 0;\n\twhile (index < length && a[index] === b[index]) {\n\t\tindex++;\n\t}\n\treturn index;\n}\n\nfunction withUsageEstimate(\n\tmessage: AssistantMessage,\n\tcontext: Context,\n\toptions: StreamOptions | undefined,\n\tpromptCache: Map<string, string>,\n): AssistantMessage {\n\tconst promptText = serializeContext(context);\n\tconst promptTokens = estimateTokens(promptText);\n\tconst outputTokens = estimateTokens(assistantContentToText(message.content));\n\tlet input = promptTokens;\n\tlet cacheRead = 0;\n\tlet cacheWrite = 0;\n\tconst sessionId = options?.sessionId;\n\n\tif (sessionId && options?.cacheRetention !== \"none\") {\n\t\tconst previousPrompt = promptCache.get(sessionId);\n\t\tif (previousPrompt) {\n\t\t\tconst cachedChars = commonPrefixLength(previousPrompt, promptText);\n\t\t\tcacheRead = estimateTokens(previousPrompt.slice(0, cachedChars));\n\t\t\tcacheWrite = estimateTokens(promptText.slice(cachedChars));\n\t\t\tinput = Math.max(0, promptTokens - cacheRead);\n\t\t} else {\n\t\t\tcacheWrite = promptTokens;\n\t\t}\n\t\tpromptCache.set(sessionId, promptText);\n\t}\n\n\treturn {\n\t\t...message,\n\t\tusage: {\n\t\t\tinput,\n\t\t\toutput: outputTokens,\n\t\t\tcacheRead,\n\t\t\tcacheWrite,\n\t\t\ttotalTokens: input + outputTokens + cacheRead + cacheWrite,\n\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t},\n\t};\n}\n\nfunction splitStringByTokenSize(text: string, minTokenSize: number, maxTokenSize: number): string[] {\n\tconst chunks: string[] = [];\n\tlet index = 0;\n\twhile (index < text.length) {\n\t\tconst tokenSize = minTokenSize + Math.floor(Math.random() * (maxTokenSize - minTokenSize + 1));\n\t\tconst charSize = Math.max(1, tokenSize * 4);\n\t\tchunks.push(text.slice(index, index + charSize));\n\t\tindex += charSize;\n\t}\n\treturn chunks.length > 0 ? chunks : [\"\"];\n}\n\nfunction cloneMessage(message: AssistantMessage, api: string, provider: string, modelId: string): AssistantMessage {\n\tconst cloned = structuredClone(message);\n\treturn {\n\t\t...cloned,\n\t\tapi,\n\t\tprovider,\n\t\tmodel: modelId,\n\t\ttimestamp: cloned.timestamp ?? Date.now(),\n\t\tusage: cloned.usage ?? DEFAULT_USAGE,\n\t};\n}\n\nfunction createErrorMessage(error: unknown, api: string, provider: string, modelId: string): AssistantMessage {\n\treturn {\n\t\trole: \"assistant\",\n\t\tcontent: [],\n\t\tapi,\n\t\tprovider,\n\t\tmodel: modelId,\n\t\tusage: DEFAULT_USAGE,\n\t\tstopReason: \"error\",\n\t\terrorMessage: error instanceof Error ? error.message : String(error),\n\t\ttimestamp: Date.now(),\n\t};\n}\n\nfunction createAbortedMessage(partial: AssistantMessage): AssistantMessage {\n\treturn {\n\t\t...partial,\n\t\tstopReason: \"aborted\",\n\t\terrorMessage: \"Request was aborted\",\n\t\ttimestamp: Date.now(),\n\t};\n}\n\nfunction scheduleChunk(chunk: string, tokensPerSecond: number | undefined): Promise<void> {\n\tif (!tokensPerSecond || tokensPerSecond <= 0) {\n\t\treturn new Promise((resolve) => queueMicrotask(resolve));\n\t}\n\tconst delayMs = (estimateTokens(chunk) / tokensPerSecond) * 1000;\n\treturn new Promise((resolve) => setTimeout(resolve, delayMs));\n}\n\nasync function streamWithDeltas(\n\tstream: AssistantMessageEventStream,\n\tmessage: AssistantMessage,\n\tminTokenSize: number,\n\tmaxTokenSize: number,\n\ttokensPerSecond: number | undefined,\n\tsignal: AbortSignal | undefined,\n): Promise<void> {\n\tconst partial: AssistantMessage = { ...message, content: [] };\n\tif (signal?.aborted) {\n\t\tconst aborted = createAbortedMessage(partial);\n\t\tstream.push({ type: \"error\", reason: \"aborted\", error: aborted });\n\t\tstream.end(aborted);\n\t\treturn;\n\t}\n\n\tstream.push({ type: \"start\", partial: { ...partial } });\n\n\tfor (let index = 0; index < message.content.length; index++) {\n\t\tif (signal?.aborted) {\n\t\t\tconst aborted = createAbortedMessage(partial);\n\t\t\tstream.push({ type: \"error\", reason: \"aborted\", error: aborted });\n\t\t\tstream.end(aborted);\n\t\t\treturn;\n\t\t}\n\n\t\tconst block = message.content[index];\n\n\t\tif (block.type === \"thinking\") {\n\t\t\tpartial.content = [...partial.content, { type: \"thinking\", thinking: \"\" }];\n\t\t\tstream.push({ type: \"thinking_start\", contentIndex: index, partial: { ...partial } });\n\t\t\tfor (const chunk of splitStringByTokenSize(block.thinking, minTokenSize, maxTokenSize)) {\n\t\t\t\tawait scheduleChunk(chunk, tokensPerSecond);\n\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\tconst aborted = createAbortedMessage(partial);\n\t\t\t\t\tstream.push({ type: \"error\", reason: \"aborted\", error: aborted });\n\t\t\t\t\tstream.end(aborted);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t(partial.content[index] as ThinkingContent).thinking += chunk;\n\t\t\t\tstream.push({ type: \"thinking_delta\", contentIndex: index, delta: chunk, partial: { ...partial } });\n\t\t\t}\n\t\t\tstream.push({\n\t\t\t\ttype: \"thinking_end\",\n\t\t\t\tcontentIndex: index,\n\t\t\t\tcontent: block.thinking,\n\t\t\t\tpartial: { ...partial },\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (block.type === \"text\") {\n\t\t\tpartial.content = [...partial.content, { type: \"text\", text: \"\" }];\n\t\t\tstream.push({ type: \"text_start\", contentIndex: index, partial: { ...partial } });\n\t\t\tfor (const chunk of splitStringByTokenSize(block.text, minTokenSize, maxTokenSize)) {\n\t\t\t\tawait scheduleChunk(chunk, tokensPerSecond);\n\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\tconst aborted = createAbortedMessage(partial);\n\t\t\t\t\tstream.push({ type: \"error\", reason: \"aborted\", error: aborted });\n\t\t\t\t\tstream.end(aborted);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t(partial.content[index] as TextContent).text += chunk;\n\t\t\t\tstream.push({ type: \"text_delta\", contentIndex: index, delta: chunk, partial: { ...partial } });\n\t\t\t}\n\t\t\tstream.push({ type: \"text_end\", contentIndex: index, content: block.text, partial: { ...partial } });\n\t\t\tcontinue;\n\t\t}\n\n\t\tpartial.content = [...partial.content, { type: \"toolCall\", id: block.id, name: block.name, arguments: {} }];\n\t\tstream.push({ type: \"toolcall_start\", contentIndex: index, partial: { ...partial } });\n\t\tfor (const chunk of splitStringByTokenSize(JSON.stringify(block.arguments), minTokenSize, maxTokenSize)) {\n\t\t\tawait scheduleChunk(chunk, tokensPerSecond);\n\t\t\tif (signal?.aborted) {\n\t\t\t\tconst aborted = createAbortedMessage(partial);\n\t\t\t\tstream.push({ type: \"error\", reason: \"aborted\", error: aborted });\n\t\t\t\tstream.end(aborted);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tstream.push({ type: \"toolcall_delta\", contentIndex: index, delta: chunk, partial: { ...partial } });\n\t\t}\n\t\t(partial.content[index] as ToolCall).arguments = block.arguments;\n\t\tstream.push({ type: \"toolcall_end\", contentIndex: index, toolCall: block, partial: { ...partial } });\n\t}\n\n\tif (message.stopReason === \"error\" || message.stopReason === \"aborted\") {\n\t\tstream.push({ type: \"error\", reason: message.stopReason, error: message });\n\t\tstream.end(message);\n\t\treturn;\n\t}\n\n\tstream.push({ type: \"done\", reason: message.stopReason, message });\n\tstream.end(message);\n}\n\nexport function createFauxCore(options: RegisterFauxProviderOptions) {\n\tconst api = options.api ?? randomId(DEFAULT_API);\n\tconst provider = options.provider ?? DEFAULT_PROVIDER;\n\tconst minTokenSize = Math.max(\n\t\t1,\n\t\tMath.min(options.tokenSize?.min ?? DEFAULT_MIN_TOKEN_SIZE, options.tokenSize?.max ?? DEFAULT_MAX_TOKEN_SIZE),\n\t);\n\tconst maxTokenSize = Math.max(minTokenSize, options.tokenSize?.max ?? DEFAULT_MAX_TOKEN_SIZE);\n\tlet pendingResponses: FauxResponseStep[] = [];\n\tconst tokensPerSecond = options.tokensPerSecond;\n\tconst state = { callCount: 0 };\n\tconst promptCache = new Map<string, string>();\n\n\tconst modelDefinitions = options.models?.length\n\t\t? options.models\n\t\t: [\n\t\t\t\t{\n\t\t\t\t\tid: DEFAULT_MODEL_ID,\n\t\t\t\t\tname: DEFAULT_MODEL_NAME,\n\t\t\t\t\treasoning: false,\n\t\t\t\t\tinput: [\"text\", \"image\"] as (\"text\" | \"image\")[],\n\t\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\t\t\t\tcontextWindow: 128000,\n\t\t\t\t\tmaxTokens: 16384,\n\t\t\t\t},\n\t\t\t];\n\tconst models = modelDefinitions.map((definition) => ({\n\t\tid: definition.id,\n\t\tname: definition.name ?? definition.id,\n\t\tapi,\n\t\tprovider,\n\t\tbaseUrl: DEFAULT_BASE_URL,\n\t\treasoning: definition.reasoning ?? false,\n\t\tinput: definition.input ?? [\"text\", \"image\"],\n\t\tcost: definition.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tcontextWindow: definition.contextWindow ?? 128000,\n\t\tmaxTokens: definition.maxTokens ?? 16384,\n\t})) as [Model<string>, ...Model<string>[]];\n\n\tconst stream: StreamFunction<string, StreamOptions> = (requestModel, context, streamOptions) => {\n\t\tconst outer = createAssistantMessageEventStream();\n\t\tconst step = pendingResponses.shift();\n\t\tstate.callCount++;\n\n\t\tqueueMicrotask(async () => {\n\t\t\ttry {\n\t\t\t\tawait streamOptions?.onResponse?.({ status: 200, headers: {} }, requestModel);\n\t\t\t\tif (!step) {\n\t\t\t\t\tlet message = createErrorMessage(\n\t\t\t\t\t\tnew Error(\"No more faux responses queued\"),\n\t\t\t\t\t\tapi,\n\t\t\t\t\t\tprovider,\n\t\t\t\t\t\trequestModel.id,\n\t\t\t\t\t);\n\t\t\t\t\tmessage = withUsageEstimate(message, context, streamOptions, promptCache);\n\t\t\t\t\touter.push({ type: \"error\", reason: \"error\", error: message });\n\t\t\t\t\touter.end(message);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst resolved =\n\t\t\t\t\ttypeof step === \"function\" ? await step(context, streamOptions, state, requestModel) : step;\n\t\t\t\tlet message = cloneMessage(resolved, api, provider, requestModel.id);\n\t\t\t\tmessage = withUsageEstimate(message, context, streamOptions, promptCache);\n\t\t\t\tawait streamWithDeltas(outer, message, minTokenSize, maxTokenSize, tokensPerSecond, streamOptions?.signal);\n\t\t\t} catch (error) {\n\t\t\t\tconst message = createErrorMessage(error, api, provider, requestModel.id);\n\t\t\t\touter.push({ type: \"error\", reason: \"error\", error: message });\n\t\t\t\touter.end(message);\n\t\t\t}\n\t\t});\n\n\t\treturn outer;\n\t};\n\n\tconst streamSimple: StreamFunction<string, SimpleStreamOptions> = (streamModel, context, streamOptions) =>\n\t\tstream(streamModel, context, streamOptions);\n\n\tfunction getModel(): Model<string>;\n\tfunction getModel(requestedModelId: string): Model<string> | undefined;\n\tfunction getModel(requestedModelId?: string): Model<string> | undefined {\n\t\tif (!requestedModelId) {\n\t\t\treturn models[0];\n\t\t}\n\t\treturn models.find((candidate) => candidate.id === requestedModelId);\n\t}\n\n\treturn {\n\t\tapi,\n\t\tprovider,\n\t\tmodels,\n\t\tstream,\n\t\tstreamSimple,\n\t\tgetModel,\n\t\tstate,\n\t\tsetResponses(responses: FauxResponseStep[]) {\n\t\t\tpendingResponses = [...responses];\n\t\t},\n\t\tappendResponses(responses: FauxResponseStep[]) {\n\t\t\tpendingResponses.push(...responses);\n\t\t},\n\t\tgetPendingResponseCount() {\n\t\t\treturn pendingResponses.length;\n\t\t},\n\t};\n}\n\n/**\n * Faux provider for tests built on explicit `Models` collections:\n *\n * ```ts\n * const faux = fauxProvider();\n * const models = createModels();\n * models.setProvider(faux.provider);\n * faux.setResponses([fauxAssistantMessage(\"hi\")]);\n * ```\n */\nexport function fauxProvider(options: RegisterFauxProviderOptions = {}): FauxProviderHandle {\n\tconst core = createFauxCore(options);\n\tconst provider = createProvider({\n\t\tid: core.provider,\n\t\tauth: { apiKey: { name: \"Faux\", resolve: async () => ({ auth: {} }) } },\n\t\tmodels: core.models,\n\t\tapi: { stream: core.stream, streamSimple: core.streamSimple },\n\t});\n\treturn {\n\t\tprovider,\n\t\tapi: core.api,\n\t\tmodels: core.models,\n\t\tgetModel: core.getModel,\n\t\tstate: core.state,\n\t\tsetResponses: core.setResponses,\n\t\tappendResponses: core.appendResponses,\n\t\tgetPendingResponseCount: core.getPendingResponseCount,\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"faux.d.ts","sourceRoot":"","sources":["../../src/providers/faux.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,KAAK,EACX,gBAAgB,EAEhB,OAAO,EAGP,KAAK,EACL,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,WAAW,EACX,eAAe,EACf,QAAQ,EAGR,MAAM,aAAa,CAAC;AAoBrB,MAAM,WAAW,mBAAmB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,CAAC,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC;IAC7B,IAAI,CAAC,EAAE;Q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EAAE,KAAK,IAAI,CAAC;IACtD,eAAe,EAAE,CAAC,SAAS,EAAE,gBAAgB,EAAE,KAAK,IAAI,CAAC;IACzD,uBAAuB,EAAE,MAAM,MAAM,CAAC;CACtC;AA6QD,wBAAgB,cAAc,CAAC,OAAO,EAAE,2BAA2B;;;;;;;;;;;;;;;;EAyGlE;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,2BAAgC,GAAG,kBAAkB,CAkB1F","sourcesContent":["import { createProvider, type Provider } from \"../models.ts\";\nimport type {\n\tAssistantMessage,\n\tAssistantMessageEventStream,\n\tContext,\n\tImageContent,\n\tMessage,\n\tModel,\n\tSimpleStreamOptions,\n\tStreamFunction,\n\tStreamOptions,\n\tTextContent,\n\tThinkingContent,\n\tToolCall,\n\tToolResultMessage,\n\tUsage,\n} from \"../types.ts\";\nimport { createAssistantMessageEventStream } from \"../utils/event-stream.ts\";\n\nconst DEFAULT_API = \"faux\";\nconst DEFAULT_PROVIDER = \"faux\";\nconst DEFAULT_MODEL_ID = \"faux-1\";\nconst DEFAULT_MODEL_NAME = \"Faux Model\";\nconst DEFAULT_BASE_URL = \"http://localhost:0\";\nconst DEFAULT_MIN_TOKEN_SIZE = 3;\nconst DEFAULT_MAX_TOKEN_SIZE = 5;\n\nconst DEFAULT_USAGE: Usage = {\n\tinput: 0,\n\toutput: 0,\n\tcacheRead: 0,\n\tcacheWrite: 0,\n\ttotalTokens: 0,\n\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n};\n\nexport interface FauxModelDefinition {\n\tid: string;\n\tname?: string;\n\treasoning?: boolean;\n\tinput?: (\"text\" | \"image\")[];\n\tcost?: { input: number; output: number; cacheRead: number; cacheWrite: number };\n\tcontextWindow?: number;\n\tmaxTokens?: number;\n}\n\nexport type FauxContentBlock = TextContent | ThinkingContent | ToolCall;\n\nexport function fauxText(text: string): TextContent {\n\treturn { type: \"text\", text };\n}\n\nexport function fauxThinking(thinking: string): ThinkingContent {\n\treturn { type: \"thinking\", thinking };\n}\n\nexport function fauxToolCall(name: string, arguments_: ToolCall[\"arguments\"], options: { id?: string } = {}): ToolCall {\n\treturn {\n\t\ttype: \"toolCall\",\n\t\tid: options.id ?? randomId(\"tool\"),\n\t\tname,\n\t\targuments: arguments_,\n\t};\n}\n\nfunction normalizeFauxAssistantContent(content: string | FauxContentBlock | FauxContentBlock[]): FauxContentBlock[] {\n\tif (typeof content === \"string\") {\n\t\treturn [fauxText(content)];\n\t}\n\treturn Array.isArray(content) ? content : [content];\n}\n\nexport function fauxAssistantMessage(\n\tcontent: string | FauxContentBlock | FauxContentBlock[],\n\toptions: {\n\t\tstopReason?: AssistantMessage[\"stopReason\"];\n\t\terrorMessage?: string;\n\t\tresponseId?: string;\n\t\ttimestamp?: number;\n\t} = {},\n): AssistantMessage {\n\treturn {\n\t\trole: \"assistant\",\n\t\tcontent: normalizeFauxAssistantContent(content),\n\t\tapi: DEFAULT_API,\n\t\tprovider: DEFAULT_PROVIDER,\n\t\tmodel: DEFAULT_MODEL_ID,\n\t\tusage: DEFAULT_USAGE,\n\t\tstopReason: options.stopReason ?? \"stop\",\n\t\terrorMessage: options.errorMessage,\n\t\tresponseId: options.responseId,\n\t\ttimestamp: options.timestamp ?? Date.now(),\n\t};\n}\n\nexport type FauxResponseFactory = (\n\tcontext: Context,\n\toptions: StreamOptions | undefined,\n\tstate: { callCount: number },\n\tmodel: Model<string>,\n) => AssistantMessage | Promise<AssistantMessage>;\n\nexport type FauxResponseStep = AssistantMessage | FauxResponseFactory;\n\nexport interface RegisterFauxProviderOptions {\n\tapi?: string;\n\tprovider?: string;\n\tmodels?: FauxModelDefinition[];\n\ttokensPerSecond?: number;\n\ttokenSize?: {\n\t\tmin?: number;\n\t\tmax?: number;\n\t};\n}\n\nexport interface FauxProviderRegistration {\n\tapi: string;\n\tmodels: [Model<string>, ...Model<string>[]];\n\tgetModel(): Model<string>;\n\tgetModel(modelId: string): Model<string> | undefined;\n\tstate: { callCount: number };\n\tsetResponses: (responses: FauxResponseStep[]) => void;\n\tappendResponses: (responses: FauxResponseStep[]) => void;\n\tgetPendingResponseCount: () => number;\n\tunregister: () => void;\n}\n\nexport interface FauxProviderHandle {\n\tprovider: Provider;\n\tapi: string;\n\tmodels: [Model<string>, ...Model<string>[]];\n\tgetModel(): Model<string>;\n\tgetModel(modelId: string): Model<string> | undefined;\n\tstate: { callCount: number };\n\tsetResponses: (responses: FauxResponseStep[]) => void;\n\tappendResponses: (responses: FauxResponseStep[]) => void;\n\tgetPendingResponseCount: () => number;\n}\n\nfunction estimateTokens(text: string): number {\n\treturn Math.ceil(text.length / 4);\n}\n\nfunction randomId(prefix: string): string {\n\treturn `${prefix}:${Date.now()}:${Math.random().toString(36).slice(2)}`;\n}\n\nfunction contentToText(content: string | Array<TextContent | ImageContent>): string {\n\tif (typeof content === \"string\") {\n\t\treturn content;\n\t}\n\treturn content\n\t\t.map((block) => {\n\t\t\tif (block.type === \"text\") {\n\t\t\t\treturn block.text;\n\t\t\t}\n\t\t\treturn `[image:${block.mimeType}:${block.data.length}]`;\n\t\t})\n\t\t.join(\"\\n\");\n}\n\nfunction assistantContentToText(content: Array<TextContent | ThinkingContent | ToolCall>): string {\n\treturn content\n\t\t.map((block) => {\n\t\t\tif (block.type === \"text\") {\n\t\t\t\treturn block.text;\n\t\t\t}\n\t\t\tif (block.type === \"thinking\") {\n\t\t\t\treturn block.thinking;\n\t\t\t}\n\t\t\treturn `${block.name}:${JSON.stringify(block.arguments)}`;\n\t\t})\n\t\t.join(\"\\n\");\n}\n\nfunction toolResultToText(message: ToolResultMessage): string {\n\treturn [message.toolName, ...message.content.map((block) => contentToText([block]))].join(\"\\n\");\n}\n\nfunction messageToText(message: Message): string {\n\tif (message.role === \"user\") {\n\t\treturn contentToText(message.content);\n\t}\n\tif (message.role === \"assistant\") {\n\t\treturn assistantContentToText(message.content);\n\t}\n\treturn toolResultToText(message);\n}\n\nfunction serializeContext(context: Context): string {\n\tconst parts: string[] = [];\n\tif (context.systemPrompt) {\n\t\tparts.push(`system:${context.systemPrompt}`);\n\t}\n\tfor (const message of context.messages) {\n\t\tparts.push(`${message.role}:${messageToText(message)}`);\n\t}\n\tif (context.tools?.length) {\n\t\tparts.push(`tools:${JSON.stringify(context.tools)}`);\n\t}\n\treturn parts.join(\"\\n\\n\");\n}\n\nfunction commonPrefixLength(a: string, b: string): number {\n\tconst length = Math.min(a.length, b.length);\n\tlet index = 0;\n\twhile (index < length && a[index] === b[index]) {\n\t\tindex++;\n\t}\n\treturn index;\n}\n\nfunction withUsageEstimate(\n\tmessage: AssistantMessage,\n\tcontext: Context,\n\toptions: StreamOptions | undefined,\n\tpromptCache: Map<string, string>,\n): AssistantMessage {\n\tconst promptText = serializeContext(context);\n\tconst promptTokens = estimateTokens(promptText);\n\tconst outputTokens = estimateTokens(assistantContentToText(message.content));\n\tlet input = promptTokens;\n\tlet cacheRead = 0;\n\tlet cacheWrite = 0;\n\tconst sessionId = options?.sessionId;\n\n\tif (sessionId && options?.cacheRetention !== \"none\") {\n\t\tconst previousPrompt = promptCache.get(sessionId);\n\t\tif (previousPrompt) {\n\t\t\tconst cachedChars = commonPrefixLength(previousPrompt, promptText);\n\t\t\tcacheRead = estimateTokens(previousPrompt.slice(0, cachedChars));\n\t\t\tcacheWrite = estimateTokens(promptText.slice(cachedChars));\n\t\t\tcacheWrite = Math.max(0, promptTokens - cacheRead);\n\t\t\tinput = 0;\n\t\t} else {\n\t\t\tcacheWrite = promptTokens;\n\t\t\tinput = 0;\n\t\t}\n\t\tpromptCache.set(sessionId, promptText);\n\t}\n\n\treturn {\n\t\t...message,\n\t\tusage: {\n\t\t\tmeasurement: \"estimated\",\n\t\t\tcostSource: \"estimated\",\n\t\t\tinput,\n\t\t\toutput: outputTokens,\n\t\t\tcacheRead,\n\t\t\tcacheWrite,\n\t\t\ttotalTokens: input + outputTokens + cacheRead + cacheWrite,\n\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t},\n\t};\n}\n\nfunction splitStringByTokenSize(text: string, minTokenSize: number, maxTokenSize: number): string[] {\n\tconst chunks: string[] = [];\n\tlet index = 0;\n\twhile (index < text.length) {\n\t\tconst tokenSize = minTokenSize + Math.floor(Math.random() * (maxTokenSize - minTokenSize + 1));\n\t\tconst charSize = Math.max(1, tokenSize * 4);\n\t\tchunks.push(text.slice(index, index + charSize));\n\t\tindex += charSize;\n\t}\n\treturn chunks.length > 0 ? chunks : [\"\"];\n}\n\nfunction cloneMessage(message: AssistantMessage, api: string, provider: string, modelId: string): AssistantMessage {\n\tconst cloned = structuredClone(message);\n\treturn {\n\t\t...cloned,\n\t\tapi,\n\t\tprovider,\n\t\tmodel: modelId,\n\t\ttimestamp: cloned.timestamp ?? Date.now(),\n\t\tusage: cloned.usage ?? DEFAULT_USAGE,\n\t};\n}\n\nfunction createErrorMessage(error: unknown, api: string, provider: string, modelId: string): AssistantMessage {\n\treturn {\n\t\trole: \"assistant\",\n\t\tcontent: [],\n\t\tapi,\n\t\tprovider,\n\t\tmodel: modelId,\n\t\tusage: DEFAULT_USAGE,\n\t\tstopReason: \"error\",\n\t\terrorMessage: error instanceof Error ? error.message : String(error),\n\t\ttimestamp: Date.now(),\n\t};\n}\n\nfunction createAbortedMessage(partial: AssistantMessage): AssistantMessage {\n\treturn {\n\t\t...partial,\n\t\tstopReason: \"aborted\",\n\t\terrorMessage: \"Request was aborted\",\n\t\ttimestamp: Date.now(),\n\t};\n}\n\nfunction scheduleChunk(chunk: string, tokensPerSecond: number | undefined): Promise<void> {\n\tif (!tokensPerSecond || tokensPerSecond <= 0) {\n\t\treturn new Promise((resolve) => queueMicrotask(resolve));\n\t}\n\tconst delayMs = (estimateTokens(chunk) / tokensPerSecond) * 1000;\n\treturn new Promise((resolve) => setTimeout(resolve, delayMs));\n}\n\nasync function streamWithDeltas(\n\tstream: AssistantMessageEventStream,\n\tmessage: AssistantMessage,\n\tminTokenSize: number,\n\tmaxTokenSize: number,\n\ttokensPerSecond: number | undefined,\n\tsignal: AbortSignal | undefined,\n): Promise<void> {\n\tconst partial: AssistantMessage = { ...message, content: [] };\n\tif (signal?.aborted) {\n\t\tconst aborted = createAbortedMessage(partial);\n\t\tstream.push({ type: \"error\", reason: \"aborted\", error: aborted });\n\t\tstream.end(aborted);\n\t\treturn;\n\t}\n\n\tstream.push({ type: \"start\", partial: { ...partial } });\n\n\tfor (let index = 0; index < message.content.length; index++) {\n\t\tif (signal?.aborted) {\n\t\t\tconst aborted = createAbortedMessage(partial);\n\t\t\tstream.push({ type: \"error\", reason: \"aborted\", error: aborted });\n\t\t\tstream.end(aborted);\n\t\t\treturn;\n\t\t}\n\n\t\tconst block = message.content[index];\n\n\t\tif (block.type === \"thinking\") {\n\t\t\tpartial.content = [...partial.content, { type: \"thinking\", thinking: \"\" }];\n\t\t\tstream.push({ type: \"thinking_start\", contentIndex: index, partial: { ...partial } });\n\t\t\tfor (const chunk of splitStringByTokenSize(block.thinking, minTokenSize, maxTokenSize)) {\n\t\t\t\tawait scheduleChunk(chunk, tokensPerSecond);\n\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\tconst aborted = createAbortedMessage(partial);\n\t\t\t\t\tstream.push({ type: \"error\", reason: \"aborted\", error: aborted });\n\t\t\t\t\tstream.end(aborted);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t(partial.content[index] as ThinkingContent).thinking += chunk;\n\t\t\t\tstream.push({ type: \"thinking_delta\", contentIndex: index, delta: chunk, partial: { ...partial } });\n\t\t\t}\n\t\t\tstream.push({\n\t\t\t\ttype: \"thinking_end\",\n\t\t\t\tcontentIndex: index,\n\t\t\t\tcontent: block.thinking,\n\t\t\t\tpartial: { ...partial },\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (block.type === \"text\") {\n\t\t\tpartial.content = [...partial.content, { type: \"text\", text: \"\" }];\n\t\t\tstream.push({ type: \"text_start\", contentIndex: index, partial: { ...partial } });\n\t\t\tfor (const chunk of splitStringByTokenSize(block.text, minTokenSize, maxTokenSize)) {\n\t\t\t\tawait scheduleChunk(chunk, tokensPerSecond);\n\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\tconst aborted = createAbortedMessage(partial);\n\t\t\t\t\tstream.push({ type: \"error\", reason: \"aborted\", error: aborted });\n\t\t\t\t\tstream.end(aborted);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t(partial.content[index] as TextContent).text += chunk;\n\t\t\t\tstream.push({ type: \"text_delta\", contentIndex: index, delta: chunk, partial: { ...partial } });\n\t\t\t}\n\t\t\tstream.push({ type: \"text_end\", contentIndex: index, content: block.text, partial: { ...partial } });\n\t\t\tcontinue;\n\t\t}\n\n\t\tpartial.content = [...partial.content, { type: \"toolCall\", id: block.id, name: block.name, arguments: {} }];\n\t\tstream.push({ type: \"toolcall_start\", contentIndex: index, partial: { ...partial } });\n\t\tfor (const chunk of splitStringByTokenSize(JSON.stringify(block.arguments), minTokenSize, maxTokenSize)) {\n\t\t\tawait scheduleChunk(chunk, tokensPerSecond);\n\t\t\tif (signal?.aborted) {\n\t\t\t\tconst aborted = createAbortedMessage(partial);\n\t\t\t\tstream.push({ type: \"error\", reason: \"aborted\", error: aborted });\n\t\t\t\tstream.end(aborted);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tstream.push({ type: \"toolcall_delta\", contentIndex: index, delta: chunk, partial: { ...partial } });\n\t\t}\n\t\t(partial.content[index] as ToolCall).arguments = block.arguments;\n\t\tstream.push({ type: \"toolcall_end\", contentIndex: index, toolCall: block, partial: { ...partial } });\n\t}\n\n\tif (message.stopReason === \"error\" || message.stopReason === \"aborted\") {\n\t\tstream.push({ type: \"error\", reason: message.stopReason, error: message });\n\t\tstream.end(message);\n\t\treturn;\n\t}\n\n\tstream.push({ type: \"done\", reason: message.stopReason, message });\n\tstream.end(message);\n}\n\nexport function createFauxCore(options: RegisterFauxProviderOptions) {\n\tconst api = options.api ?? randomId(DEFAULT_API);\n\tconst provider = options.provider ?? DEFAULT_PROVIDER;\n\tconst minTokenSize = Math.max(\n\t\t1,\n\t\tMath.min(options.tokenSize?.min ?? DEFAULT_MIN_TOKEN_SIZE, options.tokenSize?.max ?? DEFAULT_MAX_TOKEN_SIZE),\n\t);\n\tconst maxTokenSize = Math.max(minTokenSize, options.tokenSize?.max ?? DEFAULT_MAX_TOKEN_SIZE);\n\tlet pendingResponses: FauxResponseStep[] = [];\n\tconst tokensPerSecond = options.tokensPerSecond;\n\tconst state = { callCount: 0 };\n\tconst promptCache = new Map<string, string>();\n\n\tconst modelDefinitions = options.models?.length\n\t\t? options.models\n\t\t: [\n\t\t\t\t{\n\t\t\t\t\tid: DEFAULT_MODEL_ID,\n\t\t\t\t\tname: DEFAULT_MODEL_NAME,\n\t\t\t\t\treasoning: false,\n\t\t\t\t\tinput: [\"text\", \"image\"] as (\"text\" | \"image\")[],\n\t\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\t\t\t\tcontextWindow: 128000,\n\t\t\t\t\tmaxTokens: 16384,\n\t\t\t\t},\n\t\t\t];\n\tconst models = modelDefinitions.map((definition) => ({\n\t\tid: definition.id,\n\t\tname: definition.name ?? definition.id,\n\t\tapi,\n\t\tprovider,\n\t\tbaseUrl: DEFAULT_BASE_URL,\n\t\treasoning: definition.reasoning ?? false,\n\t\tinput: definition.input ?? [\"text\", \"image\"],\n\t\tcost: definition.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tcontextWindow: definition.contextWindow ?? 128000,\n\t\tmaxTokens: definition.maxTokens ?? 16384,\n\t})) as [Model<string>, ...Model<string>[]];\n\n\tconst stream: StreamFunction<string, StreamOptions> = (requestModel, context, streamOptions) => {\n\t\tconst outer = createAssistantMessageEventStream();\n\t\tconst step = pendingResponses.shift();\n\t\tstate.callCount++;\n\n\t\tqueueMicrotask(async () => {\n\t\t\ttry {\n\t\t\t\tawait streamOptions?.onResponse?.({ status: 200, headers: {} }, requestModel);\n\t\t\t\tif (!step) {\n\t\t\t\t\tlet message = createErrorMessage(\n\t\t\t\t\t\tnew Error(\"No more faux responses queued\"),\n\t\t\t\t\t\tapi,\n\t\t\t\t\t\tprovider,\n\t\t\t\t\t\trequestModel.id,\n\t\t\t\t\t);\n\t\t\t\t\tmessage = withUsageEstimate(message, context, streamOptions, promptCache);\n\t\t\t\t\touter.push({ type: \"error\", reason: \"error\", error: message });\n\t\t\t\t\touter.end(message);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst resolved =\n\t\t\t\t\ttypeof step === \"function\" ? await step(context, streamOptions, state, requestModel) : step;\n\t\t\t\tlet message = cloneMessage(resolved, api, provider, requestModel.id);\n\t\t\t\tmessage = withUsageEstimate(message, context, streamOptions, promptCache);\n\t\t\t\tawait streamWithDeltas(outer, message, minTokenSize, maxTokenSize, tokensPerSecond, streamOptions?.signal);\n\t\t\t} catch (error) {\n\t\t\t\tconst message = createErrorMessage(error, api, provider, requestModel.id);\n\t\t\t\touter.push({ type: \"error\", reason: \"error\", error: message });\n\t\t\t\touter.end(message);\n\t\t\t}\n\t\t});\n\n\t\treturn outer;\n\t};\n\n\tconst streamSimple: StreamFunction<string, SimpleStreamOptions> = (streamModel, context, streamOptions) =>\n\t\tstream(streamModel, context, streamOptions);\n\n\tfunction getModel(): Model<string>;\n\tfunction getModel(requestedModelId: string): Model<string> | undefined;\n\tfunction getModel(requestedModelId?: string): Model<string> | undefined {\n\t\tif (!requestedModelId) {\n\t\t\treturn models[0];\n\t\t}\n\t\treturn models.find((candidate) => candidate.id === requestedModelId);\n\t}\n\n\treturn {\n\t\tapi,\n\t\tprovider,\n\t\tmodels,\n\t\tstream,\n\t\tstreamSimple,\n\t\tgetModel,\n\t\tstate,\n\t\tsetResponses(responses: FauxResponseStep[]) {\n\t\t\tpendingResponses = [...responses];\n\t\t},\n\t\tappendResponses(responses: FauxResponseStep[]) {\n\t\t\tpendingResponses.push(...responses);\n\t\t},\n\t\tgetPendingResponseCount() {\n\t\t\treturn pendingResponses.length;\n\t\t},\n\t};\n}\n\n/**\n * Faux provider for tests built on explicit `Models` collections:\n *\n * ```ts\n * const faux = fauxProvider();\n * const models = createModels();\n * models.setProvider(faux.provider);\n * faux.setResponses([fauxAssistantMessage(\"hi\")]);\n * ```\n */\nexport function fauxProvider(options: RegisterFauxProviderOptions = {}): FauxProviderHandle {\n\tconst core = createFauxCore(options);\n\tconst provider = createProvider({\n\t\tid: core.provider,\n\t\tauth: { apiKey: { name: \"Faux\", resolve: async () => ({ auth: {} }) } },\n\t\tmodels: core.models,\n\t\tapi: { stream: core.stream, streamSimple: core.streamSimple },\n\t});\n\treturn {\n\t\tprovider,\n\t\tapi: core.api,\n\t\tmodels: core.models,\n\t\tgetModel: core.getModel,\n\t\tstate: core.state,\n\t\tsetResponses: core.setResponses,\n\t\tappendResponses: core.appendResponses,\n\t\tgetPendingResponseCount: core.getPendingResponseCount,\n\t};\n}\n"]}
|
package/dist/providers/faux.js
CHANGED
|
@@ -128,16 +128,20 @@ function withUsageEstimate(message, context, options, promptCache) {
|
|
|
128
128
|
const cachedChars = commonPrefixLength(previousPrompt, promptText);
|
|
129
129
|
cacheRead = estimateTokens(previousPrompt.slice(0, cachedChars));
|
|
130
130
|
cacheWrite = estimateTokens(promptText.slice(cachedChars));
|
|
131
|
-
|
|
131
|
+
cacheWrite = Math.max(0, promptTokens - cacheRead);
|
|
132
|
+
input = 0;
|
|
132
133
|
}
|
|
133
134
|
else {
|
|
134
135
|
cacheWrite = promptTokens;
|
|
136
|
+
input = 0;
|
|
135
137
|
}
|
|
136
138
|
promptCache.set(sessionId, promptText);
|
|
137
139
|
}
|
|
138
140
|
return {
|
|
139
141
|
...message,
|
|
140
142
|
usage: {
|
|
143
|
+
measurement: "estimated",
|
|
144
|
+
costSource: "estimated",
|
|
141
145
|
input,
|
|
142
146
|
output: outputTokens,
|
|
143
147
|
cacheRead,
|