@ancha-labs/cli 0.4.53 → 0.4.55
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 +911 -917
- package/lib/assets/docs/cloud.md +4 -2
- package/lib/assets/harbor/companion.mjs +30 -11
- package/lib/worker.mjs +86 -20
- package/package.json +1 -1
package/lib/assets/docs/cloud.md
CHANGED
|
@@ -94,7 +94,7 @@ agent:
|
|
|
94
94
|
AGENT_TASK: '{"task": {{task_json}}}'
|
|
95
95
|
```
|
|
96
96
|
|
|
97
|
-
`{{task_json}}` encodes the task as a JSON string, including quotes and newlines. The CLI, `ancha agent upload --json` and the console’s
|
|
97
|
+
`{{task_json}}` encodes the task as a JSON string, including quotes and newlines. The CLI, `ancha agent upload --json` and the console’s upload result show the same explanation and mapping. Apply the mapping, then run `ancha agent upload` again.
|
|
98
98
|
|
|
99
99
|
## Run tests in the cloud
|
|
100
100
|
|
|
@@ -114,6 +114,8 @@ ancha run --on cloud
|
|
|
114
114
|
- `--agent`, `--seed`, `--strict`, `--allow-simulated`, `--min-pass-rate`, `--allow-unwrapped` and `--idempotency-key` mean what they mean on this computer. `--compare <baseline>` compares with a saved baseline: `ancha baseline save before --from <run id>`, fix the agent, then `--compare before`. A cloud run's keys come from the workspace, so `--pass-env` and `--inherit-env` belong to runs on this computer, and its results live in the workspace, so it takes no `--out` or `--upload`.
|
|
115
115
|
- With `--json` the run announces acceptance with `run_submitted` (`run_detached` with `--detach`), carrying `target: "cloud"` and adding `defaulted: true` when the saved login chose cloud. A followed run prints NDJSON events and ends with `run_finished`: `url` is the result, `summary` the verdict with the attempt and check counts, and `next` the commands to run next. The exit codes are `ancha run`'s: 0 when every check passes, 1 when a check failed, 3 when an attempt could not run or be graded, 4 for an endpoint coverage error with `--strict`, or a verdict using simulated tool answers with `--strict` or in CI, and 2 for a cancelled run.
|
|
116
116
|
|
|
117
|
+
In a cloud attempt, each provider base URL points at the attempt's model gateway; `ANCHA_MODEL_URLS` maps each provider host to its gateway URL, so compare hosts rather than whole URLs. With `OPENROUTER_API_KEY`, Ancha fills `ANTHROPIC_AUTH_TOKEN` and `OPENAI_API_KEY` when the agent routes those clients to OpenRouter and holds no key of its own.
|
|
118
|
+
|
|
117
119
|
## Follow a run from anywhere
|
|
118
120
|
|
|
119
121
|
A run keeps going when the command stops: Ctrl-C or a dropped connection ends only the following, and the command prints the `ancha wait` line to pick it up. `--detach` returns as soon as the run is accepted, with its id and link.
|
|
@@ -127,7 +129,7 @@ ancha runs show <run id> # the run and its attempts
|
|
|
127
129
|
|
|
128
130
|
## The first steps, done or not
|
|
129
131
|
|
|
130
|
-
`ancha status` prints the workspace's three steps
|
|
132
|
+
`ancha status` prints the workspace's three steps and the next command:
|
|
131
133
|
|
|
132
134
|
- **Agent uploaded**: `ancha agent upload` started this project's agent with a task, or a cloud run graded it.
|
|
133
135
|
- **Tests added**: the workspace holds a trace or a test made from one, or a cloud run ran this project's tests.
|
|
@@ -187002,10 +187002,13 @@ function notRoutedMessage(toolkit) {
|
|
|
187002
187002
|
var RouteRefusal = class extends Error {
|
|
187003
187003
|
reason;
|
|
187004
187004
|
toolkit;
|
|
187005
|
-
|
|
187006
|
-
|
|
187005
|
+
/** For SCHEMA: the field and what it held, as types (SPEC-104 F1). */
|
|
187006
|
+
detail;
|
|
187007
|
+
constructor(reason2, toolkit, detail3) {
|
|
187008
|
+
super(reason2 === "SCHEMA" && detail3 ? `The request does not match this endpoint's input schema: ${detail3}.` : reason2 === "NO_WORLD" && toolkit ? noWorldMessage(toolkit) : reason2 === "NOT_ROUTED" && toolkit ? notRoutedMessage(toolkit) : reason2 === "NETSUITE_TOOL" ? NETSUITE_FIX : "Configure this call to use the declared QuickBooks or NetSuite route.");
|
|
187007
187009
|
this.reason = reason2;
|
|
187008
187010
|
this.toolkit = toolkit;
|
|
187011
|
+
if (detail3) this.detail = detail3;
|
|
187009
187012
|
}
|
|
187010
187013
|
};
|
|
187011
187014
|
var activeComposioToolkits = (route15) => route15.activeToolkits ?? route15.toolkits ?? { quickbooks: "composio" };
|
|
@@ -187057,9 +187060,25 @@ var switchOf = (raw3, key5) => {
|
|
|
187057
187060
|
};
|
|
187058
187061
|
var connections2 = /* @__PURE__ */ new WeakMap();
|
|
187059
187062
|
var bytes2 = (value5) => Buffer.from(JSON.stringify(value5));
|
|
187060
|
-
function
|
|
187061
|
-
const
|
|
187062
|
-
|
|
187063
|
+
function schemaDetail(issues, at4) {
|
|
187064
|
+
const issue9 = issues[0];
|
|
187065
|
+
if (!issue9) return void 0;
|
|
187066
|
+
const path6 = [...at4 ? [at4] : [], ...issue9.path].reduce((text25, key5) => typeof key5 === "number" ? `${text25}[${key5}]` : text25 ? `${text25}.${String(key5)}` : String(key5), "");
|
|
187067
|
+
const said = issue9.code === "invalid_type" ? `expected ${issue9.expected}, received ${issue9.input === null ? "null" : Array.isArray(issue9.input) ? "array" : typeof issue9.input}` : issue9.code === "unrecognized_keys" ? `unknown field${issue9.keys.length === 1 ? "" : "s"} ${issue9.keys.slice(0, 3).join(", ")}` : issue9.code === "too_small" ? `expected at least ${String(issue9.minimum)}${issue9.origin === "array" ? ` item${issue9.minimum === 1 ? "" : "s"}` : ""}` : issue9.code === "invalid_value" ? "not an accepted value" : issue9.code.replace(/_/g, " ");
|
|
187068
|
+
return `${path6 ? `${path6}: ` : ""}${said}`.slice(0, 160);
|
|
187069
|
+
}
|
|
187070
|
+
function jsonText(value5) {
|
|
187071
|
+
if (typeof value5 !== "string") return value5;
|
|
187072
|
+
try {
|
|
187073
|
+
return JSON.parse(value5);
|
|
187074
|
+
} catch {
|
|
187075
|
+
return value5;
|
|
187076
|
+
}
|
|
187077
|
+
}
|
|
187078
|
+
function parsed3(schema2, value5, at4) {
|
|
187079
|
+
const result = schema2.safeParse(value5, { reportInput: true });
|
|
187080
|
+
if (result.success) return result.data;
|
|
187081
|
+
throw new RouteRefusal("SCHEMA", void 0, schemaDetail(result.error.issues, at4));
|
|
187063
187082
|
}
|
|
187064
187083
|
function jsonBody3(body7, contentType) {
|
|
187065
187084
|
if (typeof contentType !== "string" || !/^application\/json(?:\s*;|$)/i.test(contentType)) refuse("CONTENT_TYPE");
|
|
@@ -187076,7 +187095,7 @@ function toolArguments(route15, name5, value5 = {}, metaOnly = false) {
|
|
|
187076
187095
|
if (!meta5.has(name5) && (metaOnly || !quickbooks.test(name5))) refuse(name5.startsWith("COMPOSIO_") || metaOnly ? "META_TOOL" : "TOOL");
|
|
187077
187096
|
const { account: _account, ...args } = value5;
|
|
187078
187097
|
if (name5 === multi) {
|
|
187079
|
-
const items = parsed3(external_exports.array(external_exports.object({ tool_slug: external_exports.string(), arguments: record10.optional() }).passthrough()).min(1), args.tools);
|
|
187098
|
+
const items = parsed3(external_exports.array(external_exports.object({ tool_slug: external_exports.string(), arguments: external_exports.preprocess(jsonText, record10).optional() }).passthrough()).min(1), jsonText(args.tools), "tools");
|
|
187080
187099
|
for (const item2 of items) requireWorld(item2.tool_slug, route15);
|
|
187081
187100
|
args.tools = items.map(({ account: _account2, connected_account_id: _id, user_id: _user, ...item2 }) => {
|
|
187082
187101
|
if (item2.tool_slug.startsWith("NETSUITE_")) refuse("NETSUITE_TOOL");
|
|
@@ -187150,7 +187169,7 @@ function validateComposio(method2, target5, apiKey, body7, contentType, route15,
|
|
|
187150
187169
|
if (Array.isArray(json37)) refuse("MCP_BATCH");
|
|
187151
187170
|
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);
|
|
187152
187171
|
if (value5.method === "tools/call") {
|
|
187153
|
-
const params10 = parsed3(external_exports.strictObject({ name: external_exports.string(), arguments: record10.optional(), account: external_exports.unknown().optional(), _meta: record10.optional() }), value5.params);
|
|
187172
|
+
const params10 = parsed3(external_exports.strictObject({ name: external_exports.string(), arguments: record10.optional(), account: external_exports.unknown().optional(), _meta: record10.optional() }), value5.params, "params");
|
|
187154
187173
|
const call2 = toolArguments(route15, params10.name, params10.arguments);
|
|
187155
187174
|
if (!qb) refuse("SESSION_ENDPOINT");
|
|
187156
187175
|
const { account: _account, ...kept } = params10;
|
|
@@ -187309,9 +187328,9 @@ async function readComposioBody(req) {
|
|
|
187309
187328
|
}
|
|
187310
187329
|
return Buffer.concat(chunks);
|
|
187311
187330
|
}
|
|
187312
|
-
function refuseComposio(res, reason2, toolkit) {
|
|
187331
|
+
function refuseComposio(res, reason2, toolkit, detail3) {
|
|
187313
187332
|
res.writeHead(403, { "content-type": "application/json", connection: "close" });
|
|
187314
|
-
res.end(JSON.stringify({ error: { code: "COMPOSIO_ROUTE_REFUSED", reason: reason2, message: new RouteRefusal(reason2, toolkit).message } }));
|
|
187333
|
+
res.end(JSON.stringify({ error: { code: "COMPOSIO_ROUTE_REFUSED", reason: reason2, message: new RouteRefusal(reason2, toolkit, detail3).message } }));
|
|
187315
187334
|
}
|
|
187316
187335
|
var routeIds = /* @__PURE__ */ new WeakMap();
|
|
187317
187336
|
function nextRouteId(route15, kind) {
|
|
@@ -187549,8 +187568,8 @@ async function startIsolationGateway(options4) {
|
|
|
187549
187568
|
const reason2 = error64 instanceof RouteRefusal ? error64.reason : "JSON";
|
|
187550
187569
|
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");
|
|
187551
187570
|
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 });
|
|
187553
|
-
refuseComposio(res, reason2, toolkit);
|
|
187571
|
+
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, ...error64 instanceof RouteRefusal && error64.detail && { detail: error64.detail } });
|
|
187572
|
+
refuseComposio(res, reason2, toolkit, error64 instanceof RouteRefusal ? error64.detail : void 0);
|
|
187554
187573
|
return;
|
|
187555
187574
|
}
|
|
187556
187575
|
}
|
package/lib/worker.mjs
CHANGED
|
@@ -71084,9 +71084,25 @@ function requireWorld(name5, route15) {
|
|
|
71084
71084
|
if (!(route15.toolkits ?? { quickbooks: "composio" })[toolkit]) throw new RouteRefusal("NOT_ROUTED", toolkit);
|
|
71085
71085
|
if (!activeComposioToolkits(route15)[toolkit]) throw new RouteRefusal("NO_WORLD", toolkit);
|
|
71086
71086
|
}
|
|
71087
|
-
function
|
|
71088
|
-
const
|
|
71089
|
-
|
|
71087
|
+
function schemaDetail(issues, at4) {
|
|
71088
|
+
const issue9 = issues[0];
|
|
71089
|
+
if (!issue9) return void 0;
|
|
71090
|
+
const path8 = [...at4 ? [at4] : [], ...issue9.path].reduce((text26, key5) => typeof key5 === "number" ? `${text26}[${key5}]` : text26 ? `${text26}.${String(key5)}` : String(key5), "");
|
|
71091
|
+
const said = issue9.code === "invalid_type" ? `expected ${issue9.expected}, received ${issue9.input === null ? "null" : Array.isArray(issue9.input) ? "array" : typeof issue9.input}` : issue9.code === "unrecognized_keys" ? `unknown field${issue9.keys.length === 1 ? "" : "s"} ${issue9.keys.slice(0, 3).join(", ")}` : issue9.code === "too_small" ? `expected at least ${String(issue9.minimum)}${issue9.origin === "array" ? ` item${issue9.minimum === 1 ? "" : "s"}` : ""}` : issue9.code === "invalid_value" ? "not an accepted value" : issue9.code.replace(/_/g, " ");
|
|
71092
|
+
return `${path8 ? `${path8}: ` : ""}${said}`.slice(0, 160);
|
|
71093
|
+
}
|
|
71094
|
+
function jsonText(value5) {
|
|
71095
|
+
if (typeof value5 !== "string") return value5;
|
|
71096
|
+
try {
|
|
71097
|
+
return JSON.parse(value5);
|
|
71098
|
+
} catch {
|
|
71099
|
+
return value5;
|
|
71100
|
+
}
|
|
71101
|
+
}
|
|
71102
|
+
function parsed2(schema2, value5, at4) {
|
|
71103
|
+
const result = schema2.safeParse(value5, { reportInput: true });
|
|
71104
|
+
if (result.success) return result.data;
|
|
71105
|
+
throw new RouteRefusal("SCHEMA", void 0, schemaDetail(result.error.issues, at4));
|
|
71090
71106
|
}
|
|
71091
71107
|
function jsonBody(body7, contentType) {
|
|
71092
71108
|
if (typeof contentType !== "string" || !/^application\/json(?:\s*;|$)/i.test(contentType)) refuse("CONTENT_TYPE");
|
|
@@ -71103,7 +71119,7 @@ function toolArguments(route15, name5, value5 = {}, metaOnly = false) {
|
|
|
71103
71119
|
if (!meta3.has(name5) && (metaOnly || !quickbooks.test(name5))) refuse(name5.startsWith("COMPOSIO_") || metaOnly ? "META_TOOL" : "TOOL");
|
|
71104
71120
|
const { account: _account, ...args } = value5;
|
|
71105
71121
|
if (name5 === multi) {
|
|
71106
|
-
const items = parsed2(external_exports.array(external_exports.object({ tool_slug: external_exports.string(), arguments: record7.optional() }).passthrough()).min(1), args.tools);
|
|
71122
|
+
const items = parsed2(external_exports.array(external_exports.object({ tool_slug: external_exports.string(), arguments: external_exports.preprocess(jsonText, record7).optional() }).passthrough()).min(1), jsonText(args.tools), "tools");
|
|
71107
71123
|
for (const item2 of items) requireWorld(item2.tool_slug, route15);
|
|
71108
71124
|
args.tools = items.map(({ account: _account2, connected_account_id: _id, user_id: _user, ...item2 }) => {
|
|
71109
71125
|
if (item2.tool_slug.startsWith("NETSUITE_")) refuse("NETSUITE_TOOL");
|
|
@@ -71177,7 +71193,7 @@ function validateComposio(method2, target5, apiKey, body7, contentType, route15,
|
|
|
71177
71193
|
if (Array.isArray(json37)) refuse("MCP_BATCH");
|
|
71178
71194
|
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);
|
|
71179
71195
|
if (value5.method === "tools/call") {
|
|
71180
|
-
const params10 = parsed2(external_exports.strictObject({ name: external_exports.string(), arguments: record7.optional(), account: external_exports.unknown().optional(), _meta: record7.optional() }), value5.params);
|
|
71196
|
+
const params10 = parsed2(external_exports.strictObject({ name: external_exports.string(), arguments: record7.optional(), account: external_exports.unknown().optional(), _meta: record7.optional() }), value5.params, "params");
|
|
71181
71197
|
const call2 = toolArguments(route15, params10.name, params10.arguments);
|
|
71182
71198
|
if (!qb) refuse("SESSION_ENDPOINT");
|
|
71183
71199
|
const { account: _account, ...kept } = params10;
|
|
@@ -71336,9 +71352,9 @@ async function readComposioBody(req) {
|
|
|
71336
71352
|
}
|
|
71337
71353
|
return Buffer.concat(chunks);
|
|
71338
71354
|
}
|
|
71339
|
-
function refuseComposio(res, reason2, toolkit) {
|
|
71355
|
+
function refuseComposio(res, reason2, toolkit, detail3) {
|
|
71340
71356
|
res.writeHead(403, { "content-type": "application/json", connection: "close" });
|
|
71341
|
-
res.end(JSON.stringify({ error: { code: "COMPOSIO_ROUTE_REFUSED", reason: reason2, message: new RouteRefusal(reason2, toolkit).message } }));
|
|
71357
|
+
res.end(JSON.stringify({ error: { code: "COMPOSIO_ROUTE_REFUSED", reason: reason2, message: new RouteRefusal(reason2, toolkit, detail3).message } }));
|
|
71342
71358
|
}
|
|
71343
71359
|
function nextRouteId(route15, kind) {
|
|
71344
71360
|
let ids3 = routeIds.get(route15);
|
|
@@ -71437,10 +71453,13 @@ var init_composio = __esm({
|
|
|
71437
71453
|
RouteRefusal = class extends Error {
|
|
71438
71454
|
reason;
|
|
71439
71455
|
toolkit;
|
|
71440
|
-
|
|
71441
|
-
|
|
71456
|
+
/** For SCHEMA: the field and what it held, as types (SPEC-104 F1). */
|
|
71457
|
+
detail;
|
|
71458
|
+
constructor(reason2, toolkit, detail3) {
|
|
71459
|
+
super(reason2 === "SCHEMA" && detail3 ? `The request does not match this endpoint's input schema: ${detail3}.` : reason2 === "NO_WORLD" && toolkit ? noWorldMessage(toolkit) : reason2 === "NOT_ROUTED" && toolkit ? notRoutedMessage(toolkit) : reason2 === "NETSUITE_TOOL" ? NETSUITE_FIX : "Configure this call to use the declared QuickBooks or NetSuite route.");
|
|
71442
71460
|
this.reason = reason2;
|
|
71443
71461
|
this.toolkit = toolkit;
|
|
71462
|
+
if (detail3) this.detail = detail3;
|
|
71444
71463
|
}
|
|
71445
71464
|
};
|
|
71446
71465
|
activeComposioToolkits = (route15) => route15.activeToolkits ?? route15.toolkits ?? { quickbooks: "composio" };
|
|
@@ -71497,7 +71516,14 @@ import { createServer, request } from "node:http";
|
|
|
71497
71516
|
import { request as secureRequest } from "node:https";
|
|
71498
71517
|
import { isIP } from "node:net";
|
|
71499
71518
|
import { brotliDecompressSync, gunzipSync, inflateSync } from "node:zlib";
|
|
71500
|
-
function modelFailure(status5) {
|
|
71519
|
+
function modelFailure(status5, message8) {
|
|
71520
|
+
if (status5 === 402 && /in-flight/i.test(message8 ?? "")) return {
|
|
71521
|
+
code: "MODEL_CREDITS_EXHAUSTED",
|
|
71522
|
+
kind: "fix",
|
|
71523
|
+
outcome: "The model key's credits do not cover the requests running at once",
|
|
71524
|
+
did: "says the model key's credits do not cover the requests running at once",
|
|
71525
|
+
fix: "Add credits in the model provider account, or run fewer attempts at once (ancha run --concurrency 1, or parallel: 1 in ancha.yaml)."
|
|
71526
|
+
};
|
|
71501
71527
|
return status5 === 429 ? { code: "MODEL_RATE_LIMITED", kind: "retry", outcome: "The model provider rate-limited the key", did: "rate-limited the agent's model key", fix: "Wait a little, then run the same command again." } : status5 === 402 ? { code: "MODEL_CREDITS_EXHAUSTED", kind: "fix", outcome: "The model key is out of credits", did: "says the agent's model key is out of credits", fix: "Add credits in the model provider account, then run again." } : { code: "MODEL_KEY_REFUSED", kind: "fix", outcome: "The model key was refused", did: "refused the agent's model key", fix: void 0 };
|
|
71502
71528
|
}
|
|
71503
71529
|
function refusalMessage(body7, encoding) {
|
|
@@ -71635,8 +71661,8 @@ async function startIsolationGateway(options5) {
|
|
|
71635
71661
|
const reason2 = error64 instanceof RouteRefusal ? error64.reason : "JSON";
|
|
71636
71662
|
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");
|
|
71637
71663
|
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 });
|
|
71639
|
-
refuseComposio(res, reason2, toolkit);
|
|
71664
|
+
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, ...error64 instanceof RouteRefusal && error64.detail && { detail: error64.detail } });
|
|
71665
|
+
refuseComposio(res, reason2, toolkit, error64 instanceof RouteRefusal ? error64.detail : void 0);
|
|
71640
71666
|
return;
|
|
71641
71667
|
}
|
|
71642
71668
|
}
|
|
@@ -72472,7 +72498,8 @@ async function bounded(response6, cap) {
|
|
|
72472
72498
|
}
|
|
72473
72499
|
return Buffer.concat(chunks);
|
|
72474
72500
|
}
|
|
72475
|
-
function refusedDetail(reason2 = "REFUSED", toolkit) {
|
|
72501
|
+
function refusedDetail(reason2 = "REFUSED", toolkit, detail3) {
|
|
72502
|
+
if (reason2 === "SCHEMA" && detail3) return `a Composio call was refused (SCHEMA: ${detail3}): send the fields its input schema names; the route supplies the world connection.`;
|
|
72476
72503
|
const fix = REFUSAL_FIX[reason2] ?? "use the declared QuickBooks route";
|
|
72477
72504
|
return `a Composio call was refused (${reason2}): ${typeof fix === "function" ? fix(toolkit) : `${fix}.`}`;
|
|
72478
72505
|
}
|
|
@@ -72670,7 +72697,7 @@ async function startIngressClient(options5) {
|
|
|
72670
72697
|
if (reached) counts2[toolkit].reached++;
|
|
72671
72698
|
}
|
|
72672
72699
|
if (event3.op === "refused") counts2[toolkit].refused++;
|
|
72673
|
-
record15({ ...event3, toolkit, relayHash: hash2(id15) }, event3.status, event3.op === "refused" ? issue9("ROUTE_REFUSED", refusedDetail(event3.reason, toolkit), toolkit, event3.reason === "NO_WORLD" ? "agent" : "harness") : event3.op === "execute" && !reached && event3.reason === "ARGUMENTS" ? issue9("ROUTE_ARGUMENTS", "The agent's NETSUITE_RUN_SUITEQL_QUERY arguments were invalid; it got Composio's failure response.", toolkit, "agent") : event3.op === "execute" && !reached && event3.status === 401 && toolkit === "quickbooks" && (event3.via ?? "direct") === "direct" ? issue9("ROUTE_KEY_REJECTED", KEY_REJECTED, toolkit) : event3.op === "execute" && !reached ? issue9("ROUTE_NOT_REACHED", toolkit === "netsuite" ? "The SuiteQL call did not reach the NetSuite world: check q, limit and offset, then run again." : unreachedDetail(event3.status), toolkit) : event3.op === "catalog" && event3.via !== "mcp" && event3.status === 401 ? issue9("ROUTE_KEY_REJECTED", KEY_REJECTED, toolkit) : void 0);
|
|
72700
|
+
record15({ ...event3, toolkit, relayHash: hash2(id15) }, event3.status, event3.op === "refused" ? issue9("ROUTE_REFUSED", refusedDetail(event3.reason, toolkit, event3.detail), toolkit, event3.reason === "NO_WORLD" ? "agent" : "harness") : event3.op === "execute" && !reached && event3.reason === "ARGUMENTS" ? issue9("ROUTE_ARGUMENTS", "The agent's NETSUITE_RUN_SUITEQL_QUERY arguments were invalid; it got Composio's failure response.", toolkit, "agent") : event3.op === "execute" && !reached && event3.status === 401 && toolkit === "quickbooks" && (event3.via ?? "direct") === "direct" ? issue9("ROUTE_KEY_REJECTED", KEY_REJECTED, toolkit) : event3.op === "execute" && !reached ? issue9("ROUTE_NOT_REACHED", toolkit === "netsuite" ? "The SuiteQL call did not reach the NetSuite world: check q, limit and offset, then run again." : unreachedDetail(event3.status), toolkit) : event3.op === "catalog" && event3.via !== "mcp" && event3.status === 401 ? issue9("ROUTE_KEY_REJECTED", KEY_REJECTED, toolkit) : void 0);
|
|
72674
72701
|
},
|
|
72675
72702
|
summary: () => {
|
|
72676
72703
|
const result = {};
|
|
@@ -73543,6 +73570,27 @@ var init_agent_env = __esm({
|
|
|
73543
73570
|
});
|
|
73544
73571
|
|
|
73545
73572
|
// backend/src/agent-fix.ts
|
|
73573
|
+
function modelBaseUrlFix(host) {
|
|
73574
|
+
const variable = host === "openrouter.ai" ? "OPENROUTER_BASE_URL" : host === "api.openai.com" ? "OPENAI_BASE_URL" : host === "api.anthropic.com" ? "ANTHROPIC_BASE_URL" : void 0;
|
|
73575
|
+
const prefix2 = "in Ancha a model provider is reached through its base URL variable: ";
|
|
73576
|
+
if (!variable && host) return `${prefix2}build the client from its ${host} entry in ANCHA_MODEL_URLS`;
|
|
73577
|
+
if (!variable) return `${prefix2}build the client from OPENROUTER_BASE_URL, OPENAI_BASE_URL or ANTHROPIC_BASE_URL for that provider, or its entry in ANCHA_MODEL_URLS`;
|
|
73578
|
+
return `${prefix2}build the client from ${variable} (${host === "api.anthropic.com" ? "Anthropic SDK" : "OpenAI SDK"}: baseURL: process.env.${variable}${host === "openrouter.ai" ? "; @openrouter/ai-sdk-provider: createOpenRouter({ baseURL: process.env.OPENROUTER_BASE_URL })" : ""})`;
|
|
73579
|
+
}
|
|
73580
|
+
function modelUnreachable(log2, requests2) {
|
|
73581
|
+
if (requests2 === void 0 || Object.values(requests2).some((count11) => count11.requests > 0)) return void 0;
|
|
73582
|
+
const sdk = SDK_CONNECTION.test(log2);
|
|
73583
|
+
if (!sdk && !NET_CONNECTION.test(log2)) return void 0;
|
|
73584
|
+
const named4 = (host2) => ({ host: host2, message: `It could not reach ${host2}: its model client calls https://${host2} directly.`, fix: modelBaseUrlFix(host2) });
|
|
73585
|
+
const failed2 = [...log2.matchAll(/getaddrinfo\s+(?:ENOTFOUND|EAI_AGAIN)\s+([a-z0-9.-]+)|request to https?:\/\/([a-z0-9.-]+)/gi)].map((match3) => (match3[1] ?? match3[2]).toLowerCase());
|
|
73586
|
+
if (failed2.length > 0) {
|
|
73587
|
+
const host2 = failed2.find((name5) => CLOUD_MODEL_HOSTS.includes(name5));
|
|
73588
|
+
return host2 ? named4(host2) : void 0;
|
|
73589
|
+
}
|
|
73590
|
+
if (!sdk) return void 0;
|
|
73591
|
+
const host = [...log2.matchAll(/https?:\/\/([a-z0-9.-]+)/gi)].map((match3) => match3[1].toLowerCase()).find((name5) => CLOUD_MODEL_HOSTS.includes(name5));
|
|
73592
|
+
return host ? named4(host) : { message: "Its model client could not connect, and it made no model request through Ancha.", fix: modelBaseUrlFix() };
|
|
73593
|
+
}
|
|
73546
73594
|
function givenByTwins(name5) {
|
|
73547
73595
|
twinVariables ??= new Set(Object.keys(toolConnectionEnvironment(Object.fromEntries(SUPPORTED_TWINS.map((twin) => [twin, ANY_SERVICE])))));
|
|
73548
73596
|
return twinVariables.has(name5);
|
|
@@ -73610,11 +73658,15 @@ function missingFix(text26, context3) {
|
|
|
73610
73658
|
return void 0;
|
|
73611
73659
|
}
|
|
73612
73660
|
function likelyFix(logTail3, context3 = {}) {
|
|
73661
|
+
const unreachable = modelUnreachable(logTail3.join("\n"), context3.modelRequests);
|
|
73662
|
+
if (unreachable) return unreachable.fix;
|
|
73613
73663
|
const task2 = taskFix(logTail3.join("\n"), context3.command);
|
|
73614
73664
|
if (task2 !== void 0 || context3.withheld !== void 0) return task2 ?? context3.withheld;
|
|
73615
73665
|
if (logTail3.some((line2) => /^Not logged in · Please run \/login\b/.test(line2.trim()))) {
|
|
73616
|
-
return
|
|
73666
|
+
return context3.target === "cloud" ? "Claude Code had no key (its /login stays on your computer): through OpenRouter, set ANTHROPIC_BASE_URL: https://openrouter.ai/api under agent.env and run ancha secrets set OPENROUTER_API_KEY in the project (Claude Code gets it as ANTHROPIC_AUTH_TOKEN); with an Anthropic key, run ancha secrets set ANTHROPIC_API_KEY in the project" : '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, set ANTHROPIC_API_KEY in this shell and list it under agent.pass_env in ancha.yaml';
|
|
73617
73667
|
}
|
|
73668
|
+
const model = logTail3.map((line2) => MODEL_ID_REFUSED.map((pattern) => pattern.exec(line2)?.[1]).find(Boolean)).find(Boolean);
|
|
73669
|
+
if (model !== void 0) return `its model ${model} is not a model id the provider serves: use an id from the provider's model list (openrouter.ai/models for OpenRouter) where the agent sets its model: agent.env, agent.command or its code`;
|
|
73618
73670
|
const errors2 = logTail3.filter((line2) => /error|exception|fatal|panic|missing|required|usage|not set|not found|cannot|can't/i.test(line2));
|
|
73619
73671
|
for (const lines of [errors2, logTail3]) {
|
|
73620
73672
|
const fix = lines.length === 0 ? void 0 : keyFix(lines, context3) ?? missingFix(lines.join("\n"), context3);
|
|
@@ -73622,18 +73674,22 @@ function likelyFix(logTail3, context3 = {}) {
|
|
|
73622
73674
|
}
|
|
73623
73675
|
return void 0;
|
|
73624
73676
|
}
|
|
73625
|
-
var TASK_WORD, TASK_NAME, TASK_FLAG, CREDENTIAL, MISSING, twinVariables, escape2;
|
|
73677
|
+
var SDK_CONNECTION, NET_CONNECTION, TASK_WORD, TASK_NAME, TASK_FLAG, CREDENTIAL, MISSING, twinVariables, escape2, MODEL_ID_REFUSED;
|
|
73626
73678
|
var init_agent_fix = __esm({
|
|
73627
73679
|
"backend/src/agent-fix.ts"() {
|
|
73628
73680
|
"use strict";
|
|
73629
73681
|
init_src();
|
|
73630
73682
|
init_agent_env();
|
|
73683
|
+
init_jobs_contract();
|
|
73684
|
+
SDK_CONNECTION = /APIConnectionError|Connection error\.|AI_RetryError|AI_APICallError|Cannot connect to API/;
|
|
73685
|
+
NET_CONNECTION = /getaddrinfo\s+(?:ENOTFOUND|EAI_AGAIN)|request to https?:\/\/\S+\s+failed|Temporary failure in name resolution|httpx\.ConnectError|fetch failed/i;
|
|
73631
73686
|
TASK_WORD = "(?:TASKS?|PROMPTS?|QUERY|QUERIES|INSTRUCTIONS?|MESSAGES?|REQUESTS?|INPUTS?)";
|
|
73632
73687
|
TASK_NAME = new RegExp(`(?<![A-Za-z0-9_])((?:[A-Z][A-Z0-9]*_)*${TASK_WORD}(?:_[A-Z0-9]+)*)(?![A-Za-z0-9_])`, "g");
|
|
73633
73688
|
TASK_FLAG = /(?<![\w-])(--(?:task|prompt|message|input|query|instructions?|request)(?:-file)?)(?![\w-])/g;
|
|
73634
73689
|
CREDENTIAL = /(?<![A-Za-z0-9_])([A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*_(?:KEY|TOKEN|SECRET|PASSWORD))(?![A-Za-z0-9_])/g;
|
|
73635
73690
|
MISSING = /missing|not set|unset|undefined|required|must be set|no .*(?:key|token)|KeyError|not found|empty|expected/i;
|
|
73636
73691
|
escape2 = (text26) => text26.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
73692
|
+
MODEL_ID_REFUSED = [/([\w.:/@-]+)['"`]? is not a valid model ID/i, /The model [`'"]?([\w.:/@-]+)[`'"]? does not exist/i, /not_found_error\W+(?:message\W+)?model: ([\w.:/@-]+)/i];
|
|
73637
73693
|
}
|
|
73638
73694
|
});
|
|
73639
73695
|
|
|
@@ -224049,6 +224105,11 @@ function containedEnvironment(input5) {
|
|
|
224049
224105
|
if (openRouter && !values3.OPENAI_API_KEY && (values3.OPENROUTER_API_KEY || !openAi)) values3.OPENAI_BASE_URL ??= openRouter + "/api/v1";
|
|
224050
224106
|
if (openAi) values3.OPENAI_BASE_URL ??= openAi + "/v1";
|
|
224051
224107
|
if (mapped.modelUrls["api.anthropic.com"]) values3.ANTHROPIC_BASE_URL ??= mapped.modelUrls["api.anthropic.com"];
|
|
224108
|
+
if (openRouter && values3.OPENROUTER_API_KEY) {
|
|
224109
|
+
const routed = (value5) => value5 === openRouter || value5?.startsWith(openRouter + "/") || value5?.startsWith(openRouter + "?") || value5?.startsWith(openRouter + "#");
|
|
224110
|
+
if (routed(values3.ANTHROPIC_BASE_URL) && !values3.ANTHROPIC_AUTH_TOKEN && !values3.ANTHROPIC_API_KEY) values3.ANTHROPIC_AUTH_TOKEN = values3.OPENROUTER_API_KEY;
|
|
224111
|
+
if (routed(values3.OPENAI_BASE_URL) && !values3.OPENAI_API_KEY) values3.OPENAI_API_KEY = values3.OPENROUTER_API_KEY;
|
|
224112
|
+
}
|
|
224052
224113
|
for (const [base6, api4] of [["OPENROUTER_BASE_URL", "OPENROUTER_API_BASE"], ["OPENAI_BASE_URL", "OPENAI_API_BASE"], ["ANTHROPIC_BASE_URL", "ANTHROPIC_API_BASE"]]) {
|
|
224053
224114
|
if (values3[base6]) values3[api4] ??= values3[base6];
|
|
224054
224115
|
}
|
|
@@ -225972,7 +226033,7 @@ var init_agent_outcome = __esm({
|
|
|
225972
226033
|
// backend/src/runner/trial.ts
|
|
225973
226034
|
import { setTimeout as sleep9 } from "node:timers/promises";
|
|
225974
226035
|
import { closeSync as closeSync6, openSync as openSync6, writeSync as writeSync6 } from "node:fs";
|
|
225975
|
-
import { mkdir as mkdir11 } from "node:fs/promises";
|
|
226036
|
+
import { mkdir as mkdir11, readFile as readFile9 } from "node:fs/promises";
|
|
225976
226037
|
import { join as join21 } from "node:path";
|
|
225977
226038
|
function answersFrom(agent, source) {
|
|
225978
226039
|
const mode = agent.answer ?? "auto";
|
|
@@ -225989,7 +226050,7 @@ async function recordAnswer(backend, envId, sessionId, output2, source, printed)
|
|
|
225989
226050
|
}
|
|
225990
226051
|
}
|
|
225991
226052
|
function modelKeyIssue(refusal, given2) {
|
|
225992
|
-
const failure5 = modelFailure(refusal.status);
|
|
226053
|
+
const failure5 = modelFailure(refusal.status, refusal.message);
|
|
225993
226054
|
return {
|
|
225994
226055
|
kind: "model",
|
|
225995
226056
|
owner: "harness",
|
|
@@ -226139,6 +226200,10 @@ async function runTrialInner(spec) {
|
|
|
226139
226200
|
const capture3 = await captureTrialAfterFailure(failure5, backend, env.id, session2.id, dir, scene2, { ...spec.judge, ...signal !== void 0 && { signal } }, void 0, spec.onCaptured);
|
|
226140
226201
|
const { checks: checks2, trace: trace2, simMs } = capture3, harnessIssues = [...capture3.harnessIssues, ...playOutIssues];
|
|
226141
226202
|
if (output2?.modelRefusal !== void 0) harnessIssues.push(modelKeyIssue(output2.modelRefusal, Object.keys(agent.env ?? {})));
|
|
226203
|
+
if ((exit === "spawn_failed" || exit === "exited" && exitCode !== 0) && output2?.model && !output2.modelReplies?.length) {
|
|
226204
|
+
const unreachable = modelUnreachable(await readFile9(join21(dir, "agent.log"), "utf8").catch(() => ""), output2.model.requests);
|
|
226205
|
+
if (unreachable) harnessIssues.push({ kind: "model", owner: "harness", service: unreachable.host ?? "model", code: "MODEL_UNREACHABLE", message: `${unreachable.message} ${unreachable.fix.charAt(0).toUpperCase()}${unreachable.fix.slice(1)}.` });
|
|
226206
|
+
}
|
|
226142
226207
|
if (failure5 !== void 0) throw failure5.error;
|
|
226143
226208
|
signal?.throwIfAborted();
|
|
226144
226209
|
return {
|
|
@@ -226185,6 +226250,7 @@ var init_trial = __esm({
|
|
|
226185
226250
|
init_budget();
|
|
226186
226251
|
init_agent_output();
|
|
226187
226252
|
init_agent_outcome();
|
|
226253
|
+
init_agent_fix();
|
|
226188
226254
|
init_agent_env();
|
|
226189
226255
|
EXIT_COMMAND_NOT_FOUND2 = 127;
|
|
226190
226256
|
unknownRoute18 = (error64) => error64 instanceof AnchaError && error64.code === "USAGE" && error64.message.startsWith("no such route");
|
|
@@ -226193,7 +226259,7 @@ var init_trial = __esm({
|
|
|
226193
226259
|
|
|
226194
226260
|
// backend/src/runner/run.ts
|
|
226195
226261
|
import { createHash as createHash61, randomInt } from "node:crypto";
|
|
226196
|
-
import { access as access4, mkdir as mkdir12, readFile as
|
|
226262
|
+
import { access as access4, mkdir as mkdir12, readFile as readFile10, writeFile as writeFile11 } from "node:fs/promises";
|
|
226197
226263
|
import { dirname as dirname7, join as join22, relative as relative5, resolve as resolve12 } from "node:path";
|
|
226198
226264
|
function interrupted(dir) {
|
|
226199
226265
|
return new AnchaError("USAGE", "run interrupted", dir === void 0 ? {} : { hint: `partial results in ${dir}` });
|
|
@@ -226370,7 +226436,7 @@ async function executeRun(opts) {
|
|
|
226370
226436
|
for (const [index, item2] of cases.entries()) {
|
|
226371
226437
|
const source = await recordsFor(pathOf6(item2), opts.root);
|
|
226372
226438
|
if (source === void 0) continue;
|
|
226373
|
-
const text26 = await
|
|
226439
|
+
const text26 = await readFile10(source), copy = join22(dir, "records", `${index}.jsonl`);
|
|
226374
226440
|
await mkdir12(dirname7(copy), { recursive: true });
|
|
226375
226441
|
await writeFile11(copy, text26, { flag: "wx", mode: 384 });
|
|
226376
226442
|
kept.set(item2.id, copy);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ancha-labs/cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.55",
|
|
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": {
|