@code-yeongyu/senpi-ai 2026.8.12 → 2026.8.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -8
- package/dist/api/anthropic-messages.js.map +1 -1
- package/dist/api/azure-openai-responses.js +5 -1
- package/dist/api/azure-openai-responses.js.map +1 -1
- package/dist/api/bedrock-converse-stream.js.map +1 -1
- package/dist/api/bedrock-converse-stream.lazy.js.map +1 -1
- package/dist/api/google-generative-ai.d.ts.map +1 -1
- package/dist/api/google-generative-ai.js +2 -2
- package/dist/api/google-generative-ai.js.map +1 -1
- package/dist/api/google-shared.d.ts +15 -1
- package/dist/api/google-shared.d.ts.map +1 -1
- package/dist/api/google-shared.js +103 -4
- package/dist/api/google-shared.js.map +1 -1
- package/dist/api/google-vertex.d.ts.map +1 -1
- package/dist/api/google-vertex.js +2 -2
- package/dist/api/google-vertex.js.map +1 -1
- package/dist/api/lazy.d.ts +5 -1
- package/dist/api/lazy.d.ts.map +1 -1
- package/dist/api/lazy.js +19 -7
- package/dist/api/lazy.js.map +1 -1
- package/dist/api/openai-codex-responses.js.map +1 -1
- package/dist/api/openai-completions.d.ts +3 -1
- package/dist/api/openai-completions.d.ts.map +1 -1
- package/dist/api/openai-completions.js +47 -7
- 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 +22 -9
- package/dist/api/openai-responses-shared.js.map +1 -1
- package/dist/api/openai-responses.js +5 -1
- package/dist/api/openai-responses.js.map +1 -1
- package/dist/api/pi-messages.d.ts.map +1 -1
- package/dist/api/pi-messages.js.map +1 -1
- package/dist/api/simple-options.d.ts +2 -0
- package/dist/api/simple-options.d.ts.map +1 -1
- package/dist/api/simple-options.js +8 -2
- package/dist/api/simple-options.js.map +1 -1
- package/dist/api/transform-messages.js.map +1 -1
- package/dist/api/warm-prompt-cache.js.map +1 -1
- package/dist/auth/credential-store.d.ts +6 -6
- package/dist/auth/credential-store.d.ts.map +1 -1
- package/dist/auth/credential-store.js +22 -11
- package/dist/auth/credential-store.js.map +1 -1
- package/dist/auth/helpers.d.ts +1 -0
- package/dist/auth/helpers.d.ts.map +1 -1
- package/dist/auth/helpers.js +7 -2
- package/dist/auth/helpers.js.map +1 -1
- package/dist/auth/oauth/anthropic.d.ts.map +1 -1
- package/dist/auth/oauth/anthropic.js +14 -8
- package/dist/auth/oauth/anthropic.js.map +1 -1
- package/dist/auth/oauth/device-code.d.ts +1 -1
- package/dist/auth/oauth/device-code.d.ts.map +1 -1
- package/dist/auth/oauth/device-code.js +4 -4
- package/dist/auth/oauth/device-code.js.map +1 -1
- package/dist/auth/oauth/github-copilot.d.ts.map +1 -1
- package/dist/auth/oauth/github-copilot.js +43 -30
- package/dist/auth/oauth/github-copilot.js.map +1 -1
- package/dist/auth/oauth/kimi-coding.d.ts.map +1 -1
- package/dist/auth/oauth/kimi-coding.js +17 -5
- package/dist/auth/oauth/kimi-coding.js.map +1 -1
- package/dist/auth/oauth/load.d.ts.map +1 -1
- package/dist/auth/oauth/load.js.map +1 -1
- package/dist/auth/oauth/openai-codex.d.ts.map +1 -1
- package/dist/auth/oauth/openai-codex.js +12 -5
- package/dist/auth/oauth/openai-codex.js.map +1 -1
- package/dist/auth/oauth/openrouter.d.ts.map +1 -1
- package/dist/auth/oauth/openrouter.js +10 -10
- package/dist/auth/oauth/openrouter.js.map +1 -1
- package/dist/auth/oauth/radius.d.ts.map +1 -1
- package/dist/auth/oauth/radius.js +8 -7
- package/dist/auth/oauth/radius.js.map +1 -1
- package/dist/auth/oauth/xai.d.ts.map +1 -1
- package/dist/auth/oauth/xai.js +3 -2
- package/dist/auth/oauth/xai.js.map +1 -1
- package/dist/auth/resolve.d.ts +1 -0
- package/dist/auth/resolve.d.ts.map +1 -1
- package/dist/auth/resolve.js +24 -13
- package/dist/auth/resolve.js.map +1 -1
- package/dist/auth/types.d.ts +21 -8
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth/types.js.map +1 -1
- package/dist/cli.js +1 -0
- package/dist/cli.js.map +1 -1
- package/dist/compat.js.map +1 -1
- package/dist/env-api-keys.d.ts.map +1 -1
- package/dist/env-api-keys.js +3 -0
- package/dist/env-api-keys.js.map +1 -1
- package/dist/image-models.generated.d.ts +69 -54
- package/dist/image-models.generated.d.ts.map +1 -1
- package/dist/image-models.generated.js +15 -0
- package/dist/image-models.generated.js.map +1 -1
- package/dist/images-models.d.ts.map +1 -1
- package/dist/images-models.js +1 -0
- package/dist/images-models.js.map +1 -1
- package/dist/model.d.ts +2 -0
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js.map +1 -1
- package/dist/models-store.d.ts +9 -12
- package/dist/models-store.d.ts.map +1 -1
- package/dist/models-store.js +6 -3
- package/dist/models-store.js.map +1 -1
- package/dist/models.d.ts +40 -18
- package/dist/models.d.ts.map +1 -1
- package/dist/models.generated.d.ts +6 -0
- package/dist/models.generated.d.ts.map +1 -1
- package/dist/models.generated.js +6 -0
- package/dist/models.generated.js.map +1 -1
- package/dist/models.js +247 -91
- package/dist/models.js.map +1 -1
- package/dist/node/provider-scope.d.ts.map +1 -1
- package/dist/providers/all.d.ts.map +1 -1
- package/dist/providers/all.js +6 -0
- package/dist/providers/all.js.map +1 -1
- package/dist/providers/amazon-bedrock.d.ts.map +1 -1
- package/dist/providers/amazon-bedrock.js +15 -7
- package/dist/providers/amazon-bedrock.js.map +1 -1
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +15 -6
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/baseten.d.ts +3 -0
- package/dist/providers/baseten.d.ts.map +1 -0
- package/dist/providers/baseten.js +15 -0
- package/dist/providers/baseten.js.map +1 -0
- package/dist/providers/baseten.models.d.ts +4 -0
- package/dist/providers/baseten.models.d.ts.map +1 -0
- package/dist/providers/baseten.models.js +6 -0
- package/dist/providers/baseten.models.js.map +1 -0
- package/dist/providers/cloudflare-auth.d.ts.map +1 -1
- package/dist/providers/cloudflare-auth.js +15 -10
- package/dist/providers/cloudflare-auth.js.map +1 -1
- package/dist/providers/data/.manifest.json +1 -1
- package/dist/providers/data/baseten.json +1 -0
- package/dist/providers/data/fireworks.json +1 -1
- package/dist/providers/data/github-copilot.json +1 -1
- package/dist/providers/data/opencode-go.json +1 -1
- package/dist/providers/data/opencode.json +1 -1
- package/dist/providers/data/opengateway.json +1 -0
- package/dist/providers/data/openrouter.json +1 -1
- package/dist/providers/data/qwen-token-plan-cn.json +1 -1
- package/dist/providers/data/qwen-token-plan-individual.json +1 -0
- package/dist/providers/data/qwen-token-plan.json +1 -1
- package/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/providers/data/xai.json +1 -1
- package/dist/providers/faux.d.ts +18 -13
- package/dist/providers/faux.d.ts.map +1 -1
- package/dist/providers/faux.js +95 -5
- package/dist/providers/faux.js.map +1 -1
- package/dist/providers/github-copilot.js +1 -1
- package/dist/providers/github-copilot.js.map +1 -1
- package/dist/providers/google-vertex.d.ts.map +1 -1
- package/dist/providers/google-vertex.js +15 -7
- package/dist/providers/google-vertex.js.map +1 -1
- package/dist/providers/kimi-coding.d.ts.map +1 -1
- package/dist/providers/kimi-coding.js +1 -0
- package/dist/providers/kimi-coding.js.map +1 -1
- package/dist/providers/ollama.d.ts.map +1 -1
- package/dist/providers/ollama.js +1 -2
- package/dist/providers/ollama.js.map +1 -1
- package/dist/providers/openai-codex.d.ts.map +1 -1
- package/dist/providers/openai-codex.js +5 -1
- package/dist/providers/openai-codex.js.map +1 -1
- package/dist/providers/opengateway.d.ts +3 -0
- package/dist/providers/opengateway.d.ts.map +1 -0
- package/dist/providers/opengateway.js +15 -0
- package/dist/providers/opengateway.js.map +1 -0
- package/dist/providers/opengateway.models.d.ts +4 -0
- package/dist/providers/opengateway.models.d.ts.map +1 -0
- package/dist/providers/opengateway.models.js +6 -0
- package/dist/providers/opengateway.models.js.map +1 -0
- package/dist/providers/qwen-token-plan-individual.d.ts +3 -0
- package/dist/providers/qwen-token-plan-individual.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual.js +15 -0
- package/dist/providers/qwen-token-plan-individual.js.map +1 -0
- package/dist/providers/qwen-token-plan-individual.models.d.ts +4 -0
- package/dist/providers/qwen-token-plan-individual.models.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual.models.js +6 -0
- package/dist/providers/qwen-token-plan-individual.models.js.map +1 -0
- package/dist/providers/radius.d.ts.map +1 -1
- package/dist/providers/radius.js +36 -26
- package/dist/providers/radius.js.map +1 -1
- package/dist/providers/xai.d.ts.map +1 -1
- package/dist/providers/xai.js +1 -0
- package/dist/providers/xai.js.map +1 -1
- package/dist/tool-call-middleware/context-transformer.js.map +1 -1
- package/dist/tool-call-middleware/protocols/anthropic-xml/recovery-wrapper-state.d.ts.map +1 -1
- package/dist/tool-call-middleware/protocols/kimi-xtml/parse.js.map +1 -1
- package/dist/tool-call-middleware/recovery-content-lifecycle.d.ts.map +1 -1
- package/dist/tool-call-middleware/recovery-event-stream.d.ts.map +1 -1
- package/dist/tool-call-middleware/recovery-native-projection.d.ts.map +1 -1
- package/dist/tool-call-middleware/recovery-native-projection.js.map +1 -1
- package/dist/tool-call-middleware/recovery-stream-terminal.d.ts.map +1 -1
- package/dist/tool-call-middleware/recovery-stream-wrapper.d.ts.map +1 -1
- package/dist/tool-call-middleware/recovery-stream-wrapper.js +5 -0
- package/dist/tool-call-middleware/recovery-stream-wrapper.js.map +1 -1
- package/dist/tool-call-middleware/recovery-text-projection.d.ts.map +1 -1
- package/dist/tool-call-middleware/recovery-text-projection.js.map +1 -1
- package/dist/tool-call-middleware/stream-thinking-projection.d.ts.map +1 -1
- package/dist/tool-call-middleware/stream-wrapper-shared.d.ts.map +1 -1
- package/dist/tool-call-middleware/stream-wrapper-shared.js.map +1 -1
- package/dist/tool-call-middleware/stream-wrapper.js.map +1 -1
- package/dist/types.d.ts +94 -87
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/abort.d.ts +8 -0
- package/dist/utils/abort.d.ts.map +1 -0
- package/dist/utils/abort.js +49 -0
- package/dist/utils/abort.js.map +1 -0
- package/dist/utils/deferred-tools.js.map +1 -1
- package/dist/utils/event-stream.d.ts.map +1 -1
- package/dist/utils/overflow.d.ts +14 -1
- package/dist/utils/overflow.d.ts.map +1 -1
- package/dist/utils/overflow.js +18 -1
- package/dist/utils/overflow.js.map +1 -1
- package/dist/utils/prompt-cache-ttl.d.ts +3 -1
- package/dist/utils/prompt-cache-ttl.d.ts.map +1 -1
- package/dist/utils/prompt-cache-ttl.js +2 -0
- package/dist/utils/prompt-cache-ttl.js.map +1 -1
- package/dist/utils/provider-retry.js.map +1 -1
- package/dist/utils/retry.d.ts +25 -0
- package/dist/utils/retry.d.ts.map +1 -1
- package/dist/utils/retry.js +64 -0
- package/dist/utils/retry.js.map +1 -1
- package/dist/utils/tool-schema-compat.d.ts.map +1 -1
- package/dist/utils/tool-schema-compat.js +1 -0
- package/dist/utils/tool-schema-compat.js.map +1 -1
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +6 -0
- package/dist/utils/validation.js.map +1 -1
- package/package.json +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ollama.d.ts","sourceRoot":"","sources":["../../src/providers/ollama.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,QAAQ,EAA6B,MAAM,cAAc,CAAC;AAGxF,eAAO,MAAM,wBAAwB,uBAAuB,CAAC;AAC7D,eAAO,MAAM,6BAA6B,SAAS,CAAC;AACpD,eAAO,MAAM,yBAAyB,QAAQ,CAAC;AAG/C,MAAM,WAAW,qBAAqB;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;
|
|
1
|
+
{"version":3,"file":"ollama.d.ts","sourceRoot":"","sources":["../../src/providers/ollama.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,QAAQ,EAA6B,MAAM,cAAc,CAAC;AAGxF,eAAO,MAAM,wBAAwB,uBAAuB,CAAC;AAC7D,eAAO,MAAM,6BAA6B,SAAS,CAAC;AACpD,eAAO,MAAM,yBAAyB,QAAQ,CAAC;AAG/C,MAAM,WAAW,qBAAqB;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAwJD,wBAAgB,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,QAAQ,CAAC,oBAAoB,CAAC,CAWlG"}
|
package/dist/providers/ollama.js
CHANGED
|
@@ -113,8 +113,7 @@ async function fetchOllamaModels(host, context) {
|
|
|
113
113
|
}
|
|
114
114
|
if (tags.length > 0 && rejected.length === tags.length)
|
|
115
115
|
throw rejected[0].reason;
|
|
116
|
-
const
|
|
117
|
-
const previousById = new Map((stored?.models ?? [])
|
|
116
|
+
const previousById = new Map((context.stored?.models ?? [])
|
|
118
117
|
.filter((model) => model.provider === "ollama" && model.api === "openai-completions")
|
|
119
118
|
.map((model) => [model.id, model]));
|
|
120
119
|
const models = inspections.flatMap((inspection) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ollama.js","sourceRoot":"","sources":["../../src/providers/ollama.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAA4C,MAAM,cAAc,CAAC;AAGxF,MAAM,CAAC,MAAM,wBAAwB,GAAG,oBAAoB,CAAC;AAC7D,MAAM,CAAC,MAAM,6BAA6B,GAAG,MAAM,CAAC;AACpD,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,CAAC;AAC/C,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAelC,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,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F,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QACjD,IAAI,UAAU,CAAC,MAAM,KAAK,WAAW;YAAE,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACzF,MAAM,QAAQ,GAAG,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACzD,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACnC,CAAC,CAAC,CAAC;IACH,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,QAAQ,CAAC,CAAC,CAAE,CAAC,MAAM,CAAC;IAC1E,OAAO,MAAM,CAAC;AACf,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAO,GAA0B,EAAE;IACjE,MAAM,IAAI,GAAG,mBAAmB,CAAC,OAAO,CAAC,OAAO,IAAI,wBAAwB,CAAC,CAAC;IAC9E,OAAO,cAAc,CAAC;QACrB,EAAE,EAAE,QAAQ;QACZ,IAAI,EAAE,cAAc;QACpB,OAAO,EAAE,GAAG,IAAI,KAAK;QACrB,IAAI,EAAE,EAAE,MAAM,EAAE,aAAa,CAAC,gBAAgB,EAAE,CAAC,gBAAgB,CAAC,CAAC,EAAE;QACrE,MAAM,EAAE,EAAE;QACV,WAAW,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,EAAE,OAAO,CAAC;QAC1D,GAAG,EAAE,oBAAoB,EAAE;KAC3B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { openAICompletionsApi } from \"../api/openai-completions.lazy.ts\";\nimport { envApiKeyAuth } from \"../auth/helpers.ts\";\nimport { createProvider, type Provider, type RefreshModelsContext } from \"../models.ts\";\nimport type { Model } from \"../types.ts\";\n\nexport const DEFAULT_OLLAMA_CLOUD_URL = \"https://ollama.com\";\nexport const DEFAULT_OLLAMA_CONTEXT_WINDOW = 128000;\nexport const DEFAULT_OLLAMA_MAX_TOKENS = 16384;\nconst OLLAMA_SHOW_CONCURRENCY = 6;\n\nexport interface OllamaProviderOptions {\n\tbaseUrl?: string;\n}\n\ntype OllamaTagsModel = {\n\tname: string;\n};\n\ntype OllamaShowResponse = {\n\tcapabilities: string[];\n\tmodelInfo: Record<string, unknown>;\n};\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction normalizeOllamaHost(value: string): string {\n\tconst host = new URL(value);\n\thost.pathname = host.pathname.replace(/\\/v1\\/?$/u, \"\");\n\treturn host.toString().replace(/\\/$/u, \"\");\n}\n\nasync function fetchOllamaJson(\n\turl: URL,\n\tapiKey: string,\n\tsignal: AbortSignal | undefined,\n\tinit?: RequestInit,\n): Promise<unknown> {\n\tconst response = await fetch(url, {\n\t\t...init,\n\t\theaders: {\n\t\t\taccept: \"application/json\",\n\t\t\tauthorization: `Bearer ${apiKey}`,\n\t\t\t...init?.headers,\n\t\t},\n\t\tsignal,\n\t});\n\tif (!response.ok) {\n\t\tthrow new Error(`Could not load Ollama catalog from ${url}: ${response.status}`);\n\t}\n\treturn response.json();\n}\n\nfunction parseTagsResponse(value: unknown): OllamaTagsModel[] {\n\tif (!isRecord(value) || !Array.isArray(value.models)) {\n\t\tthrow new Error(\"Invalid Ollama tags response\");\n\t}\n\tconst models: OllamaTagsModel[] = [];\n\tfor (const entry of value.models) {\n\t\tif (!isRecord(entry)) continue;\n\t\tconst name =\n\t\t\ttypeof entry.name === \"string\" ? entry.name : typeof entry.model === \"string\" ? entry.model : undefined;\n\t\tif (name) models.push({ name });\n\t}\n\treturn models;\n}\n\nfunction parseShowResponse(value: unknown): OllamaShowResponse {\n\tif (!isRecord(value) || !Array.isArray(value.capabilities)) {\n\t\tthrow new Error(\"Invalid Ollama show response\");\n\t}\n\treturn {\n\t\tcapabilities: value.capabilities.filter((entry): entry is string => typeof entry === \"string\"),\n\t\tmodelInfo: isRecord(value.model_info) ? value.model_info : {},\n\t};\n}\n\nfunction getContextWindow(modelInfo: Record<string, unknown>): number {\n\tconst architecture = modelInfo[\"general.architecture\"];\n\tconst preferred = typeof architecture === \"string\" ? modelInfo[`${architecture}.context_length`] : undefined;\n\tconst candidate = preferred ?? Object.entries(modelInfo).find(([key]) => key.endsWith(\".context_length\"))?.[1];\n\tconst parsed = typeof candidate === \"number\" ? candidate : Number(candidate);\n\treturn Number.isFinite(parsed) && parsed > 0 ? parsed : DEFAULT_OLLAMA_CONTEXT_WINDOW;\n}\n\nfunction toOllamaModel(\n\thost: string,\n\tentry: OllamaTagsModel,\n\tshow: OllamaShowResponse,\n): Model<\"openai-completions\"> | undefined {\n\tif (!show.capabilities.includes(\"tools\")) return undefined;\n\treturn {\n\t\tid: entry.name,\n\t\tname: entry.name,\n\t\tapi: \"openai-completions\",\n\t\tprovider: \"ollama\",\n\t\tbaseUrl: `${host}/v1`,\n\t\treasoning: show.capabilities.includes(\"thinking\"),\n\t\tinput: show.capabilities.includes(\"vision\") ? [\"text\", \"image\"] : [\"text\"],\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tcontextWindow: getContextWindow(show.modelInfo),\n\t\tmaxTokens: DEFAULT_OLLAMA_MAX_TOKENS,\n\t\tcompat: {\n\t\t\tsupportsStore: false,\n\t\t\tsupportsDeveloperRole: false,\n\t\t\tsupportsReasoningEffort: true,\n\t\t\tmaxTokensField: \"max_tokens\",\n\t\t\tsupportsStrictMode: false,\n\t\t\tsupportsLongCacheRetention: false,\n\t\t},\n\t};\n}\n\nasync function fetchOllamaModels(host: string, context: RefreshModelsContext): Promise<Model<\"openai-completions\">[]> {\n\tconst apiKey = context.credential?.type === \"api_key\" ? context.credential.key : undefined;\n\tif (!apiKey) return [];\n\tconst tags = parseTagsResponse(await fetchOllamaJson(new URL(\"/api/tags\", host), apiKey, context.signal));\n\ttype Inspection =\n\t\t| { status: \"fulfilled\"; entry: OllamaTagsModel; model: Model<\"openai-completions\"> | undefined }\n\t\t| { status: \"rejected\"; entry: OllamaTagsModel; reason: unknown };\n\tconst inspections: Inspection[] = new Array(tags.length);\n\tlet nextIndex = 0;\n\tconst inspectNext = async (): Promise<void> => {\n\t\twhile (nextIndex < tags.length) {\n\t\t\tconst index = nextIndex++;\n\t\t\tconst entry = tags[index]!;\n\t\t\ttry {\n\t\t\t\tconst show = parseShowResponse(\n\t\t\t\t\tawait fetchOllamaJson(new URL(\"/api/show\", host), apiKey, context.signal, {\n\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\theaders: { \"content-type\": \"application/json\" },\n\t\t\t\t\t\tbody: JSON.stringify({ model: entry.name }),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tinspections[index] = { status: \"fulfilled\", entry, model: toOllamaModel(host, entry, show) };\n\t\t\t} catch (reason) {\n\t\t\t\tinspections[index] = { status: \"rejected\", entry, reason };\n\t\t\t}\n\t\t}\n\t};\n\tawait Promise.all(Array.from({ length: Math.min(OLLAMA_SHOW_CONCURRENCY, tags.length) }, () => inspectNext()));\n\tconst rejected = inspections.filter((inspection) => inspection.status === \"rejected\");\n\tif (context.signal?.aborted) {\n\t\tthrow rejected[0]?.reason ?? context.signal.reason ?? new Error(\"Ollama catalog refresh aborted\");\n\t}\n\tif (tags.length > 0 && rejected.length === tags.length) throw rejected[0]!.reason;\n\tconst stored = rejected.length > 0 ? await context.store.read() : undefined;\n\tconst previousById = new Map(\n\t\t(stored?.models ?? [])\n\t\t\t.filter(\n\t\t\t\t(model): model is Model<\"openai-completions\"> =>\n\t\t\t\t\tmodel.provider === \"ollama\" && model.api === \"openai-completions\",\n\t\t\t)\n\t\t\t.map((model) => [model.id, model]),\n\t);\n\tconst models = inspections.flatMap((inspection) => {\n\t\tif (inspection.status === \"fulfilled\") return inspection.model ? [inspection.model] : [];\n\t\tconst previous = previousById.get(inspection.entry.name);\n\t\treturn previous ? [previous] : [];\n\t});\n\tif (rejected.length > 0 && models.length === 0) throw rejected[0]!.reason;\n\treturn models;\n}\n\nexport function ollamaProvider(options: OllamaProviderOptions = {}): Provider<\"openai-completions\"> {\n\tconst host = normalizeOllamaHost(options.baseUrl ?? DEFAULT_OLLAMA_CLOUD_URL);\n\treturn createProvider({\n\t\tid: \"ollama\",\n\t\tname: \"Ollama Cloud\",\n\t\tbaseUrl: `${host}/v1`,\n\t\tauth: { apiKey: envApiKeyAuth(\"Ollama API key\", [\"OLLAMA_API_KEY\"]) },\n\t\tmodels: [],\n\t\tfetchModels: (context) => fetchOllamaModels(host, context),\n\t\tapi: openAICompletionsApi(),\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ollama.js","sourceRoot":"","sources":["../../src/providers/ollama.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAA4C,MAAM,cAAc,CAAC;AAGxF,MAAM,CAAC,MAAM,wBAAwB,GAAG,oBAAoB,CAAC;AAC7D,MAAM,CAAC,MAAM,6BAA6B,GAAG,MAAM,CAAC;AACpD,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,CAAC;AAC/C,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAelC,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAa;IACzC,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;IAC5B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QA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,IAAI,CAAC,CAAC;QACzD,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACnC,CAAC,CAAC,CAAC;IACH,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,QAAQ,CAAC,CAAC,CAAE,CAAC,MAAM,CAAC;IAC1E,OAAO,MAAM,CAAC;AACf,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,UAAiC,EAAE;IACjE,MAAM,IAAI,GAAG,mBAAmB,CAAC,OAAO,CAAC,OAAO,IAAI,wBAAwB,CAAC,CAAC;IAC9E,OAAO,cAAc,CAAC;QACrB,EAAE,EAAE,QAAQ;QACZ,IAAI,EAAE,cAAc;QACpB,OAAO,EAAE,GAAG,IAAI,KAAK;QACrB,IAAI,EAAE,EAAE,MAAM,EAAE,aAAa,CAAC,gBAAgB,EAAE,CAAC,gBAAgB,CAAC,CAAC,EAAE;QACrE,MAAM,EAAE,EAAE;QACV,WAAW,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,EAAE,OAAO,CAAC;QAC1D,GAAG,EAAE,oBAAoB,EAAE;KAC3B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { openAICompletionsApi } from \"../api/openai-completions.lazy.ts\";\nimport { envApiKeyAuth } from \"../auth/helpers.ts\";\nimport { createProvider, type Provider, type RefreshModelsContext } from \"../models.ts\";\nimport type { Model } from \"../types.ts\";\n\nexport const DEFAULT_OLLAMA_CLOUD_URL = \"https://ollama.com\";\nexport const DEFAULT_OLLAMA_CONTEXT_WINDOW = 128000;\nexport const DEFAULT_OLLAMA_MAX_TOKENS = 16384;\nconst OLLAMA_SHOW_CONCURRENCY = 6;\n\nexport interface OllamaProviderOptions {\n\tbaseUrl?: string;\n}\n\ntype OllamaTagsModel = {\n\tname: string;\n};\n\ntype OllamaShowResponse = {\n\tcapabilities: string[];\n\tmodelInfo: Record<string, unknown>;\n};\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction normalizeOllamaHost(value: string): string {\n\tconst host = new URL(value);\n\thost.pathname = host.pathname.replace(/\\/v1\\/?$/u, \"\");\n\treturn host.toString().replace(/\\/$/u, \"\");\n}\n\nasync function fetchOllamaJson(\n\turl: URL,\n\tapiKey: string,\n\tsignal: AbortSignal | undefined,\n\tinit?: RequestInit,\n): Promise<unknown> {\n\tconst response = await fetch(url, {\n\t\t...init,\n\t\theaders: {\n\t\t\taccept: \"application/json\",\n\t\t\tauthorization: `Bearer ${apiKey}`,\n\t\t\t...init?.headers,\n\t\t},\n\t\tsignal,\n\t});\n\tif (!response.ok) {\n\t\tthrow new Error(`Could not load Ollama catalog from ${url}: ${response.status}`);\n\t}\n\treturn response.json();\n}\n\nfunction parseTagsResponse(value: unknown): OllamaTagsModel[] {\n\tif (!isRecord(value) || !Array.isArray(value.models)) {\n\t\tthrow new Error(\"Invalid Ollama tags response\");\n\t}\n\tconst models: OllamaTagsModel[] = [];\n\tfor (const entry of value.models) {\n\t\tif (!isRecord(entry)) continue;\n\t\tconst name =\n\t\t\ttypeof entry.name === \"string\" ? entry.name : typeof entry.model === \"string\" ? entry.model : undefined;\n\t\tif (name) models.push({ name });\n\t}\n\treturn models;\n}\n\nfunction parseShowResponse(value: unknown): OllamaShowResponse {\n\tif (!isRecord(value) || !Array.isArray(value.capabilities)) {\n\t\tthrow new Error(\"Invalid Ollama show response\");\n\t}\n\treturn {\n\t\tcapabilities: value.capabilities.filter((entry): entry is string => typeof entry === \"string\"),\n\t\tmodelInfo: isRecord(value.model_info) ? value.model_info : {},\n\t};\n}\n\nfunction getContextWindow(modelInfo: Record<string, unknown>): number {\n\tconst architecture = modelInfo[\"general.architecture\"];\n\tconst preferred = typeof architecture === \"string\" ? modelInfo[`${architecture}.context_length`] : undefined;\n\tconst candidate = preferred ?? Object.entries(modelInfo).find(([key]) => key.endsWith(\".context_length\"))?.[1];\n\tconst parsed = typeof candidate === \"number\" ? candidate : Number(candidate);\n\treturn Number.isFinite(parsed) && parsed > 0 ? parsed : DEFAULT_OLLAMA_CONTEXT_WINDOW;\n}\n\nfunction toOllamaModel(\n\thost: string,\n\tentry: OllamaTagsModel,\n\tshow: OllamaShowResponse,\n): Model<\"openai-completions\"> | undefined {\n\tif (!show.capabilities.includes(\"tools\")) return undefined;\n\treturn {\n\t\tid: entry.name,\n\t\tname: entry.name,\n\t\tapi: \"openai-completions\",\n\t\tprovider: \"ollama\",\n\t\tbaseUrl: `${host}/v1`,\n\t\treasoning: show.capabilities.includes(\"thinking\"),\n\t\tinput: show.capabilities.includes(\"vision\") ? [\"text\", \"image\"] : [\"text\"],\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tcontextWindow: getContextWindow(show.modelInfo),\n\t\tmaxTokens: DEFAULT_OLLAMA_MAX_TOKENS,\n\t\tcompat: {\n\t\t\tsupportsStore: false,\n\t\t\tsupportsDeveloperRole: false,\n\t\t\tsupportsReasoningEffort: true,\n\t\t\tmaxTokensField: \"max_tokens\",\n\t\t\tsupportsStrictMode: false,\n\t\t\tsupportsLongCacheRetention: false,\n\t\t},\n\t};\n}\n\nasync function fetchOllamaModels(host: string, context: RefreshModelsContext): Promise<Model<\"openai-completions\">[]> {\n\tconst apiKey = context.credential?.type === \"api_key\" ? context.credential.key : undefined;\n\tif (!apiKey) return [];\n\tconst tags = parseTagsResponse(await fetchOllamaJson(new URL(\"/api/tags\", host), apiKey, context.signal));\n\ttype Inspection =\n\t\t| { status: \"fulfilled\"; entry: OllamaTagsModel; model: Model<\"openai-completions\"> | undefined }\n\t\t| { status: \"rejected\"; entry: OllamaTagsModel; reason: unknown };\n\tconst inspections: Inspection[] = new Array(tags.length);\n\tlet nextIndex = 0;\n\tconst inspectNext = async (): Promise<void> => {\n\t\twhile (nextIndex < tags.length) {\n\t\t\tconst index = nextIndex++;\n\t\t\tconst entry = tags[index]!;\n\t\t\ttry {\n\t\t\t\tconst show = parseShowResponse(\n\t\t\t\t\tawait fetchOllamaJson(new URL(\"/api/show\", host), apiKey, context.signal, {\n\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\theaders: { \"content-type\": \"application/json\" },\n\t\t\t\t\t\tbody: JSON.stringify({ model: entry.name }),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tinspections[index] = { status: \"fulfilled\", entry, model: toOllamaModel(host, entry, show) };\n\t\t\t} catch (reason) {\n\t\t\t\tinspections[index] = { status: \"rejected\", entry, reason };\n\t\t\t}\n\t\t}\n\t};\n\tawait Promise.all(Array.from({ length: Math.min(OLLAMA_SHOW_CONCURRENCY, tags.length) }, () => inspectNext()));\n\tconst rejected = inspections.filter((inspection) => inspection.status === \"rejected\");\n\tif (context.signal?.aborted) {\n\t\tthrow rejected[0]?.reason ?? context.signal.reason ?? new Error(\"Ollama catalog refresh aborted\");\n\t}\n\tif (tags.length > 0 && rejected.length === tags.length) throw rejected[0]!.reason;\n\tconst previousById = new Map(\n\t\t(context.stored?.models ?? [])\n\t\t\t.filter(\n\t\t\t\t(model): model is Model<\"openai-completions\"> =>\n\t\t\t\t\tmodel.provider === \"ollama\" && model.api === \"openai-completions\",\n\t\t\t)\n\t\t\t.map((model) => [model.id, model]),\n\t);\n\tconst models = inspections.flatMap((inspection) => {\n\t\tif (inspection.status === \"fulfilled\") return inspection.model ? [inspection.model] : [];\n\t\tconst previous = previousById.get(inspection.entry.name);\n\t\treturn previous ? [previous] : [];\n\t});\n\tif (rejected.length > 0 && models.length === 0) throw rejected[0]!.reason;\n\treturn models;\n}\n\nexport function ollamaProvider(options: OllamaProviderOptions = {}): Provider<\"openai-completions\"> {\n\tconst host = normalizeOllamaHost(options.baseUrl ?? DEFAULT_OLLAMA_CLOUD_URL);\n\treturn createProvider({\n\t\tid: \"ollama\",\n\t\tname: \"Ollama Cloud\",\n\t\tbaseUrl: `${host}/v1`,\n\t\tauth: { apiKey: envApiKeyAuth(\"Ollama API key\", [\"OLLAMA_API_KEY\"]) },\n\t\tmodels: [],\n\t\tfetchModels: (context) => fetchOllamaModels(host, context),\n\t\tapi: openAICompletionsApi(),\n\t});\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-codex.d.ts","sourceRoot":"","sources":["../../src/providers/openai-codex.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7D,wBAAgB,mBAAmB,IAAI,QAAQ,CAAC,wBAAwB,CAAC,
|
|
1
|
+
{"version":3,"file":"openai-codex.d.ts","sourceRoot":"","sources":["../../src/providers/openai-codex.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7D,wBAAgB,mBAAmB,IAAI,QAAQ,CAAC,wBAAwB,CAAC,CAexE"}
|
|
@@ -9,7 +9,11 @@ export function openaiCodexProvider() {
|
|
|
9
9
|
name: "OpenAI Codex",
|
|
10
10
|
baseUrl: "https://chatgpt.com/backend-api",
|
|
11
11
|
auth: {
|
|
12
|
-
oauth: lazyOAuth({
|
|
12
|
+
oauth: lazyOAuth({
|
|
13
|
+
name: "OpenAI (ChatGPT Plus/Pro)",
|
|
14
|
+
isSubscription: true,
|
|
15
|
+
load: loadOpenAICodexOAuth,
|
|
16
|
+
}),
|
|
13
17
|
},
|
|
14
18
|
models: Object.values(OPENAI_CODEX_MODELS),
|
|
15
19
|
api: openAICodexResponsesApi(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-codex.js","sourceRoot":"","sources":["../../src/providers/openai-codex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAiB,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,MAAM,UAAU,mBAAmB;IAClC,OAAO,cAAc,CAAC;QACrB,EAAE,EAAE,cAAc;QAClB,IAAI,EAAE,cAAc;QACpB,OAAO,EAAE,iCAAiC;QAC1C,IAAI,EAAE;YACL,KAAK,EAAE,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"openai-codex.js","sourceRoot":"","sources":["../../src/providers/openai-codex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAiB,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,MAAM,UAAU,mBAAmB;IAClC,OAAO,cAAc,CAAC;QACrB,EAAE,EAAE,cAAc;QAClB,IAAI,EAAE,cAAc;QACpB,OAAO,EAAE,iCAAiC;QAC1C,IAAI,EAAE;YACL,KAAK,EAAE,SAAS,CAAC;gBAChB,IAAI,EAAE,2BAA2B;gBACjC,cAAc,EAAE,IAAI;gBACpB,IAAI,EAAE,oBAAoB;aAC1B,CAAC;SACF;QACD,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC;QAC1C,GAAG,EAAE,uBAAuB,EAAE;KAC9B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { openAICodexResponsesApi } from \"../api/openai-codex-responses.lazy.ts\";\nimport { lazyOAuth } from \"../auth/helpers.ts\";\nimport { loadOpenAICodexOAuth } from \"../auth/oauth/load.ts\";\nimport { createProvider, type Provider } from \"../models.ts\";\nimport { OPENAI_CODEX_MODELS } from \"./openai-codex.models.ts\";\n\nexport function openaiCodexProvider(): Provider<\"openai-codex-responses\"> {\n\treturn createProvider({\n\t\tid: \"openai-codex\",\n\t\tname: \"OpenAI Codex\",\n\t\tbaseUrl: \"https://chatgpt.com/backend-api\",\n\t\tauth: {\n\t\t\toauth: lazyOAuth({\n\t\t\t\tname: \"OpenAI (ChatGPT Plus/Pro)\",\n\t\t\t\tisSubscription: true,\n\t\t\t\tload: loadOpenAICodexOAuth,\n\t\t\t}),\n\t\t},\n\t\tmodels: Object.values(OPENAI_CODEX_MODELS),\n\t\tapi: openAICodexResponsesApi(),\n\t});\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opengateway.d.ts","sourceRoot":"","sources":["../../src/providers/opengateway.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7D,wBAAgB,mBAAmB,IAAI,QAAQ,CAAC,oBAAoB,CAAC,CASpE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { openAICompletionsApi } from "../api/openai-completions.lazy.js";
|
|
2
|
+
import { envApiKeyAuth } from "../auth/helpers.js";
|
|
3
|
+
import { createProvider } from "../models.js";
|
|
4
|
+
import { OPENGATEWAY_MODELS } from "./opengateway.models.js";
|
|
5
|
+
export function opengatewayProvider() {
|
|
6
|
+
return createProvider({
|
|
7
|
+
id: "opengateway",
|
|
8
|
+
name: "OpenGateway",
|
|
9
|
+
baseUrl: "https://apis.opengateway.ai/v1",
|
|
10
|
+
auth: { apiKey: envApiKeyAuth("OpenGateway API key", ["OPENGATEWAY_API_KEY"]) },
|
|
11
|
+
models: Object.values(OPENGATEWAY_MODELS),
|
|
12
|
+
api: openAICompletionsApi(),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=opengateway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opengateway.js","sourceRoot":"","sources":["../../src/providers/opengateway.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAiB,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,MAAM,UAAU,mBAAmB;IAClC,OAAO,cAAc,CAAC;QACrB,EAAE,EAAE,aAAa;QACjB,IAAI,EAAE,aAAa;QACnB,OAAO,EAAE,gCAAgC;QACzC,IAAI,EAAE,EAAE,MAAM,EAAE,aAAa,CAAC,qBAAqB,EAAE,CAAC,qBAAqB,CAAC,CAAC,EAAE;QAC/E,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC;QACzC,GAAG,EAAE,oBAAoB,EAAE;KAC3B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { openAICompletionsApi } from \"../api/openai-completions.lazy.ts\";\nimport { envApiKeyAuth } from \"../auth/helpers.ts\";\nimport { createProvider, type Provider } from \"../models.ts\";\nimport { OPENGATEWAY_MODELS } from \"./opengateway.models.ts\";\n\nexport function opengatewayProvider(): Provider<\"openai-completions\"> {\n\treturn createProvider({\n\t\tid: \"opengateway\",\n\t\tname: \"OpenGateway\",\n\t\tbaseUrl: \"https://apis.opengateway.ai/v1\",\n\t\tauth: { apiKey: envApiKeyAuth(\"OpenGateway API key\", [\"OPENGATEWAY_API_KEY\"]) },\n\t\tmodels: Object.values(OPENGATEWAY_MODELS),\n\t\tapi: openAICompletionsApi(),\n\t});\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opengateway.models.d.ts","sourceRoot":"","sources":["../../src/providers/opengateway.models.ts"],"names":[],"mappings":"AAGA,OAAO,MAAM,MAAM,yBAAyB,CAAuB;AACnE,OAAO,EAAuB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE7E,eAAO,MAAM,kBAAkB,EAAE,YAAY,CAAC,OAAO,MAAM,EAAE,aAAa,CAC/B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// This file is auto-generated by scripts/generate-models.ts
|
|
2
|
+
// Do not edit manually - run 'npm run generate-models' to update
|
|
3
|
+
import values from "./data/opengateway.json" with { type: "json" };
|
|
4
|
+
import { flattenModelCatalog } from "../model-catalog.js";
|
|
5
|
+
export const OPENGATEWAY_MODELS = flattenModelCatalog("opengateway", values);
|
|
6
|
+
//# sourceMappingURL=opengateway.models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opengateway.models.js","sourceRoot":"","sources":["../../src/providers/opengateway.models.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,iEAAiE;AAEjE,OAAO,MAAM,MAAM,yBAAyB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAqB,MAAM,qBAAqB,CAAC;AAE7E,MAAM,CAAC,MAAM,kBAAkB,GAC9B,mBAAmB,CAAC,aAAa,EAAE,MAAM,CAAC,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 values from \"./data/opengateway.json\" with { type: \"json\" };\nimport { flattenModelCatalog, type ModelCatalog } from \"../model-catalog.ts\";\n\nexport const OPENGATEWAY_MODELS: ModelCatalog<typeof values, \"opengateway\"> =\n\tflattenModelCatalog(\"opengateway\", values);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qwen-token-plan-individual.d.ts","sourceRoot":"","sources":["../../src/providers/qwen-token-plan-individual.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7D,wBAAgB,+BAA+B,IAAI,QAAQ,CAAC,oBAAoB,CAAC,CAShF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { openAICompletionsApi } from "../api/openai-completions.lazy.js";
|
|
2
|
+
import { envApiKeyAuth } from "../auth/helpers.js";
|
|
3
|
+
import { createProvider } from "../models.js";
|
|
4
|
+
import { QWEN_TOKEN_PLAN_INDIVIDUAL_MODELS } from "./qwen-token-plan-individual.models.js";
|
|
5
|
+
export function qwenTokenPlanIndividualProvider() {
|
|
6
|
+
return createProvider({
|
|
7
|
+
id: "qwen-token-plan-individual",
|
|
8
|
+
name: "Qwen Token Plan Individual",
|
|
9
|
+
baseUrl: "https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
|
|
10
|
+
auth: { apiKey: envApiKeyAuth("Qwen Token Plan Individual API key", ["QWEN_TOKEN_PLAN_API_KEY"]) },
|
|
11
|
+
models: Object.values(QWEN_TOKEN_PLAN_INDIVIDUAL_MODELS),
|
|
12
|
+
api: openAICompletionsApi(),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=qwen-token-plan-individual.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qwen-token-plan-individual.js","sourceRoot":"","sources":["../../src/providers/qwen-token-plan-individual.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAiB,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAE3F,MAAM,UAAU,+BAA+B;IAC9C,OAAO,cAAc,CAAC;QACrB,EAAE,EAAE,4BAA4B;QAChC,IAAI,EAAE,4BAA4B;QAClC,OAAO,EAAE,wEAAwE;QACjF,IAAI,EAAE,EAAE,MAAM,EAAE,aAAa,CAAC,oCAAoC,EAAE,CAAC,yBAAyB,CAAC,CAAC,EAAE;QAClG,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,iCAAiC,CAAC;QACxD,GAAG,EAAE,oBAAoB,EAAE;KAC3B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { openAICompletionsApi } from \"../api/openai-completions.lazy.ts\";\nimport { envApiKeyAuth } from \"../auth/helpers.ts\";\nimport { createProvider, type Provider } from \"../models.ts\";\nimport { QWEN_TOKEN_PLAN_INDIVIDUAL_MODELS } from \"./qwen-token-plan-individual.models.ts\";\n\nexport function qwenTokenPlanIndividualProvider(): Provider<\"openai-completions\"> {\n\treturn createProvider({\n\t\tid: \"qwen-token-plan-individual\",\n\t\tname: \"Qwen Token Plan Individual\",\n\t\tbaseUrl: \"https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1\",\n\t\tauth: { apiKey: envApiKeyAuth(\"Qwen Token Plan Individual API key\", [\"QWEN_TOKEN_PLAN_API_KEY\"]) },\n\t\tmodels: Object.values(QWEN_TOKEN_PLAN_INDIVIDUAL_MODELS),\n\t\tapi: openAICompletionsApi(),\n\t});\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import values from "./data/qwen-token-plan-individual.json";
|
|
2
|
+
import { type ModelCatalog } from "../model-catalog.ts";
|
|
3
|
+
export declare const QWEN_TOKEN_PLAN_INDIVIDUAL_MODELS: ModelCatalog<typeof values, "qwen-token-plan-individual">;
|
|
4
|
+
//# sourceMappingURL=qwen-token-plan-individual.models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qwen-token-plan-individual.models.d.ts","sourceRoot":"","sources":["../../src/providers/qwen-token-plan-individual.models.ts"],"names":[],"mappings":"AAGA,OAAO,MAAM,MAAM,wCAAwC,CAAuB;AAClF,OAAO,EAAuB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE7E,eAAO,MAAM,iCAAiC,EAAE,YAAY,CAAC,OAAO,MAAM,EAAE,4BAA4B,CAC9C,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// This file is auto-generated by scripts/generate-models.ts
|
|
2
|
+
// Do not edit manually - run 'npm run generate-models' to update
|
|
3
|
+
import values from "./data/qwen-token-plan-individual.json" with { type: "json" };
|
|
4
|
+
import { flattenModelCatalog } from "../model-catalog.js";
|
|
5
|
+
export const QWEN_TOKEN_PLAN_INDIVIDUAL_MODELS = flattenModelCatalog("qwen-token-plan-individual", values);
|
|
6
|
+
//# sourceMappingURL=qwen-token-plan-individual.models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qwen-token-plan-individual.models.js","sourceRoot":"","sources":["../../src/providers/qwen-token-plan-individual.models.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,iEAAiE;AAEjE,OAAO,MAAM,MAAM,wCAAwC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAqB,MAAM,qBAAqB,CAAC;AAE7E,MAAM,CAAC,MAAM,iCAAiC,GAC7C,mBAAmB,CAAC,4BAA4B,EAAE,MAAM,CAAC,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 values from \"./data/qwen-token-plan-individual.json\" with { type: \"json\" };\nimport { flattenModelCatalog, type ModelCatalog } from \"../model-catalog.ts\";\n\nexport const QWEN_TOKEN_PLAN_INDIVIDUAL_MODELS: ModelCatalog<typeof values, \"qwen-token-plan-individual\"> =\n\tflattenModelCatalog(\"qwen-token-plan-individual\", values);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"radius.d.ts","sourceRoot":"","sources":["../../src/providers/radius.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAS7C,MAAM,WAAW,qBAAqB;IACrC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,+EAA+E;AAC/E,wBAAgB,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,QAAQ,CAAC,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"radius.d.ts","sourceRoot":"","sources":["../../src/providers/radius.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAS7C,MAAM,WAAW,qBAAqB;IACrC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,+EAA+E;AAC/E,wBAAgB,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,QAAQ,CAAC,aAAa,CAAC,CA8D3F"}
|
package/dist/providers/radius.js
CHANGED
|
@@ -8,7 +8,6 @@ export function radiusProvider(options = {}) {
|
|
|
8
8
|
const name = options.name ?? "Radius";
|
|
9
9
|
const gateway = normalizeRadiusGatewayUrl(options.gateway ?? DEFAULT_RADIUS_GATEWAY);
|
|
10
10
|
let models = getRadiusModels(id, undefined);
|
|
11
|
-
let inflightRefresh;
|
|
12
11
|
const streams = piMessagesApi();
|
|
13
12
|
return {
|
|
14
13
|
id,
|
|
@@ -18,34 +17,45 @@ export function radiusProvider(options = {}) {
|
|
|
18
17
|
oauth: lazyOAuth({ name, load: () => loadRadiusOAuth({ name, gateway }) }),
|
|
19
18
|
},
|
|
20
19
|
getModels: () => models,
|
|
21
|
-
refreshModels: (context) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
refreshModels: async (context) => {
|
|
21
|
+
const stored = context.stored;
|
|
22
|
+
if (stored) {
|
|
23
|
+
const restored = stored.models.filter((model) => model.provider === id);
|
|
24
|
+
if (!(await context.publish({
|
|
25
|
+
update: () => {
|
|
26
|
+
models = restored;
|
|
27
|
+
},
|
|
28
|
+
}))) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Import catalogs cached by the pre-ModelsStore Radius implementation.
|
|
33
|
+
if (!stored && context.credential?.type === "oauth") {
|
|
34
|
+
const legacy = getRadiusModels(id, context.credential);
|
|
35
|
+
if (legacy.length > 0) {
|
|
36
|
+
if (!(await context.publish({
|
|
37
|
+
persist: { models: legacy, checkedAt: Date.now() },
|
|
38
|
+
update: () => {
|
|
31
39
|
models = legacy;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
if (!context.allowNetwork || context.signal?.aborted)
|
|
36
|
-
return;
|
|
37
|
-
const apiKey = context.credential?.type === "oauth" ? context.credential.access : context.credential?.key;
|
|
38
|
-
const config = await loadRadiusGatewayConfig(gateway, apiKey, context.signal);
|
|
39
|
-
if (context.signal?.aborted)
|
|
40
|
+
},
|
|
41
|
+
}))) {
|
|
40
42
|
return;
|
|
41
|
-
|
|
42
|
-
await context.store.write({ models, checkedAt: Date.now() });
|
|
43
|
-
}
|
|
44
|
-
finally {
|
|
45
|
-
inflightRefresh = undefined;
|
|
43
|
+
}
|
|
46
44
|
}
|
|
47
|
-
}
|
|
48
|
-
|
|
45
|
+
}
|
|
46
|
+
if (!context.allowNetwork || context.signal.aborted)
|
|
47
|
+
return;
|
|
48
|
+
const apiKey = context.credential?.type === "oauth" ? context.credential.access : context.credential?.key;
|
|
49
|
+
const config = await loadRadiusGatewayConfig(gateway, apiKey, context.signal);
|
|
50
|
+
if (context.signal.aborted)
|
|
51
|
+
return;
|
|
52
|
+
const refreshed = getRadiusModelsFromConfig(id, config);
|
|
53
|
+
await context.publish({
|
|
54
|
+
persist: { models: refreshed, checkedAt: Date.now() },
|
|
55
|
+
update: () => {
|
|
56
|
+
models = refreshed;
|
|
57
|
+
},
|
|
58
|
+
});
|
|
49
59
|
},
|
|
50
60
|
stream: (model, context, streamOptions) => streams.stream(model, context, streamOptions),
|
|
51
61
|
streamSimple: (model, context, streamOptions) => streams.streamSimple(model, context, streamOptions),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"radius.js","sourceRoot":"","sources":["../../src/providers/radius.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EACN,sBAAsB,EACtB,eAAe,EACf,yBAAyB,EACzB,uBAAuB,EACvB,yBAAyB,GACzB,MAAM,oBAAoB,CAAC;AAQ5B,+EAA+E;AAC/E,MAAM,UAAU,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"radius.js","sourceRoot":"","sources":["../../src/providers/radius.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EACN,sBAAsB,EACtB,eAAe,EACf,yBAAyB,EACzB,uBAAuB,EACvB,yBAAyB,GACzB,MAAM,oBAAoB,CAAC;AAQ5B,+EAA+E;AAC/E,MAAM,UAAU,cAAc,CAAC,UAAiC,EAAE;IACjE,MAAM,EAAE,GAAG,OAAO,CAAC,EAAE,IAAI,QAAQ,CAAC;IAClC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,QAAQ,CAAC;IACtC,MAAM,OAAO,GAAG,yBAAyB,CAAC,OAAO,CAAC,OAAO,IAAI,sBAAsB,CAAC,CAAC;IACrF,IAAI,MAAM,GAAG,eAAe,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,aAAa,EAAE,CAAC;IAEhC,OAAO;QACN,EAAE;QACF,IAAI;QACJ,IAAI,EAAE;YACL,MAAM,E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C;YAED,IAAI,CAAC,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO;gBAAE,OAAO;YAC5D,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC;YAC1G,MAAM,MAAM,GAAG,MAAM,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;YAC9E,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO;gBAAE,OAAO;YACnC,MAAM,SAAS,GAAG,yBAAyB,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;YACxD,MAAM,OAAO,CAAC,OAAO,CAAC;gBACrB,OAAO,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE;gBACrD,MAAM,EAAE,GAAG,EAAE;oBACZ,MAAM,GAAG,SAAS,CAAC;gBACpB,CAAC;aACD,CAAC,CAAC;QACJ,CAAC;QACD,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,CAAC;QACxF,YAAY,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,CAAC;KACpG,CAAC;AACH,CAAC","sourcesContent":["import { piMessagesApi } from \"../api/pi-messages.lazy.ts\";\nimport { envApiKeyAuth, lazyOAuth } from \"../auth/helpers.ts\";\nimport { loadRadiusOAuth } from \"../auth/oauth/load.ts\";\nimport type { Provider } from \"../models.ts\";\nimport {\n\tDEFAULT_RADIUS_GATEWAY,\n\tgetRadiusModels,\n\tgetRadiusModelsFromConfig,\n\tloadRadiusGatewayConfig,\n\tnormalizeRadiusGatewayUrl,\n} from \"./radius-config.ts\";\n\nexport interface RadiusProviderOptions {\n\tid?: string;\n\tname?: string;\n\tgateway?: string;\n}\n\n/** Radius gateway provider with a persisted, dynamically refreshed catalog. */\nexport function radiusProvider(options: RadiusProviderOptions = {}): Provider<\"pi-messages\"> {\n\tconst id = options.id ?? \"radius\";\n\tconst name = options.name ?? \"Radius\";\n\tconst gateway = normalizeRadiusGatewayUrl(options.gateway ?? DEFAULT_RADIUS_GATEWAY);\n\tlet models = getRadiusModels(id, undefined);\n\tconst streams = piMessagesApi();\n\n\treturn {\n\t\tid,\n\t\tname,\n\t\tauth: {\n\t\t\tapiKey: envApiKeyAuth(\"Radius API key\", [\"RADIUS_API_KEY\"]),\n\t\t\toauth: lazyOAuth({ name, load: () => loadRadiusOAuth({ name, gateway }) }),\n\t\t},\n\t\tgetModels: () => models,\n\t\trefreshModels: async (context) => {\n\t\t\tconst stored = context.stored;\n\t\t\tif (stored) {\n\t\t\t\tconst restored = stored.models.filter((model) => model.provider === id) as typeof models;\n\t\t\t\tif (\n\t\t\t\t\t!(await context.publish({\n\t\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\t\tmodels = restored;\n\t\t\t\t\t\t},\n\t\t\t\t\t}))\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Import catalogs cached by the pre-ModelsStore Radius implementation.\n\t\t\tif (!stored && context.credential?.type === \"oauth\") {\n\t\t\t\tconst legacy = getRadiusModels(id, context.credential);\n\t\t\t\tif (legacy.length > 0) {\n\t\t\t\t\tif (\n\t\t\t\t\t\t!(await context.publish({\n\t\t\t\t\t\t\tpersist: { models: legacy, checkedAt: Date.now() },\n\t\t\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\t\t\tmodels = legacy;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}))\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!context.allowNetwork || context.signal.aborted) return;\n\t\t\tconst apiKey = context.credential?.type === \"oauth\" ? context.credential.access : context.credential?.key;\n\t\t\tconst config = await loadRadiusGatewayConfig(gateway, apiKey, context.signal);\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst refreshed = getRadiusModelsFromConfig(id, config);\n\t\t\tawait context.publish({\n\t\t\t\tpersist: { models: refreshed, checkedAt: Date.now() },\n\t\t\t\tupdate: () => {\n\t\t\t\t\tmodels = refreshed;\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t\tstream: (model, context, streamOptions) => streams.stream(model, context, streamOptions),\n\t\tstreamSimple: (model, context, streamOptions) => streams.streamSimple(model, context, streamOptions),\n\t};\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xai.d.ts","sourceRoot":"","sources":["../../src/providers/xai.ts"],"names":[],"mappings":"AAIA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7D,wBAAgB,WAAW,IAAI,QAAQ,CAAC,oBAAoB,GAAG,kBAAkB,CAAC,
|
|
1
|
+
{"version":3,"file":"xai.d.ts","sourceRoot":"","sources":["../../src/providers/xai.ts"],"names":[],"mappings":"AAIA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7D,wBAAgB,WAAW,IAAI,QAAQ,CAAC,oBAAoB,GAAG,kBAAkB,CAAC,CAoBjF"}
|
package/dist/providers/xai.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xai.js","sourceRoot":"","sources":["../../src/providers/xai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAiB,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,MAAM,UAAU,WAAW;IAC1B,OAAO,cAAc,CAAC;QACrB,EAAE,EAAE,KAAK;QACT,IAAI,EAAE,KAAK;QACX,OAAO,EAAE,qBAAqB;QAC9B,IAAI,EAAE;YACL,MAAM,EAAE,aAAa,CAAC,aAAa,EAAE,CAAC,aAAa,CAAC,CAAC;YACrD,KAAK,EAAE,SAAS,CAAC;gBAChB,IAAI,EAAE,2BAA2B;gBACjC,UAAU,EAAE,qCAAqC;gBACjD,IAAI,EAAE,YAAY;aAClB,CAAC;SACF;QACD,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;QACjC,GAAG,EAAE;YACJ,oBAAoB,EAAE,oBAAoB,EAAE;YAC5C,kBAAkB,EAAE,kBAAkB,EAAE;SACxC;KACD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { openAICompletionsApi } from \"../api/openai-completions.lazy.ts\";\nimport { openAIResponsesApi } from \"../api/openai-responses.lazy.ts\";\nimport { envApiKeyAuth, lazyOAuth } from \"../auth/helpers.ts\";\nimport { loadXaiOAuth } from \"../auth/oauth/load.ts\";\nimport { createProvider, type Provider } from \"../models.ts\";\nimport { XAI_MODELS } from \"./xai.models.ts\";\n\nexport function xaiProvider(): Provider<\"openai-completions\" | \"openai-responses\"> {\n\treturn createProvider({\n\t\tid: \"xai\",\n\t\tname: \"xAI\",\n\t\tbaseUrl: \"https://api.x.ai/v1\",\n\t\tauth: {\n\t\t\tapiKey: envApiKeyAuth(\"xAI API key\", [\"XAI_API_KEY\"]),\n\t\t\toauth: lazyOAuth({\n\t\t\t\tname: \"xAI (Grok/X subscription)\",\n\t\t\t\tloginLabel: \"Sign in with SuperGrok or X Premium\",\n\t\t\t\tload: loadXaiOAuth,\n\t\t\t}),\n\t\t},\n\t\tmodels: Object.values(XAI_MODELS),\n\t\tapi: {\n\t\t\t\"openai-completions\": openAICompletionsApi(),\n\t\t\t\"openai-responses\": openAIResponsesApi(),\n\t\t},\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"xai.js","sourceRoot":"","sources":["../../src/providers/xai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAiB,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,MAAM,UAAU,WAAW;IAC1B,OAAO,cAAc,CAAC;QACrB,EAAE,EAAE,KAAK;QACT,IAAI,EAAE,KAAK;QACX,OAAO,EAAE,qBAAqB;QAC9B,IAAI,EAAE;YACL,MAAM,EAAE,aAAa,CAAC,aAAa,EAAE,CAAC,aAAa,CAAC,CAAC;YACrD,KAAK,EAAE,SAAS,CAAC;gBAChB,IAAI,EAAE,2BAA2B;gBACjC,cAAc,EAAE,IAAI;gBACpB,UAAU,EAAE,qCAAqC;gBACjD,IAAI,EAAE,YAAY;aAClB,CAAC;SACF;QACD,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;QACjC,GAAG,EAAE;YACJ,oBAAoB,EAAE,oBAAoB,EAAE;YAC5C,kBAAkB,EAAE,kBAAkB,EAAE;SACxC;KACD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { openAICompletionsApi } from \"../api/openai-completions.lazy.ts\";\nimport { openAIResponsesApi } from \"../api/openai-responses.lazy.ts\";\nimport { envApiKeyAuth, lazyOAuth } from \"../auth/helpers.ts\";\nimport { loadXaiOAuth } from \"../auth/oauth/load.ts\";\nimport { createProvider, type Provider } from \"../models.ts\";\nimport { XAI_MODELS } from \"./xai.models.ts\";\n\nexport function xaiProvider(): Provider<\"openai-completions\" | \"openai-responses\"> {\n\treturn createProvider({\n\t\tid: \"xai\",\n\t\tname: \"xAI\",\n\t\tbaseUrl: \"https://api.x.ai/v1\",\n\t\tauth: {\n\t\t\tapiKey: envApiKeyAuth(\"xAI API key\", [\"XAI_API_KEY\"]),\n\t\t\toauth: lazyOAuth({\n\t\t\t\tname: \"xAI (Grok/X subscription)\",\n\t\t\t\tisSubscription: true,\n\t\t\t\tloginLabel: \"Sign in with SuperGrok or X Premium\",\n\t\t\t\tload: loadXaiOAuth,\n\t\t\t}),\n\t\t},\n\t\tmodels: Object.values(XAI_MODELS),\n\t\tapi: {\n\t\t\t\"openai-completions\": openAICompletionsApi(),\n\t\t\t\"openai-responses\": openAIResponsesApi(),\n\t\t},\n\t});\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-transformer.js","sourceRoot":"","sources":["../../src/tool-call-middleware/context-transformer.ts"],"names":[],"mappings":"AASA,OAAO,EACN,0BAA0B,EAC1B,8BAA8B,EAC9B,mCAAmC,EACnC,8BAA8B,EAC9B,8BAA8B,GAC9B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACN,mBAAmB,EACnB,uBAAuB,EACvB,4BAA4B,EAC5B,uBAAuB,EACvB,uBAAuB,GACvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACN,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,6BAA6B,EAC7B,wBAAwB,GACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,6BAA6B,EAC7B,wBAAwB,GACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,0BAA0B,EAC1B,sBAAsB,EACtB,0BAA0B,EAC1B,+BAA+B,EAC/B,0BAA0B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EAAE,CAAC;gBACb,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACvB,MAAM;YACP,CAAC;YACD,KAAK,UAAU,EAAE,CAAC;gBACjB,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACvB,MAAM;YACP,CAAC;YACD,KAAK,UAAU,EAAE,CAAC;gBACjB,MAAM,YAAY,GAAG,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;gBAC1E,UAAU,CAAC,IAAI,CAAC;oBACf,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,YAAY;iBAClB,CAAC,CAAC;gBACH,MAAM;YACP,CAAC;QACF,CAAC;IACF,CAAC;IAED,uDAAuD;IACvD,OAAO;QACN,GAAG,OAAO;QACV,OAAO,EAAE,UAAU;KACnB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,0BAA0B,CAAC,OAA0B,EAAE,QAA0B;IACzF,sDAAsD;IACtD,MAAM,iBAAiB,GAAG,QAAQ,CAAC,kBAAkB,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAE7G,0CAA0C;IAC1C,OAAO;QACN,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,iBAAiB;QAC1B,SAAS,EAAE,OAAO,CAAC,SAAS;KAC5B,CAAC;AACH,CAAC","sourcesContent":["import type {\n\tAssistantMessage,\n\tContext,\n\tMessage,\n\tTextContent,\n\tThinkingContent,\n\tToolResultMessage,\n\tUserMessage,\n} from \"../types.ts\";\nimport {\n\tanthropicXmlFormatToolCall,\n\tanthropicXmlFormatToolResponse,\n\tanthropicXmlFormatToolsSystemPrompt,\n\tcreateAnthropicXmlStreamParser,\n\tparseAnthropicXmlGeneratedText,\n} from \"./protocols/anthropic-xml/index.ts\";\nimport {\n\tantmlFormatToolCall,\n\tantmlFormatToolResponse,\n\tantmlFormatToolsSystemPrompt,\n\tcreateAntmlStreamParser,\n\tparseAntmlGeneratedText,\n} from \"./protocols/antml/index.ts\";\nimport {\n\tgemma4CreateStreamParser,\n\tgemma4FormatToolCall,\n\tgemma4FormatToolResponse,\n\tgemma4FormatToolsSystemPrompt,\n\tgemma4ParseGeneratedText,\n} from \"./protocols/gemma4.ts\";\nimport {\n\thermesCreateStreamParser,\n\thermesFormatToolCall,\n\thermesFormatToolResponse,\n\thermesFormatToolsSystemPrompt,\n\thermesParseGeneratedText,\n} from \"./protocols/hermes.ts\";\nimport {\n\tcreateKimiXtmlStreamParser,\n\tkimiXtmlFormatToolCall,\n\tkimiXtmlFormatToolResponse,\n\tkimiXtmlFormatToolsSystemPrompt,\n\tparseKimiXtmlGeneratedText,\n} from \"./protocols/kimi-xtml/index.ts\";\nimport {\n\tcreateMorphXmlStreamParser,\n\tmorphXmlFormatToolCall,\n\tmorphXmlFormatToolResponse,\n\tmorphXmlFormatToolsSystemPrompt,\n\tparseMorphXmlGeneratedText,\n} from \"./protocols/morph-xml.ts\";\nimport {\n\tcreateYamlXmlStreamParser,\n\tparseYamlXmlGeneratedText,\n\tyamlXmlFormatToolCall,\n\tyamlXmlFormatToolResponse,\n\tyamlXmlFormatToolsSystemPrompt,\n} from \"./protocols/yaml-xml.ts\";\nimport type { ToolCallFormat, ToolCallProtocol } from \"./types.ts\";\n\n/**\n * Hermes protocol implementation for tool call formatting and parsing.\n */\nconst hermesProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: hermesFormatToolsSystemPrompt,\n\tformatToolResponse: hermesFormatToolResponse,\n\tformatToolCall: hermesFormatToolCall,\n\tparseGeneratedText: hermesParseGeneratedText,\n\tcreateStreamParser: hermesCreateStreamParser,\n};\n\n/**\n * MorphXml protocol implementation for tool call formatting and parsing.\n */\nconst morphXmlProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: morphXmlFormatToolsSystemPrompt,\n\tformatToolResponse: morphXmlFormatToolResponse,\n\tformatToolCall: morphXmlFormatToolCall,\n\tparseGeneratedText: parseMorphXmlGeneratedText,\n\tcreateStreamParser: createMorphXmlStreamParser,\n};\n\nconst yamlXmlProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: yamlXmlFormatToolsSystemPrompt,\n\tformatToolResponse: yamlXmlFormatToolResponse,\n\tformatToolCall: yamlXmlFormatToolCall,\n\tparseGeneratedText: parseYamlXmlGeneratedText,\n\tcreateStreamParser: createYamlXmlStreamParser,\n};\n\n/**\n * Gemma 4 protocol implementation for tool call formatting and parsing.\n */\nconst gemma4Protocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: gemma4FormatToolsSystemPrompt,\n\tformatToolResponse: gemma4FormatToolResponse,\n\tformatToolCall: gemma4FormatToolCall,\n\tparseGeneratedText: gemma4ParseGeneratedText,\n\tcreateStreamParser: gemma4CreateStreamParser,\n};\n\nconst antmlProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: antmlFormatToolsSystemPrompt,\n\tformatToolResponse: antmlFormatToolResponse,\n\tformatToolCall: antmlFormatToolCall,\n\tparseGeneratedText: parseAntmlGeneratedText,\n\tcreateStreamParser: createAntmlStreamParser,\n};\n\nconst kimiXtmlProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: kimiXtmlFormatToolsSystemPrompt,\n\tformatToolResponse: kimiXtmlFormatToolResponse,\n\tformatToolCall: kimiXtmlFormatToolCall,\n\tparseGeneratedText: parseKimiXtmlGeneratedText,\n\tcreateStreamParser: createKimiXtmlStreamParser,\n};\n\nconst anthropicXmlProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: anthropicXmlFormatToolsSystemPrompt,\n\tformatToolResponse: anthropicXmlFormatToolResponse,\n\tformatToolCall: anthropicXmlFormatToolCall,\n\tparseGeneratedText: parseAnthropicXmlGeneratedText,\n\tcreateStreamParser: createAnthropicXmlStreamParser,\n};\n\n/**\n * Protocol registry mapping format strings to protocol implementations.\n */\nconst protocolRegistry: Record<ToolCallFormat, ToolCallProtocol> = {\n\t\"anthropic-xml\": anthropicXmlProtocol,\n\tantml: antmlProtocol,\n\thermes: hermesProtocol,\n\txml: morphXmlProtocol,\n\t\"morph-xml\": morphXmlProtocol,\n\t\"yaml-xml\": yamlXmlProtocol,\n\t\"gemma4-delimiter\": gemma4Protocol,\n\t\"kimi-xtml\": kimiXtmlProtocol,\n};\n\n/**\n * Gets the protocol implementation for a given tool call format.\n * @param format - The tool call format\n * @returns The protocol implementation\n * @throws Error if the format is not supported\n */\nexport function getProtocol(format: ToolCallFormat): ToolCallProtocol {\n\tconst protocol = protocolRegistry[format];\n\tif (!protocol) {\n\t\tthrow new Error(`Unsupported tool call format: ${format}`);\n\t}\n\treturn protocol;\n}\n\n/**\n * Transforms a context for text-based tool calling.\n * - Strips tools from context (provider sees tool-free request)\n * - Injects tool definitions into system prompt\n * - Converts tool call messages in history to text format\n * - Converts tool result messages to user messages with text content\n *\n * @param context - The original context\n * @param protocol - The protocol to use for formatting\n * @returns A new transformed context (original is not mutated)\n */\nexport function transformContext(context: Context, protocol: ToolCallProtocol): Context {\n\t// Build new context without mutating original\n\tconst transformed: Context = {\n\t\tsystemPrompt: context.systemPrompt,\n\t\tmessages: context.messages.map((msg) => transformMessage(msg, protocol)),\n\t\ttools: undefined, // Strip tools - provider sees tool-free request\n\t};\n\n\t// Inject tool definitions into system prompt if tools exist\n\tif (context.tools && context.tools.length > 0) {\n\t\tconst toolPrompt = protocol.formatToolsSystemPrompt(context.tools);\n\t\tif (toolPrompt) {\n\t\t\ttransformed.systemPrompt = context.systemPrompt ? `${toolPrompt}\\n\\n${context.systemPrompt}` : toolPrompt;\n\t\t}\n\t}\n\n\treturn transformed;\n}\n\n/**\n * Transforms a single message for text-based tool calling.\n * - AssistantMessage with ToolCall blocks: convert to text\n * - ToolResultMessage: convert to UserMessage with text content\n * - Other messages: pass through unchanged\n */\nfunction transformMessage(message: Message, protocol: ToolCallProtocol): Message {\n\tswitch (message.role) {\n\t\tcase \"assistant\": {\n\t\t\treturn transformAssistantMessage(message, protocol);\n\t\t}\n\t\tcase \"toolResult\": {\n\t\t\treturn transformToolResultMessage(message, protocol);\n\t\t}\n\t\tdefault: {\n\t\t\treturn message;\n\t\t}\n\t}\n}\n\n/**\n * Transforms an AssistantMessage, converting ToolCall content blocks to text.\n *\n * Flagged incomplete calls replay as canonical formatted calls from their sanitized parsed arguments; the paired error toolResult (created by agent-loop/pair-repair) is what tells the model the call failed — raw truncated markup never re-enters context.\n */\nfunction transformAssistantMessage(message: AssistantMessage, protocol: ToolCallProtocol): AssistantMessage {\n\t// Check if message has any ToolCall content blocks\n\tconst hasToolCalls = message.content.some((block) => block.type === \"toolCall\");\n\tif (!hasToolCalls) {\n\t\t// No tool calls - pass through unchanged\n\t\treturn message;\n\t}\n\n\t// Transform content blocks\n\tconst newContent: (TextContent | ThinkingContent)[] = [];\n\n\tfor (const block of message.content) {\n\t\tswitch (block.type) {\n\t\t\tcase \"text\": {\n\t\t\t\tnewContent.push(block);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"thinking\": {\n\t\t\t\tnewContent.push(block);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"toolCall\": {\n\t\t\t\tconst toolCallText = protocol.formatToolCall(block.name, block.arguments);\n\t\t\t\tnewContent.push({\n\t\t\t\t\ttype: \"text\",\n\t\t\t\t\ttext: toolCallText,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Return new AssistantMessage with transformed content\n\treturn {\n\t\t...message,\n\t\tcontent: newContent,\n\t};\n}\n\n/**\n * Transforms a ToolResultMessage to a UserMessage with text content.\n */\nfunction transformToolResultMessage(message: ToolResultMessage, protocol: ToolCallProtocol): UserMessage {\n\t// Format tool result as text using protocol formatter\n\tconst formattedResponse = protocol.formatToolResponse(message.toolName, message.toolCallId, message.content);\n\n\t// Return as UserMessage with text content\n\treturn {\n\t\trole: \"user\",\n\t\tcontent: formattedResponse,\n\t\ttimestamp: message.timestamp,\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"context-transformer.js","sourceRoot":"","sources":["../../src/tool-call-middleware/context-transformer.ts"],"names":[],"mappings":"AASA,OAAO,EACN,0BAA0B,EAC1B,8BAA8B,EAC9B,mCAAmC,EACnC,8BAA8B,EAC9B,8BAA8B,GAC9B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACN,mBAAmB,EACnB,uBAAuB,EACvB,4BAA4B,EAC5B,uBAAuB,EACvB,uBAAuB,GACvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACN,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,6BAA6B,EAC7B,wBAAwB,GACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,6BAA6B,EAC7B,wBAAwB,GACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,0BAA0B,EAC1B,sBAAsB,EACtB,0BAA0B,EAC1B,+BAA+B,EAC/B,0BAA0B,GAC1B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACN,0BAA0B,EAC1B,sBAAsB,EACtB,0BAA0B,EAC1B,+BAA+B,EAC/B,0BAA0B,GAC1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACN,yBAAyB,EACzB,yBAAyB,EACzB,qBAAqB,EACrB,yBAAyB,EACzB,8BAA8B,GAC9B,MAAM,yBAAyB,CAAC;AAGjC;;GAEG;AACH,MAAM,cAAc,GAAqB;IACxC,uBAAuB,EAAE,6BAA6B;IACtD,kBAAkB,EAAE,wBAAwB;IAC5C,cAAc,EAAE,oBAAoB;IACpC,kBAAkB,EAAE,wBAAwB;IAC5C,kBAAkB,EAAE,wBAAwB;CAC5C,CAAC;AAEF;;GAEG;AACH,MAAM,gBAAgB,GAAqB;IAC1C,uBAAuB,EAAE,+BAA+B;IACxD,kBAAkB,EAAE,0BAA0B;IAC9C,cAAc,EAAE,sBAAsB;IACtC,kB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AACH,CAAC;AAED;;GAEG;AACH,SAAS,0BAA0B,CAAC,OAA0B,EAAE,QAA0B;IACzF,sDAAsD;IACtD,MAAM,iBAAiB,GAAG,QAAQ,CAAC,kBAAkB,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAE7G,0CAA0C;IAC1C,OAAO;QACN,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,iBAAiB;QAC1B,SAAS,EAAE,OAAO,CAAC,SAAS;KAC5B,CAAC;AACH,CAAC","sourcesContent":["import type {\n\tAssistantMessage,\n\tContext,\n\tMessage,\n\tTextContent,\n\tThinkingContent,\n\tToolResultMessage,\n\tUserMessage,\n} from \"../types.ts\";\nimport {\n\tanthropicXmlFormatToolCall,\n\tanthropicXmlFormatToolResponse,\n\tanthropicXmlFormatToolsSystemPrompt,\n\tcreateAnthropicXmlStreamParser,\n\tparseAnthropicXmlGeneratedText,\n} from \"./protocols/anthropic-xml/index.ts\";\nimport {\n\tantmlFormatToolCall,\n\tantmlFormatToolResponse,\n\tantmlFormatToolsSystemPrompt,\n\tcreateAntmlStreamParser,\n\tparseAntmlGeneratedText,\n} from \"./protocols/antml/index.ts\";\nimport {\n\tgemma4CreateStreamParser,\n\tgemma4FormatToolCall,\n\tgemma4FormatToolResponse,\n\tgemma4FormatToolsSystemPrompt,\n\tgemma4ParseGeneratedText,\n} from \"./protocols/gemma4.ts\";\nimport {\n\thermesCreateStreamParser,\n\thermesFormatToolCall,\n\thermesFormatToolResponse,\n\thermesFormatToolsSystemPrompt,\n\thermesParseGeneratedText,\n} from \"./protocols/hermes.ts\";\nimport {\n\tcreateKimiXtmlStreamParser,\n\tkimiXtmlFormatToolCall,\n\tkimiXtmlFormatToolResponse,\n\tkimiXtmlFormatToolsSystemPrompt,\n\tparseKimiXtmlGeneratedText,\n} from \"./protocols/kimi-xtml/index.ts\";\nimport {\n\tcreateMorphXmlStreamParser,\n\tmorphXmlFormatToolCall,\n\tmorphXmlFormatToolResponse,\n\tmorphXmlFormatToolsSystemPrompt,\n\tparseMorphXmlGeneratedText,\n} from \"./protocols/morph-xml.ts\";\nimport {\n\tcreateYamlXmlStreamParser,\n\tparseYamlXmlGeneratedText,\n\tyamlXmlFormatToolCall,\n\tyamlXmlFormatToolResponse,\n\tyamlXmlFormatToolsSystemPrompt,\n} from \"./protocols/yaml-xml.ts\";\nimport type { ToolCallFormat, ToolCallProtocol } from \"./types.ts\";\n\n/**\n * Hermes protocol implementation for tool call formatting and parsing.\n */\nconst hermesProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: hermesFormatToolsSystemPrompt,\n\tformatToolResponse: hermesFormatToolResponse,\n\tformatToolCall: hermesFormatToolCall,\n\tparseGeneratedText: hermesParseGeneratedText,\n\tcreateStreamParser: hermesCreateStreamParser,\n};\n\n/**\n * MorphXml protocol implementation for tool call formatting and parsing.\n */\nconst morphXmlProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: morphXmlFormatToolsSystemPrompt,\n\tformatToolResponse: morphXmlFormatToolResponse,\n\tformatToolCall: morphXmlFormatToolCall,\n\tparseGeneratedText: parseMorphXmlGeneratedText,\n\tcreateStreamParser: createMorphXmlStreamParser,\n};\n\nconst yamlXmlProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: yamlXmlFormatToolsSystemPrompt,\n\tformatToolResponse: yamlXmlFormatToolResponse,\n\tformatToolCall: yamlXmlFormatToolCall,\n\tparseGeneratedText: parseYamlXmlGeneratedText,\n\tcreateStreamParser: createYamlXmlStreamParser,\n};\n\n/**\n * Gemma 4 protocol implementation for tool call formatting and parsing.\n */\nconst gemma4Protocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: gemma4FormatToolsSystemPrompt,\n\tformatToolResponse: gemma4FormatToolResponse,\n\tformatToolCall: gemma4FormatToolCall,\n\tparseGeneratedText: gemma4ParseGeneratedText,\n\tcreateStreamParser: gemma4CreateStreamParser,\n};\n\nconst antmlProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: antmlFormatToolsSystemPrompt,\n\tformatToolResponse: antmlFormatToolResponse,\n\tformatToolCall: antmlFormatToolCall,\n\tparseGeneratedText: parseAntmlGeneratedText,\n\tcreateStreamParser: createAntmlStreamParser,\n};\n\nconst kimiXtmlProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: kimiXtmlFormatToolsSystemPrompt,\n\tformatToolResponse: kimiXtmlFormatToolResponse,\n\tformatToolCall: kimiXtmlFormatToolCall,\n\tparseGeneratedText: parseKimiXtmlGeneratedText,\n\tcreateStreamParser: createKimiXtmlStreamParser,\n};\n\nconst anthropicXmlProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: anthropicXmlFormatToolsSystemPrompt,\n\tformatToolResponse: anthropicXmlFormatToolResponse,\n\tformatToolCall: anthropicXmlFormatToolCall,\n\tparseGeneratedText: parseAnthropicXmlGeneratedText,\n\tcreateStreamParser: createAnthropicXmlStreamParser,\n};\n\n/**\n * Protocol registry mapping format strings to protocol implementations.\n */\nconst protocolRegistry: Record<ToolCallFormat, ToolCallProtocol> = {\n\t\"anthropic-xml\": anthropicXmlProtocol,\n\tantml: antmlProtocol,\n\thermes: hermesProtocol,\n\txml: morphXmlProtocol,\n\t\"morph-xml\": morphXmlProtocol,\n\t\"yaml-xml\": yamlXmlProtocol,\n\t\"gemma4-delimiter\": gemma4Protocol,\n\t\"kimi-xtml\": kimiXtmlProtocol,\n};\n\n/**\n * Gets the protocol implementation for a given tool call format.\n * @param format - The tool call format\n * @returns The protocol implementation\n * @throws Error if the format is not supported\n */\nexport function getProtocol(format: ToolCallFormat): ToolCallProtocol {\n\tconst protocol = protocolRegistry[format];\n\tif (!protocol) {\n\t\tthrow new Error(`Unsupported tool call format: ${format}`);\n\t}\n\treturn protocol;\n}\n\n/**\n * Transforms a context for text-based tool calling.\n * - Strips tools from context (provider sees tool-free request)\n * - Injects tool definitions into system prompt\n * - Converts tool call messages in history to text format\n * - Converts tool result messages to user messages with text content\n *\n * @param context - The original context\n * @param protocol - The protocol to use for formatting\n * @returns A new transformed context (original is not mutated)\n */\nexport function transformContext(context: Context, protocol: ToolCallProtocol): Context {\n\t// Build new context without mutating original\n\tconst transformed: Context = {\n\t\tsystemPrompt: context.systemPrompt,\n\t\tmessages: context.messages.map((msg) => transformMessage(msg, protocol)),\n\t\ttools: undefined, // Strip tools - provider sees tool-free request\n\t};\n\n\t// Inject tool definitions into system prompt if tools exist\n\tif (context.tools && context.tools.length > 0) {\n\t\tconst toolPrompt = protocol.formatToolsSystemPrompt(context.tools);\n\t\tif (toolPrompt) {\n\t\t\ttransformed.systemPrompt = context.systemPrompt ? `${toolPrompt}\\n\\n${context.systemPrompt}` : toolPrompt;\n\t\t}\n\t}\n\n\treturn transformed;\n}\n\n/**\n * Transforms a single message for text-based tool calling.\n * - AssistantMessage with ToolCall blocks: convert to text\n * - ToolResultMessage: convert to UserMessage with text content\n * - Other messages: pass through unchanged\n */\nfunction transformMessage(message: Message, protocol: ToolCallProtocol): Message {\n\tswitch (message.role) {\n\t\tcase \"assistant\": {\n\t\t\treturn transformAssistantMessage(message, protocol);\n\t\t}\n\t\tcase \"toolResult\": {\n\t\t\treturn transformToolResultMessage(message, protocol);\n\t\t}\n\t\tdefault: {\n\t\t\treturn message;\n\t\t}\n\t}\n}\n\n/**\n * Transforms an AssistantMessage, converting ToolCall content blocks to text.\n *\n * Flagged incomplete calls replay as canonical formatted calls from their sanitized parsed arguments; the paired error toolResult (created by agent-loop/pair-repair) is what tells the model the call failed — raw truncated markup never re-enters context.\n */\nfunction transformAssistantMessage(message: AssistantMessage, protocol: ToolCallProtocol): AssistantMessage {\n\t// Check if message has any ToolCall content blocks\n\tconst hasToolCalls = message.content.some((block) => block.type === \"toolCall\");\n\tif (!hasToolCalls) {\n\t\t// No tool calls - pass through unchanged\n\t\treturn message;\n\t}\n\n\t// Transform content blocks\n\tconst newContent: (TextContent | ThinkingContent)[] = [];\n\n\tfor (const block of message.content) {\n\t\tswitch (block.type) {\n\t\t\tcase \"text\": {\n\t\t\t\tnewContent.push(block);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"thinking\": {\n\t\t\t\tnewContent.push(block);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"toolCall\": {\n\t\t\t\tconst toolCallText = protocol.formatToolCall(block.name, block.arguments);\n\t\t\t\tnewContent.push({\n\t\t\t\t\ttype: \"text\",\n\t\t\t\t\ttext: toolCallText,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Return new AssistantMessage with transformed content\n\treturn {\n\t\t...message,\n\t\tcontent: newContent,\n\t};\n}\n\n/**\n * Transforms a ToolResultMessage to a UserMessage with text content.\n */\nfunction transformToolResultMessage(message: ToolResultMessage, protocol: ToolCallProtocol): UserMessage {\n\t// Format tool result as text using protocol formatter\n\tconst formattedResponse = protocol.formatToolResponse(message.toolName, message.toolCallId, message.content);\n\n\t// Return as UserMessage with text content\n\treturn {\n\t\trole: \"user\",\n\t\tcontent: formattedResponse,\n\t\ttimestamp: message.timestamp,\n\t};\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recovery-wrapper-state.d.ts","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/recovery-wrapper-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAK9C,KAAK,6BAA6B,GAAG;IACpC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;IACjC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAC9B;IAAE,QAAQ,CAAC,IA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AAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;YACpD,IAAI,IAAI;gBAAE,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC7D,CAAC;IACF,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import type { Tool } from \"../../../types.ts\";\nimport type { ParsedToolCall, ParserOptions } from \"../../types.ts\";\nimport {\n\tparseXtmlAttributes,\n\tXTML_ARGUMENT_CLOSE,\n\tXTML_ARGUMENT_OPEN,\n\tXTML_CALL_CLOSE,\n\tXTML_CALL_OPEN,\n\tXTML_SEP,\n\tXTML_TOOLS_CLOSE,\n\tXTML_TOOLS_OPEN,\n} from \"./markers.ts\";\n\ntype CoercedValue = { ok: true; value: unknown } | { ok: false };\n\nexport function coerceXtmlArgumentValue(raw: string, type: string | undefined): CoercedValue {\n\tswitch (type) {\n\t\tcase undefined:\n\t\tcase \"string\":\n\t\t\treturn { ok: true, value: raw };\n\t\tcase \"number\": {\n\t\t\tconst parsed = Number(raw);\n\t\t\treturn Number.isNaN(parsed) ? { ok: false } : { ok: true, value: parsed };\n\t\t}\n\t\tcase \"boolean\":\n\t\t\tif (raw === \"true\") return { ok: true, value: true };\n\t\t\tif (raw === \"false\") return { ok: true, value: false };\n\t\t\treturn { ok: false };\n\t\tcase \"object\":\n\t\tcase \"array\":\n\t\t\ttry {\n\t\t\t\treturn { ok: true, value: JSON.parse(raw) };\n\t\t\t} catch {\n\t\t\t\treturn { ok: false };\n\t\t\t}\n\t\tdefault:\n\t\t\treturn { ok: true, value: raw };\n\t}\n}\n\nfunction parseCallBody(body: string, tool: Tool, options?: ParserOptions): Record<string, unknown> | null {\n\tconst args: Record<string, unknown> = {};\n\tlet rest = body;\n\tfor (;;) {\n\t\trest = rest.replace(/^\\s+/, \"\");\n\t\tif (!rest.startsWith(XTML_ARGUMENT_OPEN)) break;\n\t\tconst headerEnd = rest.indexOf(XTML_SEP, XTML_ARGUMENT_OPEN.length);\n\t\tif (headerEnd === -1) break;\n\t\tconst attributes = parseXtmlAttributes(rest.slice(XTML_ARGUMENT_OPEN.length, headerEnd));\n\t\tconst key = attributes.key;\n\t\tconst valueStart = headerEnd + XTML_SEP.length;\n\t\tconst valueEnd = rest.indexOf(XTML_ARGUMENT_CLOSE, valueStart);\n\t\tif (valueEnd === -1 || !key) break;\n\t\tconst coerced = coerceXtmlArgumentValue(rest.slice(valueStart, valueEnd), attributes.type);\n\t\tif (!coerced.ok) {\n\t\t\toptions?.onError?.(`kimi-xtml: invalid value for argument \"${key}\" on tool \"${tool.name}\".`, {\n\t\t\t\ttoolCall: rest.slice(0, valueEnd + XTML_ARGUMENT_CLOSE.length),\n\t\t\t});\n\t\t\treturn null;\n\t\t}\n\t\targs[key] = coerced.value;\n\t\trest = rest.slice(valueEnd + XTML_ARGUMENT_CLOSE.length);\n\t}\n\treturn args;\n}\n\nexport function parseKimiXtmlGeneratedText(text: string, tools: Tool[], options?: ParserOptions): ParsedToolCall[] {\n\tconst parsed: ParsedToolCall[] = [];\n\tlet cursor = 0;\n\twhile (cursor < text.length) {\n\t\tconst blockStart = text.indexOf(XTML_TOOLS_OPEN, cursor);\n\t\tif (blockStart === -1) break;\n\t\tconst bodyStart = blockStart + XTML_TOOLS_OPEN.length;\n\t\tconst blockEnd = text.indexOf(XTML_TOOLS_CLOSE, bodyStart);\n\t\tconst block = blockEnd === -1 ? text.slice(bodyStart) : text.slice(bodyStart, blockEnd);\n\t\tcursor = blockEnd === -1 ? text.length : blockEnd + XTML_TOOLS_CLOSE.length;\n\n\t\tlet callCursor = 0;\n\t\twhile (callCursor < block.length) {\n\t\t\tconst callStart = block.indexOf(XTML_CALL_OPEN, callCursor);\n\t\t\tif (callStart === -1) break;\n\t\t\tconst headerEnd = block.indexOf(XTML_SEP, callStart + XTML_CALL_OPEN.length);\n\t\t\tif (headerEnd === -1) break;\n\t\t\tconst attributes = parseXtmlAttributes(block.slice(callStart + XTML_CALL_OPEN.length, headerEnd));\n\t\t\tconst bodyEnd = block.indexOf(XTML_CALL_CLOSE, headerEnd + XTML_SEP.length);\n\t\t\tconst callBody =\n\t\t\t\tbodyEnd === -1\n\t\t\t\t\t? block.slice(headerEnd + XTML_SEP.length)\n\t\t\t\t\t: block.slice(headerEnd + XTML_SEP.length, bodyEnd);\n\t\t\tcallCursor = bodyEnd === -1 ? block.length : bodyEnd + XTML_CALL_CLOSE.length;\n\n\t\t\tconst name = attributes.tool;\n\t\t\tconst tool = name ? tools.find((candidate) => candidate.name === name) : undefined;\n\t\t\tif (!tool) {\n\t\t\t\toptions?.onError?.(`kimi-xtml: call for unknown tool \"${name ?? \"\"}\".`, { toolCall: callBody });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst args = parseCallBody(callBody, tool, options);\n\t\t\tif (args) parsed.push({ name: tool.name, arguments: args });\n\t\t}\n\t}\n\treturn parsed;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recovery-content-lifecycle.d.ts","sourceRoot":"","sources":["../../src/tool-call-middleware/recovery-content-lifecycle.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,CAAC;AAInE,wEAAwE;AACxE,qBAAa,wBAAwB;IACpC,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,mBAAmB,CAAM;IAEjC,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO
|
|
1
|
+
{"version":3,"file":"recovery-content-lifecycle.d.ts","sourceRoot":"","sources":["../../src/tool-call-middleware/recovery-content-lifecycle.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,CAAC;AAInE,wEAAwE;AACxE,qBAAa,wBAAwB;IACpC,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,mBAAmB,CAAM;IAEjC,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAIrC,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,GAAG,IAAI;IAI1D,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,GAAG,OAAO;IAIhE,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,GAAG,OAAO;CAM3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recovery-event-stream.d.ts","sourceRoot":"","sources":["../../src/tool-call-middleware/recovery-event-stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAGvE,KAAK,mBAAmB,GAAG,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEtD,0FAA0F;AAC1F,qBAAa,mCAAoC,SAAQ,2BAA2B;IACnF,OAAO,CAAC,mBAAmB,CAAkC;IAC7D,OAAO,CAAC,mBAAmB,CAA4B;IACvD,OAAO,CAAC,YAAY,CAAS;IAE7B,sBAAsB,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI
|
|
1
|
+
{"version":3,"file":"recovery-event-stream.d.ts","sourceRoot":"","sources":["../../src/tool-call-middleware/recovery-event-stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAGvE,KAAK,mBAAmB,GAAG,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEtD,0FAA0F;AAC1F,qBAAa,mCAAoC,SAAQ,2BAA2B;IACnF,OAAO,CAAC,mBAAmB,CAAkC;IAC7D,OAAO,CAAC,mBAAmB,CAA4B;IACvD,OAAO,CAAC,YAAY,CAAS;IAE7B,sBAAsB,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI;IAI1D,gBAAgB,IAAI,OAAO;IAMlB,IAAI,CAAC,KAAK,EAAE,qBAAqB,GAAG,IAAI;IAIxC,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,qBAAqB,CAAC;CAevE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recovery-native-projection.d.ts","sourceRoot":"","sources":["../../src/tool-call-middleware/recovery-native-projection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC3F,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAepE,2FAA2F;AAC3F,qBAAa,wBAAwB;IACpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA8B;IACrD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;IAC3C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAmC;IACtE,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CAAsC;IAClF,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqB;IACjD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAqB;IAClD,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAA6B;IACtE,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,0BAA0B,CAAM;IACxC,OAAO,CAAC,eAAe,CAAK;
|
|
1
|
+
{"version":3,"file":"recovery-native-projection.d.ts","sourceRoot":"","sources":["../../src/tool-call-middleware/recovery-native-projection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC3F,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAepE,2F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AAM,EAAE,SAAS,iBAAiB,EAAE,GAAG,iBAAiB,EAAE;IAgB7E,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,WAAW;IAOnB,OAAO,CAAC,mBAAmB;CAU3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recovery-native-projection.js","sourceRoot":"","sources":["../../src/tool-call-middleware/recovery-native-projection.ts"],"names":[],"mappings":"AAOA,SAAS,iBAAiB,CAAC,KAAmB;IAC7C,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU;QAAE,OAAO,EAAE,GAAG,KAAK,EAAE,SAAS,EAAE,EAAE,GAAG,KAAK,CAAC,SAAS,EAAE,EAAE,CAAC;IACtF,OAAO,EAAE,GAAG,KAAK,EAAE,CAAC;AACrB,CAAC;AAED,SAAS,aAAa,CAAC,QAAkB;IACxC,OAAO,EAAE,GAAG,QAAQ,EAAE,SAAS,EAAE,EAAE,GAAG,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC;AAC9D,CAAC;AAED,2FAA2F;AAC3F,MAAM,OAAO,wBAAwB;IAYpC,YAAY,MAAmC,EAAE,OAAyB,EAAE,QAAQ,GAAmB,OAAO;QAT7F,uBAAkB,GAAG,IAAI,GAAG,EAAwB,CAAC;QACrD,gCAA2B,GAAG,IAAI,GAAG,EAA2B,CAAC;QACjE,gBAAW,GAAG,IAAI,GAAG,EAAU,CAAC;QAChC,iBAAY,GAAG,IAAI,GAAG,EAAU,CAAC;QACjC,6BAAwB,GAAG,IAAI,GAAG,EAAkB,CAAC;QAE9D,+BAA0B,GAAG,CAAC,CAAC,CAAC;QAChC,oBAAe,GAAG,CAAC,CAAC;QAG3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,iBAAiB,GAAG,aAAa,QAAQ,GAAG,CAAC;IACnD,CAAC;IAED,iBAAiB,CAAC,MAAwB;QACzC,KAAK,MAAM,KAAK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D","sourcesContent":["import type { AssistantMessage, AssistantMessageEventStream, ToolCall } from \"../types.ts\";\nimport type { StreamParserEvent, ToolCallFormat } from \"./types.ts\";\n\ntype ContentBlock = AssistantMessage[\"content\"][number];\ntype ContentRange = { start: number; end: number };\ntype NativeLifecycle = \"started\" | \"ended\";\n\nfunction cloneContentBlock(block: ContentBlock): ContentBlock {\n\tif (block.type === \"toolCall\") return { ...block, arguments: { ...block.arguments } };\n\treturn { ...block };\n}\n\nfunction cloneToolCall(toolCall: ToolCall): ToolCall {\n\treturn { ...toolCall, arguments: { ...toolCall.arguments } };\n}\n\n/** Maintains source-index order and native/recovered ID ownership for recovery streams. */\nexport class RecoveryNativeProjection {\n\tprivate readonly stream: AssistantMessageEventStream;\n\tprivate readonly message: AssistantMessage;\n\tprivate readonly rangesByInnerIndex = new Map<number, ContentRange>();\n\tprivate readonly nativeLifecycleByInnerIndex = new Map<number, NativeLifecycle>();\n\tprivate readonly reservedIds = new Set<string>();\n\tprivate readonly recoveredIds = new Set<string>();\n\tprivate readonly recoveredIdByParserIndex = new Map<number, string>();\n\tprivate readonly recoveredIdPrefix: string;\n\tprivate highestProjectedInnerIndex = -1;\n\tprivate nextRecoveredId = 0;\n\n\tconstructor(stream: AssistantMessageEventStream, message: AssistantMessage, protocol: ToolCallFormat = \"antml\") {\n\t\tthis.stream = stream;\n\t\tthis.message = message;\n\t\tthis.recoveredIdPrefix = `recovered-${protocol}-`;\n\t}\n\n\treserveVisibleIds(source: AssistantMessage): void {\n\t\tfor (const block of source.content) {\n\t\t\tif (block.type === \"toolCall\") this.reservedIds.add(block.id);\n\t\t}\n\t}\n\n\tsynchronizeLower(source: AssistantMessage, contentIndex: number): boolean {\n\t\tfor (let innerIndex = 0; innerIndex < contentIndex && innerIndex < source.content.length; innerIndex += 1) {\n\t\t\tif (this.rangesByInnerIndex.has(innerIndex)) continue;\n\t\t\tif (!this.appendUnannounced(source, innerIndex)) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tsynchronizeRemaining(source: AssistantMessage): boolean {\n\t\tfor (let innerIndex = 0; innerIndex < source.content.length; innerIndex += 1) {\n\t\t\tif (this.rangesByInnerIndex.has(innerIndex)) continue;\n\t\t\tif (!this.appendUnannounced(source, innerIndex)) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tstartText(innerIndex: number, outerIndex: number): boolean {\n\t\tif (!this.recordRange(innerIndex, { start: outerIndex, end: this.message.content.length })) return false;\n\t\treturn true;\n\t}\n\n\trecordProjectedBlock(innerIndex: number, outerIndex: number): boolean {\n\t\treturn this.recordRange(innerIndex, { start: outerIndex, end: outerIndex + 1 });\n\t}\n\n\textendText(innerIndex: number): void {\n\t\tconst range = this.rangesByInnerIndex.get(innerIndex);\n\t\tif (range) range.end = this.message.content.length;\n\t}\n\n\tprojectNativeStart(source: AssistantMessage, innerIndex: number): \"projected\" | \"collision\" | \"invalid\" {\n\t\tif (this.nativeLifecycleByInnerIndex.has(innerIndex) || this.rangesByInnerIndex.has(innerIndex)) return \"invalid\";\n\t\tconst block = source.content[innerIndex];\n\t\tif (block?.type !== \"toolCall\" || innerIndex <= this.highestProjectedInnerIndex) return \"invalid\";\n\t\tif (this.recoveredIds.has(block.id)) return \"collision\";\n\t\tthis.reservedIds.add(block.id);\n\t\tconst outerIndex = this.message.content.length;\n\t\tthis.message.content.push(cloneContentBlock(block));\n\t\tif (!this.recordRange(innerIndex, { start: outerIndex, end: outerIndex + 1 })) return \"invalid\";\n\t\tthis.nativeLifecycleByInnerIndex.set(innerIndex, \"started\");\n\t\tthis.stream.push({ type: \"toolcall_start\", contentIndex: outerIndex, partial: this.message });\n\t\treturn \"projected\";\n\t}\n\n\tprojectNativeDelta(source: AssistantMessage, innerIndex: number, delta: string): boolean {\n\t\tif (this.nativeLifecycleByInnerIndex.get(innerIndex) !== \"started\") return false;\n\t\tconst outerIndex = this.rangesByInnerIndex.get(innerIndex)?.start;\n\t\tconst block = source.content[innerIndex];\n\t\tif (outerIndex == null || block?.type !== \"toolCall\") return false;\n\t\tthis.message.content[outerIndex] = cloneContentBlock(block);\n\t\tthis.stream.push({ type: \"toolcall_delta\", contentIndex: outerIndex, delta, partial: this.message });\n\t\treturn true;\n\t}\n\n\tprojectNativeEnd(innerIndex: number, toolCall: ToolCall): boolean {\n\t\tif (this.nativeLifecycleByInnerIndex.get(innerIndex) !== \"started\") return false;\n\t\tconst outerIndex = this.rangesByInnerIndex.get(innerIndex)?.start;\n\t\tif (outerIndex == null) return false;\n\t\tconst finalToolCall = cloneToolCall(toolCall);\n\t\tthis.message.content[outerIndex] = finalToolCall;\n\t\tthis.nativeLifecycleByInnerIndex.set(innerIndex, \"ended\");\n\t\tthis.stream.push({\n\t\t\ttype: \"toolcall_end\",\n\t\t\tcontentIndex: outerIndex,\n\t\t\ttoolCall: finalToolCall,\n\t\t\tpartial: this.message,\n\t\t});\n\t\treturn true;\n\t}\n\n\tassignRecoveredIds(events: readonly StreamParserEvent[]): StreamParserEvent[] {\n\t\treturn events.map((event) => {\n\t\t\tif (event.type === \"toolcall_start\") {\n\t\t\t\tconst id = this.allocateRecoveredId();\n\t\t\t\tthis.recoveredIdByParserIndex.set(event.index, id);\n\t\t\t\treturn { ...event, id };\n\t\t\t}\n\t\t\tif (event.type === \"toolcall_end\") {\n\t\t\t\tconst id = this.recoveredIdByParserIndex.get(event.index) ?? event.id;\n\t\t\t\tthis.recoveredIdByParserIndex.delete(event.index);\n\t\t\t\treturn { ...event, id };\n\t\t\t}\n\t\t\treturn event;\n\t\t});\n\t}\n\n\tprivate appendUnannounced(source: AssistantMessage, innerIndex: number): boolean {\n\t\tconst block = source.content[innerIndex];\n\t\tif (!block || innerIndex <= this.highestProjectedInnerIndex) return false;\n\t\tif (block.type === \"toolCall\" && this.recoveredIds.has(block.id)) return false;\n\t\tconst outerIndex = this.message.content.length;\n\t\tthis.message.content.push(cloneContentBlock(block));\n\t\treturn this.recordRange(innerIndex, { start: outerIndex, end: outerIndex + 1 });\n\t}\n\n\tprivate recordRange(innerIndex: number, range: ContentRange): boolean {\n\t\tif (this.rangesByInnerIndex.has(innerIndex) || innerIndex <= this.highestProjectedInnerIndex) return false;\n\t\tthis.rangesByInnerIndex.set(innerIndex, range);\n\t\tthis.highestProjectedInnerIndex = innerIndex;\n\t\treturn true;\n\t}\n\n\tprivate allocateRecoveredId(): string {\n\t\tfor (;;) {\n\t\t\tconst id = `${this.recoveredIdPrefix}${this.nextRecoveredId}`;\n\t\t\tthis.nextRecoveredId += 1;\n\t\t\tif (this.reservedIds.has(id)) continue;\n\t\t\tthis.reservedIds.add(id);\n\t\t\tthis.recoveredIds.add(id);\n\t\t\treturn id;\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"recovery-native-projection.js","sourceRoot":"","sources":["../../src/tool-call-middleware/recovery-native-projection.ts"],"names":[],"mappings":"AAOA,SAAS,iBAAiB,CAAC,KAAmB;IAC7C,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU;QAAE,OAAO,EAAE,GAAG,KAAK,EAAE,SAAS,EAAE,EAAE,GAAG,KAAK,CAAC,SAAS,EAAE,EAAE,CAAC;IACtF,OAAO,EAAE,GAAG,KAAK,EAAE,CAAC;AACrB,CAAC;AAED,SAAS,aAAa,CAAC,QAAkB;IACxC,OAAO,EAAE,GAAG,QAAQ,EAAE,SAAS,EAAE,EAAE,GAAG,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC;AAC9D,CAAC;AAED,2FAA2F;AAC3F,MAAM,OAAO,wBAAwB;IAYpC,YAAY,MAAmC,EAAE,OAAyB,EAAE,WAA2B,OAAO;QAT7F,uBAAkB,GAAG,IAAI,GAAG,EAAwB,CAAC;QACrD,gCAA2B,GAAG,IAAI,GAAG,EAA2B,CAAC;QACjE,gBAAW,GAAG,IAAI,GAAG,EAAU,CAAC;QAChC,iBAAY,GAAG,IAAI,GAAG,EAAU,CAAC;QACjC,6BAAwB,GAAG,IAAI,GAAG,EAAkB,CAAC;QAE9D,+BAA0B,GAAG,CAAC,CAA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YAC1B,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;gBAAE,SAAS;YACvC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACzB,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAC1B,OAAO,EAAE,CAAC;QACX,CAAC;IACF,CAAC;CACD","sourcesContent":["import type { AssistantMessage, AssistantMessageEventStream, ToolCall } from \"../types.ts\";\nimport type { StreamParserEvent, ToolCallFormat } from \"./types.ts\";\n\ntype ContentBlock = AssistantMessage[\"content\"][number];\ntype ContentRange = { start: number; end: number };\ntype NativeLifecycle = \"started\" | \"ended\";\n\nfunction cloneContentBlock(block: ContentBlock): ContentBlock {\n\tif (block.type === \"toolCall\") return { ...block, arguments: { ...block.arguments } };\n\treturn { ...block };\n}\n\nfunction cloneToolCall(toolCall: ToolCall): ToolCall {\n\treturn { ...toolCall, arguments: { ...toolCall.arguments } };\n}\n\n/** Maintains source-index order and native/recovered ID ownership for recovery streams. */\nexport class RecoveryNativeProjection {\n\tprivate readonly stream: AssistantMessageEventStream;\n\tprivate readonly message: AssistantMessage;\n\tprivate readonly rangesByInnerIndex = new Map<number, ContentRange>();\n\tprivate readonly nativeLifecycleByInnerIndex = new Map<number, NativeLifecycle>();\n\tprivate readonly reservedIds = new Set<string>();\n\tprivate readonly recoveredIds = new Set<string>();\n\tprivate readonly recoveredIdByParserIndex = new Map<number, string>();\n\tprivate readonly recoveredIdPrefix: string;\n\tprivate highestProjectedInnerIndex = -1;\n\tprivate nextRecoveredId = 0;\n\n\tconstructor(stream: AssistantMessageEventStream, message: AssistantMessage, protocol: ToolCallFormat = \"antml\") {\n\t\tthis.stream = stream;\n\t\tthis.message = message;\n\t\tthis.recoveredIdPrefix = `recovered-${protocol}-`;\n\t}\n\n\treserveVisibleIds(source: AssistantMessage): void {\n\t\tfor (const block of source.content) {\n\t\t\tif (block.type === \"toolCall\") this.reservedIds.add(block.id);\n\t\t}\n\t}\n\n\tsynchronizeLower(source: AssistantMessage, contentIndex: number): boolean {\n\t\tfor (let innerIndex = 0; innerIndex < contentIndex && innerIndex < source.content.length; innerIndex += 1) {\n\t\t\tif (this.rangesByInnerIndex.has(innerIndex)) continue;\n\t\t\tif (!this.appendUnannounced(source, innerIndex)) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tsynchronizeRemaining(source: AssistantMessage): boolean {\n\t\tfor (let innerIndex = 0; innerIndex < source.content.length; innerIndex += 1) {\n\t\t\tif (this.rangesByInnerIndex.has(innerIndex)) continue;\n\t\t\tif (!this.appendUnannounced(source, innerIndex)) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tstartText(innerIndex: number, outerIndex: number): boolean {\n\t\tif (!this.recordRange(innerIndex, { start: outerIndex, end: this.message.content.length })) return false;\n\t\treturn true;\n\t}\n\n\trecordProjectedBlock(innerIndex: number, outerIndex: number): boolean {\n\t\treturn this.recordRange(innerIndex, { start: outerIndex, end: outerIndex + 1 });\n\t}\n\n\textendText(innerIndex: number): void {\n\t\tconst range = this.rangesByInnerIndex.get(innerIndex);\n\t\tif (range) range.end = this.message.content.length;\n\t}\n\n\tprojectNativeStart(source: AssistantMessage, innerIndex: number): \"projected\" | \"collision\" | \"invalid\" {\n\t\tif (this.nativeLifecycleByInnerIndex.has(innerIndex) || this.rangesByInnerIndex.has(innerIndex)) return \"invalid\";\n\t\tconst block = source.content[innerIndex];\n\t\tif (block?.type !== \"toolCall\" || innerIndex <= this.highestProjectedInnerIndex) return \"invalid\";\n\t\tif (this.recoveredIds.has(block.id)) return \"collision\";\n\t\tthis.reservedIds.add(block.id);\n\t\tconst outerIndex = this.message.content.length;\n\t\tthis.message.content.push(cloneContentBlock(block));\n\t\tif (!this.recordRange(innerIndex, { start: outerIndex, end: outerIndex + 1 })) return \"invalid\";\n\t\tthis.nativeLifecycleByInnerIndex.set(innerIndex, \"started\");\n\t\tthis.stream.push({ type: \"toolcall_start\", contentIndex: outerIndex, partial: this.message });\n\t\treturn \"projected\";\n\t}\n\n\tprojectNativeDelta(source: AssistantMessage, innerIndex: number, delta: string): boolean {\n\t\tif (this.nativeLifecycleByInnerIndex.get(innerIndex) !== \"started\") return false;\n\t\tconst outerIndex = this.rangesByInnerIndex.get(innerIndex)?.start;\n\t\tconst block = source.content[innerIndex];\n\t\tif (outerIndex == null || block?.type !== \"toolCall\") return false;\n\t\tthis.message.content[outerIndex] = cloneContentBlock(block);\n\t\tthis.stream.push({ type: \"toolcall_delta\", contentIndex: outerIndex, delta, partial: this.message });\n\t\treturn true;\n\t}\n\n\tprojectNativeEnd(innerIndex: number, toolCall: ToolCall): boolean {\n\t\tif (this.nativeLifecycleByInnerIndex.get(innerIndex) !== \"started\") return false;\n\t\tconst outerIndex = this.rangesByInnerIndex.get(innerIndex)?.start;\n\t\tif (outerIndex == null) return false;\n\t\tconst finalToolCall = cloneToolCall(toolCall);\n\t\tthis.message.content[outerIndex] = finalToolCall;\n\t\tthis.nativeLifecycleByInnerIndex.set(innerIndex, \"ended\");\n\t\tthis.stream.push({\n\t\t\ttype: \"toolcall_end\",\n\t\t\tcontentIndex: outerIndex,\n\t\t\ttoolCall: finalToolCall,\n\t\t\tpartial: this.message,\n\t\t});\n\t\treturn true;\n\t}\n\n\tassignRecoveredIds(events: readonly StreamParserEvent[]): StreamParserEvent[] {\n\t\treturn events.map((event) => {\n\t\t\tif (event.type === \"toolcall_start\") {\n\t\t\t\tconst id = this.allocateRecoveredId();\n\t\t\t\tthis.recoveredIdByParserIndex.set(event.index, id);\n\t\t\t\treturn { ...event, id };\n\t\t\t}\n\t\t\tif (event.type === \"toolcall_end\") {\n\t\t\t\tconst id = this.recoveredIdByParserIndex.get(event.index) ?? event.id;\n\t\t\t\tthis.recoveredIdByParserIndex.delete(event.index);\n\t\t\t\treturn { ...event, id };\n\t\t\t}\n\t\t\treturn event;\n\t\t});\n\t}\n\n\tprivate appendUnannounced(source: AssistantMessage, innerIndex: number): boolean {\n\t\tconst block = source.content[innerIndex];\n\t\tif (!block || innerIndex <= this.highestProjectedInnerIndex) return false;\n\t\tif (block.type === \"toolCall\" && this.recoveredIds.has(block.id)) return false;\n\t\tconst outerIndex = this.message.content.length;\n\t\tthis.message.content.push(cloneContentBlock(block));\n\t\treturn this.recordRange(innerIndex, { start: outerIndex, end: outerIndex + 1 });\n\t}\n\n\tprivate recordRange(innerIndex: number, range: ContentRange): boolean {\n\t\tif (this.rangesByInnerIndex.has(innerIndex) || innerIndex <= this.highestProjectedInnerIndex) return false;\n\t\tthis.rangesByInnerIndex.set(innerIndex, range);\n\t\tthis.highestProjectedInnerIndex = innerIndex;\n\t\treturn true;\n\t}\n\n\tprivate allocateRecoveredId(): string {\n\t\tfor (;;) {\n\t\t\tconst id = `${this.recoveredIdPrefix}${this.nextRecoveredId}`;\n\t\t\tthis.nextRecoveredId += 1;\n\t\t\tif (this.reservedIds.has(id)) continue;\n\t\t\tthis.reservedIds.add(id);\n\t\t\tthis.recoveredIds.add(id);\n\t\t\treturn id;\n\t\t}\n\t}\n}\n"]}
|