@cloudflare/tanstack-ai 0.1.9 → 0.1.10
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 +5 -5
- package/dist/adapters/anthropic.cjs +2 -3
- package/dist/adapters/anthropic.cjs.map +1 -1
- package/dist/adapters/anthropic.d.cts +4 -3
- package/dist/adapters/anthropic.d.mts +4 -3
- package/dist/adapters/anthropic.mjs +3 -3
- package/dist/adapters/anthropic.mjs.map +1 -1
- package/dist/adapters/gemini.cjs +2 -3
- package/dist/adapters/gemini.cjs.map +1 -1
- package/dist/adapters/gemini.d.cts +6 -6
- package/dist/adapters/gemini.d.mts +6 -6
- package/dist/adapters/gemini.mjs +4 -3
- package/dist/adapters/gemini.mjs.map +1 -1
- package/dist/adapters/grok.cjs +2 -6
- package/dist/adapters/grok.cjs.map +1 -1
- package/dist/adapters/grok.d.cts +5 -4
- package/dist/adapters/grok.d.mts +5 -4
- package/dist/adapters/grok.mjs +3 -6
- package/dist/adapters/grok.mjs.map +1 -1
- package/dist/adapters/openai.cjs +2 -3
- package/dist/adapters/openai.cjs.map +1 -1
- package/dist/adapters/openai.d.cts +6 -5
- package/dist/adapters/openai.d.mts +6 -5
- package/dist/adapters/openai.mjs +3 -3
- package/dist/adapters/openai.mjs.map +1 -1
- package/dist/adapters/openrouter.cjs +3 -17
- package/dist/adapters/openrouter.cjs.map +1 -1
- package/dist/adapters/openrouter.d.cts +4 -4
- package/dist/adapters/openrouter.d.mts +4 -4
- package/dist/adapters/openrouter.mjs +4 -17
- package/dist/adapters/openrouter.mjs.map +1 -1
- package/dist/adapters/workers-ai-image.cjs +5 -6
- package/dist/adapters/workers-ai-image.cjs.map +1 -1
- package/dist/adapters/workers-ai-image.d.cts +1 -1
- package/dist/adapters/workers-ai-image.d.mts +2 -2
- package/dist/adapters/workers-ai-image.mjs +5 -5
- package/dist/adapters/workers-ai-image.mjs.map +1 -1
- package/dist/adapters/workers-ai-summarize.cjs +3 -4
- package/dist/adapters/workers-ai-summarize.cjs.map +1 -1
- package/dist/adapters/workers-ai-summarize.d.cts +1 -1
- package/dist/adapters/workers-ai-summarize.d.mts +2 -2
- package/dist/adapters/workers-ai-summarize.mjs +3 -3
- package/dist/adapters/workers-ai-summarize.mjs.map +1 -1
- package/dist/adapters/workers-ai-transcription.cjs +5 -6
- package/dist/adapters/workers-ai-transcription.cjs.map +1 -1
- package/dist/adapters/workers-ai-transcription.d.cts +1 -1
- package/dist/adapters/workers-ai-transcription.d.mts +2 -2
- package/dist/adapters/workers-ai-transcription.mjs +5 -5
- package/dist/adapters/workers-ai-transcription.mjs.map +1 -1
- package/dist/adapters/workers-ai-tts.cjs +5 -6
- package/dist/adapters/workers-ai-tts.cjs.map +1 -1
- package/dist/adapters/workers-ai-tts.d.cts +1 -1
- package/dist/adapters/workers-ai-tts.d.mts +2 -2
- package/dist/adapters/workers-ai-tts.mjs +5 -5
- package/dist/adapters/workers-ai-tts.mjs.map +1 -1
- package/dist/adapters/workers-ai.cjs +520 -3
- package/dist/adapters/workers-ai.cjs.map +1 -0
- package/dist/adapters/workers-ai.d.cts +2 -2
- package/dist/adapters/workers-ai.d.mts +3 -3
- package/dist/adapters/workers-ai.mjs +56 -41
- package/dist/adapters/workers-ai.mjs.map +1 -1
- package/dist/{binary-p4H_N_3M.mjs → binary-B5YCVsro.mjs} +1 -1
- package/dist/{binary-C9FAYwZj.cjs.map → binary-B5YCVsro.mjs.map} +1 -1
- package/dist/{binary-C9FAYwZj.cjs → binary-CZhr1_2n.cjs} +1 -1
- package/dist/{binary-p4H_N_3M.mjs.map → binary-CZhr1_2n.cjs.map} +1 -1
- package/dist/{create-fetcher-CeUOJgrh.mjs → create-fetcher-BnSnCaHf.mjs} +1 -1
- package/dist/{create-fetcher-By-hTiT9.cjs.map → create-fetcher-BnSnCaHf.mjs.map} +1 -1
- package/dist/{create-fetcher-6p6heb85.d.mts → create-fetcher-Bp5yCNaO.d.cts} +1 -1
- package/dist/{create-fetcher-vAQ8WW-p.d.cts → create-fetcher-Bp5yCNaO.d.mts} +1 -1
- package/dist/{create-fetcher-By-hTiT9.cjs → create-fetcher-YVxWCTVL.cjs} +1 -1
- package/dist/{create-fetcher-CeUOJgrh.mjs.map → create-fetcher-YVxWCTVL.cjs.map} +1 -1
- package/dist/{defineProperty-CbyrzcbA.mjs → defineProperty-BC3bEcwq.mjs} +4 -4
- package/dist/{defineProperty-DQoAg20E.cjs → defineProperty-In8g9yAD.cjs} +4 -4
- package/dist/index.cjs +2 -3
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/dist/{workers-ai-rest-GKy2r7eG.mjs → workers-ai-rest-B6_yU35Q.mjs} +1 -1
- package/dist/{workers-ai-rest-CkNCtBwv.cjs.map → workers-ai-rest-B6_yU35Q.mjs.map} +1 -1
- package/dist/{workers-ai-rest-CkNCtBwv.cjs → workers-ai-rest-_MXOmyDs.cjs} +1 -1
- package/dist/{workers-ai-rest-GKy2r7eG.mjs.map → workers-ai-rest-_MXOmyDs.cjs.map} +1 -1
- package/package.json +9 -9
- package/dist/workers-ai-BOZ5iyhY.cjs +0 -521
- package/dist/workers-ai-BOZ5iyhY.cjs.map +0 -1
package/dist/adapters/openai.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as createGatewayFetch } from "../create-fetcher-
|
|
2
|
-
import { OPENAI_CHAT_MODELS, OPENAI_IMAGE_MODELS, OPENAI_TRANSCRIPTION_MODELS, OPENAI_TTS_MODELS, OPENAI_VIDEO_MODELS, OpenAIImageAdapter,
|
|
1
|
+
import { t as createGatewayFetch } from "../create-fetcher-BnSnCaHf.mjs";
|
|
2
|
+
import { OPENAI_CHAT_MODELS, OPENAI_IMAGE_MODELS, OPENAI_TRANSCRIPTION_MODELS, OPENAI_TTS_MODELS, OPENAI_VIDEO_MODELS, OpenAIImageAdapter, OpenAITTSAdapter, OpenAITextAdapter, OpenAITranscriptionAdapter, OpenAIVideoAdapter, createOpenaiSummarize } from "@tanstack/ai-openai";
|
|
3
3
|
//#region src/adapters/openai.ts
|
|
4
4
|
/**
|
|
5
5
|
* Builds an OpenAI-compatible config that injects the gateway fetch.
|
|
@@ -26,7 +26,7 @@ function createOpenAiChat(model, config) {
|
|
|
26
26
|
* @param config Configuration options
|
|
27
27
|
*/
|
|
28
28
|
function createOpenAiSummarize(model, config) {
|
|
29
|
-
return
|
|
29
|
+
return createOpenaiSummarize(model, config.apiKey ?? "unused", { fetch: createGatewayFetch("openai", config) });
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Creates an OpenAI image adapter which uses Cloudflare AI Gateway.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.mjs","names":[],"sources":["../../src/adapters/openai.ts"],"sourcesContent":["import {\n\
|
|
1
|
+
{"version":3,"file":"openai.mjs","names":[],"sources":["../../src/adapters/openai.ts"],"sourcesContent":["import {\n\tcreateOpenaiSummarize,\n\tOpenAIImageAdapter,\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\";\nimport type { AnySummarizeAdapter } from \"@tanstack/ai\";\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(\n\tmodel: OpenAIChatModel,\n\tconfig: OpenAiGatewayConfig,\n): OpenAITextAdapter<OpenAIChatModel> {\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(\n\tmodel: OpenAIChatModel,\n\tconfig: OpenAiGatewayConfig,\n): AnySummarizeAdapter {\n\treturn createOpenaiSummarize(model, config.apiKey ?? \"unused\", {\n\t\tfetch: createGatewayFetch(\"openai\", config),\n\t});\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"],"mappings":";;;;;;;AA2BA,SAAS,kBAAkB,UAAkB,QAA6B;CACzE,OAAO;EACN,QAAQ,OAAO,UAAU;EACzB,OAAO,mBAAmB,UAAU,MAAM;CAC3C;AACD;;;;;;;AAQA,SAAgB,iBACf,OACA,QACqC;CACrC,OAAO,IAAI,kBAAkB,kBAAkB,UAAU,MAAM,GAAG,KAAK;AACxE;;;;;;AAOA,SAAgB,sBACf,OACA,QACsB;CACtB,OAAO,sBAAsB,OAAO,OAAO,UAAU,UAAU,EAC9D,OAAO,mBAAmB,UAAU,MAAM,EAC3C,CAAC;AACF;;;;;;AAOA,SAAgB,kBAAkB,OAAyB,QAA6B;CACvF,OAAO,IAAI,mBAAmB,kBAAkB,UAAU,MAAM,GAAG,KAAK;AACzE;;;;;;AAOA,SAAgB,0BACf,OACA,QACC;CACD,OAAO,IAAI,2BAA2B,kBAAkB,UAAU,MAAM,GAAG,KAAK;AACjF;;;;;;AAOA,SAAgB,gBAAgB,OAAuB,QAA6B;CACnF,OAAO,IAAI,iBAAiB,kBAAkB,UAAU,MAAM,GAAG,KAAK;AACvE;;;;;;AAOA,SAAgB,kBAAkB,OAAyB,QAA6B;CACvF,OAAO,IAAI,mBAAmB,kBAAkB,UAAU,MAAM,GAAG,KAAK;AACzE"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("../
|
|
3
|
-
const require_create_fetcher = require("../create-fetcher-By-hTiT9.cjs");
|
|
2
|
+
const require_create_fetcher = require("../create-fetcher-YVxWCTVL.cjs");
|
|
4
3
|
let _tanstack_ai_openrouter = require("@tanstack/ai-openrouter");
|
|
5
4
|
let _openrouter_sdk = require("@openrouter/sdk");
|
|
6
5
|
//#region src/adapters/openrouter.ts
|
|
@@ -34,20 +33,6 @@ function buildOpenRouterImageConfig(config) {
|
|
|
34
33
|
};
|
|
35
34
|
}
|
|
36
35
|
/**
|
|
37
|
-
* Build OpenRouter summarize config.
|
|
38
|
-
*
|
|
39
|
-
* `OpenRouterSummarizeConfig` extends `OpenRouterConfig` with optional
|
|
40
|
-
* `temperature` and `maxTokens` fields. Since those are optional, a plain
|
|
41
|
-
* `OpenRouterConfig` is structurally compatible — no cast needed.
|
|
42
|
-
*/
|
|
43
|
-
function buildOpenRouterSummarizeConfig(config) {
|
|
44
|
-
const httpClient = new _openrouter_sdk.HTTPClient({ fetcher: require_create_fetcher.createGatewayFetch("openrouter", config) });
|
|
45
|
-
return {
|
|
46
|
-
apiKey: config.apiKey ?? "unused",
|
|
47
|
-
httpClient
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
36
|
* Creates an OpenRouter chat adapter which uses Cloudflare AI Gateway.
|
|
52
37
|
* Supports both binding and credential-based configurations.
|
|
53
38
|
*
|
|
@@ -75,7 +60,8 @@ function createOpenRouterImage(model, config) {
|
|
|
75
60
|
* @param config Configuration options
|
|
76
61
|
*/
|
|
77
62
|
function createOpenRouterSummarize(model, config) {
|
|
78
|
-
|
|
63
|
+
const httpClient = new _openrouter_sdk.HTTPClient({ fetcher: require_create_fetcher.createGatewayFetch("openrouter", config) });
|
|
64
|
+
return (0, _tanstack_ai_openrouter.createOpenRouterSummarize)(model, config.apiKey ?? "unused", { httpClient });
|
|
79
65
|
}
|
|
80
66
|
//#endregion
|
|
81
67
|
exports.createOpenRouterChat = createOpenRouterChat;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openrouter.cjs","names":["HTTPClient","createGatewayFetch","OpenRouterTextAdapter","OpenRouterImageAdapter"
|
|
1
|
+
{"version":3,"file":"openrouter.cjs","names":["HTTPClient","createGatewayFetch","OpenRouterTextAdapter","OpenRouterImageAdapter"],"sources":["../../src/adapters/openrouter.ts"],"sourcesContent":["import {\n\tOpenRouterTextAdapter,\n\tOpenRouterImageAdapter,\n\tcreateOpenRouterSummarize as createOpenRouterSummarizeAdapter,\n\ttype OpenRouterConfig,\n\ttype OpenRouterImageConfig,\n} from \"@tanstack/ai-openrouter\";\nimport { HTTPClient } from \"@openrouter/sdk\";\nimport { createGatewayFetch, type AiGatewayAdapterConfig } from \"../utils/create-fetcher\";\nimport type { AnySummarizeAdapter, 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// 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): AnySummarizeAdapter {\n\tconst httpClient = new HTTPClient({\n\t\tfetcher: createGatewayFetch(\"openrouter\", config),\n\t});\n\t// Cast needed: we accept any string model while upstream expects a literal\n\t// union, and the installed @openrouter/sdk HTTPClient may differ structurally\n\t// from the version @tanstack/ai-openrouter was built against.\n\treturn createOpenRouterSummarizeAdapter(model as any, config.apiKey ?? \"unused\", {\n\t\thttpClient: httpClient as any,\n\t});\n}\n"],"mappings":";;;;;;;;;;;AAmBA,SAAS,sBAAsB,QAAmD;CACjF,MAAM,aAAa,IAAIA,gBAAAA,WAAW,EACjC,SAASC,uBAAAA,mBAAmB,cAAc,MAAM,EACjD,CAAC;CACD,OAAO;EACN,QAAQ,OAAO,UAAU;EAIb;CACb;AACD;;;;;;;;;;AAWA,SAAS,2BAA2B,QAAwD;CAC3F,MAAM,aAAa,IAAID,gBAAAA,WAAW,EACjC,SAASC,uBAAAA,mBAAmB,cAAc,MAAM,EACjD,CAAC;CACD,OAAO;EACN,QAAQ,OAAO,UAAU;EACzB;CACD;AACD;;;;;;;;AA0BA,SAAgB,qBACf,OACA,QACiB;CAEjB,OAAO,IAAIC,wBAAAA,sBAAsB,sBAAsB,MAAM,GAAG,KAAY;AAC7E;;;;;;;;AASA,SAAgB,sBACf,OACA,QACC;CAED,OAAO,IAAIC,wBAAAA,uBAAuB,2BAA2B,MAAM,GAAG,KAAY;AACnF;;;;;;;;AASA,SAAgB,0BACf,OACA,QACsB;CACtB,MAAM,aAAa,IAAIH,gBAAAA,WAAW,EACjC,SAASC,uBAAAA,mBAAmB,cAAc,MAAM,EACjD,CAAC;CAID,QAAA,GAAA,wBAAA,0BAAA,CAAwC,OAAc,OAAO,UAAU,UAAU,EACpE,WACb,CAAC;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as AiGatewayAdapterConfig } from "../create-fetcher-
|
|
2
|
-
import { AnyTextAdapter } from "@tanstack/ai";
|
|
3
|
-
import { OpenRouterImageAdapter
|
|
1
|
+
import { t as AiGatewayAdapterConfig } from "../create-fetcher-Bp5yCNaO.cjs";
|
|
2
|
+
import { AnySummarizeAdapter, AnyTextAdapter } from "@tanstack/ai";
|
|
3
|
+
import { OpenRouterImageAdapter } from "@tanstack/ai-openrouter";
|
|
4
4
|
|
|
5
5
|
//#region src/adapters/openrouter.d.ts
|
|
6
6
|
type OpenRouterGatewayConfig = AiGatewayAdapterConfig;
|
|
@@ -33,7 +33,7 @@ declare function createOpenRouterImage(model: OpenRouterImageModel, config: Open
|
|
|
33
33
|
* @param model The model to use for summarization
|
|
34
34
|
* @param config Configuration options
|
|
35
35
|
*/
|
|
36
|
-
declare function createOpenRouterSummarize(model: OpenRouterSummarizeModel, config: OpenRouterGatewayConfig):
|
|
36
|
+
declare function createOpenRouterSummarize(model: OpenRouterSummarizeModel, config: OpenRouterGatewayConfig): AnySummarizeAdapter;
|
|
37
37
|
//#endregion
|
|
38
38
|
export { OpenRouterChatModel, OpenRouterGatewayConfig, OpenRouterImageModel, OpenRouterSummarizeModel, createOpenRouterChat, createOpenRouterImage, createOpenRouterSummarize };
|
|
39
39
|
//# sourceMappingURL=openrouter.d.cts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as AiGatewayAdapterConfig } from "../create-fetcher-
|
|
2
|
-
import { OpenRouterImageAdapter
|
|
3
|
-
import { AnyTextAdapter } from "@tanstack/ai";
|
|
1
|
+
import { t as AiGatewayAdapterConfig } from "../create-fetcher-Bp5yCNaO.mjs";
|
|
2
|
+
import { OpenRouterImageAdapter } from "@tanstack/ai-openrouter";
|
|
3
|
+
import { AnySummarizeAdapter, AnyTextAdapter } from "@tanstack/ai";
|
|
4
4
|
|
|
5
5
|
//#region src/adapters/openrouter.d.ts
|
|
6
6
|
type OpenRouterGatewayConfig = AiGatewayAdapterConfig;
|
|
@@ -33,7 +33,7 @@ declare function createOpenRouterImage(model: OpenRouterImageModel, config: Open
|
|
|
33
33
|
* @param model The model to use for summarization
|
|
34
34
|
* @param config Configuration options
|
|
35
35
|
*/
|
|
36
|
-
declare function createOpenRouterSummarize(model: OpenRouterSummarizeModel, config: OpenRouterGatewayConfig):
|
|
36
|
+
declare function createOpenRouterSummarize(model: OpenRouterSummarizeModel, config: OpenRouterGatewayConfig): AnySummarizeAdapter;
|
|
37
37
|
//#endregion
|
|
38
38
|
export { OpenRouterChatModel, OpenRouterGatewayConfig, OpenRouterImageModel, OpenRouterSummarizeModel, createOpenRouterChat, createOpenRouterImage, createOpenRouterSummarize };
|
|
39
39
|
//# sourceMappingURL=openrouter.d.mts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as createGatewayFetch } from "../create-fetcher-
|
|
2
|
-
import { OpenRouterImageAdapter,
|
|
1
|
+
import { t as createGatewayFetch } from "../create-fetcher-BnSnCaHf.mjs";
|
|
2
|
+
import { OpenRouterImageAdapter, OpenRouterTextAdapter, createOpenRouterSummarize as createOpenRouterSummarize$1 } from "@tanstack/ai-openrouter";
|
|
3
3
|
import { HTTPClient } from "@openrouter/sdk";
|
|
4
4
|
//#region src/adapters/openrouter.ts
|
|
5
5
|
/**
|
|
@@ -32,20 +32,6 @@ function buildOpenRouterImageConfig(config) {
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
* Build OpenRouter summarize config.
|
|
36
|
-
*
|
|
37
|
-
* `OpenRouterSummarizeConfig` extends `OpenRouterConfig` with optional
|
|
38
|
-
* `temperature` and `maxTokens` fields. Since those are optional, a plain
|
|
39
|
-
* `OpenRouterConfig` is structurally compatible — no cast needed.
|
|
40
|
-
*/
|
|
41
|
-
function buildOpenRouterSummarizeConfig(config) {
|
|
42
|
-
const httpClient = new HTTPClient({ fetcher: createGatewayFetch("openrouter", config) });
|
|
43
|
-
return {
|
|
44
|
-
apiKey: config.apiKey ?? "unused",
|
|
45
|
-
httpClient
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
35
|
* Creates an OpenRouter chat adapter which uses Cloudflare AI Gateway.
|
|
50
36
|
* Supports both binding and credential-based configurations.
|
|
51
37
|
*
|
|
@@ -73,7 +59,8 @@ function createOpenRouterImage(model, config) {
|
|
|
73
59
|
* @param config Configuration options
|
|
74
60
|
*/
|
|
75
61
|
function createOpenRouterSummarize(model, config) {
|
|
76
|
-
|
|
62
|
+
const httpClient = new HTTPClient({ fetcher: createGatewayFetch("openrouter", config) });
|
|
63
|
+
return createOpenRouterSummarize$1(model, config.apiKey ?? "unused", { httpClient });
|
|
77
64
|
}
|
|
78
65
|
//#endregion
|
|
79
66
|
export { createOpenRouterChat, createOpenRouterImage, createOpenRouterSummarize };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openrouter.mjs","names":[],"sources":["../../src/adapters/openrouter.ts"],"sourcesContent":["import {\n\tOpenRouterTextAdapter,\n\tOpenRouterImageAdapter,\n\
|
|
1
|
+
{"version":3,"file":"openrouter.mjs","names":["createOpenRouterSummarizeAdapter"],"sources":["../../src/adapters/openrouter.ts"],"sourcesContent":["import {\n\tOpenRouterTextAdapter,\n\tOpenRouterImageAdapter,\n\tcreateOpenRouterSummarize as createOpenRouterSummarizeAdapter,\n\ttype OpenRouterConfig,\n\ttype OpenRouterImageConfig,\n} from \"@tanstack/ai-openrouter\";\nimport { HTTPClient } from \"@openrouter/sdk\";\nimport { createGatewayFetch, type AiGatewayAdapterConfig } from \"../utils/create-fetcher\";\nimport type { AnySummarizeAdapter, 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// 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): AnySummarizeAdapter {\n\tconst httpClient = new HTTPClient({\n\t\tfetcher: createGatewayFetch(\"openrouter\", config),\n\t});\n\t// Cast needed: we accept any string model while upstream expects a literal\n\t// union, and the installed @openrouter/sdk HTTPClient may differ structurally\n\t// from the version @tanstack/ai-openrouter was built against.\n\treturn createOpenRouterSummarizeAdapter(model as any, config.apiKey ?? \"unused\", {\n\t\thttpClient: httpClient as any,\n\t});\n}\n"],"mappings":";;;;;;;;;;AAmBA,SAAS,sBAAsB,QAAmD;CACjF,MAAM,aAAa,IAAI,WAAW,EACjC,SAAS,mBAAmB,cAAc,MAAM,EACjD,CAAC;CACD,OAAO;EACN,QAAQ,OAAO,UAAU;EAIb;CACb;AACD;;;;;;;;;;AAWA,SAAS,2BAA2B,QAAwD;CAC3F,MAAM,aAAa,IAAI,WAAW,EACjC,SAAS,mBAAmB,cAAc,MAAM,EACjD,CAAC;CACD,OAAO;EACN,QAAQ,OAAO,UAAU;EACzB;CACD;AACD;;;;;;;;AA0BA,SAAgB,qBACf,OACA,QACiB;CAEjB,OAAO,IAAI,sBAAsB,sBAAsB,MAAM,GAAG,KAAY;AAC7E;;;;;;;;AASA,SAAgB,sBACf,OACA,QACC;CAED,OAAO,IAAI,uBAAuB,2BAA2B,MAAM,GAAG,KAAY;AACnF;;;;;;;;AASA,SAAgB,0BACf,OACA,QACsB;CACtB,MAAM,aAAa,IAAI,WAAW,EACjC,SAAS,mBAAmB,cAAc,MAAM,EACjD,CAAC;CAID,OAAOA,4BAAiC,OAAc,OAAO,UAAU,UAAU,EACpE,WACb,CAAC;AACF"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("../
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const require_binary = require("../binary-C9FAYwZj.cjs");
|
|
2
|
+
const require_create_fetcher = require("../create-fetcher-YVxWCTVL.cjs");
|
|
3
|
+
const require_defineProperty = require("../defineProperty-In8g9yAD.cjs");
|
|
4
|
+
const require_workers_ai_rest = require("../workers-ai-rest-_MXOmyDs.cjs");
|
|
5
|
+
const require_binary = require("../binary-CZhr1_2n.cjs");
|
|
7
6
|
let _tanstack_ai_adapters = require("@tanstack/ai/adapters");
|
|
8
7
|
//#region src/adapters/workers-ai-image.ts
|
|
9
8
|
var WorkersAiImageAdapter = class extends _tanstack_ai_adapters.BaseImageAdapter {
|
|
10
9
|
constructor(config, model) {
|
|
11
|
-
super(
|
|
10
|
+
super(model);
|
|
12
11
|
require_defineProperty._defineProperty(this, "name", "workers-ai-image");
|
|
13
12
|
require_defineProperty._defineProperty(this, "adapterConfig", void 0);
|
|
14
13
|
require_create_fetcher.validateWorkersAiConfig(config);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workers-ai-image.cjs","names":["BaseImageAdapter","isDirectBindingConfig","isDirectCredentialsConfig","binaryToBase64","workersAiRestFetch","uint8ArrayToBase64","createGatewayFetch"],"sources":["../../src/adapters/workers-ai-image.ts"],"sourcesContent":["import { BaseImageAdapter } from \"@tanstack/ai/adapters\";\nimport type { ImageGenerationOptions, ImageGenerationResult } from \"@tanstack/ai\";\nimport type { AiModels, BaseAiTextToImage } from \"@cloudflare/workers-types\";\nimport {\n\ttype WorkersAiAdapterConfig,\n\ttype WorkersAiDirectBindingConfig,\n\ttype AiGatewayAdapterConfig,\n\tcreateGatewayFetch,\n\tisDirectBindingConfig,\n\tisDirectCredentialsConfig,\n\tvalidateWorkersAiConfig,\n} from \"../utils/create-fetcher\";\nimport { workersAiRestFetch } from \"../utils/workers-ai-rest\";\nimport { binaryToBase64, uint8ArrayToBase64 } from \"../utils/binary\";\nimport type { WorkersAiDirectCredentialsConfig } from \"../utils/create-fetcher\";\n\n// ---------------------------------------------------------------------------\n// Model type derived from @cloudflare/workers-types\n// ---------------------------------------------------------------------------\n\nexport type WorkersAiImageModel =\n\t| { [K in keyof AiModels]: AiModels[K] extends BaseAiTextToImage ? K : never }[keyof AiModels]\n\t| (string & {});\n\n// ---------------------------------------------------------------------------\n// WorkersAiImageAdapter: image generation via Workers AI\n// Extends BaseImageAdapter so it works with TanStack AI's generateImage()\n// ---------------------------------------------------------------------------\n\nexport class WorkersAiImageAdapter extends BaseImageAdapter<WorkersAiImageModel> {\n\treadonly name = \"workers-ai-image\" as const;\n\tprivate adapterConfig: WorkersAiAdapterConfig;\n\n\tconstructor(config: WorkersAiAdapterConfig, model: WorkersAiImageModel) {\n\t\tsuper(
|
|
1
|
+
{"version":3,"file":"workers-ai-image.cjs","names":["BaseImageAdapter","isDirectBindingConfig","isDirectCredentialsConfig","binaryToBase64","workersAiRestFetch","uint8ArrayToBase64","createGatewayFetch"],"sources":["../../src/adapters/workers-ai-image.ts"],"sourcesContent":["import { BaseImageAdapter } from \"@tanstack/ai/adapters\";\nimport type { ImageGenerationOptions, ImageGenerationResult } from \"@tanstack/ai\";\nimport type { AiModels, BaseAiTextToImage } from \"@cloudflare/workers-types\";\nimport {\n\ttype WorkersAiAdapterConfig,\n\ttype WorkersAiDirectBindingConfig,\n\ttype AiGatewayAdapterConfig,\n\tcreateGatewayFetch,\n\tisDirectBindingConfig,\n\tisDirectCredentialsConfig,\n\tvalidateWorkersAiConfig,\n} from \"../utils/create-fetcher\";\nimport { workersAiRestFetch } from \"../utils/workers-ai-rest\";\nimport { binaryToBase64, uint8ArrayToBase64 } from \"../utils/binary\";\nimport type { WorkersAiDirectCredentialsConfig } from \"../utils/create-fetcher\";\n\n// ---------------------------------------------------------------------------\n// Model type derived from @cloudflare/workers-types\n// ---------------------------------------------------------------------------\n\nexport type WorkersAiImageModel =\n\t| { [K in keyof AiModels]: AiModels[K] extends BaseAiTextToImage ? K : never }[keyof AiModels]\n\t| (string & {});\n\n// ---------------------------------------------------------------------------\n// WorkersAiImageAdapter: image generation via Workers AI\n// Extends BaseImageAdapter so it works with TanStack AI's generateImage()\n// ---------------------------------------------------------------------------\n\nexport class WorkersAiImageAdapter extends BaseImageAdapter<WorkersAiImageModel> {\n\treadonly name = \"workers-ai-image\" as const;\n\tprivate adapterConfig: WorkersAiAdapterConfig;\n\n\tconstructor(config: WorkersAiAdapterConfig, model: WorkersAiImageModel) {\n\t\tsuper(model);\n\t\tvalidateWorkersAiConfig(config);\n\t\tthis.adapterConfig = config;\n\t}\n\n\tasync generateImages(options: ImageGenerationOptions): Promise<ImageGenerationResult> {\n\t\tconst { prompt, size, modelOptions } = options;\n\t\tconst extra: Record<string, unknown> = { ...modelOptions };\n\n\t\t// Note: Workers AI Stable Diffusion models only generate a single image\n\t\t// per request — there is no multi-image parameter. `numberOfImages` from\n\t\t// the TanStack AI options is intentionally not forwarded. Use\n\t\t// `modelOptions.num_steps` to control the number of diffusion steps.\n\n\t\tif (size) {\n\t\t\tconst [w, h] = size.split(\"x\");\n\t\t\tif (w) extra.width = Number(w);\n\t\t\tif (h) extra.height = Number(h);\n\t\t}\n\n\t\tif (isDirectBindingConfig(this.adapterConfig)) {\n\t\t\treturn this.generateViaBinding(prompt, extra);\n\t\t}\n\n\t\tif (isDirectCredentialsConfig(this.adapterConfig)) {\n\t\t\treturn this.generateViaRest(prompt, extra);\n\t\t}\n\n\t\t// Gateway mode\n\t\treturn this.generateViaGateway(prompt, extra);\n\t}\n\n\tprivate async generateViaBinding(\n\t\tprompt: string,\n\t\toptions: Record<string, unknown>,\n\t): Promise<ImageGenerationResult> {\n\t\tconst ai = (this.adapterConfig as WorkersAiDirectBindingConfig).binding;\n\t\tconst result = await ai.run(this.model, { prompt, ...options });\n\n\t\tconst b64 = await binaryToBase64(result, \"image\");\n\t\treturn this.wrapResult(b64);\n\t}\n\n\tprivate async generateViaRest(\n\t\tprompt: string,\n\t\toptions: Record<string, unknown>,\n\t): Promise<ImageGenerationResult> {\n\t\tconst config = this.adapterConfig as WorkersAiDirectCredentialsConfig;\n\t\tconst response = await workersAiRestFetch(\n\t\t\tconfig,\n\t\t\tthis.model,\n\t\t\t{ prompt, ...options },\n\t\t\t{ label: \"Workers AI image\", signal: (options as { signal?: AbortSignal }).signal },\n\t\t);\n\n\t\tconst buffer = await response.arrayBuffer();\n\t\treturn this.wrapResult(uint8ArrayToBase64(new Uint8Array(buffer)));\n\t}\n\n\tprivate async generateViaGateway(\n\t\tprompt: string,\n\t\toptions: Record<string, unknown>,\n\t): Promise<ImageGenerationResult> {\n\t\tconst gatewayConfig = this.adapterConfig as AiGatewayAdapterConfig;\n\t\tconst gatewayFetch = createGatewayFetch(\"workers-ai\", gatewayConfig);\n\n\t\t// The URL here is a placeholder — createGatewayFetch for \"workers-ai\" extracts\n\t\t// the model from the body, sets it as the endpoint, and routes through the gateway.\n\t\t// The actual URL path is not used.\n\t\tconst response = await gatewayFetch(\"https://api.cloudflare.com/v1/images/generations\", {\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify({\n\t\t\t\tmodel: this.model,\n\t\t\t\tprompt,\n\t\t\t\t...options,\n\t\t\t}),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tconst errorText = await response.text();\n\t\t\tthrow new Error(\n\t\t\t\t`Workers AI image gateway request failed (${response.status}): ${errorText}`,\n\t\t\t);\n\t\t}\n\n\t\tconst buffer = await response.arrayBuffer();\n\t\treturn this.wrapResult(uint8ArrayToBase64(new Uint8Array(buffer)));\n\t}\n\n\t/** Wrap a base64 image string into the standard ImageGenerationResult. */\n\tprivate wrapResult(b64: string): ImageGenerationResult {\n\t\treturn {\n\t\t\tid: this.generateId(),\n\t\t\tmodel: this.model,\n\t\t\timages: [{ b64Json: b64 }],\n\t\t};\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// Factory function\n// ---------------------------------------------------------------------------\n\n/**\n * Creates a Workers AI image generation adapter.\n *\n * Works with TanStack AI's `generateImage()` activity function:\n * ```ts\n * import { generateImage } from \"@tanstack/ai\";\n * import { createWorkersAiImage } from \"@cloudflare/tanstack-ai\";\n *\n * const adapter = createWorkersAiImage(\n * \"@cf/stabilityai/stable-diffusion-xl-base-1.0\",\n * { binding: env.AI },\n * );\n *\n * const result = await generateImage({ adapter, prompt: \"a cat in space\" });\n * ```\n *\n * Note: Factory takes `(model, config)` for ergonomics — the class constructor\n * uses `(config, model)` to match TanStack AI's upstream convention.\n */\nexport function createWorkersAiImage(model: WorkersAiImageModel, config: WorkersAiAdapterConfig) {\n\treturn new WorkersAiImageAdapter(config, model);\n}\n"],"mappings":";;;;;;;AA6BA,IAAa,wBAAb,cAA2CA,sBAAAA,iBAAsC;CAIhF,YAAY,QAAgC,OAA4B;EACvE,MAAM,KAAK;+CAJH,QAAO,kBAAA;+CACR,iBAAA,KAAA,CAAA;EAIP,uBAAA,wBAAwB,MAAM;EAC9B,KAAK,gBAAgB;CACtB;CAEA,MAAM,eAAe,SAAiE;EACrF,MAAM,EAAE,QAAQ,MAAM,iBAAiB;EACvC,MAAM,QAAiC,EAAE,GAAG,aAAa;EAOzD,IAAI,MAAM;GACT,MAAM,CAAC,GAAG,KAAK,KAAK,MAAM,GAAG;GAC7B,IAAI,GAAG,MAAM,QAAQ,OAAO,CAAC;GAC7B,IAAI,GAAG,MAAM,SAAS,OAAO,CAAC;EAC/B;EAEA,IAAIC,uBAAAA,sBAAsB,KAAK,aAAa,GAC3C,OAAO,KAAK,mBAAmB,QAAQ,KAAK;EAG7C,IAAIC,uBAAAA,0BAA0B,KAAK,aAAa,GAC/C,OAAO,KAAK,gBAAgB,QAAQ,KAAK;EAI1C,OAAO,KAAK,mBAAmB,QAAQ,KAAK;CAC7C;CAEA,MAAc,mBACb,QACA,SACiC;EAIjC,MAAM,MAAM,MAAMC,eAAAA,eAAe,MAHrB,KAAK,cAA+C,QACxC,IAAI,KAAK,OAAO;GAAE;GAAQ,GAAG;EAAQ,CAAC,GAErB,OAAO;EAChD,OAAO,KAAK,WAAW,GAAG;CAC3B;CAEA,MAAc,gBACb,QACA,SACiC;EACjC,MAAM,SAAS,KAAK;EAQpB,MAAM,SAAS,OAAM,MAPEC,wBAAAA,mBACtB,QACA,KAAK,OACL;GAAE;GAAQ,GAAG;EAAQ,GACrB;GAAE,OAAO;GAAoB,QAAS,QAAqC;EAAO,CACnF,EAAA,CAE8B,YAAY;EAC1C,OAAO,KAAK,WAAWC,eAAAA,mBAAmB,IAAI,WAAW,MAAM,CAAC,CAAC;CAClE;CAEA,MAAc,mBACb,QACA,SACiC;EACjC,MAAM,gBAAgB,KAAK;EAM3B,MAAM,WAAW,MALIC,uBAAAA,mBAAmB,cAAc,aAKpB,CAAC,CAAC,oDAAoD;GACvF,QAAQ;GACR,MAAM,KAAK,UAAU;IACpB,OAAO,KAAK;IACZ;IACA,GAAG;GACJ,CAAC;EACF,CAAC;EAED,IAAI,CAAC,SAAS,IAAI;GACjB,MAAM,YAAY,MAAM,SAAS,KAAK;GACtC,MAAM,IAAI,MACT,4CAA4C,SAAS,OAAO,KAAK,WAClE;EACD;EAEA,MAAM,SAAS,MAAM,SAAS,YAAY;EAC1C,OAAO,KAAK,WAAWD,eAAAA,mBAAmB,IAAI,WAAW,MAAM,CAAC,CAAC;CAClE;;CAGA,WAAmB,KAAoC;EACtD,OAAO;GACN,IAAI,KAAK,WAAW;GACpB,OAAO,KAAK;GACZ,QAAQ,CAAC,EAAE,SAAS,IAAI,CAAC;EAC1B;CACD;AACD;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,qBAAqB,OAA4B,QAAgC;CAChG,OAAO,IAAI,sBAAsB,QAAQ,KAAK;AAC/C"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as WorkersAiAdapterConfig } from "../create-fetcher-
|
|
1
|
+
import { i as WorkersAiAdapterConfig } from "../create-fetcher-Bp5yCNaO.cjs";
|
|
2
2
|
import { ImageGenerationOptions, ImageGenerationResult } from "@tanstack/ai";
|
|
3
3
|
import { BaseImageAdapter } from "@tanstack/ai/adapters";
|
|
4
4
|
import { AiModels, BaseAiTextToImage } from "@cloudflare/workers-types";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as WorkersAiAdapterConfig } from "../create-fetcher-
|
|
2
|
-
import { BaseImageAdapter } from "@tanstack/ai/adapters";
|
|
1
|
+
import { i as WorkersAiAdapterConfig } from "../create-fetcher-Bp5yCNaO.mjs";
|
|
3
2
|
import { ImageGenerationOptions, ImageGenerationResult } from "@tanstack/ai";
|
|
3
|
+
import { BaseImageAdapter } from "@tanstack/ai/adapters";
|
|
4
4
|
import { AiModels, BaseAiTextToImage } from "@cloudflare/workers-types";
|
|
5
5
|
|
|
6
6
|
//#region src/adapters/workers-ai-image.d.ts
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { a as validateWorkersAiConfig, i as isDirectCredentialsConfig, r as isDirectBindingConfig, t as createGatewayFetch } from "../create-fetcher-
|
|
2
|
-
import { t as _defineProperty } from "../defineProperty-
|
|
3
|
-
import { t as workersAiRestFetch } from "../workers-ai-rest-
|
|
4
|
-
import { n as uint8ArrayToBase64, t as binaryToBase64 } from "../binary-
|
|
1
|
+
import { a as validateWorkersAiConfig, i as isDirectCredentialsConfig, r as isDirectBindingConfig, t as createGatewayFetch } from "../create-fetcher-BnSnCaHf.mjs";
|
|
2
|
+
import { t as _defineProperty } from "../defineProperty-BC3bEcwq.mjs";
|
|
3
|
+
import { t as workersAiRestFetch } from "../workers-ai-rest-B6_yU35Q.mjs";
|
|
4
|
+
import { n as uint8ArrayToBase64, t as binaryToBase64 } from "../binary-B5YCVsro.mjs";
|
|
5
5
|
import { BaseImageAdapter } from "@tanstack/ai/adapters";
|
|
6
6
|
//#region src/adapters/workers-ai-image.ts
|
|
7
7
|
var WorkersAiImageAdapter = class extends BaseImageAdapter {
|
|
8
8
|
constructor(config, model) {
|
|
9
|
-
super(
|
|
9
|
+
super(model);
|
|
10
10
|
_defineProperty(this, "name", "workers-ai-image");
|
|
11
11
|
_defineProperty(this, "adapterConfig", void 0);
|
|
12
12
|
validateWorkersAiConfig(config);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workers-ai-image.mjs","names":[],"sources":["../../src/adapters/workers-ai-image.ts"],"sourcesContent":["import { BaseImageAdapter } from \"@tanstack/ai/adapters\";\nimport type { ImageGenerationOptions, ImageGenerationResult } from \"@tanstack/ai\";\nimport type { AiModels, BaseAiTextToImage } from \"@cloudflare/workers-types\";\nimport {\n\ttype WorkersAiAdapterConfig,\n\ttype WorkersAiDirectBindingConfig,\n\ttype AiGatewayAdapterConfig,\n\tcreateGatewayFetch,\n\tisDirectBindingConfig,\n\tisDirectCredentialsConfig,\n\tvalidateWorkersAiConfig,\n} from \"../utils/create-fetcher\";\nimport { workersAiRestFetch } from \"../utils/workers-ai-rest\";\nimport { binaryToBase64, uint8ArrayToBase64 } from \"../utils/binary\";\nimport type { WorkersAiDirectCredentialsConfig } from \"../utils/create-fetcher\";\n\n// ---------------------------------------------------------------------------\n// Model type derived from @cloudflare/workers-types\n// ---------------------------------------------------------------------------\n\nexport type WorkersAiImageModel =\n\t| { [K in keyof AiModels]: AiModels[K] extends BaseAiTextToImage ? K : never }[keyof AiModels]\n\t| (string & {});\n\n// ---------------------------------------------------------------------------\n// WorkersAiImageAdapter: image generation via Workers AI\n// Extends BaseImageAdapter so it works with TanStack AI's generateImage()\n// ---------------------------------------------------------------------------\n\nexport class WorkersAiImageAdapter extends BaseImageAdapter<WorkersAiImageModel> {\n\treadonly name = \"workers-ai-image\" as const;\n\tprivate adapterConfig: WorkersAiAdapterConfig;\n\n\tconstructor(config: WorkersAiAdapterConfig, model: WorkersAiImageModel) {\n\t\tsuper(
|
|
1
|
+
{"version":3,"file":"workers-ai-image.mjs","names":[],"sources":["../../src/adapters/workers-ai-image.ts"],"sourcesContent":["import { BaseImageAdapter } from \"@tanstack/ai/adapters\";\nimport type { ImageGenerationOptions, ImageGenerationResult } from \"@tanstack/ai\";\nimport type { AiModels, BaseAiTextToImage } from \"@cloudflare/workers-types\";\nimport {\n\ttype WorkersAiAdapterConfig,\n\ttype WorkersAiDirectBindingConfig,\n\ttype AiGatewayAdapterConfig,\n\tcreateGatewayFetch,\n\tisDirectBindingConfig,\n\tisDirectCredentialsConfig,\n\tvalidateWorkersAiConfig,\n} from \"../utils/create-fetcher\";\nimport { workersAiRestFetch } from \"../utils/workers-ai-rest\";\nimport { binaryToBase64, uint8ArrayToBase64 } from \"../utils/binary\";\nimport type { WorkersAiDirectCredentialsConfig } from \"../utils/create-fetcher\";\n\n// ---------------------------------------------------------------------------\n// Model type derived from @cloudflare/workers-types\n// ---------------------------------------------------------------------------\n\nexport type WorkersAiImageModel =\n\t| { [K in keyof AiModels]: AiModels[K] extends BaseAiTextToImage ? K : never }[keyof AiModels]\n\t| (string & {});\n\n// ---------------------------------------------------------------------------\n// WorkersAiImageAdapter: image generation via Workers AI\n// Extends BaseImageAdapter so it works with TanStack AI's generateImage()\n// ---------------------------------------------------------------------------\n\nexport class WorkersAiImageAdapter extends BaseImageAdapter<WorkersAiImageModel> {\n\treadonly name = \"workers-ai-image\" as const;\n\tprivate adapterConfig: WorkersAiAdapterConfig;\n\n\tconstructor(config: WorkersAiAdapterConfig, model: WorkersAiImageModel) {\n\t\tsuper(model);\n\t\tvalidateWorkersAiConfig(config);\n\t\tthis.adapterConfig = config;\n\t}\n\n\tasync generateImages(options: ImageGenerationOptions): Promise<ImageGenerationResult> {\n\t\tconst { prompt, size, modelOptions } = options;\n\t\tconst extra: Record<string, unknown> = { ...modelOptions };\n\n\t\t// Note: Workers AI Stable Diffusion models only generate a single image\n\t\t// per request — there is no multi-image parameter. `numberOfImages` from\n\t\t// the TanStack AI options is intentionally not forwarded. Use\n\t\t// `modelOptions.num_steps` to control the number of diffusion steps.\n\n\t\tif (size) {\n\t\t\tconst [w, h] = size.split(\"x\");\n\t\t\tif (w) extra.width = Number(w);\n\t\t\tif (h) extra.height = Number(h);\n\t\t}\n\n\t\tif (isDirectBindingConfig(this.adapterConfig)) {\n\t\t\treturn this.generateViaBinding(prompt, extra);\n\t\t}\n\n\t\tif (isDirectCredentialsConfig(this.adapterConfig)) {\n\t\t\treturn this.generateViaRest(prompt, extra);\n\t\t}\n\n\t\t// Gateway mode\n\t\treturn this.generateViaGateway(prompt, extra);\n\t}\n\n\tprivate async generateViaBinding(\n\t\tprompt: string,\n\t\toptions: Record<string, unknown>,\n\t): Promise<ImageGenerationResult> {\n\t\tconst ai = (this.adapterConfig as WorkersAiDirectBindingConfig).binding;\n\t\tconst result = await ai.run(this.model, { prompt, ...options });\n\n\t\tconst b64 = await binaryToBase64(result, \"image\");\n\t\treturn this.wrapResult(b64);\n\t}\n\n\tprivate async generateViaRest(\n\t\tprompt: string,\n\t\toptions: Record<string, unknown>,\n\t): Promise<ImageGenerationResult> {\n\t\tconst config = this.adapterConfig as WorkersAiDirectCredentialsConfig;\n\t\tconst response = await workersAiRestFetch(\n\t\t\tconfig,\n\t\t\tthis.model,\n\t\t\t{ prompt, ...options },\n\t\t\t{ label: \"Workers AI image\", signal: (options as { signal?: AbortSignal }).signal },\n\t\t);\n\n\t\tconst buffer = await response.arrayBuffer();\n\t\treturn this.wrapResult(uint8ArrayToBase64(new Uint8Array(buffer)));\n\t}\n\n\tprivate async generateViaGateway(\n\t\tprompt: string,\n\t\toptions: Record<string, unknown>,\n\t): Promise<ImageGenerationResult> {\n\t\tconst gatewayConfig = this.adapterConfig as AiGatewayAdapterConfig;\n\t\tconst gatewayFetch = createGatewayFetch(\"workers-ai\", gatewayConfig);\n\n\t\t// The URL here is a placeholder — createGatewayFetch for \"workers-ai\" extracts\n\t\t// the model from the body, sets it as the endpoint, and routes through the gateway.\n\t\t// The actual URL path is not used.\n\t\tconst response = await gatewayFetch(\"https://api.cloudflare.com/v1/images/generations\", {\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify({\n\t\t\t\tmodel: this.model,\n\t\t\t\tprompt,\n\t\t\t\t...options,\n\t\t\t}),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tconst errorText = await response.text();\n\t\t\tthrow new Error(\n\t\t\t\t`Workers AI image gateway request failed (${response.status}): ${errorText}`,\n\t\t\t);\n\t\t}\n\n\t\tconst buffer = await response.arrayBuffer();\n\t\treturn this.wrapResult(uint8ArrayToBase64(new Uint8Array(buffer)));\n\t}\n\n\t/** Wrap a base64 image string into the standard ImageGenerationResult. */\n\tprivate wrapResult(b64: string): ImageGenerationResult {\n\t\treturn {\n\t\t\tid: this.generateId(),\n\t\t\tmodel: this.model,\n\t\t\timages: [{ b64Json: b64 }],\n\t\t};\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// Factory function\n// ---------------------------------------------------------------------------\n\n/**\n * Creates a Workers AI image generation adapter.\n *\n * Works with TanStack AI's `generateImage()` activity function:\n * ```ts\n * import { generateImage } from \"@tanstack/ai\";\n * import { createWorkersAiImage } from \"@cloudflare/tanstack-ai\";\n *\n * const adapter = createWorkersAiImage(\n * \"@cf/stabilityai/stable-diffusion-xl-base-1.0\",\n * { binding: env.AI },\n * );\n *\n * const result = await generateImage({ adapter, prompt: \"a cat in space\" });\n * ```\n *\n * Note: Factory takes `(model, config)` for ergonomics — the class constructor\n * uses `(config, model)` to match TanStack AI's upstream convention.\n */\nexport function createWorkersAiImage(model: WorkersAiImageModel, config: WorkersAiAdapterConfig) {\n\treturn new WorkersAiImageAdapter(config, model);\n}\n"],"mappings":";;;;;;AA6BA,IAAa,wBAAb,cAA2C,iBAAsC;CAIhF,YAAY,QAAgC,OAA4B;EACvE,MAAM,KAAK;wBAJH,QAAO,kBAAA;wBACR,iBAAA,KAAA,CAAA;EAIP,wBAAwB,MAAM;EAC9B,KAAK,gBAAgB;CACtB;CAEA,MAAM,eAAe,SAAiE;EACrF,MAAM,EAAE,QAAQ,MAAM,iBAAiB;EACvC,MAAM,QAAiC,EAAE,GAAG,aAAa;EAOzD,IAAI,MAAM;GACT,MAAM,CAAC,GAAG,KAAK,KAAK,MAAM,GAAG;GAC7B,IAAI,GAAG,MAAM,QAAQ,OAAO,CAAC;GAC7B,IAAI,GAAG,MAAM,SAAS,OAAO,CAAC;EAC/B;EAEA,IAAI,sBAAsB,KAAK,aAAa,GAC3C,OAAO,KAAK,mBAAmB,QAAQ,KAAK;EAG7C,IAAI,0BAA0B,KAAK,aAAa,GAC/C,OAAO,KAAK,gBAAgB,QAAQ,KAAK;EAI1C,OAAO,KAAK,mBAAmB,QAAQ,KAAK;CAC7C;CAEA,MAAc,mBACb,QACA,SACiC;EAIjC,MAAM,MAAM,MAAM,eAAe,MAHrB,KAAK,cAA+C,QACxC,IAAI,KAAK,OAAO;GAAE;GAAQ,GAAG;EAAQ,CAAC,GAErB,OAAO;EAChD,OAAO,KAAK,WAAW,GAAG;CAC3B;CAEA,MAAc,gBACb,QACA,SACiC;EACjC,MAAM,SAAS,KAAK;EAQpB,MAAM,SAAS,OAAM,MAPE,mBACtB,QACA,KAAK,OACL;GAAE;GAAQ,GAAG;EAAQ,GACrB;GAAE,OAAO;GAAoB,QAAS,QAAqC;EAAO,CACnF,EAAA,CAE8B,YAAY;EAC1C,OAAO,KAAK,WAAW,mBAAmB,IAAI,WAAW,MAAM,CAAC,CAAC;CAClE;CAEA,MAAc,mBACb,QACA,SACiC;EACjC,MAAM,gBAAgB,KAAK;EAM3B,MAAM,WAAW,MALI,mBAAmB,cAAc,aAKpB,CAAC,CAAC,oDAAoD;GACvF,QAAQ;GACR,MAAM,KAAK,UAAU;IACpB,OAAO,KAAK;IACZ;IACA,GAAG;GACJ,CAAC;EACF,CAAC;EAED,IAAI,CAAC,SAAS,IAAI;GACjB,MAAM,YAAY,MAAM,SAAS,KAAK;GACtC,MAAM,IAAI,MACT,4CAA4C,SAAS,OAAO,KAAK,WAClE;EACD;EAEA,MAAM,SAAS,MAAM,SAAS,YAAY;EAC1C,OAAO,KAAK,WAAW,mBAAmB,IAAI,WAAW,MAAM,CAAC,CAAC;CAClE;;CAGA,WAAmB,KAAoC;EACtD,OAAO;GACN,IAAI,KAAK,WAAW;GACpB,OAAO,KAAK;GACZ,QAAQ,CAAC,EAAE,SAAS,IAAI,CAAC;EAC1B;CACD;AACD;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,qBAAqB,OAA4B,QAAgC;CAChG,OAAO,IAAI,sBAAsB,QAAQ,KAAK;AAC/C"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("../
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const require_workers_ai_rest = require("../workers-ai-rest-CkNCtBwv.cjs");
|
|
2
|
+
const require_create_fetcher = require("../create-fetcher-YVxWCTVL.cjs");
|
|
3
|
+
const require_defineProperty = require("../defineProperty-In8g9yAD.cjs");
|
|
4
|
+
const require_workers_ai_rest = require("../workers-ai-rest-_MXOmyDs.cjs");
|
|
6
5
|
let _tanstack_ai_adapters = require("@tanstack/ai/adapters");
|
|
7
6
|
//#region src/adapters/workers-ai-summarize.ts
|
|
8
7
|
var WorkersAiSummarizeAdapter = class extends _tanstack_ai_adapters.BaseSummarizeAdapter {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workers-ai-summarize.cjs","names":["BaseSummarizeAdapter","isDirectBindingConfig","isDirectCredentialsConfig","workersAiRestFetch","createGatewayFetch"],"sources":["../../src/adapters/workers-ai-summarize.ts"],"sourcesContent":["import { BaseSummarizeAdapter } from \"@tanstack/ai/adapters\";\nimport type { SummarizationOptions, SummarizationResult } from \"@tanstack/ai\";\nimport {\n\ttype WorkersAiAdapterConfig,\n\ttype WorkersAiDirectBindingConfig,\n\ttype WorkersAiDirectCredentialsConfig,\n\ttype AiGatewayAdapterConfig,\n\tcreateGatewayFetch,\n\tisDirectBindingConfig,\n\tisDirectCredentialsConfig,\n\tvalidateWorkersAiConfig,\n} from \"../utils/create-fetcher\";\nimport { workersAiRestFetch } from \"../utils/workers-ai-rest\";\n\n// ---------------------------------------------------------------------------\n// Model types\n// ---------------------------------------------------------------------------\n\n/**\n * Workers AI models that support summarization.\n */\nexport type WorkersAiSummarizeModel = \"@cf/facebook/bart-large-cnn\" | (string & {});\n\n// ---------------------------------------------------------------------------\n// WorkersAiSummarizeAdapter\n// ---------------------------------------------------------------------------\n\nexport class WorkersAiSummarizeAdapter extends BaseSummarizeAdapter<WorkersAiSummarizeModel> {\n\treadonly name = \"workers-ai-summarize\" as const;\n\tprivate adapterConfig: WorkersAiAdapterConfig;\n\n\tconstructor(config: WorkersAiAdapterConfig, model: WorkersAiSummarizeModel) {\n\t\tsuper({}, model);\n\t\tvalidateWorkersAiConfig(config);\n\t\tthis.adapterConfig = config;\n\t}\n\n\tasync summarize(options: SummarizationOptions): Promise<SummarizationResult> {\n\t\tconst { text, maxLength } = options;\n\n\t\tconst payload: Record<string, unknown> = { input_text: text };\n\t\tif (maxLength != null) payload.max_length = maxLength;\n\n\t\tif (isDirectBindingConfig(this.adapterConfig)) {\n\t\t\treturn this.summarizeViaBinding(payload);\n\t\t}\n\n\t\tif (isDirectCredentialsConfig(this.adapterConfig)) {\n\t\t\treturn this.summarizeViaRest(payload);\n\t\t}\n\n\t\treturn this.summarizeViaGateway(payload);\n\t}\n\n\tprivate async summarizeViaBinding(\n\t\tpayload: Record<string, unknown>,\n\t): Promise<SummarizationResult> {\n\t\tconst ai = (this.adapterConfig as WorkersAiDirectBindingConfig).binding;\n\t\tconst result = (await ai.run(this.model, payload)) as Record<string, unknown>;\n\t\treturn this.wrapResult((result.summary as string) ?? \"\");\n\t}\n\n\tprivate async summarizeViaRest(payload: Record<string, unknown>): Promise<SummarizationResult> {\n\t\tconst config = this.adapterConfig as WorkersAiDirectCredentialsConfig;\n\t\tconst response = await workersAiRestFetch(config, this.model, payload, {\n\t\t\tlabel: \"Workers AI summarize\",\n\t\t});\n\n\t\tconst data = (await response.json()) as { result?: { summary?: string } };\n\t\treturn this.wrapResult(data.result?.summary ?? \"\");\n\t}\n\n\tprivate async summarizeViaGateway(\n\t\tpayload: Record<string, unknown>,\n\t): Promise<SummarizationResult> {\n\t\tconst gatewayConfig = this.adapterConfig as AiGatewayAdapterConfig;\n\t\tconst gatewayFetch = createGatewayFetch(\"workers-ai\", gatewayConfig);\n\n\t\t// The URL here is a placeholder — createGatewayFetch for \"workers-ai\" extracts\n\t\t// the model from the body, sets it as the endpoint, and routes through the gateway.\n\t\t// The actual URL path is not used.\n\t\tconst response = await gatewayFetch(\"https://api.cloudflare.com/v1/ai/summarization\", {\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify({\n\t\t\t\tmodel: this.model,\n\t\t\t\t...payload,\n\t\t\t}),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tconst errorText = await response.text();\n\t\t\tthrow new Error(\n\t\t\t\t`Workers AI summarize gateway request failed (${response.status}): ${errorText}`,\n\t\t\t);\n\t\t}\n\n\t\tconst data = (await response.json()) as { result?: { summary?: string }; summary?: string };\n\t\treturn this.wrapResult(data.result?.summary ?? data.summary ?? \"\");\n\t}\n\n\tprivate wrapResult(summary: string): SummarizationResult {\n\t\treturn {\n\t\t\tid: this.generateId(),\n\t\t\tmodel: this.model,\n\t\t\tsummary,\n\t\t\t// BART-large-CNN doesn't return token usage\n\t\t\tusage: { promptTokens: 0, completionTokens: 0, totalTokens: 0 },\n\t\t};\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// Factory function\n// ---------------------------------------------------------------------------\n\n/**\n * Creates a Workers AI summarization adapter.\n *\n * Works with TanStack AI's `summarize()` activity function:\n * ```ts\n * import { summarize } from \"@tanstack/ai\";\n * import { createWorkersAiSummarize } from \"@cloudflare/tanstack-ai\";\n *\n * const adapter = createWorkersAiSummarize(\"@cf/facebook/bart-large-cnn\", {\n * binding: env.AI,\n * });\n *\n * const result = await summarize({ adapter, text: \"Long article here...\" });\n * // result.summary\n * ```\n *\n * Note: Factory takes `(model, config)` for ergonomics — the class constructor\n * uses `(config, model)` to match TanStack AI's upstream convention.\n */\nexport function createWorkersAiSummarize(\n\tmodel: WorkersAiSummarizeModel,\n\tconfig: WorkersAiAdapterConfig,\n) {\n\treturn new WorkersAiSummarizeAdapter(config, model);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"workers-ai-summarize.cjs","names":["BaseSummarizeAdapter","isDirectBindingConfig","isDirectCredentialsConfig","workersAiRestFetch","createGatewayFetch"],"sources":["../../src/adapters/workers-ai-summarize.ts"],"sourcesContent":["import { BaseSummarizeAdapter } from \"@tanstack/ai/adapters\";\nimport type { SummarizationOptions, SummarizationResult } from \"@tanstack/ai\";\nimport {\n\ttype WorkersAiAdapterConfig,\n\ttype WorkersAiDirectBindingConfig,\n\ttype WorkersAiDirectCredentialsConfig,\n\ttype AiGatewayAdapterConfig,\n\tcreateGatewayFetch,\n\tisDirectBindingConfig,\n\tisDirectCredentialsConfig,\n\tvalidateWorkersAiConfig,\n} from \"../utils/create-fetcher\";\nimport { workersAiRestFetch } from \"../utils/workers-ai-rest\";\n\n// ---------------------------------------------------------------------------\n// Model types\n// ---------------------------------------------------------------------------\n\n/**\n * Workers AI models that support summarization.\n */\nexport type WorkersAiSummarizeModel = \"@cf/facebook/bart-large-cnn\" | (string & {});\n\n// ---------------------------------------------------------------------------\n// WorkersAiSummarizeAdapter\n// ---------------------------------------------------------------------------\n\nexport class WorkersAiSummarizeAdapter extends BaseSummarizeAdapter<WorkersAiSummarizeModel> {\n\treadonly name = \"workers-ai-summarize\" as const;\n\tprivate adapterConfig: WorkersAiAdapterConfig;\n\n\tconstructor(config: WorkersAiAdapterConfig, model: WorkersAiSummarizeModel) {\n\t\tsuper({}, model);\n\t\tvalidateWorkersAiConfig(config);\n\t\tthis.adapterConfig = config;\n\t}\n\n\tasync summarize(options: SummarizationOptions): Promise<SummarizationResult> {\n\t\tconst { text, maxLength } = options;\n\n\t\tconst payload: Record<string, unknown> = { input_text: text };\n\t\tif (maxLength != null) payload.max_length = maxLength;\n\n\t\tif (isDirectBindingConfig(this.adapterConfig)) {\n\t\t\treturn this.summarizeViaBinding(payload);\n\t\t}\n\n\t\tif (isDirectCredentialsConfig(this.adapterConfig)) {\n\t\t\treturn this.summarizeViaRest(payload);\n\t\t}\n\n\t\treturn this.summarizeViaGateway(payload);\n\t}\n\n\tprivate async summarizeViaBinding(\n\t\tpayload: Record<string, unknown>,\n\t): Promise<SummarizationResult> {\n\t\tconst ai = (this.adapterConfig as WorkersAiDirectBindingConfig).binding;\n\t\tconst result = (await ai.run(this.model, payload)) as Record<string, unknown>;\n\t\treturn this.wrapResult((result.summary as string) ?? \"\");\n\t}\n\n\tprivate async summarizeViaRest(payload: Record<string, unknown>): Promise<SummarizationResult> {\n\t\tconst config = this.adapterConfig as WorkersAiDirectCredentialsConfig;\n\t\tconst response = await workersAiRestFetch(config, this.model, payload, {\n\t\t\tlabel: \"Workers AI summarize\",\n\t\t});\n\n\t\tconst data = (await response.json()) as { result?: { summary?: string } };\n\t\treturn this.wrapResult(data.result?.summary ?? \"\");\n\t}\n\n\tprivate async summarizeViaGateway(\n\t\tpayload: Record<string, unknown>,\n\t): Promise<SummarizationResult> {\n\t\tconst gatewayConfig = this.adapterConfig as AiGatewayAdapterConfig;\n\t\tconst gatewayFetch = createGatewayFetch(\"workers-ai\", gatewayConfig);\n\n\t\t// The URL here is a placeholder — createGatewayFetch for \"workers-ai\" extracts\n\t\t// the model from the body, sets it as the endpoint, and routes through the gateway.\n\t\t// The actual URL path is not used.\n\t\tconst response = await gatewayFetch(\"https://api.cloudflare.com/v1/ai/summarization\", {\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify({\n\t\t\t\tmodel: this.model,\n\t\t\t\t...payload,\n\t\t\t}),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tconst errorText = await response.text();\n\t\t\tthrow new Error(\n\t\t\t\t`Workers AI summarize gateway request failed (${response.status}): ${errorText}`,\n\t\t\t);\n\t\t}\n\n\t\tconst data = (await response.json()) as { result?: { summary?: string }; summary?: string };\n\t\treturn this.wrapResult(data.result?.summary ?? data.summary ?? \"\");\n\t}\n\n\tprivate wrapResult(summary: string): SummarizationResult {\n\t\treturn {\n\t\t\tid: this.generateId(),\n\t\t\tmodel: this.model,\n\t\t\tsummary,\n\t\t\t// BART-large-CNN doesn't return token usage\n\t\t\tusage: { promptTokens: 0, completionTokens: 0, totalTokens: 0 },\n\t\t};\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// Factory function\n// ---------------------------------------------------------------------------\n\n/**\n * Creates a Workers AI summarization adapter.\n *\n * Works with TanStack AI's `summarize()` activity function:\n * ```ts\n * import { summarize } from \"@tanstack/ai\";\n * import { createWorkersAiSummarize } from \"@cloudflare/tanstack-ai\";\n *\n * const adapter = createWorkersAiSummarize(\"@cf/facebook/bart-large-cnn\", {\n * binding: env.AI,\n * });\n *\n * const result = await summarize({ adapter, text: \"Long article here...\" });\n * // result.summary\n * ```\n *\n * Note: Factory takes `(model, config)` for ergonomics — the class constructor\n * uses `(config, model)` to match TanStack AI's upstream convention.\n */\nexport function createWorkersAiSummarize(\n\tmodel: WorkersAiSummarizeModel,\n\tconfig: WorkersAiAdapterConfig,\n) {\n\treturn new WorkersAiSummarizeAdapter(config, model);\n}\n"],"mappings":";;;;;;AA2BA,IAAa,4BAAb,cAA+CA,sBAAAA,qBAA8C;CAI5F,YAAY,QAAgC,OAAgC;EAC3E,MAAM,CAAC,GAAG,KAAK;+CAJP,QAAO,sBAAA;+CACR,iBAAA,KAAA,CAAA;EAIP,uBAAA,wBAAwB,MAAM;EAC9B,KAAK,gBAAgB;CACtB;CAEA,MAAM,UAAU,SAA6D;EAC5E,MAAM,EAAE,MAAM,cAAc;EAE5B,MAAM,UAAmC,EAAE,YAAY,KAAK;EAC5D,IAAI,aAAa,MAAM,QAAQ,aAAa;EAE5C,IAAIC,uBAAAA,sBAAsB,KAAK,aAAa,GAC3C,OAAO,KAAK,oBAAoB,OAAO;EAGxC,IAAIC,uBAAAA,0BAA0B,KAAK,aAAa,GAC/C,OAAO,KAAK,iBAAiB,OAAO;EAGrC,OAAO,KAAK,oBAAoB,OAAO;CACxC;CAEA,MAAc,oBACb,SAC+B;EAE/B,MAAM,SAAU,MADJ,KAAK,cAA+C,QACvC,IAAI,KAAK,OAAO,OAAO;EAChD,OAAO,KAAK,WAAY,OAAO,WAAsB,EAAE;CACxD;CAEA,MAAc,iBAAiB,SAAgE;EAC9F,MAAM,SAAS,KAAK;EAKpB,MAAM,OAAQ,OAAM,MAJGC,wBAAAA,mBAAmB,QAAQ,KAAK,OAAO,SAAS,EACtE,OAAO,uBACR,CAAC,EAAA,CAE4B,KAAK;EAClC,OAAO,KAAK,WAAW,KAAK,QAAQ,WAAW,EAAE;CAClD;CAEA,MAAc,oBACb,SAC+B;EAC/B,MAAM,gBAAgB,KAAK;EAM3B,MAAM,WAAW,MALIC,uBAAAA,mBAAmB,cAAc,aAKpB,CAAC,CAAC,kDAAkD;GACrF,QAAQ;GACR,MAAM,KAAK,UAAU;IACpB,OAAO,KAAK;IACZ,GAAG;GACJ,CAAC;EACF,CAAC;EAED,IAAI,CAAC,SAAS,IAAI;GACjB,MAAM,YAAY,MAAM,SAAS,KAAK;GACtC,MAAM,IAAI,MACT,gDAAgD,SAAS,OAAO,KAAK,WACtE;EACD;EAEA,MAAM,OAAQ,MAAM,SAAS,KAAK;EAClC,OAAO,KAAK,WAAW,KAAK,QAAQ,WAAW,KAAK,WAAW,EAAE;CAClE;CAEA,WAAmB,SAAsC;EACxD,OAAO;GACN,IAAI,KAAK,WAAW;GACpB,OAAO,KAAK;GACZ;GAEA,OAAO;IAAE,cAAc;IAAG,kBAAkB;IAAG,aAAa;GAAE;EAC/D;CACD;AACD;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,yBACf,OACA,QACC;CACD,OAAO,IAAI,0BAA0B,QAAQ,KAAK;AACnD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as WorkersAiAdapterConfig } from "../create-fetcher-
|
|
1
|
+
import { i as WorkersAiAdapterConfig } from "../create-fetcher-Bp5yCNaO.cjs";
|
|
2
2
|
import { SummarizationOptions, SummarizationResult } from "@tanstack/ai";
|
|
3
3
|
import { BaseSummarizeAdapter } from "@tanstack/ai/adapters";
|
|
4
4
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as WorkersAiAdapterConfig } from "../create-fetcher-
|
|
2
|
-
import { BaseSummarizeAdapter } from "@tanstack/ai/adapters";
|
|
1
|
+
import { i as WorkersAiAdapterConfig } from "../create-fetcher-Bp5yCNaO.mjs";
|
|
3
2
|
import { SummarizationOptions, SummarizationResult } from "@tanstack/ai";
|
|
3
|
+
import { BaseSummarizeAdapter } from "@tanstack/ai/adapters";
|
|
4
4
|
|
|
5
5
|
//#region src/adapters/workers-ai-summarize.d.ts
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as validateWorkersAiConfig, i as isDirectCredentialsConfig, r as isDirectBindingConfig, t as createGatewayFetch } from "../create-fetcher-
|
|
2
|
-
import { t as _defineProperty } from "../defineProperty-
|
|
3
|
-
import { t as workersAiRestFetch } from "../workers-ai-rest-
|
|
1
|
+
import { a as validateWorkersAiConfig, i as isDirectCredentialsConfig, r as isDirectBindingConfig, t as createGatewayFetch } from "../create-fetcher-BnSnCaHf.mjs";
|
|
2
|
+
import { t as _defineProperty } from "../defineProperty-BC3bEcwq.mjs";
|
|
3
|
+
import { t as workersAiRestFetch } from "../workers-ai-rest-B6_yU35Q.mjs";
|
|
4
4
|
import { BaseSummarizeAdapter } from "@tanstack/ai/adapters";
|
|
5
5
|
//#region src/adapters/workers-ai-summarize.ts
|
|
6
6
|
var WorkersAiSummarizeAdapter = class extends BaseSummarizeAdapter {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workers-ai-summarize.mjs","names":[],"sources":["../../src/adapters/workers-ai-summarize.ts"],"sourcesContent":["import { BaseSummarizeAdapter } from \"@tanstack/ai/adapters\";\nimport type { SummarizationOptions, SummarizationResult } from \"@tanstack/ai\";\nimport {\n\ttype WorkersAiAdapterConfig,\n\ttype WorkersAiDirectBindingConfig,\n\ttype WorkersAiDirectCredentialsConfig,\n\ttype AiGatewayAdapterConfig,\n\tcreateGatewayFetch,\n\tisDirectBindingConfig,\n\tisDirectCredentialsConfig,\n\tvalidateWorkersAiConfig,\n} from \"../utils/create-fetcher\";\nimport { workersAiRestFetch } from \"../utils/workers-ai-rest\";\n\n// ---------------------------------------------------------------------------\n// Model types\n// ---------------------------------------------------------------------------\n\n/**\n * Workers AI models that support summarization.\n */\nexport type WorkersAiSummarizeModel = \"@cf/facebook/bart-large-cnn\" | (string & {});\n\n// ---------------------------------------------------------------------------\n// WorkersAiSummarizeAdapter\n// ---------------------------------------------------------------------------\n\nexport class WorkersAiSummarizeAdapter extends BaseSummarizeAdapter<WorkersAiSummarizeModel> {\n\treadonly name = \"workers-ai-summarize\" as const;\n\tprivate adapterConfig: WorkersAiAdapterConfig;\n\n\tconstructor(config: WorkersAiAdapterConfig, model: WorkersAiSummarizeModel) {\n\t\tsuper({}, model);\n\t\tvalidateWorkersAiConfig(config);\n\t\tthis.adapterConfig = config;\n\t}\n\n\tasync summarize(options: SummarizationOptions): Promise<SummarizationResult> {\n\t\tconst { text, maxLength } = options;\n\n\t\tconst payload: Record<string, unknown> = { input_text: text };\n\t\tif (maxLength != null) payload.max_length = maxLength;\n\n\t\tif (isDirectBindingConfig(this.adapterConfig)) {\n\t\t\treturn this.summarizeViaBinding(payload);\n\t\t}\n\n\t\tif (isDirectCredentialsConfig(this.adapterConfig)) {\n\t\t\treturn this.summarizeViaRest(payload);\n\t\t}\n\n\t\treturn this.summarizeViaGateway(payload);\n\t}\n\n\tprivate async summarizeViaBinding(\n\t\tpayload: Record<string, unknown>,\n\t): Promise<SummarizationResult> {\n\t\tconst ai = (this.adapterConfig as WorkersAiDirectBindingConfig).binding;\n\t\tconst result = (await ai.run(this.model, payload)) as Record<string, unknown>;\n\t\treturn this.wrapResult((result.summary as string) ?? \"\");\n\t}\n\n\tprivate async summarizeViaRest(payload: Record<string, unknown>): Promise<SummarizationResult> {\n\t\tconst config = this.adapterConfig as WorkersAiDirectCredentialsConfig;\n\t\tconst response = await workersAiRestFetch(config, this.model, payload, {\n\t\t\tlabel: \"Workers AI summarize\",\n\t\t});\n\n\t\tconst data = (await response.json()) as { result?: { summary?: string } };\n\t\treturn this.wrapResult(data.result?.summary ?? \"\");\n\t}\n\n\tprivate async summarizeViaGateway(\n\t\tpayload: Record<string, unknown>,\n\t): Promise<SummarizationResult> {\n\t\tconst gatewayConfig = this.adapterConfig as AiGatewayAdapterConfig;\n\t\tconst gatewayFetch = createGatewayFetch(\"workers-ai\", gatewayConfig);\n\n\t\t// The URL here is a placeholder — createGatewayFetch for \"workers-ai\" extracts\n\t\t// the model from the body, sets it as the endpoint, and routes through the gateway.\n\t\t// The actual URL path is not used.\n\t\tconst response = await gatewayFetch(\"https://api.cloudflare.com/v1/ai/summarization\", {\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify({\n\t\t\t\tmodel: this.model,\n\t\t\t\t...payload,\n\t\t\t}),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tconst errorText = await response.text();\n\t\t\tthrow new Error(\n\t\t\t\t`Workers AI summarize gateway request failed (${response.status}): ${errorText}`,\n\t\t\t);\n\t\t}\n\n\t\tconst data = (await response.json()) as { result?: { summary?: string }; summary?: string };\n\t\treturn this.wrapResult(data.result?.summary ?? data.summary ?? \"\");\n\t}\n\n\tprivate wrapResult(summary: string): SummarizationResult {\n\t\treturn {\n\t\t\tid: this.generateId(),\n\t\t\tmodel: this.model,\n\t\t\tsummary,\n\t\t\t// BART-large-CNN doesn't return token usage\n\t\t\tusage: { promptTokens: 0, completionTokens: 0, totalTokens: 0 },\n\t\t};\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// Factory function\n// ---------------------------------------------------------------------------\n\n/**\n * Creates a Workers AI summarization adapter.\n *\n * Works with TanStack AI's `summarize()` activity function:\n * ```ts\n * import { summarize } from \"@tanstack/ai\";\n * import { createWorkersAiSummarize } from \"@cloudflare/tanstack-ai\";\n *\n * const adapter = createWorkersAiSummarize(\"@cf/facebook/bart-large-cnn\", {\n * binding: env.AI,\n * });\n *\n * const result = await summarize({ adapter, text: \"Long article here...\" });\n * // result.summary\n * ```\n *\n * Note: Factory takes `(model, config)` for ergonomics — the class constructor\n * uses `(config, model)` to match TanStack AI's upstream convention.\n */\nexport function createWorkersAiSummarize(\n\tmodel: WorkersAiSummarizeModel,\n\tconfig: WorkersAiAdapterConfig,\n) {\n\treturn new WorkersAiSummarizeAdapter(config, model);\n}\n"],"mappings":";;;;;AA2BA,IAAa,4BAAb,cAA+C,qBAA8C;CAI5F,YAAY,QAAgC,OAAgC;
|
|
1
|
+
{"version":3,"file":"workers-ai-summarize.mjs","names":[],"sources":["../../src/adapters/workers-ai-summarize.ts"],"sourcesContent":["import { BaseSummarizeAdapter } from \"@tanstack/ai/adapters\";\nimport type { SummarizationOptions, SummarizationResult } from \"@tanstack/ai\";\nimport {\n\ttype WorkersAiAdapterConfig,\n\ttype WorkersAiDirectBindingConfig,\n\ttype WorkersAiDirectCredentialsConfig,\n\ttype AiGatewayAdapterConfig,\n\tcreateGatewayFetch,\n\tisDirectBindingConfig,\n\tisDirectCredentialsConfig,\n\tvalidateWorkersAiConfig,\n} from \"../utils/create-fetcher\";\nimport { workersAiRestFetch } from \"../utils/workers-ai-rest\";\n\n// ---------------------------------------------------------------------------\n// Model types\n// ---------------------------------------------------------------------------\n\n/**\n * Workers AI models that support summarization.\n */\nexport type WorkersAiSummarizeModel = \"@cf/facebook/bart-large-cnn\" | (string & {});\n\n// ---------------------------------------------------------------------------\n// WorkersAiSummarizeAdapter\n// ---------------------------------------------------------------------------\n\nexport class WorkersAiSummarizeAdapter extends BaseSummarizeAdapter<WorkersAiSummarizeModel> {\n\treadonly name = \"workers-ai-summarize\" as const;\n\tprivate adapterConfig: WorkersAiAdapterConfig;\n\n\tconstructor(config: WorkersAiAdapterConfig, model: WorkersAiSummarizeModel) {\n\t\tsuper({}, model);\n\t\tvalidateWorkersAiConfig(config);\n\t\tthis.adapterConfig = config;\n\t}\n\n\tasync summarize(options: SummarizationOptions): Promise<SummarizationResult> {\n\t\tconst { text, maxLength } = options;\n\n\t\tconst payload: Record<string, unknown> = { input_text: text };\n\t\tif (maxLength != null) payload.max_length = maxLength;\n\n\t\tif (isDirectBindingConfig(this.adapterConfig)) {\n\t\t\treturn this.summarizeViaBinding(payload);\n\t\t}\n\n\t\tif (isDirectCredentialsConfig(this.adapterConfig)) {\n\t\t\treturn this.summarizeViaRest(payload);\n\t\t}\n\n\t\treturn this.summarizeViaGateway(payload);\n\t}\n\n\tprivate async summarizeViaBinding(\n\t\tpayload: Record<string, unknown>,\n\t): Promise<SummarizationResult> {\n\t\tconst ai = (this.adapterConfig as WorkersAiDirectBindingConfig).binding;\n\t\tconst result = (await ai.run(this.model, payload)) as Record<string, unknown>;\n\t\treturn this.wrapResult((result.summary as string) ?? \"\");\n\t}\n\n\tprivate async summarizeViaRest(payload: Record<string, unknown>): Promise<SummarizationResult> {\n\t\tconst config = this.adapterConfig as WorkersAiDirectCredentialsConfig;\n\t\tconst response = await workersAiRestFetch(config, this.model, payload, {\n\t\t\tlabel: \"Workers AI summarize\",\n\t\t});\n\n\t\tconst data = (await response.json()) as { result?: { summary?: string } };\n\t\treturn this.wrapResult(data.result?.summary ?? \"\");\n\t}\n\n\tprivate async summarizeViaGateway(\n\t\tpayload: Record<string, unknown>,\n\t): Promise<SummarizationResult> {\n\t\tconst gatewayConfig = this.adapterConfig as AiGatewayAdapterConfig;\n\t\tconst gatewayFetch = createGatewayFetch(\"workers-ai\", gatewayConfig);\n\n\t\t// The URL here is a placeholder — createGatewayFetch for \"workers-ai\" extracts\n\t\t// the model from the body, sets it as the endpoint, and routes through the gateway.\n\t\t// The actual URL path is not used.\n\t\tconst response = await gatewayFetch(\"https://api.cloudflare.com/v1/ai/summarization\", {\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify({\n\t\t\t\tmodel: this.model,\n\t\t\t\t...payload,\n\t\t\t}),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tconst errorText = await response.text();\n\t\t\tthrow new Error(\n\t\t\t\t`Workers AI summarize gateway request failed (${response.status}): ${errorText}`,\n\t\t\t);\n\t\t}\n\n\t\tconst data = (await response.json()) as { result?: { summary?: string }; summary?: string };\n\t\treturn this.wrapResult(data.result?.summary ?? data.summary ?? \"\");\n\t}\n\n\tprivate wrapResult(summary: string): SummarizationResult {\n\t\treturn {\n\t\t\tid: this.generateId(),\n\t\t\tmodel: this.model,\n\t\t\tsummary,\n\t\t\t// BART-large-CNN doesn't return token usage\n\t\t\tusage: { promptTokens: 0, completionTokens: 0, totalTokens: 0 },\n\t\t};\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// Factory function\n// ---------------------------------------------------------------------------\n\n/**\n * Creates a Workers AI summarization adapter.\n *\n * Works with TanStack AI's `summarize()` activity function:\n * ```ts\n * import { summarize } from \"@tanstack/ai\";\n * import { createWorkersAiSummarize } from \"@cloudflare/tanstack-ai\";\n *\n * const adapter = createWorkersAiSummarize(\"@cf/facebook/bart-large-cnn\", {\n * binding: env.AI,\n * });\n *\n * const result = await summarize({ adapter, text: \"Long article here...\" });\n * // result.summary\n * ```\n *\n * Note: Factory takes `(model, config)` for ergonomics — the class constructor\n * uses `(config, model)` to match TanStack AI's upstream convention.\n */\nexport function createWorkersAiSummarize(\n\tmodel: WorkersAiSummarizeModel,\n\tconfig: WorkersAiAdapterConfig,\n) {\n\treturn new WorkersAiSummarizeAdapter(config, model);\n}\n"],"mappings":";;;;;AA2BA,IAAa,4BAAb,cAA+C,qBAA8C;CAI5F,YAAY,QAAgC,OAAgC;EAC3E,MAAM,CAAC,GAAG,KAAK;wBAJP,QAAO,sBAAA;wBACR,iBAAA,KAAA,CAAA;EAIP,wBAAwB,MAAM;EAC9B,KAAK,gBAAgB;CACtB;CAEA,MAAM,UAAU,SAA6D;EAC5E,MAAM,EAAE,MAAM,cAAc;EAE5B,MAAM,UAAmC,EAAE,YAAY,KAAK;EAC5D,IAAI,aAAa,MAAM,QAAQ,aAAa;EAE5C,IAAI,sBAAsB,KAAK,aAAa,GAC3C,OAAO,KAAK,oBAAoB,OAAO;EAGxC,IAAI,0BAA0B,KAAK,aAAa,GAC/C,OAAO,KAAK,iBAAiB,OAAO;EAGrC,OAAO,KAAK,oBAAoB,OAAO;CACxC;CAEA,MAAc,oBACb,SAC+B;EAE/B,MAAM,SAAU,MADJ,KAAK,cAA+C,QACvC,IAAI,KAAK,OAAO,OAAO;EAChD,OAAO,KAAK,WAAY,OAAO,WAAsB,EAAE;CACxD;CAEA,MAAc,iBAAiB,SAAgE;EAC9F,MAAM,SAAS,KAAK;EAKpB,MAAM,OAAQ,OAAM,MAJG,mBAAmB,QAAQ,KAAK,OAAO,SAAS,EACtE,OAAO,uBACR,CAAC,EAAA,CAE4B,KAAK;EAClC,OAAO,KAAK,WAAW,KAAK,QAAQ,WAAW,EAAE;CAClD;CAEA,MAAc,oBACb,SAC+B;EAC/B,MAAM,gBAAgB,KAAK;EAM3B,MAAM,WAAW,MALI,mBAAmB,cAAc,aAKpB,CAAC,CAAC,kDAAkD;GACrF,QAAQ;GACR,MAAM,KAAK,UAAU;IACpB,OAAO,KAAK;IACZ,GAAG;GACJ,CAAC;EACF,CAAC;EAED,IAAI,CAAC,SAAS,IAAI;GACjB,MAAM,YAAY,MAAM,SAAS,KAAK;GACtC,MAAM,IAAI,MACT,gDAAgD,SAAS,OAAO,KAAK,WACtE;EACD;EAEA,MAAM,OAAQ,MAAM,SAAS,KAAK;EAClC,OAAO,KAAK,WAAW,KAAK,QAAQ,WAAW,KAAK,WAAW,EAAE;CAClE;CAEA,WAAmB,SAAsC;EACxD,OAAO;GACN,IAAI,KAAK,WAAW;GACpB,OAAO,KAAK;GACZ;GAEA,OAAO;IAAE,cAAc;IAAG,kBAAkB;IAAG,aAAa;GAAE;EAC/D;CACD;AACD;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,yBACf,OACA,QACC;CACD,OAAO,IAAI,0BAA0B,QAAQ,KAAK;AACnD"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("../
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const require_binary = require("../binary-C9FAYwZj.cjs");
|
|
2
|
+
const require_create_fetcher = require("../create-fetcher-YVxWCTVL.cjs");
|
|
3
|
+
const require_defineProperty = require("../defineProperty-In8g9yAD.cjs");
|
|
4
|
+
const require_workers_ai_rest = require("../workers-ai-rest-_MXOmyDs.cjs");
|
|
5
|
+
const require_binary = require("../binary-CZhr1_2n.cjs");
|
|
7
6
|
let _tanstack_ai_adapters = require("@tanstack/ai/adapters");
|
|
8
7
|
//#region src/adapters/workers-ai-transcription.ts
|
|
9
8
|
var WorkersAiTranscriptionAdapter = class extends _tanstack_ai_adapters.BaseTranscriptionAdapter {
|
|
10
9
|
constructor(config, model) {
|
|
11
|
-
super(
|
|
10
|
+
super(model);
|
|
12
11
|
require_defineProperty._defineProperty(this, "name", "workers-ai-transcription");
|
|
13
12
|
require_defineProperty._defineProperty(this, "adapterConfig", void 0);
|
|
14
13
|
require_create_fetcher.validateWorkersAiConfig(config);
|