@cloudflare/tanstack-ai 0.1.2 → 0.1.4
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 +42 -0
- package/dist/_tsup-dts-rollup.d.cts +13 -4
- package/dist/_tsup-dts-rollup.d.ts +13 -4
- package/dist/adapters/anthropic.cjs +3 -3
- package/dist/adapters/anthropic.js +2 -2
- package/dist/adapters/grok.cjs +3 -3
- package/dist/adapters/grok.js +2 -2
- package/dist/adapters/openai.cjs +3 -3
- package/dist/adapters/openai.js +2 -2
- package/dist/adapters/openrouter.cjs +3 -3
- package/dist/adapters/openrouter.js +2 -2
- package/dist/adapters/workers-ai-image.cjs +3 -3
- package/dist/adapters/workers-ai-image.js +2 -2
- package/dist/adapters/workers-ai-summarize.cjs +3 -3
- package/dist/adapters/workers-ai-summarize.js +2 -2
- package/dist/adapters/workers-ai-transcription.cjs +3 -3
- package/dist/adapters/workers-ai-transcription.js +2 -2
- package/dist/adapters/workers-ai-tts.cjs +3 -3
- package/dist/adapters/workers-ai-tts.js +2 -2
- package/dist/adapters/workers-ai.cjs +3 -3
- package/dist/adapters/workers-ai.js +2 -2
- package/dist/{chunk-LG2I3ANT.cjs → chunk-32U73O6E.cjs} +49 -33
- package/dist/chunk-32U73O6E.cjs.map +1 -0
- package/dist/{chunk-ZHTFBZXJ.cjs → chunk-3PJHW45X.cjs} +6 -6
- package/dist/{chunk-ZHTFBZXJ.cjs.map → chunk-3PJHW45X.cjs.map} +1 -1
- package/dist/{chunk-T5KPTTLK.js → chunk-DG46OSFY.js} +2 -2
- package/dist/{chunk-IDPLTBQX.cjs → chunk-H24HFVUJ.cjs} +6 -6
- package/dist/{chunk-IDPLTBQX.cjs.map → chunk-H24HFVUJ.cjs.map} +1 -1
- package/dist/{chunk-JK5ZFOZZ.js → chunk-I2MCLFJ5.js} +2 -2
- package/dist/{chunk-OKU3GB5P.js → chunk-IPEZXCDR.js} +2 -2
- package/dist/{chunk-ARLHMZ5B.cjs → chunk-KDVHOUEP.cjs} +6 -6
- package/dist/{chunk-ARLHMZ5B.cjs.map → chunk-KDVHOUEP.cjs.map} +1 -1
- package/dist/{chunk-UWBO33IG.cjs → chunk-KW27GIQL.cjs} +5 -5
- package/dist/{chunk-UWBO33IG.cjs.map → chunk-KW27GIQL.cjs.map} +1 -1
- package/dist/{chunk-7KZQWFUE.cjs → chunk-MMTLH53H.cjs} +3 -3
- package/dist/chunk-MMTLH53H.cjs.map +1 -0
- package/dist/{chunk-DSBHOQQ4.js → chunk-MOAWHNNP.js} +2 -2
- package/dist/chunk-MOAWHNNP.js.map +1 -0
- package/dist/{chunk-3KUHT3K6.js → chunk-NSWLVANP.js} +46 -30
- package/dist/chunk-NSWLVANP.js.map +1 -0
- package/dist/{chunk-Y7W7NDVS.js → chunk-OGAH3FYW.js} +2 -2
- package/dist/{chunk-2QN5XFI2.js → chunk-QMRONSLN.js} +2 -2
- package/dist/{chunk-5A2F2QCL.js → chunk-RWLCEKT6.js} +2 -2
- package/dist/{chunk-O7MBRPCW.js → chunk-S5QBHI6O.js} +26 -29
- package/dist/chunk-S5QBHI6O.js.map +1 -0
- package/dist/{chunk-ICHJ2G63.cjs → chunk-TG4UQPGB.cjs} +3 -3
- package/dist/{chunk-ICHJ2G63.cjs.map → chunk-TG4UQPGB.cjs.map} +1 -1
- package/dist/{chunk-7SKFZ4SU.cjs → chunk-U2PMR3PT.cjs} +5 -5
- package/dist/{chunk-7SKFZ4SU.cjs.map → chunk-U2PMR3PT.cjs.map} +1 -1
- package/dist/{chunk-IMURYJRF.cjs → chunk-U5NL4EM4.cjs} +33 -36
- package/dist/chunk-U5NL4EM4.cjs.map +1 -0
- package/dist/{chunk-AYTKQRE4.cjs → chunk-XFQ3QESX.cjs} +6 -6
- package/dist/{chunk-AYTKQRE4.cjs.map → chunk-XFQ3QESX.cjs.map} +1 -1
- package/dist/{chunk-DZZVI4W5.js → chunk-ZJMMBD6H.js} +2 -2
- package/dist/index.cjs +11 -11
- package/dist/index.js +10 -10
- package/package.json +11 -10
- package/dist/chunk-3KUHT3K6.js.map +0 -1
- package/dist/chunk-7KZQWFUE.cjs.map +0 -1
- package/dist/chunk-DSBHOQQ4.js.map +0 -1
- package/dist/chunk-IMURYJRF.cjs.map +0 -1
- package/dist/chunk-LG2I3ANT.cjs.map +0 -1
- package/dist/chunk-O7MBRPCW.js.map +0 -1
- /package/dist/{chunk-T5KPTTLK.js.map → chunk-DG46OSFY.js.map} +0 -0
- /package/dist/{chunk-JK5ZFOZZ.js.map → chunk-I2MCLFJ5.js.map} +0 -0
- /package/dist/{chunk-OKU3GB5P.js.map → chunk-IPEZXCDR.js.map} +0 -0
- /package/dist/{chunk-Y7W7NDVS.js.map → chunk-OGAH3FYW.js.map} +0 -0
- /package/dist/{chunk-2QN5XFI2.js.map → chunk-QMRONSLN.js.map} +0 -0
- /package/dist/{chunk-5A2F2QCL.js.map → chunk-RWLCEKT6.js.map} +0 -0
- /package/dist/{chunk-DZZVI4W5.js.map → chunk-ZJMMBD6H.js.map} +0 -0
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
isDirectBindingConfig,
|
|
5
5
|
isDirectCredentialsConfig,
|
|
6
6
|
validateWorkersAiConfig
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-S5QBHI6O.js";
|
|
8
8
|
import {
|
|
9
9
|
__publicField
|
|
10
10
|
} from "./chunk-V6TY7KAL.js";
|
|
@@ -16,50 +16,69 @@ import {
|
|
|
16
16
|
import OpenAI from "openai";
|
|
17
17
|
function buildWorkersAiClient(config) {
|
|
18
18
|
validateWorkersAiConfig(config);
|
|
19
|
+
const sessionHeaders = config.sessionAffinity ? { "x-session-affinity": config.sessionAffinity } : void 0;
|
|
19
20
|
if (isDirectBindingConfig(config)) {
|
|
20
21
|
return new OpenAI({
|
|
21
22
|
apiKey: "unused",
|
|
22
|
-
fetch: createWorkersAiBindingFetch(
|
|
23
|
+
fetch: createWorkersAiBindingFetch(
|
|
24
|
+
config.binding,
|
|
25
|
+
sessionHeaders ? { extraHeaders: sessionHeaders } : void 0
|
|
26
|
+
)
|
|
23
27
|
});
|
|
24
28
|
}
|
|
25
29
|
if (isDirectCredentialsConfig(config)) {
|
|
26
30
|
return new OpenAI({
|
|
27
31
|
baseURL: `https://api.cloudflare.com/client/v4/accounts/${config.accountId}/ai/v1`,
|
|
28
|
-
apiKey: config.apiKey
|
|
32
|
+
apiKey: config.apiKey,
|
|
33
|
+
defaultHeaders: sessionHeaders
|
|
29
34
|
});
|
|
30
35
|
}
|
|
31
36
|
const gatewayConfig = config;
|
|
32
37
|
return new OpenAI({
|
|
33
|
-
fetch: createGatewayFetch("workers-ai", gatewayConfig),
|
|
38
|
+
fetch: createGatewayFetch("workers-ai", gatewayConfig, sessionHeaders),
|
|
34
39
|
apiKey: gatewayConfig.apiKey ?? "unused"
|
|
35
40
|
});
|
|
36
41
|
}
|
|
37
42
|
function extractTextContent(content) {
|
|
38
43
|
if (content === null) return "";
|
|
39
44
|
if (typeof content === "string") return content;
|
|
40
|
-
return content.
|
|
45
|
+
return content.flatMap((p) => p.type === "text" ? [p.content] : []).join("");
|
|
46
|
+
}
|
|
47
|
+
function convertContentPart(part) {
|
|
48
|
+
switch (part.type) {
|
|
49
|
+
case "text":
|
|
50
|
+
if (part.content) {
|
|
51
|
+
return { type: "text", text: part.content };
|
|
52
|
+
}
|
|
53
|
+
return void 0;
|
|
54
|
+
case "image": {
|
|
55
|
+
let url;
|
|
56
|
+
if (part.source.type === "data") {
|
|
57
|
+
url = part.source.value.startsWith("data:") ? part.source.value : `data:${part.source.mimeType};base64,${part.source.value}`;
|
|
58
|
+
} else {
|
|
59
|
+
url = part.source.value;
|
|
60
|
+
}
|
|
61
|
+
return { type: "image_url", image_url: { url } };
|
|
62
|
+
}
|
|
63
|
+
default:
|
|
64
|
+
console.warn(
|
|
65
|
+
`[@cloudflare/tanstack-ai] Unsupported content part type "${part.type}" \u2014 skipping`
|
|
66
|
+
);
|
|
67
|
+
return void 0;
|
|
68
|
+
}
|
|
41
69
|
}
|
|
42
70
|
function buildUserContent(content) {
|
|
43
71
|
if (content === null) return "";
|
|
44
72
|
if (typeof content === "string") return content;
|
|
45
|
-
const hasImages = content.some((p) => p.type === "
|
|
73
|
+
const hasImages = content.some((p) => p.type === "image");
|
|
46
74
|
if (!hasImages) {
|
|
47
|
-
return content.
|
|
75
|
+
return content.flatMap((p) => p.type === "text" ? [p.content] : []).join("");
|
|
48
76
|
}
|
|
49
77
|
const parts = [];
|
|
50
78
|
for (const part of content) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
parts.push({
|
|
55
|
-
type: "image_url",
|
|
56
|
-
image_url: { url: part.content }
|
|
57
|
-
});
|
|
58
|
-
} else if (part.type === "image_url" && part.image_url) {
|
|
59
|
-
parts.push({
|
|
60
|
-
type: "image_url",
|
|
61
|
-
image_url: part.image_url
|
|
62
|
-
});
|
|
79
|
+
const converted = convertContentPart(part);
|
|
80
|
+
if (converted) {
|
|
81
|
+
parts.push(converted);
|
|
63
82
|
}
|
|
64
83
|
}
|
|
65
84
|
return parts;
|
|
@@ -127,8 +146,8 @@ function buildOpenAITools(tools) {
|
|
|
127
146
|
}
|
|
128
147
|
}));
|
|
129
148
|
}
|
|
130
|
-
function generateId(prefix) {
|
|
131
|
-
return `${prefix}-${crypto.randomUUID()}`;
|
|
149
|
+
function generateId(prefix = "chatcmpl") {
|
|
150
|
+
return `${prefix}-${crypto.randomUUID().replace(/-/g, "").slice(0, 16)}`;
|
|
132
151
|
}
|
|
133
152
|
var WorkersAiTextAdapter = class extends BaseTextAdapter {
|
|
134
153
|
constructor(model, config) {
|
|
@@ -142,14 +161,14 @@ var WorkersAiTextAdapter = class extends BaseTextAdapter {
|
|
|
142
161
|
const openAIMessages = buildOpenAIMessages(systemPrompts, messages);
|
|
143
162
|
const openAITools = buildOpenAITools(tools);
|
|
144
163
|
const timestamp = Date.now();
|
|
145
|
-
const runId = generateId(
|
|
146
|
-
const messageId = generateId(
|
|
164
|
+
const runId = generateId();
|
|
165
|
+
const messageId = generateId();
|
|
147
166
|
let hasEmittedRunStarted = false;
|
|
148
167
|
let hasEmittedTextMessageStart = false;
|
|
149
168
|
let accumulatedContent = "";
|
|
150
169
|
let hasEmittedStepStarted = false;
|
|
151
170
|
let accumulatedReasoning = "";
|
|
152
|
-
const stepId = generateId(
|
|
171
|
+
const stepId = generateId();
|
|
153
172
|
let hasReceivedFinishReason = false;
|
|
154
173
|
const toolCallsInProgress = /* @__PURE__ */ new Map();
|
|
155
174
|
try {
|
|
@@ -261,7 +280,7 @@ var WorkersAiTextAdapter = class extends BaseTextAdapter {
|
|
|
261
280
|
};
|
|
262
281
|
}
|
|
263
282
|
const delta = choice.delta;
|
|
264
|
-
const reasoningContent = delta.reasoning_content;
|
|
283
|
+
const reasoningContent = delta.reasoning_content ?? delta.reasoning;
|
|
265
284
|
if (reasoningContent) {
|
|
266
285
|
if (!hasEmittedStepStarted) {
|
|
267
286
|
hasEmittedStepStarted = true;
|
|
@@ -309,16 +328,13 @@ var WorkersAiTextAdapter = class extends BaseTextAdapter {
|
|
|
309
328
|
const index = toolCallDelta.index;
|
|
310
329
|
if (!toolCallsInProgress.has(index)) {
|
|
311
330
|
toolCallsInProgress.set(index, {
|
|
312
|
-
id:
|
|
331
|
+
id: generateId("chatcmpl-tool"),
|
|
313
332
|
name: toolCallDelta.function?.name || "",
|
|
314
333
|
arguments: "",
|
|
315
334
|
started: false
|
|
316
335
|
});
|
|
317
336
|
}
|
|
318
337
|
const toolCall = toolCallsInProgress.get(index);
|
|
319
|
-
if (toolCallDelta.id) {
|
|
320
|
-
toolCall.id = toolCallDelta.id;
|
|
321
|
-
}
|
|
322
338
|
if (toolCallDelta.function?.name) {
|
|
323
339
|
toolCall.name = toolCallDelta.function.name;
|
|
324
340
|
}
|
|
@@ -502,4 +518,4 @@ export {
|
|
|
502
518
|
WorkersAiTextAdapter,
|
|
503
519
|
createWorkersAiChat
|
|
504
520
|
};
|
|
505
|
-
//# sourceMappingURL=chunk-
|
|
521
|
+
//# sourceMappingURL=chunk-NSWLVANP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/adapters/workers-ai.ts"],"sourcesContent":["import type { AiModels, BaseAiTextGeneration } from \"@cloudflare/workers-types\";\nimport type { ContentPart, ModelMessage, StreamChunk, TextOptions } from \"@tanstack/ai\";\nimport {\n\tBaseTextAdapter,\n\ttype StructuredOutputOptions,\n\ttype StructuredOutputResult,\n} from \"@tanstack/ai/adapters\";\nimport OpenAI from \"openai\";\nimport {\n\ttype WorkersAiAdapterConfig,\n\ttype AiGatewayAdapterConfig,\n\tcreateGatewayFetch,\n\tcreateWorkersAiBindingFetch,\n\tisDirectBindingConfig,\n\tisDirectCredentialsConfig,\n\tvalidateWorkersAiConfig,\n} from \"../utils/create-fetcher\";\n\n// ---------------------------------------------------------------------------\n// Model types derived from @cloudflare/workers-types\n// ---------------------------------------------------------------------------\n\nexport type WorkersAiTextModel =\n\t| {\n\t\t\t[K in keyof AiModels]: AiModels[K] extends BaseAiTextGeneration ? K : never;\n\t }[keyof AiModels]\n\t| (string & {});\n\n// ---------------------------------------------------------------------------\n// Helpers: build the right OpenAI client depending on config mode\n// ---------------------------------------------------------------------------\n\nfunction buildWorkersAiClient(config: WorkersAiAdapterConfig): OpenAI {\n\tvalidateWorkersAiConfig(config);\n\n\tconst sessionHeaders: Record<string, string> | undefined = config.sessionAffinity\n\t\t? { \"x-session-affinity\": config.sessionAffinity }\n\t\t: undefined;\n\n\tif (isDirectBindingConfig(config)) {\n\t\t// Plain binding mode: shim translates OpenAI fetch calls to env.AI.run()\n\t\treturn new OpenAI({\n\t\t\tapiKey: \"unused\",\n\t\t\tfetch: createWorkersAiBindingFetch(\n\t\t\t\tconfig.binding,\n\t\t\t\tsessionHeaders ? { extraHeaders: sessionHeaders } : undefined,\n\t\t\t),\n\t\t});\n\t}\n\n\tif (isDirectCredentialsConfig(config)) {\n\t\t// Plain REST mode: point OpenAI SDK at Workers AI's OpenAI-compatible endpoint\n\t\treturn new OpenAI({\n\t\t\tbaseURL: `https://api.cloudflare.com/client/v4/accounts/${config.accountId}/ai/v1`,\n\t\t\tapiKey: config.apiKey,\n\t\t\tdefaultHeaders: sessionHeaders,\n\t\t});\n\t}\n\n\t// Gateway mode (existing): use createGatewayFetch\n\tconst gatewayConfig = config as AiGatewayAdapterConfig;\n\treturn new OpenAI({\n\t\tfetch: createGatewayFetch(\"workers-ai\", gatewayConfig, sessionHeaders),\n\t\tapiKey: gatewayConfig.apiKey ?? \"unused\",\n\t});\n}\n\n// ---------------------------------------------------------------------------\n// Shared message-building helpers\n// ---------------------------------------------------------------------------\n\nfunction extractTextContent(content: ModelMessage[\"content\"]): string {\n\tif (content === null) return \"\";\n\tif (typeof content === \"string\") return content;\n\treturn content.flatMap((p) => (p.type === \"text\" ? [p.content] : [])).join(\"\");\n}\n\n/**\n * Convert a single TanStack AI {@link ContentPart} to the OpenAI Chat\n * Completions multi-modal format.\n *\n * TODO: handle other content types (audio, video, document)\n */\nfunction convertContentPart(part: ContentPart): OpenAI.Chat.ChatCompletionContentPart | undefined {\n\tswitch (part.type) {\n\t\tcase \"text\":\n\t\t\tif (part.content) {\n\t\t\t\treturn { type: \"text\", text: part.content };\n\t\t\t}\n\t\t\treturn undefined;\n\t\tcase \"image\": {\n\t\t\tlet url: string;\n\t\t\tif (part.source.type === \"data\") {\n\t\t\t\turl = part.source.value.startsWith(\"data:\")\n\t\t\t\t\t? part.source.value\n\t\t\t\t\t: `data:${part.source.mimeType};base64,${part.source.value}`;\n\t\t\t} else {\n\t\t\t\turl = part.source.value;\n\t\t\t}\n\t\t\treturn { type: \"image_url\", image_url: { url } };\n\t\t}\n\t\tdefault:\n\t\t\t// audio, video, document — not supported for now\n\t\t\tconsole.warn(\n\t\t\t\t`[@cloudflare/tanstack-ai] Unsupported content part type \"${part.type}\" — skipping`,\n\t\t\t);\n\t\t\treturn undefined;\n\t}\n}\n\n/**\n * Build OpenAI-compatible user message content from TanStack AI content.\n *\n * If the content has only text parts, returns a plain string.\n * If it includes image parts, returns an array of content parts in\n * OpenAI's multi-modal format (text + image_url).\n */\nfunction buildUserContent(\n\tcontent: ModelMessage[\"content\"],\n): string | OpenAI.Chat.ChatCompletionContentPart[] {\n\tif (content === null) return \"\";\n\tif (typeof content === \"string\") return content;\n\n\tconst hasImages = content.some((p) => p.type === \"image\");\n\tif (!hasImages) {\n\t\treturn content.flatMap((p) => (p.type === \"text\" ? [p.content] : [])).join(\"\");\n\t}\n\n\tconst parts: OpenAI.Chat.ChatCompletionContentPart[] = [];\n\tfor (const part of content) {\n\t\tconst converted = convertContentPart(part);\n\t\tif (converted) {\n\t\t\tparts.push(converted);\n\t\t}\n\t}\n\treturn parts;\n}\n\nfunction buildOpenAIMessages(\n\tsystemPrompts: string[] | undefined,\n\tmessages: ModelMessage[],\n\toptions?: { includeToolMessages?: boolean },\n): OpenAI.Chat.ChatCompletionMessageParam[] {\n\tconst includeTools = options?.includeToolMessages ?? true;\n\tconst openAIMessages: OpenAI.Chat.ChatCompletionMessageParam[] = [];\n\n\tif (systemPrompts && systemPrompts.length > 0) {\n\t\topenAIMessages.push({\n\t\t\trole: \"system\",\n\t\t\tcontent: systemPrompts.join(\"\\n\"),\n\t\t});\n\t}\n\n\tfor (const message of messages) {\n\t\tif (message.role === \"user\") {\n\t\t\topenAIMessages.push({\n\t\t\t\trole: \"user\",\n\t\t\t\tcontent: buildUserContent(message.content),\n\t\t\t});\n\t\t} else if (message.role === \"assistant\") {\n\t\t\tconst assistantMessage: OpenAI.Chat.ChatCompletionAssistantMessageParam = {\n\t\t\t\trole: \"assistant\",\n\t\t\t\tcontent: extractTextContent(message.content),\n\t\t\t};\n\t\t\tif (includeTools && message.toolCalls && message.toolCalls.length > 0) {\n\t\t\t\tassistantMessage.tool_calls = message.toolCalls.map((tc) => ({\n\t\t\t\t\tid: tc.id,\n\t\t\t\t\ttype: \"function\" as const,\n\t\t\t\t\tfunction: {\n\t\t\t\t\t\tname: tc.function.name,\n\t\t\t\t\t\targuments: tc.function.arguments,\n\t\t\t\t\t},\n\t\t\t\t}));\n\t\t\t}\n\t\t\topenAIMessages.push(assistantMessage);\n\t\t} else if (includeTools && message.role === \"tool\") {\n\t\t\tlet toolContent: string;\n\t\t\tif (typeof message.content === \"string\") {\n\t\t\t\ttry {\n\t\t\t\t\tJSON.parse(message.content);\n\t\t\t\t\ttoolContent = message.content;\n\t\t\t\t} catch {\n\t\t\t\t\ttoolContent = JSON.stringify(message.content);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\ttoolContent = JSON.stringify(message.content);\n\t\t\t}\n\t\t\topenAIMessages.push({\n\t\t\t\trole: \"tool\",\n\t\t\t\ttool_call_id: message.toolCallId || `tool_${crypto.randomUUID().slice(0, 8)}`,\n\t\t\t\tcontent: toolContent,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn openAIMessages;\n}\n\nfunction buildOpenAITools(\n\ttools: Array<{ name: string; description: string; inputSchema?: unknown }> | undefined,\n): OpenAI.Chat.ChatCompletionTool[] | undefined {\n\tif (!tools) return undefined;\n\treturn tools.map((tool) => ({\n\t\ttype: \"function\" as const,\n\t\tfunction: {\n\t\t\tname: tool.name,\n\t\t\tdescription: tool.description,\n\t\t\tparameters: tool.inputSchema as Record<string, unknown>,\n\t\t},\n\t}));\n}\n\n// ---------------------------------------------------------------------------\n// ID generation\n// ---------------------------------------------------------------------------\n\nfunction generateId(prefix = \"chatcmpl\"): string {\n\treturn `${prefix}-${crypto.randomUUID().replace(/-/g, \"\").slice(0, 16)}`;\n}\n\n// ---------------------------------------------------------------------------\n// WorkersAiTextAdapter: chat / structured output via OpenAI Chat Completions\n// ---------------------------------------------------------------------------\n\n// TODO: Replace `any` generic params with proper types once BaseTextAdapter's\n// provider-options generics stabilize. Workers AI doesn't have provider-specific\n// options in the TanStack sense, so `any` is pragmatic for now.\nexport class WorkersAiTextAdapter<TModel extends WorkersAiTextModel> extends BaseTextAdapter<\n\tTModel,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any -- BaseTextAdapter generic params are opaque\n\tany,\n\tany,\n\tany\n> {\n\tname = \"workers-ai\" as const;\n\n\tprivate client: OpenAI;\n\n\tconstructor(model: TModel, config: WorkersAiAdapterConfig) {\n\t\tsuper({ apiKey: \"unused\" }, model);\n\t\tthis.client = buildWorkersAiClient(config);\n\t}\n\n\tasync *chatStream(options: TextOptions<any>): AsyncIterable<StreamChunk> {\n\t\tconst { systemPrompts, messages, tools, temperature, model } = options;\n\n\t\tconst openAIMessages = buildOpenAIMessages(systemPrompts, messages);\n\t\tconst openAITools = buildOpenAITools(tools);\n\n\t\tconst timestamp = Date.now();\n\t\tconst runId = generateId();\n\t\tconst messageId = generateId();\n\t\tlet hasEmittedRunStarted = false;\n\t\tlet hasEmittedTextMessageStart = false;\n\t\tlet accumulatedContent = \"\";\n\t\tlet hasEmittedStepStarted = false;\n\t\tlet accumulatedReasoning = \"\";\n\t\tconst stepId = generateId();\n\t\tlet hasReceivedFinishReason = false;\n\t\tconst toolCallsInProgress = new Map<\n\t\t\tnumber,\n\t\t\t{ id: string; name: string; arguments: string; started: boolean }\n\t\t>();\n\n\t\ttry {\n\t\t\tlet stream: AsyncIterable<OpenAI.Chat.Completions.ChatCompletionChunk>;\n\t\t\ttry {\n\t\t\t\tstream = await this.client.chat.completions.create({\n\t\t\t\t\tmodel: model ?? this.model,\n\t\t\t\t\tmessages: openAIMessages,\n\t\t\t\t\ttools: openAITools,\n\t\t\t\t\ttemperature,\n\t\t\t\t\tstream: true,\n\t\t\t\t\tstream_options: { include_usage: true },\n\t\t\t\t});\n\t\t\t} catch (streamError: unknown) {\n\t\t\t\t// Some models (e.g. GPT-OSS) don't support streaming via the REST API.\n\t\t\t\t// Fall back to a non-streaming call and yield the result as a single chunk.\n\t\t\t\tconsole.warn(\n\t\t\t\t\t\"[tanstack-ai] Streaming failed, falling back to non-streaming:\",\n\t\t\t\t\tstreamError instanceof Error ? streamError.message : streamError,\n\t\t\t\t);\n\t\t\t\tconst nonStreamResult = await this.client.chat.completions.create({\n\t\t\t\t\tmodel: model ?? this.model,\n\t\t\t\t\tmessages: openAIMessages,\n\t\t\t\t\ttools: openAITools,\n\t\t\t\t\ttemperature,\n\t\t\t\t});\n\n\t\t\t\tyield {\n\t\t\t\t\ttype: \"RUN_STARTED\",\n\t\t\t\t\trunId,\n\t\t\t\t\tmodel: nonStreamResult.model || model || this.model,\n\t\t\t\t\ttimestamp,\n\t\t\t\t} satisfies StreamChunk;\n\n\t\t\t\tconst msg = nonStreamResult.choices[0]?.message;\n\t\t\t\tif (msg?.content) {\n\t\t\t\t\tyield {\n\t\t\t\t\t\ttype: \"TEXT_MESSAGE_START\",\n\t\t\t\t\t\tmessageId,\n\t\t\t\t\t\tmodel: nonStreamResult.model || model || this.model,\n\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t\trole: \"assistant\",\n\t\t\t\t\t} satisfies StreamChunk;\n\t\t\t\t\tyield {\n\t\t\t\t\t\ttype: \"TEXT_MESSAGE_CONTENT\",\n\t\t\t\t\t\tmessageId,\n\t\t\t\t\t\tmodel: nonStreamResult.model || model || this.model,\n\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t\tdelta: msg.content,\n\t\t\t\t\t\tcontent: msg.content,\n\t\t\t\t\t} satisfies StreamChunk;\n\t\t\t\t\tyield {\n\t\t\t\t\t\ttype: \"TEXT_MESSAGE_END\",\n\t\t\t\t\t\tmessageId,\n\t\t\t\t\t\tmodel: nonStreamResult.model || model || this.model,\n\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t} satisfies StreamChunk;\n\t\t\t\t}\n\n\t\t\t\tif (msg?.tool_calls) {\n\t\t\t\t\tfor (const tc of msg.tool_calls) {\n\t\t\t\t\t\tif (tc.type !== \"function\") continue;\n\t\t\t\t\t\tconst fn = tc.function;\n\t\t\t\t\t\tlet parsedInput: unknown = {};\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tparsedInput = fn.arguments ? JSON.parse(fn.arguments) : {};\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tparsedInput = {};\n\t\t\t\t\t\t}\n\t\t\t\t\t\tyield {\n\t\t\t\t\t\t\ttype: \"TOOL_CALL_START\",\n\t\t\t\t\t\t\ttoolCallId: tc.id,\n\t\t\t\t\t\t\ttoolName: fn.name,\n\t\t\t\t\t\t\tmodel: nonStreamResult.model || model || this.model,\n\t\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t\t\tindex: 0,\n\t\t\t\t\t\t} satisfies StreamChunk;\n\t\t\t\t\t\tyield {\n\t\t\t\t\t\t\ttype: \"TOOL_CALL_END\",\n\t\t\t\t\t\t\ttoolCallId: tc.id,\n\t\t\t\t\t\t\ttoolName: fn.name,\n\t\t\t\t\t\t\tmodel: nonStreamResult.model || model || this.model,\n\t\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t\t\tinput: parsedInput,\n\t\t\t\t\t\t} satisfies StreamChunk;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst finishReason = nonStreamResult.choices[0]?.finish_reason;\n\t\t\t\tyield {\n\t\t\t\t\ttype: \"RUN_FINISHED\",\n\t\t\t\t\trunId,\n\t\t\t\t\tmodel: nonStreamResult.model || model || this.model,\n\t\t\t\t\ttimestamp,\n\t\t\t\t\tusage: nonStreamResult.usage\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tpromptTokens: nonStreamResult.usage.prompt_tokens,\n\t\t\t\t\t\t\t\tcompletionTokens: nonStreamResult.usage.completion_tokens,\n\t\t\t\t\t\t\t\ttotalTokens: nonStreamResult.usage.total_tokens,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: undefined,\n\t\t\t\t\tfinishReason:\n\t\t\t\t\t\tfinishReason === \"tool_calls\" || finishReason === \"function_call\"\n\t\t\t\t\t\t\t? \"tool_calls\"\n\t\t\t\t\t\t\t: ((finishReason as \"stop\" | \"length\" | \"content_filter\") ?? \"stop\"),\n\t\t\t\t} satisfies StreamChunk;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tfor await (const chunk of stream) {\n\t\t\t\tif (!chunk.choices || chunk.choices.length === 0) continue;\n\t\t\t\tconst choice = chunk.choices[0];\n\t\t\t\tif (!choice) continue;\n\n\t\t\t\t// Emit RUN_STARTED on first chunk\n\t\t\t\tif (!hasEmittedRunStarted) {\n\t\t\t\t\thasEmittedRunStarted = true;\n\t\t\t\t\tyield {\n\t\t\t\t\t\ttype: \"RUN_STARTED\",\n\t\t\t\t\t\trunId,\n\t\t\t\t\t\tmodel: chunk.model || model || this.model,\n\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t} satisfies StreamChunk;\n\t\t\t\t}\n\n\t\t\t\tconst delta = choice.delta;\n\n\t\t\t\t// Reasoning content (used by models like QwQ, DeepSeek R1, Kimi K2.5)\n\t\t\t\t// The OpenAI SDK doesn't type this field, but models send it as an extension.\n\t\t\t\tconst reasoningContent = ((delta as Record<string, unknown>).reasoning_content ??\n\t\t\t\t\t(delta as Record<string, unknown>).reasoning) as string | undefined;\n\t\t\t\tif (reasoningContent) {\n\t\t\t\t\t// RUN_STARTED is already guaranteed by the guard above\n\t\t\t\t\tif (!hasEmittedStepStarted) {\n\t\t\t\t\t\thasEmittedStepStarted = true;\n\t\t\t\t\t\tyield {\n\t\t\t\t\t\t\ttype: \"STEP_STARTED\",\n\t\t\t\t\t\t\tstepId,\n\t\t\t\t\t\t\tstepType: \"thinking\",\n\t\t\t\t\t\t\tmodel: chunk.model || model || this.model,\n\t\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t\t} satisfies StreamChunk;\n\t\t\t\t\t}\n\t\t\t\t\taccumulatedReasoning += reasoningContent;\n\t\t\t\t\t// TODO: TanStack AI's StreamProcessor currently treats STEP_FINISHED as an\n\t\t\t\t\t// incremental reasoning event (with `delta` + accumulated `content`), so we\n\t\t\t\t\t// emit one per token. If TanStack AI adds a dedicated STEP_CONTENT event\n\t\t\t\t\t// type, this should be updated to emit STEP_CONTENT per token and a single\n\t\t\t\t\t// STEP_FINISHED when reasoning ends (i.e. when the first non-reasoning\n\t\t\t\t\t// content or finish_reason arrives).\n\t\t\t\t\tyield {\n\t\t\t\t\t\ttype: \"STEP_FINISHED\",\n\t\t\t\t\t\tstepId,\n\t\t\t\t\t\tdelta: reasoningContent,\n\t\t\t\t\t\tcontent: accumulatedReasoning,\n\t\t\t\t\t\tmodel: chunk.model || model || this.model,\n\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t} satisfies StreamChunk;\n\t\t\t\t}\n\n\t\t\t\t// Text content\n\t\t\t\tif (delta.content) {\n\t\t\t\t\tif (!hasEmittedTextMessageStart) {\n\t\t\t\t\t\thasEmittedTextMessageStart = true;\n\t\t\t\t\t\tyield {\n\t\t\t\t\t\t\ttype: \"TEXT_MESSAGE_START\",\n\t\t\t\t\t\t\tmessageId,\n\t\t\t\t\t\t\tmodel: chunk.model || model || this.model,\n\t\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t\t\trole: \"assistant\",\n\t\t\t\t\t\t} satisfies StreamChunk;\n\t\t\t\t\t}\n\n\t\t\t\t\taccumulatedContent += delta.content;\n\t\t\t\t\tyield {\n\t\t\t\t\t\ttype: \"TEXT_MESSAGE_CONTENT\",\n\t\t\t\t\t\tmessageId,\n\t\t\t\t\t\tmodel: chunk.model || model || this.model,\n\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t\tdelta: delta.content,\n\t\t\t\t\t\tcontent: accumulatedContent,\n\t\t\t\t\t} satisfies StreamChunk;\n\t\t\t\t}\n\n\t\t\t\t// Tool calls\n\t\t\t\tif (delta.tool_calls) {\n\t\t\t\t\tfor (const toolCallDelta of delta.tool_calls) {\n\t\t\t\t\t\tconst index = toolCallDelta.index;\n\n\t\t\t\t\t\tif (!toolCallsInProgress.has(index)) {\n\t\t\t\t\t\t\t// Always generate a unique ID per tool call index.\n\t\t\t\t\t\t\t// The backend may send the same ID for multiple tool calls,\n\t\t\t\t\t\t\t// so we cannot trust toolCallDelta.id to be unique.\n\t\t\t\t\t\t\ttoolCallsInProgress.set(index, {\n\t\t\t\t\t\t\t\tid: generateId(\"chatcmpl-tool\"),\n\t\t\t\t\t\t\t\tname: toolCallDelta.function?.name || \"\",\n\t\t\t\t\t\t\t\targuments: \"\",\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst toolCall = toolCallsInProgress.get(index)!;\n\n\t\t\t\t\t\t// Only update name if provided (ID is already set at creation time\n\t\t\t\t\t\t// and should not be overwritten by subsequent chunks that may have\n\t\t\t\t\t\t// duplicate/shared IDs from the backend)\n\t\t\t\t\t\tif (toolCallDelta.function?.name) {\n\t\t\t\t\t\t\ttoolCall.name = toolCallDelta.function.name;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (toolCallDelta.function?.arguments) {\n\t\t\t\t\t\t\ttoolCall.arguments += toolCallDelta.function.arguments;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Emit TOOL_CALL_START once we have id and name\n\t\t\t\t\t\tif (toolCall.id && toolCall.name && !toolCall.started) {\n\t\t\t\t\t\t\ttoolCall.started = true;\n\t\t\t\t\t\t\tyield {\n\t\t\t\t\t\t\t\ttype: \"TOOL_CALL_START\",\n\t\t\t\t\t\t\t\ttoolCallId: toolCall.id,\n\t\t\t\t\t\t\t\ttoolName: toolCall.name,\n\t\t\t\t\t\t\t\tmodel: chunk.model || model || this.model,\n\t\t\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t\t\t\tindex,\n\t\t\t\t\t\t\t} satisfies StreamChunk;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Stream tool call arguments\n\t\t\t\t\t\tif (toolCallDelta.function?.arguments && toolCall.started) {\n\t\t\t\t\t\t\tyield {\n\t\t\t\t\t\t\t\ttype: \"TOOL_CALL_ARGS\",\n\t\t\t\t\t\t\t\ttoolCallId: toolCall.id,\n\t\t\t\t\t\t\t\tmodel: chunk.model || model || this.model,\n\t\t\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t\t\t\tdelta: toolCallDelta.function.arguments,\n\t\t\t\t\t\t\t} satisfies StreamChunk;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Finish\n\t\t\t\tif (choice.finish_reason) {\n\t\t\t\t\thasReceivedFinishReason = true;\n\n\t\t\t\t\t// End tool calls\n\t\t\t\t\tif (choice.finish_reason === \"tool_calls\" || toolCallsInProgress.size > 0) {\n\t\t\t\t\t\tfor (const [, toolCall] of toolCallsInProgress) {\n\t\t\t\t\t\t\tlet parsedInput: unknown = {};\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tparsedInput = toolCall.arguments\n\t\t\t\t\t\t\t\t\t? JSON.parse(toolCall.arguments)\n\t\t\t\t\t\t\t\t\t: {};\n\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\tparsedInput = {};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tyield {\n\t\t\t\t\t\t\t\ttype: \"TOOL_CALL_END\",\n\t\t\t\t\t\t\t\ttoolCallId: toolCall.id,\n\t\t\t\t\t\t\t\ttoolName: toolCall.name,\n\t\t\t\t\t\t\t\tmodel: chunk.model || model || this.model,\n\t\t\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t\t\t\tinput: parsedInput,\n\t\t\t\t\t\t\t} satisfies StreamChunk;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst computedFinishReason =\n\t\t\t\t\t\tchoice.finish_reason === \"tool_calls\" ||\n\t\t\t\t\t\tchoice.finish_reason === \"function_call\" ||\n\t\t\t\t\t\ttoolCallsInProgress.size > 0\n\t\t\t\t\t\t\t? \"tool_calls\"\n\t\t\t\t\t\t\t: (choice.finish_reason as \"stop\" | \"length\" | \"content_filter\");\n\n\t\t\t\t\t// End text message if started\n\t\t\t\t\tif (hasEmittedTextMessageStart) {\n\t\t\t\t\t\tyield {\n\t\t\t\t\t\t\ttype: \"TEXT_MESSAGE_END\",\n\t\t\t\t\t\t\tmessageId,\n\t\t\t\t\t\t\tmodel: chunk.model || model || this.model,\n\t\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t\t} satisfies StreamChunk;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Emit RUN_FINISHED\n\t\t\t\t\tyield {\n\t\t\t\t\t\ttype: \"RUN_FINISHED\",\n\t\t\t\t\t\trunId,\n\t\t\t\t\t\tmodel: chunk.model || model || this.model,\n\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t\tusage: chunk.usage\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tpromptTokens: chunk.usage.prompt_tokens,\n\t\t\t\t\t\t\t\t\tcompletionTokens: chunk.usage.completion_tokens,\n\t\t\t\t\t\t\t\t\ttotalTokens: chunk.usage.total_tokens,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\tfinishReason: computedFinishReason,\n\t\t\t\t\t} satisfies StreamChunk;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Premature stream termination: the stream ended without a finish_reason.\n\t\t\t// This can happen when Workers AI truncates a response or the connection drops.\n\t\t\t// Emit proper closing events so the consumer doesn't hang.\n\t\t\tif (hasEmittedRunStarted && !hasReceivedFinishReason) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t\"[tanstack-ai] Stream ended without finish_reason — possible truncation or connection drop\",\n\t\t\t\t);\n\n\t\t\t\t// Close any open tool calls\n\t\t\t\tfor (const [, toolCall] of toolCallsInProgress) {\n\t\t\t\t\tif (toolCall.started) {\n\t\t\t\t\t\tlet parsedInput: unknown = {};\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tparsedInput = toolCall.arguments ? JSON.parse(toolCall.arguments) : {};\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tparsedInput = {};\n\t\t\t\t\t\t}\n\t\t\t\t\t\tyield {\n\t\t\t\t\t\t\ttype: \"TOOL_CALL_END\",\n\t\t\t\t\t\t\ttoolCallId: toolCall.id,\n\t\t\t\t\t\t\ttoolName: toolCall.name,\n\t\t\t\t\t\t\tmodel: model ?? this.model,\n\t\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t\t\tinput: parsedInput,\n\t\t\t\t\t\t} satisfies StreamChunk;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Close text message if open\n\t\t\t\tif (hasEmittedTextMessageStart) {\n\t\t\t\t\tyield {\n\t\t\t\t\t\ttype: \"TEXT_MESSAGE_END\",\n\t\t\t\t\t\tmessageId,\n\t\t\t\t\t\tmodel: model ?? this.model,\n\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t} satisfies StreamChunk;\n\t\t\t\t}\n\n\t\t\t\tyield {\n\t\t\t\t\ttype: \"RUN_FINISHED\",\n\t\t\t\t\trunId,\n\t\t\t\t\tmodel: model ?? this.model,\n\t\t\t\t\ttimestamp,\n\t\t\t\t\tfinishReason: \"stop\",\n\t\t\t\t} satisfies StreamChunk;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tconst code =\n\t\t\t\terror instanceof Error ? (error as Error & { code?: string }).code : undefined;\n\t\t\tif (!hasEmittedRunStarted) {\n\t\t\t\tyield {\n\t\t\t\t\ttype: \"RUN_STARTED\",\n\t\t\t\t\trunId,\n\t\t\t\t\tmodel: model ?? this.model,\n\t\t\t\t\ttimestamp,\n\t\t\t\t} satisfies StreamChunk;\n\t\t\t}\n\t\t\tyield {\n\t\t\t\ttype: \"RUN_ERROR\",\n\t\t\t\trunId,\n\t\t\t\tmodel: model ?? this.model,\n\t\t\t\ttimestamp,\n\t\t\t\terror: {\n\t\t\t\t\tmessage: message || \"Unknown error\",\n\t\t\t\t\tcode,\n\t\t\t\t},\n\t\t\t} satisfies StreamChunk;\n\t\t}\n\t}\n\n\tasync structuredOutput(\n\t\toptions: StructuredOutputOptions<any>,\n\t): Promise<StructuredOutputResult<unknown>> {\n\t\tconst { outputSchema, chatOptions } = options;\n\t\tconst { systemPrompts, messages, temperature, model } = chatOptions;\n\n\t\tconst openAIMessages = buildOpenAIMessages(systemPrompts, messages, {\n\t\t\tincludeToolMessages: false,\n\t\t});\n\n\t\tconst response = await this.client.chat.completions.create({\n\t\t\tmodel: model ?? this.model,\n\t\t\tmessages: openAIMessages,\n\t\t\ttemperature,\n\t\t\tstream: false,\n\t\t\tresponse_format: {\n\t\t\t\ttype: \"json_schema\",\n\t\t\t\tjson_schema: {\n\t\t\t\t\tname: \"structured_output\",\n\t\t\t\t\tstrict: true,\n\t\t\t\t\tschema: outputSchema,\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\n\t\tconst choice = response.choices?.[0];\n\n\t\tif (!choice) {\n\t\t\tthrow new Error(\n\t\t\t\t`Workers AI structured output returned no choices: ${JSON.stringify(response)}`,\n\t\t\t);\n\t\t}\n\n\t\tconst rawContent = choice.message?.content ?? \"\";\n\n\t\t// Workers AI REST endpoint may return `content` as an already-parsed object\n\t\t// when using json_schema response format, so normalise both cases.\n\t\tlet data: unknown;\n\t\tlet rawText: string;\n\n\t\tif (typeof rawContent === \"string\") {\n\t\t\trawText = rawContent;\n\t\t\ttry {\n\t\t\t\tdata = JSON.parse(rawText);\n\t\t\t} catch {\n\t\t\t\tdata = rawText;\n\t\t\t}\n\t\t} else {\n\t\t\t// Already an object — stringify for rawText, use directly for data\n\t\t\tdata = rawContent;\n\t\t\trawText = JSON.stringify(rawContent);\n\t\t}\n\n\t\treturn { data, rawText };\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// Factory functions\n// ---------------------------------------------------------------------------\n\nexport function createWorkersAiChat(model: WorkersAiTextModel, config: WorkersAiAdapterConfig) {\n\treturn new WorkersAiTextAdapter(model, config);\n}\n"],"mappings":";;;;;;;;;;;;AAEA;AAAA,EACC;AAAA,OAGM;AACP,OAAO,Y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QAAI,OAAO,eAAe,UAAU;AACnC,gBAAU;AACV,UAAI;AACH,eAAO,KAAK,MAAM,OAAO;AAAA,MAC1B,QAAQ;AACP,eAAO;AAAA,MACR;AAAA,IACD,OAAO;AAEN,aAAO;AACP,gBAAU,KAAK,UAAU,UAAU;AAAA,IACpC;AAEA,WAAO,EAAE,MAAM,QAAQ;AAAA,EACxB;AACD;AAMO,SAAS,oBAAoB,OAA2B,QAAgC;AAC9F,SAAO,IAAI,qBAAqB,OAAO,MAAM;AAC9C;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createGatewayFetch
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-S5QBHI6O.js";
|
|
4
4
|
|
|
5
5
|
// src/adapters/grok.ts
|
|
6
6
|
import {
|
|
@@ -45,4 +45,4 @@ export {
|
|
|
45
45
|
createGrokImage,
|
|
46
46
|
createGrokSummarize
|
|
47
47
|
};
|
|
48
|
-
//# sourceMappingURL=chunk-
|
|
48
|
+
//# sourceMappingURL=chunk-OGAH3FYW.js.map
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
isDirectBindingConfig,
|
|
11
11
|
isDirectCredentialsConfig,
|
|
12
12
|
validateWorkersAiConfig
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-S5QBHI6O.js";
|
|
14
14
|
import {
|
|
15
15
|
__publicField
|
|
16
16
|
} from "./chunk-V6TY7KAL.js";
|
|
@@ -108,4 +108,4 @@ export {
|
|
|
108
108
|
WorkersAiTTSAdapter,
|
|
109
109
|
createWorkersAiTts
|
|
110
110
|
};
|
|
111
|
-
//# sourceMappingURL=chunk-
|
|
111
|
+
//# sourceMappingURL=chunk-QMRONSLN.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createGatewayFetch
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-S5QBHI6O.js";
|
|
4
4
|
|
|
5
5
|
// src/adapters/openai.ts
|
|
6
6
|
import {
|
|
@@ -54,4 +54,4 @@ export {
|
|
|
54
54
|
createOpenAiTts,
|
|
55
55
|
createOpenAiVideo
|
|
56
56
|
};
|
|
57
|
-
//# sourceMappingURL=chunk-
|
|
57
|
+
//# sourceMappingURL=chunk-RWLCEKT6.js.map
|
|
@@ -54,7 +54,9 @@ function createGatewayFetch(provider, config, headers = {}) {
|
|
|
54
54
|
query
|
|
55
55
|
};
|
|
56
56
|
if (provider === "workers-ai") {
|
|
57
|
-
request.endpoint
|
|
57
|
+
if (!request.endpoint.startsWith("run/")) {
|
|
58
|
+
request.endpoint = `run/${query.model}`;
|
|
59
|
+
}
|
|
58
60
|
delete query.model;
|
|
59
61
|
delete query.instructions;
|
|
60
62
|
}
|
|
@@ -85,27 +87,10 @@ function normalizeMessagesForBinding(messages) {
|
|
|
85
87
|
if (normalized.content === null || normalized.content === void 0) {
|
|
86
88
|
normalized.content = "";
|
|
87
89
|
}
|
|
88
|
-
if (normalized.tool_call_id && typeof normalized.tool_call_id === "string") {
|
|
89
|
-
normalized.tool_call_id = sanitizeToolCallId(normalized.tool_call_id);
|
|
90
|
-
}
|
|
91
|
-
if (Array.isArray(normalized.tool_calls)) {
|
|
92
|
-
normalized.tool_calls = normalized.tool_calls.map(
|
|
93
|
-
(tc) => {
|
|
94
|
-
if (tc.id && typeof tc.id === "string") {
|
|
95
|
-
return { ...tc, id: sanitizeToolCallId(tc.id) };
|
|
96
|
-
}
|
|
97
|
-
return tc;
|
|
98
|
-
}
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
90
|
return normalized;
|
|
102
91
|
});
|
|
103
92
|
}
|
|
104
|
-
function
|
|
105
|
-
const alphanumeric = id.replace(/[^a-zA-Z0-9]/g, "");
|
|
106
|
-
return alphanumeric.slice(0, 9).padEnd(9, "0");
|
|
107
|
-
}
|
|
108
|
-
function createWorkersAiBindingFetch(binding) {
|
|
93
|
+
function createWorkersAiBindingFetch(binding, options) {
|
|
109
94
|
return async (_input, init) => {
|
|
110
95
|
if (!init?.body) {
|
|
111
96
|
return new Response("No body", { status: 400 });
|
|
@@ -129,7 +114,11 @@ function createWorkersAiBindingFetch(binding) {
|
|
|
129
114
|
if (typeof body.max_tokens === "number") inputs.max_tokens = body.max_tokens;
|
|
130
115
|
if (body.response_format) inputs.response_format = body.response_format;
|
|
131
116
|
if (stream) inputs.stream = true;
|
|
132
|
-
const result = await binding.run(
|
|
117
|
+
const result = await binding.run(
|
|
118
|
+
model,
|
|
119
|
+
inputs,
|
|
120
|
+
options?.extraHeaders ? { extraHeaders: options.extraHeaders } : void 0
|
|
121
|
+
);
|
|
133
122
|
if (stream && result instanceof ReadableStream) {
|
|
134
123
|
const transformed = transformWorkersAiStream(
|
|
135
124
|
result,
|
|
@@ -153,7 +142,7 @@ function createWorkersAiBindingFetch(binding) {
|
|
|
153
142
|
finishReason = "tool_calls";
|
|
154
143
|
message.tool_calls = responseObj.tool_calls.map(
|
|
155
144
|
(tc) => ({
|
|
156
|
-
id:
|
|
145
|
+
id: tc.id || crypto.randomUUID(),
|
|
157
146
|
type: "function",
|
|
158
147
|
function: {
|
|
159
148
|
name: tc.function?.name || tc.name || "",
|
|
@@ -182,7 +171,7 @@ function transformWorkersAiStream(source, model) {
|
|
|
182
171
|
let buffer = "";
|
|
183
172
|
let hasToolCalls = false;
|
|
184
173
|
let isOpenAiFormat = false;
|
|
185
|
-
const
|
|
174
|
+
const toolCallState = /* @__PURE__ */ new Map();
|
|
186
175
|
return source.pipeThrough(
|
|
187
176
|
new TransformStream({
|
|
188
177
|
transform(chunk, controller) {
|
|
@@ -202,8 +191,16 @@ function transformWorkersAiStream(source, model) {
|
|
|
202
191
|
if (choice?.delta?.tool_calls) {
|
|
203
192
|
hasToolCalls = true;
|
|
204
193
|
for (const tc of choice.delta.tool_calls) {
|
|
205
|
-
|
|
206
|
-
|
|
194
|
+
const tcIndex = tc.index ?? 0;
|
|
195
|
+
if (!toolCallState.has(tcIndex)) {
|
|
196
|
+
const id = tc.id || `call${streamId}${tcIndex}`;
|
|
197
|
+
toolCallState.set(tcIndex, {
|
|
198
|
+
id,
|
|
199
|
+
name: tc.function?.name || ""
|
|
200
|
+
});
|
|
201
|
+
tc.id = id;
|
|
202
|
+
} else {
|
|
203
|
+
delete tc.id;
|
|
207
204
|
}
|
|
208
205
|
}
|
|
209
206
|
}
|
|
@@ -248,10 +245,10 @@ function transformWorkersAiStream(source, model) {
|
|
|
248
245
|
const toolCallDelta = {
|
|
249
246
|
index: tcIndex
|
|
250
247
|
};
|
|
251
|
-
if (!
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
toolCallDelta.id =
|
|
248
|
+
if (!toolCallState.has(tcIndex)) {
|
|
249
|
+
const id = tcId || `call${streamId}${tcIndex}`;
|
|
250
|
+
toolCallState.set(tcIndex, { id, name: tcName || "" });
|
|
251
|
+
toolCallDelta.id = id;
|
|
255
252
|
toolCallDelta.type = "function";
|
|
256
253
|
toolCallDelta.function = {
|
|
257
254
|
name: tcName || "",
|
|
@@ -324,4 +321,4 @@ export {
|
|
|
324
321
|
createGatewayFetch,
|
|
325
322
|
createWorkersAiBindingFetch
|
|
326
323
|
};
|
|
327
|
-
//# sourceMappingURL=chunk-
|
|
324
|
+
//# sourceMappingURL=chunk-S5QBHI6O.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/create-fetcher.ts"],"sourcesContent":["// ---------------------------------------------------------------------------\n// AI Gateway types (for third-party providers + Workers AI through gateway)\n// ---------------------------------------------------------------------------\n\nexport interface CloudflareAiGateway {\n\trun(request: unknown): Promise<Response>;\n}\n\nexport interface AiGatewayBindingConfig {\n\t/**\n\t * The AI Gateway binding\n\t * @example\n\t * env.AI.gateway('my-gateway-id')\n\t */\n\tbinding: CloudflareAiGateway;\n\t/**\n\t * The Provider API Key if you want to manually pass it, ignore if using Unified Billing or BYOK.\n\t */\n\tapiKey?: string;\n}\n\nexport type AiGatewayCredentialsConfig = {\n\t/**\n\t * The Cloudflare account ID\n\t */\n\taccountId: string;\n\t/**\n\t * The AI Gateway ID\n\t */\n\tgatewayId: string;\n} & (\n\t| {\n\t\t\t/** Cloudflare API Key for AI Gateway */\n\t\t\tcfApiKey: string;\n\t\t\tapiKey?: string;\n\t }\n\t| {\n\t\t\t/** Provider API Key */\n\t\t\tapiKey: string;\n\t\t\t/** Cloudflare API Key for AI Gateway */\n\t\t\tcfApiKey?: string;\n\t }\n);\n\nexport interface AiGatewayConfig {\n\tskipCache?: boolean;\n\tcacheTtl?: number;\n\tcustomCacheKey?: string;\n\tmetadata?: Record<string, unknown>;\n}\n\nexport type AiGatewayAdapterConfig = (AiGatewayBindingConfig | AiGatewayCredentialsConfig) &\n\tAiGatewayConfig;\n\n// ---------------------------------------------------------------------------\n// Plain Workers AI types (direct binding or REST, no gateway)\n// ---------------------------------------------------------------------------\n\n/**\n * The Workers AI binding interface (env.AI).\n * Accepts a model name and inputs, returns results directly.\n * Includes `gateway()` which is present on `env.AI` but not on `env.AI.gateway(id)`,\n * enabling structural discrimination from `CloudflareAiGateway`.\n */\nexport interface WorkersAiBinding {\n\trun(\n\t\tmodel: string,\n\t\tinputs: Record<string, unknown>,\n\t\toptions?: Record<string, unknown>,\n\t): Promise<unknown>;\n\tgateway(gatewayId: string): CloudflareAiGateway;\n}\n\nexport interface WorkersAiDirectBindingConfig {\n\t/**\n\t * The Workers AI binding (env.AI).\n\t * @example\n\t * { binding: env.AI }\n\t */\n\tbinding: WorkersAiBinding;\n}\n\nexport interface WorkersAiDirectCredentialsConfig {\n\t/**\n\t * The Cloudflare account ID\n\t */\n\taccountId: string;\n\t/**\n\t * The Cloudflare API key for Workers AI\n\t */\n\tapiKey: string;\n}\n\n/**\n * Config for Workers AI adapters. Supports four modes:\n * - Plain binding: `{ binding: env.AI }`\n * - Plain REST: `{ accountId, apiKey }`\n * - AI Gateway binding: `{ binding: env.AI.gateway(id) }`\n * - AI Gateway REST: `{ accountId, gatewayId, ... }`\n *\n * The third union member intersects `AiGatewayAdapterConfig` with `{ apiKey?: string }`.\n * For the gateway binding variant, `AiGatewayBindingConfig` already includes `apiKey?`,\n * so the intersection is redundant there. For the gateway credentials variant, this\n * `apiKey` represents the Workers AI token (used in the `Authorization` header to the\n * upstream provider), distinct from `cfApiKey` (used in the `cf-aig-authorization`\n * header for authenticated gateways).\n */\nexport type WorkersAiAdapterConfig = (\n\t| WorkersAiDirectBindingConfig\n\t| WorkersAiDirectCredentialsConfig\n\t| (AiGatewayAdapterConfig & { apiKey?: string })\n) & {\n\t/**\n\t * Session affinity key for prefix-cache optimization.\n\t * Routes requests with the same key to the same backend replica.\n\t */\n\tsessionAffinity?: string;\n};\n\n// ---------------------------------------------------------------------------\n// Config detection helpers\n// ---------------------------------------------------------------------------\n\n/** Returns true if this is a plain Workers AI binding config (`{ binding: env.AI }`) */\nexport function isDirectBindingConfig(\n\tconfig: WorkersAiAdapterConfig,\n): config is WorkersAiDirectBindingConfig {\n\t// env.AI has a .gateway() method; env.AI.gateway(id) does not.\n\t// This distinguishes direct bindings from AI Gateway bindings.\n\treturn (\n\t\t\"binding\" in config &&\n\t\ttypeof (config.binding as unknown as Record<string, unknown>).gateway === \"function\"\n\t);\n}\n\n/** Returns true if this is a plain Workers AI REST config (accountId + apiKey, no gatewayId) */\nexport function isDirectCredentialsConfig(\n\tconfig: WorkersAiAdapterConfig,\n): config is WorkersAiDirectCredentialsConfig {\n\treturn \"accountId\" in config && \"apiKey\" in config && !(\"gatewayId\" in config);\n}\n\n/** Returns true if this is an AI Gateway config (has gateway binding or `gatewayId`) */\nexport function isGatewayConfig(config: WorkersAiAdapterConfig): config is AiGatewayAdapterConfig {\n\tif (\"gatewayId\" in config) return true;\n\t// Has `binding` but NOT a direct Workers AI binding (no .gateway method)\n\treturn \"binding\" in config && !isDirectBindingConfig(config);\n}\n\n// ---------------------------------------------------------------------------\n// Config validation\n// ---------------------------------------------------------------------------\n\n/**\n * Validates that a WorkersAiAdapterConfig contains a valid configuration.\n * Throws an error if neither a binding, credentials (accountId + apiKey),\n * nor a gateway configuration is provided.\n */\nexport function validateWorkersAiConfig(config: WorkersAiAdapterConfig): void {\n\tif (\n\t\t!isDirectBindingConfig(config) &&\n\t\t!isDirectCredentialsConfig(config) &&\n\t\t!isGatewayConfig(config)\n\t) {\n\t\tthrow new Error(\n\t\t\t\"Invalid Workers AI configuration: you must provide either a binding (e.g. { binding: env.AI }), \" +\n\t\t\t\t\"credentials ({ accountId, apiKey }), or a gateway configuration ({ binding: env.AI.gateway(id) } \" +\n\t\t\t\t\"or { accountId, gatewayId }).\",\n\t\t);\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// createGatewayFetch -- for routing through AI Gateway\n// ---------------------------------------------------------------------------\n\nexport function createGatewayFetch(\n\tprovider: string,\n\tconfig: AiGatewayAdapterConfig,\n\theaders: Record<string, string> = {},\n): typeof fetch {\n\treturn (input, init) => {\n\t\tlet query: Record<string, unknown> = {};\n\n\t\tconst url =\n\t\t\ttypeof input === \"string\" ? input : input instanceof URL ? input.href : input.url;\n\t\tconst urlObj = new URL(url);\n\n\t\t// Extract endpoint path (remove /v1/ prefix if present)\n\t\tconst endpoint = urlObj.pathname.replace(/^\\/v1\\//, \"\").replace(/^\\//, \"\") + urlObj.search;\n\n\t\tif (init?.body) {\n\t\t\ttry {\n\t\t\t\tquery = JSON.parse(init.body as string);\n\t\t\t} catch {\n\t\t\t\tquery = { _raw: init.body };\n\t\t\t}\n\t\t}\n\n\t\tconst cacheHeaders: Record<string, string> = {};\n\n\t\tif (\"skipCache\" in config && config.skipCache) {\n\t\t\tcacheHeaders[\"cf-aig-skip-cache\"] = \"true\";\n\t\t}\n\n\t\tif (typeof config.cacheTtl === \"number\") {\n\t\t\tcacheHeaders[\"cf-aig-cache-ttl\"] = String(config.cacheTtl);\n\t\t}\n\n\t\tif (typeof config.customCacheKey === \"string\") {\n\t\t\tcacheHeaders[\"cf-aig-cache-key\"] = config.customCacheKey;\n\t\t}\n\n\t\tif (typeof config.metadata === \"object\") {\n\t\t\tcacheHeaders[\"cf-aig-metadata\"] = JSON.stringify(config.metadata);\n\t\t}\n\n\t\tconst request: {\n\t\t\tprovider: string;\n\t\t\tendpoint: string;\n\t\t\theaders: Record<string, string>;\n\t\t\tquery: Record<string, unknown>;\n\t\t} = {\n\t\t\tprovider,\n\t\t\tendpoint,\n\t\t\theaders: {\n\t\t\t\t...(init?.headers as Record<string, string> | undefined),\n\t\t\t\t...headers,\n\t\t\t\t...cacheHeaders,\n\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t},\n\t\t\tquery,\n\t\t};\n\n\t\tif (provider === \"workers-ai\") {\n\t\t\tif (!request.endpoint.startsWith(\"run/\")) {\n\t\t\t\trequest.endpoint = `run/${query.model}`;\n\t\t\t}\n\t\t\tdelete query.model;\n\t\t\tdelete query.instructions;\n\t\t}\n\n\t\tif (config.apiKey) {\n\t\t\trequest.headers[\"authorization\"] = `Bearer ${config.apiKey}`;\n\t\t}\n\n\t\tif (\"binding\" in config) {\n\t\t\treturn config.binding.run(request);\n\t\t}\n\n\t\treturn fetch(\n\t\t\t`https://gateway.ai.cloudflare.com/v1/${config.accountId}/${config.gatewayId}`,\n\t\t\t{\n\t\t\t\t...init,\n\t\t\t\theaders: {\n\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\t...headers,\n\t\t\t\t\t...cacheHeaders,\n\t\t\t\t\t...(config.cfApiKey\n\t\t\t\t\t\t? { \"cf-aig-authorization\": `Bearer ${config.cfApiKey}` }\n\t\t\t\t\t\t: {}),\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify(request),\n\t\t\t},\n\t\t);\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// createWorkersAiBindingFetch -- shim that makes env.AI look like an OpenAI endpoint\n// ---------------------------------------------------------------------------\n\n/**\n * Normalize messages before passing to Workers AI binding.\n *\n * The binding has strict schema validation that may differ from the OpenAI API:\n * - `content` must not be null\n *\n * Content arrays (with image_url parts) are passed through as-is since the\n * Workers AI binding accepts them at runtime for vision-capable models.\n */\nfunction normalizeMessagesForBinding(\n\tmessages: Record<string, unknown>[],\n): Record<string, unknown>[] {\n\treturn messages.map((msg) => {\n\t\tconst normalized = { ...msg };\n\n\t\t// content: null → content: \"\"\n\t\tif (normalized.content === null || normalized.content === undefined) {\n\t\t\tnormalized.content = \"\";\n\t\t}\n\n\t\treturn normalized;\n\t});\n}\n\n/**\n * Creates a fetch function that intercepts OpenAI SDK requests and translates them\n * to Workers AI binding calls (env.AI.run). This allows the WorkersAiTextAdapter\n * to use the OpenAI SDK against a plain Workers AI binding.\n *\n * NOTE: The `input` URL parameter is intentionally ignored. The model name and all\n * request parameters are extracted from the JSON body, matching Workers AI's\n * `binding.run(model, inputs)` calling convention.\n */\nexport function createWorkersAiBindingFetch(\n\tbinding: WorkersAiBinding,\n\toptions?: { extraHeaders?: Record<string, string> },\n): typeof fetch {\n\treturn async (_input, init) => {\n\t\tif (!init?.body) {\n\t\t\treturn new Response(\"No body\", { status: 400 });\n\t\t}\n\n\t\tlet body: Record<string, unknown>;\n\t\ttry {\n\t\t\tbody = JSON.parse(init.body as string);\n\t\t} catch {\n\t\t\treturn new Response(\"Invalid JSON body\", { status: 400 });\n\t\t}\n\n\t\tconst model = body.model as string;\n\t\tconst stream = body.stream as boolean | undefined;\n\n\t\t// Build Workers AI inputs from OpenAI format\n\t\tconst inputs: Record<string, unknown> = {};\n\t\tif (body.messages) {\n\t\t\tinputs.messages = normalizeMessagesForBinding(\n\t\t\t\tbody.messages as Record<string, unknown>[],\n\t\t\t);\n\t\t}\n\t\tif (body.tools) inputs.tools = body.tools;\n\t\tif (typeof body.temperature === \"number\") inputs.temperature = body.temperature;\n\t\tif (typeof body.max_tokens === \"number\") inputs.max_tokens = body.max_tokens;\n\t\tif (body.response_format) inputs.response_format = body.response_format;\n\t\tif (stream) inputs.stream = true;\n\n\t\tconst result = await binding.run(\n\t\t\tmodel,\n\t\t\tinputs,\n\t\t\toptions?.extraHeaders ? { extraHeaders: options.extraHeaders } : undefined,\n\t\t);\n\n\t\tif (stream && result instanceof ReadableStream) {\n\t\t\t// Workers AI returns an SSE stream with `data: {\"response\":\"chunk\"}` format.\n\t\t\t// Transform it to OpenAI-compatible SSE format.\n\t\t\tconst transformed = transformWorkersAiStream(\n\t\t\t\tresult as ReadableStream<Uint8Array>,\n\t\t\t\tmodel,\n\t\t\t);\n\t\t\treturn new Response(transformed, {\n\t\t\t\theaders: {\n\t\t\t\t\t\"Content-Type\": \"text/event-stream\",\n\t\t\t\t\t\"Cache-Control\": \"no-cache\",\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\t// Graceful degradation: some models return a complete (non-streaming)\n\t\t// response even when `stream: true` is requested. Fall through to the\n\t\t// non-streaming wrapper which produces a valid OpenAI Chat Completion\n\t\t// response that the SDK can consume.\n\n\t\t// Non-streaming: Workers AI returns { response: \"text\", tool_calls?: [...] }\n\t\t// Wrap into OpenAI Chat Completion format.\n\t\tconst responseObj =\n\t\t\ttypeof result === \"object\" && result !== null\n\t\t\t\t? (result as Record<string, unknown>)\n\t\t\t\t: { response: String(result) };\n\n\t\tconst responseText = typeof responseObj.response === \"string\" ? responseObj.response : \"\";\n\n\t\tconst message: Record<string, unknown> = {\n\t\t\trole: \"assistant\",\n\t\t\tcontent: responseText,\n\t\t};\n\t\tlet finishReason = \"stop\";\n\n\t\t// Handle tool calls if present in Workers AI response\n\t\tif (Array.isArray(responseObj.tool_calls) && responseObj.tool_calls.length > 0) {\n\t\t\tfinishReason = \"tool_calls\";\n\t\t\tmessage.tool_calls = responseObj.tool_calls.map(\n\t\t\t\t(tc: {\n\t\t\t\t\tid?: string;\n\t\t\t\t\tname?: string;\n\t\t\t\t\targuments: unknown;\n\t\t\t\t\tfunction?: { name: string; arguments?: unknown };\n\t\t\t\t}) => ({\n\t\t\t\t\tid: tc.id || crypto.randomUUID(),\n\t\t\t\t\ttype: \"function\",\n\t\t\t\t\tfunction: {\n\t\t\t\t\t\tname: tc.function?.name || tc.name || \"\",\n\t\t\t\t\t\targuments:\n\t\t\t\t\t\t\ttypeof (tc.function?.arguments ?? tc.arguments) === \"string\"\n\t\t\t\t\t\t\t\t? ((tc.function?.arguments ?? tc.arguments) as string)\n\t\t\t\t\t\t\t\t: JSON.stringify(tc.function?.arguments ?? tc.arguments ?? {}),\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tconst openAiResponse = {\n\t\t\tid: `workers-ai-${crypto.randomUUID()}`,\n\t\t\tobject: \"chat.completion\",\n\t\t\tcreated: Math.floor(Date.now() / 1000),\n\t\t\tmodel,\n\t\t\tchoices: [{ index: 0, message, finish_reason: finishReason }],\n\t\t};\n\n\t\treturn new Response(JSON.stringify(openAiResponse), {\n\t\t\theaders: { \"Content-Type\": \"application/json\" },\n\t\t});\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Stream transformer: Workers AI SSE -> OpenAI-compatible SSE\n// Uses TransformStream for proper backpressure.\n// ---------------------------------------------------------------------------\n\n/**\n * Transforms a Workers AI SSE stream (data: {\"response\":\"chunk\"}) into\n * an OpenAI-compatible SSE stream (data: {\"choices\":[{\"delta\":{\"content\":\"chunk\"}}]}).\n *\n * Workers AI binding streams tool calls in an OpenAI-like nested format:\n * { tool_calls: [{ id, type, index, function: { name, arguments } }] }\n * Arguments are streamed incrementally across multiple SSE chunks, so the\n * transformer must forward them as incremental deltas rather than a single blob.\n */\nfunction transformWorkersAiStream(\n\tsource: ReadableStream<Uint8Array>,\n\tmodel: string,\n): ReadableStream<Uint8Array> {\n\tconst decoder = new TextDecoder();\n\tconst encoder = new TextEncoder();\n\t// Generate a stable ID and timestamp for the entire stream, matching OpenAI's\n\t// convention where all chunks in a single response share the same id/created.\n\tconst streamId = `workers-ai-${crypto.randomUUID()}`;\n\tconst created = Math.floor(Date.now() / 1000);\n\tlet buffer = \"\";\n\tlet hasToolCalls = false;\n\t// When true, the source stream is already in OpenAI format (some models\n\t// like Qwen3, Kimi K2.5 stream OpenAI-compatible SSE through the binding).\n\t// In that case, flush() should only emit [DONE] and skip the finish chunk.\n\tlet isOpenAiFormat = false;\n\t// Track tool call state per index: store the generated/assigned ID so that\n\t// subsequent argument deltas use the same ID (matching the working streaming.ts pattern).\n\tconst toolCallState = new Map<number, { id: string; name: string }>();\n\n\treturn source.pipeThrough(\n\t\tnew TransformStream<Uint8Array, Uint8Array>({\n\t\t\ttransform(chunk, controller) {\n\t\t\t\tbuffer += decoder.decode(chunk, { stream: true });\n\t\t\t\tconst lines = buffer.split(\"\\n\");\n\t\t\t\tbuffer = lines.pop() || \"\";\n\n\t\t\t\tfor (const line of lines) {\n\t\t\t\t\tconst trimmed = line.trim();\n\t\t\t\t\tif (!trimmed || !trimmed.startsWith(\"data: \")) continue;\n\t\t\t\t\tconst data = trimmed.slice(6);\n\n\t\t\t\t\t// Swallow source [DONE]; we emit our own in flush()\n\t\t\t\t\tif (data === \"[DONE]\") continue;\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst parsed = JSON.parse(data);\n\n\t\t\t\t\t\t// Some models (Qwen3, Kimi K2.5) return OpenAI-compatible format\n\t\t\t\t\t\t// directly through the binding, with `choices[].delta.content` and\n\t\t\t\t\t\t// optional `reasoning_content`. Detect this and pass through as-is.\n\t\t\t\t\t\tif (parsed.choices !== undefined) {\n\t\t\t\t\t\t\t// Already OpenAI format — pass through but ensure each tool call\n\t\t\t\t\t\t\t// index gets a unique, stable ID across all chunks.\n\t\t\t\t\t\t\tisOpenAiFormat = true;\n\t\t\t\t\t\t\tconst choice = parsed.choices?.[0];\n\t\t\t\t\t\t\tif (choice?.delta?.tool_calls) {\n\t\t\t\t\t\t\t\thasToolCalls = true;\n\t\t\t\t\t\t\t\tfor (const tc of choice.delta.tool_calls) {\n\t\t\t\t\t\t\t\t\tconst tcIndex = tc.index ?? 0;\n\t\t\t\t\t\t\t\t\tif (!toolCallState.has(tcIndex)) {\n\t\t\t\t\t\t\t\t\t\t// First chunk for this index — generate/store unique ID\n\t\t\t\t\t\t\t\t\t\tconst id = tc.id || `call${streamId}${tcIndex}`;\n\t\t\t\t\t\t\t\t\t\ttoolCallState.set(tcIndex, {\n\t\t\t\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\t\t\t\tname: tc.function?.name || \"\",\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\ttc.id = id;\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t// Subsequent chunk — reuse stored ID, remove id from delta\n\t\t\t\t\t\t\t\t\t\t// (OpenAI format only sends id in first chunk)\n\t\t\t\t\t\t\t\t\t\tdelete tc.id;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (choice?.finish_reason === \"tool_calls\") {\n\t\t\t\t\t\t\t\thasToolCalls = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcontroller.enqueue(\n\t\t\t\t\t\t\t\tencoder.encode(`data: ${JSON.stringify(parsed)}\\n\\n`),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// --- Workers AI native format handling below ---\n\n\t\t\t\t\t\t// Text content\n\t\t\t\t\t\tif (parsed.response != null && parsed.response !== \"\") {\n\t\t\t\t\t\t\tconst openAiChunk = {\n\t\t\t\t\t\t\t\tid: streamId,\n\t\t\t\t\t\t\t\tobject: \"chat.completion.chunk\",\n\t\t\t\t\t\t\t\tcreated,\n\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\tchoices: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tindex: 0,\n\t\t\t\t\t\t\t\t\t\tdelta: { content: parsed.response },\n\t\t\t\t\t\t\t\t\t\tfinish_reason: null,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tcontroller.enqueue(\n\t\t\t\t\t\t\t\tencoder.encode(`data: ${JSON.stringify(openAiChunk)}\\n\\n`),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Tool calls — Workers AI binding streams these incrementally:\n\t\t\t\t\t\t// Chunk A: { id, type, index, function: { name } } — start\n\t\t\t\t\t\t// Chunk B: { index, function: { arguments: \"partial...\" } } — args delta\n\t\t\t\t\t\t// Chunk C: { index, function: { arguments: \"rest...\" } } — args delta\n\t\t\t\t\t\t// Chunk D: { id: null, type: null, index, function: { name: null, arguments: \"\" } } — finalize (skip)\n\t\t\t\t\t\tif (Array.isArray(parsed.tool_calls) && parsed.tool_calls.length > 0) {\n\t\t\t\t\t\t\tfor (const tc of parsed.tool_calls) {\n\t\t\t\t\t\t\t\tconst tcIndex = tc.index ?? 0;\n\n\t\t\t\t\t\t\t\t// Resolve name and arguments from either nested or flat format\n\t\t\t\t\t\t\t\tconst tcName = tc.function?.name ?? tc.name ?? null;\n\t\t\t\t\t\t\t\tconst tcArgs = tc.function?.arguments ?? tc.arguments ?? null;\n\t\t\t\t\t\t\t\tconst tcId = tc.id ?? null;\n\n\t\t\t\t\t\t\t\t// Skip finalization chunks where everything is null/empty\n\t\t\t\t\t\t\t\tif (!tcId && !tcName && (!tcArgs || tcArgs === \"\")) continue;\n\n\t\t\t\t\t\t\t\thasToolCalls = true;\n\n\t\t\t\t\t\t\t\t// Build the OpenAI-compatible tool_calls delta\n\t\t\t\t\t\t\t\tconst toolCallDelta: Record<string, unknown> = {\n\t\t\t\t\t\t\t\t\tindex: tcIndex,\n\t\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\t\tif (!toolCallState.has(tcIndex)) {\n\t\t\t\t\t\t\t\t\t// First chunk for this tool call index — emit id, type, name.\n\t\t\t\t\t\t\t\t\tconst id = tcId || `call${streamId}${tcIndex}`;\n\t\t\t\t\t\t\t\t\ttoolCallState.set(tcIndex, { id, name: tcName || \"\" });\n\t\t\t\t\t\t\t\t\ttoolCallDelta.id = id;\n\t\t\t\t\t\t\t\t\ttoolCallDelta.type = \"function\";\n\t\t\t\t\t\t\t\t\ttoolCallDelta.function = {\n\t\t\t\t\t\t\t\t\t\tname: tcName || \"\",\n\t\t\t\t\t\t\t\t\t\t// Include arguments if they arrive in the same chunk\n\t\t\t\t\t\t\t\t\t\targuments:\n\t\t\t\t\t\t\t\t\t\t\ttcArgs != null\n\t\t\t\t\t\t\t\t\t\t\t\t? typeof tcArgs === \"string\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t? tcArgs\n\t\t\t\t\t\t\t\t\t\t\t\t\t: JSON.stringify(tcArgs)\n\t\t\t\t\t\t\t\t\t\t\t\t: \"\",\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// Subsequent chunks — only include arguments delta\n\t\t\t\t\t\t\t\t\tif (tcArgs != null && tcArgs !== \"\") {\n\t\t\t\t\t\t\t\t\t\ttoolCallDelta.function = {\n\t\t\t\t\t\t\t\t\t\t\targuments:\n\t\t\t\t\t\t\t\t\t\t\t\ttypeof tcArgs === \"string\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t? tcArgs\n\t\t\t\t\t\t\t\t\t\t\t\t\t: JSON.stringify(tcArgs),\n\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tcontinue; // Nothing useful to forward\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tconst toolChunk = {\n\t\t\t\t\t\t\t\t\tid: streamId,\n\t\t\t\t\t\t\t\t\tobject: \"chat.completion.chunk\",\n\t\t\t\t\t\t\t\t\tcreated,\n\t\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\t\tchoices: [\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tindex: 0,\n\t\t\t\t\t\t\t\t\t\t\tdelta: { tool_calls: [toolCallDelta] },\n\t\t\t\t\t\t\t\t\t\t\tfinish_reason: null,\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\tcontroller.enqueue(\n\t\t\t\t\t\t\t\t\tencoder.encode(`data: ${JSON.stringify(toolChunk)}\\n\\n`),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t// Log malformed SSE events for debugging; don't break the stream.\n\t\t\t\t\t\tconsole.warn(\"[tanstack-ai] failed to parse SSE event:\", data, e);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\tflush(controller) {\n\t\t\t\tif (!isOpenAiFormat) {\n\t\t\t\t\t// Workers AI native format: emit a finish chunk with stop/tool_calls\n\t\t\t\t\tconst finalChunk = {\n\t\t\t\t\t\tid: streamId,\n\t\t\t\t\t\tobject: \"chat.completion.chunk\",\n\t\t\t\t\t\tcreated,\n\t\t\t\t\t\tmodel,\n\t\t\t\t\t\tchoices: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tindex: 0,\n\t\t\t\t\t\t\t\tdelta: {},\n\t\t\t\t\t\t\t\tfinish_reason: hasToolCalls ? \"tool_calls\" : \"stop\",\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\tcontroller.enqueue(encoder.encode(`data: ${JSON.stringify(finalChunk)}\\n\\n`));\n\t\t\t\t}\n\t\t\t\t// OpenAI format already includes its own finish_reason in the stream.\n\t\t\t\t// Either way, emit a [DONE] sentinel.\n\t\t\t\tcontroller.enqueue(encoder.encode(\"data: [DONE]\\n\\n\"));\n\t\t\t},\n\t\t}),\n\t);\n}\n"],"mappings":";AA4HO,SAAS,sBACf,QACyC;AAGzC,SACC,aAAa,UACb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,YACD;AAAA,UACD,SAAS,GAAG;AAEX,oBAAQ,KAAK,4CAA4C,MAAM,CAAC;AAAA,UACjE;AAAA,QACD;AAAA,MACD;AAAA,MACA,MAAM,YAAY;AACjB,YAAI,CAAC,gBAAgB;AAEpB,gBAAM,aAAa;AAAA,YAClB,IAAI;AAAA,YACJ,QAAQ;AAAA,YACR;AAAA,YACA;AAAA,YACA,SAAS;AAAA,cACR;AAAA,gBACC,OAAO;AAAA,gBACP,OAAO,CAAC;AAAA,gBACR,eAAe,eAAe,eAAe;AAAA,cAC9C;AAAA,YACD;AAAA,UACD;AACA,qBAAW,QAAQ,QAAQ,OAAO,SAAS,KAAK,UAAU,UAAU,CAAC;AAAA;AAAA,CAAM,CAAC;AAAA,QAC7E;AAGA,mBAAW,QAAQ,QAAQ,OAAO,kBAAkB,CAAC;AAAA,MACtD;AAAA,IACD,CAAC;AAAA,EACF;AACD;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkU5NL4EM4cjs = require('./chunk-U5NL4EM4.cjs');
|
|
4
4
|
|
|
5
5
|
// src/adapters/openai.ts
|
|
6
6
|
|
|
@@ -19,7 +19,7 @@ var _aiopenai = require('@tanstack/ai-openai');
|
|
|
19
19
|
function buildOpenAiConfig(provider, config) {
|
|
20
20
|
return {
|
|
21
21
|
apiKey: _nullishCoalesce(config.apiKey, () => ( "unused")),
|
|
22
|
-
fetch:
|
|
22
|
+
fetch: _chunkU5NL4EM4cjs.createGatewayFetch.call(void 0, provider, config)
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
function createOpenAiChat(model, config) {
|
|
@@ -54,4 +54,4 @@ function createOpenAiVideo(model, config) {
|
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
exports.OPENAI_CHAT_MODELS = _aiopenai.OPENAI_CHAT_MODELS; exports.OPENAI_IMAGE_MODELS = _aiopenai.OPENAI_IMAGE_MODELS; exports.OPENAI_TRANSCRIPTION_MODELS = _aiopenai.OPENAI_TRANSCRIPTION_MODELS; exports.OPENAI_TTS_MODELS = _aiopenai.OPENAI_TTS_MODELS; exports.OPENAI_VIDEO_MODELS = _aiopenai.OPENAI_VIDEO_MODELS; exports.createOpenAiChat = createOpenAiChat; exports.createOpenAiSummarize = createOpenAiSummarize; exports.createOpenAiImage = createOpenAiImage; exports.createOpenAiTranscription = createOpenAiTranscription; exports.createOpenAiTts = createOpenAiTts; exports.createOpenAiVideo = createOpenAiVideo;
|
|
57
|
-
//# sourceMappingURL=chunk-
|
|
57
|
+
//# sourceMappingURL=chunk-TG4UQPGB.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/ai/ai/packages/tanstack-ai/dist/chunk-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/ai/ai/packages/tanstack-ai/dist/chunk-TG4UQPGB.cjs","../src/adapters/openai.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACJA;AACC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA,+CAMM;AASP,SAAS,iBAAA,CAAkB,QAAA,EAAkB,MAAA,EAA6B;AACzE,EAAA,OAAO;AAAA,IACN,MAAA,mBAAQ,MAAA,CAAO,MAAA,UAAU,UAAA;AAAA,IACzB,KAAA,EAAO,kDAAA,QAAmB,EAAU,MAAM;AAAA,EAC3C,CAAA;AACD;AAQO,SAAS,gBAAA,CAAiB,KAAA,EAAwB,MAAA,EAA6B;AACrF,EAAA,OAAO,IAAI,gCAAA,CAAkB,iBAAA,CAAkB,QAAA,EAAU,MAAM,CAAA,EAAG,KAAK,CAAA;AACxE;AAOO,SAAS,qBAAA,CAAsB,KAAA,EAAwB,MAAA,EAA6B;AAC1F,EAAA,OAAO,IAAI,qCAAA,CAAuB,iBAAA,CAAkB,QAAA,EAAU,MAAM,CAAA,EAAG,KAAK,CAAA;AAC7E;AAOO,SAAS,iBAAA,CAAkB,KAAA,EAAyB,MAAA,EAA6B;AACvF,EAAA,OAAO,IAAI,iCAAA,CAAmB,iBAAA,CAAkB,QAAA,EAAU,MAAM,CAAA,EAAG,KAAK,CAAA;AACzE;AAOO,SAAS,yBAAA,CACf,KAAA,EACA,MAAA,EACC;AACD,EAAA,OAAO,IAAI,yCAAA,CAA2B,iBAAA,CAAkB,QAAA,EAAU,MAAM,CAAA,EAAG,KAAK,CAAA;AACjF;AAOO,SAAS,eAAA,CAAgB,KAAA,EAAuB,MAAA,EAA6B;AACnF,EAAA,OAAO,IAAI,+BAAA,CAAiB,iBAAA,CAAkB,QAAA,EAAU,MAAM,CAAA,EAAG,KAAK,CAAA;AACvE;AAOO,SAAS,iBAAA,CAAkB,KAAA,EAAyB,MAAA,EAA6B;AACvF,EAAA,OAAO,IAAI,iCAAA,CAAmB,iBAAA,CAAkB,QAAA,EAAU,MAAM,CAAA,EAAG,KAAK,CAAA;AACzE;AD/CA;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,smBAAC","file":"/home/runner/work/ai/ai/packages/tanstack-ai/dist/chunk-TG4UQPGB.cjs","sourcesContent":[null,"import {\n\tOpenAIImageAdapter,\n\tOpenAISummarizeAdapter,\n\tOpenAITextAdapter,\n\tOpenAITranscriptionAdapter,\n\tOpenAITTSAdapter,\n\tOpenAIVideoAdapter,\n\tOPENAI_CHAT_MODELS,\n\tOPENAI_IMAGE_MODELS,\n\tOPENAI_TRANSCRIPTION_MODELS,\n\tOPENAI_TTS_MODELS,\n\tOPENAI_VIDEO_MODELS,\n\ttype OpenAIChatModel,\n\ttype OpenAIImageModel,\n\ttype OpenAITranscriptionModel,\n\ttype OpenAITTSModel,\n\ttype OpenAIVideoModel,\n} from \"@tanstack/ai-openai\";\nimport { createGatewayFetch, type AiGatewayAdapterConfig } from \"../utils/create-fetcher\";\n\nexport type OpenAiGatewayConfig = AiGatewayAdapterConfig;\n\n/**\n * Builds an OpenAI-compatible config that injects the gateway fetch.\n * OpenAITextConfig extends OpenAI SDK's ClientOptions, which supports a `fetch` parameter.\n */\nfunction buildOpenAiConfig(provider: string, config: OpenAiGatewayConfig) {\n\treturn {\n\t\tapiKey: config.apiKey ?? \"unused\",\n\t\tfetch: createGatewayFetch(provider, config),\n\t};\n}\n\n/**\n * Creates an OpenAI chat adapter which uses Cloudflare AI Gateway.\n * Supports both binding and credential-based configurations.\n * @param model The OpenAI model to use\n * @param config Configuration options\n */\nexport function createOpenAiChat(model: OpenAIChatModel, config: OpenAiGatewayConfig) {\n\treturn new OpenAITextAdapter(buildOpenAiConfig(\"openai\", config), model);\n}\n\n/**\n * Creates an OpenAI summarize adapter which uses Cloudflare AI Gateway.\n * @param model The OpenAI model to use\n * @param config Configuration options\n */\nexport function createOpenAiSummarize(model: OpenAIChatModel, config: OpenAiGatewayConfig) {\n\treturn new OpenAISummarizeAdapter(buildOpenAiConfig(\"openai\", config), model);\n}\n\n/**\n * Creates an OpenAI image adapter which uses Cloudflare AI Gateway.\n * @param model The OpenAI image model to use\n * @param config Configuration options\n */\nexport function createOpenAiImage(model: OpenAIImageModel, config: OpenAiGatewayConfig) {\n\treturn new OpenAIImageAdapter(buildOpenAiConfig(\"openai\", config), model);\n}\n\n/**\n * Creates an OpenAI transcription adapter which uses Cloudflare AI Gateway.\n * @param model The OpenAI transcription model to use\n * @param config Configuration options\n */\nexport function createOpenAiTranscription(\n\tmodel: OpenAITranscriptionModel,\n\tconfig: OpenAiGatewayConfig,\n) {\n\treturn new OpenAITranscriptionAdapter(buildOpenAiConfig(\"openai\", config), model);\n}\n\n/**\n * Creates an OpenAI TTS adapter which uses Cloudflare AI Gateway.\n * @param model The OpenAI TTS model to use\n * @param config Configuration options\n */\nexport function createOpenAiTts(model: OpenAITTSModel, config: OpenAiGatewayConfig) {\n\treturn new OpenAITTSAdapter(buildOpenAiConfig(\"openai\", config), model);\n}\n\n/**\n * Creates an OpenAI video adapter which uses Cloudflare AI Gateway.\n * @param model The OpenAI video model to use\n * @param config Configuration options\n */\nexport function createOpenAiVideo(model: OpenAIVideoModel, config: OpenAiGatewayConfig) {\n\treturn new OpenAIVideoAdapter(buildOpenAiConfig(\"openai\", config), model);\n}\n\nexport {\n\tOPENAI_CHAT_MODELS,\n\tOPENAI_IMAGE_MODELS,\n\tOPENAI_TRANSCRIPTION_MODELS,\n\tOPENAI_TTS_MODELS,\n\tOPENAI_VIDEO_MODELS,\n\ttype OpenAIChatModel,\n\ttype OpenAIImageModel,\n\ttype OpenAITranscriptionModel,\n\ttype OpenAITTSModel,\n\ttype OpenAIVideoModel,\n};\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkU5NL4EM4cjs = require('./chunk-U5NL4EM4.cjs');
|
|
4
4
|
|
|
5
5
|
// src/adapters/openrouter.ts
|
|
6
6
|
|
|
@@ -11,7 +11,7 @@ var _aiopenrouter = require('@tanstack/ai-openrouter');
|
|
|
11
11
|
var _sdk = require('@openrouter/sdk');
|
|
12
12
|
function buildOpenRouterConfig(config) {
|
|
13
13
|
const httpClient = new (0, _sdk.HTTPClient)({
|
|
14
|
-
fetcher:
|
|
14
|
+
fetcher: _chunkU5NL4EM4cjs.createGatewayFetch.call(void 0, "openrouter", config)
|
|
15
15
|
});
|
|
16
16
|
return {
|
|
17
17
|
apiKey: _nullishCoalesce(config.apiKey, () => ( "unused")),
|
|
@@ -23,7 +23,7 @@ function buildOpenRouterConfig(config) {
|
|
|
23
23
|
}
|
|
24
24
|
function buildOpenRouterImageConfig(config) {
|
|
25
25
|
const httpClient = new (0, _sdk.HTTPClient)({
|
|
26
|
-
fetcher:
|
|
26
|
+
fetcher: _chunkU5NL4EM4cjs.createGatewayFetch.call(void 0, "openrouter", config)
|
|
27
27
|
});
|
|
28
28
|
return {
|
|
29
29
|
apiKey: _nullishCoalesce(config.apiKey, () => ( "unused")),
|
|
@@ -32,7 +32,7 @@ function buildOpenRouterImageConfig(config) {
|
|
|
32
32
|
}
|
|
33
33
|
function buildOpenRouterSummarizeConfig(config) {
|
|
34
34
|
const httpClient = new (0, _sdk.HTTPClient)({
|
|
35
|
-
fetcher:
|
|
35
|
+
fetcher: _chunkU5NL4EM4cjs.createGatewayFetch.call(void 0, "openrouter", config)
|
|
36
36
|
});
|
|
37
37
|
return {
|
|
38
38
|
apiKey: _nullishCoalesce(config.apiKey, () => ( "unused")),
|
|
@@ -54,4 +54,4 @@ function createOpenRouterSummarize(model, config) {
|
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
exports.createOpenRouterChat = createOpenRouterChat; exports.createOpenRouterImage = createOpenRouterImage; exports.createOpenRouterSummarize = createOpenRouterSummarize;
|
|
57
|
-
//# sourceMappingURL=chunk-
|
|
57
|
+
//# sourceMappingURL=chunk-U2PMR3PT.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/ai/ai/packages/tanstack-ai/dist/chunk-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/ai/ai/packages/tanstack-ai/dist/chunk-U2PMR3PT.cjs","../src/adapters/openrouter.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACJA;AACC;AACA;AACA;AAAA,uDAIM;AACP,sCAA2B;AAY3B,SAAS,qBAAA,CAAsB,MAAA,EAAmD;AACjF,EAAA,MAAM,WAAA,EAAa,IAAI,oBAAA,CAAW;AAAA,IACjC,OAAA,EAAS,kDAAA,YAAmB,EAAc,MAAM;AAAA,EACjD,CAAC,CAAA;AACD,EAAA,OAAO;AAAA,IACN,MAAA,mBAAQ,MAAA,CAAO,MAAA,UAAU,UAAA;AAAA;AAAA;AAAA;AAAA,IAIzB;AAAA,EACD,CAAA;AACD;AAWA,SAAS,0BAAA,CAA2B,MAAA,EAAwD;AAC3F,EAAA,MAAM,WAAA,EAAa,IAAI,oBAAA,CAAW;AAAA,IACjC,OAAA,EAAS,kDAAA,YAAmB,EAAc,MAAM;AAAA,EACjD,CAAC,CAAA;AACD,EAAA,OAAO;AAAA,IACN,MAAA,mBAAQ,MAAA,CAAO,MAAA,UAAU,UAAA;AAAA,IACzB;AAAA,EACD,CAAA;AACD;AASA,SAAS,8BAAA,CACR,MAAA,EAC4B;AAC5B,EAAA,MAAM,WAAA,EAAa,IAAI,oBAAA,CAAW;AAAA,IACjC,OAAA,EAAS,kDAAA,YAAmB,EAAc,MAAM;AAAA,EACjD,CAAC,CAAA;AACD,EAAA,OAAO;AAAA,IACN,MAAA,mBAAQ,MAAA,CAAO,MAAA,UAAU,UAAA;AAAA,IACzB;AAAA,EACD,CAAA;AACD;AA0BO,SAAS,oBAAA,CACf,KAAA,EACA,MAAA,EACiB;AAEjB,EAAA,OAAO,IAAI,wCAAA,CAAsB,qBAAA,CAAsB,MAAM,CAAA,EAAG,KAAY,CAAA;AAC7E;AASO,SAAS,qBAAA,CACf,KAAA,EACA,MAAA,EACC;AAED,EAAA,OAAO,IAAI,yCAAA,CAAuB,0BAAA,CAA2B,MAAM,CAAA,EAAG,KAAY,CAAA;AACnF;AASO,SAAS,yBAAA,CACf,KAAA,EACA,MAAA,EACC;AAED,EAAA,OAAO,IAAI,6CAAA,CAA2B,8BAAA,CAA+B,MAAM,CAAA,EAAG,KAAY,CAAA;AAC3F;ADjFA;AACA;AACE;AACA;AACA;AACF,0KAAC","file":"/home/runner/work/ai/ai/packages/tanstack-ai/dist/chunk-U2PMR3PT.cjs","sourcesContent":[null,"import {\n\tOpenRouterTextAdapter,\n\tOpenRouterImageAdapter,\n\tOpenRouterSummarizeAdapter,\n\ttype OpenRouterConfig,\n\ttype OpenRouterImageConfig,\n\ttype OpenRouterSummarizeConfig,\n} from \"@tanstack/ai-openrouter\";\nimport { HTTPClient } from \"@openrouter/sdk\";\nimport { createGatewayFetch, type AiGatewayAdapterConfig } from \"../utils/create-fetcher\";\nimport type { AnyTextAdapter } from \"@tanstack/ai\";\n\nexport type OpenRouterGatewayConfig = AiGatewayAdapterConfig;\n\n/**\n * Build OpenRouter config that routes requests through AI Gateway.\n *\n * The OpenRouter SDK accepts an `httpClient` with a custom `fetcher`,\n * which we use to inject the AI Gateway fetch.\n */\nfunction buildOpenRouterConfig(config: OpenRouterGatewayConfig): OpenRouterConfig {\n\tconst httpClient = new HTTPClient({\n\t\tfetcher: createGatewayFetch(\"openrouter\", config),\n\t});\n\treturn {\n\t\tapiKey: config.apiKey ?? \"unused\",\n\t\t// Cast needed: the installed @openrouter/sdk version may differ from the\n\t\t// version @tanstack/ai-openrouter was built against. The HTTPClient interface\n\t\t// is structurally compatible but TypeScript sees them as separate declarations.\n\t\thttpClient: httpClient as unknown as OpenRouterConfig[\"httpClient\"],\n\t};\n}\n\n/**\n * Build OpenRouter image config that routes requests through AI Gateway.\n *\n * `OpenRouterImageConfig` extends `OpenRouterClientConfig` which declares\n * `baseURL` and `apiKey` but not `httpClient`. However, the image adapter\n * internally creates an `OpenRouter` SDK instance (which does accept\n * `httpClient` via `SDKOptions`). The double-cast is needed because the\n * declared config type is narrower than what the SDK constructor accepts.\n */\nfunction buildOpenRouterImageConfig(config: OpenRouterGatewayConfig): OpenRouterImageConfig {\n\tconst httpClient = new HTTPClient({\n\t\tfetcher: createGatewayFetch(\"openrouter\", config),\n\t});\n\treturn {\n\t\tapiKey: config.apiKey ?? \"unused\",\n\t\thttpClient,\n\t} as unknown as OpenRouterImageConfig;\n}\n\n/**\n * Build OpenRouter summarize config.\n *\n * `OpenRouterSummarizeConfig` extends `OpenRouterConfig` with optional\n * `temperature` and `maxTokens` fields. Since those are optional, a plain\n * `OpenRouterConfig` is structurally compatible — no cast needed.\n */\nfunction buildOpenRouterSummarizeConfig(\n\tconfig: OpenRouterGatewayConfig,\n): OpenRouterSummarizeConfig {\n\tconst httpClient = new HTTPClient({\n\t\tfetcher: createGatewayFetch(\"openrouter\", config),\n\t});\n\treturn {\n\t\tapiKey: config.apiKey ?? \"unused\",\n\t\thttpClient: httpClient as unknown as OpenRouterSummarizeConfig[\"httpClient\"],\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Chat model type — OpenRouter supports many models; we use a loose string type\n// ---------------------------------------------------------------------------\n\n/** OpenRouter chat model identifier. Accepts any string since OpenRouter proxies hundreds of models. */\nexport type OpenRouterChatModel = string;\n\n/** OpenRouter image model identifier. */\nexport type OpenRouterImageModel = string;\n\n/** OpenRouter summarize model identifier (same as chat models). */\nexport type OpenRouterSummarizeModel = string;\n\n// ---------------------------------------------------------------------------\n// Factory functions\n// ---------------------------------------------------------------------------\n\n/**\n * Creates an OpenRouter chat adapter which uses Cloudflare AI Gateway.\n * Supports both binding and credential-based configurations.\n *\n * @param model The model to use (e.g. \"openai/gpt-4o\", \"anthropic/claude-sonnet-4-5\")\n * @param config Configuration options\n */\nexport function createOpenRouterChat(\n\tmodel: OpenRouterChatModel,\n\tconfig: OpenRouterGatewayConfig,\n): AnyTextAdapter {\n\t// Cast needed: we accept any string model while upstream expects a literal union\n\treturn new OpenRouterTextAdapter(buildOpenRouterConfig(config), model as any);\n}\n\n/**\n * Creates an OpenRouter image adapter which uses Cloudflare AI Gateway.\n * Supports both binding and credential-based configurations.\n *\n * @param model The image model to use\n * @param config Configuration options\n */\nexport function createOpenRouterImage(\n\tmodel: OpenRouterImageModel,\n\tconfig: OpenRouterGatewayConfig,\n) {\n\t// Cast needed: we accept any string model while upstream expects a literal union\n\treturn new OpenRouterImageAdapter(buildOpenRouterImageConfig(config), model as any);\n}\n\n/**\n * Creates an OpenRouter summarize adapter which uses Cloudflare AI Gateway.\n * Supports both binding and credential-based configurations.\n *\n * @param model The model to use for summarization\n * @param config Configuration options\n */\nexport function createOpenRouterSummarize(\n\tmodel: OpenRouterSummarizeModel,\n\tconfig: OpenRouterGatewayConfig,\n) {\n\t// Cast needed: we accept any string model while upstream expects a literal union\n\treturn new OpenRouterSummarizeAdapter(buildOpenRouterSummarizeConfig(config), model as any);\n}\n"]}
|