@usewhisper/sdk 1.1.0 → 2.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/README.md +256 -256
- package/index.d.mts +311 -3
- package/index.d.ts +311 -3
- package/index.js +388 -12
- package/index.mjs +381 -11
- package/package.json +56 -56
package/index.d.mts
CHANGED
|
@@ -1,3 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whisper - Simple Memory Layer for AI Agents
|
|
3
|
+
*
|
|
4
|
+
* Two methods:
|
|
5
|
+
* - getContext(): Retrieve relevant context before LLM call
|
|
6
|
+
* - capture(): Extract and store memories after LLM response
|
|
7
|
+
*
|
|
8
|
+
* Zero magic - you control when to get context and when to capture
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
interface WhisperOptions extends WhisperConfig {
|
|
12
|
+
/**
|
|
13
|
+
* Maximum context results to retrieve.
|
|
14
|
+
* Default: 10
|
|
15
|
+
*/
|
|
16
|
+
contextLimit?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Which memory types to use.
|
|
19
|
+
* Default: all 7 types
|
|
20
|
+
*/
|
|
21
|
+
memoryTypes?: Array<"factual" | "preference" | "event" | "relationship" | "opinion" | "goal" | "instruction">;
|
|
22
|
+
/**
|
|
23
|
+
* Prefix for context injection.
|
|
24
|
+
* Default: "Relevant context:"
|
|
25
|
+
*/
|
|
26
|
+
contextPrefix?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Extract structured memories before writing.
|
|
29
|
+
* Default: true
|
|
30
|
+
*/
|
|
31
|
+
autoExtract?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Minimum extraction confidence for auto-write.
|
|
34
|
+
* Default: 0.65
|
|
35
|
+
*/
|
|
36
|
+
autoExtractMinConfidence?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Maximum extracted memories to write per remember/capture call.
|
|
39
|
+
* Default: 5
|
|
40
|
+
*/
|
|
41
|
+
maxMemoriesPerCapture?: number;
|
|
42
|
+
}
|
|
43
|
+
interface ContextResult {
|
|
44
|
+
context: string;
|
|
45
|
+
results: QueryResult["results"];
|
|
46
|
+
count: number;
|
|
47
|
+
}
|
|
48
|
+
interface RememberResult {
|
|
49
|
+
success: boolean;
|
|
50
|
+
memoryId?: string;
|
|
51
|
+
memoryIds?: string[];
|
|
52
|
+
extracted?: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Simple, transparent memory layer
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* import { Whisper } from '@usewhisper/sdk';
|
|
60
|
+
*
|
|
61
|
+
* const whisper = new Whisper({
|
|
62
|
+
* apiKey: process.env.WHISPER_KEY,
|
|
63
|
+
* project: 'my-app'
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* // BEFORE: Get relevant context
|
|
67
|
+
* const { context, results } = await whisper.getContext("What does user prefer?");
|
|
68
|
+
*
|
|
69
|
+
* // Inject context into your LLM prompt
|
|
70
|
+
* const prompt = `${context}\n\nUser: What does user prefer?`;
|
|
71
|
+
* const response = await llm.complete(prompt);
|
|
72
|
+
*
|
|
73
|
+
* // AFTER: Capture what happened
|
|
74
|
+
* await whisper.capture(response);
|
|
75
|
+
* // → Memories extracted & stored (async)
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
declare class Whisper {
|
|
79
|
+
private client;
|
|
80
|
+
private options;
|
|
81
|
+
private sessionId?;
|
|
82
|
+
private userId?;
|
|
83
|
+
constructor(options: WhisperOptions);
|
|
84
|
+
/**
|
|
85
|
+
* Set session ID for conversation tracking
|
|
86
|
+
*/
|
|
87
|
+
session(sessionId: string): this;
|
|
88
|
+
/**
|
|
89
|
+
* Set user ID for user-specific memories
|
|
90
|
+
*/
|
|
91
|
+
user(userId: string): this;
|
|
92
|
+
/**
|
|
93
|
+
* Get relevant context BEFORE your LLM call
|
|
94
|
+
*
|
|
95
|
+
* @param query - What you want to know / user question
|
|
96
|
+
* @returns Context string and raw results
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const { context, results, count } = await whisper.getContext(
|
|
101
|
+
* "What are user's preferences?",
|
|
102
|
+
* { userId: "user-123" }
|
|
103
|
+
* );
|
|
104
|
+
*
|
|
105
|
+
* // Results: [
|
|
106
|
+
* // { content: "User prefers dark mode", type: "preference", score: 0.95 },
|
|
107
|
+
* // { content: "Allergic to nuts", type: "factual", score: 0.89 }
|
|
108
|
+
* // ]
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
getContext(query: string, options?: {
|
|
112
|
+
userId?: string;
|
|
113
|
+
sessionId?: string;
|
|
114
|
+
project?: string;
|
|
115
|
+
limit?: number;
|
|
116
|
+
}): Promise<ContextResult>;
|
|
117
|
+
/**
|
|
118
|
+
* Remember what happened AFTER your LLM response
|
|
119
|
+
*
|
|
120
|
+
* Fire-and-forget - doesn't block your response
|
|
121
|
+
*
|
|
122
|
+
* @param content - What your LLM responded with
|
|
123
|
+
* @returns Promise that resolves when stored (or fails silently)
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const llmResponse = "I've set your theme to dark mode and removed nuts from recommendations.";
|
|
128
|
+
*
|
|
129
|
+
* await whisper.remember(llmResponse, { userId: "user-123" });
|
|
130
|
+
* // → Auto-extracts: "theme set to dark mode", "nut allergy"
|
|
131
|
+
* // → Stored as preferences
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
remember(content: string, options?: {
|
|
135
|
+
userId?: string;
|
|
136
|
+
sessionId?: string;
|
|
137
|
+
project?: string;
|
|
138
|
+
}): Promise<RememberResult>;
|
|
139
|
+
/**
|
|
140
|
+
* Alias for remember() - same thing
|
|
141
|
+
*/
|
|
142
|
+
capture(content: string, options?: {
|
|
143
|
+
userId?: string;
|
|
144
|
+
sessionId?: string;
|
|
145
|
+
project?: string;
|
|
146
|
+
}): Promise<RememberResult>;
|
|
147
|
+
/**
|
|
148
|
+
* Capture from multiple messages (e.g., full conversation)
|
|
149
|
+
*/
|
|
150
|
+
captureSession(messages: Array<{
|
|
151
|
+
role: string;
|
|
152
|
+
content: string;
|
|
153
|
+
}>, options?: {
|
|
154
|
+
userId?: string;
|
|
155
|
+
sessionId?: string;
|
|
156
|
+
project?: string;
|
|
157
|
+
}): Promise<{
|
|
158
|
+
success: boolean;
|
|
159
|
+
extracted: number;
|
|
160
|
+
}>;
|
|
161
|
+
/**
|
|
162
|
+
* Run a full agent turn with automatic memory read (before) + write (after).
|
|
163
|
+
*/
|
|
164
|
+
runTurn(params: {
|
|
165
|
+
userMessage: string;
|
|
166
|
+
generate: (prompt: string) => Promise<string>;
|
|
167
|
+
userId?: string;
|
|
168
|
+
sessionId?: string;
|
|
169
|
+
project?: string;
|
|
170
|
+
limit?: number;
|
|
171
|
+
}): Promise<{
|
|
172
|
+
response: string;
|
|
173
|
+
context: string;
|
|
174
|
+
count: number;
|
|
175
|
+
extracted: number;
|
|
176
|
+
}>;
|
|
177
|
+
/**
|
|
178
|
+
* Direct access to WhisperContext for advanced usage
|
|
179
|
+
*/
|
|
180
|
+
raw(): WhisperContext;
|
|
181
|
+
private extractMemoryIdsFromBulkResponse;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
interface AgentMiddlewareConfig extends WhisperOptions {
|
|
185
|
+
/**
|
|
186
|
+
* Build the prompt passed to the model.
|
|
187
|
+
*/
|
|
188
|
+
promptBuilder?: (params: {
|
|
189
|
+
context: string;
|
|
190
|
+
userMessage: string;
|
|
191
|
+
}) => string;
|
|
192
|
+
}
|
|
193
|
+
interface AgentTurnParams {
|
|
194
|
+
userMessage: string;
|
|
195
|
+
userId?: string;
|
|
196
|
+
sessionId?: string;
|
|
197
|
+
project?: string;
|
|
198
|
+
contextLimit?: number;
|
|
199
|
+
}
|
|
200
|
+
interface AgentTurnResult {
|
|
201
|
+
prompt: string;
|
|
202
|
+
context: string;
|
|
203
|
+
contextCount: number;
|
|
204
|
+
}
|
|
205
|
+
interface WrappedGenerateResult {
|
|
206
|
+
response: string;
|
|
207
|
+
prompt: string;
|
|
208
|
+
context: string;
|
|
209
|
+
contextCount: number;
|
|
210
|
+
extracted: number;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Drop-in middleware for existing AI agents.
|
|
214
|
+
*
|
|
215
|
+
* Typical flow:
|
|
216
|
+
* 1) beforeTurn -> retrieve context
|
|
217
|
+
* 2) call your model
|
|
218
|
+
* 3) afterTurn -> store memories
|
|
219
|
+
*/
|
|
220
|
+
declare class WhisperAgentMiddleware {
|
|
221
|
+
private readonly whisper;
|
|
222
|
+
private readonly promptBuilder;
|
|
223
|
+
constructor(config: AgentMiddlewareConfig);
|
|
224
|
+
beforeTurn(params: AgentTurnParams): Promise<AgentTurnResult>;
|
|
225
|
+
afterTurn(params: {
|
|
226
|
+
userMessage: string;
|
|
227
|
+
assistantMessage: string;
|
|
228
|
+
userId?: string;
|
|
229
|
+
sessionId?: string;
|
|
230
|
+
project?: string;
|
|
231
|
+
}): Promise<{
|
|
232
|
+
success: boolean;
|
|
233
|
+
extracted: number;
|
|
234
|
+
}>;
|
|
235
|
+
wrapGenerate(params: AgentTurnParams & {
|
|
236
|
+
generate: (prompt: string) => Promise<string>;
|
|
237
|
+
}): Promise<WrappedGenerateResult>;
|
|
238
|
+
raw(): Whisper;
|
|
239
|
+
}
|
|
240
|
+
declare function createAgentMiddleware(config: AgentMiddlewareConfig): WhisperAgentMiddleware;
|
|
241
|
+
|
|
1
242
|
/**
|
|
2
243
|
* Whisper Context SDK
|
|
3
244
|
* TypeScript SDK for the Whisper Context API
|
|
@@ -6,7 +247,6 @@ interface WhisperConfig {
|
|
|
6
247
|
apiKey: string;
|
|
7
248
|
baseUrl?: string;
|
|
8
249
|
project?: string;
|
|
9
|
-
orgId?: string;
|
|
10
250
|
timeoutMs?: number;
|
|
11
251
|
retry?: {
|
|
12
252
|
maxAttempts?: number;
|
|
@@ -95,6 +335,23 @@ interface Memory {
|
|
|
95
335
|
createdAt: string;
|
|
96
336
|
updatedAt: string;
|
|
97
337
|
}
|
|
338
|
+
type MemoryKind = "factual" | "preference" | "event" | "relationship" | "opinion" | "goal" | "instruction";
|
|
339
|
+
interface ExtractedMemory {
|
|
340
|
+
content: string;
|
|
341
|
+
memoryType: MemoryKind;
|
|
342
|
+
entityMentions: string[];
|
|
343
|
+
eventDate: string | null;
|
|
344
|
+
confidence: number;
|
|
345
|
+
reasoning?: string;
|
|
346
|
+
inferred?: boolean;
|
|
347
|
+
}
|
|
348
|
+
interface MemoryExtractionResult {
|
|
349
|
+
explicit: ExtractedMemory[];
|
|
350
|
+
implicit: ExtractedMemory[];
|
|
351
|
+
all: ExtractedMemory[];
|
|
352
|
+
extractionMethod: "pattern" | "inference" | "hybrid" | "skipped";
|
|
353
|
+
latencyMs: number;
|
|
354
|
+
}
|
|
98
355
|
type WhisperErrorCode = "INVALID_API_KEY" | "PROJECT_NOT_FOUND" | "PROJECT_AMBIGUOUS" | "RATE_LIMITED" | "TEMPORARY_UNAVAILABLE" | "NETWORK_ERROR" | "TIMEOUT" | "REQUEST_FAILED" | "MISSING_PROJECT";
|
|
99
356
|
declare class WhisperError extends Error {
|
|
100
357
|
code: WhisperErrorCode;
|
|
@@ -113,7 +370,6 @@ declare class WhisperContext {
|
|
|
113
370
|
private apiKey;
|
|
114
371
|
private baseUrl;
|
|
115
372
|
private defaultProject?;
|
|
116
|
-
private orgId?;
|
|
117
373
|
private timeoutMs;
|
|
118
374
|
private retryConfig;
|
|
119
375
|
private projectRefToId;
|
|
@@ -184,6 +440,51 @@ declare class WhisperContext {
|
|
|
184
440
|
path: "sota" | "legacy";
|
|
185
441
|
fallback_used: boolean;
|
|
186
442
|
}>;
|
|
443
|
+
addMemoriesBulk(params: {
|
|
444
|
+
project?: string;
|
|
445
|
+
memories: Array<{
|
|
446
|
+
content: string;
|
|
447
|
+
memory_type?: MemoryKind | "episodic" | "semantic" | "procedural";
|
|
448
|
+
user_id?: string;
|
|
449
|
+
session_id?: string;
|
|
450
|
+
agent_id?: string;
|
|
451
|
+
importance?: number;
|
|
452
|
+
confidence?: number;
|
|
453
|
+
metadata?: Record<string, any>;
|
|
454
|
+
entity_mentions?: string[];
|
|
455
|
+
document_date?: string;
|
|
456
|
+
event_date?: string;
|
|
457
|
+
}>;
|
|
458
|
+
namespace?: string;
|
|
459
|
+
tags?: string[];
|
|
460
|
+
async?: boolean;
|
|
461
|
+
webhook_url?: string;
|
|
462
|
+
}): Promise<any>;
|
|
463
|
+
extractMemories(params: {
|
|
464
|
+
project?: string;
|
|
465
|
+
message: string;
|
|
466
|
+
context?: string;
|
|
467
|
+
session_id?: string;
|
|
468
|
+
user_id?: string;
|
|
469
|
+
enable_pattern?: boolean;
|
|
470
|
+
enable_inference?: boolean;
|
|
471
|
+
min_confidence?: number;
|
|
472
|
+
}): Promise<MemoryExtractionResult>;
|
|
473
|
+
extractSessionMemories(params: {
|
|
474
|
+
project?: string;
|
|
475
|
+
user_id?: string;
|
|
476
|
+
messages: Array<{
|
|
477
|
+
role: "user" | "assistant" | "system";
|
|
478
|
+
content: string;
|
|
479
|
+
timestamp?: string;
|
|
480
|
+
}>;
|
|
481
|
+
enable_pattern?: boolean;
|
|
482
|
+
enable_inference?: boolean;
|
|
483
|
+
}): Promise<{
|
|
484
|
+
memories: ExtractedMemory[];
|
|
485
|
+
count: number;
|
|
486
|
+
latencyMs: number;
|
|
487
|
+
}>;
|
|
187
488
|
searchMemories(params: {
|
|
188
489
|
project?: string;
|
|
189
490
|
query: string;
|
|
@@ -490,6 +791,13 @@ declare class WhisperContext {
|
|
|
490
791
|
path: "sota" | "legacy";
|
|
491
792
|
fallback_used: boolean;
|
|
492
793
|
}>;
|
|
794
|
+
addBulk: (params: Parameters<WhisperContext["addMemoriesBulk"]>[0]) => Promise<any>;
|
|
795
|
+
extract: (params: Parameters<WhisperContext["extractMemories"]>[0]) => Promise<MemoryExtractionResult>;
|
|
796
|
+
extractSession: (params: Parameters<WhisperContext["extractSessionMemories"]>[0]) => Promise<{
|
|
797
|
+
memories: ExtractedMemory[];
|
|
798
|
+
count: number;
|
|
799
|
+
latencyMs: number;
|
|
800
|
+
}>;
|
|
493
801
|
search: (params: Parameters<WhisperContext["searchMemories"]>[0]) => Promise<any>;
|
|
494
802
|
searchSOTA: (params: Parameters<WhisperContext["searchMemoriesSOTA"]>[0]) => Promise<any>;
|
|
495
803
|
ingestSession: (params: Parameters<WhisperContext["ingestSession"]>[0]) => Promise<{
|
|
@@ -611,4 +919,4 @@ declare class WhisperContext {
|
|
|
611
919
|
};
|
|
612
920
|
}
|
|
613
921
|
|
|
614
|
-
export { type Memory, type Project, type QueryParams, type QueryResult, type Source, type WhisperConfig, WhisperContext, WhisperError, type WhisperErrorCode, WhisperContext as default };
|
|
922
|
+
export { type ExtractedMemory, type Memory, type MemoryExtractionResult, type MemoryKind, type Project, type QueryParams, type QueryResult, type Source, Whisper, WhisperAgentMiddleware, type WhisperConfig, WhisperContext, Whisper as WhisperDefault, WhisperError, type WhisperErrorCode, createAgentMiddleware, WhisperContext as default };
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whisper - Simple Memory Layer for AI Agents
|
|
3
|
+
*
|
|
4
|
+
* Two methods:
|
|
5
|
+
* - getContext(): Retrieve relevant context before LLM call
|
|
6
|
+
* - capture(): Extract and store memories after LLM response
|
|
7
|
+
*
|
|
8
|
+
* Zero magic - you control when to get context and when to capture
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
interface WhisperOptions extends WhisperConfig {
|
|
12
|
+
/**
|
|
13
|
+
* Maximum context results to retrieve.
|
|
14
|
+
* Default: 10
|
|
15
|
+
*/
|
|
16
|
+
contextLimit?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Which memory types to use.
|
|
19
|
+
* Default: all 7 types
|
|
20
|
+
*/
|
|
21
|
+
memoryTypes?: Array<"factual" | "preference" | "event" | "relationship" | "opinion" | "goal" | "instruction">;
|
|
22
|
+
/**
|
|
23
|
+
* Prefix for context injection.
|
|
24
|
+
* Default: "Relevant context:"
|
|
25
|
+
*/
|
|
26
|
+
contextPrefix?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Extract structured memories before writing.
|
|
29
|
+
* Default: true
|
|
30
|
+
*/
|
|
31
|
+
autoExtract?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Minimum extraction confidence for auto-write.
|
|
34
|
+
* Default: 0.65
|
|
35
|
+
*/
|
|
36
|
+
autoExtractMinConfidence?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Maximum extracted memories to write per remember/capture call.
|
|
39
|
+
* Default: 5
|
|
40
|
+
*/
|
|
41
|
+
maxMemoriesPerCapture?: number;
|
|
42
|
+
}
|
|
43
|
+
interface ContextResult {
|
|
44
|
+
context: string;
|
|
45
|
+
results: QueryResult["results"];
|
|
46
|
+
count: number;
|
|
47
|
+
}
|
|
48
|
+
interface RememberResult {
|
|
49
|
+
success: boolean;
|
|
50
|
+
memoryId?: string;
|
|
51
|
+
memoryIds?: string[];
|
|
52
|
+
extracted?: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Simple, transparent memory layer
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* import { Whisper } from '@usewhisper/sdk';
|
|
60
|
+
*
|
|
61
|
+
* const whisper = new Whisper({
|
|
62
|
+
* apiKey: process.env.WHISPER_KEY,
|
|
63
|
+
* project: 'my-app'
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* // BEFORE: Get relevant context
|
|
67
|
+
* const { context, results } = await whisper.getContext("What does user prefer?");
|
|
68
|
+
*
|
|
69
|
+
* // Inject context into your LLM prompt
|
|
70
|
+
* const prompt = `${context}\n\nUser: What does user prefer?`;
|
|
71
|
+
* const response = await llm.complete(prompt);
|
|
72
|
+
*
|
|
73
|
+
* // AFTER: Capture what happened
|
|
74
|
+
* await whisper.capture(response);
|
|
75
|
+
* // → Memories extracted & stored (async)
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
declare class Whisper {
|
|
79
|
+
private client;
|
|
80
|
+
private options;
|
|
81
|
+
private sessionId?;
|
|
82
|
+
private userId?;
|
|
83
|
+
constructor(options: WhisperOptions);
|
|
84
|
+
/**
|
|
85
|
+
* Set session ID for conversation tracking
|
|
86
|
+
*/
|
|
87
|
+
session(sessionId: string): this;
|
|
88
|
+
/**
|
|
89
|
+
* Set user ID for user-specific memories
|
|
90
|
+
*/
|
|
91
|
+
user(userId: string): this;
|
|
92
|
+
/**
|
|
93
|
+
* Get relevant context BEFORE your LLM call
|
|
94
|
+
*
|
|
95
|
+
* @param query - What you want to know / user question
|
|
96
|
+
* @returns Context string and raw results
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const { context, results, count } = await whisper.getContext(
|
|
101
|
+
* "What are user's preferences?",
|
|
102
|
+
* { userId: "user-123" }
|
|
103
|
+
* );
|
|
104
|
+
*
|
|
105
|
+
* // Results: [
|
|
106
|
+
* // { content: "User prefers dark mode", type: "preference", score: 0.95 },
|
|
107
|
+
* // { content: "Allergic to nuts", type: "factual", score: 0.89 }
|
|
108
|
+
* // ]
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
getContext(query: string, options?: {
|
|
112
|
+
userId?: string;
|
|
113
|
+
sessionId?: string;
|
|
114
|
+
project?: string;
|
|
115
|
+
limit?: number;
|
|
116
|
+
}): Promise<ContextResult>;
|
|
117
|
+
/**
|
|
118
|
+
* Remember what happened AFTER your LLM response
|
|
119
|
+
*
|
|
120
|
+
* Fire-and-forget - doesn't block your response
|
|
121
|
+
*
|
|
122
|
+
* @param content - What your LLM responded with
|
|
123
|
+
* @returns Promise that resolves when stored (or fails silently)
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const llmResponse = "I've set your theme to dark mode and removed nuts from recommendations.";
|
|
128
|
+
*
|
|
129
|
+
* await whisper.remember(llmResponse, { userId: "user-123" });
|
|
130
|
+
* // → Auto-extracts: "theme set to dark mode", "nut allergy"
|
|
131
|
+
* // → Stored as preferences
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
remember(content: string, options?: {
|
|
135
|
+
userId?: string;
|
|
136
|
+
sessionId?: string;
|
|
137
|
+
project?: string;
|
|
138
|
+
}): Promise<RememberResult>;
|
|
139
|
+
/**
|
|
140
|
+
* Alias for remember() - same thing
|
|
141
|
+
*/
|
|
142
|
+
capture(content: string, options?: {
|
|
143
|
+
userId?: string;
|
|
144
|
+
sessionId?: string;
|
|
145
|
+
project?: string;
|
|
146
|
+
}): Promise<RememberResult>;
|
|
147
|
+
/**
|
|
148
|
+
* Capture from multiple messages (e.g., full conversation)
|
|
149
|
+
*/
|
|
150
|
+
captureSession(messages: Array<{
|
|
151
|
+
role: string;
|
|
152
|
+
content: string;
|
|
153
|
+
}>, options?: {
|
|
154
|
+
userId?: string;
|
|
155
|
+
sessionId?: string;
|
|
156
|
+
project?: string;
|
|
157
|
+
}): Promise<{
|
|
158
|
+
success: boolean;
|
|
159
|
+
extracted: number;
|
|
160
|
+
}>;
|
|
161
|
+
/**
|
|
162
|
+
* Run a full agent turn with automatic memory read (before) + write (after).
|
|
163
|
+
*/
|
|
164
|
+
runTurn(params: {
|
|
165
|
+
userMessage: string;
|
|
166
|
+
generate: (prompt: string) => Promise<string>;
|
|
167
|
+
userId?: string;
|
|
168
|
+
sessionId?: string;
|
|
169
|
+
project?: string;
|
|
170
|
+
limit?: number;
|
|
171
|
+
}): Promise<{
|
|
172
|
+
response: string;
|
|
173
|
+
context: string;
|
|
174
|
+
count: number;
|
|
175
|
+
extracted: number;
|
|
176
|
+
}>;
|
|
177
|
+
/**
|
|
178
|
+
* Direct access to WhisperContext for advanced usage
|
|
179
|
+
*/
|
|
180
|
+
raw(): WhisperContext;
|
|
181
|
+
private extractMemoryIdsFromBulkResponse;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
interface AgentMiddlewareConfig extends WhisperOptions {
|
|
185
|
+
/**
|
|
186
|
+
* Build the prompt passed to the model.
|
|
187
|
+
*/
|
|
188
|
+
promptBuilder?: (params: {
|
|
189
|
+
context: string;
|
|
190
|
+
userMessage: string;
|
|
191
|
+
}) => string;
|
|
192
|
+
}
|
|
193
|
+
interface AgentTurnParams {
|
|
194
|
+
userMessage: string;
|
|
195
|
+
userId?: string;
|
|
196
|
+
sessionId?: string;
|
|
197
|
+
project?: string;
|
|
198
|
+
contextLimit?: number;
|
|
199
|
+
}
|
|
200
|
+
interface AgentTurnResult {
|
|
201
|
+
prompt: string;
|
|
202
|
+
context: string;
|
|
203
|
+
contextCount: number;
|
|
204
|
+
}
|
|
205
|
+
interface WrappedGenerateResult {
|
|
206
|
+
response: string;
|
|
207
|
+
prompt: string;
|
|
208
|
+
context: string;
|
|
209
|
+
contextCount: number;
|
|
210
|
+
extracted: number;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Drop-in middleware for existing AI agents.
|
|
214
|
+
*
|
|
215
|
+
* Typical flow:
|
|
216
|
+
* 1) beforeTurn -> retrieve context
|
|
217
|
+
* 2) call your model
|
|
218
|
+
* 3) afterTurn -> store memories
|
|
219
|
+
*/
|
|
220
|
+
declare class WhisperAgentMiddleware {
|
|
221
|
+
private readonly whisper;
|
|
222
|
+
private readonly promptBuilder;
|
|
223
|
+
constructor(config: AgentMiddlewareConfig);
|
|
224
|
+
beforeTurn(params: AgentTurnParams): Promise<AgentTurnResult>;
|
|
225
|
+
afterTurn(params: {
|
|
226
|
+
userMessage: string;
|
|
227
|
+
assistantMessage: string;
|
|
228
|
+
userId?: string;
|
|
229
|
+
sessionId?: string;
|
|
230
|
+
project?: string;
|
|
231
|
+
}): Promise<{
|
|
232
|
+
success: boolean;
|
|
233
|
+
extracted: number;
|
|
234
|
+
}>;
|
|
235
|
+
wrapGenerate(params: AgentTurnParams & {
|
|
236
|
+
generate: (prompt: string) => Promise<string>;
|
|
237
|
+
}): Promise<WrappedGenerateResult>;
|
|
238
|
+
raw(): Whisper;
|
|
239
|
+
}
|
|
240
|
+
declare function createAgentMiddleware(config: AgentMiddlewareConfig): WhisperAgentMiddleware;
|
|
241
|
+
|
|
1
242
|
/**
|
|
2
243
|
* Whisper Context SDK
|
|
3
244
|
* TypeScript SDK for the Whisper Context API
|
|
@@ -6,7 +247,6 @@ interface WhisperConfig {
|
|
|
6
247
|
apiKey: string;
|
|
7
248
|
baseUrl?: string;
|
|
8
249
|
project?: string;
|
|
9
|
-
orgId?: string;
|
|
10
250
|
timeoutMs?: number;
|
|
11
251
|
retry?: {
|
|
12
252
|
maxAttempts?: number;
|
|
@@ -95,6 +335,23 @@ interface Memory {
|
|
|
95
335
|
createdAt: string;
|
|
96
336
|
updatedAt: string;
|
|
97
337
|
}
|
|
338
|
+
type MemoryKind = "factual" | "preference" | "event" | "relationship" | "opinion" | "goal" | "instruction";
|
|
339
|
+
interface ExtractedMemory {
|
|
340
|
+
content: string;
|
|
341
|
+
memoryType: MemoryKind;
|
|
342
|
+
entityMentions: string[];
|
|
343
|
+
eventDate: string | null;
|
|
344
|
+
confidence: number;
|
|
345
|
+
reasoning?: string;
|
|
346
|
+
inferred?: boolean;
|
|
347
|
+
}
|
|
348
|
+
interface MemoryExtractionResult {
|
|
349
|
+
explicit: ExtractedMemory[];
|
|
350
|
+
implicit: ExtractedMemory[];
|
|
351
|
+
all: ExtractedMemory[];
|
|
352
|
+
extractionMethod: "pattern" | "inference" | "hybrid" | "skipped";
|
|
353
|
+
latencyMs: number;
|
|
354
|
+
}
|
|
98
355
|
type WhisperErrorCode = "INVALID_API_KEY" | "PROJECT_NOT_FOUND" | "PROJECT_AMBIGUOUS" | "RATE_LIMITED" | "TEMPORARY_UNAVAILABLE" | "NETWORK_ERROR" | "TIMEOUT" | "REQUEST_FAILED" | "MISSING_PROJECT";
|
|
99
356
|
declare class WhisperError extends Error {
|
|
100
357
|
code: WhisperErrorCode;
|
|
@@ -113,7 +370,6 @@ declare class WhisperContext {
|
|
|
113
370
|
private apiKey;
|
|
114
371
|
private baseUrl;
|
|
115
372
|
private defaultProject?;
|
|
116
|
-
private orgId?;
|
|
117
373
|
private timeoutMs;
|
|
118
374
|
private retryConfig;
|
|
119
375
|
private projectRefToId;
|
|
@@ -184,6 +440,51 @@ declare class WhisperContext {
|
|
|
184
440
|
path: "sota" | "legacy";
|
|
185
441
|
fallback_used: boolean;
|
|
186
442
|
}>;
|
|
443
|
+
addMemoriesBulk(params: {
|
|
444
|
+
project?: string;
|
|
445
|
+
memories: Array<{
|
|
446
|
+
content: string;
|
|
447
|
+
memory_type?: MemoryKind | "episodic" | "semantic" | "procedural";
|
|
448
|
+
user_id?: string;
|
|
449
|
+
session_id?: string;
|
|
450
|
+
agent_id?: string;
|
|
451
|
+
importance?: number;
|
|
452
|
+
confidence?: number;
|
|
453
|
+
metadata?: Record<string, any>;
|
|
454
|
+
entity_mentions?: string[];
|
|
455
|
+
document_date?: string;
|
|
456
|
+
event_date?: string;
|
|
457
|
+
}>;
|
|
458
|
+
namespace?: string;
|
|
459
|
+
tags?: string[];
|
|
460
|
+
async?: boolean;
|
|
461
|
+
webhook_url?: string;
|
|
462
|
+
}): Promise<any>;
|
|
463
|
+
extractMemories(params: {
|
|
464
|
+
project?: string;
|
|
465
|
+
message: string;
|
|
466
|
+
context?: string;
|
|
467
|
+
session_id?: string;
|
|
468
|
+
user_id?: string;
|
|
469
|
+
enable_pattern?: boolean;
|
|
470
|
+
enable_inference?: boolean;
|
|
471
|
+
min_confidence?: number;
|
|
472
|
+
}): Promise<MemoryExtractionResult>;
|
|
473
|
+
extractSessionMemories(params: {
|
|
474
|
+
project?: string;
|
|
475
|
+
user_id?: string;
|
|
476
|
+
messages: Array<{
|
|
477
|
+
role: "user" | "assistant" | "system";
|
|
478
|
+
content: string;
|
|
479
|
+
timestamp?: string;
|
|
480
|
+
}>;
|
|
481
|
+
enable_pattern?: boolean;
|
|
482
|
+
enable_inference?: boolean;
|
|
483
|
+
}): Promise<{
|
|
484
|
+
memories: ExtractedMemory[];
|
|
485
|
+
count: number;
|
|
486
|
+
latencyMs: number;
|
|
487
|
+
}>;
|
|
187
488
|
searchMemories(params: {
|
|
188
489
|
project?: string;
|
|
189
490
|
query: string;
|
|
@@ -490,6 +791,13 @@ declare class WhisperContext {
|
|
|
490
791
|
path: "sota" | "legacy";
|
|
491
792
|
fallback_used: boolean;
|
|
492
793
|
}>;
|
|
794
|
+
addBulk: (params: Parameters<WhisperContext["addMemoriesBulk"]>[0]) => Promise<any>;
|
|
795
|
+
extract: (params: Parameters<WhisperContext["extractMemories"]>[0]) => Promise<MemoryExtractionResult>;
|
|
796
|
+
extractSession: (params: Parameters<WhisperContext["extractSessionMemories"]>[0]) => Promise<{
|
|
797
|
+
memories: ExtractedMemory[];
|
|
798
|
+
count: number;
|
|
799
|
+
latencyMs: number;
|
|
800
|
+
}>;
|
|
493
801
|
search: (params: Parameters<WhisperContext["searchMemories"]>[0]) => Promise<any>;
|
|
494
802
|
searchSOTA: (params: Parameters<WhisperContext["searchMemoriesSOTA"]>[0]) => Promise<any>;
|
|
495
803
|
ingestSession: (params: Parameters<WhisperContext["ingestSession"]>[0]) => Promise<{
|
|
@@ -611,4 +919,4 @@ declare class WhisperContext {
|
|
|
611
919
|
};
|
|
612
920
|
}
|
|
613
921
|
|
|
614
|
-
export { type Memory, type Project, type QueryParams, type QueryResult, type Source, type WhisperConfig, WhisperContext, WhisperError, type WhisperErrorCode, WhisperContext as default };
|
|
922
|
+
export { type ExtractedMemory, type Memory, type MemoryExtractionResult, type MemoryKind, type Project, type QueryParams, type QueryResult, type Source, Whisper, WhisperAgentMiddleware, type WhisperConfig, WhisperContext, Whisper as WhisperDefault, WhisperError, type WhisperErrorCode, createAgentMiddleware, WhisperContext as default };
|