@withgateway/sdk 0.2.6 → 0.2.9
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 +24 -8
- package/dist/cli.js +15468 -11263
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +15233 -11028
- 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 +291 -40
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +284 -37
- package/dist/files/index.mjs.map +1 -1
- package/dist/hooks/index.d.mts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +203 -47
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +198 -42
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/{index-BaKu5ZSU.d.mts → index-C3UzD0G3.d.mts} +75 -1
- package/dist/{index-BaKu5ZSU.d.ts → index-C3UzD0G3.d.ts} +75 -1
- package/dist/{index-CLkMr6VG.d.ts → index-D-_4Ibcn.d.ts} +36 -4
- package/dist/{index-CdbmO4aX.d.mts → index-FfK4Nump.d.mts} +36 -4
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2149 -615
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2053 -566
- package/dist/index.mjs.map +1 -1
- package/dist/traces/index.js +268 -31
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +262 -28
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.js +19 -11
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +19 -11
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/worlds/index.d.mts +886 -117
- package/dist/worlds/index.d.ts +886 -117
- package/dist/worlds/index.js +1770 -452
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +1752 -434
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +14 -10
- package/runtime/gatewaysdk/environment/_toml.py +3 -10
- package/runtime/gatewaysdk/environment/_world.py +95 -28
- package/runtime/gatewaysdk/environment/runtime.py +10 -6
- package/runtime/gatewaysdk/environment/schema/__main__.py +35 -0
- package/runtime/gatewaysdk/environment/schema/api.py +19 -23
- package/runtime/gatewaysdk/environment/schema/batch.py +68 -14
- package/runtime/gatewaysdk/environment/schema/bundle_runtime.py +4 -2
- package/runtime/gatewaysdk/environment/schema/cast.py +264 -0
- package/runtime/gatewaysdk/environment/schema/compiler.py +35 -1
- package/runtime/gatewaysdk/environment/schema/conform.py +28 -10
- package/runtime/gatewaysdk/environment/schema/connector.py +59 -14
- package/runtime/gatewaysdk/environment/schema/connectors/custom/handlers.py +38 -1
- package/runtime/gatewaysdk/environment/schema/connectors/google-drive/readers/merge.toml +3 -1
- package/runtime/gatewaysdk/environment/schema/credentials.py +20 -0
- package/runtime/gatewaysdk/environment/schema/csv_rows.py +117 -0
- package/runtime/gatewaysdk/environment/schema/cycles.py +121 -0
- package/runtime/gatewaysdk/environment/schema/data.py +21 -5
- package/runtime/gatewaysdk/environment/schema/grading.py +95 -13
- package/runtime/gatewaysdk/environment/schema/handler_errors.py +44 -0
- package/runtime/gatewaysdk/environment/schema/handler_scan.py +175 -0
- package/runtime/gatewaysdk/environment/schema/host.py +68 -115
- package/runtime/gatewaysdk/environment/schema/host_requests.py +78 -0
- package/runtime/gatewaysdk/environment/schema/host_surfaces.py +12 -0
- package/runtime/gatewaysdk/environment/schema/ingest.py +5 -18
- package/runtime/gatewaysdk/environment/schema/local.py +7 -10
- package/runtime/gatewaysdk/environment/schema/openapi_document.py +322 -0
- package/runtime/gatewaysdk/environment/schema/openapi_import.py +382 -0
- package/runtime/gatewaysdk/environment/schema/openapi_routes.py +441 -0
- package/runtime/gatewaysdk/environment/schema/openapi_schemas.py +629 -0
- package/runtime/gatewaysdk/environment/schema/openapi_source.py +210 -0
- package/runtime/gatewaysdk/environment/schema/platform.py +110 -299
- package/runtime/gatewaysdk/environment/schema/platform_import.py +182 -0
- package/runtime/gatewaysdk/environment/schema/platform_query.py +95 -0
- package/runtime/gatewaysdk/environment/schema/route_bindings.py +176 -0
- package/runtime/gatewaysdk/environment/schema/runtime.py +56 -7
- package/runtime/gatewaysdk/environment/schema/scaffold.py +64 -5
- package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +70 -22
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +54 -4
- package/runtime/gatewaysdk/environment/schema/skills/hooks-getting-started/SKILL.md +27 -2
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/ROWS.md +62 -0
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +91 -54
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +146 -146
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +11 -7
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +30 -0
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/new-world-sandbox.md +43 -0
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/openapi-import.md +90 -0
- package/runtime/gatewaysdk/environment/schema/store.py +15 -6
- package/runtime/gatewaysdk/environment/schema/store_contract.py +119 -0
- package/runtime/gatewaysdk/environment/schema/tasks.py +121 -32
- package/runtime/gatewaysdk/environment/schema/tools_world.py +32 -10
- package/runtime/gatewaysdk/environment/schema/tree_import.py +228 -0
- package/runtime/gatewaysdk/environment/schema/ui.py +18 -2
- package/runtime/gatewaysdk/environment/schema/validation.py +35 -0
- package/runtime/gatewaysdk/environment/schema/verbs.py +8 -2
- package/runtime/gatewaysdk/environment/world.py +42 -3
- package/runtime/gatewaysdk/environment/world_session_contract.py +57 -0
- package/skills/benchmarks-getting-started/SKILL.md +70 -22
- package/skills/connector-schema-authoring/SKILL.md +54 -4
- package/skills/connector-schema-authoring/connector-worlds.md +21 -7
- package/skills/connector-schema-authoring/world-schema.md +144 -83
- package/skills/hooks-getting-started/SKILL.md +27 -2
- package/skills/world-data-ingestion/ROWS.md +62 -0
- package/skills/world-data-ingestion/SKILL.md +91 -54
- package/skills/worlds-getting-started/SKILL.md +146 -146
- package/skills/worlds-getting-started/references/cli-mcp-map.md +11 -7
- package/skills/worlds-getting-started/references/gotchas.md +30 -0
- package/skills/worlds-getting-started/references/new-world-sandbox.md +43 -0
- package/skills/worlds-getting-started/references/openapi-import.md +90 -0
package/dist/worlds/index.js
CHANGED
|
@@ -5,11 +5,20 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __esm = (fn, res) => function __init() {
|
|
9
|
-
|
|
8
|
+
var __esm = (fn, res, err) => function __init() {
|
|
9
|
+
if (err) throw err[0];
|
|
10
|
+
try {
|
|
11
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
12
|
+
} catch (e) {
|
|
13
|
+
throw err = [e], e;
|
|
14
|
+
}
|
|
10
15
|
};
|
|
11
16
|
var __commonJS = (cb, mod) => function __require() {
|
|
12
|
-
|
|
17
|
+
try {
|
|
18
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
19
|
+
} catch (e) {
|
|
20
|
+
throw mod = 0, e;
|
|
21
|
+
}
|
|
13
22
|
};
|
|
14
23
|
var __export = (target, all) => {
|
|
15
24
|
for (var name in all)
|
|
@@ -33,7 +42,275 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
33
42
|
));
|
|
34
43
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
44
|
|
|
45
|
+
// src/worlds/transport.ts
|
|
46
|
+
function platformTimeoutMs(env = process.env) {
|
|
47
|
+
const raw = env[PLATFORM_TIMEOUT_ENV];
|
|
48
|
+
if (raw === void 0 || raw === "") return PLATFORM_TIMEOUT_DEFAULT_MS;
|
|
49
|
+
const value = Number(raw);
|
|
50
|
+
if (Number.isInteger(value) && value > 0) return value;
|
|
51
|
+
throw new Error(`${PLATFORM_TIMEOUT_ENV} must be a positive whole number of milliseconds, not \`${raw}\`.`);
|
|
52
|
+
}
|
|
53
|
+
var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, PlatformTransport;
|
|
54
|
+
var init_transport = __esm({
|
|
55
|
+
"src/worlds/transport.ts"() {
|
|
56
|
+
"use strict";
|
|
57
|
+
PLATFORM_TIMEOUT_ENV = "GATEWAY_TIMEOUT_MS";
|
|
58
|
+
PLATFORM_TIMEOUT_DEFAULT_MS = 12e4;
|
|
59
|
+
CHECK_HOST = "Check GATEWAY_HOST (or --host) points at a running platform, then retry.";
|
|
60
|
+
RETRY = "Retry; if it repeats, check the network between here and the platform.";
|
|
61
|
+
CAUSES = {
|
|
62
|
+
ECONNREFUSED: { reason: "connection refused", next: CHECK_HOST },
|
|
63
|
+
ENOTFOUND: { reason: "DNS lookup failed", next: CHECK_HOST },
|
|
64
|
+
EAI_AGAIN: { reason: "DNS lookup failed", next: CHECK_HOST },
|
|
65
|
+
ETIMEDOUT: { reason: "connect timed out", next: CHECK_HOST },
|
|
66
|
+
UND_ERR_CONNECT_TIMEOUT: { reason: "connect timed out", next: CHECK_HOST },
|
|
67
|
+
EHOSTUNREACH: { reason: "host unreachable", next: CHECK_HOST },
|
|
68
|
+
ENETUNREACH: { reason: "network unreachable", next: RETRY },
|
|
69
|
+
ECONNRESET: { reason: "connection dropped", next: RETRY },
|
|
70
|
+
UND_ERR_SOCKET: { reason: "connection dropped", next: RETRY },
|
|
71
|
+
EPIPE: { reason: "connection dropped", next: RETRY }
|
|
72
|
+
};
|
|
73
|
+
UNKNOWN_CAUSE = { reason: "network error", next: CHECK_HOST };
|
|
74
|
+
TransportCause = class _TransportCause {
|
|
75
|
+
constructor(reason, detail, next) {
|
|
76
|
+
this.reason = reason;
|
|
77
|
+
this.detail = detail;
|
|
78
|
+
this.next = next;
|
|
79
|
+
}
|
|
80
|
+
reason;
|
|
81
|
+
detail;
|
|
82
|
+
next;
|
|
83
|
+
static timeout(timeoutMs) {
|
|
84
|
+
return new _TransportCause(
|
|
85
|
+
`timed out after ${timeoutMs / 1e3}s`,
|
|
86
|
+
null,
|
|
87
|
+
`Retry; if the platform is slow, raise ${PLATFORM_TIMEOUT_ENV} (milliseconds per request).`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
static of(error) {
|
|
91
|
+
const cause = error instanceof Error && error.cause instanceof Error ? error.cause : void 0;
|
|
92
|
+
const code = cause && "code" in cause && typeof cause.code === "string" ? cause.code : null;
|
|
93
|
+
const message = cause?.message ?? (error instanceof Error ? error.message : String(error));
|
|
94
|
+
const known = code && CAUSES[code] || UNKNOWN_CAUSE;
|
|
95
|
+
return new _TransportCause(known.reason, code ? `${code}: ${message}` : message, known.next);
|
|
96
|
+
}
|
|
97
|
+
describe() {
|
|
98
|
+
return this.detail === null ? this.reason : `${this.reason} (${this.detail})`;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
UnreachableError = class extends Error {
|
|
102
|
+
constructor(host, method, route, failure) {
|
|
103
|
+
super(`${method} ${route}: no answer from ${host}: ${failure.describe()}. ${failure.next}`);
|
|
104
|
+
this.host = host;
|
|
105
|
+
this.method = method;
|
|
106
|
+
this.route = route;
|
|
107
|
+
this.failure = failure;
|
|
108
|
+
this.name = "UnreachableError";
|
|
109
|
+
}
|
|
110
|
+
host;
|
|
111
|
+
method;
|
|
112
|
+
route;
|
|
113
|
+
failure;
|
|
114
|
+
};
|
|
115
|
+
PlatformTransport = class {
|
|
116
|
+
constructor(endpoint, timeoutMs = platformTimeoutMs()) {
|
|
117
|
+
this.endpoint = endpoint;
|
|
118
|
+
this.timeoutMs = timeoutMs;
|
|
119
|
+
}
|
|
120
|
+
endpoint;
|
|
121
|
+
timeoutMs;
|
|
122
|
+
/** A request that legitimately takes longer (a sandbox exec, a world create) waits its own budget; every other one waits the default. */
|
|
123
|
+
budget(ownMs) {
|
|
124
|
+
return Math.max(ownMs ?? 0, this.timeoutMs);
|
|
125
|
+
}
|
|
126
|
+
async send(method, route, body, opts = {}) {
|
|
127
|
+
const timeoutMs = this.budget(opts.timeoutMs);
|
|
128
|
+
const payload = body === void 0 ? {} : { body: JSON.stringify(body) };
|
|
129
|
+
const controller = new AbortController();
|
|
130
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
131
|
+
try {
|
|
132
|
+
const res = await fetch(`${this.endpoint.host}${route}`, {
|
|
133
|
+
method,
|
|
134
|
+
headers: {
|
|
135
|
+
"content-type": "application/json",
|
|
136
|
+
accept: "application/json",
|
|
137
|
+
authorization: "Basic " + Buffer.from(`${this.endpoint.publicKey}:${this.endpoint.secretKey}`).toString("base64")
|
|
138
|
+
},
|
|
139
|
+
...payload,
|
|
140
|
+
signal: controller.signal
|
|
141
|
+
});
|
|
142
|
+
return { status: res.status, ok: res.ok, text: await res.text() };
|
|
143
|
+
} catch (error) {
|
|
144
|
+
const cause = controller.signal.aborted ? TransportCause.timeout(timeoutMs) : TransportCause.of(error);
|
|
145
|
+
throw new UnreachableError(this.endpoint.host, method, route, cause);
|
|
146
|
+
} finally {
|
|
147
|
+
clearTimeout(timer);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// src/worlds/browserReconnect.ts
|
|
155
|
+
async function closeConnection(c) {
|
|
156
|
+
await c.context.close();
|
|
157
|
+
await c.browser.close();
|
|
158
|
+
}
|
|
159
|
+
async function releaseConnection(c) {
|
|
160
|
+
await closeConnection(c).catch(() => void 0);
|
|
161
|
+
}
|
|
162
|
+
function isBrowserGone(error) {
|
|
163
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
164
|
+
if (PAGE_NETWORK_ERROR.test(message)) return false;
|
|
165
|
+
return BROWSER_GONE_PATTERNS.some((p) => p.test(message));
|
|
166
|
+
}
|
|
167
|
+
function refusalIsTransient(error) {
|
|
168
|
+
const { status, code } = error;
|
|
169
|
+
if (typeof status !== "number") return true;
|
|
170
|
+
if (status >= 500) return true;
|
|
171
|
+
return status === 400 && code === "browser_capacity";
|
|
172
|
+
}
|
|
173
|
+
function describe(error) {
|
|
174
|
+
return error instanceof Error ? error.message : String(error);
|
|
175
|
+
}
|
|
176
|
+
var RECOVER_BUDGET_MS, BACKOFF_BASE_MS, BACKOFF_CAP_MS, BROWSER_GONE_PATTERNS, PAGE_NETWORK_ERROR, REDACTED, TOKEN_QUERY_VALUE, SecretScrubber, BrowserReconnected, BrowserUnrecoverable, BrowserReconnector;
|
|
177
|
+
var init_browserReconnect = __esm({
|
|
178
|
+
"src/worlds/browserReconnect.ts"() {
|
|
179
|
+
"use strict";
|
|
180
|
+
RECOVER_BUDGET_MS = 9e4;
|
|
181
|
+
BACKOFF_BASE_MS = 1e3;
|
|
182
|
+
BACKOFF_CAP_MS = 5e3;
|
|
183
|
+
BROWSER_GONE_PATTERNS = [
|
|
184
|
+
/target page, context or browser has been closed/i,
|
|
185
|
+
/\bbrowser has been (closed|disconnected)\b/i,
|
|
186
|
+
/\bbrowser (has )?disconnected\b/i,
|
|
187
|
+
/\btarget closed\b/i,
|
|
188
|
+
/\bwebsocket is not open\b/i,
|
|
189
|
+
/\bconnection closed\b/i
|
|
190
|
+
];
|
|
191
|
+
PAGE_NETWORK_ERROR = /net::ERR_/i;
|
|
192
|
+
REDACTED = "<redacted>";
|
|
193
|
+
TOKEN_QUERY_VALUE = /([?&]token=)[^&#\s"')]*/gi;
|
|
194
|
+
SecretScrubber = class {
|
|
195
|
+
secrets;
|
|
196
|
+
constructor(secrets) {
|
|
197
|
+
const known = secrets.filter((s) => Boolean(s));
|
|
198
|
+
this.secrets = [
|
|
199
|
+
.../* @__PURE__ */ new Set([...known, ...known.map((s) => encodeURIComponent(s))])
|
|
200
|
+
].sort((a, b) => b.length - a.length);
|
|
201
|
+
}
|
|
202
|
+
scrub(text2) {
|
|
203
|
+
const bare = this.secrets.reduce(
|
|
204
|
+
(out, secret) => out.split(secret).join(REDACTED),
|
|
205
|
+
text2
|
|
206
|
+
);
|
|
207
|
+
return bare.replace(TOKEN_QUERY_VALUE, `$1${REDACTED}`);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
BrowserReconnected = class extends Error {
|
|
211
|
+
constructor(outcome, restoredUrl, cause) {
|
|
212
|
+
super(
|
|
213
|
+
`the browser was lost mid-action and reconnected (${outcome}); ` + (restoredUrl ? `the page was reopened at ${restoredUrl}. ` : "it is on a blank page. ") + "The action may or may not have taken effect \u2014 look at the page before acting again.",
|
|
214
|
+
{ cause }
|
|
215
|
+
);
|
|
216
|
+
this.outcome = outcome;
|
|
217
|
+
this.restoredUrl = restoredUrl;
|
|
218
|
+
this.name = "BrowserReconnected";
|
|
219
|
+
}
|
|
220
|
+
outcome;
|
|
221
|
+
restoredUrl;
|
|
222
|
+
};
|
|
223
|
+
BrowserUnrecoverable = class extends Error {
|
|
224
|
+
constructor(message, cause) {
|
|
225
|
+
super(message, { cause });
|
|
226
|
+
this.name = "BrowserUnrecoverable";
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
BrowserReconnector = class {
|
|
230
|
+
constructor(repair, connect, opts = {}) {
|
|
231
|
+
this.repair = repair;
|
|
232
|
+
this.connect = connect;
|
|
233
|
+
this.sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
234
|
+
this.now = opts.now ?? Date.now;
|
|
235
|
+
this.budgetMs = opts.budgetMs ?? RECOVER_BUDGET_MS;
|
|
236
|
+
this.scrub = opts.scrub ?? ((text2) => text2);
|
|
237
|
+
}
|
|
238
|
+
repair;
|
|
239
|
+
connect;
|
|
240
|
+
sleep;
|
|
241
|
+
now;
|
|
242
|
+
scrub;
|
|
243
|
+
budgetMs;
|
|
244
|
+
/**
|
|
245
|
+
* Repair, reconnect and `restore` until it works or the budget runs out.
|
|
246
|
+
* `restore` receives each new connection (the owner adopts it and reopens
|
|
247
|
+
* its page); a restore that fails counts as a failed reconnect, because the
|
|
248
|
+
* browser may have died again. A repair the platform refuses for good
|
|
249
|
+
* rethrows `cause` untouched.
|
|
250
|
+
*/
|
|
251
|
+
async recover(cause, restore) {
|
|
252
|
+
const deadline = this.now() + this.budgetMs;
|
|
253
|
+
let reason = describe(cause);
|
|
254
|
+
for (let attempt = 1; ; attempt++) {
|
|
255
|
+
const step = await this.attempt(restore);
|
|
256
|
+
if (step.kind === "recovered")
|
|
257
|
+
return { outcome: step.outcome, attempts: attempt };
|
|
258
|
+
if (step.kind === "stop") throw cause;
|
|
259
|
+
reason = step.reason;
|
|
260
|
+
const remaining = deadline - this.now();
|
|
261
|
+
if (remaining <= 0) break;
|
|
262
|
+
const backoff = Math.min(
|
|
263
|
+
BACKOFF_BASE_MS * 2 ** (attempt - 1),
|
|
264
|
+
BACKOFF_CAP_MS
|
|
265
|
+
);
|
|
266
|
+
await this.sleep(Math.min(step.waitMs ?? backoff, remaining));
|
|
267
|
+
}
|
|
268
|
+
throw new BrowserUnrecoverable(
|
|
269
|
+
`the session's browser could not be recovered within ${Math.round(this.budgetMs / 1e3)}s: ${this.scrub(reason)}`,
|
|
270
|
+
cause
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
async attempt(restore) {
|
|
274
|
+
let answer;
|
|
275
|
+
try {
|
|
276
|
+
answer = await this.repair();
|
|
277
|
+
} catch (error) {
|
|
278
|
+
if (!refusalIsTransient(error)) return { kind: "stop" };
|
|
279
|
+
return {
|
|
280
|
+
kind: "wait",
|
|
281
|
+
reason: `repair failed: ${describe(error)}`,
|
|
282
|
+
waitMs: null
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
const outcome = answer.outcome;
|
|
286
|
+
if (outcome === "starting")
|
|
287
|
+
return {
|
|
288
|
+
kind: "wait",
|
|
289
|
+
reason: "a new browser is still starting",
|
|
290
|
+
waitMs: answer.retryAfterMs
|
|
291
|
+
};
|
|
292
|
+
try {
|
|
293
|
+
await restore(await this.connect());
|
|
294
|
+
} catch (error) {
|
|
295
|
+
return {
|
|
296
|
+
kind: "wait",
|
|
297
|
+
reason: `reconnect failed: ${describe(error)}`,
|
|
298
|
+
waitMs: null
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
return { kind: "recovered", outcome };
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
|
|
36
307
|
// src/worlds/browser.ts
|
|
308
|
+
function assertBrowserTier(value) {
|
|
309
|
+
if (BROWSER_TIERS.includes(value)) return;
|
|
310
|
+
throw new Error(
|
|
311
|
+
`Unknown browser tier: ${String(value)}; choose from ${BROWSER_TIERS.join(", ")}`
|
|
312
|
+
);
|
|
313
|
+
}
|
|
37
314
|
function surfaceKinds(s) {
|
|
38
315
|
const kinds = ["tools"];
|
|
39
316
|
if (s.api) kinds.push("api");
|
|
@@ -41,9 +318,9 @@ function surfaceKinds(s) {
|
|
|
41
318
|
if (s.browser) kinds.push("browser");
|
|
42
319
|
return kinds;
|
|
43
320
|
}
|
|
44
|
-
function uiUrl(ui,
|
|
321
|
+
function uiUrl(ui, path12) {
|
|
45
322
|
const base = ui.url.replace(/\/+$/, "");
|
|
46
|
-
const rel =
|
|
323
|
+
const rel = path12.startsWith("/") ? path12 : `/${path12}`;
|
|
47
324
|
if (!ui.token) return base + rel;
|
|
48
325
|
const [beforeHash, hash] = splitHash(rel);
|
|
49
326
|
const joiner = beforeHash.includes("?") ? "&" : "?";
|
|
@@ -109,19 +386,34 @@ async function openBrowser(surfaces, opts = {}) {
|
|
|
109
386
|
const mode = resolveBrowserMode(surfaces, opts.mode ?? "auto");
|
|
110
387
|
const pw = opts.playwright ?? await loadPlaywright();
|
|
111
388
|
const viewport = surfaces.browser?.viewport ?? DEFAULT_VIEWPORT;
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
389
|
+
const attach = async () => {
|
|
390
|
+
const browser = mode === "hosted" ? surfaces.browser.protocol === "playwright" ? await pw.chromium.connect(surfaces.browser.wsUrl) : await pw.chromium.connectOverCDP(surfaces.browser.wsUrl) : await pw.chromium.launch({ headless: opts.headless ?? true });
|
|
391
|
+
const context = await browser.newContext({ viewport });
|
|
392
|
+
return { browser, context, page: await context.newPage() };
|
|
393
|
+
};
|
|
394
|
+
let live = await attach();
|
|
395
|
+
const reattach = async () => {
|
|
396
|
+
const fresh = await attach();
|
|
397
|
+
await releaseConnection(live);
|
|
398
|
+
live = fresh;
|
|
399
|
+
return fresh;
|
|
400
|
+
};
|
|
401
|
+
const scrubber = new SecretScrubber([
|
|
402
|
+
surfaces.browser?.wsUrl,
|
|
403
|
+
surfaces.ui?.token
|
|
404
|
+
]);
|
|
405
|
+
const reconnector = mode === "hosted" && surfaces.browser.protocol === "cdp" && opts.repair ? new BrowserReconnector(opts.repair, reattach, {
|
|
406
|
+
scrub: (text2) => scrubber.scrub(text2)
|
|
407
|
+
}) : null;
|
|
115
408
|
return new WorldBrowser(
|
|
116
|
-
page,
|
|
409
|
+
live.page,
|
|
117
410
|
surfaces.ui,
|
|
118
411
|
mode,
|
|
119
|
-
|
|
120
|
-
await context.close();
|
|
121
|
-
await browser.close();
|
|
122
|
-
},
|
|
412
|
+
() => closeConnection(live),
|
|
123
413
|
viewport,
|
|
124
|
-
opts.recorder ?? null
|
|
414
|
+
opts.recorder ?? null,
|
|
415
|
+
reconnector,
|
|
416
|
+
scrubber
|
|
125
417
|
);
|
|
126
418
|
}
|
|
127
419
|
function computerUseToolkit(browser, opts = {}) {
|
|
@@ -173,12 +465,14 @@ function computerUseToolkit(browser, opts = {}) {
|
|
|
173
465
|
specs
|
|
174
466
|
};
|
|
175
467
|
}
|
|
176
|
-
var SURFACE_KINDS, DEFAULT_VIEWPORT, SETTLE_TIMEOUT_MS, SETTLE_QUIET_MS, SETTLE_POLL_MS, EVENT_BATCH_SIZE, EVENT_FLUSH_INTERVAL_MS, EVENT_MAX_RETRIES, EVENT_SCREENSHOT_QUALITY, EVENT_MAX_STRING, SECRET_KEY, SECRET_VALUE, WorldSurfaceUnavailable, UI_TOKEN_QUERY, BrowserActionRecorder, WorldBrowser, COMPUTER_USE_SPECS, str;
|
|
468
|
+
var SURFACE_KINDS, BROWSER_TIERS, DEFAULT_VIEWPORT, SETTLE_TIMEOUT_MS, SETTLE_QUIET_MS, SETTLE_POLL_MS, EVENT_BATCH_SIZE, EVENT_FLUSH_INTERVAL_MS, EVENT_MAX_RETRIES, EVENT_SCREENSHOT_QUALITY, EVENT_MAX_STRING, SECRET_KEY, SECRET_VALUE, WorldSurfaceUnavailable, UI_TOKEN_QUERY, BrowserActionRecorder, WorldBrowser, COMPUTER_USE_SPECS, str;
|
|
177
469
|
var init_browser = __esm({
|
|
178
470
|
"src/worlds/browser.ts"() {
|
|
179
471
|
"use strict";
|
|
180
472
|
init_session();
|
|
473
|
+
init_browserReconnect();
|
|
181
474
|
SURFACE_KINDS = ["tools", "api", "ui", "browser"];
|
|
475
|
+
BROWSER_TIERS = ["standard", "premium"];
|
|
182
476
|
DEFAULT_VIEWPORT = { width: 1280, height: 800 };
|
|
183
477
|
SETTLE_TIMEOUT_MS = 5e3;
|
|
184
478
|
SETTLE_QUIET_MS = 150;
|
|
@@ -195,6 +489,7 @@ var init_browser = __esm({
|
|
|
195
489
|
super(`World surface '${surface}' is unavailable: ${reason}`);
|
|
196
490
|
this.surface = surface;
|
|
197
491
|
}
|
|
492
|
+
surface;
|
|
198
493
|
};
|
|
199
494
|
UI_TOKEN_QUERY = "token";
|
|
200
495
|
BrowserActionRecorder = class {
|
|
@@ -203,6 +498,9 @@ var init_browser = __esm({
|
|
|
203
498
|
this.agentId = agentId;
|
|
204
499
|
this.opts = opts;
|
|
205
500
|
}
|
|
501
|
+
post;
|
|
502
|
+
agentId;
|
|
503
|
+
opts;
|
|
206
504
|
seq = 0;
|
|
207
505
|
base = null;
|
|
208
506
|
queue = [];
|
|
@@ -216,8 +514,8 @@ var init_browser = __esm({
|
|
|
216
514
|
}
|
|
217
515
|
resolveBase() {
|
|
218
516
|
if (this.base === null) {
|
|
219
|
-
const
|
|
220
|
-
this.base =
|
|
517
|
+
const resolve7 = this.opts.resumeFrom ?? (async () => 0);
|
|
518
|
+
this.base = resolve7().then((n) => {
|
|
221
519
|
if (!Number.isInteger(n) || n < 0)
|
|
222
520
|
throw new Error(
|
|
223
521
|
`browser event base seq must be a non-negative integer, got ${String(n)}`
|
|
@@ -286,13 +584,38 @@ var init_browser = __esm({
|
|
|
286
584
|
}
|
|
287
585
|
};
|
|
288
586
|
WorldBrowser = class {
|
|
289
|
-
constructor(page, ui, mode, teardown, viewport = DEFAULT_VIEWPORT, recorder = null) {
|
|
290
|
-
this.page = page;
|
|
587
|
+
constructor(page, ui, mode, teardown, viewport = DEFAULT_VIEWPORT, recorder = null, reconnector = null, scrubber = new SecretScrubber([ui?.token])) {
|
|
291
588
|
this.ui = ui;
|
|
292
589
|
this.mode = mode;
|
|
293
590
|
this.teardown = teardown;
|
|
294
591
|
this.viewport = viewport;
|
|
295
592
|
this.recorder = recorder;
|
|
593
|
+
this.reconnector = reconnector;
|
|
594
|
+
this.scrubber = scrubber;
|
|
595
|
+
this.current = page;
|
|
596
|
+
this.watchNetwork(page);
|
|
597
|
+
}
|
|
598
|
+
ui;
|
|
599
|
+
mode;
|
|
600
|
+
teardown;
|
|
601
|
+
viewport;
|
|
602
|
+
recorder;
|
|
603
|
+
reconnector;
|
|
604
|
+
scrubber;
|
|
605
|
+
current;
|
|
606
|
+
inflight = 0;
|
|
607
|
+
lastNetwork = Date.now();
|
|
608
|
+
/** Where the page last was after an action, token stripped: what a
|
|
609
|
+
* reconnect reopens. Null until the page has left `about:blank`. */
|
|
610
|
+
lastUrl = null;
|
|
611
|
+
/** The live Playwright page; a new object after a reconnect. */
|
|
612
|
+
get page() {
|
|
613
|
+
return this.current;
|
|
614
|
+
}
|
|
615
|
+
get agentId() {
|
|
616
|
+
return this.recorder?.agentId ?? null;
|
|
617
|
+
}
|
|
618
|
+
watchNetwork(page) {
|
|
296
619
|
page.on("request", () => {
|
|
297
620
|
this.inflight += 1;
|
|
298
621
|
this.lastNetwork = Date.now();
|
|
@@ -304,42 +627,105 @@ var init_browser = __esm({
|
|
|
304
627
|
page.on("requestfinished", done);
|
|
305
628
|
page.on("requestfailed", done);
|
|
306
629
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
630
|
+
/** Run `fn` against the page. If it fails because the browser is gone,
|
|
631
|
+
* recover; then `retry` runs it ONCE more and `report` throws
|
|
632
|
+
* `BrowserReconnected` instead of replaying it. Any other error, and a
|
|
633
|
+
* second loss during the retry, propagate unchanged. */
|
|
634
|
+
async resilient(fn, onLoss) {
|
|
635
|
+
try {
|
|
636
|
+
return this.remember(await fn());
|
|
637
|
+
} catch (error) {
|
|
638
|
+
if (!this.reconnector || !isBrowserGone(error)) throw error;
|
|
639
|
+
const recovered = await this.recover(this.reconnector, error);
|
|
640
|
+
if (onLoss === "report")
|
|
641
|
+
throw new BrowserReconnected(
|
|
642
|
+
recovered.outcome,
|
|
643
|
+
recovered.restoredUrl,
|
|
644
|
+
error
|
|
645
|
+
);
|
|
646
|
+
}
|
|
647
|
+
return this.remember(await fn());
|
|
648
|
+
}
|
|
649
|
+
remember(result) {
|
|
650
|
+
this.lastUrl = this.openedUrl() ?? this.lastUrl;
|
|
651
|
+
return result;
|
|
652
|
+
}
|
|
653
|
+
/** The page's URL less its token; null while it is blank. */
|
|
654
|
+
openedUrl() {
|
|
655
|
+
const url = this.page.url();
|
|
656
|
+
return url && url !== "about:blank" ? withoutUiToken(url) : null;
|
|
657
|
+
}
|
|
658
|
+
async recover(reconnector, cause) {
|
|
659
|
+
const started = Date.now();
|
|
660
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
661
|
+
const args = { cause: this.scrubber.scrub(message).slice(0, 200) };
|
|
662
|
+
let result;
|
|
663
|
+
try {
|
|
664
|
+
result = await reconnector.recover(cause, (c) => this.adopt(c));
|
|
665
|
+
} catch (error) {
|
|
666
|
+
await this.report("browser_reconnect", args, started, error);
|
|
667
|
+
throw error;
|
|
668
|
+
}
|
|
669
|
+
const restoredUrl = this.openedUrl();
|
|
670
|
+
await this.report(
|
|
671
|
+
"browser_reconnect",
|
|
672
|
+
{ ...args, ...result, restoredUrl },
|
|
673
|
+
started,
|
|
674
|
+
null
|
|
675
|
+
);
|
|
676
|
+
return { ...result, restoredUrl };
|
|
677
|
+
}
|
|
678
|
+
/** Take over a new connection's page and reopen the page the agent was on
|
|
679
|
+
* (`openBrowser` owns the connection itself). A new browser has no session
|
|
680
|
+
* cookie, so a World Host UI is first loaded with its token, exactly as
|
|
681
|
+
* `goto()` loads the entry page. */
|
|
682
|
+
async adopt(connection) {
|
|
683
|
+
this.current = connection.page;
|
|
684
|
+
this.inflight = 0;
|
|
685
|
+
this.watchNetwork(connection.page);
|
|
686
|
+
const last = this.lastUrl;
|
|
687
|
+
if (!last) return;
|
|
688
|
+
if (this.ui?.token)
|
|
689
|
+
await this.page.goto(uiEntryUrl(this.ui), { waitUntil: "load" });
|
|
690
|
+
if (withoutUiToken(this.page.url()) !== last)
|
|
691
|
+
await this.page.goto(last, { waitUntil: "load" });
|
|
692
|
+
await this.settle();
|
|
311
693
|
}
|
|
312
694
|
/** Run one action and report it: the event carries what was asked,
|
|
313
695
|
* whether it worked, and the screen after — for failures too, so a
|
|
314
696
|
* reviewer sees what the agent saw when the selector did not match. */
|
|
315
|
-
async act(action, args, fn) {
|
|
316
|
-
const recorder = this.recorder;
|
|
317
|
-
if (!recorder) return fn();
|
|
697
|
+
async act(action, args, fn, onLoss = "report") {
|
|
318
698
|
const started = Date.now();
|
|
319
|
-
let ok = true;
|
|
320
|
-
let error = null;
|
|
321
699
|
try {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
recorder.record({
|
|
329
|
-
agentId: recorder.agentId,
|
|
330
|
-
seq: recorder.nextSeq(),
|
|
331
|
-
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
332
|
-
action,
|
|
333
|
-
args: redactActionArgs(action, args),
|
|
334
|
-
ok,
|
|
335
|
-
error,
|
|
336
|
-
durationMs: Date.now() - started,
|
|
337
|
-
mode: this.mode,
|
|
338
|
-
viewport: { ...this.viewport },
|
|
339
|
-
...await this.observeForEvent()
|
|
340
|
-
});
|
|
700
|
+
const result = await this.resilient(fn, onLoss);
|
|
701
|
+
await this.report(action, args, started, null);
|
|
702
|
+
return result;
|
|
703
|
+
} catch (error) {
|
|
704
|
+
await this.report(action, args, started, error);
|
|
705
|
+
throw error;
|
|
341
706
|
}
|
|
342
707
|
}
|
|
708
|
+
/** One event on the recorder, if there is one; `failure` null means ok. */
|
|
709
|
+
async report(action, args, started, failure) {
|
|
710
|
+
const recorder = this.recorder;
|
|
711
|
+
if (!recorder) return;
|
|
712
|
+
const error = failure === null ? null : this.scrubber.scrub(
|
|
713
|
+
failure instanceof Error ? `${failure.name}: ${failure.message}` : String(failure)
|
|
714
|
+
).slice(0, 4e3);
|
|
715
|
+
recorder.record({
|
|
716
|
+
agentId: recorder.agentId,
|
|
717
|
+
seq: recorder.nextSeq(),
|
|
718
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
719
|
+
action,
|
|
720
|
+
args: redactActionArgs(action, args),
|
|
721
|
+
ok: failure === null,
|
|
722
|
+
error,
|
|
723
|
+
durationMs: Date.now() - started,
|
|
724
|
+
mode: this.mode,
|
|
725
|
+
viewport: { ...this.viewport },
|
|
726
|
+
...await this.observeForEvent()
|
|
727
|
+
});
|
|
728
|
+
}
|
|
343
729
|
async observeForEvent() {
|
|
344
730
|
const out = {
|
|
345
731
|
url: null,
|
|
@@ -386,7 +772,9 @@ var init_browser = __esm({
|
|
|
386
772
|
await this.page.goto(target, { waitUntil: "load" });
|
|
387
773
|
await this.settle();
|
|
388
774
|
return this.page.url();
|
|
389
|
-
}
|
|
775
|
+
},
|
|
776
|
+
// Navigating again lands on the same page: safe to replay.
|
|
777
|
+
"retry"
|
|
390
778
|
);
|
|
391
779
|
}
|
|
392
780
|
async back() {
|
|
@@ -439,22 +827,25 @@ var init_browser = __esm({
|
|
|
439
827
|
);
|
|
440
828
|
}
|
|
441
829
|
async screenshot(fullPage = false) {
|
|
442
|
-
return this.
|
|
830
|
+
return this.resilient(
|
|
831
|
+
() => this.page.screenshot({ type: "png", fullPage }),
|
|
832
|
+
"retry"
|
|
833
|
+
);
|
|
443
834
|
}
|
|
444
835
|
async screenshotBase64(fullPage = false) {
|
|
445
836
|
return (await this.screenshot(fullPage)).toString("base64");
|
|
446
837
|
}
|
|
447
838
|
async text(selector = "body") {
|
|
448
|
-
return this.page.innerText(selector);
|
|
839
|
+
return this.resilient(() => this.page.innerText(selector), "retry");
|
|
449
840
|
}
|
|
450
841
|
async html() {
|
|
451
|
-
return this.page.content();
|
|
842
|
+
return this.resilient(() => this.page.content(), "retry");
|
|
452
843
|
}
|
|
453
844
|
get url() {
|
|
454
845
|
return this.page.url();
|
|
455
846
|
}
|
|
456
847
|
async title() {
|
|
457
|
-
return this.page.title();
|
|
848
|
+
return this.resilient(() => this.page.title(), "retry");
|
|
458
849
|
}
|
|
459
850
|
async close() {
|
|
460
851
|
try {
|
|
@@ -510,6 +901,82 @@ var init_browser = __esm({
|
|
|
510
901
|
}
|
|
511
902
|
});
|
|
512
903
|
|
|
904
|
+
// src/worlds/sessionContract.ts
|
|
905
|
+
function serializeCallBody(body) {
|
|
906
|
+
const text2 = JSON.stringify(body);
|
|
907
|
+
const size = Buffer.byteLength(text2, "utf8");
|
|
908
|
+
if (size > CALL_BODY_LIMIT_BYTES) throw new WorldCallTooLarge(size);
|
|
909
|
+
return text2;
|
|
910
|
+
}
|
|
911
|
+
function idleWarning(idleExpiresAt, now = /* @__PURE__ */ new Date()) {
|
|
912
|
+
if (!idleExpiresAt) return null;
|
|
913
|
+
const leftMs = new Date(idleExpiresAt).getTime() - now.getTime();
|
|
914
|
+
if (leftMs >= IDLE_WARNING_MINUTES * 6e4) return null;
|
|
915
|
+
const minutes = Math.max(0, Math.floor(leftMs / 6e4));
|
|
916
|
+
return `warning: session expires in ${minutes}m (idle TTL); call a tool to extend it or \`gateway worlds session pin\` to keep it`;
|
|
917
|
+
}
|
|
918
|
+
var CALL_BODY_LIMIT_BYTES, CALL_BODY_LIMIT_LABEL, IDLE_WARNING_MINUTES, EXPLORATORY_TASK, EXPLORATORY_TASK_SOURCE, NO_GRADER_REASON, WorldCallTooLarge;
|
|
919
|
+
var init_sessionContract = __esm({
|
|
920
|
+
"src/worlds/sessionContract.ts"() {
|
|
921
|
+
"use strict";
|
|
922
|
+
CALL_BODY_LIMIT_BYTES = 4 * 1024 * 1024;
|
|
923
|
+
CALL_BODY_LIMIT_LABEL = "4mb";
|
|
924
|
+
IDLE_WARNING_MINUTES = 5;
|
|
925
|
+
EXPLORATORY_TASK = Object.freeze({
|
|
926
|
+
instruction: "exploratory session"
|
|
927
|
+
});
|
|
928
|
+
EXPLORATORY_TASK_SOURCE = "none";
|
|
929
|
+
NO_GRADER_REASON = "no grader";
|
|
930
|
+
WorldCallTooLarge = class extends Error {
|
|
931
|
+
constructor(size, limitBytes = CALL_BODY_LIMIT_BYTES, limit = CALL_BODY_LIMIT_LABEL) {
|
|
932
|
+
super(
|
|
933
|
+
`call body is ${size} bytes; the platform accepts at most ${limit} (${limitBytes} bytes)`
|
|
934
|
+
);
|
|
935
|
+
this.size = size;
|
|
936
|
+
this.limitBytes = limitBytes;
|
|
937
|
+
this.limit = limit;
|
|
938
|
+
this.name = "WorldCallTooLarge";
|
|
939
|
+
}
|
|
940
|
+
size;
|
|
941
|
+
limitBytes;
|
|
942
|
+
limit;
|
|
943
|
+
code = "payload_too_large";
|
|
944
|
+
/** The structured refusal the CLIs print. */
|
|
945
|
+
toJSON() {
|
|
946
|
+
return {
|
|
947
|
+
status: "error",
|
|
948
|
+
code: this.code,
|
|
949
|
+
limit: this.limit,
|
|
950
|
+
size: this.size
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
});
|
|
956
|
+
|
|
957
|
+
// src/worlds/taskRef.ts
|
|
958
|
+
var isTaskIdRef, isTaskSpec, taskLabel, assertTaskRef;
|
|
959
|
+
var init_taskRef = __esm({
|
|
960
|
+
"src/worlds/taskRef.ts"() {
|
|
961
|
+
"use strict";
|
|
962
|
+
isTaskIdRef = (task) => typeof task === "object" && task !== null && "id" in task;
|
|
963
|
+
isTaskSpec = (task) => typeof task === "object" && task !== null && "instruction" in task;
|
|
964
|
+
taskLabel = (task, info) => {
|
|
965
|
+
if (typeof task === "string") return task;
|
|
966
|
+
if (isTaskIdRef(task)) return info?.name ?? task.id;
|
|
967
|
+
if (task.name) return task.name;
|
|
968
|
+
return info?.hash ? `inline:${info.hash.slice(0, 12)}` : "inline";
|
|
969
|
+
};
|
|
970
|
+
assertTaskRef = (task) => {
|
|
971
|
+
const malformed = task === null || typeof task === "string" && !task || isTaskIdRef(task) && !task.id || isTaskSpec(task) && !task.instruction || typeof task === "object" && !isTaskIdRef(task) && !isTaskSpec(task);
|
|
972
|
+
if (malformed)
|
|
973
|
+
throw new Error(
|
|
974
|
+
"openSession needs a task: a bundled task name, a stored task { id, version? } or { instruction, seed?, grader?, metadata? } \u2014 or none at all for an exploratory session"
|
|
975
|
+
);
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
});
|
|
979
|
+
|
|
513
980
|
// src/worlds/session.ts
|
|
514
981
|
var session_exports = {};
|
|
515
982
|
__export(session_exports, {
|
|
@@ -525,6 +992,34 @@ __export(session_exports, {
|
|
|
525
992
|
schemaFromSignature: () => schemaFromSignature,
|
|
526
993
|
taskLabel: () => taskLabel
|
|
527
994
|
});
|
|
995
|
+
function numericGrade(record) {
|
|
996
|
+
const rewards = {};
|
|
997
|
+
const nested = record.rewards;
|
|
998
|
+
if (nested && typeof nested === "object") {
|
|
999
|
+
for (const [key, value] of Object.entries(nested)) {
|
|
1000
|
+
if (typeof value === "number") rewards[key] = value;
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
for (const [key, value] of Object.entries(record)) {
|
|
1004
|
+
if (key !== "reward" && typeof value === "number") rewards[key] = value;
|
|
1005
|
+
}
|
|
1006
|
+
return {
|
|
1007
|
+
reward: typeof record.reward === "number" ? record.reward : null,
|
|
1008
|
+
rewards
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
function verifierGrades(value) {
|
|
1012
|
+
if (!value || typeof value !== "object") return void 0;
|
|
1013
|
+
const out = {};
|
|
1014
|
+
for (const [name, grade] of Object.entries(value)) {
|
|
1015
|
+
const record = grade && typeof grade === "object" ? grade : {};
|
|
1016
|
+
out[name] = {
|
|
1017
|
+
...numericGrade(record),
|
|
1018
|
+
...typeof record.error === "string" ? { error: record.error } : {}
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
return out;
|
|
1022
|
+
}
|
|
528
1023
|
function schemaFromSignature(spec) {
|
|
529
1024
|
if (spec.inputSchema)
|
|
530
1025
|
return {
|
|
@@ -584,12 +1079,9 @@ async function attachSession(sessionId, options = {}) {
|
|
|
584
1079
|
);
|
|
585
1080
|
return new WorldSession(sessionId, state2, options);
|
|
586
1081
|
}
|
|
587
|
-
async function openSession(slugOrRef, taskOrOpts, positionalOpts = {}) {
|
|
588
|
-
const { task, ...opts } =
|
|
589
|
-
if (task
|
|
590
|
-
throw new Error(
|
|
591
|
-
"openSession needs a task: a bundled task name, a stored task { id, version? } or { instruction, seed?, grader?, metadata? }"
|
|
592
|
-
);
|
|
1082
|
+
async function openSession(slugOrRef, taskOrOpts = {}, positionalOpts = {}) {
|
|
1083
|
+
const { task, ...opts } = isOpenSessionOptions(taskOrOpts) ? taskOrOpts : { task: taskOrOpts, ...positionalOpts };
|
|
1084
|
+
if (task !== void 0) assertTaskRef(task);
|
|
593
1085
|
const options = opts.options ?? {};
|
|
594
1086
|
const unknown = (opts.surfaces ?? []).filter(
|
|
595
1087
|
(s) => !SURFACE_KINDS.includes(s)
|
|
@@ -598,6 +1090,7 @@ async function openSession(slugOrRef, taskOrOpts, positionalOpts = {}) {
|
|
|
598
1090
|
throw new Error(
|
|
599
1091
|
`Unknown world surfaces: ${unknown.join(", ")}; choose from ${SURFACE_KINDS.join(", ")}`
|
|
600
1092
|
);
|
|
1093
|
+
if (opts.browserTier !== void 0) assertBrowserTier(opts.browserTier);
|
|
601
1094
|
const at = slugOrRef.indexOf("@");
|
|
602
1095
|
const slug = at === -1 ? slugOrRef : slugOrRef.slice(0, at);
|
|
603
1096
|
const ref = at === -1 ? "" : slugOrRef.slice(at + 1);
|
|
@@ -607,9 +1100,10 @@ async function openSession(slugOrRef, taskOrOpts, positionalOpts = {}) {
|
|
|
607
1100
|
"/api/public/world-sessions",
|
|
608
1101
|
{
|
|
609
1102
|
...opts.versionId ? { versionId: opts.versionId } : { slug, ...ref && { ref } },
|
|
610
|
-
task,
|
|
1103
|
+
...task === void 0 ? {} : { task },
|
|
611
1104
|
...opts.reuseWarm === void 0 ? {} : { reuseWarm: opts.reuseWarm },
|
|
612
|
-
...opts.surfaces?.length ? { surfaces: opts.surfaces } : {}
|
|
1105
|
+
...opts.surfaces?.length ? { surfaces: opts.surfaces } : {},
|
|
1106
|
+
...opts.browserTier === void 0 ? {} : { browserTier: opts.browserTier }
|
|
613
1107
|
}
|
|
614
1108
|
);
|
|
615
1109
|
return new WorldSession(state2.sessionId, state2, options);
|
|
@@ -685,21 +1179,16 @@ async function runSessions(opts) {
|
|
|
685
1179
|
passed: failed === 0 && (opts.failUnder === void 0 || mean >= opts.failUnder)
|
|
686
1180
|
};
|
|
687
1181
|
}
|
|
688
|
-
var import_node_crypto,
|
|
1182
|
+
var import_node_crypto, READY_TIMEOUT_MS, READY_POLL_MS, CALL_TIMEOUT_MS, CALL_POLL_MS, JUDGED_GRADE_TIMEOUT_MS, JUDGED_GRADE_POLL_MS, EXPORT_PAGE, sleep, modelToolName, WorldSessionTimeout, WorldSessionCallError, WorldSession, OPEN_SESSION_OPTION_KEYS, isOpenSessionOptions;
|
|
689
1183
|
var init_session = __esm({
|
|
690
1184
|
"src/worlds/session.ts"() {
|
|
691
1185
|
"use strict";
|
|
692
1186
|
import_node_crypto = require("crypto");
|
|
693
1187
|
init_worlds();
|
|
694
1188
|
init_browser();
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
if (typeof task === "string") return task;
|
|
699
|
-
if (isTaskIdRef(task)) return info?.name ?? task.id;
|
|
700
|
-
if (task.name) return task.name;
|
|
701
|
-
return info?.hash ? `inline:${info.hash.slice(0, 12)}` : "inline";
|
|
702
|
-
};
|
|
1189
|
+
init_sessionContract();
|
|
1190
|
+
init_taskRef();
|
|
1191
|
+
init_taskRef();
|
|
703
1192
|
READY_TIMEOUT_MS = 10 * 6e4;
|
|
704
1193
|
READY_POLL_MS = 2e3;
|
|
705
1194
|
CALL_TIMEOUT_MS = 3 * 6e4;
|
|
@@ -719,16 +1208,25 @@ var init_session = __esm({
|
|
|
719
1208
|
this.current = current;
|
|
720
1209
|
this.options = options;
|
|
721
1210
|
}
|
|
1211
|
+
sessionId;
|
|
1212
|
+
current;
|
|
1213
|
+
options;
|
|
722
1214
|
/** The task's display name: a bundled scenario's, or the inline spec's
|
|
723
|
-
* `name` (null when the spec was unnamed).
|
|
724
|
-
get task() {
|
|
725
|
-
return this.current.taskName;
|
|
726
|
-
}
|
|
727
|
-
/** The task's display name: a bundled scenario's, or the inline spec's
|
|
728
|
-
* `name` (null when the spec was unnamed). */
|
|
1215
|
+
* `name` (null when the spec was unnamed). `task` is the same. */
|
|
729
1216
|
get taskName() {
|
|
730
1217
|
return this.current.taskName;
|
|
731
1218
|
}
|
|
1219
|
+
get task() {
|
|
1220
|
+
return this.taskName;
|
|
1221
|
+
}
|
|
1222
|
+
/** `{idleExpiresAt, pinned}` as of the last state read: when the fleet
|
|
1223
|
+
* reaps the session (null once pinned), and whether it is pinned. */
|
|
1224
|
+
get idle() {
|
|
1225
|
+
return {
|
|
1226
|
+
idleExpiresAt: this.current.idleExpiresAt ?? null,
|
|
1227
|
+
pinned: this.current.pinned ?? false
|
|
1228
|
+
};
|
|
1229
|
+
}
|
|
732
1230
|
/** The platform's notices about the world this session runs on (empty
|
|
733
1231
|
* for a schema world). Printed by the CLI on stderr at open. */
|
|
734
1232
|
get deprecations() {
|
|
@@ -802,23 +1300,37 @@ var init_session = __esm({
|
|
|
802
1300
|
const { agentId, record = true, ...rest } = opts;
|
|
803
1301
|
return openBrowser(await this.surfaces(), {
|
|
804
1302
|
...rest,
|
|
805
|
-
recorder: record ? this.browserRecorder(agentId) : null
|
|
1303
|
+
recorder: record ? this.browserRecorder(agentId) : null,
|
|
1304
|
+
repair: () => this.repairBrowser()
|
|
806
1305
|
});
|
|
807
1306
|
}
|
|
1307
|
+
/** Ask the platform to make this session's hosted browser reachable again
|
|
1308
|
+
* after its connection dropped: `healthy` (reconnect now), `replaced` (a new,
|
|
1309
|
+
* blank browser behind the same wsUrl; reconnect and reopen your page) or
|
|
1310
|
+
* `starting` (ask again in `retryAfterMs`). `browser()` does this on its
|
|
1311
|
+
* own; call it when you drive your own Playwright against `wsUrl`. */
|
|
1312
|
+
async repairBrowser() {
|
|
1313
|
+
return apiRequest(
|
|
1314
|
+
this.options,
|
|
1315
|
+
"POST",
|
|
1316
|
+
`/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/browser-repair`,
|
|
1317
|
+
{}
|
|
1318
|
+
);
|
|
1319
|
+
}
|
|
808
1320
|
/** The reporter `browser()` uses; exposed for a page you drive yourself. */
|
|
809
1321
|
browserRecorder(agentId) {
|
|
810
|
-
const
|
|
1322
|
+
const path12 = `/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/browser-events`;
|
|
811
1323
|
const id = agentId ?? process.env.GATEWAY_AGENT_ID ?? `agent-${(0, import_node_crypto.randomUUID)().replace(/-/g, "").slice(0, 8)}`;
|
|
812
1324
|
return new BrowserActionRecorder(
|
|
813
1325
|
async (events) => {
|
|
814
|
-
await apiRequest(this.options, "POST",
|
|
1326
|
+
await apiRequest(this.options, "POST", path12, { events });
|
|
815
1327
|
},
|
|
816
1328
|
id,
|
|
817
1329
|
{
|
|
818
1330
|
// Continue this agent's timeline where the platform has it, so the
|
|
819
1331
|
// same id reopened later never re-numbers from zero.
|
|
820
1332
|
resumeFrom: async () => {
|
|
821
|
-
const summary = await apiRequest(this.options, "GET",
|
|
1333
|
+
const summary = await apiRequest(this.options, "GET", path12);
|
|
822
1334
|
return summary.agents.find((a) => a.agentId === id)?.nextSeq ?? 0;
|
|
823
1335
|
}
|
|
824
1336
|
}
|
|
@@ -866,6 +1378,7 @@ var init_session = __esm({
|
|
|
866
1378
|
}
|
|
867
1379
|
/** Enqueue one interaction and wait for the container's answer. */
|
|
868
1380
|
async exchange(body, timeoutMs) {
|
|
1381
|
+
serializeCallBody(body);
|
|
869
1382
|
const enqueued = await apiRequest(
|
|
870
1383
|
this.options,
|
|
871
1384
|
"POST",
|
|
@@ -937,26 +1450,25 @@ var init_session = __esm({
|
|
|
937
1450
|
* the judge's budget (15 min) instead of a call's. `timeoutMs` overrides
|
|
938
1451
|
* either. `report` is the agent's own account of what it did and found,
|
|
939
1452
|
* handed to the judge as its claim beside the evidence (the state and the
|
|
940
|
-
* calls); assertions and python graders ignore it.
|
|
1453
|
+
* calls); assertions and python graders ignore it. `worlds` names the
|
|
1454
|
+
* task's other sessions by alias (`{alias: sessionId}`): the platform
|
|
1455
|
+
* reads each one's evidence and hands it to the cross-world verifiers
|
|
1456
|
+
* anchored on this session, whose grades come back under `verifiers`. */
|
|
941
1457
|
async grade(opts = {}) {
|
|
942
1458
|
const raw = await this.exchange(
|
|
943
|
-
|
|
1459
|
+
{
|
|
1460
|
+
kind: "grade",
|
|
1461
|
+
...opts.report !== void 0 ? { report: opts.report } : {},
|
|
1462
|
+
...opts.worlds && Object.keys(opts.worlds).length > 0 ? { worlds: opts.worlds } : {}
|
|
1463
|
+
},
|
|
944
1464
|
opts.timeoutMs
|
|
945
1465
|
);
|
|
946
1466
|
const record = raw && typeof raw === "object" ? raw : {};
|
|
947
|
-
const
|
|
948
|
-
const nested = record.rewards;
|
|
949
|
-
if (nested && typeof nested === "object") {
|
|
950
|
-
for (const [key, value] of Object.entries(nested)) {
|
|
951
|
-
if (typeof value === "number") rewards[key] = value;
|
|
952
|
-
}
|
|
953
|
-
}
|
|
954
|
-
for (const [key, value] of Object.entries(record)) {
|
|
955
|
-
if (key !== "reward" && typeof value === "number") rewards[key] = value;
|
|
956
|
-
}
|
|
1467
|
+
const verifiers = verifierGrades(record.verifiers);
|
|
957
1468
|
return {
|
|
958
|
-
|
|
959
|
-
|
|
1469
|
+
...numericGrade(record),
|
|
1470
|
+
...typeof record.reason === "string" ? { reason: record.reason } : {},
|
|
1471
|
+
...verifiers ? { verifiers } : {},
|
|
960
1472
|
raw
|
|
961
1473
|
};
|
|
962
1474
|
}
|
|
@@ -1063,6 +1575,46 @@ var init_session = __esm({
|
|
|
1063
1575
|
);
|
|
1064
1576
|
}
|
|
1065
1577
|
};
|
|
1578
|
+
OPEN_SESSION_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
1579
|
+
"task",
|
|
1580
|
+
"versionId",
|
|
1581
|
+
"reuseWarm",
|
|
1582
|
+
"surfaces",
|
|
1583
|
+
"browserTier",
|
|
1584
|
+
"options"
|
|
1585
|
+
]);
|
|
1586
|
+
isOpenSessionOptions = (value) => typeof value === "object" && value !== null && Object.keys(value).every((key) => OPEN_SESSION_OPTION_KEYS.has(key));
|
|
1587
|
+
}
|
|
1588
|
+
});
|
|
1589
|
+
|
|
1590
|
+
// src/worlds/sessionList.ts
|
|
1591
|
+
async function listSessions(filter = {}, options = {}) {
|
|
1592
|
+
const params = new URLSearchParams();
|
|
1593
|
+
if (filter.state) params.set("state", filter.state);
|
|
1594
|
+
if (filter.slug) params.set("slug", filter.slug);
|
|
1595
|
+
if (filter.limit !== void 0) params.set("limit", String(filter.limit));
|
|
1596
|
+
const qs = params.toString();
|
|
1597
|
+
const res = await apiRequest(
|
|
1598
|
+
options,
|
|
1599
|
+
"GET",
|
|
1600
|
+
`/api/public/world-sessions${qs ? `?${qs}` : ""}`
|
|
1601
|
+
);
|
|
1602
|
+
return res.sessions;
|
|
1603
|
+
}
|
|
1604
|
+
var SESSION_STATES;
|
|
1605
|
+
var init_sessionList = __esm({
|
|
1606
|
+
"src/worlds/sessionList.ts"() {
|
|
1607
|
+
"use strict";
|
|
1608
|
+
init_worlds();
|
|
1609
|
+
SESSION_STATES = [
|
|
1610
|
+
"PROVISIONING",
|
|
1611
|
+
"RUNNING",
|
|
1612
|
+
"IDLE",
|
|
1613
|
+
"STOPPING",
|
|
1614
|
+
"STOPPED",
|
|
1615
|
+
"FAILED",
|
|
1616
|
+
"LOST"
|
|
1617
|
+
];
|
|
1066
1618
|
}
|
|
1067
1619
|
});
|
|
1068
1620
|
|
|
@@ -1148,16 +1700,23 @@ function aggregateTaskGrade(worlds) {
|
|
|
1148
1700
|
const rewards = {};
|
|
1149
1701
|
const ungraded = [];
|
|
1150
1702
|
const graded = [];
|
|
1151
|
-
|
|
1703
|
+
const verifiers = {};
|
|
1704
|
+
const fold = (key, grade) => {
|
|
1152
1705
|
if (typeof grade.reward === "number") {
|
|
1153
|
-
rewards[
|
|
1706
|
+
rewards[key] = grade.reward;
|
|
1154
1707
|
graded.push(grade.reward);
|
|
1155
|
-
} else ungraded.push(
|
|
1156
|
-
for (const [
|
|
1157
|
-
rewards[`${
|
|
1708
|
+
} else ungraded.push(key);
|
|
1709
|
+
for (const [name, value] of Object.entries(grade.rewards))
|
|
1710
|
+
rewards[`${key}.${name}`] = value;
|
|
1711
|
+
};
|
|
1712
|
+
for (const [alias, grade] of Object.entries(worlds)) {
|
|
1713
|
+
fold(alias, grade);
|
|
1714
|
+
Object.assign(verifiers, grade.verifiers ?? {});
|
|
1158
1715
|
}
|
|
1716
|
+
for (const [name, grade] of Object.entries(verifiers))
|
|
1717
|
+
fold(`${VERIFIER_REWARD_PREFIX}${name}`, grade);
|
|
1159
1718
|
const reward = graded.length > 0 ? graded.reduce((a, b) => a + b, 0) / graded.length : null;
|
|
1160
|
-
return { reward, rewards, worlds, ungraded };
|
|
1719
|
+
return { reward, rewards, worlds, ungraded, verifiers };
|
|
1161
1720
|
}
|
|
1162
1721
|
function fromResponse(answer, options) {
|
|
1163
1722
|
const sessions = {};
|
|
@@ -1190,6 +1749,7 @@ async function openTask(ref, opts = {}) {
|
|
|
1190
1749
|
throw new Error(
|
|
1191
1750
|
"openTask needs a spec that names its worlds; a single-world spec opens with openSession"
|
|
1192
1751
|
);
|
|
1752
|
+
if (opts.browserTier !== void 0) assertBrowserTier(opts.browserTier);
|
|
1193
1753
|
const answer = await apiRequest(
|
|
1194
1754
|
options,
|
|
1195
1755
|
"POST",
|
|
@@ -1197,7 +1757,8 @@ async function openTask(ref, opts = {}) {
|
|
|
1197
1757
|
{
|
|
1198
1758
|
task,
|
|
1199
1759
|
...opts.reuseWarm === void 0 ? {} : { reuseWarm: opts.reuseWarm },
|
|
1200
|
-
...opts.surfaces?.length ? { surfaces: opts.surfaces } : {}
|
|
1760
|
+
...opts.surfaces?.length ? { surfaces: opts.surfaces } : {},
|
|
1761
|
+
...opts.browserTier === void 0 ? {} : { browserTier: opts.browserTier }
|
|
1201
1762
|
}
|
|
1202
1763
|
);
|
|
1203
1764
|
return fromResponse(answer, options);
|
|
@@ -1273,7 +1834,7 @@ async function attachManifest(manifest, options = {}) {
|
|
|
1273
1834
|
function isTaskManifest(value) {
|
|
1274
1835
|
return typeof value === "object" && value !== null && !Array.isArray(value) && typeof value.sessions === "object" && value.sessions !== null && !("instruction" in value && "worlds" in value);
|
|
1275
1836
|
}
|
|
1276
|
-
var TASK_SESSIONS, manifestSession, TaskSessions;
|
|
1837
|
+
var TASK_SESSIONS, VERIFIER_REWARD_PREFIX, manifestSession, TaskSessions;
|
|
1277
1838
|
var init_taskSessions = __esm({
|
|
1278
1839
|
"src/worlds/taskSessions.ts"() {
|
|
1279
1840
|
"use strict";
|
|
@@ -1281,6 +1842,7 @@ var init_taskSessions = __esm({
|
|
|
1281
1842
|
init_browser();
|
|
1282
1843
|
init_session();
|
|
1283
1844
|
TASK_SESSIONS = "/api/public/world-task-sessions";
|
|
1845
|
+
VERIFIER_REWARD_PREFIX = "x.";
|
|
1284
1846
|
manifestSession = (s, state2, world) => ({
|
|
1285
1847
|
slug: world.slug,
|
|
1286
1848
|
ref: world.ref,
|
|
@@ -1311,6 +1873,13 @@ var init_taskSessions = __esm({
|
|
|
1311
1873
|
this.worlds = worlds;
|
|
1312
1874
|
this.hash = hash;
|
|
1313
1875
|
}
|
|
1876
|
+
taskId;
|
|
1877
|
+
taskVersion;
|
|
1878
|
+
name;
|
|
1879
|
+
instruction;
|
|
1880
|
+
sessions;
|
|
1881
|
+
worlds;
|
|
1882
|
+
hash;
|
|
1314
1883
|
/** This alias's `{slug, ref}` as recorded at open/attach — the world a
|
|
1315
1884
|
* `TaskRun` filing needs to name, without exposing the whole map. */
|
|
1316
1885
|
worldRef(alias) {
|
|
@@ -1370,10 +1939,20 @@ var init_taskSessions = __esm({
|
|
|
1370
1939
|
}
|
|
1371
1940
|
/** Grade every world and aggregate — see `TaskGrade`. One `report` (the
|
|
1372
1941
|
* agent's own account of the whole investigation) goes to every world's
|
|
1373
|
-
* judge; a world graded by assertions or python ignores it.
|
|
1942
|
+
* judge; a world graded by assertions or python ignores it. Each grade
|
|
1943
|
+
* names the task's other sessions by alias, so the cross-world verifiers
|
|
1944
|
+
* anchored on that world can read them. */
|
|
1374
1945
|
async grade(opts = {}) {
|
|
1375
1946
|
return aggregateTaskGrade(
|
|
1376
|
-
await this.each(
|
|
1947
|
+
await this.each(
|
|
1948
|
+
(session, alias) => session.grade({ ...opts, worlds: this.otherSessions(alias) })
|
|
1949
|
+
)
|
|
1950
|
+
);
|
|
1951
|
+
}
|
|
1952
|
+
/** The task's other sessions by alias: what a grade names. */
|
|
1953
|
+
otherSessions(alias) {
|
|
1954
|
+
return Object.fromEntries(
|
|
1955
|
+
Object.entries(this.sessions).filter(([other]) => other !== alias).map(([other, session]) => [other, session.sessionId])
|
|
1377
1956
|
);
|
|
1378
1957
|
}
|
|
1379
1958
|
/** Every world's call log, keyed by alias. */
|
|
@@ -1419,10 +1998,11 @@ var init_evals = __esm({
|
|
|
1419
1998
|
constructor(options = {}) {
|
|
1420
1999
|
this.options = options;
|
|
1421
2000
|
}
|
|
1422
|
-
|
|
2001
|
+
options;
|
|
1423
2002
|
async createEvaluation(versionId, opts = {}) {
|
|
1424
2003
|
const body = { versionId };
|
|
1425
2004
|
if (opts.model !== void 0) body.model = opts.model;
|
|
2005
|
+
if (opts.runId !== void 0) body.runId = opts.runId;
|
|
1426
2006
|
if (opts.rolloutsPerExample !== void 0)
|
|
1427
2007
|
body.rolloutsPerExample = opts.rolloutsPerExample;
|
|
1428
2008
|
if (opts.metadata !== void 0) body.metadata = opts.metadata;
|
|
@@ -1434,7 +2014,6 @@ var init_evals = __esm({
|
|
|
1434
2014
|
);
|
|
1435
2015
|
return answer.evaluationId;
|
|
1436
2016
|
}
|
|
1437
|
-
/** Push one batch of samples; returns how many the platform inserted. */
|
|
1438
2017
|
async pushSamples(evaluationId, samples) {
|
|
1439
2018
|
const answer = await apiRequest(
|
|
1440
2019
|
this.options,
|
|
@@ -1444,7 +2023,6 @@ var init_evals = __esm({
|
|
|
1444
2023
|
);
|
|
1445
2024
|
return answer.inserted ?? samples.length;
|
|
1446
2025
|
}
|
|
1447
|
-
/** Close the evaluation out; returns its final status. */
|
|
1448
2026
|
async finalizeEvaluation(evaluationId, opts = {}) {
|
|
1449
2027
|
const body = {
|
|
1450
2028
|
status: opts.status ?? "COMPLETED"
|
|
@@ -1624,10 +2202,10 @@ var init_users = __esm({
|
|
|
1624
2202
|
totalItems: Number(meta.totalItems ?? rows.length)
|
|
1625
2203
|
};
|
|
1626
2204
|
}
|
|
1627
|
-
async requestJson(method,
|
|
2205
|
+
async requestJson(method, path12, payload) {
|
|
1628
2206
|
let response;
|
|
1629
2207
|
try {
|
|
1630
|
-
response = await fetch(`${this.host}${
|
|
2208
|
+
response = await fetch(`${this.host}${path12}`, {
|
|
1631
2209
|
method,
|
|
1632
2210
|
headers: {
|
|
1633
2211
|
Authorization: this.authHeader(),
|
|
@@ -1638,17 +2216,17 @@ var init_users = __esm({
|
|
|
1638
2216
|
});
|
|
1639
2217
|
} catch (error) {
|
|
1640
2218
|
throw new UserProfileError(
|
|
1641
|
-
`${method} ${
|
|
2219
|
+
`${method} ${path12} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
1642
2220
|
{ cause: error }
|
|
1643
2221
|
);
|
|
1644
2222
|
}
|
|
1645
2223
|
const text2 = await response.text();
|
|
1646
2224
|
if (!response.ok) {
|
|
1647
2225
|
throw new UserProfileError(
|
|
1648
|
-
`${method} ${
|
|
2226
|
+
`${method} ${path12} failed (${response.status}): ${text2.slice(0, 500)}`
|
|
1649
2227
|
);
|
|
1650
2228
|
}
|
|
1651
|
-
this.log("%s %s -> %s", method,
|
|
2229
|
+
this.log("%s %s -> %s", method, path12, response.status);
|
|
1652
2230
|
return safeJson(text2);
|
|
1653
2231
|
}
|
|
1654
2232
|
authHeader() {
|
|
@@ -1713,9 +2291,9 @@ function getAmbientSessionId() {
|
|
|
1713
2291
|
return currentSessionStorage.getStore();
|
|
1714
2292
|
}
|
|
1715
2293
|
function withSession(sessionId, fn) {
|
|
1716
|
-
return new Promise((
|
|
2294
|
+
return new Promise((resolve7, reject) => {
|
|
1717
2295
|
currentSessionStorage.run(sessionId, () => {
|
|
1718
|
-
Promise.resolve().then(fn).then(
|
|
2296
|
+
Promise.resolve().then(fn).then(resolve7, reject);
|
|
1719
2297
|
});
|
|
1720
2298
|
});
|
|
1721
2299
|
}
|
|
@@ -1912,10 +2490,10 @@ var init_scores = __esm({
|
|
|
1912
2490
|
metadata: signalMetadata
|
|
1913
2491
|
});
|
|
1914
2492
|
}
|
|
1915
|
-
async request(method,
|
|
2493
|
+
async request(method, path12, payload) {
|
|
1916
2494
|
let response;
|
|
1917
2495
|
try {
|
|
1918
|
-
response = await fetch(`${this.host}${
|
|
2496
|
+
response = await fetch(`${this.host}${path12}`, {
|
|
1919
2497
|
method,
|
|
1920
2498
|
headers: {
|
|
1921
2499
|
Authorization: this.authHeader(),
|
|
@@ -1926,17 +2504,17 @@ var init_scores = __esm({
|
|
|
1926
2504
|
});
|
|
1927
2505
|
} catch (error) {
|
|
1928
2506
|
throw new ScoreError(
|
|
1929
|
-
`${method} ${
|
|
2507
|
+
`${method} ${path12} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
1930
2508
|
{ cause: error }
|
|
1931
2509
|
);
|
|
1932
2510
|
}
|
|
1933
2511
|
const text2 = await response.text();
|
|
1934
2512
|
if (!response.ok) {
|
|
1935
2513
|
throw new ScoreError(
|
|
1936
|
-
`${method} ${
|
|
2514
|
+
`${method} ${path12} failed (${response.status}): ${text2.slice(0, 500)}`
|
|
1937
2515
|
);
|
|
1938
2516
|
}
|
|
1939
|
-
this.log("%s %s -> %s", method,
|
|
2517
|
+
this.log("%s %s -> %s", method, path12, response.status);
|
|
1940
2518
|
}
|
|
1941
2519
|
authHeader() {
|
|
1942
2520
|
return `Basic ${Buffer.from(`${this.publicKey}:${this.secretKey}`).toString(
|
|
@@ -1964,7 +2542,7 @@ var require_package = __commonJS({
|
|
|
1964
2542
|
"package.json"(exports2, module2) {
|
|
1965
2543
|
module2.exports = {
|
|
1966
2544
|
name: "@withgateway/sdk",
|
|
1967
|
-
version: "0.2.
|
|
2545
|
+
version: "0.2.9",
|
|
1968
2546
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
1969
2547
|
main: "./dist/index.js",
|
|
1970
2548
|
module: "./dist/index.mjs",
|
|
@@ -2119,16 +2697,16 @@ var require_package = __commonJS({
|
|
|
2119
2697
|
}
|
|
2120
2698
|
},
|
|
2121
2699
|
optionalDependencies: {
|
|
2122
|
-
"@arizeai/openinference-instrumentation-anthropic": "^0.
|
|
2123
|
-
"@arizeai/openinference-instrumentation-openai": "^4.
|
|
2700
|
+
"@arizeai/openinference-instrumentation-anthropic": "^0.2.8",
|
|
2701
|
+
"@arizeai/openinference-instrumentation-openai": "^4.2.7"
|
|
2124
2702
|
},
|
|
2125
2703
|
devDependencies: {
|
|
2126
|
-
"@anthropic-ai/sdk": "^0.
|
|
2704
|
+
"@anthropic-ai/sdk": "^0.91.1",
|
|
2127
2705
|
"@opentelemetry/api": "^1.9.0",
|
|
2128
|
-
"@opentelemetry/exporter-trace-otlp-http": "^0.
|
|
2129
|
-
"@opentelemetry/resources": "^2.
|
|
2130
|
-
"@opentelemetry/sdk-trace-base": "^
|
|
2131
|
-
"@opentelemetry/sdk-trace-node": "^2.
|
|
2706
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.222.0",
|
|
2707
|
+
"@opentelemetry/resources": "^2.11.0",
|
|
2708
|
+
"@opentelemetry/sdk-trace-base": "^2.11.0",
|
|
2709
|
+
"@opentelemetry/sdk-trace-node": "^2.11.0",
|
|
2132
2710
|
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
2133
2711
|
"@types/node": "^20.0.0",
|
|
2134
2712
|
openai: "^4.70.0",
|
|
@@ -2141,7 +2719,9 @@ var require_package = __commonJS({
|
|
|
2141
2719
|
protobufjs: "^8.4.1",
|
|
2142
2720
|
"vite@6": "^6.4.3",
|
|
2143
2721
|
postcss: "^8.5.18",
|
|
2144
|
-
"picomatch@4": "^4.0.4"
|
|
2722
|
+
"picomatch@4": "^4.0.4",
|
|
2723
|
+
nanoid: ">=3.3.18",
|
|
2724
|
+
esbuild: ">=0.28.1"
|
|
2145
2725
|
},
|
|
2146
2726
|
pnpm: {
|
|
2147
2727
|
overrides: {
|
|
@@ -2149,7 +2729,9 @@ var require_package = __commonJS({
|
|
|
2149
2729
|
vitest: "^3.2.6",
|
|
2150
2730
|
"vite@6": "^6.4.3",
|
|
2151
2731
|
postcss: "^8.5.18",
|
|
2152
|
-
"picomatch@4": "^4.0.4"
|
|
2732
|
+
"picomatch@4": "^4.0.4",
|
|
2733
|
+
nanoid: ">=3.3.18",
|
|
2734
|
+
esbuild: ">=0.28.1"
|
|
2153
2735
|
}
|
|
2154
2736
|
},
|
|
2155
2737
|
bin: {
|
|
@@ -2665,7 +3247,7 @@ function worldRef(live, alias) {
|
|
|
2665
3247
|
sessionId: session.sessionId
|
|
2666
3248
|
};
|
|
2667
3249
|
}
|
|
2668
|
-
async function fileTaskRun(live, runId, model, report, grade, agentError, traced, runDir, options) {
|
|
3250
|
+
async function fileTaskRun(live, runId, model, report, grade, agentError, traced, runDir, options, setRunId) {
|
|
2669
3251
|
const aliases = live.aliases;
|
|
2670
3252
|
const anchor = aliases[0];
|
|
2671
3253
|
const worldsMeta = Object.fromEntries(
|
|
@@ -2677,6 +3259,7 @@ async function fileTaskRun(live, runId, model, report, grade, agentError, traced
|
|
|
2677
3259
|
{
|
|
2678
3260
|
model,
|
|
2679
3261
|
rolloutsPerExample: 1,
|
|
3262
|
+
...setRunId ? { runId: setRunId } : {},
|
|
2680
3263
|
metadata: {
|
|
2681
3264
|
source: "worlds-task-run",
|
|
2682
3265
|
task: {
|
|
@@ -2759,6 +3342,7 @@ async function runTask(ref, agent, opts) {
|
|
|
2759
3342
|
const live = await openTask(ref, {
|
|
2760
3343
|
surfaces: opts.surfaces,
|
|
2761
3344
|
reuseWarm: opts.reuseWarm,
|
|
3345
|
+
browserTier: opts.browserTier,
|
|
2762
3346
|
options
|
|
2763
3347
|
});
|
|
2764
3348
|
const started = Date.now();
|
|
@@ -2794,6 +3378,8 @@ async function runTask(ref, agent, opts) {
|
|
|
2794
3378
|
const message = (error instanceof Error ? error.message : String(error)) || "Unknown error";
|
|
2795
3379
|
agentError = message.slice(0, 2e3);
|
|
2796
3380
|
}
|
|
3381
|
+
if (traced)
|
|
3382
|
+
await Promise.resolve().then(() => (init_init(), init_exports)).then((tracing) => tracing.flush()).catch(() => void 0);
|
|
2797
3383
|
const grade = report !== null ? await live.grade({ report }) : await live.grade();
|
|
2798
3384
|
fs.writeFileSync(
|
|
2799
3385
|
path.join(runDir, "manifest.json"),
|
|
@@ -2834,7 +3420,8 @@ async function runTask(ref, agent, opts) {
|
|
|
2834
3420
|
agentError,
|
|
2835
3421
|
traced,
|
|
2836
3422
|
runDir,
|
|
2837
|
-
options
|
|
3423
|
+
options,
|
|
3424
|
+
opts.setRunId
|
|
2838
3425
|
);
|
|
2839
3426
|
summary.filed = true;
|
|
2840
3427
|
}
|
|
@@ -2871,8 +3458,12 @@ var init_taskRun = __esm({
|
|
|
2871
3458
|
this.sessions = sessions;
|
|
2872
3459
|
this.manifest = manifest;
|
|
2873
3460
|
}
|
|
3461
|
+
runId;
|
|
3462
|
+
instruction;
|
|
3463
|
+
model;
|
|
3464
|
+
sessions;
|
|
3465
|
+
manifest;
|
|
2874
3466
|
notes = {};
|
|
2875
|
-
/** The alias's session, or a clear error naming the aliases there are. */
|
|
2876
3467
|
session(alias) {
|
|
2877
3468
|
const session = this.sessions[alias];
|
|
2878
3469
|
if (!session)
|
|
@@ -2881,8 +3472,7 @@ var init_taskRun = __esm({
|
|
|
2881
3472
|
);
|
|
2882
3473
|
return session;
|
|
2883
3474
|
}
|
|
2884
|
-
/**
|
|
2885
|
-
* when it was not opened with `surfaces: ["api"]`. */
|
|
3475
|
+
/** Raises when the session was not opened with `surfaces: ["api"]`. */
|
|
2886
3476
|
async api(alias) {
|
|
2887
3477
|
const surfaces = await this.session(alias).surfaces();
|
|
2888
3478
|
if (!surfaces.api)
|
|
@@ -2892,10 +3482,7 @@ var init_taskRun = __esm({
|
|
|
2892
3482
|
);
|
|
2893
3483
|
return { url: surfaces.api.url, token: surfaces.api.token };
|
|
2894
3484
|
}
|
|
2895
|
-
/**
|
|
2896
|
-
* `<alias>.<tool>` so a model can tell which world a call goes to. A
|
|
2897
|
-
* world that exposes no tools contributes nothing — there is nothing to
|
|
2898
|
-
* merge. */
|
|
3485
|
+
/** Each tool is prefixed `<alias>.<tool>` so a model can tell which world a call goes to. */
|
|
2899
3486
|
async toolkit() {
|
|
2900
3487
|
const schemas = [];
|
|
2901
3488
|
const impls = {};
|
|
@@ -2920,8 +3507,7 @@ var init_taskRun = __esm({
|
|
|
2920
3507
|
}
|
|
2921
3508
|
return { schemas, impls, specs };
|
|
2922
3509
|
}
|
|
2923
|
-
/**
|
|
2924
|
-
* overrides a key an earlier one set). */
|
|
3510
|
+
/** Merged into `run.json` under `notes`; a later call overrides an earlier key. */
|
|
2925
3511
|
record(notes) {
|
|
2926
3512
|
Object.assign(this.notes, notes);
|
|
2927
3513
|
}
|
|
@@ -2931,23 +3517,263 @@ var init_taskRun = __esm({
|
|
|
2931
3517
|
}
|
|
2932
3518
|
});
|
|
2933
3519
|
|
|
3520
|
+
// src/worlds/checkoutProvenance.ts
|
|
3521
|
+
var import_node_child_process, CheckoutProvenance;
|
|
3522
|
+
var init_checkoutProvenance = __esm({
|
|
3523
|
+
"src/worlds/checkoutProvenance.ts"() {
|
|
3524
|
+
"use strict";
|
|
3525
|
+
import_node_child_process = require("child_process");
|
|
3526
|
+
CheckoutProvenance = class _CheckoutProvenance {
|
|
3527
|
+
constructor(cwd, env) {
|
|
3528
|
+
this.cwd = cwd;
|
|
3529
|
+
this.env = env;
|
|
3530
|
+
}
|
|
3531
|
+
cwd;
|
|
3532
|
+
env;
|
|
3533
|
+
static read(cwd = process.cwd(), env = process.env) {
|
|
3534
|
+
return new _CheckoutProvenance(cwd, env).checkout();
|
|
3535
|
+
}
|
|
3536
|
+
checkout() {
|
|
3537
|
+
const commit = this.git("rev-parse", "HEAD");
|
|
3538
|
+
if (!commit) return this.withPr({});
|
|
3539
|
+
const branch = this.env.GITHUB_HEAD_REF || this.git("rev-parse", "--abbrev-ref", "HEAD");
|
|
3540
|
+
const remote = this.git("config", "--get", "remote.origin.url");
|
|
3541
|
+
return this.withPr({
|
|
3542
|
+
commit,
|
|
3543
|
+
...branch && branch !== "HEAD" ? { branch } : {},
|
|
3544
|
+
...remote ? { repoUrl: _CheckoutProvenance.withoutCredentials(remote) } : {}
|
|
3545
|
+
});
|
|
3546
|
+
}
|
|
3547
|
+
/** Security: credentials are stripped; scp-style `git@host:org/repo` has none and is kept. */
|
|
3548
|
+
static withoutCredentials(url) {
|
|
3549
|
+
return url.replace(/^([a-z][a-z0-9+.-]*:\/\/)[^@/]+@/i, "$1");
|
|
3550
|
+
}
|
|
3551
|
+
withPr(checkout) {
|
|
3552
|
+
const pr = this.pullRequest();
|
|
3553
|
+
return pr ? { ...checkout, pr } : checkout;
|
|
3554
|
+
}
|
|
3555
|
+
pullRequest() {
|
|
3556
|
+
const url = this.env.GATEWAY_PR_URL;
|
|
3557
|
+
const fromUrl = url ? /\/pull\/(\d+)/.exec(url)?.[1] : void 0;
|
|
3558
|
+
if (url && fromUrl)
|
|
3559
|
+
return {
|
|
3560
|
+
number: Number(fromUrl),
|
|
3561
|
+
url,
|
|
3562
|
+
...this.env.GATEWAY_PR_TITLE ? { title: this.env.GATEWAY_PR_TITLE } : {}
|
|
3563
|
+
};
|
|
3564
|
+
const number = /^refs\/pull\/(\d+)\//.exec(this.env.GITHUB_REF ?? "")?.[1];
|
|
3565
|
+
const server = this.env.GITHUB_SERVER_URL;
|
|
3566
|
+
const repo = this.env.GITHUB_REPOSITORY;
|
|
3567
|
+
if (!number || !server || !repo) return void 0;
|
|
3568
|
+
return { number: Number(number), url: `${server}/${repo}/pull/${number}` };
|
|
3569
|
+
}
|
|
3570
|
+
git(...args) {
|
|
3571
|
+
try {
|
|
3572
|
+
const out = (0, import_node_child_process.execFileSync)("git", args, {
|
|
3573
|
+
cwd: this.cwd,
|
|
3574
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
3575
|
+
timeout: 5e3
|
|
3576
|
+
}).toString().trim();
|
|
3577
|
+
return out || void 0;
|
|
3578
|
+
} catch {
|
|
3579
|
+
return void 0;
|
|
3580
|
+
}
|
|
3581
|
+
}
|
|
3582
|
+
};
|
|
3583
|
+
}
|
|
3584
|
+
});
|
|
3585
|
+
|
|
3586
|
+
// src/worlds/setRun.ts
|
|
3587
|
+
async function runSet(datasetId, agent, opts) {
|
|
3588
|
+
const options = opts.options ?? {};
|
|
3589
|
+
const git = opts.git === void 0 ? CheckoutProvenance.read() : opts.git;
|
|
3590
|
+
const opened = await apiRequest(options, "POST", SET_RUNS, {
|
|
3591
|
+
datasetId,
|
|
3592
|
+
model: opts.model,
|
|
3593
|
+
source: opts.source ?? "sdk",
|
|
3594
|
+
...git && Object.keys(git).length ? { git } : {}
|
|
3595
|
+
});
|
|
3596
|
+
const close = (status) => apiRequest(
|
|
3597
|
+
options,
|
|
3598
|
+
"POST",
|
|
3599
|
+
`${SET_RUNS}/${encodeURIComponent(opened.id)}/close`,
|
|
3600
|
+
{ status }
|
|
3601
|
+
);
|
|
3602
|
+
const onInterrupt = () => {
|
|
3603
|
+
void close("failed").finally(() => process.exit(130));
|
|
3604
|
+
};
|
|
3605
|
+
process.once("SIGINT", onInterrupt);
|
|
3606
|
+
const planned = await runPlannedTasks(opened, agent, opts, options).finally(
|
|
3607
|
+
() => process.off("SIGINT", onInterrupt)
|
|
3608
|
+
);
|
|
3609
|
+
const { tasks, failed } = planned;
|
|
3610
|
+
const requested = failed ? "failed" : "completed";
|
|
3611
|
+
const setRun = await close(requested);
|
|
3612
|
+
return {
|
|
3613
|
+
setRun,
|
|
3614
|
+
tasks,
|
|
3615
|
+
failed: failed || setRun.status !== "completed",
|
|
3616
|
+
closedAsRequested: setRun.status === requested
|
|
3617
|
+
};
|
|
3618
|
+
}
|
|
3619
|
+
async function runPlannedTasks(opened, agent, opts, options) {
|
|
3620
|
+
const tasks = [];
|
|
3621
|
+
let failed = false;
|
|
3622
|
+
for (const task of opened.tasks) {
|
|
3623
|
+
try {
|
|
3624
|
+
const summary = await runTask(task.worldTaskId, agent, {
|
|
3625
|
+
model: opts.model,
|
|
3626
|
+
surfaces: opts.surfaces,
|
|
3627
|
+
browserTier: opts.browserTier,
|
|
3628
|
+
outDir: opts.outDir,
|
|
3629
|
+
trace: opts.trace,
|
|
3630
|
+
setRunId: opened.id,
|
|
3631
|
+
options
|
|
3632
|
+
});
|
|
3633
|
+
tasks.push(summary);
|
|
3634
|
+
failed ||= summary.agentError !== null;
|
|
3635
|
+
opts.onTask?.(summary);
|
|
3636
|
+
} catch (error) {
|
|
3637
|
+
failed = true;
|
|
3638
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3639
|
+
process.stderr.write(`task ${task.name} could not run: ${message}
|
|
3640
|
+
`);
|
|
3641
|
+
}
|
|
3642
|
+
}
|
|
3643
|
+
return { tasks, failed };
|
|
3644
|
+
}
|
|
3645
|
+
var SET_RUNS;
|
|
3646
|
+
var init_setRun = __esm({
|
|
3647
|
+
"src/worlds/setRun.ts"() {
|
|
3648
|
+
"use strict";
|
|
3649
|
+
init_worlds();
|
|
3650
|
+
init_checkoutProvenance();
|
|
3651
|
+
init_taskRun();
|
|
3652
|
+
SET_RUNS = "/api/public/set-runs";
|
|
3653
|
+
}
|
|
3654
|
+
});
|
|
3655
|
+
|
|
3656
|
+
// src/worlds/checkoutTarget.ts
|
|
3657
|
+
var fs2, path2, CheckoutRefusedError, NAMED_EDITS, CheckoutTarget;
|
|
3658
|
+
var init_checkoutTarget = __esm({
|
|
3659
|
+
"src/worlds/checkoutTarget.ts"() {
|
|
3660
|
+
"use strict";
|
|
3661
|
+
fs2 = __toESM(require("fs"));
|
|
3662
|
+
path2 = __toESM(require("path"));
|
|
3663
|
+
CheckoutRefusedError = class extends Error {
|
|
3664
|
+
constructor(message) {
|
|
3665
|
+
super(`checkout refused: ${message}`);
|
|
3666
|
+
this.name = "CheckoutRefusedError";
|
|
3667
|
+
}
|
|
3668
|
+
};
|
|
3669
|
+
NAMED_EDITS = 3;
|
|
3670
|
+
CheckoutTarget = class _CheckoutTarget {
|
|
3671
|
+
constructor(dir, replaces) {
|
|
3672
|
+
this.dir = dir;
|
|
3673
|
+
this.replaces = replaces;
|
|
3674
|
+
}
|
|
3675
|
+
dir;
|
|
3676
|
+
replaces;
|
|
3677
|
+
static resolve(slug, target, opts) {
|
|
3678
|
+
if (target === void 0) return _CheckoutTarget.fresh(slug, opts.cwd);
|
|
3679
|
+
return _CheckoutTarget.explicit(
|
|
3680
|
+
_CheckoutTarget.confined(target, opts.cwd),
|
|
3681
|
+
slug,
|
|
3682
|
+
opts
|
|
3683
|
+
);
|
|
3684
|
+
}
|
|
3685
|
+
/** The absolute destination; a relative target may not resolve above `cwd`. */
|
|
3686
|
+
static confined(target, cwd) {
|
|
3687
|
+
const dir = path2.resolve(cwd, target);
|
|
3688
|
+
if (path2.isAbsolute(target)) return dir;
|
|
3689
|
+
const rel = path2.relative(cwd, dir);
|
|
3690
|
+
if (rel === "" || !rel.startsWith("..") && !path2.isAbsolute(rel))
|
|
3691
|
+
return dir;
|
|
3692
|
+
throw new CheckoutRefusedError(
|
|
3693
|
+
`--target ${target} resolves outside the current directory (${cwd}) \u2014 run from that directory, or pass an absolute path`
|
|
3694
|
+
);
|
|
3695
|
+
}
|
|
3696
|
+
static fresh(slug, cwd) {
|
|
3697
|
+
const base = path2.join(cwd, slug);
|
|
3698
|
+
let dir = base;
|
|
3699
|
+
let i = 1;
|
|
3700
|
+
while (fs2.existsSync(dir)) dir = `${base}-${i++}`;
|
|
3701
|
+
return new _CheckoutTarget(dir, []);
|
|
3702
|
+
}
|
|
3703
|
+
static explicit(dir, slug, opts) {
|
|
3704
|
+
if (!fs2.existsSync(dir)) return new _CheckoutTarget(dir, []);
|
|
3705
|
+
if (!fs2.statSync(dir).isDirectory())
|
|
3706
|
+
throw new CheckoutRefusedError(`${dir} is a file`);
|
|
3707
|
+
if (fs2.readdirSync(dir).length === 0) return new _CheckoutTarget(dir, []);
|
|
3708
|
+
const state2 = opts.state(dir);
|
|
3709
|
+
const refusal = _CheckoutTarget.refusal(dir, slug, state2);
|
|
3710
|
+
if (refusal === null || opts.force)
|
|
3711
|
+
return new _CheckoutTarget(dir, _CheckoutTarget.tracked(state2));
|
|
3712
|
+
throw new CheckoutRefusedError(refusal);
|
|
3713
|
+
}
|
|
3714
|
+
/** Base files plus local edits — everything the archive would see in the old
|
|
3715
|
+
* checkout. `.env-metadata.json` is local input: a key that would leave the
|
|
3716
|
+
* checkout (`../x`, `/etc/x`) is dropped, never removed. */
|
|
3717
|
+
static tracked(state2) {
|
|
3718
|
+
if (!state2.meta?.baseFiles) return [];
|
|
3719
|
+
return [
|
|
3720
|
+
.../* @__PURE__ */ new Set([...Object.keys(state2.meta.baseFiles), ...state2.dirty])
|
|
3721
|
+
].filter(_CheckoutTarget.confinedRel).sort();
|
|
3722
|
+
}
|
|
3723
|
+
static confinedRel(rel) {
|
|
3724
|
+
if (rel === "" || path2.isAbsolute(rel)) return false;
|
|
3725
|
+
return !rel.split(/[\\/]/).includes("..");
|
|
3726
|
+
}
|
|
3727
|
+
/** Why `dir` cannot be overwritten, or null when it is a clean checkout of `slug`. */
|
|
3728
|
+
static refusal(dir, slug, state2) {
|
|
3729
|
+
if (!state2.meta?.baseFiles)
|
|
3730
|
+
return `${dir} is not empty and is not a checkout of "${slug}" \u2014 pick an empty --target, or pass --force to overwrite it`;
|
|
3731
|
+
if (state2.meta.slug !== void 0 && state2.meta.slug !== slug)
|
|
3732
|
+
return `${dir} tracks "${state2.meta.slug}", not "${slug}" \u2014 pick another --target, or pass --force to replace it`;
|
|
3733
|
+
if (state2.clean) return null;
|
|
3734
|
+
const n = state2.dirty.length;
|
|
3735
|
+
const named = state2.dirty.slice(0, NAMED_EDITS).join(", ");
|
|
3736
|
+
const more = n > NAMED_EDITS ? `, +${n - NAMED_EDITS} more` : "";
|
|
3737
|
+
return `${dir} has ${n} local edit${n === 1 ? "" : "s"} not pushed (${named}${more}) \u2014 push or propose them first, or pass --force to discard them`;
|
|
3738
|
+
}
|
|
3739
|
+
/** Remove the replaced checkout's files (and the dirs they leave empty). */
|
|
3740
|
+
clear() {
|
|
3741
|
+
for (const rel of this.replaces) {
|
|
3742
|
+
const abs = path2.join(this.dir, rel);
|
|
3743
|
+
fs2.rmSync(abs, { force: true });
|
|
3744
|
+
this.pruneEmptyParents(path2.dirname(abs));
|
|
3745
|
+
}
|
|
3746
|
+
}
|
|
3747
|
+
pruneEmptyParents(from) {
|
|
3748
|
+
let cur = from;
|
|
3749
|
+
while (cur !== this.dir && cur.startsWith(this.dir)) {
|
|
3750
|
+
if (fs2.existsSync(cur) && fs2.readdirSync(cur).length > 0) return;
|
|
3751
|
+
fs2.rmSync(cur, { recursive: true, force: true });
|
|
3752
|
+
cur = path2.dirname(cur);
|
|
3753
|
+
}
|
|
3754
|
+
}
|
|
3755
|
+
};
|
|
3756
|
+
}
|
|
3757
|
+
});
|
|
3758
|
+
|
|
2934
3759
|
// src/worlds/worldDir.ts
|
|
2935
|
-
var import_node_crypto4,
|
|
3760
|
+
var import_node_crypto4, fs3, path3, 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;
|
|
2936
3761
|
var init_worldDir = __esm({
|
|
2937
3762
|
"src/worlds/worldDir.ts"() {
|
|
2938
3763
|
"use strict";
|
|
2939
3764
|
import_node_crypto4 = require("crypto");
|
|
2940
|
-
|
|
2941
|
-
|
|
3765
|
+
fs3 = __toESM(require("fs"));
|
|
3766
|
+
path3 = __toESM(require("path"));
|
|
2942
3767
|
WORLD_MANIFEST = "gateway-env.toml";
|
|
2943
3768
|
API_BUNDLE_MANIFEST = "gateway-api-world.toml";
|
|
2944
3769
|
BUNDLED_WORLD_PREFIX = "server/world/";
|
|
2945
3770
|
CONNECTOR_SPEC = "connector.toml";
|
|
2946
3771
|
PYPROJECT = "pyproject.toml";
|
|
3772
|
+
BENCHMARK_CONFIG = "benchmark.json";
|
|
2947
3773
|
WORLD_SCHEMA_MARKERS = ["schema/world.json", "schema/runtime.json", "schema/lock.json"];
|
|
2948
3774
|
WORLD_ROOT_MARKERS = [CONNECTOR_SPEC, ...WORLD_SCHEMA_MARKERS];
|
|
2949
|
-
BROAD_ROOT_MARKERS = [WORLD_MANIFEST, API_BUNDLE_MANIFEST];
|
|
2950
|
-
SKIPPED_DIRS = /* @__PURE__ */ new Set(["dist", "build", "outputs", "__pycache__"]);
|
|
3775
|
+
BROAD_ROOT_MARKERS = [WORLD_MANIFEST, API_BUNDLE_MANIFEST, BENCHMARK_CONFIG];
|
|
3776
|
+
SKIPPED_DIRS = /* @__PURE__ */ new Set(["dist", "build", "outputs", "__pycache__", "node_modules"]);
|
|
2951
3777
|
V1_DEP = /["']verifiers\s*(?:\[[^\]]*\])?\s*(?:>=|~=|==|>)\s*(?:0\.(?:[2-9]\d*|[1-9]\d+)|[1-9]\d*)/;
|
|
2952
3778
|
V1_IMPORT = /^\s*(?:from\s+verifiers\.v1\s+import\b|from\s+verifiers\s+import\s+v1\b|import\s+verifiers\.v1\b)/m;
|
|
2953
3779
|
V1_TASKSET = /class\s+\w+\s*\(\s*(?:(?:vf|v1|verifiers(?:\.v1)?)\.)?Taskset\s*[,)]/;
|
|
@@ -2959,19 +3785,21 @@ var init_worldDir = __esm({
|
|
|
2959
3785
|
this.dir = dir;
|
|
2960
3786
|
this.worldRoot = worldRoot;
|
|
2961
3787
|
}
|
|
3788
|
+
dir;
|
|
3789
|
+
worldRoot;
|
|
2962
3790
|
pathsMemo;
|
|
2963
3791
|
static open(dir) {
|
|
2964
|
-
const present = (rel) =>
|
|
3792
|
+
const present = (rel) => fs3.existsSync(path3.join(dir, rel));
|
|
2965
3793
|
const bundled = present(API_BUNDLE_MANIFEST) && WORLD_ROOT_MARKERS.some((m) => present(BUNDLED_WORLD_PREFIX + m));
|
|
2966
3794
|
return new _WorldDir(dir, bundled ? BUNDLED_WORLD_PREFIX : "");
|
|
2967
3795
|
}
|
|
2968
3796
|
// ── Files ──────────────────────────────────────────────────────────────
|
|
2969
3797
|
has(rel) {
|
|
2970
|
-
return
|
|
3798
|
+
return fs3.existsSync(path3.join(this.dir, rel));
|
|
2971
3799
|
}
|
|
2972
3800
|
text(rel) {
|
|
2973
3801
|
try {
|
|
2974
|
-
return
|
|
3802
|
+
return fs3.readFileSync(path3.join(this.dir, rel), "utf-8");
|
|
2975
3803
|
} catch {
|
|
2976
3804
|
return null;
|
|
2977
3805
|
}
|
|
@@ -2981,20 +3809,21 @@ var init_worldDir = __esm({
|
|
|
2981
3809
|
return this.worldRoot + rel;
|
|
2982
3810
|
}
|
|
2983
3811
|
/** Every regular file the archive rules keep (`_archive.py`: no hidden,
|
|
2984
|
-
* dist, build, outputs, pycache or egg-info directories), as
|
|
2985
|
-
* relpaths. Root files enter only when a Gateway manifest
|
|
2986
|
-
* or they are README.md, pyproject.toml or
|
|
3812
|
+
* dist, build, outputs, pycache, node_modules or egg-info directories), as
|
|
3813
|
+
* sorted relpaths. Root files enter only when a Gateway manifest or
|
|
3814
|
+
* benchmark.json widens the root, or they are README.md, pyproject.toml or
|
|
3815
|
+
* Python. */
|
|
2987
3816
|
get archivePaths() {
|
|
2988
3817
|
if (this.pathsMemo) return this.pathsMemo;
|
|
2989
3818
|
const broad = BROAD_ROOT_MARKERS.some((m) => this.has(m));
|
|
2990
3819
|
const out = [];
|
|
2991
3820
|
const walk = (rel) => {
|
|
2992
|
-
for (const entry of
|
|
3821
|
+
for (const entry of fs3.readdirSync(rel ? path3.join(this.dir, rel) : this.dir, { withFileTypes: true })) {
|
|
2993
3822
|
const child = rel ? `${rel}/${entry.name}` : entry.name;
|
|
2994
3823
|
if (entry.isDirectory()) {
|
|
2995
3824
|
if (!skippedDir(entry.name)) walk(child);
|
|
2996
3825
|
} else if (entry.isFile() && !entry.name.startsWith(".")) {
|
|
2997
|
-
const rootKept = broad || ["README.md", PYPROJECT].includes(entry.name) || entry.name.endsWith(".py");
|
|
3826
|
+
const rootKept = broad || ["README.md", PYPROJECT, ...BROAD_ROOT_MARKERS].includes(entry.name) || entry.name.endsWith(".py");
|
|
2998
3827
|
if (rel || rootKept) out.push(child);
|
|
2999
3828
|
}
|
|
3000
3829
|
}
|
|
@@ -3002,10 +3831,37 @@ var init_worldDir = __esm({
|
|
|
3002
3831
|
walk("");
|
|
3003
3832
|
return this.pathsMemo = out.sort(byCodePoint);
|
|
3004
3833
|
}
|
|
3005
|
-
/**
|
|
3006
|
-
*
|
|
3007
|
-
|
|
3008
|
-
|
|
3834
|
+
/** What the archive rules leave out, collapsed to the entry that decided
|
|
3835
|
+
* it: a pruned directory counts its files once, a dropped root file is
|
|
3836
|
+
* named. Dot entries (`.git/`, `.gateway/`, `.gitignore`) are the one
|
|
3837
|
+
* universal convention and stay unreported. `push` prints the rest so
|
|
3838
|
+
* nothing disappears silently. */
|
|
3839
|
+
get exclusions() {
|
|
3840
|
+
const kept = new Set(this.archivePaths);
|
|
3841
|
+
const out = [];
|
|
3842
|
+
const filesUnder = (rel) => fs3.readdirSync(path3.join(this.dir, rel), { withFileTypes: true }).flatMap((entry) => {
|
|
3843
|
+
const child = `${rel}/${entry.name}`;
|
|
3844
|
+
if (entry.isDirectory()) return filesUnder(child);
|
|
3845
|
+
return entry.isFile() ? [child] : [];
|
|
3846
|
+
});
|
|
3847
|
+
for (const entry of fs3.readdirSync(this.dir, { withFileTypes: true }).sort((a, b) => byCodePoint(a.name, b.name))) {
|
|
3848
|
+
if (entry.name.startsWith(".")) continue;
|
|
3849
|
+
if (entry.isDirectory()) {
|
|
3850
|
+
const all = filesUnder(entry.name);
|
|
3851
|
+
const missing = all.filter((rel) => !kept.has(rel));
|
|
3852
|
+
if (missing.length === 0) continue;
|
|
3853
|
+
const whole = missing.length === all.length;
|
|
3854
|
+
out.push(...whole ? [{ path: `${entry.name}/`, files: missing.length }] : missing.map((p) => ({ path: p, files: 1 })));
|
|
3855
|
+
continue;
|
|
3856
|
+
}
|
|
3857
|
+
if (!kept.has(entry.name)) out.push({ path: entry.name, files: 1 });
|
|
3858
|
+
}
|
|
3859
|
+
return out;
|
|
3860
|
+
}
|
|
3861
|
+
/** A root `.gitignore` is present: the Python SDK honours it when
|
|
3862
|
+
* collecting, this package does not reimplement gitignore. */
|
|
3863
|
+
get hasRootGitignore() {
|
|
3864
|
+
return this.has(".gitignore");
|
|
3009
3865
|
}
|
|
3010
3866
|
/** SHA-256 over `utf8("file:" + relpath)` + bytes per archive path in
|
|
3011
3867
|
* sorted order: the version's identity, byte-compatible with
|
|
@@ -3014,7 +3870,7 @@ var init_worldDir = __esm({
|
|
|
3014
3870
|
const hasher = (0, import_node_crypto4.createHash)("sha256");
|
|
3015
3871
|
for (const rel of this.archivePaths) {
|
|
3016
3872
|
hasher.update(Buffer.from(`file:${rel}`, "utf-8"));
|
|
3017
|
-
hasher.update(
|
|
3873
|
+
hasher.update(fs3.readFileSync(path3.join(this.dir, rel)));
|
|
3018
3874
|
}
|
|
3019
3875
|
return hasher.digest("hex");
|
|
3020
3876
|
}
|
|
@@ -3077,14 +3933,121 @@ var init_worldDir = __esm({
|
|
|
3077
3933
|
}
|
|
3078
3934
|
});
|
|
3079
3935
|
|
|
3936
|
+
// src/worlds/tar.ts
|
|
3937
|
+
function archiveMode(mode) {
|
|
3938
|
+
return (mode & 73) !== 0 ? TAR_EXEC_MODE : TAR_FILE_MODE;
|
|
3939
|
+
}
|
|
3940
|
+
function field(header, start, end) {
|
|
3941
|
+
return header.subarray(start, end).toString("utf-8").replace(/\0.*$/, "");
|
|
3942
|
+
}
|
|
3943
|
+
function octalField(header, start, end) {
|
|
3944
|
+
return parseInt(field(header, start, end).trim(), 8);
|
|
3945
|
+
}
|
|
3946
|
+
function paxPath(body) {
|
|
3947
|
+
let off = 0;
|
|
3948
|
+
let found = null;
|
|
3949
|
+
while (off < body.length) {
|
|
3950
|
+
const sp = body.indexOf(32, off);
|
|
3951
|
+
if (sp === -1) break;
|
|
3952
|
+
const len = parseInt(body.subarray(off, sp).toString("ascii"), 10);
|
|
3953
|
+
if (!Number.isFinite(len) || len <= 0) break;
|
|
3954
|
+
const record = body.subarray(sp + 1, off + len);
|
|
3955
|
+
const eq = record.indexOf(61);
|
|
3956
|
+
const key = eq === -1 ? "" : record.subarray(0, eq).toString("utf-8");
|
|
3957
|
+
if (key === "path")
|
|
3958
|
+
found = record.subarray(eq + 1).toString("utf-8").replace(/\n$/, "");
|
|
3959
|
+
off += len;
|
|
3960
|
+
}
|
|
3961
|
+
return found;
|
|
3962
|
+
}
|
|
3963
|
+
var fs4, path4, import_node_zlib, TAR_FILE_MODE, TAR_EXEC_MODE, TarArchive;
|
|
3964
|
+
var init_tar = __esm({
|
|
3965
|
+
"src/worlds/tar.ts"() {
|
|
3966
|
+
"use strict";
|
|
3967
|
+
fs4 = __toESM(require("fs"));
|
|
3968
|
+
path4 = __toESM(require("path"));
|
|
3969
|
+
import_node_zlib = require("zlib");
|
|
3970
|
+
TAR_FILE_MODE = 420;
|
|
3971
|
+
TAR_EXEC_MODE = 493;
|
|
3972
|
+
TarArchive = class _TarArchive {
|
|
3973
|
+
constructor(tar) {
|
|
3974
|
+
this.tar = tar;
|
|
3975
|
+
}
|
|
3976
|
+
tar;
|
|
3977
|
+
static fromGzip(bundle) {
|
|
3978
|
+
return new _TarArchive((0, import_node_zlib.gunzipSync)(bundle));
|
|
3979
|
+
}
|
|
3980
|
+
static fromTar(tar) {
|
|
3981
|
+
return new _TarArchive(tar);
|
|
3982
|
+
}
|
|
3983
|
+
/** Every member, names fully resolved; metadata members are consumed. */
|
|
3984
|
+
*members() {
|
|
3985
|
+
const tar = this.tar;
|
|
3986
|
+
let offset = 0;
|
|
3987
|
+
let pendingName = null;
|
|
3988
|
+
while (offset + 512 <= tar.length) {
|
|
3989
|
+
const header = tar.subarray(offset, offset + 512);
|
|
3990
|
+
offset += 512;
|
|
3991
|
+
if (header.every((b) => b === 0)) break;
|
|
3992
|
+
const size = octalField(header, 124, 136) || 0;
|
|
3993
|
+
const mode = octalField(header, 100, 108) || TAR_FILE_MODE;
|
|
3994
|
+
const typeflag = String.fromCharCode(header[156] ?? 0);
|
|
3995
|
+
const bytes = tar.subarray(offset, offset + size);
|
|
3996
|
+
offset += Math.ceil(size / 512) * 512;
|
|
3997
|
+
if (typeflag === "L") {
|
|
3998
|
+
pendingName = bytes.toString("utf-8").replace(/\0.*$/, "");
|
|
3999
|
+
continue;
|
|
4000
|
+
}
|
|
4001
|
+
if (typeflag === "x") {
|
|
4002
|
+
pendingName = paxPath(bytes) ?? pendingName;
|
|
4003
|
+
continue;
|
|
4004
|
+
}
|
|
4005
|
+
if (typeflag === "K" || typeflag === "g") continue;
|
|
4006
|
+
const name = pendingName ?? _TarArchive.ustarName(header);
|
|
4007
|
+
pendingName = null;
|
|
4008
|
+
yield { name: name.replace(/^\.\//, ""), bytes, typeflag, mode };
|
|
4009
|
+
}
|
|
4010
|
+
}
|
|
4011
|
+
static ustarName(header) {
|
|
4012
|
+
const name = field(header, 0, 100);
|
|
4013
|
+
const magic = header.subarray(257, 262).toString("ascii");
|
|
4014
|
+
const prefix = magic === "ustar" ? field(header, 345, 500) : "";
|
|
4015
|
+
return prefix ? `${prefix}/${name}` : name;
|
|
4016
|
+
}
|
|
4017
|
+
/** Regular files only, confined to `dir` (absolute or `..` names are
|
|
4018
|
+
* skipped, never written). Returns the number of files written. */
|
|
4019
|
+
extractTo(dir) {
|
|
4020
|
+
let written = 0;
|
|
4021
|
+
for (const member of this.members()) {
|
|
4022
|
+
if (member.typeflag !== "0" && member.typeflag !== "\0") continue;
|
|
4023
|
+
if (!_TarArchive.isConfined(member.name)) continue;
|
|
4024
|
+
const target = path4.join(dir, member.name);
|
|
4025
|
+
fs4.mkdirSync(path4.dirname(target), { recursive: true });
|
|
4026
|
+
const mode = archiveMode(member.mode);
|
|
4027
|
+
fs4.writeFileSync(target, member.bytes, { mode });
|
|
4028
|
+
fs4.chmodSync(target, mode);
|
|
4029
|
+
written++;
|
|
4030
|
+
}
|
|
4031
|
+
return written;
|
|
4032
|
+
}
|
|
4033
|
+
static isConfined(name) {
|
|
4034
|
+
if (name === "" || name.startsWith("/")) return false;
|
|
4035
|
+
return !name.split("/").includes("..");
|
|
4036
|
+
}
|
|
4037
|
+
};
|
|
4038
|
+
}
|
|
4039
|
+
});
|
|
4040
|
+
|
|
3080
4041
|
// src/worlds/hub.ts
|
|
3081
4042
|
var hub_exports = {};
|
|
3082
4043
|
__export(hub_exports, {
|
|
3083
4044
|
DEFAULT_BRANCH: () => DEFAULT_BRANCH,
|
|
4045
|
+
DetachedPushError: () => DetachedPushError,
|
|
3084
4046
|
PushSlugConflict: () => PushSlugConflict,
|
|
3085
4047
|
archiveMode: () => archiveMode,
|
|
3086
4048
|
buildFileManifest: () => buildFileManifest,
|
|
3087
4049
|
buildSourceTarball: () => buildSourceTarball,
|
|
4050
|
+
checkoutIdentity: () => checkoutIdentity,
|
|
3088
4051
|
collectArchiveRelPaths: () => collectArchiveRelPaths,
|
|
3089
4052
|
computeContentHash: () => computeContentHash,
|
|
3090
4053
|
createRef: () => createRef,
|
|
@@ -3093,6 +4056,7 @@ __export(hub_exports, {
|
|
|
3093
4056
|
propose: () => propose,
|
|
3094
4057
|
pull: () => pull,
|
|
3095
4058
|
push: () => push,
|
|
4059
|
+
pushBranch: () => pushBranch,
|
|
3096
4060
|
pushSlug: () => pushSlug,
|
|
3097
4061
|
readLocalMeta: () => readLocalMeta,
|
|
3098
4062
|
resolvePushSlug: () => resolvePushSlug,
|
|
@@ -3118,9 +4082,6 @@ function octal(value, length) {
|
|
|
3118
4082
|
"ascii"
|
|
3119
4083
|
);
|
|
3120
4084
|
}
|
|
3121
|
-
function archiveMode(mode) {
|
|
3122
|
-
return (mode & 73) !== 0 ? EXEC_MODE : FILE_MODE;
|
|
3123
|
-
}
|
|
3124
4085
|
function tarHeader(name, size, mode = FILE_MODE) {
|
|
3125
4086
|
const header = Buffer.alloc(512);
|
|
3126
4087
|
header.write(name, 0, 100, "utf-8");
|
|
@@ -3164,21 +4125,21 @@ function tarMember(name, payload, mode) {
|
|
|
3164
4125
|
function buildSourceTarball(dir) {
|
|
3165
4126
|
const parts = [];
|
|
3166
4127
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
3167
|
-
const abs =
|
|
4128
|
+
const abs = path5.join(dir, relPath);
|
|
3168
4129
|
parts.push(
|
|
3169
4130
|
...tarMember(
|
|
3170
4131
|
relPath,
|
|
3171
|
-
|
|
3172
|
-
archiveMode(
|
|
4132
|
+
fs5.readFileSync(abs),
|
|
4133
|
+
archiveMode(fs5.statSync(abs).mode)
|
|
3173
4134
|
)
|
|
3174
4135
|
);
|
|
3175
4136
|
}
|
|
3176
4137
|
parts.push(Buffer.alloc(1024));
|
|
3177
|
-
return (0,
|
|
4138
|
+
return (0, import_node_zlib2.gzipSync)(Buffer.concat(parts), { level: 9 });
|
|
3178
4139
|
}
|
|
3179
4140
|
function readLocalMeta(dir) {
|
|
3180
4141
|
try {
|
|
3181
|
-
const raw =
|
|
4142
|
+
const raw = fs5.readFileSync(path5.join(dir, META_RELPATH), "utf-8");
|
|
3182
4143
|
const parsed = JSON.parse(raw);
|
|
3183
4144
|
return parsed && typeof parsed === "object" ? parsed : null;
|
|
3184
4145
|
} catch {
|
|
@@ -3201,16 +4162,16 @@ function resolvePushSlug(dir, opts = {}) {
|
|
|
3201
4162
|
}
|
|
3202
4163
|
const first = declared[0];
|
|
3203
4164
|
if (first) return { ...base, slug: first.slug, source: first.source };
|
|
3204
|
-
return { ...base, slug:
|
|
4165
|
+
return { ...base, slug: path5.basename(path5.resolve(dir)), source: "directory name" };
|
|
3205
4166
|
}
|
|
3206
4167
|
function writeLocalMeta(dir, meta) {
|
|
3207
|
-
|
|
3208
|
-
|
|
4168
|
+
fs5.mkdirSync(path5.join(dir, ".gateway"), { recursive: true });
|
|
4169
|
+
fs5.writeFileSync(path5.join(dir, META_RELPATH), JSON.stringify(meta, null, 2));
|
|
3209
4170
|
}
|
|
3210
4171
|
function snapshotTreeHashes(dir) {
|
|
3211
4172
|
const out = {};
|
|
3212
4173
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
3213
|
-
out[relPath] = (0, import_node_crypto5.createHash)("sha256").update(
|
|
4174
|
+
out[relPath] = (0, import_node_crypto5.createHash)("sha256").update(fs5.readFileSync(path5.join(dir, relPath))).digest("hex");
|
|
3214
4175
|
}
|
|
3215
4176
|
return out;
|
|
3216
4177
|
}
|
|
@@ -3228,7 +4189,7 @@ function localTreeState(dir) {
|
|
|
3228
4189
|
}
|
|
3229
4190
|
function readPyproject(dir) {
|
|
3230
4191
|
try {
|
|
3231
|
-
const text2 =
|
|
4192
|
+
const text2 = fs5.readFileSync(path5.join(dir, "pyproject.toml"), "utf-8");
|
|
3232
4193
|
const section = /\[project\]([\s\S]*?)(\n\[|$)/.exec(text2)?.[1] ?? "";
|
|
3233
4194
|
const name = /\bname\s*=\s*"([^"]+)"/.exec(section)?.[1];
|
|
3234
4195
|
const version = /\bversion\s*=\s*"([^"]+)"/.exec(section)?.[1];
|
|
@@ -3251,7 +4212,7 @@ function readWorldContractVersion(dir) {
|
|
|
3251
4212
|
}
|
|
3252
4213
|
function buildFileManifest(dir) {
|
|
3253
4214
|
return collectArchiveRelPaths(dir).map((relPath) => {
|
|
3254
|
-
const payload =
|
|
4215
|
+
const payload = fs5.readFileSync(path5.join(dir, relPath));
|
|
3255
4216
|
return {
|
|
3256
4217
|
path: relPath,
|
|
3257
4218
|
isDirectory: false,
|
|
@@ -3275,30 +4236,36 @@ async function putObject(url, data, shaB64) {
|
|
|
3275
4236
|
);
|
|
3276
4237
|
}
|
|
3277
4238
|
}
|
|
4239
|
+
function pushBranch(dir, localMeta, explicit) {
|
|
4240
|
+
if (explicit) return explicit;
|
|
4241
|
+
if (typeof localMeta.tag === "string" && localMeta.tag) throw new DetachedPushError(dir, localMeta.tag);
|
|
4242
|
+
return localMeta.branch ?? DEFAULT_BRANCH;
|
|
4243
|
+
}
|
|
3278
4244
|
async function push(dir, opts = {}) {
|
|
3279
4245
|
const options = opts.options ?? {};
|
|
3280
|
-
if (!
|
|
4246
|
+
if (!fs5.statSync(dir).isDirectory())
|
|
3281
4247
|
throw new Error(`Not a directory: ${dir}`);
|
|
3282
4248
|
const localMeta = readLocalMeta(dir) ?? {};
|
|
3283
|
-
const branch =
|
|
4249
|
+
const branch = pushBranch(dir, localMeta, opts.branch);
|
|
3284
4250
|
const baseVersionId = opts.baseVersionId ?? localMeta.versionId ?? null;
|
|
4251
|
+
const world = WorldDir.open(dir);
|
|
3285
4252
|
const fileManifest = buildFileManifest(dir);
|
|
3286
4253
|
if (fileManifest.length === 0)
|
|
3287
4254
|
throw new Error(
|
|
3288
4255
|
`Nothing to push: ${dir} has no files the archive rules keep (a world root marker, README.md, pyproject.toml, *.py, or any file below a subdirectory).`
|
|
3289
4256
|
);
|
|
3290
|
-
const contentHash =
|
|
4257
|
+
const contentHash = world.contentHash;
|
|
3291
4258
|
const pyproject = readPyproject(dir);
|
|
3292
4259
|
const contractVersion = pyproject.version ? void 0 : readWorldContractVersion(dir).version;
|
|
3293
4260
|
if (contractVersion) pyproject.version = contractVersion;
|
|
3294
|
-
const slug = opts.slug ?? localMeta.slug ?? pyproject.name ??
|
|
4261
|
+
const slug = opts.slug ?? localMeta.slug ?? pyproject.name ?? path5.basename(path5.resolve(dir));
|
|
3295
4262
|
const metadata = {
|
|
3296
4263
|
...opts.name !== void 0 ? { name: opts.name } : {},
|
|
3297
4264
|
...opts.description !== void 0 ? { description: opts.description } : {},
|
|
3298
4265
|
...opts.tags !== void 0 ? { tags: opts.tags } : {},
|
|
3299
4266
|
...opts.visibility ? { visibility: opts.visibility } : {}
|
|
3300
4267
|
};
|
|
3301
|
-
const
|
|
4268
|
+
const resolve7 = await apiRequest(
|
|
3302
4269
|
options,
|
|
3303
4270
|
"POST",
|
|
3304
4271
|
"/api/public/benchmark-containers/resolve",
|
|
@@ -3307,7 +4274,7 @@ async function push(dir, opts = {}) {
|
|
|
3307
4274
|
const tarball = buildSourceTarball(dir);
|
|
3308
4275
|
const bundleSha256 = sha256b64(tarball);
|
|
3309
4276
|
const version = await apiRequest(options, "POST", "/api/public/benchmark-containers/versions", {
|
|
3310
|
-
containerId:
|
|
4277
|
+
containerId: resolve7.containerId,
|
|
3311
4278
|
contentHash,
|
|
3312
4279
|
bundleSha256,
|
|
3313
4280
|
bundleSizeBytes: tarball.length,
|
|
@@ -3346,56 +4313,36 @@ async function push(dir, opts = {}) {
|
|
|
3346
4313
|
baseFiles: snapshotTreeHashes(dir)
|
|
3347
4314
|
});
|
|
3348
4315
|
return {
|
|
3349
|
-
containerId:
|
|
4316
|
+
containerId: resolve7.containerId,
|
|
3350
4317
|
slug,
|
|
3351
4318
|
versionId: version.versionId,
|
|
3352
4319
|
contentHash,
|
|
3353
4320
|
branch: final.branch ?? branch,
|
|
3354
4321
|
state: final.state ?? null,
|
|
3355
|
-
alreadyUploaded: Boolean(version.alreadyUploaded)
|
|
4322
|
+
alreadyUploaded: Boolean(version.alreadyUploaded),
|
|
4323
|
+
editSessionId: final.editSessionId ?? null,
|
|
4324
|
+
filesKept: fileManifest.length,
|
|
4325
|
+
excluded: world.exclusions
|
|
3356
4326
|
};
|
|
3357
4327
|
}
|
|
3358
4328
|
function extractBundle(bundle, dir) {
|
|
3359
|
-
|
|
3360
|
-
let offset = 0;
|
|
3361
|
-
let longName = null;
|
|
3362
|
-
let written = 0;
|
|
3363
|
-
while (offset + 512 <= tar.length) {
|
|
3364
|
-
const header = tar.subarray(offset, offset + 512);
|
|
3365
|
-
offset += 512;
|
|
3366
|
-
if (header.every((b) => b === 0)) break;
|
|
3367
|
-
const rawName = header.subarray(0, 100).toString("utf-8").replace(/\0.*$/, "");
|
|
3368
|
-
const size = parseInt(
|
|
3369
|
-
header.subarray(124, 136).toString("ascii").replace(/\0.*$/, "").trim(),
|
|
3370
|
-
8
|
|
3371
|
-
) || 0;
|
|
3372
|
-
const mode = parseInt(
|
|
3373
|
-
header.subarray(100, 108).toString("ascii").replace(/\0.*$/, "").trim(),
|
|
3374
|
-
8
|
|
3375
|
-
) || FILE_MODE;
|
|
3376
|
-
const typeflag = header.subarray(156, 157).toString("ascii");
|
|
3377
|
-
const body = tar.subarray(offset, offset + size);
|
|
3378
|
-
offset += size + (size % 512 === 0 ? 0 : 512 - size % 512);
|
|
3379
|
-
if (typeflag === "L") {
|
|
3380
|
-
longName = body.toString("utf-8").replace(/\0.*$/, "");
|
|
3381
|
-
continue;
|
|
3382
|
-
}
|
|
3383
|
-
const name = (longName ?? rawName).replace(/^\.\//, "");
|
|
3384
|
-
longName = null;
|
|
3385
|
-
if (typeflag !== "0" && typeflag !== "") continue;
|
|
3386
|
-
if (name.startsWith("/") || name.split("/").includes("..")) continue;
|
|
3387
|
-
const target = path3.join(dir, name);
|
|
3388
|
-
fs3.mkdirSync(path3.dirname(target), { recursive: true });
|
|
3389
|
-
fs3.writeFileSync(target, body, { mode: archiveMode(mode) });
|
|
3390
|
-
fs3.chmodSync(target, archiveMode(mode));
|
|
3391
|
-
written++;
|
|
3392
|
-
}
|
|
3393
|
-
return written;
|
|
4329
|
+
return TarArchive.fromGzip(bundle).extractTo(dir);
|
|
3394
4330
|
}
|
|
3395
|
-
|
|
4331
|
+
function checkoutIdentity(ref, resolved) {
|
|
4332
|
+
if (resolved.tag) return { tag: resolved.tag };
|
|
4333
|
+
if (resolved.branch) return { branch: resolved.branch };
|
|
4334
|
+
const pinned = ref === "latest" || /^\d|^[0-9a-f]{8,}$/.test(ref);
|
|
4335
|
+
return { branch: pinned ? DEFAULT_BRANCH : ref };
|
|
4336
|
+
}
|
|
4337
|
+
async function pull(slugRef, target, options = {}, opts = {}) {
|
|
3396
4338
|
const at = slugRef.indexOf("@");
|
|
3397
4339
|
const slug = at === -1 ? slugRef : slugRef.slice(0, at);
|
|
3398
4340
|
const ref = at === -1 ? "latest" : slugRef.slice(at + 1);
|
|
4341
|
+
const landing = CheckoutTarget.resolve(slug, target, {
|
|
4342
|
+
cwd: process.cwd(),
|
|
4343
|
+
force: opts.force ?? false,
|
|
4344
|
+
state: localTreeState
|
|
4345
|
+
});
|
|
3399
4346
|
const details = await apiRequest(options, "POST", "/api/public/benchmark-containers/resolve-version", {
|
|
3400
4347
|
slug,
|
|
3401
4348
|
ref
|
|
@@ -3403,13 +4350,6 @@ async function pull(slugRef, target, options = {}) {
|
|
|
3403
4350
|
if (!details.downloadUrl) {
|
|
3404
4351
|
throw new Error(`${slug}@${ref} resolved but has no uploaded bundle`);
|
|
3405
4352
|
}
|
|
3406
|
-
let dir = target ?? path3.join(process.cwd(), slug);
|
|
3407
|
-
if (!target) {
|
|
3408
|
-
let i = 1;
|
|
3409
|
-
const base = dir;
|
|
3410
|
-
while (fs3.existsSync(dir)) dir = `${base}-${i++}`;
|
|
3411
|
-
}
|
|
3412
|
-
fs3.mkdirSync(dir, { recursive: true });
|
|
3413
4353
|
const resp = await fetch(details.downloadUrl);
|
|
3414
4354
|
if (!resp.ok) throw new Error(`bundle download -> ${resp.status}`);
|
|
3415
4355
|
const bundle = Buffer.from(await resp.arrayBuffer());
|
|
@@ -3418,12 +4358,14 @@ async function pull(slugRef, target, options = {}) {
|
|
|
3418
4358
|
`bundle integrity check failed for ${slug}@${ref}: downloaded sha256 != recorded bundleSha256`
|
|
3419
4359
|
);
|
|
3420
4360
|
}
|
|
4361
|
+
const dir = landing.dir;
|
|
4362
|
+
fs5.mkdirSync(dir, { recursive: true });
|
|
4363
|
+
landing.clear();
|
|
3421
4364
|
const files = extractBundle(bundle, dir);
|
|
3422
|
-
const branch = ref === "latest" || /^\d|^[0-9a-f]{8,}$/.test(ref) ? DEFAULT_BRANCH : ref;
|
|
3423
4365
|
writeLocalMeta(dir, {
|
|
3424
4366
|
slug,
|
|
3425
4367
|
ref,
|
|
3426
|
-
|
|
4368
|
+
...checkoutIdentity(ref, details),
|
|
3427
4369
|
versionId: details.versionId,
|
|
3428
4370
|
contentHash: details.contentHash,
|
|
3429
4371
|
semanticVersion: details.semanticVersion ?? void 0,
|
|
@@ -3442,13 +4384,13 @@ async function propose(dir, opts) {
|
|
|
3442
4384
|
if (state2.clean)
|
|
3443
4385
|
throw new Error("Nothing to propose \u2014 the tree matches its base.");
|
|
3444
4386
|
const changes = state2.dirty.map((relPath) => {
|
|
3445
|
-
const abs =
|
|
3446
|
-
if (!
|
|
4387
|
+
const abs = path5.join(dir, relPath);
|
|
4388
|
+
if (!fs5.existsSync(abs))
|
|
3447
4389
|
return { path: relPath, action: "delete" };
|
|
3448
4390
|
return {
|
|
3449
4391
|
path: relPath,
|
|
3450
4392
|
action: "write",
|
|
3451
|
-
newContent:
|
|
4393
|
+
newContent: fs5.readFileSync(abs, "utf-8")
|
|
3452
4394
|
};
|
|
3453
4395
|
});
|
|
3454
4396
|
const res = await apiRequest(
|
|
@@ -3474,20 +4416,21 @@ async function createRef(slug, name, kind, versionId, options = {}) {
|
|
|
3474
4416
|
...versionId ? { versionId } : {}
|
|
3475
4417
|
});
|
|
3476
4418
|
}
|
|
3477
|
-
var import_node_crypto5,
|
|
4419
|
+
var import_node_crypto5, import_node_zlib2, fs5, path5, DEFAULT_BRANCH, META_RELPATH, FILE_MODE, MINTED_SUFFIX, PushSlugConflict, sha256b64, DetachedPushError;
|
|
3478
4420
|
var init_hub = __esm({
|
|
3479
4421
|
"src/worlds/hub.ts"() {
|
|
3480
4422
|
"use strict";
|
|
3481
4423
|
import_node_crypto5 = require("crypto");
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
4424
|
+
import_node_zlib2 = require("zlib");
|
|
4425
|
+
fs5 = __toESM(require("fs"));
|
|
4426
|
+
path5 = __toESM(require("path"));
|
|
3485
4427
|
init_worlds();
|
|
4428
|
+
init_checkoutTarget();
|
|
3486
4429
|
init_worldDir();
|
|
4430
|
+
init_tar();
|
|
3487
4431
|
DEFAULT_BRANCH = "main";
|
|
3488
|
-
META_RELPATH =
|
|
3489
|
-
FILE_MODE =
|
|
3490
|
-
EXEC_MODE = 493;
|
|
4432
|
+
META_RELPATH = path5.join(".gateway", ".env-metadata.json");
|
|
4433
|
+
FILE_MODE = TAR_FILE_MODE;
|
|
3491
4434
|
MINTED_SUFFIX = /^-\d+$/;
|
|
3492
4435
|
PushSlugConflict = class extends Error {
|
|
3493
4436
|
constructor(dir, tracked, declared) {
|
|
@@ -3499,8 +4442,19 @@ var init_hub = __esm({
|
|
|
3499
4442
|
this.declared = declared;
|
|
3500
4443
|
this.name = "PushSlugConflict";
|
|
3501
4444
|
}
|
|
4445
|
+
dir;
|
|
4446
|
+
tracked;
|
|
4447
|
+
declared;
|
|
3502
4448
|
};
|
|
3503
4449
|
sha256b64 = (data) => (0, import_node_crypto5.createHash)("sha256").update(data).digest("base64");
|
|
4450
|
+
DetachedPushError = class extends Error {
|
|
4451
|
+
constructor(dir, tag) {
|
|
4452
|
+
super(
|
|
4453
|
+
`push refused: ${dir} is a checkout of tag "${tag}" (tags are immutable). Nothing was pushed. Pass --branch <name> to land these files on a branch, or checkout a branch first.`
|
|
4454
|
+
);
|
|
4455
|
+
this.name = "DetachedPushError";
|
|
4456
|
+
}
|
|
4457
|
+
};
|
|
3504
4458
|
}
|
|
3505
4459
|
});
|
|
3506
4460
|
|
|
@@ -3687,22 +4641,140 @@ var init_validate = __esm({
|
|
|
3687
4641
|
}
|
|
3688
4642
|
});
|
|
3689
4643
|
|
|
4644
|
+
// src/worlds/sandbox.ts
|
|
4645
|
+
function parseSlugRef(slugRef) {
|
|
4646
|
+
const at = slugRef.indexOf("@");
|
|
4647
|
+
if (at === -1) return { slug: slugRef };
|
|
4648
|
+
return { slug: slugRef.slice(0, at), ref: slugRef.slice(at + 1) };
|
|
4649
|
+
}
|
|
4650
|
+
function rebaseConflicts(error) {
|
|
4651
|
+
if (!(error instanceof ApiError) || error.status !== 409) return null;
|
|
4652
|
+
let body;
|
|
4653
|
+
try {
|
|
4654
|
+
body = JSON.parse(error.text);
|
|
4655
|
+
} catch {
|
|
4656
|
+
return null;
|
|
4657
|
+
}
|
|
4658
|
+
const conflicts = body?.conflicts;
|
|
4659
|
+
if (!Array.isArray(conflicts)) return null;
|
|
4660
|
+
return conflicts.filter(isConflictPath).map(({ path: path12, reason }) => ({ path: path12, reason }));
|
|
4661
|
+
}
|
|
4662
|
+
function isConflictPath(value) {
|
|
4663
|
+
const entry = value;
|
|
4664
|
+
return typeof entry?.path === "string" && typeof entry.reason === "string";
|
|
4665
|
+
}
|
|
4666
|
+
function uncommittedPaths(error) {
|
|
4667
|
+
if (!(error instanceof ApiError) || error.status !== 409 || error.code !== "sandbox_uncommitted") return null;
|
|
4668
|
+
let body;
|
|
4669
|
+
try {
|
|
4670
|
+
body = JSON.parse(error.text);
|
|
4671
|
+
} catch {
|
|
4672
|
+
return null;
|
|
4673
|
+
}
|
|
4674
|
+
const uncommitted = body?.uncommitted;
|
|
4675
|
+
if (!Array.isArray(uncommitted)) return null;
|
|
4676
|
+
return uncommitted.filter((p) => typeof p === "string");
|
|
4677
|
+
}
|
|
4678
|
+
function listQuery(filter) {
|
|
4679
|
+
const params = new URLSearchParams();
|
|
4680
|
+
if (filter.status) params.set("status", filter.status);
|
|
4681
|
+
if (filter.slug) params.set("slug", filter.slug);
|
|
4682
|
+
if (filter.limit !== void 0) params.set("limit", String(filter.limit));
|
|
4683
|
+
const qs = params.toString();
|
|
4684
|
+
return qs ? `?${qs}` : "";
|
|
4685
|
+
}
|
|
4686
|
+
var isSandboxImportPending, sid, SANDBOXES, SANDBOX_REQUEST_TIMEOUT_MS, WorldSandboxClient;
|
|
4687
|
+
var init_sandbox = __esm({
|
|
4688
|
+
"src/worlds/sandbox.ts"() {
|
|
4689
|
+
"use strict";
|
|
4690
|
+
init_worlds();
|
|
4691
|
+
isSandboxImportPending = (answer) => !("versionId" in answer);
|
|
4692
|
+
sid = encodeURIComponent;
|
|
4693
|
+
SANDBOXES = "/api/public/benchmark-containers/sandboxes";
|
|
4694
|
+
SANDBOX_REQUEST_TIMEOUT_MS = 66e4;
|
|
4695
|
+
WorldSandboxClient = class {
|
|
4696
|
+
constructor(options = {}) {
|
|
4697
|
+
this.options = options;
|
|
4698
|
+
}
|
|
4699
|
+
options;
|
|
4700
|
+
request(method, path12, body) {
|
|
4701
|
+
return apiRequest(this.options, method, path12, body, {
|
|
4702
|
+
timeoutMs: SANDBOX_REQUEST_TIMEOUT_MS
|
|
4703
|
+
});
|
|
4704
|
+
}
|
|
4705
|
+
/**
|
|
4706
|
+
* `{ slug, ref? }` opens a READY version; `{ new, from }` opens a sandbox on
|
|
4707
|
+
* a world that does not exist yet (409 `world_exists` if the slug is taken,
|
|
4708
|
+
* 400 naming the shipped templates if `from` is unknown). Its first commit
|
|
4709
|
+
* creates the world on `main`.
|
|
4710
|
+
*/
|
|
4711
|
+
open(target) {
|
|
4712
|
+
return this.request("POST", `${SANDBOXES}`, target);
|
|
4713
|
+
}
|
|
4714
|
+
status(sandboxId) {
|
|
4715
|
+
return this.request("GET", `${SANDBOXES}/${sid(sandboxId)}`);
|
|
4716
|
+
}
|
|
4717
|
+
/** The project's sandboxes, newest first — how an agent finds one it left open. */
|
|
4718
|
+
async list(filter = {}) {
|
|
4719
|
+
const res = await this.request("GET", `${SANDBOXES}${listQuery(filter)}`);
|
|
4720
|
+
return res.sandboxes;
|
|
4721
|
+
}
|
|
4722
|
+
async read(sandboxId, filePath) {
|
|
4723
|
+
const res = await this.request(
|
|
4724
|
+
"GET",
|
|
4725
|
+
`${SANDBOXES}/${sid(sandboxId)}/file?path=${encodeURIComponent(filePath)}`
|
|
4726
|
+
);
|
|
4727
|
+
return { path: res.path, size: res.size, bytes: Buffer.from(res.contentBase64, "base64") };
|
|
4728
|
+
}
|
|
4729
|
+
write(sandboxId, filePath, bytes) {
|
|
4730
|
+
return this.request("PUT", `${SANDBOXES}/${sid(sandboxId)}/file`, {
|
|
4731
|
+
path: filePath,
|
|
4732
|
+
contentBase64: bytes.toString("base64")
|
|
4733
|
+
});
|
|
4734
|
+
}
|
|
4735
|
+
exec(sandboxId, input) {
|
|
4736
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/exec`, input);
|
|
4737
|
+
}
|
|
4738
|
+
check(sandboxId) {
|
|
4739
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/check`, {});
|
|
4740
|
+
}
|
|
4741
|
+
/** With `rebase`, a moved base is replayed onto; a 409 then names the conflicting paths (`rebaseConflicts`). */
|
|
4742
|
+
commit(sandboxId, input) {
|
|
4743
|
+
const { rebase, ...rest } = input;
|
|
4744
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/commit`, rebase ? { ...rest, rebase: true } : rest);
|
|
4745
|
+
}
|
|
4746
|
+
/**
|
|
4747
|
+
* A rows file already in the sandbox tree into the PLATFORM world the
|
|
4748
|
+
* sandbox was opened on (201 with the version, 202 with the batch to poll,
|
|
4749
|
+
* 400 naming a refused row). Not `commit`: a commit versions the source
|
|
4750
|
+
* tree and never carries data.
|
|
4751
|
+
*/
|
|
4752
|
+
importData(sandboxId, input) {
|
|
4753
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/import`, input);
|
|
4754
|
+
}
|
|
4755
|
+
/** Uncommitted work is a 409 (`uncommittedPaths`) unless `force` discards it. */
|
|
4756
|
+
close(sandboxId, opts = {}) {
|
|
4757
|
+
return this.request("DELETE", `${SANDBOXES}/${sid(sandboxId)}`, opts.force ? { force: true } : void 0);
|
|
4758
|
+
}
|
|
4759
|
+
};
|
|
4760
|
+
}
|
|
4761
|
+
});
|
|
4762
|
+
|
|
3690
4763
|
// src/worlds/describe.ts
|
|
3691
|
-
async function describeWorld(
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
`describeWorld reads a world's head version: pass the slug without @ref (got ${slug})`
|
|
3695
|
-
);
|
|
4764
|
+
async function describeWorld(slugRef, options = {}) {
|
|
4765
|
+
const { slug, ref } = parseSlugRef(slugRef);
|
|
4766
|
+
const query = ref === void 0 ? "" : `?ref=${encodeURIComponent(ref)}`;
|
|
3696
4767
|
return apiRequest(
|
|
3697
4768
|
options,
|
|
3698
4769
|
"GET",
|
|
3699
|
-
`/api/public/worlds/${encodeURIComponent(slug)}`
|
|
4770
|
+
`/api/public/worlds/${encodeURIComponent(slug)}${query}`
|
|
3700
4771
|
);
|
|
3701
4772
|
}
|
|
3702
4773
|
var init_describe = __esm({
|
|
3703
4774
|
"src/worlds/describe.ts"() {
|
|
3704
4775
|
"use strict";
|
|
3705
4776
|
init_worlds();
|
|
4777
|
+
init_sandbox();
|
|
3706
4778
|
}
|
|
3707
4779
|
});
|
|
3708
4780
|
|
|
@@ -3807,6 +4879,7 @@ var init_json = __esm({
|
|
|
3807
4879
|
constructor(text2) {
|
|
3808
4880
|
this.text = text2;
|
|
3809
4881
|
}
|
|
4882
|
+
text;
|
|
3810
4883
|
/** A float in Python's eyes: a fraction, an exponent, or a non-finite literal. */
|
|
3811
4884
|
get isFloat() {
|
|
3812
4885
|
return /[.eE]/.test(this.text) || /[nN]/.test(this.text);
|
|
@@ -3821,6 +4894,7 @@ var init_json = __esm({
|
|
|
3821
4894
|
constructor(s) {
|
|
3822
4895
|
this.s = s;
|
|
3823
4896
|
}
|
|
4897
|
+
s;
|
|
3824
4898
|
i = 0;
|
|
3825
4899
|
skipWs() {
|
|
3826
4900
|
const s = this.s;
|
|
@@ -4100,24 +5174,24 @@ function roundForm(plaintext, decimals) {
|
|
|
4100
5174
|
if (typeof plaintext === "string" || isInt(plaintext) || !Number.isFinite(plaintext)) return plaintext;
|
|
4101
5175
|
return pyRound(new JsonNumber(pyFloatRepr(plaintext)), decimals).value;
|
|
4102
5176
|
}
|
|
4103
|
-
function redactionOf(redact,
|
|
5177
|
+
function redactionOf(redact, field2) {
|
|
4104
5178
|
if (!redact) return null;
|
|
4105
|
-
const named = (names) => (names ?? []).some((name) => name ===
|
|
5179
|
+
const named = (names) => (names ?? []).some((name) => name === field2 || name.slice(name.lastIndexOf(".") + 1) === field2);
|
|
4106
5180
|
if (named(redact.drop)) return "drop";
|
|
4107
5181
|
if (named(redact.hash)) return "hash";
|
|
4108
5182
|
if (named(redact.preserve)) return "preserve";
|
|
4109
|
-
const decimals = redact.round?.[
|
|
5183
|
+
const decimals = redact.round?.[field2];
|
|
4110
5184
|
if (typeof decimals === "number") return `round:${decimals}`;
|
|
4111
5185
|
return null;
|
|
4112
5186
|
}
|
|
4113
|
-
function storedForms(world,
|
|
5187
|
+
function storedForms(world, field2, plaintext, transform) {
|
|
4114
5188
|
if (transform?.length) plaintext = applyTransforms(plaintext, transform);
|
|
4115
|
-
const policy = redactionOf(world.redact,
|
|
5189
|
+
const policy = redactionOf(world.redact, field2);
|
|
4116
5190
|
const salt = world.redact?.slug ?? world.slug;
|
|
4117
5191
|
if (policy === "drop") return [];
|
|
4118
5192
|
if (policy === "hash") return [hashForm(salt, plaintext)];
|
|
4119
5193
|
if (policy === "preserve") return [preserveForm(salt, plaintext)];
|
|
4120
|
-
if (policy !== null) return [roundForm(plaintext, world.redact.round[
|
|
5194
|
+
if (policy !== null) return [roundForm(plaintext, world.redact.round[field2])];
|
|
4121
5195
|
return [plaintext];
|
|
4122
5196
|
}
|
|
4123
5197
|
var import_node_crypto7, isInt;
|
|
@@ -4203,71 +5277,42 @@ var init_router = __esm({
|
|
|
4203
5277
|
super(message);
|
|
4204
5278
|
this.exitCode = exitCode;
|
|
4205
5279
|
}
|
|
5280
|
+
exitCode;
|
|
4206
5281
|
};
|
|
4207
5282
|
}
|
|
4208
5283
|
});
|
|
4209
5284
|
|
|
4210
5285
|
// src/cli/config.ts
|
|
4211
|
-
function transportDetail(error, timeoutMs) {
|
|
4212
|
-
if (error instanceof Error && error.name === "AbortError") return `timed out after ${Math.round(timeoutMs / 1e3)}s`;
|
|
4213
|
-
const cause = error instanceof Error && error.cause instanceof Error ? error.cause : void 0;
|
|
4214
|
-
const code = cause && "code" in cause && typeof cause.code === "string" ? `${cause.code}: ` : "";
|
|
4215
|
-
const message = cause?.message ?? (error instanceof Error ? error.message : String(error));
|
|
4216
|
-
return `${code}${message}`;
|
|
4217
|
-
}
|
|
4218
5286
|
async function api(creds, method, route, body, init2 = {}) {
|
|
4219
|
-
const
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
let res;
|
|
4223
|
-
try {
|
|
4224
|
-
res = await fetch(`${creds.host}${route}`, {
|
|
4225
|
-
method,
|
|
4226
|
-
headers: {
|
|
4227
|
-
"content-type": "application/json",
|
|
4228
|
-
accept: "application/json",
|
|
4229
|
-
authorization: "Basic " + Buffer.from(`${creds.publicKey}:${creds.secretKey}`).toString("base64")
|
|
4230
|
-
},
|
|
4231
|
-
...body === void 0 ? {} : { body: JSON.stringify(body) },
|
|
4232
|
-
signal: controller.signal
|
|
4233
|
-
});
|
|
4234
|
-
} catch (error) {
|
|
4235
|
-
clearTimeout(timer);
|
|
4236
|
-
throw new UnreachableError(creds.host, method, route, transportDetail(error, timeoutMs));
|
|
4237
|
-
}
|
|
4238
|
-
try {
|
|
4239
|
-
const text2 = await res.text();
|
|
4240
|
-
if (!res.ok) throw new ApiError(res.status, method, route, text2);
|
|
4241
|
-
return text2 ? JSON.parse(text2) : {};
|
|
4242
|
-
} finally {
|
|
4243
|
-
clearTimeout(timer);
|
|
4244
|
-
}
|
|
5287
|
+
const reply = await new PlatformTransport(creds).send(method, route, body, init2);
|
|
5288
|
+
if (!reply.ok) throw new ApiError2(reply.status, method, route, reply.text);
|
|
5289
|
+
return reply.text ? JSON.parse(reply.text) : {};
|
|
4245
5290
|
}
|
|
4246
|
-
var
|
|
5291
|
+
var fs6, os, path6, ApiError2;
|
|
4247
5292
|
var init_config = __esm({
|
|
4248
5293
|
"src/cli/config.ts"() {
|
|
4249
5294
|
"use strict";
|
|
4250
|
-
|
|
5295
|
+
fs6 = __toESM(require("fs"));
|
|
4251
5296
|
os = __toESM(require("os"));
|
|
4252
|
-
|
|
5297
|
+
path6 = __toESM(require("path"));
|
|
4253
5298
|
init_router();
|
|
4254
|
-
|
|
5299
|
+
init_worlds();
|
|
5300
|
+
init_transport();
|
|
5301
|
+
ApiError2 = class extends CliError {
|
|
4255
5302
|
constructor(status, method, route, text2) {
|
|
4256
|
-
|
|
5303
|
+
const body = parseErrorBody(text2);
|
|
5304
|
+
super(`${method} ${route} -> ${status}: ${body.detail}`, 1);
|
|
4257
5305
|
this.status = status;
|
|
4258
5306
|
this.method = method;
|
|
4259
5307
|
this.route = route;
|
|
4260
5308
|
this.text = text2;
|
|
5309
|
+
this.code = body.code;
|
|
4261
5310
|
}
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
this.method = method;
|
|
4268
|
-
this.route = route;
|
|
4269
|
-
this.detail = detail;
|
|
4270
|
-
}
|
|
5311
|
+
status;
|
|
5312
|
+
method;
|
|
5313
|
+
route;
|
|
5314
|
+
text;
|
|
5315
|
+
code;
|
|
4271
5316
|
};
|
|
4272
5317
|
}
|
|
4273
5318
|
});
|
|
@@ -4287,22 +5332,22 @@ function runtimeRoot() {
|
|
|
4287
5332
|
const candidates = [];
|
|
4288
5333
|
if (process.env.GATEWAY_RUNTIME_PATH)
|
|
4289
5334
|
candidates.push(process.env.GATEWAY_RUNTIME_PATH);
|
|
4290
|
-
const entry = process.argv[1] &&
|
|
5335
|
+
const entry = process.argv[1] && fs7.existsSync(process.argv[1]) ? path7.dirname(fs7.realpathSync(process.argv[1])) : null;
|
|
4291
5336
|
if (entry) {
|
|
4292
|
-
candidates.push(
|
|
4293
|
-
candidates.push(
|
|
4294
|
-
candidates.push(
|
|
5337
|
+
candidates.push(path7.resolve(entry, "..", "runtime"));
|
|
5338
|
+
candidates.push(path7.resolve(entry, "..", "..", "runtime"));
|
|
5339
|
+
candidates.push(path7.resolve(entry, "..", "..", "sdk", "src"));
|
|
4295
5340
|
}
|
|
4296
|
-
candidates.push(
|
|
5341
|
+
candidates.push(path7.resolve(process.cwd(), "runtime"));
|
|
4297
5342
|
for (const root of candidates)
|
|
4298
|
-
if (
|
|
4299
|
-
|
|
5343
|
+
if (fs7.existsSync(
|
|
5344
|
+
path7.join(root, "gatewaysdk", "environment", "schema", "platform.py")
|
|
4300
5345
|
))
|
|
4301
5346
|
return root;
|
|
4302
5347
|
return null;
|
|
4303
5348
|
}
|
|
4304
5349
|
function probeVersion(name) {
|
|
4305
|
-
const probe = (0,
|
|
5350
|
+
const probe = (0, import_node_child_process2.spawnSync)(
|
|
4306
5351
|
name,
|
|
4307
5352
|
["-c", "import sys;print(sys.version_info[0],sys.version_info[1])"],
|
|
4308
5353
|
{ encoding: "utf8", timeout: 1e4 }
|
|
@@ -4316,7 +5361,7 @@ function atLeastMinimum(version) {
|
|
|
4316
5361
|
return major > MIN_PYTHON[0] || major === MIN_PYTHON[0] && minor >= MIN_PYTHON[1];
|
|
4317
5362
|
}
|
|
4318
5363
|
function uvPython() {
|
|
4319
|
-
const found = (0,
|
|
5364
|
+
const found = (0, import_node_child_process2.spawnSync)("uv", UV_FIND, { encoding: "utf8", timeout: 1e4 });
|
|
4320
5365
|
if (found.status !== 0) return null;
|
|
4321
5366
|
const line = found.stdout.trim().split(/\r?\n/)[0] ?? "";
|
|
4322
5367
|
return line || null;
|
|
@@ -4375,12 +5420,12 @@ function localRuntime() {
|
|
|
4375
5420
|
return { python, root };
|
|
4376
5421
|
}
|
|
4377
5422
|
function localPythonHasYaml(python) {
|
|
4378
|
-
return (0,
|
|
5423
|
+
return (0, import_node_child_process2.spawnSync)(python, ["-c", "import yaml"], { timeout: 1e4 }).status === 0;
|
|
4379
5424
|
}
|
|
4380
5425
|
async function localBridge(request, local, opts = {}) {
|
|
4381
5426
|
const input = JSON.stringify(request);
|
|
4382
|
-
return await new Promise((
|
|
4383
|
-
const child = (0,
|
|
5427
|
+
return await new Promise((resolve7, reject) => {
|
|
5428
|
+
const child = (0, import_node_child_process2.spawn)(
|
|
4384
5429
|
local.python,
|
|
4385
5430
|
["-I", "-B", "-c", BRIDGE_BOOTSTRAP, local.root],
|
|
4386
5431
|
{
|
|
@@ -4424,7 +5469,7 @@ async function localBridge(request, local, opts = {}) {
|
|
|
4424
5469
|
payload = null;
|
|
4425
5470
|
}
|
|
4426
5471
|
if (payload && typeof payload === "object") {
|
|
4427
|
-
|
|
5472
|
+
resolve7(payload);
|
|
4428
5473
|
return;
|
|
4429
5474
|
}
|
|
4430
5475
|
reject(
|
|
@@ -4437,17 +5482,17 @@ async function localBridge(request, local, opts = {}) {
|
|
|
4437
5482
|
child.stdin.end(input);
|
|
4438
5483
|
});
|
|
4439
5484
|
}
|
|
4440
|
-
var
|
|
5485
|
+
var import_node_child_process2, fs7, net, path7, MIN_PYTHON, DIAGNOSTIC_TAIL, BRIDGE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
|
|
4441
5486
|
var init_local = __esm({
|
|
4442
5487
|
"src/cli/runtime/local.ts"() {
|
|
4443
5488
|
"use strict";
|
|
4444
|
-
|
|
4445
|
-
|
|
5489
|
+
import_node_child_process2 = require("child_process");
|
|
5490
|
+
fs7 = __toESM(require("fs"));
|
|
4446
5491
|
net = __toESM(require("net"));
|
|
4447
|
-
|
|
5492
|
+
path7 = __toESM(require("path"));
|
|
4448
5493
|
init_router();
|
|
4449
5494
|
init_config();
|
|
4450
|
-
MIN_PYTHON = [3,
|
|
5495
|
+
MIN_PYTHON = [3, 12];
|
|
4451
5496
|
DIAGNOSTIC_TAIL = 600;
|
|
4452
5497
|
BRIDGE_BOOTSTRAP = `import sys,runpy,types,os
|
|
4453
5498
|
root=sys.argv[1]
|
|
@@ -4459,7 +5504,6 @@ runpy.run_module('gatewaysdk.environment.schema.platform',run_name='__main__')`;
|
|
|
4459
5504
|
PYTHON_CANDIDATES = [
|
|
4460
5505
|
"python3.13",
|
|
4461
5506
|
"python3.12",
|
|
4462
|
-
"python3.11",
|
|
4463
5507
|
"python3",
|
|
4464
5508
|
"python"
|
|
4465
5509
|
];
|
|
@@ -4472,12 +5516,12 @@ function isBuildOutput(relPath) {
|
|
|
4472
5516
|
return BUILD_OUTPUT.test(relPath);
|
|
4473
5517
|
}
|
|
4474
5518
|
function readWorldFiles(dir, opts = {}) {
|
|
4475
|
-
if (!
|
|
5519
|
+
if (!fs8.existsSync(dir) || !fs8.statSync(dir).isDirectory())
|
|
4476
5520
|
throw new CliError(`Not a directory: ${dir}`);
|
|
4477
5521
|
const out = [];
|
|
4478
5522
|
const walk = (rel) => {
|
|
4479
|
-
const abs = rel ?
|
|
4480
|
-
const entries =
|
|
5523
|
+
const abs = rel ? path8.join(dir, rel) : dir;
|
|
5524
|
+
const entries = fs8.readdirSync(abs, { withFileTypes: true });
|
|
4481
5525
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
4482
5526
|
for (const entry of entries) {
|
|
4483
5527
|
const childRel = rel ? `${rel}/${entry.name}` : entry.name;
|
|
@@ -4487,7 +5531,7 @@ function readWorldFiles(dir, opts = {}) {
|
|
|
4487
5531
|
if (!opts.buildOutputs && isBuildOutput(childRel)) continue;
|
|
4488
5532
|
out.push({
|
|
4489
5533
|
path: childRel,
|
|
4490
|
-
content:
|
|
5534
|
+
content: fs8.readFileSync(path8.join(dir, childRel)).toString("base64")
|
|
4491
5535
|
});
|
|
4492
5536
|
}
|
|
4493
5537
|
}
|
|
@@ -4501,20 +5545,22 @@ function assertSafeRelPath(rel) {
|
|
|
4501
5545
|
throw new CliError(`The runtime returned an unsafe file path: ${rel}`, 1);
|
|
4502
5546
|
}
|
|
4503
5547
|
function writeWorldFiles(dir, files, opts = {}) {
|
|
5548
|
+
if (files.length > MAX_WORLD_FILES)
|
|
5549
|
+
throw new CliError(`The runtime returned ${files.length} files, over the ${MAX_WORLD_FILES} limit`, 1);
|
|
4504
5550
|
for (const file of files) assertSafeRelPath(file.path);
|
|
4505
|
-
if (opts.clean &&
|
|
5551
|
+
if (opts.clean && fs8.existsSync(dir)) {
|
|
4506
5552
|
const keep = new Set(files.map((f) => f.path));
|
|
4507
5553
|
for (const existing of readWorldFiles(dir)) {
|
|
4508
|
-
if (!keep.has(existing.path))
|
|
5554
|
+
if (!keep.has(existing.path)) fs8.rmSync(path8.join(dir, existing.path));
|
|
4509
5555
|
}
|
|
4510
5556
|
pruneEmptyDirs(dir);
|
|
4511
5557
|
}
|
|
4512
|
-
|
|
5558
|
+
fs8.mkdirSync(dir, { recursive: true });
|
|
4513
5559
|
const written = [];
|
|
4514
5560
|
for (const file of files) {
|
|
4515
|
-
const target =
|
|
4516
|
-
|
|
4517
|
-
|
|
5561
|
+
const target = path8.join(dir, file.path);
|
|
5562
|
+
fs8.mkdirSync(path8.dirname(target), { recursive: true });
|
|
5563
|
+
fs8.writeFileSync(target, Buffer.from(file.content, "base64"));
|
|
4518
5564
|
written.push(file.path);
|
|
4519
5565
|
}
|
|
4520
5566
|
return written;
|
|
@@ -4522,14 +5568,14 @@ function writeWorldFiles(dir, files, opts = {}) {
|
|
|
4522
5568
|
function pruneEmptyDirs(root) {
|
|
4523
5569
|
const walk = (abs) => {
|
|
4524
5570
|
let empty = true;
|
|
4525
|
-
for (const entry of
|
|
4526
|
-
const child =
|
|
5571
|
+
for (const entry of fs8.readdirSync(abs, { withFileTypes: true })) {
|
|
5572
|
+
const child = path8.join(abs, entry.name);
|
|
4527
5573
|
if (entry.isDirectory()) {
|
|
4528
5574
|
if (SKIP_DIRS.has(entry.name)) {
|
|
4529
5575
|
empty = false;
|
|
4530
5576
|
continue;
|
|
4531
5577
|
}
|
|
4532
|
-
if (walk(child))
|
|
5578
|
+
if (walk(child)) fs8.rmdirSync(child);
|
|
4533
5579
|
else empty = false;
|
|
4534
5580
|
} else empty = false;
|
|
4535
5581
|
}
|
|
@@ -4549,58 +5595,61 @@ function detailFrom(payload) {
|
|
|
4549
5595
|
if (typeof detail.code !== "string" || typeof detail.message !== "string") return null;
|
|
4550
5596
|
return detail;
|
|
4551
5597
|
}
|
|
5598
|
+
function isYamlSource(name, base64) {
|
|
5599
|
+
if (name.endsWith(".json")) return false;
|
|
5600
|
+
if (YAML_NAME.test(name)) return true;
|
|
5601
|
+
const head = Buffer.from(base64.slice(0, 256), "base64").toString("utf8").trimStart();
|
|
5602
|
+
return !["{", "["].includes(head[0] ?? "");
|
|
5603
|
+
}
|
|
5604
|
+
function yamlDocument(request) {
|
|
5605
|
+
if (request.command === "init-openapi")
|
|
5606
|
+
return isYamlSource(String(request.source ?? ""), String(request.document ?? ""));
|
|
5607
|
+
return request.command === "conform" && Array.isArray(request.openapi) && request.openapi.some((doc) => YAML_NAME.test(doc.path ?? ""));
|
|
5608
|
+
}
|
|
5609
|
+
function runsLocally(request) {
|
|
5610
|
+
const local = localRuntime();
|
|
5611
|
+
return local !== null && !(yamlDocument(request) && !localPythonHasYaml(local.python));
|
|
5612
|
+
}
|
|
4552
5613
|
async function runtime(creds, request, opts = {}) {
|
|
4553
5614
|
const local = localRuntime();
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
const
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
return payload;
|
|
5615
|
+
if (local && runsLocally(request)) {
|
|
5616
|
+
const payload2 = await localBridge(request, local, opts);
|
|
5617
|
+
const detail2 = detailFrom(payload2);
|
|
5618
|
+
if (detail2) throw new BridgeRejected(detail2);
|
|
5619
|
+
return payload2;
|
|
4560
5620
|
}
|
|
4561
5621
|
if (!creds)
|
|
4562
5622
|
throw new CliError(
|
|
4563
5623
|
"This needs the schema runtime (the CLI bundles it) or platform credentials (`gateway auth login`). " + localRuntimeReason()
|
|
4564
5624
|
);
|
|
4565
|
-
const controller = new AbortController();
|
|
4566
|
-
const timer = setTimeout(() => controller.abort(), opts.timeoutMs ?? 18e4);
|
|
4567
5625
|
const route = "/api/public/worlds/runtime";
|
|
5626
|
+
const res = await new PlatformTransport(creds).send("POST", route, request, {
|
|
5627
|
+
timeoutMs: opts.timeoutMs ?? RUNTIME_TIMEOUT_MS
|
|
5628
|
+
});
|
|
5629
|
+
let payload = null;
|
|
4568
5630
|
try {
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
"content-type": "application/json",
|
|
4573
|
-
accept: "application/json",
|
|
4574
|
-
authorization: "Basic " + Buffer.from(`${creds.publicKey}:${creds.secretKey}`).toString("base64")
|
|
4575
|
-
},
|
|
4576
|
-
body: JSON.stringify(request),
|
|
4577
|
-
signal: controller.signal
|
|
4578
|
-
});
|
|
4579
|
-
const text2 = await res.text();
|
|
4580
|
-
let payload = null;
|
|
4581
|
-
try {
|
|
4582
|
-
payload = text2 ? JSON.parse(text2) : {};
|
|
4583
|
-
} catch {
|
|
4584
|
-
payload = null;
|
|
4585
|
-
}
|
|
4586
|
-
const detail = detailFrom(payload);
|
|
4587
|
-
if (detail) throw new BridgeRejected(detail);
|
|
4588
|
-
if (!res.ok)
|
|
4589
|
-
throw new CliError(`POST ${route} (${request.command}) -> ${res.status}: ${text2.slice(0, 600)}`, 1);
|
|
4590
|
-
if (payload === null) throw new CliError(`POST ${route} (${request.command}) returned non-JSON`, 1);
|
|
4591
|
-
return payload;
|
|
4592
|
-
} finally {
|
|
4593
|
-
clearTimeout(timer);
|
|
5631
|
+
payload = res.text ? JSON.parse(res.text) : {};
|
|
5632
|
+
} catch {
|
|
5633
|
+
payload = null;
|
|
4594
5634
|
}
|
|
5635
|
+
const detail = detailFrom(payload);
|
|
5636
|
+
if (detail) throw new BridgeRejected(detail);
|
|
5637
|
+
if (!res.ok)
|
|
5638
|
+
throw new CliError(`POST ${route} (${request.command}) -> ${res.status}: ${res.text.slice(0, 600)}`, 1);
|
|
5639
|
+
if (payload === null) throw new CliError(`POST ${route} (${request.command}) returned non-JSON`, 1);
|
|
5640
|
+
return payload;
|
|
4595
5641
|
}
|
|
4596
|
-
var
|
|
5642
|
+
var fs8, path8, MAX_WORLD_FILES, RUNTIME_TIMEOUT_MS, SKIP_DIRS, BUILD_OUTPUT, BridgeRejected, YAML_NAME;
|
|
4597
5643
|
var init_client = __esm({
|
|
4598
5644
|
"src/cli/runtime/client.ts"() {
|
|
4599
5645
|
"use strict";
|
|
4600
|
-
|
|
4601
|
-
|
|
5646
|
+
fs8 = __toESM(require("fs"));
|
|
5647
|
+
path8 = __toESM(require("path"));
|
|
4602
5648
|
init_router();
|
|
4603
5649
|
init_local();
|
|
5650
|
+
init_transport();
|
|
5651
|
+
MAX_WORLD_FILES = 2e3;
|
|
5652
|
+
RUNTIME_TIMEOUT_MS = 18e4;
|
|
4604
5653
|
SKIP_DIRS = /* @__PURE__ */ new Set(["__pycache__", ".git", "node_modules", ".gateway"]);
|
|
4605
5654
|
BUILD_OUTPUT = /(^|\/)state\.(sqlite|json)$/;
|
|
4606
5655
|
BridgeRejected = class extends CliError {
|
|
@@ -4608,7 +5657,9 @@ var init_client = __esm({
|
|
|
4608
5657
|
super(formatBridgeError(detail), 1);
|
|
4609
5658
|
this.detail = detail;
|
|
4610
5659
|
}
|
|
5660
|
+
detail;
|
|
4611
5661
|
};
|
|
5662
|
+
YAML_NAME = /\.ya?ml$/i;
|
|
4612
5663
|
}
|
|
4613
5664
|
});
|
|
4614
5665
|
|
|
@@ -4616,8 +5667,10 @@ var init_client = __esm({
|
|
|
4616
5667
|
var data_exports = {};
|
|
4617
5668
|
__export(data_exports, {
|
|
4618
5669
|
checkLocalWorldData: () => checkLocalWorldData,
|
|
5670
|
+
chunkLocalWorldFiles: () => chunkLocalWorldFiles,
|
|
4619
5671
|
dropBuildOutputs: () => dropBuildOutputs,
|
|
4620
5672
|
importLocalWorldData: () => importLocalWorldData,
|
|
5673
|
+
importLocalWorldFiles: () => importLocalWorldFiles,
|
|
4621
5674
|
ingestLocalToolCalls: () => ingestLocalToolCalls,
|
|
4622
5675
|
queryLocalWorldData: () => queryLocalWorldData,
|
|
4623
5676
|
queryLocalWorldDataAcross: () => queryLocalWorldDataAcross,
|
|
@@ -4644,11 +5697,57 @@ async function importLocalWorldData(dir, rows, opts, creds) {
|
|
|
4644
5697
|
} : {}
|
|
4645
5698
|
};
|
|
4646
5699
|
}
|
|
5700
|
+
async function importLocalWorldFiles(dir, sources, opts) {
|
|
5701
|
+
const local = localRuntime();
|
|
5702
|
+
if (!local)
|
|
5703
|
+
throw new CliError(
|
|
5704
|
+
`Rows files stream into a directory through the bundled runtime on this machine, and none can run: ${localRuntimeReason()}`,
|
|
5705
|
+
1
|
|
5706
|
+
);
|
|
5707
|
+
const res = await runtime(null, {
|
|
5708
|
+
command: "import-files",
|
|
5709
|
+
world: path9.resolve(dir),
|
|
5710
|
+
sources: sources.map((source) => path9.resolve(source)),
|
|
5711
|
+
mode: opts.mode ?? "append",
|
|
5712
|
+
...opts.entity ? { entity: opts.entity } : {},
|
|
5713
|
+
...opts.delimiter ? { delimiter: opts.delimiter } : {},
|
|
5714
|
+
...opts.merge && opts.merge !== "upsert" ? { merge: opts.merge } : {},
|
|
5715
|
+
...opts.redact && opts.redact !== "off" ? { redact: opts.redact } : {},
|
|
5716
|
+
...opts.dryRun ? { dry_run: true } : {}
|
|
5717
|
+
});
|
|
5718
|
+
return {
|
|
5719
|
+
kind: res.kind ?? "unknown",
|
|
5720
|
+
entity_counts: res.entity_counts ?? {},
|
|
5721
|
+
changed: Boolean(res.changed),
|
|
5722
|
+
rows: res.rows ?? 0,
|
|
5723
|
+
...res.proof ? { proof: res.proof } : {},
|
|
5724
|
+
...res.deferred ? { deferred: res.deferred } : {}
|
|
5725
|
+
};
|
|
5726
|
+
}
|
|
5727
|
+
async function chunkLocalWorldFiles(dir, sources, out, opts) {
|
|
5728
|
+
const local = localRuntime();
|
|
5729
|
+
if (!local)
|
|
5730
|
+
throw new CliError(
|
|
5731
|
+
`Rows files are cut into chunks by the bundled runtime on this machine, and none can run: ${localRuntimeReason()}`,
|
|
5732
|
+
1
|
|
5733
|
+
);
|
|
5734
|
+
const res = await runtime(null, {
|
|
5735
|
+
command: "chunk-files",
|
|
5736
|
+
world: path9.resolve(dir),
|
|
5737
|
+
sources: sources.map((source) => path9.resolve(source)),
|
|
5738
|
+
out: path9.resolve(out),
|
|
5739
|
+
...opts.entity ? { entity: opts.entity } : {},
|
|
5740
|
+
...opts.delimiter ? { delimiter: opts.delimiter } : {},
|
|
5741
|
+
...opts.chunkBytes ? { chunk_bytes: opts.chunkBytes } : {},
|
|
5742
|
+
...opts.chunkRows ? { chunk_rows: opts.chunkRows } : {}
|
|
5743
|
+
});
|
|
5744
|
+
return { rows: res.rows ?? 0, chunks: res.chunks ?? [] };
|
|
5745
|
+
}
|
|
4647
5746
|
function dropBuildOutputs(dir) {
|
|
4648
5747
|
const dropped = [];
|
|
4649
5748
|
for (const file of readWorldFiles(dir, { buildOutputs: true })) {
|
|
4650
5749
|
if (!BUILD_OUTPUT2.test(file.path)) continue;
|
|
4651
|
-
|
|
5750
|
+
fs9.rmSync(path9.join(dir, file.path), { force: true });
|
|
4652
5751
|
dropped.push(file.path);
|
|
4653
5752
|
}
|
|
4654
5753
|
return dropped;
|
|
@@ -4715,7 +5814,7 @@ async function queryLocalWorldDataAcross(dir, entity, where, opts) {
|
|
|
4715
5814
|
const payload = await localBridge(
|
|
4716
5815
|
{
|
|
4717
5816
|
command: "query",
|
|
4718
|
-
world:
|
|
5817
|
+
world: path9.resolve(dir),
|
|
4719
5818
|
entity,
|
|
4720
5819
|
across: true,
|
|
4721
5820
|
...opts.compare ? { compare: true } : {},
|
|
@@ -4762,12 +5861,12 @@ async function ingestLocalToolCalls(dir, records, opts, creds) {
|
|
|
4762
5861
|
...res.batch !== void 0 ? { batch: res.batch } : {}
|
|
4763
5862
|
};
|
|
4764
5863
|
}
|
|
4765
|
-
var
|
|
5864
|
+
var fs9, path9, BUILD_OUTPUT2;
|
|
4766
5865
|
var init_data = __esm({
|
|
4767
5866
|
"src/cli/runtime/data.ts"() {
|
|
4768
5867
|
"use strict";
|
|
4769
|
-
|
|
4770
|
-
|
|
5868
|
+
fs9 = __toESM(require("fs"));
|
|
5869
|
+
path9 = __toESM(require("path"));
|
|
4771
5870
|
init_router();
|
|
4772
5871
|
init_client();
|
|
4773
5872
|
init_local();
|
|
@@ -4810,27 +5909,27 @@ function typescriptPrefix() {
|
|
|
4810
5909
|
}
|
|
4811
5910
|
}
|
|
4812
5911
|
function command(script, wrapperDir) {
|
|
4813
|
-
const suffix =
|
|
5912
|
+
const suffix = path10.extname(script).toLowerCase();
|
|
4814
5913
|
if (PYTHON_SUFFIXES.includes(suffix)) return { file: process.env.GATEWAY_PYTHON || "python3", args: ["-c", PY_WRAPPER, script] };
|
|
4815
5914
|
if (NODE_SUFFIXES.includes(suffix)) {
|
|
4816
|
-
const wrapper =
|
|
4817
|
-
|
|
5915
|
+
const wrapper = path10.join(wrapperDir, "transform-wrapper.mjs");
|
|
5916
|
+
fs10.writeFileSync(wrapper, NODE_WRAPPER);
|
|
4818
5917
|
const flags = suffix === ".ts" || suffix === ".mts" ? typescriptPrefix() : [];
|
|
4819
5918
|
return { file: process.env.GATEWAY_NODE || process.execPath, args: [...flags, wrapper, script] };
|
|
4820
5919
|
}
|
|
4821
|
-
throw new CliError(`${
|
|
5920
|
+
throw new CliError(`${path10.basename(script)}: a transform script is .py, .ts, .mjs, .js or .cjs`, 1);
|
|
4822
5921
|
}
|
|
4823
5922
|
async function runTransform(script, records, opts = {}) {
|
|
4824
|
-
if (!
|
|
4825
|
-
const resolved =
|
|
4826
|
-
const name =
|
|
5923
|
+
if (!fs10.existsSync(script) || !fs10.statSync(script).isFile()) throw new CliError(`no transform script at ${script}`, 1);
|
|
5924
|
+
const resolved = path10.resolve(script);
|
|
5925
|
+
const name = path10.basename(script);
|
|
4827
5926
|
const timeoutMs = opts.timeoutMs ?? DEFAULT_TRANSFORM_TIMEOUT_MS;
|
|
4828
|
-
const scratch =
|
|
5927
|
+
const scratch = fs10.mkdtempSync(path10.join(os2.tmpdir(), "gateway-transform-"));
|
|
4829
5928
|
try {
|
|
4830
5929
|
const { file, args } = command(resolved, scratch);
|
|
4831
5930
|
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !SCRUBBED.test(key)));
|
|
4832
|
-
const done = await new Promise((
|
|
4833
|
-
const child = (0,
|
|
5931
|
+
const done = await new Promise((resolve7, reject) => {
|
|
5932
|
+
const child = (0, import_node_child_process3.spawn)(file, args, { cwd: path10.dirname(resolved), env, stdio: ["pipe", "pipe", "pipe"] });
|
|
4834
5933
|
let stdout = "";
|
|
4835
5934
|
let stderr = "";
|
|
4836
5935
|
let timedOut = false;
|
|
@@ -4846,7 +5945,7 @@ async function runTransform(script, records, opts = {}) {
|
|
|
4846
5945
|
});
|
|
4847
5946
|
child.on("close", (code) => {
|
|
4848
5947
|
clearTimeout(timer);
|
|
4849
|
-
|
|
5948
|
+
resolve7({ code, stdout, stderr, timedOut });
|
|
4850
5949
|
});
|
|
4851
5950
|
child.stdin.on("error", () => void 0);
|
|
4852
5951
|
child.stdin.end(records.map((record) => JSON.stringify(record) + "\n").join(""));
|
|
@@ -4861,21 +5960,21 @@ async function runTransform(script, records, opts = {}) {
|
|
|
4861
5960
|
}
|
|
4862
5961
|
return { rows: checkRows(value, name), stderr: done.stderr };
|
|
4863
5962
|
} finally {
|
|
4864
|
-
|
|
5963
|
+
fs10.rmSync(scratch, { recursive: true, force: true });
|
|
4865
5964
|
}
|
|
4866
5965
|
}
|
|
4867
5966
|
async function transformRecords(transform, records, opts = {}) {
|
|
4868
5967
|
if (typeof transform === "function") return { rows: checkRows(await transform(records), "transform(records)"), stderr: "" };
|
|
4869
5968
|
return runTransform(transform, records, opts);
|
|
4870
5969
|
}
|
|
4871
|
-
var
|
|
5970
|
+
var import_node_child_process3, fs10, os2, path10, import_node_module, import_meta, DEFAULT_TRANSFORM_TIMEOUT_MS, NODE_SUFFIXES, PYTHON_SUFFIXES, SCRUBBED, PY_WRAPPER, NODE_WRAPPER, isObject, tail;
|
|
4872
5971
|
var init_transform = __esm({
|
|
4873
5972
|
"src/cli/platform/worldData/transform.ts"() {
|
|
4874
5973
|
"use strict";
|
|
4875
|
-
|
|
4876
|
-
|
|
5974
|
+
import_node_child_process3 = require("child_process");
|
|
5975
|
+
fs10 = __toESM(require("fs"));
|
|
4877
5976
|
os2 = __toESM(require("os"));
|
|
4878
|
-
|
|
5977
|
+
path10 = __toESM(require("path"));
|
|
4879
5978
|
import_node_module = require("module");
|
|
4880
5979
|
init_router();
|
|
4881
5980
|
import_meta = {};
|
|
@@ -5014,12 +6113,12 @@ function phaseLine(status) {
|
|
|
5014
6113
|
const phase = status.progress?.phase;
|
|
5015
6114
|
return phase ? `${status.state} (${phase})` : status.state;
|
|
5016
6115
|
}
|
|
5017
|
-
var import_node_crypto8,
|
|
6116
|
+
var import_node_crypto8, fs11, TERMINAL_STATES, sleepMs, WorldDataApi;
|
|
5018
6117
|
var init_batches = __esm({
|
|
5019
6118
|
"src/cli/platform/worldData/batches.ts"() {
|
|
5020
6119
|
"use strict";
|
|
5021
6120
|
import_node_crypto8 = require("crypto");
|
|
5022
|
-
|
|
6121
|
+
fs11 = __toESM(require("fs"));
|
|
5023
6122
|
init_config();
|
|
5024
6123
|
init_router();
|
|
5025
6124
|
TERMINAL_STATES = /* @__PURE__ */ new Set([
|
|
@@ -5028,7 +6127,7 @@ var init_batches = __esm({
|
|
|
5028
6127
|
"published",
|
|
5029
6128
|
"failed"
|
|
5030
6129
|
]);
|
|
5031
|
-
sleepMs = (ms) => new Promise((
|
|
6130
|
+
sleepMs = (ms) => new Promise((resolve7) => setTimeout(resolve7, ms));
|
|
5032
6131
|
WorldDataApi = class {
|
|
5033
6132
|
constructor(creds, slug, sleep2 = sleepMs) {
|
|
5034
6133
|
this.creds = creds;
|
|
@@ -5036,6 +6135,9 @@ var init_batches = __esm({
|
|
|
5036
6135
|
this.sleep = sleep2;
|
|
5037
6136
|
this.base = `/api/public/worlds/${encodeURIComponent(slug)}/data`;
|
|
5038
6137
|
}
|
|
6138
|
+
creds;
|
|
6139
|
+
slug;
|
|
6140
|
+
sleep;
|
|
5039
6141
|
base;
|
|
5040
6142
|
open(body) {
|
|
5041
6143
|
return api(this.creds, "POST", `${this.base}/batches`, body);
|
|
@@ -5234,7 +6336,7 @@ function gzipDeterministic(raw, opts = {}) {
|
|
|
5234
6336
|
level === 9 ? 2 : level === 1 ? 4 : 0,
|
|
5235
6337
|
255
|
|
5236
6338
|
]);
|
|
5237
|
-
const body = (0,
|
|
6339
|
+
const body = (0, import_node_zlib3.deflateRawSync)(raw, { level });
|
|
5238
6340
|
const trailer = Buffer.alloc(8);
|
|
5239
6341
|
trailer.writeUInt32LE(crc32(raw), 0);
|
|
5240
6342
|
trailer.writeUInt32LE(raw.length >>> 0, 4);
|
|
@@ -5254,12 +6356,12 @@ function crc32(data) {
|
|
|
5254
6356
|
crc = table[(crc ^ data[i]) & 255] ^ crc >>> 8;
|
|
5255
6357
|
return (crc ^ 4294967295) >>> 0;
|
|
5256
6358
|
}
|
|
5257
|
-
var import_node_crypto9,
|
|
6359
|
+
var import_node_crypto9, import_node_zlib3, DEFAULT_CHUNK_BYTES, GZIP_LEVEL, chunkName, table;
|
|
5258
6360
|
var init_chunker = __esm({
|
|
5259
6361
|
"src/cli/platform/worldData/chunker.ts"() {
|
|
5260
6362
|
"use strict";
|
|
5261
6363
|
import_node_crypto9 = require("crypto");
|
|
5262
|
-
|
|
6364
|
+
import_node_zlib3 = require("zlib");
|
|
5263
6365
|
init_json();
|
|
5264
6366
|
DEFAULT_CHUNK_BYTES = 64 * 1024 * 1024;
|
|
5265
6367
|
GZIP_LEVEL = 9;
|
|
@@ -5331,7 +6433,7 @@ function parseToolCallRecord(raw) {
|
|
|
5331
6433
|
}
|
|
5332
6434
|
function readToolCallRecords(paths) {
|
|
5333
6435
|
const records = [];
|
|
5334
|
-
for (const file of paths) records.push(...toolCallRecordsIn(
|
|
6436
|
+
for (const file of paths) records.push(...toolCallRecordsIn(fs12.readFileSync(file, "utf8"), file));
|
|
5335
6437
|
return records;
|
|
5336
6438
|
}
|
|
5337
6439
|
function toolCallRecordsIn(text2, where) {
|
|
@@ -5367,7 +6469,7 @@ async function emit(sink, record) {
|
|
|
5367
6469
|
return;
|
|
5368
6470
|
}
|
|
5369
6471
|
if (typeof sink === "string") {
|
|
5370
|
-
|
|
6472
|
+
fs12.appendFileSync(sink, JSON.stringify(record) + "\n");
|
|
5371
6473
|
return;
|
|
5372
6474
|
}
|
|
5373
6475
|
if (typeof sink === "function") {
|
|
@@ -5447,7 +6549,7 @@ async function ingest(world, records, options = {}) {
|
|
|
5447
6549
|
const mode = options.mode ?? "append";
|
|
5448
6550
|
const dryRun = Boolean(options.dryRun);
|
|
5449
6551
|
const creds = credentialsOf(options);
|
|
5450
|
-
const local =
|
|
6552
|
+
const local = fs12.existsSync(world) && fs12.statSync(world).isDirectory();
|
|
5451
6553
|
const map = options.map === void 0 ? void 0 : options.map;
|
|
5452
6554
|
let rows = null;
|
|
5453
6555
|
let stderr = "";
|
|
@@ -5463,9 +6565,9 @@ async function ingest(world, records, options = {}) {
|
|
|
5463
6565
|
if (!creds) throw new Error("Gateway keys missing: set GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY (or pass publicKey/secretKey).");
|
|
5464
6566
|
const { pull: pull2 } = await Promise.resolve().then(() => (init_hub(), hub_exports));
|
|
5465
6567
|
const slug = world.split("@", 1)[0];
|
|
5466
|
-
const scratch =
|
|
6568
|
+
const scratch = fs12.mkdtempSync(path11.join(os3.tmpdir(), "gateway-ingest-"));
|
|
5467
6569
|
try {
|
|
5468
|
-
const pulled = await pull2(world,
|
|
6570
|
+
const pulled = await pull2(world, path11.join(scratch, slug), options);
|
|
5469
6571
|
let report;
|
|
5470
6572
|
let projected;
|
|
5471
6573
|
if (rows === null) {
|
|
@@ -5486,7 +6588,7 @@ async function ingest(world, records, options = {}) {
|
|
|
5486
6588
|
if (status.entityCounts) report.entityCounts = status.entityCounts;
|
|
5487
6589
|
return report;
|
|
5488
6590
|
} finally {
|
|
5489
|
-
|
|
6591
|
+
fs12.rmSync(scratch, { recursive: true, force: true });
|
|
5490
6592
|
}
|
|
5491
6593
|
}
|
|
5492
6594
|
async function ingestToolCalls(world, records, options = {}) {
|
|
@@ -5539,66 +6641,139 @@ async function sessionToolObservations(sessionId, options = {}) {
|
|
|
5539
6641
|
for (const observation of trace3.observations ?? []) out.push({ traceId: trace3.id ?? null, ...observation });
|
|
5540
6642
|
return out;
|
|
5541
6643
|
}
|
|
5542
|
-
var
|
|
6644
|
+
var fs12, os3, path11, isObject2, isoOf;
|
|
5543
6645
|
var init_ingest = __esm({
|
|
5544
6646
|
"src/worlds/ingest.ts"() {
|
|
5545
6647
|
"use strict";
|
|
5546
|
-
|
|
6648
|
+
fs12 = __toESM(require("fs"));
|
|
5547
6649
|
os3 = __toESM(require("os"));
|
|
5548
|
-
|
|
6650
|
+
path11 = __toESM(require("path"));
|
|
5549
6651
|
init_worlds();
|
|
5550
6652
|
isObject2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5551
6653
|
isoOf = (value) => value instanceof Date ? value.toISOString() : typeof value === "string" ? value : void 0;
|
|
5552
6654
|
}
|
|
5553
6655
|
});
|
|
5554
6656
|
|
|
5555
|
-
// src/worlds/
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
return { slug: slugRef.slice(0, at), ref: slugRef.slice(at + 1) };
|
|
5560
|
-
}
|
|
5561
|
-
var sid, WorldSandboxClient;
|
|
5562
|
-
var init_sandbox = __esm({
|
|
5563
|
-
"src/worlds/sandbox.ts"() {
|
|
6657
|
+
// src/worlds/editSessions.ts
|
|
6658
|
+
var WORLDS, WorldEditClient;
|
|
6659
|
+
var init_editSessions = __esm({
|
|
6660
|
+
"src/worlds/editSessions.ts"() {
|
|
5564
6661
|
"use strict";
|
|
5565
6662
|
init_worlds();
|
|
5566
|
-
|
|
5567
|
-
|
|
6663
|
+
WORLDS = "/api/public/worlds";
|
|
6664
|
+
WorldEditClient = class {
|
|
5568
6665
|
constructor(options = {}) {
|
|
5569
6666
|
this.options = options;
|
|
5570
6667
|
}
|
|
5571
|
-
|
|
5572
|
-
|
|
6668
|
+
options;
|
|
6669
|
+
/** The credential's current session and the world's newest-first sessions. */
|
|
6670
|
+
list(slug, query = {}) {
|
|
6671
|
+
const qs = new URLSearchParams();
|
|
6672
|
+
if (query.status) qs.set("status", query.status);
|
|
6673
|
+
if (query.limit !== void 0) qs.set("limit", String(query.limit));
|
|
6674
|
+
const suffix = qs.size ? `?${qs.toString()}` : "";
|
|
6675
|
+
return apiRequest(this.options, "GET", `${WORLDS}/${encodeURIComponent(slug)}/edits${suffix}`);
|
|
5573
6676
|
}
|
|
5574
|
-
|
|
5575
|
-
|
|
6677
|
+
/** Seal a session into a version on main (the credential's current one when `sessionId` is omitted). */
|
|
6678
|
+
close(slug, input = {}) {
|
|
6679
|
+
return apiRequest(this.options, "POST", `${WORLDS}/${encodeURIComponent(slug)}/edits/close`, input);
|
|
5576
6680
|
}
|
|
5577
|
-
|
|
5578
|
-
|
|
6681
|
+
/** Drop the session's private branch without making a version. */
|
|
6682
|
+
discard(slug, input = {}) {
|
|
6683
|
+
return apiRequest(this.options, "POST", `${WORLDS}/${encodeURIComponent(slug)}/edits/discard`, input);
|
|
6684
|
+
}
|
|
6685
|
+
/** Undo a sealed session (source and data) as a new sealed session. */
|
|
6686
|
+
rollback(slug, input) {
|
|
6687
|
+
return apiRequest(this.options, "POST", `${WORLDS}/${encodeURIComponent(slug)}/edits/rollback`, input);
|
|
6688
|
+
}
|
|
6689
|
+
};
|
|
6690
|
+
}
|
|
6691
|
+
});
|
|
6692
|
+
|
|
6693
|
+
// src/worlds/dryRun.ts
|
|
6694
|
+
var DRY_RUN_KIND, DRY_RUN_AGENT, STATUS_WAIT_CAP_SECONDS, cid, HostedDryRunClient, DryRunOutcome;
|
|
6695
|
+
var init_dryRun = __esm({
|
|
6696
|
+
"src/worlds/dryRun.ts"() {
|
|
6697
|
+
"use strict";
|
|
6698
|
+
init_worlds();
|
|
6699
|
+
DRY_RUN_KIND = "dry-run";
|
|
6700
|
+
DRY_RUN_AGENT = "oracle";
|
|
6701
|
+
STATUS_WAIT_CAP_SECONDS = 50;
|
|
6702
|
+
cid = (id) => `/api/public/environments/${encodeURIComponent(id)}`;
|
|
6703
|
+
HostedDryRunClient = class {
|
|
6704
|
+
constructor(options = {}) {
|
|
6705
|
+
this.options = options;
|
|
6706
|
+
}
|
|
6707
|
+
options;
|
|
6708
|
+
/** Dispatch ONE oracle job for `task` on `containerId` (a container id, not a slug); pins `versionId` when given. */
|
|
6709
|
+
dispatch(target) {
|
|
6710
|
+
return apiRequest(
|
|
5579
6711
|
this.options,
|
|
5580
|
-
"
|
|
5581
|
-
|
|
6712
|
+
"POST",
|
|
6713
|
+
`${cid(target.containerId)}/dry-run`,
|
|
6714
|
+
{
|
|
6715
|
+
task: target.task,
|
|
6716
|
+
...target.versionId ? { versionId: target.versionId } : {}
|
|
6717
|
+
}
|
|
5582
6718
|
);
|
|
5583
|
-
return { path: res.path, size: res.size, bytes: Buffer.from(res.contentBase64, "base64") };
|
|
5584
|
-
}
|
|
5585
|
-
write(sandboxId, filePath, bytes) {
|
|
5586
|
-
return apiRequest(this.options, "PUT", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/file`, {
|
|
5587
|
-
path: filePath,
|
|
5588
|
-
contentBase64: bytes.toString("base64")
|
|
5589
|
-
});
|
|
5590
6719
|
}
|
|
5591
|
-
|
|
5592
|
-
|
|
6720
|
+
/** One status read, blocking server-side for up to `waitSeconds` (capped). */
|
|
6721
|
+
status(runId, waitSeconds = 0) {
|
|
6722
|
+
const wait = Math.max(
|
|
6723
|
+
0,
|
|
6724
|
+
Math.min(Math.floor(waitSeconds), STATUS_WAIT_CAP_SECONDS)
|
|
6725
|
+
);
|
|
6726
|
+
const suffix = wait ? `?waitSeconds=${wait}` : "";
|
|
6727
|
+
return apiRequest(
|
|
6728
|
+
this.options,
|
|
6729
|
+
"GET",
|
|
6730
|
+
`/api/public/environments/runs/${encodeURIComponent(runId)}${suffix}`
|
|
6731
|
+
);
|
|
5593
6732
|
}
|
|
5594
|
-
|
|
5595
|
-
|
|
6733
|
+
/** Poll until the run settles or `timeoutSeconds` pass; the last verdict either way. */
|
|
6734
|
+
async settle(runId, opts) {
|
|
6735
|
+
const now = opts.now ?? Date.now;
|
|
6736
|
+
const sleep2 = opts.sleep ?? ((ms) => new Promise((resolve7) => setTimeout(resolve7, ms)));
|
|
6737
|
+
const deadline = now() + opts.timeoutSeconds * 1e3;
|
|
6738
|
+
for (; ; ) {
|
|
6739
|
+
const budget = Math.floor(
|
|
6740
|
+
Math.min(45, Math.max(0, (deadline - now()) / 1e3))
|
|
6741
|
+
);
|
|
6742
|
+
const asked = now();
|
|
6743
|
+
const verdict = await this.status(runId, budget);
|
|
6744
|
+
if (verdict.settled || now() >= deadline) return verdict;
|
|
6745
|
+
opts.onProgress?.(verdict);
|
|
6746
|
+
if (now() - asked < 1e3) await sleep2(1e3);
|
|
6747
|
+
}
|
|
5596
6748
|
}
|
|
5597
|
-
|
|
5598
|
-
|
|
6749
|
+
};
|
|
6750
|
+
DryRunOutcome = class {
|
|
6751
|
+
constructor(verdict) {
|
|
6752
|
+
this.verdict = verdict;
|
|
6753
|
+
}
|
|
6754
|
+
verdict;
|
|
6755
|
+
get settlement() {
|
|
6756
|
+
return this.verdict.dryRun?.settlement ?? null;
|
|
6757
|
+
}
|
|
6758
|
+
/** Why the dry run did not pass, or null when it did. */
|
|
6759
|
+
reason() {
|
|
6760
|
+
if (!this.verdict.settled) return `still running after the wait`;
|
|
6761
|
+
const settlement = this.settlement;
|
|
6762
|
+
if (!settlement)
|
|
6763
|
+
return `the runner filed no settlement (${this.verdict.status})`;
|
|
6764
|
+
const lastErrorLine = settlement.errorTail?.trim().split("\n").at(-1) || null;
|
|
6765
|
+
if (settlement.exitCode !== null && settlement.exitCode !== 0)
|
|
6766
|
+
return `the runner failed (exit ${settlement.exitCode}): ${lastErrorLine ?? "harbor exited non-zero"}`;
|
|
6767
|
+
if (settlement.reward === null && lastErrorLine)
|
|
6768
|
+
return `the runner failed (exit ?): ${lastErrorLine}`;
|
|
6769
|
+
if (settlement.reward === null)
|
|
6770
|
+
return "ungraded: the grader ran but wrote no reward";
|
|
6771
|
+
if (settlement.reward !== 1)
|
|
6772
|
+
return `the reference solution scored ${settlement.reward}, not 1.0`;
|
|
6773
|
+
return null;
|
|
5599
6774
|
}
|
|
5600
|
-
|
|
5601
|
-
return
|
|
6775
|
+
passed() {
|
|
6776
|
+
return this.reason() === null;
|
|
5602
6777
|
}
|
|
5603
6778
|
};
|
|
5604
6779
|
}
|
|
@@ -5607,23 +6782,53 @@ var init_sandbox = __esm({
|
|
|
5607
6782
|
// src/worlds/index.ts
|
|
5608
6783
|
var worlds_exports = {};
|
|
5609
6784
|
__export(worlds_exports, {
|
|
5610
|
-
ApiError: () =>
|
|
6785
|
+
ApiError: () => ApiError,
|
|
6786
|
+
BROWSER_GONE_PATTERNS: () => BROWSER_GONE_PATTERNS,
|
|
6787
|
+
BROWSER_TIERS: () => BROWSER_TIERS,
|
|
5611
6788
|
BrowserActionRecorder: () => BrowserActionRecorder,
|
|
6789
|
+
BrowserReconnected: () => BrowserReconnected,
|
|
6790
|
+
BrowserReconnector: () => BrowserReconnector,
|
|
6791
|
+
BrowserUnrecoverable: () => BrowserUnrecoverable,
|
|
6792
|
+
CALL_BODY_LIMIT_BYTES: () => CALL_BODY_LIMIT_BYTES,
|
|
6793
|
+
CALL_BODY_LIMIT_LABEL: () => CALL_BODY_LIMIT_LABEL,
|
|
5612
6794
|
COMPUTER_USE_SPECS: () => COMPUTER_USE_SPECS,
|
|
6795
|
+
CheckoutProvenance: () => CheckoutProvenance,
|
|
5613
6796
|
DEFAULT_BRANCH: () => DEFAULT_BRANCH,
|
|
5614
6797
|
DEFAULT_VIEWPORT: () => DEFAULT_VIEWPORT,
|
|
6798
|
+
DRY_RUN_AGENT: () => DRY_RUN_AGENT,
|
|
6799
|
+
DRY_RUN_KIND: () => DRY_RUN_KIND,
|
|
6800
|
+
DetachedPushError: () => DetachedPushError,
|
|
6801
|
+
DryRunOutcome: () => DryRunOutcome,
|
|
5615
6802
|
EVENT_BATCH_SIZE: () => EVENT_BATCH_SIZE,
|
|
5616
6803
|
EVENT_FLUSH_INTERVAL_MS: () => EVENT_FLUSH_INTERVAL_MS,
|
|
5617
6804
|
EVENT_MAX_RETRIES: () => EVENT_MAX_RETRIES,
|
|
6805
|
+
EXPLORATORY_TASK: () => EXPLORATORY_TASK,
|
|
6806
|
+
EXPLORATORY_TASK_SOURCE: () => EXPLORATORY_TASK_SOURCE,
|
|
5618
6807
|
GatewayEvalsClient: () => GatewayEvalsClient,
|
|
6808
|
+
HostedDryRunClient: () => HostedDryRunClient,
|
|
6809
|
+
IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
|
|
6810
|
+
NO_GRADER_REASON: () => NO_GRADER_REASON,
|
|
6811
|
+
PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
6812
|
+
PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
|
|
6813
|
+
PlatformTransport: () => PlatformTransport,
|
|
5619
6814
|
PushSlugConflict: () => PushSlugConflict,
|
|
6815
|
+
RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
|
|
6816
|
+
SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
|
|
6817
|
+
SESSION_STATES: () => SESSION_STATES,
|
|
6818
|
+
STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
|
|
5620
6819
|
STRIP_PREFIX: () => STRIP_PREFIX,
|
|
5621
6820
|
SURFACE_KINDS: () => SURFACE_KINDS,
|
|
6821
|
+
SecretScrubber: () => SecretScrubber,
|
|
5622
6822
|
TRANSFORMS: () => TRANSFORMS,
|
|
5623
6823
|
TaskRun: () => TaskRun,
|
|
5624
6824
|
TaskSessions: () => TaskSessions,
|
|
6825
|
+
TransportCause: () => TransportCause,
|
|
6826
|
+
UnreachableError: () => UnreachableError,
|
|
6827
|
+
VERIFIER_REWARD_PREFIX: () => VERIFIER_REWARD_PREFIX,
|
|
5625
6828
|
WHITESPACE: () => WHITESPACE,
|
|
5626
6829
|
WorldBrowser: () => WorldBrowser,
|
|
6830
|
+
WorldCallTooLarge: () => WorldCallTooLarge,
|
|
6831
|
+
WorldEditClient: () => WorldEditClient,
|
|
5627
6832
|
WorldSandboxClient: () => WorldSandboxClient,
|
|
5628
6833
|
WorldSession: () => WorldSession,
|
|
5629
6834
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
@@ -5635,12 +6840,16 @@ __export(worlds_exports, {
|
|
|
5635
6840
|
apiRequest: () => apiRequest,
|
|
5636
6841
|
applyTransforms: () => applyTransforms,
|
|
5637
6842
|
archiveMode: () => archiveMode,
|
|
6843
|
+
assertBrowserTier: () => assertBrowserTier,
|
|
6844
|
+
assertTaskRef: () => assertTaskRef,
|
|
5638
6845
|
attachManifest: () => attachManifest,
|
|
5639
6846
|
attachSession: () => attachSession,
|
|
5640
6847
|
attachTask: () => attachTask,
|
|
5641
6848
|
buildFileManifest: () => buildFileManifest,
|
|
5642
6849
|
buildSourceTarball: () => buildSourceTarball,
|
|
5643
6850
|
captureToolCalls: () => captureToolCalls,
|
|
6851
|
+
checkoutIdentity: () => checkoutIdentity,
|
|
6852
|
+
closeConnection: () => closeConnection,
|
|
5644
6853
|
collectArchiveRelPaths: () => collectArchiveRelPaths,
|
|
5645
6854
|
computeContentHash: () => computeContentHash,
|
|
5646
6855
|
computerUseToolkit: () => computerUseToolkit,
|
|
@@ -5654,13 +6863,18 @@ __export(worlds_exports, {
|
|
|
5654
6863
|
getRun: () => getRun,
|
|
5655
6864
|
getTask: () => getTask,
|
|
5656
6865
|
hashForm: () => hashForm,
|
|
6866
|
+
idleWarning: () => idleWarning,
|
|
5657
6867
|
ingest: () => ingest,
|
|
5658
6868
|
ingestToolCalls: () => ingestToolCalls,
|
|
6869
|
+
isBrowserGone: () => isBrowserGone,
|
|
6870
|
+
isSandboxImportPending: () => isSandboxImportPending,
|
|
5659
6871
|
isTaskIdRef: () => isTaskIdRef,
|
|
5660
6872
|
isTaskManifest: () => isTaskManifest,
|
|
5661
6873
|
isTaskSpec: () => isTaskSpec,
|
|
5662
6874
|
listEnvSecretKeys: () => listEnvSecretKeys,
|
|
5663
6875
|
listRunConfigs: () => listRunConfigs,
|
|
6876
|
+
listRuns: () => listRuns,
|
|
6877
|
+
listSessions: () => listSessions,
|
|
5664
6878
|
listTaskSessions: () => listTaskSessions,
|
|
5665
6879
|
listTasks: () => listTasks,
|
|
5666
6880
|
localTreeState: () => localTreeState,
|
|
@@ -5672,28 +6886,35 @@ __export(worlds_exports, {
|
|
|
5672
6886
|
openTask: () => openTask,
|
|
5673
6887
|
openWorld: () => openWorld,
|
|
5674
6888
|
openWorldVersion: () => openWorldVersion,
|
|
6889
|
+
parseErrorBody: () => parseErrorBody,
|
|
5675
6890
|
parseSlugRef: () => parseSlugRef,
|
|
5676
6891
|
parseToolCallRecord: () => parseToolCallRecord,
|
|
5677
6892
|
parseTransform: () => parseTransform,
|
|
5678
6893
|
parseWorldTaskRefs: () => parseWorldTaskRefs,
|
|
6894
|
+
platformTimeoutMs: () => platformTimeoutMs,
|
|
5679
6895
|
preserveForm: () => preserveForm,
|
|
5680
6896
|
propose: () => propose,
|
|
5681
6897
|
pull: () => pull,
|
|
5682
6898
|
push: () => push,
|
|
6899
|
+
pushBranch: () => pushBranch,
|
|
5683
6900
|
pushSlug: () => pushSlug,
|
|
5684
6901
|
pyText: () => pyText,
|
|
5685
6902
|
queryRows: () => queryRows,
|
|
5686
6903
|
queryRowsSearch: () => queryRowsSearch,
|
|
5687
6904
|
readLocalMeta: () => readLocalMeta,
|
|
5688
6905
|
readToolCallRecords: () => readToolCallRecords,
|
|
6906
|
+
rebaseConflicts: () => rebaseConflicts,
|
|
5689
6907
|
redactActionArgs: () => redactActionArgs,
|
|
5690
6908
|
redactionOf: () => redactionOf,
|
|
6909
|
+
releaseConnection: () => releaseConnection,
|
|
5691
6910
|
resolveBrowserMode: () => resolveBrowserMode,
|
|
5692
6911
|
resolvePushSlug: () => resolvePushSlug,
|
|
5693
6912
|
roundForm: () => roundForm,
|
|
5694
6913
|
runSessions: () => runSessions,
|
|
6914
|
+
runSet: () => runSet,
|
|
5695
6915
|
runTask: () => runTask,
|
|
5696
6916
|
schemaFromSignature: () => schemaFromSignature,
|
|
6917
|
+
serializeCallBody: () => serializeCallBody,
|
|
5697
6918
|
sessionToolObservations: () => sessionToolObservations,
|
|
5698
6919
|
setEnvSecret: () => setEnvSecret,
|
|
5699
6920
|
shapeText: () => shapeText,
|
|
@@ -5705,6 +6926,7 @@ __export(worlds_exports, {
|
|
|
5705
6926
|
toolCallsFromObservations: () => toolCallsFromObservations,
|
|
5706
6927
|
uiEntryUrl: () => uiEntryUrl,
|
|
5707
6928
|
uiUrl: () => uiUrl,
|
|
6929
|
+
uncommittedPaths: () => uncommittedPaths,
|
|
5708
6930
|
updateTask: () => updateTask,
|
|
5709
6931
|
upsertRunConfig: () => upsertRunConfig,
|
|
5710
6932
|
validateTask: () => validateTask,
|
|
@@ -5725,19 +6947,29 @@ function resolveEnv(options) {
|
|
|
5725
6947
|
}
|
|
5726
6948
|
return { host: host.replace(/\/+$/, ""), publicKey, secretKey };
|
|
5727
6949
|
}
|
|
5728
|
-
|
|
5729
|
-
const {
|
|
5730
|
-
|
|
5731
|
-
|
|
5732
|
-
|
|
5733
|
-
|
|
5734
|
-
|
|
5735
|
-
|
|
5736
|
-
|
|
5737
|
-
}
|
|
5738
|
-
const
|
|
5739
|
-
if (
|
|
5740
|
-
|
|
6950
|
+
function parseErrorBody(text2, limit = 600) {
|
|
6951
|
+
const raw = { detail: text2.slice(0, limit), code: null };
|
|
6952
|
+
let parsed;
|
|
6953
|
+
try {
|
|
6954
|
+
parsed = JSON.parse(text2);
|
|
6955
|
+
} catch {
|
|
6956
|
+
return raw;
|
|
6957
|
+
}
|
|
6958
|
+
if (parsed === null || typeof parsed !== "object") return raw;
|
|
6959
|
+
const { message, code } = parsed;
|
|
6960
|
+
const stableCode = typeof code === "string" ? code : null;
|
|
6961
|
+
if (typeof message !== "string") return { ...raw, code: stableCode };
|
|
6962
|
+
if (stableCode === null)
|
|
6963
|
+
return { detail: message.slice(0, limit), code: null };
|
|
6964
|
+
return {
|
|
6965
|
+
detail: `${message} (${stableCode})`.slice(0, limit),
|
|
6966
|
+
code: stableCode
|
|
6967
|
+
};
|
|
6968
|
+
}
|
|
6969
|
+
async function apiRequest(options, method, path12, body, init2 = {}) {
|
|
6970
|
+
const reply = await new PlatformTransport(resolveEnv(options)).send(method, path12, body, init2);
|
|
6971
|
+
if (!reply.ok) throw new ApiError(reply.status, method, path12, reply.text);
|
|
6972
|
+
return JSON.parse(reply.text);
|
|
5741
6973
|
}
|
|
5742
6974
|
async function setEnvSecret(slug, key, value, options = {}) {
|
|
5743
6975
|
return apiRequest(
|
|
@@ -5807,6 +7039,19 @@ async function getRun(runId, options = {}) {
|
|
|
5807
7039
|
`/api/public/benchmark-containers/runs/${encodeURIComponent(runId)}`
|
|
5808
7040
|
);
|
|
5809
7041
|
}
|
|
7042
|
+
async function listRuns(filter = {}, options = {}) {
|
|
7043
|
+
const params = new URLSearchParams();
|
|
7044
|
+
if (filter.slug) params.set("slug", filter.slug);
|
|
7045
|
+
if (filter.status) params.set("status", filter.status);
|
|
7046
|
+
if (filter.limit !== void 0) params.set("limit", String(filter.limit));
|
|
7047
|
+
const qs = params.toString();
|
|
7048
|
+
const res = await apiRequest(
|
|
7049
|
+
options,
|
|
7050
|
+
"GET",
|
|
7051
|
+
`/api/public/benchmark-containers/runs${qs ? `?${qs}` : ""}`
|
|
7052
|
+
);
|
|
7053
|
+
return res.runs;
|
|
7054
|
+
}
|
|
5810
7055
|
async function waitForRun(runId, opts = {}) {
|
|
5811
7056
|
const deadline = Date.now() + (opts.timeoutMinutes ?? 45) * 6e4;
|
|
5812
7057
|
for (; ; ) {
|
|
@@ -5818,7 +7063,7 @@ async function waitForRun(runId, opts = {}) {
|
|
|
5818
7063
|
);
|
|
5819
7064
|
opts.onTick?.(run);
|
|
5820
7065
|
await new Promise(
|
|
5821
|
-
(
|
|
7066
|
+
(resolve7) => setTimeout(resolve7, (opts.intervalSeconds ?? 20) * 1e3)
|
|
5822
7067
|
);
|
|
5823
7068
|
}
|
|
5824
7069
|
}
|
|
@@ -5841,8 +7086,8 @@ function detectProvenance() {
|
|
|
5841
7086
|
}
|
|
5842
7087
|
if (!out.branch || !out.commit) {
|
|
5843
7088
|
try {
|
|
5844
|
-
const { execFileSync } = require("child_process");
|
|
5845
|
-
const git = (args) =>
|
|
7089
|
+
const { execFileSync: execFileSync2 } = require("child_process");
|
|
7090
|
+
const git = (args) => execFileSync2("git", args, {
|
|
5846
7091
|
encoding: "utf-8",
|
|
5847
7092
|
stdio: ["ignore", "pipe", "ignore"]
|
|
5848
7093
|
}).toString().trim();
|
|
@@ -5900,15 +7145,23 @@ async function resolveWorld(slugRef, slug, ref, pin, options) {
|
|
|
5900
7145
|
}
|
|
5901
7146
|
return world;
|
|
5902
7147
|
}
|
|
5903
|
-
var
|
|
7148
|
+
var ApiError, WorldTask, WorldSet;
|
|
5904
7149
|
var init_worlds = __esm({
|
|
5905
7150
|
"src/worlds/index.ts"() {
|
|
7151
|
+
init_transport();
|
|
7152
|
+
init_transport();
|
|
5906
7153
|
init_session();
|
|
7154
|
+
init_sessionList();
|
|
7155
|
+
init_sessionContract();
|
|
7156
|
+
init_taskRef();
|
|
5907
7157
|
init_tasks();
|
|
5908
7158
|
init_taskSessions();
|
|
5909
7159
|
init_taskRun();
|
|
7160
|
+
init_setRun();
|
|
7161
|
+
init_checkoutProvenance();
|
|
5910
7162
|
init_evals();
|
|
5911
7163
|
init_browser();
|
|
7164
|
+
init_browserReconnect();
|
|
5912
7165
|
init_hub();
|
|
5913
7166
|
init_validate();
|
|
5914
7167
|
init_describe();
|
|
@@ -5918,12 +7171,20 @@ var init_worlds = __esm({
|
|
|
5918
7171
|
init_migrate();
|
|
5919
7172
|
init_ingest();
|
|
5920
7173
|
init_sandbox();
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
7174
|
+
init_editSessions();
|
|
7175
|
+
init_dryRun();
|
|
7176
|
+
ApiError = class extends Error {
|
|
7177
|
+
constructor(status, method, path12, text2) {
|
|
7178
|
+
const parsed = parseErrorBody(text2);
|
|
7179
|
+
super(`${method} ${path12} -> ${status}: ${parsed.detail}`);
|
|
5924
7180
|
this.status = status;
|
|
7181
|
+
this.text = text2;
|
|
5925
7182
|
this.name = "ApiError";
|
|
7183
|
+
this.code = parsed.code;
|
|
5926
7184
|
}
|
|
7185
|
+
status;
|
|
7186
|
+
text;
|
|
7187
|
+
code;
|
|
5927
7188
|
};
|
|
5928
7189
|
WorldTask = class {
|
|
5929
7190
|
constructor(world, name, variant) {
|
|
@@ -5931,6 +7192,9 @@ var init_worlds = __esm({
|
|
|
5931
7192
|
this.name = name;
|
|
5932
7193
|
this.variant = variant;
|
|
5933
7194
|
}
|
|
7195
|
+
world;
|
|
7196
|
+
name;
|
|
7197
|
+
variant;
|
|
5934
7198
|
};
|
|
5935
7199
|
WorldSet = class {
|
|
5936
7200
|
constructor(slugRef, slug, ref, version, tasks, options) {
|
|
@@ -5941,6 +7205,12 @@ var init_worlds = __esm({
|
|
|
5941
7205
|
this.tasks = tasks;
|
|
5942
7206
|
this.options = options;
|
|
5943
7207
|
}
|
|
7208
|
+
slugRef;
|
|
7209
|
+
slug;
|
|
7210
|
+
ref;
|
|
7211
|
+
version;
|
|
7212
|
+
tasks;
|
|
7213
|
+
options;
|
|
5944
7214
|
task(variant) {
|
|
5945
7215
|
const hit = this.tasks.find(
|
|
5946
7216
|
(t) => t.variant === variant || t.name.includes(variant)
|
|
@@ -5964,6 +7234,7 @@ var init_worlds = __esm({
|
|
|
5964
7234
|
versionId: this.version.versionId,
|
|
5965
7235
|
reuseWarm: opts.reuseWarm,
|
|
5966
7236
|
surfaces: opts.surfaces,
|
|
7237
|
+
browserTier: opts.browserTier,
|
|
5967
7238
|
options: this.options
|
|
5968
7239
|
});
|
|
5969
7240
|
}
|
|
@@ -5993,22 +7264,52 @@ init_worlds();
|
|
|
5993
7264
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5994
7265
|
0 && (module.exports = {
|
|
5995
7266
|
ApiError,
|
|
7267
|
+
BROWSER_GONE_PATTERNS,
|
|
7268
|
+
BROWSER_TIERS,
|
|
5996
7269
|
BrowserActionRecorder,
|
|
7270
|
+
BrowserReconnected,
|
|
7271
|
+
BrowserReconnector,
|
|
7272
|
+
BrowserUnrecoverable,
|
|
7273
|
+
CALL_BODY_LIMIT_BYTES,
|
|
7274
|
+
CALL_BODY_LIMIT_LABEL,
|
|
5997
7275
|
COMPUTER_USE_SPECS,
|
|
7276
|
+
CheckoutProvenance,
|
|
5998
7277
|
DEFAULT_BRANCH,
|
|
5999
7278
|
DEFAULT_VIEWPORT,
|
|
7279
|
+
DRY_RUN_AGENT,
|
|
7280
|
+
DRY_RUN_KIND,
|
|
7281
|
+
DetachedPushError,
|
|
7282
|
+
DryRunOutcome,
|
|
6000
7283
|
EVENT_BATCH_SIZE,
|
|
6001
7284
|
EVENT_FLUSH_INTERVAL_MS,
|
|
6002
7285
|
EVENT_MAX_RETRIES,
|
|
7286
|
+
EXPLORATORY_TASK,
|
|
7287
|
+
EXPLORATORY_TASK_SOURCE,
|
|
6003
7288
|
GatewayEvalsClient,
|
|
7289
|
+
HostedDryRunClient,
|
|
7290
|
+
IDLE_WARNING_MINUTES,
|
|
7291
|
+
NO_GRADER_REASON,
|
|
7292
|
+
PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
7293
|
+
PLATFORM_TIMEOUT_ENV,
|
|
7294
|
+
PlatformTransport,
|
|
6004
7295
|
PushSlugConflict,
|
|
7296
|
+
RECOVER_BUDGET_MS,
|
|
7297
|
+
SANDBOX_REQUEST_TIMEOUT_MS,
|
|
7298
|
+
SESSION_STATES,
|
|
7299
|
+
STATUS_WAIT_CAP_SECONDS,
|
|
6005
7300
|
STRIP_PREFIX,
|
|
6006
7301
|
SURFACE_KINDS,
|
|
7302
|
+
SecretScrubber,
|
|
6007
7303
|
TRANSFORMS,
|
|
6008
7304
|
TaskRun,
|
|
6009
7305
|
TaskSessions,
|
|
7306
|
+
TransportCause,
|
|
7307
|
+
UnreachableError,
|
|
7308
|
+
VERIFIER_REWARD_PREFIX,
|
|
6010
7309
|
WHITESPACE,
|
|
6011
7310
|
WorldBrowser,
|
|
7311
|
+
WorldCallTooLarge,
|
|
7312
|
+
WorldEditClient,
|
|
6012
7313
|
WorldSandboxClient,
|
|
6013
7314
|
WorldSession,
|
|
6014
7315
|
WorldSessionCallError,
|
|
@@ -6020,12 +7321,16 @@ init_worlds();
|
|
|
6020
7321
|
apiRequest,
|
|
6021
7322
|
applyTransforms,
|
|
6022
7323
|
archiveMode,
|
|
7324
|
+
assertBrowserTier,
|
|
7325
|
+
assertTaskRef,
|
|
6023
7326
|
attachManifest,
|
|
6024
7327
|
attachSession,
|
|
6025
7328
|
attachTask,
|
|
6026
7329
|
buildFileManifest,
|
|
6027
7330
|
buildSourceTarball,
|
|
6028
7331
|
captureToolCalls,
|
|
7332
|
+
checkoutIdentity,
|
|
7333
|
+
closeConnection,
|
|
6029
7334
|
collectArchiveRelPaths,
|
|
6030
7335
|
computeContentHash,
|
|
6031
7336
|
computerUseToolkit,
|
|
@@ -6039,13 +7344,18 @@ init_worlds();
|
|
|
6039
7344
|
getRun,
|
|
6040
7345
|
getTask,
|
|
6041
7346
|
hashForm,
|
|
7347
|
+
idleWarning,
|
|
6042
7348
|
ingest,
|
|
6043
7349
|
ingestToolCalls,
|
|
7350
|
+
isBrowserGone,
|
|
7351
|
+
isSandboxImportPending,
|
|
6044
7352
|
isTaskIdRef,
|
|
6045
7353
|
isTaskManifest,
|
|
6046
7354
|
isTaskSpec,
|
|
6047
7355
|
listEnvSecretKeys,
|
|
6048
7356
|
listRunConfigs,
|
|
7357
|
+
listRuns,
|
|
7358
|
+
listSessions,
|
|
6049
7359
|
listTaskSessions,
|
|
6050
7360
|
listTasks,
|
|
6051
7361
|
localTreeState,
|
|
@@ -6057,28 +7367,35 @@ init_worlds();
|
|
|
6057
7367
|
openTask,
|
|
6058
7368
|
openWorld,
|
|
6059
7369
|
openWorldVersion,
|
|
7370
|
+
parseErrorBody,
|
|
6060
7371
|
parseSlugRef,
|
|
6061
7372
|
parseToolCallRecord,
|
|
6062
7373
|
parseTransform,
|
|
6063
7374
|
parseWorldTaskRefs,
|
|
7375
|
+
platformTimeoutMs,
|
|
6064
7376
|
preserveForm,
|
|
6065
7377
|
propose,
|
|
6066
7378
|
pull,
|
|
6067
7379
|
push,
|
|
7380
|
+
pushBranch,
|
|
6068
7381
|
pushSlug,
|
|
6069
7382
|
pyText,
|
|
6070
7383
|
queryRows,
|
|
6071
7384
|
queryRowsSearch,
|
|
6072
7385
|
readLocalMeta,
|
|
6073
7386
|
readToolCallRecords,
|
|
7387
|
+
rebaseConflicts,
|
|
6074
7388
|
redactActionArgs,
|
|
6075
7389
|
redactionOf,
|
|
7390
|
+
releaseConnection,
|
|
6076
7391
|
resolveBrowserMode,
|
|
6077
7392
|
resolvePushSlug,
|
|
6078
7393
|
roundForm,
|
|
6079
7394
|
runSessions,
|
|
7395
|
+
runSet,
|
|
6080
7396
|
runTask,
|
|
6081
7397
|
schemaFromSignature,
|
|
7398
|
+
serializeCallBody,
|
|
6082
7399
|
sessionToolObservations,
|
|
6083
7400
|
setEnvSecret,
|
|
6084
7401
|
shapeText,
|
|
@@ -6090,6 +7407,7 @@ init_worlds();
|
|
|
6090
7407
|
toolCallsFromObservations,
|
|
6091
7408
|
uiEntryUrl,
|
|
6092
7409
|
uiUrl,
|
|
7410
|
+
uncommittedPaths,
|
|
6093
7411
|
updateTask,
|
|
6094
7412
|
upsertRunConfig,
|
|
6095
7413
|
validateTask,
|