@prisme.ai/sdk 1.0.2 → 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 +250 -0
- package/dist/index.d.mts +1129 -0
- package/dist/index.d.ts +1129 -7
- package/dist/index.js +1326 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1287 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +50 -12
- package/Readme.md +0 -28
- package/dist/_virtual/_tslib.js +0 -116
- package/dist/lib/ApiError.d.ts +0 -8
- package/dist/lib/ApiError.test.d.ts +0 -1
- package/dist/lib/HTTPError.d.ts +0 -6
- package/dist/lib/HTTPError.test.d.ts +0 -1
- package/dist/lib/ImportProcessing.d.ts +0 -19
- package/dist/lib/WorkspacesEndpoint.d.ts +0 -10
- package/dist/lib/api.d.ts +0 -155
- package/dist/lib/api.test.d.ts +0 -1
- package/dist/lib/endpoints/users.d.ts +0 -13
- package/dist/lib/endpoints/workspaces.d.ts +0 -25
- package/dist/lib/endpoints/workspacesVersions.d.ts +0 -10
- package/dist/lib/events.d.ts +0 -40
- package/dist/lib/events.test.d.ts +0 -1
- package/dist/lib/fetch.d.ts +0 -2
- package/dist/lib/fetcher.d.ts +0 -24
- package/dist/lib/fetcher.test.d.ts +0 -1
- package/dist/lib/interpolate.d.ts +0 -2
- package/dist/lib/interpolate.test.d.ts +0 -1
- package/dist/lib/interpolateVars.d.ts +0 -2
- package/dist/lib/types.d.ts +0 -17
- package/dist/lib/utils.d.ts +0 -4
- package/dist/lib/utils.test.d.ts +0 -1
- package/dist/sdk/index.js +0 -19
- package/dist/sdk/lib/ApiError.js +0 -24
- package/dist/sdk/lib/HTTPError.js +0 -21
- package/dist/sdk/lib/ImportProcessing.js +0 -17
- package/dist/sdk/lib/WorkspacesEndpoint.js +0 -19
- package/dist/sdk/lib/api.js +0 -1018
- package/dist/sdk/lib/endpoints/users.js +0 -94
- package/dist/sdk/lib/endpoints/workspaces.js +0 -144
- package/dist/sdk/lib/endpoints/workspacesVersions.js +0 -40
- package/dist/sdk/lib/events.js +0 -169
- package/dist/sdk/lib/fetch.js +0 -12
- package/dist/sdk/lib/fetcher.js +0 -213
- package/dist/sdk/lib/interpolate.js +0 -26
- package/dist/sdk/lib/interpolateVars.js +0 -26
- package/dist/sdk/lib/utils.js +0 -65
- package/index.ts +0 -7
- package/lib/ApiError.test.ts +0 -13
- package/lib/ApiError.ts +0 -21
- package/lib/HTTPError.test.ts +0 -8
- package/lib/HTTPError.ts +0 -13
- package/lib/ImportProcessing.ts +0 -22
- package/lib/api.test.ts +0 -787
- package/lib/api.ts +0 -949
- package/lib/endpoints/users.ts +0 -58
- package/lib/endpoints/workspaces.ts +0 -121
- package/lib/endpoints/workspacesVersions.ts +0 -38
- package/lib/events.test.ts +0 -89
- package/lib/events.ts +0 -222
- package/lib/fetcher.test.ts +0 -246
- package/lib/fetcher.ts +0 -198
- package/lib/types.ts +0 -21
- package/lib/utils.test.ts +0 -38
- package/lib/utils.ts +0 -51
- package/tsconfig.json +0 -21
package/dist/index.js
ADDED
|
@@ -0,0 +1,1326 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AuthenticationError: () => AuthenticationError,
|
|
24
|
+
ConflictError: () => ConflictError,
|
|
25
|
+
ConnectionError: () => ConnectionError,
|
|
26
|
+
InternalServerError: () => InternalServerError,
|
|
27
|
+
NotFoundError: () => NotFoundError,
|
|
28
|
+
PageIterator: () => PageIterator,
|
|
29
|
+
PermissionDeniedError: () => PermissionDeniedError,
|
|
30
|
+
PrismeAI: () => PrismeAI,
|
|
31
|
+
PrismeAIError: () => PrismeAIError,
|
|
32
|
+
RateLimitError: () => RateLimitError,
|
|
33
|
+
SSEStream: () => SSEStream,
|
|
34
|
+
TimeoutError: () => TimeoutError,
|
|
35
|
+
ValidationError: () => ValidationError
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
|
|
39
|
+
// src/core/errors.ts
|
|
40
|
+
var PrismeAIError = class extends Error {
|
|
41
|
+
status;
|
|
42
|
+
headers;
|
|
43
|
+
body;
|
|
44
|
+
constructor(message, { status, headers, body } = {}) {
|
|
45
|
+
super(message);
|
|
46
|
+
this.name = "PrismeAIError";
|
|
47
|
+
this.status = status;
|
|
48
|
+
this.headers = headers;
|
|
49
|
+
this.body = body;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var AuthenticationError = class extends PrismeAIError {
|
|
53
|
+
status = 401;
|
|
54
|
+
constructor(message, opts) {
|
|
55
|
+
super(message, { status: 401, ...opts });
|
|
56
|
+
this.name = "AuthenticationError";
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var PermissionDeniedError = class extends PrismeAIError {
|
|
60
|
+
status = 403;
|
|
61
|
+
constructor(message, opts) {
|
|
62
|
+
super(message, { status: 403, ...opts });
|
|
63
|
+
this.name = "PermissionDeniedError";
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var NotFoundError = class extends PrismeAIError {
|
|
67
|
+
status = 404;
|
|
68
|
+
constructor(message, opts) {
|
|
69
|
+
super(message, { status: 404, ...opts });
|
|
70
|
+
this.name = "NotFoundError";
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
var ConflictError = class extends PrismeAIError {
|
|
74
|
+
status = 409;
|
|
75
|
+
constructor(message, opts) {
|
|
76
|
+
super(message, { status: 409, ...opts });
|
|
77
|
+
this.name = "ConflictError";
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
var ValidationError = class extends PrismeAIError {
|
|
81
|
+
status = 422;
|
|
82
|
+
constructor(message, opts) {
|
|
83
|
+
super(message, { status: 422, ...opts });
|
|
84
|
+
this.name = "ValidationError";
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
var RateLimitError = class extends PrismeAIError {
|
|
88
|
+
status = 429;
|
|
89
|
+
retryAfter;
|
|
90
|
+
constructor(message, opts) {
|
|
91
|
+
super(message, { status: 429, ...opts });
|
|
92
|
+
this.name = "RateLimitError";
|
|
93
|
+
this.retryAfter = opts?.headers ? parseRetryAfter(opts.headers.get("retry-after")) : void 0;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
var InternalServerError = class extends PrismeAIError {
|
|
97
|
+
status = 500;
|
|
98
|
+
constructor(message, opts) {
|
|
99
|
+
super(message, { status: 500, ...opts });
|
|
100
|
+
this.name = "InternalServerError";
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
var ConnectionError = class extends PrismeAIError {
|
|
104
|
+
constructor(message) {
|
|
105
|
+
super(message);
|
|
106
|
+
this.name = "ConnectionError";
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
var TimeoutError = class extends PrismeAIError {
|
|
110
|
+
constructor(message) {
|
|
111
|
+
super(message);
|
|
112
|
+
this.name = "TimeoutError";
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
function parseRetryAfter(value) {
|
|
116
|
+
if (!value) return void 0;
|
|
117
|
+
const seconds = Number(value);
|
|
118
|
+
if (!Number.isNaN(seconds)) return seconds * 1e3;
|
|
119
|
+
const date = Date.parse(value);
|
|
120
|
+
if (!Number.isNaN(date)) return date - Date.now();
|
|
121
|
+
return void 0;
|
|
122
|
+
}
|
|
123
|
+
function errorFromStatus(status, message, headers, body) {
|
|
124
|
+
const opts = { headers, body };
|
|
125
|
+
switch (status) {
|
|
126
|
+
case 401:
|
|
127
|
+
return new AuthenticationError(message, opts);
|
|
128
|
+
case 403:
|
|
129
|
+
return new PermissionDeniedError(message, opts);
|
|
130
|
+
case 404:
|
|
131
|
+
return new NotFoundError(message, opts);
|
|
132
|
+
case 409:
|
|
133
|
+
return new ConflictError(message, opts);
|
|
134
|
+
case 422:
|
|
135
|
+
return new ValidationError(message, opts);
|
|
136
|
+
case 429:
|
|
137
|
+
return new RateLimitError(message, opts);
|
|
138
|
+
default:
|
|
139
|
+
if (status >= 500) return new InternalServerError(message, opts);
|
|
140
|
+
return new PrismeAIError(message, { status, ...opts });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/core/http-client.ts
|
|
145
|
+
var DEFAULT_TIMEOUT = 6e4;
|
|
146
|
+
var DEFAULT_MAX_RETRIES = 2;
|
|
147
|
+
var RETRY_STATUS_CODES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
|
|
148
|
+
var INITIAL_RETRY_DELAY = 500;
|
|
149
|
+
var MAX_RETRY_DELAY = 8e3;
|
|
150
|
+
var HttpClient = class {
|
|
151
|
+
baseURL;
|
|
152
|
+
defaultHeaders;
|
|
153
|
+
timeout;
|
|
154
|
+
maxRetries;
|
|
155
|
+
constructor(options) {
|
|
156
|
+
this.baseURL = options.baseURL.replace(/\/+$/, "");
|
|
157
|
+
this.defaultHeaders = options.headers;
|
|
158
|
+
this.timeout = options.timeout ?? DEFAULT_TIMEOUT;
|
|
159
|
+
this.maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
160
|
+
}
|
|
161
|
+
async request(options) {
|
|
162
|
+
const url = this.buildURL(options.path, options.query);
|
|
163
|
+
const headers = {
|
|
164
|
+
...this.defaultHeaders,
|
|
165
|
+
...options.headers
|
|
166
|
+
};
|
|
167
|
+
if (options.body !== void 0 && !headers["content-type"]) {
|
|
168
|
+
headers["content-type"] = "application/json";
|
|
169
|
+
}
|
|
170
|
+
const fetchOptions = {
|
|
171
|
+
method: options.method,
|
|
172
|
+
headers,
|
|
173
|
+
signal: options.signal
|
|
174
|
+
};
|
|
175
|
+
if (options.body !== void 0) {
|
|
176
|
+
if (options.body instanceof FormData) {
|
|
177
|
+
delete headers["content-type"];
|
|
178
|
+
fetchOptions.body = options.body;
|
|
179
|
+
} else {
|
|
180
|
+
fetchOptions.body = JSON.stringify(options.body);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const timeout = options.timeout ?? this.timeout;
|
|
184
|
+
let lastError;
|
|
185
|
+
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
186
|
+
if (attempt > 0) {
|
|
187
|
+
const delay = this.getRetryDelay(attempt, lastError);
|
|
188
|
+
await sleep(delay);
|
|
189
|
+
}
|
|
190
|
+
const controller = new AbortController();
|
|
191
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
192
|
+
if (options.signal) {
|
|
193
|
+
options.signal.addEventListener("abort", () => controller.abort(), { once: true });
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
const response = await fetch(url, {
|
|
197
|
+
...fetchOptions,
|
|
198
|
+
signal: controller.signal
|
|
199
|
+
});
|
|
200
|
+
clearTimeout(timeoutId);
|
|
201
|
+
if (response.ok) {
|
|
202
|
+
if (options.raw) return response;
|
|
203
|
+
const text = await response.text();
|
|
204
|
+
if (!text) return void 0;
|
|
205
|
+
try {
|
|
206
|
+
return JSON.parse(text);
|
|
207
|
+
} catch {
|
|
208
|
+
return text;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
const body = await this.safeParseBody(response);
|
|
212
|
+
const message = extractErrorMessage(body, response.statusText);
|
|
213
|
+
const error = errorFromStatus(response.status, message, response.headers, body);
|
|
214
|
+
if (RETRY_STATUS_CODES.has(response.status) && attempt < this.maxRetries) {
|
|
215
|
+
lastError = error;
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
throw error;
|
|
219
|
+
} catch (err) {
|
|
220
|
+
clearTimeout(timeoutId);
|
|
221
|
+
if (err instanceof PrismeAIError) throw err;
|
|
222
|
+
if (err instanceof DOMException && err.name === "AbortError") {
|
|
223
|
+
if (options.signal?.aborted) {
|
|
224
|
+
throw new PrismeAIError("Request aborted");
|
|
225
|
+
}
|
|
226
|
+
throw new TimeoutError(`Request timed out after ${timeout}ms`);
|
|
227
|
+
}
|
|
228
|
+
if (attempt < this.maxRetries) {
|
|
229
|
+
lastError = new ConnectionError(
|
|
230
|
+
err instanceof Error ? err.message : "Connection failed"
|
|
231
|
+
);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
throw new ConnectionError(
|
|
235
|
+
err instanceof Error ? err.message : "Connection failed"
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
throw lastError ?? new PrismeAIError("Request failed after retries");
|
|
240
|
+
}
|
|
241
|
+
async requestRaw(options) {
|
|
242
|
+
return this.request({ ...options, raw: true });
|
|
243
|
+
}
|
|
244
|
+
get(path, query, options) {
|
|
245
|
+
return this.request({ method: "GET", path, query, ...options });
|
|
246
|
+
}
|
|
247
|
+
post(path, body, options) {
|
|
248
|
+
return this.request({ method: "POST", path, body, ...options });
|
|
249
|
+
}
|
|
250
|
+
put(path, body, options) {
|
|
251
|
+
return this.request({ method: "PUT", path, body, ...options });
|
|
252
|
+
}
|
|
253
|
+
patch(path, body, options) {
|
|
254
|
+
return this.request({ method: "PATCH", path, body, ...options });
|
|
255
|
+
}
|
|
256
|
+
delete(path, query, options) {
|
|
257
|
+
return this.request({ method: "DELETE", path, query, ...options });
|
|
258
|
+
}
|
|
259
|
+
buildURL(path, query) {
|
|
260
|
+
const url = new URL(path, this.baseURL + "/");
|
|
261
|
+
if (query) {
|
|
262
|
+
for (const [key, value] of Object.entries(query)) {
|
|
263
|
+
if (value !== void 0 && value !== null) {
|
|
264
|
+
url.searchParams.set(key, String(value));
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return url.toString();
|
|
269
|
+
}
|
|
270
|
+
getRetryDelay(attempt, lastError) {
|
|
271
|
+
if (lastError instanceof RateLimitError && lastError.retryAfter) {
|
|
272
|
+
return Math.min(lastError.retryAfter, MAX_RETRY_DELAY);
|
|
273
|
+
}
|
|
274
|
+
const base = INITIAL_RETRY_DELAY * Math.pow(2, attempt - 1);
|
|
275
|
+
const jitter = base * 0.2 * Math.random();
|
|
276
|
+
return Math.min(base + jitter, MAX_RETRY_DELAY);
|
|
277
|
+
}
|
|
278
|
+
async safeParseBody(response) {
|
|
279
|
+
try {
|
|
280
|
+
const text = await response.text();
|
|
281
|
+
try {
|
|
282
|
+
return JSON.parse(text);
|
|
283
|
+
} catch {
|
|
284
|
+
return text;
|
|
285
|
+
}
|
|
286
|
+
} catch {
|
|
287
|
+
return void 0;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
function extractErrorMessage(body, fallback) {
|
|
292
|
+
if (body && typeof body === "object") {
|
|
293
|
+
const obj = body;
|
|
294
|
+
if (typeof obj.message === "string") return obj.message;
|
|
295
|
+
if (typeof obj.error === "string") return obj.error;
|
|
296
|
+
if (obj.error && typeof obj.error === "object") {
|
|
297
|
+
const inner = obj.error;
|
|
298
|
+
if (typeof inner.message === "string") return inner.message;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return fallback;
|
|
302
|
+
}
|
|
303
|
+
function sleep(ms) {
|
|
304
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// src/core/pagination.ts
|
|
308
|
+
var PageIterator = class {
|
|
309
|
+
httpClient;
|
|
310
|
+
options;
|
|
311
|
+
pageSize;
|
|
312
|
+
currentPage;
|
|
313
|
+
extractData;
|
|
314
|
+
constructor(httpClient, options, extractData, pageSize = 20, startPage = 1) {
|
|
315
|
+
this.httpClient = httpClient;
|
|
316
|
+
this.options = options;
|
|
317
|
+
this.extractData = extractData;
|
|
318
|
+
this.pageSize = pageSize;
|
|
319
|
+
this.currentPage = startPage;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Fetch a specific page.
|
|
323
|
+
*/
|
|
324
|
+
async getPage(page) {
|
|
325
|
+
const targetPage = page ?? this.currentPage;
|
|
326
|
+
const query = {
|
|
327
|
+
...this.options.query,
|
|
328
|
+
page: targetPage,
|
|
329
|
+
limit: this.pageSize
|
|
330
|
+
};
|
|
331
|
+
const raw = await this.httpClient.request({
|
|
332
|
+
...this.options,
|
|
333
|
+
query
|
|
334
|
+
});
|
|
335
|
+
return this.extractData(raw);
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Collect all items across all pages into a single array.
|
|
339
|
+
*/
|
|
340
|
+
async toArray() {
|
|
341
|
+
const items = [];
|
|
342
|
+
for await (const item of this) {
|
|
343
|
+
items.push(item);
|
|
344
|
+
}
|
|
345
|
+
return items;
|
|
346
|
+
}
|
|
347
|
+
async *[Symbol.asyncIterator]() {
|
|
348
|
+
let page = this.currentPage;
|
|
349
|
+
while (true) {
|
|
350
|
+
const result = await this.getPage(page);
|
|
351
|
+
for (const item of result.data) {
|
|
352
|
+
yield item;
|
|
353
|
+
}
|
|
354
|
+
if (result.data.length < this.pageSize || result.hasMore === false) {
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
page++;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
function defaultExtractor(body) {
|
|
362
|
+
if (Array.isArray(body)) {
|
|
363
|
+
return { data: body, hasMore: false };
|
|
364
|
+
}
|
|
365
|
+
const obj = body;
|
|
366
|
+
const data = obj.results ?? obj.data ?? obj.items ?? obj.documents ?? [];
|
|
367
|
+
const total = obj.total;
|
|
368
|
+
const page = obj.page;
|
|
369
|
+
const limit = obj.limit;
|
|
370
|
+
let hasMore;
|
|
371
|
+
if (total !== void 0 && page !== void 0 && limit !== void 0) {
|
|
372
|
+
hasMore = page * limit < total;
|
|
373
|
+
} else if (obj.hasMore !== void 0) {
|
|
374
|
+
hasMore = obj.hasMore;
|
|
375
|
+
}
|
|
376
|
+
return { data, total, page, limit, hasMore };
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// src/core/base-resource.ts
|
|
380
|
+
var BaseResource = class {
|
|
381
|
+
httpClient;
|
|
382
|
+
constructor(httpClient) {
|
|
383
|
+
this.httpClient = httpClient;
|
|
384
|
+
}
|
|
385
|
+
_get(path, query) {
|
|
386
|
+
return this.httpClient.get(path, query);
|
|
387
|
+
}
|
|
388
|
+
_post(path, body, options) {
|
|
389
|
+
return this.httpClient.post(path, body, options);
|
|
390
|
+
}
|
|
391
|
+
_put(path, body) {
|
|
392
|
+
return this.httpClient.put(path, body);
|
|
393
|
+
}
|
|
394
|
+
_patch(path, body) {
|
|
395
|
+
return this.httpClient.patch(path, body);
|
|
396
|
+
}
|
|
397
|
+
_del(path, query) {
|
|
398
|
+
return this.httpClient.delete(path, query);
|
|
399
|
+
}
|
|
400
|
+
_paginate(path, query, pagination, extractor) {
|
|
401
|
+
return new PageIterator(
|
|
402
|
+
this.httpClient,
|
|
403
|
+
{
|
|
404
|
+
method: "GET",
|
|
405
|
+
path,
|
|
406
|
+
query: { ...query }
|
|
407
|
+
},
|
|
408
|
+
extractor ?? defaultExtractor,
|
|
409
|
+
pagination?.limit ?? 20,
|
|
410
|
+
pagination?.page ?? 1
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Build a path with workspace ID prefix.
|
|
415
|
+
*/
|
|
416
|
+
buildPath(workspaceId, ...segments) {
|
|
417
|
+
return `/workspaces/${workspaceId}/webhooks/${segments.join("/")}`;
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
// src/core/streaming.ts
|
|
422
|
+
var SSEStream = class {
|
|
423
|
+
response;
|
|
424
|
+
controller;
|
|
425
|
+
_done = false;
|
|
426
|
+
constructor(response, controller) {
|
|
427
|
+
this.response = response;
|
|
428
|
+
this.controller = controller;
|
|
429
|
+
}
|
|
430
|
+
get done() {
|
|
431
|
+
return this._done;
|
|
432
|
+
}
|
|
433
|
+
abort() {
|
|
434
|
+
this.controller.abort();
|
|
435
|
+
this._done = true;
|
|
436
|
+
}
|
|
437
|
+
async *[Symbol.asyncIterator]() {
|
|
438
|
+
const body = this.response.body;
|
|
439
|
+
if (!body) {
|
|
440
|
+
this._done = true;
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
const reader = body.getReader();
|
|
444
|
+
const decoder = new TextDecoder();
|
|
445
|
+
let buffer = "";
|
|
446
|
+
try {
|
|
447
|
+
while (true) {
|
|
448
|
+
const { done, value } = await reader.read();
|
|
449
|
+
if (done) {
|
|
450
|
+
if (buffer.trim()) {
|
|
451
|
+
const event = parseSSEBlock(buffer);
|
|
452
|
+
if (event !== null) {
|
|
453
|
+
yield event;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
458
|
+
buffer += decoder.decode(value, { stream: true });
|
|
459
|
+
const events = extractSSEEvents(buffer);
|
|
460
|
+
buffer = events.remaining;
|
|
461
|
+
for (const event of events.parsed) {
|
|
462
|
+
if (event !== null) {
|
|
463
|
+
yield event;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
} catch (err) {
|
|
468
|
+
if (this.controller.signal.aborted) return;
|
|
469
|
+
throw err;
|
|
470
|
+
} finally {
|
|
471
|
+
this._done = true;
|
|
472
|
+
reader.releaseLock();
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
function extractSSEEvents(buffer) {
|
|
477
|
+
const parsed = [];
|
|
478
|
+
const blocks = buffer.split(/\n\n/);
|
|
479
|
+
const remaining = blocks.pop() ?? "";
|
|
480
|
+
for (const block of blocks) {
|
|
481
|
+
const event = parseSSEBlock(block);
|
|
482
|
+
if (event !== null) {
|
|
483
|
+
parsed.push(event);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
return { parsed, remaining };
|
|
487
|
+
}
|
|
488
|
+
function parseSSEBlock(block) {
|
|
489
|
+
let data = "";
|
|
490
|
+
let eventType = "";
|
|
491
|
+
for (const line of block.split("\n")) {
|
|
492
|
+
if (line.startsWith("data:")) {
|
|
493
|
+
const value = line.slice(5).trimStart();
|
|
494
|
+
data += (data ? "\n" : "") + value;
|
|
495
|
+
} else if (line.startsWith("event:")) {
|
|
496
|
+
eventType = line.slice(6).trimStart();
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
if (!data) return null;
|
|
500
|
+
if (data === "[DONE]") return null;
|
|
501
|
+
try {
|
|
502
|
+
const parsed = JSON.parse(data);
|
|
503
|
+
if (eventType) {
|
|
504
|
+
parsed.__event = eventType;
|
|
505
|
+
}
|
|
506
|
+
return parsed;
|
|
507
|
+
} catch {
|
|
508
|
+
return { data, event: eventType || void 0 };
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// src/resources/agents/messages.ts
|
|
513
|
+
var Messages = class extends BaseResource {
|
|
514
|
+
workspaceId;
|
|
515
|
+
constructor(httpClient, workspaceId) {
|
|
516
|
+
super(httpClient);
|
|
517
|
+
this.workspaceId = workspaceId;
|
|
518
|
+
}
|
|
519
|
+
path(...segments) {
|
|
520
|
+
return this.buildPath(this.workspaceId, ...segments);
|
|
521
|
+
}
|
|
522
|
+
/** Send a message to an agent and get a complete response. */
|
|
523
|
+
send(agentId, params) {
|
|
524
|
+
return this._post(this.path("agents", agentId, "messages"), params);
|
|
525
|
+
}
|
|
526
|
+
/** Send a message and receive the response as an SSE stream. */
|
|
527
|
+
async stream(agentId, params) {
|
|
528
|
+
const controller = new AbortController();
|
|
529
|
+
const response = await this.httpClient.requestRaw({
|
|
530
|
+
method: "POST",
|
|
531
|
+
path: this.path("agents", agentId, "messages", "stream"),
|
|
532
|
+
body: params,
|
|
533
|
+
headers: {
|
|
534
|
+
accept: "text/event-stream"
|
|
535
|
+
},
|
|
536
|
+
signal: controller.signal
|
|
537
|
+
});
|
|
538
|
+
return new SSEStream(response, controller);
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
// src/resources/agents/conversations.ts
|
|
543
|
+
var Conversations = class extends BaseResource {
|
|
544
|
+
workspaceId;
|
|
545
|
+
constructor(httpClient, workspaceId) {
|
|
546
|
+
super(httpClient);
|
|
547
|
+
this.workspaceId = workspaceId;
|
|
548
|
+
}
|
|
549
|
+
path(...segments) {
|
|
550
|
+
return this.buildPath(this.workspaceId, ...segments);
|
|
551
|
+
}
|
|
552
|
+
/** List conversations. */
|
|
553
|
+
list(params) {
|
|
554
|
+
return this._paginate(this.path("conversations"), params);
|
|
555
|
+
}
|
|
556
|
+
/** Create a new conversation. */
|
|
557
|
+
create(params) {
|
|
558
|
+
return this._post(this.path("conversations"), params);
|
|
559
|
+
}
|
|
560
|
+
/** Get a conversation by ID. */
|
|
561
|
+
get(conversationId) {
|
|
562
|
+
return this.httpClient.get(this.path("conversations", conversationId));
|
|
563
|
+
}
|
|
564
|
+
/** Update a conversation. */
|
|
565
|
+
update(conversationId, params) {
|
|
566
|
+
return this._patch(this.path("conversations", conversationId), params);
|
|
567
|
+
}
|
|
568
|
+
/** Delete a conversation. */
|
|
569
|
+
delete(conversationId) {
|
|
570
|
+
return this._del(this.path("conversations", conversationId));
|
|
571
|
+
}
|
|
572
|
+
/** List messages in a conversation. */
|
|
573
|
+
messages(conversationId, params) {
|
|
574
|
+
return this._paginate(
|
|
575
|
+
this.path("conversations", conversationId, "messages"),
|
|
576
|
+
params
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
/** Share a conversation. */
|
|
580
|
+
share(conversationId, params) {
|
|
581
|
+
return this._post(this.path("conversations", conversationId, "share"), params);
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
// src/resources/agents/tools.ts
|
|
586
|
+
var Tools = class extends BaseResource {
|
|
587
|
+
workspaceId;
|
|
588
|
+
constructor(httpClient, workspaceId) {
|
|
589
|
+
super(httpClient);
|
|
590
|
+
this.workspaceId = workspaceId;
|
|
591
|
+
}
|
|
592
|
+
path(...segments) {
|
|
593
|
+
return this.buildPath(this.workspaceId, ...segments);
|
|
594
|
+
}
|
|
595
|
+
/** List tools available for agents. */
|
|
596
|
+
list(params) {
|
|
597
|
+
return this._paginate(this.path("tools"), params);
|
|
598
|
+
}
|
|
599
|
+
/** Create a new tool. */
|
|
600
|
+
create(params) {
|
|
601
|
+
return this._post(this.path("tools"), params);
|
|
602
|
+
}
|
|
603
|
+
/** Get a tool by ID. */
|
|
604
|
+
get(toolId) {
|
|
605
|
+
return this.httpClient.get(this.path("tools", toolId));
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
// src/resources/agents/access.ts
|
|
610
|
+
var Access = class extends BaseResource {
|
|
611
|
+
workspaceId;
|
|
612
|
+
constructor(httpClient, workspaceId) {
|
|
613
|
+
super(httpClient);
|
|
614
|
+
this.workspaceId = workspaceId;
|
|
615
|
+
}
|
|
616
|
+
path(...segments) {
|
|
617
|
+
return this.buildPath(this.workspaceId, ...segments);
|
|
618
|
+
}
|
|
619
|
+
/** List access entries for an agent. */
|
|
620
|
+
list(agentId, params) {
|
|
621
|
+
return this._paginate(this.path("agents", agentId, "access"), params);
|
|
622
|
+
}
|
|
623
|
+
/** Grant access to an agent. */
|
|
624
|
+
grant(agentId, params) {
|
|
625
|
+
return this._post(this.path("agents", agentId, "access"), params);
|
|
626
|
+
}
|
|
627
|
+
/** Revoke access to an agent. */
|
|
628
|
+
revoke(agentId, accessId) {
|
|
629
|
+
return this._del(this.path("agents", agentId, "access", accessId));
|
|
630
|
+
}
|
|
631
|
+
/** Request access to an agent. */
|
|
632
|
+
requestAccess(agentId) {
|
|
633
|
+
return this._post(this.path("agents", agentId, "access-requests"));
|
|
634
|
+
}
|
|
635
|
+
/** List access requests for an agent. */
|
|
636
|
+
listRequests(agentId, params) {
|
|
637
|
+
return this._paginate(this.path("agents", agentId, "access-requests"), params);
|
|
638
|
+
}
|
|
639
|
+
/** Handle an access request (approve/reject). */
|
|
640
|
+
handleRequest(agentId, requestId, params) {
|
|
641
|
+
return this._post(
|
|
642
|
+
this.path("agents", agentId, "access-requests", requestId, params.action)
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
// src/resources/agents/analytics.ts
|
|
648
|
+
var Analytics = class extends BaseResource {
|
|
649
|
+
workspaceId;
|
|
650
|
+
constructor(httpClient, workspaceId) {
|
|
651
|
+
super(httpClient);
|
|
652
|
+
this.workspaceId = workspaceId;
|
|
653
|
+
}
|
|
654
|
+
path(...segments) {
|
|
655
|
+
return this.buildPath(this.workspaceId, ...segments);
|
|
656
|
+
}
|
|
657
|
+
/** Get analytics for an agent. */
|
|
658
|
+
get(agentId, params) {
|
|
659
|
+
return this.httpClient.get(this.path("agents", agentId, "analytics"), params);
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
// src/resources/agents/evaluations.ts
|
|
664
|
+
var Evaluations = class extends BaseResource {
|
|
665
|
+
workspaceId;
|
|
666
|
+
constructor(httpClient, workspaceId) {
|
|
667
|
+
super(httpClient);
|
|
668
|
+
this.workspaceId = workspaceId;
|
|
669
|
+
}
|
|
670
|
+
path(...segments) {
|
|
671
|
+
return this.buildPath(this.workspaceId, ...segments);
|
|
672
|
+
}
|
|
673
|
+
/** List evaluations for an agent. */
|
|
674
|
+
list(agentId, params) {
|
|
675
|
+
return this._paginate(this.path("agents", agentId, "evaluations"), params);
|
|
676
|
+
}
|
|
677
|
+
/** Create a new evaluation. */
|
|
678
|
+
create(agentId, params) {
|
|
679
|
+
return this._post(this.path("agents", agentId, "evaluations"), params);
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
// src/resources/agents/a2a.ts
|
|
684
|
+
var A2A = class extends BaseResource {
|
|
685
|
+
workspaceId;
|
|
686
|
+
constructor(httpClient, workspaceId) {
|
|
687
|
+
super(httpClient);
|
|
688
|
+
this.workspaceId = workspaceId;
|
|
689
|
+
}
|
|
690
|
+
path(...segments) {
|
|
691
|
+
return this.buildPath(this.workspaceId, ...segments);
|
|
692
|
+
}
|
|
693
|
+
/** Send a message via A2A protocol. */
|
|
694
|
+
send(agentId, params) {
|
|
695
|
+
return this._post(this.path("agents", agentId, "a2a", "send"), params);
|
|
696
|
+
}
|
|
697
|
+
/** Send a message and subscribe to SSE events (A2A protocol). */
|
|
698
|
+
async sendSubscribe(agentId, params) {
|
|
699
|
+
const controller = new AbortController();
|
|
700
|
+
const response = await this.httpClient.requestRaw({
|
|
701
|
+
method: "POST",
|
|
702
|
+
path: this.path("agents", agentId, "a2a", "send-subscribe"),
|
|
703
|
+
body: params,
|
|
704
|
+
headers: {
|
|
705
|
+
accept: "text/event-stream"
|
|
706
|
+
},
|
|
707
|
+
signal: controller.signal
|
|
708
|
+
});
|
|
709
|
+
return new SSEStream(response, controller);
|
|
710
|
+
}
|
|
711
|
+
/** Get the A2A agent card. */
|
|
712
|
+
getCard(agentId) {
|
|
713
|
+
return this.httpClient.get(this.path("agents", agentId, "a2a", "card"));
|
|
714
|
+
}
|
|
715
|
+
/** Get the extended A2A agent card with tools and sub-agents. */
|
|
716
|
+
getExtendedCard(agentId) {
|
|
717
|
+
return this.httpClient.get(this.path("agents", agentId, "a2a", "card", "extended"));
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
// src/resources/agents/index.ts
|
|
722
|
+
var Agents = class extends BaseResource {
|
|
723
|
+
messages;
|
|
724
|
+
conversations;
|
|
725
|
+
tools;
|
|
726
|
+
access;
|
|
727
|
+
analytics;
|
|
728
|
+
evaluations;
|
|
729
|
+
a2a;
|
|
730
|
+
workspaceId;
|
|
731
|
+
constructor(httpClient, workspaceId) {
|
|
732
|
+
super(httpClient);
|
|
733
|
+
this.workspaceId = workspaceId;
|
|
734
|
+
this.messages = new Messages(httpClient, workspaceId);
|
|
735
|
+
this.conversations = new Conversations(httpClient, workspaceId);
|
|
736
|
+
this.tools = new Tools(httpClient, workspaceId);
|
|
737
|
+
this.access = new Access(httpClient, workspaceId);
|
|
738
|
+
this.analytics = new Analytics(httpClient, workspaceId);
|
|
739
|
+
this.evaluations = new Evaluations(httpClient, workspaceId);
|
|
740
|
+
this.a2a = new A2A(httpClient, workspaceId);
|
|
741
|
+
}
|
|
742
|
+
path(...segments) {
|
|
743
|
+
return this.buildPath(this.workspaceId, ...segments);
|
|
744
|
+
}
|
|
745
|
+
/** List all agents. */
|
|
746
|
+
list(params) {
|
|
747
|
+
return this._paginate(this.path("agents"), params);
|
|
748
|
+
}
|
|
749
|
+
/** Create a new agent. */
|
|
750
|
+
create(params) {
|
|
751
|
+
return this._post(this.path("agents"), params);
|
|
752
|
+
}
|
|
753
|
+
/** Get an agent by ID. */
|
|
754
|
+
get(agentId) {
|
|
755
|
+
return this.httpClient.get(this.path("agents", agentId));
|
|
756
|
+
}
|
|
757
|
+
/** Update an agent. */
|
|
758
|
+
update(agentId, params) {
|
|
759
|
+
return this._patch(this.path("agents", agentId), params);
|
|
760
|
+
}
|
|
761
|
+
/** Delete an agent. */
|
|
762
|
+
delete(agentId) {
|
|
763
|
+
return this._del(this.path("agents", agentId));
|
|
764
|
+
}
|
|
765
|
+
/** Publish an agent (promote draft to published). */
|
|
766
|
+
publish(agentId) {
|
|
767
|
+
return this._post(this.path("agents", agentId, "publish"));
|
|
768
|
+
}
|
|
769
|
+
/** Discard the current draft. */
|
|
770
|
+
discardDraft(agentId) {
|
|
771
|
+
return this._post(this.path("agents", agentId, "discard-draft"));
|
|
772
|
+
}
|
|
773
|
+
/** Update agent discovery settings. */
|
|
774
|
+
discovery(agentId, params) {
|
|
775
|
+
return this._patch(this.path("agents", agentId, "discovery"), params);
|
|
776
|
+
}
|
|
777
|
+
/** Export an agent configuration. */
|
|
778
|
+
export(agentId) {
|
|
779
|
+
return this.httpClient.get(this.path("agents", agentId, "export"));
|
|
780
|
+
}
|
|
781
|
+
/** Import an agent configuration. */
|
|
782
|
+
import(config) {
|
|
783
|
+
return this._post(this.path("agents", "import"), config);
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
|
|
787
|
+
// src/resources/tasks/index.ts
|
|
788
|
+
var Tasks = class extends BaseResource {
|
|
789
|
+
workspaceId;
|
|
790
|
+
constructor(httpClient, workspaceId) {
|
|
791
|
+
super(httpClient);
|
|
792
|
+
this.workspaceId = workspaceId;
|
|
793
|
+
}
|
|
794
|
+
path(...segments) {
|
|
795
|
+
return this.buildPath(this.workspaceId, ...segments);
|
|
796
|
+
}
|
|
797
|
+
/** List tasks. */
|
|
798
|
+
list(params) {
|
|
799
|
+
return this._paginate(this.path("tasks"), params);
|
|
800
|
+
}
|
|
801
|
+
/** Get a task by ID. */
|
|
802
|
+
get(taskId) {
|
|
803
|
+
return this.httpClient.get(this.path("tasks", taskId));
|
|
804
|
+
}
|
|
805
|
+
/** Cancel a running task. */
|
|
806
|
+
cancel(taskId) {
|
|
807
|
+
return this._post(this.path("tasks", taskId, "cancel"));
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
|
|
811
|
+
// src/resources/artifacts/index.ts
|
|
812
|
+
var Artifacts = class extends BaseResource {
|
|
813
|
+
workspaceId;
|
|
814
|
+
constructor(httpClient, workspaceId) {
|
|
815
|
+
super(httpClient);
|
|
816
|
+
this.workspaceId = workspaceId;
|
|
817
|
+
}
|
|
818
|
+
path(...segments) {
|
|
819
|
+
return this.buildPath(this.workspaceId, ...segments);
|
|
820
|
+
}
|
|
821
|
+
list(params) {
|
|
822
|
+
return this._paginate(this.path("artifacts"), params);
|
|
823
|
+
}
|
|
824
|
+
get(artifactId) {
|
|
825
|
+
return this.httpClient.get(this.path("artifacts", artifactId));
|
|
826
|
+
}
|
|
827
|
+
update(artifactId, params) {
|
|
828
|
+
return this._patch(this.path("artifacts", artifactId), params);
|
|
829
|
+
}
|
|
830
|
+
delete(artifactId) {
|
|
831
|
+
return this._del(this.path("artifacts", artifactId));
|
|
832
|
+
}
|
|
833
|
+
share(artifactId, params) {
|
|
834
|
+
return this._post(this.path("artifacts", artifactId, "share"), params);
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
|
|
838
|
+
// src/resources/shares/index.ts
|
|
839
|
+
var Shares = class extends BaseResource {
|
|
840
|
+
workspaceId;
|
|
841
|
+
constructor(httpClient, workspaceId) {
|
|
842
|
+
super(httpClient);
|
|
843
|
+
this.workspaceId = workspaceId;
|
|
844
|
+
}
|
|
845
|
+
path(...segments) {
|
|
846
|
+
return this.buildPath(this.workspaceId, ...segments);
|
|
847
|
+
}
|
|
848
|
+
list(params) {
|
|
849
|
+
return this._paginate(this.path("shares"), params);
|
|
850
|
+
}
|
|
851
|
+
get(shareId) {
|
|
852
|
+
return this.httpClient.get(this.path("shares", shareId));
|
|
853
|
+
}
|
|
854
|
+
};
|
|
855
|
+
|
|
856
|
+
// src/resources/ratings/index.ts
|
|
857
|
+
var Ratings = class extends BaseResource {
|
|
858
|
+
workspaceId;
|
|
859
|
+
constructor(httpClient, workspaceId) {
|
|
860
|
+
super(httpClient);
|
|
861
|
+
this.workspaceId = workspaceId;
|
|
862
|
+
}
|
|
863
|
+
path(...segments) {
|
|
864
|
+
return this.buildPath(this.workspaceId, ...segments);
|
|
865
|
+
}
|
|
866
|
+
/** Submit a rating for an agent response. */
|
|
867
|
+
create(params) {
|
|
868
|
+
return this._post(this.path("ratings"), params);
|
|
869
|
+
}
|
|
870
|
+
};
|
|
871
|
+
|
|
872
|
+
// src/resources/activity/index.ts
|
|
873
|
+
var Activity = class extends BaseResource {
|
|
874
|
+
workspaceId;
|
|
875
|
+
constructor(httpClient, workspaceId) {
|
|
876
|
+
super(httpClient);
|
|
877
|
+
this.workspaceId = workspaceId;
|
|
878
|
+
}
|
|
879
|
+
path(...segments) {
|
|
880
|
+
return this.buildPath(this.workspaceId, ...segments);
|
|
881
|
+
}
|
|
882
|
+
/** List recent activity. */
|
|
883
|
+
list(params) {
|
|
884
|
+
return this._paginate(this.path("activity"), params);
|
|
885
|
+
}
|
|
886
|
+
};
|
|
887
|
+
|
|
888
|
+
// src/resources/profiles/index.ts
|
|
889
|
+
var Profiles = class extends BaseResource {
|
|
890
|
+
workspaceId;
|
|
891
|
+
constructor(httpClient, workspaceId) {
|
|
892
|
+
super(httpClient);
|
|
893
|
+
this.workspaceId = workspaceId;
|
|
894
|
+
}
|
|
895
|
+
path(...segments) {
|
|
896
|
+
return this.buildPath(this.workspaceId, ...segments);
|
|
897
|
+
}
|
|
898
|
+
/** List user profiles. */
|
|
899
|
+
list(params) {
|
|
900
|
+
return this._paginate(this.path("profiles"), params);
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
|
|
904
|
+
// src/resources/orgs/index.ts
|
|
905
|
+
var Orgs = class extends BaseResource {
|
|
906
|
+
workspaceId;
|
|
907
|
+
constructor(httpClient, workspaceId) {
|
|
908
|
+
super(httpClient);
|
|
909
|
+
this.workspaceId = workspaceId;
|
|
910
|
+
}
|
|
911
|
+
path(...segments) {
|
|
912
|
+
return this.buildPath(this.workspaceId, ...segments);
|
|
913
|
+
}
|
|
914
|
+
/** List agents available in the organization. */
|
|
915
|
+
listAgents(params) {
|
|
916
|
+
return this._paginate(this.path("orgs", "agents"), params);
|
|
917
|
+
}
|
|
918
|
+
};
|
|
919
|
+
|
|
920
|
+
// src/core/uploads.ts
|
|
921
|
+
var import_promises = require("fs/promises");
|
|
922
|
+
async function toFormData(fieldName, input, options = {}) {
|
|
923
|
+
const formData = new FormData();
|
|
924
|
+
const blob = await toBlob(input, options);
|
|
925
|
+
formData.append(fieldName, blob, options.filename ?? "file");
|
|
926
|
+
return formData;
|
|
927
|
+
}
|
|
928
|
+
async function toBlob(input, options) {
|
|
929
|
+
const contentType = options.contentType ?? "application/octet-stream";
|
|
930
|
+
if (input instanceof Blob) {
|
|
931
|
+
return input;
|
|
932
|
+
}
|
|
933
|
+
if (typeof input === "string") {
|
|
934
|
+
const data = await (0, import_promises.readFile)(input);
|
|
935
|
+
return new Blob([data], { type: contentType });
|
|
936
|
+
}
|
|
937
|
+
if (input instanceof Buffer || input instanceof ArrayBuffer || input instanceof Uint8Array) {
|
|
938
|
+
return new Blob([input], { type: contentType });
|
|
939
|
+
}
|
|
940
|
+
if (input instanceof ReadableStream) {
|
|
941
|
+
const chunks = [];
|
|
942
|
+
const reader = input.getReader();
|
|
943
|
+
while (true) {
|
|
944
|
+
const { done, value } = await reader.read();
|
|
945
|
+
if (done) break;
|
|
946
|
+
chunks.push(value);
|
|
947
|
+
}
|
|
948
|
+
return new Blob(chunks, { type: contentType });
|
|
949
|
+
}
|
|
950
|
+
throw new TypeError(`Unsupported file input type: ${typeof input}`);
|
|
951
|
+
}
|
|
952
|
+
function mimeFromFilename(filename) {
|
|
953
|
+
const ext = filename.split(".").pop()?.toLowerCase();
|
|
954
|
+
const mimeTypes = {
|
|
955
|
+
pdf: "application/pdf",
|
|
956
|
+
json: "application/json",
|
|
957
|
+
csv: "text/csv",
|
|
958
|
+
txt: "text/plain",
|
|
959
|
+
md: "text/markdown",
|
|
960
|
+
html: "text/html",
|
|
961
|
+
xml: "application/xml",
|
|
962
|
+
png: "image/png",
|
|
963
|
+
jpg: "image/jpeg",
|
|
964
|
+
jpeg: "image/jpeg",
|
|
965
|
+
gif: "image/gif",
|
|
966
|
+
svg: "image/svg+xml",
|
|
967
|
+
webp: "image/webp",
|
|
968
|
+
mp3: "audio/mpeg",
|
|
969
|
+
mp4: "video/mp4",
|
|
970
|
+
zip: "application/zip",
|
|
971
|
+
doc: "application/msword",
|
|
972
|
+
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
973
|
+
xls: "application/vnd.ms-excel",
|
|
974
|
+
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
975
|
+
};
|
|
976
|
+
return mimeTypes[ext ?? ""] ?? "application/octet-stream";
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
// src/resources/storage/files.ts
|
|
980
|
+
var Files = class extends BaseResource {
|
|
981
|
+
workspaceId;
|
|
982
|
+
constructor(httpClient, workspaceId) {
|
|
983
|
+
super(httpClient);
|
|
984
|
+
this.workspaceId = workspaceId;
|
|
985
|
+
}
|
|
986
|
+
path(...segments) {
|
|
987
|
+
return this.buildPath(this.workspaceId, ...segments);
|
|
988
|
+
}
|
|
989
|
+
/** List files. */
|
|
990
|
+
list(params) {
|
|
991
|
+
return this._paginate(this.path("files"), params);
|
|
992
|
+
}
|
|
993
|
+
/** Upload a file. */
|
|
994
|
+
async upload(file, params) {
|
|
995
|
+
const filename = params?.filename ?? params?.name ?? "file";
|
|
996
|
+
const contentType = params?.contentType ?? mimeFromFilename(filename);
|
|
997
|
+
const formData = await toFormData("file", file, { filename, contentType });
|
|
998
|
+
if (params?.name) {
|
|
999
|
+
formData.append("name", params.name);
|
|
1000
|
+
}
|
|
1001
|
+
if (params?.metadata) {
|
|
1002
|
+
formData.append("metadata", JSON.stringify(params.metadata));
|
|
1003
|
+
}
|
|
1004
|
+
return this.httpClient.post(this.path("files"), formData);
|
|
1005
|
+
}
|
|
1006
|
+
/** Get file metadata. */
|
|
1007
|
+
get(fileId) {
|
|
1008
|
+
return this.httpClient.get(this.path("files", fileId));
|
|
1009
|
+
}
|
|
1010
|
+
/** Delete a file. */
|
|
1011
|
+
delete(fileId) {
|
|
1012
|
+
return this._del(this.path("files", fileId));
|
|
1013
|
+
}
|
|
1014
|
+
/** Download a file. Returns the raw Response for streaming. */
|
|
1015
|
+
async download(fileId) {
|
|
1016
|
+
return this.httpClient.requestRaw({
|
|
1017
|
+
method: "GET",
|
|
1018
|
+
path: this.path("files", fileId, "download")
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
|
|
1023
|
+
// src/resources/storage/vector-stores/files.ts
|
|
1024
|
+
var VSFiles = class extends BaseResource {
|
|
1025
|
+
workspaceId;
|
|
1026
|
+
constructor(httpClient, workspaceId) {
|
|
1027
|
+
super(httpClient);
|
|
1028
|
+
this.workspaceId = workspaceId;
|
|
1029
|
+
}
|
|
1030
|
+
path(...segments) {
|
|
1031
|
+
return this.buildPath(this.workspaceId, ...segments);
|
|
1032
|
+
}
|
|
1033
|
+
/** List files in a vector store. */
|
|
1034
|
+
list(vectorStoreId, params) {
|
|
1035
|
+
return this._paginate(
|
|
1036
|
+
this.path("vector-stores", vectorStoreId, "files"),
|
|
1037
|
+
params
|
|
1038
|
+
);
|
|
1039
|
+
}
|
|
1040
|
+
/** Add a file to a vector store. */
|
|
1041
|
+
add(vectorStoreId, params) {
|
|
1042
|
+
return this._post(
|
|
1043
|
+
this.path("vector-stores", vectorStoreId, "files"),
|
|
1044
|
+
params
|
|
1045
|
+
);
|
|
1046
|
+
}
|
|
1047
|
+
/** Update a file in a vector store. */
|
|
1048
|
+
update(vectorStoreId, fileId, params) {
|
|
1049
|
+
return this._patch(
|
|
1050
|
+
this.path("vector-stores", vectorStoreId, "files", fileId),
|
|
1051
|
+
params
|
|
1052
|
+
);
|
|
1053
|
+
}
|
|
1054
|
+
/** Remove a file from a vector store. */
|
|
1055
|
+
delete(vectorStoreId, fileId) {
|
|
1056
|
+
return this._del(
|
|
1057
|
+
this.path("vector-stores", vectorStoreId, "files", fileId)
|
|
1058
|
+
);
|
|
1059
|
+
}
|
|
1060
|
+
/** Get chunks for a file in a vector store. */
|
|
1061
|
+
chunks(vectorStoreId, fileId) {
|
|
1062
|
+
return this.httpClient.get(
|
|
1063
|
+
this.path("vector-stores", vectorStoreId, "files", fileId, "chunks")
|
|
1064
|
+
);
|
|
1065
|
+
}
|
|
1066
|
+
/** Reindex a specific file in a vector store. */
|
|
1067
|
+
reindex(vectorStoreId, fileId) {
|
|
1068
|
+
return this._post(
|
|
1069
|
+
this.path("vector-stores", vectorStoreId, "files", fileId, "reindex")
|
|
1070
|
+
);
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
1073
|
+
|
|
1074
|
+
// src/resources/storage/vector-stores/access.ts
|
|
1075
|
+
var VSAccess = class extends BaseResource {
|
|
1076
|
+
workspaceId;
|
|
1077
|
+
constructor(httpClient, workspaceId) {
|
|
1078
|
+
super(httpClient);
|
|
1079
|
+
this.workspaceId = workspaceId;
|
|
1080
|
+
}
|
|
1081
|
+
path(...segments) {
|
|
1082
|
+
return this.buildPath(this.workspaceId, ...segments);
|
|
1083
|
+
}
|
|
1084
|
+
/** List access entries for a vector store. */
|
|
1085
|
+
list(vectorStoreId) {
|
|
1086
|
+
return this._paginate(
|
|
1087
|
+
this.path("vector-stores", vectorStoreId, "access")
|
|
1088
|
+
);
|
|
1089
|
+
}
|
|
1090
|
+
/** Grant access to a vector store. */
|
|
1091
|
+
grant(vectorStoreId, params) {
|
|
1092
|
+
return this._post(
|
|
1093
|
+
this.path("vector-stores", vectorStoreId, "access"),
|
|
1094
|
+
params
|
|
1095
|
+
);
|
|
1096
|
+
}
|
|
1097
|
+
/** Update access for a vector store. */
|
|
1098
|
+
update(vectorStoreId, accessId, params) {
|
|
1099
|
+
return this._patch(
|
|
1100
|
+
this.path("vector-stores", vectorStoreId, "access", accessId),
|
|
1101
|
+
params
|
|
1102
|
+
);
|
|
1103
|
+
}
|
|
1104
|
+
/** Revoke access to a vector store. */
|
|
1105
|
+
revoke(vectorStoreId, accessId) {
|
|
1106
|
+
return this._del(
|
|
1107
|
+
this.path("vector-stores", vectorStoreId, "access", accessId)
|
|
1108
|
+
);
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
|
|
1112
|
+
// src/resources/storage/vector-stores/index.ts
|
|
1113
|
+
var VectorStores = class extends BaseResource {
|
|
1114
|
+
files;
|
|
1115
|
+
access;
|
|
1116
|
+
workspaceId;
|
|
1117
|
+
constructor(httpClient, workspaceId) {
|
|
1118
|
+
super(httpClient);
|
|
1119
|
+
this.workspaceId = workspaceId;
|
|
1120
|
+
this.files = new VSFiles(httpClient, workspaceId);
|
|
1121
|
+
this.access = new VSAccess(httpClient, workspaceId);
|
|
1122
|
+
}
|
|
1123
|
+
path(...segments) {
|
|
1124
|
+
return this.buildPath(this.workspaceId, ...segments);
|
|
1125
|
+
}
|
|
1126
|
+
/** List vector stores. */
|
|
1127
|
+
list(params) {
|
|
1128
|
+
return this._paginate(this.path("vector-stores"), params);
|
|
1129
|
+
}
|
|
1130
|
+
/** Create a new vector store. */
|
|
1131
|
+
create(params) {
|
|
1132
|
+
return this._post(this.path("vector-stores"), params);
|
|
1133
|
+
}
|
|
1134
|
+
/** Get a vector store by ID. */
|
|
1135
|
+
get(vectorStoreId) {
|
|
1136
|
+
return this.httpClient.get(this.path("vector-stores", vectorStoreId));
|
|
1137
|
+
}
|
|
1138
|
+
/** Update a vector store. */
|
|
1139
|
+
update(vectorStoreId, params) {
|
|
1140
|
+
return this._patch(this.path("vector-stores", vectorStoreId), params);
|
|
1141
|
+
}
|
|
1142
|
+
/** Delete a vector store. */
|
|
1143
|
+
delete(vectorStoreId) {
|
|
1144
|
+
return this._del(this.path("vector-stores", vectorStoreId));
|
|
1145
|
+
}
|
|
1146
|
+
/** Search a vector store. */
|
|
1147
|
+
search(vectorStoreId, params) {
|
|
1148
|
+
return this._post(
|
|
1149
|
+
this.path("vector-stores", vectorStoreId, "search"),
|
|
1150
|
+
params
|
|
1151
|
+
);
|
|
1152
|
+
}
|
|
1153
|
+
/** Reindex a vector store. */
|
|
1154
|
+
reindex(vectorStoreId) {
|
|
1155
|
+
return this._post(this.path("vector-stores", vectorStoreId, "reindex"));
|
|
1156
|
+
}
|
|
1157
|
+
/** Get crawl status for a vector store. */
|
|
1158
|
+
crawlStatus(vectorStoreId) {
|
|
1159
|
+
return this.httpClient.get(
|
|
1160
|
+
this.path("vector-stores", vectorStoreId, "crawl-status")
|
|
1161
|
+
);
|
|
1162
|
+
}
|
|
1163
|
+
/** Trigger a recrawl for a vector store. */
|
|
1164
|
+
recrawl(vectorStoreId) {
|
|
1165
|
+
return this._post(this.path("vector-stores", vectorStoreId, "recrawl"));
|
|
1166
|
+
}
|
|
1167
|
+
};
|
|
1168
|
+
|
|
1169
|
+
// src/resources/storage/skills.ts
|
|
1170
|
+
var Skills = class extends BaseResource {
|
|
1171
|
+
workspaceId;
|
|
1172
|
+
constructor(httpClient, workspaceId) {
|
|
1173
|
+
super(httpClient);
|
|
1174
|
+
this.workspaceId = workspaceId;
|
|
1175
|
+
}
|
|
1176
|
+
path(...segments) {
|
|
1177
|
+
return this.buildPath(this.workspaceId, ...segments);
|
|
1178
|
+
}
|
|
1179
|
+
list(params) {
|
|
1180
|
+
return this._paginate(this.path("skills"), params);
|
|
1181
|
+
}
|
|
1182
|
+
create(params) {
|
|
1183
|
+
return this._post(this.path("skills"), params);
|
|
1184
|
+
}
|
|
1185
|
+
get(skillId) {
|
|
1186
|
+
return this.httpClient.get(this.path("skills", skillId));
|
|
1187
|
+
}
|
|
1188
|
+
update(skillId, params) {
|
|
1189
|
+
return this._patch(this.path("skills", skillId), params);
|
|
1190
|
+
}
|
|
1191
|
+
delete(skillId) {
|
|
1192
|
+
return this._del(this.path("skills", skillId));
|
|
1193
|
+
}
|
|
1194
|
+
};
|
|
1195
|
+
|
|
1196
|
+
// src/resources/storage/stats.ts
|
|
1197
|
+
var Stats = class extends BaseResource {
|
|
1198
|
+
workspaceId;
|
|
1199
|
+
constructor(httpClient, workspaceId) {
|
|
1200
|
+
super(httpClient);
|
|
1201
|
+
this.workspaceId = workspaceId;
|
|
1202
|
+
}
|
|
1203
|
+
path(...segments) {
|
|
1204
|
+
return this.buildPath(this.workspaceId, ...segments);
|
|
1205
|
+
}
|
|
1206
|
+
/** Get storage statistics. */
|
|
1207
|
+
get(params) {
|
|
1208
|
+
return this.httpClient.get(
|
|
1209
|
+
this.path("stats"),
|
|
1210
|
+
params
|
|
1211
|
+
);
|
|
1212
|
+
}
|
|
1213
|
+
};
|
|
1214
|
+
|
|
1215
|
+
// src/resources/storage/index.ts
|
|
1216
|
+
var Storage = class {
|
|
1217
|
+
files;
|
|
1218
|
+
vectorStores;
|
|
1219
|
+
skills;
|
|
1220
|
+
stats;
|
|
1221
|
+
constructor(httpClient, workspaceId) {
|
|
1222
|
+
this.files = new Files(httpClient, workspaceId);
|
|
1223
|
+
this.vectorStores = new VectorStores(httpClient, workspaceId);
|
|
1224
|
+
this.skills = new Skills(httpClient, workspaceId);
|
|
1225
|
+
this.stats = new Stats(httpClient, workspaceId);
|
|
1226
|
+
}
|
|
1227
|
+
};
|
|
1228
|
+
|
|
1229
|
+
// src/client.ts
|
|
1230
|
+
var ENVIRONMENTS = {
|
|
1231
|
+
sandbox: "https://api.sandbox.prisme.ai/v2",
|
|
1232
|
+
production: "https://api.eda.prisme.ai/v2",
|
|
1233
|
+
prod: "https://api.eda.prisme.ai/v2"
|
|
1234
|
+
};
|
|
1235
|
+
var PrismeAI = class {
|
|
1236
|
+
/** Agent Factory resources. */
|
|
1237
|
+
agents;
|
|
1238
|
+
tasks;
|
|
1239
|
+
artifacts;
|
|
1240
|
+
shares;
|
|
1241
|
+
ratings;
|
|
1242
|
+
activity;
|
|
1243
|
+
profiles;
|
|
1244
|
+
orgs;
|
|
1245
|
+
/** Storage resources (files, vector stores, skills, stats). */
|
|
1246
|
+
storage;
|
|
1247
|
+
agentFactoryClient;
|
|
1248
|
+
storageClient;
|
|
1249
|
+
constructor(options) {
|
|
1250
|
+
const baseURL = resolveBaseURL(options);
|
|
1251
|
+
const headers = buildAuthHeaders(options);
|
|
1252
|
+
this.agentFactoryClient = new HttpClient({
|
|
1253
|
+
baseURL,
|
|
1254
|
+
headers,
|
|
1255
|
+
timeout: options.timeout,
|
|
1256
|
+
maxRetries: options.maxRetries
|
|
1257
|
+
});
|
|
1258
|
+
this.agents = new Agents(this.agentFactoryClient, options.agentFactoryWorkspaceId);
|
|
1259
|
+
this.tasks = new Tasks(this.agentFactoryClient, options.agentFactoryWorkspaceId);
|
|
1260
|
+
this.artifacts = new Artifacts(this.agentFactoryClient, options.agentFactoryWorkspaceId);
|
|
1261
|
+
this.shares = new Shares(this.agentFactoryClient, options.agentFactoryWorkspaceId);
|
|
1262
|
+
this.ratings = new Ratings(this.agentFactoryClient, options.agentFactoryWorkspaceId);
|
|
1263
|
+
this.activity = new Activity(this.agentFactoryClient, options.agentFactoryWorkspaceId);
|
|
1264
|
+
this.profiles = new Profiles(this.agentFactoryClient, options.agentFactoryWorkspaceId);
|
|
1265
|
+
this.orgs = new Orgs(this.agentFactoryClient, options.agentFactoryWorkspaceId);
|
|
1266
|
+
if (options.storageWorkspaceId) {
|
|
1267
|
+
this.storageClient = new HttpClient({
|
|
1268
|
+
baseURL,
|
|
1269
|
+
headers,
|
|
1270
|
+
timeout: options.timeout,
|
|
1271
|
+
maxRetries: options.maxRetries
|
|
1272
|
+
});
|
|
1273
|
+
this.storage = new Storage(this.storageClient, options.storageWorkspaceId);
|
|
1274
|
+
} else {
|
|
1275
|
+
this.storage = new Storage(this.agentFactoryClient, options.agentFactoryWorkspaceId);
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
};
|
|
1279
|
+
function resolveBaseURL(options) {
|
|
1280
|
+
if (options.baseURL) return options.baseURL;
|
|
1281
|
+
if (options.environment) {
|
|
1282
|
+
const env = ENVIRONMENTS[options.environment];
|
|
1283
|
+
if (env) return env;
|
|
1284
|
+
if (options.environment.startsWith("http")) return options.environment;
|
|
1285
|
+
throw new Error(
|
|
1286
|
+
`Unknown environment: "${options.environment}". Use "sandbox", "production", or provide a baseURL.`
|
|
1287
|
+
);
|
|
1288
|
+
}
|
|
1289
|
+
return ENVIRONMENTS.production;
|
|
1290
|
+
}
|
|
1291
|
+
function buildAuthHeaders(options) {
|
|
1292
|
+
const headers = {};
|
|
1293
|
+
if (options.apiKey) {
|
|
1294
|
+
headers["x-prismeai-api-key"] = options.apiKey;
|
|
1295
|
+
}
|
|
1296
|
+
if (options.bearerToken) {
|
|
1297
|
+
headers["authorization"] = `Bearer ${options.bearerToken}`;
|
|
1298
|
+
}
|
|
1299
|
+
if (!options.apiKey && !options.bearerToken) {
|
|
1300
|
+
const envApiKey = process.env.PRISMEAI_API_KEY;
|
|
1301
|
+
const envBearerToken = process.env.PRISMEAI_BEARER_TOKEN;
|
|
1302
|
+
if (envApiKey) {
|
|
1303
|
+
headers["x-prismeai-api-key"] = envApiKey;
|
|
1304
|
+
} else if (envBearerToken) {
|
|
1305
|
+
headers["authorization"] = `Bearer ${envBearerToken}`;
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
return headers;
|
|
1309
|
+
}
|
|
1310
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1311
|
+
0 && (module.exports = {
|
|
1312
|
+
AuthenticationError,
|
|
1313
|
+
ConflictError,
|
|
1314
|
+
ConnectionError,
|
|
1315
|
+
InternalServerError,
|
|
1316
|
+
NotFoundError,
|
|
1317
|
+
PageIterator,
|
|
1318
|
+
PermissionDeniedError,
|
|
1319
|
+
PrismeAI,
|
|
1320
|
+
PrismeAIError,
|
|
1321
|
+
RateLimitError,
|
|
1322
|
+
SSEStream,
|
|
1323
|
+
TimeoutError,
|
|
1324
|
+
ValidationError
|
|
1325
|
+
});
|
|
1326
|
+
//# sourceMappingURL=index.js.map
|