@ancha-labs/cli 0.4.52 → 0.4.53
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 +1591 -1475
- package/lib/assets/docs/cloud.md +3 -1
- package/lib/assets/harbor/companion.mjs +30 -2
- package/lib/worker.mjs +58 -4
- package/package.json +1 -1
package/lib/assets/docs/cloud.md
CHANGED
|
@@ -155,11 +155,13 @@ The agent's own keys, its model provider's for one, live in the workspace:
|
|
|
155
155
|
export OPENAI_API_KEY=… # the value comes from this shell, never from arguments
|
|
156
156
|
ancha secrets set OPENAI_API_KEY
|
|
157
157
|
ancha secrets list # names only, never values
|
|
158
|
-
ancha secrets unset OPENAI_API_KEY
|
|
158
|
+
ancha secrets unset OPENAI_API_KEY OPENROUTER_API_KEY
|
|
159
159
|
```
|
|
160
160
|
|
|
161
161
|
Run in the agent's project, `ancha secrets set` also names each one under `agent.pass_env` in `ancha.yaml`. A secret's value has at least 8 characters; shorter settings belong under `agent.env`. A cloud run gives the agent those names with the values they had when the run was accepted, so a later change leaves accepted runs as they were. When the workspace lacks one, the run stops before any machine starts, with `CONFIG_INVALID` and the `ancha secrets set` command to run. Setting and removing secrets takes an admin key; the one `ancha login` saves is.
|
|
162
162
|
|
|
163
|
+
`ancha secrets unset NAME [NAME ...]` removes each named variable and reports each result. All names are validated before removal; a name that is not saved leaves the other removals running. With `--json`, one result lists `removed`, `notSaved` when present, and the remaining `names` when returned by the workspace. A single removal keeps `removed` as a name; several names return an array.
|
|
164
|
+
|
|
163
165
|
## Tools reached through Composio
|
|
164
166
|
|
|
165
167
|
An agent that runs QuickBooks or NetSuite tools through Composio keeps its client code in cloud runs. QuickBooks calls go through Composio's servers to the world's QuickBooks. `NETSUITE_RUN_SUITEQL_QUERY` through `session.execute` or `tools.execute` runs against the world's NetSuite through the attempt's gateway.
|
|
@@ -187476,6 +187476,18 @@ function reject2(response6, status4 = 403, message9 = "This destination is outsi
|
|
|
187476
187476
|
response6.writeHead(status4, { "content-type": "application/json", "connection": "close" });
|
|
187477
187477
|
response6.end(JSON.stringify({ error: message9 }));
|
|
187478
187478
|
}
|
|
187479
|
+
function refusedRpc(body7) {
|
|
187480
|
+
try {
|
|
187481
|
+
const value5 = JSON.parse(body7?.toString("utf8") ?? "");
|
|
187482
|
+
if (!value5 || typeof value5 !== "object" || Array.isArray(value5)) return {};
|
|
187483
|
+
const { method: method2, params: params10 } = value5;
|
|
187484
|
+
if (typeof method2 !== "string" || method2.match(/^[A-Za-z][A-Za-z0-9_./-]{0,63}$/)?.[0] !== method2) return {};
|
|
187485
|
+
const name5 = method2 === "tools/call" ? params10?.name : void 0;
|
|
187486
|
+
return { rpc: method2, ...typeof name5 === "string" && name5.match(/^[A-Z][A-Z0-9_]{0,79}$/)?.[0] === name5 && { slug: name5 } };
|
|
187487
|
+
} catch {
|
|
187488
|
+
return {};
|
|
187489
|
+
}
|
|
187490
|
+
}
|
|
187479
187491
|
async function startIsolationGateway(options4) {
|
|
187480
187492
|
options4.signal?.throwIfAborted();
|
|
187481
187493
|
const env = structuredClone(options4.env), session2 = options4.session && structuredClone(options4.session);
|
|
@@ -187506,6 +187518,7 @@ async function startIsolationGateway(options4) {
|
|
|
187506
187518
|
const modelHosts = new Set((options4.modelHosts ?? []).map(normalizeModelHost));
|
|
187507
187519
|
const sockets = /* @__PURE__ */ new Set();
|
|
187508
187520
|
const upstreamRequests = /* @__PURE__ */ new Set();
|
|
187521
|
+
const modelCounts = {};
|
|
187509
187522
|
const modelActivity = /* @__PURE__ */ new Set();
|
|
187510
187523
|
const localRequests = /* @__PURE__ */ new Set();
|
|
187511
187524
|
let exposedOrigin, closed = false;
|
|
@@ -187535,7 +187548,8 @@ async function startIsolationGateway(options4) {
|
|
|
187535
187548
|
} catch (error64) {
|
|
187536
187549
|
const reason2 = error64 instanceof RouteRefusal ? error64.reason : "JSON";
|
|
187537
187550
|
const toolkit = (error64 instanceof RouteRefusal ? error64.toolkit : void 0) ?? (reason2 === "NETSUITE_TOOL" || /NETSUITE_/.test(toolBody?.toString("utf8") ?? "") || /NETSUITE_/.test(req.url ?? "") || route15?.toolkits && !route15.toolkits.quickbooks ? "netsuite" : "quickbooks");
|
|
187538
|
-
|
|
187551
|
+
const via = composioVia((req.url ?? "").slice("/_tool/composio".length));
|
|
187552
|
+
route15?.record({ leg: "platform", op: "refused", toolkit, via, method: ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"].includes(req.method ?? "") ? req.method : "OTHER", ...req.method === "POST" && via === "mcp" && refusedRpc(toolBody), status: 403, ms: Math.round(performance.now() - toolStarted), reason: reason2 });
|
|
187539
187553
|
refuseComposio(res, reason2, toolkit);
|
|
187540
187554
|
return;
|
|
187541
187555
|
}
|
|
@@ -187597,12 +187611,25 @@ async function startIsolationGateway(options4) {
|
|
|
187597
187611
|
if (!path6) return reject2(res);
|
|
187598
187612
|
let upstream;
|
|
187599
187613
|
let modelHost;
|
|
187614
|
+
let recordModelStatus;
|
|
187600
187615
|
let modelAddress;
|
|
187601
187616
|
let targetPath = req.url;
|
|
187602
187617
|
let transform3;
|
|
187603
187618
|
const model = /^\/_model\/([a-zA-Z0-9.-]+)(\/.*)?$/.exec(path6);
|
|
187604
187619
|
if (toolCall || model && modelHosts.has(model[1].toLowerCase())) {
|
|
187605
187620
|
modelHost = toolCall ? "backend.composio.dev" : model[1].toLowerCase();
|
|
187621
|
+
if (!toolCall && modelHost && (modelCounts[modelHost] || Object.keys(modelCounts).length < 8)) {
|
|
187622
|
+
const count9 = modelCounts[modelHost] ??= { requests: 0, ok: 0, refused: 0, other: 0 };
|
|
187623
|
+
count9.requests++;
|
|
187624
|
+
let recorded2 = false;
|
|
187625
|
+
recordModelStatus = (status4) => {
|
|
187626
|
+
if (recorded2) return;
|
|
187627
|
+
recorded2 = true;
|
|
187628
|
+
count9[status4 >= 200 && status4 < 300 ? "ok" : status4 === 401 || status4 === 403 ? "refused" : "other"]++;
|
|
187629
|
+
};
|
|
187630
|
+
res.once("finish", () => recordModelStatus?.(res.statusCode));
|
|
187631
|
+
res.once("close", () => recordModelStatus?.(502));
|
|
187632
|
+
}
|
|
187606
187633
|
const activityCallback = toolCall ? toolCall.op === "execute" ? options4.onModelActivity ?? route15.activity : void 0 : options4.onModelActivity;
|
|
187607
187634
|
if (toolCall) {
|
|
187608
187635
|
const call2 = toolCall, endWindow = call2.op === "execute" ? route15.begin() : void 0;
|
|
@@ -187707,6 +187734,7 @@ async function startIsolationGateway(options4) {
|
|
|
187707
187734
|
};
|
|
187708
187735
|
if (!toolCall && modelHost !== void 0 && reply6.statusCode !== void 0) {
|
|
187709
187736
|
const host = modelHost, status4 = reply6.statusCode;
|
|
187737
|
+
recordModelStatus?.(status4);
|
|
187710
187738
|
if (!MODEL_REFUSALS.has(status4)) observe2(host, status4);
|
|
187711
187739
|
else {
|
|
187712
187740
|
const chunks2 = [];
|
|
@@ -187939,7 +187967,7 @@ ${Object.entries(reply6.headers).map(([name5, value5]) => `${name5}: ${value5}`)
|
|
|
187939
187967
|
if (exposedOrigin !== url4 && exposedOrigin !== parsed4.origin) throw new Error("Sandbox relay origin is already configured");
|
|
187940
187968
|
exposedOrigin = parsed4.origin;
|
|
187941
187969
|
return mapped(exposedOrigin);
|
|
187942
|
-
}, close: close2 };
|
|
187970
|
+
}, modelRequests: () => Object.fromEntries(Object.entries(modelCounts).map(([host, counts2]) => [host, { ...counts2 }])), close: close2 };
|
|
187943
187971
|
}
|
|
187944
187972
|
|
|
187945
187973
|
// backend/src/agent-input.ts
|
package/lib/worker.mjs
CHANGED
|
@@ -71562,6 +71562,18 @@ function reject2(response6, status5 = 403, message8 = "This destination is outsi
|
|
|
71562
71562
|
response6.writeHead(status5, { "content-type": "application/json", "connection": "close" });
|
|
71563
71563
|
response6.end(JSON.stringify({ error: message8 }));
|
|
71564
71564
|
}
|
|
71565
|
+
function refusedRpc(body7) {
|
|
71566
|
+
try {
|
|
71567
|
+
const value5 = JSON.parse(body7?.toString("utf8") ?? "");
|
|
71568
|
+
if (!value5 || typeof value5 !== "object" || Array.isArray(value5)) return {};
|
|
71569
|
+
const { method: method2, params: params10 } = value5;
|
|
71570
|
+
if (typeof method2 !== "string" || method2.match(/^[A-Za-z][A-Za-z0-9_./-]{0,63}$/)?.[0] !== method2) return {};
|
|
71571
|
+
const name5 = method2 === "tools/call" ? params10?.name : void 0;
|
|
71572
|
+
return { rpc: method2, ...typeof name5 === "string" && name5.match(/^[A-Z][A-Z0-9_]{0,79}$/)?.[0] === name5 && { slug: name5 } };
|
|
71573
|
+
} catch {
|
|
71574
|
+
return {};
|
|
71575
|
+
}
|
|
71576
|
+
}
|
|
71565
71577
|
async function startIsolationGateway(options5) {
|
|
71566
71578
|
options5.signal?.throwIfAborted();
|
|
71567
71579
|
const env = structuredClone(options5.env), session2 = options5.session && structuredClone(options5.session);
|
|
@@ -71592,6 +71604,7 @@ async function startIsolationGateway(options5) {
|
|
|
71592
71604
|
const modelHosts = new Set((options5.modelHosts ?? []).map(normalizeModelHost));
|
|
71593
71605
|
const sockets = /* @__PURE__ */ new Set();
|
|
71594
71606
|
const upstreamRequests = /* @__PURE__ */ new Set();
|
|
71607
|
+
const modelCounts = {};
|
|
71595
71608
|
const modelActivity = /* @__PURE__ */ new Set();
|
|
71596
71609
|
const localRequests = /* @__PURE__ */ new Set();
|
|
71597
71610
|
let exposedOrigin, closed = false;
|
|
@@ -71621,7 +71634,8 @@ async function startIsolationGateway(options5) {
|
|
|
71621
71634
|
} catch (error64) {
|
|
71622
71635
|
const reason2 = error64 instanceof RouteRefusal ? error64.reason : "JSON";
|
|
71623
71636
|
const toolkit = (error64 instanceof RouteRefusal ? error64.toolkit : void 0) ?? (reason2 === "NETSUITE_TOOL" || /NETSUITE_/.test(toolBody?.toString("utf8") ?? "") || /NETSUITE_/.test(req.url ?? "") || route15?.toolkits && !route15.toolkits.quickbooks ? "netsuite" : "quickbooks");
|
|
71624
|
-
|
|
71637
|
+
const via = composioVia((req.url ?? "").slice("/_tool/composio".length));
|
|
71638
|
+
route15?.record({ leg: "platform", op: "refused", toolkit, via, method: ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"].includes(req.method ?? "") ? req.method : "OTHER", ...req.method === "POST" && via === "mcp" && refusedRpc(toolBody), status: 403, ms: Math.round(performance.now() - toolStarted), reason: reason2 });
|
|
71625
71639
|
refuseComposio(res, reason2, toolkit);
|
|
71626
71640
|
return;
|
|
71627
71641
|
}
|
|
@@ -71683,12 +71697,25 @@ async function startIsolationGateway(options5) {
|
|
|
71683
71697
|
if (!path8) return reject2(res);
|
|
71684
71698
|
let upstream;
|
|
71685
71699
|
let modelHost;
|
|
71700
|
+
let recordModelStatus;
|
|
71686
71701
|
let modelAddress;
|
|
71687
71702
|
let targetPath = req.url;
|
|
71688
71703
|
let transform3;
|
|
71689
71704
|
const model = /^\/_model\/([a-zA-Z0-9.-]+)(\/.*)?$/.exec(path8);
|
|
71690
71705
|
if (toolCall || model && modelHosts.has(model[1].toLowerCase())) {
|
|
71691
71706
|
modelHost = toolCall ? "backend.composio.dev" : model[1].toLowerCase();
|
|
71707
|
+
if (!toolCall && modelHost && (modelCounts[modelHost] || Object.keys(modelCounts).length < 8)) {
|
|
71708
|
+
const count11 = modelCounts[modelHost] ??= { requests: 0, ok: 0, refused: 0, other: 0 };
|
|
71709
|
+
count11.requests++;
|
|
71710
|
+
let recorded2 = false;
|
|
71711
|
+
recordModelStatus = (status5) => {
|
|
71712
|
+
if (recorded2) return;
|
|
71713
|
+
recorded2 = true;
|
|
71714
|
+
count11[status5 >= 200 && status5 < 300 ? "ok" : status5 === 401 || status5 === 403 ? "refused" : "other"]++;
|
|
71715
|
+
};
|
|
71716
|
+
res.once("finish", () => recordModelStatus?.(res.statusCode));
|
|
71717
|
+
res.once("close", () => recordModelStatus?.(502));
|
|
71718
|
+
}
|
|
71692
71719
|
const activityCallback = toolCall ? toolCall.op === "execute" ? options5.onModelActivity ?? route15.activity : void 0 : options5.onModelActivity;
|
|
71693
71720
|
if (toolCall) {
|
|
71694
71721
|
const call2 = toolCall, endWindow = call2.op === "execute" ? route15.begin() : void 0;
|
|
@@ -71793,6 +71820,7 @@ async function startIsolationGateway(options5) {
|
|
|
71793
71820
|
};
|
|
71794
71821
|
if (!toolCall && modelHost !== void 0 && reply6.statusCode !== void 0) {
|
|
71795
71822
|
const host = modelHost, status5 = reply6.statusCode;
|
|
71823
|
+
recordModelStatus?.(status5);
|
|
71796
71824
|
if (!MODEL_REFUSALS.has(status5)) observe2(host, status5);
|
|
71797
71825
|
else {
|
|
71798
71826
|
const chunks2 = [];
|
|
@@ -72025,7 +72053,7 @@ ${Object.entries(reply6.headers).map(([name5, value5]) => `${name5}: ${value5}`)
|
|
|
72025
72053
|
if (exposedOrigin !== url4 && exposedOrigin !== parsed4.origin) throw new Error("Sandbox relay origin is already configured");
|
|
72026
72054
|
exposedOrigin = parsed4.origin;
|
|
72027
72055
|
return mapped(exposedOrigin);
|
|
72028
|
-
}, close: close2 };
|
|
72056
|
+
}, modelRequests: () => Object.fromEntries(Object.entries(modelCounts).map(([host, counts2]) => [host, { ...counts2 }])), close: close2 };
|
|
72029
72057
|
}
|
|
72030
72058
|
var BODY_LIMIT, HOP_HEADERS, MODEL_REFUSALS, REFUSAL_BYTES;
|
|
72031
72059
|
var init_gateway = __esm({
|
|
@@ -223966,6 +223994,27 @@ var init_process = __esm({
|
|
|
223966
223994
|
});
|
|
223967
223995
|
|
|
223968
223996
|
// backend/src/execution/contained-env.ts
|
|
223997
|
+
function modelSettings(values3, modelUrls) {
|
|
223998
|
+
const settings = [];
|
|
223999
|
+
for (const name5 of ["ANTHROPIC_BASE_URL", "OPENAI_BASE_URL", "OPENROUTER_BASE_URL"]) {
|
|
224000
|
+
const value5 = values3[name5];
|
|
224001
|
+
if (!value5) continue;
|
|
224002
|
+
const mapped = Object.entries(modelUrls).find(([, url4]) => value5 === url4 || value5.startsWith(url4 + "/") || value5.startsWith(url4 + "?") || value5.startsWith(url4 + "#"));
|
|
224003
|
+
if (mapped) {
|
|
224004
|
+
settings.push({ name: name5, via: "ancha", host: mapped[0] });
|
|
224005
|
+
continue;
|
|
224006
|
+
}
|
|
224007
|
+
let host;
|
|
224008
|
+
try {
|
|
224009
|
+
const parsed4 = new URL(value5).hostname;
|
|
224010
|
+
host = parsed4.length <= 253 ? parsed4 || void 0 : void 0;
|
|
224011
|
+
} catch {
|
|
224012
|
+
}
|
|
224013
|
+
settings.push({ name: name5, ...host && { host } });
|
|
224014
|
+
}
|
|
224015
|
+
for (const name5 of ["ANTHROPIC_AUTH_TOKEN", "ANTHROPIC_API_KEY", "OPENAI_API_KEY", "OPENROUTER_API_KEY"]) settings.push({ name: name5, set: !!values3[name5] });
|
|
224016
|
+
return settings;
|
|
224017
|
+
}
|
|
223969
224018
|
function vmEnvironmentNames(agent) {
|
|
223970
224019
|
const execution2 = agent.execution === void 0 ? void 0 : parseExecutionPolicy(agent.execution);
|
|
223971
224020
|
const env = [.../* @__PURE__ */ new Set([...agent.passEnv ?? [], ...execution2?.mode === "container" ? execution2.env : []])].sort();
|
|
@@ -225093,6 +225142,7 @@ async function startVmAgent(command, opts, deps = {}) {
|
|
|
225093
225142
|
if (Object.entries(values3).some(([name5, value5]) => !/^[A-Za-z_][A-Za-z0-9_]*$/.test(name5) || value5?.includes("\0")) || Buffer.byteLength(JSON.stringify(values3)) + Buffer.byteLength(command) > 262144) {
|
|
225094
225143
|
throw new AnchaError("CONFIG_INVALID", "Agent launch environment and command must fit within 256 KiB and contain valid variable names.");
|
|
225095
225144
|
}
|
|
225145
|
+
const settings = modelSettings(values3, mapped.modelUrls);
|
|
225096
225146
|
await mkdir7(opts.dir, { recursive: true });
|
|
225097
225147
|
await writeFile9(join17(opts.dir, "execution.json"), JSON.stringify({ mode: "vm", runtime: runtime2, contained: !unsafe, network: unsafe ? "local-test" : "loopback-with-scoped-gateway", project: "prepared-copy", scratch: "fresh-per-attempt", credentials: "explicit-only", modelHosts, uid: descriptor2.uid, gid: descriptor2.gid, pids: 1024 }, null, 2) + "\n", { mode: 384 });
|
|
225098
225148
|
opts.signal?.throwIfAborted();
|
|
@@ -225200,7 +225250,7 @@ async function startVmAgent(command, opts, deps = {}) {
|
|
|
225200
225250
|
return { pid: child3.pid, exited, async stop() {
|
|
225201
225251
|
await cleanup();
|
|
225202
225252
|
await exited;
|
|
225203
|
-
}, output: () => ({ stdout: tail.text(), printed: tail.length(), modelReplies: replies.list(), sessionRefusals: refusals.list(), modelRefusal: replies.refusal() }) };
|
|
225253
|
+
}, output: () => ({ stdout: tail.text(), printed: tail.length(), model: { settings, requests: gateway2.modelRequests() }, modelReplies: replies.list(), sessionRefusals: refusals.list(), modelRefusal: replies.refusal() }) };
|
|
225204
225254
|
} catch (error64) {
|
|
225205
225255
|
await cleanup();
|
|
225206
225256
|
throw error64;
|
|
@@ -225495,13 +225545,14 @@ async function runEndpointTrial(spec) {
|
|
|
225495
225545
|
if (failure5) throw failure5.error;
|
|
225496
225546
|
signal?.throwIfAborted();
|
|
225497
225547
|
const { checks: checks2, trace: trace2, simMs, harnessIssues } = capture3;
|
|
225498
|
-
const result = completion;
|
|
225548
|
+
const result = completion, model = child3?.output?.().model;
|
|
225499
225549
|
return {
|
|
225500
225550
|
sceneId: scene2.id,
|
|
225501
225551
|
trial,
|
|
225502
225552
|
envId: env.id,
|
|
225503
225553
|
sessionId: session2.id,
|
|
225504
225554
|
...result,
|
|
225555
|
+
...model && { model },
|
|
225505
225556
|
realMs: Math.round(performance.now() - startedAt),
|
|
225506
225557
|
simMs,
|
|
225507
225558
|
checks: checks2,
|
|
@@ -225723,6 +225774,7 @@ async function runHttpTaskTrial(spec) {
|
|
|
225723
225774
|
signal?.throwIfAborted();
|
|
225724
225775
|
if (controlFailure) throw controlFailure.error;
|
|
225725
225776
|
const issues = [...capture3.harnessIssues, ...failure5 ? [{ kind: "delivery", owner: "harness", service: "agent-input", message: failure5 }] : [], ...answerIssue ? [answerIssue] : []];
|
|
225777
|
+
const model = child3?.output?.().model;
|
|
225726
225778
|
const exit = !ready3 ? "spawn_failed" : timedOut ? "timeout" : "done";
|
|
225727
225779
|
return {
|
|
225728
225780
|
sceneId: scene2.id,
|
|
@@ -225731,6 +225783,7 @@ async function runHttpTaskTrial(spec) {
|
|
|
225731
225783
|
sessionId: session2.id,
|
|
225732
225784
|
exit,
|
|
225733
225785
|
exitCode: null,
|
|
225786
|
+
...model && { model },
|
|
225734
225787
|
realMs: Math.round(performance.now() - started2),
|
|
225735
225788
|
simMs: capture3.simMs,
|
|
225736
225789
|
checks: capture3.checks,
|
|
@@ -226101,6 +226154,7 @@ async function runTrialInner(spec) {
|
|
|
226101
226154
|
simMs,
|
|
226102
226155
|
...playOut !== void 0 && playOut.toMs > playOut.fromMs && { playOut },
|
|
226103
226156
|
checks: checks2,
|
|
226157
|
+
...output2?.model && { model: output2.model },
|
|
226104
226158
|
...output2?.modelReplies?.length && { modelReplies: output2.modelReplies },
|
|
226105
226159
|
...output2?.sessionRefusals?.length && { sessionRefusals: output2.sessionRefusals },
|
|
226106
226160
|
logTail: exit === "idle" || exit === "done" || exit === "exited" && exitCode === 0 ? [] : await logTail(join21(dir, "agent.log")),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ancha-labs/cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.53",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Simulation playgrounds for agents: run your agent against stateful replicas of Slack, GitHub, Datadog and more, each attempt on a fresh cloud machine in your app.ancha.io workspace, or on your computer.",
|
|
6
6
|
"bugs": {
|