@umituz/web-ai 0.0.0-stage → 1.0.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 (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +98 -2
  3. package/dist/ABTesting-DDqNhHtP.d.ts +184 -0
  4. package/dist/ABTesting-DWBtKTMQ.d.cts +184 -0
  5. package/dist/ContentGeneration-B6iK2B33.d.cts +93 -0
  6. package/dist/ContentGeneration-B6iK2B33.d.ts +93 -0
  7. package/dist/ProviderConfig-a55tLhWT.d.cts +99 -0
  8. package/dist/ProviderConfig-a55tLhWT.d.ts +99 -0
  9. package/dist/cache-manager-Df9LLYGA.d.cts +31 -0
  10. package/dist/cache-manager-Df9LLYGA.d.ts +31 -0
  11. package/dist/chat/index.cjs +534 -0
  12. package/dist/chat/index.cjs.map +1 -0
  13. package/dist/chat/index.d.cts +25 -0
  14. package/dist/chat/index.d.ts +25 -0
  15. package/dist/chat/index.js +527 -0
  16. package/dist/chat/index.js.map +1 -0
  17. package/dist/chat.service-DBKq9I2c.d.cts +124 -0
  18. package/dist/chat.service-RQn8UTXD.d.ts +124 -0
  19. package/dist/content/index.cjs +3769 -0
  20. package/dist/content/index.cjs.map +1 -0
  21. package/dist/content/index.d.cts +225 -0
  22. package/dist/content/index.d.ts +225 -0
  23. package/dist/content/index.js +3738 -0
  24. package/dist/content/index.js.map +1 -0
  25. package/dist/core/index.cjs +1040 -0
  26. package/dist/core/index.cjs.map +1 -0
  27. package/dist/core/index.d.cts +232 -0
  28. package/dist/core/index.d.ts +232 -0
  29. package/dist/core/index.js +969 -0
  30. package/dist/core/index.js.map +1 -0
  31. package/dist/create-ai-BhNaz86i.d.ts +268 -0
  32. package/dist/create-ai-DGZFBOA1.d.cts +268 -0
  33. package/dist/hooks/index.cjs +5056 -0
  34. package/dist/hooks/index.cjs.map +1 -0
  35. package/dist/hooks/index.d.cts +210 -0
  36. package/dist/hooks/index.d.ts +210 -0
  37. package/dist/hooks/index.js +5045 -0
  38. package/dist/hooks/index.js.map +1 -0
  39. package/dist/index-DjX9ZKuM.d.cts +14 -0
  40. package/dist/index-DxLvE588.d.ts +14 -0
  41. package/dist/index-fXjxTR5W.d.cts +66 -0
  42. package/dist/index-fXjxTR5W.d.ts +66 -0
  43. package/dist/index.cjs +3158 -0
  44. package/dist/index.cjs.map +1 -0
  45. package/dist/index.d.cts +11 -0
  46. package/dist/index.d.ts +11 -0
  47. package/dist/index.js +3048 -0
  48. package/dist/index.js.map +1 -0
  49. package/dist/provider.factory-COsnprLH.d.cts +110 -0
  50. package/dist/provider.factory-CpWFyjbw.d.ts +110 -0
  51. package/dist/providers/index.cjs +2410 -0
  52. package/dist/providers/index.cjs.map +1 -0
  53. package/dist/providers/index.d.cts +333 -0
  54. package/dist/providers/index.d.ts +333 -0
  55. package/dist/providers/index.js +2376 -0
  56. package/dist/providers/index.js.map +1 -0
  57. package/dist/request-deduplicator.util-NDo0_n1y.d.cts +50 -0
  58. package/dist/request-deduplicator.util-NDo0_n1y.d.ts +50 -0
  59. package/dist/wizard/index.cjs +230 -0
  60. package/dist/wizard/index.cjs.map +1 -0
  61. package/dist/wizard/index.d.cts +86 -0
  62. package/dist/wizard/index.d.ts +86 -0
  63. package/dist/wizard/index.js +223 -0
  64. package/dist/wizard/index.js.map +1 -0
  65. package/package.json +111 -4
@@ -0,0 +1,333 @@
1
+ import { C as CostEstimateRequest, b as ITextProvider, I as IMediaProvider } from '../provider.factory-COsnprLH.cjs';
2
+ export { A as AnyProvider, a as IProviderBase, P as ProviderCapability, c as ProviderFactory, d as ProviderFactoryConfig, i as isMediaProvider, e as isTextProvider } from '../provider.factory-COsnprLH.cjs';
3
+ import { P as ProviderHealth, c as TextTier, T as TextRequest, G as GenerationResult, b as StructuredTextRequest, a as StructuredGeneration, S as StreamCallbacks, F as FinishReason, C as ChatMessage, d as TokenUsage } from '../index-fXjxTR5W.cjs';
4
+ import { q as AIError, h as AnthropicProviderConfig, e as AnthropicEffort, s as AnthropicMessage, f as AnthropicMessagesRequest, i as AnthropicStopReason, g as AnthropicMessagesResponse, n as GroqProviderConfig, m as GroqMessage, t as GroqGenerationConfig, k as GroqChatRequest, l as GroqChatResponse, S as StreamRequestOptions$1 } from '../create-ai-DGZFBOA1.cjs';
5
+ export { A as AIProviderConfig, a as ANTHROPIC_API_VERSION, b as ANTHROPIC_DEFAULT_MAX_TOKENS, c as ANTHROPIC_MODELS, d as ANTHROPIC_TIERS, j as AnthropicStreamEvent, G as GroqChatChunk, o as createAI } from '../create-ai-DGZFBOA1.cjs';
6
+ import { b as CacheStats } from '../cache-manager-Df9LLYGA.cjs';
7
+ import { a as TierModelMap } from '../index-DjX9ZKuM.cjs';
8
+ import { b as RetryManager, a as RequestQueue, R as RequestDeduplicator } from '../request-deduplicator.util-NDo0_n1y.cjs';
9
+ import { c as GeminiConfig, I as ImageGenerationRequest, G as GeneratedContent, V as VideoGenerationRequest, a as ImageToVideoRequest, b as VideoToVideoRequest, F as FalConfig, P as PrunaConfig } from '../ProviderConfig-a55tLhWT.cjs';
10
+
11
+ interface BaseProviderConfig {
12
+ apiKey: string;
13
+ baseUrl?: string;
14
+ timeout?: number;
15
+ retryAttempts?: number;
16
+ }
17
+ /**
18
+ * Convenience base for providers that talk raw fetch (gemini/fal/pruna style):
19
+ * timeout-bounded fetch plus a simple retry loop. The Groq and Anthropic
20
+ * providers bring their own transport machinery and do not extend this.
21
+ */
22
+ declare abstract class BaseProvider {
23
+ protected config: BaseProviderConfig;
24
+ constructor(config: BaseProviderConfig);
25
+ healthCheck(): Promise<ProviderHealth>;
26
+ estimateCost(_request: CostEstimateRequest): Promise<number>;
27
+ protected fetchWithTimeout(url: string, options: RequestInit, timeout?: number): Promise<Response>;
28
+ protected withRetry<T>(fn: () => Promise<T>, maxAttempts?: number): Promise<T>;
29
+ }
30
+ declare class ProviderError extends AIError {
31
+ readonly providerId: string;
32
+ constructor(message: string, providerId: string, originalError?: unknown);
33
+ }
34
+
35
+ /**
36
+ * Anthropic provider over raw fetch — no SDK dependency, Workers-safe.
37
+ * Implements the neutral ITextProvider surface with tier-based model
38
+ * resolution and full token-usage propagation.
39
+ */
40
+ declare class AnthropicProvider implements ITextProvider {
41
+ readonly config: AnthropicProviderConfig;
42
+ readonly id = "anthropic";
43
+ readonly name = "Anthropic";
44
+ readonly capabilities: readonly ["text"];
45
+ private readonly transport;
46
+ private readonly tiers;
47
+ private readonly jsonParser;
48
+ constructor(config: AnthropicProviderConfig);
49
+ resolveModel(tier: TextTier): string;
50
+ healthCheck(): Promise<ProviderHealth>;
51
+ estimateCost(): Promise<number>;
52
+ generate(request: TextRequest): Promise<GenerationResult>;
53
+ generateStructured<T>(request: StructuredTextRequest): Promise<StructuredGeneration<T>>;
54
+ stream(request: TextRequest, callbacks: StreamCallbacks): Promise<GenerationResult>;
55
+ private toGenerationResult;
56
+ }
57
+
58
+ /**
59
+ * Builds Messages API requests from neutral TextRequests.
60
+ *
61
+ * Wire rules enforced here (anthropic-version 2026-10-21):
62
+ * - `max_tokens` is always set — the API rejects requests without it.
63
+ * - temperature/top_p are NEVER emitted. This API version rejects them with
64
+ * a 400 even when copied straight from the request; they stay hints on
65
+ * TextRequest for providers that still honor sampling.
66
+ * - `systemPrompt` maps to the top-level `system` slot, not an in-band message.
67
+ * - `thinking` is omitted — adaptive thinking is the API's default.
68
+ * - `output_config.effort` defaults per model (opus/haiku medium, sonnet high)
69
+ * unless the caller pinned one on provider config.
70
+ */
71
+ declare class AnthropicRequestBuilder {
72
+ private readonly model;
73
+ private messages;
74
+ private systemPrompt;
75
+ private maxTokens;
76
+ private effort;
77
+ private stopSequences;
78
+ private streamEnabled;
79
+ constructor(model: string);
80
+ static for(model: string): AnthropicRequestBuilder;
81
+ withRequest(request: TextRequest): this;
82
+ withEffort(effort: AnthropicEffort | undefined): this;
83
+ withStream(stream: boolean): this;
84
+ withSystemPromptOverride(systemPrompt: string | undefined): this;
85
+ withMessagesOverride(messages: AnthropicMessage[]): this;
86
+ build(): AnthropicMessagesRequest;
87
+ }
88
+ declare function defaultEffortForModel(model: string): AnthropicEffort;
89
+
90
+ declare function mapAnthropicStopReason(reason: AnthropicStopReason | null | undefined): FinishReason | undefined;
91
+ interface AnthropicStreamOutcome {
92
+ readonly text: string;
93
+ readonly model: string | null;
94
+ readonly inputTokens: number | undefined;
95
+ readonly outputTokens: number | undefined;
96
+ readonly finishReason: FinishReason | undefined;
97
+ }
98
+ /**
99
+ * Line-buffered SSE consumer for Anthropic stream events. Only `data:` lines
100
+ * carry payloads (each JSON payload self-describes via `type`); `event:`
101
+ * lines are ignored as decoration. Harvests the model from message_start,
102
+ * output tokens + stop reason from message_delta, and input tokens from the
103
+ * message_start usage block, so the final GenerationResult matches the
104
+ * non-streaming shape.
105
+ */
106
+ declare function consumeAnthropicStream(stream: ReadableStream<Uint8Array>, callbacks: Pick<StreamCallbacks, "onChunk">): Promise<AnthropicStreamOutcome>;
107
+
108
+ interface StreamRequestOptions {
109
+ readonly signal?: AbortSignal;
110
+ }
111
+ /**
112
+ * Raw HTTP transport for the Anthropic Messages API (anthropic-version
113
+ * 2026-10-21). Auth is `x-api-key` — NOT a Bearer header. All failures leave
114
+ * here as core AIError with the neutral taxonomy (401→INVALID_API_KEY,
115
+ * 429→RATE_LIMIT, ≥500→SERVER, network TypeError→NETWORK, abort→ABORT).
116
+ */
117
+ declare class AnthropicHttpTransport {
118
+ private readonly config;
119
+ constructor(config: AnthropicProviderConfig);
120
+ postMessages(request: AnthropicMessagesRequest, options?: StreamRequestOptions): Promise<AnthropicMessagesResponse>;
121
+ streamMessages(request: AnthropicMessagesRequest, options?: StreamRequestOptions): Promise<ReadableStream<Uint8Array>>;
122
+ listModels(): Promise<Response>;
123
+ private baseUrl;
124
+ private buildHeaders;
125
+ private throwFromErrorResponse;
126
+ private normalizeError;
127
+ }
128
+
129
+ /**
130
+ * Groq provider over the ported machinery (dedupe/retry/queue pipeline,
131
+ * LRU+TTL response cache). Implements the neutral ITextProvider surface:
132
+ * tier-based model resolution, GenerationResult with token usage, and
133
+ * callback-based streaming.
134
+ */
135
+ declare class GroqProvider implements ITextProvider {
136
+ readonly config: GroqProviderConfig;
137
+ readonly id = "groq";
138
+ readonly name = "Groq";
139
+ readonly capabilities: readonly ["text"];
140
+ private readonly client;
141
+ private readonly tiers;
142
+ private readonly cache;
143
+ private readonly jsonParser;
144
+ constructor(config: GroqProviderConfig);
145
+ resolveModel(tier: TextTier): string;
146
+ healthCheck(): Promise<ProviderHealth>;
147
+ estimateCost(): Promise<number>;
148
+ generate(request: TextRequest): Promise<GenerationResult>;
149
+ generateStructured<T>(request: StructuredTextRequest): Promise<StructuredGeneration<T>>;
150
+ stream(request: TextRequest, callbacks: StreamCallbacks): Promise<GenerationResult>;
151
+ getCacheStats(): CacheStats;
152
+ clearCache(): void;
153
+ cancelPendingRequests(): void;
154
+ private buildWireRequest;
155
+ private generationConfig;
156
+ }
157
+ /** Maps neutral messages to Groq's wire format; systemPrompt becomes the leading system message. */
158
+ declare function toGroqMessages(messages: ReadonlyArray<ChatMessage>, systemPrompt?: string): GroqMessage[];
159
+
160
+ declare const GROQ_MODELS: {
161
+ readonly LLAMA_3_1_8B_INSTANT: "llama-3.1-8b-instant";
162
+ readonly LLAMA_3_3_70B_VERSATILE: "llama-3.3-70b-versatile";
163
+ readonly LLAMA_3_1_70B_VERSATILE: "llama-3.1-70b-versatile";
164
+ readonly GPT_OSS_20B: "openai/gpt-oss-20b";
165
+ readonly GPT_OSS_120B: "openai/gpt-oss-120b";
166
+ readonly MIXTRAL_8X7B: "mixtral-8x7b-32768";
167
+ readonly GEMMA_2_9B: "gemma2-9b-it";
168
+ readonly LLAMA_4_SCOUT_17B: "meta-llama/llama-4-scout-17b-16e-instruct";
169
+ readonly KIMI_K2_INSTRUCT: "moonshotai/kimi-k2-instruct";
170
+ readonly QWEN3_32B: "qwen/qwen3-32b";
171
+ };
172
+ /**
173
+ * Neutral tier → Groq model. fast = 8b instant for cheap high-volume turns,
174
+ * balanced = 70b versatile for everyday quality, powerful = gpt-oss-120b for
175
+ * the heavy lifting. Override per instance via `models` in provider config.
176
+ */
177
+ declare const GROQ_TIERS: TierModelMap;
178
+
179
+ declare class GroqChatRequestBuilder {
180
+ private readonly model;
181
+ private messages;
182
+ private generationConfig;
183
+ private streamEnabled;
184
+ private jsonResponse;
185
+ constructor(model: string);
186
+ static for(model: string): GroqChatRequestBuilder;
187
+ withMessages(messages: ReadonlyArray<GroqMessage>): this;
188
+ withConfig(config: GroqGenerationConfig | undefined): this;
189
+ withStream(stream: boolean): this;
190
+ withJsonResponse(enabled: boolean): this;
191
+ build(): GroqChatRequest;
192
+ }
193
+
194
+ /**
195
+ * Raw HTTP transport for Groq's OpenAI-compatible chat/completions endpoint.
196
+ * All failures leave here as core AIError with the right AIErrorType —
197
+ * callers up the stack only ever see the neutral taxonomy.
198
+ */
199
+ declare class GroqHttpTransport {
200
+ private readonly config;
201
+ private readonly pendingAbortControllers;
202
+ constructor(config: GroqProviderConfig);
203
+ cancelPendingRequests(): void;
204
+ postChatCompletion(request: GroqChatRequest): Promise<GroqChatResponse>;
205
+ streamChatCompletion(request: GroqChatRequest, options?: StreamRequestOptions$1): Promise<ReadableStream<Uint8Array>>;
206
+ private baseUrl;
207
+ private request;
208
+ private buildHeaders;
209
+ private throwFromErrorResponse;
210
+ private normalizeError;
211
+ }
212
+
213
+ interface GroqHttpClientDeps {
214
+ readonly transport?: GroqHttpTransport;
215
+ readonly retryManager?: RetryManager;
216
+ readonly queue?: RequestQueue;
217
+ readonly deduplicator?: RequestDeduplicator;
218
+ }
219
+ /**
220
+ * Groq HTTP client with the ported strategy stack: identical concurrent
221
+ * requests are deduplicated, transient failures retried with backoff, and
222
+ * everything is funneled through a priority queue. Composition root for
223
+ * GroqProvider — no global state.
224
+ */
225
+ declare class GroqHttpClient {
226
+ private readonly transport;
227
+ private readonly executor;
228
+ constructor(config: GroqProviderConfig, deps?: GroqHttpClientDeps);
229
+ cancelPendingRequests(): void;
230
+ postChatCompletion(request: GroqChatRequest): Promise<GroqChatResponse>;
231
+ streamChatCompletion(request: GroqChatRequest, options?: StreamRequestOptions$1): Promise<ReadableStream<Uint8Array>>;
232
+ }
233
+
234
+ /**
235
+ * Extracts the displayable text delta from one Groq SSE `data:` payload.
236
+ * Returns null for role-only chunks, finish-only chunks, and unparseable
237
+ * payloads — the generic line machinery skips nulls.
238
+ */
239
+ declare function extractContentFromSsePayload(payload: string): string | null;
240
+ interface GroqStreamOutcome {
241
+ readonly text: string;
242
+ readonly model: string | null;
243
+ readonly finishReason: FinishReason | undefined;
244
+ readonly usage: TokenUsage | undefined;
245
+ }
246
+ /**
247
+ * Consumes a Groq SSE body: forwards text deltas through `callbacks.onChunk`
248
+ * and harvests model/finish_reason/usage from the surrounding chunks so the
249
+ * resulting GenerationResult is as complete as the non-streaming one.
250
+ */
251
+ declare function consumeGroqStream(stream: ReadableStream<Uint8Array>, callbacks: Pick<StreamCallbacks, "onChunk">): Promise<GroqStreamOutcome>;
252
+
253
+ declare const GEMINI_TIERS: TierModelMap;
254
+ /**
255
+ * Gemini provider — text via generateContent (multi-turn aware, system
256
+ * instruction in the proper slot) plus inline image generation. Video is not
257
+ * supported by this surface and throws with a clear message.
258
+ */
259
+ declare class GeminiProvider extends BaseProvider implements ITextProvider, IMediaProvider {
260
+ readonly id = "gemini";
261
+ readonly name = "Google Gemini";
262
+ readonly capabilities: readonly ["text", "image"];
263
+ private models;
264
+ private readonly tiers;
265
+ private readonly jsonParser;
266
+ constructor(config: GeminiConfig);
267
+ resolveModel(tier: TextTier): string;
268
+ healthCheck(): Promise<ProviderHealth>;
269
+ estimateCost(request: CostEstimateRequest): Promise<number>;
270
+ generate(request: TextRequest): Promise<GenerationResult>;
271
+ generateStructured<T>(request: StructuredTextRequest): Promise<StructuredGeneration<T>>;
272
+ stream(request: TextRequest, callbacks: StreamCallbacks): Promise<GenerationResult>;
273
+ generateImage(request: ImageGenerationRequest): Promise<GeneratedContent>;
274
+ generateVideo(_request: VideoGenerationRequest): Promise<GeneratedContent>;
275
+ imageToVideo(_request: ImageToVideoRequest): Promise<GeneratedContent>;
276
+ videoToVideo(_request: VideoToVideoRequest): Promise<GeneratedContent>;
277
+ private authHeaders;
278
+ private buildImagePrompt;
279
+ }
280
+ declare function createGeminiProvider(config: GeminiConfig): GeminiProvider;
281
+
282
+ /** Media-only provider: fal.ai for image and video generation. */
283
+ declare class FalProvider extends BaseProvider implements IMediaProvider {
284
+ readonly id = "fal";
285
+ readonly name = "FAL";
286
+ readonly capabilities: readonly ["image", "video"];
287
+ private models;
288
+ constructor(config: FalConfig);
289
+ healthCheck(): Promise<ProviderHealth>;
290
+ estimateCost(request: CostEstimateRequest): Promise<number>;
291
+ generateImage(request: ImageGenerationRequest): Promise<GeneratedContent>;
292
+ generateVideo(request: VideoGenerationRequest): Promise<GeneratedContent>;
293
+ imageToVideo(request: ImageToVideoRequest): Promise<GeneratedContent>;
294
+ videoToVideo(_request: VideoToVideoRequest): Promise<GeneratedContent>;
295
+ }
296
+ declare function createFalProvider(config: FalConfig): FalProvider;
297
+
298
+ interface PrunaRequest {
299
+ model?: string;
300
+ image?: string;
301
+ [key: string]: unknown;
302
+ }
303
+ interface PrunaProgressStage {
304
+ stage: 'uploading' | 'processing' | 'polling' | 'predicting';
305
+ result?: {
306
+ url: string;
307
+ model?: string;
308
+ };
309
+ error?: Error;
310
+ }
311
+ declare function generateWithPruna(request: PrunaRequest, apiKey: string, signal?: AbortSignal, onProgress?: (stage: PrunaProgressStage['stage'], attempt?: number) => void): AsyncGenerator<PrunaProgressStage>;
312
+
313
+ /**
314
+ * Placeholder seat for the Pruna fleet: registering it makes the provider
315
+ * visible to health/fallback machinery, while actual generation goes through
316
+ * the lazy-loaded `generateWithPruna` helper (peer optional dependency).
317
+ */
318
+ declare class PrunaProvider implements IMediaProvider {
319
+ readonly config: PrunaConfig;
320
+ readonly id = "pruna";
321
+ readonly name = "Pruna AI";
322
+ readonly capabilities: readonly ["image", "video"];
323
+ constructor(config: PrunaConfig);
324
+ healthCheck(): Promise<ProviderHealth>;
325
+ estimateCost(_request: CostEstimateRequest): Promise<number>;
326
+ generateImage(_request: ImageGenerationRequest): Promise<GeneratedContent>;
327
+ generateVideo(_request: VideoGenerationRequest): Promise<GeneratedContent>;
328
+ imageToVideo(_request: ImageToVideoRequest): Promise<GeneratedContent>;
329
+ videoToVideo(_request: VideoToVideoRequest): Promise<GeneratedContent>;
330
+ }
331
+ declare function createPrunaProvider(config: PrunaConfig): PrunaProvider;
332
+
333
+ export { AnthropicEffort, AnthropicHttpTransport, AnthropicMessagesRequest, AnthropicMessagesResponse, AnthropicProvider, AnthropicProviderConfig, AnthropicRequestBuilder, AnthropicStopReason, BaseProvider, type BaseProviderConfig, CostEstimateRequest, FalProvider, GEMINI_TIERS, GROQ_MODELS, GROQ_TIERS, GeminiProvider, GroqChatRequest, GroqChatRequestBuilder, GroqChatResponse, GroqHttpClient, GroqHttpTransport, GroqMessage, GroqProvider, GroqProviderConfig, IMediaProvider, ITextProvider, ProviderError, type PrunaProgressStage, PrunaProvider, type PrunaRequest, consumeAnthropicStream, consumeGroqStream, createFalProvider, createGeminiProvider, createPrunaProvider, defaultEffortForModel, extractContentFromSsePayload, generateWithPruna, mapAnthropicStopReason, toGroqMessages };
@@ -0,0 +1,333 @@
1
+ import { C as CostEstimateRequest, b as ITextProvider, I as IMediaProvider } from '../provider.factory-CpWFyjbw.js';
2
+ export { A as AnyProvider, a as IProviderBase, P as ProviderCapability, c as ProviderFactory, d as ProviderFactoryConfig, i as isMediaProvider, e as isTextProvider } from '../provider.factory-CpWFyjbw.js';
3
+ import { P as ProviderHealth, c as TextTier, T as TextRequest, G as GenerationResult, b as StructuredTextRequest, a as StructuredGeneration, S as StreamCallbacks, F as FinishReason, C as ChatMessage, d as TokenUsage } from '../index-fXjxTR5W.js';
4
+ import { q as AIError, h as AnthropicProviderConfig, e as AnthropicEffort, s as AnthropicMessage, f as AnthropicMessagesRequest, i as AnthropicStopReason, g as AnthropicMessagesResponse, n as GroqProviderConfig, m as GroqMessage, t as GroqGenerationConfig, k as GroqChatRequest, l as GroqChatResponse, S as StreamRequestOptions$1 } from '../create-ai-BhNaz86i.js';
5
+ export { A as AIProviderConfig, a as ANTHROPIC_API_VERSION, b as ANTHROPIC_DEFAULT_MAX_TOKENS, c as ANTHROPIC_MODELS, d as ANTHROPIC_TIERS, j as AnthropicStreamEvent, G as GroqChatChunk, o as createAI } from '../create-ai-BhNaz86i.js';
6
+ import { b as CacheStats } from '../cache-manager-Df9LLYGA.js';
7
+ import { a as TierModelMap } from '../index-DxLvE588.js';
8
+ import { b as RetryManager, a as RequestQueue, R as RequestDeduplicator } from '../request-deduplicator.util-NDo0_n1y.js';
9
+ import { c as GeminiConfig, I as ImageGenerationRequest, G as GeneratedContent, V as VideoGenerationRequest, a as ImageToVideoRequest, b as VideoToVideoRequest, F as FalConfig, P as PrunaConfig } from '../ProviderConfig-a55tLhWT.js';
10
+
11
+ interface BaseProviderConfig {
12
+ apiKey: string;
13
+ baseUrl?: string;
14
+ timeout?: number;
15
+ retryAttempts?: number;
16
+ }
17
+ /**
18
+ * Convenience base for providers that talk raw fetch (gemini/fal/pruna style):
19
+ * timeout-bounded fetch plus a simple retry loop. The Groq and Anthropic
20
+ * providers bring their own transport machinery and do not extend this.
21
+ */
22
+ declare abstract class BaseProvider {
23
+ protected config: BaseProviderConfig;
24
+ constructor(config: BaseProviderConfig);
25
+ healthCheck(): Promise<ProviderHealth>;
26
+ estimateCost(_request: CostEstimateRequest): Promise<number>;
27
+ protected fetchWithTimeout(url: string, options: RequestInit, timeout?: number): Promise<Response>;
28
+ protected withRetry<T>(fn: () => Promise<T>, maxAttempts?: number): Promise<T>;
29
+ }
30
+ declare class ProviderError extends AIError {
31
+ readonly providerId: string;
32
+ constructor(message: string, providerId: string, originalError?: unknown);
33
+ }
34
+
35
+ /**
36
+ * Anthropic provider over raw fetch — no SDK dependency, Workers-safe.
37
+ * Implements the neutral ITextProvider surface with tier-based model
38
+ * resolution and full token-usage propagation.
39
+ */
40
+ declare class AnthropicProvider implements ITextProvider {
41
+ readonly config: AnthropicProviderConfig;
42
+ readonly id = "anthropic";
43
+ readonly name = "Anthropic";
44
+ readonly capabilities: readonly ["text"];
45
+ private readonly transport;
46
+ private readonly tiers;
47
+ private readonly jsonParser;
48
+ constructor(config: AnthropicProviderConfig);
49
+ resolveModel(tier: TextTier): string;
50
+ healthCheck(): Promise<ProviderHealth>;
51
+ estimateCost(): Promise<number>;
52
+ generate(request: TextRequest): Promise<GenerationResult>;
53
+ generateStructured<T>(request: StructuredTextRequest): Promise<StructuredGeneration<T>>;
54
+ stream(request: TextRequest, callbacks: StreamCallbacks): Promise<GenerationResult>;
55
+ private toGenerationResult;
56
+ }
57
+
58
+ /**
59
+ * Builds Messages API requests from neutral TextRequests.
60
+ *
61
+ * Wire rules enforced here (anthropic-version 2026-10-21):
62
+ * - `max_tokens` is always set — the API rejects requests without it.
63
+ * - temperature/top_p are NEVER emitted. This API version rejects them with
64
+ * a 400 even when copied straight from the request; they stay hints on
65
+ * TextRequest for providers that still honor sampling.
66
+ * - `systemPrompt` maps to the top-level `system` slot, not an in-band message.
67
+ * - `thinking` is omitted — adaptive thinking is the API's default.
68
+ * - `output_config.effort` defaults per model (opus/haiku medium, sonnet high)
69
+ * unless the caller pinned one on provider config.
70
+ */
71
+ declare class AnthropicRequestBuilder {
72
+ private readonly model;
73
+ private messages;
74
+ private systemPrompt;
75
+ private maxTokens;
76
+ private effort;
77
+ private stopSequences;
78
+ private streamEnabled;
79
+ constructor(model: string);
80
+ static for(model: string): AnthropicRequestBuilder;
81
+ withRequest(request: TextRequest): this;
82
+ withEffort(effort: AnthropicEffort | undefined): this;
83
+ withStream(stream: boolean): this;
84
+ withSystemPromptOverride(systemPrompt: string | undefined): this;
85
+ withMessagesOverride(messages: AnthropicMessage[]): this;
86
+ build(): AnthropicMessagesRequest;
87
+ }
88
+ declare function defaultEffortForModel(model: string): AnthropicEffort;
89
+
90
+ declare function mapAnthropicStopReason(reason: AnthropicStopReason | null | undefined): FinishReason | undefined;
91
+ interface AnthropicStreamOutcome {
92
+ readonly text: string;
93
+ readonly model: string | null;
94
+ readonly inputTokens: number | undefined;
95
+ readonly outputTokens: number | undefined;
96
+ readonly finishReason: FinishReason | undefined;
97
+ }
98
+ /**
99
+ * Line-buffered SSE consumer for Anthropic stream events. Only `data:` lines
100
+ * carry payloads (each JSON payload self-describes via `type`); `event:`
101
+ * lines are ignored as decoration. Harvests the model from message_start,
102
+ * output tokens + stop reason from message_delta, and input tokens from the
103
+ * message_start usage block, so the final GenerationResult matches the
104
+ * non-streaming shape.
105
+ */
106
+ declare function consumeAnthropicStream(stream: ReadableStream<Uint8Array>, callbacks: Pick<StreamCallbacks, "onChunk">): Promise<AnthropicStreamOutcome>;
107
+
108
+ interface StreamRequestOptions {
109
+ readonly signal?: AbortSignal;
110
+ }
111
+ /**
112
+ * Raw HTTP transport for the Anthropic Messages API (anthropic-version
113
+ * 2026-10-21). Auth is `x-api-key` — NOT a Bearer header. All failures leave
114
+ * here as core AIError with the neutral taxonomy (401→INVALID_API_KEY,
115
+ * 429→RATE_LIMIT, ≥500→SERVER, network TypeError→NETWORK, abort→ABORT).
116
+ */
117
+ declare class AnthropicHttpTransport {
118
+ private readonly config;
119
+ constructor(config: AnthropicProviderConfig);
120
+ postMessages(request: AnthropicMessagesRequest, options?: StreamRequestOptions): Promise<AnthropicMessagesResponse>;
121
+ streamMessages(request: AnthropicMessagesRequest, options?: StreamRequestOptions): Promise<ReadableStream<Uint8Array>>;
122
+ listModels(): Promise<Response>;
123
+ private baseUrl;
124
+ private buildHeaders;
125
+ private throwFromErrorResponse;
126
+ private normalizeError;
127
+ }
128
+
129
+ /**
130
+ * Groq provider over the ported machinery (dedupe/retry/queue pipeline,
131
+ * LRU+TTL response cache). Implements the neutral ITextProvider surface:
132
+ * tier-based model resolution, GenerationResult with token usage, and
133
+ * callback-based streaming.
134
+ */
135
+ declare class GroqProvider implements ITextProvider {
136
+ readonly config: GroqProviderConfig;
137
+ readonly id = "groq";
138
+ readonly name = "Groq";
139
+ readonly capabilities: readonly ["text"];
140
+ private readonly client;
141
+ private readonly tiers;
142
+ private readonly cache;
143
+ private readonly jsonParser;
144
+ constructor(config: GroqProviderConfig);
145
+ resolveModel(tier: TextTier): string;
146
+ healthCheck(): Promise<ProviderHealth>;
147
+ estimateCost(): Promise<number>;
148
+ generate(request: TextRequest): Promise<GenerationResult>;
149
+ generateStructured<T>(request: StructuredTextRequest): Promise<StructuredGeneration<T>>;
150
+ stream(request: TextRequest, callbacks: StreamCallbacks): Promise<GenerationResult>;
151
+ getCacheStats(): CacheStats;
152
+ clearCache(): void;
153
+ cancelPendingRequests(): void;
154
+ private buildWireRequest;
155
+ private generationConfig;
156
+ }
157
+ /** Maps neutral messages to Groq's wire format; systemPrompt becomes the leading system message. */
158
+ declare function toGroqMessages(messages: ReadonlyArray<ChatMessage>, systemPrompt?: string): GroqMessage[];
159
+
160
+ declare const GROQ_MODELS: {
161
+ readonly LLAMA_3_1_8B_INSTANT: "llama-3.1-8b-instant";
162
+ readonly LLAMA_3_3_70B_VERSATILE: "llama-3.3-70b-versatile";
163
+ readonly LLAMA_3_1_70B_VERSATILE: "llama-3.1-70b-versatile";
164
+ readonly GPT_OSS_20B: "openai/gpt-oss-20b";
165
+ readonly GPT_OSS_120B: "openai/gpt-oss-120b";
166
+ readonly MIXTRAL_8X7B: "mixtral-8x7b-32768";
167
+ readonly GEMMA_2_9B: "gemma2-9b-it";
168
+ readonly LLAMA_4_SCOUT_17B: "meta-llama/llama-4-scout-17b-16e-instruct";
169
+ readonly KIMI_K2_INSTRUCT: "moonshotai/kimi-k2-instruct";
170
+ readonly QWEN3_32B: "qwen/qwen3-32b";
171
+ };
172
+ /**
173
+ * Neutral tier → Groq model. fast = 8b instant for cheap high-volume turns,
174
+ * balanced = 70b versatile for everyday quality, powerful = gpt-oss-120b for
175
+ * the heavy lifting. Override per instance via `models` in provider config.
176
+ */
177
+ declare const GROQ_TIERS: TierModelMap;
178
+
179
+ declare class GroqChatRequestBuilder {
180
+ private readonly model;
181
+ private messages;
182
+ private generationConfig;
183
+ private streamEnabled;
184
+ private jsonResponse;
185
+ constructor(model: string);
186
+ static for(model: string): GroqChatRequestBuilder;
187
+ withMessages(messages: ReadonlyArray<GroqMessage>): this;
188
+ withConfig(config: GroqGenerationConfig | undefined): this;
189
+ withStream(stream: boolean): this;
190
+ withJsonResponse(enabled: boolean): this;
191
+ build(): GroqChatRequest;
192
+ }
193
+
194
+ /**
195
+ * Raw HTTP transport for Groq's OpenAI-compatible chat/completions endpoint.
196
+ * All failures leave here as core AIError with the right AIErrorType —
197
+ * callers up the stack only ever see the neutral taxonomy.
198
+ */
199
+ declare class GroqHttpTransport {
200
+ private readonly config;
201
+ private readonly pendingAbortControllers;
202
+ constructor(config: GroqProviderConfig);
203
+ cancelPendingRequests(): void;
204
+ postChatCompletion(request: GroqChatRequest): Promise<GroqChatResponse>;
205
+ streamChatCompletion(request: GroqChatRequest, options?: StreamRequestOptions$1): Promise<ReadableStream<Uint8Array>>;
206
+ private baseUrl;
207
+ private request;
208
+ private buildHeaders;
209
+ private throwFromErrorResponse;
210
+ private normalizeError;
211
+ }
212
+
213
+ interface GroqHttpClientDeps {
214
+ readonly transport?: GroqHttpTransport;
215
+ readonly retryManager?: RetryManager;
216
+ readonly queue?: RequestQueue;
217
+ readonly deduplicator?: RequestDeduplicator;
218
+ }
219
+ /**
220
+ * Groq HTTP client with the ported strategy stack: identical concurrent
221
+ * requests are deduplicated, transient failures retried with backoff, and
222
+ * everything is funneled through a priority queue. Composition root for
223
+ * GroqProvider — no global state.
224
+ */
225
+ declare class GroqHttpClient {
226
+ private readonly transport;
227
+ private readonly executor;
228
+ constructor(config: GroqProviderConfig, deps?: GroqHttpClientDeps);
229
+ cancelPendingRequests(): void;
230
+ postChatCompletion(request: GroqChatRequest): Promise<GroqChatResponse>;
231
+ streamChatCompletion(request: GroqChatRequest, options?: StreamRequestOptions$1): Promise<ReadableStream<Uint8Array>>;
232
+ }
233
+
234
+ /**
235
+ * Extracts the displayable text delta from one Groq SSE `data:` payload.
236
+ * Returns null for role-only chunks, finish-only chunks, and unparseable
237
+ * payloads — the generic line machinery skips nulls.
238
+ */
239
+ declare function extractContentFromSsePayload(payload: string): string | null;
240
+ interface GroqStreamOutcome {
241
+ readonly text: string;
242
+ readonly model: string | null;
243
+ readonly finishReason: FinishReason | undefined;
244
+ readonly usage: TokenUsage | undefined;
245
+ }
246
+ /**
247
+ * Consumes a Groq SSE body: forwards text deltas through `callbacks.onChunk`
248
+ * and harvests model/finish_reason/usage from the surrounding chunks so the
249
+ * resulting GenerationResult is as complete as the non-streaming one.
250
+ */
251
+ declare function consumeGroqStream(stream: ReadableStream<Uint8Array>, callbacks: Pick<StreamCallbacks, "onChunk">): Promise<GroqStreamOutcome>;
252
+
253
+ declare const GEMINI_TIERS: TierModelMap;
254
+ /**
255
+ * Gemini provider — text via generateContent (multi-turn aware, system
256
+ * instruction in the proper slot) plus inline image generation. Video is not
257
+ * supported by this surface and throws with a clear message.
258
+ */
259
+ declare class GeminiProvider extends BaseProvider implements ITextProvider, IMediaProvider {
260
+ readonly id = "gemini";
261
+ readonly name = "Google Gemini";
262
+ readonly capabilities: readonly ["text", "image"];
263
+ private models;
264
+ private readonly tiers;
265
+ private readonly jsonParser;
266
+ constructor(config: GeminiConfig);
267
+ resolveModel(tier: TextTier): string;
268
+ healthCheck(): Promise<ProviderHealth>;
269
+ estimateCost(request: CostEstimateRequest): Promise<number>;
270
+ generate(request: TextRequest): Promise<GenerationResult>;
271
+ generateStructured<T>(request: StructuredTextRequest): Promise<StructuredGeneration<T>>;
272
+ stream(request: TextRequest, callbacks: StreamCallbacks): Promise<GenerationResult>;
273
+ generateImage(request: ImageGenerationRequest): Promise<GeneratedContent>;
274
+ generateVideo(_request: VideoGenerationRequest): Promise<GeneratedContent>;
275
+ imageToVideo(_request: ImageToVideoRequest): Promise<GeneratedContent>;
276
+ videoToVideo(_request: VideoToVideoRequest): Promise<GeneratedContent>;
277
+ private authHeaders;
278
+ private buildImagePrompt;
279
+ }
280
+ declare function createGeminiProvider(config: GeminiConfig): GeminiProvider;
281
+
282
+ /** Media-only provider: fal.ai for image and video generation. */
283
+ declare class FalProvider extends BaseProvider implements IMediaProvider {
284
+ readonly id = "fal";
285
+ readonly name = "FAL";
286
+ readonly capabilities: readonly ["image", "video"];
287
+ private models;
288
+ constructor(config: FalConfig);
289
+ healthCheck(): Promise<ProviderHealth>;
290
+ estimateCost(request: CostEstimateRequest): Promise<number>;
291
+ generateImage(request: ImageGenerationRequest): Promise<GeneratedContent>;
292
+ generateVideo(request: VideoGenerationRequest): Promise<GeneratedContent>;
293
+ imageToVideo(request: ImageToVideoRequest): Promise<GeneratedContent>;
294
+ videoToVideo(_request: VideoToVideoRequest): Promise<GeneratedContent>;
295
+ }
296
+ declare function createFalProvider(config: FalConfig): FalProvider;
297
+
298
+ interface PrunaRequest {
299
+ model?: string;
300
+ image?: string;
301
+ [key: string]: unknown;
302
+ }
303
+ interface PrunaProgressStage {
304
+ stage: 'uploading' | 'processing' | 'polling' | 'predicting';
305
+ result?: {
306
+ url: string;
307
+ model?: string;
308
+ };
309
+ error?: Error;
310
+ }
311
+ declare function generateWithPruna(request: PrunaRequest, apiKey: string, signal?: AbortSignal, onProgress?: (stage: PrunaProgressStage['stage'], attempt?: number) => void): AsyncGenerator<PrunaProgressStage>;
312
+
313
+ /**
314
+ * Placeholder seat for the Pruna fleet: registering it makes the provider
315
+ * visible to health/fallback machinery, while actual generation goes through
316
+ * the lazy-loaded `generateWithPruna` helper (peer optional dependency).
317
+ */
318
+ declare class PrunaProvider implements IMediaProvider {
319
+ readonly config: PrunaConfig;
320
+ readonly id = "pruna";
321
+ readonly name = "Pruna AI";
322
+ readonly capabilities: readonly ["image", "video"];
323
+ constructor(config: PrunaConfig);
324
+ healthCheck(): Promise<ProviderHealth>;
325
+ estimateCost(_request: CostEstimateRequest): Promise<number>;
326
+ generateImage(_request: ImageGenerationRequest): Promise<GeneratedContent>;
327
+ generateVideo(_request: VideoGenerationRequest): Promise<GeneratedContent>;
328
+ imageToVideo(_request: ImageToVideoRequest): Promise<GeneratedContent>;
329
+ videoToVideo(_request: VideoToVideoRequest): Promise<GeneratedContent>;
330
+ }
331
+ declare function createPrunaProvider(config: PrunaConfig): PrunaProvider;
332
+
333
+ export { AnthropicEffort, AnthropicHttpTransport, AnthropicMessagesRequest, AnthropicMessagesResponse, AnthropicProvider, AnthropicProviderConfig, AnthropicRequestBuilder, AnthropicStopReason, BaseProvider, type BaseProviderConfig, CostEstimateRequest, FalProvider, GEMINI_TIERS, GROQ_MODELS, GROQ_TIERS, GeminiProvider, GroqChatRequest, GroqChatRequestBuilder, GroqChatResponse, GroqHttpClient, GroqHttpTransport, GroqMessage, GroqProvider, GroqProviderConfig, IMediaProvider, ITextProvider, ProviderError, type PrunaProgressStage, PrunaProvider, type PrunaRequest, consumeAnthropicStream, consumeGroqStream, createFalProvider, createGeminiProvider, createPrunaProvider, defaultEffortForModel, extractContentFromSsePayload, generateWithPruna, mapAnthropicStopReason, toGroqMessages };