@ancha-labs/cli 0.4.36 → 0.4.38
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/lib/ancha.mjs +9490 -8945
- package/lib/assets/docs/cloud.md +25 -0
- package/lib/assets/docs/tools.md +1 -1
- package/lib/assets/harbor/companion.mjs +305 -188
- package/lib/assets/ui/app.js +1 -1
- package/lib/mcp-entry.mjs +3 -0
- package/lib/worker.mjs +167102 -166604
- package/lib/world-server.mjs +5 -2
- package/package.json +1 -1
|
@@ -54385,7 +54385,7 @@ var require_websocket = __commonJS({
|
|
|
54385
54385
|
var http = __require("http");
|
|
54386
54386
|
var net = __require("net");
|
|
54387
54387
|
var tls = __require("tls");
|
|
54388
|
-
var { randomBytes: randomBytes4, createHash:
|
|
54388
|
+
var { randomBytes: randomBytes4, createHash: createHash58 } = __require("crypto");
|
|
54389
54389
|
var { Duplex, Readable: Readable2 } = __require("stream");
|
|
54390
54390
|
var { URL: URL2 } = __require("url");
|
|
54391
54391
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
@@ -55066,7 +55066,7 @@ var require_websocket = __commonJS({
|
|
|
55066
55066
|
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
55067
55067
|
return;
|
|
55068
55068
|
}
|
|
55069
|
-
const digest3 =
|
|
55069
|
+
const digest3 = createHash58("sha1").update(key5 + GUID).digest("base64");
|
|
55070
55070
|
if (res.headers["sec-websocket-accept"] !== digest3) {
|
|
55071
55071
|
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
55072
55072
|
return;
|
|
@@ -55435,7 +55435,7 @@ var require_websocket_server = __commonJS({
|
|
|
55435
55435
|
var EventEmitter2 = __require("events");
|
|
55436
55436
|
var http = __require("http");
|
|
55437
55437
|
var { Duplex } = __require("stream");
|
|
55438
|
-
var { createHash:
|
|
55438
|
+
var { createHash: createHash58 } = __require("crypto");
|
|
55439
55439
|
var extension2 = require_extension();
|
|
55440
55440
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
55441
55441
|
var subprotocol2 = require_subprotocol();
|
|
@@ -55742,7 +55742,7 @@ var require_websocket_server = __commonJS({
|
|
|
55742
55742
|
);
|
|
55743
55743
|
}
|
|
55744
55744
|
if (this._state > RUNNING) return abortHandshake(socket, 503);
|
|
55745
|
-
const digest3 =
|
|
55745
|
+
const digest3 = createHash58("sha1").update(key5 + GUID).digest("base64");
|
|
55746
55746
|
const headers = [
|
|
55747
55747
|
"HTTP/1.1 101 Switching Protocols",
|
|
55748
55748
|
"Upgrade: websocket",
|
|
@@ -56474,121 +56474,6 @@ var serve = (options4, listeningListener) => {
|
|
|
56474
56474
|
return server;
|
|
56475
56475
|
};
|
|
56476
56476
|
|
|
56477
|
-
// packages/core/src/errors.ts
|
|
56478
|
-
var AnchaError = class extends Error {
|
|
56479
|
-
code;
|
|
56480
|
-
hint;
|
|
56481
|
-
docs;
|
|
56482
|
-
constructor(code2, message9, opts = {}) {
|
|
56483
|
-
super(message9, opts.cause === void 0 ? void 0 : { cause: opts.cause });
|
|
56484
|
-
this.name = "AnchaError";
|
|
56485
|
-
this.code = code2;
|
|
56486
|
-
if (opts.hint !== void 0) this.hint = opts.hint;
|
|
56487
|
-
if (opts.docs !== void 0) this.docs = opts.docs;
|
|
56488
|
-
}
|
|
56489
|
-
};
|
|
56490
|
-
function toErrorJson(e) {
|
|
56491
|
-
if (e instanceof AnchaError) {
|
|
56492
|
-
const out = { code: e.code, message: e.message };
|
|
56493
|
-
if (e.hint !== void 0) out.hint = e.hint;
|
|
56494
|
-
if (e.docs !== void 0) out.docs = e.docs;
|
|
56495
|
-
return out;
|
|
56496
|
-
}
|
|
56497
|
-
return { code: "INTERNAL", message: e instanceof Error ? e.message : String(e) };
|
|
56498
|
-
}
|
|
56499
|
-
|
|
56500
|
-
// packages/core/src/execution-support.ts
|
|
56501
|
-
var all = { local: true, container: true, managed: true, "cloud-vm": true };
|
|
56502
|
-
var sceneOnly = { local: true, container: true, managed: false, "cloud-vm": true };
|
|
56503
|
-
var thisComputer = { local: true, container: true, managed: false, "cloud-vm": false };
|
|
56504
|
-
var localOnly = { local: true, container: false, managed: false, "cloud-vm": false };
|
|
56505
|
-
var EXECUTION_SUPPORT = {
|
|
56506
|
-
"input.scene": { ...sceneOnly, reason: "scene worlds cannot be imported without changing their semantics" },
|
|
56507
|
-
"input.test": { ...sceneOnly, reason: "local test worlds cannot be equated with saved managed worlds" },
|
|
56508
|
-
"input.managed-task": { local: false, container: false, managed: true, "cloud-vm": false, reason: "explicit saved-world tasks use runs start or the console" },
|
|
56509
|
-
"managed.world-reference": { local: false, container: false, managed: true, "cloud-vm": false, reason: "an explicit reference to an existing managed world, not an imported local world" },
|
|
56510
|
-
"id": all,
|
|
56511
|
-
"title": all,
|
|
56512
|
-
"task": sceneOnly,
|
|
56513
|
-
"start.task": all,
|
|
56514
|
-
"attempts": all,
|
|
56515
|
-
"twins": sceneOnly,
|
|
56516
|
-
"world": sceneOnly,
|
|
56517
|
-
"start_time": sceneOnly,
|
|
56518
|
-
"time_scale": sceneOnly,
|
|
56519
|
-
"skip_idle": sceneOnly,
|
|
56520
|
-
"seed": sceneOnly,
|
|
56521
|
-
"world_rules": sceneOnly,
|
|
56522
|
-
"people": sceneOnly,
|
|
56523
|
-
"until": sceneOnly,
|
|
56524
|
-
"trigger": sceneOnly,
|
|
56525
|
-
"tools": sceneOnly,
|
|
56526
|
-
"deadline": sceneOnly,
|
|
56527
|
-
"start.message": sceneOnly,
|
|
56528
|
-
"pass": sceneOnly,
|
|
56529
|
-
"agent_input": sceneOnly,
|
|
56530
|
-
"scene.timeout": sceneOnly,
|
|
56531
|
-
"test.timeout": all,
|
|
56532
|
-
"checks.state": all,
|
|
56533
|
-
"checks.trace": all,
|
|
56534
|
-
"checks.answer": all,
|
|
56535
|
-
"checks.process": all,
|
|
56536
|
-
"checks.judge": sceneOnly,
|
|
56537
|
-
"agent.input.command": all,
|
|
56538
|
-
"agent.input.per_event": sceneOnly,
|
|
56539
|
-
"agent.input.events": localOnly,
|
|
56540
|
-
"agent.input.http": all,
|
|
56541
|
-
"agent.endpoint": { ...localOnly, "cloud-vm": true },
|
|
56542
|
-
"agent.slack_transport.feed": sceneOnly,
|
|
56543
|
-
"agent.slack_transport.http": { ...localOnly, "cloud-vm": true },
|
|
56544
|
-
"agent.slack_transport.socket": { ...localOnly, "cloud-vm": true },
|
|
56545
|
-
"agent.env": sceneOnly,
|
|
56546
|
-
"agent.pass_env": sceneOnly,
|
|
56547
|
-
"agent.execution": sceneOnly,
|
|
56548
|
-
"judge": sceneOnly,
|
|
56549
|
-
"min_pass_rate": sceneOnly,
|
|
56550
|
-
"--agent": all,
|
|
56551
|
-
"--trials": all,
|
|
56552
|
-
"--attempts": all,
|
|
56553
|
-
"--parallel": all,
|
|
56554
|
-
"--concurrency": all,
|
|
56555
|
-
"--idempotency-key": all,
|
|
56556
|
-
"--on": all,
|
|
56557
|
-
"--json": all,
|
|
56558
|
-
"--agent-url": localOnly,
|
|
56559
|
-
"--compare": sceneOnly,
|
|
56560
|
-
"--min-pass-rate": sceneOnly,
|
|
56561
|
-
"--strict": sceneOnly,
|
|
56562
|
-
"--allow-simulated": sceneOnly,
|
|
56563
|
-
"--seed": sceneOnly,
|
|
56564
|
-
"--out": thisComputer,
|
|
56565
|
-
"--detach": sceneOnly,
|
|
56566
|
-
"--pass-env": thisComputer,
|
|
56567
|
-
"--inherit-env": thisComputer,
|
|
56568
|
-
"--upload": thisComputer,
|
|
56569
|
-
"--upload-required": thisComputer,
|
|
56570
|
-
"--allow-unwrapped": sceneOnly,
|
|
56571
|
-
"--bundle-file": { local: false, container: false, managed: false, "cloud-vm": true, reason: "files a cloud run carries besides the project and its tests" }
|
|
56572
|
-
};
|
|
56573
|
-
|
|
56574
|
-
// packages/core/src/relay.ts
|
|
56575
|
-
function relayRefusal(status4, body7) {
|
|
56576
|
-
const error64 = typeof body7 === "object" && body7 !== null ? body7.error : void 0;
|
|
56577
|
-
const code2 = typeof error64?.code === "string" ? error64.code : void 0;
|
|
56578
|
-
const said = typeof error64?.message === "string" ? `: ${error64.message}` : "";
|
|
56579
|
-
const ownKey = "or set OPENROUTER_API_KEY to use your own model key";
|
|
56580
|
-
if (code2 === "MODEL_CREDIT_EXHAUSTED" || status4 === 402) return new AnchaError("CONFIG_INVALID", `the workspace is out of model credit${said}`, { hint: `add credit in the workspace's Settings, ${ownKey}` });
|
|
56581
|
-
if (code2 === "MODEL_KEYS_OFF") return new AnchaError("CONFIG_INVALID", `model calls are turned off for this workspace${said}`, { hint: `ask the workspace's owner to turn them on, ${ownKey}` });
|
|
56582
|
-
if (code2 === "MODEL_KEY_UNAVAILABLE") return new AnchaError("SERVER_UNREACHABLE", `the workspace has no model key right now${said}`, { hint: `try again in a few minutes, ${ownKey}` });
|
|
56583
|
-
if (code2 === "MODEL_NOT_ALLOWED") return new AnchaError("CONFIG_INVALID", `the workspace's relay doesn't serve this model${said}`, { hint: `use one of the models it names, ${ownKey}` });
|
|
56584
|
-
if (code2 === "RELAY_FIELD_NOT_ALLOWED" || code2 === "MAX_TOKENS_TOO_HIGH") {
|
|
56585
|
-
const reason2 = typeof error64?.message === "string" ? error64.message : code2;
|
|
56586
|
-
return new AnchaError("INTERNAL", `Ancha's request to the workspace model relay was refused (${reason2}): a bug in Ancha, not your input`, { hint: ownKey });
|
|
56587
|
-
}
|
|
56588
|
-
if (status4 === 413) return new AnchaError("USAGE", "the request is larger than the workspace's relay accepts (256 KB)", { hint: "shorten the description or the world" });
|
|
56589
|
-
return void 0;
|
|
56590
|
-
}
|
|
56591
|
-
|
|
56592
56477
|
// node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/classic/external.js
|
|
56593
56478
|
var external_exports = {};
|
|
56594
56479
|
__export(external_exports, {
|
|
@@ -76306,6 +76191,124 @@ function date4(params10) {
|
|
|
76306
76191
|
return _coercedDate(ZodDate, params10);
|
|
76307
76192
|
}
|
|
76308
76193
|
|
|
76194
|
+
// packages/core/src/errors.ts
|
|
76195
|
+
var AnchaError = class extends Error {
|
|
76196
|
+
code;
|
|
76197
|
+
hint;
|
|
76198
|
+
docs;
|
|
76199
|
+
constructor(code2, message9, opts = {}) {
|
|
76200
|
+
super(message9, opts.cause === void 0 ? void 0 : { cause: opts.cause });
|
|
76201
|
+
this.name = "AnchaError";
|
|
76202
|
+
this.code = code2;
|
|
76203
|
+
if (opts.hint !== void 0) this.hint = opts.hint;
|
|
76204
|
+
if (opts.docs !== void 0) this.docs = opts.docs;
|
|
76205
|
+
}
|
|
76206
|
+
};
|
|
76207
|
+
function toErrorJson(e) {
|
|
76208
|
+
if (e instanceof AnchaError) {
|
|
76209
|
+
const out = { code: e.code, message: e.message };
|
|
76210
|
+
if (e.hint !== void 0) out.hint = e.hint;
|
|
76211
|
+
if (e.docs !== void 0) out.docs = e.docs;
|
|
76212
|
+
return out;
|
|
76213
|
+
}
|
|
76214
|
+
return { code: "INTERNAL", message: e instanceof Error ? e.message : String(e) };
|
|
76215
|
+
}
|
|
76216
|
+
|
|
76217
|
+
// packages/core/src/agent-routes.ts
|
|
76218
|
+
var agentRoutesSchema = external_exports.strictObject({ quickbooks: external_exports.literal("composio").optional() });
|
|
76219
|
+
|
|
76220
|
+
// packages/core/src/execution-support.ts
|
|
76221
|
+
var all = { local: true, container: true, managed: true, "cloud-vm": true };
|
|
76222
|
+
var sceneOnly = { local: true, container: true, managed: false, "cloud-vm": true };
|
|
76223
|
+
var thisComputer = { local: true, container: true, managed: false, "cloud-vm": false };
|
|
76224
|
+
var localOnly = { local: true, container: false, managed: false, "cloud-vm": false };
|
|
76225
|
+
var EXECUTION_SUPPORT = {
|
|
76226
|
+
"input.scene": { ...sceneOnly, reason: "scene worlds cannot be imported without changing their semantics" },
|
|
76227
|
+
"input.test": { ...sceneOnly, reason: "local test worlds cannot be equated with saved managed worlds" },
|
|
76228
|
+
"input.managed-task": { local: false, container: false, managed: true, "cloud-vm": false, reason: "explicit saved-world tasks use runs start or the console" },
|
|
76229
|
+
"managed.world-reference": { local: false, container: false, managed: true, "cloud-vm": false, reason: "an explicit reference to an existing managed world, not an imported local world" },
|
|
76230
|
+
"id": all,
|
|
76231
|
+
"title": all,
|
|
76232
|
+
"task": sceneOnly,
|
|
76233
|
+
"start.task": all,
|
|
76234
|
+
"attempts": all,
|
|
76235
|
+
"twins": sceneOnly,
|
|
76236
|
+
"world": sceneOnly,
|
|
76237
|
+
"start_time": sceneOnly,
|
|
76238
|
+
"time_scale": sceneOnly,
|
|
76239
|
+
"skip_idle": sceneOnly,
|
|
76240
|
+
"seed": sceneOnly,
|
|
76241
|
+
"world_rules": sceneOnly,
|
|
76242
|
+
"people": sceneOnly,
|
|
76243
|
+
"until": sceneOnly,
|
|
76244
|
+
"trigger": sceneOnly,
|
|
76245
|
+
"tools": sceneOnly,
|
|
76246
|
+
"deadline": sceneOnly,
|
|
76247
|
+
"start.message": sceneOnly,
|
|
76248
|
+
"pass": sceneOnly,
|
|
76249
|
+
"agent_input": sceneOnly,
|
|
76250
|
+
"scene.timeout": sceneOnly,
|
|
76251
|
+
"test.timeout": all,
|
|
76252
|
+
"checks.state": all,
|
|
76253
|
+
"checks.trace": all,
|
|
76254
|
+
"checks.answer": all,
|
|
76255
|
+
"checks.process": all,
|
|
76256
|
+
"checks.judge": sceneOnly,
|
|
76257
|
+
"agent.input.command": all,
|
|
76258
|
+
"agent.input.per_event": sceneOnly,
|
|
76259
|
+
"agent.input.events": localOnly,
|
|
76260
|
+
"agent.input.http": all,
|
|
76261
|
+
"agent.endpoint": { ...localOnly, "cloud-vm": true },
|
|
76262
|
+
"agent.slack_transport.feed": sceneOnly,
|
|
76263
|
+
"agent.slack_transport.http": { ...localOnly, "cloud-vm": true },
|
|
76264
|
+
"agent.slack_transport.socket": { ...localOnly, "cloud-vm": true },
|
|
76265
|
+
"agent.env": sceneOnly,
|
|
76266
|
+
"agent.pass_env": sceneOnly,
|
|
76267
|
+
"agent.execution": sceneOnly,
|
|
76268
|
+
"judge": sceneOnly,
|
|
76269
|
+
"min_pass_rate": sceneOnly,
|
|
76270
|
+
"--agent": all,
|
|
76271
|
+
"--trials": all,
|
|
76272
|
+
"--attempts": all,
|
|
76273
|
+
"--parallel": all,
|
|
76274
|
+
"--concurrency": all,
|
|
76275
|
+
"--idempotency-key": all,
|
|
76276
|
+
"--on": all,
|
|
76277
|
+
"--json": all,
|
|
76278
|
+
"--agent-url": localOnly,
|
|
76279
|
+
"--compare": sceneOnly,
|
|
76280
|
+
"--min-pass-rate": sceneOnly,
|
|
76281
|
+
"--strict": sceneOnly,
|
|
76282
|
+
"--allow-simulated": sceneOnly,
|
|
76283
|
+
"--seed": sceneOnly,
|
|
76284
|
+
"--out": thisComputer,
|
|
76285
|
+
"--detach": sceneOnly,
|
|
76286
|
+
"--pass-env": thisComputer,
|
|
76287
|
+
"--inherit-env": thisComputer,
|
|
76288
|
+
"--upload": thisComputer,
|
|
76289
|
+
"--upload-required": thisComputer,
|
|
76290
|
+
"--allow-unwrapped": sceneOnly,
|
|
76291
|
+
"--bundle-file": { local: false, container: false, managed: false, "cloud-vm": true, reason: "files a cloud run carries besides the project and its tests" }
|
|
76292
|
+
};
|
|
76293
|
+
|
|
76294
|
+
// packages/core/src/relay.ts
|
|
76295
|
+
function relayRefusal(status4, body7) {
|
|
76296
|
+
const error64 = typeof body7 === "object" && body7 !== null ? body7.error : void 0;
|
|
76297
|
+
const code2 = typeof error64?.code === "string" ? error64.code : void 0;
|
|
76298
|
+
const said = typeof error64?.message === "string" ? `: ${error64.message}` : "";
|
|
76299
|
+
const ownKey = "or set OPENROUTER_API_KEY to use your own model key";
|
|
76300
|
+
if (code2 === "MODEL_CREDIT_EXHAUSTED" || status4 === 402) return new AnchaError("CONFIG_INVALID", `the workspace is out of model credit${said}`, { hint: `add credit in the workspace's Settings, ${ownKey}` });
|
|
76301
|
+
if (code2 === "MODEL_KEYS_OFF") return new AnchaError("CONFIG_INVALID", `model calls are turned off for this workspace${said}`, { hint: `ask the workspace's owner to turn them on, ${ownKey}` });
|
|
76302
|
+
if (code2 === "MODEL_KEY_UNAVAILABLE") return new AnchaError("SERVER_UNREACHABLE", `the workspace has no model key right now${said}`, { hint: `try again in a few minutes, ${ownKey}` });
|
|
76303
|
+
if (code2 === "MODEL_NOT_ALLOWED") return new AnchaError("CONFIG_INVALID", `the workspace's relay doesn't serve this model${said}`, { hint: `use one of the models it names, ${ownKey}` });
|
|
76304
|
+
if (code2 === "RELAY_FIELD_NOT_ALLOWED" || code2 === "MAX_TOKENS_TOO_HIGH") {
|
|
76305
|
+
const reason2 = typeof error64?.message === "string" ? error64.message : code2;
|
|
76306
|
+
return new AnchaError("INTERNAL", `Ancha's request to the workspace model relay was refused (${reason2}): a bug in Ancha, not your input`, { hint: ownKey });
|
|
76307
|
+
}
|
|
76308
|
+
if (status4 === 413) return new AnchaError("USAGE", "the request is larger than the workspace's relay accepts (256 KB)", { hint: "shorten the description or the world" });
|
|
76309
|
+
return void 0;
|
|
76310
|
+
}
|
|
76311
|
+
|
|
76309
76312
|
// packages/core/src/answer.ts
|
|
76310
76313
|
var SYMBOLS = "$\u20AC\xA3\xA5\u20B9\u20A9\u20BD\u20BA\u20AA\u20AB\u0E3F\u20B1\u20A6\u20B4\u20B8\u20A1\u20B2\u20B5\u20AD\xA2";
|
|
76311
76314
|
var CODES = [
|
|
@@ -81968,23 +81971,23 @@ var AttioSeedSchema = external_exports.strictObject({
|
|
|
81968
81971
|
const emails = new Set(seed44.members.map((m) => m.email.toLowerCase()));
|
|
81969
81972
|
const lookupOf = (a) => a.type === "select" || a.type === "status" ? { options: a.options } : a.type === "record-reference" ? { target: a.target } : a.type === "actor-reference" ? { target: "member" } : {};
|
|
81970
81973
|
const named4 = (given2, attributes3, standard2, path6) => {
|
|
81971
|
-
for (const [
|
|
81972
|
-
const custom3 = attributes3.find((a) => a.api_slug ===
|
|
81973
|
-
if (custom3 === void 0 && !Object.hasOwn(standard2,
|
|
81974
|
-
issue9([...path6,
|
|
81974
|
+
for (const [slug11, value5] of Object.entries(given2)) {
|
|
81975
|
+
const custom3 = attributes3.find((a) => a.api_slug === slug11);
|
|
81976
|
+
if (custom3 === void 0 && !Object.hasOwn(standard2, slug11)) {
|
|
81977
|
+
issue9([...path6, slug11], `no attribute "${slug11}"`);
|
|
81975
81978
|
continue;
|
|
81976
81979
|
}
|
|
81977
|
-
const { options: options4, target: target5 } = custom3 === void 0 ? standard2[
|
|
81980
|
+
const { options: options4, target: target5 } = custom3 === void 0 ? standard2[slug11] : lookupOf(custom3);
|
|
81978
81981
|
for (const item2 of Array.isArray(value5) ? value5 : [value5]) {
|
|
81979
81982
|
if (typeof item2 !== "string") continue;
|
|
81980
|
-
if (options4 !== void 0 && !options4.includes(item2)) issue9([...path6,
|
|
81981
|
-
if (target5 === "member" && !members4.has(item2) && !emails.has(item2.toLowerCase())) issue9([...path6,
|
|
81982
|
-
else if (target5 !== void 0 && target5 !== "member" && recordObject.get(item2) !== target5) issue9([...path6,
|
|
81983
|
+
if (options4 !== void 0 && !options4.includes(item2)) issue9([...path6, slug11], `"${item2}" is not an option of ${slug11}`);
|
|
81984
|
+
if (target5 === "member" && !members4.has(item2) && !emails.has(item2.toLowerCase())) issue9([...path6, slug11], `unknown member ${item2}`);
|
|
81985
|
+
else if (target5 !== void 0 && target5 !== "member" && recordObject.get(item2) !== target5) issue9([...path6, slug11], `${item2} is not a ${target5} record`);
|
|
81983
81986
|
}
|
|
81984
81987
|
}
|
|
81985
81988
|
};
|
|
81986
81989
|
for (const object23 of ["people", "companies", "deals"]) {
|
|
81987
|
-
const standard2 = { ...Object.fromEntries(ATTIO_STANDARD_ATTRIBUTES[object23].map((
|
|
81990
|
+
const standard2 = { ...Object.fromEntries(ATTIO_STANDARD_ATTRIBUTES[object23].map((slug11) => [slug11, {}])), ...STANDARD_LOOKUPS[object23], ...object23 === "deals" && { stage: { options: seed44.deal_stages } } };
|
|
81988
81991
|
seed44.records[object23].forEach((r2, i) => named4(r2.values, seed44.attributes[object23] ?? [], standard2, ["records", object23, i, "values"]));
|
|
81989
81992
|
}
|
|
81990
81993
|
seed44.lists.forEach((l, i) => {
|
|
@@ -89791,8 +89794,8 @@ function metricExtension(query11) {
|
|
|
89791
89794
|
if (!expression4(depth + 1) || !take2(/^\)/)) return false;
|
|
89792
89795
|
} else if (take2(/^(?:anomalies|outliers|forecast)\(/)) {
|
|
89793
89796
|
if (!expression4(depth + 1) || !take2(/^,/) || !take2(/^(?:'[^'\r\n]+'|"[^"\r\n]+")/) || !take2(/^,/)) return false;
|
|
89794
|
-
const
|
|
89795
|
-
if (!
|
|
89797
|
+
const parameter2 = take2(numberPattern);
|
|
89798
|
+
if (!parameter2 || !Number.isFinite(Number(parameter2[0])) || !take2(/^\)/)) return false;
|
|
89796
89799
|
} else {
|
|
89797
89800
|
const number7 = take2(numberPattern);
|
|
89798
89801
|
return number7 !== null && Number.isFinite(Number(number7[0]));
|
|
@@ -91049,7 +91052,7 @@ function parseSceneYaml(text25) {
|
|
|
91049
91052
|
// packages/core/src/tool-call-trace.ts
|
|
91050
91053
|
function projectToolCalls(trace2) {
|
|
91051
91054
|
const completed = new Map(trace2.filter((e) => e.toolEvent?.kind === "completion").map((e) => [e.toolEvent.call_id, e]));
|
|
91052
|
-
return trace2.filter((e) => e.toolEvent?.kind !== "completion" && !(e.service === "tools" && (e.path === "/register" || e.path === "/calls/complete"))).map((entry2) => {
|
|
91055
|
+
return trace2.filter((e) => !e.routeEvent && e.toolEvent?.kind !== "completion" && !(e.service === "tools" && (e.path === "/register" || e.path === "/calls/complete"))).map((entry2) => {
|
|
91053
91056
|
if (entry2.service !== "tools" || !entry2.path.startsWith("/tools/")) return entry2;
|
|
91054
91057
|
const response6 = entry2.response;
|
|
91055
91058
|
if (!response6 || !response6.passthrough || entry2.completion || response6.execution_status === "succeeded" || response6.execution_status === "failed") return entry2;
|
|
@@ -128311,11 +128314,11 @@ function orgFor(call2) {
|
|
|
128311
128314
|
return org5;
|
|
128312
128315
|
}
|
|
128313
128316
|
var slugify2 = (name5) => name5.toLowerCase().normalize("NFKD").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "organization";
|
|
128314
|
-
function checkSlug(ctx,
|
|
128315
|
-
if (typeof
|
|
128316
|
-
const owner5 = getOrg(ctx,
|
|
128317
|
+
function checkSlug(ctx, slug11, except) {
|
|
128318
|
+
if (typeof slug11 !== "string" || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(slug11) || slug11.length > 100) throw new ClerkError(422, "form_param_format_invalid", "is invalid", "slug must contain only lowercase letters, digits and dashes", { param_name: "slug" });
|
|
128319
|
+
const owner5 = getOrg(ctx, slug11);
|
|
128317
128320
|
if (owner5 && owner5.id !== except) throw taken("slug", "slug");
|
|
128318
|
-
return
|
|
128321
|
+
return slug11;
|
|
128319
128322
|
}
|
|
128320
128323
|
function seats(value5) {
|
|
128321
128324
|
if (value5 === void 0) return void 0;
|
|
@@ -128346,14 +128349,14 @@ function createOrg(call2) {
|
|
|
128346
128349
|
const body7 = fields8(call2, ["name", "slug", "created_by", "max_allowed_memberships", "public_metadata", "private_metadata"], ["role_set_key"]);
|
|
128347
128350
|
const name5 = text17(body7.name, "name");
|
|
128348
128351
|
if (!name5?.trim()) throw missing3("name");
|
|
128349
|
-
const
|
|
128352
|
+
const slug11 = checkSlug(ctx, body7.slug ?? slugify2(name5));
|
|
128350
128353
|
const creator = body7.created_by === void 0 ? void 0 : getUser6(ctx, String(body7.created_by));
|
|
128351
128354
|
if (body7.created_by !== void 0 && !creator) throw new ClerkError(422, "form_param_value_invalid", "is invalid", "created_by must be an existing user", { param_name: "created_by" });
|
|
128352
128355
|
const now11 = ctx.clock.nowMs();
|
|
128353
128356
|
const org5 = {
|
|
128354
128357
|
id: newId2(ctx.ids, "org"),
|
|
128355
128358
|
name: name5,
|
|
128356
|
-
slug:
|
|
128359
|
+
slug: slug11,
|
|
128357
128360
|
max_members: seats(body7.max_allowed_memberships) ?? 0,
|
|
128358
128361
|
admin_delete_enabled: 1,
|
|
128359
128362
|
public_metadata: JSON.stringify(json14(body7.public_metadata, "public_metadata") ?? {}),
|
|
@@ -128362,7 +128365,7 @@ function createOrg(call2) {
|
|
|
128362
128365
|
created_ms: now11,
|
|
128363
128366
|
updated_ms: now11
|
|
128364
128367
|
};
|
|
128365
|
-
ctx.store.db.prepare("INSERT INTO clerk_orgs (id, name, slug, max_members, public_metadata, private_metadata, created_by, created_ms, updated_ms) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)").run(org5.id, name5,
|
|
128368
|
+
ctx.store.db.prepare("INSERT INTO clerk_orgs (id, name, slug, max_members, public_metadata, private_metadata, created_by, created_ms, updated_ms) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)").run(org5.id, name5, slug11, org5.max_members, org5.public_metadata, org5.private_metadata, org5.created_by, now11, now11);
|
|
128366
128369
|
if (creator) ctx.store.db.prepare("INSERT INTO clerk_memberships (id, org_id, user_id, role, created_ms, updated_ms) VALUES (?, ?, ?, ?, ?, ?)").run(newId2(ctx.ids, "orgmem"), org5.id, creator.id, "org:admin", now11, now11);
|
|
128367
128370
|
return respond3(call2, 200, orgJson(ctx, org5));
|
|
128368
128371
|
}
|
|
@@ -129488,8 +129491,8 @@ function rpc(call2, cat, schema2, bind, params10) {
|
|
|
129488
129491
|
const type = routine.types[routine.args.indexOf(n2)];
|
|
129489
129492
|
const value5 = args[n2];
|
|
129490
129493
|
const serialized = value5 === null ? null : typeof value5 === "object" ? JSON.stringify(value5) : String(value5);
|
|
129491
|
-
const
|
|
129492
|
-
const sql5 = Array.isArray(value5) && type.endsWith("[]") ? `array(select json_array_elements_text(${
|
|
129494
|
+
const parameter2 = bind.add(serialized);
|
|
129495
|
+
const sql5 = Array.isArray(value5) && type.endsWith("[]") ? `array(select json_array_elements_text(${parameter2}::json))::${type}` : `${parameter2}::${type}`;
|
|
129493
129496
|
return `${ident2(n2)} := ${sql5}`;
|
|
129494
129497
|
});
|
|
129495
129498
|
return { source: `${qualified2(schema2, name5)}(${argumentsSql.join(",")})`, table: routine.relation ?? name5, scalar: routine.scalar, set: routine.set, void: routine.result === "void" };
|
|
@@ -133056,10 +133059,10 @@ var attioRoutes = [
|
|
|
133056
133059
|
coverage: { status: "partial", notes: "assert by a unique attribute: updates the match (appending to multiselect values) or creates a record" },
|
|
133057
133060
|
run: (r2) => {
|
|
133058
133061
|
const object23 = findObject(r2.ctx, r2.param("object"));
|
|
133059
|
-
const
|
|
133060
|
-
if (!
|
|
133061
|
-
const attr = attributesOf(r2.ctx, object23.id).find((a) => a.api_slug ===
|
|
133062
|
-
if (!attr) invalid19(`Cannot find attribute with slug/ID "${
|
|
133062
|
+
const slug11 = r2.query.get("matching_attribute");
|
|
133063
|
+
if (!slug11) invalid19("The matching_attribute query parameter is required.", "missing_value");
|
|
133064
|
+
const attr = attributesOf(r2.ctx, object23.id).find((a) => a.api_slug === slug11 || a.id === slug11);
|
|
133065
|
+
if (!attr) invalid19(`Cannot find attribute with slug/ID "${slug11}".`, "value_not_found");
|
|
133063
133066
|
if (!attr.is_unique) invalid19(`Attribute with slug "${attr.api_slug}" is not unique and cannot be used to match records.`);
|
|
133064
133067
|
const given2 = (r2.data.values ?? {})[attr.api_slug] ?? (r2.data.values ?? {})[attr.id];
|
|
133065
133068
|
if (given2 === void 0) invalid19(`The values must include the matching attribute "${attr.api_slug}".`, "missing_value");
|
|
@@ -133379,13 +133382,13 @@ function seed24(ctx) {
|
|
|
133379
133382
|
run3(ctx, "INSERT INTO attio_members (id, ref, first_name, last_name, email, access_level, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)", id14, m.ref, m.first_name, m.last_name, m.email, m.access_level, created4);
|
|
133380
133383
|
}
|
|
133381
133384
|
run3(ctx, "INSERT INTO attio_tokens (token, member_id) VALUES (?, ?)", ctx.secrets.hex(64), members4.get(data6.agent));
|
|
133382
|
-
const used = (
|
|
133383
|
-
const v = r2.values[
|
|
133385
|
+
const used = (slug11) => [...new Set(data6.records.companies.flatMap((r2) => {
|
|
133386
|
+
const v = r2.values[slug11];
|
|
133384
133387
|
return Array.isArray(v) ? v.map(String) : typeof v === "string" ? [v] : [];
|
|
133385
133388
|
}))];
|
|
133386
133389
|
const objects = standard(data6.deal_stages, [.../* @__PURE__ */ new Set([...used("categories"), "B2B", "B2C", "SaaS", "Retail"])]);
|
|
133387
133390
|
const objectIds = /* @__PURE__ */ new Map();
|
|
133388
|
-
for (const
|
|
133391
|
+
for (const slug11 of Object.keys(objects)) objectIds.set(slug11, uuid12(ctx));
|
|
133389
133392
|
const addAttributes = (parentId, specs) => specs.forEach((spec, position) => {
|
|
133390
133393
|
const id14 = uuid12(ctx);
|
|
133391
133394
|
const config12 = { currency: { default_currency_code: spec.currency ?? null, display_type: spec.currency ? "symbol" : null }, record_reference: { allowed_object_ids: spec.target ? [objectIds.get(spec.target)] : null } };
|
|
@@ -133408,28 +133411,28 @@ function seed24(ctx) {
|
|
|
133408
133411
|
);
|
|
133409
133412
|
(spec.options ?? []).forEach((title2, i) => run3(ctx, "INSERT INTO attio_options (id, attribute_id, title, position) VALUES (?, ?, ?, ?)", uuid12(ctx), id14, title2, i));
|
|
133410
133413
|
});
|
|
133411
|
-
for (const [
|
|
133412
|
-
run3(ctx, "INSERT INTO attio_objects (id, api_slug, singular_noun, plural_noun, created_at) VALUES (?, ?, ?, ?, ?)", objectIds.get(
|
|
133413
|
-
addAttributes(objectIds.get(
|
|
133414
|
+
for (const [slug11, o] of Object.entries(objects)) {
|
|
133415
|
+
run3(ctx, "INSERT INTO attio_objects (id, api_slug, singular_noun, plural_noun, created_at) VALUES (?, ?, ?, ?, ?)", objectIds.get(slug11), slug11, o.singular, o.plural, created4);
|
|
133416
|
+
addAttributes(objectIds.get(slug11), [...o.attributes, ...(data6.attributes[slug11] ?? []).map((a) => ({ ...a, target: a.target }))]);
|
|
133414
133417
|
}
|
|
133415
133418
|
const records4 = /* @__PURE__ */ new Map();
|
|
133416
133419
|
const order6 = ["companies", "people", "deals"];
|
|
133417
|
-
for (const
|
|
133420
|
+
for (const slug11 of order6) for (const r2 of data6.records[slug11]) {
|
|
133418
133421
|
const id14 = uuid12(ctx);
|
|
133419
133422
|
records4.set(r2.ref, id14);
|
|
133420
|
-
run3(ctx, "INSERT INTO attio_records (id, object_id, created_at, created_by) VALUES (?, ?, ?, ?)", id14, objectIds.get(
|
|
133423
|
+
run3(ctx, "INSERT INTO attio_records (id, object_id, created_at, created_by) VALUES (?, ?, ?, ?)", id14, objectIds.get(slug11), at4(r2.created), JSON.stringify(actor2(members4.get(data6.agent))));
|
|
133421
133424
|
}
|
|
133422
133425
|
const write5 = (parentId, parent3, values3, when11, by2) => {
|
|
133423
133426
|
const attributes3 = all5(ctx, "SELECT * FROM attio_attributes WHERE parent_id = ? ORDER BY position", parent3);
|
|
133424
|
-
for (const [
|
|
133425
|
-
const attr = attributes3.find((a) => a.api_slug ===
|
|
133426
|
-
if (!attr) throw new AnchaError("SCENE_INVALID", `seed.attio: no attribute "${
|
|
133427
|
+
for (const [slug11, raw3] of Object.entries(values3)) {
|
|
133428
|
+
const attr = attributes3.find((a) => a.api_slug === slug11);
|
|
133429
|
+
if (!attr) throw new AnchaError("SCENE_INVALID", `seed.attio: no attribute "${slug11}"`);
|
|
133427
133430
|
const list17 = raw3 === null ? [] : Array.isArray(raw3) ? raw3 : [raw3];
|
|
133428
133431
|
const items = list17.map((v) => parseValue(ctx, attr, attr.type === "record-reference" ? { target_record_id: records4.get(String(v)) ?? String(v) } : attr.type === "actor-reference" ? members4.get(String(v)) ?? String(v) : v));
|
|
133429
133432
|
writeValues(ctx, parentId, attr, items, actor2(by2), true, when11);
|
|
133430
133433
|
}
|
|
133431
133434
|
};
|
|
133432
|
-
for (const
|
|
133435
|
+
for (const slug11 of order6) for (const r2 of data6.records[slug11]) write5(records4.get(r2.ref), objectIds.get(slug11), r2.values, at4(r2.created), members4.get(data6.agent));
|
|
133433
133436
|
for (const l of data6.lists) {
|
|
133434
133437
|
const id14 = uuid12(ctx);
|
|
133435
133438
|
run3(ctx, "INSERT INTO attio_lists (id, api_slug, name, parent_object, created_by, created_at) VALUES (?, ?, ?, ?, ?, ?)", id14, l.api_slug, l.name, l.parent_object, members4.get(data6.agent), at4(l.created));
|
|
@@ -133440,7 +133443,7 @@ function seed24(ctx) {
|
|
|
133440
133443
|
write5(entryId, `list:${id14}`, e.values, at4(e.created), members4.get(data6.agent));
|
|
133441
133444
|
}
|
|
133442
133445
|
}
|
|
133443
|
-
const objectOf = (ref23) => order6.find((
|
|
133446
|
+
const objectOf = (ref23) => order6.find((slug11) => data6.records[slug11].some((r2) => r2.ref === ref23));
|
|
133444
133447
|
for (const n2 of data6.notes) {
|
|
133445
133448
|
run3(
|
|
133446
133449
|
ctx,
|
|
@@ -147854,8 +147857,8 @@ function literalRoutesFirst(a, b) {
|
|
|
147854
147857
|
const left = a.path.split("/"), right = b.path.split("/");
|
|
147855
147858
|
for (let i = 0; i < Math.min(left.length, right.length); i++) {
|
|
147856
147859
|
if (left[i] === right[i]) continue;
|
|
147857
|
-
const
|
|
147858
|
-
if (
|
|
147860
|
+
const parameter2 = (part) => part.startsWith("{");
|
|
147861
|
+
if (parameter2(left[i]) !== parameter2(right[i])) return parameter2(left[i]) ? 1 : -1;
|
|
147859
147862
|
return left[i].localeCompare(right[i]);
|
|
147860
147863
|
}
|
|
147861
147864
|
return right.length - left.length;
|
|
@@ -151255,10 +151258,10 @@ function handle29(route15) {
|
|
|
151255
151258
|
all: (name5) => url4.searchParams.getAll(name5).filter((v) => v !== "")
|
|
151256
151259
|
};
|
|
151257
151260
|
const run4 = () => {
|
|
151258
|
-
const
|
|
151259
|
-
if (
|
|
151261
|
+
const slug11 = c.req.param("org");
|
|
151262
|
+
if (slug11 !== void 0) {
|
|
151260
151263
|
const o = org4(ctx);
|
|
151261
|
-
if (decodeURIComponent(
|
|
151264
|
+
if (decodeURIComponent(slug11) !== o.slug && decodeURIComponent(slug11) !== o.id) notFound19();
|
|
151262
151265
|
}
|
|
151263
151266
|
return route15.run(r2);
|
|
151264
151267
|
};
|
|
@@ -166248,7 +166251,7 @@ function wantsJson(accept) {
|
|
|
166248
166251
|
if (media2 === "application/json") json37 = Math.max(json37, Number.isFinite(q) ? q : 0);
|
|
166249
166252
|
if (["application/xml", "text/xml"].includes(media2)) xml2 = Math.max(xml2, Number.isFinite(q) ? q : 0);
|
|
166250
166253
|
}
|
|
166251
|
-
return
|
|
166254
|
+
return !(xml2 > 0 && xml2 > json37);
|
|
166252
166255
|
}
|
|
166253
166256
|
function xmlElement(name5, value5, type = name5) {
|
|
166254
166257
|
if (Array.isArray(value5)) return value5.map((v) => xmlElement(name5, v, type)).join("");
|
|
@@ -168288,19 +168291,19 @@ function controlRoutes(opts) {
|
|
|
168288
168291
|
throw new AnchaError("USAGE", "request body must be JSON");
|
|
168289
168292
|
});
|
|
168290
168293
|
if (!payload3 || typeof payload3 !== "object" || Array.isArray(payload3)) throw new AnchaError("USAGE", "request body must be an object");
|
|
168291
|
-
const { configuration, seed: seed44, ttlMs, paused, execution, ...rest2 } = payload3;
|
|
168294
|
+
const { configuration, seed: seed44, ttlMs, paused, execution: execution2, ...rest2 } = payload3;
|
|
168292
168295
|
if (Object.keys(rest2).length) throw new AnchaError("USAGE", "only configuration, seed, ttlMs, paused and execution are accepted");
|
|
168293
168296
|
if (seed44 !== void 0 && (typeof seed44 !== "string" || !seed44.length || seed44.length > 200)) throw new AnchaError("USAGE", "seed must be nonempty text up to 200 characters");
|
|
168294
168297
|
if (ttlMs !== void 0 && typeof ttlMs !== "number") throw new AnchaError("USAGE", "ttlMs must be a number");
|
|
168295
168298
|
if (paused !== void 0 && typeof paused !== "boolean") throw new AnchaError("USAGE", "paused must be a boolean");
|
|
168296
|
-
if (
|
|
168297
|
-
if (
|
|
168299
|
+
if (execution2 !== void 0 && execution2 !== "manual" && execution2 !== "paced") throw new AnchaError("USAGE", "execution must be manual or paced");
|
|
168300
|
+
if (execution2 === "manual" && paused !== true) throw new AnchaError("USAGE", "manual execution requires paused: true");
|
|
168298
168301
|
const compiled2 = compileSandboxConfiguration(configuration);
|
|
168299
168302
|
const env = manager.create(compiled2.scene, {
|
|
168300
168303
|
seed: seed44,
|
|
168301
168304
|
ttlMs,
|
|
168302
168305
|
paused,
|
|
168303
|
-
execution,
|
|
168306
|
+
execution: execution2,
|
|
168304
168307
|
sandbox: { name: compiled2.configuration.name, evaluation: "ungraded", fingerprint: compiled2.fingerprint, configuration: compiled2.configuration }
|
|
168305
168308
|
});
|
|
168306
168309
|
try {
|
|
@@ -168321,9 +168324,9 @@ function controlRoutes(opts) {
|
|
|
168321
168324
|
if (typeof payload3 !== "object" || payload3 === null || Array.isArray(payload3)) {
|
|
168322
168325
|
throw new AnchaError("USAGE", "request body must be a JSON object", { hint: 'POST { "scene": { \u2026 }, "seed"?: "\u2026" }' });
|
|
168323
168326
|
}
|
|
168324
|
-
const { scene: scene2, seed: seed44, ttlMs, paused, execution, people: people3, ...rest2 } = payload3;
|
|
168325
|
-
if (
|
|
168326
|
-
if (
|
|
168327
|
+
const { scene: scene2, seed: seed44, ttlMs, paused, execution: execution2, people: people3, ...rest2 } = payload3;
|
|
168328
|
+
if (execution2 !== void 0 && execution2 !== "paced" && execution2 !== "manual") throw new AnchaError("USAGE", '"execution" must be paced or manual');
|
|
168329
|
+
if (execution2 === "manual" && paused !== true) throw new AnchaError("USAGE", "manual execution requires paused: true");
|
|
168327
168330
|
if (paused !== void 0 && typeof paused !== "boolean") throw new AnchaError("USAGE", '"paused" must be a boolean');
|
|
168328
168331
|
if (Object.keys(rest2).length > 0) {
|
|
168329
168332
|
throw new AnchaError("USAGE", `unknown field in request body: ${Object.keys(rest2).map((k) => `"${k}"`).join(", ")}`, { hint: 'the only fields are "scene", "seed", "ttlMs", "paused", "execution" and "people"' });
|
|
@@ -168343,7 +168346,7 @@ function controlRoutes(opts) {
|
|
|
168343
168346
|
if (seed44 !== void 0 && typeof seed44 !== "string") {
|
|
168344
168347
|
throw new AnchaError("USAGE", '"seed" must be a string', { hint: 'omit it to use the default seed, "<scene id>:1"' });
|
|
168345
168348
|
}
|
|
168346
|
-
const env = manager.create(parseScene(scene2), { ...seed44 !== void 0 && { seed: seed44 }, ...ttlMs !== void 0 && { ttlMs }, ...paused !== void 0 && { paused }, ...
|
|
168349
|
+
const env = manager.create(parseScene(scene2), { ...seed44 !== void 0 && { seed: seed44 }, ...ttlMs !== void 0 && { ttlMs }, ...paused !== void 0 && { paused }, ...execution2 !== void 0 && { execution: execution2 }, ...replay !== void 0 && { people: replay } });
|
|
168347
168350
|
try {
|
|
168348
168351
|
await opts.prepareTransports?.(env);
|
|
168349
168352
|
} catch (error64) {
|
|
@@ -183821,7 +183824,7 @@ var McpServer = class {
|
|
|
183821
183824
|
}
|
|
183822
183825
|
return registeredPrompt;
|
|
183823
183826
|
}
|
|
183824
|
-
_createRegisteredTool(name5, title2, description2, inputSchema, outputSchema, annotations, icons,
|
|
183827
|
+
_createRegisteredTool(name5, title2, description2, inputSchema, outputSchema, annotations, icons, execution2, scopeChallenge, _meta, handler) {
|
|
183825
183828
|
validateAndWarnToolName(name5);
|
|
183826
183829
|
let currentHandler = handler;
|
|
183827
183830
|
let outputSchemaJson;
|
|
@@ -183838,7 +183841,7 @@ var McpServer = class {
|
|
|
183838
183841
|
},
|
|
183839
183842
|
annotations,
|
|
183840
183843
|
icons,
|
|
183841
|
-
execution,
|
|
183844
|
+
execution: execution2,
|
|
183842
183845
|
scopeChallenge,
|
|
183843
183846
|
_meta,
|
|
183844
183847
|
handler,
|
|
@@ -186274,6 +186277,76 @@ function createAttemptConnectionManifest(env, options4 = {}) {
|
|
|
186274
186277
|
};
|
|
186275
186278
|
}
|
|
186276
186279
|
|
|
186280
|
+
// backend/src/execution/composio.ts
|
|
186281
|
+
import { createHash as createHash57 } from "node:crypto";
|
|
186282
|
+
var RouteRefusal = class extends Error {
|
|
186283
|
+
reason;
|
|
186284
|
+
constructor(reason2) {
|
|
186285
|
+
super("Configure this call to use the declared QuickBooks route.");
|
|
186286
|
+
this.reason = reason2;
|
|
186287
|
+
}
|
|
186288
|
+
};
|
|
186289
|
+
var refuse = (reason2) => {
|
|
186290
|
+
throw new RouteRefusal(reason2);
|
|
186291
|
+
};
|
|
186292
|
+
var slug10 = "QUICKBOOKS_[A-Z0-9_]{1,96}";
|
|
186293
|
+
var execution = new RegExp(`^/api/v3(?:\\.1)?/tools/execute/(${slug10})$`);
|
|
186294
|
+
var catalogTool = new RegExp(`^/api/v3(?:\\.1)?/tools/(${slug10})$`);
|
|
186295
|
+
var parameter = external_exports.strictObject({ name: external_exports.string(), value: external_exports.string(), in: external_exports.literal("header") });
|
|
186296
|
+
var bodySchema = external_exports.strictObject({ user_id: external_exports.string().optional(), version: external_exports.string().optional(), arguments: external_exports.record(external_exports.string(), external_exports.unknown()).optional(), custom_auth_params: external_exports.strictObject({ base_url: external_exports.string(), parameters: external_exports.array(parameter).length(2) }) });
|
|
186297
|
+
function validateComposio(method2, target5, apiKey, body7, contentType, route15) {
|
|
186298
|
+
if (!route15.available()) refuse("ROUTE_UNAVAILABLE");
|
|
186299
|
+
if (typeof apiKey !== "string" || apiKey !== route15.apiKey || !route15.apiKey) refuse("API_KEY");
|
|
186300
|
+
if (target5.length > 8192 || target5.includes("#") || /[%\\\x00-\x20\x7f#]/.test(target5.split("?")[0]) || target5.includes("//")) refuse("PATH");
|
|
186301
|
+
const url4 = new URL(target5, "https://backend.composio.dev");
|
|
186302
|
+
const match3 = execution.exec(url4.pathname);
|
|
186303
|
+
if (match3) {
|
|
186304
|
+
if (method2 !== "POST") refuse("METHOD");
|
|
186305
|
+
if (url4.search) refuse("QUERY");
|
|
186306
|
+
if (typeof contentType !== "string" || !/^application\/json(?:\s*;|$)/i.test(contentType)) refuse("CONTENT_TYPE");
|
|
186307
|
+
if (body7.length > 65536) refuse("BODY_TOO_LARGE");
|
|
186308
|
+
let json37;
|
|
186309
|
+
try {
|
|
186310
|
+
json37 = JSON.parse(body7.toString("utf8"));
|
|
186311
|
+
} catch {
|
|
186312
|
+
refuse("JSON");
|
|
186313
|
+
}
|
|
186314
|
+
const parsed3 = bodySchema.safeParse(json37);
|
|
186315
|
+
if (!parsed3.success) return refuse("SCHEMA");
|
|
186316
|
+
const value5 = parsed3.data;
|
|
186317
|
+
if (value5.custom_auth_params.base_url.replace(/\/$/, "") !== route15.publicUrl.replace(/\/$/, "")) refuse("BASE_URL");
|
|
186318
|
+
const params10 = value5.custom_auth_params.parameters;
|
|
186319
|
+
if (!params10.some((p2) => p2.name.toLowerCase() === "authorization" && p2.value === `Bearer ${route15.token}`) || !params10.some((p2) => p2.name.toLowerCase() === "x-quickbooks-realm-id" && p2.value === route15.realm)) refuse("PARAMETERS");
|
|
186320
|
+
value5.user_id = `ancha-${createHash57("sha256").update(route15.attemptId).digest("hex").slice(0, 16)}`;
|
|
186321
|
+
return { op: "execute", slug: match3[1], body: Buffer.from(JSON.stringify(value5)) };
|
|
186322
|
+
}
|
|
186323
|
+
const tool = catalogTool.exec(url4.pathname), toolkit = /^\/api\/v3(?:\.1)?\/toolkits\/quickbooks$/i.test(url4.pathname);
|
|
186324
|
+
const list17 = /^\/api\/v3(?:\.1)?\/tools$/.test(url4.pathname);
|
|
186325
|
+
if (!tool && !toolkit && !list17) refuse("PATH");
|
|
186326
|
+
if (method2 !== "GET") refuse("METHOD");
|
|
186327
|
+
if (body7.length) refuse("SCHEMA");
|
|
186328
|
+
if (tool || toolkit) return { op: "catalog", ...tool && { slug: tool[1] } };
|
|
186329
|
+
const toolkits = url4.searchParams.getAll("toolkit_slug"), slugs = url4.searchParams.getAll("tool_slugs").flatMap((value5) => value5.split(","));
|
|
186330
|
+
if (!toolkits.length && !slugs.length) refuse("QUERY");
|
|
186331
|
+
if (toolkits.some((value5) => value5.toLowerCase() !== "quickbooks") || !slugs.every((value5) => new RegExp(`^${slug10}$`).test(value5))) refuse("QUERY");
|
|
186332
|
+
return { op: "catalog" };
|
|
186333
|
+
}
|
|
186334
|
+
async function readComposioBody(req) {
|
|
186335
|
+
if (Number(req.headers["content-length"] ?? 0) > 65536) refuse("BODY_TOO_LARGE");
|
|
186336
|
+
const chunks = [];
|
|
186337
|
+
let size2 = 0;
|
|
186338
|
+
for await (const chunk of req.iterator({ destroyOnReturn: false })) {
|
|
186339
|
+
size2 += chunk.length;
|
|
186340
|
+
if (size2 > 65536) refuse("BODY_TOO_LARGE");
|
|
186341
|
+
chunks.push(Buffer.from(chunk));
|
|
186342
|
+
}
|
|
186343
|
+
return Buffer.concat(chunks);
|
|
186344
|
+
}
|
|
186345
|
+
function refuseComposio(res, reason2) {
|
|
186346
|
+
res.writeHead(403, { "content-type": "application/json", connection: "close" });
|
|
186347
|
+
res.end(JSON.stringify({ error: { code: "COMPOSIO_ROUTE_REFUSED", reason: reason2, message: "Configure this call to use the declared QuickBooks route." } }));
|
|
186348
|
+
}
|
|
186349
|
+
|
|
186277
186350
|
// backend/src/execution/gateway.ts
|
|
186278
186351
|
import { lookup as lookup5 } from "node:dns/promises";
|
|
186279
186352
|
import { createServer, request } from "node:http";
|
|
@@ -186390,6 +186463,24 @@ async function startIsolationGateway(options4) {
|
|
|
186390
186463
|
});
|
|
186391
186464
|
const server = createServer({ maxHeaderSize: 16 * 1024 }, async (req, res) => {
|
|
186392
186465
|
if (closed) return reject2(res, 503);
|
|
186466
|
+
const tool = (req.url ?? "").startsWith("/_tool/composio");
|
|
186467
|
+
let toolCall;
|
|
186468
|
+
let toolBody;
|
|
186469
|
+
const toolStarted = performance.now();
|
|
186470
|
+
const route15 = options4.composio;
|
|
186471
|
+
if (tool) {
|
|
186472
|
+
try {
|
|
186473
|
+
if (!route15) throw new RouteRefusal("ROUTE_UNAVAILABLE");
|
|
186474
|
+
if (!safePath2(req.url ?? "") || !(req.url ?? "").startsWith("/_tool/composio/")) throw new RouteRefusal("PATH");
|
|
186475
|
+
toolBody = await readComposioBody(req);
|
|
186476
|
+
toolCall = validateComposio(req.method ?? "", req.url.slice("/_tool/composio".length), req.headers["x-api-key"], toolBody, req.headers["content-type"], route15);
|
|
186477
|
+
} catch (error64) {
|
|
186478
|
+
const reason2 = error64 instanceof RouteRefusal ? error64.reason : "JSON";
|
|
186479
|
+
route15?.record({ leg: "platform", op: "refused", method: ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"].includes(req.method ?? "") ? req.method : "OTHER", status: 403, ms: Math.round(performance.now() - toolStarted), reason: reason2 });
|
|
186480
|
+
refuseComposio(res, reason2);
|
|
186481
|
+
return;
|
|
186482
|
+
}
|
|
186483
|
+
}
|
|
186393
186484
|
const path6 = safePath2(req.url ?? "");
|
|
186394
186485
|
if (!path6) return reject2(res);
|
|
186395
186486
|
let upstream;
|
|
@@ -186398,18 +186489,30 @@ async function startIsolationGateway(options4) {
|
|
|
186398
186489
|
let targetPath = req.url;
|
|
186399
186490
|
let transform3;
|
|
186400
186491
|
const model = /^\/_model\/([a-zA-Z0-9.-]+)(\/.*)?$/.exec(path6);
|
|
186401
|
-
if (model && modelHosts.has(model[1].toLowerCase())) {
|
|
186402
|
-
modelHost = model[1].toLowerCase();
|
|
186403
|
-
|
|
186492
|
+
if (toolCall || model && modelHosts.has(model[1].toLowerCase())) {
|
|
186493
|
+
modelHost = toolCall ? "backend.composio.dev" : model[1].toLowerCase();
|
|
186494
|
+
const activityCallback = toolCall ? toolCall.op === "execute" ? options4.onModelActivity ?? route15.activity : void 0 : options4.onModelActivity;
|
|
186495
|
+
if (toolCall) {
|
|
186496
|
+
const call2 = toolCall, endWindow = call2.op === "execute" ? route15.begin() : void 0;
|
|
186497
|
+
let recorded2 = false;
|
|
186498
|
+
const record10 = () => {
|
|
186499
|
+
if (recorded2) return;
|
|
186500
|
+
recorded2 = true;
|
|
186501
|
+
route15.record({ leg: "platform", op: call2.op, method: req.method, ...call2.slug && { slug: call2.slug }, status: res.writableFinished ? res.statusCode : 502, ms: Math.round(performance.now() - toolStarted) }, endWindow?.());
|
|
186502
|
+
};
|
|
186503
|
+
res.once("finish", record10);
|
|
186504
|
+
res.once("close", record10);
|
|
186505
|
+
}
|
|
186506
|
+
if (activityCallback) {
|
|
186404
186507
|
const ended = new Promise((resolve8) => {
|
|
186405
186508
|
res.once("finish", resolve8);
|
|
186406
186509
|
res.once("close", resolve8);
|
|
186407
186510
|
});
|
|
186408
|
-
const started =
|
|
186511
|
+
const started = activityCallback(true);
|
|
186409
186512
|
const activity3 = (async () => {
|
|
186410
186513
|
await started;
|
|
186411
186514
|
await ended;
|
|
186412
|
-
await
|
|
186515
|
+
await activityCallback(false);
|
|
186413
186516
|
})().catch(() => {
|
|
186414
186517
|
});
|
|
186415
186518
|
modelActivity.add(activity3);
|
|
@@ -186420,7 +186523,7 @@ async function startIsolationGateway(options4) {
|
|
|
186420
186523
|
if (!res.destroyed) reject2(res, 503, "Model activity could not be registered.");
|
|
186421
186524
|
return;
|
|
186422
186525
|
}
|
|
186423
|
-
if (closed || req.destroyed || res.destroyed) return;
|
|
186526
|
+
if (closed || !toolCall && req.destroyed || res.destroyed) return;
|
|
186424
186527
|
}
|
|
186425
186528
|
let timer;
|
|
186426
186529
|
try {
|
|
@@ -186431,11 +186534,11 @@ async function startIsolationGateway(options4) {
|
|
|
186431
186534
|
timer.unref();
|
|
186432
186535
|
})
|
|
186433
186536
|
]);
|
|
186434
|
-
if (closed || req.destroyed || res.destroyed) return;
|
|
186537
|
+
if (closed || !toolCall && req.destroyed || res.destroyed) return;
|
|
186435
186538
|
if (!addresses3.length || addresses3.some((answer) => !isPublicModelAddress(answer.address))) return reject2(res);
|
|
186436
186539
|
modelAddress = addresses3[0];
|
|
186437
186540
|
upstream = new URL(`https://${modelHost}`);
|
|
186438
|
-
targetPath = (model[2] ?? "/") + (req.url.includes("?") ? "?" + req.url.split("?").slice(1).join("?") : "");
|
|
186541
|
+
targetPath = toolCall ? req.url.slice("/_tool/composio".length) : (model[2] ?? "/") + (req.url.includes("?") ? "?" + req.url.split("?").slice(1).join("?") : "");
|
|
186439
186542
|
} catch {
|
|
186440
186543
|
if (!res.destroyed) reject2(res, 502, "Model destination could not be resolved.");
|
|
186441
186544
|
return;
|
|
@@ -186448,15 +186551,15 @@ async function startIsolationGateway(options4) {
|
|
|
186448
186551
|
break;
|
|
186449
186552
|
}
|
|
186450
186553
|
if (!upstream) {
|
|
186451
|
-
const
|
|
186452
|
-
if (!
|
|
186453
|
-
upstream =
|
|
186554
|
+
const route16 = sessionRoutes2.get(path6);
|
|
186555
|
+
if (!route16 || req.method !== route16.method || req.headers.authorization !== `Bearer ${session2.token}`) return reject2(res);
|
|
186556
|
+
upstream = route16.upstream;
|
|
186454
186557
|
if (path6 === "/_ancha/context") transform3 = "context";
|
|
186455
186558
|
}
|
|
186456
186559
|
const socketOpen = decodeURIComponent(path6) === `/e/${env.id}/slack/api/apps.connections.open`;
|
|
186457
186560
|
if (req.method === "CONNECT" || req.method === "TRACE" || req.headers.upgrade || decodeURIComponent(path6).endsWith("/apps.connections.open") && !(socketOpen && options4.slackSocket && session2)) return reject2(res, 501, "This transport is not qualified for contained execution.");
|
|
186458
186561
|
if (socketOpen && options4.slackSocket && session2) transform3 = "socket";
|
|
186459
|
-
const headers = cleanHeaders(req.headers);
|
|
186562
|
+
const headers = toolCall ? { "x-api-key": route15.apiKey, accept: "application/json", "accept-encoding": "identity", ...toolCall.body && { "content-type": "application/json", "content-length": String(toolCall.body.length) } } : cleanHeaders(req.headers);
|
|
186460
186563
|
headers.host = modelHost ?? new URL(exposedOrigin ?? upstream.origin).host;
|
|
186461
186564
|
delete headers["x-ancha-client-origin"];
|
|
186462
186565
|
if (transform3) headers["accept-encoding"] = "identity";
|
|
@@ -186475,7 +186578,7 @@ async function startIsolationGateway(options4) {
|
|
|
186475
186578
|
} catch {
|
|
186476
186579
|
}
|
|
186477
186580
|
};
|
|
186478
|
-
if (modelHost !== void 0 && reply6.statusCode !== void 0) {
|
|
186581
|
+
if (!toolCall && modelHost !== void 0 && reply6.statusCode !== void 0) {
|
|
186479
186582
|
const host = modelHost, status4 = reply6.statusCode;
|
|
186480
186583
|
if (!MODEL_REFUSALS.has(status4)) observe2(host, status4);
|
|
186481
186584
|
else {
|
|
@@ -186499,7 +186602,17 @@ async function startIsolationGateway(options4) {
|
|
|
186499
186602
|
reject2(res, 502, "Tool redirects are not allowed through the sandbox gateway.");
|
|
186500
186603
|
return;
|
|
186501
186604
|
}
|
|
186502
|
-
const responseHeaders = cleanHeaders(reply6.headers);
|
|
186605
|
+
const responseHeaders = toolCall ? { "content-type": reply6.headers["content-type"] ?? "application/json" } : cleanHeaders(reply6.headers);
|
|
186606
|
+
if (toolCall) {
|
|
186607
|
+
let received = 0;
|
|
186608
|
+
reply6.on("data", (chunk) => {
|
|
186609
|
+
received += chunk.length;
|
|
186610
|
+
if (received > BODY_LIMIT) {
|
|
186611
|
+
reply6.destroy();
|
|
186612
|
+
res.destroy();
|
|
186613
|
+
}
|
|
186614
|
+
});
|
|
186615
|
+
}
|
|
186503
186616
|
if (!transform3) {
|
|
186504
186617
|
res.writeHead(reply6.statusCode ?? 502, responseHeaders);
|
|
186505
186618
|
reply6.pipe(res);
|
|
@@ -186563,7 +186676,11 @@ async function startIsolationGateway(options4) {
|
|
|
186563
186676
|
});
|
|
186564
186677
|
req.on("aborted", () => target5.destroy());
|
|
186565
186678
|
res.on("close", () => target5.destroy());
|
|
186566
|
-
|
|
186679
|
+
if (toolCall) {
|
|
186680
|
+
const deadline2 = setTimeout(() => target5.destroy(), Math.max(1, 12e4 - (performance.now() - toolStarted)));
|
|
186681
|
+
target5.once("close", () => clearTimeout(deadline2));
|
|
186682
|
+
target5.end(toolCall.body);
|
|
186683
|
+
} else req.pipe(target5);
|
|
186567
186684
|
});
|
|
186568
186685
|
server.requestTimeout = 12e4;
|
|
186569
186686
|
server.headersTimeout = 15e3;
|