@usewhisper/sdk 3.5.0 → 3.7.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/README.md CHANGED
@@ -1,6 +1,15 @@
1
- # @usewhisper/sdk
2
-
3
- Official TypeScript SDK for [Whisper Context API](https://usewhisper.dev) - Give your AI agents perfect context.
1
+ # @usewhisper/sdk
2
+
3
+ Official TypeScript SDK for [Whisper Context API](https://usewhisper.dev) - Give your AI agents perfect context.
4
+
5
+ `WhisperClient` is the primary SDK surface. `WhisperContext` remains available for compatibility, but automatic memory/retrieval behavior now lives in `WhisperClient.createAgentRuntime()`.
6
+
7
+ ## What's New in v3.6
8
+
9
+ - Automatic runtime for scope resolution, pre-retrieval, session continuity, and background capture.
10
+ - Legacy wrapper turn helpers now run through the automatic runtime by default.
11
+ - Context query responses expose `meta.source_scope`.
12
+ - URL/domain queries automatically narrow to matching sources when possible.
4
13
 
5
14
  ## Installation
6
15
 
@@ -10,64 +19,57 @@ npm install @usewhisper/sdk
10
19
 
11
20
  ## Quick Start
12
21
 
13
- ```typescript
14
- import { WhisperContext } from '@usewhisper/sdk';
15
-
16
- const whisper = new WhisperContext({
17
- apiKey: 'wsk_your_api_key_here'
18
- });
19
-
20
- // Create a project
21
- const project = await whisper.createProject({
22
- name: 'my-docs',
23
- description: 'Documentation context'
24
- });
25
-
26
- // Ingest documents
27
- await whisper.ingest(project.id, [
28
- {
29
- title: 'Authentication Guide',
30
- content: 'To authenticate users, use JWT tokens...',
31
- metadata: { category: 'auth' }
32
- }
33
- ]);
34
-
35
- // Query context
36
- const result = await whisper.query({
37
- project: 'my-docs',
38
- query: 'How do I authenticate users?',
39
- top_k: 5
40
- });
41
-
42
- console.log(result.context);
43
- ```
22
+ ```typescript
23
+ import { WhisperClient } from '@usewhisper/sdk';
24
+
25
+ const client = new WhisperClient({
26
+ apiKey: 'wsk_your_api_key_here',
27
+ project: 'my-docs'
28
+ });
29
+
30
+ const runtime = client.createAgentRuntime({
31
+ workspacePath: process.cwd(),
32
+ userId: 'user-123',
33
+ sessionId: 'session-abc',
34
+ clientName: 'my-agent-host'
35
+ });
36
+
37
+ const prepared = await runtime.beforeTurn({
38
+ userMessage: 'How do I authenticate users?'
39
+ });
40
+
41
+ console.log(prepared.context);
42
+ ```
44
43
 
45
44
  ## Authentication
46
45
 
47
46
  Get your API key from the [Whisper dashboard](https://usewhisper.dev/dashboard):
48
47
 
49
48
  ```typescript
50
- const whisper = new WhisperContext({
51
- apiKey: 'wsk_...', // Your API key
52
- baseUrl: 'https://context.usewhisper.dev' // Optional, defaults to production
53
- });
54
- ```
49
+ const client = new WhisperClient({
50
+ apiKey: 'wsk_...', // Your API key
51
+ baseUrl: 'https://context.usewhisper.dev' // Optional, defaults to production
52
+ });
53
+ ```
55
54
 
56
55
  ## Core Features
57
56
 
58
57
  ### Context Query
59
58
 
60
59
  ```typescript
61
- const result = await whisper.query({
62
- project: 'my-docs',
63
- query: 'Your question here',
64
- top_k: 10, // Number of results
65
- include_memories: true, // Include conversational memory
66
- include_graph: true, // Include knowledge graph
67
- hybrid: true, // Hybrid vector + keyword search
68
- rerank: true // Rerank results for better relevance
69
- });
70
- ```
60
+ const result = await client.query({
61
+ project: 'my-docs',
62
+ query: 'Your question here',
63
+ top_k: 10, // Number of results
64
+ source_ids: ['src_abc'], // Optional explicit source isolation
65
+ include_memories: true, // Include conversational memory
66
+ include_graph: true, // Include knowledge graph
67
+ hybrid: true, // Hybrid vector + keyword search
68
+ rerank: true // Rerank results for better relevance
69
+ });
70
+
71
+ console.log(result.meta.source_scope);
72
+ ```
71
73
 
72
74
  ### Project Management
73
75
 
package/index.d.mts CHANGED
@@ -77,6 +77,7 @@ interface RememberResult {
77
77
  */
78
78
  declare class Whisper {
79
79
  private client;
80
+ private runtimeClient;
80
81
  private options;
81
82
  private sessionId?;
82
83
  private userId?;
@@ -660,6 +661,13 @@ interface PreparedTurn {
660
661
  targetBudgetMs: number;
661
662
  hardTimeoutMs: number;
662
663
  branchStatus: Record<string, "ok" | "error" | "timeout" | "skipped">;
664
+ focusedScopeApplied: boolean;
665
+ focusedSourceIds: string[];
666
+ focusedFileHints: string[];
667
+ clientScoped: boolean;
668
+ fallbackUsed: boolean;
669
+ droppedBelowFloor: number;
670
+ dedupedCount: number;
663
671
  };
664
672
  context: string;
665
673
  items: Array<{
@@ -701,8 +709,43 @@ interface AgentRuntimeStatus {
701
709
  mergedCount: number;
702
710
  droppedCount: number;
703
711
  bufferedLowSalience: number;
712
+ focusedPassHits: number;
713
+ fallbackTriggers: number;
714
+ floorDroppedCount: number;
715
+ injectedItemCount: number;
716
+ sourceScopedTurns: number;
717
+ broadScopedTurns: number;
718
+ totalTurns: number;
704
719
  };
705
720
  }
721
+ interface AgentRuntimeRankWeights {
722
+ focusedPassBonus?: number;
723
+ sourceMatchBonus?: number;
724
+ touchedFileBonus?: number;
725
+ clientMatchBonus?: number;
726
+ highSalienceBonus?: number;
727
+ mediumSalienceBonus?: number;
728
+ staleBroadPenalty?: number;
729
+ unrelatedClientPenalty?: number;
730
+ lowSaliencePenalty?: number;
731
+ }
732
+ interface AgentRuntimeSourceActivityOptions {
733
+ maxTurns?: number;
734
+ maxIdleMs?: number;
735
+ decayAfterTurns?: number;
736
+ decayAfterIdleMs?: number;
737
+ evictOnTaskSwitch?: boolean;
738
+ }
739
+ interface AgentRuntimeRetrievalOptions {
740
+ focusedTopK?: number;
741
+ broadTopK?: number;
742
+ minFocusedResults?: number;
743
+ minFocusedTopScore?: number;
744
+ minProjectScore?: number;
745
+ minMemoryScore?: number;
746
+ rankWeights?: AgentRuntimeRankWeights;
747
+ sourceActivity?: AgentRuntimeSourceActivityOptions;
748
+ }
706
749
  interface AgentRuntimeOptions extends AgentRunContext {
707
750
  topK?: number;
708
751
  maxTokens?: number;
@@ -710,6 +753,7 @@ interface AgentRuntimeOptions extends AgentRunContext {
710
753
  hardRetrievalTimeoutMs?: number;
711
754
  bindingStorePath?: string;
712
755
  recentWorkLimit?: number;
756
+ retrieval?: AgentRuntimeRetrievalOptions;
713
757
  }
714
758
  interface QueueStatus {
715
759
  queued: number;
@@ -786,20 +830,37 @@ interface RuntimeAdapter {
786
830
  declare class WhisperAgentRuntime {
787
831
  private readonly args;
788
832
  private readonly bindingStore;
789
- private readonly topK;
833
+ private readonly focusedTopK;
834
+ private readonly broadTopK;
790
835
  private readonly maxTokens;
791
836
  private readonly targetRetrievalMs;
792
837
  private readonly hardRetrievalTimeoutMs;
793
838
  private readonly recentWorkLimit;
794
839
  private readonly baseContext;
795
840
  private readonly clientName;
841
+ private readonly minFocusedResults;
842
+ private readonly minFocusedTopScore;
843
+ private readonly minProjectScore;
844
+ private readonly minMemoryScore;
845
+ private readonly rankWeights;
846
+ private readonly sourceActivityOptions;
796
847
  private bindings;
797
848
  private touchedFiles;
798
849
  private recentWork;
850
+ private recentSourceActivity;
799
851
  private bufferedLowSalience;
800
852
  private lastPreparedTurn;
801
853
  private mergedCount;
802
854
  private droppedCount;
855
+ private focusedPassHits;
856
+ private fallbackTriggers;
857
+ private floorDroppedCount;
858
+ private injectedItemCount;
859
+ private sourceScopedTurns;
860
+ private broadScopedTurns;
861
+ private totalTurns;
862
+ private currentTurn;
863
+ private lastTaskSummary;
803
864
  private lastScope;
804
865
  constructor(args: {
805
866
  baseContext: AgentRunContext;
@@ -809,11 +870,24 @@ declare class WhisperAgentRuntime {
809
870
  private getBindings;
810
871
  private pushTouchedFiles;
811
872
  private pushWorkEvent;
873
+ noteSourceActivity(sourceIds?: string[]): void;
874
+ private refreshTaskSummary;
875
+ private activeSourceIds;
876
+ private focusedScope;
877
+ private exactFileMetadataFilter;
812
878
  private makeTaskFrameQuery;
813
879
  private resolveScope;
814
880
  private runBranch;
815
881
  private contextItems;
816
882
  private memoryItems;
883
+ private stableItemKey;
884
+ private metadataStrings;
885
+ private hasSourceMatch;
886
+ private hasFileMatch;
887
+ private hasClientMatch;
888
+ private salienceAdjustment;
889
+ private narrowFocusedMemories;
890
+ private applyRelevanceFloor;
817
891
  private rerank;
818
892
  private buildContext;
819
893
  bootstrap(context?: Partial<AgentRunContext>): Promise<PreparedTurn>;
@@ -1178,6 +1252,7 @@ interface QueryParams {
1178
1252
  threshold?: number;
1179
1253
  chunk_types?: string[];
1180
1254
  source_ids?: string[];
1255
+ metadata_filter?: Record<string, any>;
1181
1256
  hybrid?: boolean;
1182
1257
  vector_weight?: number;
1183
1258
  bm25_weight?: number;
@@ -1212,6 +1287,12 @@ interface QueryResult {
1212
1287
  cache_hit: boolean;
1213
1288
  tokens_used: number;
1214
1289
  context_hash: string;
1290
+ source_scope?: {
1291
+ mode: "none" | "explicit" | "auto";
1292
+ source_ids: string[];
1293
+ host?: string;
1294
+ matched_sources?: number;
1295
+ };
1215
1296
  profile?: string;
1216
1297
  compression?: any;
1217
1298
  timing?: {
@@ -2055,4 +2136,4 @@ declare class WhisperContext {
2055
2136
  };
2056
2137
  }
2057
2138
 
2058
- export { type AgentRunContext, type AgentRuntimeOptions, type AgentRuntimeStatus, type CanonicalSourceCreateParams, type CanonicalSourceCreateResult, type CanonicalSourceType, type ExtractedMemory, LangChainMemoryAdapter, LangGraphCheckpointAdapter, type Memory, type MemoryExtractionResult, type MemoryKind, type MemoryLatencyBreakdown, type MemorySearchResponse, type MemoryWriteAck, type MemoryWriteResult, type PreparedTurn, type Project, type QueryParams, type QueryResult, type Source, type TurnCaptureResult, type TurnInput, type VideoIngestionStatus, type VideoSourceMetadata, Whisper, WhisperAgentMiddleware, WhisperClient, type WhisperConfig, WhisperContext, Whisper as WhisperDefault, WhisperError, type WhisperErrorCode, WhisperClient as WhisperRuntimeClient, type WorkEvent, type WorkEventKind, type WorkEventSalience, createAgentMiddleware, createLangChainMemoryAdapter, createLangGraphCheckpointAdapter, WhisperContext as default, memoryGraphToMermaid };
2139
+ export { type AgentRunContext, type AgentRuntimeOptions, type AgentRuntimeRankWeights, type AgentRuntimeRetrievalOptions, type AgentRuntimeSourceActivityOptions, type AgentRuntimeStatus, type CanonicalSourceCreateParams, type CanonicalSourceCreateResult, type CanonicalSourceType, type ExtractedMemory, LangChainMemoryAdapter, LangGraphCheckpointAdapter, type Memory, type MemoryExtractionResult, type MemoryKind, type MemoryLatencyBreakdown, type MemorySearchResponse, type MemoryWriteAck, type MemoryWriteResult, type PreparedTurn, type Project, type QueryParams, type QueryResult, type Source, type TurnCaptureResult, type TurnInput, type VideoIngestionStatus, type VideoSourceMetadata, Whisper, WhisperAgentMiddleware, WhisperClient, type WhisperConfig, WhisperContext, Whisper as WhisperDefault, WhisperError, type WhisperErrorCode, WhisperClient as WhisperRuntimeClient, type WorkEvent, type WorkEventKind, type WorkEventSalience, createAgentMiddleware, createLangChainMemoryAdapter, createLangGraphCheckpointAdapter, WhisperContext as default, memoryGraphToMermaid };
package/index.d.ts CHANGED
@@ -77,6 +77,7 @@ interface RememberResult {
77
77
  */
78
78
  declare class Whisper {
79
79
  private client;
80
+ private runtimeClient;
80
81
  private options;
81
82
  private sessionId?;
82
83
  private userId?;
@@ -660,6 +661,13 @@ interface PreparedTurn {
660
661
  targetBudgetMs: number;
661
662
  hardTimeoutMs: number;
662
663
  branchStatus: Record<string, "ok" | "error" | "timeout" | "skipped">;
664
+ focusedScopeApplied: boolean;
665
+ focusedSourceIds: string[];
666
+ focusedFileHints: string[];
667
+ clientScoped: boolean;
668
+ fallbackUsed: boolean;
669
+ droppedBelowFloor: number;
670
+ dedupedCount: number;
663
671
  };
664
672
  context: string;
665
673
  items: Array<{
@@ -701,8 +709,43 @@ interface AgentRuntimeStatus {
701
709
  mergedCount: number;
702
710
  droppedCount: number;
703
711
  bufferedLowSalience: number;
712
+ focusedPassHits: number;
713
+ fallbackTriggers: number;
714
+ floorDroppedCount: number;
715
+ injectedItemCount: number;
716
+ sourceScopedTurns: number;
717
+ broadScopedTurns: number;
718
+ totalTurns: number;
704
719
  };
705
720
  }
721
+ interface AgentRuntimeRankWeights {
722
+ focusedPassBonus?: number;
723
+ sourceMatchBonus?: number;
724
+ touchedFileBonus?: number;
725
+ clientMatchBonus?: number;
726
+ highSalienceBonus?: number;
727
+ mediumSalienceBonus?: number;
728
+ staleBroadPenalty?: number;
729
+ unrelatedClientPenalty?: number;
730
+ lowSaliencePenalty?: number;
731
+ }
732
+ interface AgentRuntimeSourceActivityOptions {
733
+ maxTurns?: number;
734
+ maxIdleMs?: number;
735
+ decayAfterTurns?: number;
736
+ decayAfterIdleMs?: number;
737
+ evictOnTaskSwitch?: boolean;
738
+ }
739
+ interface AgentRuntimeRetrievalOptions {
740
+ focusedTopK?: number;
741
+ broadTopK?: number;
742
+ minFocusedResults?: number;
743
+ minFocusedTopScore?: number;
744
+ minProjectScore?: number;
745
+ minMemoryScore?: number;
746
+ rankWeights?: AgentRuntimeRankWeights;
747
+ sourceActivity?: AgentRuntimeSourceActivityOptions;
748
+ }
706
749
  interface AgentRuntimeOptions extends AgentRunContext {
707
750
  topK?: number;
708
751
  maxTokens?: number;
@@ -710,6 +753,7 @@ interface AgentRuntimeOptions extends AgentRunContext {
710
753
  hardRetrievalTimeoutMs?: number;
711
754
  bindingStorePath?: string;
712
755
  recentWorkLimit?: number;
756
+ retrieval?: AgentRuntimeRetrievalOptions;
713
757
  }
714
758
  interface QueueStatus {
715
759
  queued: number;
@@ -786,20 +830,37 @@ interface RuntimeAdapter {
786
830
  declare class WhisperAgentRuntime {
787
831
  private readonly args;
788
832
  private readonly bindingStore;
789
- private readonly topK;
833
+ private readonly focusedTopK;
834
+ private readonly broadTopK;
790
835
  private readonly maxTokens;
791
836
  private readonly targetRetrievalMs;
792
837
  private readonly hardRetrievalTimeoutMs;
793
838
  private readonly recentWorkLimit;
794
839
  private readonly baseContext;
795
840
  private readonly clientName;
841
+ private readonly minFocusedResults;
842
+ private readonly minFocusedTopScore;
843
+ private readonly minProjectScore;
844
+ private readonly minMemoryScore;
845
+ private readonly rankWeights;
846
+ private readonly sourceActivityOptions;
796
847
  private bindings;
797
848
  private touchedFiles;
798
849
  private recentWork;
850
+ private recentSourceActivity;
799
851
  private bufferedLowSalience;
800
852
  private lastPreparedTurn;
801
853
  private mergedCount;
802
854
  private droppedCount;
855
+ private focusedPassHits;
856
+ private fallbackTriggers;
857
+ private floorDroppedCount;
858
+ private injectedItemCount;
859
+ private sourceScopedTurns;
860
+ private broadScopedTurns;
861
+ private totalTurns;
862
+ private currentTurn;
863
+ private lastTaskSummary;
803
864
  private lastScope;
804
865
  constructor(args: {
805
866
  baseContext: AgentRunContext;
@@ -809,11 +870,24 @@ declare class WhisperAgentRuntime {
809
870
  private getBindings;
810
871
  private pushTouchedFiles;
811
872
  private pushWorkEvent;
873
+ noteSourceActivity(sourceIds?: string[]): void;
874
+ private refreshTaskSummary;
875
+ private activeSourceIds;
876
+ private focusedScope;
877
+ private exactFileMetadataFilter;
812
878
  private makeTaskFrameQuery;
813
879
  private resolveScope;
814
880
  private runBranch;
815
881
  private contextItems;
816
882
  private memoryItems;
883
+ private stableItemKey;
884
+ private metadataStrings;
885
+ private hasSourceMatch;
886
+ private hasFileMatch;
887
+ private hasClientMatch;
888
+ private salienceAdjustment;
889
+ private narrowFocusedMemories;
890
+ private applyRelevanceFloor;
817
891
  private rerank;
818
892
  private buildContext;
819
893
  bootstrap(context?: Partial<AgentRunContext>): Promise<PreparedTurn>;
@@ -1178,6 +1252,7 @@ interface QueryParams {
1178
1252
  threshold?: number;
1179
1253
  chunk_types?: string[];
1180
1254
  source_ids?: string[];
1255
+ metadata_filter?: Record<string, any>;
1181
1256
  hybrid?: boolean;
1182
1257
  vector_weight?: number;
1183
1258
  bm25_weight?: number;
@@ -1212,6 +1287,12 @@ interface QueryResult {
1212
1287
  cache_hit: boolean;
1213
1288
  tokens_used: number;
1214
1289
  context_hash: string;
1290
+ source_scope?: {
1291
+ mode: "none" | "explicit" | "auto";
1292
+ source_ids: string[];
1293
+ host?: string;
1294
+ matched_sources?: number;
1295
+ };
1215
1296
  profile?: string;
1216
1297
  compression?: any;
1217
1298
  timing?: {
@@ -2055,4 +2136,4 @@ declare class WhisperContext {
2055
2136
  };
2056
2137
  }
2057
2138
 
2058
- export { type AgentRunContext, type AgentRuntimeOptions, type AgentRuntimeStatus, type CanonicalSourceCreateParams, type CanonicalSourceCreateResult, type CanonicalSourceType, type ExtractedMemory, LangChainMemoryAdapter, LangGraphCheckpointAdapter, type Memory, type MemoryExtractionResult, type MemoryKind, type MemoryLatencyBreakdown, type MemorySearchResponse, type MemoryWriteAck, type MemoryWriteResult, type PreparedTurn, type Project, type QueryParams, type QueryResult, type Source, type TurnCaptureResult, type TurnInput, type VideoIngestionStatus, type VideoSourceMetadata, Whisper, WhisperAgentMiddleware, WhisperClient, type WhisperConfig, WhisperContext, Whisper as WhisperDefault, WhisperError, type WhisperErrorCode, WhisperClient as WhisperRuntimeClient, type WorkEvent, type WorkEventKind, type WorkEventSalience, createAgentMiddleware, createLangChainMemoryAdapter, createLangGraphCheckpointAdapter, WhisperContext as default, memoryGraphToMermaid };
2139
+ export { type AgentRunContext, type AgentRuntimeOptions, type AgentRuntimeRankWeights, type AgentRuntimeRetrievalOptions, type AgentRuntimeSourceActivityOptions, type AgentRuntimeStatus, type CanonicalSourceCreateParams, type CanonicalSourceCreateResult, type CanonicalSourceType, type ExtractedMemory, LangChainMemoryAdapter, LangGraphCheckpointAdapter, type Memory, type MemoryExtractionResult, type MemoryKind, type MemoryLatencyBreakdown, type MemorySearchResponse, type MemoryWriteAck, type MemoryWriteResult, type PreparedTurn, type Project, type QueryParams, type QueryResult, type Source, type TurnCaptureResult, type TurnInput, type VideoIngestionStatus, type VideoSourceMetadata, Whisper, WhisperAgentMiddleware, WhisperClient, type WhisperConfig, WhisperContext, Whisper as WhisperDefault, WhisperError, type WhisperErrorCode, WhisperClient as WhisperRuntimeClient, type WorkEvent, type WorkEventKind, type WorkEventSalience, createAgentMiddleware, createLangChainMemoryAdapter, createLangGraphCheckpointAdapter, WhisperContext as default, memoryGraphToMermaid };