@withgateway/sdk 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/cli.js +2880 -2032
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +2982 -2135
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.d.mts +1 -1
- package/dist/files/index.d.ts +1 -1
- package/dist/files/index.js +180 -41
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +172 -35
- package/dist/files/index.mjs.map +1 -1
- package/dist/{index-CBqbB_0J.d.ts → index-DUHmS74p.d.ts} +1 -1
- package/dist/{index-D-AMnAMa.d.mts → index-mJhG3vZU.d.mts} +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1309 -540
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1287 -532
- package/dist/index.mjs.map +1 -1
- package/dist/{media-CbcAfQvd.d.mts → media-BIApiPzS.d.mts} +21 -2
- package/dist/{media-CbcAfQvd.d.ts → media-BIApiPzS.d.ts} +21 -2
- package/dist/traces/index.d.mts +1 -1
- package/dist/traces/index.d.ts +1 -1
- package/dist/traces/index.js +177 -38
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +169 -32
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.d.mts +2 -2
- package/dist/tracing/index.d.ts +2 -2
- package/dist/tracing/index.js +69 -13
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +69 -13
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/worlds/index.d.mts +249 -120
- package/dist/worlds/index.d.ts +249 -120
- package/dist/worlds/index.js +1240 -484
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +1231 -476
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +1 -1
- package/runtime/gatewaysdk/environment/_bundle.py +2 -27
- package/runtime/gatewaysdk/environment/_materialize.py +49 -69
- package/runtime/gatewaysdk/environment/_world.py +122 -197
- package/runtime/gatewaysdk/environment/backing.py +137 -0
- package/runtime/gatewaysdk/environment/core.py +1 -1
- package/runtime/gatewaysdk/environment/legacy_sqlite.py +301 -0
- package/runtime/gatewaysdk/environment/reward_keys.py +25 -0
- package/runtime/gatewaysdk/environment/runtime.py +8 -13
- package/runtime/gatewaysdk/environment/schema/__init__.py +4 -4
- package/runtime/gatewaysdk/environment/schema/admin_routes.py +86 -0
- package/runtime/gatewaysdk/environment/schema/api.py +266 -514
- package/runtime/gatewaysdk/environment/schema/batch.py +42 -37
- package/runtime/gatewaysdk/environment/schema/bundle_runtime.py +17 -5
- package/runtime/gatewaysdk/environment/schema/call_log.py +291 -0
- package/runtime/gatewaysdk/environment/schema/call_redaction.py +344 -0
- package/runtime/gatewaysdk/environment/schema/compiler.py +334 -158
- package/runtime/gatewaysdk/environment/schema/conform.py +8 -12
- package/runtime/gatewaysdk/environment/schema/connector.py +27 -62
- package/runtime/gatewaysdk/environment/schema/data.py +50 -207
- package/runtime/gatewaysdk/environment/schema/database/__init__.py +24 -0
- package/runtime/gatewaysdk/environment/schema/database/audit.py +121 -0
- package/runtime/gatewaysdk/environment/schema/database/base.py +995 -0
- package/runtime/gatewaysdk/environment/schema/database/budget.py +33 -0
- package/runtime/gatewaysdk/environment/schema/database/connections.py +101 -0
- package/runtime/gatewaysdk/environment/schema/database/engines.py +8 -0
- package/runtime/gatewaysdk/environment/schema/database/guard.py +208 -0
- package/runtime/gatewaysdk/environment/schema/database/ingest.py +154 -0
- package/runtime/gatewaysdk/environment/schema/database/matching.py +58 -0
- package/runtime/gatewaysdk/environment/schema/database/provenance.py +30 -0
- package/runtime/gatewaysdk/environment/schema/database/rows.py +53 -0
- package/runtime/gatewaysdk/environment/schema/database/runtime_rows.py +39 -0
- package/runtime/gatewaysdk/environment/schema/database/sqlite.py +367 -0
- package/runtime/gatewaysdk/environment/schema/domain_migration.py +236 -0
- package/runtime/gatewaysdk/environment/schema/envelope.py +169 -0
- package/runtime/gatewaysdk/environment/schema/extract.py +6 -13
- package/runtime/gatewaysdk/environment/schema/grading.py +45 -30
- package/runtime/gatewaysdk/environment/schema/handler_errors.py +142 -12
- package/runtime/gatewaysdk/environment/schema/host.py +158 -250
- package/runtime/gatewaysdk/environment/schema/lanes.py +53 -0
- package/runtime/gatewaysdk/environment/schema/local.py +44 -71
- package/runtime/gatewaysdk/environment/schema/mapping.py +5 -25
- package/runtime/gatewaysdk/environment/schema/openapi_import.py +112 -73
- package/runtime/gatewaysdk/environment/schema/openapi_paging.py +147 -0
- package/runtime/gatewaysdk/environment/schema/openapi_payloads.py +288 -0
- package/runtime/gatewaysdk/environment/schema/openapi_routes.py +97 -102
- package/runtime/gatewaysdk/environment/schema/openapi_schemas.py +113 -30
- package/runtime/gatewaysdk/environment/schema/platform.py +123 -171
- package/runtime/gatewaysdk/environment/schema/platform_import.py +2 -3
- package/runtime/gatewaysdk/environment/schema/platform_query.py +61 -5
- package/runtime/gatewaysdk/environment/schema/primary_key.py +61 -0
- package/runtime/gatewaysdk/environment/schema/proof.py +19 -12
- package/runtime/gatewaysdk/environment/schema/runtime.py +77 -160
- package/runtime/gatewaysdk/environment/schema/served_names.py +58 -0
- package/runtime/gatewaysdk/environment/schema/session_files.py +166 -0
- package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +2 -2
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +19 -11
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/ROWS.md +29 -3
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +14 -14
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +12 -12
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +3 -2
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +15 -0
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/openapi-import.md +50 -21
- package/runtime/gatewaysdk/environment/schema/slack.py +4 -8
- package/runtime/gatewaysdk/environment/schema/snapshot.py +385 -129
- package/runtime/gatewaysdk/environment/schema/store_contract.py +8 -14
- package/runtime/gatewaysdk/environment/schema/tasks.py +140 -55
- package/runtime/gatewaysdk/environment/schema/tools_world.py +110 -87
- package/runtime/gatewaysdk/environment/schema/ui.py +24 -5
- package/runtime/gatewaysdk/environment/schema/ui_static/app.js +100 -130
- package/runtime/gatewaysdk/environment/schema/ui_static/index.html +1 -8
- package/runtime/gatewaysdk/environment/schema/validation.py +166 -40
- package/runtime/gatewaysdk/environment/schema/workers.py +142 -57
- package/runtime/gatewaysdk/environment/schema/world_sql.py +81 -0
- package/runtime/gatewaysdk/environment/schema/world_tests.py +71 -39
- package/runtime/gatewaysdk/environment/score.py +57 -0
- package/runtime/gatewaysdk/environment/secret_values.py +36 -0
- package/runtime/gatewaysdk/environment/world.py +42 -3
- package/runtime/gatewaysdk/environment/world_session_contract.py +32 -5
- package/skills/benchmarks-getting-started/SKILL.md +2 -2
- package/skills/connector-schema-authoring/SKILL.md +19 -11
- package/skills/connector-schema-authoring/connector-worlds.md +13 -4
- package/skills/connector-schema-authoring/world-schema.md +103 -51
- package/skills/world-data-ingestion/ROWS.md +29 -3
- package/skills/world-data-ingestion/SKILL.md +14 -14
- package/skills/worlds-getting-started/SKILL.md +12 -12
- package/skills/worlds-getting-started/references/cli-mcp-map.md +3 -2
- package/skills/worlds-getting-started/references/gotchas.md +15 -0
- package/skills/worlds-getting-started/references/openapi-import.md +50 -21
- package/runtime/gatewaysdk/environment/schema/store.py +0 -1013
package/dist/worlds/index.js
CHANGED
|
@@ -42,6 +42,28 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
42
42
|
));
|
|
43
43
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
44
44
|
|
|
45
|
+
// src/worlds/platformEndpoint.ts
|
|
46
|
+
function platformEndpoint(options) {
|
|
47
|
+
const publicKey = options.publicKey ?? process.env.GATEWAY_PUBLIC_KEY;
|
|
48
|
+
const secretKey = options.secretKey ?? process.env.GATEWAY_SECRET_KEY;
|
|
49
|
+
if (!publicKey || !secretKey) return null;
|
|
50
|
+
const host = options.host ?? process.env.GATEWAY_HOST ?? DEFAULT_HOST;
|
|
51
|
+
return { host: host.replace(/\/+$/, ""), publicKey, secretKey };
|
|
52
|
+
}
|
|
53
|
+
function requirePlatformEndpoint(options) {
|
|
54
|
+
const endpoint = platformEndpoint(options);
|
|
55
|
+
if (!endpoint) throw new Error(GATEWAY_KEYS_MISSING);
|
|
56
|
+
return endpoint;
|
|
57
|
+
}
|
|
58
|
+
var DEFAULT_HOST, GATEWAY_KEYS_MISSING;
|
|
59
|
+
var init_platformEndpoint = __esm({
|
|
60
|
+
"src/worlds/platformEndpoint.ts"() {
|
|
61
|
+
"use strict";
|
|
62
|
+
DEFAULT_HOST = "https://withgateway.ai";
|
|
63
|
+
GATEWAY_KEYS_MISSING = "Gateway keys missing: set GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY (or pass publicKey/secretKey).";
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
45
67
|
// src/worlds/transport.ts
|
|
46
68
|
function platformTimeoutMs(env = process.env) {
|
|
47
69
|
const raw = env[PLATFORM_TIMEOUT_ENV];
|
|
@@ -50,7 +72,7 @@ function platformTimeoutMs(env = process.env) {
|
|
|
50
72
|
if (Number.isInteger(value) && value > 0) return value;
|
|
51
73
|
throw new Error(`${PLATFORM_TIMEOUT_ENV} must be a positive whole number of milliseconds, not \`${raw}\`.`);
|
|
52
74
|
}
|
|
53
|
-
var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, PlatformTransport;
|
|
75
|
+
var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, sleep, RetryPolicy, Attempt, PlatformTransport;
|
|
54
76
|
var init_transport = __esm({
|
|
55
77
|
"src/worlds/transport.ts"() {
|
|
56
78
|
"use strict";
|
|
@@ -112,6 +134,56 @@ var init_transport = __esm({
|
|
|
112
134
|
route;
|
|
113
135
|
failure;
|
|
114
136
|
};
|
|
137
|
+
sleep = (ms) => new Promise((resolve7) => setTimeout(resolve7, ms));
|
|
138
|
+
RetryPolicy = class _RetryPolicy {
|
|
139
|
+
constructor(delaysMs, wait = sleep, budgetMs = Number.POSITIVE_INFINITY, now = Date.now) {
|
|
140
|
+
this.delaysMs = delaysMs;
|
|
141
|
+
this.wait = wait;
|
|
142
|
+
this.budgetMs = budgetMs;
|
|
143
|
+
this.now = now;
|
|
144
|
+
}
|
|
145
|
+
delaysMs;
|
|
146
|
+
wait;
|
|
147
|
+
budgetMs;
|
|
148
|
+
now;
|
|
149
|
+
static NONE = new _RetryPolicy([]);
|
|
150
|
+
/** A platform restart or a short edge outage: no wait starts that would end past five minutes, so a step ends
|
|
151
|
+
* within the budget plus one request timeout. */
|
|
152
|
+
static FILING = new _RetryPolicy([250, 500, 1e3, 2e3, 4e3, 8e3, 16e3, 3e4], sleep, 3e5);
|
|
153
|
+
static TRANSIENT_STATUSES = /* @__PURE__ */ new Set([502, 503, 504]);
|
|
154
|
+
async run(attempt) {
|
|
155
|
+
const started = this.now();
|
|
156
|
+
for (let tries = 0; ; tries += 1) {
|
|
157
|
+
const outcome = await Attempt.of(attempt);
|
|
158
|
+
const delayMs = this.delaysMs[tries];
|
|
159
|
+
const spent = delayMs === void 0 || this.now() - started + delayMs >= this.budgetMs;
|
|
160
|
+
if (!outcome.transient || spent) return outcome.settle();
|
|
161
|
+
await this.wait(delayMs);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
Attempt = class _Attempt {
|
|
166
|
+
constructor(reply, error, transient) {
|
|
167
|
+
this.reply = reply;
|
|
168
|
+
this.error = error;
|
|
169
|
+
this.transient = transient;
|
|
170
|
+
}
|
|
171
|
+
reply;
|
|
172
|
+
error;
|
|
173
|
+
transient;
|
|
174
|
+
static async of(attempt) {
|
|
175
|
+
try {
|
|
176
|
+
const reply = await attempt();
|
|
177
|
+
return new _Attempt(reply, null, RetryPolicy.TRANSIENT_STATUSES.has(reply.status));
|
|
178
|
+
} catch (error) {
|
|
179
|
+
return new _Attempt(null, error, error instanceof UnreachableError);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
settle() {
|
|
183
|
+
if (this.reply) return this.reply;
|
|
184
|
+
throw this.error;
|
|
185
|
+
}
|
|
186
|
+
};
|
|
115
187
|
PlatformTransport = class {
|
|
116
188
|
constructor(endpoint, timeoutMs = platformTimeoutMs()) {
|
|
117
189
|
this.endpoint = endpoint;
|
|
@@ -125,6 +197,9 @@ var init_transport = __esm({
|
|
|
125
197
|
}
|
|
126
198
|
async send(method, route, body, opts = {}) {
|
|
127
199
|
const timeoutMs = this.budget(opts.timeoutMs);
|
|
200
|
+
return (opts.retry ?? RetryPolicy.NONE).run(() => this.once(method, route, body, timeoutMs));
|
|
201
|
+
}
|
|
202
|
+
async once(method, route, body, timeoutMs) {
|
|
128
203
|
const payload = body === void 0 ? {} : { body: JSON.stringify(body) };
|
|
129
204
|
const controller = new AbortController();
|
|
130
205
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
@@ -318,9 +393,9 @@ function surfaceKinds(s) {
|
|
|
318
393
|
if (s.browser) kinds.push("browser");
|
|
319
394
|
return kinds;
|
|
320
395
|
}
|
|
321
|
-
function uiUrl(ui,
|
|
396
|
+
function uiUrl(ui, path13) {
|
|
322
397
|
const base = ui.url.replace(/\/+$/, "");
|
|
323
|
-
const rel =
|
|
398
|
+
const rel = path13.startsWith("/") ? path13 : `/${path13}`;
|
|
324
399
|
if (!ui.token) return base + rel;
|
|
325
400
|
const [beforeHash, hash] = splitHash(rel);
|
|
326
401
|
const joiner = beforeHash.includes("?") ? "&" : "?";
|
|
@@ -561,7 +636,7 @@ var init_browser = __esm({
|
|
|
561
636
|
}
|
|
562
637
|
async send(batch) {
|
|
563
638
|
const retries = this.opts.maxRetries ?? EVENT_MAX_RETRIES;
|
|
564
|
-
const
|
|
639
|
+
const sleep4 = this.opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
565
640
|
for (let attempt = 0; attempt < retries; attempt++) {
|
|
566
641
|
try {
|
|
567
642
|
const base = await this.resolveBase();
|
|
@@ -578,7 +653,7 @@ var init_browser = __esm({
|
|
|
578
653
|
);
|
|
579
654
|
return;
|
|
580
655
|
}
|
|
581
|
-
await
|
|
656
|
+
await sleep4(500 * 2 ** attempt);
|
|
582
657
|
}
|
|
583
658
|
}
|
|
584
659
|
}
|
|
@@ -1215,13 +1290,13 @@ var init_screen = __esm({
|
|
|
1215
1290
|
});
|
|
1216
1291
|
}
|
|
1217
1292
|
async drag(action) {
|
|
1218
|
-
const
|
|
1219
|
-
if (
|
|
1293
|
+
const path13 = action.args.path ?? [];
|
|
1294
|
+
if (path13.length < 2) throw new Error("a drag needs at least two points");
|
|
1220
1295
|
return this.held(action.args.modifiers ?? [], async () => {
|
|
1221
|
-
await this.moveTo(
|
|
1296
|
+
await this.moveTo(path13[0]);
|
|
1222
1297
|
await this.page.mouse.down({ button: "left" });
|
|
1223
1298
|
try {
|
|
1224
|
-
for (const point2 of
|
|
1299
|
+
for (const point2 of path13.slice(1)) await this.moveTo(point2, DRAG_STEPS);
|
|
1225
1300
|
} finally {
|
|
1226
1301
|
await this.page.mouse.up({ button: "left" });
|
|
1227
1302
|
}
|
|
@@ -1312,7 +1387,7 @@ var init_media = __esm({
|
|
|
1312
1387
|
put;
|
|
1313
1388
|
maxBytes;
|
|
1314
1389
|
/** The uploader for `GATEWAY_HOST` / `GATEWAY_PUBLIC_KEY` /
|
|
1315
|
-
* `GATEWAY_SECRET_KEY`
|
|
1390
|
+
* `GATEWAY_SECRET_KEY` only; null when any is unset, so a run traced with a saved login uploads none. */
|
|
1316
1391
|
static fromEnv(env = process.env) {
|
|
1317
1392
|
const host = env.GATEWAY_HOST;
|
|
1318
1393
|
const publicKey = env.GATEWAY_PUBLIC_KEY;
|
|
@@ -2182,7 +2257,7 @@ function idleWarning(idleExpiresAt, now = /* @__PURE__ */ new Date()) {
|
|
|
2182
2257
|
const minutes = Math.max(0, Math.floor(leftMs / 6e4));
|
|
2183
2258
|
return `warning: session expires in ${minutes}m (idle TTL); call a tool to extend it or \`gateway worlds session pin\` to keep it`;
|
|
2184
2259
|
}
|
|
2185
|
-
var CALL_BODY_LIMIT_BYTES, CALL_BODY_LIMIT_LABEL, IDLE_WARNING_MINUTES, EXPLORATORY_TASK, EXPLORATORY_TASK_SOURCE, NO_GRADER_REASON, WorldCallTooLarge;
|
|
2260
|
+
var CALL_BODY_LIMIT_BYTES, CALL_BODY_LIMIT_LABEL, IDLE_WARNING_MINUTES, EXPLORATORY_TASK, EXPLORATORY_TASK_SOURCE, NO_GRADER_REASON, WorldCallTooLarge, stillStartingHint;
|
|
2186
2261
|
var init_sessionContract = __esm({
|
|
2187
2262
|
"src/worlds/sessionContract.ts"() {
|
|
2188
2263
|
"use strict";
|
|
@@ -2218,6 +2293,65 @@ var init_sessionContract = __esm({
|
|
|
2218
2293
|
};
|
|
2219
2294
|
}
|
|
2220
2295
|
};
|
|
2296
|
+
stillStartingHint = (sessionId) => `It keeps opening: poll \`gateway worlds session status ${sessionId}\` until ready, or end it with \`gateway worlds session close ${sessionId}\`.`;
|
|
2297
|
+
}
|
|
2298
|
+
});
|
|
2299
|
+
|
|
2300
|
+
// src/worlds/sessionReadiness.ts
|
|
2301
|
+
var READY_TIMEOUT_MS, READY_POLL_MS, sleep2, WorldSessionTimeout, WorldSessionCallError, WorldSessionOpenFailed, ENDED, SessionReadiness;
|
|
2302
|
+
var init_sessionReadiness = __esm({
|
|
2303
|
+
"src/worlds/sessionReadiness.ts"() {
|
|
2304
|
+
"use strict";
|
|
2305
|
+
READY_TIMEOUT_MS = 10 * 6e4;
|
|
2306
|
+
READY_POLL_MS = 2e3;
|
|
2307
|
+
sleep2 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
2308
|
+
WorldSessionTimeout = class extends Error {
|
|
2309
|
+
};
|
|
2310
|
+
WorldSessionCallError = class extends Error {
|
|
2311
|
+
};
|
|
2312
|
+
WorldSessionOpenFailed = class extends WorldSessionCallError {
|
|
2313
|
+
constructor(sessionId, state2, code, reason) {
|
|
2314
|
+
super(
|
|
2315
|
+
reason === null ? `World session ${sessionId} ${state2.toLowerCase()} before it was ready.` : `World session ${sessionId} failed to open: ${reason}${code ? ` (${code})` : ""}`
|
|
2316
|
+
);
|
|
2317
|
+
this.sessionId = sessionId;
|
|
2318
|
+
this.state = state2;
|
|
2319
|
+
this.code = code;
|
|
2320
|
+
this.name = "WorldSessionOpenFailed";
|
|
2321
|
+
}
|
|
2322
|
+
sessionId;
|
|
2323
|
+
state;
|
|
2324
|
+
code;
|
|
2325
|
+
};
|
|
2326
|
+
ENDED = /* @__PURE__ */ new Set(["FAILED", "STOPPED"]);
|
|
2327
|
+
SessionReadiness = class {
|
|
2328
|
+
constructor(sessionId, status) {
|
|
2329
|
+
this.sessionId = sessionId;
|
|
2330
|
+
this.status = status;
|
|
2331
|
+
}
|
|
2332
|
+
sessionId;
|
|
2333
|
+
status;
|
|
2334
|
+
async wait(timeoutMs = READY_TIMEOUT_MS) {
|
|
2335
|
+
const deadline = Date.now() + timeoutMs;
|
|
2336
|
+
for (; ; ) {
|
|
2337
|
+
const state2 = await this.status();
|
|
2338
|
+
if (state2.ready) return state2;
|
|
2339
|
+
if (ENDED.has(state2.state))
|
|
2340
|
+
throw new WorldSessionOpenFailed(
|
|
2341
|
+
this.sessionId,
|
|
2342
|
+
state2.state,
|
|
2343
|
+
state2.failure?.code ?? null,
|
|
2344
|
+
state2.failure?.message ?? null
|
|
2345
|
+
);
|
|
2346
|
+
const left = deadline - Date.now();
|
|
2347
|
+
if (left <= 0)
|
|
2348
|
+
throw new WorldSessionTimeout(
|
|
2349
|
+
`World session ${this.sessionId} still ${state2.state} after ${Math.round(timeoutMs / 1e3)}s.`
|
|
2350
|
+
);
|
|
2351
|
+
await sleep2(Math.min(READY_POLL_MS, left));
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
};
|
|
2221
2355
|
}
|
|
2222
2356
|
});
|
|
2223
2357
|
|
|
@@ -2313,11 +2447,184 @@ var init_taskRef = __esm({
|
|
|
2313
2447
|
}
|
|
2314
2448
|
});
|
|
2315
2449
|
|
|
2450
|
+
// src/worlds/worldNotice.ts
|
|
2451
|
+
var TOOL_CONTRACT_UNREAD, DEPRECATION, NOTICE_KINDS, WorldNotice, WorldToolsUnread;
|
|
2452
|
+
var init_worldNotice = __esm({
|
|
2453
|
+
"src/worlds/worldNotice.ts"() {
|
|
2454
|
+
"use strict";
|
|
2455
|
+
TOOL_CONTRACT_UNREAD = "tool-contract-unread";
|
|
2456
|
+
DEPRECATION = { label: "deprecated", next: "Instead", refusesRun: false };
|
|
2457
|
+
NOTICE_KINDS = /* @__PURE__ */ new Map([
|
|
2458
|
+
[TOOL_CONTRACT_UNREAD, { label: "warning", next: "Then", refusesRun: true }]
|
|
2459
|
+
]);
|
|
2460
|
+
WorldNotice = class _WorldNotice {
|
|
2461
|
+
constructor(notice, kind) {
|
|
2462
|
+
this.notice = notice;
|
|
2463
|
+
this.kind = kind;
|
|
2464
|
+
}
|
|
2465
|
+
notice;
|
|
2466
|
+
kind;
|
|
2467
|
+
static of(notice) {
|
|
2468
|
+
return new _WorldNotice(notice, NOTICE_KINDS.get(notice.code) ?? DEPRECATION);
|
|
2469
|
+
}
|
|
2470
|
+
get refusesRun() {
|
|
2471
|
+
return this.kind.refusesRun;
|
|
2472
|
+
}
|
|
2473
|
+
line() {
|
|
2474
|
+
const { code, message, replacement } = this.notice;
|
|
2475
|
+
return `${this.kind.label} (${code}): ${message} ${this.kind.next}: ${replacement}`;
|
|
2476
|
+
}
|
|
2477
|
+
};
|
|
2478
|
+
WorldToolsUnread = class _WorldToolsUnread extends Error {
|
|
2479
|
+
constructor(world, notice) {
|
|
2480
|
+
super(
|
|
2481
|
+
`refused before the agent ran, nothing filed: world ${world} has no readable tools: ${notice.notice.message} Then: ${notice.notice.replacement}`
|
|
2482
|
+
);
|
|
2483
|
+
this.world = world;
|
|
2484
|
+
this.notice = notice;
|
|
2485
|
+
this.name = "WorldToolsUnread";
|
|
2486
|
+
this.code = notice.notice.code;
|
|
2487
|
+
}
|
|
2488
|
+
world;
|
|
2489
|
+
notice;
|
|
2490
|
+
code;
|
|
2491
|
+
static refuse(world, notices) {
|
|
2492
|
+
const refusing = notices.map((notice) => WorldNotice.of(notice)).find((notice) => notice.refusesRun);
|
|
2493
|
+
if (refusing) throw new _WorldToolsUnread(world, refusing);
|
|
2494
|
+
}
|
|
2495
|
+
};
|
|
2496
|
+
}
|
|
2497
|
+
});
|
|
2498
|
+
|
|
2499
|
+
// src/worlds/grade.ts
|
|
2500
|
+
var messageOf, Score, GradeRefused, GradePayload;
|
|
2501
|
+
var init_grade = __esm({
|
|
2502
|
+
"src/worlds/grade.ts"() {
|
|
2503
|
+
"use strict";
|
|
2504
|
+
messageOf = (error) => (error instanceof Error ? error.message || error.name : String(error)) || "Error";
|
|
2505
|
+
Score = class _Score {
|
|
2506
|
+
static RULE = "a score is a number from 0 to 1";
|
|
2507
|
+
static admits(value) {
|
|
2508
|
+
return Number.isFinite(value) && value >= 0 && value <= 1;
|
|
2509
|
+
}
|
|
2510
|
+
/** Every number among `scores` that is not a score, as `'<key>' = <value>`
|
|
2511
|
+
* and the rule, or null when all of them are. Pairs, not a map, so that no
|
|
2512
|
+
* key hides another. */
|
|
2513
|
+
static problem(scores2) {
|
|
2514
|
+
const refused = [...scores2].flatMap(
|
|
2515
|
+
([key, value]) => typeof value === "number" && !_Score.admits(value) ? [`'${key}' = ${String(value)}`] : []
|
|
2516
|
+
);
|
|
2517
|
+
return refused.length ? `${refused.join(", ")}; ${_Score.RULE}` : null;
|
|
2518
|
+
}
|
|
2519
|
+
};
|
|
2520
|
+
GradeRefused = class extends Error {
|
|
2521
|
+
name = "GradeRefused";
|
|
2522
|
+
};
|
|
2523
|
+
GradePayload = class _GradePayload {
|
|
2524
|
+
/** A grade payload's numbers, checked: every number in it must be a score,
|
|
2525
|
+
* and its rewards and verifiers objects by name, or the grade is refused; a
|
|
2526
|
+
* cross-world verifier's grade that breaks either rule is that verifier's
|
|
2527
|
+
* error, the way the World Host answers one that could not grade. */
|
|
2528
|
+
static read(raw) {
|
|
2529
|
+
if (!_GradePayload.objectOrAbsent(raw))
|
|
2530
|
+
throw new GradeRefused("the grade is not an object");
|
|
2531
|
+
const record = _GradePayload.record(raw);
|
|
2532
|
+
const problem = _GradePayload.problem(record) ?? _GradePayload.verifiersProblem(record.verifiers);
|
|
2533
|
+
if (problem) throw new GradeRefused(problem);
|
|
2534
|
+
const verifiers = _GradePayload.verifiers(record.verifiers);
|
|
2535
|
+
return {
|
|
2536
|
+
..._GradePayload.numbers(record),
|
|
2537
|
+
...typeof record.reason === "string" ? { reason: record.reason } : {},
|
|
2538
|
+
...typeof record.error === "string" ? { error: record.error } : {},
|
|
2539
|
+
...verifiers ? { verifiers } : {}
|
|
2540
|
+
};
|
|
2541
|
+
}
|
|
2542
|
+
/** A world whose grade call failed (the platform refused it, the host had
|
|
2543
|
+
* lost the session): that world's error, never a score. */
|
|
2544
|
+
static failedCall(error) {
|
|
2545
|
+
return { ..._GradePayload.failed(messageOf(error)), raw: null };
|
|
2546
|
+
}
|
|
2547
|
+
static problem(record) {
|
|
2548
|
+
if (!_GradePayload.objectOrAbsent(record.rewards))
|
|
2549
|
+
return "the grade's rewards are not an object";
|
|
2550
|
+
const scores2 = Score.problem(_GradePayload.scores(record));
|
|
2551
|
+
if (scores2) return `the grade answered ${scores2}`;
|
|
2552
|
+
const twice = _GradePayload.twice(record);
|
|
2553
|
+
return twice.length ? `the grade answered ${twice.map((key) => `'${key}'`).join(", ")} both beside and inside rewards` : null;
|
|
2554
|
+
}
|
|
2555
|
+
static twice(record) {
|
|
2556
|
+
return Object.entries(_GradePayload.record(record.rewards)).filter(
|
|
2557
|
+
([key, value]) => key !== "reward" && typeof value === "number" && typeof record[key] === "number"
|
|
2558
|
+
).map(([key]) => key);
|
|
2559
|
+
}
|
|
2560
|
+
static verifiersProblem(value) {
|
|
2561
|
+
return _GradePayload.objectOrAbsent(value) ? null : "the grade's verifiers are not an object";
|
|
2562
|
+
}
|
|
2563
|
+
static scores(record) {
|
|
2564
|
+
return [
|
|
2565
|
+
["reward", record.reward],
|
|
2566
|
+
...Object.entries(_GradePayload.record(record.rewards)),
|
|
2567
|
+
...Object.entries(record).filter(
|
|
2568
|
+
([key]) => key !== "reward" && key !== "rewards"
|
|
2569
|
+
)
|
|
2570
|
+
];
|
|
2571
|
+
}
|
|
2572
|
+
static isRecord(value) {
|
|
2573
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2574
|
+
}
|
|
2575
|
+
static objectOrAbsent(value) {
|
|
2576
|
+
return value === void 0 || value === null || _GradePayload.isRecord(value);
|
|
2577
|
+
}
|
|
2578
|
+
static record(value) {
|
|
2579
|
+
return _GradePayload.isRecord(value) ? value : {};
|
|
2580
|
+
}
|
|
2581
|
+
/** `reward`, and every numeric key under `rewards` (the host's shape) or at
|
|
2582
|
+
* the top level (a bundled verifier's). */
|
|
2583
|
+
static numbers(record) {
|
|
2584
|
+
const rewards = {};
|
|
2585
|
+
for (const [key, value] of Object.entries(
|
|
2586
|
+
_GradePayload.record(record.rewards)
|
|
2587
|
+
))
|
|
2588
|
+
if (typeof value === "number") rewards[key] = value;
|
|
2589
|
+
for (const [key, value] of Object.entries(record))
|
|
2590
|
+
if (key !== "reward" && typeof value === "number") rewards[key] = value;
|
|
2591
|
+
return {
|
|
2592
|
+
reward: typeof record.reward === "number" ? record.reward : null,
|
|
2593
|
+
rewards
|
|
2594
|
+
};
|
|
2595
|
+
}
|
|
2596
|
+
static verifiers(value) {
|
|
2597
|
+
if (!_GradePayload.isRecord(value)) return void 0;
|
|
2598
|
+
return Object.fromEntries(
|
|
2599
|
+
Object.entries(value).map(([name, grade]) => [
|
|
2600
|
+
name,
|
|
2601
|
+
_GradePayload.verifier(name, grade)
|
|
2602
|
+
])
|
|
2603
|
+
);
|
|
2604
|
+
}
|
|
2605
|
+
static verifier(name, grade) {
|
|
2606
|
+
if (!_GradePayload.isRecord(grade))
|
|
2607
|
+
return _GradePayload.failed(`the grade's verifier '${name}' is not an object`);
|
|
2608
|
+
const problem = _GradePayload.problem(grade);
|
|
2609
|
+
if (problem) return _GradePayload.failed(problem);
|
|
2610
|
+
return {
|
|
2611
|
+
..._GradePayload.numbers(grade),
|
|
2612
|
+
...typeof grade.error === "string" ? { error: grade.error } : {}
|
|
2613
|
+
};
|
|
2614
|
+
}
|
|
2615
|
+
static failed(error) {
|
|
2616
|
+
return { reward: null, rewards: {}, error };
|
|
2617
|
+
}
|
|
2618
|
+
};
|
|
2619
|
+
}
|
|
2620
|
+
});
|
|
2621
|
+
|
|
2316
2622
|
// src/worlds/session.ts
|
|
2317
2623
|
var session_exports2 = {};
|
|
2318
2624
|
__export(session_exports2, {
|
|
2319
2625
|
WorldSession: () => WorldSession,
|
|
2320
2626
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
2627
|
+
WorldSessionOpenFailed: () => WorldSessionOpenFailed,
|
|
2321
2628
|
WorldSessionTimeout: () => WorldSessionTimeout,
|
|
2322
2629
|
attachSession: () => attachSession,
|
|
2323
2630
|
isTaskIdRef: () => isTaskIdRef,
|
|
@@ -2328,34 +2635,6 @@ __export(session_exports2, {
|
|
|
2328
2635
|
schemaFromSignature: () => schemaFromSignature,
|
|
2329
2636
|
taskLabel: () => taskLabel
|
|
2330
2637
|
});
|
|
2331
|
-
function numericGrade(record) {
|
|
2332
|
-
const rewards = {};
|
|
2333
|
-
const nested = record.rewards;
|
|
2334
|
-
if (nested && typeof nested === "object") {
|
|
2335
|
-
for (const [key, value] of Object.entries(nested)) {
|
|
2336
|
-
if (typeof value === "number") rewards[key] = value;
|
|
2337
|
-
}
|
|
2338
|
-
}
|
|
2339
|
-
for (const [key, value] of Object.entries(record)) {
|
|
2340
|
-
if (key !== "reward" && typeof value === "number") rewards[key] = value;
|
|
2341
|
-
}
|
|
2342
|
-
return {
|
|
2343
|
-
reward: typeof record.reward === "number" ? record.reward : null,
|
|
2344
|
-
rewards
|
|
2345
|
-
};
|
|
2346
|
-
}
|
|
2347
|
-
function verifierGrades(value) {
|
|
2348
|
-
if (!value || typeof value !== "object") return void 0;
|
|
2349
|
-
const out = {};
|
|
2350
|
-
for (const [name, grade] of Object.entries(value)) {
|
|
2351
|
-
const record = grade && typeof grade === "object" ? grade : {};
|
|
2352
|
-
out[name] = {
|
|
2353
|
-
...numericGrade(record),
|
|
2354
|
-
...typeof record.error === "string" ? { error: record.error } : {}
|
|
2355
|
-
};
|
|
2356
|
-
}
|
|
2357
|
-
return out;
|
|
2358
|
-
}
|
|
2359
2638
|
function schemaFromSignature(spec) {
|
|
2360
2639
|
if (spec.inputSchema)
|
|
2361
2640
|
return {
|
|
@@ -2463,6 +2742,7 @@ async function runSessions(opts) {
|
|
|
2463
2742
|
const taskRef = tasks[next++];
|
|
2464
2743
|
let task = taskLabel(taskRef);
|
|
2465
2744
|
let session = null;
|
|
2745
|
+
let keepWarm = opts.keepWarm ?? true;
|
|
2466
2746
|
try {
|
|
2467
2747
|
session = await openSession(opts.world, {
|
|
2468
2748
|
task: taskRef,
|
|
@@ -2470,6 +2750,7 @@ async function runSessions(opts) {
|
|
|
2470
2750
|
options
|
|
2471
2751
|
});
|
|
2472
2752
|
task = taskLabel(taskRef, session.taskInfo);
|
|
2753
|
+
WorldToolsUnread.refuse(opts.world.split("@", 1)[0], session.deprecations);
|
|
2473
2754
|
await session.ready();
|
|
2474
2755
|
const toolkit = await session.toolkit();
|
|
2475
2756
|
const live = session;
|
|
@@ -2492,19 +2773,19 @@ async function runSessions(opts) {
|
|
|
2492
2773
|
results.push(result);
|
|
2493
2774
|
opts.onResult?.(result);
|
|
2494
2775
|
} catch (error) {
|
|
2776
|
+
if (error instanceof WorldToolsUnread) keepWarm = false;
|
|
2495
2777
|
const result = {
|
|
2496
2778
|
task,
|
|
2497
2779
|
sessionId: session?.sessionId ?? "",
|
|
2498
2780
|
reward: 0,
|
|
2499
2781
|
rewards: {},
|
|
2500
|
-
// An
|
|
2501
|
-
// caller checking truthiness; name the type instead.
|
|
2782
|
+
// An empty message reads as "no error" to a truthiness check; name the type instead.
|
|
2502
2783
|
error: (error instanceof Error ? error.message : String(error)) || (error instanceof Error ? error.name : "Unknown error")
|
|
2503
2784
|
};
|
|
2504
2785
|
results.push(result);
|
|
2505
2786
|
opts.onResult?.(result);
|
|
2506
2787
|
} finally {
|
|
2507
|
-
await session?.close({ keepWarm
|
|
2788
|
+
await session?.close({ keepWarm }).catch(() => void 0);
|
|
2508
2789
|
}
|
|
2509
2790
|
}
|
|
2510
2791
|
})
|
|
@@ -2518,7 +2799,7 @@ async function runSessions(opts) {
|
|
|
2518
2799
|
passed: failed === 0 && (opts.failUnder === void 0 || mean >= opts.failUnder)
|
|
2519
2800
|
};
|
|
2520
2801
|
}
|
|
2521
|
-
var import_node_crypto2,
|
|
2802
|
+
var import_node_crypto2, CALL_TIMEOUT_MS, CALL_POLL_MS, JUDGED_GRADE_TIMEOUT_MS, JUDGED_GRADE_POLL_MS, EXPORT_PAGE, sleep3, modelToolName, WorldSession, OPEN_SESSION_OPTION_KEYS, isOpenSessionOptions;
|
|
2522
2803
|
var init_session2 = __esm({
|
|
2523
2804
|
"src/worlds/session.ts"() {
|
|
2524
2805
|
"use strict";
|
|
@@ -2527,22 +2808,20 @@ var init_session2 = __esm({
|
|
|
2527
2808
|
init_browser();
|
|
2528
2809
|
init_nativeComputer();
|
|
2529
2810
|
init_sessionContract();
|
|
2811
|
+
init_sessionReadiness();
|
|
2530
2812
|
init_session();
|
|
2531
2813
|
init_taskRef();
|
|
2814
|
+
init_worldNotice();
|
|
2815
|
+
init_grade();
|
|
2532
2816
|
init_taskRef();
|
|
2533
|
-
|
|
2534
|
-
READY_POLL_MS = 2e3;
|
|
2817
|
+
init_sessionReadiness();
|
|
2535
2818
|
CALL_TIMEOUT_MS = 3 * 6e4;
|
|
2536
2819
|
CALL_POLL_MS = 400;
|
|
2537
2820
|
JUDGED_GRADE_TIMEOUT_MS = 15 * 6e4;
|
|
2538
2821
|
JUDGED_GRADE_POLL_MS = 2e3;
|
|
2539
2822
|
EXPORT_PAGE = 500;
|
|
2540
|
-
|
|
2823
|
+
sleep3 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
2541
2824
|
modelToolName = (name) => name.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 64) || "tool";
|
|
2542
|
-
WorldSessionTimeout = class extends Error {
|
|
2543
|
-
};
|
|
2544
|
-
WorldSessionCallError = class extends Error {
|
|
2545
|
-
};
|
|
2546
2825
|
WorldSession = class {
|
|
2547
2826
|
constructor(sessionId, current, options) {
|
|
2548
2827
|
this.sessionId = sessionId;
|
|
@@ -2660,18 +2939,17 @@ var init_session2 = __esm({
|
|
|
2660
2939
|
}
|
|
2661
2940
|
/** The reporter `browser()` uses; exposed for a page you drive yourself. */
|
|
2662
2941
|
browserRecorder(agentId) {
|
|
2663
|
-
const
|
|
2942
|
+
const path13 = `/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/browser-events`;
|
|
2664
2943
|
const id = agentId ?? process.env.GATEWAY_AGENT_ID ?? `agent-${(0, import_node_crypto2.randomUUID)().replace(/-/g, "").slice(0, 8)}`;
|
|
2665
2944
|
return new BrowserActionRecorder(
|
|
2666
2945
|
async (events) => {
|
|
2667
|
-
await apiRequest(this.options, "POST",
|
|
2946
|
+
await apiRequest(this.options, "POST", path13, { events });
|
|
2668
2947
|
},
|
|
2669
2948
|
id,
|
|
2670
2949
|
{
|
|
2671
|
-
// Continue this agent's timeline where the platform has it, so
|
|
2672
|
-
// same id reopened later never re-numbers from zero.
|
|
2950
|
+
// Continue this agent's timeline where the platform has it, so a reopened id never re-numbers from zero.
|
|
2673
2951
|
resumeFrom: async () => {
|
|
2674
|
-
const summary = await apiRequest(this.options, "GET",
|
|
2952
|
+
const summary = await apiRequest(this.options, "GET", path13);
|
|
2675
2953
|
return summary.agents.find((a) => a.agentId === id)?.nextSeq ?? 0;
|
|
2676
2954
|
}
|
|
2677
2955
|
}
|
|
@@ -2699,29 +2977,22 @@ var init_session2 = __esm({
|
|
|
2699
2977
|
tools: this.current.tools,
|
|
2700
2978
|
surfaces: this.current.surfaces,
|
|
2701
2979
|
task: this.current.task,
|
|
2980
|
+
deprecations: this.current.deprecations,
|
|
2702
2981
|
...fresh
|
|
2703
2982
|
};
|
|
2704
2983
|
return this.current;
|
|
2705
2984
|
}
|
|
2706
2985
|
/**
|
|
2707
|
-
* Wait until the
|
|
2708
|
-
* asked the platform for work
|
|
2986
|
+
* Wait until the session answers calls: a World Host holds it, or the
|
|
2987
|
+
* process inside a pod has asked the platform for work. Throws
|
|
2988
|
+
* `WorldSessionOpenFailed` (with the platform's reason) when it ended
|
|
2989
|
+
* first, and `WorldSessionTimeout` when `timeoutMs` (default ten minutes)
|
|
2990
|
+
* ran out while it was still starting.
|
|
2709
2991
|
*/
|
|
2710
2992
|
async ready(opts = {}) {
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
if (state2.ready) return state2;
|
|
2715
|
-
if (state2.state === "FAILED" || state2.state === "STOPPED")
|
|
2716
|
-
throw new WorldSessionCallError(
|
|
2717
|
-
`World session ${state2.state.toLowerCase()} before it was ready.`
|
|
2718
|
-
);
|
|
2719
|
-
if (Date.now() > deadline)
|
|
2720
|
-
throw new WorldSessionTimeout(
|
|
2721
|
-
`World session still ${state2.state} after ${Math.round((opts.timeoutMs ?? READY_TIMEOUT_MS) / 1e3)}s.`
|
|
2722
|
-
);
|
|
2723
|
-
await sleep(READY_POLL_MS);
|
|
2724
|
-
}
|
|
2993
|
+
return new SessionReadiness(this.sessionId, () => this.status()).wait(
|
|
2994
|
+
opts.timeoutMs
|
|
2995
|
+
);
|
|
2725
2996
|
}
|
|
2726
2997
|
/** Enqueue one interaction and wait for the container's answer. */
|
|
2727
2998
|
async exchange(body, timeoutMs) {
|
|
@@ -2751,7 +3022,7 @@ var init_session2 = __esm({
|
|
|
2751
3022
|
throw new WorldSessionTimeout(
|
|
2752
3023
|
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.`
|
|
2753
3024
|
);
|
|
2754
|
-
await
|
|
3025
|
+
await sleep3(pollMs2);
|
|
2755
3026
|
}
|
|
2756
3027
|
}
|
|
2757
3028
|
/**
|
|
@@ -2800,7 +3071,9 @@ var init_session2 = __esm({
|
|
|
2800
3071
|
* calls); assertions and python graders ignore it. `worlds` names the
|
|
2801
3072
|
* task's other sessions by alias (`{alias: sessionId}`): the platform
|
|
2802
3073
|
* reads each one's evidence and hands it to the cross-world verifiers
|
|
2803
|
-
* anchored on this session, whose grades come back under `verifiers`.
|
|
3074
|
+
* anchored on this session, whose grades come back under `verifiers`. A
|
|
3075
|
+
* score that is not a number from 0 to 1 is refused by key and value
|
|
3076
|
+
* (`GradeRefused`); a verifier's is that verifier's `error`. */
|
|
2804
3077
|
async grade(opts = {}) {
|
|
2805
3078
|
const raw = await this.exchange(
|
|
2806
3079
|
{
|
|
@@ -2810,14 +3083,7 @@ var init_session2 = __esm({
|
|
|
2810
3083
|
},
|
|
2811
3084
|
opts.timeoutMs
|
|
2812
3085
|
);
|
|
2813
|
-
|
|
2814
|
-
const verifiers = verifierGrades(record.verifiers);
|
|
2815
|
-
return {
|
|
2816
|
-
...numericGrade(record),
|
|
2817
|
-
...typeof record.reason === "string" ? { reason: record.reason } : {},
|
|
2818
|
-
...verifiers ? { verifiers } : {},
|
|
2819
|
-
raw
|
|
2820
|
-
};
|
|
3086
|
+
return { ...GradePayload.read(raw), raw };
|
|
2821
3087
|
}
|
|
2822
3088
|
/**
|
|
2823
3089
|
* Put rows into the LIVE world through its contract, in one batch:
|
|
@@ -3081,26 +3347,28 @@ var init_surfaceDescriptor = __esm({
|
|
|
3081
3347
|
|
|
3082
3348
|
// src/worlds/taskSessions.ts
|
|
3083
3349
|
function aggregateTaskGrade(worlds) {
|
|
3084
|
-
const
|
|
3085
|
-
const ungraded = [];
|
|
3086
|
-
const graded = [];
|
|
3350
|
+
const fold = new TaskGradeFold();
|
|
3087
3351
|
const verifiers = {};
|
|
3088
|
-
const fold = (key, grade) => {
|
|
3089
|
-
if (typeof grade.reward === "number") {
|
|
3090
|
-
rewards[key] = grade.reward;
|
|
3091
|
-
graded.push(grade.reward);
|
|
3092
|
-
} else ungraded.push(key);
|
|
3093
|
-
for (const [name, value] of Object.entries(grade.rewards))
|
|
3094
|
-
rewards[`${key}.${name}`] = value;
|
|
3095
|
-
};
|
|
3096
3352
|
for (const [alias, grade] of Object.entries(worlds)) {
|
|
3097
|
-
fold(alias, grade);
|
|
3353
|
+
fold.add(alias, grade, `world ${alias}`);
|
|
3098
3354
|
Object.assign(verifiers, grade.verifiers ?? {});
|
|
3099
3355
|
}
|
|
3100
3356
|
for (const [name, grade] of Object.entries(verifiers))
|
|
3101
|
-
fold(`${VERIFIER_REWARD_PREFIX}${name}`, grade);
|
|
3102
|
-
|
|
3103
|
-
|
|
3357
|
+
fold.add(`${VERIFIER_REWARD_PREFIX}${name}`, grade, `verifier ${name}`);
|
|
3358
|
+
return {
|
|
3359
|
+
reward: fold.reward(),
|
|
3360
|
+
rewards: fold.rewards,
|
|
3361
|
+
worlds,
|
|
3362
|
+
ungraded: fold.ungraded,
|
|
3363
|
+
verifiers,
|
|
3364
|
+
errors: fold.errors
|
|
3365
|
+
};
|
|
3366
|
+
}
|
|
3367
|
+
function taskGradeError(grade) {
|
|
3368
|
+
const lines = Object.entries(grade.errors).map(
|
|
3369
|
+
([key, why]) => `${key}: ${why}`
|
|
3370
|
+
);
|
|
3371
|
+
return lines.length ? lines.join("; ") : null;
|
|
3104
3372
|
}
|
|
3105
3373
|
function fromResponse(answer, options) {
|
|
3106
3374
|
const sessions = {};
|
|
@@ -3223,12 +3491,13 @@ async function attachManifest(manifest, options = {}) {
|
|
|
3223
3491
|
function isTaskManifest(value) {
|
|
3224
3492
|
return typeof value === "object" && value !== null && !Array.isArray(value) && typeof value.sessions === "object" && value.sessions !== null && !("instruction" in value && "worlds" in value);
|
|
3225
3493
|
}
|
|
3226
|
-
var TASK_SESSIONS, VERIFIER_REWARD_PREFIX, manifestSession, TaskSessions;
|
|
3494
|
+
var TASK_SESSIONS, VERIFIER_REWARD_PREFIX, manifestSession, TaskGradeFold, TaskSessions;
|
|
3227
3495
|
var init_taskSessions = __esm({
|
|
3228
3496
|
"src/worlds/taskSessions.ts"() {
|
|
3229
3497
|
"use strict";
|
|
3230
3498
|
init_worlds();
|
|
3231
3499
|
init_browser();
|
|
3500
|
+
init_grade();
|
|
3232
3501
|
init_surfaceDescriptor();
|
|
3233
3502
|
init_session2();
|
|
3234
3503
|
TASK_SESSIONS = "/api/public/world-task-sessions";
|
|
@@ -3243,6 +3512,36 @@ var init_taskSessions = __esm({
|
|
|
3243
3512
|
state: state2.state,
|
|
3244
3513
|
...surfaceDescriptor(s)
|
|
3245
3514
|
});
|
|
3515
|
+
TaskGradeFold = class {
|
|
3516
|
+
rewards = {};
|
|
3517
|
+
ungraded = [];
|
|
3518
|
+
errors = {};
|
|
3519
|
+
sources = /* @__PURE__ */ new Map();
|
|
3520
|
+
graded = [];
|
|
3521
|
+
add(key, grade, source) {
|
|
3522
|
+
if (grade.error) this.errors[key] = grade.error;
|
|
3523
|
+
if (typeof grade.reward === "number") {
|
|
3524
|
+
this.put(key, grade.reward, source);
|
|
3525
|
+
this.graded.push(grade.reward);
|
|
3526
|
+
} else this.ungraded.push(key);
|
|
3527
|
+
for (const [name, value] of Object.entries(grade.rewards))
|
|
3528
|
+
this.put(`${key}.${name}`, value, source);
|
|
3529
|
+
}
|
|
3530
|
+
reward() {
|
|
3531
|
+
if (Object.keys(this.errors).length > 0 || !this.graded.length)
|
|
3532
|
+
return null;
|
|
3533
|
+
return this.graded.reduce((a, b) => a + b, 0) / this.graded.length;
|
|
3534
|
+
}
|
|
3535
|
+
put(key, value, source) {
|
|
3536
|
+
const first = this.sources.get(key) ?? source;
|
|
3537
|
+
this.sources.set(key, first);
|
|
3538
|
+
if (first !== source) {
|
|
3539
|
+
this.errors[key] = `two rewards are named ${key} (${first} and ${source}); rename one of them`;
|
|
3540
|
+
return;
|
|
3541
|
+
}
|
|
3542
|
+
this.rewards[key] = value;
|
|
3543
|
+
}
|
|
3544
|
+
};
|
|
3246
3545
|
TaskSessions = class {
|
|
3247
3546
|
constructor(taskId, taskVersion, name, instruction, sessions, worlds, hash = null) {
|
|
3248
3547
|
this.taskId = taskId;
|
|
@@ -3321,11 +3620,13 @@ var init_taskSessions = __esm({
|
|
|
3321
3620
|
* agent's own account of the whole investigation) goes to every world's
|
|
3322
3621
|
* judge; a world graded by assertions or python ignores it. Each grade
|
|
3323
3622
|
* names the task's other sessions by alias, so the cross-world verifiers
|
|
3324
|
-
* anchored on that world can read them.
|
|
3623
|
+
* anchored on that world can read them. A world whose grade call fails is
|
|
3624
|
+
* that world's error: the task's grade names it and keeps every other
|
|
3625
|
+
* world's grade. */
|
|
3325
3626
|
async grade(opts = {}) {
|
|
3326
3627
|
return aggregateTaskGrade(
|
|
3327
3628
|
await this.each(
|
|
3328
|
-
(session, alias) => session.grade({ ...opts, worlds: this.otherSessions(alias) })
|
|
3629
|
+
(session, alias) => session.grade({ ...opts, worlds: this.otherSessions(alias) }).catch((error) => GradePayload.failedCall(error))
|
|
3329
3630
|
)
|
|
3330
3631
|
);
|
|
3331
3632
|
}
|
|
@@ -3373,12 +3674,16 @@ var init_evals = __esm({
|
|
|
3373
3674
|
"src/worlds/evals.ts"() {
|
|
3374
3675
|
"use strict";
|
|
3375
3676
|
init_worlds();
|
|
3677
|
+
init_transport();
|
|
3376
3678
|
EVALUATIONS = "/api/public/benchmark-containers/evaluations";
|
|
3377
3679
|
GatewayEvalsClient = class {
|
|
3378
|
-
constructor(options = {}) {
|
|
3680
|
+
constructor(options = {}, retry = RetryPolicy.FILING) {
|
|
3379
3681
|
this.options = options;
|
|
3682
|
+
this.retry = retry;
|
|
3380
3683
|
}
|
|
3381
3684
|
options;
|
|
3685
|
+
retry;
|
|
3686
|
+
keyed = /* @__PURE__ */ new Set();
|
|
3382
3687
|
async createEvaluation(versionId, opts = {}) {
|
|
3383
3688
|
const body = { versionId };
|
|
3384
3689
|
if (opts.model !== void 0) body.model = opts.model;
|
|
@@ -3386,12 +3691,18 @@ var init_evals = __esm({
|
|
|
3386
3691
|
if (opts.rolloutsPerExample !== void 0)
|
|
3387
3692
|
body.rolloutsPerExample = opts.rolloutsPerExample;
|
|
3388
3693
|
if (opts.metadata !== void 0) body.metadata = opts.metadata;
|
|
3694
|
+
if (opts.idempotencyKey !== void 0)
|
|
3695
|
+
body.idempotencyKey = opts.idempotencyKey;
|
|
3389
3696
|
const answer = await apiRequest(
|
|
3390
3697
|
this.options,
|
|
3391
3698
|
"POST",
|
|
3392
3699
|
EVALUATIONS,
|
|
3393
|
-
body
|
|
3700
|
+
body,
|
|
3701
|
+
{
|
|
3702
|
+
retry: opts.idempotencyKey === void 0 ? RetryPolicy.NONE : this.retry
|
|
3703
|
+
}
|
|
3394
3704
|
);
|
|
3705
|
+
if (opts.idempotencyKey !== void 0) this.keyed.add(answer.evaluationId);
|
|
3395
3706
|
return answer.evaluationId;
|
|
3396
3707
|
}
|
|
3397
3708
|
async pushSamples(evaluationId, samples) {
|
|
@@ -3399,7 +3710,8 @@ var init_evals = __esm({
|
|
|
3399
3710
|
this.options,
|
|
3400
3711
|
"POST",
|
|
3401
3712
|
`${EVALUATIONS}/${encodeURIComponent(evaluationId)}/samples`,
|
|
3402
|
-
{ samples }
|
|
3713
|
+
{ samples },
|
|
3714
|
+
{ retry: this.retryFor(evaluationId) }
|
|
3403
3715
|
);
|
|
3404
3716
|
return answer.inserted ?? samples.length;
|
|
3405
3717
|
}
|
|
@@ -3412,10 +3724,300 @@ var init_evals = __esm({
|
|
|
3412
3724
|
this.options,
|
|
3413
3725
|
"POST",
|
|
3414
3726
|
`${EVALUATIONS}/${encodeURIComponent(evaluationId)}/finalize`,
|
|
3415
|
-
body
|
|
3727
|
+
body,
|
|
3728
|
+
{ retry: this.retryFor(evaluationId) }
|
|
3416
3729
|
);
|
|
3417
3730
|
return answer.status;
|
|
3418
3731
|
}
|
|
3732
|
+
retryFor(evaluationId) {
|
|
3733
|
+
return this.keyed.has(evaluationId) ? this.retry : RetryPolicy.NONE;
|
|
3734
|
+
}
|
|
3735
|
+
};
|
|
3736
|
+
}
|
|
3737
|
+
});
|
|
3738
|
+
|
|
3739
|
+
// src/worlds/runSignals.ts
|
|
3740
|
+
var import_node_os, OWNER, RunSignals;
|
|
3741
|
+
var init_runSignals = __esm({
|
|
3742
|
+
"src/worlds/runSignals.ts"() {
|
|
3743
|
+
"use strict";
|
|
3744
|
+
import_node_os = require("os");
|
|
3745
|
+
OWNER = /* @__PURE__ */ Symbol("RunSignals");
|
|
3746
|
+
RunSignals = class _RunSignals {
|
|
3747
|
+
constructor(target = process) {
|
|
3748
|
+
this.target = target;
|
|
3749
|
+
}
|
|
3750
|
+
target;
|
|
3751
|
+
static SIGNALS = ["SIGINT", "SIGTERM"];
|
|
3752
|
+
cleanups = [];
|
|
3753
|
+
heardSignal = null;
|
|
3754
|
+
heardCount = 0;
|
|
3755
|
+
listening = false;
|
|
3756
|
+
left = false;
|
|
3757
|
+
listener = Object.assign(
|
|
3758
|
+
(signal) => this.heard(signal),
|
|
3759
|
+
{ [OWNER]: this }
|
|
3760
|
+
);
|
|
3761
|
+
/** The signal that arrived, once one has: start nothing new. */
|
|
3762
|
+
get signal() {
|
|
3763
|
+
return this.owner().heardSignal;
|
|
3764
|
+
}
|
|
3765
|
+
async during(cleanup, work) {
|
|
3766
|
+
return this.owner().hold(cleanup, work);
|
|
3767
|
+
}
|
|
3768
|
+
owner() {
|
|
3769
|
+
const owners = this.target.listeners("SIGINT").map((listener) => listener[OWNER]);
|
|
3770
|
+
return owners.find((owner) => owner !== void 0) ?? this;
|
|
3771
|
+
}
|
|
3772
|
+
async hold(cleanup, work) {
|
|
3773
|
+
this.listen();
|
|
3774
|
+
this.cleanups.push(cleanup);
|
|
3775
|
+
try {
|
|
3776
|
+
return await work();
|
|
3777
|
+
} finally {
|
|
3778
|
+
this.cleanups.splice(this.cleanups.indexOf(cleanup), 1);
|
|
3779
|
+
if (!this.cleanups.length && this.heardSignal === null) this.unlisten();
|
|
3780
|
+
}
|
|
3781
|
+
}
|
|
3782
|
+
heard(signal) {
|
|
3783
|
+
this.heardCount += 1;
|
|
3784
|
+
if (this.heardCount > 2) return this.leave(signal);
|
|
3785
|
+
this.heardSignal ??= signal;
|
|
3786
|
+
void this.cleanUp(signal, this.heardCount === 2).finally(() => this.leave(signal));
|
|
3787
|
+
}
|
|
3788
|
+
async cleanUp(signal, urgent) {
|
|
3789
|
+
for (const cleanup of [...this.cleanups].reverse())
|
|
3790
|
+
await Promise.resolve().then(() => cleanup(signal, urgent)).catch(() => void 0);
|
|
3791
|
+
}
|
|
3792
|
+
leave(signal) {
|
|
3793
|
+
if (this.left) return;
|
|
3794
|
+
this.left = true;
|
|
3795
|
+
this.unlisten();
|
|
3796
|
+
if (this.target.listenerCount(signal) === 0)
|
|
3797
|
+
this.target.exit(128 + import_node_os.constants.signals[signal]);
|
|
3798
|
+
}
|
|
3799
|
+
listen() {
|
|
3800
|
+
if (this.listening) return;
|
|
3801
|
+
this.listening = true;
|
|
3802
|
+
for (const signal of _RunSignals.SIGNALS)
|
|
3803
|
+
this.target.on(signal, this.listener);
|
|
3804
|
+
}
|
|
3805
|
+
unlisten() {
|
|
3806
|
+
this.listening = false;
|
|
3807
|
+
for (const signal of _RunSignals.SIGNALS)
|
|
3808
|
+
this.target.off(signal, this.listener);
|
|
3809
|
+
}
|
|
3810
|
+
};
|
|
3811
|
+
}
|
|
3812
|
+
});
|
|
3813
|
+
|
|
3814
|
+
// src/worlds/taskRunDir.ts
|
|
3815
|
+
function sessionRecord({ api: api2, ui, browser, ...session }) {
|
|
3816
|
+
return {
|
|
3817
|
+
...session,
|
|
3818
|
+
...api2 ? { api: { url: api2.url } } : {},
|
|
3819
|
+
...ui ? { ui: { ...ui, entry: withoutUiToken(ui.entry) } } : {},
|
|
3820
|
+
...browser ? { browser: browserRecord(browser) } : {}
|
|
3821
|
+
};
|
|
3822
|
+
}
|
|
3823
|
+
var fs, path, TaskRunDir, browserRecord;
|
|
3824
|
+
var init_taskRunDir = __esm({
|
|
3825
|
+
"src/worlds/taskRunDir.ts"() {
|
|
3826
|
+
"use strict";
|
|
3827
|
+
fs = __toESM(require("fs"));
|
|
3828
|
+
path = __toESM(require("path"));
|
|
3829
|
+
init_browser();
|
|
3830
|
+
TaskRunDir = class {
|
|
3831
|
+
constructor(path13) {
|
|
3832
|
+
this.path = path13;
|
|
3833
|
+
}
|
|
3834
|
+
path;
|
|
3835
|
+
writeManifest(manifest) {
|
|
3836
|
+
this.writeJson("manifest.json", {
|
|
3837
|
+
...manifest,
|
|
3838
|
+
sessions: Object.fromEntries(
|
|
3839
|
+
Object.entries(manifest.sessions).map(([alias, session]) => [
|
|
3840
|
+
alias,
|
|
3841
|
+
sessionRecord(session)
|
|
3842
|
+
])
|
|
3843
|
+
)
|
|
3844
|
+
});
|
|
3845
|
+
}
|
|
3846
|
+
writeJson(name, value) {
|
|
3847
|
+
this.write(name, JSON.stringify(value, null, 2));
|
|
3848
|
+
}
|
|
3849
|
+
write(name, text2) {
|
|
3850
|
+
fs.mkdirSync(this.path, { recursive: true });
|
|
3851
|
+
fs.writeFileSync(path.join(this.path, name), text2);
|
|
3852
|
+
}
|
|
3853
|
+
};
|
|
3854
|
+
browserRecord = ({ viewport, tier }) => ({
|
|
3855
|
+
viewport,
|
|
3856
|
+
...tier ? { tier } : {}
|
|
3857
|
+
});
|
|
3858
|
+
}
|
|
3859
|
+
});
|
|
3860
|
+
|
|
3861
|
+
// src/worlds/taskRunOutcome.ts
|
|
3862
|
+
var TaskRunOutcome;
|
|
3863
|
+
var init_taskRunOutcome = __esm({
|
|
3864
|
+
"src/worlds/taskRunOutcome.ts"() {
|
|
3865
|
+
"use strict";
|
|
3866
|
+
init_grade();
|
|
3867
|
+
init_taskSessions();
|
|
3868
|
+
TaskRunOutcome = class {
|
|
3869
|
+
constructor(runId, live, model, runDir) {
|
|
3870
|
+
this.runId = runId;
|
|
3871
|
+
this.live = live;
|
|
3872
|
+
this.model = model;
|
|
3873
|
+
this.runDir = runDir;
|
|
3874
|
+
}
|
|
3875
|
+
runId;
|
|
3876
|
+
live;
|
|
3877
|
+
model;
|
|
3878
|
+
runDir;
|
|
3879
|
+
report = null;
|
|
3880
|
+
extra = {};
|
|
3881
|
+
notes = {};
|
|
3882
|
+
agentError = null;
|
|
3883
|
+
grade = null;
|
|
3884
|
+
traced = false;
|
|
3885
|
+
runError = null;
|
|
3886
|
+
fileError = null;
|
|
3887
|
+
evaluationId;
|
|
3888
|
+
evaluationStatus = null;
|
|
3889
|
+
started = Date.now();
|
|
3890
|
+
/** The run stopped short of a grade; the first reason stands. */
|
|
3891
|
+
stopped(error) {
|
|
3892
|
+
this.runError ??= messageOf(error).slice(0, 2e3);
|
|
3893
|
+
}
|
|
3894
|
+
agentRaised(error) {
|
|
3895
|
+
this.agentError = messageOf(error).slice(0, 2e3);
|
|
3896
|
+
}
|
|
3897
|
+
/** Every reason the run failed, on one line: the evaluation's
|
|
3898
|
+
* `metrics.error`. A run that never reached a grade has failed whatever
|
|
3899
|
+
* its reasons say. */
|
|
3900
|
+
failure() {
|
|
3901
|
+
const reasons = [
|
|
3902
|
+
this.agentError === null ? null : `agent raised: ${this.agentError}`,
|
|
3903
|
+
this.runError === null ? null : `the run stopped: ${this.runError}`,
|
|
3904
|
+
this.gradeError(),
|
|
3905
|
+
this.grade === null && this.runError === null ? "the run stopped before it was graded" : null
|
|
3906
|
+
].filter((reason) => reason !== null);
|
|
3907
|
+
return reasons.length ? reasons.join("; ") : null;
|
|
3908
|
+
}
|
|
3909
|
+
async file(evals, setRunId) {
|
|
3910
|
+
let created;
|
|
3911
|
+
try {
|
|
3912
|
+
created = await evals.createEvaluation(this.ref(this.live.aliases[0]).versionId, {
|
|
3913
|
+
model: this.model,
|
|
3914
|
+
rolloutsPerExample: 1,
|
|
3915
|
+
idempotencyKey: this.runId,
|
|
3916
|
+
...setRunId ? { runId: setRunId } : {},
|
|
3917
|
+
metadata: this.metadata()
|
|
3918
|
+
});
|
|
3919
|
+
await evals.pushSamples(created, [this.sample()]);
|
|
3920
|
+
this.evaluationStatus = await evals.finalizeEvaluation(created, this.finalized());
|
|
3921
|
+
this.evaluationId = created;
|
|
3922
|
+
} catch (error) {
|
|
3923
|
+
this.fileError = created ? `evaluation ${created}: ${messageOf(error)}` : messageOf(error);
|
|
3924
|
+
if (created)
|
|
3925
|
+
await evals.finalizeEvaluation(created, { status: "FAILED", metrics: { error: this.fileError } }).catch(() => void 0);
|
|
3926
|
+
}
|
|
3927
|
+
}
|
|
3928
|
+
summary() {
|
|
3929
|
+
const live = this.live;
|
|
3930
|
+
const { evaluationId: _agentEvaluationId, ...extra } = this.extra;
|
|
3931
|
+
return {
|
|
3932
|
+
...extra,
|
|
3933
|
+
runId: this.runId,
|
|
3934
|
+
taskId: live.taskId,
|
|
3935
|
+
taskVersion: live.taskVersion,
|
|
3936
|
+
name: live.name,
|
|
3937
|
+
instruction: live.instruction ?? "",
|
|
3938
|
+
model: this.model,
|
|
3939
|
+
aliases: live.aliases,
|
|
3940
|
+
reward: this.grade?.reward ?? null,
|
|
3941
|
+
rewards: this.grade?.rewards ?? {},
|
|
3942
|
+
ungraded: this.grade?.ungraded ?? live.aliases,
|
|
3943
|
+
agentError: this.agentError,
|
|
3944
|
+
runError: this.runError,
|
|
3945
|
+
gradeError: this.gradeError(),
|
|
3946
|
+
fileError: this.fileError,
|
|
3947
|
+
evaluationStatus: this.evaluationStatus,
|
|
3948
|
+
report: this.report,
|
|
3949
|
+
traced: this.traced,
|
|
3950
|
+
runDir: this.runDir,
|
|
3951
|
+
durationSeconds: Math.round((Date.now() - this.started) / 10) / 100,
|
|
3952
|
+
notes: this.notes,
|
|
3953
|
+
filed: this.evaluationId !== void 0,
|
|
3954
|
+
...this.evaluationId ? { evaluationId: this.evaluationId } : {}
|
|
3955
|
+
};
|
|
3956
|
+
}
|
|
3957
|
+
gradeError() {
|
|
3958
|
+
return this.grade ? taskGradeError(this.grade) : null;
|
|
3959
|
+
}
|
|
3960
|
+
ref(alias) {
|
|
3961
|
+
const { slug, ref } = this.live.worldRef(alias);
|
|
3962
|
+
const session = this.live.sessions[alias];
|
|
3963
|
+
return { slug, ref, versionId: session.versionId, sessionId: session.sessionId };
|
|
3964
|
+
}
|
|
3965
|
+
metadata() {
|
|
3966
|
+
const live = this.live;
|
|
3967
|
+
return {
|
|
3968
|
+
source: "worlds-task-run",
|
|
3969
|
+
task: { id: live.taskId, version: live.taskVersion, name: live.name, hash: live.hash },
|
|
3970
|
+
anchor: live.aliases[0],
|
|
3971
|
+
worlds: Object.fromEntries(live.aliases.map((alias) => [alias, this.ref(alias)])),
|
|
3972
|
+
runId: this.runId
|
|
3973
|
+
};
|
|
3974
|
+
}
|
|
3975
|
+
sample() {
|
|
3976
|
+
const live = this.live;
|
|
3977
|
+
const reward = this.grade?.reward ?? null;
|
|
3978
|
+
const gradeError = this.gradeError();
|
|
3979
|
+
const sample = {
|
|
3980
|
+
exampleId: live.name ?? live.taskId ?? this.runId,
|
|
3981
|
+
task: live.name ?? live.taskId ?? this.runId,
|
|
3982
|
+
rolloutIndex: 0,
|
|
3983
|
+
prompt: live.instruction,
|
|
3984
|
+
...this.report === null ? {} : { completion: this.report },
|
|
3985
|
+
rewards: this.grade?.rewards ?? {},
|
|
3986
|
+
info: {
|
|
3987
|
+
sessionId: this.runId,
|
|
3988
|
+
worlds: Object.fromEntries(
|
|
3989
|
+
live.aliases.map((alias) => [
|
|
3990
|
+
alias,
|
|
3991
|
+
{ ...this.ref(alias), reward: this.grade?.worlds[alias]?.reward ?? null }
|
|
3992
|
+
])
|
|
3993
|
+
),
|
|
3994
|
+
ungraded: this.grade?.ungraded ?? live.aliases,
|
|
3995
|
+
traced: this.traced,
|
|
3996
|
+
runDir: this.runDir,
|
|
3997
|
+
...this.agentError ? { agentError: this.agentError } : {},
|
|
3998
|
+
...this.runError ? { runError: this.runError } : {},
|
|
3999
|
+
...gradeError ? { verifyError: gradeError } : {}
|
|
4000
|
+
}
|
|
4001
|
+
};
|
|
4002
|
+
if (typeof reward === "number")
|
|
4003
|
+
Object.assign(sample, { reward, score: reward, correct: reward >= 1 });
|
|
4004
|
+
return sample;
|
|
4005
|
+
}
|
|
4006
|
+
finalized() {
|
|
4007
|
+
const reward = this.grade?.reward ?? null;
|
|
4008
|
+
const failure = this.failure();
|
|
4009
|
+
return {
|
|
4010
|
+
status: failure ? "FAILED" : "COMPLETED",
|
|
4011
|
+
metrics: {
|
|
4012
|
+
...typeof reward === "number" ? { avg_reward: reward } : {},
|
|
4013
|
+
reward,
|
|
4014
|
+
...Object.fromEntries(
|
|
4015
|
+
Object.entries(this.grade?.rewards ?? {}).map(([key, value]) => [`rewards.${key}`, value])
|
|
4016
|
+
),
|
|
4017
|
+
...failure ? { error: failure } : {}
|
|
4018
|
+
}
|
|
4019
|
+
};
|
|
4020
|
+
}
|
|
3419
4021
|
};
|
|
3420
4022
|
}
|
|
3421
4023
|
});
|
|
@@ -3428,7 +4030,7 @@ function getEnv(key) {
|
|
|
3428
4030
|
function isGatewayConfigured() {
|
|
3429
4031
|
return !!(getEnv(GATEWAY_ENV.HOST) && getEnv(GATEWAY_ENV.PUBLIC_KEY) && getEnv(GATEWAY_ENV.SECRET_KEY));
|
|
3430
4032
|
}
|
|
3431
|
-
var GATEWAY_ENV, OPENTELEMETRY_PEERS, MODULE_NOT_FOUND, OpenTelemetryMissing;
|
|
4033
|
+
var GATEWAY_ENV, OTLP_TRACES_PATH, OPENTELEMETRY_PEERS, PINNED_PEERS, MODULE_NOT_FOUND, OpenTelemetryMissing;
|
|
3432
4034
|
var init_prerequisites = __esm({
|
|
3433
4035
|
"src/tracing/prerequisites.ts"() {
|
|
3434
4036
|
"use strict";
|
|
@@ -3436,21 +4038,25 @@ var init_prerequisites = __esm({
|
|
|
3436
4038
|
HOST: "GATEWAY_HOST",
|
|
3437
4039
|
PUBLIC_KEY: "GATEWAY_PUBLIC_KEY",
|
|
3438
4040
|
SECRET_KEY: "GATEWAY_SECRET_KEY",
|
|
4041
|
+
API_KEY: "GATEWAY_API_KEY",
|
|
3439
4042
|
ENDPOINT: "GATEWAY_OTLP_ENDPOINT"
|
|
3440
4043
|
};
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
"@opentelemetry/
|
|
3444
|
-
"@opentelemetry/
|
|
3445
|
-
"@opentelemetry/
|
|
3446
|
-
"@opentelemetry/sdk-trace-
|
|
3447
|
-
|
|
4044
|
+
OTLP_TRACES_PATH = "/api/public/otel/v1/traces";
|
|
4045
|
+
OPENTELEMETRY_PEERS = {
|
|
4046
|
+
"@opentelemetry/api": "1.9.0",
|
|
4047
|
+
"@opentelemetry/exporter-trace-otlp-http": "0.222.0",
|
|
4048
|
+
"@opentelemetry/resources": "2.11.0",
|
|
4049
|
+
"@opentelemetry/sdk-trace-base": "2.11.0",
|
|
4050
|
+
"@opentelemetry/sdk-trace-node": "2.11.0"
|
|
4051
|
+
};
|
|
4052
|
+
PINNED_PEERS = Object.entries(OPENTELEMETRY_PEERS).map(([name, version]) => `${name}@${version}`).join(" ");
|
|
3448
4053
|
MODULE_NOT_FOUND = /* @__PURE__ */ new Set(["MODULE_NOT_FOUND", "ERR_MODULE_NOT_FOUND"]);
|
|
3449
4054
|
OpenTelemetryMissing = class _OpenTelemetryMissing extends Error {
|
|
3450
4055
|
constructor() {
|
|
3451
4056
|
super(
|
|
3452
|
-
`OpenTelemetry packages not found. Install them with:
|
|
3453
|
-
npm install ${
|
|
4057
|
+
`OpenTelemetry packages not found. Install them next to @withgateway/sdk, at the versions it is tested with:
|
|
4058
|
+
npm install ${PINNED_PEERS}
|
|
4059
|
+
npm install -g ${PINNED_PEERS} (the gateway CLI, when it was installed with npm install -g)`
|
|
3454
4060
|
);
|
|
3455
4061
|
this.name = "OpenTelemetryMissing";
|
|
3456
4062
|
}
|
|
@@ -3625,10 +4231,10 @@ var init_users = __esm({
|
|
|
3625
4231
|
totalItems: Number(meta.totalItems ?? rows.length)
|
|
3626
4232
|
};
|
|
3627
4233
|
}
|
|
3628
|
-
async requestJson(method,
|
|
4234
|
+
async requestJson(method, path13, payload) {
|
|
3629
4235
|
let response;
|
|
3630
4236
|
try {
|
|
3631
|
-
response = await fetch(`${this.host}${
|
|
4237
|
+
response = await fetch(`${this.host}${path13}`, {
|
|
3632
4238
|
method,
|
|
3633
4239
|
headers: {
|
|
3634
4240
|
Authorization: this.authHeader(),
|
|
@@ -3639,17 +4245,17 @@ var init_users = __esm({
|
|
|
3639
4245
|
});
|
|
3640
4246
|
} catch (error) {
|
|
3641
4247
|
throw new UserProfileError(
|
|
3642
|
-
`${method} ${
|
|
4248
|
+
`${method} ${path13} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
3643
4249
|
{ cause: error }
|
|
3644
4250
|
);
|
|
3645
4251
|
}
|
|
3646
4252
|
const text2 = await response.text();
|
|
3647
4253
|
if (!response.ok) {
|
|
3648
4254
|
throw new UserProfileError(
|
|
3649
|
-
`${method} ${
|
|
4255
|
+
`${method} ${path13} failed (${response.status}): ${text2.slice(0, 500)}`
|
|
3650
4256
|
);
|
|
3651
4257
|
}
|
|
3652
|
-
this.log("%s %s -> %s", method,
|
|
4258
|
+
this.log("%s %s -> %s", method, path13, response.status);
|
|
3653
4259
|
return safeJson(text2);
|
|
3654
4260
|
}
|
|
3655
4261
|
authHeader() {
|
|
@@ -4094,10 +4700,10 @@ var init_scores = __esm({
|
|
|
4094
4700
|
metadata: signalMetadata
|
|
4095
4701
|
});
|
|
4096
4702
|
}
|
|
4097
|
-
async request(method,
|
|
4703
|
+
async request(method, path13, payload) {
|
|
4098
4704
|
let response;
|
|
4099
4705
|
try {
|
|
4100
|
-
response = await fetch(`${this.host}${
|
|
4706
|
+
response = await fetch(`${this.host}${path13}`, {
|
|
4101
4707
|
method,
|
|
4102
4708
|
headers: {
|
|
4103
4709
|
Authorization: this.authHeader(),
|
|
@@ -4108,17 +4714,17 @@ var init_scores = __esm({
|
|
|
4108
4714
|
});
|
|
4109
4715
|
} catch (error) {
|
|
4110
4716
|
throw new ScoreError(
|
|
4111
|
-
`${method} ${
|
|
4717
|
+
`${method} ${path13} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
4112
4718
|
{ cause: error }
|
|
4113
4719
|
);
|
|
4114
4720
|
}
|
|
4115
4721
|
const text2 = await response.text();
|
|
4116
4722
|
if (!response.ok) {
|
|
4117
4723
|
throw new ScoreError(
|
|
4118
|
-
`${method} ${
|
|
4724
|
+
`${method} ${path13} failed (${response.status}): ${text2.slice(0, 500)}`
|
|
4119
4725
|
);
|
|
4120
4726
|
}
|
|
4121
|
-
this.log("%s %s -> %s", method,
|
|
4727
|
+
this.log("%s %s -> %s", method, path13, response.status);
|
|
4122
4728
|
}
|
|
4123
4729
|
authHeader() {
|
|
4124
4730
|
return `Basic ${Buffer.from(`${this.publicKey}:${this.secretKey}`).toString(
|
|
@@ -4146,7 +4752,7 @@ var require_package = __commonJS({
|
|
|
4146
4752
|
"package.json"(exports2, module2) {
|
|
4147
4753
|
module2.exports = {
|
|
4148
4754
|
name: "@withgateway/sdk",
|
|
4149
|
-
version: "0.3.
|
|
4755
|
+
version: "0.3.3",
|
|
4150
4756
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
4151
4757
|
main: "./dist/index.js",
|
|
4152
4758
|
module: "./dist/index.mjs",
|
|
@@ -4567,7 +5173,7 @@ function buildProvider(config, logFn) {
|
|
|
4567
5173
|
const host = config.host ?? getEnv(GATEWAY_ENV.HOST);
|
|
4568
5174
|
const publicKey = config.publicKey ?? getEnv(GATEWAY_ENV.PUBLIC_KEY);
|
|
4569
5175
|
const secretKey = config.secretKey ?? getEnv(GATEWAY_ENV.SECRET_KEY);
|
|
4570
|
-
const endpoint = config.endpoint ?? getEnv(GATEWAY_ENV.ENDPOINT) ?? (host ? `${host.replace(/\/$/, "")}${
|
|
5176
|
+
const endpoint = config.endpoint ?? getEnv(GATEWAY_ENV.ENDPOINT) ?? (host ? `${host.replace(/\/$/, "")}${OTLP_TRACES_PATH}` : void 0);
|
|
4571
5177
|
const missing = [];
|
|
4572
5178
|
if (!host) missing.push("host (or GATEWAY_HOST env var)");
|
|
4573
5179
|
if (!publicKey) missing.push("publicKey (or GATEWAY_PUBLIC_KEY env var)");
|
|
@@ -4810,7 +5416,7 @@ async function shutdown() {
|
|
|
4810
5416
|
function isInitialized() {
|
|
4811
5417
|
return state.initialized;
|
|
4812
5418
|
}
|
|
4813
|
-
var
|
|
5419
|
+
var state;
|
|
4814
5420
|
var init_init = __esm({
|
|
4815
5421
|
"src/tracing/init.ts"() {
|
|
4816
5422
|
"use strict";
|
|
@@ -4821,7 +5427,6 @@ var init_init = __esm({
|
|
|
4821
5427
|
init_build();
|
|
4822
5428
|
init_prerequisites();
|
|
4823
5429
|
init_prerequisites();
|
|
4824
|
-
DEFAULT_OTLP_PATH = "/api/public/otel/v1/traces";
|
|
4825
5430
|
state = {
|
|
4826
5431
|
initialized: false,
|
|
4827
5432
|
provider: null
|
|
@@ -4830,124 +5435,94 @@ var init_init = __esm({
|
|
|
4830
5435
|
});
|
|
4831
5436
|
|
|
4832
5437
|
// src/worlds/taskTracing.ts
|
|
4833
|
-
var TaskTracing;
|
|
5438
|
+
var HOST_WITH_AUTHORITY, TRACING_HELD_ELSEWHERE, TaskTracing;
|
|
4834
5439
|
var init_taskTracing = __esm({
|
|
4835
5440
|
"src/worlds/taskTracing.ts"() {
|
|
4836
5441
|
"use strict";
|
|
4837
5442
|
init_prerequisites();
|
|
5443
|
+
init_platformEndpoint();
|
|
5444
|
+
HOST_WITH_AUTHORITY = /^[a-z][a-z0-9+.-]*:\/\/[^/\\?#@\s]+(\/|$)/i;
|
|
5445
|
+
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.";
|
|
4838
5446
|
TaskTracing = class _TaskTracing {
|
|
4839
5447
|
constructor(load = () => Promise.resolve().then(() => (init_init(), init_exports))) {
|
|
4840
5448
|
this.load = load;
|
|
4841
5449
|
}
|
|
4842
5450
|
load;
|
|
4843
5451
|
static warned = false;
|
|
4844
|
-
|
|
4845
|
-
|
|
5452
|
+
static target = null;
|
|
5453
|
+
async start(requested, options) {
|
|
5454
|
+
if (!requested) return false;
|
|
5455
|
+
const endpoint = platformEndpoint(options);
|
|
4846
5456
|
try {
|
|
4847
|
-
|
|
5457
|
+
await this.initOnce(_TaskTracing.config(endpoint));
|
|
4848
5458
|
return true;
|
|
4849
5459
|
} catch (error) {
|
|
4850
|
-
_TaskTracing.warnOnce(error);
|
|
5460
|
+
_TaskTracing.warnOnce(_TaskTracing.reason(error, endpoint));
|
|
4851
5461
|
return false;
|
|
4852
5462
|
}
|
|
4853
5463
|
}
|
|
4854
|
-
|
|
5464
|
+
// init() keeps the first provider for the whole process and ignores later calls, so a later run is
|
|
5465
|
+
// traced only when it exports to the same place with the same keys.
|
|
5466
|
+
async initOnce(config) {
|
|
5467
|
+
const tracing = await this.load();
|
|
5468
|
+
const target = JSON.stringify([config.endpoint, config.publicKey, config.secretKey]);
|
|
5469
|
+
if (!tracing.isInitialized()) {
|
|
5470
|
+
tracing.init(config);
|
|
5471
|
+
_TaskTracing.target = target;
|
|
5472
|
+
return;
|
|
5473
|
+
}
|
|
5474
|
+
if (_TaskTracing.target !== target) throw new Error(TRACING_HELD_ELSEWHERE);
|
|
5475
|
+
}
|
|
5476
|
+
static config(endpoint) {
|
|
5477
|
+
if (!endpoint) throw new Error(GATEWAY_KEYS_MISSING);
|
|
5478
|
+
return { ...endpoint, endpoint: _TaskTracing.destination(endpoint) };
|
|
5479
|
+
}
|
|
5480
|
+
// B1: a saved login's keys go to their own host only. The redirect is compared as text, never parsed:
|
|
5481
|
+
// a fixed "<host>/" prefix leaves no URL parser room to read another host into it.
|
|
5482
|
+
static destination(endpoint) {
|
|
5483
|
+
const redirect = getEnv(GATEWAY_ENV.ENDPOINT);
|
|
5484
|
+
if (!redirect) return `${endpoint.host}${OTLP_TRACES_PATH}`;
|
|
5485
|
+
if (_TaskTracing.underHost(redirect, endpoint.host) || _TaskTracing.environmentKeys(endpoint)) return redirect;
|
|
5486
|
+
throw new Error(
|
|
5487
|
+
`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.`
|
|
5488
|
+
);
|
|
5489
|
+
}
|
|
5490
|
+
static underHost(redirect, host) {
|
|
5491
|
+
return HOST_WITH_AUTHORITY.test(host) && redirect.startsWith(`${host}/`);
|
|
5492
|
+
}
|
|
5493
|
+
static environmentKeys(endpoint) {
|
|
5494
|
+
const secretKey = getEnv(GATEWAY_ENV.SECRET_KEY) ?? getEnv(GATEWAY_ENV.API_KEY);
|
|
5495
|
+
return endpoint.publicKey === getEnv(GATEWAY_ENV.PUBLIC_KEY) && endpoint.secretKey === secretKey;
|
|
5496
|
+
}
|
|
5497
|
+
static warnOnce(reason) {
|
|
4855
5498
|
if (_TaskTracing.warned) return;
|
|
4856
5499
|
_TaskTracing.warned = true;
|
|
4857
5500
|
console.warn(
|
|
4858
|
-
`[gatewaysdk.tracing] Task runs in this process are not traced. ${
|
|
5501
|
+
`[gatewaysdk.tracing] Task runs in this process are not traced. ${reason}
|
|
4859
5502
|
Pass --no-trace (trace: false) to run untraced without this warning.`
|
|
4860
5503
|
);
|
|
4861
5504
|
}
|
|
4862
|
-
static reason(error) {
|
|
4863
|
-
if (OpenTelemetryMissing.explains(error))
|
|
4864
|
-
|
|
4865
|
-
|
|
5505
|
+
static reason(error, endpoint) {
|
|
5506
|
+
if (OpenTelemetryMissing.explains(error)) return new OpenTelemetryMissing().message;
|
|
5507
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
5508
|
+
const keys = endpoint ? [endpoint.publicKey, endpoint.secretKey] : [];
|
|
5509
|
+
return keys.reduce((text2, key) => text2.split(key).join("[redacted]"), message);
|
|
4866
5510
|
}
|
|
4867
5511
|
};
|
|
4868
5512
|
}
|
|
4869
5513
|
});
|
|
4870
5514
|
|
|
4871
5515
|
// src/worlds/taskRun.ts
|
|
4872
|
-
function
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
async function fileTaskRun(live, runId, model, report, grade, agentError, traced, runDir, options, setRunId) {
|
|
4883
|
-
const aliases = live.aliases;
|
|
4884
|
-
const anchor = aliases[0];
|
|
4885
|
-
const worldsMeta = Object.fromEntries(
|
|
4886
|
-
aliases.map((alias) => [alias, worldRef(live, alias)])
|
|
4887
|
-
);
|
|
4888
|
-
const evals = new GatewayEvalsClient(options);
|
|
4889
|
-
const evaluationId = await evals.createEvaluation(
|
|
4890
|
-
worldRef(live, anchor).versionId,
|
|
4891
|
-
{
|
|
4892
|
-
model,
|
|
4893
|
-
rolloutsPerExample: 1,
|
|
4894
|
-
...setRunId ? { runId: setRunId } : {},
|
|
4895
|
-
metadata: {
|
|
4896
|
-
source: "worlds-task-run",
|
|
4897
|
-
task: {
|
|
4898
|
-
id: live.taskId,
|
|
4899
|
-
version: live.taskVersion,
|
|
4900
|
-
name: live.name,
|
|
4901
|
-
hash: live.hash
|
|
4902
|
-
},
|
|
4903
|
-
anchor,
|
|
4904
|
-
worlds: worldsMeta,
|
|
4905
|
-
runId
|
|
4906
|
-
}
|
|
4907
|
-
}
|
|
4908
|
-
);
|
|
4909
|
-
const reward = grade.reward;
|
|
4910
|
-
const sample = {
|
|
4911
|
-
exampleId: live.name ?? live.taskId ?? runId,
|
|
4912
|
-
task: live.name ?? live.taskId ?? runId,
|
|
4913
|
-
rolloutIndex: 0,
|
|
4914
|
-
prompt: live.instruction,
|
|
4915
|
-
...report === null ? {} : { completion: report },
|
|
4916
|
-
rewards: grade.rewards,
|
|
4917
|
-
info: {
|
|
4918
|
-
sessionId: runId,
|
|
4919
|
-
worlds: Object.fromEntries(
|
|
4920
|
-
aliases.map((alias) => [
|
|
4921
|
-
alias,
|
|
4922
|
-
{
|
|
4923
|
-
...worldRef(live, alias),
|
|
4924
|
-
reward: grade.worlds[alias]?.reward ?? null
|
|
4925
|
-
}
|
|
4926
|
-
])
|
|
4927
|
-
),
|
|
4928
|
-
ungraded: grade.ungraded,
|
|
4929
|
-
traced,
|
|
4930
|
-
runDir,
|
|
4931
|
-
...agentError ? { agentError } : {}
|
|
4932
|
-
}
|
|
4933
|
-
};
|
|
4934
|
-
if (typeof reward === "number") {
|
|
4935
|
-
sample.reward = reward;
|
|
4936
|
-
sample.score = reward;
|
|
4937
|
-
sample.correct = reward >= 1;
|
|
4938
|
-
}
|
|
4939
|
-
await evals.pushSamples(evaluationId, [sample]);
|
|
4940
|
-
await evals.finalizeEvaluation(evaluationId, {
|
|
4941
|
-
status: agentError ? "FAILED" : "COMPLETED",
|
|
4942
|
-
metrics: {
|
|
4943
|
-
...typeof reward === "number" ? { avg_reward: reward } : {},
|
|
4944
|
-
reward,
|
|
4945
|
-
...Object.fromEntries(
|
|
4946
|
-
Object.entries(grade.rewards).map(([k, v]) => [`rewards.${k}`, v])
|
|
4947
|
-
)
|
|
4948
|
-
}
|
|
4949
|
-
});
|
|
4950
|
-
return evaluationId;
|
|
5516
|
+
function taskRunFailure(summary) {
|
|
5517
|
+
if (summary.agentError !== null) return `agent raised: ${summary.agentError}`;
|
|
5518
|
+
if (summary.runError !== null) return `the run stopped: ${summary.runError}`;
|
|
5519
|
+
if (summary.gradeError !== null)
|
|
5520
|
+
return `the task could not be graded: ${summary.gradeError}`;
|
|
5521
|
+
if (summary.fileError !== null)
|
|
5522
|
+
return `the run could not be filed: ${summary.fileError}`;
|
|
5523
|
+
if (summary.filed && summary.evaluationStatus !== "COMPLETED")
|
|
5524
|
+
return `the platform settled evaluation ${summary.evaluationId} as ${summary.evaluationStatus}`;
|
|
5525
|
+
return null;
|
|
4951
5526
|
}
|
|
4952
5527
|
function reportFromResult(result) {
|
|
4953
5528
|
if (result === void 0 || result === null)
|
|
@@ -4965,113 +5540,49 @@ function reportFromResult(result) {
|
|
|
4965
5540
|
);
|
|
4966
5541
|
return { report, extra };
|
|
4967
5542
|
}
|
|
5543
|
+
async function refuseUnreadTools(live) {
|
|
5544
|
+
try {
|
|
5545
|
+
for (const alias of live.aliases)
|
|
5546
|
+
WorldToolsUnread.refuse(`${live.worldRef(alias).slug} (alias ${alias})`, live.session(alias).deprecations);
|
|
5547
|
+
} catch (error) {
|
|
5548
|
+
await live.close({ keepWarm: false }).catch(() => void 0);
|
|
5549
|
+
throw error;
|
|
5550
|
+
}
|
|
5551
|
+
}
|
|
4968
5552
|
async function runTask(ref, agent, opts) {
|
|
4969
5553
|
const runId = `wtr-${(0, import_node_crypto4.randomBytes)(6).toString("hex")}`;
|
|
4970
|
-
const outDir = opts.outDir ?? "runs";
|
|
4971
|
-
const runDir = path.join(outDir, runId);
|
|
4972
|
-
fs.mkdirSync(runDir, { recursive: true });
|
|
4973
5554
|
const options = opts.options ?? {};
|
|
4974
|
-
const
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
await live.manifest()
|
|
4990
|
-
);
|
|
4991
|
-
let agentError = null;
|
|
4992
|
-
let report = null;
|
|
4993
|
-
let extra = {};
|
|
4994
|
-
try {
|
|
4995
|
-
const invoke = () => agent(taskRun);
|
|
4996
|
-
const result = traced ? await (await Promise.resolve().then(() => (init_session(), session_exports))).withSession(runId, invoke) : await invoke();
|
|
4997
|
-
({ report, extra } = reportFromResult(result));
|
|
4998
|
-
} catch (error) {
|
|
4999
|
-
const message = (error instanceof Error ? error.message : String(error)) || "Unknown error";
|
|
5000
|
-
agentError = message.slice(0, 2e3);
|
|
5001
|
-
}
|
|
5002
|
-
if (traced)
|
|
5003
|
-
await Promise.resolve().then(() => (init_init(), init_exports)).then((tracing) => tracing.flush()).catch(() => void 0);
|
|
5004
|
-
const grade = report !== null ? await live.grade({ report }) : await live.grade();
|
|
5005
|
-
fs.writeFileSync(
|
|
5006
|
-
path.join(runDir, "manifest.json"),
|
|
5007
|
-
JSON.stringify(taskRun.manifest, null, 2)
|
|
5008
|
-
);
|
|
5009
|
-
fs.writeFileSync(
|
|
5010
|
-
path.join(runDir, "grades.json"),
|
|
5011
|
-
JSON.stringify(grade, null, 2)
|
|
5012
|
-
);
|
|
5013
|
-
if (report) fs.writeFileSync(path.join(runDir, "report.md"), report);
|
|
5014
|
-
const summary = {
|
|
5015
|
-
runId,
|
|
5016
|
-
taskId: live.taskId,
|
|
5017
|
-
taskVersion: live.taskVersion,
|
|
5018
|
-
name: live.name,
|
|
5019
|
-
instruction: taskRun.instruction,
|
|
5020
|
-
model: opts.model,
|
|
5021
|
-
aliases: live.aliases,
|
|
5022
|
-
reward: grade.reward,
|
|
5023
|
-
rewards: grade.rewards,
|
|
5024
|
-
ungraded: grade.ungraded,
|
|
5025
|
-
agentError,
|
|
5026
|
-
report,
|
|
5027
|
-
traced,
|
|
5028
|
-
runDir,
|
|
5029
|
-
durationSeconds: Math.round((Date.now() - started) / 10) / 100,
|
|
5030
|
-
notes: taskRun.notes,
|
|
5031
|
-
filed: false,
|
|
5032
|
-
...extra
|
|
5033
|
-
};
|
|
5034
|
-
if (opts.file !== false) {
|
|
5035
|
-
summary.evaluationId = await fileTaskRun(
|
|
5036
|
-
live,
|
|
5037
|
-
runId,
|
|
5038
|
-
opts.model,
|
|
5039
|
-
report,
|
|
5040
|
-
grade,
|
|
5041
|
-
agentError,
|
|
5042
|
-
traced,
|
|
5043
|
-
runDir,
|
|
5044
|
-
options,
|
|
5045
|
-
opts.setRunId
|
|
5046
|
-
);
|
|
5047
|
-
summary.filed = true;
|
|
5048
|
-
}
|
|
5049
|
-
fs.writeFileSync(
|
|
5050
|
-
path.join(runDir, "run.json"),
|
|
5051
|
-
JSON.stringify(summary, null, 2)
|
|
5052
|
-
);
|
|
5053
|
-
return summary;
|
|
5054
|
-
} finally {
|
|
5055
|
-
if (!opts.keepUp) {
|
|
5056
|
-
try {
|
|
5057
|
-
await live.close({ keepWarm: false });
|
|
5058
|
-
} catch {
|
|
5059
|
-
}
|
|
5060
|
-
}
|
|
5061
|
-
}
|
|
5555
|
+
const opening = new TaskOpening(
|
|
5556
|
+
openTask(ref, {
|
|
5557
|
+
surfaces: opts.surfaces,
|
|
5558
|
+
reuseWarm: opts.reuseWarm,
|
|
5559
|
+
browserTier: opts.browserTier,
|
|
5560
|
+
options
|
|
5561
|
+
}).then(async (live) => {
|
|
5562
|
+
await refuseUnreadTools(live);
|
|
5563
|
+
return new LiveTaskRun(runId, live, opts, options);
|
|
5564
|
+
})
|
|
5565
|
+
);
|
|
5566
|
+
return new RunSignals().during(
|
|
5567
|
+
(signal, urgent) => opening.interrupt(signal, urgent),
|
|
5568
|
+
() => opening.complete(agent)
|
|
5569
|
+
);
|
|
5062
5570
|
}
|
|
5063
|
-
var import_node_crypto4,
|
|
5571
|
+
var import_node_crypto4, path2, TaskRun, FILING_UNFINISHED, describeValue, RESULT_CONTRACT, LiveTaskRun, TaskOpening;
|
|
5064
5572
|
var init_taskRun = __esm({
|
|
5065
5573
|
"src/worlds/taskRun.ts"() {
|
|
5066
5574
|
"use strict";
|
|
5067
5575
|
import_node_crypto4 = require("crypto");
|
|
5068
|
-
|
|
5069
|
-
path = __toESM(require("path"));
|
|
5576
|
+
path2 = __toESM(require("path"));
|
|
5070
5577
|
init_browser();
|
|
5071
5578
|
init_evals();
|
|
5579
|
+
init_runSignals();
|
|
5072
5580
|
init_session2();
|
|
5073
5581
|
init_taskSessions();
|
|
5582
|
+
init_taskRunDir();
|
|
5583
|
+
init_taskRunOutcome();
|
|
5074
5584
|
init_taskTracing();
|
|
5585
|
+
init_worldNotice();
|
|
5075
5586
|
TaskRun = class {
|
|
5076
5587
|
constructor(runId, instruction, model, sessions, manifest) {
|
|
5077
5588
|
this.runId = runId;
|
|
@@ -5134,8 +5645,127 @@ var init_taskRun = __esm({
|
|
|
5134
5645
|
Object.assign(this.notes, notes);
|
|
5135
5646
|
}
|
|
5136
5647
|
};
|
|
5648
|
+
FILING_UNFINISHED = "the filing did not finish";
|
|
5137
5649
|
describeValue = (value) => Array.isArray(value) ? "array" : value === null ? "null" : typeof value;
|
|
5138
5650
|
RESULT_CONTRACT = "return a string report, an object {report?: string, ...} or nothing";
|
|
5651
|
+
LiveTaskRun = class {
|
|
5652
|
+
constructor(runId, live, opts, options) {
|
|
5653
|
+
this.live = live;
|
|
5654
|
+
this.opts = opts;
|
|
5655
|
+
this.options = options;
|
|
5656
|
+
this.files = new TaskRunDir(path2.join(opts.outDir ?? "runs", runId));
|
|
5657
|
+
this.outcome = new TaskRunOutcome(runId, live, opts.model, this.files.path);
|
|
5658
|
+
}
|
|
5659
|
+
live;
|
|
5660
|
+
opts;
|
|
5661
|
+
options;
|
|
5662
|
+
files;
|
|
5663
|
+
outcome;
|
|
5664
|
+
played = false;
|
|
5665
|
+
interrupted = false;
|
|
5666
|
+
filing = null;
|
|
5667
|
+
ending = null;
|
|
5668
|
+
async complete(agent) {
|
|
5669
|
+
try {
|
|
5670
|
+
await this.play(agent).catch((error) => this.outcome.stopped(error));
|
|
5671
|
+
this.played = true;
|
|
5672
|
+
await this.file();
|
|
5673
|
+
return this.record();
|
|
5674
|
+
} finally {
|
|
5675
|
+
await this.end();
|
|
5676
|
+
}
|
|
5677
|
+
}
|
|
5678
|
+
async interrupt(signal, urgent = false) {
|
|
5679
|
+
const sessions = this.opts.keepUp ? "leaving its sessions up" : "closing its sessions";
|
|
5680
|
+
const how = urgent ? " now, without waiting" : "";
|
|
5681
|
+
process.stderr.write(`${this.outcome.runId} interrupted by ${signal}; ${sessions}${how}
|
|
5682
|
+
`);
|
|
5683
|
+
if (!this.played) this.outcome.stopped(`interrupted by ${signal}`);
|
|
5684
|
+
this.interrupted = true;
|
|
5685
|
+
try {
|
|
5686
|
+
if (!urgent) await this.filing;
|
|
5687
|
+
this.record();
|
|
5688
|
+
} catch (error) {
|
|
5689
|
+
const why = error instanceof Error ? error.message : String(error);
|
|
5690
|
+
process.stderr.write(`${this.outcome.runId}: run.json not written: ${why}
|
|
5691
|
+
`);
|
|
5692
|
+
} finally {
|
|
5693
|
+
await this.end();
|
|
5694
|
+
}
|
|
5695
|
+
}
|
|
5696
|
+
summary() {
|
|
5697
|
+
return this.outcome.summary();
|
|
5698
|
+
}
|
|
5699
|
+
async play(agent) {
|
|
5700
|
+
await this.live.ready();
|
|
5701
|
+
this.outcome.traced = await new TaskTracing().start(this.opts.trace !== false, this.options);
|
|
5702
|
+
const run = new TaskRun(
|
|
5703
|
+
this.outcome.runId,
|
|
5704
|
+
this.live.instruction ?? "",
|
|
5705
|
+
this.opts.model,
|
|
5706
|
+
this.live.sessions,
|
|
5707
|
+
await this.live.manifest()
|
|
5708
|
+
);
|
|
5709
|
+
this.outcome.notes = run.notes;
|
|
5710
|
+
this.files.writeManifest(run.manifest);
|
|
5711
|
+
await this.callAgent(agent, run);
|
|
5712
|
+
const report = this.outcome.report;
|
|
5713
|
+
this.outcome.grade = await this.live.grade(report !== null ? { report } : {});
|
|
5714
|
+
this.files.writeJson("grades.json", this.outcome.grade);
|
|
5715
|
+
if (report) this.files.write("report.md", report);
|
|
5716
|
+
}
|
|
5717
|
+
async callAgent(agent, run) {
|
|
5718
|
+
try {
|
|
5719
|
+
const invoke = () => agent(run);
|
|
5720
|
+
const result = this.outcome.traced ? await (await Promise.resolve().then(() => (init_session(), session_exports))).withSession(run.runId, invoke) : await invoke();
|
|
5721
|
+
({ report: this.outcome.report, extra: this.outcome.extra } = reportFromResult(result));
|
|
5722
|
+
} catch (error) {
|
|
5723
|
+
this.outcome.agentRaised(error);
|
|
5724
|
+
}
|
|
5725
|
+
if (this.outcome.traced)
|
|
5726
|
+
await Promise.resolve().then(() => (init_init(), init_exports)).then((tracing) => tracing.flush()).catch(() => void 0);
|
|
5727
|
+
}
|
|
5728
|
+
async file() {
|
|
5729
|
+
if (this.opts.file === false || this.interrupted) return;
|
|
5730
|
+
this.files.writeJson("run.json", { ...this.outcome.summary(), fileError: FILING_UNFINISHED });
|
|
5731
|
+
this.filing = this.outcome.file(new GatewayEvalsClient(this.options), this.opts.setRunId);
|
|
5732
|
+
await this.filing;
|
|
5733
|
+
}
|
|
5734
|
+
record() {
|
|
5735
|
+
const summary = this.outcome.summary();
|
|
5736
|
+
this.files.writeJson("run.json", summary);
|
|
5737
|
+
return summary;
|
|
5738
|
+
}
|
|
5739
|
+
end() {
|
|
5740
|
+
this.ending ??= this.opts.keepUp ? Promise.resolve() : this.live.close({ keepWarm: false }).then(
|
|
5741
|
+
() => void 0,
|
|
5742
|
+
() => void 0
|
|
5743
|
+
);
|
|
5744
|
+
return this.ending;
|
|
5745
|
+
}
|
|
5746
|
+
};
|
|
5747
|
+
TaskOpening = class {
|
|
5748
|
+
interrupting = null;
|
|
5749
|
+
run = null;
|
|
5750
|
+
opened;
|
|
5751
|
+
constructor(opening) {
|
|
5752
|
+
this.opened = opening.then((run) => this.run = run);
|
|
5753
|
+
}
|
|
5754
|
+
async complete(agent) {
|
|
5755
|
+
const run = await this.opened;
|
|
5756
|
+
if (!this.interrupting) return run.complete(agent);
|
|
5757
|
+
await this.interrupting;
|
|
5758
|
+
return run.summary();
|
|
5759
|
+
}
|
|
5760
|
+
interrupt(signal, urgent = false) {
|
|
5761
|
+
if (urgent) return this.run?.interrupt(signal, true) ?? Promise.resolve();
|
|
5762
|
+
this.interrupting ??= this.opened.then(
|
|
5763
|
+
(run) => run.interrupt(signal),
|
|
5764
|
+
() => void 0
|
|
5765
|
+
);
|
|
5766
|
+
return this.interrupting;
|
|
5767
|
+
}
|
|
5768
|
+
};
|
|
5139
5769
|
}
|
|
5140
5770
|
});
|
|
5141
5771
|
|
|
@@ -5215,63 +5845,101 @@ async function runSet(datasetId, agent, opts) {
|
|
|
5215
5845
|
source: opts.source ?? "sdk",
|
|
5216
5846
|
...git && Object.keys(git).length ? { git } : {}
|
|
5217
5847
|
});
|
|
5218
|
-
|
|
5219
|
-
options,
|
|
5220
|
-
"POST",
|
|
5221
|
-
`${SET_RUNS}/${encodeURIComponent(opened.id)}/close`,
|
|
5222
|
-
{ status }
|
|
5223
|
-
);
|
|
5224
|
-
const onInterrupt = () => {
|
|
5225
|
-
void close("failed").finally(() => process.exit(130));
|
|
5226
|
-
};
|
|
5227
|
-
process.once("SIGINT", onInterrupt);
|
|
5228
|
-
const planned = await runPlannedTasks(opened, agent, opts, options).finally(
|
|
5229
|
-
() => process.off("SIGINT", onInterrupt)
|
|
5230
|
-
);
|
|
5231
|
-
const { tasks, failed } = planned;
|
|
5232
|
-
const requested = failed ? "failed" : "completed";
|
|
5233
|
-
const setRun = await close(requested);
|
|
5234
|
-
return {
|
|
5235
|
-
setRun,
|
|
5236
|
-
tasks,
|
|
5237
|
-
failed: failed || setRun.status !== "completed",
|
|
5238
|
-
closedAsRequested: setRun.status === requested
|
|
5239
|
-
};
|
|
5240
|
-
}
|
|
5241
|
-
async function runPlannedTasks(opened, agent, opts, options) {
|
|
5242
|
-
const tasks = [];
|
|
5243
|
-
let failed = false;
|
|
5244
|
-
for (const task of opened.tasks) {
|
|
5245
|
-
try {
|
|
5246
|
-
const summary = await runTask(task.worldTaskId, agent, {
|
|
5247
|
-
model: opts.model,
|
|
5248
|
-
surfaces: opts.surfaces,
|
|
5249
|
-
browserTier: opts.browserTier,
|
|
5250
|
-
outDir: opts.outDir,
|
|
5251
|
-
trace: opts.trace,
|
|
5252
|
-
setRunId: opened.id,
|
|
5253
|
-
options
|
|
5254
|
-
});
|
|
5255
|
-
tasks.push(summary);
|
|
5256
|
-
failed ||= summary.agentError !== null;
|
|
5257
|
-
opts.onTask?.(summary);
|
|
5258
|
-
} catch (error) {
|
|
5259
|
-
failed = true;
|
|
5260
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
5261
|
-
process.stderr.write(`task ${task.name} could not run: ${message}
|
|
5262
|
-
`);
|
|
5263
|
-
}
|
|
5264
|
-
}
|
|
5265
|
-
return { tasks, failed };
|
|
5848
|
+
return new SetRunner(opened, agent, opts, options).run();
|
|
5266
5849
|
}
|
|
5267
|
-
var SET_RUNS;
|
|
5850
|
+
var SET_RUNS, SetRunner;
|
|
5268
5851
|
var init_setRun = __esm({
|
|
5269
5852
|
"src/worlds/setRun.ts"() {
|
|
5270
5853
|
"use strict";
|
|
5271
5854
|
init_worlds();
|
|
5272
5855
|
init_checkoutProvenance();
|
|
5856
|
+
init_runSignals();
|
|
5273
5857
|
init_taskRun();
|
|
5274
5858
|
SET_RUNS = "/api/public/set-runs";
|
|
5859
|
+
SetRunner = class {
|
|
5860
|
+
constructor(opened, agent, opts, options) {
|
|
5861
|
+
this.opened = opened;
|
|
5862
|
+
this.agent = agent;
|
|
5863
|
+
this.opts = opts;
|
|
5864
|
+
this.options = options;
|
|
5865
|
+
}
|
|
5866
|
+
opened;
|
|
5867
|
+
agent;
|
|
5868
|
+
opts;
|
|
5869
|
+
options;
|
|
5870
|
+
tasks = [];
|
|
5871
|
+
failures = [];
|
|
5872
|
+
failed = false;
|
|
5873
|
+
current = null;
|
|
5874
|
+
interrupted = null;
|
|
5875
|
+
signals = new RunSignals();
|
|
5876
|
+
async run() {
|
|
5877
|
+
await this.signals.during(
|
|
5878
|
+
(signal2) => this.interrupt(signal2).then(() => void 0),
|
|
5879
|
+
() => this.runTasks()
|
|
5880
|
+
);
|
|
5881
|
+
const signal = this.signals.signal;
|
|
5882
|
+
if (signal !== null) return this.result(await this.interrupt(signal), "failed");
|
|
5883
|
+
const requested = this.failed ? "failed" : "completed";
|
|
5884
|
+
return this.result(await this.close(requested, this.failures), requested);
|
|
5885
|
+
}
|
|
5886
|
+
interrupt(signal) {
|
|
5887
|
+
const stopped = this.current ? [{ worldTaskId: this.current, reason: `interrupted by ${signal}` }] : [];
|
|
5888
|
+
this.interrupted ??= this.close("failed", [...this.failures, ...stopped]);
|
|
5889
|
+
return this.interrupted;
|
|
5890
|
+
}
|
|
5891
|
+
async runTasks() {
|
|
5892
|
+
for (const task of this.opened.tasks) {
|
|
5893
|
+
if (this.signals.signal !== null) return;
|
|
5894
|
+
this.current = task.worldTaskId;
|
|
5895
|
+
await this.runOne(task);
|
|
5896
|
+
}
|
|
5897
|
+
this.current = null;
|
|
5898
|
+
}
|
|
5899
|
+
async runOne(task) {
|
|
5900
|
+
try {
|
|
5901
|
+
const summary = await runTask(task.worldTaskId, this.agent, {
|
|
5902
|
+
model: this.opts.model,
|
|
5903
|
+
surfaces: this.opts.surfaces,
|
|
5904
|
+
browserTier: this.opts.browserTier,
|
|
5905
|
+
outDir: this.opts.outDir,
|
|
5906
|
+
trace: this.opts.trace,
|
|
5907
|
+
setRunId: this.opened.id,
|
|
5908
|
+
options: this.options
|
|
5909
|
+
});
|
|
5910
|
+
this.tasks.push(summary);
|
|
5911
|
+
this.failed ||= taskRunFailure(summary) !== null;
|
|
5912
|
+
if (summary.fileError !== null)
|
|
5913
|
+
this.failures.push({ worldTaskId: task.worldTaskId, reason: summary.fileError });
|
|
5914
|
+
this.opts.onTask?.(summary);
|
|
5915
|
+
} catch (error) {
|
|
5916
|
+
this.failed = true;
|
|
5917
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
5918
|
+
process.stderr.write(`task ${task.name} could not run: ${message}
|
|
5919
|
+
`);
|
|
5920
|
+
this.failures.push({
|
|
5921
|
+
worldTaskId: task.worldTaskId,
|
|
5922
|
+
reason: message || (error instanceof Error ? error.name : "Error")
|
|
5923
|
+
});
|
|
5924
|
+
}
|
|
5925
|
+
}
|
|
5926
|
+
close(status, failures = []) {
|
|
5927
|
+
return apiRequest(
|
|
5928
|
+
this.options,
|
|
5929
|
+
"POST",
|
|
5930
|
+
`${SET_RUNS}/${encodeURIComponent(this.opened.id)}/close`,
|
|
5931
|
+
{ status, ...failures.length ? { failures } : {} }
|
|
5932
|
+
);
|
|
5933
|
+
}
|
|
5934
|
+
result(setRun, requested) {
|
|
5935
|
+
return {
|
|
5936
|
+
setRun,
|
|
5937
|
+
tasks: this.tasks,
|
|
5938
|
+
failed: this.failed || setRun.status !== "completed",
|
|
5939
|
+
closedAsRequested: setRun.status === requested
|
|
5940
|
+
};
|
|
5941
|
+
}
|
|
5942
|
+
};
|
|
5275
5943
|
}
|
|
5276
5944
|
});
|
|
5277
5945
|
|
|
@@ -5322,12 +5990,12 @@ var init_requestLog = __esm({
|
|
|
5322
5990
|
});
|
|
5323
5991
|
|
|
5324
5992
|
// src/worlds/checkoutTarget.ts
|
|
5325
|
-
var fs2,
|
|
5993
|
+
var fs2, path3, CheckoutRefusedError, NAMED_EDITS, CheckoutTarget;
|
|
5326
5994
|
var init_checkoutTarget = __esm({
|
|
5327
5995
|
"src/worlds/checkoutTarget.ts"() {
|
|
5328
5996
|
"use strict";
|
|
5329
5997
|
fs2 = __toESM(require("fs"));
|
|
5330
|
-
|
|
5998
|
+
path3 = __toESM(require("path"));
|
|
5331
5999
|
CheckoutRefusedError = class extends Error {
|
|
5332
6000
|
constructor(message) {
|
|
5333
6001
|
super(`checkout refused: ${message}`);
|
|
@@ -5352,17 +6020,17 @@ var init_checkoutTarget = __esm({
|
|
|
5352
6020
|
}
|
|
5353
6021
|
/** The absolute destination; a relative target may not resolve above `cwd`. */
|
|
5354
6022
|
static confined(target, cwd) {
|
|
5355
|
-
const dir =
|
|
5356
|
-
if (
|
|
5357
|
-
const rel =
|
|
5358
|
-
if (rel === "" || !rel.startsWith("..") && !
|
|
6023
|
+
const dir = path3.resolve(cwd, target);
|
|
6024
|
+
if (path3.isAbsolute(target)) return dir;
|
|
6025
|
+
const rel = path3.relative(cwd, dir);
|
|
6026
|
+
if (rel === "" || !rel.startsWith("..") && !path3.isAbsolute(rel))
|
|
5359
6027
|
return dir;
|
|
5360
6028
|
throw new CheckoutRefusedError(
|
|
5361
6029
|
`--target ${target} resolves outside the current directory (${cwd}) \u2014 run from that directory, or pass an absolute path`
|
|
5362
6030
|
);
|
|
5363
6031
|
}
|
|
5364
6032
|
static fresh(slug, cwd) {
|
|
5365
|
-
const base =
|
|
6033
|
+
const base = path3.join(cwd, slug);
|
|
5366
6034
|
let dir = base;
|
|
5367
6035
|
let i = 1;
|
|
5368
6036
|
while (fs2.existsSync(dir)) dir = `${base}-${i++}`;
|
|
@@ -5389,7 +6057,7 @@ var init_checkoutTarget = __esm({
|
|
|
5389
6057
|
].filter(_CheckoutTarget.confinedRel).sort();
|
|
5390
6058
|
}
|
|
5391
6059
|
static confinedRel(rel) {
|
|
5392
|
-
if (rel === "" ||
|
|
6060
|
+
if (rel === "" || path3.isAbsolute(rel)) return false;
|
|
5393
6061
|
return !rel.split(/[\\/]/).includes("..");
|
|
5394
6062
|
}
|
|
5395
6063
|
/** Why `dir` cannot be overwritten, or null when it is a clean checkout of `slug`. */
|
|
@@ -5407,9 +6075,9 @@ var init_checkoutTarget = __esm({
|
|
|
5407
6075
|
/** Remove the replaced checkout's files (and the dirs they leave empty). */
|
|
5408
6076
|
clear() {
|
|
5409
6077
|
for (const rel of this.replaces) {
|
|
5410
|
-
const abs =
|
|
6078
|
+
const abs = path3.join(this.dir, rel);
|
|
5411
6079
|
fs2.rmSync(abs, { force: true });
|
|
5412
|
-
this.pruneEmptyParents(
|
|
6080
|
+
this.pruneEmptyParents(path3.dirname(abs));
|
|
5413
6081
|
}
|
|
5414
6082
|
}
|
|
5415
6083
|
pruneEmptyParents(from) {
|
|
@@ -5417,7 +6085,7 @@ var init_checkoutTarget = __esm({
|
|
|
5417
6085
|
while (cur !== this.dir && cur.startsWith(this.dir)) {
|
|
5418
6086
|
if (fs2.existsSync(cur) && fs2.readdirSync(cur).length > 0) return;
|
|
5419
6087
|
fs2.rmSync(cur, { recursive: true, force: true });
|
|
5420
|
-
cur =
|
|
6088
|
+
cur = path3.dirname(cur);
|
|
5421
6089
|
}
|
|
5422
6090
|
}
|
|
5423
6091
|
};
|
|
@@ -5425,13 +6093,13 @@ var init_checkoutTarget = __esm({
|
|
|
5425
6093
|
});
|
|
5426
6094
|
|
|
5427
6095
|
// src/worlds/worldDir.ts
|
|
5428
|
-
var import_node_crypto5, fs3,
|
|
6096
|
+
var import_node_crypto5, fs3, path4, 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;
|
|
5429
6097
|
var init_worldDir = __esm({
|
|
5430
6098
|
"src/worlds/worldDir.ts"() {
|
|
5431
6099
|
"use strict";
|
|
5432
6100
|
import_node_crypto5 = require("crypto");
|
|
5433
6101
|
fs3 = __toESM(require("fs"));
|
|
5434
|
-
|
|
6102
|
+
path4 = __toESM(require("path"));
|
|
5435
6103
|
WORLD_MANIFEST = "gateway-env.toml";
|
|
5436
6104
|
API_BUNDLE_MANIFEST = "gateway-api-world.toml";
|
|
5437
6105
|
BUNDLED_WORLD_PREFIX = "server/world/";
|
|
@@ -5457,17 +6125,17 @@ var init_worldDir = __esm({
|
|
|
5457
6125
|
worldRoot;
|
|
5458
6126
|
pathsMemo;
|
|
5459
6127
|
static open(dir) {
|
|
5460
|
-
const present = (rel) => fs3.existsSync(
|
|
6128
|
+
const present = (rel) => fs3.existsSync(path4.join(dir, rel));
|
|
5461
6129
|
const bundled = present(API_BUNDLE_MANIFEST) && WORLD_ROOT_MARKERS.some((m) => present(BUNDLED_WORLD_PREFIX + m));
|
|
5462
6130
|
return new _WorldDir(dir, bundled ? BUNDLED_WORLD_PREFIX : "");
|
|
5463
6131
|
}
|
|
5464
6132
|
// ── Files ──────────────────────────────────────────────────────────────
|
|
5465
6133
|
has(rel) {
|
|
5466
|
-
return fs3.existsSync(
|
|
6134
|
+
return fs3.existsSync(path4.join(this.dir, rel));
|
|
5467
6135
|
}
|
|
5468
6136
|
text(rel) {
|
|
5469
6137
|
try {
|
|
5470
|
-
return fs3.readFileSync(
|
|
6138
|
+
return fs3.readFileSync(path4.join(this.dir, rel), "utf-8");
|
|
5471
6139
|
} catch {
|
|
5472
6140
|
return null;
|
|
5473
6141
|
}
|
|
@@ -5486,7 +6154,7 @@ var init_worldDir = __esm({
|
|
|
5486
6154
|
const broad = BROAD_ROOT_MARKERS.some((m) => this.has(m));
|
|
5487
6155
|
const out = [];
|
|
5488
6156
|
const walk = (rel) => {
|
|
5489
|
-
for (const entry of fs3.readdirSync(rel ?
|
|
6157
|
+
for (const entry of fs3.readdirSync(rel ? path4.join(this.dir, rel) : this.dir, { withFileTypes: true })) {
|
|
5490
6158
|
const child = rel ? `${rel}/${entry.name}` : entry.name;
|
|
5491
6159
|
if (entry.isDirectory()) {
|
|
5492
6160
|
if (!skippedDir(entry.name)) walk(child);
|
|
@@ -5507,7 +6175,7 @@ var init_worldDir = __esm({
|
|
|
5507
6175
|
get exclusions() {
|
|
5508
6176
|
const kept = new Set(this.archivePaths);
|
|
5509
6177
|
const out = [];
|
|
5510
|
-
const filesUnder = (rel) => fs3.readdirSync(
|
|
6178
|
+
const filesUnder = (rel) => fs3.readdirSync(path4.join(this.dir, rel), { withFileTypes: true }).flatMap((entry) => {
|
|
5511
6179
|
const child = `${rel}/${entry.name}`;
|
|
5512
6180
|
if (entry.isDirectory()) return filesUnder(child);
|
|
5513
6181
|
return entry.isFile() ? [child] : [];
|
|
@@ -5538,7 +6206,7 @@ var init_worldDir = __esm({
|
|
|
5538
6206
|
const hasher = (0, import_node_crypto5.createHash)("sha256");
|
|
5539
6207
|
for (const rel of this.archivePaths) {
|
|
5540
6208
|
hasher.update(Buffer.from(`file:${rel}`, "utf-8"));
|
|
5541
|
-
hasher.update(fs3.readFileSync(
|
|
6209
|
+
hasher.update(fs3.readFileSync(path4.join(this.dir, rel)));
|
|
5542
6210
|
}
|
|
5543
6211
|
return hasher.digest("hex");
|
|
5544
6212
|
}
|
|
@@ -5628,12 +6296,12 @@ function paxPath(body) {
|
|
|
5628
6296
|
}
|
|
5629
6297
|
return found;
|
|
5630
6298
|
}
|
|
5631
|
-
var fs4,
|
|
6299
|
+
var fs4, path5, import_node_zlib, TAR_FILE_MODE, TAR_EXEC_MODE, TarArchive;
|
|
5632
6300
|
var init_tar = __esm({
|
|
5633
6301
|
"src/worlds/tar.ts"() {
|
|
5634
6302
|
"use strict";
|
|
5635
6303
|
fs4 = __toESM(require("fs"));
|
|
5636
|
-
|
|
6304
|
+
path5 = __toESM(require("path"));
|
|
5637
6305
|
import_node_zlib = require("zlib");
|
|
5638
6306
|
TAR_FILE_MODE = 420;
|
|
5639
6307
|
TAR_EXEC_MODE = 493;
|
|
@@ -5689,8 +6357,8 @@ var init_tar = __esm({
|
|
|
5689
6357
|
for (const member of this.members()) {
|
|
5690
6358
|
if (member.typeflag !== "0" && member.typeflag !== "\0") continue;
|
|
5691
6359
|
if (!_TarArchive.isConfined(member.name)) continue;
|
|
5692
|
-
const target =
|
|
5693
|
-
fs4.mkdirSync(
|
|
6360
|
+
const target = path5.join(dir, member.name);
|
|
6361
|
+
fs4.mkdirSync(path5.dirname(target), { recursive: true });
|
|
5694
6362
|
const mode = archiveMode(member.mode);
|
|
5695
6363
|
fs4.writeFileSync(target, member.bytes, { mode });
|
|
5696
6364
|
fs4.chmodSync(target, mode);
|
|
@@ -5793,7 +6461,7 @@ function tarMember(name, payload, mode) {
|
|
|
5793
6461
|
function buildSourceTarball(dir) {
|
|
5794
6462
|
const parts = [];
|
|
5795
6463
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
5796
|
-
const abs =
|
|
6464
|
+
const abs = path6.join(dir, relPath);
|
|
5797
6465
|
parts.push(
|
|
5798
6466
|
...tarMember(
|
|
5799
6467
|
relPath,
|
|
@@ -5807,7 +6475,7 @@ function buildSourceTarball(dir) {
|
|
|
5807
6475
|
}
|
|
5808
6476
|
function readLocalMeta(dir) {
|
|
5809
6477
|
try {
|
|
5810
|
-
const raw = fs5.readFileSync(
|
|
6478
|
+
const raw = fs5.readFileSync(path6.join(dir, META_RELPATH), "utf-8");
|
|
5811
6479
|
const parsed = JSON.parse(raw);
|
|
5812
6480
|
return parsed && typeof parsed === "object" ? parsed : null;
|
|
5813
6481
|
} catch {
|
|
@@ -5830,16 +6498,16 @@ function resolvePushSlug(dir, opts = {}) {
|
|
|
5830
6498
|
}
|
|
5831
6499
|
const first = declared[0];
|
|
5832
6500
|
if (first) return { ...base, slug: first.slug, source: first.source };
|
|
5833
|
-
return { ...base, slug:
|
|
6501
|
+
return { ...base, slug: path6.basename(path6.resolve(dir)), source: "directory name" };
|
|
5834
6502
|
}
|
|
5835
6503
|
function writeLocalMeta(dir, meta) {
|
|
5836
|
-
fs5.mkdirSync(
|
|
5837
|
-
fs5.writeFileSync(
|
|
6504
|
+
fs5.mkdirSync(path6.join(dir, ".gateway"), { recursive: true });
|
|
6505
|
+
fs5.writeFileSync(path6.join(dir, META_RELPATH), JSON.stringify(meta, null, 2));
|
|
5838
6506
|
}
|
|
5839
6507
|
function snapshotTreeHashes(dir) {
|
|
5840
6508
|
const out = {};
|
|
5841
6509
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
5842
|
-
out[relPath] = (0, import_node_crypto6.createHash)("sha256").update(fs5.readFileSync(
|
|
6510
|
+
out[relPath] = (0, import_node_crypto6.createHash)("sha256").update(fs5.readFileSync(path6.join(dir, relPath))).digest("hex");
|
|
5843
6511
|
}
|
|
5844
6512
|
return out;
|
|
5845
6513
|
}
|
|
@@ -5857,7 +6525,7 @@ function localTreeState(dir) {
|
|
|
5857
6525
|
}
|
|
5858
6526
|
function readPyproject(dir) {
|
|
5859
6527
|
try {
|
|
5860
|
-
const text2 = fs5.readFileSync(
|
|
6528
|
+
const text2 = fs5.readFileSync(path6.join(dir, "pyproject.toml"), "utf-8");
|
|
5861
6529
|
const section = /\[project\]([\s\S]*?)(\n\[|$)/.exec(text2)?.[1] ?? "";
|
|
5862
6530
|
const name = /\bname\s*=\s*"([^"]+)"/.exec(section)?.[1];
|
|
5863
6531
|
const version = /\bversion\s*=\s*"([^"]+)"/.exec(section)?.[1];
|
|
@@ -5880,7 +6548,7 @@ function readWorldContractVersion(dir) {
|
|
|
5880
6548
|
}
|
|
5881
6549
|
function buildFileManifest(dir) {
|
|
5882
6550
|
return collectArchiveRelPaths(dir).map((relPath) => {
|
|
5883
|
-
const payload = fs5.readFileSync(
|
|
6551
|
+
const payload = fs5.readFileSync(path6.join(dir, relPath));
|
|
5884
6552
|
return {
|
|
5885
6553
|
path: relPath,
|
|
5886
6554
|
isDirectory: false,
|
|
@@ -5926,7 +6594,7 @@ async function push(dir, opts = {}) {
|
|
|
5926
6594
|
const pyproject = readPyproject(dir);
|
|
5927
6595
|
const contractVersion = pyproject.version ? void 0 : readWorldContractVersion(dir).version;
|
|
5928
6596
|
if (contractVersion) pyproject.version = contractVersion;
|
|
5929
|
-
const slug = opts.slug ?? localMeta.slug ?? pyproject.name ??
|
|
6597
|
+
const slug = opts.slug ?? localMeta.slug ?? pyproject.name ?? path6.basename(path6.resolve(dir));
|
|
5930
6598
|
const metadata = {
|
|
5931
6599
|
...opts.name !== void 0 ? { name: opts.name } : {},
|
|
5932
6600
|
...opts.description !== void 0 ? { description: opts.description } : {},
|
|
@@ -6052,7 +6720,7 @@ async function propose(dir, opts) {
|
|
|
6052
6720
|
if (state2.clean)
|
|
6053
6721
|
throw new Error("Nothing to propose \u2014 the tree matches its base.");
|
|
6054
6722
|
const changes = state2.dirty.map((relPath) => {
|
|
6055
|
-
const abs =
|
|
6723
|
+
const abs = path6.join(dir, relPath);
|
|
6056
6724
|
if (!fs5.existsSync(abs))
|
|
6057
6725
|
return { path: relPath, action: "delete" };
|
|
6058
6726
|
return {
|
|
@@ -6084,20 +6752,20 @@ async function createRef(slug, name, kind, versionId, options = {}) {
|
|
|
6084
6752
|
...versionId ? { versionId } : {}
|
|
6085
6753
|
});
|
|
6086
6754
|
}
|
|
6087
|
-
var import_node_crypto6, import_node_zlib2, fs5,
|
|
6755
|
+
var import_node_crypto6, import_node_zlib2, fs5, path6, DEFAULT_BRANCH, META_RELPATH, FILE_MODE, MINTED_SUFFIX, PushSlugConflict, sha256b64, DetachedPushError;
|
|
6088
6756
|
var init_hub = __esm({
|
|
6089
6757
|
"src/worlds/hub.ts"() {
|
|
6090
6758
|
"use strict";
|
|
6091
6759
|
import_node_crypto6 = require("crypto");
|
|
6092
6760
|
import_node_zlib2 = require("zlib");
|
|
6093
6761
|
fs5 = __toESM(require("fs"));
|
|
6094
|
-
|
|
6762
|
+
path6 = __toESM(require("path"));
|
|
6095
6763
|
init_worlds();
|
|
6096
6764
|
init_checkoutTarget();
|
|
6097
6765
|
init_worldDir();
|
|
6098
6766
|
init_tar();
|
|
6099
6767
|
DEFAULT_BRANCH = "main";
|
|
6100
|
-
META_RELPATH =
|
|
6768
|
+
META_RELPATH = path6.join(".gateway", ".env-metadata.json");
|
|
6101
6769
|
FILE_MODE = TAR_FILE_MODE;
|
|
6102
6770
|
MINTED_SUFFIX = /^-\d+$/;
|
|
6103
6771
|
PushSlugConflict = class extends Error {
|
|
@@ -6325,7 +6993,7 @@ function rebaseConflicts(error) {
|
|
|
6325
6993
|
}
|
|
6326
6994
|
const conflicts = body?.conflicts;
|
|
6327
6995
|
if (!Array.isArray(conflicts)) return null;
|
|
6328
|
-
return conflicts.filter(isConflictPath).map(({ path:
|
|
6996
|
+
return conflicts.filter(isConflictPath).map(({ path: path13, reason }) => ({ path: path13, reason }));
|
|
6329
6997
|
}
|
|
6330
6998
|
function isConflictPath(value) {
|
|
6331
6999
|
const entry = value;
|
|
@@ -6365,8 +7033,8 @@ var init_sandbox = __esm({
|
|
|
6365
7033
|
this.options = options;
|
|
6366
7034
|
}
|
|
6367
7035
|
options;
|
|
6368
|
-
request(method,
|
|
6369
|
-
return apiRequest(this.options, method,
|
|
7036
|
+
request(method, path13, body) {
|
|
7037
|
+
return apiRequest(this.options, method, path13, body, {
|
|
6370
7038
|
timeoutMs: SANDBOX_REQUEST_TIMEOUT_MS
|
|
6371
7039
|
});
|
|
6372
7040
|
}
|
|
@@ -6897,6 +7565,17 @@ async function queryRows(slugRef, entity, opts = {}, options = {}) {
|
|
|
6897
7565
|
`/api/public/worlds/${encodeURIComponent(slug)}/data${queryRowsSearch(entity, opts, ref)}`
|
|
6898
7566
|
);
|
|
6899
7567
|
}
|
|
7568
|
+
async function sqlRows(slugRef, sql, opts = {}, options = {}) {
|
|
7569
|
+
const [slug, ref] = slugRef.split("@", 2);
|
|
7570
|
+
if (!slug || ref === "") throw new Error(`sqlRows needs a slug, optionally slug@ref (got ${slugRef})`);
|
|
7571
|
+
if (!sql.trim()) throw new Error("sqlRows needs one SQL statement");
|
|
7572
|
+
return apiRequest(options, "POST", `/api/public/worlds/${encodeURIComponent(slug)}/data/sql`, {
|
|
7573
|
+
sql,
|
|
7574
|
+
...ref ? { ref } : {},
|
|
7575
|
+
...opts.limit !== void 0 ? { limit: opts.limit } : {},
|
|
7576
|
+
...opts.scenario ? { scenario: opts.scenario } : {}
|
|
7577
|
+
});
|
|
7578
|
+
}
|
|
6900
7579
|
var init_query = __esm({
|
|
6901
7580
|
"src/worlds/query.ts"() {
|
|
6902
7581
|
"use strict";
|
|
@@ -6956,13 +7635,13 @@ async function api(creds, method, route, body, init2 = {}) {
|
|
|
6956
7635
|
if (!reply.ok) throw new ApiError2(reply.status, method, route, reply.text);
|
|
6957
7636
|
return reply.text ? JSON.parse(reply.text) : {};
|
|
6958
7637
|
}
|
|
6959
|
-
var fs6, os,
|
|
7638
|
+
var fs6, os, path7, ApiError2;
|
|
6960
7639
|
var init_config = __esm({
|
|
6961
7640
|
"src/cli/config.ts"() {
|
|
6962
7641
|
"use strict";
|
|
6963
7642
|
fs6 = __toESM(require("fs"));
|
|
6964
7643
|
os = __toESM(require("os"));
|
|
6965
|
-
|
|
7644
|
+
path7 = __toESM(require("path"));
|
|
6966
7645
|
init_router();
|
|
6967
7646
|
init_worlds();
|
|
6968
7647
|
init_transport();
|
|
@@ -7000,16 +7679,16 @@ function runtimeRoot() {
|
|
|
7000
7679
|
const candidates = [];
|
|
7001
7680
|
if (process.env.GATEWAY_RUNTIME_PATH)
|
|
7002
7681
|
candidates.push(process.env.GATEWAY_RUNTIME_PATH);
|
|
7003
|
-
const entry = process.argv[1] && fs7.existsSync(process.argv[1]) ?
|
|
7682
|
+
const entry = process.argv[1] && fs7.existsSync(process.argv[1]) ? path8.dirname(fs7.realpathSync(process.argv[1])) : null;
|
|
7004
7683
|
if (entry) {
|
|
7005
|
-
candidates.push(
|
|
7006
|
-
candidates.push(
|
|
7007
|
-
candidates.push(
|
|
7684
|
+
candidates.push(path8.resolve(entry, "..", "runtime"));
|
|
7685
|
+
candidates.push(path8.resolve(entry, "..", "..", "runtime"));
|
|
7686
|
+
candidates.push(path8.resolve(entry, "..", "..", "sdk", "src"));
|
|
7008
7687
|
}
|
|
7009
|
-
candidates.push(
|
|
7688
|
+
candidates.push(path8.resolve(process.cwd(), "runtime"));
|
|
7010
7689
|
for (const root of candidates)
|
|
7011
7690
|
if (fs7.existsSync(
|
|
7012
|
-
|
|
7691
|
+
path8.join(root, "gatewaysdk", "environment", "schema", "platform.py")
|
|
7013
7692
|
))
|
|
7014
7693
|
return root;
|
|
7015
7694
|
return null;
|
|
@@ -7098,13 +7777,12 @@ async function localBridge(request, local, opts = {}) {
|
|
|
7098
7777
|
["-I", "-B", "-c", BRIDGE_BOOTSTRAP, local.root],
|
|
7099
7778
|
{
|
|
7100
7779
|
stdio: ["pipe", "pipe", "pipe"],
|
|
7101
|
-
//
|
|
7102
|
-
// place the runtime may import and run a world's own Python (check's
|
|
7103
|
-
// handler execution, `worlds call`, `worlds test` tool cases).
|
|
7780
|
+
// The author's machine running the author's world: the one place the runtime may run its Python.
|
|
7104
7781
|
env: {
|
|
7105
7782
|
PATH: process.env.PATH ?? "",
|
|
7106
7783
|
HOME: process.env.HOME ?? "",
|
|
7107
7784
|
TMPDIR: process.env.TMPDIR ?? "",
|
|
7785
|
+
...process.env.VIRTUAL_ENV ? { VIRTUAL_ENV: process.env.VIRTUAL_ENV } : {},
|
|
7108
7786
|
GATEWAY_RUNTIME_EXECUTE: "1"
|
|
7109
7787
|
}
|
|
7110
7788
|
}
|
|
@@ -7150,14 +7828,14 @@ async function localBridge(request, local, opts = {}) {
|
|
|
7150
7828
|
child.stdin.end(input);
|
|
7151
7829
|
});
|
|
7152
7830
|
}
|
|
7153
|
-
var import_node_child_process2, fs7, net,
|
|
7831
|
+
var import_node_child_process2, fs7, net, path8, MIN_PYTHON, MIN_PYTHON_LABEL, DIAGNOSTIC_TAIL, BRIDGE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
|
|
7154
7832
|
var init_local = __esm({
|
|
7155
7833
|
"src/cli/runtime/local.ts"() {
|
|
7156
7834
|
"use strict";
|
|
7157
7835
|
import_node_child_process2 = require("child_process");
|
|
7158
7836
|
fs7 = __toESM(require("fs"));
|
|
7159
7837
|
net = __toESM(require("net"));
|
|
7160
|
-
|
|
7838
|
+
path8 = __toESM(require("path"));
|
|
7161
7839
|
init_router();
|
|
7162
7840
|
init_config();
|
|
7163
7841
|
MIN_PYTHON = [3, 12];
|
|
@@ -7180,16 +7858,44 @@ runpy.run_module('gatewaysdk.environment.schema.platform',run_name='__main__')`;
|
|
|
7180
7858
|
}
|
|
7181
7859
|
});
|
|
7182
7860
|
|
|
7861
|
+
// src/worlds/databaseEngines.ts
|
|
7862
|
+
function isWorldSnapshotOutput(path13) {
|
|
7863
|
+
return SNAPSHOT_OUTPUTS.has(path13.slice(path13.lastIndexOf("/") + 1));
|
|
7864
|
+
}
|
|
7865
|
+
var WORLD_DATABASE_ENGINES, DEFAULT_WORLD_DATABASE_ENGINE, WORLD_SNAPSHOT_FILE_PATH, WORLD_SNAPSHOT_SIDECAR_PATH, WORLD_SNAPSHOT_CONTENT_TYPE, SNAPSHOT_OUTPUTS;
|
|
7866
|
+
var init_databaseEngines = __esm({
|
|
7867
|
+
"src/worlds/databaseEngines.ts"() {
|
|
7868
|
+
"use strict";
|
|
7869
|
+
WORLD_DATABASE_ENGINES = [
|
|
7870
|
+
{
|
|
7871
|
+
engine: "sqlite",
|
|
7872
|
+
label: "SQLite",
|
|
7873
|
+
target: "sqlite-json/1",
|
|
7874
|
+
snapshotName: "state.sqlite",
|
|
7875
|
+
contentType: "application/vnd.sqlite3"
|
|
7876
|
+
}
|
|
7877
|
+
];
|
|
7878
|
+
DEFAULT_WORLD_DATABASE_ENGINE = WORLD_DATABASE_ENGINES[0];
|
|
7879
|
+
WORLD_SNAPSHOT_FILE_PATH = `db/${DEFAULT_WORLD_DATABASE_ENGINE.snapshotName}`;
|
|
7880
|
+
WORLD_SNAPSHOT_SIDECAR_PATH = "db/state.json";
|
|
7881
|
+
WORLD_SNAPSHOT_CONTENT_TYPE = DEFAULT_WORLD_DATABASE_ENGINE.contentType;
|
|
7882
|
+
SNAPSHOT_OUTPUTS = /* @__PURE__ */ new Set([
|
|
7883
|
+
...WORLD_DATABASE_ENGINES.map((engine) => engine.snapshotName),
|
|
7884
|
+
WORLD_SNAPSHOT_SIDECAR_PATH.slice("db/".length)
|
|
7885
|
+
]);
|
|
7886
|
+
}
|
|
7887
|
+
});
|
|
7888
|
+
|
|
7183
7889
|
// src/cli/runtime/client.ts
|
|
7184
7890
|
function isBuildOutput(relPath) {
|
|
7185
|
-
return
|
|
7891
|
+
return isWorldSnapshotOutput(relPath);
|
|
7186
7892
|
}
|
|
7187
7893
|
function readWorldFiles(dir, opts = {}) {
|
|
7188
7894
|
if (!fs8.existsSync(dir) || !fs8.statSync(dir).isDirectory())
|
|
7189
7895
|
throw new CliError(`Not a directory: ${dir}`);
|
|
7190
7896
|
const out = [];
|
|
7191
7897
|
const walk = (rel) => {
|
|
7192
|
-
const abs = rel ?
|
|
7898
|
+
const abs = rel ? path9.join(dir, rel) : dir;
|
|
7193
7899
|
const entries = fs8.readdirSync(abs, { withFileTypes: true });
|
|
7194
7900
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
7195
7901
|
for (const entry of entries) {
|
|
@@ -7200,7 +7906,7 @@ function readWorldFiles(dir, opts = {}) {
|
|
|
7200
7906
|
if (!opts.buildOutputs && isBuildOutput(childRel)) continue;
|
|
7201
7907
|
out.push({
|
|
7202
7908
|
path: childRel,
|
|
7203
|
-
content: fs8.readFileSync(
|
|
7909
|
+
content: fs8.readFileSync(path9.join(dir, childRel)).toString("base64")
|
|
7204
7910
|
});
|
|
7205
7911
|
}
|
|
7206
7912
|
}
|
|
@@ -7220,15 +7926,15 @@ function writeWorldFiles(dir, files, opts = {}) {
|
|
|
7220
7926
|
if (opts.clean && fs8.existsSync(dir)) {
|
|
7221
7927
|
const keep = new Set(files.map((f) => f.path));
|
|
7222
7928
|
for (const existing of readWorldFiles(dir)) {
|
|
7223
|
-
if (!keep.has(existing.path)) fs8.rmSync(
|
|
7929
|
+
if (!keep.has(existing.path)) fs8.rmSync(path9.join(dir, existing.path));
|
|
7224
7930
|
}
|
|
7225
7931
|
pruneEmptyDirs(dir);
|
|
7226
7932
|
}
|
|
7227
7933
|
fs8.mkdirSync(dir, { recursive: true });
|
|
7228
7934
|
const written = [];
|
|
7229
7935
|
for (const file of files) {
|
|
7230
|
-
const target =
|
|
7231
|
-
fs8.mkdirSync(
|
|
7936
|
+
const target = path9.join(dir, file.path);
|
|
7937
|
+
fs8.mkdirSync(path9.dirname(target), { recursive: true });
|
|
7232
7938
|
fs8.writeFileSync(target, Buffer.from(file.content, "base64"));
|
|
7233
7939
|
written.push(file.path);
|
|
7234
7940
|
}
|
|
@@ -7238,7 +7944,7 @@ function pruneEmptyDirs(root) {
|
|
|
7238
7944
|
const walk = (abs) => {
|
|
7239
7945
|
let empty = true;
|
|
7240
7946
|
for (const entry of fs8.readdirSync(abs, { withFileTypes: true })) {
|
|
7241
|
-
const child =
|
|
7947
|
+
const child = path9.join(abs, entry.name);
|
|
7242
7948
|
if (entry.isDirectory()) {
|
|
7243
7949
|
if (SKIP_DIRS.has(entry.name)) {
|
|
7244
7950
|
empty = false;
|
|
@@ -7275,13 +7981,9 @@ function yamlDocument(request) {
|
|
|
7275
7981
|
return isYamlSource(String(request.source ?? ""), String(request.document ?? ""));
|
|
7276
7982
|
return request.command === "conform" && Array.isArray(request.openapi) && request.openapi.some((doc) => YAML_NAME.test(doc.path ?? ""));
|
|
7277
7983
|
}
|
|
7278
|
-
function runsLocally(request) {
|
|
7279
|
-
const local = localRuntime();
|
|
7280
|
-
return local !== null && !(yamlDocument(request) && !localPythonHasYaml(local.python));
|
|
7281
|
-
}
|
|
7282
7984
|
async function runtime(creds, request, opts = {}) {
|
|
7283
|
-
const local =
|
|
7284
|
-
if (local
|
|
7985
|
+
const local = new RuntimeRoute().local(request);
|
|
7986
|
+
if (local) {
|
|
7285
7987
|
const payload2 = await localBridge(request, local, opts);
|
|
7286
7988
|
const detail2 = detailFrom(payload2);
|
|
7287
7989
|
if (detail2) throw new BridgeRejected(detail2);
|
|
@@ -7308,19 +8010,19 @@ async function runtime(creds, request, opts = {}) {
|
|
|
7308
8010
|
if (payload === null) throw new CliError(`POST ${route} (${request.command}) returned non-JSON`, 1);
|
|
7309
8011
|
return payload;
|
|
7310
8012
|
}
|
|
7311
|
-
var fs8,
|
|
8013
|
+
var fs8, path9, MAX_WORLD_FILES, RUNTIME_TIMEOUT_MS, SKIP_DIRS, BridgeRejected, YAML_NAME, YAML_NEEDS_PYYAML, YAML_NOT_ON_PLATFORM, RuntimeRoute;
|
|
7312
8014
|
var init_client = __esm({
|
|
7313
8015
|
"src/cli/runtime/client.ts"() {
|
|
7314
8016
|
"use strict";
|
|
7315
8017
|
fs8 = __toESM(require("fs"));
|
|
7316
|
-
|
|
8018
|
+
path9 = __toESM(require("path"));
|
|
7317
8019
|
init_router();
|
|
7318
8020
|
init_local();
|
|
7319
8021
|
init_transport();
|
|
8022
|
+
init_databaseEngines();
|
|
7320
8023
|
MAX_WORLD_FILES = 2e3;
|
|
7321
8024
|
RUNTIME_TIMEOUT_MS = 18e4;
|
|
7322
8025
|
SKIP_DIRS = /* @__PURE__ */ new Set(["__pycache__", ".git", "node_modules", ".gateway"]);
|
|
7323
|
-
BUILD_OUTPUT = /(^|\/)state\.(sqlite|json)$/;
|
|
7324
8026
|
BridgeRejected = class extends CliError {
|
|
7325
8027
|
constructor(detail) {
|
|
7326
8028
|
super(formatBridgeError(detail), 1);
|
|
@@ -7329,6 +8031,26 @@ var init_client = __esm({
|
|
|
7329
8031
|
detail;
|
|
7330
8032
|
};
|
|
7331
8033
|
YAML_NAME = /\.ya?ml$/i;
|
|
8034
|
+
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";
|
|
8035
|
+
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)";
|
|
8036
|
+
RuntimeRoute = class _RuntimeRoute {
|
|
8037
|
+
constructor(here = localRuntime, hasYaml = localPythonHasYaml) {
|
|
8038
|
+
this.here = here;
|
|
8039
|
+
this.hasYaml = hasYaml;
|
|
8040
|
+
}
|
|
8041
|
+
here;
|
|
8042
|
+
hasYaml;
|
|
8043
|
+
local(request) {
|
|
8044
|
+
const local = this.here();
|
|
8045
|
+
const yaml = yamlDocument(request);
|
|
8046
|
+
if (yaml && local === null) throw _RuntimeRoute.refusal(YAML_NOT_ON_PLATFORM);
|
|
8047
|
+
if (yaml && local !== null && !this.hasYaml(local.python)) throw _RuntimeRoute.refusal(YAML_NEEDS_PYYAML);
|
|
8048
|
+
return local;
|
|
8049
|
+
}
|
|
8050
|
+
static refusal(message) {
|
|
8051
|
+
return new BridgeRejected({ code: "conform", message, schema_path: "/openapi/source" });
|
|
8052
|
+
}
|
|
8053
|
+
};
|
|
7332
8054
|
}
|
|
7333
8055
|
});
|
|
7334
8056
|
|
|
@@ -7343,7 +8065,8 @@ __export(data_exports, {
|
|
|
7343
8065
|
ingestLocalToolCalls: () => ingestLocalToolCalls,
|
|
7344
8066
|
queryLocalWorldData: () => queryLocalWorldData,
|
|
7345
8067
|
queryLocalWorldDataAcross: () => queryLocalWorldDataAcross,
|
|
7346
|
-
showLocalWorldData: () => showLocalWorldData
|
|
8068
|
+
showLocalWorldData: () => showLocalWorldData,
|
|
8069
|
+
sqlLocalWorldData: () => sqlLocalWorldData
|
|
7347
8070
|
});
|
|
7348
8071
|
async function importLocalWorldData(dir, rows, opts, creds) {
|
|
7349
8072
|
const res = await runtime(creds, {
|
|
@@ -7375,8 +8098,8 @@ async function importLocalWorldFiles(dir, sources, opts) {
|
|
|
7375
8098
|
);
|
|
7376
8099
|
const res = await runtime(null, {
|
|
7377
8100
|
command: "import-files",
|
|
7378
|
-
world:
|
|
7379
|
-
sources: sources.map((source) =>
|
|
8101
|
+
world: path10.resolve(dir),
|
|
8102
|
+
sources: sources.map((source) => path10.resolve(source)),
|
|
7380
8103
|
mode: opts.mode ?? "append",
|
|
7381
8104
|
...opts.entity ? { entity: opts.entity } : {},
|
|
7382
8105
|
...opts.delimiter ? { delimiter: opts.delimiter } : {},
|
|
@@ -7402,9 +8125,9 @@ async function chunkLocalWorldFiles(dir, sources, out, opts) {
|
|
|
7402
8125
|
);
|
|
7403
8126
|
const res = await runtime(null, {
|
|
7404
8127
|
command: "chunk-files",
|
|
7405
|
-
world:
|
|
7406
|
-
sources: sources.map((source) =>
|
|
7407
|
-
out:
|
|
8128
|
+
world: path10.resolve(dir),
|
|
8129
|
+
sources: sources.map((source) => path10.resolve(source)),
|
|
8130
|
+
out: path10.resolve(out),
|
|
7408
8131
|
...opts.entity ? { entity: opts.entity } : {},
|
|
7409
8132
|
...opts.delimiter ? { delimiter: opts.delimiter } : {},
|
|
7410
8133
|
...opts.chunkBytes ? { chunk_bytes: opts.chunkBytes } : {},
|
|
@@ -7415,8 +8138,8 @@ async function chunkLocalWorldFiles(dir, sources, out, opts) {
|
|
|
7415
8138
|
function dropBuildOutputs(dir) {
|
|
7416
8139
|
const dropped = [];
|
|
7417
8140
|
for (const file of readWorldFiles(dir, { buildOutputs: true })) {
|
|
7418
|
-
if (!
|
|
7419
|
-
fs9.rmSync(
|
|
8141
|
+
if (!isBuildOutput(file.path)) continue;
|
|
8142
|
+
fs9.rmSync(path10.join(dir, file.path), { force: true });
|
|
7420
8143
|
dropped.push(file.path);
|
|
7421
8144
|
}
|
|
7422
8145
|
return dropped;
|
|
@@ -7483,7 +8206,7 @@ async function queryLocalWorldDataAcross(dir, entity, where, opts) {
|
|
|
7483
8206
|
const payload = await localBridge(
|
|
7484
8207
|
{
|
|
7485
8208
|
command: "query",
|
|
7486
|
-
world:
|
|
8209
|
+
world: path10.resolve(dir),
|
|
7487
8210
|
entity,
|
|
7488
8211
|
across: true,
|
|
7489
8212
|
...opts.compare ? { compare: true } : {},
|
|
@@ -7499,6 +8222,28 @@ async function queryLocalWorldDataAcross(dir, entity, where, opts) {
|
|
|
7499
8222
|
if (detail) throw new BridgeRejected(detail);
|
|
7500
8223
|
return payload;
|
|
7501
8224
|
}
|
|
8225
|
+
async function sqlLocalWorldData(dir, sql, opts) {
|
|
8226
|
+
const local = localRuntime();
|
|
8227
|
+
if (!local)
|
|
8228
|
+
throw new CliError(
|
|
8229
|
+
"`worlds data sql` on a directory reads the world's database in place, so it needs the bundled runtime on this machine. " + localRuntimeReason(),
|
|
8230
|
+
1
|
|
8231
|
+
);
|
|
8232
|
+
const payload = await localBridge(
|
|
8233
|
+
{
|
|
8234
|
+
command: "sql",
|
|
8235
|
+
world: path10.resolve(dir),
|
|
8236
|
+
sql,
|
|
8237
|
+
...opts.limit !== void 0 ? { limit: opts.limit } : {},
|
|
8238
|
+
...opts.scenario ? { scenario: opts.scenario } : {}
|
|
8239
|
+
},
|
|
8240
|
+
local
|
|
8241
|
+
);
|
|
8242
|
+
const detail = detailFrom(payload);
|
|
8243
|
+
if (detail) throw new BridgeRejected(detail);
|
|
8244
|
+
const { status: _status, ...answer } = payload;
|
|
8245
|
+
return answer;
|
|
8246
|
+
}
|
|
7502
8247
|
async function ingestLocalToolCalls(dir, records, opts, creds) {
|
|
7503
8248
|
const res = await runtime(creds, {
|
|
7504
8249
|
command: "ingest-calls",
|
|
@@ -7530,16 +8275,15 @@ async function ingestLocalToolCalls(dir, records, opts, creds) {
|
|
|
7530
8275
|
...res.batch !== void 0 ? { batch: res.batch } : {}
|
|
7531
8276
|
};
|
|
7532
8277
|
}
|
|
7533
|
-
var fs9,
|
|
8278
|
+
var fs9, path10;
|
|
7534
8279
|
var init_data = __esm({
|
|
7535
8280
|
"src/cli/runtime/data.ts"() {
|
|
7536
8281
|
"use strict";
|
|
7537
8282
|
fs9 = __toESM(require("fs"));
|
|
7538
|
-
|
|
8283
|
+
path10 = __toESM(require("path"));
|
|
7539
8284
|
init_router();
|
|
7540
8285
|
init_client();
|
|
7541
8286
|
init_local();
|
|
7542
|
-
BUILD_OUTPUT2 = /(^|\/)state\.(sqlite|json)$/;
|
|
7543
8287
|
}
|
|
7544
8288
|
});
|
|
7545
8289
|
|
|
@@ -7578,27 +8322,27 @@ function typescriptPrefix() {
|
|
|
7578
8322
|
}
|
|
7579
8323
|
}
|
|
7580
8324
|
function command(script, wrapperDir) {
|
|
7581
|
-
const suffix =
|
|
8325
|
+
const suffix = path11.extname(script).toLowerCase();
|
|
7582
8326
|
if (PYTHON_SUFFIXES.includes(suffix)) return { file: process.env.GATEWAY_PYTHON || "python3", args: ["-c", PY_WRAPPER, script] };
|
|
7583
8327
|
if (NODE_SUFFIXES.includes(suffix)) {
|
|
7584
|
-
const wrapper =
|
|
8328
|
+
const wrapper = path11.join(wrapperDir, "transform-wrapper.mjs");
|
|
7585
8329
|
fs10.writeFileSync(wrapper, NODE_WRAPPER);
|
|
7586
8330
|
const flags = suffix === ".ts" || suffix === ".mts" ? typescriptPrefix() : [];
|
|
7587
8331
|
return { file: process.env.GATEWAY_NODE || process.execPath, args: [...flags, wrapper, script] };
|
|
7588
8332
|
}
|
|
7589
|
-
throw new CliError(`${
|
|
8333
|
+
throw new CliError(`${path11.basename(script)}: a transform script is .py, .ts, .mjs, .js or .cjs`, 1);
|
|
7590
8334
|
}
|
|
7591
8335
|
async function runTransform(script, records, opts = {}) {
|
|
7592
8336
|
if (!fs10.existsSync(script) || !fs10.statSync(script).isFile()) throw new CliError(`no transform script at ${script}`, 1);
|
|
7593
|
-
const resolved =
|
|
7594
|
-
const name =
|
|
8337
|
+
const resolved = path11.resolve(script);
|
|
8338
|
+
const name = path11.basename(script);
|
|
7595
8339
|
const timeoutMs = opts.timeoutMs ?? DEFAULT_TRANSFORM_TIMEOUT_MS;
|
|
7596
|
-
const scratch = fs10.mkdtempSync(
|
|
8340
|
+
const scratch = fs10.mkdtempSync(path11.join(os2.tmpdir(), "gateway-transform-"));
|
|
7597
8341
|
try {
|
|
7598
8342
|
const { file, args } = command(resolved, scratch);
|
|
7599
8343
|
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !SCRUBBED.test(key)));
|
|
7600
8344
|
const done = await new Promise((resolve7, reject) => {
|
|
7601
|
-
const child = (0, import_node_child_process3.spawn)(file, args, { cwd:
|
|
8345
|
+
const child = (0, import_node_child_process3.spawn)(file, args, { cwd: path11.dirname(resolved), env, stdio: ["pipe", "pipe", "pipe"] });
|
|
7602
8346
|
let stdout = "";
|
|
7603
8347
|
let stderr = "";
|
|
7604
8348
|
let timedOut = false;
|
|
@@ -7636,14 +8380,14 @@ async function transformRecords(transform, records, opts = {}) {
|
|
|
7636
8380
|
if (typeof transform === "function") return { rows: checkRows(await transform(records), "transform(records)"), stderr: "" };
|
|
7637
8381
|
return runTransform(transform, records, opts);
|
|
7638
8382
|
}
|
|
7639
|
-
var import_node_child_process3, fs10, os2,
|
|
8383
|
+
var import_node_child_process3, fs10, os2, path11, import_node_module, import_meta, DEFAULT_TRANSFORM_TIMEOUT_MS, NODE_SUFFIXES, PYTHON_SUFFIXES, SCRUBBED, PY_WRAPPER, NODE_WRAPPER, isObject, tail;
|
|
7640
8384
|
var init_transform = __esm({
|
|
7641
8385
|
"src/cli/platform/worldData/transform.ts"() {
|
|
7642
8386
|
"use strict";
|
|
7643
8387
|
import_node_child_process3 = require("child_process");
|
|
7644
8388
|
fs10 = __toESM(require("fs"));
|
|
7645
8389
|
os2 = __toESM(require("os"));
|
|
7646
|
-
|
|
8390
|
+
path11 = __toESM(require("path"));
|
|
7647
8391
|
import_node_module = require("module");
|
|
7648
8392
|
init_router();
|
|
7649
8393
|
import_meta = {};
|
|
@@ -7763,7 +8507,7 @@ async function forEachLimited(items, limit, fn) {
|
|
|
7763
8507
|
if (failure) throw failure;
|
|
7764
8508
|
}
|
|
7765
8509
|
async function waitForBatch(client, batchId, opts = {}) {
|
|
7766
|
-
const
|
|
8510
|
+
const sleep4 = opts.sleep ?? client.sleep;
|
|
7767
8511
|
let delay = opts.initialDelayMs ?? 1e3;
|
|
7768
8512
|
let last = "";
|
|
7769
8513
|
for (; ; ) {
|
|
@@ -7774,7 +8518,7 @@ async function waitForBatch(client, batchId, opts = {}) {
|
|
|
7774
8518
|
last = phase;
|
|
7775
8519
|
}
|
|
7776
8520
|
if (isSettled(status)) return status;
|
|
7777
|
-
await
|
|
8521
|
+
await sleep4(delay);
|
|
7778
8522
|
delay = Math.min(1e4, Math.round(delay * 1.5));
|
|
7779
8523
|
}
|
|
7780
8524
|
}
|
|
@@ -7798,10 +8542,10 @@ var init_batches = __esm({
|
|
|
7798
8542
|
]);
|
|
7799
8543
|
sleepMs = (ms) => new Promise((resolve7) => setTimeout(resolve7, ms));
|
|
7800
8544
|
WorldDataApi = class {
|
|
7801
|
-
constructor(creds, slug,
|
|
8545
|
+
constructor(creds, slug, sleep4 = sleepMs) {
|
|
7802
8546
|
this.creds = creds;
|
|
7803
8547
|
this.slug = slug;
|
|
7804
|
-
this.sleep =
|
|
8548
|
+
this.sleep = sleep4;
|
|
7805
8549
|
this.base = `/api/public/worlds/${encodeURIComponent(slug)}/data`;
|
|
7806
8550
|
}
|
|
7807
8551
|
creds;
|
|
@@ -8205,19 +8949,13 @@ function toolCallsFromObservations(observations, opts = {}) {
|
|
|
8205
8949
|
}
|
|
8206
8950
|
return out;
|
|
8207
8951
|
}
|
|
8208
|
-
function credentialsOf(options) {
|
|
8209
|
-
const host = (options.host ?? process.env.GATEWAY_HOST ?? "https://withgateway.ai").replace(/\/+$/, "");
|
|
8210
|
-
const publicKey = options.publicKey ?? process.env.GATEWAY_PUBLIC_KEY;
|
|
8211
|
-
const secretKey = options.secretKey ?? process.env.GATEWAY_SECRET_KEY;
|
|
8212
|
-
return publicKey && secretKey ? { host, publicKey, secretKey } : null;
|
|
8213
|
-
}
|
|
8214
8952
|
async function ingest(world, records, options = {}) {
|
|
8215
8953
|
const { ingestLocalToolCalls: ingestLocalToolCalls2, importLocalWorldData: importLocalWorldData2, checkLocalWorldData: checkLocalWorldData2 } = await Promise.resolve().then(() => (init_data(), data_exports));
|
|
8216
8954
|
if (options.transform !== void 0 && options.map !== void 0) throw new Error("records go through one of transform, map");
|
|
8217
8955
|
const redact = options.redact ?? "off";
|
|
8218
8956
|
const mode = options.mode ?? "append";
|
|
8219
8957
|
const dryRun = Boolean(options.dryRun);
|
|
8220
|
-
const creds =
|
|
8958
|
+
const creds = platformEndpoint(options);
|
|
8221
8959
|
const local = fs12.existsSync(world) && fs12.statSync(world).isDirectory();
|
|
8222
8960
|
const map = options.map === void 0 ? void 0 : options.map;
|
|
8223
8961
|
let rows = null;
|
|
@@ -8231,12 +8969,12 @@ async function ingest(world, records, options = {}) {
|
|
|
8231
8969
|
const landed = dryRun ? await checkLocalWorldData2(world, rows, creds, { redact }) : await importLocalWorldData2(world, rows, { mode, redact }, creds);
|
|
8232
8970
|
return transformReport(world, records.length, rows, stderr, { dryRun, redact, changed: !dryRun && landed.changed, kind: landed.kind, entityCounts: landed.entity_counts });
|
|
8233
8971
|
}
|
|
8234
|
-
if (!creds) throw new Error(
|
|
8972
|
+
if (!creds) throw new Error(GATEWAY_KEYS_MISSING);
|
|
8235
8973
|
const { pull: pull2 } = await Promise.resolve().then(() => (init_hub(), hub_exports));
|
|
8236
8974
|
const slug = world.split("@", 1)[0];
|
|
8237
|
-
const scratch = fs12.mkdtempSync(
|
|
8975
|
+
const scratch = fs12.mkdtempSync(path12.join(os3.tmpdir(), "gateway-ingest-"));
|
|
8238
8976
|
try {
|
|
8239
|
-
const pulled = await pull2(world,
|
|
8977
|
+
const pulled = await pull2(world, path12.join(scratch, slug), options);
|
|
8240
8978
|
let report;
|
|
8241
8979
|
let projected;
|
|
8242
8980
|
if (rows === null) {
|
|
@@ -8310,14 +9048,15 @@ async function sessionToolObservations(sessionId, options = {}) {
|
|
|
8310
9048
|
for (const observation of trace3.observations ?? []) out.push({ traceId: trace3.id ?? null, ...observation });
|
|
8311
9049
|
return out;
|
|
8312
9050
|
}
|
|
8313
|
-
var fs12, os3,
|
|
9051
|
+
var fs12, os3, path12, isObject2, isoOf;
|
|
8314
9052
|
var init_ingest = __esm({
|
|
8315
9053
|
"src/worlds/ingest.ts"() {
|
|
8316
9054
|
"use strict";
|
|
8317
9055
|
fs12 = __toESM(require("fs"));
|
|
8318
9056
|
os3 = __toESM(require("os"));
|
|
8319
|
-
|
|
9057
|
+
path12 = __toESM(require("path"));
|
|
8320
9058
|
init_worlds();
|
|
9059
|
+
init_platformEndpoint();
|
|
8321
9060
|
isObject2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8322
9061
|
isoOf = (value) => value instanceof Date ? value.toISOString() : typeof value === "string" ? value : void 0;
|
|
8323
9062
|
}
|
|
@@ -8418,7 +9157,7 @@ var init_dryRun = __esm({
|
|
|
8418
9157
|
/** Poll until the run settles or `timeoutSeconds` pass; the last verdict either way. */
|
|
8419
9158
|
async settle(runId, opts) {
|
|
8420
9159
|
const now = opts.now ?? Date.now;
|
|
8421
|
-
const
|
|
9160
|
+
const sleep4 = opts.sleep ?? ((ms) => new Promise((resolve7) => setTimeout(resolve7, ms)));
|
|
8422
9161
|
const deadline = now() + opts.timeoutSeconds * 1e3;
|
|
8423
9162
|
for (; ; ) {
|
|
8424
9163
|
const budget = Math.floor(
|
|
@@ -8428,7 +9167,7 @@ var init_dryRun = __esm({
|
|
|
8428
9167
|
const verdict = await this.status(runId, budget);
|
|
8429
9168
|
if (verdict.settled || now() >= deadline) return verdict;
|
|
8430
9169
|
opts.onProgress?.(verdict);
|
|
8431
|
-
if (now() - asked < 1e3) await
|
|
9170
|
+
if (now() - asked < 1e3) await sleep4(1e3);
|
|
8432
9171
|
}
|
|
8433
9172
|
}
|
|
8434
9173
|
};
|
|
@@ -8496,6 +9235,8 @@ __export(worlds_exports, {
|
|
|
8496
9235
|
EXPLORATORY_TASK: () => EXPLORATORY_TASK,
|
|
8497
9236
|
EXPLORATORY_TASK_SOURCE: () => EXPLORATORY_TASK_SOURCE,
|
|
8498
9237
|
GatewayEvalsClient: () => GatewayEvalsClient,
|
|
9238
|
+
GradePayload: () => GradePayload,
|
|
9239
|
+
GradeRefused: () => GradeRefused,
|
|
8499
9240
|
HostedDryRunClient: () => HostedDryRunClient,
|
|
8500
9241
|
IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
|
|
8501
9242
|
KEY_NAMES: () => KEY_NAMES,
|
|
@@ -8511,6 +9252,7 @@ __export(worlds_exports, {
|
|
|
8511
9252
|
PlatformTransport: () => PlatformTransport,
|
|
8512
9253
|
PushSlugConflict: () => PushSlugConflict,
|
|
8513
9254
|
RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
|
|
9255
|
+
RetryPolicy: () => RetryPolicy,
|
|
8514
9256
|
SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
|
|
8515
9257
|
SECRET_KEY: () => SECRET_KEY,
|
|
8516
9258
|
SESSION_STATES: () => SESSION_STATES,
|
|
@@ -8518,8 +9260,10 @@ __export(worlds_exports, {
|
|
|
8518
9260
|
STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
|
|
8519
9261
|
STRIP_PREFIX: () => STRIP_PREFIX,
|
|
8520
9262
|
SURFACE_KINDS: () => SURFACE_KINDS,
|
|
9263
|
+
Score: () => Score,
|
|
8521
9264
|
Screen: () => Screen,
|
|
8522
9265
|
SecretScrubber: () => SecretScrubber,
|
|
9266
|
+
TOOL_CONTRACT_UNREAD: () => TOOL_CONTRACT_UNREAD,
|
|
8523
9267
|
TRANSFORMS: () => TRANSFORMS,
|
|
8524
9268
|
TaskEditClient: () => TaskEditClient,
|
|
8525
9269
|
TaskRun: () => TaskRun,
|
|
@@ -8531,14 +9275,17 @@ __export(worlds_exports, {
|
|
|
8531
9275
|
WorldBrowser: () => WorldBrowser,
|
|
8532
9276
|
WorldCallTooLarge: () => WorldCallTooLarge,
|
|
8533
9277
|
WorldEditClient: () => WorldEditClient,
|
|
9278
|
+
WorldNotice: () => WorldNotice,
|
|
8534
9279
|
WorldRequestLog: () => WorldRequestLog,
|
|
8535
9280
|
WorldSandboxClient: () => WorldSandboxClient,
|
|
8536
9281
|
WorldSession: () => WorldSession,
|
|
8537
9282
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
9283
|
+
WorldSessionOpenFailed: () => WorldSessionOpenFailed,
|
|
8538
9284
|
WorldSessionTimeout: () => WorldSessionTimeout,
|
|
8539
9285
|
WorldSet: () => WorldSet,
|
|
8540
9286
|
WorldSurfaceUnavailable: () => WorldSurfaceUnavailable,
|
|
8541
9287
|
WorldTask: () => WorldTask,
|
|
9288
|
+
WorldToolsUnread: () => WorldToolsUnread,
|
|
8542
9289
|
aggregateTaskGrade: () => aggregateTaskGrade,
|
|
8543
9290
|
apiRequest: () => apiRequest,
|
|
8544
9291
|
applyTransforms: () => applyTransforms,
|
|
@@ -8581,6 +9328,7 @@ __export(worlds_exports, {
|
|
|
8581
9328
|
listTaskSessions: () => listTaskSessions,
|
|
8582
9329
|
listTasks: () => listTasks,
|
|
8583
9330
|
localTreeState: () => localTreeState,
|
|
9331
|
+
messageOf: () => messageOf,
|
|
8584
9332
|
migrateProjectWorlds: () => migrateProjectWorlds,
|
|
8585
9333
|
migrateWorld: () => migrateWorld,
|
|
8586
9334
|
modelToolName: () => modelToolName,
|
|
@@ -8624,10 +9372,14 @@ __export(worlds_exports, {
|
|
|
8624
9372
|
setEnvSecret: () => setEnvSecret,
|
|
8625
9373
|
shapeText: () => shapeText,
|
|
8626
9374
|
snapshotTreeHashes: () => snapshotTreeHashes,
|
|
9375
|
+
sqlRows: () => sqlRows,
|
|
9376
|
+
stillStartingHint: () => stillStartingHint,
|
|
8627
9377
|
storedForms: () => storedForms,
|
|
8628
9378
|
surfaceDescriptor: () => surfaceDescriptor,
|
|
8629
9379
|
surfaceKinds: () => surfaceKinds,
|
|
9380
|
+
taskGradeError: () => taskGradeError,
|
|
8630
9381
|
taskLabel: () => taskLabel,
|
|
9382
|
+
taskRunFailure: () => taskRunFailure,
|
|
8631
9383
|
toolCallRecordsIn: () => toolCallRecordsIn,
|
|
8632
9384
|
toolCallsFromObservations: () => toolCallsFromObservations,
|
|
8633
9385
|
uiEntryUrl: () => uiEntryUrl,
|
|
@@ -8642,17 +9394,6 @@ __export(worlds_exports, {
|
|
|
8642
9394
|
writeLocalMeta: () => writeLocalMeta
|
|
8643
9395
|
});
|
|
8644
9396
|
module.exports = __toCommonJS(worlds_exports);
|
|
8645
|
-
function resolveEnv(options) {
|
|
8646
|
-
const host = options.host ?? process.env.GATEWAY_HOST ?? "https://withgateway.ai";
|
|
8647
|
-
const publicKey = options.publicKey ?? process.env.GATEWAY_PUBLIC_KEY;
|
|
8648
|
-
const secretKey = options.secretKey ?? process.env.GATEWAY_SECRET_KEY;
|
|
8649
|
-
if (!publicKey || !secretKey) {
|
|
8650
|
-
throw new Error(
|
|
8651
|
-
"Gateway keys missing: set GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY (or pass publicKey/secretKey)."
|
|
8652
|
-
);
|
|
8653
|
-
}
|
|
8654
|
-
return { host: host.replace(/\/+$/, ""), publicKey, secretKey };
|
|
8655
|
-
}
|
|
8656
9397
|
function parseErrorBody(text2, limit = 600) {
|
|
8657
9398
|
const raw = { detail: text2.slice(0, limit), code: null };
|
|
8658
9399
|
let parsed;
|
|
@@ -8672,9 +9413,9 @@ function parseErrorBody(text2, limit = 600) {
|
|
|
8672
9413
|
code: stableCode
|
|
8673
9414
|
};
|
|
8674
9415
|
}
|
|
8675
|
-
async function apiRequest(options, method,
|
|
8676
|
-
const reply = await new PlatformTransport(
|
|
8677
|
-
if (!reply.ok) throw new ApiError(reply.status, method,
|
|
9416
|
+
async function apiRequest(options, method, path13, body, init2 = {}) {
|
|
9417
|
+
const reply = await new PlatformTransport(requirePlatformEndpoint(options)).send(method, path13, body, init2);
|
|
9418
|
+
if (!reply.ok) throw new ApiError(reply.status, method, path13, reply.text);
|
|
8678
9419
|
return JSON.parse(reply.text);
|
|
8679
9420
|
}
|
|
8680
9421
|
async function setEnvSecret(slug, key, value, options = {}) {
|
|
@@ -8786,7 +9527,6 @@ function detectProvenance() {
|
|
|
8786
9527
|
kind: "ci",
|
|
8787
9528
|
id: env.GITHUB_ACTOR,
|
|
8788
9529
|
name: env.GITHUB_ACTOR,
|
|
8789
|
-
// GitHub serves every account's avatar at /<login>.png.
|
|
8790
9530
|
imageUrl: `${server}/${env.GITHUB_ACTOR}.png`
|
|
8791
9531
|
};
|
|
8792
9532
|
}
|
|
@@ -8854,9 +9594,11 @@ async function resolveWorld(slugRef, slug, ref, pin, options) {
|
|
|
8854
9594
|
var ApiError, WorldTask, WorldSet;
|
|
8855
9595
|
var init_worlds = __esm({
|
|
8856
9596
|
"src/worlds/index.ts"() {
|
|
9597
|
+
init_platformEndpoint();
|
|
8857
9598
|
init_transport();
|
|
8858
9599
|
init_transport();
|
|
8859
9600
|
init_session2();
|
|
9601
|
+
init_grade();
|
|
8860
9602
|
init_sessionList();
|
|
8861
9603
|
init_sessionContract();
|
|
8862
9604
|
init_taskRef();
|
|
@@ -8882,10 +9624,11 @@ var init_worlds = __esm({
|
|
|
8882
9624
|
init_sandbox();
|
|
8883
9625
|
init_editSessions();
|
|
8884
9626
|
init_dryRun();
|
|
9627
|
+
init_worldNotice();
|
|
8885
9628
|
ApiError = class extends Error {
|
|
8886
|
-
constructor(status, method,
|
|
9629
|
+
constructor(status, method, path13, text2) {
|
|
8887
9630
|
const parsed = parseErrorBody(text2);
|
|
8888
|
-
super(`${method} ${
|
|
9631
|
+
super(`${method} ${path13} -> ${status}: ${parsed.detail}`);
|
|
8889
9632
|
this.status = status;
|
|
8890
9633
|
this.text = text2;
|
|
8891
9634
|
this.name = "ApiError";
|
|
@@ -9001,6 +9744,8 @@ init_worlds();
|
|
|
9001
9744
|
EXPLORATORY_TASK,
|
|
9002
9745
|
EXPLORATORY_TASK_SOURCE,
|
|
9003
9746
|
GatewayEvalsClient,
|
|
9747
|
+
GradePayload,
|
|
9748
|
+
GradeRefused,
|
|
9004
9749
|
HostedDryRunClient,
|
|
9005
9750
|
IDLE_WARNING_MINUTES,
|
|
9006
9751
|
KEY_NAMES,
|
|
@@ -9016,6 +9761,7 @@ init_worlds();
|
|
|
9016
9761
|
PlatformTransport,
|
|
9017
9762
|
PushSlugConflict,
|
|
9018
9763
|
RECOVER_BUDGET_MS,
|
|
9764
|
+
RetryPolicy,
|
|
9019
9765
|
SANDBOX_REQUEST_TIMEOUT_MS,
|
|
9020
9766
|
SECRET_KEY,
|
|
9021
9767
|
SESSION_STATES,
|
|
@@ -9023,8 +9769,10 @@ init_worlds();
|
|
|
9023
9769
|
STATUS_WAIT_CAP_SECONDS,
|
|
9024
9770
|
STRIP_PREFIX,
|
|
9025
9771
|
SURFACE_KINDS,
|
|
9772
|
+
Score,
|
|
9026
9773
|
Screen,
|
|
9027
9774
|
SecretScrubber,
|
|
9775
|
+
TOOL_CONTRACT_UNREAD,
|
|
9028
9776
|
TRANSFORMS,
|
|
9029
9777
|
TaskEditClient,
|
|
9030
9778
|
TaskRun,
|
|
@@ -9036,14 +9784,17 @@ init_worlds();
|
|
|
9036
9784
|
WorldBrowser,
|
|
9037
9785
|
WorldCallTooLarge,
|
|
9038
9786
|
WorldEditClient,
|
|
9787
|
+
WorldNotice,
|
|
9039
9788
|
WorldRequestLog,
|
|
9040
9789
|
WorldSandboxClient,
|
|
9041
9790
|
WorldSession,
|
|
9042
9791
|
WorldSessionCallError,
|
|
9792
|
+
WorldSessionOpenFailed,
|
|
9043
9793
|
WorldSessionTimeout,
|
|
9044
9794
|
WorldSet,
|
|
9045
9795
|
WorldSurfaceUnavailable,
|
|
9046
9796
|
WorldTask,
|
|
9797
|
+
WorldToolsUnread,
|
|
9047
9798
|
aggregateTaskGrade,
|
|
9048
9799
|
apiRequest,
|
|
9049
9800
|
applyTransforms,
|
|
@@ -9086,6 +9837,7 @@ init_worlds();
|
|
|
9086
9837
|
listTaskSessions,
|
|
9087
9838
|
listTasks,
|
|
9088
9839
|
localTreeState,
|
|
9840
|
+
messageOf,
|
|
9089
9841
|
migrateProjectWorlds,
|
|
9090
9842
|
migrateWorld,
|
|
9091
9843
|
modelToolName,
|
|
@@ -9129,10 +9881,14 @@ init_worlds();
|
|
|
9129
9881
|
setEnvSecret,
|
|
9130
9882
|
shapeText,
|
|
9131
9883
|
snapshotTreeHashes,
|
|
9884
|
+
sqlRows,
|
|
9885
|
+
stillStartingHint,
|
|
9132
9886
|
storedForms,
|
|
9133
9887
|
surfaceDescriptor,
|
|
9134
9888
|
surfaceKinds,
|
|
9889
|
+
taskGradeError,
|
|
9135
9890
|
taskLabel,
|
|
9891
|
+
taskRunFailure,
|
|
9136
9892
|
toolCallRecordsIn,
|
|
9137
9893
|
toolCallsFromObservations,
|
|
9138
9894
|
uiEntryUrl,
|