@cadraos/sdk 0.3.14-p46.4 → 0.3.15
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 +104 -53
- package/dist/ai-functions/react/index.cjs +176 -0
- package/dist/ai-functions/react/index.cjs.map +1 -0
- package/dist/ai-functions/react/index.d.cts +129 -0
- package/dist/ai-functions/react/index.d.ts +129 -0
- package/dist/ai-functions/react/index.js +153 -0
- package/dist/ai-functions/react/index.js.map +1 -0
- package/dist/ai-functions/server/index.cjs +296 -0
- package/dist/ai-functions/server/index.cjs.map +1 -0
- package/dist/ai-functions/server/index.d.cts +334 -0
- package/dist/ai-functions/server/index.d.ts +334 -0
- package/dist/ai-functions/server/index.js +284 -0
- package/dist/ai-functions/server/index.js.map +1 -0
- package/dist/chat/index.cjs +303 -17
- package/dist/chat/index.cjs.map +1 -1
- package/dist/chat/index.d.cts +211 -0
- package/dist/chat/index.d.ts +211 -0
- package/dist/chat/index.js +303 -17
- package/dist/chat/index.js.map +1 -1
- package/dist/index.cjs +225 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +279 -1
- package/dist/index.d.ts +279 -1
- package/dist/index.js +219 -4
- package/dist/index.js.map +1 -1
- package/dist/kanban/index.cjs +218 -3
- package/dist/kanban/index.cjs.map +1 -1
- package/dist/kanban/index.d.cts +211 -0
- package/dist/kanban/index.d.ts +211 -0
- package/dist/kanban/index.js +218 -3
- package/dist/kanban/index.js.map +1 -1
- package/dist/teams/index.cjs +218 -3
- package/dist/teams/index.cjs.map +1 -1
- package/dist/teams/index.d.cts +211 -0
- package/dist/teams/index.d.ts +211 -0
- package/dist/teams/index.js +218 -3
- package/dist/teams/index.js.map +1 -1
- package/package.json +21 -1
package/dist/teams/index.js
CHANGED
|
@@ -65,6 +65,14 @@ var CadraError = class extends Error {
|
|
|
65
65
|
details;
|
|
66
66
|
/** Request ID from server (for debugging) */
|
|
67
67
|
requestId;
|
|
68
|
+
/**
|
|
69
|
+
* The server's own `error.code` exactly as sent on the wire (e.g.
|
|
70
|
+
* `FUNCTION_NOT_PUBLISHED`, `DUPLICATE_REQUEST`, `VARIABLE_TYPE`).
|
|
71
|
+
* Populated by `parseApiError` for EVERY status. `code` keeps its historic
|
|
72
|
+
* per-class values (`conflict`, `server_error`, `validation_error`, …) for
|
|
73
|
+
* compatibility; branch on `serverCode` when you need the precise reason.
|
|
74
|
+
*/
|
|
75
|
+
serverCode;
|
|
68
76
|
constructor(message, code, status, details, requestId) {
|
|
69
77
|
super(message);
|
|
70
78
|
this.name = "CadraError";
|
|
@@ -142,6 +150,12 @@ function parseApiError(status, body, requestId) {
|
|
|
142
150
|
const message = errorBody?.error?.message ?? "An error occurred";
|
|
143
151
|
const code = errorBody?.error?.code ?? "unknown_error";
|
|
144
152
|
const details = errorBody?.error?.details;
|
|
153
|
+
const serverCode = typeof errorBody?.error?.code === "string" ? errorBody.error.code : void 0;
|
|
154
|
+
const error = buildApiError(status, message, code, details, requestId);
|
|
155
|
+
if (serverCode !== void 0) error.serverCode = serverCode;
|
|
156
|
+
return error;
|
|
157
|
+
}
|
|
158
|
+
function buildApiError(status, message, code, details, requestId) {
|
|
145
159
|
switch (status) {
|
|
146
160
|
case 400:
|
|
147
161
|
case 422: {
|
|
@@ -177,6 +191,42 @@ function parseApiError(status, body, requestId) {
|
|
|
177
191
|
}
|
|
178
192
|
}
|
|
179
193
|
|
|
194
|
+
// src/errors/ai-function-errors.ts
|
|
195
|
+
var AiFunctionDuplicateError = class extends ConflictError {
|
|
196
|
+
/** The existing run's execution id. */
|
|
197
|
+
executionId;
|
|
198
|
+
/** The existing run's status (`running`, a terminal status, or `abandoned`). */
|
|
199
|
+
runStatus;
|
|
200
|
+
constructor(message, details, requestId) {
|
|
201
|
+
super(message, details, requestId);
|
|
202
|
+
this.name = "AiFunctionDuplicateError";
|
|
203
|
+
this.serverCode = "DUPLICATE_REQUEST";
|
|
204
|
+
this.executionId = typeof details?.executionId === "string" ? details.executionId : void 0;
|
|
205
|
+
this.runStatus = typeof details?.status === "string" ? details.status : void 0;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
var AiFunctionChargedError = class extends CadraError {
|
|
209
|
+
constructor(source) {
|
|
210
|
+
super(source.message, source.code, source.status, source.details, source.requestId);
|
|
211
|
+
this.name = "AiFunctionChargedError";
|
|
212
|
+
this.serverCode = source.serverCode;
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
var AiFunctionParameterError = class extends ValidationError {
|
|
216
|
+
functionKey;
|
|
217
|
+
issues;
|
|
218
|
+
constructor(functionKey, issues) {
|
|
219
|
+
super(
|
|
220
|
+
`Invalid parameters for AI function "${functionKey}": ` + issues.map((i) => `${i.name} (${i.code})`).join(", "),
|
|
221
|
+
issues.map((i) => ({ field: i.name, message: i.code })),
|
|
222
|
+
{ functionKey, issues }
|
|
223
|
+
);
|
|
224
|
+
this.name = "AiFunctionParameterError";
|
|
225
|
+
this.functionKey = functionKey;
|
|
226
|
+
this.issues = issues;
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
180
230
|
// src/utils/retry.ts
|
|
181
231
|
var DEFAULT_RETRY_CONFIG = {
|
|
182
232
|
maxRetries: 3,
|
|
@@ -241,6 +291,10 @@ var HttpClient = class {
|
|
|
241
291
|
constructor(config) {
|
|
242
292
|
this.config = config;
|
|
243
293
|
}
|
|
294
|
+
/** The client-wide request timeout (ms) this client was configured with. */
|
|
295
|
+
get timeoutMs() {
|
|
296
|
+
return this.config.timeout;
|
|
297
|
+
}
|
|
244
298
|
/**
|
|
245
299
|
* Get authorization header value
|
|
246
300
|
*/
|
|
@@ -295,7 +349,8 @@ var HttpClient = class {
|
|
|
295
349
|
headers["Idempotency-Key"] = options.idempotencyKey;
|
|
296
350
|
}
|
|
297
351
|
const controller = new AbortController();
|
|
298
|
-
const
|
|
352
|
+
const timeoutMs = options.timeoutMs ?? this.config.timeout;
|
|
353
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
299
354
|
try {
|
|
300
355
|
const doFetch = this.config.fetch ?? fetch;
|
|
301
356
|
const response = await doFetch(url, {
|
|
@@ -331,7 +386,7 @@ var HttpClient = class {
|
|
|
331
386
|
} catch (error) {
|
|
332
387
|
clearTimeout(timeoutId);
|
|
333
388
|
if (error instanceof Error && error.name === "AbortError") {
|
|
334
|
-
throw new TimeoutError(`Request timed out after ${this.config.timeout}ms`);
|
|
389
|
+
throw new TimeoutError(`Request timed out after ${options.timeoutMs ?? this.config.timeout}ms`);
|
|
335
390
|
}
|
|
336
391
|
if (error instanceof TypeError && error.message.includes("fetch")) {
|
|
337
392
|
throw new NetworkError(`Network error: ${error.message}`);
|
|
@@ -363,7 +418,8 @@ var HttpClient = class {
|
|
|
363
418
|
path,
|
|
364
419
|
body,
|
|
365
420
|
idempotencyKey: options?.idempotencyKey,
|
|
366
|
-
skipRetry: options?.skipRetry
|
|
421
|
+
skipRetry: options?.skipRetry,
|
|
422
|
+
timeoutMs: options?.timeoutMs
|
|
367
423
|
});
|
|
368
424
|
}
|
|
369
425
|
/**
|
|
@@ -1112,6 +1168,10 @@ var ExecutionStreamControllerImpl = class {
|
|
|
1112
1168
|
toolName,
|
|
1113
1169
|
result: data.result,
|
|
1114
1170
|
durationMs: data.durationMs ?? 0,
|
|
1171
|
+
// CAD-243: pass the producer's failure verdict through.
|
|
1172
|
+
...data.isError === true ? { isError: true } : {},
|
|
1173
|
+
...typeof data.status === "string" ? { status: data.status } : {},
|
|
1174
|
+
...typeof data.error === "string" ? { error: data.error } : {},
|
|
1115
1175
|
forwardedFrom: event.data._forwardedFrom,
|
|
1116
1176
|
// CAD-87 S1-001 EventIdentity → (execId, seq) reducer dedup (S1-003).
|
|
1117
1177
|
sourceExecutionId: data.sourceExecutionId ?? data.executionId,
|
|
@@ -3350,6 +3410,156 @@ var RemoteRunnersAPI = class extends BaseResourceAPI {
|
|
|
3350
3410
|
}
|
|
3351
3411
|
};
|
|
3352
3412
|
|
|
3413
|
+
// src/resources/ai-functions.ts
|
|
3414
|
+
var AI_FUNCTION_RUN_TIMEOUT_MS = 31e4;
|
|
3415
|
+
var AI_FUNCTION_DESCRIPTOR_TTL_MS = 6e4;
|
|
3416
|
+
function checkAiFunctionParameters(parameters, variables) {
|
|
3417
|
+
const issues = [];
|
|
3418
|
+
const declared = /* @__PURE__ */ new Set();
|
|
3419
|
+
for (const p of parameters) {
|
|
3420
|
+
declared.add(p.name);
|
|
3421
|
+
const has = Object.prototype.hasOwnProperty.call(variables, p.name);
|
|
3422
|
+
const value = has ? variables[p.name] : void 0;
|
|
3423
|
+
if (value === void 0 || value === null) {
|
|
3424
|
+
if (p.required) issues.push({ name: p.name, code: "missing" });
|
|
3425
|
+
continue;
|
|
3426
|
+
}
|
|
3427
|
+
switch (p.type) {
|
|
3428
|
+
case "number":
|
|
3429
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
3430
|
+
issues.push({ name: p.name, code: "type" });
|
|
3431
|
+
}
|
|
3432
|
+
break;
|
|
3433
|
+
case "boolean":
|
|
3434
|
+
if (typeof value !== "boolean") issues.push({ name: p.name, code: "type" });
|
|
3435
|
+
break;
|
|
3436
|
+
case "enum":
|
|
3437
|
+
if (typeof value !== "string") issues.push({ name: p.name, code: "type" });
|
|
3438
|
+
else if (p.options && !p.options.includes(value)) {
|
|
3439
|
+
issues.push({ name: p.name, code: "option" });
|
|
3440
|
+
}
|
|
3441
|
+
break;
|
|
3442
|
+
case "string":
|
|
3443
|
+
case "text":
|
|
3444
|
+
if (typeof value !== "string") issues.push({ name: p.name, code: "type" });
|
|
3445
|
+
else if (typeof p.maxLength === "number" && value.length > p.maxLength) {
|
|
3446
|
+
issues.push({ name: p.name, code: "too_long" });
|
|
3447
|
+
}
|
|
3448
|
+
break;
|
|
3449
|
+
case "image":
|
|
3450
|
+
if (typeof value !== "string") issues.push({ name: p.name, code: "type" });
|
|
3451
|
+
break;
|
|
3452
|
+
}
|
|
3453
|
+
}
|
|
3454
|
+
for (const name of Object.keys(variables)) {
|
|
3455
|
+
if (!declared.has(name)) issues.push({ name, code: "unknown" });
|
|
3456
|
+
}
|
|
3457
|
+
return issues;
|
|
3458
|
+
}
|
|
3459
|
+
var AiFunctionsAPI = class extends BaseResourceAPI {
|
|
3460
|
+
descriptorCache = /* @__PURE__ */ new Map();
|
|
3461
|
+
constructor(http) {
|
|
3462
|
+
super(http, "/api/v1/ai-functions");
|
|
3463
|
+
}
|
|
3464
|
+
/**
|
|
3465
|
+
* List the functions this org can call — the index (D27a). Each entry carries
|
|
3466
|
+
* the live version's typed parameters; never prompt text.
|
|
3467
|
+
*/
|
|
3468
|
+
async list() {
|
|
3469
|
+
const data = await this.httpGet("");
|
|
3470
|
+
const functions = Array.isArray(data) ? data : data?.functions ?? [];
|
|
3471
|
+
for (const d of functions) this.cacheDescriptor(d);
|
|
3472
|
+
return functions;
|
|
3473
|
+
}
|
|
3474
|
+
/**
|
|
3475
|
+
* Get one function's descriptor by key (D27a).
|
|
3476
|
+
* `NotFoundError` (`FUNCTION_NOT_FOUND`) / `ConflictError` (`FUNCTION_NOT_PUBLISHED`).
|
|
3477
|
+
*/
|
|
3478
|
+
async get(functionKey) {
|
|
3479
|
+
const data = await this.httpGet(
|
|
3480
|
+
`/${encodeURIComponent(functionKey)}`
|
|
3481
|
+
);
|
|
3482
|
+
const descriptor = data && typeof data === "object" && "function" in data && !("functionKey" in data) ? data.function : data;
|
|
3483
|
+
this.cacheDescriptor(descriptor, functionKey);
|
|
3484
|
+
return descriptor;
|
|
3485
|
+
}
|
|
3486
|
+
/**
|
|
3487
|
+
* Read one of this org's own runs (safe projection, §6.5).
|
|
3488
|
+
*/
|
|
3489
|
+
async getRun(executionId) {
|
|
3490
|
+
return this.httpGet(`/runs/${encodeURIComponent(executionId)}`);
|
|
3491
|
+
}
|
|
3492
|
+
/** Forget cached descriptors (one key, or all). */
|
|
3493
|
+
clearDescriptorCache(functionKey) {
|
|
3494
|
+
if (functionKey) this.descriptorCache.delete(functionKey);
|
|
3495
|
+
else this.descriptorCache.clear();
|
|
3496
|
+
}
|
|
3497
|
+
async run(refOrKey, parametersOrOptions, shorthandOpts) {
|
|
3498
|
+
let ref;
|
|
3499
|
+
let options;
|
|
3500
|
+
if (typeof refOrKey === "string") {
|
|
3501
|
+
ref = { functionKey: refOrKey };
|
|
3502
|
+
options = { ...shorthandOpts ?? {}, variables: parametersOrOptions };
|
|
3503
|
+
} else {
|
|
3504
|
+
ref = refOrKey;
|
|
3505
|
+
options = parametersOrOptions;
|
|
3506
|
+
}
|
|
3507
|
+
const variables = options.variables ?? {};
|
|
3508
|
+
const functionKey = "functionKey" in ref ? ref.functionKey : void 0;
|
|
3509
|
+
const shouldCheck = functionKey !== void 0 && options.version === void 0 && options.validate !== false;
|
|
3510
|
+
if (shouldCheck) {
|
|
3511
|
+
const descriptor = await this.getCachedDescriptor(functionKey);
|
|
3512
|
+
const issues = checkAiFunctionParameters(descriptor.parameters, variables);
|
|
3513
|
+
if (issues.length > 0) {
|
|
3514
|
+
throw new AiFunctionParameterError(functionKey, issues);
|
|
3515
|
+
}
|
|
3516
|
+
}
|
|
3517
|
+
const body = {
|
|
3518
|
+
ref,
|
|
3519
|
+
variables,
|
|
3520
|
+
version: options.version,
|
|
3521
|
+
idempotencyKey: options.idempotencyKey ?? generateExecutionId(),
|
|
3522
|
+
params: options.params
|
|
3523
|
+
};
|
|
3524
|
+
try {
|
|
3525
|
+
return await this.httpPost("/run", body, {
|
|
3526
|
+
skipRetry: true,
|
|
3527
|
+
timeoutMs: Math.max(AI_FUNCTION_RUN_TIMEOUT_MS, this.http.timeoutMs ?? 0)
|
|
3528
|
+
});
|
|
3529
|
+
} catch (error) {
|
|
3530
|
+
throw this.mapRunError(error, functionKey);
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
// ── internals ──────────────────────────────────────────────────────────────
|
|
3534
|
+
cacheDescriptor(descriptor, key) {
|
|
3535
|
+
if (!descriptor || typeof descriptor !== "object") return;
|
|
3536
|
+
const cacheKey = key ?? descriptor.functionKey;
|
|
3537
|
+
if (!cacheKey) return;
|
|
3538
|
+
this.descriptorCache.set(cacheKey, {
|
|
3539
|
+
descriptor,
|
|
3540
|
+
expiresAt: Date.now() + AI_FUNCTION_DESCRIPTOR_TTL_MS
|
|
3541
|
+
});
|
|
3542
|
+
}
|
|
3543
|
+
async getCachedDescriptor(functionKey) {
|
|
3544
|
+
const hit = this.descriptorCache.get(functionKey);
|
|
3545
|
+
if (hit && hit.expiresAt > Date.now()) return hit.descriptor;
|
|
3546
|
+
return this.get(functionKey);
|
|
3547
|
+
}
|
|
3548
|
+
mapRunError(error, functionKey) {
|
|
3549
|
+
if (!(error instanceof CadraError)) return error;
|
|
3550
|
+
if (error.serverCode === "DUPLICATE_REQUEST") {
|
|
3551
|
+
return new AiFunctionDuplicateError(error.message, error.details, error.requestId);
|
|
3552
|
+
}
|
|
3553
|
+
if (error.details?.charged === true) {
|
|
3554
|
+
return new AiFunctionChargedError(error);
|
|
3555
|
+
}
|
|
3556
|
+
if (functionKey && error.serverCode?.startsWith("VARIABLE_")) {
|
|
3557
|
+
this.descriptorCache.delete(functionKey);
|
|
3558
|
+
}
|
|
3559
|
+
return error;
|
|
3560
|
+
}
|
|
3561
|
+
};
|
|
3562
|
+
|
|
3353
3563
|
// src/client.ts
|
|
3354
3564
|
var DEFAULT_BASE_URL = "https://api.cadraos.com";
|
|
3355
3565
|
var DEFAULT_TIMEOUT = 3e4;
|
|
@@ -3396,6 +3606,10 @@ var CadraClient = class {
|
|
|
3396
3606
|
* Remote runner operations (list)
|
|
3397
3607
|
*/
|
|
3398
3608
|
remoteRunners;
|
|
3609
|
+
/**
|
|
3610
|
+
* AI function operations (list, get, run, getRun) — p93
|
|
3611
|
+
*/
|
|
3612
|
+
aiFunctions;
|
|
3399
3613
|
/**
|
|
3400
3614
|
* Create a new AI SaaS client
|
|
3401
3615
|
*
|
|
@@ -3485,6 +3699,7 @@ var CadraClient = class {
|
|
|
3485
3699
|
this.kanban = new KanbanAPI(this.httpClient, getStreamConfig);
|
|
3486
3700
|
this.remoteAgents = new RemoteAgentsAPI(this.httpClient, getStreamConfig);
|
|
3487
3701
|
this.remoteRunners = new RemoteRunnersAPI(this.httpClient);
|
|
3702
|
+
this.aiFunctions = new AiFunctionsAPI(this.httpClient);
|
|
3488
3703
|
}
|
|
3489
3704
|
/**
|
|
3490
3705
|
* Validate client options
|