@usewhisper/sdk 3.9.0 → 3.10.1
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 +285 -215
- package/adapters/ai-sdk.d.mts +2434 -0
- package/adapters/ai-sdk.d.ts +2434 -0
- package/adapters/ai-sdk.js +3141 -0
- package/adapters/ai-sdk.mjs +3104 -0
- package/adapters/tools.d.mts +2 -0
- package/adapters/tools.d.ts +2 -0
- package/adapters/tools.js +7097 -0
- package/adapters/tools.mjs +7066 -0
- package/index.d.mts +2 -2262
- package/index.d.ts +2 -2262
- package/index.js +4995 -123
- package/index.mjs +4996 -122
- package/package.json +30 -3
- package/router/memory-router.d.mts +2 -0
- package/router/memory-router.d.ts +2 -0
- package/router/memory-router.js +3118 -0
- package/router/memory-router.mjs +3080 -0
package/README.md
CHANGED
|
@@ -10,15 +10,15 @@ Official TypeScript SDK for [Whisper Context API](https://usewhisper.dev) - Give
|
|
|
10
10
|
- Legacy wrapper turn helpers now run through the automatic runtime by default.
|
|
11
11
|
- Context query responses expose `meta.source_scope`.
|
|
12
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
|
-
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @usewhisper/sdk
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
22
|
```typescript
|
|
23
23
|
import { WhisperClient } from '@usewhisper/sdk';
|
|
24
24
|
|
|
@@ -27,36 +27,107 @@ const client = new WhisperClient({
|
|
|
27
27
|
project: 'my-docs'
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
userId: 'user-123',
|
|
33
|
-
sessionId: 'session-abc',
|
|
34
|
-
clientName: 'my-agent-host'
|
|
30
|
+
const result = await client.query({
|
|
31
|
+
query: 'How does authentication work?'
|
|
35
32
|
});
|
|
36
33
|
|
|
37
|
-
|
|
38
|
-
|
|
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',
|
|
39
69
|
});
|
|
40
70
|
|
|
41
|
-
|
|
71
|
+
const tools = whisperTools({
|
|
72
|
+
apiKey: process.env.WHISPER_API_KEY!,
|
|
73
|
+
project: 'my-docs',
|
|
74
|
+
});
|
|
42
75
|
```
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
|
49
120
|
const client = new WhisperClient({
|
|
50
121
|
apiKey: 'wsk_...', // Your API key
|
|
51
122
|
baseUrl: 'https://context.usewhisper.dev' // Optional, defaults to production
|
|
52
123
|
});
|
|
53
124
|
```
|
|
54
|
-
|
|
55
|
-
## Core Features
|
|
56
|
-
|
|
57
|
-
### Context Query
|
|
58
|
-
|
|
59
|
-
```typescript
|
|
125
|
+
|
|
126
|
+
## Core Features
|
|
127
|
+
|
|
128
|
+
### Context Query
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
60
131
|
const result = await client.query({
|
|
61
132
|
project: 'my-docs',
|
|
62
133
|
query: 'Your question here',
|
|
@@ -70,189 +141,188 @@ const result = await client.query({
|
|
|
70
141
|
|
|
71
142
|
console.log(result.meta.source_scope);
|
|
72
143
|
```
|
|
73
|
-
|
|
74
|
-
### Project Management
|
|
75
|
-
|
|
76
|
-
```typescript
|
|
77
|
-
// Create project
|
|
78
|
-
await whisper.createProject({ name: 'my-project' });
|
|
79
|
-
|
|
80
|
-
// List projects
|
|
81
|
-
const { projects } = await whisper.listProjects();
|
|
82
|
-
|
|
83
|
-
// Get project details
|
|
84
|
-
const project = await whisper.getProject(projectId);
|
|
85
|
-
|
|
86
|
-
// Delete project
|
|
87
|
-
await whisper.deleteProject(projectId);
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
### Data Sources
|
|
91
|
-
|
|
92
|
-
Connect 15+ auto-sync sources:
|
|
93
|
-
|
|
94
|
-
```typescript
|
|
95
|
-
// GitHub repository
|
|
96
|
-
await whisper.addSource(projectId, {
|
|
97
|
-
name: 'GitHub Repo',
|
|
98
|
-
connector_type: 'github',
|
|
99
|
-
config: {
|
|
100
|
-
repo: 'owner/repo',
|
|
101
|
-
token: 'ghp_...',
|
|
102
|
-
branch: 'main'
|
|
103
|
-
},
|
|
104
|
-
sync_schedule: '0 */6 * * *' // Sync every 6 hours
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
// Notion workspace
|
|
108
|
-
await whisper.addSource(projectId, {
|
|
109
|
-
name: 'Notion Docs',
|
|
110
|
-
connector_type: 'notion',
|
|
111
|
-
config: {
|
|
112
|
-
token: 'secret_...',
|
|
113
|
-
database_id: '...'
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
// Sync source manually
|
|
118
|
-
await whisper.syncSource(sourceId);
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### Direct Ingestion
|
|
122
|
-
|
|
123
|
-
```typescript
|
|
124
|
-
await whisper.ingest(projectId, [
|
|
125
|
-
{
|
|
126
|
-
title: 'Document Title',
|
|
127
|
-
content: 'Document content...',
|
|
128
|
-
metadata: {
|
|
129
|
-
author: 'John Doe',
|
|
130
|
-
tags: ['api', 'docs']
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
]);
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
### Conversational Memory
|
|
137
|
-
|
|
138
|
-
```typescript
|
|
139
|
-
// Add memory
|
|
140
|
-
await whisper.addMemory({
|
|
141
|
-
project: 'my-docs',
|
|
142
|
-
content: 'User prefers dark mode',
|
|
143
|
-
memory_type: 'factual',
|
|
144
|
-
user_id: 'user123',
|
|
145
|
-
importance: 0.8
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// Search memories
|
|
149
|
-
const { memories } = await whisper.searchMemories({
|
|
150
|
-
project: 'my-docs',
|
|
151
|
-
query: 'user preferences',
|
|
152
|
-
user_id: 'user123',
|
|
153
|
-
top_k: 10
|
|
154
|
-
});
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
## Supported Connectors
|
|
158
|
-
|
|
159
|
-
- **GitHub** - Repositories, issues, PRs
|
|
160
|
-
- **GitLab** - Projects, issues, MRs
|
|
161
|
-
- **Notion** - Pages, databases
|
|
162
|
-
- **Confluence** - Spaces, pages
|
|
163
|
-
- **Slack** - Channels, messages
|
|
164
|
-
- **Discord** - Channels, messages
|
|
165
|
-
- **URLs** - Web pages
|
|
166
|
-
- **Sitemaps** - Entire websites
|
|
167
|
-
- **PDFs** - PDF documents
|
|
168
|
-
- **API Specs** - OpenAPI/Swagger
|
|
169
|
-
- **Databases** - PostgreSQL, MySQL
|
|
170
|
-
- **npm** - Package documentation
|
|
171
|
-
- **PyPI** - Package documentation
|
|
172
|
-
- **arXiv** - Research papers
|
|
173
|
-
- **HuggingFace** - Model docs
|
|
174
|
-
|
|
175
|
-
## API Reference
|
|
176
|
-
|
|
177
|
-
### WhisperContext
|
|
178
|
-
|
|
179
|
-
#### Constructor
|
|
180
|
-
|
|
181
|
-
```typescript
|
|
182
|
-
new WhisperContext(config: {
|
|
183
|
-
apiKey: string;
|
|
184
|
-
baseUrl?: string;
|
|
185
|
-
})
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
#### Methods
|
|
189
|
-
|
|
190
|
-
**Projects:**
|
|
191
|
-
- `createProject(params)` - Create a new project
|
|
192
|
-
- `listProjects()` - List all projects
|
|
193
|
-
- `getProject(id)` - Get project details
|
|
194
|
-
- `deleteProject(id)` - Delete a project
|
|
195
|
-
|
|
196
|
-
**Sources:**
|
|
197
|
-
- `addSource(projectId, params)` - Add a data source
|
|
198
|
-
- `listSources(projectId)` - List project sources
|
|
199
|
-
- `syncSource(sourceId)` - Manually sync a source
|
|
200
|
-
- `
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
- `
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
- `
|
|
209
|
-
- `
|
|
210
|
-
- `
|
|
211
|
-
- `
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
- `
|
|
216
|
-
- `
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
- [
|
|
252
|
-
- [
|
|
253
|
-
- [
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
MIT
|
|
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
|