@withgateway/sdk 0.3.3 → 0.6.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 +3005 -1401
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +2996 -1392
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.js +128 -37
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +126 -35
- 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-mJhG3vZU.d.mts → index-Di9nNqOY.d.mts} +26 -3
- package/dist/{index-DUHmS74p.d.ts → index-LA-PMRJT.d.ts} +26 -3
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1078 -260
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1040 -251
- package/dist/index.mjs.map +1 -1
- package/dist/replay/index.d.mts +1 -1
- package/dist/replay/index.d.ts +1 -1
- package/dist/replay/index.js.map +1 -1
- package/dist/replay/index.mjs.map +1 -1
- package/dist/traces/index.js +125 -34
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +123 -32
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.d.mts +1 -1
- package/dist/tracing/index.d.ts +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 +819 -438
- package/dist/worlds/index.d.ts +819 -438
- package/dist/worlds/index.js +912 -236
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +908 -232
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +1 -1
- package/runtime/gatewaysdk/environment/_bundle.py +4 -6
- package/runtime/gatewaysdk/environment/_materialize.py +5 -25
- package/runtime/gatewaysdk/environment/_world.py +82 -66
- 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/runtime.py +45 -2
- package/runtime/gatewaysdk/environment/schema/admission.py +174 -0
- package/runtime/gatewaysdk/environment/schema/api.py +198 -474
- package/runtime/gatewaysdk/environment/schema/assertions.py +458 -0
- package/runtime/gatewaysdk/environment/schema/batch.py +3 -3
- package/runtime/gatewaysdk/environment/schema/bundle_runtime.py +1 -0
- package/runtime/gatewaysdk/environment/schema/cache_layout.py +5 -0
- package/runtime/gatewaysdk/environment/schema/call_capture.py +321 -0
- package/runtime/gatewaysdk/environment/schema/call_log.py +276 -18
- package/runtime/gatewaysdk/environment/schema/call_redaction.py +207 -19
- package/runtime/gatewaysdk/environment/schema/cast.py +15 -35
- package/runtime/gatewaysdk/environment/schema/compiler.py +4 -1
- package/runtime/gatewaysdk/environment/schema/conform.py +38 -35
- package/runtime/gatewaysdk/environment/schema/connector.py +94 -152
- package/runtime/gatewaysdk/environment/schema/connectors/confluence/connector.toml +1 -12
- package/runtime/gatewaysdk/environment/schema/connectors/custom/handlers.py +2 -1
- package/runtime/gatewaysdk/environment/schema/connectors/github/api/handlers.py +217 -58
- package/runtime/gatewaysdk/environment/schema/connectors/github/connector.toml +10 -19
- package/runtime/gatewaysdk/environment/schema/connectors/github/scenarios/default/seed/github_webhooks.json +10 -2
- package/runtime/gatewaysdk/environment/schema/connectors/github/tests/webhooks.json +47 -0
- package/runtime/gatewaysdk/environment/schema/connectors/github/world.json +21 -0
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/api/handlers.py +185 -18
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/connector.toml +29 -14
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/provenance.json +43 -12
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/scenarios/default/seed/jamf_webhooks.json +2 -2
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/scope.toml +4 -17
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/tests/webhooks.json +107 -0
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/vendor-openapi.json +1 -1
- package/runtime/gatewaysdk/environment/schema/connectors/linear/api/handlers.py +85 -1
- package/runtime/gatewaysdk/environment/schema/connectors/linear/connector.toml +19 -31
- package/runtime/gatewaysdk/environment/schema/connectors/linear/provenance.json +18 -8
- package/runtime/gatewaysdk/environment/schema/connectors/linear/scenarios/default/seed/webhooks.json +19 -3
- package/runtime/gatewaysdk/environment/schema/connectors/linear/tests/test_webhooks.py +71 -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 +45 -37
- 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 +52 -5
- 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 +438 -0
- package/runtime/gatewaysdk/environment/schema/ledger_spill.py +828 -0
- package/runtime/gatewaysdk/environment/schema/local.py +32 -116
- package/runtime/gatewaysdk/environment/schema/openapi_schemas.py +20 -5
- package/runtime/gatewaysdk/environment/schema/platform.py +29 -234
- 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 +136 -176
- package/runtime/gatewaysdk/environment/schema/scaffold.py +2 -1
- 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/CONNECTORS.md +3 -3
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +50 -28
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/ROWS.md +12 -8
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +20 -22
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +25 -25
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +24 -16
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +71 -7
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/journal-checks.md +182 -0
- package/runtime/gatewaysdk/environment/schema/snapshot.py +150 -30
- 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 +103 -203
- package/runtime/gatewaysdk/environment/schema/validation.py +69 -1
- package/runtime/gatewaysdk/environment/schema/verbs.py +38 -36
- package/runtime/gatewaysdk/environment/schema/webhooks.py +687 -0
- 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 +970 -0
- package/runtime/gatewaysdk/environment/schema/world_tests.py +83 -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/CONNECTORS.md +3 -3
- package/skills/connector-schema-authoring/SKILL.md +50 -28
- package/skills/connector-schema-authoring/connector-worlds.md +282 -18
- package/skills/connector-schema-authoring/world-schema.md +7 -6
- package/skills/world-data-ingestion/ROWS.md +12 -8
- package/skills/world-data-ingestion/SKILL.md +20 -22
- package/skills/worlds-getting-started/SKILL.md +25 -25
- package/skills/worlds-getting-started/references/cli-mcp-map.md +24 -16
- package/skills/worlds-getting-started/references/gotchas.md +71 -7
- 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 },
|
|
@@ -107,11 +113,11 @@ var init_transport = __esm({
|
|
|
107
113
|
}
|
|
108
114
|
};
|
|
109
115
|
UnreachableError = class extends Error {
|
|
110
|
-
constructor(host, method,
|
|
111
|
-
super(`${method} ${
|
|
116
|
+
constructor(host, method, route2, failure) {
|
|
117
|
+
super(`${method} ${route2}: no answer from ${host}: ${failure.describe()}. ${failure.next}`);
|
|
112
118
|
this.host = host;
|
|
113
119
|
this.method = method;
|
|
114
|
-
this.route =
|
|
120
|
+
this.route = route2;
|
|
115
121
|
this.failure = failure;
|
|
116
122
|
this.name = "UnreachableError";
|
|
117
123
|
}
|
|
@@ -181,16 +187,16 @@ var init_transport = __esm({
|
|
|
181
187
|
budget(ownMs) {
|
|
182
188
|
return Math.max(ownMs ?? 0, this.timeoutMs);
|
|
183
189
|
}
|
|
184
|
-
async send(method,
|
|
190
|
+
async send(method, route2, body, opts = {}) {
|
|
185
191
|
const timeoutMs = this.budget(opts.timeoutMs);
|
|
186
|
-
return (opts.retry ?? RetryPolicy.NONE).run(() => this.once(method,
|
|
192
|
+
return (opts.retry ?? RetryPolicy.NONE).run(() => this.once(method, route2, body, timeoutMs));
|
|
187
193
|
}
|
|
188
|
-
async once(method,
|
|
194
|
+
async once(method, route2, body, timeoutMs) {
|
|
189
195
|
const payload = body === void 0 ? {} : { body: JSON.stringify(body) };
|
|
190
196
|
const controller = new AbortController();
|
|
191
197
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
192
198
|
try {
|
|
193
|
-
const res = await fetch(`${this.endpoint.host}${
|
|
199
|
+
const res = await fetch(`${this.endpoint.host}${route2}`, {
|
|
194
200
|
method,
|
|
195
201
|
headers: {
|
|
196
202
|
"content-type": "application/json",
|
|
@@ -203,7 +209,7 @@ var init_transport = __esm({
|
|
|
203
209
|
return { status: res.status, ok: res.ok, text: await res.text() };
|
|
204
210
|
} catch (error) {
|
|
205
211
|
const cause = controller.signal.aborted ? TransportCause.timeout(timeoutMs) : TransportCause.of(error);
|
|
206
|
-
throw new UnreachableError(this.endpoint.host, method,
|
|
212
|
+
throw new UnreachableError(this.endpoint.host, method, route2, cause);
|
|
207
213
|
} finally {
|
|
208
214
|
clearTimeout(timer);
|
|
209
215
|
}
|
|
@@ -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
|
|
@@ -1434,11 +1471,11 @@ var init_media = __esm({
|
|
|
1434
1471
|
status
|
|
1435
1472
|
);
|
|
1436
1473
|
}
|
|
1437
|
-
async send(method,
|
|
1438
|
-
const reply = await this.transport.send(method,
|
|
1474
|
+
async send(method, route2, body) {
|
|
1475
|
+
const reply = await this.transport.send(method, route2, body);
|
|
1439
1476
|
if (!reply.ok)
|
|
1440
1477
|
throw new MediaUploadError(
|
|
1441
|
-
`${method} ${
|
|
1478
|
+
`${method} ${route2} -> ${reply.status}`,
|
|
1442
1479
|
reply.status
|
|
1443
1480
|
);
|
|
1444
1481
|
return reply.text ? JSON.parse(reply.text) : {};
|
|
@@ -1791,7 +1828,7 @@ function click(button, count) {
|
|
|
1791
1828
|
modifiers: modifierChord(raw.text)
|
|
1792
1829
|
});
|
|
1793
1830
|
}
|
|
1794
|
-
var SCROLL_STEP_PX, NOT_EXECUTED, MAX_ERROR2, SCROLL_DIRECTIONS, MEMBERS, AnthropicComputer, AnthropicComputer20251124;
|
|
1831
|
+
var SCROLL_STEP_PX, NOT_EXECUTED, MAX_ERROR2, SCROLL_DIRECTIONS, IMAGE_PARTS, MEMBERS, AnthropicComputer, AnthropicComputer20251124;
|
|
1795
1832
|
var init_anthropic = __esm({
|
|
1796
1833
|
"src/worlds/nativeComputer/anthropic.ts"() {
|
|
1797
1834
|
"use strict";
|
|
@@ -1807,6 +1844,14 @@ var init_anthropic = __esm({
|
|
|
1807
1844
|
left: [-1, 0],
|
|
1808
1845
|
right: [1, 0]
|
|
1809
1846
|
};
|
|
1847
|
+
IMAGE_PARTS = {
|
|
1848
|
+
6: (data) => ({ type: "image-data", data, mediaType: "image/png" }),
|
|
1849
|
+
7: (data) => ({
|
|
1850
|
+
type: "file",
|
|
1851
|
+
mediaType: "image/png",
|
|
1852
|
+
data: { type: "data", data }
|
|
1853
|
+
})
|
|
1854
|
+
};
|
|
1810
1855
|
MEMBERS = {
|
|
1811
1856
|
screenshot: () => new ComputerAction("screenshot"),
|
|
1812
1857
|
zoom: (raw) => new ComputerAction("zoom", {
|
|
@@ -1916,15 +1961,17 @@ var init_anthropic = __esm({
|
|
|
1916
1961
|
];
|
|
1917
1962
|
return [{ type: "text", text: result.text ?? "OK" }];
|
|
1918
1963
|
}
|
|
1919
|
-
/** For `anthropic.tools.computerToolset_20260801(
|
|
1920
|
-
* (or `computer_20251124` with the legacy kind
|
|
1921
|
-
* and returns `{ type: "image", data }` or
|
|
1922
|
-
* into the tool result
|
|
1964
|
+
/** For `anthropic.tools.computerToolset_20260801(computer.aiSdk({ version: 7 }))`
|
|
1965
|
+
* (AI SDK 7 only), or `computer_20251124` with the legacy kind (AI SDK 6
|
|
1966
|
+
* and 7): `execute` runs one action and returns `{ type: "image", data }` or
|
|
1967
|
+
* text; `toModelOutput` turns that into the tool result in the part shape
|
|
1968
|
+
* of `options.version`. Calls run one at a time, and once a call fails the
|
|
1923
1969
|
* rest of that step's calls answer as not executed. */
|
|
1924
|
-
aiSdk() {
|
|
1970
|
+
aiSdk(options = {}) {
|
|
1971
|
+
const imagePart = _AnthropicComputer.imagePart(options);
|
|
1925
1972
|
let failedStep;
|
|
1926
|
-
const execute = (input,
|
|
1927
|
-
const step =
|
|
1973
|
+
const execute = (input, options2) => this.serial(async () => {
|
|
1974
|
+
const step = options2?.messages?.length;
|
|
1928
1975
|
if (step !== void 0 && step === failedStep)
|
|
1929
1976
|
throw new Error(NOT_EXECUTED);
|
|
1930
1977
|
try {
|
|
@@ -1936,7 +1983,7 @@ var init_anthropic = __esm({
|
|
|
1936
1983
|
});
|
|
1937
1984
|
return {
|
|
1938
1985
|
execute,
|
|
1939
|
-
toModelOutput: ({ output }) => _AnthropicComputer.
|
|
1986
|
+
toModelOutput: ({ output }) => _AnthropicComputer.modelOutput(output, imagePart)
|
|
1940
1987
|
};
|
|
1941
1988
|
}
|
|
1942
1989
|
static aiSdkOutput(result) {
|
|
@@ -1944,16 +1991,26 @@ var init_anthropic = __esm({
|
|
|
1944
1991
|
return { type: "image", data: result.image.toString("base64") };
|
|
1945
1992
|
return result.text ?? "OK";
|
|
1946
1993
|
}
|
|
1947
|
-
/**
|
|
1948
|
-
*
|
|
1949
|
-
|
|
1994
|
+
/** A screenshot as the image part of AI SDK `options.version`:
|
|
1995
|
+
* `image-data` for 6 (the default), `file` with `{ type: "data", data }`
|
|
1996
|
+
* for 7. */
|
|
1997
|
+
static aiSdkModelOutput(output, options = {}) {
|
|
1998
|
+
return _AnthropicComputer.modelOutput(
|
|
1999
|
+
output,
|
|
2000
|
+
_AnthropicComputer.imagePart(options)
|
|
2001
|
+
);
|
|
2002
|
+
}
|
|
2003
|
+
static imagePart({
|
|
2004
|
+
version = 6
|
|
2005
|
+
}) {
|
|
2006
|
+
if (Object.hasOwn(IMAGE_PARTS, version)) return IMAGE_PARTS[version];
|
|
2007
|
+
throw new Error(
|
|
2008
|
+
`unsupported AI SDK version ${version}; choose ${Object.keys(IMAGE_PARTS).join(" or ")}`
|
|
2009
|
+
);
|
|
2010
|
+
}
|
|
2011
|
+
static modelOutput(output, imagePart) {
|
|
1950
2012
|
if (typeof output === "string") return { type: "text", value: output };
|
|
1951
|
-
return {
|
|
1952
|
-
type: "content",
|
|
1953
|
-
value: [
|
|
1954
|
-
{ type: "image-data", data: output.data, mediaType: "image/png" }
|
|
1955
|
-
]
|
|
1956
|
-
};
|
|
2013
|
+
return { type: "content", value: [imagePart(output.data)] };
|
|
1957
2014
|
}
|
|
1958
2015
|
envelope(block, content, isError = false) {
|
|
1959
2016
|
return {
|
|
@@ -2243,13 +2300,16 @@ function idleWarning(idleExpiresAt, now = /* @__PURE__ */ new Date()) {
|
|
|
2243
2300
|
const minutes = Math.max(0, Math.floor(leftMs / 6e4));
|
|
2244
2301
|
return `warning: session expires in ${minutes}m (idle TTL); call a tool to extend it or \`gateway worlds session pin\` to keep it`;
|
|
2245
2302
|
}
|
|
2246
|
-
var CALL_BODY_LIMIT_BYTES, CALL_BODY_LIMIT_LABEL, IDLE_WARNING_MINUTES, EXPLORATORY_TASK, EXPLORATORY_TASK_SOURCE, NO_GRADER_REASON, WorldCallTooLarge, stillStartingHint;
|
|
2303
|
+
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
2304
|
var init_sessionContract = __esm({
|
|
2248
2305
|
"src/worlds/sessionContract.ts"() {
|
|
2249
2306
|
"use strict";
|
|
2250
2307
|
CALL_BODY_LIMIT_BYTES = 4 * 1024 * 1024;
|
|
2251
2308
|
CALL_BODY_LIMIT_LABEL = "4mb";
|
|
2252
2309
|
IDLE_WARNING_MINUTES = 5;
|
|
2310
|
+
REQUEST_LOG_PAGE_MAX = 200;
|
|
2311
|
+
REQUEST_BODY_CAPTURE_BYTES = 64 * 1024;
|
|
2312
|
+
REQUESTS_NOT_RECORDED = "requests_not_recorded";
|
|
2253
2313
|
EXPLORATORY_TASK = Object.freeze({
|
|
2254
2314
|
instruction: "exploratory session"
|
|
2255
2315
|
});
|
|
@@ -2283,6 +2343,217 @@ var init_sessionContract = __esm({
|
|
|
2283
2343
|
}
|
|
2284
2344
|
});
|
|
2285
2345
|
|
|
2346
|
+
// src/worlds/toolSchema.ts
|
|
2347
|
+
function schemaFromSignature(spec) {
|
|
2348
|
+
if (spec.inputSchema)
|
|
2349
|
+
return {
|
|
2350
|
+
type: "function",
|
|
2351
|
+
function: {
|
|
2352
|
+
name: modelToolName(spec.name),
|
|
2353
|
+
description: spec.doc ?? spec.name,
|
|
2354
|
+
parameters: spec.inputSchema
|
|
2355
|
+
}
|
|
2356
|
+
};
|
|
2357
|
+
const inside = /\(([\s\S]*)\)\s*$/.exec(spec.signature.trim())?.[1] ?? "";
|
|
2358
|
+
const properties = {};
|
|
2359
|
+
const required2 = [];
|
|
2360
|
+
const params = [];
|
|
2361
|
+
let depth = 0;
|
|
2362
|
+
let current = "";
|
|
2363
|
+
for (const ch of inside) {
|
|
2364
|
+
if ("([{".includes(ch)) depth++;
|
|
2365
|
+
if (")]}".includes(ch)) depth--;
|
|
2366
|
+
if (ch === "," && depth === 0) {
|
|
2367
|
+
params.push(current);
|
|
2368
|
+
current = "";
|
|
2369
|
+
} else current += ch;
|
|
2370
|
+
}
|
|
2371
|
+
if (current.trim()) params.push(current);
|
|
2372
|
+
for (const raw of params) {
|
|
2373
|
+
const param = raw.trim();
|
|
2374
|
+
if (!param || param.startsWith("*") || param === "self") continue;
|
|
2375
|
+
const eq = param.indexOf("=");
|
|
2376
|
+
const name = (eq === -1 ? param : param.slice(0, eq)).split(":")[0].trim();
|
|
2377
|
+
if (!name) continue;
|
|
2378
|
+
if (eq === -1) {
|
|
2379
|
+
properties[name] = { type: "string" };
|
|
2380
|
+
required2.push(name);
|
|
2381
|
+
continue;
|
|
2382
|
+
}
|
|
2383
|
+
const value = param.slice(eq + 1).trim();
|
|
2384
|
+
if (/^-?\d+(\.\d+)?$/.test(value)) properties[name] = { type: "number" };
|
|
2385
|
+
else if (value === "True" || value === "False")
|
|
2386
|
+
properties[name] = { type: "boolean" };
|
|
2387
|
+
else properties[name] = { type: "string" };
|
|
2388
|
+
}
|
|
2389
|
+
return {
|
|
2390
|
+
type: "function",
|
|
2391
|
+
function: {
|
|
2392
|
+
name: modelToolName(spec.name),
|
|
2393
|
+
description: spec.doc ?? spec.name,
|
|
2394
|
+
parameters: { type: "object", properties, required: required2 }
|
|
2395
|
+
}
|
|
2396
|
+
};
|
|
2397
|
+
}
|
|
2398
|
+
var modelToolName;
|
|
2399
|
+
var init_toolSchema = __esm({
|
|
2400
|
+
"src/worlds/toolSchema.ts"() {
|
|
2401
|
+
"use strict";
|
|
2402
|
+
modelToolName = (name) => name.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 64) || "tool";
|
|
2403
|
+
}
|
|
2404
|
+
});
|
|
2405
|
+
|
|
2406
|
+
// src/worlds/requestLedger.ts
|
|
2407
|
+
function platformMessage(text2) {
|
|
2408
|
+
try {
|
|
2409
|
+
const { message } = JSON.parse(text2);
|
|
2410
|
+
return typeof message === "string" ? message : null;
|
|
2411
|
+
} catch {
|
|
2412
|
+
return null;
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2415
|
+
var WORLD_REQUEST_VIAS, WorldRequestFilterError, NOT_RECORDED, WorldRequestsNotRecorded, STATUS, INSTANT, WORLDS, SESSIONS, Instant, WorldRequestQuery, WorldRequestLedger;
|
|
2416
|
+
var init_requestLedger = __esm({
|
|
2417
|
+
"src/worlds/requestLedger.ts"() {
|
|
2418
|
+
"use strict";
|
|
2419
|
+
init_worlds();
|
|
2420
|
+
init_sessionContract();
|
|
2421
|
+
WORLD_REQUEST_VIAS = ["api", "ui", "tool", "webhook"];
|
|
2422
|
+
WorldRequestFilterError = class extends Error {
|
|
2423
|
+
};
|
|
2424
|
+
NOT_RECORDED = "This session's engine records no requests; only hosted World Host sessions do.";
|
|
2425
|
+
WorldRequestsNotRecorded = class _WorldRequestsNotRecorded extends Error {
|
|
2426
|
+
static from(error) {
|
|
2427
|
+
if (!(error instanceof ApiError) || error.code !== REQUESTS_NOT_RECORDED) return error;
|
|
2428
|
+
return new _WorldRequestsNotRecorded(platformMessage(error.text) || NOT_RECORDED);
|
|
2429
|
+
}
|
|
2430
|
+
static async mapped(read) {
|
|
2431
|
+
try {
|
|
2432
|
+
return await read;
|
|
2433
|
+
} catch (error) {
|
|
2434
|
+
throw _WorldRequestsNotRecorded.from(error);
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
};
|
|
2438
|
+
STATUS = /^(?:[1-5]\d\d|[1-5]xx)$/;
|
|
2439
|
+
INSTANT = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
2440
|
+
WORLDS = "/api/public/worlds";
|
|
2441
|
+
SESSIONS = "/api/public/world-sessions";
|
|
2442
|
+
Instant = class _Instant {
|
|
2443
|
+
static parse(flag, raw) {
|
|
2444
|
+
const match = INSTANT.exec(raw);
|
|
2445
|
+
const millis = match ? _Instant.fromParts(match) : null;
|
|
2446
|
+
if (millis === null)
|
|
2447
|
+
throw new WorldRequestFilterError(
|
|
2448
|
+
`--${flag} must be an ISO 8601 date or time (2026-10-05, 2026-10-05T14:30:00Z), not \`${raw}\`.`
|
|
2449
|
+
);
|
|
2450
|
+
return millis;
|
|
2451
|
+
}
|
|
2452
|
+
static fromParts(match) {
|
|
2453
|
+
const [year, month, day, hour, minute, second] = [1, 2, 3, 4, 5, 6].map((i) => Number(match[i] ?? 0));
|
|
2454
|
+
const offset = _Instant.offsetMinutes(match[8]);
|
|
2455
|
+
if (offset === null || year < 1 || hour > 23 || minute > 59 || second > 59) return null;
|
|
2456
|
+
const date = /* @__PURE__ */ new Date(0);
|
|
2457
|
+
date.setUTCFullYear(year, month - 1, day);
|
|
2458
|
+
if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month - 1 || date.getUTCDate() !== day) return null;
|
|
2459
|
+
date.setUTCHours(hour, minute, second, Number((match[7] ?? "").padEnd(3, "0")));
|
|
2460
|
+
const utc = date.getTime() - offset * 6e4;
|
|
2461
|
+
const utcYear = new Date(utc).getUTCFullYear();
|
|
2462
|
+
return utcYear < 1 || utcYear > 9999 ? null : utc;
|
|
2463
|
+
}
|
|
2464
|
+
static offsetMinutes(zone) {
|
|
2465
|
+
if (zone === void 0 || zone === "Z") return 0;
|
|
2466
|
+
const hours = Number(zone.slice(1, 3));
|
|
2467
|
+
const minutes = Number(zone.slice(4, 6));
|
|
2468
|
+
if (hours > 23 || minutes > 59) return null;
|
|
2469
|
+
return (zone.startsWith("-") ? -1 : 1) * (hours * 60 + minutes);
|
|
2470
|
+
}
|
|
2471
|
+
};
|
|
2472
|
+
WorldRequestQuery = class _WorldRequestQuery {
|
|
2473
|
+
constructor(entries) {
|
|
2474
|
+
this.entries = entries;
|
|
2475
|
+
}
|
|
2476
|
+
entries;
|
|
2477
|
+
static parse(filter = {}) {
|
|
2478
|
+
const via = _WorldRequestQuery.via(filter.via);
|
|
2479
|
+
const status = _WorldRequestQuery.status(filter.status);
|
|
2480
|
+
const since = filter.since === void 0 ? void 0 : Instant.parse("since", filter.since);
|
|
2481
|
+
const until = filter.until === void 0 ? void 0 : Instant.parse("until", filter.until);
|
|
2482
|
+
if (since !== void 0 && until !== void 0 && since > until)
|
|
2483
|
+
throw new WorldRequestFilterError("--since must not be after --until.");
|
|
2484
|
+
const values = [
|
|
2485
|
+
["session", filter.session],
|
|
2486
|
+
["version", filter.version],
|
|
2487
|
+
["via", via],
|
|
2488
|
+
["operation", filter.operation],
|
|
2489
|
+
["status", status],
|
|
2490
|
+
["since", since === void 0 ? void 0 : new Date(since).toISOString()],
|
|
2491
|
+
["until", until === void 0 ? void 0 : new Date(until).toISOString()],
|
|
2492
|
+
["limit", filter.limit === void 0 ? void 0 : String(filter.limit)],
|
|
2493
|
+
["cursor", filter.cursor]
|
|
2494
|
+
];
|
|
2495
|
+
return new _WorldRequestQuery(values.filter((entry) => entry[1] !== void 0));
|
|
2496
|
+
}
|
|
2497
|
+
static via(value) {
|
|
2498
|
+
if (value === void 0) return void 0;
|
|
2499
|
+
const lower = value.toLowerCase();
|
|
2500
|
+
if (WORLD_REQUEST_VIAS.includes(lower)) return lower;
|
|
2501
|
+
throw new WorldRequestFilterError(`--via must be one of ${WORLD_REQUEST_VIAS.join(", ")}, not \`${value}\`.`);
|
|
2502
|
+
}
|
|
2503
|
+
static status(value) {
|
|
2504
|
+
if (value === void 0) return void 0;
|
|
2505
|
+
const lower = value.toLowerCase();
|
|
2506
|
+
if (STATUS.test(lower)) return lower;
|
|
2507
|
+
throw new WorldRequestFilterError(`--status must be a code (200) or a class (2xx), not \`${value}\`.`);
|
|
2508
|
+
}
|
|
2509
|
+
get filtered() {
|
|
2510
|
+
return this.entries.some(([key]) => key !== "limit");
|
|
2511
|
+
}
|
|
2512
|
+
params() {
|
|
2513
|
+
return this.entries.map(([key, value]) => [key, value]);
|
|
2514
|
+
}
|
|
2515
|
+
search() {
|
|
2516
|
+
return this.entries.length ? `?${new URLSearchParams(this.entries).toString()}` : "";
|
|
2517
|
+
}
|
|
2518
|
+
};
|
|
2519
|
+
WorldRequestLedger = class {
|
|
2520
|
+
constructor(options = {}) {
|
|
2521
|
+
this.options = options;
|
|
2522
|
+
}
|
|
2523
|
+
options;
|
|
2524
|
+
/** A page of the world's requests, newest first; `nextCursor` reads the page after it. Narrowed to a session
|
|
2525
|
+
* whose engine records none: `WorldRequestsNotRecorded`. */
|
|
2526
|
+
list(slug, query = WorldRequestQuery.parse()) {
|
|
2527
|
+
return WorldRequestsNotRecorded.mapped(
|
|
2528
|
+
apiRequest(
|
|
2529
|
+
this.options,
|
|
2530
|
+
"GET",
|
|
2531
|
+
`${WORLDS}/${encodeURIComponent(slug)}/requests${query.search()}`
|
|
2532
|
+
)
|
|
2533
|
+
);
|
|
2534
|
+
}
|
|
2535
|
+
/** One of the world's requests, with its headers and bodies. */
|
|
2536
|
+
get(slug, requestId) {
|
|
2537
|
+
return apiRequest(
|
|
2538
|
+
this.options,
|
|
2539
|
+
"GET",
|
|
2540
|
+
`${WORLDS}/${encodeURIComponent(slug)}/requests/${encodeURIComponent(requestId)}`
|
|
2541
|
+
);
|
|
2542
|
+
}
|
|
2543
|
+
/** A page of one session's requests, newest first; `WorldRequestsNotRecorded` when its engine records none. */
|
|
2544
|
+
forSession(sessionId, query = WorldRequestQuery.parse()) {
|
|
2545
|
+
return WorldRequestsNotRecorded.mapped(
|
|
2546
|
+
apiRequest(
|
|
2547
|
+
this.options,
|
|
2548
|
+
"GET",
|
|
2549
|
+
`${SESSIONS}/${encodeURIComponent(sessionId)}/requests${query.search()}`
|
|
2550
|
+
)
|
|
2551
|
+
);
|
|
2552
|
+
}
|
|
2553
|
+
};
|
|
2554
|
+
}
|
|
2555
|
+
});
|
|
2556
|
+
|
|
2286
2557
|
// src/worlds/sessionReadiness.ts
|
|
2287
2558
|
var READY_TIMEOUT_MS, READY_POLL_MS, sleep2, WorldSessionTimeout, WorldSessionCallError, WorldSessionOpenFailed, ENDED, SessionReadiness;
|
|
2288
2559
|
var init_sessionReadiness = __esm({
|
|
@@ -2622,57 +2893,6 @@ __export(session_exports2, {
|
|
|
2622
2893
|
taskLabel: () => taskLabel
|
|
2623
2894
|
});
|
|
2624
2895
|
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
2896
|
async function attachSession(sessionId, options = {}) {
|
|
2677
2897
|
const state2 = await apiRequest(
|
|
2678
2898
|
options,
|
|
@@ -2693,6 +2913,7 @@ async function openSession(slugOrRef, taskOrOpts = {}, positionalOpts = {}) {
|
|
|
2693
2913
|
`Unknown world surfaces: ${unknown.join(", ")}; choose from ${SURFACE_KINDS.join(", ")}`
|
|
2694
2914
|
);
|
|
2695
2915
|
if (opts.browserTier !== void 0) assertBrowserTier(opts.browserTier);
|
|
2916
|
+
if (opts.auth !== void 0) assertSessionAuthMode(opts.auth);
|
|
2696
2917
|
const at = slugOrRef.indexOf("@");
|
|
2697
2918
|
const slug = at === -1 ? slugOrRef : slugOrRef.slice(0, at);
|
|
2698
2919
|
const ref = at === -1 ? "" : slugOrRef.slice(at + 1);
|
|
@@ -2705,7 +2926,8 @@ async function openSession(slugOrRef, taskOrOpts = {}, positionalOpts = {}) {
|
|
|
2705
2926
|
...task === void 0 ? {} : { task },
|
|
2706
2927
|
...opts.reuseWarm === void 0 ? {} : { reuseWarm: opts.reuseWarm },
|
|
2707
2928
|
...opts.surfaces?.length ? { surfaces: opts.surfaces } : {},
|
|
2708
|
-
...opts.browserTier === void 0 ? {} : { browserTier: opts.browserTier }
|
|
2929
|
+
...opts.browserTier === void 0 ? {} : { browserTier: opts.browserTier },
|
|
2930
|
+
...opts.auth === void 0 ? {} : { auth: opts.auth }
|
|
2709
2931
|
}
|
|
2710
2932
|
);
|
|
2711
2933
|
return new WorldSession(state2.sessionId, state2, options);
|
|
@@ -2786,7 +3008,7 @@ async function runSessions(opts) {
|
|
|
2786
3008
|
passed: failed === 0 && (opts.failUnder === void 0 || mean >= opts.failUnder)
|
|
2787
3009
|
};
|
|
2788
3010
|
}
|
|
2789
|
-
var CALL_TIMEOUT_MS, CALL_POLL_MS, JUDGED_GRADE_TIMEOUT_MS, JUDGED_GRADE_POLL_MS, EXPORT_PAGE, sleep3,
|
|
3011
|
+
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
3012
|
var init_session2 = __esm({
|
|
2791
3013
|
"src/worlds/session.ts"() {
|
|
2792
3014
|
"use strict";
|
|
@@ -2794,6 +3016,8 @@ var init_session2 = __esm({
|
|
|
2794
3016
|
init_browser();
|
|
2795
3017
|
init_nativeComputer();
|
|
2796
3018
|
init_sessionContract();
|
|
3019
|
+
init_toolSchema();
|
|
3020
|
+
init_requestLedger();
|
|
2797
3021
|
init_sessionReadiness();
|
|
2798
3022
|
init_session();
|
|
2799
3023
|
init_taskRef();
|
|
@@ -2807,7 +3031,6 @@ var init_session2 = __esm({
|
|
|
2807
3031
|
JUDGED_GRADE_POLL_MS = 2e3;
|
|
2808
3032
|
EXPORT_PAGE = 500;
|
|
2809
3033
|
sleep3 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
2810
|
-
modelToolName = (name) => name.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 64) || "tool";
|
|
2811
3034
|
WorldSession = class {
|
|
2812
3035
|
constructor(sessionId, current, options) {
|
|
2813
3036
|
this.sessionId = sessionId;
|
|
@@ -2877,12 +3100,12 @@ var init_session2 = __esm({
|
|
|
2877
3100
|
);
|
|
2878
3101
|
return api2.url;
|
|
2879
3102
|
}
|
|
2880
|
-
/** Headers every request to `api()` needs
|
|
2881
|
-
*
|
|
2882
|
-
* world's own declared auth
|
|
3103
|
+
/** Headers every request to `api()` needs: a World Host session's token in the
|
|
3104
|
+
* platform's `X-World-Session` header, which every world takes; `{}` for a pod
|
|
3105
|
+
* or hosted twin, which answers with the world's own declared auth. */
|
|
2883
3106
|
async apiHeaders() {
|
|
2884
3107
|
const { api: api2 } = await this.surfaces();
|
|
2885
|
-
return api2?.token ? {
|
|
3108
|
+
return api2?.token ? { [PLATFORM_SESSION_HEADER]: api2.token } : {};
|
|
2886
3109
|
}
|
|
2887
3110
|
/** URL of the world's UI entry page for this session. */
|
|
2888
3111
|
async ui() {
|
|
@@ -2953,11 +3176,28 @@ var init_session2 = __esm({
|
|
|
2953
3176
|
}
|
|
2954
3177
|
/** The session's latest platform state (one request, no waiting). */
|
|
2955
3178
|
async status() {
|
|
3179
|
+
return this.refresh(
|
|
3180
|
+
await apiRequest(
|
|
3181
|
+
this.options,
|
|
3182
|
+
"GET",
|
|
3183
|
+
`/api/public/world-sessions/${encodeURIComponent(this.sessionId)}`
|
|
3184
|
+
)
|
|
3185
|
+
);
|
|
3186
|
+
}
|
|
3187
|
+
/** The world started over under the same id, URLs and token, on what its pin (or `version`, which becomes
|
|
3188
|
+
* its pin) resolves to now: base data plus the task's seed. A grade then reads only the new world's requests. */
|
|
3189
|
+
async restart(opts = {}) {
|
|
2956
3190
|
const fresh = await apiRequest(
|
|
2957
3191
|
this.options,
|
|
2958
|
-
"
|
|
2959
|
-
`/api/public/world-sessions/${encodeURIComponent(this.sessionId)}
|
|
3192
|
+
"POST",
|
|
3193
|
+
`/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/restart`,
|
|
3194
|
+
opts.version ? { version: opts.version } : {}
|
|
2960
3195
|
);
|
|
3196
|
+
this.refresh(fresh);
|
|
3197
|
+
return fresh;
|
|
3198
|
+
}
|
|
3199
|
+
// A status read carries neither the objective nor the open's notices; keep the ones we opened with.
|
|
3200
|
+
refresh(fresh) {
|
|
2961
3201
|
this.current = {
|
|
2962
3202
|
instruction: this.current.instruction,
|
|
2963
3203
|
tools: this.current.tools,
|
|
@@ -2992,7 +3232,7 @@ var init_session2 = __esm({
|
|
|
2992
3232
|
const { callId } = enqueued;
|
|
2993
3233
|
const judged = enqueued.pending === true;
|
|
2994
3234
|
const budgetMs = timeoutMs ?? (judged ? JUDGED_GRADE_TIMEOUT_MS : CALL_TIMEOUT_MS);
|
|
2995
|
-
const
|
|
3235
|
+
const pollMs = judged ? JUDGED_GRADE_POLL_MS : CALL_POLL_MS;
|
|
2996
3236
|
const deadline = Date.now() + budgetMs;
|
|
2997
3237
|
for (; ; ) {
|
|
2998
3238
|
const call = await apiRequest(
|
|
@@ -3008,7 +3248,7 @@ var init_session2 = __esm({
|
|
|
3008
3248
|
throw new WorldSessionTimeout(
|
|
3009
3249
|
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
3250
|
);
|
|
3011
|
-
await sleep3(
|
|
3251
|
+
await sleep3(pollMs);
|
|
3012
3252
|
}
|
|
3013
3253
|
}
|
|
3014
3254
|
/**
|
|
@@ -3101,19 +3341,31 @@ var init_session2 = __esm({
|
|
|
3101
3341
|
async reset(opts = {}) {
|
|
3102
3342
|
await this.exchange({ kind: "reset" }, opts.timeoutMs);
|
|
3103
3343
|
}
|
|
3344
|
+
/** One page of the session's entries in its world's request ledger, newest
|
|
3345
|
+
* first and without bodies: at most `limit` after `cursor` (the last page's
|
|
3346
|
+
* `nextCursor`). Reading it records nothing in the session. */
|
|
3347
|
+
async requests(opts = {}) {
|
|
3348
|
+
return new WorldRequestLedger(this.options).forSession(
|
|
3349
|
+
this.sessionId,
|
|
3350
|
+
WorldRequestQuery.parse({ cursor: opts.cursor, limit: opts.limit ?? REQUEST_LOG_PAGE_MAX })
|
|
3351
|
+
);
|
|
3352
|
+
}
|
|
3353
|
+
page(route2, limit, cursor) {
|
|
3354
|
+
const query = new URLSearchParams({ limit: String(limit) });
|
|
3355
|
+
if (cursor) query.set("cursor", cursor);
|
|
3356
|
+
return apiRequest(
|
|
3357
|
+
this.options,
|
|
3358
|
+
"GET",
|
|
3359
|
+
`/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/${route2}?${query.toString()}`
|
|
3360
|
+
);
|
|
3361
|
+
}
|
|
3104
3362
|
/** The session's call log, oldest first: every tool call, seed, reset,
|
|
3105
3363
|
* grade with its result — the record of the episode. */
|
|
3106
3364
|
async export() {
|
|
3107
3365
|
const calls = [];
|
|
3108
3366
|
let cursor;
|
|
3109
3367
|
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
|
-
);
|
|
3368
|
+
const page = await this.page("calls", EXPORT_PAGE, cursor);
|
|
3117
3369
|
for (const call of page.calls) {
|
|
3118
3370
|
calls.push({
|
|
3119
3371
|
seq: Number(call.seq),
|
|
@@ -3195,6 +3447,7 @@ var init_session2 = __esm({
|
|
|
3195
3447
|
"reuseWarm",
|
|
3196
3448
|
"surfaces",
|
|
3197
3449
|
"browserTier",
|
|
3450
|
+
"auth",
|
|
3198
3451
|
"options"
|
|
3199
3452
|
]);
|
|
3200
3453
|
isOpenSessionOptions = (value) => typeof value === "object" && value !== null && Object.keys(value).every((key) => OPEN_SESSION_OPTION_KEYS.has(key));
|
|
@@ -3309,11 +3562,50 @@ var init_tasks = __esm({
|
|
|
3309
3562
|
}
|
|
3310
3563
|
});
|
|
3311
3564
|
|
|
3565
|
+
// src/worlds/taskGrades.ts
|
|
3566
|
+
var TASKS2, compact2, TaskGrades;
|
|
3567
|
+
var init_taskGrades = __esm({
|
|
3568
|
+
"src/worlds/taskGrades.ts"() {
|
|
3569
|
+
"use strict";
|
|
3570
|
+
init_worlds();
|
|
3571
|
+
TASKS2 = "/api/public/world-tasks";
|
|
3572
|
+
compact2 = (body) => Object.fromEntries(Object.entries(body).filter(([, v]) => v !== void 0));
|
|
3573
|
+
TaskGrades = class {
|
|
3574
|
+
constructor(options = {}) {
|
|
3575
|
+
this.options = options;
|
|
3576
|
+
}
|
|
3577
|
+
options;
|
|
3578
|
+
try(sessionId, target) {
|
|
3579
|
+
return apiRequest(
|
|
3580
|
+
this.options,
|
|
3581
|
+
"POST",
|
|
3582
|
+
`${TASKS2}/try`,
|
|
3583
|
+
compact2({ sessionId, ...target })
|
|
3584
|
+
);
|
|
3585
|
+
}
|
|
3586
|
+
regrade(taskId, scope = {}) {
|
|
3587
|
+
return apiRequest(
|
|
3588
|
+
this.options,
|
|
3589
|
+
"POST",
|
|
3590
|
+
`${TASKS2}/${encodeURIComponent(taskId)}/regrade`,
|
|
3591
|
+
compact2({ ...scope })
|
|
3592
|
+
);
|
|
3593
|
+
}
|
|
3594
|
+
};
|
|
3595
|
+
}
|
|
3596
|
+
});
|
|
3597
|
+
|
|
3312
3598
|
// src/worlds/surfaceDescriptor.ts
|
|
3313
3599
|
function surfaceDescriptor(s) {
|
|
3314
3600
|
return {
|
|
3315
3601
|
surfaces: surfaceKinds(s),
|
|
3316
|
-
...s.api ? {
|
|
3602
|
+
...s.api ? {
|
|
3603
|
+
api: {
|
|
3604
|
+
url: s.api.url,
|
|
3605
|
+
...s.api.token ? { token: s.api.token } : {},
|
|
3606
|
+
...s.api.auth ? { auth: s.api.auth } : {}
|
|
3607
|
+
}
|
|
3608
|
+
} : {},
|
|
3317
3609
|
...s.ui ? { ui: { url: s.ui.url, entry: uiEntryUrl(s.ui), apiPath: s.ui.apiPath ?? null } } : {},
|
|
3318
3610
|
...s.browser ? {
|
|
3319
3611
|
browser: {
|
|
@@ -3363,8 +3655,7 @@ function fromResponse(answer, options) {
|
|
|
3363
3655
|
sessions[alias] = new WorldSession(state2.sessionId, state2, options);
|
|
3364
3656
|
worlds[alias] = {
|
|
3365
3657
|
slug: state2.slug,
|
|
3366
|
-
ref: state2.ref
|
|
3367
|
-
private: state2.private ?? null
|
|
3658
|
+
ref: state2.ref
|
|
3368
3659
|
};
|
|
3369
3660
|
}
|
|
3370
3661
|
return new TaskSessions(
|
|
@@ -3439,7 +3730,6 @@ async function attachTask(taskId, options = {}) {
|
|
|
3439
3730
|
{
|
|
3440
3731
|
slug: row.slug ?? "",
|
|
3441
3732
|
ref: null,
|
|
3442
|
-
private: null,
|
|
3443
3733
|
versionId: row.versionId,
|
|
3444
3734
|
sessionId: row.sessionId,
|
|
3445
3735
|
ready: row.ready,
|
|
@@ -3469,7 +3759,7 @@ async function attachManifest(manifest, options = {}) {
|
|
|
3469
3759
|
Object.fromEntries(
|
|
3470
3760
|
Object.entries(manifest.sessions).map(([alias, entry]) => [
|
|
3471
3761
|
alias,
|
|
3472
|
-
{ slug: entry.slug, ref: entry.ref
|
|
3762
|
+
{ slug: entry.slug, ref: entry.ref }
|
|
3473
3763
|
])
|
|
3474
3764
|
)
|
|
3475
3765
|
);
|
|
@@ -3491,7 +3781,6 @@ var init_taskSessions = __esm({
|
|
|
3491
3781
|
manifestSession = (s, state2, world) => ({
|
|
3492
3782
|
slug: world.slug,
|
|
3493
3783
|
ref: world.ref,
|
|
3494
|
-
private: world.private,
|
|
3495
3784
|
versionId: state2.versionId,
|
|
3496
3785
|
sessionId: state2.sessionId,
|
|
3497
3786
|
ready: state2.ready,
|
|
@@ -3548,7 +3837,7 @@ var init_taskSessions = __esm({
|
|
|
3548
3837
|
/** This alias's world as recorded at open/attach — what a `TaskRun`
|
|
3549
3838
|
* filing needs to name, without exposing the whole map. */
|
|
3550
3839
|
worldRef(alias) {
|
|
3551
|
-
return this.worlds[alias] ?? { slug: "", ref: null
|
|
3840
|
+
return this.worlds[alias] ?? { slug: "", ref: null };
|
|
3552
3841
|
}
|
|
3553
3842
|
/** The aliases, in the spec's order. */
|
|
3554
3843
|
get aliases() {
|
|
@@ -3873,16 +4162,12 @@ var init_taskRunOutcome = __esm({
|
|
|
3873
4162
|
evaluationId;
|
|
3874
4163
|
evaluationStatus = null;
|
|
3875
4164
|
started = Date.now();
|
|
3876
|
-
/** The run stopped short of a grade; the first reason stands. */
|
|
3877
4165
|
stopped(error) {
|
|
3878
4166
|
this.runError ??= messageOf(error).slice(0, 2e3);
|
|
3879
4167
|
}
|
|
3880
4168
|
agentRaised(error) {
|
|
3881
4169
|
this.agentError = messageOf(error).slice(0, 2e3);
|
|
3882
4170
|
}
|
|
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
4171
|
failure() {
|
|
3887
4172
|
const reasons = [
|
|
3888
4173
|
this.agentError === null ? null : `agent raised: ${this.agentError}`,
|
|
@@ -3978,6 +4263,7 @@ var init_taskRunOutcome = __esm({
|
|
|
3978
4263
|
])
|
|
3979
4264
|
),
|
|
3980
4265
|
ungraded: this.grade?.ungraded ?? live.aliases,
|
|
4266
|
+
verifierVersion: live.taskVersion,
|
|
3981
4267
|
traced: this.traced,
|
|
3982
4268
|
runDir: this.runDir,
|
|
3983
4269
|
...this.agentError ? { agentError: this.agentError } : {},
|
|
@@ -4738,7 +5024,7 @@ var require_package = __commonJS({
|
|
|
4738
5024
|
"package.json"(exports, module) {
|
|
4739
5025
|
module.exports = {
|
|
4740
5026
|
name: "@withgateway/sdk",
|
|
4741
|
-
version: "0.
|
|
5027
|
+
version: "0.6.0",
|
|
4742
5028
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
4743
5029
|
main: "./dist/index.js",
|
|
4744
5030
|
module: "./dist/index.mjs",
|
|
@@ -5930,51 +6216,195 @@ var init_setRun = __esm({
|
|
|
5930
6216
|
});
|
|
5931
6217
|
|
|
5932
6218
|
// src/worlds/requestLog.ts
|
|
5933
|
-
|
|
6219
|
+
function worldRequestsUnrecorded(counts) {
|
|
6220
|
+
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)));
|
|
6221
|
+
return parts.length > 0 ? `Not recorded: ${parts.join(", ")}` : null;
|
|
6222
|
+
}
|
|
6223
|
+
function counted(value) {
|
|
6224
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : 0;
|
|
6225
|
+
}
|
|
6226
|
+
var UNRECORDED, WorldRequestLog;
|
|
5934
6227
|
var init_requestLog = __esm({
|
|
5935
6228
|
"src/worlds/requestLog.ts"() {
|
|
5936
6229
|
"use strict";
|
|
6230
|
+
init_requestLedger();
|
|
6231
|
+
UNRECORDED = [
|
|
6232
|
+
["lost", "{n} request", "{n} requests"],
|
|
6233
|
+
["shed", "{n} request's headers and bodies", "{n} requests' headers and bodies"],
|
|
6234
|
+
["hostsLost", "the requests {n} lost host held", "the requests {n} lost hosts held"]
|
|
6235
|
+
];
|
|
5937
6236
|
WorldRequestLog = class _WorldRequestLog {
|
|
5938
|
-
constructor(requests) {
|
|
6237
|
+
constructor(requests, notRecorded = null, unrecorded = null) {
|
|
5939
6238
|
this.requests = requests;
|
|
6239
|
+
this.notRecorded = notRecorded;
|
|
6240
|
+
this.unrecorded = unrecorded;
|
|
5940
6241
|
}
|
|
5941
6242
|
requests;
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
|
|
5945
|
-
|
|
5946
|
-
|
|
5947
|
-
|
|
5948
|
-
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
|
|
5953
|
-
|
|
5954
|
-
|
|
5955
|
-
|
|
6243
|
+
notRecorded;
|
|
6244
|
+
unrecorded;
|
|
6245
|
+
/** Every entry the ledger holds for the session, oldest first, and the line for what it did not record;
|
|
6246
|
+
* for a session the World Host did not serve, none, and `notRecorded` says why. */
|
|
6247
|
+
static async load(session) {
|
|
6248
|
+
try {
|
|
6249
|
+
return await _WorldRequestLog.pages(session);
|
|
6250
|
+
} catch (error) {
|
|
6251
|
+
const refused = WorldRequestsNotRecorded.from(error);
|
|
6252
|
+
if (!(refused instanceof WorldRequestsNotRecorded)) throw error;
|
|
6253
|
+
return new _WorldRequestLog([], refused.message);
|
|
6254
|
+
}
|
|
6255
|
+
}
|
|
6256
|
+
static async pages(session) {
|
|
6257
|
+
const requests = [];
|
|
6258
|
+
let cursor;
|
|
6259
|
+
for (; ; ) {
|
|
6260
|
+
const page = await session.requests(cursor ? { cursor } : {});
|
|
6261
|
+
requests.push(...page.requests);
|
|
6262
|
+
if (!page.nextCursor || page.requests.length === 0)
|
|
6263
|
+
return new _WorldRequestLog(requests.reverse(), null, worldRequestsUnrecorded(page));
|
|
6264
|
+
cursor = page.nextCursor;
|
|
6265
|
+
}
|
|
6266
|
+
}
|
|
6267
|
+
/** Each entry in the shape of a ledger line, `kind: "request"`, so one JSONL
|
|
6268
|
+
* file holds both: `args` what was asked, `result` what came back under the
|
|
6269
|
+
* entry's `requestId`. */
|
|
5956
6270
|
asCalls() {
|
|
5957
6271
|
return this.requests.map((r) => ({
|
|
5958
|
-
seq:
|
|
6272
|
+
seq: r.seq,
|
|
5959
6273
|
kind: "request",
|
|
5960
|
-
tool: r.operation
|
|
6274
|
+
tool: r.operation,
|
|
5961
6275
|
args: {
|
|
5962
|
-
method: r.method
|
|
5963
|
-
path: r.path
|
|
5964
|
-
|
|
5965
|
-
|
|
5966
|
-
|
|
5967
|
-
|
|
6276
|
+
method: r.method,
|
|
6277
|
+
path: r.path,
|
|
6278
|
+
query: r.query,
|
|
6279
|
+
via: r.via,
|
|
6280
|
+
contentType: r.request.contentType,
|
|
6281
|
+
bodyBytes: r.request.bodyBytes,
|
|
6282
|
+
truncated: r.request.truncated
|
|
6283
|
+
},
|
|
6284
|
+
result: {
|
|
6285
|
+
requestId: r.id,
|
|
6286
|
+
status: r.response.status,
|
|
6287
|
+
rows: r.rows,
|
|
6288
|
+
found: r.found,
|
|
6289
|
+
durationMs: r.durationMs,
|
|
6290
|
+
contentType: r.response.contentType,
|
|
6291
|
+
bodyBytes: r.response.bodyBytes,
|
|
6292
|
+
truncated: r.response.truncated
|
|
5968
6293
|
},
|
|
5969
|
-
result: { status: r.status ?? null, rows: r.rows ?? null, found: r.found ?? null },
|
|
5970
6294
|
error: null,
|
|
5971
|
-
completedAt: r.at
|
|
6295
|
+
completedAt: r.at
|
|
5972
6296
|
}));
|
|
5973
6297
|
}
|
|
5974
6298
|
};
|
|
5975
6299
|
}
|
|
5976
6300
|
});
|
|
5977
6301
|
|
|
6302
|
+
// src/worlds/webhooks.ts
|
|
6303
|
+
async function listWebhooks(options, sessionId, page = {}) {
|
|
6304
|
+
const query = new URLSearchParams({
|
|
6305
|
+
after: String(page.after ?? 0),
|
|
6306
|
+
limit: String(page.limit ?? WORLD_WEBHOOK_PAGE_MAX),
|
|
6307
|
+
tail: String(page.tail ?? false)
|
|
6308
|
+
});
|
|
6309
|
+
if (page.epoch) query.set("epoch", page.epoch);
|
|
6310
|
+
return apiRequest(options, "GET", `${route(sessionId)}?${query.toString()}`);
|
|
6311
|
+
}
|
|
6312
|
+
var WORLD_WEBHOOK_PAGE_MAX, FORWARD_TIMEOUT_MS, ERROR_CHARS, route, WorldWebhookForwarder;
|
|
6313
|
+
var init_webhooks = __esm({
|
|
6314
|
+
"src/worlds/webhooks.ts"() {
|
|
6315
|
+
"use strict";
|
|
6316
|
+
init_worlds();
|
|
6317
|
+
WORLD_WEBHOOK_PAGE_MAX = 100;
|
|
6318
|
+
FORWARD_TIMEOUT_MS = 1e4;
|
|
6319
|
+
ERROR_CHARS = 500;
|
|
6320
|
+
route = (sessionId) => `/api/public/world-sessions/${encodeURIComponent(sessionId)}/webhooks`;
|
|
6321
|
+
WorldWebhookForwarder = class {
|
|
6322
|
+
constructor(options, sessionId, forwardTo, opts = {}) {
|
|
6323
|
+
this.options = options;
|
|
6324
|
+
this.sessionId = sessionId;
|
|
6325
|
+
this.forwardTo = forwardTo;
|
|
6326
|
+
this.send = opts.fetch ?? fetch;
|
|
6327
|
+
}
|
|
6328
|
+
options;
|
|
6329
|
+
sessionId;
|
|
6330
|
+
forwardTo;
|
|
6331
|
+
after = 0;
|
|
6332
|
+
epoch = null;
|
|
6333
|
+
answers = [];
|
|
6334
|
+
send;
|
|
6335
|
+
get cursor() {
|
|
6336
|
+
return this.after;
|
|
6337
|
+
}
|
|
6338
|
+
/** Where forwarding begins: the deliveries the session still holds (`replay`), or only those it sends from now. */
|
|
6339
|
+
async start(replay) {
|
|
6340
|
+
if (replay) return null;
|
|
6341
|
+
const page = await this.poll([], { tail: true, limit: 1 });
|
|
6342
|
+
this.follow(page);
|
|
6343
|
+
return page;
|
|
6344
|
+
}
|
|
6345
|
+
/** One poll: the answers held so far sent, the next page forwarded. A poll that fails keeps its answers for the next. */
|
|
6346
|
+
async round() {
|
|
6347
|
+
const page = await this.withAnswers((answers) => this.poll(answers));
|
|
6348
|
+
const forwarded = [];
|
|
6349
|
+
for (const delivery of page.deliveries) {
|
|
6350
|
+
const answer = await this.forward(delivery);
|
|
6351
|
+
this.answers.push(answer);
|
|
6352
|
+
forwarded.push({ delivery, answer });
|
|
6353
|
+
}
|
|
6354
|
+
this.follow(page);
|
|
6355
|
+
return { page, forwarded };
|
|
6356
|
+
}
|
|
6357
|
+
/** Sends the answers still held; the cursor stays, so a delivery this poll returns is forwarded by the next round. */
|
|
6358
|
+
async settle() {
|
|
6359
|
+
if (this.answers.length === 0) return 0;
|
|
6360
|
+
const page = await this.withAnswers((answers) => this.poll(answers, { limit: 1 }));
|
|
6361
|
+
return page.answered;
|
|
6362
|
+
}
|
|
6363
|
+
follow(page) {
|
|
6364
|
+
this.after = page.next;
|
|
6365
|
+
this.epoch = page.epoch;
|
|
6366
|
+
}
|
|
6367
|
+
async withAnswers(poll) {
|
|
6368
|
+
const answers = this.answers.splice(0, WORLD_WEBHOOK_PAGE_MAX);
|
|
6369
|
+
try {
|
|
6370
|
+
return await poll(answers);
|
|
6371
|
+
} catch (error) {
|
|
6372
|
+
this.answers.unshift(...answers);
|
|
6373
|
+
throw error;
|
|
6374
|
+
}
|
|
6375
|
+
}
|
|
6376
|
+
poll(answers, opts = {}) {
|
|
6377
|
+
return apiRequest(this.options, "POST", route(this.sessionId), {
|
|
6378
|
+
after: this.after,
|
|
6379
|
+
epoch: this.epoch,
|
|
6380
|
+
tail: opts.tail ?? false,
|
|
6381
|
+
limit: opts.limit ?? WORLD_WEBHOOK_PAGE_MAX,
|
|
6382
|
+
subscriptions: false,
|
|
6383
|
+
answers
|
|
6384
|
+
});
|
|
6385
|
+
}
|
|
6386
|
+
async forward(delivery) {
|
|
6387
|
+
const started = Date.now();
|
|
6388
|
+
try {
|
|
6389
|
+
const reply = await this.send(this.forwardTo, {
|
|
6390
|
+
method: "POST",
|
|
6391
|
+
headers: delivery.headers,
|
|
6392
|
+
body: delivery.payload,
|
|
6393
|
+
redirect: "manual",
|
|
6394
|
+
signal: AbortSignal.timeout(FORWARD_TIMEOUT_MS)
|
|
6395
|
+
});
|
|
6396
|
+
await reply.arrayBuffer().catch(() => void 0);
|
|
6397
|
+
if (reply.status < 100 || reply.status > 599) throw new Error("the receiver answered an invalid HTTP status");
|
|
6398
|
+
return { id: delivery.id, status: reply.status, durationMs: Date.now() - started, error: null };
|
|
6399
|
+
} catch (error) {
|
|
6400
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
6401
|
+
return { id: delivery.id, status: 0, durationMs: Date.now() - started, error: message.slice(0, ERROR_CHARS) };
|
|
6402
|
+
}
|
|
6403
|
+
}
|
|
6404
|
+
};
|
|
6405
|
+
}
|
|
6406
|
+
});
|
|
6407
|
+
|
|
5978
6408
|
// src/worlds/checkoutTarget.ts
|
|
5979
6409
|
import * as fs2 from "fs";
|
|
5980
6410
|
import * as path3 from "path";
|
|
@@ -6663,7 +7093,8 @@ function checkoutIdentity(ref, resolved) {
|
|
|
6663
7093
|
async function pull(slugRef, target, options = {}, opts = {}) {
|
|
6664
7094
|
const at = slugRef.indexOf("@");
|
|
6665
7095
|
const slug = at === -1 ? slugRef : slugRef.slice(0, at);
|
|
6666
|
-
const
|
|
7096
|
+
const asked = at === -1 ? void 0 : slugRef.slice(at + 1);
|
|
7097
|
+
const ref = asked ?? "latest";
|
|
6667
7098
|
const landing = CheckoutTarget.resolve(slug, target, {
|
|
6668
7099
|
cwd: process.cwd(),
|
|
6669
7100
|
force: opts.force ?? false,
|
|
@@ -6671,7 +7102,7 @@ async function pull(slugRef, target, options = {}, opts = {}) {
|
|
|
6671
7102
|
});
|
|
6672
7103
|
const details = await apiRequest(options, "POST", "/api/public/benchmark-containers/resolve-version", {
|
|
6673
7104
|
slug,
|
|
6674
|
-
ref
|
|
7105
|
+
...asked ? { ref: asked } : {}
|
|
6675
7106
|
});
|
|
6676
7107
|
if (!details.downloadUrl) {
|
|
6677
7108
|
throw new Error(`${slug}@${ref} resolved but has no uploaded bundle`);
|
|
@@ -6857,7 +7288,7 @@ async function validateWorld(dir, opts) {
|
|
|
6857
7288
|
options,
|
|
6858
7289
|
"POST",
|
|
6859
7290
|
"/api/public/benchmark-containers/resolve-version",
|
|
6860
|
-
{ slug, ref: branch }
|
|
7291
|
+
{ slug, ...branch === DEFAULT_BRANCH ? {} : { ref: branch } }
|
|
6861
7292
|
);
|
|
6862
7293
|
tipVersionId = tip.versionId ?? null;
|
|
6863
7294
|
} catch {
|
|
@@ -6964,11 +7395,16 @@ var init_validate = __esm({
|
|
|
6964
7395
|
});
|
|
6965
7396
|
|
|
6966
7397
|
// src/worlds/sandbox.ts
|
|
7398
|
+
import { createHash as createHash5, randomUUID as randomUUID2 } from "crypto";
|
|
6967
7399
|
function parseSlugRef(slugRef) {
|
|
6968
7400
|
const at = slugRef.indexOf("@");
|
|
6969
7401
|
if (at === -1) return { slug: slugRef };
|
|
6970
7402
|
return { slug: slugRef.slice(0, at), ref: slugRef.slice(at + 1) };
|
|
6971
7403
|
}
|
|
7404
|
+
function nameGlob(pattern) {
|
|
7405
|
+
const literal = (part) => part.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
|
|
7406
|
+
return new RegExp(`^${pattern.split("*").map(literal).join(".*")}$`);
|
|
7407
|
+
}
|
|
6972
7408
|
function rebaseConflicts(error) {
|
|
6973
7409
|
if (!(error instanceof ApiError) || error.status !== 409) return null;
|
|
6974
7410
|
let body;
|
|
@@ -6986,7 +7422,8 @@ function isConflictPath(value) {
|
|
|
6986
7422
|
return typeof entry?.path === "string" && typeof entry.reason === "string";
|
|
6987
7423
|
}
|
|
6988
7424
|
function uncommittedPaths(error) {
|
|
6989
|
-
if (!(error instanceof ApiError) || error.status !== 409 || error.code !== "sandbox_uncommitted")
|
|
7425
|
+
if (!(error instanceof ApiError) || error.status !== 409 || error.code !== "sandbox_uncommitted")
|
|
7426
|
+
return null;
|
|
6990
7427
|
let body;
|
|
6991
7428
|
try {
|
|
6992
7429
|
body = JSON.parse(error.text);
|
|
@@ -6997,6 +7434,53 @@ function uncommittedPaths(error) {
|
|
|
6997
7434
|
if (!Array.isArray(uncommitted)) return null;
|
|
6998
7435
|
return uncommitted.filter((p) => typeof p === "string");
|
|
6999
7436
|
}
|
|
7437
|
+
function carriedWarnings(error) {
|
|
7438
|
+
const kept = typeof error === "object" && error !== null ? carried.get(error) ?? [] : [];
|
|
7439
|
+
const shown = error instanceof Error ? error.message : "";
|
|
7440
|
+
return unique([...kept, ...bodyWarnings(error)]).filter((warning) => !shown.includes(warning));
|
|
7441
|
+
}
|
|
7442
|
+
function carrying(error, warnings) {
|
|
7443
|
+
if (warnings.length > 0 && typeof error === "object" && error !== null)
|
|
7444
|
+
carried.set(error, unique([...carried.get(error) ?? [], ...warnings]));
|
|
7445
|
+
return error;
|
|
7446
|
+
}
|
|
7447
|
+
function unique(warnings) {
|
|
7448
|
+
return [...new Set(warnings)];
|
|
7449
|
+
}
|
|
7450
|
+
function bodyWarnings(error) {
|
|
7451
|
+
if (!(error instanceof ApiError)) return [];
|
|
7452
|
+
let body;
|
|
7453
|
+
try {
|
|
7454
|
+
body = JSON.parse(error.text);
|
|
7455
|
+
} catch {
|
|
7456
|
+
return [];
|
|
7457
|
+
}
|
|
7458
|
+
const warnings = body?.warnings;
|
|
7459
|
+
if (!Array.isArray(warnings)) return [];
|
|
7460
|
+
return warnings.filter((w) => typeof w === "string");
|
|
7461
|
+
}
|
|
7462
|
+
function deferredWarnings(error) {
|
|
7463
|
+
if (!(error instanceof ApiError) || error.status !== 409 || error.code !== "sandbox_exec_deferred") return null;
|
|
7464
|
+
return bodyWarnings(error);
|
|
7465
|
+
}
|
|
7466
|
+
function rowsRefusal(error) {
|
|
7467
|
+
if (!(error instanceof ApiError) || error.status !== 400 || error.code !== "rows_refused") return null;
|
|
7468
|
+
let body;
|
|
7469
|
+
try {
|
|
7470
|
+
body = JSON.parse(error.text);
|
|
7471
|
+
} catch {
|
|
7472
|
+
return null;
|
|
7473
|
+
}
|
|
7474
|
+
const { message, batchId, refusalCount, refusals, reportUrl } = body;
|
|
7475
|
+
if (typeof batchId !== "string" || typeof refusalCount !== "number" || !Array.isArray(refusals)) return null;
|
|
7476
|
+
return {
|
|
7477
|
+
message: typeof message === "string" ? message : "",
|
|
7478
|
+
batchId,
|
|
7479
|
+
refusalCount,
|
|
7480
|
+
refusals: refusals.filter((r) => typeof r === "object" && r !== null),
|
|
7481
|
+
reportUrl: typeof reportUrl === "string" ? reportUrl : null
|
|
7482
|
+
};
|
|
7483
|
+
}
|
|
7000
7484
|
function listQuery(filter) {
|
|
7001
7485
|
const params = new URLSearchParams();
|
|
7002
7486
|
if (filter.status) params.set("status", filter.status);
|
|
@@ -7005,15 +7489,51 @@ function listQuery(filter) {
|
|
|
7005
7489
|
const qs = params.toString();
|
|
7006
7490
|
return qs ? `?${qs}` : "";
|
|
7007
7491
|
}
|
|
7008
|
-
var isSandboxImportPending, sid, SANDBOXES, SANDBOX_REQUEST_TIMEOUT_MS, WorldSandboxClient;
|
|
7492
|
+
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
7493
|
var init_sandbox = __esm({
|
|
7010
7494
|
"src/worlds/sandbox.ts"() {
|
|
7011
7495
|
"use strict";
|
|
7012
7496
|
init_worlds();
|
|
7497
|
+
isSandboxCommitPending = (answer) => !("versionId" in answer);
|
|
7013
7498
|
isSandboxImportPending = (answer) => !("versionId" in answer);
|
|
7014
7499
|
sid = encodeURIComponent;
|
|
7015
7500
|
SANDBOXES = "/api/public/benchmark-containers/sandboxes";
|
|
7016
|
-
SANDBOX_REQUEST_TIMEOUT_MS =
|
|
7501
|
+
SANDBOX_REQUEST_TIMEOUT_MS = 29e4;
|
|
7502
|
+
SANDBOX_WRITE_CHUNK_BYTES = 4 * 1024 * 1024;
|
|
7503
|
+
SANDBOX_FILE_MAX_BYTES = 256 * 1024 * 1024;
|
|
7504
|
+
SANDBOX_WRITE_SKIPPED = [
|
|
7505
|
+
".git/",
|
|
7506
|
+
".gateway/",
|
|
7507
|
+
"scratch/",
|
|
7508
|
+
".scratch/",
|
|
7509
|
+
"__pycache__/",
|
|
7510
|
+
"*.pyc",
|
|
7511
|
+
".pytest_cache/",
|
|
7512
|
+
".mypy_cache/",
|
|
7513
|
+
".ruff_cache/",
|
|
7514
|
+
"node_modules/",
|
|
7515
|
+
".venv/",
|
|
7516
|
+
"venv/",
|
|
7517
|
+
".DS_Store",
|
|
7518
|
+
"*.swp"
|
|
7519
|
+
];
|
|
7520
|
+
WriteTreeFilter = class {
|
|
7521
|
+
directories = new Set(
|
|
7522
|
+
SANDBOX_WRITE_SKIPPED.filter((pattern) => pattern.endsWith("/")).map((pattern) => pattern.slice(0, -1))
|
|
7523
|
+
);
|
|
7524
|
+
files = SANDBOX_WRITE_SKIPPED.filter((pattern) => !pattern.endsWith("/")).map(nameGlob);
|
|
7525
|
+
skipsDirectory(name) {
|
|
7526
|
+
return this.directories.has(name);
|
|
7527
|
+
}
|
|
7528
|
+
skipsFile(name) {
|
|
7529
|
+
return this.files.some((glob) => glob.test(name));
|
|
7530
|
+
}
|
|
7531
|
+
};
|
|
7532
|
+
SANDBOX_EXEC_WAIT_MS = 4e4;
|
|
7533
|
+
SANDBOX_EXEC_TIMEOUT_MAX_S = 600;
|
|
7534
|
+
SANDBOX_EXEC_REPORT_MARGIN_MS = 35e3;
|
|
7535
|
+
SANDBOX_EXEC_START_ATTEMPTS = 3;
|
|
7536
|
+
carried = /* @__PURE__ */ new WeakMap();
|
|
7017
7537
|
WorldSandboxClient = class {
|
|
7018
7538
|
constructor(options = {}) {
|
|
7019
7539
|
this.options = options;
|
|
@@ -7038,7 +7558,10 @@ var init_sandbox = __esm({
|
|
|
7038
7558
|
}
|
|
7039
7559
|
/** The project's sandboxes, newest first — how an agent finds one it left open. */
|
|
7040
7560
|
async list(filter = {}) {
|
|
7041
|
-
const res = await this.request(
|
|
7561
|
+
const res = await this.request(
|
|
7562
|
+
"GET",
|
|
7563
|
+
`${SANDBOXES}${listQuery(filter)}`
|
|
7564
|
+
);
|
|
7042
7565
|
return res.sandboxes;
|
|
7043
7566
|
}
|
|
7044
7567
|
async read(sandboxId, filePath) {
|
|
@@ -7046,16 +7569,72 @@ var init_sandbox = __esm({
|
|
|
7046
7569
|
"GET",
|
|
7047
7570
|
`${SANDBOXES}/${sid(sandboxId)}/file?path=${encodeURIComponent(filePath)}`
|
|
7048
7571
|
);
|
|
7049
|
-
return {
|
|
7572
|
+
return {
|
|
7573
|
+
path: res.path,
|
|
7574
|
+
size: res.size,
|
|
7575
|
+
bytes: Buffer.from(res.contentBase64, "base64")
|
|
7576
|
+
};
|
|
7050
7577
|
}
|
|
7051
|
-
|
|
7052
|
-
|
|
7053
|
-
|
|
7054
|
-
|
|
7055
|
-
|
|
7578
|
+
/** A file past one chunk goes up in parts under one upload id; the platform lands it whole once the last part's
|
|
7579
|
+
* size and SHA-256 check out. */
|
|
7580
|
+
async write(sandboxId, filePath, bytes) {
|
|
7581
|
+
if (bytes.length <= SANDBOX_WRITE_CHUNK_BYTES)
|
|
7582
|
+
return this.putFile(sandboxId, { path: filePath, contentBase64: bytes.toString("base64") });
|
|
7583
|
+
const whole = { upload: randomUUID2(), size: bytes.length, sha256: createHash5("sha256").update(bytes).digest("hex") };
|
|
7584
|
+
let answer = { path: filePath, received: 0 };
|
|
7585
|
+
for (let offset = 0; offset < bytes.length; offset += SANDBOX_WRITE_CHUNK_BYTES) {
|
|
7586
|
+
const part = bytes.subarray(offset, offset + SANDBOX_WRITE_CHUNK_BYTES);
|
|
7587
|
+
answer = await this.putFile(sandboxId, {
|
|
7588
|
+
path: filePath,
|
|
7589
|
+
contentBase64: part.toString("base64"),
|
|
7590
|
+
...whole,
|
|
7591
|
+
offset,
|
|
7592
|
+
last: offset + part.length === bytes.length
|
|
7593
|
+
});
|
|
7594
|
+
}
|
|
7595
|
+
return answer;
|
|
7596
|
+
}
|
|
7597
|
+
putFile(sandboxId, body) {
|
|
7598
|
+
return this.request("PUT", `${SANDBOXES}/${sid(sandboxId)}/file`, body);
|
|
7599
|
+
}
|
|
7600
|
+
/** Runs as a job on the platform: a command that outlasts one request is waited on again until its result. */
|
|
7601
|
+
async exec(sandboxId, input) {
|
|
7602
|
+
const budgetMs = (input.timeoutMs ?? SANDBOX_EXEC_TIMEOUT_MAX_S * 1e3) + SANDBOX_EXEC_REPORT_MARGIN_MS;
|
|
7603
|
+
let answer = await this.startExec(sandboxId, { ...input, waitMs: SANDBOX_EXEC_WAIT_MS });
|
|
7604
|
+
const deadline = Date.now() + budgetMs;
|
|
7605
|
+
const warnings = [...answer.warnings ?? []];
|
|
7606
|
+
try {
|
|
7607
|
+
while ("state" in answer) {
|
|
7608
|
+
if (Date.now() >= deadline)
|
|
7609
|
+
throw new Error(
|
|
7610
|
+
`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.`
|
|
7611
|
+
);
|
|
7612
|
+
answer = await this.execStep(sandboxId, { execId: answer.execId, waitMs: SANDBOX_EXEC_WAIT_MS });
|
|
7613
|
+
warnings.push(...answer.warnings ?? []);
|
|
7614
|
+
}
|
|
7615
|
+
} catch (error) {
|
|
7616
|
+
throw carrying(error, warnings);
|
|
7617
|
+
}
|
|
7618
|
+
return { ...answer, warnings };
|
|
7619
|
+
}
|
|
7620
|
+
// A deferred start ran nothing (the platform was still getting the sandbox ready), so starting again is safe. What
|
|
7621
|
+
// getting ready found rides on the deferral alone (no later call reports it), so it is kept for the answer, or for
|
|
7622
|
+
// the error when a later attempt fails.
|
|
7623
|
+
async startExec(sandboxId, body) {
|
|
7624
|
+
const kept = [];
|
|
7625
|
+
for (let attempt = 1; ; attempt += 1) {
|
|
7626
|
+
try {
|
|
7627
|
+
const answer = await this.execStep(sandboxId, body);
|
|
7628
|
+
return { ...answer, warnings: unique([...kept, ...answer.warnings ?? []]) };
|
|
7629
|
+
} catch (error) {
|
|
7630
|
+
const warnings = deferredWarnings(error);
|
|
7631
|
+
if (warnings === null || attempt === SANDBOX_EXEC_START_ATTEMPTS) throw carrying(error, kept);
|
|
7632
|
+
kept.push(...warnings);
|
|
7633
|
+
}
|
|
7634
|
+
}
|
|
7056
7635
|
}
|
|
7057
|
-
|
|
7058
|
-
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/exec`,
|
|
7636
|
+
execStep(sandboxId, body) {
|
|
7637
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/exec`, body);
|
|
7059
7638
|
}
|
|
7060
7639
|
check(sandboxId) {
|
|
7061
7640
|
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/check`, {});
|
|
@@ -7063,7 +7642,11 @@ var init_sandbox = __esm({
|
|
|
7063
7642
|
/** With `rebase`, a moved base is replayed onto; a 409 then names the conflicting paths (`rebaseConflicts`). */
|
|
7064
7643
|
commit(sandboxId, input) {
|
|
7065
7644
|
const { rebase, ...rest } = input;
|
|
7066
|
-
return this.request(
|
|
7645
|
+
return this.request(
|
|
7646
|
+
"POST",
|
|
7647
|
+
`${SANDBOXES}/${sid(sandboxId)}/commit`,
|
|
7648
|
+
rebase ? { ...rest, rebase: true } : rest
|
|
7649
|
+
);
|
|
7067
7650
|
}
|
|
7068
7651
|
/**
|
|
7069
7652
|
* A rows file already in the sandbox tree into the PLATFORM world the
|
|
@@ -7076,7 +7659,11 @@ var init_sandbox = __esm({
|
|
|
7076
7659
|
}
|
|
7077
7660
|
/** Uncommitted work is a 409 (`uncommittedPaths`) unless `force` discards it. */
|
|
7078
7661
|
close(sandboxId, opts = {}) {
|
|
7079
|
-
return this.request(
|
|
7662
|
+
return this.request(
|
|
7663
|
+
"DELETE",
|
|
7664
|
+
`${SANDBOXES}/${sid(sandboxId)}`,
|
|
7665
|
+
opts.force ? { force: true } : void 0
|
|
7666
|
+
);
|
|
7080
7667
|
}
|
|
7081
7668
|
};
|
|
7082
7669
|
}
|
|
@@ -7395,7 +7982,7 @@ var init_json = __esm({
|
|
|
7395
7982
|
});
|
|
7396
7983
|
|
|
7397
7984
|
// src/worlds/transforms.ts
|
|
7398
|
-
import { createHash as
|
|
7985
|
+
import { createHash as createHash6 } from "crypto";
|
|
7399
7986
|
function parseTransform(name) {
|
|
7400
7987
|
const simple = Object.prototype.hasOwnProperty.call(SIMPLE, name) ? SIMPLE[name] : void 0;
|
|
7401
7988
|
if (simple) return simple;
|
|
@@ -7433,7 +8020,7 @@ var init_transforms = __esm({
|
|
|
7433
8020
|
return at === -1 ? "" : value.slice(at + 1).toLowerCase();
|
|
7434
8021
|
};
|
|
7435
8022
|
stripPrefix = (prefix) => (value) => value.startsWith(prefix) ? value.slice(prefix.length) : value;
|
|
7436
|
-
hex = (algorithm, value) =>
|
|
8023
|
+
hex = (algorithm, value) => createHash6(algorithm).update(value, "utf8").digest("hex");
|
|
7437
8024
|
SIMPLE = {
|
|
7438
8025
|
lower: (value) => value.toLowerCase(),
|
|
7439
8026
|
upper: (value) => value.toUpperCase(),
|
|
@@ -7457,7 +8044,7 @@ var init_transforms = __esm({
|
|
|
7457
8044
|
});
|
|
7458
8045
|
|
|
7459
8046
|
// src/worlds/redaction.ts
|
|
7460
|
-
import { createHash as
|
|
8047
|
+
import { createHash as createHash7 } from "crypto";
|
|
7461
8048
|
function pyText(value) {
|
|
7462
8049
|
if (typeof value === "string") return value;
|
|
7463
8050
|
if (Number.isInteger(value)) return String(value);
|
|
@@ -7466,7 +8053,7 @@ function pyText(value) {
|
|
|
7466
8053
|
return pyFloatRepr(value);
|
|
7467
8054
|
}
|
|
7468
8055
|
function hashForm(slug, plaintext) {
|
|
7469
|
-
return "sha256:" +
|
|
8056
|
+
return "sha256:" + createHash7("sha256").update(`${slug}:${pyText(plaintext)}`, "utf8").digest("hex");
|
|
7470
8057
|
}
|
|
7471
8058
|
function preserveForm(slug, plaintext) {
|
|
7472
8059
|
const kind = typeof plaintext === "string" ? "str" : isInt(plaintext) ? "int" : "float";
|
|
@@ -7475,12 +8062,12 @@ function preserveForm(slug, plaintext) {
|
|
|
7475
8062
|
}
|
|
7476
8063
|
function shapeText(slug, text2, kind) {
|
|
7477
8064
|
const seed = Buffer.from(`${slug}:${text2}`, "utf8");
|
|
7478
|
-
let digest =
|
|
8065
|
+
let digest = createHash7("sha256").update(seed).digest();
|
|
7479
8066
|
let cursor = 0;
|
|
7480
8067
|
const out = [];
|
|
7481
8068
|
for (const char of text2) {
|
|
7482
8069
|
if (cursor === digest.length) {
|
|
7483
|
-
digest =
|
|
8070
|
+
digest = createHash7("sha256").update(Buffer.concat([digest, seed])).digest();
|
|
7484
8071
|
cursor = 0;
|
|
7485
8072
|
}
|
|
7486
8073
|
const byte = digest[cursor];
|
|
@@ -7619,9 +8206,9 @@ var init_router = __esm({
|
|
|
7619
8206
|
import * as fs6 from "fs";
|
|
7620
8207
|
import * as os from "os";
|
|
7621
8208
|
import * as path7 from "path";
|
|
7622
|
-
async function api(creds, method,
|
|
7623
|
-
const reply = await new PlatformTransport(creds).send(method,
|
|
7624
|
-
if (!reply.ok) throw new ApiError2(reply.status, method,
|
|
8209
|
+
async function api(creds, method, route2, body, init2 = {}) {
|
|
8210
|
+
const reply = await new PlatformTransport(creds).send(method, route2, body, init2);
|
|
8211
|
+
if (!reply.ok) throw new ApiError2(reply.status, method, route2, reply.text);
|
|
7625
8212
|
return reply.text ? JSON.parse(reply.text) : {};
|
|
7626
8213
|
}
|
|
7627
8214
|
var ApiError2;
|
|
@@ -7632,12 +8219,12 @@ var init_config = __esm({
|
|
|
7632
8219
|
init_worlds();
|
|
7633
8220
|
init_transport();
|
|
7634
8221
|
ApiError2 = class extends CliError {
|
|
7635
|
-
constructor(status, method,
|
|
7636
|
-
const body = parseErrorBody(text2);
|
|
7637
|
-
super(`${method} ${
|
|
8222
|
+
constructor(status, method, route2, text2) {
|
|
8223
|
+
const body = parseErrorBody(text2, status);
|
|
8224
|
+
super(`${method} ${route2} -> ${status}: ${body.detail}`, 1);
|
|
7638
8225
|
this.status = status;
|
|
7639
8226
|
this.method = method;
|
|
7640
|
-
this.route =
|
|
8227
|
+
this.route = route2;
|
|
7641
8228
|
this.text = text2;
|
|
7642
8229
|
this.code = body.code;
|
|
7643
8230
|
}
|
|
@@ -7655,6 +8242,14 @@ import { spawn, spawnSync } from "child_process";
|
|
|
7655
8242
|
import * as fs7 from "fs";
|
|
7656
8243
|
import * as net from "net";
|
|
7657
8244
|
import * as path8 from "path";
|
|
8245
|
+
function forwardedEnv() {
|
|
8246
|
+
return Object.fromEntries(
|
|
8247
|
+
FORWARDED_ENV.flatMap((name) => {
|
|
8248
|
+
const value = process.env[name];
|
|
8249
|
+
return value ? [[name, value]] : [];
|
|
8250
|
+
})
|
|
8251
|
+
);
|
|
8252
|
+
}
|
|
7658
8253
|
function tailOf(output) {
|
|
7659
8254
|
return output.length > DIAGNOSTIC_TAIL ? `\u2026${output.slice(-DIAGNOSTIC_TAIL)}` : output;
|
|
7660
8255
|
}
|
|
@@ -7772,7 +8367,7 @@ async function localBridge(request, local, opts = {}) {
|
|
|
7772
8367
|
PATH: process.env.PATH ?? "",
|
|
7773
8368
|
HOME: process.env.HOME ?? "",
|
|
7774
8369
|
TMPDIR: process.env.TMPDIR ?? "",
|
|
7775
|
-
...
|
|
8370
|
+
...forwardedEnv(),
|
|
7776
8371
|
GATEWAY_RUNTIME_EXECUTE: "1"
|
|
7777
8372
|
}
|
|
7778
8373
|
}
|
|
@@ -7818,7 +8413,7 @@ async function localBridge(request, local, opts = {}) {
|
|
|
7818
8413
|
child.stdin.end(input);
|
|
7819
8414
|
});
|
|
7820
8415
|
}
|
|
7821
|
-
var MIN_PYTHON, MIN_PYTHON_LABEL, DIAGNOSTIC_TAIL, BRIDGE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
|
|
8416
|
+
var MIN_PYTHON, MIN_PYTHON_LABEL, DIAGNOSTIC_TAIL, FORWARDED_ENV, BRIDGE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
|
|
7822
8417
|
var init_local = __esm({
|
|
7823
8418
|
"src/cli/runtime/local.ts"() {
|
|
7824
8419
|
"use strict";
|
|
@@ -7827,6 +8422,7 @@ var init_local = __esm({
|
|
|
7827
8422
|
MIN_PYTHON = [3, 12];
|
|
7828
8423
|
MIN_PYTHON_LABEL = MIN_PYTHON.join(".");
|
|
7829
8424
|
DIAGNOSTIC_TAIL = 600;
|
|
8425
|
+
FORWARDED_ENV = ["VIRTUAL_ENV", "GATEWAY_SNAPSHOT_STORE"];
|
|
7830
8426
|
BRIDGE_BOOTSTRAP = `import sys,runpy,types,os
|
|
7831
8427
|
root=sys.argv[1]
|
|
7832
8428
|
package=types.ModuleType('gatewaysdk')
|
|
@@ -7981,8 +8577,8 @@ async function runtime(creds, request, opts = {}) {
|
|
|
7981
8577
|
throw new CliError(
|
|
7982
8578
|
"This needs the schema runtime (the CLI bundles it) or platform credentials (`gateway auth login`). " + localRuntimeReason()
|
|
7983
8579
|
);
|
|
7984
|
-
const
|
|
7985
|
-
const res = await new PlatformTransport(creds).send("POST",
|
|
8580
|
+
const route2 = "/api/public/worlds/runtime";
|
|
8581
|
+
const res = await new PlatformTransport(creds).send("POST", route2, request, {
|
|
7986
8582
|
timeoutMs: opts.timeoutMs ?? RUNTIME_TIMEOUT_MS
|
|
7987
8583
|
});
|
|
7988
8584
|
let payload = null;
|
|
@@ -7994,8 +8590,8 @@ async function runtime(creds, request, opts = {}) {
|
|
|
7994
8590
|
const detail = detailFrom(payload);
|
|
7995
8591
|
if (detail) throw new BridgeRejected(detail);
|
|
7996
8592
|
if (!res.ok)
|
|
7997
|
-
throw new CliError(`POST ${
|
|
7998
|
-
if (payload === null) throw new CliError(`POST ${
|
|
8593
|
+
throw new CliError(`POST ${route2} (${request.command}) -> ${res.status}: ${res.text.slice(0, 600)}`, 1);
|
|
8594
|
+
if (payload === null) throw new CliError(`POST ${route2} (${request.command}) returned non-JSON`, 1);
|
|
7999
8595
|
return payload;
|
|
8000
8596
|
}
|
|
8001
8597
|
var MAX_WORLD_FILES, RUNTIME_TIMEOUT_MS, SKIP_DIRS, BridgeRejected, YAML_NAME, YAML_NEEDS_PYYAML, YAML_NOT_ON_PLATFORM, RuntimeRoute;
|
|
@@ -8455,18 +9051,22 @@ if (fn) {
|
|
|
8455
9051
|
});
|
|
8456
9052
|
|
|
8457
9053
|
// src/cli/platform/worldData/batches.ts
|
|
8458
|
-
import { createHash as
|
|
9054
|
+
import { createHash as createHash8 } from "crypto";
|
|
8459
9055
|
import * as fs11 from "fs";
|
|
8460
9056
|
function isSettled(status) {
|
|
8461
9057
|
if (!TERMINAL_STATES.has(status.state)) return false;
|
|
8462
9058
|
if (status.state !== "applied") return true;
|
|
8463
9059
|
return status.dryRun === true || status.publish !== "now" || !status.snapshotId;
|
|
8464
9060
|
}
|
|
9061
|
+
function worldDataPollMs() {
|
|
9062
|
+
const raw = Number(process.env.GATEWAY_WORLD_DATA_POLL_MS ?? 1e3);
|
|
9063
|
+
return Number.isFinite(raw) && raw >= 0 ? raw : 1e3;
|
|
9064
|
+
}
|
|
8465
9065
|
function uploadHeadersFor(gz) {
|
|
8466
9066
|
return {
|
|
8467
9067
|
"content-type": "application/gzip",
|
|
8468
9068
|
"content-length": String(gz.length),
|
|
8469
|
-
"x-amz-checksum-sha256":
|
|
9069
|
+
"x-amz-checksum-sha256": createHash8("sha256").update(gz).digest("base64")
|
|
8470
9070
|
};
|
|
8471
9071
|
}
|
|
8472
9072
|
async function forEachLimited(items, limit, fn) {
|
|
@@ -8504,6 +9104,8 @@ async function waitForBatch(client, batchId, opts = {}) {
|
|
|
8504
9104
|
last = phase;
|
|
8505
9105
|
}
|
|
8506
9106
|
if (isSettled(status)) return status;
|
|
9107
|
+
if (opts.deadlineMs !== void 0 && (opts.now ?? Date.now)() >= opts.deadlineMs)
|
|
9108
|
+
return status;
|
|
8507
9109
|
await sleep4(delay);
|
|
8508
9110
|
delay = Math.min(1e4, Math.round(delay * 1.5));
|
|
8509
9111
|
}
|
|
@@ -8553,11 +9155,6 @@ var init_batches = __esm({
|
|
|
8553
9155
|
}
|
|
8554
9156
|
);
|
|
8555
9157
|
}
|
|
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
9158
|
async stageDrive(batchId, chunk) {
|
|
8562
9159
|
const staged = await api(this.creds, "POST", `${this.base}/batches/${batchId}/chunks`, {
|
|
8563
9160
|
ordinal: chunk.ordinal,
|
|
@@ -8611,11 +9208,6 @@ var init_batches = __esm({
|
|
|
8611
9208
|
message ? { message } : {}
|
|
8612
9209
|
);
|
|
8613
9210
|
}
|
|
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
9211
|
async put(uploadUrl, gz, signed) {
|
|
8620
9212
|
const headers = signed ?? uploadHeadersFor(gz);
|
|
8621
9213
|
const delays = [500, 1500, 4e3];
|
|
@@ -8642,7 +9234,6 @@ var init_batches = __esm({
|
|
|
8642
9234
|
await this.sleep(delays[attempt]);
|
|
8643
9235
|
}
|
|
8644
9236
|
}
|
|
8645
|
-
/** Register, upload unless the server already holds the content, confirm. */
|
|
8646
9237
|
async upload(batchId, chunk) {
|
|
8647
9238
|
const registered = await this.register(batchId, chunk);
|
|
8648
9239
|
if (!registered.uploaded) {
|
|
@@ -8669,7 +9260,7 @@ var init_batches = __esm({
|
|
|
8669
9260
|
});
|
|
8670
9261
|
|
|
8671
9262
|
// src/cli/platform/worldData/chunker.ts
|
|
8672
|
-
import { createHash as
|
|
9263
|
+
import { createHash as createHash9 } from "crypto";
|
|
8673
9264
|
import { deflateRawSync } from "zlib";
|
|
8674
9265
|
function chunkLine(row, declared) {
|
|
8675
9266
|
if (declared !== null) return dumps(row.row) + "\n";
|
|
@@ -8710,12 +9301,12 @@ function finishChunk(ordinal, raw, rows, entity, firstRow = 0) {
|
|
|
8710
9301
|
const gz = gzipDeterministic(raw, { name: chunkName(ordinal) });
|
|
8711
9302
|
return {
|
|
8712
9303
|
ordinal,
|
|
8713
|
-
digest:
|
|
9304
|
+
digest: createHash9("sha256").update(gz).digest("hex"),
|
|
8714
9305
|
bytes: gz.length,
|
|
8715
9306
|
rows,
|
|
8716
9307
|
entity,
|
|
8717
9308
|
rawBytes: raw.length,
|
|
8718
|
-
contentSha256:
|
|
9309
|
+
contentSha256: createHash9("sha256").update(raw).digest("hex"),
|
|
8719
9310
|
firstRow,
|
|
8720
9311
|
gz
|
|
8721
9312
|
};
|
|
@@ -8783,22 +9374,33 @@ async function pushRows(creds, slug, rows, opts = {}) {
|
|
|
8783
9374
|
publish: opts.publish ?? "now",
|
|
8784
9375
|
...opts.message ? { message: opts.message } : {}
|
|
8785
9376
|
});
|
|
8786
|
-
if (!opened.batchId)
|
|
9377
|
+
if (!opened.batchId)
|
|
9378
|
+
throw new Error("the platform opened no batch (no batchId in the answer)");
|
|
8787
9379
|
const tagged = (async function* () {
|
|
8788
9380
|
for (const [entity, listed] of Object.entries(rows))
|
|
8789
9381
|
for (let index = 0; index < listed.length; index++)
|
|
8790
|
-
yield {
|
|
9382
|
+
yield {
|
|
9383
|
+
entity,
|
|
9384
|
+
row: parseJson(JSON.stringify(listed[index])),
|
|
9385
|
+
where: `${entity}[${index}]`
|
|
9386
|
+
};
|
|
8791
9387
|
})();
|
|
8792
|
-
const chunks = buildChunks(tagged, {
|
|
8793
|
-
|
|
8794
|
-
|
|
9388
|
+
const chunks = buildChunks(tagged, {
|
|
9389
|
+
chunkBytes: opts.chunkBytes ?? DEFAULT_CHUNK_BYTES,
|
|
9390
|
+
chunkRows: null,
|
|
9391
|
+
entity: null
|
|
8795
9392
|
});
|
|
9393
|
+
await forEachLimited(
|
|
9394
|
+
chunks,
|
|
9395
|
+
Math.max(1, opts.parallel ?? 4),
|
|
9396
|
+
async (chunk) => {
|
|
9397
|
+
await client.upload(opened.batchId, chunk);
|
|
9398
|
+
}
|
|
9399
|
+
);
|
|
8796
9400
|
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;
|
|
9401
|
+
return waitForBatch(client, opened.batchId, {
|
|
9402
|
+
initialDelayMs: worldDataPollMs()
|
|
9403
|
+
});
|
|
8802
9404
|
}
|
|
8803
9405
|
var init_push = __esm({
|
|
8804
9406
|
"src/cli/platform/worldData/push.ts"() {
|
|
@@ -9047,12 +9649,12 @@ var init_ingest = __esm({
|
|
|
9047
9649
|
});
|
|
9048
9650
|
|
|
9049
9651
|
// src/worlds/editSessions.ts
|
|
9050
|
-
var
|
|
9652
|
+
var WORLDS2, WorldEditClient, TASK_EDITS, TaskEditClient;
|
|
9051
9653
|
var init_editSessions = __esm({
|
|
9052
9654
|
"src/worlds/editSessions.ts"() {
|
|
9053
9655
|
"use strict";
|
|
9054
9656
|
init_worlds();
|
|
9055
|
-
|
|
9657
|
+
WORLDS2 = "/api/public/worlds";
|
|
9056
9658
|
WorldEditClient = class {
|
|
9057
9659
|
constructor(options = {}) {
|
|
9058
9660
|
this.options = options;
|
|
@@ -9064,19 +9666,19 @@ var init_editSessions = __esm({
|
|
|
9064
9666
|
if (query.status) qs.set("status", query.status);
|
|
9065
9667
|
if (query.limit !== void 0) qs.set("limit", String(query.limit));
|
|
9066
9668
|
const suffix = qs.size ? `?${qs.toString()}` : "";
|
|
9067
|
-
return apiRequest(this.options, "GET", `${
|
|
9669
|
+
return apiRequest(this.options, "GET", `${WORLDS2}/${encodeURIComponent(slug)}/edits${suffix}`);
|
|
9068
9670
|
}
|
|
9069
9671
|
/** Seal a session into a version on main (the credential's current one when `sessionId` is omitted). */
|
|
9070
9672
|
close(slug, input = {}) {
|
|
9071
|
-
return apiRequest(this.options, "POST", `${
|
|
9673
|
+
return apiRequest(this.options, "POST", `${WORLDS2}/${encodeURIComponent(slug)}/edits/close`, input);
|
|
9072
9674
|
}
|
|
9073
9675
|
/** Drop the session's private branch without making a version. */
|
|
9074
9676
|
discard(slug, input = {}) {
|
|
9075
|
-
return apiRequest(this.options, "POST", `${
|
|
9677
|
+
return apiRequest(this.options, "POST", `${WORLDS2}/${encodeURIComponent(slug)}/edits/discard`, input);
|
|
9076
9678
|
}
|
|
9077
9679
|
/** Undo a sealed session (source and data) as a new sealed session. */
|
|
9078
9680
|
rollback(slug, input) {
|
|
9079
|
-
return apiRequest(this.options, "POST", `${
|
|
9681
|
+
return apiRequest(this.options, "POST", `${WORLDS2}/${encodeURIComponent(slug)}/edits/rollback`, input);
|
|
9080
9682
|
}
|
|
9081
9683
|
};
|
|
9082
9684
|
TASK_EDITS = "/api/public/world-task-edits";
|
|
@@ -9230,15 +9832,27 @@ __export(worlds_exports, {
|
|
|
9230
9832
|
NativeComputer: () => NativeComputer,
|
|
9231
9833
|
OpenAIComputer: () => OpenAIComputer,
|
|
9232
9834
|
OpenAIPreviewComputer: () => OpenAIPreviewComputer,
|
|
9835
|
+
PLATFORM_SESSION_HEADER: () => PLATFORM_SESSION_HEADER,
|
|
9233
9836
|
PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
9234
9837
|
PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
|
|
9235
9838
|
PendingSafetyChecks: () => PendingSafetyChecks,
|
|
9236
9839
|
PlatformTransport: () => PlatformTransport,
|
|
9237
9840
|
PushSlugConflict: () => PushSlugConflict,
|
|
9238
9841
|
RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
|
|
9842
|
+
REQUESTS_NOT_RECORDED: () => REQUESTS_NOT_RECORDED,
|
|
9843
|
+
REQUEST_BODY_CAPTURE_BYTES: () => REQUEST_BODY_CAPTURE_BYTES,
|
|
9844
|
+
REQUEST_LOG_PAGE_MAX: () => REQUEST_LOG_PAGE_MAX,
|
|
9239
9845
|
RetryPolicy: () => RetryPolicy,
|
|
9846
|
+
SANDBOX_EXEC_REPORT_MARGIN_MS: () => SANDBOX_EXEC_REPORT_MARGIN_MS,
|
|
9847
|
+
SANDBOX_EXEC_START_ATTEMPTS: () => SANDBOX_EXEC_START_ATTEMPTS,
|
|
9848
|
+
SANDBOX_EXEC_TIMEOUT_MAX_S: () => SANDBOX_EXEC_TIMEOUT_MAX_S,
|
|
9849
|
+
SANDBOX_EXEC_WAIT_MS: () => SANDBOX_EXEC_WAIT_MS,
|
|
9850
|
+
SANDBOX_FILE_MAX_BYTES: () => SANDBOX_FILE_MAX_BYTES,
|
|
9240
9851
|
SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
|
|
9852
|
+
SANDBOX_WRITE_CHUNK_BYTES: () => SANDBOX_WRITE_CHUNK_BYTES,
|
|
9853
|
+
SANDBOX_WRITE_SKIPPED: () => SANDBOX_WRITE_SKIPPED,
|
|
9241
9854
|
SECRET_KEY: () => SECRET_KEY,
|
|
9855
|
+
SESSION_AUTH_MODES: () => SESSION_AUTH_MODES,
|
|
9242
9856
|
SESSION_STATES: () => SESSION_STATES,
|
|
9243
9857
|
SPAN_PREFIX: () => SPAN_PREFIX,
|
|
9244
9858
|
STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
|
|
@@ -9250,17 +9864,24 @@ __export(worlds_exports, {
|
|
|
9250
9864
|
TOOL_CONTRACT_UNREAD: () => TOOL_CONTRACT_UNREAD,
|
|
9251
9865
|
TRANSFORMS: () => TRANSFORMS,
|
|
9252
9866
|
TaskEditClient: () => TaskEditClient,
|
|
9867
|
+
TaskGrades: () => TaskGrades,
|
|
9253
9868
|
TaskRun: () => TaskRun,
|
|
9254
9869
|
TaskSessions: () => TaskSessions,
|
|
9255
9870
|
TransportCause: () => TransportCause,
|
|
9256
9871
|
UnreachableError: () => UnreachableError,
|
|
9257
9872
|
VERIFIER_REWARD_PREFIX: () => VERIFIER_REWARD_PREFIX,
|
|
9258
9873
|
WHITESPACE: () => WHITESPACE,
|
|
9874
|
+
WORLD_REQUEST_VIAS: () => WORLD_REQUEST_VIAS,
|
|
9875
|
+
WORLD_WEBHOOK_PAGE_MAX: () => WORLD_WEBHOOK_PAGE_MAX,
|
|
9259
9876
|
WorldBrowser: () => WorldBrowser,
|
|
9260
9877
|
WorldCallTooLarge: () => WorldCallTooLarge,
|
|
9261
9878
|
WorldEditClient: () => WorldEditClient,
|
|
9262
9879
|
WorldNotice: () => WorldNotice,
|
|
9880
|
+
WorldRequestFilterError: () => WorldRequestFilterError,
|
|
9881
|
+
WorldRequestLedger: () => WorldRequestLedger,
|
|
9263
9882
|
WorldRequestLog: () => WorldRequestLog,
|
|
9883
|
+
WorldRequestQuery: () => WorldRequestQuery,
|
|
9884
|
+
WorldRequestsNotRecorded: () => WorldRequestsNotRecorded,
|
|
9264
9885
|
WorldSandboxClient: () => WorldSandboxClient,
|
|
9265
9886
|
WorldSession: () => WorldSession,
|
|
9266
9887
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
@@ -9270,18 +9891,23 @@ __export(worlds_exports, {
|
|
|
9270
9891
|
WorldSurfaceUnavailable: () => WorldSurfaceUnavailable,
|
|
9271
9892
|
WorldTask: () => WorldTask,
|
|
9272
9893
|
WorldToolsUnread: () => WorldToolsUnread,
|
|
9894
|
+
WorldWebhookForwarder: () => WorldWebhookForwarder,
|
|
9895
|
+
WriteTreeFilter: () => WriteTreeFilter,
|
|
9273
9896
|
aggregateTaskGrade: () => aggregateTaskGrade,
|
|
9274
9897
|
apiRequest: () => apiRequest,
|
|
9275
9898
|
applyTransforms: () => applyTransforms,
|
|
9276
9899
|
archiveMode: () => archiveMode,
|
|
9277
9900
|
assertBrowserTier: () => assertBrowserTier,
|
|
9901
|
+
assertSessionAuthMode: () => assertSessionAuthMode,
|
|
9278
9902
|
assertTaskRef: () => assertTaskRef,
|
|
9279
9903
|
attachManifest: () => attachManifest,
|
|
9280
9904
|
attachSession: () => attachSession,
|
|
9281
9905
|
attachTask: () => attachTask,
|
|
9282
9906
|
buildFileManifest: () => buildFileManifest,
|
|
9283
9907
|
buildSourceTarball: () => buildSourceTarball,
|
|
9908
|
+
capabilityLabel: () => capabilityLabel,
|
|
9284
9909
|
captureToolCalls: () => captureToolCalls,
|
|
9910
|
+
carriedWarnings: () => carriedWarnings,
|
|
9285
9911
|
checkoutIdentity: () => checkoutIdentity,
|
|
9286
9912
|
closeConnection: () => closeConnection,
|
|
9287
9913
|
collectArchiveRelPaths: () => collectArchiveRelPaths,
|
|
@@ -9300,7 +9926,9 @@ __export(worlds_exports, {
|
|
|
9300
9926
|
idleWarning: () => idleWarning,
|
|
9301
9927
|
ingest: () => ingest,
|
|
9302
9928
|
ingestToolCalls: () => ingestToolCalls,
|
|
9929
|
+
invalidFields: () => invalidFields,
|
|
9303
9930
|
isBrowserGone: () => isBrowserGone,
|
|
9931
|
+
isSandboxCommitPending: () => isSandboxCommitPending,
|
|
9304
9932
|
isSandboxImportPending: () => isSandboxImportPending,
|
|
9305
9933
|
isTaskIdRef: () => isTaskIdRef,
|
|
9306
9934
|
isTaskManifest: () => isTaskManifest,
|
|
@@ -9311,6 +9939,7 @@ __export(worlds_exports, {
|
|
|
9311
9939
|
listSessions: () => listSessions,
|
|
9312
9940
|
listTaskSessions: () => listTaskSessions,
|
|
9313
9941
|
listTasks: () => listTasks,
|
|
9942
|
+
listWebhooks: () => listWebhooks,
|
|
9314
9943
|
localTreeState: () => localTreeState,
|
|
9315
9944
|
messageOf: () => messageOf,
|
|
9316
9945
|
migrateProjectWorlds: () => migrateProjectWorlds,
|
|
@@ -9347,6 +9976,7 @@ __export(worlds_exports, {
|
|
|
9347
9976
|
resolveBrowserMode: () => resolveBrowserMode,
|
|
9348
9977
|
resolvePushSlug: () => resolvePushSlug,
|
|
9349
9978
|
roundForm: () => roundForm,
|
|
9979
|
+
rowsRefusal: () => rowsRefusal,
|
|
9350
9980
|
runSessions: () => runSessions,
|
|
9351
9981
|
runSet: () => runSet,
|
|
9352
9982
|
runTask: () => runTask,
|
|
@@ -9375,27 +10005,42 @@ __export(worlds_exports, {
|
|
|
9375
10005
|
validateWorld: () => validateWorld,
|
|
9376
10006
|
waitForRun: () => waitForRun,
|
|
9377
10007
|
withoutUiToken: () => withoutUiToken,
|
|
10008
|
+
worldRequestsUnrecorded: () => worldRequestsUnrecorded,
|
|
9378
10009
|
writeLocalMeta: () => writeLocalMeta
|
|
9379
10010
|
});
|
|
9380
|
-
function
|
|
9381
|
-
|
|
10011
|
+
function edgeAnswer(text2, status) {
|
|
10012
|
+
if (status !== void 0 && status >= 500) return EDGE_ANSWERS[status] ?? EDGE_FAILURE;
|
|
10013
|
+
return /^\s*</.test(text2) ? EDGE_PAGE : null;
|
|
10014
|
+
}
|
|
10015
|
+
function parseErrorBody(text2, status) {
|
|
10016
|
+
const raw = { detail: text2.slice(0, DETAIL_LIMIT), code: null };
|
|
9382
10017
|
let parsed;
|
|
9383
10018
|
try {
|
|
9384
10019
|
parsed = JSON.parse(text2);
|
|
9385
10020
|
} catch {
|
|
9386
|
-
return
|
|
10021
|
+
return { detail: (edgeAnswer(text2, status) ?? text2).slice(0, DETAIL_LIMIT), code: null };
|
|
9387
10022
|
}
|
|
9388
10023
|
if (parsed === null || typeof parsed !== "object") return raw;
|
|
9389
|
-
const { message, code } = parsed;
|
|
10024
|
+
const { message, code, error } = parsed;
|
|
9390
10025
|
const stableCode = typeof code === "string" ? code : null;
|
|
9391
10026
|
if (typeof message !== "string") return { ...raw, code: stableCode };
|
|
9392
|
-
|
|
9393
|
-
|
|
10027
|
+
const fields = invalidFields(error);
|
|
10028
|
+
const said = fields ? `${message}: ${fields}` : message;
|
|
10029
|
+
if (stableCode === null) return { detail: said.slice(0, DETAIL_LIMIT), code: null };
|
|
9394
10030
|
return {
|
|
9395
|
-
detail: `${
|
|
10031
|
+
detail: `${said} (${stableCode})`.slice(0, DETAIL_LIMIT),
|
|
9396
10032
|
code: stableCode
|
|
9397
10033
|
};
|
|
9398
10034
|
}
|
|
10035
|
+
function invalidFields(error) {
|
|
10036
|
+
const issues = Array.isArray(error) ? error : [];
|
|
10037
|
+
return issues.filter(
|
|
10038
|
+
(issue) => issue !== null && typeof issue === "object" && typeof issue.message === "string"
|
|
10039
|
+
).map((issue) => {
|
|
10040
|
+
const path13 = Array.isArray(issue.path) ? issue.path.map(String).join(".") : "";
|
|
10041
|
+
return path13 ? `${path13}: ${issue.message}` : issue.message;
|
|
10042
|
+
}).join("; ");
|
|
10043
|
+
}
|
|
9399
10044
|
async function apiRequest(options, method, path13, body, init2 = {}) {
|
|
9400
10045
|
const reply = await new PlatformTransport(requirePlatformEndpoint(options)).send(method, path13, body, init2);
|
|
9401
10046
|
if (!reply.ok) throw new ApiError(reply.status, method, path13, reply.text);
|
|
@@ -9574,7 +10219,7 @@ async function resolveWorld(slugRef, slug, ref, pin, options) {
|
|
|
9574
10219
|
}
|
|
9575
10220
|
return world;
|
|
9576
10221
|
}
|
|
9577
|
-
var ApiError, WorldTask, WorldSet;
|
|
10222
|
+
var ApiError, DETAIL_LIMIT, EDGE_ANSWERS, EDGE_FAILURE, EDGE_PAGE, WorldTask, WorldSet;
|
|
9578
10223
|
var init_worlds = __esm({
|
|
9579
10224
|
"src/worlds/index.ts"() {
|
|
9580
10225
|
init_platformEndpoint();
|
|
@@ -9586,6 +10231,7 @@ var init_worlds = __esm({
|
|
|
9586
10231
|
init_sessionContract();
|
|
9587
10232
|
init_taskRef();
|
|
9588
10233
|
init_tasks();
|
|
10234
|
+
init_taskGrades();
|
|
9589
10235
|
init_taskSessions();
|
|
9590
10236
|
init_taskRun();
|
|
9591
10237
|
init_setRun();
|
|
@@ -9594,6 +10240,8 @@ var init_worlds = __esm({
|
|
|
9594
10240
|
init_browser();
|
|
9595
10241
|
init_surfaceDescriptor();
|
|
9596
10242
|
init_requestLog();
|
|
10243
|
+
init_requestLedger();
|
|
10244
|
+
init_webhooks();
|
|
9597
10245
|
init_browserReconnect();
|
|
9598
10246
|
init_nativeComputer();
|
|
9599
10247
|
init_hub();
|
|
@@ -9610,7 +10258,7 @@ var init_worlds = __esm({
|
|
|
9610
10258
|
init_worldNotice();
|
|
9611
10259
|
ApiError = class extends Error {
|
|
9612
10260
|
constructor(status, method, path13, text2) {
|
|
9613
|
-
const parsed = parseErrorBody(text2);
|
|
10261
|
+
const parsed = parseErrorBody(text2, status);
|
|
9614
10262
|
super(`${method} ${path13} -> ${status}: ${parsed.detail}`);
|
|
9615
10263
|
this.status = status;
|
|
9616
10264
|
this.text = text2;
|
|
@@ -9621,6 +10269,14 @@ var init_worlds = __esm({
|
|
|
9621
10269
|
text;
|
|
9622
10270
|
code;
|
|
9623
10271
|
};
|
|
10272
|
+
DETAIL_LIMIT = 600;
|
|
10273
|
+
EDGE_ANSWERS = {
|
|
10274
|
+
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.",
|
|
10275
|
+
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.",
|
|
10276
|
+
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."
|
|
10277
|
+
};
|
|
10278
|
+
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.";
|
|
10279
|
+
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
10280
|
WorldTask = class {
|
|
9625
10281
|
constructor(world, name, variant) {
|
|
9626
10282
|
this.world = world;
|
|
@@ -9656,12 +10312,7 @@ var init_worlds = __esm({
|
|
|
9656
10312
|
}
|
|
9657
10313
|
return hit;
|
|
9658
10314
|
}
|
|
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
|
-
*/
|
|
10315
|
+
/** Open a live session on a bundled task's name or an inline `WorldTaskSpec`; the platform boots or reuses a warm container. */
|
|
9665
10316
|
async open(task, opts = {}) {
|
|
9666
10317
|
const { openSession: openSession2 } = await Promise.resolve().then(() => (init_session2(), session_exports2));
|
|
9667
10318
|
return openSession2(this.slug, {
|
|
@@ -9673,11 +10324,7 @@ var init_worlds = __esm({
|
|
|
9673
10324
|
options: this.options
|
|
9674
10325
|
});
|
|
9675
10326
|
}
|
|
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
|
-
*/
|
|
10327
|
+
/** Start a hosted run of a run config on this version (or `opts.versionId`): one graded run per model, provenance detected unless given. */
|
|
9681
10328
|
async dispatch(runConfigId, opts = {}) {
|
|
9682
10329
|
const provenance = opts.provenance ?? detectProvenance();
|
|
9683
10330
|
return apiRequest(
|
|
@@ -9737,15 +10384,27 @@ export {
|
|
|
9737
10384
|
NativeComputer,
|
|
9738
10385
|
OpenAIComputer,
|
|
9739
10386
|
OpenAIPreviewComputer,
|
|
10387
|
+
PLATFORM_SESSION_HEADER,
|
|
9740
10388
|
PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
9741
10389
|
PLATFORM_TIMEOUT_ENV,
|
|
9742
10390
|
PendingSafetyChecks,
|
|
9743
10391
|
PlatformTransport,
|
|
9744
10392
|
PushSlugConflict,
|
|
9745
10393
|
RECOVER_BUDGET_MS,
|
|
10394
|
+
REQUESTS_NOT_RECORDED,
|
|
10395
|
+
REQUEST_BODY_CAPTURE_BYTES,
|
|
10396
|
+
REQUEST_LOG_PAGE_MAX,
|
|
9746
10397
|
RetryPolicy,
|
|
10398
|
+
SANDBOX_EXEC_REPORT_MARGIN_MS,
|
|
10399
|
+
SANDBOX_EXEC_START_ATTEMPTS,
|
|
10400
|
+
SANDBOX_EXEC_TIMEOUT_MAX_S,
|
|
10401
|
+
SANDBOX_EXEC_WAIT_MS,
|
|
10402
|
+
SANDBOX_FILE_MAX_BYTES,
|
|
9747
10403
|
SANDBOX_REQUEST_TIMEOUT_MS,
|
|
10404
|
+
SANDBOX_WRITE_CHUNK_BYTES,
|
|
10405
|
+
SANDBOX_WRITE_SKIPPED,
|
|
9748
10406
|
SECRET_KEY,
|
|
10407
|
+
SESSION_AUTH_MODES,
|
|
9749
10408
|
SESSION_STATES,
|
|
9750
10409
|
SPAN_PREFIX,
|
|
9751
10410
|
STATUS_WAIT_CAP_SECONDS,
|
|
@@ -9757,17 +10416,24 @@ export {
|
|
|
9757
10416
|
TOOL_CONTRACT_UNREAD,
|
|
9758
10417
|
TRANSFORMS,
|
|
9759
10418
|
TaskEditClient,
|
|
10419
|
+
TaskGrades,
|
|
9760
10420
|
TaskRun,
|
|
9761
10421
|
TaskSessions,
|
|
9762
10422
|
TransportCause,
|
|
9763
10423
|
UnreachableError,
|
|
9764
10424
|
VERIFIER_REWARD_PREFIX,
|
|
9765
10425
|
WHITESPACE,
|
|
10426
|
+
WORLD_REQUEST_VIAS,
|
|
10427
|
+
WORLD_WEBHOOK_PAGE_MAX,
|
|
9766
10428
|
WorldBrowser,
|
|
9767
10429
|
WorldCallTooLarge,
|
|
9768
10430
|
WorldEditClient,
|
|
9769
10431
|
WorldNotice,
|
|
10432
|
+
WorldRequestFilterError,
|
|
10433
|
+
WorldRequestLedger,
|
|
9770
10434
|
WorldRequestLog,
|
|
10435
|
+
WorldRequestQuery,
|
|
10436
|
+
WorldRequestsNotRecorded,
|
|
9771
10437
|
WorldSandboxClient,
|
|
9772
10438
|
WorldSession,
|
|
9773
10439
|
WorldSessionCallError,
|
|
@@ -9777,18 +10443,23 @@ export {
|
|
|
9777
10443
|
WorldSurfaceUnavailable,
|
|
9778
10444
|
WorldTask,
|
|
9779
10445
|
WorldToolsUnread,
|
|
10446
|
+
WorldWebhookForwarder,
|
|
10447
|
+
WriteTreeFilter,
|
|
9780
10448
|
aggregateTaskGrade,
|
|
9781
10449
|
apiRequest,
|
|
9782
10450
|
applyTransforms,
|
|
9783
10451
|
archiveMode,
|
|
9784
10452
|
assertBrowserTier,
|
|
10453
|
+
assertSessionAuthMode,
|
|
9785
10454
|
assertTaskRef,
|
|
9786
10455
|
attachManifest,
|
|
9787
10456
|
attachSession,
|
|
9788
10457
|
attachTask,
|
|
9789
10458
|
buildFileManifest,
|
|
9790
10459
|
buildSourceTarball,
|
|
10460
|
+
capabilityLabel,
|
|
9791
10461
|
captureToolCalls,
|
|
10462
|
+
carriedWarnings,
|
|
9792
10463
|
checkoutIdentity,
|
|
9793
10464
|
closeConnection,
|
|
9794
10465
|
collectArchiveRelPaths,
|
|
@@ -9807,7 +10478,9 @@ export {
|
|
|
9807
10478
|
idleWarning,
|
|
9808
10479
|
ingest,
|
|
9809
10480
|
ingestToolCalls,
|
|
10481
|
+
invalidFields,
|
|
9810
10482
|
isBrowserGone,
|
|
10483
|
+
isSandboxCommitPending,
|
|
9811
10484
|
isSandboxImportPending,
|
|
9812
10485
|
isTaskIdRef,
|
|
9813
10486
|
isTaskManifest,
|
|
@@ -9818,6 +10491,7 @@ export {
|
|
|
9818
10491
|
listSessions,
|
|
9819
10492
|
listTaskSessions,
|
|
9820
10493
|
listTasks,
|
|
10494
|
+
listWebhooks,
|
|
9821
10495
|
localTreeState,
|
|
9822
10496
|
messageOf,
|
|
9823
10497
|
migrateProjectWorlds,
|
|
@@ -9854,6 +10528,7 @@ export {
|
|
|
9854
10528
|
resolveBrowserMode,
|
|
9855
10529
|
resolvePushSlug,
|
|
9856
10530
|
roundForm,
|
|
10531
|
+
rowsRefusal,
|
|
9857
10532
|
runSessions,
|
|
9858
10533
|
runSet,
|
|
9859
10534
|
runTask,
|
|
@@ -9882,6 +10557,7 @@ export {
|
|
|
9882
10557
|
validateWorld,
|
|
9883
10558
|
waitForRun,
|
|
9884
10559
|
withoutUiToken,
|
|
10560
|
+
worldRequestsUnrecorded,
|
|
9885
10561
|
writeLocalMeta
|
|
9886
10562
|
};
|
|
9887
10563
|
//# sourceMappingURL=index.mjs.map
|