@snap-agent/core 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.
- package/LICENSE +22 -0
- package/README.md +625 -0
- package/dist/chunk-V4TPAVOY.mjs +2227 -0
- package/dist/chunk-Y5TTFQWC.mjs +801 -0
- package/dist/dist-2CMI4QQD.mjs +1825 -0
- package/dist/dist-JU54Y3G4.mjs +3216 -0
- package/dist/index-CDsqnM8L.d.mts +680 -0
- package/dist/index-CDsqnM8L.d.ts +680 -0
- package/dist/index.d.mts +472 -0
- package/dist/index.d.ts +472 -0
- package/dist/index.js +9413 -0
- package/dist/index.mjs +1284 -0
- package/dist/storage/index.d.mts +1 -0
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.js +829 -0
- package/dist/storage/index.mjs +10 -0
- package/package.json +114 -0
|
@@ -0,0 +1,680 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin system for extending agent capabilities
|
|
3
|
+
*/
|
|
4
|
+
interface BasePlugin {
|
|
5
|
+
name: string;
|
|
6
|
+
type: 'rag' | 'tool' | 'middleware' | 'analytics';
|
|
7
|
+
priority?: number;
|
|
8
|
+
}
|
|
9
|
+
interface RAGContext {
|
|
10
|
+
content: string;
|
|
11
|
+
sources?: Array<{
|
|
12
|
+
id: string;
|
|
13
|
+
title?: string;
|
|
14
|
+
score?: number;
|
|
15
|
+
type?: string;
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
}>;
|
|
18
|
+
metadata?: Record<string, any>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Document to be ingested into RAG system
|
|
22
|
+
*/
|
|
23
|
+
interface RAGDocument {
|
|
24
|
+
id: string;
|
|
25
|
+
content: string;
|
|
26
|
+
metadata?: Record<string, any>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Result of an ingestion operation
|
|
30
|
+
*/
|
|
31
|
+
interface IngestResult {
|
|
32
|
+
success: boolean;
|
|
33
|
+
indexed: number;
|
|
34
|
+
failed: number;
|
|
35
|
+
errors?: Array<{
|
|
36
|
+
id: string;
|
|
37
|
+
error: string;
|
|
38
|
+
}>;
|
|
39
|
+
metadata?: Record<string, any>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Options for ingestion operations
|
|
43
|
+
*/
|
|
44
|
+
interface IngestOptions {
|
|
45
|
+
agentId?: string;
|
|
46
|
+
batchSize?: number;
|
|
47
|
+
skipExisting?: boolean;
|
|
48
|
+
overwrite?: boolean;
|
|
49
|
+
[key: string]: any;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Options for bulk operations
|
|
53
|
+
* For 'insert': document with full RAGDocument required
|
|
54
|
+
* For 'update': document with Partial<RAGDocument> optional
|
|
55
|
+
* For 'delete': document not needed
|
|
56
|
+
*/
|
|
57
|
+
type BulkOperation = {
|
|
58
|
+
type: 'insert';
|
|
59
|
+
id: string;
|
|
60
|
+
document: RAGDocument;
|
|
61
|
+
} | {
|
|
62
|
+
type: 'update';
|
|
63
|
+
id: string;
|
|
64
|
+
document?: Partial<RAGDocument>;
|
|
65
|
+
} | {
|
|
66
|
+
type: 'delete';
|
|
67
|
+
id: string;
|
|
68
|
+
document?: never;
|
|
69
|
+
};
|
|
70
|
+
interface BulkResult {
|
|
71
|
+
success: boolean;
|
|
72
|
+
inserted: number;
|
|
73
|
+
updated: number;
|
|
74
|
+
deleted: number;
|
|
75
|
+
failed: number;
|
|
76
|
+
errors?: Array<{
|
|
77
|
+
id: string;
|
|
78
|
+
operation: string;
|
|
79
|
+
error: string;
|
|
80
|
+
}>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Authentication configuration for URL-based ingestion
|
|
84
|
+
*/
|
|
85
|
+
type URLSourceAuth = {
|
|
86
|
+
type: 'bearer';
|
|
87
|
+
token: string;
|
|
88
|
+
} | {
|
|
89
|
+
type: 'basic';
|
|
90
|
+
username: string;
|
|
91
|
+
password: string;
|
|
92
|
+
} | {
|
|
93
|
+
type: 'api-key';
|
|
94
|
+
header: string;
|
|
95
|
+
key: string;
|
|
96
|
+
} | {
|
|
97
|
+
type: 'custom';
|
|
98
|
+
headers: Record<string, string>;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Configuration for transforming external data to RAGDocuments
|
|
102
|
+
*/
|
|
103
|
+
interface DataTransform {
|
|
104
|
+
documentPath?: string;
|
|
105
|
+
fieldMapping?: {
|
|
106
|
+
id?: string;
|
|
107
|
+
content?: string;
|
|
108
|
+
[key: string]: string | undefined;
|
|
109
|
+
};
|
|
110
|
+
customTransform?: (data: any) => RAGDocument[];
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Schedule configuration for recurring ingestion
|
|
114
|
+
*/
|
|
115
|
+
interface IngestionSchedule {
|
|
116
|
+
cron?: string;
|
|
117
|
+
interval?: number;
|
|
118
|
+
timezone?: string;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* URL source configuration for data ingestion
|
|
122
|
+
*/
|
|
123
|
+
interface URLSource {
|
|
124
|
+
url: string;
|
|
125
|
+
type: 'json' | 'csv' | 'xml' | 'api';
|
|
126
|
+
auth?: URLSourceAuth;
|
|
127
|
+
transform?: DataTransform;
|
|
128
|
+
schedule?: IngestionSchedule;
|
|
129
|
+
headers?: Record<string, string>;
|
|
130
|
+
timeout?: number;
|
|
131
|
+
metadata?: Record<string, any>;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Result of URL-based ingestion
|
|
135
|
+
*/
|
|
136
|
+
interface URLIngestResult extends IngestResult {
|
|
137
|
+
sourceUrl: string;
|
|
138
|
+
fetchedAt: Date;
|
|
139
|
+
documentsFetched: number;
|
|
140
|
+
scheduleId?: string;
|
|
141
|
+
}
|
|
142
|
+
interface RAGPlugin extends BasePlugin {
|
|
143
|
+
type: 'rag';
|
|
144
|
+
/**
|
|
145
|
+
* Retrieve contextual information for a message
|
|
146
|
+
*/
|
|
147
|
+
retrieveContext(message: string, options: {
|
|
148
|
+
agentId: string;
|
|
149
|
+
threadId?: string;
|
|
150
|
+
filters?: Record<string, any>;
|
|
151
|
+
metadata?: Record<string, any>;
|
|
152
|
+
}): Promise<RAGContext>;
|
|
153
|
+
/**
|
|
154
|
+
* Optional: Format the context for the LLM
|
|
155
|
+
* If not provided, RAGContext.content will be used directly
|
|
156
|
+
*/
|
|
157
|
+
formatContext?(context: RAGContext): string;
|
|
158
|
+
/**
|
|
159
|
+
* Optional: Ingest documents into the RAG system
|
|
160
|
+
* Allows plugins to provide their own indexing logic
|
|
161
|
+
*/
|
|
162
|
+
ingest?(documents: RAGDocument[], options?: IngestOptions): Promise<IngestResult>;
|
|
163
|
+
/**
|
|
164
|
+
* Optional: Ingest documents from a URL source
|
|
165
|
+
* Supports CSV, JSON, XML, and API endpoints with authentication and scheduling
|
|
166
|
+
*/
|
|
167
|
+
ingestFromUrl?(source: URLSource, options?: IngestOptions): Promise<URLIngestResult>;
|
|
168
|
+
/**
|
|
169
|
+
* Optional: Handle webhook payloads for real-time updates
|
|
170
|
+
* Useful for product updates, inventory changes, etc.
|
|
171
|
+
*/
|
|
172
|
+
handleWebhook?(payload: any, source: string, options?: IngestOptions): Promise<IngestResult>;
|
|
173
|
+
/**
|
|
174
|
+
* Optional: Update a single document
|
|
175
|
+
*/
|
|
176
|
+
update?(id: string, document: Partial<RAGDocument>, options?: IngestOptions): Promise<void>;
|
|
177
|
+
/**
|
|
178
|
+
* Optional: Delete document(s) by ID
|
|
179
|
+
*/
|
|
180
|
+
delete?(ids: string | string[], options?: IngestOptions): Promise<number>;
|
|
181
|
+
/**
|
|
182
|
+
* Optional: Bulk operations for efficient batch processing
|
|
183
|
+
*/
|
|
184
|
+
bulk?(operations: BulkOperation[], options?: IngestOptions): Promise<BulkResult>;
|
|
185
|
+
}
|
|
186
|
+
interface Tool {
|
|
187
|
+
name: string;
|
|
188
|
+
description: string;
|
|
189
|
+
parameters: Record<string, any>;
|
|
190
|
+
execute: (args: any) => Promise<any>;
|
|
191
|
+
}
|
|
192
|
+
interface ToolPlugin extends BasePlugin {
|
|
193
|
+
type: 'tool';
|
|
194
|
+
getTools(): Tool[];
|
|
195
|
+
}
|
|
196
|
+
interface MiddlewarePlugin extends BasePlugin {
|
|
197
|
+
type: 'middleware';
|
|
198
|
+
beforeRequest?(messages: any[], context: {
|
|
199
|
+
agentId: string;
|
|
200
|
+
threadId?: string;
|
|
201
|
+
}): Promise<{
|
|
202
|
+
messages: any[];
|
|
203
|
+
metadata?: any;
|
|
204
|
+
}>;
|
|
205
|
+
afterResponse?(response: string, context: {
|
|
206
|
+
agentId: string;
|
|
207
|
+
threadId?: string;
|
|
208
|
+
metadata?: any;
|
|
209
|
+
}): Promise<{
|
|
210
|
+
response: string;
|
|
211
|
+
metadata?: any;
|
|
212
|
+
}>;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Performance timing breakdown
|
|
216
|
+
*/
|
|
217
|
+
interface PerformanceTimings {
|
|
218
|
+
total: number;
|
|
219
|
+
llmApiTime?: number;
|
|
220
|
+
ragRetrievalTime?: number;
|
|
221
|
+
pluginExecutionTime?: number;
|
|
222
|
+
dbQueryTime?: number;
|
|
223
|
+
timeToFirstToken?: number;
|
|
224
|
+
timeToLastToken?: number;
|
|
225
|
+
queueTime?: number;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* RAG-specific metrics
|
|
229
|
+
*/
|
|
230
|
+
interface RAGMetrics {
|
|
231
|
+
enabled: boolean;
|
|
232
|
+
documentsRetrieved?: number;
|
|
233
|
+
vectorSearchTime?: number;
|
|
234
|
+
embeddingTime?: number;
|
|
235
|
+
cacheHit?: boolean;
|
|
236
|
+
avgSimilarityScore?: number;
|
|
237
|
+
rerankTime?: number;
|
|
238
|
+
contextLength?: number;
|
|
239
|
+
contextTokens?: number;
|
|
240
|
+
sourcesCount?: number;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Token and cost metrics
|
|
244
|
+
*/
|
|
245
|
+
interface TokenMetrics {
|
|
246
|
+
promptTokens: number;
|
|
247
|
+
completionTokens: number;
|
|
248
|
+
totalTokens: number;
|
|
249
|
+
estimatedCost?: number;
|
|
250
|
+
embeddingTokens?: number;
|
|
251
|
+
embeddingCost?: number;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Request tracking data (extended)
|
|
255
|
+
*/
|
|
256
|
+
interface RequestTrackingData {
|
|
257
|
+
agentId: string;
|
|
258
|
+
threadId?: string;
|
|
259
|
+
userId?: string;
|
|
260
|
+
organizationId?: string;
|
|
261
|
+
message: string;
|
|
262
|
+
messageLength: number;
|
|
263
|
+
timestamp: Date;
|
|
264
|
+
model?: string;
|
|
265
|
+
provider?: string;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Response tracking data (extended)
|
|
269
|
+
*/
|
|
270
|
+
interface ResponseTrackingData {
|
|
271
|
+
agentId: string;
|
|
272
|
+
threadId?: string;
|
|
273
|
+
userId?: string;
|
|
274
|
+
organizationId?: string;
|
|
275
|
+
response: string;
|
|
276
|
+
responseLength: number;
|
|
277
|
+
timestamp: Date;
|
|
278
|
+
timings: PerformanceTimings;
|
|
279
|
+
tokens: TokenMetrics;
|
|
280
|
+
rag?: RAGMetrics;
|
|
281
|
+
success: boolean;
|
|
282
|
+
errorType?: string;
|
|
283
|
+
errorMessage?: string;
|
|
284
|
+
model?: string;
|
|
285
|
+
provider?: string;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Error tracking data
|
|
289
|
+
*/
|
|
290
|
+
interface ErrorTrackingData {
|
|
291
|
+
agentId: string;
|
|
292
|
+
threadId?: string;
|
|
293
|
+
timestamp: Date;
|
|
294
|
+
errorType: string;
|
|
295
|
+
errorMessage: string;
|
|
296
|
+
errorCode?: string;
|
|
297
|
+
isRetryable?: boolean;
|
|
298
|
+
component?: 'llm' | 'rag' | 'plugin' | 'database' | 'network';
|
|
299
|
+
}
|
|
300
|
+
interface AnalyticsPlugin extends BasePlugin {
|
|
301
|
+
type: 'analytics';
|
|
302
|
+
/**
|
|
303
|
+
* Track incoming request (basic - for backwards compatibility)
|
|
304
|
+
*/
|
|
305
|
+
trackRequest(data: {
|
|
306
|
+
agentId: string;
|
|
307
|
+
threadId?: string;
|
|
308
|
+
message: string;
|
|
309
|
+
timestamp: Date;
|
|
310
|
+
}): Promise<void>;
|
|
311
|
+
/**
|
|
312
|
+
* Track response (basic - for backwards compatibility)
|
|
313
|
+
*/
|
|
314
|
+
trackResponse(data: {
|
|
315
|
+
agentId: string;
|
|
316
|
+
threadId?: string;
|
|
317
|
+
response: string;
|
|
318
|
+
latency: number;
|
|
319
|
+
tokensUsed?: number;
|
|
320
|
+
timestamp: Date;
|
|
321
|
+
}): Promise<void>;
|
|
322
|
+
/**
|
|
323
|
+
* Track request with extended data (optional)
|
|
324
|
+
*/
|
|
325
|
+
trackRequestExtended?(data: RequestTrackingData): Promise<void>;
|
|
326
|
+
/**
|
|
327
|
+
* Track response with extended metrics (optional)
|
|
328
|
+
*/
|
|
329
|
+
trackResponseExtended?(data: ResponseTrackingData): Promise<void>;
|
|
330
|
+
/**
|
|
331
|
+
* Track errors (optional)
|
|
332
|
+
*/
|
|
333
|
+
trackError?(data: ErrorTrackingData): Promise<void>;
|
|
334
|
+
/**
|
|
335
|
+
* Get aggregated metrics (optional)
|
|
336
|
+
*/
|
|
337
|
+
getMetrics?(options?: {
|
|
338
|
+
agentId?: string;
|
|
339
|
+
startDate?: Date;
|
|
340
|
+
endDate?: Date;
|
|
341
|
+
groupBy?: 'hour' | 'day' | 'week' | 'month';
|
|
342
|
+
}): Promise<Record<string, any>>;
|
|
343
|
+
}
|
|
344
|
+
type Plugin = RAGPlugin | ToolPlugin | MiddlewarePlugin | AnalyticsPlugin;
|
|
345
|
+
|
|
346
|
+
type ProviderType = 'openai' | 'anthropic' | 'google';
|
|
347
|
+
interface ProviderConfig {
|
|
348
|
+
openai?: {
|
|
349
|
+
apiKey: string;
|
|
350
|
+
};
|
|
351
|
+
anthropic?: {
|
|
352
|
+
apiKey: string;
|
|
353
|
+
};
|
|
354
|
+
google?: {
|
|
355
|
+
apiKey: string;
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* RAG configuration for zero-config RAG setup
|
|
360
|
+
*/
|
|
361
|
+
interface RAGConfig {
|
|
362
|
+
/**
|
|
363
|
+
* Enable RAG with default plugin
|
|
364
|
+
*/
|
|
365
|
+
enabled: boolean;
|
|
366
|
+
/**
|
|
367
|
+
* API key for embedding provider
|
|
368
|
+
* If not provided, will use the provider's API key from ClientConfig
|
|
369
|
+
*/
|
|
370
|
+
embeddingProviderApiKey?: string;
|
|
371
|
+
/**
|
|
372
|
+
* Embedding provider to use
|
|
373
|
+
* @default 'openai'
|
|
374
|
+
*/
|
|
375
|
+
embeddingProvider?: 'openai';
|
|
376
|
+
/**
|
|
377
|
+
* Embedding model to use
|
|
378
|
+
* @default 'text-embedding-3-small'
|
|
379
|
+
*/
|
|
380
|
+
embeddingModel?: string;
|
|
381
|
+
/**
|
|
382
|
+
* Number of results to return
|
|
383
|
+
* @default 5
|
|
384
|
+
*/
|
|
385
|
+
limit?: number;
|
|
386
|
+
}
|
|
387
|
+
interface AgentConfig {
|
|
388
|
+
name: string;
|
|
389
|
+
description?: string;
|
|
390
|
+
instructions: string;
|
|
391
|
+
provider: ProviderType;
|
|
392
|
+
model: string;
|
|
393
|
+
userId: string;
|
|
394
|
+
metadata?: Record<string, any>;
|
|
395
|
+
organizationId?: string;
|
|
396
|
+
phone?: string;
|
|
397
|
+
plugins?: Plugin[];
|
|
398
|
+
rag?: RAGConfig;
|
|
399
|
+
}
|
|
400
|
+
interface AgentData extends AgentConfig {
|
|
401
|
+
id: string;
|
|
402
|
+
createdAt: Date;
|
|
403
|
+
updatedAt: Date;
|
|
404
|
+
files: AgentFile[];
|
|
405
|
+
}
|
|
406
|
+
interface AgentFile {
|
|
407
|
+
fileId: string;
|
|
408
|
+
filename: string;
|
|
409
|
+
addedAt: Date;
|
|
410
|
+
}
|
|
411
|
+
interface ThreadConfig {
|
|
412
|
+
agentId: string;
|
|
413
|
+
userId: string;
|
|
414
|
+
name?: string;
|
|
415
|
+
metadata?: Record<string, any>;
|
|
416
|
+
organizationId?: string;
|
|
417
|
+
endUserId?: string;
|
|
418
|
+
}
|
|
419
|
+
interface ThreadData extends ThreadConfig {
|
|
420
|
+
id: string;
|
|
421
|
+
createdAt: Date;
|
|
422
|
+
updatedAt: Date;
|
|
423
|
+
messages: MessageData[];
|
|
424
|
+
isPendingThread: boolean;
|
|
425
|
+
}
|
|
426
|
+
type MessageRole = 'user' | 'assistant' | 'system';
|
|
427
|
+
interface MessageData {
|
|
428
|
+
id: string;
|
|
429
|
+
role: MessageRole;
|
|
430
|
+
content: string;
|
|
431
|
+
timestamp: Date;
|
|
432
|
+
metadata?: Record<string, any>;
|
|
433
|
+
attachments?: MessageAttachment[];
|
|
434
|
+
}
|
|
435
|
+
interface MessageAttachment {
|
|
436
|
+
fileId: string;
|
|
437
|
+
filename: string;
|
|
438
|
+
contentType: string;
|
|
439
|
+
size: number;
|
|
440
|
+
}
|
|
441
|
+
interface ChatRequest {
|
|
442
|
+
threadId: string;
|
|
443
|
+
message: string;
|
|
444
|
+
attachments?: MessageAttachment[];
|
|
445
|
+
useRAG?: boolean;
|
|
446
|
+
ragFilters?: Record<string, any>;
|
|
447
|
+
contextLength?: number;
|
|
448
|
+
}
|
|
449
|
+
interface ChatResponse {
|
|
450
|
+
reply: string;
|
|
451
|
+
messageId: string;
|
|
452
|
+
threadId: string;
|
|
453
|
+
timestamp: Date;
|
|
454
|
+
metadata?: Record<string, any>;
|
|
455
|
+
usage?: {
|
|
456
|
+
promptTokens: number;
|
|
457
|
+
completionTokens: number;
|
|
458
|
+
totalTokens: number;
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
interface StreamCallbacks {
|
|
462
|
+
onChunk: (chunk: string) => void;
|
|
463
|
+
onComplete: (fullResponse: string, metadata?: Record<string, any>) => void;
|
|
464
|
+
onError: (error: Error) => void;
|
|
465
|
+
}
|
|
466
|
+
interface StorageAdapter {
|
|
467
|
+
createAgent(config: AgentConfig): Promise<string>;
|
|
468
|
+
getAgent(agentId: string): Promise<AgentData | null>;
|
|
469
|
+
updateAgent(agentId: string, updates: Partial<AgentConfig>): Promise<void>;
|
|
470
|
+
deleteAgent(agentId: string): Promise<void>;
|
|
471
|
+
listAgents(userId: string, organizationId?: string): Promise<AgentData[]>;
|
|
472
|
+
createThread(config: ThreadConfig): Promise<string>;
|
|
473
|
+
getThread(threadId: string): Promise<ThreadData | null>;
|
|
474
|
+
updateThread(threadId: string, updates: Partial<ThreadConfig>): Promise<void>;
|
|
475
|
+
deleteThread(threadId: string): Promise<void>;
|
|
476
|
+
listThreads(filters: {
|
|
477
|
+
userId?: string;
|
|
478
|
+
agentId?: string;
|
|
479
|
+
organizationId?: string;
|
|
480
|
+
}): Promise<ThreadData[]>;
|
|
481
|
+
addMessage(threadId: string, role: MessageRole, content: string, attachments?: MessageAttachment[]): Promise<string>;
|
|
482
|
+
getMessages(threadId: string, limit?: number): Promise<MessageData[]>;
|
|
483
|
+
getConversationContext(threadId: string, maxMessages?: number): Promise<Array<{
|
|
484
|
+
role: string;
|
|
485
|
+
content: string;
|
|
486
|
+
}>>;
|
|
487
|
+
}
|
|
488
|
+
interface ClientConfig {
|
|
489
|
+
storage: StorageAdapter;
|
|
490
|
+
providers: ProviderConfig;
|
|
491
|
+
}
|
|
492
|
+
declare class AgentSDKError extends Error {
|
|
493
|
+
constructor(message: string);
|
|
494
|
+
}
|
|
495
|
+
declare class AgentNotFoundError extends AgentSDKError {
|
|
496
|
+
constructor(agentId: string);
|
|
497
|
+
}
|
|
498
|
+
declare class ThreadNotFoundError extends AgentSDKError {
|
|
499
|
+
constructor(threadId: string);
|
|
500
|
+
}
|
|
501
|
+
declare class ProviderNotFoundError extends AgentSDKError {
|
|
502
|
+
constructor(provider: string);
|
|
503
|
+
}
|
|
504
|
+
declare class InvalidConfigError extends AgentSDKError {
|
|
505
|
+
constructor(message: string);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
interface MongoDBStorageConfig {
|
|
509
|
+
uri: string;
|
|
510
|
+
dbName?: string;
|
|
511
|
+
agentsCollection?: string;
|
|
512
|
+
threadsCollection?: string;
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* MongoDB Storage Adapter
|
|
516
|
+
* Provides persistent storage for agents and threads using MongoDB
|
|
517
|
+
*/
|
|
518
|
+
declare class MongoDBStorage implements StorageAdapter {
|
|
519
|
+
private client;
|
|
520
|
+
private db;
|
|
521
|
+
private config;
|
|
522
|
+
constructor(config: MongoDBStorageConfig | string);
|
|
523
|
+
private ensureConnection;
|
|
524
|
+
disconnect(): Promise<void>;
|
|
525
|
+
createAgent(config: AgentConfig): Promise<string>;
|
|
526
|
+
getAgent(agentId: string): Promise<AgentData | null>;
|
|
527
|
+
updateAgent(agentId: string, updates: Partial<AgentConfig>): Promise<void>;
|
|
528
|
+
deleteAgent(agentId: string): Promise<void>;
|
|
529
|
+
listAgents(userId: string, organizationId?: string): Promise<AgentData[]>;
|
|
530
|
+
createThread(config: ThreadConfig): Promise<string>;
|
|
531
|
+
getThread(threadId: string): Promise<ThreadData | null>;
|
|
532
|
+
updateThread(threadId: string, updates: Partial<ThreadConfig>): Promise<void>;
|
|
533
|
+
deleteThread(threadId: string): Promise<void>;
|
|
534
|
+
listThreads(filters: {
|
|
535
|
+
userId?: string;
|
|
536
|
+
agentId?: string;
|
|
537
|
+
organizationId?: string;
|
|
538
|
+
}): Promise<ThreadData[]>;
|
|
539
|
+
addMessage(threadId: string, role: MessageRole, content: string, attachments?: MessageAttachment[]): Promise<string>;
|
|
540
|
+
getMessages(threadId: string, limit?: number): Promise<MessageData[]>;
|
|
541
|
+
getConversationContext(threadId: string, maxMessages?: number): Promise<Array<{
|
|
542
|
+
role: string;
|
|
543
|
+
content: string;
|
|
544
|
+
}>>;
|
|
545
|
+
private agentDocToData;
|
|
546
|
+
private threadDocToData;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* In-Memory Storage Adapter
|
|
551
|
+
* Provides temporary storage for agents and threads (useful for testing and development)
|
|
552
|
+
*/
|
|
553
|
+
declare class MemoryStorage implements StorageAdapter {
|
|
554
|
+
private agents;
|
|
555
|
+
private threads;
|
|
556
|
+
private idCounter;
|
|
557
|
+
private generateId;
|
|
558
|
+
createAgent(config: AgentConfig): Promise<string>;
|
|
559
|
+
getAgent(agentId: string): Promise<AgentData | null>;
|
|
560
|
+
updateAgent(agentId: string, updates: Partial<AgentConfig>): Promise<void>;
|
|
561
|
+
deleteAgent(agentId: string): Promise<void>;
|
|
562
|
+
listAgents(userId: string, organizationId?: string): Promise<AgentData[]>;
|
|
563
|
+
createThread(config: ThreadConfig): Promise<string>;
|
|
564
|
+
getThread(threadId: string): Promise<ThreadData | null>;
|
|
565
|
+
updateThread(threadId: string, updates: Partial<ThreadConfig>): Promise<void>;
|
|
566
|
+
deleteThread(threadId: string): Promise<void>;
|
|
567
|
+
listThreads(filters: {
|
|
568
|
+
userId?: string;
|
|
569
|
+
agentId?: string;
|
|
570
|
+
organizationId?: string;
|
|
571
|
+
}): Promise<ThreadData[]>;
|
|
572
|
+
addMessage(threadId: string, role: MessageRole, content: string, attachments?: MessageAttachment[]): Promise<string>;
|
|
573
|
+
getMessages(threadId: string, limit?: number): Promise<MessageData[]>;
|
|
574
|
+
getConversationContext(threadId: string, maxMessages?: number): Promise<Array<{
|
|
575
|
+
role: string;
|
|
576
|
+
content: string;
|
|
577
|
+
}>>;
|
|
578
|
+
/**
|
|
579
|
+
* Clear all stored data
|
|
580
|
+
*/
|
|
581
|
+
clear(): void;
|
|
582
|
+
/**
|
|
583
|
+
* Get statistics about stored data
|
|
584
|
+
*/
|
|
585
|
+
getStats(): {
|
|
586
|
+
agents: number;
|
|
587
|
+
threads: number;
|
|
588
|
+
messages: number;
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Upstash Redis configuration
|
|
594
|
+
*/
|
|
595
|
+
interface UpstashStorageConfig {
|
|
596
|
+
/**
|
|
597
|
+
* Upstash Redis REST URL
|
|
598
|
+
* @example "https://your-redis.upstash.io"
|
|
599
|
+
*/
|
|
600
|
+
url: string;
|
|
601
|
+
/**
|
|
602
|
+
* Upstash Redis REST token
|
|
603
|
+
*/
|
|
604
|
+
token: string;
|
|
605
|
+
/**
|
|
606
|
+
* Optional key prefix for multi-tenancy
|
|
607
|
+
* @default "snap-agent"
|
|
608
|
+
*/
|
|
609
|
+
prefix?: string;
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Upstash Redis Storage Adapter
|
|
613
|
+
*
|
|
614
|
+
* Edge-compatible persistent storage using Upstash Redis REST API.
|
|
615
|
+
* Works with Cloudflare Workers, Vercel Edge, Deno Deploy, and any WinterCG runtime.
|
|
616
|
+
*
|
|
617
|
+
* @example
|
|
618
|
+
* ```typescript
|
|
619
|
+
* import { UpstashStorage } from '@snap-agent/core/storage';
|
|
620
|
+
*
|
|
621
|
+
* const storage = new UpstashStorage({
|
|
622
|
+
* url: process.env.UPSTASH_REDIS_REST_URL!,
|
|
623
|
+
* token: process.env.UPSTASH_REDIS_REST_TOKEN!,
|
|
624
|
+
* });
|
|
625
|
+
*
|
|
626
|
+
* const client = createClient({
|
|
627
|
+
* storage,
|
|
628
|
+
* providers: { openai: { apiKey: process.env.OPENAI_API_KEY! } },
|
|
629
|
+
* });
|
|
630
|
+
* ```
|
|
631
|
+
*/
|
|
632
|
+
declare class UpstashStorage implements StorageAdapter {
|
|
633
|
+
private url;
|
|
634
|
+
private token;
|
|
635
|
+
private prefix;
|
|
636
|
+
constructor(config: UpstashStorageConfig);
|
|
637
|
+
private command;
|
|
638
|
+
private pipeline;
|
|
639
|
+
private key;
|
|
640
|
+
private generateId;
|
|
641
|
+
createAgent(config: AgentConfig): Promise<string>;
|
|
642
|
+
getAgent(agentId: string): Promise<AgentData | null>;
|
|
643
|
+
updateAgent(agentId: string, updates: Partial<AgentConfig>): Promise<void>;
|
|
644
|
+
deleteAgent(agentId: string): Promise<void>;
|
|
645
|
+
listAgents(userId: string, organizationId?: string): Promise<AgentData[]>;
|
|
646
|
+
createThread(config: ThreadConfig): Promise<string>;
|
|
647
|
+
getThread(threadId: string): Promise<ThreadData | null>;
|
|
648
|
+
updateThread(threadId: string, updates: Partial<ThreadConfig>): Promise<void>;
|
|
649
|
+
deleteThread(threadId: string): Promise<void>;
|
|
650
|
+
listThreads(filters: {
|
|
651
|
+
userId?: string;
|
|
652
|
+
agentId?: string;
|
|
653
|
+
organizationId?: string;
|
|
654
|
+
}): Promise<ThreadData[]>;
|
|
655
|
+
addMessage(threadId: string, role: MessageRole, content: string, attachments?: MessageAttachment[]): Promise<string>;
|
|
656
|
+
getMessages(threadId: string, limit?: number): Promise<MessageData[]>;
|
|
657
|
+
getConversationContext(threadId: string, maxMessages?: number): Promise<Array<{
|
|
658
|
+
role: string;
|
|
659
|
+
content: string;
|
|
660
|
+
}>>;
|
|
661
|
+
private parseStoredAgent;
|
|
662
|
+
private parseStoredThread;
|
|
663
|
+
/**
|
|
664
|
+
* Test connection to Upstash Redis
|
|
665
|
+
*/
|
|
666
|
+
ping(): Promise<boolean>;
|
|
667
|
+
/**
|
|
668
|
+
* Clear all data with this prefix (use with caution!)
|
|
669
|
+
*/
|
|
670
|
+
clear(): Promise<void>;
|
|
671
|
+
/**
|
|
672
|
+
* Get storage statistics
|
|
673
|
+
*/
|
|
674
|
+
getStats(): Promise<{
|
|
675
|
+
agents: number;
|
|
676
|
+
threads: number;
|
|
677
|
+
}>;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
export { type AgentData as A, type BulkOperation as B, type ClientConfig as C, AgentSDKError as D, type ErrorTrackingData as E, AgentNotFoundError as F, ThreadNotFoundError as G, ProviderNotFoundError as H, type IngestOptions as I, InvalidConfigError as J, MongoDBStorage as K, MemoryStorage as L, type MessageRole as M, UpstashStorage as N, type MongoDBStorageConfig as O, type ProviderConfig as P, type UpstashStorageConfig as Q, type RAGDocument as R, type StorageAdapter as S, type ThreadData as T, type URLSource as U, type ProviderType as a, type AgentConfig as b, type AgentFile as c, type Plugin as d, type IngestResult as e, type BulkResult as f, type URLIngestResult as g, type ThreadConfig as h, type MessageAttachment as i, type MessageData as j, type ChatRequest as k, type ChatResponse as l, type StreamCallbacks as m, type RAGPlugin as n, type ToolPlugin as o, type MiddlewarePlugin as p, type AnalyticsPlugin as q, type RAGContext as r, type RAGConfig as s, type BasePlugin as t, type Tool as u, type PerformanceTimings as v, type RAGMetrics as w, type TokenMetrics as x, type RequestTrackingData as y, type ResponseTrackingData as z };
|