@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.mjs
CHANGED
|
@@ -190,10 +190,10 @@ var init_users = __esm({
|
|
|
190
190
|
totalItems: Number(meta.totalItems ?? rows.length)
|
|
191
191
|
};
|
|
192
192
|
}
|
|
193
|
-
async requestJson(method,
|
|
193
|
+
async requestJson(method, path17, payload) {
|
|
194
194
|
let response;
|
|
195
195
|
try {
|
|
196
|
-
response = await fetch(`${this.host}${
|
|
196
|
+
response = await fetch(`${this.host}${path17}`, {
|
|
197
197
|
method,
|
|
198
198
|
headers: {
|
|
199
199
|
Authorization: this.authHeader(),
|
|
@@ -204,17 +204,17 @@ var init_users = __esm({
|
|
|
204
204
|
});
|
|
205
205
|
} catch (error) {
|
|
206
206
|
throw new UserProfileError(
|
|
207
|
-
`${method} ${
|
|
207
|
+
`${method} ${path17} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
208
208
|
{ cause: error }
|
|
209
209
|
);
|
|
210
210
|
}
|
|
211
211
|
const text2 = await response.text();
|
|
212
212
|
if (!response.ok) {
|
|
213
213
|
throw new UserProfileError(
|
|
214
|
-
`${method} ${
|
|
214
|
+
`${method} ${path17} failed (${response.status}): ${text2.slice(0, 500)}`
|
|
215
215
|
);
|
|
216
216
|
}
|
|
217
|
-
this.log("%s %s -> %s", method,
|
|
217
|
+
this.log("%s %s -> %s", method, path17, response.status);
|
|
218
218
|
return safeJson4(text2);
|
|
219
219
|
}
|
|
220
220
|
authHeader() {
|
|
@@ -403,10 +403,10 @@ var init_scores = __esm({
|
|
|
403
403
|
metadata: signalMetadata
|
|
404
404
|
});
|
|
405
405
|
}
|
|
406
|
-
async request(method,
|
|
406
|
+
async request(method, path17, payload) {
|
|
407
407
|
let response;
|
|
408
408
|
try {
|
|
409
|
-
response = await fetch(`${this.host}${
|
|
409
|
+
response = await fetch(`${this.host}${path17}`, {
|
|
410
410
|
method,
|
|
411
411
|
headers: {
|
|
412
412
|
Authorization: this.authHeader(),
|
|
@@ -417,17 +417,17 @@ var init_scores = __esm({
|
|
|
417
417
|
});
|
|
418
418
|
} catch (error) {
|
|
419
419
|
throw new ScoreError(
|
|
420
|
-
`${method} ${
|
|
420
|
+
`${method} ${path17} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
421
421
|
{ cause: error }
|
|
422
422
|
);
|
|
423
423
|
}
|
|
424
424
|
const text2 = await response.text();
|
|
425
425
|
if (!response.ok) {
|
|
426
426
|
throw new ScoreError(
|
|
427
|
-
`${method} ${
|
|
427
|
+
`${method} ${path17} failed (${response.status}): ${text2.slice(0, 500)}`
|
|
428
428
|
);
|
|
429
429
|
}
|
|
430
|
-
this.log("%s %s -> %s", method,
|
|
430
|
+
this.log("%s %s -> %s", method, path17, response.status);
|
|
431
431
|
}
|
|
432
432
|
authHeader() {
|
|
433
433
|
return `Basic ${Buffer.from(`${this.publicKey}:${this.secretKey}`).toString(
|
|
@@ -450,6 +450,28 @@ var init_scores = __esm({
|
|
|
450
450
|
}
|
|
451
451
|
});
|
|
452
452
|
|
|
453
|
+
// src/worlds/platformEndpoint.ts
|
|
454
|
+
function platformEndpoint(options) {
|
|
455
|
+
const publicKey = options.publicKey ?? process.env.GATEWAY_PUBLIC_KEY;
|
|
456
|
+
const secretKey = options.secretKey ?? process.env.GATEWAY_SECRET_KEY;
|
|
457
|
+
if (!publicKey || !secretKey) return null;
|
|
458
|
+
const host = options.host ?? process.env.GATEWAY_HOST ?? DEFAULT_HOST;
|
|
459
|
+
return { host: host.replace(/\/+$/, ""), publicKey, secretKey };
|
|
460
|
+
}
|
|
461
|
+
function requirePlatformEndpoint(options) {
|
|
462
|
+
const endpoint = platformEndpoint(options);
|
|
463
|
+
if (!endpoint) throw new Error(GATEWAY_KEYS_MISSING);
|
|
464
|
+
return endpoint;
|
|
465
|
+
}
|
|
466
|
+
var DEFAULT_HOST, GATEWAY_KEYS_MISSING;
|
|
467
|
+
var init_platformEndpoint = __esm({
|
|
468
|
+
"src/worlds/platformEndpoint.ts"() {
|
|
469
|
+
"use strict";
|
|
470
|
+
DEFAULT_HOST = "https://withgateway.ai";
|
|
471
|
+
GATEWAY_KEYS_MISSING = "Gateway keys missing: set GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY (or pass publicKey/secretKey).";
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
|
|
453
475
|
// src/worlds/transport.ts
|
|
454
476
|
function platformTimeoutMs(env = process.env) {
|
|
455
477
|
const raw = env[PLATFORM_TIMEOUT_ENV];
|
|
@@ -458,7 +480,7 @@ function platformTimeoutMs(env = process.env) {
|
|
|
458
480
|
if (Number.isInteger(value) && value > 0) return value;
|
|
459
481
|
throw new Error(`${PLATFORM_TIMEOUT_ENV} must be a positive whole number of milliseconds, not \`${raw}\`.`);
|
|
460
482
|
}
|
|
461
|
-
var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, PlatformTransport;
|
|
483
|
+
var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, sleep2, RetryPolicy, Attempt, PlatformTransport;
|
|
462
484
|
var init_transport = __esm({
|
|
463
485
|
"src/worlds/transport.ts"() {
|
|
464
486
|
"use strict";
|
|
@@ -520,6 +542,56 @@ var init_transport = __esm({
|
|
|
520
542
|
route;
|
|
521
543
|
failure;
|
|
522
544
|
};
|
|
545
|
+
sleep2 = (ms) => new Promise((resolve11) => setTimeout(resolve11, ms));
|
|
546
|
+
RetryPolicy = class _RetryPolicy {
|
|
547
|
+
constructor(delaysMs, wait = sleep2, budgetMs = Number.POSITIVE_INFINITY, now = Date.now) {
|
|
548
|
+
this.delaysMs = delaysMs;
|
|
549
|
+
this.wait = wait;
|
|
550
|
+
this.budgetMs = budgetMs;
|
|
551
|
+
this.now = now;
|
|
552
|
+
}
|
|
553
|
+
delaysMs;
|
|
554
|
+
wait;
|
|
555
|
+
budgetMs;
|
|
556
|
+
now;
|
|
557
|
+
static NONE = new _RetryPolicy([]);
|
|
558
|
+
/** A platform restart or a short edge outage: no wait starts that would end past five minutes, so a step ends
|
|
559
|
+
* within the budget plus one request timeout. */
|
|
560
|
+
static FILING = new _RetryPolicy([250, 500, 1e3, 2e3, 4e3, 8e3, 16e3, 3e4], sleep2, 3e5);
|
|
561
|
+
static TRANSIENT_STATUSES = /* @__PURE__ */ new Set([502, 503, 504]);
|
|
562
|
+
async run(attempt) {
|
|
563
|
+
const started = this.now();
|
|
564
|
+
for (let tries = 0; ; tries += 1) {
|
|
565
|
+
const outcome = await Attempt.of(attempt);
|
|
566
|
+
const delayMs = this.delaysMs[tries];
|
|
567
|
+
const spent = delayMs === void 0 || this.now() - started + delayMs >= this.budgetMs;
|
|
568
|
+
if (!outcome.transient || spent) return outcome.settle();
|
|
569
|
+
await this.wait(delayMs);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
Attempt = class _Attempt {
|
|
574
|
+
constructor(reply, error, transient) {
|
|
575
|
+
this.reply = reply;
|
|
576
|
+
this.error = error;
|
|
577
|
+
this.transient = transient;
|
|
578
|
+
}
|
|
579
|
+
reply;
|
|
580
|
+
error;
|
|
581
|
+
transient;
|
|
582
|
+
static async of(attempt) {
|
|
583
|
+
try {
|
|
584
|
+
const reply = await attempt();
|
|
585
|
+
return new _Attempt(reply, null, RetryPolicy.TRANSIENT_STATUSES.has(reply.status));
|
|
586
|
+
} catch (error) {
|
|
587
|
+
return new _Attempt(null, error, error instanceof UnreachableError);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
settle() {
|
|
591
|
+
if (this.reply) return this.reply;
|
|
592
|
+
throw this.error;
|
|
593
|
+
}
|
|
594
|
+
};
|
|
523
595
|
PlatformTransport = class {
|
|
524
596
|
constructor(endpoint, timeoutMs = platformTimeoutMs()) {
|
|
525
597
|
this.endpoint = endpoint;
|
|
@@ -533,6 +605,9 @@ var init_transport = __esm({
|
|
|
533
605
|
}
|
|
534
606
|
async send(method, route, body, opts = {}) {
|
|
535
607
|
const timeoutMs = this.budget(opts.timeoutMs);
|
|
608
|
+
return (opts.retry ?? RetryPolicy.NONE).run(() => this.once(method, route, body, timeoutMs));
|
|
609
|
+
}
|
|
610
|
+
async once(method, route, body, timeoutMs) {
|
|
536
611
|
const payload = body === void 0 ? {} : { body: JSON.stringify(body) };
|
|
537
612
|
const controller = new AbortController();
|
|
538
613
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
@@ -726,9 +801,9 @@ function surfaceKinds(s) {
|
|
|
726
801
|
if (s.browser) kinds.push("browser");
|
|
727
802
|
return kinds;
|
|
728
803
|
}
|
|
729
|
-
function uiUrl(ui,
|
|
804
|
+
function uiUrl(ui, path17) {
|
|
730
805
|
const base = ui.url.replace(/\/+$/, "");
|
|
731
|
-
const rel =
|
|
806
|
+
const rel = path17.startsWith("/") ? path17 : `/${path17}`;
|
|
732
807
|
if (!ui.token) return base + rel;
|
|
733
808
|
const [beforeHash, hash] = splitHash(rel);
|
|
734
809
|
const joiner = beforeHash.includes("?") ? "&" : "?";
|
|
@@ -969,7 +1044,7 @@ var init_browser = __esm({
|
|
|
969
1044
|
}
|
|
970
1045
|
async send(batch) {
|
|
971
1046
|
const retries = this.opts.maxRetries ?? EVENT_MAX_RETRIES;
|
|
972
|
-
const
|
|
1047
|
+
const sleep5 = this.opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
973
1048
|
for (let attempt = 0; attempt < retries; attempt++) {
|
|
974
1049
|
try {
|
|
975
1050
|
const base = await this.resolveBase();
|
|
@@ -986,7 +1061,7 @@ var init_browser = __esm({
|
|
|
986
1061
|
);
|
|
987
1062
|
return;
|
|
988
1063
|
}
|
|
989
|
-
await
|
|
1064
|
+
await sleep5(500 * 2 ** attempt);
|
|
990
1065
|
}
|
|
991
1066
|
}
|
|
992
1067
|
}
|
|
@@ -1623,13 +1698,13 @@ var init_screen = __esm({
|
|
|
1623
1698
|
});
|
|
1624
1699
|
}
|
|
1625
1700
|
async drag(action) {
|
|
1626
|
-
const
|
|
1627
|
-
if (
|
|
1701
|
+
const path17 = action.args.path ?? [];
|
|
1702
|
+
if (path17.length < 2) throw new Error("a drag needs at least two points");
|
|
1628
1703
|
return this.held(action.args.modifiers ?? [], async () => {
|
|
1629
|
-
await this.moveTo(
|
|
1704
|
+
await this.moveTo(path17[0]);
|
|
1630
1705
|
await this.page.mouse.down({ button: "left" });
|
|
1631
1706
|
try {
|
|
1632
|
-
for (const point2 of
|
|
1707
|
+
for (const point2 of path17.slice(1)) await this.moveTo(point2, DRAG_STEPS);
|
|
1633
1708
|
} finally {
|
|
1634
1709
|
await this.page.mouse.up({ button: "left" });
|
|
1635
1710
|
}
|
|
@@ -1720,7 +1795,7 @@ var init_media = __esm({
|
|
|
1720
1795
|
put;
|
|
1721
1796
|
maxBytes;
|
|
1722
1797
|
/** The uploader for `GATEWAY_HOST` / `GATEWAY_PUBLIC_KEY` /
|
|
1723
|
-
* `GATEWAY_SECRET_KEY`
|
|
1798
|
+
* `GATEWAY_SECRET_KEY` only; null when any is unset, so a run traced with a saved login uploads none. */
|
|
1724
1799
|
static fromEnv(env = process.env) {
|
|
1725
1800
|
const host = env.GATEWAY_HOST;
|
|
1726
1801
|
const publicKey = env.GATEWAY_PUBLIC_KEY;
|
|
@@ -2590,7 +2665,7 @@ function idleWarning(idleExpiresAt, now = /* @__PURE__ */ new Date()) {
|
|
|
2590
2665
|
const minutes = Math.max(0, Math.floor(leftMs / 6e4));
|
|
2591
2666
|
return `warning: session expires in ${minutes}m (idle TTL); call a tool to extend it or \`gateway worlds session pin\` to keep it`;
|
|
2592
2667
|
}
|
|
2593
|
-
var CALL_BODY_LIMIT_BYTES, CALL_BODY_LIMIT_LABEL, IDLE_WARNING_MINUTES, EXPLORATORY_TASK, EXPLORATORY_TASK_SOURCE, NO_GRADER_REASON, WorldCallTooLarge;
|
|
2668
|
+
var CALL_BODY_LIMIT_BYTES, CALL_BODY_LIMIT_LABEL, IDLE_WARNING_MINUTES, EXPLORATORY_TASK, EXPLORATORY_TASK_SOURCE, NO_GRADER_REASON, WorldCallTooLarge, stillStartingHint;
|
|
2594
2669
|
var init_sessionContract = __esm({
|
|
2595
2670
|
"src/worlds/sessionContract.ts"() {
|
|
2596
2671
|
"use strict";
|
|
@@ -2626,6 +2701,65 @@ var init_sessionContract = __esm({
|
|
|
2626
2701
|
};
|
|
2627
2702
|
}
|
|
2628
2703
|
};
|
|
2704
|
+
stillStartingHint = (sessionId) => `It keeps opening: poll \`gateway worlds session status ${sessionId}\` until ready, or end it with \`gateway worlds session close ${sessionId}\`.`;
|
|
2705
|
+
}
|
|
2706
|
+
});
|
|
2707
|
+
|
|
2708
|
+
// src/worlds/sessionReadiness.ts
|
|
2709
|
+
var READY_TIMEOUT_MS, READY_POLL_MS, sleep3, WorldSessionTimeout, WorldSessionCallError, WorldSessionOpenFailed, ENDED, SessionReadiness;
|
|
2710
|
+
var init_sessionReadiness = __esm({
|
|
2711
|
+
"src/worlds/sessionReadiness.ts"() {
|
|
2712
|
+
"use strict";
|
|
2713
|
+
READY_TIMEOUT_MS = 10 * 6e4;
|
|
2714
|
+
READY_POLL_MS = 2e3;
|
|
2715
|
+
sleep3 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
2716
|
+
WorldSessionTimeout = class extends Error {
|
|
2717
|
+
};
|
|
2718
|
+
WorldSessionCallError = class extends Error {
|
|
2719
|
+
};
|
|
2720
|
+
WorldSessionOpenFailed = class extends WorldSessionCallError {
|
|
2721
|
+
constructor(sessionId, state2, code, reason) {
|
|
2722
|
+
super(
|
|
2723
|
+
reason === null ? `World session ${sessionId} ${state2.toLowerCase()} before it was ready.` : `World session ${sessionId} failed to open: ${reason}${code ? ` (${code})` : ""}`
|
|
2724
|
+
);
|
|
2725
|
+
this.sessionId = sessionId;
|
|
2726
|
+
this.state = state2;
|
|
2727
|
+
this.code = code;
|
|
2728
|
+
this.name = "WorldSessionOpenFailed";
|
|
2729
|
+
}
|
|
2730
|
+
sessionId;
|
|
2731
|
+
state;
|
|
2732
|
+
code;
|
|
2733
|
+
};
|
|
2734
|
+
ENDED = /* @__PURE__ */ new Set(["FAILED", "STOPPED"]);
|
|
2735
|
+
SessionReadiness = class {
|
|
2736
|
+
constructor(sessionId, status) {
|
|
2737
|
+
this.sessionId = sessionId;
|
|
2738
|
+
this.status = status;
|
|
2739
|
+
}
|
|
2740
|
+
sessionId;
|
|
2741
|
+
status;
|
|
2742
|
+
async wait(timeoutMs = READY_TIMEOUT_MS) {
|
|
2743
|
+
const deadline = Date.now() + timeoutMs;
|
|
2744
|
+
for (; ; ) {
|
|
2745
|
+
const state2 = await this.status();
|
|
2746
|
+
if (state2.ready) return state2;
|
|
2747
|
+
if (ENDED.has(state2.state))
|
|
2748
|
+
throw new WorldSessionOpenFailed(
|
|
2749
|
+
this.sessionId,
|
|
2750
|
+
state2.state,
|
|
2751
|
+
state2.failure?.code ?? null,
|
|
2752
|
+
state2.failure?.message ?? null
|
|
2753
|
+
);
|
|
2754
|
+
const left = deadline - Date.now();
|
|
2755
|
+
if (left <= 0)
|
|
2756
|
+
throw new WorldSessionTimeout(
|
|
2757
|
+
`World session ${this.sessionId} still ${state2.state} after ${Math.round(timeoutMs / 1e3)}s.`
|
|
2758
|
+
);
|
|
2759
|
+
await sleep3(Math.min(READY_POLL_MS, left));
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
};
|
|
2629
2763
|
}
|
|
2630
2764
|
});
|
|
2631
2765
|
|
|
@@ -2721,11 +2855,184 @@ var init_taskRef = __esm({
|
|
|
2721
2855
|
}
|
|
2722
2856
|
});
|
|
2723
2857
|
|
|
2858
|
+
// src/worlds/worldNotice.ts
|
|
2859
|
+
var TOOL_CONTRACT_UNREAD, DEPRECATION, NOTICE_KINDS, WorldNotice, WorldToolsUnread;
|
|
2860
|
+
var init_worldNotice = __esm({
|
|
2861
|
+
"src/worlds/worldNotice.ts"() {
|
|
2862
|
+
"use strict";
|
|
2863
|
+
TOOL_CONTRACT_UNREAD = "tool-contract-unread";
|
|
2864
|
+
DEPRECATION = { label: "deprecated", next: "Instead", refusesRun: false };
|
|
2865
|
+
NOTICE_KINDS = /* @__PURE__ */ new Map([
|
|
2866
|
+
[TOOL_CONTRACT_UNREAD, { label: "warning", next: "Then", refusesRun: true }]
|
|
2867
|
+
]);
|
|
2868
|
+
WorldNotice = class _WorldNotice {
|
|
2869
|
+
constructor(notice, kind) {
|
|
2870
|
+
this.notice = notice;
|
|
2871
|
+
this.kind = kind;
|
|
2872
|
+
}
|
|
2873
|
+
notice;
|
|
2874
|
+
kind;
|
|
2875
|
+
static of(notice) {
|
|
2876
|
+
return new _WorldNotice(notice, NOTICE_KINDS.get(notice.code) ?? DEPRECATION);
|
|
2877
|
+
}
|
|
2878
|
+
get refusesRun() {
|
|
2879
|
+
return this.kind.refusesRun;
|
|
2880
|
+
}
|
|
2881
|
+
line() {
|
|
2882
|
+
const { code, message, replacement } = this.notice;
|
|
2883
|
+
return `${this.kind.label} (${code}): ${message} ${this.kind.next}: ${replacement}`;
|
|
2884
|
+
}
|
|
2885
|
+
};
|
|
2886
|
+
WorldToolsUnread = class _WorldToolsUnread extends Error {
|
|
2887
|
+
constructor(world, notice) {
|
|
2888
|
+
super(
|
|
2889
|
+
`refused before the agent ran, nothing filed: world ${world} has no readable tools: ${notice.notice.message} Then: ${notice.notice.replacement}`
|
|
2890
|
+
);
|
|
2891
|
+
this.world = world;
|
|
2892
|
+
this.notice = notice;
|
|
2893
|
+
this.name = "WorldToolsUnread";
|
|
2894
|
+
this.code = notice.notice.code;
|
|
2895
|
+
}
|
|
2896
|
+
world;
|
|
2897
|
+
notice;
|
|
2898
|
+
code;
|
|
2899
|
+
static refuse(world, notices) {
|
|
2900
|
+
const refusing = notices.map((notice) => WorldNotice.of(notice)).find((notice) => notice.refusesRun);
|
|
2901
|
+
if (refusing) throw new _WorldToolsUnread(world, refusing);
|
|
2902
|
+
}
|
|
2903
|
+
};
|
|
2904
|
+
}
|
|
2905
|
+
});
|
|
2906
|
+
|
|
2907
|
+
// src/worlds/grade.ts
|
|
2908
|
+
var messageOf, Score, GradeRefused, GradePayload;
|
|
2909
|
+
var init_grade = __esm({
|
|
2910
|
+
"src/worlds/grade.ts"() {
|
|
2911
|
+
"use strict";
|
|
2912
|
+
messageOf = (error) => (error instanceof Error ? error.message || error.name : String(error)) || "Error";
|
|
2913
|
+
Score = class _Score {
|
|
2914
|
+
static RULE = "a score is a number from 0 to 1";
|
|
2915
|
+
static admits(value) {
|
|
2916
|
+
return Number.isFinite(value) && value >= 0 && value <= 1;
|
|
2917
|
+
}
|
|
2918
|
+
/** Every number among `scores` that is not a score, as `'<key>' = <value>`
|
|
2919
|
+
* and the rule, or null when all of them are. Pairs, not a map, so that no
|
|
2920
|
+
* key hides another. */
|
|
2921
|
+
static problem(scores2) {
|
|
2922
|
+
const refused = [...scores2].flatMap(
|
|
2923
|
+
([key2, value]) => typeof value === "number" && !_Score.admits(value) ? [`'${key2}' = ${String(value)}`] : []
|
|
2924
|
+
);
|
|
2925
|
+
return refused.length ? `${refused.join(", ")}; ${_Score.RULE}` : null;
|
|
2926
|
+
}
|
|
2927
|
+
};
|
|
2928
|
+
GradeRefused = class extends Error {
|
|
2929
|
+
name = "GradeRefused";
|
|
2930
|
+
};
|
|
2931
|
+
GradePayload = class _GradePayload {
|
|
2932
|
+
/** A grade payload's numbers, checked: every number in it must be a score,
|
|
2933
|
+
* and its rewards and verifiers objects by name, or the grade is refused; a
|
|
2934
|
+
* cross-world verifier's grade that breaks either rule is that verifier's
|
|
2935
|
+
* error, the way the World Host answers one that could not grade. */
|
|
2936
|
+
static read(raw) {
|
|
2937
|
+
if (!_GradePayload.objectOrAbsent(raw))
|
|
2938
|
+
throw new GradeRefused("the grade is not an object");
|
|
2939
|
+
const record = _GradePayload.record(raw);
|
|
2940
|
+
const problem = _GradePayload.problem(record) ?? _GradePayload.verifiersProblem(record.verifiers);
|
|
2941
|
+
if (problem) throw new GradeRefused(problem);
|
|
2942
|
+
const verifiers = _GradePayload.verifiers(record.verifiers);
|
|
2943
|
+
return {
|
|
2944
|
+
..._GradePayload.numbers(record),
|
|
2945
|
+
...typeof record.reason === "string" ? { reason: record.reason } : {},
|
|
2946
|
+
...typeof record.error === "string" ? { error: record.error } : {},
|
|
2947
|
+
...verifiers ? { verifiers } : {}
|
|
2948
|
+
};
|
|
2949
|
+
}
|
|
2950
|
+
/** A world whose grade call failed (the platform refused it, the host had
|
|
2951
|
+
* lost the session): that world's error, never a score. */
|
|
2952
|
+
static failedCall(error) {
|
|
2953
|
+
return { ..._GradePayload.failed(messageOf(error)), raw: null };
|
|
2954
|
+
}
|
|
2955
|
+
static problem(record) {
|
|
2956
|
+
if (!_GradePayload.objectOrAbsent(record.rewards))
|
|
2957
|
+
return "the grade's rewards are not an object";
|
|
2958
|
+
const scores2 = Score.problem(_GradePayload.scores(record));
|
|
2959
|
+
if (scores2) return `the grade answered ${scores2}`;
|
|
2960
|
+
const twice = _GradePayload.twice(record);
|
|
2961
|
+
return twice.length ? `the grade answered ${twice.map((key2) => `'${key2}'`).join(", ")} both beside and inside rewards` : null;
|
|
2962
|
+
}
|
|
2963
|
+
static twice(record) {
|
|
2964
|
+
return Object.entries(_GradePayload.record(record.rewards)).filter(
|
|
2965
|
+
([key2, value]) => key2 !== "reward" && typeof value === "number" && typeof record[key2] === "number"
|
|
2966
|
+
).map(([key2]) => key2);
|
|
2967
|
+
}
|
|
2968
|
+
static verifiersProblem(value) {
|
|
2969
|
+
return _GradePayload.objectOrAbsent(value) ? null : "the grade's verifiers are not an object";
|
|
2970
|
+
}
|
|
2971
|
+
static scores(record) {
|
|
2972
|
+
return [
|
|
2973
|
+
["reward", record.reward],
|
|
2974
|
+
...Object.entries(_GradePayload.record(record.rewards)),
|
|
2975
|
+
...Object.entries(record).filter(
|
|
2976
|
+
([key2]) => key2 !== "reward" && key2 !== "rewards"
|
|
2977
|
+
)
|
|
2978
|
+
];
|
|
2979
|
+
}
|
|
2980
|
+
static isRecord(value) {
|
|
2981
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2982
|
+
}
|
|
2983
|
+
static objectOrAbsent(value) {
|
|
2984
|
+
return value === void 0 || value === null || _GradePayload.isRecord(value);
|
|
2985
|
+
}
|
|
2986
|
+
static record(value) {
|
|
2987
|
+
return _GradePayload.isRecord(value) ? value : {};
|
|
2988
|
+
}
|
|
2989
|
+
/** `reward`, and every numeric key under `rewards` (the host's shape) or at
|
|
2990
|
+
* the top level (a bundled verifier's). */
|
|
2991
|
+
static numbers(record) {
|
|
2992
|
+
const rewards = {};
|
|
2993
|
+
for (const [key2, value] of Object.entries(
|
|
2994
|
+
_GradePayload.record(record.rewards)
|
|
2995
|
+
))
|
|
2996
|
+
if (typeof value === "number") rewards[key2] = value;
|
|
2997
|
+
for (const [key2, value] of Object.entries(record))
|
|
2998
|
+
if (key2 !== "reward" && typeof value === "number") rewards[key2] = value;
|
|
2999
|
+
return {
|
|
3000
|
+
reward: typeof record.reward === "number" ? record.reward : null,
|
|
3001
|
+
rewards
|
|
3002
|
+
};
|
|
3003
|
+
}
|
|
3004
|
+
static verifiers(value) {
|
|
3005
|
+
if (!_GradePayload.isRecord(value)) return void 0;
|
|
3006
|
+
return Object.fromEntries(
|
|
3007
|
+
Object.entries(value).map(([name, grade]) => [
|
|
3008
|
+
name,
|
|
3009
|
+
_GradePayload.verifier(name, grade)
|
|
3010
|
+
])
|
|
3011
|
+
);
|
|
3012
|
+
}
|
|
3013
|
+
static verifier(name, grade) {
|
|
3014
|
+
if (!_GradePayload.isRecord(grade))
|
|
3015
|
+
return _GradePayload.failed(`the grade's verifier '${name}' is not an object`);
|
|
3016
|
+
const problem = _GradePayload.problem(grade);
|
|
3017
|
+
if (problem) return _GradePayload.failed(problem);
|
|
3018
|
+
return {
|
|
3019
|
+
..._GradePayload.numbers(grade),
|
|
3020
|
+
...typeof grade.error === "string" ? { error: grade.error } : {}
|
|
3021
|
+
};
|
|
3022
|
+
}
|
|
3023
|
+
static failed(error) {
|
|
3024
|
+
return { reward: null, rewards: {}, error };
|
|
3025
|
+
}
|
|
3026
|
+
};
|
|
3027
|
+
}
|
|
3028
|
+
});
|
|
3029
|
+
|
|
2724
3030
|
// src/worlds/session.ts
|
|
2725
3031
|
var session_exports2 = {};
|
|
2726
3032
|
__export(session_exports2, {
|
|
2727
3033
|
WorldSession: () => WorldSession,
|
|
2728
3034
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
3035
|
+
WorldSessionOpenFailed: () => WorldSessionOpenFailed,
|
|
2729
3036
|
WorldSessionTimeout: () => WorldSessionTimeout,
|
|
2730
3037
|
attachSession: () => attachSession,
|
|
2731
3038
|
isTaskIdRef: () => isTaskIdRef,
|
|
@@ -2737,34 +3044,6 @@ __export(session_exports2, {
|
|
|
2737
3044
|
taskLabel: () => taskLabel
|
|
2738
3045
|
});
|
|
2739
3046
|
import { randomUUID } from "crypto";
|
|
2740
|
-
function numericGrade(record) {
|
|
2741
|
-
const rewards = {};
|
|
2742
|
-
const nested = record.rewards;
|
|
2743
|
-
if (nested && typeof nested === "object") {
|
|
2744
|
-
for (const [key2, value] of Object.entries(nested)) {
|
|
2745
|
-
if (typeof value === "number") rewards[key2] = value;
|
|
2746
|
-
}
|
|
2747
|
-
}
|
|
2748
|
-
for (const [key2, value] of Object.entries(record)) {
|
|
2749
|
-
if (key2 !== "reward" && typeof value === "number") rewards[key2] = value;
|
|
2750
|
-
}
|
|
2751
|
-
return {
|
|
2752
|
-
reward: typeof record.reward === "number" ? record.reward : null,
|
|
2753
|
-
rewards
|
|
2754
|
-
};
|
|
2755
|
-
}
|
|
2756
|
-
function verifierGrades(value) {
|
|
2757
|
-
if (!value || typeof value !== "object") return void 0;
|
|
2758
|
-
const out = {};
|
|
2759
|
-
for (const [name, grade] of Object.entries(value)) {
|
|
2760
|
-
const record = grade && typeof grade === "object" ? grade : {};
|
|
2761
|
-
out[name] = {
|
|
2762
|
-
...numericGrade(record),
|
|
2763
|
-
...typeof record.error === "string" ? { error: record.error } : {}
|
|
2764
|
-
};
|
|
2765
|
-
}
|
|
2766
|
-
return out;
|
|
2767
|
-
}
|
|
2768
3047
|
function schemaFromSignature(spec) {
|
|
2769
3048
|
if (spec.inputSchema)
|
|
2770
3049
|
return {
|
|
@@ -2872,6 +3151,7 @@ async function runSessions(opts) {
|
|
|
2872
3151
|
const taskRef = tasks[next++];
|
|
2873
3152
|
let task = taskLabel(taskRef);
|
|
2874
3153
|
let session = null;
|
|
3154
|
+
let keepWarm = opts.keepWarm ?? true;
|
|
2875
3155
|
try {
|
|
2876
3156
|
session = await openSession(opts.world, {
|
|
2877
3157
|
task: taskRef,
|
|
@@ -2879,6 +3159,7 @@ async function runSessions(opts) {
|
|
|
2879
3159
|
options
|
|
2880
3160
|
});
|
|
2881
3161
|
task = taskLabel(taskRef, session.taskInfo);
|
|
3162
|
+
WorldToolsUnread.refuse(opts.world.split("@", 1)[0], session.deprecations);
|
|
2882
3163
|
await session.ready();
|
|
2883
3164
|
const toolkit = await session.toolkit();
|
|
2884
3165
|
const live = session;
|
|
@@ -2901,19 +3182,19 @@ async function runSessions(opts) {
|
|
|
2901
3182
|
results.push(result);
|
|
2902
3183
|
opts.onResult?.(result);
|
|
2903
3184
|
} catch (error) {
|
|
3185
|
+
if (error instanceof WorldToolsUnread) keepWarm = false;
|
|
2904
3186
|
const result = {
|
|
2905
3187
|
task,
|
|
2906
3188
|
sessionId: session?.sessionId ?? "",
|
|
2907
3189
|
reward: 0,
|
|
2908
3190
|
rewards: {},
|
|
2909
|
-
// An
|
|
2910
|
-
// caller checking truthiness; name the type instead.
|
|
3191
|
+
// An empty message reads as "no error" to a truthiness check; name the type instead.
|
|
2911
3192
|
error: (error instanceof Error ? error.message : String(error)) || (error instanceof Error ? error.name : "Unknown error")
|
|
2912
3193
|
};
|
|
2913
3194
|
results.push(result);
|
|
2914
3195
|
opts.onResult?.(result);
|
|
2915
3196
|
} finally {
|
|
2916
|
-
await session?.close({ keepWarm
|
|
3197
|
+
await session?.close({ keepWarm }).catch(() => void 0);
|
|
2917
3198
|
}
|
|
2918
3199
|
}
|
|
2919
3200
|
})
|
|
@@ -2927,7 +3208,7 @@ async function runSessions(opts) {
|
|
|
2927
3208
|
passed: failed === 0 && (opts.failUnder === void 0 || mean >= opts.failUnder)
|
|
2928
3209
|
};
|
|
2929
3210
|
}
|
|
2930
|
-
var
|
|
3211
|
+
var CALL_TIMEOUT_MS, CALL_POLL_MS, JUDGED_GRADE_TIMEOUT_MS, JUDGED_GRADE_POLL_MS, EXPORT_PAGE, sleep4, modelToolName, WorldSession, OPEN_SESSION_OPTION_KEYS, isOpenSessionOptions;
|
|
2931
3212
|
var init_session2 = __esm({
|
|
2932
3213
|
"src/worlds/session.ts"() {
|
|
2933
3214
|
"use strict";
|
|
@@ -2935,22 +3216,20 @@ var init_session2 = __esm({
|
|
|
2935
3216
|
init_browser();
|
|
2936
3217
|
init_nativeComputer();
|
|
2937
3218
|
init_sessionContract();
|
|
3219
|
+
init_sessionReadiness();
|
|
2938
3220
|
init_session();
|
|
2939
3221
|
init_taskRef();
|
|
3222
|
+
init_worldNotice();
|
|
3223
|
+
init_grade();
|
|
2940
3224
|
init_taskRef();
|
|
2941
|
-
|
|
2942
|
-
READY_POLL_MS = 2e3;
|
|
3225
|
+
init_sessionReadiness();
|
|
2943
3226
|
CALL_TIMEOUT_MS = 3 * 6e4;
|
|
2944
3227
|
CALL_POLL_MS = 400;
|
|
2945
3228
|
JUDGED_GRADE_TIMEOUT_MS = 15 * 6e4;
|
|
2946
3229
|
JUDGED_GRADE_POLL_MS = 2e3;
|
|
2947
3230
|
EXPORT_PAGE = 500;
|
|
2948
|
-
|
|
3231
|
+
sleep4 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
2949
3232
|
modelToolName = (name) => name.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 64) || "tool";
|
|
2950
|
-
WorldSessionTimeout = class extends Error {
|
|
2951
|
-
};
|
|
2952
|
-
WorldSessionCallError = class extends Error {
|
|
2953
|
-
};
|
|
2954
3233
|
WorldSession = class {
|
|
2955
3234
|
constructor(sessionId, current, options) {
|
|
2956
3235
|
this.sessionId = sessionId;
|
|
@@ -3068,18 +3347,17 @@ var init_session2 = __esm({
|
|
|
3068
3347
|
}
|
|
3069
3348
|
/** The reporter `browser()` uses; exposed for a page you drive yourself. */
|
|
3070
3349
|
browserRecorder(agentId) {
|
|
3071
|
-
const
|
|
3350
|
+
const path17 = `/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/browser-events`;
|
|
3072
3351
|
const id = agentId ?? process.env.GATEWAY_AGENT_ID ?? `agent-${randomUUID().replace(/-/g, "").slice(0, 8)}`;
|
|
3073
3352
|
return new BrowserActionRecorder(
|
|
3074
3353
|
async (events) => {
|
|
3075
|
-
await apiRequest(this.options, "POST",
|
|
3354
|
+
await apiRequest(this.options, "POST", path17, { events });
|
|
3076
3355
|
},
|
|
3077
3356
|
id,
|
|
3078
3357
|
{
|
|
3079
|
-
// Continue this agent's timeline where the platform has it, so
|
|
3080
|
-
// same id reopened later never re-numbers from zero.
|
|
3358
|
+
// Continue this agent's timeline where the platform has it, so a reopened id never re-numbers from zero.
|
|
3081
3359
|
resumeFrom: async () => {
|
|
3082
|
-
const summary = await apiRequest(this.options, "GET",
|
|
3360
|
+
const summary = await apiRequest(this.options, "GET", path17);
|
|
3083
3361
|
return summary.agents.find((a) => a.agentId === id)?.nextSeq ?? 0;
|
|
3084
3362
|
}
|
|
3085
3363
|
}
|
|
@@ -3107,29 +3385,22 @@ var init_session2 = __esm({
|
|
|
3107
3385
|
tools: this.current.tools,
|
|
3108
3386
|
surfaces: this.current.surfaces,
|
|
3109
3387
|
task: this.current.task,
|
|
3388
|
+
deprecations: this.current.deprecations,
|
|
3110
3389
|
...fresh
|
|
3111
3390
|
};
|
|
3112
3391
|
return this.current;
|
|
3113
3392
|
}
|
|
3114
3393
|
/**
|
|
3115
|
-
* Wait until the
|
|
3116
|
-
* asked the platform for work
|
|
3394
|
+
* Wait until the session answers calls: a World Host holds it, or the
|
|
3395
|
+
* process inside a pod has asked the platform for work. Throws
|
|
3396
|
+
* `WorldSessionOpenFailed` (with the platform's reason) when it ended
|
|
3397
|
+
* first, and `WorldSessionTimeout` when `timeoutMs` (default ten minutes)
|
|
3398
|
+
* ran out while it was still starting.
|
|
3117
3399
|
*/
|
|
3118
3400
|
async ready(opts = {}) {
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
if (state2.ready) return state2;
|
|
3123
|
-
if (state2.state === "FAILED" || state2.state === "STOPPED")
|
|
3124
|
-
throw new WorldSessionCallError(
|
|
3125
|
-
`World session ${state2.state.toLowerCase()} before it was ready.`
|
|
3126
|
-
);
|
|
3127
|
-
if (Date.now() > deadline)
|
|
3128
|
-
throw new WorldSessionTimeout(
|
|
3129
|
-
`World session still ${state2.state} after ${Math.round((opts.timeoutMs ?? READY_TIMEOUT_MS) / 1e3)}s.`
|
|
3130
|
-
);
|
|
3131
|
-
await sleep2(READY_POLL_MS);
|
|
3132
|
-
}
|
|
3401
|
+
return new SessionReadiness(this.sessionId, () => this.status()).wait(
|
|
3402
|
+
opts.timeoutMs
|
|
3403
|
+
);
|
|
3133
3404
|
}
|
|
3134
3405
|
/** Enqueue one interaction and wait for the container's answer. */
|
|
3135
3406
|
async exchange(body, timeoutMs) {
|
|
@@ -3159,7 +3430,7 @@ var init_session2 = __esm({
|
|
|
3159
3430
|
throw new WorldSessionTimeout(
|
|
3160
3431
|
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.`
|
|
3161
3432
|
);
|
|
3162
|
-
await
|
|
3433
|
+
await sleep4(pollMs2);
|
|
3163
3434
|
}
|
|
3164
3435
|
}
|
|
3165
3436
|
/**
|
|
@@ -3208,7 +3479,9 @@ var init_session2 = __esm({
|
|
|
3208
3479
|
* calls); assertions and python graders ignore it. `worlds` names the
|
|
3209
3480
|
* task's other sessions by alias (`{alias: sessionId}`): the platform
|
|
3210
3481
|
* reads each one's evidence and hands it to the cross-world verifiers
|
|
3211
|
-
* anchored on this session, whose grades come back under `verifiers`.
|
|
3482
|
+
* anchored on this session, whose grades come back under `verifiers`. A
|
|
3483
|
+
* score that is not a number from 0 to 1 is refused by key and value
|
|
3484
|
+
* (`GradeRefused`); a verifier's is that verifier's `error`. */
|
|
3212
3485
|
async grade(opts = {}) {
|
|
3213
3486
|
const raw = await this.exchange(
|
|
3214
3487
|
{
|
|
@@ -3218,14 +3491,7 @@ var init_session2 = __esm({
|
|
|
3218
3491
|
},
|
|
3219
3492
|
opts.timeoutMs
|
|
3220
3493
|
);
|
|
3221
|
-
|
|
3222
|
-
const verifiers = verifierGrades(record.verifiers);
|
|
3223
|
-
return {
|
|
3224
|
-
...numericGrade(record),
|
|
3225
|
-
...typeof record.reason === "string" ? { reason: record.reason } : {},
|
|
3226
|
-
...verifiers ? { verifiers } : {},
|
|
3227
|
-
raw
|
|
3228
|
-
};
|
|
3494
|
+
return { ...GradePayload.read(raw), raw };
|
|
3229
3495
|
}
|
|
3230
3496
|
/**
|
|
3231
3497
|
* Put rows into the LIVE world through its contract, in one batch:
|
|
@@ -3489,26 +3755,28 @@ var init_surfaceDescriptor = __esm({
|
|
|
3489
3755
|
|
|
3490
3756
|
// src/worlds/taskSessions.ts
|
|
3491
3757
|
function aggregateTaskGrade(worlds) {
|
|
3492
|
-
const
|
|
3493
|
-
const ungraded = [];
|
|
3494
|
-
const graded = [];
|
|
3758
|
+
const fold = new TaskGradeFold();
|
|
3495
3759
|
const verifiers = {};
|
|
3496
|
-
const fold = (key2, grade) => {
|
|
3497
|
-
if (typeof grade.reward === "number") {
|
|
3498
|
-
rewards[key2] = grade.reward;
|
|
3499
|
-
graded.push(grade.reward);
|
|
3500
|
-
} else ungraded.push(key2);
|
|
3501
|
-
for (const [name, value] of Object.entries(grade.rewards))
|
|
3502
|
-
rewards[`${key2}.${name}`] = value;
|
|
3503
|
-
};
|
|
3504
3760
|
for (const [alias, grade] of Object.entries(worlds)) {
|
|
3505
|
-
fold(alias, grade);
|
|
3761
|
+
fold.add(alias, grade, `world ${alias}`);
|
|
3506
3762
|
Object.assign(verifiers, grade.verifiers ?? {});
|
|
3507
3763
|
}
|
|
3508
3764
|
for (const [name, grade] of Object.entries(verifiers))
|
|
3509
|
-
fold(`${VERIFIER_REWARD_PREFIX}${name}`, grade);
|
|
3510
|
-
|
|
3511
|
-
|
|
3765
|
+
fold.add(`${VERIFIER_REWARD_PREFIX}${name}`, grade, `verifier ${name}`);
|
|
3766
|
+
return {
|
|
3767
|
+
reward: fold.reward(),
|
|
3768
|
+
rewards: fold.rewards,
|
|
3769
|
+
worlds,
|
|
3770
|
+
ungraded: fold.ungraded,
|
|
3771
|
+
verifiers,
|
|
3772
|
+
errors: fold.errors
|
|
3773
|
+
};
|
|
3774
|
+
}
|
|
3775
|
+
function taskGradeError(grade) {
|
|
3776
|
+
const lines = Object.entries(grade.errors).map(
|
|
3777
|
+
([key2, why]) => `${key2}: ${why}`
|
|
3778
|
+
);
|
|
3779
|
+
return lines.length ? lines.join("; ") : null;
|
|
3512
3780
|
}
|
|
3513
3781
|
function fromResponse(answer, options) {
|
|
3514
3782
|
const sessions2 = {};
|
|
@@ -3631,12 +3899,13 @@ async function attachManifest(manifest, options = {}) {
|
|
|
3631
3899
|
function isTaskManifest(value) {
|
|
3632
3900
|
return typeof value === "object" && value !== null && !Array.isArray(value) && typeof value.sessions === "object" && value.sessions !== null && !("instruction" in value && "worlds" in value);
|
|
3633
3901
|
}
|
|
3634
|
-
var TASK_SESSIONS, VERIFIER_REWARD_PREFIX, manifestSession, TaskSessions;
|
|
3902
|
+
var TASK_SESSIONS, VERIFIER_REWARD_PREFIX, manifestSession, TaskGradeFold, TaskSessions;
|
|
3635
3903
|
var init_taskSessions = __esm({
|
|
3636
3904
|
"src/worlds/taskSessions.ts"() {
|
|
3637
3905
|
"use strict";
|
|
3638
3906
|
init_worlds();
|
|
3639
3907
|
init_browser();
|
|
3908
|
+
init_grade();
|
|
3640
3909
|
init_surfaceDescriptor();
|
|
3641
3910
|
init_session2();
|
|
3642
3911
|
TASK_SESSIONS = "/api/public/world-task-sessions";
|
|
@@ -3651,6 +3920,36 @@ var init_taskSessions = __esm({
|
|
|
3651
3920
|
state: state2.state,
|
|
3652
3921
|
...surfaceDescriptor(s)
|
|
3653
3922
|
});
|
|
3923
|
+
TaskGradeFold = class {
|
|
3924
|
+
rewards = {};
|
|
3925
|
+
ungraded = [];
|
|
3926
|
+
errors = {};
|
|
3927
|
+
sources = /* @__PURE__ */ new Map();
|
|
3928
|
+
graded = [];
|
|
3929
|
+
add(key2, grade, source) {
|
|
3930
|
+
if (grade.error) this.errors[key2] = grade.error;
|
|
3931
|
+
if (typeof grade.reward === "number") {
|
|
3932
|
+
this.put(key2, grade.reward, source);
|
|
3933
|
+
this.graded.push(grade.reward);
|
|
3934
|
+
} else this.ungraded.push(key2);
|
|
3935
|
+
for (const [name, value] of Object.entries(grade.rewards))
|
|
3936
|
+
this.put(`${key2}.${name}`, value, source);
|
|
3937
|
+
}
|
|
3938
|
+
reward() {
|
|
3939
|
+
if (Object.keys(this.errors).length > 0 || !this.graded.length)
|
|
3940
|
+
return null;
|
|
3941
|
+
return this.graded.reduce((a, b) => a + b, 0) / this.graded.length;
|
|
3942
|
+
}
|
|
3943
|
+
put(key2, value, source) {
|
|
3944
|
+
const first = this.sources.get(key2) ?? source;
|
|
3945
|
+
this.sources.set(key2, first);
|
|
3946
|
+
if (first !== source) {
|
|
3947
|
+
this.errors[key2] = `two rewards are named ${key2} (${first} and ${source}); rename one of them`;
|
|
3948
|
+
return;
|
|
3949
|
+
}
|
|
3950
|
+
this.rewards[key2] = value;
|
|
3951
|
+
}
|
|
3952
|
+
};
|
|
3654
3953
|
TaskSessions = class {
|
|
3655
3954
|
constructor(taskId, taskVersion, name, instruction, sessions2, worlds, hash = null) {
|
|
3656
3955
|
this.taskId = taskId;
|
|
@@ -3729,11 +4028,13 @@ var init_taskSessions = __esm({
|
|
|
3729
4028
|
* agent's own account of the whole investigation) goes to every world's
|
|
3730
4029
|
* judge; a world graded by assertions or python ignores it. Each grade
|
|
3731
4030
|
* names the task's other sessions by alias, so the cross-world verifiers
|
|
3732
|
-
* anchored on that world can read them.
|
|
4031
|
+
* anchored on that world can read them. A world whose grade call fails is
|
|
4032
|
+
* that world's error: the task's grade names it and keeps every other
|
|
4033
|
+
* world's grade. */
|
|
3733
4034
|
async grade(opts = {}) {
|
|
3734
4035
|
return aggregateTaskGrade(
|
|
3735
4036
|
await this.each(
|
|
3736
|
-
(session, alias) => session.grade({ ...opts, worlds: this.otherSessions(alias) })
|
|
4037
|
+
(session, alias) => session.grade({ ...opts, worlds: this.otherSessions(alias) }).catch((error) => GradePayload.failedCall(error))
|
|
3737
4038
|
)
|
|
3738
4039
|
);
|
|
3739
4040
|
}
|
|
@@ -3781,12 +4082,16 @@ var init_evals = __esm({
|
|
|
3781
4082
|
"src/worlds/evals.ts"() {
|
|
3782
4083
|
"use strict";
|
|
3783
4084
|
init_worlds();
|
|
4085
|
+
init_transport();
|
|
3784
4086
|
EVALUATIONS = "/api/public/benchmark-containers/evaluations";
|
|
3785
4087
|
GatewayEvalsClient = class {
|
|
3786
|
-
constructor(options = {}) {
|
|
4088
|
+
constructor(options = {}, retry = RetryPolicy.FILING) {
|
|
3787
4089
|
this.options = options;
|
|
4090
|
+
this.retry = retry;
|
|
3788
4091
|
}
|
|
3789
4092
|
options;
|
|
4093
|
+
retry;
|
|
4094
|
+
keyed = /* @__PURE__ */ new Set();
|
|
3790
4095
|
async createEvaluation(versionId, opts = {}) {
|
|
3791
4096
|
const body = { versionId };
|
|
3792
4097
|
if (opts.model !== void 0) body.model = opts.model;
|
|
@@ -3794,12 +4099,18 @@ var init_evals = __esm({
|
|
|
3794
4099
|
if (opts.rolloutsPerExample !== void 0)
|
|
3795
4100
|
body.rolloutsPerExample = opts.rolloutsPerExample;
|
|
3796
4101
|
if (opts.metadata !== void 0) body.metadata = opts.metadata;
|
|
4102
|
+
if (opts.idempotencyKey !== void 0)
|
|
4103
|
+
body.idempotencyKey = opts.idempotencyKey;
|
|
3797
4104
|
const answer = await apiRequest(
|
|
3798
4105
|
this.options,
|
|
3799
4106
|
"POST",
|
|
3800
4107
|
EVALUATIONS,
|
|
3801
|
-
body
|
|
4108
|
+
body,
|
|
4109
|
+
{
|
|
4110
|
+
retry: opts.idempotencyKey === void 0 ? RetryPolicy.NONE : this.retry
|
|
4111
|
+
}
|
|
3802
4112
|
);
|
|
4113
|
+
if (opts.idempotencyKey !== void 0) this.keyed.add(answer.evaluationId);
|
|
3803
4114
|
return answer.evaluationId;
|
|
3804
4115
|
}
|
|
3805
4116
|
async pushSamples(evaluationId, samples) {
|
|
@@ -3807,7 +4118,8 @@ var init_evals = __esm({
|
|
|
3807
4118
|
this.options,
|
|
3808
4119
|
"POST",
|
|
3809
4120
|
`${EVALUATIONS}/${encodeURIComponent(evaluationId)}/samples`,
|
|
3810
|
-
{ samples }
|
|
4121
|
+
{ samples },
|
|
4122
|
+
{ retry: this.retryFor(evaluationId) }
|
|
3811
4123
|
);
|
|
3812
4124
|
return answer.inserted ?? samples.length;
|
|
3813
4125
|
}
|
|
@@ -3820,10 +4132,300 @@ var init_evals = __esm({
|
|
|
3820
4132
|
this.options,
|
|
3821
4133
|
"POST",
|
|
3822
4134
|
`${EVALUATIONS}/${encodeURIComponent(evaluationId)}/finalize`,
|
|
3823
|
-
body
|
|
4135
|
+
body,
|
|
4136
|
+
{ retry: this.retryFor(evaluationId) }
|
|
3824
4137
|
);
|
|
3825
4138
|
return answer.status;
|
|
3826
4139
|
}
|
|
4140
|
+
retryFor(evaluationId) {
|
|
4141
|
+
return this.keyed.has(evaluationId) ? this.retry : RetryPolicy.NONE;
|
|
4142
|
+
}
|
|
4143
|
+
};
|
|
4144
|
+
}
|
|
4145
|
+
});
|
|
4146
|
+
|
|
4147
|
+
// src/worlds/runSignals.ts
|
|
4148
|
+
import { constants } from "os";
|
|
4149
|
+
var OWNER, RunSignals;
|
|
4150
|
+
var init_runSignals = __esm({
|
|
4151
|
+
"src/worlds/runSignals.ts"() {
|
|
4152
|
+
"use strict";
|
|
4153
|
+
OWNER = /* @__PURE__ */ Symbol("RunSignals");
|
|
4154
|
+
RunSignals = class _RunSignals {
|
|
4155
|
+
constructor(target = process) {
|
|
4156
|
+
this.target = target;
|
|
4157
|
+
}
|
|
4158
|
+
target;
|
|
4159
|
+
static SIGNALS = ["SIGINT", "SIGTERM"];
|
|
4160
|
+
cleanups = [];
|
|
4161
|
+
heardSignal = null;
|
|
4162
|
+
heardCount = 0;
|
|
4163
|
+
listening = false;
|
|
4164
|
+
left = false;
|
|
4165
|
+
listener = Object.assign(
|
|
4166
|
+
(signal) => this.heard(signal),
|
|
4167
|
+
{ [OWNER]: this }
|
|
4168
|
+
);
|
|
4169
|
+
/** The signal that arrived, once one has: start nothing new. */
|
|
4170
|
+
get signal() {
|
|
4171
|
+
return this.owner().heardSignal;
|
|
4172
|
+
}
|
|
4173
|
+
async during(cleanup, work) {
|
|
4174
|
+
return this.owner().hold(cleanup, work);
|
|
4175
|
+
}
|
|
4176
|
+
owner() {
|
|
4177
|
+
const owners = this.target.listeners("SIGINT").map((listener) => listener[OWNER]);
|
|
4178
|
+
return owners.find((owner) => owner !== void 0) ?? this;
|
|
4179
|
+
}
|
|
4180
|
+
async hold(cleanup, work) {
|
|
4181
|
+
this.listen();
|
|
4182
|
+
this.cleanups.push(cleanup);
|
|
4183
|
+
try {
|
|
4184
|
+
return await work();
|
|
4185
|
+
} finally {
|
|
4186
|
+
this.cleanups.splice(this.cleanups.indexOf(cleanup), 1);
|
|
4187
|
+
if (!this.cleanups.length && this.heardSignal === null) this.unlisten();
|
|
4188
|
+
}
|
|
4189
|
+
}
|
|
4190
|
+
heard(signal) {
|
|
4191
|
+
this.heardCount += 1;
|
|
4192
|
+
if (this.heardCount > 2) return this.leave(signal);
|
|
4193
|
+
this.heardSignal ??= signal;
|
|
4194
|
+
void this.cleanUp(signal, this.heardCount === 2).finally(() => this.leave(signal));
|
|
4195
|
+
}
|
|
4196
|
+
async cleanUp(signal, urgent) {
|
|
4197
|
+
for (const cleanup of [...this.cleanups].reverse())
|
|
4198
|
+
await Promise.resolve().then(() => cleanup(signal, urgent)).catch(() => void 0);
|
|
4199
|
+
}
|
|
4200
|
+
leave(signal) {
|
|
4201
|
+
if (this.left) return;
|
|
4202
|
+
this.left = true;
|
|
4203
|
+
this.unlisten();
|
|
4204
|
+
if (this.target.listenerCount(signal) === 0)
|
|
4205
|
+
this.target.exit(128 + constants.signals[signal]);
|
|
4206
|
+
}
|
|
4207
|
+
listen() {
|
|
4208
|
+
if (this.listening) return;
|
|
4209
|
+
this.listening = true;
|
|
4210
|
+
for (const signal of _RunSignals.SIGNALS)
|
|
4211
|
+
this.target.on(signal, this.listener);
|
|
4212
|
+
}
|
|
4213
|
+
unlisten() {
|
|
4214
|
+
this.listening = false;
|
|
4215
|
+
for (const signal of _RunSignals.SIGNALS)
|
|
4216
|
+
this.target.off(signal, this.listener);
|
|
4217
|
+
}
|
|
4218
|
+
};
|
|
4219
|
+
}
|
|
4220
|
+
});
|
|
4221
|
+
|
|
4222
|
+
// src/worlds/taskRunDir.ts
|
|
4223
|
+
import * as fs from "fs";
|
|
4224
|
+
import * as path from "path";
|
|
4225
|
+
function sessionRecord({ api: api2, ui, browser, ...session }) {
|
|
4226
|
+
return {
|
|
4227
|
+
...session,
|
|
4228
|
+
...api2 ? { api: { url: api2.url } } : {},
|
|
4229
|
+
...ui ? { ui: { ...ui, entry: withoutUiToken(ui.entry) } } : {},
|
|
4230
|
+
...browser ? { browser: browserRecord(browser) } : {}
|
|
4231
|
+
};
|
|
4232
|
+
}
|
|
4233
|
+
var TaskRunDir, browserRecord;
|
|
4234
|
+
var init_taskRunDir = __esm({
|
|
4235
|
+
"src/worlds/taskRunDir.ts"() {
|
|
4236
|
+
"use strict";
|
|
4237
|
+
init_browser();
|
|
4238
|
+
TaskRunDir = class {
|
|
4239
|
+
constructor(path17) {
|
|
4240
|
+
this.path = path17;
|
|
4241
|
+
}
|
|
4242
|
+
path;
|
|
4243
|
+
writeManifest(manifest) {
|
|
4244
|
+
this.writeJson("manifest.json", {
|
|
4245
|
+
...manifest,
|
|
4246
|
+
sessions: Object.fromEntries(
|
|
4247
|
+
Object.entries(manifest.sessions).map(([alias, session]) => [
|
|
4248
|
+
alias,
|
|
4249
|
+
sessionRecord(session)
|
|
4250
|
+
])
|
|
4251
|
+
)
|
|
4252
|
+
});
|
|
4253
|
+
}
|
|
4254
|
+
writeJson(name, value) {
|
|
4255
|
+
this.write(name, JSON.stringify(value, null, 2));
|
|
4256
|
+
}
|
|
4257
|
+
write(name, text2) {
|
|
4258
|
+
fs.mkdirSync(this.path, { recursive: true });
|
|
4259
|
+
fs.writeFileSync(path.join(this.path, name), text2);
|
|
4260
|
+
}
|
|
4261
|
+
};
|
|
4262
|
+
browserRecord = ({ viewport, tier }) => ({
|
|
4263
|
+
viewport,
|
|
4264
|
+
...tier ? { tier } : {}
|
|
4265
|
+
});
|
|
4266
|
+
}
|
|
4267
|
+
});
|
|
4268
|
+
|
|
4269
|
+
// src/worlds/taskRunOutcome.ts
|
|
4270
|
+
var TaskRunOutcome;
|
|
4271
|
+
var init_taskRunOutcome = __esm({
|
|
4272
|
+
"src/worlds/taskRunOutcome.ts"() {
|
|
4273
|
+
"use strict";
|
|
4274
|
+
init_grade();
|
|
4275
|
+
init_taskSessions();
|
|
4276
|
+
TaskRunOutcome = class {
|
|
4277
|
+
constructor(runId, live, model, runDir) {
|
|
4278
|
+
this.runId = runId;
|
|
4279
|
+
this.live = live;
|
|
4280
|
+
this.model = model;
|
|
4281
|
+
this.runDir = runDir;
|
|
4282
|
+
}
|
|
4283
|
+
runId;
|
|
4284
|
+
live;
|
|
4285
|
+
model;
|
|
4286
|
+
runDir;
|
|
4287
|
+
report = null;
|
|
4288
|
+
extra = {};
|
|
4289
|
+
notes = {};
|
|
4290
|
+
agentError = null;
|
|
4291
|
+
grade = null;
|
|
4292
|
+
traced = false;
|
|
4293
|
+
runError = null;
|
|
4294
|
+
fileError = null;
|
|
4295
|
+
evaluationId;
|
|
4296
|
+
evaluationStatus = null;
|
|
4297
|
+
started = Date.now();
|
|
4298
|
+
/** The run stopped short of a grade; the first reason stands. */
|
|
4299
|
+
stopped(error) {
|
|
4300
|
+
this.runError ??= messageOf(error).slice(0, 2e3);
|
|
4301
|
+
}
|
|
4302
|
+
agentRaised(error) {
|
|
4303
|
+
this.agentError = messageOf(error).slice(0, 2e3);
|
|
4304
|
+
}
|
|
4305
|
+
/** Every reason the run failed, on one line: the evaluation's
|
|
4306
|
+
* `metrics.error`. A run that never reached a grade has failed whatever
|
|
4307
|
+
* its reasons say. */
|
|
4308
|
+
failure() {
|
|
4309
|
+
const reasons = [
|
|
4310
|
+
this.agentError === null ? null : `agent raised: ${this.agentError}`,
|
|
4311
|
+
this.runError === null ? null : `the run stopped: ${this.runError}`,
|
|
4312
|
+
this.gradeError(),
|
|
4313
|
+
this.grade === null && this.runError === null ? "the run stopped before it was graded" : null
|
|
4314
|
+
].filter((reason) => reason !== null);
|
|
4315
|
+
return reasons.length ? reasons.join("; ") : null;
|
|
4316
|
+
}
|
|
4317
|
+
async file(evals, setRunId) {
|
|
4318
|
+
let created;
|
|
4319
|
+
try {
|
|
4320
|
+
created = await evals.createEvaluation(this.ref(this.live.aliases[0]).versionId, {
|
|
4321
|
+
model: this.model,
|
|
4322
|
+
rolloutsPerExample: 1,
|
|
4323
|
+
idempotencyKey: this.runId,
|
|
4324
|
+
...setRunId ? { runId: setRunId } : {},
|
|
4325
|
+
metadata: this.metadata()
|
|
4326
|
+
});
|
|
4327
|
+
await evals.pushSamples(created, [this.sample()]);
|
|
4328
|
+
this.evaluationStatus = await evals.finalizeEvaluation(created, this.finalized());
|
|
4329
|
+
this.evaluationId = created;
|
|
4330
|
+
} catch (error) {
|
|
4331
|
+
this.fileError = created ? `evaluation ${created}: ${messageOf(error)}` : messageOf(error);
|
|
4332
|
+
if (created)
|
|
4333
|
+
await evals.finalizeEvaluation(created, { status: "FAILED", metrics: { error: this.fileError } }).catch(() => void 0);
|
|
4334
|
+
}
|
|
4335
|
+
}
|
|
4336
|
+
summary() {
|
|
4337
|
+
const live = this.live;
|
|
4338
|
+
const { evaluationId: _agentEvaluationId, ...extra } = this.extra;
|
|
4339
|
+
return {
|
|
4340
|
+
...extra,
|
|
4341
|
+
runId: this.runId,
|
|
4342
|
+
taskId: live.taskId,
|
|
4343
|
+
taskVersion: live.taskVersion,
|
|
4344
|
+
name: live.name,
|
|
4345
|
+
instruction: live.instruction ?? "",
|
|
4346
|
+
model: this.model,
|
|
4347
|
+
aliases: live.aliases,
|
|
4348
|
+
reward: this.grade?.reward ?? null,
|
|
4349
|
+
rewards: this.grade?.rewards ?? {},
|
|
4350
|
+
ungraded: this.grade?.ungraded ?? live.aliases,
|
|
4351
|
+
agentError: this.agentError,
|
|
4352
|
+
runError: this.runError,
|
|
4353
|
+
gradeError: this.gradeError(),
|
|
4354
|
+
fileError: this.fileError,
|
|
4355
|
+
evaluationStatus: this.evaluationStatus,
|
|
4356
|
+
report: this.report,
|
|
4357
|
+
traced: this.traced,
|
|
4358
|
+
runDir: this.runDir,
|
|
4359
|
+
durationSeconds: Math.round((Date.now() - this.started) / 10) / 100,
|
|
4360
|
+
notes: this.notes,
|
|
4361
|
+
filed: this.evaluationId !== void 0,
|
|
4362
|
+
...this.evaluationId ? { evaluationId: this.evaluationId } : {}
|
|
4363
|
+
};
|
|
4364
|
+
}
|
|
4365
|
+
gradeError() {
|
|
4366
|
+
return this.grade ? taskGradeError(this.grade) : null;
|
|
4367
|
+
}
|
|
4368
|
+
ref(alias) {
|
|
4369
|
+
const { slug, ref } = this.live.worldRef(alias);
|
|
4370
|
+
const session = this.live.sessions[alias];
|
|
4371
|
+
return { slug, ref, versionId: session.versionId, sessionId: session.sessionId };
|
|
4372
|
+
}
|
|
4373
|
+
metadata() {
|
|
4374
|
+
const live = this.live;
|
|
4375
|
+
return {
|
|
4376
|
+
source: "worlds-task-run",
|
|
4377
|
+
task: { id: live.taskId, version: live.taskVersion, name: live.name, hash: live.hash },
|
|
4378
|
+
anchor: live.aliases[0],
|
|
4379
|
+
worlds: Object.fromEntries(live.aliases.map((alias) => [alias, this.ref(alias)])),
|
|
4380
|
+
runId: this.runId
|
|
4381
|
+
};
|
|
4382
|
+
}
|
|
4383
|
+
sample() {
|
|
4384
|
+
const live = this.live;
|
|
4385
|
+
const reward = this.grade?.reward ?? null;
|
|
4386
|
+
const gradeError = this.gradeError();
|
|
4387
|
+
const sample = {
|
|
4388
|
+
exampleId: live.name ?? live.taskId ?? this.runId,
|
|
4389
|
+
task: live.name ?? live.taskId ?? this.runId,
|
|
4390
|
+
rolloutIndex: 0,
|
|
4391
|
+
prompt: live.instruction,
|
|
4392
|
+
...this.report === null ? {} : { completion: this.report },
|
|
4393
|
+
rewards: this.grade?.rewards ?? {},
|
|
4394
|
+
info: {
|
|
4395
|
+
sessionId: this.runId,
|
|
4396
|
+
worlds: Object.fromEntries(
|
|
4397
|
+
live.aliases.map((alias) => [
|
|
4398
|
+
alias,
|
|
4399
|
+
{ ...this.ref(alias), reward: this.grade?.worlds[alias]?.reward ?? null }
|
|
4400
|
+
])
|
|
4401
|
+
),
|
|
4402
|
+
ungraded: this.grade?.ungraded ?? live.aliases,
|
|
4403
|
+
traced: this.traced,
|
|
4404
|
+
runDir: this.runDir,
|
|
4405
|
+
...this.agentError ? { agentError: this.agentError } : {},
|
|
4406
|
+
...this.runError ? { runError: this.runError } : {},
|
|
4407
|
+
...gradeError ? { verifyError: gradeError } : {}
|
|
4408
|
+
}
|
|
4409
|
+
};
|
|
4410
|
+
if (typeof reward === "number")
|
|
4411
|
+
Object.assign(sample, { reward, score: reward, correct: reward >= 1 });
|
|
4412
|
+
return sample;
|
|
4413
|
+
}
|
|
4414
|
+
finalized() {
|
|
4415
|
+
const reward = this.grade?.reward ?? null;
|
|
4416
|
+
const failure = this.failure();
|
|
4417
|
+
return {
|
|
4418
|
+
status: failure ? "FAILED" : "COMPLETED",
|
|
4419
|
+
metrics: {
|
|
4420
|
+
...typeof reward === "number" ? { avg_reward: reward } : {},
|
|
4421
|
+
reward,
|
|
4422
|
+
...Object.fromEntries(
|
|
4423
|
+
Object.entries(this.grade?.rewards ?? {}).map(([key2, value]) => [`rewards.${key2}`, value])
|
|
4424
|
+
),
|
|
4425
|
+
...failure ? { error: failure } : {}
|
|
4426
|
+
}
|
|
4427
|
+
};
|
|
4428
|
+
}
|
|
3827
4429
|
};
|
|
3828
4430
|
}
|
|
3829
4431
|
});
|
|
@@ -3836,7 +4438,7 @@ function getEnv(key2) {
|
|
|
3836
4438
|
function isGatewayConfigured() {
|
|
3837
4439
|
return !!(getEnv(GATEWAY_ENV.HOST) && getEnv(GATEWAY_ENV.PUBLIC_KEY) && getEnv(GATEWAY_ENV.SECRET_KEY));
|
|
3838
4440
|
}
|
|
3839
|
-
var GATEWAY_ENV, OPENTELEMETRY_PEERS, MODULE_NOT_FOUND, OpenTelemetryMissing;
|
|
4441
|
+
var GATEWAY_ENV, OTLP_TRACES_PATH, OPENTELEMETRY_PEERS, PINNED_PEERS, MODULE_NOT_FOUND, OpenTelemetryMissing;
|
|
3840
4442
|
var init_prerequisites = __esm({
|
|
3841
4443
|
"src/tracing/prerequisites.ts"() {
|
|
3842
4444
|
"use strict";
|
|
@@ -3844,21 +4446,25 @@ var init_prerequisites = __esm({
|
|
|
3844
4446
|
HOST: "GATEWAY_HOST",
|
|
3845
4447
|
PUBLIC_KEY: "GATEWAY_PUBLIC_KEY",
|
|
3846
4448
|
SECRET_KEY: "GATEWAY_SECRET_KEY",
|
|
4449
|
+
API_KEY: "GATEWAY_API_KEY",
|
|
3847
4450
|
ENDPOINT: "GATEWAY_OTLP_ENDPOINT"
|
|
3848
4451
|
};
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
"@opentelemetry/
|
|
3852
|
-
"@opentelemetry/
|
|
3853
|
-
"@opentelemetry/
|
|
3854
|
-
"@opentelemetry/sdk-trace-
|
|
3855
|
-
|
|
4452
|
+
OTLP_TRACES_PATH = "/api/public/otel/v1/traces";
|
|
4453
|
+
OPENTELEMETRY_PEERS = {
|
|
4454
|
+
"@opentelemetry/api": "1.9.0",
|
|
4455
|
+
"@opentelemetry/exporter-trace-otlp-http": "0.222.0",
|
|
4456
|
+
"@opentelemetry/resources": "2.11.0",
|
|
4457
|
+
"@opentelemetry/sdk-trace-base": "2.11.0",
|
|
4458
|
+
"@opentelemetry/sdk-trace-node": "2.11.0"
|
|
4459
|
+
};
|
|
4460
|
+
PINNED_PEERS = Object.entries(OPENTELEMETRY_PEERS).map(([name, version]) => `${name}@${version}`).join(" ");
|
|
3856
4461
|
MODULE_NOT_FOUND = /* @__PURE__ */ new Set(["MODULE_NOT_FOUND", "ERR_MODULE_NOT_FOUND"]);
|
|
3857
4462
|
OpenTelemetryMissing = class _OpenTelemetryMissing extends Error {
|
|
3858
4463
|
constructor() {
|
|
3859
4464
|
super(
|
|
3860
|
-
`OpenTelemetry packages not found. Install them with:
|
|
3861
|
-
npm install ${
|
|
4465
|
+
`OpenTelemetry packages not found. Install them next to @withgateway/sdk, at the versions it is tested with:
|
|
4466
|
+
npm install ${PINNED_PEERS}
|
|
4467
|
+
npm install -g ${PINNED_PEERS} (the gateway CLI, when it was installed with npm install -g)`
|
|
3862
4468
|
);
|
|
3863
4469
|
this.name = "OpenTelemetryMissing";
|
|
3864
4470
|
}
|
|
@@ -4171,7 +4777,7 @@ var require_package = __commonJS({
|
|
|
4171
4777
|
"package.json"(exports, module) {
|
|
4172
4778
|
module.exports = {
|
|
4173
4779
|
name: "@withgateway/sdk",
|
|
4174
|
-
version: "0.3.
|
|
4780
|
+
version: "0.3.3",
|
|
4175
4781
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
4176
4782
|
main: "./dist/index.js",
|
|
4177
4783
|
module: "./dist/index.mjs",
|
|
@@ -4679,7 +5285,7 @@ function buildProvider(config, logFn) {
|
|
|
4679
5285
|
const host = config.host ?? getEnv(GATEWAY_ENV.HOST);
|
|
4680
5286
|
const publicKey = config.publicKey ?? getEnv(GATEWAY_ENV.PUBLIC_KEY);
|
|
4681
5287
|
const secretKey = config.secretKey ?? getEnv(GATEWAY_ENV.SECRET_KEY);
|
|
4682
|
-
const endpoint = config.endpoint ?? getEnv(GATEWAY_ENV.ENDPOINT) ?? (host ? `${host.replace(/\/$/, "")}${
|
|
5288
|
+
const endpoint = config.endpoint ?? getEnv(GATEWAY_ENV.ENDPOINT) ?? (host ? `${host.replace(/\/$/, "")}${OTLP_TRACES_PATH}` : void 0);
|
|
4683
5289
|
const missing = [];
|
|
4684
5290
|
if (!host) missing.push("host (or GATEWAY_HOST env var)");
|
|
4685
5291
|
if (!publicKey) missing.push("publicKey (or GATEWAY_PUBLIC_KEY env var)");
|
|
@@ -4922,7 +5528,7 @@ async function shutdown2() {
|
|
|
4922
5528
|
function isInitialized() {
|
|
4923
5529
|
return state.initialized;
|
|
4924
5530
|
}
|
|
4925
|
-
var
|
|
5531
|
+
var state;
|
|
4926
5532
|
var init_init = __esm({
|
|
4927
5533
|
"src/tracing/init.ts"() {
|
|
4928
5534
|
"use strict";
|
|
@@ -4933,7 +5539,6 @@ var init_init = __esm({
|
|
|
4933
5539
|
init_build();
|
|
4934
5540
|
init_prerequisites();
|
|
4935
5541
|
init_prerequisites();
|
|
4936
|
-
DEFAULT_OTLP_PATH = "/api/public/otel/v1/traces";
|
|
4937
5542
|
state = {
|
|
4938
5543
|
initialized: false,
|
|
4939
5544
|
provider: null
|
|
@@ -4942,39 +5547,78 @@ var init_init = __esm({
|
|
|
4942
5547
|
});
|
|
4943
5548
|
|
|
4944
5549
|
// src/worlds/taskTracing.ts
|
|
4945
|
-
var TaskTracing;
|
|
5550
|
+
var HOST_WITH_AUTHORITY, TRACING_HELD_ELSEWHERE, TaskTracing;
|
|
4946
5551
|
var init_taskTracing = __esm({
|
|
4947
5552
|
"src/worlds/taskTracing.ts"() {
|
|
4948
5553
|
"use strict";
|
|
4949
5554
|
init_prerequisites();
|
|
5555
|
+
init_platformEndpoint();
|
|
5556
|
+
HOST_WITH_AUTHORITY = /^[a-z][a-z0-9+.-]*:\/\/[^/\\?#@\s]+(\/|$)/i;
|
|
5557
|
+
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.";
|
|
4950
5558
|
TaskTracing = class _TaskTracing {
|
|
4951
5559
|
constructor(load = () => Promise.resolve().then(() => (init_init(), init_exports))) {
|
|
4952
5560
|
this.load = load;
|
|
4953
5561
|
}
|
|
4954
5562
|
load;
|
|
4955
5563
|
static warned = false;
|
|
4956
|
-
|
|
4957
|
-
|
|
5564
|
+
static target = null;
|
|
5565
|
+
async start(requested, options) {
|
|
5566
|
+
if (!requested) return false;
|
|
5567
|
+
const endpoint = platformEndpoint(options);
|
|
4958
5568
|
try {
|
|
4959
|
-
|
|
5569
|
+
await this.initOnce(_TaskTracing.config(endpoint));
|
|
4960
5570
|
return true;
|
|
4961
5571
|
} catch (error) {
|
|
4962
|
-
_TaskTracing.warnOnce(error);
|
|
5572
|
+
_TaskTracing.warnOnce(_TaskTracing.reason(error, endpoint));
|
|
4963
5573
|
return false;
|
|
4964
5574
|
}
|
|
4965
5575
|
}
|
|
4966
|
-
|
|
5576
|
+
// init() keeps the first provider for the whole process and ignores later calls, so a later run is
|
|
5577
|
+
// traced only when it exports to the same place with the same keys.
|
|
5578
|
+
async initOnce(config) {
|
|
5579
|
+
const tracing2 = await this.load();
|
|
5580
|
+
const target = JSON.stringify([config.endpoint, config.publicKey, config.secretKey]);
|
|
5581
|
+
if (!tracing2.isInitialized()) {
|
|
5582
|
+
tracing2.init(config);
|
|
5583
|
+
_TaskTracing.target = target;
|
|
5584
|
+
return;
|
|
5585
|
+
}
|
|
5586
|
+
if (_TaskTracing.target !== target) throw new Error(TRACING_HELD_ELSEWHERE);
|
|
5587
|
+
}
|
|
5588
|
+
static config(endpoint) {
|
|
5589
|
+
if (!endpoint) throw new Error(GATEWAY_KEYS_MISSING);
|
|
5590
|
+
return { ...endpoint, endpoint: _TaskTracing.destination(endpoint) };
|
|
5591
|
+
}
|
|
5592
|
+
// B1: a saved login's keys go to their own host only. The redirect is compared as text, never parsed:
|
|
5593
|
+
// a fixed "<host>/" prefix leaves no URL parser room to read another host into it.
|
|
5594
|
+
static destination(endpoint) {
|
|
5595
|
+
const redirect = getEnv(GATEWAY_ENV.ENDPOINT);
|
|
5596
|
+
if (!redirect) return `${endpoint.host}${OTLP_TRACES_PATH}`;
|
|
5597
|
+
if (_TaskTracing.underHost(redirect, endpoint.host) || _TaskTracing.environmentKeys(endpoint)) return redirect;
|
|
5598
|
+
throw new Error(
|
|
5599
|
+
`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.`
|
|
5600
|
+
);
|
|
5601
|
+
}
|
|
5602
|
+
static underHost(redirect, host) {
|
|
5603
|
+
return HOST_WITH_AUTHORITY.test(host) && redirect.startsWith(`${host}/`);
|
|
5604
|
+
}
|
|
5605
|
+
static environmentKeys(endpoint) {
|
|
5606
|
+
const secretKey = getEnv(GATEWAY_ENV.SECRET_KEY) ?? getEnv(GATEWAY_ENV.API_KEY);
|
|
5607
|
+
return endpoint.publicKey === getEnv(GATEWAY_ENV.PUBLIC_KEY) && endpoint.secretKey === secretKey;
|
|
5608
|
+
}
|
|
5609
|
+
static warnOnce(reason) {
|
|
4967
5610
|
if (_TaskTracing.warned) return;
|
|
4968
5611
|
_TaskTracing.warned = true;
|
|
4969
5612
|
console.warn(
|
|
4970
|
-
`[gatewaysdk.tracing] Task runs in this process are not traced. ${
|
|
5613
|
+
`[gatewaysdk.tracing] Task runs in this process are not traced. ${reason}
|
|
4971
5614
|
Pass --no-trace (trace: false) to run untraced without this warning.`
|
|
4972
5615
|
);
|
|
4973
5616
|
}
|
|
4974
|
-
static reason(error) {
|
|
4975
|
-
if (OpenTelemetryMissing.explains(error))
|
|
4976
|
-
|
|
4977
|
-
|
|
5617
|
+
static reason(error, endpoint) {
|
|
5618
|
+
if (OpenTelemetryMissing.explains(error)) return new OpenTelemetryMissing().message;
|
|
5619
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
5620
|
+
const keys = endpoint ? [endpoint.publicKey, endpoint.secretKey] : [];
|
|
5621
|
+
return keys.reduce((text2, key2) => text2.split(key2).join("[redacted]"), message);
|
|
4978
5622
|
}
|
|
4979
5623
|
};
|
|
4980
5624
|
}
|
|
@@ -4982,87 +5626,17 @@ Pass --no-trace (trace: false) to run untraced without this warning.`
|
|
|
4982
5626
|
|
|
4983
5627
|
// src/worlds/taskRun.ts
|
|
4984
5628
|
import { randomBytes } from "crypto";
|
|
4985
|
-
import * as
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
}
|
|
4997
|
-
async function fileTaskRun(live, runId, model, report, grade, agentError, traced, runDir, options, setRunId) {
|
|
4998
|
-
const aliases = live.aliases;
|
|
4999
|
-
const anchor = aliases[0];
|
|
5000
|
-
const worldsMeta = Object.fromEntries(
|
|
5001
|
-
aliases.map((alias) => [alias, worldRef(live, alias)])
|
|
5002
|
-
);
|
|
5003
|
-
const evals = new GatewayEvalsClient(options);
|
|
5004
|
-
const evaluationId = await evals.createEvaluation(
|
|
5005
|
-
worldRef(live, anchor).versionId,
|
|
5006
|
-
{
|
|
5007
|
-
model,
|
|
5008
|
-
rolloutsPerExample: 1,
|
|
5009
|
-
...setRunId ? { runId: setRunId } : {},
|
|
5010
|
-
metadata: {
|
|
5011
|
-
source: "worlds-task-run",
|
|
5012
|
-
task: {
|
|
5013
|
-
id: live.taskId,
|
|
5014
|
-
version: live.taskVersion,
|
|
5015
|
-
name: live.name,
|
|
5016
|
-
hash: live.hash
|
|
5017
|
-
},
|
|
5018
|
-
anchor,
|
|
5019
|
-
worlds: worldsMeta,
|
|
5020
|
-
runId
|
|
5021
|
-
}
|
|
5022
|
-
}
|
|
5023
|
-
);
|
|
5024
|
-
const reward = grade.reward;
|
|
5025
|
-
const sample = {
|
|
5026
|
-
exampleId: live.name ?? live.taskId ?? runId,
|
|
5027
|
-
task: live.name ?? live.taskId ?? runId,
|
|
5028
|
-
rolloutIndex: 0,
|
|
5029
|
-
prompt: live.instruction,
|
|
5030
|
-
...report === null ? {} : { completion: report },
|
|
5031
|
-
rewards: grade.rewards,
|
|
5032
|
-
info: {
|
|
5033
|
-
sessionId: runId,
|
|
5034
|
-
worlds: Object.fromEntries(
|
|
5035
|
-
aliases.map((alias) => [
|
|
5036
|
-
alias,
|
|
5037
|
-
{
|
|
5038
|
-
...worldRef(live, alias),
|
|
5039
|
-
reward: grade.worlds[alias]?.reward ?? null
|
|
5040
|
-
}
|
|
5041
|
-
])
|
|
5042
|
-
),
|
|
5043
|
-
ungraded: grade.ungraded,
|
|
5044
|
-
traced,
|
|
5045
|
-
runDir,
|
|
5046
|
-
...agentError ? { agentError } : {}
|
|
5047
|
-
}
|
|
5048
|
-
};
|
|
5049
|
-
if (typeof reward === "number") {
|
|
5050
|
-
sample.reward = reward;
|
|
5051
|
-
sample.score = reward;
|
|
5052
|
-
sample.correct = reward >= 1;
|
|
5053
|
-
}
|
|
5054
|
-
await evals.pushSamples(evaluationId, [sample]);
|
|
5055
|
-
await evals.finalizeEvaluation(evaluationId, {
|
|
5056
|
-
status: agentError ? "FAILED" : "COMPLETED",
|
|
5057
|
-
metrics: {
|
|
5058
|
-
...typeof reward === "number" ? { avg_reward: reward } : {},
|
|
5059
|
-
reward,
|
|
5060
|
-
...Object.fromEntries(
|
|
5061
|
-
Object.entries(grade.rewards).map(([k, v]) => [`rewards.${k}`, v])
|
|
5062
|
-
)
|
|
5063
|
-
}
|
|
5064
|
-
});
|
|
5065
|
-
return evaluationId;
|
|
5629
|
+
import * as path2 from "path";
|
|
5630
|
+
function taskRunFailure(summary) {
|
|
5631
|
+
if (summary.agentError !== null) return `agent raised: ${summary.agentError}`;
|
|
5632
|
+
if (summary.runError !== null) return `the run stopped: ${summary.runError}`;
|
|
5633
|
+
if (summary.gradeError !== null)
|
|
5634
|
+
return `the task could not be graded: ${summary.gradeError}`;
|
|
5635
|
+
if (summary.fileError !== null)
|
|
5636
|
+
return `the run could not be filed: ${summary.fileError}`;
|
|
5637
|
+
if (summary.filed && summary.evaluationStatus !== "COMPLETED")
|
|
5638
|
+
return `the platform settled evaluation ${summary.evaluationId} as ${summary.evaluationStatus}`;
|
|
5639
|
+
return null;
|
|
5066
5640
|
}
|
|
5067
5641
|
function reportFromResult(result) {
|
|
5068
5642
|
if (result === void 0 || result === null)
|
|
@@ -5080,110 +5654,47 @@ function reportFromResult(result) {
|
|
|
5080
5654
|
);
|
|
5081
5655
|
return { report, extra };
|
|
5082
5656
|
}
|
|
5657
|
+
async function refuseUnreadTools(live) {
|
|
5658
|
+
try {
|
|
5659
|
+
for (const alias of live.aliases)
|
|
5660
|
+
WorldToolsUnread.refuse(`${live.worldRef(alias).slug} (alias ${alias})`, live.session(alias).deprecations);
|
|
5661
|
+
} catch (error) {
|
|
5662
|
+
await live.close({ keepWarm: false }).catch(() => void 0);
|
|
5663
|
+
throw error;
|
|
5664
|
+
}
|
|
5665
|
+
}
|
|
5083
5666
|
async function runTask(ref, agent, opts) {
|
|
5084
5667
|
const runId = `wtr-${randomBytes(6).toString("hex")}`;
|
|
5085
|
-
const outDir = opts.outDir ?? "runs";
|
|
5086
|
-
const runDir = path.join(outDir, runId);
|
|
5087
|
-
fs.mkdirSync(runDir, { recursive: true });
|
|
5088
5668
|
const options = opts.options ?? {};
|
|
5089
|
-
const
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
await live.manifest()
|
|
5105
|
-
);
|
|
5106
|
-
let agentError = null;
|
|
5107
|
-
let report = null;
|
|
5108
|
-
let extra = {};
|
|
5109
|
-
try {
|
|
5110
|
-
const invoke = () => agent(taskRun);
|
|
5111
|
-
const result = traced ? await (await Promise.resolve().then(() => (init_session(), session_exports))).withSession(runId, invoke) : await invoke();
|
|
5112
|
-
({ report, extra } = reportFromResult(result));
|
|
5113
|
-
} catch (error) {
|
|
5114
|
-
const message = (error instanceof Error ? error.message : String(error)) || "Unknown error";
|
|
5115
|
-
agentError = message.slice(0, 2e3);
|
|
5116
|
-
}
|
|
5117
|
-
if (traced)
|
|
5118
|
-
await Promise.resolve().then(() => (init_init(), init_exports)).then((tracing2) => tracing2.flush()).catch(() => void 0);
|
|
5119
|
-
const grade = report !== null ? await live.grade({ report }) : await live.grade();
|
|
5120
|
-
fs.writeFileSync(
|
|
5121
|
-
path.join(runDir, "manifest.json"),
|
|
5122
|
-
JSON.stringify(taskRun.manifest, null, 2)
|
|
5123
|
-
);
|
|
5124
|
-
fs.writeFileSync(
|
|
5125
|
-
path.join(runDir, "grades.json"),
|
|
5126
|
-
JSON.stringify(grade, null, 2)
|
|
5127
|
-
);
|
|
5128
|
-
if (report) fs.writeFileSync(path.join(runDir, "report.md"), report);
|
|
5129
|
-
const summary = {
|
|
5130
|
-
runId,
|
|
5131
|
-
taskId: live.taskId,
|
|
5132
|
-
taskVersion: live.taskVersion,
|
|
5133
|
-
name: live.name,
|
|
5134
|
-
instruction: taskRun.instruction,
|
|
5135
|
-
model: opts.model,
|
|
5136
|
-
aliases: live.aliases,
|
|
5137
|
-
reward: grade.reward,
|
|
5138
|
-
rewards: grade.rewards,
|
|
5139
|
-
ungraded: grade.ungraded,
|
|
5140
|
-
agentError,
|
|
5141
|
-
report,
|
|
5142
|
-
traced,
|
|
5143
|
-
runDir,
|
|
5144
|
-
durationSeconds: Math.round((Date.now() - started) / 10) / 100,
|
|
5145
|
-
notes: taskRun.notes,
|
|
5146
|
-
filed: false,
|
|
5147
|
-
...extra
|
|
5148
|
-
};
|
|
5149
|
-
if (opts.file !== false) {
|
|
5150
|
-
summary.evaluationId = await fileTaskRun(
|
|
5151
|
-
live,
|
|
5152
|
-
runId,
|
|
5153
|
-
opts.model,
|
|
5154
|
-
report,
|
|
5155
|
-
grade,
|
|
5156
|
-
agentError,
|
|
5157
|
-
traced,
|
|
5158
|
-
runDir,
|
|
5159
|
-
options,
|
|
5160
|
-
opts.setRunId
|
|
5161
|
-
);
|
|
5162
|
-
summary.filed = true;
|
|
5163
|
-
}
|
|
5164
|
-
fs.writeFileSync(
|
|
5165
|
-
path.join(runDir, "run.json"),
|
|
5166
|
-
JSON.stringify(summary, null, 2)
|
|
5167
|
-
);
|
|
5168
|
-
return summary;
|
|
5169
|
-
} finally {
|
|
5170
|
-
if (!opts.keepUp) {
|
|
5171
|
-
try {
|
|
5172
|
-
await live.close({ keepWarm: false });
|
|
5173
|
-
} catch {
|
|
5174
|
-
}
|
|
5175
|
-
}
|
|
5176
|
-
}
|
|
5669
|
+
const opening = new TaskOpening(
|
|
5670
|
+
openTask(ref, {
|
|
5671
|
+
surfaces: opts.surfaces,
|
|
5672
|
+
reuseWarm: opts.reuseWarm,
|
|
5673
|
+
browserTier: opts.browserTier,
|
|
5674
|
+
options
|
|
5675
|
+
}).then(async (live) => {
|
|
5676
|
+
await refuseUnreadTools(live);
|
|
5677
|
+
return new LiveTaskRun(runId, live, opts, options);
|
|
5678
|
+
})
|
|
5679
|
+
);
|
|
5680
|
+
return new RunSignals().during(
|
|
5681
|
+
(signal, urgent) => opening.interrupt(signal, urgent),
|
|
5682
|
+
() => opening.complete(agent)
|
|
5683
|
+
);
|
|
5177
5684
|
}
|
|
5178
|
-
var TaskRun, describeValue, RESULT_CONTRACT;
|
|
5685
|
+
var TaskRun, FILING_UNFINISHED, describeValue, RESULT_CONTRACT, LiveTaskRun, TaskOpening;
|
|
5179
5686
|
var init_taskRun = __esm({
|
|
5180
5687
|
"src/worlds/taskRun.ts"() {
|
|
5181
5688
|
"use strict";
|
|
5182
5689
|
init_browser();
|
|
5183
5690
|
init_evals();
|
|
5691
|
+
init_runSignals();
|
|
5184
5692
|
init_session2();
|
|
5185
5693
|
init_taskSessions();
|
|
5694
|
+
init_taskRunDir();
|
|
5695
|
+
init_taskRunOutcome();
|
|
5186
5696
|
init_taskTracing();
|
|
5697
|
+
init_worldNotice();
|
|
5187
5698
|
TaskRun = class {
|
|
5188
5699
|
constructor(runId, instruction, model, sessions2, manifest) {
|
|
5189
5700
|
this.runId = runId;
|
|
@@ -5246,8 +5757,127 @@ var init_taskRun = __esm({
|
|
|
5246
5757
|
Object.assign(this.notes, notes);
|
|
5247
5758
|
}
|
|
5248
5759
|
};
|
|
5760
|
+
FILING_UNFINISHED = "the filing did not finish";
|
|
5249
5761
|
describeValue = (value) => Array.isArray(value) ? "array" : value === null ? "null" : typeof value;
|
|
5250
5762
|
RESULT_CONTRACT = "return a string report, an object {report?: string, ...} or nothing";
|
|
5763
|
+
LiveTaskRun = class {
|
|
5764
|
+
constructor(runId, live, opts, options) {
|
|
5765
|
+
this.live = live;
|
|
5766
|
+
this.opts = opts;
|
|
5767
|
+
this.options = options;
|
|
5768
|
+
this.files = new TaskRunDir(path2.join(opts.outDir ?? "runs", runId));
|
|
5769
|
+
this.outcome = new TaskRunOutcome(runId, live, opts.model, this.files.path);
|
|
5770
|
+
}
|
|
5771
|
+
live;
|
|
5772
|
+
opts;
|
|
5773
|
+
options;
|
|
5774
|
+
files;
|
|
5775
|
+
outcome;
|
|
5776
|
+
played = false;
|
|
5777
|
+
interrupted = false;
|
|
5778
|
+
filing = null;
|
|
5779
|
+
ending = null;
|
|
5780
|
+
async complete(agent) {
|
|
5781
|
+
try {
|
|
5782
|
+
await this.play(agent).catch((error) => this.outcome.stopped(error));
|
|
5783
|
+
this.played = true;
|
|
5784
|
+
await this.file();
|
|
5785
|
+
return this.record();
|
|
5786
|
+
} finally {
|
|
5787
|
+
await this.end();
|
|
5788
|
+
}
|
|
5789
|
+
}
|
|
5790
|
+
async interrupt(signal, urgent = false) {
|
|
5791
|
+
const sessions2 = this.opts.keepUp ? "leaving its sessions up" : "closing its sessions";
|
|
5792
|
+
const how = urgent ? " now, without waiting" : "";
|
|
5793
|
+
process.stderr.write(`${this.outcome.runId} interrupted by ${signal}; ${sessions2}${how}
|
|
5794
|
+
`);
|
|
5795
|
+
if (!this.played) this.outcome.stopped(`interrupted by ${signal}`);
|
|
5796
|
+
this.interrupted = true;
|
|
5797
|
+
try {
|
|
5798
|
+
if (!urgent) await this.filing;
|
|
5799
|
+
this.record();
|
|
5800
|
+
} catch (error) {
|
|
5801
|
+
const why = error instanceof Error ? error.message : String(error);
|
|
5802
|
+
process.stderr.write(`${this.outcome.runId}: run.json not written: ${why}
|
|
5803
|
+
`);
|
|
5804
|
+
} finally {
|
|
5805
|
+
await this.end();
|
|
5806
|
+
}
|
|
5807
|
+
}
|
|
5808
|
+
summary() {
|
|
5809
|
+
return this.outcome.summary();
|
|
5810
|
+
}
|
|
5811
|
+
async play(agent) {
|
|
5812
|
+
await this.live.ready();
|
|
5813
|
+
this.outcome.traced = await new TaskTracing().start(this.opts.trace !== false, this.options);
|
|
5814
|
+
const run = new TaskRun(
|
|
5815
|
+
this.outcome.runId,
|
|
5816
|
+
this.live.instruction ?? "",
|
|
5817
|
+
this.opts.model,
|
|
5818
|
+
this.live.sessions,
|
|
5819
|
+
await this.live.manifest()
|
|
5820
|
+
);
|
|
5821
|
+
this.outcome.notes = run.notes;
|
|
5822
|
+
this.files.writeManifest(run.manifest);
|
|
5823
|
+
await this.callAgent(agent, run);
|
|
5824
|
+
const report = this.outcome.report;
|
|
5825
|
+
this.outcome.grade = await this.live.grade(report !== null ? { report } : {});
|
|
5826
|
+
this.files.writeJson("grades.json", this.outcome.grade);
|
|
5827
|
+
if (report) this.files.write("report.md", report);
|
|
5828
|
+
}
|
|
5829
|
+
async callAgent(agent, run) {
|
|
5830
|
+
try {
|
|
5831
|
+
const invoke = () => agent(run);
|
|
5832
|
+
const result = this.outcome.traced ? await (await Promise.resolve().then(() => (init_session(), session_exports))).withSession(run.runId, invoke) : await invoke();
|
|
5833
|
+
({ report: this.outcome.report, extra: this.outcome.extra } = reportFromResult(result));
|
|
5834
|
+
} catch (error) {
|
|
5835
|
+
this.outcome.agentRaised(error);
|
|
5836
|
+
}
|
|
5837
|
+
if (this.outcome.traced)
|
|
5838
|
+
await Promise.resolve().then(() => (init_init(), init_exports)).then((tracing2) => tracing2.flush()).catch(() => void 0);
|
|
5839
|
+
}
|
|
5840
|
+
async file() {
|
|
5841
|
+
if (this.opts.file === false || this.interrupted) return;
|
|
5842
|
+
this.files.writeJson("run.json", { ...this.outcome.summary(), fileError: FILING_UNFINISHED });
|
|
5843
|
+
this.filing = this.outcome.file(new GatewayEvalsClient(this.options), this.opts.setRunId);
|
|
5844
|
+
await this.filing;
|
|
5845
|
+
}
|
|
5846
|
+
record() {
|
|
5847
|
+
const summary = this.outcome.summary();
|
|
5848
|
+
this.files.writeJson("run.json", summary);
|
|
5849
|
+
return summary;
|
|
5850
|
+
}
|
|
5851
|
+
end() {
|
|
5852
|
+
this.ending ??= this.opts.keepUp ? Promise.resolve() : this.live.close({ keepWarm: false }).then(
|
|
5853
|
+
() => void 0,
|
|
5854
|
+
() => void 0
|
|
5855
|
+
);
|
|
5856
|
+
return this.ending;
|
|
5857
|
+
}
|
|
5858
|
+
};
|
|
5859
|
+
TaskOpening = class {
|
|
5860
|
+
interrupting = null;
|
|
5861
|
+
run = null;
|
|
5862
|
+
opened;
|
|
5863
|
+
constructor(opening) {
|
|
5864
|
+
this.opened = opening.then((run) => this.run = run);
|
|
5865
|
+
}
|
|
5866
|
+
async complete(agent) {
|
|
5867
|
+
const run = await this.opened;
|
|
5868
|
+
if (!this.interrupting) return run.complete(agent);
|
|
5869
|
+
await this.interrupting;
|
|
5870
|
+
return run.summary();
|
|
5871
|
+
}
|
|
5872
|
+
interrupt(signal, urgent = false) {
|
|
5873
|
+
if (urgent) return this.run?.interrupt(signal, true) ?? Promise.resolve();
|
|
5874
|
+
this.interrupting ??= this.opened.then(
|
|
5875
|
+
(run) => run.interrupt(signal),
|
|
5876
|
+
() => void 0
|
|
5877
|
+
);
|
|
5878
|
+
return this.interrupting;
|
|
5879
|
+
}
|
|
5880
|
+
};
|
|
5251
5881
|
}
|
|
5252
5882
|
});
|
|
5253
5883
|
|
|
@@ -5327,63 +5957,101 @@ async function runSet(datasetId, agent, opts) {
|
|
|
5327
5957
|
source: opts.source ?? "sdk",
|
|
5328
5958
|
...git && Object.keys(git).length ? { git } : {}
|
|
5329
5959
|
});
|
|
5330
|
-
|
|
5331
|
-
options,
|
|
5332
|
-
"POST",
|
|
5333
|
-
`${SET_RUNS}/${encodeURIComponent(opened.id)}/close`,
|
|
5334
|
-
{ status }
|
|
5335
|
-
);
|
|
5336
|
-
const onInterrupt = () => {
|
|
5337
|
-
void close("failed").finally(() => process.exit(130));
|
|
5338
|
-
};
|
|
5339
|
-
process.once("SIGINT", onInterrupt);
|
|
5340
|
-
const planned = await runPlannedTasks(opened, agent, opts, options).finally(
|
|
5341
|
-
() => process.off("SIGINT", onInterrupt)
|
|
5342
|
-
);
|
|
5343
|
-
const { tasks, failed } = planned;
|
|
5344
|
-
const requested = failed ? "failed" : "completed";
|
|
5345
|
-
const setRun = await close(requested);
|
|
5346
|
-
return {
|
|
5347
|
-
setRun,
|
|
5348
|
-
tasks,
|
|
5349
|
-
failed: failed || setRun.status !== "completed",
|
|
5350
|
-
closedAsRequested: setRun.status === requested
|
|
5351
|
-
};
|
|
5960
|
+
return new SetRunner(opened, agent, opts, options).run();
|
|
5352
5961
|
}
|
|
5353
|
-
|
|
5354
|
-
const tasks = [];
|
|
5355
|
-
let failed = false;
|
|
5356
|
-
for (const task of opened.tasks) {
|
|
5357
|
-
try {
|
|
5358
|
-
const summary = await runTask(task.worldTaskId, agent, {
|
|
5359
|
-
model: opts.model,
|
|
5360
|
-
surfaces: opts.surfaces,
|
|
5361
|
-
browserTier: opts.browserTier,
|
|
5362
|
-
outDir: opts.outDir,
|
|
5363
|
-
trace: opts.trace,
|
|
5364
|
-
setRunId: opened.id,
|
|
5365
|
-
options
|
|
5366
|
-
});
|
|
5367
|
-
tasks.push(summary);
|
|
5368
|
-
failed ||= summary.agentError !== null;
|
|
5369
|
-
opts.onTask?.(summary);
|
|
5370
|
-
} catch (error) {
|
|
5371
|
-
failed = true;
|
|
5372
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
5373
|
-
process.stderr.write(`task ${task.name} could not run: ${message}
|
|
5374
|
-
`);
|
|
5375
|
-
}
|
|
5376
|
-
}
|
|
5377
|
-
return { tasks, failed };
|
|
5378
|
-
}
|
|
5379
|
-
var SET_RUNS;
|
|
5962
|
+
var SET_RUNS, SetRunner;
|
|
5380
5963
|
var init_setRun = __esm({
|
|
5381
5964
|
"src/worlds/setRun.ts"() {
|
|
5382
5965
|
"use strict";
|
|
5383
5966
|
init_worlds();
|
|
5384
5967
|
init_checkoutProvenance();
|
|
5968
|
+
init_runSignals();
|
|
5385
5969
|
init_taskRun();
|
|
5386
5970
|
SET_RUNS = "/api/public/set-runs";
|
|
5971
|
+
SetRunner = class {
|
|
5972
|
+
constructor(opened, agent, opts, options) {
|
|
5973
|
+
this.opened = opened;
|
|
5974
|
+
this.agent = agent;
|
|
5975
|
+
this.opts = opts;
|
|
5976
|
+
this.options = options;
|
|
5977
|
+
}
|
|
5978
|
+
opened;
|
|
5979
|
+
agent;
|
|
5980
|
+
opts;
|
|
5981
|
+
options;
|
|
5982
|
+
tasks = [];
|
|
5983
|
+
failures = [];
|
|
5984
|
+
failed = false;
|
|
5985
|
+
current = null;
|
|
5986
|
+
interrupted = null;
|
|
5987
|
+
signals = new RunSignals();
|
|
5988
|
+
async run() {
|
|
5989
|
+
await this.signals.during(
|
|
5990
|
+
(signal2) => this.interrupt(signal2).then(() => void 0),
|
|
5991
|
+
() => this.runTasks()
|
|
5992
|
+
);
|
|
5993
|
+
const signal = this.signals.signal;
|
|
5994
|
+
if (signal !== null) return this.result(await this.interrupt(signal), "failed");
|
|
5995
|
+
const requested = this.failed ? "failed" : "completed";
|
|
5996
|
+
return this.result(await this.close(requested, this.failures), requested);
|
|
5997
|
+
}
|
|
5998
|
+
interrupt(signal) {
|
|
5999
|
+
const stopped = this.current ? [{ worldTaskId: this.current, reason: `interrupted by ${signal}` }] : [];
|
|
6000
|
+
this.interrupted ??= this.close("failed", [...this.failures, ...stopped]);
|
|
6001
|
+
return this.interrupted;
|
|
6002
|
+
}
|
|
6003
|
+
async runTasks() {
|
|
6004
|
+
for (const task of this.opened.tasks) {
|
|
6005
|
+
if (this.signals.signal !== null) return;
|
|
6006
|
+
this.current = task.worldTaskId;
|
|
6007
|
+
await this.runOne(task);
|
|
6008
|
+
}
|
|
6009
|
+
this.current = null;
|
|
6010
|
+
}
|
|
6011
|
+
async runOne(task) {
|
|
6012
|
+
try {
|
|
6013
|
+
const summary = await runTask(task.worldTaskId, this.agent, {
|
|
6014
|
+
model: this.opts.model,
|
|
6015
|
+
surfaces: this.opts.surfaces,
|
|
6016
|
+
browserTier: this.opts.browserTier,
|
|
6017
|
+
outDir: this.opts.outDir,
|
|
6018
|
+
trace: this.opts.trace,
|
|
6019
|
+
setRunId: this.opened.id,
|
|
6020
|
+
options: this.options
|
|
6021
|
+
});
|
|
6022
|
+
this.tasks.push(summary);
|
|
6023
|
+
this.failed ||= taskRunFailure(summary) !== null;
|
|
6024
|
+
if (summary.fileError !== null)
|
|
6025
|
+
this.failures.push({ worldTaskId: task.worldTaskId, reason: summary.fileError });
|
|
6026
|
+
this.opts.onTask?.(summary);
|
|
6027
|
+
} catch (error) {
|
|
6028
|
+
this.failed = true;
|
|
6029
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
6030
|
+
process.stderr.write(`task ${task.name} could not run: ${message}
|
|
6031
|
+
`);
|
|
6032
|
+
this.failures.push({
|
|
6033
|
+
worldTaskId: task.worldTaskId,
|
|
6034
|
+
reason: message || (error instanceof Error ? error.name : "Error")
|
|
6035
|
+
});
|
|
6036
|
+
}
|
|
6037
|
+
}
|
|
6038
|
+
close(status, failures = []) {
|
|
6039
|
+
return apiRequest(
|
|
6040
|
+
this.options,
|
|
6041
|
+
"POST",
|
|
6042
|
+
`${SET_RUNS}/${encodeURIComponent(this.opened.id)}/close`,
|
|
6043
|
+
{ status, ...failures.length ? { failures } : {} }
|
|
6044
|
+
);
|
|
6045
|
+
}
|
|
6046
|
+
result(setRun, requested) {
|
|
6047
|
+
return {
|
|
6048
|
+
setRun,
|
|
6049
|
+
tasks: this.tasks,
|
|
6050
|
+
failed: this.failed || setRun.status !== "completed",
|
|
6051
|
+
closedAsRequested: setRun.status === requested
|
|
6052
|
+
};
|
|
6053
|
+
}
|
|
6054
|
+
};
|
|
5387
6055
|
}
|
|
5388
6056
|
});
|
|
5389
6057
|
|
|
@@ -5435,7 +6103,7 @@ var init_requestLog = __esm({
|
|
|
5435
6103
|
|
|
5436
6104
|
// src/worlds/checkoutTarget.ts
|
|
5437
6105
|
import * as fs2 from "fs";
|
|
5438
|
-
import * as
|
|
6106
|
+
import * as path3 from "path";
|
|
5439
6107
|
var CheckoutRefusedError, NAMED_EDITS, CheckoutTarget;
|
|
5440
6108
|
var init_checkoutTarget = __esm({
|
|
5441
6109
|
"src/worlds/checkoutTarget.ts"() {
|
|
@@ -5464,17 +6132,17 @@ var init_checkoutTarget = __esm({
|
|
|
5464
6132
|
}
|
|
5465
6133
|
/** The absolute destination; a relative target may not resolve above `cwd`. */
|
|
5466
6134
|
static confined(target, cwd) {
|
|
5467
|
-
const dir =
|
|
5468
|
-
if (
|
|
5469
|
-
const rel =
|
|
5470
|
-
if (rel === "" || !rel.startsWith("..") && !
|
|
6135
|
+
const dir = path3.resolve(cwd, target);
|
|
6136
|
+
if (path3.isAbsolute(target)) return dir;
|
|
6137
|
+
const rel = path3.relative(cwd, dir);
|
|
6138
|
+
if (rel === "" || !rel.startsWith("..") && !path3.isAbsolute(rel))
|
|
5471
6139
|
return dir;
|
|
5472
6140
|
throw new CheckoutRefusedError(
|
|
5473
6141
|
`--target ${target} resolves outside the current directory (${cwd}) \u2014 run from that directory, or pass an absolute path`
|
|
5474
6142
|
);
|
|
5475
6143
|
}
|
|
5476
6144
|
static fresh(slug, cwd) {
|
|
5477
|
-
const base =
|
|
6145
|
+
const base = path3.join(cwd, slug);
|
|
5478
6146
|
let dir = base;
|
|
5479
6147
|
let i = 1;
|
|
5480
6148
|
while (fs2.existsSync(dir)) dir = `${base}-${i++}`;
|
|
@@ -5501,7 +6169,7 @@ var init_checkoutTarget = __esm({
|
|
|
5501
6169
|
].filter(_CheckoutTarget.confinedRel).sort();
|
|
5502
6170
|
}
|
|
5503
6171
|
static confinedRel(rel) {
|
|
5504
|
-
if (rel === "" ||
|
|
6172
|
+
if (rel === "" || path3.isAbsolute(rel)) return false;
|
|
5505
6173
|
return !rel.split(/[\\/]/).includes("..");
|
|
5506
6174
|
}
|
|
5507
6175
|
/** Why `dir` cannot be overwritten, or null when it is a clean checkout of `slug`. */
|
|
@@ -5519,9 +6187,9 @@ var init_checkoutTarget = __esm({
|
|
|
5519
6187
|
/** Remove the replaced checkout's files (and the dirs they leave empty). */
|
|
5520
6188
|
clear() {
|
|
5521
6189
|
for (const rel of this.replaces) {
|
|
5522
|
-
const abs =
|
|
6190
|
+
const abs = path3.join(this.dir, rel);
|
|
5523
6191
|
fs2.rmSync(abs, { force: true });
|
|
5524
|
-
this.pruneEmptyParents(
|
|
6192
|
+
this.pruneEmptyParents(path3.dirname(abs));
|
|
5525
6193
|
}
|
|
5526
6194
|
}
|
|
5527
6195
|
pruneEmptyParents(from) {
|
|
@@ -5529,7 +6197,7 @@ var init_checkoutTarget = __esm({
|
|
|
5529
6197
|
while (cur !== this.dir && cur.startsWith(this.dir)) {
|
|
5530
6198
|
if (fs2.existsSync(cur) && fs2.readdirSync(cur).length > 0) return;
|
|
5531
6199
|
fs2.rmSync(cur, { recursive: true, force: true });
|
|
5532
|
-
cur =
|
|
6200
|
+
cur = path3.dirname(cur);
|
|
5533
6201
|
}
|
|
5534
6202
|
}
|
|
5535
6203
|
};
|
|
@@ -5539,7 +6207,7 @@ var init_checkoutTarget = __esm({
|
|
|
5539
6207
|
// src/worlds/worldDir.ts
|
|
5540
6208
|
import { createHash as createHash4 } from "crypto";
|
|
5541
6209
|
import * as fs3 from "fs";
|
|
5542
|
-
import * as
|
|
6210
|
+
import * as path4 from "path";
|
|
5543
6211
|
var 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;
|
|
5544
6212
|
var init_worldDir = __esm({
|
|
5545
6213
|
"src/worlds/worldDir.ts"() {
|
|
@@ -5569,17 +6237,17 @@ var init_worldDir = __esm({
|
|
|
5569
6237
|
worldRoot;
|
|
5570
6238
|
pathsMemo;
|
|
5571
6239
|
static open(dir) {
|
|
5572
|
-
const present = (rel) => fs3.existsSync(
|
|
6240
|
+
const present = (rel) => fs3.existsSync(path4.join(dir, rel));
|
|
5573
6241
|
const bundled = present(API_BUNDLE_MANIFEST) && WORLD_ROOT_MARKERS.some((m) => present(BUNDLED_WORLD_PREFIX + m));
|
|
5574
6242
|
return new _WorldDir(dir, bundled ? BUNDLED_WORLD_PREFIX : "");
|
|
5575
6243
|
}
|
|
5576
6244
|
// ── Files ──────────────────────────────────────────────────────────────
|
|
5577
6245
|
has(rel) {
|
|
5578
|
-
return fs3.existsSync(
|
|
6246
|
+
return fs3.existsSync(path4.join(this.dir, rel));
|
|
5579
6247
|
}
|
|
5580
6248
|
text(rel) {
|
|
5581
6249
|
try {
|
|
5582
|
-
return fs3.readFileSync(
|
|
6250
|
+
return fs3.readFileSync(path4.join(this.dir, rel), "utf-8");
|
|
5583
6251
|
} catch {
|
|
5584
6252
|
return null;
|
|
5585
6253
|
}
|
|
@@ -5598,7 +6266,7 @@ var init_worldDir = __esm({
|
|
|
5598
6266
|
const broad = BROAD_ROOT_MARKERS.some((m) => this.has(m));
|
|
5599
6267
|
const out = [];
|
|
5600
6268
|
const walk = (rel) => {
|
|
5601
|
-
for (const entry of fs3.readdirSync(rel ?
|
|
6269
|
+
for (const entry of fs3.readdirSync(rel ? path4.join(this.dir, rel) : this.dir, { withFileTypes: true })) {
|
|
5602
6270
|
const child = rel ? `${rel}/${entry.name}` : entry.name;
|
|
5603
6271
|
if (entry.isDirectory()) {
|
|
5604
6272
|
if (!skippedDir(entry.name)) walk(child);
|
|
@@ -5619,7 +6287,7 @@ var init_worldDir = __esm({
|
|
|
5619
6287
|
get exclusions() {
|
|
5620
6288
|
const kept = new Set(this.archivePaths);
|
|
5621
6289
|
const out = [];
|
|
5622
|
-
const filesUnder = (rel) => fs3.readdirSync(
|
|
6290
|
+
const filesUnder = (rel) => fs3.readdirSync(path4.join(this.dir, rel), { withFileTypes: true }).flatMap((entry) => {
|
|
5623
6291
|
const child = `${rel}/${entry.name}`;
|
|
5624
6292
|
if (entry.isDirectory()) return filesUnder(child);
|
|
5625
6293
|
return entry.isFile() ? [child] : [];
|
|
@@ -5650,7 +6318,7 @@ var init_worldDir = __esm({
|
|
|
5650
6318
|
const hasher = createHash4("sha256");
|
|
5651
6319
|
for (const rel of this.archivePaths) {
|
|
5652
6320
|
hasher.update(Buffer.from(`file:${rel}`, "utf-8"));
|
|
5653
|
-
hasher.update(fs3.readFileSync(
|
|
6321
|
+
hasher.update(fs3.readFileSync(path4.join(this.dir, rel)));
|
|
5654
6322
|
}
|
|
5655
6323
|
return hasher.digest("hex");
|
|
5656
6324
|
}
|
|
@@ -5715,7 +6383,7 @@ var init_worldDir = __esm({
|
|
|
5715
6383
|
|
|
5716
6384
|
// src/worlds/tar.ts
|
|
5717
6385
|
import * as fs4 from "fs";
|
|
5718
|
-
import * as
|
|
6386
|
+
import * as path5 from "path";
|
|
5719
6387
|
import { gunzipSync } from "zlib";
|
|
5720
6388
|
function archiveMode(mode) {
|
|
5721
6389
|
return (mode & 73) !== 0 ? TAR_EXEC_MODE : TAR_FILE_MODE;
|
|
@@ -5801,8 +6469,8 @@ var init_tar = __esm({
|
|
|
5801
6469
|
for (const member of this.members()) {
|
|
5802
6470
|
if (member.typeflag !== "0" && member.typeflag !== "\0") continue;
|
|
5803
6471
|
if (!_TarArchive.isConfined(member.name)) continue;
|
|
5804
|
-
const target =
|
|
5805
|
-
fs4.mkdirSync(
|
|
6472
|
+
const target = path5.join(dir, member.name);
|
|
6473
|
+
fs4.mkdirSync(path5.dirname(target), { recursive: true });
|
|
5806
6474
|
const mode = archiveMode(member.mode);
|
|
5807
6475
|
fs4.writeFileSync(target, member.bytes, { mode });
|
|
5808
6476
|
fs4.chmodSync(target, mode);
|
|
@@ -5846,7 +6514,7 @@ __export(hub_exports, {
|
|
|
5846
6514
|
import { createHash as createHash5 } from "crypto";
|
|
5847
6515
|
import { gzipSync } from "zlib";
|
|
5848
6516
|
import * as fs5 from "fs";
|
|
5849
|
-
import * as
|
|
6517
|
+
import * as path6 from "path";
|
|
5850
6518
|
function collectArchiveRelPaths(dir) {
|
|
5851
6519
|
const world = WorldDir.open(dir);
|
|
5852
6520
|
if (world.hasRootGitignore) {
|
|
@@ -5909,7 +6577,7 @@ function tarMember(name, payload, mode) {
|
|
|
5909
6577
|
function buildSourceTarball(dir) {
|
|
5910
6578
|
const parts2 = [];
|
|
5911
6579
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
5912
|
-
const abs =
|
|
6580
|
+
const abs = path6.join(dir, relPath);
|
|
5913
6581
|
parts2.push(
|
|
5914
6582
|
...tarMember(
|
|
5915
6583
|
relPath,
|
|
@@ -5923,7 +6591,7 @@ function buildSourceTarball(dir) {
|
|
|
5923
6591
|
}
|
|
5924
6592
|
function readLocalMeta(dir) {
|
|
5925
6593
|
try {
|
|
5926
|
-
const raw = fs5.readFileSync(
|
|
6594
|
+
const raw = fs5.readFileSync(path6.join(dir, META_RELPATH), "utf-8");
|
|
5927
6595
|
const parsed = JSON.parse(raw);
|
|
5928
6596
|
return parsed && typeof parsed === "object" ? parsed : null;
|
|
5929
6597
|
} catch {
|
|
@@ -5946,16 +6614,16 @@ function resolvePushSlug(dir, opts = {}) {
|
|
|
5946
6614
|
}
|
|
5947
6615
|
const first = declared[0];
|
|
5948
6616
|
if (first) return { ...base, slug: first.slug, source: first.source };
|
|
5949
|
-
return { ...base, slug:
|
|
6617
|
+
return { ...base, slug: path6.basename(path6.resolve(dir)), source: "directory name" };
|
|
5950
6618
|
}
|
|
5951
6619
|
function writeLocalMeta(dir, meta) {
|
|
5952
|
-
fs5.mkdirSync(
|
|
5953
|
-
fs5.writeFileSync(
|
|
6620
|
+
fs5.mkdirSync(path6.join(dir, ".gateway"), { recursive: true });
|
|
6621
|
+
fs5.writeFileSync(path6.join(dir, META_RELPATH), JSON.stringify(meta, null, 2));
|
|
5954
6622
|
}
|
|
5955
6623
|
function snapshotTreeHashes(dir) {
|
|
5956
6624
|
const out = {};
|
|
5957
6625
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
5958
|
-
out[relPath] = createHash5("sha256").update(fs5.readFileSync(
|
|
6626
|
+
out[relPath] = createHash5("sha256").update(fs5.readFileSync(path6.join(dir, relPath))).digest("hex");
|
|
5959
6627
|
}
|
|
5960
6628
|
return out;
|
|
5961
6629
|
}
|
|
@@ -5973,7 +6641,7 @@ function localTreeState(dir) {
|
|
|
5973
6641
|
}
|
|
5974
6642
|
function readPyproject(dir) {
|
|
5975
6643
|
try {
|
|
5976
|
-
const text2 = fs5.readFileSync(
|
|
6644
|
+
const text2 = fs5.readFileSync(path6.join(dir, "pyproject.toml"), "utf-8");
|
|
5977
6645
|
const section = /\[project\]([\s\S]*?)(\n\[|$)/.exec(text2)?.[1] ?? "";
|
|
5978
6646
|
const name = /\bname\s*=\s*"([^"]+)"/.exec(section)?.[1];
|
|
5979
6647
|
const version = /\bversion\s*=\s*"([^"]+)"/.exec(section)?.[1];
|
|
@@ -5996,7 +6664,7 @@ function readWorldContractVersion(dir) {
|
|
|
5996
6664
|
}
|
|
5997
6665
|
function buildFileManifest(dir) {
|
|
5998
6666
|
return collectArchiveRelPaths(dir).map((relPath) => {
|
|
5999
|
-
const payload = fs5.readFileSync(
|
|
6667
|
+
const payload = fs5.readFileSync(path6.join(dir, relPath));
|
|
6000
6668
|
return {
|
|
6001
6669
|
path: relPath,
|
|
6002
6670
|
isDirectory: false,
|
|
@@ -6042,7 +6710,7 @@ async function push(dir, opts = {}) {
|
|
|
6042
6710
|
const pyproject = readPyproject(dir);
|
|
6043
6711
|
const contractVersion = pyproject.version ? void 0 : readWorldContractVersion(dir).version;
|
|
6044
6712
|
if (contractVersion) pyproject.version = contractVersion;
|
|
6045
|
-
const slug = opts.slug ?? localMeta.slug ?? pyproject.name ??
|
|
6713
|
+
const slug = opts.slug ?? localMeta.slug ?? pyproject.name ?? path6.basename(path6.resolve(dir));
|
|
6046
6714
|
const metadata = {
|
|
6047
6715
|
...opts.name !== void 0 ? { name: opts.name } : {},
|
|
6048
6716
|
...opts.description !== void 0 ? { description: opts.description } : {},
|
|
@@ -6168,7 +6836,7 @@ async function propose(dir, opts) {
|
|
|
6168
6836
|
if (state2.clean)
|
|
6169
6837
|
throw new Error("Nothing to propose \u2014 the tree matches its base.");
|
|
6170
6838
|
const changes = state2.dirty.map((relPath) => {
|
|
6171
|
-
const abs =
|
|
6839
|
+
const abs = path6.join(dir, relPath);
|
|
6172
6840
|
if (!fs5.existsSync(abs))
|
|
6173
6841
|
return { path: relPath, action: "delete" };
|
|
6174
6842
|
return {
|
|
@@ -6209,7 +6877,7 @@ var init_hub = __esm({
|
|
|
6209
6877
|
init_worldDir();
|
|
6210
6878
|
init_tar();
|
|
6211
6879
|
DEFAULT_BRANCH = "main";
|
|
6212
|
-
META_RELPATH =
|
|
6880
|
+
META_RELPATH = path6.join(".gateway", ".env-metadata.json");
|
|
6213
6881
|
FILE_MODE = TAR_FILE_MODE;
|
|
6214
6882
|
MINTED_SUFFIX = /^-\d+$/;
|
|
6215
6883
|
PushSlugConflict = class extends Error {
|
|
@@ -6437,7 +7105,7 @@ function rebaseConflicts(error) {
|
|
|
6437
7105
|
}
|
|
6438
7106
|
const conflicts = body?.conflicts;
|
|
6439
7107
|
if (!Array.isArray(conflicts)) return null;
|
|
6440
|
-
return conflicts.filter(isConflictPath).map(({ path:
|
|
7108
|
+
return conflicts.filter(isConflictPath).map(({ path: path17, reason }) => ({ path: path17, reason }));
|
|
6441
7109
|
}
|
|
6442
7110
|
function isConflictPath(value) {
|
|
6443
7111
|
const entry = value;
|
|
@@ -6477,8 +7145,8 @@ var init_sandbox = __esm({
|
|
|
6477
7145
|
this.options = options;
|
|
6478
7146
|
}
|
|
6479
7147
|
options;
|
|
6480
|
-
request(method,
|
|
6481
|
-
return apiRequest(this.options, method,
|
|
7148
|
+
request(method, path17, body) {
|
|
7149
|
+
return apiRequest(this.options, method, path17, body, {
|
|
6482
7150
|
timeoutMs: SANDBOX_REQUEST_TIMEOUT_MS
|
|
6483
7151
|
});
|
|
6484
7152
|
}
|
|
@@ -7009,6 +7677,17 @@ async function queryRows(slugRef, entity, opts = {}, options = {}) {
|
|
|
7009
7677
|
`/api/public/worlds/${encodeURIComponent(slug)}/data${queryRowsSearch(entity, opts, ref)}`
|
|
7010
7678
|
);
|
|
7011
7679
|
}
|
|
7680
|
+
async function sqlRows(slugRef, sql, opts = {}, options = {}) {
|
|
7681
|
+
const [slug, ref] = slugRef.split("@", 2);
|
|
7682
|
+
if (!slug || ref === "") throw new Error(`sqlRows needs a slug, optionally slug@ref (got ${slugRef})`);
|
|
7683
|
+
if (!sql.trim()) throw new Error("sqlRows needs one SQL statement");
|
|
7684
|
+
return apiRequest(options, "POST", `/api/public/worlds/${encodeURIComponent(slug)}/data/sql`, {
|
|
7685
|
+
sql,
|
|
7686
|
+
...ref ? { ref } : {},
|
|
7687
|
+
...opts.limit !== void 0 ? { limit: opts.limit } : {},
|
|
7688
|
+
...opts.scenario ? { scenario: opts.scenario } : {}
|
|
7689
|
+
});
|
|
7690
|
+
}
|
|
7012
7691
|
var init_query = __esm({
|
|
7013
7692
|
"src/worlds/query.ts"() {
|
|
7014
7693
|
"use strict";
|
|
@@ -7065,7 +7744,7 @@ var init_router = __esm({
|
|
|
7065
7744
|
// src/cli/config.ts
|
|
7066
7745
|
import * as fs6 from "fs";
|
|
7067
7746
|
import * as os from "os";
|
|
7068
|
-
import * as
|
|
7747
|
+
import * as path7 from "path";
|
|
7069
7748
|
async function api(creds, method, route, body, init3 = {}) {
|
|
7070
7749
|
const reply = await new PlatformTransport(creds).send(method, route, body, init3);
|
|
7071
7750
|
if (!reply.ok) throw new ApiError2(reply.status, method, route, reply.text);
|
|
@@ -7101,7 +7780,7 @@ var init_config = __esm({
|
|
|
7101
7780
|
import { spawn, spawnSync } from "child_process";
|
|
7102
7781
|
import * as fs7 from "fs";
|
|
7103
7782
|
import * as net from "net";
|
|
7104
|
-
import * as
|
|
7783
|
+
import * as path8 from "path";
|
|
7105
7784
|
function tailOf(output) {
|
|
7106
7785
|
return output.length > DIAGNOSTIC_TAIL ? `\u2026${output.slice(-DIAGNOSTIC_TAIL)}` : output;
|
|
7107
7786
|
}
|
|
@@ -7116,16 +7795,16 @@ function runtimeRoot() {
|
|
|
7116
7795
|
const candidates = [];
|
|
7117
7796
|
if (process.env.GATEWAY_RUNTIME_PATH)
|
|
7118
7797
|
candidates.push(process.env.GATEWAY_RUNTIME_PATH);
|
|
7119
|
-
const entry = process.argv[1] && fs7.existsSync(process.argv[1]) ?
|
|
7798
|
+
const entry = process.argv[1] && fs7.existsSync(process.argv[1]) ? path8.dirname(fs7.realpathSync(process.argv[1])) : null;
|
|
7120
7799
|
if (entry) {
|
|
7121
|
-
candidates.push(
|
|
7122
|
-
candidates.push(
|
|
7123
|
-
candidates.push(
|
|
7800
|
+
candidates.push(path8.resolve(entry, "..", "runtime"));
|
|
7801
|
+
candidates.push(path8.resolve(entry, "..", "..", "runtime"));
|
|
7802
|
+
candidates.push(path8.resolve(entry, "..", "..", "sdk", "src"));
|
|
7124
7803
|
}
|
|
7125
|
-
candidates.push(
|
|
7804
|
+
candidates.push(path8.resolve(process.cwd(), "runtime"));
|
|
7126
7805
|
for (const root of candidates)
|
|
7127
7806
|
if (fs7.existsSync(
|
|
7128
|
-
|
|
7807
|
+
path8.join(root, "gatewaysdk", "environment", "schema", "platform.py")
|
|
7129
7808
|
))
|
|
7130
7809
|
return root;
|
|
7131
7810
|
return null;
|
|
@@ -7214,13 +7893,12 @@ async function localBridge(request, local, opts = {}) {
|
|
|
7214
7893
|
["-I", "-B", "-c", BRIDGE_BOOTSTRAP, local.root],
|
|
7215
7894
|
{
|
|
7216
7895
|
stdio: ["pipe", "pipe", "pipe"],
|
|
7217
|
-
//
|
|
7218
|
-
// place the runtime may import and run a world's own Python (check's
|
|
7219
|
-
// handler execution, `worlds call`, `worlds test` tool cases).
|
|
7896
|
+
// The author's machine running the author's world: the one place the runtime may run its Python.
|
|
7220
7897
|
env: {
|
|
7221
7898
|
PATH: process.env.PATH ?? "",
|
|
7222
7899
|
HOME: process.env.HOME ?? "",
|
|
7223
7900
|
TMPDIR: process.env.TMPDIR ?? "",
|
|
7901
|
+
...process.env.VIRTUAL_ENV ? { VIRTUAL_ENV: process.env.VIRTUAL_ENV } : {},
|
|
7224
7902
|
GATEWAY_RUNTIME_EXECUTE: "1"
|
|
7225
7903
|
}
|
|
7226
7904
|
}
|
|
@@ -7292,18 +7970,46 @@ runpy.run_module('gatewaysdk.environment.schema.platform',run_name='__main__')`;
|
|
|
7292
7970
|
}
|
|
7293
7971
|
});
|
|
7294
7972
|
|
|
7973
|
+
// src/worlds/databaseEngines.ts
|
|
7974
|
+
function isWorldSnapshotOutput(path17) {
|
|
7975
|
+
return SNAPSHOT_OUTPUTS.has(path17.slice(path17.lastIndexOf("/") + 1));
|
|
7976
|
+
}
|
|
7977
|
+
var WORLD_DATABASE_ENGINES, DEFAULT_WORLD_DATABASE_ENGINE, WORLD_SNAPSHOT_FILE_PATH, WORLD_SNAPSHOT_SIDECAR_PATH, WORLD_SNAPSHOT_CONTENT_TYPE, SNAPSHOT_OUTPUTS;
|
|
7978
|
+
var init_databaseEngines = __esm({
|
|
7979
|
+
"src/worlds/databaseEngines.ts"() {
|
|
7980
|
+
"use strict";
|
|
7981
|
+
WORLD_DATABASE_ENGINES = [
|
|
7982
|
+
{
|
|
7983
|
+
engine: "sqlite",
|
|
7984
|
+
label: "SQLite",
|
|
7985
|
+
target: "sqlite-json/1",
|
|
7986
|
+
snapshotName: "state.sqlite",
|
|
7987
|
+
contentType: "application/vnd.sqlite3"
|
|
7988
|
+
}
|
|
7989
|
+
];
|
|
7990
|
+
DEFAULT_WORLD_DATABASE_ENGINE = WORLD_DATABASE_ENGINES[0];
|
|
7991
|
+
WORLD_SNAPSHOT_FILE_PATH = `db/${DEFAULT_WORLD_DATABASE_ENGINE.snapshotName}`;
|
|
7992
|
+
WORLD_SNAPSHOT_SIDECAR_PATH = "db/state.json";
|
|
7993
|
+
WORLD_SNAPSHOT_CONTENT_TYPE = DEFAULT_WORLD_DATABASE_ENGINE.contentType;
|
|
7994
|
+
SNAPSHOT_OUTPUTS = /* @__PURE__ */ new Set([
|
|
7995
|
+
...WORLD_DATABASE_ENGINES.map((engine) => engine.snapshotName),
|
|
7996
|
+
WORLD_SNAPSHOT_SIDECAR_PATH.slice("db/".length)
|
|
7997
|
+
]);
|
|
7998
|
+
}
|
|
7999
|
+
});
|
|
8000
|
+
|
|
7295
8001
|
// src/cli/runtime/client.ts
|
|
7296
8002
|
import * as fs8 from "fs";
|
|
7297
|
-
import * as
|
|
8003
|
+
import * as path9 from "path";
|
|
7298
8004
|
function isBuildOutput(relPath) {
|
|
7299
|
-
return
|
|
8005
|
+
return isWorldSnapshotOutput(relPath);
|
|
7300
8006
|
}
|
|
7301
8007
|
function readWorldFiles(dir, opts = {}) {
|
|
7302
8008
|
if (!fs8.existsSync(dir) || !fs8.statSync(dir).isDirectory())
|
|
7303
8009
|
throw new CliError(`Not a directory: ${dir}`);
|
|
7304
8010
|
const out = [];
|
|
7305
8011
|
const walk = (rel) => {
|
|
7306
|
-
const abs = rel ?
|
|
8012
|
+
const abs = rel ? path9.join(dir, rel) : dir;
|
|
7307
8013
|
const entries = fs8.readdirSync(abs, { withFileTypes: true });
|
|
7308
8014
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
7309
8015
|
for (const entry of entries) {
|
|
@@ -7314,7 +8020,7 @@ function readWorldFiles(dir, opts = {}) {
|
|
|
7314
8020
|
if (!opts.buildOutputs && isBuildOutput(childRel)) continue;
|
|
7315
8021
|
out.push({
|
|
7316
8022
|
path: childRel,
|
|
7317
|
-
content: fs8.readFileSync(
|
|
8023
|
+
content: fs8.readFileSync(path9.join(dir, childRel)).toString("base64")
|
|
7318
8024
|
});
|
|
7319
8025
|
}
|
|
7320
8026
|
}
|
|
@@ -7334,15 +8040,15 @@ function writeWorldFiles(dir, files, opts = {}) {
|
|
|
7334
8040
|
if (opts.clean && fs8.existsSync(dir)) {
|
|
7335
8041
|
const keep = new Set(files.map((f) => f.path));
|
|
7336
8042
|
for (const existing of readWorldFiles(dir)) {
|
|
7337
|
-
if (!keep.has(existing.path)) fs8.rmSync(
|
|
8043
|
+
if (!keep.has(existing.path)) fs8.rmSync(path9.join(dir, existing.path));
|
|
7338
8044
|
}
|
|
7339
8045
|
pruneEmptyDirs(dir);
|
|
7340
8046
|
}
|
|
7341
8047
|
fs8.mkdirSync(dir, { recursive: true });
|
|
7342
8048
|
const written = [];
|
|
7343
8049
|
for (const file of files) {
|
|
7344
|
-
const target =
|
|
7345
|
-
fs8.mkdirSync(
|
|
8050
|
+
const target = path9.join(dir, file.path);
|
|
8051
|
+
fs8.mkdirSync(path9.dirname(target), { recursive: true });
|
|
7346
8052
|
fs8.writeFileSync(target, Buffer.from(file.content, "base64"));
|
|
7347
8053
|
written.push(file.path);
|
|
7348
8054
|
}
|
|
@@ -7352,7 +8058,7 @@ function pruneEmptyDirs(root) {
|
|
|
7352
8058
|
const walk = (abs) => {
|
|
7353
8059
|
let empty = true;
|
|
7354
8060
|
for (const entry of fs8.readdirSync(abs, { withFileTypes: true })) {
|
|
7355
|
-
const child =
|
|
8061
|
+
const child = path9.join(abs, entry.name);
|
|
7356
8062
|
if (entry.isDirectory()) {
|
|
7357
8063
|
if (SKIP_DIRS.has(entry.name)) {
|
|
7358
8064
|
empty = false;
|
|
@@ -7389,13 +8095,9 @@ function yamlDocument(request) {
|
|
|
7389
8095
|
return isYamlSource(String(request.source ?? ""), String(request.document ?? ""));
|
|
7390
8096
|
return request.command === "conform" && Array.isArray(request.openapi) && request.openapi.some((doc) => YAML_NAME.test(doc.path ?? ""));
|
|
7391
8097
|
}
|
|
7392
|
-
function runsLocally(request) {
|
|
7393
|
-
const local = localRuntime();
|
|
7394
|
-
return local !== null && !(yamlDocument(request) && !localPythonHasYaml(local.python));
|
|
7395
|
-
}
|
|
7396
8098
|
async function runtime(creds, request, opts = {}) {
|
|
7397
|
-
const local =
|
|
7398
|
-
if (local
|
|
8099
|
+
const local = new RuntimeRoute().local(request);
|
|
8100
|
+
if (local) {
|
|
7399
8101
|
const payload2 = await localBridge(request, local, opts);
|
|
7400
8102
|
const detail2 = detailFrom(payload2);
|
|
7401
8103
|
if (detail2) throw new BridgeRejected(detail2);
|
|
@@ -7422,17 +8124,17 @@ async function runtime(creds, request, opts = {}) {
|
|
|
7422
8124
|
if (payload === null) throw new CliError(`POST ${route} (${request.command}) returned non-JSON`, 1);
|
|
7423
8125
|
return payload;
|
|
7424
8126
|
}
|
|
7425
|
-
var MAX_WORLD_FILES, RUNTIME_TIMEOUT_MS, SKIP_DIRS,
|
|
8127
|
+
var MAX_WORLD_FILES, RUNTIME_TIMEOUT_MS, SKIP_DIRS, BridgeRejected, YAML_NAME, YAML_NEEDS_PYYAML, YAML_NOT_ON_PLATFORM, RuntimeRoute;
|
|
7426
8128
|
var init_client = __esm({
|
|
7427
8129
|
"src/cli/runtime/client.ts"() {
|
|
7428
8130
|
"use strict";
|
|
7429
8131
|
init_router();
|
|
7430
8132
|
init_local();
|
|
7431
8133
|
init_transport();
|
|
8134
|
+
init_databaseEngines();
|
|
7432
8135
|
MAX_WORLD_FILES = 2e3;
|
|
7433
8136
|
RUNTIME_TIMEOUT_MS = 18e4;
|
|
7434
8137
|
SKIP_DIRS = /* @__PURE__ */ new Set(["__pycache__", ".git", "node_modules", ".gateway"]);
|
|
7435
|
-
BUILD_OUTPUT = /(^|\/)state\.(sqlite|json)$/;
|
|
7436
8138
|
BridgeRejected = class extends CliError {
|
|
7437
8139
|
constructor(detail) {
|
|
7438
8140
|
super(formatBridgeError(detail), 1);
|
|
@@ -7441,6 +8143,26 @@ var init_client = __esm({
|
|
|
7441
8143
|
detail;
|
|
7442
8144
|
};
|
|
7443
8145
|
YAML_NAME = /\.ya?ml$/i;
|
|
8146
|
+
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";
|
|
8147
|
+
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)";
|
|
8148
|
+
RuntimeRoute = class _RuntimeRoute {
|
|
8149
|
+
constructor(here = localRuntime, hasYaml = localPythonHasYaml) {
|
|
8150
|
+
this.here = here;
|
|
8151
|
+
this.hasYaml = hasYaml;
|
|
8152
|
+
}
|
|
8153
|
+
here;
|
|
8154
|
+
hasYaml;
|
|
8155
|
+
local(request) {
|
|
8156
|
+
const local = this.here();
|
|
8157
|
+
const yaml = yamlDocument(request);
|
|
8158
|
+
if (yaml && local === null) throw _RuntimeRoute.refusal(YAML_NOT_ON_PLATFORM);
|
|
8159
|
+
if (yaml && local !== null && !this.hasYaml(local.python)) throw _RuntimeRoute.refusal(YAML_NEEDS_PYYAML);
|
|
8160
|
+
return local;
|
|
8161
|
+
}
|
|
8162
|
+
static refusal(message) {
|
|
8163
|
+
return new BridgeRejected({ code: "conform", message, schema_path: "/openapi/source" });
|
|
8164
|
+
}
|
|
8165
|
+
};
|
|
7444
8166
|
}
|
|
7445
8167
|
});
|
|
7446
8168
|
|
|
@@ -7455,10 +8177,11 @@ __export(data_exports, {
|
|
|
7455
8177
|
ingestLocalToolCalls: () => ingestLocalToolCalls,
|
|
7456
8178
|
queryLocalWorldData: () => queryLocalWorldData,
|
|
7457
8179
|
queryLocalWorldDataAcross: () => queryLocalWorldDataAcross,
|
|
7458
|
-
showLocalWorldData: () => showLocalWorldData
|
|
8180
|
+
showLocalWorldData: () => showLocalWorldData,
|
|
8181
|
+
sqlLocalWorldData: () => sqlLocalWorldData
|
|
7459
8182
|
});
|
|
7460
8183
|
import * as fs9 from "fs";
|
|
7461
|
-
import * as
|
|
8184
|
+
import * as path10 from "path";
|
|
7462
8185
|
async function importLocalWorldData(dir, rows, opts, creds) {
|
|
7463
8186
|
const res = await runtime(creds, {
|
|
7464
8187
|
command: "import-data",
|
|
@@ -7489,8 +8212,8 @@ async function importLocalWorldFiles(dir, sources, opts) {
|
|
|
7489
8212
|
);
|
|
7490
8213
|
const res = await runtime(null, {
|
|
7491
8214
|
command: "import-files",
|
|
7492
|
-
world:
|
|
7493
|
-
sources: sources.map((source) =>
|
|
8215
|
+
world: path10.resolve(dir),
|
|
8216
|
+
sources: sources.map((source) => path10.resolve(source)),
|
|
7494
8217
|
mode: opts.mode ?? "append",
|
|
7495
8218
|
...opts.entity ? { entity: opts.entity } : {},
|
|
7496
8219
|
...opts.delimiter ? { delimiter: opts.delimiter } : {},
|
|
@@ -7516,9 +8239,9 @@ async function chunkLocalWorldFiles(dir, sources, out, opts) {
|
|
|
7516
8239
|
);
|
|
7517
8240
|
const res = await runtime(null, {
|
|
7518
8241
|
command: "chunk-files",
|
|
7519
|
-
world:
|
|
7520
|
-
sources: sources.map((source) =>
|
|
7521
|
-
out:
|
|
8242
|
+
world: path10.resolve(dir),
|
|
8243
|
+
sources: sources.map((source) => path10.resolve(source)),
|
|
8244
|
+
out: path10.resolve(out),
|
|
7522
8245
|
...opts.entity ? { entity: opts.entity } : {},
|
|
7523
8246
|
...opts.delimiter ? { delimiter: opts.delimiter } : {},
|
|
7524
8247
|
...opts.chunkBytes ? { chunk_bytes: opts.chunkBytes } : {},
|
|
@@ -7529,8 +8252,8 @@ async function chunkLocalWorldFiles(dir, sources, out, opts) {
|
|
|
7529
8252
|
function dropBuildOutputs(dir) {
|
|
7530
8253
|
const dropped = [];
|
|
7531
8254
|
for (const file of readWorldFiles(dir, { buildOutputs: true })) {
|
|
7532
|
-
if (!
|
|
7533
|
-
fs9.rmSync(
|
|
8255
|
+
if (!isBuildOutput(file.path)) continue;
|
|
8256
|
+
fs9.rmSync(path10.join(dir, file.path), { force: true });
|
|
7534
8257
|
dropped.push(file.path);
|
|
7535
8258
|
}
|
|
7536
8259
|
return dropped;
|
|
@@ -7597,7 +8320,7 @@ async function queryLocalWorldDataAcross(dir, entity, where, opts) {
|
|
|
7597
8320
|
const payload = await localBridge(
|
|
7598
8321
|
{
|
|
7599
8322
|
command: "query",
|
|
7600
|
-
world:
|
|
8323
|
+
world: path10.resolve(dir),
|
|
7601
8324
|
entity,
|
|
7602
8325
|
across: true,
|
|
7603
8326
|
...opts.compare ? { compare: true } : {},
|
|
@@ -7613,6 +8336,28 @@ async function queryLocalWorldDataAcross(dir, entity, where, opts) {
|
|
|
7613
8336
|
if (detail) throw new BridgeRejected(detail);
|
|
7614
8337
|
return payload;
|
|
7615
8338
|
}
|
|
8339
|
+
async function sqlLocalWorldData(dir, sql, opts) {
|
|
8340
|
+
const local = localRuntime();
|
|
8341
|
+
if (!local)
|
|
8342
|
+
throw new CliError(
|
|
8343
|
+
"`worlds data sql` on a directory reads the world's database in place, so it needs the bundled runtime on this machine. " + localRuntimeReason(),
|
|
8344
|
+
1
|
|
8345
|
+
);
|
|
8346
|
+
const payload = await localBridge(
|
|
8347
|
+
{
|
|
8348
|
+
command: "sql",
|
|
8349
|
+
world: path10.resolve(dir),
|
|
8350
|
+
sql,
|
|
8351
|
+
...opts.limit !== void 0 ? { limit: opts.limit } : {},
|
|
8352
|
+
...opts.scenario ? { scenario: opts.scenario } : {}
|
|
8353
|
+
},
|
|
8354
|
+
local
|
|
8355
|
+
);
|
|
8356
|
+
const detail = detailFrom(payload);
|
|
8357
|
+
if (detail) throw new BridgeRejected(detail);
|
|
8358
|
+
const { status: _status, ...answer } = payload;
|
|
8359
|
+
return answer;
|
|
8360
|
+
}
|
|
7616
8361
|
async function ingestLocalToolCalls(dir, records, opts, creds) {
|
|
7617
8362
|
const res = await runtime(creds, {
|
|
7618
8363
|
command: "ingest-calls",
|
|
@@ -7644,14 +8389,12 @@ async function ingestLocalToolCalls(dir, records, opts, creds) {
|
|
|
7644
8389
|
...res.batch !== void 0 ? { batch: res.batch } : {}
|
|
7645
8390
|
};
|
|
7646
8391
|
}
|
|
7647
|
-
var BUILD_OUTPUT2;
|
|
7648
8392
|
var init_data = __esm({
|
|
7649
8393
|
"src/cli/runtime/data.ts"() {
|
|
7650
8394
|
"use strict";
|
|
7651
8395
|
init_router();
|
|
7652
8396
|
init_client();
|
|
7653
8397
|
init_local();
|
|
7654
|
-
BUILD_OUTPUT2 = /(^|\/)state\.(sqlite|json)$/;
|
|
7655
8398
|
}
|
|
7656
8399
|
});
|
|
7657
8400
|
|
|
@@ -7670,7 +8413,7 @@ __export(transform_exports, {
|
|
|
7670
8413
|
import { spawn as spawn2 } from "child_process";
|
|
7671
8414
|
import * as fs10 from "fs";
|
|
7672
8415
|
import * as os2 from "os";
|
|
7673
|
-
import * as
|
|
8416
|
+
import * as path11 from "path";
|
|
7674
8417
|
import { createRequire } from "module";
|
|
7675
8418
|
function checkRows(value, where) {
|
|
7676
8419
|
if (!isObject(value)) throw new CliError(`${where} must return {entity: [rows]}; got ${value === null ? "null" : Array.isArray(value) ? "an array" : typeof value}`, 1);
|
|
@@ -7695,27 +8438,27 @@ function typescriptPrefix() {
|
|
|
7695
8438
|
}
|
|
7696
8439
|
}
|
|
7697
8440
|
function command(script, wrapperDir) {
|
|
7698
|
-
const suffix =
|
|
8441
|
+
const suffix = path11.extname(script).toLowerCase();
|
|
7699
8442
|
if (PYTHON_SUFFIXES.includes(suffix)) return { file: process.env.GATEWAY_PYTHON || "python3", args: ["-c", PY_WRAPPER, script] };
|
|
7700
8443
|
if (NODE_SUFFIXES.includes(suffix)) {
|
|
7701
|
-
const wrapper =
|
|
8444
|
+
const wrapper = path11.join(wrapperDir, "transform-wrapper.mjs");
|
|
7702
8445
|
fs10.writeFileSync(wrapper, NODE_WRAPPER);
|
|
7703
8446
|
const flags = suffix === ".ts" || suffix === ".mts" ? typescriptPrefix() : [];
|
|
7704
8447
|
return { file: process.env.GATEWAY_NODE || process.execPath, args: [...flags, wrapper, script] };
|
|
7705
8448
|
}
|
|
7706
|
-
throw new CliError(`${
|
|
8449
|
+
throw new CliError(`${path11.basename(script)}: a transform script is .py, .ts, .mjs, .js or .cjs`, 1);
|
|
7707
8450
|
}
|
|
7708
8451
|
async function runTransform(script, records, opts = {}) {
|
|
7709
8452
|
if (!fs10.existsSync(script) || !fs10.statSync(script).isFile()) throw new CliError(`no transform script at ${script}`, 1);
|
|
7710
|
-
const resolved =
|
|
7711
|
-
const name =
|
|
8453
|
+
const resolved = path11.resolve(script);
|
|
8454
|
+
const name = path11.basename(script);
|
|
7712
8455
|
const timeoutMs = opts.timeoutMs ?? DEFAULT_TRANSFORM_TIMEOUT_MS;
|
|
7713
|
-
const scratch = fs10.mkdtempSync(
|
|
8456
|
+
const scratch = fs10.mkdtempSync(path11.join(os2.tmpdir(), "gateway-transform-"));
|
|
7714
8457
|
try {
|
|
7715
8458
|
const { file, args } = command(resolved, scratch);
|
|
7716
8459
|
const env = Object.fromEntries(Object.entries(process.env).filter(([key2]) => !SCRUBBED.test(key2)));
|
|
7717
8460
|
const done = await new Promise((resolve11, reject) => {
|
|
7718
|
-
const child = spawn2(file, args, { cwd:
|
|
8461
|
+
const child = spawn2(file, args, { cwd: path11.dirname(resolved), env, stdio: ["pipe", "pipe", "pipe"] });
|
|
7719
8462
|
let stdout = "";
|
|
7720
8463
|
let stderr = "";
|
|
7721
8464
|
let timedOut = false;
|
|
@@ -7876,7 +8619,7 @@ async function forEachLimited(items, limit, fn) {
|
|
|
7876
8619
|
if (failure) throw failure;
|
|
7877
8620
|
}
|
|
7878
8621
|
async function waitForBatch(client2, batchId, opts = {}) {
|
|
7879
|
-
const
|
|
8622
|
+
const sleep5 = opts.sleep ?? client2.sleep;
|
|
7880
8623
|
let delay = opts.initialDelayMs ?? 1e3;
|
|
7881
8624
|
let last = "";
|
|
7882
8625
|
for (; ; ) {
|
|
@@ -7887,7 +8630,7 @@ async function waitForBatch(client2, batchId, opts = {}) {
|
|
|
7887
8630
|
last = phase;
|
|
7888
8631
|
}
|
|
7889
8632
|
if (isSettled(status)) return status;
|
|
7890
|
-
await
|
|
8633
|
+
await sleep5(delay);
|
|
7891
8634
|
delay = Math.min(1e4, Math.round(delay * 1.5));
|
|
7892
8635
|
}
|
|
7893
8636
|
}
|
|
@@ -7909,10 +8652,10 @@ var init_batches = __esm({
|
|
|
7909
8652
|
]);
|
|
7910
8653
|
sleepMs = (ms) => new Promise((resolve11) => setTimeout(resolve11, ms));
|
|
7911
8654
|
WorldDataApi = class {
|
|
7912
|
-
constructor(creds, slug,
|
|
8655
|
+
constructor(creds, slug, sleep5 = sleepMs) {
|
|
7913
8656
|
this.creds = creds;
|
|
7914
8657
|
this.slug = slug;
|
|
7915
|
-
this.sleep =
|
|
8658
|
+
this.sleep = sleep5;
|
|
7916
8659
|
this.base = `/api/public/worlds/${encodeURIComponent(slug)}/data`;
|
|
7917
8660
|
}
|
|
7918
8661
|
creds;
|
|
@@ -8195,7 +8938,7 @@ var init_push = __esm({
|
|
|
8195
8938
|
// src/worlds/ingest.ts
|
|
8196
8939
|
import * as fs12 from "fs";
|
|
8197
8940
|
import * as os3 from "os";
|
|
8198
|
-
import * as
|
|
8941
|
+
import * as path12 from "path";
|
|
8199
8942
|
function parseToolCallRecord(raw) {
|
|
8200
8943
|
const none = { record: null, skip: null };
|
|
8201
8944
|
if (!isObject2(raw)) return { ...none, refusal: "record is not an object" };
|
|
@@ -8319,19 +9062,13 @@ function toolCallsFromObservations(observations, opts = {}) {
|
|
|
8319
9062
|
}
|
|
8320
9063
|
return out;
|
|
8321
9064
|
}
|
|
8322
|
-
function credentialsOf(options) {
|
|
8323
|
-
const host = (options.host ?? process.env.GATEWAY_HOST ?? "https://withgateway.ai").replace(/\/+$/, "");
|
|
8324
|
-
const publicKey = options.publicKey ?? process.env.GATEWAY_PUBLIC_KEY;
|
|
8325
|
-
const secretKey = options.secretKey ?? process.env.GATEWAY_SECRET_KEY;
|
|
8326
|
-
return publicKey && secretKey ? { host, publicKey, secretKey } : null;
|
|
8327
|
-
}
|
|
8328
9065
|
async function ingest(world, records, options = {}) {
|
|
8329
9066
|
const { ingestLocalToolCalls: ingestLocalToolCalls2, importLocalWorldData: importLocalWorldData2, checkLocalWorldData: checkLocalWorldData2 } = await Promise.resolve().then(() => (init_data(), data_exports));
|
|
8330
9067
|
if (options.transform !== void 0 && options.map !== void 0) throw new Error("records go through one of transform, map");
|
|
8331
9068
|
const redact = options.redact ?? "off";
|
|
8332
9069
|
const mode = options.mode ?? "append";
|
|
8333
9070
|
const dryRun = Boolean(options.dryRun);
|
|
8334
|
-
const creds =
|
|
9071
|
+
const creds = platformEndpoint(options);
|
|
8335
9072
|
const local = fs12.existsSync(world) && fs12.statSync(world).isDirectory();
|
|
8336
9073
|
const map = options.map === void 0 ? void 0 : options.map;
|
|
8337
9074
|
let rows = null;
|
|
@@ -8345,12 +9082,12 @@ async function ingest(world, records, options = {}) {
|
|
|
8345
9082
|
const landed = dryRun ? await checkLocalWorldData2(world, rows, creds, { redact }) : await importLocalWorldData2(world, rows, { mode, redact }, creds);
|
|
8346
9083
|
return transformReport(world, records.length, rows, stderr, { dryRun, redact, changed: !dryRun && landed.changed, kind: landed.kind, entityCounts: landed.entity_counts });
|
|
8347
9084
|
}
|
|
8348
|
-
if (!creds) throw new Error(
|
|
9085
|
+
if (!creds) throw new Error(GATEWAY_KEYS_MISSING);
|
|
8349
9086
|
const { pull: pull2 } = await Promise.resolve().then(() => (init_hub(), hub_exports));
|
|
8350
9087
|
const slug = world.split("@", 1)[0];
|
|
8351
|
-
const scratch = fs12.mkdtempSync(
|
|
9088
|
+
const scratch = fs12.mkdtempSync(path12.join(os3.tmpdir(), "gateway-ingest-"));
|
|
8352
9089
|
try {
|
|
8353
|
-
const pulled = await pull2(world,
|
|
9090
|
+
const pulled = await pull2(world, path12.join(scratch, slug), options);
|
|
8354
9091
|
let report;
|
|
8355
9092
|
let projected;
|
|
8356
9093
|
if (rows === null) {
|
|
@@ -8429,6 +9166,7 @@ var init_ingest = __esm({
|
|
|
8429
9166
|
"src/worlds/ingest.ts"() {
|
|
8430
9167
|
"use strict";
|
|
8431
9168
|
init_worlds();
|
|
9169
|
+
init_platformEndpoint();
|
|
8432
9170
|
isObject2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8433
9171
|
isoOf = (value) => value instanceof Date ? value.toISOString() : typeof value === "string" ? value : void 0;
|
|
8434
9172
|
}
|
|
@@ -8529,7 +9267,7 @@ var init_dryRun = __esm({
|
|
|
8529
9267
|
/** Poll until the run settles or `timeoutSeconds` pass; the last verdict either way. */
|
|
8530
9268
|
async settle(runId, opts) {
|
|
8531
9269
|
const now = opts.now ?? Date.now;
|
|
8532
|
-
const
|
|
9270
|
+
const sleep5 = opts.sleep ?? ((ms) => new Promise((resolve11) => setTimeout(resolve11, ms)));
|
|
8533
9271
|
const deadline = now() + opts.timeoutSeconds * 1e3;
|
|
8534
9272
|
for (; ; ) {
|
|
8535
9273
|
const budget = Math.floor(
|
|
@@ -8539,7 +9277,7 @@ var init_dryRun = __esm({
|
|
|
8539
9277
|
const verdict = await this.status(runId, budget);
|
|
8540
9278
|
if (verdict.settled || now() >= deadline) return verdict;
|
|
8541
9279
|
opts.onProgress?.(verdict);
|
|
8542
|
-
if (now() - asked < 1e3) await
|
|
9280
|
+
if (now() - asked < 1e3) await sleep5(1e3);
|
|
8543
9281
|
}
|
|
8544
9282
|
}
|
|
8545
9283
|
};
|
|
@@ -8607,6 +9345,8 @@ __export(worlds_exports, {
|
|
|
8607
9345
|
EXPLORATORY_TASK: () => EXPLORATORY_TASK,
|
|
8608
9346
|
EXPLORATORY_TASK_SOURCE: () => EXPLORATORY_TASK_SOURCE,
|
|
8609
9347
|
GatewayEvalsClient: () => GatewayEvalsClient,
|
|
9348
|
+
GradePayload: () => GradePayload,
|
|
9349
|
+
GradeRefused: () => GradeRefused,
|
|
8610
9350
|
HostedDryRunClient: () => HostedDryRunClient,
|
|
8611
9351
|
IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
|
|
8612
9352
|
KEY_NAMES: () => KEY_NAMES,
|
|
@@ -8622,6 +9362,7 @@ __export(worlds_exports, {
|
|
|
8622
9362
|
PlatformTransport: () => PlatformTransport,
|
|
8623
9363
|
PushSlugConflict: () => PushSlugConflict,
|
|
8624
9364
|
RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
|
|
9365
|
+
RetryPolicy: () => RetryPolicy,
|
|
8625
9366
|
SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
|
|
8626
9367
|
SECRET_KEY: () => SECRET_KEY,
|
|
8627
9368
|
SESSION_STATES: () => SESSION_STATES,
|
|
@@ -8629,8 +9370,10 @@ __export(worlds_exports, {
|
|
|
8629
9370
|
STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
|
|
8630
9371
|
STRIP_PREFIX: () => STRIP_PREFIX,
|
|
8631
9372
|
SURFACE_KINDS: () => SURFACE_KINDS,
|
|
9373
|
+
Score: () => Score,
|
|
8632
9374
|
Screen: () => Screen,
|
|
8633
9375
|
SecretScrubber: () => SecretScrubber,
|
|
9376
|
+
TOOL_CONTRACT_UNREAD: () => TOOL_CONTRACT_UNREAD,
|
|
8634
9377
|
TRANSFORMS: () => TRANSFORMS,
|
|
8635
9378
|
TaskEditClient: () => TaskEditClient,
|
|
8636
9379
|
TaskRun: () => TaskRun,
|
|
@@ -8642,14 +9385,17 @@ __export(worlds_exports, {
|
|
|
8642
9385
|
WorldBrowser: () => WorldBrowser,
|
|
8643
9386
|
WorldCallTooLarge: () => WorldCallTooLarge,
|
|
8644
9387
|
WorldEditClient: () => WorldEditClient,
|
|
9388
|
+
WorldNotice: () => WorldNotice,
|
|
8645
9389
|
WorldRequestLog: () => WorldRequestLog,
|
|
8646
9390
|
WorldSandboxClient: () => WorldSandboxClient,
|
|
8647
9391
|
WorldSession: () => WorldSession,
|
|
8648
9392
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
9393
|
+
WorldSessionOpenFailed: () => WorldSessionOpenFailed,
|
|
8649
9394
|
WorldSessionTimeout: () => WorldSessionTimeout,
|
|
8650
9395
|
WorldSet: () => WorldSet,
|
|
8651
9396
|
WorldSurfaceUnavailable: () => WorldSurfaceUnavailable,
|
|
8652
9397
|
WorldTask: () => WorldTask,
|
|
9398
|
+
WorldToolsUnread: () => WorldToolsUnread,
|
|
8653
9399
|
aggregateTaskGrade: () => aggregateTaskGrade,
|
|
8654
9400
|
apiRequest: () => apiRequest,
|
|
8655
9401
|
applyTransforms: () => applyTransforms,
|
|
@@ -8692,6 +9438,7 @@ __export(worlds_exports, {
|
|
|
8692
9438
|
listTaskSessions: () => listTaskSessions,
|
|
8693
9439
|
listTasks: () => listTasks,
|
|
8694
9440
|
localTreeState: () => localTreeState,
|
|
9441
|
+
messageOf: () => messageOf,
|
|
8695
9442
|
migrateProjectWorlds: () => migrateProjectWorlds,
|
|
8696
9443
|
migrateWorld: () => migrateWorld,
|
|
8697
9444
|
modelToolName: () => modelToolName,
|
|
@@ -8735,10 +9482,14 @@ __export(worlds_exports, {
|
|
|
8735
9482
|
setEnvSecret: () => setEnvSecret,
|
|
8736
9483
|
shapeText: () => shapeText,
|
|
8737
9484
|
snapshotTreeHashes: () => snapshotTreeHashes,
|
|
9485
|
+
sqlRows: () => sqlRows,
|
|
9486
|
+
stillStartingHint: () => stillStartingHint,
|
|
8738
9487
|
storedForms: () => storedForms,
|
|
8739
9488
|
surfaceDescriptor: () => surfaceDescriptor,
|
|
8740
9489
|
surfaceKinds: () => surfaceKinds,
|
|
9490
|
+
taskGradeError: () => taskGradeError,
|
|
8741
9491
|
taskLabel: () => taskLabel,
|
|
9492
|
+
taskRunFailure: () => taskRunFailure,
|
|
8742
9493
|
toolCallRecordsIn: () => toolCallRecordsIn,
|
|
8743
9494
|
toolCallsFromObservations: () => toolCallsFromObservations,
|
|
8744
9495
|
uiEntryUrl: () => uiEntryUrl,
|
|
@@ -8752,17 +9503,6 @@ __export(worlds_exports, {
|
|
|
8752
9503
|
withoutUiToken: () => withoutUiToken,
|
|
8753
9504
|
writeLocalMeta: () => writeLocalMeta
|
|
8754
9505
|
});
|
|
8755
|
-
function resolveEnv(options) {
|
|
8756
|
-
const host = options.host ?? process.env.GATEWAY_HOST ?? "https://withgateway.ai";
|
|
8757
|
-
const publicKey = options.publicKey ?? process.env.GATEWAY_PUBLIC_KEY;
|
|
8758
|
-
const secretKey = options.secretKey ?? process.env.GATEWAY_SECRET_KEY;
|
|
8759
|
-
if (!publicKey || !secretKey) {
|
|
8760
|
-
throw new Error(
|
|
8761
|
-
"Gateway keys missing: set GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY (or pass publicKey/secretKey)."
|
|
8762
|
-
);
|
|
8763
|
-
}
|
|
8764
|
-
return { host: host.replace(/\/+$/, ""), publicKey, secretKey };
|
|
8765
|
-
}
|
|
8766
9506
|
function parseErrorBody(text2, limit = 600) {
|
|
8767
9507
|
const raw = { detail: text2.slice(0, limit), code: null };
|
|
8768
9508
|
let parsed;
|
|
@@ -8782,9 +9522,9 @@ function parseErrorBody(text2, limit = 600) {
|
|
|
8782
9522
|
code: stableCode
|
|
8783
9523
|
};
|
|
8784
9524
|
}
|
|
8785
|
-
async function apiRequest(options, method,
|
|
8786
|
-
const reply = await new PlatformTransport(
|
|
8787
|
-
if (!reply.ok) throw new ApiError(reply.status, method,
|
|
9525
|
+
async function apiRequest(options, method, path17, body, init3 = {}) {
|
|
9526
|
+
const reply = await new PlatformTransport(requirePlatformEndpoint(options)).send(method, path17, body, init3);
|
|
9527
|
+
if (!reply.ok) throw new ApiError(reply.status, method, path17, reply.text);
|
|
8788
9528
|
return JSON.parse(reply.text);
|
|
8789
9529
|
}
|
|
8790
9530
|
async function setEnvSecret(slug, key2, value, options = {}) {
|
|
@@ -8896,7 +9636,6 @@ function detectProvenance() {
|
|
|
8896
9636
|
kind: "ci",
|
|
8897
9637
|
id: env.GITHUB_ACTOR,
|
|
8898
9638
|
name: env.GITHUB_ACTOR,
|
|
8899
|
-
// GitHub serves every account's avatar at /<login>.png.
|
|
8900
9639
|
imageUrl: `${server}/${env.GITHUB_ACTOR}.png`
|
|
8901
9640
|
};
|
|
8902
9641
|
}
|
|
@@ -8965,9 +9704,11 @@ var ApiError, WorldTask, WorldSet;
|
|
|
8965
9704
|
var init_worlds = __esm({
|
|
8966
9705
|
"src/worlds/index.ts"() {
|
|
8967
9706
|
"use strict";
|
|
9707
|
+
init_platformEndpoint();
|
|
8968
9708
|
init_transport();
|
|
8969
9709
|
init_transport();
|
|
8970
9710
|
init_session2();
|
|
9711
|
+
init_grade();
|
|
8971
9712
|
init_sessionList();
|
|
8972
9713
|
init_sessionContract();
|
|
8973
9714
|
init_taskRef();
|
|
@@ -8993,10 +9734,11 @@ var init_worlds = __esm({
|
|
|
8993
9734
|
init_sandbox();
|
|
8994
9735
|
init_editSessions();
|
|
8995
9736
|
init_dryRun();
|
|
9737
|
+
init_worldNotice();
|
|
8996
9738
|
ApiError = class extends Error {
|
|
8997
|
-
constructor(status, method,
|
|
9739
|
+
constructor(status, method, path17, text2) {
|
|
8998
9740
|
const parsed = parseErrorBody(text2);
|
|
8999
|
-
super(`${method} ${
|
|
9741
|
+
super(`${method} ${path17} -> ${status}: ${parsed.detail}`);
|
|
9000
9742
|
this.status = status;
|
|
9001
9743
|
this.text = text2;
|
|
9002
9744
|
this.name = "ApiError";
|
|
@@ -9651,8 +10393,8 @@ var GatewayContext = class _GatewayContext {
|
|
|
9651
10393
|
}
|
|
9652
10394
|
return resolved;
|
|
9653
10395
|
}
|
|
9654
|
-
async requestJson(method,
|
|
9655
|
-
const response = await fetch(`${this.host}${
|
|
10396
|
+
async requestJson(method, path17, payload) {
|
|
10397
|
+
const response = await fetch(`${this.host}${path17}`, {
|
|
9656
10398
|
method,
|
|
9657
10399
|
headers: {
|
|
9658
10400
|
Authorization: this.authHeader(),
|
|
@@ -9663,7 +10405,7 @@ var GatewayContext = class _GatewayContext {
|
|
|
9663
10405
|
const text2 = await response.text();
|
|
9664
10406
|
const body = text2 ? safeJson(text2) : {};
|
|
9665
10407
|
if (!response.ok) {
|
|
9666
|
-
const message = typeof body.message === "string" ? body.message : `Gateway API ${response.status} on ${
|
|
10408
|
+
const message = typeof body.message === "string" ? body.message : `Gateway API ${response.status} on ${path17}`;
|
|
9667
10409
|
if (response.status === 409) {
|
|
9668
10410
|
throw new GatewayContextConflictError(
|
|
9669
10411
|
message,
|
|
@@ -9672,7 +10414,7 @@ var GatewayContext = class _GatewayContext {
|
|
|
9672
10414
|
}
|
|
9673
10415
|
throw new GatewayContextError(message);
|
|
9674
10416
|
}
|
|
9675
|
-
this.log("%s %s -> %s", method,
|
|
10417
|
+
this.log("%s %s -> %s", method, path17, response.status);
|
|
9676
10418
|
return body;
|
|
9677
10419
|
}
|
|
9678
10420
|
authHeader() {
|
|
@@ -9779,11 +10521,11 @@ function primaryPathForKind(kind, snapshot) {
|
|
|
9779
10521
|
const preferred = kind === "agent" ? "AGENTS.md" : kind === "prompt" ? "PROMPT.md" : kind === "skill" ? "SKILL.md" : "MEMORY.md";
|
|
9780
10522
|
if (readFile(snapshot, preferred)) return preferred;
|
|
9781
10523
|
return Object.entries(snapshot.files).find(
|
|
9782
|
-
([
|
|
10524
|
+
([path17, entry]) => entry.type === "file" && path17.endsWith(".md")
|
|
9783
10525
|
)?.[0] ?? null;
|
|
9784
10526
|
}
|
|
9785
|
-
function parseJsonFile(snapshot,
|
|
9786
|
-
const content = readFile(snapshot,
|
|
10527
|
+
function parseJsonFile(snapshot, path17) {
|
|
10528
|
+
const content = readFile(snapshot, path17);
|
|
9787
10529
|
if (!content) return {};
|
|
9788
10530
|
try {
|
|
9789
10531
|
const parsed = JSON.parse(content);
|
|
@@ -9792,8 +10534,8 @@ function parseJsonFile(snapshot, path16) {
|
|
|
9792
10534
|
return {};
|
|
9793
10535
|
}
|
|
9794
10536
|
}
|
|
9795
|
-
function readFile(snapshot,
|
|
9796
|
-
const entry = snapshot.files[
|
|
10537
|
+
function readFile(snapshot, path17) {
|
|
10538
|
+
const entry = snapshot.files[path17];
|
|
9797
10539
|
return entry?.type === "file" ? entry.content : null;
|
|
9798
10540
|
}
|
|
9799
10541
|
function provenanceFor(snapshot, label) {
|
|
@@ -9895,16 +10637,16 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
9895
10637
|
`/api/public/context/memory/${encodeIdentifier2(identifier)}${suffix}`
|
|
9896
10638
|
);
|
|
9897
10639
|
}
|
|
9898
|
-
async read(target,
|
|
10640
|
+
async read(target, path17, options = {}) {
|
|
9899
10641
|
const snapshot = typeof target === "string" ? await this.pull(target, options) : target;
|
|
9900
|
-
const file = snapshot.files[
|
|
10642
|
+
const file = snapshot.files[path17];
|
|
9901
10643
|
return file?.type === "file" ? file.content : null;
|
|
9902
10644
|
}
|
|
9903
|
-
async write(target,
|
|
10645
|
+
async write(target, path17, content, options = {}) {
|
|
9904
10646
|
const snapshot = typeof target === "string" ? await this.pull(target) : target;
|
|
9905
10647
|
return this.push(snapshot.repo.repoHandle, {
|
|
9906
10648
|
files: {
|
|
9907
|
-
[
|
|
10649
|
+
[path17]: {
|
|
9908
10650
|
content,
|
|
9909
10651
|
...options.mimeType ? { mimeType: options.mimeType } : {}
|
|
9910
10652
|
}
|
|
@@ -9914,10 +10656,10 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
9914
10656
|
...runtimeContextPayload2(options)
|
|
9915
10657
|
});
|
|
9916
10658
|
}
|
|
9917
|
-
async delete(target,
|
|
10659
|
+
async delete(target, path17, options = {}) {
|
|
9918
10660
|
const snapshot = typeof target === "string" ? await this.pull(target) : target;
|
|
9919
10661
|
return this.push(snapshot.repo.repoHandle, {
|
|
9920
|
-
files: { [
|
|
10662
|
+
files: { [path17]: null },
|
|
9921
10663
|
parentCommit: options.parentCommit ?? snapshot.commit.commitHash,
|
|
9922
10664
|
message: options.message,
|
|
9923
10665
|
...runtimeContextPayload2(options)
|
|
@@ -9930,8 +10672,8 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
9930
10672
|
payload
|
|
9931
10673
|
);
|
|
9932
10674
|
}
|
|
9933
|
-
async requestJson(method,
|
|
9934
|
-
const response = await fetch(`${this.host}${
|
|
10675
|
+
async requestJson(method, path17, payload) {
|
|
10676
|
+
const response = await fetch(`${this.host}${path17}`, {
|
|
9935
10677
|
method,
|
|
9936
10678
|
headers: {
|
|
9937
10679
|
Authorization: this.authHeader(),
|
|
@@ -9942,7 +10684,7 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
9942
10684
|
const text2 = await response.text();
|
|
9943
10685
|
const body = text2 ? safeJson2(text2) : {};
|
|
9944
10686
|
if (!response.ok) {
|
|
9945
|
-
const message = typeof body.message === "string" ? body.message : `Gateway API ${response.status} on ${
|
|
10687
|
+
const message = typeof body.message === "string" ? body.message : `Gateway API ${response.status} on ${path17}`;
|
|
9946
10688
|
if (response.status === 409) {
|
|
9947
10689
|
throw new GatewayMemoryConflictError(
|
|
9948
10690
|
message,
|
|
@@ -9951,7 +10693,7 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
9951
10693
|
}
|
|
9952
10694
|
throw new GatewayMemoryError(message);
|
|
9953
10695
|
}
|
|
9954
|
-
this.log("%s %s -> %s", method,
|
|
10696
|
+
this.log("%s %s -> %s", method, path17, response.status);
|
|
9955
10697
|
return body;
|
|
9956
10698
|
}
|
|
9957
10699
|
authHeader() {
|
|
@@ -10113,10 +10855,10 @@ var PersonasClient = class _PersonasClient {
|
|
|
10113
10855
|
done: Boolean(payload.done)
|
|
10114
10856
|
};
|
|
10115
10857
|
}
|
|
10116
|
-
async requestJson(method,
|
|
10858
|
+
async requestJson(method, path17, payload) {
|
|
10117
10859
|
let response;
|
|
10118
10860
|
try {
|
|
10119
|
-
response = await fetch(`${this.host}${
|
|
10861
|
+
response = await fetch(`${this.host}${path17}`, {
|
|
10120
10862
|
method,
|
|
10121
10863
|
headers: {
|
|
10122
10864
|
Authorization: this.authHeader(),
|
|
@@ -10127,7 +10869,7 @@ var PersonasClient = class _PersonasClient {
|
|
|
10127
10869
|
});
|
|
10128
10870
|
} catch (error) {
|
|
10129
10871
|
const reason = error instanceof Error ? error.message : String(error);
|
|
10130
|
-
throw new PersonaError(`${method} ${
|
|
10872
|
+
throw new PersonaError(`${method} ${path17} failed: ${reason}`, {
|
|
10131
10873
|
cause: error
|
|
10132
10874
|
});
|
|
10133
10875
|
}
|
|
@@ -10135,10 +10877,10 @@ var PersonasClient = class _PersonasClient {
|
|
|
10135
10877
|
if (!response.ok) {
|
|
10136
10878
|
const detail = text2.slice(0, 500);
|
|
10137
10879
|
throw new PersonaError(
|
|
10138
|
-
`${method} ${
|
|
10880
|
+
`${method} ${path17} failed (${response.status}): ${detail}`
|
|
10139
10881
|
);
|
|
10140
10882
|
}
|
|
10141
|
-
this.log("%s %s -> %s", method,
|
|
10883
|
+
this.log("%s %s -> %s", method, path17, response.status);
|
|
10142
10884
|
return safeJson3(text2);
|
|
10143
10885
|
}
|
|
10144
10886
|
authHeader() {
|
|
@@ -10363,10 +11105,10 @@ var SessionRecording = class _SessionRecording {
|
|
|
10363
11105
|
};
|
|
10364
11106
|
}
|
|
10365
11107
|
/** Dump the full session as a JSON fixture (for regression tests). */
|
|
10366
|
-
toFixture(
|
|
10367
|
-
mkdirSync(dirname(
|
|
10368
|
-
writeFileSync(
|
|
10369
|
-
return
|
|
11108
|
+
toFixture(path17) {
|
|
11109
|
+
mkdirSync(dirname(path17), { recursive: true });
|
|
11110
|
+
writeFileSync(path17, JSON.stringify(this.toJSON(), null, 2), "utf-8");
|
|
11111
|
+
return path17;
|
|
10370
11112
|
}
|
|
10371
11113
|
static fromApi(raw) {
|
|
10372
11114
|
return new _SessionRecording({
|
|
@@ -11397,8 +12139,8 @@ var GatewaySecurity = class _GatewaySecurity {
|
|
|
11397
12139
|
);
|
|
11398
12140
|
}
|
|
11399
12141
|
}
|
|
11400
|
-
async postJson(
|
|
11401
|
-
const response = await fetch(`${this.host}${
|
|
12142
|
+
async postJson(path17, payload) {
|
|
12143
|
+
const response = await fetch(`${this.host}${path17}`, {
|
|
11402
12144
|
method: "POST",
|
|
11403
12145
|
headers: {
|
|
11404
12146
|
Authorization: this.authHeader(),
|
|
@@ -11409,7 +12151,7 @@ var GatewaySecurity = class _GatewaySecurity {
|
|
|
11409
12151
|
if (!response.ok) {
|
|
11410
12152
|
const body = await response.text();
|
|
11411
12153
|
throw new GatewaySecurityError(
|
|
11412
|
-
`Gateway API ${response.status} on ${
|
|
12154
|
+
`Gateway API ${response.status} on ${path17}: ${body || response.statusText}`
|
|
11413
12155
|
);
|
|
11414
12156
|
}
|
|
11415
12157
|
return await response.json();
|
|
@@ -11502,7 +12244,7 @@ __export(files_exports, {
|
|
|
11502
12244
|
init_worlds();
|
|
11503
12245
|
import { createHash as createHash10 } from "crypto";
|
|
11504
12246
|
import * as fs13 from "fs";
|
|
11505
|
-
import * as
|
|
12247
|
+
import * as path13 from "path";
|
|
11506
12248
|
import { Readable, Transform } from "stream";
|
|
11507
12249
|
import { pipeline } from "stream/promises";
|
|
11508
12250
|
var DRIVE_PREFIX = "drive:";
|
|
@@ -11553,7 +12295,7 @@ async function readFile2(options = {}, filePath, limits = {}) {
|
|
|
11553
12295
|
async function downloadFile(options = {}, filePath, outPath, onProgress) {
|
|
11554
12296
|
const file = await getFile(options, filePath);
|
|
11555
12297
|
const res = await openDownload(file.url);
|
|
11556
|
-
fs13.mkdirSync(
|
|
12298
|
+
fs13.mkdirSync(path13.dirname(path13.resolve(outPath)), { recursive: true });
|
|
11557
12299
|
const source = Readable.fromWeb(res.body);
|
|
11558
12300
|
await pipeline(source, counting((n) => onProgress?.(n, file.sizeBytes)), fs13.createWriteStream(outPath));
|
|
11559
12301
|
return { ...file, out: outPath };
|
|
@@ -11602,7 +12344,7 @@ var CONTENT_TYPES = {
|
|
|
11602
12344
|
".mp4": "video/mp4"
|
|
11603
12345
|
};
|
|
11604
12346
|
function contentTypeFor(name) {
|
|
11605
|
-
return CONTENT_TYPES[
|
|
12347
|
+
return CONTENT_TYPES[path13.extname(name).toLowerCase()] ?? "application/octet-stream";
|
|
11606
12348
|
}
|
|
11607
12349
|
function counting(report) {
|
|
11608
12350
|
let seen = 0;
|
|
@@ -13424,9 +14166,9 @@ function alternatives(raw) {
|
|
|
13424
14166
|
if (!parts2.length || parts2.includes("*")) return [];
|
|
13425
14167
|
return parts2;
|
|
13426
14168
|
}
|
|
13427
|
-
function hasPath(node,
|
|
14169
|
+
function hasPath(node, path17) {
|
|
13428
14170
|
let current = node;
|
|
13429
|
-
for (const part of
|
|
14171
|
+
for (const part of path17.split(".")) {
|
|
13430
14172
|
if (current && typeof current === "object" && !Array.isArray(current) && part in current) {
|
|
13431
14173
|
current = current[part];
|
|
13432
14174
|
continue;
|
|
@@ -13467,7 +14209,7 @@ function matches(m, event) {
|
|
|
13467
14209
|
if (m.args.length) {
|
|
13468
14210
|
const haystacks = event.event === "pre_request" || event.event === "post_response" ? [event.request?.query, event.request?.body] : [event.toolInput];
|
|
13469
14211
|
const present = haystacks.filter((h) => h !== void 0 && h !== null);
|
|
13470
|
-
if (!m.args.every((
|
|
14212
|
+
if (!m.args.every((path17) => present.some((h) => hasPath(h, path17))))
|
|
13471
14213
|
return false;
|
|
13472
14214
|
}
|
|
13473
14215
|
return true;
|
|
@@ -14303,7 +15045,7 @@ function parseHandler(event, raw, position) {
|
|
|
14303
15045
|
// src/hooks/handlers.ts
|
|
14304
15046
|
import { spawn as spawn3 } from "child_process";
|
|
14305
15047
|
import * as fs15 from "fs";
|
|
14306
|
-
import * as
|
|
15048
|
+
import * as path14 from "path";
|
|
14307
15049
|
import { pathToFileURL } from "url";
|
|
14308
15050
|
function parseStdout(text2, handler) {
|
|
14309
15051
|
const stripped = text2.trim();
|
|
@@ -14504,7 +15246,7 @@ var RecordHandler = class {
|
|
|
14504
15246
|
record.source = this.opts.source ?? null;
|
|
14505
15247
|
if (Array.isArray(this.sink)) this.sink.push(record);
|
|
14506
15248
|
else if (typeof this.sink === "string") {
|
|
14507
|
-
fs15.mkdirSync(
|
|
15249
|
+
fs15.mkdirSync(path14.dirname(this.sink), { recursive: true });
|
|
14508
15250
|
fs15.appendFileSync(this.sink, JSON.stringify(record) + "\n");
|
|
14509
15251
|
} else await this.sink(record);
|
|
14510
15252
|
return allow();
|
|
@@ -14715,7 +15457,7 @@ async function importCallable(target, cwd) {
|
|
|
14715
15457
|
const hash = target.lastIndexOf("#");
|
|
14716
15458
|
const modulePath = target.slice(0, hash);
|
|
14717
15459
|
const exportName = target.slice(hash + 1) || "default";
|
|
14718
|
-
const resolved = modulePath.startsWith(".") ||
|
|
15460
|
+
const resolved = modulePath.startsWith(".") || path14.isAbsolute(modulePath) ? pathToFileURL(path14.resolve(cwd, modulePath)).href : modulePath;
|
|
14719
15461
|
let module;
|
|
14720
15462
|
try {
|
|
14721
15463
|
module = await import(resolved);
|
|
@@ -14779,7 +15521,7 @@ async function buildHandler(spec, aliases, opts) {
|
|
|
14779
15521
|
|
|
14780
15522
|
// src/hooks/live.ts
|
|
14781
15523
|
import * as fs16 from "fs";
|
|
14782
|
-
import * as
|
|
15524
|
+
import * as path15 from "path";
|
|
14783
15525
|
var USER_AGENT = "gateway-hooks/1 (+https://withgateway.ai)";
|
|
14784
15526
|
var TAGS = /<(script|style)[^>]*>.*?<\/\1>/gis;
|
|
14785
15527
|
var STRIP = /<[^>]+>/g;
|
|
@@ -14799,13 +15541,13 @@ var Pacer = class {
|
|
|
14799
15541
|
/** Waits until the interval since the tool's last call has passed; resolves to the
|
|
14800
15542
|
* seconds waited. `sleep`/`clock` are injectable for tests. */
|
|
14801
15543
|
async wait(name, intervalMs, opts = {}) {
|
|
14802
|
-
const
|
|
15544
|
+
const sleep5 = opts.sleep ?? ((seconds) => new Promise((resolve11) => setTimeout(resolve11, seconds * 1e3)));
|
|
14803
15545
|
const clock = opts.clock ?? (() => Date.now() / 1e3);
|
|
14804
15546
|
const now = clock();
|
|
14805
15547
|
const due = (this.last.get(name) ?? -Infinity) + intervalMs / 1e3;
|
|
14806
15548
|
const waited = Math.max(0, due - now);
|
|
14807
15549
|
this.last.set(name, Math.max(now, due));
|
|
14808
|
-
if (waited) await
|
|
15550
|
+
if (waited) await sleep5(waited);
|
|
14809
15551
|
return Math.round(waited * 1e3) / 1e3;
|
|
14810
15552
|
}
|
|
14811
15553
|
};
|
|
@@ -15147,7 +15889,7 @@ var CallableTool = class _CallableTool {
|
|
|
15147
15889
|
}
|
|
15148
15890
|
};
|
|
15149
15891
|
function readConnection(root) {
|
|
15150
|
-
const file =
|
|
15892
|
+
const file = path15.join(root, "connector.toml");
|
|
15151
15893
|
if (!fs16.existsSync(file)) throw new Error(`no connector.toml at ${root}`);
|
|
15152
15894
|
const raw = parseToml(fs16.readFileSync(file, "utf8"));
|
|
15153
15895
|
const connector = raw.connector ?? {};
|
|
@@ -15163,7 +15905,7 @@ function readConnection(root) {
|
|
|
15163
15905
|
};
|
|
15164
15906
|
}
|
|
15165
15907
|
return {
|
|
15166
|
-
slug: connector.slug ??
|
|
15908
|
+
slug: connector.slug ?? path15.basename(root),
|
|
15167
15909
|
baseUrl: (connector.base_url ?? "").replace(/\/+$/, ""),
|
|
15168
15910
|
scheme: auth.scheme ?? "none",
|
|
15169
15911
|
...typeof auth.name === "string" ? { authName: auth.name } : {},
|
|
@@ -15180,8 +15922,8 @@ var ConnectorTool = class {
|
|
|
15180
15922
|
this.spec = spec;
|
|
15181
15923
|
this.live = live;
|
|
15182
15924
|
let location = spec.options.connector;
|
|
15183
|
-
if (!
|
|
15184
|
-
const root = fs16.existsSync(location) && fs16.statSync(location).isFile() ?
|
|
15925
|
+
if (!path15.isAbsolute(location)) location = path15.resolve(baseDir, location);
|
|
15926
|
+
const root = fs16.existsSync(location) && fs16.statSync(location).isFile() ? path15.dirname(location) : location;
|
|
15185
15927
|
try {
|
|
15186
15928
|
this.connection = readConnection(root);
|
|
15187
15929
|
} catch (error) {
|
|
@@ -15338,7 +16080,7 @@ var Recorder = class {
|
|
|
15338
16080
|
}
|
|
15339
16081
|
file;
|
|
15340
16082
|
write(line) {
|
|
15341
|
-
fs16.mkdirSync(
|
|
16083
|
+
fs16.mkdirSync(path15.dirname(this.file), { recursive: true });
|
|
15342
16084
|
fs16.appendFileSync(this.file, canonical2(line) + "\n");
|
|
15343
16085
|
}
|
|
15344
16086
|
};
|
|
@@ -15434,7 +16176,7 @@ var LiveTools = class _LiveTools {
|
|
|
15434
16176
|
...config.live.record ? { record: interpolatePath(config.live.record, run.runId, directory) } : {},
|
|
15435
16177
|
...config.live.replay ? { replay: interpolatePath(config.live.replay, run.runId, directory) } : {}
|
|
15436
16178
|
};
|
|
15437
|
-
return _LiveTools.create(run, live,
|
|
16179
|
+
return _LiveTools.create(run, live, path15.dirname(path15.resolve(file)));
|
|
15438
16180
|
}
|
|
15439
16181
|
/** The declared tools for a model. `openai`: `{type: "function", function: {name,
|
|
15440
16182
|
* description, parameters}}`; `anthropic`: `{name, description, input_schema}`. */
|
|
@@ -15761,7 +16503,7 @@ var RedactionAudit = class _RedactionAudit {
|
|
|
15761
16503
|
// src/hooks/run.ts
|
|
15762
16504
|
import { randomBytes as randomBytes3 } from "crypto";
|
|
15763
16505
|
import * as fs17 from "fs";
|
|
15764
|
-
import * as
|
|
16506
|
+
import * as path16 from "path";
|
|
15765
16507
|
var BLOCKING_EVENTS = [
|
|
15766
16508
|
"pre_tool_call",
|
|
15767
16509
|
"pre_request",
|
|
@@ -15812,12 +16554,12 @@ var HookRun = class _HookRun {
|
|
|
15812
16554
|
declaredOnly: options.declaredOnly ?? config.aliasDeclaredOnly
|
|
15813
16555
|
});
|
|
15814
16556
|
this.cwd = options.cwd ?? process.cwd();
|
|
15815
|
-
this.runDir = options.runDir ??
|
|
16557
|
+
this.runDir = options.runDir ?? path16.join(this.cwd, "runs", this.runId);
|
|
15816
16558
|
const chosen = options.legend !== void 0 ? options.legend : config.aliasLegend;
|
|
15817
|
-
this.legendPath = chosen ?
|
|
16559
|
+
this.legendPath = chosen ? path16.resolve(this.cwd, interpolatePath(chosen, this.runId, this.runDir)) : null;
|
|
15818
16560
|
this.sessionId = options.session;
|
|
15819
16561
|
this.source = options.source;
|
|
15820
|
-
this.configDir = config.source ?
|
|
16562
|
+
this.configDir = config.source ? path16.dirname(path16.resolve(config.source)) : this.cwd;
|
|
15821
16563
|
}
|
|
15822
16564
|
/** Build from a parsed config (an object in the file's shape, or a `HookConfig`);
|
|
15823
16565
|
* handlers are constructed now, so a callable that does not import fails here. */
|
|
@@ -16227,7 +16969,7 @@ var HookRun = class _HookRun {
|
|
|
16227
16969
|
throw new Error(
|
|
16228
16970
|
"no legend path: set [alias] legend, pass legend to the run, or give a path"
|
|
16229
16971
|
);
|
|
16230
|
-
fs17.mkdirSync(
|
|
16972
|
+
fs17.mkdirSync(path16.dirname(target), { recursive: true });
|
|
16231
16973
|
fs17.writeFileSync(target, JSON.stringify(this.legend(), null, 2) + "\n");
|
|
16232
16974
|
return target;
|
|
16233
16975
|
}
|
|
@@ -16324,14 +17066,14 @@ var HookedSession = class {
|
|
|
16324
17066
|
* `apiHeaders()`), `pre_request` before it and `post_response` after. Returns
|
|
16325
17067
|
* `{status, body, headers}`; a 4xx/5xx is returned, not thrown, so the agent sees
|
|
16326
17068
|
* the vendor's own error shape (rewritten like any result). */
|
|
16327
|
-
async request(method,
|
|
17069
|
+
async request(method, path17, opts = {}) {
|
|
16328
17070
|
if (!this.inner.api && !this.requestFn)
|
|
16329
17071
|
throw new Error(
|
|
16330
17072
|
"this session has no api surface (pass requestFn for a transport of your own)"
|
|
16331
17073
|
);
|
|
16332
17074
|
let request = {
|
|
16333
17075
|
method: method.toUpperCase(),
|
|
16334
|
-
path:
|
|
17076
|
+
path: path17,
|
|
16335
17077
|
query: { ...opts.query ?? {} },
|
|
16336
17078
|
body: opts.body ?? null
|
|
16337
17079
|
};
|
|
@@ -16803,6 +17545,8 @@ export {
|
|
|
16803
17545
|
GatewaySecurityError,
|
|
16804
17546
|
GatewayToolApprovalRequiredError,
|
|
16805
17547
|
GatewayToolBlockedError,
|
|
17548
|
+
GradePayload,
|
|
17549
|
+
GradeRefused,
|
|
16806
17550
|
HostedDryRunClient,
|
|
16807
17551
|
IDLE_WARNING_MINUTES,
|
|
16808
17552
|
KEY_NAMES,
|
|
@@ -16828,6 +17572,7 @@ export {
|
|
|
16828
17572
|
ReplayReport,
|
|
16829
17573
|
ReplaySuite,
|
|
16830
17574
|
ReplayTask,
|
|
17575
|
+
RetryPolicy,
|
|
16831
17576
|
SANDBOX_REQUEST_TIMEOUT_MS,
|
|
16832
17577
|
SECRET_KEY,
|
|
16833
17578
|
SESSION_STATES,
|
|
@@ -16837,6 +17582,7 @@ export {
|
|
|
16837
17582
|
SUCCESS_METRIC_NAME_KEY,
|
|
16838
17583
|
SUCCESS_SIGNAL_KEY,
|
|
16839
17584
|
SURFACE_KINDS,
|
|
17585
|
+
Score,
|
|
16840
17586
|
ScoreError,
|
|
16841
17587
|
ScoresClient,
|
|
16842
17588
|
Screen,
|
|
@@ -16845,6 +17591,7 @@ export {
|
|
|
16845
17591
|
SessionRecording,
|
|
16846
17592
|
SessionTrace,
|
|
16847
17593
|
StubMissError,
|
|
17594
|
+
TOOL_CONTRACT_UNREAD,
|
|
16848
17595
|
TRANSFORMS,
|
|
16849
17596
|
TaskEditClient,
|
|
16850
17597
|
TaskRun,
|
|
@@ -16860,14 +17607,17 @@ export {
|
|
|
16860
17607
|
WorldBrowser,
|
|
16861
17608
|
WorldCallTooLarge,
|
|
16862
17609
|
WorldEditClient,
|
|
17610
|
+
WorldNotice,
|
|
16863
17611
|
WorldRequestLog,
|
|
16864
17612
|
WorldSandboxClient,
|
|
16865
17613
|
WorldSession,
|
|
16866
17614
|
WorldSessionCallError,
|
|
17615
|
+
WorldSessionOpenFailed,
|
|
16867
17616
|
WorldSessionTimeout,
|
|
16868
17617
|
WorldSet,
|
|
16869
17618
|
WorldSurfaceUnavailable,
|
|
16870
17619
|
WorldTask,
|
|
17620
|
+
WorldToolsUnread,
|
|
16871
17621
|
addExperimentAttributes,
|
|
16872
17622
|
aggregateTaskGrade,
|
|
16873
17623
|
apiRequest,
|
|
@@ -16934,6 +17684,7 @@ export {
|
|
|
16934
17684
|
loadSession,
|
|
16935
17685
|
localTreeState,
|
|
16936
17686
|
memory,
|
|
17687
|
+
messageOf,
|
|
16937
17688
|
migrateProjectWorlds,
|
|
16938
17689
|
migrateWorld,
|
|
16939
17690
|
modelToolName,
|
|
@@ -16991,12 +17742,16 @@ export {
|
|
|
16991
17742
|
setExperimentContext,
|
|
16992
17743
|
shapeText,
|
|
16993
17744
|
snapshotTreeHashes,
|
|
17745
|
+
sqlRows,
|
|
17746
|
+
stillStartingHint,
|
|
16994
17747
|
storedForms,
|
|
16995
17748
|
success,
|
|
16996
17749
|
suite,
|
|
16997
17750
|
surfaceDescriptor,
|
|
16998
17751
|
surfaceKinds,
|
|
17752
|
+
taskGradeError,
|
|
16999
17753
|
taskLabel,
|
|
17754
|
+
taskRunFailure,
|
|
17000
17755
|
toolCallRecordsIn,
|
|
17001
17756
|
toolCallsFromObservations,
|
|
17002
17757
|
traces_exports as traces,
|