@usewhisper/sdk 1.0.1 → 2.0.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 +208 -2
- package/index.d.ts +208 -2
- package/index.js +232 -15
- package/index.mjs +228 -15
- package/package.json +56 -56
package/README.md
CHANGED
|
@@ -1,256 +1,256 @@
|
|
|
1
|
-
# @usewhisper/sdk
|
|
2
|
-
|
|
3
|
-
Official TypeScript SDK for [Whisper Context API](https://usewhisper.dev) - Give your AI agents perfect context.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @usewhisper/sdk
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Quick Start
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
14
|
-
import { WhisperContext } from '@usewhisper/sdk';
|
|
15
|
-
|
|
16
|
-
const whisper = new WhisperContext({
|
|
17
|
-
apiKey: 'wctx_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
|
-
```
|
|
44
|
-
|
|
45
|
-
## Authentication
|
|
46
|
-
|
|
47
|
-
Get your API key from the [Whisper dashboard](https://usewhisper.dev/dashboard):
|
|
48
|
-
|
|
49
|
-
```typescript
|
|
50
|
-
const whisper = new WhisperContext({
|
|
51
|
-
apiKey: 'wctx_...', // Your API key
|
|
52
|
-
baseUrl: 'https://context.usewhisper.dev' // Optional, defaults to production
|
|
53
|
-
});
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## Core Features
|
|
57
|
-
|
|
58
|
-
### Context Query
|
|
59
|
-
|
|
60
|
-
```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
|
-
```
|
|
71
|
-
|
|
72
|
-
### Project Management
|
|
73
|
-
|
|
74
|
-
```typescript
|
|
75
|
-
// Create project
|
|
76
|
-
await whisper.createProject({ name: 'my-project' });
|
|
77
|
-
|
|
78
|
-
// List projects
|
|
79
|
-
const { projects } = await whisper.listProjects();
|
|
80
|
-
|
|
81
|
-
// Get project details
|
|
82
|
-
const project = await whisper.getProject(projectId);
|
|
83
|
-
|
|
84
|
-
// Delete project
|
|
85
|
-
await whisper.deleteProject(projectId);
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### Data Sources
|
|
89
|
-
|
|
90
|
-
Connect 15+ auto-sync sources:
|
|
91
|
-
|
|
92
|
-
```typescript
|
|
93
|
-
// GitHub repository
|
|
94
|
-
await whisper.addSource(projectId, {
|
|
95
|
-
name: 'GitHub Repo',
|
|
96
|
-
connector_type: 'github',
|
|
97
|
-
config: {
|
|
98
|
-
repo: 'owner/repo',
|
|
99
|
-
token: 'ghp_...',
|
|
100
|
-
branch: 'main'
|
|
101
|
-
},
|
|
102
|
-
sync_schedule: '0 */6 * * *' // Sync every 6 hours
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// Notion workspace
|
|
106
|
-
await whisper.addSource(projectId, {
|
|
107
|
-
name: 'Notion Docs',
|
|
108
|
-
connector_type: 'notion',
|
|
109
|
-
config: {
|
|
110
|
-
token: 'secret_...',
|
|
111
|
-
database_id: '...'
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
// Sync source manually
|
|
116
|
-
await whisper.syncSource(sourceId);
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
### Direct Ingestion
|
|
120
|
-
|
|
121
|
-
```typescript
|
|
122
|
-
await whisper.ingest(projectId, [
|
|
123
|
-
{
|
|
124
|
-
title: 'Document Title',
|
|
125
|
-
content: 'Document content...',
|
|
126
|
-
metadata: {
|
|
127
|
-
author: 'John Doe',
|
|
128
|
-
tags: ['api', 'docs']
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
]);
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
### Conversational Memory
|
|
135
|
-
|
|
136
|
-
```typescript
|
|
137
|
-
// Add memory
|
|
138
|
-
await whisper.addMemory({
|
|
139
|
-
project: 'my-docs',
|
|
140
|
-
content: 'User prefers dark mode',
|
|
141
|
-
memory_type: 'factual',
|
|
142
|
-
user_id: 'user123',
|
|
143
|
-
importance: 0.8
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
// Search memories
|
|
147
|
-
const { memories } = await whisper.searchMemories({
|
|
148
|
-
project: 'my-docs',
|
|
149
|
-
query: 'user preferences',
|
|
150
|
-
user_id: 'user123',
|
|
151
|
-
top_k: 10
|
|
152
|
-
});
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
## Supported Connectors
|
|
156
|
-
|
|
157
|
-
- **GitHub** - Repositories, issues, PRs
|
|
158
|
-
- **GitLab** - Projects, issues, MRs
|
|
159
|
-
- **Notion** - Pages, databases
|
|
160
|
-
- **Confluence** - Spaces, pages
|
|
161
|
-
- **Slack** - Channels, messages
|
|
162
|
-
- **Discord** - Channels, messages
|
|
163
|
-
- **URLs** - Web pages
|
|
164
|
-
- **Sitemaps** - Entire websites
|
|
165
|
-
- **PDFs** - PDF documents
|
|
166
|
-
- **API Specs** - OpenAPI/Swagger
|
|
167
|
-
- **Databases** - PostgreSQL, MySQL
|
|
168
|
-
- **npm** - Package documentation
|
|
169
|
-
- **PyPI** - Package documentation
|
|
170
|
-
- **arXiv** - Research papers
|
|
171
|
-
- **HuggingFace** - Model docs
|
|
172
|
-
|
|
173
|
-
## API Reference
|
|
174
|
-
|
|
175
|
-
### WhisperContext
|
|
176
|
-
|
|
177
|
-
#### Constructor
|
|
178
|
-
|
|
179
|
-
```typescript
|
|
180
|
-
new WhisperContext(config: {
|
|
181
|
-
apiKey: string;
|
|
182
|
-
baseUrl?: string;
|
|
183
|
-
})
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
#### Methods
|
|
187
|
-
|
|
188
|
-
**Projects:**
|
|
189
|
-
- `createProject(params)` - Create a new project
|
|
190
|
-
- `listProjects()` - List all projects
|
|
191
|
-
- `getProject(id)` - Get project details
|
|
192
|
-
- `deleteProject(id)` - Delete a project
|
|
193
|
-
|
|
194
|
-
**Sources:**
|
|
195
|
-
- `addSource(projectId, params)` - Add a data source
|
|
196
|
-
- `listSources(projectId)` - List project sources
|
|
197
|
-
- `syncSource(sourceId)` - Manually sync a source
|
|
198
|
-
- `updateSource(sourceId, params)` - Update source config
|
|
199
|
-
- `deleteSource(sourceId)` - Delete a source
|
|
200
|
-
|
|
201
|
-
**Context:**
|
|
202
|
-
- `query(params)` - Query context from your data
|
|
203
|
-
- `ingest(projectId, documents)` - Directly ingest documents
|
|
204
|
-
|
|
205
|
-
**Memory:**
|
|
206
|
-
- `addMemory(params)` - Add conversational memory
|
|
207
|
-
- `searchMemories(params)` - Search memories
|
|
208
|
-
- `listMemories(params)` - List all memories
|
|
209
|
-
- `updateMemory(id, params)` - Update a memory
|
|
210
|
-
- `deleteMemory(id)` - Delete a memory
|
|
211
|
-
|
|
212
|
-
**API Keys:**
|
|
213
|
-
- `createApiKey(params)` - Create a new API key
|
|
214
|
-
- `listApiKeys()` - List all API keys
|
|
215
|
-
- `deleteApiKey(id)` - Delete an API key
|
|
216
|
-
|
|
217
|
-
**Usage:**
|
|
218
|
-
- `getUsage(days)` - Get usage statistics
|
|
219
|
-
|
|
220
|
-
## Error Handling
|
|
221
|
-
|
|
222
|
-
```typescript
|
|
223
|
-
try {
|
|
224
|
-
const result = await whisper.query({
|
|
225
|
-
project: 'my-docs',
|
|
226
|
-
query: 'test'
|
|
227
|
-
});
|
|
228
|
-
} catch (error) {
|
|
229
|
-
if (error.message.includes('401')) {
|
|
230
|
-
console.error('Invalid API key');
|
|
231
|
-
} else if (error.message.includes('404')) {
|
|
232
|
-
console.error('Project not found');
|
|
233
|
-
} else {
|
|
234
|
-
console.error('Query failed:', error.message);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
## TypeScript Support
|
|
240
|
-
|
|
241
|
-
Full TypeScript support with type definitions included:
|
|
242
|
-
|
|
243
|
-
```typescript
|
|
244
|
-
import { WhisperContext, QueryParams, QueryResult } from '@usewhisper/sdk';
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
## Links
|
|
248
|
-
|
|
249
|
-
- [Documentation](https://docs.usewhisper.dev)
|
|
250
|
-
- [API Reference](https://context.usewhisper.dev)
|
|
251
|
-
- [GitHub](https://github.com/usewhisper/whisper)
|
|
252
|
-
- [Website](https://usewhisper.dev)
|
|
253
|
-
|
|
254
|
-
## License
|
|
255
|
-
|
|
256
|
-
MIT
|
|
1
|
+
# @usewhisper/sdk
|
|
2
|
+
|
|
3
|
+
Official TypeScript SDK for [Whisper Context API](https://usewhisper.dev) - Give your AI agents perfect context.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @usewhisper/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { WhisperContext } from '@usewhisper/sdk';
|
|
15
|
+
|
|
16
|
+
const whisper = new WhisperContext({
|
|
17
|
+
apiKey: 'wctx_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
|
+
```
|
|
44
|
+
|
|
45
|
+
## Authentication
|
|
46
|
+
|
|
47
|
+
Get your API key from the [Whisper dashboard](https://usewhisper.dev/dashboard):
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
const whisper = new WhisperContext({
|
|
51
|
+
apiKey: 'wctx_...', // Your API key
|
|
52
|
+
baseUrl: 'https://context.usewhisper.dev' // Optional, defaults to production
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Core Features
|
|
57
|
+
|
|
58
|
+
### Context Query
|
|
59
|
+
|
|
60
|
+
```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
|
+
```
|
|
71
|
+
|
|
72
|
+
### Project Management
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
// Create project
|
|
76
|
+
await whisper.createProject({ name: 'my-project' });
|
|
77
|
+
|
|
78
|
+
// List projects
|
|
79
|
+
const { projects } = await whisper.listProjects();
|
|
80
|
+
|
|
81
|
+
// Get project details
|
|
82
|
+
const project = await whisper.getProject(projectId);
|
|
83
|
+
|
|
84
|
+
// Delete project
|
|
85
|
+
await whisper.deleteProject(projectId);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Data Sources
|
|
89
|
+
|
|
90
|
+
Connect 15+ auto-sync sources:
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
// GitHub repository
|
|
94
|
+
await whisper.addSource(projectId, {
|
|
95
|
+
name: 'GitHub Repo',
|
|
96
|
+
connector_type: 'github',
|
|
97
|
+
config: {
|
|
98
|
+
repo: 'owner/repo',
|
|
99
|
+
token: 'ghp_...',
|
|
100
|
+
branch: 'main'
|
|
101
|
+
},
|
|
102
|
+
sync_schedule: '0 */6 * * *' // Sync every 6 hours
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// Notion workspace
|
|
106
|
+
await whisper.addSource(projectId, {
|
|
107
|
+
name: 'Notion Docs',
|
|
108
|
+
connector_type: 'notion',
|
|
109
|
+
config: {
|
|
110
|
+
token: 'secret_...',
|
|
111
|
+
database_id: '...'
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Sync source manually
|
|
116
|
+
await whisper.syncSource(sourceId);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Direct Ingestion
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
await whisper.ingest(projectId, [
|
|
123
|
+
{
|
|
124
|
+
title: 'Document Title',
|
|
125
|
+
content: 'Document content...',
|
|
126
|
+
metadata: {
|
|
127
|
+
author: 'John Doe',
|
|
128
|
+
tags: ['api', 'docs']
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
]);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Conversational Memory
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
// Add memory
|
|
138
|
+
await whisper.addMemory({
|
|
139
|
+
project: 'my-docs',
|
|
140
|
+
content: 'User prefers dark mode',
|
|
141
|
+
memory_type: 'factual',
|
|
142
|
+
user_id: 'user123',
|
|
143
|
+
importance: 0.8
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// Search memories
|
|
147
|
+
const { memories } = await whisper.searchMemories({
|
|
148
|
+
project: 'my-docs',
|
|
149
|
+
query: 'user preferences',
|
|
150
|
+
user_id: 'user123',
|
|
151
|
+
top_k: 10
|
|
152
|
+
});
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Supported Connectors
|
|
156
|
+
|
|
157
|
+
- **GitHub** - Repositories, issues, PRs
|
|
158
|
+
- **GitLab** - Projects, issues, MRs
|
|
159
|
+
- **Notion** - Pages, databases
|
|
160
|
+
- **Confluence** - Spaces, pages
|
|
161
|
+
- **Slack** - Channels, messages
|
|
162
|
+
- **Discord** - Channels, messages
|
|
163
|
+
- **URLs** - Web pages
|
|
164
|
+
- **Sitemaps** - Entire websites
|
|
165
|
+
- **PDFs** - PDF documents
|
|
166
|
+
- **API Specs** - OpenAPI/Swagger
|
|
167
|
+
- **Databases** - PostgreSQL, MySQL
|
|
168
|
+
- **npm** - Package documentation
|
|
169
|
+
- **PyPI** - Package documentation
|
|
170
|
+
- **arXiv** - Research papers
|
|
171
|
+
- **HuggingFace** - Model docs
|
|
172
|
+
|
|
173
|
+
## API Reference
|
|
174
|
+
|
|
175
|
+
### WhisperContext
|
|
176
|
+
|
|
177
|
+
#### Constructor
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
new WhisperContext(config: {
|
|
181
|
+
apiKey: string;
|
|
182
|
+
baseUrl?: string;
|
|
183
|
+
})
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
#### Methods
|
|
187
|
+
|
|
188
|
+
**Projects:**
|
|
189
|
+
- `createProject(params)` - Create a new project
|
|
190
|
+
- `listProjects()` - List all projects
|
|
191
|
+
- `getProject(id)` - Get project details
|
|
192
|
+
- `deleteProject(id)` - Delete a project
|
|
193
|
+
|
|
194
|
+
**Sources:**
|
|
195
|
+
- `addSource(projectId, params)` - Add a data source
|
|
196
|
+
- `listSources(projectId)` - List project sources
|
|
197
|
+
- `syncSource(sourceId)` - Manually sync a source
|
|
198
|
+
- `updateSource(sourceId, params)` - Update source config
|
|
199
|
+
- `deleteSource(sourceId)` - Delete a source
|
|
200
|
+
|
|
201
|
+
**Context:**
|
|
202
|
+
- `query(params)` - Query context from your data
|
|
203
|
+
- `ingest(projectId, documents)` - Directly ingest documents
|
|
204
|
+
|
|
205
|
+
**Memory:**
|
|
206
|
+
- `addMemory(params)` - Add conversational memory
|
|
207
|
+
- `searchMemories(params)` - Search memories
|
|
208
|
+
- `listMemories(params)` - List all memories
|
|
209
|
+
- `updateMemory(id, params)` - Update a memory
|
|
210
|
+
- `deleteMemory(id)` - Delete a memory
|
|
211
|
+
|
|
212
|
+
**API Keys:**
|
|
213
|
+
- `createApiKey(params)` - Create a new API key
|
|
214
|
+
- `listApiKeys()` - List all API keys
|
|
215
|
+
- `deleteApiKey(id)` - Delete an API key
|
|
216
|
+
|
|
217
|
+
**Usage:**
|
|
218
|
+
- `getUsage(days)` - Get usage statistics
|
|
219
|
+
|
|
220
|
+
## Error Handling
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
try {
|
|
224
|
+
const result = await whisper.query({
|
|
225
|
+
project: 'my-docs',
|
|
226
|
+
query: 'test'
|
|
227
|
+
});
|
|
228
|
+
} catch (error) {
|
|
229
|
+
if (error.message.includes('401')) {
|
|
230
|
+
console.error('Invalid API key');
|
|
231
|
+
} else if (error.message.includes('404')) {
|
|
232
|
+
console.error('Project not found');
|
|
233
|
+
} else {
|
|
234
|
+
console.error('Query failed:', error.message);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## TypeScript Support
|
|
240
|
+
|
|
241
|
+
Full TypeScript support with type definitions included:
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
import { WhisperContext, QueryParams, QueryResult } from '@usewhisper/sdk';
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Links
|
|
248
|
+
|
|
249
|
+
- [Documentation](https://docs.usewhisper.dev)
|
|
250
|
+
- [API Reference](https://context.usewhisper.dev)
|
|
251
|
+
- [GitHub](https://github.com/usewhisper/whisper)
|
|
252
|
+
- [Website](https://usewhisper.dev)
|
|
253
|
+
|
|
254
|
+
## License
|
|
255
|
+
|
|
256
|
+
MIT
|