@usewhisper/sdk 3.10.0 → 3.11.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,15 +1,15 @@
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.
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.
13
13
 
14
14
  ## Installation
15
15
 
@@ -17,59 +17,163 @@ Official TypeScript SDK for [Whisper Context API](https://usewhisper.dev) - Give
17
17
  npm install @usewhisper/sdk
18
18
  ```
19
19
 
20
+ ## Simple API (quickstart)
21
+
22
+ Four methods cover the most common use cases. The full `learn()` / `query()` signatures with all options are documented further below for power users.
23
+
24
+ ```typescript
25
+ import { WhisperClient } from '@usewhisper/sdk';
26
+
27
+ const whisper = new WhisperClient({
28
+ apiKey: process.env.WHISPER_API_KEY!,
29
+ project: 'my-project',
30
+ });
31
+
32
+ // Store a conversation — sessionId is auto-generated if omitted
33
+ await whisper.remember({
34
+ messages: [
35
+ { role: 'user', content: 'I prefer TypeScript over JavaScript' },
36
+ { role: 'assistant', content: 'Got it, I will use TypeScript.' },
37
+ ],
38
+ userId: req.user.id, // required unless getIdentity() is configured on the client
39
+ });
40
+
41
+ // Index a source — type is auto-detected from the URL
42
+ await whisper.ingest({ url: 'https://github.com/your-org/your-repo' });
43
+ await whisper.ingest({ url: 'https://docs.example.com' });
44
+ await whisper.ingest({ url: 'https://youtube.com/watch?v=abc123' });
45
+
46
+ // Query with short aliases — include_memories defaults to true when not specified
47
+ const { context } = await whisper.query({ q: userMessage, userId: req.user.id });
48
+
49
+ // Get everything Whisper knows about a user
50
+ const profile = await whisper.userProfile(req.user.id);
51
+ ```
52
+
20
53
  ## Quick Start
21
54
 
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
- ```
55
+ ```typescript
56
+ import { WhisperClient } from '@usewhisper/sdk';
57
+
58
+ const client = new WhisperClient({
59
+ apiKey: 'wsk_your_api_key_here',
60
+ project: 'my-docs'
61
+ });
62
+
63
+ const result = await client.query({
64
+ query: 'How does authentication work?'
65
+ });
66
+
67
+ console.log(result.meta.total);
68
+ ```
69
+
70
+ ### Typed errors
71
+
72
+ ```typescript
73
+ import { WhisperError } from '@usewhisper/sdk';
74
+
75
+ try {
76
+ await client.query({ query: 'How do I authenticate users?' });
77
+ } catch (error) {
78
+ if (error instanceof WhisperError) {
79
+ console.error(error.code, error.retryable, error.requestId, error.hint);
80
+ }
81
+ }
82
+ ```
83
+
84
+ ### Preflight (recommended before production)
85
+
86
+ ```typescript
87
+ const preflight = await client.preflight({ requireIdentity: false });
88
+ if (!preflight.ok) {
89
+ console.error(preflight.checks);
90
+ }
91
+ ```
92
+
93
+ ### Framework-native adapters
94
+
95
+ ```typescript
96
+ import { withWhisper } from '@usewhisper/sdk/ai-sdk';
97
+ import { whisperTools } from '@usewhisper/sdk/tools';
98
+
99
+ const wrappedModel = withWhisper(model, {
100
+ apiKey: process.env.WHISPER_API_KEY!,
101
+ project: 'my-docs',
102
+ });
103
+
104
+ const tools = whisperTools({
105
+ apiKey: process.env.WHISPER_API_KEY!,
106
+ project: 'my-docs',
107
+ });
108
+ ```
109
+
110
+ ### Experimental Memory Router (beta)
111
+
112
+ ```typescript
113
+ import { createMemoryRouter } from '@usewhisper/sdk/router';
114
+
115
+ const router = createMemoryRouter({
116
+ beta: true, // required until GA
117
+ apiKey: process.env.WHISPER_API_KEY!,
118
+ project: 'my-docs',
119
+ providerBaseUrl: 'https://api.openai.com',
120
+ providerApiKey: process.env.OPENAI_API_KEY!,
121
+ });
122
+
123
+ const response = await router.chatCompletions({
124
+ model: 'gpt-4o-mini',
125
+ messages: [{ role: 'user', content: 'What did we decide about retries?' }],
126
+ });
127
+ ```
128
+
129
+ ### SDK ownership contract
130
+
131
+ - SDK owns:
132
+ - auth header wiring and base URL resolution
133
+ - retries for retryable failures
134
+ - typed `WhisperError` surface
135
+ - `client.preflight()` readiness checks
136
+ - identity-mode guardrails (`demo-local` vs `app-identity`)
137
+ - Caller owns:
138
+ - authenticated app identity source (`getIdentity` and/or per-call identity)
139
+ - app-specific retry overrides
140
+ - application authorization decisions
141
+
142
+ ### Migration policy
143
+
144
+ - Release `N`: additive contract changes only, deprecations warn.
145
+ - Release `N+1`: deprecated paths may be enforced/removed.
146
+ - Current behavior: `demo-local` in non-local environments emits warnings (warn-only).
43
147
 
44
148
  ## Authentication
45
149
 
46
150
  Get your API key from the [Whisper dashboard](https://usewhisper.dev/dashboard):
47
151
 
48
152
  ```typescript
49
- const client = new WhisperClient({
50
- apiKey: 'wsk_...', // Your API key
51
- baseUrl: 'https://context.usewhisper.dev' // Optional, defaults to production
52
- });
53
- ```
153
+ const client = new WhisperClient({
154
+ apiKey: 'wsk_...', // Your API key
155
+ baseUrl: 'https://context.usewhisper.dev' // Optional, defaults to production
156
+ });
157
+ ```
54
158
 
55
159
  ## Core Features
56
160
 
57
161
  ### Context Query
58
162
 
59
163
  ```typescript
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
- ```
164
+ const result = await client.query({
165
+ project: 'my-docs',
166
+ query: 'Your question here',
167
+ top_k: 10, // Number of results
168
+ source_ids: ['src_abc'], // Optional explicit source isolation
169
+ include_memories: true, // Include conversational memory
170
+ include_graph: true, // Include knowledge graph
171
+ hybrid: true, // Hybrid vector + keyword search
172
+ rerank: true // Rerank results for better relevance
173
+ });
174
+
175
+ console.log(result.meta.source_scope);
176
+ ```
73
177
 
74
178
  ### Project Management
75
179
 
@@ -197,7 +301,6 @@ new WhisperContext(config: {
197
301
  - `addSource(projectId, params)` - Add a data source
198
302
  - `listSources(projectId)` - List project sources
199
303
  - `syncSource(sourceId)` - Manually sync a source
200
- - `updateSource(sourceId, params)` - Update source config
201
304
  - `deleteSource(sourceId)` - Delete a source
202
305
 
203
306
  **Context:**