@usewhisper/sdk 0.2.5 → 1.0.1

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.
@@ -5,9 +5,17 @@
5
5
  interface WhisperConfig {
6
6
  apiKey: string;
7
7
  baseUrl?: string;
8
+ project?: string;
9
+ orgId?: string;
10
+ timeoutMs?: number;
11
+ retry?: {
12
+ maxAttempts?: number;
13
+ baseDelayMs?: number;
14
+ maxDelayMs?: number;
15
+ };
8
16
  }
9
17
  interface QueryParams {
10
- project: string;
18
+ project?: string;
11
19
  query: string;
12
20
  top_k?: number;
13
21
  threshold?: number;
@@ -87,10 +95,38 @@ interface Memory {
87
95
  createdAt: string;
88
96
  updatedAt: string;
89
97
  }
98
+ type WhisperErrorCode = "INVALID_API_KEY" | "PROJECT_NOT_FOUND" | "PROJECT_AMBIGUOUS" | "RATE_LIMITED" | "TEMPORARY_UNAVAILABLE" | "NETWORK_ERROR" | "TIMEOUT" | "REQUEST_FAILED" | "MISSING_PROJECT";
99
+ declare class WhisperError extends Error {
100
+ code: WhisperErrorCode;
101
+ status?: number;
102
+ retryable: boolean;
103
+ details?: unknown;
104
+ constructor(args: {
105
+ code: WhisperErrorCode;
106
+ message: string;
107
+ status?: number;
108
+ retryable?: boolean;
109
+ details?: unknown;
110
+ });
111
+ }
90
112
  declare class WhisperContext {
91
113
  private apiKey;
92
114
  private baseUrl;
115
+ private defaultProject?;
116
+ private orgId?;
117
+ private timeoutMs;
118
+ private retryConfig;
119
+ private projectRefToId;
120
+ private projectCache;
121
+ private projectCacheExpiresAt;
93
122
  constructor(config: WhisperConfig);
123
+ withProject(project: string): WhisperContext;
124
+ private getRequiredProject;
125
+ private refreshProjectCache;
126
+ private resolveProjectId;
127
+ private getProjectRefCandidates;
128
+ private withProjectRefFallback;
129
+ private classifyError;
94
130
  private request;
95
131
  query(params: QueryParams): Promise<QueryResult>;
96
132
  createProject(params: {
@@ -123,30 +159,37 @@ declare class WhisperContext {
123
159
  }>): Promise<{
124
160
  ingested: number;
125
161
  }>;
162
+ addContext(params: {
163
+ project?: string;
164
+ content: string;
165
+ title?: string;
166
+ metadata?: Record<string, any>;
167
+ }): Promise<{
168
+ ingested: number;
169
+ }>;
126
170
  addMemory(params: {
127
- project: string;
171
+ project?: string;
128
172
  content: string;
129
- memory_type?: "factual" | "episodic" | "semantic" | "procedural";
173
+ memory_type?: "factual" | "preference" | "event" | "relationship" | "opinion" | "goal" | "instruction";
130
174
  user_id?: string;
131
175
  session_id?: string;
132
176
  agent_id?: string;
133
177
  importance?: number;
134
178
  metadata?: Record<string, any>;
135
179
  expires_in_seconds?: number;
136
- }): Promise<Memory>;
180
+ }): Promise<{
181
+ id: string;
182
+ success: boolean;
183
+ }>;
137
184
  searchMemories(params: {
138
- project: string;
185
+ project?: string;
139
186
  query: string;
140
187
  user_id?: string;
141
188
  session_id?: string;
142
189
  agent_id?: string;
143
- memory_type?: "factual" | "episodic" | "semantic" | "procedural";
190
+ memory_type?: "factual" | "preference" | "event" | "relationship" | "opinion" | "goal" | "instruction";
144
191
  top_k?: number;
145
- }): Promise<{
146
- memories: Array<Memory & {
147
- score: number;
148
- }>;
149
- }>;
192
+ }): Promise<any>;
150
193
  createApiKey(params: {
151
194
  name: string;
152
195
  scopes?: string[];
@@ -161,12 +204,9 @@ declare class WhisperContext {
161
204
  keys: any[];
162
205
  }>;
163
206
  getUsage(days?: number): Promise<any>;
164
- /**
165
- * SOTA Memory Search - Search memories with temporal and type filtering
166
- */
167
207
  searchMemoriesSOTA(params: {
168
208
  query: string;
169
- project: string;
209
+ project?: string;
170
210
  user_id?: string;
171
211
  session_id?: string;
172
212
  question_date?: string;
@@ -176,11 +216,8 @@ declare class WhisperContext {
176
216
  include_chunks?: boolean;
177
217
  include_relations?: boolean;
178
218
  }): Promise<any>;
179
- /**
180
- * Ingest Session - Create memories from a conversation
181
- */
182
219
  ingestSession(params: {
183
- project: string;
220
+ project?: string;
184
221
  session_id: string;
185
222
  user_id?: string;
186
223
  messages: Array<{
@@ -195,41 +232,29 @@ declare class WhisperContext {
195
232
  memories_invalidated: number;
196
233
  errors?: string[];
197
234
  }>;
198
- /**
199
- * Get Session Memories - Recent memories from a session
200
- */
201
235
  getSessionMemories(params: {
202
236
  session_id: string;
203
- project: string;
237
+ project?: string;
204
238
  limit?: number;
205
239
  since_date?: string;
206
240
  }): Promise<{
207
241
  memories: any[];
208
242
  count: number;
209
243
  }>;
210
- /**
211
- * Get User Profile - Long-term user preferences and facts
212
- */
213
244
  getUserProfile(params: {
214
245
  user_id: string;
215
- project: string;
246
+ project?: string;
216
247
  memory_types?: string;
217
248
  }): Promise<{
218
249
  user_id: string;
219
250
  memories: any[];
220
251
  count: number;
221
252
  }>;
222
- /**
223
- * Get Memory Versions - Version chain history
224
- */
225
253
  getMemoryVersions(memoryId: string): Promise<{
226
254
  memory_id: string;
227
255
  versions: any[];
228
256
  count: number;
229
257
  }>;
230
- /**
231
- * Update Memory - Create a new version
232
- */
233
258
  updateMemory(memoryId: string, params: {
234
259
  content: string;
235
260
  reasoning?: string;
@@ -238,36 +263,24 @@ declare class WhisperContext {
238
263
  new_memory_id: string;
239
264
  old_memory_id: string;
240
265
  }>;
241
- /**
242
- * Delete Memory - Soft delete
243
- */
244
266
  deleteMemory(memoryId: string): Promise<{
245
267
  success: boolean;
246
268
  deleted: string;
247
269
  }>;
248
- /**
249
- * Get Memory Relations - Graph connections
250
- */
251
270
  getMemoryRelations(memoryId: string): Promise<{
252
271
  memory_id: string;
253
272
  relations: any[];
254
273
  count: number;
255
274
  }>;
256
- /**
257
- * Oracle Search - Tree-guided document navigation with research mode
258
- */
259
275
  oracleSearch(params: {
260
276
  query: string;
261
- project: string;
277
+ project?: string;
262
278
  max_results?: number;
263
279
  mode?: "search" | "research";
264
280
  max_steps?: number;
265
281
  }): Promise<any>;
266
- /**
267
- * Autosubscribe - Auto-index project dependencies
268
- */
269
282
  autosubscribe(params: {
270
- project: string;
283
+ project?: string;
271
284
  source: {
272
285
  type: "github" | "local";
273
286
  owner?: string;
@@ -285,12 +298,9 @@ declare class WhisperContext {
285
298
  dependencies?: any[];
286
299
  auto_sync_enabled: boolean;
287
300
  }>;
288
- /**
289
- * Create Shared Context - Save and share a conversation
290
- */
291
301
  createSharedContext(params: {
292
302
  session_id: string;
293
- project: string;
303
+ project?: string;
294
304
  title?: string;
295
305
  include_memories?: boolean;
296
306
  include_chunks?: boolean;
@@ -304,9 +314,6 @@ declare class WhisperContext {
304
314
  messages_count: number;
305
315
  expires_at: string;
306
316
  }>;
307
- /**
308
- * Load Shared Context - View shared context (public endpoint)
309
- */
310
317
  loadSharedContext(shareId: string): Promise<{
311
318
  share_id: string;
312
319
  title: string;
@@ -317,12 +324,9 @@ declare class WhisperContext {
317
324
  chunks?: any[];
318
325
  metadata: any;
319
326
  }>;
320
- /**
321
- * Resume from Shared Context - Fork shared context to new session
322
- */
323
327
  resumeFromSharedContext(params: {
324
328
  share_id: string;
325
- project: string;
329
+ project?: string;
326
330
  new_session_id?: string;
327
331
  }): Promise<{
328
332
  success: boolean;
@@ -331,20 +335,14 @@ declare class WhisperContext {
331
335
  messages_restored: number;
332
336
  chunks_restored: number;
333
337
  }>;
334
- /**
335
- * Consolidate Memories - Find and merge duplicates
336
- */
337
338
  consolidateMemories(params: {
338
- project: string;
339
+ project?: string;
339
340
  similarity_threshold?: number;
340
341
  auto_merge?: boolean;
341
342
  dry_run?: boolean;
342
343
  }): Promise<any>;
343
- /**
344
- * Update Importance Decay - Apply time-based relevance scoring
345
- */
346
344
  updateImportanceDecay(params: {
347
- project: string;
345
+ project?: string;
348
346
  decay_function?: "exponential" | "linear" | "logarithmic";
349
347
  half_life_days?: number;
350
348
  access_boost?: number;
@@ -357,16 +355,10 @@ declare class WhisperContext {
357
355
  memories_archived: number;
358
356
  config: any;
359
357
  }>;
360
- /**
361
- * Get Importance Statistics
362
- */
363
- getImportanceStats(project: string): Promise<{
358
+ getImportanceStats(project?: string): Promise<{
364
359
  project_id: string;
365
360
  statistics: any;
366
361
  }>;
367
- /**
368
- * Get Cache Statistics
369
- */
370
362
  getCacheStats(): Promise<{
371
363
  cache_type: string;
372
364
  hit_rate: number;
@@ -378,11 +370,8 @@ declare class WhisperContext {
378
370
  average_latency_ms: number;
379
371
  uptime_seconds: number;
380
372
  }>;
381
- /**
382
- * Warm Cache - Preload common queries
383
- */
384
373
  warmCache(params: {
385
- project: string;
374
+ project?: string;
386
375
  queries: string[];
387
376
  ttl_seconds?: number;
388
377
  }): Promise<{
@@ -391,9 +380,6 @@ declare class WhisperContext {
391
380
  errors: string[];
392
381
  cache_size_increase_bytes: number;
393
382
  }>;
394
- /**
395
- * Clear Cache Pattern
396
- */
397
383
  clearCache(params: {
398
384
  pattern?: string;
399
385
  clear_all?: boolean;
@@ -402,31 +388,172 @@ declare class WhisperContext {
402
388
  keys_cleared: number;
403
389
  bytes_freed: number;
404
390
  }>;
405
- /**
406
- * Get Cost Summary - Cost tracking overview
407
- */
408
- getCostSummary(params: {
391
+ getCostSummary(params?: {
409
392
  project?: string;
410
393
  start_date?: string;
411
394
  end_date?: string;
412
395
  }): Promise<any>;
413
- /**
414
- * Get Cost Breakdown - Detailed cost analysis
415
- */
416
- getCostBreakdown(params: {
396
+ getCostBreakdown(params?: {
417
397
  project?: string;
418
398
  group_by?: "model" | "task" | "day" | "hour";
419
399
  start_date?: string;
420
400
  end_date?: string;
421
401
  }): Promise<any>;
422
- /**
423
- * Get Savings Report - Compare actual vs always-Opus costs
424
- */
425
- getCostSavings(params: {
402
+ getCostSavings(params?: {
426
403
  project?: string;
427
404
  start_date?: string;
428
405
  end_date?: string;
429
406
  }): Promise<any>;
407
+ readonly projects: {
408
+ create: (params: {
409
+ name: string;
410
+ description?: string;
411
+ settings?: Record<string, any>;
412
+ }) => Promise<Project>;
413
+ list: () => Promise<{
414
+ projects: Project[];
415
+ }>;
416
+ get: (id: string) => Promise<Project & {
417
+ sources: Source[];
418
+ }>;
419
+ delete: (id: string) => Promise<{
420
+ deleted: boolean;
421
+ }>;
422
+ };
423
+ readonly sources: {
424
+ add: (projectId: string, params: {
425
+ name: string;
426
+ connector_type: string;
427
+ config: Record<string, any>;
428
+ sync_schedule?: string;
429
+ }) => Promise<Source>;
430
+ sync: (sourceId: string) => Promise<any>;
431
+ syncSource: (sourceId: string) => Promise<any>;
432
+ };
433
+ readonly memory: {
434
+ add: (params: Parameters<WhisperContext["addMemory"]>[0]) => Promise<{
435
+ id: string;
436
+ success: boolean;
437
+ }>;
438
+ search: (params: Parameters<WhisperContext["searchMemories"]>[0]) => Promise<any>;
439
+ searchSOTA: (params: Parameters<WhisperContext["searchMemoriesSOTA"]>[0]) => Promise<any>;
440
+ ingestSession: (params: Parameters<WhisperContext["ingestSession"]>[0]) => Promise<{
441
+ success: boolean;
442
+ memories_created: number;
443
+ relations_created: number;
444
+ memories_invalidated: number;
445
+ errors?: string[];
446
+ }>;
447
+ getSessionMemories: (params: Parameters<WhisperContext["getSessionMemories"]>[0]) => Promise<{
448
+ memories: any[];
449
+ count: number;
450
+ }>;
451
+ getUserProfile: (params: Parameters<WhisperContext["getUserProfile"]>[0]) => Promise<{
452
+ user_id: string;
453
+ memories: any[];
454
+ count: number;
455
+ }>;
456
+ getVersions: (memoryId: string) => Promise<{
457
+ memory_id: string;
458
+ versions: any[];
459
+ count: number;
460
+ }>;
461
+ update: (memoryId: string, params: Parameters<WhisperContext["updateMemory"]>[1]) => Promise<{
462
+ success: boolean;
463
+ new_memory_id: string;
464
+ old_memory_id: string;
465
+ }>;
466
+ delete: (memoryId: string) => Promise<{
467
+ success: boolean;
468
+ deleted: string;
469
+ }>;
470
+ getRelations: (memoryId: string) => Promise<{
471
+ memory_id: string;
472
+ relations: any[];
473
+ count: number;
474
+ }>;
475
+ consolidate: (params: Parameters<WhisperContext["consolidateMemories"]>[0]) => Promise<any>;
476
+ updateDecay: (params: Parameters<WhisperContext["updateImportanceDecay"]>[0]) => Promise<{
477
+ success: boolean;
478
+ memories_updated: number;
479
+ average_importance: number;
480
+ memories_archived: number;
481
+ config: any;
482
+ }>;
483
+ getImportanceStats: (project?: string) => Promise<{
484
+ project_id: string;
485
+ statistics: any;
486
+ }>;
487
+ };
488
+ readonly keys: {
489
+ create: (params: Parameters<WhisperContext["createApiKey"]>[0]) => Promise<{
490
+ key: string;
491
+ prefix: string;
492
+ name: string;
493
+ }>;
494
+ list: () => Promise<{
495
+ keys: any[];
496
+ }>;
497
+ getUsage: (days?: number) => Promise<any>;
498
+ };
499
+ readonly oracle: {
500
+ search: (params: Parameters<WhisperContext["oracleSearch"]>[0]) => Promise<any>;
501
+ };
502
+ readonly context: {
503
+ createShare: (params: Parameters<WhisperContext["createSharedContext"]>[0]) => Promise<{
504
+ success: boolean;
505
+ share_id: string;
506
+ share_url: string;
507
+ title: string;
508
+ memories_count: number;
509
+ messages_count: number;
510
+ expires_at: string;
511
+ }>;
512
+ loadShare: (shareId: string) => Promise<{
513
+ share_id: string;
514
+ title: string;
515
+ created_at: string;
516
+ expires_at: string;
517
+ memories: any[];
518
+ messages: any[];
519
+ chunks?: any[];
520
+ metadata: any;
521
+ }>;
522
+ resumeShare: (params: Parameters<WhisperContext["resumeFromSharedContext"]>[0]) => Promise<{
523
+ success: boolean;
524
+ session_id: string;
525
+ memories_restored: number;
526
+ messages_restored: number;
527
+ chunks_restored: number;
528
+ }>;
529
+ };
530
+ readonly optimization: {
531
+ getCacheStats: () => Promise<{
532
+ cache_type: string;
533
+ hit_rate: number;
534
+ total_requests: number;
535
+ hits: number;
536
+ misses: number;
537
+ size_bytes: number;
538
+ keys_count: number;
539
+ average_latency_ms: number;
540
+ uptime_seconds: number;
541
+ }>;
542
+ warmCache: (params: Parameters<WhisperContext["warmCache"]>[0]) => Promise<{
543
+ success: boolean;
544
+ queries_warmed: number;
545
+ errors: string[];
546
+ cache_size_increase_bytes: number;
547
+ }>;
548
+ clearCache: (params: Parameters<WhisperContext["clearCache"]>[0]) => Promise<{
549
+ success: boolean;
550
+ keys_cleared: number;
551
+ bytes_freed: number;
552
+ }>;
553
+ getCostSummary: (params?: Parameters<WhisperContext["getCostSummary"]>[0]) => Promise<any>;
554
+ getCostBreakdown: (params?: Parameters<WhisperContext["getCostBreakdown"]>[0]) => Promise<any>;
555
+ getCostSavings: (params?: Parameters<WhisperContext["getCostSavings"]>[0]) => Promise<any>;
556
+ };
430
557
  }
431
558
 
432
- export { type Memory, type Project, type QueryParams, type QueryResult, type Source, type WhisperConfig, WhisperContext, WhisperContext as default };
559
+ export { type Memory, type Project, type QueryParams, type QueryResult, type Source, type WhisperConfig, WhisperContext, WhisperError, type WhisperErrorCode, WhisperContext as default };