@ancha-labs/cli 0.4.44 → 0.4.46
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 +238 -178
- package/lib/assets/harbor/companion.mjs +123 -113
- package/lib/worker.mjs +173 -127
- package/package.json +1 -1
package/lib/worker.mjs
CHANGED
|
@@ -71724,135 +71724,145 @@ async function startIsolationGateway(options5) {
|
|
|
71724
71724
|
headers.host = modelHost ?? new URL(exposedOrigin ?? upstream.origin).host;
|
|
71725
71725
|
delete headers["x-ancha-client-origin"];
|
|
71726
71726
|
if (transform3) headers["accept-encoding"] = "identity";
|
|
71727
|
-
|
|
71728
|
-
|
|
71729
|
-
|
|
71730
|
-
|
|
71731
|
-
|
|
71732
|
-
|
|
71733
|
-
|
|
71734
|
-
|
|
71735
|
-
|
|
71736
|
-
|
|
71737
|
-
|
|
71738
|
-
|
|
71739
|
-
|
|
71727
|
+
let target5;
|
|
71728
|
+
try {
|
|
71729
|
+
target5 = (modelHost ? secureRequest : request)({
|
|
71730
|
+
hostname: modelAddress?.address ?? upstream.hostname.replace(/^\[|\]$/g, ""),
|
|
71731
|
+
port: modelHost ? 443 : upstream.port || 80,
|
|
71732
|
+
path: targetPath,
|
|
71733
|
+
method: req.method,
|
|
71734
|
+
headers,
|
|
71735
|
+
agent: false,
|
|
71736
|
+
...modelHost && { servername: modelHost, rejectUnauthorized: true, family: modelAddress.family }
|
|
71737
|
+
}, (reply6) => {
|
|
71738
|
+
if (!reply6.statusCode || reply6.statusCode < 100) {
|
|
71739
|
+
reply6.destroy();
|
|
71740
|
+
reject2(res, 502, "Tool connection failed.");
|
|
71741
|
+
return;
|
|
71740
71742
|
}
|
|
71741
|
-
|
|
71742
|
-
|
|
71743
|
-
|
|
71744
|
-
|
|
71745
|
-
|
|
71743
|
+
const observe2 = (host, status5, message8) => {
|
|
71744
|
+
try {
|
|
71745
|
+
options5.onModelReply?.(host, status5, message8);
|
|
71746
|
+
} catch {
|
|
71747
|
+
}
|
|
71748
|
+
};
|
|
71749
|
+
if (!toolCall && modelHost !== void 0 && reply6.statusCode !== void 0) {
|
|
71750
|
+
const host = modelHost, status5 = reply6.statusCode;
|
|
71751
|
+
if (!MODEL_REFUSALS.has(status5)) observe2(host, status5);
|
|
71752
|
+
else {
|
|
71753
|
+
const chunks2 = [];
|
|
71754
|
+
let size3 = 0, told = false;
|
|
71755
|
+
const tell = () => {
|
|
71756
|
+
if (told) return;
|
|
71757
|
+
told = true;
|
|
71758
|
+
observe2(host, status5, size3 <= REFUSAL_BYTES ? refusalMessage(Buffer.concat(chunks2), reply6.headers["content-encoding"]?.toLowerCase()) : void 0);
|
|
71759
|
+
};
|
|
71760
|
+
reply6.on("data", (chunk) => {
|
|
71761
|
+
size3 += chunk.length;
|
|
71762
|
+
if (size3 <= REFUSAL_BYTES) chunks2.push(chunk);
|
|
71763
|
+
});
|
|
71764
|
+
reply6.once("end", tell);
|
|
71765
|
+
reply6.once("close", tell);
|
|
71766
|
+
}
|
|
71767
|
+
}
|
|
71768
|
+
if (reply6.statusCode && reply6.statusCode >= 300 && reply6.statusCode < 400) {
|
|
71769
|
+
reply6.destroy();
|
|
71770
|
+
reject2(res, 502, "Tool redirects are not allowed through the sandbox gateway.");
|
|
71771
|
+
return;
|
|
71772
|
+
}
|
|
71773
|
+
const responseHeaders = toolCall ? { "content-type": reply6.headers["content-type"] ?? "application/json" } : cleanHeaders(reply6.headers);
|
|
71774
|
+
if (toolCall?.via === "mcp" && typeof reply6.headers["mcp-session-id"] === "string" && /^[\x21-\x7e]{1,256}$/.test(reply6.headers["mcp-session-id"])) responseHeaders["mcp-session-id"] = reply6.headers["mcp-session-id"];
|
|
71775
|
+
const successful2 = reply6.statusCode !== void 0 && reply6.statusCode >= 200 && reply6.statusCode < 300;
|
|
71776
|
+
if (toolCall?.response === "session-delete" && successful2) route15.sessions.delete(toolCall.sessionId);
|
|
71777
|
+
if (toolCall && successful2 && (toolCall.response === "session-create" || toolCall.response === "session-get")) {
|
|
71746
71778
|
const chunks2 = [];
|
|
71747
|
-
let size3 = 0,
|
|
71748
|
-
const
|
|
71749
|
-
if (
|
|
71750
|
-
|
|
71751
|
-
|
|
71779
|
+
let size3 = 0, failed2 = false;
|
|
71780
|
+
const fail6 = () => {
|
|
71781
|
+
if (failed2) return;
|
|
71782
|
+
failed2 = true;
|
|
71783
|
+
reply6.destroy();
|
|
71784
|
+
if (!res.headersSent) reject2(res, 502, "Composio returned an invalid session response.");
|
|
71785
|
+
else res.destroy();
|
|
71752
71786
|
};
|
|
71753
71787
|
reply6.on("data", (chunk) => {
|
|
71754
71788
|
size3 += chunk.length;
|
|
71755
|
-
if (size3
|
|
71789
|
+
if (size3 > 1024 * 1024) fail6();
|
|
71790
|
+
else if (!failed2) chunks2.push(Buffer.from(chunk));
|
|
71791
|
+
});
|
|
71792
|
+
reply6.once("error", fail6);
|
|
71793
|
+
reply6.once("aborted", fail6);
|
|
71794
|
+
reply6.once("end", () => {
|
|
71795
|
+
if (failed2) return;
|
|
71796
|
+
try {
|
|
71797
|
+
const value5 = rewriteComposioSession(JSON.parse(Buffer.concat(chunks2).toString("utf8")), toolCall, route15, exposedOrigin);
|
|
71798
|
+
const body7 = JSON.stringify(value5);
|
|
71799
|
+
res.writeHead(reply6.statusCode, { "content-type": "application/json", "content-length": Buffer.byteLength(body7) });
|
|
71800
|
+
res.end(body7);
|
|
71801
|
+
} catch {
|
|
71802
|
+
fail6();
|
|
71803
|
+
}
|
|
71756
71804
|
});
|
|
71757
|
-
|
|
71758
|
-
reply6.once("close", tell);
|
|
71805
|
+
return;
|
|
71759
71806
|
}
|
|
71760
|
-
|
|
71761
|
-
|
|
71762
|
-
|
|
71763
|
-
|
|
71764
|
-
|
|
71765
|
-
|
|
71766
|
-
|
|
71767
|
-
|
|
71768
|
-
|
|
71769
|
-
|
|
71770
|
-
|
|
71771
|
-
|
|
71772
|
-
|
|
71773
|
-
|
|
71774
|
-
|
|
71775
|
-
|
|
71776
|
-
|
|
71777
|
-
|
|
71778
|
-
else res.destroy();
|
|
71779
|
-
};
|
|
71807
|
+
if (toolCall) {
|
|
71808
|
+
let received = 0;
|
|
71809
|
+
reply6.on("data", (chunk) => {
|
|
71810
|
+
received += chunk.length;
|
|
71811
|
+
if (received > BODY_LIMIT) {
|
|
71812
|
+
reply6.destroy();
|
|
71813
|
+
res.destroy();
|
|
71814
|
+
}
|
|
71815
|
+
});
|
|
71816
|
+
}
|
|
71817
|
+
if (!transform3) {
|
|
71818
|
+
res.writeHead(reply6.statusCode ?? 502, responseHeaders);
|
|
71819
|
+
reply6.pipe(res);
|
|
71820
|
+
reply6.on("error", () => res.destroy());
|
|
71821
|
+
return;
|
|
71822
|
+
}
|
|
71823
|
+
const chunks = [];
|
|
71824
|
+
let size2 = 0;
|
|
71780
71825
|
reply6.on("data", (chunk) => {
|
|
71781
|
-
|
|
71782
|
-
if (
|
|
71783
|
-
|
|
71784
|
-
|
|
71785
|
-
|
|
71786
|
-
|
|
71787
|
-
reply6.
|
|
71788
|
-
if (
|
|
71826
|
+
size2 += chunk.length;
|
|
71827
|
+
if (size2 > BODY_LIMIT) {
|
|
71828
|
+
reply6.destroy();
|
|
71829
|
+
reject2(res, 502, "Tool response exceeded the sandbox gateway limit.");
|
|
71830
|
+
} else chunks.push(chunk);
|
|
71831
|
+
});
|
|
71832
|
+
reply6.on("error", () => {
|
|
71833
|
+
if (!res.headersSent) reject2(res, 502, "Tool connection failed.");
|
|
71834
|
+
else res.destroy();
|
|
71835
|
+
});
|
|
71836
|
+
reply6.on("end", () => {
|
|
71837
|
+
if (size2 > BODY_LIMIT) return;
|
|
71789
71838
|
try {
|
|
71790
|
-
|
|
71839
|
+
let value5 = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
71840
|
+
if (transform3 === "context" && reply6.statusCode === 200) {
|
|
71841
|
+
const connection4 = mapped(exposedOrigin ?? "");
|
|
71842
|
+
value5 = { ...value5, env: connection4.env, session: connection4.session };
|
|
71843
|
+
}
|
|
71844
|
+
if (transform3 === "socket" && reply6.statusCode === 200 && value5?.ok === true) {
|
|
71845
|
+
const grant = new URL(value5.url);
|
|
71846
|
+
const expected = loopbackOrigin(session2.eventsUrl);
|
|
71847
|
+
if (grant.protocol !== "ws:" || grant.hostname !== expected.hostname || grant.port !== expected.port || grant.search || grant.hash || grant.username || grant.password || !/^\/_ancha\/socket\/[a-f0-9]{64}$/.test(grant.pathname)) throw new Error("Invalid socket grant");
|
|
71848
|
+
for (const [path9, old] of socketGrants) if (old.expires <= Date.now()) socketGrants.delete(path9);
|
|
71849
|
+
if (socketGrants.size >= 128) throw new Error("Too many socket grants");
|
|
71850
|
+
socketGrants.set(grant.pathname, { url: grant, expires: Date.now() + 3e4 });
|
|
71851
|
+
value5 = { ...value5, url: (exposedOrigin ?? "").replace(/^http:/, "ws:") + grant.pathname };
|
|
71852
|
+
}
|
|
71791
71853
|
const body7 = JSON.stringify(value5);
|
|
71792
|
-
|
|
71854
|
+
delete responseHeaders["content-encoding"];
|
|
71855
|
+
delete responseHeaders["content-length"];
|
|
71856
|
+
res.writeHead(reply6.statusCode ?? 502, { ...responseHeaders, "content-length": Buffer.byteLength(body7) });
|
|
71793
71857
|
res.end(body7);
|
|
71794
71858
|
} catch {
|
|
71795
|
-
|
|
71859
|
+
reject2(res, 502, "Tool context was not a valid bounded response.");
|
|
71796
71860
|
}
|
|
71797
71861
|
});
|
|
71798
|
-
return;
|
|
71799
|
-
}
|
|
71800
|
-
if (toolCall) {
|
|
71801
|
-
let received = 0;
|
|
71802
|
-
reply6.on("data", (chunk) => {
|
|
71803
|
-
received += chunk.length;
|
|
71804
|
-
if (received > BODY_LIMIT) {
|
|
71805
|
-
reply6.destroy();
|
|
71806
|
-
res.destroy();
|
|
71807
|
-
}
|
|
71808
|
-
});
|
|
71809
|
-
}
|
|
71810
|
-
if (!transform3) {
|
|
71811
|
-
res.writeHead(reply6.statusCode ?? 502, responseHeaders);
|
|
71812
|
-
reply6.pipe(res);
|
|
71813
|
-
reply6.on("error", () => res.destroy());
|
|
71814
|
-
return;
|
|
71815
|
-
}
|
|
71816
|
-
const chunks = [];
|
|
71817
|
-
let size2 = 0;
|
|
71818
|
-
reply6.on("data", (chunk) => {
|
|
71819
|
-
size2 += chunk.length;
|
|
71820
|
-
if (size2 > BODY_LIMIT) {
|
|
71821
|
-
reply6.destroy();
|
|
71822
|
-
reject2(res, 502, "Tool response exceeded the sandbox gateway limit.");
|
|
71823
|
-
} else chunks.push(chunk);
|
|
71824
|
-
});
|
|
71825
|
-
reply6.on("error", () => {
|
|
71826
|
-
if (!res.headersSent) reject2(res, 502, "Tool connection failed.");
|
|
71827
|
-
else res.destroy();
|
|
71828
|
-
});
|
|
71829
|
-
reply6.on("end", () => {
|
|
71830
|
-
if (size2 > BODY_LIMIT) return;
|
|
71831
|
-
try {
|
|
71832
|
-
let value5 = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
71833
|
-
if (transform3 === "context" && reply6.statusCode === 200) {
|
|
71834
|
-
const connection4 = mapped(exposedOrigin ?? "");
|
|
71835
|
-
value5 = { ...value5, env: connection4.env, session: connection4.session };
|
|
71836
|
-
}
|
|
71837
|
-
if (transform3 === "socket" && reply6.statusCode === 200 && value5?.ok === true) {
|
|
71838
|
-
const grant = new URL(value5.url);
|
|
71839
|
-
const expected = loopbackOrigin(session2.eventsUrl);
|
|
71840
|
-
if (grant.protocol !== "ws:" || grant.hostname !== expected.hostname || grant.port !== expected.port || grant.search || grant.hash || grant.username || grant.password || !/^\/_ancha\/socket\/[a-f0-9]{64}$/.test(grant.pathname)) throw new Error("Invalid socket grant");
|
|
71841
|
-
for (const [path9, old] of socketGrants) if (old.expires <= Date.now()) socketGrants.delete(path9);
|
|
71842
|
-
if (socketGrants.size >= 128) throw new Error("Too many socket grants");
|
|
71843
|
-
socketGrants.set(grant.pathname, { url: grant, expires: Date.now() + 3e4 });
|
|
71844
|
-
value5 = { ...value5, url: (exposedOrigin ?? "").replace(/^http:/, "ws:") + grant.pathname };
|
|
71845
|
-
}
|
|
71846
|
-
const body7 = JSON.stringify(value5);
|
|
71847
|
-
delete responseHeaders["content-encoding"];
|
|
71848
|
-
delete responseHeaders["content-length"];
|
|
71849
|
-
res.writeHead(reply6.statusCode ?? 502, { ...responseHeaders, "content-length": Buffer.byteLength(body7) });
|
|
71850
|
-
res.end(body7);
|
|
71851
|
-
} catch {
|
|
71852
|
-
reject2(res, 502, "Tool context was not a valid bounded response.");
|
|
71853
|
-
}
|
|
71854
71862
|
});
|
|
71855
|
-
}
|
|
71863
|
+
} catch {
|
|
71864
|
+
return reject2(res, 502, "Tool connection failed.");
|
|
71865
|
+
}
|
|
71856
71866
|
upstreamRequests.add(target5);
|
|
71857
71867
|
target5.once("close", () => upstreamRequests.delete(target5));
|
|
71858
71868
|
target5.once("error", () => {
|
|
@@ -72172,7 +72182,8 @@ function createComposioConnection(options5) {
|
|
|
72172
72182
|
signal.removeEventListener("abort", abort);
|
|
72173
72183
|
}
|
|
72174
72184
|
}
|
|
72175
|
-
const tag3 = (expiry, lease) => createHmac("sha256",
|
|
72185
|
+
const tag3 = (expiry, lease, key5 = options5.apiKey) => createHmac("sha256", key5).update(`ancha-route:${expiry}:${lease}`).digest("hex").slice(0, 16);
|
|
72186
|
+
const signers = [options5.apiKey, ...options5.savedApiKey && options5.savedApiKey !== options5.apiKey ? [options5.savedApiKey] : []];
|
|
72176
72187
|
async function sweep() {
|
|
72177
72188
|
const signal = AbortSignal.timeout(5e3);
|
|
72178
72189
|
let cursor4, deletions = 0;
|
|
@@ -72190,7 +72201,7 @@ function createComposioConnection(options5) {
|
|
|
72190
72201
|
if (!config12.success || visited.has(config12.data.id)) continue;
|
|
72191
72202
|
visited.add(config12.data.id);
|
|
72192
72203
|
const match3 = /^ancha-route-(\d{10})-([a-z0-9]{12})-([a-f0-9]{16})$/.exec(config12.data.name);
|
|
72193
|
-
if (!match3 || Number(match3[1]) * 1e3 >= Date.now() || !timingSafeEqual2(Buffer.from(match3[3]), Buffer.from(tag3(match3[1], match3[2])))) continue;
|
|
72204
|
+
if (!match3 || Number(match3[1]) * 1e3 >= Date.now() || !signers.some((key5) => timingSafeEqual2(Buffer.from(match3[3]), Buffer.from(tag3(match3[1], match3[2], key5))))) continue;
|
|
72194
72205
|
const accounts2 = await call2(`/connected_accounts?${new URLSearchParams({ auth_config_ids: config12.data.id, limit: "50" })}`, "GET", void 0, signal);
|
|
72195
72206
|
if (accounts2.status < 200 || accounts2.status >= 300) continue;
|
|
72196
72207
|
const listed = pageSchema.safeParse(accounts2.data);
|
|
@@ -72333,7 +72344,7 @@ var init_composio_connection = __esm({
|
|
|
72333
72344
|
status;
|
|
72334
72345
|
slug;
|
|
72335
72346
|
constructor(status5, slug11) {
|
|
72336
|
-
super(`Composio did not create the attempt's test connection (${status5} ${slug11}): check that the workspace secret COMPOSIO_API_KEY is a project API key that may create auth configs and connected accounts.`);
|
|
72347
|
+
super(status5 === 401 || status5 === 403 ? `Composio did not create the attempt's test connection (${status5} ${slug11}): check that the workspace secret COMPOSIO_API_KEY is a project API key that may create auth configs and connected accounts.` : `Composio did not create the attempt's test connection (${status5} ${slug11}); run again.`);
|
|
72337
72348
|
this.name = "ComposioConnectionError";
|
|
72338
72349
|
this.status = status5;
|
|
72339
72350
|
this.slug = slug11;
|
|
@@ -72342,6 +72353,26 @@ var init_composio_connection = __esm({
|
|
|
72342
72353
|
}
|
|
72343
72354
|
});
|
|
72344
72355
|
|
|
72356
|
+
// backend/src/execution/connection-route.ts
|
|
72357
|
+
function unusableRouteKey(value5) {
|
|
72358
|
+
const key5 = routeKey(value5);
|
|
72359
|
+
if (!key5 || /^[\x21-\x7e]+$/.test(key5)) return void 0;
|
|
72360
|
+
return /[\r\n]/.test(key5) ? "a line break" : /[ \t]/.test(key5) ? "a space or tab" : /[^\x00-\x7f]/.test(key5) ? "a character that is not plain ASCII, such as a curly quote" : "a control character";
|
|
72361
|
+
}
|
|
72362
|
+
var routeKey, unusableKeyReason;
|
|
72363
|
+
var init_connection_route = __esm({
|
|
72364
|
+
"backend/src/execution/connection-route.ts"() {
|
|
72365
|
+
"use strict";
|
|
72366
|
+
routeKey = (value5) => value5?.trim() ?? "";
|
|
72367
|
+
unusableKeyReason = (what, next2 = "run ancha agent upload again") => ({
|
|
72368
|
+
code: "route_key",
|
|
72369
|
+
level: "fail",
|
|
72370
|
+
message: `The workspace secret COMPOSIO_API_KEY contains ${what}, which an API key cannot carry in a request header.`,
|
|
72371
|
+
fix: `Export the Composio project\u2019s API key as COMPOSIO_API_KEY without that character, run ancha secrets set COMPOSIO_API_KEY, then ${next2}.`
|
|
72372
|
+
});
|
|
72373
|
+
}
|
|
72374
|
+
});
|
|
72375
|
+
|
|
72345
72376
|
// backend/src/execution/ingress-client.ts
|
|
72346
72377
|
import { createHash as createHash5, randomBytes as randomBytes2 } from "node:crypto";
|
|
72347
72378
|
function ingressPath(path8, realm) {
|
|
@@ -72378,7 +72409,10 @@ async function startIngressClient(options5) {
|
|
|
72378
72409
|
for (const toolkit of ["quickbooks", "netsuite"]) if (toolkits[toolkit] && twins.includes(toolkit)) activeToolkits[toolkit] = "composio";
|
|
72379
72410
|
const qb = !!activeToolkits.quickbooks;
|
|
72380
72411
|
const connection4 = qb ? env.services.quickbooks : { url: "http://127.0.0.1", token: "", accountId: "" };
|
|
72381
|
-
|
|
72412
|
+
const apiKey = routeKey(descriptor2.secretValues.COMPOSIO_API_KEY);
|
|
72413
|
+
if (!connection4 || qb && (!connection4.accountId || !connection4.token) || !apiKey) throw new AnchaError("CONFIG_INVALID", "Composio route credentials are required");
|
|
72414
|
+
const unusable = unusableRouteKey(apiKey);
|
|
72415
|
+
if (unusable) throw new AnchaError("CONFIG_INVALID", unusableKeyReason(unusable).message);
|
|
72382
72416
|
const local2 = new URL(connection4.url);
|
|
72383
72417
|
if (qb && (local2.protocol !== "http:" || local2.hostname !== "127.0.0.1" || local2.username || local2.password || local2.search || local2.hash || local2.pathname.replace(/\/$/, "") !== `/e/${env.id}/quickbooks`)) throw new Error("QuickBooks route must target its local world");
|
|
72384
72418
|
const ns = activeToolkits.netsuite ? env.services.netsuite : void 0;
|
|
@@ -72497,7 +72531,8 @@ async function startIngressClient(options5) {
|
|
|
72497
72531
|
const user9 = `ancha-${hash2(descriptor2.attemptId)}`;
|
|
72498
72532
|
const lifecycle2 = createComposioConnection({
|
|
72499
72533
|
...options5.composio,
|
|
72500
|
-
apiKey
|
|
72534
|
+
apiKey,
|
|
72535
|
+
savedApiKey: descriptor2.secretValues.COMPOSIO_API_KEY,
|
|
72501
72536
|
user: user9,
|
|
72502
72537
|
publicUrl,
|
|
72503
72538
|
token: connection4.token,
|
|
@@ -72523,14 +72558,14 @@ async function startIngressClient(options5) {
|
|
|
72523
72558
|
publicUrl,
|
|
72524
72559
|
token: connection4.token,
|
|
72525
72560
|
realm: connection4.accountId,
|
|
72526
|
-
apiKey
|
|
72561
|
+
apiKey,
|
|
72527
72562
|
attemptId: descriptor2.attemptId,
|
|
72528
72563
|
agentKey,
|
|
72529
72564
|
user: user9,
|
|
72530
72565
|
connection: () => !qb || closed || failed2 || signal.aborted || Date.now() >= expires ? Promise.reject(new ComposioConnectionError(503, "ROUTE_CLOSED")) : lifecycle2.connection(),
|
|
72531
72566
|
sessions: sessions2,
|
|
72532
72567
|
narrowed: (toolkits2) => {
|
|
72533
|
-
for (const toolkit of toolkits2) if (![agentKey,
|
|
72568
|
+
for (const toolkit of toolkits2) if (![agentKey, apiKey, connection4.token, ns?.token, publicUrl].some((secret) => secret && toolkit.includes(secret))) narrowed.add(toolkit);
|
|
72534
72569
|
},
|
|
72535
72570
|
signal: failure5.signal,
|
|
72536
72571
|
get failed() {
|
|
@@ -72561,7 +72596,7 @@ async function startIngressClient(options5) {
|
|
|
72561
72596
|
if (reached) counts2[toolkit].reached++;
|
|
72562
72597
|
}
|
|
72563
72598
|
if (event3.op === "refused") counts2[toolkit].refused++;
|
|
72564
|
-
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 ? 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) : void 0);
|
|
72599
|
+
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);
|
|
72565
72600
|
},
|
|
72566
72601
|
summary: () => {
|
|
72567
72602
|
const result = {};
|
|
@@ -72598,7 +72633,7 @@ async function startIngressClient(options5) {
|
|
|
72598
72633
|
}
|
|
72599
72634
|
};
|
|
72600
72635
|
}
|
|
72601
|
-
var headersSchema, requestSchema, batchSchema, bindSchema, forwarded, methods, hash2, REFUSAL_FIX, unreachedDetail;
|
|
72636
|
+
var headersSchema, requestSchema, batchSchema, bindSchema, forwarded, methods, hash2, REFUSAL_FIX, unreachedDetail, KEY_REJECTED;
|
|
72602
72637
|
var init_ingress_client = __esm({
|
|
72603
72638
|
"backend/src/execution/ingress-client.ts"() {
|
|
72604
72639
|
"use strict";
|
|
@@ -72606,6 +72641,7 @@ var init_ingress_client = __esm({
|
|
|
72606
72641
|
init_src();
|
|
72607
72642
|
init_composio();
|
|
72608
72643
|
init_composio_connection();
|
|
72644
|
+
init_connection_route();
|
|
72609
72645
|
headersSchema = external_exports.record(external_exports.string(), external_exports.string());
|
|
72610
72646
|
requestSchema = external_exports.strictObject({ rid: external_exports.string().min(1).max(256), method: external_exports.enum(["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE"]), path: external_exports.string().max(8192), query: external_exports.string().max(8192), headers: headersSchema, body_b64: external_exports.string().max(87384) });
|
|
72611
72647
|
batchSchema = external_exports.strictObject({ requests: external_exports.array(requestSchema).max(8) });
|
|
@@ -72636,6 +72672,7 @@ var init_ingress_client = __esm({
|
|
|
72636
72672
|
MCP_BATCH: "send one JSON-RPC object per MCP request"
|
|
72637
72673
|
};
|
|
72638
72674
|
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.`;
|
|
72675
|
+
KEY_REJECTED = "Composio answered 401 to the agent's call through the route: it does not accept the workspace secret COMPOSIO_API_KEY, which the route sends for the agent. Export the Composio project's API key as COMPOSIO_API_KEY, run ancha secrets set COMPOSIO_API_KEY, then run again.";
|
|
72639
72676
|
}
|
|
72640
72677
|
});
|
|
72641
72678
|
|
|
@@ -72665,6 +72702,12 @@ async function runRoutedTrial(spec, run5) {
|
|
|
72665
72702
|
if (!spec.agent.routes?.quickbooks && !spec.agent.routes?.netsuite) return run5(spec);
|
|
72666
72703
|
const descriptor2 = attemptDescriptor();
|
|
72667
72704
|
const startedAt = performance.now();
|
|
72705
|
+
const unusable = unusableRouteKey(descriptor2.secretValues.COMPOSIO_API_KEY);
|
|
72706
|
+
if (unusable) {
|
|
72707
|
+
const { message: message8, fix } = unusableKeyReason(unusable, "run again");
|
|
72708
|
+
const result = await invalidTrial({ scene: spec.scene, trial: spec.trial, dir: spec.dir, startedAt, envId: spec.env.id, service: spec.agent.routes.quickbooks ? "quickbooks" : "netsuite", error: { code: "ROUTE_KEY_REJECTED", message: `${message8} ${fix}` } });
|
|
72709
|
+
return { ...result, harnessIssues: result.harnessIssues.map((issue9) => ({ ...issue9, code: "ROUTE_KEY_REJECTED" })) };
|
|
72710
|
+
}
|
|
72668
72711
|
let sessionId, captured;
|
|
72669
72712
|
const route15 = await startIngressClient({
|
|
72670
72713
|
routes: spec.agent.routes,
|
|
@@ -72703,13 +72746,15 @@ async function runRoutedTrial(spec, run5) {
|
|
|
72703
72746
|
return { ...result, routes: route15.summary(), ...result.harnessIssues.some((issue9) => issue9.owner === "harness" && issue9.code?.startsWith("ROUTE_")) && { valid: false, passed: false } };
|
|
72704
72747
|
} catch (error64) {
|
|
72705
72748
|
await route15.close();
|
|
72706
|
-
const
|
|
72749
|
+
const stopped = error64 instanceof AnchaError && error64.code === "AGENT_UNREACHABLE" ? error64 : void 0;
|
|
72750
|
+
const connectionIssue = route15.entries().find((entry2) => entry2.issue?.code === "ROUTE_CONNECTION_FAILED")?.issue ?? (stopped ? route15.entries().find((entry2) => entry2.issue?.code === "ROUTE_KEY_REJECTED")?.issue : void 0);
|
|
72707
72751
|
if (!route15.failed && !connectionIssue || spec.signal?.aborted) throw error64;
|
|
72708
|
-
const result = await invalidTrial({ scene: spec.scene, trial: spec.trial, dir: spec.dir, startedAt, envId: spec.env.id, ...sessionId && { sessionId }, ...captured && { capture: captured }, service: spec.agent.routes.quickbooks ? "quickbooks" : "netsuite", error: connectionIssue ? { code: "ROUTE_CONNECTION_FAILED", message: connectionIssue.message } : { code: "ROUTE_INGRESS_FAILED", message: "The Composio route could not be kept open." } });
|
|
72752
|
+
const result = await invalidTrial({ scene: spec.scene, trial: spec.trial, dir: spec.dir, startedAt, envId: spec.env.id, ...sessionId && { sessionId }, ...captured && { capture: captured }, service: spec.agent.routes.quickbooks ? "quickbooks" : "netsuite", error: connectionIssue ? { code: connectionIssue.code ?? "ROUTE_CONNECTION_FAILED", message: connectionIssue.message } : { code: "ROUTE_INGRESS_FAILED", message: "The Composio route could not be kept open." } });
|
|
72709
72753
|
if (!captured) {
|
|
72710
72754
|
result.trace = route15.entries().map((entry2, i) => ({ ...entry2, seq: i + 1 }));
|
|
72711
72755
|
result.harnessIssues = collectHarnessIssues(result.trace, []);
|
|
72712
72756
|
}
|
|
72757
|
+
if (stopped && connectionIssue?.code === "ROUTE_KEY_REJECTED") result.harnessIssues.push({ kind: "pipeline", owner: "agent", service: "agent", code: stopped.code, message: `${stopped.code}: ${stopped.message}`.slice(0, 500) });
|
|
72713
72758
|
await mkdir2(spec.dir, { recursive: true });
|
|
72714
72759
|
await writeFile2(join3(spec.dir, "trace.jsonl"), result.trace.map((entry2) => JSON.stringify(entry2) + "\n").join(""));
|
|
72715
72760
|
return { ...result, routes: route15.summary() };
|
|
@@ -72727,6 +72772,7 @@ var init_routed_trial = __esm({
|
|
|
72727
72772
|
init_invalid_trial();
|
|
72728
72773
|
init_runtime();
|
|
72729
72774
|
init_ingress_client();
|
|
72775
|
+
init_connection_route();
|
|
72730
72776
|
connections2 = /* @__PURE__ */ new WeakMap();
|
|
72731
72777
|
captures = /* @__PURE__ */ new WeakMap();
|
|
72732
72778
|
trialIngress = (env) => connections2.get(env);
|
|
@@ -128817,10 +128863,10 @@ var init_connect_registry = __esm({
|
|
|
128817
128863
|
});
|
|
128818
128864
|
|
|
128819
128865
|
// packages/server/src/twins/stripe/connect.ts
|
|
128820
|
-
function requestAccount(ctx, header4,
|
|
128866
|
+
function requestAccount(ctx, header4, routeKey2) {
|
|
128821
128867
|
if (header4 === void 0) return null;
|
|
128822
128868
|
const id15 = header4.trim();
|
|
128823
|
-
if (!ACCOUNT_SCOPED.has(
|
|
128869
|
+
if (!ACCOUNT_SCOPED.has(routeKey2)) unsupported8(`the Stripe-Account header on ${routeKey2}`);
|
|
128824
128870
|
const account9 = load2(ctx, id15);
|
|
128825
128871
|
if (!account9 || account9.object !== "account" || account9.deleted) {
|
|
128826
128872
|
throw new StripeError(403, "invalid_request_error", `The provided key does not have access to account '${id15}' (or that account does not exist). Application access may have been revoked.`, { code: "account_invalid" });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ancha-labs/cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.46",
|
|
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": {
|