@usewhisper/sdk 1.0.0 → 1.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.
@@ -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,40 @@ 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" | "episodic" | "semantic" | "procedural" | "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
+ allow_legacy_fallback?: boolean;
181
+ }): Promise<{
182
+ id: string;
183
+ success: boolean;
184
+ path: "sota" | "legacy";
185
+ fallback_used: boolean;
186
+ }>;
137
187
  searchMemories(params: {
138
- project: string;
188
+ project?: string;
139
189
  query: string;
140
190
  user_id?: string;
141
191
  session_id?: string;
142
192
  agent_id?: string;
143
- memory_type?: "factual" | "episodic" | "semantic" | "procedural";
193
+ memory_type?: "factual" | "preference" | "event" | "relationship" | "opinion" | "goal" | "instruction";
144
194
  top_k?: number;
145
- }): Promise<{
146
- memories: Array<Memory & {
147
- score: number;
148
- }>;
149
- }>;
195
+ }): Promise<any>;
150
196
  createApiKey(params: {
151
197
  name: string;
152
198
  scopes?: string[];
@@ -161,12 +207,9 @@ declare class WhisperContext {
161
207
  keys: any[];
162
208
  }>;
163
209
  getUsage(days?: number): Promise<any>;
164
- /**
165
- * SOTA Memory Search - Search memories with temporal and type filtering
166
- */
167
210
  searchMemoriesSOTA(params: {
168
211
  query: string;
169
- project: string;
212
+ project?: string;
170
213
  user_id?: string;
171
214
  session_id?: string;
172
215
  question_date?: string;
@@ -176,11 +219,8 @@ declare class WhisperContext {
176
219
  include_chunks?: boolean;
177
220
  include_relations?: boolean;
178
221
  }): Promise<any>;
179
- /**
180
- * Ingest Session - Create memories from a conversation
181
- */
182
222
  ingestSession(params: {
183
- project: string;
223
+ project?: string;
184
224
  session_id: string;
185
225
  user_id?: string;
186
226
  messages: Array<{
@@ -195,41 +235,29 @@ declare class WhisperContext {
195
235
  memories_invalidated: number;
196
236
  errors?: string[];
197
237
  }>;
198
- /**
199
- * Get Session Memories - Recent memories from a session
200
- */
201
238
  getSessionMemories(params: {
202
239
  session_id: string;
203
- project: string;
240
+ project?: string;
204
241
  limit?: number;
205
242
  since_date?: string;
206
243
  }): Promise<{
207
244
  memories: any[];
208
245
  count: number;
209
246
  }>;
210
- /**
211
- * Get User Profile - Long-term user preferences and facts
212
- */
213
247
  getUserProfile(params: {
214
248
  user_id: string;
215
- project: string;
249
+ project?: string;
216
250
  memory_types?: string;
217
251
  }): Promise<{
218
252
  user_id: string;
219
253
  memories: any[];
220
254
  count: number;
221
255
  }>;
222
- /**
223
- * Get Memory Versions - Version chain history
224
- */
225
256
  getMemoryVersions(memoryId: string): Promise<{
226
257
  memory_id: string;
227
258
  versions: any[];
228
259
  count: number;
229
260
  }>;
230
- /**
231
- * Update Memory - Create a new version
232
- */
233
261
  updateMemory(memoryId: string, params: {
234
262
  content: string;
235
263
  reasoning?: string;
@@ -238,36 +266,24 @@ declare class WhisperContext {
238
266
  new_memory_id: string;
239
267
  old_memory_id: string;
240
268
  }>;
241
- /**
242
- * Delete Memory - Soft delete
243
- */
244
269
  deleteMemory(memoryId: string): Promise<{
245
270
  success: boolean;
246
271
  deleted: string;
247
272
  }>;
248
- /**
249
- * Get Memory Relations - Graph connections
250
- */
251
273
  getMemoryRelations(memoryId: string): Promise<{
252
274
  memory_id: string;
253
275
  relations: any[];
254
276
  count: number;
255
277
  }>;
256
- /**
257
- * Oracle Search - Tree-guided document navigation with research mode
258
- */
259
278
  oracleSearch(params: {
260
279
  query: string;
261
- project: string;
280
+ project?: string;
262
281
  max_results?: number;
263
282
  mode?: "search" | "research";
264
283
  max_steps?: number;
265
284
  }): Promise<any>;
266
- /**
267
- * Autosubscribe - Auto-index project dependencies
268
- */
269
285
  autosubscribe(params: {
270
- project: string;
286
+ project?: string;
271
287
  source: {
272
288
  type: "github" | "local";
273
289
  owner?: string;
@@ -285,12 +301,9 @@ declare class WhisperContext {
285
301
  dependencies?: any[];
286
302
  auto_sync_enabled: boolean;
287
303
  }>;
288
- /**
289
- * Create Shared Context - Save and share a conversation
290
- */
291
304
  createSharedContext(params: {
292
305
  session_id: string;
293
- project: string;
306
+ project?: string;
294
307
  title?: string;
295
308
  include_memories?: boolean;
296
309
  include_chunks?: boolean;
@@ -304,9 +317,6 @@ declare class WhisperContext {
304
317
  messages_count: number;
305
318
  expires_at: string;
306
319
  }>;
307
- /**
308
- * Load Shared Context - View shared context (public endpoint)
309
- */
310
320
  loadSharedContext(shareId: string): Promise<{
311
321
  share_id: string;
312
322
  title: string;
@@ -317,12 +327,9 @@ declare class WhisperContext {
317
327
  chunks?: any[];
318
328
  metadata: any;
319
329
  }>;
320
- /**
321
- * Resume from Shared Context - Fork shared context to new session
322
- */
323
330
  resumeFromSharedContext(params: {
324
331
  share_id: string;
325
- project: string;
332
+ project?: string;
326
333
  new_session_id?: string;
327
334
  }): Promise<{
328
335
  success: boolean;
@@ -331,20 +338,14 @@ declare class WhisperContext {
331
338
  messages_restored: number;
332
339
  chunks_restored: number;
333
340
  }>;
334
- /**
335
- * Consolidate Memories - Find and merge duplicates
336
- */
337
341
  consolidateMemories(params: {
338
- project: string;
342
+ project?: string;
339
343
  similarity_threshold?: number;
340
344
  auto_merge?: boolean;
341
345
  dry_run?: boolean;
342
346
  }): Promise<any>;
343
- /**
344
- * Update Importance Decay - Apply time-based relevance scoring
345
- */
346
347
  updateImportanceDecay(params: {
347
- project: string;
348
+ project?: string;
348
349
  decay_function?: "exponential" | "linear" | "logarithmic";
349
350
  half_life_days?: number;
350
351
  access_boost?: number;
@@ -357,16 +358,10 @@ declare class WhisperContext {
357
358
  memories_archived: number;
358
359
  config: any;
359
360
  }>;
360
- /**
361
- * Get Importance Statistics
362
- */
363
- getImportanceStats(project: string): Promise<{
361
+ getImportanceStats(project?: string): Promise<{
364
362
  project_id: string;
365
363
  statistics: any;
366
364
  }>;
367
- /**
368
- * Get Cache Statistics
369
- */
370
365
  getCacheStats(): Promise<{
371
366
  cache_type: string;
372
367
  hit_rate: number;
@@ -378,11 +373,8 @@ declare class WhisperContext {
378
373
  average_latency_ms: number;
379
374
  uptime_seconds: number;
380
375
  }>;
381
- /**
382
- * Warm Cache - Preload common queries
383
- */
384
376
  warmCache(params: {
385
- project: string;
377
+ project?: string;
386
378
  queries: string[];
387
379
  ttl_seconds?: number;
388
380
  }): Promise<{
@@ -391,9 +383,6 @@ declare class WhisperContext {
391
383
  errors: string[];
392
384
  cache_size_increase_bytes: number;
393
385
  }>;
394
- /**
395
- * Clear Cache Pattern
396
- */
397
386
  clearCache(params: {
398
387
  pattern?: string;
399
388
  clear_all?: boolean;
@@ -402,31 +391,224 @@ declare class WhisperContext {
402
391
  keys_cleared: number;
403
392
  bytes_freed: number;
404
393
  }>;
405
- /**
406
- * Get Cost Summary - Cost tracking overview
407
- */
408
- getCostSummary(params: {
394
+ getCostSummary(params?: {
409
395
  project?: string;
410
396
  start_date?: string;
411
397
  end_date?: string;
412
398
  }): Promise<any>;
413
- /**
414
- * Get Cost Breakdown - Detailed cost analysis
415
- */
416
- getCostBreakdown(params: {
399
+ getCostBreakdown(params?: {
417
400
  project?: string;
418
401
  group_by?: "model" | "task" | "day" | "hour";
419
402
  start_date?: string;
420
403
  end_date?: string;
421
404
  }): Promise<any>;
422
405
  /**
423
- * Get Savings Report - Compare actual vs always-Opus costs
406
+ * Semantic search over raw documents without pre-indexing.
407
+ * Send file contents/summaries directly — the API embeds them in-memory and ranks by similarity.
408
+ * Perfect for AI agents to semantically explore a codebase on-the-fly.
424
409
  */
425
- getCostSavings(params: {
410
+ semanticSearch(params: {
411
+ query: string;
412
+ documents: Array<{
413
+ id: string;
414
+ content: string;
415
+ }>;
416
+ top_k?: number;
417
+ threshold?: number;
418
+ }): Promise<{
419
+ results: Array<{
420
+ id: string;
421
+ score: number;
422
+ content: string;
423
+ snippet: string;
424
+ }>;
425
+ total_searched: number;
426
+ total_returned: number;
427
+ query: string;
428
+ latency_ms: number;
429
+ }>;
430
+ searchFiles(params: {
431
+ query: string;
432
+ path?: string;
433
+ mode?: "content" | "filename" | "both";
434
+ file_types?: string[];
435
+ max_results?: number;
436
+ context_lines?: number;
437
+ case_sensitive?: boolean;
438
+ }): Promise<{
439
+ results: Array<{
440
+ file: string;
441
+ matches: Array<{
442
+ line: number;
443
+ content: string;
444
+ context_before: string[];
445
+ context_after: string[];
446
+ }>;
447
+ }>;
448
+ total_files: number;
449
+ total_matches: number;
450
+ search_path: string;
451
+ mode: string;
452
+ latency_ms: number;
453
+ engine: "ripgrep" | "node";
454
+ }>;
455
+ getCostSavings(params?: {
426
456
  project?: string;
427
457
  start_date?: string;
428
458
  end_date?: string;
429
459
  }): Promise<any>;
460
+ readonly projects: {
461
+ create: (params: {
462
+ name: string;
463
+ description?: string;
464
+ settings?: Record<string, any>;
465
+ }) => Promise<Project>;
466
+ list: () => Promise<{
467
+ projects: Project[];
468
+ }>;
469
+ get: (id: string) => Promise<Project & {
470
+ sources: Source[];
471
+ }>;
472
+ delete: (id: string) => Promise<{
473
+ deleted: boolean;
474
+ }>;
475
+ };
476
+ readonly sources: {
477
+ add: (projectId: string, params: {
478
+ name: string;
479
+ connector_type: string;
480
+ config: Record<string, any>;
481
+ sync_schedule?: string;
482
+ }) => Promise<Source>;
483
+ sync: (sourceId: string) => Promise<any>;
484
+ syncSource: (sourceId: string) => Promise<any>;
485
+ };
486
+ readonly memory: {
487
+ add: (params: Parameters<WhisperContext["addMemory"]>[0]) => Promise<{
488
+ id: string;
489
+ success: boolean;
490
+ path: "sota" | "legacy";
491
+ fallback_used: boolean;
492
+ }>;
493
+ search: (params: Parameters<WhisperContext["searchMemories"]>[0]) => Promise<any>;
494
+ searchSOTA: (params: Parameters<WhisperContext["searchMemoriesSOTA"]>[0]) => Promise<any>;
495
+ ingestSession: (params: Parameters<WhisperContext["ingestSession"]>[0]) => Promise<{
496
+ success: boolean;
497
+ memories_created: number;
498
+ relations_created: number;
499
+ memories_invalidated: number;
500
+ errors?: string[];
501
+ }>;
502
+ getSessionMemories: (params: Parameters<WhisperContext["getSessionMemories"]>[0]) => Promise<{
503
+ memories: any[];
504
+ count: number;
505
+ }>;
506
+ getUserProfile: (params: Parameters<WhisperContext["getUserProfile"]>[0]) => Promise<{
507
+ user_id: string;
508
+ memories: any[];
509
+ count: number;
510
+ }>;
511
+ getVersions: (memoryId: string) => Promise<{
512
+ memory_id: string;
513
+ versions: any[];
514
+ count: number;
515
+ }>;
516
+ update: (memoryId: string, params: Parameters<WhisperContext["updateMemory"]>[1]) => Promise<{
517
+ success: boolean;
518
+ new_memory_id: string;
519
+ old_memory_id: string;
520
+ }>;
521
+ delete: (memoryId: string) => Promise<{
522
+ success: boolean;
523
+ deleted: string;
524
+ }>;
525
+ getRelations: (memoryId: string) => Promise<{
526
+ memory_id: string;
527
+ relations: any[];
528
+ count: number;
529
+ }>;
530
+ consolidate: (params: Parameters<WhisperContext["consolidateMemories"]>[0]) => Promise<any>;
531
+ updateDecay: (params: Parameters<WhisperContext["updateImportanceDecay"]>[0]) => Promise<{
532
+ success: boolean;
533
+ memories_updated: number;
534
+ average_importance: number;
535
+ memories_archived: number;
536
+ config: any;
537
+ }>;
538
+ getImportanceStats: (project?: string) => Promise<{
539
+ project_id: string;
540
+ statistics: any;
541
+ }>;
542
+ };
543
+ readonly keys: {
544
+ create: (params: Parameters<WhisperContext["createApiKey"]>[0]) => Promise<{
545
+ key: string;
546
+ prefix: string;
547
+ name: string;
548
+ }>;
549
+ list: () => Promise<{
550
+ keys: any[];
551
+ }>;
552
+ getUsage: (days?: number) => Promise<any>;
553
+ };
554
+ readonly oracle: {
555
+ search: (params: Parameters<WhisperContext["oracleSearch"]>[0]) => Promise<any>;
556
+ };
557
+ readonly context: {
558
+ createShare: (params: Parameters<WhisperContext["createSharedContext"]>[0]) => Promise<{
559
+ success: boolean;
560
+ share_id: string;
561
+ share_url: string;
562
+ title: string;
563
+ memories_count: number;
564
+ messages_count: number;
565
+ expires_at: string;
566
+ }>;
567
+ loadShare: (shareId: string) => Promise<{
568
+ share_id: string;
569
+ title: string;
570
+ created_at: string;
571
+ expires_at: string;
572
+ memories: any[];
573
+ messages: any[];
574
+ chunks?: any[];
575
+ metadata: any;
576
+ }>;
577
+ resumeShare: (params: Parameters<WhisperContext["resumeFromSharedContext"]>[0]) => Promise<{
578
+ success: boolean;
579
+ session_id: string;
580
+ memories_restored: number;
581
+ messages_restored: number;
582
+ chunks_restored: number;
583
+ }>;
584
+ };
585
+ readonly optimization: {
586
+ getCacheStats: () => Promise<{
587
+ cache_type: string;
588
+ hit_rate: number;
589
+ total_requests: number;
590
+ hits: number;
591
+ misses: number;
592
+ size_bytes: number;
593
+ keys_count: number;
594
+ average_latency_ms: number;
595
+ uptime_seconds: number;
596
+ }>;
597
+ warmCache: (params: Parameters<WhisperContext["warmCache"]>[0]) => Promise<{
598
+ success: boolean;
599
+ queries_warmed: number;
600
+ errors: string[];
601
+ cache_size_increase_bytes: number;
602
+ }>;
603
+ clearCache: (params: Parameters<WhisperContext["clearCache"]>[0]) => Promise<{
604
+ success: boolean;
605
+ keys_cleared: number;
606
+ bytes_freed: number;
607
+ }>;
608
+ getCostSummary: (params?: Parameters<WhisperContext["getCostSummary"]>[0]) => Promise<any>;
609
+ getCostBreakdown: (params?: Parameters<WhisperContext["getCostBreakdown"]>[0]) => Promise<any>;
610
+ getCostSavings: (params?: Parameters<WhisperContext["getCostSavings"]>[0]) => Promise<any>;
611
+ };
430
612
  }
431
613
 
432
- export { type Memory, type Project, type QueryParams, type QueryResult, type Source, type WhisperConfig, WhisperContext, WhisperContext as default };
614
+ export { type Memory, type Project, type QueryParams, type QueryResult, type Source, type WhisperConfig, WhisperContext, WhisperError, type WhisperErrorCode, WhisperContext as default };