@usewhisper/sdk 3.10.1 → 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,328 +1,361 @@
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
-
14
- ## Installation
15
-
16
- ```bash
17
- npm install @usewhisper/sdk
18
- ```
19
-
20
- ## Quick Start
21
-
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 result = await client.query({
31
- query: 'How does authentication work?'
32
- });
33
-
34
- console.log(result.meta.total);
35
- ```
36
-
37
- ### Typed errors
38
-
39
- ```typescript
40
- import { WhisperError } from '@usewhisper/sdk';
41
-
42
- try {
43
- await client.query({ query: 'How do I authenticate users?' });
44
- } catch (error) {
45
- if (error instanceof WhisperError) {
46
- console.error(error.code, error.retryable, error.requestId, error.hint);
47
- }
48
- }
49
- ```
50
-
51
- ### Preflight (recommended before production)
52
-
53
- ```typescript
54
- const preflight = await client.preflight({ requireIdentity: false });
55
- if (!preflight.ok) {
56
- console.error(preflight.checks);
57
- }
58
- ```
59
-
60
- ### Framework-native adapters
61
-
62
- ```typescript
63
- import { withWhisper } from '@usewhisper/sdk/ai-sdk';
64
- import { whisperTools } from '@usewhisper/sdk/tools';
65
-
66
- const wrappedModel = withWhisper(model, {
67
- apiKey: process.env.WHISPER_API_KEY!,
68
- project: 'my-docs',
69
- });
70
-
71
- const tools = whisperTools({
72
- apiKey: process.env.WHISPER_API_KEY!,
73
- project: 'my-docs',
74
- });
75
- ```
76
-
77
- ### Experimental Memory Router (beta)
78
-
79
- ```typescript
80
- import { createMemoryRouter } from '@usewhisper/sdk/router';
81
-
82
- const router = createMemoryRouter({
83
- beta: true, // required until GA
84
- apiKey: process.env.WHISPER_API_KEY!,
85
- project: 'my-docs',
86
- providerBaseUrl: 'https://api.openai.com',
87
- providerApiKey: process.env.OPENAI_API_KEY!,
88
- });
89
-
90
- const response = await router.chatCompletions({
91
- model: 'gpt-4o-mini',
92
- messages: [{ role: 'user', content: 'What did we decide about retries?' }],
93
- });
94
- ```
95
-
96
- ### SDK ownership contract
97
-
98
- - SDK owns:
99
- - auth header wiring and base URL resolution
100
- - retries for retryable failures
101
- - typed `WhisperError` surface
102
- - `client.preflight()` readiness checks
103
- - identity-mode guardrails (`demo-local` vs `app-identity`)
104
- - Caller owns:
105
- - authenticated app identity source (`getIdentity` and/or per-call identity)
106
- - app-specific retry overrides
107
- - application authorization decisions
108
-
109
- ### Migration policy
110
-
111
- - Release `N`: additive contract changes only, deprecations warn.
112
- - Release `N+1`: deprecated paths may be enforced/removed.
113
- - Current behavior: `demo-local` in non-local environments emits warnings (warn-only).
114
-
115
- ## Authentication
116
-
117
- Get your API key from the [Whisper dashboard](https://usewhisper.dev/dashboard):
118
-
119
- ```typescript
120
- const client = new WhisperClient({
121
- apiKey: 'wsk_...', // Your API key
122
- baseUrl: 'https://context.usewhisper.dev' // Optional, defaults to production
123
- });
124
- ```
125
-
126
- ## Core Features
127
-
128
- ### Context Query
129
-
130
- ```typescript
131
- const result = await client.query({
132
- project: 'my-docs',
133
- query: 'Your question here',
134
- top_k: 10, // Number of results
135
- source_ids: ['src_abc'], // Optional explicit source isolation
136
- include_memories: true, // Include conversational memory
137
- include_graph: true, // Include knowledge graph
138
- hybrid: true, // Hybrid vector + keyword search
139
- rerank: true // Rerank results for better relevance
140
- });
141
-
142
- console.log(result.meta.source_scope);
143
- ```
144
-
145
- ### Project Management
146
-
147
- ```typescript
148
- // Create project
149
- await whisper.createProject({ name: 'my-project' });
150
-
151
- // List projects
152
- const { projects } = await whisper.listProjects();
153
-
154
- // Get project details
155
- const project = await whisper.getProject(projectId);
156
-
157
- // Delete project
158
- await whisper.deleteProject(projectId);
159
- ```
160
-
161
- ### Data Sources
162
-
163
- Connect 15+ auto-sync sources:
164
-
165
- ```typescript
166
- // GitHub repository
167
- await whisper.addSource(projectId, {
168
- name: 'GitHub Repo',
169
- connector_type: 'github',
170
- config: {
171
- repo: 'owner/repo',
172
- token: 'ghp_...',
173
- branch: 'main'
174
- },
175
- sync_schedule: '0 */6 * * *' // Sync every 6 hours
176
- });
177
-
178
- // Notion workspace
179
- await whisper.addSource(projectId, {
180
- name: 'Notion Docs',
181
- connector_type: 'notion',
182
- config: {
183
- token: 'secret_...',
184
- database_id: '...'
185
- }
186
- });
187
-
188
- // Sync source manually
189
- await whisper.syncSource(sourceId);
190
- ```
191
-
192
- ### Direct Ingestion
193
-
194
- ```typescript
195
- await whisper.ingest(projectId, [
196
- {
197
- title: 'Document Title',
198
- content: 'Document content...',
199
- metadata: {
200
- author: 'John Doe',
201
- tags: ['api', 'docs']
202
- }
203
- }
204
- ]);
205
- ```
206
-
207
- ### Conversational Memory
208
-
209
- ```typescript
210
- // Add memory
211
- await whisper.addMemory({
212
- project: 'my-docs',
213
- content: 'User prefers dark mode',
214
- memory_type: 'factual',
215
- user_id: 'user123',
216
- importance: 0.8
217
- });
218
-
219
- // Search memories
220
- const { memories } = await whisper.searchMemories({
221
- project: 'my-docs',
222
- query: 'user preferences',
223
- user_id: 'user123',
224
- top_k: 10
225
- });
226
- ```
227
-
228
- ## Supported Connectors
229
-
230
- - **GitHub** - Repositories, issues, PRs
231
- - **GitLab** - Projects, issues, MRs
232
- - **Notion** - Pages, databases
233
- - **Confluence** - Spaces, pages
234
- - **Slack** - Channels, messages
235
- - **Discord** - Channels, messages
236
- - **URLs** - Web pages
237
- - **Sitemaps** - Entire websites
238
- - **PDFs** - PDF documents
239
- - **API Specs** - OpenAPI/Swagger
240
- - **Databases** - PostgreSQL, MySQL
241
- - **npm** - Package documentation
242
- - **PyPI** - Package documentation
243
- - **arXiv** - Research papers
244
- - **HuggingFace** - Model docs
245
-
246
- ## API Reference
247
-
248
- ### WhisperContext
249
-
250
- #### Constructor
251
-
252
- ```typescript
253
- new WhisperContext(config: {
254
- apiKey: string;
255
- baseUrl?: string;
256
- })
257
- ```
258
-
259
- #### Methods
260
-
261
- **Projects:**
262
- - `createProject(params)` - Create a new project
263
- - `listProjects()` - List all projects
264
- - `getProject(id)` - Get project details
265
- - `deleteProject(id)` - Delete a project
266
-
267
- **Sources:**
268
- - `addSource(projectId, params)` - Add a data source
269
- - `listSources(projectId)` - List project sources
270
- - `syncSource(sourceId)` - Manually sync a source
271
- - `deleteSource(sourceId)` - Delete a source
272
-
273
- **Context:**
274
- - `query(params)` - Query context from your data
275
- - `ingest(projectId, documents)` - Directly ingest documents
276
-
277
- **Memory:**
278
- - `addMemory(params)` - Add conversational memory
279
- - `searchMemories(params)` - Search memories
280
- - `listMemories(params)` - List all memories
281
- - `updateMemory(id, params)` - Update a memory
282
- - `deleteMemory(id)` - Delete a memory
283
-
284
- **API Keys:**
285
- - `createApiKey(params)` - Create a new API key
286
- - `listApiKeys()` - List all API keys
287
- - `deleteApiKey(id)` - Delete an API key
288
-
289
- **Usage:**
290
- - `getUsage(days)` - Get usage statistics
291
-
292
- ## Error Handling
293
-
294
- ```typescript
295
- try {
296
- const result = await whisper.query({
297
- project: 'my-docs',
298
- query: 'test'
299
- });
300
- } catch (error) {
301
- if (error.message.includes('401')) {
302
- console.error('Invalid API key');
303
- } else if (error.message.includes('404')) {
304
- console.error('Project not found');
305
- } else {
306
- console.error('Query failed:', error.message);
307
- }
308
- }
309
- ```
310
-
311
- ## TypeScript Support
312
-
313
- Full TypeScript support with type definitions included:
314
-
315
- ```typescript
316
- import { WhisperContext, QueryParams, QueryResult } from '@usewhisper/sdk';
317
- ```
318
-
319
- ## Links
320
-
321
- - [Documentation](https://docs.usewhisper.dev)
322
- - [API Reference](https://context.usewhisper.dev)
323
- - [GitHub](https://github.com/usewhisper/whisper)
324
- - [Website](https://usewhisper.dev)
325
-
326
- ## License
327
-
328
- MIT
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
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @usewhisper/sdk
18
+ ```
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
+
53
+ ## Quick Start
54
+
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).
147
+
148
+ ## Authentication
149
+
150
+ Get your API key from the [Whisper dashboard](https://usewhisper.dev/dashboard):
151
+
152
+ ```typescript
153
+ const client = new WhisperClient({
154
+ apiKey: 'wsk_...', // Your API key
155
+ baseUrl: 'https://context.usewhisper.dev' // Optional, defaults to production
156
+ });
157
+ ```
158
+
159
+ ## Core Features
160
+
161
+ ### Context Query
162
+
163
+ ```typescript
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
+ ```
177
+
178
+ ### Project Management
179
+
180
+ ```typescript
181
+ // Create project
182
+ await whisper.createProject({ name: 'my-project' });
183
+
184
+ // List projects
185
+ const { projects } = await whisper.listProjects();
186
+
187
+ // Get project details
188
+ const project = await whisper.getProject(projectId);
189
+
190
+ // Delete project
191
+ await whisper.deleteProject(projectId);
192
+ ```
193
+
194
+ ### Data Sources
195
+
196
+ Connect 15+ auto-sync sources:
197
+
198
+ ```typescript
199
+ // GitHub repository
200
+ await whisper.addSource(projectId, {
201
+ name: 'GitHub Repo',
202
+ connector_type: 'github',
203
+ config: {
204
+ repo: 'owner/repo',
205
+ token: 'ghp_...',
206
+ branch: 'main'
207
+ },
208
+ sync_schedule: '0 */6 * * *' // Sync every 6 hours
209
+ });
210
+
211
+ // Notion workspace
212
+ await whisper.addSource(projectId, {
213
+ name: 'Notion Docs',
214
+ connector_type: 'notion',
215
+ config: {
216
+ token: 'secret_...',
217
+ database_id: '...'
218
+ }
219
+ });
220
+
221
+ // Sync source manually
222
+ await whisper.syncSource(sourceId);
223
+ ```
224
+
225
+ ### Direct Ingestion
226
+
227
+ ```typescript
228
+ await whisper.ingest(projectId, [
229
+ {
230
+ title: 'Document Title',
231
+ content: 'Document content...',
232
+ metadata: {
233
+ author: 'John Doe',
234
+ tags: ['api', 'docs']
235
+ }
236
+ }
237
+ ]);
238
+ ```
239
+
240
+ ### Conversational Memory
241
+
242
+ ```typescript
243
+ // Add memory
244
+ await whisper.addMemory({
245
+ project: 'my-docs',
246
+ content: 'User prefers dark mode',
247
+ memory_type: 'factual',
248
+ user_id: 'user123',
249
+ importance: 0.8
250
+ });
251
+
252
+ // Search memories
253
+ const { memories } = await whisper.searchMemories({
254
+ project: 'my-docs',
255
+ query: 'user preferences',
256
+ user_id: 'user123',
257
+ top_k: 10
258
+ });
259
+ ```
260
+
261
+ ## Supported Connectors
262
+
263
+ - **GitHub** - Repositories, issues, PRs
264
+ - **GitLab** - Projects, issues, MRs
265
+ - **Notion** - Pages, databases
266
+ - **Confluence** - Spaces, pages
267
+ - **Slack** - Channels, messages
268
+ - **Discord** - Channels, messages
269
+ - **URLs** - Web pages
270
+ - **Sitemaps** - Entire websites
271
+ - **PDFs** - PDF documents
272
+ - **API Specs** - OpenAPI/Swagger
273
+ - **Databases** - PostgreSQL, MySQL
274
+ - **npm** - Package documentation
275
+ - **PyPI** - Package documentation
276
+ - **arXiv** - Research papers
277
+ - **HuggingFace** - Model docs
278
+
279
+ ## API Reference
280
+
281
+ ### WhisperContext
282
+
283
+ #### Constructor
284
+
285
+ ```typescript
286
+ new WhisperContext(config: {
287
+ apiKey: string;
288
+ baseUrl?: string;
289
+ })
290
+ ```
291
+
292
+ #### Methods
293
+
294
+ **Projects:**
295
+ - `createProject(params)` - Create a new project
296
+ - `listProjects()` - List all projects
297
+ - `getProject(id)` - Get project details
298
+ - `deleteProject(id)` - Delete a project
299
+
300
+ **Sources:**
301
+ - `addSource(projectId, params)` - Add a data source
302
+ - `listSources(projectId)` - List project sources
303
+ - `syncSource(sourceId)` - Manually sync a source
304
+ - `deleteSource(sourceId)` - Delete a source
305
+
306
+ **Context:**
307
+ - `query(params)` - Query context from your data
308
+ - `ingest(projectId, documents)` - Directly ingest documents
309
+
310
+ **Memory:**
311
+ - `addMemory(params)` - Add conversational memory
312
+ - `searchMemories(params)` - Search memories
313
+ - `listMemories(params)` - List all memories
314
+ - `updateMemory(id, params)` - Update a memory
315
+ - `deleteMemory(id)` - Delete a memory
316
+
317
+ **API Keys:**
318
+ - `createApiKey(params)` - Create a new API key
319
+ - `listApiKeys()` - List all API keys
320
+ - `deleteApiKey(id)` - Delete an API key
321
+
322
+ **Usage:**
323
+ - `getUsage(days)` - Get usage statistics
324
+
325
+ ## Error Handling
326
+
327
+ ```typescript
328
+ try {
329
+ const result = await whisper.query({
330
+ project: 'my-docs',
331
+ query: 'test'
332
+ });
333
+ } catch (error) {
334
+ if (error.message.includes('401')) {
335
+ console.error('Invalid API key');
336
+ } else if (error.message.includes('404')) {
337
+ console.error('Project not found');
338
+ } else {
339
+ console.error('Query failed:', error.message);
340
+ }
341
+ }
342
+ ```
343
+
344
+ ## TypeScript Support
345
+
346
+ Full TypeScript support with type definitions included:
347
+
348
+ ```typescript
349
+ import { WhisperContext, QueryParams, QueryResult } from '@usewhisper/sdk';
350
+ ```
351
+
352
+ ## Links
353
+
354
+ - [Documentation](https://docs.usewhisper.dev)
355
+ - [API Reference](https://context.usewhisper.dev)
356
+ - [GitHub](https://github.com/usewhisper/whisper)
357
+ - [Website](https://usewhisper.dev)
358
+
359
+ ## License
360
+
361
+ MIT