@ancha-labs/cli 0.4.51 → 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 +1632 -1485
- package/lib/assets/docs/cloud.md +4 -2
- package/lib/assets/harbor/companion.mjs +42 -5
- package/lib/worker.mjs +73 -8
- 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.
|
|
@@ -181,7 +183,7 @@ ancha run --on cloud
|
|
|
181
183
|
- Declare either route or both. Each test's world decides which routed tools it answers. QuickBooks-only and NetSuite-only tests can use the same agent configuration. A call to a declared tool that the world lacks returns `403 COMPOSIO_ROUTE_REFUSED` with reason `NO_WORLD` and a fix to add the tool to the world or run the call in a test whose world has it. The agent gets that answer and the attempt is graded as usual, as it is when a SuiteQL call's arguments are invalid. A call to a QuickBooks or NetSuite tool whose toolkit is not under `agent.routes` returns reason `NOT_ROUTED` with the line to add, such as `quickbooks: composio`; the attempt is invalid until the route is declared.
|
|
182
184
|
- The agent keeps its Composio code. Each attempt sets `COMPOSIO_BASE_URL` to Composio's API through the attempt's gateway (the Composio SDKs read it; a client built with an explicit base URL takes this value) and `COMPOSIO_API_KEY` to a key for this attempt; the gateway sends the project's key to Composio for QuickBooks calls. `QUICKBOOKS_PUBLIC_URL` is this world's QuickBooks at an address Composio reaches for this attempt only; `QUICKBOOKS_ACCESS_TOKEN` and `QUICKBOOKS_REALM_ID` are the world's, as in any test with QuickBooks.
|
|
183
185
|
- QuickBooks direct executions (`tools.execute`) reach the world whatever user ID or connected account the agent names: the gateway supplies the world's address and credentials on each call. An agent that already passes `custom_auth_params` keeps them: `base_url` is `QUICKBOOKS_PUBLIC_URL` with the world's `Authorization` and `x-quickbooks-realm-id` headers.
|
|
184
|
-
- When the world has routed QuickBooks, Tool Router sessions reach the world through a QuickBooks connection the attempt creates in the project for its own user (`ancha-…`). Sessions are pinned to it, and the session's MCP URL points at the gateway, so an MCP client in the agent's process reaches the same session. When the attempt ends it deletes the sessions, the connection and its auth config.
|
|
186
|
+
- When the world has routed QuickBooks, Tool Router sessions reach the world through a QuickBooks connection the attempt creates in the project for its own user (`ancha-…`). Sessions are pinned to it, and the session's MCP URL points at the gateway, so an MCP client in the agent's process reaches the same session. MCP clients such as Claude Code connect as they do to Composio: their tool calls reach the world, and every other request goes to Composio as sent. When the attempt ends it deletes the sessions, the connection and its auth config.
|
|
185
187
|
- NetSuite calls use `NETSUITE_RUN_SUITEQL_QUERY`, its SuiteQL query in `q` and optional paging arguments, through `session.execute` or `tools.execute`. The gateway supplies the world's NetSuite credentials and returns the SuiteQL REST body in the Composio response. When QuickBooks is inactive in the test, sessions are created, read and deleted in the gateway; when both routes are active, the gateway handles NetSuite reads and Composio handles QuickBooks.
|
|
186
188
|
- Before an agent with an active QuickBooks route starts, the attempt checks that `QUICKBOOKS_PUBLIC_URL` answers from outside.
|
|
187
189
|
- The gateway keeps every call on the world: a call that names another toolkit's tools, changes a session's connection, proxies a request or reaches another attempt's session gets `403 COMPOSIO_ROUTE_REFUSED` with a `reason`, and the attempt is invalid with `ROUTE_REFUSED`, so every result rests on calls inside the world.
|
|
@@ -187139,13 +187139,16 @@ function validateComposio(method2, target5, apiKey, body7, contentType, route15,
|
|
|
187139
187139
|
}
|
|
187140
187140
|
const mcp = /^\/tool_router\/([^/]+)\/mcp$/.exec(url4.pathname);
|
|
187141
187141
|
if (mcp) {
|
|
187142
|
-
if (method2 !== "POST") refuse("METHOD");
|
|
187143
187142
|
if (!identifier4.test(mcp[1]) || !route15.sessions.has(mcp[1])) refuse("SESSION");
|
|
187144
187143
|
noQuery();
|
|
187144
|
+
if (method2 === "GET" || method2 === "DELETE") {
|
|
187145
|
+
empty2();
|
|
187146
|
+
return { ...base6, local: "mcp", response: method2 === "GET" ? "mcp-get" : "mcp-delete" };
|
|
187147
|
+
}
|
|
187148
|
+
if (method2 !== "POST") refuse("METHOD");
|
|
187145
187149
|
const forwarded = protocolHeaders(headers), json37 = jsonBody3(body7, contentType);
|
|
187146
187150
|
if (Array.isArray(json37)) refuse("MCP_BATCH");
|
|
187147
187151
|
const value5 = parsed3(external_exports.strictObject({ jsonrpc: external_exports.literal("2.0"), id: external_exports.union([external_exports.string(), external_exports.number(), external_exports.null()]).optional(), method: external_exports.string(), params: record10.optional() }), json37);
|
|
187148
|
-
if (!["initialize", "notifications/initialized", "notifications/cancelled", "ping", "tools/list", "tools/call"].includes(value5.method)) refuse("MCP_METHOD");
|
|
187149
187152
|
if (value5.method === "tools/call") {
|
|
187150
187153
|
const params10 = parsed3(external_exports.strictObject({ name: external_exports.string(), arguments: record10.optional(), account: external_exports.unknown().optional(), _meta: record10.optional() }), value5.params);
|
|
187151
187154
|
const call2 = toolArguments(route15, params10.name, params10.arguments);
|
|
@@ -187321,6 +187324,12 @@ function nextRouteId(route15, kind) {
|
|
|
187321
187324
|
}
|
|
187322
187325
|
var suiteqlArguments = external_exports.strictObject({ q: external_exports.string(), limit: external_exports.number().int().min(1).optional(), offset: external_exports.number().int().min(0).optional() });
|
|
187323
187326
|
async function executeLocalComposio(call2, route15, origin, fetcher = fetch, signal) {
|
|
187327
|
+
if (call2.local === "mcp") return call2.response === "mcp-get" ? { status: 405, headers: { allow: "POST" }, body: {
|
|
187328
|
+
error: "method_not_allowed",
|
|
187329
|
+
message: "This MCP endpoint accepts POST requests. GET/SSE streaming is not supported on this transport.",
|
|
187330
|
+
allowed_methods: ["POST"],
|
|
187331
|
+
docs: "https://docs.composio.dev/mcp"
|
|
187332
|
+
} } : { status: 405 };
|
|
187324
187333
|
if (call2.local === "session") {
|
|
187325
187334
|
route15.narrowed(call2.narrowed ?? []);
|
|
187326
187335
|
if (call2.response === "session-delete") {
|
|
@@ -187467,6 +187476,18 @@ function reject2(response6, status4 = 403, message9 = "This destination is outsi
|
|
|
187467
187476
|
response6.writeHead(status4, { "content-type": "application/json", "connection": "close" });
|
|
187468
187477
|
response6.end(JSON.stringify({ error: message9 }));
|
|
187469
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
|
+
}
|
|
187470
187491
|
async function startIsolationGateway(options4) {
|
|
187471
187492
|
options4.signal?.throwIfAborted();
|
|
187472
187493
|
const env = structuredClone(options4.env), session2 = options4.session && structuredClone(options4.session);
|
|
@@ -187497,6 +187518,7 @@ async function startIsolationGateway(options4) {
|
|
|
187497
187518
|
const modelHosts = new Set((options4.modelHosts ?? []).map(normalizeModelHost));
|
|
187498
187519
|
const sockets = /* @__PURE__ */ new Set();
|
|
187499
187520
|
const upstreamRequests = /* @__PURE__ */ new Set();
|
|
187521
|
+
const modelCounts = {};
|
|
187500
187522
|
const modelActivity = /* @__PURE__ */ new Set();
|
|
187501
187523
|
const localRequests = /* @__PURE__ */ new Set();
|
|
187502
187524
|
let exposedOrigin, closed = false;
|
|
@@ -187526,7 +187548,8 @@ async function startIsolationGateway(options4) {
|
|
|
187526
187548
|
} catch (error64) {
|
|
187527
187549
|
const reason2 = error64 instanceof RouteRefusal ? error64.reason : "JSON";
|
|
187528
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");
|
|
187529
|
-
|
|
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 });
|
|
187530
187553
|
refuseComposio(res, reason2, toolkit);
|
|
187531
187554
|
return;
|
|
187532
187555
|
}
|
|
@@ -187552,7 +187575,7 @@ async function startIsolationGateway(options4) {
|
|
|
187552
187575
|
reached = result.reached;
|
|
187553
187576
|
invalidArguments = result.invalidArguments === true;
|
|
187554
187577
|
if (!res.destroyed) {
|
|
187555
|
-
res.writeHead(result.status, { "content-type": "application/json" });
|
|
187578
|
+
res.writeHead(result.status, { "content-type": "application/json", ...result.headers });
|
|
187556
187579
|
res.end(result.body === void 0 ? void 0 : JSON.stringify(result.body));
|
|
187557
187580
|
}
|
|
187558
187581
|
} catch {
|
|
@@ -187588,12 +187611,25 @@ async function startIsolationGateway(options4) {
|
|
|
187588
187611
|
if (!path6) return reject2(res);
|
|
187589
187612
|
let upstream;
|
|
187590
187613
|
let modelHost;
|
|
187614
|
+
let recordModelStatus;
|
|
187591
187615
|
let modelAddress;
|
|
187592
187616
|
let targetPath = req.url;
|
|
187593
187617
|
let transform3;
|
|
187594
187618
|
const model = /^\/_model\/([a-zA-Z0-9.-]+)(\/.*)?$/.exec(path6);
|
|
187595
187619
|
if (toolCall || model && modelHosts.has(model[1].toLowerCase())) {
|
|
187596
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
|
+
}
|
|
187597
187633
|
const activityCallback = toolCall ? toolCall.op === "execute" ? options4.onModelActivity ?? route15.activity : void 0 : options4.onModelActivity;
|
|
187598
187634
|
if (toolCall) {
|
|
187599
187635
|
const call2 = toolCall, endWindow = call2.op === "execute" ? route15.begin() : void 0;
|
|
@@ -187698,6 +187734,7 @@ async function startIsolationGateway(options4) {
|
|
|
187698
187734
|
};
|
|
187699
187735
|
if (!toolCall && modelHost !== void 0 && reply6.statusCode !== void 0) {
|
|
187700
187736
|
const host = modelHost, status4 = reply6.statusCode;
|
|
187737
|
+
recordModelStatus?.(status4);
|
|
187701
187738
|
if (!MODEL_REFUSALS.has(status4)) observe2(host, status4);
|
|
187702
187739
|
else {
|
|
187703
187740
|
const chunks2 = [];
|
|
@@ -187930,7 +187967,7 @@ ${Object.entries(reply6.headers).map(([name5, value5]) => `${name5}: ${value5}`)
|
|
|
187930
187967
|
if (exposedOrigin !== url4 && exposedOrigin !== parsed4.origin) throw new Error("Sandbox relay origin is already configured");
|
|
187931
187968
|
exposedOrigin = parsed4.origin;
|
|
187932
187969
|
return mapped(exposedOrigin);
|
|
187933
|
-
}, close: close2 };
|
|
187970
|
+
}, modelRequests: () => Object.fromEntries(Object.entries(modelCounts).map(([host, counts2]) => [host, { ...counts2 }])), close: close2 };
|
|
187934
187971
|
}
|
|
187935
187972
|
|
|
187936
187973
|
// backend/src/agent-input.ts
|
package/lib/worker.mjs
CHANGED
|
@@ -71166,13 +71166,16 @@ function validateComposio(method2, target5, apiKey, body7, contentType, route15,
|
|
|
71166
71166
|
}
|
|
71167
71167
|
const mcp = /^\/tool_router\/([^/]+)\/mcp$/.exec(url4.pathname);
|
|
71168
71168
|
if (mcp) {
|
|
71169
|
-
if (method2 !== "POST") refuse("METHOD");
|
|
71170
71169
|
if (!identifier.test(mcp[1]) || !route15.sessions.has(mcp[1])) refuse("SESSION");
|
|
71171
71170
|
noQuery();
|
|
71171
|
+
if (method2 === "GET" || method2 === "DELETE") {
|
|
71172
|
+
empty2();
|
|
71173
|
+
return { ...base6, local: "mcp", response: method2 === "GET" ? "mcp-get" : "mcp-delete" };
|
|
71174
|
+
}
|
|
71175
|
+
if (method2 !== "POST") refuse("METHOD");
|
|
71172
71176
|
const forwarded2 = protocolHeaders(headers), json37 = jsonBody(body7, contentType);
|
|
71173
71177
|
if (Array.isArray(json37)) refuse("MCP_BATCH");
|
|
71174
71178
|
const value5 = parsed2(external_exports.strictObject({ jsonrpc: external_exports.literal("2.0"), id: external_exports.union([external_exports.string(), external_exports.number(), external_exports.null()]).optional(), method: external_exports.string(), params: record7.optional() }), json37);
|
|
71175
|
-
if (!["initialize", "notifications/initialized", "notifications/cancelled", "ping", "tools/list", "tools/call"].includes(value5.method)) refuse("MCP_METHOD");
|
|
71176
71179
|
if (value5.method === "tools/call") {
|
|
71177
71180
|
const params10 = parsed2(external_exports.strictObject({ name: external_exports.string(), arguments: record7.optional(), account: external_exports.unknown().optional(), _meta: record7.optional() }), value5.params);
|
|
71178
71181
|
const call2 = toolArguments(route15, params10.name, params10.arguments);
|
|
@@ -71346,6 +71349,12 @@ function nextRouteId(route15, kind) {
|
|
|
71346
71349
|
return `${kind}_${ids3.fork(kind).alnumUpper(16)}`;
|
|
71347
71350
|
}
|
|
71348
71351
|
async function executeLocalComposio(call2, route15, origin, fetcher = fetch, signal) {
|
|
71352
|
+
if (call2.local === "mcp") return call2.response === "mcp-get" ? { status: 405, headers: { allow: "POST" }, body: {
|
|
71353
|
+
error: "method_not_allowed",
|
|
71354
|
+
message: "This MCP endpoint accepts POST requests. GET/SSE streaming is not supported on this transport.",
|
|
71355
|
+
allowed_methods: ["POST"],
|
|
71356
|
+
docs: "https://docs.composio.dev/mcp"
|
|
71357
|
+
} } : { status: 405 };
|
|
71349
71358
|
if (call2.local === "session") {
|
|
71350
71359
|
route15.narrowed(call2.narrowed ?? []);
|
|
71351
71360
|
if (call2.response === "session-delete") {
|
|
@@ -71553,6 +71562,18 @@ function reject2(response6, status5 = 403, message8 = "This destination is outsi
|
|
|
71553
71562
|
response6.writeHead(status5, { "content-type": "application/json", "connection": "close" });
|
|
71554
71563
|
response6.end(JSON.stringify({ error: message8 }));
|
|
71555
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
|
+
}
|
|
71556
71577
|
async function startIsolationGateway(options5) {
|
|
71557
71578
|
options5.signal?.throwIfAborted();
|
|
71558
71579
|
const env = structuredClone(options5.env), session2 = options5.session && structuredClone(options5.session);
|
|
@@ -71583,6 +71604,7 @@ async function startIsolationGateway(options5) {
|
|
|
71583
71604
|
const modelHosts = new Set((options5.modelHosts ?? []).map(normalizeModelHost));
|
|
71584
71605
|
const sockets = /* @__PURE__ */ new Set();
|
|
71585
71606
|
const upstreamRequests = /* @__PURE__ */ new Set();
|
|
71607
|
+
const modelCounts = {};
|
|
71586
71608
|
const modelActivity = /* @__PURE__ */ new Set();
|
|
71587
71609
|
const localRequests = /* @__PURE__ */ new Set();
|
|
71588
71610
|
let exposedOrigin, closed = false;
|
|
@@ -71612,7 +71634,8 @@ async function startIsolationGateway(options5) {
|
|
|
71612
71634
|
} catch (error64) {
|
|
71613
71635
|
const reason2 = error64 instanceof RouteRefusal ? error64.reason : "JSON";
|
|
71614
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");
|
|
71615
|
-
|
|
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 });
|
|
71616
71639
|
refuseComposio(res, reason2, toolkit);
|
|
71617
71640
|
return;
|
|
71618
71641
|
}
|
|
@@ -71638,7 +71661,7 @@ async function startIsolationGateway(options5) {
|
|
|
71638
71661
|
reached = result.reached;
|
|
71639
71662
|
invalidArguments = result.invalidArguments === true;
|
|
71640
71663
|
if (!res.destroyed) {
|
|
71641
|
-
res.writeHead(result.status, { "content-type": "application/json" });
|
|
71664
|
+
res.writeHead(result.status, { "content-type": "application/json", ...result.headers });
|
|
71642
71665
|
res.end(result.body === void 0 ? void 0 : JSON.stringify(result.body));
|
|
71643
71666
|
}
|
|
71644
71667
|
} catch {
|
|
@@ -71674,12 +71697,25 @@ async function startIsolationGateway(options5) {
|
|
|
71674
71697
|
if (!path8) return reject2(res);
|
|
71675
71698
|
let upstream;
|
|
71676
71699
|
let modelHost;
|
|
71700
|
+
let recordModelStatus;
|
|
71677
71701
|
let modelAddress;
|
|
71678
71702
|
let targetPath = req.url;
|
|
71679
71703
|
let transform3;
|
|
71680
71704
|
const model = /^\/_model\/([a-zA-Z0-9.-]+)(\/.*)?$/.exec(path8);
|
|
71681
71705
|
if (toolCall || model && modelHosts.has(model[1].toLowerCase())) {
|
|
71682
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
|
+
}
|
|
71683
71719
|
const activityCallback = toolCall ? toolCall.op === "execute" ? options5.onModelActivity ?? route15.activity : void 0 : options5.onModelActivity;
|
|
71684
71720
|
if (toolCall) {
|
|
71685
71721
|
const call2 = toolCall, endWindow = call2.op === "execute" ? route15.begin() : void 0;
|
|
@@ -71784,6 +71820,7 @@ async function startIsolationGateway(options5) {
|
|
|
71784
71820
|
};
|
|
71785
71821
|
if (!toolCall && modelHost !== void 0 && reply6.statusCode !== void 0) {
|
|
71786
71822
|
const host = modelHost, status5 = reply6.statusCode;
|
|
71823
|
+
recordModelStatus?.(status5);
|
|
71787
71824
|
if (!MODEL_REFUSALS.has(status5)) observe2(host, status5);
|
|
71788
71825
|
else {
|
|
71789
71826
|
const chunks2 = [];
|
|
@@ -72016,7 +72053,7 @@ ${Object.entries(reply6.headers).map(([name5, value5]) => `${name5}: ${value5}`)
|
|
|
72016
72053
|
if (exposedOrigin !== url4 && exposedOrigin !== parsed4.origin) throw new Error("Sandbox relay origin is already configured");
|
|
72017
72054
|
exposedOrigin = parsed4.origin;
|
|
72018
72055
|
return mapped(exposedOrigin);
|
|
72019
|
-
}, close: close2 };
|
|
72056
|
+
}, modelRequests: () => Object.fromEntries(Object.entries(modelCounts).map(([host, counts2]) => [host, { ...counts2 }])), close: close2 };
|
|
72020
72057
|
}
|
|
72021
72058
|
var BODY_LIMIT, HOP_HEADERS, MODEL_REFUSALS, REFUSAL_BYTES;
|
|
72022
72059
|
var init_gateway = __esm({
|
|
@@ -72705,7 +72742,6 @@ var init_ingress_client = __esm({
|
|
|
72705
72742
|
TOOL: "execute a QUICKBOOKS_ tool",
|
|
72706
72743
|
META_TOOL: "use COMPOSIO_MULTI_EXECUTE_TOOL, COMPOSIO_SEARCH_TOOLS or COMPOSIO_GET_TOOL_SCHEMAS; multi-execute items must be QUICKBOOKS_ tools",
|
|
72707
72744
|
ACCOUNT: "list the route connected accounts and use the returned test connection",
|
|
72708
|
-
MCP_METHOD: "use initialize, notifications/initialized, notifications/cancelled, ping, tools/list or tools/call",
|
|
72709
72745
|
MCP_BATCH: "send one JSON-RPC object per MCP request"
|
|
72710
72746
|
};
|
|
72711
72747
|
unreachedDetail = (status5) => status5 === 401 || status5 === 403 ? `Composio answered ${status5} without calling the world: check the workspace secret COMPOSIO_API_KEY.` : status5 >= 500 ? `Composio answered ${status5} without calling the world; run again.` : `Composio answered ${status5} without calling the world: check the QuickBooks tool arguments and use the connection supplied by the route.`;
|
|
@@ -73576,6 +73612,9 @@ function missingFix(text26, context3) {
|
|
|
73576
73612
|
function likelyFix(logTail3, context3 = {}) {
|
|
73577
73613
|
const task2 = taskFix(logTail3.join("\n"), context3.command);
|
|
73578
73614
|
if (task2 !== void 0 || context3.withheld !== void 0) return task2 ?? context3.withheld;
|
|
73615
|
+
if (logTail3.some((line2) => /^Not logged in · Please run \/login\b/.test(line2.trim()))) {
|
|
73616
|
+
return `Claude Code had no key (its /login stays on your computer): through OpenRouter, start agent.command with ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY" and set ANTHROPIC_BASE_URL: https://openrouter.ai/api under agent.env; with an Anthropic key, ${context3.target === "cloud" ? "run ancha secrets set ANTHROPIC_API_KEY in the project" : "set ANTHROPIC_API_KEY in this shell and list it under agent.pass_env in ancha.yaml"}`;
|
|
73617
|
+
}
|
|
73579
73618
|
const errors2 = logTail3.filter((line2) => /error|exception|fatal|panic|missing|required|usage|not set|not found|cannot|can't/i.test(line2));
|
|
73580
73619
|
for (const lines of [errors2, logTail3]) {
|
|
73581
73620
|
const fix = lines.length === 0 ? void 0 : keyFix(lines, context3) ?? missingFix(lines.join("\n"), context3);
|
|
@@ -223955,6 +223994,27 @@ var init_process = __esm({
|
|
|
223955
223994
|
});
|
|
223956
223995
|
|
|
223957
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
|
+
}
|
|
223958
224018
|
function vmEnvironmentNames(agent) {
|
|
223959
224019
|
const execution2 = agent.execution === void 0 ? void 0 : parseExecutionPolicy(agent.execution);
|
|
223960
224020
|
const env = [.../* @__PURE__ */ new Set([...agent.passEnv ?? [], ...execution2?.mode === "container" ? execution2.env : []])].sort();
|
|
@@ -225082,6 +225142,7 @@ async function startVmAgent(command, opts, deps = {}) {
|
|
|
225082
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) {
|
|
225083
225143
|
throw new AnchaError("CONFIG_INVALID", "Agent launch environment and command must fit within 256 KiB and contain valid variable names.");
|
|
225084
225144
|
}
|
|
225145
|
+
const settings = modelSettings(values3, mapped.modelUrls);
|
|
225085
225146
|
await mkdir7(opts.dir, { recursive: true });
|
|
225086
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 });
|
|
225087
225148
|
opts.signal?.throwIfAborted();
|
|
@@ -225189,7 +225250,7 @@ async function startVmAgent(command, opts, deps = {}) {
|
|
|
225189
225250
|
return { pid: child3.pid, exited, async stop() {
|
|
225190
225251
|
await cleanup();
|
|
225191
225252
|
await exited;
|
|
225192
|
-
}, 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() }) };
|
|
225193
225254
|
} catch (error64) {
|
|
225194
225255
|
await cleanup();
|
|
225195
225256
|
throw error64;
|
|
@@ -225484,13 +225545,14 @@ async function runEndpointTrial(spec) {
|
|
|
225484
225545
|
if (failure5) throw failure5.error;
|
|
225485
225546
|
signal?.throwIfAborted();
|
|
225486
225547
|
const { checks: checks2, trace: trace2, simMs, harnessIssues } = capture3;
|
|
225487
|
-
const result = completion;
|
|
225548
|
+
const result = completion, model = child3?.output?.().model;
|
|
225488
225549
|
return {
|
|
225489
225550
|
sceneId: scene2.id,
|
|
225490
225551
|
trial,
|
|
225491
225552
|
envId: env.id,
|
|
225492
225553
|
sessionId: session2.id,
|
|
225493
225554
|
...result,
|
|
225555
|
+
...model && { model },
|
|
225494
225556
|
realMs: Math.round(performance.now() - startedAt),
|
|
225495
225557
|
simMs,
|
|
225496
225558
|
checks: checks2,
|
|
@@ -225712,6 +225774,7 @@ async function runHttpTaskTrial(spec) {
|
|
|
225712
225774
|
signal?.throwIfAborted();
|
|
225713
225775
|
if (controlFailure) throw controlFailure.error;
|
|
225714
225776
|
const issues = [...capture3.harnessIssues, ...failure5 ? [{ kind: "delivery", owner: "harness", service: "agent-input", message: failure5 }] : [], ...answerIssue ? [answerIssue] : []];
|
|
225777
|
+
const model = child3?.output?.().model;
|
|
225715
225778
|
const exit = !ready3 ? "spawn_failed" : timedOut ? "timeout" : "done";
|
|
225716
225779
|
return {
|
|
225717
225780
|
sceneId: scene2.id,
|
|
@@ -225720,6 +225783,7 @@ async function runHttpTaskTrial(spec) {
|
|
|
225720
225783
|
sessionId: session2.id,
|
|
225721
225784
|
exit,
|
|
225722
225785
|
exitCode: null,
|
|
225786
|
+
...model && { model },
|
|
225723
225787
|
realMs: Math.round(performance.now() - started2),
|
|
225724
225788
|
simMs: capture3.simMs,
|
|
225725
225789
|
checks: capture3.checks,
|
|
@@ -226090,6 +226154,7 @@ async function runTrialInner(spec) {
|
|
|
226090
226154
|
simMs,
|
|
226091
226155
|
...playOut !== void 0 && playOut.toMs > playOut.fromMs && { playOut },
|
|
226092
226156
|
checks: checks2,
|
|
226157
|
+
...output2?.model && { model: output2.model },
|
|
226093
226158
|
...output2?.modelReplies?.length && { modelReplies: output2.modelReplies },
|
|
226094
226159
|
...output2?.sessionRefusals?.length && { sessionRefusals: output2.sessionRefusals },
|
|
226095
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": {
|