@usewhisper/sdk 0.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 -0
- package/index.cjs +117 -0
- package/index.d.cts +166 -0
- package/index.d.ts +166 -0
- package/index.js +92 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +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
|
package/index.cjs
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/sdk/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
WhisperContext: () => WhisperContext,
|
|
24
|
+
default: () => index_default
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var WhisperContext = class {
|
|
28
|
+
apiKey;
|
|
29
|
+
baseUrl;
|
|
30
|
+
constructor(config) {
|
|
31
|
+
if (!config.apiKey) {
|
|
32
|
+
throw new Error("API key is required");
|
|
33
|
+
}
|
|
34
|
+
this.apiKey = config.apiKey;
|
|
35
|
+
this.baseUrl = config.baseUrl || "https://context.usewhisper.dev";
|
|
36
|
+
}
|
|
37
|
+
async request(endpoint, options = {}) {
|
|
38
|
+
const response = await fetch(`${this.baseUrl}${endpoint}`, {
|
|
39
|
+
...options,
|
|
40
|
+
headers: {
|
|
41
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
42
|
+
"Content-Type": "application/json",
|
|
43
|
+
...options.headers
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
const error = await response.json().catch(() => ({ error: "Request failed" }));
|
|
48
|
+
throw new Error(error.error || `HTTP ${response.status}: ${response.statusText}`);
|
|
49
|
+
}
|
|
50
|
+
return response.json();
|
|
51
|
+
}
|
|
52
|
+
async query(params) {
|
|
53
|
+
return this.request("/v1/context/query", {
|
|
54
|
+
method: "POST",
|
|
55
|
+
body: JSON.stringify(params)
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
async createProject(params) {
|
|
59
|
+
return this.request("/v1/projects", {
|
|
60
|
+
method: "POST",
|
|
61
|
+
body: JSON.stringify(params)
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async listProjects() {
|
|
65
|
+
return this.request("/v1/projects");
|
|
66
|
+
}
|
|
67
|
+
async getProject(id) {
|
|
68
|
+
return this.request(`/v1/projects/${id}`);
|
|
69
|
+
}
|
|
70
|
+
async deleteProject(id) {
|
|
71
|
+
return this.request(`/v1/projects/${id}`, { method: "DELETE" });
|
|
72
|
+
}
|
|
73
|
+
async addSource(projectId, params) {
|
|
74
|
+
return this.request(`/v1/projects/${projectId}/sources`, {
|
|
75
|
+
method: "POST",
|
|
76
|
+
body: JSON.stringify(params)
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
async syncSource(sourceId) {
|
|
80
|
+
return this.request(`/v1/sources/${sourceId}/sync`, { method: "POST" });
|
|
81
|
+
}
|
|
82
|
+
async ingest(projectId, documents) {
|
|
83
|
+
return this.request(`/v1/projects/${projectId}/ingest`, {
|
|
84
|
+
method: "POST",
|
|
85
|
+
body: JSON.stringify({ documents })
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
async addMemory(params) {
|
|
89
|
+
return this.request("/v1/memories", {
|
|
90
|
+
method: "POST",
|
|
91
|
+
body: JSON.stringify(params)
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async searchMemories(params) {
|
|
95
|
+
return this.request("/v1/memories/search", {
|
|
96
|
+
method: "POST",
|
|
97
|
+
body: JSON.stringify(params)
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
async createApiKey(params) {
|
|
101
|
+
return this.request("/v1/keys", {
|
|
102
|
+
method: "POST",
|
|
103
|
+
body: JSON.stringify(params)
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
async listApiKeys() {
|
|
107
|
+
return this.request("/v1/keys");
|
|
108
|
+
}
|
|
109
|
+
async getUsage(days = 30) {
|
|
110
|
+
return this.request(`/v1/usage?days=${days}`);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
var index_default = WhisperContext;
|
|
114
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
115
|
+
0 && (module.exports = {
|
|
116
|
+
WhisperContext
|
|
117
|
+
});
|
package/index.d.cts
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whisper Context SDK
|
|
3
|
+
* TypeScript SDK for the Whisper Context API
|
|
4
|
+
*/
|
|
5
|
+
interface WhisperConfig {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
}
|
|
9
|
+
interface QueryParams {
|
|
10
|
+
project: string;
|
|
11
|
+
query: string;
|
|
12
|
+
top_k?: number;
|
|
13
|
+
threshold?: number;
|
|
14
|
+
chunk_types?: string[];
|
|
15
|
+
source_ids?: string[];
|
|
16
|
+
hybrid?: boolean;
|
|
17
|
+
vector_weight?: number;
|
|
18
|
+
bm25_weight?: number;
|
|
19
|
+
rerank?: boolean;
|
|
20
|
+
include_memories?: boolean;
|
|
21
|
+
user_id?: string;
|
|
22
|
+
session_id?: string;
|
|
23
|
+
agent_id?: string;
|
|
24
|
+
include_graph?: boolean;
|
|
25
|
+
graph_depth?: number;
|
|
26
|
+
max_tokens?: number;
|
|
27
|
+
compress?: boolean;
|
|
28
|
+
compression_strategy?: "summarize" | "extract" | "delta" | "adaptive";
|
|
29
|
+
use_cache?: boolean;
|
|
30
|
+
}
|
|
31
|
+
interface QueryResult {
|
|
32
|
+
results: Array<{
|
|
33
|
+
id: string;
|
|
34
|
+
content: string;
|
|
35
|
+
score: number;
|
|
36
|
+
metadata: Record<string, any>;
|
|
37
|
+
source: string;
|
|
38
|
+
document: string;
|
|
39
|
+
type: string;
|
|
40
|
+
retrieval_source: string;
|
|
41
|
+
}>;
|
|
42
|
+
context: string;
|
|
43
|
+
meta: {
|
|
44
|
+
query: string;
|
|
45
|
+
total: number;
|
|
46
|
+
latency_ms: number;
|
|
47
|
+
cache_hit: boolean;
|
|
48
|
+
tokens_used: number;
|
|
49
|
+
context_hash: string;
|
|
50
|
+
compression?: any;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
interface Project {
|
|
54
|
+
id: string;
|
|
55
|
+
orgId: string;
|
|
56
|
+
name: string;
|
|
57
|
+
slug: string;
|
|
58
|
+
description?: string;
|
|
59
|
+
settings?: Record<string, any>;
|
|
60
|
+
createdAt: string;
|
|
61
|
+
updatedAt: string;
|
|
62
|
+
}
|
|
63
|
+
interface Source {
|
|
64
|
+
id: string;
|
|
65
|
+
projectId: string;
|
|
66
|
+
name: string;
|
|
67
|
+
connectorType: string;
|
|
68
|
+
config: Record<string, any>;
|
|
69
|
+
status: string;
|
|
70
|
+
syncSchedule?: string;
|
|
71
|
+
lastSyncAt?: string;
|
|
72
|
+
syncError?: string;
|
|
73
|
+
createdAt: string;
|
|
74
|
+
updatedAt: string;
|
|
75
|
+
}
|
|
76
|
+
interface Memory {
|
|
77
|
+
id: string;
|
|
78
|
+
projectId: string;
|
|
79
|
+
content: string;
|
|
80
|
+
memoryType: "factual" | "episodic" | "semantic" | "procedural";
|
|
81
|
+
userId?: string;
|
|
82
|
+
sessionId?: string;
|
|
83
|
+
agentId?: string;
|
|
84
|
+
importance: number;
|
|
85
|
+
metadata: Record<string, any>;
|
|
86
|
+
accessCount: number;
|
|
87
|
+
createdAt: string;
|
|
88
|
+
updatedAt: string;
|
|
89
|
+
}
|
|
90
|
+
declare class WhisperContext {
|
|
91
|
+
private apiKey;
|
|
92
|
+
private baseUrl;
|
|
93
|
+
constructor(config: WhisperConfig);
|
|
94
|
+
private request;
|
|
95
|
+
query(params: QueryParams): Promise<QueryResult>;
|
|
96
|
+
createProject(params: {
|
|
97
|
+
name: string;
|
|
98
|
+
description?: string;
|
|
99
|
+
settings?: Record<string, any>;
|
|
100
|
+
}): Promise<Project>;
|
|
101
|
+
listProjects(): Promise<{
|
|
102
|
+
projects: Project[];
|
|
103
|
+
}>;
|
|
104
|
+
getProject(id: string): Promise<Project & {
|
|
105
|
+
sources: Source[];
|
|
106
|
+
}>;
|
|
107
|
+
deleteProject(id: string): Promise<{
|
|
108
|
+
deleted: boolean;
|
|
109
|
+
}>;
|
|
110
|
+
addSource(projectId: string, params: {
|
|
111
|
+
name: string;
|
|
112
|
+
connector_type: string;
|
|
113
|
+
config: Record<string, any>;
|
|
114
|
+
sync_schedule?: string;
|
|
115
|
+
}): Promise<Source>;
|
|
116
|
+
syncSource(sourceId: string): Promise<any>;
|
|
117
|
+
ingest(projectId: string, documents: Array<{
|
|
118
|
+
id?: string;
|
|
119
|
+
title: string;
|
|
120
|
+
content: string;
|
|
121
|
+
metadata?: Record<string, any>;
|
|
122
|
+
file_path?: string;
|
|
123
|
+
}>): Promise<{
|
|
124
|
+
ingested: number;
|
|
125
|
+
}>;
|
|
126
|
+
addMemory(params: {
|
|
127
|
+
project: string;
|
|
128
|
+
content: string;
|
|
129
|
+
memory_type?: "factual" | "episodic" | "semantic" | "procedural";
|
|
130
|
+
user_id?: string;
|
|
131
|
+
session_id?: string;
|
|
132
|
+
agent_id?: string;
|
|
133
|
+
importance?: number;
|
|
134
|
+
metadata?: Record<string, any>;
|
|
135
|
+
expires_in_seconds?: number;
|
|
136
|
+
}): Promise<Memory>;
|
|
137
|
+
searchMemories(params: {
|
|
138
|
+
project: string;
|
|
139
|
+
query: string;
|
|
140
|
+
user_id?: string;
|
|
141
|
+
session_id?: string;
|
|
142
|
+
agent_id?: string;
|
|
143
|
+
memory_type?: "factual" | "episodic" | "semantic" | "procedural";
|
|
144
|
+
top_k?: number;
|
|
145
|
+
}): Promise<{
|
|
146
|
+
memories: Array<Memory & {
|
|
147
|
+
score: number;
|
|
148
|
+
}>;
|
|
149
|
+
}>;
|
|
150
|
+
createApiKey(params: {
|
|
151
|
+
name: string;
|
|
152
|
+
scopes?: string[];
|
|
153
|
+
rate_limit?: number;
|
|
154
|
+
expires_in_days?: number;
|
|
155
|
+
}): Promise<{
|
|
156
|
+
key: string;
|
|
157
|
+
prefix: string;
|
|
158
|
+
name: string;
|
|
159
|
+
}>;
|
|
160
|
+
listApiKeys(): Promise<{
|
|
161
|
+
keys: any[];
|
|
162
|
+
}>;
|
|
163
|
+
getUsage(days?: number): Promise<any>;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export { type Memory, type Project, type QueryParams, type QueryResult, type Source, type WhisperConfig, WhisperContext, WhisperContext as default };
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whisper Context SDK
|
|
3
|
+
* TypeScript SDK for the Whisper Context API
|
|
4
|
+
*/
|
|
5
|
+
interface WhisperConfig {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
}
|
|
9
|
+
interface QueryParams {
|
|
10
|
+
project: string;
|
|
11
|
+
query: string;
|
|
12
|
+
top_k?: number;
|
|
13
|
+
threshold?: number;
|
|
14
|
+
chunk_types?: string[];
|
|
15
|
+
source_ids?: string[];
|
|
16
|
+
hybrid?: boolean;
|
|
17
|
+
vector_weight?: number;
|
|
18
|
+
bm25_weight?: number;
|
|
19
|
+
rerank?: boolean;
|
|
20
|
+
include_memories?: boolean;
|
|
21
|
+
user_id?: string;
|
|
22
|
+
session_id?: string;
|
|
23
|
+
agent_id?: string;
|
|
24
|
+
include_graph?: boolean;
|
|
25
|
+
graph_depth?: number;
|
|
26
|
+
max_tokens?: number;
|
|
27
|
+
compress?: boolean;
|
|
28
|
+
compression_strategy?: "summarize" | "extract" | "delta" | "adaptive";
|
|
29
|
+
use_cache?: boolean;
|
|
30
|
+
}
|
|
31
|
+
interface QueryResult {
|
|
32
|
+
results: Array<{
|
|
33
|
+
id: string;
|
|
34
|
+
content: string;
|
|
35
|
+
score: number;
|
|
36
|
+
metadata: Record<string, any>;
|
|
37
|
+
source: string;
|
|
38
|
+
document: string;
|
|
39
|
+
type: string;
|
|
40
|
+
retrieval_source: string;
|
|
41
|
+
}>;
|
|
42
|
+
context: string;
|
|
43
|
+
meta: {
|
|
44
|
+
query: string;
|
|
45
|
+
total: number;
|
|
46
|
+
latency_ms: number;
|
|
47
|
+
cache_hit: boolean;
|
|
48
|
+
tokens_used: number;
|
|
49
|
+
context_hash: string;
|
|
50
|
+
compression?: any;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
interface Project {
|
|
54
|
+
id: string;
|
|
55
|
+
orgId: string;
|
|
56
|
+
name: string;
|
|
57
|
+
slug: string;
|
|
58
|
+
description?: string;
|
|
59
|
+
settings?: Record<string, any>;
|
|
60
|
+
createdAt: string;
|
|
61
|
+
updatedAt: string;
|
|
62
|
+
}
|
|
63
|
+
interface Source {
|
|
64
|
+
id: string;
|
|
65
|
+
projectId: string;
|
|
66
|
+
name: string;
|
|
67
|
+
connectorType: string;
|
|
68
|
+
config: Record<string, any>;
|
|
69
|
+
status: string;
|
|
70
|
+
syncSchedule?: string;
|
|
71
|
+
lastSyncAt?: string;
|
|
72
|
+
syncError?: string;
|
|
73
|
+
createdAt: string;
|
|
74
|
+
updatedAt: string;
|
|
75
|
+
}
|
|
76
|
+
interface Memory {
|
|
77
|
+
id: string;
|
|
78
|
+
projectId: string;
|
|
79
|
+
content: string;
|
|
80
|
+
memoryType: "factual" | "episodic" | "semantic" | "procedural";
|
|
81
|
+
userId?: string;
|
|
82
|
+
sessionId?: string;
|
|
83
|
+
agentId?: string;
|
|
84
|
+
importance: number;
|
|
85
|
+
metadata: Record<string, any>;
|
|
86
|
+
accessCount: number;
|
|
87
|
+
createdAt: string;
|
|
88
|
+
updatedAt: string;
|
|
89
|
+
}
|
|
90
|
+
declare class WhisperContext {
|
|
91
|
+
private apiKey;
|
|
92
|
+
private baseUrl;
|
|
93
|
+
constructor(config: WhisperConfig);
|
|
94
|
+
private request;
|
|
95
|
+
query(params: QueryParams): Promise<QueryResult>;
|
|
96
|
+
createProject(params: {
|
|
97
|
+
name: string;
|
|
98
|
+
description?: string;
|
|
99
|
+
settings?: Record<string, any>;
|
|
100
|
+
}): Promise<Project>;
|
|
101
|
+
listProjects(): Promise<{
|
|
102
|
+
projects: Project[];
|
|
103
|
+
}>;
|
|
104
|
+
getProject(id: string): Promise<Project & {
|
|
105
|
+
sources: Source[];
|
|
106
|
+
}>;
|
|
107
|
+
deleteProject(id: string): Promise<{
|
|
108
|
+
deleted: boolean;
|
|
109
|
+
}>;
|
|
110
|
+
addSource(projectId: string, params: {
|
|
111
|
+
name: string;
|
|
112
|
+
connector_type: string;
|
|
113
|
+
config: Record<string, any>;
|
|
114
|
+
sync_schedule?: string;
|
|
115
|
+
}): Promise<Source>;
|
|
116
|
+
syncSource(sourceId: string): Promise<any>;
|
|
117
|
+
ingest(projectId: string, documents: Array<{
|
|
118
|
+
id?: string;
|
|
119
|
+
title: string;
|
|
120
|
+
content: string;
|
|
121
|
+
metadata?: Record<string, any>;
|
|
122
|
+
file_path?: string;
|
|
123
|
+
}>): Promise<{
|
|
124
|
+
ingested: number;
|
|
125
|
+
}>;
|
|
126
|
+
addMemory(params: {
|
|
127
|
+
project: string;
|
|
128
|
+
content: string;
|
|
129
|
+
memory_type?: "factual" | "episodic" | "semantic" | "procedural";
|
|
130
|
+
user_id?: string;
|
|
131
|
+
session_id?: string;
|
|
132
|
+
agent_id?: string;
|
|
133
|
+
importance?: number;
|
|
134
|
+
metadata?: Record<string, any>;
|
|
135
|
+
expires_in_seconds?: number;
|
|
136
|
+
}): Promise<Memory>;
|
|
137
|
+
searchMemories(params: {
|
|
138
|
+
project: string;
|
|
139
|
+
query: string;
|
|
140
|
+
user_id?: string;
|
|
141
|
+
session_id?: string;
|
|
142
|
+
agent_id?: string;
|
|
143
|
+
memory_type?: "factual" | "episodic" | "semantic" | "procedural";
|
|
144
|
+
top_k?: number;
|
|
145
|
+
}): Promise<{
|
|
146
|
+
memories: Array<Memory & {
|
|
147
|
+
score: number;
|
|
148
|
+
}>;
|
|
149
|
+
}>;
|
|
150
|
+
createApiKey(params: {
|
|
151
|
+
name: string;
|
|
152
|
+
scopes?: string[];
|
|
153
|
+
rate_limit?: number;
|
|
154
|
+
expires_in_days?: number;
|
|
155
|
+
}): Promise<{
|
|
156
|
+
key: string;
|
|
157
|
+
prefix: string;
|
|
158
|
+
name: string;
|
|
159
|
+
}>;
|
|
160
|
+
listApiKeys(): Promise<{
|
|
161
|
+
keys: any[];
|
|
162
|
+
}>;
|
|
163
|
+
getUsage(days?: number): Promise<any>;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export { type Memory, type Project, type QueryParams, type QueryResult, type Source, type WhisperConfig, WhisperContext, WhisperContext as default };
|
package/index.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// src/sdk/index.ts
|
|
2
|
+
var WhisperContext = class {
|
|
3
|
+
apiKey;
|
|
4
|
+
baseUrl;
|
|
5
|
+
constructor(config) {
|
|
6
|
+
if (!config.apiKey) {
|
|
7
|
+
throw new Error("API key is required");
|
|
8
|
+
}
|
|
9
|
+
this.apiKey = config.apiKey;
|
|
10
|
+
this.baseUrl = config.baseUrl || "https://context.usewhisper.dev";
|
|
11
|
+
}
|
|
12
|
+
async request(endpoint, options = {}) {
|
|
13
|
+
const response = await fetch(`${this.baseUrl}${endpoint}`, {
|
|
14
|
+
...options,
|
|
15
|
+
headers: {
|
|
16
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
17
|
+
"Content-Type": "application/json",
|
|
18
|
+
...options.headers
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
const error = await response.json().catch(() => ({ error: "Request failed" }));
|
|
23
|
+
throw new Error(error.error || `HTTP ${response.status}: ${response.statusText}`);
|
|
24
|
+
}
|
|
25
|
+
return response.json();
|
|
26
|
+
}
|
|
27
|
+
async query(params) {
|
|
28
|
+
return this.request("/v1/context/query", {
|
|
29
|
+
method: "POST",
|
|
30
|
+
body: JSON.stringify(params)
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async createProject(params) {
|
|
34
|
+
return this.request("/v1/projects", {
|
|
35
|
+
method: "POST",
|
|
36
|
+
body: JSON.stringify(params)
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async listProjects() {
|
|
40
|
+
return this.request("/v1/projects");
|
|
41
|
+
}
|
|
42
|
+
async getProject(id) {
|
|
43
|
+
return this.request(`/v1/projects/${id}`);
|
|
44
|
+
}
|
|
45
|
+
async deleteProject(id) {
|
|
46
|
+
return this.request(`/v1/projects/${id}`, { method: "DELETE" });
|
|
47
|
+
}
|
|
48
|
+
async addSource(projectId, params) {
|
|
49
|
+
return this.request(`/v1/projects/${projectId}/sources`, {
|
|
50
|
+
method: "POST",
|
|
51
|
+
body: JSON.stringify(params)
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async syncSource(sourceId) {
|
|
55
|
+
return this.request(`/v1/sources/${sourceId}/sync`, { method: "POST" });
|
|
56
|
+
}
|
|
57
|
+
async ingest(projectId, documents) {
|
|
58
|
+
return this.request(`/v1/projects/${projectId}/ingest`, {
|
|
59
|
+
method: "POST",
|
|
60
|
+
body: JSON.stringify({ documents })
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async addMemory(params) {
|
|
64
|
+
return this.request("/v1/memories", {
|
|
65
|
+
method: "POST",
|
|
66
|
+
body: JSON.stringify(params)
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async searchMemories(params) {
|
|
70
|
+
return this.request("/v1/memories/search", {
|
|
71
|
+
method: "POST",
|
|
72
|
+
body: JSON.stringify(params)
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
async createApiKey(params) {
|
|
76
|
+
return this.request("/v1/keys", {
|
|
77
|
+
method: "POST",
|
|
78
|
+
body: JSON.stringify(params)
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async listApiKeys() {
|
|
82
|
+
return this.request("/v1/keys");
|
|
83
|
+
}
|
|
84
|
+
async getUsage(days = 30) {
|
|
85
|
+
return this.request(`/v1/usage?days=${days}`);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
var index_default = WhisperContext;
|
|
89
|
+
export {
|
|
90
|
+
WhisperContext,
|
|
91
|
+
index_default as default
|
|
92
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@usewhisper/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript SDK for Whisper Context API - Add reliable context to your AI agents",
|
|
5
|
+
"main": "index.cjs",
|
|
6
|
+
"module": "index.js",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./index.js",
|
|
11
|
+
"require": "./index.cjs",
|
|
12
|
+
"types": "./index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"index.js",
|
|
17
|
+
"index.cjs",
|
|
18
|
+
"index.d.ts",
|
|
19
|
+
"index.d.cts",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"whisper",
|
|
24
|
+
"context",
|
|
25
|
+
"ai",
|
|
26
|
+
"llm",
|
|
27
|
+
"rag",
|
|
28
|
+
"embeddings",
|
|
29
|
+
"vector-search",
|
|
30
|
+
"knowledge-graph",
|
|
31
|
+
"semantic-search"
|
|
32
|
+
],
|
|
33
|
+
"author": "Whisper",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/Alixus/whisper"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://usewhisper.dev",
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/Alinxus/whisper/issues"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^22.0.0",
|
|
45
|
+
"tsup": "^8.3.0",
|
|
46
|
+
"typescript": "^5.7.0"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=18.0.0"
|
|
51
|
+
}
|
|
52
|
+
}
|