@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.js
CHANGED
|
@@ -72,7 +72,7 @@ function platformTimeoutMs(env = process.env) {
|
|
|
72
72
|
if (Number.isInteger(value) && value > 0) return value;
|
|
73
73
|
throw new Error(`${PLATFORM_TIMEOUT_ENV} must be a positive whole number of milliseconds, not \`${raw}\`.`);
|
|
74
74
|
}
|
|
75
|
-
var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, sleep, RetryPolicy, Attempt, PlatformTransport;
|
|
75
|
+
var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, FETCH_LIMIT, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, sleep, RetryPolicy, Attempt, PlatformTransport;
|
|
76
76
|
var init_transport = __esm({
|
|
77
77
|
"src/worlds/transport.ts"() {
|
|
78
78
|
"use strict";
|
|
@@ -80,7 +80,13 @@ var init_transport = __esm({
|
|
|
80
80
|
PLATFORM_TIMEOUT_DEFAULT_MS = 12e4;
|
|
81
81
|
CHECK_HOST = "Check GATEWAY_HOST (or --host) points at a running platform, then retry.";
|
|
82
82
|
RETRY = "Retry; if it repeats, check the network between here and the platform.";
|
|
83
|
+
FETCH_LIMIT = {
|
|
84
|
+
reason: "Node's fetch stopped waiting after 300 s",
|
|
85
|
+
next: "The platform may still be running it: check what it changed before you retry."
|
|
86
|
+
};
|
|
83
87
|
CAUSES = {
|
|
88
|
+
UND_ERR_HEADERS_TIMEOUT: FETCH_LIMIT,
|
|
89
|
+
UND_ERR_BODY_TIMEOUT: FETCH_LIMIT,
|
|
84
90
|
ECONNREFUSED: { reason: "connection refused", next: CHECK_HOST },
|
|
85
91
|
ENOTFOUND: { reason: "DNS lookup failed", next: CHECK_HOST },
|
|
86
92
|
EAI_AGAIN: { reason: "DNS lookup failed", next: CHECK_HOST },
|
|
@@ -121,11 +127,11 @@ var init_transport = __esm({
|
|
|
121
127
|
}
|
|
122
128
|
};
|
|
123
129
|
UnreachableError = class extends Error {
|
|
124
|
-
constructor(host, method,
|
|
125
|
-
super(`${method} ${
|
|
130
|
+
constructor(host, method, route2, failure) {
|
|
131
|
+
super(`${method} ${route2}: no answer from ${host}: ${failure.describe()}. ${failure.next}`);
|
|
126
132
|
this.host = host;
|
|
127
133
|
this.method = method;
|
|
128
|
-
this.route =
|
|
134
|
+
this.route = route2;
|
|
129
135
|
this.failure = failure;
|
|
130
136
|
this.name = "UnreachableError";
|
|
131
137
|
}
|
|
@@ -195,16 +201,16 @@ var init_transport = __esm({
|
|
|
195
201
|
budget(ownMs) {
|
|
196
202
|
return Math.max(ownMs ?? 0, this.timeoutMs);
|
|
197
203
|
}
|
|
198
|
-
async send(method,
|
|
204
|
+
async send(method, route2, body, opts = {}) {
|
|
199
205
|
const timeoutMs = this.budget(opts.timeoutMs);
|
|
200
|
-
return (opts.retry ?? RetryPolicy.NONE).run(() => this.once(method,
|
|
206
|
+
return (opts.retry ?? RetryPolicy.NONE).run(() => this.once(method, route2, body, timeoutMs));
|
|
201
207
|
}
|
|
202
|
-
async once(method,
|
|
208
|
+
async once(method, route2, body, timeoutMs) {
|
|
203
209
|
const payload = body === void 0 ? {} : { body: JSON.stringify(body) };
|
|
204
210
|
const controller = new AbortController();
|
|
205
211
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
206
212
|
try {
|
|
207
|
-
const res = await fetch(`${this.endpoint.host}${
|
|
213
|
+
const res = await fetch(`${this.endpoint.host}${route2}`, {
|
|
208
214
|
method,
|
|
209
215
|
headers: {
|
|
210
216
|
"content-type": "application/json",
|
|
@@ -217,7 +223,7 @@ var init_transport = __esm({
|
|
|
217
223
|
return { status: res.status, ok: res.ok, text: await res.text() };
|
|
218
224
|
} catch (error) {
|
|
219
225
|
const cause = controller.signal.aborted ? TransportCause.timeout(timeoutMs) : TransportCause.of(error);
|
|
220
|
-
throw new UnreachableError(this.endpoint.host, method,
|
|
226
|
+
throw new UnreachableError(this.endpoint.host, method, route2, cause);
|
|
221
227
|
} finally {
|
|
222
228
|
clearTimeout(timer);
|
|
223
229
|
}
|
|
@@ -380,6 +386,12 @@ var init_browserReconnect = __esm({
|
|
|
380
386
|
});
|
|
381
387
|
|
|
382
388
|
// src/worlds/browser.ts
|
|
389
|
+
function assertSessionAuthMode(value) {
|
|
390
|
+
if (SESSION_AUTH_MODES.includes(value)) return;
|
|
391
|
+
throw new Error(
|
|
392
|
+
`Unknown session auth: ${String(value)}; choose from ${SESSION_AUTH_MODES.join(", ")}`
|
|
393
|
+
);
|
|
394
|
+
}
|
|
383
395
|
function assertBrowserTier(value) {
|
|
384
396
|
if (BROWSER_TIERS.includes(value)) return;
|
|
385
397
|
throw new Error(
|
|
@@ -416,6 +428,15 @@ function splitHash(url) {
|
|
|
416
428
|
const h = url.indexOf("#");
|
|
417
429
|
return h < 0 ? [url, ""] : [url.slice(0, h), url.slice(h)];
|
|
418
430
|
}
|
|
431
|
+
function capabilityLabel(url) {
|
|
432
|
+
let host = "";
|
|
433
|
+
try {
|
|
434
|
+
host = url ? new URL(url).hostname : "";
|
|
435
|
+
} catch {
|
|
436
|
+
return null;
|
|
437
|
+
}
|
|
438
|
+
return CAPABILITY_HOST.exec(host)?.[1] ?? null;
|
|
439
|
+
}
|
|
419
440
|
function redactActionArgs(action, args) {
|
|
420
441
|
const secretField = action === "browser_type" && SECRET_KEY.test(String(args.selector ?? ""));
|
|
421
442
|
const out = {};
|
|
@@ -475,7 +496,9 @@ async function openBrowser(surfaces, opts = {}) {
|
|
|
475
496
|
};
|
|
476
497
|
const scrubber = new SecretScrubber([
|
|
477
498
|
surfaces.browser?.wsUrl,
|
|
478
|
-
surfaces.ui?.token
|
|
499
|
+
surfaces.ui?.token,
|
|
500
|
+
capabilityLabel(surfaces.ui?.url),
|
|
501
|
+
capabilityLabel(surfaces.api?.url)
|
|
479
502
|
]);
|
|
480
503
|
const reconnector = mode === "hosted" && surfaces.browser.protocol === "cdp" && opts.repair ? new BrowserReconnector(opts.repair, reattach, {
|
|
481
504
|
scrub: (text2) => scrubber.scrub(text2)
|
|
@@ -540,13 +563,15 @@ function computerUseToolkit(browser, opts = {}) {
|
|
|
540
563
|
specs
|
|
541
564
|
};
|
|
542
565
|
}
|
|
543
|
-
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;
|
|
566
|
+
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;
|
|
544
567
|
var init_browser = __esm({
|
|
545
568
|
"src/worlds/browser.ts"() {
|
|
546
569
|
"use strict";
|
|
547
570
|
init_session2();
|
|
548
571
|
init_browserReconnect();
|
|
549
572
|
SURFACE_KINDS = ["tools", "api", "ui", "browser"];
|
|
573
|
+
PLATFORM_SESSION_HEADER = "X-World-Session";
|
|
574
|
+
SESSION_AUTH_MODES = ["vendor", "open"];
|
|
550
575
|
BROWSER_TIERS = ["standard", "premium"];
|
|
551
576
|
DEFAULT_VIEWPORT = { width: 1280, height: 800 };
|
|
552
577
|
SETTLE_TIMEOUT_MS = 5e3;
|
|
@@ -567,6 +592,7 @@ var init_browser = __esm({
|
|
|
567
592
|
surface;
|
|
568
593
|
};
|
|
569
594
|
UI_TOKEN_QUERY = "token";
|
|
595
|
+
CAPABILITY_HOST = /^o-[a-z0-9]+-([a-z2-7]{26})(?:-api)?\./;
|
|
570
596
|
BrowserActionRecorder = class {
|
|
571
597
|
constructor(post, agentId, opts = {}) {
|
|
572
598
|
this.post = post;
|
|
@@ -659,7 +685,10 @@ var init_browser = __esm({
|
|
|
659
685
|
}
|
|
660
686
|
};
|
|
661
687
|
WorldBrowser = class {
|
|
662
|
-
constructor(page, ui, mode, teardown, viewport = DEFAULT_VIEWPORT, recorder = null, reconnector = null, scrubber = new SecretScrubber([
|
|
688
|
+
constructor(page, ui, mode, teardown, viewport = DEFAULT_VIEWPORT, recorder = null, reconnector = null, scrubber = new SecretScrubber([
|
|
689
|
+
ui?.token,
|
|
690
|
+
capabilityLabel(ui?.url)
|
|
691
|
+
])) {
|
|
663
692
|
this.ui = ui;
|
|
664
693
|
this.mode = mode;
|
|
665
694
|
this.teardown = teardown;
|
|
@@ -796,7 +825,15 @@ var init_browser = __esm({
|
|
|
796
825
|
seq: recorder.nextSeq(),
|
|
797
826
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
798
827
|
action,
|
|
799
|
-
args: redactActionArgs(
|
|
828
|
+
args: redactActionArgs(
|
|
829
|
+
action,
|
|
830
|
+
Object.fromEntries(
|
|
831
|
+
Object.entries(args).map(([key, value]) => [
|
|
832
|
+
key,
|
|
833
|
+
typeof value === "string" ? this.scrubber.scrub(value) : value
|
|
834
|
+
])
|
|
835
|
+
)
|
|
836
|
+
),
|
|
800
837
|
ok: failure === null,
|
|
801
838
|
error,
|
|
802
839
|
durationMs: Date.now() - started,
|
|
@@ -812,8 +849,8 @@ var init_browser = __esm({
|
|
|
812
849
|
screenshot: null
|
|
813
850
|
};
|
|
814
851
|
try {
|
|
815
|
-
out.url = this.page.url();
|
|
816
|
-
out.title = await this.page.title();
|
|
852
|
+
out.url = this.scrubber.scrub(this.page.url());
|
|
853
|
+
out.title = this.scrubber.scrub(await this.page.title());
|
|
817
854
|
const jpeg = await this.page.screenshot({
|
|
818
855
|
type: "jpeg",
|
|
819
856
|
quality: EVENT_SCREENSHOT_QUALITY
|
|
@@ -1448,11 +1485,11 @@ var init_media = __esm({
|
|
|
1448
1485
|
status
|
|
1449
1486
|
);
|
|
1450
1487
|
}
|
|
1451
|
-
async send(method,
|
|
1452
|
-
const reply = await this.transport.send(method,
|
|
1488
|
+
async send(method, route2, body) {
|
|
1489
|
+
const reply = await this.transport.send(method, route2, body);
|
|
1453
1490
|
if (!reply.ok)
|
|
1454
1491
|
throw new MediaUploadError(
|
|
1455
|
-
`${method} ${
|
|
1492
|
+
`${method} ${route2} -> ${reply.status}`,
|
|
1456
1493
|
reply.status
|
|
1457
1494
|
);
|
|
1458
1495
|
return reply.text ? JSON.parse(reply.text) : {};
|
|
@@ -1805,7 +1842,7 @@ function click(button, count) {
|
|
|
1805
1842
|
modifiers: modifierChord(raw.text)
|
|
1806
1843
|
});
|
|
1807
1844
|
}
|
|
1808
|
-
var SCROLL_STEP_PX, NOT_EXECUTED, MAX_ERROR2, SCROLL_DIRECTIONS, MEMBERS, AnthropicComputer, AnthropicComputer20251124;
|
|
1845
|
+
var SCROLL_STEP_PX, NOT_EXECUTED, MAX_ERROR2, SCROLL_DIRECTIONS, IMAGE_PARTS, MEMBERS, AnthropicComputer, AnthropicComputer20251124;
|
|
1809
1846
|
var init_anthropic = __esm({
|
|
1810
1847
|
"src/worlds/nativeComputer/anthropic.ts"() {
|
|
1811
1848
|
"use strict";
|
|
@@ -1821,6 +1858,14 @@ var init_anthropic = __esm({
|
|
|
1821
1858
|
left: [-1, 0],
|
|
1822
1859
|
right: [1, 0]
|
|
1823
1860
|
};
|
|
1861
|
+
IMAGE_PARTS = {
|
|
1862
|
+
6: (data) => ({ type: "image-data", data, mediaType: "image/png" }),
|
|
1863
|
+
7: (data) => ({
|
|
1864
|
+
type: "file",
|
|
1865
|
+
mediaType: "image/png",
|
|
1866
|
+
data: { type: "data", data }
|
|
1867
|
+
})
|
|
1868
|
+
};
|
|
1824
1869
|
MEMBERS = {
|
|
1825
1870
|
screenshot: () => new ComputerAction("screenshot"),
|
|
1826
1871
|
zoom: (raw) => new ComputerAction("zoom", {
|
|
@@ -1930,15 +1975,17 @@ var init_anthropic = __esm({
|
|
|
1930
1975
|
];
|
|
1931
1976
|
return [{ type: "text", text: result.text ?? "OK" }];
|
|
1932
1977
|
}
|
|
1933
|
-
/** For `anthropic.tools.computerToolset_20260801(
|
|
1934
|
-
* (or `computer_20251124` with the legacy kind
|
|
1935
|
-
* and returns `{ type: "image", data }` or
|
|
1936
|
-
* into the tool result
|
|
1978
|
+
/** For `anthropic.tools.computerToolset_20260801(computer.aiSdk({ version: 7 }))`
|
|
1979
|
+
* (AI SDK 7 only), or `computer_20251124` with the legacy kind (AI SDK 6
|
|
1980
|
+
* and 7): `execute` runs one action and returns `{ type: "image", data }` or
|
|
1981
|
+
* text; `toModelOutput` turns that into the tool result in the part shape
|
|
1982
|
+
* of `options.version`. Calls run one at a time, and once a call fails the
|
|
1937
1983
|
* rest of that step's calls answer as not executed. */
|
|
1938
|
-
aiSdk() {
|
|
1984
|
+
aiSdk(options = {}) {
|
|
1985
|
+
const imagePart = _AnthropicComputer.imagePart(options);
|
|
1939
1986
|
let failedStep;
|
|
1940
|
-
const execute = (input,
|
|
1941
|
-
const step =
|
|
1987
|
+
const execute = (input, options2) => this.serial(async () => {
|
|
1988
|
+
const step = options2?.messages?.length;
|
|
1942
1989
|
if (step !== void 0 && step === failedStep)
|
|
1943
1990
|
throw new Error(NOT_EXECUTED);
|
|
1944
1991
|
try {
|
|
@@ -1950,7 +1997,7 @@ var init_anthropic = __esm({
|
|
|
1950
1997
|
});
|
|
1951
1998
|
return {
|
|
1952
1999
|
execute,
|
|
1953
|
-
toModelOutput: ({ output }) => _AnthropicComputer.
|
|
2000
|
+
toModelOutput: ({ output }) => _AnthropicComputer.modelOutput(output, imagePart)
|
|
1954
2001
|
};
|
|
1955
2002
|
}
|
|
1956
2003
|
static aiSdkOutput(result) {
|
|
@@ -1958,16 +2005,26 @@ var init_anthropic = __esm({
|
|
|
1958
2005
|
return { type: "image", data: result.image.toString("base64") };
|
|
1959
2006
|
return result.text ?? "OK";
|
|
1960
2007
|
}
|
|
1961
|
-
/**
|
|
1962
|
-
*
|
|
1963
|
-
|
|
2008
|
+
/** A screenshot as the image part of AI SDK `options.version`:
|
|
2009
|
+
* `image-data` for 6 (the default), `file` with `{ type: "data", data }`
|
|
2010
|
+
* for 7. */
|
|
2011
|
+
static aiSdkModelOutput(output, options = {}) {
|
|
2012
|
+
return _AnthropicComputer.modelOutput(
|
|
2013
|
+
output,
|
|
2014
|
+
_AnthropicComputer.imagePart(options)
|
|
2015
|
+
);
|
|
2016
|
+
}
|
|
2017
|
+
static imagePart({
|
|
2018
|
+
version = 6
|
|
2019
|
+
}) {
|
|
2020
|
+
if (Object.hasOwn(IMAGE_PARTS, version)) return IMAGE_PARTS[version];
|
|
2021
|
+
throw new Error(
|
|
2022
|
+
`unsupported AI SDK version ${version}; choose ${Object.keys(IMAGE_PARTS).join(" or ")}`
|
|
2023
|
+
);
|
|
2024
|
+
}
|
|
2025
|
+
static modelOutput(output, imagePart) {
|
|
1964
2026
|
if (typeof output === "string") return { type: "text", value: output };
|
|
1965
|
-
return {
|
|
1966
|
-
type: "content",
|
|
1967
|
-
value: [
|
|
1968
|
-
{ type: "image-data", data: output.data, mediaType: "image/png" }
|
|
1969
|
-
]
|
|
1970
|
-
};
|
|
2027
|
+
return { type: "content", value: [imagePart(output.data)] };
|
|
1971
2028
|
}
|
|
1972
2029
|
envelope(block, content, isError = false) {
|
|
1973
2030
|
return {
|
|
@@ -2257,13 +2314,16 @@ function idleWarning(idleExpiresAt, now = /* @__PURE__ */ new Date()) {
|
|
|
2257
2314
|
const minutes = Math.max(0, Math.floor(leftMs / 6e4));
|
|
2258
2315
|
return `warning: session expires in ${minutes}m (idle TTL); call a tool to extend it or \`gateway worlds session pin\` to keep it`;
|
|
2259
2316
|
}
|
|
2260
|
-
var CALL_BODY_LIMIT_BYTES, CALL_BODY_LIMIT_LABEL, IDLE_WARNING_MINUTES, EXPLORATORY_TASK, EXPLORATORY_TASK_SOURCE, NO_GRADER_REASON, WorldCallTooLarge, stillStartingHint;
|
|
2317
|
+
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;
|
|
2261
2318
|
var init_sessionContract = __esm({
|
|
2262
2319
|
"src/worlds/sessionContract.ts"() {
|
|
2263
2320
|
"use strict";
|
|
2264
2321
|
CALL_BODY_LIMIT_BYTES = 4 * 1024 * 1024;
|
|
2265
2322
|
CALL_BODY_LIMIT_LABEL = "4mb";
|
|
2266
2323
|
IDLE_WARNING_MINUTES = 5;
|
|
2324
|
+
REQUEST_LOG_PAGE_MAX = 200;
|
|
2325
|
+
REQUEST_BODY_CAPTURE_BYTES = 64 * 1024;
|
|
2326
|
+
REQUESTS_NOT_RECORDED = "requests_not_recorded";
|
|
2267
2327
|
EXPLORATORY_TASK = Object.freeze({
|
|
2268
2328
|
instruction: "exploratory session"
|
|
2269
2329
|
});
|
|
@@ -2297,6 +2357,217 @@ var init_sessionContract = __esm({
|
|
|
2297
2357
|
}
|
|
2298
2358
|
});
|
|
2299
2359
|
|
|
2360
|
+
// src/worlds/toolSchema.ts
|
|
2361
|
+
function schemaFromSignature(spec) {
|
|
2362
|
+
if (spec.inputSchema)
|
|
2363
|
+
return {
|
|
2364
|
+
type: "function",
|
|
2365
|
+
function: {
|
|
2366
|
+
name: modelToolName(spec.name),
|
|
2367
|
+
description: spec.doc ?? spec.name,
|
|
2368
|
+
parameters: spec.inputSchema
|
|
2369
|
+
}
|
|
2370
|
+
};
|
|
2371
|
+
const inside = /\(([\s\S]*)\)\s*$/.exec(spec.signature.trim())?.[1] ?? "";
|
|
2372
|
+
const properties = {};
|
|
2373
|
+
const required2 = [];
|
|
2374
|
+
const params = [];
|
|
2375
|
+
let depth = 0;
|
|
2376
|
+
let current = "";
|
|
2377
|
+
for (const ch of inside) {
|
|
2378
|
+
if ("([{".includes(ch)) depth++;
|
|
2379
|
+
if (")]}".includes(ch)) depth--;
|
|
2380
|
+
if (ch === "," && depth === 0) {
|
|
2381
|
+
params.push(current);
|
|
2382
|
+
current = "";
|
|
2383
|
+
} else current += ch;
|
|
2384
|
+
}
|
|
2385
|
+
if (current.trim()) params.push(current);
|
|
2386
|
+
for (const raw of params) {
|
|
2387
|
+
const param = raw.trim();
|
|
2388
|
+
if (!param || param.startsWith("*") || param === "self") continue;
|
|
2389
|
+
const eq = param.indexOf("=");
|
|
2390
|
+
const name = (eq === -1 ? param : param.slice(0, eq)).split(":")[0].trim();
|
|
2391
|
+
if (!name) continue;
|
|
2392
|
+
if (eq === -1) {
|
|
2393
|
+
properties[name] = { type: "string" };
|
|
2394
|
+
required2.push(name);
|
|
2395
|
+
continue;
|
|
2396
|
+
}
|
|
2397
|
+
const value = param.slice(eq + 1).trim();
|
|
2398
|
+
if (/^-?\d+(\.\d+)?$/.test(value)) properties[name] = { type: "number" };
|
|
2399
|
+
else if (value === "True" || value === "False")
|
|
2400
|
+
properties[name] = { type: "boolean" };
|
|
2401
|
+
else properties[name] = { type: "string" };
|
|
2402
|
+
}
|
|
2403
|
+
return {
|
|
2404
|
+
type: "function",
|
|
2405
|
+
function: {
|
|
2406
|
+
name: modelToolName(spec.name),
|
|
2407
|
+
description: spec.doc ?? spec.name,
|
|
2408
|
+
parameters: { type: "object", properties, required: required2 }
|
|
2409
|
+
}
|
|
2410
|
+
};
|
|
2411
|
+
}
|
|
2412
|
+
var modelToolName;
|
|
2413
|
+
var init_toolSchema = __esm({
|
|
2414
|
+
"src/worlds/toolSchema.ts"() {
|
|
2415
|
+
"use strict";
|
|
2416
|
+
modelToolName = (name) => name.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 64) || "tool";
|
|
2417
|
+
}
|
|
2418
|
+
});
|
|
2419
|
+
|
|
2420
|
+
// src/worlds/requestLedger.ts
|
|
2421
|
+
function platformMessage(text2) {
|
|
2422
|
+
try {
|
|
2423
|
+
const { message } = JSON.parse(text2);
|
|
2424
|
+
return typeof message === "string" ? message : null;
|
|
2425
|
+
} catch {
|
|
2426
|
+
return null;
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
var WORLD_REQUEST_VIAS, WorldRequestFilterError, NOT_RECORDED, WorldRequestsNotRecorded, STATUS, INSTANT, WORLDS, SESSIONS, Instant, WorldRequestQuery, WorldRequestLedger;
|
|
2430
|
+
var init_requestLedger = __esm({
|
|
2431
|
+
"src/worlds/requestLedger.ts"() {
|
|
2432
|
+
"use strict";
|
|
2433
|
+
init_worlds();
|
|
2434
|
+
init_sessionContract();
|
|
2435
|
+
WORLD_REQUEST_VIAS = ["api", "ui", "tool", "webhook"];
|
|
2436
|
+
WorldRequestFilterError = class extends Error {
|
|
2437
|
+
};
|
|
2438
|
+
NOT_RECORDED = "This session's engine records no requests; only hosted World Host sessions do.";
|
|
2439
|
+
WorldRequestsNotRecorded = class _WorldRequestsNotRecorded extends Error {
|
|
2440
|
+
static from(error) {
|
|
2441
|
+
if (!(error instanceof ApiError) || error.code !== REQUESTS_NOT_RECORDED) return error;
|
|
2442
|
+
return new _WorldRequestsNotRecorded(platformMessage(error.text) || NOT_RECORDED);
|
|
2443
|
+
}
|
|
2444
|
+
static async mapped(read) {
|
|
2445
|
+
try {
|
|
2446
|
+
return await read;
|
|
2447
|
+
} catch (error) {
|
|
2448
|
+
throw _WorldRequestsNotRecorded.from(error);
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2451
|
+
};
|
|
2452
|
+
STATUS = /^(?:[1-5]\d\d|[1-5]xx)$/;
|
|
2453
|
+
INSTANT = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
2454
|
+
WORLDS = "/api/public/worlds";
|
|
2455
|
+
SESSIONS = "/api/public/world-sessions";
|
|
2456
|
+
Instant = class _Instant {
|
|
2457
|
+
static parse(flag, raw) {
|
|
2458
|
+
const match = INSTANT.exec(raw);
|
|
2459
|
+
const millis = match ? _Instant.fromParts(match) : null;
|
|
2460
|
+
if (millis === null)
|
|
2461
|
+
throw new WorldRequestFilterError(
|
|
2462
|
+
`--${flag} must be an ISO 8601 date or time (2026-10-05, 2026-10-05T14:30:00Z), not \`${raw}\`.`
|
|
2463
|
+
);
|
|
2464
|
+
return millis;
|
|
2465
|
+
}
|
|
2466
|
+
static fromParts(match) {
|
|
2467
|
+
const [year, month, day, hour, minute, second] = [1, 2, 3, 4, 5, 6].map((i) => Number(match[i] ?? 0));
|
|
2468
|
+
const offset = _Instant.offsetMinutes(match[8]);
|
|
2469
|
+
if (offset === null || year < 1 || hour > 23 || minute > 59 || second > 59) return null;
|
|
2470
|
+
const date = /* @__PURE__ */ new Date(0);
|
|
2471
|
+
date.setUTCFullYear(year, month - 1, day);
|
|
2472
|
+
if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month - 1 || date.getUTCDate() !== day) return null;
|
|
2473
|
+
date.setUTCHours(hour, minute, second, Number((match[7] ?? "").padEnd(3, "0")));
|
|
2474
|
+
const utc = date.getTime() - offset * 6e4;
|
|
2475
|
+
const utcYear = new Date(utc).getUTCFullYear();
|
|
2476
|
+
return utcYear < 1 || utcYear > 9999 ? null : utc;
|
|
2477
|
+
}
|
|
2478
|
+
static offsetMinutes(zone) {
|
|
2479
|
+
if (zone === void 0 || zone === "Z") return 0;
|
|
2480
|
+
const hours = Number(zone.slice(1, 3));
|
|
2481
|
+
const minutes = Number(zone.slice(4, 6));
|
|
2482
|
+
if (hours > 23 || minutes > 59) return null;
|
|
2483
|
+
return (zone.startsWith("-") ? -1 : 1) * (hours * 60 + minutes);
|
|
2484
|
+
}
|
|
2485
|
+
};
|
|
2486
|
+
WorldRequestQuery = class _WorldRequestQuery {
|
|
2487
|
+
constructor(entries) {
|
|
2488
|
+
this.entries = entries;
|
|
2489
|
+
}
|
|
2490
|
+
entries;
|
|
2491
|
+
static parse(filter = {}) {
|
|
2492
|
+
const via = _WorldRequestQuery.via(filter.via);
|
|
2493
|
+
const status = _WorldRequestQuery.status(filter.status);
|
|
2494
|
+
const since = filter.since === void 0 ? void 0 : Instant.parse("since", filter.since);
|
|
2495
|
+
const until = filter.until === void 0 ? void 0 : Instant.parse("until", filter.until);
|
|
2496
|
+
if (since !== void 0 && until !== void 0 && since > until)
|
|
2497
|
+
throw new WorldRequestFilterError("--since must not be after --until.");
|
|
2498
|
+
const values = [
|
|
2499
|
+
["session", filter.session],
|
|
2500
|
+
["version", filter.version],
|
|
2501
|
+
["via", via],
|
|
2502
|
+
["operation", filter.operation],
|
|
2503
|
+
["status", status],
|
|
2504
|
+
["since", since === void 0 ? void 0 : new Date(since).toISOString()],
|
|
2505
|
+
["until", until === void 0 ? void 0 : new Date(until).toISOString()],
|
|
2506
|
+
["limit", filter.limit === void 0 ? void 0 : String(filter.limit)],
|
|
2507
|
+
["cursor", filter.cursor]
|
|
2508
|
+
];
|
|
2509
|
+
return new _WorldRequestQuery(values.filter((entry) => entry[1] !== void 0));
|
|
2510
|
+
}
|
|
2511
|
+
static via(value) {
|
|
2512
|
+
if (value === void 0) return void 0;
|
|
2513
|
+
const lower = value.toLowerCase();
|
|
2514
|
+
if (WORLD_REQUEST_VIAS.includes(lower)) return lower;
|
|
2515
|
+
throw new WorldRequestFilterError(`--via must be one of ${WORLD_REQUEST_VIAS.join(", ")}, not \`${value}\`.`);
|
|
2516
|
+
}
|
|
2517
|
+
static status(value) {
|
|
2518
|
+
if (value === void 0) return void 0;
|
|
2519
|
+
const lower = value.toLowerCase();
|
|
2520
|
+
if (STATUS.test(lower)) return lower;
|
|
2521
|
+
throw new WorldRequestFilterError(`--status must be a code (200) or a class (2xx), not \`${value}\`.`);
|
|
2522
|
+
}
|
|
2523
|
+
get filtered() {
|
|
2524
|
+
return this.entries.some(([key]) => key !== "limit");
|
|
2525
|
+
}
|
|
2526
|
+
params() {
|
|
2527
|
+
return this.entries.map(([key, value]) => [key, value]);
|
|
2528
|
+
}
|
|
2529
|
+
search() {
|
|
2530
|
+
return this.entries.length ? `?${new URLSearchParams(this.entries).toString()}` : "";
|
|
2531
|
+
}
|
|
2532
|
+
};
|
|
2533
|
+
WorldRequestLedger = class {
|
|
2534
|
+
constructor(options = {}) {
|
|
2535
|
+
this.options = options;
|
|
2536
|
+
}
|
|
2537
|
+
options;
|
|
2538
|
+
/** A page of the world's requests, newest first; `nextCursor` reads the page after it. Narrowed to a session
|
|
2539
|
+
* whose engine records none: `WorldRequestsNotRecorded`. */
|
|
2540
|
+
list(slug, query = WorldRequestQuery.parse()) {
|
|
2541
|
+
return WorldRequestsNotRecorded.mapped(
|
|
2542
|
+
apiRequest(
|
|
2543
|
+
this.options,
|
|
2544
|
+
"GET",
|
|
2545
|
+
`${WORLDS}/${encodeURIComponent(slug)}/requests${query.search()}`
|
|
2546
|
+
)
|
|
2547
|
+
);
|
|
2548
|
+
}
|
|
2549
|
+
/** One of the world's requests, with its headers and bodies. */
|
|
2550
|
+
get(slug, requestId) {
|
|
2551
|
+
return apiRequest(
|
|
2552
|
+
this.options,
|
|
2553
|
+
"GET",
|
|
2554
|
+
`${WORLDS}/${encodeURIComponent(slug)}/requests/${encodeURIComponent(requestId)}`
|
|
2555
|
+
);
|
|
2556
|
+
}
|
|
2557
|
+
/** A page of one session's requests, newest first; `WorldRequestsNotRecorded` when its engine records none. */
|
|
2558
|
+
forSession(sessionId, query = WorldRequestQuery.parse()) {
|
|
2559
|
+
return WorldRequestsNotRecorded.mapped(
|
|
2560
|
+
apiRequest(
|
|
2561
|
+
this.options,
|
|
2562
|
+
"GET",
|
|
2563
|
+
`${SESSIONS}/${encodeURIComponent(sessionId)}/requests${query.search()}`
|
|
2564
|
+
)
|
|
2565
|
+
);
|
|
2566
|
+
}
|
|
2567
|
+
};
|
|
2568
|
+
}
|
|
2569
|
+
});
|
|
2570
|
+
|
|
2300
2571
|
// src/worlds/sessionReadiness.ts
|
|
2301
2572
|
var READY_TIMEOUT_MS, READY_POLL_MS, sleep2, WorldSessionTimeout, WorldSessionCallError, WorldSessionOpenFailed, ENDED, SessionReadiness;
|
|
2302
2573
|
var init_sessionReadiness = __esm({
|
|
@@ -2635,57 +2906,6 @@ __export(session_exports2, {
|
|
|
2635
2906
|
schemaFromSignature: () => schemaFromSignature,
|
|
2636
2907
|
taskLabel: () => taskLabel
|
|
2637
2908
|
});
|
|
2638
|
-
function schemaFromSignature(spec) {
|
|
2639
|
-
if (spec.inputSchema)
|
|
2640
|
-
return {
|
|
2641
|
-
type: "function",
|
|
2642
|
-
function: {
|
|
2643
|
-
name: modelToolName(spec.name),
|
|
2644
|
-
description: spec.doc ?? spec.name,
|
|
2645
|
-
parameters: spec.inputSchema
|
|
2646
|
-
}
|
|
2647
|
-
};
|
|
2648
|
-
const inside = /\(([\s\S]*)\)\s*$/.exec(spec.signature.trim())?.[1] ?? "";
|
|
2649
|
-
const properties = {};
|
|
2650
|
-
const required2 = [];
|
|
2651
|
-
const params = [];
|
|
2652
|
-
let depth = 0;
|
|
2653
|
-
let current = "";
|
|
2654
|
-
for (const ch of inside) {
|
|
2655
|
-
if ("([{".includes(ch)) depth++;
|
|
2656
|
-
if (")]}".includes(ch)) depth--;
|
|
2657
|
-
if (ch === "," && depth === 0) {
|
|
2658
|
-
params.push(current);
|
|
2659
|
-
current = "";
|
|
2660
|
-
} else current += ch;
|
|
2661
|
-
}
|
|
2662
|
-
if (current.trim()) params.push(current);
|
|
2663
|
-
for (const raw of params) {
|
|
2664
|
-
const param = raw.trim();
|
|
2665
|
-
if (!param || param.startsWith("*") || param === "self") continue;
|
|
2666
|
-
const eq = param.indexOf("=");
|
|
2667
|
-
const name = (eq === -1 ? param : param.slice(0, eq)).split(":")[0].trim();
|
|
2668
|
-
if (!name) continue;
|
|
2669
|
-
if (eq === -1) {
|
|
2670
|
-
properties[name] = { type: "string" };
|
|
2671
|
-
required2.push(name);
|
|
2672
|
-
continue;
|
|
2673
|
-
}
|
|
2674
|
-
const value = param.slice(eq + 1).trim();
|
|
2675
|
-
if (/^-?\d+(\.\d+)?$/.test(value)) properties[name] = { type: "number" };
|
|
2676
|
-
else if (value === "True" || value === "False")
|
|
2677
|
-
properties[name] = { type: "boolean" };
|
|
2678
|
-
else properties[name] = { type: "string" };
|
|
2679
|
-
}
|
|
2680
|
-
return {
|
|
2681
|
-
type: "function",
|
|
2682
|
-
function: {
|
|
2683
|
-
name: modelToolName(spec.name),
|
|
2684
|
-
description: spec.doc ?? spec.name,
|
|
2685
|
-
parameters: { type: "object", properties, required: required2 }
|
|
2686
|
-
}
|
|
2687
|
-
};
|
|
2688
|
-
}
|
|
2689
2909
|
async function attachSession(sessionId, options = {}) {
|
|
2690
2910
|
const state2 = await apiRequest(
|
|
2691
2911
|
options,
|
|
@@ -2706,6 +2926,7 @@ async function openSession(slugOrRef, taskOrOpts = {}, positionalOpts = {}) {
|
|
|
2706
2926
|
`Unknown world surfaces: ${unknown.join(", ")}; choose from ${SURFACE_KINDS.join(", ")}`
|
|
2707
2927
|
);
|
|
2708
2928
|
if (opts.browserTier !== void 0) assertBrowserTier(opts.browserTier);
|
|
2929
|
+
if (opts.auth !== void 0) assertSessionAuthMode(opts.auth);
|
|
2709
2930
|
const at = slugOrRef.indexOf("@");
|
|
2710
2931
|
const slug = at === -1 ? slugOrRef : slugOrRef.slice(0, at);
|
|
2711
2932
|
const ref = at === -1 ? "" : slugOrRef.slice(at + 1);
|
|
@@ -2718,7 +2939,8 @@ async function openSession(slugOrRef, taskOrOpts = {}, positionalOpts = {}) {
|
|
|
2718
2939
|
...task === void 0 ? {} : { task },
|
|
2719
2940
|
...opts.reuseWarm === void 0 ? {} : { reuseWarm: opts.reuseWarm },
|
|
2720
2941
|
...opts.surfaces?.length ? { surfaces: opts.surfaces } : {},
|
|
2721
|
-
...opts.browserTier === void 0 ? {} : { browserTier: opts.browserTier }
|
|
2942
|
+
...opts.browserTier === void 0 ? {} : { browserTier: opts.browserTier },
|
|
2943
|
+
...opts.auth === void 0 ? {} : { auth: opts.auth }
|
|
2722
2944
|
}
|
|
2723
2945
|
);
|
|
2724
2946
|
return new WorldSession(state2.sessionId, state2, options);
|
|
@@ -2799,7 +3021,7 @@ async function runSessions(opts) {
|
|
|
2799
3021
|
passed: failed === 0 && (opts.failUnder === void 0 || mean >= opts.failUnder)
|
|
2800
3022
|
};
|
|
2801
3023
|
}
|
|
2802
|
-
var import_node_crypto2, CALL_TIMEOUT_MS, CALL_POLL_MS, JUDGED_GRADE_TIMEOUT_MS, JUDGED_GRADE_POLL_MS, EXPORT_PAGE, sleep3,
|
|
3024
|
+
var import_node_crypto2, CALL_TIMEOUT_MS, CALL_POLL_MS, JUDGED_GRADE_TIMEOUT_MS, JUDGED_GRADE_POLL_MS, EXPORT_PAGE, sleep3, WorldSession, OPEN_SESSION_OPTION_KEYS, isOpenSessionOptions;
|
|
2803
3025
|
var init_session2 = __esm({
|
|
2804
3026
|
"src/worlds/session.ts"() {
|
|
2805
3027
|
"use strict";
|
|
@@ -2808,6 +3030,8 @@ var init_session2 = __esm({
|
|
|
2808
3030
|
init_browser();
|
|
2809
3031
|
init_nativeComputer();
|
|
2810
3032
|
init_sessionContract();
|
|
3033
|
+
init_toolSchema();
|
|
3034
|
+
init_requestLedger();
|
|
2811
3035
|
init_sessionReadiness();
|
|
2812
3036
|
init_session();
|
|
2813
3037
|
init_taskRef();
|
|
@@ -2821,7 +3045,6 @@ var init_session2 = __esm({
|
|
|
2821
3045
|
JUDGED_GRADE_POLL_MS = 2e3;
|
|
2822
3046
|
EXPORT_PAGE = 500;
|
|
2823
3047
|
sleep3 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
2824
|
-
modelToolName = (name) => name.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 64) || "tool";
|
|
2825
3048
|
WorldSession = class {
|
|
2826
3049
|
constructor(sessionId, current, options) {
|
|
2827
3050
|
this.sessionId = sessionId;
|
|
@@ -2891,12 +3114,12 @@ var init_session2 = __esm({
|
|
|
2891
3114
|
);
|
|
2892
3115
|
return api2.url;
|
|
2893
3116
|
}
|
|
2894
|
-
/** Headers every request to `api()` needs
|
|
2895
|
-
*
|
|
2896
|
-
* world's own declared auth
|
|
3117
|
+
/** Headers every request to `api()` needs: a World Host session's token in the
|
|
3118
|
+
* platform's `X-World-Session` header, which every world takes; `{}` for a pod
|
|
3119
|
+
* or hosted twin, which answers with the world's own declared auth. */
|
|
2897
3120
|
async apiHeaders() {
|
|
2898
3121
|
const { api: api2 } = await this.surfaces();
|
|
2899
|
-
return api2?.token ? {
|
|
3122
|
+
return api2?.token ? { [PLATFORM_SESSION_HEADER]: api2.token } : {};
|
|
2900
3123
|
}
|
|
2901
3124
|
/** URL of the world's UI entry page for this session. */
|
|
2902
3125
|
async ui() {
|
|
@@ -2967,11 +3190,28 @@ var init_session2 = __esm({
|
|
|
2967
3190
|
}
|
|
2968
3191
|
/** The session's latest platform state (one request, no waiting). */
|
|
2969
3192
|
async status() {
|
|
3193
|
+
return this.refresh(
|
|
3194
|
+
await apiRequest(
|
|
3195
|
+
this.options,
|
|
3196
|
+
"GET",
|
|
3197
|
+
`/api/public/world-sessions/${encodeURIComponent(this.sessionId)}`
|
|
3198
|
+
)
|
|
3199
|
+
);
|
|
3200
|
+
}
|
|
3201
|
+
/** The world started over under the same id, URLs and token, on what its pin (or `version`, which becomes
|
|
3202
|
+
* its pin) resolves to now: base data plus the task's seed. A grade then reads only the new world's requests. */
|
|
3203
|
+
async restart(opts = {}) {
|
|
2970
3204
|
const fresh = await apiRequest(
|
|
2971
3205
|
this.options,
|
|
2972
|
-
"
|
|
2973
|
-
`/api/public/world-sessions/${encodeURIComponent(this.sessionId)}
|
|
3206
|
+
"POST",
|
|
3207
|
+
`/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/restart`,
|
|
3208
|
+
opts.version ? { version: opts.version } : {}
|
|
2974
3209
|
);
|
|
3210
|
+
this.refresh(fresh);
|
|
3211
|
+
return fresh;
|
|
3212
|
+
}
|
|
3213
|
+
// A status read carries neither the objective nor the open's notices; keep the ones we opened with.
|
|
3214
|
+
refresh(fresh) {
|
|
2975
3215
|
this.current = {
|
|
2976
3216
|
instruction: this.current.instruction,
|
|
2977
3217
|
tools: this.current.tools,
|
|
@@ -3006,7 +3246,7 @@ var init_session2 = __esm({
|
|
|
3006
3246
|
const { callId } = enqueued;
|
|
3007
3247
|
const judged = enqueued.pending === true;
|
|
3008
3248
|
const budgetMs = timeoutMs ?? (judged ? JUDGED_GRADE_TIMEOUT_MS : CALL_TIMEOUT_MS);
|
|
3009
|
-
const
|
|
3249
|
+
const pollMs = judged ? JUDGED_GRADE_POLL_MS : CALL_POLL_MS;
|
|
3010
3250
|
const deadline = Date.now() + budgetMs;
|
|
3011
3251
|
for (; ; ) {
|
|
3012
3252
|
const call = await apiRequest(
|
|
@@ -3022,7 +3262,7 @@ var init_session2 = __esm({
|
|
|
3022
3262
|
throw new WorldSessionTimeout(
|
|
3023
3263
|
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.`
|
|
3024
3264
|
);
|
|
3025
|
-
await sleep3(
|
|
3265
|
+
await sleep3(pollMs);
|
|
3026
3266
|
}
|
|
3027
3267
|
}
|
|
3028
3268
|
/**
|
|
@@ -3115,19 +3355,31 @@ var init_session2 = __esm({
|
|
|
3115
3355
|
async reset(opts = {}) {
|
|
3116
3356
|
await this.exchange({ kind: "reset" }, opts.timeoutMs);
|
|
3117
3357
|
}
|
|
3358
|
+
/** One page of the session's entries in its world's request ledger, newest
|
|
3359
|
+
* first and without bodies: at most `limit` after `cursor` (the last page's
|
|
3360
|
+
* `nextCursor`). Reading it records nothing in the session. */
|
|
3361
|
+
async requests(opts = {}) {
|
|
3362
|
+
return new WorldRequestLedger(this.options).forSession(
|
|
3363
|
+
this.sessionId,
|
|
3364
|
+
WorldRequestQuery.parse({ cursor: opts.cursor, limit: opts.limit ?? REQUEST_LOG_PAGE_MAX })
|
|
3365
|
+
);
|
|
3366
|
+
}
|
|
3367
|
+
page(route2, limit, cursor) {
|
|
3368
|
+
const query = new URLSearchParams({ limit: String(limit) });
|
|
3369
|
+
if (cursor) query.set("cursor", cursor);
|
|
3370
|
+
return apiRequest(
|
|
3371
|
+
this.options,
|
|
3372
|
+
"GET",
|
|
3373
|
+
`/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/${route2}?${query.toString()}`
|
|
3374
|
+
);
|
|
3375
|
+
}
|
|
3118
3376
|
/** The session's call log, oldest first: every tool call, seed, reset,
|
|
3119
3377
|
* grade with its result — the record of the episode. */
|
|
3120
3378
|
async export() {
|
|
3121
3379
|
const calls = [];
|
|
3122
3380
|
let cursor;
|
|
3123
3381
|
do {
|
|
3124
|
-
const
|
|
3125
|
-
if (cursor) params.set("cursor", cursor);
|
|
3126
|
-
const page = await apiRequest(
|
|
3127
|
-
this.options,
|
|
3128
|
-
"GET",
|
|
3129
|
-
`/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/calls?${params.toString()}`
|
|
3130
|
-
);
|
|
3382
|
+
const page = await this.page("calls", EXPORT_PAGE, cursor);
|
|
3131
3383
|
for (const call of page.calls) {
|
|
3132
3384
|
calls.push({
|
|
3133
3385
|
seq: Number(call.seq),
|
|
@@ -3209,6 +3461,7 @@ var init_session2 = __esm({
|
|
|
3209
3461
|
"reuseWarm",
|
|
3210
3462
|
"surfaces",
|
|
3211
3463
|
"browserTier",
|
|
3464
|
+
"auth",
|
|
3212
3465
|
"options"
|
|
3213
3466
|
]);
|
|
3214
3467
|
isOpenSessionOptions = (value) => typeof value === "object" && value !== null && Object.keys(value).every((key) => OPEN_SESSION_OPTION_KEYS.has(key));
|
|
@@ -3323,11 +3576,50 @@ var init_tasks = __esm({
|
|
|
3323
3576
|
}
|
|
3324
3577
|
});
|
|
3325
3578
|
|
|
3579
|
+
// src/worlds/taskGrades.ts
|
|
3580
|
+
var TASKS2, compact2, TaskGrades;
|
|
3581
|
+
var init_taskGrades = __esm({
|
|
3582
|
+
"src/worlds/taskGrades.ts"() {
|
|
3583
|
+
"use strict";
|
|
3584
|
+
init_worlds();
|
|
3585
|
+
TASKS2 = "/api/public/world-tasks";
|
|
3586
|
+
compact2 = (body) => Object.fromEntries(Object.entries(body).filter(([, v]) => v !== void 0));
|
|
3587
|
+
TaskGrades = class {
|
|
3588
|
+
constructor(options = {}) {
|
|
3589
|
+
this.options = options;
|
|
3590
|
+
}
|
|
3591
|
+
options;
|
|
3592
|
+
try(sessionId, target) {
|
|
3593
|
+
return apiRequest(
|
|
3594
|
+
this.options,
|
|
3595
|
+
"POST",
|
|
3596
|
+
`${TASKS2}/try`,
|
|
3597
|
+
compact2({ sessionId, ...target })
|
|
3598
|
+
);
|
|
3599
|
+
}
|
|
3600
|
+
regrade(taskId, scope = {}) {
|
|
3601
|
+
return apiRequest(
|
|
3602
|
+
this.options,
|
|
3603
|
+
"POST",
|
|
3604
|
+
`${TASKS2}/${encodeURIComponent(taskId)}/regrade`,
|
|
3605
|
+
compact2({ ...scope })
|
|
3606
|
+
);
|
|
3607
|
+
}
|
|
3608
|
+
};
|
|
3609
|
+
}
|
|
3610
|
+
});
|
|
3611
|
+
|
|
3326
3612
|
// src/worlds/surfaceDescriptor.ts
|
|
3327
3613
|
function surfaceDescriptor(s) {
|
|
3328
3614
|
return {
|
|
3329
3615
|
surfaces: surfaceKinds(s),
|
|
3330
|
-
...s.api ? {
|
|
3616
|
+
...s.api ? {
|
|
3617
|
+
api: {
|
|
3618
|
+
url: s.api.url,
|
|
3619
|
+
...s.api.token ? { token: s.api.token } : {},
|
|
3620
|
+
...s.api.auth ? { auth: s.api.auth } : {}
|
|
3621
|
+
}
|
|
3622
|
+
} : {},
|
|
3331
3623
|
...s.ui ? { ui: { url: s.ui.url, entry: uiEntryUrl(s.ui), apiPath: s.ui.apiPath ?? null } } : {},
|
|
3332
3624
|
...s.browser ? {
|
|
3333
3625
|
browser: {
|
|
@@ -3377,8 +3669,7 @@ function fromResponse(answer, options) {
|
|
|
3377
3669
|
sessions[alias] = new WorldSession(state2.sessionId, state2, options);
|
|
3378
3670
|
worlds[alias] = {
|
|
3379
3671
|
slug: state2.slug,
|
|
3380
|
-
ref: state2.ref
|
|
3381
|
-
private: state2.private ?? null
|
|
3672
|
+
ref: state2.ref
|
|
3382
3673
|
};
|
|
3383
3674
|
}
|
|
3384
3675
|
return new TaskSessions(
|
|
@@ -3453,7 +3744,6 @@ async function attachTask(taskId, options = {}) {
|
|
|
3453
3744
|
{
|
|
3454
3745
|
slug: row.slug ?? "",
|
|
3455
3746
|
ref: null,
|
|
3456
|
-
private: null,
|
|
3457
3747
|
versionId: row.versionId,
|
|
3458
3748
|
sessionId: row.sessionId,
|
|
3459
3749
|
ready: row.ready,
|
|
@@ -3483,7 +3773,7 @@ async function attachManifest(manifest, options = {}) {
|
|
|
3483
3773
|
Object.fromEntries(
|
|
3484
3774
|
Object.entries(manifest.sessions).map(([alias, entry]) => [
|
|
3485
3775
|
alias,
|
|
3486
|
-
{ slug: entry.slug, ref: entry.ref
|
|
3776
|
+
{ slug: entry.slug, ref: entry.ref }
|
|
3487
3777
|
])
|
|
3488
3778
|
)
|
|
3489
3779
|
);
|
|
@@ -3505,7 +3795,6 @@ var init_taskSessions = __esm({
|
|
|
3505
3795
|
manifestSession = (s, state2, world) => ({
|
|
3506
3796
|
slug: world.slug,
|
|
3507
3797
|
ref: world.ref,
|
|
3508
|
-
private: world.private,
|
|
3509
3798
|
versionId: state2.versionId,
|
|
3510
3799
|
sessionId: state2.sessionId,
|
|
3511
3800
|
ready: state2.ready,
|
|
@@ -3562,7 +3851,7 @@ var init_taskSessions = __esm({
|
|
|
3562
3851
|
/** This alias's world as recorded at open/attach — what a `TaskRun`
|
|
3563
3852
|
* filing needs to name, without exposing the whole map. */
|
|
3564
3853
|
worldRef(alias) {
|
|
3565
|
-
return this.worlds[alias] ?? { slug: "", ref: null
|
|
3854
|
+
return this.worlds[alias] ?? { slug: "", ref: null };
|
|
3566
3855
|
}
|
|
3567
3856
|
/** The aliases, in the spec's order. */
|
|
3568
3857
|
get aliases() {
|
|
@@ -3887,16 +4176,12 @@ var init_taskRunOutcome = __esm({
|
|
|
3887
4176
|
evaluationId;
|
|
3888
4177
|
evaluationStatus = null;
|
|
3889
4178
|
started = Date.now();
|
|
3890
|
-
/** The run stopped short of a grade; the first reason stands. */
|
|
3891
4179
|
stopped(error) {
|
|
3892
4180
|
this.runError ??= messageOf(error).slice(0, 2e3);
|
|
3893
4181
|
}
|
|
3894
4182
|
agentRaised(error) {
|
|
3895
4183
|
this.agentError = messageOf(error).slice(0, 2e3);
|
|
3896
4184
|
}
|
|
3897
|
-
/** Every reason the run failed, on one line: the evaluation's
|
|
3898
|
-
* `metrics.error`. A run that never reached a grade has failed whatever
|
|
3899
|
-
* its reasons say. */
|
|
3900
4185
|
failure() {
|
|
3901
4186
|
const reasons = [
|
|
3902
4187
|
this.agentError === null ? null : `agent raised: ${this.agentError}`,
|
|
@@ -3992,6 +4277,7 @@ var init_taskRunOutcome = __esm({
|
|
|
3992
4277
|
])
|
|
3993
4278
|
),
|
|
3994
4279
|
ungraded: this.grade?.ungraded ?? live.aliases,
|
|
4280
|
+
verifierVersion: live.taskVersion,
|
|
3995
4281
|
traced: this.traced,
|
|
3996
4282
|
runDir: this.runDir,
|
|
3997
4283
|
...this.agentError ? { agentError: this.agentError } : {},
|
|
@@ -4752,7 +5038,7 @@ var require_package = __commonJS({
|
|
|
4752
5038
|
"package.json"(exports2, module2) {
|
|
4753
5039
|
module2.exports = {
|
|
4754
5040
|
name: "@withgateway/sdk",
|
|
4755
|
-
version: "0.
|
|
5041
|
+
version: "0.6.0",
|
|
4756
5042
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
4757
5043
|
main: "./dist/index.js",
|
|
4758
5044
|
module: "./dist/index.mjs",
|
|
@@ -5944,51 +6230,195 @@ var init_setRun = __esm({
|
|
|
5944
6230
|
});
|
|
5945
6231
|
|
|
5946
6232
|
// src/worlds/requestLog.ts
|
|
5947
|
-
|
|
6233
|
+
function worldRequestsUnrecorded(counts) {
|
|
6234
|
+
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)));
|
|
6235
|
+
return parts.length > 0 ? `Not recorded: ${parts.join(", ")}` : null;
|
|
6236
|
+
}
|
|
6237
|
+
function counted(value) {
|
|
6238
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : 0;
|
|
6239
|
+
}
|
|
6240
|
+
var UNRECORDED, WorldRequestLog;
|
|
5948
6241
|
var init_requestLog = __esm({
|
|
5949
6242
|
"src/worlds/requestLog.ts"() {
|
|
5950
6243
|
"use strict";
|
|
6244
|
+
init_requestLedger();
|
|
6245
|
+
UNRECORDED = [
|
|
6246
|
+
["lost", "{n} request", "{n} requests"],
|
|
6247
|
+
["shed", "{n} request's headers and bodies", "{n} requests' headers and bodies"],
|
|
6248
|
+
["hostsLost", "the requests {n} lost host held", "the requests {n} lost hosts held"]
|
|
6249
|
+
];
|
|
5951
6250
|
WorldRequestLog = class _WorldRequestLog {
|
|
5952
|
-
constructor(requests) {
|
|
6251
|
+
constructor(requests, notRecorded = null, unrecorded = null) {
|
|
5953
6252
|
this.requests = requests;
|
|
6253
|
+
this.notRecorded = notRecorded;
|
|
6254
|
+
this.unrecorded = unrecorded;
|
|
5954
6255
|
}
|
|
5955
6256
|
requests;
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
|
|
5964
|
-
|
|
5965
|
-
|
|
5966
|
-
|
|
5967
|
-
|
|
5968
|
-
|
|
5969
|
-
|
|
6257
|
+
notRecorded;
|
|
6258
|
+
unrecorded;
|
|
6259
|
+
/** Every entry the ledger holds for the session, oldest first, and the line for what it did not record;
|
|
6260
|
+
* for a session the World Host did not serve, none, and `notRecorded` says why. */
|
|
6261
|
+
static async load(session) {
|
|
6262
|
+
try {
|
|
6263
|
+
return await _WorldRequestLog.pages(session);
|
|
6264
|
+
} catch (error) {
|
|
6265
|
+
const refused = WorldRequestsNotRecorded.from(error);
|
|
6266
|
+
if (!(refused instanceof WorldRequestsNotRecorded)) throw error;
|
|
6267
|
+
return new _WorldRequestLog([], refused.message);
|
|
6268
|
+
}
|
|
6269
|
+
}
|
|
6270
|
+
static async pages(session) {
|
|
6271
|
+
const requests = [];
|
|
6272
|
+
let cursor;
|
|
6273
|
+
for (; ; ) {
|
|
6274
|
+
const page = await session.requests(cursor ? { cursor } : {});
|
|
6275
|
+
requests.push(...page.requests);
|
|
6276
|
+
if (!page.nextCursor || page.requests.length === 0)
|
|
6277
|
+
return new _WorldRequestLog(requests.reverse(), null, worldRequestsUnrecorded(page));
|
|
6278
|
+
cursor = page.nextCursor;
|
|
6279
|
+
}
|
|
6280
|
+
}
|
|
6281
|
+
/** Each entry in the shape of a ledger line, `kind: "request"`, so one JSONL
|
|
6282
|
+
* file holds both: `args` what was asked, `result` what came back under the
|
|
6283
|
+
* entry's `requestId`. */
|
|
5970
6284
|
asCalls() {
|
|
5971
6285
|
return this.requests.map((r) => ({
|
|
5972
|
-
seq:
|
|
6286
|
+
seq: r.seq,
|
|
5973
6287
|
kind: "request",
|
|
5974
|
-
tool: r.operation
|
|
6288
|
+
tool: r.operation,
|
|
5975
6289
|
args: {
|
|
5976
|
-
method: r.method
|
|
5977
|
-
path: r.path
|
|
5978
|
-
|
|
5979
|
-
|
|
5980
|
-
|
|
5981
|
-
|
|
6290
|
+
method: r.method,
|
|
6291
|
+
path: r.path,
|
|
6292
|
+
query: r.query,
|
|
6293
|
+
via: r.via,
|
|
6294
|
+
contentType: r.request.contentType,
|
|
6295
|
+
bodyBytes: r.request.bodyBytes,
|
|
6296
|
+
truncated: r.request.truncated
|
|
6297
|
+
},
|
|
6298
|
+
result: {
|
|
6299
|
+
requestId: r.id,
|
|
6300
|
+
status: r.response.status,
|
|
6301
|
+
rows: r.rows,
|
|
6302
|
+
found: r.found,
|
|
6303
|
+
durationMs: r.durationMs,
|
|
6304
|
+
contentType: r.response.contentType,
|
|
6305
|
+
bodyBytes: r.response.bodyBytes,
|
|
6306
|
+
truncated: r.response.truncated
|
|
5982
6307
|
},
|
|
5983
|
-
result: { status: r.status ?? null, rows: r.rows ?? null, found: r.found ?? null },
|
|
5984
6308
|
error: null,
|
|
5985
|
-
completedAt: r.at
|
|
6309
|
+
completedAt: r.at
|
|
5986
6310
|
}));
|
|
5987
6311
|
}
|
|
5988
6312
|
};
|
|
5989
6313
|
}
|
|
5990
6314
|
});
|
|
5991
6315
|
|
|
6316
|
+
// src/worlds/webhooks.ts
|
|
6317
|
+
async function listWebhooks(options, sessionId, page = {}) {
|
|
6318
|
+
const query = new URLSearchParams({
|
|
6319
|
+
after: String(page.after ?? 0),
|
|
6320
|
+
limit: String(page.limit ?? WORLD_WEBHOOK_PAGE_MAX),
|
|
6321
|
+
tail: String(page.tail ?? false)
|
|
6322
|
+
});
|
|
6323
|
+
if (page.epoch) query.set("epoch", page.epoch);
|
|
6324
|
+
return apiRequest(options, "GET", `${route(sessionId)}?${query.toString()}`);
|
|
6325
|
+
}
|
|
6326
|
+
var WORLD_WEBHOOK_PAGE_MAX, FORWARD_TIMEOUT_MS, ERROR_CHARS, route, WorldWebhookForwarder;
|
|
6327
|
+
var init_webhooks = __esm({
|
|
6328
|
+
"src/worlds/webhooks.ts"() {
|
|
6329
|
+
"use strict";
|
|
6330
|
+
init_worlds();
|
|
6331
|
+
WORLD_WEBHOOK_PAGE_MAX = 100;
|
|
6332
|
+
FORWARD_TIMEOUT_MS = 1e4;
|
|
6333
|
+
ERROR_CHARS = 500;
|
|
6334
|
+
route = (sessionId) => `/api/public/world-sessions/${encodeURIComponent(sessionId)}/webhooks`;
|
|
6335
|
+
WorldWebhookForwarder = class {
|
|
6336
|
+
constructor(options, sessionId, forwardTo, opts = {}) {
|
|
6337
|
+
this.options = options;
|
|
6338
|
+
this.sessionId = sessionId;
|
|
6339
|
+
this.forwardTo = forwardTo;
|
|
6340
|
+
this.send = opts.fetch ?? fetch;
|
|
6341
|
+
}
|
|
6342
|
+
options;
|
|
6343
|
+
sessionId;
|
|
6344
|
+
forwardTo;
|
|
6345
|
+
after = 0;
|
|
6346
|
+
epoch = null;
|
|
6347
|
+
answers = [];
|
|
6348
|
+
send;
|
|
6349
|
+
get cursor() {
|
|
6350
|
+
return this.after;
|
|
6351
|
+
}
|
|
6352
|
+
/** Where forwarding begins: the deliveries the session still holds (`replay`), or only those it sends from now. */
|
|
6353
|
+
async start(replay) {
|
|
6354
|
+
if (replay) return null;
|
|
6355
|
+
const page = await this.poll([], { tail: true, limit: 1 });
|
|
6356
|
+
this.follow(page);
|
|
6357
|
+
return page;
|
|
6358
|
+
}
|
|
6359
|
+
/** One poll: the answers held so far sent, the next page forwarded. A poll that fails keeps its answers for the next. */
|
|
6360
|
+
async round() {
|
|
6361
|
+
const page = await this.withAnswers((answers) => this.poll(answers));
|
|
6362
|
+
const forwarded = [];
|
|
6363
|
+
for (const delivery of page.deliveries) {
|
|
6364
|
+
const answer = await this.forward(delivery);
|
|
6365
|
+
this.answers.push(answer);
|
|
6366
|
+
forwarded.push({ delivery, answer });
|
|
6367
|
+
}
|
|
6368
|
+
this.follow(page);
|
|
6369
|
+
return { page, forwarded };
|
|
6370
|
+
}
|
|
6371
|
+
/** Sends the answers still held; the cursor stays, so a delivery this poll returns is forwarded by the next round. */
|
|
6372
|
+
async settle() {
|
|
6373
|
+
if (this.answers.length === 0) return 0;
|
|
6374
|
+
const page = await this.withAnswers((answers) => this.poll(answers, { limit: 1 }));
|
|
6375
|
+
return page.answered;
|
|
6376
|
+
}
|
|
6377
|
+
follow(page) {
|
|
6378
|
+
this.after = page.next;
|
|
6379
|
+
this.epoch = page.epoch;
|
|
6380
|
+
}
|
|
6381
|
+
async withAnswers(poll) {
|
|
6382
|
+
const answers = this.answers.splice(0, WORLD_WEBHOOK_PAGE_MAX);
|
|
6383
|
+
try {
|
|
6384
|
+
return await poll(answers);
|
|
6385
|
+
} catch (error) {
|
|
6386
|
+
this.answers.unshift(...answers);
|
|
6387
|
+
throw error;
|
|
6388
|
+
}
|
|
6389
|
+
}
|
|
6390
|
+
poll(answers, opts = {}) {
|
|
6391
|
+
return apiRequest(this.options, "POST", route(this.sessionId), {
|
|
6392
|
+
after: this.after,
|
|
6393
|
+
epoch: this.epoch,
|
|
6394
|
+
tail: opts.tail ?? false,
|
|
6395
|
+
limit: opts.limit ?? WORLD_WEBHOOK_PAGE_MAX,
|
|
6396
|
+
subscriptions: false,
|
|
6397
|
+
answers
|
|
6398
|
+
});
|
|
6399
|
+
}
|
|
6400
|
+
async forward(delivery) {
|
|
6401
|
+
const started = Date.now();
|
|
6402
|
+
try {
|
|
6403
|
+
const reply = await this.send(this.forwardTo, {
|
|
6404
|
+
method: "POST",
|
|
6405
|
+
headers: delivery.headers,
|
|
6406
|
+
body: delivery.payload,
|
|
6407
|
+
redirect: "manual",
|
|
6408
|
+
signal: AbortSignal.timeout(FORWARD_TIMEOUT_MS)
|
|
6409
|
+
});
|
|
6410
|
+
await reply.arrayBuffer().catch(() => void 0);
|
|
6411
|
+
if (reply.status < 100 || reply.status > 599) throw new Error("the receiver answered an invalid HTTP status");
|
|
6412
|
+
return { id: delivery.id, status: reply.status, durationMs: Date.now() - started, error: null };
|
|
6413
|
+
} catch (error) {
|
|
6414
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
6415
|
+
return { id: delivery.id, status: 0, durationMs: Date.now() - started, error: message.slice(0, ERROR_CHARS) };
|
|
6416
|
+
}
|
|
6417
|
+
}
|
|
6418
|
+
};
|
|
6419
|
+
}
|
|
6420
|
+
});
|
|
6421
|
+
|
|
5992
6422
|
// src/worlds/checkoutTarget.ts
|
|
5993
6423
|
var fs2, path3, CheckoutRefusedError, NAMED_EDITS, CheckoutTarget;
|
|
5994
6424
|
var init_checkoutTarget = __esm({
|
|
@@ -6673,7 +7103,8 @@ function checkoutIdentity(ref, resolved) {
|
|
|
6673
7103
|
async function pull(slugRef, target, options = {}, opts = {}) {
|
|
6674
7104
|
const at = slugRef.indexOf("@");
|
|
6675
7105
|
const slug = at === -1 ? slugRef : slugRef.slice(0, at);
|
|
6676
|
-
const
|
|
7106
|
+
const asked = at === -1 ? void 0 : slugRef.slice(at + 1);
|
|
7107
|
+
const ref = asked ?? "latest";
|
|
6677
7108
|
const landing = CheckoutTarget.resolve(slug, target, {
|
|
6678
7109
|
cwd: process.cwd(),
|
|
6679
7110
|
force: opts.force ?? false,
|
|
@@ -6681,7 +7112,7 @@ async function pull(slugRef, target, options = {}, opts = {}) {
|
|
|
6681
7112
|
});
|
|
6682
7113
|
const details = await apiRequest(options, "POST", "/api/public/benchmark-containers/resolve-version", {
|
|
6683
7114
|
slug,
|
|
6684
|
-
ref
|
|
7115
|
+
...asked ? { ref: asked } : {}
|
|
6685
7116
|
});
|
|
6686
7117
|
if (!details.downloadUrl) {
|
|
6687
7118
|
throw new Error(`${slug}@${ref} resolved but has no uploaded bundle`);
|
|
@@ -6871,7 +7302,7 @@ async function validateWorld(dir, opts) {
|
|
|
6871
7302
|
options,
|
|
6872
7303
|
"POST",
|
|
6873
7304
|
"/api/public/benchmark-containers/resolve-version",
|
|
6874
|
-
{ slug, ref: branch }
|
|
7305
|
+
{ slug, ...branch === DEFAULT_BRANCH ? {} : { ref: branch } }
|
|
6875
7306
|
);
|
|
6876
7307
|
tipVersionId = tip.versionId ?? null;
|
|
6877
7308
|
} catch {
|
|
@@ -6983,6 +7414,10 @@ function parseSlugRef(slugRef) {
|
|
|
6983
7414
|
if (at === -1) return { slug: slugRef };
|
|
6984
7415
|
return { slug: slugRef.slice(0, at), ref: slugRef.slice(at + 1) };
|
|
6985
7416
|
}
|
|
7417
|
+
function nameGlob(pattern) {
|
|
7418
|
+
const literal = (part) => part.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
|
|
7419
|
+
return new RegExp(`^${pattern.split("*").map(literal).join(".*")}$`);
|
|
7420
|
+
}
|
|
6986
7421
|
function rebaseConflicts(error) {
|
|
6987
7422
|
if (!(error instanceof ApiError) || error.status !== 409) return null;
|
|
6988
7423
|
let body;
|
|
@@ -7000,7 +7435,8 @@ function isConflictPath(value) {
|
|
|
7000
7435
|
return typeof entry?.path === "string" && typeof entry.reason === "string";
|
|
7001
7436
|
}
|
|
7002
7437
|
function uncommittedPaths(error) {
|
|
7003
|
-
if (!(error instanceof ApiError) || error.status !== 409 || error.code !== "sandbox_uncommitted")
|
|
7438
|
+
if (!(error instanceof ApiError) || error.status !== 409 || error.code !== "sandbox_uncommitted")
|
|
7439
|
+
return null;
|
|
7004
7440
|
let body;
|
|
7005
7441
|
try {
|
|
7006
7442
|
body = JSON.parse(error.text);
|
|
@@ -7011,6 +7447,53 @@ function uncommittedPaths(error) {
|
|
|
7011
7447
|
if (!Array.isArray(uncommitted)) return null;
|
|
7012
7448
|
return uncommitted.filter((p) => typeof p === "string");
|
|
7013
7449
|
}
|
|
7450
|
+
function carriedWarnings(error) {
|
|
7451
|
+
const kept = typeof error === "object" && error !== null ? carried.get(error) ?? [] : [];
|
|
7452
|
+
const shown = error instanceof Error ? error.message : "";
|
|
7453
|
+
return unique([...kept, ...bodyWarnings(error)]).filter((warning) => !shown.includes(warning));
|
|
7454
|
+
}
|
|
7455
|
+
function carrying(error, warnings) {
|
|
7456
|
+
if (warnings.length > 0 && typeof error === "object" && error !== null)
|
|
7457
|
+
carried.set(error, unique([...carried.get(error) ?? [], ...warnings]));
|
|
7458
|
+
return error;
|
|
7459
|
+
}
|
|
7460
|
+
function unique(warnings) {
|
|
7461
|
+
return [...new Set(warnings)];
|
|
7462
|
+
}
|
|
7463
|
+
function bodyWarnings(error) {
|
|
7464
|
+
if (!(error instanceof ApiError)) return [];
|
|
7465
|
+
let body;
|
|
7466
|
+
try {
|
|
7467
|
+
body = JSON.parse(error.text);
|
|
7468
|
+
} catch {
|
|
7469
|
+
return [];
|
|
7470
|
+
}
|
|
7471
|
+
const warnings = body?.warnings;
|
|
7472
|
+
if (!Array.isArray(warnings)) return [];
|
|
7473
|
+
return warnings.filter((w) => typeof w === "string");
|
|
7474
|
+
}
|
|
7475
|
+
function deferredWarnings(error) {
|
|
7476
|
+
if (!(error instanceof ApiError) || error.status !== 409 || error.code !== "sandbox_exec_deferred") return null;
|
|
7477
|
+
return bodyWarnings(error);
|
|
7478
|
+
}
|
|
7479
|
+
function rowsRefusal(error) {
|
|
7480
|
+
if (!(error instanceof ApiError) || error.status !== 400 || error.code !== "rows_refused") return null;
|
|
7481
|
+
let body;
|
|
7482
|
+
try {
|
|
7483
|
+
body = JSON.parse(error.text);
|
|
7484
|
+
} catch {
|
|
7485
|
+
return null;
|
|
7486
|
+
}
|
|
7487
|
+
const { message, batchId, refusalCount, refusals, reportUrl } = body;
|
|
7488
|
+
if (typeof batchId !== "string" || typeof refusalCount !== "number" || !Array.isArray(refusals)) return null;
|
|
7489
|
+
return {
|
|
7490
|
+
message: typeof message === "string" ? message : "",
|
|
7491
|
+
batchId,
|
|
7492
|
+
refusalCount,
|
|
7493
|
+
refusals: refusals.filter((r) => typeof r === "object" && r !== null),
|
|
7494
|
+
reportUrl: typeof reportUrl === "string" ? reportUrl : null
|
|
7495
|
+
};
|
|
7496
|
+
}
|
|
7014
7497
|
function listQuery(filter) {
|
|
7015
7498
|
const params = new URLSearchParams();
|
|
7016
7499
|
if (filter.status) params.set("status", filter.status);
|
|
@@ -7019,15 +7502,52 @@ function listQuery(filter) {
|
|
|
7019
7502
|
const qs = params.toString();
|
|
7020
7503
|
return qs ? `?${qs}` : "";
|
|
7021
7504
|
}
|
|
7022
|
-
var isSandboxImportPending, sid, SANDBOXES, SANDBOX_REQUEST_TIMEOUT_MS, WorldSandboxClient;
|
|
7505
|
+
var import_node_crypto7, 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;
|
|
7023
7506
|
var init_sandbox = __esm({
|
|
7024
7507
|
"src/worlds/sandbox.ts"() {
|
|
7025
7508
|
"use strict";
|
|
7509
|
+
import_node_crypto7 = require("crypto");
|
|
7026
7510
|
init_worlds();
|
|
7511
|
+
isSandboxCommitPending = (answer) => !("versionId" in answer);
|
|
7027
7512
|
isSandboxImportPending = (answer) => !("versionId" in answer);
|
|
7028
7513
|
sid = encodeURIComponent;
|
|
7029
7514
|
SANDBOXES = "/api/public/benchmark-containers/sandboxes";
|
|
7030
|
-
SANDBOX_REQUEST_TIMEOUT_MS =
|
|
7515
|
+
SANDBOX_REQUEST_TIMEOUT_MS = 29e4;
|
|
7516
|
+
SANDBOX_WRITE_CHUNK_BYTES = 4 * 1024 * 1024;
|
|
7517
|
+
SANDBOX_FILE_MAX_BYTES = 256 * 1024 * 1024;
|
|
7518
|
+
SANDBOX_WRITE_SKIPPED = [
|
|
7519
|
+
".git/",
|
|
7520
|
+
".gateway/",
|
|
7521
|
+
"scratch/",
|
|
7522
|
+
".scratch/",
|
|
7523
|
+
"__pycache__/",
|
|
7524
|
+
"*.pyc",
|
|
7525
|
+
".pytest_cache/",
|
|
7526
|
+
".mypy_cache/",
|
|
7527
|
+
".ruff_cache/",
|
|
7528
|
+
"node_modules/",
|
|
7529
|
+
".venv/",
|
|
7530
|
+
"venv/",
|
|
7531
|
+
".DS_Store",
|
|
7532
|
+
"*.swp"
|
|
7533
|
+
];
|
|
7534
|
+
WriteTreeFilter = class {
|
|
7535
|
+
directories = new Set(
|
|
7536
|
+
SANDBOX_WRITE_SKIPPED.filter((pattern) => pattern.endsWith("/")).map((pattern) => pattern.slice(0, -1))
|
|
7537
|
+
);
|
|
7538
|
+
files = SANDBOX_WRITE_SKIPPED.filter((pattern) => !pattern.endsWith("/")).map(nameGlob);
|
|
7539
|
+
skipsDirectory(name) {
|
|
7540
|
+
return this.directories.has(name);
|
|
7541
|
+
}
|
|
7542
|
+
skipsFile(name) {
|
|
7543
|
+
return this.files.some((glob) => glob.test(name));
|
|
7544
|
+
}
|
|
7545
|
+
};
|
|
7546
|
+
SANDBOX_EXEC_WAIT_MS = 4e4;
|
|
7547
|
+
SANDBOX_EXEC_TIMEOUT_MAX_S = 600;
|
|
7548
|
+
SANDBOX_EXEC_REPORT_MARGIN_MS = 35e3;
|
|
7549
|
+
SANDBOX_EXEC_START_ATTEMPTS = 3;
|
|
7550
|
+
carried = /* @__PURE__ */ new WeakMap();
|
|
7031
7551
|
WorldSandboxClient = class {
|
|
7032
7552
|
constructor(options = {}) {
|
|
7033
7553
|
this.options = options;
|
|
@@ -7052,7 +7572,10 @@ var init_sandbox = __esm({
|
|
|
7052
7572
|
}
|
|
7053
7573
|
/** The project's sandboxes, newest first — how an agent finds one it left open. */
|
|
7054
7574
|
async list(filter = {}) {
|
|
7055
|
-
const res = await this.request(
|
|
7575
|
+
const res = await this.request(
|
|
7576
|
+
"GET",
|
|
7577
|
+
`${SANDBOXES}${listQuery(filter)}`
|
|
7578
|
+
);
|
|
7056
7579
|
return res.sandboxes;
|
|
7057
7580
|
}
|
|
7058
7581
|
async read(sandboxId, filePath) {
|
|
@@ -7060,16 +7583,72 @@ var init_sandbox = __esm({
|
|
|
7060
7583
|
"GET",
|
|
7061
7584
|
`${SANDBOXES}/${sid(sandboxId)}/file?path=${encodeURIComponent(filePath)}`
|
|
7062
7585
|
);
|
|
7063
|
-
return {
|
|
7586
|
+
return {
|
|
7587
|
+
path: res.path,
|
|
7588
|
+
size: res.size,
|
|
7589
|
+
bytes: Buffer.from(res.contentBase64, "base64")
|
|
7590
|
+
};
|
|
7064
7591
|
}
|
|
7065
|
-
|
|
7066
|
-
|
|
7067
|
-
|
|
7068
|
-
|
|
7069
|
-
|
|
7592
|
+
/** A file past one chunk goes up in parts under one upload id; the platform lands it whole once the last part's
|
|
7593
|
+
* size and SHA-256 check out. */
|
|
7594
|
+
async write(sandboxId, filePath, bytes) {
|
|
7595
|
+
if (bytes.length <= SANDBOX_WRITE_CHUNK_BYTES)
|
|
7596
|
+
return this.putFile(sandboxId, { path: filePath, contentBase64: bytes.toString("base64") });
|
|
7597
|
+
const whole = { upload: (0, import_node_crypto7.randomUUID)(), size: bytes.length, sha256: (0, import_node_crypto7.createHash)("sha256").update(bytes).digest("hex") };
|
|
7598
|
+
let answer = { path: filePath, received: 0 };
|
|
7599
|
+
for (let offset = 0; offset < bytes.length; offset += SANDBOX_WRITE_CHUNK_BYTES) {
|
|
7600
|
+
const part = bytes.subarray(offset, offset + SANDBOX_WRITE_CHUNK_BYTES);
|
|
7601
|
+
answer = await this.putFile(sandboxId, {
|
|
7602
|
+
path: filePath,
|
|
7603
|
+
contentBase64: part.toString("base64"),
|
|
7604
|
+
...whole,
|
|
7605
|
+
offset,
|
|
7606
|
+
last: offset + part.length === bytes.length
|
|
7607
|
+
});
|
|
7608
|
+
}
|
|
7609
|
+
return answer;
|
|
7070
7610
|
}
|
|
7071
|
-
|
|
7072
|
-
return this.request("
|
|
7611
|
+
putFile(sandboxId, body) {
|
|
7612
|
+
return this.request("PUT", `${SANDBOXES}/${sid(sandboxId)}/file`, body);
|
|
7613
|
+
}
|
|
7614
|
+
/** Runs as a job on the platform: a command that outlasts one request is waited on again until its result. */
|
|
7615
|
+
async exec(sandboxId, input) {
|
|
7616
|
+
const budgetMs = (input.timeoutMs ?? SANDBOX_EXEC_TIMEOUT_MAX_S * 1e3) + SANDBOX_EXEC_REPORT_MARGIN_MS;
|
|
7617
|
+
let answer = await this.startExec(sandboxId, { ...input, waitMs: SANDBOX_EXEC_WAIT_MS });
|
|
7618
|
+
const deadline = Date.now() + budgetMs;
|
|
7619
|
+
const warnings = [...answer.warnings ?? []];
|
|
7620
|
+
try {
|
|
7621
|
+
while ("state" in answer) {
|
|
7622
|
+
if (Date.now() >= deadline)
|
|
7623
|
+
throw new Error(
|
|
7624
|
+
`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.`
|
|
7625
|
+
);
|
|
7626
|
+
answer = await this.execStep(sandboxId, { execId: answer.execId, waitMs: SANDBOX_EXEC_WAIT_MS });
|
|
7627
|
+
warnings.push(...answer.warnings ?? []);
|
|
7628
|
+
}
|
|
7629
|
+
} catch (error) {
|
|
7630
|
+
throw carrying(error, warnings);
|
|
7631
|
+
}
|
|
7632
|
+
return { ...answer, warnings };
|
|
7633
|
+
}
|
|
7634
|
+
// A deferred start ran nothing (the platform was still getting the sandbox ready), so starting again is safe. What
|
|
7635
|
+
// getting ready found rides on the deferral alone (no later call reports it), so it is kept for the answer, or for
|
|
7636
|
+
// the error when a later attempt fails.
|
|
7637
|
+
async startExec(sandboxId, body) {
|
|
7638
|
+
const kept = [];
|
|
7639
|
+
for (let attempt = 1; ; attempt += 1) {
|
|
7640
|
+
try {
|
|
7641
|
+
const answer = await this.execStep(sandboxId, body);
|
|
7642
|
+
return { ...answer, warnings: unique([...kept, ...answer.warnings ?? []]) };
|
|
7643
|
+
} catch (error) {
|
|
7644
|
+
const warnings = deferredWarnings(error);
|
|
7645
|
+
if (warnings === null || attempt === SANDBOX_EXEC_START_ATTEMPTS) throw carrying(error, kept);
|
|
7646
|
+
kept.push(...warnings);
|
|
7647
|
+
}
|
|
7648
|
+
}
|
|
7649
|
+
}
|
|
7650
|
+
execStep(sandboxId, body) {
|
|
7651
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/exec`, body);
|
|
7073
7652
|
}
|
|
7074
7653
|
check(sandboxId) {
|
|
7075
7654
|
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/check`, {});
|
|
@@ -7077,7 +7656,11 @@ var init_sandbox = __esm({
|
|
|
7077
7656
|
/** With `rebase`, a moved base is replayed onto; a 409 then names the conflicting paths (`rebaseConflicts`). */
|
|
7078
7657
|
commit(sandboxId, input) {
|
|
7079
7658
|
const { rebase, ...rest } = input;
|
|
7080
|
-
return this.request(
|
|
7659
|
+
return this.request(
|
|
7660
|
+
"POST",
|
|
7661
|
+
`${SANDBOXES}/${sid(sandboxId)}/commit`,
|
|
7662
|
+
rebase ? { ...rest, rebase: true } : rest
|
|
7663
|
+
);
|
|
7081
7664
|
}
|
|
7082
7665
|
/**
|
|
7083
7666
|
* A rows file already in the sandbox tree into the PLATFORM world the
|
|
@@ -7090,7 +7673,11 @@ var init_sandbox = __esm({
|
|
|
7090
7673
|
}
|
|
7091
7674
|
/** Uncommitted work is a 409 (`uncommittedPaths`) unless `force` discards it. */
|
|
7092
7675
|
close(sandboxId, opts = {}) {
|
|
7093
|
-
return this.request(
|
|
7676
|
+
return this.request(
|
|
7677
|
+
"DELETE",
|
|
7678
|
+
`${SANDBOXES}/${sid(sandboxId)}`,
|
|
7679
|
+
opts.force ? { force: true } : void 0
|
|
7680
|
+
);
|
|
7094
7681
|
}
|
|
7095
7682
|
};
|
|
7096
7683
|
}
|
|
@@ -7426,11 +8013,11 @@ function applyTransforms(value, chain) {
|
|
|
7426
8013
|
for (const step of steps) out = step(out);
|
|
7427
8014
|
return out;
|
|
7428
8015
|
}
|
|
7429
|
-
var
|
|
8016
|
+
var import_node_crypto8, WHITESPACE, WHITESPACE_EDGES, WHITESPACE_RUN, NOT_DIGIT, STRIP_PREFIX, trim, emailLocalPart, emailDomain, stripPrefix, hex, SIMPLE, TRANSFORMS, text;
|
|
7430
8017
|
var init_transforms = __esm({
|
|
7431
8018
|
"src/worlds/transforms.ts"() {
|
|
7432
8019
|
"use strict";
|
|
7433
|
-
|
|
8020
|
+
import_node_crypto8 = require("crypto");
|
|
7434
8021
|
init_json();
|
|
7435
8022
|
WHITESPACE = " \n\r\f\v";
|
|
7436
8023
|
WHITESPACE_EDGES = new RegExp(`^[${WHITESPACE}]+|[${WHITESPACE}]+$`, "g");
|
|
@@ -7447,7 +8034,7 @@ var init_transforms = __esm({
|
|
|
7447
8034
|
return at === -1 ? "" : value.slice(at + 1).toLowerCase();
|
|
7448
8035
|
};
|
|
7449
8036
|
stripPrefix = (prefix) => (value) => value.startsWith(prefix) ? value.slice(prefix.length) : value;
|
|
7450
|
-
hex = (algorithm, value) => (0,
|
|
8037
|
+
hex = (algorithm, value) => (0, import_node_crypto8.createHash)(algorithm).update(value, "utf8").digest("hex");
|
|
7451
8038
|
SIMPLE = {
|
|
7452
8039
|
lower: (value) => value.toLowerCase(),
|
|
7453
8040
|
upper: (value) => value.toUpperCase(),
|
|
@@ -7479,7 +8066,7 @@ function pyText(value) {
|
|
|
7479
8066
|
return pyFloatRepr(value);
|
|
7480
8067
|
}
|
|
7481
8068
|
function hashForm(slug, plaintext) {
|
|
7482
|
-
return "sha256:" + (0,
|
|
8069
|
+
return "sha256:" + (0, import_node_crypto9.createHash)("sha256").update(`${slug}:${pyText(plaintext)}`, "utf8").digest("hex");
|
|
7483
8070
|
}
|
|
7484
8071
|
function preserveForm(slug, plaintext) {
|
|
7485
8072
|
const kind = typeof plaintext === "string" ? "str" : isInt(plaintext) ? "int" : "float";
|
|
@@ -7488,12 +8075,12 @@ function preserveForm(slug, plaintext) {
|
|
|
7488
8075
|
}
|
|
7489
8076
|
function shapeText(slug, text2, kind) {
|
|
7490
8077
|
const seed = Buffer.from(`${slug}:${text2}`, "utf8");
|
|
7491
|
-
let digest = (0,
|
|
8078
|
+
let digest = (0, import_node_crypto9.createHash)("sha256").update(seed).digest();
|
|
7492
8079
|
let cursor = 0;
|
|
7493
8080
|
const out = [];
|
|
7494
8081
|
for (const char of text2) {
|
|
7495
8082
|
if (cursor === digest.length) {
|
|
7496
|
-
digest = (0,
|
|
8083
|
+
digest = (0, import_node_crypto9.createHash)("sha256").update(Buffer.concat([digest, seed])).digest();
|
|
7497
8084
|
cursor = 0;
|
|
7498
8085
|
}
|
|
7499
8086
|
const byte = digest[cursor];
|
|
@@ -7530,11 +8117,11 @@ function storedForms(world, field2, plaintext, transform) {
|
|
|
7530
8117
|
if (policy !== null) return [roundForm(plaintext, world.redact.round[field2])];
|
|
7531
8118
|
return [plaintext];
|
|
7532
8119
|
}
|
|
7533
|
-
var
|
|
8120
|
+
var import_node_crypto9, isInt;
|
|
7534
8121
|
var init_redaction = __esm({
|
|
7535
8122
|
"src/worlds/redaction.ts"() {
|
|
7536
8123
|
"use strict";
|
|
7537
|
-
|
|
8124
|
+
import_node_crypto9 = require("crypto");
|
|
7538
8125
|
init_json();
|
|
7539
8126
|
init_transforms();
|
|
7540
8127
|
isInt = (value) => typeof value === "number" && Number.isInteger(value);
|
|
@@ -7630,9 +8217,9 @@ var init_router = __esm({
|
|
|
7630
8217
|
});
|
|
7631
8218
|
|
|
7632
8219
|
// src/cli/config.ts
|
|
7633
|
-
async function api(creds, method,
|
|
7634
|
-
const reply = await new PlatformTransport(creds).send(method,
|
|
7635
|
-
if (!reply.ok) throw new ApiError2(reply.status, method,
|
|
8220
|
+
async function api(creds, method, route2, body, init2 = {}) {
|
|
8221
|
+
const reply = await new PlatformTransport(creds).send(method, route2, body, init2);
|
|
8222
|
+
if (!reply.ok) throw new ApiError2(reply.status, method, route2, reply.text);
|
|
7636
8223
|
return reply.text ? JSON.parse(reply.text) : {};
|
|
7637
8224
|
}
|
|
7638
8225
|
var fs6, os, path7, ApiError2;
|
|
@@ -7646,12 +8233,12 @@ var init_config = __esm({
|
|
|
7646
8233
|
init_worlds();
|
|
7647
8234
|
init_transport();
|
|
7648
8235
|
ApiError2 = class extends CliError {
|
|
7649
|
-
constructor(status, method,
|
|
7650
|
-
const body = parseErrorBody(text2);
|
|
7651
|
-
super(`${method} ${
|
|
8236
|
+
constructor(status, method, route2, text2) {
|
|
8237
|
+
const body = parseErrorBody(text2, status);
|
|
8238
|
+
super(`${method} ${route2} -> ${status}: ${body.detail}`, 1);
|
|
7652
8239
|
this.status = status;
|
|
7653
8240
|
this.method = method;
|
|
7654
|
-
this.route =
|
|
8241
|
+
this.route = route2;
|
|
7655
8242
|
this.text = text2;
|
|
7656
8243
|
this.code = body.code;
|
|
7657
8244
|
}
|
|
@@ -7665,6 +8252,14 @@ var init_config = __esm({
|
|
|
7665
8252
|
});
|
|
7666
8253
|
|
|
7667
8254
|
// src/cli/runtime/local.ts
|
|
8255
|
+
function forwardedEnv() {
|
|
8256
|
+
return Object.fromEntries(
|
|
8257
|
+
FORWARDED_ENV.flatMap((name) => {
|
|
8258
|
+
const value = process.env[name];
|
|
8259
|
+
return value ? [[name, value]] : [];
|
|
8260
|
+
})
|
|
8261
|
+
);
|
|
8262
|
+
}
|
|
7668
8263
|
function tailOf(output) {
|
|
7669
8264
|
return output.length > DIAGNOSTIC_TAIL ? `\u2026${output.slice(-DIAGNOSTIC_TAIL)}` : output;
|
|
7670
8265
|
}
|
|
@@ -7782,7 +8377,7 @@ async function localBridge(request, local, opts = {}) {
|
|
|
7782
8377
|
PATH: process.env.PATH ?? "",
|
|
7783
8378
|
HOME: process.env.HOME ?? "",
|
|
7784
8379
|
TMPDIR: process.env.TMPDIR ?? "",
|
|
7785
|
-
...
|
|
8380
|
+
...forwardedEnv(),
|
|
7786
8381
|
GATEWAY_RUNTIME_EXECUTE: "1"
|
|
7787
8382
|
}
|
|
7788
8383
|
}
|
|
@@ -7828,7 +8423,7 @@ async function localBridge(request, local, opts = {}) {
|
|
|
7828
8423
|
child.stdin.end(input);
|
|
7829
8424
|
});
|
|
7830
8425
|
}
|
|
7831
|
-
var import_node_child_process2, fs7, net, path8, MIN_PYTHON, MIN_PYTHON_LABEL, DIAGNOSTIC_TAIL, BRIDGE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
|
|
8426
|
+
var import_node_child_process2, fs7, net, path8, MIN_PYTHON, MIN_PYTHON_LABEL, DIAGNOSTIC_TAIL, FORWARDED_ENV, BRIDGE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
|
|
7832
8427
|
var init_local = __esm({
|
|
7833
8428
|
"src/cli/runtime/local.ts"() {
|
|
7834
8429
|
"use strict";
|
|
@@ -7841,6 +8436,7 @@ var init_local = __esm({
|
|
|
7841
8436
|
MIN_PYTHON = [3, 12];
|
|
7842
8437
|
MIN_PYTHON_LABEL = MIN_PYTHON.join(".");
|
|
7843
8438
|
DIAGNOSTIC_TAIL = 600;
|
|
8439
|
+
FORWARDED_ENV = ["VIRTUAL_ENV", "GATEWAY_SNAPSHOT_STORE"];
|
|
7844
8440
|
BRIDGE_BOOTSTRAP = `import sys,runpy,types,os
|
|
7845
8441
|
root=sys.argv[1]
|
|
7846
8442
|
package=types.ModuleType('gatewaysdk')
|
|
@@ -7993,8 +8589,8 @@ async function runtime(creds, request, opts = {}) {
|
|
|
7993
8589
|
throw new CliError(
|
|
7994
8590
|
"This needs the schema runtime (the CLI bundles it) or platform credentials (`gateway auth login`). " + localRuntimeReason()
|
|
7995
8591
|
);
|
|
7996
|
-
const
|
|
7997
|
-
const res = await new PlatformTransport(creds).send("POST",
|
|
8592
|
+
const route2 = "/api/public/worlds/runtime";
|
|
8593
|
+
const res = await new PlatformTransport(creds).send("POST", route2, request, {
|
|
7998
8594
|
timeoutMs: opts.timeoutMs ?? RUNTIME_TIMEOUT_MS
|
|
7999
8595
|
});
|
|
8000
8596
|
let payload = null;
|
|
@@ -8006,8 +8602,8 @@ async function runtime(creds, request, opts = {}) {
|
|
|
8006
8602
|
const detail = detailFrom(payload);
|
|
8007
8603
|
if (detail) throw new BridgeRejected(detail);
|
|
8008
8604
|
if (!res.ok)
|
|
8009
|
-
throw new CliError(`POST ${
|
|
8010
|
-
if (payload === null) throw new CliError(`POST ${
|
|
8605
|
+
throw new CliError(`POST ${route2} (${request.command}) -> ${res.status}: ${res.text.slice(0, 600)}`, 1);
|
|
8606
|
+
if (payload === null) throw new CliError(`POST ${route2} (${request.command}) returned non-JSON`, 1);
|
|
8011
8607
|
return payload;
|
|
8012
8608
|
}
|
|
8013
8609
|
var fs8, path9, MAX_WORLD_FILES, RUNTIME_TIMEOUT_MS, SKIP_DIRS, BridgeRejected, YAML_NAME, YAML_NEEDS_PYYAML, YAML_NOT_ON_PLATFORM, RuntimeRoute;
|
|
@@ -8476,11 +9072,15 @@ function isSettled(status) {
|
|
|
8476
9072
|
if (status.state !== "applied") return true;
|
|
8477
9073
|
return status.dryRun === true || status.publish !== "now" || !status.snapshotId;
|
|
8478
9074
|
}
|
|
9075
|
+
function worldDataPollMs() {
|
|
9076
|
+
const raw = Number(process.env.GATEWAY_WORLD_DATA_POLL_MS ?? 1e3);
|
|
9077
|
+
return Number.isFinite(raw) && raw >= 0 ? raw : 1e3;
|
|
9078
|
+
}
|
|
8479
9079
|
function uploadHeadersFor(gz) {
|
|
8480
9080
|
return {
|
|
8481
9081
|
"content-type": "application/gzip",
|
|
8482
9082
|
"content-length": String(gz.length),
|
|
8483
|
-
"x-amz-checksum-sha256": (0,
|
|
9083
|
+
"x-amz-checksum-sha256": (0, import_node_crypto10.createHash)("sha256").update(gz).digest("base64")
|
|
8484
9084
|
};
|
|
8485
9085
|
}
|
|
8486
9086
|
async function forEachLimited(items, limit, fn) {
|
|
@@ -8518,6 +9118,8 @@ async function waitForBatch(client, batchId, opts = {}) {
|
|
|
8518
9118
|
last = phase;
|
|
8519
9119
|
}
|
|
8520
9120
|
if (isSettled(status)) return status;
|
|
9121
|
+
if (opts.deadlineMs !== void 0 && (opts.now ?? Date.now)() >= opts.deadlineMs)
|
|
9122
|
+
return status;
|
|
8521
9123
|
await sleep4(delay);
|
|
8522
9124
|
delay = Math.min(1e4, Math.round(delay * 1.5));
|
|
8523
9125
|
}
|
|
@@ -8526,11 +9128,11 @@ function phaseLine(status) {
|
|
|
8526
9128
|
const phase = status.progress?.phase;
|
|
8527
9129
|
return phase ? `${status.state} (${phase})` : status.state;
|
|
8528
9130
|
}
|
|
8529
|
-
var
|
|
9131
|
+
var import_node_crypto10, fs11, TERMINAL_STATES, sleepMs, WorldDataApi;
|
|
8530
9132
|
var init_batches = __esm({
|
|
8531
9133
|
"src/cli/platform/worldData/batches.ts"() {
|
|
8532
9134
|
"use strict";
|
|
8533
|
-
|
|
9135
|
+
import_node_crypto10 = require("crypto");
|
|
8534
9136
|
fs11 = __toESM(require("fs"));
|
|
8535
9137
|
init_config();
|
|
8536
9138
|
init_router();
|
|
@@ -8569,11 +9171,6 @@ var init_batches = __esm({
|
|
|
8569
9171
|
}
|
|
8570
9172
|
);
|
|
8571
9173
|
}
|
|
8572
|
-
/**
|
|
8573
|
-
* Stage a project-drive rows file as one chunk, on the platform: the server
|
|
8574
|
-
* streams it out of drive storage into chunk storage and answers with the
|
|
8575
|
-
* digest and gzipped size it derived. No bytes pass through this process.
|
|
8576
|
-
*/
|
|
8577
9174
|
async stageDrive(batchId, chunk) {
|
|
8578
9175
|
const staged = await api(this.creds, "POST", `${this.base}/batches/${batchId}/chunks`, {
|
|
8579
9176
|
ordinal: chunk.ordinal,
|
|
@@ -8627,11 +9224,6 @@ var init_batches = __esm({
|
|
|
8627
9224
|
message ? { message } : {}
|
|
8628
9225
|
);
|
|
8629
9226
|
}
|
|
8630
|
-
/**
|
|
8631
|
-
* PUT the gzipped chunk to its presigned URL with exactly the headers the
|
|
8632
|
-
* URL was signed for (the platform's `uploadHeaders`; the same three when it
|
|
8633
|
-
* sends none), with backoff on a dropped connection or a 5xx.
|
|
8634
|
-
*/
|
|
8635
9227
|
async put(uploadUrl, gz, signed) {
|
|
8636
9228
|
const headers = signed ?? uploadHeadersFor(gz);
|
|
8637
9229
|
const delays = [500, 1500, 4e3];
|
|
@@ -8658,7 +9250,6 @@ var init_batches = __esm({
|
|
|
8658
9250
|
await this.sleep(delays[attempt]);
|
|
8659
9251
|
}
|
|
8660
9252
|
}
|
|
8661
|
-
/** Register, upload unless the server already holds the content, confirm. */
|
|
8662
9253
|
async upload(batchId, chunk) {
|
|
8663
9254
|
const registered = await this.register(batchId, chunk);
|
|
8664
9255
|
if (!registered.uploaded) {
|
|
@@ -8724,12 +9315,12 @@ function finishChunk(ordinal, raw, rows, entity, firstRow = 0) {
|
|
|
8724
9315
|
const gz = gzipDeterministic(raw, { name: chunkName(ordinal) });
|
|
8725
9316
|
return {
|
|
8726
9317
|
ordinal,
|
|
8727
|
-
digest: (0,
|
|
9318
|
+
digest: (0, import_node_crypto11.createHash)("sha256").update(gz).digest("hex"),
|
|
8728
9319
|
bytes: gz.length,
|
|
8729
9320
|
rows,
|
|
8730
9321
|
entity,
|
|
8731
9322
|
rawBytes: raw.length,
|
|
8732
|
-
contentSha256: (0,
|
|
9323
|
+
contentSha256: (0, import_node_crypto11.createHash)("sha256").update(raw).digest("hex"),
|
|
8733
9324
|
firstRow,
|
|
8734
9325
|
gz
|
|
8735
9326
|
};
|
|
@@ -8769,11 +9360,11 @@ function crc32(data) {
|
|
|
8769
9360
|
crc = table[(crc ^ data[i]) & 255] ^ crc >>> 8;
|
|
8770
9361
|
return (crc ^ 4294967295) >>> 0;
|
|
8771
9362
|
}
|
|
8772
|
-
var
|
|
9363
|
+
var import_node_crypto11, import_node_zlib3, DEFAULT_CHUNK_BYTES, GZIP_LEVEL, chunkName, table;
|
|
8773
9364
|
var init_chunker = __esm({
|
|
8774
9365
|
"src/cli/platform/worldData/chunker.ts"() {
|
|
8775
9366
|
"use strict";
|
|
8776
|
-
|
|
9367
|
+
import_node_crypto11 = require("crypto");
|
|
8777
9368
|
import_node_zlib3 = require("zlib");
|
|
8778
9369
|
init_json();
|
|
8779
9370
|
DEFAULT_CHUNK_BYTES = 64 * 1024 * 1024;
|
|
@@ -8799,22 +9390,33 @@ async function pushRows(creds, slug, rows, opts = {}) {
|
|
|
8799
9390
|
publish: opts.publish ?? "now",
|
|
8800
9391
|
...opts.message ? { message: opts.message } : {}
|
|
8801
9392
|
});
|
|
8802
|
-
if (!opened.batchId)
|
|
9393
|
+
if (!opened.batchId)
|
|
9394
|
+
throw new Error("the platform opened no batch (no batchId in the answer)");
|
|
8803
9395
|
const tagged = (async function* () {
|
|
8804
9396
|
for (const [entity, listed] of Object.entries(rows))
|
|
8805
9397
|
for (let index = 0; index < listed.length; index++)
|
|
8806
|
-
yield {
|
|
9398
|
+
yield {
|
|
9399
|
+
entity,
|
|
9400
|
+
row: parseJson(JSON.stringify(listed[index])),
|
|
9401
|
+
where: `${entity}[${index}]`
|
|
9402
|
+
};
|
|
8807
9403
|
})();
|
|
8808
|
-
const chunks = buildChunks(tagged, {
|
|
8809
|
-
|
|
8810
|
-
|
|
9404
|
+
const chunks = buildChunks(tagged, {
|
|
9405
|
+
chunkBytes: opts.chunkBytes ?? DEFAULT_CHUNK_BYTES,
|
|
9406
|
+
chunkRows: null,
|
|
9407
|
+
entity: null
|
|
8811
9408
|
});
|
|
9409
|
+
await forEachLimited(
|
|
9410
|
+
chunks,
|
|
9411
|
+
Math.max(1, opts.parallel ?? 4),
|
|
9412
|
+
async (chunk) => {
|
|
9413
|
+
await client.upload(opened.batchId, chunk);
|
|
9414
|
+
}
|
|
9415
|
+
);
|
|
8812
9416
|
await client.complete(opened.batchId);
|
|
8813
|
-
return waitForBatch(client, opened.batchId, {
|
|
8814
|
-
|
|
8815
|
-
|
|
8816
|
-
const raw = Number(process.env.GATEWAY_WORLD_DATA_POLL_MS ?? 1e3);
|
|
8817
|
-
return Number.isFinite(raw) && raw >= 0 ? raw : 1e3;
|
|
9417
|
+
return waitForBatch(client, opened.batchId, {
|
|
9418
|
+
initialDelayMs: worldDataPollMs()
|
|
9419
|
+
});
|
|
8818
9420
|
}
|
|
8819
9421
|
var init_push = __esm({
|
|
8820
9422
|
"src/cli/platform/worldData/push.ts"() {
|
|
@@ -9063,12 +9665,12 @@ var init_ingest = __esm({
|
|
|
9063
9665
|
});
|
|
9064
9666
|
|
|
9065
9667
|
// src/worlds/editSessions.ts
|
|
9066
|
-
var
|
|
9668
|
+
var WORLDS2, WorldEditClient, TASK_EDITS, TaskEditClient;
|
|
9067
9669
|
var init_editSessions = __esm({
|
|
9068
9670
|
"src/worlds/editSessions.ts"() {
|
|
9069
9671
|
"use strict";
|
|
9070
9672
|
init_worlds();
|
|
9071
|
-
|
|
9673
|
+
WORLDS2 = "/api/public/worlds";
|
|
9072
9674
|
WorldEditClient = class {
|
|
9073
9675
|
constructor(options = {}) {
|
|
9074
9676
|
this.options = options;
|
|
@@ -9080,19 +9682,19 @@ var init_editSessions = __esm({
|
|
|
9080
9682
|
if (query.status) qs.set("status", query.status);
|
|
9081
9683
|
if (query.limit !== void 0) qs.set("limit", String(query.limit));
|
|
9082
9684
|
const suffix = qs.size ? `?${qs.toString()}` : "";
|
|
9083
|
-
return apiRequest(this.options, "GET", `${
|
|
9685
|
+
return apiRequest(this.options, "GET", `${WORLDS2}/${encodeURIComponent(slug)}/edits${suffix}`);
|
|
9084
9686
|
}
|
|
9085
9687
|
/** Seal a session into a version on main (the credential's current one when `sessionId` is omitted). */
|
|
9086
9688
|
close(slug, input = {}) {
|
|
9087
|
-
return apiRequest(this.options, "POST", `${
|
|
9689
|
+
return apiRequest(this.options, "POST", `${WORLDS2}/${encodeURIComponent(slug)}/edits/close`, input);
|
|
9088
9690
|
}
|
|
9089
9691
|
/** Drop the session's private branch without making a version. */
|
|
9090
9692
|
discard(slug, input = {}) {
|
|
9091
|
-
return apiRequest(this.options, "POST", `${
|
|
9693
|
+
return apiRequest(this.options, "POST", `${WORLDS2}/${encodeURIComponent(slug)}/edits/discard`, input);
|
|
9092
9694
|
}
|
|
9093
9695
|
/** Undo a sealed session (source and data) as a new sealed session. */
|
|
9094
9696
|
rollback(slug, input) {
|
|
9095
|
-
return apiRequest(this.options, "POST", `${
|
|
9697
|
+
return apiRequest(this.options, "POST", `${WORLDS2}/${encodeURIComponent(slug)}/edits/rollback`, input);
|
|
9096
9698
|
}
|
|
9097
9699
|
};
|
|
9098
9700
|
TASK_EDITS = "/api/public/world-task-edits";
|
|
@@ -9246,15 +9848,27 @@ __export(worlds_exports, {
|
|
|
9246
9848
|
NativeComputer: () => NativeComputer,
|
|
9247
9849
|
OpenAIComputer: () => OpenAIComputer,
|
|
9248
9850
|
OpenAIPreviewComputer: () => OpenAIPreviewComputer,
|
|
9851
|
+
PLATFORM_SESSION_HEADER: () => PLATFORM_SESSION_HEADER,
|
|
9249
9852
|
PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
9250
9853
|
PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
|
|
9251
9854
|
PendingSafetyChecks: () => PendingSafetyChecks,
|
|
9252
9855
|
PlatformTransport: () => PlatformTransport,
|
|
9253
9856
|
PushSlugConflict: () => PushSlugConflict,
|
|
9254
9857
|
RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
|
|
9858
|
+
REQUESTS_NOT_RECORDED: () => REQUESTS_NOT_RECORDED,
|
|
9859
|
+
REQUEST_BODY_CAPTURE_BYTES: () => REQUEST_BODY_CAPTURE_BYTES,
|
|
9860
|
+
REQUEST_LOG_PAGE_MAX: () => REQUEST_LOG_PAGE_MAX,
|
|
9255
9861
|
RetryPolicy: () => RetryPolicy,
|
|
9862
|
+
SANDBOX_EXEC_REPORT_MARGIN_MS: () => SANDBOX_EXEC_REPORT_MARGIN_MS,
|
|
9863
|
+
SANDBOX_EXEC_START_ATTEMPTS: () => SANDBOX_EXEC_START_ATTEMPTS,
|
|
9864
|
+
SANDBOX_EXEC_TIMEOUT_MAX_S: () => SANDBOX_EXEC_TIMEOUT_MAX_S,
|
|
9865
|
+
SANDBOX_EXEC_WAIT_MS: () => SANDBOX_EXEC_WAIT_MS,
|
|
9866
|
+
SANDBOX_FILE_MAX_BYTES: () => SANDBOX_FILE_MAX_BYTES,
|
|
9256
9867
|
SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
|
|
9868
|
+
SANDBOX_WRITE_CHUNK_BYTES: () => SANDBOX_WRITE_CHUNK_BYTES,
|
|
9869
|
+
SANDBOX_WRITE_SKIPPED: () => SANDBOX_WRITE_SKIPPED,
|
|
9257
9870
|
SECRET_KEY: () => SECRET_KEY,
|
|
9871
|
+
SESSION_AUTH_MODES: () => SESSION_AUTH_MODES,
|
|
9258
9872
|
SESSION_STATES: () => SESSION_STATES,
|
|
9259
9873
|
SPAN_PREFIX: () => SPAN_PREFIX,
|
|
9260
9874
|
STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
|
|
@@ -9266,17 +9880,24 @@ __export(worlds_exports, {
|
|
|
9266
9880
|
TOOL_CONTRACT_UNREAD: () => TOOL_CONTRACT_UNREAD,
|
|
9267
9881
|
TRANSFORMS: () => TRANSFORMS,
|
|
9268
9882
|
TaskEditClient: () => TaskEditClient,
|
|
9883
|
+
TaskGrades: () => TaskGrades,
|
|
9269
9884
|
TaskRun: () => TaskRun,
|
|
9270
9885
|
TaskSessions: () => TaskSessions,
|
|
9271
9886
|
TransportCause: () => TransportCause,
|
|
9272
9887
|
UnreachableError: () => UnreachableError,
|
|
9273
9888
|
VERIFIER_REWARD_PREFIX: () => VERIFIER_REWARD_PREFIX,
|
|
9274
9889
|
WHITESPACE: () => WHITESPACE,
|
|
9890
|
+
WORLD_REQUEST_VIAS: () => WORLD_REQUEST_VIAS,
|
|
9891
|
+
WORLD_WEBHOOK_PAGE_MAX: () => WORLD_WEBHOOK_PAGE_MAX,
|
|
9275
9892
|
WorldBrowser: () => WorldBrowser,
|
|
9276
9893
|
WorldCallTooLarge: () => WorldCallTooLarge,
|
|
9277
9894
|
WorldEditClient: () => WorldEditClient,
|
|
9278
9895
|
WorldNotice: () => WorldNotice,
|
|
9896
|
+
WorldRequestFilterError: () => WorldRequestFilterError,
|
|
9897
|
+
WorldRequestLedger: () => WorldRequestLedger,
|
|
9279
9898
|
WorldRequestLog: () => WorldRequestLog,
|
|
9899
|
+
WorldRequestQuery: () => WorldRequestQuery,
|
|
9900
|
+
WorldRequestsNotRecorded: () => WorldRequestsNotRecorded,
|
|
9280
9901
|
WorldSandboxClient: () => WorldSandboxClient,
|
|
9281
9902
|
WorldSession: () => WorldSession,
|
|
9282
9903
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
@@ -9286,18 +9907,23 @@ __export(worlds_exports, {
|
|
|
9286
9907
|
WorldSurfaceUnavailable: () => WorldSurfaceUnavailable,
|
|
9287
9908
|
WorldTask: () => WorldTask,
|
|
9288
9909
|
WorldToolsUnread: () => WorldToolsUnread,
|
|
9910
|
+
WorldWebhookForwarder: () => WorldWebhookForwarder,
|
|
9911
|
+
WriteTreeFilter: () => WriteTreeFilter,
|
|
9289
9912
|
aggregateTaskGrade: () => aggregateTaskGrade,
|
|
9290
9913
|
apiRequest: () => apiRequest,
|
|
9291
9914
|
applyTransforms: () => applyTransforms,
|
|
9292
9915
|
archiveMode: () => archiveMode,
|
|
9293
9916
|
assertBrowserTier: () => assertBrowserTier,
|
|
9917
|
+
assertSessionAuthMode: () => assertSessionAuthMode,
|
|
9294
9918
|
assertTaskRef: () => assertTaskRef,
|
|
9295
9919
|
attachManifest: () => attachManifest,
|
|
9296
9920
|
attachSession: () => attachSession,
|
|
9297
9921
|
attachTask: () => attachTask,
|
|
9298
9922
|
buildFileManifest: () => buildFileManifest,
|
|
9299
9923
|
buildSourceTarball: () => buildSourceTarball,
|
|
9924
|
+
capabilityLabel: () => capabilityLabel,
|
|
9300
9925
|
captureToolCalls: () => captureToolCalls,
|
|
9926
|
+
carriedWarnings: () => carriedWarnings,
|
|
9301
9927
|
checkoutIdentity: () => checkoutIdentity,
|
|
9302
9928
|
closeConnection: () => closeConnection,
|
|
9303
9929
|
collectArchiveRelPaths: () => collectArchiveRelPaths,
|
|
@@ -9316,7 +9942,9 @@ __export(worlds_exports, {
|
|
|
9316
9942
|
idleWarning: () => idleWarning,
|
|
9317
9943
|
ingest: () => ingest,
|
|
9318
9944
|
ingestToolCalls: () => ingestToolCalls,
|
|
9945
|
+
invalidFields: () => invalidFields,
|
|
9319
9946
|
isBrowserGone: () => isBrowserGone,
|
|
9947
|
+
isSandboxCommitPending: () => isSandboxCommitPending,
|
|
9320
9948
|
isSandboxImportPending: () => isSandboxImportPending,
|
|
9321
9949
|
isTaskIdRef: () => isTaskIdRef,
|
|
9322
9950
|
isTaskManifest: () => isTaskManifest,
|
|
@@ -9327,6 +9955,7 @@ __export(worlds_exports, {
|
|
|
9327
9955
|
listSessions: () => listSessions,
|
|
9328
9956
|
listTaskSessions: () => listTaskSessions,
|
|
9329
9957
|
listTasks: () => listTasks,
|
|
9958
|
+
listWebhooks: () => listWebhooks,
|
|
9330
9959
|
localTreeState: () => localTreeState,
|
|
9331
9960
|
messageOf: () => messageOf,
|
|
9332
9961
|
migrateProjectWorlds: () => migrateProjectWorlds,
|
|
@@ -9363,6 +9992,7 @@ __export(worlds_exports, {
|
|
|
9363
9992
|
resolveBrowserMode: () => resolveBrowserMode,
|
|
9364
9993
|
resolvePushSlug: () => resolvePushSlug,
|
|
9365
9994
|
roundForm: () => roundForm,
|
|
9995
|
+
rowsRefusal: () => rowsRefusal,
|
|
9366
9996
|
runSessions: () => runSessions,
|
|
9367
9997
|
runSet: () => runSet,
|
|
9368
9998
|
runTask: () => runTask,
|
|
@@ -9391,28 +10021,43 @@ __export(worlds_exports, {
|
|
|
9391
10021
|
validateWorld: () => validateWorld,
|
|
9392
10022
|
waitForRun: () => waitForRun,
|
|
9393
10023
|
withoutUiToken: () => withoutUiToken,
|
|
10024
|
+
worldRequestsUnrecorded: () => worldRequestsUnrecorded,
|
|
9394
10025
|
writeLocalMeta: () => writeLocalMeta
|
|
9395
10026
|
});
|
|
9396
10027
|
module.exports = __toCommonJS(worlds_exports);
|
|
9397
|
-
function
|
|
9398
|
-
|
|
10028
|
+
function edgeAnswer(text2, status) {
|
|
10029
|
+
if (status !== void 0 && status >= 500) return EDGE_ANSWERS[status] ?? EDGE_FAILURE;
|
|
10030
|
+
return /^\s*</.test(text2) ? EDGE_PAGE : null;
|
|
10031
|
+
}
|
|
10032
|
+
function parseErrorBody(text2, status) {
|
|
10033
|
+
const raw = { detail: text2.slice(0, DETAIL_LIMIT), code: null };
|
|
9399
10034
|
let parsed;
|
|
9400
10035
|
try {
|
|
9401
10036
|
parsed = JSON.parse(text2);
|
|
9402
10037
|
} catch {
|
|
9403
|
-
return
|
|
10038
|
+
return { detail: (edgeAnswer(text2, status) ?? text2).slice(0, DETAIL_LIMIT), code: null };
|
|
9404
10039
|
}
|
|
9405
10040
|
if (parsed === null || typeof parsed !== "object") return raw;
|
|
9406
|
-
const { message, code } = parsed;
|
|
10041
|
+
const { message, code, error } = parsed;
|
|
9407
10042
|
const stableCode = typeof code === "string" ? code : null;
|
|
9408
10043
|
if (typeof message !== "string") return { ...raw, code: stableCode };
|
|
9409
|
-
|
|
9410
|
-
|
|
10044
|
+
const fields = invalidFields(error);
|
|
10045
|
+
const said = fields ? `${message}: ${fields}` : message;
|
|
10046
|
+
if (stableCode === null) return { detail: said.slice(0, DETAIL_LIMIT), code: null };
|
|
9411
10047
|
return {
|
|
9412
|
-
detail: `${
|
|
10048
|
+
detail: `${said} (${stableCode})`.slice(0, DETAIL_LIMIT),
|
|
9413
10049
|
code: stableCode
|
|
9414
10050
|
};
|
|
9415
10051
|
}
|
|
10052
|
+
function invalidFields(error) {
|
|
10053
|
+
const issues = Array.isArray(error) ? error : [];
|
|
10054
|
+
return issues.filter(
|
|
10055
|
+
(issue) => issue !== null && typeof issue === "object" && typeof issue.message === "string"
|
|
10056
|
+
).map((issue) => {
|
|
10057
|
+
const path13 = Array.isArray(issue.path) ? issue.path.map(String).join(".") : "";
|
|
10058
|
+
return path13 ? `${path13}: ${issue.message}` : issue.message;
|
|
10059
|
+
}).join("; ");
|
|
10060
|
+
}
|
|
9416
10061
|
async function apiRequest(options, method, path13, body, init2 = {}) {
|
|
9417
10062
|
const reply = await new PlatformTransport(requirePlatformEndpoint(options)).send(method, path13, body, init2);
|
|
9418
10063
|
if (!reply.ok) throw new ApiError(reply.status, method, path13, reply.text);
|
|
@@ -9591,7 +10236,7 @@ async function resolveWorld(slugRef, slug, ref, pin, options) {
|
|
|
9591
10236
|
}
|
|
9592
10237
|
return world;
|
|
9593
10238
|
}
|
|
9594
|
-
var ApiError, WorldTask, WorldSet;
|
|
10239
|
+
var ApiError, DETAIL_LIMIT, EDGE_ANSWERS, EDGE_FAILURE, EDGE_PAGE, WorldTask, WorldSet;
|
|
9595
10240
|
var init_worlds = __esm({
|
|
9596
10241
|
"src/worlds/index.ts"() {
|
|
9597
10242
|
init_platformEndpoint();
|
|
@@ -9603,6 +10248,7 @@ var init_worlds = __esm({
|
|
|
9603
10248
|
init_sessionContract();
|
|
9604
10249
|
init_taskRef();
|
|
9605
10250
|
init_tasks();
|
|
10251
|
+
init_taskGrades();
|
|
9606
10252
|
init_taskSessions();
|
|
9607
10253
|
init_taskRun();
|
|
9608
10254
|
init_setRun();
|
|
@@ -9611,6 +10257,8 @@ var init_worlds = __esm({
|
|
|
9611
10257
|
init_browser();
|
|
9612
10258
|
init_surfaceDescriptor();
|
|
9613
10259
|
init_requestLog();
|
|
10260
|
+
init_requestLedger();
|
|
10261
|
+
init_webhooks();
|
|
9614
10262
|
init_browserReconnect();
|
|
9615
10263
|
init_nativeComputer();
|
|
9616
10264
|
init_hub();
|
|
@@ -9627,7 +10275,7 @@ var init_worlds = __esm({
|
|
|
9627
10275
|
init_worldNotice();
|
|
9628
10276
|
ApiError = class extends Error {
|
|
9629
10277
|
constructor(status, method, path13, text2) {
|
|
9630
|
-
const parsed = parseErrorBody(text2);
|
|
10278
|
+
const parsed = parseErrorBody(text2, status);
|
|
9631
10279
|
super(`${method} ${path13} -> ${status}: ${parsed.detail}`);
|
|
9632
10280
|
this.status = status;
|
|
9633
10281
|
this.text = text2;
|
|
@@ -9638,6 +10286,14 @@ var init_worlds = __esm({
|
|
|
9638
10286
|
text;
|
|
9639
10287
|
code;
|
|
9640
10288
|
};
|
|
10289
|
+
DETAIL_LIMIT = 600;
|
|
10290
|
+
EDGE_ANSWERS = {
|
|
10291
|
+
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.",
|
|
10292
|
+
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.",
|
|
10293
|
+
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."
|
|
10294
|
+
};
|
|
10295
|
+
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.";
|
|
10296
|
+
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.";
|
|
9641
10297
|
WorldTask = class {
|
|
9642
10298
|
constructor(world, name, variant) {
|
|
9643
10299
|
this.world = world;
|
|
@@ -9673,12 +10329,7 @@ var init_worlds = __esm({
|
|
|
9673
10329
|
}
|
|
9674
10330
|
return hit;
|
|
9675
10331
|
}
|
|
9676
|
-
/**
|
|
9677
|
-
* Open a LIVE session against one of this world's tasks — a bundled task's
|
|
9678
|
-
* name or an inline `WorldTaskSpec`: the platform boots (or reuses) a warm
|
|
9679
|
-
* container, and your agent calls its tools through the platform. See
|
|
9680
|
-
* worlds/session.ts.
|
|
9681
|
-
*/
|
|
10332
|
+
/** Open a live session on a bundled task's name or an inline `WorldTaskSpec`; the platform boots or reuses a warm container. */
|
|
9682
10333
|
async open(task, opts = {}) {
|
|
9683
10334
|
const { openSession: openSession2 } = await Promise.resolve().then(() => (init_session2(), session_exports2));
|
|
9684
10335
|
return openSession2(this.slug, {
|
|
@@ -9690,11 +10341,7 @@ var init_worlds = __esm({
|
|
|
9690
10341
|
options: this.options
|
|
9691
10342
|
});
|
|
9692
10343
|
}
|
|
9693
|
-
/**
|
|
9694
|
-
* Start a HOSTED run of a run config against this world — the platform
|
|
9695
|
-
* executes the (Python) world in parallel containers per the config's
|
|
9696
|
-
* `parallelism` and files one graded run per model. Returns those runs.
|
|
9697
|
-
*/
|
|
10344
|
+
/** Start a hosted run of a run config on this version (or `opts.versionId`): one graded run per model, provenance detected unless given. */
|
|
9698
10345
|
async dispatch(runConfigId, opts = {}) {
|
|
9699
10346
|
const provenance = opts.provenance ?? detectProvenance();
|
|
9700
10347
|
return apiRequest(
|
|
@@ -9755,15 +10402,27 @@ init_worlds();
|
|
|
9755
10402
|
NativeComputer,
|
|
9756
10403
|
OpenAIComputer,
|
|
9757
10404
|
OpenAIPreviewComputer,
|
|
10405
|
+
PLATFORM_SESSION_HEADER,
|
|
9758
10406
|
PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
9759
10407
|
PLATFORM_TIMEOUT_ENV,
|
|
9760
10408
|
PendingSafetyChecks,
|
|
9761
10409
|
PlatformTransport,
|
|
9762
10410
|
PushSlugConflict,
|
|
9763
10411
|
RECOVER_BUDGET_MS,
|
|
10412
|
+
REQUESTS_NOT_RECORDED,
|
|
10413
|
+
REQUEST_BODY_CAPTURE_BYTES,
|
|
10414
|
+
REQUEST_LOG_PAGE_MAX,
|
|
9764
10415
|
RetryPolicy,
|
|
10416
|
+
SANDBOX_EXEC_REPORT_MARGIN_MS,
|
|
10417
|
+
SANDBOX_EXEC_START_ATTEMPTS,
|
|
10418
|
+
SANDBOX_EXEC_TIMEOUT_MAX_S,
|
|
10419
|
+
SANDBOX_EXEC_WAIT_MS,
|
|
10420
|
+
SANDBOX_FILE_MAX_BYTES,
|
|
9765
10421
|
SANDBOX_REQUEST_TIMEOUT_MS,
|
|
10422
|
+
SANDBOX_WRITE_CHUNK_BYTES,
|
|
10423
|
+
SANDBOX_WRITE_SKIPPED,
|
|
9766
10424
|
SECRET_KEY,
|
|
10425
|
+
SESSION_AUTH_MODES,
|
|
9767
10426
|
SESSION_STATES,
|
|
9768
10427
|
SPAN_PREFIX,
|
|
9769
10428
|
STATUS_WAIT_CAP_SECONDS,
|
|
@@ -9775,17 +10434,24 @@ init_worlds();
|
|
|
9775
10434
|
TOOL_CONTRACT_UNREAD,
|
|
9776
10435
|
TRANSFORMS,
|
|
9777
10436
|
TaskEditClient,
|
|
10437
|
+
TaskGrades,
|
|
9778
10438
|
TaskRun,
|
|
9779
10439
|
TaskSessions,
|
|
9780
10440
|
TransportCause,
|
|
9781
10441
|
UnreachableError,
|
|
9782
10442
|
VERIFIER_REWARD_PREFIX,
|
|
9783
10443
|
WHITESPACE,
|
|
10444
|
+
WORLD_REQUEST_VIAS,
|
|
10445
|
+
WORLD_WEBHOOK_PAGE_MAX,
|
|
9784
10446
|
WorldBrowser,
|
|
9785
10447
|
WorldCallTooLarge,
|
|
9786
10448
|
WorldEditClient,
|
|
9787
10449
|
WorldNotice,
|
|
10450
|
+
WorldRequestFilterError,
|
|
10451
|
+
WorldRequestLedger,
|
|
9788
10452
|
WorldRequestLog,
|
|
10453
|
+
WorldRequestQuery,
|
|
10454
|
+
WorldRequestsNotRecorded,
|
|
9789
10455
|
WorldSandboxClient,
|
|
9790
10456
|
WorldSession,
|
|
9791
10457
|
WorldSessionCallError,
|
|
@@ -9795,18 +10461,23 @@ init_worlds();
|
|
|
9795
10461
|
WorldSurfaceUnavailable,
|
|
9796
10462
|
WorldTask,
|
|
9797
10463
|
WorldToolsUnread,
|
|
10464
|
+
WorldWebhookForwarder,
|
|
10465
|
+
WriteTreeFilter,
|
|
9798
10466
|
aggregateTaskGrade,
|
|
9799
10467
|
apiRequest,
|
|
9800
10468
|
applyTransforms,
|
|
9801
10469
|
archiveMode,
|
|
9802
10470
|
assertBrowserTier,
|
|
10471
|
+
assertSessionAuthMode,
|
|
9803
10472
|
assertTaskRef,
|
|
9804
10473
|
attachManifest,
|
|
9805
10474
|
attachSession,
|
|
9806
10475
|
attachTask,
|
|
9807
10476
|
buildFileManifest,
|
|
9808
10477
|
buildSourceTarball,
|
|
10478
|
+
capabilityLabel,
|
|
9809
10479
|
captureToolCalls,
|
|
10480
|
+
carriedWarnings,
|
|
9810
10481
|
checkoutIdentity,
|
|
9811
10482
|
closeConnection,
|
|
9812
10483
|
collectArchiveRelPaths,
|
|
@@ -9825,7 +10496,9 @@ init_worlds();
|
|
|
9825
10496
|
idleWarning,
|
|
9826
10497
|
ingest,
|
|
9827
10498
|
ingestToolCalls,
|
|
10499
|
+
invalidFields,
|
|
9828
10500
|
isBrowserGone,
|
|
10501
|
+
isSandboxCommitPending,
|
|
9829
10502
|
isSandboxImportPending,
|
|
9830
10503
|
isTaskIdRef,
|
|
9831
10504
|
isTaskManifest,
|
|
@@ -9836,6 +10509,7 @@ init_worlds();
|
|
|
9836
10509
|
listSessions,
|
|
9837
10510
|
listTaskSessions,
|
|
9838
10511
|
listTasks,
|
|
10512
|
+
listWebhooks,
|
|
9839
10513
|
localTreeState,
|
|
9840
10514
|
messageOf,
|
|
9841
10515
|
migrateProjectWorlds,
|
|
@@ -9872,6 +10546,7 @@ init_worlds();
|
|
|
9872
10546
|
resolveBrowserMode,
|
|
9873
10547
|
resolvePushSlug,
|
|
9874
10548
|
roundForm,
|
|
10549
|
+
rowsRefusal,
|
|
9875
10550
|
runSessions,
|
|
9876
10551
|
runSet,
|
|
9877
10552
|
runTask,
|
|
@@ -9900,6 +10575,7 @@ init_worlds();
|
|
|
9900
10575
|
validateWorld,
|
|
9901
10576
|
waitForRun,
|
|
9902
10577
|
withoutUiToken,
|
|
10578
|
+
worldRequestsUnrecorded,
|
|
9903
10579
|
writeLocalMeta
|
|
9904
10580
|
});
|
|
9905
10581
|
//# sourceMappingURL=index.js.map
|