workers-ai-provider 2.0.0 → 2.0.1

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.
@@ -0,0 +1,63 @@
1
+ import {
2
+ require_token_error,
3
+ require_token_util
4
+ } from "./chunk-H3ZBSMAH.js";
5
+ import {
6
+ __commonJS
7
+ } from "./chunk-LOLDRYLH.js";
8
+
9
+ // ../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/token.js
10
+ var require_token = __commonJS({
11
+ "../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/token.js"(exports, module) {
12
+ var __defProp = Object.defineProperty;
13
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
14
+ var __getOwnPropNames = Object.getOwnPropertyNames;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var token_exports = {};
30
+ __export(token_exports, {
31
+ refreshToken: () => refreshToken
32
+ });
33
+ module.exports = __toCommonJS(token_exports);
34
+ var import_token_error = require_token_error();
35
+ var import_token_util = require_token_util();
36
+ async function refreshToken() {
37
+ const { projectId, teamId } = (0, import_token_util.findProjectInfo)();
38
+ let maybeToken = (0, import_token_util.loadToken)(projectId);
39
+ if (!maybeToken || (0, import_token_util.isExpired)((0, import_token_util.getTokenPayload)(maybeToken.token))) {
40
+ const authToken = (0, import_token_util.getVercelCliToken)();
41
+ if (!authToken) {
42
+ throw new import_token_error.VercelOidcTokenError(
43
+ "Failed to refresh OIDC token: login to vercel cli"
44
+ );
45
+ }
46
+ if (!projectId) {
47
+ throw new import_token_error.VercelOidcTokenError(
48
+ "Failed to refresh OIDC token: project id not found"
49
+ );
50
+ }
51
+ maybeToken = await (0, import_token_util.getVercelOidcToken)(authToken, projectId, teamId);
52
+ if (!maybeToken) {
53
+ throw new import_token_error.VercelOidcTokenError("Failed to refresh OIDC token");
54
+ }
55
+ (0, import_token_util.saveToken)(maybeToken, projectId);
56
+ }
57
+ process.env.VERCEL_OIDC_TOKEN = maybeToken.token;
58
+ return;
59
+ }
60
+ }
61
+ });
62
+ export default require_token();
63
+ //# sourceMappingURL=token-4SRL5WJU.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/token.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar token_exports = {};\n__export(token_exports, {\n refreshToken: () => refreshToken\n});\nmodule.exports = __toCommonJS(token_exports);\nvar import_token_error = require(\"./token-error\");\nvar import_token_util = require(\"./token-util\");\nasync function refreshToken() {\n const { projectId, teamId } = (0, import_token_util.findProjectInfo)();\n let maybeToken = (0, import_token_util.loadToken)(projectId);\n if (!maybeToken || (0, import_token_util.isExpired)((0, import_token_util.getTokenPayload)(maybeToken.token))) {\n const authToken = (0, import_token_util.getVercelCliToken)();\n if (!authToken) {\n throw new import_token_error.VercelOidcTokenError(\n \"Failed to refresh OIDC token: login to vercel cli\"\n );\n }\n if (!projectId) {\n throw new import_token_error.VercelOidcTokenError(\n \"Failed to refresh OIDC token: project id not found\"\n );\n }\n maybeToken = await (0, import_token_util.getVercelOidcToken)(authToken, projectId, teamId);\n if (!maybeToken) {\n throw new import_token_error.VercelOidcTokenError(\"Failed to refresh OIDC token\");\n }\n (0, import_token_util.saveToken)(maybeToken, projectId);\n }\n process.env.VERCEL_OIDC_TOKEN = maybeToken.token;\n return;\n}\n// Annotate the CommonJS export names for ESM import in node:\n0 && (module.exports = {\n refreshToken\n});\n"],"mappings":";;;;;;;;;AAAA;AAAA;AACA,QAAI,YAAY,OAAO;AACvB,QAAI,mBAAmB,OAAO;AAC9B,QAAI,oBAAoB,OAAO;AAC/B,QAAI,eAAe,OAAO,UAAU;AACpC,QAAI,WAAW,CAAC,QAAQ,QAAQ;AAC9B,eAAS,QAAQ;AACf,kBAAU,QAAQ,MAAM,EAAE,KAAK,IAAI,IAAI,GAAG,YAAY,KAAK,CAAC;AAAA,IAChE;AACA,QAAI,cAAc,CAAC,IAAI,MAAM,QAAQ,SAAS;AAC5C,UAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;AAClE,iBAAS,OAAO,kBAAkB,IAAI;AACpC,cAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ;AACzC,sBAAU,IAAI,KAAK,EAAE,KAAK,MAAM,KAAK,GAAG,GAAG,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK,WAAW,CAAC;AAAA,MACvH;AACA,aAAO;AAAA,IACT;AACA,QAAI,eAAe,CAAC,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,QAAI,gBAAgB,CAAC;AACrB,aAAS,eAAe;AAAA,MACtB,cAAc,MAAM;AAAA,IACtB,CAAC;AACD,WAAO,UAAU,aAAa,aAAa;AAC3C,QAAI,qBAAqB;AACzB,QAAI,oBAAoB;AACxB,mBAAe,eAAe;AAC5B,YAAM,EAAE,WAAW,OAAO,KAAK,GAAG,kBAAkB,iBAAiB;AACrE,UAAI,cAAc,GAAG,kBAAkB,WAAW,SAAS;AAC3D,UAAI,CAAC,eAAe,GAAG,kBAAkB,YAAY,GAAG,kBAAkB,iBAAiB,WAAW,KAAK,CAAC,GAAG;AAC7G,cAAM,aAAa,GAAG,kBAAkB,mBAAmB;AAC3D,YAAI,CAAC,WAAW;AACd,gBAAM,IAAI,mBAAmB;AAAA,YAC3B;AAAA,UACF;AAAA,QACF;AACA,YAAI,CAAC,WAAW;AACd,gBAAM,IAAI,mBAAmB;AAAA,YAC3B;AAAA,UACF;AAAA,QACF;AACA,qBAAa,OAAO,GAAG,kBAAkB,oBAAoB,WAAW,WAAW,MAAM;AACzF,YAAI,CAAC,YAAY;AACf,gBAAM,IAAI,mBAAmB,qBAAqB,8BAA8B;AAAA,QAClF;AACA,SAAC,GAAG,kBAAkB,WAAW,YAAY,SAAS;AAAA,MACxD;AACA,cAAQ,IAAI,oBAAoB,WAAW;AAC3C;AAAA,IACF;AAAA;AAAA;","names":[]}
@@ -0,0 +1,6 @@
1
+ import {
2
+ require_token_util
3
+ } from "./chunk-H3ZBSMAH.js";
4
+ import "./chunk-LOLDRYLH.js";
5
+ export default require_token_util();
6
+ //# sourceMappingURL=token-util-24B4MTMT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "workers-ai-provider",
3
3
  "description": "Workers AI Provider for the vercel AI SDK",
4
4
  "type": "module",
5
- "version": "2.0.0",
5
+ "version": "2.0.1",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "repository": {
@@ -32,10 +32,10 @@
32
32
  ],
33
33
  "dependencies": {
34
34
  "@ai-sdk/provider": "^2.0.0",
35
- "@ai-sdk/provider-utils": "^3.0.7"
35
+ "@ai-sdk/provider-utils": "^3.0.19"
36
36
  },
37
37
  "devDependencies": {
38
- "@cloudflare/workers-types": "^4.20250831.0",
38
+ "@cloudflare/workers-types": "^4.20251221.0",
39
39
  "zod": "^3.25.76"
40
40
  },
41
41
  "scripts": {
package/src/streaming.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { LanguageModelV2StreamPart } from "@ai-sdk/provider";
2
+ import { generateId } from "ai";
2
3
  import { events } from "fetch-event-stream";
3
4
  import { mapWorkersAIUsage } from "./map-workersai-usage";
4
5
  import { processPartialToolCalls } from "./utils";
5
- import { generateId } from "ai";
6
6
 
7
7
  export function getMappedStream(response: Response) {
8
8
  const chunkEvent = events(response);
@@ -1,4 +1,4 @@
1
- import { TooManyEmbeddingValuesForCallError, type EmbeddingModelV2 } from "@ai-sdk/provider";
1
+ import { type EmbeddingModelV2, TooManyEmbeddingValuesForCallError } from "@ai-sdk/provider";
2
2
  import type { StringLike } from "./utils";
3
3
  import type { EmbeddingModels } from "./workersai-models";
4
4
 
@@ -38,7 +38,7 @@ export class WorkersAIEmbeddingModel implements EmbeddingModelV2<string> {
38
38
 
39
39
  get maxEmbeddingsPerCall(): number {
40
40
  // https://developers.cloudflare.com/workers-ai/platform/limits/#text-embeddings
41
- const maxEmbeddingsPerCall = this.modelId === "@cf/baai/bge-large-en-v1.5" ? 1500 : 3000;
41
+ const maxEmbeddingsPerCall = 3000;
42
42
  return this.settings.maxEmbeddingsPerCall ?? maxEmbeddingsPerCall;
43
43
  }
44
44
 
@@ -74,15 +74,17 @@ export class WorkersAIEmbeddingModel implements EmbeddingModelV2<string> {
74
74
 
75
75
  const response = await this.config.binding.run(
76
76
  this.modelId,
77
- // @ts-expect-error: Error introduced with "@cloudflare/workers-types": "^4.20250617.0"
78
77
  {
79
78
  text: values,
80
79
  },
81
- { gateway: this.config.gateway ?? gateway, ...passthroughOptions },
80
+ {
81
+ gateway: this.config.gateway ?? gateway,
82
+ ...passthroughOptions,
83
+ tags: [],
84
+ },
82
85
  );
83
86
 
84
87
  return {
85
- // @ts-expect-error: Error introduced with "@cloudflare/workers-types": "^4.20250617.0"
86
88
  embeddings: response.data,
87
89
  };
88
90
  }
@@ -3,6 +3,7 @@ import type {
3
3
  LanguageModelV2CallWarning,
4
4
  LanguageModelV2StreamPart,
5
5
  } from "@ai-sdk/provider";
6
+ import { generateId } from "ai";
6
7
  import { convertToWorkersAIChatMessages } from "./convert-to-workersai-chat-messages";
7
8
  import { mapWorkersAIFinishReason } from "./map-workersai-finish-reason";
8
9
  import { mapWorkersAIUsage } from "./map-workersai-usage";
@@ -15,7 +16,6 @@ import {
15
16
  } from "./utils";
16
17
  import type { WorkersAIChatSettings } from "./workersai-chat-settings";
17
18
  import type { TextGenerationModels } from "./workersai-models";
18
- import { generateId } from "ai";
19
19
 
20
20
  type WorkersAIChatConfig = {
21
21
  provider: string;
@@ -156,7 +156,11 @@ export class WorkersAIChatLanguageModel implements LanguageModelV2 {
156
156
  // @ts-expect-error response_format not yet added to types
157
157
  response_format: args.response_format,
158
158
  },
159
- { gateway: this.config.gateway ?? gateway, ...passthroughOptions },
159
+ {
160
+ gateway: this.config.gateway ?? gateway,
161
+ ...passthroughOptions,
162
+ tags: [],
163
+ },
160
164
  );
161
165
 
162
166
  if (output instanceof ReadableStream) {
@@ -300,7 +304,11 @@ export class WorkersAIChatLanguageModel implements LanguageModelV2 {
300
304
  // @ts-expect-error response_format not yet added to types
301
305
  response_format: args.response_format,
302
306
  },
303
- { gateway: this.config.gateway ?? gateway, ...passthroughOptions },
307
+ {
308
+ gateway: this.config.gateway ?? gateway,
309
+ ...passthroughOptions,
310
+ tags: [],
311
+ },
304
312
  );
305
313
 
306
314
  if (!(response instanceof ReadableStream)) {
@@ -1,5 +1,4 @@
1
- import type { ImageModelV2 } from "@ai-sdk/provider";
2
- import type { ImageModelV2CallWarning } from "@ai-sdk/provider";
1
+ import type { ImageModelV2, ImageModelV2CallWarning } from "@ai-sdk/provider";
3
2
  import type { WorkersAIImageConfig } from "./workersai-image-config";
4
3
  import type { WorkersAIImageSettings } from "./workersai-image-settings";
5
4
  import type { ImageGenerationModels } from "./workersai-models";