groq-rag 0.1.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.
@@ -0,0 +1,771 @@
1
+ import Groq from 'groq-sdk';
2
+ import * as groq_sdk_core_mjs from 'groq-sdk/core.mjs';
3
+ import * as groq_sdk_lib_streaming_mjs from 'groq-sdk/lib/streaming.mjs';
4
+ import { ChatCompletionCreateParamsNonStreaming, ChatCompletion, ChatCompletionCreateParamsStreaming } from 'groq-sdk/resources/chat/completions';
5
+
6
+ interface GroqRAGConfig {
7
+ apiKey?: string;
8
+ baseURL?: string;
9
+ timeout?: number;
10
+ maxRetries?: number;
11
+ embedding?: EmbeddingConfig;
12
+ vectorStore?: VectorStoreConfig;
13
+ web?: WebConfig;
14
+ }
15
+ interface EmbeddingConfig {
16
+ provider: 'groq' | 'openai' | 'local' | 'custom';
17
+ model?: string;
18
+ apiKey?: string;
19
+ baseURL?: string;
20
+ dimensions?: number;
21
+ }
22
+ interface VectorStoreConfig {
23
+ provider: 'memory' | 'chroma' | 'pinecone' | 'qdrant' | 'custom';
24
+ connectionString?: string;
25
+ apiKey?: string;
26
+ namespace?: string;
27
+ indexName?: string;
28
+ }
29
+ interface WebConfig {
30
+ userAgent?: string;
31
+ timeout?: number;
32
+ maxContentLength?: number;
33
+ followRedirects?: boolean;
34
+ proxy?: string;
35
+ }
36
+ interface Document {
37
+ id: string;
38
+ content: string;
39
+ metadata?: Record<string, unknown>;
40
+ embedding?: number[];
41
+ }
42
+ interface DocumentChunk {
43
+ id: string;
44
+ documentId: string;
45
+ content: string;
46
+ metadata?: Record<string, unknown>;
47
+ embedding?: number[];
48
+ startIndex?: number;
49
+ endIndex?: number;
50
+ }
51
+ interface EmbeddingResult {
52
+ embedding: number[];
53
+ tokenCount?: number;
54
+ }
55
+ interface SearchResult {
56
+ document: DocumentChunk;
57
+ score: number;
58
+ relevance?: 'high' | 'medium' | 'low';
59
+ }
60
+ interface RAGOptions {
61
+ /** Number of documents to retrieve */
62
+ topK?: number;
63
+ /** Minimum similarity score (0-1) */
64
+ minScore?: number;
65
+ /** Include document metadata in context */
66
+ includeMetadata?: boolean;
67
+ /** Custom context template */
68
+ contextTemplate?: string;
69
+ /** Maximum context length in tokens */
70
+ maxContextTokens?: number;
71
+ }
72
+ interface RAGChatOptions extends RAGOptions {
73
+ messages: Groq.Chat.ChatCompletionMessageParam[];
74
+ model?: string;
75
+ temperature?: number;
76
+ maxTokens?: number;
77
+ stream?: boolean;
78
+ systemPrompt?: string;
79
+ }
80
+ interface RAGResponse {
81
+ content: string;
82
+ sources: SearchResult[];
83
+ usage?: {
84
+ promptTokens: number;
85
+ completionTokens: number;
86
+ totalTokens: number;
87
+ };
88
+ }
89
+ interface FetchOptions {
90
+ headers?: Record<string, string>;
91
+ timeout?: number;
92
+ maxLength?: number;
93
+ extractText?: boolean;
94
+ includeLinks?: boolean;
95
+ includeImages?: boolean;
96
+ }
97
+ interface FetchResult {
98
+ url: string;
99
+ title?: string;
100
+ content: string;
101
+ markdown?: string;
102
+ links?: Array<{
103
+ text: string;
104
+ href: string;
105
+ }>;
106
+ images?: Array<{
107
+ alt: string;
108
+ src: string;
109
+ }>;
110
+ metadata?: {
111
+ description?: string;
112
+ author?: string;
113
+ publishedDate?: string;
114
+ };
115
+ fetchedAt: Date;
116
+ }
117
+ interface SearchOptions {
118
+ maxResults?: number;
119
+ language?: string;
120
+ region?: string;
121
+ safeSearch?: boolean;
122
+ }
123
+ interface WebSearchResult {
124
+ title: string;
125
+ url: string;
126
+ snippet: string;
127
+ position: number;
128
+ }
129
+ interface BrowseOptions extends FetchOptions {
130
+ /** Wait for JavaScript to execute */
131
+ waitForJs?: boolean;
132
+ /** Wait for specific selector */
133
+ waitForSelector?: string;
134
+ /** Execute custom JavaScript */
135
+ executeScript?: string;
136
+ /** Screenshot options */
137
+ screenshot?: boolean;
138
+ /** Scroll to load more content */
139
+ scrollToBottom?: boolean;
140
+ }
141
+ interface ToolDefinition {
142
+ name: string;
143
+ description: string;
144
+ parameters: {
145
+ type: 'object';
146
+ properties: Record<string, unknown>;
147
+ required?: string[];
148
+ };
149
+ execute: (params: Record<string, unknown>) => Promise<unknown>;
150
+ }
151
+ interface ToolResult {
152
+ name: string;
153
+ result: unknown;
154
+ error?: string;
155
+ executionTime?: number;
156
+ }
157
+ interface AgentConfig {
158
+ name?: string;
159
+ model?: string;
160
+ systemPrompt?: string;
161
+ tools?: ToolDefinition[];
162
+ maxIterations?: number;
163
+ verbose?: boolean;
164
+ memory?: AgentMemory;
165
+ }
166
+ interface AgentMemory {
167
+ messages: Groq.Chat.ChatCompletionMessageParam[];
168
+ context?: string;
169
+ variables?: Record<string, unknown>;
170
+ }
171
+ interface AgentStep {
172
+ thought?: string;
173
+ action?: string;
174
+ actionInput?: Record<string, unknown>;
175
+ observation?: string;
176
+ isFinal?: boolean;
177
+ }
178
+ interface AgentResult {
179
+ output: string;
180
+ steps: AgentStep[];
181
+ toolCalls: ToolResult[];
182
+ totalTokens?: number;
183
+ }
184
+ interface ChunkingOptions {
185
+ strategy: 'fixed' | 'sentence' | 'paragraph' | 'semantic' | 'recursive';
186
+ chunkSize?: number;
187
+ chunkOverlap?: number;
188
+ separators?: string[];
189
+ }
190
+ interface VectorStore {
191
+ add(documents: DocumentChunk[]): Promise<void>;
192
+ search(query: number[], options?: {
193
+ topK?: number;
194
+ filter?: Record<string, unknown>;
195
+ }): Promise<SearchResult[]>;
196
+ delete(ids: string[]): Promise<void>;
197
+ clear(): Promise<void>;
198
+ count(): Promise<number>;
199
+ }
200
+ interface EmbeddingProvider {
201
+ embed(text: string): Promise<EmbeddingResult>;
202
+ embedBatch(texts: string[]): Promise<EmbeddingResult[]>;
203
+ dimensions: number;
204
+ }
205
+
206
+ /**
207
+ * RAG Retriever - handles document ingestion and retrieval
208
+ */
209
+ declare class Retriever {
210
+ private vectorStore;
211
+ private embeddings;
212
+ private chunker;
213
+ constructor(vectorStore: VectorStore, embeddings: EmbeddingProvider, chunkingOptions?: Partial<ChunkingOptions>);
214
+ /**
215
+ * Add a document to the retriever
216
+ */
217
+ addDocument(content: string, metadata?: Record<string, unknown>): Promise<string>;
218
+ /**
219
+ * Add multiple documents
220
+ */
221
+ addDocuments(documents: Array<{
222
+ content: string;
223
+ metadata?: Record<string, unknown>;
224
+ }>): Promise<string[]>;
225
+ /**
226
+ * Add raw text directly (without chunking)
227
+ */
228
+ addChunk(content: string, metadata?: Record<string, unknown>): Promise<string>;
229
+ /**
230
+ * Retrieve relevant documents for a query
231
+ */
232
+ retrieve(query: string, options?: RAGOptions): Promise<SearchResult[]>;
233
+ /**
234
+ * Retrieve and format context for LLM
235
+ */
236
+ getContext(query: string, options?: RAGOptions): Promise<string>;
237
+ /**
238
+ * Delete documents by ID
239
+ */
240
+ deleteDocuments(ids: string[]): Promise<void>;
241
+ /**
242
+ * Clear all documents
243
+ */
244
+ clear(): Promise<void>;
245
+ /**
246
+ * Get document count
247
+ */
248
+ count(): Promise<number>;
249
+ }
250
+ /**
251
+ * Create a default retriever with in-memory storage
252
+ */
253
+ declare function createRetriever(vectorStore: VectorStore, embeddings: EmbeddingProvider, options?: Partial<ChunkingOptions>): Retriever;
254
+
255
+ /**
256
+ * Web content fetcher - fetches and parses web pages
257
+ */
258
+ declare class WebFetcher {
259
+ private config;
260
+ private turndown;
261
+ constructor(config?: WebConfig);
262
+ /**
263
+ * Fetch a URL and extract content
264
+ */
265
+ fetch(url: string, options?: FetchOptions): Promise<FetchResult>;
266
+ /**
267
+ * Fetch multiple URLs in parallel
268
+ */
269
+ fetchMany(urls: string[], options?: FetchOptions): Promise<Array<FetchResult | Error>>;
270
+ /**
271
+ * Fetch and extract just the text content
272
+ */
273
+ fetchText(url: string): Promise<string>;
274
+ /**
275
+ * Fetch and convert to markdown
276
+ */
277
+ fetchMarkdown(url: string): Promise<string>;
278
+ }
279
+ /**
280
+ * Create a web fetcher with default config
281
+ */
282
+ declare function createFetcher(config?: WebConfig): WebFetcher;
283
+
284
+ /**
285
+ * Web search provider interface
286
+ */
287
+ interface SearchProvider {
288
+ search(query: string, options?: SearchOptions): Promise<WebSearchResult[]>;
289
+ }
290
+ /**
291
+ * DuckDuckGo search (no API key required)
292
+ */
293
+ declare class DuckDuckGoSearch implements SearchProvider {
294
+ private baseUrl;
295
+ search(query: string, options?: SearchOptions): Promise<WebSearchResult[]>;
296
+ private parseResults;
297
+ private decodeUrl;
298
+ private decodeHtml;
299
+ }
300
+ /**
301
+ * Brave Search API
302
+ */
303
+ declare class BraveSearch implements SearchProvider {
304
+ private apiKey;
305
+ private baseUrl;
306
+ constructor(apiKey: string);
307
+ search(query: string, options?: SearchOptions): Promise<WebSearchResult[]>;
308
+ }
309
+ /**
310
+ * Serper.dev Google Search API
311
+ */
312
+ declare class SerperSearch implements SearchProvider {
313
+ private apiKey;
314
+ private baseUrl;
315
+ constructor(apiKey: string);
316
+ search(query: string, options?: SearchOptions): Promise<WebSearchResult[]>;
317
+ }
318
+ /**
319
+ * Create a search provider based on available API keys
320
+ */
321
+ declare function createSearchProvider(config?: {
322
+ provider?: 'duckduckgo' | 'brave' | 'serper';
323
+ apiKey?: string;
324
+ }): SearchProvider;
325
+
326
+ /**
327
+ * ReAct-style agent that can use tools
328
+ */
329
+ declare class Agent {
330
+ private client;
331
+ private config;
332
+ private executor;
333
+ private messages;
334
+ constructor(client: Groq, config?: AgentConfig);
335
+ private getDefaultSystemPrompt;
336
+ /**
337
+ * Add a tool to the agent
338
+ */
339
+ addTool(tool: ToolDefinition): void;
340
+ /**
341
+ * Run the agent with a user message
342
+ */
343
+ run(input: string): Promise<AgentResult>;
344
+ /**
345
+ * Run with streaming output
346
+ */
347
+ runStream(input: string): AsyncGenerator<{
348
+ type: 'thought' | 'tool_call' | 'tool_result' | 'content' | 'done';
349
+ data: unknown;
350
+ }>;
351
+ /**
352
+ * Clear conversation history
353
+ */
354
+ clearHistory(): void;
355
+ /**
356
+ * Get conversation history
357
+ */
358
+ getHistory(): Groq.Chat.ChatCompletionMessageParam[];
359
+ }
360
+ /**
361
+ * Create an agent with default configuration
362
+ */
363
+ declare function createAgent(client: Groq, config?: AgentConfig): Agent;
364
+
365
+ /**
366
+ * Extended Groq client with RAG, web, and agent capabilities
367
+ */
368
+ declare class GroqRAG {
369
+ private groq;
370
+ private config;
371
+ private retriever?;
372
+ private fetcher;
373
+ private searchProvider;
374
+ chat: ChatWithRAG;
375
+ web: WebModule;
376
+ rag: RAGModule;
377
+ constructor(config?: GroqRAGConfig);
378
+ /**
379
+ * Get the underlying Groq client
380
+ */
381
+ get client(): Groq;
382
+ /**
383
+ * Initialize RAG with vector store and embeddings
384
+ */
385
+ initRAG(options?: {
386
+ embedding?: EmbeddingConfig;
387
+ vectorStore?: VectorStoreConfig;
388
+ chunking?: Partial<ChunkingOptions>;
389
+ }): Promise<Retriever>;
390
+ /**
391
+ * Get the retriever (initializes with defaults if not already initialized)
392
+ */
393
+ getRetriever(): Promise<Retriever>;
394
+ /**
395
+ * Get the web fetcher
396
+ */
397
+ getFetcher(): WebFetcher;
398
+ /**
399
+ * Get the search provider
400
+ */
401
+ getSearchProvider(): SearchProvider;
402
+ /**
403
+ * Create an agent with tools
404
+ */
405
+ createAgent(config?: AgentConfig): Agent;
406
+ /**
407
+ * Create an agent with built-in tools (web search, fetch, RAG)
408
+ */
409
+ createAgentWithBuiltins(config?: AgentConfig): Promise<Agent>;
410
+ /**
411
+ * Standard chat completions (passthrough to Groq)
412
+ */
413
+ complete(params: ChatCompletionCreateParamsNonStreaming): Promise<ChatCompletion>;
414
+ /**
415
+ * Streaming chat completions (passthrough to Groq)
416
+ */
417
+ stream(params: ChatCompletionCreateParamsStreaming): groq_sdk_core_mjs.APIPromise<groq_sdk_lib_streaming_mjs.Stream<Groq.Chat.Completions.ChatCompletionChunk>>;
418
+ }
419
+ /**
420
+ * Chat module with RAG support
421
+ */
422
+ declare class ChatWithRAG {
423
+ private parent;
424
+ constructor(parent: GroqRAG);
425
+ /**
426
+ * Chat with RAG-augmented context
427
+ */
428
+ withRAG(options: RAGChatOptions): Promise<RAGResponse>;
429
+ /**
430
+ * Chat with web search augmentation
431
+ */
432
+ withWebSearch(options: {
433
+ messages: Groq.Chat.ChatCompletionMessageParam[];
434
+ model?: string;
435
+ searchQuery?: string;
436
+ maxResults?: number;
437
+ }): Promise<{
438
+ content: string;
439
+ sources: WebSearchResult[];
440
+ }>;
441
+ /**
442
+ * Chat with URL content
443
+ */
444
+ withUrl(options: {
445
+ messages: Groq.Chat.ChatCompletionMessageParam[];
446
+ url: string;
447
+ model?: string;
448
+ }): Promise<{
449
+ content: string;
450
+ source: FetchResult;
451
+ }>;
452
+ }
453
+ /**
454
+ * Web module for fetching and searching
455
+ */
456
+ declare class WebModule {
457
+ private parent;
458
+ constructor(parent: GroqRAG);
459
+ /**
460
+ * Fetch a URL
461
+ */
462
+ fetch(url: string, options?: FetchOptions): Promise<FetchResult>;
463
+ /**
464
+ * Fetch multiple URLs
465
+ */
466
+ fetchMany(urls: string[], options?: FetchOptions): Promise<Array<FetchResult | Error>>;
467
+ /**
468
+ * Search the web
469
+ */
470
+ search(query: string, options?: SearchOptions): Promise<WebSearchResult[]>;
471
+ /**
472
+ * Fetch URL and convert to markdown
473
+ */
474
+ fetchMarkdown(url: string): Promise<string>;
475
+ }
476
+ /**
477
+ * RAG module for document management
478
+ */
479
+ declare class RAGModule {
480
+ private parent;
481
+ constructor(parent: GroqRAG);
482
+ /**
483
+ * Add a document to the knowledge base
484
+ */
485
+ addDocument(content: string, metadata?: Record<string, unknown>): Promise<string>;
486
+ /**
487
+ * Add multiple documents
488
+ */
489
+ addDocuments(documents: Array<{
490
+ content: string;
491
+ metadata?: Record<string, unknown>;
492
+ }>): Promise<string[]>;
493
+ /**
494
+ * Add a URL's content to the knowledge base
495
+ */
496
+ addUrl(url: string, metadata?: Record<string, unknown>): Promise<string>;
497
+ /**
498
+ * Query the knowledge base
499
+ */
500
+ query(query: string, options?: {
501
+ topK?: number;
502
+ minScore?: number;
503
+ }): Promise<SearchResult[]>;
504
+ /**
505
+ * Get formatted context for a query
506
+ */
507
+ getContext(query: string, options?: {
508
+ topK?: number;
509
+ includeMetadata?: boolean;
510
+ }): Promise<string>;
511
+ /**
512
+ * Clear the knowledge base
513
+ */
514
+ clear(): Promise<void>;
515
+ /**
516
+ * Get document count
517
+ */
518
+ count(): Promise<number>;
519
+ }
520
+
521
+ /**
522
+ * In-memory vector store implementation
523
+ */
524
+ declare class MemoryVectorStore implements VectorStore {
525
+ private documents;
526
+ add(documents: DocumentChunk[]): Promise<void>;
527
+ search(queryEmbedding: number[], options?: {
528
+ topK?: number;
529
+ filter?: Record<string, unknown>;
530
+ }): Promise<SearchResult[]>;
531
+ delete(ids: string[]): Promise<void>;
532
+ clear(): Promise<void>;
533
+ count(): Promise<number>;
534
+ /**
535
+ * Get all documents (useful for debugging)
536
+ */
537
+ getAll(): DocumentChunk[];
538
+ }
539
+ /**
540
+ * Chroma vector store adapter
541
+ */
542
+ declare class ChromaVectorStore implements VectorStore {
543
+ private baseURL;
544
+ private collectionName;
545
+ private collectionId?;
546
+ constructor(config: VectorStoreConfig);
547
+ private ensureCollection;
548
+ add(documents: DocumentChunk[]): Promise<void>;
549
+ search(queryEmbedding: number[], options?: {
550
+ topK?: number;
551
+ filter?: Record<string, unknown>;
552
+ }): Promise<SearchResult[]>;
553
+ delete(ids: string[]): Promise<void>;
554
+ clear(): Promise<void>;
555
+ count(): Promise<number>;
556
+ }
557
+ /**
558
+ * Create a vector store based on config
559
+ */
560
+ declare function createVectorStore(config: VectorStoreConfig): VectorStore;
561
+
562
+ /**
563
+ * Groq-based embedding provider (uses compatible models)
564
+ */
565
+ declare class GroqEmbeddings implements EmbeddingProvider {
566
+ private client;
567
+ private model;
568
+ dimensions: number;
569
+ constructor(config: EmbeddingConfig & {
570
+ groqClient?: Groq;
571
+ });
572
+ embed(text: string): Promise<EmbeddingResult>;
573
+ embedBatch(texts: string[]): Promise<EmbeddingResult[]>;
574
+ /**
575
+ * Generate a pseudo-embedding (for demo purposes)
576
+ * In production, replace with actual embedding API
577
+ */
578
+ private generatePseudoEmbedding;
579
+ }
580
+ /**
581
+ * OpenAI-compatible embedding provider
582
+ */
583
+ declare class OpenAIEmbeddings implements EmbeddingProvider {
584
+ private apiKey;
585
+ private baseURL;
586
+ private model;
587
+ dimensions: number;
588
+ constructor(config: EmbeddingConfig);
589
+ embed(text: string): Promise<EmbeddingResult>;
590
+ embedBatch(texts: string[]): Promise<EmbeddingResult[]>;
591
+ }
592
+ /**
593
+ * Create an embedding provider based on config
594
+ */
595
+ declare function createEmbeddingProvider(config: EmbeddingConfig, groqClient?: Groq): EmbeddingProvider;
596
+
597
+ /**
598
+ * Tool executor - manages and executes tools
599
+ */
600
+ declare class ToolExecutor {
601
+ private tools;
602
+ constructor(tools?: ToolDefinition[]);
603
+ /**
604
+ * Register a tool
605
+ */
606
+ register(tool: ToolDefinition): void;
607
+ /**
608
+ * Unregister a tool
609
+ */
610
+ unregister(name: string): boolean;
611
+ /**
612
+ * Get all registered tools
613
+ */
614
+ getTools(): ToolDefinition[];
615
+ /**
616
+ * Get tools in Groq API format
617
+ */
618
+ getToolsForAPI(): Groq.Chat.ChatCompletionTool[];
619
+ /**
620
+ * Check if a tool exists
621
+ */
622
+ has(name: string): boolean;
623
+ /**
624
+ * Execute a tool by name
625
+ */
626
+ execute(name: string, params: Record<string, unknown>): Promise<ToolResult>;
627
+ /**
628
+ * Execute multiple tool calls in parallel
629
+ */
630
+ executeMany(calls: Array<{
631
+ name: string;
632
+ params: Record<string, unknown>;
633
+ }>): Promise<ToolResult[]>;
634
+ /**
635
+ * Process tool calls from Groq API response
636
+ */
637
+ processToolCalls(toolCalls: Groq.Chat.ChatCompletionMessageToolCall[]): Promise<Array<{
638
+ toolCallId: string;
639
+ result: ToolResult;
640
+ }>>;
641
+ /**
642
+ * Format tool results as messages for Groq API
643
+ */
644
+ formatToolResultsAsMessages(results: Array<{
645
+ toolCallId: string;
646
+ result: ToolResult;
647
+ }>): Groq.Chat.ChatCompletionToolMessageParam[];
648
+ }
649
+ /**
650
+ * Create a tool executor with optional initial tools
651
+ */
652
+ declare function createToolExecutor(tools?: ToolDefinition[]): ToolExecutor;
653
+
654
+ /**
655
+ * Create web search tool
656
+ */
657
+ declare function createWebSearchTool(searchProvider?: DuckDuckGoSearch): ToolDefinition;
658
+ /**
659
+ * Create URL fetch tool
660
+ */
661
+ declare function createFetchUrlTool(fetcher?: WebFetcher): ToolDefinition;
662
+ /**
663
+ * Create RAG query tool
664
+ */
665
+ declare function createRAGQueryTool(retriever: Retriever): ToolDefinition;
666
+ /**
667
+ * Create calculator tool
668
+ */
669
+ declare function createCalculatorTool(): ToolDefinition;
670
+ /**
671
+ * Create current datetime tool
672
+ */
673
+ declare function createDateTimeTool(): ToolDefinition;
674
+ /**
675
+ * Get all built-in tools (except RAG which needs a retriever)
676
+ */
677
+ declare function getBuiltinTools(): ToolDefinition[];
678
+
679
+ /**
680
+ * Text chunking utilities for RAG
681
+ */
682
+ declare class TextChunker {
683
+ private options;
684
+ constructor(options?: Partial<ChunkingOptions>);
685
+ /**
686
+ * Chunk text into smaller pieces
687
+ */
688
+ chunk(text: string, documentId: string): DocumentChunk[];
689
+ /**
690
+ * Fixed-size chunking with overlap
691
+ */
692
+ private fixedChunk;
693
+ /**
694
+ * Sentence-based chunking
695
+ */
696
+ private sentenceChunk;
697
+ /**
698
+ * Paragraph-based chunking
699
+ */
700
+ private paragraphChunk;
701
+ /**
702
+ * Recursive character text splitter (LangChain-style)
703
+ */
704
+ private recursiveChunk;
705
+ private recursiveSplit;
706
+ /**
707
+ * Semantic chunking (placeholder - would use embeddings in production)
708
+ */
709
+ private semanticChunk;
710
+ }
711
+ /**
712
+ * Utility function for quick chunking
713
+ */
714
+ declare function chunkText(text: string, documentId: string, options?: Partial<ChunkingOptions>): DocumentChunk[];
715
+
716
+ /**
717
+ * Generate a unique ID
718
+ */
719
+ declare function generateId(): string;
720
+ /**
721
+ * Cosine similarity between two vectors
722
+ */
723
+ declare function cosineSimilarity(a: number[], b: number[]): number;
724
+ /**
725
+ * Estimate token count (rough approximation)
726
+ */
727
+ declare function estimateTokens(text: string): number;
728
+ /**
729
+ * Truncate text to approximate token limit
730
+ */
731
+ declare function truncateToTokens(text: string, maxTokens: number): string;
732
+ /**
733
+ * Clean and normalize text
734
+ */
735
+ declare function cleanText(text: string): string;
736
+ /**
737
+ * Extract URLs from text
738
+ */
739
+ declare function extractUrls(text: string): string[];
740
+ /**
741
+ * Sleep utility
742
+ */
743
+ declare function sleep(ms: number): Promise<void>;
744
+ /**
745
+ * Retry with exponential backoff
746
+ */
747
+ declare function retry<T>(fn: () => Promise<T>, options?: {
748
+ maxRetries?: number;
749
+ baseDelay?: number;
750
+ maxDelay?: number;
751
+ }): Promise<T>;
752
+ /**
753
+ * Create a context string from search results
754
+ */
755
+ declare function formatContext(results: Array<{
756
+ content: string;
757
+ metadata?: Record<string, unknown>;
758
+ }>, options?: {
759
+ includeMetadata?: boolean;
760
+ separator?: string;
761
+ }): string;
762
+ /**
763
+ * Parse JSON safely
764
+ */
765
+ declare function safeJsonParse<T>(text: string, defaultValue: T): T;
766
+ /**
767
+ * Batch array into chunks
768
+ */
769
+ declare function batch<T>(array: T[], size: number): T[][];
770
+
771
+ export { Agent, type AgentConfig, type AgentMemory, type AgentResult, type AgentStep, BraveSearch, type BrowseOptions, ChromaVectorStore, type ChunkingOptions, type Document, type DocumentChunk, DuckDuckGoSearch, type EmbeddingConfig, type EmbeddingProvider, type EmbeddingResult, type FetchOptions, type FetchResult, GroqEmbeddings, GroqRAG, type GroqRAGConfig, MemoryVectorStore, OpenAIEmbeddings, type RAGChatOptions, type RAGOptions, type RAGResponse, Retriever, type SearchOptions, type SearchProvider, type SearchResult, SerperSearch, TextChunker, type ToolDefinition, ToolExecutor, type ToolResult, type VectorStore, type VectorStoreConfig, type WebConfig, WebFetcher, type WebSearchResult, batch, chunkText, cleanText, cosineSimilarity, createAgent, createCalculatorTool, createDateTimeTool, createEmbeddingProvider, createFetchUrlTool, createFetcher, createRAGQueryTool, createRetriever, createSearchProvider, createToolExecutor, createVectorStore, createWebSearchTool, GroqRAG as default, estimateTokens, extractUrls, formatContext, generateId, getBuiltinTools, retry, safeJsonParse, sleep, truncateToTokens };