@umituz/web-ai 1.1.0 → 1.2.0

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.
Files changed (48) hide show
  1. package/README.md +29 -3
  2. package/dist/{cancellation-error-_39nYWwz.d.cts → cancellation-error-BWb59Wkj.d.cts} +1 -1
  3. package/dist/{cancellation-error-hYcE9AS9.d.ts → cancellation-error-D9LETLCD.d.ts} +1 -1
  4. package/dist/chat/index.cjs +1 -0
  5. package/dist/chat/index.cjs.map +1 -1
  6. package/dist/chat/index.js +1 -0
  7. package/dist/chat/index.js.map +1 -1
  8. package/dist/content/index.cjs +622 -8
  9. package/dist/content/index.cjs.map +1 -1
  10. package/dist/content/index.d.cts +2 -2
  11. package/dist/content/index.d.ts +2 -2
  12. package/dist/content/index.js +622 -8
  13. package/dist/content/index.js.map +1 -1
  14. package/dist/context-manager-CuZz0vnC.d.cts +104 -0
  15. package/dist/context-manager-CuZz0vnC.d.ts +104 -0
  16. package/dist/core/index.cjs +147 -10
  17. package/dist/core/index.cjs.map +1 -1
  18. package/dist/core/index.d.cts +91 -73
  19. package/dist/core/index.d.ts +91 -73
  20. package/dist/core/index.js +141 -11
  21. package/dist/core/index.js.map +1 -1
  22. package/dist/{create-ai-D-oEWzf9.d.ts → create-ai-Cq3HkJxd.d.ts} +61 -1
  23. package/dist/{create-ai-DRysRImc.d.cts → create-ai-DDyTVzef.d.cts} +61 -1
  24. package/dist/hooks/index.cjs +747 -15
  25. package/dist/hooks/index.cjs.map +1 -1
  26. package/dist/hooks/index.d.cts +57 -4
  27. package/dist/hooks/index.d.ts +57 -4
  28. package/dist/hooks/index.js +746 -16
  29. package/dist/hooks/index.js.map +1 -1
  30. package/dist/index.cjs +1180 -242
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.cts +7 -6
  33. package/dist/index.d.ts +7 -6
  34. package/dist/index.js +1140 -243
  35. package/dist/index.js.map +1 -1
  36. package/dist/providers/index.cjs +1212 -362
  37. package/dist/providers/index.cjs.map +1 -1
  38. package/dist/providers/index.d.cts +422 -10
  39. package/dist/providers/index.d.ts +422 -10
  40. package/dist/providers/index.js +1179 -363
  41. package/dist/providers/index.js.map +1 -1
  42. package/dist/remote-chat-client-LrNlew4n.d.cts +70 -0
  43. package/dist/remote-chat-client-LrNlew4n.d.ts +70 -0
  44. package/dist/{requestQueue-D89wx91Q.d.cts → requestQueue--h2uZ-Q3.d.cts} +1 -1
  45. package/dist/{requestQueue-AP6n_bRH.d.ts → requestQueue-BGeCy4Fd.d.ts} +1 -1
  46. package/package.json +1 -1
  47. package/dist/tool-call-accumulator-C7KhaXZA.d.cts +0 -69
  48. package/dist/tool-call-accumulator-C7KhaXZA.d.ts +0 -69
@@ -228,6 +228,57 @@ interface StreamRequestOptions {
228
228
  readonly signal?: AbortSignal;
229
229
  }
230
230
 
231
+ /**
232
+ * Wire-neutral config for any OpenAI-compatible chat-completions endpoint:
233
+ * OpenAI itself, Groq, OpenRouter, vLLM, LiteLLM, or a Cloudflare AI Gateway
234
+ * in front of any of them. Two URL shapes are accepted because gateways hand
235
+ * out both: `baseUrl` (the API root, `/chat/completions` appended) or
236
+ * `endpointUrl` (the complete chat-completions URL, which wins).
237
+ *
238
+ * Model choice: `model` pins every request to one id — the single-model
239
+ * gateway case; `models` maps the neutral tiers (fast/balanced/powerful) the
240
+ * way the named providers do. Explicit `model` on a request still overrides
241
+ * both, as everywhere in the package.
242
+ */
243
+ interface OpenAiCompatibleProviderConfig {
244
+ readonly apiKey: string;
245
+ readonly baseUrl?: string;
246
+ readonly endpointUrl?: string;
247
+ readonly model?: string;
248
+ readonly models?: TierModelMap;
249
+ readonly timeoutMs?: number;
250
+ }
251
+
252
+ /**
253
+ * Structural types for Cloudflare Workers AI — no @cloudflare/workers-types
254
+ * dependency, exactly like the apps that consume this package. A binding is
255
+ * "anything with run(model, input)"; the env is "anything that may carry an
256
+ * optional AI binding", so `{ AI?: ... }` app envs satisfy it as-is.
257
+ */
258
+ interface WorkersAIBinding {
259
+ run(model: string, input: Record<string, unknown>): Promise<unknown>;
260
+ }
261
+ interface WorkersAIEnv {
262
+ AI?: WorkersAIBinding;
263
+ }
264
+ /** Chat message shape the Workers AI text models speak (OpenAI convention). */
265
+ interface WorkersAIMessage {
266
+ role: 'system' | 'user' | 'assistant';
267
+ content: string;
268
+ }
269
+ /** Error carrying the provider status when one exists (route → HTTP code). */
270
+ declare class WorkersAIError extends Error {
271
+ readonly status?: number;
272
+ constructor(message: string, status?: number);
273
+ }
274
+ /** Constructor config for the class-based provider (createAI wiring). */
275
+ interface WorkersAIProviderConfig {
276
+ /** The `env.AI` binding — its presence IS the enabled flag (no apiKey). */
277
+ binding: WorkersAIBinding;
278
+ /** Per-tier model overrides; defaults live in WORKERS_AI_TIERS. */
279
+ models?: Partial<Record<TextTier, string>>;
280
+ }
281
+
231
282
  /**
232
283
  * Composition root for the whole package — replaces the old
233
284
  * `configureProvider()` singleton. A provider block's presence means the
@@ -255,7 +306,16 @@ interface AIProviderConfig {
255
306
  gemini?: Omit<GeminiConfig, "enabled">;
256
307
  fal?: Omit<FalConfig, "enabled">;
257
308
  pruna?: Omit<PrunaConfig, "enabled">;
309
+ /** Any OpenAI-compatible endpoint (OpenAI, OpenRouter, vLLM, LiteLLM,
310
+ * Cloudflare AI Gateway) addressed by URL — the gateway shape apps
311
+ * deploy behind instead of a named vendor key. */
312
+ openaiCompatible?: Omit<OpenAiCompatibleProviderConfig, "apiKey"> & {
313
+ apiKey?: string;
314
+ };
315
+ /** Cloudflare Workers AI over the `env.AI` binding — no apiKey; the
316
+ * binding's presence IS the enabled flag (free-tier text lane). */
317
+ workersAI?: WorkersAIProviderConfig;
258
318
  }
259
319
  declare function createAI(config?: AIProviderConfig): ProviderFactory;
260
320
 
261
- export { type AIProviderConfig as A, type GroqChatChunk as G, type StreamRequestOptions as S, ANTHROPIC_API_VERSION as a, ANTHROPIC_DEFAULT_MAX_TOKENS as b, ANTHROPIC_MODELS as c, ANTHROPIC_TIERS as d, type AnthropicEffort as e, type AnthropicMessagesRequest as f, type AnthropicMessagesResponse as g, type AnthropicProviderConfig as h, type AnthropicStopReason as i, type AnthropicStreamEvent as j, type GroqChatRequest as k, type GroqChatResponse as l, type GroqChoice as m, type GroqChunkChoice as n, type GroqConfig as o, type GroqErrorResponse as p, type GroqGenerationConfig as q, type GroqMessage as r, type GroqMessageRole as s, type GroqProviderConfig as t, type GroqReasoningEffort as u, type GroqUsage as v, createAI as w, type AnthropicMessage as x };
321
+ export { type AIProviderConfig as A, createAI as B, type AnthropicMessage as C, type GroqChatChunk as G, type OpenAiCompatibleProviderConfig as O, type StreamRequestOptions as S, type WorkersAIBinding as W, ANTHROPIC_API_VERSION as a, ANTHROPIC_DEFAULT_MAX_TOKENS as b, ANTHROPIC_MODELS as c, ANTHROPIC_TIERS as d, type AnthropicEffort as e, type AnthropicMessagesRequest as f, type AnthropicMessagesResponse as g, type AnthropicProviderConfig as h, type AnthropicStopReason as i, type AnthropicStreamEvent as j, type GroqChatRequest as k, type GroqChatResponse as l, type GroqChoice as m, type GroqChunkChoice as n, type GroqConfig as o, type GroqErrorResponse as p, type GroqGenerationConfig as q, type GroqMessage as r, type GroqMessageRole as s, type GroqProviderConfig as t, type GroqReasoningEffort as u, type GroqUsage as v, type WorkersAIEnv as w, WorkersAIError as x, type WorkersAIMessage as y, type WorkersAIProviderConfig as z };
@@ -228,6 +228,57 @@ interface StreamRequestOptions {
228
228
  readonly signal?: AbortSignal;
229
229
  }
230
230
 
231
+ /**
232
+ * Wire-neutral config for any OpenAI-compatible chat-completions endpoint:
233
+ * OpenAI itself, Groq, OpenRouter, vLLM, LiteLLM, or a Cloudflare AI Gateway
234
+ * in front of any of them. Two URL shapes are accepted because gateways hand
235
+ * out both: `baseUrl` (the API root, `/chat/completions` appended) or
236
+ * `endpointUrl` (the complete chat-completions URL, which wins).
237
+ *
238
+ * Model choice: `model` pins every request to one id — the single-model
239
+ * gateway case; `models` maps the neutral tiers (fast/balanced/powerful) the
240
+ * way the named providers do. Explicit `model` on a request still overrides
241
+ * both, as everywhere in the package.
242
+ */
243
+ interface OpenAiCompatibleProviderConfig {
244
+ readonly apiKey: string;
245
+ readonly baseUrl?: string;
246
+ readonly endpointUrl?: string;
247
+ readonly model?: string;
248
+ readonly models?: TierModelMap;
249
+ readonly timeoutMs?: number;
250
+ }
251
+
252
+ /**
253
+ * Structural types for Cloudflare Workers AI — no @cloudflare/workers-types
254
+ * dependency, exactly like the apps that consume this package. A binding is
255
+ * "anything with run(model, input)"; the env is "anything that may carry an
256
+ * optional AI binding", so `{ AI?: ... }` app envs satisfy it as-is.
257
+ */
258
+ interface WorkersAIBinding {
259
+ run(model: string, input: Record<string, unknown>): Promise<unknown>;
260
+ }
261
+ interface WorkersAIEnv {
262
+ AI?: WorkersAIBinding;
263
+ }
264
+ /** Chat message shape the Workers AI text models speak (OpenAI convention). */
265
+ interface WorkersAIMessage {
266
+ role: 'system' | 'user' | 'assistant';
267
+ content: string;
268
+ }
269
+ /** Error carrying the provider status when one exists (route → HTTP code). */
270
+ declare class WorkersAIError extends Error {
271
+ readonly status?: number;
272
+ constructor(message: string, status?: number);
273
+ }
274
+ /** Constructor config for the class-based provider (createAI wiring). */
275
+ interface WorkersAIProviderConfig {
276
+ /** The `env.AI` binding — its presence IS the enabled flag (no apiKey). */
277
+ binding: WorkersAIBinding;
278
+ /** Per-tier model overrides; defaults live in WORKERS_AI_TIERS. */
279
+ models?: Partial<Record<TextTier, string>>;
280
+ }
281
+
231
282
  /**
232
283
  * Composition root for the whole package — replaces the old
233
284
  * `configureProvider()` singleton. A provider block's presence means the
@@ -255,7 +306,16 @@ interface AIProviderConfig {
255
306
  gemini?: Omit<GeminiConfig, "enabled">;
256
307
  fal?: Omit<FalConfig, "enabled">;
257
308
  pruna?: Omit<PrunaConfig, "enabled">;
309
+ /** Any OpenAI-compatible endpoint (OpenAI, OpenRouter, vLLM, LiteLLM,
310
+ * Cloudflare AI Gateway) addressed by URL — the gateway shape apps
311
+ * deploy behind instead of a named vendor key. */
312
+ openaiCompatible?: Omit<OpenAiCompatibleProviderConfig, "apiKey"> & {
313
+ apiKey?: string;
314
+ };
315
+ /** Cloudflare Workers AI over the `env.AI` binding — no apiKey; the
316
+ * binding's presence IS the enabled flag (free-tier text lane). */
317
+ workersAI?: WorkersAIProviderConfig;
258
318
  }
259
319
  declare function createAI(config?: AIProviderConfig): ProviderFactory;
260
320
 
261
- export { type AIProviderConfig as A, type GroqChatChunk as G, type StreamRequestOptions as S, ANTHROPIC_API_VERSION as a, ANTHROPIC_DEFAULT_MAX_TOKENS as b, ANTHROPIC_MODELS as c, ANTHROPIC_TIERS as d, type AnthropicEffort as e, type AnthropicMessagesRequest as f, type AnthropicMessagesResponse as g, type AnthropicProviderConfig as h, type AnthropicStopReason as i, type AnthropicStreamEvent as j, type GroqChatRequest as k, type GroqChatResponse as l, type GroqChoice as m, type GroqChunkChoice as n, type GroqConfig as o, type GroqErrorResponse as p, type GroqGenerationConfig as q, type GroqMessage as r, type GroqMessageRole as s, type GroqProviderConfig as t, type GroqReasoningEffort as u, type GroqUsage as v, createAI as w, type AnthropicMessage as x };
321
+ export { type AIProviderConfig as A, createAI as B, type AnthropicMessage as C, type GroqChatChunk as G, type OpenAiCompatibleProviderConfig as O, type StreamRequestOptions as S, type WorkersAIBinding as W, ANTHROPIC_API_VERSION as a, ANTHROPIC_DEFAULT_MAX_TOKENS as b, ANTHROPIC_MODELS as c, ANTHROPIC_TIERS as d, type AnthropicEffort as e, type AnthropicMessagesRequest as f, type AnthropicMessagesResponse as g, type AnthropicProviderConfig as h, type AnthropicStopReason as i, type AnthropicStreamEvent as j, type GroqChatRequest as k, type GroqChatResponse as l, type GroqChoice as m, type GroqChunkChoice as n, type GroqConfig as o, type GroqErrorResponse as p, type GroqGenerationConfig as q, type GroqMessage as r, type GroqMessageRole as s, type GroqProviderConfig as t, type GroqReasoningEffort as u, type GroqUsage as v, type WorkersAIEnv as w, WorkersAIError as x, type WorkersAIMessage as y, type WorkersAIProviderConfig as z };