@umituz/web-ai-groq-provider 1.1.13 → 2.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 (55) hide show
  1. package/README.md +154 -72
  2. package/dist/domains/chat/index.cjs +539 -0
  3. package/dist/domains/chat/index.cjs.map +1 -0
  4. package/dist/domains/chat/index.d.cts +322 -0
  5. package/dist/domains/chat/index.d.ts +322 -0
  6. package/dist/domains/chat/index.js +531 -0
  7. package/dist/domains/chat/index.js.map +1 -0
  8. package/dist/domains/groq/index.cjs +1499 -0
  9. package/dist/domains/groq/index.cjs.map +1 -0
  10. package/dist/domains/groq/index.d.cts +561 -0
  11. package/dist/domains/groq/index.d.ts +561 -0
  12. package/dist/domains/groq/index.js +1453 -0
  13. package/dist/domains/groq/index.js.map +1 -0
  14. package/dist/index.cjs +1993 -0
  15. package/dist/index.cjs.map +1 -0
  16. package/dist/index.d.cts +53 -0
  17. package/dist/index.d.ts +53 -0
  18. package/dist/index.js +1937 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/text-generation.service-BP4Q_SH0.d.cts +252 -0
  21. package/dist/text-generation.service-BP4Q_SH0.d.ts +252 -0
  22. package/package.json +25 -11
  23. package/src/domains/chat/entities/chat.entities.ts +0 -113
  24. package/src/domains/chat/entities/index.ts +0 -14
  25. package/src/domains/chat/hooks/index.ts +0 -5
  26. package/src/domains/chat/hooks/use-chat.hook.ts +0 -259
  27. package/src/domains/chat/index.ts +0 -32
  28. package/src/domains/chat/interfaces/chat.interface.ts +0 -80
  29. package/src/domains/chat/interfaces/index.ts +0 -10
  30. package/src/domains/chat/services/chat.service.ts +0 -195
  31. package/src/domains/chat/services/index.ts +0 -5
  32. package/src/domains/chat/utils/message-formatter.ts +0 -49
  33. package/src/domains/groq/constants/error.constants.ts +0 -46
  34. package/src/domains/groq/constants/groq.constants.ts +0 -68
  35. package/src/domains/groq/constants/index.ts +0 -20
  36. package/src/domains/groq/entities/groq.entities.ts +0 -196
  37. package/src/domains/groq/entities/index.ts +0 -20
  38. package/src/domains/groq/hooks/index.ts +0 -7
  39. package/src/domains/groq/hooks/use-groq.hook.ts +0 -232
  40. package/src/domains/groq/index.ts +0 -72
  41. package/src/domains/groq/interfaces/groq.interface.ts +0 -77
  42. package/src/domains/groq/interfaces/index.ts +0 -22
  43. package/src/domains/groq/services/http-client.service.ts +0 -265
  44. package/src/domains/groq/services/index.ts +0 -9
  45. package/src/domains/groq/services/text-generation.service.ts +0 -238
  46. package/src/domains/groq/utils/cache-manager.util.ts +0 -215
  47. package/src/domains/groq/utils/debounce.util.ts +0 -268
  48. package/src/domains/groq/utils/error.util.ts +0 -57
  49. package/src/domains/groq/utils/groq-error.util.ts +0 -18
  50. package/src/domains/groq/utils/index.ts +0 -37
  51. package/src/domains/groq/utils/message.util.ts +0 -57
  52. package/src/domains/groq/utils/request-deduplicator.util.ts +0 -123
  53. package/src/domains/groq/utils/request-queue.util.ts +0 -178
  54. package/src/domains/groq/utils/retry.util.ts +0 -207
  55. package/src/index.ts +0 -15
@@ -0,0 +1,561 @@
1
+ import { G as GroqConfig, d as GroqChatRequest, e as GroqChatResponse, n as IGroqHttpClient, T as TextGenerationService, j as GroqGenerationConfig, C as CacheManager, b as CacheStats, k as GroqMessage, l as GroqMessageRole } from '../../text-generation.service-BP4Q_SH0.cjs';
2
+ export { a as CacheOptions, c as GroqChatChunk, f as GroqChoice, g as GroqChunkChoice, h as GroqErrorResponse, i as GroqFinishReason, m as GroqUsage, I as IGroqChatService, S as StreamingCallbacks, o as StructuredGenerationOptions, p as TextGenerationOptions, q as cacheManager } from '../../text-generation.service-BP4Q_SH0.cjs';
3
+
4
+ /**
5
+ * Groq Config Store
6
+ * @description Single source of truth for the active GroqConfig.
7
+ * Delegates key validation → validators/api-key-validator.
8
+ */
9
+
10
+ declare class GroqConfigStore {
11
+ private config;
12
+ /**
13
+ * Validate and persist the given config. Cancels any prior state
14
+ * by overwriting (callers that need atomicity should use `reset()` first).
15
+ *
16
+ * @throws GroqError with type `INVALID_API_KEY` if validation fails.
17
+ */
18
+ initialize(config: GroqConfig): GroqConfig;
19
+ /**
20
+ * Returns the active config or throws if not initialized.
21
+ *
22
+ * @throws GroqError with type `MISSING_CONFIG` when not initialized.
23
+ */
24
+ get(): GroqConfig;
25
+ getOrNull(): GroqConfig | null;
26
+ isInitialized(): boolean;
27
+ /**
28
+ * Replace the API key.
29
+ *
30
+ * @throws GroqError with type `MISSING_CONFIG` if not initialized,
31
+ * or `INVALID_API_KEY` if the new key fails validation.
32
+ */
33
+ setApiKey(apiKey: string): void;
34
+ reset(): void;
35
+ }
36
+
37
+ /**
38
+ * Groq HTTP Transport
39
+ * @description Low-level transport. Delegates:
40
+ * - error body parsing → extractors/response-error-message-extractor
41
+ * - status classification → validators/http-status-classifier
42
+ */
43
+
44
+ declare class GroqHttpTransport {
45
+ private readonly configStore;
46
+ private readonly pendingAbortControllers;
47
+ constructor(configStore: GroqConfigStore);
48
+ cancelPendingRequests(): void;
49
+ postChatCompletion(request: GroqChatRequest): Promise<GroqChatResponse>;
50
+ streamChatCompletion(request: GroqChatRequest): Promise<ReadableStream<Uint8Array>>;
51
+ private request;
52
+ private buildHeaders;
53
+ private throwFromErrorResponse;
54
+ private normalizeError;
55
+ }
56
+
57
+ /**
58
+ * Request Deduplicator Utility
59
+ * @description Prevents duplicate in-flight API calls for the same request
60
+ */
61
+ declare class RequestDeduplicator {
62
+ private readonly pendingRequests;
63
+ private readonly ttl;
64
+ constructor(ttl?: number);
65
+ execute<T>(key: string, requestFn: () => Promise<T>): Promise<T>;
66
+ cancelAll(): void;
67
+ private cleanup;
68
+ }
69
+ declare const requestDeduplicator: RequestDeduplicator;
70
+
71
+ /**
72
+ * Request Queue Manager Utility
73
+ * @description Manages concurrent requests with priority and limits
74
+ */
75
+ interface QueueOptions {
76
+ readonly maxConcurrent?: number;
77
+ readonly defaultPriority?: number;
78
+ readonly requestTimeout?: number;
79
+ }
80
+ declare class RequestQueue {
81
+ private queue;
82
+ private readonly activeRequests;
83
+ private readonly maxConcurrent;
84
+ private readonly defaultPriority;
85
+ private readonly requestTimeout;
86
+ private requestIdCounter;
87
+ constructor(options?: QueueOptions);
88
+ add<T>(requestFn: () => Promise<T>, priority?: number): Promise<T>;
89
+ cancelAll(): void;
90
+ private sortQueue;
91
+ private process;
92
+ private executeRequest;
93
+ }
94
+ declare const requestQueue: RequestQueue;
95
+
96
+ /**
97
+ * Retry Manager
98
+ * @description Orchestrates retry logic for failed requests. Delegates
99
+ * the actual delay math → calculations/exponential-backoff
100
+ * and the error classification → validators/error-classifier.
101
+ * No hardcoded values; all rules are explicit parameters.
102
+ */
103
+ interface RetryOptions {
104
+ readonly maxAttempts?: number;
105
+ readonly initialDelay?: number;
106
+ readonly maxDelay?: number;
107
+ readonly backoffMultiplier?: number;
108
+ readonly jitterFactor?: number;
109
+ /** Custom retry predicate; bypasses the default error-type classifier. */
110
+ readonly shouldRetry?: (error: Error) => boolean;
111
+ }
112
+ declare class RetryManager {
113
+ private readonly defaults;
114
+ constructor();
115
+ execute<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
116
+ private shouldRetry;
117
+ private delay;
118
+ }
119
+ declare const retryManager: RetryManager;
120
+ /** Convenience function: execute `fn` with the default retry manager. */
121
+ declare function withRetry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
122
+
123
+ /**
124
+ * Groq HTTP Client
125
+ * @description Facade that wires the transport together with the
126
+ * request executor strategies (retry, queue, deduplication).
127
+ */
128
+
129
+ interface GroqHttpClientDeps {
130
+ readonly configStore?: GroqConfigStore;
131
+ readonly transport?: GroqHttpTransport;
132
+ readonly retryManager?: RetryManager;
133
+ readonly queue?: RequestQueue;
134
+ readonly deduplicator?: RequestDeduplicator;
135
+ }
136
+ declare class GroqHttpClient implements IGroqHttpClient {
137
+ private readonly configStore;
138
+ private readonly transport;
139
+ private readonly executor;
140
+ constructor(deps?: GroqHttpClientDeps);
141
+ initialize(config: GroqConfig): void;
142
+ cancelPendingRequests(): void;
143
+ isInitialized(): boolean;
144
+ getApiKey(): string;
145
+ setApiKey(apiKey: string): void;
146
+ postChatCompletion(request: GroqChatRequest): Promise<GroqChatResponse>;
147
+ streamChatCompletion(request: GroqChatRequest): Promise<ReadableStream<Uint8Array>>;
148
+ reset(): void;
149
+ }
150
+
151
+ /**
152
+ * useGroq Hook
153
+ * @description React hook for Groq text generation.
154
+ * Each component instance owns its own AbortController
155
+ * so unmounting one component does NOT cancel requests
156
+ * issued by other consumers. Use `cancel()` to abort
157
+ * an in-flight request from the same component.
158
+ *
159
+ * @example
160
+ * ```tsx
161
+ * import { useGroq, getProvider } from "@umituz/web-ai-groq-provider";
162
+ *
163
+ * function MyComponent() {
164
+ * const { generate, isLoading, error, result, cancel } = useGroq(
165
+ * { model: "llama-3.3-70b-versatile" },
166
+ * { textGeneration: getProvider()!.textGeneration },
167
+ * );
168
+ * // ...
169
+ * }
170
+ * ```
171
+ */
172
+
173
+ interface UseGroqOptions {
174
+ readonly model?: string;
175
+ readonly generationConfig?: GroqGenerationConfig;
176
+ readonly onStart?: () => void;
177
+ readonly onSuccess?: (result: string) => void;
178
+ readonly onError?: (error: string) => void;
179
+ }
180
+ interface UseGroqReturn {
181
+ readonly isLoading: boolean;
182
+ readonly error: string | null;
183
+ readonly result: string | null;
184
+ /** Generate a completion from a single prompt. */
185
+ generate: (prompt: string, options?: GroqGenerationConfig) => Promise<string | null>;
186
+ /** Generate a structured JSON completion. */
187
+ generateJSON: <T = Record<string, unknown>>(prompt: string, options?: GroqGenerationConfig & {
188
+ schema?: Record<string, unknown>;
189
+ }) => Promise<T | null>;
190
+ /** Stream a completion. Returns the full text. */
191
+ stream: (prompt: string, onChunk: (chunk: string) => void, options?: GroqGenerationConfig) => Promise<string | null>;
192
+ /** Cancel any in-flight request issued by this hook instance. */
193
+ cancel: () => void;
194
+ /** Reset the hook state to its initial values. Does not clear the cache. */
195
+ reset: () => void;
196
+ /** Clear the error state. */
197
+ clearError: () => void;
198
+ }
199
+ interface UseGroqDeps {
200
+ readonly textGeneration: TextGenerationService;
201
+ }
202
+ declare function useGroq(options?: UseGroqOptions, deps?: UseGroqDeps): UseGroqReturn;
203
+
204
+ /**
205
+ * useCacheStats Hook
206
+ * @description React hook that exposes dynamic, real-time statistics
207
+ * of the active CacheManager. The numbers are computed
208
+ * on every interval tick — no value is hardcoded.
209
+ *
210
+ * @example
211
+ * ```tsx
212
+ * function CacheDebug() {
213
+ * const stats = useCacheStats({ pollIntervalMs: 2000 });
214
+ * return <pre>{JSON.stringify(stats, null, 2)}</pre>;
215
+ * }
216
+ * ```
217
+ */
218
+
219
+ interface UseCacheStatsOptions {
220
+ /** Polling interval in milliseconds. Default 1000. */
221
+ readonly pollIntervalMs?: number;
222
+ /** When false, polling is paused and the last snapshot is returned. */
223
+ readonly enabled?: boolean;
224
+ }
225
+ declare function useCacheStats(cache: CacheManager, options?: UseCacheStatsOptions): CacheStats;
226
+
227
+ /**
228
+ * Groq Constants
229
+ * @description Available models and default configurations
230
+ */
231
+ /**
232
+ * Available Groq models
233
+ */
234
+ declare const GROQ_MODELS: {
235
+ /** Llama 3.1 8B - Fast and efficient (560 T/s) */
236
+ readonly LLAMA_3_1_8B_INSTANT: "llama-3.1-8b-instant";
237
+ /** Llama 3.3 70B - Versatile and powerful (280 T/s) */
238
+ readonly LLAMA_3_3_70B_VERSATILE: "llama-3.3-70b-versatile";
239
+ /** Llama 3.1 70B - Versatile (280 T/s) */
240
+ readonly LLAMA_3_1_70B_VERSATILE: "llama-3.1-70b-versatile";
241
+ /** GPT-OSS 20B - Experimental (1000 T/s) */
242
+ readonly GPT_OSS_20B: "openai/gpt-oss-20b";
243
+ /** GPT-OSS 120B - Large experimental model */
244
+ readonly GPT_OSS_120B: "openai/gpt-oss-120b";
245
+ /** Mixtral 8x7b - MoE model */
246
+ readonly MIXTRAL_8X7B: "mixtral-8x7b-32768";
247
+ /** Gemma 2 9B - Google's model */
248
+ readonly GEMMA_2_9B: "gemma2-9b-it";
249
+ /** Llama 4 Scout 17B - New model (30K T/s) */
250
+ readonly LLAMA_4_SCOUT_17B: "meta-llama/llama-4-scout-17b-16e-instruct";
251
+ /** Kimi K2 - Moonshot AI model */
252
+ readonly KIMI_K2_INSTRUCT: "moonshotai/kimi-k2-instruct";
253
+ /** Qwen 3 32B - Alibaba's model */
254
+ readonly QWEN3_32B: "qwen/qwen3-32b";
255
+ };
256
+ /**
257
+ * Default models for different use cases
258
+ */
259
+ declare const DEFAULT_MODELS: {
260
+ readonly TEXT: "llama-3.1-8b-instant";
261
+ readonly FAST: "llama-3.1-8b-instant";
262
+ readonly EXPERIMENTAL: "openai/gpt-oss-20b";
263
+ };
264
+ /**
265
+ * Default generation configuration
266
+ */
267
+ declare const DEFAULT_GENERATION_CONFIG: {
268
+ readonly temperature: 0.7;
269
+ readonly maxTokens: 1024;
270
+ readonly topP: 1;
271
+ };
272
+ /**
273
+ * API endpoints
274
+ */
275
+ declare const API_ENDPOINTS: {
276
+ readonly CHAT: "/chat/completions";
277
+ };
278
+ /**
279
+ * Default base URL
280
+ */
281
+ declare const DEFAULT_BASE_URL: "https://api.groq.com/openai/v1";
282
+ /**
283
+ * Default timeouts
284
+ */
285
+ declare const TIMEOUTS: {
286
+ readonly DEFAULT: 30000;
287
+ readonly STREAMING: 60000;
288
+ };
289
+
290
+ /**
291
+ * Error Types
292
+ * @description Error type enum and user-friendly message table.
293
+ * The classification logic (status → type, type → retryable, ...)
294
+ * lives in the validators/ and resolvers/ folders; this file
295
+ * only contains the enum and the message table.
296
+ */
297
+ declare enum GroqErrorType {
298
+ INVALID_API_KEY = "INVALID_API_KEY",
299
+ MISSING_CONFIG = "MISSING_CONFIG",
300
+ NETWORK_ERROR = "NETWORK_ERROR",
301
+ ABORT_ERROR = "ABORT_ERROR",
302
+ RATE_LIMIT_ERROR = "RATE_LIMIT_ERROR",
303
+ SERVER_ERROR = "SERVER_ERROR",
304
+ CLIENT_ERROR = "CLIENT_ERROR",
305
+ UNKNOWN_ERROR = "UNKNOWN_ERROR"
306
+ }
307
+ declare const USER_FRIENDLY_ERROR_MESSAGES: Readonly<Record<GroqErrorType, string>>;
308
+
309
+ /**
310
+ * Groq Request Builder
311
+ * @description Builder for constructing GroqChatRequest instances
312
+ * from a domain intent (model + messages + generation config).
313
+ * Implements the Builder pattern; each method is fluent.
314
+ */
315
+
316
+ declare class GroqChatRequestBuilder {
317
+ private readonly model;
318
+ private messages;
319
+ private generationConfig;
320
+ private streamEnabled;
321
+ constructor(model: string);
322
+ static for(model: string): GroqChatRequestBuilder;
323
+ withMessages(messages: ReadonlyArray<GroqMessage>): this;
324
+ withConfig(config: GroqGenerationConfig | undefined): this;
325
+ withStream(stream: boolean): this;
326
+ build(): GroqChatRequest;
327
+ }
328
+
329
+ /**
330
+ * Structured Prompt Builder
331
+ * @description Builds user prompts that ask the model to emit JSON,
332
+ * optionally constrained to a JSON Schema.
333
+ */
334
+ declare class StructuredPromptBuilder {
335
+ private schema;
336
+ private request;
337
+ constructor(request: string);
338
+ static for(request: string): StructuredPromptBuilder;
339
+ withSchema(schema: Record<string, unknown> | undefined): this;
340
+ build(): string;
341
+ }
342
+
343
+ /**
344
+ * Streaming Response Parser
345
+ * @description Parses Server-Sent Events (SSE) from Groq streaming responses.
346
+ * Delegates the line-level logic → parsers/sse-line-extractor.
347
+ */
348
+ interface StreamingParserCallbacks {
349
+ readonly onChunk: (content: string) => void;
350
+ }
351
+ declare class StreamingResponseParser {
352
+ private readonly callbacks;
353
+ private readonly decoder;
354
+ constructor(callbacks: StreamingParserCallbacks);
355
+ parse(stream: ReadableStream<Uint8Array>): Promise<string>;
356
+ }
357
+
358
+ /**
359
+ * JSON Response Parser
360
+ * @description Parses JSON payloads extracted by parsers/json-content-extractor.
361
+ */
362
+ declare class JsonResponseParser {
363
+ parse<T>(rawContent: string): T;
364
+ }
365
+
366
+ /**
367
+ * Request Executor Strategy
368
+ * @description Strategy contract for composing request execution behaviors
369
+ * (retry, queue, deduplication, etc.).
370
+ *
371
+ * @example
372
+ * ```typescript
373
+ * const retryThenQueue = new CompositeExecutor([
374
+ * new RetryExecutor(retryManager),
375
+ * new QueueExecutor(queue, priority),
376
+ * ]);
377
+ * const result = await retryThenQueue.execute(fetchSomething, payload);
378
+ * ```
379
+ */
380
+ interface IRequestExecutor<TArgs extends unknown[], TResult> {
381
+ /**
382
+ * Run `fn(...args)` through this executor's behavior. Implementations
383
+ * may add retries, queueing, dedup, etc.
384
+ */
385
+ execute(fn: (...args: TArgs) => Promise<TResult>, ...args: TArgs): Promise<TResult>;
386
+ }
387
+
388
+ /**
389
+ * Retry Executor Strategy
390
+ * @description Wraps a request function with retry logic.
391
+ *
392
+ * @example
393
+ * ```typescript
394
+ * const executor = new RetryExecutor(retryManager, { maxAttempts: 5 });
395
+ * await executor.execute(unreliableRequest, payload);
396
+ * ```
397
+ */
398
+
399
+ declare class RetryExecutor<TArgs extends unknown[], TResult> implements IRequestExecutor<TArgs, TResult> {
400
+ private readonly retryManager;
401
+ private readonly options?;
402
+ constructor(retryManager: RetryManager, options?: RetryOptions | undefined);
403
+ execute(fn: (...args: TArgs) => Promise<TResult>, ...args: TArgs): Promise<TResult>;
404
+ }
405
+
406
+ /**
407
+ * Queue Executor Strategy
408
+ * @description Wraps a request function with a concurrency-limiting queue.
409
+ *
410
+ * @example
411
+ * ```typescript
412
+ * const executor = new QueueExecutor(queue, 10); // priority 10
413
+ * await executor.execute(someRequest, payload);
414
+ * ```
415
+ */
416
+
417
+ declare class QueueExecutor<TArgs extends unknown[], TResult> implements IRequestExecutor<TArgs, TResult> {
418
+ private readonly queue;
419
+ private readonly priority;
420
+ constructor(queue: RequestQueue, priority: number);
421
+ execute(fn: (...args: TArgs) => Promise<TResult>, ...args: TArgs): Promise<TResult>;
422
+ }
423
+
424
+ /**
425
+ * Dedupe Executor Strategy
426
+ * @description Coalesces in-flight requests with the same key
427
+ */
428
+
429
+ type KeyGenerator<TArgs extends unknown[]> = (...args: TArgs) => string;
430
+ interface DedupeExecutorOptions<TArgs extends unknown[]> {
431
+ readonly generateKey: KeyGenerator<TArgs>;
432
+ }
433
+ declare class DedupeExecutor<TArgs extends unknown[], TResult> implements IRequestExecutor<TArgs, TResult> {
434
+ private readonly deduplicator;
435
+ private readonly options;
436
+ constructor(deduplicator: RequestDeduplicator, options: DedupeExecutorOptions<TArgs>);
437
+ execute(fn: (...args: TArgs) => Promise<TResult>, ...args: TArgs): Promise<TResult>;
438
+ }
439
+
440
+ /**
441
+ * Composite Executor Strategy
442
+ * @description Chains multiple IRequestExecutor instances.
443
+ * Order matters: the OUTERMOST executor wraps the others.
444
+ * Execution flows top-to-bottom on the way in,
445
+ * bottom-to-top on the way out.
446
+ *
447
+ * Example with [Dedupe, Retry, Queue]:
448
+ * Dedupe -> Retry -> Queue -> fn
449
+ */
450
+
451
+ declare class CompositeExecutor<TArgs extends unknown[], TResult> implements IRequestExecutor<TArgs, TResult> {
452
+ private readonly executors;
453
+ constructor(executors: ReadonlyArray<IRequestExecutor<TArgs, TResult>>);
454
+ execute(fn: (...args: TArgs) => Promise<TResult>, ...args: TArgs): Promise<TResult>;
455
+ private compress;
456
+ }
457
+
458
+ /**
459
+ * Message Factory and Transformer
460
+ * @description Builders and converters for Groq messages
461
+ */
462
+
463
+ declare const createUserMessage: (content: string) => GroqMessage;
464
+ declare const createAssistantMessage: (content: string) => GroqMessage;
465
+ declare const createSystemMessage: (content: string) => GroqMessage;
466
+ declare const createMessage: (role: GroqMessageRole, content: string) => GroqMessage;
467
+ declare const promptToMessages: (prompt: string) => GroqMessage[];
468
+ declare const extractTextFromMessages: (messages: ReadonlyArray<GroqMessage>) => string;
469
+ declare const formatMessagesForDisplay: (messages: ReadonlyArray<GroqMessage>) => string;
470
+
471
+ /**
472
+ * User-Friendly Error Resolver
473
+ * @description Maps any thrown value (Error, GroqError, string, etc.)
474
+ * to a user-facing string suitable for display. No I/O,
475
+ * no hardcoded user-facing strings: the mapping table
476
+ * is explicit and overridable.
477
+ *
478
+ * @example
479
+ * ```typescript
480
+ * resolveUserFriendlyErrorMessage(new GroqError(GroqErrorType.RATE_LIMIT_ERROR, "x"));
481
+ * // "You've reached the rate limit. Please wait a moment and try again."
482
+ * ```
483
+ */
484
+ declare function resolveUserFriendlyErrorMessage(error: unknown): string;
485
+
486
+ /**
487
+ * Groq Error
488
+ * @description Custom error class for Groq API operations.
489
+ */
490
+
491
+ interface GroqErrorMetadata {
492
+ readonly status?: number;
493
+ readonly url?: string;
494
+ readonly [key: string]: unknown;
495
+ }
496
+ declare class GroqError extends Error {
497
+ readonly type: GroqErrorType;
498
+ readonly cause?: Error;
499
+ readonly metadata: GroqErrorMetadata;
500
+ constructor(type: GroqErrorType, message: string, cause?: Error, metadata?: GroqErrorMetadata);
501
+ toString(): string;
502
+ toJSON(): {
503
+ name: string;
504
+ type: GroqErrorType;
505
+ message: string;
506
+ metadata: GroqErrorMetadata;
507
+ };
508
+ }
509
+
510
+ /**
511
+ * Error Resolver
512
+ * @description Resolves any thrown value to a user-friendly message.
513
+ * Delegates the actual classification → resolvers/user-friendly-error-resolver.
514
+ */
515
+
516
+ declare const resolveUserFriendlyMessage: typeof resolveUserFriendlyErrorMessage;
517
+ interface LoggedError {
518
+ readonly message: string;
519
+ readonly type: string;
520
+ readonly stack?: string;
521
+ readonly metadata?: GroqErrorMetadata;
522
+ }
523
+ declare function formatErrorForLogging(error: unknown): LoggedError;
524
+
525
+ /**
526
+ * Debounce and Throttle
527
+ * @description Rate limiting utilities. Delegates timing math
528
+ * → calculations/timing-window.
529
+ */
530
+ interface DebounceOptions {
531
+ readonly delay?: number;
532
+ readonly leading?: boolean;
533
+ readonly trailing?: boolean;
534
+ }
535
+ interface ThrottleOptions {
536
+ readonly interval?: number;
537
+ readonly leading?: boolean;
538
+ readonly trailing?: boolean;
539
+ }
540
+ declare class DebounceManager {
541
+ private readonly timers;
542
+ private readonly lastArgs;
543
+ debounce<T extends (...args: never[]) => unknown>(fn: T, options?: DebounceOptions): T;
544
+ debounceByKey<T extends (...args: never[]) => unknown>(key: string, fn: T, delay?: number): T;
545
+ cancelDebounce(key: string): void;
546
+ flushDebounce<T extends (...args: never[]) => unknown>(key: string, fn: T): void;
547
+ }
548
+ declare class ThrottleManager {
549
+ private readonly timers;
550
+ private readonly lastArgs;
551
+ throttle<T extends (...args: never[]) => unknown>(fn: T, options?: ThrottleOptions): T;
552
+ throttleByKey<T extends (...args: never[]) => unknown>(key: string, fn: T, interval?: number): T;
553
+ cancelThrottle(key: string): void;
554
+ isThrottled(key: string): boolean;
555
+ }
556
+ declare const debounceManager: DebounceManager;
557
+ declare const throttleManager: ThrottleManager;
558
+ declare function debounce<T extends (...args: never[]) => unknown>(fn: T, delay?: number): T;
559
+ declare function throttle<T extends (...args: never[]) => unknown>(fn: T, interval?: number): T;
560
+
561
+ export { API_ENDPOINTS, CacheManager, CacheStats, CompositeExecutor, DEFAULT_BASE_URL, DEFAULT_GENERATION_CONFIG, DEFAULT_MODELS, type DebounceOptions, DedupeExecutor, type DedupeExecutorOptions, GROQ_MODELS, GroqChatRequest, GroqChatRequestBuilder, GroqChatResponse, GroqConfig, GroqConfigStore, GroqError, type GroqErrorMetadata, GroqErrorType, GroqGenerationConfig, GroqHttpClient, type GroqHttpClientDeps, GroqHttpTransport, GroqMessage, GroqMessageRole, IGroqHttpClient, type IRequestExecutor, JsonResponseParser, QueueExecutor, type QueueOptions, RequestDeduplicator, RequestQueue, RetryExecutor, RetryManager, type RetryOptions, type StreamingParserCallbacks, StreamingResponseParser, StructuredPromptBuilder, TIMEOUTS, TextGenerationService, type ThrottleOptions, USER_FRIENDLY_ERROR_MESSAGES, type UseCacheStatsOptions, type UseGroqDeps, type UseGroqOptions, type UseGroqReturn, createAssistantMessage, createMessage, createSystemMessage, createUserMessage, debounce, debounceManager, extractTextFromMessages, formatErrorForLogging, formatMessagesForDisplay, promptToMessages, requestDeduplicator, requestQueue, resolveUserFriendlyMessage, retryManager, throttle, throttleManager, useCacheStats, useGroq, withRetry };