@withgateway/sdk 0.3.3 → 0.4.0
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 +2221 -962
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +2212 -953
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.js +81 -19
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +79 -17
- package/dist/files/index.mjs.map +1 -1
- package/dist/hooks/index.d.mts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +124 -11
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +124 -11
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/{index-C3UzD0G3.d.mts → index-CDPQBsU5.d.mts} +19 -3
- package/dist/{index-C3UzD0G3.d.ts → index-CDPQBsU5.d.ts} +19 -3
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +903 -221
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +868 -212
- package/dist/index.mjs.map +1 -1
- package/dist/traces/index.js +78 -16
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +76 -14
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.js +7 -1
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +7 -1
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/worlds/index.d.mts +692 -410
- package/dist/worlds/index.d.ts +692 -410
- package/dist/worlds/index.js +740 -197
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +736 -193
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +1 -1
- package/runtime/gatewaysdk/environment/_materialize.py +5 -25
- package/runtime/gatewaysdk/environment/_world.py +58 -65
- package/runtime/gatewaysdk/environment/backing.py +20 -24
- package/runtime/gatewaysdk/environment/core.py +1 -16
- package/runtime/gatewaysdk/environment/legacy_sqlite.py +14 -27
- package/runtime/gatewaysdk/environment/schema/admission.py +174 -0
- package/runtime/gatewaysdk/environment/schema/api.py +174 -471
- package/runtime/gatewaysdk/environment/schema/assertions.py +458 -0
- package/runtime/gatewaysdk/environment/schema/batch.py +3 -3
- package/runtime/gatewaysdk/environment/schema/cache_layout.py +5 -0
- package/runtime/gatewaysdk/environment/schema/call_capture.py +309 -0
- package/runtime/gatewaysdk/environment/schema/call_log.py +230 -18
- package/runtime/gatewaysdk/environment/schema/call_redaction.py +201 -19
- package/runtime/gatewaysdk/environment/schema/cast.py +15 -35
- package/runtime/gatewaysdk/environment/schema/conform.py +6 -27
- package/runtime/gatewaysdk/environment/schema/connector.py +89 -152
- package/runtime/gatewaysdk/environment/schema/connectors/confluence/connector.toml +1 -12
- package/runtime/gatewaysdk/environment/schema/connectors/github/connector.toml +1 -0
- package/runtime/gatewaysdk/environment/schema/connectors/servicenow/connector.toml +2 -5
- package/runtime/gatewaysdk/environment/schema/cors.py +54 -0
- package/runtime/gatewaysdk/environment/schema/credentials.py +313 -8
- package/runtime/gatewaysdk/environment/schema/data.py +14 -13
- package/runtime/gatewaysdk/environment/schema/database/base.py +106 -165
- package/runtime/gatewaysdk/environment/schema/database/guard.py +43 -36
- package/runtime/gatewaysdk/environment/schema/database/reads.py +169 -0
- package/runtime/gatewaysdk/environment/schema/database/sqlite.py +57 -31
- package/runtime/gatewaysdk/environment/schema/declared_routes.py +210 -0
- package/runtime/gatewaysdk/environment/schema/door.py +899 -0
- package/runtime/gatewaysdk/environment/schema/envelope.py +86 -28
- package/runtime/gatewaysdk/environment/schema/grading.py +58 -86
- package/runtime/gatewaysdk/environment/schema/handler_errors.py +25 -4
- package/runtime/gatewaysdk/environment/schema/host.py +229 -1695
- package/runtime/gatewaysdk/environment/schema/host_control.py +144 -0
- package/runtime/gatewaysdk/environment/schema/host_handoff.py +370 -0
- package/runtime/gatewaysdk/environment/schema/host_loops.py +97 -0
- package/runtime/gatewaysdk/environment/schema/host_owners.py +121 -0
- package/runtime/gatewaysdk/environment/schema/host_proxy.py +111 -0
- package/runtime/gatewaysdk/environment/schema/host_requests.py +6 -0
- package/runtime/gatewaysdk/environment/schema/host_session.py +126 -0
- package/runtime/gatewaysdk/environment/schema/host_surfaces.py +79 -21
- package/runtime/gatewaysdk/environment/schema/host_transfers.py +127 -0
- package/runtime/gatewaysdk/environment/schema/host_versions.py +242 -0
- package/runtime/gatewaysdk/environment/schema/host_workers.py +577 -0
- package/runtime/gatewaysdk/environment/schema/journal.py +437 -0
- package/runtime/gatewaysdk/environment/schema/ledger_spill.py +828 -0
- package/runtime/gatewaysdk/environment/schema/local.py +31 -116
- package/runtime/gatewaysdk/environment/schema/platform.py +15 -17
- package/runtime/gatewaysdk/environment/schema/request_body.py +238 -0
- package/runtime/gatewaysdk/environment/schema/request_ledger.py +958 -0
- package/runtime/gatewaysdk/environment/schema/route_bindings.py +25 -3
- package/runtime/gatewaysdk/environment/schema/route_miss.py +54 -0
- package/runtime/gatewaysdk/environment/schema/runtime.py +129 -176
- package/runtime/gatewaysdk/environment/schema/session_files.py +133 -24
- package/runtime/gatewaysdk/environment/schema/session_move.py +275 -0
- package/runtime/gatewaysdk/environment/schema/skills/agents/connector-template-author.md +5 -1
- package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +8 -9
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +31 -6
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/ROWS.md +12 -8
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +13 -13
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +23 -23
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +11 -6
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +35 -2
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/journal-checks.md +182 -0
- package/runtime/gatewaysdk/environment/schema/snapshot.py +149 -29
- package/runtime/gatewaysdk/environment/schema/spill_files.py +228 -0
- package/runtime/gatewaysdk/environment/schema/tasks.py +229 -323
- package/runtime/gatewaysdk/environment/schema/tools_world.py +84 -203
- package/runtime/gatewaysdk/environment/schema/validation.py +69 -1
- package/runtime/gatewaysdk/environment/schema/verbs.py +32 -36
- package/runtime/gatewaysdk/environment/schema/worker.py +6 -4
- package/runtime/gatewaysdk/environment/schema/workers.py +203 -39
- package/runtime/gatewaysdk/environment/schema/world_host.py +953 -0
- package/runtime/gatewaysdk/environment/schema/world_tests.py +9 -11
- package/runtime/gatewaysdk/environment/world.py +1 -1
- package/runtime/gatewaysdk/environment/world_session_contract.py +14 -0
- package/skills/agents/connector-template-author.md +5 -1
- package/skills/benchmarks-getting-started/SKILL.md +8 -9
- package/skills/connector-schema-authoring/SKILL.md +31 -6
- package/skills/connector-schema-authoring/connector-worlds.md +129 -7
- package/skills/world-data-ingestion/ROWS.md +12 -8
- package/skills/world-data-ingestion/SKILL.md +13 -13
- package/skills/worlds-getting-started/SKILL.md +23 -23
- package/skills/worlds-getting-started/references/cli-mcp-map.md +11 -6
- package/skills/worlds-getting-started/references/gotchas.md +35 -2
- package/skills/worlds-getting-started/references/journal-checks.md +182 -0
package/dist/worlds/index.mjs
CHANGED
|
@@ -58,7 +58,7 @@ function platformTimeoutMs(env = process.env) {
|
|
|
58
58
|
if (Number.isInteger(value) && value > 0) return value;
|
|
59
59
|
throw new Error(`${PLATFORM_TIMEOUT_ENV} must be a positive whole number of milliseconds, not \`${raw}\`.`);
|
|
60
60
|
}
|
|
61
|
-
var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, sleep, RetryPolicy, Attempt, PlatformTransport;
|
|
61
|
+
var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, FETCH_LIMIT, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, sleep, RetryPolicy, Attempt, PlatformTransport;
|
|
62
62
|
var init_transport = __esm({
|
|
63
63
|
"src/worlds/transport.ts"() {
|
|
64
64
|
"use strict";
|
|
@@ -66,7 +66,13 @@ var init_transport = __esm({
|
|
|
66
66
|
PLATFORM_TIMEOUT_DEFAULT_MS = 12e4;
|
|
67
67
|
CHECK_HOST = "Check GATEWAY_HOST (or --host) points at a running platform, then retry.";
|
|
68
68
|
RETRY = "Retry; if it repeats, check the network between here and the platform.";
|
|
69
|
+
FETCH_LIMIT = {
|
|
70
|
+
reason: "Node's fetch stopped waiting after 300 s",
|
|
71
|
+
next: "The platform may still be running it: check what it changed before you retry."
|
|
72
|
+
};
|
|
69
73
|
CAUSES = {
|
|
74
|
+
UND_ERR_HEADERS_TIMEOUT: FETCH_LIMIT,
|
|
75
|
+
UND_ERR_BODY_TIMEOUT: FETCH_LIMIT,
|
|
70
76
|
ECONNREFUSED: { reason: "connection refused", next: CHECK_HOST },
|
|
71
77
|
ENOTFOUND: { reason: "DNS lookup failed", next: CHECK_HOST },
|
|
72
78
|
EAI_AGAIN: { reason: "DNS lookup failed", next: CHECK_HOST },
|
|
@@ -366,6 +372,12 @@ var init_browserReconnect = __esm({
|
|
|
366
372
|
});
|
|
367
373
|
|
|
368
374
|
// src/worlds/browser.ts
|
|
375
|
+
function assertSessionAuthMode(value) {
|
|
376
|
+
if (SESSION_AUTH_MODES.includes(value)) return;
|
|
377
|
+
throw new Error(
|
|
378
|
+
`Unknown session auth: ${String(value)}; choose from ${SESSION_AUTH_MODES.join(", ")}`
|
|
379
|
+
);
|
|
380
|
+
}
|
|
369
381
|
function assertBrowserTier(value) {
|
|
370
382
|
if (BROWSER_TIERS.includes(value)) return;
|
|
371
383
|
throw new Error(
|
|
@@ -402,6 +414,15 @@ function splitHash(url) {
|
|
|
402
414
|
const h = url.indexOf("#");
|
|
403
415
|
return h < 0 ? [url, ""] : [url.slice(0, h), url.slice(h)];
|
|
404
416
|
}
|
|
417
|
+
function capabilityLabel(url) {
|
|
418
|
+
let host = "";
|
|
419
|
+
try {
|
|
420
|
+
host = url ? new URL(url).hostname : "";
|
|
421
|
+
} catch {
|
|
422
|
+
return null;
|
|
423
|
+
}
|
|
424
|
+
return CAPABILITY_HOST.exec(host)?.[1] ?? null;
|
|
425
|
+
}
|
|
405
426
|
function redactActionArgs(action, args) {
|
|
406
427
|
const secretField = action === "browser_type" && SECRET_KEY.test(String(args.selector ?? ""));
|
|
407
428
|
const out = {};
|
|
@@ -461,7 +482,9 @@ async function openBrowser(surfaces, opts = {}) {
|
|
|
461
482
|
};
|
|
462
483
|
const scrubber = new SecretScrubber([
|
|
463
484
|
surfaces.browser?.wsUrl,
|
|
464
|
-
surfaces.ui?.token
|
|
485
|
+
surfaces.ui?.token,
|
|
486
|
+
capabilityLabel(surfaces.ui?.url),
|
|
487
|
+
capabilityLabel(surfaces.api?.url)
|
|
465
488
|
]);
|
|
466
489
|
const reconnector = mode === "hosted" && surfaces.browser.protocol === "cdp" && opts.repair ? new BrowserReconnector(opts.repair, reattach, {
|
|
467
490
|
scrub: (text2) => scrubber.scrub(text2)
|
|
@@ -526,13 +549,15 @@ function computerUseToolkit(browser, opts = {}) {
|
|
|
526
549
|
specs
|
|
527
550
|
};
|
|
528
551
|
}
|
|
529
|
-
var SURFACE_KINDS, BROWSER_TIERS, DEFAULT_VIEWPORT, SETTLE_TIMEOUT_MS, SETTLE_QUIET_MS, SETTLE_POLL_MS, EVENT_BATCH_SIZE, EVENT_FLUSH_INTERVAL_MS, EVENT_MAX_RETRIES, EVENT_SCREENSHOT_QUALITY, EVENT_MAX_STRING, SECRET_KEY, SECRET_VALUE, WorldSurfaceUnavailable, UI_TOKEN_QUERY, BrowserActionRecorder, WorldBrowser, COMPUTER_USE_SPECS, str;
|
|
552
|
+
var SURFACE_KINDS, PLATFORM_SESSION_HEADER, SESSION_AUTH_MODES, BROWSER_TIERS, DEFAULT_VIEWPORT, SETTLE_TIMEOUT_MS, SETTLE_QUIET_MS, SETTLE_POLL_MS, EVENT_BATCH_SIZE, EVENT_FLUSH_INTERVAL_MS, EVENT_MAX_RETRIES, EVENT_SCREENSHOT_QUALITY, EVENT_MAX_STRING, SECRET_KEY, SECRET_VALUE, WorldSurfaceUnavailable, UI_TOKEN_QUERY, CAPABILITY_HOST, BrowserActionRecorder, WorldBrowser, COMPUTER_USE_SPECS, str;
|
|
530
553
|
var init_browser = __esm({
|
|
531
554
|
"src/worlds/browser.ts"() {
|
|
532
555
|
"use strict";
|
|
533
556
|
init_session2();
|
|
534
557
|
init_browserReconnect();
|
|
535
558
|
SURFACE_KINDS = ["tools", "api", "ui", "browser"];
|
|
559
|
+
PLATFORM_SESSION_HEADER = "X-World-Session";
|
|
560
|
+
SESSION_AUTH_MODES = ["vendor", "open"];
|
|
536
561
|
BROWSER_TIERS = ["standard", "premium"];
|
|
537
562
|
DEFAULT_VIEWPORT = { width: 1280, height: 800 };
|
|
538
563
|
SETTLE_TIMEOUT_MS = 5e3;
|
|
@@ -553,6 +578,7 @@ var init_browser = __esm({
|
|
|
553
578
|
surface;
|
|
554
579
|
};
|
|
555
580
|
UI_TOKEN_QUERY = "token";
|
|
581
|
+
CAPABILITY_HOST = /^o-[a-z0-9]+-([a-z2-7]{26})(?:-api)?\./;
|
|
556
582
|
BrowserActionRecorder = class {
|
|
557
583
|
constructor(post, agentId, opts = {}) {
|
|
558
584
|
this.post = post;
|
|
@@ -645,7 +671,10 @@ var init_browser = __esm({
|
|
|
645
671
|
}
|
|
646
672
|
};
|
|
647
673
|
WorldBrowser = class {
|
|
648
|
-
constructor(page, ui, mode, teardown, viewport = DEFAULT_VIEWPORT, recorder = null, reconnector = null, scrubber = new SecretScrubber([
|
|
674
|
+
constructor(page, ui, mode, teardown, viewport = DEFAULT_VIEWPORT, recorder = null, reconnector = null, scrubber = new SecretScrubber([
|
|
675
|
+
ui?.token,
|
|
676
|
+
capabilityLabel(ui?.url)
|
|
677
|
+
])) {
|
|
649
678
|
this.ui = ui;
|
|
650
679
|
this.mode = mode;
|
|
651
680
|
this.teardown = teardown;
|
|
@@ -782,7 +811,15 @@ var init_browser = __esm({
|
|
|
782
811
|
seq: recorder.nextSeq(),
|
|
783
812
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
784
813
|
action,
|
|
785
|
-
args: redactActionArgs(
|
|
814
|
+
args: redactActionArgs(
|
|
815
|
+
action,
|
|
816
|
+
Object.fromEntries(
|
|
817
|
+
Object.entries(args).map(([key, value]) => [
|
|
818
|
+
key,
|
|
819
|
+
typeof value === "string" ? this.scrubber.scrub(value) : value
|
|
820
|
+
])
|
|
821
|
+
)
|
|
822
|
+
),
|
|
786
823
|
ok: failure === null,
|
|
787
824
|
error,
|
|
788
825
|
durationMs: Date.now() - started,
|
|
@@ -798,8 +835,8 @@ var init_browser = __esm({
|
|
|
798
835
|
screenshot: null
|
|
799
836
|
};
|
|
800
837
|
try {
|
|
801
|
-
out.url = this.page.url();
|
|
802
|
-
out.title = await this.page.title();
|
|
838
|
+
out.url = this.scrubber.scrub(this.page.url());
|
|
839
|
+
out.title = this.scrubber.scrub(await this.page.title());
|
|
803
840
|
const jpeg = await this.page.screenshot({
|
|
804
841
|
type: "jpeg",
|
|
805
842
|
quality: EVENT_SCREENSHOT_QUALITY
|
|
@@ -2243,13 +2280,16 @@ function idleWarning(idleExpiresAt, now = /* @__PURE__ */ new Date()) {
|
|
|
2243
2280
|
const minutes = Math.max(0, Math.floor(leftMs / 6e4));
|
|
2244
2281
|
return `warning: session expires in ${minutes}m (idle TTL); call a tool to extend it or \`gateway worlds session pin\` to keep it`;
|
|
2245
2282
|
}
|
|
2246
|
-
var CALL_BODY_LIMIT_BYTES, CALL_BODY_LIMIT_LABEL, IDLE_WARNING_MINUTES, EXPLORATORY_TASK, EXPLORATORY_TASK_SOURCE, NO_GRADER_REASON, WorldCallTooLarge, stillStartingHint;
|
|
2283
|
+
var CALL_BODY_LIMIT_BYTES, CALL_BODY_LIMIT_LABEL, IDLE_WARNING_MINUTES, REQUEST_LOG_PAGE_MAX, REQUEST_BODY_CAPTURE_BYTES, REQUESTS_NOT_RECORDED, EXPLORATORY_TASK, EXPLORATORY_TASK_SOURCE, NO_GRADER_REASON, WorldCallTooLarge, stillStartingHint;
|
|
2247
2284
|
var init_sessionContract = __esm({
|
|
2248
2285
|
"src/worlds/sessionContract.ts"() {
|
|
2249
2286
|
"use strict";
|
|
2250
2287
|
CALL_BODY_LIMIT_BYTES = 4 * 1024 * 1024;
|
|
2251
2288
|
CALL_BODY_LIMIT_LABEL = "4mb";
|
|
2252
2289
|
IDLE_WARNING_MINUTES = 5;
|
|
2290
|
+
REQUEST_LOG_PAGE_MAX = 200;
|
|
2291
|
+
REQUEST_BODY_CAPTURE_BYTES = 64 * 1024;
|
|
2292
|
+
REQUESTS_NOT_RECORDED = "requests_not_recorded";
|
|
2253
2293
|
EXPLORATORY_TASK = Object.freeze({
|
|
2254
2294
|
instruction: "exploratory session"
|
|
2255
2295
|
});
|
|
@@ -2283,6 +2323,217 @@ var init_sessionContract = __esm({
|
|
|
2283
2323
|
}
|
|
2284
2324
|
});
|
|
2285
2325
|
|
|
2326
|
+
// src/worlds/toolSchema.ts
|
|
2327
|
+
function schemaFromSignature(spec) {
|
|
2328
|
+
if (spec.inputSchema)
|
|
2329
|
+
return {
|
|
2330
|
+
type: "function",
|
|
2331
|
+
function: {
|
|
2332
|
+
name: modelToolName(spec.name),
|
|
2333
|
+
description: spec.doc ?? spec.name,
|
|
2334
|
+
parameters: spec.inputSchema
|
|
2335
|
+
}
|
|
2336
|
+
};
|
|
2337
|
+
const inside = /\(([\s\S]*)\)\s*$/.exec(spec.signature.trim())?.[1] ?? "";
|
|
2338
|
+
const properties = {};
|
|
2339
|
+
const required2 = [];
|
|
2340
|
+
const params = [];
|
|
2341
|
+
let depth = 0;
|
|
2342
|
+
let current = "";
|
|
2343
|
+
for (const ch of inside) {
|
|
2344
|
+
if ("([{".includes(ch)) depth++;
|
|
2345
|
+
if (")]}".includes(ch)) depth--;
|
|
2346
|
+
if (ch === "," && depth === 0) {
|
|
2347
|
+
params.push(current);
|
|
2348
|
+
current = "";
|
|
2349
|
+
} else current += ch;
|
|
2350
|
+
}
|
|
2351
|
+
if (current.trim()) params.push(current);
|
|
2352
|
+
for (const raw of params) {
|
|
2353
|
+
const param = raw.trim();
|
|
2354
|
+
if (!param || param.startsWith("*") || param === "self") continue;
|
|
2355
|
+
const eq = param.indexOf("=");
|
|
2356
|
+
const name = (eq === -1 ? param : param.slice(0, eq)).split(":")[0].trim();
|
|
2357
|
+
if (!name) continue;
|
|
2358
|
+
if (eq === -1) {
|
|
2359
|
+
properties[name] = { type: "string" };
|
|
2360
|
+
required2.push(name);
|
|
2361
|
+
continue;
|
|
2362
|
+
}
|
|
2363
|
+
const value = param.slice(eq + 1).trim();
|
|
2364
|
+
if (/^-?\d+(\.\d+)?$/.test(value)) properties[name] = { type: "number" };
|
|
2365
|
+
else if (value === "True" || value === "False")
|
|
2366
|
+
properties[name] = { type: "boolean" };
|
|
2367
|
+
else properties[name] = { type: "string" };
|
|
2368
|
+
}
|
|
2369
|
+
return {
|
|
2370
|
+
type: "function",
|
|
2371
|
+
function: {
|
|
2372
|
+
name: modelToolName(spec.name),
|
|
2373
|
+
description: spec.doc ?? spec.name,
|
|
2374
|
+
parameters: { type: "object", properties, required: required2 }
|
|
2375
|
+
}
|
|
2376
|
+
};
|
|
2377
|
+
}
|
|
2378
|
+
var modelToolName;
|
|
2379
|
+
var init_toolSchema = __esm({
|
|
2380
|
+
"src/worlds/toolSchema.ts"() {
|
|
2381
|
+
"use strict";
|
|
2382
|
+
modelToolName = (name) => name.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 64) || "tool";
|
|
2383
|
+
}
|
|
2384
|
+
});
|
|
2385
|
+
|
|
2386
|
+
// src/worlds/requestLedger.ts
|
|
2387
|
+
function platformMessage(text2) {
|
|
2388
|
+
try {
|
|
2389
|
+
const { message } = JSON.parse(text2);
|
|
2390
|
+
return typeof message === "string" ? message : null;
|
|
2391
|
+
} catch {
|
|
2392
|
+
return null;
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
var WORLD_REQUEST_VIAS, WorldRequestFilterError, NOT_RECORDED, WorldRequestsNotRecorded, STATUS, INSTANT, WORLDS, SESSIONS, Instant, WorldRequestQuery, WorldRequestLedger;
|
|
2396
|
+
var init_requestLedger = __esm({
|
|
2397
|
+
"src/worlds/requestLedger.ts"() {
|
|
2398
|
+
"use strict";
|
|
2399
|
+
init_worlds();
|
|
2400
|
+
init_sessionContract();
|
|
2401
|
+
WORLD_REQUEST_VIAS = ["api", "ui", "tool"];
|
|
2402
|
+
WorldRequestFilterError = class extends Error {
|
|
2403
|
+
};
|
|
2404
|
+
NOT_RECORDED = "This session's engine records no requests; only hosted World Host sessions do.";
|
|
2405
|
+
WorldRequestsNotRecorded = class _WorldRequestsNotRecorded extends Error {
|
|
2406
|
+
static from(error) {
|
|
2407
|
+
if (!(error instanceof ApiError) || error.code !== REQUESTS_NOT_RECORDED) return error;
|
|
2408
|
+
return new _WorldRequestsNotRecorded(platformMessage(error.text) || NOT_RECORDED);
|
|
2409
|
+
}
|
|
2410
|
+
static async mapped(read) {
|
|
2411
|
+
try {
|
|
2412
|
+
return await read;
|
|
2413
|
+
} catch (error) {
|
|
2414
|
+
throw _WorldRequestsNotRecorded.from(error);
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
};
|
|
2418
|
+
STATUS = /^(?:[1-5]\d\d|[1-5]xx)$/;
|
|
2419
|
+
INSTANT = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
2420
|
+
WORLDS = "/api/public/worlds";
|
|
2421
|
+
SESSIONS = "/api/public/world-sessions";
|
|
2422
|
+
Instant = class _Instant {
|
|
2423
|
+
static parse(flag, raw) {
|
|
2424
|
+
const match = INSTANT.exec(raw);
|
|
2425
|
+
const millis = match ? _Instant.fromParts(match) : null;
|
|
2426
|
+
if (millis === null)
|
|
2427
|
+
throw new WorldRequestFilterError(
|
|
2428
|
+
`--${flag} must be an ISO 8601 date or time (2026-10-05, 2026-10-05T14:30:00Z), not \`${raw}\`.`
|
|
2429
|
+
);
|
|
2430
|
+
return millis;
|
|
2431
|
+
}
|
|
2432
|
+
static fromParts(match) {
|
|
2433
|
+
const [year, month, day, hour, minute, second] = [1, 2, 3, 4, 5, 6].map((i) => Number(match[i] ?? 0));
|
|
2434
|
+
const offset = _Instant.offsetMinutes(match[8]);
|
|
2435
|
+
if (offset === null || year < 1 || hour > 23 || minute > 59 || second > 59) return null;
|
|
2436
|
+
const date = /* @__PURE__ */ new Date(0);
|
|
2437
|
+
date.setUTCFullYear(year, month - 1, day);
|
|
2438
|
+
if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month - 1 || date.getUTCDate() !== day) return null;
|
|
2439
|
+
date.setUTCHours(hour, minute, second, Number((match[7] ?? "").padEnd(3, "0")));
|
|
2440
|
+
const utc = date.getTime() - offset * 6e4;
|
|
2441
|
+
const utcYear = new Date(utc).getUTCFullYear();
|
|
2442
|
+
return utcYear < 1 || utcYear > 9999 ? null : utc;
|
|
2443
|
+
}
|
|
2444
|
+
static offsetMinutes(zone) {
|
|
2445
|
+
if (zone === void 0 || zone === "Z") return 0;
|
|
2446
|
+
const hours = Number(zone.slice(1, 3));
|
|
2447
|
+
const minutes = Number(zone.slice(4, 6));
|
|
2448
|
+
if (hours > 23 || minutes > 59) return null;
|
|
2449
|
+
return (zone.startsWith("-") ? -1 : 1) * (hours * 60 + minutes);
|
|
2450
|
+
}
|
|
2451
|
+
};
|
|
2452
|
+
WorldRequestQuery = class _WorldRequestQuery {
|
|
2453
|
+
constructor(entries) {
|
|
2454
|
+
this.entries = entries;
|
|
2455
|
+
}
|
|
2456
|
+
entries;
|
|
2457
|
+
static parse(filter = {}) {
|
|
2458
|
+
const via = _WorldRequestQuery.via(filter.via);
|
|
2459
|
+
const status = _WorldRequestQuery.status(filter.status);
|
|
2460
|
+
const since = filter.since === void 0 ? void 0 : Instant.parse("since", filter.since);
|
|
2461
|
+
const until = filter.until === void 0 ? void 0 : Instant.parse("until", filter.until);
|
|
2462
|
+
if (since !== void 0 && until !== void 0 && since > until)
|
|
2463
|
+
throw new WorldRequestFilterError("--since must not be after --until.");
|
|
2464
|
+
const values = [
|
|
2465
|
+
["session", filter.session],
|
|
2466
|
+
["version", filter.version],
|
|
2467
|
+
["via", via],
|
|
2468
|
+
["operation", filter.operation],
|
|
2469
|
+
["status", status],
|
|
2470
|
+
["since", since === void 0 ? void 0 : new Date(since).toISOString()],
|
|
2471
|
+
["until", until === void 0 ? void 0 : new Date(until).toISOString()],
|
|
2472
|
+
["limit", filter.limit === void 0 ? void 0 : String(filter.limit)],
|
|
2473
|
+
["cursor", filter.cursor]
|
|
2474
|
+
];
|
|
2475
|
+
return new _WorldRequestQuery(values.filter((entry) => entry[1] !== void 0));
|
|
2476
|
+
}
|
|
2477
|
+
static via(value) {
|
|
2478
|
+
if (value === void 0) return void 0;
|
|
2479
|
+
const lower = value.toLowerCase();
|
|
2480
|
+
if (WORLD_REQUEST_VIAS.includes(lower)) return lower;
|
|
2481
|
+
throw new WorldRequestFilterError(`--via must be one of ${WORLD_REQUEST_VIAS.join(", ")}, not \`${value}\`.`);
|
|
2482
|
+
}
|
|
2483
|
+
static status(value) {
|
|
2484
|
+
if (value === void 0) return void 0;
|
|
2485
|
+
const lower = value.toLowerCase();
|
|
2486
|
+
if (STATUS.test(lower)) return lower;
|
|
2487
|
+
throw new WorldRequestFilterError(`--status must be a code (200) or a class (2xx), not \`${value}\`.`);
|
|
2488
|
+
}
|
|
2489
|
+
get filtered() {
|
|
2490
|
+
return this.entries.some(([key]) => key !== "limit");
|
|
2491
|
+
}
|
|
2492
|
+
params() {
|
|
2493
|
+
return this.entries.map(([key, value]) => [key, value]);
|
|
2494
|
+
}
|
|
2495
|
+
search() {
|
|
2496
|
+
return this.entries.length ? `?${new URLSearchParams(this.entries).toString()}` : "";
|
|
2497
|
+
}
|
|
2498
|
+
};
|
|
2499
|
+
WorldRequestLedger = class {
|
|
2500
|
+
constructor(options = {}) {
|
|
2501
|
+
this.options = options;
|
|
2502
|
+
}
|
|
2503
|
+
options;
|
|
2504
|
+
/** A page of the world's requests, newest first; `nextCursor` reads the page after it. Narrowed to a session
|
|
2505
|
+
* whose engine records none: `WorldRequestsNotRecorded`. */
|
|
2506
|
+
list(slug, query = WorldRequestQuery.parse()) {
|
|
2507
|
+
return WorldRequestsNotRecorded.mapped(
|
|
2508
|
+
apiRequest(
|
|
2509
|
+
this.options,
|
|
2510
|
+
"GET",
|
|
2511
|
+
`${WORLDS}/${encodeURIComponent(slug)}/requests${query.search()}`
|
|
2512
|
+
)
|
|
2513
|
+
);
|
|
2514
|
+
}
|
|
2515
|
+
/** One of the world's requests, with its headers and bodies. */
|
|
2516
|
+
get(slug, requestId) {
|
|
2517
|
+
return apiRequest(
|
|
2518
|
+
this.options,
|
|
2519
|
+
"GET",
|
|
2520
|
+
`${WORLDS}/${encodeURIComponent(slug)}/requests/${encodeURIComponent(requestId)}`
|
|
2521
|
+
);
|
|
2522
|
+
}
|
|
2523
|
+
/** A page of one session's requests, newest first; `WorldRequestsNotRecorded` when its engine records none. */
|
|
2524
|
+
forSession(sessionId, query = WorldRequestQuery.parse()) {
|
|
2525
|
+
return WorldRequestsNotRecorded.mapped(
|
|
2526
|
+
apiRequest(
|
|
2527
|
+
this.options,
|
|
2528
|
+
"GET",
|
|
2529
|
+
`${SESSIONS}/${encodeURIComponent(sessionId)}/requests${query.search()}`
|
|
2530
|
+
)
|
|
2531
|
+
);
|
|
2532
|
+
}
|
|
2533
|
+
};
|
|
2534
|
+
}
|
|
2535
|
+
});
|
|
2536
|
+
|
|
2286
2537
|
// src/worlds/sessionReadiness.ts
|
|
2287
2538
|
var READY_TIMEOUT_MS, READY_POLL_MS, sleep2, WorldSessionTimeout, WorldSessionCallError, WorldSessionOpenFailed, ENDED, SessionReadiness;
|
|
2288
2539
|
var init_sessionReadiness = __esm({
|
|
@@ -2622,57 +2873,6 @@ __export(session_exports2, {
|
|
|
2622
2873
|
taskLabel: () => taskLabel
|
|
2623
2874
|
});
|
|
2624
2875
|
import { randomUUID } from "crypto";
|
|
2625
|
-
function schemaFromSignature(spec) {
|
|
2626
|
-
if (spec.inputSchema)
|
|
2627
|
-
return {
|
|
2628
|
-
type: "function",
|
|
2629
|
-
function: {
|
|
2630
|
-
name: modelToolName(spec.name),
|
|
2631
|
-
description: spec.doc ?? spec.name,
|
|
2632
|
-
parameters: spec.inputSchema
|
|
2633
|
-
}
|
|
2634
|
-
};
|
|
2635
|
-
const inside = /\(([\s\S]*)\)\s*$/.exec(spec.signature.trim())?.[1] ?? "";
|
|
2636
|
-
const properties = {};
|
|
2637
|
-
const required2 = [];
|
|
2638
|
-
const params = [];
|
|
2639
|
-
let depth = 0;
|
|
2640
|
-
let current = "";
|
|
2641
|
-
for (const ch of inside) {
|
|
2642
|
-
if ("([{".includes(ch)) depth++;
|
|
2643
|
-
if (")]}".includes(ch)) depth--;
|
|
2644
|
-
if (ch === "," && depth === 0) {
|
|
2645
|
-
params.push(current);
|
|
2646
|
-
current = "";
|
|
2647
|
-
} else current += ch;
|
|
2648
|
-
}
|
|
2649
|
-
if (current.trim()) params.push(current);
|
|
2650
|
-
for (const raw of params) {
|
|
2651
|
-
const param = raw.trim();
|
|
2652
|
-
if (!param || param.startsWith("*") || param === "self") continue;
|
|
2653
|
-
const eq = param.indexOf("=");
|
|
2654
|
-
const name = (eq === -1 ? param : param.slice(0, eq)).split(":")[0].trim();
|
|
2655
|
-
if (!name) continue;
|
|
2656
|
-
if (eq === -1) {
|
|
2657
|
-
properties[name] = { type: "string" };
|
|
2658
|
-
required2.push(name);
|
|
2659
|
-
continue;
|
|
2660
|
-
}
|
|
2661
|
-
const value = param.slice(eq + 1).trim();
|
|
2662
|
-
if (/^-?\d+(\.\d+)?$/.test(value)) properties[name] = { type: "number" };
|
|
2663
|
-
else if (value === "True" || value === "False")
|
|
2664
|
-
properties[name] = { type: "boolean" };
|
|
2665
|
-
else properties[name] = { type: "string" };
|
|
2666
|
-
}
|
|
2667
|
-
return {
|
|
2668
|
-
type: "function",
|
|
2669
|
-
function: {
|
|
2670
|
-
name: modelToolName(spec.name),
|
|
2671
|
-
description: spec.doc ?? spec.name,
|
|
2672
|
-
parameters: { type: "object", properties, required: required2 }
|
|
2673
|
-
}
|
|
2674
|
-
};
|
|
2675
|
-
}
|
|
2676
2876
|
async function attachSession(sessionId, options = {}) {
|
|
2677
2877
|
const state2 = await apiRequest(
|
|
2678
2878
|
options,
|
|
@@ -2693,6 +2893,7 @@ async function openSession(slugOrRef, taskOrOpts = {}, positionalOpts = {}) {
|
|
|
2693
2893
|
`Unknown world surfaces: ${unknown.join(", ")}; choose from ${SURFACE_KINDS.join(", ")}`
|
|
2694
2894
|
);
|
|
2695
2895
|
if (opts.browserTier !== void 0) assertBrowserTier(opts.browserTier);
|
|
2896
|
+
if (opts.auth !== void 0) assertSessionAuthMode(opts.auth);
|
|
2696
2897
|
const at = slugOrRef.indexOf("@");
|
|
2697
2898
|
const slug = at === -1 ? slugOrRef : slugOrRef.slice(0, at);
|
|
2698
2899
|
const ref = at === -1 ? "" : slugOrRef.slice(at + 1);
|
|
@@ -2705,7 +2906,8 @@ async function openSession(slugOrRef, taskOrOpts = {}, positionalOpts = {}) {
|
|
|
2705
2906
|
...task === void 0 ? {} : { task },
|
|
2706
2907
|
...opts.reuseWarm === void 0 ? {} : { reuseWarm: opts.reuseWarm },
|
|
2707
2908
|
...opts.surfaces?.length ? { surfaces: opts.surfaces } : {},
|
|
2708
|
-
...opts.browserTier === void 0 ? {} : { browserTier: opts.browserTier }
|
|
2909
|
+
...opts.browserTier === void 0 ? {} : { browserTier: opts.browserTier },
|
|
2910
|
+
...opts.auth === void 0 ? {} : { auth: opts.auth }
|
|
2709
2911
|
}
|
|
2710
2912
|
);
|
|
2711
2913
|
return new WorldSession(state2.sessionId, state2, options);
|
|
@@ -2786,7 +2988,7 @@ async function runSessions(opts) {
|
|
|
2786
2988
|
passed: failed === 0 && (opts.failUnder === void 0 || mean >= opts.failUnder)
|
|
2787
2989
|
};
|
|
2788
2990
|
}
|
|
2789
|
-
var CALL_TIMEOUT_MS, CALL_POLL_MS, JUDGED_GRADE_TIMEOUT_MS, JUDGED_GRADE_POLL_MS, EXPORT_PAGE, sleep3,
|
|
2991
|
+
var CALL_TIMEOUT_MS, CALL_POLL_MS, JUDGED_GRADE_TIMEOUT_MS, JUDGED_GRADE_POLL_MS, EXPORT_PAGE, sleep3, WorldSession, OPEN_SESSION_OPTION_KEYS, isOpenSessionOptions;
|
|
2790
2992
|
var init_session2 = __esm({
|
|
2791
2993
|
"src/worlds/session.ts"() {
|
|
2792
2994
|
"use strict";
|
|
@@ -2794,6 +2996,8 @@ var init_session2 = __esm({
|
|
|
2794
2996
|
init_browser();
|
|
2795
2997
|
init_nativeComputer();
|
|
2796
2998
|
init_sessionContract();
|
|
2999
|
+
init_toolSchema();
|
|
3000
|
+
init_requestLedger();
|
|
2797
3001
|
init_sessionReadiness();
|
|
2798
3002
|
init_session();
|
|
2799
3003
|
init_taskRef();
|
|
@@ -2807,7 +3011,6 @@ var init_session2 = __esm({
|
|
|
2807
3011
|
JUDGED_GRADE_POLL_MS = 2e3;
|
|
2808
3012
|
EXPORT_PAGE = 500;
|
|
2809
3013
|
sleep3 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
2810
|
-
modelToolName = (name) => name.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 64) || "tool";
|
|
2811
3014
|
WorldSession = class {
|
|
2812
3015
|
constructor(sessionId, current, options) {
|
|
2813
3016
|
this.sessionId = sessionId;
|
|
@@ -2877,12 +3080,12 @@ var init_session2 = __esm({
|
|
|
2877
3080
|
);
|
|
2878
3081
|
return api2.url;
|
|
2879
3082
|
}
|
|
2880
|
-
/** Headers every request to `api()` needs
|
|
2881
|
-
*
|
|
2882
|
-
* world's own declared auth
|
|
3083
|
+
/** Headers every request to `api()` needs: a World Host session's token in the
|
|
3084
|
+
* platform's `X-World-Session` header, which every world takes; `{}` for a pod
|
|
3085
|
+
* or hosted twin, which answers with the world's own declared auth. */
|
|
2883
3086
|
async apiHeaders() {
|
|
2884
3087
|
const { api: api2 } = await this.surfaces();
|
|
2885
|
-
return api2?.token ? {
|
|
3088
|
+
return api2?.token ? { [PLATFORM_SESSION_HEADER]: api2.token } : {};
|
|
2886
3089
|
}
|
|
2887
3090
|
/** URL of the world's UI entry page for this session. */
|
|
2888
3091
|
async ui() {
|
|
@@ -2953,11 +3156,28 @@ var init_session2 = __esm({
|
|
|
2953
3156
|
}
|
|
2954
3157
|
/** The session's latest platform state (one request, no waiting). */
|
|
2955
3158
|
async status() {
|
|
3159
|
+
return this.refresh(
|
|
3160
|
+
await apiRequest(
|
|
3161
|
+
this.options,
|
|
3162
|
+
"GET",
|
|
3163
|
+
`/api/public/world-sessions/${encodeURIComponent(this.sessionId)}`
|
|
3164
|
+
)
|
|
3165
|
+
);
|
|
3166
|
+
}
|
|
3167
|
+
/** The world started over under the same id, URLs and token, on what its pin (or `version`, which becomes
|
|
3168
|
+
* its pin) resolves to now: base data plus the task's seed. A grade then reads only the new world's requests. */
|
|
3169
|
+
async restart(opts = {}) {
|
|
2956
3170
|
const fresh = await apiRequest(
|
|
2957
3171
|
this.options,
|
|
2958
|
-
"
|
|
2959
|
-
`/api/public/world-sessions/${encodeURIComponent(this.sessionId)}
|
|
3172
|
+
"POST",
|
|
3173
|
+
`/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/restart`,
|
|
3174
|
+
opts.version ? { version: opts.version } : {}
|
|
2960
3175
|
);
|
|
3176
|
+
this.refresh(fresh);
|
|
3177
|
+
return fresh;
|
|
3178
|
+
}
|
|
3179
|
+
// A status read carries neither the objective nor the open's notices; keep the ones we opened with.
|
|
3180
|
+
refresh(fresh) {
|
|
2961
3181
|
this.current = {
|
|
2962
3182
|
instruction: this.current.instruction,
|
|
2963
3183
|
tools: this.current.tools,
|
|
@@ -2992,7 +3212,7 @@ var init_session2 = __esm({
|
|
|
2992
3212
|
const { callId } = enqueued;
|
|
2993
3213
|
const judged = enqueued.pending === true;
|
|
2994
3214
|
const budgetMs = timeoutMs ?? (judged ? JUDGED_GRADE_TIMEOUT_MS : CALL_TIMEOUT_MS);
|
|
2995
|
-
const
|
|
3215
|
+
const pollMs = judged ? JUDGED_GRADE_POLL_MS : CALL_POLL_MS;
|
|
2996
3216
|
const deadline = Date.now() + budgetMs;
|
|
2997
3217
|
for (; ; ) {
|
|
2998
3218
|
const call = await apiRequest(
|
|
@@ -3008,7 +3228,7 @@ var init_session2 = __esm({
|
|
|
3008
3228
|
throw new WorldSessionTimeout(
|
|
3009
3229
|
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.`
|
|
3010
3230
|
);
|
|
3011
|
-
await sleep3(
|
|
3231
|
+
await sleep3(pollMs);
|
|
3012
3232
|
}
|
|
3013
3233
|
}
|
|
3014
3234
|
/**
|
|
@@ -3101,19 +3321,31 @@ var init_session2 = __esm({
|
|
|
3101
3321
|
async reset(opts = {}) {
|
|
3102
3322
|
await this.exchange({ kind: "reset" }, opts.timeoutMs);
|
|
3103
3323
|
}
|
|
3324
|
+
/** One page of the session's entries in its world's request ledger, newest
|
|
3325
|
+
* first and without bodies: at most `limit` after `cursor` (the last page's
|
|
3326
|
+
* `nextCursor`). Reading it records nothing in the session. */
|
|
3327
|
+
async requests(opts = {}) {
|
|
3328
|
+
return new WorldRequestLedger(this.options).forSession(
|
|
3329
|
+
this.sessionId,
|
|
3330
|
+
WorldRequestQuery.parse({ cursor: opts.cursor, limit: opts.limit ?? REQUEST_LOG_PAGE_MAX })
|
|
3331
|
+
);
|
|
3332
|
+
}
|
|
3333
|
+
page(route, limit, cursor) {
|
|
3334
|
+
const query = new URLSearchParams({ limit: String(limit) });
|
|
3335
|
+
if (cursor) query.set("cursor", cursor);
|
|
3336
|
+
return apiRequest(
|
|
3337
|
+
this.options,
|
|
3338
|
+
"GET",
|
|
3339
|
+
`/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/${route}?${query.toString()}`
|
|
3340
|
+
);
|
|
3341
|
+
}
|
|
3104
3342
|
/** The session's call log, oldest first: every tool call, seed, reset,
|
|
3105
3343
|
* grade with its result — the record of the episode. */
|
|
3106
3344
|
async export() {
|
|
3107
3345
|
const calls = [];
|
|
3108
3346
|
let cursor;
|
|
3109
3347
|
do {
|
|
3110
|
-
const
|
|
3111
|
-
if (cursor) params.set("cursor", cursor);
|
|
3112
|
-
const page = await apiRequest(
|
|
3113
|
-
this.options,
|
|
3114
|
-
"GET",
|
|
3115
|
-
`/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/calls?${params.toString()}`
|
|
3116
|
-
);
|
|
3348
|
+
const page = await this.page("calls", EXPORT_PAGE, cursor);
|
|
3117
3349
|
for (const call of page.calls) {
|
|
3118
3350
|
calls.push({
|
|
3119
3351
|
seq: Number(call.seq),
|
|
@@ -3195,6 +3427,7 @@ var init_session2 = __esm({
|
|
|
3195
3427
|
"reuseWarm",
|
|
3196
3428
|
"surfaces",
|
|
3197
3429
|
"browserTier",
|
|
3430
|
+
"auth",
|
|
3198
3431
|
"options"
|
|
3199
3432
|
]);
|
|
3200
3433
|
isOpenSessionOptions = (value) => typeof value === "object" && value !== null && Object.keys(value).every((key) => OPEN_SESSION_OPTION_KEYS.has(key));
|
|
@@ -3309,11 +3542,50 @@ var init_tasks = __esm({
|
|
|
3309
3542
|
}
|
|
3310
3543
|
});
|
|
3311
3544
|
|
|
3545
|
+
// src/worlds/taskGrades.ts
|
|
3546
|
+
var TASKS2, compact2, TaskGrades;
|
|
3547
|
+
var init_taskGrades = __esm({
|
|
3548
|
+
"src/worlds/taskGrades.ts"() {
|
|
3549
|
+
"use strict";
|
|
3550
|
+
init_worlds();
|
|
3551
|
+
TASKS2 = "/api/public/world-tasks";
|
|
3552
|
+
compact2 = (body) => Object.fromEntries(Object.entries(body).filter(([, v]) => v !== void 0));
|
|
3553
|
+
TaskGrades = class {
|
|
3554
|
+
constructor(options = {}) {
|
|
3555
|
+
this.options = options;
|
|
3556
|
+
}
|
|
3557
|
+
options;
|
|
3558
|
+
try(sessionId, target) {
|
|
3559
|
+
return apiRequest(
|
|
3560
|
+
this.options,
|
|
3561
|
+
"POST",
|
|
3562
|
+
`${TASKS2}/try`,
|
|
3563
|
+
compact2({ sessionId, ...target })
|
|
3564
|
+
);
|
|
3565
|
+
}
|
|
3566
|
+
regrade(taskId, scope = {}) {
|
|
3567
|
+
return apiRequest(
|
|
3568
|
+
this.options,
|
|
3569
|
+
"POST",
|
|
3570
|
+
`${TASKS2}/${encodeURIComponent(taskId)}/regrade`,
|
|
3571
|
+
compact2({ ...scope })
|
|
3572
|
+
);
|
|
3573
|
+
}
|
|
3574
|
+
};
|
|
3575
|
+
}
|
|
3576
|
+
});
|
|
3577
|
+
|
|
3312
3578
|
// src/worlds/surfaceDescriptor.ts
|
|
3313
3579
|
function surfaceDescriptor(s) {
|
|
3314
3580
|
return {
|
|
3315
3581
|
surfaces: surfaceKinds(s),
|
|
3316
|
-
...s.api ? {
|
|
3582
|
+
...s.api ? {
|
|
3583
|
+
api: {
|
|
3584
|
+
url: s.api.url,
|
|
3585
|
+
...s.api.token ? { token: s.api.token } : {},
|
|
3586
|
+
...s.api.auth ? { auth: s.api.auth } : {}
|
|
3587
|
+
}
|
|
3588
|
+
} : {},
|
|
3317
3589
|
...s.ui ? { ui: { url: s.ui.url, entry: uiEntryUrl(s.ui), apiPath: s.ui.apiPath ?? null } } : {},
|
|
3318
3590
|
...s.browser ? {
|
|
3319
3591
|
browser: {
|
|
@@ -3363,8 +3635,7 @@ function fromResponse(answer, options) {
|
|
|
3363
3635
|
sessions[alias] = new WorldSession(state2.sessionId, state2, options);
|
|
3364
3636
|
worlds[alias] = {
|
|
3365
3637
|
slug: state2.slug,
|
|
3366
|
-
ref: state2.ref
|
|
3367
|
-
private: state2.private ?? null
|
|
3638
|
+
ref: state2.ref
|
|
3368
3639
|
};
|
|
3369
3640
|
}
|
|
3370
3641
|
return new TaskSessions(
|
|
@@ -3439,7 +3710,6 @@ async function attachTask(taskId, options = {}) {
|
|
|
3439
3710
|
{
|
|
3440
3711
|
slug: row.slug ?? "",
|
|
3441
3712
|
ref: null,
|
|
3442
|
-
private: null,
|
|
3443
3713
|
versionId: row.versionId,
|
|
3444
3714
|
sessionId: row.sessionId,
|
|
3445
3715
|
ready: row.ready,
|
|
@@ -3469,7 +3739,7 @@ async function attachManifest(manifest, options = {}) {
|
|
|
3469
3739
|
Object.fromEntries(
|
|
3470
3740
|
Object.entries(manifest.sessions).map(([alias, entry]) => [
|
|
3471
3741
|
alias,
|
|
3472
|
-
{ slug: entry.slug, ref: entry.ref
|
|
3742
|
+
{ slug: entry.slug, ref: entry.ref }
|
|
3473
3743
|
])
|
|
3474
3744
|
)
|
|
3475
3745
|
);
|
|
@@ -3491,7 +3761,6 @@ var init_taskSessions = __esm({
|
|
|
3491
3761
|
manifestSession = (s, state2, world) => ({
|
|
3492
3762
|
slug: world.slug,
|
|
3493
3763
|
ref: world.ref,
|
|
3494
|
-
private: world.private,
|
|
3495
3764
|
versionId: state2.versionId,
|
|
3496
3765
|
sessionId: state2.sessionId,
|
|
3497
3766
|
ready: state2.ready,
|
|
@@ -3548,7 +3817,7 @@ var init_taskSessions = __esm({
|
|
|
3548
3817
|
/** This alias's world as recorded at open/attach — what a `TaskRun`
|
|
3549
3818
|
* filing needs to name, without exposing the whole map. */
|
|
3550
3819
|
worldRef(alias) {
|
|
3551
|
-
return this.worlds[alias] ?? { slug: "", ref: null
|
|
3820
|
+
return this.worlds[alias] ?? { slug: "", ref: null };
|
|
3552
3821
|
}
|
|
3553
3822
|
/** The aliases, in the spec's order. */
|
|
3554
3823
|
get aliases() {
|
|
@@ -3873,16 +4142,12 @@ var init_taskRunOutcome = __esm({
|
|
|
3873
4142
|
evaluationId;
|
|
3874
4143
|
evaluationStatus = null;
|
|
3875
4144
|
started = Date.now();
|
|
3876
|
-
/** The run stopped short of a grade; the first reason stands. */
|
|
3877
4145
|
stopped(error) {
|
|
3878
4146
|
this.runError ??= messageOf(error).slice(0, 2e3);
|
|
3879
4147
|
}
|
|
3880
4148
|
agentRaised(error) {
|
|
3881
4149
|
this.agentError = messageOf(error).slice(0, 2e3);
|
|
3882
4150
|
}
|
|
3883
|
-
/** Every reason the run failed, on one line: the evaluation's
|
|
3884
|
-
* `metrics.error`. A run that never reached a grade has failed whatever
|
|
3885
|
-
* its reasons say. */
|
|
3886
4151
|
failure() {
|
|
3887
4152
|
const reasons = [
|
|
3888
4153
|
this.agentError === null ? null : `agent raised: ${this.agentError}`,
|
|
@@ -3978,6 +4243,7 @@ var init_taskRunOutcome = __esm({
|
|
|
3978
4243
|
])
|
|
3979
4244
|
),
|
|
3980
4245
|
ungraded: this.grade?.ungraded ?? live.aliases,
|
|
4246
|
+
verifierVersion: live.taskVersion,
|
|
3981
4247
|
traced: this.traced,
|
|
3982
4248
|
runDir: this.runDir,
|
|
3983
4249
|
...this.agentError ? { agentError: this.agentError } : {},
|
|
@@ -4738,7 +5004,7 @@ var require_package = __commonJS({
|
|
|
4738
5004
|
"package.json"(exports, module) {
|
|
4739
5005
|
module.exports = {
|
|
4740
5006
|
name: "@withgateway/sdk",
|
|
4741
|
-
version: "0.
|
|
5007
|
+
version: "0.4.0",
|
|
4742
5008
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
4743
5009
|
main: "./dist/index.js",
|
|
4744
5010
|
module: "./dist/index.mjs",
|
|
@@ -5930,45 +6196,83 @@ var init_setRun = __esm({
|
|
|
5930
6196
|
});
|
|
5931
6197
|
|
|
5932
6198
|
// src/worlds/requestLog.ts
|
|
5933
|
-
|
|
6199
|
+
function worldRequestsUnrecorded(counts) {
|
|
6200
|
+
const parts = UNRECORDED.map(([field2, one, many]) => [counted(counts[field2]), one, many]).filter(([count]) => count > 0).map(([count, one, many]) => (count === 1 ? one : many).replace("{n}", String(count)));
|
|
6201
|
+
return parts.length > 0 ? `Not recorded: ${parts.join(", ")}` : null;
|
|
6202
|
+
}
|
|
6203
|
+
function counted(value) {
|
|
6204
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : 0;
|
|
6205
|
+
}
|
|
6206
|
+
var UNRECORDED, WorldRequestLog;
|
|
5934
6207
|
var init_requestLog = __esm({
|
|
5935
6208
|
"src/worlds/requestLog.ts"() {
|
|
5936
6209
|
"use strict";
|
|
6210
|
+
init_requestLedger();
|
|
6211
|
+
UNRECORDED = [
|
|
6212
|
+
["lost", "{n} request", "{n} requests"],
|
|
6213
|
+
["shed", "{n} request's headers and bodies", "{n} requests' headers and bodies"],
|
|
6214
|
+
["hostsLost", "the requests {n} lost host held", "the requests {n} lost hosts held"]
|
|
6215
|
+
];
|
|
5937
6216
|
WorldRequestLog = class _WorldRequestLog {
|
|
5938
|
-
constructor(requests) {
|
|
6217
|
+
constructor(requests, notRecorded = null, unrecorded = null) {
|
|
5939
6218
|
this.requests = requests;
|
|
6219
|
+
this.notRecorded = notRecorded;
|
|
6220
|
+
this.unrecorded = unrecorded;
|
|
5940
6221
|
}
|
|
5941
6222
|
requests;
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
|
|
5945
|
-
|
|
5946
|
-
|
|
5947
|
-
|
|
5948
|
-
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
|
|
5953
|
-
|
|
5954
|
-
|
|
5955
|
-
|
|
6223
|
+
notRecorded;
|
|
6224
|
+
unrecorded;
|
|
6225
|
+
/** Every entry the ledger holds for the session, oldest first, and the line for what it did not record;
|
|
6226
|
+
* for a session the World Host did not serve, none, and `notRecorded` says why. */
|
|
6227
|
+
static async load(session) {
|
|
6228
|
+
try {
|
|
6229
|
+
return await _WorldRequestLog.pages(session);
|
|
6230
|
+
} catch (error) {
|
|
6231
|
+
const refused = WorldRequestsNotRecorded.from(error);
|
|
6232
|
+
if (!(refused instanceof WorldRequestsNotRecorded)) throw error;
|
|
6233
|
+
return new _WorldRequestLog([], refused.message);
|
|
6234
|
+
}
|
|
6235
|
+
}
|
|
6236
|
+
static async pages(session) {
|
|
6237
|
+
const requests = [];
|
|
6238
|
+
let cursor;
|
|
6239
|
+
for (; ; ) {
|
|
6240
|
+
const page = await session.requests(cursor ? { cursor } : {});
|
|
6241
|
+
requests.push(...page.requests);
|
|
6242
|
+
if (!page.nextCursor || page.requests.length === 0)
|
|
6243
|
+
return new _WorldRequestLog(requests.reverse(), null, worldRequestsUnrecorded(page));
|
|
6244
|
+
cursor = page.nextCursor;
|
|
6245
|
+
}
|
|
6246
|
+
}
|
|
6247
|
+
/** Each entry in the shape of a ledger line, `kind: "request"`, so one JSONL
|
|
6248
|
+
* file holds both: `args` what was asked, `result` what came back under the
|
|
6249
|
+
* entry's `requestId`. */
|
|
5956
6250
|
asCalls() {
|
|
5957
6251
|
return this.requests.map((r) => ({
|
|
5958
|
-
seq:
|
|
6252
|
+
seq: r.seq,
|
|
5959
6253
|
kind: "request",
|
|
5960
|
-
tool: r.operation
|
|
6254
|
+
tool: r.operation,
|
|
5961
6255
|
args: {
|
|
5962
|
-
method: r.method
|
|
5963
|
-
path: r.path
|
|
5964
|
-
|
|
5965
|
-
|
|
5966
|
-
|
|
5967
|
-
|
|
6256
|
+
method: r.method,
|
|
6257
|
+
path: r.path,
|
|
6258
|
+
query: r.query,
|
|
6259
|
+
via: r.via,
|
|
6260
|
+
contentType: r.request.contentType,
|
|
6261
|
+
bodyBytes: r.request.bodyBytes,
|
|
6262
|
+
truncated: r.request.truncated
|
|
6263
|
+
},
|
|
6264
|
+
result: {
|
|
6265
|
+
requestId: r.id,
|
|
6266
|
+
status: r.response.status,
|
|
6267
|
+
rows: r.rows,
|
|
6268
|
+
found: r.found,
|
|
6269
|
+
durationMs: r.durationMs,
|
|
6270
|
+
contentType: r.response.contentType,
|
|
6271
|
+
bodyBytes: r.response.bodyBytes,
|
|
6272
|
+
truncated: r.response.truncated
|
|
5968
6273
|
},
|
|
5969
|
-
result: { status: r.status ?? null, rows: r.rows ?? null, found: r.found ?? null },
|
|
5970
6274
|
error: null,
|
|
5971
|
-
completedAt: r.at
|
|
6275
|
+
completedAt: r.at
|
|
5972
6276
|
}));
|
|
5973
6277
|
}
|
|
5974
6278
|
};
|
|
@@ -6663,7 +6967,8 @@ function checkoutIdentity(ref, resolved) {
|
|
|
6663
6967
|
async function pull(slugRef, target, options = {}, opts = {}) {
|
|
6664
6968
|
const at = slugRef.indexOf("@");
|
|
6665
6969
|
const slug = at === -1 ? slugRef : slugRef.slice(0, at);
|
|
6666
|
-
const
|
|
6970
|
+
const asked = at === -1 ? void 0 : slugRef.slice(at + 1);
|
|
6971
|
+
const ref = asked ?? "latest";
|
|
6667
6972
|
const landing = CheckoutTarget.resolve(slug, target, {
|
|
6668
6973
|
cwd: process.cwd(),
|
|
6669
6974
|
force: opts.force ?? false,
|
|
@@ -6671,7 +6976,7 @@ async function pull(slugRef, target, options = {}, opts = {}) {
|
|
|
6671
6976
|
});
|
|
6672
6977
|
const details = await apiRequest(options, "POST", "/api/public/benchmark-containers/resolve-version", {
|
|
6673
6978
|
slug,
|
|
6674
|
-
ref
|
|
6979
|
+
...asked ? { ref: asked } : {}
|
|
6675
6980
|
});
|
|
6676
6981
|
if (!details.downloadUrl) {
|
|
6677
6982
|
throw new Error(`${slug}@${ref} resolved but has no uploaded bundle`);
|
|
@@ -6857,7 +7162,7 @@ async function validateWorld(dir, opts) {
|
|
|
6857
7162
|
options,
|
|
6858
7163
|
"POST",
|
|
6859
7164
|
"/api/public/benchmark-containers/resolve-version",
|
|
6860
|
-
{ slug, ref: branch }
|
|
7165
|
+
{ slug, ...branch === DEFAULT_BRANCH ? {} : { ref: branch } }
|
|
6861
7166
|
);
|
|
6862
7167
|
tipVersionId = tip.versionId ?? null;
|
|
6863
7168
|
} catch {
|
|
@@ -6964,11 +7269,16 @@ var init_validate = __esm({
|
|
|
6964
7269
|
});
|
|
6965
7270
|
|
|
6966
7271
|
// src/worlds/sandbox.ts
|
|
7272
|
+
import { createHash as createHash5, randomUUID as randomUUID2 } from "crypto";
|
|
6967
7273
|
function parseSlugRef(slugRef) {
|
|
6968
7274
|
const at = slugRef.indexOf("@");
|
|
6969
7275
|
if (at === -1) return { slug: slugRef };
|
|
6970
7276
|
return { slug: slugRef.slice(0, at), ref: slugRef.slice(at + 1) };
|
|
6971
7277
|
}
|
|
7278
|
+
function nameGlob(pattern) {
|
|
7279
|
+
const literal = (part) => part.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
|
|
7280
|
+
return new RegExp(`^${pattern.split("*").map(literal).join(".*")}$`);
|
|
7281
|
+
}
|
|
6972
7282
|
function rebaseConflicts(error) {
|
|
6973
7283
|
if (!(error instanceof ApiError) || error.status !== 409) return null;
|
|
6974
7284
|
let body;
|
|
@@ -6986,7 +7296,8 @@ function isConflictPath(value) {
|
|
|
6986
7296
|
return typeof entry?.path === "string" && typeof entry.reason === "string";
|
|
6987
7297
|
}
|
|
6988
7298
|
function uncommittedPaths(error) {
|
|
6989
|
-
if (!(error instanceof ApiError) || error.status !== 409 || error.code !== "sandbox_uncommitted")
|
|
7299
|
+
if (!(error instanceof ApiError) || error.status !== 409 || error.code !== "sandbox_uncommitted")
|
|
7300
|
+
return null;
|
|
6990
7301
|
let body;
|
|
6991
7302
|
try {
|
|
6992
7303
|
body = JSON.parse(error.text);
|
|
@@ -6997,6 +7308,53 @@ function uncommittedPaths(error) {
|
|
|
6997
7308
|
if (!Array.isArray(uncommitted)) return null;
|
|
6998
7309
|
return uncommitted.filter((p) => typeof p === "string");
|
|
6999
7310
|
}
|
|
7311
|
+
function carriedWarnings(error) {
|
|
7312
|
+
const kept = typeof error === "object" && error !== null ? carried.get(error) ?? [] : [];
|
|
7313
|
+
const shown = error instanceof Error ? error.message : "";
|
|
7314
|
+
return unique([...kept, ...bodyWarnings(error)]).filter((warning) => !shown.includes(warning));
|
|
7315
|
+
}
|
|
7316
|
+
function carrying(error, warnings) {
|
|
7317
|
+
if (warnings.length > 0 && typeof error === "object" && error !== null)
|
|
7318
|
+
carried.set(error, unique([...carried.get(error) ?? [], ...warnings]));
|
|
7319
|
+
return error;
|
|
7320
|
+
}
|
|
7321
|
+
function unique(warnings) {
|
|
7322
|
+
return [...new Set(warnings)];
|
|
7323
|
+
}
|
|
7324
|
+
function bodyWarnings(error) {
|
|
7325
|
+
if (!(error instanceof ApiError)) return [];
|
|
7326
|
+
let body;
|
|
7327
|
+
try {
|
|
7328
|
+
body = JSON.parse(error.text);
|
|
7329
|
+
} catch {
|
|
7330
|
+
return [];
|
|
7331
|
+
}
|
|
7332
|
+
const warnings = body?.warnings;
|
|
7333
|
+
if (!Array.isArray(warnings)) return [];
|
|
7334
|
+
return warnings.filter((w) => typeof w === "string");
|
|
7335
|
+
}
|
|
7336
|
+
function deferredWarnings(error) {
|
|
7337
|
+
if (!(error instanceof ApiError) || error.status !== 409 || error.code !== "sandbox_exec_deferred") return null;
|
|
7338
|
+
return bodyWarnings(error);
|
|
7339
|
+
}
|
|
7340
|
+
function rowsRefusal(error) {
|
|
7341
|
+
if (!(error instanceof ApiError) || error.status !== 400 || error.code !== "rows_refused") return null;
|
|
7342
|
+
let body;
|
|
7343
|
+
try {
|
|
7344
|
+
body = JSON.parse(error.text);
|
|
7345
|
+
} catch {
|
|
7346
|
+
return null;
|
|
7347
|
+
}
|
|
7348
|
+
const { message, batchId, refusalCount, refusals, reportUrl } = body;
|
|
7349
|
+
if (typeof batchId !== "string" || typeof refusalCount !== "number" || !Array.isArray(refusals)) return null;
|
|
7350
|
+
return {
|
|
7351
|
+
message: typeof message === "string" ? message : "",
|
|
7352
|
+
batchId,
|
|
7353
|
+
refusalCount,
|
|
7354
|
+
refusals: refusals.filter((r) => typeof r === "object" && r !== null),
|
|
7355
|
+
reportUrl: typeof reportUrl === "string" ? reportUrl : null
|
|
7356
|
+
};
|
|
7357
|
+
}
|
|
7000
7358
|
function listQuery(filter) {
|
|
7001
7359
|
const params = new URLSearchParams();
|
|
7002
7360
|
if (filter.status) params.set("status", filter.status);
|
|
@@ -7005,15 +7363,51 @@ function listQuery(filter) {
|
|
|
7005
7363
|
const qs = params.toString();
|
|
7006
7364
|
return qs ? `?${qs}` : "";
|
|
7007
7365
|
}
|
|
7008
|
-
var isSandboxImportPending, sid, SANDBOXES, SANDBOX_REQUEST_TIMEOUT_MS, WorldSandboxClient;
|
|
7366
|
+
var isSandboxCommitPending, isSandboxImportPending, sid, SANDBOXES, SANDBOX_REQUEST_TIMEOUT_MS, SANDBOX_WRITE_CHUNK_BYTES, SANDBOX_FILE_MAX_BYTES, SANDBOX_WRITE_SKIPPED, WriteTreeFilter, SANDBOX_EXEC_WAIT_MS, SANDBOX_EXEC_TIMEOUT_MAX_S, SANDBOX_EXEC_REPORT_MARGIN_MS, SANDBOX_EXEC_START_ATTEMPTS, carried, WorldSandboxClient;
|
|
7009
7367
|
var init_sandbox = __esm({
|
|
7010
7368
|
"src/worlds/sandbox.ts"() {
|
|
7011
7369
|
"use strict";
|
|
7012
7370
|
init_worlds();
|
|
7371
|
+
isSandboxCommitPending = (answer) => !("versionId" in answer);
|
|
7013
7372
|
isSandboxImportPending = (answer) => !("versionId" in answer);
|
|
7014
7373
|
sid = encodeURIComponent;
|
|
7015
7374
|
SANDBOXES = "/api/public/benchmark-containers/sandboxes";
|
|
7016
|
-
SANDBOX_REQUEST_TIMEOUT_MS =
|
|
7375
|
+
SANDBOX_REQUEST_TIMEOUT_MS = 29e4;
|
|
7376
|
+
SANDBOX_WRITE_CHUNK_BYTES = 4 * 1024 * 1024;
|
|
7377
|
+
SANDBOX_FILE_MAX_BYTES = 256 * 1024 * 1024;
|
|
7378
|
+
SANDBOX_WRITE_SKIPPED = [
|
|
7379
|
+
".git/",
|
|
7380
|
+
".gateway/",
|
|
7381
|
+
"scratch/",
|
|
7382
|
+
".scratch/",
|
|
7383
|
+
"__pycache__/",
|
|
7384
|
+
"*.pyc",
|
|
7385
|
+
".pytest_cache/",
|
|
7386
|
+
".mypy_cache/",
|
|
7387
|
+
".ruff_cache/",
|
|
7388
|
+
"node_modules/",
|
|
7389
|
+
".venv/",
|
|
7390
|
+
"venv/",
|
|
7391
|
+
".DS_Store",
|
|
7392
|
+
"*.swp"
|
|
7393
|
+
];
|
|
7394
|
+
WriteTreeFilter = class {
|
|
7395
|
+
directories = new Set(
|
|
7396
|
+
SANDBOX_WRITE_SKIPPED.filter((pattern) => pattern.endsWith("/")).map((pattern) => pattern.slice(0, -1))
|
|
7397
|
+
);
|
|
7398
|
+
files = SANDBOX_WRITE_SKIPPED.filter((pattern) => !pattern.endsWith("/")).map(nameGlob);
|
|
7399
|
+
skipsDirectory(name) {
|
|
7400
|
+
return this.directories.has(name);
|
|
7401
|
+
}
|
|
7402
|
+
skipsFile(name) {
|
|
7403
|
+
return this.files.some((glob) => glob.test(name));
|
|
7404
|
+
}
|
|
7405
|
+
};
|
|
7406
|
+
SANDBOX_EXEC_WAIT_MS = 4e4;
|
|
7407
|
+
SANDBOX_EXEC_TIMEOUT_MAX_S = 600;
|
|
7408
|
+
SANDBOX_EXEC_REPORT_MARGIN_MS = 35e3;
|
|
7409
|
+
SANDBOX_EXEC_START_ATTEMPTS = 3;
|
|
7410
|
+
carried = /* @__PURE__ */ new WeakMap();
|
|
7017
7411
|
WorldSandboxClient = class {
|
|
7018
7412
|
constructor(options = {}) {
|
|
7019
7413
|
this.options = options;
|
|
@@ -7038,7 +7432,10 @@ var init_sandbox = __esm({
|
|
|
7038
7432
|
}
|
|
7039
7433
|
/** The project's sandboxes, newest first — how an agent finds one it left open. */
|
|
7040
7434
|
async list(filter = {}) {
|
|
7041
|
-
const res = await this.request(
|
|
7435
|
+
const res = await this.request(
|
|
7436
|
+
"GET",
|
|
7437
|
+
`${SANDBOXES}${listQuery(filter)}`
|
|
7438
|
+
);
|
|
7042
7439
|
return res.sandboxes;
|
|
7043
7440
|
}
|
|
7044
7441
|
async read(sandboxId, filePath) {
|
|
@@ -7046,16 +7443,72 @@ var init_sandbox = __esm({
|
|
|
7046
7443
|
"GET",
|
|
7047
7444
|
`${SANDBOXES}/${sid(sandboxId)}/file?path=${encodeURIComponent(filePath)}`
|
|
7048
7445
|
);
|
|
7049
|
-
return {
|
|
7446
|
+
return {
|
|
7447
|
+
path: res.path,
|
|
7448
|
+
size: res.size,
|
|
7449
|
+
bytes: Buffer.from(res.contentBase64, "base64")
|
|
7450
|
+
};
|
|
7050
7451
|
}
|
|
7051
|
-
|
|
7052
|
-
|
|
7053
|
-
|
|
7054
|
-
|
|
7055
|
-
|
|
7452
|
+
/** A file past one chunk goes up in parts under one upload id; the platform lands it whole once the last part's
|
|
7453
|
+
* size and SHA-256 check out. */
|
|
7454
|
+
async write(sandboxId, filePath, bytes) {
|
|
7455
|
+
if (bytes.length <= SANDBOX_WRITE_CHUNK_BYTES)
|
|
7456
|
+
return this.putFile(sandboxId, { path: filePath, contentBase64: bytes.toString("base64") });
|
|
7457
|
+
const whole = { upload: randomUUID2(), size: bytes.length, sha256: createHash5("sha256").update(bytes).digest("hex") };
|
|
7458
|
+
let answer = { path: filePath, received: 0 };
|
|
7459
|
+
for (let offset = 0; offset < bytes.length; offset += SANDBOX_WRITE_CHUNK_BYTES) {
|
|
7460
|
+
const part = bytes.subarray(offset, offset + SANDBOX_WRITE_CHUNK_BYTES);
|
|
7461
|
+
answer = await this.putFile(sandboxId, {
|
|
7462
|
+
path: filePath,
|
|
7463
|
+
contentBase64: part.toString("base64"),
|
|
7464
|
+
...whole,
|
|
7465
|
+
offset,
|
|
7466
|
+
last: offset + part.length === bytes.length
|
|
7467
|
+
});
|
|
7468
|
+
}
|
|
7469
|
+
return answer;
|
|
7470
|
+
}
|
|
7471
|
+
putFile(sandboxId, body) {
|
|
7472
|
+
return this.request("PUT", `${SANDBOXES}/${sid(sandboxId)}/file`, body);
|
|
7473
|
+
}
|
|
7474
|
+
/** Runs as a job on the platform: a command that outlasts one request is waited on again until its result. */
|
|
7475
|
+
async exec(sandboxId, input) {
|
|
7476
|
+
const budgetMs = (input.timeoutMs ?? SANDBOX_EXEC_TIMEOUT_MAX_S * 1e3) + SANDBOX_EXEC_REPORT_MARGIN_MS;
|
|
7477
|
+
let answer = await this.startExec(sandboxId, { ...input, waitMs: SANDBOX_EXEC_WAIT_MS });
|
|
7478
|
+
const deadline = Date.now() + budgetMs;
|
|
7479
|
+
const warnings = [...answer.warnings ?? []];
|
|
7480
|
+
try {
|
|
7481
|
+
while ("state" in answer) {
|
|
7482
|
+
if (Date.now() >= deadline)
|
|
7483
|
+
throw new Error(
|
|
7484
|
+
`exec ${answer.execId} in sandbox ${sandboxId} has not reported back within ${budgetMs / 1e3} s, past its timeout: the sandbox may have restarted. Check the sandbox's status, then run the command again.`
|
|
7485
|
+
);
|
|
7486
|
+
answer = await this.execStep(sandboxId, { execId: answer.execId, waitMs: SANDBOX_EXEC_WAIT_MS });
|
|
7487
|
+
warnings.push(...answer.warnings ?? []);
|
|
7488
|
+
}
|
|
7489
|
+
} catch (error) {
|
|
7490
|
+
throw carrying(error, warnings);
|
|
7491
|
+
}
|
|
7492
|
+
return { ...answer, warnings };
|
|
7493
|
+
}
|
|
7494
|
+
// A deferred start ran nothing (the platform was still getting the sandbox ready), so starting again is safe. What
|
|
7495
|
+
// getting ready found rides on the deferral alone (no later call reports it), so it is kept for the answer, or for
|
|
7496
|
+
// the error when a later attempt fails.
|
|
7497
|
+
async startExec(sandboxId, body) {
|
|
7498
|
+
const kept = [];
|
|
7499
|
+
for (let attempt = 1; ; attempt += 1) {
|
|
7500
|
+
try {
|
|
7501
|
+
const answer = await this.execStep(sandboxId, body);
|
|
7502
|
+
return { ...answer, warnings: unique([...kept, ...answer.warnings ?? []]) };
|
|
7503
|
+
} catch (error) {
|
|
7504
|
+
const warnings = deferredWarnings(error);
|
|
7505
|
+
if (warnings === null || attempt === SANDBOX_EXEC_START_ATTEMPTS) throw carrying(error, kept);
|
|
7506
|
+
kept.push(...warnings);
|
|
7507
|
+
}
|
|
7508
|
+
}
|
|
7056
7509
|
}
|
|
7057
|
-
|
|
7058
|
-
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/exec`,
|
|
7510
|
+
execStep(sandboxId, body) {
|
|
7511
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/exec`, body);
|
|
7059
7512
|
}
|
|
7060
7513
|
check(sandboxId) {
|
|
7061
7514
|
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/check`, {});
|
|
@@ -7063,7 +7516,11 @@ var init_sandbox = __esm({
|
|
|
7063
7516
|
/** With `rebase`, a moved base is replayed onto; a 409 then names the conflicting paths (`rebaseConflicts`). */
|
|
7064
7517
|
commit(sandboxId, input) {
|
|
7065
7518
|
const { rebase, ...rest } = input;
|
|
7066
|
-
return this.request(
|
|
7519
|
+
return this.request(
|
|
7520
|
+
"POST",
|
|
7521
|
+
`${SANDBOXES}/${sid(sandboxId)}/commit`,
|
|
7522
|
+
rebase ? { ...rest, rebase: true } : rest
|
|
7523
|
+
);
|
|
7067
7524
|
}
|
|
7068
7525
|
/**
|
|
7069
7526
|
* A rows file already in the sandbox tree into the PLATFORM world the
|
|
@@ -7076,7 +7533,11 @@ var init_sandbox = __esm({
|
|
|
7076
7533
|
}
|
|
7077
7534
|
/** Uncommitted work is a 409 (`uncommittedPaths`) unless `force` discards it. */
|
|
7078
7535
|
close(sandboxId, opts = {}) {
|
|
7079
|
-
return this.request(
|
|
7536
|
+
return this.request(
|
|
7537
|
+
"DELETE",
|
|
7538
|
+
`${SANDBOXES}/${sid(sandboxId)}`,
|
|
7539
|
+
opts.force ? { force: true } : void 0
|
|
7540
|
+
);
|
|
7080
7541
|
}
|
|
7081
7542
|
};
|
|
7082
7543
|
}
|
|
@@ -7395,7 +7856,7 @@ var init_json = __esm({
|
|
|
7395
7856
|
});
|
|
7396
7857
|
|
|
7397
7858
|
// src/worlds/transforms.ts
|
|
7398
|
-
import { createHash as
|
|
7859
|
+
import { createHash as createHash6 } from "crypto";
|
|
7399
7860
|
function parseTransform(name) {
|
|
7400
7861
|
const simple = Object.prototype.hasOwnProperty.call(SIMPLE, name) ? SIMPLE[name] : void 0;
|
|
7401
7862
|
if (simple) return simple;
|
|
@@ -7433,7 +7894,7 @@ var init_transforms = __esm({
|
|
|
7433
7894
|
return at === -1 ? "" : value.slice(at + 1).toLowerCase();
|
|
7434
7895
|
};
|
|
7435
7896
|
stripPrefix = (prefix) => (value) => value.startsWith(prefix) ? value.slice(prefix.length) : value;
|
|
7436
|
-
hex = (algorithm, value) =>
|
|
7897
|
+
hex = (algorithm, value) => createHash6(algorithm).update(value, "utf8").digest("hex");
|
|
7437
7898
|
SIMPLE = {
|
|
7438
7899
|
lower: (value) => value.toLowerCase(),
|
|
7439
7900
|
upper: (value) => value.toUpperCase(),
|
|
@@ -7457,7 +7918,7 @@ var init_transforms = __esm({
|
|
|
7457
7918
|
});
|
|
7458
7919
|
|
|
7459
7920
|
// src/worlds/redaction.ts
|
|
7460
|
-
import { createHash as
|
|
7921
|
+
import { createHash as createHash7 } from "crypto";
|
|
7461
7922
|
function pyText(value) {
|
|
7462
7923
|
if (typeof value === "string") return value;
|
|
7463
7924
|
if (Number.isInteger(value)) return String(value);
|
|
@@ -7466,7 +7927,7 @@ function pyText(value) {
|
|
|
7466
7927
|
return pyFloatRepr(value);
|
|
7467
7928
|
}
|
|
7468
7929
|
function hashForm(slug, plaintext) {
|
|
7469
|
-
return "sha256:" +
|
|
7930
|
+
return "sha256:" + createHash7("sha256").update(`${slug}:${pyText(plaintext)}`, "utf8").digest("hex");
|
|
7470
7931
|
}
|
|
7471
7932
|
function preserveForm(slug, plaintext) {
|
|
7472
7933
|
const kind = typeof plaintext === "string" ? "str" : isInt(plaintext) ? "int" : "float";
|
|
@@ -7475,12 +7936,12 @@ function preserveForm(slug, plaintext) {
|
|
|
7475
7936
|
}
|
|
7476
7937
|
function shapeText(slug, text2, kind) {
|
|
7477
7938
|
const seed = Buffer.from(`${slug}:${text2}`, "utf8");
|
|
7478
|
-
let digest =
|
|
7939
|
+
let digest = createHash7("sha256").update(seed).digest();
|
|
7479
7940
|
let cursor = 0;
|
|
7480
7941
|
const out = [];
|
|
7481
7942
|
for (const char of text2) {
|
|
7482
7943
|
if (cursor === digest.length) {
|
|
7483
|
-
digest =
|
|
7944
|
+
digest = createHash7("sha256").update(Buffer.concat([digest, seed])).digest();
|
|
7484
7945
|
cursor = 0;
|
|
7485
7946
|
}
|
|
7486
7947
|
const byte = digest[cursor];
|
|
@@ -7633,7 +8094,7 @@ var init_config = __esm({
|
|
|
7633
8094
|
init_transport();
|
|
7634
8095
|
ApiError2 = class extends CliError {
|
|
7635
8096
|
constructor(status, method, route, text2) {
|
|
7636
|
-
const body = parseErrorBody(text2);
|
|
8097
|
+
const body = parseErrorBody(text2, status);
|
|
7637
8098
|
super(`${method} ${route} -> ${status}: ${body.detail}`, 1);
|
|
7638
8099
|
this.status = status;
|
|
7639
8100
|
this.method = method;
|
|
@@ -7655,6 +8116,14 @@ import { spawn, spawnSync } from "child_process";
|
|
|
7655
8116
|
import * as fs7 from "fs";
|
|
7656
8117
|
import * as net from "net";
|
|
7657
8118
|
import * as path8 from "path";
|
|
8119
|
+
function forwardedEnv() {
|
|
8120
|
+
return Object.fromEntries(
|
|
8121
|
+
FORWARDED_ENV.flatMap((name) => {
|
|
8122
|
+
const value = process.env[name];
|
|
8123
|
+
return value ? [[name, value]] : [];
|
|
8124
|
+
})
|
|
8125
|
+
);
|
|
8126
|
+
}
|
|
7658
8127
|
function tailOf(output) {
|
|
7659
8128
|
return output.length > DIAGNOSTIC_TAIL ? `\u2026${output.slice(-DIAGNOSTIC_TAIL)}` : output;
|
|
7660
8129
|
}
|
|
@@ -7772,7 +8241,7 @@ async function localBridge(request, local, opts = {}) {
|
|
|
7772
8241
|
PATH: process.env.PATH ?? "",
|
|
7773
8242
|
HOME: process.env.HOME ?? "",
|
|
7774
8243
|
TMPDIR: process.env.TMPDIR ?? "",
|
|
7775
|
-
...
|
|
8244
|
+
...forwardedEnv(),
|
|
7776
8245
|
GATEWAY_RUNTIME_EXECUTE: "1"
|
|
7777
8246
|
}
|
|
7778
8247
|
}
|
|
@@ -7818,7 +8287,7 @@ async function localBridge(request, local, opts = {}) {
|
|
|
7818
8287
|
child.stdin.end(input);
|
|
7819
8288
|
});
|
|
7820
8289
|
}
|
|
7821
|
-
var MIN_PYTHON, MIN_PYTHON_LABEL, DIAGNOSTIC_TAIL, BRIDGE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
|
|
8290
|
+
var MIN_PYTHON, MIN_PYTHON_LABEL, DIAGNOSTIC_TAIL, FORWARDED_ENV, BRIDGE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
|
|
7822
8291
|
var init_local = __esm({
|
|
7823
8292
|
"src/cli/runtime/local.ts"() {
|
|
7824
8293
|
"use strict";
|
|
@@ -7827,6 +8296,7 @@ var init_local = __esm({
|
|
|
7827
8296
|
MIN_PYTHON = [3, 12];
|
|
7828
8297
|
MIN_PYTHON_LABEL = MIN_PYTHON.join(".");
|
|
7829
8298
|
DIAGNOSTIC_TAIL = 600;
|
|
8299
|
+
FORWARDED_ENV = ["VIRTUAL_ENV", "GATEWAY_SNAPSHOT_STORE"];
|
|
7830
8300
|
BRIDGE_BOOTSTRAP = `import sys,runpy,types,os
|
|
7831
8301
|
root=sys.argv[1]
|
|
7832
8302
|
package=types.ModuleType('gatewaysdk')
|
|
@@ -8455,18 +8925,22 @@ if (fn) {
|
|
|
8455
8925
|
});
|
|
8456
8926
|
|
|
8457
8927
|
// src/cli/platform/worldData/batches.ts
|
|
8458
|
-
import { createHash as
|
|
8928
|
+
import { createHash as createHash8 } from "crypto";
|
|
8459
8929
|
import * as fs11 from "fs";
|
|
8460
8930
|
function isSettled(status) {
|
|
8461
8931
|
if (!TERMINAL_STATES.has(status.state)) return false;
|
|
8462
8932
|
if (status.state !== "applied") return true;
|
|
8463
8933
|
return status.dryRun === true || status.publish !== "now" || !status.snapshotId;
|
|
8464
8934
|
}
|
|
8935
|
+
function worldDataPollMs() {
|
|
8936
|
+
const raw = Number(process.env.GATEWAY_WORLD_DATA_POLL_MS ?? 1e3);
|
|
8937
|
+
return Number.isFinite(raw) && raw >= 0 ? raw : 1e3;
|
|
8938
|
+
}
|
|
8465
8939
|
function uploadHeadersFor(gz) {
|
|
8466
8940
|
return {
|
|
8467
8941
|
"content-type": "application/gzip",
|
|
8468
8942
|
"content-length": String(gz.length),
|
|
8469
|
-
"x-amz-checksum-sha256":
|
|
8943
|
+
"x-amz-checksum-sha256": createHash8("sha256").update(gz).digest("base64")
|
|
8470
8944
|
};
|
|
8471
8945
|
}
|
|
8472
8946
|
async function forEachLimited(items, limit, fn) {
|
|
@@ -8504,6 +8978,8 @@ async function waitForBatch(client, batchId, opts = {}) {
|
|
|
8504
8978
|
last = phase;
|
|
8505
8979
|
}
|
|
8506
8980
|
if (isSettled(status)) return status;
|
|
8981
|
+
if (opts.deadlineMs !== void 0 && (opts.now ?? Date.now)() >= opts.deadlineMs)
|
|
8982
|
+
return status;
|
|
8507
8983
|
await sleep4(delay);
|
|
8508
8984
|
delay = Math.min(1e4, Math.round(delay * 1.5));
|
|
8509
8985
|
}
|
|
@@ -8553,11 +9029,6 @@ var init_batches = __esm({
|
|
|
8553
9029
|
}
|
|
8554
9030
|
);
|
|
8555
9031
|
}
|
|
8556
|
-
/**
|
|
8557
|
-
* Stage a project-drive rows file as one chunk, on the platform: the server
|
|
8558
|
-
* streams it out of drive storage into chunk storage and answers with the
|
|
8559
|
-
* digest and gzipped size it derived. No bytes pass through this process.
|
|
8560
|
-
*/
|
|
8561
9032
|
async stageDrive(batchId, chunk) {
|
|
8562
9033
|
const staged = await api(this.creds, "POST", `${this.base}/batches/${batchId}/chunks`, {
|
|
8563
9034
|
ordinal: chunk.ordinal,
|
|
@@ -8611,11 +9082,6 @@ var init_batches = __esm({
|
|
|
8611
9082
|
message ? { message } : {}
|
|
8612
9083
|
);
|
|
8613
9084
|
}
|
|
8614
|
-
/**
|
|
8615
|
-
* PUT the gzipped chunk to its presigned URL with exactly the headers the
|
|
8616
|
-
* URL was signed for (the platform's `uploadHeaders`; the same three when it
|
|
8617
|
-
* sends none), with backoff on a dropped connection or a 5xx.
|
|
8618
|
-
*/
|
|
8619
9085
|
async put(uploadUrl, gz, signed) {
|
|
8620
9086
|
const headers = signed ?? uploadHeadersFor(gz);
|
|
8621
9087
|
const delays = [500, 1500, 4e3];
|
|
@@ -8642,7 +9108,6 @@ var init_batches = __esm({
|
|
|
8642
9108
|
await this.sleep(delays[attempt]);
|
|
8643
9109
|
}
|
|
8644
9110
|
}
|
|
8645
|
-
/** Register, upload unless the server already holds the content, confirm. */
|
|
8646
9111
|
async upload(batchId, chunk) {
|
|
8647
9112
|
const registered = await this.register(batchId, chunk);
|
|
8648
9113
|
if (!registered.uploaded) {
|
|
@@ -8669,7 +9134,7 @@ var init_batches = __esm({
|
|
|
8669
9134
|
});
|
|
8670
9135
|
|
|
8671
9136
|
// src/cli/platform/worldData/chunker.ts
|
|
8672
|
-
import { createHash as
|
|
9137
|
+
import { createHash as createHash9 } from "crypto";
|
|
8673
9138
|
import { deflateRawSync } from "zlib";
|
|
8674
9139
|
function chunkLine(row, declared) {
|
|
8675
9140
|
if (declared !== null) return dumps(row.row) + "\n";
|
|
@@ -8710,12 +9175,12 @@ function finishChunk(ordinal, raw, rows, entity, firstRow = 0) {
|
|
|
8710
9175
|
const gz = gzipDeterministic(raw, { name: chunkName(ordinal) });
|
|
8711
9176
|
return {
|
|
8712
9177
|
ordinal,
|
|
8713
|
-
digest:
|
|
9178
|
+
digest: createHash9("sha256").update(gz).digest("hex"),
|
|
8714
9179
|
bytes: gz.length,
|
|
8715
9180
|
rows,
|
|
8716
9181
|
entity,
|
|
8717
9182
|
rawBytes: raw.length,
|
|
8718
|
-
contentSha256:
|
|
9183
|
+
contentSha256: createHash9("sha256").update(raw).digest("hex"),
|
|
8719
9184
|
firstRow,
|
|
8720
9185
|
gz
|
|
8721
9186
|
};
|
|
@@ -8783,22 +9248,33 @@ async function pushRows(creds, slug, rows, opts = {}) {
|
|
|
8783
9248
|
publish: opts.publish ?? "now",
|
|
8784
9249
|
...opts.message ? { message: opts.message } : {}
|
|
8785
9250
|
});
|
|
8786
|
-
if (!opened.batchId)
|
|
9251
|
+
if (!opened.batchId)
|
|
9252
|
+
throw new Error("the platform opened no batch (no batchId in the answer)");
|
|
8787
9253
|
const tagged = (async function* () {
|
|
8788
9254
|
for (const [entity, listed] of Object.entries(rows))
|
|
8789
9255
|
for (let index = 0; index < listed.length; index++)
|
|
8790
|
-
yield {
|
|
9256
|
+
yield {
|
|
9257
|
+
entity,
|
|
9258
|
+
row: parseJson(JSON.stringify(listed[index])),
|
|
9259
|
+
where: `${entity}[${index}]`
|
|
9260
|
+
};
|
|
8791
9261
|
})();
|
|
8792
|
-
const chunks = buildChunks(tagged, {
|
|
8793
|
-
|
|
8794
|
-
|
|
9262
|
+
const chunks = buildChunks(tagged, {
|
|
9263
|
+
chunkBytes: opts.chunkBytes ?? DEFAULT_CHUNK_BYTES,
|
|
9264
|
+
chunkRows: null,
|
|
9265
|
+
entity: null
|
|
8795
9266
|
});
|
|
9267
|
+
await forEachLimited(
|
|
9268
|
+
chunks,
|
|
9269
|
+
Math.max(1, opts.parallel ?? 4),
|
|
9270
|
+
async (chunk) => {
|
|
9271
|
+
await client.upload(opened.batchId, chunk);
|
|
9272
|
+
}
|
|
9273
|
+
);
|
|
8796
9274
|
await client.complete(opened.batchId);
|
|
8797
|
-
return waitForBatch(client, opened.batchId, {
|
|
8798
|
-
|
|
8799
|
-
|
|
8800
|
-
const raw = Number(process.env.GATEWAY_WORLD_DATA_POLL_MS ?? 1e3);
|
|
8801
|
-
return Number.isFinite(raw) && raw >= 0 ? raw : 1e3;
|
|
9275
|
+
return waitForBatch(client, opened.batchId, {
|
|
9276
|
+
initialDelayMs: worldDataPollMs()
|
|
9277
|
+
});
|
|
8802
9278
|
}
|
|
8803
9279
|
var init_push = __esm({
|
|
8804
9280
|
"src/cli/platform/worldData/push.ts"() {
|
|
@@ -9047,12 +9523,12 @@ var init_ingest = __esm({
|
|
|
9047
9523
|
});
|
|
9048
9524
|
|
|
9049
9525
|
// src/worlds/editSessions.ts
|
|
9050
|
-
var
|
|
9526
|
+
var WORLDS2, WorldEditClient, TASK_EDITS, TaskEditClient;
|
|
9051
9527
|
var init_editSessions = __esm({
|
|
9052
9528
|
"src/worlds/editSessions.ts"() {
|
|
9053
9529
|
"use strict";
|
|
9054
9530
|
init_worlds();
|
|
9055
|
-
|
|
9531
|
+
WORLDS2 = "/api/public/worlds";
|
|
9056
9532
|
WorldEditClient = class {
|
|
9057
9533
|
constructor(options = {}) {
|
|
9058
9534
|
this.options = options;
|
|
@@ -9064,19 +9540,19 @@ var init_editSessions = __esm({
|
|
|
9064
9540
|
if (query.status) qs.set("status", query.status);
|
|
9065
9541
|
if (query.limit !== void 0) qs.set("limit", String(query.limit));
|
|
9066
9542
|
const suffix = qs.size ? `?${qs.toString()}` : "";
|
|
9067
|
-
return apiRequest(this.options, "GET", `${
|
|
9543
|
+
return apiRequest(this.options, "GET", `${WORLDS2}/${encodeURIComponent(slug)}/edits${suffix}`);
|
|
9068
9544
|
}
|
|
9069
9545
|
/** Seal a session into a version on main (the credential's current one when `sessionId` is omitted). */
|
|
9070
9546
|
close(slug, input = {}) {
|
|
9071
|
-
return apiRequest(this.options, "POST", `${
|
|
9547
|
+
return apiRequest(this.options, "POST", `${WORLDS2}/${encodeURIComponent(slug)}/edits/close`, input);
|
|
9072
9548
|
}
|
|
9073
9549
|
/** Drop the session's private branch without making a version. */
|
|
9074
9550
|
discard(slug, input = {}) {
|
|
9075
|
-
return apiRequest(this.options, "POST", `${
|
|
9551
|
+
return apiRequest(this.options, "POST", `${WORLDS2}/${encodeURIComponent(slug)}/edits/discard`, input);
|
|
9076
9552
|
}
|
|
9077
9553
|
/** Undo a sealed session (source and data) as a new sealed session. */
|
|
9078
9554
|
rollback(slug, input) {
|
|
9079
|
-
return apiRequest(this.options, "POST", `${
|
|
9555
|
+
return apiRequest(this.options, "POST", `${WORLDS2}/${encodeURIComponent(slug)}/edits/rollback`, input);
|
|
9080
9556
|
}
|
|
9081
9557
|
};
|
|
9082
9558
|
TASK_EDITS = "/api/public/world-task-edits";
|
|
@@ -9230,15 +9706,27 @@ __export(worlds_exports, {
|
|
|
9230
9706
|
NativeComputer: () => NativeComputer,
|
|
9231
9707
|
OpenAIComputer: () => OpenAIComputer,
|
|
9232
9708
|
OpenAIPreviewComputer: () => OpenAIPreviewComputer,
|
|
9709
|
+
PLATFORM_SESSION_HEADER: () => PLATFORM_SESSION_HEADER,
|
|
9233
9710
|
PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
9234
9711
|
PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
|
|
9235
9712
|
PendingSafetyChecks: () => PendingSafetyChecks,
|
|
9236
9713
|
PlatformTransport: () => PlatformTransport,
|
|
9237
9714
|
PushSlugConflict: () => PushSlugConflict,
|
|
9238
9715
|
RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
|
|
9716
|
+
REQUESTS_NOT_RECORDED: () => REQUESTS_NOT_RECORDED,
|
|
9717
|
+
REQUEST_BODY_CAPTURE_BYTES: () => REQUEST_BODY_CAPTURE_BYTES,
|
|
9718
|
+
REQUEST_LOG_PAGE_MAX: () => REQUEST_LOG_PAGE_MAX,
|
|
9239
9719
|
RetryPolicy: () => RetryPolicy,
|
|
9720
|
+
SANDBOX_EXEC_REPORT_MARGIN_MS: () => SANDBOX_EXEC_REPORT_MARGIN_MS,
|
|
9721
|
+
SANDBOX_EXEC_START_ATTEMPTS: () => SANDBOX_EXEC_START_ATTEMPTS,
|
|
9722
|
+
SANDBOX_EXEC_TIMEOUT_MAX_S: () => SANDBOX_EXEC_TIMEOUT_MAX_S,
|
|
9723
|
+
SANDBOX_EXEC_WAIT_MS: () => SANDBOX_EXEC_WAIT_MS,
|
|
9724
|
+
SANDBOX_FILE_MAX_BYTES: () => SANDBOX_FILE_MAX_BYTES,
|
|
9240
9725
|
SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
|
|
9726
|
+
SANDBOX_WRITE_CHUNK_BYTES: () => SANDBOX_WRITE_CHUNK_BYTES,
|
|
9727
|
+
SANDBOX_WRITE_SKIPPED: () => SANDBOX_WRITE_SKIPPED,
|
|
9241
9728
|
SECRET_KEY: () => SECRET_KEY,
|
|
9729
|
+
SESSION_AUTH_MODES: () => SESSION_AUTH_MODES,
|
|
9242
9730
|
SESSION_STATES: () => SESSION_STATES,
|
|
9243
9731
|
SPAN_PREFIX: () => SPAN_PREFIX,
|
|
9244
9732
|
STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
|
|
@@ -9250,17 +9738,23 @@ __export(worlds_exports, {
|
|
|
9250
9738
|
TOOL_CONTRACT_UNREAD: () => TOOL_CONTRACT_UNREAD,
|
|
9251
9739
|
TRANSFORMS: () => TRANSFORMS,
|
|
9252
9740
|
TaskEditClient: () => TaskEditClient,
|
|
9741
|
+
TaskGrades: () => TaskGrades,
|
|
9253
9742
|
TaskRun: () => TaskRun,
|
|
9254
9743
|
TaskSessions: () => TaskSessions,
|
|
9255
9744
|
TransportCause: () => TransportCause,
|
|
9256
9745
|
UnreachableError: () => UnreachableError,
|
|
9257
9746
|
VERIFIER_REWARD_PREFIX: () => VERIFIER_REWARD_PREFIX,
|
|
9258
9747
|
WHITESPACE: () => WHITESPACE,
|
|
9748
|
+
WORLD_REQUEST_VIAS: () => WORLD_REQUEST_VIAS,
|
|
9259
9749
|
WorldBrowser: () => WorldBrowser,
|
|
9260
9750
|
WorldCallTooLarge: () => WorldCallTooLarge,
|
|
9261
9751
|
WorldEditClient: () => WorldEditClient,
|
|
9262
9752
|
WorldNotice: () => WorldNotice,
|
|
9753
|
+
WorldRequestFilterError: () => WorldRequestFilterError,
|
|
9754
|
+
WorldRequestLedger: () => WorldRequestLedger,
|
|
9263
9755
|
WorldRequestLog: () => WorldRequestLog,
|
|
9756
|
+
WorldRequestQuery: () => WorldRequestQuery,
|
|
9757
|
+
WorldRequestsNotRecorded: () => WorldRequestsNotRecorded,
|
|
9264
9758
|
WorldSandboxClient: () => WorldSandboxClient,
|
|
9265
9759
|
WorldSession: () => WorldSession,
|
|
9266
9760
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
@@ -9270,18 +9764,22 @@ __export(worlds_exports, {
|
|
|
9270
9764
|
WorldSurfaceUnavailable: () => WorldSurfaceUnavailable,
|
|
9271
9765
|
WorldTask: () => WorldTask,
|
|
9272
9766
|
WorldToolsUnread: () => WorldToolsUnread,
|
|
9767
|
+
WriteTreeFilter: () => WriteTreeFilter,
|
|
9273
9768
|
aggregateTaskGrade: () => aggregateTaskGrade,
|
|
9274
9769
|
apiRequest: () => apiRequest,
|
|
9275
9770
|
applyTransforms: () => applyTransforms,
|
|
9276
9771
|
archiveMode: () => archiveMode,
|
|
9277
9772
|
assertBrowserTier: () => assertBrowserTier,
|
|
9773
|
+
assertSessionAuthMode: () => assertSessionAuthMode,
|
|
9278
9774
|
assertTaskRef: () => assertTaskRef,
|
|
9279
9775
|
attachManifest: () => attachManifest,
|
|
9280
9776
|
attachSession: () => attachSession,
|
|
9281
9777
|
attachTask: () => attachTask,
|
|
9282
9778
|
buildFileManifest: () => buildFileManifest,
|
|
9283
9779
|
buildSourceTarball: () => buildSourceTarball,
|
|
9780
|
+
capabilityLabel: () => capabilityLabel,
|
|
9284
9781
|
captureToolCalls: () => captureToolCalls,
|
|
9782
|
+
carriedWarnings: () => carriedWarnings,
|
|
9285
9783
|
checkoutIdentity: () => checkoutIdentity,
|
|
9286
9784
|
closeConnection: () => closeConnection,
|
|
9287
9785
|
collectArchiveRelPaths: () => collectArchiveRelPaths,
|
|
@@ -9300,7 +9798,9 @@ __export(worlds_exports, {
|
|
|
9300
9798
|
idleWarning: () => idleWarning,
|
|
9301
9799
|
ingest: () => ingest,
|
|
9302
9800
|
ingestToolCalls: () => ingestToolCalls,
|
|
9801
|
+
invalidFields: () => invalidFields,
|
|
9303
9802
|
isBrowserGone: () => isBrowserGone,
|
|
9803
|
+
isSandboxCommitPending: () => isSandboxCommitPending,
|
|
9304
9804
|
isSandboxImportPending: () => isSandboxImportPending,
|
|
9305
9805
|
isTaskIdRef: () => isTaskIdRef,
|
|
9306
9806
|
isTaskManifest: () => isTaskManifest,
|
|
@@ -9347,6 +9847,7 @@ __export(worlds_exports, {
|
|
|
9347
9847
|
resolveBrowserMode: () => resolveBrowserMode,
|
|
9348
9848
|
resolvePushSlug: () => resolvePushSlug,
|
|
9349
9849
|
roundForm: () => roundForm,
|
|
9850
|
+
rowsRefusal: () => rowsRefusal,
|
|
9350
9851
|
runSessions: () => runSessions,
|
|
9351
9852
|
runSet: () => runSet,
|
|
9352
9853
|
runTask: () => runTask,
|
|
@@ -9375,27 +9876,42 @@ __export(worlds_exports, {
|
|
|
9375
9876
|
validateWorld: () => validateWorld,
|
|
9376
9877
|
waitForRun: () => waitForRun,
|
|
9377
9878
|
withoutUiToken: () => withoutUiToken,
|
|
9879
|
+
worldRequestsUnrecorded: () => worldRequestsUnrecorded,
|
|
9378
9880
|
writeLocalMeta: () => writeLocalMeta
|
|
9379
9881
|
});
|
|
9380
|
-
function
|
|
9381
|
-
|
|
9882
|
+
function edgeAnswer(text2, status) {
|
|
9883
|
+
if (status !== void 0 && status >= 500) return EDGE_ANSWERS[status] ?? EDGE_FAILURE;
|
|
9884
|
+
return /^\s*</.test(text2) ? EDGE_PAGE : null;
|
|
9885
|
+
}
|
|
9886
|
+
function parseErrorBody(text2, status) {
|
|
9887
|
+
const raw = { detail: text2.slice(0, DETAIL_LIMIT), code: null };
|
|
9382
9888
|
let parsed;
|
|
9383
9889
|
try {
|
|
9384
9890
|
parsed = JSON.parse(text2);
|
|
9385
9891
|
} catch {
|
|
9386
|
-
return
|
|
9892
|
+
return { detail: (edgeAnswer(text2, status) ?? text2).slice(0, DETAIL_LIMIT), code: null };
|
|
9387
9893
|
}
|
|
9388
9894
|
if (parsed === null || typeof parsed !== "object") return raw;
|
|
9389
|
-
const { message, code } = parsed;
|
|
9895
|
+
const { message, code, error } = parsed;
|
|
9390
9896
|
const stableCode = typeof code === "string" ? code : null;
|
|
9391
9897
|
if (typeof message !== "string") return { ...raw, code: stableCode };
|
|
9392
|
-
|
|
9393
|
-
|
|
9898
|
+
const fields = invalidFields(error);
|
|
9899
|
+
const said = fields ? `${message}: ${fields}` : message;
|
|
9900
|
+
if (stableCode === null) return { detail: said.slice(0, DETAIL_LIMIT), code: null };
|
|
9394
9901
|
return {
|
|
9395
|
-
detail: `${
|
|
9902
|
+
detail: `${said} (${stableCode})`.slice(0, DETAIL_LIMIT),
|
|
9396
9903
|
code: stableCode
|
|
9397
9904
|
};
|
|
9398
9905
|
}
|
|
9906
|
+
function invalidFields(error) {
|
|
9907
|
+
const issues = Array.isArray(error) ? error : [];
|
|
9908
|
+
return issues.filter(
|
|
9909
|
+
(issue) => issue !== null && typeof issue === "object" && typeof issue.message === "string"
|
|
9910
|
+
).map((issue) => {
|
|
9911
|
+
const path13 = Array.isArray(issue.path) ? issue.path.map(String).join(".") : "";
|
|
9912
|
+
return path13 ? `${path13}: ${issue.message}` : issue.message;
|
|
9913
|
+
}).join("; ");
|
|
9914
|
+
}
|
|
9399
9915
|
async function apiRequest(options, method, path13, body, init2 = {}) {
|
|
9400
9916
|
const reply = await new PlatformTransport(requirePlatformEndpoint(options)).send(method, path13, body, init2);
|
|
9401
9917
|
if (!reply.ok) throw new ApiError(reply.status, method, path13, reply.text);
|
|
@@ -9574,7 +10090,7 @@ async function resolveWorld(slugRef, slug, ref, pin, options) {
|
|
|
9574
10090
|
}
|
|
9575
10091
|
return world;
|
|
9576
10092
|
}
|
|
9577
|
-
var ApiError, WorldTask, WorldSet;
|
|
10093
|
+
var ApiError, DETAIL_LIMIT, EDGE_ANSWERS, EDGE_FAILURE, EDGE_PAGE, WorldTask, WorldSet;
|
|
9578
10094
|
var init_worlds = __esm({
|
|
9579
10095
|
"src/worlds/index.ts"() {
|
|
9580
10096
|
init_platformEndpoint();
|
|
@@ -9586,6 +10102,7 @@ var init_worlds = __esm({
|
|
|
9586
10102
|
init_sessionContract();
|
|
9587
10103
|
init_taskRef();
|
|
9588
10104
|
init_tasks();
|
|
10105
|
+
init_taskGrades();
|
|
9589
10106
|
init_taskSessions();
|
|
9590
10107
|
init_taskRun();
|
|
9591
10108
|
init_setRun();
|
|
@@ -9594,6 +10111,7 @@ var init_worlds = __esm({
|
|
|
9594
10111
|
init_browser();
|
|
9595
10112
|
init_surfaceDescriptor();
|
|
9596
10113
|
init_requestLog();
|
|
10114
|
+
init_requestLedger();
|
|
9597
10115
|
init_browserReconnect();
|
|
9598
10116
|
init_nativeComputer();
|
|
9599
10117
|
init_hub();
|
|
@@ -9610,7 +10128,7 @@ var init_worlds = __esm({
|
|
|
9610
10128
|
init_worldNotice();
|
|
9611
10129
|
ApiError = class extends Error {
|
|
9612
10130
|
constructor(status, method, path13, text2) {
|
|
9613
|
-
const parsed = parseErrorBody(text2);
|
|
10131
|
+
const parsed = parseErrorBody(text2, status);
|
|
9614
10132
|
super(`${method} ${path13} -> ${status}: ${parsed.detail}`);
|
|
9615
10133
|
this.status = status;
|
|
9616
10134
|
this.text = text2;
|
|
@@ -9621,6 +10139,14 @@ var init_worlds = __esm({
|
|
|
9621
10139
|
text;
|
|
9622
10140
|
code;
|
|
9623
10141
|
};
|
|
10142
|
+
DETAIL_LIMIT = 600;
|
|
10143
|
+
EDGE_ANSWERS = {
|
|
10144
|
+
502: "Bad Gateway from the load balancer in front of the platform, not the platform's answer: the web server dropped the connection or restarted mid-request. Retry; if it repeats, the platform is restarting or overloaded.",
|
|
10145
|
+
503: "Service Unavailable from the load balancer in front of the platform, not the platform's answer: no web server was ready to take the request (a deploy or a restart). Retry in a minute.",
|
|
10146
|
+
504: "Gateway Time-out from the load balancer in front of the platform, not the platform's answer: the request sent nothing back within the load balancer's idle timeout (60 s unless the deployment raises it: Helm ingress.idleTimeoutSeconds) and was cut there, though the platform may still be running it. Check what it changed before you retry."
|
|
10147
|
+
};
|
|
10148
|
+
EDGE_FAILURE = "The platform failed without its JSON error body: a proxy in front of it answered, or the server stopped before its error handler ran. Retry; if it repeats, report the request and the time.";
|
|
10149
|
+
EDGE_PAGE = "An HTML page answered instead of the platform's JSON: a proxy in front of the platform, or the configured host is not the platform.";
|
|
9624
10150
|
WorldTask = class {
|
|
9625
10151
|
constructor(world, name, variant) {
|
|
9626
10152
|
this.world = world;
|
|
@@ -9656,12 +10182,7 @@ var init_worlds = __esm({
|
|
|
9656
10182
|
}
|
|
9657
10183
|
return hit;
|
|
9658
10184
|
}
|
|
9659
|
-
/**
|
|
9660
|
-
* Open a LIVE session against one of this world's tasks — a bundled task's
|
|
9661
|
-
* name or an inline `WorldTaskSpec`: the platform boots (or reuses) a warm
|
|
9662
|
-
* container, and your agent calls its tools through the platform. See
|
|
9663
|
-
* worlds/session.ts.
|
|
9664
|
-
*/
|
|
10185
|
+
/** Open a live session on a bundled task's name or an inline `WorldTaskSpec`; the platform boots or reuses a warm container. */
|
|
9665
10186
|
async open(task, opts = {}) {
|
|
9666
10187
|
const { openSession: openSession2 } = await Promise.resolve().then(() => (init_session2(), session_exports2));
|
|
9667
10188
|
return openSession2(this.slug, {
|
|
@@ -9673,11 +10194,7 @@ var init_worlds = __esm({
|
|
|
9673
10194
|
options: this.options
|
|
9674
10195
|
});
|
|
9675
10196
|
}
|
|
9676
|
-
/**
|
|
9677
|
-
* Start a HOSTED run of a run config against this world — the platform
|
|
9678
|
-
* executes the (Python) world in parallel containers per the config's
|
|
9679
|
-
* `parallelism` and files one graded run per model. Returns those runs.
|
|
9680
|
-
*/
|
|
10197
|
+
/** Start a hosted run of a run config on this version (or `opts.versionId`): one graded run per model, provenance detected unless given. */
|
|
9681
10198
|
async dispatch(runConfigId, opts = {}) {
|
|
9682
10199
|
const provenance = opts.provenance ?? detectProvenance();
|
|
9683
10200
|
return apiRequest(
|
|
@@ -9737,15 +10254,27 @@ export {
|
|
|
9737
10254
|
NativeComputer,
|
|
9738
10255
|
OpenAIComputer,
|
|
9739
10256
|
OpenAIPreviewComputer,
|
|
10257
|
+
PLATFORM_SESSION_HEADER,
|
|
9740
10258
|
PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
9741
10259
|
PLATFORM_TIMEOUT_ENV,
|
|
9742
10260
|
PendingSafetyChecks,
|
|
9743
10261
|
PlatformTransport,
|
|
9744
10262
|
PushSlugConflict,
|
|
9745
10263
|
RECOVER_BUDGET_MS,
|
|
10264
|
+
REQUESTS_NOT_RECORDED,
|
|
10265
|
+
REQUEST_BODY_CAPTURE_BYTES,
|
|
10266
|
+
REQUEST_LOG_PAGE_MAX,
|
|
9746
10267
|
RetryPolicy,
|
|
10268
|
+
SANDBOX_EXEC_REPORT_MARGIN_MS,
|
|
10269
|
+
SANDBOX_EXEC_START_ATTEMPTS,
|
|
10270
|
+
SANDBOX_EXEC_TIMEOUT_MAX_S,
|
|
10271
|
+
SANDBOX_EXEC_WAIT_MS,
|
|
10272
|
+
SANDBOX_FILE_MAX_BYTES,
|
|
9747
10273
|
SANDBOX_REQUEST_TIMEOUT_MS,
|
|
10274
|
+
SANDBOX_WRITE_CHUNK_BYTES,
|
|
10275
|
+
SANDBOX_WRITE_SKIPPED,
|
|
9748
10276
|
SECRET_KEY,
|
|
10277
|
+
SESSION_AUTH_MODES,
|
|
9749
10278
|
SESSION_STATES,
|
|
9750
10279
|
SPAN_PREFIX,
|
|
9751
10280
|
STATUS_WAIT_CAP_SECONDS,
|
|
@@ -9757,17 +10286,23 @@ export {
|
|
|
9757
10286
|
TOOL_CONTRACT_UNREAD,
|
|
9758
10287
|
TRANSFORMS,
|
|
9759
10288
|
TaskEditClient,
|
|
10289
|
+
TaskGrades,
|
|
9760
10290
|
TaskRun,
|
|
9761
10291
|
TaskSessions,
|
|
9762
10292
|
TransportCause,
|
|
9763
10293
|
UnreachableError,
|
|
9764
10294
|
VERIFIER_REWARD_PREFIX,
|
|
9765
10295
|
WHITESPACE,
|
|
10296
|
+
WORLD_REQUEST_VIAS,
|
|
9766
10297
|
WorldBrowser,
|
|
9767
10298
|
WorldCallTooLarge,
|
|
9768
10299
|
WorldEditClient,
|
|
9769
10300
|
WorldNotice,
|
|
10301
|
+
WorldRequestFilterError,
|
|
10302
|
+
WorldRequestLedger,
|
|
9770
10303
|
WorldRequestLog,
|
|
10304
|
+
WorldRequestQuery,
|
|
10305
|
+
WorldRequestsNotRecorded,
|
|
9771
10306
|
WorldSandboxClient,
|
|
9772
10307
|
WorldSession,
|
|
9773
10308
|
WorldSessionCallError,
|
|
@@ -9777,18 +10312,22 @@ export {
|
|
|
9777
10312
|
WorldSurfaceUnavailable,
|
|
9778
10313
|
WorldTask,
|
|
9779
10314
|
WorldToolsUnread,
|
|
10315
|
+
WriteTreeFilter,
|
|
9780
10316
|
aggregateTaskGrade,
|
|
9781
10317
|
apiRequest,
|
|
9782
10318
|
applyTransforms,
|
|
9783
10319
|
archiveMode,
|
|
9784
10320
|
assertBrowserTier,
|
|
10321
|
+
assertSessionAuthMode,
|
|
9785
10322
|
assertTaskRef,
|
|
9786
10323
|
attachManifest,
|
|
9787
10324
|
attachSession,
|
|
9788
10325
|
attachTask,
|
|
9789
10326
|
buildFileManifest,
|
|
9790
10327
|
buildSourceTarball,
|
|
10328
|
+
capabilityLabel,
|
|
9791
10329
|
captureToolCalls,
|
|
10330
|
+
carriedWarnings,
|
|
9792
10331
|
checkoutIdentity,
|
|
9793
10332
|
closeConnection,
|
|
9794
10333
|
collectArchiveRelPaths,
|
|
@@ -9807,7 +10346,9 @@ export {
|
|
|
9807
10346
|
idleWarning,
|
|
9808
10347
|
ingest,
|
|
9809
10348
|
ingestToolCalls,
|
|
10349
|
+
invalidFields,
|
|
9810
10350
|
isBrowserGone,
|
|
10351
|
+
isSandboxCommitPending,
|
|
9811
10352
|
isSandboxImportPending,
|
|
9812
10353
|
isTaskIdRef,
|
|
9813
10354
|
isTaskManifest,
|
|
@@ -9854,6 +10395,7 @@ export {
|
|
|
9854
10395
|
resolveBrowserMode,
|
|
9855
10396
|
resolvePushSlug,
|
|
9856
10397
|
roundForm,
|
|
10398
|
+
rowsRefusal,
|
|
9857
10399
|
runSessions,
|
|
9858
10400
|
runSet,
|
|
9859
10401
|
runTask,
|
|
@@ -9882,6 +10424,7 @@ export {
|
|
|
9882
10424
|
validateWorld,
|
|
9883
10425
|
waitForRun,
|
|
9884
10426
|
withoutUiToken,
|
|
10427
|
+
worldRequestsUnrecorded,
|
|
9885
10428
|
writeLocalMeta
|
|
9886
10429
|
};
|
|
9887
10430
|
//# sourceMappingURL=index.mjs.map
|