@ancha-labs/cli 0.4.15 → 0.4.17
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 +1890 -1297
- package/lib/assets/SKILL.md +1 -1
- package/lib/assets/agents-section.md +1 -1
- package/lib/assets/docs/cloud.md +3 -1
- package/lib/assets/docs/datasets.md +2 -2
- package/lib/assets/docs/scenes.md +2 -2
- package/lib/assets/docs/setup.md +2 -2
- package/lib/assets/docs/traces.md +1 -1
- package/lib/assets/harbor/companion.mjs +114 -38
- package/lib/assets/harbor/driver.py +17 -3
- package/lib/assets/ui/app.js +1 -1
- package/lib/mcp-entry.mjs +10 -6
- package/lib/worker.mjs +220 -73
- package/lib/world-server.mjs +71 -36
- package/package.json +1 -1
package/lib/worker.mjs
CHANGED
|
@@ -20827,7 +20827,7 @@ var init_answer = __esm({
|
|
|
20827
20827
|
not_contains: texts.optional().describe("Text the final answer must not contain"),
|
|
20828
20828
|
numbers: external_exports.array(AnswerNumberSchema).min(1).optional().describe("Numbers the final answer must state, each within its tolerance; thousands separators, currency codes and symbols, minus signs and parentheses for negatives are read"),
|
|
20829
20829
|
case: external_exports.enum(["insensitive", "sensitive"]).optional().describe("How contains and not_contains compare letters; default insensitive")
|
|
20830
|
-
}).describe("Checks the agent's final answer (what it posts to ANCHA_DONE_URL, its HTTP reply, or
|
|
20830
|
+
}).describe("Checks the agent's final answer (what it posts to ANCHA_DONE_URL, its HTTP reply, or what it prints on stdout): the text and numbers it states");
|
|
20831
20831
|
}
|
|
20832
20832
|
});
|
|
20833
20833
|
|
|
@@ -24332,10 +24332,10 @@ var init_better_stack = __esm({
|
|
|
24332
24332
|
open4.add(entry2.source);
|
|
24333
24333
|
}
|
|
24334
24334
|
});
|
|
24335
|
-
seed43.onCall.forEach((
|
|
24335
|
+
seed43.onCall.forEach((calendar4, i) => calendar4.users.forEach((user8, j) => {
|
|
24336
24336
|
if (!people3.has(user8)) issue6(["onCall", i, "users", j], `${user8} is not a user`);
|
|
24337
24337
|
}));
|
|
24338
|
-
if (seed43.onCall.filter((
|
|
24338
|
+
if (seed43.onCall.filter((calendar4) => calendar4.default).length > 1) issue6(["onCall"], "only one default calendar");
|
|
24339
24339
|
seed43.statusPages.forEach((page18, i) => {
|
|
24340
24340
|
const names5 = new Set(page18.resources.map((resource2) => resource2.publicName));
|
|
24341
24341
|
page18.resources.forEach((resource2, j) => {
|
|
@@ -31158,10 +31158,14 @@ var init_netsuite = __esm({
|
|
|
31158
31158
|
id: id8.optional(),
|
|
31159
31159
|
externalId: text11.optional(),
|
|
31160
31160
|
fields: external_exports.record(external_exports.string(), external_exports.unknown()).optional(),
|
|
31161
|
-
apply: external_exports.array(application).optional()
|
|
31161
|
+
apply: external_exports.array(application).optional(),
|
|
31162
|
+
credit: external_exports.array(application).optional()
|
|
31162
31163
|
}).refine((check3) => check3.id === void 0 !== (check3.externalId === void 0), { message: "name the record with id or with externalId, not both", path: ["id"] });
|
|
31163
|
-
NetsuiteUnchangedCheckSchema = external_exports.strictObject({
|
|
31164
|
-
|
|
31164
|
+
NetsuiteUnchangedCheckSchema = external_exports.strictObject({
|
|
31165
|
+
types: external_exports.array(external_exports.enum(netsuiteRecordTypes)).min(1),
|
|
31166
|
+
except: external_exports.array(external_exports.strictObject({ type: external_exports.enum(netsuiteRecordTypes), id: id8.optional(), externalId: text11.optional() }).refine((check3) => check3.id === void 0 !== (check3.externalId === void 0), { message: "name the record with id or with externalId, not both" })).optional()
|
|
31167
|
+
});
|
|
31168
|
+
NetsuiteCountCheckSchema = external_exports.strictObject({ type: external_exports.enum(netsuiteRecordTypes), count: external_exports.number().int().min(0), includeSettlement: external_exports.boolean().optional() });
|
|
31165
31169
|
}
|
|
31166
31170
|
});
|
|
31167
31171
|
|
|
@@ -40642,11 +40646,21 @@ var init_file = __esm({
|
|
|
40642
40646
|
}
|
|
40643
40647
|
});
|
|
40644
40648
|
|
|
40649
|
+
// packages/core/src/datasets/netsuite-pe/writes.ts
|
|
40650
|
+
var init_writes = __esm({
|
|
40651
|
+
"packages/core/src/datasets/netsuite-pe/writes.ts"() {
|
|
40652
|
+
"use strict";
|
|
40653
|
+
init_netsuite();
|
|
40654
|
+
init_evals();
|
|
40655
|
+
}
|
|
40656
|
+
});
|
|
40657
|
+
|
|
40645
40658
|
// packages/core/src/datasets/netsuite-pe/evals.ts
|
|
40646
40659
|
var init_evals = __esm({
|
|
40647
40660
|
"packages/core/src/datasets/netsuite-pe/evals.ts"() {
|
|
40648
40661
|
"use strict";
|
|
40649
40662
|
init_netsuite();
|
|
40663
|
+
init_writes();
|
|
40650
40664
|
init_netsuite_money();
|
|
40651
40665
|
}
|
|
40652
40666
|
});
|
|
@@ -61080,8 +61094,10 @@ function evaluateTrace(trace, calls2, tools) {
|
|
|
61080
61094
|
function finalAnswer(trace) {
|
|
61081
61095
|
const entry2 = trace.findLast((e) => e.source === "agent" && e.service === "agent" && e.path === "/done");
|
|
61082
61096
|
if (!entry2) return void 0;
|
|
61083
|
-
const
|
|
61084
|
-
|
|
61097
|
+
const request2 = typeof entry2.request === "object" && entry2.request !== null ? entry2.request : void 0;
|
|
61098
|
+
const output2 = typeof entry2.request === "string" ? entry2.request : request2?.output;
|
|
61099
|
+
const source = request2?.source === "reply" || request2?.source === "stdout" ? request2.source : "done";
|
|
61100
|
+
return { text: answerText(output2), seq: entry2.seq, source, ...typeof request2?.printed === "number" && { printed: request2.printed } };
|
|
61085
61101
|
}
|
|
61086
61102
|
function evaluateAnswer(check3, trace) {
|
|
61087
61103
|
const contains3 = asList(check3.contains), absent = asList(check3.not_contains), sensitive = check3.case === "sensitive";
|
|
@@ -61093,13 +61109,22 @@ function evaluateAnswer(check3, trace) {
|
|
|
61093
61109
|
];
|
|
61094
61110
|
const expected = parts3.length ? `the final answer ${parts3.join("; ")}` : "a final answer";
|
|
61095
61111
|
const answer = finalAnswer(trace);
|
|
61112
|
+
if (answer?.printed !== void 0) {
|
|
61113
|
+
return {
|
|
61114
|
+
passed: false,
|
|
61115
|
+
expected,
|
|
61116
|
+
actual: `${answer.printed.toLocaleString("en-US")} characters on stdout`,
|
|
61117
|
+
evidence: [answer.seq],
|
|
61118
|
+
explanation: `The agent printed ${answer.printed.toLocaleString("en-US")} characters on stdout, more than an answer can be, so it gave no final answer. An agent prints its logs on stderr, or posts its answer to ANCHA_DONE_URL, body {"output": <its answer>}.`
|
|
61119
|
+
};
|
|
61120
|
+
}
|
|
61096
61121
|
if (!answer || answer.text.trim() === "") {
|
|
61097
61122
|
return {
|
|
61098
61123
|
passed: false,
|
|
61099
61124
|
expected,
|
|
61100
61125
|
actual: answer ? "an empty final answer" : "no final answer",
|
|
61101
61126
|
evidence: answer ? [answer.seq] : [],
|
|
61102
|
-
explanation: `The agent gave ${answer ? "an empty" : "no"} final answer. An agent answers with a POST to ANCHA_DONE_URL, body {"output": <its answer>}, or by printing it
|
|
61127
|
+
explanation: `The agent gave ${answer ? "an empty" : "no"} final answer. An agent answers with a POST to ANCHA_DONE_URL, body {"output": <its answer>}, or by printing it on stdout.`
|
|
61103
61128
|
};
|
|
61104
61129
|
}
|
|
61105
61130
|
const text24 = comparableText(answer.text, sensitive);
|
|
@@ -61116,7 +61141,8 @@ function evaluateAnswer(check3, trace) {
|
|
|
61116
61141
|
const explanation = [
|
|
61117
61142
|
...missing6.length ? [`The final answer does not contain ${quoted2(missing6)}.`] : [],
|
|
61118
61143
|
...unstated.length ? [`It states no number within ${unstated.map((n2) => `${plainNumber(n2.tolerance)} of ${n2.written}`).join(", nor within ")}: ${said}.`] : [],
|
|
61119
|
-
...present2.length ? [`It contains ${quoted2(present2)}, which it must not.`] : []
|
|
61144
|
+
...present2.length ? [`It contains ${quoted2(present2)}, which it must not.`] : [],
|
|
61145
|
+
...answer.source === "stdout" ? ["Its answer is everything it printed on stdout."] : answer.source === "reply" ? ["Its answer is its HTTP reply."] : []
|
|
61120
61146
|
].join(" ");
|
|
61121
61147
|
return { passed: false, expected, actual, explanation, evidence: [answer.seq] };
|
|
61122
61148
|
}
|
|
@@ -103433,7 +103459,7 @@ function collectionWrite(kind, c, body6) {
|
|
|
103433
103459
|
const result = create(c.env.ctx, kind, accountId(c), body6);
|
|
103434
103460
|
return new Response(null, { status: 201, headers: { "x-restli-id": String(result.id), "x-restli-protocol-version": "2.0.0" } });
|
|
103435
103461
|
}
|
|
103436
|
-
function
|
|
103462
|
+
function calendar2(raw3) {
|
|
103437
103463
|
const match3 = /^\((?:year:(\d{4}),month:(\d{1,2}),day:(\d{1,2})|day:(\d{1,2}),month:(\d{1,2}),year:(\d{4}))\)$/.exec(raw3);
|
|
103438
103464
|
if (!match3) invalid8("Date must be (year:YYYY,month:M,day:D) or (day:D,month:M,year:YYYY)");
|
|
103439
103465
|
const y = match3[1] ?? match3[6], m = match3[2] ?? match3[5], d = match3[3] ?? match3[4], date10 = `${y}-${m.padStart(2, "0")}-${d.padStart(2, "0")}`;
|
|
@@ -103515,7 +103541,7 @@ var init_routes2 = __esm({
|
|
|
103515
103541
|
if (!["DAILY", "ALL"].includes(q.get("timeGranularity") ?? "")) gap2(`timeGranularity ${q.get("timeGranularity")}`);
|
|
103516
103542
|
const range2 = /^\(start:(\([^()]+\))(?:,end:(\([^()]+\)))?\)$/.exec(q.get("dateRange") ?? "");
|
|
103517
103543
|
if (!range2) invalid8("dateRange requires start and optional end tuples");
|
|
103518
|
-
const start =
|
|
103544
|
+
const start = calendar2(range2[1]), end = range2[2] ? calendar2(range2[2]) : c.env.ctx.clock.now().toISOString().slice(0, 10);
|
|
103519
103545
|
if (end < start) invalid8("dateRange.end precedes start");
|
|
103520
103546
|
const selectedFields2 = q.get("fields")?.split(",") ?? ["impressions", "clicks"];
|
|
103521
103547
|
const allowed2 = ["pivotValues", "dateRange", "impressions", "clicks", "oneClickLeads", "costInLocalCurrency"];
|
|
@@ -134350,9 +134376,9 @@ function seed21(ctx) {
|
|
|
134350
134376
|
entry2.resolved?.by ?? null
|
|
134351
134377
|
);
|
|
134352
134378
|
}
|
|
134353
|
-
for (const
|
|
134354
|
-
const users5 =
|
|
134355
|
-
db3.prepare("INSERT INTO bs_calendars (id, name, is_default, users) VALUES (?, ?, ?, ?)").run(nextId3(ctx, "calendar"),
|
|
134379
|
+
for (const calendar4 of input4.onCall) {
|
|
134380
|
+
const users5 = calendar4.users.map((email11) => db3.prepare("SELECT id FROM bs_users WHERE email = ?").get(email11).id);
|
|
134381
|
+
db3.prepare("INSERT INTO bs_calendars (id, name, is_default, users) VALUES (?, ?, ?, ?)").run(nextId3(ctx, "calendar"), calendar4.name, calendar4.default ? 1 : 0, JSON.stringify(users5));
|
|
134356
134382
|
}
|
|
134357
134383
|
for (const page18 of input4.statusPages) {
|
|
134358
134384
|
const id14 = nextId3(ctx, "page");
|
|
@@ -134408,9 +134434,9 @@ function dumpState20(ctx) {
|
|
|
134408
134434
|
resolvedBy: row2.resolved_by,
|
|
134409
134435
|
...row2.summary && { summary: row2.summary }
|
|
134410
134436
|
})),
|
|
134411
|
-
onCall: db3.prepare("SELECT * FROM bs_calendars ORDER BY rowid").all().map((
|
|
134412
|
-
name:
|
|
134413
|
-
users: JSON.parse(
|
|
134437
|
+
onCall: db3.prepare("SELECT * FROM bs_calendars ORDER BY rowid").all().map((calendar4) => ({
|
|
134438
|
+
name: calendar4.name,
|
|
134439
|
+
users: JSON.parse(calendar4.users).map((id14) => db3.prepare("SELECT email FROM bs_users WHERE id = ?").get(id14)?.email ?? id14)
|
|
134414
134440
|
})),
|
|
134415
134441
|
statusPages: db3.prepare("SELECT * FROM bs_pages ORDER BY rowid").all().map((page18) => ({
|
|
134416
134442
|
id: page18.id,
|
|
@@ -148410,7 +148436,7 @@ function feeFor(series2, count4, price3, taker) {
|
|
|
148410
148436
|
const exact = rate * series2.fee_multiplier * (count4 / 100) * (price3 / ONE) * (1 - price3 / ONE);
|
|
148411
148437
|
return Math.ceil(exact * 100 - 1e-9) * 1e4;
|
|
148412
148438
|
}
|
|
148413
|
-
function
|
|
148439
|
+
function ledger2(ctx, now11) {
|
|
148414
148440
|
const db3 = ctx.store.db, positions2 = /* @__PURE__ */ new Map();
|
|
148415
148441
|
let cash = db3.prepare("SELECT COALESCE(SUM(amount), 0) AS total FROM kx_deposits WHERE at_ms <= ?").get(now11).total;
|
|
148416
148442
|
for (const fill of db3.prepare("SELECT * FROM kx_fills WHERE created_ms <= ? ORDER BY created_ms, rowid").all(now11)) {
|
|
@@ -148448,7 +148474,7 @@ function ledger(ctx, now11) {
|
|
|
148448
148474
|
return { cash, positions: positions2 };
|
|
148449
148475
|
}
|
|
148450
148476
|
function balances(ctx, now11) {
|
|
148451
|
-
const { cash, positions: positions2 } =
|
|
148477
|
+
const { cash, positions: positions2 } = ledger2(ctx, now11);
|
|
148452
148478
|
const held = restingOrders(ctx, now11).reduce((total2, order5) => total2 + collateral(order5), 0);
|
|
148453
148479
|
let value4 = 0;
|
|
148454
148480
|
for (const entry2 of positions2.values()) if (entry2.position) value4 += Math.abs(entry2.position) * (entry2.position > 0 ? getMarket(ctx, entry2.ticker).last_price : ONE - getMarket(ctx, entry2.ticker).last_price);
|
|
@@ -148493,7 +148519,7 @@ function seed32(ctx) {
|
|
|
148493
148519
|
});
|
|
148494
148520
|
});
|
|
148495
148521
|
input4.orders.forEach((entry2, i) => {
|
|
148496
|
-
const id14 = seededUuid(`order:${i}`), created3 = at3(entry2.created), series2 = seriesOfMarket(ctx, getMarket(ctx, entry2.market)), positionBefore =
|
|
148522
|
+
const id14 = seededUuid(`order:${i}`), created3 = at3(entry2.created), series2 = seriesOfMarket(ctx, getMarket(ctx, entry2.market)), positionBefore = ledger2(ctx, created3).positions.get(entry2.market)?.position ?? 0;
|
|
148497
148523
|
const legacy2 = legacySide(entry2.side, positionBefore);
|
|
148498
148524
|
db3.prepare(`INSERT INTO kx_orders (id, client_order_id, ticker, book_side, side, action, outcome_side, price, initial, filled, time_in_force, post_only, stp, cancel_on_pause, expiration_ms, created_ms, updated_ms, canceled_ms,
|
|
148499
148525
|
taker_cost, maker_cost, taker_fees, maker_fees) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, 0, 'taker_at_cross', 0, NULL, ?, ?, ?, 0, 0, 0, 0)`).run(id14, entry2.clientOrderId ?? null, entry2.market, entry2.side, legacy2.side, legacy2.action, legacy2.outcome, price3(entry2.price), count4(entry2.count), entry2.timeInForce, created3, created3, entry2.canceled === void 0 ? null : at3(entry2.canceled));
|
|
@@ -148986,7 +149012,7 @@ function positions(call2) {
|
|
|
148986
149012
|
choice2(settlement, "settlement_status", ["all", "settled", "unsettled"]);
|
|
148987
149013
|
for (const name5 of counts) choice2(name5, "count_filter", ["position", "total_traded"]);
|
|
148988
149014
|
const ticker2 = params10.get("ticker"), eventTicker = params10.get("event_ticker");
|
|
148989
|
-
const entries3 = [...
|
|
149015
|
+
const entries3 = [...ledger2(ctx, now11).positions.values()].filter((entry2) => {
|
|
148990
149016
|
const market2 = getMarket(ctx, entry2.ticker);
|
|
148991
149017
|
return (settlement === "all" || settlement === "settled" === (entry2.settlement !== void 0)) && (!ticker2 || entry2.ticker === ticker2) && (!eventTicker || market2.event === eventTicker) && (!counts.length || counts.some((name5) => name5 === "position" ? entry2.position !== 0 : entry2.traded !== 0));
|
|
148992
149018
|
});
|
|
@@ -149028,7 +149054,7 @@ function settlements(call2) {
|
|
|
149028
149054
|
const ctx = call2.ctx, now11 = ctx.clock.nowMs(), params10 = query9(call2, ["limit", "cursor", "ticker", "event_ticker", "min_ts", "max_ts", "subaccount"]), ticker2 = params10.get("ticker"), eventTicker = params10.get("event_ticker");
|
|
149029
149055
|
primary2(params10.get("subaccount"));
|
|
149030
149056
|
const within2 = timeRange2(params10, "min_ts", "max_ts");
|
|
149031
|
-
const rows7 = [...
|
|
149057
|
+
const rows7 = [...ledger2(ctx, now11).positions.values()].filter((entry2) => entry2.settlement && (!ticker2 || entry2.ticker === ticker2) && (!eventTicker || getMarket(ctx, entry2.ticker).event === eventTicker) && within2(entry2.settlement.at)).sort((a, b) => b.settlement.at - a.settlement.at);
|
|
149032
149058
|
const result = page14(call2, rows7, 200, 100);
|
|
149033
149059
|
return json22({
|
|
149034
149060
|
settlements: result.items.map((entry2) => ({
|
|
@@ -164001,7 +164027,7 @@ function bindValue(value4) {
|
|
|
164001
164027
|
if (typeof value4 === "string") return value4 === "" ? null : value4;
|
|
164002
164028
|
invalid24("Each params value must be a string or a number.");
|
|
164003
164029
|
}
|
|
164004
|
-
function
|
|
164030
|
+
function calendar3(y, m, d) {
|
|
164005
164031
|
const date10 = /* @__PURE__ */ new Date(0);
|
|
164006
164032
|
date10.setUTCFullYear(y, m - 1, d);
|
|
164007
164033
|
date10.setUTCHours(0, 0, 0, 0);
|
|
@@ -164011,7 +164037,7 @@ function calendar2(y, m, d) {
|
|
|
164011
164037
|
function isoDate(text24) {
|
|
164012
164038
|
const match3 = /^(\d{4})-(\d{2})-(\d{2})$/.exec(text24);
|
|
164013
164039
|
if (!match3) invalid24("Expected a YYYY-MM-DD world date.");
|
|
164014
|
-
|
|
164040
|
+
calendar3(+match3[1], +match3[2], +match3[3]);
|
|
164015
164041
|
return text24;
|
|
164016
164042
|
}
|
|
164017
164043
|
function dateModel(model) {
|
|
@@ -164050,7 +164076,7 @@ function parseDate2(value4, model) {
|
|
|
164050
164076
|
const values2 = new Map(tokens3.map((t, i) => [t, match3[i + 1]]));
|
|
164051
164077
|
if (!values2.has("YYYY") || !values2.has("DD") || !["MM", "MON", "MONTH"].some((t) => values2.has(t))) invalid24("TO_DATE requires year, month and day.", true);
|
|
164052
164078
|
const month = values2.has("MM") ? Number(values2.get("MM")) : MONTHS2.findIndex((m) => values2.has("MON") ? m.slice(0, 3).toLowerCase() === values2.get("MON").toLowerCase() : m.toLowerCase() === values2.get("MONTH").toLowerCase()) + 1;
|
|
164053
|
-
const date10 =
|
|
164079
|
+
const date10 = calendar3(Number(values2.get("YYYY")), month, Number(values2.get("DD")));
|
|
164054
164080
|
let hour2 = Number(values2.get("HH24") ?? values2.get("HH12") ?? values2.get("HH") ?? 0);
|
|
164055
164081
|
const minute2 = Number(values2.get("MI") ?? 0), second = Number(values2.get("SS") ?? 0);
|
|
164056
164082
|
if (values2.has("HH12") || values2.has("HH")) {
|
|
@@ -169055,20 +169081,36 @@ function record8(ctx, args) {
|
|
|
169055
169081
|
}
|
|
169056
169082
|
const applied = composite2 ? [...byLine.values()].sort((a, b) => a.doc - b.doc || a.line - b.line) : applications(ctx, id14).map((a) => ({ doc: a.doc, amount: a.amount })).sort((a, b) => a.doc - b.doc);
|
|
169057
169083
|
const wanted = args.apply?.map((a) => composite2 ? { ...a, line: a.line ?? 0 } : { ...a }).sort((a, b) => a.doc - b.doc || (a.line ?? 0) - (b.line ?? 0));
|
|
169058
|
-
|
|
169084
|
+
const creditLines = args.credit?.some((a) => a.line !== void 0);
|
|
169085
|
+
const credits = /* @__PURE__ */ new Map();
|
|
169086
|
+
for (const a of edges(ctx, id14).filter((a2) => a2.source !== id14)) {
|
|
169087
|
+
const key4 = creditLines ? `${a.source}:${a.sourceline}` : String(a.source);
|
|
169088
|
+
const item2 = credits.get(key4) ?? { doc: a.source, ...creditLines && { line: a.sourceline }, amount: 0 };
|
|
169089
|
+
item2.amount = Math.round((item2.amount + a.amount) * 100) / 100;
|
|
169090
|
+
credits.set(key4, item2);
|
|
169091
|
+
}
|
|
169092
|
+
const sort = (a, b) => a.doc - b.doc || (a.line ?? 0) - (b.line ?? 0);
|
|
169093
|
+
const credited = [...credits.values()].sort(sort);
|
|
169094
|
+
const wantedCredits = args.credit?.map((a) => creditLines ? { ...a, line: a.line ?? 0 } : { ...a }).sort(sort);
|
|
169095
|
+
const creditExpected = args.credit === void 0 ? "" : ` and credits ${JSON.stringify(args.credit)}`;
|
|
169096
|
+
return checkOutcome(matches8(actual, args.fields ?? {}) && (wanted === void 0 || isDeepStrictEqual(applied, wanted)) && (wantedCredits === void 0 || isDeepStrictEqual(credited, wantedCredits)), expected + creditExpected, JSON.stringify({ record: actual, apply: applied, credit: credited }));
|
|
169059
169097
|
}
|
|
169060
169098
|
function unchanged(ctx, args) {
|
|
169061
|
-
const
|
|
169062
|
-
|
|
169099
|
+
const allowed2 = (args.except ?? []).map((r2) => ({ type: r2.type, id: r2.id ?? byExternalId(ctx, r2.type, r2.externalId) }));
|
|
169100
|
+
const changes = sql(ctx).prepare("SELECT recordtype, id, operation FROM ns_history ORDER BY ordinal").all().filter((row2) => args.types.includes(row2.recordtype) && !allowed2.some((r2) => r2.type === row2.recordtype && r2.id === row2.id));
|
|
169101
|
+
const types = args.types.length >= netsuiteRecordTypes.length && netsuiteRecordTypes.every((type) => args.types.includes(type)) ? "NetSuite records" : args.types.length > 4 ? `${args.types.slice(0, 3).join(", ")} and ${args.types.length - 3} more record types` : args.types.join(", ");
|
|
169102
|
+
const except = args.except?.length ? ` except ${args.except.map((r2) => `${r2.type} ${r2.id ?? `eid:${r2.externalId}`}`).join(", ")}` : "";
|
|
169103
|
+
return checkOutcome(changes.length === 0, `no writes to ${types}${except}`, changes.length ? JSON.stringify(changes) : except ? "no other committed writes" : "no committed writes");
|
|
169063
169104
|
}
|
|
169064
169105
|
function count3(ctx, args) {
|
|
169065
|
-
const actual = recordIds(ctx, args.type).length;
|
|
169106
|
+
const actual = args.includeSettlement && isTx(args.type) ? sql(ctx).prepare("SELECT COUNT(*) AS count FROM ns_transactions WHERE recordtype = ?").get(args.type).count : recordIds(ctx, args.type).length;
|
|
169066
169107
|
return checkOutcome(actual === args.count, `${args.count} ${args.type} records`, `${actual} records`);
|
|
169067
169108
|
}
|
|
169068
169109
|
var init_checks13 = __esm({
|
|
169069
169110
|
"packages/server/src/twins/netsuite/checks.ts"() {
|
|
169070
169111
|
"use strict";
|
|
169071
169112
|
init_open_items();
|
|
169113
|
+
init_src();
|
|
169072
169114
|
init_checks4();
|
|
169073
169115
|
init_store5();
|
|
169074
169116
|
}
|
|
@@ -174400,8 +174442,9 @@ var init_sessions = __esm({
|
|
|
174400
174442
|
});
|
|
174401
174443
|
}
|
|
174402
174444
|
/**
|
|
174403
|
-
* The runner records the agent's answer for it when the agent posted none (SPEC-053 F2): an HTTP agent's reply, or
|
|
174404
|
-
*
|
|
174445
|
+
* The runner records the agent's answer for it when the agent posted none (SPEC-053 F2): an HTTP agent's reply, or its
|
|
174446
|
+
* stdout (SPEC-056 A), or how much it printed when that is too long to be an answer. The same `POST /done` entry, with
|
|
174447
|
+
* that source; never a second answer.
|
|
174405
174448
|
*/
|
|
174406
174449
|
answer(env, id14, answer) {
|
|
174407
174450
|
return env.serialize(() => {
|
|
@@ -174409,7 +174452,7 @@ var init_sessions = __esm({
|
|
|
174409
174452
|
if (state3 === "prepared") throw new AnchaError("SESSION_CONFLICT", "session has not started");
|
|
174410
174453
|
if (state3 === "finished") throw new AnchaError("SESSION_CONFLICT", "session has finished");
|
|
174411
174454
|
if (env.trace.list().some((entry2) => entry2.service === "agent" && entry2.path === "/done")) return { recorded: false };
|
|
174412
|
-
env.trace.record({ source: "agent", service: "agent", method: "POST", path: "/done", status: 200, request: { output: answer.output, source: answer.source } });
|
|
174455
|
+
env.trace.record({ source: "agent", service: "agent", method: "POST", path: "/done", status: 200, request: { output: answer.output, source: answer.source, ...answer.printed !== void 0 && { printed: answer.printed } } });
|
|
174413
174456
|
return { recorded: true };
|
|
174414
174457
|
});
|
|
174415
174458
|
}
|
|
@@ -174778,10 +174821,13 @@ function sessionRoutes(opts, sessions) {
|
|
|
174778
174821
|
} catch {
|
|
174779
174822
|
throw new AnchaError("USAGE", "request must be a JSON object");
|
|
174780
174823
|
}
|
|
174781
|
-
fields10(input4, ["output", "source"]);
|
|
174824
|
+
fields10(input4, ["output", "source", "printed"]);
|
|
174782
174825
|
if (typeof input4.output !== "string" || input4.output.length > MAX_ANSWER_CHARS) throw new AnchaError("USAGE", `output must be a string of at most ${MAX_ANSWER_CHARS} characters`);
|
|
174783
174826
|
if (input4.source !== "reply" && input4.source !== "stdout") throw new AnchaError("USAGE", "source must be reply or stdout");
|
|
174784
|
-
|
|
174827
|
+
if (input4.printed !== void 0 && (input4.source !== "stdout" || input4.output !== "" || typeof input4.printed !== "number" || !Number.isSafeInteger(input4.printed) || input4.printed <= 0)) {
|
|
174828
|
+
throw new AnchaError("USAGE", "printed is how many characters stdout held, with source stdout and an empty output");
|
|
174829
|
+
}
|
|
174830
|
+
return c.json(await sessions.answer(opts.manager.get(c.req.param("id")), c.req.param("sid"), { output: input4.output, source: input4.source, ...input4.printed !== void 0 && { printed: input4.printed } }));
|
|
174785
174831
|
});
|
|
174786
174832
|
app2.post("/envs/:id/trials/:sid/agent", async (c) => {
|
|
174787
174833
|
let input4;
|
|
@@ -174828,7 +174874,7 @@ var init_session_routes = __esm({
|
|
|
174828
174874
|
init_src();
|
|
174829
174875
|
init_feed();
|
|
174830
174876
|
init_env_info();
|
|
174831
|
-
MAX_ANSWER_CHARS =
|
|
174877
|
+
MAX_ANSWER_CHARS = 64 * 1024;
|
|
174832
174878
|
}
|
|
174833
174879
|
});
|
|
174834
174880
|
|
|
@@ -177022,6 +177068,26 @@ import { lookup as lookup5 } from "node:dns/promises";
|
|
|
177022
177068
|
import { createServer, request } from "node:http";
|
|
177023
177069
|
import { request as secureRequest } from "node:https";
|
|
177024
177070
|
import { isIP as isIP3 } from "node:net";
|
|
177071
|
+
import { brotliDecompressSync, gunzipSync, inflateSync } from "node:zlib";
|
|
177072
|
+
function refusalMessage(body6, encoding) {
|
|
177073
|
+
let text24;
|
|
177074
|
+
try {
|
|
177075
|
+
const raw3 = encoding === "gzip" || encoding === "x-gzip" ? gunzipSync(body6) : encoding === "deflate" ? inflateSync(body6) : encoding === "br" ? brotliDecompressSync(body6) : !encoding || encoding === "identity" ? body6 : void 0;
|
|
177076
|
+
if (raw3 === void 0) return void 0;
|
|
177077
|
+
text24 = raw3.toString("utf8");
|
|
177078
|
+
} catch {
|
|
177079
|
+
return void 0;
|
|
177080
|
+
}
|
|
177081
|
+
let message7 = text24;
|
|
177082
|
+
try {
|
|
177083
|
+
const json33 = JSON.parse(text24);
|
|
177084
|
+
const error64 = json33?.error;
|
|
177085
|
+
message7 = typeof error64 === "string" ? error64 : typeof error64?.message === "string" ? error64.message : typeof json33?.message === "string" ? json33.message : typeof json33?.detail === "string" ? json33.detail : typeof error64?.type === "string" ? error64.type : typeof error64?.code === "string" ? error64.code : text24;
|
|
177086
|
+
} catch {
|
|
177087
|
+
}
|
|
177088
|
+
const line2 = String(message7).replace(/\b(sk|rk|pk)-[\w*-]{4,}/g, "$1-\u2026").replace(/\s+/g, " ").trim();
|
|
177089
|
+
return line2 === "" ? void 0 : line2.length > 300 ? `${line2.slice(0, 299)}\u2026` : line2;
|
|
177090
|
+
}
|
|
177025
177091
|
function loopbackOrigin(value4) {
|
|
177026
177092
|
const url4 = new URL(value4);
|
|
177027
177093
|
if (url4.protocol !== "http:" || !["127.0.0.1", "localhost", "[::1]"].includes(url4.hostname) || url4.username || url4.password) throw new Error("Isolation gateway requires a local HTTP tool server");
|
|
@@ -177162,11 +177228,30 @@ async function startIsolationGateway(options4) {
|
|
|
177162
177228
|
agent: false,
|
|
177163
177229
|
...modelHost && { servername: modelHost, rejectUnauthorized: true, family: modelAddress.family }
|
|
177164
177230
|
}, (reply5) => {
|
|
177165
|
-
|
|
177231
|
+
const observe2 = (host, status4, message7) => {
|
|
177166
177232
|
try {
|
|
177167
|
-
options4.onModelReply?.(
|
|
177233
|
+
options4.onModelReply?.(host, status4, message7);
|
|
177168
177234
|
} catch {
|
|
177169
177235
|
}
|
|
177236
|
+
};
|
|
177237
|
+
if (modelHost !== void 0 && reply5.statusCode !== void 0) {
|
|
177238
|
+
const host = modelHost, status4 = reply5.statusCode;
|
|
177239
|
+
if (!MODEL_REFUSALS.has(status4)) observe2(host, status4);
|
|
177240
|
+
else {
|
|
177241
|
+
const chunks2 = [];
|
|
177242
|
+
let size3 = 0, told = false;
|
|
177243
|
+
const tell = () => {
|
|
177244
|
+
if (told) return;
|
|
177245
|
+
told = true;
|
|
177246
|
+
observe2(host, status4, size3 <= REFUSAL_BYTES ? refusalMessage(Buffer.concat(chunks2), reply5.headers["content-encoding"]?.toLowerCase()) : void 0);
|
|
177247
|
+
};
|
|
177248
|
+
reply5.on("data", (chunk) => {
|
|
177249
|
+
size3 += chunk.length;
|
|
177250
|
+
if (size3 <= REFUSAL_BYTES) chunks2.push(chunk);
|
|
177251
|
+
});
|
|
177252
|
+
reply5.once("end", tell);
|
|
177253
|
+
reply5.once("close", tell);
|
|
177254
|
+
}
|
|
177170
177255
|
}
|
|
177171
177256
|
if (reply5.statusCode && reply5.statusCode >= 300 && reply5.statusCode < 400) {
|
|
177172
177257
|
reply5.destroy();
|
|
@@ -177278,12 +177363,14 @@ async function startIsolationGateway(options4) {
|
|
|
177278
177363
|
return mapped(exposedOrigin);
|
|
177279
177364
|
}, close };
|
|
177280
177365
|
}
|
|
177281
|
-
var BODY_LIMIT, HOP_HEADERS;
|
|
177366
|
+
var BODY_LIMIT, HOP_HEADERS, MODEL_REFUSALS, REFUSAL_BYTES;
|
|
177282
177367
|
var init_gateway = __esm({
|
|
177283
177368
|
"backend/src/execution/gateway.ts"() {
|
|
177284
177369
|
"use strict";
|
|
177285
177370
|
BODY_LIMIT = 8 * 1024 * 1024;
|
|
177286
177371
|
HOP_HEADERS = /* @__PURE__ */ new Set(["connection", "proxy-connection", "proxy-authenticate", "proxy-authorization", "keep-alive", "te", "trailer", "transfer-encoding", "upgrade"]);
|
|
177372
|
+
MODEL_REFUSALS = /* @__PURE__ */ new Set([401, 402, 403, 429]);
|
|
177373
|
+
REFUSAL_BYTES = 4096;
|
|
177287
177374
|
}
|
|
177288
177375
|
});
|
|
177289
177376
|
|
|
@@ -177587,7 +177674,7 @@ var init_agent_env = __esm({
|
|
|
177587
177674
|
import { createHash as createHash53 } from "node:crypto";
|
|
177588
177675
|
import { readdir, readFile as readFile3 } from "node:fs/promises";
|
|
177589
177676
|
import { join as join4 } from "node:path";
|
|
177590
|
-
import { gunzipSync, gzipSync } from "node:zlib";
|
|
177677
|
+
import { gunzipSync as gunzipSync2, gzipSync } from "node:zlib";
|
|
177591
177678
|
function bundleSource(env) {
|
|
177592
177679
|
return env.CI === "true" || env.GITHUB_ACTIONS ? "ci" : "cli";
|
|
177593
177680
|
}
|
|
@@ -204027,38 +204114,38 @@ function withoutScriptBanners(lines) {
|
|
|
204027
204114
|
if (end > start && YARN_DONE.test(lines[end - 1].trim())) end--;
|
|
204028
204115
|
return lines.slice(start, end);
|
|
204029
204116
|
}
|
|
204030
|
-
function
|
|
204031
|
-
|
|
204032
|
-
const blank = lines.findLastIndex((line2) => line2.trim() === "");
|
|
204033
|
-
let block2 = (blank >= 0 ? lines.slice(blank + 1) : lines.slice(-ANSWER_MAX_LINES)).join("\n");
|
|
204034
|
-
if (Buffer.byteLength(block2) > ANSWER_MAX_BYTES) {
|
|
204035
|
-
const bytes2 = Buffer.from(block2);
|
|
204036
|
-
let end = bytes2.subarray(bytes2.length - ANSWER_MAX_BYTES).toString("utf8").replace(/^�+/, "");
|
|
204037
|
-
const line2 = end.indexOf("\n");
|
|
204038
|
-
if (line2 >= 0 && line2 < end.length - 1) end = end.slice(line2 + 1);
|
|
204039
|
-
block2 = end;
|
|
204040
|
-
}
|
|
204041
|
-
return block2.replace(/^\s*\n/, "").trimEnd();
|
|
204117
|
+
function stdoutAnswer(stdout) {
|
|
204118
|
+
return withoutScriptBanners(stdout.replace(ANSI, "").replace(/\r\n?/g, "\n").trimEnd().split("\n")).join("\n").trimEnd();
|
|
204042
204119
|
}
|
|
204043
|
-
var
|
|
204120
|
+
var ANSWER_MAX_CHARS, STDOUT_MAX_CHARS, OutputTail, ModelReplies, ANSI, NPM_SCRIPT, NPM_COMMAND, YARN_RUN, YARN_COMMAND, YARN_DONE;
|
|
204044
204121
|
var init_agent_output = __esm({
|
|
204045
204122
|
"backend/src/runner/agent-output.ts"() {
|
|
204046
204123
|
"use strict";
|
|
204047
|
-
|
|
204048
|
-
|
|
204049
|
-
|
|
204124
|
+
init_gateway();
|
|
204125
|
+
ANSWER_MAX_CHARS = 64 * 1024;
|
|
204126
|
+
STDOUT_MAX_CHARS = 2 * ANSWER_MAX_CHARS;
|
|
204050
204127
|
OutputTail = class {
|
|
204128
|
+
max;
|
|
204051
204129
|
#text = "";
|
|
204052
204130
|
#cut = false;
|
|
204131
|
+
#length = 0;
|
|
204132
|
+
constructor(max = STDOUT_MAX_CHARS) {
|
|
204133
|
+
this.max = max;
|
|
204134
|
+
}
|
|
204053
204135
|
push(text24) {
|
|
204054
204136
|
this.#text += text24;
|
|
204055
|
-
|
|
204137
|
+
this.#length += text24.length;
|
|
204138
|
+
if (this.#text.length > this.max * 2) this.#trim();
|
|
204056
204139
|
}
|
|
204057
204140
|
#trim() {
|
|
204058
|
-
if (this.#text.length <=
|
|
204059
|
-
this.#text = this.#text.slice(-
|
|
204141
|
+
if (this.#text.length <= this.max) return;
|
|
204142
|
+
this.#text = this.#text.slice(-this.max);
|
|
204060
204143
|
this.#cut = true;
|
|
204061
204144
|
}
|
|
204145
|
+
/** How many characters were pushed in all. */
|
|
204146
|
+
length() {
|
|
204147
|
+
return this.#length;
|
|
204148
|
+
}
|
|
204062
204149
|
/** What was kept; a first line cut in the middle is left out. */
|
|
204063
204150
|
text() {
|
|
204064
204151
|
this.#trim();
|
|
@@ -204067,15 +204154,23 @@ var init_agent_output = __esm({
|
|
|
204067
204154
|
};
|
|
204068
204155
|
ModelReplies = class {
|
|
204069
204156
|
#counts = /* @__PURE__ */ new Map();
|
|
204070
|
-
|
|
204157
|
+
#last;
|
|
204158
|
+
add(host, status4, message7) {
|
|
204071
204159
|
const key4 = `${host} ${status4}`;
|
|
204072
204160
|
const reply5 = this.#counts.get(key4);
|
|
204073
|
-
if (reply5)
|
|
204074
|
-
|
|
204161
|
+
if (reply5) {
|
|
204162
|
+
reply5.count++;
|
|
204163
|
+
if (message7 !== void 0) reply5.message ??= message7;
|
|
204164
|
+
} else if (this.#counts.size < 100) this.#counts.set(key4, { host, status: status4, count: 1, ...message7 !== void 0 && { message: message7 } });
|
|
204165
|
+
this.#last = { host, status: status4, ...message7 !== void 0 && { message: message7 } };
|
|
204075
204166
|
}
|
|
204076
204167
|
list() {
|
|
204077
204168
|
return [...this.#counts.values()].map((reply5) => ({ ...reply5 }));
|
|
204078
204169
|
}
|
|
204170
|
+
/** The last reply, when it refused the key: the provider stopped the agent there. */
|
|
204171
|
+
refusal() {
|
|
204172
|
+
return this.#last !== void 0 && MODEL_REFUSALS.has(this.#last.status) ? { ...this.#last } : void 0;
|
|
204173
|
+
}
|
|
204079
204174
|
};
|
|
204080
204175
|
ANSI = /\x1b\[[0-9;?]*[ -/]*[@-~]/g;
|
|
204081
204176
|
NPM_SCRIPT = /^> (?:\S+@\S* )?[\w:.-]+(?: \/\S*)?$/;
|
|
@@ -204161,7 +204256,7 @@ function outputCopy(logFd) {
|
|
|
204161
204256
|
closeSync2(stderr.fd);
|
|
204162
204257
|
}
|
|
204163
204258
|
},
|
|
204164
|
-
|
|
204259
|
+
output: () => ({ stdout: tail.text(), printed: tail.length() })
|
|
204165
204260
|
};
|
|
204166
204261
|
}
|
|
204167
204262
|
function startAgentProcess(command, opts) {
|
|
@@ -204218,7 +204313,7 @@ function startAgentProcess(command, opts) {
|
|
|
204218
204313
|
return { pid, exited, async stop() {
|
|
204219
204314
|
terminate();
|
|
204220
204315
|
await exited;
|
|
204221
|
-
}, ...stdout && { output:
|
|
204316
|
+
}, ...stdout && { output: stdout.output } };
|
|
204222
204317
|
}
|
|
204223
204318
|
var KILL_GRACE_MS, GROUP_POLL_MS, COPY_MS;
|
|
204224
204319
|
var init_process = __esm({
|
|
@@ -205013,7 +205108,7 @@ async function startContainedAgent(command, opts) {
|
|
|
205013
205108
|
]);
|
|
205014
205109
|
await run4(["start", relayName]);
|
|
205015
205110
|
const replies = new ModelReplies();
|
|
205016
|
-
gateway = await startIsolationGateway({ env: opts.env, session: opts.session, modelHosts: policy.modelHosts, onModelReply: (host, status5) => replies.add(host, status5) });
|
|
205111
|
+
gateway = await startIsolationGateway({ env: opts.env, session: opts.session, modelHosts: policy.modelHosts, onModelReply: (host, status5, message7) => replies.add(host, status5, message7) });
|
|
205017
205112
|
const script = isolationRelayScript({ port: RELAY_PORT, ...opts.runtime?.port && { agentPort: opts.runtime.port } });
|
|
205018
205113
|
relayChild = spawn2("docker", ["--context", context3, "exec", "-i", relayName, "node", "-e", script], { env: dockerEnvironment(), stdio: ["pipe", "pipe", "pipe"] });
|
|
205019
205114
|
relayChild.stderr.on("data", () => {
|
|
@@ -205105,7 +205200,7 @@ async function startContainedAgent(command, opts) {
|
|
|
205105
205200
|
return { pid: child2.pid, exited, async stop() {
|
|
205106
205201
|
await cleanup();
|
|
205107
205202
|
await exited;
|
|
205108
|
-
}, output: () => ({ stdout: tail.text(), modelReplies: replies.list() }) };
|
|
205203
|
+
}, output: () => ({ stdout: tail.text(), printed: tail.length(), modelReplies: replies.list(), modelRefusal: replies.refusal() }) };
|
|
205109
205204
|
} catch (error64) {
|
|
205110
205205
|
opts.signal?.removeEventListener("abort", abort);
|
|
205111
205206
|
await cleanup();
|
|
@@ -205291,7 +205386,7 @@ async function startVmAgent(command, opts, deps = {}) {
|
|
|
205291
205386
|
...opts.session && { session: opts.session },
|
|
205292
205387
|
modelHosts,
|
|
205293
205388
|
port: unsafe ? 0 : 18991,
|
|
205294
|
-
onModelReply: (host, status4) => replies.add(host, status4)
|
|
205389
|
+
onModelReply: (host, status4, message7) => replies.add(host, status4, message7)
|
|
205295
205390
|
});
|
|
205296
205391
|
const mapped = gateway.rewrite(unsafe ? gateway.url : VM_GATEWAY_ORIGIN);
|
|
205297
205392
|
const agentRuntime = { ...opts.runtime, ...taskFile !== void 0 && { taskFile }, ...opts.runtime?.attempt && { attempt: { ...opts.runtime.attempt, stateDir: paths2.state, records: records3 } } };
|
|
@@ -205413,7 +205508,7 @@ async function startVmAgent(command, opts, deps = {}) {
|
|
|
205413
205508
|
return { pid: child2.pid, exited, async stop() {
|
|
205414
205509
|
await cleanup();
|
|
205415
205510
|
await exited;
|
|
205416
|
-
}, output: () => ({ stdout: tail.text(), modelReplies: replies.list() }) };
|
|
205511
|
+
}, output: () => ({ stdout: tail.text(), printed: tail.length(), modelReplies: replies.list(), modelRefusal: replies.refusal() }) };
|
|
205417
205512
|
} catch (error64) {
|
|
205418
205513
|
await cleanup();
|
|
205419
205514
|
throw error64;
|
|
@@ -206212,6 +206307,34 @@ var init_per_event = __esm({
|
|
|
206212
206307
|
}
|
|
206213
206308
|
});
|
|
206214
206309
|
|
|
206310
|
+
// backend/src/agent-outcome.ts
|
|
206311
|
+
function modelKeyName(host, given2) {
|
|
206312
|
+
const [pattern, usual] = PROVIDER_KEYS[host] ?? [/(?!)/, "NAME"];
|
|
206313
|
+
return given2.find((name5) => pattern.test(name5) && /KEY|TOKEN/.test(name5)) ?? usual;
|
|
206314
|
+
}
|
|
206315
|
+
var PROVIDER_KEYS;
|
|
206316
|
+
var init_agent_outcome = __esm({
|
|
206317
|
+
"backend/src/agent-outcome.ts"() {
|
|
206318
|
+
"use strict";
|
|
206319
|
+
init_src();
|
|
206320
|
+
init_agent_fix();
|
|
206321
|
+
init_gateway();
|
|
206322
|
+
PROVIDER_KEYS = {
|
|
206323
|
+
"api.anthropic.com": [/ANTHROPIC|CLAUDE/, "ANTHROPIC_API_KEY"],
|
|
206324
|
+
"api.openai.com": [/OPENAI/, "OPENAI_API_KEY"],
|
|
206325
|
+
"openrouter.ai": [/OPENROUTER/, "OPENROUTER_API_KEY"],
|
|
206326
|
+
"generativelanguage.googleapis.com": [/GEMINI|GOOGLE/, "GEMINI_API_KEY"],
|
|
206327
|
+
"api.groq.com": [/GROQ/, "GROQ_API_KEY"],
|
|
206328
|
+
"api.mistral.ai": [/MISTRAL/, "MISTRAL_API_KEY"],
|
|
206329
|
+
"api.together.xyz": [/TOGETHER/, "TOGETHER_API_KEY"],
|
|
206330
|
+
"api.fireworks.ai": [/FIREWORKS/, "FIREWORKS_API_KEY"],
|
|
206331
|
+
"api.deepseek.com": [/DEEPSEEK/, "DEEPSEEK_API_KEY"],
|
|
206332
|
+
"api.x.ai": [/XAI|GROK/, "XAI_API_KEY"],
|
|
206333
|
+
"api.cohere.com": [/COHERE|CO_API/, "COHERE_API_KEY"]
|
|
206334
|
+
};
|
|
206335
|
+
}
|
|
206336
|
+
});
|
|
206337
|
+
|
|
206215
206338
|
// backend/src/runner/trial.ts
|
|
206216
206339
|
import { setTimeout as sleep8 } from "node:timers/promises";
|
|
206217
206340
|
import { closeSync as closeSync6, openSync as openSync6, writeSync as writeSync6 } from "node:fs";
|
|
@@ -206221,16 +206344,29 @@ function answersFrom(agent, source) {
|
|
|
206221
206344
|
const mode = agent.answer ?? "auto";
|
|
206222
206345
|
return mode === "auto" || mode === "stdout" && source === "stdout";
|
|
206223
206346
|
}
|
|
206224
|
-
async function recordAnswer(backend, envId, sessionId, output2, source) {
|
|
206225
|
-
if (output2.trim() === "" || backend.recordAnswer === void 0) return void 0;
|
|
206347
|
+
async function recordAnswer(backend, envId, sessionId, output2, source, printed) {
|
|
206348
|
+
if (output2.trim() === "" && printed === void 0 || backend.recordAnswer === void 0) return void 0;
|
|
206226
206349
|
try {
|
|
206227
|
-
await backend.recordAnswer(envId, sessionId, { output: output2, source });
|
|
206350
|
+
await backend.recordAnswer(envId, sessionId, { output: output2, source, ...printed !== void 0 && { printed } });
|
|
206228
206351
|
return void 0;
|
|
206229
206352
|
} catch (error64) {
|
|
206230
206353
|
if (unknownRoute18(error64)) return void 0;
|
|
206231
206354
|
return { kind: "world", owner: "harness", service: "agent", message: `the agent's answer from its ${source === "reply" ? "reply" : "stdout"} could not be recorded: ${error64 instanceof Error ? error64.message : String(error64)}` };
|
|
206232
206355
|
}
|
|
206233
206356
|
}
|
|
206357
|
+
function modelKeyIssue(refusal, given2) {
|
|
206358
|
+
return {
|
|
206359
|
+
kind: "model",
|
|
206360
|
+
owner: "harness",
|
|
206361
|
+
service: refusal.host,
|
|
206362
|
+
code: "MODEL_KEY_REFUSED",
|
|
206363
|
+
message: `${refusal.host} refused the agent's model key (${refusal.status}${refusal.message ? `: ${refusal.message}` : ""}), so the attempt tested nothing. Give the agent a working ${modelKeyName(refusal.host, given2)} and run again.`
|
|
206364
|
+
};
|
|
206365
|
+
}
|
|
206366
|
+
function recordStdout(backend, envId, sessionId, output2) {
|
|
206367
|
+
const answer = stdoutAnswer(output2?.stdout ?? ""), printed = output2?.printed ?? output2?.stdout.length ?? 0;
|
|
206368
|
+
return printed > STDOUT_MAX_CHARS || answer.length > ANSWER_MAX_CHARS ? recordAnswer(backend, envId, sessionId, "", "stdout", printed) : recordAnswer(backend, envId, sessionId, answer, "stdout");
|
|
206369
|
+
}
|
|
206234
206370
|
async function runTrial(spec) {
|
|
206235
206371
|
const { backend, env, scene: scene2, trial, dir, signal, inheritedEnv = process.env } = spec;
|
|
206236
206372
|
const agent = scene2.agent_input && spec.agent.mode !== "endpoint" ? { ...spec.agent, taskInput: sceneTaskInput(scene2, spec.agent.taskInput) } : spec.agent;
|
|
@@ -206325,7 +206461,7 @@ async function runTrial(spec) {
|
|
|
206325
206461
|
const playOutIssues = [];
|
|
206326
206462
|
const ended = exit === "timeout" || exit === "done" || exit === "exited" && exitCode === 0;
|
|
206327
206463
|
if (ended && failure5 === void 0 && !signal?.aborted && answersFrom(agent, "stdout")) {
|
|
206328
|
-
const issue6 = await
|
|
206464
|
+
const issue6 = await recordStdout(backend, env.id, session2.id, output2);
|
|
206329
206465
|
if (issue6 !== void 0) playOutIssues.push(issue6);
|
|
206330
206466
|
}
|
|
206331
206467
|
let playOut;
|
|
@@ -206338,6 +206474,7 @@ async function runTrial(spec) {
|
|
|
206338
206474
|
}
|
|
206339
206475
|
const capture3 = await captureTrialAfterFailure(failure5, backend, env.id, session2.id, dir, scene2, { ...spec.judge, ...signal !== void 0 && { signal } }, void 0, spec.onCaptured);
|
|
206340
206476
|
const { checks: checks2, trace, simMs } = capture3, harnessIssues = [...capture3.harnessIssues, ...playOutIssues];
|
|
206477
|
+
if (output2?.modelRefusal !== void 0) harnessIssues.push(modelKeyIssue(output2.modelRefusal, Object.keys(agent.env ?? {})));
|
|
206341
206478
|
if (failure5 !== void 0) throw failure5.error;
|
|
206342
206479
|
signal?.throwIfAborted();
|
|
206343
206480
|
return {
|
|
@@ -206377,6 +206514,7 @@ var init_trial = __esm({
|
|
|
206377
206514
|
init_per_event();
|
|
206378
206515
|
init_budget();
|
|
206379
206516
|
init_agent_output();
|
|
206517
|
+
init_agent_outcome();
|
|
206380
206518
|
init_agent_env();
|
|
206381
206519
|
EXIT_COMMAND_NOT_FOUND2 = 127;
|
|
206382
206520
|
unknownRoute18 = (error64) => error64 instanceof AnchaError && error64.code === "USAGE" && error64.message.startsWith("no such route");
|
|
@@ -206843,6 +206981,14 @@ var init_baselines = __esm({
|
|
|
206843
206981
|
}
|
|
206844
206982
|
});
|
|
206845
206983
|
|
|
206984
|
+
// backend/src/kit/connection-tools.ts
|
|
206985
|
+
var init_connection_tools = __esm({
|
|
206986
|
+
"backend/src/kit/connection-tools.ts"() {
|
|
206987
|
+
"use strict";
|
|
206988
|
+
init_src();
|
|
206989
|
+
}
|
|
206990
|
+
});
|
|
206991
|
+
|
|
206846
206992
|
// packages/cli/src/runner/worker.ts
|
|
206847
206993
|
init_src();
|
|
206848
206994
|
|
|
@@ -206960,11 +207106,12 @@ init_report2();
|
|
|
206960
207106
|
|
|
206961
207107
|
// packages/cli/src/cloud-bundle.ts
|
|
206962
207108
|
init_src();
|
|
206963
|
-
init_baselines();
|
|
206964
207109
|
import { basename as basename5, resolve as resolve12 } from "node:path";
|
|
207110
|
+
init_baselines();
|
|
206965
207111
|
|
|
206966
207112
|
// backend/src/cloud/bundle.ts
|
|
206967
207113
|
init_src();
|
|
207114
|
+
init_connection_tools();
|
|
206968
207115
|
init_jobs_contract();
|
|
206969
207116
|
|
|
206970
207117
|
// backend/src/cloud/dependencies.ts
|