@usewhisper/sdk 3.6.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
@@ -661,6 +661,13 @@ interface PreparedTurn {
661
661
  targetBudgetMs: number;
662
662
  hardTimeoutMs: number;
663
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;
664
671
  };
665
672
  context: string;
666
673
  items: Array<{
@@ -702,8 +709,43 @@ interface AgentRuntimeStatus {
702
709
  mergedCount: number;
703
710
  droppedCount: number;
704
711
  bufferedLowSalience: number;
712
+ focusedPassHits: number;
713
+ fallbackTriggers: number;
714
+ floorDroppedCount: number;
715
+ injectedItemCount: number;
716
+ sourceScopedTurns: number;
717
+ broadScopedTurns: number;
718
+ totalTurns: number;
705
719
  };
706
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
+ }
707
749
  interface AgentRuntimeOptions extends AgentRunContext {
708
750
  topK?: number;
709
751
  maxTokens?: number;
@@ -711,6 +753,7 @@ interface AgentRuntimeOptions extends AgentRunContext {
711
753
  hardRetrievalTimeoutMs?: number;
712
754
  bindingStorePath?: string;
713
755
  recentWorkLimit?: number;
756
+ retrieval?: AgentRuntimeRetrievalOptions;
714
757
  }
715
758
  interface QueueStatus {
716
759
  queued: number;
@@ -787,20 +830,37 @@ interface RuntimeAdapter {
787
830
  declare class WhisperAgentRuntime {
788
831
  private readonly args;
789
832
  private readonly bindingStore;
790
- private readonly topK;
833
+ private readonly focusedTopK;
834
+ private readonly broadTopK;
791
835
  private readonly maxTokens;
792
836
  private readonly targetRetrievalMs;
793
837
  private readonly hardRetrievalTimeoutMs;
794
838
  private readonly recentWorkLimit;
795
839
  private readonly baseContext;
796
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;
797
847
  private bindings;
798
848
  private touchedFiles;
799
849
  private recentWork;
850
+ private recentSourceActivity;
800
851
  private bufferedLowSalience;
801
852
  private lastPreparedTurn;
802
853
  private mergedCount;
803
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;
804
864
  private lastScope;
805
865
  constructor(args: {
806
866
  baseContext: AgentRunContext;
@@ -810,11 +870,24 @@ declare class WhisperAgentRuntime {
810
870
  private getBindings;
811
871
  private pushTouchedFiles;
812
872
  private pushWorkEvent;
873
+ noteSourceActivity(sourceIds?: string[]): void;
874
+ private refreshTaskSummary;
875
+ private activeSourceIds;
876
+ private focusedScope;
877
+ private exactFileMetadataFilter;
813
878
  private makeTaskFrameQuery;
814
879
  private resolveScope;
815
880
  private runBranch;
816
881
  private contextItems;
817
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;
818
891
  private rerank;
819
892
  private buildContext;
820
893
  bootstrap(context?: Partial<AgentRunContext>): Promise<PreparedTurn>;
@@ -1179,6 +1252,7 @@ interface QueryParams {
1179
1252
  threshold?: number;
1180
1253
  chunk_types?: string[];
1181
1254
  source_ids?: string[];
1255
+ metadata_filter?: Record<string, any>;
1182
1256
  hybrid?: boolean;
1183
1257
  vector_weight?: number;
1184
1258
  bm25_weight?: number;
@@ -2062,4 +2136,4 @@ declare class WhisperContext {
2062
2136
  };
2063
2137
  }
2064
2138
 
2065
- 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
@@ -661,6 +661,13 @@ interface PreparedTurn {
661
661
  targetBudgetMs: number;
662
662
  hardTimeoutMs: number;
663
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;
664
671
  };
665
672
  context: string;
666
673
  items: Array<{
@@ -702,8 +709,43 @@ interface AgentRuntimeStatus {
702
709
  mergedCount: number;
703
710
  droppedCount: number;
704
711
  bufferedLowSalience: number;
712
+ focusedPassHits: number;
713
+ fallbackTriggers: number;
714
+ floorDroppedCount: number;
715
+ injectedItemCount: number;
716
+ sourceScopedTurns: number;
717
+ broadScopedTurns: number;
718
+ totalTurns: number;
705
719
  };
706
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
+ }
707
749
  interface AgentRuntimeOptions extends AgentRunContext {
708
750
  topK?: number;
709
751
  maxTokens?: number;
@@ -711,6 +753,7 @@ interface AgentRuntimeOptions extends AgentRunContext {
711
753
  hardRetrievalTimeoutMs?: number;
712
754
  bindingStorePath?: string;
713
755
  recentWorkLimit?: number;
756
+ retrieval?: AgentRuntimeRetrievalOptions;
714
757
  }
715
758
  interface QueueStatus {
716
759
  queued: number;
@@ -787,20 +830,37 @@ interface RuntimeAdapter {
787
830
  declare class WhisperAgentRuntime {
788
831
  private readonly args;
789
832
  private readonly bindingStore;
790
- private readonly topK;
833
+ private readonly focusedTopK;
834
+ private readonly broadTopK;
791
835
  private readonly maxTokens;
792
836
  private readonly targetRetrievalMs;
793
837
  private readonly hardRetrievalTimeoutMs;
794
838
  private readonly recentWorkLimit;
795
839
  private readonly baseContext;
796
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;
797
847
  private bindings;
798
848
  private touchedFiles;
799
849
  private recentWork;
850
+ private recentSourceActivity;
800
851
  private bufferedLowSalience;
801
852
  private lastPreparedTurn;
802
853
  private mergedCount;
803
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;
804
864
  private lastScope;
805
865
  constructor(args: {
806
866
  baseContext: AgentRunContext;
@@ -810,11 +870,24 @@ declare class WhisperAgentRuntime {
810
870
  private getBindings;
811
871
  private pushTouchedFiles;
812
872
  private pushWorkEvent;
873
+ noteSourceActivity(sourceIds?: string[]): void;
874
+ private refreshTaskSummary;
875
+ private activeSourceIds;
876
+ private focusedScope;
877
+ private exactFileMetadataFilter;
813
878
  private makeTaskFrameQuery;
814
879
  private resolveScope;
815
880
  private runBranch;
816
881
  private contextItems;
817
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;
818
891
  private rerank;
819
892
  private buildContext;
820
893
  bootstrap(context?: Partial<AgentRunContext>): Promise<PreparedTurn>;
@@ -1179,6 +1252,7 @@ interface QueryParams {
1179
1252
  threshold?: number;
1180
1253
  chunk_types?: string[];
1181
1254
  source_ids?: string[];
1255
+ metadata_filter?: Record<string, any>;
1182
1256
  hybrid?: boolean;
1183
1257
  vector_weight?: number;
1184
1258
  bm25_weight?: number;
@@ -2062,4 +2136,4 @@ declare class WhisperContext {
2062
2136
  };
2063
2137
  }
2064
2138
 
2065
- 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 };