@ai2aim.ai/hivemind-sdk 1.0.14 → 2.0.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 +233 -657
- package/dist/cli-config.d.ts.map +1 -1
- package/dist/cli-config.js +0 -3
- package/dist/cli-config.js.map +1 -1
- package/dist/cli.js +115 -184
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts +83 -1110
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +338 -1374
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/sse.d.ts +14 -0
- package/dist/sse.d.ts.map +1 -0
- package/dist/sse.js +103 -0
- package/dist/sse.js.map +1 -0
- package/dist/types.d.ts +167 -613
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -3
- package/dist/types.js.map +1 -1
- package/dist/web.d.ts +0 -9
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +589 -1120
- package/dist/web.js.map +1 -1
- package/dist/ws.d.ts +33 -0
- package/dist/ws.d.ts.map +1 -0
- package/dist/ws.js +78 -0
- package/dist/ws.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,758 +1,334 @@
|
|
|
1
|
-
# @hivemind
|
|
1
|
+
# @ai2aim.ai/hivemind-sdk
|
|
2
2
|
|
|
3
|
-
Node.js / TypeScript SDK for the
|
|
4
|
-
Covers every endpoint — organizations, RAG queries, generation, scraping, analytics, billing, audio, agents, admin, Jira integration, and more.
|
|
5
|
-
Includes a **CLI** (`hivemind`) for init, config, health, helper utilities, query, search, org creation, music generation, scraping, and manual schedule execution.
|
|
3
|
+
Node.js / TypeScript SDK for the API-key-scoped Hivemind API.
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
The SDK tracks the current backend contract:
|
|
6
|
+
- no public organization id in request paths
|
|
7
|
+
- no public billing endpoints
|
|
8
|
+
- no public tier or employee-id surface
|
|
9
|
+
- API keys scope their own data
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
## Install
|
|
10
12
|
|
|
11
13
|
```bash
|
|
12
14
|
cd sdk
|
|
13
15
|
npm install
|
|
14
16
|
npm run build
|
|
15
|
-
|
|
16
|
-
# Then in your other project:
|
|
17
|
-
npm install ../path-to/VERTEX-AI/sdk
|
|
18
17
|
```
|
|
19
18
|
|
|
20
|
-
|
|
19
|
+
Then from another project:
|
|
21
20
|
|
|
22
21
|
```bash
|
|
23
|
-
npm install
|
|
22
|
+
npm install ../path-to/VERTEX-AI/sdk
|
|
24
23
|
```
|
|
25
24
|
|
|
26
|
-
## Quick
|
|
27
|
-
|
|
28
|
-
Set **HIVEMIND_BASE_URL** (or HIVEMIND_API_URL) in your environment once. Then create clients with only the overrides you need (e.g. `adminKey`, `apiKey`); baseUrl is read from env when omitted.
|
|
25
|
+
## Quick Start
|
|
29
26
|
|
|
30
|
-
```
|
|
31
|
-
import { HivemindClient } from "@hivemind
|
|
27
|
+
```ts
|
|
28
|
+
import { HivemindClient } from "@ai2aim.ai/hivemind-sdk";
|
|
32
29
|
|
|
33
30
|
const client = new HivemindClient({
|
|
34
|
-
|
|
31
|
+
baseUrl: process.env.HIVEMIND_BASE_URL!,
|
|
32
|
+
apiKey: process.env.HIVEMIND_API_KEY!,
|
|
35
33
|
});
|
|
36
34
|
|
|
37
35
|
const health = await client.health();
|
|
38
|
-
const result = await client.query(
|
|
36
|
+
const result = await client.query({
|
|
37
|
+
query: "Summarize the indexed knowledge base.",
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
console.log(health.status);
|
|
39
41
|
console.log(result.answer);
|
|
40
42
|
```
|
|
41
43
|
|
|
42
|
-
##
|
|
44
|
+
## Bootstrap A New API Key Scope
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { HivemindClient } from "@ai2aim.ai/hivemind-sdk";
|
|
48
|
+
|
|
49
|
+
const admin = new HivemindClient({
|
|
50
|
+
baseUrl: process.env.HIVEMIND_BASE_URL!,
|
|
51
|
+
adminKey: process.env.HIVEMIND_ADMIN_KEY!,
|
|
52
|
+
});
|
|
43
53
|
|
|
44
|
-
|
|
54
|
+
const issued = await admin.issueApiKey({
|
|
55
|
+
name: "Acme Marketing",
|
|
56
|
+
settings: { timezone: "UTC", brand_voice: "playful" },
|
|
57
|
+
});
|
|
45
58
|
|
|
46
|
-
|
|
47
|
-
|
|
59
|
+
console.log(issued.api_key);
|
|
60
|
+
console.log(issued.scope.name);
|
|
61
|
+
```
|
|
48
62
|
|
|
49
|
-
|
|
50
|
-
const apiKey = await getOrgApiKeyFromDb(orgId);
|
|
63
|
+
## Content Creator Example
|
|
51
64
|
|
|
52
|
-
|
|
65
|
+
```ts
|
|
66
|
+
const client = new HivemindClient({
|
|
67
|
+
baseUrl: process.env.HIVEMIND_BASE_URL!,
|
|
68
|
+
apiKey: process.env.HIVEMIND_API_KEY!,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const project = await client.createProject({
|
|
53
72
|
name: "Launch Campaign",
|
|
54
|
-
description: "Q4 rollout",
|
|
55
|
-
}
|
|
73
|
+
description: "Q4 rollout workspace",
|
|
74
|
+
});
|
|
56
75
|
|
|
57
|
-
const item = await client.createContentItem(
|
|
76
|
+
const item = await client.createContentItem(project.project_id, {
|
|
58
77
|
item_type: "article",
|
|
59
78
|
title: "Launch Post",
|
|
60
79
|
content: "We are launching this quarter.",
|
|
61
80
|
status: "ready",
|
|
62
|
-
}
|
|
81
|
+
});
|
|
63
82
|
|
|
64
|
-
const schedule = await client.createPublishSchedule(
|
|
83
|
+
const schedule = await client.createPublishSchedule(project.project_id, {
|
|
65
84
|
content_id: item.content_id,
|
|
66
85
|
target_platforms: ["linkedin", "x"],
|
|
67
86
|
publish_at: "2026-03-17T12:00:00Z",
|
|
68
|
-
}, { apiKey });
|
|
69
|
-
|
|
70
|
-
console.log(schedule.status); // "scheduled"
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
In normal deployments, the backend processes due schedules automatically with its background content schedule runner. The manual admin fallback is:
|
|
74
|
-
|
|
75
|
-
```typescript
|
|
76
|
-
const admin = new HivemindClient({
|
|
77
|
-
baseUrl: process.env.HIVEMIND_BASE_URL,
|
|
78
|
-
adminKey: process.env.HIVEMIND_ADMIN_KEY,
|
|
79
87
|
});
|
|
80
88
|
|
|
81
|
-
|
|
82
|
-
console.log(result.published);
|
|
89
|
+
console.log(schedule.status);
|
|
83
90
|
```
|
|
84
91
|
|
|
85
92
|
## Configuration
|
|
86
93
|
|
|
87
94
|
| Option | Required | Description |
|
|
88
95
|
|---|---|---|
|
|
89
|
-
| `baseUrl` | No* | API base URL
|
|
90
|
-
| `apiPrefix` | No | Path prefix
|
|
91
|
-
| `apiKey` | No |
|
|
92
|
-
| `adminKey` | No | Bootstrap admin key for admin
|
|
93
|
-
| `webhookSecret` | No | Secret for webhook
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
| `employeeId` | No | Employee ID header for RBAC |
|
|
97
|
-
| `timeoutMs` | No | Request timeout in ms (default 30 000) |
|
|
98
|
-
| `insecure` | No | Skip TLS verification for self-signed certs |
|
|
99
|
-
|
|
100
|
-
### API key from your database or cache
|
|
96
|
+
| `baseUrl` | No* | API base URL. Defaults to `HIVEMIND_BASE_URL` or `HIVEMIND_API_URL`. |
|
|
97
|
+
| `apiPrefix` | No | Path prefix. Defaults to `/v1`. |
|
|
98
|
+
| `apiKey` | No | Bearer API key for API-key-scoped routes. |
|
|
99
|
+
| `adminKey` | No | Bootstrap admin key for admin routes and `issueApiKey()`. |
|
|
100
|
+
| `webhookSecret` | No | Secret for webhook receiver routes. |
|
|
101
|
+
| `timeoutMs` | No | Request timeout in ms. Defaults to `30000`. |
|
|
102
|
+
| `insecure` | No | Reserved for self-signed TLS workflows. |
|
|
101
103
|
|
|
102
|
-
|
|
104
|
+
\* Required unless already present in env.
|
|
103
105
|
|
|
104
|
-
|
|
106
|
+
## Main Methods
|
|
105
107
|
|
|
106
|
-
|
|
107
|
-
import { HivemindClient } from "@hivemind/sdk";
|
|
108
|
+
### Core
|
|
108
109
|
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
```ts
|
|
111
|
+
client.root();
|
|
112
|
+
client.health();
|
|
113
|
+
client.adminLogin({ admin_key });
|
|
114
|
+
```
|
|
111
115
|
|
|
112
|
-
|
|
113
|
-
const apiKey = await getOrgApiKeyFromDb(orgId); // your function
|
|
116
|
+
### API key scope
|
|
114
117
|
|
|
115
|
-
|
|
118
|
+
```ts
|
|
119
|
+
client.issueApiKey({ name, settings });
|
|
120
|
+
client.getCurrentScope();
|
|
121
|
+
client.rotateApiKey();
|
|
116
122
|
```
|
|
117
123
|
|
|
118
|
-
|
|
124
|
+
### Documents and knowledge
|
|
119
125
|
|
|
120
|
-
|
|
126
|
+
```ts
|
|
127
|
+
client.uploadDocument(file, "handbook.pdf");
|
|
128
|
+
client.query({ query: "What is our refund policy?" });
|
|
129
|
+
client.search({ query: "best B2B onboarding examples", num: 5 });
|
|
130
|
+
client.getAuditLogs();
|
|
131
|
+
```
|
|
121
132
|
|
|
122
|
-
|
|
133
|
+
### Projects
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
client.createProject({ name, description });
|
|
137
|
+
client.listProjects();
|
|
138
|
+
client.getProject(projectId);
|
|
139
|
+
client.updateProject(projectId, { status: "archived" });
|
|
140
|
+
client.deleteProject(projectId);
|
|
141
|
+
|
|
142
|
+
client.chatProject(projectId, { message, user_id });
|
|
143
|
+
client.getProjectChatHistory(projectId, userId);
|
|
144
|
+
|
|
145
|
+
client.createContentItem(projectId, params);
|
|
146
|
+
client.listContentItems(projectId);
|
|
147
|
+
client.getContentItem(projectId, contentId);
|
|
148
|
+
client.updateContentItem(projectId, contentId, params);
|
|
149
|
+
client.deleteContentItem(projectId, contentId);
|
|
150
|
+
|
|
151
|
+
client.createProjectSource(projectId, params);
|
|
152
|
+
client.scrapeProjectSources(projectId, { urls });
|
|
153
|
+
client.listProjectSources(projectId);
|
|
154
|
+
client.getProjectSource(projectId, sourceId);
|
|
155
|
+
client.updateProjectSource(projectId, sourceId, params);
|
|
156
|
+
client.deleteProjectSource(projectId, sourceId);
|
|
157
|
+
|
|
158
|
+
client.createPublishSchedule(projectId, params);
|
|
159
|
+
client.listPublishSchedules(projectId);
|
|
160
|
+
client.getPublishSchedule(projectId, scheduleId);
|
|
161
|
+
client.updatePublishSchedule(projectId, scheduleId, params);
|
|
162
|
+
client.deletePublishSchedule(projectId, scheduleId);
|
|
163
|
+
```
|
|
123
164
|
|
|
124
|
-
|
|
125
|
-
|---|---|
|
|
126
|
-
| `HIVEMIND_BASE_URL` | API base URL (required) |
|
|
127
|
-
| `HIVEMIND_API_KEY` | Org API key (for org-scoped commands) |
|
|
128
|
-
| `HIVEMIND_ADMIN_KEY` | Admin key for org:create and schedule:run-due |
|
|
129
|
-
| `HIVEMIND_API_PREFIX` | Path prefix (default `/v1`) |
|
|
130
|
-
| `HIVEMIND_INSECURE` | Set to `true` to skip TLS verification |
|
|
131
|
-
| `HIVEMIND_TIMEOUT_MS` | Request timeout in ms |
|
|
165
|
+
### Generation and jobs
|
|
132
166
|
|
|
133
|
-
|
|
167
|
+
```ts
|
|
168
|
+
const job = await client.generateImage({ prompt: "Studio product photo" });
|
|
169
|
+
const status = await client.getJob(job.job_id);
|
|
170
|
+
const final = await client.waitForJob(job.job_id);
|
|
171
|
+
```
|
|
134
172
|
|
|
135
|
-
|
|
173
|
+
Also available:
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
client.generateVideo(params);
|
|
177
|
+
client.generateMusic(params);
|
|
178
|
+
client.dataChat(params);
|
|
179
|
+
client.createAgent(params);
|
|
180
|
+
client.queryAgent(params);
|
|
181
|
+
client.transcribeAudio(params);
|
|
182
|
+
client.synthesizeAudio(params);
|
|
183
|
+
client.trainModel(params);
|
|
184
|
+
client.predict(params);
|
|
185
|
+
client.forecast(params);
|
|
186
|
+
```
|
|
136
187
|
|
|
137
|
-
|
|
188
|
+
### Jira and blueprints
|
|
189
|
+
|
|
190
|
+
```ts
|
|
191
|
+
client.connectJira(params);
|
|
192
|
+
client.getJiraStatus();
|
|
193
|
+
client.syncJira(params);
|
|
194
|
+
client.disconnectJira();
|
|
195
|
+
|
|
196
|
+
client.createBlueprint(params);
|
|
197
|
+
client.listBlueprints();
|
|
198
|
+
client.getBlueprint(blueprintId);
|
|
199
|
+
client.updateBlueprint(blueprintId, params);
|
|
200
|
+
client.publishBlueprint(blueprintId);
|
|
201
|
+
client.archiveBlueprint(blueprintId);
|
|
202
|
+
client.deleteBlueprint(blueprintId);
|
|
203
|
+
|
|
204
|
+
client.createDocumentFromBlueprint(params);
|
|
205
|
+
client.listManagedDocuments();
|
|
206
|
+
client.getManagedDocument(documentId);
|
|
207
|
+
client.updateDocumentSection(documentId, params);
|
|
208
|
+
client.performDocumentWorkflow(documentId, params);
|
|
209
|
+
client.generateDocumentSection(documentId, params);
|
|
210
|
+
client.deleteManagedDocument(documentId);
|
|
211
|
+
```
|
|
138
212
|
|
|
139
|
-
|
|
140
|
-
const admin = new HivemindClient({
|
|
141
|
-
adminKey: "your-bootstrap-admin-key",
|
|
142
|
-
});
|
|
213
|
+
### Scraping
|
|
143
214
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
215
|
+
```ts
|
|
216
|
+
client.getScrapingConfig();
|
|
217
|
+
client.scrape({ urls: ["https://example.com"] });
|
|
218
|
+
client.getScrapeStatus(taskId);
|
|
219
|
+
client.scrapeAndWait(["https://example.com"]);
|
|
220
|
+
```
|
|
150
221
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
222
|
+
### Admin
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
client.getAdminConfig();
|
|
226
|
+
client.getAdminConfigOverrides();
|
|
227
|
+
client.updateAdminSetting({ key, value });
|
|
228
|
+
client.getLogLevel();
|
|
229
|
+
client.setLogLevel({ level: "DEBUG" });
|
|
230
|
+
client.getLoggers();
|
|
231
|
+
client.getInboundTraffic();
|
|
232
|
+
client.resetInboundTraffic();
|
|
233
|
+
client.getOutboundStatus();
|
|
234
|
+
client.getCors();
|
|
235
|
+
client.setCors("*");
|
|
236
|
+
client.getRateLimits();
|
|
237
|
+
client.resetRateLimit(scopeId);
|
|
238
|
+
client.listJobs();
|
|
239
|
+
client.getFeatureFlags();
|
|
240
|
+
client.getFeatureFlag(key);
|
|
241
|
+
client.setFeatureFlag({ key, enabled: true });
|
|
242
|
+
client.deleteFeatureFlag(key);
|
|
243
|
+
client.getMaintenanceMode();
|
|
244
|
+
client.setMaintenanceMode({ enabled: true, message: "Maintenance" });
|
|
245
|
+
client.getCacheStats();
|
|
246
|
+
client.flushCache();
|
|
247
|
+
client.getAdminAudit();
|
|
248
|
+
client.getSystemInfo();
|
|
249
|
+
client.runDueSchedules();
|
|
156
250
|
```
|
|
157
251
|
|
|
158
252
|
## CLI
|
|
159
253
|
|
|
160
|
-
After
|
|
254
|
+
After building, the `hivemind` binary is available.
|
|
161
255
|
|
|
162
256
|
### Commands
|
|
163
257
|
|
|
164
|
-
| Command | Description |
|
|
165
|
-
|---|---|
|
|
166
|
-
| `hivemind init` | Create `.hivemindrc.json` and `.env.example` in the current directory |
|
|
167
|
-
| `hivemind config` | Print resolved config (secrets masked) |
|
|
168
|
-
| `hivemind health` | Call the API health endpoint |
|
|
169
|
-
| `hivemind helper validate` | Validate config and test connection |
|
|
170
|
-
| `hivemind helper env` | Print env var template for copy-paste |
|
|
171
|
-
| `hivemind query <org_id> <question>` | Run a RAG query (needs API key) |
|
|
172
|
-
| `hivemind search <org_id> <query>` | Run source discovery search (needs API key) |
|
|
173
|
-
| `hivemind org:create <org_id> <name>` | Create an organization (needs admin key) |
|
|
174
|
-
| `hivemind music <org_id> <genre> <mood>` | Start music generation (needs API key) |
|
|
175
|
-
| `hivemind scrape <url...>` | Submit URLs to scrape |
|
|
176
|
-
| `hivemind scrape:status <task_id>` | Get scrape task status and result |
|
|
177
|
-
| `hivemind schedule:run-due` | Manually process due Content Creator schedules (needs admin key) |
|
|
178
|
-
|
|
179
|
-
### Examples
|
|
180
|
-
|
|
181
258
|
```bash
|
|
182
|
-
# Initialize config in current directory
|
|
183
259
|
hivemind init
|
|
184
|
-
|
|
185
|
-
# Only create .env.example
|
|
186
|
-
hivemind init --env-only
|
|
187
|
-
|
|
188
|
-
# Check connection
|
|
189
|
-
export HIVEMIND_BASE_URL=https://your-api.com
|
|
260
|
+
hivemind config
|
|
190
261
|
hivemind health
|
|
191
|
-
|
|
192
|
-
# Validate config and ping API
|
|
193
262
|
hivemind helper validate
|
|
194
|
-
|
|
195
|
-
# Print env template
|
|
196
263
|
hivemind helper env
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
hivemind
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
hivemind
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
hivemind org:create acme "Acme Corp" --tier premium
|
|
206
|
-
|
|
207
|
-
# Generate music and wait for completion
|
|
208
|
-
hivemind music my-org ambient uplifting --duration 30 --wait
|
|
209
|
-
|
|
210
|
-
# Scrape URLs and wait for results
|
|
211
|
-
hivemind scrape https://example.com https://example.org --wait
|
|
212
|
-
|
|
213
|
-
# Manually run due Content Creator schedules
|
|
264
|
+
hivemind query "What is our refund policy?"
|
|
265
|
+
hivemind search "content marketing trends 2026"
|
|
266
|
+
hivemind api-key:issue "Acme Marketing"
|
|
267
|
+
hivemind api-key:scope
|
|
268
|
+
hivemind api-key:rotate
|
|
269
|
+
hivemind music ambient uplifting --wait
|
|
270
|
+
hivemind scrape https://example.com --wait
|
|
271
|
+
hivemind scrape:status <task_id>
|
|
214
272
|
hivemind schedule:run-due
|
|
273
|
+
hivemind start-web
|
|
215
274
|
```
|
|
216
275
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
- **`-d, --dir <path>`** (for init, config, health, helper, query, search, org:create, music, scrape, schedule:run-due): Directory to use for `.hivemindrc.json` (default: current directory).
|
|
220
|
-
- **`-u, --url <url>`** (health): Override base URL for a one-off health check.
|
|
221
|
-
- **`--skip-ping`** (helper validate): Validate config only, do not call the API.
|
|
222
|
-
|
|
223
|
-
### Search, music, and schedules
|
|
224
|
-
|
|
225
|
-
```typescript
|
|
226
|
-
const search = await client.search("my-org", {
|
|
227
|
-
query: "best B2B content strategy",
|
|
228
|
-
type: "news",
|
|
229
|
-
num: 10,
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
const musicJob = await client.generateMusic("my-org", {
|
|
233
|
-
genre: "ambient",
|
|
234
|
-
mood: "uplifting",
|
|
235
|
-
duration: 30,
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
const music = await client.waitForJob("my-org", musicJob.job_id);
|
|
239
|
-
|
|
240
|
-
const schedules = await client.listPublishSchedules("my-org", "proj_123", { apiKey });
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
## All methods
|
|
276
|
+
## Streaming
|
|
244
277
|
|
|
245
|
-
|
|
278
|
+
### SSE
|
|
246
279
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
{ "success": true, "statusCode": 200, "data": { ... }, "message": "Request successful" }
|
|
256
|
-
```
|
|
257
|
-
The SDK returns the **`data`** payload directly (unwrapped).
|
|
258
|
-
|
|
259
|
-
### Health
|
|
260
|
-
|
|
261
|
-
| Method | Auth | Description |
|
|
262
|
-
|---|---|---|
|
|
263
|
-
| `health()` | None | Service health check |
|
|
264
|
-
|
|
265
|
-
**Returns** `HealthResponse`:
|
|
266
|
-
|
|
267
|
-
| Field | Type | Description |
|
|
268
|
-
|-----------|--------|-------------------------------------------------------|
|
|
269
|
-
| `service` | string | Service name |
|
|
270
|
-
| `version` | string | Service version |
|
|
271
|
-
| `status` | string | Health status (`"ok"`) |
|
|
272
|
-
| `stats` | object | `{ organizations, documents, total_chunks }` |
|
|
273
|
-
|
|
274
|
-
### Admin auth
|
|
275
|
-
|
|
276
|
-
| Method | Auth | Description |
|
|
277
|
-
|---|---|---|
|
|
278
|
-
| `adminLogin({ admin_key })` | None | Exchange admin key for a signed session token |
|
|
279
|
-
|
|
280
|
-
**Parameters** (`AdminLoginParams`):
|
|
281
|
-
|
|
282
|
-
| Field | Type | Required | Description |
|
|
283
|
-
|-------------|--------|----------|----------------------------|
|
|
284
|
-
| `admin_key` | string | Yes | The bootstrap admin key |
|
|
285
|
-
|
|
286
|
-
**Returns** `AdminLoginResponse`:
|
|
287
|
-
|
|
288
|
-
| Field | Type | Description |
|
|
289
|
-
|----------------------|--------|------------------------------------------|
|
|
290
|
-
| `access_token` | string | Signed JWT session token |
|
|
291
|
-
| `token_type` | string | Always `"bearer"` |
|
|
292
|
-
| `expires_in_seconds` | number | Token validity (default 28800 = 8 hours) |
|
|
293
|
-
|
|
294
|
-
```typescript
|
|
295
|
-
const { access_token } = await client.adminLogin({ admin_key: "your-admin-key" });
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
### Organizations
|
|
299
|
-
|
|
300
|
-
| Method | Auth | Description |
|
|
301
|
-
|---|---|---|
|
|
302
|
-
| `createOrganization(params, options?)` | Admin | Create org idempotently; returns existing org instead of throwing on duplicates |
|
|
303
|
-
| `ensureOrganization(params)` | Admin | Create org if missing, or return existing org without throwing |
|
|
304
|
-
| `getAdminOrganization(orgId)` | Admin | Get org details with admin credentials |
|
|
305
|
-
| `getOrganization(orgId, options?)` | API Key | Get org details |
|
|
306
|
-
| `rotateApiKey(orgId, options?)` | Admin | Rotate org API key (24h grace period for old key) |
|
|
307
|
-
| `suspendOrganization(orgId, options?)` | Admin | Suspend an org (blocks API access) |
|
|
308
|
-
| `reactivateOrganization(orgId, options?)` | Admin | Reactivate a suspended org |
|
|
309
|
-
| `deleteOrganization(orgId, options?)` | Admin | Permanently delete an org (irreversible) |
|
|
310
|
-
|
|
311
|
-
**`createOrganization` parameters** (`OrgCreateParams`):
|
|
312
|
-
|
|
313
|
-
| Field | Type | Required | Default | Description |
|
|
314
|
-
|------------|--------|----------|--------------|------------------------------------------------|
|
|
315
|
-
| `org_id` | string | Yes | — | Unique org identifier (2–64 chars) |
|
|
316
|
-
| `name` | string | Yes | — | Display name (2–128 chars) |
|
|
317
|
-
| `tier` | string | No | `"standard"` | `"free"`, `"standard"`, `"premium"`, `"enterprise"` |
|
|
318
|
-
| `settings` | object | No | `{}` | Custom org settings |
|
|
319
|
-
|
|
320
|
-
**Returns** `OrgEnsureResponse` by default:
|
|
321
|
-
|
|
322
|
-
| Field | Type | Description |
|
|
323
|
-
|----------------|----------------------|-----------------------------------------------|
|
|
324
|
-
| `created` | `true \| false` | Whether this call created the org |
|
|
325
|
-
| `organization` | Organization | Full organization entity |
|
|
326
|
-
| `api_key` | `string \| null` | Generated API key, or `null` if org existed |
|
|
327
|
-
|
|
328
|
-
```typescript
|
|
329
|
-
const ensured = await admin.createOrganization({
|
|
330
|
-
org_id: "acme-corp",
|
|
331
|
-
name: "Acme Corporation",
|
|
332
|
-
tier: "premium",
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
if (ensured.created) {
|
|
336
|
-
console.log("New API key:", ensured.api_key);
|
|
337
|
-
} else {
|
|
338
|
-
console.log("Organization already existed:", ensured.organization.org_id);
|
|
280
|
+
```ts
|
|
281
|
+
for await (const evt of client.chatProjectSse("proj_123", {
|
|
282
|
+
message: "Summarize our saved sources.",
|
|
283
|
+
user_id: "sdk-user",
|
|
284
|
+
})) {
|
|
285
|
+
if (evt.event === "done") {
|
|
286
|
+
console.log(evt.data.answer);
|
|
287
|
+
}
|
|
339
288
|
}
|
|
340
289
|
```
|
|
341
290
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
```typescript
|
|
345
|
-
const created = await admin.createOrganization(
|
|
346
|
-
{
|
|
347
|
-
org_id: "acme-corp",
|
|
348
|
-
name: "Acme Corporation",
|
|
349
|
-
tier: "premium",
|
|
350
|
-
},
|
|
351
|
-
{ allowExisting: false },
|
|
352
|
-
);
|
|
353
|
-
console.log("New API key:", created.api_key);
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
### Documents
|
|
291
|
+
### WebSocket
|
|
357
292
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
| `uploadDocument(orgId, file, filename, options?)` | API Key | Upload a document (Buffer or Blob) |
|
|
361
|
-
|
|
362
|
-
**Parameters:**
|
|
363
|
-
|
|
364
|
-
| Param | Type | Required | Description |
|
|
365
|
-
|------------|----------------|----------|---------------------------------------|
|
|
366
|
-
| `orgId` | string | Yes | Organization identifier |
|
|
367
|
-
| `file` | Blob \| Buffer | Yes | Document content |
|
|
368
|
-
| `filename` | string | Yes | Original filename (e.g. `"report.pdf"`) |
|
|
369
|
-
|
|
370
|
-
**Returns** `DocumentUploadResponse`:
|
|
371
|
-
|
|
372
|
-
| Field | Type | Description |
|
|
373
|
-
|---------------|--------|-------------------------------------------|
|
|
374
|
-
| `document_id` | string | Unique document identifier |
|
|
375
|
-
| `org_id` | string | Organization ID |
|
|
376
|
-
| `filename` | string | Original filename |
|
|
377
|
-
| `chunks` | number | Number of text chunks created |
|
|
378
|
-
| `status` | string | Processing status (e.g. `"processed"`) |
|
|
379
|
-
|
|
380
|
-
```typescript
|
|
381
|
-
import { readFileSync } from "fs";
|
|
382
|
-
const file = readFileSync("./report.pdf");
|
|
383
|
-
const result = await client.uploadDocument("acme-corp", file, "report.pdf");
|
|
384
|
-
console.log(`${result.chunks} chunks created`);
|
|
385
|
-
```
|
|
293
|
+
```ts
|
|
294
|
+
const ws = await client.chatProjectWebSocket("proj_123");
|
|
386
295
|
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|---|---|---|
|
|
391
|
-
| `query(orgId, params, options?)` | API Key | RAG query with retrieval and generation |
|
|
392
|
-
|
|
393
|
-
**Parameters** (`QueryParams`):
|
|
394
|
-
|
|
395
|
-
| Field | Type | Required | Default | Description |
|
|
396
|
-
|----------------------|--------|----------|--------------|-------------------------------------------|
|
|
397
|
-
| `query` | string | Yes | — | Query text |
|
|
398
|
-
| `user_id` | string | No | `null` | User identifier for tracking |
|
|
399
|
-
| `model_type` | string | No | `"gemini-pro"` | Gemini model for generation |
|
|
400
|
-
| `temperature` | number | No | `0.2` | Sampling temperature (0.0–1.0) |
|
|
401
|
-
| `retrieval_strategy` | string | No | `"hybrid"` | `"hybrid"`, `"dense"`, or `"sparse"` |
|
|
402
|
-
|
|
403
|
-
**Returns** `QueryResponse`:
|
|
404
|
-
|
|
405
|
-
| Field | Type | Description |
|
|
406
|
-
|--------------|----------|-------------------------------------------------|
|
|
407
|
-
| `answer` | string | Generated answer text |
|
|
408
|
-
| `sources` | object[] | Source citations (doc_id, chunk_id, score, snippet) |
|
|
409
|
-
| `model_type` | string | Model used |
|
|
410
|
-
|
|
411
|
-
```typescript
|
|
412
|
-
const result = await client.query("acme-corp", {
|
|
413
|
-
query: "What are the key findings in Q4?",
|
|
414
|
-
temperature: 0.2,
|
|
415
|
-
});
|
|
416
|
-
console.log(result.answer);
|
|
417
|
-
result.sources.forEach(s => console.log(s.doc_id, s.score));
|
|
418
|
-
```
|
|
419
|
-
|
|
420
|
-
### Generation
|
|
421
|
-
|
|
422
|
-
| Method | Auth | Description |
|
|
423
|
-
|---|---|---|
|
|
424
|
-
| `generateVideo(orgId, params, options?)` | API Key | Start async video generation (Vertex AI Veo) |
|
|
425
|
-
| `generateImage(orgId, params, options?)` | API Key | Start async image generation (Vertex AI Imagen) |
|
|
426
|
-
|
|
427
|
-
**`generateVideo` parameters** (`GenerateVideoParams`):
|
|
428
|
-
|
|
429
|
-
| Field | Type | Required | Default | Description |
|
|
430
|
-
|----------------|--------|----------|----------|------------------------------------|
|
|
431
|
-
| `prompt` | string | Yes | — | Video generation prompt |
|
|
432
|
-
| `duration` | number | No | `8` | Duration: `4`, `6`, or `8` seconds |
|
|
433
|
-
| `aspect_ratio` | string | No | `"16:9"` | Aspect ratio |
|
|
434
|
-
| `style` | string | No | `null` | Visual style hint |
|
|
435
|
-
| `user_id` | string | No | `null` | User identifier |
|
|
436
|
-
|
|
437
|
-
**`generateImage` parameters** (`GenerateImageParams`):
|
|
438
|
-
|
|
439
|
-
| Field | Type | Required | Default | Description |
|
|
440
|
-
|----------------|--------|----------|---------|-------------------------------|
|
|
441
|
-
| `prompt` | string | Yes | — | Image generation prompt |
|
|
442
|
-
| `aspect_ratio` | string | No | `"1:1"` | Aspect ratio |
|
|
443
|
-
| `style` | string | No | `null` | Visual style hint |
|
|
444
|
-
| `num_images` | number | No | `1` | Number of images (1–8) |
|
|
445
|
-
| `user_id` | string | No | `null` | User identifier |
|
|
446
|
-
|
|
447
|
-
**Both return** `JobAcceptedResponse` (HTTP 202):
|
|
448
|
-
|
|
449
|
-
| Field | Type | Description |
|
|
450
|
-
|------------------|--------|-----------------------------------------------|
|
|
451
|
-
| `job_id` | string | Job ID — use with `getJob()` / `waitForJob()` |
|
|
452
|
-
| `status` | string | Always `"processing"` |
|
|
453
|
-
| `estimated_time` | number | Estimated processing time in seconds |
|
|
454
|
-
|
|
455
|
-
```typescript
|
|
456
|
-
const job = await client.generateVideo("acme-corp", {
|
|
457
|
-
prompt: "A drone flyover of a mountain lake at sunset",
|
|
458
|
-
duration: 8,
|
|
459
|
-
style: "cinematic",
|
|
460
|
-
});
|
|
461
|
-
const result = await client.waitForJob("acme-corp", job.job_id);
|
|
462
|
-
console.log(result.result); // { output_url, signed_url }
|
|
463
|
-
```
|
|
464
|
-
|
|
465
|
-
### Jobs
|
|
466
|
-
|
|
467
|
-
| Method | Auth | Description |
|
|
468
|
-
|---|---|---|
|
|
469
|
-
| `getJob(orgId, jobId, options?)` | API Key | Get job status |
|
|
470
|
-
| `waitForJob(orgId, jobId, intervalMs?, maxWaitMs?, options?)` | API Key | Poll until job reaches terminal status |
|
|
471
|
-
|
|
472
|
-
**Returns** `JobStatusResponse`:
|
|
473
|
-
|
|
474
|
-
| Field | Type | Description |
|
|
475
|
-
|----------|----------------|------------------------------------------------------|
|
|
476
|
-
| `job_id` | string | Job identifier |
|
|
477
|
-
| `status` | string | `"processing"`, `"completed"`, `"failed"`, `"cancelled"` |
|
|
478
|
-
| `result` | object \| null | Result payload when completed (e.g. `{ output_url, signed_url }`) |
|
|
479
|
-
| `error` | string \| null | Error message if failed |
|
|
480
|
-
|
|
481
|
-
**`waitForJob` parameters:**
|
|
482
|
-
|
|
483
|
-
| Param | Type | Default | Description |
|
|
484
|
-
|--------------|--------|-----------|-----------------------------|
|
|
485
|
-
| `intervalMs` | number | `2000` | Polling interval (ms) |
|
|
486
|
-
| `maxWaitMs` | number | `300000` | Maximum wait time (ms) |
|
|
487
|
-
|
|
488
|
-
### Data chat
|
|
489
|
-
|
|
490
|
-
| Method | Auth | Description |
|
|
491
|
-
|---|---|---|
|
|
492
|
-
| `dataChat(orgId, params, options?)` | API Key | Natural-language questions over BigQuery |
|
|
493
|
-
|
|
494
|
-
**Parameters** (`DataChatParams`):
|
|
495
|
-
|
|
496
|
-
| Field | Type | Required | Description |
|
|
497
|
-
|------------|--------|----------|--------------------------------|
|
|
498
|
-
| `question` | string | Yes | Natural-language question |
|
|
499
|
-
| `user_id` | string | No | User identifier for tracking |
|
|
500
|
-
|
|
501
|
-
**Returns** `DataChatResponse`:
|
|
502
|
-
|
|
503
|
-
| Field | Type | Description |
|
|
504
|
-
|----------|----------|------------------------------------|
|
|
505
|
-
| `answer` | string | Natural-language answer |
|
|
506
|
-
| `sql` | string | Generated SQL query |
|
|
507
|
-
| `rows` | object[] | Result rows from BigQuery |
|
|
508
|
-
|
|
509
|
-
```typescript
|
|
510
|
-
const result = await client.dataChat("acme-corp", {
|
|
511
|
-
question: "How many active users this month?",
|
|
512
|
-
});
|
|
513
|
-
console.log(result.answer); // "There are 1,247 active users."
|
|
514
|
-
console.log(result.sql); // "SELECT COUNT(DISTINCT user_id) FROM ..."
|
|
515
|
-
```
|
|
516
|
-
|
|
517
|
-
### Agents
|
|
518
|
-
|
|
519
|
-
| Method | Auth | Description |
|
|
520
|
-
|---|---|---|
|
|
521
|
-
| `createAgent(orgId, params, options?)` | API Key | Create a custom AI agent template |
|
|
522
|
-
| `queryAgent(orgId, params, options?)` | API Key | Query an AI agent |
|
|
523
|
-
|
|
524
|
-
**`createAgent` parameters** (`AgentCreateParams`):
|
|
525
|
-
|
|
526
|
-
| Field | Type | Required | Default | Description |
|
|
527
|
-
|----------------|----------|----------|---------|---------------------------------|
|
|
528
|
-
| `name` | string | Yes | — | Agent name (2–64 chars) |
|
|
529
|
-
| `instructions` | string | Yes | — | System instructions (min 4 chars) |
|
|
530
|
-
| `tools` | string[] | No | `[]` | Tool identifiers to enable |
|
|
531
|
-
|
|
532
|
-
**`queryAgent` parameters** (`AgentQueryParams`):
|
|
533
|
-
|
|
534
|
-
| Field | Type | Required | Default | Description |
|
|
535
|
-
|--------------|--------|----------|----------|--------------------------|
|
|
536
|
-
| `query` | string | Yes | — | User query |
|
|
537
|
-
| `user_id` | string | Yes | — | User identifier |
|
|
538
|
-
| `agent_type` | string | No | `"auto"` | Agent type to route to |
|
|
539
|
-
|
|
540
|
-
### Audio
|
|
541
|
-
|
|
542
|
-
| Method | Auth | Description |
|
|
543
|
-
|---|---|---|
|
|
544
|
-
| `transcribeAudio(orgId, params, options?)` | API Key | Speech-to-text transcription |
|
|
545
|
-
| `synthesizeAudio(orgId, params, options?)` | API Key | Text-to-speech synthesis |
|
|
546
|
-
|
|
547
|
-
**`transcribeAudio` parameters** (`AudioTranscribeParams`):
|
|
548
|
-
|
|
549
|
-
| Field | Type | Required | Default | Description |
|
|
550
|
-
|-----------------|--------|----------|------------|---------------------------|
|
|
551
|
-
| `audio_text` | string | No | — | Legacy text fallback |
|
|
552
|
-
| `audio_url` | string | No | — | Audio URL for Scribe |
|
|
553
|
-
| `language_code` | string | No | `"en-US"` | BCP-47 language code |
|
|
554
|
-
| `model_id` | string | No | `"scribe_v2"` | STT model override |
|
|
555
|
-
|
|
556
|
-
**`synthesizeAudio` parameters** (`AudioSynthesizeParams`):
|
|
557
|
-
|
|
558
|
-
| Field | Type | Required | Default | Description |
|
|
559
|
-
|------------------|--------|----------|----------------------|--------------------------------|
|
|
560
|
-
| `text` | string | Yes | — | Text to synthesize |
|
|
561
|
-
| `voice_name` | string | No | `"en-US-Neural2-J"` | Voice identifier / voice ID |
|
|
562
|
-
| `model_id` | string | No | backend default | ElevenLabs TTS model override |
|
|
563
|
-
| `output_format` | string | No | backend default | Output format override |
|
|
564
|
-
| `language_code` | string | No | — | ISO 639-1 language code |
|
|
565
|
-
| `seed` | number | No | — | Deterministic synthesis seed |
|
|
566
|
-
| `voice_settings` | object | No | backend default | Per-request voice settings |
|
|
567
|
-
|
|
568
|
-
### Analytics / ML
|
|
569
|
-
|
|
570
|
-
| Method | Auth | Description |
|
|
571
|
-
|---|---|---|
|
|
572
|
-
| `trainModel(orgId, params, options?)` | API Key | Train a predictive model on tabular data |
|
|
573
|
-
| `predict(orgId, params, options?)` | API Key | Run predictions with a trained model |
|
|
574
|
-
| `forecast(orgId, params, options?)` | API Key | Time-series forecast (ARIMA-based) |
|
|
575
|
-
|
|
576
|
-
**`trainModel` parameters** (`TrainModelParams`):
|
|
577
|
-
|
|
578
|
-
| Field | Type | Required | Description |
|
|
579
|
-
|-------------------|----------|----------|-----------------------------|
|
|
580
|
-
| `target_column` | string | Yes | Column to predict |
|
|
581
|
-
| `feature_columns` | string[] | Yes | Feature column names |
|
|
582
|
-
| `rows` | object[] | Yes | Training data rows |
|
|
583
|
-
|
|
584
|
-
**`predict` parameters** (`PredictParams`):
|
|
585
|
-
|
|
586
|
-
| Field | Type | Required | Description |
|
|
587
|
-
|-------------|----------|----------|------------------------------|
|
|
588
|
-
| `model_id` | string | Yes | Trained model ID |
|
|
589
|
-
| `instances` | object[] | Yes | Data instances to predict on |
|
|
590
|
-
|
|
591
|
-
**`forecast` parameters** (`ForecastParams`):
|
|
592
|
-
|
|
593
|
-
| Field | Type | Required | Default | Description |
|
|
594
|
-
|-----------|----------|----------|---------|--------------------------------|
|
|
595
|
-
| `series` | number[] | Yes | — | Historical time-series values |
|
|
596
|
-
| `horizon` | number | No | `30` | Forecast horizon (1–365) |
|
|
597
|
-
|
|
598
|
-
```typescript
|
|
599
|
-
// Train
|
|
600
|
-
const model = await client.trainModel("acme-corp", {
|
|
601
|
-
target_column: "churn",
|
|
602
|
-
feature_columns: ["tenure", "monthly_charges"],
|
|
603
|
-
rows: [{ tenure: 12, monthly_charges: 50, churn: 0 }],
|
|
604
|
-
});
|
|
605
|
-
|
|
606
|
-
// Predict
|
|
607
|
-
const { predictions } = await client.predict("acme-corp", {
|
|
608
|
-
model_id: model.model_id,
|
|
609
|
-
instances: [{ tenure: 6, monthly_charges: 65 }],
|
|
296
|
+
const frame = await ws.chat({
|
|
297
|
+
message: "What are our strongest sources?",
|
|
298
|
+
user_id: "sdk-user",
|
|
610
299
|
});
|
|
611
|
-
```
|
|
612
|
-
|
|
613
|
-
### Billing
|
|
614
|
-
|
|
615
|
-
| Method | Auth | Description |
|
|
616
|
-
|---|---|---|
|
|
617
|
-
| `getUsage(orgId, month?, options?)` | API Key | Monthly usage summary with tier limits |
|
|
618
|
-
| `getInvoice(orgId, month?, options?)` | API Key | Monthly invoice with cost breakdown |
|
|
619
|
-
|
|
620
|
-
**Optional `month` parameter:** `YYYY-MM` format. Defaults to current month.
|
|
621
|
-
|
|
622
|
-
**`getUsage` returns** `UsageSummaryResponse`:
|
|
623
|
-
|
|
624
|
-
| Field | Type | Description |
|
|
625
|
-
|-------------------|----------|------------------------------------------------|
|
|
626
|
-
| `org_id` | string | Organization ID |
|
|
627
|
-
| `month` | string | Month (`YYYY-MM`) |
|
|
628
|
-
| `usage` | object | `{ tokens_used, images_generated, videos_generated, storage_bytes, compute_hours }` |
|
|
629
|
-
| `limits` | object | Tier limits |
|
|
630
|
-
| `within_quota` | boolean | Whether all metrics are within quota |
|
|
631
|
-
| `exceeded_limits` | string[] | List of exceeded metric names |
|
|
632
|
-
|
|
633
|
-
**`getInvoice` returns** `InvoiceResponse`:
|
|
634
300
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
| `org_id` | string | Organization ID |
|
|
638
|
-
| `month` | string | Month (`YYYY-MM`) |
|
|
639
|
-
| `total` | number | Total cost in USD |
|
|
640
|
-
| `line_items` | object[] | Itemized costs per resource type |
|
|
641
|
-
|
|
642
|
-
### Audit
|
|
643
|
-
|
|
644
|
-
| Method | Auth | Description |
|
|
645
|
-
|---|---|---|
|
|
646
|
-
| `getAuditLogs(orgId, options?)` | API Key | List audit log records |
|
|
647
|
-
|
|
648
|
-
**Returns** `AuditLogResponse`:
|
|
649
|
-
|
|
650
|
-
| Field | Type | Description |
|
|
651
|
-
|-----------|----------------|--------------------|
|
|
652
|
-
| `org_id` | string | Organization ID |
|
|
653
|
-
| `records` | AuditRecord[] | Audit log entries |
|
|
654
|
-
|
|
655
|
-
Each `AuditRecord`:
|
|
656
|
-
|
|
657
|
-
| Field | Type | Description |
|
|
658
|
-
|------------|----------------|-----------------------------------------|
|
|
659
|
-
| `timestamp`| string | ISO 8601 timestamp |
|
|
660
|
-
| `action` | string | Action (e.g. `"query.execute"`) |
|
|
661
|
-
| `resource` | string | Resource path |
|
|
662
|
-
| `status` | string | `"success"` or `"failure"` |
|
|
663
|
-
| `user_id` | string \| null | User who performed the action |
|
|
664
|
-
| `metadata` | object | Additional context |
|
|
665
|
-
|
|
666
|
-
### Scraping
|
|
667
|
-
|
|
668
|
-
| Method | Auth | Description |
|
|
669
|
-
|---|---|---|
|
|
670
|
-
| `getScrapingConfig()` | None | Runtime scraping configuration |
|
|
671
|
-
| `scrape({ urls })` | None | Submit URLs for scraping |
|
|
672
|
-
| `getScrapeStatus(taskId)` | None | Check scrape task status and results |
|
|
673
|
-
| `scrapeAndWait(urls, intervalMs?, maxWaitMs?)` | None | Submit + poll until results are ready |
|
|
674
|
-
|
|
675
|
-
**`scrape` parameters** (`ScrapeParams`):
|
|
676
|
-
|
|
677
|
-
| Field | Type | Required | Description |
|
|
678
|
-
|--------|----------|----------|---------------------------------|
|
|
679
|
-
| `urls` | string[] | Yes | URLs to scrape |
|
|
680
|
-
|
|
681
|
-
**`getScrapeStatus` returns** `ScrapeStatusResponse`:
|
|
682
|
-
|
|
683
|
-
| Field | Type | Description |
|
|
684
|
-
|-----------|-------------------|----------------------------------------------------|
|
|
685
|
-
| `task_id` | string | Task identifier |
|
|
686
|
-
| `status` | string | `"PENDING"`, `"SUCCESS"`, `"FAILURE"`, `"completed"` |
|
|
687
|
-
| `result` | ScrapeResultItem[] | Scraped results (each with url, title, full_text) |
|
|
688
|
-
|
|
689
|
-
```typescript
|
|
690
|
-
const result = await client.scrapeAndWait(["https://example.com"]);
|
|
691
|
-
for (const page of result.result) {
|
|
692
|
-
console.log(page.title, page.full_text?.substring(0, 200));
|
|
301
|
+
if (frame.type === "result") {
|
|
302
|
+
console.log(frame.payload.answer);
|
|
693
303
|
}
|
|
694
|
-
```
|
|
695
304
|
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
| Method | Auth | Description |
|
|
699
|
-
|---|---|---|
|
|
700
|
-
| `sendVideoCompleteWebhook(payload)` | Webhook | Send video completion notification |
|
|
701
|
-
| `sendDocumentProcessedWebhook(payload)` | Webhook | Send document processing notification |
|
|
702
|
-
|
|
703
|
-
**`VideoCompleteWebhook` payload:**
|
|
704
|
-
|
|
705
|
-
| Field | Type | Required | Description |
|
|
706
|
-
|------------|--------|----------|-------------------------------------|
|
|
707
|
-
| `job_id` | string | Yes | Job identifier |
|
|
708
|
-
| `org_id` | string | Yes | Organization identifier |
|
|
709
|
-
| `status` | string | Yes | Completion status |
|
|
710
|
-
| `metadata` | object | No | Additional data (e.g. `{ output_uri }`) |
|
|
305
|
+
ws.close();
|
|
306
|
+
```
|
|
711
307
|
|
|
712
|
-
|
|
308
|
+
## Dashboard
|
|
713
309
|
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
310
|
+
`hivemind start-web` launches a local browser dashboard with:
|
|
311
|
+
- connection settings
|
|
312
|
+
- API key issuance and rotation
|
|
313
|
+
- query and search
|
|
314
|
+
- document upload
|
|
315
|
+
- project creation and chat
|
|
316
|
+
- generation jobs
|
|
317
|
+
- scraping
|
|
318
|
+
- manual request runner
|
|
720
319
|
|
|
721
|
-
## Error
|
|
320
|
+
## Error Handling
|
|
722
321
|
|
|
723
|
-
All API
|
|
322
|
+
All API failures throw `HivemindError`.
|
|
724
323
|
|
|
725
|
-
```
|
|
726
|
-
import { HivemindClient, HivemindError } from "@hivemind
|
|
324
|
+
```ts
|
|
325
|
+
import { HivemindClient, HivemindError } from "@ai2aim.ai/hivemind-sdk";
|
|
727
326
|
|
|
728
327
|
try {
|
|
729
|
-
await client.query(
|
|
328
|
+
await client.query({ query: "hello" });
|
|
730
329
|
} catch (err) {
|
|
731
330
|
if (err instanceof HivemindError) {
|
|
732
331
|
console.error(err.statusCode, err.detail);
|
|
733
332
|
}
|
|
734
333
|
}
|
|
735
334
|
```
|
|
736
|
-
|
|
737
|
-
`createOrganization(params)` and `ensureOrganization(params)` are idempotent for
|
|
738
|
-
duplicate organizations by default. Pass `createOrganization(params, { allowExisting: false })`
|
|
739
|
-
if you want duplicate-org responses to throw `HivemindError`.
|
|
740
|
-
|
|
741
|
-
## Vercel / Next.js example
|
|
742
|
-
|
|
743
|
-
```typescript
|
|
744
|
-
// app/api/query/route.ts (Next.js App Router)
|
|
745
|
-
import { HivemindClient } from "@hivemind/sdk";
|
|
746
|
-
import { NextResponse } from "next/server";
|
|
747
|
-
|
|
748
|
-
// With HIVEMIND_API_URL set in env
|
|
749
|
-
const client = new HivemindClient({
|
|
750
|
-
apiKey: process.env.HIVEMIND_API_KEY!,
|
|
751
|
-
});
|
|
752
|
-
|
|
753
|
-
export async function POST(req: Request) {
|
|
754
|
-
const { query } = await req.json();
|
|
755
|
-
const result = await client.query("my-org", { query });
|
|
756
|
-
return NextResponse.json(result);
|
|
757
|
-
}
|
|
758
|
-
```
|