@bimpeai/sdk 0.0.0-beta-20260606071952
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/LICENSE +21 -0
- package/README.md +192 -0
- package/dist/index.cjs +803 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +478 -0
- package/dist/index.d.ts +478 -0
- package/dist/index.js +774 -0
- package/dist/index.js.map +1 -0
- package/package.json +60 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,803 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/version.ts
|
|
4
|
+
var VERSION = "0.0.0-beta-20260606071952";
|
|
5
|
+
|
|
6
|
+
// src/core/envelope.ts
|
|
7
|
+
function unwrapEnvelope(body) {
|
|
8
|
+
if (!isEnvelope(body)) {
|
|
9
|
+
throw new TypeError("Response is not a BimpeAI envelope (missing `message` field)");
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
data: body.data,
|
|
13
|
+
meta: body.meta ?? null
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function isEnvelope(value) {
|
|
17
|
+
return typeof value === "object" && value !== null && "message" in value && typeof value.message === "string";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// src/core/errors.ts
|
|
21
|
+
var BimpeAIError = class extends Error {
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = new.target.name;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var UserError = class extends BimpeAIError {
|
|
28
|
+
};
|
|
29
|
+
var ConnectionError = class extends BimpeAIError {
|
|
30
|
+
cause;
|
|
31
|
+
constructor(message, cause) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.cause = cause;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var ConnectionTimeoutError = class extends ConnectionError {
|
|
37
|
+
};
|
|
38
|
+
var ApiError = class extends BimpeAIError {
|
|
39
|
+
status;
|
|
40
|
+
code;
|
|
41
|
+
requestId;
|
|
42
|
+
headers;
|
|
43
|
+
body;
|
|
44
|
+
constructor(init) {
|
|
45
|
+
super(init.message);
|
|
46
|
+
this.status = init.status;
|
|
47
|
+
this.code = init.code;
|
|
48
|
+
this.requestId = init.requestId;
|
|
49
|
+
this.headers = init.headers;
|
|
50
|
+
this.body = init.body;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var BadRequestError = class extends ApiError {
|
|
54
|
+
};
|
|
55
|
+
var ValidationError = class extends BadRequestError {
|
|
56
|
+
fieldErrors;
|
|
57
|
+
constructor(init) {
|
|
58
|
+
super(init);
|
|
59
|
+
this.fieldErrors = init.fieldErrors;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var AuthenticationError = class extends ApiError {
|
|
63
|
+
};
|
|
64
|
+
var PermissionDeniedError = class extends ApiError {
|
|
65
|
+
};
|
|
66
|
+
var NotFoundError = class extends ApiError {
|
|
67
|
+
};
|
|
68
|
+
var ConflictError = class extends ApiError {
|
|
69
|
+
};
|
|
70
|
+
var RateLimitError = class extends ApiError {
|
|
71
|
+
retryAfter;
|
|
72
|
+
limit;
|
|
73
|
+
remaining;
|
|
74
|
+
resetAt;
|
|
75
|
+
constructor(init) {
|
|
76
|
+
super(init);
|
|
77
|
+
this.retryAfter = init.retryAfter ?? null;
|
|
78
|
+
this.limit = init.limit ?? null;
|
|
79
|
+
this.remaining = init.remaining ?? null;
|
|
80
|
+
this.resetAt = init.resetAt ?? null;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
var InternalServerError = class extends ApiError {
|
|
84
|
+
};
|
|
85
|
+
var NotImplementedError = class extends ApiError {
|
|
86
|
+
};
|
|
87
|
+
function mapApiError(status, body, headers) {
|
|
88
|
+
const errBody = body ?? {};
|
|
89
|
+
const message = normaliseMessage(errBody.message) ?? `HTTP ${status}`;
|
|
90
|
+
const code = errBody.code ?? null;
|
|
91
|
+
const requestId = headers.get("x-request-id") ?? errBody.request_id ?? null;
|
|
92
|
+
const init = { message, status, code, requestId, headers, body };
|
|
93
|
+
if (status === 400) {
|
|
94
|
+
if (code === "validation_error") {
|
|
95
|
+
return new ValidationError({ ...init, fieldErrors: parseFieldErrors(errBody.message) });
|
|
96
|
+
}
|
|
97
|
+
return new BadRequestError(init);
|
|
98
|
+
}
|
|
99
|
+
if (status === 401) return new AuthenticationError(init);
|
|
100
|
+
if (status === 403) return new PermissionDeniedError(init);
|
|
101
|
+
if (status === 404) return new NotFoundError(init);
|
|
102
|
+
if (status === 409) return new ConflictError(init);
|
|
103
|
+
if (status === 429) {
|
|
104
|
+
return new RateLimitError({
|
|
105
|
+
...init,
|
|
106
|
+
retryAfter: parseRetryAfter(headers.get("retry-after")),
|
|
107
|
+
limit: numOrNull(headers.get("x-ratelimit-limit")),
|
|
108
|
+
remaining: numOrNull(headers.get("x-ratelimit-remaining")),
|
|
109
|
+
resetAt: parseReset(headers.get("x-ratelimit-reset"))
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (status === 501) return new NotImplementedError(init);
|
|
113
|
+
if (status >= 500) return new InternalServerError(init);
|
|
114
|
+
return new ApiError(init);
|
|
115
|
+
}
|
|
116
|
+
function normaliseMessage(m) {
|
|
117
|
+
if (Array.isArray(m)) return m.join("; ");
|
|
118
|
+
if (typeof m === "string") return m;
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
function parseFieldErrors(m) {
|
|
122
|
+
if (!Array.isArray(m)) return [];
|
|
123
|
+
const out = [];
|
|
124
|
+
for (const entry of m) {
|
|
125
|
+
if (typeof entry !== "string") continue;
|
|
126
|
+
const idx = entry.indexOf(":");
|
|
127
|
+
if (idx === -1) out.push({ path: "", message: entry });
|
|
128
|
+
else out.push({ path: entry.slice(0, idx).trim(), message: entry.slice(idx + 1).trim() });
|
|
129
|
+
}
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
function parseRetryAfter(raw) {
|
|
133
|
+
if (!raw) return null;
|
|
134
|
+
const asNumber = Number(raw);
|
|
135
|
+
if (Number.isFinite(asNumber)) return Math.max(0, Math.floor(asNumber));
|
|
136
|
+
const asDate = Date.parse(raw);
|
|
137
|
+
if (Number.isFinite(asDate)) return Math.max(0, Math.ceil((asDate - Date.now()) / 1e3));
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
function parseReset(raw) {
|
|
141
|
+
if (!raw) return null;
|
|
142
|
+
const seconds = Number(raw);
|
|
143
|
+
if (!Number.isFinite(seconds)) return null;
|
|
144
|
+
return new Date(seconds * 1e3);
|
|
145
|
+
}
|
|
146
|
+
function numOrNull(raw) {
|
|
147
|
+
if (raw === null) return null;
|
|
148
|
+
const n = Number(raw);
|
|
149
|
+
return Number.isFinite(n) ? n : null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/core/headers.ts
|
|
153
|
+
function mergeHeaders(...sources) {
|
|
154
|
+
const out = new Headers();
|
|
155
|
+
for (const src of sources) {
|
|
156
|
+
if (!src) continue;
|
|
157
|
+
if (src instanceof Headers) {
|
|
158
|
+
src.forEach((value, key) => out.set(key, value));
|
|
159
|
+
} else {
|
|
160
|
+
for (const [key, value] of Object.entries(src)) out.set(key, value);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/core/request-id.ts
|
|
167
|
+
var HAS_RANDOM_UUID = typeof globalThis.crypto !== "undefined" && typeof globalThis.crypto.randomUUID === "function";
|
|
168
|
+
function generateRequestId() {
|
|
169
|
+
if (HAS_RANDOM_UUID) return globalThis.crypto.randomUUID();
|
|
170
|
+
return fallbackUuidV4();
|
|
171
|
+
}
|
|
172
|
+
function fallbackUuidV4() {
|
|
173
|
+
const bytes = new Uint8Array(16);
|
|
174
|
+
if (typeof globalThis.crypto?.getRandomValues === "function") {
|
|
175
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
176
|
+
} else {
|
|
177
|
+
for (let i = 0; i < 16; i += 1) bytes[i] = Math.floor(Math.random() * 256);
|
|
178
|
+
}
|
|
179
|
+
bytes[6] = (bytes[6] ?? 0) & 15 | 64;
|
|
180
|
+
bytes[8] = (bytes[8] ?? 0) & 63 | 128;
|
|
181
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
|
|
182
|
+
return `${hex.slice(0, 4).join("")}-${hex.slice(4, 6).join("")}-${hex.slice(6, 8).join("")}-${hex.slice(8, 10).join("")}-${hex.slice(10, 16).join("")}`;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// src/core/idempotency.ts
|
|
186
|
+
function resolveIdempotencyKey({
|
|
187
|
+
supplied,
|
|
188
|
+
maxRetries
|
|
189
|
+
}) {
|
|
190
|
+
if (supplied) return supplied;
|
|
191
|
+
if (maxRetries > 0) return generateRequestId();
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// src/core/retries.ts
|
|
196
|
+
var DEFAULT_BASE_MS = 500;
|
|
197
|
+
var DEFAULT_MAX_BACKOFF_MS = 8e3;
|
|
198
|
+
var RETRYABLE_STATUSES = /* @__PURE__ */ new Set([408, 429]);
|
|
199
|
+
function shouldRetry(error, attempt, maxRetries) {
|
|
200
|
+
if (attempt >= maxRetries) return false;
|
|
201
|
+
if (!(error instanceof BimpeAIError)) return false;
|
|
202
|
+
if (error instanceof ConnectionTimeoutError || error instanceof ConnectionError) return true;
|
|
203
|
+
if (error instanceof NotImplementedError) return false;
|
|
204
|
+
if (error instanceof ConflictError) return false;
|
|
205
|
+
if (error instanceof ApiError) {
|
|
206
|
+
if (RETRYABLE_STATUSES.has(error.status)) return true;
|
|
207
|
+
if (error.status >= 500 && error.status !== 501) return true;
|
|
208
|
+
}
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
function computeBackoff(attempt, baseMs = DEFAULT_BASE_MS, maxMs = DEFAULT_MAX_BACKOFF_MS, retryAfterMs) {
|
|
212
|
+
if (typeof retryAfterMs === "number" && retryAfterMs >= 0) {
|
|
213
|
+
return Math.min(retryAfterMs, maxMs);
|
|
214
|
+
}
|
|
215
|
+
const exponential = Math.min(maxMs, baseMs * 2 ** attempt);
|
|
216
|
+
const jitter = 0.5 + Math.random() * 0.5;
|
|
217
|
+
return Math.floor(exponential * jitter);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/core/http-client.ts
|
|
221
|
+
var DEFAULT_BASE_URL = "https://api.bimpeai.com";
|
|
222
|
+
var API_PATH_PREFIX = "/api/v1/console";
|
|
223
|
+
var HttpClient = class {
|
|
224
|
+
apiKey;
|
|
225
|
+
baseUrl;
|
|
226
|
+
timeout;
|
|
227
|
+
maxRetries;
|
|
228
|
+
fetchImpl;
|
|
229
|
+
defaultHeaders;
|
|
230
|
+
logger;
|
|
231
|
+
userAgent;
|
|
232
|
+
constructor(config) {
|
|
233
|
+
if (!config.apiKey) throw new UserError("apiKey is required");
|
|
234
|
+
this.apiKey = config.apiKey;
|
|
235
|
+
this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
236
|
+
this.timeout = config.timeout ?? 3e4;
|
|
237
|
+
this.maxRetries = config.maxRetries ?? 2;
|
|
238
|
+
this.fetchImpl = config.fetch ?? globalThis.fetch.bind(globalThis);
|
|
239
|
+
this.defaultHeaders = config.defaultHeaders ?? {};
|
|
240
|
+
this.logger = config.logger;
|
|
241
|
+
this.userAgent = buildUserAgent();
|
|
242
|
+
}
|
|
243
|
+
async request(spec) {
|
|
244
|
+
const url = this.buildUrl(spec.path, spec.query);
|
|
245
|
+
const maxRetries = spec.maxRetries ?? this.maxRetries;
|
|
246
|
+
const timeout = spec.timeout ?? this.timeout;
|
|
247
|
+
const idempotencyKey = isWrite(spec.method) ? resolveIdempotencyKey({ supplied: spec.idempotencyKey, maxRetries }) : null;
|
|
248
|
+
const requestId = readHeader(spec.headers, "x-request-id") ?? generateRequestId();
|
|
249
|
+
let attempt = 0;
|
|
250
|
+
while (true) {
|
|
251
|
+
try {
|
|
252
|
+
return await this.send(url, spec, idempotencyKey, requestId, timeout);
|
|
253
|
+
} catch (error) {
|
|
254
|
+
if (!shouldRetry(error, attempt, maxRetries)) throw error;
|
|
255
|
+
const retryAfter = error instanceof ApiError ? parseRetryAfterMs(error.headers.get("retry-after")) : void 0;
|
|
256
|
+
const delay = computeBackoff(attempt, DEFAULT_BASE_MS, DEFAULT_MAX_BACKOFF_MS, retryAfter);
|
|
257
|
+
this.logger?.debug("retrying request", { attempt, delay, requestId });
|
|
258
|
+
await sleep(delay);
|
|
259
|
+
attempt += 1;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
async send(url, spec, idempotencyKey, requestId, timeout) {
|
|
264
|
+
const headers = mergeHeaders(
|
|
265
|
+
this.defaultHeaders,
|
|
266
|
+
{
|
|
267
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
268
|
+
Accept: "application/json",
|
|
269
|
+
"User-Agent": this.userAgent,
|
|
270
|
+
"X-Request-Id": requestId,
|
|
271
|
+
...spec.body !== void 0 ? { "Content-Type": "application/json" } : {},
|
|
272
|
+
...idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {}
|
|
273
|
+
},
|
|
274
|
+
spec.headers
|
|
275
|
+
);
|
|
276
|
+
const controller = new AbortController();
|
|
277
|
+
const timeoutHandle = setTimeout(
|
|
278
|
+
() => controller.abort(new DOMException("timeout", "TimeoutError")),
|
|
279
|
+
timeout
|
|
280
|
+
);
|
|
281
|
+
const { signal, cleanup } = composeSignals(controller.signal, spec.signal);
|
|
282
|
+
let response;
|
|
283
|
+
try {
|
|
284
|
+
response = await this.fetchImpl(url, {
|
|
285
|
+
method: spec.method,
|
|
286
|
+
headers,
|
|
287
|
+
body: spec.body !== void 0 ? JSON.stringify(spec.body) : null,
|
|
288
|
+
signal
|
|
289
|
+
});
|
|
290
|
+
} catch (cause) {
|
|
291
|
+
if (isAbortError(cause)) {
|
|
292
|
+
if (controller.signal.aborted) throw new ConnectionTimeoutError("request timed out", cause);
|
|
293
|
+
throw new ConnectionError("request aborted", cause);
|
|
294
|
+
}
|
|
295
|
+
throw new ConnectionError("network error", cause);
|
|
296
|
+
} finally {
|
|
297
|
+
clearTimeout(timeoutHandle);
|
|
298
|
+
cleanup();
|
|
299
|
+
}
|
|
300
|
+
const text = await response.text();
|
|
301
|
+
const parsed = text.length ? safeJson(text) : null;
|
|
302
|
+
if (!response.ok) {
|
|
303
|
+
throw mapApiError(response.status, parsed, response.headers);
|
|
304
|
+
}
|
|
305
|
+
let unwrapped;
|
|
306
|
+
try {
|
|
307
|
+
unwrapped = unwrapEnvelope(parsed);
|
|
308
|
+
} catch {
|
|
309
|
+
throw new BimpeAIError(
|
|
310
|
+
`Expected a BimpeAI response envelope but got an unrecognised body (status ${response.status})`
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
return {
|
|
314
|
+
data: unwrapped.data,
|
|
315
|
+
meta: unwrapped.meta,
|
|
316
|
+
requestId: response.headers.get("x-request-id") ?? requestId,
|
|
317
|
+
status: response.status,
|
|
318
|
+
headers: response.headers
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
buildUrl(path, query) {
|
|
322
|
+
const url = new URL(`${this.baseUrl}${API_PATH_PREFIX}${path}`);
|
|
323
|
+
if (query) {
|
|
324
|
+
for (const [key, value] of Object.entries(query)) {
|
|
325
|
+
if (value === void 0) continue;
|
|
326
|
+
url.searchParams.set(key, String(value));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return url.toString();
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
function buildUserAgent() {
|
|
333
|
+
const runtime = detectRuntime();
|
|
334
|
+
const platform = typeof process !== "undefined" ? `${process.platform}/${process.arch}` : "unknown";
|
|
335
|
+
return `bimpeai-sdk-typescript/${VERSION} (${runtime}; ${platform})`;
|
|
336
|
+
}
|
|
337
|
+
function detectRuntime() {
|
|
338
|
+
const g = globalThis;
|
|
339
|
+
if (typeof g.Bun !== "undefined") return `Bun/${g.Bun.version}`;
|
|
340
|
+
if (typeof g.Deno !== "undefined") return `Deno/${g.Deno.version.deno}`;
|
|
341
|
+
if (typeof process !== "undefined" && process.versions?.node)
|
|
342
|
+
return `Node/${process.versions.node}`;
|
|
343
|
+
return "Browser";
|
|
344
|
+
}
|
|
345
|
+
function isWrite(method) {
|
|
346
|
+
return method === "POST" || method === "PATCH" || method === "PUT" || method === "DELETE";
|
|
347
|
+
}
|
|
348
|
+
function readHeader(headers, name) {
|
|
349
|
+
if (!headers) return void 0;
|
|
350
|
+
const lower = name.toLowerCase();
|
|
351
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
352
|
+
if (key.toLowerCase() === lower) return value;
|
|
353
|
+
}
|
|
354
|
+
return void 0;
|
|
355
|
+
}
|
|
356
|
+
function isAbortError(e) {
|
|
357
|
+
return typeof e === "object" && e !== null && "name" in e && (e.name === "AbortError" || e.name === "TimeoutError");
|
|
358
|
+
}
|
|
359
|
+
function composeSignals(a, b) {
|
|
360
|
+
const noop = () => {
|
|
361
|
+
};
|
|
362
|
+
if (!b) return { signal: a, cleanup: noop };
|
|
363
|
+
const anyFn = AbortSignal.any;
|
|
364
|
+
if (typeof anyFn === "function") return { signal: anyFn([a, b]), cleanup: noop };
|
|
365
|
+
const ctrl = new AbortController();
|
|
366
|
+
const onA = () => ctrl.abort(a.reason);
|
|
367
|
+
const onB = () => ctrl.abort(b.reason);
|
|
368
|
+
if (a.aborted) ctrl.abort(a.reason);
|
|
369
|
+
else a.addEventListener("abort", onA, { once: true });
|
|
370
|
+
if (b.aborted) ctrl.abort(b.reason);
|
|
371
|
+
else b.addEventListener("abort", onB, { once: true });
|
|
372
|
+
const cleanup = () => {
|
|
373
|
+
a.removeEventListener("abort", onA);
|
|
374
|
+
b.removeEventListener("abort", onB);
|
|
375
|
+
};
|
|
376
|
+
return { signal: ctrl.signal, cleanup };
|
|
377
|
+
}
|
|
378
|
+
function safeJson(text) {
|
|
379
|
+
try {
|
|
380
|
+
return JSON.parse(text);
|
|
381
|
+
} catch {
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
function parseRetryAfterMs(raw) {
|
|
386
|
+
if (!raw || !raw.trim()) return void 0;
|
|
387
|
+
const seconds = Number(raw);
|
|
388
|
+
if (Number.isFinite(seconds)) return Math.max(0, Math.floor(seconds)) * 1e3;
|
|
389
|
+
const asDate = Date.parse(raw);
|
|
390
|
+
if (Number.isFinite(asDate)) return Math.max(0, asDate - Date.now());
|
|
391
|
+
return void 0;
|
|
392
|
+
}
|
|
393
|
+
function sleep(ms) {
|
|
394
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// src/resources/agents/actions.ts
|
|
398
|
+
var AgentActions = class {
|
|
399
|
+
constructor(client) {
|
|
400
|
+
this.client = client;
|
|
401
|
+
}
|
|
402
|
+
client;
|
|
403
|
+
async list(agentId) {
|
|
404
|
+
const res = await this.client.request({
|
|
405
|
+
method: "GET",
|
|
406
|
+
path: `/agents/${agentId}/actions`
|
|
407
|
+
});
|
|
408
|
+
return res.data;
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
// src/core/pagination.ts
|
|
413
|
+
var Page = class {
|
|
414
|
+
data;
|
|
415
|
+
meta;
|
|
416
|
+
requestId;
|
|
417
|
+
fetcher;
|
|
418
|
+
constructor(init) {
|
|
419
|
+
this.data = init.data;
|
|
420
|
+
this.meta = init.meta;
|
|
421
|
+
this.requestId = init.requestId;
|
|
422
|
+
this.fetcher = init.fetcher;
|
|
423
|
+
}
|
|
424
|
+
get hasNextPage() {
|
|
425
|
+
return this.meta?.has_next_page === true;
|
|
426
|
+
}
|
|
427
|
+
async getNextPage() {
|
|
428
|
+
if (!this.hasNextPage || !this.meta) return null;
|
|
429
|
+
return this.fetcher(this.meta.current_page + 1);
|
|
430
|
+
}
|
|
431
|
+
async *[Symbol.asyncIterator]() {
|
|
432
|
+
let cursor = this;
|
|
433
|
+
while (cursor) {
|
|
434
|
+
for (const item of cursor.data) yield item;
|
|
435
|
+
cursor = await cursor.getNextPage();
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
async *pages() {
|
|
439
|
+
let cursor = this;
|
|
440
|
+
while (cursor) {
|
|
441
|
+
yield cursor;
|
|
442
|
+
cursor = await cursor.getNextPage();
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
var PagePromise = class {
|
|
447
|
+
load;
|
|
448
|
+
constructor(load) {
|
|
449
|
+
this.load = load;
|
|
450
|
+
}
|
|
451
|
+
// biome-ignore lint/suspicious/noThenProperty: this is an intentional thenable so list() can be awaited
|
|
452
|
+
then(onfulfilled, onrejected) {
|
|
453
|
+
return this.load().then(onfulfilled, onrejected);
|
|
454
|
+
}
|
|
455
|
+
catch(onrejected) {
|
|
456
|
+
return this.load().then(void 0, onrejected);
|
|
457
|
+
}
|
|
458
|
+
finally(onfinally) {
|
|
459
|
+
return this.load().finally(onfinally);
|
|
460
|
+
}
|
|
461
|
+
async *[Symbol.asyncIterator]() {
|
|
462
|
+
const first = await this.load();
|
|
463
|
+
yield* first;
|
|
464
|
+
}
|
|
465
|
+
pages() {
|
|
466
|
+
const load = this.load;
|
|
467
|
+
return {
|
|
468
|
+
async *[Symbol.asyncIterator]() {
|
|
469
|
+
const first = await load();
|
|
470
|
+
yield* first.pages();
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
// src/resources/agents/channels.ts
|
|
477
|
+
var AgentChannels = class {
|
|
478
|
+
constructor(client) {
|
|
479
|
+
this.client = client;
|
|
480
|
+
}
|
|
481
|
+
client;
|
|
482
|
+
async list(agentId) {
|
|
483
|
+
const res = await this.client.request({
|
|
484
|
+
method: "GET",
|
|
485
|
+
path: `/agents/${agentId}/channels`
|
|
486
|
+
});
|
|
487
|
+
return res.data;
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
// src/resources/agents/conversation-flows.ts
|
|
492
|
+
var AgentConversationFlows = class {
|
|
493
|
+
constructor(client) {
|
|
494
|
+
this.client = client;
|
|
495
|
+
}
|
|
496
|
+
client;
|
|
497
|
+
async list(agentId) {
|
|
498
|
+
const res = await this.client.request({
|
|
499
|
+
method: "GET",
|
|
500
|
+
path: `/agents/${agentId}/conversation_flows`
|
|
501
|
+
});
|
|
502
|
+
return res.data;
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
// src/resources/agents/integrations.ts
|
|
507
|
+
var AgentIntegrations = class {
|
|
508
|
+
constructor(client) {
|
|
509
|
+
this.client = client;
|
|
510
|
+
}
|
|
511
|
+
client;
|
|
512
|
+
async list(agentId) {
|
|
513
|
+
const res = await this.client.request({
|
|
514
|
+
method: "GET",
|
|
515
|
+
path: `/agents/${agentId}/integrations`
|
|
516
|
+
});
|
|
517
|
+
return res.data;
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
// src/resources/agents/knowledge-bases.ts
|
|
522
|
+
var AgentKnowledgeBases = class {
|
|
523
|
+
constructor(client) {
|
|
524
|
+
this.client = client;
|
|
525
|
+
}
|
|
526
|
+
client;
|
|
527
|
+
async list(agentId) {
|
|
528
|
+
const res = await this.client.request({
|
|
529
|
+
method: "GET",
|
|
530
|
+
path: `/agents/${agentId}/knowledge_bases`
|
|
531
|
+
});
|
|
532
|
+
return res.data;
|
|
533
|
+
}
|
|
534
|
+
async create(agentId, body, options = {}) {
|
|
535
|
+
const res = await this.client.request({
|
|
536
|
+
method: "POST",
|
|
537
|
+
path: `/agents/${agentId}/knowledge_bases`,
|
|
538
|
+
body,
|
|
539
|
+
...options
|
|
540
|
+
});
|
|
541
|
+
return res.data;
|
|
542
|
+
}
|
|
543
|
+
async update(agentId, kbId, body) {
|
|
544
|
+
const res = await this.client.request({
|
|
545
|
+
method: "PATCH",
|
|
546
|
+
path: `/agents/${agentId}/knowledge_bases/${kbId}`,
|
|
547
|
+
body
|
|
548
|
+
});
|
|
549
|
+
return res.data;
|
|
550
|
+
}
|
|
551
|
+
async delete(agentId, kbId) {
|
|
552
|
+
await this.client.request({
|
|
553
|
+
method: "DELETE",
|
|
554
|
+
path: `/agents/${agentId}/knowledge_bases/${kbId}`
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
// src/resources/agents/agents.ts
|
|
560
|
+
var Agents = class {
|
|
561
|
+
constructor(client) {
|
|
562
|
+
this.client = client;
|
|
563
|
+
this.integrations = new AgentIntegrations(client);
|
|
564
|
+
this.channels = new AgentChannels(client);
|
|
565
|
+
this.conversationFlows = new AgentConversationFlows(client);
|
|
566
|
+
this.actions = new AgentActions(client);
|
|
567
|
+
this.knowledgeBases = new AgentKnowledgeBases(client);
|
|
568
|
+
}
|
|
569
|
+
client;
|
|
570
|
+
integrations;
|
|
571
|
+
channels;
|
|
572
|
+
conversationFlows;
|
|
573
|
+
actions;
|
|
574
|
+
knowledgeBases;
|
|
575
|
+
list(query = {}) {
|
|
576
|
+
return new PagePromise(() => this.fetchPage(query.page ?? 1, query));
|
|
577
|
+
}
|
|
578
|
+
async create(body, options = {}) {
|
|
579
|
+
const res = await this.client.request({
|
|
580
|
+
method: "POST",
|
|
581
|
+
path: "/agents",
|
|
582
|
+
body,
|
|
583
|
+
...options
|
|
584
|
+
});
|
|
585
|
+
return res.data;
|
|
586
|
+
}
|
|
587
|
+
async retrieve(agentId) {
|
|
588
|
+
const res = await this.client.request({
|
|
589
|
+
method: "GET",
|
|
590
|
+
path: `/agents/${agentId}`
|
|
591
|
+
});
|
|
592
|
+
return res.data;
|
|
593
|
+
}
|
|
594
|
+
async update(agentId, body) {
|
|
595
|
+
const res = await this.client.request({
|
|
596
|
+
method: "PATCH",
|
|
597
|
+
path: `/agents/${agentId}`,
|
|
598
|
+
body
|
|
599
|
+
});
|
|
600
|
+
return res.data;
|
|
601
|
+
}
|
|
602
|
+
async fetchPage(page, query) {
|
|
603
|
+
const res = await this.client.request({
|
|
604
|
+
method: "GET",
|
|
605
|
+
path: "/agents",
|
|
606
|
+
query: { page, limit: query.limit, search: query.search, sort: query.sort }
|
|
607
|
+
});
|
|
608
|
+
return new Page({
|
|
609
|
+
data: res.data,
|
|
610
|
+
meta: res.meta,
|
|
611
|
+
requestId: res.requestId,
|
|
612
|
+
fetcher: (next) => this.fetchPage(next, query)
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
};
|
|
616
|
+
|
|
617
|
+
// src/resources/calls/calls.ts
|
|
618
|
+
var Calls = class {
|
|
619
|
+
constructor(client) {
|
|
620
|
+
this.client = client;
|
|
621
|
+
}
|
|
622
|
+
client;
|
|
623
|
+
async list() {
|
|
624
|
+
const res = await this.client.request({ method: "GET", path: "/calls" });
|
|
625
|
+
return res.data;
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
// src/resources/conversations/messages.ts
|
|
630
|
+
var Messages = class {
|
|
631
|
+
constructor(client) {
|
|
632
|
+
this.client = client;
|
|
633
|
+
}
|
|
634
|
+
client;
|
|
635
|
+
list(agentId, conversationId, query = {}) {
|
|
636
|
+
return new PagePromise(() => this.fetchPage(agentId, conversationId, query.page ?? 1, query));
|
|
637
|
+
}
|
|
638
|
+
async send(agentId, conversationId, body, options = {}) {
|
|
639
|
+
const res = await this.client.request({
|
|
640
|
+
method: "POST",
|
|
641
|
+
path: `/agents/${agentId}/conversations/${conversationId}/messages`,
|
|
642
|
+
body,
|
|
643
|
+
...options
|
|
644
|
+
});
|
|
645
|
+
return res.data;
|
|
646
|
+
}
|
|
647
|
+
async fetchPage(agentId, conversationId, page, query) {
|
|
648
|
+
const res = await this.client.request({
|
|
649
|
+
method: "GET",
|
|
650
|
+
path: `/agents/${agentId}/conversations/${conversationId}/messages`,
|
|
651
|
+
query: { page, limit: query.limit }
|
|
652
|
+
});
|
|
653
|
+
return new Page({
|
|
654
|
+
data: res.data,
|
|
655
|
+
meta: res.meta,
|
|
656
|
+
requestId: res.requestId,
|
|
657
|
+
fetcher: (next) => this.fetchPage(agentId, conversationId, next, query)
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
// src/resources/conversations/conversations.ts
|
|
663
|
+
var Conversations = class {
|
|
664
|
+
constructor(client) {
|
|
665
|
+
this.client = client;
|
|
666
|
+
this.messages = new Messages(client);
|
|
667
|
+
}
|
|
668
|
+
client;
|
|
669
|
+
messages;
|
|
670
|
+
list(agentId, query = {}) {
|
|
671
|
+
return new PagePromise(() => this.fetchPage(agentId, query.page ?? 1, query));
|
|
672
|
+
}
|
|
673
|
+
async retrieve(agentId, conversationId) {
|
|
674
|
+
const res = await this.client.request({
|
|
675
|
+
method: "GET",
|
|
676
|
+
path: `/agents/${agentId}/conversations/${conversationId}`
|
|
677
|
+
});
|
|
678
|
+
return res.data;
|
|
679
|
+
}
|
|
680
|
+
async fetchPage(agentId, page, query) {
|
|
681
|
+
const res = await this.client.request({
|
|
682
|
+
method: "GET",
|
|
683
|
+
path: `/agents/${agentId}/conversations`,
|
|
684
|
+
query: { page, limit: query.limit, search: query.search, channel: query.channel }
|
|
685
|
+
});
|
|
686
|
+
return new Page({
|
|
687
|
+
data: res.data,
|
|
688
|
+
meta: res.meta,
|
|
689
|
+
requestId: res.requestId,
|
|
690
|
+
fetcher: (next) => this.fetchPage(agentId, next, query)
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
|
|
695
|
+
// src/resources/workflows/workflows.ts
|
|
696
|
+
var Workflows = class {
|
|
697
|
+
constructor(client) {
|
|
698
|
+
this.client = client;
|
|
699
|
+
}
|
|
700
|
+
client;
|
|
701
|
+
list(query = {}) {
|
|
702
|
+
return new PagePromise(() => this.fetchPage(query.page ?? 1, query));
|
|
703
|
+
}
|
|
704
|
+
async create(body, options = {}) {
|
|
705
|
+
const res = await this.client.request({
|
|
706
|
+
method: "POST",
|
|
707
|
+
path: "/workflows",
|
|
708
|
+
body,
|
|
709
|
+
...options
|
|
710
|
+
});
|
|
711
|
+
return res.data;
|
|
712
|
+
}
|
|
713
|
+
async retrieve(workflowId) {
|
|
714
|
+
const res = await this.client.request({
|
|
715
|
+
method: "GET",
|
|
716
|
+
path: `/workflows/${workflowId}`
|
|
717
|
+
});
|
|
718
|
+
return res.data;
|
|
719
|
+
}
|
|
720
|
+
async update(workflowId, body) {
|
|
721
|
+
const res = await this.client.request({
|
|
722
|
+
method: "PATCH",
|
|
723
|
+
path: `/workflows/${workflowId}`,
|
|
724
|
+
body
|
|
725
|
+
});
|
|
726
|
+
return res.data;
|
|
727
|
+
}
|
|
728
|
+
async delete(workflowId) {
|
|
729
|
+
await this.client.request({
|
|
730
|
+
method: "DELETE",
|
|
731
|
+
path: `/workflows/${workflowId}`
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
async fetchPage(page, query) {
|
|
735
|
+
const res = await this.client.request({
|
|
736
|
+
method: "GET",
|
|
737
|
+
path: "/workflows",
|
|
738
|
+
query: {
|
|
739
|
+
page,
|
|
740
|
+
limit: query.limit,
|
|
741
|
+
search: query.search,
|
|
742
|
+
sort: query.sort,
|
|
743
|
+
scope: query.scope
|
|
744
|
+
}
|
|
745
|
+
});
|
|
746
|
+
return new Page({
|
|
747
|
+
data: res.data,
|
|
748
|
+
meta: res.meta,
|
|
749
|
+
requestId: res.requestId,
|
|
750
|
+
fetcher: (next) => this.fetchPage(next, query)
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
};
|
|
754
|
+
|
|
755
|
+
// src/client.ts
|
|
756
|
+
var BimpeAI = class {
|
|
757
|
+
agents;
|
|
758
|
+
workflows;
|
|
759
|
+
conversations;
|
|
760
|
+
calls;
|
|
761
|
+
http;
|
|
762
|
+
constructor(config) {
|
|
763
|
+
this.http = new HttpClient(config);
|
|
764
|
+
this.agents = new Agents(this.http);
|
|
765
|
+
this.workflows = new Workflows(this.http);
|
|
766
|
+
this.conversations = new Conversations(this.http);
|
|
767
|
+
this.calls = new Calls(this.http);
|
|
768
|
+
}
|
|
769
|
+
request(spec) {
|
|
770
|
+
return this.http.request(spec);
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
|
|
774
|
+
exports.AgentActions = AgentActions;
|
|
775
|
+
exports.AgentChannels = AgentChannels;
|
|
776
|
+
exports.AgentConversationFlows = AgentConversationFlows;
|
|
777
|
+
exports.AgentIntegrations = AgentIntegrations;
|
|
778
|
+
exports.AgentKnowledgeBases = AgentKnowledgeBases;
|
|
779
|
+
exports.Agents = Agents;
|
|
780
|
+
exports.ApiError = ApiError;
|
|
781
|
+
exports.AuthenticationError = AuthenticationError;
|
|
782
|
+
exports.BadRequestError = BadRequestError;
|
|
783
|
+
exports.BimpeAI = BimpeAI;
|
|
784
|
+
exports.BimpeAIError = BimpeAIError;
|
|
785
|
+
exports.Calls = Calls;
|
|
786
|
+
exports.ConflictError = ConflictError;
|
|
787
|
+
exports.ConnectionError = ConnectionError;
|
|
788
|
+
exports.ConnectionTimeoutError = ConnectionTimeoutError;
|
|
789
|
+
exports.Conversations = Conversations;
|
|
790
|
+
exports.InternalServerError = InternalServerError;
|
|
791
|
+
exports.Messages = Messages;
|
|
792
|
+
exports.NotFoundError = NotFoundError;
|
|
793
|
+
exports.NotImplementedError = NotImplementedError;
|
|
794
|
+
exports.Page = Page;
|
|
795
|
+
exports.PagePromise = PagePromise;
|
|
796
|
+
exports.PermissionDeniedError = PermissionDeniedError;
|
|
797
|
+
exports.RateLimitError = RateLimitError;
|
|
798
|
+
exports.UserError = UserError;
|
|
799
|
+
exports.VERSION = VERSION;
|
|
800
|
+
exports.ValidationError = ValidationError;
|
|
801
|
+
exports.Workflows = Workflows;
|
|
802
|
+
//# sourceMappingURL=index.cjs.map
|
|
803
|
+
//# sourceMappingURL=index.cjs.map
|