@withgateway/sdk 0.3.1 → 0.3.3
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/README.md +4 -3
- package/dist/cli.js +2880 -2032
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +2982 -2135
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.d.mts +1 -1
- package/dist/files/index.d.ts +1 -1
- package/dist/files/index.js +180 -41
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +172 -35
- package/dist/files/index.mjs.map +1 -1
- package/dist/{index-CBqbB_0J.d.ts → index-DUHmS74p.d.ts} +1 -1
- package/dist/{index-D-AMnAMa.d.mts → index-mJhG3vZU.d.mts} +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1309 -540
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1287 -532
- package/dist/index.mjs.map +1 -1
- package/dist/{media-CbcAfQvd.d.mts → media-BIApiPzS.d.mts} +21 -2
- package/dist/{media-CbcAfQvd.d.ts → media-BIApiPzS.d.ts} +21 -2
- package/dist/traces/index.d.mts +1 -1
- package/dist/traces/index.d.ts +1 -1
- package/dist/traces/index.js +177 -38
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +169 -32
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.d.mts +2 -2
- package/dist/tracing/index.d.ts +2 -2
- package/dist/tracing/index.js +69 -13
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +69 -13
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/worlds/index.d.mts +249 -120
- package/dist/worlds/index.d.ts +249 -120
- package/dist/worlds/index.js +1240 -484
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +1231 -476
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +1 -1
- package/runtime/gatewaysdk/environment/_bundle.py +2 -27
- package/runtime/gatewaysdk/environment/_materialize.py +49 -69
- package/runtime/gatewaysdk/environment/_world.py +122 -197
- package/runtime/gatewaysdk/environment/backing.py +137 -0
- package/runtime/gatewaysdk/environment/core.py +1 -1
- package/runtime/gatewaysdk/environment/legacy_sqlite.py +301 -0
- package/runtime/gatewaysdk/environment/reward_keys.py +25 -0
- package/runtime/gatewaysdk/environment/runtime.py +8 -13
- package/runtime/gatewaysdk/environment/schema/__init__.py +4 -4
- package/runtime/gatewaysdk/environment/schema/admin_routes.py +86 -0
- package/runtime/gatewaysdk/environment/schema/api.py +266 -514
- package/runtime/gatewaysdk/environment/schema/batch.py +42 -37
- package/runtime/gatewaysdk/environment/schema/bundle_runtime.py +17 -5
- package/runtime/gatewaysdk/environment/schema/call_log.py +291 -0
- package/runtime/gatewaysdk/environment/schema/call_redaction.py +344 -0
- package/runtime/gatewaysdk/environment/schema/compiler.py +334 -158
- package/runtime/gatewaysdk/environment/schema/conform.py +8 -12
- package/runtime/gatewaysdk/environment/schema/connector.py +27 -62
- package/runtime/gatewaysdk/environment/schema/data.py +50 -207
- package/runtime/gatewaysdk/environment/schema/database/__init__.py +24 -0
- package/runtime/gatewaysdk/environment/schema/database/audit.py +121 -0
- package/runtime/gatewaysdk/environment/schema/database/base.py +995 -0
- package/runtime/gatewaysdk/environment/schema/database/budget.py +33 -0
- package/runtime/gatewaysdk/environment/schema/database/connections.py +101 -0
- package/runtime/gatewaysdk/environment/schema/database/engines.py +8 -0
- package/runtime/gatewaysdk/environment/schema/database/guard.py +208 -0
- package/runtime/gatewaysdk/environment/schema/database/ingest.py +154 -0
- package/runtime/gatewaysdk/environment/schema/database/matching.py +58 -0
- package/runtime/gatewaysdk/environment/schema/database/provenance.py +30 -0
- package/runtime/gatewaysdk/environment/schema/database/rows.py +53 -0
- package/runtime/gatewaysdk/environment/schema/database/runtime_rows.py +39 -0
- package/runtime/gatewaysdk/environment/schema/database/sqlite.py +367 -0
- package/runtime/gatewaysdk/environment/schema/domain_migration.py +236 -0
- package/runtime/gatewaysdk/environment/schema/envelope.py +169 -0
- package/runtime/gatewaysdk/environment/schema/extract.py +6 -13
- package/runtime/gatewaysdk/environment/schema/grading.py +45 -30
- package/runtime/gatewaysdk/environment/schema/handler_errors.py +142 -12
- package/runtime/gatewaysdk/environment/schema/host.py +158 -250
- package/runtime/gatewaysdk/environment/schema/lanes.py +53 -0
- package/runtime/gatewaysdk/environment/schema/local.py +44 -71
- package/runtime/gatewaysdk/environment/schema/mapping.py +5 -25
- package/runtime/gatewaysdk/environment/schema/openapi_import.py +112 -73
- package/runtime/gatewaysdk/environment/schema/openapi_paging.py +147 -0
- package/runtime/gatewaysdk/environment/schema/openapi_payloads.py +288 -0
- package/runtime/gatewaysdk/environment/schema/openapi_routes.py +97 -102
- package/runtime/gatewaysdk/environment/schema/openapi_schemas.py +113 -30
- package/runtime/gatewaysdk/environment/schema/platform.py +123 -171
- package/runtime/gatewaysdk/environment/schema/platform_import.py +2 -3
- package/runtime/gatewaysdk/environment/schema/platform_query.py +61 -5
- package/runtime/gatewaysdk/environment/schema/primary_key.py +61 -0
- package/runtime/gatewaysdk/environment/schema/proof.py +19 -12
- package/runtime/gatewaysdk/environment/schema/runtime.py +77 -160
- package/runtime/gatewaysdk/environment/schema/served_names.py +58 -0
- package/runtime/gatewaysdk/environment/schema/session_files.py +166 -0
- package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +2 -2
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +19 -11
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/ROWS.md +29 -3
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +14 -14
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +12 -12
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +3 -2
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +15 -0
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/openapi-import.md +50 -21
- package/runtime/gatewaysdk/environment/schema/slack.py +4 -8
- package/runtime/gatewaysdk/environment/schema/snapshot.py +385 -129
- package/runtime/gatewaysdk/environment/schema/store_contract.py +8 -14
- package/runtime/gatewaysdk/environment/schema/tasks.py +140 -55
- package/runtime/gatewaysdk/environment/schema/tools_world.py +110 -87
- package/runtime/gatewaysdk/environment/schema/ui.py +24 -5
- package/runtime/gatewaysdk/environment/schema/ui_static/app.js +100 -130
- package/runtime/gatewaysdk/environment/schema/ui_static/index.html +1 -8
- package/runtime/gatewaysdk/environment/schema/validation.py +166 -40
- package/runtime/gatewaysdk/environment/schema/workers.py +142 -57
- package/runtime/gatewaysdk/environment/schema/world_sql.py +81 -0
- package/runtime/gatewaysdk/environment/schema/world_tests.py +71 -39
- package/runtime/gatewaysdk/environment/score.py +57 -0
- package/runtime/gatewaysdk/environment/secret_values.py +36 -0
- package/runtime/gatewaysdk/environment/world.py +42 -3
- package/runtime/gatewaysdk/environment/world_session_contract.py +32 -5
- package/skills/benchmarks-getting-started/SKILL.md +2 -2
- package/skills/connector-schema-authoring/SKILL.md +19 -11
- package/skills/connector-schema-authoring/connector-worlds.md +13 -4
- package/skills/connector-schema-authoring/world-schema.md +103 -51
- package/skills/world-data-ingestion/ROWS.md +29 -3
- package/skills/world-data-ingestion/SKILL.md +14 -14
- package/skills/worlds-getting-started/SKILL.md +12 -12
- package/skills/worlds-getting-started/references/cli-mcp-map.md +3 -2
- package/skills/worlds-getting-started/references/gotchas.md +15 -0
- package/skills/worlds-getting-started/references/openapi-import.md +50 -21
- package/runtime/gatewaysdk/environment/schema/store.py +0 -1013
package/dist/index.js
CHANGED
|
@@ -204,10 +204,10 @@ var init_users = __esm({
|
|
|
204
204
|
totalItems: Number(meta.totalItems ?? rows.length)
|
|
205
205
|
};
|
|
206
206
|
}
|
|
207
|
-
async requestJson(method,
|
|
207
|
+
async requestJson(method, path17, payload) {
|
|
208
208
|
let response;
|
|
209
209
|
try {
|
|
210
|
-
response = await fetch(`${this.host}${
|
|
210
|
+
response = await fetch(`${this.host}${path17}`, {
|
|
211
211
|
method,
|
|
212
212
|
headers: {
|
|
213
213
|
Authorization: this.authHeader(),
|
|
@@ -218,17 +218,17 @@ var init_users = __esm({
|
|
|
218
218
|
});
|
|
219
219
|
} catch (error) {
|
|
220
220
|
throw new UserProfileError(
|
|
221
|
-
`${method} ${
|
|
221
|
+
`${method} ${path17} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
222
222
|
{ cause: error }
|
|
223
223
|
);
|
|
224
224
|
}
|
|
225
225
|
const text2 = await response.text();
|
|
226
226
|
if (!response.ok) {
|
|
227
227
|
throw new UserProfileError(
|
|
228
|
-
`${method} ${
|
|
228
|
+
`${method} ${path17} failed (${response.status}): ${text2.slice(0, 500)}`
|
|
229
229
|
);
|
|
230
230
|
}
|
|
231
|
-
this.log("%s %s -> %s", method,
|
|
231
|
+
this.log("%s %s -> %s", method, path17, response.status);
|
|
232
232
|
return safeJson4(text2);
|
|
233
233
|
}
|
|
234
234
|
authHeader() {
|
|
@@ -417,10 +417,10 @@ var init_scores = __esm({
|
|
|
417
417
|
metadata: signalMetadata
|
|
418
418
|
});
|
|
419
419
|
}
|
|
420
|
-
async request(method,
|
|
420
|
+
async request(method, path17, payload) {
|
|
421
421
|
let response;
|
|
422
422
|
try {
|
|
423
|
-
response = await fetch(`${this.host}${
|
|
423
|
+
response = await fetch(`${this.host}${path17}`, {
|
|
424
424
|
method,
|
|
425
425
|
headers: {
|
|
426
426
|
Authorization: this.authHeader(),
|
|
@@ -431,17 +431,17 @@ var init_scores = __esm({
|
|
|
431
431
|
});
|
|
432
432
|
} catch (error) {
|
|
433
433
|
throw new ScoreError(
|
|
434
|
-
`${method} ${
|
|
434
|
+
`${method} ${path17} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
435
435
|
{ cause: error }
|
|
436
436
|
);
|
|
437
437
|
}
|
|
438
438
|
const text2 = await response.text();
|
|
439
439
|
if (!response.ok) {
|
|
440
440
|
throw new ScoreError(
|
|
441
|
-
`${method} ${
|
|
441
|
+
`${method} ${path17} failed (${response.status}): ${text2.slice(0, 500)}`
|
|
442
442
|
);
|
|
443
443
|
}
|
|
444
|
-
this.log("%s %s -> %s", method,
|
|
444
|
+
this.log("%s %s -> %s", method, path17, response.status);
|
|
445
445
|
}
|
|
446
446
|
authHeader() {
|
|
447
447
|
return `Basic ${Buffer.from(`${this.publicKey}:${this.secretKey}`).toString(
|
|
@@ -464,6 +464,28 @@ var init_scores = __esm({
|
|
|
464
464
|
}
|
|
465
465
|
});
|
|
466
466
|
|
|
467
|
+
// src/worlds/platformEndpoint.ts
|
|
468
|
+
function platformEndpoint(options) {
|
|
469
|
+
const publicKey = options.publicKey ?? process.env.GATEWAY_PUBLIC_KEY;
|
|
470
|
+
const secretKey = options.secretKey ?? process.env.GATEWAY_SECRET_KEY;
|
|
471
|
+
if (!publicKey || !secretKey) return null;
|
|
472
|
+
const host = options.host ?? process.env.GATEWAY_HOST ?? DEFAULT_HOST;
|
|
473
|
+
return { host: host.replace(/\/+$/, ""), publicKey, secretKey };
|
|
474
|
+
}
|
|
475
|
+
function requirePlatformEndpoint(options) {
|
|
476
|
+
const endpoint = platformEndpoint(options);
|
|
477
|
+
if (!endpoint) throw new Error(GATEWAY_KEYS_MISSING);
|
|
478
|
+
return endpoint;
|
|
479
|
+
}
|
|
480
|
+
var DEFAULT_HOST, GATEWAY_KEYS_MISSING;
|
|
481
|
+
var init_platformEndpoint = __esm({
|
|
482
|
+
"src/worlds/platformEndpoint.ts"() {
|
|
483
|
+
"use strict";
|
|
484
|
+
DEFAULT_HOST = "https://withgateway.ai";
|
|
485
|
+
GATEWAY_KEYS_MISSING = "Gateway keys missing: set GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY (or pass publicKey/secretKey).";
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
|
|
467
489
|
// src/worlds/transport.ts
|
|
468
490
|
function platformTimeoutMs(env = process.env) {
|
|
469
491
|
const raw = env[PLATFORM_TIMEOUT_ENV];
|
|
@@ -472,7 +494,7 @@ function platformTimeoutMs(env = process.env) {
|
|
|
472
494
|
if (Number.isInteger(value) && value > 0) return value;
|
|
473
495
|
throw new Error(`${PLATFORM_TIMEOUT_ENV} must be a positive whole number of milliseconds, not \`${raw}\`.`);
|
|
474
496
|
}
|
|
475
|
-
var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, PlatformTransport;
|
|
497
|
+
var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, sleep2, RetryPolicy, Attempt, PlatformTransport;
|
|
476
498
|
var init_transport = __esm({
|
|
477
499
|
"src/worlds/transport.ts"() {
|
|
478
500
|
"use strict";
|
|
@@ -534,6 +556,56 @@ var init_transport = __esm({
|
|
|
534
556
|
route;
|
|
535
557
|
failure;
|
|
536
558
|
};
|
|
559
|
+
sleep2 = (ms) => new Promise((resolve11) => setTimeout(resolve11, ms));
|
|
560
|
+
RetryPolicy = class _RetryPolicy {
|
|
561
|
+
constructor(delaysMs, wait = sleep2, budgetMs = Number.POSITIVE_INFINITY, now = Date.now) {
|
|
562
|
+
this.delaysMs = delaysMs;
|
|
563
|
+
this.wait = wait;
|
|
564
|
+
this.budgetMs = budgetMs;
|
|
565
|
+
this.now = now;
|
|
566
|
+
}
|
|
567
|
+
delaysMs;
|
|
568
|
+
wait;
|
|
569
|
+
budgetMs;
|
|
570
|
+
now;
|
|
571
|
+
static NONE = new _RetryPolicy([]);
|
|
572
|
+
/** A platform restart or a short edge outage: no wait starts that would end past five minutes, so a step ends
|
|
573
|
+
* within the budget plus one request timeout. */
|
|
574
|
+
static FILING = new _RetryPolicy([250, 500, 1e3, 2e3, 4e3, 8e3, 16e3, 3e4], sleep2, 3e5);
|
|
575
|
+
static TRANSIENT_STATUSES = /* @__PURE__ */ new Set([502, 503, 504]);
|
|
576
|
+
async run(attempt) {
|
|
577
|
+
const started = this.now();
|
|
578
|
+
for (let tries = 0; ; tries += 1) {
|
|
579
|
+
const outcome = await Attempt.of(attempt);
|
|
580
|
+
const delayMs = this.delaysMs[tries];
|
|
581
|
+
const spent = delayMs === void 0 || this.now() - started + delayMs >= this.budgetMs;
|
|
582
|
+
if (!outcome.transient || spent) return outcome.settle();
|
|
583
|
+
await this.wait(delayMs);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
Attempt = class _Attempt {
|
|
588
|
+
constructor(reply, error, transient) {
|
|
589
|
+
this.reply = reply;
|
|
590
|
+
this.error = error;
|
|
591
|
+
this.transient = transient;
|
|
592
|
+
}
|
|
593
|
+
reply;
|
|
594
|
+
error;
|
|
595
|
+
transient;
|
|
596
|
+
static async of(attempt) {
|
|
597
|
+
try {
|
|
598
|
+
const reply = await attempt();
|
|
599
|
+
return new _Attempt(reply, null, RetryPolicy.TRANSIENT_STATUSES.has(reply.status));
|
|
600
|
+
} catch (error) {
|
|
601
|
+
return new _Attempt(null, error, error instanceof UnreachableError);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
settle() {
|
|
605
|
+
if (this.reply) return this.reply;
|
|
606
|
+
throw this.error;
|
|
607
|
+
}
|
|
608
|
+
};
|
|
537
609
|
PlatformTransport = class {
|
|
538
610
|
constructor(endpoint, timeoutMs = platformTimeoutMs()) {
|
|
539
611
|
this.endpoint = endpoint;
|
|
@@ -547,6 +619,9 @@ var init_transport = __esm({
|
|
|
547
619
|
}
|
|
548
620
|
async send(method, route, body, opts = {}) {
|
|
549
621
|
const timeoutMs = this.budget(opts.timeoutMs);
|
|
622
|
+
return (opts.retry ?? RetryPolicy.NONE).run(() => this.once(method, route, body, timeoutMs));
|
|
623
|
+
}
|
|
624
|
+
async once(method, route, body, timeoutMs) {
|
|
550
625
|
const payload = body === void 0 ? {} : { body: JSON.stringify(body) };
|
|
551
626
|
const controller = new AbortController();
|
|
552
627
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
@@ -740,9 +815,9 @@ function surfaceKinds(s) {
|
|
|
740
815
|
if (s.browser) kinds.push("browser");
|
|
741
816
|
return kinds;
|
|
742
817
|
}
|
|
743
|
-
function uiUrl(ui,
|
|
818
|
+
function uiUrl(ui, path17) {
|
|
744
819
|
const base = ui.url.replace(/\/+$/, "");
|
|
745
|
-
const rel =
|
|
820
|
+
const rel = path17.startsWith("/") ? path17 : `/${path17}`;
|
|
746
821
|
if (!ui.token) return base + rel;
|
|
747
822
|
const [beforeHash, hash] = splitHash(rel);
|
|
748
823
|
const joiner = beforeHash.includes("?") ? "&" : "?";
|
|
@@ -983,7 +1058,7 @@ var init_browser = __esm({
|
|
|
983
1058
|
}
|
|
984
1059
|
async send(batch) {
|
|
985
1060
|
const retries = this.opts.maxRetries ?? EVENT_MAX_RETRIES;
|
|
986
|
-
const
|
|
1061
|
+
const sleep5 = this.opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
987
1062
|
for (let attempt = 0; attempt < retries; attempt++) {
|
|
988
1063
|
try {
|
|
989
1064
|
const base = await this.resolveBase();
|
|
@@ -1000,7 +1075,7 @@ var init_browser = __esm({
|
|
|
1000
1075
|
);
|
|
1001
1076
|
return;
|
|
1002
1077
|
}
|
|
1003
|
-
await
|
|
1078
|
+
await sleep5(500 * 2 ** attempt);
|
|
1004
1079
|
}
|
|
1005
1080
|
}
|
|
1006
1081
|
}
|
|
@@ -1637,13 +1712,13 @@ var init_screen = __esm({
|
|
|
1637
1712
|
});
|
|
1638
1713
|
}
|
|
1639
1714
|
async drag(action) {
|
|
1640
|
-
const
|
|
1641
|
-
if (
|
|
1715
|
+
const path17 = action.args.path ?? [];
|
|
1716
|
+
if (path17.length < 2) throw new Error("a drag needs at least two points");
|
|
1642
1717
|
return this.held(action.args.modifiers ?? [], async () => {
|
|
1643
|
-
await this.moveTo(
|
|
1718
|
+
await this.moveTo(path17[0]);
|
|
1644
1719
|
await this.page.mouse.down({ button: "left" });
|
|
1645
1720
|
try {
|
|
1646
|
-
for (const point2 of
|
|
1721
|
+
for (const point2 of path17.slice(1)) await this.moveTo(point2, DRAG_STEPS);
|
|
1647
1722
|
} finally {
|
|
1648
1723
|
await this.page.mouse.up({ button: "left" });
|
|
1649
1724
|
}
|
|
@@ -1734,7 +1809,7 @@ var init_media = __esm({
|
|
|
1734
1809
|
put;
|
|
1735
1810
|
maxBytes;
|
|
1736
1811
|
/** The uploader for `GATEWAY_HOST` / `GATEWAY_PUBLIC_KEY` /
|
|
1737
|
-
* `GATEWAY_SECRET_KEY`
|
|
1812
|
+
* `GATEWAY_SECRET_KEY` only; null when any is unset, so a run traced with a saved login uploads none. */
|
|
1738
1813
|
static fromEnv(env = process.env) {
|
|
1739
1814
|
const host = env.GATEWAY_HOST;
|
|
1740
1815
|
const publicKey = env.GATEWAY_PUBLIC_KEY;
|
|
@@ -2604,7 +2679,7 @@ function idleWarning(idleExpiresAt, now = /* @__PURE__ */ new Date()) {
|
|
|
2604
2679
|
const minutes = Math.max(0, Math.floor(leftMs / 6e4));
|
|
2605
2680
|
return `warning: session expires in ${minutes}m (idle TTL); call a tool to extend it or \`gateway worlds session pin\` to keep it`;
|
|
2606
2681
|
}
|
|
2607
|
-
var CALL_BODY_LIMIT_BYTES, CALL_BODY_LIMIT_LABEL, IDLE_WARNING_MINUTES, EXPLORATORY_TASK, EXPLORATORY_TASK_SOURCE, NO_GRADER_REASON, WorldCallTooLarge;
|
|
2682
|
+
var CALL_BODY_LIMIT_BYTES, CALL_BODY_LIMIT_LABEL, IDLE_WARNING_MINUTES, EXPLORATORY_TASK, EXPLORATORY_TASK_SOURCE, NO_GRADER_REASON, WorldCallTooLarge, stillStartingHint;
|
|
2608
2683
|
var init_sessionContract = __esm({
|
|
2609
2684
|
"src/worlds/sessionContract.ts"() {
|
|
2610
2685
|
"use strict";
|
|
@@ -2640,6 +2715,65 @@ var init_sessionContract = __esm({
|
|
|
2640
2715
|
};
|
|
2641
2716
|
}
|
|
2642
2717
|
};
|
|
2718
|
+
stillStartingHint = (sessionId) => `It keeps opening: poll \`gateway worlds session status ${sessionId}\` until ready, or end it with \`gateway worlds session close ${sessionId}\`.`;
|
|
2719
|
+
}
|
|
2720
|
+
});
|
|
2721
|
+
|
|
2722
|
+
// src/worlds/sessionReadiness.ts
|
|
2723
|
+
var READY_TIMEOUT_MS, READY_POLL_MS, sleep3, WorldSessionTimeout, WorldSessionCallError, WorldSessionOpenFailed, ENDED, SessionReadiness;
|
|
2724
|
+
var init_sessionReadiness = __esm({
|
|
2725
|
+
"src/worlds/sessionReadiness.ts"() {
|
|
2726
|
+
"use strict";
|
|
2727
|
+
READY_TIMEOUT_MS = 10 * 6e4;
|
|
2728
|
+
READY_POLL_MS = 2e3;
|
|
2729
|
+
sleep3 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
2730
|
+
WorldSessionTimeout = class extends Error {
|
|
2731
|
+
};
|
|
2732
|
+
WorldSessionCallError = class extends Error {
|
|
2733
|
+
};
|
|
2734
|
+
WorldSessionOpenFailed = class extends WorldSessionCallError {
|
|
2735
|
+
constructor(sessionId, state2, code, reason) {
|
|
2736
|
+
super(
|
|
2737
|
+
reason === null ? `World session ${sessionId} ${state2.toLowerCase()} before it was ready.` : `World session ${sessionId} failed to open: ${reason}${code ? ` (${code})` : ""}`
|
|
2738
|
+
);
|
|
2739
|
+
this.sessionId = sessionId;
|
|
2740
|
+
this.state = state2;
|
|
2741
|
+
this.code = code;
|
|
2742
|
+
this.name = "WorldSessionOpenFailed";
|
|
2743
|
+
}
|
|
2744
|
+
sessionId;
|
|
2745
|
+
state;
|
|
2746
|
+
code;
|
|
2747
|
+
};
|
|
2748
|
+
ENDED = /* @__PURE__ */ new Set(["FAILED", "STOPPED"]);
|
|
2749
|
+
SessionReadiness = class {
|
|
2750
|
+
constructor(sessionId, status) {
|
|
2751
|
+
this.sessionId = sessionId;
|
|
2752
|
+
this.status = status;
|
|
2753
|
+
}
|
|
2754
|
+
sessionId;
|
|
2755
|
+
status;
|
|
2756
|
+
async wait(timeoutMs = READY_TIMEOUT_MS) {
|
|
2757
|
+
const deadline = Date.now() + timeoutMs;
|
|
2758
|
+
for (; ; ) {
|
|
2759
|
+
const state2 = await this.status();
|
|
2760
|
+
if (state2.ready) return state2;
|
|
2761
|
+
if (ENDED.has(state2.state))
|
|
2762
|
+
throw new WorldSessionOpenFailed(
|
|
2763
|
+
this.sessionId,
|
|
2764
|
+
state2.state,
|
|
2765
|
+
state2.failure?.code ?? null,
|
|
2766
|
+
state2.failure?.message ?? null
|
|
2767
|
+
);
|
|
2768
|
+
const left = deadline - Date.now();
|
|
2769
|
+
if (left <= 0)
|
|
2770
|
+
throw new WorldSessionTimeout(
|
|
2771
|
+
`World session ${this.sessionId} still ${state2.state} after ${Math.round(timeoutMs / 1e3)}s.`
|
|
2772
|
+
);
|
|
2773
|
+
await sleep3(Math.min(READY_POLL_MS, left));
|
|
2774
|
+
}
|
|
2775
|
+
}
|
|
2776
|
+
};
|
|
2643
2777
|
}
|
|
2644
2778
|
});
|
|
2645
2779
|
|
|
@@ -2735,11 +2869,184 @@ var init_taskRef = __esm({
|
|
|
2735
2869
|
}
|
|
2736
2870
|
});
|
|
2737
2871
|
|
|
2872
|
+
// src/worlds/worldNotice.ts
|
|
2873
|
+
var TOOL_CONTRACT_UNREAD, DEPRECATION, NOTICE_KINDS, WorldNotice, WorldToolsUnread;
|
|
2874
|
+
var init_worldNotice = __esm({
|
|
2875
|
+
"src/worlds/worldNotice.ts"() {
|
|
2876
|
+
"use strict";
|
|
2877
|
+
TOOL_CONTRACT_UNREAD = "tool-contract-unread";
|
|
2878
|
+
DEPRECATION = { label: "deprecated", next: "Instead", refusesRun: false };
|
|
2879
|
+
NOTICE_KINDS = /* @__PURE__ */ new Map([
|
|
2880
|
+
[TOOL_CONTRACT_UNREAD, { label: "warning", next: "Then", refusesRun: true }]
|
|
2881
|
+
]);
|
|
2882
|
+
WorldNotice = class _WorldNotice {
|
|
2883
|
+
constructor(notice, kind) {
|
|
2884
|
+
this.notice = notice;
|
|
2885
|
+
this.kind = kind;
|
|
2886
|
+
}
|
|
2887
|
+
notice;
|
|
2888
|
+
kind;
|
|
2889
|
+
static of(notice) {
|
|
2890
|
+
return new _WorldNotice(notice, NOTICE_KINDS.get(notice.code) ?? DEPRECATION);
|
|
2891
|
+
}
|
|
2892
|
+
get refusesRun() {
|
|
2893
|
+
return this.kind.refusesRun;
|
|
2894
|
+
}
|
|
2895
|
+
line() {
|
|
2896
|
+
const { code, message, replacement } = this.notice;
|
|
2897
|
+
return `${this.kind.label} (${code}): ${message} ${this.kind.next}: ${replacement}`;
|
|
2898
|
+
}
|
|
2899
|
+
};
|
|
2900
|
+
WorldToolsUnread = class _WorldToolsUnread extends Error {
|
|
2901
|
+
constructor(world, notice) {
|
|
2902
|
+
super(
|
|
2903
|
+
`refused before the agent ran, nothing filed: world ${world} has no readable tools: ${notice.notice.message} Then: ${notice.notice.replacement}`
|
|
2904
|
+
);
|
|
2905
|
+
this.world = world;
|
|
2906
|
+
this.notice = notice;
|
|
2907
|
+
this.name = "WorldToolsUnread";
|
|
2908
|
+
this.code = notice.notice.code;
|
|
2909
|
+
}
|
|
2910
|
+
world;
|
|
2911
|
+
notice;
|
|
2912
|
+
code;
|
|
2913
|
+
static refuse(world, notices) {
|
|
2914
|
+
const refusing = notices.map((notice) => WorldNotice.of(notice)).find((notice) => notice.refusesRun);
|
|
2915
|
+
if (refusing) throw new _WorldToolsUnread(world, refusing);
|
|
2916
|
+
}
|
|
2917
|
+
};
|
|
2918
|
+
}
|
|
2919
|
+
});
|
|
2920
|
+
|
|
2921
|
+
// src/worlds/grade.ts
|
|
2922
|
+
var messageOf, Score, GradeRefused, GradePayload;
|
|
2923
|
+
var init_grade = __esm({
|
|
2924
|
+
"src/worlds/grade.ts"() {
|
|
2925
|
+
"use strict";
|
|
2926
|
+
messageOf = (error) => (error instanceof Error ? error.message || error.name : String(error)) || "Error";
|
|
2927
|
+
Score = class _Score {
|
|
2928
|
+
static RULE = "a score is a number from 0 to 1";
|
|
2929
|
+
static admits(value) {
|
|
2930
|
+
return Number.isFinite(value) && value >= 0 && value <= 1;
|
|
2931
|
+
}
|
|
2932
|
+
/** Every number among `scores` that is not a score, as `'<key>' = <value>`
|
|
2933
|
+
* and the rule, or null when all of them are. Pairs, not a map, so that no
|
|
2934
|
+
* key hides another. */
|
|
2935
|
+
static problem(scores2) {
|
|
2936
|
+
const refused = [...scores2].flatMap(
|
|
2937
|
+
([key2, value]) => typeof value === "number" && !_Score.admits(value) ? [`'${key2}' = ${String(value)}`] : []
|
|
2938
|
+
);
|
|
2939
|
+
return refused.length ? `${refused.join(", ")}; ${_Score.RULE}` : null;
|
|
2940
|
+
}
|
|
2941
|
+
};
|
|
2942
|
+
GradeRefused = class extends Error {
|
|
2943
|
+
name = "GradeRefused";
|
|
2944
|
+
};
|
|
2945
|
+
GradePayload = class _GradePayload {
|
|
2946
|
+
/** A grade payload's numbers, checked: every number in it must be a score,
|
|
2947
|
+
* and its rewards and verifiers objects by name, or the grade is refused; a
|
|
2948
|
+
* cross-world verifier's grade that breaks either rule is that verifier's
|
|
2949
|
+
* error, the way the World Host answers one that could not grade. */
|
|
2950
|
+
static read(raw) {
|
|
2951
|
+
if (!_GradePayload.objectOrAbsent(raw))
|
|
2952
|
+
throw new GradeRefused("the grade is not an object");
|
|
2953
|
+
const record = _GradePayload.record(raw);
|
|
2954
|
+
const problem = _GradePayload.problem(record) ?? _GradePayload.verifiersProblem(record.verifiers);
|
|
2955
|
+
if (problem) throw new GradeRefused(problem);
|
|
2956
|
+
const verifiers = _GradePayload.verifiers(record.verifiers);
|
|
2957
|
+
return {
|
|
2958
|
+
..._GradePayload.numbers(record),
|
|
2959
|
+
...typeof record.reason === "string" ? { reason: record.reason } : {},
|
|
2960
|
+
...typeof record.error === "string" ? { error: record.error } : {},
|
|
2961
|
+
...verifiers ? { verifiers } : {}
|
|
2962
|
+
};
|
|
2963
|
+
}
|
|
2964
|
+
/** A world whose grade call failed (the platform refused it, the host had
|
|
2965
|
+
* lost the session): that world's error, never a score. */
|
|
2966
|
+
static failedCall(error) {
|
|
2967
|
+
return { ..._GradePayload.failed(messageOf(error)), raw: null };
|
|
2968
|
+
}
|
|
2969
|
+
static problem(record) {
|
|
2970
|
+
if (!_GradePayload.objectOrAbsent(record.rewards))
|
|
2971
|
+
return "the grade's rewards are not an object";
|
|
2972
|
+
const scores2 = Score.problem(_GradePayload.scores(record));
|
|
2973
|
+
if (scores2) return `the grade answered ${scores2}`;
|
|
2974
|
+
const twice = _GradePayload.twice(record);
|
|
2975
|
+
return twice.length ? `the grade answered ${twice.map((key2) => `'${key2}'`).join(", ")} both beside and inside rewards` : null;
|
|
2976
|
+
}
|
|
2977
|
+
static twice(record) {
|
|
2978
|
+
return Object.entries(_GradePayload.record(record.rewards)).filter(
|
|
2979
|
+
([key2, value]) => key2 !== "reward" && typeof value === "number" && typeof record[key2] === "number"
|
|
2980
|
+
).map(([key2]) => key2);
|
|
2981
|
+
}
|
|
2982
|
+
static verifiersProblem(value) {
|
|
2983
|
+
return _GradePayload.objectOrAbsent(value) ? null : "the grade's verifiers are not an object";
|
|
2984
|
+
}
|
|
2985
|
+
static scores(record) {
|
|
2986
|
+
return [
|
|
2987
|
+
["reward", record.reward],
|
|
2988
|
+
...Object.entries(_GradePayload.record(record.rewards)),
|
|
2989
|
+
...Object.entries(record).filter(
|
|
2990
|
+
([key2]) => key2 !== "reward" && key2 !== "rewards"
|
|
2991
|
+
)
|
|
2992
|
+
];
|
|
2993
|
+
}
|
|
2994
|
+
static isRecord(value) {
|
|
2995
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2996
|
+
}
|
|
2997
|
+
static objectOrAbsent(value) {
|
|
2998
|
+
return value === void 0 || value === null || _GradePayload.isRecord(value);
|
|
2999
|
+
}
|
|
3000
|
+
static record(value) {
|
|
3001
|
+
return _GradePayload.isRecord(value) ? value : {};
|
|
3002
|
+
}
|
|
3003
|
+
/** `reward`, and every numeric key under `rewards` (the host's shape) or at
|
|
3004
|
+
* the top level (a bundled verifier's). */
|
|
3005
|
+
static numbers(record) {
|
|
3006
|
+
const rewards = {};
|
|
3007
|
+
for (const [key2, value] of Object.entries(
|
|
3008
|
+
_GradePayload.record(record.rewards)
|
|
3009
|
+
))
|
|
3010
|
+
if (typeof value === "number") rewards[key2] = value;
|
|
3011
|
+
for (const [key2, value] of Object.entries(record))
|
|
3012
|
+
if (key2 !== "reward" && typeof value === "number") rewards[key2] = value;
|
|
3013
|
+
return {
|
|
3014
|
+
reward: typeof record.reward === "number" ? record.reward : null,
|
|
3015
|
+
rewards
|
|
3016
|
+
};
|
|
3017
|
+
}
|
|
3018
|
+
static verifiers(value) {
|
|
3019
|
+
if (!_GradePayload.isRecord(value)) return void 0;
|
|
3020
|
+
return Object.fromEntries(
|
|
3021
|
+
Object.entries(value).map(([name, grade]) => [
|
|
3022
|
+
name,
|
|
3023
|
+
_GradePayload.verifier(name, grade)
|
|
3024
|
+
])
|
|
3025
|
+
);
|
|
3026
|
+
}
|
|
3027
|
+
static verifier(name, grade) {
|
|
3028
|
+
if (!_GradePayload.isRecord(grade))
|
|
3029
|
+
return _GradePayload.failed(`the grade's verifier '${name}' is not an object`);
|
|
3030
|
+
const problem = _GradePayload.problem(grade);
|
|
3031
|
+
if (problem) return _GradePayload.failed(problem);
|
|
3032
|
+
return {
|
|
3033
|
+
..._GradePayload.numbers(grade),
|
|
3034
|
+
...typeof grade.error === "string" ? { error: grade.error } : {}
|
|
3035
|
+
};
|
|
3036
|
+
}
|
|
3037
|
+
static failed(error) {
|
|
3038
|
+
return { reward: null, rewards: {}, error };
|
|
3039
|
+
}
|
|
3040
|
+
};
|
|
3041
|
+
}
|
|
3042
|
+
});
|
|
3043
|
+
|
|
2738
3044
|
// src/worlds/session.ts
|
|
2739
3045
|
var session_exports2 = {};
|
|
2740
3046
|
__export(session_exports2, {
|
|
2741
3047
|
WorldSession: () => WorldSession,
|
|
2742
3048
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
3049
|
+
WorldSessionOpenFailed: () => WorldSessionOpenFailed,
|
|
2743
3050
|
WorldSessionTimeout: () => WorldSessionTimeout,
|
|
2744
3051
|
attachSession: () => attachSession,
|
|
2745
3052
|
isTaskIdRef: () => isTaskIdRef,
|
|
@@ -2750,34 +3057,6 @@ __export(session_exports2, {
|
|
|
2750
3057
|
schemaFromSignature: () => schemaFromSignature,
|
|
2751
3058
|
taskLabel: () => taskLabel
|
|
2752
3059
|
});
|
|
2753
|
-
function numericGrade(record) {
|
|
2754
|
-
const rewards = {};
|
|
2755
|
-
const nested = record.rewards;
|
|
2756
|
-
if (nested && typeof nested === "object") {
|
|
2757
|
-
for (const [key2, value] of Object.entries(nested)) {
|
|
2758
|
-
if (typeof value === "number") rewards[key2] = value;
|
|
2759
|
-
}
|
|
2760
|
-
}
|
|
2761
|
-
for (const [key2, value] of Object.entries(record)) {
|
|
2762
|
-
if (key2 !== "reward" && typeof value === "number") rewards[key2] = value;
|
|
2763
|
-
}
|
|
2764
|
-
return {
|
|
2765
|
-
reward: typeof record.reward === "number" ? record.reward : null,
|
|
2766
|
-
rewards
|
|
2767
|
-
};
|
|
2768
|
-
}
|
|
2769
|
-
function verifierGrades(value) {
|
|
2770
|
-
if (!value || typeof value !== "object") return void 0;
|
|
2771
|
-
const out = {};
|
|
2772
|
-
for (const [name, grade] of Object.entries(value)) {
|
|
2773
|
-
const record = grade && typeof grade === "object" ? grade : {};
|
|
2774
|
-
out[name] = {
|
|
2775
|
-
...numericGrade(record),
|
|
2776
|
-
...typeof record.error === "string" ? { error: record.error } : {}
|
|
2777
|
-
};
|
|
2778
|
-
}
|
|
2779
|
-
return out;
|
|
2780
|
-
}
|
|
2781
3060
|
function schemaFromSignature(spec) {
|
|
2782
3061
|
if (spec.inputSchema)
|
|
2783
3062
|
return {
|
|
@@ -2885,6 +3164,7 @@ async function runSessions(opts) {
|
|
|
2885
3164
|
const taskRef = tasks[next++];
|
|
2886
3165
|
let task = taskLabel(taskRef);
|
|
2887
3166
|
let session = null;
|
|
3167
|
+
let keepWarm = opts.keepWarm ?? true;
|
|
2888
3168
|
try {
|
|
2889
3169
|
session = await openSession(opts.world, {
|
|
2890
3170
|
task: taskRef,
|
|
@@ -2892,6 +3172,7 @@ async function runSessions(opts) {
|
|
|
2892
3172
|
options
|
|
2893
3173
|
});
|
|
2894
3174
|
task = taskLabel(taskRef, session.taskInfo);
|
|
3175
|
+
WorldToolsUnread.refuse(opts.world.split("@", 1)[0], session.deprecations);
|
|
2895
3176
|
await session.ready();
|
|
2896
3177
|
const toolkit = await session.toolkit();
|
|
2897
3178
|
const live = session;
|
|
@@ -2914,19 +3195,19 @@ async function runSessions(opts) {
|
|
|
2914
3195
|
results.push(result);
|
|
2915
3196
|
opts.onResult?.(result);
|
|
2916
3197
|
} catch (error) {
|
|
3198
|
+
if (error instanceof WorldToolsUnread) keepWarm = false;
|
|
2917
3199
|
const result = {
|
|
2918
3200
|
task,
|
|
2919
3201
|
sessionId: session?.sessionId ?? "",
|
|
2920
3202
|
reward: 0,
|
|
2921
3203
|
rewards: {},
|
|
2922
|
-
// An
|
|
2923
|
-
// caller checking truthiness; name the type instead.
|
|
3204
|
+
// An empty message reads as "no error" to a truthiness check; name the type instead.
|
|
2924
3205
|
error: (error instanceof Error ? error.message : String(error)) || (error instanceof Error ? error.name : "Unknown error")
|
|
2925
3206
|
};
|
|
2926
3207
|
results.push(result);
|
|
2927
3208
|
opts.onResult?.(result);
|
|
2928
3209
|
} finally {
|
|
2929
|
-
await session?.close({ keepWarm
|
|
3210
|
+
await session?.close({ keepWarm }).catch(() => void 0);
|
|
2930
3211
|
}
|
|
2931
3212
|
}
|
|
2932
3213
|
})
|
|
@@ -2940,7 +3221,7 @@ async function runSessions(opts) {
|
|
|
2940
3221
|
passed: failed === 0 && (opts.failUnder === void 0 || mean >= opts.failUnder)
|
|
2941
3222
|
};
|
|
2942
3223
|
}
|
|
2943
|
-
var import_node_crypto2,
|
|
3224
|
+
var import_node_crypto2, CALL_TIMEOUT_MS, CALL_POLL_MS, JUDGED_GRADE_TIMEOUT_MS, JUDGED_GRADE_POLL_MS, EXPORT_PAGE, sleep4, modelToolName, WorldSession, OPEN_SESSION_OPTION_KEYS, isOpenSessionOptions;
|
|
2944
3225
|
var init_session2 = __esm({
|
|
2945
3226
|
"src/worlds/session.ts"() {
|
|
2946
3227
|
"use strict";
|
|
@@ -2949,22 +3230,20 @@ var init_session2 = __esm({
|
|
|
2949
3230
|
init_browser();
|
|
2950
3231
|
init_nativeComputer();
|
|
2951
3232
|
init_sessionContract();
|
|
3233
|
+
init_sessionReadiness();
|
|
2952
3234
|
init_session();
|
|
2953
3235
|
init_taskRef();
|
|
3236
|
+
init_worldNotice();
|
|
3237
|
+
init_grade();
|
|
2954
3238
|
init_taskRef();
|
|
2955
|
-
|
|
2956
|
-
READY_POLL_MS = 2e3;
|
|
3239
|
+
init_sessionReadiness();
|
|
2957
3240
|
CALL_TIMEOUT_MS = 3 * 6e4;
|
|
2958
3241
|
CALL_POLL_MS = 400;
|
|
2959
3242
|
JUDGED_GRADE_TIMEOUT_MS = 15 * 6e4;
|
|
2960
3243
|
JUDGED_GRADE_POLL_MS = 2e3;
|
|
2961
3244
|
EXPORT_PAGE = 500;
|
|
2962
|
-
|
|
3245
|
+
sleep4 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
2963
3246
|
modelToolName = (name) => name.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 64) || "tool";
|
|
2964
|
-
WorldSessionTimeout = class extends Error {
|
|
2965
|
-
};
|
|
2966
|
-
WorldSessionCallError = class extends Error {
|
|
2967
|
-
};
|
|
2968
3247
|
WorldSession = class {
|
|
2969
3248
|
constructor(sessionId, current, options) {
|
|
2970
3249
|
this.sessionId = sessionId;
|
|
@@ -3082,18 +3361,17 @@ var init_session2 = __esm({
|
|
|
3082
3361
|
}
|
|
3083
3362
|
/** The reporter `browser()` uses; exposed for a page you drive yourself. */
|
|
3084
3363
|
browserRecorder(agentId) {
|
|
3085
|
-
const
|
|
3364
|
+
const path17 = `/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/browser-events`;
|
|
3086
3365
|
const id = agentId ?? process.env.GATEWAY_AGENT_ID ?? `agent-${(0, import_node_crypto2.randomUUID)().replace(/-/g, "").slice(0, 8)}`;
|
|
3087
3366
|
return new BrowserActionRecorder(
|
|
3088
3367
|
async (events) => {
|
|
3089
|
-
await apiRequest(this.options, "POST",
|
|
3368
|
+
await apiRequest(this.options, "POST", path17, { events });
|
|
3090
3369
|
},
|
|
3091
3370
|
id,
|
|
3092
3371
|
{
|
|
3093
|
-
// Continue this agent's timeline where the platform has it, so
|
|
3094
|
-
// same id reopened later never re-numbers from zero.
|
|
3372
|
+
// Continue this agent's timeline where the platform has it, so a reopened id never re-numbers from zero.
|
|
3095
3373
|
resumeFrom: async () => {
|
|
3096
|
-
const summary = await apiRequest(this.options, "GET",
|
|
3374
|
+
const summary = await apiRequest(this.options, "GET", path17);
|
|
3097
3375
|
return summary.agents.find((a) => a.agentId === id)?.nextSeq ?? 0;
|
|
3098
3376
|
}
|
|
3099
3377
|
}
|
|
@@ -3121,29 +3399,22 @@ var init_session2 = __esm({
|
|
|
3121
3399
|
tools: this.current.tools,
|
|
3122
3400
|
surfaces: this.current.surfaces,
|
|
3123
3401
|
task: this.current.task,
|
|
3402
|
+
deprecations: this.current.deprecations,
|
|
3124
3403
|
...fresh
|
|
3125
3404
|
};
|
|
3126
3405
|
return this.current;
|
|
3127
3406
|
}
|
|
3128
3407
|
/**
|
|
3129
|
-
* Wait until the
|
|
3130
|
-
* asked the platform for work
|
|
3408
|
+
* Wait until the session answers calls: a World Host holds it, or the
|
|
3409
|
+
* process inside a pod has asked the platform for work. Throws
|
|
3410
|
+
* `WorldSessionOpenFailed` (with the platform's reason) when it ended
|
|
3411
|
+
* first, and `WorldSessionTimeout` when `timeoutMs` (default ten minutes)
|
|
3412
|
+
* ran out while it was still starting.
|
|
3131
3413
|
*/
|
|
3132
3414
|
async ready(opts = {}) {
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
if (state2.ready) return state2;
|
|
3137
|
-
if (state2.state === "FAILED" || state2.state === "STOPPED")
|
|
3138
|
-
throw new WorldSessionCallError(
|
|
3139
|
-
`World session ${state2.state.toLowerCase()} before it was ready.`
|
|
3140
|
-
);
|
|
3141
|
-
if (Date.now() > deadline)
|
|
3142
|
-
throw new WorldSessionTimeout(
|
|
3143
|
-
`World session still ${state2.state} after ${Math.round((opts.timeoutMs ?? READY_TIMEOUT_MS) / 1e3)}s.`
|
|
3144
|
-
);
|
|
3145
|
-
await sleep2(READY_POLL_MS);
|
|
3146
|
-
}
|
|
3415
|
+
return new SessionReadiness(this.sessionId, () => this.status()).wait(
|
|
3416
|
+
opts.timeoutMs
|
|
3417
|
+
);
|
|
3147
3418
|
}
|
|
3148
3419
|
/** Enqueue one interaction and wait for the container's answer. */
|
|
3149
3420
|
async exchange(body, timeoutMs) {
|
|
@@ -3173,7 +3444,7 @@ var init_session2 = __esm({
|
|
|
3173
3444
|
throw new WorldSessionTimeout(
|
|
3174
3445
|
judged ? `Grade ${callId} still ${call.state} after ${Math.round(budgetMs / 1e3)}s \u2014 the judge has not answered; the platform finalizes the call on its own, read it back with export().` : `Call ${callId} still ${call.state} after ${Math.round(budgetMs / 1e3)}s \u2014 the container may have died.`
|
|
3175
3446
|
);
|
|
3176
|
-
await
|
|
3447
|
+
await sleep4(pollMs2);
|
|
3177
3448
|
}
|
|
3178
3449
|
}
|
|
3179
3450
|
/**
|
|
@@ -3222,7 +3493,9 @@ var init_session2 = __esm({
|
|
|
3222
3493
|
* calls); assertions and python graders ignore it. `worlds` names the
|
|
3223
3494
|
* task's other sessions by alias (`{alias: sessionId}`): the platform
|
|
3224
3495
|
* reads each one's evidence and hands it to the cross-world verifiers
|
|
3225
|
-
* anchored on this session, whose grades come back under `verifiers`.
|
|
3496
|
+
* anchored on this session, whose grades come back under `verifiers`. A
|
|
3497
|
+
* score that is not a number from 0 to 1 is refused by key and value
|
|
3498
|
+
* (`GradeRefused`); a verifier's is that verifier's `error`. */
|
|
3226
3499
|
async grade(opts = {}) {
|
|
3227
3500
|
const raw = await this.exchange(
|
|
3228
3501
|
{
|
|
@@ -3232,14 +3505,7 @@ var init_session2 = __esm({
|
|
|
3232
3505
|
},
|
|
3233
3506
|
opts.timeoutMs
|
|
3234
3507
|
);
|
|
3235
|
-
|
|
3236
|
-
const verifiers = verifierGrades(record.verifiers);
|
|
3237
|
-
return {
|
|
3238
|
-
...numericGrade(record),
|
|
3239
|
-
...typeof record.reason === "string" ? { reason: record.reason } : {},
|
|
3240
|
-
...verifiers ? { verifiers } : {},
|
|
3241
|
-
raw
|
|
3242
|
-
};
|
|
3508
|
+
return { ...GradePayload.read(raw), raw };
|
|
3243
3509
|
}
|
|
3244
3510
|
/**
|
|
3245
3511
|
* Put rows into the LIVE world through its contract, in one batch:
|
|
@@ -3503,26 +3769,28 @@ var init_surfaceDescriptor = __esm({
|
|
|
3503
3769
|
|
|
3504
3770
|
// src/worlds/taskSessions.ts
|
|
3505
3771
|
function aggregateTaskGrade(worlds) {
|
|
3506
|
-
const
|
|
3507
|
-
const ungraded = [];
|
|
3508
|
-
const graded = [];
|
|
3772
|
+
const fold = new TaskGradeFold();
|
|
3509
3773
|
const verifiers = {};
|
|
3510
|
-
const fold = (key2, grade) => {
|
|
3511
|
-
if (typeof grade.reward === "number") {
|
|
3512
|
-
rewards[key2] = grade.reward;
|
|
3513
|
-
graded.push(grade.reward);
|
|
3514
|
-
} else ungraded.push(key2);
|
|
3515
|
-
for (const [name, value] of Object.entries(grade.rewards))
|
|
3516
|
-
rewards[`${key2}.${name}`] = value;
|
|
3517
|
-
};
|
|
3518
3774
|
for (const [alias, grade] of Object.entries(worlds)) {
|
|
3519
|
-
fold(alias, grade);
|
|
3775
|
+
fold.add(alias, grade, `world ${alias}`);
|
|
3520
3776
|
Object.assign(verifiers, grade.verifiers ?? {});
|
|
3521
3777
|
}
|
|
3522
3778
|
for (const [name, grade] of Object.entries(verifiers))
|
|
3523
|
-
fold(`${VERIFIER_REWARD_PREFIX}${name}`, grade);
|
|
3524
|
-
|
|
3525
|
-
|
|
3779
|
+
fold.add(`${VERIFIER_REWARD_PREFIX}${name}`, grade, `verifier ${name}`);
|
|
3780
|
+
return {
|
|
3781
|
+
reward: fold.reward(),
|
|
3782
|
+
rewards: fold.rewards,
|
|
3783
|
+
worlds,
|
|
3784
|
+
ungraded: fold.ungraded,
|
|
3785
|
+
verifiers,
|
|
3786
|
+
errors: fold.errors
|
|
3787
|
+
};
|
|
3788
|
+
}
|
|
3789
|
+
function taskGradeError(grade) {
|
|
3790
|
+
const lines = Object.entries(grade.errors).map(
|
|
3791
|
+
([key2, why]) => `${key2}: ${why}`
|
|
3792
|
+
);
|
|
3793
|
+
return lines.length ? lines.join("; ") : null;
|
|
3526
3794
|
}
|
|
3527
3795
|
function fromResponse(answer, options) {
|
|
3528
3796
|
const sessions2 = {};
|
|
@@ -3645,12 +3913,13 @@ async function attachManifest(manifest, options = {}) {
|
|
|
3645
3913
|
function isTaskManifest(value) {
|
|
3646
3914
|
return typeof value === "object" && value !== null && !Array.isArray(value) && typeof value.sessions === "object" && value.sessions !== null && !("instruction" in value && "worlds" in value);
|
|
3647
3915
|
}
|
|
3648
|
-
var TASK_SESSIONS, VERIFIER_REWARD_PREFIX, manifestSession, TaskSessions;
|
|
3916
|
+
var TASK_SESSIONS, VERIFIER_REWARD_PREFIX, manifestSession, TaskGradeFold, TaskSessions;
|
|
3649
3917
|
var init_taskSessions = __esm({
|
|
3650
3918
|
"src/worlds/taskSessions.ts"() {
|
|
3651
3919
|
"use strict";
|
|
3652
3920
|
init_worlds();
|
|
3653
3921
|
init_browser();
|
|
3922
|
+
init_grade();
|
|
3654
3923
|
init_surfaceDescriptor();
|
|
3655
3924
|
init_session2();
|
|
3656
3925
|
TASK_SESSIONS = "/api/public/world-task-sessions";
|
|
@@ -3665,6 +3934,36 @@ var init_taskSessions = __esm({
|
|
|
3665
3934
|
state: state2.state,
|
|
3666
3935
|
...surfaceDescriptor(s)
|
|
3667
3936
|
});
|
|
3937
|
+
TaskGradeFold = class {
|
|
3938
|
+
rewards = {};
|
|
3939
|
+
ungraded = [];
|
|
3940
|
+
errors = {};
|
|
3941
|
+
sources = /* @__PURE__ */ new Map();
|
|
3942
|
+
graded = [];
|
|
3943
|
+
add(key2, grade, source) {
|
|
3944
|
+
if (grade.error) this.errors[key2] = grade.error;
|
|
3945
|
+
if (typeof grade.reward === "number") {
|
|
3946
|
+
this.put(key2, grade.reward, source);
|
|
3947
|
+
this.graded.push(grade.reward);
|
|
3948
|
+
} else this.ungraded.push(key2);
|
|
3949
|
+
for (const [name, value] of Object.entries(grade.rewards))
|
|
3950
|
+
this.put(`${key2}.${name}`, value, source);
|
|
3951
|
+
}
|
|
3952
|
+
reward() {
|
|
3953
|
+
if (Object.keys(this.errors).length > 0 || !this.graded.length)
|
|
3954
|
+
return null;
|
|
3955
|
+
return this.graded.reduce((a, b) => a + b, 0) / this.graded.length;
|
|
3956
|
+
}
|
|
3957
|
+
put(key2, value, source) {
|
|
3958
|
+
const first = this.sources.get(key2) ?? source;
|
|
3959
|
+
this.sources.set(key2, first);
|
|
3960
|
+
if (first !== source) {
|
|
3961
|
+
this.errors[key2] = `two rewards are named ${key2} (${first} and ${source}); rename one of them`;
|
|
3962
|
+
return;
|
|
3963
|
+
}
|
|
3964
|
+
this.rewards[key2] = value;
|
|
3965
|
+
}
|
|
3966
|
+
};
|
|
3668
3967
|
TaskSessions = class {
|
|
3669
3968
|
constructor(taskId, taskVersion, name, instruction, sessions2, worlds, hash = null) {
|
|
3670
3969
|
this.taskId = taskId;
|
|
@@ -3743,11 +4042,13 @@ var init_taskSessions = __esm({
|
|
|
3743
4042
|
* agent's own account of the whole investigation) goes to every world's
|
|
3744
4043
|
* judge; a world graded by assertions or python ignores it. Each grade
|
|
3745
4044
|
* names the task's other sessions by alias, so the cross-world verifiers
|
|
3746
|
-
* anchored on that world can read them.
|
|
4045
|
+
* anchored on that world can read them. A world whose grade call fails is
|
|
4046
|
+
* that world's error: the task's grade names it and keeps every other
|
|
4047
|
+
* world's grade. */
|
|
3747
4048
|
async grade(opts = {}) {
|
|
3748
4049
|
return aggregateTaskGrade(
|
|
3749
4050
|
await this.each(
|
|
3750
|
-
(session, alias) => session.grade({ ...opts, worlds: this.otherSessions(alias) })
|
|
4051
|
+
(session, alias) => session.grade({ ...opts, worlds: this.otherSessions(alias) }).catch((error) => GradePayload.failedCall(error))
|
|
3751
4052
|
)
|
|
3752
4053
|
);
|
|
3753
4054
|
}
|
|
@@ -3795,12 +4096,16 @@ var init_evals = __esm({
|
|
|
3795
4096
|
"src/worlds/evals.ts"() {
|
|
3796
4097
|
"use strict";
|
|
3797
4098
|
init_worlds();
|
|
4099
|
+
init_transport();
|
|
3798
4100
|
EVALUATIONS = "/api/public/benchmark-containers/evaluations";
|
|
3799
4101
|
GatewayEvalsClient = class {
|
|
3800
|
-
constructor(options = {}) {
|
|
4102
|
+
constructor(options = {}, retry = RetryPolicy.FILING) {
|
|
3801
4103
|
this.options = options;
|
|
4104
|
+
this.retry = retry;
|
|
3802
4105
|
}
|
|
3803
4106
|
options;
|
|
4107
|
+
retry;
|
|
4108
|
+
keyed = /* @__PURE__ */ new Set();
|
|
3804
4109
|
async createEvaluation(versionId, opts = {}) {
|
|
3805
4110
|
const body = { versionId };
|
|
3806
4111
|
if (opts.model !== void 0) body.model = opts.model;
|
|
@@ -3808,12 +4113,18 @@ var init_evals = __esm({
|
|
|
3808
4113
|
if (opts.rolloutsPerExample !== void 0)
|
|
3809
4114
|
body.rolloutsPerExample = opts.rolloutsPerExample;
|
|
3810
4115
|
if (opts.metadata !== void 0) body.metadata = opts.metadata;
|
|
4116
|
+
if (opts.idempotencyKey !== void 0)
|
|
4117
|
+
body.idempotencyKey = opts.idempotencyKey;
|
|
3811
4118
|
const answer = await apiRequest(
|
|
3812
4119
|
this.options,
|
|
3813
4120
|
"POST",
|
|
3814
4121
|
EVALUATIONS,
|
|
3815
|
-
body
|
|
4122
|
+
body,
|
|
4123
|
+
{
|
|
4124
|
+
retry: opts.idempotencyKey === void 0 ? RetryPolicy.NONE : this.retry
|
|
4125
|
+
}
|
|
3816
4126
|
);
|
|
4127
|
+
if (opts.idempotencyKey !== void 0) this.keyed.add(answer.evaluationId);
|
|
3817
4128
|
return answer.evaluationId;
|
|
3818
4129
|
}
|
|
3819
4130
|
async pushSamples(evaluationId, samples) {
|
|
@@ -3821,7 +4132,8 @@ var init_evals = __esm({
|
|
|
3821
4132
|
this.options,
|
|
3822
4133
|
"POST",
|
|
3823
4134
|
`${EVALUATIONS}/${encodeURIComponent(evaluationId)}/samples`,
|
|
3824
|
-
{ samples }
|
|
4135
|
+
{ samples },
|
|
4136
|
+
{ retry: this.retryFor(evaluationId) }
|
|
3825
4137
|
);
|
|
3826
4138
|
return answer.inserted ?? samples.length;
|
|
3827
4139
|
}
|
|
@@ -3834,10 +4146,300 @@ var init_evals = __esm({
|
|
|
3834
4146
|
this.options,
|
|
3835
4147
|
"POST",
|
|
3836
4148
|
`${EVALUATIONS}/${encodeURIComponent(evaluationId)}/finalize`,
|
|
3837
|
-
body
|
|
4149
|
+
body,
|
|
4150
|
+
{ retry: this.retryFor(evaluationId) }
|
|
3838
4151
|
);
|
|
3839
4152
|
return answer.status;
|
|
3840
4153
|
}
|
|
4154
|
+
retryFor(evaluationId) {
|
|
4155
|
+
return this.keyed.has(evaluationId) ? this.retry : RetryPolicy.NONE;
|
|
4156
|
+
}
|
|
4157
|
+
};
|
|
4158
|
+
}
|
|
4159
|
+
});
|
|
4160
|
+
|
|
4161
|
+
// src/worlds/runSignals.ts
|
|
4162
|
+
var import_node_os, OWNER, RunSignals;
|
|
4163
|
+
var init_runSignals = __esm({
|
|
4164
|
+
"src/worlds/runSignals.ts"() {
|
|
4165
|
+
"use strict";
|
|
4166
|
+
import_node_os = require("os");
|
|
4167
|
+
OWNER = /* @__PURE__ */ Symbol("RunSignals");
|
|
4168
|
+
RunSignals = class _RunSignals {
|
|
4169
|
+
constructor(target = process) {
|
|
4170
|
+
this.target = target;
|
|
4171
|
+
}
|
|
4172
|
+
target;
|
|
4173
|
+
static SIGNALS = ["SIGINT", "SIGTERM"];
|
|
4174
|
+
cleanups = [];
|
|
4175
|
+
heardSignal = null;
|
|
4176
|
+
heardCount = 0;
|
|
4177
|
+
listening = false;
|
|
4178
|
+
left = false;
|
|
4179
|
+
listener = Object.assign(
|
|
4180
|
+
(signal) => this.heard(signal),
|
|
4181
|
+
{ [OWNER]: this }
|
|
4182
|
+
);
|
|
4183
|
+
/** The signal that arrived, once one has: start nothing new. */
|
|
4184
|
+
get signal() {
|
|
4185
|
+
return this.owner().heardSignal;
|
|
4186
|
+
}
|
|
4187
|
+
async during(cleanup, work) {
|
|
4188
|
+
return this.owner().hold(cleanup, work);
|
|
4189
|
+
}
|
|
4190
|
+
owner() {
|
|
4191
|
+
const owners = this.target.listeners("SIGINT").map((listener) => listener[OWNER]);
|
|
4192
|
+
return owners.find((owner) => owner !== void 0) ?? this;
|
|
4193
|
+
}
|
|
4194
|
+
async hold(cleanup, work) {
|
|
4195
|
+
this.listen();
|
|
4196
|
+
this.cleanups.push(cleanup);
|
|
4197
|
+
try {
|
|
4198
|
+
return await work();
|
|
4199
|
+
} finally {
|
|
4200
|
+
this.cleanups.splice(this.cleanups.indexOf(cleanup), 1);
|
|
4201
|
+
if (!this.cleanups.length && this.heardSignal === null) this.unlisten();
|
|
4202
|
+
}
|
|
4203
|
+
}
|
|
4204
|
+
heard(signal) {
|
|
4205
|
+
this.heardCount += 1;
|
|
4206
|
+
if (this.heardCount > 2) return this.leave(signal);
|
|
4207
|
+
this.heardSignal ??= signal;
|
|
4208
|
+
void this.cleanUp(signal, this.heardCount === 2).finally(() => this.leave(signal));
|
|
4209
|
+
}
|
|
4210
|
+
async cleanUp(signal, urgent) {
|
|
4211
|
+
for (const cleanup of [...this.cleanups].reverse())
|
|
4212
|
+
await Promise.resolve().then(() => cleanup(signal, urgent)).catch(() => void 0);
|
|
4213
|
+
}
|
|
4214
|
+
leave(signal) {
|
|
4215
|
+
if (this.left) return;
|
|
4216
|
+
this.left = true;
|
|
4217
|
+
this.unlisten();
|
|
4218
|
+
if (this.target.listenerCount(signal) === 0)
|
|
4219
|
+
this.target.exit(128 + import_node_os.constants.signals[signal]);
|
|
4220
|
+
}
|
|
4221
|
+
listen() {
|
|
4222
|
+
if (this.listening) return;
|
|
4223
|
+
this.listening = true;
|
|
4224
|
+
for (const signal of _RunSignals.SIGNALS)
|
|
4225
|
+
this.target.on(signal, this.listener);
|
|
4226
|
+
}
|
|
4227
|
+
unlisten() {
|
|
4228
|
+
this.listening = false;
|
|
4229
|
+
for (const signal of _RunSignals.SIGNALS)
|
|
4230
|
+
this.target.off(signal, this.listener);
|
|
4231
|
+
}
|
|
4232
|
+
};
|
|
4233
|
+
}
|
|
4234
|
+
});
|
|
4235
|
+
|
|
4236
|
+
// src/worlds/taskRunDir.ts
|
|
4237
|
+
function sessionRecord({ api: api2, ui, browser, ...session }) {
|
|
4238
|
+
return {
|
|
4239
|
+
...session,
|
|
4240
|
+
...api2 ? { api: { url: api2.url } } : {},
|
|
4241
|
+
...ui ? { ui: { ...ui, entry: withoutUiToken(ui.entry) } } : {},
|
|
4242
|
+
...browser ? { browser: browserRecord(browser) } : {}
|
|
4243
|
+
};
|
|
4244
|
+
}
|
|
4245
|
+
var fs, path, TaskRunDir, browserRecord;
|
|
4246
|
+
var init_taskRunDir = __esm({
|
|
4247
|
+
"src/worlds/taskRunDir.ts"() {
|
|
4248
|
+
"use strict";
|
|
4249
|
+
fs = __toESM(require("fs"));
|
|
4250
|
+
path = __toESM(require("path"));
|
|
4251
|
+
init_browser();
|
|
4252
|
+
TaskRunDir = class {
|
|
4253
|
+
constructor(path17) {
|
|
4254
|
+
this.path = path17;
|
|
4255
|
+
}
|
|
4256
|
+
path;
|
|
4257
|
+
writeManifest(manifest) {
|
|
4258
|
+
this.writeJson("manifest.json", {
|
|
4259
|
+
...manifest,
|
|
4260
|
+
sessions: Object.fromEntries(
|
|
4261
|
+
Object.entries(manifest.sessions).map(([alias, session]) => [
|
|
4262
|
+
alias,
|
|
4263
|
+
sessionRecord(session)
|
|
4264
|
+
])
|
|
4265
|
+
)
|
|
4266
|
+
});
|
|
4267
|
+
}
|
|
4268
|
+
writeJson(name, value) {
|
|
4269
|
+
this.write(name, JSON.stringify(value, null, 2));
|
|
4270
|
+
}
|
|
4271
|
+
write(name, text2) {
|
|
4272
|
+
fs.mkdirSync(this.path, { recursive: true });
|
|
4273
|
+
fs.writeFileSync(path.join(this.path, name), text2);
|
|
4274
|
+
}
|
|
4275
|
+
};
|
|
4276
|
+
browserRecord = ({ viewport, tier }) => ({
|
|
4277
|
+
viewport,
|
|
4278
|
+
...tier ? { tier } : {}
|
|
4279
|
+
});
|
|
4280
|
+
}
|
|
4281
|
+
});
|
|
4282
|
+
|
|
4283
|
+
// src/worlds/taskRunOutcome.ts
|
|
4284
|
+
var TaskRunOutcome;
|
|
4285
|
+
var init_taskRunOutcome = __esm({
|
|
4286
|
+
"src/worlds/taskRunOutcome.ts"() {
|
|
4287
|
+
"use strict";
|
|
4288
|
+
init_grade();
|
|
4289
|
+
init_taskSessions();
|
|
4290
|
+
TaskRunOutcome = class {
|
|
4291
|
+
constructor(runId, live, model, runDir) {
|
|
4292
|
+
this.runId = runId;
|
|
4293
|
+
this.live = live;
|
|
4294
|
+
this.model = model;
|
|
4295
|
+
this.runDir = runDir;
|
|
4296
|
+
}
|
|
4297
|
+
runId;
|
|
4298
|
+
live;
|
|
4299
|
+
model;
|
|
4300
|
+
runDir;
|
|
4301
|
+
report = null;
|
|
4302
|
+
extra = {};
|
|
4303
|
+
notes = {};
|
|
4304
|
+
agentError = null;
|
|
4305
|
+
grade = null;
|
|
4306
|
+
traced = false;
|
|
4307
|
+
runError = null;
|
|
4308
|
+
fileError = null;
|
|
4309
|
+
evaluationId;
|
|
4310
|
+
evaluationStatus = null;
|
|
4311
|
+
started = Date.now();
|
|
4312
|
+
/** The run stopped short of a grade; the first reason stands. */
|
|
4313
|
+
stopped(error) {
|
|
4314
|
+
this.runError ??= messageOf(error).slice(0, 2e3);
|
|
4315
|
+
}
|
|
4316
|
+
agentRaised(error) {
|
|
4317
|
+
this.agentError = messageOf(error).slice(0, 2e3);
|
|
4318
|
+
}
|
|
4319
|
+
/** Every reason the run failed, on one line: the evaluation's
|
|
4320
|
+
* `metrics.error`. A run that never reached a grade has failed whatever
|
|
4321
|
+
* its reasons say. */
|
|
4322
|
+
failure() {
|
|
4323
|
+
const reasons = [
|
|
4324
|
+
this.agentError === null ? null : `agent raised: ${this.agentError}`,
|
|
4325
|
+
this.runError === null ? null : `the run stopped: ${this.runError}`,
|
|
4326
|
+
this.gradeError(),
|
|
4327
|
+
this.grade === null && this.runError === null ? "the run stopped before it was graded" : null
|
|
4328
|
+
].filter((reason) => reason !== null);
|
|
4329
|
+
return reasons.length ? reasons.join("; ") : null;
|
|
4330
|
+
}
|
|
4331
|
+
async file(evals, setRunId) {
|
|
4332
|
+
let created;
|
|
4333
|
+
try {
|
|
4334
|
+
created = await evals.createEvaluation(this.ref(this.live.aliases[0]).versionId, {
|
|
4335
|
+
model: this.model,
|
|
4336
|
+
rolloutsPerExample: 1,
|
|
4337
|
+
idempotencyKey: this.runId,
|
|
4338
|
+
...setRunId ? { runId: setRunId } : {},
|
|
4339
|
+
metadata: this.metadata()
|
|
4340
|
+
});
|
|
4341
|
+
await evals.pushSamples(created, [this.sample()]);
|
|
4342
|
+
this.evaluationStatus = await evals.finalizeEvaluation(created, this.finalized());
|
|
4343
|
+
this.evaluationId = created;
|
|
4344
|
+
} catch (error) {
|
|
4345
|
+
this.fileError = created ? `evaluation ${created}: ${messageOf(error)}` : messageOf(error);
|
|
4346
|
+
if (created)
|
|
4347
|
+
await evals.finalizeEvaluation(created, { status: "FAILED", metrics: { error: this.fileError } }).catch(() => void 0);
|
|
4348
|
+
}
|
|
4349
|
+
}
|
|
4350
|
+
summary() {
|
|
4351
|
+
const live = this.live;
|
|
4352
|
+
const { evaluationId: _agentEvaluationId, ...extra } = this.extra;
|
|
4353
|
+
return {
|
|
4354
|
+
...extra,
|
|
4355
|
+
runId: this.runId,
|
|
4356
|
+
taskId: live.taskId,
|
|
4357
|
+
taskVersion: live.taskVersion,
|
|
4358
|
+
name: live.name,
|
|
4359
|
+
instruction: live.instruction ?? "",
|
|
4360
|
+
model: this.model,
|
|
4361
|
+
aliases: live.aliases,
|
|
4362
|
+
reward: this.grade?.reward ?? null,
|
|
4363
|
+
rewards: this.grade?.rewards ?? {},
|
|
4364
|
+
ungraded: this.grade?.ungraded ?? live.aliases,
|
|
4365
|
+
agentError: this.agentError,
|
|
4366
|
+
runError: this.runError,
|
|
4367
|
+
gradeError: this.gradeError(),
|
|
4368
|
+
fileError: this.fileError,
|
|
4369
|
+
evaluationStatus: this.evaluationStatus,
|
|
4370
|
+
report: this.report,
|
|
4371
|
+
traced: this.traced,
|
|
4372
|
+
runDir: this.runDir,
|
|
4373
|
+
durationSeconds: Math.round((Date.now() - this.started) / 10) / 100,
|
|
4374
|
+
notes: this.notes,
|
|
4375
|
+
filed: this.evaluationId !== void 0,
|
|
4376
|
+
...this.evaluationId ? { evaluationId: this.evaluationId } : {}
|
|
4377
|
+
};
|
|
4378
|
+
}
|
|
4379
|
+
gradeError() {
|
|
4380
|
+
return this.grade ? taskGradeError(this.grade) : null;
|
|
4381
|
+
}
|
|
4382
|
+
ref(alias) {
|
|
4383
|
+
const { slug, ref } = this.live.worldRef(alias);
|
|
4384
|
+
const session = this.live.sessions[alias];
|
|
4385
|
+
return { slug, ref, versionId: session.versionId, sessionId: session.sessionId };
|
|
4386
|
+
}
|
|
4387
|
+
metadata() {
|
|
4388
|
+
const live = this.live;
|
|
4389
|
+
return {
|
|
4390
|
+
source: "worlds-task-run",
|
|
4391
|
+
task: { id: live.taskId, version: live.taskVersion, name: live.name, hash: live.hash },
|
|
4392
|
+
anchor: live.aliases[0],
|
|
4393
|
+
worlds: Object.fromEntries(live.aliases.map((alias) => [alias, this.ref(alias)])),
|
|
4394
|
+
runId: this.runId
|
|
4395
|
+
};
|
|
4396
|
+
}
|
|
4397
|
+
sample() {
|
|
4398
|
+
const live = this.live;
|
|
4399
|
+
const reward = this.grade?.reward ?? null;
|
|
4400
|
+
const gradeError = this.gradeError();
|
|
4401
|
+
const sample = {
|
|
4402
|
+
exampleId: live.name ?? live.taskId ?? this.runId,
|
|
4403
|
+
task: live.name ?? live.taskId ?? this.runId,
|
|
4404
|
+
rolloutIndex: 0,
|
|
4405
|
+
prompt: live.instruction,
|
|
4406
|
+
...this.report === null ? {} : { completion: this.report },
|
|
4407
|
+
rewards: this.grade?.rewards ?? {},
|
|
4408
|
+
info: {
|
|
4409
|
+
sessionId: this.runId,
|
|
4410
|
+
worlds: Object.fromEntries(
|
|
4411
|
+
live.aliases.map((alias) => [
|
|
4412
|
+
alias,
|
|
4413
|
+
{ ...this.ref(alias), reward: this.grade?.worlds[alias]?.reward ?? null }
|
|
4414
|
+
])
|
|
4415
|
+
),
|
|
4416
|
+
ungraded: this.grade?.ungraded ?? live.aliases,
|
|
4417
|
+
traced: this.traced,
|
|
4418
|
+
runDir: this.runDir,
|
|
4419
|
+
...this.agentError ? { agentError: this.agentError } : {},
|
|
4420
|
+
...this.runError ? { runError: this.runError } : {},
|
|
4421
|
+
...gradeError ? { verifyError: gradeError } : {}
|
|
4422
|
+
}
|
|
4423
|
+
};
|
|
4424
|
+
if (typeof reward === "number")
|
|
4425
|
+
Object.assign(sample, { reward, score: reward, correct: reward >= 1 });
|
|
4426
|
+
return sample;
|
|
4427
|
+
}
|
|
4428
|
+
finalized() {
|
|
4429
|
+
const reward = this.grade?.reward ?? null;
|
|
4430
|
+
const failure = this.failure();
|
|
4431
|
+
return {
|
|
4432
|
+
status: failure ? "FAILED" : "COMPLETED",
|
|
4433
|
+
metrics: {
|
|
4434
|
+
...typeof reward === "number" ? { avg_reward: reward } : {},
|
|
4435
|
+
reward,
|
|
4436
|
+
...Object.fromEntries(
|
|
4437
|
+
Object.entries(this.grade?.rewards ?? {}).map(([key2, value]) => [`rewards.${key2}`, value])
|
|
4438
|
+
),
|
|
4439
|
+
...failure ? { error: failure } : {}
|
|
4440
|
+
}
|
|
4441
|
+
};
|
|
4442
|
+
}
|
|
3841
4443
|
};
|
|
3842
4444
|
}
|
|
3843
4445
|
});
|
|
@@ -3850,7 +4452,7 @@ function getEnv(key2) {
|
|
|
3850
4452
|
function isGatewayConfigured() {
|
|
3851
4453
|
return !!(getEnv(GATEWAY_ENV.HOST) && getEnv(GATEWAY_ENV.PUBLIC_KEY) && getEnv(GATEWAY_ENV.SECRET_KEY));
|
|
3852
4454
|
}
|
|
3853
|
-
var GATEWAY_ENV, OPENTELEMETRY_PEERS, MODULE_NOT_FOUND, OpenTelemetryMissing;
|
|
4455
|
+
var GATEWAY_ENV, OTLP_TRACES_PATH, OPENTELEMETRY_PEERS, PINNED_PEERS, MODULE_NOT_FOUND, OpenTelemetryMissing;
|
|
3854
4456
|
var init_prerequisites = __esm({
|
|
3855
4457
|
"src/tracing/prerequisites.ts"() {
|
|
3856
4458
|
"use strict";
|
|
@@ -3858,21 +4460,25 @@ var init_prerequisites = __esm({
|
|
|
3858
4460
|
HOST: "GATEWAY_HOST",
|
|
3859
4461
|
PUBLIC_KEY: "GATEWAY_PUBLIC_KEY",
|
|
3860
4462
|
SECRET_KEY: "GATEWAY_SECRET_KEY",
|
|
4463
|
+
API_KEY: "GATEWAY_API_KEY",
|
|
3861
4464
|
ENDPOINT: "GATEWAY_OTLP_ENDPOINT"
|
|
3862
4465
|
};
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
"@opentelemetry/
|
|
3866
|
-
"@opentelemetry/
|
|
3867
|
-
"@opentelemetry/
|
|
3868
|
-
"@opentelemetry/sdk-trace-
|
|
3869
|
-
|
|
4466
|
+
OTLP_TRACES_PATH = "/api/public/otel/v1/traces";
|
|
4467
|
+
OPENTELEMETRY_PEERS = {
|
|
4468
|
+
"@opentelemetry/api": "1.9.0",
|
|
4469
|
+
"@opentelemetry/exporter-trace-otlp-http": "0.222.0",
|
|
4470
|
+
"@opentelemetry/resources": "2.11.0",
|
|
4471
|
+
"@opentelemetry/sdk-trace-base": "2.11.0",
|
|
4472
|
+
"@opentelemetry/sdk-trace-node": "2.11.0"
|
|
4473
|
+
};
|
|
4474
|
+
PINNED_PEERS = Object.entries(OPENTELEMETRY_PEERS).map(([name, version]) => `${name}@${version}`).join(" ");
|
|
3870
4475
|
MODULE_NOT_FOUND = /* @__PURE__ */ new Set(["MODULE_NOT_FOUND", "ERR_MODULE_NOT_FOUND"]);
|
|
3871
4476
|
OpenTelemetryMissing = class _OpenTelemetryMissing extends Error {
|
|
3872
4477
|
constructor() {
|
|
3873
4478
|
super(
|
|
3874
|
-
`OpenTelemetry packages not found. Install them with:
|
|
3875
|
-
npm install ${
|
|
4479
|
+
`OpenTelemetry packages not found. Install them next to @withgateway/sdk, at the versions it is tested with:
|
|
4480
|
+
npm install ${PINNED_PEERS}
|
|
4481
|
+
npm install -g ${PINNED_PEERS} (the gateway CLI, when it was installed with npm install -g)`
|
|
3876
4482
|
);
|
|
3877
4483
|
this.name = "OpenTelemetryMissing";
|
|
3878
4484
|
}
|
|
@@ -4185,7 +4791,7 @@ var require_package = __commonJS({
|
|
|
4185
4791
|
"package.json"(exports2, module2) {
|
|
4186
4792
|
module2.exports = {
|
|
4187
4793
|
name: "@withgateway/sdk",
|
|
4188
|
-
version: "0.3.
|
|
4794
|
+
version: "0.3.3",
|
|
4189
4795
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
4190
4796
|
main: "./dist/index.js",
|
|
4191
4797
|
module: "./dist/index.mjs",
|
|
@@ -4693,7 +5299,7 @@ function buildProvider(config, logFn) {
|
|
|
4693
5299
|
const host = config.host ?? getEnv(GATEWAY_ENV.HOST);
|
|
4694
5300
|
const publicKey = config.publicKey ?? getEnv(GATEWAY_ENV.PUBLIC_KEY);
|
|
4695
5301
|
const secretKey = config.secretKey ?? getEnv(GATEWAY_ENV.SECRET_KEY);
|
|
4696
|
-
const endpoint = config.endpoint ?? getEnv(GATEWAY_ENV.ENDPOINT) ?? (host ? `${host.replace(/\/$/, "")}${
|
|
5302
|
+
const endpoint = config.endpoint ?? getEnv(GATEWAY_ENV.ENDPOINT) ?? (host ? `${host.replace(/\/$/, "")}${OTLP_TRACES_PATH}` : void 0);
|
|
4697
5303
|
const missing = [];
|
|
4698
5304
|
if (!host) missing.push("host (or GATEWAY_HOST env var)");
|
|
4699
5305
|
if (!publicKey) missing.push("publicKey (or GATEWAY_PUBLIC_KEY env var)");
|
|
@@ -4936,7 +5542,7 @@ async function shutdown2() {
|
|
|
4936
5542
|
function isInitialized() {
|
|
4937
5543
|
return state.initialized;
|
|
4938
5544
|
}
|
|
4939
|
-
var
|
|
5545
|
+
var state;
|
|
4940
5546
|
var init_init = __esm({
|
|
4941
5547
|
"src/tracing/init.ts"() {
|
|
4942
5548
|
"use strict";
|
|
@@ -4947,7 +5553,6 @@ var init_init = __esm({
|
|
|
4947
5553
|
init_build();
|
|
4948
5554
|
init_prerequisites();
|
|
4949
5555
|
init_prerequisites();
|
|
4950
|
-
DEFAULT_OTLP_PATH = "/api/public/otel/v1/traces";
|
|
4951
5556
|
state = {
|
|
4952
5557
|
initialized: false,
|
|
4953
5558
|
provider: null
|
|
@@ -4956,124 +5561,94 @@ var init_init = __esm({
|
|
|
4956
5561
|
});
|
|
4957
5562
|
|
|
4958
5563
|
// src/worlds/taskTracing.ts
|
|
4959
|
-
var TaskTracing;
|
|
5564
|
+
var HOST_WITH_AUTHORITY, TRACING_HELD_ELSEWHERE, TaskTracing;
|
|
4960
5565
|
var init_taskTracing = __esm({
|
|
4961
5566
|
"src/worlds/taskTracing.ts"() {
|
|
4962
5567
|
"use strict";
|
|
4963
5568
|
init_prerequisites();
|
|
5569
|
+
init_platformEndpoint();
|
|
5570
|
+
HOST_WITH_AUTHORITY = /^[a-z][a-z0-9+.-]*:\/\/[^/\\?#@\s]+(\/|$)/i;
|
|
5571
|
+
TRACING_HELD_ELSEWHERE = "Tracing in this process already sends spans to another destination or with other keys (an earlier run, or the agent's own tracing.init()), so this run's spans would not reach its own project.";
|
|
4964
5572
|
TaskTracing = class _TaskTracing {
|
|
4965
5573
|
constructor(load = () => Promise.resolve().then(() => (init_init(), init_exports))) {
|
|
4966
5574
|
this.load = load;
|
|
4967
5575
|
}
|
|
4968
5576
|
load;
|
|
4969
5577
|
static warned = false;
|
|
4970
|
-
|
|
4971
|
-
|
|
5578
|
+
static target = null;
|
|
5579
|
+
async start(requested, options) {
|
|
5580
|
+
if (!requested) return false;
|
|
5581
|
+
const endpoint = platformEndpoint(options);
|
|
4972
5582
|
try {
|
|
4973
|
-
|
|
5583
|
+
await this.initOnce(_TaskTracing.config(endpoint));
|
|
4974
5584
|
return true;
|
|
4975
5585
|
} catch (error) {
|
|
4976
|
-
_TaskTracing.warnOnce(error);
|
|
5586
|
+
_TaskTracing.warnOnce(_TaskTracing.reason(error, endpoint));
|
|
4977
5587
|
return false;
|
|
4978
5588
|
}
|
|
4979
5589
|
}
|
|
4980
|
-
|
|
5590
|
+
// init() keeps the first provider for the whole process and ignores later calls, so a later run is
|
|
5591
|
+
// traced only when it exports to the same place with the same keys.
|
|
5592
|
+
async initOnce(config) {
|
|
5593
|
+
const tracing2 = await this.load();
|
|
5594
|
+
const target = JSON.stringify([config.endpoint, config.publicKey, config.secretKey]);
|
|
5595
|
+
if (!tracing2.isInitialized()) {
|
|
5596
|
+
tracing2.init(config);
|
|
5597
|
+
_TaskTracing.target = target;
|
|
5598
|
+
return;
|
|
5599
|
+
}
|
|
5600
|
+
if (_TaskTracing.target !== target) throw new Error(TRACING_HELD_ELSEWHERE);
|
|
5601
|
+
}
|
|
5602
|
+
static config(endpoint) {
|
|
5603
|
+
if (!endpoint) throw new Error(GATEWAY_KEYS_MISSING);
|
|
5604
|
+
return { ...endpoint, endpoint: _TaskTracing.destination(endpoint) };
|
|
5605
|
+
}
|
|
5606
|
+
// B1: a saved login's keys go to their own host only. The redirect is compared as text, never parsed:
|
|
5607
|
+
// a fixed "<host>/" prefix leaves no URL parser room to read another host into it.
|
|
5608
|
+
static destination(endpoint) {
|
|
5609
|
+
const redirect = getEnv(GATEWAY_ENV.ENDPOINT);
|
|
5610
|
+
if (!redirect) return `${endpoint.host}${OTLP_TRACES_PATH}`;
|
|
5611
|
+
if (_TaskTracing.underHost(redirect, endpoint.host) || _TaskTracing.environmentKeys(endpoint)) return redirect;
|
|
5612
|
+
throw new Error(
|
|
5613
|
+
`GATEWAY_OTLP_ENDPOINT is not under ${endpoint.host}, and this run's keys are not GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY: they are sent to ${endpoint.host} only. Unset GATEWAY_OTLP_ENDPOINT, or set both keys in the environment.`
|
|
5614
|
+
);
|
|
5615
|
+
}
|
|
5616
|
+
static underHost(redirect, host) {
|
|
5617
|
+
return HOST_WITH_AUTHORITY.test(host) && redirect.startsWith(`${host}/`);
|
|
5618
|
+
}
|
|
5619
|
+
static environmentKeys(endpoint) {
|
|
5620
|
+
const secretKey = getEnv(GATEWAY_ENV.SECRET_KEY) ?? getEnv(GATEWAY_ENV.API_KEY);
|
|
5621
|
+
return endpoint.publicKey === getEnv(GATEWAY_ENV.PUBLIC_KEY) && endpoint.secretKey === secretKey;
|
|
5622
|
+
}
|
|
5623
|
+
static warnOnce(reason) {
|
|
4981
5624
|
if (_TaskTracing.warned) return;
|
|
4982
5625
|
_TaskTracing.warned = true;
|
|
4983
5626
|
console.warn(
|
|
4984
|
-
`[gatewaysdk.tracing] Task runs in this process are not traced. ${
|
|
5627
|
+
`[gatewaysdk.tracing] Task runs in this process are not traced. ${reason}
|
|
4985
5628
|
Pass --no-trace (trace: false) to run untraced without this warning.`
|
|
4986
5629
|
);
|
|
4987
5630
|
}
|
|
4988
|
-
static reason(error) {
|
|
4989
|
-
if (OpenTelemetryMissing.explains(error))
|
|
4990
|
-
|
|
4991
|
-
|
|
5631
|
+
static reason(error, endpoint) {
|
|
5632
|
+
if (OpenTelemetryMissing.explains(error)) return new OpenTelemetryMissing().message;
|
|
5633
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
5634
|
+
const keys = endpoint ? [endpoint.publicKey, endpoint.secretKey] : [];
|
|
5635
|
+
return keys.reduce((text2, key2) => text2.split(key2).join("[redacted]"), message);
|
|
4992
5636
|
}
|
|
4993
5637
|
};
|
|
4994
5638
|
}
|
|
4995
5639
|
});
|
|
4996
5640
|
|
|
4997
5641
|
// src/worlds/taskRun.ts
|
|
4998
|
-
function
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
async function fileTaskRun(live, runId, model, report, grade, agentError, traced, runDir, options, setRunId) {
|
|
5009
|
-
const aliases = live.aliases;
|
|
5010
|
-
const anchor = aliases[0];
|
|
5011
|
-
const worldsMeta = Object.fromEntries(
|
|
5012
|
-
aliases.map((alias) => [alias, worldRef(live, alias)])
|
|
5013
|
-
);
|
|
5014
|
-
const evals = new GatewayEvalsClient(options);
|
|
5015
|
-
const evaluationId = await evals.createEvaluation(
|
|
5016
|
-
worldRef(live, anchor).versionId,
|
|
5017
|
-
{
|
|
5018
|
-
model,
|
|
5019
|
-
rolloutsPerExample: 1,
|
|
5020
|
-
...setRunId ? { runId: setRunId } : {},
|
|
5021
|
-
metadata: {
|
|
5022
|
-
source: "worlds-task-run",
|
|
5023
|
-
task: {
|
|
5024
|
-
id: live.taskId,
|
|
5025
|
-
version: live.taskVersion,
|
|
5026
|
-
name: live.name,
|
|
5027
|
-
hash: live.hash
|
|
5028
|
-
},
|
|
5029
|
-
anchor,
|
|
5030
|
-
worlds: worldsMeta,
|
|
5031
|
-
runId
|
|
5032
|
-
}
|
|
5033
|
-
}
|
|
5034
|
-
);
|
|
5035
|
-
const reward = grade.reward;
|
|
5036
|
-
const sample = {
|
|
5037
|
-
exampleId: live.name ?? live.taskId ?? runId,
|
|
5038
|
-
task: live.name ?? live.taskId ?? runId,
|
|
5039
|
-
rolloutIndex: 0,
|
|
5040
|
-
prompt: live.instruction,
|
|
5041
|
-
...report === null ? {} : { completion: report },
|
|
5042
|
-
rewards: grade.rewards,
|
|
5043
|
-
info: {
|
|
5044
|
-
sessionId: runId,
|
|
5045
|
-
worlds: Object.fromEntries(
|
|
5046
|
-
aliases.map((alias) => [
|
|
5047
|
-
alias,
|
|
5048
|
-
{
|
|
5049
|
-
...worldRef(live, alias),
|
|
5050
|
-
reward: grade.worlds[alias]?.reward ?? null
|
|
5051
|
-
}
|
|
5052
|
-
])
|
|
5053
|
-
),
|
|
5054
|
-
ungraded: grade.ungraded,
|
|
5055
|
-
traced,
|
|
5056
|
-
runDir,
|
|
5057
|
-
...agentError ? { agentError } : {}
|
|
5058
|
-
}
|
|
5059
|
-
};
|
|
5060
|
-
if (typeof reward === "number") {
|
|
5061
|
-
sample.reward = reward;
|
|
5062
|
-
sample.score = reward;
|
|
5063
|
-
sample.correct = reward >= 1;
|
|
5064
|
-
}
|
|
5065
|
-
await evals.pushSamples(evaluationId, [sample]);
|
|
5066
|
-
await evals.finalizeEvaluation(evaluationId, {
|
|
5067
|
-
status: agentError ? "FAILED" : "COMPLETED",
|
|
5068
|
-
metrics: {
|
|
5069
|
-
...typeof reward === "number" ? { avg_reward: reward } : {},
|
|
5070
|
-
reward,
|
|
5071
|
-
...Object.fromEntries(
|
|
5072
|
-
Object.entries(grade.rewards).map(([k, v]) => [`rewards.${k}`, v])
|
|
5073
|
-
)
|
|
5074
|
-
}
|
|
5075
|
-
});
|
|
5076
|
-
return evaluationId;
|
|
5642
|
+
function taskRunFailure(summary) {
|
|
5643
|
+
if (summary.agentError !== null) return `agent raised: ${summary.agentError}`;
|
|
5644
|
+
if (summary.runError !== null) return `the run stopped: ${summary.runError}`;
|
|
5645
|
+
if (summary.gradeError !== null)
|
|
5646
|
+
return `the task could not be graded: ${summary.gradeError}`;
|
|
5647
|
+
if (summary.fileError !== null)
|
|
5648
|
+
return `the run could not be filed: ${summary.fileError}`;
|
|
5649
|
+
if (summary.filed && summary.evaluationStatus !== "COMPLETED")
|
|
5650
|
+
return `the platform settled evaluation ${summary.evaluationId} as ${summary.evaluationStatus}`;
|
|
5651
|
+
return null;
|
|
5077
5652
|
}
|
|
5078
5653
|
function reportFromResult(result) {
|
|
5079
5654
|
if (result === void 0 || result === null)
|
|
@@ -5091,113 +5666,49 @@ function reportFromResult(result) {
|
|
|
5091
5666
|
);
|
|
5092
5667
|
return { report, extra };
|
|
5093
5668
|
}
|
|
5669
|
+
async function refuseUnreadTools(live) {
|
|
5670
|
+
try {
|
|
5671
|
+
for (const alias of live.aliases)
|
|
5672
|
+
WorldToolsUnread.refuse(`${live.worldRef(alias).slug} (alias ${alias})`, live.session(alias).deprecations);
|
|
5673
|
+
} catch (error) {
|
|
5674
|
+
await live.close({ keepWarm: false }).catch(() => void 0);
|
|
5675
|
+
throw error;
|
|
5676
|
+
}
|
|
5677
|
+
}
|
|
5094
5678
|
async function runTask(ref, agent, opts) {
|
|
5095
5679
|
const runId = `wtr-${(0, import_node_crypto4.randomBytes)(6).toString("hex")}`;
|
|
5096
|
-
const outDir = opts.outDir ?? "runs";
|
|
5097
|
-
const runDir = path.join(outDir, runId);
|
|
5098
|
-
fs.mkdirSync(runDir, { recursive: true });
|
|
5099
5680
|
const options = opts.options ?? {};
|
|
5100
|
-
const
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
await live.manifest()
|
|
5116
|
-
);
|
|
5117
|
-
let agentError = null;
|
|
5118
|
-
let report = null;
|
|
5119
|
-
let extra = {};
|
|
5120
|
-
try {
|
|
5121
|
-
const invoke = () => agent(taskRun);
|
|
5122
|
-
const result = traced ? await (await Promise.resolve().then(() => (init_session(), session_exports))).withSession(runId, invoke) : await invoke();
|
|
5123
|
-
({ report, extra } = reportFromResult(result));
|
|
5124
|
-
} catch (error) {
|
|
5125
|
-
const message = (error instanceof Error ? error.message : String(error)) || "Unknown error";
|
|
5126
|
-
agentError = message.slice(0, 2e3);
|
|
5127
|
-
}
|
|
5128
|
-
if (traced)
|
|
5129
|
-
await Promise.resolve().then(() => (init_init(), init_exports)).then((tracing2) => tracing2.flush()).catch(() => void 0);
|
|
5130
|
-
const grade = report !== null ? await live.grade({ report }) : await live.grade();
|
|
5131
|
-
fs.writeFileSync(
|
|
5132
|
-
path.join(runDir, "manifest.json"),
|
|
5133
|
-
JSON.stringify(taskRun.manifest, null, 2)
|
|
5134
|
-
);
|
|
5135
|
-
fs.writeFileSync(
|
|
5136
|
-
path.join(runDir, "grades.json"),
|
|
5137
|
-
JSON.stringify(grade, null, 2)
|
|
5138
|
-
);
|
|
5139
|
-
if (report) fs.writeFileSync(path.join(runDir, "report.md"), report);
|
|
5140
|
-
const summary = {
|
|
5141
|
-
runId,
|
|
5142
|
-
taskId: live.taskId,
|
|
5143
|
-
taskVersion: live.taskVersion,
|
|
5144
|
-
name: live.name,
|
|
5145
|
-
instruction: taskRun.instruction,
|
|
5146
|
-
model: opts.model,
|
|
5147
|
-
aliases: live.aliases,
|
|
5148
|
-
reward: grade.reward,
|
|
5149
|
-
rewards: grade.rewards,
|
|
5150
|
-
ungraded: grade.ungraded,
|
|
5151
|
-
agentError,
|
|
5152
|
-
report,
|
|
5153
|
-
traced,
|
|
5154
|
-
runDir,
|
|
5155
|
-
durationSeconds: Math.round((Date.now() - started) / 10) / 100,
|
|
5156
|
-
notes: taskRun.notes,
|
|
5157
|
-
filed: false,
|
|
5158
|
-
...extra
|
|
5159
|
-
};
|
|
5160
|
-
if (opts.file !== false) {
|
|
5161
|
-
summary.evaluationId = await fileTaskRun(
|
|
5162
|
-
live,
|
|
5163
|
-
runId,
|
|
5164
|
-
opts.model,
|
|
5165
|
-
report,
|
|
5166
|
-
grade,
|
|
5167
|
-
agentError,
|
|
5168
|
-
traced,
|
|
5169
|
-
runDir,
|
|
5170
|
-
options,
|
|
5171
|
-
opts.setRunId
|
|
5172
|
-
);
|
|
5173
|
-
summary.filed = true;
|
|
5174
|
-
}
|
|
5175
|
-
fs.writeFileSync(
|
|
5176
|
-
path.join(runDir, "run.json"),
|
|
5177
|
-
JSON.stringify(summary, null, 2)
|
|
5178
|
-
);
|
|
5179
|
-
return summary;
|
|
5180
|
-
} finally {
|
|
5181
|
-
if (!opts.keepUp) {
|
|
5182
|
-
try {
|
|
5183
|
-
await live.close({ keepWarm: false });
|
|
5184
|
-
} catch {
|
|
5185
|
-
}
|
|
5186
|
-
}
|
|
5187
|
-
}
|
|
5681
|
+
const opening = new TaskOpening(
|
|
5682
|
+
openTask(ref, {
|
|
5683
|
+
surfaces: opts.surfaces,
|
|
5684
|
+
reuseWarm: opts.reuseWarm,
|
|
5685
|
+
browserTier: opts.browserTier,
|
|
5686
|
+
options
|
|
5687
|
+
}).then(async (live) => {
|
|
5688
|
+
await refuseUnreadTools(live);
|
|
5689
|
+
return new LiveTaskRun(runId, live, opts, options);
|
|
5690
|
+
})
|
|
5691
|
+
);
|
|
5692
|
+
return new RunSignals().during(
|
|
5693
|
+
(signal, urgent) => opening.interrupt(signal, urgent),
|
|
5694
|
+
() => opening.complete(agent)
|
|
5695
|
+
);
|
|
5188
5696
|
}
|
|
5189
|
-
var import_node_crypto4,
|
|
5697
|
+
var import_node_crypto4, path2, TaskRun, FILING_UNFINISHED, describeValue, RESULT_CONTRACT, LiveTaskRun, TaskOpening;
|
|
5190
5698
|
var init_taskRun = __esm({
|
|
5191
5699
|
"src/worlds/taskRun.ts"() {
|
|
5192
5700
|
"use strict";
|
|
5193
5701
|
import_node_crypto4 = require("crypto");
|
|
5194
|
-
|
|
5195
|
-
path = __toESM(require("path"));
|
|
5702
|
+
path2 = __toESM(require("path"));
|
|
5196
5703
|
init_browser();
|
|
5197
5704
|
init_evals();
|
|
5705
|
+
init_runSignals();
|
|
5198
5706
|
init_session2();
|
|
5199
5707
|
init_taskSessions();
|
|
5708
|
+
init_taskRunDir();
|
|
5709
|
+
init_taskRunOutcome();
|
|
5200
5710
|
init_taskTracing();
|
|
5711
|
+
init_worldNotice();
|
|
5201
5712
|
TaskRun = class {
|
|
5202
5713
|
constructor(runId, instruction, model, sessions2, manifest) {
|
|
5203
5714
|
this.runId = runId;
|
|
@@ -5260,8 +5771,127 @@ var init_taskRun = __esm({
|
|
|
5260
5771
|
Object.assign(this.notes, notes);
|
|
5261
5772
|
}
|
|
5262
5773
|
};
|
|
5774
|
+
FILING_UNFINISHED = "the filing did not finish";
|
|
5263
5775
|
describeValue = (value) => Array.isArray(value) ? "array" : value === null ? "null" : typeof value;
|
|
5264
5776
|
RESULT_CONTRACT = "return a string report, an object {report?: string, ...} or nothing";
|
|
5777
|
+
LiveTaskRun = class {
|
|
5778
|
+
constructor(runId, live, opts, options) {
|
|
5779
|
+
this.live = live;
|
|
5780
|
+
this.opts = opts;
|
|
5781
|
+
this.options = options;
|
|
5782
|
+
this.files = new TaskRunDir(path2.join(opts.outDir ?? "runs", runId));
|
|
5783
|
+
this.outcome = new TaskRunOutcome(runId, live, opts.model, this.files.path);
|
|
5784
|
+
}
|
|
5785
|
+
live;
|
|
5786
|
+
opts;
|
|
5787
|
+
options;
|
|
5788
|
+
files;
|
|
5789
|
+
outcome;
|
|
5790
|
+
played = false;
|
|
5791
|
+
interrupted = false;
|
|
5792
|
+
filing = null;
|
|
5793
|
+
ending = null;
|
|
5794
|
+
async complete(agent) {
|
|
5795
|
+
try {
|
|
5796
|
+
await this.play(agent).catch((error) => this.outcome.stopped(error));
|
|
5797
|
+
this.played = true;
|
|
5798
|
+
await this.file();
|
|
5799
|
+
return this.record();
|
|
5800
|
+
} finally {
|
|
5801
|
+
await this.end();
|
|
5802
|
+
}
|
|
5803
|
+
}
|
|
5804
|
+
async interrupt(signal, urgent = false) {
|
|
5805
|
+
const sessions2 = this.opts.keepUp ? "leaving its sessions up" : "closing its sessions";
|
|
5806
|
+
const how = urgent ? " now, without waiting" : "";
|
|
5807
|
+
process.stderr.write(`${this.outcome.runId} interrupted by ${signal}; ${sessions2}${how}
|
|
5808
|
+
`);
|
|
5809
|
+
if (!this.played) this.outcome.stopped(`interrupted by ${signal}`);
|
|
5810
|
+
this.interrupted = true;
|
|
5811
|
+
try {
|
|
5812
|
+
if (!urgent) await this.filing;
|
|
5813
|
+
this.record();
|
|
5814
|
+
} catch (error) {
|
|
5815
|
+
const why = error instanceof Error ? error.message : String(error);
|
|
5816
|
+
process.stderr.write(`${this.outcome.runId}: run.json not written: ${why}
|
|
5817
|
+
`);
|
|
5818
|
+
} finally {
|
|
5819
|
+
await this.end();
|
|
5820
|
+
}
|
|
5821
|
+
}
|
|
5822
|
+
summary() {
|
|
5823
|
+
return this.outcome.summary();
|
|
5824
|
+
}
|
|
5825
|
+
async play(agent) {
|
|
5826
|
+
await this.live.ready();
|
|
5827
|
+
this.outcome.traced = await new TaskTracing().start(this.opts.trace !== false, this.options);
|
|
5828
|
+
const run = new TaskRun(
|
|
5829
|
+
this.outcome.runId,
|
|
5830
|
+
this.live.instruction ?? "",
|
|
5831
|
+
this.opts.model,
|
|
5832
|
+
this.live.sessions,
|
|
5833
|
+
await this.live.manifest()
|
|
5834
|
+
);
|
|
5835
|
+
this.outcome.notes = run.notes;
|
|
5836
|
+
this.files.writeManifest(run.manifest);
|
|
5837
|
+
await this.callAgent(agent, run);
|
|
5838
|
+
const report = this.outcome.report;
|
|
5839
|
+
this.outcome.grade = await this.live.grade(report !== null ? { report } : {});
|
|
5840
|
+
this.files.writeJson("grades.json", this.outcome.grade);
|
|
5841
|
+
if (report) this.files.write("report.md", report);
|
|
5842
|
+
}
|
|
5843
|
+
async callAgent(agent, run) {
|
|
5844
|
+
try {
|
|
5845
|
+
const invoke = () => agent(run);
|
|
5846
|
+
const result = this.outcome.traced ? await (await Promise.resolve().then(() => (init_session(), session_exports))).withSession(run.runId, invoke) : await invoke();
|
|
5847
|
+
({ report: this.outcome.report, extra: this.outcome.extra } = reportFromResult(result));
|
|
5848
|
+
} catch (error) {
|
|
5849
|
+
this.outcome.agentRaised(error);
|
|
5850
|
+
}
|
|
5851
|
+
if (this.outcome.traced)
|
|
5852
|
+
await Promise.resolve().then(() => (init_init(), init_exports)).then((tracing2) => tracing2.flush()).catch(() => void 0);
|
|
5853
|
+
}
|
|
5854
|
+
async file() {
|
|
5855
|
+
if (this.opts.file === false || this.interrupted) return;
|
|
5856
|
+
this.files.writeJson("run.json", { ...this.outcome.summary(), fileError: FILING_UNFINISHED });
|
|
5857
|
+
this.filing = this.outcome.file(new GatewayEvalsClient(this.options), this.opts.setRunId);
|
|
5858
|
+
await this.filing;
|
|
5859
|
+
}
|
|
5860
|
+
record() {
|
|
5861
|
+
const summary = this.outcome.summary();
|
|
5862
|
+
this.files.writeJson("run.json", summary);
|
|
5863
|
+
return summary;
|
|
5864
|
+
}
|
|
5865
|
+
end() {
|
|
5866
|
+
this.ending ??= this.opts.keepUp ? Promise.resolve() : this.live.close({ keepWarm: false }).then(
|
|
5867
|
+
() => void 0,
|
|
5868
|
+
() => void 0
|
|
5869
|
+
);
|
|
5870
|
+
return this.ending;
|
|
5871
|
+
}
|
|
5872
|
+
};
|
|
5873
|
+
TaskOpening = class {
|
|
5874
|
+
interrupting = null;
|
|
5875
|
+
run = null;
|
|
5876
|
+
opened;
|
|
5877
|
+
constructor(opening) {
|
|
5878
|
+
this.opened = opening.then((run) => this.run = run);
|
|
5879
|
+
}
|
|
5880
|
+
async complete(agent) {
|
|
5881
|
+
const run = await this.opened;
|
|
5882
|
+
if (!this.interrupting) return run.complete(agent);
|
|
5883
|
+
await this.interrupting;
|
|
5884
|
+
return run.summary();
|
|
5885
|
+
}
|
|
5886
|
+
interrupt(signal, urgent = false) {
|
|
5887
|
+
if (urgent) return this.run?.interrupt(signal, true) ?? Promise.resolve();
|
|
5888
|
+
this.interrupting ??= this.opened.then(
|
|
5889
|
+
(run) => run.interrupt(signal),
|
|
5890
|
+
() => void 0
|
|
5891
|
+
);
|
|
5892
|
+
return this.interrupting;
|
|
5893
|
+
}
|
|
5894
|
+
};
|
|
5265
5895
|
}
|
|
5266
5896
|
});
|
|
5267
5897
|
|
|
@@ -5341,63 +5971,101 @@ async function runSet(datasetId, agent, opts) {
|
|
|
5341
5971
|
source: opts.source ?? "sdk",
|
|
5342
5972
|
...git && Object.keys(git).length ? { git } : {}
|
|
5343
5973
|
});
|
|
5344
|
-
|
|
5345
|
-
options,
|
|
5346
|
-
"POST",
|
|
5347
|
-
`${SET_RUNS}/${encodeURIComponent(opened.id)}/close`,
|
|
5348
|
-
{ status }
|
|
5349
|
-
);
|
|
5350
|
-
const onInterrupt = () => {
|
|
5351
|
-
void close("failed").finally(() => process.exit(130));
|
|
5352
|
-
};
|
|
5353
|
-
process.once("SIGINT", onInterrupt);
|
|
5354
|
-
const planned = await runPlannedTasks(opened, agent, opts, options).finally(
|
|
5355
|
-
() => process.off("SIGINT", onInterrupt)
|
|
5356
|
-
);
|
|
5357
|
-
const { tasks, failed } = planned;
|
|
5358
|
-
const requested = failed ? "failed" : "completed";
|
|
5359
|
-
const setRun = await close(requested);
|
|
5360
|
-
return {
|
|
5361
|
-
setRun,
|
|
5362
|
-
tasks,
|
|
5363
|
-
failed: failed || setRun.status !== "completed",
|
|
5364
|
-
closedAsRequested: setRun.status === requested
|
|
5365
|
-
};
|
|
5974
|
+
return new SetRunner(opened, agent, opts, options).run();
|
|
5366
5975
|
}
|
|
5367
|
-
|
|
5368
|
-
const tasks = [];
|
|
5369
|
-
let failed = false;
|
|
5370
|
-
for (const task of opened.tasks) {
|
|
5371
|
-
try {
|
|
5372
|
-
const summary = await runTask(task.worldTaskId, agent, {
|
|
5373
|
-
model: opts.model,
|
|
5374
|
-
surfaces: opts.surfaces,
|
|
5375
|
-
browserTier: opts.browserTier,
|
|
5376
|
-
outDir: opts.outDir,
|
|
5377
|
-
trace: opts.trace,
|
|
5378
|
-
setRunId: opened.id,
|
|
5379
|
-
options
|
|
5380
|
-
});
|
|
5381
|
-
tasks.push(summary);
|
|
5382
|
-
failed ||= summary.agentError !== null;
|
|
5383
|
-
opts.onTask?.(summary);
|
|
5384
|
-
} catch (error) {
|
|
5385
|
-
failed = true;
|
|
5386
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
5387
|
-
process.stderr.write(`task ${task.name} could not run: ${message}
|
|
5388
|
-
`);
|
|
5389
|
-
}
|
|
5390
|
-
}
|
|
5391
|
-
return { tasks, failed };
|
|
5392
|
-
}
|
|
5393
|
-
var SET_RUNS;
|
|
5976
|
+
var SET_RUNS, SetRunner;
|
|
5394
5977
|
var init_setRun = __esm({
|
|
5395
5978
|
"src/worlds/setRun.ts"() {
|
|
5396
5979
|
"use strict";
|
|
5397
5980
|
init_worlds();
|
|
5398
5981
|
init_checkoutProvenance();
|
|
5982
|
+
init_runSignals();
|
|
5399
5983
|
init_taskRun();
|
|
5400
5984
|
SET_RUNS = "/api/public/set-runs";
|
|
5985
|
+
SetRunner = class {
|
|
5986
|
+
constructor(opened, agent, opts, options) {
|
|
5987
|
+
this.opened = opened;
|
|
5988
|
+
this.agent = agent;
|
|
5989
|
+
this.opts = opts;
|
|
5990
|
+
this.options = options;
|
|
5991
|
+
}
|
|
5992
|
+
opened;
|
|
5993
|
+
agent;
|
|
5994
|
+
opts;
|
|
5995
|
+
options;
|
|
5996
|
+
tasks = [];
|
|
5997
|
+
failures = [];
|
|
5998
|
+
failed = false;
|
|
5999
|
+
current = null;
|
|
6000
|
+
interrupted = null;
|
|
6001
|
+
signals = new RunSignals();
|
|
6002
|
+
async run() {
|
|
6003
|
+
await this.signals.during(
|
|
6004
|
+
(signal2) => this.interrupt(signal2).then(() => void 0),
|
|
6005
|
+
() => this.runTasks()
|
|
6006
|
+
);
|
|
6007
|
+
const signal = this.signals.signal;
|
|
6008
|
+
if (signal !== null) return this.result(await this.interrupt(signal), "failed");
|
|
6009
|
+
const requested = this.failed ? "failed" : "completed";
|
|
6010
|
+
return this.result(await this.close(requested, this.failures), requested);
|
|
6011
|
+
}
|
|
6012
|
+
interrupt(signal) {
|
|
6013
|
+
const stopped = this.current ? [{ worldTaskId: this.current, reason: `interrupted by ${signal}` }] : [];
|
|
6014
|
+
this.interrupted ??= this.close("failed", [...this.failures, ...stopped]);
|
|
6015
|
+
return this.interrupted;
|
|
6016
|
+
}
|
|
6017
|
+
async runTasks() {
|
|
6018
|
+
for (const task of this.opened.tasks) {
|
|
6019
|
+
if (this.signals.signal !== null) return;
|
|
6020
|
+
this.current = task.worldTaskId;
|
|
6021
|
+
await this.runOne(task);
|
|
6022
|
+
}
|
|
6023
|
+
this.current = null;
|
|
6024
|
+
}
|
|
6025
|
+
async runOne(task) {
|
|
6026
|
+
try {
|
|
6027
|
+
const summary = await runTask(task.worldTaskId, this.agent, {
|
|
6028
|
+
model: this.opts.model,
|
|
6029
|
+
surfaces: this.opts.surfaces,
|
|
6030
|
+
browserTier: this.opts.browserTier,
|
|
6031
|
+
outDir: this.opts.outDir,
|
|
6032
|
+
trace: this.opts.trace,
|
|
6033
|
+
setRunId: this.opened.id,
|
|
6034
|
+
options: this.options
|
|
6035
|
+
});
|
|
6036
|
+
this.tasks.push(summary);
|
|
6037
|
+
this.failed ||= taskRunFailure(summary) !== null;
|
|
6038
|
+
if (summary.fileError !== null)
|
|
6039
|
+
this.failures.push({ worldTaskId: task.worldTaskId, reason: summary.fileError });
|
|
6040
|
+
this.opts.onTask?.(summary);
|
|
6041
|
+
} catch (error) {
|
|
6042
|
+
this.failed = true;
|
|
6043
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
6044
|
+
process.stderr.write(`task ${task.name} could not run: ${message}
|
|
6045
|
+
`);
|
|
6046
|
+
this.failures.push({
|
|
6047
|
+
worldTaskId: task.worldTaskId,
|
|
6048
|
+
reason: message || (error instanceof Error ? error.name : "Error")
|
|
6049
|
+
});
|
|
6050
|
+
}
|
|
6051
|
+
}
|
|
6052
|
+
close(status, failures = []) {
|
|
6053
|
+
return apiRequest(
|
|
6054
|
+
this.options,
|
|
6055
|
+
"POST",
|
|
6056
|
+
`${SET_RUNS}/${encodeURIComponent(this.opened.id)}/close`,
|
|
6057
|
+
{ status, ...failures.length ? { failures } : {} }
|
|
6058
|
+
);
|
|
6059
|
+
}
|
|
6060
|
+
result(setRun, requested) {
|
|
6061
|
+
return {
|
|
6062
|
+
setRun,
|
|
6063
|
+
tasks: this.tasks,
|
|
6064
|
+
failed: this.failed || setRun.status !== "completed",
|
|
6065
|
+
closedAsRequested: setRun.status === requested
|
|
6066
|
+
};
|
|
6067
|
+
}
|
|
6068
|
+
};
|
|
5401
6069
|
}
|
|
5402
6070
|
});
|
|
5403
6071
|
|
|
@@ -5448,12 +6116,12 @@ var init_requestLog = __esm({
|
|
|
5448
6116
|
});
|
|
5449
6117
|
|
|
5450
6118
|
// src/worlds/checkoutTarget.ts
|
|
5451
|
-
var fs2,
|
|
6119
|
+
var fs2, path3, CheckoutRefusedError, NAMED_EDITS, CheckoutTarget;
|
|
5452
6120
|
var init_checkoutTarget = __esm({
|
|
5453
6121
|
"src/worlds/checkoutTarget.ts"() {
|
|
5454
6122
|
"use strict";
|
|
5455
6123
|
fs2 = __toESM(require("fs"));
|
|
5456
|
-
|
|
6124
|
+
path3 = __toESM(require("path"));
|
|
5457
6125
|
CheckoutRefusedError = class extends Error {
|
|
5458
6126
|
constructor(message) {
|
|
5459
6127
|
super(`checkout refused: ${message}`);
|
|
@@ -5478,17 +6146,17 @@ var init_checkoutTarget = __esm({
|
|
|
5478
6146
|
}
|
|
5479
6147
|
/** The absolute destination; a relative target may not resolve above `cwd`. */
|
|
5480
6148
|
static confined(target, cwd) {
|
|
5481
|
-
const dir =
|
|
5482
|
-
if (
|
|
5483
|
-
const rel =
|
|
5484
|
-
if (rel === "" || !rel.startsWith("..") && !
|
|
6149
|
+
const dir = path3.resolve(cwd, target);
|
|
6150
|
+
if (path3.isAbsolute(target)) return dir;
|
|
6151
|
+
const rel = path3.relative(cwd, dir);
|
|
6152
|
+
if (rel === "" || !rel.startsWith("..") && !path3.isAbsolute(rel))
|
|
5485
6153
|
return dir;
|
|
5486
6154
|
throw new CheckoutRefusedError(
|
|
5487
6155
|
`--target ${target} resolves outside the current directory (${cwd}) \u2014 run from that directory, or pass an absolute path`
|
|
5488
6156
|
);
|
|
5489
6157
|
}
|
|
5490
6158
|
static fresh(slug, cwd) {
|
|
5491
|
-
const base =
|
|
6159
|
+
const base = path3.join(cwd, slug);
|
|
5492
6160
|
let dir = base;
|
|
5493
6161
|
let i = 1;
|
|
5494
6162
|
while (fs2.existsSync(dir)) dir = `${base}-${i++}`;
|
|
@@ -5515,7 +6183,7 @@ var init_checkoutTarget = __esm({
|
|
|
5515
6183
|
].filter(_CheckoutTarget.confinedRel).sort();
|
|
5516
6184
|
}
|
|
5517
6185
|
static confinedRel(rel) {
|
|
5518
|
-
if (rel === "" ||
|
|
6186
|
+
if (rel === "" || path3.isAbsolute(rel)) return false;
|
|
5519
6187
|
return !rel.split(/[\\/]/).includes("..");
|
|
5520
6188
|
}
|
|
5521
6189
|
/** Why `dir` cannot be overwritten, or null when it is a clean checkout of `slug`. */
|
|
@@ -5533,9 +6201,9 @@ var init_checkoutTarget = __esm({
|
|
|
5533
6201
|
/** Remove the replaced checkout's files (and the dirs they leave empty). */
|
|
5534
6202
|
clear() {
|
|
5535
6203
|
for (const rel of this.replaces) {
|
|
5536
|
-
const abs =
|
|
6204
|
+
const abs = path3.join(this.dir, rel);
|
|
5537
6205
|
fs2.rmSync(abs, { force: true });
|
|
5538
|
-
this.pruneEmptyParents(
|
|
6206
|
+
this.pruneEmptyParents(path3.dirname(abs));
|
|
5539
6207
|
}
|
|
5540
6208
|
}
|
|
5541
6209
|
pruneEmptyParents(from) {
|
|
@@ -5543,7 +6211,7 @@ var init_checkoutTarget = __esm({
|
|
|
5543
6211
|
while (cur !== this.dir && cur.startsWith(this.dir)) {
|
|
5544
6212
|
if (fs2.existsSync(cur) && fs2.readdirSync(cur).length > 0) return;
|
|
5545
6213
|
fs2.rmSync(cur, { recursive: true, force: true });
|
|
5546
|
-
cur =
|
|
6214
|
+
cur = path3.dirname(cur);
|
|
5547
6215
|
}
|
|
5548
6216
|
}
|
|
5549
6217
|
};
|
|
@@ -5551,13 +6219,13 @@ var init_checkoutTarget = __esm({
|
|
|
5551
6219
|
});
|
|
5552
6220
|
|
|
5553
6221
|
// src/worlds/worldDir.ts
|
|
5554
|
-
var import_node_crypto5, fs3,
|
|
6222
|
+
var import_node_crypto5, fs3, path4, WORLD_MANIFEST, API_BUNDLE_MANIFEST, BUNDLED_WORLD_PREFIX, CONNECTOR_SPEC, PYPROJECT, BENCHMARK_CONFIG, WORLD_SCHEMA_MARKERS, WORLD_ROOT_MARKERS, BROAD_ROOT_MARKERS, SKIPPED_DIRS, V1_DEP, V1_IMPORT, V1_TASKSET, HARBOR_TASK, skippedDir, byCodePoint, WorldDir;
|
|
5555
6223
|
var init_worldDir = __esm({
|
|
5556
6224
|
"src/worlds/worldDir.ts"() {
|
|
5557
6225
|
"use strict";
|
|
5558
6226
|
import_node_crypto5 = require("crypto");
|
|
5559
6227
|
fs3 = __toESM(require("fs"));
|
|
5560
|
-
|
|
6228
|
+
path4 = __toESM(require("path"));
|
|
5561
6229
|
WORLD_MANIFEST = "gateway-env.toml";
|
|
5562
6230
|
API_BUNDLE_MANIFEST = "gateway-api-world.toml";
|
|
5563
6231
|
BUNDLED_WORLD_PREFIX = "server/world/";
|
|
@@ -5583,17 +6251,17 @@ var init_worldDir = __esm({
|
|
|
5583
6251
|
worldRoot;
|
|
5584
6252
|
pathsMemo;
|
|
5585
6253
|
static open(dir) {
|
|
5586
|
-
const present = (rel) => fs3.existsSync(
|
|
6254
|
+
const present = (rel) => fs3.existsSync(path4.join(dir, rel));
|
|
5587
6255
|
const bundled = present(API_BUNDLE_MANIFEST) && WORLD_ROOT_MARKERS.some((m) => present(BUNDLED_WORLD_PREFIX + m));
|
|
5588
6256
|
return new _WorldDir(dir, bundled ? BUNDLED_WORLD_PREFIX : "");
|
|
5589
6257
|
}
|
|
5590
6258
|
// ── Files ──────────────────────────────────────────────────────────────
|
|
5591
6259
|
has(rel) {
|
|
5592
|
-
return fs3.existsSync(
|
|
6260
|
+
return fs3.existsSync(path4.join(this.dir, rel));
|
|
5593
6261
|
}
|
|
5594
6262
|
text(rel) {
|
|
5595
6263
|
try {
|
|
5596
|
-
return fs3.readFileSync(
|
|
6264
|
+
return fs3.readFileSync(path4.join(this.dir, rel), "utf-8");
|
|
5597
6265
|
} catch {
|
|
5598
6266
|
return null;
|
|
5599
6267
|
}
|
|
@@ -5612,7 +6280,7 @@ var init_worldDir = __esm({
|
|
|
5612
6280
|
const broad = BROAD_ROOT_MARKERS.some((m) => this.has(m));
|
|
5613
6281
|
const out = [];
|
|
5614
6282
|
const walk = (rel) => {
|
|
5615
|
-
for (const entry of fs3.readdirSync(rel ?
|
|
6283
|
+
for (const entry of fs3.readdirSync(rel ? path4.join(this.dir, rel) : this.dir, { withFileTypes: true })) {
|
|
5616
6284
|
const child = rel ? `${rel}/${entry.name}` : entry.name;
|
|
5617
6285
|
if (entry.isDirectory()) {
|
|
5618
6286
|
if (!skippedDir(entry.name)) walk(child);
|
|
@@ -5633,7 +6301,7 @@ var init_worldDir = __esm({
|
|
|
5633
6301
|
get exclusions() {
|
|
5634
6302
|
const kept = new Set(this.archivePaths);
|
|
5635
6303
|
const out = [];
|
|
5636
|
-
const filesUnder = (rel) => fs3.readdirSync(
|
|
6304
|
+
const filesUnder = (rel) => fs3.readdirSync(path4.join(this.dir, rel), { withFileTypes: true }).flatMap((entry) => {
|
|
5637
6305
|
const child = `${rel}/${entry.name}`;
|
|
5638
6306
|
if (entry.isDirectory()) return filesUnder(child);
|
|
5639
6307
|
return entry.isFile() ? [child] : [];
|
|
@@ -5664,7 +6332,7 @@ var init_worldDir = __esm({
|
|
|
5664
6332
|
const hasher = (0, import_node_crypto5.createHash)("sha256");
|
|
5665
6333
|
for (const rel of this.archivePaths) {
|
|
5666
6334
|
hasher.update(Buffer.from(`file:${rel}`, "utf-8"));
|
|
5667
|
-
hasher.update(fs3.readFileSync(
|
|
6335
|
+
hasher.update(fs3.readFileSync(path4.join(this.dir, rel)));
|
|
5668
6336
|
}
|
|
5669
6337
|
return hasher.digest("hex");
|
|
5670
6338
|
}
|
|
@@ -5754,12 +6422,12 @@ function paxPath(body) {
|
|
|
5754
6422
|
}
|
|
5755
6423
|
return found;
|
|
5756
6424
|
}
|
|
5757
|
-
var fs4,
|
|
6425
|
+
var fs4, path5, import_node_zlib, TAR_FILE_MODE, TAR_EXEC_MODE, TarArchive;
|
|
5758
6426
|
var init_tar = __esm({
|
|
5759
6427
|
"src/worlds/tar.ts"() {
|
|
5760
6428
|
"use strict";
|
|
5761
6429
|
fs4 = __toESM(require("fs"));
|
|
5762
|
-
|
|
6430
|
+
path5 = __toESM(require("path"));
|
|
5763
6431
|
import_node_zlib = require("zlib");
|
|
5764
6432
|
TAR_FILE_MODE = 420;
|
|
5765
6433
|
TAR_EXEC_MODE = 493;
|
|
@@ -5815,8 +6483,8 @@ var init_tar = __esm({
|
|
|
5815
6483
|
for (const member of this.members()) {
|
|
5816
6484
|
if (member.typeflag !== "0" && member.typeflag !== "\0") continue;
|
|
5817
6485
|
if (!_TarArchive.isConfined(member.name)) continue;
|
|
5818
|
-
const target =
|
|
5819
|
-
fs4.mkdirSync(
|
|
6486
|
+
const target = path5.join(dir, member.name);
|
|
6487
|
+
fs4.mkdirSync(path5.dirname(target), { recursive: true });
|
|
5820
6488
|
const mode = archiveMode(member.mode);
|
|
5821
6489
|
fs4.writeFileSync(target, member.bytes, { mode });
|
|
5822
6490
|
fs4.chmodSync(target, mode);
|
|
@@ -5919,7 +6587,7 @@ function tarMember(name, payload, mode) {
|
|
|
5919
6587
|
function buildSourceTarball(dir) {
|
|
5920
6588
|
const parts2 = [];
|
|
5921
6589
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
5922
|
-
const abs =
|
|
6590
|
+
const abs = path6.join(dir, relPath);
|
|
5923
6591
|
parts2.push(
|
|
5924
6592
|
...tarMember(
|
|
5925
6593
|
relPath,
|
|
@@ -5933,7 +6601,7 @@ function buildSourceTarball(dir) {
|
|
|
5933
6601
|
}
|
|
5934
6602
|
function readLocalMeta(dir) {
|
|
5935
6603
|
try {
|
|
5936
|
-
const raw = fs5.readFileSync(
|
|
6604
|
+
const raw = fs5.readFileSync(path6.join(dir, META_RELPATH), "utf-8");
|
|
5937
6605
|
const parsed = JSON.parse(raw);
|
|
5938
6606
|
return parsed && typeof parsed === "object" ? parsed : null;
|
|
5939
6607
|
} catch {
|
|
@@ -5956,16 +6624,16 @@ function resolvePushSlug(dir, opts = {}) {
|
|
|
5956
6624
|
}
|
|
5957
6625
|
const first = declared[0];
|
|
5958
6626
|
if (first) return { ...base, slug: first.slug, source: first.source };
|
|
5959
|
-
return { ...base, slug:
|
|
6627
|
+
return { ...base, slug: path6.basename(path6.resolve(dir)), source: "directory name" };
|
|
5960
6628
|
}
|
|
5961
6629
|
function writeLocalMeta(dir, meta) {
|
|
5962
|
-
fs5.mkdirSync(
|
|
5963
|
-
fs5.writeFileSync(
|
|
6630
|
+
fs5.mkdirSync(path6.join(dir, ".gateway"), { recursive: true });
|
|
6631
|
+
fs5.writeFileSync(path6.join(dir, META_RELPATH), JSON.stringify(meta, null, 2));
|
|
5964
6632
|
}
|
|
5965
6633
|
function snapshotTreeHashes(dir) {
|
|
5966
6634
|
const out = {};
|
|
5967
6635
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
5968
|
-
out[relPath] = (0, import_node_crypto6.createHash)("sha256").update(fs5.readFileSync(
|
|
6636
|
+
out[relPath] = (0, import_node_crypto6.createHash)("sha256").update(fs5.readFileSync(path6.join(dir, relPath))).digest("hex");
|
|
5969
6637
|
}
|
|
5970
6638
|
return out;
|
|
5971
6639
|
}
|
|
@@ -5983,7 +6651,7 @@ function localTreeState(dir) {
|
|
|
5983
6651
|
}
|
|
5984
6652
|
function readPyproject(dir) {
|
|
5985
6653
|
try {
|
|
5986
|
-
const text2 = fs5.readFileSync(
|
|
6654
|
+
const text2 = fs5.readFileSync(path6.join(dir, "pyproject.toml"), "utf-8");
|
|
5987
6655
|
const section = /\[project\]([\s\S]*?)(\n\[|$)/.exec(text2)?.[1] ?? "";
|
|
5988
6656
|
const name = /\bname\s*=\s*"([^"]+)"/.exec(section)?.[1];
|
|
5989
6657
|
const version = /\bversion\s*=\s*"([^"]+)"/.exec(section)?.[1];
|
|
@@ -6006,7 +6674,7 @@ function readWorldContractVersion(dir) {
|
|
|
6006
6674
|
}
|
|
6007
6675
|
function buildFileManifest(dir) {
|
|
6008
6676
|
return collectArchiveRelPaths(dir).map((relPath) => {
|
|
6009
|
-
const payload = fs5.readFileSync(
|
|
6677
|
+
const payload = fs5.readFileSync(path6.join(dir, relPath));
|
|
6010
6678
|
return {
|
|
6011
6679
|
path: relPath,
|
|
6012
6680
|
isDirectory: false,
|
|
@@ -6052,7 +6720,7 @@ async function push(dir, opts = {}) {
|
|
|
6052
6720
|
const pyproject = readPyproject(dir);
|
|
6053
6721
|
const contractVersion = pyproject.version ? void 0 : readWorldContractVersion(dir).version;
|
|
6054
6722
|
if (contractVersion) pyproject.version = contractVersion;
|
|
6055
|
-
const slug = opts.slug ?? localMeta.slug ?? pyproject.name ??
|
|
6723
|
+
const slug = opts.slug ?? localMeta.slug ?? pyproject.name ?? path6.basename(path6.resolve(dir));
|
|
6056
6724
|
const metadata = {
|
|
6057
6725
|
...opts.name !== void 0 ? { name: opts.name } : {},
|
|
6058
6726
|
...opts.description !== void 0 ? { description: opts.description } : {},
|
|
@@ -6178,7 +6846,7 @@ async function propose(dir, opts) {
|
|
|
6178
6846
|
if (state2.clean)
|
|
6179
6847
|
throw new Error("Nothing to propose \u2014 the tree matches its base.");
|
|
6180
6848
|
const changes = state2.dirty.map((relPath) => {
|
|
6181
|
-
const abs =
|
|
6849
|
+
const abs = path6.join(dir, relPath);
|
|
6182
6850
|
if (!fs5.existsSync(abs))
|
|
6183
6851
|
return { path: relPath, action: "delete" };
|
|
6184
6852
|
return {
|
|
@@ -6210,20 +6878,20 @@ async function createRef(slug, name, kind, versionId, options = {}) {
|
|
|
6210
6878
|
...versionId ? { versionId } : {}
|
|
6211
6879
|
});
|
|
6212
6880
|
}
|
|
6213
|
-
var import_node_crypto6, import_node_zlib2, fs5,
|
|
6881
|
+
var import_node_crypto6, import_node_zlib2, fs5, path6, DEFAULT_BRANCH, META_RELPATH, FILE_MODE, MINTED_SUFFIX, PushSlugConflict, sha256b64, DetachedPushError;
|
|
6214
6882
|
var init_hub = __esm({
|
|
6215
6883
|
"src/worlds/hub.ts"() {
|
|
6216
6884
|
"use strict";
|
|
6217
6885
|
import_node_crypto6 = require("crypto");
|
|
6218
6886
|
import_node_zlib2 = require("zlib");
|
|
6219
6887
|
fs5 = __toESM(require("fs"));
|
|
6220
|
-
|
|
6888
|
+
path6 = __toESM(require("path"));
|
|
6221
6889
|
init_worlds();
|
|
6222
6890
|
init_checkoutTarget();
|
|
6223
6891
|
init_worldDir();
|
|
6224
6892
|
init_tar();
|
|
6225
6893
|
DEFAULT_BRANCH = "main";
|
|
6226
|
-
META_RELPATH =
|
|
6894
|
+
META_RELPATH = path6.join(".gateway", ".env-metadata.json");
|
|
6227
6895
|
FILE_MODE = TAR_FILE_MODE;
|
|
6228
6896
|
MINTED_SUFFIX = /^-\d+$/;
|
|
6229
6897
|
PushSlugConflict = class extends Error {
|
|
@@ -6451,7 +7119,7 @@ function rebaseConflicts(error) {
|
|
|
6451
7119
|
}
|
|
6452
7120
|
const conflicts = body?.conflicts;
|
|
6453
7121
|
if (!Array.isArray(conflicts)) return null;
|
|
6454
|
-
return conflicts.filter(isConflictPath).map(({ path:
|
|
7122
|
+
return conflicts.filter(isConflictPath).map(({ path: path17, reason }) => ({ path: path17, reason }));
|
|
6455
7123
|
}
|
|
6456
7124
|
function isConflictPath(value) {
|
|
6457
7125
|
const entry = value;
|
|
@@ -6491,8 +7159,8 @@ var init_sandbox = __esm({
|
|
|
6491
7159
|
this.options = options;
|
|
6492
7160
|
}
|
|
6493
7161
|
options;
|
|
6494
|
-
request(method,
|
|
6495
|
-
return apiRequest(this.options, method,
|
|
7162
|
+
request(method, path17, body) {
|
|
7163
|
+
return apiRequest(this.options, method, path17, body, {
|
|
6496
7164
|
timeoutMs: SANDBOX_REQUEST_TIMEOUT_MS
|
|
6497
7165
|
});
|
|
6498
7166
|
}
|
|
@@ -7023,6 +7691,17 @@ async function queryRows(slugRef, entity, opts = {}, options = {}) {
|
|
|
7023
7691
|
`/api/public/worlds/${encodeURIComponent(slug)}/data${queryRowsSearch(entity, opts, ref)}`
|
|
7024
7692
|
);
|
|
7025
7693
|
}
|
|
7694
|
+
async function sqlRows(slugRef, sql, opts = {}, options = {}) {
|
|
7695
|
+
const [slug, ref] = slugRef.split("@", 2);
|
|
7696
|
+
if (!slug || ref === "") throw new Error(`sqlRows needs a slug, optionally slug@ref (got ${slugRef})`);
|
|
7697
|
+
if (!sql.trim()) throw new Error("sqlRows needs one SQL statement");
|
|
7698
|
+
return apiRequest(options, "POST", `/api/public/worlds/${encodeURIComponent(slug)}/data/sql`, {
|
|
7699
|
+
sql,
|
|
7700
|
+
...ref ? { ref } : {},
|
|
7701
|
+
...opts.limit !== void 0 ? { limit: opts.limit } : {},
|
|
7702
|
+
...opts.scenario ? { scenario: opts.scenario } : {}
|
|
7703
|
+
});
|
|
7704
|
+
}
|
|
7026
7705
|
var init_query = __esm({
|
|
7027
7706
|
"src/worlds/query.ts"() {
|
|
7028
7707
|
"use strict";
|
|
@@ -7082,13 +7761,13 @@ async function api(creds, method, route, body, init3 = {}) {
|
|
|
7082
7761
|
if (!reply.ok) throw new ApiError2(reply.status, method, route, reply.text);
|
|
7083
7762
|
return reply.text ? JSON.parse(reply.text) : {};
|
|
7084
7763
|
}
|
|
7085
|
-
var fs6, os,
|
|
7764
|
+
var fs6, os, path7, ApiError2;
|
|
7086
7765
|
var init_config = __esm({
|
|
7087
7766
|
"src/cli/config.ts"() {
|
|
7088
7767
|
"use strict";
|
|
7089
7768
|
fs6 = __toESM(require("fs"));
|
|
7090
7769
|
os = __toESM(require("os"));
|
|
7091
|
-
|
|
7770
|
+
path7 = __toESM(require("path"));
|
|
7092
7771
|
init_router();
|
|
7093
7772
|
init_worlds();
|
|
7094
7773
|
init_transport();
|
|
@@ -7126,16 +7805,16 @@ function runtimeRoot() {
|
|
|
7126
7805
|
const candidates = [];
|
|
7127
7806
|
if (process.env.GATEWAY_RUNTIME_PATH)
|
|
7128
7807
|
candidates.push(process.env.GATEWAY_RUNTIME_PATH);
|
|
7129
|
-
const entry = process.argv[1] && fs7.existsSync(process.argv[1]) ?
|
|
7808
|
+
const entry = process.argv[1] && fs7.existsSync(process.argv[1]) ? path8.dirname(fs7.realpathSync(process.argv[1])) : null;
|
|
7130
7809
|
if (entry) {
|
|
7131
|
-
candidates.push(
|
|
7132
|
-
candidates.push(
|
|
7133
|
-
candidates.push(
|
|
7810
|
+
candidates.push(path8.resolve(entry, "..", "runtime"));
|
|
7811
|
+
candidates.push(path8.resolve(entry, "..", "..", "runtime"));
|
|
7812
|
+
candidates.push(path8.resolve(entry, "..", "..", "sdk", "src"));
|
|
7134
7813
|
}
|
|
7135
|
-
candidates.push(
|
|
7814
|
+
candidates.push(path8.resolve(process.cwd(), "runtime"));
|
|
7136
7815
|
for (const root of candidates)
|
|
7137
7816
|
if (fs7.existsSync(
|
|
7138
|
-
|
|
7817
|
+
path8.join(root, "gatewaysdk", "environment", "schema", "platform.py")
|
|
7139
7818
|
))
|
|
7140
7819
|
return root;
|
|
7141
7820
|
return null;
|
|
@@ -7224,13 +7903,12 @@ async function localBridge(request, local, opts = {}) {
|
|
|
7224
7903
|
["-I", "-B", "-c", BRIDGE_BOOTSTRAP, local.root],
|
|
7225
7904
|
{
|
|
7226
7905
|
stdio: ["pipe", "pipe", "pipe"],
|
|
7227
|
-
//
|
|
7228
|
-
// place the runtime may import and run a world's own Python (check's
|
|
7229
|
-
// handler execution, `worlds call`, `worlds test` tool cases).
|
|
7906
|
+
// The author's machine running the author's world: the one place the runtime may run its Python.
|
|
7230
7907
|
env: {
|
|
7231
7908
|
PATH: process.env.PATH ?? "",
|
|
7232
7909
|
HOME: process.env.HOME ?? "",
|
|
7233
7910
|
TMPDIR: process.env.TMPDIR ?? "",
|
|
7911
|
+
...process.env.VIRTUAL_ENV ? { VIRTUAL_ENV: process.env.VIRTUAL_ENV } : {},
|
|
7234
7912
|
GATEWAY_RUNTIME_EXECUTE: "1"
|
|
7235
7913
|
}
|
|
7236
7914
|
}
|
|
@@ -7276,14 +7954,14 @@ async function localBridge(request, local, opts = {}) {
|
|
|
7276
7954
|
child.stdin.end(input);
|
|
7277
7955
|
});
|
|
7278
7956
|
}
|
|
7279
|
-
var import_node_child_process2, fs7, net,
|
|
7957
|
+
var import_node_child_process2, fs7, net, path8, MIN_PYTHON, MIN_PYTHON_LABEL, DIAGNOSTIC_TAIL, BRIDGE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
|
|
7280
7958
|
var init_local = __esm({
|
|
7281
7959
|
"src/cli/runtime/local.ts"() {
|
|
7282
7960
|
"use strict";
|
|
7283
7961
|
import_node_child_process2 = require("child_process");
|
|
7284
7962
|
fs7 = __toESM(require("fs"));
|
|
7285
7963
|
net = __toESM(require("net"));
|
|
7286
|
-
|
|
7964
|
+
path8 = __toESM(require("path"));
|
|
7287
7965
|
init_router();
|
|
7288
7966
|
init_config();
|
|
7289
7967
|
MIN_PYTHON = [3, 12];
|
|
@@ -7306,16 +7984,44 @@ runpy.run_module('gatewaysdk.environment.schema.platform',run_name='__main__')`;
|
|
|
7306
7984
|
}
|
|
7307
7985
|
});
|
|
7308
7986
|
|
|
7987
|
+
// src/worlds/databaseEngines.ts
|
|
7988
|
+
function isWorldSnapshotOutput(path17) {
|
|
7989
|
+
return SNAPSHOT_OUTPUTS.has(path17.slice(path17.lastIndexOf("/") + 1));
|
|
7990
|
+
}
|
|
7991
|
+
var WORLD_DATABASE_ENGINES, DEFAULT_WORLD_DATABASE_ENGINE, WORLD_SNAPSHOT_FILE_PATH, WORLD_SNAPSHOT_SIDECAR_PATH, WORLD_SNAPSHOT_CONTENT_TYPE, SNAPSHOT_OUTPUTS;
|
|
7992
|
+
var init_databaseEngines = __esm({
|
|
7993
|
+
"src/worlds/databaseEngines.ts"() {
|
|
7994
|
+
"use strict";
|
|
7995
|
+
WORLD_DATABASE_ENGINES = [
|
|
7996
|
+
{
|
|
7997
|
+
engine: "sqlite",
|
|
7998
|
+
label: "SQLite",
|
|
7999
|
+
target: "sqlite-json/1",
|
|
8000
|
+
snapshotName: "state.sqlite",
|
|
8001
|
+
contentType: "application/vnd.sqlite3"
|
|
8002
|
+
}
|
|
8003
|
+
];
|
|
8004
|
+
DEFAULT_WORLD_DATABASE_ENGINE = WORLD_DATABASE_ENGINES[0];
|
|
8005
|
+
WORLD_SNAPSHOT_FILE_PATH = `db/${DEFAULT_WORLD_DATABASE_ENGINE.snapshotName}`;
|
|
8006
|
+
WORLD_SNAPSHOT_SIDECAR_PATH = "db/state.json";
|
|
8007
|
+
WORLD_SNAPSHOT_CONTENT_TYPE = DEFAULT_WORLD_DATABASE_ENGINE.contentType;
|
|
8008
|
+
SNAPSHOT_OUTPUTS = /* @__PURE__ */ new Set([
|
|
8009
|
+
...WORLD_DATABASE_ENGINES.map((engine) => engine.snapshotName),
|
|
8010
|
+
WORLD_SNAPSHOT_SIDECAR_PATH.slice("db/".length)
|
|
8011
|
+
]);
|
|
8012
|
+
}
|
|
8013
|
+
});
|
|
8014
|
+
|
|
7309
8015
|
// src/cli/runtime/client.ts
|
|
7310
8016
|
function isBuildOutput(relPath) {
|
|
7311
|
-
return
|
|
8017
|
+
return isWorldSnapshotOutput(relPath);
|
|
7312
8018
|
}
|
|
7313
8019
|
function readWorldFiles(dir, opts = {}) {
|
|
7314
8020
|
if (!fs8.existsSync(dir) || !fs8.statSync(dir).isDirectory())
|
|
7315
8021
|
throw new CliError(`Not a directory: ${dir}`);
|
|
7316
8022
|
const out = [];
|
|
7317
8023
|
const walk = (rel) => {
|
|
7318
|
-
const abs = rel ?
|
|
8024
|
+
const abs = rel ? path9.join(dir, rel) : dir;
|
|
7319
8025
|
const entries = fs8.readdirSync(abs, { withFileTypes: true });
|
|
7320
8026
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
7321
8027
|
for (const entry of entries) {
|
|
@@ -7326,7 +8032,7 @@ function readWorldFiles(dir, opts = {}) {
|
|
|
7326
8032
|
if (!opts.buildOutputs && isBuildOutput(childRel)) continue;
|
|
7327
8033
|
out.push({
|
|
7328
8034
|
path: childRel,
|
|
7329
|
-
content: fs8.readFileSync(
|
|
8035
|
+
content: fs8.readFileSync(path9.join(dir, childRel)).toString("base64")
|
|
7330
8036
|
});
|
|
7331
8037
|
}
|
|
7332
8038
|
}
|
|
@@ -7346,15 +8052,15 @@ function writeWorldFiles(dir, files, opts = {}) {
|
|
|
7346
8052
|
if (opts.clean && fs8.existsSync(dir)) {
|
|
7347
8053
|
const keep = new Set(files.map((f) => f.path));
|
|
7348
8054
|
for (const existing of readWorldFiles(dir)) {
|
|
7349
|
-
if (!keep.has(existing.path)) fs8.rmSync(
|
|
8055
|
+
if (!keep.has(existing.path)) fs8.rmSync(path9.join(dir, existing.path));
|
|
7350
8056
|
}
|
|
7351
8057
|
pruneEmptyDirs(dir);
|
|
7352
8058
|
}
|
|
7353
8059
|
fs8.mkdirSync(dir, { recursive: true });
|
|
7354
8060
|
const written = [];
|
|
7355
8061
|
for (const file of files) {
|
|
7356
|
-
const target =
|
|
7357
|
-
fs8.mkdirSync(
|
|
8062
|
+
const target = path9.join(dir, file.path);
|
|
8063
|
+
fs8.mkdirSync(path9.dirname(target), { recursive: true });
|
|
7358
8064
|
fs8.writeFileSync(target, Buffer.from(file.content, "base64"));
|
|
7359
8065
|
written.push(file.path);
|
|
7360
8066
|
}
|
|
@@ -7364,7 +8070,7 @@ function pruneEmptyDirs(root) {
|
|
|
7364
8070
|
const walk = (abs) => {
|
|
7365
8071
|
let empty = true;
|
|
7366
8072
|
for (const entry of fs8.readdirSync(abs, { withFileTypes: true })) {
|
|
7367
|
-
const child =
|
|
8073
|
+
const child = path9.join(abs, entry.name);
|
|
7368
8074
|
if (entry.isDirectory()) {
|
|
7369
8075
|
if (SKIP_DIRS.has(entry.name)) {
|
|
7370
8076
|
empty = false;
|
|
@@ -7401,13 +8107,9 @@ function yamlDocument(request) {
|
|
|
7401
8107
|
return isYamlSource(String(request.source ?? ""), String(request.document ?? ""));
|
|
7402
8108
|
return request.command === "conform" && Array.isArray(request.openapi) && request.openapi.some((doc) => YAML_NAME.test(doc.path ?? ""));
|
|
7403
8109
|
}
|
|
7404
|
-
function runsLocally(request) {
|
|
7405
|
-
const local = localRuntime();
|
|
7406
|
-
return local !== null && !(yamlDocument(request) && !localPythonHasYaml(local.python));
|
|
7407
|
-
}
|
|
7408
8110
|
async function runtime(creds, request, opts = {}) {
|
|
7409
|
-
const local =
|
|
7410
|
-
if (local
|
|
8111
|
+
const local = new RuntimeRoute().local(request);
|
|
8112
|
+
if (local) {
|
|
7411
8113
|
const payload2 = await localBridge(request, local, opts);
|
|
7412
8114
|
const detail2 = detailFrom(payload2);
|
|
7413
8115
|
if (detail2) throw new BridgeRejected(detail2);
|
|
@@ -7434,19 +8136,19 @@ async function runtime(creds, request, opts = {}) {
|
|
|
7434
8136
|
if (payload === null) throw new CliError(`POST ${route} (${request.command}) returned non-JSON`, 1);
|
|
7435
8137
|
return payload;
|
|
7436
8138
|
}
|
|
7437
|
-
var fs8,
|
|
8139
|
+
var fs8, path9, MAX_WORLD_FILES, RUNTIME_TIMEOUT_MS, SKIP_DIRS, BridgeRejected, YAML_NAME, YAML_NEEDS_PYYAML, YAML_NOT_ON_PLATFORM, RuntimeRoute;
|
|
7438
8140
|
var init_client = __esm({
|
|
7439
8141
|
"src/cli/runtime/client.ts"() {
|
|
7440
8142
|
"use strict";
|
|
7441
8143
|
fs8 = __toESM(require("fs"));
|
|
7442
|
-
|
|
8144
|
+
path9 = __toESM(require("path"));
|
|
7443
8145
|
init_router();
|
|
7444
8146
|
init_local();
|
|
7445
8147
|
init_transport();
|
|
8148
|
+
init_databaseEngines();
|
|
7446
8149
|
MAX_WORLD_FILES = 2e3;
|
|
7447
8150
|
RUNTIME_TIMEOUT_MS = 18e4;
|
|
7448
8151
|
SKIP_DIRS = /* @__PURE__ */ new Set(["__pycache__", ".git", "node_modules", ".gateway"]);
|
|
7449
|
-
BUILD_OUTPUT = /(^|\/)state\.(sqlite|json)$/;
|
|
7450
8152
|
BridgeRejected = class extends CliError {
|
|
7451
8153
|
constructor(detail) {
|
|
7452
8154
|
super(formatBridgeError(detail), 1);
|
|
@@ -7455,6 +8157,26 @@ var init_client = __esm({
|
|
|
7455
8157
|
detail;
|
|
7456
8158
|
};
|
|
7457
8159
|
YAML_NAME = /\.ya?ml$/i;
|
|
8160
|
+
YAML_NEEDS_PYYAML = "Reading a YAML document needs PyYAML in the Python that runs the schema runtime: pip install pyyaml there, set GATEWAY_PYTHON to an interpreter that has it, or convert the document to JSON";
|
|
8161
|
+
YAML_NOT_ON_PLATFORM = "The platform's schema runtime reads JSON documents only: convert the document to JSON, or read it here with GATEWAY_RUNTIME=local and a Python that has PyYAML (pip install pyyaml, or set GATEWAY_PYTHON to one)";
|
|
8162
|
+
RuntimeRoute = class _RuntimeRoute {
|
|
8163
|
+
constructor(here = localRuntime, hasYaml = localPythonHasYaml) {
|
|
8164
|
+
this.here = here;
|
|
8165
|
+
this.hasYaml = hasYaml;
|
|
8166
|
+
}
|
|
8167
|
+
here;
|
|
8168
|
+
hasYaml;
|
|
8169
|
+
local(request) {
|
|
8170
|
+
const local = this.here();
|
|
8171
|
+
const yaml = yamlDocument(request);
|
|
8172
|
+
if (yaml && local === null) throw _RuntimeRoute.refusal(YAML_NOT_ON_PLATFORM);
|
|
8173
|
+
if (yaml && local !== null && !this.hasYaml(local.python)) throw _RuntimeRoute.refusal(YAML_NEEDS_PYYAML);
|
|
8174
|
+
return local;
|
|
8175
|
+
}
|
|
8176
|
+
static refusal(message) {
|
|
8177
|
+
return new BridgeRejected({ code: "conform", message, schema_path: "/openapi/source" });
|
|
8178
|
+
}
|
|
8179
|
+
};
|
|
7458
8180
|
}
|
|
7459
8181
|
});
|
|
7460
8182
|
|
|
@@ -7469,7 +8191,8 @@ __export(data_exports, {
|
|
|
7469
8191
|
ingestLocalToolCalls: () => ingestLocalToolCalls,
|
|
7470
8192
|
queryLocalWorldData: () => queryLocalWorldData,
|
|
7471
8193
|
queryLocalWorldDataAcross: () => queryLocalWorldDataAcross,
|
|
7472
|
-
showLocalWorldData: () => showLocalWorldData
|
|
8194
|
+
showLocalWorldData: () => showLocalWorldData,
|
|
8195
|
+
sqlLocalWorldData: () => sqlLocalWorldData
|
|
7473
8196
|
});
|
|
7474
8197
|
async function importLocalWorldData(dir, rows, opts, creds) {
|
|
7475
8198
|
const res = await runtime(creds, {
|
|
@@ -7501,8 +8224,8 @@ async function importLocalWorldFiles(dir, sources, opts) {
|
|
|
7501
8224
|
);
|
|
7502
8225
|
const res = await runtime(null, {
|
|
7503
8226
|
command: "import-files",
|
|
7504
|
-
world:
|
|
7505
|
-
sources: sources.map((source) =>
|
|
8227
|
+
world: path10.resolve(dir),
|
|
8228
|
+
sources: sources.map((source) => path10.resolve(source)),
|
|
7506
8229
|
mode: opts.mode ?? "append",
|
|
7507
8230
|
...opts.entity ? { entity: opts.entity } : {},
|
|
7508
8231
|
...opts.delimiter ? { delimiter: opts.delimiter } : {},
|
|
@@ -7528,9 +8251,9 @@ async function chunkLocalWorldFiles(dir, sources, out, opts) {
|
|
|
7528
8251
|
);
|
|
7529
8252
|
const res = await runtime(null, {
|
|
7530
8253
|
command: "chunk-files",
|
|
7531
|
-
world:
|
|
7532
|
-
sources: sources.map((source) =>
|
|
7533
|
-
out:
|
|
8254
|
+
world: path10.resolve(dir),
|
|
8255
|
+
sources: sources.map((source) => path10.resolve(source)),
|
|
8256
|
+
out: path10.resolve(out),
|
|
7534
8257
|
...opts.entity ? { entity: opts.entity } : {},
|
|
7535
8258
|
...opts.delimiter ? { delimiter: opts.delimiter } : {},
|
|
7536
8259
|
...opts.chunkBytes ? { chunk_bytes: opts.chunkBytes } : {},
|
|
@@ -7541,8 +8264,8 @@ async function chunkLocalWorldFiles(dir, sources, out, opts) {
|
|
|
7541
8264
|
function dropBuildOutputs(dir) {
|
|
7542
8265
|
const dropped = [];
|
|
7543
8266
|
for (const file of readWorldFiles(dir, { buildOutputs: true })) {
|
|
7544
|
-
if (!
|
|
7545
|
-
fs9.rmSync(
|
|
8267
|
+
if (!isBuildOutput(file.path)) continue;
|
|
8268
|
+
fs9.rmSync(path10.join(dir, file.path), { force: true });
|
|
7546
8269
|
dropped.push(file.path);
|
|
7547
8270
|
}
|
|
7548
8271
|
return dropped;
|
|
@@ -7609,7 +8332,7 @@ async function queryLocalWorldDataAcross(dir, entity, where, opts) {
|
|
|
7609
8332
|
const payload = await localBridge(
|
|
7610
8333
|
{
|
|
7611
8334
|
command: "query",
|
|
7612
|
-
world:
|
|
8335
|
+
world: path10.resolve(dir),
|
|
7613
8336
|
entity,
|
|
7614
8337
|
across: true,
|
|
7615
8338
|
...opts.compare ? { compare: true } : {},
|
|
@@ -7625,6 +8348,28 @@ async function queryLocalWorldDataAcross(dir, entity, where, opts) {
|
|
|
7625
8348
|
if (detail) throw new BridgeRejected(detail);
|
|
7626
8349
|
return payload;
|
|
7627
8350
|
}
|
|
8351
|
+
async function sqlLocalWorldData(dir, sql, opts) {
|
|
8352
|
+
const local = localRuntime();
|
|
8353
|
+
if (!local)
|
|
8354
|
+
throw new CliError(
|
|
8355
|
+
"`worlds data sql` on a directory reads the world's database in place, so it needs the bundled runtime on this machine. " + localRuntimeReason(),
|
|
8356
|
+
1
|
|
8357
|
+
);
|
|
8358
|
+
const payload = await localBridge(
|
|
8359
|
+
{
|
|
8360
|
+
command: "sql",
|
|
8361
|
+
world: path10.resolve(dir),
|
|
8362
|
+
sql,
|
|
8363
|
+
...opts.limit !== void 0 ? { limit: opts.limit } : {},
|
|
8364
|
+
...opts.scenario ? { scenario: opts.scenario } : {}
|
|
8365
|
+
},
|
|
8366
|
+
local
|
|
8367
|
+
);
|
|
8368
|
+
const detail = detailFrom(payload);
|
|
8369
|
+
if (detail) throw new BridgeRejected(detail);
|
|
8370
|
+
const { status: _status, ...answer } = payload;
|
|
8371
|
+
return answer;
|
|
8372
|
+
}
|
|
7628
8373
|
async function ingestLocalToolCalls(dir, records, opts, creds) {
|
|
7629
8374
|
const res = await runtime(creds, {
|
|
7630
8375
|
command: "ingest-calls",
|
|
@@ -7656,16 +8401,15 @@ async function ingestLocalToolCalls(dir, records, opts, creds) {
|
|
|
7656
8401
|
...res.batch !== void 0 ? { batch: res.batch } : {}
|
|
7657
8402
|
};
|
|
7658
8403
|
}
|
|
7659
|
-
var fs9,
|
|
8404
|
+
var fs9, path10;
|
|
7660
8405
|
var init_data = __esm({
|
|
7661
8406
|
"src/cli/runtime/data.ts"() {
|
|
7662
8407
|
"use strict";
|
|
7663
8408
|
fs9 = __toESM(require("fs"));
|
|
7664
|
-
|
|
8409
|
+
path10 = __toESM(require("path"));
|
|
7665
8410
|
init_router();
|
|
7666
8411
|
init_client();
|
|
7667
8412
|
init_local();
|
|
7668
|
-
BUILD_OUTPUT2 = /(^|\/)state\.(sqlite|json)$/;
|
|
7669
8413
|
}
|
|
7670
8414
|
});
|
|
7671
8415
|
|
|
@@ -7704,27 +8448,27 @@ function typescriptPrefix() {
|
|
|
7704
8448
|
}
|
|
7705
8449
|
}
|
|
7706
8450
|
function command(script, wrapperDir) {
|
|
7707
|
-
const suffix =
|
|
8451
|
+
const suffix = path11.extname(script).toLowerCase();
|
|
7708
8452
|
if (PYTHON_SUFFIXES.includes(suffix)) return { file: process.env.GATEWAY_PYTHON || "python3", args: ["-c", PY_WRAPPER, script] };
|
|
7709
8453
|
if (NODE_SUFFIXES.includes(suffix)) {
|
|
7710
|
-
const wrapper =
|
|
8454
|
+
const wrapper = path11.join(wrapperDir, "transform-wrapper.mjs");
|
|
7711
8455
|
fs10.writeFileSync(wrapper, NODE_WRAPPER);
|
|
7712
8456
|
const flags = suffix === ".ts" || suffix === ".mts" ? typescriptPrefix() : [];
|
|
7713
8457
|
return { file: process.env.GATEWAY_NODE || process.execPath, args: [...flags, wrapper, script] };
|
|
7714
8458
|
}
|
|
7715
|
-
throw new CliError(`${
|
|
8459
|
+
throw new CliError(`${path11.basename(script)}: a transform script is .py, .ts, .mjs, .js or .cjs`, 1);
|
|
7716
8460
|
}
|
|
7717
8461
|
async function runTransform(script, records, opts = {}) {
|
|
7718
8462
|
if (!fs10.existsSync(script) || !fs10.statSync(script).isFile()) throw new CliError(`no transform script at ${script}`, 1);
|
|
7719
|
-
const resolved =
|
|
7720
|
-
const name =
|
|
8463
|
+
const resolved = path11.resolve(script);
|
|
8464
|
+
const name = path11.basename(script);
|
|
7721
8465
|
const timeoutMs = opts.timeoutMs ?? DEFAULT_TRANSFORM_TIMEOUT_MS;
|
|
7722
|
-
const scratch = fs10.mkdtempSync(
|
|
8466
|
+
const scratch = fs10.mkdtempSync(path11.join(os2.tmpdir(), "gateway-transform-"));
|
|
7723
8467
|
try {
|
|
7724
8468
|
const { file, args } = command(resolved, scratch);
|
|
7725
8469
|
const env = Object.fromEntries(Object.entries(process.env).filter(([key2]) => !SCRUBBED.test(key2)));
|
|
7726
8470
|
const done = await new Promise((resolve11, reject) => {
|
|
7727
|
-
const child = (0, import_node_child_process3.spawn)(file, args, { cwd:
|
|
8471
|
+
const child = (0, import_node_child_process3.spawn)(file, args, { cwd: path11.dirname(resolved), env, stdio: ["pipe", "pipe", "pipe"] });
|
|
7728
8472
|
let stdout = "";
|
|
7729
8473
|
let stderr = "";
|
|
7730
8474
|
let timedOut = false;
|
|
@@ -7762,14 +8506,14 @@ async function transformRecords(transform, records, opts = {}) {
|
|
|
7762
8506
|
if (typeof transform === "function") return { rows: checkRows(await transform(records), "transform(records)"), stderr: "" };
|
|
7763
8507
|
return runTransform(transform, records, opts);
|
|
7764
8508
|
}
|
|
7765
|
-
var import_node_child_process3, fs10, os2,
|
|
8509
|
+
var import_node_child_process3, fs10, os2, path11, import_node_module, import_meta, DEFAULT_TRANSFORM_TIMEOUT_MS, NODE_SUFFIXES, PYTHON_SUFFIXES, SCRUBBED, PY_WRAPPER, NODE_WRAPPER, isObject, tail;
|
|
7766
8510
|
var init_transform = __esm({
|
|
7767
8511
|
"src/cli/platform/worldData/transform.ts"() {
|
|
7768
8512
|
"use strict";
|
|
7769
8513
|
import_node_child_process3 = require("child_process");
|
|
7770
8514
|
fs10 = __toESM(require("fs"));
|
|
7771
8515
|
os2 = __toESM(require("os"));
|
|
7772
|
-
|
|
8516
|
+
path11 = __toESM(require("path"));
|
|
7773
8517
|
import_node_module = require("module");
|
|
7774
8518
|
init_router();
|
|
7775
8519
|
import_meta = {};
|
|
@@ -7889,7 +8633,7 @@ async function forEachLimited(items, limit, fn) {
|
|
|
7889
8633
|
if (failure) throw failure;
|
|
7890
8634
|
}
|
|
7891
8635
|
async function waitForBatch(client2, batchId, opts = {}) {
|
|
7892
|
-
const
|
|
8636
|
+
const sleep5 = opts.sleep ?? client2.sleep;
|
|
7893
8637
|
let delay = opts.initialDelayMs ?? 1e3;
|
|
7894
8638
|
let last = "";
|
|
7895
8639
|
for (; ; ) {
|
|
@@ -7900,7 +8644,7 @@ async function waitForBatch(client2, batchId, opts = {}) {
|
|
|
7900
8644
|
last = phase;
|
|
7901
8645
|
}
|
|
7902
8646
|
if (isSettled(status)) return status;
|
|
7903
|
-
await
|
|
8647
|
+
await sleep5(delay);
|
|
7904
8648
|
delay = Math.min(1e4, Math.round(delay * 1.5));
|
|
7905
8649
|
}
|
|
7906
8650
|
}
|
|
@@ -7924,10 +8668,10 @@ var init_batches = __esm({
|
|
|
7924
8668
|
]);
|
|
7925
8669
|
sleepMs = (ms) => new Promise((resolve11) => setTimeout(resolve11, ms));
|
|
7926
8670
|
WorldDataApi = class {
|
|
7927
|
-
constructor(creds, slug,
|
|
8671
|
+
constructor(creds, slug, sleep5 = sleepMs) {
|
|
7928
8672
|
this.creds = creds;
|
|
7929
8673
|
this.slug = slug;
|
|
7930
|
-
this.sleep =
|
|
8674
|
+
this.sleep = sleep5;
|
|
7931
8675
|
this.base = `/api/public/worlds/${encodeURIComponent(slug)}/data`;
|
|
7932
8676
|
}
|
|
7933
8677
|
creds;
|
|
@@ -8331,19 +9075,13 @@ function toolCallsFromObservations(observations, opts = {}) {
|
|
|
8331
9075
|
}
|
|
8332
9076
|
return out;
|
|
8333
9077
|
}
|
|
8334
|
-
function credentialsOf(options) {
|
|
8335
|
-
const host = (options.host ?? process.env.GATEWAY_HOST ?? "https://withgateway.ai").replace(/\/+$/, "");
|
|
8336
|
-
const publicKey = options.publicKey ?? process.env.GATEWAY_PUBLIC_KEY;
|
|
8337
|
-
const secretKey = options.secretKey ?? process.env.GATEWAY_SECRET_KEY;
|
|
8338
|
-
return publicKey && secretKey ? { host, publicKey, secretKey } : null;
|
|
8339
|
-
}
|
|
8340
9078
|
async function ingest(world, records, options = {}) {
|
|
8341
9079
|
const { ingestLocalToolCalls: ingestLocalToolCalls2, importLocalWorldData: importLocalWorldData2, checkLocalWorldData: checkLocalWorldData2 } = await Promise.resolve().then(() => (init_data(), data_exports));
|
|
8342
9080
|
if (options.transform !== void 0 && options.map !== void 0) throw new Error("records go through one of transform, map");
|
|
8343
9081
|
const redact = options.redact ?? "off";
|
|
8344
9082
|
const mode = options.mode ?? "append";
|
|
8345
9083
|
const dryRun = Boolean(options.dryRun);
|
|
8346
|
-
const creds =
|
|
9084
|
+
const creds = platformEndpoint(options);
|
|
8347
9085
|
const local = fs12.existsSync(world) && fs12.statSync(world).isDirectory();
|
|
8348
9086
|
const map = options.map === void 0 ? void 0 : options.map;
|
|
8349
9087
|
let rows = null;
|
|
@@ -8357,12 +9095,12 @@ async function ingest(world, records, options = {}) {
|
|
|
8357
9095
|
const landed = dryRun ? await checkLocalWorldData2(world, rows, creds, { redact }) : await importLocalWorldData2(world, rows, { mode, redact }, creds);
|
|
8358
9096
|
return transformReport(world, records.length, rows, stderr, { dryRun, redact, changed: !dryRun && landed.changed, kind: landed.kind, entityCounts: landed.entity_counts });
|
|
8359
9097
|
}
|
|
8360
|
-
if (!creds) throw new Error(
|
|
9098
|
+
if (!creds) throw new Error(GATEWAY_KEYS_MISSING);
|
|
8361
9099
|
const { pull: pull2 } = await Promise.resolve().then(() => (init_hub(), hub_exports));
|
|
8362
9100
|
const slug = world.split("@", 1)[0];
|
|
8363
|
-
const scratch = fs12.mkdtempSync(
|
|
9101
|
+
const scratch = fs12.mkdtempSync(path12.join(os3.tmpdir(), "gateway-ingest-"));
|
|
8364
9102
|
try {
|
|
8365
|
-
const pulled = await pull2(world,
|
|
9103
|
+
const pulled = await pull2(world, path12.join(scratch, slug), options);
|
|
8366
9104
|
let report;
|
|
8367
9105
|
let projected;
|
|
8368
9106
|
if (rows === null) {
|
|
@@ -8436,14 +9174,15 @@ async function sessionToolObservations(sessionId, options = {}) {
|
|
|
8436
9174
|
for (const observation of trace5.observations ?? []) out.push({ traceId: trace5.id ?? null, ...observation });
|
|
8437
9175
|
return out;
|
|
8438
9176
|
}
|
|
8439
|
-
var fs12, os3,
|
|
9177
|
+
var fs12, os3, path12, isObject2, isoOf;
|
|
8440
9178
|
var init_ingest = __esm({
|
|
8441
9179
|
"src/worlds/ingest.ts"() {
|
|
8442
9180
|
"use strict";
|
|
8443
9181
|
fs12 = __toESM(require("fs"));
|
|
8444
9182
|
os3 = __toESM(require("os"));
|
|
8445
|
-
|
|
9183
|
+
path12 = __toESM(require("path"));
|
|
8446
9184
|
init_worlds();
|
|
9185
|
+
init_platformEndpoint();
|
|
8447
9186
|
isObject2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8448
9187
|
isoOf = (value) => value instanceof Date ? value.toISOString() : typeof value === "string" ? value : void 0;
|
|
8449
9188
|
}
|
|
@@ -8544,7 +9283,7 @@ var init_dryRun = __esm({
|
|
|
8544
9283
|
/** Poll until the run settles or `timeoutSeconds` pass; the last verdict either way. */
|
|
8545
9284
|
async settle(runId, opts) {
|
|
8546
9285
|
const now = opts.now ?? Date.now;
|
|
8547
|
-
const
|
|
9286
|
+
const sleep5 = opts.sleep ?? ((ms) => new Promise((resolve11) => setTimeout(resolve11, ms)));
|
|
8548
9287
|
const deadline = now() + opts.timeoutSeconds * 1e3;
|
|
8549
9288
|
for (; ; ) {
|
|
8550
9289
|
const budget = Math.floor(
|
|
@@ -8554,7 +9293,7 @@ var init_dryRun = __esm({
|
|
|
8554
9293
|
const verdict = await this.status(runId, budget);
|
|
8555
9294
|
if (verdict.settled || now() >= deadline) return verdict;
|
|
8556
9295
|
opts.onProgress?.(verdict);
|
|
8557
|
-
if (now() - asked < 1e3) await
|
|
9296
|
+
if (now() - asked < 1e3) await sleep5(1e3);
|
|
8558
9297
|
}
|
|
8559
9298
|
}
|
|
8560
9299
|
};
|
|
@@ -8622,6 +9361,8 @@ __export(worlds_exports, {
|
|
|
8622
9361
|
EXPLORATORY_TASK: () => EXPLORATORY_TASK,
|
|
8623
9362
|
EXPLORATORY_TASK_SOURCE: () => EXPLORATORY_TASK_SOURCE,
|
|
8624
9363
|
GatewayEvalsClient: () => GatewayEvalsClient,
|
|
9364
|
+
GradePayload: () => GradePayload,
|
|
9365
|
+
GradeRefused: () => GradeRefused,
|
|
8625
9366
|
HostedDryRunClient: () => HostedDryRunClient,
|
|
8626
9367
|
IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
|
|
8627
9368
|
KEY_NAMES: () => KEY_NAMES,
|
|
@@ -8637,6 +9378,7 @@ __export(worlds_exports, {
|
|
|
8637
9378
|
PlatformTransport: () => PlatformTransport,
|
|
8638
9379
|
PushSlugConflict: () => PushSlugConflict,
|
|
8639
9380
|
RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
|
|
9381
|
+
RetryPolicy: () => RetryPolicy,
|
|
8640
9382
|
SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
|
|
8641
9383
|
SECRET_KEY: () => SECRET_KEY,
|
|
8642
9384
|
SESSION_STATES: () => SESSION_STATES,
|
|
@@ -8644,8 +9386,10 @@ __export(worlds_exports, {
|
|
|
8644
9386
|
STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
|
|
8645
9387
|
STRIP_PREFIX: () => STRIP_PREFIX,
|
|
8646
9388
|
SURFACE_KINDS: () => SURFACE_KINDS,
|
|
9389
|
+
Score: () => Score,
|
|
8647
9390
|
Screen: () => Screen,
|
|
8648
9391
|
SecretScrubber: () => SecretScrubber,
|
|
9392
|
+
TOOL_CONTRACT_UNREAD: () => TOOL_CONTRACT_UNREAD,
|
|
8649
9393
|
TRANSFORMS: () => TRANSFORMS,
|
|
8650
9394
|
TaskEditClient: () => TaskEditClient,
|
|
8651
9395
|
TaskRun: () => TaskRun,
|
|
@@ -8657,14 +9401,17 @@ __export(worlds_exports, {
|
|
|
8657
9401
|
WorldBrowser: () => WorldBrowser,
|
|
8658
9402
|
WorldCallTooLarge: () => WorldCallTooLarge,
|
|
8659
9403
|
WorldEditClient: () => WorldEditClient,
|
|
9404
|
+
WorldNotice: () => WorldNotice,
|
|
8660
9405
|
WorldRequestLog: () => WorldRequestLog,
|
|
8661
9406
|
WorldSandboxClient: () => WorldSandboxClient,
|
|
8662
9407
|
WorldSession: () => WorldSession,
|
|
8663
9408
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
9409
|
+
WorldSessionOpenFailed: () => WorldSessionOpenFailed,
|
|
8664
9410
|
WorldSessionTimeout: () => WorldSessionTimeout,
|
|
8665
9411
|
WorldSet: () => WorldSet,
|
|
8666
9412
|
WorldSurfaceUnavailable: () => WorldSurfaceUnavailable,
|
|
8667
9413
|
WorldTask: () => WorldTask,
|
|
9414
|
+
WorldToolsUnread: () => WorldToolsUnread,
|
|
8668
9415
|
aggregateTaskGrade: () => aggregateTaskGrade,
|
|
8669
9416
|
apiRequest: () => apiRequest,
|
|
8670
9417
|
applyTransforms: () => applyTransforms,
|
|
@@ -8707,6 +9454,7 @@ __export(worlds_exports, {
|
|
|
8707
9454
|
listTaskSessions: () => listTaskSessions,
|
|
8708
9455
|
listTasks: () => listTasks,
|
|
8709
9456
|
localTreeState: () => localTreeState,
|
|
9457
|
+
messageOf: () => messageOf,
|
|
8710
9458
|
migrateProjectWorlds: () => migrateProjectWorlds,
|
|
8711
9459
|
migrateWorld: () => migrateWorld,
|
|
8712
9460
|
modelToolName: () => modelToolName,
|
|
@@ -8750,10 +9498,14 @@ __export(worlds_exports, {
|
|
|
8750
9498
|
setEnvSecret: () => setEnvSecret,
|
|
8751
9499
|
shapeText: () => shapeText,
|
|
8752
9500
|
snapshotTreeHashes: () => snapshotTreeHashes,
|
|
9501
|
+
sqlRows: () => sqlRows,
|
|
9502
|
+
stillStartingHint: () => stillStartingHint,
|
|
8753
9503
|
storedForms: () => storedForms,
|
|
8754
9504
|
surfaceDescriptor: () => surfaceDescriptor,
|
|
8755
9505
|
surfaceKinds: () => surfaceKinds,
|
|
9506
|
+
taskGradeError: () => taskGradeError,
|
|
8756
9507
|
taskLabel: () => taskLabel,
|
|
9508
|
+
taskRunFailure: () => taskRunFailure,
|
|
8757
9509
|
toolCallRecordsIn: () => toolCallRecordsIn,
|
|
8758
9510
|
toolCallsFromObservations: () => toolCallsFromObservations,
|
|
8759
9511
|
uiEntryUrl: () => uiEntryUrl,
|
|
@@ -8767,17 +9519,6 @@ __export(worlds_exports, {
|
|
|
8767
9519
|
withoutUiToken: () => withoutUiToken,
|
|
8768
9520
|
writeLocalMeta: () => writeLocalMeta
|
|
8769
9521
|
});
|
|
8770
|
-
function resolveEnv(options) {
|
|
8771
|
-
const host = options.host ?? process.env.GATEWAY_HOST ?? "https://withgateway.ai";
|
|
8772
|
-
const publicKey = options.publicKey ?? process.env.GATEWAY_PUBLIC_KEY;
|
|
8773
|
-
const secretKey = options.secretKey ?? process.env.GATEWAY_SECRET_KEY;
|
|
8774
|
-
if (!publicKey || !secretKey) {
|
|
8775
|
-
throw new Error(
|
|
8776
|
-
"Gateway keys missing: set GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY (or pass publicKey/secretKey)."
|
|
8777
|
-
);
|
|
8778
|
-
}
|
|
8779
|
-
return { host: host.replace(/\/+$/, ""), publicKey, secretKey };
|
|
8780
|
-
}
|
|
8781
9522
|
function parseErrorBody(text2, limit = 600) {
|
|
8782
9523
|
const raw = { detail: text2.slice(0, limit), code: null };
|
|
8783
9524
|
let parsed;
|
|
@@ -8797,9 +9538,9 @@ function parseErrorBody(text2, limit = 600) {
|
|
|
8797
9538
|
code: stableCode
|
|
8798
9539
|
};
|
|
8799
9540
|
}
|
|
8800
|
-
async function apiRequest(options, method,
|
|
8801
|
-
const reply = await new PlatformTransport(
|
|
8802
|
-
if (!reply.ok) throw new ApiError(reply.status, method,
|
|
9541
|
+
async function apiRequest(options, method, path17, body, init3 = {}) {
|
|
9542
|
+
const reply = await new PlatformTransport(requirePlatformEndpoint(options)).send(method, path17, body, init3);
|
|
9543
|
+
if (!reply.ok) throw new ApiError(reply.status, method, path17, reply.text);
|
|
8803
9544
|
return JSON.parse(reply.text);
|
|
8804
9545
|
}
|
|
8805
9546
|
async function setEnvSecret(slug, key2, value, options = {}) {
|
|
@@ -8911,7 +9652,6 @@ function detectProvenance() {
|
|
|
8911
9652
|
kind: "ci",
|
|
8912
9653
|
id: env.GITHUB_ACTOR,
|
|
8913
9654
|
name: env.GITHUB_ACTOR,
|
|
8914
|
-
// GitHub serves every account's avatar at /<login>.png.
|
|
8915
9655
|
imageUrl: `${server}/${env.GITHUB_ACTOR}.png`
|
|
8916
9656
|
};
|
|
8917
9657
|
}
|
|
@@ -8980,9 +9720,11 @@ var ApiError, WorldTask, WorldSet;
|
|
|
8980
9720
|
var init_worlds = __esm({
|
|
8981
9721
|
"src/worlds/index.ts"() {
|
|
8982
9722
|
"use strict";
|
|
9723
|
+
init_platformEndpoint();
|
|
8983
9724
|
init_transport();
|
|
8984
9725
|
init_transport();
|
|
8985
9726
|
init_session2();
|
|
9727
|
+
init_grade();
|
|
8986
9728
|
init_sessionList();
|
|
8987
9729
|
init_sessionContract();
|
|
8988
9730
|
init_taskRef();
|
|
@@ -9008,10 +9750,11 @@ var init_worlds = __esm({
|
|
|
9008
9750
|
init_sandbox();
|
|
9009
9751
|
init_editSessions();
|
|
9010
9752
|
init_dryRun();
|
|
9753
|
+
init_worldNotice();
|
|
9011
9754
|
ApiError = class extends Error {
|
|
9012
|
-
constructor(status, method,
|
|
9755
|
+
constructor(status, method, path17, text2) {
|
|
9013
9756
|
const parsed = parseErrorBody(text2);
|
|
9014
|
-
super(`${method} ${
|
|
9757
|
+
super(`${method} ${path17} -> ${status}: ${parsed.detail}`);
|
|
9015
9758
|
this.status = status;
|
|
9016
9759
|
this.text = text2;
|
|
9017
9760
|
this.name = "ApiError";
|
|
@@ -9148,6 +9891,8 @@ __export(src_exports, {
|
|
|
9148
9891
|
GatewaySecurityError: () => GatewaySecurityError,
|
|
9149
9892
|
GatewayToolApprovalRequiredError: () => GatewayToolApprovalRequiredError,
|
|
9150
9893
|
GatewayToolBlockedError: () => GatewayToolBlockedError,
|
|
9894
|
+
GradePayload: () => GradePayload,
|
|
9895
|
+
GradeRefused: () => GradeRefused,
|
|
9151
9896
|
HostedDryRunClient: () => HostedDryRunClient,
|
|
9152
9897
|
IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
|
|
9153
9898
|
KEY_NAMES: () => KEY_NAMES,
|
|
@@ -9173,6 +9918,7 @@ __export(src_exports, {
|
|
|
9173
9918
|
ReplayReport: () => ReplayReport,
|
|
9174
9919
|
ReplaySuite: () => ReplaySuite,
|
|
9175
9920
|
ReplayTask: () => ReplayTask,
|
|
9921
|
+
RetryPolicy: () => RetryPolicy,
|
|
9176
9922
|
SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
|
|
9177
9923
|
SECRET_KEY: () => SECRET_KEY,
|
|
9178
9924
|
SESSION_STATES: () => SESSION_STATES,
|
|
@@ -9182,6 +9928,7 @@ __export(src_exports, {
|
|
|
9182
9928
|
SUCCESS_METRIC_NAME_KEY: () => SUCCESS_METRIC_NAME_KEY,
|
|
9183
9929
|
SUCCESS_SIGNAL_KEY: () => SUCCESS_SIGNAL_KEY,
|
|
9184
9930
|
SURFACE_KINDS: () => SURFACE_KINDS,
|
|
9931
|
+
Score: () => Score,
|
|
9185
9932
|
ScoreError: () => ScoreError,
|
|
9186
9933
|
ScoresClient: () => ScoresClient,
|
|
9187
9934
|
Screen: () => Screen,
|
|
@@ -9190,6 +9937,7 @@ __export(src_exports, {
|
|
|
9190
9937
|
SessionRecording: () => SessionRecording,
|
|
9191
9938
|
SessionTrace: () => SessionTrace,
|
|
9192
9939
|
StubMissError: () => StubMissError,
|
|
9940
|
+
TOOL_CONTRACT_UNREAD: () => TOOL_CONTRACT_UNREAD,
|
|
9193
9941
|
TRANSFORMS: () => TRANSFORMS,
|
|
9194
9942
|
TaskEditClient: () => TaskEditClient,
|
|
9195
9943
|
TaskRun: () => TaskRun,
|
|
@@ -9205,14 +9953,17 @@ __export(src_exports, {
|
|
|
9205
9953
|
WorldBrowser: () => WorldBrowser,
|
|
9206
9954
|
WorldCallTooLarge: () => WorldCallTooLarge,
|
|
9207
9955
|
WorldEditClient: () => WorldEditClient,
|
|
9956
|
+
WorldNotice: () => WorldNotice,
|
|
9208
9957
|
WorldRequestLog: () => WorldRequestLog,
|
|
9209
9958
|
WorldSandboxClient: () => WorldSandboxClient,
|
|
9210
9959
|
WorldSession: () => WorldSession,
|
|
9211
9960
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
9961
|
+
WorldSessionOpenFailed: () => WorldSessionOpenFailed,
|
|
9212
9962
|
WorldSessionTimeout: () => WorldSessionTimeout,
|
|
9213
9963
|
WorldSet: () => WorldSet,
|
|
9214
9964
|
WorldSurfaceUnavailable: () => WorldSurfaceUnavailable,
|
|
9215
9965
|
WorldTask: () => WorldTask,
|
|
9966
|
+
WorldToolsUnread: () => WorldToolsUnread,
|
|
9216
9967
|
addExperimentAttributes: () => addExperimentAttributes,
|
|
9217
9968
|
aggregateTaskGrade: () => aggregateTaskGrade,
|
|
9218
9969
|
apiRequest: () => apiRequest,
|
|
@@ -9279,6 +10030,7 @@ __export(src_exports, {
|
|
|
9279
10030
|
loadSession: () => loadSession,
|
|
9280
10031
|
localTreeState: () => localTreeState,
|
|
9281
10032
|
memory: () => memory,
|
|
10033
|
+
messageOf: () => messageOf,
|
|
9282
10034
|
migrateProjectWorlds: () => migrateProjectWorlds,
|
|
9283
10035
|
migrateWorld: () => migrateWorld,
|
|
9284
10036
|
modelToolName: () => modelToolName,
|
|
@@ -9336,12 +10088,16 @@ __export(src_exports, {
|
|
|
9336
10088
|
setExperimentContext: () => setExperimentContext,
|
|
9337
10089
|
shapeText: () => shapeText,
|
|
9338
10090
|
snapshotTreeHashes: () => snapshotTreeHashes,
|
|
10091
|
+
sqlRows: () => sqlRows,
|
|
10092
|
+
stillStartingHint: () => stillStartingHint,
|
|
9339
10093
|
storedForms: () => storedForms,
|
|
9340
10094
|
success: () => success,
|
|
9341
10095
|
suite: () => suite,
|
|
9342
10096
|
surfaceDescriptor: () => surfaceDescriptor,
|
|
9343
10097
|
surfaceKinds: () => surfaceKinds,
|
|
10098
|
+
taskGradeError: () => taskGradeError,
|
|
9344
10099
|
taskLabel: () => taskLabel,
|
|
10100
|
+
taskRunFailure: () => taskRunFailure,
|
|
9345
10101
|
toolCallRecordsIn: () => toolCallRecordsIn,
|
|
9346
10102
|
toolCallsFromObservations: () => toolCallsFromObservations,
|
|
9347
10103
|
traces: () => traces_exports,
|
|
@@ -9930,8 +10686,8 @@ var GatewayContext = class _GatewayContext {
|
|
|
9930
10686
|
}
|
|
9931
10687
|
return resolved;
|
|
9932
10688
|
}
|
|
9933
|
-
async requestJson(method,
|
|
9934
|
-
const response = await fetch(`${this.host}${
|
|
10689
|
+
async requestJson(method, path17, payload) {
|
|
10690
|
+
const response = await fetch(`${this.host}${path17}`, {
|
|
9935
10691
|
method,
|
|
9936
10692
|
headers: {
|
|
9937
10693
|
Authorization: this.authHeader(),
|
|
@@ -9942,7 +10698,7 @@ var GatewayContext = class _GatewayContext {
|
|
|
9942
10698
|
const text2 = await response.text();
|
|
9943
10699
|
const body = text2 ? safeJson(text2) : {};
|
|
9944
10700
|
if (!response.ok) {
|
|
9945
|
-
const message = typeof body.message === "string" ? body.message : `Gateway API ${response.status} on ${
|
|
10701
|
+
const message = typeof body.message === "string" ? body.message : `Gateway API ${response.status} on ${path17}`;
|
|
9946
10702
|
if (response.status === 409) {
|
|
9947
10703
|
throw new GatewayContextConflictError(
|
|
9948
10704
|
message,
|
|
@@ -9951,7 +10707,7 @@ var GatewayContext = class _GatewayContext {
|
|
|
9951
10707
|
}
|
|
9952
10708
|
throw new GatewayContextError(message);
|
|
9953
10709
|
}
|
|
9954
|
-
this.log("%s %s -> %s", method,
|
|
10710
|
+
this.log("%s %s -> %s", method, path17, response.status);
|
|
9955
10711
|
return body;
|
|
9956
10712
|
}
|
|
9957
10713
|
authHeader() {
|
|
@@ -10058,11 +10814,11 @@ function primaryPathForKind(kind, snapshot) {
|
|
|
10058
10814
|
const preferred = kind === "agent" ? "AGENTS.md" : kind === "prompt" ? "PROMPT.md" : kind === "skill" ? "SKILL.md" : "MEMORY.md";
|
|
10059
10815
|
if (readFile(snapshot, preferred)) return preferred;
|
|
10060
10816
|
return Object.entries(snapshot.files).find(
|
|
10061
|
-
([
|
|
10817
|
+
([path17, entry]) => entry.type === "file" && path17.endsWith(".md")
|
|
10062
10818
|
)?.[0] ?? null;
|
|
10063
10819
|
}
|
|
10064
|
-
function parseJsonFile(snapshot,
|
|
10065
|
-
const content = readFile(snapshot,
|
|
10820
|
+
function parseJsonFile(snapshot, path17) {
|
|
10821
|
+
const content = readFile(snapshot, path17);
|
|
10066
10822
|
if (!content) return {};
|
|
10067
10823
|
try {
|
|
10068
10824
|
const parsed = JSON.parse(content);
|
|
@@ -10071,8 +10827,8 @@ function parseJsonFile(snapshot, path16) {
|
|
|
10071
10827
|
return {};
|
|
10072
10828
|
}
|
|
10073
10829
|
}
|
|
10074
|
-
function readFile(snapshot,
|
|
10075
|
-
const entry = snapshot.files[
|
|
10830
|
+
function readFile(snapshot, path17) {
|
|
10831
|
+
const entry = snapshot.files[path17];
|
|
10076
10832
|
return entry?.type === "file" ? entry.content : null;
|
|
10077
10833
|
}
|
|
10078
10834
|
function provenanceFor(snapshot, label) {
|
|
@@ -10174,16 +10930,16 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
10174
10930
|
`/api/public/context/memory/${encodeIdentifier2(identifier)}${suffix}`
|
|
10175
10931
|
);
|
|
10176
10932
|
}
|
|
10177
|
-
async read(target,
|
|
10933
|
+
async read(target, path17, options = {}) {
|
|
10178
10934
|
const snapshot = typeof target === "string" ? await this.pull(target, options) : target;
|
|
10179
|
-
const file = snapshot.files[
|
|
10935
|
+
const file = snapshot.files[path17];
|
|
10180
10936
|
return file?.type === "file" ? file.content : null;
|
|
10181
10937
|
}
|
|
10182
|
-
async write(target,
|
|
10938
|
+
async write(target, path17, content, options = {}) {
|
|
10183
10939
|
const snapshot = typeof target === "string" ? await this.pull(target) : target;
|
|
10184
10940
|
return this.push(snapshot.repo.repoHandle, {
|
|
10185
10941
|
files: {
|
|
10186
|
-
[
|
|
10942
|
+
[path17]: {
|
|
10187
10943
|
content,
|
|
10188
10944
|
...options.mimeType ? { mimeType: options.mimeType } : {}
|
|
10189
10945
|
}
|
|
@@ -10193,10 +10949,10 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
10193
10949
|
...runtimeContextPayload2(options)
|
|
10194
10950
|
});
|
|
10195
10951
|
}
|
|
10196
|
-
async delete(target,
|
|
10952
|
+
async delete(target, path17, options = {}) {
|
|
10197
10953
|
const snapshot = typeof target === "string" ? await this.pull(target) : target;
|
|
10198
10954
|
return this.push(snapshot.repo.repoHandle, {
|
|
10199
|
-
files: { [
|
|
10955
|
+
files: { [path17]: null },
|
|
10200
10956
|
parentCommit: options.parentCommit ?? snapshot.commit.commitHash,
|
|
10201
10957
|
message: options.message,
|
|
10202
10958
|
...runtimeContextPayload2(options)
|
|
@@ -10209,8 +10965,8 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
10209
10965
|
payload
|
|
10210
10966
|
);
|
|
10211
10967
|
}
|
|
10212
|
-
async requestJson(method,
|
|
10213
|
-
const response = await fetch(`${this.host}${
|
|
10968
|
+
async requestJson(method, path17, payload) {
|
|
10969
|
+
const response = await fetch(`${this.host}${path17}`, {
|
|
10214
10970
|
method,
|
|
10215
10971
|
headers: {
|
|
10216
10972
|
Authorization: this.authHeader(),
|
|
@@ -10221,7 +10977,7 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
10221
10977
|
const text2 = await response.text();
|
|
10222
10978
|
const body = text2 ? safeJson2(text2) : {};
|
|
10223
10979
|
if (!response.ok) {
|
|
10224
|
-
const message = typeof body.message === "string" ? body.message : `Gateway API ${response.status} on ${
|
|
10980
|
+
const message = typeof body.message === "string" ? body.message : `Gateway API ${response.status} on ${path17}`;
|
|
10225
10981
|
if (response.status === 409) {
|
|
10226
10982
|
throw new GatewayMemoryConflictError(
|
|
10227
10983
|
message,
|
|
@@ -10230,7 +10986,7 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
10230
10986
|
}
|
|
10231
10987
|
throw new GatewayMemoryError(message);
|
|
10232
10988
|
}
|
|
10233
|
-
this.log("%s %s -> %s", method,
|
|
10989
|
+
this.log("%s %s -> %s", method, path17, response.status);
|
|
10234
10990
|
return body;
|
|
10235
10991
|
}
|
|
10236
10992
|
authHeader() {
|
|
@@ -10392,10 +11148,10 @@ var PersonasClient = class _PersonasClient {
|
|
|
10392
11148
|
done: Boolean(payload.done)
|
|
10393
11149
|
};
|
|
10394
11150
|
}
|
|
10395
|
-
async requestJson(method,
|
|
11151
|
+
async requestJson(method, path17, payload) {
|
|
10396
11152
|
let response;
|
|
10397
11153
|
try {
|
|
10398
|
-
response = await fetch(`${this.host}${
|
|
11154
|
+
response = await fetch(`${this.host}${path17}`, {
|
|
10399
11155
|
method,
|
|
10400
11156
|
headers: {
|
|
10401
11157
|
Authorization: this.authHeader(),
|
|
@@ -10406,7 +11162,7 @@ var PersonasClient = class _PersonasClient {
|
|
|
10406
11162
|
});
|
|
10407
11163
|
} catch (error) {
|
|
10408
11164
|
const reason = error instanceof Error ? error.message : String(error);
|
|
10409
|
-
throw new PersonaError(`${method} ${
|
|
11165
|
+
throw new PersonaError(`${method} ${path17} failed: ${reason}`, {
|
|
10410
11166
|
cause: error
|
|
10411
11167
|
});
|
|
10412
11168
|
}
|
|
@@ -10414,10 +11170,10 @@ var PersonasClient = class _PersonasClient {
|
|
|
10414
11170
|
if (!response.ok) {
|
|
10415
11171
|
const detail = text2.slice(0, 500);
|
|
10416
11172
|
throw new PersonaError(
|
|
10417
|
-
`${method} ${
|
|
11173
|
+
`${method} ${path17} failed (${response.status}): ${detail}`
|
|
10418
11174
|
);
|
|
10419
11175
|
}
|
|
10420
|
-
this.log("%s %s -> %s", method,
|
|
11176
|
+
this.log("%s %s -> %s", method, path17, response.status);
|
|
10421
11177
|
return safeJson3(text2);
|
|
10422
11178
|
}
|
|
10423
11179
|
authHeader() {
|
|
@@ -10642,10 +11398,10 @@ var SessionRecording = class _SessionRecording {
|
|
|
10642
11398
|
};
|
|
10643
11399
|
}
|
|
10644
11400
|
/** Dump the full session as a JSON fixture (for regression tests). */
|
|
10645
|
-
toFixture(
|
|
10646
|
-
(0, import_node_fs.mkdirSync)((0, import_node_path.dirname)(
|
|
10647
|
-
(0, import_node_fs.writeFileSync)(
|
|
10648
|
-
return
|
|
11401
|
+
toFixture(path17) {
|
|
11402
|
+
(0, import_node_fs.mkdirSync)((0, import_node_path.dirname)(path17), { recursive: true });
|
|
11403
|
+
(0, import_node_fs.writeFileSync)(path17, JSON.stringify(this.toJSON(), null, 2), "utf-8");
|
|
11404
|
+
return path17;
|
|
10649
11405
|
}
|
|
10650
11406
|
static fromApi(raw) {
|
|
10651
11407
|
return new _SessionRecording({
|
|
@@ -11676,8 +12432,8 @@ var GatewaySecurity = class _GatewaySecurity {
|
|
|
11676
12432
|
);
|
|
11677
12433
|
}
|
|
11678
12434
|
}
|
|
11679
|
-
async postJson(
|
|
11680
|
-
const response = await fetch(`${this.host}${
|
|
12435
|
+
async postJson(path17, payload) {
|
|
12436
|
+
const response = await fetch(`${this.host}${path17}`, {
|
|
11681
12437
|
method: "POST",
|
|
11682
12438
|
headers: {
|
|
11683
12439
|
Authorization: this.authHeader(),
|
|
@@ -11688,7 +12444,7 @@ var GatewaySecurity = class _GatewaySecurity {
|
|
|
11688
12444
|
if (!response.ok) {
|
|
11689
12445
|
const body = await response.text();
|
|
11690
12446
|
throw new GatewaySecurityError(
|
|
11691
|
-
`Gateway API ${response.status} on ${
|
|
12447
|
+
`Gateway API ${response.status} on ${path17}: ${body || response.statusText}`
|
|
11692
12448
|
);
|
|
11693
12449
|
}
|
|
11694
12450
|
return await response.json();
|
|
@@ -11780,7 +12536,7 @@ __export(files_exports, {
|
|
|
11780
12536
|
});
|
|
11781
12537
|
var import_node_crypto11 = require("crypto");
|
|
11782
12538
|
var fs13 = __toESM(require("fs"));
|
|
11783
|
-
var
|
|
12539
|
+
var path13 = __toESM(require("path"));
|
|
11784
12540
|
var import_node_stream = require("stream");
|
|
11785
12541
|
var import_promises = require("stream/promises");
|
|
11786
12542
|
init_worlds();
|
|
@@ -11832,7 +12588,7 @@ async function readFile2(options = {}, filePath, limits = {}) {
|
|
|
11832
12588
|
async function downloadFile(options = {}, filePath, outPath, onProgress) {
|
|
11833
12589
|
const file = await getFile(options, filePath);
|
|
11834
12590
|
const res = await openDownload(file.url);
|
|
11835
|
-
fs13.mkdirSync(
|
|
12591
|
+
fs13.mkdirSync(path13.dirname(path13.resolve(outPath)), { recursive: true });
|
|
11836
12592
|
const source = import_node_stream.Readable.fromWeb(res.body);
|
|
11837
12593
|
await (0, import_promises.pipeline)(source, counting((n) => onProgress?.(n, file.sizeBytes)), fs13.createWriteStream(outPath));
|
|
11838
12594
|
return { ...file, out: outPath };
|
|
@@ -11881,7 +12637,7 @@ var CONTENT_TYPES = {
|
|
|
11881
12637
|
".mp4": "video/mp4"
|
|
11882
12638
|
};
|
|
11883
12639
|
function contentTypeFor(name) {
|
|
11884
|
-
return CONTENT_TYPES[
|
|
12640
|
+
return CONTENT_TYPES[path13.extname(name).toLowerCase()] ?? "application/octet-stream";
|
|
11885
12641
|
}
|
|
11886
12642
|
function counting(report) {
|
|
11887
12643
|
let seen = 0;
|
|
@@ -13703,9 +14459,9 @@ function alternatives(raw) {
|
|
|
13703
14459
|
if (!parts2.length || parts2.includes("*")) return [];
|
|
13704
14460
|
return parts2;
|
|
13705
14461
|
}
|
|
13706
|
-
function hasPath(node,
|
|
14462
|
+
function hasPath(node, path17) {
|
|
13707
14463
|
let current = node;
|
|
13708
|
-
for (const part of
|
|
14464
|
+
for (const part of path17.split(".")) {
|
|
13709
14465
|
if (current && typeof current === "object" && !Array.isArray(current) && part in current) {
|
|
13710
14466
|
current = current[part];
|
|
13711
14467
|
continue;
|
|
@@ -13746,7 +14502,7 @@ function matches(m, event) {
|
|
|
13746
14502
|
if (m.args.length) {
|
|
13747
14503
|
const haystacks = event.event === "pre_request" || event.event === "post_response" ? [event.request?.query, event.request?.body] : [event.toolInput];
|
|
13748
14504
|
const present = haystacks.filter((h) => h !== void 0 && h !== null);
|
|
13749
|
-
if (!m.args.every((
|
|
14505
|
+
if (!m.args.every((path17) => present.some((h) => hasPath(h, path17))))
|
|
13750
14506
|
return false;
|
|
13751
14507
|
}
|
|
13752
14508
|
return true;
|
|
@@ -14582,7 +15338,7 @@ function parseHandler(event, raw, position) {
|
|
|
14582
15338
|
// src/hooks/handlers.ts
|
|
14583
15339
|
var import_node_child_process4 = require("child_process");
|
|
14584
15340
|
var fs15 = __toESM(require("fs"));
|
|
14585
|
-
var
|
|
15341
|
+
var path14 = __toESM(require("path"));
|
|
14586
15342
|
var import_node_url = require("url");
|
|
14587
15343
|
function parseStdout(text2, handler) {
|
|
14588
15344
|
const stripped = text2.trim();
|
|
@@ -14783,7 +15539,7 @@ var RecordHandler = class {
|
|
|
14783
15539
|
record.source = this.opts.source ?? null;
|
|
14784
15540
|
if (Array.isArray(this.sink)) this.sink.push(record);
|
|
14785
15541
|
else if (typeof this.sink === "string") {
|
|
14786
|
-
fs15.mkdirSync(
|
|
15542
|
+
fs15.mkdirSync(path14.dirname(this.sink), { recursive: true });
|
|
14787
15543
|
fs15.appendFileSync(this.sink, JSON.stringify(record) + "\n");
|
|
14788
15544
|
} else await this.sink(record);
|
|
14789
15545
|
return allow();
|
|
@@ -14994,7 +15750,7 @@ async function importCallable(target, cwd) {
|
|
|
14994
15750
|
const hash = target.lastIndexOf("#");
|
|
14995
15751
|
const modulePath = target.slice(0, hash);
|
|
14996
15752
|
const exportName = target.slice(hash + 1) || "default";
|
|
14997
|
-
const resolved = modulePath.startsWith(".") ||
|
|
15753
|
+
const resolved = modulePath.startsWith(".") || path14.isAbsolute(modulePath) ? (0, import_node_url.pathToFileURL)(path14.resolve(cwd, modulePath)).href : modulePath;
|
|
14998
15754
|
let module2;
|
|
14999
15755
|
try {
|
|
15000
15756
|
module2 = await import(resolved);
|
|
@@ -15058,7 +15814,7 @@ async function buildHandler(spec, aliases, opts) {
|
|
|
15058
15814
|
|
|
15059
15815
|
// src/hooks/live.ts
|
|
15060
15816
|
var fs16 = __toESM(require("fs"));
|
|
15061
|
-
var
|
|
15817
|
+
var path15 = __toESM(require("path"));
|
|
15062
15818
|
var USER_AGENT = "gateway-hooks/1 (+https://withgateway.ai)";
|
|
15063
15819
|
var TAGS = /<(script|style)[^>]*>.*?<\/\1>/gis;
|
|
15064
15820
|
var STRIP = /<[^>]+>/g;
|
|
@@ -15078,13 +15834,13 @@ var Pacer = class {
|
|
|
15078
15834
|
/** Waits until the interval since the tool's last call has passed; resolves to the
|
|
15079
15835
|
* seconds waited. `sleep`/`clock` are injectable for tests. */
|
|
15080
15836
|
async wait(name, intervalMs, opts = {}) {
|
|
15081
|
-
const
|
|
15837
|
+
const sleep5 = opts.sleep ?? ((seconds) => new Promise((resolve11) => setTimeout(resolve11, seconds * 1e3)));
|
|
15082
15838
|
const clock = opts.clock ?? (() => Date.now() / 1e3);
|
|
15083
15839
|
const now = clock();
|
|
15084
15840
|
const due = (this.last.get(name) ?? -Infinity) + intervalMs / 1e3;
|
|
15085
15841
|
const waited = Math.max(0, due - now);
|
|
15086
15842
|
this.last.set(name, Math.max(now, due));
|
|
15087
|
-
if (waited) await
|
|
15843
|
+
if (waited) await sleep5(waited);
|
|
15088
15844
|
return Math.round(waited * 1e3) / 1e3;
|
|
15089
15845
|
}
|
|
15090
15846
|
};
|
|
@@ -15426,7 +16182,7 @@ var CallableTool = class _CallableTool {
|
|
|
15426
16182
|
}
|
|
15427
16183
|
};
|
|
15428
16184
|
function readConnection(root) {
|
|
15429
|
-
const file =
|
|
16185
|
+
const file = path15.join(root, "connector.toml");
|
|
15430
16186
|
if (!fs16.existsSync(file)) throw new Error(`no connector.toml at ${root}`);
|
|
15431
16187
|
const raw = parseToml(fs16.readFileSync(file, "utf8"));
|
|
15432
16188
|
const connector = raw.connector ?? {};
|
|
@@ -15442,7 +16198,7 @@ function readConnection(root) {
|
|
|
15442
16198
|
};
|
|
15443
16199
|
}
|
|
15444
16200
|
return {
|
|
15445
|
-
slug: connector.slug ??
|
|
16201
|
+
slug: connector.slug ?? path15.basename(root),
|
|
15446
16202
|
baseUrl: (connector.base_url ?? "").replace(/\/+$/, ""),
|
|
15447
16203
|
scheme: auth.scheme ?? "none",
|
|
15448
16204
|
...typeof auth.name === "string" ? { authName: auth.name } : {},
|
|
@@ -15459,8 +16215,8 @@ var ConnectorTool = class {
|
|
|
15459
16215
|
this.spec = spec;
|
|
15460
16216
|
this.live = live;
|
|
15461
16217
|
let location = spec.options.connector;
|
|
15462
|
-
if (!
|
|
15463
|
-
const root = fs16.existsSync(location) && fs16.statSync(location).isFile() ?
|
|
16218
|
+
if (!path15.isAbsolute(location)) location = path15.resolve(baseDir, location);
|
|
16219
|
+
const root = fs16.existsSync(location) && fs16.statSync(location).isFile() ? path15.dirname(location) : location;
|
|
15464
16220
|
try {
|
|
15465
16221
|
this.connection = readConnection(root);
|
|
15466
16222
|
} catch (error) {
|
|
@@ -15617,7 +16373,7 @@ var Recorder = class {
|
|
|
15617
16373
|
}
|
|
15618
16374
|
file;
|
|
15619
16375
|
write(line) {
|
|
15620
|
-
fs16.mkdirSync(
|
|
16376
|
+
fs16.mkdirSync(path15.dirname(this.file), { recursive: true });
|
|
15621
16377
|
fs16.appendFileSync(this.file, canonical2(line) + "\n");
|
|
15622
16378
|
}
|
|
15623
16379
|
};
|
|
@@ -15713,7 +16469,7 @@ var LiveTools = class _LiveTools {
|
|
|
15713
16469
|
...config.live.record ? { record: interpolatePath(config.live.record, run.runId, directory) } : {},
|
|
15714
16470
|
...config.live.replay ? { replay: interpolatePath(config.live.replay, run.runId, directory) } : {}
|
|
15715
16471
|
};
|
|
15716
|
-
return _LiveTools.create(run, live,
|
|
16472
|
+
return _LiveTools.create(run, live, path15.dirname(path15.resolve(file)));
|
|
15717
16473
|
}
|
|
15718
16474
|
/** The declared tools for a model. `openai`: `{type: "function", function: {name,
|
|
15719
16475
|
* description, parameters}}`; `anthropic`: `{name, description, input_schema}`. */
|
|
@@ -16040,7 +16796,7 @@ var RedactionAudit = class _RedactionAudit {
|
|
|
16040
16796
|
// src/hooks/run.ts
|
|
16041
16797
|
var import_node_crypto14 = require("crypto");
|
|
16042
16798
|
var fs17 = __toESM(require("fs"));
|
|
16043
|
-
var
|
|
16799
|
+
var path16 = __toESM(require("path"));
|
|
16044
16800
|
var BLOCKING_EVENTS = [
|
|
16045
16801
|
"pre_tool_call",
|
|
16046
16802
|
"pre_request",
|
|
@@ -16091,12 +16847,12 @@ var HookRun = class _HookRun {
|
|
|
16091
16847
|
declaredOnly: options.declaredOnly ?? config.aliasDeclaredOnly
|
|
16092
16848
|
});
|
|
16093
16849
|
this.cwd = options.cwd ?? process.cwd();
|
|
16094
|
-
this.runDir = options.runDir ??
|
|
16850
|
+
this.runDir = options.runDir ?? path16.join(this.cwd, "runs", this.runId);
|
|
16095
16851
|
const chosen = options.legend !== void 0 ? options.legend : config.aliasLegend;
|
|
16096
|
-
this.legendPath = chosen ?
|
|
16852
|
+
this.legendPath = chosen ? path16.resolve(this.cwd, interpolatePath(chosen, this.runId, this.runDir)) : null;
|
|
16097
16853
|
this.sessionId = options.session;
|
|
16098
16854
|
this.source = options.source;
|
|
16099
|
-
this.configDir = config.source ?
|
|
16855
|
+
this.configDir = config.source ? path16.dirname(path16.resolve(config.source)) : this.cwd;
|
|
16100
16856
|
}
|
|
16101
16857
|
/** Build from a parsed config (an object in the file's shape, or a `HookConfig`);
|
|
16102
16858
|
* handlers are constructed now, so a callable that does not import fails here. */
|
|
@@ -16506,7 +17262,7 @@ var HookRun = class _HookRun {
|
|
|
16506
17262
|
throw new Error(
|
|
16507
17263
|
"no legend path: set [alias] legend, pass legend to the run, or give a path"
|
|
16508
17264
|
);
|
|
16509
|
-
fs17.mkdirSync(
|
|
17265
|
+
fs17.mkdirSync(path16.dirname(target), { recursive: true });
|
|
16510
17266
|
fs17.writeFileSync(target, JSON.stringify(this.legend(), null, 2) + "\n");
|
|
16511
17267
|
return target;
|
|
16512
17268
|
}
|
|
@@ -16603,14 +17359,14 @@ var HookedSession = class {
|
|
|
16603
17359
|
* `apiHeaders()`), `pre_request` before it and `post_response` after. Returns
|
|
16604
17360
|
* `{status, body, headers}`; a 4xx/5xx is returned, not thrown, so the agent sees
|
|
16605
17361
|
* the vendor's own error shape (rewritten like any result). */
|
|
16606
|
-
async request(method,
|
|
17362
|
+
async request(method, path17, opts = {}) {
|
|
16607
17363
|
if (!this.inner.api && !this.requestFn)
|
|
16608
17364
|
throw new Error(
|
|
16609
17365
|
"this session has no api surface (pass requestFn for a transport of your own)"
|
|
16610
17366
|
);
|
|
16611
17367
|
let request = {
|
|
16612
17368
|
method: method.toUpperCase(),
|
|
16613
|
-
path:
|
|
17369
|
+
path: path17,
|
|
16614
17370
|
query: { ...opts.query ?? {} },
|
|
16615
17371
|
body: opts.body ?? null
|
|
16616
17372
|
};
|
|
@@ -17079,6 +17835,8 @@ var tracing = {
|
|
|
17079
17835
|
GatewaySecurityError,
|
|
17080
17836
|
GatewayToolApprovalRequiredError,
|
|
17081
17837
|
GatewayToolBlockedError,
|
|
17838
|
+
GradePayload,
|
|
17839
|
+
GradeRefused,
|
|
17082
17840
|
HostedDryRunClient,
|
|
17083
17841
|
IDLE_WARNING_MINUTES,
|
|
17084
17842
|
KEY_NAMES,
|
|
@@ -17104,6 +17862,7 @@ var tracing = {
|
|
|
17104
17862
|
ReplayReport,
|
|
17105
17863
|
ReplaySuite,
|
|
17106
17864
|
ReplayTask,
|
|
17865
|
+
RetryPolicy,
|
|
17107
17866
|
SANDBOX_REQUEST_TIMEOUT_MS,
|
|
17108
17867
|
SECRET_KEY,
|
|
17109
17868
|
SESSION_STATES,
|
|
@@ -17113,6 +17872,7 @@ var tracing = {
|
|
|
17113
17872
|
SUCCESS_METRIC_NAME_KEY,
|
|
17114
17873
|
SUCCESS_SIGNAL_KEY,
|
|
17115
17874
|
SURFACE_KINDS,
|
|
17875
|
+
Score,
|
|
17116
17876
|
ScoreError,
|
|
17117
17877
|
ScoresClient,
|
|
17118
17878
|
Screen,
|
|
@@ -17121,6 +17881,7 @@ var tracing = {
|
|
|
17121
17881
|
SessionRecording,
|
|
17122
17882
|
SessionTrace,
|
|
17123
17883
|
StubMissError,
|
|
17884
|
+
TOOL_CONTRACT_UNREAD,
|
|
17124
17885
|
TRANSFORMS,
|
|
17125
17886
|
TaskEditClient,
|
|
17126
17887
|
TaskRun,
|
|
@@ -17136,14 +17897,17 @@ var tracing = {
|
|
|
17136
17897
|
WorldBrowser,
|
|
17137
17898
|
WorldCallTooLarge,
|
|
17138
17899
|
WorldEditClient,
|
|
17900
|
+
WorldNotice,
|
|
17139
17901
|
WorldRequestLog,
|
|
17140
17902
|
WorldSandboxClient,
|
|
17141
17903
|
WorldSession,
|
|
17142
17904
|
WorldSessionCallError,
|
|
17905
|
+
WorldSessionOpenFailed,
|
|
17143
17906
|
WorldSessionTimeout,
|
|
17144
17907
|
WorldSet,
|
|
17145
17908
|
WorldSurfaceUnavailable,
|
|
17146
17909
|
WorldTask,
|
|
17910
|
+
WorldToolsUnread,
|
|
17147
17911
|
addExperimentAttributes,
|
|
17148
17912
|
aggregateTaskGrade,
|
|
17149
17913
|
apiRequest,
|
|
@@ -17210,6 +17974,7 @@ var tracing = {
|
|
|
17210
17974
|
loadSession,
|
|
17211
17975
|
localTreeState,
|
|
17212
17976
|
memory,
|
|
17977
|
+
messageOf,
|
|
17213
17978
|
migrateProjectWorlds,
|
|
17214
17979
|
migrateWorld,
|
|
17215
17980
|
modelToolName,
|
|
@@ -17267,12 +18032,16 @@ var tracing = {
|
|
|
17267
18032
|
setExperimentContext,
|
|
17268
18033
|
shapeText,
|
|
17269
18034
|
snapshotTreeHashes,
|
|
18035
|
+
sqlRows,
|
|
18036
|
+
stillStartingHint,
|
|
17270
18037
|
storedForms,
|
|
17271
18038
|
success,
|
|
17272
18039
|
suite,
|
|
17273
18040
|
surfaceDescriptor,
|
|
17274
18041
|
surfaceKinds,
|
|
18042
|
+
taskGradeError,
|
|
17275
18043
|
taskLabel,
|
|
18044
|
+
taskRunFailure,
|
|
17276
18045
|
toolCallRecordsIn,
|
|
17277
18046
|
toolCallsFromObservations,
|
|
17278
18047
|
traces,
|