workers-ai-provider 4.0.0 → 4.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.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as createResumableStream, E as wireableProviders, S as WireFormat, T as findProviderBySlug, _ as GATEWAY_PROVIDERS, a as ProviderPlugin, b as ResumableStreamOptions, c as selectTransport, d as FallbackAttempt, f as GatewayErrorCode, g as Billing, h as WorkersAIGatewayError, i as ParsedSlug, l as FallbackLeg, m as WorkersAIFallbackError, n as DispatchInfo, o as Transport, p as GatewayErrorContext, r as FallbackOptions, s as parseSlug, t as DelegateCallOptions, u as createClientFallbackModel, v as GatewayDelegateError, w as detectProviderByUrl, x as ResumeExpiredPolicy, y as GatewayProviderInfo } from "./gateway-delegate-CAX7trdL.mjs";
1
+ import { C as createResumableStream, E as wireableProviders, S as WireFormat, T as findProviderBySlug, _ as GATEWAY_PROVIDERS, a as ProviderPlugin, b as ResumableStreamOptions, c as selectTransport, d as FallbackAttempt, f as GatewayErrorCode, g as Billing, h as WorkersAIGatewayError, i as ParsedSlug, l as FallbackLeg, m as WorkersAIFallbackError, n as DispatchInfo, o as Transport, p as GatewayErrorContext, r as FallbackOptions, s as parseSlug, t as DelegateCallOptions, u as createClientFallbackModel, v as GatewayDelegateError, w as detectProviderByUrl, x as ResumeExpiredPolicy, y as GatewayProviderInfo } from "./gateway-delegate-DYjgGAa-.mjs";
2
2
  import { GatewayFetchConfig, createGatewayFetch, createGatewayProvider } from "./gateway-provider.mjs";
3
3
  import { EmbeddingModelV4, EmbeddingModelV4CallOptions, EmbeddingModelV4Result, ImageModelV4, LanguageModelV4, RerankingModelV4, SpeechModelV4, TranscriptionModelV4 } from "@ai-sdk/provider";
4
4
 
@@ -484,11 +484,40 @@ interface WorkersAI {
484
484
  }
485
485
  /**
486
486
  * Create a Workers AI provider instance.
487
+ *
488
+ * @deprecated Use `createAI` from `agents/models/ai-sdk`, with the binding or
489
+ * with an account id and API token (credentials mode's `apiKey`):
490
+ *
491
+ * ```ts
492
+ * import { createAI } from "agents/models/ai-sdk";
493
+ * const ai = createAI({ binding: env.AI }); // or { accountId, apiToken }
494
+ * ai("@cf/zai-org/glm-4.7-flash"); // was workersai("@cf/…")
495
+ * ai("anthropic/claude-opus-4.8"); // was "anthropic/…" + providers; the catalog's spelling
496
+ * ai("dynamic/support"); // dynamic routes, as before
497
+ * ai(createAnthropic({ apiKey: "cloudflare" })("claude-opus-4-8")); // a vendor's own model
498
+ * ai.embedding("@cf/baai/bge-base-en-v1.5"); // .image/.speech/.transcription/.reranking alike
499
+ * ```
500
+ *
501
+ * `vendorKey`, `byokAlias` and `zdr` cover BYOK, and through the binding a
502
+ * catalog stream resumes after a dropped connection. For AI Search, use
503
+ * `ai-search-provider`.
487
504
  */
488
505
  declare function createWorkersAI(options: WorkersAISettings): WorkersAI;
506
+ /**
507
+ * @deprecated Use `createAISearchNamespace` from `ai-search-provider`, over the
508
+ * `ai_search_namespaces` binding that replaces `env.AI.autorag()`:
509
+ * `createAISearchNamespace({ binding: env.AI_SEARCH }).get("my-instance").chat()`.
510
+ * @see https://developers.cloudflare.com/ai-search/api/migration/workers-binding/
511
+ */
489
512
  type AISearchSettings = {
490
513
  binding: AutoRAG;
491
514
  };
515
+ /**
516
+ * @deprecated Use `createAISearchNamespace` from `ai-search-provider`, over the
517
+ * `ai_search_namespaces` binding that replaces `env.AI.autorag()`:
518
+ * `createAISearchNamespace({ binding: env.AI_SEARCH }).get("my-instance").chat()`.
519
+ * @see https://developers.cloudflare.com/ai-search/api/migration/workers-binding/
520
+ */
492
521
  interface AISearchProvider {
493
522
  (settings?: AISearchChatSettings): AISearchChatLanguageModel;
494
523
  /**
@@ -500,7 +529,11 @@ interface AISearchProvider {
500
529
  * Create an AI Search provider instance.
501
530
  *
502
531
  * AI Search (formerly AutoRAG) is Cloudflare's managed search service.
503
- * @see https://developers.cloudflare.com/ai-search/
532
+ *
533
+ * @deprecated Use `createAISearchNamespace` from `ai-search-provider`, over the
534
+ * `ai_search_namespaces` binding that replaces `env.AI.autorag()`:
535
+ * `createAISearchNamespace({ binding: env.AI_SEARCH }).get("my-instance").chat()`.
536
+ * @see https://developers.cloudflare.com/ai-search/api/migration/workers-binding/
504
537
  */
505
538
  declare function createAISearch(options: AISearchSettings, /** @internal */
506
539
 
@@ -516,8 +549,9 @@ type AutoRAGSettings = AISearchSettings;
516
549
  */
517
550
  type AutoRAGProvider = AISearchProvider;
518
551
  /**
519
- * @deprecated Use `createAISearch` instead. AutoRAG has been renamed to AI Search.
520
- * @see https://developers.cloudflare.com/ai-search/
552
+ * @deprecated Use `createAISearchNamespace` from `ai-search-provider`. AutoRAG
553
+ * has been renamed to AI Search.
554
+ * @see https://developers.cloudflare.com/ai-search/api/migration/workers-binding/
521
555
  */
522
556
  declare function createAutoRAG(options: AISearchSettings): AISearchProvider;
523
557
  //#endregion
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { C as GatewayDelegateError, S as headersToObject, _ as detectProviderByUrl, a as WORKERS_AI_ERROR_CODE_TO_STATUS, b as asText, c as parseWorkersAIErrorCode, d as isForcedToolChoice, f as normalizeMessagesForBinding$1, g as GATEWAY_PROVIDERS, h as createResumableStream, i as WorkersAIGatewayError, l as SSEDecoder, m as processText, n as createGatewayProvider, o as isAbortError, p as parseLeakedToolCalls$1, r as WorkersAIFallbackError, s as messageOf, t as createGatewayFetch, u as getToolNames, v as findProviderBySlug, w as _defineProperty, x as buildGatewayEntry, y as wireableProviders } from "./gateway-provider-BIZ2bimW.mjs";
1
+ import { C as GatewayDelegateError, S as headersToObject, _ as detectProviderByUrl, a as WORKERS_AI_ERROR_CODE_TO_STATUS, b as asText, c as parseWorkersAIErrorCode, d as isForcedToolChoice, f as normalizeMessagesForBinding$1, g as GATEWAY_PROVIDERS, h as createResumableStream, i as WorkersAIGatewayError, l as SSEDecoder, m as processText, n as createGatewayProvider, o as isAbortError, p as parseLeakedToolCalls$1, r as WorkersAIFallbackError, s as messageOf, t as createGatewayFetch, u as getToolNames, v as findProviderBySlug, w as _defineProperty, x as buildGatewayEntry, y as wireableProviders } from "./gateway-provider-BQj8ZnKv.mjs";
2
2
  import { APICallError, TooManyEmbeddingValuesForCallError, UnsupportedFunctionalityError } from "@ai-sdk/provider";
3
3
  import { generateId } from "ai";
4
4
  //#region src/workersai-error.ts
@@ -1793,6 +1793,9 @@ var AutoRAGChatLanguageModel = class extends AISearchChatLanguageModel {};
1793
1793
  * Fallback triggers on `doGenerate`/`doStream` rejection (the dispatch never
1794
1794
  * produced a stream). Errors that surface *mid-stream* — after content has
1795
1795
  * already been emitted — are not recoverable here and propagate as-is.
1796
+ *
1797
+ * @deprecated Use the `fallback` option of `createAI` from
1798
+ * `agents/models/ai-sdk`: `ai(primary, { fallback: [secondary, "@cf/…"] })`.
1796
1799
  */
1797
1800
  function createClientFallbackModel(legs) {
1798
1801
  if (legs.length === 0) throw new Error("createClientFallbackModel requires at least one model leg.");
@@ -2224,6 +2227,23 @@ const DEFAULT_GATEWAY_ID = "default";
2224
2227
  const DYNAMIC_ROUTE_WIRE_FORMAT = "openai";
2225
2228
  /**
2226
2229
  * Create a Workers AI provider instance.
2230
+ *
2231
+ * @deprecated Use `createAI` from `agents/models/ai-sdk`, with the binding or
2232
+ * with an account id and API token (credentials mode's `apiKey`):
2233
+ *
2234
+ * ```ts
2235
+ * import { createAI } from "agents/models/ai-sdk";
2236
+ * const ai = createAI({ binding: env.AI }); // or { accountId, apiToken }
2237
+ * ai("@cf/zai-org/glm-4.7-flash"); // was workersai("@cf/…")
2238
+ * ai("anthropic/claude-opus-4.8"); // was "anthropic/…" + providers; the catalog's spelling
2239
+ * ai("dynamic/support"); // dynamic routes, as before
2240
+ * ai(createAnthropic({ apiKey: "cloudflare" })("claude-opus-4-8")); // a vendor's own model
2241
+ * ai.embedding("@cf/baai/bge-base-en-v1.5"); // .image/.speech/.transcription/.reranking alike
2242
+ * ```
2243
+ *
2244
+ * `vendorKey`, `byokAlias` and `zdr` cover BYOK, and through the binding a
2245
+ * catalog stream resumes after a dropped connection. For AI Search, use
2246
+ * `ai-search-provider`.
2227
2247
  */
2228
2248
  function createWorkersAI(options) {
2229
2249
  if (!options.binding && !("accountId" in options && "apiKey" in options)) throw new Error("Invalid Workers AI configuration: you must provide either a binding (e.g. { binding: env.AI }) or credentials ({ accountId, apiKey }).");
@@ -2381,7 +2401,11 @@ A gateway defaults to "default" but can be set via \`gateway\`. Otherwise use a
2381
2401
  * Create an AI Search provider instance.
2382
2402
  *
2383
2403
  * AI Search (formerly AutoRAG) is Cloudflare's managed search service.
2384
- * @see https://developers.cloudflare.com/ai-search/
2404
+ *
2405
+ * @deprecated Use `createAISearchNamespace` from `ai-search-provider`, over the
2406
+ * `ai_search_namespaces` binding that replaces `env.AI.autorag()`:
2407
+ * `createAISearchNamespace({ binding: env.AI_SEARCH }).get("my-instance").chat()`.
2408
+ * @see https://developers.cloudflare.com/ai-search/api/migration/workers-binding/
2385
2409
  */
2386
2410
  function createAISearch(options, providerName = "aisearch.chat") {
2387
2411
  const binding = options.binding;
@@ -2398,8 +2422,9 @@ function createAISearch(options, providerName = "aisearch.chat") {
2398
2422
  }
2399
2423
  let autoRAGWarned = false;
2400
2424
  /**
2401
- * @deprecated Use `createAISearch` instead. AutoRAG has been renamed to AI Search.
2402
- * @see https://developers.cloudflare.com/ai-search/
2425
+ * @deprecated Use `createAISearchNamespace` from `ai-search-provider`. AutoRAG
2426
+ * has been renamed to AI Search.
2427
+ * @see https://developers.cloudflare.com/ai-search/api/migration/workers-binding/
2403
2428
  */
2404
2429
  function createAutoRAG(options) {
2405
2430
  if (!autoRAGWarned) {