@withgateway/sdk 0.3.0 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/dist/cli.js +3971 -2338
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +3950 -2318
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.d.mts +1 -1
- package/dist/files/index.d.ts +1 -1
- package/dist/files/index.js +214 -41
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +206 -35
- package/dist/files/index.mjs.map +1 -1
- package/dist/{index-DAb-FCMg.d.ts → index-DUHmS74p.d.ts} +3 -13
- package/dist/{index-D6oi1TWE.d.mts → index-mJhG3vZU.d.mts} +3 -13
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1456 -564
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1433 -557
- package/dist/index.mjs.map +1 -1
- package/dist/{media-CbcAfQvd.d.mts → media-BIApiPzS.d.mts} +21 -2
- package/dist/{media-CbcAfQvd.d.ts → media-BIApiPzS.d.ts} +21 -2
- package/dist/traces/index.d.mts +1 -1
- package/dist/traces/index.d.ts +1 -1
- package/dist/traces/index.js +211 -38
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +203 -32
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.d.mts +2 -2
- package/dist/tracing/index.d.ts +2 -2
- package/dist/tracing/index.js +96 -21
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +96 -21
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/worlds/index.d.mts +300 -123
- package/dist/worlds/index.d.ts +300 -123
- package/dist/worlds/index.js +1385 -508
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +1377 -501
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +1 -1
- package/runtime/gatewaysdk/environment/_bundle.py +2 -27
- package/runtime/gatewaysdk/environment/_materialize.py +49 -69
- package/runtime/gatewaysdk/environment/_world.py +122 -197
- package/runtime/gatewaysdk/environment/backing.py +137 -0
- package/runtime/gatewaysdk/environment/core.py +1 -1
- package/runtime/gatewaysdk/environment/legacy_sqlite.py +301 -0
- package/runtime/gatewaysdk/environment/reward_keys.py +25 -0
- package/runtime/gatewaysdk/environment/runtime.py +8 -13
- package/runtime/gatewaysdk/environment/schema/__init__.py +4 -4
- package/runtime/gatewaysdk/environment/schema/admin_routes.py +86 -0
- package/runtime/gatewaysdk/environment/schema/api.py +266 -515
- package/runtime/gatewaysdk/environment/schema/batch.py +42 -37
- package/runtime/gatewaysdk/environment/schema/bundle_runtime.py +17 -5
- package/runtime/gatewaysdk/environment/schema/call_log.py +291 -0
- package/runtime/gatewaysdk/environment/schema/call_redaction.py +344 -0
- package/runtime/gatewaysdk/environment/schema/cast.py +31 -4
- package/runtime/gatewaysdk/environment/schema/compiler.py +334 -158
- package/runtime/gatewaysdk/environment/schema/conform.py +8 -12
- package/runtime/gatewaysdk/environment/schema/connector.py +27 -62
- package/runtime/gatewaysdk/environment/schema/data.py +50 -207
- package/runtime/gatewaysdk/environment/schema/database/__init__.py +24 -0
- package/runtime/gatewaysdk/environment/schema/database/audit.py +121 -0
- package/runtime/gatewaysdk/environment/schema/database/base.py +995 -0
- package/runtime/gatewaysdk/environment/schema/database/budget.py +33 -0
- package/runtime/gatewaysdk/environment/schema/database/connections.py +101 -0
- package/runtime/gatewaysdk/environment/schema/database/engines.py +8 -0
- package/runtime/gatewaysdk/environment/schema/database/guard.py +208 -0
- package/runtime/gatewaysdk/environment/schema/database/ingest.py +154 -0
- package/runtime/gatewaysdk/environment/schema/database/matching.py +58 -0
- package/runtime/gatewaysdk/environment/schema/database/provenance.py +30 -0
- package/runtime/gatewaysdk/environment/schema/database/rows.py +53 -0
- package/runtime/gatewaysdk/environment/schema/database/runtime_rows.py +39 -0
- package/runtime/gatewaysdk/environment/schema/database/sqlite.py +367 -0
- package/runtime/gatewaysdk/environment/schema/domain_migration.py +236 -0
- package/runtime/gatewaysdk/environment/schema/envelope.py +169 -0
- package/runtime/gatewaysdk/environment/schema/extract.py +6 -13
- package/runtime/gatewaysdk/environment/schema/grading.py +45 -30
- package/runtime/gatewaysdk/environment/schema/handler_errors.py +142 -12
- package/runtime/gatewaysdk/environment/schema/host.py +158 -250
- package/runtime/gatewaysdk/environment/schema/lanes.py +53 -0
- package/runtime/gatewaysdk/environment/schema/local.py +44 -71
- package/runtime/gatewaysdk/environment/schema/mapping.py +5 -25
- package/runtime/gatewaysdk/environment/schema/openapi_import.py +112 -73
- package/runtime/gatewaysdk/environment/schema/openapi_paging.py +147 -0
- package/runtime/gatewaysdk/environment/schema/openapi_payloads.py +288 -0
- package/runtime/gatewaysdk/environment/schema/openapi_routes.py +97 -102
- package/runtime/gatewaysdk/environment/schema/openapi_schemas.py +113 -30
- package/runtime/gatewaysdk/environment/schema/platform.py +124 -178
- package/runtime/gatewaysdk/environment/schema/platform_import.py +2 -3
- package/runtime/gatewaysdk/environment/schema/platform_query.py +61 -5
- package/runtime/gatewaysdk/environment/schema/primary_key.py +61 -0
- package/runtime/gatewaysdk/environment/schema/proof.py +19 -12
- package/runtime/gatewaysdk/environment/schema/runtime.py +77 -160
- package/runtime/gatewaysdk/environment/schema/served_names.py +58 -0
- package/runtime/gatewaysdk/environment/schema/session_files.py +166 -0
- package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +2 -2
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +22 -14
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/ROWS.md +29 -3
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +16 -16
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +18 -18
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +3 -2
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +15 -0
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/openapi-import.md +50 -21
- package/runtime/gatewaysdk/environment/schema/slack.py +4 -8
- package/runtime/gatewaysdk/environment/schema/snapshot.py +385 -129
- package/runtime/gatewaysdk/environment/schema/store_contract.py +8 -14
- package/runtime/gatewaysdk/environment/schema/tasks.py +140 -55
- package/runtime/gatewaysdk/environment/schema/tools_world.py +110 -87
- package/runtime/gatewaysdk/environment/schema/ui.py +24 -5
- package/runtime/gatewaysdk/environment/schema/ui_static/app.js +100 -130
- package/runtime/gatewaysdk/environment/schema/ui_static/index.html +1 -8
- package/runtime/gatewaysdk/environment/schema/validation.py +166 -40
- package/runtime/gatewaysdk/environment/schema/workers.py +142 -57
- package/runtime/gatewaysdk/environment/schema/world_sql.py +81 -0
- package/runtime/gatewaysdk/environment/schema/world_tests.py +71 -39
- package/runtime/gatewaysdk/environment/score.py +57 -0
- package/runtime/gatewaysdk/environment/secret_values.py +36 -0
- package/runtime/gatewaysdk/environment/world.py +42 -3
- package/runtime/gatewaysdk/environment/world_session_contract.py +32 -5
- package/skills/benchmarks-getting-started/SKILL.md +2 -2
- package/skills/connector-schema-authoring/SKILL.md +22 -14
- package/skills/connector-schema-authoring/connector-worlds.md +26 -10
- package/skills/connector-schema-authoring/world-schema.md +111 -51
- package/skills/world-data-ingestion/ROWS.md +29 -3
- package/skills/world-data-ingestion/SKILL.md +16 -16
- package/skills/worlds-getting-started/SKILL.md +18 -18
- package/skills/worlds-getting-started/references/cli-mcp-map.md +3 -2
- package/skills/worlds-getting-started/references/gotchas.md +15 -0
- package/skills/worlds-getting-started/references/openapi-import.md +50 -21
- package/runtime/gatewaysdk/environment/schema/store.py +0 -1013
package/dist/worlds/index.mjs
CHANGED
|
@@ -28,6 +28,28 @@ var __export = (target, all) => {
|
|
|
28
28
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
+
// src/worlds/platformEndpoint.ts
|
|
32
|
+
function platformEndpoint(options) {
|
|
33
|
+
const publicKey = options.publicKey ?? process.env.GATEWAY_PUBLIC_KEY;
|
|
34
|
+
const secretKey = options.secretKey ?? process.env.GATEWAY_SECRET_KEY;
|
|
35
|
+
if (!publicKey || !secretKey) return null;
|
|
36
|
+
const host = options.host ?? process.env.GATEWAY_HOST ?? DEFAULT_HOST;
|
|
37
|
+
return { host: host.replace(/\/+$/, ""), publicKey, secretKey };
|
|
38
|
+
}
|
|
39
|
+
function requirePlatformEndpoint(options) {
|
|
40
|
+
const endpoint = platformEndpoint(options);
|
|
41
|
+
if (!endpoint) throw new Error(GATEWAY_KEYS_MISSING);
|
|
42
|
+
return endpoint;
|
|
43
|
+
}
|
|
44
|
+
var DEFAULT_HOST, GATEWAY_KEYS_MISSING;
|
|
45
|
+
var init_platformEndpoint = __esm({
|
|
46
|
+
"src/worlds/platformEndpoint.ts"() {
|
|
47
|
+
"use strict";
|
|
48
|
+
DEFAULT_HOST = "https://withgateway.ai";
|
|
49
|
+
GATEWAY_KEYS_MISSING = "Gateway keys missing: set GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY (or pass publicKey/secretKey).";
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
31
53
|
// src/worlds/transport.ts
|
|
32
54
|
function platformTimeoutMs(env = process.env) {
|
|
33
55
|
const raw = env[PLATFORM_TIMEOUT_ENV];
|
|
@@ -36,7 +58,7 @@ function platformTimeoutMs(env = process.env) {
|
|
|
36
58
|
if (Number.isInteger(value) && value > 0) return value;
|
|
37
59
|
throw new Error(`${PLATFORM_TIMEOUT_ENV} must be a positive whole number of milliseconds, not \`${raw}\`.`);
|
|
38
60
|
}
|
|
39
|
-
var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, PlatformTransport;
|
|
61
|
+
var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, sleep, RetryPolicy, Attempt, PlatformTransport;
|
|
40
62
|
var init_transport = __esm({
|
|
41
63
|
"src/worlds/transport.ts"() {
|
|
42
64
|
"use strict";
|
|
@@ -98,6 +120,56 @@ var init_transport = __esm({
|
|
|
98
120
|
route;
|
|
99
121
|
failure;
|
|
100
122
|
};
|
|
123
|
+
sleep = (ms) => new Promise((resolve7) => setTimeout(resolve7, ms));
|
|
124
|
+
RetryPolicy = class _RetryPolicy {
|
|
125
|
+
constructor(delaysMs, wait = sleep, budgetMs = Number.POSITIVE_INFINITY, now = Date.now) {
|
|
126
|
+
this.delaysMs = delaysMs;
|
|
127
|
+
this.wait = wait;
|
|
128
|
+
this.budgetMs = budgetMs;
|
|
129
|
+
this.now = now;
|
|
130
|
+
}
|
|
131
|
+
delaysMs;
|
|
132
|
+
wait;
|
|
133
|
+
budgetMs;
|
|
134
|
+
now;
|
|
135
|
+
static NONE = new _RetryPolicy([]);
|
|
136
|
+
/** A platform restart or a short edge outage: no wait starts that would end past five minutes, so a step ends
|
|
137
|
+
* within the budget plus one request timeout. */
|
|
138
|
+
static FILING = new _RetryPolicy([250, 500, 1e3, 2e3, 4e3, 8e3, 16e3, 3e4], sleep, 3e5);
|
|
139
|
+
static TRANSIENT_STATUSES = /* @__PURE__ */ new Set([502, 503, 504]);
|
|
140
|
+
async run(attempt) {
|
|
141
|
+
const started = this.now();
|
|
142
|
+
for (let tries = 0; ; tries += 1) {
|
|
143
|
+
const outcome = await Attempt.of(attempt);
|
|
144
|
+
const delayMs = this.delaysMs[tries];
|
|
145
|
+
const spent = delayMs === void 0 || this.now() - started + delayMs >= this.budgetMs;
|
|
146
|
+
if (!outcome.transient || spent) return outcome.settle();
|
|
147
|
+
await this.wait(delayMs);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
Attempt = class _Attempt {
|
|
152
|
+
constructor(reply, error, transient) {
|
|
153
|
+
this.reply = reply;
|
|
154
|
+
this.error = error;
|
|
155
|
+
this.transient = transient;
|
|
156
|
+
}
|
|
157
|
+
reply;
|
|
158
|
+
error;
|
|
159
|
+
transient;
|
|
160
|
+
static async of(attempt) {
|
|
161
|
+
try {
|
|
162
|
+
const reply = await attempt();
|
|
163
|
+
return new _Attempt(reply, null, RetryPolicy.TRANSIENT_STATUSES.has(reply.status));
|
|
164
|
+
} catch (error) {
|
|
165
|
+
return new _Attempt(null, error, error instanceof UnreachableError);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
settle() {
|
|
169
|
+
if (this.reply) return this.reply;
|
|
170
|
+
throw this.error;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
101
173
|
PlatformTransport = class {
|
|
102
174
|
constructor(endpoint, timeoutMs = platformTimeoutMs()) {
|
|
103
175
|
this.endpoint = endpoint;
|
|
@@ -111,6 +183,9 @@ var init_transport = __esm({
|
|
|
111
183
|
}
|
|
112
184
|
async send(method, route, body, opts = {}) {
|
|
113
185
|
const timeoutMs = this.budget(opts.timeoutMs);
|
|
186
|
+
return (opts.retry ?? RetryPolicy.NONE).run(() => this.once(method, route, body, timeoutMs));
|
|
187
|
+
}
|
|
188
|
+
async once(method, route, body, timeoutMs) {
|
|
114
189
|
const payload = body === void 0 ? {} : { body: JSON.stringify(body) };
|
|
115
190
|
const controller = new AbortController();
|
|
116
191
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
@@ -304,9 +379,9 @@ function surfaceKinds(s) {
|
|
|
304
379
|
if (s.browser) kinds.push("browser");
|
|
305
380
|
return kinds;
|
|
306
381
|
}
|
|
307
|
-
function uiUrl(ui,
|
|
382
|
+
function uiUrl(ui, path13) {
|
|
308
383
|
const base = ui.url.replace(/\/+$/, "");
|
|
309
|
-
const rel =
|
|
384
|
+
const rel = path13.startsWith("/") ? path13 : `/${path13}`;
|
|
310
385
|
if (!ui.token) return base + rel;
|
|
311
386
|
const [beforeHash, hash] = splitHash(rel);
|
|
312
387
|
const joiner = beforeHash.includes("?") ? "&" : "?";
|
|
@@ -547,7 +622,7 @@ var init_browser = __esm({
|
|
|
547
622
|
}
|
|
548
623
|
async send(batch) {
|
|
549
624
|
const retries = this.opts.maxRetries ?? EVENT_MAX_RETRIES;
|
|
550
|
-
const
|
|
625
|
+
const sleep4 = this.opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
551
626
|
for (let attempt = 0; attempt < retries; attempt++) {
|
|
552
627
|
try {
|
|
553
628
|
const base = await this.resolveBase();
|
|
@@ -564,7 +639,7 @@ var init_browser = __esm({
|
|
|
564
639
|
);
|
|
565
640
|
return;
|
|
566
641
|
}
|
|
567
|
-
await
|
|
642
|
+
await sleep4(500 * 2 ** attempt);
|
|
568
643
|
}
|
|
569
644
|
}
|
|
570
645
|
}
|
|
@@ -1201,13 +1276,13 @@ var init_screen = __esm({
|
|
|
1201
1276
|
});
|
|
1202
1277
|
}
|
|
1203
1278
|
async drag(action) {
|
|
1204
|
-
const
|
|
1205
|
-
if (
|
|
1279
|
+
const path13 = action.args.path ?? [];
|
|
1280
|
+
if (path13.length < 2) throw new Error("a drag needs at least two points");
|
|
1206
1281
|
return this.held(action.args.modifiers ?? [], async () => {
|
|
1207
|
-
await this.moveTo(
|
|
1282
|
+
await this.moveTo(path13[0]);
|
|
1208
1283
|
await this.page.mouse.down({ button: "left" });
|
|
1209
1284
|
try {
|
|
1210
|
-
for (const point2 of
|
|
1285
|
+
for (const point2 of path13.slice(1)) await this.moveTo(point2, DRAG_STEPS);
|
|
1211
1286
|
} finally {
|
|
1212
1287
|
await this.page.mouse.up({ button: "left" });
|
|
1213
1288
|
}
|
|
@@ -1298,7 +1373,7 @@ var init_media = __esm({
|
|
|
1298
1373
|
put;
|
|
1299
1374
|
maxBytes;
|
|
1300
1375
|
/** The uploader for `GATEWAY_HOST` / `GATEWAY_PUBLIC_KEY` /
|
|
1301
|
-
* `GATEWAY_SECRET_KEY`
|
|
1376
|
+
* `GATEWAY_SECRET_KEY` only; null when any is unset, so a run traced with a saved login uploads none. */
|
|
1302
1377
|
static fromEnv(env = process.env) {
|
|
1303
1378
|
const host = env.GATEWAY_HOST;
|
|
1304
1379
|
const publicKey = env.GATEWAY_PUBLIC_KEY;
|
|
@@ -2168,7 +2243,7 @@ function idleWarning(idleExpiresAt, now = /* @__PURE__ */ new Date()) {
|
|
|
2168
2243
|
const minutes = Math.max(0, Math.floor(leftMs / 6e4));
|
|
2169
2244
|
return `warning: session expires in ${minutes}m (idle TTL); call a tool to extend it or \`gateway worlds session pin\` to keep it`;
|
|
2170
2245
|
}
|
|
2171
|
-
var CALL_BODY_LIMIT_BYTES, CALL_BODY_LIMIT_LABEL, IDLE_WARNING_MINUTES, EXPLORATORY_TASK, EXPLORATORY_TASK_SOURCE, NO_GRADER_REASON, WorldCallTooLarge;
|
|
2246
|
+
var CALL_BODY_LIMIT_BYTES, CALL_BODY_LIMIT_LABEL, IDLE_WARNING_MINUTES, EXPLORATORY_TASK, EXPLORATORY_TASK_SOURCE, NO_GRADER_REASON, WorldCallTooLarge, stillStartingHint;
|
|
2172
2247
|
var init_sessionContract = __esm({
|
|
2173
2248
|
"src/worlds/sessionContract.ts"() {
|
|
2174
2249
|
"use strict";
|
|
@@ -2204,6 +2279,65 @@ var init_sessionContract = __esm({
|
|
|
2204
2279
|
};
|
|
2205
2280
|
}
|
|
2206
2281
|
};
|
|
2282
|
+
stillStartingHint = (sessionId) => `It keeps opening: poll \`gateway worlds session status ${sessionId}\` until ready, or end it with \`gateway worlds session close ${sessionId}\`.`;
|
|
2283
|
+
}
|
|
2284
|
+
});
|
|
2285
|
+
|
|
2286
|
+
// src/worlds/sessionReadiness.ts
|
|
2287
|
+
var READY_TIMEOUT_MS, READY_POLL_MS, sleep2, WorldSessionTimeout, WorldSessionCallError, WorldSessionOpenFailed, ENDED, SessionReadiness;
|
|
2288
|
+
var init_sessionReadiness = __esm({
|
|
2289
|
+
"src/worlds/sessionReadiness.ts"() {
|
|
2290
|
+
"use strict";
|
|
2291
|
+
READY_TIMEOUT_MS = 10 * 6e4;
|
|
2292
|
+
READY_POLL_MS = 2e3;
|
|
2293
|
+
sleep2 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
2294
|
+
WorldSessionTimeout = class extends Error {
|
|
2295
|
+
};
|
|
2296
|
+
WorldSessionCallError = class extends Error {
|
|
2297
|
+
};
|
|
2298
|
+
WorldSessionOpenFailed = class extends WorldSessionCallError {
|
|
2299
|
+
constructor(sessionId, state2, code, reason) {
|
|
2300
|
+
super(
|
|
2301
|
+
reason === null ? `World session ${sessionId} ${state2.toLowerCase()} before it was ready.` : `World session ${sessionId} failed to open: ${reason}${code ? ` (${code})` : ""}`
|
|
2302
|
+
);
|
|
2303
|
+
this.sessionId = sessionId;
|
|
2304
|
+
this.state = state2;
|
|
2305
|
+
this.code = code;
|
|
2306
|
+
this.name = "WorldSessionOpenFailed";
|
|
2307
|
+
}
|
|
2308
|
+
sessionId;
|
|
2309
|
+
state;
|
|
2310
|
+
code;
|
|
2311
|
+
};
|
|
2312
|
+
ENDED = /* @__PURE__ */ new Set(["FAILED", "STOPPED"]);
|
|
2313
|
+
SessionReadiness = class {
|
|
2314
|
+
constructor(sessionId, status) {
|
|
2315
|
+
this.sessionId = sessionId;
|
|
2316
|
+
this.status = status;
|
|
2317
|
+
}
|
|
2318
|
+
sessionId;
|
|
2319
|
+
status;
|
|
2320
|
+
async wait(timeoutMs = READY_TIMEOUT_MS) {
|
|
2321
|
+
const deadline = Date.now() + timeoutMs;
|
|
2322
|
+
for (; ; ) {
|
|
2323
|
+
const state2 = await this.status();
|
|
2324
|
+
if (state2.ready) return state2;
|
|
2325
|
+
if (ENDED.has(state2.state))
|
|
2326
|
+
throw new WorldSessionOpenFailed(
|
|
2327
|
+
this.sessionId,
|
|
2328
|
+
state2.state,
|
|
2329
|
+
state2.failure?.code ?? null,
|
|
2330
|
+
state2.failure?.message ?? null
|
|
2331
|
+
);
|
|
2332
|
+
const left = deadline - Date.now();
|
|
2333
|
+
if (left <= 0)
|
|
2334
|
+
throw new WorldSessionTimeout(
|
|
2335
|
+
`World session ${this.sessionId} still ${state2.state} after ${Math.round(timeoutMs / 1e3)}s.`
|
|
2336
|
+
);
|
|
2337
|
+
await sleep2(Math.min(READY_POLL_MS, left));
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
};
|
|
2207
2341
|
}
|
|
2208
2342
|
});
|
|
2209
2343
|
|
|
@@ -2299,11 +2433,184 @@ var init_taskRef = __esm({
|
|
|
2299
2433
|
}
|
|
2300
2434
|
});
|
|
2301
2435
|
|
|
2436
|
+
// src/worlds/worldNotice.ts
|
|
2437
|
+
var TOOL_CONTRACT_UNREAD, DEPRECATION, NOTICE_KINDS, WorldNotice, WorldToolsUnread;
|
|
2438
|
+
var init_worldNotice = __esm({
|
|
2439
|
+
"src/worlds/worldNotice.ts"() {
|
|
2440
|
+
"use strict";
|
|
2441
|
+
TOOL_CONTRACT_UNREAD = "tool-contract-unread";
|
|
2442
|
+
DEPRECATION = { label: "deprecated", next: "Instead", refusesRun: false };
|
|
2443
|
+
NOTICE_KINDS = /* @__PURE__ */ new Map([
|
|
2444
|
+
[TOOL_CONTRACT_UNREAD, { label: "warning", next: "Then", refusesRun: true }]
|
|
2445
|
+
]);
|
|
2446
|
+
WorldNotice = class _WorldNotice {
|
|
2447
|
+
constructor(notice, kind) {
|
|
2448
|
+
this.notice = notice;
|
|
2449
|
+
this.kind = kind;
|
|
2450
|
+
}
|
|
2451
|
+
notice;
|
|
2452
|
+
kind;
|
|
2453
|
+
static of(notice) {
|
|
2454
|
+
return new _WorldNotice(notice, NOTICE_KINDS.get(notice.code) ?? DEPRECATION);
|
|
2455
|
+
}
|
|
2456
|
+
get refusesRun() {
|
|
2457
|
+
return this.kind.refusesRun;
|
|
2458
|
+
}
|
|
2459
|
+
line() {
|
|
2460
|
+
const { code, message, replacement } = this.notice;
|
|
2461
|
+
return `${this.kind.label} (${code}): ${message} ${this.kind.next}: ${replacement}`;
|
|
2462
|
+
}
|
|
2463
|
+
};
|
|
2464
|
+
WorldToolsUnread = class _WorldToolsUnread extends Error {
|
|
2465
|
+
constructor(world, notice) {
|
|
2466
|
+
super(
|
|
2467
|
+
`refused before the agent ran, nothing filed: world ${world} has no readable tools: ${notice.notice.message} Then: ${notice.notice.replacement}`
|
|
2468
|
+
);
|
|
2469
|
+
this.world = world;
|
|
2470
|
+
this.notice = notice;
|
|
2471
|
+
this.name = "WorldToolsUnread";
|
|
2472
|
+
this.code = notice.notice.code;
|
|
2473
|
+
}
|
|
2474
|
+
world;
|
|
2475
|
+
notice;
|
|
2476
|
+
code;
|
|
2477
|
+
static refuse(world, notices) {
|
|
2478
|
+
const refusing = notices.map((notice) => WorldNotice.of(notice)).find((notice) => notice.refusesRun);
|
|
2479
|
+
if (refusing) throw new _WorldToolsUnread(world, refusing);
|
|
2480
|
+
}
|
|
2481
|
+
};
|
|
2482
|
+
}
|
|
2483
|
+
});
|
|
2484
|
+
|
|
2485
|
+
// src/worlds/grade.ts
|
|
2486
|
+
var messageOf, Score, GradeRefused, GradePayload;
|
|
2487
|
+
var init_grade = __esm({
|
|
2488
|
+
"src/worlds/grade.ts"() {
|
|
2489
|
+
"use strict";
|
|
2490
|
+
messageOf = (error) => (error instanceof Error ? error.message || error.name : String(error)) || "Error";
|
|
2491
|
+
Score = class _Score {
|
|
2492
|
+
static RULE = "a score is a number from 0 to 1";
|
|
2493
|
+
static admits(value) {
|
|
2494
|
+
return Number.isFinite(value) && value >= 0 && value <= 1;
|
|
2495
|
+
}
|
|
2496
|
+
/** Every number among `scores` that is not a score, as `'<key>' = <value>`
|
|
2497
|
+
* and the rule, or null when all of them are. Pairs, not a map, so that no
|
|
2498
|
+
* key hides another. */
|
|
2499
|
+
static problem(scores2) {
|
|
2500
|
+
const refused = [...scores2].flatMap(
|
|
2501
|
+
([key, value]) => typeof value === "number" && !_Score.admits(value) ? [`'${key}' = ${String(value)}`] : []
|
|
2502
|
+
);
|
|
2503
|
+
return refused.length ? `${refused.join(", ")}; ${_Score.RULE}` : null;
|
|
2504
|
+
}
|
|
2505
|
+
};
|
|
2506
|
+
GradeRefused = class extends Error {
|
|
2507
|
+
name = "GradeRefused";
|
|
2508
|
+
};
|
|
2509
|
+
GradePayload = class _GradePayload {
|
|
2510
|
+
/** A grade payload's numbers, checked: every number in it must be a score,
|
|
2511
|
+
* and its rewards and verifiers objects by name, or the grade is refused; a
|
|
2512
|
+
* cross-world verifier's grade that breaks either rule is that verifier's
|
|
2513
|
+
* error, the way the World Host answers one that could not grade. */
|
|
2514
|
+
static read(raw) {
|
|
2515
|
+
if (!_GradePayload.objectOrAbsent(raw))
|
|
2516
|
+
throw new GradeRefused("the grade is not an object");
|
|
2517
|
+
const record = _GradePayload.record(raw);
|
|
2518
|
+
const problem = _GradePayload.problem(record) ?? _GradePayload.verifiersProblem(record.verifiers);
|
|
2519
|
+
if (problem) throw new GradeRefused(problem);
|
|
2520
|
+
const verifiers = _GradePayload.verifiers(record.verifiers);
|
|
2521
|
+
return {
|
|
2522
|
+
..._GradePayload.numbers(record),
|
|
2523
|
+
...typeof record.reason === "string" ? { reason: record.reason } : {},
|
|
2524
|
+
...typeof record.error === "string" ? { error: record.error } : {},
|
|
2525
|
+
...verifiers ? { verifiers } : {}
|
|
2526
|
+
};
|
|
2527
|
+
}
|
|
2528
|
+
/** A world whose grade call failed (the platform refused it, the host had
|
|
2529
|
+
* lost the session): that world's error, never a score. */
|
|
2530
|
+
static failedCall(error) {
|
|
2531
|
+
return { ..._GradePayload.failed(messageOf(error)), raw: null };
|
|
2532
|
+
}
|
|
2533
|
+
static problem(record) {
|
|
2534
|
+
if (!_GradePayload.objectOrAbsent(record.rewards))
|
|
2535
|
+
return "the grade's rewards are not an object";
|
|
2536
|
+
const scores2 = Score.problem(_GradePayload.scores(record));
|
|
2537
|
+
if (scores2) return `the grade answered ${scores2}`;
|
|
2538
|
+
const twice = _GradePayload.twice(record);
|
|
2539
|
+
return twice.length ? `the grade answered ${twice.map((key) => `'${key}'`).join(", ")} both beside and inside rewards` : null;
|
|
2540
|
+
}
|
|
2541
|
+
static twice(record) {
|
|
2542
|
+
return Object.entries(_GradePayload.record(record.rewards)).filter(
|
|
2543
|
+
([key, value]) => key !== "reward" && typeof value === "number" && typeof record[key] === "number"
|
|
2544
|
+
).map(([key]) => key);
|
|
2545
|
+
}
|
|
2546
|
+
static verifiersProblem(value) {
|
|
2547
|
+
return _GradePayload.objectOrAbsent(value) ? null : "the grade's verifiers are not an object";
|
|
2548
|
+
}
|
|
2549
|
+
static scores(record) {
|
|
2550
|
+
return [
|
|
2551
|
+
["reward", record.reward],
|
|
2552
|
+
...Object.entries(_GradePayload.record(record.rewards)),
|
|
2553
|
+
...Object.entries(record).filter(
|
|
2554
|
+
([key]) => key !== "reward" && key !== "rewards"
|
|
2555
|
+
)
|
|
2556
|
+
];
|
|
2557
|
+
}
|
|
2558
|
+
static isRecord(value) {
|
|
2559
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2560
|
+
}
|
|
2561
|
+
static objectOrAbsent(value) {
|
|
2562
|
+
return value === void 0 || value === null || _GradePayload.isRecord(value);
|
|
2563
|
+
}
|
|
2564
|
+
static record(value) {
|
|
2565
|
+
return _GradePayload.isRecord(value) ? value : {};
|
|
2566
|
+
}
|
|
2567
|
+
/** `reward`, and every numeric key under `rewards` (the host's shape) or at
|
|
2568
|
+
* the top level (a bundled verifier's). */
|
|
2569
|
+
static numbers(record) {
|
|
2570
|
+
const rewards = {};
|
|
2571
|
+
for (const [key, value] of Object.entries(
|
|
2572
|
+
_GradePayload.record(record.rewards)
|
|
2573
|
+
))
|
|
2574
|
+
if (typeof value === "number") rewards[key] = value;
|
|
2575
|
+
for (const [key, value] of Object.entries(record))
|
|
2576
|
+
if (key !== "reward" && typeof value === "number") rewards[key] = value;
|
|
2577
|
+
return {
|
|
2578
|
+
reward: typeof record.reward === "number" ? record.reward : null,
|
|
2579
|
+
rewards
|
|
2580
|
+
};
|
|
2581
|
+
}
|
|
2582
|
+
static verifiers(value) {
|
|
2583
|
+
if (!_GradePayload.isRecord(value)) return void 0;
|
|
2584
|
+
return Object.fromEntries(
|
|
2585
|
+
Object.entries(value).map(([name, grade]) => [
|
|
2586
|
+
name,
|
|
2587
|
+
_GradePayload.verifier(name, grade)
|
|
2588
|
+
])
|
|
2589
|
+
);
|
|
2590
|
+
}
|
|
2591
|
+
static verifier(name, grade) {
|
|
2592
|
+
if (!_GradePayload.isRecord(grade))
|
|
2593
|
+
return _GradePayload.failed(`the grade's verifier '${name}' is not an object`);
|
|
2594
|
+
const problem = _GradePayload.problem(grade);
|
|
2595
|
+
if (problem) return _GradePayload.failed(problem);
|
|
2596
|
+
return {
|
|
2597
|
+
..._GradePayload.numbers(grade),
|
|
2598
|
+
...typeof grade.error === "string" ? { error: grade.error } : {}
|
|
2599
|
+
};
|
|
2600
|
+
}
|
|
2601
|
+
static failed(error) {
|
|
2602
|
+
return { reward: null, rewards: {}, error };
|
|
2603
|
+
}
|
|
2604
|
+
};
|
|
2605
|
+
}
|
|
2606
|
+
});
|
|
2607
|
+
|
|
2302
2608
|
// src/worlds/session.ts
|
|
2303
2609
|
var session_exports2 = {};
|
|
2304
2610
|
__export(session_exports2, {
|
|
2305
2611
|
WorldSession: () => WorldSession,
|
|
2306
2612
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
2613
|
+
WorldSessionOpenFailed: () => WorldSessionOpenFailed,
|
|
2307
2614
|
WorldSessionTimeout: () => WorldSessionTimeout,
|
|
2308
2615
|
attachSession: () => attachSession,
|
|
2309
2616
|
isTaskIdRef: () => isTaskIdRef,
|
|
@@ -2315,34 +2622,6 @@ __export(session_exports2, {
|
|
|
2315
2622
|
taskLabel: () => taskLabel
|
|
2316
2623
|
});
|
|
2317
2624
|
import { randomUUID } from "crypto";
|
|
2318
|
-
function numericGrade(record) {
|
|
2319
|
-
const rewards = {};
|
|
2320
|
-
const nested = record.rewards;
|
|
2321
|
-
if (nested && typeof nested === "object") {
|
|
2322
|
-
for (const [key, value] of Object.entries(nested)) {
|
|
2323
|
-
if (typeof value === "number") rewards[key] = value;
|
|
2324
|
-
}
|
|
2325
|
-
}
|
|
2326
|
-
for (const [key, value] of Object.entries(record)) {
|
|
2327
|
-
if (key !== "reward" && typeof value === "number") rewards[key] = value;
|
|
2328
|
-
}
|
|
2329
|
-
return {
|
|
2330
|
-
reward: typeof record.reward === "number" ? record.reward : null,
|
|
2331
|
-
rewards
|
|
2332
|
-
};
|
|
2333
|
-
}
|
|
2334
|
-
function verifierGrades(value) {
|
|
2335
|
-
if (!value || typeof value !== "object") return void 0;
|
|
2336
|
-
const out = {};
|
|
2337
|
-
for (const [name, grade] of Object.entries(value)) {
|
|
2338
|
-
const record = grade && typeof grade === "object" ? grade : {};
|
|
2339
|
-
out[name] = {
|
|
2340
|
-
...numericGrade(record),
|
|
2341
|
-
...typeof record.error === "string" ? { error: record.error } : {}
|
|
2342
|
-
};
|
|
2343
|
-
}
|
|
2344
|
-
return out;
|
|
2345
|
-
}
|
|
2346
2625
|
function schemaFromSignature(spec) {
|
|
2347
2626
|
if (spec.inputSchema)
|
|
2348
2627
|
return {
|
|
@@ -2450,6 +2729,7 @@ async function runSessions(opts) {
|
|
|
2450
2729
|
const taskRef = tasks[next++];
|
|
2451
2730
|
let task = taskLabel(taskRef);
|
|
2452
2731
|
let session = null;
|
|
2732
|
+
let keepWarm = opts.keepWarm ?? true;
|
|
2453
2733
|
try {
|
|
2454
2734
|
session = await openSession(opts.world, {
|
|
2455
2735
|
task: taskRef,
|
|
@@ -2457,6 +2737,7 @@ async function runSessions(opts) {
|
|
|
2457
2737
|
options
|
|
2458
2738
|
});
|
|
2459
2739
|
task = taskLabel(taskRef, session.taskInfo);
|
|
2740
|
+
WorldToolsUnread.refuse(opts.world.split("@", 1)[0], session.deprecations);
|
|
2460
2741
|
await session.ready();
|
|
2461
2742
|
const toolkit = await session.toolkit();
|
|
2462
2743
|
const live = session;
|
|
@@ -2479,19 +2760,19 @@ async function runSessions(opts) {
|
|
|
2479
2760
|
results.push(result);
|
|
2480
2761
|
opts.onResult?.(result);
|
|
2481
2762
|
} catch (error) {
|
|
2763
|
+
if (error instanceof WorldToolsUnread) keepWarm = false;
|
|
2482
2764
|
const result = {
|
|
2483
2765
|
task,
|
|
2484
2766
|
sessionId: session?.sessionId ?? "",
|
|
2485
2767
|
reward: 0,
|
|
2486
2768
|
rewards: {},
|
|
2487
|
-
// An
|
|
2488
|
-
// caller checking truthiness; name the type instead.
|
|
2769
|
+
// An empty message reads as "no error" to a truthiness check; name the type instead.
|
|
2489
2770
|
error: (error instanceof Error ? error.message : String(error)) || (error instanceof Error ? error.name : "Unknown error")
|
|
2490
2771
|
};
|
|
2491
2772
|
results.push(result);
|
|
2492
2773
|
opts.onResult?.(result);
|
|
2493
2774
|
} finally {
|
|
2494
|
-
await session?.close({ keepWarm
|
|
2775
|
+
await session?.close({ keepWarm }).catch(() => void 0);
|
|
2495
2776
|
}
|
|
2496
2777
|
}
|
|
2497
2778
|
})
|
|
@@ -2505,7 +2786,7 @@ async function runSessions(opts) {
|
|
|
2505
2786
|
passed: failed === 0 && (opts.failUnder === void 0 || mean >= opts.failUnder)
|
|
2506
2787
|
};
|
|
2507
2788
|
}
|
|
2508
|
-
var
|
|
2789
|
+
var CALL_TIMEOUT_MS, CALL_POLL_MS, JUDGED_GRADE_TIMEOUT_MS, JUDGED_GRADE_POLL_MS, EXPORT_PAGE, sleep3, modelToolName, WorldSession, OPEN_SESSION_OPTION_KEYS, isOpenSessionOptions;
|
|
2509
2790
|
var init_session2 = __esm({
|
|
2510
2791
|
"src/worlds/session.ts"() {
|
|
2511
2792
|
"use strict";
|
|
@@ -2513,22 +2794,20 @@ var init_session2 = __esm({
|
|
|
2513
2794
|
init_browser();
|
|
2514
2795
|
init_nativeComputer();
|
|
2515
2796
|
init_sessionContract();
|
|
2797
|
+
init_sessionReadiness();
|
|
2516
2798
|
init_session();
|
|
2517
2799
|
init_taskRef();
|
|
2800
|
+
init_worldNotice();
|
|
2801
|
+
init_grade();
|
|
2518
2802
|
init_taskRef();
|
|
2519
|
-
|
|
2520
|
-
READY_POLL_MS = 2e3;
|
|
2803
|
+
init_sessionReadiness();
|
|
2521
2804
|
CALL_TIMEOUT_MS = 3 * 6e4;
|
|
2522
2805
|
CALL_POLL_MS = 400;
|
|
2523
2806
|
JUDGED_GRADE_TIMEOUT_MS = 15 * 6e4;
|
|
2524
2807
|
JUDGED_GRADE_POLL_MS = 2e3;
|
|
2525
2808
|
EXPORT_PAGE = 500;
|
|
2526
|
-
|
|
2809
|
+
sleep3 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
2527
2810
|
modelToolName = (name) => name.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 64) || "tool";
|
|
2528
|
-
WorldSessionTimeout = class extends Error {
|
|
2529
|
-
};
|
|
2530
|
-
WorldSessionCallError = class extends Error {
|
|
2531
|
-
};
|
|
2532
2811
|
WorldSession = class {
|
|
2533
2812
|
constructor(sessionId, current, options) {
|
|
2534
2813
|
this.sessionId = sessionId;
|
|
@@ -2646,18 +2925,17 @@ var init_session2 = __esm({
|
|
|
2646
2925
|
}
|
|
2647
2926
|
/** The reporter `browser()` uses; exposed for a page you drive yourself. */
|
|
2648
2927
|
browserRecorder(agentId) {
|
|
2649
|
-
const
|
|
2928
|
+
const path13 = `/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/browser-events`;
|
|
2650
2929
|
const id = agentId ?? process.env.GATEWAY_AGENT_ID ?? `agent-${randomUUID().replace(/-/g, "").slice(0, 8)}`;
|
|
2651
2930
|
return new BrowserActionRecorder(
|
|
2652
2931
|
async (events) => {
|
|
2653
|
-
await apiRequest(this.options, "POST",
|
|
2932
|
+
await apiRequest(this.options, "POST", path13, { events });
|
|
2654
2933
|
},
|
|
2655
2934
|
id,
|
|
2656
2935
|
{
|
|
2657
|
-
// Continue this agent's timeline where the platform has it, so
|
|
2658
|
-
// same id reopened later never re-numbers from zero.
|
|
2936
|
+
// Continue this agent's timeline where the platform has it, so a reopened id never re-numbers from zero.
|
|
2659
2937
|
resumeFrom: async () => {
|
|
2660
|
-
const summary = await apiRequest(this.options, "GET",
|
|
2938
|
+
const summary = await apiRequest(this.options, "GET", path13);
|
|
2661
2939
|
return summary.agents.find((a) => a.agentId === id)?.nextSeq ?? 0;
|
|
2662
2940
|
}
|
|
2663
2941
|
}
|
|
@@ -2685,29 +2963,22 @@ var init_session2 = __esm({
|
|
|
2685
2963
|
tools: this.current.tools,
|
|
2686
2964
|
surfaces: this.current.surfaces,
|
|
2687
2965
|
task: this.current.task,
|
|
2966
|
+
deprecations: this.current.deprecations,
|
|
2688
2967
|
...fresh
|
|
2689
2968
|
};
|
|
2690
2969
|
return this.current;
|
|
2691
2970
|
}
|
|
2692
2971
|
/**
|
|
2693
|
-
* Wait until the
|
|
2694
|
-
* asked the platform for work
|
|
2972
|
+
* Wait until the session answers calls: a World Host holds it, or the
|
|
2973
|
+
* process inside a pod has asked the platform for work. Throws
|
|
2974
|
+
* `WorldSessionOpenFailed` (with the platform's reason) when it ended
|
|
2975
|
+
* first, and `WorldSessionTimeout` when `timeoutMs` (default ten minutes)
|
|
2976
|
+
* ran out while it was still starting.
|
|
2695
2977
|
*/
|
|
2696
2978
|
async ready(opts = {}) {
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
if (state2.ready) return state2;
|
|
2701
|
-
if (state2.state === "FAILED" || state2.state === "STOPPED")
|
|
2702
|
-
throw new WorldSessionCallError(
|
|
2703
|
-
`World session ${state2.state.toLowerCase()} before it was ready.`
|
|
2704
|
-
);
|
|
2705
|
-
if (Date.now() > deadline)
|
|
2706
|
-
throw new WorldSessionTimeout(
|
|
2707
|
-
`World session still ${state2.state} after ${Math.round((opts.timeoutMs ?? READY_TIMEOUT_MS) / 1e3)}s.`
|
|
2708
|
-
);
|
|
2709
|
-
await sleep(READY_POLL_MS);
|
|
2710
|
-
}
|
|
2979
|
+
return new SessionReadiness(this.sessionId, () => this.status()).wait(
|
|
2980
|
+
opts.timeoutMs
|
|
2981
|
+
);
|
|
2711
2982
|
}
|
|
2712
2983
|
/** Enqueue one interaction and wait for the container's answer. */
|
|
2713
2984
|
async exchange(body, timeoutMs) {
|
|
@@ -2737,7 +3008,7 @@ var init_session2 = __esm({
|
|
|
2737
3008
|
throw new WorldSessionTimeout(
|
|
2738
3009
|
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.`
|
|
2739
3010
|
);
|
|
2740
|
-
await
|
|
3011
|
+
await sleep3(pollMs2);
|
|
2741
3012
|
}
|
|
2742
3013
|
}
|
|
2743
3014
|
/**
|
|
@@ -2786,7 +3057,9 @@ var init_session2 = __esm({
|
|
|
2786
3057
|
* calls); assertions and python graders ignore it. `worlds` names the
|
|
2787
3058
|
* task's other sessions by alias (`{alias: sessionId}`): the platform
|
|
2788
3059
|
* reads each one's evidence and hands it to the cross-world verifiers
|
|
2789
|
-
* anchored on this session, whose grades come back under `verifiers`.
|
|
3060
|
+
* anchored on this session, whose grades come back under `verifiers`. A
|
|
3061
|
+
* score that is not a number from 0 to 1 is refused by key and value
|
|
3062
|
+
* (`GradeRefused`); a verifier's is that verifier's `error`. */
|
|
2790
3063
|
async grade(opts = {}) {
|
|
2791
3064
|
const raw = await this.exchange(
|
|
2792
3065
|
{
|
|
@@ -2796,14 +3069,7 @@ var init_session2 = __esm({
|
|
|
2796
3069
|
},
|
|
2797
3070
|
opts.timeoutMs
|
|
2798
3071
|
);
|
|
2799
|
-
|
|
2800
|
-
const verifiers = verifierGrades(record.verifiers);
|
|
2801
|
-
return {
|
|
2802
|
-
...numericGrade(record),
|
|
2803
|
-
...typeof record.reason === "string" ? { reason: record.reason } : {},
|
|
2804
|
-
...verifiers ? { verifiers } : {},
|
|
2805
|
-
raw
|
|
2806
|
-
};
|
|
3072
|
+
return { ...GradePayload.read(raw), raw };
|
|
2807
3073
|
}
|
|
2808
3074
|
/**
|
|
2809
3075
|
* Put rows into the LIVE world through its contract, in one batch:
|
|
@@ -3043,28 +3309,52 @@ var init_tasks = __esm({
|
|
|
3043
3309
|
}
|
|
3044
3310
|
});
|
|
3045
3311
|
|
|
3312
|
+
// src/worlds/surfaceDescriptor.ts
|
|
3313
|
+
function surfaceDescriptor(s) {
|
|
3314
|
+
return {
|
|
3315
|
+
surfaces: surfaceKinds(s),
|
|
3316
|
+
...s.api ? { api: { url: s.api.url, ...s.api.token ? { token: s.api.token } : {} } } : {},
|
|
3317
|
+
...s.ui ? { ui: { url: s.ui.url, entry: uiEntryUrl(s.ui), apiPath: s.ui.apiPath ?? null } } : {},
|
|
3318
|
+
...s.browser ? {
|
|
3319
|
+
browser: {
|
|
3320
|
+
wsUrl: s.browser.wsUrl,
|
|
3321
|
+
viewport: s.browser.viewport,
|
|
3322
|
+
...s.browser.tier ? { tier: s.browser.tier } : {}
|
|
3323
|
+
}
|
|
3324
|
+
} : {}
|
|
3325
|
+
};
|
|
3326
|
+
}
|
|
3327
|
+
var init_surfaceDescriptor = __esm({
|
|
3328
|
+
"src/worlds/surfaceDescriptor.ts"() {
|
|
3329
|
+
"use strict";
|
|
3330
|
+
init_browser();
|
|
3331
|
+
}
|
|
3332
|
+
});
|
|
3333
|
+
|
|
3046
3334
|
// src/worlds/taskSessions.ts
|
|
3047
3335
|
function aggregateTaskGrade(worlds) {
|
|
3048
|
-
const
|
|
3049
|
-
const ungraded = [];
|
|
3050
|
-
const graded = [];
|
|
3336
|
+
const fold = new TaskGradeFold();
|
|
3051
3337
|
const verifiers = {};
|
|
3052
|
-
const fold = (key, grade) => {
|
|
3053
|
-
if (typeof grade.reward === "number") {
|
|
3054
|
-
rewards[key] = grade.reward;
|
|
3055
|
-
graded.push(grade.reward);
|
|
3056
|
-
} else ungraded.push(key);
|
|
3057
|
-
for (const [name, value] of Object.entries(grade.rewards))
|
|
3058
|
-
rewards[`${key}.${name}`] = value;
|
|
3059
|
-
};
|
|
3060
3338
|
for (const [alias, grade] of Object.entries(worlds)) {
|
|
3061
|
-
fold(alias, grade);
|
|
3339
|
+
fold.add(alias, grade, `world ${alias}`);
|
|
3062
3340
|
Object.assign(verifiers, grade.verifiers ?? {});
|
|
3063
3341
|
}
|
|
3064
3342
|
for (const [name, grade] of Object.entries(verifiers))
|
|
3065
|
-
fold(`${VERIFIER_REWARD_PREFIX}${name}`, grade);
|
|
3066
|
-
|
|
3067
|
-
|
|
3343
|
+
fold.add(`${VERIFIER_REWARD_PREFIX}${name}`, grade, `verifier ${name}`);
|
|
3344
|
+
return {
|
|
3345
|
+
reward: fold.reward(),
|
|
3346
|
+
rewards: fold.rewards,
|
|
3347
|
+
worlds,
|
|
3348
|
+
ungraded: fold.ungraded,
|
|
3349
|
+
verifiers,
|
|
3350
|
+
errors: fold.errors
|
|
3351
|
+
};
|
|
3352
|
+
}
|
|
3353
|
+
function taskGradeError(grade) {
|
|
3354
|
+
const lines = Object.entries(grade.errors).map(
|
|
3355
|
+
([key, why]) => `${key}: ${why}`
|
|
3356
|
+
);
|
|
3357
|
+
return lines.length ? lines.join("; ") : null;
|
|
3068
3358
|
}
|
|
3069
3359
|
function fromResponse(answer, options) {
|
|
3070
3360
|
const sessions = {};
|
|
@@ -3187,12 +3477,14 @@ async function attachManifest(manifest, options = {}) {
|
|
|
3187
3477
|
function isTaskManifest(value) {
|
|
3188
3478
|
return typeof value === "object" && value !== null && !Array.isArray(value) && typeof value.sessions === "object" && value.sessions !== null && !("instruction" in value && "worlds" in value);
|
|
3189
3479
|
}
|
|
3190
|
-
var TASK_SESSIONS, VERIFIER_REWARD_PREFIX, manifestSession, TaskSessions;
|
|
3480
|
+
var TASK_SESSIONS, VERIFIER_REWARD_PREFIX, manifestSession, TaskGradeFold, TaskSessions;
|
|
3191
3481
|
var init_taskSessions = __esm({
|
|
3192
3482
|
"src/worlds/taskSessions.ts"() {
|
|
3193
3483
|
"use strict";
|
|
3194
3484
|
init_worlds();
|
|
3195
3485
|
init_browser();
|
|
3486
|
+
init_grade();
|
|
3487
|
+
init_surfaceDescriptor();
|
|
3196
3488
|
init_session2();
|
|
3197
3489
|
TASK_SESSIONS = "/api/public/world-task-sessions";
|
|
3198
3490
|
VERIFIER_REWARD_PREFIX = "x.";
|
|
@@ -3204,19 +3496,38 @@ var init_taskSessions = __esm({
|
|
|
3204
3496
|
sessionId: state2.sessionId,
|
|
3205
3497
|
ready: state2.ready,
|
|
3206
3498
|
state: state2.state,
|
|
3207
|
-
|
|
3208
|
-
...s.api ? {
|
|
3209
|
-
api: { url: s.api.url, ...s.api.token ? { token: s.api.token } : {} }
|
|
3210
|
-
} : {},
|
|
3211
|
-
...s.ui ? {
|
|
3212
|
-
ui: {
|
|
3213
|
-
url: s.ui.url,
|
|
3214
|
-
entry: uiEntryUrl(s.ui),
|
|
3215
|
-
apiPath: s.ui.apiPath ?? null
|
|
3216
|
-
}
|
|
3217
|
-
} : {},
|
|
3218
|
-
...s.browser ? { browser: { wsUrl: s.browser.wsUrl, viewport: s.browser.viewport } } : {}
|
|
3499
|
+
...surfaceDescriptor(s)
|
|
3219
3500
|
});
|
|
3501
|
+
TaskGradeFold = class {
|
|
3502
|
+
rewards = {};
|
|
3503
|
+
ungraded = [];
|
|
3504
|
+
errors = {};
|
|
3505
|
+
sources = /* @__PURE__ */ new Map();
|
|
3506
|
+
graded = [];
|
|
3507
|
+
add(key, grade, source) {
|
|
3508
|
+
if (grade.error) this.errors[key] = grade.error;
|
|
3509
|
+
if (typeof grade.reward === "number") {
|
|
3510
|
+
this.put(key, grade.reward, source);
|
|
3511
|
+
this.graded.push(grade.reward);
|
|
3512
|
+
} else this.ungraded.push(key);
|
|
3513
|
+
for (const [name, value] of Object.entries(grade.rewards))
|
|
3514
|
+
this.put(`${key}.${name}`, value, source);
|
|
3515
|
+
}
|
|
3516
|
+
reward() {
|
|
3517
|
+
if (Object.keys(this.errors).length > 0 || !this.graded.length)
|
|
3518
|
+
return null;
|
|
3519
|
+
return this.graded.reduce((a, b) => a + b, 0) / this.graded.length;
|
|
3520
|
+
}
|
|
3521
|
+
put(key, value, source) {
|
|
3522
|
+
const first = this.sources.get(key) ?? source;
|
|
3523
|
+
this.sources.set(key, first);
|
|
3524
|
+
if (first !== source) {
|
|
3525
|
+
this.errors[key] = `two rewards are named ${key} (${first} and ${source}); rename one of them`;
|
|
3526
|
+
return;
|
|
3527
|
+
}
|
|
3528
|
+
this.rewards[key] = value;
|
|
3529
|
+
}
|
|
3530
|
+
};
|
|
3220
3531
|
TaskSessions = class {
|
|
3221
3532
|
constructor(taskId, taskVersion, name, instruction, sessions, worlds, hash = null) {
|
|
3222
3533
|
this.taskId = taskId;
|
|
@@ -3295,11 +3606,13 @@ var init_taskSessions = __esm({
|
|
|
3295
3606
|
* agent's own account of the whole investigation) goes to every world's
|
|
3296
3607
|
* judge; a world graded by assertions or python ignores it. Each grade
|
|
3297
3608
|
* names the task's other sessions by alias, so the cross-world verifiers
|
|
3298
|
-
* anchored on that world can read them.
|
|
3609
|
+
* anchored on that world can read them. A world whose grade call fails is
|
|
3610
|
+
* that world's error: the task's grade names it and keeps every other
|
|
3611
|
+
* world's grade. */
|
|
3299
3612
|
async grade(opts = {}) {
|
|
3300
3613
|
return aggregateTaskGrade(
|
|
3301
3614
|
await this.each(
|
|
3302
|
-
(session, alias) => session.grade({ ...opts, worlds: this.otherSessions(alias) })
|
|
3615
|
+
(session, alias) => session.grade({ ...opts, worlds: this.otherSessions(alias) }).catch((error) => GradePayload.failedCall(error))
|
|
3303
3616
|
)
|
|
3304
3617
|
);
|
|
3305
3618
|
}
|
|
@@ -3347,12 +3660,16 @@ var init_evals = __esm({
|
|
|
3347
3660
|
"src/worlds/evals.ts"() {
|
|
3348
3661
|
"use strict";
|
|
3349
3662
|
init_worlds();
|
|
3663
|
+
init_transport();
|
|
3350
3664
|
EVALUATIONS = "/api/public/benchmark-containers/evaluations";
|
|
3351
3665
|
GatewayEvalsClient = class {
|
|
3352
|
-
constructor(options = {}) {
|
|
3666
|
+
constructor(options = {}, retry = RetryPolicy.FILING) {
|
|
3353
3667
|
this.options = options;
|
|
3668
|
+
this.retry = retry;
|
|
3354
3669
|
}
|
|
3355
3670
|
options;
|
|
3671
|
+
retry;
|
|
3672
|
+
keyed = /* @__PURE__ */ new Set();
|
|
3356
3673
|
async createEvaluation(versionId, opts = {}) {
|
|
3357
3674
|
const body = { versionId };
|
|
3358
3675
|
if (opts.model !== void 0) body.model = opts.model;
|
|
@@ -3360,12 +3677,18 @@ var init_evals = __esm({
|
|
|
3360
3677
|
if (opts.rolloutsPerExample !== void 0)
|
|
3361
3678
|
body.rolloutsPerExample = opts.rolloutsPerExample;
|
|
3362
3679
|
if (opts.metadata !== void 0) body.metadata = opts.metadata;
|
|
3680
|
+
if (opts.idempotencyKey !== void 0)
|
|
3681
|
+
body.idempotencyKey = opts.idempotencyKey;
|
|
3363
3682
|
const answer = await apiRequest(
|
|
3364
3683
|
this.options,
|
|
3365
3684
|
"POST",
|
|
3366
3685
|
EVALUATIONS,
|
|
3367
|
-
body
|
|
3686
|
+
body,
|
|
3687
|
+
{
|
|
3688
|
+
retry: opts.idempotencyKey === void 0 ? RetryPolicy.NONE : this.retry
|
|
3689
|
+
}
|
|
3368
3690
|
);
|
|
3691
|
+
if (opts.idempotencyKey !== void 0) this.keyed.add(answer.evaluationId);
|
|
3369
3692
|
return answer.evaluationId;
|
|
3370
3693
|
}
|
|
3371
3694
|
async pushSamples(evaluationId, samples) {
|
|
@@ -3373,7 +3696,8 @@ var init_evals = __esm({
|
|
|
3373
3696
|
this.options,
|
|
3374
3697
|
"POST",
|
|
3375
3698
|
`${EVALUATIONS}/${encodeURIComponent(evaluationId)}/samples`,
|
|
3376
|
-
{ samples }
|
|
3699
|
+
{ samples },
|
|
3700
|
+
{ retry: this.retryFor(evaluationId) }
|
|
3377
3701
|
);
|
|
3378
3702
|
return answer.inserted ?? samples.length;
|
|
3379
3703
|
}
|
|
@@ -3386,10 +3710,347 @@ var init_evals = __esm({
|
|
|
3386
3710
|
this.options,
|
|
3387
3711
|
"POST",
|
|
3388
3712
|
`${EVALUATIONS}/${encodeURIComponent(evaluationId)}/finalize`,
|
|
3389
|
-
body
|
|
3713
|
+
body,
|
|
3714
|
+
{ retry: this.retryFor(evaluationId) }
|
|
3390
3715
|
);
|
|
3391
3716
|
return answer.status;
|
|
3392
3717
|
}
|
|
3718
|
+
retryFor(evaluationId) {
|
|
3719
|
+
return this.keyed.has(evaluationId) ? this.retry : RetryPolicy.NONE;
|
|
3720
|
+
}
|
|
3721
|
+
};
|
|
3722
|
+
}
|
|
3723
|
+
});
|
|
3724
|
+
|
|
3725
|
+
// src/worlds/runSignals.ts
|
|
3726
|
+
import { constants } from "os";
|
|
3727
|
+
var OWNER, RunSignals;
|
|
3728
|
+
var init_runSignals = __esm({
|
|
3729
|
+
"src/worlds/runSignals.ts"() {
|
|
3730
|
+
"use strict";
|
|
3731
|
+
OWNER = /* @__PURE__ */ Symbol("RunSignals");
|
|
3732
|
+
RunSignals = class _RunSignals {
|
|
3733
|
+
constructor(target = process) {
|
|
3734
|
+
this.target = target;
|
|
3735
|
+
}
|
|
3736
|
+
target;
|
|
3737
|
+
static SIGNALS = ["SIGINT", "SIGTERM"];
|
|
3738
|
+
cleanups = [];
|
|
3739
|
+
heardSignal = null;
|
|
3740
|
+
heardCount = 0;
|
|
3741
|
+
listening = false;
|
|
3742
|
+
left = false;
|
|
3743
|
+
listener = Object.assign(
|
|
3744
|
+
(signal) => this.heard(signal),
|
|
3745
|
+
{ [OWNER]: this }
|
|
3746
|
+
);
|
|
3747
|
+
/** The signal that arrived, once one has: start nothing new. */
|
|
3748
|
+
get signal() {
|
|
3749
|
+
return this.owner().heardSignal;
|
|
3750
|
+
}
|
|
3751
|
+
async during(cleanup, work) {
|
|
3752
|
+
return this.owner().hold(cleanup, work);
|
|
3753
|
+
}
|
|
3754
|
+
owner() {
|
|
3755
|
+
const owners = this.target.listeners("SIGINT").map((listener) => listener[OWNER]);
|
|
3756
|
+
return owners.find((owner) => owner !== void 0) ?? this;
|
|
3757
|
+
}
|
|
3758
|
+
async hold(cleanup, work) {
|
|
3759
|
+
this.listen();
|
|
3760
|
+
this.cleanups.push(cleanup);
|
|
3761
|
+
try {
|
|
3762
|
+
return await work();
|
|
3763
|
+
} finally {
|
|
3764
|
+
this.cleanups.splice(this.cleanups.indexOf(cleanup), 1);
|
|
3765
|
+
if (!this.cleanups.length && this.heardSignal === null) this.unlisten();
|
|
3766
|
+
}
|
|
3767
|
+
}
|
|
3768
|
+
heard(signal) {
|
|
3769
|
+
this.heardCount += 1;
|
|
3770
|
+
if (this.heardCount > 2) return this.leave(signal);
|
|
3771
|
+
this.heardSignal ??= signal;
|
|
3772
|
+
void this.cleanUp(signal, this.heardCount === 2).finally(() => this.leave(signal));
|
|
3773
|
+
}
|
|
3774
|
+
async cleanUp(signal, urgent) {
|
|
3775
|
+
for (const cleanup of [...this.cleanups].reverse())
|
|
3776
|
+
await Promise.resolve().then(() => cleanup(signal, urgent)).catch(() => void 0);
|
|
3777
|
+
}
|
|
3778
|
+
leave(signal) {
|
|
3779
|
+
if (this.left) return;
|
|
3780
|
+
this.left = true;
|
|
3781
|
+
this.unlisten();
|
|
3782
|
+
if (this.target.listenerCount(signal) === 0)
|
|
3783
|
+
this.target.exit(128 + constants.signals[signal]);
|
|
3784
|
+
}
|
|
3785
|
+
listen() {
|
|
3786
|
+
if (this.listening) return;
|
|
3787
|
+
this.listening = true;
|
|
3788
|
+
for (const signal of _RunSignals.SIGNALS)
|
|
3789
|
+
this.target.on(signal, this.listener);
|
|
3790
|
+
}
|
|
3791
|
+
unlisten() {
|
|
3792
|
+
this.listening = false;
|
|
3793
|
+
for (const signal of _RunSignals.SIGNALS)
|
|
3794
|
+
this.target.off(signal, this.listener);
|
|
3795
|
+
}
|
|
3796
|
+
};
|
|
3797
|
+
}
|
|
3798
|
+
});
|
|
3799
|
+
|
|
3800
|
+
// src/worlds/taskRunDir.ts
|
|
3801
|
+
import * as fs from "fs";
|
|
3802
|
+
import * as path from "path";
|
|
3803
|
+
function sessionRecord({ api: api2, ui, browser, ...session }) {
|
|
3804
|
+
return {
|
|
3805
|
+
...session,
|
|
3806
|
+
...api2 ? { api: { url: api2.url } } : {},
|
|
3807
|
+
...ui ? { ui: { ...ui, entry: withoutUiToken(ui.entry) } } : {},
|
|
3808
|
+
...browser ? { browser: browserRecord(browser) } : {}
|
|
3809
|
+
};
|
|
3810
|
+
}
|
|
3811
|
+
var TaskRunDir, browserRecord;
|
|
3812
|
+
var init_taskRunDir = __esm({
|
|
3813
|
+
"src/worlds/taskRunDir.ts"() {
|
|
3814
|
+
"use strict";
|
|
3815
|
+
init_browser();
|
|
3816
|
+
TaskRunDir = class {
|
|
3817
|
+
constructor(path13) {
|
|
3818
|
+
this.path = path13;
|
|
3819
|
+
}
|
|
3820
|
+
path;
|
|
3821
|
+
writeManifest(manifest) {
|
|
3822
|
+
this.writeJson("manifest.json", {
|
|
3823
|
+
...manifest,
|
|
3824
|
+
sessions: Object.fromEntries(
|
|
3825
|
+
Object.entries(manifest.sessions).map(([alias, session]) => [
|
|
3826
|
+
alias,
|
|
3827
|
+
sessionRecord(session)
|
|
3828
|
+
])
|
|
3829
|
+
)
|
|
3830
|
+
});
|
|
3831
|
+
}
|
|
3832
|
+
writeJson(name, value) {
|
|
3833
|
+
this.write(name, JSON.stringify(value, null, 2));
|
|
3834
|
+
}
|
|
3835
|
+
write(name, text2) {
|
|
3836
|
+
fs.mkdirSync(this.path, { recursive: true });
|
|
3837
|
+
fs.writeFileSync(path.join(this.path, name), text2);
|
|
3838
|
+
}
|
|
3839
|
+
};
|
|
3840
|
+
browserRecord = ({ viewport, tier }) => ({
|
|
3841
|
+
viewport,
|
|
3842
|
+
...tier ? { tier } : {}
|
|
3843
|
+
});
|
|
3844
|
+
}
|
|
3845
|
+
});
|
|
3846
|
+
|
|
3847
|
+
// src/worlds/taskRunOutcome.ts
|
|
3848
|
+
var TaskRunOutcome;
|
|
3849
|
+
var init_taskRunOutcome = __esm({
|
|
3850
|
+
"src/worlds/taskRunOutcome.ts"() {
|
|
3851
|
+
"use strict";
|
|
3852
|
+
init_grade();
|
|
3853
|
+
init_taskSessions();
|
|
3854
|
+
TaskRunOutcome = class {
|
|
3855
|
+
constructor(runId, live, model, runDir) {
|
|
3856
|
+
this.runId = runId;
|
|
3857
|
+
this.live = live;
|
|
3858
|
+
this.model = model;
|
|
3859
|
+
this.runDir = runDir;
|
|
3860
|
+
}
|
|
3861
|
+
runId;
|
|
3862
|
+
live;
|
|
3863
|
+
model;
|
|
3864
|
+
runDir;
|
|
3865
|
+
report = null;
|
|
3866
|
+
extra = {};
|
|
3867
|
+
notes = {};
|
|
3868
|
+
agentError = null;
|
|
3869
|
+
grade = null;
|
|
3870
|
+
traced = false;
|
|
3871
|
+
runError = null;
|
|
3872
|
+
fileError = null;
|
|
3873
|
+
evaluationId;
|
|
3874
|
+
evaluationStatus = null;
|
|
3875
|
+
started = Date.now();
|
|
3876
|
+
/** The run stopped short of a grade; the first reason stands. */
|
|
3877
|
+
stopped(error) {
|
|
3878
|
+
this.runError ??= messageOf(error).slice(0, 2e3);
|
|
3879
|
+
}
|
|
3880
|
+
agentRaised(error) {
|
|
3881
|
+
this.agentError = messageOf(error).slice(0, 2e3);
|
|
3882
|
+
}
|
|
3883
|
+
/** Every reason the run failed, on one line: the evaluation's
|
|
3884
|
+
* `metrics.error`. A run that never reached a grade has failed whatever
|
|
3885
|
+
* its reasons say. */
|
|
3886
|
+
failure() {
|
|
3887
|
+
const reasons = [
|
|
3888
|
+
this.agentError === null ? null : `agent raised: ${this.agentError}`,
|
|
3889
|
+
this.runError === null ? null : `the run stopped: ${this.runError}`,
|
|
3890
|
+
this.gradeError(),
|
|
3891
|
+
this.grade === null && this.runError === null ? "the run stopped before it was graded" : null
|
|
3892
|
+
].filter((reason) => reason !== null);
|
|
3893
|
+
return reasons.length ? reasons.join("; ") : null;
|
|
3894
|
+
}
|
|
3895
|
+
async file(evals, setRunId) {
|
|
3896
|
+
let created;
|
|
3897
|
+
try {
|
|
3898
|
+
created = await evals.createEvaluation(this.ref(this.live.aliases[0]).versionId, {
|
|
3899
|
+
model: this.model,
|
|
3900
|
+
rolloutsPerExample: 1,
|
|
3901
|
+
idempotencyKey: this.runId,
|
|
3902
|
+
...setRunId ? { runId: setRunId } : {},
|
|
3903
|
+
metadata: this.metadata()
|
|
3904
|
+
});
|
|
3905
|
+
await evals.pushSamples(created, [this.sample()]);
|
|
3906
|
+
this.evaluationStatus = await evals.finalizeEvaluation(created, this.finalized());
|
|
3907
|
+
this.evaluationId = created;
|
|
3908
|
+
} catch (error) {
|
|
3909
|
+
this.fileError = created ? `evaluation ${created}: ${messageOf(error)}` : messageOf(error);
|
|
3910
|
+
if (created)
|
|
3911
|
+
await evals.finalizeEvaluation(created, { status: "FAILED", metrics: { error: this.fileError } }).catch(() => void 0);
|
|
3912
|
+
}
|
|
3913
|
+
}
|
|
3914
|
+
summary() {
|
|
3915
|
+
const live = this.live;
|
|
3916
|
+
const { evaluationId: _agentEvaluationId, ...extra } = this.extra;
|
|
3917
|
+
return {
|
|
3918
|
+
...extra,
|
|
3919
|
+
runId: this.runId,
|
|
3920
|
+
taskId: live.taskId,
|
|
3921
|
+
taskVersion: live.taskVersion,
|
|
3922
|
+
name: live.name,
|
|
3923
|
+
instruction: live.instruction ?? "",
|
|
3924
|
+
model: this.model,
|
|
3925
|
+
aliases: live.aliases,
|
|
3926
|
+
reward: this.grade?.reward ?? null,
|
|
3927
|
+
rewards: this.grade?.rewards ?? {},
|
|
3928
|
+
ungraded: this.grade?.ungraded ?? live.aliases,
|
|
3929
|
+
agentError: this.agentError,
|
|
3930
|
+
runError: this.runError,
|
|
3931
|
+
gradeError: this.gradeError(),
|
|
3932
|
+
fileError: this.fileError,
|
|
3933
|
+
evaluationStatus: this.evaluationStatus,
|
|
3934
|
+
report: this.report,
|
|
3935
|
+
traced: this.traced,
|
|
3936
|
+
runDir: this.runDir,
|
|
3937
|
+
durationSeconds: Math.round((Date.now() - this.started) / 10) / 100,
|
|
3938
|
+
notes: this.notes,
|
|
3939
|
+
filed: this.evaluationId !== void 0,
|
|
3940
|
+
...this.evaluationId ? { evaluationId: this.evaluationId } : {}
|
|
3941
|
+
};
|
|
3942
|
+
}
|
|
3943
|
+
gradeError() {
|
|
3944
|
+
return this.grade ? taskGradeError(this.grade) : null;
|
|
3945
|
+
}
|
|
3946
|
+
ref(alias) {
|
|
3947
|
+
const { slug, ref } = this.live.worldRef(alias);
|
|
3948
|
+
const session = this.live.sessions[alias];
|
|
3949
|
+
return { slug, ref, versionId: session.versionId, sessionId: session.sessionId };
|
|
3950
|
+
}
|
|
3951
|
+
metadata() {
|
|
3952
|
+
const live = this.live;
|
|
3953
|
+
return {
|
|
3954
|
+
source: "worlds-task-run",
|
|
3955
|
+
task: { id: live.taskId, version: live.taskVersion, name: live.name, hash: live.hash },
|
|
3956
|
+
anchor: live.aliases[0],
|
|
3957
|
+
worlds: Object.fromEntries(live.aliases.map((alias) => [alias, this.ref(alias)])),
|
|
3958
|
+
runId: this.runId
|
|
3959
|
+
};
|
|
3960
|
+
}
|
|
3961
|
+
sample() {
|
|
3962
|
+
const live = this.live;
|
|
3963
|
+
const reward = this.grade?.reward ?? null;
|
|
3964
|
+
const gradeError = this.gradeError();
|
|
3965
|
+
const sample = {
|
|
3966
|
+
exampleId: live.name ?? live.taskId ?? this.runId,
|
|
3967
|
+
task: live.name ?? live.taskId ?? this.runId,
|
|
3968
|
+
rolloutIndex: 0,
|
|
3969
|
+
prompt: live.instruction,
|
|
3970
|
+
...this.report === null ? {} : { completion: this.report },
|
|
3971
|
+
rewards: this.grade?.rewards ?? {},
|
|
3972
|
+
info: {
|
|
3973
|
+
sessionId: this.runId,
|
|
3974
|
+
worlds: Object.fromEntries(
|
|
3975
|
+
live.aliases.map((alias) => [
|
|
3976
|
+
alias,
|
|
3977
|
+
{ ...this.ref(alias), reward: this.grade?.worlds[alias]?.reward ?? null }
|
|
3978
|
+
])
|
|
3979
|
+
),
|
|
3980
|
+
ungraded: this.grade?.ungraded ?? live.aliases,
|
|
3981
|
+
traced: this.traced,
|
|
3982
|
+
runDir: this.runDir,
|
|
3983
|
+
...this.agentError ? { agentError: this.agentError } : {},
|
|
3984
|
+
...this.runError ? { runError: this.runError } : {},
|
|
3985
|
+
...gradeError ? { verifyError: gradeError } : {}
|
|
3986
|
+
}
|
|
3987
|
+
};
|
|
3988
|
+
if (typeof reward === "number")
|
|
3989
|
+
Object.assign(sample, { reward, score: reward, correct: reward >= 1 });
|
|
3990
|
+
return sample;
|
|
3991
|
+
}
|
|
3992
|
+
finalized() {
|
|
3993
|
+
const reward = this.grade?.reward ?? null;
|
|
3994
|
+
const failure = this.failure();
|
|
3995
|
+
return {
|
|
3996
|
+
status: failure ? "FAILED" : "COMPLETED",
|
|
3997
|
+
metrics: {
|
|
3998
|
+
...typeof reward === "number" ? { avg_reward: reward } : {},
|
|
3999
|
+
reward,
|
|
4000
|
+
...Object.fromEntries(
|
|
4001
|
+
Object.entries(this.grade?.rewards ?? {}).map(([key, value]) => [`rewards.${key}`, value])
|
|
4002
|
+
),
|
|
4003
|
+
...failure ? { error: failure } : {}
|
|
4004
|
+
}
|
|
4005
|
+
};
|
|
4006
|
+
}
|
|
4007
|
+
};
|
|
4008
|
+
}
|
|
4009
|
+
});
|
|
4010
|
+
|
|
4011
|
+
// src/tracing/prerequisites.ts
|
|
4012
|
+
function getEnv(key) {
|
|
4013
|
+
const value = process.env[key];
|
|
4014
|
+
return value ? value : void 0;
|
|
4015
|
+
}
|
|
4016
|
+
function isGatewayConfigured() {
|
|
4017
|
+
return !!(getEnv(GATEWAY_ENV.HOST) && getEnv(GATEWAY_ENV.PUBLIC_KEY) && getEnv(GATEWAY_ENV.SECRET_KEY));
|
|
4018
|
+
}
|
|
4019
|
+
var GATEWAY_ENV, OTLP_TRACES_PATH, OPENTELEMETRY_PEERS, PINNED_PEERS, MODULE_NOT_FOUND, OpenTelemetryMissing;
|
|
4020
|
+
var init_prerequisites = __esm({
|
|
4021
|
+
"src/tracing/prerequisites.ts"() {
|
|
4022
|
+
"use strict";
|
|
4023
|
+
GATEWAY_ENV = {
|
|
4024
|
+
HOST: "GATEWAY_HOST",
|
|
4025
|
+
PUBLIC_KEY: "GATEWAY_PUBLIC_KEY",
|
|
4026
|
+
SECRET_KEY: "GATEWAY_SECRET_KEY",
|
|
4027
|
+
API_KEY: "GATEWAY_API_KEY",
|
|
4028
|
+
ENDPOINT: "GATEWAY_OTLP_ENDPOINT"
|
|
4029
|
+
};
|
|
4030
|
+
OTLP_TRACES_PATH = "/api/public/otel/v1/traces";
|
|
4031
|
+
OPENTELEMETRY_PEERS = {
|
|
4032
|
+
"@opentelemetry/api": "1.9.0",
|
|
4033
|
+
"@opentelemetry/exporter-trace-otlp-http": "0.222.0",
|
|
4034
|
+
"@opentelemetry/resources": "2.11.0",
|
|
4035
|
+
"@opentelemetry/sdk-trace-base": "2.11.0",
|
|
4036
|
+
"@opentelemetry/sdk-trace-node": "2.11.0"
|
|
4037
|
+
};
|
|
4038
|
+
PINNED_PEERS = Object.entries(OPENTELEMETRY_PEERS).map(([name, version]) => `${name}@${version}`).join(" ");
|
|
4039
|
+
MODULE_NOT_FOUND = /* @__PURE__ */ new Set(["MODULE_NOT_FOUND", "ERR_MODULE_NOT_FOUND"]);
|
|
4040
|
+
OpenTelemetryMissing = class _OpenTelemetryMissing extends Error {
|
|
4041
|
+
constructor() {
|
|
4042
|
+
super(
|
|
4043
|
+
`OpenTelemetry packages not found. Install them next to @withgateway/sdk, at the versions it is tested with:
|
|
4044
|
+
npm install ${PINNED_PEERS}
|
|
4045
|
+
npm install -g ${PINNED_PEERS} (the gateway CLI, when it was installed with npm install -g)`
|
|
4046
|
+
);
|
|
4047
|
+
this.name = "OpenTelemetryMissing";
|
|
4048
|
+
}
|
|
4049
|
+
static explains(error) {
|
|
4050
|
+
if (error instanceof _OpenTelemetryMissing) return true;
|
|
4051
|
+
const { code, message } = error ?? {};
|
|
4052
|
+
return MODULE_NOT_FOUND.has(String(code)) && String(message).includes("@opentelemetry/");
|
|
4053
|
+
}
|
|
3393
4054
|
};
|
|
3394
4055
|
}
|
|
3395
4056
|
});
|
|
@@ -3556,10 +4217,10 @@ var init_users = __esm({
|
|
|
3556
4217
|
totalItems: Number(meta.totalItems ?? rows.length)
|
|
3557
4218
|
};
|
|
3558
4219
|
}
|
|
3559
|
-
async requestJson(method,
|
|
4220
|
+
async requestJson(method, path13, payload) {
|
|
3560
4221
|
let response;
|
|
3561
4222
|
try {
|
|
3562
|
-
response = await fetch(`${this.host}${
|
|
4223
|
+
response = await fetch(`${this.host}${path13}`, {
|
|
3563
4224
|
method,
|
|
3564
4225
|
headers: {
|
|
3565
4226
|
Authorization: this.authHeader(),
|
|
@@ -3570,17 +4231,17 @@ var init_users = __esm({
|
|
|
3570
4231
|
});
|
|
3571
4232
|
} catch (error) {
|
|
3572
4233
|
throw new UserProfileError(
|
|
3573
|
-
`${method} ${
|
|
4234
|
+
`${method} ${path13} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
3574
4235
|
{ cause: error }
|
|
3575
4236
|
);
|
|
3576
4237
|
}
|
|
3577
4238
|
const text2 = await response.text();
|
|
3578
4239
|
if (!response.ok) {
|
|
3579
4240
|
throw new UserProfileError(
|
|
3580
|
-
`${method} ${
|
|
4241
|
+
`${method} ${path13} failed (${response.status}): ${text2.slice(0, 500)}`
|
|
3581
4242
|
);
|
|
3582
4243
|
}
|
|
3583
|
-
this.log("%s %s -> %s", method,
|
|
4244
|
+
this.log("%s %s -> %s", method, path13, response.status);
|
|
3584
4245
|
return safeJson(text2);
|
|
3585
4246
|
}
|
|
3586
4247
|
authHeader() {
|
|
@@ -4025,10 +4686,10 @@ var init_scores = __esm({
|
|
|
4025
4686
|
metadata: signalMetadata
|
|
4026
4687
|
});
|
|
4027
4688
|
}
|
|
4028
|
-
async request(method,
|
|
4689
|
+
async request(method, path13, payload) {
|
|
4029
4690
|
let response;
|
|
4030
4691
|
try {
|
|
4031
|
-
response = await fetch(`${this.host}${
|
|
4692
|
+
response = await fetch(`${this.host}${path13}`, {
|
|
4032
4693
|
method,
|
|
4033
4694
|
headers: {
|
|
4034
4695
|
Authorization: this.authHeader(),
|
|
@@ -4039,17 +4700,17 @@ var init_scores = __esm({
|
|
|
4039
4700
|
});
|
|
4040
4701
|
} catch (error) {
|
|
4041
4702
|
throw new ScoreError(
|
|
4042
|
-
`${method} ${
|
|
4703
|
+
`${method} ${path13} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
4043
4704
|
{ cause: error }
|
|
4044
4705
|
);
|
|
4045
4706
|
}
|
|
4046
4707
|
const text2 = await response.text();
|
|
4047
4708
|
if (!response.ok) {
|
|
4048
4709
|
throw new ScoreError(
|
|
4049
|
-
`${method} ${
|
|
4710
|
+
`${method} ${path13} failed (${response.status}): ${text2.slice(0, 500)}`
|
|
4050
4711
|
);
|
|
4051
4712
|
}
|
|
4052
|
-
this.log("%s %s -> %s", method,
|
|
4713
|
+
this.log("%s %s -> %s", method, path13, response.status);
|
|
4053
4714
|
}
|
|
4054
4715
|
authHeader() {
|
|
4055
4716
|
return `Basic ${Buffer.from(`${this.publicKey}:${this.secretKey}`).toString(
|
|
@@ -4077,7 +4738,7 @@ var require_package = __commonJS({
|
|
|
4077
4738
|
"package.json"(exports, module) {
|
|
4078
4739
|
module.exports = {
|
|
4079
4740
|
name: "@withgateway/sdk",
|
|
4080
|
-
version: "0.3.
|
|
4741
|
+
version: "0.3.3",
|
|
4081
4742
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
4082
4743
|
main: "./dist/index.js",
|
|
4083
4744
|
module: "./dist/index.mjs",
|
|
@@ -4486,10 +5147,6 @@ __export(init_exports, {
|
|
|
4486
5147
|
isInitialized: () => isInitialized,
|
|
4487
5148
|
shutdown: () => shutdown
|
|
4488
5149
|
});
|
|
4489
|
-
function getEnv(key) {
|
|
4490
|
-
const value = process.env[key];
|
|
4491
|
-
return value ? value : void 0;
|
|
4492
|
-
}
|
|
4493
5150
|
function log(message, ...args) {
|
|
4494
5151
|
if (state.debug) {
|
|
4495
5152
|
console.log(`[gatewaysdk.tracing] ${message}`, ...args);
|
|
@@ -4499,10 +5156,10 @@ function warn(message, ...args) {
|
|
|
4499
5156
|
console.warn(`[gatewaysdk.tracing] ${message}`, ...args);
|
|
4500
5157
|
}
|
|
4501
5158
|
function buildProvider(config, logFn) {
|
|
4502
|
-
const host = config.host ?? getEnv(
|
|
4503
|
-
const publicKey = config.publicKey ?? getEnv(
|
|
4504
|
-
const secretKey = config.secretKey ?? getEnv(
|
|
4505
|
-
const endpoint = config.endpoint ?? getEnv(
|
|
5159
|
+
const host = config.host ?? getEnv(GATEWAY_ENV.HOST);
|
|
5160
|
+
const publicKey = config.publicKey ?? getEnv(GATEWAY_ENV.PUBLIC_KEY);
|
|
5161
|
+
const secretKey = config.secretKey ?? getEnv(GATEWAY_ENV.SECRET_KEY);
|
|
5162
|
+
const endpoint = config.endpoint ?? getEnv(GATEWAY_ENV.ENDPOINT) ?? (host ? `${host.replace(/\/$/, "")}${OTLP_TRACES_PATH}` : void 0);
|
|
4506
5163
|
const missing = [];
|
|
4507
5164
|
if (!host) missing.push("host (or GATEWAY_HOST env var)");
|
|
4508
5165
|
if (!publicKey) missing.push("publicKey (or GATEWAY_PUBLIC_KEY env var)");
|
|
@@ -4539,9 +5196,7 @@ function buildProvider(config, logFn) {
|
|
|
4539
5196
|
ATTR_SERVICE_NAME = "service.name";
|
|
4540
5197
|
}
|
|
4541
5198
|
} catch {
|
|
4542
|
-
throw new
|
|
4543
|
-
"OpenTelemetry packages not found. Install them with:\nnpm install @opentelemetry/sdk-trace-node @opentelemetry/sdk-trace-base @opentelemetry/exporter-trace-otlp-http @opentelemetry/resources"
|
|
4544
|
-
);
|
|
5199
|
+
throw new OpenTelemetryMissing();
|
|
4545
5200
|
}
|
|
4546
5201
|
const resourceAttrs = {
|
|
4547
5202
|
[ATTR_SERVICE_NAME]: config.serviceName ?? "gatewaysdk-tracing"
|
|
@@ -4747,13 +5402,7 @@ async function shutdown() {
|
|
|
4747
5402
|
function isInitialized() {
|
|
4748
5403
|
return state.initialized;
|
|
4749
5404
|
}
|
|
4750
|
-
|
|
4751
|
-
const host = getEnv(ENV_VARS.HOST);
|
|
4752
|
-
const publicKey = getEnv(ENV_VARS.PUBLIC_KEY);
|
|
4753
|
-
const secretKey = getEnv(ENV_VARS.SECRET_KEY);
|
|
4754
|
-
return !!(host && publicKey && secretKey);
|
|
4755
|
-
}
|
|
4756
|
-
var ENV_VARS, DEFAULT_OTLP_PATH, state;
|
|
5405
|
+
var state;
|
|
4757
5406
|
var init_init = __esm({
|
|
4758
5407
|
"src/tracing/init.ts"() {
|
|
4759
5408
|
"use strict";
|
|
@@ -4762,13 +5411,8 @@ var init_init = __esm({
|
|
|
4762
5411
|
init_session();
|
|
4763
5412
|
init_scores();
|
|
4764
5413
|
init_build();
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
PUBLIC_KEY: "GATEWAY_PUBLIC_KEY",
|
|
4768
|
-
SECRET_KEY: "GATEWAY_SECRET_KEY",
|
|
4769
|
-
ENDPOINT: "GATEWAY_OTLP_ENDPOINT"
|
|
4770
|
-
};
|
|
4771
|
-
DEFAULT_OTLP_PATH = "/api/public/otel/v1/traces";
|
|
5414
|
+
init_prerequisites();
|
|
5415
|
+
init_prerequisites();
|
|
4772
5416
|
state = {
|
|
4773
5417
|
initialized: false,
|
|
4774
5418
|
provider: null
|
|
@@ -4776,89 +5420,97 @@ var init_init = __esm({
|
|
|
4776
5420
|
}
|
|
4777
5421
|
});
|
|
4778
5422
|
|
|
5423
|
+
// src/worlds/taskTracing.ts
|
|
5424
|
+
var HOST_WITH_AUTHORITY, TRACING_HELD_ELSEWHERE, TaskTracing;
|
|
5425
|
+
var init_taskTracing = __esm({
|
|
5426
|
+
"src/worlds/taskTracing.ts"() {
|
|
5427
|
+
"use strict";
|
|
5428
|
+
init_prerequisites();
|
|
5429
|
+
init_platformEndpoint();
|
|
5430
|
+
HOST_WITH_AUTHORITY = /^[a-z][a-z0-9+.-]*:\/\/[^/\\?#@\s]+(\/|$)/i;
|
|
5431
|
+
TRACING_HELD_ELSEWHERE = "Tracing in this process already sends spans to another destination or with other keys (an earlier run, or the agent's own tracing.init()), so this run's spans would not reach its own project.";
|
|
5432
|
+
TaskTracing = class _TaskTracing {
|
|
5433
|
+
constructor(load = () => Promise.resolve().then(() => (init_init(), init_exports))) {
|
|
5434
|
+
this.load = load;
|
|
5435
|
+
}
|
|
5436
|
+
load;
|
|
5437
|
+
static warned = false;
|
|
5438
|
+
static target = null;
|
|
5439
|
+
async start(requested, options) {
|
|
5440
|
+
if (!requested) return false;
|
|
5441
|
+
const endpoint = platformEndpoint(options);
|
|
5442
|
+
try {
|
|
5443
|
+
await this.initOnce(_TaskTracing.config(endpoint));
|
|
5444
|
+
return true;
|
|
5445
|
+
} catch (error) {
|
|
5446
|
+
_TaskTracing.warnOnce(_TaskTracing.reason(error, endpoint));
|
|
5447
|
+
return false;
|
|
5448
|
+
}
|
|
5449
|
+
}
|
|
5450
|
+
// init() keeps the first provider for the whole process and ignores later calls, so a later run is
|
|
5451
|
+
// traced only when it exports to the same place with the same keys.
|
|
5452
|
+
async initOnce(config) {
|
|
5453
|
+
const tracing = await this.load();
|
|
5454
|
+
const target = JSON.stringify([config.endpoint, config.publicKey, config.secretKey]);
|
|
5455
|
+
if (!tracing.isInitialized()) {
|
|
5456
|
+
tracing.init(config);
|
|
5457
|
+
_TaskTracing.target = target;
|
|
5458
|
+
return;
|
|
5459
|
+
}
|
|
5460
|
+
if (_TaskTracing.target !== target) throw new Error(TRACING_HELD_ELSEWHERE);
|
|
5461
|
+
}
|
|
5462
|
+
static config(endpoint) {
|
|
5463
|
+
if (!endpoint) throw new Error(GATEWAY_KEYS_MISSING);
|
|
5464
|
+
return { ...endpoint, endpoint: _TaskTracing.destination(endpoint) };
|
|
5465
|
+
}
|
|
5466
|
+
// B1: a saved login's keys go to their own host only. The redirect is compared as text, never parsed:
|
|
5467
|
+
// a fixed "<host>/" prefix leaves no URL parser room to read another host into it.
|
|
5468
|
+
static destination(endpoint) {
|
|
5469
|
+
const redirect = getEnv(GATEWAY_ENV.ENDPOINT);
|
|
5470
|
+
if (!redirect) return `${endpoint.host}${OTLP_TRACES_PATH}`;
|
|
5471
|
+
if (_TaskTracing.underHost(redirect, endpoint.host) || _TaskTracing.environmentKeys(endpoint)) return redirect;
|
|
5472
|
+
throw new Error(
|
|
5473
|
+
`GATEWAY_OTLP_ENDPOINT is not under ${endpoint.host}, and this run's keys are not GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY: they are sent to ${endpoint.host} only. Unset GATEWAY_OTLP_ENDPOINT, or set both keys in the environment.`
|
|
5474
|
+
);
|
|
5475
|
+
}
|
|
5476
|
+
static underHost(redirect, host) {
|
|
5477
|
+
return HOST_WITH_AUTHORITY.test(host) && redirect.startsWith(`${host}/`);
|
|
5478
|
+
}
|
|
5479
|
+
static environmentKeys(endpoint) {
|
|
5480
|
+
const secretKey = getEnv(GATEWAY_ENV.SECRET_KEY) ?? getEnv(GATEWAY_ENV.API_KEY);
|
|
5481
|
+
return endpoint.publicKey === getEnv(GATEWAY_ENV.PUBLIC_KEY) && endpoint.secretKey === secretKey;
|
|
5482
|
+
}
|
|
5483
|
+
static warnOnce(reason) {
|
|
5484
|
+
if (_TaskTracing.warned) return;
|
|
5485
|
+
_TaskTracing.warned = true;
|
|
5486
|
+
console.warn(
|
|
5487
|
+
`[gatewaysdk.tracing] Task runs in this process are not traced. ${reason}
|
|
5488
|
+
Pass --no-trace (trace: false) to run untraced without this warning.`
|
|
5489
|
+
);
|
|
5490
|
+
}
|
|
5491
|
+
static reason(error, endpoint) {
|
|
5492
|
+
if (OpenTelemetryMissing.explains(error)) return new OpenTelemetryMissing().message;
|
|
5493
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
5494
|
+
const keys = endpoint ? [endpoint.publicKey, endpoint.secretKey] : [];
|
|
5495
|
+
return keys.reduce((text2, key) => text2.split(key).join("[redacted]"), message);
|
|
5496
|
+
}
|
|
5497
|
+
};
|
|
5498
|
+
}
|
|
5499
|
+
});
|
|
5500
|
+
|
|
4779
5501
|
// src/worlds/taskRun.ts
|
|
4780
5502
|
import { randomBytes } from "crypto";
|
|
4781
|
-
import * as
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
}
|
|
4793
|
-
async function fileTaskRun(live, runId, model, report, grade, agentError, traced, runDir, options, setRunId) {
|
|
4794
|
-
const aliases = live.aliases;
|
|
4795
|
-
const anchor = aliases[0];
|
|
4796
|
-
const worldsMeta = Object.fromEntries(
|
|
4797
|
-
aliases.map((alias) => [alias, worldRef(live, alias)])
|
|
4798
|
-
);
|
|
4799
|
-
const evals = new GatewayEvalsClient(options);
|
|
4800
|
-
const evaluationId = await evals.createEvaluation(
|
|
4801
|
-
worldRef(live, anchor).versionId,
|
|
4802
|
-
{
|
|
4803
|
-
model,
|
|
4804
|
-
rolloutsPerExample: 1,
|
|
4805
|
-
...setRunId ? { runId: setRunId } : {},
|
|
4806
|
-
metadata: {
|
|
4807
|
-
source: "worlds-task-run",
|
|
4808
|
-
task: {
|
|
4809
|
-
id: live.taskId,
|
|
4810
|
-
version: live.taskVersion,
|
|
4811
|
-
name: live.name,
|
|
4812
|
-
hash: live.hash
|
|
4813
|
-
},
|
|
4814
|
-
anchor,
|
|
4815
|
-
worlds: worldsMeta,
|
|
4816
|
-
runId
|
|
4817
|
-
}
|
|
4818
|
-
}
|
|
4819
|
-
);
|
|
4820
|
-
const reward = grade.reward;
|
|
4821
|
-
const sample = {
|
|
4822
|
-
exampleId: live.name ?? live.taskId ?? runId,
|
|
4823
|
-
task: live.name ?? live.taskId ?? runId,
|
|
4824
|
-
rolloutIndex: 0,
|
|
4825
|
-
prompt: live.instruction,
|
|
4826
|
-
...report === null ? {} : { completion: report },
|
|
4827
|
-
rewards: grade.rewards,
|
|
4828
|
-
info: {
|
|
4829
|
-
sessionId: runId,
|
|
4830
|
-
worlds: Object.fromEntries(
|
|
4831
|
-
aliases.map((alias) => [
|
|
4832
|
-
alias,
|
|
4833
|
-
{
|
|
4834
|
-
...worldRef(live, alias),
|
|
4835
|
-
reward: grade.worlds[alias]?.reward ?? null
|
|
4836
|
-
}
|
|
4837
|
-
])
|
|
4838
|
-
),
|
|
4839
|
-
ungraded: grade.ungraded,
|
|
4840
|
-
traced,
|
|
4841
|
-
runDir,
|
|
4842
|
-
...agentError ? { agentError } : {}
|
|
4843
|
-
}
|
|
4844
|
-
};
|
|
4845
|
-
if (typeof reward === "number") {
|
|
4846
|
-
sample.reward = reward;
|
|
4847
|
-
sample.score = reward;
|
|
4848
|
-
sample.correct = reward >= 1;
|
|
4849
|
-
}
|
|
4850
|
-
await evals.pushSamples(evaluationId, [sample]);
|
|
4851
|
-
await evals.finalizeEvaluation(evaluationId, {
|
|
4852
|
-
status: agentError ? "FAILED" : "COMPLETED",
|
|
4853
|
-
metrics: {
|
|
4854
|
-
...typeof reward === "number" ? { avg_reward: reward } : {},
|
|
4855
|
-
reward,
|
|
4856
|
-
...Object.fromEntries(
|
|
4857
|
-
Object.entries(grade.rewards).map(([k, v]) => [`rewards.${k}`, v])
|
|
4858
|
-
)
|
|
4859
|
-
}
|
|
4860
|
-
});
|
|
4861
|
-
return evaluationId;
|
|
5503
|
+
import * as path2 from "path";
|
|
5504
|
+
function taskRunFailure(summary) {
|
|
5505
|
+
if (summary.agentError !== null) return `agent raised: ${summary.agentError}`;
|
|
5506
|
+
if (summary.runError !== null) return `the run stopped: ${summary.runError}`;
|
|
5507
|
+
if (summary.gradeError !== null)
|
|
5508
|
+
return `the task could not be graded: ${summary.gradeError}`;
|
|
5509
|
+
if (summary.fileError !== null)
|
|
5510
|
+
return `the run could not be filed: ${summary.fileError}`;
|
|
5511
|
+
if (summary.filed && summary.evaluationStatus !== "COMPLETED")
|
|
5512
|
+
return `the platform settled evaluation ${summary.evaluationId} as ${summary.evaluationStatus}`;
|
|
5513
|
+
return null;
|
|
4862
5514
|
}
|
|
4863
5515
|
function reportFromResult(result) {
|
|
4864
5516
|
if (result === void 0 || result === null)
|
|
@@ -4876,120 +5528,47 @@ function reportFromResult(result) {
|
|
|
4876
5528
|
);
|
|
4877
5529
|
return { report, extra };
|
|
4878
5530
|
}
|
|
5531
|
+
async function refuseUnreadTools(live) {
|
|
5532
|
+
try {
|
|
5533
|
+
for (const alias of live.aliases)
|
|
5534
|
+
WorldToolsUnread.refuse(`${live.worldRef(alias).slug} (alias ${alias})`, live.session(alias).deprecations);
|
|
5535
|
+
} catch (error) {
|
|
5536
|
+
await live.close({ keepWarm: false }).catch(() => void 0);
|
|
5537
|
+
throw error;
|
|
5538
|
+
}
|
|
5539
|
+
}
|
|
4879
5540
|
async function runTask(ref, agent, opts) {
|
|
4880
5541
|
const runId = `wtr-${randomBytes(6).toString("hex")}`;
|
|
4881
|
-
const outDir = opts.outDir ?? "runs";
|
|
4882
|
-
const runDir = path.join(outDir, runId);
|
|
4883
|
-
fs.mkdirSync(runDir, { recursive: true });
|
|
4884
5542
|
const options = opts.options ?? {};
|
|
4885
|
-
const
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
traced = true;
|
|
4901
|
-
}
|
|
4902
|
-
} catch {
|
|
4903
|
-
traced = false;
|
|
4904
|
-
}
|
|
4905
|
-
}
|
|
4906
|
-
const taskRun = new TaskRun(
|
|
4907
|
-
runId,
|
|
4908
|
-
live.instruction ?? "",
|
|
4909
|
-
opts.model,
|
|
4910
|
-
live.sessions,
|
|
4911
|
-
await live.manifest()
|
|
4912
|
-
);
|
|
4913
|
-
let agentError = null;
|
|
4914
|
-
let report = null;
|
|
4915
|
-
let extra = {};
|
|
4916
|
-
try {
|
|
4917
|
-
const invoke = () => agent(taskRun);
|
|
4918
|
-
const result = traced ? await (await Promise.resolve().then(() => (init_session(), session_exports))).withSession(runId, invoke) : await invoke();
|
|
4919
|
-
({ report, extra } = reportFromResult(result));
|
|
4920
|
-
} catch (error) {
|
|
4921
|
-
const message = (error instanceof Error ? error.message : String(error)) || "Unknown error";
|
|
4922
|
-
agentError = message.slice(0, 2e3);
|
|
4923
|
-
}
|
|
4924
|
-
if (traced)
|
|
4925
|
-
await Promise.resolve().then(() => (init_init(), init_exports)).then((tracing) => tracing.flush()).catch(() => void 0);
|
|
4926
|
-
const grade = report !== null ? await live.grade({ report }) : await live.grade();
|
|
4927
|
-
fs.writeFileSync(
|
|
4928
|
-
path.join(runDir, "manifest.json"),
|
|
4929
|
-
JSON.stringify(taskRun.manifest, null, 2)
|
|
4930
|
-
);
|
|
4931
|
-
fs.writeFileSync(
|
|
4932
|
-
path.join(runDir, "grades.json"),
|
|
4933
|
-
JSON.stringify(grade, null, 2)
|
|
4934
|
-
);
|
|
4935
|
-
if (report) fs.writeFileSync(path.join(runDir, "report.md"), report);
|
|
4936
|
-
const summary = {
|
|
4937
|
-
runId,
|
|
4938
|
-
taskId: live.taskId,
|
|
4939
|
-
taskVersion: live.taskVersion,
|
|
4940
|
-
name: live.name,
|
|
4941
|
-
instruction: taskRun.instruction,
|
|
4942
|
-
model: opts.model,
|
|
4943
|
-
aliases: live.aliases,
|
|
4944
|
-
reward: grade.reward,
|
|
4945
|
-
rewards: grade.rewards,
|
|
4946
|
-
ungraded: grade.ungraded,
|
|
4947
|
-
agentError,
|
|
4948
|
-
report,
|
|
4949
|
-
traced,
|
|
4950
|
-
runDir,
|
|
4951
|
-
durationSeconds: Math.round((Date.now() - started) / 10) / 100,
|
|
4952
|
-
notes: taskRun.notes,
|
|
4953
|
-
filed: false,
|
|
4954
|
-
...extra
|
|
4955
|
-
};
|
|
4956
|
-
if (opts.file !== false) {
|
|
4957
|
-
summary.evaluationId = await fileTaskRun(
|
|
4958
|
-
live,
|
|
4959
|
-
runId,
|
|
4960
|
-
opts.model,
|
|
4961
|
-
report,
|
|
4962
|
-
grade,
|
|
4963
|
-
agentError,
|
|
4964
|
-
traced,
|
|
4965
|
-
runDir,
|
|
4966
|
-
options,
|
|
4967
|
-
opts.setRunId
|
|
4968
|
-
);
|
|
4969
|
-
summary.filed = true;
|
|
4970
|
-
}
|
|
4971
|
-
fs.writeFileSync(
|
|
4972
|
-
path.join(runDir, "run.json"),
|
|
4973
|
-
JSON.stringify(summary, null, 2)
|
|
4974
|
-
);
|
|
4975
|
-
return summary;
|
|
4976
|
-
} finally {
|
|
4977
|
-
if (!opts.keepUp) {
|
|
4978
|
-
try {
|
|
4979
|
-
await live.close({ keepWarm: false });
|
|
4980
|
-
} catch {
|
|
4981
|
-
}
|
|
4982
|
-
}
|
|
4983
|
-
}
|
|
5543
|
+
const opening = new TaskOpening(
|
|
5544
|
+
openTask(ref, {
|
|
5545
|
+
surfaces: opts.surfaces,
|
|
5546
|
+
reuseWarm: opts.reuseWarm,
|
|
5547
|
+
browserTier: opts.browserTier,
|
|
5548
|
+
options
|
|
5549
|
+
}).then(async (live) => {
|
|
5550
|
+
await refuseUnreadTools(live);
|
|
5551
|
+
return new LiveTaskRun(runId, live, opts, options);
|
|
5552
|
+
})
|
|
5553
|
+
);
|
|
5554
|
+
return new RunSignals().during(
|
|
5555
|
+
(signal, urgent) => opening.interrupt(signal, urgent),
|
|
5556
|
+
() => opening.complete(agent)
|
|
5557
|
+
);
|
|
4984
5558
|
}
|
|
4985
|
-
var TaskRun, describeValue, RESULT_CONTRACT;
|
|
5559
|
+
var TaskRun, FILING_UNFINISHED, describeValue, RESULT_CONTRACT, LiveTaskRun, TaskOpening;
|
|
4986
5560
|
var init_taskRun = __esm({
|
|
4987
5561
|
"src/worlds/taskRun.ts"() {
|
|
4988
5562
|
"use strict";
|
|
4989
5563
|
init_browser();
|
|
4990
5564
|
init_evals();
|
|
5565
|
+
init_runSignals();
|
|
4991
5566
|
init_session2();
|
|
4992
5567
|
init_taskSessions();
|
|
5568
|
+
init_taskRunDir();
|
|
5569
|
+
init_taskRunOutcome();
|
|
5570
|
+
init_taskTracing();
|
|
5571
|
+
init_worldNotice();
|
|
4993
5572
|
TaskRun = class {
|
|
4994
5573
|
constructor(runId, instruction, model, sessions, manifest) {
|
|
4995
5574
|
this.runId = runId;
|
|
@@ -5052,8 +5631,127 @@ var init_taskRun = __esm({
|
|
|
5052
5631
|
Object.assign(this.notes, notes);
|
|
5053
5632
|
}
|
|
5054
5633
|
};
|
|
5634
|
+
FILING_UNFINISHED = "the filing did not finish";
|
|
5055
5635
|
describeValue = (value) => Array.isArray(value) ? "array" : value === null ? "null" : typeof value;
|
|
5056
5636
|
RESULT_CONTRACT = "return a string report, an object {report?: string, ...} or nothing";
|
|
5637
|
+
LiveTaskRun = class {
|
|
5638
|
+
constructor(runId, live, opts, options) {
|
|
5639
|
+
this.live = live;
|
|
5640
|
+
this.opts = opts;
|
|
5641
|
+
this.options = options;
|
|
5642
|
+
this.files = new TaskRunDir(path2.join(opts.outDir ?? "runs", runId));
|
|
5643
|
+
this.outcome = new TaskRunOutcome(runId, live, opts.model, this.files.path);
|
|
5644
|
+
}
|
|
5645
|
+
live;
|
|
5646
|
+
opts;
|
|
5647
|
+
options;
|
|
5648
|
+
files;
|
|
5649
|
+
outcome;
|
|
5650
|
+
played = false;
|
|
5651
|
+
interrupted = false;
|
|
5652
|
+
filing = null;
|
|
5653
|
+
ending = null;
|
|
5654
|
+
async complete(agent) {
|
|
5655
|
+
try {
|
|
5656
|
+
await this.play(agent).catch((error) => this.outcome.stopped(error));
|
|
5657
|
+
this.played = true;
|
|
5658
|
+
await this.file();
|
|
5659
|
+
return this.record();
|
|
5660
|
+
} finally {
|
|
5661
|
+
await this.end();
|
|
5662
|
+
}
|
|
5663
|
+
}
|
|
5664
|
+
async interrupt(signal, urgent = false) {
|
|
5665
|
+
const sessions = this.opts.keepUp ? "leaving its sessions up" : "closing its sessions";
|
|
5666
|
+
const how = urgent ? " now, without waiting" : "";
|
|
5667
|
+
process.stderr.write(`${this.outcome.runId} interrupted by ${signal}; ${sessions}${how}
|
|
5668
|
+
`);
|
|
5669
|
+
if (!this.played) this.outcome.stopped(`interrupted by ${signal}`);
|
|
5670
|
+
this.interrupted = true;
|
|
5671
|
+
try {
|
|
5672
|
+
if (!urgent) await this.filing;
|
|
5673
|
+
this.record();
|
|
5674
|
+
} catch (error) {
|
|
5675
|
+
const why = error instanceof Error ? error.message : String(error);
|
|
5676
|
+
process.stderr.write(`${this.outcome.runId}: run.json not written: ${why}
|
|
5677
|
+
`);
|
|
5678
|
+
} finally {
|
|
5679
|
+
await this.end();
|
|
5680
|
+
}
|
|
5681
|
+
}
|
|
5682
|
+
summary() {
|
|
5683
|
+
return this.outcome.summary();
|
|
5684
|
+
}
|
|
5685
|
+
async play(agent) {
|
|
5686
|
+
await this.live.ready();
|
|
5687
|
+
this.outcome.traced = await new TaskTracing().start(this.opts.trace !== false, this.options);
|
|
5688
|
+
const run = new TaskRun(
|
|
5689
|
+
this.outcome.runId,
|
|
5690
|
+
this.live.instruction ?? "",
|
|
5691
|
+
this.opts.model,
|
|
5692
|
+
this.live.sessions,
|
|
5693
|
+
await this.live.manifest()
|
|
5694
|
+
);
|
|
5695
|
+
this.outcome.notes = run.notes;
|
|
5696
|
+
this.files.writeManifest(run.manifest);
|
|
5697
|
+
await this.callAgent(agent, run);
|
|
5698
|
+
const report = this.outcome.report;
|
|
5699
|
+
this.outcome.grade = await this.live.grade(report !== null ? { report } : {});
|
|
5700
|
+
this.files.writeJson("grades.json", this.outcome.grade);
|
|
5701
|
+
if (report) this.files.write("report.md", report);
|
|
5702
|
+
}
|
|
5703
|
+
async callAgent(agent, run) {
|
|
5704
|
+
try {
|
|
5705
|
+
const invoke = () => agent(run);
|
|
5706
|
+
const result = this.outcome.traced ? await (await Promise.resolve().then(() => (init_session(), session_exports))).withSession(run.runId, invoke) : await invoke();
|
|
5707
|
+
({ report: this.outcome.report, extra: this.outcome.extra } = reportFromResult(result));
|
|
5708
|
+
} catch (error) {
|
|
5709
|
+
this.outcome.agentRaised(error);
|
|
5710
|
+
}
|
|
5711
|
+
if (this.outcome.traced)
|
|
5712
|
+
await Promise.resolve().then(() => (init_init(), init_exports)).then((tracing) => tracing.flush()).catch(() => void 0);
|
|
5713
|
+
}
|
|
5714
|
+
async file() {
|
|
5715
|
+
if (this.opts.file === false || this.interrupted) return;
|
|
5716
|
+
this.files.writeJson("run.json", { ...this.outcome.summary(), fileError: FILING_UNFINISHED });
|
|
5717
|
+
this.filing = this.outcome.file(new GatewayEvalsClient(this.options), this.opts.setRunId);
|
|
5718
|
+
await this.filing;
|
|
5719
|
+
}
|
|
5720
|
+
record() {
|
|
5721
|
+
const summary = this.outcome.summary();
|
|
5722
|
+
this.files.writeJson("run.json", summary);
|
|
5723
|
+
return summary;
|
|
5724
|
+
}
|
|
5725
|
+
end() {
|
|
5726
|
+
this.ending ??= this.opts.keepUp ? Promise.resolve() : this.live.close({ keepWarm: false }).then(
|
|
5727
|
+
() => void 0,
|
|
5728
|
+
() => void 0
|
|
5729
|
+
);
|
|
5730
|
+
return this.ending;
|
|
5731
|
+
}
|
|
5732
|
+
};
|
|
5733
|
+
TaskOpening = class {
|
|
5734
|
+
interrupting = null;
|
|
5735
|
+
run = null;
|
|
5736
|
+
opened;
|
|
5737
|
+
constructor(opening) {
|
|
5738
|
+
this.opened = opening.then((run) => this.run = run);
|
|
5739
|
+
}
|
|
5740
|
+
async complete(agent) {
|
|
5741
|
+
const run = await this.opened;
|
|
5742
|
+
if (!this.interrupting) return run.complete(agent);
|
|
5743
|
+
await this.interrupting;
|
|
5744
|
+
return run.summary();
|
|
5745
|
+
}
|
|
5746
|
+
interrupt(signal, urgent = false) {
|
|
5747
|
+
if (urgent) return this.run?.interrupt(signal, true) ?? Promise.resolve();
|
|
5748
|
+
this.interrupting ??= this.opened.then(
|
|
5749
|
+
(run) => run.interrupt(signal),
|
|
5750
|
+
() => void 0
|
|
5751
|
+
);
|
|
5752
|
+
return this.interrupting;
|
|
5753
|
+
}
|
|
5754
|
+
};
|
|
5057
5755
|
}
|
|
5058
5756
|
});
|
|
5059
5757
|
|
|
@@ -5133,69 +5831,153 @@ async function runSet(datasetId, agent, opts) {
|
|
|
5133
5831
|
source: opts.source ?? "sdk",
|
|
5134
5832
|
...git && Object.keys(git).length ? { git } : {}
|
|
5135
5833
|
});
|
|
5136
|
-
|
|
5137
|
-
options,
|
|
5138
|
-
"POST",
|
|
5139
|
-
`${SET_RUNS}/${encodeURIComponent(opened.id)}/close`,
|
|
5140
|
-
{ status }
|
|
5141
|
-
);
|
|
5142
|
-
const onInterrupt = () => {
|
|
5143
|
-
void close("failed").finally(() => process.exit(130));
|
|
5144
|
-
};
|
|
5145
|
-
process.once("SIGINT", onInterrupt);
|
|
5146
|
-
const planned = await runPlannedTasks(opened, agent, opts, options).finally(
|
|
5147
|
-
() => process.off("SIGINT", onInterrupt)
|
|
5148
|
-
);
|
|
5149
|
-
const { tasks, failed } = planned;
|
|
5150
|
-
const requested = failed ? "failed" : "completed";
|
|
5151
|
-
const setRun = await close(requested);
|
|
5152
|
-
return {
|
|
5153
|
-
setRun,
|
|
5154
|
-
tasks,
|
|
5155
|
-
failed: failed || setRun.status !== "completed",
|
|
5156
|
-
closedAsRequested: setRun.status === requested
|
|
5157
|
-
};
|
|
5158
|
-
}
|
|
5159
|
-
async function runPlannedTasks(opened, agent, opts, options) {
|
|
5160
|
-
const tasks = [];
|
|
5161
|
-
let failed = false;
|
|
5162
|
-
for (const task of opened.tasks) {
|
|
5163
|
-
try {
|
|
5164
|
-
const summary = await runTask(task.worldTaskId, agent, {
|
|
5165
|
-
model: opts.model,
|
|
5166
|
-
surfaces: opts.surfaces,
|
|
5167
|
-
browserTier: opts.browserTier,
|
|
5168
|
-
outDir: opts.outDir,
|
|
5169
|
-
trace: opts.trace,
|
|
5170
|
-
setRunId: opened.id,
|
|
5171
|
-
options
|
|
5172
|
-
});
|
|
5173
|
-
tasks.push(summary);
|
|
5174
|
-
failed ||= summary.agentError !== null;
|
|
5175
|
-
opts.onTask?.(summary);
|
|
5176
|
-
} catch (error) {
|
|
5177
|
-
failed = true;
|
|
5178
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
5179
|
-
process.stderr.write(`task ${task.name} could not run: ${message}
|
|
5180
|
-
`);
|
|
5181
|
-
}
|
|
5182
|
-
}
|
|
5183
|
-
return { tasks, failed };
|
|
5834
|
+
return new SetRunner(opened, agent, opts, options).run();
|
|
5184
5835
|
}
|
|
5185
|
-
var SET_RUNS;
|
|
5836
|
+
var SET_RUNS, SetRunner;
|
|
5186
5837
|
var init_setRun = __esm({
|
|
5187
5838
|
"src/worlds/setRun.ts"() {
|
|
5188
5839
|
"use strict";
|
|
5189
5840
|
init_worlds();
|
|
5190
5841
|
init_checkoutProvenance();
|
|
5842
|
+
init_runSignals();
|
|
5191
5843
|
init_taskRun();
|
|
5192
5844
|
SET_RUNS = "/api/public/set-runs";
|
|
5845
|
+
SetRunner = class {
|
|
5846
|
+
constructor(opened, agent, opts, options) {
|
|
5847
|
+
this.opened = opened;
|
|
5848
|
+
this.agent = agent;
|
|
5849
|
+
this.opts = opts;
|
|
5850
|
+
this.options = options;
|
|
5851
|
+
}
|
|
5852
|
+
opened;
|
|
5853
|
+
agent;
|
|
5854
|
+
opts;
|
|
5855
|
+
options;
|
|
5856
|
+
tasks = [];
|
|
5857
|
+
failures = [];
|
|
5858
|
+
failed = false;
|
|
5859
|
+
current = null;
|
|
5860
|
+
interrupted = null;
|
|
5861
|
+
signals = new RunSignals();
|
|
5862
|
+
async run() {
|
|
5863
|
+
await this.signals.during(
|
|
5864
|
+
(signal2) => this.interrupt(signal2).then(() => void 0),
|
|
5865
|
+
() => this.runTasks()
|
|
5866
|
+
);
|
|
5867
|
+
const signal = this.signals.signal;
|
|
5868
|
+
if (signal !== null) return this.result(await this.interrupt(signal), "failed");
|
|
5869
|
+
const requested = this.failed ? "failed" : "completed";
|
|
5870
|
+
return this.result(await this.close(requested, this.failures), requested);
|
|
5871
|
+
}
|
|
5872
|
+
interrupt(signal) {
|
|
5873
|
+
const stopped = this.current ? [{ worldTaskId: this.current, reason: `interrupted by ${signal}` }] : [];
|
|
5874
|
+
this.interrupted ??= this.close("failed", [...this.failures, ...stopped]);
|
|
5875
|
+
return this.interrupted;
|
|
5876
|
+
}
|
|
5877
|
+
async runTasks() {
|
|
5878
|
+
for (const task of this.opened.tasks) {
|
|
5879
|
+
if (this.signals.signal !== null) return;
|
|
5880
|
+
this.current = task.worldTaskId;
|
|
5881
|
+
await this.runOne(task);
|
|
5882
|
+
}
|
|
5883
|
+
this.current = null;
|
|
5884
|
+
}
|
|
5885
|
+
async runOne(task) {
|
|
5886
|
+
try {
|
|
5887
|
+
const summary = await runTask(task.worldTaskId, this.agent, {
|
|
5888
|
+
model: this.opts.model,
|
|
5889
|
+
surfaces: this.opts.surfaces,
|
|
5890
|
+
browserTier: this.opts.browserTier,
|
|
5891
|
+
outDir: this.opts.outDir,
|
|
5892
|
+
trace: this.opts.trace,
|
|
5893
|
+
setRunId: this.opened.id,
|
|
5894
|
+
options: this.options
|
|
5895
|
+
});
|
|
5896
|
+
this.tasks.push(summary);
|
|
5897
|
+
this.failed ||= taskRunFailure(summary) !== null;
|
|
5898
|
+
if (summary.fileError !== null)
|
|
5899
|
+
this.failures.push({ worldTaskId: task.worldTaskId, reason: summary.fileError });
|
|
5900
|
+
this.opts.onTask?.(summary);
|
|
5901
|
+
} catch (error) {
|
|
5902
|
+
this.failed = true;
|
|
5903
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
5904
|
+
process.stderr.write(`task ${task.name} could not run: ${message}
|
|
5905
|
+
`);
|
|
5906
|
+
this.failures.push({
|
|
5907
|
+
worldTaskId: task.worldTaskId,
|
|
5908
|
+
reason: message || (error instanceof Error ? error.name : "Error")
|
|
5909
|
+
});
|
|
5910
|
+
}
|
|
5911
|
+
}
|
|
5912
|
+
close(status, failures = []) {
|
|
5913
|
+
return apiRequest(
|
|
5914
|
+
this.options,
|
|
5915
|
+
"POST",
|
|
5916
|
+
`${SET_RUNS}/${encodeURIComponent(this.opened.id)}/close`,
|
|
5917
|
+
{ status, ...failures.length ? { failures } : {} }
|
|
5918
|
+
);
|
|
5919
|
+
}
|
|
5920
|
+
result(setRun, requested) {
|
|
5921
|
+
return {
|
|
5922
|
+
setRun,
|
|
5923
|
+
tasks: this.tasks,
|
|
5924
|
+
failed: this.failed || setRun.status !== "completed",
|
|
5925
|
+
closedAsRequested: setRun.status === requested
|
|
5926
|
+
};
|
|
5927
|
+
}
|
|
5928
|
+
};
|
|
5929
|
+
}
|
|
5930
|
+
});
|
|
5931
|
+
|
|
5932
|
+
// src/worlds/requestLog.ts
|
|
5933
|
+
var WorldRequestLog;
|
|
5934
|
+
var init_requestLog = __esm({
|
|
5935
|
+
"src/worlds/requestLog.ts"() {
|
|
5936
|
+
"use strict";
|
|
5937
|
+
WorldRequestLog = class _WorldRequestLog {
|
|
5938
|
+
constructor(requests) {
|
|
5939
|
+
this.requests = requests;
|
|
5940
|
+
}
|
|
5941
|
+
requests;
|
|
5942
|
+
static async read(session) {
|
|
5943
|
+
const state2 = await session.state();
|
|
5944
|
+
const calls = state2?.calls;
|
|
5945
|
+
if (!Array.isArray(calls)) return null;
|
|
5946
|
+
return new _WorldRequestLog(calls.filter((c) => typeof c === "object" && c !== null));
|
|
5947
|
+
}
|
|
5948
|
+
/** How many older requests the world no longer keeps (its log is bounded): the gap
|
|
5949
|
+
* before the first entry it still holds. */
|
|
5950
|
+
get dropped() {
|
|
5951
|
+
const first = Number(this.requests[0]?.seq) || 1;
|
|
5952
|
+
return Math.max(0, first - 1);
|
|
5953
|
+
}
|
|
5954
|
+
/** Each request in the shape of a ledger line, `kind: "request"`, so one JSONL
|
|
5955
|
+
* file holds both. */
|
|
5956
|
+
asCalls() {
|
|
5957
|
+
return this.requests.map((r) => ({
|
|
5958
|
+
seq: Number(r.seq) || 0,
|
|
5959
|
+
kind: "request",
|
|
5960
|
+
tool: r.operation ?? null,
|
|
5961
|
+
args: {
|
|
5962
|
+
method: r.method ?? null,
|
|
5963
|
+
path: r.path ?? null,
|
|
5964
|
+
args: r.args ?? null,
|
|
5965
|
+
query: r.query ?? null,
|
|
5966
|
+
body: r.body ?? null,
|
|
5967
|
+
via: r.via ?? null
|
|
5968
|
+
},
|
|
5969
|
+
result: { status: r.status ?? null, rows: r.rows ?? null, found: r.found ?? null },
|
|
5970
|
+
error: null,
|
|
5971
|
+
completedAt: r.at ?? null
|
|
5972
|
+
}));
|
|
5973
|
+
}
|
|
5974
|
+
};
|
|
5193
5975
|
}
|
|
5194
5976
|
});
|
|
5195
5977
|
|
|
5196
5978
|
// src/worlds/checkoutTarget.ts
|
|
5197
5979
|
import * as fs2 from "fs";
|
|
5198
|
-
import * as
|
|
5980
|
+
import * as path3 from "path";
|
|
5199
5981
|
var CheckoutRefusedError, NAMED_EDITS, CheckoutTarget;
|
|
5200
5982
|
var init_checkoutTarget = __esm({
|
|
5201
5983
|
"src/worlds/checkoutTarget.ts"() {
|
|
@@ -5224,17 +6006,17 @@ var init_checkoutTarget = __esm({
|
|
|
5224
6006
|
}
|
|
5225
6007
|
/** The absolute destination; a relative target may not resolve above `cwd`. */
|
|
5226
6008
|
static confined(target, cwd) {
|
|
5227
|
-
const dir =
|
|
5228
|
-
if (
|
|
5229
|
-
const rel =
|
|
5230
|
-
if (rel === "" || !rel.startsWith("..") && !
|
|
6009
|
+
const dir = path3.resolve(cwd, target);
|
|
6010
|
+
if (path3.isAbsolute(target)) return dir;
|
|
6011
|
+
const rel = path3.relative(cwd, dir);
|
|
6012
|
+
if (rel === "" || !rel.startsWith("..") && !path3.isAbsolute(rel))
|
|
5231
6013
|
return dir;
|
|
5232
6014
|
throw new CheckoutRefusedError(
|
|
5233
6015
|
`--target ${target} resolves outside the current directory (${cwd}) \u2014 run from that directory, or pass an absolute path`
|
|
5234
6016
|
);
|
|
5235
6017
|
}
|
|
5236
6018
|
static fresh(slug, cwd) {
|
|
5237
|
-
const base =
|
|
6019
|
+
const base = path3.join(cwd, slug);
|
|
5238
6020
|
let dir = base;
|
|
5239
6021
|
let i = 1;
|
|
5240
6022
|
while (fs2.existsSync(dir)) dir = `${base}-${i++}`;
|
|
@@ -5261,7 +6043,7 @@ var init_checkoutTarget = __esm({
|
|
|
5261
6043
|
].filter(_CheckoutTarget.confinedRel).sort();
|
|
5262
6044
|
}
|
|
5263
6045
|
static confinedRel(rel) {
|
|
5264
|
-
if (rel === "" ||
|
|
6046
|
+
if (rel === "" || path3.isAbsolute(rel)) return false;
|
|
5265
6047
|
return !rel.split(/[\\/]/).includes("..");
|
|
5266
6048
|
}
|
|
5267
6049
|
/** Why `dir` cannot be overwritten, or null when it is a clean checkout of `slug`. */
|
|
@@ -5279,9 +6061,9 @@ var init_checkoutTarget = __esm({
|
|
|
5279
6061
|
/** Remove the replaced checkout's files (and the dirs they leave empty). */
|
|
5280
6062
|
clear() {
|
|
5281
6063
|
for (const rel of this.replaces) {
|
|
5282
|
-
const abs =
|
|
6064
|
+
const abs = path3.join(this.dir, rel);
|
|
5283
6065
|
fs2.rmSync(abs, { force: true });
|
|
5284
|
-
this.pruneEmptyParents(
|
|
6066
|
+
this.pruneEmptyParents(path3.dirname(abs));
|
|
5285
6067
|
}
|
|
5286
6068
|
}
|
|
5287
6069
|
pruneEmptyParents(from) {
|
|
@@ -5289,7 +6071,7 @@ var init_checkoutTarget = __esm({
|
|
|
5289
6071
|
while (cur !== this.dir && cur.startsWith(this.dir)) {
|
|
5290
6072
|
if (fs2.existsSync(cur) && fs2.readdirSync(cur).length > 0) return;
|
|
5291
6073
|
fs2.rmSync(cur, { recursive: true, force: true });
|
|
5292
|
-
cur =
|
|
6074
|
+
cur = path3.dirname(cur);
|
|
5293
6075
|
}
|
|
5294
6076
|
}
|
|
5295
6077
|
};
|
|
@@ -5299,7 +6081,7 @@ var init_checkoutTarget = __esm({
|
|
|
5299
6081
|
// src/worlds/worldDir.ts
|
|
5300
6082
|
import { createHash as createHash3 } from "crypto";
|
|
5301
6083
|
import * as fs3 from "fs";
|
|
5302
|
-
import * as
|
|
6084
|
+
import * as path4 from "path";
|
|
5303
6085
|
var WORLD_MANIFEST, API_BUNDLE_MANIFEST, BUNDLED_WORLD_PREFIX, CONNECTOR_SPEC, PYPROJECT, BENCHMARK_CONFIG, WORLD_SCHEMA_MARKERS, WORLD_ROOT_MARKERS, BROAD_ROOT_MARKERS, SKIPPED_DIRS, V1_DEP, V1_IMPORT, V1_TASKSET, HARBOR_TASK, skippedDir, byCodePoint, WorldDir;
|
|
5304
6086
|
var init_worldDir = __esm({
|
|
5305
6087
|
"src/worlds/worldDir.ts"() {
|
|
@@ -5329,17 +6111,17 @@ var init_worldDir = __esm({
|
|
|
5329
6111
|
worldRoot;
|
|
5330
6112
|
pathsMemo;
|
|
5331
6113
|
static open(dir) {
|
|
5332
|
-
const present = (rel) => fs3.existsSync(
|
|
6114
|
+
const present = (rel) => fs3.existsSync(path4.join(dir, rel));
|
|
5333
6115
|
const bundled = present(API_BUNDLE_MANIFEST) && WORLD_ROOT_MARKERS.some((m) => present(BUNDLED_WORLD_PREFIX + m));
|
|
5334
6116
|
return new _WorldDir(dir, bundled ? BUNDLED_WORLD_PREFIX : "");
|
|
5335
6117
|
}
|
|
5336
6118
|
// ── Files ──────────────────────────────────────────────────────────────
|
|
5337
6119
|
has(rel) {
|
|
5338
|
-
return fs3.existsSync(
|
|
6120
|
+
return fs3.existsSync(path4.join(this.dir, rel));
|
|
5339
6121
|
}
|
|
5340
6122
|
text(rel) {
|
|
5341
6123
|
try {
|
|
5342
|
-
return fs3.readFileSync(
|
|
6124
|
+
return fs3.readFileSync(path4.join(this.dir, rel), "utf-8");
|
|
5343
6125
|
} catch {
|
|
5344
6126
|
return null;
|
|
5345
6127
|
}
|
|
@@ -5358,7 +6140,7 @@ var init_worldDir = __esm({
|
|
|
5358
6140
|
const broad = BROAD_ROOT_MARKERS.some((m) => this.has(m));
|
|
5359
6141
|
const out = [];
|
|
5360
6142
|
const walk = (rel) => {
|
|
5361
|
-
for (const entry of fs3.readdirSync(rel ?
|
|
6143
|
+
for (const entry of fs3.readdirSync(rel ? path4.join(this.dir, rel) : this.dir, { withFileTypes: true })) {
|
|
5362
6144
|
const child = rel ? `${rel}/${entry.name}` : entry.name;
|
|
5363
6145
|
if (entry.isDirectory()) {
|
|
5364
6146
|
if (!skippedDir(entry.name)) walk(child);
|
|
@@ -5379,7 +6161,7 @@ var init_worldDir = __esm({
|
|
|
5379
6161
|
get exclusions() {
|
|
5380
6162
|
const kept = new Set(this.archivePaths);
|
|
5381
6163
|
const out = [];
|
|
5382
|
-
const filesUnder = (rel) => fs3.readdirSync(
|
|
6164
|
+
const filesUnder = (rel) => fs3.readdirSync(path4.join(this.dir, rel), { withFileTypes: true }).flatMap((entry) => {
|
|
5383
6165
|
const child = `${rel}/${entry.name}`;
|
|
5384
6166
|
if (entry.isDirectory()) return filesUnder(child);
|
|
5385
6167
|
return entry.isFile() ? [child] : [];
|
|
@@ -5410,7 +6192,7 @@ var init_worldDir = __esm({
|
|
|
5410
6192
|
const hasher = createHash3("sha256");
|
|
5411
6193
|
for (const rel of this.archivePaths) {
|
|
5412
6194
|
hasher.update(Buffer.from(`file:${rel}`, "utf-8"));
|
|
5413
|
-
hasher.update(fs3.readFileSync(
|
|
6195
|
+
hasher.update(fs3.readFileSync(path4.join(this.dir, rel)));
|
|
5414
6196
|
}
|
|
5415
6197
|
return hasher.digest("hex");
|
|
5416
6198
|
}
|
|
@@ -5475,7 +6257,7 @@ var init_worldDir = __esm({
|
|
|
5475
6257
|
|
|
5476
6258
|
// src/worlds/tar.ts
|
|
5477
6259
|
import * as fs4 from "fs";
|
|
5478
|
-
import * as
|
|
6260
|
+
import * as path5 from "path";
|
|
5479
6261
|
import { gunzipSync } from "zlib";
|
|
5480
6262
|
function archiveMode(mode) {
|
|
5481
6263
|
return (mode & 73) !== 0 ? TAR_EXEC_MODE : TAR_FILE_MODE;
|
|
@@ -5561,8 +6343,8 @@ var init_tar = __esm({
|
|
|
5561
6343
|
for (const member of this.members()) {
|
|
5562
6344
|
if (member.typeflag !== "0" && member.typeflag !== "\0") continue;
|
|
5563
6345
|
if (!_TarArchive.isConfined(member.name)) continue;
|
|
5564
|
-
const target =
|
|
5565
|
-
fs4.mkdirSync(
|
|
6346
|
+
const target = path5.join(dir, member.name);
|
|
6347
|
+
fs4.mkdirSync(path5.dirname(target), { recursive: true });
|
|
5566
6348
|
const mode = archiveMode(member.mode);
|
|
5567
6349
|
fs4.writeFileSync(target, member.bytes, { mode });
|
|
5568
6350
|
fs4.chmodSync(target, mode);
|
|
@@ -5606,7 +6388,7 @@ __export(hub_exports, {
|
|
|
5606
6388
|
import { createHash as createHash4 } from "crypto";
|
|
5607
6389
|
import { gzipSync } from "zlib";
|
|
5608
6390
|
import * as fs5 from "fs";
|
|
5609
|
-
import * as
|
|
6391
|
+
import * as path6 from "path";
|
|
5610
6392
|
function collectArchiveRelPaths(dir) {
|
|
5611
6393
|
const world = WorldDir.open(dir);
|
|
5612
6394
|
if (world.hasRootGitignore) {
|
|
@@ -5669,7 +6451,7 @@ function tarMember(name, payload, mode) {
|
|
|
5669
6451
|
function buildSourceTarball(dir) {
|
|
5670
6452
|
const parts = [];
|
|
5671
6453
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
5672
|
-
const abs =
|
|
6454
|
+
const abs = path6.join(dir, relPath);
|
|
5673
6455
|
parts.push(
|
|
5674
6456
|
...tarMember(
|
|
5675
6457
|
relPath,
|
|
@@ -5683,7 +6465,7 @@ function buildSourceTarball(dir) {
|
|
|
5683
6465
|
}
|
|
5684
6466
|
function readLocalMeta(dir) {
|
|
5685
6467
|
try {
|
|
5686
|
-
const raw = fs5.readFileSync(
|
|
6468
|
+
const raw = fs5.readFileSync(path6.join(dir, META_RELPATH), "utf-8");
|
|
5687
6469
|
const parsed = JSON.parse(raw);
|
|
5688
6470
|
return parsed && typeof parsed === "object" ? parsed : null;
|
|
5689
6471
|
} catch {
|
|
@@ -5706,16 +6488,16 @@ function resolvePushSlug(dir, opts = {}) {
|
|
|
5706
6488
|
}
|
|
5707
6489
|
const first = declared[0];
|
|
5708
6490
|
if (first) return { ...base, slug: first.slug, source: first.source };
|
|
5709
|
-
return { ...base, slug:
|
|
6491
|
+
return { ...base, slug: path6.basename(path6.resolve(dir)), source: "directory name" };
|
|
5710
6492
|
}
|
|
5711
6493
|
function writeLocalMeta(dir, meta) {
|
|
5712
|
-
fs5.mkdirSync(
|
|
5713
|
-
fs5.writeFileSync(
|
|
6494
|
+
fs5.mkdirSync(path6.join(dir, ".gateway"), { recursive: true });
|
|
6495
|
+
fs5.writeFileSync(path6.join(dir, META_RELPATH), JSON.stringify(meta, null, 2));
|
|
5714
6496
|
}
|
|
5715
6497
|
function snapshotTreeHashes(dir) {
|
|
5716
6498
|
const out = {};
|
|
5717
6499
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
5718
|
-
out[relPath] = createHash4("sha256").update(fs5.readFileSync(
|
|
6500
|
+
out[relPath] = createHash4("sha256").update(fs5.readFileSync(path6.join(dir, relPath))).digest("hex");
|
|
5719
6501
|
}
|
|
5720
6502
|
return out;
|
|
5721
6503
|
}
|
|
@@ -5733,7 +6515,7 @@ function localTreeState(dir) {
|
|
|
5733
6515
|
}
|
|
5734
6516
|
function readPyproject(dir) {
|
|
5735
6517
|
try {
|
|
5736
|
-
const text2 = fs5.readFileSync(
|
|
6518
|
+
const text2 = fs5.readFileSync(path6.join(dir, "pyproject.toml"), "utf-8");
|
|
5737
6519
|
const section = /\[project\]([\s\S]*?)(\n\[|$)/.exec(text2)?.[1] ?? "";
|
|
5738
6520
|
const name = /\bname\s*=\s*"([^"]+)"/.exec(section)?.[1];
|
|
5739
6521
|
const version = /\bversion\s*=\s*"([^"]+)"/.exec(section)?.[1];
|
|
@@ -5756,7 +6538,7 @@ function readWorldContractVersion(dir) {
|
|
|
5756
6538
|
}
|
|
5757
6539
|
function buildFileManifest(dir) {
|
|
5758
6540
|
return collectArchiveRelPaths(dir).map((relPath) => {
|
|
5759
|
-
const payload = fs5.readFileSync(
|
|
6541
|
+
const payload = fs5.readFileSync(path6.join(dir, relPath));
|
|
5760
6542
|
return {
|
|
5761
6543
|
path: relPath,
|
|
5762
6544
|
isDirectory: false,
|
|
@@ -5802,7 +6584,7 @@ async function push(dir, opts = {}) {
|
|
|
5802
6584
|
const pyproject = readPyproject(dir);
|
|
5803
6585
|
const contractVersion = pyproject.version ? void 0 : readWorldContractVersion(dir).version;
|
|
5804
6586
|
if (contractVersion) pyproject.version = contractVersion;
|
|
5805
|
-
const slug = opts.slug ?? localMeta.slug ?? pyproject.name ??
|
|
6587
|
+
const slug = opts.slug ?? localMeta.slug ?? pyproject.name ?? path6.basename(path6.resolve(dir));
|
|
5806
6588
|
const metadata = {
|
|
5807
6589
|
...opts.name !== void 0 ? { name: opts.name } : {},
|
|
5808
6590
|
...opts.description !== void 0 ? { description: opts.description } : {},
|
|
@@ -5928,7 +6710,7 @@ async function propose(dir, opts) {
|
|
|
5928
6710
|
if (state2.clean)
|
|
5929
6711
|
throw new Error("Nothing to propose \u2014 the tree matches its base.");
|
|
5930
6712
|
const changes = state2.dirty.map((relPath) => {
|
|
5931
|
-
const abs =
|
|
6713
|
+
const abs = path6.join(dir, relPath);
|
|
5932
6714
|
if (!fs5.existsSync(abs))
|
|
5933
6715
|
return { path: relPath, action: "delete" };
|
|
5934
6716
|
return {
|
|
@@ -5969,7 +6751,7 @@ var init_hub = __esm({
|
|
|
5969
6751
|
init_worldDir();
|
|
5970
6752
|
init_tar();
|
|
5971
6753
|
DEFAULT_BRANCH = "main";
|
|
5972
|
-
META_RELPATH =
|
|
6754
|
+
META_RELPATH = path6.join(".gateway", ".env-metadata.json");
|
|
5973
6755
|
FILE_MODE = TAR_FILE_MODE;
|
|
5974
6756
|
MINTED_SUFFIX = /^-\d+$/;
|
|
5975
6757
|
PushSlugConflict = class extends Error {
|
|
@@ -6197,7 +6979,7 @@ function rebaseConflicts(error) {
|
|
|
6197
6979
|
}
|
|
6198
6980
|
const conflicts = body?.conflicts;
|
|
6199
6981
|
if (!Array.isArray(conflicts)) return null;
|
|
6200
|
-
return conflicts.filter(isConflictPath).map(({ path:
|
|
6982
|
+
return conflicts.filter(isConflictPath).map(({ path: path13, reason }) => ({ path: path13, reason }));
|
|
6201
6983
|
}
|
|
6202
6984
|
function isConflictPath(value) {
|
|
6203
6985
|
const entry = value;
|
|
@@ -6237,8 +7019,8 @@ var init_sandbox = __esm({
|
|
|
6237
7019
|
this.options = options;
|
|
6238
7020
|
}
|
|
6239
7021
|
options;
|
|
6240
|
-
request(method,
|
|
6241
|
-
return apiRequest(this.options, method,
|
|
7022
|
+
request(method, path13, body) {
|
|
7023
|
+
return apiRequest(this.options, method, path13, body, {
|
|
6242
7024
|
timeoutMs: SANDBOX_REQUEST_TIMEOUT_MS
|
|
6243
7025
|
});
|
|
6244
7026
|
}
|
|
@@ -6769,6 +7551,17 @@ async function queryRows(slugRef, entity, opts = {}, options = {}) {
|
|
|
6769
7551
|
`/api/public/worlds/${encodeURIComponent(slug)}/data${queryRowsSearch(entity, opts, ref)}`
|
|
6770
7552
|
);
|
|
6771
7553
|
}
|
|
7554
|
+
async function sqlRows(slugRef, sql, opts = {}, options = {}) {
|
|
7555
|
+
const [slug, ref] = slugRef.split("@", 2);
|
|
7556
|
+
if (!slug || ref === "") throw new Error(`sqlRows needs a slug, optionally slug@ref (got ${slugRef})`);
|
|
7557
|
+
if (!sql.trim()) throw new Error("sqlRows needs one SQL statement");
|
|
7558
|
+
return apiRequest(options, "POST", `/api/public/worlds/${encodeURIComponent(slug)}/data/sql`, {
|
|
7559
|
+
sql,
|
|
7560
|
+
...ref ? { ref } : {},
|
|
7561
|
+
...opts.limit !== void 0 ? { limit: opts.limit } : {},
|
|
7562
|
+
...opts.scenario ? { scenario: opts.scenario } : {}
|
|
7563
|
+
});
|
|
7564
|
+
}
|
|
6772
7565
|
var init_query = __esm({
|
|
6773
7566
|
"src/worlds/query.ts"() {
|
|
6774
7567
|
"use strict";
|
|
@@ -6825,7 +7618,7 @@ var init_router = __esm({
|
|
|
6825
7618
|
// src/cli/config.ts
|
|
6826
7619
|
import * as fs6 from "fs";
|
|
6827
7620
|
import * as os from "os";
|
|
6828
|
-
import * as
|
|
7621
|
+
import * as path7 from "path";
|
|
6829
7622
|
async function api(creds, method, route, body, init2 = {}) {
|
|
6830
7623
|
const reply = await new PlatformTransport(creds).send(method, route, body, init2);
|
|
6831
7624
|
if (!reply.ok) throw new ApiError2(reply.status, method, route, reply.text);
|
|
@@ -6861,7 +7654,7 @@ var init_config = __esm({
|
|
|
6861
7654
|
import { spawn, spawnSync } from "child_process";
|
|
6862
7655
|
import * as fs7 from "fs";
|
|
6863
7656
|
import * as net from "net";
|
|
6864
|
-
import * as
|
|
7657
|
+
import * as path8 from "path";
|
|
6865
7658
|
function tailOf(output) {
|
|
6866
7659
|
return output.length > DIAGNOSTIC_TAIL ? `\u2026${output.slice(-DIAGNOSTIC_TAIL)}` : output;
|
|
6867
7660
|
}
|
|
@@ -6876,16 +7669,16 @@ function runtimeRoot() {
|
|
|
6876
7669
|
const candidates = [];
|
|
6877
7670
|
if (process.env.GATEWAY_RUNTIME_PATH)
|
|
6878
7671
|
candidates.push(process.env.GATEWAY_RUNTIME_PATH);
|
|
6879
|
-
const entry = process.argv[1] && fs7.existsSync(process.argv[1]) ?
|
|
7672
|
+
const entry = process.argv[1] && fs7.existsSync(process.argv[1]) ? path8.dirname(fs7.realpathSync(process.argv[1])) : null;
|
|
6880
7673
|
if (entry) {
|
|
6881
|
-
candidates.push(
|
|
6882
|
-
candidates.push(
|
|
6883
|
-
candidates.push(
|
|
7674
|
+
candidates.push(path8.resolve(entry, "..", "runtime"));
|
|
7675
|
+
candidates.push(path8.resolve(entry, "..", "..", "runtime"));
|
|
7676
|
+
candidates.push(path8.resolve(entry, "..", "..", "sdk", "src"));
|
|
6884
7677
|
}
|
|
6885
|
-
candidates.push(
|
|
7678
|
+
candidates.push(path8.resolve(process.cwd(), "runtime"));
|
|
6886
7679
|
for (const root of candidates)
|
|
6887
7680
|
if (fs7.existsSync(
|
|
6888
|
-
|
|
7681
|
+
path8.join(root, "gatewaysdk", "environment", "schema", "platform.py")
|
|
6889
7682
|
))
|
|
6890
7683
|
return root;
|
|
6891
7684
|
return null;
|
|
@@ -6974,13 +7767,12 @@ async function localBridge(request, local, opts = {}) {
|
|
|
6974
7767
|
["-I", "-B", "-c", BRIDGE_BOOTSTRAP, local.root],
|
|
6975
7768
|
{
|
|
6976
7769
|
stdio: ["pipe", "pipe", "pipe"],
|
|
6977
|
-
//
|
|
6978
|
-
// place the runtime may import and run a world's own Python (check's
|
|
6979
|
-
// handler execution, `worlds call`, `worlds test` tool cases).
|
|
7770
|
+
// The author's machine running the author's world: the one place the runtime may run its Python.
|
|
6980
7771
|
env: {
|
|
6981
7772
|
PATH: process.env.PATH ?? "",
|
|
6982
7773
|
HOME: process.env.HOME ?? "",
|
|
6983
7774
|
TMPDIR: process.env.TMPDIR ?? "",
|
|
7775
|
+
...process.env.VIRTUAL_ENV ? { VIRTUAL_ENV: process.env.VIRTUAL_ENV } : {},
|
|
6984
7776
|
GATEWAY_RUNTIME_EXECUTE: "1"
|
|
6985
7777
|
}
|
|
6986
7778
|
}
|
|
@@ -7026,13 +7818,14 @@ async function localBridge(request, local, opts = {}) {
|
|
|
7026
7818
|
child.stdin.end(input);
|
|
7027
7819
|
});
|
|
7028
7820
|
}
|
|
7029
|
-
var MIN_PYTHON, DIAGNOSTIC_TAIL, BRIDGE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
|
|
7821
|
+
var MIN_PYTHON, MIN_PYTHON_LABEL, DIAGNOSTIC_TAIL, BRIDGE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
|
|
7030
7822
|
var init_local = __esm({
|
|
7031
7823
|
"src/cli/runtime/local.ts"() {
|
|
7032
7824
|
"use strict";
|
|
7033
7825
|
init_router();
|
|
7034
7826
|
init_config();
|
|
7035
7827
|
MIN_PYTHON = [3, 12];
|
|
7828
|
+
MIN_PYTHON_LABEL = MIN_PYTHON.join(".");
|
|
7036
7829
|
DIAGNOSTIC_TAIL = 600;
|
|
7037
7830
|
BRIDGE_BOOTSTRAP = `import sys,runpy,types,os
|
|
7038
7831
|
root=sys.argv[1]
|
|
@@ -7051,18 +7844,46 @@ runpy.run_module('gatewaysdk.environment.schema.platform',run_name='__main__')`;
|
|
|
7051
7844
|
}
|
|
7052
7845
|
});
|
|
7053
7846
|
|
|
7847
|
+
// src/worlds/databaseEngines.ts
|
|
7848
|
+
function isWorldSnapshotOutput(path13) {
|
|
7849
|
+
return SNAPSHOT_OUTPUTS.has(path13.slice(path13.lastIndexOf("/") + 1));
|
|
7850
|
+
}
|
|
7851
|
+
var WORLD_DATABASE_ENGINES, DEFAULT_WORLD_DATABASE_ENGINE, WORLD_SNAPSHOT_FILE_PATH, WORLD_SNAPSHOT_SIDECAR_PATH, WORLD_SNAPSHOT_CONTENT_TYPE, SNAPSHOT_OUTPUTS;
|
|
7852
|
+
var init_databaseEngines = __esm({
|
|
7853
|
+
"src/worlds/databaseEngines.ts"() {
|
|
7854
|
+
"use strict";
|
|
7855
|
+
WORLD_DATABASE_ENGINES = [
|
|
7856
|
+
{
|
|
7857
|
+
engine: "sqlite",
|
|
7858
|
+
label: "SQLite",
|
|
7859
|
+
target: "sqlite-json/1",
|
|
7860
|
+
snapshotName: "state.sqlite",
|
|
7861
|
+
contentType: "application/vnd.sqlite3"
|
|
7862
|
+
}
|
|
7863
|
+
];
|
|
7864
|
+
DEFAULT_WORLD_DATABASE_ENGINE = WORLD_DATABASE_ENGINES[0];
|
|
7865
|
+
WORLD_SNAPSHOT_FILE_PATH = `db/${DEFAULT_WORLD_DATABASE_ENGINE.snapshotName}`;
|
|
7866
|
+
WORLD_SNAPSHOT_SIDECAR_PATH = "db/state.json";
|
|
7867
|
+
WORLD_SNAPSHOT_CONTENT_TYPE = DEFAULT_WORLD_DATABASE_ENGINE.contentType;
|
|
7868
|
+
SNAPSHOT_OUTPUTS = /* @__PURE__ */ new Set([
|
|
7869
|
+
...WORLD_DATABASE_ENGINES.map((engine) => engine.snapshotName),
|
|
7870
|
+
WORLD_SNAPSHOT_SIDECAR_PATH.slice("db/".length)
|
|
7871
|
+
]);
|
|
7872
|
+
}
|
|
7873
|
+
});
|
|
7874
|
+
|
|
7054
7875
|
// src/cli/runtime/client.ts
|
|
7055
7876
|
import * as fs8 from "fs";
|
|
7056
|
-
import * as
|
|
7877
|
+
import * as path9 from "path";
|
|
7057
7878
|
function isBuildOutput(relPath) {
|
|
7058
|
-
return
|
|
7879
|
+
return isWorldSnapshotOutput(relPath);
|
|
7059
7880
|
}
|
|
7060
7881
|
function readWorldFiles(dir, opts = {}) {
|
|
7061
7882
|
if (!fs8.existsSync(dir) || !fs8.statSync(dir).isDirectory())
|
|
7062
7883
|
throw new CliError(`Not a directory: ${dir}`);
|
|
7063
7884
|
const out = [];
|
|
7064
7885
|
const walk = (rel) => {
|
|
7065
|
-
const abs = rel ?
|
|
7886
|
+
const abs = rel ? path9.join(dir, rel) : dir;
|
|
7066
7887
|
const entries = fs8.readdirSync(abs, { withFileTypes: true });
|
|
7067
7888
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
7068
7889
|
for (const entry of entries) {
|
|
@@ -7073,7 +7894,7 @@ function readWorldFiles(dir, opts = {}) {
|
|
|
7073
7894
|
if (!opts.buildOutputs && isBuildOutput(childRel)) continue;
|
|
7074
7895
|
out.push({
|
|
7075
7896
|
path: childRel,
|
|
7076
|
-
content: fs8.readFileSync(
|
|
7897
|
+
content: fs8.readFileSync(path9.join(dir, childRel)).toString("base64")
|
|
7077
7898
|
});
|
|
7078
7899
|
}
|
|
7079
7900
|
}
|
|
@@ -7093,15 +7914,15 @@ function writeWorldFiles(dir, files, opts = {}) {
|
|
|
7093
7914
|
if (opts.clean && fs8.existsSync(dir)) {
|
|
7094
7915
|
const keep = new Set(files.map((f) => f.path));
|
|
7095
7916
|
for (const existing of readWorldFiles(dir)) {
|
|
7096
|
-
if (!keep.has(existing.path)) fs8.rmSync(
|
|
7917
|
+
if (!keep.has(existing.path)) fs8.rmSync(path9.join(dir, existing.path));
|
|
7097
7918
|
}
|
|
7098
7919
|
pruneEmptyDirs(dir);
|
|
7099
7920
|
}
|
|
7100
7921
|
fs8.mkdirSync(dir, { recursive: true });
|
|
7101
7922
|
const written = [];
|
|
7102
7923
|
for (const file of files) {
|
|
7103
|
-
const target =
|
|
7104
|
-
fs8.mkdirSync(
|
|
7924
|
+
const target = path9.join(dir, file.path);
|
|
7925
|
+
fs8.mkdirSync(path9.dirname(target), { recursive: true });
|
|
7105
7926
|
fs8.writeFileSync(target, Buffer.from(file.content, "base64"));
|
|
7106
7927
|
written.push(file.path);
|
|
7107
7928
|
}
|
|
@@ -7111,7 +7932,7 @@ function pruneEmptyDirs(root) {
|
|
|
7111
7932
|
const walk = (abs) => {
|
|
7112
7933
|
let empty = true;
|
|
7113
7934
|
for (const entry of fs8.readdirSync(abs, { withFileTypes: true })) {
|
|
7114
|
-
const child =
|
|
7935
|
+
const child = path9.join(abs, entry.name);
|
|
7115
7936
|
if (entry.isDirectory()) {
|
|
7116
7937
|
if (SKIP_DIRS.has(entry.name)) {
|
|
7117
7938
|
empty = false;
|
|
@@ -7148,13 +7969,9 @@ function yamlDocument(request) {
|
|
|
7148
7969
|
return isYamlSource(String(request.source ?? ""), String(request.document ?? ""));
|
|
7149
7970
|
return request.command === "conform" && Array.isArray(request.openapi) && request.openapi.some((doc) => YAML_NAME.test(doc.path ?? ""));
|
|
7150
7971
|
}
|
|
7151
|
-
function runsLocally(request) {
|
|
7152
|
-
const local = localRuntime();
|
|
7153
|
-
return local !== null && !(yamlDocument(request) && !localPythonHasYaml(local.python));
|
|
7154
|
-
}
|
|
7155
7972
|
async function runtime(creds, request, opts = {}) {
|
|
7156
|
-
const local =
|
|
7157
|
-
if (local
|
|
7973
|
+
const local = new RuntimeRoute().local(request);
|
|
7974
|
+
if (local) {
|
|
7158
7975
|
const payload2 = await localBridge(request, local, opts);
|
|
7159
7976
|
const detail2 = detailFrom(payload2);
|
|
7160
7977
|
if (detail2) throw new BridgeRejected(detail2);
|
|
@@ -7181,17 +7998,17 @@ async function runtime(creds, request, opts = {}) {
|
|
|
7181
7998
|
if (payload === null) throw new CliError(`POST ${route} (${request.command}) returned non-JSON`, 1);
|
|
7182
7999
|
return payload;
|
|
7183
8000
|
}
|
|
7184
|
-
var MAX_WORLD_FILES, RUNTIME_TIMEOUT_MS, SKIP_DIRS,
|
|
8001
|
+
var MAX_WORLD_FILES, RUNTIME_TIMEOUT_MS, SKIP_DIRS, BridgeRejected, YAML_NAME, YAML_NEEDS_PYYAML, YAML_NOT_ON_PLATFORM, RuntimeRoute;
|
|
7185
8002
|
var init_client = __esm({
|
|
7186
8003
|
"src/cli/runtime/client.ts"() {
|
|
7187
8004
|
"use strict";
|
|
7188
8005
|
init_router();
|
|
7189
8006
|
init_local();
|
|
7190
8007
|
init_transport();
|
|
8008
|
+
init_databaseEngines();
|
|
7191
8009
|
MAX_WORLD_FILES = 2e3;
|
|
7192
8010
|
RUNTIME_TIMEOUT_MS = 18e4;
|
|
7193
8011
|
SKIP_DIRS = /* @__PURE__ */ new Set(["__pycache__", ".git", "node_modules", ".gateway"]);
|
|
7194
|
-
BUILD_OUTPUT = /(^|\/)state\.(sqlite|json)$/;
|
|
7195
8012
|
BridgeRejected = class extends CliError {
|
|
7196
8013
|
constructor(detail) {
|
|
7197
8014
|
super(formatBridgeError(detail), 1);
|
|
@@ -7200,6 +8017,26 @@ var init_client = __esm({
|
|
|
7200
8017
|
detail;
|
|
7201
8018
|
};
|
|
7202
8019
|
YAML_NAME = /\.ya?ml$/i;
|
|
8020
|
+
YAML_NEEDS_PYYAML = "Reading a YAML document needs PyYAML in the Python that runs the schema runtime: pip install pyyaml there, set GATEWAY_PYTHON to an interpreter that has it, or convert the document to JSON";
|
|
8021
|
+
YAML_NOT_ON_PLATFORM = "The platform's schema runtime reads JSON documents only: convert the document to JSON, or read it here with GATEWAY_RUNTIME=local and a Python that has PyYAML (pip install pyyaml, or set GATEWAY_PYTHON to one)";
|
|
8022
|
+
RuntimeRoute = class _RuntimeRoute {
|
|
8023
|
+
constructor(here = localRuntime, hasYaml = localPythonHasYaml) {
|
|
8024
|
+
this.here = here;
|
|
8025
|
+
this.hasYaml = hasYaml;
|
|
8026
|
+
}
|
|
8027
|
+
here;
|
|
8028
|
+
hasYaml;
|
|
8029
|
+
local(request) {
|
|
8030
|
+
const local = this.here();
|
|
8031
|
+
const yaml = yamlDocument(request);
|
|
8032
|
+
if (yaml && local === null) throw _RuntimeRoute.refusal(YAML_NOT_ON_PLATFORM);
|
|
8033
|
+
if (yaml && local !== null && !this.hasYaml(local.python)) throw _RuntimeRoute.refusal(YAML_NEEDS_PYYAML);
|
|
8034
|
+
return local;
|
|
8035
|
+
}
|
|
8036
|
+
static refusal(message) {
|
|
8037
|
+
return new BridgeRejected({ code: "conform", message, schema_path: "/openapi/source" });
|
|
8038
|
+
}
|
|
8039
|
+
};
|
|
7203
8040
|
}
|
|
7204
8041
|
});
|
|
7205
8042
|
|
|
@@ -7214,10 +8051,11 @@ __export(data_exports, {
|
|
|
7214
8051
|
ingestLocalToolCalls: () => ingestLocalToolCalls,
|
|
7215
8052
|
queryLocalWorldData: () => queryLocalWorldData,
|
|
7216
8053
|
queryLocalWorldDataAcross: () => queryLocalWorldDataAcross,
|
|
7217
|
-
showLocalWorldData: () => showLocalWorldData
|
|
8054
|
+
showLocalWorldData: () => showLocalWorldData,
|
|
8055
|
+
sqlLocalWorldData: () => sqlLocalWorldData
|
|
7218
8056
|
});
|
|
7219
8057
|
import * as fs9 from "fs";
|
|
7220
|
-
import * as
|
|
8058
|
+
import * as path10 from "path";
|
|
7221
8059
|
async function importLocalWorldData(dir, rows, opts, creds) {
|
|
7222
8060
|
const res = await runtime(creds, {
|
|
7223
8061
|
command: "import-data",
|
|
@@ -7248,8 +8086,8 @@ async function importLocalWorldFiles(dir, sources, opts) {
|
|
|
7248
8086
|
);
|
|
7249
8087
|
const res = await runtime(null, {
|
|
7250
8088
|
command: "import-files",
|
|
7251
|
-
world:
|
|
7252
|
-
sources: sources.map((source) =>
|
|
8089
|
+
world: path10.resolve(dir),
|
|
8090
|
+
sources: sources.map((source) => path10.resolve(source)),
|
|
7253
8091
|
mode: opts.mode ?? "append",
|
|
7254
8092
|
...opts.entity ? { entity: opts.entity } : {},
|
|
7255
8093
|
...opts.delimiter ? { delimiter: opts.delimiter } : {},
|
|
@@ -7275,9 +8113,9 @@ async function chunkLocalWorldFiles(dir, sources, out, opts) {
|
|
|
7275
8113
|
);
|
|
7276
8114
|
const res = await runtime(null, {
|
|
7277
8115
|
command: "chunk-files",
|
|
7278
|
-
world:
|
|
7279
|
-
sources: sources.map((source) =>
|
|
7280
|
-
out:
|
|
8116
|
+
world: path10.resolve(dir),
|
|
8117
|
+
sources: sources.map((source) => path10.resolve(source)),
|
|
8118
|
+
out: path10.resolve(out),
|
|
7281
8119
|
...opts.entity ? { entity: opts.entity } : {},
|
|
7282
8120
|
...opts.delimiter ? { delimiter: opts.delimiter } : {},
|
|
7283
8121
|
...opts.chunkBytes ? { chunk_bytes: opts.chunkBytes } : {},
|
|
@@ -7288,8 +8126,8 @@ async function chunkLocalWorldFiles(dir, sources, out, opts) {
|
|
|
7288
8126
|
function dropBuildOutputs(dir) {
|
|
7289
8127
|
const dropped = [];
|
|
7290
8128
|
for (const file of readWorldFiles(dir, { buildOutputs: true })) {
|
|
7291
|
-
if (!
|
|
7292
|
-
fs9.rmSync(
|
|
8129
|
+
if (!isBuildOutput(file.path)) continue;
|
|
8130
|
+
fs9.rmSync(path10.join(dir, file.path), { force: true });
|
|
7293
8131
|
dropped.push(file.path);
|
|
7294
8132
|
}
|
|
7295
8133
|
return dropped;
|
|
@@ -7356,7 +8194,7 @@ async function queryLocalWorldDataAcross(dir, entity, where, opts) {
|
|
|
7356
8194
|
const payload = await localBridge(
|
|
7357
8195
|
{
|
|
7358
8196
|
command: "query",
|
|
7359
|
-
world:
|
|
8197
|
+
world: path10.resolve(dir),
|
|
7360
8198
|
entity,
|
|
7361
8199
|
across: true,
|
|
7362
8200
|
...opts.compare ? { compare: true } : {},
|
|
@@ -7372,6 +8210,28 @@ async function queryLocalWorldDataAcross(dir, entity, where, opts) {
|
|
|
7372
8210
|
if (detail) throw new BridgeRejected(detail);
|
|
7373
8211
|
return payload;
|
|
7374
8212
|
}
|
|
8213
|
+
async function sqlLocalWorldData(dir, sql, opts) {
|
|
8214
|
+
const local = localRuntime();
|
|
8215
|
+
if (!local)
|
|
8216
|
+
throw new CliError(
|
|
8217
|
+
"`worlds data sql` on a directory reads the world's database in place, so it needs the bundled runtime on this machine. " + localRuntimeReason(),
|
|
8218
|
+
1
|
|
8219
|
+
);
|
|
8220
|
+
const payload = await localBridge(
|
|
8221
|
+
{
|
|
8222
|
+
command: "sql",
|
|
8223
|
+
world: path10.resolve(dir),
|
|
8224
|
+
sql,
|
|
8225
|
+
...opts.limit !== void 0 ? { limit: opts.limit } : {},
|
|
8226
|
+
...opts.scenario ? { scenario: opts.scenario } : {}
|
|
8227
|
+
},
|
|
8228
|
+
local
|
|
8229
|
+
);
|
|
8230
|
+
const detail = detailFrom(payload);
|
|
8231
|
+
if (detail) throw new BridgeRejected(detail);
|
|
8232
|
+
const { status: _status, ...answer } = payload;
|
|
8233
|
+
return answer;
|
|
8234
|
+
}
|
|
7375
8235
|
async function ingestLocalToolCalls(dir, records, opts, creds) {
|
|
7376
8236
|
const res = await runtime(creds, {
|
|
7377
8237
|
command: "ingest-calls",
|
|
@@ -7403,14 +8263,12 @@ async function ingestLocalToolCalls(dir, records, opts, creds) {
|
|
|
7403
8263
|
...res.batch !== void 0 ? { batch: res.batch } : {}
|
|
7404
8264
|
};
|
|
7405
8265
|
}
|
|
7406
|
-
var BUILD_OUTPUT2;
|
|
7407
8266
|
var init_data = __esm({
|
|
7408
8267
|
"src/cli/runtime/data.ts"() {
|
|
7409
8268
|
"use strict";
|
|
7410
8269
|
init_router();
|
|
7411
8270
|
init_client();
|
|
7412
8271
|
init_local();
|
|
7413
|
-
BUILD_OUTPUT2 = /(^|\/)state\.(sqlite|json)$/;
|
|
7414
8272
|
}
|
|
7415
8273
|
});
|
|
7416
8274
|
|
|
@@ -7429,7 +8287,7 @@ __export(transform_exports, {
|
|
|
7429
8287
|
import { spawn as spawn2 } from "child_process";
|
|
7430
8288
|
import * as fs10 from "fs";
|
|
7431
8289
|
import * as os2 from "os";
|
|
7432
|
-
import * as
|
|
8290
|
+
import * as path11 from "path";
|
|
7433
8291
|
import { createRequire } from "module";
|
|
7434
8292
|
function checkRows(value, where) {
|
|
7435
8293
|
if (!isObject(value)) throw new CliError(`${where} must return {entity: [rows]}; got ${value === null ? "null" : Array.isArray(value) ? "an array" : typeof value}`, 1);
|
|
@@ -7454,27 +8312,27 @@ function typescriptPrefix() {
|
|
|
7454
8312
|
}
|
|
7455
8313
|
}
|
|
7456
8314
|
function command(script, wrapperDir) {
|
|
7457
|
-
const suffix =
|
|
8315
|
+
const suffix = path11.extname(script).toLowerCase();
|
|
7458
8316
|
if (PYTHON_SUFFIXES.includes(suffix)) return { file: process.env.GATEWAY_PYTHON || "python3", args: ["-c", PY_WRAPPER, script] };
|
|
7459
8317
|
if (NODE_SUFFIXES.includes(suffix)) {
|
|
7460
|
-
const wrapper =
|
|
8318
|
+
const wrapper = path11.join(wrapperDir, "transform-wrapper.mjs");
|
|
7461
8319
|
fs10.writeFileSync(wrapper, NODE_WRAPPER);
|
|
7462
8320
|
const flags = suffix === ".ts" || suffix === ".mts" ? typescriptPrefix() : [];
|
|
7463
8321
|
return { file: process.env.GATEWAY_NODE || process.execPath, args: [...flags, wrapper, script] };
|
|
7464
8322
|
}
|
|
7465
|
-
throw new CliError(`${
|
|
8323
|
+
throw new CliError(`${path11.basename(script)}: a transform script is .py, .ts, .mjs, .js or .cjs`, 1);
|
|
7466
8324
|
}
|
|
7467
8325
|
async function runTransform(script, records, opts = {}) {
|
|
7468
8326
|
if (!fs10.existsSync(script) || !fs10.statSync(script).isFile()) throw new CliError(`no transform script at ${script}`, 1);
|
|
7469
|
-
const resolved =
|
|
7470
|
-
const name =
|
|
8327
|
+
const resolved = path11.resolve(script);
|
|
8328
|
+
const name = path11.basename(script);
|
|
7471
8329
|
const timeoutMs = opts.timeoutMs ?? DEFAULT_TRANSFORM_TIMEOUT_MS;
|
|
7472
|
-
const scratch = fs10.mkdtempSync(
|
|
8330
|
+
const scratch = fs10.mkdtempSync(path11.join(os2.tmpdir(), "gateway-transform-"));
|
|
7473
8331
|
try {
|
|
7474
8332
|
const { file, args } = command(resolved, scratch);
|
|
7475
8333
|
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !SCRUBBED.test(key)));
|
|
7476
8334
|
const done = await new Promise((resolve7, reject) => {
|
|
7477
|
-
const child = spawn2(file, args, { cwd:
|
|
8335
|
+
const child = spawn2(file, args, { cwd: path11.dirname(resolved), env, stdio: ["pipe", "pipe", "pipe"] });
|
|
7478
8336
|
let stdout = "";
|
|
7479
8337
|
let stderr = "";
|
|
7480
8338
|
let timedOut = false;
|
|
@@ -7635,7 +8493,7 @@ async function forEachLimited(items, limit, fn) {
|
|
|
7635
8493
|
if (failure) throw failure;
|
|
7636
8494
|
}
|
|
7637
8495
|
async function waitForBatch(client, batchId, opts = {}) {
|
|
7638
|
-
const
|
|
8496
|
+
const sleep4 = opts.sleep ?? client.sleep;
|
|
7639
8497
|
let delay = opts.initialDelayMs ?? 1e3;
|
|
7640
8498
|
let last = "";
|
|
7641
8499
|
for (; ; ) {
|
|
@@ -7646,7 +8504,7 @@ async function waitForBatch(client, batchId, opts = {}) {
|
|
|
7646
8504
|
last = phase;
|
|
7647
8505
|
}
|
|
7648
8506
|
if (isSettled(status)) return status;
|
|
7649
|
-
await
|
|
8507
|
+
await sleep4(delay);
|
|
7650
8508
|
delay = Math.min(1e4, Math.round(delay * 1.5));
|
|
7651
8509
|
}
|
|
7652
8510
|
}
|
|
@@ -7668,10 +8526,10 @@ var init_batches = __esm({
|
|
|
7668
8526
|
]);
|
|
7669
8527
|
sleepMs = (ms) => new Promise((resolve7) => setTimeout(resolve7, ms));
|
|
7670
8528
|
WorldDataApi = class {
|
|
7671
|
-
constructor(creds, slug,
|
|
8529
|
+
constructor(creds, slug, sleep4 = sleepMs) {
|
|
7672
8530
|
this.creds = creds;
|
|
7673
8531
|
this.slug = slug;
|
|
7674
|
-
this.sleep =
|
|
8532
|
+
this.sleep = sleep4;
|
|
7675
8533
|
this.base = `/api/public/worlds/${encodeURIComponent(slug)}/data`;
|
|
7676
8534
|
}
|
|
7677
8535
|
creds;
|
|
@@ -7954,7 +8812,7 @@ var init_push = __esm({
|
|
|
7954
8812
|
// src/worlds/ingest.ts
|
|
7955
8813
|
import * as fs12 from "fs";
|
|
7956
8814
|
import * as os3 from "os";
|
|
7957
|
-
import * as
|
|
8815
|
+
import * as path12 from "path";
|
|
7958
8816
|
function parseToolCallRecord(raw) {
|
|
7959
8817
|
const none = { record: null, skip: null };
|
|
7960
8818
|
if (!isObject2(raw)) return { ...none, refusal: "record is not an object" };
|
|
@@ -8078,19 +8936,13 @@ function toolCallsFromObservations(observations, opts = {}) {
|
|
|
8078
8936
|
}
|
|
8079
8937
|
return out;
|
|
8080
8938
|
}
|
|
8081
|
-
function credentialsOf(options) {
|
|
8082
|
-
const host = (options.host ?? process.env.GATEWAY_HOST ?? "https://withgateway.ai").replace(/\/+$/, "");
|
|
8083
|
-
const publicKey = options.publicKey ?? process.env.GATEWAY_PUBLIC_KEY;
|
|
8084
|
-
const secretKey = options.secretKey ?? process.env.GATEWAY_SECRET_KEY;
|
|
8085
|
-
return publicKey && secretKey ? { host, publicKey, secretKey } : null;
|
|
8086
|
-
}
|
|
8087
8939
|
async function ingest(world, records, options = {}) {
|
|
8088
8940
|
const { ingestLocalToolCalls: ingestLocalToolCalls2, importLocalWorldData: importLocalWorldData2, checkLocalWorldData: checkLocalWorldData2 } = await Promise.resolve().then(() => (init_data(), data_exports));
|
|
8089
8941
|
if (options.transform !== void 0 && options.map !== void 0) throw new Error("records go through one of transform, map");
|
|
8090
8942
|
const redact = options.redact ?? "off";
|
|
8091
8943
|
const mode = options.mode ?? "append";
|
|
8092
8944
|
const dryRun = Boolean(options.dryRun);
|
|
8093
|
-
const creds =
|
|
8945
|
+
const creds = platformEndpoint(options);
|
|
8094
8946
|
const local = fs12.existsSync(world) && fs12.statSync(world).isDirectory();
|
|
8095
8947
|
const map = options.map === void 0 ? void 0 : options.map;
|
|
8096
8948
|
let rows = null;
|
|
@@ -8104,12 +8956,12 @@ async function ingest(world, records, options = {}) {
|
|
|
8104
8956
|
const landed = dryRun ? await checkLocalWorldData2(world, rows, creds, { redact }) : await importLocalWorldData2(world, rows, { mode, redact }, creds);
|
|
8105
8957
|
return transformReport(world, records.length, rows, stderr, { dryRun, redact, changed: !dryRun && landed.changed, kind: landed.kind, entityCounts: landed.entity_counts });
|
|
8106
8958
|
}
|
|
8107
|
-
if (!creds) throw new Error(
|
|
8959
|
+
if (!creds) throw new Error(GATEWAY_KEYS_MISSING);
|
|
8108
8960
|
const { pull: pull2 } = await Promise.resolve().then(() => (init_hub(), hub_exports));
|
|
8109
8961
|
const slug = world.split("@", 1)[0];
|
|
8110
|
-
const scratch = fs12.mkdtempSync(
|
|
8962
|
+
const scratch = fs12.mkdtempSync(path12.join(os3.tmpdir(), "gateway-ingest-"));
|
|
8111
8963
|
try {
|
|
8112
|
-
const pulled = await pull2(world,
|
|
8964
|
+
const pulled = await pull2(world, path12.join(scratch, slug), options);
|
|
8113
8965
|
let report;
|
|
8114
8966
|
let projected;
|
|
8115
8967
|
if (rows === null) {
|
|
@@ -8188,6 +9040,7 @@ var init_ingest = __esm({
|
|
|
8188
9040
|
"src/worlds/ingest.ts"() {
|
|
8189
9041
|
"use strict";
|
|
8190
9042
|
init_worlds();
|
|
9043
|
+
init_platformEndpoint();
|
|
8191
9044
|
isObject2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8192
9045
|
isoOf = (value) => value instanceof Date ? value.toISOString() : typeof value === "string" ? value : void 0;
|
|
8193
9046
|
}
|
|
@@ -8288,7 +9141,7 @@ var init_dryRun = __esm({
|
|
|
8288
9141
|
/** Poll until the run settles or `timeoutSeconds` pass; the last verdict either way. */
|
|
8289
9142
|
async settle(runId, opts) {
|
|
8290
9143
|
const now = opts.now ?? Date.now;
|
|
8291
|
-
const
|
|
9144
|
+
const sleep4 = opts.sleep ?? ((ms) => new Promise((resolve7) => setTimeout(resolve7, ms)));
|
|
8292
9145
|
const deadline = now() + opts.timeoutSeconds * 1e3;
|
|
8293
9146
|
for (; ; ) {
|
|
8294
9147
|
const budget = Math.floor(
|
|
@@ -8298,7 +9151,7 @@ var init_dryRun = __esm({
|
|
|
8298
9151
|
const verdict = await this.status(runId, budget);
|
|
8299
9152
|
if (verdict.settled || now() >= deadline) return verdict;
|
|
8300
9153
|
opts.onProgress?.(verdict);
|
|
8301
|
-
if (now() - asked < 1e3) await
|
|
9154
|
+
if (now() - asked < 1e3) await sleep4(1e3);
|
|
8302
9155
|
}
|
|
8303
9156
|
}
|
|
8304
9157
|
};
|
|
@@ -8366,6 +9219,8 @@ __export(worlds_exports, {
|
|
|
8366
9219
|
EXPLORATORY_TASK: () => EXPLORATORY_TASK,
|
|
8367
9220
|
EXPLORATORY_TASK_SOURCE: () => EXPLORATORY_TASK_SOURCE,
|
|
8368
9221
|
GatewayEvalsClient: () => GatewayEvalsClient,
|
|
9222
|
+
GradePayload: () => GradePayload,
|
|
9223
|
+
GradeRefused: () => GradeRefused,
|
|
8369
9224
|
HostedDryRunClient: () => HostedDryRunClient,
|
|
8370
9225
|
IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
|
|
8371
9226
|
KEY_NAMES: () => KEY_NAMES,
|
|
@@ -8381,6 +9236,7 @@ __export(worlds_exports, {
|
|
|
8381
9236
|
PlatformTransport: () => PlatformTransport,
|
|
8382
9237
|
PushSlugConflict: () => PushSlugConflict,
|
|
8383
9238
|
RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
|
|
9239
|
+
RetryPolicy: () => RetryPolicy,
|
|
8384
9240
|
SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
|
|
8385
9241
|
SECRET_KEY: () => SECRET_KEY,
|
|
8386
9242
|
SESSION_STATES: () => SESSION_STATES,
|
|
@@ -8388,8 +9244,10 @@ __export(worlds_exports, {
|
|
|
8388
9244
|
STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
|
|
8389
9245
|
STRIP_PREFIX: () => STRIP_PREFIX,
|
|
8390
9246
|
SURFACE_KINDS: () => SURFACE_KINDS,
|
|
9247
|
+
Score: () => Score,
|
|
8391
9248
|
Screen: () => Screen,
|
|
8392
9249
|
SecretScrubber: () => SecretScrubber,
|
|
9250
|
+
TOOL_CONTRACT_UNREAD: () => TOOL_CONTRACT_UNREAD,
|
|
8393
9251
|
TRANSFORMS: () => TRANSFORMS,
|
|
8394
9252
|
TaskEditClient: () => TaskEditClient,
|
|
8395
9253
|
TaskRun: () => TaskRun,
|
|
@@ -8401,13 +9259,17 @@ __export(worlds_exports, {
|
|
|
8401
9259
|
WorldBrowser: () => WorldBrowser,
|
|
8402
9260
|
WorldCallTooLarge: () => WorldCallTooLarge,
|
|
8403
9261
|
WorldEditClient: () => WorldEditClient,
|
|
9262
|
+
WorldNotice: () => WorldNotice,
|
|
9263
|
+
WorldRequestLog: () => WorldRequestLog,
|
|
8404
9264
|
WorldSandboxClient: () => WorldSandboxClient,
|
|
8405
9265
|
WorldSession: () => WorldSession,
|
|
8406
9266
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
9267
|
+
WorldSessionOpenFailed: () => WorldSessionOpenFailed,
|
|
8407
9268
|
WorldSessionTimeout: () => WorldSessionTimeout,
|
|
8408
9269
|
WorldSet: () => WorldSet,
|
|
8409
9270
|
WorldSurfaceUnavailable: () => WorldSurfaceUnavailable,
|
|
8410
9271
|
WorldTask: () => WorldTask,
|
|
9272
|
+
WorldToolsUnread: () => WorldToolsUnread,
|
|
8411
9273
|
aggregateTaskGrade: () => aggregateTaskGrade,
|
|
8412
9274
|
apiRequest: () => apiRequest,
|
|
8413
9275
|
applyTransforms: () => applyTransforms,
|
|
@@ -8450,6 +9312,7 @@ __export(worlds_exports, {
|
|
|
8450
9312
|
listTaskSessions: () => listTaskSessions,
|
|
8451
9313
|
listTasks: () => listTasks,
|
|
8452
9314
|
localTreeState: () => localTreeState,
|
|
9315
|
+
messageOf: () => messageOf,
|
|
8453
9316
|
migrateProjectWorlds: () => migrateProjectWorlds,
|
|
8454
9317
|
migrateWorld: () => migrateWorld,
|
|
8455
9318
|
modelToolName: () => modelToolName,
|
|
@@ -8493,9 +9356,14 @@ __export(worlds_exports, {
|
|
|
8493
9356
|
setEnvSecret: () => setEnvSecret,
|
|
8494
9357
|
shapeText: () => shapeText,
|
|
8495
9358
|
snapshotTreeHashes: () => snapshotTreeHashes,
|
|
9359
|
+
sqlRows: () => sqlRows,
|
|
9360
|
+
stillStartingHint: () => stillStartingHint,
|
|
8496
9361
|
storedForms: () => storedForms,
|
|
9362
|
+
surfaceDescriptor: () => surfaceDescriptor,
|
|
8497
9363
|
surfaceKinds: () => surfaceKinds,
|
|
9364
|
+
taskGradeError: () => taskGradeError,
|
|
8498
9365
|
taskLabel: () => taskLabel,
|
|
9366
|
+
taskRunFailure: () => taskRunFailure,
|
|
8499
9367
|
toolCallRecordsIn: () => toolCallRecordsIn,
|
|
8500
9368
|
toolCallsFromObservations: () => toolCallsFromObservations,
|
|
8501
9369
|
uiEntryUrl: () => uiEntryUrl,
|
|
@@ -8509,17 +9377,6 @@ __export(worlds_exports, {
|
|
|
8509
9377
|
withoutUiToken: () => withoutUiToken,
|
|
8510
9378
|
writeLocalMeta: () => writeLocalMeta
|
|
8511
9379
|
});
|
|
8512
|
-
function resolveEnv(options) {
|
|
8513
|
-
const host = options.host ?? process.env.GATEWAY_HOST ?? "https://withgateway.ai";
|
|
8514
|
-
const publicKey = options.publicKey ?? process.env.GATEWAY_PUBLIC_KEY;
|
|
8515
|
-
const secretKey = options.secretKey ?? process.env.GATEWAY_SECRET_KEY;
|
|
8516
|
-
if (!publicKey || !secretKey) {
|
|
8517
|
-
throw new Error(
|
|
8518
|
-
"Gateway keys missing: set GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY (or pass publicKey/secretKey)."
|
|
8519
|
-
);
|
|
8520
|
-
}
|
|
8521
|
-
return { host: host.replace(/\/+$/, ""), publicKey, secretKey };
|
|
8522
|
-
}
|
|
8523
9380
|
function parseErrorBody(text2, limit = 600) {
|
|
8524
9381
|
const raw = { detail: text2.slice(0, limit), code: null };
|
|
8525
9382
|
let parsed;
|
|
@@ -8539,9 +9396,9 @@ function parseErrorBody(text2, limit = 600) {
|
|
|
8539
9396
|
code: stableCode
|
|
8540
9397
|
};
|
|
8541
9398
|
}
|
|
8542
|
-
async function apiRequest(options, method,
|
|
8543
|
-
const reply = await new PlatformTransport(
|
|
8544
|
-
if (!reply.ok) throw new ApiError(reply.status, method,
|
|
9399
|
+
async function apiRequest(options, method, path13, body, init2 = {}) {
|
|
9400
|
+
const reply = await new PlatformTransport(requirePlatformEndpoint(options)).send(method, path13, body, init2);
|
|
9401
|
+
if (!reply.ok) throw new ApiError(reply.status, method, path13, reply.text);
|
|
8545
9402
|
return JSON.parse(reply.text);
|
|
8546
9403
|
}
|
|
8547
9404
|
async function setEnvSecret(slug, key, value, options = {}) {
|
|
@@ -8653,7 +9510,6 @@ function detectProvenance() {
|
|
|
8653
9510
|
kind: "ci",
|
|
8654
9511
|
id: env.GITHUB_ACTOR,
|
|
8655
9512
|
name: env.GITHUB_ACTOR,
|
|
8656
|
-
// GitHub serves every account's avatar at /<login>.png.
|
|
8657
9513
|
imageUrl: `${server}/${env.GITHUB_ACTOR}.png`
|
|
8658
9514
|
};
|
|
8659
9515
|
}
|
|
@@ -8721,9 +9577,11 @@ async function resolveWorld(slugRef, slug, ref, pin, options) {
|
|
|
8721
9577
|
var ApiError, WorldTask, WorldSet;
|
|
8722
9578
|
var init_worlds = __esm({
|
|
8723
9579
|
"src/worlds/index.ts"() {
|
|
9580
|
+
init_platformEndpoint();
|
|
8724
9581
|
init_transport();
|
|
8725
9582
|
init_transport();
|
|
8726
9583
|
init_session2();
|
|
9584
|
+
init_grade();
|
|
8727
9585
|
init_sessionList();
|
|
8728
9586
|
init_sessionContract();
|
|
8729
9587
|
init_taskRef();
|
|
@@ -8734,6 +9592,8 @@ var init_worlds = __esm({
|
|
|
8734
9592
|
init_checkoutProvenance();
|
|
8735
9593
|
init_evals();
|
|
8736
9594
|
init_browser();
|
|
9595
|
+
init_surfaceDescriptor();
|
|
9596
|
+
init_requestLog();
|
|
8737
9597
|
init_browserReconnect();
|
|
8738
9598
|
init_nativeComputer();
|
|
8739
9599
|
init_hub();
|
|
@@ -8747,10 +9607,11 @@ var init_worlds = __esm({
|
|
|
8747
9607
|
init_sandbox();
|
|
8748
9608
|
init_editSessions();
|
|
8749
9609
|
init_dryRun();
|
|
9610
|
+
init_worldNotice();
|
|
8750
9611
|
ApiError = class extends Error {
|
|
8751
|
-
constructor(status, method,
|
|
9612
|
+
constructor(status, method, path13, text2) {
|
|
8752
9613
|
const parsed = parseErrorBody(text2);
|
|
8753
|
-
super(`${method} ${
|
|
9614
|
+
super(`${method} ${path13} -> ${status}: ${parsed.detail}`);
|
|
8754
9615
|
this.status = status;
|
|
8755
9616
|
this.text = text2;
|
|
8756
9617
|
this.name = "ApiError";
|
|
@@ -8865,6 +9726,8 @@ export {
|
|
|
8865
9726
|
EXPLORATORY_TASK,
|
|
8866
9727
|
EXPLORATORY_TASK_SOURCE,
|
|
8867
9728
|
GatewayEvalsClient,
|
|
9729
|
+
GradePayload,
|
|
9730
|
+
GradeRefused,
|
|
8868
9731
|
HostedDryRunClient,
|
|
8869
9732
|
IDLE_WARNING_MINUTES,
|
|
8870
9733
|
KEY_NAMES,
|
|
@@ -8880,6 +9743,7 @@ export {
|
|
|
8880
9743
|
PlatformTransport,
|
|
8881
9744
|
PushSlugConflict,
|
|
8882
9745
|
RECOVER_BUDGET_MS,
|
|
9746
|
+
RetryPolicy,
|
|
8883
9747
|
SANDBOX_REQUEST_TIMEOUT_MS,
|
|
8884
9748
|
SECRET_KEY,
|
|
8885
9749
|
SESSION_STATES,
|
|
@@ -8887,8 +9751,10 @@ export {
|
|
|
8887
9751
|
STATUS_WAIT_CAP_SECONDS,
|
|
8888
9752
|
STRIP_PREFIX,
|
|
8889
9753
|
SURFACE_KINDS,
|
|
9754
|
+
Score,
|
|
8890
9755
|
Screen,
|
|
8891
9756
|
SecretScrubber,
|
|
9757
|
+
TOOL_CONTRACT_UNREAD,
|
|
8892
9758
|
TRANSFORMS,
|
|
8893
9759
|
TaskEditClient,
|
|
8894
9760
|
TaskRun,
|
|
@@ -8900,13 +9766,17 @@ export {
|
|
|
8900
9766
|
WorldBrowser,
|
|
8901
9767
|
WorldCallTooLarge,
|
|
8902
9768
|
WorldEditClient,
|
|
9769
|
+
WorldNotice,
|
|
9770
|
+
WorldRequestLog,
|
|
8903
9771
|
WorldSandboxClient,
|
|
8904
9772
|
WorldSession,
|
|
8905
9773
|
WorldSessionCallError,
|
|
9774
|
+
WorldSessionOpenFailed,
|
|
8906
9775
|
WorldSessionTimeout,
|
|
8907
9776
|
WorldSet,
|
|
8908
9777
|
WorldSurfaceUnavailable,
|
|
8909
9778
|
WorldTask,
|
|
9779
|
+
WorldToolsUnread,
|
|
8910
9780
|
aggregateTaskGrade,
|
|
8911
9781
|
apiRequest,
|
|
8912
9782
|
applyTransforms,
|
|
@@ -8949,6 +9819,7 @@ export {
|
|
|
8949
9819
|
listTaskSessions,
|
|
8950
9820
|
listTasks,
|
|
8951
9821
|
localTreeState,
|
|
9822
|
+
messageOf,
|
|
8952
9823
|
migrateProjectWorlds,
|
|
8953
9824
|
migrateWorld,
|
|
8954
9825
|
modelToolName,
|
|
@@ -8992,9 +9863,14 @@ export {
|
|
|
8992
9863
|
setEnvSecret,
|
|
8993
9864
|
shapeText,
|
|
8994
9865
|
snapshotTreeHashes,
|
|
9866
|
+
sqlRows,
|
|
9867
|
+
stillStartingHint,
|
|
8995
9868
|
storedForms,
|
|
9869
|
+
surfaceDescriptor,
|
|
8996
9870
|
surfaceKinds,
|
|
9871
|
+
taskGradeError,
|
|
8997
9872
|
taskLabel,
|
|
9873
|
+
taskRunFailure,
|
|
8998
9874
|
toolCallRecordsIn,
|
|
8999
9875
|
toolCallsFromObservations,
|
|
9000
9876
|
uiEntryUrl,
|