@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.mjs
CHANGED
|
@@ -8,18 +8,295 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
8
8
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
9
9
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
10
10
|
});
|
|
11
|
-
var __esm = (fn, res) => function __init() {
|
|
12
|
-
|
|
11
|
+
var __esm = (fn, res, err) => function __init() {
|
|
12
|
+
if (err) throw err[0];
|
|
13
|
+
try {
|
|
14
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
15
|
+
} catch (e) {
|
|
16
|
+
throw err = [e], e;
|
|
17
|
+
}
|
|
13
18
|
};
|
|
14
19
|
var __commonJS = (cb, mod) => function __require2() {
|
|
15
|
-
|
|
20
|
+
try {
|
|
21
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
22
|
+
} catch (e) {
|
|
23
|
+
throw mod = 0, e;
|
|
24
|
+
}
|
|
16
25
|
};
|
|
17
26
|
var __export = (target, all) => {
|
|
18
27
|
for (var name in all)
|
|
19
28
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
20
29
|
};
|
|
21
30
|
|
|
31
|
+
// src/worlds/transport.ts
|
|
32
|
+
function platformTimeoutMs(env = process.env) {
|
|
33
|
+
const raw = env[PLATFORM_TIMEOUT_ENV];
|
|
34
|
+
if (raw === void 0 || raw === "") return PLATFORM_TIMEOUT_DEFAULT_MS;
|
|
35
|
+
const value = Number(raw);
|
|
36
|
+
if (Number.isInteger(value) && value > 0) return value;
|
|
37
|
+
throw new Error(`${PLATFORM_TIMEOUT_ENV} must be a positive whole number of milliseconds, not \`${raw}\`.`);
|
|
38
|
+
}
|
|
39
|
+
var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, PlatformTransport;
|
|
40
|
+
var init_transport = __esm({
|
|
41
|
+
"src/worlds/transport.ts"() {
|
|
42
|
+
"use strict";
|
|
43
|
+
PLATFORM_TIMEOUT_ENV = "GATEWAY_TIMEOUT_MS";
|
|
44
|
+
PLATFORM_TIMEOUT_DEFAULT_MS = 12e4;
|
|
45
|
+
CHECK_HOST = "Check GATEWAY_HOST (or --host) points at a running platform, then retry.";
|
|
46
|
+
RETRY = "Retry; if it repeats, check the network between here and the platform.";
|
|
47
|
+
CAUSES = {
|
|
48
|
+
ECONNREFUSED: { reason: "connection refused", next: CHECK_HOST },
|
|
49
|
+
ENOTFOUND: { reason: "DNS lookup failed", next: CHECK_HOST },
|
|
50
|
+
EAI_AGAIN: { reason: "DNS lookup failed", next: CHECK_HOST },
|
|
51
|
+
ETIMEDOUT: { reason: "connect timed out", next: CHECK_HOST },
|
|
52
|
+
UND_ERR_CONNECT_TIMEOUT: { reason: "connect timed out", next: CHECK_HOST },
|
|
53
|
+
EHOSTUNREACH: { reason: "host unreachable", next: CHECK_HOST },
|
|
54
|
+
ENETUNREACH: { reason: "network unreachable", next: RETRY },
|
|
55
|
+
ECONNRESET: { reason: "connection dropped", next: RETRY },
|
|
56
|
+
UND_ERR_SOCKET: { reason: "connection dropped", next: RETRY },
|
|
57
|
+
EPIPE: { reason: "connection dropped", next: RETRY }
|
|
58
|
+
};
|
|
59
|
+
UNKNOWN_CAUSE = { reason: "network error", next: CHECK_HOST };
|
|
60
|
+
TransportCause = class _TransportCause {
|
|
61
|
+
constructor(reason, detail, next) {
|
|
62
|
+
this.reason = reason;
|
|
63
|
+
this.detail = detail;
|
|
64
|
+
this.next = next;
|
|
65
|
+
}
|
|
66
|
+
reason;
|
|
67
|
+
detail;
|
|
68
|
+
next;
|
|
69
|
+
static timeout(timeoutMs) {
|
|
70
|
+
return new _TransportCause(
|
|
71
|
+
`timed out after ${timeoutMs / 1e3}s`,
|
|
72
|
+
null,
|
|
73
|
+
`Retry; if the platform is slow, raise ${PLATFORM_TIMEOUT_ENV} (milliseconds per request).`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
static of(error) {
|
|
77
|
+
const cause = error instanceof Error && error.cause instanceof Error ? error.cause : void 0;
|
|
78
|
+
const code = cause && "code" in cause && typeof cause.code === "string" ? cause.code : null;
|
|
79
|
+
const message = cause?.message ?? (error instanceof Error ? error.message : String(error));
|
|
80
|
+
const known = code && CAUSES[code] || UNKNOWN_CAUSE;
|
|
81
|
+
return new _TransportCause(known.reason, code ? `${code}: ${message}` : message, known.next);
|
|
82
|
+
}
|
|
83
|
+
describe() {
|
|
84
|
+
return this.detail === null ? this.reason : `${this.reason} (${this.detail})`;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
UnreachableError = class extends Error {
|
|
88
|
+
constructor(host, method, route, failure) {
|
|
89
|
+
super(`${method} ${route}: no answer from ${host}: ${failure.describe()}. ${failure.next}`);
|
|
90
|
+
this.host = host;
|
|
91
|
+
this.method = method;
|
|
92
|
+
this.route = route;
|
|
93
|
+
this.failure = failure;
|
|
94
|
+
this.name = "UnreachableError";
|
|
95
|
+
}
|
|
96
|
+
host;
|
|
97
|
+
method;
|
|
98
|
+
route;
|
|
99
|
+
failure;
|
|
100
|
+
};
|
|
101
|
+
PlatformTransport = class {
|
|
102
|
+
constructor(endpoint, timeoutMs = platformTimeoutMs()) {
|
|
103
|
+
this.endpoint = endpoint;
|
|
104
|
+
this.timeoutMs = timeoutMs;
|
|
105
|
+
}
|
|
106
|
+
endpoint;
|
|
107
|
+
timeoutMs;
|
|
108
|
+
/** A request that legitimately takes longer (a sandbox exec, a world create) waits its own budget; every other one waits the default. */
|
|
109
|
+
budget(ownMs) {
|
|
110
|
+
return Math.max(ownMs ?? 0, this.timeoutMs);
|
|
111
|
+
}
|
|
112
|
+
async send(method, route, body, opts = {}) {
|
|
113
|
+
const timeoutMs = this.budget(opts.timeoutMs);
|
|
114
|
+
const payload = body === void 0 ? {} : { body: JSON.stringify(body) };
|
|
115
|
+
const controller = new AbortController();
|
|
116
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
117
|
+
try {
|
|
118
|
+
const res = await fetch(`${this.endpoint.host}${route}`, {
|
|
119
|
+
method,
|
|
120
|
+
headers: {
|
|
121
|
+
"content-type": "application/json",
|
|
122
|
+
accept: "application/json",
|
|
123
|
+
authorization: "Basic " + Buffer.from(`${this.endpoint.publicKey}:${this.endpoint.secretKey}`).toString("base64")
|
|
124
|
+
},
|
|
125
|
+
...payload,
|
|
126
|
+
signal: controller.signal
|
|
127
|
+
});
|
|
128
|
+
return { status: res.status, ok: res.ok, text: await res.text() };
|
|
129
|
+
} catch (error) {
|
|
130
|
+
const cause = controller.signal.aborted ? TransportCause.timeout(timeoutMs) : TransportCause.of(error);
|
|
131
|
+
throw new UnreachableError(this.endpoint.host, method, route, cause);
|
|
132
|
+
} finally {
|
|
133
|
+
clearTimeout(timer);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// src/worlds/browserReconnect.ts
|
|
141
|
+
async function closeConnection(c) {
|
|
142
|
+
await c.context.close();
|
|
143
|
+
await c.browser.close();
|
|
144
|
+
}
|
|
145
|
+
async function releaseConnection(c) {
|
|
146
|
+
await closeConnection(c).catch(() => void 0);
|
|
147
|
+
}
|
|
148
|
+
function isBrowserGone(error) {
|
|
149
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
150
|
+
if (PAGE_NETWORK_ERROR.test(message)) return false;
|
|
151
|
+
return BROWSER_GONE_PATTERNS.some((p) => p.test(message));
|
|
152
|
+
}
|
|
153
|
+
function refusalIsTransient(error) {
|
|
154
|
+
const { status, code } = error;
|
|
155
|
+
if (typeof status !== "number") return true;
|
|
156
|
+
if (status >= 500) return true;
|
|
157
|
+
return status === 400 && code === "browser_capacity";
|
|
158
|
+
}
|
|
159
|
+
function describe(error) {
|
|
160
|
+
return error instanceof Error ? error.message : String(error);
|
|
161
|
+
}
|
|
162
|
+
var RECOVER_BUDGET_MS, BACKOFF_BASE_MS, BACKOFF_CAP_MS, BROWSER_GONE_PATTERNS, PAGE_NETWORK_ERROR, REDACTED, TOKEN_QUERY_VALUE, SecretScrubber, BrowserReconnected, BrowserUnrecoverable, BrowserReconnector;
|
|
163
|
+
var init_browserReconnect = __esm({
|
|
164
|
+
"src/worlds/browserReconnect.ts"() {
|
|
165
|
+
"use strict";
|
|
166
|
+
RECOVER_BUDGET_MS = 9e4;
|
|
167
|
+
BACKOFF_BASE_MS = 1e3;
|
|
168
|
+
BACKOFF_CAP_MS = 5e3;
|
|
169
|
+
BROWSER_GONE_PATTERNS = [
|
|
170
|
+
/target page, context or browser has been closed/i,
|
|
171
|
+
/\bbrowser has been (closed|disconnected)\b/i,
|
|
172
|
+
/\bbrowser (has )?disconnected\b/i,
|
|
173
|
+
/\btarget closed\b/i,
|
|
174
|
+
/\bwebsocket is not open\b/i,
|
|
175
|
+
/\bconnection closed\b/i
|
|
176
|
+
];
|
|
177
|
+
PAGE_NETWORK_ERROR = /net::ERR_/i;
|
|
178
|
+
REDACTED = "<redacted>";
|
|
179
|
+
TOKEN_QUERY_VALUE = /([?&]token=)[^&#\s"')]*/gi;
|
|
180
|
+
SecretScrubber = class {
|
|
181
|
+
secrets;
|
|
182
|
+
constructor(secrets) {
|
|
183
|
+
const known = secrets.filter((s) => Boolean(s));
|
|
184
|
+
this.secrets = [
|
|
185
|
+
.../* @__PURE__ */ new Set([...known, ...known.map((s) => encodeURIComponent(s))])
|
|
186
|
+
].sort((a, b) => b.length - a.length);
|
|
187
|
+
}
|
|
188
|
+
scrub(text2) {
|
|
189
|
+
const bare = this.secrets.reduce(
|
|
190
|
+
(out, secret) => out.split(secret).join(REDACTED),
|
|
191
|
+
text2
|
|
192
|
+
);
|
|
193
|
+
return bare.replace(TOKEN_QUERY_VALUE, `$1${REDACTED}`);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
BrowserReconnected = class extends Error {
|
|
197
|
+
constructor(outcome, restoredUrl, cause) {
|
|
198
|
+
super(
|
|
199
|
+
`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.",
|
|
200
|
+
{ cause }
|
|
201
|
+
);
|
|
202
|
+
this.outcome = outcome;
|
|
203
|
+
this.restoredUrl = restoredUrl;
|
|
204
|
+
this.name = "BrowserReconnected";
|
|
205
|
+
}
|
|
206
|
+
outcome;
|
|
207
|
+
restoredUrl;
|
|
208
|
+
};
|
|
209
|
+
BrowserUnrecoverable = class extends Error {
|
|
210
|
+
constructor(message, cause) {
|
|
211
|
+
super(message, { cause });
|
|
212
|
+
this.name = "BrowserUnrecoverable";
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
BrowserReconnector = class {
|
|
216
|
+
constructor(repair, connect, opts = {}) {
|
|
217
|
+
this.repair = repair;
|
|
218
|
+
this.connect = connect;
|
|
219
|
+
this.sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
220
|
+
this.now = opts.now ?? Date.now;
|
|
221
|
+
this.budgetMs = opts.budgetMs ?? RECOVER_BUDGET_MS;
|
|
222
|
+
this.scrub = opts.scrub ?? ((text2) => text2);
|
|
223
|
+
}
|
|
224
|
+
repair;
|
|
225
|
+
connect;
|
|
226
|
+
sleep;
|
|
227
|
+
now;
|
|
228
|
+
scrub;
|
|
229
|
+
budgetMs;
|
|
230
|
+
/**
|
|
231
|
+
* Repair, reconnect and `restore` until it works or the budget runs out.
|
|
232
|
+
* `restore` receives each new connection (the owner adopts it and reopens
|
|
233
|
+
* its page); a restore that fails counts as a failed reconnect, because the
|
|
234
|
+
* browser may have died again. A repair the platform refuses for good
|
|
235
|
+
* rethrows `cause` untouched.
|
|
236
|
+
*/
|
|
237
|
+
async recover(cause, restore) {
|
|
238
|
+
const deadline = this.now() + this.budgetMs;
|
|
239
|
+
let reason = describe(cause);
|
|
240
|
+
for (let attempt = 1; ; attempt++) {
|
|
241
|
+
const step = await this.attempt(restore);
|
|
242
|
+
if (step.kind === "recovered")
|
|
243
|
+
return { outcome: step.outcome, attempts: attempt };
|
|
244
|
+
if (step.kind === "stop") throw cause;
|
|
245
|
+
reason = step.reason;
|
|
246
|
+
const remaining = deadline - this.now();
|
|
247
|
+
if (remaining <= 0) break;
|
|
248
|
+
const backoff = Math.min(
|
|
249
|
+
BACKOFF_BASE_MS * 2 ** (attempt - 1),
|
|
250
|
+
BACKOFF_CAP_MS
|
|
251
|
+
);
|
|
252
|
+
await this.sleep(Math.min(step.waitMs ?? backoff, remaining));
|
|
253
|
+
}
|
|
254
|
+
throw new BrowserUnrecoverable(
|
|
255
|
+
`the session's browser could not be recovered within ${Math.round(this.budgetMs / 1e3)}s: ${this.scrub(reason)}`,
|
|
256
|
+
cause
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
async attempt(restore) {
|
|
260
|
+
let answer;
|
|
261
|
+
try {
|
|
262
|
+
answer = await this.repair();
|
|
263
|
+
} catch (error) {
|
|
264
|
+
if (!refusalIsTransient(error)) return { kind: "stop" };
|
|
265
|
+
return {
|
|
266
|
+
kind: "wait",
|
|
267
|
+
reason: `repair failed: ${describe(error)}`,
|
|
268
|
+
waitMs: null
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
const outcome = answer.outcome;
|
|
272
|
+
if (outcome === "starting")
|
|
273
|
+
return {
|
|
274
|
+
kind: "wait",
|
|
275
|
+
reason: "a new browser is still starting",
|
|
276
|
+
waitMs: answer.retryAfterMs
|
|
277
|
+
};
|
|
278
|
+
try {
|
|
279
|
+
await restore(await this.connect());
|
|
280
|
+
} catch (error) {
|
|
281
|
+
return {
|
|
282
|
+
kind: "wait",
|
|
283
|
+
reason: `reconnect failed: ${describe(error)}`,
|
|
284
|
+
waitMs: null
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
return { kind: "recovered", outcome };
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
|
|
22
293
|
// src/worlds/browser.ts
|
|
294
|
+
function assertBrowserTier(value) {
|
|
295
|
+
if (BROWSER_TIERS.includes(value)) return;
|
|
296
|
+
throw new Error(
|
|
297
|
+
`Unknown browser tier: ${String(value)}; choose from ${BROWSER_TIERS.join(", ")}`
|
|
298
|
+
);
|
|
299
|
+
}
|
|
23
300
|
function surfaceKinds(s) {
|
|
24
301
|
const kinds = ["tools"];
|
|
25
302
|
if (s.api) kinds.push("api");
|
|
@@ -27,9 +304,9 @@ function surfaceKinds(s) {
|
|
|
27
304
|
if (s.browser) kinds.push("browser");
|
|
28
305
|
return kinds;
|
|
29
306
|
}
|
|
30
|
-
function uiUrl(ui,
|
|
307
|
+
function uiUrl(ui, path12) {
|
|
31
308
|
const base = ui.url.replace(/\/+$/, "");
|
|
32
|
-
const rel =
|
|
309
|
+
const rel = path12.startsWith("/") ? path12 : `/${path12}`;
|
|
33
310
|
if (!ui.token) return base + rel;
|
|
34
311
|
const [beforeHash, hash] = splitHash(rel);
|
|
35
312
|
const joiner = beforeHash.includes("?") ? "&" : "?";
|
|
@@ -95,19 +372,34 @@ async function openBrowser(surfaces, opts = {}) {
|
|
|
95
372
|
const mode = resolveBrowserMode(surfaces, opts.mode ?? "auto");
|
|
96
373
|
const pw = opts.playwright ?? await loadPlaywright();
|
|
97
374
|
const viewport = surfaces.browser?.viewport ?? DEFAULT_VIEWPORT;
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
375
|
+
const attach = async () => {
|
|
376
|
+
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 });
|
|
377
|
+
const context = await browser.newContext({ viewport });
|
|
378
|
+
return { browser, context, page: await context.newPage() };
|
|
379
|
+
};
|
|
380
|
+
let live = await attach();
|
|
381
|
+
const reattach = async () => {
|
|
382
|
+
const fresh = await attach();
|
|
383
|
+
await releaseConnection(live);
|
|
384
|
+
live = fresh;
|
|
385
|
+
return fresh;
|
|
386
|
+
};
|
|
387
|
+
const scrubber = new SecretScrubber([
|
|
388
|
+
surfaces.browser?.wsUrl,
|
|
389
|
+
surfaces.ui?.token
|
|
390
|
+
]);
|
|
391
|
+
const reconnector = mode === "hosted" && surfaces.browser.protocol === "cdp" && opts.repair ? new BrowserReconnector(opts.repair, reattach, {
|
|
392
|
+
scrub: (text2) => scrubber.scrub(text2)
|
|
393
|
+
}) : null;
|
|
101
394
|
return new WorldBrowser(
|
|
102
|
-
page,
|
|
395
|
+
live.page,
|
|
103
396
|
surfaces.ui,
|
|
104
397
|
mode,
|
|
105
|
-
|
|
106
|
-
await context.close();
|
|
107
|
-
await browser.close();
|
|
108
|
-
},
|
|
398
|
+
() => closeConnection(live),
|
|
109
399
|
viewport,
|
|
110
|
-
opts.recorder ?? null
|
|
400
|
+
opts.recorder ?? null,
|
|
401
|
+
reconnector,
|
|
402
|
+
scrubber
|
|
111
403
|
);
|
|
112
404
|
}
|
|
113
405
|
function computerUseToolkit(browser, opts = {}) {
|
|
@@ -159,12 +451,14 @@ function computerUseToolkit(browser, opts = {}) {
|
|
|
159
451
|
specs
|
|
160
452
|
};
|
|
161
453
|
}
|
|
162
|
-
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;
|
|
454
|
+
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;
|
|
163
455
|
var init_browser = __esm({
|
|
164
456
|
"src/worlds/browser.ts"() {
|
|
165
457
|
"use strict";
|
|
166
458
|
init_session();
|
|
459
|
+
init_browserReconnect();
|
|
167
460
|
SURFACE_KINDS = ["tools", "api", "ui", "browser"];
|
|
461
|
+
BROWSER_TIERS = ["standard", "premium"];
|
|
168
462
|
DEFAULT_VIEWPORT = { width: 1280, height: 800 };
|
|
169
463
|
SETTLE_TIMEOUT_MS = 5e3;
|
|
170
464
|
SETTLE_QUIET_MS = 150;
|
|
@@ -181,6 +475,7 @@ var init_browser = __esm({
|
|
|
181
475
|
super(`World surface '${surface}' is unavailable: ${reason}`);
|
|
182
476
|
this.surface = surface;
|
|
183
477
|
}
|
|
478
|
+
surface;
|
|
184
479
|
};
|
|
185
480
|
UI_TOKEN_QUERY = "token";
|
|
186
481
|
BrowserActionRecorder = class {
|
|
@@ -189,6 +484,9 @@ var init_browser = __esm({
|
|
|
189
484
|
this.agentId = agentId;
|
|
190
485
|
this.opts = opts;
|
|
191
486
|
}
|
|
487
|
+
post;
|
|
488
|
+
agentId;
|
|
489
|
+
opts;
|
|
192
490
|
seq = 0;
|
|
193
491
|
base = null;
|
|
194
492
|
queue = [];
|
|
@@ -202,8 +500,8 @@ var init_browser = __esm({
|
|
|
202
500
|
}
|
|
203
501
|
resolveBase() {
|
|
204
502
|
if (this.base === null) {
|
|
205
|
-
const
|
|
206
|
-
this.base =
|
|
503
|
+
const resolve7 = this.opts.resumeFrom ?? (async () => 0);
|
|
504
|
+
this.base = resolve7().then((n) => {
|
|
207
505
|
if (!Number.isInteger(n) || n < 0)
|
|
208
506
|
throw new Error(
|
|
209
507
|
`browser event base seq must be a non-negative integer, got ${String(n)}`
|
|
@@ -272,13 +570,38 @@ var init_browser = __esm({
|
|
|
272
570
|
}
|
|
273
571
|
};
|
|
274
572
|
WorldBrowser = class {
|
|
275
|
-
constructor(page, ui, mode, teardown, viewport = DEFAULT_VIEWPORT, recorder = null) {
|
|
276
|
-
this.page = page;
|
|
573
|
+
constructor(page, ui, mode, teardown, viewport = DEFAULT_VIEWPORT, recorder = null, reconnector = null, scrubber = new SecretScrubber([ui?.token])) {
|
|
277
574
|
this.ui = ui;
|
|
278
575
|
this.mode = mode;
|
|
279
576
|
this.teardown = teardown;
|
|
280
577
|
this.viewport = viewport;
|
|
281
578
|
this.recorder = recorder;
|
|
579
|
+
this.reconnector = reconnector;
|
|
580
|
+
this.scrubber = scrubber;
|
|
581
|
+
this.current = page;
|
|
582
|
+
this.watchNetwork(page);
|
|
583
|
+
}
|
|
584
|
+
ui;
|
|
585
|
+
mode;
|
|
586
|
+
teardown;
|
|
587
|
+
viewport;
|
|
588
|
+
recorder;
|
|
589
|
+
reconnector;
|
|
590
|
+
scrubber;
|
|
591
|
+
current;
|
|
592
|
+
inflight = 0;
|
|
593
|
+
lastNetwork = Date.now();
|
|
594
|
+
/** Where the page last was after an action, token stripped: what a
|
|
595
|
+
* reconnect reopens. Null until the page has left `about:blank`. */
|
|
596
|
+
lastUrl = null;
|
|
597
|
+
/** The live Playwright page; a new object after a reconnect. */
|
|
598
|
+
get page() {
|
|
599
|
+
return this.current;
|
|
600
|
+
}
|
|
601
|
+
get agentId() {
|
|
602
|
+
return this.recorder?.agentId ?? null;
|
|
603
|
+
}
|
|
604
|
+
watchNetwork(page) {
|
|
282
605
|
page.on("request", () => {
|
|
283
606
|
this.inflight += 1;
|
|
284
607
|
this.lastNetwork = Date.now();
|
|
@@ -290,42 +613,105 @@ var init_browser = __esm({
|
|
|
290
613
|
page.on("requestfinished", done);
|
|
291
614
|
page.on("requestfailed", done);
|
|
292
615
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
616
|
+
/** Run `fn` against the page. If it fails because the browser is gone,
|
|
617
|
+
* recover; then `retry` runs it ONCE more and `report` throws
|
|
618
|
+
* `BrowserReconnected` instead of replaying it. Any other error, and a
|
|
619
|
+
* second loss during the retry, propagate unchanged. */
|
|
620
|
+
async resilient(fn, onLoss) {
|
|
621
|
+
try {
|
|
622
|
+
return this.remember(await fn());
|
|
623
|
+
} catch (error) {
|
|
624
|
+
if (!this.reconnector || !isBrowserGone(error)) throw error;
|
|
625
|
+
const recovered = await this.recover(this.reconnector, error);
|
|
626
|
+
if (onLoss === "report")
|
|
627
|
+
throw new BrowserReconnected(
|
|
628
|
+
recovered.outcome,
|
|
629
|
+
recovered.restoredUrl,
|
|
630
|
+
error
|
|
631
|
+
);
|
|
632
|
+
}
|
|
633
|
+
return this.remember(await fn());
|
|
634
|
+
}
|
|
635
|
+
remember(result) {
|
|
636
|
+
this.lastUrl = this.openedUrl() ?? this.lastUrl;
|
|
637
|
+
return result;
|
|
638
|
+
}
|
|
639
|
+
/** The page's URL less its token; null while it is blank. */
|
|
640
|
+
openedUrl() {
|
|
641
|
+
const url = this.page.url();
|
|
642
|
+
return url && url !== "about:blank" ? withoutUiToken(url) : null;
|
|
643
|
+
}
|
|
644
|
+
async recover(reconnector, cause) {
|
|
645
|
+
const started = Date.now();
|
|
646
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
647
|
+
const args = { cause: this.scrubber.scrub(message).slice(0, 200) };
|
|
648
|
+
let result;
|
|
649
|
+
try {
|
|
650
|
+
result = await reconnector.recover(cause, (c) => this.adopt(c));
|
|
651
|
+
} catch (error) {
|
|
652
|
+
await this.report("browser_reconnect", args, started, error);
|
|
653
|
+
throw error;
|
|
654
|
+
}
|
|
655
|
+
const restoredUrl = this.openedUrl();
|
|
656
|
+
await this.report(
|
|
657
|
+
"browser_reconnect",
|
|
658
|
+
{ ...args, ...result, restoredUrl },
|
|
659
|
+
started,
|
|
660
|
+
null
|
|
661
|
+
);
|
|
662
|
+
return { ...result, restoredUrl };
|
|
663
|
+
}
|
|
664
|
+
/** Take over a new connection's page and reopen the page the agent was on
|
|
665
|
+
* (`openBrowser` owns the connection itself). A new browser has no session
|
|
666
|
+
* cookie, so a World Host UI is first loaded with its token, exactly as
|
|
667
|
+
* `goto()` loads the entry page. */
|
|
668
|
+
async adopt(connection) {
|
|
669
|
+
this.current = connection.page;
|
|
670
|
+
this.inflight = 0;
|
|
671
|
+
this.watchNetwork(connection.page);
|
|
672
|
+
const last = this.lastUrl;
|
|
673
|
+
if (!last) return;
|
|
674
|
+
if (this.ui?.token)
|
|
675
|
+
await this.page.goto(uiEntryUrl(this.ui), { waitUntil: "load" });
|
|
676
|
+
if (withoutUiToken(this.page.url()) !== last)
|
|
677
|
+
await this.page.goto(last, { waitUntil: "load" });
|
|
678
|
+
await this.settle();
|
|
297
679
|
}
|
|
298
680
|
/** Run one action and report it: the event carries what was asked,
|
|
299
681
|
* whether it worked, and the screen after — for failures too, so a
|
|
300
682
|
* reviewer sees what the agent saw when the selector did not match. */
|
|
301
|
-
async act(action, args, fn) {
|
|
302
|
-
const recorder = this.recorder;
|
|
303
|
-
if (!recorder) return fn();
|
|
683
|
+
async act(action, args, fn, onLoss = "report") {
|
|
304
684
|
const started = Date.now();
|
|
305
|
-
let ok = true;
|
|
306
|
-
let error = null;
|
|
307
685
|
try {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
recorder.record({
|
|
315
|
-
agentId: recorder.agentId,
|
|
316
|
-
seq: recorder.nextSeq(),
|
|
317
|
-
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
318
|
-
action,
|
|
319
|
-
args: redactActionArgs(action, args),
|
|
320
|
-
ok,
|
|
321
|
-
error,
|
|
322
|
-
durationMs: Date.now() - started,
|
|
323
|
-
mode: this.mode,
|
|
324
|
-
viewport: { ...this.viewport },
|
|
325
|
-
...await this.observeForEvent()
|
|
326
|
-
});
|
|
686
|
+
const result = await this.resilient(fn, onLoss);
|
|
687
|
+
await this.report(action, args, started, null);
|
|
688
|
+
return result;
|
|
689
|
+
} catch (error) {
|
|
690
|
+
await this.report(action, args, started, error);
|
|
691
|
+
throw error;
|
|
327
692
|
}
|
|
328
693
|
}
|
|
694
|
+
/** One event on the recorder, if there is one; `failure` null means ok. */
|
|
695
|
+
async report(action, args, started, failure) {
|
|
696
|
+
const recorder = this.recorder;
|
|
697
|
+
if (!recorder) return;
|
|
698
|
+
const error = failure === null ? null : this.scrubber.scrub(
|
|
699
|
+
failure instanceof Error ? `${failure.name}: ${failure.message}` : String(failure)
|
|
700
|
+
).slice(0, 4e3);
|
|
701
|
+
recorder.record({
|
|
702
|
+
agentId: recorder.agentId,
|
|
703
|
+
seq: recorder.nextSeq(),
|
|
704
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
705
|
+
action,
|
|
706
|
+
args: redactActionArgs(action, args),
|
|
707
|
+
ok: failure === null,
|
|
708
|
+
error,
|
|
709
|
+
durationMs: Date.now() - started,
|
|
710
|
+
mode: this.mode,
|
|
711
|
+
viewport: { ...this.viewport },
|
|
712
|
+
...await this.observeForEvent()
|
|
713
|
+
});
|
|
714
|
+
}
|
|
329
715
|
async observeForEvent() {
|
|
330
716
|
const out = {
|
|
331
717
|
url: null,
|
|
@@ -372,7 +758,9 @@ var init_browser = __esm({
|
|
|
372
758
|
await this.page.goto(target, { waitUntil: "load" });
|
|
373
759
|
await this.settle();
|
|
374
760
|
return this.page.url();
|
|
375
|
-
}
|
|
761
|
+
},
|
|
762
|
+
// Navigating again lands on the same page: safe to replay.
|
|
763
|
+
"retry"
|
|
376
764
|
);
|
|
377
765
|
}
|
|
378
766
|
async back() {
|
|
@@ -425,22 +813,25 @@ var init_browser = __esm({
|
|
|
425
813
|
);
|
|
426
814
|
}
|
|
427
815
|
async screenshot(fullPage = false) {
|
|
428
|
-
return this.
|
|
816
|
+
return this.resilient(
|
|
817
|
+
() => this.page.screenshot({ type: "png", fullPage }),
|
|
818
|
+
"retry"
|
|
819
|
+
);
|
|
429
820
|
}
|
|
430
821
|
async screenshotBase64(fullPage = false) {
|
|
431
822
|
return (await this.screenshot(fullPage)).toString("base64");
|
|
432
823
|
}
|
|
433
824
|
async text(selector = "body") {
|
|
434
|
-
return this.page.innerText(selector);
|
|
825
|
+
return this.resilient(() => this.page.innerText(selector), "retry");
|
|
435
826
|
}
|
|
436
827
|
async html() {
|
|
437
|
-
return this.page.content();
|
|
828
|
+
return this.resilient(() => this.page.content(), "retry");
|
|
438
829
|
}
|
|
439
830
|
get url() {
|
|
440
831
|
return this.page.url();
|
|
441
832
|
}
|
|
442
833
|
async title() {
|
|
443
|
-
return this.page.title();
|
|
834
|
+
return this.resilient(() => this.page.title(), "retry");
|
|
444
835
|
}
|
|
445
836
|
async close() {
|
|
446
837
|
try {
|
|
@@ -496,6 +887,82 @@ var init_browser = __esm({
|
|
|
496
887
|
}
|
|
497
888
|
});
|
|
498
889
|
|
|
890
|
+
// src/worlds/sessionContract.ts
|
|
891
|
+
function serializeCallBody(body) {
|
|
892
|
+
const text2 = JSON.stringify(body);
|
|
893
|
+
const size = Buffer.byteLength(text2, "utf8");
|
|
894
|
+
if (size > CALL_BODY_LIMIT_BYTES) throw new WorldCallTooLarge(size);
|
|
895
|
+
return text2;
|
|
896
|
+
}
|
|
897
|
+
function idleWarning(idleExpiresAt, now = /* @__PURE__ */ new Date()) {
|
|
898
|
+
if (!idleExpiresAt) return null;
|
|
899
|
+
const leftMs = new Date(idleExpiresAt).getTime() - now.getTime();
|
|
900
|
+
if (leftMs >= IDLE_WARNING_MINUTES * 6e4) return null;
|
|
901
|
+
const minutes = Math.max(0, Math.floor(leftMs / 6e4));
|
|
902
|
+
return `warning: session expires in ${minutes}m (idle TTL); call a tool to extend it or \`gateway worlds session pin\` to keep it`;
|
|
903
|
+
}
|
|
904
|
+
var CALL_BODY_LIMIT_BYTES, CALL_BODY_LIMIT_LABEL, IDLE_WARNING_MINUTES, EXPLORATORY_TASK, EXPLORATORY_TASK_SOURCE, NO_GRADER_REASON, WorldCallTooLarge;
|
|
905
|
+
var init_sessionContract = __esm({
|
|
906
|
+
"src/worlds/sessionContract.ts"() {
|
|
907
|
+
"use strict";
|
|
908
|
+
CALL_BODY_LIMIT_BYTES = 4 * 1024 * 1024;
|
|
909
|
+
CALL_BODY_LIMIT_LABEL = "4mb";
|
|
910
|
+
IDLE_WARNING_MINUTES = 5;
|
|
911
|
+
EXPLORATORY_TASK = Object.freeze({
|
|
912
|
+
instruction: "exploratory session"
|
|
913
|
+
});
|
|
914
|
+
EXPLORATORY_TASK_SOURCE = "none";
|
|
915
|
+
NO_GRADER_REASON = "no grader";
|
|
916
|
+
WorldCallTooLarge = class extends Error {
|
|
917
|
+
constructor(size, limitBytes = CALL_BODY_LIMIT_BYTES, limit = CALL_BODY_LIMIT_LABEL) {
|
|
918
|
+
super(
|
|
919
|
+
`call body is ${size} bytes; the platform accepts at most ${limit} (${limitBytes} bytes)`
|
|
920
|
+
);
|
|
921
|
+
this.size = size;
|
|
922
|
+
this.limitBytes = limitBytes;
|
|
923
|
+
this.limit = limit;
|
|
924
|
+
this.name = "WorldCallTooLarge";
|
|
925
|
+
}
|
|
926
|
+
size;
|
|
927
|
+
limitBytes;
|
|
928
|
+
limit;
|
|
929
|
+
code = "payload_too_large";
|
|
930
|
+
/** The structured refusal the CLIs print. */
|
|
931
|
+
toJSON() {
|
|
932
|
+
return {
|
|
933
|
+
status: "error",
|
|
934
|
+
code: this.code,
|
|
935
|
+
limit: this.limit,
|
|
936
|
+
size: this.size
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
});
|
|
942
|
+
|
|
943
|
+
// src/worlds/taskRef.ts
|
|
944
|
+
var isTaskIdRef, isTaskSpec, taskLabel, assertTaskRef;
|
|
945
|
+
var init_taskRef = __esm({
|
|
946
|
+
"src/worlds/taskRef.ts"() {
|
|
947
|
+
"use strict";
|
|
948
|
+
isTaskIdRef = (task) => typeof task === "object" && task !== null && "id" in task;
|
|
949
|
+
isTaskSpec = (task) => typeof task === "object" && task !== null && "instruction" in task;
|
|
950
|
+
taskLabel = (task, info) => {
|
|
951
|
+
if (typeof task === "string") return task;
|
|
952
|
+
if (isTaskIdRef(task)) return info?.name ?? task.id;
|
|
953
|
+
if (task.name) return task.name;
|
|
954
|
+
return info?.hash ? `inline:${info.hash.slice(0, 12)}` : "inline";
|
|
955
|
+
};
|
|
956
|
+
assertTaskRef = (task) => {
|
|
957
|
+
const malformed = task === null || typeof task === "string" && !task || isTaskIdRef(task) && !task.id || isTaskSpec(task) && !task.instruction || typeof task === "object" && !isTaskIdRef(task) && !isTaskSpec(task);
|
|
958
|
+
if (malformed)
|
|
959
|
+
throw new Error(
|
|
960
|
+
"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"
|
|
961
|
+
);
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
});
|
|
965
|
+
|
|
499
966
|
// src/worlds/session.ts
|
|
500
967
|
var session_exports = {};
|
|
501
968
|
__export(session_exports, {
|
|
@@ -512,6 +979,34 @@ __export(session_exports, {
|
|
|
512
979
|
taskLabel: () => taskLabel
|
|
513
980
|
});
|
|
514
981
|
import { randomUUID } from "crypto";
|
|
982
|
+
function numericGrade(record) {
|
|
983
|
+
const rewards = {};
|
|
984
|
+
const nested = record.rewards;
|
|
985
|
+
if (nested && typeof nested === "object") {
|
|
986
|
+
for (const [key, value] of Object.entries(nested)) {
|
|
987
|
+
if (typeof value === "number") rewards[key] = value;
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
for (const [key, value] of Object.entries(record)) {
|
|
991
|
+
if (key !== "reward" && typeof value === "number") rewards[key] = value;
|
|
992
|
+
}
|
|
993
|
+
return {
|
|
994
|
+
reward: typeof record.reward === "number" ? record.reward : null,
|
|
995
|
+
rewards
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
function verifierGrades(value) {
|
|
999
|
+
if (!value || typeof value !== "object") return void 0;
|
|
1000
|
+
const out = {};
|
|
1001
|
+
for (const [name, grade] of Object.entries(value)) {
|
|
1002
|
+
const record = grade && typeof grade === "object" ? grade : {};
|
|
1003
|
+
out[name] = {
|
|
1004
|
+
...numericGrade(record),
|
|
1005
|
+
...typeof record.error === "string" ? { error: record.error } : {}
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
1008
|
+
return out;
|
|
1009
|
+
}
|
|
515
1010
|
function schemaFromSignature(spec) {
|
|
516
1011
|
if (spec.inputSchema)
|
|
517
1012
|
return {
|
|
@@ -571,12 +1066,9 @@ async function attachSession(sessionId, options = {}) {
|
|
|
571
1066
|
);
|
|
572
1067
|
return new WorldSession(sessionId, state2, options);
|
|
573
1068
|
}
|
|
574
|
-
async function openSession(slugOrRef, taskOrOpts, positionalOpts = {}) {
|
|
575
|
-
const { task, ...opts } =
|
|
576
|
-
if (task
|
|
577
|
-
throw new Error(
|
|
578
|
-
"openSession needs a task: a bundled task name, a stored task { id, version? } or { instruction, seed?, grader?, metadata? }"
|
|
579
|
-
);
|
|
1069
|
+
async function openSession(slugOrRef, taskOrOpts = {}, positionalOpts = {}) {
|
|
1070
|
+
const { task, ...opts } = isOpenSessionOptions(taskOrOpts) ? taskOrOpts : { task: taskOrOpts, ...positionalOpts };
|
|
1071
|
+
if (task !== void 0) assertTaskRef(task);
|
|
580
1072
|
const options = opts.options ?? {};
|
|
581
1073
|
const unknown = (opts.surfaces ?? []).filter(
|
|
582
1074
|
(s) => !SURFACE_KINDS.includes(s)
|
|
@@ -585,6 +1077,7 @@ async function openSession(slugOrRef, taskOrOpts, positionalOpts = {}) {
|
|
|
585
1077
|
throw new Error(
|
|
586
1078
|
`Unknown world surfaces: ${unknown.join(", ")}; choose from ${SURFACE_KINDS.join(", ")}`
|
|
587
1079
|
);
|
|
1080
|
+
if (opts.browserTier !== void 0) assertBrowserTier(opts.browserTier);
|
|
588
1081
|
const at = slugOrRef.indexOf("@");
|
|
589
1082
|
const slug = at === -1 ? slugOrRef : slugOrRef.slice(0, at);
|
|
590
1083
|
const ref = at === -1 ? "" : slugOrRef.slice(at + 1);
|
|
@@ -594,9 +1087,10 @@ async function openSession(slugOrRef, taskOrOpts, positionalOpts = {}) {
|
|
|
594
1087
|
"/api/public/world-sessions",
|
|
595
1088
|
{
|
|
596
1089
|
...opts.versionId ? { versionId: opts.versionId } : { slug, ...ref && { ref } },
|
|
597
|
-
task,
|
|
1090
|
+
...task === void 0 ? {} : { task },
|
|
598
1091
|
...opts.reuseWarm === void 0 ? {} : { reuseWarm: opts.reuseWarm },
|
|
599
|
-
...opts.surfaces?.length ? { surfaces: opts.surfaces } : {}
|
|
1092
|
+
...opts.surfaces?.length ? { surfaces: opts.surfaces } : {},
|
|
1093
|
+
...opts.browserTier === void 0 ? {} : { browserTier: opts.browserTier }
|
|
600
1094
|
}
|
|
601
1095
|
);
|
|
602
1096
|
return new WorldSession(state2.sessionId, state2, options);
|
|
@@ -672,20 +1166,15 @@ async function runSessions(opts) {
|
|
|
672
1166
|
passed: failed === 0 && (opts.failUnder === void 0 || mean >= opts.failUnder)
|
|
673
1167
|
};
|
|
674
1168
|
}
|
|
675
|
-
var
|
|
1169
|
+
var 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;
|
|
676
1170
|
var init_session = __esm({
|
|
677
1171
|
"src/worlds/session.ts"() {
|
|
678
1172
|
"use strict";
|
|
679
1173
|
init_worlds();
|
|
680
1174
|
init_browser();
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
if (typeof task === "string") return task;
|
|
685
|
-
if (isTaskIdRef(task)) return info?.name ?? task.id;
|
|
686
|
-
if (task.name) return task.name;
|
|
687
|
-
return info?.hash ? `inline:${info.hash.slice(0, 12)}` : "inline";
|
|
688
|
-
};
|
|
1175
|
+
init_sessionContract();
|
|
1176
|
+
init_taskRef();
|
|
1177
|
+
init_taskRef();
|
|
689
1178
|
READY_TIMEOUT_MS = 10 * 6e4;
|
|
690
1179
|
READY_POLL_MS = 2e3;
|
|
691
1180
|
CALL_TIMEOUT_MS = 3 * 6e4;
|
|
@@ -705,16 +1194,25 @@ var init_session = __esm({
|
|
|
705
1194
|
this.current = current;
|
|
706
1195
|
this.options = options;
|
|
707
1196
|
}
|
|
1197
|
+
sessionId;
|
|
1198
|
+
current;
|
|
1199
|
+
options;
|
|
708
1200
|
/** The task's display name: a bundled scenario's, or the inline spec's
|
|
709
|
-
* `name` (null when the spec was unnamed).
|
|
710
|
-
get task() {
|
|
711
|
-
return this.current.taskName;
|
|
712
|
-
}
|
|
713
|
-
/** The task's display name: a bundled scenario's, or the inline spec's
|
|
714
|
-
* `name` (null when the spec was unnamed). */
|
|
1201
|
+
* `name` (null when the spec was unnamed). `task` is the same. */
|
|
715
1202
|
get taskName() {
|
|
716
1203
|
return this.current.taskName;
|
|
717
1204
|
}
|
|
1205
|
+
get task() {
|
|
1206
|
+
return this.taskName;
|
|
1207
|
+
}
|
|
1208
|
+
/** `{idleExpiresAt, pinned}` as of the last state read: when the fleet
|
|
1209
|
+
* reaps the session (null once pinned), and whether it is pinned. */
|
|
1210
|
+
get idle() {
|
|
1211
|
+
return {
|
|
1212
|
+
idleExpiresAt: this.current.idleExpiresAt ?? null,
|
|
1213
|
+
pinned: this.current.pinned ?? false
|
|
1214
|
+
};
|
|
1215
|
+
}
|
|
718
1216
|
/** The platform's notices about the world this session runs on (empty
|
|
719
1217
|
* for a schema world). Printed by the CLI on stderr at open. */
|
|
720
1218
|
get deprecations() {
|
|
@@ -788,23 +1286,37 @@ var init_session = __esm({
|
|
|
788
1286
|
const { agentId, record = true, ...rest } = opts;
|
|
789
1287
|
return openBrowser(await this.surfaces(), {
|
|
790
1288
|
...rest,
|
|
791
|
-
recorder: record ? this.browserRecorder(agentId) : null
|
|
1289
|
+
recorder: record ? this.browserRecorder(agentId) : null,
|
|
1290
|
+
repair: () => this.repairBrowser()
|
|
792
1291
|
});
|
|
793
1292
|
}
|
|
1293
|
+
/** Ask the platform to make this session's hosted browser reachable again
|
|
1294
|
+
* after its connection dropped: `healthy` (reconnect now), `replaced` (a new,
|
|
1295
|
+
* blank browser behind the same wsUrl; reconnect and reopen your page) or
|
|
1296
|
+
* `starting` (ask again in `retryAfterMs`). `browser()` does this on its
|
|
1297
|
+
* own; call it when you drive your own Playwright against `wsUrl`. */
|
|
1298
|
+
async repairBrowser() {
|
|
1299
|
+
return apiRequest(
|
|
1300
|
+
this.options,
|
|
1301
|
+
"POST",
|
|
1302
|
+
`/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/browser-repair`,
|
|
1303
|
+
{}
|
|
1304
|
+
);
|
|
1305
|
+
}
|
|
794
1306
|
/** The reporter `browser()` uses; exposed for a page you drive yourself. */
|
|
795
1307
|
browserRecorder(agentId) {
|
|
796
|
-
const
|
|
1308
|
+
const path12 = `/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/browser-events`;
|
|
797
1309
|
const id = agentId ?? process.env.GATEWAY_AGENT_ID ?? `agent-${randomUUID().replace(/-/g, "").slice(0, 8)}`;
|
|
798
1310
|
return new BrowserActionRecorder(
|
|
799
1311
|
async (events) => {
|
|
800
|
-
await apiRequest(this.options, "POST",
|
|
1312
|
+
await apiRequest(this.options, "POST", path12, { events });
|
|
801
1313
|
},
|
|
802
1314
|
id,
|
|
803
1315
|
{
|
|
804
1316
|
// Continue this agent's timeline where the platform has it, so the
|
|
805
1317
|
// same id reopened later never re-numbers from zero.
|
|
806
1318
|
resumeFrom: async () => {
|
|
807
|
-
const summary = await apiRequest(this.options, "GET",
|
|
1319
|
+
const summary = await apiRequest(this.options, "GET", path12);
|
|
808
1320
|
return summary.agents.find((a) => a.agentId === id)?.nextSeq ?? 0;
|
|
809
1321
|
}
|
|
810
1322
|
}
|
|
@@ -852,6 +1364,7 @@ var init_session = __esm({
|
|
|
852
1364
|
}
|
|
853
1365
|
/** Enqueue one interaction and wait for the container's answer. */
|
|
854
1366
|
async exchange(body, timeoutMs) {
|
|
1367
|
+
serializeCallBody(body);
|
|
855
1368
|
const enqueued = await apiRequest(
|
|
856
1369
|
this.options,
|
|
857
1370
|
"POST",
|
|
@@ -923,26 +1436,25 @@ var init_session = __esm({
|
|
|
923
1436
|
* the judge's budget (15 min) instead of a call's. `timeoutMs` overrides
|
|
924
1437
|
* either. `report` is the agent's own account of what it did and found,
|
|
925
1438
|
* handed to the judge as its claim beside the evidence (the state and the
|
|
926
|
-
* calls); assertions and python graders ignore it.
|
|
1439
|
+
* calls); assertions and python graders ignore it. `worlds` names the
|
|
1440
|
+
* task's other sessions by alias (`{alias: sessionId}`): the platform
|
|
1441
|
+
* reads each one's evidence and hands it to the cross-world verifiers
|
|
1442
|
+
* anchored on this session, whose grades come back under `verifiers`. */
|
|
927
1443
|
async grade(opts = {}) {
|
|
928
1444
|
const raw = await this.exchange(
|
|
929
|
-
|
|
1445
|
+
{
|
|
1446
|
+
kind: "grade",
|
|
1447
|
+
...opts.report !== void 0 ? { report: opts.report } : {},
|
|
1448
|
+
...opts.worlds && Object.keys(opts.worlds).length > 0 ? { worlds: opts.worlds } : {}
|
|
1449
|
+
},
|
|
930
1450
|
opts.timeoutMs
|
|
931
1451
|
);
|
|
932
1452
|
const record = raw && typeof raw === "object" ? raw : {};
|
|
933
|
-
const
|
|
934
|
-
const nested = record.rewards;
|
|
935
|
-
if (nested && typeof nested === "object") {
|
|
936
|
-
for (const [key, value] of Object.entries(nested)) {
|
|
937
|
-
if (typeof value === "number") rewards[key] = value;
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
for (const [key, value] of Object.entries(record)) {
|
|
941
|
-
if (key !== "reward" && typeof value === "number") rewards[key] = value;
|
|
942
|
-
}
|
|
1453
|
+
const verifiers = verifierGrades(record.verifiers);
|
|
943
1454
|
return {
|
|
944
|
-
|
|
945
|
-
|
|
1455
|
+
...numericGrade(record),
|
|
1456
|
+
...typeof record.reason === "string" ? { reason: record.reason } : {},
|
|
1457
|
+
...verifiers ? { verifiers } : {},
|
|
946
1458
|
raw
|
|
947
1459
|
};
|
|
948
1460
|
}
|
|
@@ -1049,6 +1561,46 @@ var init_session = __esm({
|
|
|
1049
1561
|
);
|
|
1050
1562
|
}
|
|
1051
1563
|
};
|
|
1564
|
+
OPEN_SESSION_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
1565
|
+
"task",
|
|
1566
|
+
"versionId",
|
|
1567
|
+
"reuseWarm",
|
|
1568
|
+
"surfaces",
|
|
1569
|
+
"browserTier",
|
|
1570
|
+
"options"
|
|
1571
|
+
]);
|
|
1572
|
+
isOpenSessionOptions = (value) => typeof value === "object" && value !== null && Object.keys(value).every((key) => OPEN_SESSION_OPTION_KEYS.has(key));
|
|
1573
|
+
}
|
|
1574
|
+
});
|
|
1575
|
+
|
|
1576
|
+
// src/worlds/sessionList.ts
|
|
1577
|
+
async function listSessions(filter = {}, options = {}) {
|
|
1578
|
+
const params = new URLSearchParams();
|
|
1579
|
+
if (filter.state) params.set("state", filter.state);
|
|
1580
|
+
if (filter.slug) params.set("slug", filter.slug);
|
|
1581
|
+
if (filter.limit !== void 0) params.set("limit", String(filter.limit));
|
|
1582
|
+
const qs = params.toString();
|
|
1583
|
+
const res = await apiRequest(
|
|
1584
|
+
options,
|
|
1585
|
+
"GET",
|
|
1586
|
+
`/api/public/world-sessions${qs ? `?${qs}` : ""}`
|
|
1587
|
+
);
|
|
1588
|
+
return res.sessions;
|
|
1589
|
+
}
|
|
1590
|
+
var SESSION_STATES;
|
|
1591
|
+
var init_sessionList = __esm({
|
|
1592
|
+
"src/worlds/sessionList.ts"() {
|
|
1593
|
+
"use strict";
|
|
1594
|
+
init_worlds();
|
|
1595
|
+
SESSION_STATES = [
|
|
1596
|
+
"PROVISIONING",
|
|
1597
|
+
"RUNNING",
|
|
1598
|
+
"IDLE",
|
|
1599
|
+
"STOPPING",
|
|
1600
|
+
"STOPPED",
|
|
1601
|
+
"FAILED",
|
|
1602
|
+
"LOST"
|
|
1603
|
+
];
|
|
1052
1604
|
}
|
|
1053
1605
|
});
|
|
1054
1606
|
|
|
@@ -1134,16 +1686,23 @@ function aggregateTaskGrade(worlds) {
|
|
|
1134
1686
|
const rewards = {};
|
|
1135
1687
|
const ungraded = [];
|
|
1136
1688
|
const graded = [];
|
|
1137
|
-
|
|
1689
|
+
const verifiers = {};
|
|
1690
|
+
const fold = (key, grade) => {
|
|
1138
1691
|
if (typeof grade.reward === "number") {
|
|
1139
|
-
rewards[
|
|
1692
|
+
rewards[key] = grade.reward;
|
|
1140
1693
|
graded.push(grade.reward);
|
|
1141
|
-
} else ungraded.push(
|
|
1142
|
-
for (const [
|
|
1143
|
-
rewards[`${
|
|
1694
|
+
} else ungraded.push(key);
|
|
1695
|
+
for (const [name, value] of Object.entries(grade.rewards))
|
|
1696
|
+
rewards[`${key}.${name}`] = value;
|
|
1697
|
+
};
|
|
1698
|
+
for (const [alias, grade] of Object.entries(worlds)) {
|
|
1699
|
+
fold(alias, grade);
|
|
1700
|
+
Object.assign(verifiers, grade.verifiers ?? {});
|
|
1144
1701
|
}
|
|
1702
|
+
for (const [name, grade] of Object.entries(verifiers))
|
|
1703
|
+
fold(`${VERIFIER_REWARD_PREFIX}${name}`, grade);
|
|
1145
1704
|
const reward = graded.length > 0 ? graded.reduce((a, b) => a + b, 0) / graded.length : null;
|
|
1146
|
-
return { reward, rewards, worlds, ungraded };
|
|
1705
|
+
return { reward, rewards, worlds, ungraded, verifiers };
|
|
1147
1706
|
}
|
|
1148
1707
|
function fromResponse(answer, options) {
|
|
1149
1708
|
const sessions = {};
|
|
@@ -1176,6 +1735,7 @@ async function openTask(ref, opts = {}) {
|
|
|
1176
1735
|
throw new Error(
|
|
1177
1736
|
"openTask needs a spec that names its worlds; a single-world spec opens with openSession"
|
|
1178
1737
|
);
|
|
1738
|
+
if (opts.browserTier !== void 0) assertBrowserTier(opts.browserTier);
|
|
1179
1739
|
const answer = await apiRequest(
|
|
1180
1740
|
options,
|
|
1181
1741
|
"POST",
|
|
@@ -1183,7 +1743,8 @@ async function openTask(ref, opts = {}) {
|
|
|
1183
1743
|
{
|
|
1184
1744
|
task,
|
|
1185
1745
|
...opts.reuseWarm === void 0 ? {} : { reuseWarm: opts.reuseWarm },
|
|
1186
|
-
...opts.surfaces?.length ? { surfaces: opts.surfaces } : {}
|
|
1746
|
+
...opts.surfaces?.length ? { surfaces: opts.surfaces } : {},
|
|
1747
|
+
...opts.browserTier === void 0 ? {} : { browserTier: opts.browserTier }
|
|
1187
1748
|
}
|
|
1188
1749
|
);
|
|
1189
1750
|
return fromResponse(answer, options);
|
|
@@ -1259,7 +1820,7 @@ async function attachManifest(manifest, options = {}) {
|
|
|
1259
1820
|
function isTaskManifest(value) {
|
|
1260
1821
|
return typeof value === "object" && value !== null && !Array.isArray(value) && typeof value.sessions === "object" && value.sessions !== null && !("instruction" in value && "worlds" in value);
|
|
1261
1822
|
}
|
|
1262
|
-
var TASK_SESSIONS, manifestSession, TaskSessions;
|
|
1823
|
+
var TASK_SESSIONS, VERIFIER_REWARD_PREFIX, manifestSession, TaskSessions;
|
|
1263
1824
|
var init_taskSessions = __esm({
|
|
1264
1825
|
"src/worlds/taskSessions.ts"() {
|
|
1265
1826
|
"use strict";
|
|
@@ -1267,6 +1828,7 @@ var init_taskSessions = __esm({
|
|
|
1267
1828
|
init_browser();
|
|
1268
1829
|
init_session();
|
|
1269
1830
|
TASK_SESSIONS = "/api/public/world-task-sessions";
|
|
1831
|
+
VERIFIER_REWARD_PREFIX = "x.";
|
|
1270
1832
|
manifestSession = (s, state2, world) => ({
|
|
1271
1833
|
slug: world.slug,
|
|
1272
1834
|
ref: world.ref,
|
|
@@ -1297,6 +1859,13 @@ var init_taskSessions = __esm({
|
|
|
1297
1859
|
this.worlds = worlds;
|
|
1298
1860
|
this.hash = hash;
|
|
1299
1861
|
}
|
|
1862
|
+
taskId;
|
|
1863
|
+
taskVersion;
|
|
1864
|
+
name;
|
|
1865
|
+
instruction;
|
|
1866
|
+
sessions;
|
|
1867
|
+
worlds;
|
|
1868
|
+
hash;
|
|
1300
1869
|
/** This alias's `{slug, ref}` as recorded at open/attach — the world a
|
|
1301
1870
|
* `TaskRun` filing needs to name, without exposing the whole map. */
|
|
1302
1871
|
worldRef(alias) {
|
|
@@ -1356,10 +1925,20 @@ var init_taskSessions = __esm({
|
|
|
1356
1925
|
}
|
|
1357
1926
|
/** Grade every world and aggregate — see `TaskGrade`. One `report` (the
|
|
1358
1927
|
* agent's own account of the whole investigation) goes to every world's
|
|
1359
|
-
* judge; a world graded by assertions or python ignores it.
|
|
1928
|
+
* judge; a world graded by assertions or python ignores it. Each grade
|
|
1929
|
+
* names the task's other sessions by alias, so the cross-world verifiers
|
|
1930
|
+
* anchored on that world can read them. */
|
|
1360
1931
|
async grade(opts = {}) {
|
|
1361
1932
|
return aggregateTaskGrade(
|
|
1362
|
-
await this.each(
|
|
1933
|
+
await this.each(
|
|
1934
|
+
(session, alias) => session.grade({ ...opts, worlds: this.otherSessions(alias) })
|
|
1935
|
+
)
|
|
1936
|
+
);
|
|
1937
|
+
}
|
|
1938
|
+
/** The task's other sessions by alias: what a grade names. */
|
|
1939
|
+
otherSessions(alias) {
|
|
1940
|
+
return Object.fromEntries(
|
|
1941
|
+
Object.entries(this.sessions).filter(([other]) => other !== alias).map(([other, session]) => [other, session.sessionId])
|
|
1363
1942
|
);
|
|
1364
1943
|
}
|
|
1365
1944
|
/** Every world's call log, keyed by alias. */
|
|
@@ -1405,10 +1984,11 @@ var init_evals = __esm({
|
|
|
1405
1984
|
constructor(options = {}) {
|
|
1406
1985
|
this.options = options;
|
|
1407
1986
|
}
|
|
1408
|
-
|
|
1987
|
+
options;
|
|
1409
1988
|
async createEvaluation(versionId, opts = {}) {
|
|
1410
1989
|
const body = { versionId };
|
|
1411
1990
|
if (opts.model !== void 0) body.model = opts.model;
|
|
1991
|
+
if (opts.runId !== void 0) body.runId = opts.runId;
|
|
1412
1992
|
if (opts.rolloutsPerExample !== void 0)
|
|
1413
1993
|
body.rolloutsPerExample = opts.rolloutsPerExample;
|
|
1414
1994
|
if (opts.metadata !== void 0) body.metadata = opts.metadata;
|
|
@@ -1420,7 +2000,6 @@ var init_evals = __esm({
|
|
|
1420
2000
|
);
|
|
1421
2001
|
return answer.evaluationId;
|
|
1422
2002
|
}
|
|
1423
|
-
/** Push one batch of samples; returns how many the platform inserted. */
|
|
1424
2003
|
async pushSamples(evaluationId, samples) {
|
|
1425
2004
|
const answer = await apiRequest(
|
|
1426
2005
|
this.options,
|
|
@@ -1430,7 +2009,6 @@ var init_evals = __esm({
|
|
|
1430
2009
|
);
|
|
1431
2010
|
return answer.inserted ?? samples.length;
|
|
1432
2011
|
}
|
|
1433
|
-
/** Close the evaluation out; returns its final status. */
|
|
1434
2012
|
async finalizeEvaluation(evaluationId, opts = {}) {
|
|
1435
2013
|
const body = {
|
|
1436
2014
|
status: opts.status ?? "COMPLETED"
|
|
@@ -1610,10 +2188,10 @@ var init_users = __esm({
|
|
|
1610
2188
|
totalItems: Number(meta.totalItems ?? rows.length)
|
|
1611
2189
|
};
|
|
1612
2190
|
}
|
|
1613
|
-
async requestJson(method,
|
|
2191
|
+
async requestJson(method, path12, payload) {
|
|
1614
2192
|
let response;
|
|
1615
2193
|
try {
|
|
1616
|
-
response = await fetch(`${this.host}${
|
|
2194
|
+
response = await fetch(`${this.host}${path12}`, {
|
|
1617
2195
|
method,
|
|
1618
2196
|
headers: {
|
|
1619
2197
|
Authorization: this.authHeader(),
|
|
@@ -1624,17 +2202,17 @@ var init_users = __esm({
|
|
|
1624
2202
|
});
|
|
1625
2203
|
} catch (error) {
|
|
1626
2204
|
throw new UserProfileError(
|
|
1627
|
-
`${method} ${
|
|
2205
|
+
`${method} ${path12} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
1628
2206
|
{ cause: error }
|
|
1629
2207
|
);
|
|
1630
2208
|
}
|
|
1631
2209
|
const text2 = await response.text();
|
|
1632
2210
|
if (!response.ok) {
|
|
1633
2211
|
throw new UserProfileError(
|
|
1634
|
-
`${method} ${
|
|
2212
|
+
`${method} ${path12} failed (${response.status}): ${text2.slice(0, 500)}`
|
|
1635
2213
|
);
|
|
1636
2214
|
}
|
|
1637
|
-
this.log("%s %s -> %s", method,
|
|
2215
|
+
this.log("%s %s -> %s", method, path12, response.status);
|
|
1638
2216
|
return safeJson(text2);
|
|
1639
2217
|
}
|
|
1640
2218
|
authHeader() {
|
|
@@ -1700,9 +2278,9 @@ function getAmbientSessionId() {
|
|
|
1700
2278
|
return currentSessionStorage.getStore();
|
|
1701
2279
|
}
|
|
1702
2280
|
function withSession(sessionId, fn) {
|
|
1703
|
-
return new Promise((
|
|
2281
|
+
return new Promise((resolve7, reject) => {
|
|
1704
2282
|
currentSessionStorage.run(sessionId, () => {
|
|
1705
|
-
Promise.resolve().then(fn).then(
|
|
2283
|
+
Promise.resolve().then(fn).then(resolve7, reject);
|
|
1706
2284
|
});
|
|
1707
2285
|
});
|
|
1708
2286
|
}
|
|
@@ -1898,10 +2476,10 @@ var init_scores = __esm({
|
|
|
1898
2476
|
metadata: signalMetadata
|
|
1899
2477
|
});
|
|
1900
2478
|
}
|
|
1901
|
-
async request(method,
|
|
2479
|
+
async request(method, path12, payload) {
|
|
1902
2480
|
let response;
|
|
1903
2481
|
try {
|
|
1904
|
-
response = await fetch(`${this.host}${
|
|
2482
|
+
response = await fetch(`${this.host}${path12}`, {
|
|
1905
2483
|
method,
|
|
1906
2484
|
headers: {
|
|
1907
2485
|
Authorization: this.authHeader(),
|
|
@@ -1912,17 +2490,17 @@ var init_scores = __esm({
|
|
|
1912
2490
|
});
|
|
1913
2491
|
} catch (error) {
|
|
1914
2492
|
throw new ScoreError(
|
|
1915
|
-
`${method} ${
|
|
2493
|
+
`${method} ${path12} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
1916
2494
|
{ cause: error }
|
|
1917
2495
|
);
|
|
1918
2496
|
}
|
|
1919
2497
|
const text2 = await response.text();
|
|
1920
2498
|
if (!response.ok) {
|
|
1921
2499
|
throw new ScoreError(
|
|
1922
|
-
`${method} ${
|
|
2500
|
+
`${method} ${path12} failed (${response.status}): ${text2.slice(0, 500)}`
|
|
1923
2501
|
);
|
|
1924
2502
|
}
|
|
1925
|
-
this.log("%s %s -> %s", method,
|
|
2503
|
+
this.log("%s %s -> %s", method, path12, response.status);
|
|
1926
2504
|
}
|
|
1927
2505
|
authHeader() {
|
|
1928
2506
|
return `Basic ${Buffer.from(`${this.publicKey}:${this.secretKey}`).toString(
|
|
@@ -1950,7 +2528,7 @@ var require_package = __commonJS({
|
|
|
1950
2528
|
"package.json"(exports, module) {
|
|
1951
2529
|
module.exports = {
|
|
1952
2530
|
name: "@withgateway/sdk",
|
|
1953
|
-
version: "0.2.
|
|
2531
|
+
version: "0.2.9",
|
|
1954
2532
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
1955
2533
|
main: "./dist/index.js",
|
|
1956
2534
|
module: "./dist/index.mjs",
|
|
@@ -2105,16 +2683,16 @@ var require_package = __commonJS({
|
|
|
2105
2683
|
}
|
|
2106
2684
|
},
|
|
2107
2685
|
optionalDependencies: {
|
|
2108
|
-
"@arizeai/openinference-instrumentation-anthropic": "^0.
|
|
2109
|
-
"@arizeai/openinference-instrumentation-openai": "^4.
|
|
2686
|
+
"@arizeai/openinference-instrumentation-anthropic": "^0.2.8",
|
|
2687
|
+
"@arizeai/openinference-instrumentation-openai": "^4.2.7"
|
|
2110
2688
|
},
|
|
2111
2689
|
devDependencies: {
|
|
2112
|
-
"@anthropic-ai/sdk": "^0.
|
|
2690
|
+
"@anthropic-ai/sdk": "^0.91.1",
|
|
2113
2691
|
"@opentelemetry/api": "^1.9.0",
|
|
2114
|
-
"@opentelemetry/exporter-trace-otlp-http": "^0.
|
|
2115
|
-
"@opentelemetry/resources": "^2.
|
|
2116
|
-
"@opentelemetry/sdk-trace-base": "^
|
|
2117
|
-
"@opentelemetry/sdk-trace-node": "^2.
|
|
2692
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.222.0",
|
|
2693
|
+
"@opentelemetry/resources": "^2.11.0",
|
|
2694
|
+
"@opentelemetry/sdk-trace-base": "^2.11.0",
|
|
2695
|
+
"@opentelemetry/sdk-trace-node": "^2.11.0",
|
|
2118
2696
|
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
2119
2697
|
"@types/node": "^20.0.0",
|
|
2120
2698
|
openai: "^4.70.0",
|
|
@@ -2127,7 +2705,9 @@ var require_package = __commonJS({
|
|
|
2127
2705
|
protobufjs: "^8.4.1",
|
|
2128
2706
|
"vite@6": "^6.4.3",
|
|
2129
2707
|
postcss: "^8.5.18",
|
|
2130
|
-
"picomatch@4": "^4.0.4"
|
|
2708
|
+
"picomatch@4": "^4.0.4",
|
|
2709
|
+
nanoid: ">=3.3.18",
|
|
2710
|
+
esbuild: ">=0.28.1"
|
|
2131
2711
|
},
|
|
2132
2712
|
pnpm: {
|
|
2133
2713
|
overrides: {
|
|
@@ -2135,7 +2715,9 @@ var require_package = __commonJS({
|
|
|
2135
2715
|
vitest: "^3.2.6",
|
|
2136
2716
|
"vite@6": "^6.4.3",
|
|
2137
2717
|
postcss: "^8.5.18",
|
|
2138
|
-
"picomatch@4": "^4.0.4"
|
|
2718
|
+
"picomatch@4": "^4.0.4",
|
|
2719
|
+
nanoid: ">=3.3.18",
|
|
2720
|
+
esbuild: ">=0.28.1"
|
|
2139
2721
|
}
|
|
2140
2722
|
},
|
|
2141
2723
|
bin: {
|
|
@@ -2654,7 +3236,7 @@ function worldRef(live, alias) {
|
|
|
2654
3236
|
sessionId: session.sessionId
|
|
2655
3237
|
};
|
|
2656
3238
|
}
|
|
2657
|
-
async function fileTaskRun(live, runId, model, report, grade, agentError, traced, runDir, options) {
|
|
3239
|
+
async function fileTaskRun(live, runId, model, report, grade, agentError, traced, runDir, options, setRunId) {
|
|
2658
3240
|
const aliases = live.aliases;
|
|
2659
3241
|
const anchor = aliases[0];
|
|
2660
3242
|
const worldsMeta = Object.fromEntries(
|
|
@@ -2666,6 +3248,7 @@ async function fileTaskRun(live, runId, model, report, grade, agentError, traced
|
|
|
2666
3248
|
{
|
|
2667
3249
|
model,
|
|
2668
3250
|
rolloutsPerExample: 1,
|
|
3251
|
+
...setRunId ? { runId: setRunId } : {},
|
|
2669
3252
|
metadata: {
|
|
2670
3253
|
source: "worlds-task-run",
|
|
2671
3254
|
task: {
|
|
@@ -2748,6 +3331,7 @@ async function runTask(ref, agent, opts) {
|
|
|
2748
3331
|
const live = await openTask(ref, {
|
|
2749
3332
|
surfaces: opts.surfaces,
|
|
2750
3333
|
reuseWarm: opts.reuseWarm,
|
|
3334
|
+
browserTier: opts.browserTier,
|
|
2751
3335
|
options
|
|
2752
3336
|
});
|
|
2753
3337
|
const started = Date.now();
|
|
@@ -2783,6 +3367,8 @@ async function runTask(ref, agent, opts) {
|
|
|
2783
3367
|
const message = (error instanceof Error ? error.message : String(error)) || "Unknown error";
|
|
2784
3368
|
agentError = message.slice(0, 2e3);
|
|
2785
3369
|
}
|
|
3370
|
+
if (traced)
|
|
3371
|
+
await Promise.resolve().then(() => (init_init(), init_exports)).then((tracing) => tracing.flush()).catch(() => void 0);
|
|
2786
3372
|
const grade = report !== null ? await live.grade({ report }) : await live.grade();
|
|
2787
3373
|
fs.writeFileSync(
|
|
2788
3374
|
path.join(runDir, "manifest.json"),
|
|
@@ -2823,7 +3409,8 @@ async function runTask(ref, agent, opts) {
|
|
|
2823
3409
|
agentError,
|
|
2824
3410
|
traced,
|
|
2825
3411
|
runDir,
|
|
2826
|
-
options
|
|
3412
|
+
options,
|
|
3413
|
+
opts.setRunId
|
|
2827
3414
|
);
|
|
2828
3415
|
summary.filed = true;
|
|
2829
3416
|
}
|
|
@@ -2857,8 +3444,12 @@ var init_taskRun = __esm({
|
|
|
2857
3444
|
this.sessions = sessions;
|
|
2858
3445
|
this.manifest = manifest;
|
|
2859
3446
|
}
|
|
3447
|
+
runId;
|
|
3448
|
+
instruction;
|
|
3449
|
+
model;
|
|
3450
|
+
sessions;
|
|
3451
|
+
manifest;
|
|
2860
3452
|
notes = {};
|
|
2861
|
-
/** The alias's session, or a clear error naming the aliases there are. */
|
|
2862
3453
|
session(alias) {
|
|
2863
3454
|
const session = this.sessions[alias];
|
|
2864
3455
|
if (!session)
|
|
@@ -2867,8 +3458,7 @@ var init_taskRun = __esm({
|
|
|
2867
3458
|
);
|
|
2868
3459
|
return session;
|
|
2869
3460
|
}
|
|
2870
|
-
/**
|
|
2871
|
-
* when it was not opened with `surfaces: ["api"]`. */
|
|
3461
|
+
/** Raises when the session was not opened with `surfaces: ["api"]`. */
|
|
2872
3462
|
async api(alias) {
|
|
2873
3463
|
const surfaces = await this.session(alias).surfaces();
|
|
2874
3464
|
if (!surfaces.api)
|
|
@@ -2878,10 +3468,7 @@ var init_taskRun = __esm({
|
|
|
2878
3468
|
);
|
|
2879
3469
|
return { url: surfaces.api.url, token: surfaces.api.token };
|
|
2880
3470
|
}
|
|
2881
|
-
/**
|
|
2882
|
-
* `<alias>.<tool>` so a model can tell which world a call goes to. A
|
|
2883
|
-
* world that exposes no tools contributes nothing — there is nothing to
|
|
2884
|
-
* merge. */
|
|
3471
|
+
/** Each tool is prefixed `<alias>.<tool>` so a model can tell which world a call goes to. */
|
|
2885
3472
|
async toolkit() {
|
|
2886
3473
|
const schemas = [];
|
|
2887
3474
|
const impls = {};
|
|
@@ -2906,8 +3493,7 @@ var init_taskRun = __esm({
|
|
|
2906
3493
|
}
|
|
2907
3494
|
return { schemas, impls, specs };
|
|
2908
3495
|
}
|
|
2909
|
-
/**
|
|
2910
|
-
* overrides a key an earlier one set). */
|
|
3496
|
+
/** Merged into `run.json` under `notes`; a later call overrides an earlier key. */
|
|
2911
3497
|
record(notes) {
|
|
2912
3498
|
Object.assign(this.notes, notes);
|
|
2913
3499
|
}
|
|
@@ -2917,11 +3503,250 @@ var init_taskRun = __esm({
|
|
|
2917
3503
|
}
|
|
2918
3504
|
});
|
|
2919
3505
|
|
|
2920
|
-
// src/worlds/
|
|
2921
|
-
import {
|
|
3506
|
+
// src/worlds/checkoutProvenance.ts
|
|
3507
|
+
import { execFileSync } from "child_process";
|
|
3508
|
+
var CheckoutProvenance;
|
|
3509
|
+
var init_checkoutProvenance = __esm({
|
|
3510
|
+
"src/worlds/checkoutProvenance.ts"() {
|
|
3511
|
+
"use strict";
|
|
3512
|
+
CheckoutProvenance = class _CheckoutProvenance {
|
|
3513
|
+
constructor(cwd, env) {
|
|
3514
|
+
this.cwd = cwd;
|
|
3515
|
+
this.env = env;
|
|
3516
|
+
}
|
|
3517
|
+
cwd;
|
|
3518
|
+
env;
|
|
3519
|
+
static read(cwd = process.cwd(), env = process.env) {
|
|
3520
|
+
return new _CheckoutProvenance(cwd, env).checkout();
|
|
3521
|
+
}
|
|
3522
|
+
checkout() {
|
|
3523
|
+
const commit = this.git("rev-parse", "HEAD");
|
|
3524
|
+
if (!commit) return this.withPr({});
|
|
3525
|
+
const branch = this.env.GITHUB_HEAD_REF || this.git("rev-parse", "--abbrev-ref", "HEAD");
|
|
3526
|
+
const remote = this.git("config", "--get", "remote.origin.url");
|
|
3527
|
+
return this.withPr({
|
|
3528
|
+
commit,
|
|
3529
|
+
...branch && branch !== "HEAD" ? { branch } : {},
|
|
3530
|
+
...remote ? { repoUrl: _CheckoutProvenance.withoutCredentials(remote) } : {}
|
|
3531
|
+
});
|
|
3532
|
+
}
|
|
3533
|
+
/** Security: credentials are stripped; scp-style `git@host:org/repo` has none and is kept. */
|
|
3534
|
+
static withoutCredentials(url) {
|
|
3535
|
+
return url.replace(/^([a-z][a-z0-9+.-]*:\/\/)[^@/]+@/i, "$1");
|
|
3536
|
+
}
|
|
3537
|
+
withPr(checkout) {
|
|
3538
|
+
const pr = this.pullRequest();
|
|
3539
|
+
return pr ? { ...checkout, pr } : checkout;
|
|
3540
|
+
}
|
|
3541
|
+
pullRequest() {
|
|
3542
|
+
const url = this.env.GATEWAY_PR_URL;
|
|
3543
|
+
const fromUrl = url ? /\/pull\/(\d+)/.exec(url)?.[1] : void 0;
|
|
3544
|
+
if (url && fromUrl)
|
|
3545
|
+
return {
|
|
3546
|
+
number: Number(fromUrl),
|
|
3547
|
+
url,
|
|
3548
|
+
...this.env.GATEWAY_PR_TITLE ? { title: this.env.GATEWAY_PR_TITLE } : {}
|
|
3549
|
+
};
|
|
3550
|
+
const number = /^refs\/pull\/(\d+)\//.exec(this.env.GITHUB_REF ?? "")?.[1];
|
|
3551
|
+
const server = this.env.GITHUB_SERVER_URL;
|
|
3552
|
+
const repo = this.env.GITHUB_REPOSITORY;
|
|
3553
|
+
if (!number || !server || !repo) return void 0;
|
|
3554
|
+
return { number: Number(number), url: `${server}/${repo}/pull/${number}` };
|
|
3555
|
+
}
|
|
3556
|
+
git(...args) {
|
|
3557
|
+
try {
|
|
3558
|
+
const out = execFileSync("git", args, {
|
|
3559
|
+
cwd: this.cwd,
|
|
3560
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
3561
|
+
timeout: 5e3
|
|
3562
|
+
}).toString().trim();
|
|
3563
|
+
return out || void 0;
|
|
3564
|
+
} catch {
|
|
3565
|
+
return void 0;
|
|
3566
|
+
}
|
|
3567
|
+
}
|
|
3568
|
+
};
|
|
3569
|
+
}
|
|
3570
|
+
});
|
|
3571
|
+
|
|
3572
|
+
// src/worlds/setRun.ts
|
|
3573
|
+
async function runSet(datasetId, agent, opts) {
|
|
3574
|
+
const options = opts.options ?? {};
|
|
3575
|
+
const git = opts.git === void 0 ? CheckoutProvenance.read() : opts.git;
|
|
3576
|
+
const opened = await apiRequest(options, "POST", SET_RUNS, {
|
|
3577
|
+
datasetId,
|
|
3578
|
+
model: opts.model,
|
|
3579
|
+
source: opts.source ?? "sdk",
|
|
3580
|
+
...git && Object.keys(git).length ? { git } : {}
|
|
3581
|
+
});
|
|
3582
|
+
const close = (status) => apiRequest(
|
|
3583
|
+
options,
|
|
3584
|
+
"POST",
|
|
3585
|
+
`${SET_RUNS}/${encodeURIComponent(opened.id)}/close`,
|
|
3586
|
+
{ status }
|
|
3587
|
+
);
|
|
3588
|
+
const onInterrupt = () => {
|
|
3589
|
+
void close("failed").finally(() => process.exit(130));
|
|
3590
|
+
};
|
|
3591
|
+
process.once("SIGINT", onInterrupt);
|
|
3592
|
+
const planned = await runPlannedTasks(opened, agent, opts, options).finally(
|
|
3593
|
+
() => process.off("SIGINT", onInterrupt)
|
|
3594
|
+
);
|
|
3595
|
+
const { tasks, failed } = planned;
|
|
3596
|
+
const requested = failed ? "failed" : "completed";
|
|
3597
|
+
const setRun = await close(requested);
|
|
3598
|
+
return {
|
|
3599
|
+
setRun,
|
|
3600
|
+
tasks,
|
|
3601
|
+
failed: failed || setRun.status !== "completed",
|
|
3602
|
+
closedAsRequested: setRun.status === requested
|
|
3603
|
+
};
|
|
3604
|
+
}
|
|
3605
|
+
async function runPlannedTasks(opened, agent, opts, options) {
|
|
3606
|
+
const tasks = [];
|
|
3607
|
+
let failed = false;
|
|
3608
|
+
for (const task of opened.tasks) {
|
|
3609
|
+
try {
|
|
3610
|
+
const summary = await runTask(task.worldTaskId, agent, {
|
|
3611
|
+
model: opts.model,
|
|
3612
|
+
surfaces: opts.surfaces,
|
|
3613
|
+
browserTier: opts.browserTier,
|
|
3614
|
+
outDir: opts.outDir,
|
|
3615
|
+
trace: opts.trace,
|
|
3616
|
+
setRunId: opened.id,
|
|
3617
|
+
options
|
|
3618
|
+
});
|
|
3619
|
+
tasks.push(summary);
|
|
3620
|
+
failed ||= summary.agentError !== null;
|
|
3621
|
+
opts.onTask?.(summary);
|
|
3622
|
+
} catch (error) {
|
|
3623
|
+
failed = true;
|
|
3624
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3625
|
+
process.stderr.write(`task ${task.name} could not run: ${message}
|
|
3626
|
+
`);
|
|
3627
|
+
}
|
|
3628
|
+
}
|
|
3629
|
+
return { tasks, failed };
|
|
3630
|
+
}
|
|
3631
|
+
var SET_RUNS;
|
|
3632
|
+
var init_setRun = __esm({
|
|
3633
|
+
"src/worlds/setRun.ts"() {
|
|
3634
|
+
"use strict";
|
|
3635
|
+
init_worlds();
|
|
3636
|
+
init_checkoutProvenance();
|
|
3637
|
+
init_taskRun();
|
|
3638
|
+
SET_RUNS = "/api/public/set-runs";
|
|
3639
|
+
}
|
|
3640
|
+
});
|
|
3641
|
+
|
|
3642
|
+
// src/worlds/checkoutTarget.ts
|
|
2922
3643
|
import * as fs2 from "fs";
|
|
2923
3644
|
import * as path2 from "path";
|
|
2924
|
-
var
|
|
3645
|
+
var CheckoutRefusedError, NAMED_EDITS, CheckoutTarget;
|
|
3646
|
+
var init_checkoutTarget = __esm({
|
|
3647
|
+
"src/worlds/checkoutTarget.ts"() {
|
|
3648
|
+
"use strict";
|
|
3649
|
+
CheckoutRefusedError = class extends Error {
|
|
3650
|
+
constructor(message) {
|
|
3651
|
+
super(`checkout refused: ${message}`);
|
|
3652
|
+
this.name = "CheckoutRefusedError";
|
|
3653
|
+
}
|
|
3654
|
+
};
|
|
3655
|
+
NAMED_EDITS = 3;
|
|
3656
|
+
CheckoutTarget = class _CheckoutTarget {
|
|
3657
|
+
constructor(dir, replaces) {
|
|
3658
|
+
this.dir = dir;
|
|
3659
|
+
this.replaces = replaces;
|
|
3660
|
+
}
|
|
3661
|
+
dir;
|
|
3662
|
+
replaces;
|
|
3663
|
+
static resolve(slug, target, opts) {
|
|
3664
|
+
if (target === void 0) return _CheckoutTarget.fresh(slug, opts.cwd);
|
|
3665
|
+
return _CheckoutTarget.explicit(
|
|
3666
|
+
_CheckoutTarget.confined(target, opts.cwd),
|
|
3667
|
+
slug,
|
|
3668
|
+
opts
|
|
3669
|
+
);
|
|
3670
|
+
}
|
|
3671
|
+
/** The absolute destination; a relative target may not resolve above `cwd`. */
|
|
3672
|
+
static confined(target, cwd) {
|
|
3673
|
+
const dir = path2.resolve(cwd, target);
|
|
3674
|
+
if (path2.isAbsolute(target)) return dir;
|
|
3675
|
+
const rel = path2.relative(cwd, dir);
|
|
3676
|
+
if (rel === "" || !rel.startsWith("..") && !path2.isAbsolute(rel))
|
|
3677
|
+
return dir;
|
|
3678
|
+
throw new CheckoutRefusedError(
|
|
3679
|
+
`--target ${target} resolves outside the current directory (${cwd}) \u2014 run from that directory, or pass an absolute path`
|
|
3680
|
+
);
|
|
3681
|
+
}
|
|
3682
|
+
static fresh(slug, cwd) {
|
|
3683
|
+
const base = path2.join(cwd, slug);
|
|
3684
|
+
let dir = base;
|
|
3685
|
+
let i = 1;
|
|
3686
|
+
while (fs2.existsSync(dir)) dir = `${base}-${i++}`;
|
|
3687
|
+
return new _CheckoutTarget(dir, []);
|
|
3688
|
+
}
|
|
3689
|
+
static explicit(dir, slug, opts) {
|
|
3690
|
+
if (!fs2.existsSync(dir)) return new _CheckoutTarget(dir, []);
|
|
3691
|
+
if (!fs2.statSync(dir).isDirectory())
|
|
3692
|
+
throw new CheckoutRefusedError(`${dir} is a file`);
|
|
3693
|
+
if (fs2.readdirSync(dir).length === 0) return new _CheckoutTarget(dir, []);
|
|
3694
|
+
const state2 = opts.state(dir);
|
|
3695
|
+
const refusal = _CheckoutTarget.refusal(dir, slug, state2);
|
|
3696
|
+
if (refusal === null || opts.force)
|
|
3697
|
+
return new _CheckoutTarget(dir, _CheckoutTarget.tracked(state2));
|
|
3698
|
+
throw new CheckoutRefusedError(refusal);
|
|
3699
|
+
}
|
|
3700
|
+
/** Base files plus local edits — everything the archive would see in the old
|
|
3701
|
+
* checkout. `.env-metadata.json` is local input: a key that would leave the
|
|
3702
|
+
* checkout (`../x`, `/etc/x`) is dropped, never removed. */
|
|
3703
|
+
static tracked(state2) {
|
|
3704
|
+
if (!state2.meta?.baseFiles) return [];
|
|
3705
|
+
return [
|
|
3706
|
+
.../* @__PURE__ */ new Set([...Object.keys(state2.meta.baseFiles), ...state2.dirty])
|
|
3707
|
+
].filter(_CheckoutTarget.confinedRel).sort();
|
|
3708
|
+
}
|
|
3709
|
+
static confinedRel(rel) {
|
|
3710
|
+
if (rel === "" || path2.isAbsolute(rel)) return false;
|
|
3711
|
+
return !rel.split(/[\\/]/).includes("..");
|
|
3712
|
+
}
|
|
3713
|
+
/** Why `dir` cannot be overwritten, or null when it is a clean checkout of `slug`. */
|
|
3714
|
+
static refusal(dir, slug, state2) {
|
|
3715
|
+
if (!state2.meta?.baseFiles)
|
|
3716
|
+
return `${dir} is not empty and is not a checkout of "${slug}" \u2014 pick an empty --target, or pass --force to overwrite it`;
|
|
3717
|
+
if (state2.meta.slug !== void 0 && state2.meta.slug !== slug)
|
|
3718
|
+
return `${dir} tracks "${state2.meta.slug}", not "${slug}" \u2014 pick another --target, or pass --force to replace it`;
|
|
3719
|
+
if (state2.clean) return null;
|
|
3720
|
+
const n = state2.dirty.length;
|
|
3721
|
+
const named = state2.dirty.slice(0, NAMED_EDITS).join(", ");
|
|
3722
|
+
const more = n > NAMED_EDITS ? `, +${n - NAMED_EDITS} more` : "";
|
|
3723
|
+
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`;
|
|
3724
|
+
}
|
|
3725
|
+
/** Remove the replaced checkout's files (and the dirs they leave empty). */
|
|
3726
|
+
clear() {
|
|
3727
|
+
for (const rel of this.replaces) {
|
|
3728
|
+
const abs = path2.join(this.dir, rel);
|
|
3729
|
+
fs2.rmSync(abs, { force: true });
|
|
3730
|
+
this.pruneEmptyParents(path2.dirname(abs));
|
|
3731
|
+
}
|
|
3732
|
+
}
|
|
3733
|
+
pruneEmptyParents(from) {
|
|
3734
|
+
let cur = from;
|
|
3735
|
+
while (cur !== this.dir && cur.startsWith(this.dir)) {
|
|
3736
|
+
if (fs2.existsSync(cur) && fs2.readdirSync(cur).length > 0) return;
|
|
3737
|
+
fs2.rmSync(cur, { recursive: true, force: true });
|
|
3738
|
+
cur = path2.dirname(cur);
|
|
3739
|
+
}
|
|
3740
|
+
}
|
|
3741
|
+
};
|
|
3742
|
+
}
|
|
3743
|
+
});
|
|
3744
|
+
|
|
3745
|
+
// src/worlds/worldDir.ts
|
|
3746
|
+
import { createHash as createHash2 } from "crypto";
|
|
3747
|
+
import * as fs3 from "fs";
|
|
3748
|
+
import * as path3 from "path";
|
|
3749
|
+
var WORLD_MANIFEST, API_BUNDLE_MANIFEST, BUNDLED_WORLD_PREFIX, CONNECTOR_SPEC, PYPROJECT, BENCHMARK_CONFIG, WORLD_SCHEMA_MARKERS, WORLD_ROOT_MARKERS, BROAD_ROOT_MARKERS, SKIPPED_DIRS, V1_DEP, V1_IMPORT, V1_TASKSET, HARBOR_TASK, skippedDir, byCodePoint, WorldDir;
|
|
2925
3750
|
var init_worldDir = __esm({
|
|
2926
3751
|
"src/worlds/worldDir.ts"() {
|
|
2927
3752
|
"use strict";
|
|
@@ -2930,10 +3755,11 @@ var init_worldDir = __esm({
|
|
|
2930
3755
|
BUNDLED_WORLD_PREFIX = "server/world/";
|
|
2931
3756
|
CONNECTOR_SPEC = "connector.toml";
|
|
2932
3757
|
PYPROJECT = "pyproject.toml";
|
|
3758
|
+
BENCHMARK_CONFIG = "benchmark.json";
|
|
2933
3759
|
WORLD_SCHEMA_MARKERS = ["schema/world.json", "schema/runtime.json", "schema/lock.json"];
|
|
2934
3760
|
WORLD_ROOT_MARKERS = [CONNECTOR_SPEC, ...WORLD_SCHEMA_MARKERS];
|
|
2935
|
-
BROAD_ROOT_MARKERS = [WORLD_MANIFEST, API_BUNDLE_MANIFEST];
|
|
2936
|
-
SKIPPED_DIRS = /* @__PURE__ */ new Set(["dist", "build", "outputs", "__pycache__"]);
|
|
3761
|
+
BROAD_ROOT_MARKERS = [WORLD_MANIFEST, API_BUNDLE_MANIFEST, BENCHMARK_CONFIG];
|
|
3762
|
+
SKIPPED_DIRS = /* @__PURE__ */ new Set(["dist", "build", "outputs", "__pycache__", "node_modules"]);
|
|
2937
3763
|
V1_DEP = /["']verifiers\s*(?:\[[^\]]*\])?\s*(?:>=|~=|==|>)\s*(?:0\.(?:[2-9]\d*|[1-9]\d+)|[1-9]\d*)/;
|
|
2938
3764
|
V1_IMPORT = /^\s*(?:from\s+verifiers\.v1\s+import\b|from\s+verifiers\s+import\s+v1\b|import\s+verifiers\.v1\b)/m;
|
|
2939
3765
|
V1_TASKSET = /class\s+\w+\s*\(\s*(?:(?:vf|v1|verifiers(?:\.v1)?)\.)?Taskset\s*[,)]/;
|
|
@@ -2945,19 +3771,21 @@ var init_worldDir = __esm({
|
|
|
2945
3771
|
this.dir = dir;
|
|
2946
3772
|
this.worldRoot = worldRoot;
|
|
2947
3773
|
}
|
|
3774
|
+
dir;
|
|
3775
|
+
worldRoot;
|
|
2948
3776
|
pathsMemo;
|
|
2949
3777
|
static open(dir) {
|
|
2950
|
-
const present = (rel) =>
|
|
3778
|
+
const present = (rel) => fs3.existsSync(path3.join(dir, rel));
|
|
2951
3779
|
const bundled = present(API_BUNDLE_MANIFEST) && WORLD_ROOT_MARKERS.some((m) => present(BUNDLED_WORLD_PREFIX + m));
|
|
2952
3780
|
return new _WorldDir(dir, bundled ? BUNDLED_WORLD_PREFIX : "");
|
|
2953
3781
|
}
|
|
2954
3782
|
// ── Files ──────────────────────────────────────────────────────────────
|
|
2955
3783
|
has(rel) {
|
|
2956
|
-
return
|
|
3784
|
+
return fs3.existsSync(path3.join(this.dir, rel));
|
|
2957
3785
|
}
|
|
2958
3786
|
text(rel) {
|
|
2959
3787
|
try {
|
|
2960
|
-
return
|
|
3788
|
+
return fs3.readFileSync(path3.join(this.dir, rel), "utf-8");
|
|
2961
3789
|
} catch {
|
|
2962
3790
|
return null;
|
|
2963
3791
|
}
|
|
@@ -2967,20 +3795,21 @@ var init_worldDir = __esm({
|
|
|
2967
3795
|
return this.worldRoot + rel;
|
|
2968
3796
|
}
|
|
2969
3797
|
/** Every regular file the archive rules keep (`_archive.py`: no hidden,
|
|
2970
|
-
* dist, build, outputs, pycache or egg-info directories), as
|
|
2971
|
-
* relpaths. Root files enter only when a Gateway manifest
|
|
2972
|
-
* or they are README.md, pyproject.toml or
|
|
3798
|
+
* dist, build, outputs, pycache, node_modules or egg-info directories), as
|
|
3799
|
+
* sorted relpaths. Root files enter only when a Gateway manifest or
|
|
3800
|
+
* benchmark.json widens the root, or they are README.md, pyproject.toml or
|
|
3801
|
+
* Python. */
|
|
2973
3802
|
get archivePaths() {
|
|
2974
3803
|
if (this.pathsMemo) return this.pathsMemo;
|
|
2975
3804
|
const broad = BROAD_ROOT_MARKERS.some((m) => this.has(m));
|
|
2976
3805
|
const out = [];
|
|
2977
3806
|
const walk = (rel) => {
|
|
2978
|
-
for (const entry of
|
|
3807
|
+
for (const entry of fs3.readdirSync(rel ? path3.join(this.dir, rel) : this.dir, { withFileTypes: true })) {
|
|
2979
3808
|
const child = rel ? `${rel}/${entry.name}` : entry.name;
|
|
2980
3809
|
if (entry.isDirectory()) {
|
|
2981
3810
|
if (!skippedDir(entry.name)) walk(child);
|
|
2982
3811
|
} else if (entry.isFile() && !entry.name.startsWith(".")) {
|
|
2983
|
-
const rootKept = broad || ["README.md", PYPROJECT].includes(entry.name) || entry.name.endsWith(".py");
|
|
3812
|
+
const rootKept = broad || ["README.md", PYPROJECT, ...BROAD_ROOT_MARKERS].includes(entry.name) || entry.name.endsWith(".py");
|
|
2984
3813
|
if (rel || rootKept) out.push(child);
|
|
2985
3814
|
}
|
|
2986
3815
|
}
|
|
@@ -2988,6 +3817,33 @@ var init_worldDir = __esm({
|
|
|
2988
3817
|
walk("");
|
|
2989
3818
|
return this.pathsMemo = out.sort(byCodePoint);
|
|
2990
3819
|
}
|
|
3820
|
+
/** What the archive rules leave out, collapsed to the entry that decided
|
|
3821
|
+
* it: a pruned directory counts its files once, a dropped root file is
|
|
3822
|
+
* named. Dot entries (`.git/`, `.gateway/`, `.gitignore`) are the one
|
|
3823
|
+
* universal convention and stay unreported. `push` prints the rest so
|
|
3824
|
+
* nothing disappears silently. */
|
|
3825
|
+
get exclusions() {
|
|
3826
|
+
const kept = new Set(this.archivePaths);
|
|
3827
|
+
const out = [];
|
|
3828
|
+
const filesUnder = (rel) => fs3.readdirSync(path3.join(this.dir, rel), { withFileTypes: true }).flatMap((entry) => {
|
|
3829
|
+
const child = `${rel}/${entry.name}`;
|
|
3830
|
+
if (entry.isDirectory()) return filesUnder(child);
|
|
3831
|
+
return entry.isFile() ? [child] : [];
|
|
3832
|
+
});
|
|
3833
|
+
for (const entry of fs3.readdirSync(this.dir, { withFileTypes: true }).sort((a, b) => byCodePoint(a.name, b.name))) {
|
|
3834
|
+
if (entry.name.startsWith(".")) continue;
|
|
3835
|
+
if (entry.isDirectory()) {
|
|
3836
|
+
const all = filesUnder(entry.name);
|
|
3837
|
+
const missing = all.filter((rel) => !kept.has(rel));
|
|
3838
|
+
if (missing.length === 0) continue;
|
|
3839
|
+
const whole = missing.length === all.length;
|
|
3840
|
+
out.push(...whole ? [{ path: `${entry.name}/`, files: missing.length }] : missing.map((p) => ({ path: p, files: 1 })));
|
|
3841
|
+
continue;
|
|
3842
|
+
}
|
|
3843
|
+
if (!kept.has(entry.name)) out.push({ path: entry.name, files: 1 });
|
|
3844
|
+
}
|
|
3845
|
+
return out;
|
|
3846
|
+
}
|
|
2991
3847
|
/** A root `.gitignore` is present: the Python SDK honours it when
|
|
2992
3848
|
* collecting, this package does not reimplement gitignore. */
|
|
2993
3849
|
get hasRootGitignore() {
|
|
@@ -3000,7 +3856,7 @@ var init_worldDir = __esm({
|
|
|
3000
3856
|
const hasher = createHash2("sha256");
|
|
3001
3857
|
for (const rel of this.archivePaths) {
|
|
3002
3858
|
hasher.update(Buffer.from(`file:${rel}`, "utf-8"));
|
|
3003
|
-
hasher.update(
|
|
3859
|
+
hasher.update(fs3.readFileSync(path3.join(this.dir, rel)));
|
|
3004
3860
|
}
|
|
3005
3861
|
return hasher.digest("hex");
|
|
3006
3862
|
}
|
|
@@ -3063,14 +3919,121 @@ var init_worldDir = __esm({
|
|
|
3063
3919
|
}
|
|
3064
3920
|
});
|
|
3065
3921
|
|
|
3922
|
+
// src/worlds/tar.ts
|
|
3923
|
+
import * as fs4 from "fs";
|
|
3924
|
+
import * as path4 from "path";
|
|
3925
|
+
import { gunzipSync } from "zlib";
|
|
3926
|
+
function archiveMode(mode) {
|
|
3927
|
+
return (mode & 73) !== 0 ? TAR_EXEC_MODE : TAR_FILE_MODE;
|
|
3928
|
+
}
|
|
3929
|
+
function field(header, start, end) {
|
|
3930
|
+
return header.subarray(start, end).toString("utf-8").replace(/\0.*$/, "");
|
|
3931
|
+
}
|
|
3932
|
+
function octalField(header, start, end) {
|
|
3933
|
+
return parseInt(field(header, start, end).trim(), 8);
|
|
3934
|
+
}
|
|
3935
|
+
function paxPath(body) {
|
|
3936
|
+
let off = 0;
|
|
3937
|
+
let found = null;
|
|
3938
|
+
while (off < body.length) {
|
|
3939
|
+
const sp = body.indexOf(32, off);
|
|
3940
|
+
if (sp === -1) break;
|
|
3941
|
+
const len = parseInt(body.subarray(off, sp).toString("ascii"), 10);
|
|
3942
|
+
if (!Number.isFinite(len) || len <= 0) break;
|
|
3943
|
+
const record = body.subarray(sp + 1, off + len);
|
|
3944
|
+
const eq = record.indexOf(61);
|
|
3945
|
+
const key = eq === -1 ? "" : record.subarray(0, eq).toString("utf-8");
|
|
3946
|
+
if (key === "path")
|
|
3947
|
+
found = record.subarray(eq + 1).toString("utf-8").replace(/\n$/, "");
|
|
3948
|
+
off += len;
|
|
3949
|
+
}
|
|
3950
|
+
return found;
|
|
3951
|
+
}
|
|
3952
|
+
var TAR_FILE_MODE, TAR_EXEC_MODE, TarArchive;
|
|
3953
|
+
var init_tar = __esm({
|
|
3954
|
+
"src/worlds/tar.ts"() {
|
|
3955
|
+
"use strict";
|
|
3956
|
+
TAR_FILE_MODE = 420;
|
|
3957
|
+
TAR_EXEC_MODE = 493;
|
|
3958
|
+
TarArchive = class _TarArchive {
|
|
3959
|
+
constructor(tar) {
|
|
3960
|
+
this.tar = tar;
|
|
3961
|
+
}
|
|
3962
|
+
tar;
|
|
3963
|
+
static fromGzip(bundle) {
|
|
3964
|
+
return new _TarArchive(gunzipSync(bundle));
|
|
3965
|
+
}
|
|
3966
|
+
static fromTar(tar) {
|
|
3967
|
+
return new _TarArchive(tar);
|
|
3968
|
+
}
|
|
3969
|
+
/** Every member, names fully resolved; metadata members are consumed. */
|
|
3970
|
+
*members() {
|
|
3971
|
+
const tar = this.tar;
|
|
3972
|
+
let offset = 0;
|
|
3973
|
+
let pendingName = null;
|
|
3974
|
+
while (offset + 512 <= tar.length) {
|
|
3975
|
+
const header = tar.subarray(offset, offset + 512);
|
|
3976
|
+
offset += 512;
|
|
3977
|
+
if (header.every((b) => b === 0)) break;
|
|
3978
|
+
const size = octalField(header, 124, 136) || 0;
|
|
3979
|
+
const mode = octalField(header, 100, 108) || TAR_FILE_MODE;
|
|
3980
|
+
const typeflag = String.fromCharCode(header[156] ?? 0);
|
|
3981
|
+
const bytes = tar.subarray(offset, offset + size);
|
|
3982
|
+
offset += Math.ceil(size / 512) * 512;
|
|
3983
|
+
if (typeflag === "L") {
|
|
3984
|
+
pendingName = bytes.toString("utf-8").replace(/\0.*$/, "");
|
|
3985
|
+
continue;
|
|
3986
|
+
}
|
|
3987
|
+
if (typeflag === "x") {
|
|
3988
|
+
pendingName = paxPath(bytes) ?? pendingName;
|
|
3989
|
+
continue;
|
|
3990
|
+
}
|
|
3991
|
+
if (typeflag === "K" || typeflag === "g") continue;
|
|
3992
|
+
const name = pendingName ?? _TarArchive.ustarName(header);
|
|
3993
|
+
pendingName = null;
|
|
3994
|
+
yield { name: name.replace(/^\.\//, ""), bytes, typeflag, mode };
|
|
3995
|
+
}
|
|
3996
|
+
}
|
|
3997
|
+
static ustarName(header) {
|
|
3998
|
+
const name = field(header, 0, 100);
|
|
3999
|
+
const magic = header.subarray(257, 262).toString("ascii");
|
|
4000
|
+
const prefix = magic === "ustar" ? field(header, 345, 500) : "";
|
|
4001
|
+
return prefix ? `${prefix}/${name}` : name;
|
|
4002
|
+
}
|
|
4003
|
+
/** Regular files only, confined to `dir` (absolute or `..` names are
|
|
4004
|
+
* skipped, never written). Returns the number of files written. */
|
|
4005
|
+
extractTo(dir) {
|
|
4006
|
+
let written = 0;
|
|
4007
|
+
for (const member of this.members()) {
|
|
4008
|
+
if (member.typeflag !== "0" && member.typeflag !== "\0") continue;
|
|
4009
|
+
if (!_TarArchive.isConfined(member.name)) continue;
|
|
4010
|
+
const target = path4.join(dir, member.name);
|
|
4011
|
+
fs4.mkdirSync(path4.dirname(target), { recursive: true });
|
|
4012
|
+
const mode = archiveMode(member.mode);
|
|
4013
|
+
fs4.writeFileSync(target, member.bytes, { mode });
|
|
4014
|
+
fs4.chmodSync(target, mode);
|
|
4015
|
+
written++;
|
|
4016
|
+
}
|
|
4017
|
+
return written;
|
|
4018
|
+
}
|
|
4019
|
+
static isConfined(name) {
|
|
4020
|
+
if (name === "" || name.startsWith("/")) return false;
|
|
4021
|
+
return !name.split("/").includes("..");
|
|
4022
|
+
}
|
|
4023
|
+
};
|
|
4024
|
+
}
|
|
4025
|
+
});
|
|
4026
|
+
|
|
3066
4027
|
// src/worlds/hub.ts
|
|
3067
4028
|
var hub_exports = {};
|
|
3068
4029
|
__export(hub_exports, {
|
|
3069
4030
|
DEFAULT_BRANCH: () => DEFAULT_BRANCH,
|
|
4031
|
+
DetachedPushError: () => DetachedPushError,
|
|
3070
4032
|
PushSlugConflict: () => PushSlugConflict,
|
|
3071
4033
|
archiveMode: () => archiveMode,
|
|
3072
4034
|
buildFileManifest: () => buildFileManifest,
|
|
3073
4035
|
buildSourceTarball: () => buildSourceTarball,
|
|
4036
|
+
checkoutIdentity: () => checkoutIdentity,
|
|
3074
4037
|
collectArchiveRelPaths: () => collectArchiveRelPaths,
|
|
3075
4038
|
computeContentHash: () => computeContentHash,
|
|
3076
4039
|
createRef: () => createRef,
|
|
@@ -3079,6 +4042,7 @@ __export(hub_exports, {
|
|
|
3079
4042
|
propose: () => propose,
|
|
3080
4043
|
pull: () => pull,
|
|
3081
4044
|
push: () => push,
|
|
4045
|
+
pushBranch: () => pushBranch,
|
|
3082
4046
|
pushSlug: () => pushSlug,
|
|
3083
4047
|
readLocalMeta: () => readLocalMeta,
|
|
3084
4048
|
resolvePushSlug: () => resolvePushSlug,
|
|
@@ -3086,9 +4050,9 @@ __export(hub_exports, {
|
|
|
3086
4050
|
writeLocalMeta: () => writeLocalMeta
|
|
3087
4051
|
});
|
|
3088
4052
|
import { createHash as createHash3 } from "crypto";
|
|
3089
|
-
import { gzipSync
|
|
3090
|
-
import * as
|
|
3091
|
-
import * as
|
|
4053
|
+
import { gzipSync } from "zlib";
|
|
4054
|
+
import * as fs5 from "fs";
|
|
4055
|
+
import * as path5 from "path";
|
|
3092
4056
|
function collectArchiveRelPaths(dir) {
|
|
3093
4057
|
const world = WorldDir.open(dir);
|
|
3094
4058
|
if (world.hasRootGitignore) {
|
|
@@ -3108,9 +4072,6 @@ function octal(value, length) {
|
|
|
3108
4072
|
"ascii"
|
|
3109
4073
|
);
|
|
3110
4074
|
}
|
|
3111
|
-
function archiveMode(mode) {
|
|
3112
|
-
return (mode & 73) !== 0 ? EXEC_MODE : FILE_MODE;
|
|
3113
|
-
}
|
|
3114
4075
|
function tarHeader(name, size, mode = FILE_MODE) {
|
|
3115
4076
|
const header = Buffer.alloc(512);
|
|
3116
4077
|
header.write(name, 0, 100, "utf-8");
|
|
@@ -3154,12 +4115,12 @@ function tarMember(name, payload, mode) {
|
|
|
3154
4115
|
function buildSourceTarball(dir) {
|
|
3155
4116
|
const parts = [];
|
|
3156
4117
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
3157
|
-
const abs =
|
|
4118
|
+
const abs = path5.join(dir, relPath);
|
|
3158
4119
|
parts.push(
|
|
3159
4120
|
...tarMember(
|
|
3160
4121
|
relPath,
|
|
3161
|
-
|
|
3162
|
-
archiveMode(
|
|
4122
|
+
fs5.readFileSync(abs),
|
|
4123
|
+
archiveMode(fs5.statSync(abs).mode)
|
|
3163
4124
|
)
|
|
3164
4125
|
);
|
|
3165
4126
|
}
|
|
@@ -3168,7 +4129,7 @@ function buildSourceTarball(dir) {
|
|
|
3168
4129
|
}
|
|
3169
4130
|
function readLocalMeta(dir) {
|
|
3170
4131
|
try {
|
|
3171
|
-
const raw =
|
|
4132
|
+
const raw = fs5.readFileSync(path5.join(dir, META_RELPATH), "utf-8");
|
|
3172
4133
|
const parsed = JSON.parse(raw);
|
|
3173
4134
|
return parsed && typeof parsed === "object" ? parsed : null;
|
|
3174
4135
|
} catch {
|
|
@@ -3191,16 +4152,16 @@ function resolvePushSlug(dir, opts = {}) {
|
|
|
3191
4152
|
}
|
|
3192
4153
|
const first = declared[0];
|
|
3193
4154
|
if (first) return { ...base, slug: first.slug, source: first.source };
|
|
3194
|
-
return { ...base, slug:
|
|
4155
|
+
return { ...base, slug: path5.basename(path5.resolve(dir)), source: "directory name" };
|
|
3195
4156
|
}
|
|
3196
4157
|
function writeLocalMeta(dir, meta) {
|
|
3197
|
-
|
|
3198
|
-
|
|
4158
|
+
fs5.mkdirSync(path5.join(dir, ".gateway"), { recursive: true });
|
|
4159
|
+
fs5.writeFileSync(path5.join(dir, META_RELPATH), JSON.stringify(meta, null, 2));
|
|
3199
4160
|
}
|
|
3200
4161
|
function snapshotTreeHashes(dir) {
|
|
3201
4162
|
const out = {};
|
|
3202
4163
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
3203
|
-
out[relPath] = createHash3("sha256").update(
|
|
4164
|
+
out[relPath] = createHash3("sha256").update(fs5.readFileSync(path5.join(dir, relPath))).digest("hex");
|
|
3204
4165
|
}
|
|
3205
4166
|
return out;
|
|
3206
4167
|
}
|
|
@@ -3218,7 +4179,7 @@ function localTreeState(dir) {
|
|
|
3218
4179
|
}
|
|
3219
4180
|
function readPyproject(dir) {
|
|
3220
4181
|
try {
|
|
3221
|
-
const text2 =
|
|
4182
|
+
const text2 = fs5.readFileSync(path5.join(dir, "pyproject.toml"), "utf-8");
|
|
3222
4183
|
const section = /\[project\]([\s\S]*?)(\n\[|$)/.exec(text2)?.[1] ?? "";
|
|
3223
4184
|
const name = /\bname\s*=\s*"([^"]+)"/.exec(section)?.[1];
|
|
3224
4185
|
const version = /\bversion\s*=\s*"([^"]+)"/.exec(section)?.[1];
|
|
@@ -3241,7 +4202,7 @@ function readWorldContractVersion(dir) {
|
|
|
3241
4202
|
}
|
|
3242
4203
|
function buildFileManifest(dir) {
|
|
3243
4204
|
return collectArchiveRelPaths(dir).map((relPath) => {
|
|
3244
|
-
const payload =
|
|
4205
|
+
const payload = fs5.readFileSync(path5.join(dir, relPath));
|
|
3245
4206
|
return {
|
|
3246
4207
|
path: relPath,
|
|
3247
4208
|
isDirectory: false,
|
|
@@ -3265,30 +4226,36 @@ async function putObject(url, data, shaB64) {
|
|
|
3265
4226
|
);
|
|
3266
4227
|
}
|
|
3267
4228
|
}
|
|
4229
|
+
function pushBranch(dir, localMeta, explicit) {
|
|
4230
|
+
if (explicit) return explicit;
|
|
4231
|
+
if (typeof localMeta.tag === "string" && localMeta.tag) throw new DetachedPushError(dir, localMeta.tag);
|
|
4232
|
+
return localMeta.branch ?? DEFAULT_BRANCH;
|
|
4233
|
+
}
|
|
3268
4234
|
async function push(dir, opts = {}) {
|
|
3269
4235
|
const options = opts.options ?? {};
|
|
3270
|
-
if (!
|
|
4236
|
+
if (!fs5.statSync(dir).isDirectory())
|
|
3271
4237
|
throw new Error(`Not a directory: ${dir}`);
|
|
3272
4238
|
const localMeta = readLocalMeta(dir) ?? {};
|
|
3273
|
-
const branch =
|
|
4239
|
+
const branch = pushBranch(dir, localMeta, opts.branch);
|
|
3274
4240
|
const baseVersionId = opts.baseVersionId ?? localMeta.versionId ?? null;
|
|
4241
|
+
const world = WorldDir.open(dir);
|
|
3275
4242
|
const fileManifest = buildFileManifest(dir);
|
|
3276
4243
|
if (fileManifest.length === 0)
|
|
3277
4244
|
throw new Error(
|
|
3278
4245
|
`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).`
|
|
3279
4246
|
);
|
|
3280
|
-
const contentHash =
|
|
4247
|
+
const contentHash = world.contentHash;
|
|
3281
4248
|
const pyproject = readPyproject(dir);
|
|
3282
4249
|
const contractVersion = pyproject.version ? void 0 : readWorldContractVersion(dir).version;
|
|
3283
4250
|
if (contractVersion) pyproject.version = contractVersion;
|
|
3284
|
-
const slug = opts.slug ?? localMeta.slug ?? pyproject.name ??
|
|
4251
|
+
const slug = opts.slug ?? localMeta.slug ?? pyproject.name ?? path5.basename(path5.resolve(dir));
|
|
3285
4252
|
const metadata = {
|
|
3286
4253
|
...opts.name !== void 0 ? { name: opts.name } : {},
|
|
3287
4254
|
...opts.description !== void 0 ? { description: opts.description } : {},
|
|
3288
4255
|
...opts.tags !== void 0 ? { tags: opts.tags } : {},
|
|
3289
4256
|
...opts.visibility ? { visibility: opts.visibility } : {}
|
|
3290
4257
|
};
|
|
3291
|
-
const
|
|
4258
|
+
const resolve7 = await apiRequest(
|
|
3292
4259
|
options,
|
|
3293
4260
|
"POST",
|
|
3294
4261
|
"/api/public/benchmark-containers/resolve",
|
|
@@ -3297,7 +4264,7 @@ async function push(dir, opts = {}) {
|
|
|
3297
4264
|
const tarball = buildSourceTarball(dir);
|
|
3298
4265
|
const bundleSha256 = sha256b64(tarball);
|
|
3299
4266
|
const version = await apiRequest(options, "POST", "/api/public/benchmark-containers/versions", {
|
|
3300
|
-
containerId:
|
|
4267
|
+
containerId: resolve7.containerId,
|
|
3301
4268
|
contentHash,
|
|
3302
4269
|
bundleSha256,
|
|
3303
4270
|
bundleSizeBytes: tarball.length,
|
|
@@ -3336,56 +4303,36 @@ async function push(dir, opts = {}) {
|
|
|
3336
4303
|
baseFiles: snapshotTreeHashes(dir)
|
|
3337
4304
|
});
|
|
3338
4305
|
return {
|
|
3339
|
-
containerId:
|
|
4306
|
+
containerId: resolve7.containerId,
|
|
3340
4307
|
slug,
|
|
3341
4308
|
versionId: version.versionId,
|
|
3342
4309
|
contentHash,
|
|
3343
4310
|
branch: final.branch ?? branch,
|
|
3344
4311
|
state: final.state ?? null,
|
|
3345
|
-
alreadyUploaded: Boolean(version.alreadyUploaded)
|
|
4312
|
+
alreadyUploaded: Boolean(version.alreadyUploaded),
|
|
4313
|
+
editSessionId: final.editSessionId ?? null,
|
|
4314
|
+
filesKept: fileManifest.length,
|
|
4315
|
+
excluded: world.exclusions
|
|
3346
4316
|
};
|
|
3347
4317
|
}
|
|
3348
4318
|
function extractBundle(bundle, dir) {
|
|
3349
|
-
|
|
3350
|
-
let offset = 0;
|
|
3351
|
-
let longName = null;
|
|
3352
|
-
let written = 0;
|
|
3353
|
-
while (offset + 512 <= tar.length) {
|
|
3354
|
-
const header = tar.subarray(offset, offset + 512);
|
|
3355
|
-
offset += 512;
|
|
3356
|
-
if (header.every((b) => b === 0)) break;
|
|
3357
|
-
const rawName = header.subarray(0, 100).toString("utf-8").replace(/\0.*$/, "");
|
|
3358
|
-
const size = parseInt(
|
|
3359
|
-
header.subarray(124, 136).toString("ascii").replace(/\0.*$/, "").trim(),
|
|
3360
|
-
8
|
|
3361
|
-
) || 0;
|
|
3362
|
-
const mode = parseInt(
|
|
3363
|
-
header.subarray(100, 108).toString("ascii").replace(/\0.*$/, "").trim(),
|
|
3364
|
-
8
|
|
3365
|
-
) || FILE_MODE;
|
|
3366
|
-
const typeflag = header.subarray(156, 157).toString("ascii");
|
|
3367
|
-
const body = tar.subarray(offset, offset + size);
|
|
3368
|
-
offset += size + (size % 512 === 0 ? 0 : 512 - size % 512);
|
|
3369
|
-
if (typeflag === "L") {
|
|
3370
|
-
longName = body.toString("utf-8").replace(/\0.*$/, "");
|
|
3371
|
-
continue;
|
|
3372
|
-
}
|
|
3373
|
-
const name = (longName ?? rawName).replace(/^\.\//, "");
|
|
3374
|
-
longName = null;
|
|
3375
|
-
if (typeflag !== "0" && typeflag !== "") continue;
|
|
3376
|
-
if (name.startsWith("/") || name.split("/").includes("..")) continue;
|
|
3377
|
-
const target = path3.join(dir, name);
|
|
3378
|
-
fs3.mkdirSync(path3.dirname(target), { recursive: true });
|
|
3379
|
-
fs3.writeFileSync(target, body, { mode: archiveMode(mode) });
|
|
3380
|
-
fs3.chmodSync(target, archiveMode(mode));
|
|
3381
|
-
written++;
|
|
3382
|
-
}
|
|
3383
|
-
return written;
|
|
4319
|
+
return TarArchive.fromGzip(bundle).extractTo(dir);
|
|
3384
4320
|
}
|
|
3385
|
-
|
|
4321
|
+
function checkoutIdentity(ref, resolved) {
|
|
4322
|
+
if (resolved.tag) return { tag: resolved.tag };
|
|
4323
|
+
if (resolved.branch) return { branch: resolved.branch };
|
|
4324
|
+
const pinned = ref === "latest" || /^\d|^[0-9a-f]{8,}$/.test(ref);
|
|
4325
|
+
return { branch: pinned ? DEFAULT_BRANCH : ref };
|
|
4326
|
+
}
|
|
4327
|
+
async function pull(slugRef, target, options = {}, opts = {}) {
|
|
3386
4328
|
const at = slugRef.indexOf("@");
|
|
3387
4329
|
const slug = at === -1 ? slugRef : slugRef.slice(0, at);
|
|
3388
4330
|
const ref = at === -1 ? "latest" : slugRef.slice(at + 1);
|
|
4331
|
+
const landing = CheckoutTarget.resolve(slug, target, {
|
|
4332
|
+
cwd: process.cwd(),
|
|
4333
|
+
force: opts.force ?? false,
|
|
4334
|
+
state: localTreeState
|
|
4335
|
+
});
|
|
3389
4336
|
const details = await apiRequest(options, "POST", "/api/public/benchmark-containers/resolve-version", {
|
|
3390
4337
|
slug,
|
|
3391
4338
|
ref
|
|
@@ -3393,13 +4340,6 @@ async function pull(slugRef, target, options = {}) {
|
|
|
3393
4340
|
if (!details.downloadUrl) {
|
|
3394
4341
|
throw new Error(`${slug}@${ref} resolved but has no uploaded bundle`);
|
|
3395
4342
|
}
|
|
3396
|
-
let dir = target ?? path3.join(process.cwd(), slug);
|
|
3397
|
-
if (!target) {
|
|
3398
|
-
let i = 1;
|
|
3399
|
-
const base = dir;
|
|
3400
|
-
while (fs3.existsSync(dir)) dir = `${base}-${i++}`;
|
|
3401
|
-
}
|
|
3402
|
-
fs3.mkdirSync(dir, { recursive: true });
|
|
3403
4343
|
const resp = await fetch(details.downloadUrl);
|
|
3404
4344
|
if (!resp.ok) throw new Error(`bundle download -> ${resp.status}`);
|
|
3405
4345
|
const bundle = Buffer.from(await resp.arrayBuffer());
|
|
@@ -3408,12 +4348,14 @@ async function pull(slugRef, target, options = {}) {
|
|
|
3408
4348
|
`bundle integrity check failed for ${slug}@${ref}: downloaded sha256 != recorded bundleSha256`
|
|
3409
4349
|
);
|
|
3410
4350
|
}
|
|
4351
|
+
const dir = landing.dir;
|
|
4352
|
+
fs5.mkdirSync(dir, { recursive: true });
|
|
4353
|
+
landing.clear();
|
|
3411
4354
|
const files = extractBundle(bundle, dir);
|
|
3412
|
-
const branch = ref === "latest" || /^\d|^[0-9a-f]{8,}$/.test(ref) ? DEFAULT_BRANCH : ref;
|
|
3413
4355
|
writeLocalMeta(dir, {
|
|
3414
4356
|
slug,
|
|
3415
4357
|
ref,
|
|
3416
|
-
|
|
4358
|
+
...checkoutIdentity(ref, details),
|
|
3417
4359
|
versionId: details.versionId,
|
|
3418
4360
|
contentHash: details.contentHash,
|
|
3419
4361
|
semanticVersion: details.semanticVersion ?? void 0,
|
|
@@ -3432,13 +4374,13 @@ async function propose(dir, opts) {
|
|
|
3432
4374
|
if (state2.clean)
|
|
3433
4375
|
throw new Error("Nothing to propose \u2014 the tree matches its base.");
|
|
3434
4376
|
const changes = state2.dirty.map((relPath) => {
|
|
3435
|
-
const abs =
|
|
3436
|
-
if (!
|
|
4377
|
+
const abs = path5.join(dir, relPath);
|
|
4378
|
+
if (!fs5.existsSync(abs))
|
|
3437
4379
|
return { path: relPath, action: "delete" };
|
|
3438
4380
|
return {
|
|
3439
4381
|
path: relPath,
|
|
3440
4382
|
action: "write",
|
|
3441
|
-
newContent:
|
|
4383
|
+
newContent: fs5.readFileSync(abs, "utf-8")
|
|
3442
4384
|
};
|
|
3443
4385
|
});
|
|
3444
4386
|
const res = await apiRequest(
|
|
@@ -3464,16 +4406,17 @@ async function createRef(slug, name, kind, versionId, options = {}) {
|
|
|
3464
4406
|
...versionId ? { versionId } : {}
|
|
3465
4407
|
});
|
|
3466
4408
|
}
|
|
3467
|
-
var DEFAULT_BRANCH, META_RELPATH, FILE_MODE,
|
|
4409
|
+
var DEFAULT_BRANCH, META_RELPATH, FILE_MODE, MINTED_SUFFIX, PushSlugConflict, sha256b64, DetachedPushError;
|
|
3468
4410
|
var init_hub = __esm({
|
|
3469
4411
|
"src/worlds/hub.ts"() {
|
|
3470
4412
|
"use strict";
|
|
3471
4413
|
init_worlds();
|
|
4414
|
+
init_checkoutTarget();
|
|
3472
4415
|
init_worldDir();
|
|
4416
|
+
init_tar();
|
|
3473
4417
|
DEFAULT_BRANCH = "main";
|
|
3474
|
-
META_RELPATH =
|
|
3475
|
-
FILE_MODE =
|
|
3476
|
-
EXEC_MODE = 493;
|
|
4418
|
+
META_RELPATH = path5.join(".gateway", ".env-metadata.json");
|
|
4419
|
+
FILE_MODE = TAR_FILE_MODE;
|
|
3477
4420
|
MINTED_SUFFIX = /^-\d+$/;
|
|
3478
4421
|
PushSlugConflict = class extends Error {
|
|
3479
4422
|
constructor(dir, tracked, declared) {
|
|
@@ -3485,8 +4428,19 @@ var init_hub = __esm({
|
|
|
3485
4428
|
this.declared = declared;
|
|
3486
4429
|
this.name = "PushSlugConflict";
|
|
3487
4430
|
}
|
|
4431
|
+
dir;
|
|
4432
|
+
tracked;
|
|
4433
|
+
declared;
|
|
3488
4434
|
};
|
|
3489
4435
|
sha256b64 = (data) => createHash3("sha256").update(data).digest("base64");
|
|
4436
|
+
DetachedPushError = class extends Error {
|
|
4437
|
+
constructor(dir, tag) {
|
|
4438
|
+
super(
|
|
4439
|
+
`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.`
|
|
4440
|
+
);
|
|
4441
|
+
this.name = "DetachedPushError";
|
|
4442
|
+
}
|
|
4443
|
+
};
|
|
3490
4444
|
}
|
|
3491
4445
|
});
|
|
3492
4446
|
|
|
@@ -3673,22 +4627,140 @@ var init_validate = __esm({
|
|
|
3673
4627
|
}
|
|
3674
4628
|
});
|
|
3675
4629
|
|
|
4630
|
+
// src/worlds/sandbox.ts
|
|
4631
|
+
function parseSlugRef(slugRef) {
|
|
4632
|
+
const at = slugRef.indexOf("@");
|
|
4633
|
+
if (at === -1) return { slug: slugRef };
|
|
4634
|
+
return { slug: slugRef.slice(0, at), ref: slugRef.slice(at + 1) };
|
|
4635
|
+
}
|
|
4636
|
+
function rebaseConflicts(error) {
|
|
4637
|
+
if (!(error instanceof ApiError) || error.status !== 409) return null;
|
|
4638
|
+
let body;
|
|
4639
|
+
try {
|
|
4640
|
+
body = JSON.parse(error.text);
|
|
4641
|
+
} catch {
|
|
4642
|
+
return null;
|
|
4643
|
+
}
|
|
4644
|
+
const conflicts = body?.conflicts;
|
|
4645
|
+
if (!Array.isArray(conflicts)) return null;
|
|
4646
|
+
return conflicts.filter(isConflictPath).map(({ path: path12, reason }) => ({ path: path12, reason }));
|
|
4647
|
+
}
|
|
4648
|
+
function isConflictPath(value) {
|
|
4649
|
+
const entry = value;
|
|
4650
|
+
return typeof entry?.path === "string" && typeof entry.reason === "string";
|
|
4651
|
+
}
|
|
4652
|
+
function uncommittedPaths(error) {
|
|
4653
|
+
if (!(error instanceof ApiError) || error.status !== 409 || error.code !== "sandbox_uncommitted") return null;
|
|
4654
|
+
let body;
|
|
4655
|
+
try {
|
|
4656
|
+
body = JSON.parse(error.text);
|
|
4657
|
+
} catch {
|
|
4658
|
+
return null;
|
|
4659
|
+
}
|
|
4660
|
+
const uncommitted = body?.uncommitted;
|
|
4661
|
+
if (!Array.isArray(uncommitted)) return null;
|
|
4662
|
+
return uncommitted.filter((p) => typeof p === "string");
|
|
4663
|
+
}
|
|
4664
|
+
function listQuery(filter) {
|
|
4665
|
+
const params = new URLSearchParams();
|
|
4666
|
+
if (filter.status) params.set("status", filter.status);
|
|
4667
|
+
if (filter.slug) params.set("slug", filter.slug);
|
|
4668
|
+
if (filter.limit !== void 0) params.set("limit", String(filter.limit));
|
|
4669
|
+
const qs = params.toString();
|
|
4670
|
+
return qs ? `?${qs}` : "";
|
|
4671
|
+
}
|
|
4672
|
+
var isSandboxImportPending, sid, SANDBOXES, SANDBOX_REQUEST_TIMEOUT_MS, WorldSandboxClient;
|
|
4673
|
+
var init_sandbox = __esm({
|
|
4674
|
+
"src/worlds/sandbox.ts"() {
|
|
4675
|
+
"use strict";
|
|
4676
|
+
init_worlds();
|
|
4677
|
+
isSandboxImportPending = (answer) => !("versionId" in answer);
|
|
4678
|
+
sid = encodeURIComponent;
|
|
4679
|
+
SANDBOXES = "/api/public/benchmark-containers/sandboxes";
|
|
4680
|
+
SANDBOX_REQUEST_TIMEOUT_MS = 66e4;
|
|
4681
|
+
WorldSandboxClient = class {
|
|
4682
|
+
constructor(options = {}) {
|
|
4683
|
+
this.options = options;
|
|
4684
|
+
}
|
|
4685
|
+
options;
|
|
4686
|
+
request(method, path12, body) {
|
|
4687
|
+
return apiRequest(this.options, method, path12, body, {
|
|
4688
|
+
timeoutMs: SANDBOX_REQUEST_TIMEOUT_MS
|
|
4689
|
+
});
|
|
4690
|
+
}
|
|
4691
|
+
/**
|
|
4692
|
+
* `{ slug, ref? }` opens a READY version; `{ new, from }` opens a sandbox on
|
|
4693
|
+
* a world that does not exist yet (409 `world_exists` if the slug is taken,
|
|
4694
|
+
* 400 naming the shipped templates if `from` is unknown). Its first commit
|
|
4695
|
+
* creates the world on `main`.
|
|
4696
|
+
*/
|
|
4697
|
+
open(target) {
|
|
4698
|
+
return this.request("POST", `${SANDBOXES}`, target);
|
|
4699
|
+
}
|
|
4700
|
+
status(sandboxId) {
|
|
4701
|
+
return this.request("GET", `${SANDBOXES}/${sid(sandboxId)}`);
|
|
4702
|
+
}
|
|
4703
|
+
/** The project's sandboxes, newest first — how an agent finds one it left open. */
|
|
4704
|
+
async list(filter = {}) {
|
|
4705
|
+
const res = await this.request("GET", `${SANDBOXES}${listQuery(filter)}`);
|
|
4706
|
+
return res.sandboxes;
|
|
4707
|
+
}
|
|
4708
|
+
async read(sandboxId, filePath) {
|
|
4709
|
+
const res = await this.request(
|
|
4710
|
+
"GET",
|
|
4711
|
+
`${SANDBOXES}/${sid(sandboxId)}/file?path=${encodeURIComponent(filePath)}`
|
|
4712
|
+
);
|
|
4713
|
+
return { path: res.path, size: res.size, bytes: Buffer.from(res.contentBase64, "base64") };
|
|
4714
|
+
}
|
|
4715
|
+
write(sandboxId, filePath, bytes) {
|
|
4716
|
+
return this.request("PUT", `${SANDBOXES}/${sid(sandboxId)}/file`, {
|
|
4717
|
+
path: filePath,
|
|
4718
|
+
contentBase64: bytes.toString("base64")
|
|
4719
|
+
});
|
|
4720
|
+
}
|
|
4721
|
+
exec(sandboxId, input) {
|
|
4722
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/exec`, input);
|
|
4723
|
+
}
|
|
4724
|
+
check(sandboxId) {
|
|
4725
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/check`, {});
|
|
4726
|
+
}
|
|
4727
|
+
/** With `rebase`, a moved base is replayed onto; a 409 then names the conflicting paths (`rebaseConflicts`). */
|
|
4728
|
+
commit(sandboxId, input) {
|
|
4729
|
+
const { rebase, ...rest } = input;
|
|
4730
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/commit`, rebase ? { ...rest, rebase: true } : rest);
|
|
4731
|
+
}
|
|
4732
|
+
/**
|
|
4733
|
+
* A rows file already in the sandbox tree into the PLATFORM world the
|
|
4734
|
+
* sandbox was opened on (201 with the version, 202 with the batch to poll,
|
|
4735
|
+
* 400 naming a refused row). Not `commit`: a commit versions the source
|
|
4736
|
+
* tree and never carries data.
|
|
4737
|
+
*/
|
|
4738
|
+
importData(sandboxId, input) {
|
|
4739
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/import`, input);
|
|
4740
|
+
}
|
|
4741
|
+
/** Uncommitted work is a 409 (`uncommittedPaths`) unless `force` discards it. */
|
|
4742
|
+
close(sandboxId, opts = {}) {
|
|
4743
|
+
return this.request("DELETE", `${SANDBOXES}/${sid(sandboxId)}`, opts.force ? { force: true } : void 0);
|
|
4744
|
+
}
|
|
4745
|
+
};
|
|
4746
|
+
}
|
|
4747
|
+
});
|
|
4748
|
+
|
|
3676
4749
|
// src/worlds/describe.ts
|
|
3677
|
-
async function describeWorld(
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
`describeWorld reads a world's head version: pass the slug without @ref (got ${slug})`
|
|
3681
|
-
);
|
|
4750
|
+
async function describeWorld(slugRef, options = {}) {
|
|
4751
|
+
const { slug, ref } = parseSlugRef(slugRef);
|
|
4752
|
+
const query = ref === void 0 ? "" : `?ref=${encodeURIComponent(ref)}`;
|
|
3682
4753
|
return apiRequest(
|
|
3683
4754
|
options,
|
|
3684
4755
|
"GET",
|
|
3685
|
-
`/api/public/worlds/${encodeURIComponent(slug)}`
|
|
4756
|
+
`/api/public/worlds/${encodeURIComponent(slug)}${query}`
|
|
3686
4757
|
);
|
|
3687
4758
|
}
|
|
3688
4759
|
var init_describe = __esm({
|
|
3689
4760
|
"src/worlds/describe.ts"() {
|
|
3690
4761
|
"use strict";
|
|
3691
4762
|
init_worlds();
|
|
4763
|
+
init_sandbox();
|
|
3692
4764
|
}
|
|
3693
4765
|
});
|
|
3694
4766
|
|
|
@@ -3793,6 +4865,7 @@ var init_json = __esm({
|
|
|
3793
4865
|
constructor(text2) {
|
|
3794
4866
|
this.text = text2;
|
|
3795
4867
|
}
|
|
4868
|
+
text;
|
|
3796
4869
|
/** A float in Python's eyes: a fraction, an exponent, or a non-finite literal. */
|
|
3797
4870
|
get isFloat() {
|
|
3798
4871
|
return /[.eE]/.test(this.text) || /[nN]/.test(this.text);
|
|
@@ -3807,6 +4880,7 @@ var init_json = __esm({
|
|
|
3807
4880
|
constructor(s) {
|
|
3808
4881
|
this.s = s;
|
|
3809
4882
|
}
|
|
4883
|
+
s;
|
|
3810
4884
|
i = 0;
|
|
3811
4885
|
skipWs() {
|
|
3812
4886
|
const s = this.s;
|
|
@@ -4087,24 +5161,24 @@ function roundForm(plaintext, decimals) {
|
|
|
4087
5161
|
if (typeof plaintext === "string" || isInt(plaintext) || !Number.isFinite(plaintext)) return plaintext;
|
|
4088
5162
|
return pyRound(new JsonNumber(pyFloatRepr(plaintext)), decimals).value;
|
|
4089
5163
|
}
|
|
4090
|
-
function redactionOf(redact,
|
|
5164
|
+
function redactionOf(redact, field2) {
|
|
4091
5165
|
if (!redact) return null;
|
|
4092
|
-
const named = (names) => (names ?? []).some((name) => name ===
|
|
5166
|
+
const named = (names) => (names ?? []).some((name) => name === field2 || name.slice(name.lastIndexOf(".") + 1) === field2);
|
|
4093
5167
|
if (named(redact.drop)) return "drop";
|
|
4094
5168
|
if (named(redact.hash)) return "hash";
|
|
4095
5169
|
if (named(redact.preserve)) return "preserve";
|
|
4096
|
-
const decimals = redact.round?.[
|
|
5170
|
+
const decimals = redact.round?.[field2];
|
|
4097
5171
|
if (typeof decimals === "number") return `round:${decimals}`;
|
|
4098
5172
|
return null;
|
|
4099
5173
|
}
|
|
4100
|
-
function storedForms(world,
|
|
5174
|
+
function storedForms(world, field2, plaintext, transform) {
|
|
4101
5175
|
if (transform?.length) plaintext = applyTransforms(plaintext, transform);
|
|
4102
|
-
const policy = redactionOf(world.redact,
|
|
5176
|
+
const policy = redactionOf(world.redact, field2);
|
|
4103
5177
|
const salt = world.redact?.slug ?? world.slug;
|
|
4104
5178
|
if (policy === "drop") return [];
|
|
4105
5179
|
if (policy === "hash") return [hashForm(salt, plaintext)];
|
|
4106
5180
|
if (policy === "preserve") return [preserveForm(salt, plaintext)];
|
|
4107
|
-
if (policy !== null) return [roundForm(plaintext, world.redact.round[
|
|
5181
|
+
if (policy !== null) return [roundForm(plaintext, world.redact.round[field2])];
|
|
4108
5182
|
return [plaintext];
|
|
4109
5183
|
}
|
|
4110
5184
|
var isInt;
|
|
@@ -4189,80 +5263,51 @@ var init_router = __esm({
|
|
|
4189
5263
|
super(message);
|
|
4190
5264
|
this.exitCode = exitCode;
|
|
4191
5265
|
}
|
|
5266
|
+
exitCode;
|
|
4192
5267
|
};
|
|
4193
5268
|
}
|
|
4194
5269
|
});
|
|
4195
5270
|
|
|
4196
5271
|
// src/cli/config.ts
|
|
4197
|
-
import * as
|
|
5272
|
+
import * as fs6 from "fs";
|
|
4198
5273
|
import * as os from "os";
|
|
4199
|
-
import * as
|
|
4200
|
-
function transportDetail(error, timeoutMs) {
|
|
4201
|
-
if (error instanceof Error && error.name === "AbortError") return `timed out after ${Math.round(timeoutMs / 1e3)}s`;
|
|
4202
|
-
const cause = error instanceof Error && error.cause instanceof Error ? error.cause : void 0;
|
|
4203
|
-
const code = cause && "code" in cause && typeof cause.code === "string" ? `${cause.code}: ` : "";
|
|
4204
|
-
const message = cause?.message ?? (error instanceof Error ? error.message : String(error));
|
|
4205
|
-
return `${code}${message}`;
|
|
4206
|
-
}
|
|
5274
|
+
import * as path6 from "path";
|
|
4207
5275
|
async function api(creds, method, route, body, init2 = {}) {
|
|
4208
|
-
const
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
let res;
|
|
4212
|
-
try {
|
|
4213
|
-
res = await fetch(`${creds.host}${route}`, {
|
|
4214
|
-
method,
|
|
4215
|
-
headers: {
|
|
4216
|
-
"content-type": "application/json",
|
|
4217
|
-
accept: "application/json",
|
|
4218
|
-
authorization: "Basic " + Buffer.from(`${creds.publicKey}:${creds.secretKey}`).toString("base64")
|
|
4219
|
-
},
|
|
4220
|
-
...body === void 0 ? {} : { body: JSON.stringify(body) },
|
|
4221
|
-
signal: controller.signal
|
|
4222
|
-
});
|
|
4223
|
-
} catch (error) {
|
|
4224
|
-
clearTimeout(timer);
|
|
4225
|
-
throw new UnreachableError(creds.host, method, route, transportDetail(error, timeoutMs));
|
|
4226
|
-
}
|
|
4227
|
-
try {
|
|
4228
|
-
const text2 = await res.text();
|
|
4229
|
-
if (!res.ok) throw new ApiError(res.status, method, route, text2);
|
|
4230
|
-
return text2 ? JSON.parse(text2) : {};
|
|
4231
|
-
} finally {
|
|
4232
|
-
clearTimeout(timer);
|
|
4233
|
-
}
|
|
5276
|
+
const reply = await new PlatformTransport(creds).send(method, route, body, init2);
|
|
5277
|
+
if (!reply.ok) throw new ApiError2(reply.status, method, route, reply.text);
|
|
5278
|
+
return reply.text ? JSON.parse(reply.text) : {};
|
|
4234
5279
|
}
|
|
4235
|
-
var
|
|
5280
|
+
var ApiError2;
|
|
4236
5281
|
var init_config = __esm({
|
|
4237
5282
|
"src/cli/config.ts"() {
|
|
4238
5283
|
"use strict";
|
|
4239
5284
|
init_router();
|
|
4240
|
-
|
|
5285
|
+
init_worlds();
|
|
5286
|
+
init_transport();
|
|
5287
|
+
ApiError2 = class extends CliError {
|
|
4241
5288
|
constructor(status, method, route, text2) {
|
|
4242
|
-
|
|
5289
|
+
const body = parseErrorBody(text2);
|
|
5290
|
+
super(`${method} ${route} -> ${status}: ${body.detail}`, 1);
|
|
4243
5291
|
this.status = status;
|
|
4244
5292
|
this.method = method;
|
|
4245
5293
|
this.route = route;
|
|
4246
5294
|
this.text = text2;
|
|
5295
|
+
this.code = body.code;
|
|
4247
5296
|
}
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
this.method = method;
|
|
4254
|
-
this.route = route;
|
|
4255
|
-
this.detail = detail;
|
|
4256
|
-
}
|
|
5297
|
+
status;
|
|
5298
|
+
method;
|
|
5299
|
+
route;
|
|
5300
|
+
text;
|
|
5301
|
+
code;
|
|
4257
5302
|
};
|
|
4258
5303
|
}
|
|
4259
5304
|
});
|
|
4260
5305
|
|
|
4261
5306
|
// src/cli/runtime/local.ts
|
|
4262
5307
|
import { spawn, spawnSync } from "child_process";
|
|
4263
|
-
import * as
|
|
5308
|
+
import * as fs7 from "fs";
|
|
4264
5309
|
import * as net from "net";
|
|
4265
|
-
import * as
|
|
5310
|
+
import * as path7 from "path";
|
|
4266
5311
|
function tailOf(output) {
|
|
4267
5312
|
return output.length > DIAGNOSTIC_TAIL ? `\u2026${output.slice(-DIAGNOSTIC_TAIL)}` : output;
|
|
4268
5313
|
}
|
|
@@ -4277,16 +5322,16 @@ function runtimeRoot() {
|
|
|
4277
5322
|
const candidates = [];
|
|
4278
5323
|
if (process.env.GATEWAY_RUNTIME_PATH)
|
|
4279
5324
|
candidates.push(process.env.GATEWAY_RUNTIME_PATH);
|
|
4280
|
-
const entry = process.argv[1] &&
|
|
5325
|
+
const entry = process.argv[1] && fs7.existsSync(process.argv[1]) ? path7.dirname(fs7.realpathSync(process.argv[1])) : null;
|
|
4281
5326
|
if (entry) {
|
|
4282
|
-
candidates.push(
|
|
4283
|
-
candidates.push(
|
|
4284
|
-
candidates.push(
|
|
5327
|
+
candidates.push(path7.resolve(entry, "..", "runtime"));
|
|
5328
|
+
candidates.push(path7.resolve(entry, "..", "..", "runtime"));
|
|
5329
|
+
candidates.push(path7.resolve(entry, "..", "..", "sdk", "src"));
|
|
4285
5330
|
}
|
|
4286
|
-
candidates.push(
|
|
5331
|
+
candidates.push(path7.resolve(process.cwd(), "runtime"));
|
|
4287
5332
|
for (const root of candidates)
|
|
4288
|
-
if (
|
|
4289
|
-
|
|
5333
|
+
if (fs7.existsSync(
|
|
5334
|
+
path7.join(root, "gatewaysdk", "environment", "schema", "platform.py")
|
|
4290
5335
|
))
|
|
4291
5336
|
return root;
|
|
4292
5337
|
return null;
|
|
@@ -4369,7 +5414,7 @@ function localPythonHasYaml(python) {
|
|
|
4369
5414
|
}
|
|
4370
5415
|
async function localBridge(request, local, opts = {}) {
|
|
4371
5416
|
const input = JSON.stringify(request);
|
|
4372
|
-
return await new Promise((
|
|
5417
|
+
return await new Promise((resolve7, reject) => {
|
|
4373
5418
|
const child = spawn(
|
|
4374
5419
|
local.python,
|
|
4375
5420
|
["-I", "-B", "-c", BRIDGE_BOOTSTRAP, local.root],
|
|
@@ -4414,7 +5459,7 @@ async function localBridge(request, local, opts = {}) {
|
|
|
4414
5459
|
payload = null;
|
|
4415
5460
|
}
|
|
4416
5461
|
if (payload && typeof payload === "object") {
|
|
4417
|
-
|
|
5462
|
+
resolve7(payload);
|
|
4418
5463
|
return;
|
|
4419
5464
|
}
|
|
4420
5465
|
reject(
|
|
@@ -4433,7 +5478,7 @@ var init_local = __esm({
|
|
|
4433
5478
|
"use strict";
|
|
4434
5479
|
init_router();
|
|
4435
5480
|
init_config();
|
|
4436
|
-
MIN_PYTHON = [3,
|
|
5481
|
+
MIN_PYTHON = [3, 12];
|
|
4437
5482
|
DIAGNOSTIC_TAIL = 600;
|
|
4438
5483
|
BRIDGE_BOOTSTRAP = `import sys,runpy,types,os
|
|
4439
5484
|
root=sys.argv[1]
|
|
@@ -4445,7 +5490,6 @@ runpy.run_module('gatewaysdk.environment.schema.platform',run_name='__main__')`;
|
|
|
4445
5490
|
PYTHON_CANDIDATES = [
|
|
4446
5491
|
"python3.13",
|
|
4447
5492
|
"python3.12",
|
|
4448
|
-
"python3.11",
|
|
4449
5493
|
"python3",
|
|
4450
5494
|
"python"
|
|
4451
5495
|
];
|
|
@@ -4454,18 +5498,18 @@ runpy.run_module('gatewaysdk.environment.schema.platform',run_name='__main__')`;
|
|
|
4454
5498
|
});
|
|
4455
5499
|
|
|
4456
5500
|
// src/cli/runtime/client.ts
|
|
4457
|
-
import * as
|
|
4458
|
-
import * as
|
|
5501
|
+
import * as fs8 from "fs";
|
|
5502
|
+
import * as path8 from "path";
|
|
4459
5503
|
function isBuildOutput(relPath) {
|
|
4460
5504
|
return BUILD_OUTPUT.test(relPath);
|
|
4461
5505
|
}
|
|
4462
5506
|
function readWorldFiles(dir, opts = {}) {
|
|
4463
|
-
if (!
|
|
5507
|
+
if (!fs8.existsSync(dir) || !fs8.statSync(dir).isDirectory())
|
|
4464
5508
|
throw new CliError(`Not a directory: ${dir}`);
|
|
4465
5509
|
const out = [];
|
|
4466
5510
|
const walk = (rel) => {
|
|
4467
|
-
const abs = rel ?
|
|
4468
|
-
const entries =
|
|
5511
|
+
const abs = rel ? path8.join(dir, rel) : dir;
|
|
5512
|
+
const entries = fs8.readdirSync(abs, { withFileTypes: true });
|
|
4469
5513
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
4470
5514
|
for (const entry of entries) {
|
|
4471
5515
|
const childRel = rel ? `${rel}/${entry.name}` : entry.name;
|
|
@@ -4475,7 +5519,7 @@ function readWorldFiles(dir, opts = {}) {
|
|
|
4475
5519
|
if (!opts.buildOutputs && isBuildOutput(childRel)) continue;
|
|
4476
5520
|
out.push({
|
|
4477
5521
|
path: childRel,
|
|
4478
|
-
content:
|
|
5522
|
+
content: fs8.readFileSync(path8.join(dir, childRel)).toString("base64")
|
|
4479
5523
|
});
|
|
4480
5524
|
}
|
|
4481
5525
|
}
|
|
@@ -4489,20 +5533,22 @@ function assertSafeRelPath(rel) {
|
|
|
4489
5533
|
throw new CliError(`The runtime returned an unsafe file path: ${rel}`, 1);
|
|
4490
5534
|
}
|
|
4491
5535
|
function writeWorldFiles(dir, files, opts = {}) {
|
|
5536
|
+
if (files.length > MAX_WORLD_FILES)
|
|
5537
|
+
throw new CliError(`The runtime returned ${files.length} files, over the ${MAX_WORLD_FILES} limit`, 1);
|
|
4492
5538
|
for (const file of files) assertSafeRelPath(file.path);
|
|
4493
|
-
if (opts.clean &&
|
|
5539
|
+
if (opts.clean && fs8.existsSync(dir)) {
|
|
4494
5540
|
const keep = new Set(files.map((f) => f.path));
|
|
4495
5541
|
for (const existing of readWorldFiles(dir)) {
|
|
4496
|
-
if (!keep.has(existing.path))
|
|
5542
|
+
if (!keep.has(existing.path)) fs8.rmSync(path8.join(dir, existing.path));
|
|
4497
5543
|
}
|
|
4498
5544
|
pruneEmptyDirs(dir);
|
|
4499
5545
|
}
|
|
4500
|
-
|
|
5546
|
+
fs8.mkdirSync(dir, { recursive: true });
|
|
4501
5547
|
const written = [];
|
|
4502
5548
|
for (const file of files) {
|
|
4503
|
-
const target =
|
|
4504
|
-
|
|
4505
|
-
|
|
5549
|
+
const target = path8.join(dir, file.path);
|
|
5550
|
+
fs8.mkdirSync(path8.dirname(target), { recursive: true });
|
|
5551
|
+
fs8.writeFileSync(target, Buffer.from(file.content, "base64"));
|
|
4506
5552
|
written.push(file.path);
|
|
4507
5553
|
}
|
|
4508
5554
|
return written;
|
|
@@ -4510,14 +5556,14 @@ function writeWorldFiles(dir, files, opts = {}) {
|
|
|
4510
5556
|
function pruneEmptyDirs(root) {
|
|
4511
5557
|
const walk = (abs) => {
|
|
4512
5558
|
let empty = true;
|
|
4513
|
-
for (const entry of
|
|
4514
|
-
const child =
|
|
5559
|
+
for (const entry of fs8.readdirSync(abs, { withFileTypes: true })) {
|
|
5560
|
+
const child = path8.join(abs, entry.name);
|
|
4515
5561
|
if (entry.isDirectory()) {
|
|
4516
5562
|
if (SKIP_DIRS.has(entry.name)) {
|
|
4517
5563
|
empty = false;
|
|
4518
5564
|
continue;
|
|
4519
5565
|
}
|
|
4520
|
-
if (walk(child))
|
|
5566
|
+
if (walk(child)) fs8.rmdirSync(child);
|
|
4521
5567
|
else empty = false;
|
|
4522
5568
|
} else empty = false;
|
|
4523
5569
|
}
|
|
@@ -4537,56 +5583,59 @@ function detailFrom(payload) {
|
|
|
4537
5583
|
if (typeof detail.code !== "string" || typeof detail.message !== "string") return null;
|
|
4538
5584
|
return detail;
|
|
4539
5585
|
}
|
|
5586
|
+
function isYamlSource(name, base64) {
|
|
5587
|
+
if (name.endsWith(".json")) return false;
|
|
5588
|
+
if (YAML_NAME.test(name)) return true;
|
|
5589
|
+
const head = Buffer.from(base64.slice(0, 256), "base64").toString("utf8").trimStart();
|
|
5590
|
+
return !["{", "["].includes(head[0] ?? "");
|
|
5591
|
+
}
|
|
5592
|
+
function yamlDocument(request) {
|
|
5593
|
+
if (request.command === "init-openapi")
|
|
5594
|
+
return isYamlSource(String(request.source ?? ""), String(request.document ?? ""));
|
|
5595
|
+
return request.command === "conform" && Array.isArray(request.openapi) && request.openapi.some((doc) => YAML_NAME.test(doc.path ?? ""));
|
|
5596
|
+
}
|
|
5597
|
+
function runsLocally(request) {
|
|
5598
|
+
const local = localRuntime();
|
|
5599
|
+
return local !== null && !(yamlDocument(request) && !localPythonHasYaml(local.python));
|
|
5600
|
+
}
|
|
4540
5601
|
async function runtime(creds, request, opts = {}) {
|
|
4541
5602
|
const local = localRuntime();
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
const
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
return payload;
|
|
5603
|
+
if (local && runsLocally(request)) {
|
|
5604
|
+
const payload2 = await localBridge(request, local, opts);
|
|
5605
|
+
const detail2 = detailFrom(payload2);
|
|
5606
|
+
if (detail2) throw new BridgeRejected(detail2);
|
|
5607
|
+
return payload2;
|
|
4548
5608
|
}
|
|
4549
5609
|
if (!creds)
|
|
4550
5610
|
throw new CliError(
|
|
4551
5611
|
"This needs the schema runtime (the CLI bundles it) or platform credentials (`gateway auth login`). " + localRuntimeReason()
|
|
4552
5612
|
);
|
|
4553
|
-
const controller = new AbortController();
|
|
4554
|
-
const timer = setTimeout(() => controller.abort(), opts.timeoutMs ?? 18e4);
|
|
4555
5613
|
const route = "/api/public/worlds/runtime";
|
|
5614
|
+
const res = await new PlatformTransport(creds).send("POST", route, request, {
|
|
5615
|
+
timeoutMs: opts.timeoutMs ?? RUNTIME_TIMEOUT_MS
|
|
5616
|
+
});
|
|
5617
|
+
let payload = null;
|
|
4556
5618
|
try {
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
"content-type": "application/json",
|
|
4561
|
-
accept: "application/json",
|
|
4562
|
-
authorization: "Basic " + Buffer.from(`${creds.publicKey}:${creds.secretKey}`).toString("base64")
|
|
4563
|
-
},
|
|
4564
|
-
body: JSON.stringify(request),
|
|
4565
|
-
signal: controller.signal
|
|
4566
|
-
});
|
|
4567
|
-
const text2 = await res.text();
|
|
4568
|
-
let payload = null;
|
|
4569
|
-
try {
|
|
4570
|
-
payload = text2 ? JSON.parse(text2) : {};
|
|
4571
|
-
} catch {
|
|
4572
|
-
payload = null;
|
|
4573
|
-
}
|
|
4574
|
-
const detail = detailFrom(payload);
|
|
4575
|
-
if (detail) throw new BridgeRejected(detail);
|
|
4576
|
-
if (!res.ok)
|
|
4577
|
-
throw new CliError(`POST ${route} (${request.command}) -> ${res.status}: ${text2.slice(0, 600)}`, 1);
|
|
4578
|
-
if (payload === null) throw new CliError(`POST ${route} (${request.command}) returned non-JSON`, 1);
|
|
4579
|
-
return payload;
|
|
4580
|
-
} finally {
|
|
4581
|
-
clearTimeout(timer);
|
|
5619
|
+
payload = res.text ? JSON.parse(res.text) : {};
|
|
5620
|
+
} catch {
|
|
5621
|
+
payload = null;
|
|
4582
5622
|
}
|
|
5623
|
+
const detail = detailFrom(payload);
|
|
5624
|
+
if (detail) throw new BridgeRejected(detail);
|
|
5625
|
+
if (!res.ok)
|
|
5626
|
+
throw new CliError(`POST ${route} (${request.command}) -> ${res.status}: ${res.text.slice(0, 600)}`, 1);
|
|
5627
|
+
if (payload === null) throw new CliError(`POST ${route} (${request.command}) returned non-JSON`, 1);
|
|
5628
|
+
return payload;
|
|
4583
5629
|
}
|
|
4584
|
-
var SKIP_DIRS, BUILD_OUTPUT, BridgeRejected;
|
|
5630
|
+
var MAX_WORLD_FILES, RUNTIME_TIMEOUT_MS, SKIP_DIRS, BUILD_OUTPUT, BridgeRejected, YAML_NAME;
|
|
4585
5631
|
var init_client = __esm({
|
|
4586
5632
|
"src/cli/runtime/client.ts"() {
|
|
4587
5633
|
"use strict";
|
|
4588
5634
|
init_router();
|
|
4589
5635
|
init_local();
|
|
5636
|
+
init_transport();
|
|
5637
|
+
MAX_WORLD_FILES = 2e3;
|
|
5638
|
+
RUNTIME_TIMEOUT_MS = 18e4;
|
|
4590
5639
|
SKIP_DIRS = /* @__PURE__ */ new Set(["__pycache__", ".git", "node_modules", ".gateway"]);
|
|
4591
5640
|
BUILD_OUTPUT = /(^|\/)state\.(sqlite|json)$/;
|
|
4592
5641
|
BridgeRejected = class extends CliError {
|
|
@@ -4594,7 +5643,9 @@ var init_client = __esm({
|
|
|
4594
5643
|
super(formatBridgeError(detail), 1);
|
|
4595
5644
|
this.detail = detail;
|
|
4596
5645
|
}
|
|
5646
|
+
detail;
|
|
4597
5647
|
};
|
|
5648
|
+
YAML_NAME = /\.ya?ml$/i;
|
|
4598
5649
|
}
|
|
4599
5650
|
});
|
|
4600
5651
|
|
|
@@ -4602,15 +5653,17 @@ var init_client = __esm({
|
|
|
4602
5653
|
var data_exports = {};
|
|
4603
5654
|
__export(data_exports, {
|
|
4604
5655
|
checkLocalWorldData: () => checkLocalWorldData,
|
|
5656
|
+
chunkLocalWorldFiles: () => chunkLocalWorldFiles,
|
|
4605
5657
|
dropBuildOutputs: () => dropBuildOutputs,
|
|
4606
5658
|
importLocalWorldData: () => importLocalWorldData,
|
|
5659
|
+
importLocalWorldFiles: () => importLocalWorldFiles,
|
|
4607
5660
|
ingestLocalToolCalls: () => ingestLocalToolCalls,
|
|
4608
5661
|
queryLocalWorldData: () => queryLocalWorldData,
|
|
4609
5662
|
queryLocalWorldDataAcross: () => queryLocalWorldDataAcross,
|
|
4610
5663
|
showLocalWorldData: () => showLocalWorldData
|
|
4611
5664
|
});
|
|
4612
|
-
import * as
|
|
4613
|
-
import * as
|
|
5665
|
+
import * as fs9 from "fs";
|
|
5666
|
+
import * as path9 from "path";
|
|
4614
5667
|
async function importLocalWorldData(dir, rows, opts, creds) {
|
|
4615
5668
|
const res = await runtime(creds, {
|
|
4616
5669
|
command: "import-data",
|
|
@@ -4632,11 +5685,57 @@ async function importLocalWorldData(dir, rows, opts, creds) {
|
|
|
4632
5685
|
} : {}
|
|
4633
5686
|
};
|
|
4634
5687
|
}
|
|
5688
|
+
async function importLocalWorldFiles(dir, sources, opts) {
|
|
5689
|
+
const local = localRuntime();
|
|
5690
|
+
if (!local)
|
|
5691
|
+
throw new CliError(
|
|
5692
|
+
`Rows files stream into a directory through the bundled runtime on this machine, and none can run: ${localRuntimeReason()}`,
|
|
5693
|
+
1
|
|
5694
|
+
);
|
|
5695
|
+
const res = await runtime(null, {
|
|
5696
|
+
command: "import-files",
|
|
5697
|
+
world: path9.resolve(dir),
|
|
5698
|
+
sources: sources.map((source) => path9.resolve(source)),
|
|
5699
|
+
mode: opts.mode ?? "append",
|
|
5700
|
+
...opts.entity ? { entity: opts.entity } : {},
|
|
5701
|
+
...opts.delimiter ? { delimiter: opts.delimiter } : {},
|
|
5702
|
+
...opts.merge && opts.merge !== "upsert" ? { merge: opts.merge } : {},
|
|
5703
|
+
...opts.redact && opts.redact !== "off" ? { redact: opts.redact } : {},
|
|
5704
|
+
...opts.dryRun ? { dry_run: true } : {}
|
|
5705
|
+
});
|
|
5706
|
+
return {
|
|
5707
|
+
kind: res.kind ?? "unknown",
|
|
5708
|
+
entity_counts: res.entity_counts ?? {},
|
|
5709
|
+
changed: Boolean(res.changed),
|
|
5710
|
+
rows: res.rows ?? 0,
|
|
5711
|
+
...res.proof ? { proof: res.proof } : {},
|
|
5712
|
+
...res.deferred ? { deferred: res.deferred } : {}
|
|
5713
|
+
};
|
|
5714
|
+
}
|
|
5715
|
+
async function chunkLocalWorldFiles(dir, sources, out, opts) {
|
|
5716
|
+
const local = localRuntime();
|
|
5717
|
+
if (!local)
|
|
5718
|
+
throw new CliError(
|
|
5719
|
+
`Rows files are cut into chunks by the bundled runtime on this machine, and none can run: ${localRuntimeReason()}`,
|
|
5720
|
+
1
|
|
5721
|
+
);
|
|
5722
|
+
const res = await runtime(null, {
|
|
5723
|
+
command: "chunk-files",
|
|
5724
|
+
world: path9.resolve(dir),
|
|
5725
|
+
sources: sources.map((source) => path9.resolve(source)),
|
|
5726
|
+
out: path9.resolve(out),
|
|
5727
|
+
...opts.entity ? { entity: opts.entity } : {},
|
|
5728
|
+
...opts.delimiter ? { delimiter: opts.delimiter } : {},
|
|
5729
|
+
...opts.chunkBytes ? { chunk_bytes: opts.chunkBytes } : {},
|
|
5730
|
+
...opts.chunkRows ? { chunk_rows: opts.chunkRows } : {}
|
|
5731
|
+
});
|
|
5732
|
+
return { rows: res.rows ?? 0, chunks: res.chunks ?? [] };
|
|
5733
|
+
}
|
|
4635
5734
|
function dropBuildOutputs(dir) {
|
|
4636
5735
|
const dropped = [];
|
|
4637
5736
|
for (const file of readWorldFiles(dir, { buildOutputs: true })) {
|
|
4638
5737
|
if (!BUILD_OUTPUT2.test(file.path)) continue;
|
|
4639
|
-
|
|
5738
|
+
fs9.rmSync(path9.join(dir, file.path), { force: true });
|
|
4640
5739
|
dropped.push(file.path);
|
|
4641
5740
|
}
|
|
4642
5741
|
return dropped;
|
|
@@ -4703,7 +5802,7 @@ async function queryLocalWorldDataAcross(dir, entity, where, opts) {
|
|
|
4703
5802
|
const payload = await localBridge(
|
|
4704
5803
|
{
|
|
4705
5804
|
command: "query",
|
|
4706
|
-
world:
|
|
5805
|
+
world: path9.resolve(dir),
|
|
4707
5806
|
entity,
|
|
4708
5807
|
across: true,
|
|
4709
5808
|
...opts.compare ? { compare: true } : {},
|
|
@@ -4774,9 +5873,9 @@ __export(transform_exports, {
|
|
|
4774
5873
|
transformRecords: () => transformRecords
|
|
4775
5874
|
});
|
|
4776
5875
|
import { spawn as spawn2 } from "child_process";
|
|
4777
|
-
import * as
|
|
5876
|
+
import * as fs10 from "fs";
|
|
4778
5877
|
import * as os2 from "os";
|
|
4779
|
-
import * as
|
|
5878
|
+
import * as path10 from "path";
|
|
4780
5879
|
import { createRequire } from "module";
|
|
4781
5880
|
function checkRows(value, where) {
|
|
4782
5881
|
if (!isObject(value)) throw new CliError(`${where} must return {entity: [rows]}; got ${value === null ? "null" : Array.isArray(value) ? "an array" : typeof value}`, 1);
|
|
@@ -4801,27 +5900,27 @@ function typescriptPrefix() {
|
|
|
4801
5900
|
}
|
|
4802
5901
|
}
|
|
4803
5902
|
function command(script, wrapperDir) {
|
|
4804
|
-
const suffix =
|
|
5903
|
+
const suffix = path10.extname(script).toLowerCase();
|
|
4805
5904
|
if (PYTHON_SUFFIXES.includes(suffix)) return { file: process.env.GATEWAY_PYTHON || "python3", args: ["-c", PY_WRAPPER, script] };
|
|
4806
5905
|
if (NODE_SUFFIXES.includes(suffix)) {
|
|
4807
|
-
const wrapper =
|
|
4808
|
-
|
|
5906
|
+
const wrapper = path10.join(wrapperDir, "transform-wrapper.mjs");
|
|
5907
|
+
fs10.writeFileSync(wrapper, NODE_WRAPPER);
|
|
4809
5908
|
const flags = suffix === ".ts" || suffix === ".mts" ? typescriptPrefix() : [];
|
|
4810
5909
|
return { file: process.env.GATEWAY_NODE || process.execPath, args: [...flags, wrapper, script] };
|
|
4811
5910
|
}
|
|
4812
|
-
throw new CliError(`${
|
|
5911
|
+
throw new CliError(`${path10.basename(script)}: a transform script is .py, .ts, .mjs, .js or .cjs`, 1);
|
|
4813
5912
|
}
|
|
4814
5913
|
async function runTransform(script, records, opts = {}) {
|
|
4815
|
-
if (!
|
|
4816
|
-
const resolved =
|
|
4817
|
-
const name =
|
|
5914
|
+
if (!fs10.existsSync(script) || !fs10.statSync(script).isFile()) throw new CliError(`no transform script at ${script}`, 1);
|
|
5915
|
+
const resolved = path10.resolve(script);
|
|
5916
|
+
const name = path10.basename(script);
|
|
4818
5917
|
const timeoutMs = opts.timeoutMs ?? DEFAULT_TRANSFORM_TIMEOUT_MS;
|
|
4819
|
-
const scratch =
|
|
5918
|
+
const scratch = fs10.mkdtempSync(path10.join(os2.tmpdir(), "gateway-transform-"));
|
|
4820
5919
|
try {
|
|
4821
5920
|
const { file, args } = command(resolved, scratch);
|
|
4822
5921
|
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !SCRUBBED.test(key)));
|
|
4823
|
-
const done = await new Promise((
|
|
4824
|
-
const child = spawn2(file, args, { cwd:
|
|
5922
|
+
const done = await new Promise((resolve7, reject) => {
|
|
5923
|
+
const child = spawn2(file, args, { cwd: path10.dirname(resolved), env, stdio: ["pipe", "pipe", "pipe"] });
|
|
4825
5924
|
let stdout = "";
|
|
4826
5925
|
let stderr = "";
|
|
4827
5926
|
let timedOut = false;
|
|
@@ -4837,7 +5936,7 @@ async function runTransform(script, records, opts = {}) {
|
|
|
4837
5936
|
});
|
|
4838
5937
|
child.on("close", (code) => {
|
|
4839
5938
|
clearTimeout(timer);
|
|
4840
|
-
|
|
5939
|
+
resolve7({ code, stdout, stderr, timedOut });
|
|
4841
5940
|
});
|
|
4842
5941
|
child.stdin.on("error", () => void 0);
|
|
4843
5942
|
child.stdin.end(records.map((record) => JSON.stringify(record) + "\n").join(""));
|
|
@@ -4852,7 +5951,7 @@ async function runTransform(script, records, opts = {}) {
|
|
|
4852
5951
|
}
|
|
4853
5952
|
return { rows: checkRows(value, name), stderr: done.stderr };
|
|
4854
5953
|
} finally {
|
|
4855
|
-
|
|
5954
|
+
fs10.rmSync(scratch, { recursive: true, force: true });
|
|
4856
5955
|
}
|
|
4857
5956
|
}
|
|
4858
5957
|
async function transformRecords(transform, records, opts = {}) {
|
|
@@ -4945,7 +6044,7 @@ if (fn) {
|
|
|
4945
6044
|
|
|
4946
6045
|
// src/cli/platform/worldData/batches.ts
|
|
4947
6046
|
import { createHash as createHash6 } from "crypto";
|
|
4948
|
-
import * as
|
|
6047
|
+
import * as fs11 from "fs";
|
|
4949
6048
|
function isSettled(status) {
|
|
4950
6049
|
if (!TERMINAL_STATES.has(status.state)) return false;
|
|
4951
6050
|
if (status.state !== "applied") return true;
|
|
@@ -5013,7 +6112,7 @@ var init_batches = __esm({
|
|
|
5013
6112
|
"published",
|
|
5014
6113
|
"failed"
|
|
5015
6114
|
]);
|
|
5016
|
-
sleepMs = (ms) => new Promise((
|
|
6115
|
+
sleepMs = (ms) => new Promise((resolve7) => setTimeout(resolve7, ms));
|
|
5017
6116
|
WorldDataApi = class {
|
|
5018
6117
|
constructor(creds, slug, sleep2 = sleepMs) {
|
|
5019
6118
|
this.creds = creds;
|
|
@@ -5021,6 +6120,9 @@ var init_batches = __esm({
|
|
|
5021
6120
|
this.sleep = sleep2;
|
|
5022
6121
|
this.base = `/api/public/worlds/${encodeURIComponent(slug)}/data`;
|
|
5023
6122
|
}
|
|
6123
|
+
creds;
|
|
6124
|
+
slug;
|
|
6125
|
+
sleep;
|
|
5024
6126
|
base;
|
|
5025
6127
|
open(body) {
|
|
5026
6128
|
return api(this.creds, "POST", `${this.base}/batches`, body);
|
|
@@ -5296,9 +6398,9 @@ var init_push = __esm({
|
|
|
5296
6398
|
});
|
|
5297
6399
|
|
|
5298
6400
|
// src/worlds/ingest.ts
|
|
5299
|
-
import * as
|
|
6401
|
+
import * as fs12 from "fs";
|
|
5300
6402
|
import * as os3 from "os";
|
|
5301
|
-
import * as
|
|
6403
|
+
import * as path11 from "path";
|
|
5302
6404
|
function parseToolCallRecord(raw) {
|
|
5303
6405
|
const none = { record: null, skip: null };
|
|
5304
6406
|
if (!isObject2(raw)) return { ...none, refusal: "record is not an object" };
|
|
@@ -5319,7 +6421,7 @@ function parseToolCallRecord(raw) {
|
|
|
5319
6421
|
}
|
|
5320
6422
|
function readToolCallRecords(paths) {
|
|
5321
6423
|
const records = [];
|
|
5322
|
-
for (const file of paths) records.push(...toolCallRecordsIn(
|
|
6424
|
+
for (const file of paths) records.push(...toolCallRecordsIn(fs12.readFileSync(file, "utf8"), file));
|
|
5323
6425
|
return records;
|
|
5324
6426
|
}
|
|
5325
6427
|
function toolCallRecordsIn(text2, where) {
|
|
@@ -5355,7 +6457,7 @@ async function emit(sink, record) {
|
|
|
5355
6457
|
return;
|
|
5356
6458
|
}
|
|
5357
6459
|
if (typeof sink === "string") {
|
|
5358
|
-
|
|
6460
|
+
fs12.appendFileSync(sink, JSON.stringify(record) + "\n");
|
|
5359
6461
|
return;
|
|
5360
6462
|
}
|
|
5361
6463
|
if (typeof sink === "function") {
|
|
@@ -5435,7 +6537,7 @@ async function ingest(world, records, options = {}) {
|
|
|
5435
6537
|
const mode = options.mode ?? "append";
|
|
5436
6538
|
const dryRun = Boolean(options.dryRun);
|
|
5437
6539
|
const creds = credentialsOf(options);
|
|
5438
|
-
const local =
|
|
6540
|
+
const local = fs12.existsSync(world) && fs12.statSync(world).isDirectory();
|
|
5439
6541
|
const map = options.map === void 0 ? void 0 : options.map;
|
|
5440
6542
|
let rows = null;
|
|
5441
6543
|
let stderr = "";
|
|
@@ -5451,9 +6553,9 @@ async function ingest(world, records, options = {}) {
|
|
|
5451
6553
|
if (!creds) throw new Error("Gateway keys missing: set GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY (or pass publicKey/secretKey).");
|
|
5452
6554
|
const { pull: pull2 } = await Promise.resolve().then(() => (init_hub(), hub_exports));
|
|
5453
6555
|
const slug = world.split("@", 1)[0];
|
|
5454
|
-
const scratch =
|
|
6556
|
+
const scratch = fs12.mkdtempSync(path11.join(os3.tmpdir(), "gateway-ingest-"));
|
|
5455
6557
|
try {
|
|
5456
|
-
const pulled = await pull2(world,
|
|
6558
|
+
const pulled = await pull2(world, path11.join(scratch, slug), options);
|
|
5457
6559
|
let report;
|
|
5458
6560
|
let projected;
|
|
5459
6561
|
if (rows === null) {
|
|
@@ -5474,7 +6576,7 @@ async function ingest(world, records, options = {}) {
|
|
|
5474
6576
|
if (status.entityCounts) report.entityCounts = status.entityCounts;
|
|
5475
6577
|
return report;
|
|
5476
6578
|
} finally {
|
|
5477
|
-
|
|
6579
|
+
fs12.rmSync(scratch, { recursive: true, force: true });
|
|
5478
6580
|
}
|
|
5479
6581
|
}
|
|
5480
6582
|
async function ingestToolCalls(world, records, options = {}) {
|
|
@@ -5537,53 +6639,126 @@ var init_ingest = __esm({
|
|
|
5537
6639
|
}
|
|
5538
6640
|
});
|
|
5539
6641
|
|
|
5540
|
-
// src/worlds/
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
return { slug: slugRef.slice(0, at), ref: slugRef.slice(at + 1) };
|
|
5545
|
-
}
|
|
5546
|
-
var sid, WorldSandboxClient;
|
|
5547
|
-
var init_sandbox = __esm({
|
|
5548
|
-
"src/worlds/sandbox.ts"() {
|
|
6642
|
+
// src/worlds/editSessions.ts
|
|
6643
|
+
var WORLDS, WorldEditClient;
|
|
6644
|
+
var init_editSessions = __esm({
|
|
6645
|
+
"src/worlds/editSessions.ts"() {
|
|
5549
6646
|
"use strict";
|
|
5550
6647
|
init_worlds();
|
|
5551
|
-
|
|
5552
|
-
|
|
6648
|
+
WORLDS = "/api/public/worlds";
|
|
6649
|
+
WorldEditClient = class {
|
|
5553
6650
|
constructor(options = {}) {
|
|
5554
6651
|
this.options = options;
|
|
5555
6652
|
}
|
|
5556
|
-
|
|
5557
|
-
|
|
6653
|
+
options;
|
|
6654
|
+
/** The credential's current session and the world's newest-first sessions. */
|
|
6655
|
+
list(slug, query = {}) {
|
|
6656
|
+
const qs = new URLSearchParams();
|
|
6657
|
+
if (query.status) qs.set("status", query.status);
|
|
6658
|
+
if (query.limit !== void 0) qs.set("limit", String(query.limit));
|
|
6659
|
+
const suffix = qs.size ? `?${qs.toString()}` : "";
|
|
6660
|
+
return apiRequest(this.options, "GET", `${WORLDS}/${encodeURIComponent(slug)}/edits${suffix}`);
|
|
5558
6661
|
}
|
|
5559
|
-
|
|
5560
|
-
|
|
6662
|
+
/** Seal a session into a version on main (the credential's current one when `sessionId` is omitted). */
|
|
6663
|
+
close(slug, input = {}) {
|
|
6664
|
+
return apiRequest(this.options, "POST", `${WORLDS}/${encodeURIComponent(slug)}/edits/close`, input);
|
|
5561
6665
|
}
|
|
5562
|
-
|
|
5563
|
-
|
|
6666
|
+
/** Drop the session's private branch without making a version. */
|
|
6667
|
+
discard(slug, input = {}) {
|
|
6668
|
+
return apiRequest(this.options, "POST", `${WORLDS}/${encodeURIComponent(slug)}/edits/discard`, input);
|
|
6669
|
+
}
|
|
6670
|
+
/** Undo a sealed session (source and data) as a new sealed session. */
|
|
6671
|
+
rollback(slug, input) {
|
|
6672
|
+
return apiRequest(this.options, "POST", `${WORLDS}/${encodeURIComponent(slug)}/edits/rollback`, input);
|
|
6673
|
+
}
|
|
6674
|
+
};
|
|
6675
|
+
}
|
|
6676
|
+
});
|
|
6677
|
+
|
|
6678
|
+
// src/worlds/dryRun.ts
|
|
6679
|
+
var DRY_RUN_KIND, DRY_RUN_AGENT, STATUS_WAIT_CAP_SECONDS, cid, HostedDryRunClient, DryRunOutcome;
|
|
6680
|
+
var init_dryRun = __esm({
|
|
6681
|
+
"src/worlds/dryRun.ts"() {
|
|
6682
|
+
"use strict";
|
|
6683
|
+
init_worlds();
|
|
6684
|
+
DRY_RUN_KIND = "dry-run";
|
|
6685
|
+
DRY_RUN_AGENT = "oracle";
|
|
6686
|
+
STATUS_WAIT_CAP_SECONDS = 50;
|
|
6687
|
+
cid = (id) => `/api/public/environments/${encodeURIComponent(id)}`;
|
|
6688
|
+
HostedDryRunClient = class {
|
|
6689
|
+
constructor(options = {}) {
|
|
6690
|
+
this.options = options;
|
|
6691
|
+
}
|
|
6692
|
+
options;
|
|
6693
|
+
/** Dispatch ONE oracle job for `task` on `containerId` (a container id, not a slug); pins `versionId` when given. */
|
|
6694
|
+
dispatch(target) {
|
|
6695
|
+
return apiRequest(
|
|
5564
6696
|
this.options,
|
|
5565
|
-
"
|
|
5566
|
-
|
|
6697
|
+
"POST",
|
|
6698
|
+
`${cid(target.containerId)}/dry-run`,
|
|
6699
|
+
{
|
|
6700
|
+
task: target.task,
|
|
6701
|
+
...target.versionId ? { versionId: target.versionId } : {}
|
|
6702
|
+
}
|
|
5567
6703
|
);
|
|
5568
|
-
return { path: res.path, size: res.size, bytes: Buffer.from(res.contentBase64, "base64") };
|
|
5569
6704
|
}
|
|
5570
|
-
|
|
5571
|
-
|
|
5572
|
-
|
|
5573
|
-
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
return apiRequest(
|
|
6705
|
+
/** One status read, blocking server-side for up to `waitSeconds` (capped). */
|
|
6706
|
+
status(runId, waitSeconds = 0) {
|
|
6707
|
+
const wait = Math.max(
|
|
6708
|
+
0,
|
|
6709
|
+
Math.min(Math.floor(waitSeconds), STATUS_WAIT_CAP_SECONDS)
|
|
6710
|
+
);
|
|
6711
|
+
const suffix = wait ? `?waitSeconds=${wait}` : "";
|
|
6712
|
+
return apiRequest(
|
|
6713
|
+
this.options,
|
|
6714
|
+
"GET",
|
|
6715
|
+
`/api/public/environments/runs/${encodeURIComponent(runId)}${suffix}`
|
|
6716
|
+
);
|
|
5578
6717
|
}
|
|
5579
|
-
|
|
5580
|
-
|
|
6718
|
+
/** Poll until the run settles or `timeoutSeconds` pass; the last verdict either way. */
|
|
6719
|
+
async settle(runId, opts) {
|
|
6720
|
+
const now = opts.now ?? Date.now;
|
|
6721
|
+
const sleep2 = opts.sleep ?? ((ms) => new Promise((resolve7) => setTimeout(resolve7, ms)));
|
|
6722
|
+
const deadline = now() + opts.timeoutSeconds * 1e3;
|
|
6723
|
+
for (; ; ) {
|
|
6724
|
+
const budget = Math.floor(
|
|
6725
|
+
Math.min(45, Math.max(0, (deadline - now()) / 1e3))
|
|
6726
|
+
);
|
|
6727
|
+
const asked = now();
|
|
6728
|
+
const verdict = await this.status(runId, budget);
|
|
6729
|
+
if (verdict.settled || now() >= deadline) return verdict;
|
|
6730
|
+
opts.onProgress?.(verdict);
|
|
6731
|
+
if (now() - asked < 1e3) await sleep2(1e3);
|
|
6732
|
+
}
|
|
5581
6733
|
}
|
|
5582
|
-
|
|
5583
|
-
|
|
6734
|
+
};
|
|
6735
|
+
DryRunOutcome = class {
|
|
6736
|
+
constructor(verdict) {
|
|
6737
|
+
this.verdict = verdict;
|
|
6738
|
+
}
|
|
6739
|
+
verdict;
|
|
6740
|
+
get settlement() {
|
|
6741
|
+
return this.verdict.dryRun?.settlement ?? null;
|
|
6742
|
+
}
|
|
6743
|
+
/** Why the dry run did not pass, or null when it did. */
|
|
6744
|
+
reason() {
|
|
6745
|
+
if (!this.verdict.settled) return `still running after the wait`;
|
|
6746
|
+
const settlement = this.settlement;
|
|
6747
|
+
if (!settlement)
|
|
6748
|
+
return `the runner filed no settlement (${this.verdict.status})`;
|
|
6749
|
+
const lastErrorLine = settlement.errorTail?.trim().split("\n").at(-1) || null;
|
|
6750
|
+
if (settlement.exitCode !== null && settlement.exitCode !== 0)
|
|
6751
|
+
return `the runner failed (exit ${settlement.exitCode}): ${lastErrorLine ?? "harbor exited non-zero"}`;
|
|
6752
|
+
if (settlement.reward === null && lastErrorLine)
|
|
6753
|
+
return `the runner failed (exit ?): ${lastErrorLine}`;
|
|
6754
|
+
if (settlement.reward === null)
|
|
6755
|
+
return "ungraded: the grader ran but wrote no reward";
|
|
6756
|
+
if (settlement.reward !== 1)
|
|
6757
|
+
return `the reference solution scored ${settlement.reward}, not 1.0`;
|
|
6758
|
+
return null;
|
|
5584
6759
|
}
|
|
5585
|
-
|
|
5586
|
-
return
|
|
6760
|
+
passed() {
|
|
6761
|
+
return this.reason() === null;
|
|
5587
6762
|
}
|
|
5588
6763
|
};
|
|
5589
6764
|
}
|
|
@@ -5592,23 +6767,53 @@ var init_sandbox = __esm({
|
|
|
5592
6767
|
// src/worlds/index.ts
|
|
5593
6768
|
var worlds_exports = {};
|
|
5594
6769
|
__export(worlds_exports, {
|
|
5595
|
-
ApiError: () =>
|
|
6770
|
+
ApiError: () => ApiError,
|
|
6771
|
+
BROWSER_GONE_PATTERNS: () => BROWSER_GONE_PATTERNS,
|
|
6772
|
+
BROWSER_TIERS: () => BROWSER_TIERS,
|
|
5596
6773
|
BrowserActionRecorder: () => BrowserActionRecorder,
|
|
6774
|
+
BrowserReconnected: () => BrowserReconnected,
|
|
6775
|
+
BrowserReconnector: () => BrowserReconnector,
|
|
6776
|
+
BrowserUnrecoverable: () => BrowserUnrecoverable,
|
|
6777
|
+
CALL_BODY_LIMIT_BYTES: () => CALL_BODY_LIMIT_BYTES,
|
|
6778
|
+
CALL_BODY_LIMIT_LABEL: () => CALL_BODY_LIMIT_LABEL,
|
|
5597
6779
|
COMPUTER_USE_SPECS: () => COMPUTER_USE_SPECS,
|
|
6780
|
+
CheckoutProvenance: () => CheckoutProvenance,
|
|
5598
6781
|
DEFAULT_BRANCH: () => DEFAULT_BRANCH,
|
|
5599
6782
|
DEFAULT_VIEWPORT: () => DEFAULT_VIEWPORT,
|
|
6783
|
+
DRY_RUN_AGENT: () => DRY_RUN_AGENT,
|
|
6784
|
+
DRY_RUN_KIND: () => DRY_RUN_KIND,
|
|
6785
|
+
DetachedPushError: () => DetachedPushError,
|
|
6786
|
+
DryRunOutcome: () => DryRunOutcome,
|
|
5600
6787
|
EVENT_BATCH_SIZE: () => EVENT_BATCH_SIZE,
|
|
5601
6788
|
EVENT_FLUSH_INTERVAL_MS: () => EVENT_FLUSH_INTERVAL_MS,
|
|
5602
6789
|
EVENT_MAX_RETRIES: () => EVENT_MAX_RETRIES,
|
|
6790
|
+
EXPLORATORY_TASK: () => EXPLORATORY_TASK,
|
|
6791
|
+
EXPLORATORY_TASK_SOURCE: () => EXPLORATORY_TASK_SOURCE,
|
|
5603
6792
|
GatewayEvalsClient: () => GatewayEvalsClient,
|
|
6793
|
+
HostedDryRunClient: () => HostedDryRunClient,
|
|
6794
|
+
IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
|
|
6795
|
+
NO_GRADER_REASON: () => NO_GRADER_REASON,
|
|
6796
|
+
PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
6797
|
+
PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
|
|
6798
|
+
PlatformTransport: () => PlatformTransport,
|
|
5604
6799
|
PushSlugConflict: () => PushSlugConflict,
|
|
6800
|
+
RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
|
|
6801
|
+
SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
|
|
6802
|
+
SESSION_STATES: () => SESSION_STATES,
|
|
6803
|
+
STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
|
|
5605
6804
|
STRIP_PREFIX: () => STRIP_PREFIX,
|
|
5606
6805
|
SURFACE_KINDS: () => SURFACE_KINDS,
|
|
6806
|
+
SecretScrubber: () => SecretScrubber,
|
|
5607
6807
|
TRANSFORMS: () => TRANSFORMS,
|
|
5608
6808
|
TaskRun: () => TaskRun,
|
|
5609
6809
|
TaskSessions: () => TaskSessions,
|
|
6810
|
+
TransportCause: () => TransportCause,
|
|
6811
|
+
UnreachableError: () => UnreachableError,
|
|
6812
|
+
VERIFIER_REWARD_PREFIX: () => VERIFIER_REWARD_PREFIX,
|
|
5610
6813
|
WHITESPACE: () => WHITESPACE,
|
|
5611
6814
|
WorldBrowser: () => WorldBrowser,
|
|
6815
|
+
WorldCallTooLarge: () => WorldCallTooLarge,
|
|
6816
|
+
WorldEditClient: () => WorldEditClient,
|
|
5612
6817
|
WorldSandboxClient: () => WorldSandboxClient,
|
|
5613
6818
|
WorldSession: () => WorldSession,
|
|
5614
6819
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
@@ -5620,12 +6825,16 @@ __export(worlds_exports, {
|
|
|
5620
6825
|
apiRequest: () => apiRequest,
|
|
5621
6826
|
applyTransforms: () => applyTransforms,
|
|
5622
6827
|
archiveMode: () => archiveMode,
|
|
6828
|
+
assertBrowserTier: () => assertBrowserTier,
|
|
6829
|
+
assertTaskRef: () => assertTaskRef,
|
|
5623
6830
|
attachManifest: () => attachManifest,
|
|
5624
6831
|
attachSession: () => attachSession,
|
|
5625
6832
|
attachTask: () => attachTask,
|
|
5626
6833
|
buildFileManifest: () => buildFileManifest,
|
|
5627
6834
|
buildSourceTarball: () => buildSourceTarball,
|
|
5628
6835
|
captureToolCalls: () => captureToolCalls,
|
|
6836
|
+
checkoutIdentity: () => checkoutIdentity,
|
|
6837
|
+
closeConnection: () => closeConnection,
|
|
5629
6838
|
collectArchiveRelPaths: () => collectArchiveRelPaths,
|
|
5630
6839
|
computeContentHash: () => computeContentHash,
|
|
5631
6840
|
computerUseToolkit: () => computerUseToolkit,
|
|
@@ -5639,13 +6848,18 @@ __export(worlds_exports, {
|
|
|
5639
6848
|
getRun: () => getRun,
|
|
5640
6849
|
getTask: () => getTask,
|
|
5641
6850
|
hashForm: () => hashForm,
|
|
6851
|
+
idleWarning: () => idleWarning,
|
|
5642
6852
|
ingest: () => ingest,
|
|
5643
6853
|
ingestToolCalls: () => ingestToolCalls,
|
|
6854
|
+
isBrowserGone: () => isBrowserGone,
|
|
6855
|
+
isSandboxImportPending: () => isSandboxImportPending,
|
|
5644
6856
|
isTaskIdRef: () => isTaskIdRef,
|
|
5645
6857
|
isTaskManifest: () => isTaskManifest,
|
|
5646
6858
|
isTaskSpec: () => isTaskSpec,
|
|
5647
6859
|
listEnvSecretKeys: () => listEnvSecretKeys,
|
|
5648
6860
|
listRunConfigs: () => listRunConfigs,
|
|
6861
|
+
listRuns: () => listRuns,
|
|
6862
|
+
listSessions: () => listSessions,
|
|
5649
6863
|
listTaskSessions: () => listTaskSessions,
|
|
5650
6864
|
listTasks: () => listTasks,
|
|
5651
6865
|
localTreeState: () => localTreeState,
|
|
@@ -5657,28 +6871,35 @@ __export(worlds_exports, {
|
|
|
5657
6871
|
openTask: () => openTask,
|
|
5658
6872
|
openWorld: () => openWorld,
|
|
5659
6873
|
openWorldVersion: () => openWorldVersion,
|
|
6874
|
+
parseErrorBody: () => parseErrorBody,
|
|
5660
6875
|
parseSlugRef: () => parseSlugRef,
|
|
5661
6876
|
parseToolCallRecord: () => parseToolCallRecord,
|
|
5662
6877
|
parseTransform: () => parseTransform,
|
|
5663
6878
|
parseWorldTaskRefs: () => parseWorldTaskRefs,
|
|
6879
|
+
platformTimeoutMs: () => platformTimeoutMs,
|
|
5664
6880
|
preserveForm: () => preserveForm,
|
|
5665
6881
|
propose: () => propose,
|
|
5666
6882
|
pull: () => pull,
|
|
5667
6883
|
push: () => push,
|
|
6884
|
+
pushBranch: () => pushBranch,
|
|
5668
6885
|
pushSlug: () => pushSlug,
|
|
5669
6886
|
pyText: () => pyText,
|
|
5670
6887
|
queryRows: () => queryRows,
|
|
5671
6888
|
queryRowsSearch: () => queryRowsSearch,
|
|
5672
6889
|
readLocalMeta: () => readLocalMeta,
|
|
5673
6890
|
readToolCallRecords: () => readToolCallRecords,
|
|
6891
|
+
rebaseConflicts: () => rebaseConflicts,
|
|
5674
6892
|
redactActionArgs: () => redactActionArgs,
|
|
5675
6893
|
redactionOf: () => redactionOf,
|
|
6894
|
+
releaseConnection: () => releaseConnection,
|
|
5676
6895
|
resolveBrowserMode: () => resolveBrowserMode,
|
|
5677
6896
|
resolvePushSlug: () => resolvePushSlug,
|
|
5678
6897
|
roundForm: () => roundForm,
|
|
5679
6898
|
runSessions: () => runSessions,
|
|
6899
|
+
runSet: () => runSet,
|
|
5680
6900
|
runTask: () => runTask,
|
|
5681
6901
|
schemaFromSignature: () => schemaFromSignature,
|
|
6902
|
+
serializeCallBody: () => serializeCallBody,
|
|
5682
6903
|
sessionToolObservations: () => sessionToolObservations,
|
|
5683
6904
|
setEnvSecret: () => setEnvSecret,
|
|
5684
6905
|
shapeText: () => shapeText,
|
|
@@ -5690,6 +6911,7 @@ __export(worlds_exports, {
|
|
|
5690
6911
|
toolCallsFromObservations: () => toolCallsFromObservations,
|
|
5691
6912
|
uiEntryUrl: () => uiEntryUrl,
|
|
5692
6913
|
uiUrl: () => uiUrl,
|
|
6914
|
+
uncommittedPaths: () => uncommittedPaths,
|
|
5693
6915
|
updateTask: () => updateTask,
|
|
5694
6916
|
upsertRunConfig: () => upsertRunConfig,
|
|
5695
6917
|
validateTask: () => validateTask,
|
|
@@ -5709,19 +6931,29 @@ function resolveEnv(options) {
|
|
|
5709
6931
|
}
|
|
5710
6932
|
return { host: host.replace(/\/+$/, ""), publicKey, secretKey };
|
|
5711
6933
|
}
|
|
5712
|
-
|
|
5713
|
-
const {
|
|
5714
|
-
|
|
5715
|
-
|
|
5716
|
-
|
|
5717
|
-
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
}
|
|
5722
|
-
const
|
|
5723
|
-
if (
|
|
5724
|
-
|
|
6934
|
+
function parseErrorBody(text2, limit = 600) {
|
|
6935
|
+
const raw = { detail: text2.slice(0, limit), code: null };
|
|
6936
|
+
let parsed;
|
|
6937
|
+
try {
|
|
6938
|
+
parsed = JSON.parse(text2);
|
|
6939
|
+
} catch {
|
|
6940
|
+
return raw;
|
|
6941
|
+
}
|
|
6942
|
+
if (parsed === null || typeof parsed !== "object") return raw;
|
|
6943
|
+
const { message, code } = parsed;
|
|
6944
|
+
const stableCode = typeof code === "string" ? code : null;
|
|
6945
|
+
if (typeof message !== "string") return { ...raw, code: stableCode };
|
|
6946
|
+
if (stableCode === null)
|
|
6947
|
+
return { detail: message.slice(0, limit), code: null };
|
|
6948
|
+
return {
|
|
6949
|
+
detail: `${message} (${stableCode})`.slice(0, limit),
|
|
6950
|
+
code: stableCode
|
|
6951
|
+
};
|
|
6952
|
+
}
|
|
6953
|
+
async function apiRequest(options, method, path12, body, init2 = {}) {
|
|
6954
|
+
const reply = await new PlatformTransport(resolveEnv(options)).send(method, path12, body, init2);
|
|
6955
|
+
if (!reply.ok) throw new ApiError(reply.status, method, path12, reply.text);
|
|
6956
|
+
return JSON.parse(reply.text);
|
|
5725
6957
|
}
|
|
5726
6958
|
async function setEnvSecret(slug, key, value, options = {}) {
|
|
5727
6959
|
return apiRequest(
|
|
@@ -5791,6 +7023,19 @@ async function getRun(runId, options = {}) {
|
|
|
5791
7023
|
`/api/public/benchmark-containers/runs/${encodeURIComponent(runId)}`
|
|
5792
7024
|
);
|
|
5793
7025
|
}
|
|
7026
|
+
async function listRuns(filter = {}, options = {}) {
|
|
7027
|
+
const params = new URLSearchParams();
|
|
7028
|
+
if (filter.slug) params.set("slug", filter.slug);
|
|
7029
|
+
if (filter.status) params.set("status", filter.status);
|
|
7030
|
+
if (filter.limit !== void 0) params.set("limit", String(filter.limit));
|
|
7031
|
+
const qs = params.toString();
|
|
7032
|
+
const res = await apiRequest(
|
|
7033
|
+
options,
|
|
7034
|
+
"GET",
|
|
7035
|
+
`/api/public/benchmark-containers/runs${qs ? `?${qs}` : ""}`
|
|
7036
|
+
);
|
|
7037
|
+
return res.runs;
|
|
7038
|
+
}
|
|
5794
7039
|
async function waitForRun(runId, opts = {}) {
|
|
5795
7040
|
const deadline = Date.now() + (opts.timeoutMinutes ?? 45) * 6e4;
|
|
5796
7041
|
for (; ; ) {
|
|
@@ -5802,7 +7047,7 @@ async function waitForRun(runId, opts = {}) {
|
|
|
5802
7047
|
);
|
|
5803
7048
|
opts.onTick?.(run);
|
|
5804
7049
|
await new Promise(
|
|
5805
|
-
(
|
|
7050
|
+
(resolve7) => setTimeout(resolve7, (opts.intervalSeconds ?? 20) * 1e3)
|
|
5806
7051
|
);
|
|
5807
7052
|
}
|
|
5808
7053
|
}
|
|
@@ -5825,8 +7070,8 @@ function detectProvenance() {
|
|
|
5825
7070
|
}
|
|
5826
7071
|
if (!out.branch || !out.commit) {
|
|
5827
7072
|
try {
|
|
5828
|
-
const { execFileSync } = __require("child_process");
|
|
5829
|
-
const git = (args) =>
|
|
7073
|
+
const { execFileSync: execFileSync2 } = __require("child_process");
|
|
7074
|
+
const git = (args) => execFileSync2("git", args, {
|
|
5830
7075
|
encoding: "utf-8",
|
|
5831
7076
|
stdio: ["ignore", "pipe", "ignore"]
|
|
5832
7077
|
}).toString().trim();
|
|
@@ -5884,15 +7129,23 @@ async function resolveWorld(slugRef, slug, ref, pin, options) {
|
|
|
5884
7129
|
}
|
|
5885
7130
|
return world;
|
|
5886
7131
|
}
|
|
5887
|
-
var
|
|
7132
|
+
var ApiError, WorldTask, WorldSet;
|
|
5888
7133
|
var init_worlds = __esm({
|
|
5889
7134
|
"src/worlds/index.ts"() {
|
|
7135
|
+
init_transport();
|
|
7136
|
+
init_transport();
|
|
5890
7137
|
init_session();
|
|
7138
|
+
init_sessionList();
|
|
7139
|
+
init_sessionContract();
|
|
7140
|
+
init_taskRef();
|
|
5891
7141
|
init_tasks();
|
|
5892
7142
|
init_taskSessions();
|
|
5893
7143
|
init_taskRun();
|
|
7144
|
+
init_setRun();
|
|
7145
|
+
init_checkoutProvenance();
|
|
5894
7146
|
init_evals();
|
|
5895
7147
|
init_browser();
|
|
7148
|
+
init_browserReconnect();
|
|
5896
7149
|
init_hub();
|
|
5897
7150
|
init_validate();
|
|
5898
7151
|
init_describe();
|
|
@@ -5902,12 +7155,20 @@ var init_worlds = __esm({
|
|
|
5902
7155
|
init_migrate();
|
|
5903
7156
|
init_ingest();
|
|
5904
7157
|
init_sandbox();
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
7158
|
+
init_editSessions();
|
|
7159
|
+
init_dryRun();
|
|
7160
|
+
ApiError = class extends Error {
|
|
7161
|
+
constructor(status, method, path12, text2) {
|
|
7162
|
+
const parsed = parseErrorBody(text2);
|
|
7163
|
+
super(`${method} ${path12} -> ${status}: ${parsed.detail}`);
|
|
5908
7164
|
this.status = status;
|
|
7165
|
+
this.text = text2;
|
|
5909
7166
|
this.name = "ApiError";
|
|
7167
|
+
this.code = parsed.code;
|
|
5910
7168
|
}
|
|
7169
|
+
status;
|
|
7170
|
+
text;
|
|
7171
|
+
code;
|
|
5911
7172
|
};
|
|
5912
7173
|
WorldTask = class {
|
|
5913
7174
|
constructor(world, name, variant) {
|
|
@@ -5915,6 +7176,9 @@ var init_worlds = __esm({
|
|
|
5915
7176
|
this.name = name;
|
|
5916
7177
|
this.variant = variant;
|
|
5917
7178
|
}
|
|
7179
|
+
world;
|
|
7180
|
+
name;
|
|
7181
|
+
variant;
|
|
5918
7182
|
};
|
|
5919
7183
|
WorldSet = class {
|
|
5920
7184
|
constructor(slugRef, slug, ref, version, tasks, options) {
|
|
@@ -5925,6 +7189,12 @@ var init_worlds = __esm({
|
|
|
5925
7189
|
this.tasks = tasks;
|
|
5926
7190
|
this.options = options;
|
|
5927
7191
|
}
|
|
7192
|
+
slugRef;
|
|
7193
|
+
slug;
|
|
7194
|
+
ref;
|
|
7195
|
+
version;
|
|
7196
|
+
tasks;
|
|
7197
|
+
options;
|
|
5928
7198
|
task(variant) {
|
|
5929
7199
|
const hit = this.tasks.find(
|
|
5930
7200
|
(t) => t.variant === variant || t.name.includes(variant)
|
|
@@ -5948,6 +7218,7 @@ var init_worlds = __esm({
|
|
|
5948
7218
|
versionId: this.version.versionId,
|
|
5949
7219
|
reuseWarm: opts.reuseWarm,
|
|
5950
7220
|
surfaces: opts.surfaces,
|
|
7221
|
+
browserTier: opts.browserTier,
|
|
5951
7222
|
options: this.options
|
|
5952
7223
|
});
|
|
5953
7224
|
}
|
|
@@ -5975,23 +7246,53 @@ var init_worlds = __esm({
|
|
|
5975
7246
|
});
|
|
5976
7247
|
init_worlds();
|
|
5977
7248
|
export {
|
|
5978
|
-
|
|
7249
|
+
ApiError,
|
|
7250
|
+
BROWSER_GONE_PATTERNS,
|
|
7251
|
+
BROWSER_TIERS,
|
|
5979
7252
|
BrowserActionRecorder,
|
|
7253
|
+
BrowserReconnected,
|
|
7254
|
+
BrowserReconnector,
|
|
7255
|
+
BrowserUnrecoverable,
|
|
7256
|
+
CALL_BODY_LIMIT_BYTES,
|
|
7257
|
+
CALL_BODY_LIMIT_LABEL,
|
|
5980
7258
|
COMPUTER_USE_SPECS,
|
|
7259
|
+
CheckoutProvenance,
|
|
5981
7260
|
DEFAULT_BRANCH,
|
|
5982
7261
|
DEFAULT_VIEWPORT,
|
|
7262
|
+
DRY_RUN_AGENT,
|
|
7263
|
+
DRY_RUN_KIND,
|
|
7264
|
+
DetachedPushError,
|
|
7265
|
+
DryRunOutcome,
|
|
5983
7266
|
EVENT_BATCH_SIZE,
|
|
5984
7267
|
EVENT_FLUSH_INTERVAL_MS,
|
|
5985
7268
|
EVENT_MAX_RETRIES,
|
|
7269
|
+
EXPLORATORY_TASK,
|
|
7270
|
+
EXPLORATORY_TASK_SOURCE,
|
|
5986
7271
|
GatewayEvalsClient,
|
|
7272
|
+
HostedDryRunClient,
|
|
7273
|
+
IDLE_WARNING_MINUTES,
|
|
7274
|
+
NO_GRADER_REASON,
|
|
7275
|
+
PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
7276
|
+
PLATFORM_TIMEOUT_ENV,
|
|
7277
|
+
PlatformTransport,
|
|
5987
7278
|
PushSlugConflict,
|
|
7279
|
+
RECOVER_BUDGET_MS,
|
|
7280
|
+
SANDBOX_REQUEST_TIMEOUT_MS,
|
|
7281
|
+
SESSION_STATES,
|
|
7282
|
+
STATUS_WAIT_CAP_SECONDS,
|
|
5988
7283
|
STRIP_PREFIX,
|
|
5989
7284
|
SURFACE_KINDS,
|
|
7285
|
+
SecretScrubber,
|
|
5990
7286
|
TRANSFORMS,
|
|
5991
7287
|
TaskRun,
|
|
5992
7288
|
TaskSessions,
|
|
7289
|
+
TransportCause,
|
|
7290
|
+
UnreachableError,
|
|
7291
|
+
VERIFIER_REWARD_PREFIX,
|
|
5993
7292
|
WHITESPACE,
|
|
5994
7293
|
WorldBrowser,
|
|
7294
|
+
WorldCallTooLarge,
|
|
7295
|
+
WorldEditClient,
|
|
5995
7296
|
WorldSandboxClient,
|
|
5996
7297
|
WorldSession,
|
|
5997
7298
|
WorldSessionCallError,
|
|
@@ -6003,12 +7304,16 @@ export {
|
|
|
6003
7304
|
apiRequest,
|
|
6004
7305
|
applyTransforms,
|
|
6005
7306
|
archiveMode,
|
|
7307
|
+
assertBrowserTier,
|
|
7308
|
+
assertTaskRef,
|
|
6006
7309
|
attachManifest,
|
|
6007
7310
|
attachSession,
|
|
6008
7311
|
attachTask,
|
|
6009
7312
|
buildFileManifest,
|
|
6010
7313
|
buildSourceTarball,
|
|
6011
7314
|
captureToolCalls,
|
|
7315
|
+
checkoutIdentity,
|
|
7316
|
+
closeConnection,
|
|
6012
7317
|
collectArchiveRelPaths,
|
|
6013
7318
|
computeContentHash,
|
|
6014
7319
|
computerUseToolkit,
|
|
@@ -6022,13 +7327,18 @@ export {
|
|
|
6022
7327
|
getRun,
|
|
6023
7328
|
getTask,
|
|
6024
7329
|
hashForm,
|
|
7330
|
+
idleWarning,
|
|
6025
7331
|
ingest,
|
|
6026
7332
|
ingestToolCalls,
|
|
7333
|
+
isBrowserGone,
|
|
7334
|
+
isSandboxImportPending,
|
|
6027
7335
|
isTaskIdRef,
|
|
6028
7336
|
isTaskManifest,
|
|
6029
7337
|
isTaskSpec,
|
|
6030
7338
|
listEnvSecretKeys,
|
|
6031
7339
|
listRunConfigs,
|
|
7340
|
+
listRuns,
|
|
7341
|
+
listSessions,
|
|
6032
7342
|
listTaskSessions,
|
|
6033
7343
|
listTasks,
|
|
6034
7344
|
localTreeState,
|
|
@@ -6040,28 +7350,35 @@ export {
|
|
|
6040
7350
|
openTask,
|
|
6041
7351
|
openWorld,
|
|
6042
7352
|
openWorldVersion,
|
|
7353
|
+
parseErrorBody,
|
|
6043
7354
|
parseSlugRef,
|
|
6044
7355
|
parseToolCallRecord,
|
|
6045
7356
|
parseTransform,
|
|
6046
7357
|
parseWorldTaskRefs,
|
|
7358
|
+
platformTimeoutMs,
|
|
6047
7359
|
preserveForm,
|
|
6048
7360
|
propose,
|
|
6049
7361
|
pull,
|
|
6050
7362
|
push,
|
|
7363
|
+
pushBranch,
|
|
6051
7364
|
pushSlug,
|
|
6052
7365
|
pyText,
|
|
6053
7366
|
queryRows,
|
|
6054
7367
|
queryRowsSearch,
|
|
6055
7368
|
readLocalMeta,
|
|
6056
7369
|
readToolCallRecords,
|
|
7370
|
+
rebaseConflicts,
|
|
6057
7371
|
redactActionArgs,
|
|
6058
7372
|
redactionOf,
|
|
7373
|
+
releaseConnection,
|
|
6059
7374
|
resolveBrowserMode,
|
|
6060
7375
|
resolvePushSlug,
|
|
6061
7376
|
roundForm,
|
|
6062
7377
|
runSessions,
|
|
7378
|
+
runSet,
|
|
6063
7379
|
runTask,
|
|
6064
7380
|
schemaFromSignature,
|
|
7381
|
+
serializeCallBody,
|
|
6065
7382
|
sessionToolObservations,
|
|
6066
7383
|
setEnvSecret,
|
|
6067
7384
|
shapeText,
|
|
@@ -6073,6 +7390,7 @@ export {
|
|
|
6073
7390
|
toolCallsFromObservations,
|
|
6074
7391
|
uiEntryUrl,
|
|
6075
7392
|
uiUrl,
|
|
7393
|
+
uncommittedPaths,
|
|
6076
7394
|
updateTask,
|
|
6077
7395
|
upsertRunConfig,
|
|
6078
7396
|
validateTask,
|