@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
package/README.md
CHANGED
|
@@ -68,6 +68,39 @@ const adapter = createWorkersAiChat("@cf/meta/llama-4-scout-17b-16e-instruct", {
|
|
|
68
68
|
});
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
+
### Vision (Image Inputs)
|
|
72
|
+
|
|
73
|
+
Send images to vision-capable chat models:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
const adapter = createWorkersAiChat("@cf/meta/llama-4-scout-17b-16e-instruct", {
|
|
77
|
+
accountId: "your-account-id",
|
|
78
|
+
apiKey: "your-api-key",
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const response = chat({
|
|
82
|
+
adapter,
|
|
83
|
+
stream: true,
|
|
84
|
+
messages: [
|
|
85
|
+
{
|
|
86
|
+
role: "user",
|
|
87
|
+
content: [
|
|
88
|
+
{ type: "text", content: "What's in this image?" },
|
|
89
|
+
{ type: "image", source: { type: "data", value: base64String, mimeType: "image/png" } },
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
URL sources are also supported:
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
{ type: "image", source: { type: "url", value: "https://example.com/photo.jpg" } }
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Works with all configuration modes (binding, REST, and AI Gateway).
|
|
103
|
+
|
|
71
104
|
### Image Generation
|
|
72
105
|
|
|
73
106
|
```typescript
|
|
@@ -275,6 +308,15 @@ Workers AI supports four configuration modes:
|
|
|
275
308
|
|
|
276
309
|
Third-party providers (OpenAI, Anthropic, Gemini, Grok, OpenRouter) only support the gateway modes.
|
|
277
310
|
|
|
311
|
+
All Workers AI config modes also accept `sessionAffinity` to route requests with the same key to the same backend replica for prefix-cache optimization:
|
|
312
|
+
|
|
313
|
+
```typescript
|
|
314
|
+
const adapter = createWorkersAiChat("@cf/meta/llama-3.3-70b-instruct-fp8-fast", {
|
|
315
|
+
binding: env.AI,
|
|
316
|
+
sessionAffinity: "my-unique-session-id",
|
|
317
|
+
});
|
|
318
|
+
```
|
|
319
|
+
|
|
278
320
|
## Links
|
|
279
321
|
|
|
280
322
|
- [TanStack AI Documentation](https://tanstack.com/ai)
|
|
@@ -2,6 +2,7 @@ import type { AiModels as AiModels_2 } from '@cloudflare/workers-types';
|
|
|
2
2
|
import { ANTHROPIC_MODELS } from '@tanstack/ai-anthropic';
|
|
3
3
|
import { AnthropicChatModel } from '@tanstack/ai-anthropic';
|
|
4
4
|
import { AnthropicSummarizeAdapter } from '@tanstack/ai-anthropic';
|
|
5
|
+
import { AnthropicTextAdapter } from '@tanstack/ai-anthropic';
|
|
5
6
|
import type { AnyTextAdapter } from '@tanstack/ai';
|
|
6
7
|
import type { BaseAiTextEmbeddings as BaseAiTextEmbeddings_2 } from '@cloudflare/workers-types';
|
|
7
8
|
import type { BaseAiTextGeneration as BaseAiTextGeneration_2 } from '@cloudflare/workers-types';
|
|
@@ -146,7 +147,7 @@ export declare function collectStream(stream: ReadableStream<Uint8Array>): Promi
|
|
|
146
147
|
* Since AnthropicTextConfig extends the Anthropic SDK's ClientOptions,
|
|
147
148
|
* we can inject the gateway fetch directly — no subclassing needed.
|
|
148
149
|
*/
|
|
149
|
-
declare function createAnthropicChat(model: AnthropicChatModel, config: AnthropicGatewayConfig):
|
|
150
|
+
declare function createAnthropicChat(model: AnthropicChatModel, config: AnthropicGatewayConfig): AnthropicTextAdapter<AnthropicChatModel>;
|
|
150
151
|
export { createAnthropicChat }
|
|
151
152
|
export { createAnthropicChat as createAnthropicChat_alias_1 }
|
|
152
153
|
|
|
@@ -330,7 +331,9 @@ export { createOpenRouterSummarize as createOpenRouterSummarize_alias_1 }
|
|
|
330
331
|
* request parameters are extracted from the JSON body, matching Workers AI's
|
|
331
332
|
* `binding.run(model, inputs)` calling convention.
|
|
332
333
|
*/
|
|
333
|
-
export declare function createWorkersAiBindingFetch(binding: WorkersAiBinding
|
|
334
|
+
export declare function createWorkersAiBindingFetch(binding: WorkersAiBinding, options?: {
|
|
335
|
+
extraHeaders?: Record<string, string>;
|
|
336
|
+
}): typeof fetch;
|
|
334
337
|
|
|
335
338
|
declare function createWorkersAiChat(model: WorkersAiTextModel, config: WorkersAiAdapterConfig): WorkersAiTextAdapter<WorkersAiTextModel>;
|
|
336
339
|
export { createWorkersAiChat }
|
|
@@ -601,9 +604,15 @@ export declare function validateWorkersAiConfig(config: WorkersAiAdapterConfig):
|
|
|
601
604
|
* upstream provider), distinct from `cfApiKey` (used in the `cf-aig-authorization`
|
|
602
605
|
* header for authenticated gateways).
|
|
603
606
|
*/
|
|
604
|
-
declare type WorkersAiAdapterConfig = WorkersAiDirectBindingConfig | WorkersAiDirectCredentialsConfig | (AiGatewayAdapterConfig & {
|
|
607
|
+
declare type WorkersAiAdapterConfig = (WorkersAiDirectBindingConfig | WorkersAiDirectCredentialsConfig | (AiGatewayAdapterConfig & {
|
|
605
608
|
apiKey?: string;
|
|
606
|
-
})
|
|
609
|
+
})) & {
|
|
610
|
+
/**
|
|
611
|
+
* Session affinity key for prefix-cache optimization.
|
|
612
|
+
* Routes requests with the same key to the same backend replica.
|
|
613
|
+
*/
|
|
614
|
+
sessionAffinity?: string;
|
|
615
|
+
};
|
|
607
616
|
export { WorkersAiAdapterConfig }
|
|
608
617
|
export { WorkersAiAdapterConfig as WorkersAiAdapterConfig_alias_1 }
|
|
609
618
|
|
|
@@ -2,6 +2,7 @@ import type { AiModels as AiModels_2 } from '@cloudflare/workers-types';
|
|
|
2
2
|
import { ANTHROPIC_MODELS } from '@tanstack/ai-anthropic';
|
|
3
3
|
import { AnthropicChatModel } from '@tanstack/ai-anthropic';
|
|
4
4
|
import { AnthropicSummarizeAdapter } from '@tanstack/ai-anthropic';
|
|
5
|
+
import { AnthropicTextAdapter } from '@tanstack/ai-anthropic';
|
|
5
6
|
import type { AnyTextAdapter } from '@tanstack/ai';
|
|
6
7
|
import type { BaseAiTextEmbeddings as BaseAiTextEmbeddings_2 } from '@cloudflare/workers-types';
|
|
7
8
|
import type { BaseAiTextGeneration as BaseAiTextGeneration_2 } from '@cloudflare/workers-types';
|
|
@@ -146,7 +147,7 @@ export declare function collectStream(stream: ReadableStream<Uint8Array>): Promi
|
|
|
146
147
|
* Since AnthropicTextConfig extends the Anthropic SDK's ClientOptions,
|
|
147
148
|
* we can inject the gateway fetch directly — no subclassing needed.
|
|
148
149
|
*/
|
|
149
|
-
declare function createAnthropicChat(model: AnthropicChatModel, config: AnthropicGatewayConfig):
|
|
150
|
+
declare function createAnthropicChat(model: AnthropicChatModel, config: AnthropicGatewayConfig): AnthropicTextAdapter<AnthropicChatModel>;
|
|
150
151
|
export { createAnthropicChat }
|
|
151
152
|
export { createAnthropicChat as createAnthropicChat_alias_1 }
|
|
152
153
|
|
|
@@ -330,7 +331,9 @@ export { createOpenRouterSummarize as createOpenRouterSummarize_alias_1 }
|
|
|
330
331
|
* request parameters are extracted from the JSON body, matching Workers AI's
|
|
331
332
|
* `binding.run(model, inputs)` calling convention.
|
|
332
333
|
*/
|
|
333
|
-
export declare function createWorkersAiBindingFetch(binding: WorkersAiBinding
|
|
334
|
+
export declare function createWorkersAiBindingFetch(binding: WorkersAiBinding, options?: {
|
|
335
|
+
extraHeaders?: Record<string, string>;
|
|
336
|
+
}): typeof fetch;
|
|
334
337
|
|
|
335
338
|
declare function createWorkersAiChat(model: WorkersAiTextModel, config: WorkersAiAdapterConfig): WorkersAiTextAdapter<WorkersAiTextModel>;
|
|
336
339
|
export { createWorkersAiChat }
|
|
@@ -601,9 +604,15 @@ export declare function validateWorkersAiConfig(config: WorkersAiAdapterConfig):
|
|
|
601
604
|
* upstream provider), distinct from `cfApiKey` (used in the `cf-aig-authorization`
|
|
602
605
|
* header for authenticated gateways).
|
|
603
606
|
*/
|
|
604
|
-
declare type WorkersAiAdapterConfig = WorkersAiDirectBindingConfig | WorkersAiDirectCredentialsConfig | (AiGatewayAdapterConfig & {
|
|
607
|
+
declare type WorkersAiAdapterConfig = (WorkersAiDirectBindingConfig | WorkersAiDirectCredentialsConfig | (AiGatewayAdapterConfig & {
|
|
605
608
|
apiKey?: string;
|
|
606
|
-
})
|
|
609
|
+
})) & {
|
|
610
|
+
/**
|
|
611
|
+
* Session affinity key for prefix-cache optimization.
|
|
612
|
+
* Routes requests with the same key to the same backend replica.
|
|
613
|
+
*/
|
|
614
|
+
sessionAffinity?: string;
|
|
615
|
+
};
|
|
607
616
|
export { WorkersAiAdapterConfig }
|
|
608
617
|
export { WorkersAiAdapterConfig as WorkersAiAdapterConfig_alias_1 }
|
|
609
618
|
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
require('../chunk-
|
|
5
|
+
var _chunkMMTLH53Hcjs = require('../chunk-MMTLH53H.cjs');
|
|
6
|
+
require('../chunk-U5NL4EM4.cjs');
|
|
7
7
|
require('../chunk-4DE2IREA.cjs');
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
exports.ANTHROPIC_MODELS =
|
|
12
|
+
exports.ANTHROPIC_MODELS = _chunkMMTLH53Hcjs.ANTHROPIC_MODELS; exports.createAnthropicChat = _chunkMMTLH53Hcjs.createAnthropicChat; exports.createAnthropicSummarize = _chunkMMTLH53Hcjs.createAnthropicSummarize;
|
|
13
13
|
//# sourceMappingURL=anthropic.cjs.map
|
|
@@ -2,8 +2,8 @@ import {
|
|
|
2
2
|
ANTHROPIC_MODELS,
|
|
3
3
|
createAnthropicChat,
|
|
4
4
|
createAnthropicSummarize
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-
|
|
5
|
+
} from "../chunk-MOAWHNNP.js";
|
|
6
|
+
import "../chunk-S5QBHI6O.js";
|
|
7
7
|
import "../chunk-V6TY7KAL.js";
|
|
8
8
|
export {
|
|
9
9
|
ANTHROPIC_MODELS,
|
package/dist/adapters/grok.cjs
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
8
|
-
require('../chunk-
|
|
7
|
+
var _chunkKW27GIQLcjs = require('../chunk-KW27GIQL.cjs');
|
|
8
|
+
require('../chunk-U5NL4EM4.cjs');
|
|
9
9
|
require('../chunk-4DE2IREA.cjs');
|
|
10
10
|
|
|
11
11
|
|
|
@@ -13,5 +13,5 @@ require('../chunk-4DE2IREA.cjs');
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
exports.GROK_CHAT_MODELS =
|
|
16
|
+
exports.GROK_CHAT_MODELS = _chunkKW27GIQLcjs.GROK_CHAT_MODELS; exports.GROK_IMAGE_MODELS = _chunkKW27GIQLcjs.GROK_IMAGE_MODELS; exports.createGrokChat = _chunkKW27GIQLcjs.createGrokChat; exports.createGrokImage = _chunkKW27GIQLcjs.createGrokImage; exports.createGrokSummarize = _chunkKW27GIQLcjs.createGrokSummarize;
|
|
17
17
|
//# sourceMappingURL=grok.cjs.map
|
package/dist/adapters/grok.js
CHANGED
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
createGrokChat,
|
|
5
5
|
createGrokImage,
|
|
6
6
|
createGrokSummarize
|
|
7
|
-
} from "../chunk-
|
|
8
|
-
import "../chunk-
|
|
7
|
+
} from "../chunk-OGAH3FYW.js";
|
|
8
|
+
import "../chunk-S5QBHI6O.js";
|
|
9
9
|
import "../chunk-V6TY7KAL.js";
|
|
10
10
|
export {
|
|
11
11
|
GROK_CHAT_MODELS,
|
package/dist/adapters/openai.cjs
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var
|
|
14
|
-
require('../chunk-
|
|
13
|
+
var _chunkTG4UQPGBcjs = require('../chunk-TG4UQPGB.cjs');
|
|
14
|
+
require('../chunk-U5NL4EM4.cjs');
|
|
15
15
|
require('../chunk-4DE2IREA.cjs');
|
|
16
16
|
|
|
17
17
|
|
|
@@ -25,5 +25,5 @@ require('../chunk-4DE2IREA.cjs');
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
exports.OPENAI_CHAT_MODELS =
|
|
28
|
+
exports.OPENAI_CHAT_MODELS = _chunkTG4UQPGBcjs.OPENAI_CHAT_MODELS; exports.OPENAI_IMAGE_MODELS = _chunkTG4UQPGBcjs.OPENAI_IMAGE_MODELS; exports.OPENAI_TRANSCRIPTION_MODELS = _chunkTG4UQPGBcjs.OPENAI_TRANSCRIPTION_MODELS; exports.OPENAI_TTS_MODELS = _chunkTG4UQPGBcjs.OPENAI_TTS_MODELS; exports.OPENAI_VIDEO_MODELS = _chunkTG4UQPGBcjs.OPENAI_VIDEO_MODELS; exports.createOpenAiChat = _chunkTG4UQPGBcjs.createOpenAiChat; exports.createOpenAiImage = _chunkTG4UQPGBcjs.createOpenAiImage; exports.createOpenAiSummarize = _chunkTG4UQPGBcjs.createOpenAiSummarize; exports.createOpenAiTranscription = _chunkTG4UQPGBcjs.createOpenAiTranscription; exports.createOpenAiTts = _chunkTG4UQPGBcjs.createOpenAiTts; exports.createOpenAiVideo = _chunkTG4UQPGBcjs.createOpenAiVideo;
|
|
29
29
|
//# sourceMappingURL=openai.cjs.map
|
package/dist/adapters/openai.js
CHANGED
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
createOpenAiTranscription,
|
|
11
11
|
createOpenAiTts,
|
|
12
12
|
createOpenAiVideo
|
|
13
|
-
} from "../chunk-
|
|
14
|
-
import "../chunk-
|
|
13
|
+
} from "../chunk-RWLCEKT6.js";
|
|
14
|
+
import "../chunk-S5QBHI6O.js";
|
|
15
15
|
import "../chunk-V6TY7KAL.js";
|
|
16
16
|
export {
|
|
17
17
|
OPENAI_CHAT_MODELS,
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
require('../chunk-
|
|
5
|
+
var _chunkU2PMR3PTcjs = require('../chunk-U2PMR3PT.cjs');
|
|
6
|
+
require('../chunk-U5NL4EM4.cjs');
|
|
7
7
|
require('../chunk-4DE2IREA.cjs');
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
exports.createOpenRouterChat =
|
|
12
|
+
exports.createOpenRouterChat = _chunkU2PMR3PTcjs.createOpenRouterChat; exports.createOpenRouterImage = _chunkU2PMR3PTcjs.createOpenRouterImage; exports.createOpenRouterSummarize = _chunkU2PMR3PTcjs.createOpenRouterSummarize;
|
|
13
13
|
//# sourceMappingURL=openrouter.cjs.map
|
|
@@ -2,8 +2,8 @@ import {
|
|
|
2
2
|
createOpenRouterChat,
|
|
3
3
|
createOpenRouterImage,
|
|
4
4
|
createOpenRouterSummarize
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-
|
|
5
|
+
} from "../chunk-I2MCLFJ5.js";
|
|
6
|
+
import "../chunk-S5QBHI6O.js";
|
|
7
7
|
import "../chunk-V6TY7KAL.js";
|
|
8
8
|
export {
|
|
9
9
|
createOpenRouterChat,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunk3PJHW45Xcjs = require('../chunk-3PJHW45X.cjs');
|
|
5
5
|
require('../chunk-3VQDXJLW.cjs');
|
|
6
6
|
require('../chunk-7HSUHP63.cjs');
|
|
7
|
-
require('../chunk-
|
|
7
|
+
require('../chunk-U5NL4EM4.cjs');
|
|
8
8
|
require('../chunk-4DE2IREA.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
exports.WorkersAiImageAdapter =
|
|
12
|
+
exports.WorkersAiImageAdapter = _chunk3PJHW45Xcjs.WorkersAiImageAdapter; exports.createWorkersAiImage = _chunk3PJHW45Xcjs.createWorkersAiImage;
|
|
13
13
|
//# sourceMappingURL=workers-ai-image.cjs.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
WorkersAiImageAdapter,
|
|
3
3
|
createWorkersAiImage
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-ZJMMBD6H.js";
|
|
5
5
|
import "../chunk-XU7YEPML.js";
|
|
6
6
|
import "../chunk-2VII5BK2.js";
|
|
7
|
-
import "../chunk-
|
|
7
|
+
import "../chunk-S5QBHI6O.js";
|
|
8
8
|
import "../chunk-V6TY7KAL.js";
|
|
9
9
|
export {
|
|
10
10
|
WorkersAiImageAdapter,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkH24HFVUJcjs = require('../chunk-H24HFVUJ.cjs');
|
|
5
5
|
require('../chunk-7HSUHP63.cjs');
|
|
6
|
-
require('../chunk-
|
|
6
|
+
require('../chunk-U5NL4EM4.cjs');
|
|
7
7
|
require('../chunk-4DE2IREA.cjs');
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
exports.WorkersAiSummarizeAdapter =
|
|
11
|
+
exports.WorkersAiSummarizeAdapter = _chunkH24HFVUJcjs.WorkersAiSummarizeAdapter; exports.createWorkersAiSummarize = _chunkH24HFVUJcjs.createWorkersAiSummarize;
|
|
12
12
|
//# sourceMappingURL=workers-ai-summarize.cjs.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
WorkersAiSummarizeAdapter,
|
|
3
3
|
createWorkersAiSummarize
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-IPEZXCDR.js";
|
|
5
5
|
import "../chunk-2VII5BK2.js";
|
|
6
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-S5QBHI6O.js";
|
|
7
7
|
import "../chunk-V6TY7KAL.js";
|
|
8
8
|
export {
|
|
9
9
|
WorkersAiSummarizeAdapter,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkXFQ3QESXcjs = require('../chunk-XFQ3QESX.cjs');
|
|
5
5
|
require('../chunk-3VQDXJLW.cjs');
|
|
6
6
|
require('../chunk-7HSUHP63.cjs');
|
|
7
|
-
require('../chunk-
|
|
7
|
+
require('../chunk-U5NL4EM4.cjs');
|
|
8
8
|
require('../chunk-4DE2IREA.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
exports.WorkersAiTranscriptionAdapter =
|
|
12
|
+
exports.WorkersAiTranscriptionAdapter = _chunkXFQ3QESXcjs.WorkersAiTranscriptionAdapter; exports.createWorkersAiTranscription = _chunkXFQ3QESXcjs.createWorkersAiTranscription;
|
|
13
13
|
//# sourceMappingURL=workers-ai-transcription.cjs.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
WorkersAiTranscriptionAdapter,
|
|
3
3
|
createWorkersAiTranscription
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-DG46OSFY.js";
|
|
5
5
|
import "../chunk-XU7YEPML.js";
|
|
6
6
|
import "../chunk-2VII5BK2.js";
|
|
7
|
-
import "../chunk-
|
|
7
|
+
import "../chunk-S5QBHI6O.js";
|
|
8
8
|
import "../chunk-V6TY7KAL.js";
|
|
9
9
|
export {
|
|
10
10
|
WorkersAiTranscriptionAdapter,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkKDVHOUEPcjs = require('../chunk-KDVHOUEP.cjs');
|
|
5
5
|
require('../chunk-3VQDXJLW.cjs');
|
|
6
6
|
require('../chunk-7HSUHP63.cjs');
|
|
7
|
-
require('../chunk-
|
|
7
|
+
require('../chunk-U5NL4EM4.cjs');
|
|
8
8
|
require('../chunk-4DE2IREA.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
exports.WorkersAiTTSAdapter =
|
|
12
|
+
exports.WorkersAiTTSAdapter = _chunkKDVHOUEPcjs.WorkersAiTTSAdapter; exports.createWorkersAiTts = _chunkKDVHOUEPcjs.createWorkersAiTts;
|
|
13
13
|
//# sourceMappingURL=workers-ai-tts.cjs.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
WorkersAiTTSAdapter,
|
|
3
3
|
createWorkersAiTts
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-QMRONSLN.js";
|
|
5
5
|
import "../chunk-XU7YEPML.js";
|
|
6
6
|
import "../chunk-2VII5BK2.js";
|
|
7
|
-
import "../chunk-
|
|
7
|
+
import "../chunk-S5QBHI6O.js";
|
|
8
8
|
import "../chunk-V6TY7KAL.js";
|
|
9
9
|
export {
|
|
10
10
|
WorkersAiTTSAdapter,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
require('../chunk-
|
|
4
|
+
var _chunk32U73O6Ecjs = require('../chunk-32U73O6E.cjs');
|
|
5
|
+
require('../chunk-U5NL4EM4.cjs');
|
|
6
6
|
require('../chunk-4DE2IREA.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
exports.WorkersAiTextAdapter =
|
|
10
|
+
exports.WorkersAiTextAdapter = _chunk32U73O6Ecjs.WorkersAiTextAdapter; exports.createWorkersAiChat = _chunk32U73O6Ecjs.createWorkersAiChat;
|
|
11
11
|
//# sourceMappingURL=workers-ai.cjs.map
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkU5NL4EM4cjs = require('./chunk-U5NL4EM4.cjs');
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
var _chunk4DE2IREAcjs = require('./chunk-4DE2IREA.cjs');
|
|
@@ -15,51 +15,70 @@ var _chunk4DE2IREAcjs = require('./chunk-4DE2IREA.cjs');
|
|
|
15
15
|
var _adapters = require('@tanstack/ai/adapters');
|
|
16
16
|
var _openai = require('openai'); var _openai2 = _interopRequireDefault(_openai);
|
|
17
17
|
function buildWorkersAiClient(config) {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
_chunkU5NL4EM4cjs.validateWorkersAiConfig.call(void 0, config);
|
|
19
|
+
const sessionHeaders = config.sessionAffinity ? { "x-session-affinity": config.sessionAffinity } : void 0;
|
|
20
|
+
if (_chunkU5NL4EM4cjs.isDirectBindingConfig.call(void 0, config)) {
|
|
20
21
|
return new (0, _openai2.default)({
|
|
21
22
|
apiKey: "unused",
|
|
22
|
-
fetch:
|
|
23
|
+
fetch: _chunkU5NL4EM4cjs.createWorkersAiBindingFetch.call(void 0,
|
|
24
|
+
config.binding,
|
|
25
|
+
sessionHeaders ? { extraHeaders: sessionHeaders } : void 0
|
|
26
|
+
)
|
|
23
27
|
});
|
|
24
28
|
}
|
|
25
|
-
if (
|
|
29
|
+
if (_chunkU5NL4EM4cjs.isDirectCredentialsConfig.call(void 0, config)) {
|
|
26
30
|
return new (0, _openai2.default)({
|
|
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 (0, _openai2.default)({
|
|
33
|
-
fetch:
|
|
38
|
+
fetch: _chunkU5NL4EM4cjs.createGatewayFetch.call(void 0, "workers-ai", gatewayConfig, sessionHeaders),
|
|
34
39
|
apiKey: _nullishCoalesce(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 _adapters.BaseTextAdapter {
|
|
134
153
|
constructor(model, config) {
|
|
@@ -142,14 +161,14 @@ var WorkersAiTextAdapter = class extends _adapters.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 _adapters.BaseTextAdapter {
|
|
|
261
280
|
};
|
|
262
281
|
}
|
|
263
282
|
const delta = choice.delta;
|
|
264
|
-
const reasoningContent = delta.reasoning_content;
|
|
283
|
+
const reasoningContent = _nullishCoalesce(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 _adapters.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: _optionalChain([toolCallDelta, 'access', _10 => _10.function, 'optionalAccess', _11 => _11.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 (_optionalChain([toolCallDelta, 'access', _12 => _12.function, 'optionalAccess', _13 => _13.name])) {
|
|
323
339
|
toolCall.name = toolCallDelta.function.name;
|
|
324
340
|
}
|
|
@@ -502,4 +518,4 @@ function createWorkersAiChat(model, config) {
|
|
|
502
518
|
|
|
503
519
|
|
|
504
520
|
exports.WorkersAiTextAdapter = WorkersAiTextAdapter; exports.createWorkersAiChat = createWorkersAiChat;
|
|
505
|
-
//# sourceMappingURL=chunk-
|
|
521
|
+
//# sourceMappingURL=chunk-32U73O6E.cjs.map
|