@ai2aim.ai/hivemind-sdk 1.0.15 → 3.1.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 +175 -803
- 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 +191 -204
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts +52 -1166
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +260 -1598
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +139 -833
- 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 +714 -1119
- package/dist/web.js.map +1 -1
- package/package.json +1 -1
- package/dist/ws.d.ts +0 -33
- package/dist/ws.d.ts.map +0 -1
- package/dist/ws.js +0 -78
- package/dist/ws.js.map +0 -1
package/dist/client.js
CHANGED
|
@@ -10,50 +10,12 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
15
|
};
|
|
21
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
-
var ownKeys = function(o) {
|
|
23
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
-
var ar = [];
|
|
25
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
-
return ar;
|
|
27
|
-
};
|
|
28
|
-
return ownKeys(o);
|
|
29
|
-
};
|
|
30
|
-
return function (mod) {
|
|
31
|
-
if (mod && mod.__esModule) return mod;
|
|
32
|
-
var result = {};
|
|
33
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
-
__setModuleDefault(result, mod);
|
|
35
|
-
return result;
|
|
36
|
-
};
|
|
37
|
-
})();
|
|
38
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
17
|
exports.HivemindClient = exports.HivemindError = void 0;
|
|
40
|
-
// Re-export all types for consumers
|
|
41
18
|
__exportStar(require("./types"), exports);
|
|
42
|
-
/**
|
|
43
|
-
* Error thrown when an API request fails.
|
|
44
|
-
* Contains the HTTP status code and the raw response body for inspection.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```typescript
|
|
48
|
-
* try {
|
|
49
|
-
* await client.query("my-org", { query: "hello" });
|
|
50
|
-
* } catch (err) {
|
|
51
|
-
* if (err instanceof HivemindError) {
|
|
52
|
-
* console.error(`HTTP ${err.statusCode}:`, err.detail);
|
|
53
|
-
* }
|
|
54
|
-
* }
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
19
|
class HivemindError extends Error {
|
|
58
20
|
statusCode;
|
|
59
21
|
detail;
|
|
@@ -87,9 +49,6 @@ class HivemindClient {
|
|
|
87
49
|
this.baseUrl = this.config.baseUrl;
|
|
88
50
|
this.prefix = this.config.apiPrefix ?? "/v1";
|
|
89
51
|
}
|
|
90
|
-
// -----------------------------------------------------------------------
|
|
91
|
-
// Generic HTTP helpers
|
|
92
|
-
// -----------------------------------------------------------------------
|
|
93
52
|
async request(method, path, opts = {}) {
|
|
94
53
|
const url = new URL(`${this.prefix}${path}`, this.baseUrl);
|
|
95
54
|
return this.performRequest(url, method, opts);
|
|
@@ -100,58 +59,56 @@ class HivemindClient {
|
|
|
100
59
|
}
|
|
101
60
|
async performRequest(url, method, opts = {}) {
|
|
102
61
|
if (opts.query) {
|
|
103
|
-
for (const [
|
|
104
|
-
if (
|
|
105
|
-
url.searchParams.set(
|
|
62
|
+
for (const [key, value] of Object.entries(opts.query)) {
|
|
63
|
+
if (value !== undefined && value !== null) {
|
|
64
|
+
url.searchParams.set(key, String(value));
|
|
65
|
+
}
|
|
106
66
|
}
|
|
107
67
|
}
|
|
108
68
|
const headers = { ...opts.headers };
|
|
109
69
|
const apiKey = opts.apiKey ?? this.config.apiKey;
|
|
110
|
-
|
|
111
|
-
|
|
70
|
+
const authMode = opts.authMode ?? "none";
|
|
71
|
+
if (authMode === "api" && apiKey) {
|
|
72
|
+
headers.Authorization = `Bearer ${apiKey}`;
|
|
112
73
|
}
|
|
113
|
-
if (this.config.adminKey) {
|
|
74
|
+
if (authMode === "admin" && this.config.adminKey) {
|
|
114
75
|
headers["X-Admin-Key"] = this.config.adminKey;
|
|
115
76
|
}
|
|
116
|
-
if (this.config.webhookSecret) {
|
|
77
|
+
if (authMode === "webhook" && this.config.webhookSecret) {
|
|
117
78
|
headers["X-Webhook-Secret"] = this.config.webhookSecret;
|
|
118
79
|
}
|
|
119
|
-
|
|
120
|
-
headers["X-Employee-Id"] = this.config.employeeId;
|
|
121
|
-
}
|
|
122
|
-
let bodyPayload;
|
|
80
|
+
let body;
|
|
123
81
|
if (opts.formData) {
|
|
124
|
-
|
|
82
|
+
body = opts.formData;
|
|
125
83
|
}
|
|
126
84
|
else if (opts.body !== undefined) {
|
|
127
85
|
headers["Content-Type"] = "application/json";
|
|
128
|
-
|
|
86
|
+
body = JSON.stringify(opts.body);
|
|
129
87
|
}
|
|
130
88
|
const controller = new AbortController();
|
|
131
89
|
const timeoutId = setTimeout(() => controller.abort(), this.config.timeoutMs ?? 30_000);
|
|
132
90
|
try {
|
|
133
|
-
const
|
|
91
|
+
const res = await fetch(url.toString(), {
|
|
134
92
|
method,
|
|
135
93
|
headers,
|
|
136
|
-
body:
|
|
94
|
+
body: body,
|
|
137
95
|
signal: controller.signal,
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
if (res.status === 204)
|
|
96
|
+
});
|
|
97
|
+
if (res.status === 204) {
|
|
141
98
|
return undefined;
|
|
99
|
+
}
|
|
142
100
|
const text = await res.text();
|
|
143
|
-
let
|
|
101
|
+
let parsed;
|
|
144
102
|
try {
|
|
145
|
-
|
|
103
|
+
parsed = JSON.parse(text);
|
|
146
104
|
}
|
|
147
105
|
catch {
|
|
148
|
-
|
|
106
|
+
parsed = text;
|
|
149
107
|
}
|
|
150
|
-
const envelope = this.asEnvelope(
|
|
108
|
+
const envelope = this.asEnvelope(parsed);
|
|
151
109
|
if (envelope) {
|
|
152
110
|
if (!envelope.success) {
|
|
153
|
-
|
|
154
|
-
throw new HivemindError(envelope.statusCode, envelope.data, message);
|
|
111
|
+
throw new HivemindError(envelope.statusCode, envelope.data, envelope.message || this.extractErrorMessage(envelope.data) || undefined);
|
|
155
112
|
}
|
|
156
113
|
if (envelope.statusCode === 204 || envelope.data === null) {
|
|
157
114
|
return undefined;
|
|
@@ -159,48 +116,40 @@ class HivemindClient {
|
|
|
159
116
|
return envelope.data;
|
|
160
117
|
}
|
|
161
118
|
if (!res.ok) {
|
|
162
|
-
|
|
163
|
-
throw new HivemindError(res.status, json, message);
|
|
119
|
+
throw new HivemindError(res.status, parsed, this.extractErrorMessage(parsed) || undefined);
|
|
164
120
|
}
|
|
165
|
-
return
|
|
121
|
+
return parsed;
|
|
166
122
|
}
|
|
167
123
|
finally {
|
|
168
124
|
clearTimeout(timeoutId);
|
|
169
125
|
}
|
|
170
126
|
}
|
|
171
|
-
/**
|
|
172
|
-
* Build the same request a normal REST call would, but return the full
|
|
173
|
-
* envelope instead of unwrapping `.data`. Useful when callers need
|
|
174
|
-
* `message` or `statusCode` directly.
|
|
175
|
-
*/
|
|
176
127
|
async requestEnvelope(method, path, opts = {}) {
|
|
177
128
|
const url = new URL(`${this.prefix}${path}`, this.baseUrl);
|
|
178
129
|
if (opts.query) {
|
|
179
|
-
for (const [
|
|
180
|
-
if (
|
|
181
|
-
url.searchParams.set(
|
|
130
|
+
for (const [key, value] of Object.entries(opts.query)) {
|
|
131
|
+
if (value !== undefined && value !== null) {
|
|
132
|
+
url.searchParams.set(key, String(value));
|
|
133
|
+
}
|
|
182
134
|
}
|
|
183
135
|
}
|
|
184
136
|
const headers = { ...opts.headers };
|
|
185
137
|
const apiKey = opts.apiKey ?? this.config.apiKey;
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
138
|
+
const authMode = opts.authMode ?? "api";
|
|
139
|
+
if (authMode === "api" && apiKey)
|
|
140
|
+
headers.Authorization = `Bearer ${apiKey}`;
|
|
141
|
+
if (authMode === "admin" && this.config.adminKey)
|
|
189
142
|
headers["X-Admin-Key"] = this.config.adminKey;
|
|
190
|
-
if (this.config.webhookSecret)
|
|
143
|
+
if (authMode === "webhook" && this.config.webhookSecret)
|
|
191
144
|
headers["X-Webhook-Secret"] = this.config.webhookSecret;
|
|
192
|
-
if (
|
|
193
|
-
headers["X-Employee-Id"] = this.config.employeeId;
|
|
194
|
-
if (opts.body !== undefined) {
|
|
145
|
+
if (opts.body !== undefined)
|
|
195
146
|
headers["Content-Type"] = "application/json";
|
|
196
|
-
}
|
|
197
147
|
const res = await fetch(url.toString(), {
|
|
198
148
|
method,
|
|
199
149
|
headers,
|
|
200
150
|
body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
|
|
201
151
|
});
|
|
202
|
-
|
|
203
|
-
return json;
|
|
152
|
+
return await res.json();
|
|
204
153
|
}
|
|
205
154
|
asEnvelope(payload) {
|
|
206
155
|
if (payload &&
|
|
@@ -218,21 +167,17 @@ class HivemindClient {
|
|
|
218
167
|
if (!detail || typeof detail !== "object")
|
|
219
168
|
return null;
|
|
220
169
|
const record = detail;
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if (
|
|
226
|
-
|
|
227
|
-
if (Array.isArray(nestedDetail)) {
|
|
228
|
-
const parts = nestedDetail
|
|
170
|
+
if (typeof record.message === "string")
|
|
171
|
+
return record.message;
|
|
172
|
+
if (typeof record.detail === "string")
|
|
173
|
+
return record.detail;
|
|
174
|
+
if (Array.isArray(record.detail)) {
|
|
175
|
+
const parts = record.detail
|
|
229
176
|
.map((item) => {
|
|
230
177
|
if (typeof item === "string")
|
|
231
178
|
return item;
|
|
232
|
-
if (item && typeof item === "object") {
|
|
233
|
-
|
|
234
|
-
if (typeof nestedMessage === "string")
|
|
235
|
-
return nestedMessage;
|
|
179
|
+
if (item && typeof item === "object" && typeof item.msg === "string") {
|
|
180
|
+
return item.msg;
|
|
236
181
|
}
|
|
237
182
|
return null;
|
|
238
183
|
})
|
|
@@ -241,814 +186,132 @@ class HivemindClient {
|
|
|
241
186
|
}
|
|
242
187
|
return null;
|
|
243
188
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
265
|
-
patch(path, body, options) {
|
|
266
|
-
return this.request("PATCH", path, {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
189
|
+
get(path, query, options, defaultAuthMode = "api") {
|
|
190
|
+
return this.request("GET", path, {
|
|
191
|
+
query,
|
|
192
|
+
apiKey: options?.apiKey,
|
|
193
|
+
authMode: options?.authMode ?? defaultAuthMode,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
post(path, body, options, defaultAuthMode = "api") {
|
|
197
|
+
return this.request("POST", path, {
|
|
198
|
+
body,
|
|
199
|
+
apiKey: options?.apiKey,
|
|
200
|
+
authMode: options?.authMode ?? defaultAuthMode,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
put(path, body, options, defaultAuthMode = "api") {
|
|
204
|
+
return this.request("PUT", path, {
|
|
205
|
+
body,
|
|
206
|
+
apiKey: options?.apiKey,
|
|
207
|
+
authMode: options?.authMode ?? defaultAuthMode,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
patch(path, body, options, defaultAuthMode = "api") {
|
|
211
|
+
return this.request("PATCH", path, {
|
|
212
|
+
body,
|
|
213
|
+
apiKey: options?.apiKey,
|
|
214
|
+
authMode: options?.authMode ?? defaultAuthMode,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
del(path, options, defaultAuthMode = "api") {
|
|
218
|
+
return this.request("DELETE", path, {
|
|
219
|
+
apiKey: options?.apiKey,
|
|
220
|
+
authMode: options?.authMode ?? defaultAuthMode,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
278
223
|
root() {
|
|
279
|
-
return this.requestUnprefixed("GET", "/");
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Check service health status. No authentication required.
|
|
283
|
-
*
|
|
284
|
-
* @returns Service name, version, status, and aggregate statistics.
|
|
285
|
-
*
|
|
286
|
-
* **Endpoint:** `GET /v1/health`
|
|
287
|
-
*
|
|
288
|
-
* @example
|
|
289
|
-
* ```typescript
|
|
290
|
-
* const health = await client.health();
|
|
291
|
-
* console.log(health.status); // "ok"
|
|
292
|
-
* console.log(health.stats); // { organizations: 12, documents: 450, total_chunks: 3200 }
|
|
293
|
-
* ```
|
|
294
|
-
*/
|
|
224
|
+
return this.requestUnprefixed("GET", "/", { authMode: "none" });
|
|
225
|
+
}
|
|
295
226
|
health() {
|
|
296
|
-
return this.get("/health");
|
|
297
|
-
}
|
|
298
|
-
// -----------------------------------------------------------------------
|
|
299
|
-
// Admin auth
|
|
300
|
-
// -----------------------------------------------------------------------
|
|
301
|
-
/**
|
|
302
|
-
* Exchange the bootstrap admin key for a signed session token.
|
|
303
|
-
* The token can be used as `Authorization: Bearer <token>` for admin endpoints
|
|
304
|
-
* instead of sending the raw admin key on every request.
|
|
305
|
-
*
|
|
306
|
-
* @param params - Object containing the `admin_key`.
|
|
307
|
-
* @returns Signed session token with type and expiry.
|
|
308
|
-
* @throws {@link HivemindError} 400 if admin key is not configured on the server.
|
|
309
|
-
* @throws {@link HivemindError} 401 if the admin key is invalid.
|
|
310
|
-
*
|
|
311
|
-
* **Endpoint:** `POST /v1/admin/login`
|
|
312
|
-
*
|
|
313
|
-
* @example
|
|
314
|
-
* ```typescript
|
|
315
|
-
* const { access_token, expires_in_seconds } = await client.adminLogin({
|
|
316
|
-
* admin_key: "your-bootstrap-admin-key",
|
|
317
|
-
* });
|
|
318
|
-
* // Use access_token as Bearer token for subsequent admin requests
|
|
319
|
-
* ```
|
|
320
|
-
*/
|
|
227
|
+
return this.get("/health", undefined, undefined, "none");
|
|
228
|
+
}
|
|
321
229
|
adminLogin(params) {
|
|
322
|
-
return this.post("/admin/login", params);
|
|
230
|
+
return this.post("/admin/login", params, undefined, "none");
|
|
323
231
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
try {
|
|
327
|
-
const created = await this.post("/organizations", params);
|
|
328
|
-
if (allowExisting) {
|
|
329
|
-
return { ...created, created: true };
|
|
330
|
-
}
|
|
331
|
-
return created;
|
|
332
|
-
}
|
|
333
|
-
catch (err) {
|
|
334
|
-
if (!allowExisting || !this.isOrganizationAlreadyExistsError(err, params.org_id)) {
|
|
335
|
-
throw err;
|
|
336
|
-
}
|
|
337
|
-
const organization = await this.getAdminOrganization(params.org_id);
|
|
338
|
-
return {
|
|
339
|
-
created: false,
|
|
340
|
-
organization,
|
|
341
|
-
api_key: null,
|
|
342
|
-
};
|
|
343
|
-
}
|
|
232
|
+
issueApiKey(params = {}) {
|
|
233
|
+
return this.post("/api-keys", params, undefined, "admin");
|
|
344
234
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
*/
|
|
353
|
-
ensureOrganization(params) {
|
|
354
|
-
return this.createOrganization(params, { allowExisting: true });
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Retrieve organization details including tier, status, and settings.
|
|
358
|
-
*
|
|
359
|
-
* **Auth:** Requires org-scoped API key (via config or `options.apiKey`).
|
|
360
|
-
*
|
|
361
|
-
* @param orgId - Organization identifier.
|
|
362
|
-
* @param options - Optional per-request overrides (e.g. `{ apiKey }`).
|
|
363
|
-
* @returns Full organization entity.
|
|
364
|
-
* @throws {@link HivemindError} 401 if API key is missing or invalid.
|
|
365
|
-
* @throws {@link HivemindError} 403 if the API key belongs to a different org.
|
|
366
|
-
* @throws {@link HivemindError} 404 if the organization does not exist.
|
|
367
|
-
*
|
|
368
|
-
* **Endpoint:** `GET /v1/organizations/{orgId}`
|
|
369
|
-
*/
|
|
370
|
-
getOrganization(orgId, options) {
|
|
371
|
-
return this.get(`/organizations/${orgId}`, undefined, options);
|
|
372
|
-
}
|
|
373
|
-
/**
|
|
374
|
-
* Rotate the API key for an organization. The previous key remains valid
|
|
375
|
-
* for a 24-hour grace period.
|
|
376
|
-
*
|
|
377
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
378
|
-
*
|
|
379
|
-
* @param orgId - Organization identifier.
|
|
380
|
-
* @param options - Optional per-request overrides.
|
|
381
|
-
* @returns New API key and grace period expiry for the previous key.
|
|
382
|
-
* @throws {@link HivemindError} 401 if admin credentials are invalid.
|
|
383
|
-
* @throws {@link HivemindError} 404 if the organization does not exist.
|
|
384
|
-
*
|
|
385
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/api-keys/rotate`
|
|
386
|
-
*/
|
|
387
|
-
rotateApiKey(orgId, options) {
|
|
388
|
-
return this.post(`/organizations/${orgId}/api-keys/rotate`, undefined, options);
|
|
389
|
-
}
|
|
390
|
-
/**
|
|
391
|
-
* Suspend an organization, blocking all API key access until reactivated.
|
|
392
|
-
*
|
|
393
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
394
|
-
*
|
|
395
|
-
* @param orgId - Organization identifier.
|
|
396
|
-
* @param options - Optional per-request overrides.
|
|
397
|
-
* @returns Updated organization status.
|
|
398
|
-
* @throws {@link HivemindError} 401 if admin credentials are invalid.
|
|
399
|
-
* @throws {@link HivemindError} 404 if the organization does not exist.
|
|
400
|
-
*
|
|
401
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/suspend`
|
|
402
|
-
*/
|
|
403
|
-
suspendOrganization(orgId, options) {
|
|
404
|
-
return this.post(`/organizations/${orgId}/suspend`, undefined, options);
|
|
405
|
-
}
|
|
406
|
-
/**
|
|
407
|
-
* Reactivate a suspended organization, restoring API key access.
|
|
408
|
-
*
|
|
409
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
410
|
-
*
|
|
411
|
-
* @param orgId - Organization identifier.
|
|
412
|
-
* @param options - Optional per-request overrides.
|
|
413
|
-
* @returns Updated organization status.
|
|
414
|
-
* @throws {@link HivemindError} 401 if admin credentials are invalid.
|
|
415
|
-
* @throws {@link HivemindError} 404 if the organization does not exist.
|
|
416
|
-
*
|
|
417
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/reactivate`
|
|
418
|
-
*/
|
|
419
|
-
reactivateOrganization(orgId, options) {
|
|
420
|
-
return this.post(`/organizations/${orgId}/reactivate`, undefined, options);
|
|
421
|
-
}
|
|
422
|
-
/**
|
|
423
|
-
* Permanently delete an organization and all associated data.
|
|
424
|
-
* This action is irreversible.
|
|
425
|
-
*
|
|
426
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
427
|
-
*
|
|
428
|
-
* @param orgId - Organization identifier.
|
|
429
|
-
* @param options - Optional per-request overrides.
|
|
430
|
-
* @throws {@link HivemindError} 401 if admin credentials are invalid.
|
|
431
|
-
* @throws {@link HivemindError} 404 if the organization does not exist.
|
|
432
|
-
*
|
|
433
|
-
* **Endpoint:** `DELETE /v1/organizations/{orgId}`
|
|
434
|
-
*/
|
|
435
|
-
deleteOrganization(orgId, options) {
|
|
436
|
-
return this.del(`/organizations/${orgId}`, options);
|
|
437
|
-
}
|
|
438
|
-
// -----------------------------------------------------------------------
|
|
439
|
-
// Documents
|
|
440
|
-
// -----------------------------------------------------------------------
|
|
441
|
-
/**
|
|
442
|
-
* Upload and ingest a document file (PDF, TXT, DOCX, etc.).
|
|
443
|
-
* The document is stored in GCS, split into chunks, and embedded for RAG retrieval.
|
|
444
|
-
*
|
|
445
|
-
* **Auth:** Requires org-scoped API key.
|
|
446
|
-
*
|
|
447
|
-
* @param orgId - Organization identifier.
|
|
448
|
-
* @param file - Document content as a `Blob` or `Buffer`.
|
|
449
|
-
* @param filename - Original filename (e.g. `"report.pdf"`).
|
|
450
|
-
* @param options - Optional per-request overrides (e.g. `{ apiKey }`).
|
|
451
|
-
* @returns Upload result with document ID, chunk count, and status.
|
|
452
|
-
* @throws {@link HivemindError} 400 if the file exceeds the maximum upload size (default 25 MB).
|
|
453
|
-
* @throws {@link HivemindError} 401 if API key is missing or invalid.
|
|
454
|
-
* @throws {@link HivemindError} 429 if rate limit is exceeded.
|
|
455
|
-
*
|
|
456
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/documents/upload`
|
|
457
|
-
* **Content-Type:** `multipart/form-data`
|
|
458
|
-
*
|
|
459
|
-
* @example
|
|
460
|
-
* ```typescript
|
|
461
|
-
* import { readFileSync } from "fs";
|
|
462
|
-
* const file = readFileSync("./report.pdf");
|
|
463
|
-
* const result = await client.uploadDocument("acme-corp", file, "report.pdf");
|
|
464
|
-
* console.log(`Uploaded: ${result.document_id}, ${result.chunks} chunks`);
|
|
465
|
-
* ```
|
|
466
|
-
*/
|
|
467
|
-
async uploadDocument(orgId, file, filename, options) {
|
|
235
|
+
getCurrentScope(options) {
|
|
236
|
+
return this.get("/api-key", undefined, options);
|
|
237
|
+
}
|
|
238
|
+
rotateApiKey(options) {
|
|
239
|
+
return this.post("/api-key/rotate", undefined, options);
|
|
240
|
+
}
|
|
241
|
+
async uploadDocument(file, filename, options) {
|
|
468
242
|
const form = new FormData();
|
|
469
243
|
const blob = file instanceof Blob ? file : new Blob([file], { type: "application/octet-stream" });
|
|
470
244
|
form.append("file", blob, filename);
|
|
471
|
-
return this.request("POST",
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
* const result = await client.query("acme-corp", {
|
|
496
|
-
* query: "What are the key findings in Q4?",
|
|
497
|
-
* temperature: 0.2,
|
|
498
|
-
* retrieval_strategy: "hybrid",
|
|
499
|
-
* });
|
|
500
|
-
* console.log(result.answer);
|
|
501
|
-
* console.log(result.sources); // citations with doc_id, chunk_id, score, snippet
|
|
502
|
-
* ```
|
|
503
|
-
*/
|
|
504
|
-
query(orgId, params, options) {
|
|
505
|
-
return this.post(`/organizations/${orgId}/query`, params, options);
|
|
506
|
-
}
|
|
507
|
-
/**
|
|
508
|
-
* Search indexed sources for source discovery.
|
|
509
|
-
*
|
|
510
|
-
* **Auth:** Requires org-scoped API key.
|
|
511
|
-
*
|
|
512
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/search`
|
|
513
|
-
*/
|
|
514
|
-
search(orgId, params, options) {
|
|
515
|
-
return this.post(`/organizations/${orgId}/search`, params, options);
|
|
516
|
-
}
|
|
517
|
-
// -----------------------------------------------------------------------
|
|
518
|
-
// Content Creator
|
|
519
|
-
// -----------------------------------------------------------------------
|
|
520
|
-
createProject(orgId, params, options) {
|
|
521
|
-
return this.post(`/organizations/${orgId}/projects`, params, options);
|
|
522
|
-
}
|
|
523
|
-
listProjects(orgId, options) {
|
|
524
|
-
return this.get(`/organizations/${orgId}/projects`, undefined, options);
|
|
525
|
-
}
|
|
526
|
-
getProject(orgId, projectId, options) {
|
|
527
|
-
return this.get(`/organizations/${orgId}/projects/${projectId}`, undefined, options);
|
|
528
|
-
}
|
|
529
|
-
updateProject(orgId, projectId, params, options) {
|
|
530
|
-
return this.patch(`/organizations/${orgId}/projects/${projectId}`, params, options);
|
|
531
|
-
}
|
|
532
|
-
deleteProject(orgId, projectId, options) {
|
|
533
|
-
return this.del(`/organizations/${orgId}/projects/${projectId}`, options);
|
|
534
|
-
}
|
|
535
|
-
chatProject(orgId, projectId, params, options) {
|
|
536
|
-
return this.post(`/organizations/${orgId}/projects/${projectId}/chat`, params, options);
|
|
537
|
-
}
|
|
538
|
-
getProjectChatHistory(orgId, projectId, userId, options) {
|
|
539
|
-
return this.get(`/organizations/${orgId}/projects/${projectId}/chat`, { user_id: userId }, options);
|
|
540
|
-
}
|
|
541
|
-
createContentItem(orgId, projectId, params, options) {
|
|
542
|
-
return this.post(`/organizations/${orgId}/projects/${projectId}/content`, params, options);
|
|
543
|
-
}
|
|
544
|
-
listContentItems(orgId, projectId, options) {
|
|
545
|
-
return this.get(`/organizations/${orgId}/projects/${projectId}/content`, undefined, options);
|
|
546
|
-
}
|
|
547
|
-
getContentItem(orgId, projectId, contentId, options) {
|
|
548
|
-
return this.get(`/organizations/${orgId}/projects/${projectId}/content/${contentId}`, undefined, options);
|
|
549
|
-
}
|
|
550
|
-
updateContentItem(orgId, projectId, contentId, params, options) {
|
|
551
|
-
return this.patch(`/organizations/${orgId}/projects/${projectId}/content/${contentId}`, params, options);
|
|
552
|
-
}
|
|
553
|
-
deleteContentItem(orgId, projectId, contentId, options) {
|
|
554
|
-
return this.del(`/organizations/${orgId}/projects/${projectId}/content/${contentId}`, options);
|
|
555
|
-
}
|
|
556
|
-
createProjectSource(orgId, projectId, params, options) {
|
|
557
|
-
return this.post(`/organizations/${orgId}/projects/${projectId}/sources`, params, options);
|
|
558
|
-
}
|
|
559
|
-
/**
|
|
560
|
-
* Scrape external URLs and save the normalized results as project sources.
|
|
561
|
-
*
|
|
562
|
-
* **Auth:** Requires org-scoped API key.
|
|
563
|
-
*
|
|
564
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/projects/{projectId}/sources/scrape`
|
|
565
|
-
*/
|
|
566
|
-
scrapeProjectSources(orgId, projectId, params, options) {
|
|
567
|
-
return this.post(`/organizations/${orgId}/projects/${projectId}/sources/scrape`, params, options);
|
|
568
|
-
}
|
|
569
|
-
listProjectSources(orgId, projectId, options) {
|
|
570
|
-
return this.get(`/organizations/${orgId}/projects/${projectId}/sources`, undefined, options);
|
|
571
|
-
}
|
|
572
|
-
getProjectSource(orgId, projectId, sourceId, options) {
|
|
573
|
-
return this.get(`/organizations/${orgId}/projects/${projectId}/sources/${sourceId}`, undefined, options);
|
|
574
|
-
}
|
|
575
|
-
updateProjectSource(orgId, projectId, sourceId, params, options) {
|
|
576
|
-
return this.patch(`/organizations/${orgId}/projects/${projectId}/sources/${sourceId}`, params, options);
|
|
577
|
-
}
|
|
578
|
-
deleteProjectSource(orgId, projectId, sourceId, options) {
|
|
579
|
-
return this.del(`/organizations/${orgId}/projects/${projectId}/sources/${sourceId}`, options);
|
|
580
|
-
}
|
|
581
|
-
/**
|
|
582
|
-
* Create a publish schedule for an existing content item.
|
|
583
|
-
*
|
|
584
|
-
* **Auth:** Requires org-scoped API key.
|
|
585
|
-
*
|
|
586
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/projects/{projectId}/schedules`
|
|
587
|
-
*/
|
|
588
|
-
createPublishSchedule(orgId, projectId, params, options) {
|
|
589
|
-
return this.post(`/organizations/${orgId}/projects/${projectId}/schedules`, params, options);
|
|
590
|
-
}
|
|
591
|
-
/**
|
|
592
|
-
* List publish schedules for a project.
|
|
593
|
-
*
|
|
594
|
-
* **Auth:** Requires org-scoped API key.
|
|
595
|
-
*
|
|
596
|
-
* **Endpoint:** `GET /v1/organizations/{orgId}/projects/{projectId}/schedules`
|
|
597
|
-
*/
|
|
598
|
-
listPublishSchedules(orgId, projectId, options) {
|
|
599
|
-
return this.get(`/organizations/${orgId}/projects/${projectId}/schedules`, undefined, options);
|
|
600
|
-
}
|
|
601
|
-
/**
|
|
602
|
-
* Get a single publish schedule.
|
|
603
|
-
*
|
|
604
|
-
* **Auth:** Requires org-scoped API key.
|
|
605
|
-
*
|
|
606
|
-
* **Endpoint:** `GET /v1/organizations/{orgId}/projects/{projectId}/schedules/{scheduleId}`
|
|
607
|
-
*/
|
|
608
|
-
getPublishSchedule(orgId, projectId, scheduleId, options) {
|
|
609
|
-
return this.get(`/organizations/${orgId}/projects/${projectId}/schedules/${scheduleId}`, undefined, options);
|
|
610
|
-
}
|
|
611
|
-
/**
|
|
612
|
-
* Update a publish schedule.
|
|
613
|
-
*
|
|
614
|
-
* **Auth:** Requires org-scoped API key.
|
|
615
|
-
*
|
|
616
|
-
* **Endpoint:** `PATCH /v1/organizations/{orgId}/projects/{projectId}/schedules/{scheduleId}`
|
|
617
|
-
*/
|
|
618
|
-
updatePublishSchedule(orgId, projectId, scheduleId, params, options) {
|
|
619
|
-
return this.patch(`/organizations/${orgId}/projects/${projectId}/schedules/${scheduleId}`, params, options);
|
|
620
|
-
}
|
|
621
|
-
/**
|
|
622
|
-
* Delete a publish schedule.
|
|
623
|
-
*
|
|
624
|
-
* **Auth:** Requires org-scoped API key.
|
|
625
|
-
*
|
|
626
|
-
* **Endpoint:** `DELETE /v1/organizations/{orgId}/projects/{projectId}/schedules/{scheduleId}`
|
|
627
|
-
*/
|
|
628
|
-
deletePublishSchedule(orgId, projectId, scheduleId, options) {
|
|
629
|
-
return this.del(`/organizations/${orgId}/projects/${projectId}/schedules/${scheduleId}`, options);
|
|
630
|
-
}
|
|
631
|
-
/**
|
|
632
|
-
* Manually run due Content Creator schedules immediately.
|
|
633
|
-
*
|
|
634
|
-
* This is primarily an admin fallback or operational tool. In normal
|
|
635
|
-
* deployments, due schedules are processed automatically by the backend's
|
|
636
|
-
* background content schedule runner.
|
|
637
|
-
*
|
|
638
|
-
* **Auth:** Requires admin key.
|
|
639
|
-
*
|
|
640
|
-
* **Endpoint:** `POST /v1/admin/content-creator/schedules/run-due`
|
|
641
|
-
*/
|
|
642
|
-
runDueSchedules() {
|
|
643
|
-
return this.post("/admin/content-creator/schedules/run-due");
|
|
644
|
-
}
|
|
645
|
-
// -----------------------------------------------------------------------
|
|
646
|
-
// Generation
|
|
647
|
-
// -----------------------------------------------------------------------
|
|
648
|
-
/**
|
|
649
|
-
* Start an asynchronous video generation job using Vertex AI Veo.
|
|
650
|
-
* Returns a job ID — poll with `getJob()` or `waitForJob()` for results.
|
|
651
|
-
*
|
|
652
|
-
* **Auth:** Requires org-scoped API key.
|
|
653
|
-
*
|
|
654
|
-
* @param orgId - Organization identifier.
|
|
655
|
-
* @param params - Video generation parameters (prompt, duration, aspect_ratio, style).
|
|
656
|
-
* @param options - Optional per-request overrides.
|
|
657
|
-
* @returns Job ID and estimated processing time (HTTP 202).
|
|
658
|
-
* @throws {@link HivemindError} 429 if rate limit, video quota, or concurrent job limit is exceeded.
|
|
659
|
-
*
|
|
660
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/generate/video`
|
|
661
|
-
*
|
|
662
|
-
* @example
|
|
663
|
-
* ```typescript
|
|
664
|
-
* const job = await client.generateVideo("acme-corp", {
|
|
665
|
-
* prompt: "A drone flyover of a mountain lake at sunset",
|
|
666
|
-
* duration: 8,
|
|
667
|
-
* aspect_ratio: "16:9",
|
|
668
|
-
* style: "cinematic",
|
|
669
|
-
* });
|
|
670
|
-
* const result = await client.waitForJob("acme-corp", job.job_id);
|
|
671
|
-
* console.log(result.result); // { output_url, signed_url }
|
|
672
|
-
* ```
|
|
673
|
-
*/
|
|
674
|
-
generateVideo(orgId, params, options) {
|
|
675
|
-
return this.post(`/organizations/${orgId}/generate/video`, params, options);
|
|
676
|
-
}
|
|
677
|
-
/**
|
|
678
|
-
* Start an asynchronous image generation job using Vertex AI Imagen.
|
|
679
|
-
* Returns a job ID — poll with `getJob()` or `waitForJob()` for results.
|
|
680
|
-
*
|
|
681
|
-
* **Auth:** Requires org-scoped API key.
|
|
682
|
-
*
|
|
683
|
-
* @param orgId - Organization identifier.
|
|
684
|
-
* @param params - Image generation parameters (prompt, aspect_ratio, style, num_images).
|
|
685
|
-
* @param options - Optional per-request overrides.
|
|
686
|
-
* @returns Job ID and estimated processing time (HTTP 202).
|
|
687
|
-
* @throws {@link HivemindError} 429 if rate limit, image quota, or concurrent job limit is exceeded.
|
|
688
|
-
*
|
|
689
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/generate/image`
|
|
690
|
-
*
|
|
691
|
-
* @example
|
|
692
|
-
* ```typescript
|
|
693
|
-
* const job = await client.generateImage("acme-corp", {
|
|
694
|
-
* prompt: "A futuristic city skyline at dusk",
|
|
695
|
-
* aspect_ratio: "16:9",
|
|
696
|
-
* style: "digital art",
|
|
697
|
-
* num_images: 4,
|
|
698
|
-
* });
|
|
699
|
-
* const result = await client.waitForJob("acme-corp", job.job_id);
|
|
700
|
-
* ```
|
|
701
|
-
*/
|
|
702
|
-
generateImage(orgId, params, options) {
|
|
703
|
-
return this.post(`/organizations/${orgId}/generate/image`, params, options);
|
|
704
|
-
}
|
|
705
|
-
/**
|
|
706
|
-
* Start an asynchronous music generation job.
|
|
707
|
-
* Returns a job ID — poll with `getJob()` or `waitForJob()` for results.
|
|
708
|
-
*
|
|
709
|
-
* **Auth:** Requires org-scoped API key.
|
|
710
|
-
*
|
|
711
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/generate/music`
|
|
712
|
-
*/
|
|
713
|
-
generateMusic(orgId, params, options) {
|
|
714
|
-
return this.post(`/organizations/${orgId}/generate/music`, params, options);
|
|
715
|
-
}
|
|
716
|
-
// -----------------------------------------------------------------------
|
|
717
|
-
// Jobs
|
|
718
|
-
// -----------------------------------------------------------------------
|
|
719
|
-
/**
|
|
720
|
-
* Check the status of an asynchronous job (video or image generation).
|
|
721
|
-
*
|
|
722
|
-
* **Auth:** Requires org-scoped API key.
|
|
723
|
-
*
|
|
724
|
-
* @param orgId - Organization identifier.
|
|
725
|
-
* @param jobId - Job identifier (from `generateVideo()` or `generateImage()`).
|
|
726
|
-
* @param options - Optional per-request overrides.
|
|
727
|
-
* @returns Job status, result URLs (when completed), or error details (when failed).
|
|
728
|
-
* @throws {@link HivemindError} 404 if the job does not exist.
|
|
729
|
-
*
|
|
730
|
-
* **Endpoint:** `GET /v1/organizations/{orgId}/jobs/{jobId}`
|
|
731
|
-
*/
|
|
732
|
-
getJob(orgId, jobId, options) {
|
|
733
|
-
return this.get(`/organizations/${orgId}/jobs/${jobId}`, undefined, options);
|
|
734
|
-
}
|
|
735
|
-
/**
|
|
736
|
-
* Poll a job until it reaches a terminal status (`completed`, `failed`, or `cancelled`).
|
|
737
|
-
*
|
|
738
|
-
* @param orgId - Organization identifier.
|
|
739
|
-
* @param jobId - Job identifier.
|
|
740
|
-
* @param intervalMs - Polling interval in milliseconds. @default 2000
|
|
741
|
-
* @param maxWaitMs - Maximum wait time in milliseconds. @default 300000 (5 min)
|
|
742
|
-
* @param options - Optional per-request overrides.
|
|
743
|
-
* @returns Final job status with result or error.
|
|
744
|
-
* @throws Error if the job does not complete within `maxWaitMs`.
|
|
745
|
-
*
|
|
746
|
-
* @example
|
|
747
|
-
* ```typescript
|
|
748
|
-
* const job = await client.generateVideo("acme-corp", { prompt: "..." });
|
|
749
|
-
* const result = await client.waitForJob("acme-corp", job.job_id, 3000, 600_000);
|
|
750
|
-
* if (result.status === "completed") console.log(result.result);
|
|
751
|
-
* ```
|
|
752
|
-
*/
|
|
753
|
-
async waitForJob(orgId, jobId, intervalMs = 2000, maxWaitMs = 300_000, options) {
|
|
245
|
+
return this.request("POST", "/documents/upload", {
|
|
246
|
+
formData: form,
|
|
247
|
+
apiKey: options?.apiKey,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
search(params, options) {
|
|
251
|
+
return this.post("/search", params, options);
|
|
252
|
+
}
|
|
253
|
+
generateVideo(params, options) {
|
|
254
|
+
return this.post("/generate/video", params, options);
|
|
255
|
+
}
|
|
256
|
+
generateImage(params, options) {
|
|
257
|
+
return this.post("/generate/image", params, options);
|
|
258
|
+
}
|
|
259
|
+
generateMusic(params, options) {
|
|
260
|
+
return this.post("/generate/music", params, options);
|
|
261
|
+
}
|
|
262
|
+
generateSocialContent(params, options) {
|
|
263
|
+
return this.post("/generate/social", params, options);
|
|
264
|
+
}
|
|
265
|
+
getJob(jobId, options) {
|
|
266
|
+
return this.get(`/jobs/${jobId}`, undefined, options);
|
|
267
|
+
}
|
|
268
|
+
async waitForJob(jobId, intervalMs = 2000, maxWaitMs = 300_000, options) {
|
|
754
269
|
const start = Date.now();
|
|
755
270
|
while (Date.now() - start < maxWaitMs) {
|
|
756
|
-
const job = await this.getJob(
|
|
271
|
+
const job = await this.getJob(jobId, options);
|
|
757
272
|
if (["completed", "failed", "cancelled"].includes(job.status)) {
|
|
758
273
|
return job;
|
|
759
274
|
}
|
|
760
|
-
await new Promise((
|
|
275
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
761
276
|
}
|
|
762
277
|
throw new Error(`Job ${jobId} did not complete within ${maxWaitMs}ms`);
|
|
763
278
|
}
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
dataChat(orgId, params, options) {
|
|
792
|
-
return this.post(`/organizations/${orgId}/data-chat`, params, options);
|
|
793
|
-
}
|
|
794
|
-
// -----------------------------------------------------------------------
|
|
795
|
-
// Agents
|
|
796
|
-
// -----------------------------------------------------------------------
|
|
797
|
-
/**
|
|
798
|
-
* Create a custom AI agent template with system instructions and optional tool bindings.
|
|
799
|
-
*
|
|
800
|
-
* **Auth:** Requires org-scoped API key.
|
|
801
|
-
*
|
|
802
|
-
* @param orgId - Organization identifier.
|
|
803
|
-
* @param params - Agent name, instructions, and optional tools.
|
|
804
|
-
* @param options - Optional per-request overrides.
|
|
805
|
-
* @returns Created agent with ID, name, and enabled tools.
|
|
806
|
-
*
|
|
807
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/agents/custom`
|
|
808
|
-
*
|
|
809
|
-
* @example
|
|
810
|
-
* ```typescript
|
|
811
|
-
* const agent = await client.createAgent("acme-corp", {
|
|
812
|
-
* name: "Support Bot",
|
|
813
|
-
* instructions: "You are a helpful customer support agent.",
|
|
814
|
-
* tools: ["rag_search", "ticket_create"],
|
|
815
|
-
* });
|
|
816
|
-
* console.log(agent.agent_id);
|
|
817
|
-
* ```
|
|
818
|
-
*/
|
|
819
|
-
createAgent(orgId, params, options) {
|
|
820
|
-
return this.post(`/organizations/${orgId}/agents/custom`, params, options);
|
|
821
|
-
}
|
|
822
|
-
/**
|
|
823
|
-
* Send a query to an AI agent. Routes to the specified agent type or auto-selects.
|
|
824
|
-
*
|
|
825
|
-
* **Auth:** Requires org-scoped API key.
|
|
826
|
-
*
|
|
827
|
-
* @param orgId - Organization identifier.
|
|
828
|
-
* @param params - Query text, user ID, and optional agent type.
|
|
829
|
-
* @param options - Optional per-request overrides.
|
|
830
|
-
* @returns Agent response text, agent type, and any tool calls made.
|
|
831
|
-
* @throws {@link HivemindError} 429 if rate limit or token quota is exceeded.
|
|
832
|
-
*
|
|
833
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/agents/query`
|
|
834
|
-
*/
|
|
835
|
-
queryAgent(orgId, params, options) {
|
|
836
|
-
return this.post(`/organizations/${orgId}/agents/query`, params, options);
|
|
837
|
-
}
|
|
838
|
-
// -----------------------------------------------------------------------
|
|
839
|
-
// Audio
|
|
840
|
-
// -----------------------------------------------------------------------
|
|
841
|
-
/**
|
|
842
|
-
* Transcribe audio content to text (speech-to-text).
|
|
843
|
-
*
|
|
844
|
-
* **Auth:** Requires org-scoped API key.
|
|
845
|
-
*
|
|
846
|
-
* @param orgId - Organization identifier.
|
|
847
|
-
* @param params - Audio content and optional BCP-47 language code.
|
|
848
|
-
* @param options - Optional per-request overrides.
|
|
849
|
-
* @returns Transcription result with transcript text, confidence, and language.
|
|
850
|
-
* @throws {@link HivemindError} 429 if rate limit is exceeded.
|
|
851
|
-
*
|
|
852
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/audio/transcribe`
|
|
853
|
-
*/
|
|
854
|
-
transcribeAudio(orgId, params, options) {
|
|
855
|
-
return this.post(`/organizations/${orgId}/audio/transcribe`, params, options);
|
|
856
|
-
}
|
|
857
|
-
/**
|
|
858
|
-
* Convert text to speech (text-to-speech synthesis).
|
|
859
|
-
* Returns a signed URL to the generated audio file.
|
|
860
|
-
*
|
|
861
|
-
* **Auth:** Requires org-scoped API key.
|
|
862
|
-
*
|
|
863
|
-
* @param orgId - Organization identifier.
|
|
864
|
-
* @param params - Text to synthesize and optional voice name.
|
|
865
|
-
* @param options - Optional per-request overrides.
|
|
866
|
-
* @returns Audio URL, duration, and voice used.
|
|
867
|
-
* @throws {@link HivemindError} 429 if rate limit is exceeded.
|
|
868
|
-
*
|
|
869
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/audio/synthesize`
|
|
870
|
-
*/
|
|
871
|
-
synthesizeAudio(orgId, params, options) {
|
|
872
|
-
return this.post(`/organizations/${orgId}/audio/synthesize`, params, options);
|
|
873
|
-
}
|
|
874
|
-
// -----------------------------------------------------------------------
|
|
875
|
-
// Analytics / ML
|
|
876
|
-
// -----------------------------------------------------------------------
|
|
877
|
-
/**
|
|
878
|
-
* Train a predictive model on tabular data.
|
|
879
|
-
*
|
|
880
|
-
* **Auth:** Requires org-scoped API key.
|
|
881
|
-
*
|
|
882
|
-
* @param orgId - Organization identifier.
|
|
883
|
-
* @param params - Target column, feature columns, and training data rows.
|
|
884
|
-
* @param options - Optional per-request overrides.
|
|
885
|
-
* @returns Deployed model ID and status.
|
|
886
|
-
*
|
|
887
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/analytics/train`
|
|
888
|
-
*
|
|
889
|
-
* @example
|
|
890
|
-
* ```typescript
|
|
891
|
-
* const model = await client.trainModel("acme-corp", {
|
|
892
|
-
* target_column: "churn",
|
|
893
|
-
* feature_columns: ["tenure", "monthly_charges", "total_charges"],
|
|
894
|
-
* rows: [
|
|
895
|
-
* { tenure: 12, monthly_charges: 50, total_charges: 600, churn: 0 },
|
|
896
|
-
* { tenure: 2, monthly_charges: 80, total_charges: 160, churn: 1 },
|
|
897
|
-
* ],
|
|
898
|
-
* });
|
|
899
|
-
* console.log(model.model_id); // Use with predict()
|
|
900
|
-
* ```
|
|
901
|
-
*/
|
|
902
|
-
trainModel(orgId, params, options) {
|
|
903
|
-
return this.post(`/organizations/${orgId}/analytics/train`, params, options);
|
|
904
|
-
}
|
|
905
|
-
/**
|
|
906
|
-
* Run predictions using a previously trained model.
|
|
907
|
-
*
|
|
908
|
-
* **Auth:** Requires org-scoped API key.
|
|
909
|
-
*
|
|
910
|
-
* @param orgId - Organization identifier.
|
|
911
|
-
* @param params - Model ID and data instances to predict on.
|
|
912
|
-
* @param options - Optional per-request overrides.
|
|
913
|
-
* @returns Predictions for each input instance.
|
|
914
|
-
* @throws {@link HivemindError} 404 if the model does not exist.
|
|
915
|
-
*
|
|
916
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/analytics/predict`
|
|
917
|
-
*/
|
|
918
|
-
predict(orgId, params, options) {
|
|
919
|
-
return this.post(`/organizations/${orgId}/analytics/predict`, params, options);
|
|
920
|
-
}
|
|
921
|
-
/**
|
|
922
|
-
* Generate a time-series forecast from historical data using ARIMA-based modeling.
|
|
923
|
-
*
|
|
924
|
-
* **Auth:** Requires org-scoped API key.
|
|
925
|
-
*
|
|
926
|
-
* @param orgId - Organization identifier.
|
|
927
|
-
* @param params - Historical series values and optional forecast horizon (1–365).
|
|
928
|
-
* @param options - Optional per-request overrides.
|
|
929
|
-
* @returns Predicted future values.
|
|
930
|
-
*
|
|
931
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/analytics/forecast`
|
|
932
|
-
*/
|
|
933
|
-
forecast(orgId, params, options) {
|
|
934
|
-
return this.post(`/organizations/${orgId}/analytics/forecast`, params, options);
|
|
935
|
-
}
|
|
936
|
-
// -----------------------------------------------------------------------
|
|
937
|
-
// Billing
|
|
938
|
-
// -----------------------------------------------------------------------
|
|
939
|
-
/**
|
|
940
|
-
* Get the monthly usage summary for an organization.
|
|
941
|
-
* Includes token, image, video, storage, and compute usage against tier limits.
|
|
942
|
-
*
|
|
943
|
-
* **Auth:** Requires org-scoped API key.
|
|
944
|
-
*
|
|
945
|
-
* @param orgId - Organization identifier.
|
|
946
|
-
* @param month - Month in `YYYY-MM` format. Defaults to current month.
|
|
947
|
-
* @param options - Optional per-request overrides.
|
|
948
|
-
* @returns Usage counters, tier limits, and quota status.
|
|
949
|
-
*
|
|
950
|
-
* **Endpoint:** `GET /v1/organizations/{orgId}/usage?month={month}`
|
|
951
|
-
*/
|
|
952
|
-
getUsage(orgId, month, options) {
|
|
953
|
-
const query = month ? { month } : undefined;
|
|
954
|
-
return this.get(`/organizations/${orgId}/usage`, query, options);
|
|
955
|
-
}
|
|
956
|
-
/**
|
|
957
|
-
* Get the monthly invoice with detailed cost breakdown by resource type.
|
|
958
|
-
*
|
|
959
|
-
* **Auth:** Requires org-scoped API key.
|
|
960
|
-
*
|
|
961
|
-
* @param orgId - Organization identifier.
|
|
962
|
-
* @param month - Month in `YYYY-MM` format. Defaults to current month.
|
|
963
|
-
* @param options - Optional per-request overrides.
|
|
964
|
-
* @returns Invoice with itemized costs and total in USD.
|
|
965
|
-
*
|
|
966
|
-
* **Endpoint:** `GET /v1/organizations/{orgId}/invoice?month={month}`
|
|
967
|
-
*/
|
|
968
|
-
getInvoice(orgId, month, options) {
|
|
969
|
-
const query = month ? { month } : undefined;
|
|
970
|
-
return this.get(`/organizations/${orgId}/invoice`, query, options);
|
|
971
|
-
}
|
|
972
|
-
// -----------------------------------------------------------------------
|
|
973
|
-
// Audit
|
|
974
|
-
// -----------------------------------------------------------------------
|
|
975
|
-
/**
|
|
976
|
-
* Retrieve audit log records for an organization.
|
|
977
|
-
*
|
|
978
|
-
* **Auth:** Requires org-scoped API key.
|
|
979
|
-
*
|
|
980
|
-
* @param orgId - Organization identifier.
|
|
981
|
-
* @param options - Optional per-request overrides.
|
|
982
|
-
* @returns Audit log entries with timestamps, actions, and metadata.
|
|
983
|
-
*
|
|
984
|
-
* **Endpoint:** `GET /v1/organizations/{orgId}/audit`
|
|
985
|
-
*/
|
|
986
|
-
getAuditLogs(orgId, options) {
|
|
987
|
-
return this.get(`/organizations/${orgId}/audit`, undefined, options);
|
|
988
|
-
}
|
|
989
|
-
// -----------------------------------------------------------------------
|
|
990
|
-
// Scraping
|
|
991
|
-
// -----------------------------------------------------------------------
|
|
992
|
-
/**
|
|
993
|
-
* Get the current scraping runtime configuration.
|
|
994
|
-
*
|
|
995
|
-
* **Auth:** None required.
|
|
996
|
-
*
|
|
997
|
-
* @returns Execution mode, Cloud Run status, and cache statistics.
|
|
998
|
-
*
|
|
999
|
-
* **Endpoint:** `GET /v1/scraping/config`
|
|
1000
|
-
*/
|
|
279
|
+
dataChat(params, options) {
|
|
280
|
+
return this.post("/data-chat", params, options);
|
|
281
|
+
}
|
|
282
|
+
createAgent(params, options) {
|
|
283
|
+
return this.post("/agents/custom", params, options);
|
|
284
|
+
}
|
|
285
|
+
queryAgent(params, options) {
|
|
286
|
+
return this.post("/agents/query", params, options);
|
|
287
|
+
}
|
|
288
|
+
transcribeAudio(params, options) {
|
|
289
|
+
return this.post("/audio/transcribe", params, options);
|
|
290
|
+
}
|
|
291
|
+
synthesizeAudio(params, options) {
|
|
292
|
+
return this.post("/audio/synthesize", params, options);
|
|
293
|
+
}
|
|
294
|
+
trainModel(params, options) {
|
|
295
|
+
return this.post("/analytics/train", params, options);
|
|
296
|
+
}
|
|
297
|
+
predict(params, options) {
|
|
298
|
+
return this.post("/analytics/predict", params, options);
|
|
299
|
+
}
|
|
300
|
+
forecast(params, options) {
|
|
301
|
+
return this.post("/analytics/forecast", params, options);
|
|
302
|
+
}
|
|
303
|
+
getAuditLogs(options) {
|
|
304
|
+
return this.get("/audit", undefined, options);
|
|
305
|
+
}
|
|
1001
306
|
getScrapingConfig() {
|
|
1002
|
-
return this.get("/scraping/config");
|
|
1003
|
-
}
|
|
1004
|
-
/**
|
|
1005
|
-
* Submit URLs for scraping. JS-heavy sites (Reddit, Twitter, LinkedIn)
|
|
1006
|
-
* are auto-routed to Selenium.
|
|
1007
|
-
*
|
|
1008
|
-
* **Auth:** None required.
|
|
1009
|
-
*
|
|
1010
|
-
* @param params - Object containing the `urls` array.
|
|
1011
|
-
* @returns Task ID and submission status.
|
|
1012
|
-
*
|
|
1013
|
-
* **Endpoint:** `POST /v1/scraping/scrape`
|
|
1014
|
-
*/
|
|
307
|
+
return this.get("/scraping/config", undefined, undefined, "none");
|
|
308
|
+
}
|
|
1015
309
|
scrape(params) {
|
|
1016
|
-
return this.post("/scraping/scrape", params);
|
|
1017
|
-
}
|
|
1018
|
-
/**
|
|
1019
|
-
* Check the status and results of a scrape task.
|
|
1020
|
-
*
|
|
1021
|
-
* **Auth:** None required.
|
|
1022
|
-
*
|
|
1023
|
-
* @param taskId - Task identifier (from `scrape()`).
|
|
1024
|
-
* @returns Task status and scraped results (empty while pending).
|
|
1025
|
-
*
|
|
1026
|
-
* **Endpoint:** `GET /v1/scraping/status/{taskId}`
|
|
1027
|
-
*/
|
|
310
|
+
return this.post("/scraping/scrape", params, undefined, "none");
|
|
311
|
+
}
|
|
1028
312
|
getScrapeStatus(taskId) {
|
|
1029
|
-
return this.get(`/scraping/status/${taskId}
|
|
1030
|
-
}
|
|
1031
|
-
/**
|
|
1032
|
-
* Submit a scrape job and poll until results are ready.
|
|
1033
|
-
*
|
|
1034
|
-
* @param urls - URLs to scrape.
|
|
1035
|
-
* @param intervalMs - Polling interval in milliseconds. @default 2000
|
|
1036
|
-
* @param maxWaitMs - Maximum wait time in milliseconds. @default 120000 (2 min)
|
|
1037
|
-
* @returns Final scrape status with results.
|
|
1038
|
-
* @throws Error if the task does not complete within `maxWaitMs`.
|
|
1039
|
-
*
|
|
1040
|
-
* @example
|
|
1041
|
-
* ```typescript
|
|
1042
|
-
* const result = await client.scrapeAndWait(
|
|
1043
|
-
* ["https://example.com", "https://example.org"],
|
|
1044
|
-
* 2000,
|
|
1045
|
-
* 60_000,
|
|
1046
|
-
* );
|
|
1047
|
-
* for (const item of result.result) {
|
|
1048
|
-
* console.log(item.title, item.full_text?.substring(0, 200));
|
|
1049
|
-
* }
|
|
1050
|
-
* ```
|
|
1051
|
-
*/
|
|
313
|
+
return this.get(`/scraping/status/${taskId}`, undefined, undefined, "none");
|
|
314
|
+
}
|
|
1052
315
|
async scrapeAndWait(urls, intervalMs = 2000, maxWaitMs = 120_000) {
|
|
1053
316
|
const { task_id } = await this.scrape({ urls });
|
|
1054
317
|
const start = Date.now();
|
|
@@ -1057,747 +320,146 @@ class HivemindClient {
|
|
|
1057
320
|
if (["SUCCESS", "FAILURE", "completed"].includes(status.status)) {
|
|
1058
321
|
return status;
|
|
1059
322
|
}
|
|
1060
|
-
await new Promise((
|
|
323
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
1061
324
|
}
|
|
1062
325
|
throw new Error(`Scrape ${task_id} did not complete within ${maxWaitMs}ms`);
|
|
1063
326
|
}
|
|
1064
|
-
// -----------------------------------------------------------------------
|
|
1065
|
-
// Webhooks
|
|
1066
|
-
// -----------------------------------------------------------------------
|
|
1067
|
-
/**
|
|
1068
|
-
* Send a video generation completion webhook notification.
|
|
1069
|
-
*
|
|
1070
|
-
* **Auth:** Requires `webhookSecret` in client config (sends `X-Webhook-Secret` header).
|
|
1071
|
-
*
|
|
1072
|
-
* @param payload - Webhook payload with job_id, org_id, status, and optional metadata.
|
|
1073
|
-
* @returns `{ received: true }` on success.
|
|
1074
|
-
* @throws {@link HivemindError} 401 if the webhook secret is invalid.
|
|
1075
|
-
*
|
|
1076
|
-
* **Endpoint:** `POST /v1/webhook/video-complete`
|
|
1077
|
-
*/
|
|
1078
327
|
sendVideoCompleteWebhook(payload) {
|
|
1079
|
-
return this.post("/webhook/video-complete", payload);
|
|
1080
|
-
}
|
|
1081
|
-
/**
|
|
1082
|
-
* Send a document processing completion webhook notification.
|
|
1083
|
-
*
|
|
1084
|
-
* **Auth:** Requires `webhookSecret` in client config (sends `X-Webhook-Secret` header).
|
|
1085
|
-
*
|
|
1086
|
-
* @param payload - Webhook payload with document_id, org_id, status, and optional metadata.
|
|
1087
|
-
* @returns `{ received: true }` on success.
|
|
1088
|
-
* @throws {@link HivemindError} 401 if the webhook secret is invalid.
|
|
1089
|
-
*
|
|
1090
|
-
* **Endpoint:** `POST /v1/webhook/document-processed`
|
|
1091
|
-
*/
|
|
328
|
+
return this.post("/webhook/video-complete", payload, undefined, "webhook");
|
|
329
|
+
}
|
|
1092
330
|
sendDocumentProcessedWebhook(payload) {
|
|
1093
|
-
return this.post("/webhook/document-processed", payload);
|
|
1094
|
-
}
|
|
1095
|
-
// -----------------------------------------------------------------------
|
|
1096
|
-
// Admin — Configuration
|
|
1097
|
-
// -----------------------------------------------------------------------
|
|
1098
|
-
/**
|
|
1099
|
-
* Get full service configuration overview.
|
|
1100
|
-
*
|
|
1101
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1102
|
-
*
|
|
1103
|
-
* **Endpoint:** `GET /v1/admin/config`
|
|
1104
|
-
*/
|
|
331
|
+
return this.post("/webhook/document-processed", payload, undefined, "webhook");
|
|
332
|
+
}
|
|
1105
333
|
getAdminConfig() {
|
|
1106
|
-
return this.get("/admin/config");
|
|
1107
|
-
}
|
|
1108
|
-
/**
|
|
1109
|
-
* Get runtime setting overrides.
|
|
1110
|
-
*
|
|
1111
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1112
|
-
*
|
|
1113
|
-
* **Endpoint:** `GET /v1/admin/config/overrides`
|
|
1114
|
-
*/
|
|
334
|
+
return this.get("/admin/config", undefined, undefined, "admin");
|
|
335
|
+
}
|
|
1115
336
|
getAdminConfigOverrides() {
|
|
1116
|
-
return this.get("/admin/config/overrides");
|
|
1117
|
-
}
|
|
1118
|
-
/**
|
|
1119
|
-
* Update a mutable runtime setting (e.g. log_level, debug, cors_allow_origins).
|
|
1120
|
-
*
|
|
1121
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1122
|
-
*
|
|
1123
|
-
* @param params - Setting key and new value.
|
|
1124
|
-
*
|
|
1125
|
-
* **Endpoint:** `PUT /v1/admin/settings`
|
|
1126
|
-
*/
|
|
337
|
+
return this.get("/admin/config/overrides", undefined, undefined, "admin");
|
|
338
|
+
}
|
|
1127
339
|
updateAdminSetting(params) {
|
|
1128
|
-
return this.put("/admin/settings", params);
|
|
1129
|
-
}
|
|
1130
|
-
// -----------------------------------------------------------------------
|
|
1131
|
-
// Admin — Logging
|
|
1132
|
-
// -----------------------------------------------------------------------
|
|
1133
|
-
/**
|
|
1134
|
-
* Get the current application log level.
|
|
1135
|
-
*
|
|
1136
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1137
|
-
*
|
|
1138
|
-
* **Endpoint:** `GET /v1/admin/logging/level`
|
|
1139
|
-
*/
|
|
340
|
+
return this.put("/admin/settings", params, undefined, "admin");
|
|
341
|
+
}
|
|
1140
342
|
getLogLevel() {
|
|
1141
|
-
return this.get("/admin/logging/level");
|
|
1142
|
-
}
|
|
1143
|
-
/**
|
|
1144
|
-
* Change the application log level.
|
|
1145
|
-
*
|
|
1146
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1147
|
-
*
|
|
1148
|
-
* @param params - The new log level (DEBUG, INFO, WARNING, ERROR, CRITICAL).
|
|
1149
|
-
*
|
|
1150
|
-
* **Endpoint:** `PUT /v1/admin/logging/level`
|
|
1151
|
-
*/
|
|
343
|
+
return this.get("/admin/logging/level", undefined, undefined, "admin");
|
|
344
|
+
}
|
|
1152
345
|
setLogLevel(params) {
|
|
1153
|
-
return this.put("/admin/logging/level", params);
|
|
1154
|
-
}
|
|
1155
|
-
/**
|
|
1156
|
-
* List all loggers with their levels and handlers.
|
|
1157
|
-
*
|
|
1158
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1159
|
-
*
|
|
1160
|
-
* **Endpoint:** `GET /v1/admin/logging/loggers`
|
|
1161
|
-
*/
|
|
346
|
+
return this.put("/admin/logging/level", params, undefined, "admin");
|
|
347
|
+
}
|
|
1162
348
|
getLoggers() {
|
|
1163
|
-
return this.get("/admin/logging/loggers");
|
|
1164
|
-
}
|
|
1165
|
-
// -----------------------------------------------------------------------
|
|
1166
|
-
// Admin — Traffic & Monitoring
|
|
1167
|
-
// -----------------------------------------------------------------------
|
|
1168
|
-
/**
|
|
1169
|
-
* Get inbound traffic statistics.
|
|
1170
|
-
*
|
|
1171
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1172
|
-
*
|
|
1173
|
-
* **Endpoint:** `GET /v1/admin/traffic/inbound`
|
|
1174
|
-
*/
|
|
349
|
+
return this.get("/admin/logging/loggers", undefined, undefined, "admin");
|
|
350
|
+
}
|
|
1175
351
|
getInboundTraffic() {
|
|
1176
|
-
return this.get("/admin/traffic/inbound");
|
|
1177
|
-
}
|
|
1178
|
-
/**
|
|
1179
|
-
* Reset inbound traffic counters.
|
|
1180
|
-
*
|
|
1181
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1182
|
-
*
|
|
1183
|
-
* **Endpoint:** `POST /v1/admin/traffic/inbound/reset`
|
|
1184
|
-
*/
|
|
352
|
+
return this.get("/admin/traffic/inbound", undefined, undefined, "admin");
|
|
353
|
+
}
|
|
1185
354
|
resetInboundTraffic() {
|
|
1186
|
-
return this.post("/admin/traffic/inbound/reset");
|
|
1187
|
-
}
|
|
1188
|
-
/**
|
|
1189
|
-
* Check health of outbound dependencies (GCP, Vertex, BigQuery, Redis).
|
|
1190
|
-
*
|
|
1191
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1192
|
-
*
|
|
1193
|
-
* **Endpoint:** `GET /v1/admin/traffic/outbound`
|
|
1194
|
-
*/
|
|
355
|
+
return this.post("/admin/traffic/inbound/reset", undefined, undefined, "admin");
|
|
356
|
+
}
|
|
1195
357
|
getOutboundStatus() {
|
|
1196
|
-
return this.get("/admin/traffic/outbound");
|
|
1197
|
-
}
|
|
1198
|
-
// -----------------------------------------------------------------------
|
|
1199
|
-
// Admin — CORS
|
|
1200
|
-
// -----------------------------------------------------------------------
|
|
1201
|
-
/**
|
|
1202
|
-
* Get the current CORS allowed origins.
|
|
1203
|
-
*
|
|
1204
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1205
|
-
*
|
|
1206
|
-
* **Endpoint:** `GET /v1/admin/cors`
|
|
1207
|
-
*/
|
|
358
|
+
return this.get("/admin/traffic/outbound", undefined, undefined, "admin");
|
|
359
|
+
}
|
|
1208
360
|
getCors() {
|
|
1209
|
-
return this.get("/admin/cors");
|
|
1210
|
-
}
|
|
1211
|
-
/**
|
|
1212
|
-
* Update the CORS allowed origins.
|
|
1213
|
-
*
|
|
1214
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1215
|
-
*
|
|
1216
|
-
* @param allowOrigins - Comma-separated origins or `"*"`.
|
|
1217
|
-
*
|
|
1218
|
-
* **Endpoint:** `PUT /v1/admin/cors`
|
|
1219
|
-
*/
|
|
361
|
+
return this.get("/admin/cors", undefined, undefined, "admin");
|
|
362
|
+
}
|
|
1220
363
|
setCors(allowOrigins) {
|
|
1221
|
-
return this.put("/admin/cors", { allow_origins: allowOrigins });
|
|
1222
|
-
}
|
|
1223
|
-
// -----------------------------------------------------------------------
|
|
1224
|
-
// Admin — Rate Limiting
|
|
1225
|
-
// -----------------------------------------------------------------------
|
|
1226
|
-
/**
|
|
1227
|
-
* List all rate-limit entries.
|
|
1228
|
-
*
|
|
1229
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1230
|
-
*
|
|
1231
|
-
* **Endpoint:** `GET /v1/admin/rate-limits`
|
|
1232
|
-
*/
|
|
364
|
+
return this.put("/admin/cors", { allow_origins: allowOrigins }, undefined, "admin");
|
|
365
|
+
}
|
|
1233
366
|
getRateLimits() {
|
|
1234
|
-
return this.get("/admin/rate-limits");
|
|
1235
|
-
}
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1240
|
-
*
|
|
1241
|
-
* @param orgId - Organization identifier.
|
|
1242
|
-
*
|
|
1243
|
-
* **Endpoint:** `POST /v1/admin/rate-limits/reset/{orgId}`
|
|
1244
|
-
*/
|
|
1245
|
-
resetRateLimit(orgId) {
|
|
1246
|
-
return this.post(`/admin/rate-limits/reset/${orgId}`);
|
|
1247
|
-
}
|
|
1248
|
-
// -----------------------------------------------------------------------
|
|
1249
|
-
// Admin — Organization & Job listing
|
|
1250
|
-
// -----------------------------------------------------------------------
|
|
1251
|
-
/**
|
|
1252
|
-
* List all organizations (admin view).
|
|
1253
|
-
*
|
|
1254
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1255
|
-
*
|
|
1256
|
-
* @param limit - Maximum number of organizations to return (1–1000, default 100).
|
|
1257
|
-
*
|
|
1258
|
-
* **Endpoint:** `GET /v1/admin/organizations`
|
|
1259
|
-
*/
|
|
1260
|
-
listOrganizations(limit) {
|
|
1261
|
-
const query = limit !== undefined ? { limit: String(limit) } : undefined;
|
|
1262
|
-
return this.get("/admin/organizations", query);
|
|
1263
|
-
}
|
|
1264
|
-
/**
|
|
1265
|
-
* Get a single organization (admin view).
|
|
1266
|
-
*
|
|
1267
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1268
|
-
*
|
|
1269
|
-
* @param orgId - Organization identifier.
|
|
1270
|
-
*
|
|
1271
|
-
* **Endpoint:** `GET /v1/admin/organizations/{orgId}`
|
|
1272
|
-
*/
|
|
1273
|
-
getAdminOrganization(orgId) {
|
|
1274
|
-
return this.get(`/admin/organizations/${orgId}`);
|
|
1275
|
-
}
|
|
1276
|
-
/**
|
|
1277
|
-
* List recent jobs across all organizations (admin view).
|
|
1278
|
-
*
|
|
1279
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1280
|
-
*
|
|
1281
|
-
* @param limit - Maximum number of jobs to return (1–500, default 50).
|
|
1282
|
-
*
|
|
1283
|
-
* **Endpoint:** `GET /v1/admin/jobs`
|
|
1284
|
-
*/
|
|
367
|
+
return this.get("/admin/rate-limits", undefined, undefined, "admin");
|
|
368
|
+
}
|
|
369
|
+
resetRateLimit(scopeId) {
|
|
370
|
+
return this.post(`/admin/rate-limits/reset/${scopeId}`, undefined, undefined, "admin");
|
|
371
|
+
}
|
|
1285
372
|
listJobs(limit) {
|
|
1286
|
-
const query = limit !== undefined ? { limit
|
|
1287
|
-
return this.get("/admin/jobs", query);
|
|
1288
|
-
}
|
|
1289
|
-
// -----------------------------------------------------------------------
|
|
1290
|
-
// Admin — Feature Flags
|
|
1291
|
-
// -----------------------------------------------------------------------
|
|
1292
|
-
/**
|
|
1293
|
-
* Get all feature flags.
|
|
1294
|
-
*
|
|
1295
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1296
|
-
*
|
|
1297
|
-
* **Endpoint:** `GET /v1/admin/feature-flags`
|
|
1298
|
-
*/
|
|
373
|
+
const query = limit !== undefined ? { limit } : undefined;
|
|
374
|
+
return this.get("/admin/jobs", query, undefined, "admin");
|
|
375
|
+
}
|
|
1299
376
|
getFeatureFlags() {
|
|
1300
|
-
return this.get("/admin/feature-flags");
|
|
1301
|
-
}
|
|
1302
|
-
/**
|
|
1303
|
-
* Get a single feature flag by key.
|
|
1304
|
-
*
|
|
1305
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1306
|
-
*
|
|
1307
|
-
* @param key - Feature flag key.
|
|
1308
|
-
*
|
|
1309
|
-
* **Endpoint:** `GET /v1/admin/feature-flags/{key}`
|
|
1310
|
-
*/
|
|
377
|
+
return this.get("/admin/feature-flags", undefined, undefined, "admin");
|
|
378
|
+
}
|
|
1311
379
|
getFeatureFlag(key) {
|
|
1312
|
-
return this.get(`/admin/feature-flags/${key}
|
|
1313
|
-
}
|
|
1314
|
-
/**
|
|
1315
|
-
* Create or update a feature flag.
|
|
1316
|
-
*
|
|
1317
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1318
|
-
*
|
|
1319
|
-
* @param params - Flag key and enabled status.
|
|
1320
|
-
*
|
|
1321
|
-
* **Endpoint:** `PUT /v1/admin/feature-flags`
|
|
1322
|
-
*/
|
|
380
|
+
return this.get(`/admin/feature-flags/${key}`, undefined, undefined, "admin");
|
|
381
|
+
}
|
|
1323
382
|
setFeatureFlag(params) {
|
|
1324
|
-
return this.put("/admin/feature-flags", params);
|
|
1325
|
-
}
|
|
1326
|
-
/**
|
|
1327
|
-
* Delete a feature flag.
|
|
1328
|
-
*
|
|
1329
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1330
|
-
*
|
|
1331
|
-
* @param key - Feature flag key to delete.
|
|
1332
|
-
*
|
|
1333
|
-
* **Endpoint:** `DELETE /v1/admin/feature-flags/{key}`
|
|
1334
|
-
*/
|
|
383
|
+
return this.put("/admin/feature-flags", params, undefined, "admin");
|
|
384
|
+
}
|
|
1335
385
|
deleteFeatureFlag(key) {
|
|
1336
|
-
return this.del(`/admin/feature-flags/${key}
|
|
1337
|
-
}
|
|
1338
|
-
// -----------------------------------------------------------------------
|
|
1339
|
-
// Admin — Maintenance Mode
|
|
1340
|
-
// -----------------------------------------------------------------------
|
|
1341
|
-
/**
|
|
1342
|
-
* Get current maintenance mode state.
|
|
1343
|
-
*
|
|
1344
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1345
|
-
*
|
|
1346
|
-
* **Endpoint:** `GET /v1/admin/maintenance`
|
|
1347
|
-
*/
|
|
386
|
+
return this.del(`/admin/feature-flags/${key}`, undefined, "admin");
|
|
387
|
+
}
|
|
1348
388
|
getMaintenanceMode() {
|
|
1349
|
-
return this.get("/admin/maintenance");
|
|
1350
|
-
}
|
|
1351
|
-
/**
|
|
1352
|
-
* Enable or disable maintenance mode.
|
|
1353
|
-
*
|
|
1354
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1355
|
-
*
|
|
1356
|
-
* @param params - Enabled flag and optional message.
|
|
1357
|
-
*
|
|
1358
|
-
* **Endpoint:** `PUT /v1/admin/maintenance`
|
|
1359
|
-
*/
|
|
389
|
+
return this.get("/admin/maintenance", undefined, undefined, "admin");
|
|
390
|
+
}
|
|
1360
391
|
setMaintenanceMode(params) {
|
|
1361
|
-
return this.put("/admin/maintenance", params);
|
|
1362
|
-
}
|
|
1363
|
-
// -----------------------------------------------------------------------
|
|
1364
|
-
// Admin — Cache
|
|
1365
|
-
// -----------------------------------------------------------------------
|
|
1366
|
-
/**
|
|
1367
|
-
* Get cache statistics.
|
|
1368
|
-
*
|
|
1369
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1370
|
-
*
|
|
1371
|
-
* **Endpoint:** `GET /v1/admin/cache`
|
|
1372
|
-
*/
|
|
392
|
+
return this.put("/admin/maintenance", params, undefined, "admin");
|
|
393
|
+
}
|
|
1373
394
|
getCacheStats() {
|
|
1374
|
-
return this.get("/admin/cache");
|
|
1375
|
-
}
|
|
1376
|
-
/**
|
|
1377
|
-
* Flush all caches.
|
|
1378
|
-
*
|
|
1379
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1380
|
-
*
|
|
1381
|
-
* **Endpoint:** `POST /v1/admin/cache/flush`
|
|
1382
|
-
*/
|
|
395
|
+
return this.get("/admin/cache", undefined, undefined, "admin");
|
|
396
|
+
}
|
|
1383
397
|
flushCache() {
|
|
1384
|
-
return this.post("/admin/cache/flush");
|
|
1385
|
-
}
|
|
1386
|
-
// -----------------------------------------------------------------------
|
|
1387
|
-
// Admin — Tiers & Pricing
|
|
1388
|
-
// -----------------------------------------------------------------------
|
|
1389
|
-
/**
|
|
1390
|
-
* Get all tier configurations.
|
|
1391
|
-
*
|
|
1392
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1393
|
-
*
|
|
1394
|
-
* **Endpoint:** `GET /v1/admin/tiers`
|
|
1395
|
-
*/
|
|
1396
|
-
getTiers() {
|
|
1397
|
-
return this.get("/admin/tiers");
|
|
1398
|
-
}
|
|
1399
|
-
/**
|
|
1400
|
-
* Get current pricing configuration.
|
|
1401
|
-
*
|
|
1402
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1403
|
-
*
|
|
1404
|
-
* **Endpoint:** `GET /v1/admin/pricing`
|
|
1405
|
-
*/
|
|
1406
|
-
getPricing() {
|
|
1407
|
-
return this.get("/admin/pricing");
|
|
1408
|
-
}
|
|
1409
|
-
// -----------------------------------------------------------------------
|
|
1410
|
-
// Admin — Audit & System
|
|
1411
|
-
// -----------------------------------------------------------------------
|
|
1412
|
-
/**
|
|
1413
|
-
* Get admin-level audit log entries.
|
|
1414
|
-
*
|
|
1415
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1416
|
-
*
|
|
1417
|
-
* @param limit - Maximum entries to return (1–1000, default 100).
|
|
1418
|
-
*
|
|
1419
|
-
* **Endpoint:** `GET /v1/admin/audit`
|
|
1420
|
-
*/
|
|
398
|
+
return this.post("/admin/cache/flush", undefined, undefined, "admin");
|
|
399
|
+
}
|
|
1421
400
|
getAdminAudit(limit) {
|
|
1422
|
-
const query = limit !== undefined ? { limit
|
|
1423
|
-
return this.get("/admin/audit", query);
|
|
1424
|
-
}
|
|
1425
|
-
/**
|
|
1426
|
-
* Get system information (Python version, platform, architecture, PID, etc.).
|
|
1427
|
-
*
|
|
1428
|
-
* **Auth:** Requires `adminKey` in client config.
|
|
1429
|
-
*
|
|
1430
|
-
* **Endpoint:** `GET /v1/admin/system`
|
|
1431
|
-
*/
|
|
401
|
+
const query = limit !== undefined ? { limit } : undefined;
|
|
402
|
+
return this.get("/admin/audit", query, undefined, "admin");
|
|
403
|
+
}
|
|
1432
404
|
getSystemInfo() {
|
|
1433
|
-
return this.get("/admin/system");
|
|
1434
|
-
}
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
*
|
|
1448
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/integrations/jira/connect`
|
|
1449
|
-
*/
|
|
1450
|
-
connectJira(orgId, params, options) {
|
|
1451
|
-
return this.post(`/organizations/${orgId}/integrations/jira/connect`, params, options);
|
|
1452
|
-
}
|
|
1453
|
-
/**
|
|
1454
|
-
* Get the current Jira integration status for an organization.
|
|
1455
|
-
*
|
|
1456
|
-
* **Auth:** Requires org-scoped API key.
|
|
1457
|
-
*
|
|
1458
|
-
* @param orgId - Organization identifier.
|
|
1459
|
-
* @param options - Optional per-request overrides.
|
|
1460
|
-
*
|
|
1461
|
-
* **Endpoint:** `GET /v1/organizations/{orgId}/integrations/jira/status`
|
|
1462
|
-
*/
|
|
1463
|
-
getJiraStatus(orgId, options) {
|
|
1464
|
-
return this.get(`/organizations/${orgId}/integrations/jira/status`, undefined, options);
|
|
1465
|
-
}
|
|
1466
|
-
/**
|
|
1467
|
-
* Disconnect (unlink) an organization's Jira integration.
|
|
1468
|
-
* Deregisters the webhook and deletes stored credentials.
|
|
1469
|
-
*
|
|
1470
|
-
* **Auth:** Requires org-scoped API key.
|
|
1471
|
-
*
|
|
1472
|
-
* @param orgId - Organization identifier.
|
|
1473
|
-
* @param options - Optional per-request overrides.
|
|
1474
|
-
*
|
|
1475
|
-
* **Endpoint:** `DELETE /v1/organizations/{orgId}/integrations/jira`
|
|
1476
|
-
*/
|
|
1477
|
-
disconnectJira(orgId, options) {
|
|
1478
|
-
return this.del(`/organizations/${orgId}/integrations/jira`, options);
|
|
1479
|
-
}
|
|
1480
|
-
/**
|
|
1481
|
-
* Trigger a bulk sync of Jira issues from specified projects into the
|
|
1482
|
-
* document store for RAG retrieval.
|
|
1483
|
-
*
|
|
1484
|
-
* **Auth:** Requires org-scoped API key.
|
|
1485
|
-
*
|
|
1486
|
-
* @param orgId - Organization identifier.
|
|
1487
|
-
* @param params - Object containing `project_keys` array.
|
|
1488
|
-
* @param options - Optional per-request overrides.
|
|
1489
|
-
*
|
|
1490
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/integrations/jira/sync`
|
|
1491
|
-
*/
|
|
1492
|
-
syncJira(orgId, params, options) {
|
|
1493
|
-
return this.post(`/organizations/${orgId}/integrations/jira/sync`, params, options);
|
|
1494
|
-
}
|
|
1495
|
-
/**
|
|
1496
|
-
* Send a Jira webhook event manually.
|
|
1497
|
-
*
|
|
1498
|
-
* **Auth:** Requires `webhookSecret` in client config.
|
|
1499
|
-
*
|
|
1500
|
-
* @param payload - Jira webhook payload (issue, webhookEvent, etc.).
|
|
1501
|
-
*
|
|
1502
|
-
* **Endpoint:** `POST /v1/webhook/jira`
|
|
1503
|
-
*/
|
|
405
|
+
return this.get("/admin/system", undefined, undefined, "admin");
|
|
406
|
+
}
|
|
407
|
+
connectJira(params, options) {
|
|
408
|
+
return this.post("/integrations/jira/connect", params, options);
|
|
409
|
+
}
|
|
410
|
+
getJiraStatus(options) {
|
|
411
|
+
return this.get("/integrations/jira/status", undefined, options);
|
|
412
|
+
}
|
|
413
|
+
disconnectJira(options) {
|
|
414
|
+
return this.del("/integrations/jira", options);
|
|
415
|
+
}
|
|
416
|
+
syncJira(params, options) {
|
|
417
|
+
return this.post("/integrations/jira/sync", params, options);
|
|
418
|
+
}
|
|
1504
419
|
sendJiraWebhook(payload) {
|
|
1505
|
-
return this.post("/webhook/jira", payload);
|
|
1506
|
-
}
|
|
1507
|
-
// ---------------------------------------------------------------------------
|
|
1508
|
-
// Blueprint Management
|
|
1509
|
-
// ---------------------------------------------------------------------------
|
|
1510
|
-
/**
|
|
1511
|
-
* Create a new document blueprint (template).
|
|
1512
|
-
*
|
|
1513
|
-
* **Auth:** Requires org-scoped API key.
|
|
1514
|
-
*
|
|
1515
|
-
* @param orgId - Organization ID.
|
|
1516
|
-
* @param params - Blueprint details (name, sections, workflow_config, etc.).
|
|
1517
|
-
*
|
|
1518
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/blueprints`
|
|
1519
|
-
*/
|
|
1520
|
-
createBlueprint(orgId, params, options) {
|
|
1521
|
-
return this.post(`/organizations/${orgId}/blueprints`, params, options);
|
|
1522
|
-
}
|
|
1523
|
-
/**
|
|
1524
|
-
* List all blueprints for an organization.
|
|
1525
|
-
*
|
|
1526
|
-
* **Auth:** Requires org-scoped API key.
|
|
1527
|
-
*
|
|
1528
|
-
* @param orgId - Organization ID.
|
|
1529
|
-
*
|
|
1530
|
-
* **Endpoint:** `GET /v1/organizations/{orgId}/blueprints`
|
|
1531
|
-
*/
|
|
1532
|
-
listBlueprints(orgId, options) {
|
|
1533
|
-
return this.get(`/organizations/${orgId}/blueprints`, undefined, options);
|
|
1534
|
-
}
|
|
1535
|
-
/**
|
|
1536
|
-
* Get a single blueprint by ID.
|
|
1537
|
-
*
|
|
1538
|
-
* **Auth:** Requires org-scoped API key.
|
|
1539
|
-
*
|
|
1540
|
-
* @param orgId - Organization ID.
|
|
1541
|
-
* @param blueprintId - Blueprint ID.
|
|
1542
|
-
*
|
|
1543
|
-
* **Endpoint:** `GET /v1/organizations/{orgId}/blueprints/{blueprintId}`
|
|
1544
|
-
*/
|
|
1545
|
-
getBlueprint(orgId, blueprintId, options) {
|
|
1546
|
-
return this.get(`/organizations/${orgId}/blueprints/${blueprintId}`, undefined, options);
|
|
1547
|
-
}
|
|
1548
|
-
/**
|
|
1549
|
-
* Update an existing blueprint. Only provided fields are changed.
|
|
1550
|
-
*
|
|
1551
|
-
* **Auth:** Requires org-scoped API key.
|
|
1552
|
-
*
|
|
1553
|
-
* @param orgId - Organization ID.
|
|
1554
|
-
* @param blueprintId - Blueprint ID.
|
|
1555
|
-
* @param params - Fields to update.
|
|
1556
|
-
*
|
|
1557
|
-
* **Endpoint:** `PUT /v1/organizations/{orgId}/blueprints/{blueprintId}`
|
|
1558
|
-
*/
|
|
1559
|
-
updateBlueprint(orgId, blueprintId, params, options) {
|
|
1560
|
-
return this.put(`/organizations/${orgId}/blueprints/${blueprintId}`, params, options);
|
|
1561
|
-
}
|
|
1562
|
-
/**
|
|
1563
|
-
* Publish a blueprint, making it available for document creation.
|
|
1564
|
-
*
|
|
1565
|
-
* **Auth:** Requires org-scoped API key.
|
|
1566
|
-
*
|
|
1567
|
-
* @param orgId - Organization ID.
|
|
1568
|
-
* @param blueprintId - Blueprint ID.
|
|
1569
|
-
*
|
|
1570
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/blueprints/{blueprintId}/publish`
|
|
1571
|
-
*/
|
|
1572
|
-
publishBlueprint(orgId, blueprintId, options) {
|
|
1573
|
-
return this.post(`/organizations/${orgId}/blueprints/${blueprintId}/publish`, {}, options);
|
|
1574
|
-
}
|
|
1575
|
-
/**
|
|
1576
|
-
* Archive a blueprint, preventing new documents from being created from it.
|
|
1577
|
-
*
|
|
1578
|
-
* **Auth:** Requires org-scoped API key.
|
|
1579
|
-
*
|
|
1580
|
-
* @param orgId - Organization ID.
|
|
1581
|
-
* @param blueprintId - Blueprint ID.
|
|
1582
|
-
*
|
|
1583
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/blueprints/{blueprintId}/archive`
|
|
1584
|
-
*/
|
|
1585
|
-
archiveBlueprint(orgId, blueprintId, options) {
|
|
1586
|
-
return this.post(`/organizations/${orgId}/blueprints/${blueprintId}/archive`, {}, options);
|
|
1587
|
-
}
|
|
1588
|
-
/**
|
|
1589
|
-
* Permanently delete a blueprint.
|
|
1590
|
-
*
|
|
1591
|
-
* **Auth:** Requires org-scoped API key.
|
|
1592
|
-
*
|
|
1593
|
-
* @param orgId - Organization ID.
|
|
1594
|
-
* @param blueprintId - Blueprint ID.
|
|
1595
|
-
*
|
|
1596
|
-
* **Endpoint:** `DELETE /v1/organizations/{orgId}/blueprints/{blueprintId}`
|
|
1597
|
-
*/
|
|
1598
|
-
deleteBlueprint(orgId, blueprintId, options) {
|
|
1599
|
-
return this.del(`/organizations/${orgId}/blueprints/${blueprintId}`, options);
|
|
1600
|
-
}
|
|
1601
|
-
// ---------------------------------------------------------------------------
|
|
1602
|
-
// Managed Documents
|
|
1603
|
-
// ---------------------------------------------------------------------------
|
|
1604
|
-
/**
|
|
1605
|
-
* Create a new managed document from a published blueprint.
|
|
1606
|
-
*
|
|
1607
|
-
* **Auth:** Requires org-scoped API key.
|
|
1608
|
-
*
|
|
1609
|
-
* @param orgId - Organization ID.
|
|
1610
|
-
* @param params - Document details (blueprint_id, title, sections, etc.).
|
|
1611
|
-
*
|
|
1612
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/documents/create`
|
|
1613
|
-
*/
|
|
1614
|
-
createDocumentFromBlueprint(orgId, params, options) {
|
|
1615
|
-
return this.post(`/organizations/${orgId}/documents/create`, params, options);
|
|
1616
|
-
}
|
|
1617
|
-
/**
|
|
1618
|
-
* List all managed documents for an organization.
|
|
1619
|
-
*
|
|
1620
|
-
* **Auth:** Requires org-scoped API key.
|
|
1621
|
-
*
|
|
1622
|
-
* @param orgId - Organization ID.
|
|
1623
|
-
*
|
|
1624
|
-
* **Endpoint:** `GET /v1/organizations/{orgId}/documents/managed`
|
|
1625
|
-
*/
|
|
1626
|
-
listManagedDocuments(orgId, options) {
|
|
1627
|
-
return this.get(`/organizations/${orgId}/documents/managed`, undefined, options);
|
|
1628
|
-
}
|
|
1629
|
-
/**
|
|
1630
|
-
* Get a single managed document by ID.
|
|
1631
|
-
*
|
|
1632
|
-
* **Auth:** Requires org-scoped API key.
|
|
1633
|
-
*
|
|
1634
|
-
* @param orgId - Organization ID.
|
|
1635
|
-
* @param documentId - Document ID.
|
|
1636
|
-
*
|
|
1637
|
-
* **Endpoint:** `GET /v1/organizations/{orgId}/documents/managed/{documentId}`
|
|
1638
|
-
*/
|
|
1639
|
-
getManagedDocument(orgId, documentId, options) {
|
|
1640
|
-
return this.get(`/organizations/${orgId}/documents/managed/${documentId}`, undefined, options);
|
|
1641
|
-
}
|
|
1642
|
-
/**
|
|
1643
|
-
* Update the content of a document section. Only allowed in draft/revision status.
|
|
1644
|
-
*
|
|
1645
|
-
* **Auth:** Requires org-scoped API key.
|
|
1646
|
-
*
|
|
1647
|
-
* @param orgId - Organization ID.
|
|
1648
|
-
* @param documentId - Document ID.
|
|
1649
|
-
* @param params - Section ID and new content.
|
|
1650
|
-
*
|
|
1651
|
-
* **Endpoint:** `PATCH /v1/organizations/{orgId}/documents/managed/{documentId}/sections`
|
|
1652
|
-
*/
|
|
1653
|
-
updateDocumentSection(orgId, documentId, params, options) {
|
|
1654
|
-
return this.patch(`/organizations/${orgId}/documents/managed/${documentId}/sections`, params, options);
|
|
1655
|
-
}
|
|
1656
|
-
/**
|
|
1657
|
-
* Perform a workflow action on a managed document.
|
|
1658
|
-
*
|
|
1659
|
-
* Actions: submit, approve, reject, request_changes, seal.
|
|
1660
|
-
*
|
|
1661
|
-
* **Auth:** Requires org-scoped API key.
|
|
1662
|
-
*
|
|
1663
|
-
* @param orgId - Organization ID.
|
|
1664
|
-
* @param documentId - Document ID.
|
|
1665
|
-
* @param params - Action type and optional comment.
|
|
1666
|
-
*
|
|
1667
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/documents/managed/{documentId}/workflow`
|
|
1668
|
-
*/
|
|
1669
|
-
performDocumentWorkflow(orgId, documentId, params, options) {
|
|
1670
|
-
return this.post(`/organizations/${orgId}/documents/managed/${documentId}/workflow`, params, options);
|
|
1671
|
-
}
|
|
1672
|
-
/**
|
|
1673
|
-
* Permanently delete a managed document.
|
|
1674
|
-
*
|
|
1675
|
-
* **Auth:** Requires org-scoped API key.
|
|
1676
|
-
*
|
|
1677
|
-
* @param orgId - Organization ID.
|
|
1678
|
-
* @param documentId - Document ID.
|
|
1679
|
-
*
|
|
1680
|
-
* **Endpoint:** `DELETE /v1/organizations/{orgId}/documents/managed/{documentId}`
|
|
1681
|
-
*/
|
|
1682
|
-
deleteManagedDocument(orgId, documentId, options) {
|
|
1683
|
-
return this.del(`/organizations/${orgId}/documents/managed/${documentId}`, options);
|
|
1684
|
-
}
|
|
1685
|
-
/**
|
|
1686
|
-
* AI-generate content for a document section using the blueprint's AI rules.
|
|
1687
|
-
*
|
|
1688
|
-
* **Auth:** Requires org-scoped API key.
|
|
1689
|
-
*
|
|
1690
|
-
* @param orgId - Organization ID.
|
|
1691
|
-
* @param documentId - Document ID.
|
|
1692
|
-
* @param params - Section ID and optional context for generation.
|
|
1693
|
-
*
|
|
1694
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/documents/managed/{documentId}/generate`
|
|
1695
|
-
*/
|
|
1696
|
-
generateDocumentSection(orgId, documentId, params, options) {
|
|
1697
|
-
return this.post(`/organizations/${orgId}/documents/managed/${documentId}/generate`, params, options);
|
|
1698
|
-
}
|
|
1699
|
-
// -----------------------------------------------------------------------
|
|
1700
|
-
// Streaming — SSE
|
|
1701
|
-
// -----------------------------------------------------------------------
|
|
1702
|
-
/**
|
|
1703
|
-
* Chat inside a content project using Server-Sent Events.
|
|
1704
|
-
* Returns an async iterator of typed {@link ChatStreamEvent} objects.
|
|
1705
|
-
*
|
|
1706
|
-
* **Auth:** Requires org-scoped API key.
|
|
1707
|
-
*
|
|
1708
|
-
* **Endpoint:** `POST /v1/organizations/{orgId}/projects/{projectId}/chat/stream`
|
|
1709
|
-
*
|
|
1710
|
-
* @example
|
|
1711
|
-
* ```typescript
|
|
1712
|
-
* for await (const evt of client.chatProjectSse("acme", "proj-1", {
|
|
1713
|
-
* message: "Summarize our sources",
|
|
1714
|
-
* user_id: "u1",
|
|
1715
|
-
* })) {
|
|
1716
|
-
* if (evt.event === "done") console.log(evt.data.answer);
|
|
1717
|
-
* }
|
|
1718
|
-
* ```
|
|
1719
|
-
*/
|
|
1720
|
-
async *chatProjectSse(orgId, projectId, params, options) {
|
|
1721
|
-
const url = new URL(`${this.prefix}/organizations/${orgId}/projects/${projectId}/chat/stream`, this.baseUrl);
|
|
1722
|
-
const headers = {
|
|
1723
|
-
"Content-Type": "application/json",
|
|
1724
|
-
Accept: "text/event-stream",
|
|
1725
|
-
};
|
|
1726
|
-
const apiKey = options?.apiKey ?? this.config.apiKey;
|
|
1727
|
-
if (apiKey)
|
|
1728
|
-
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
1729
|
-
if (this.config.adminKey)
|
|
1730
|
-
headers["X-Admin-Key"] = this.config.adminKey;
|
|
1731
|
-
if (this.config.employeeId)
|
|
1732
|
-
headers["X-Employee-Id"] = this.config.employeeId;
|
|
1733
|
-
const res = await fetch(url.toString(), {
|
|
1734
|
-
method: "POST",
|
|
1735
|
-
headers,
|
|
1736
|
-
body: JSON.stringify(params),
|
|
1737
|
-
});
|
|
1738
|
-
if (!res.ok || !res.body) {
|
|
1739
|
-
const text = await res.text();
|
|
1740
|
-
let detail;
|
|
1741
|
-
try {
|
|
1742
|
-
detail = JSON.parse(text);
|
|
1743
|
-
}
|
|
1744
|
-
catch {
|
|
1745
|
-
detail = text;
|
|
1746
|
-
}
|
|
1747
|
-
throw new HivemindError(res.status, detail);
|
|
1748
|
-
}
|
|
1749
|
-
const { parseSseStream } = await Promise.resolve().then(() => __importStar(require("./sse")));
|
|
1750
|
-
for await (const raw of parseSseStream(res.body)) {
|
|
1751
|
-
let data;
|
|
1752
|
-
try {
|
|
1753
|
-
data = JSON.parse(raw.data);
|
|
1754
|
-
}
|
|
1755
|
-
catch {
|
|
1756
|
-
data = raw.data;
|
|
1757
|
-
}
|
|
1758
|
-
yield { event: raw.event, data };
|
|
1759
|
-
}
|
|
420
|
+
return this.post("/webhook/jira", payload, undefined, "webhook");
|
|
1760
421
|
}
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
return {
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
422
|
+
createBlueprint(params, options) {
|
|
423
|
+
return this.post("/blueprints", params, options);
|
|
424
|
+
}
|
|
425
|
+
listBlueprints(options) {
|
|
426
|
+
return this.get("/blueprints", undefined, options);
|
|
427
|
+
}
|
|
428
|
+
getBlueprint(blueprintId, options) {
|
|
429
|
+
return this.get(`/blueprints/${blueprintId}`, undefined, options);
|
|
430
|
+
}
|
|
431
|
+
updateBlueprint(blueprintId, params, options) {
|
|
432
|
+
return this.put(`/blueprints/${blueprintId}`, params, options);
|
|
433
|
+
}
|
|
434
|
+
publishBlueprint(blueprintId, options) {
|
|
435
|
+
return this.post(`/blueprints/${blueprintId}/publish`, {}, options);
|
|
436
|
+
}
|
|
437
|
+
archiveBlueprint(blueprintId, options) {
|
|
438
|
+
return this.post(`/blueprints/${blueprintId}/archive`, {}, options);
|
|
439
|
+
}
|
|
440
|
+
deleteBlueprint(blueprintId, options) {
|
|
441
|
+
return this.del(`/blueprints/${blueprintId}`, options);
|
|
442
|
+
}
|
|
443
|
+
createDocumentFromBlueprint(params, options) {
|
|
444
|
+
return this.post("/documents/create", params, options);
|
|
445
|
+
}
|
|
446
|
+
listManagedDocuments(options) {
|
|
447
|
+
return this.get("/documents/managed", undefined, options);
|
|
448
|
+
}
|
|
449
|
+
getManagedDocument(documentId, options) {
|
|
450
|
+
return this.get(`/documents/managed/${documentId}`, undefined, options);
|
|
451
|
+
}
|
|
452
|
+
updateDocumentSection(documentId, params, options) {
|
|
453
|
+
return this.patch(`/documents/managed/${documentId}/sections`, params, options);
|
|
454
|
+
}
|
|
455
|
+
performDocumentWorkflow(documentId, params, options) {
|
|
456
|
+
return this.post(`/documents/managed/${documentId}/workflow`, params, options);
|
|
457
|
+
}
|
|
458
|
+
deleteManagedDocument(documentId, options) {
|
|
459
|
+
return this.del(`/documents/managed/${documentId}`, options);
|
|
460
|
+
}
|
|
461
|
+
generateDocumentSection(documentId, params, options) {
|
|
462
|
+
return this.post(`/documents/managed/${documentId}/generate`, params, options);
|
|
1801
463
|
}
|
|
1802
464
|
}
|
|
1803
465
|
exports.HivemindClient = HivemindClient;
|