@withgateway/sdk 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1128 -783
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1130 -785
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.js +47 -18
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +47 -18
- package/dist/files/index.mjs.map +1 -1
- package/dist/{index-mJhG3vZU.d.mts → index-Di9nNqOY.d.mts} +26 -3
- package/dist/{index-DUHmS74p.d.ts → index-LA-PMRJT.d.ts} +26 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +179 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +176 -43
- package/dist/index.mjs.map +1 -1
- package/dist/replay/index.d.mts +1 -1
- package/dist/replay/index.d.ts +1 -1
- package/dist/replay/index.js.map +1 -1
- package/dist/replay/index.mjs.map +1 -1
- package/dist/traces/index.js +47 -18
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +47 -18
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.d.mts +1 -1
- package/dist/tracing/index.d.ts +1 -1
- package/dist/tracing/index.js +1 -1
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +1 -1
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/worlds/index.d.mts +184 -85
- package/dist/worlds/index.d.ts +184 -85
- package/dist/worlds/index.js +176 -43
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +176 -43
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +1 -1
- package/runtime/gatewaysdk/environment/_bundle.py +4 -6
- package/runtime/gatewaysdk/environment/_world.py +24 -1
- package/runtime/gatewaysdk/environment/runtime.py +45 -2
- package/runtime/gatewaysdk/environment/schema/api.py +24 -3
- package/runtime/gatewaysdk/environment/schema/bundle_runtime.py +1 -0
- package/runtime/gatewaysdk/environment/schema/call_capture.py +13 -1
- package/runtime/gatewaysdk/environment/schema/call_log.py +46 -0
- package/runtime/gatewaysdk/environment/schema/call_redaction.py +6 -0
- package/runtime/gatewaysdk/environment/schema/compiler.py +4 -1
- package/runtime/gatewaysdk/environment/schema/conform.py +32 -8
- package/runtime/gatewaysdk/environment/schema/connector.py +5 -0
- package/runtime/gatewaysdk/environment/schema/connectors/custom/handlers.py +2 -1
- package/runtime/gatewaysdk/environment/schema/connectors/github/api/handlers.py +217 -58
- package/runtime/gatewaysdk/environment/schema/connectors/github/connector.toml +9 -19
- package/runtime/gatewaysdk/environment/schema/connectors/github/scenarios/default/seed/github_webhooks.json +10 -2
- package/runtime/gatewaysdk/environment/schema/connectors/github/tests/webhooks.json +47 -0
- package/runtime/gatewaysdk/environment/schema/connectors/github/world.json +21 -0
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/api/handlers.py +185 -18
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/connector.toml +29 -14
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/provenance.json +43 -12
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/scenarios/default/seed/jamf_webhooks.json +2 -2
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/scope.toml +4 -17
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/tests/webhooks.json +107 -0
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/vendor-openapi.json +1 -1
- package/runtime/gatewaysdk/environment/schema/connectors/linear/api/handlers.py +85 -1
- package/runtime/gatewaysdk/environment/schema/connectors/linear/connector.toml +19 -31
- package/runtime/gatewaysdk/environment/schema/connectors/linear/provenance.json +18 -8
- package/runtime/gatewaysdk/environment/schema/connectors/linear/scenarios/default/seed/webhooks.json +19 -3
- package/runtime/gatewaysdk/environment/schema/connectors/linear/tests/test_webhooks.py +71 -0
- package/runtime/gatewaysdk/environment/schema/database/guard.py +2 -1
- package/runtime/gatewaysdk/environment/schema/handler_errors.py +27 -1
- package/runtime/gatewaysdk/environment/schema/journal.py +4 -3
- package/runtime/gatewaysdk/environment/schema/local.py +1 -0
- package/runtime/gatewaysdk/environment/schema/openapi_schemas.py +20 -5
- package/runtime/gatewaysdk/environment/schema/platform.py +16 -219
- package/runtime/gatewaysdk/environment/schema/runtime.py +7 -0
- package/runtime/gatewaysdk/environment/schema/scaffold.py +2 -1
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/CONNECTORS.md +3 -3
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +19 -22
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +7 -9
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +3 -3
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +14 -11
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +36 -5
- package/runtime/gatewaysdk/environment/schema/snapshot.py +2 -2
- package/runtime/gatewaysdk/environment/schema/tools_world.py +19 -0
- package/runtime/gatewaysdk/environment/schema/verbs.py +6 -0
- package/runtime/gatewaysdk/environment/schema/webhooks.py +687 -0
- package/runtime/gatewaysdk/environment/schema/world_host.py +20 -3
- package/runtime/gatewaysdk/environment/schema/world_tests.py +74 -0
- package/skills/connector-schema-authoring/CONNECTORS.md +3 -3
- package/skills/connector-schema-authoring/SKILL.md +19 -22
- package/skills/connector-schema-authoring/connector-worlds.md +153 -11
- package/skills/connector-schema-authoring/world-schema.md +7 -6
- package/skills/world-data-ingestion/SKILL.md +7 -9
- package/skills/worlds-getting-started/SKILL.md +3 -3
- package/skills/worlds-getting-started/references/cli-mcp-map.md +14 -11
- package/skills/worlds-getting-started/references/gotchas.md +36 -5
package/dist/cli.mjs
CHANGED
|
@@ -367,11 +367,11 @@ var init_transport = __esm({
|
|
|
367
367
|
}
|
|
368
368
|
};
|
|
369
369
|
UnreachableError = class extends Error {
|
|
370
|
-
constructor(host, method,
|
|
371
|
-
super(`${method} ${
|
|
370
|
+
constructor(host, method, route2, failure2) {
|
|
371
|
+
super(`${method} ${route2}: no answer from ${host}: ${failure2.describe()}. ${failure2.next}`);
|
|
372
372
|
this.host = host;
|
|
373
373
|
this.method = method;
|
|
374
|
-
this.route =
|
|
374
|
+
this.route = route2;
|
|
375
375
|
this.failure = failure2;
|
|
376
376
|
this.name = "UnreachableError";
|
|
377
377
|
}
|
|
@@ -441,16 +441,16 @@ var init_transport = __esm({
|
|
|
441
441
|
budget(ownMs) {
|
|
442
442
|
return Math.max(ownMs ?? 0, this.timeoutMs);
|
|
443
443
|
}
|
|
444
|
-
async send(method,
|
|
444
|
+
async send(method, route2, body, opts = {}) {
|
|
445
445
|
const timeoutMs3 = this.budget(opts.timeoutMs);
|
|
446
|
-
return (opts.retry ?? RetryPolicy.NONE).run(() => this.once(method,
|
|
446
|
+
return (opts.retry ?? RetryPolicy.NONE).run(() => this.once(method, route2, body, timeoutMs3));
|
|
447
447
|
}
|
|
448
|
-
async once(method,
|
|
448
|
+
async once(method, route2, body, timeoutMs3) {
|
|
449
449
|
const payload = body === void 0 ? {} : { body: JSON.stringify(body) };
|
|
450
450
|
const controller = new AbortController();
|
|
451
451
|
const timer = setTimeout(() => controller.abort(), timeoutMs3);
|
|
452
452
|
try {
|
|
453
|
-
const res = await fetch(`${this.endpoint.host}${
|
|
453
|
+
const res = await fetch(`${this.endpoint.host}${route2}`, {
|
|
454
454
|
method,
|
|
455
455
|
headers: {
|
|
456
456
|
"content-type": "application/json",
|
|
@@ -463,7 +463,7 @@ var init_transport = __esm({
|
|
|
463
463
|
return { status: res.status, ok: res.ok, text: await res.text() };
|
|
464
464
|
} catch (error) {
|
|
465
465
|
const cause = controller.signal.aborted ? TransportCause.timeout(timeoutMs3) : TransportCause.of(error);
|
|
466
|
-
throw new UnreachableError(this.endpoint.host, method,
|
|
466
|
+
throw new UnreachableError(this.endpoint.host, method, route2, cause);
|
|
467
467
|
} finally {
|
|
468
468
|
clearTimeout(timer);
|
|
469
469
|
}
|
|
@@ -902,7 +902,7 @@ var init_browser = __esm({
|
|
|
902
902
|
}
|
|
903
903
|
async send(batch) {
|
|
904
904
|
const retries = this.opts.maxRetries ?? EVENT_MAX_RETRIES;
|
|
905
|
-
const
|
|
905
|
+
const sleep7 = this.opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
906
906
|
for (let attempt = 0; attempt < retries; attempt++) {
|
|
907
907
|
try {
|
|
908
908
|
const base = await this.resolveBase();
|
|
@@ -919,7 +919,7 @@ var init_browser = __esm({
|
|
|
919
919
|
);
|
|
920
920
|
return;
|
|
921
921
|
}
|
|
922
|
-
await
|
|
922
|
+
await sleep7(500 * 2 ** attempt);
|
|
923
923
|
}
|
|
924
924
|
}
|
|
925
925
|
}
|
|
@@ -1725,11 +1725,11 @@ var init_media = __esm({
|
|
|
1725
1725
|
status
|
|
1726
1726
|
);
|
|
1727
1727
|
}
|
|
1728
|
-
async send(method,
|
|
1729
|
-
const reply = await this.transport.send(method,
|
|
1728
|
+
async send(method, route2, body) {
|
|
1729
|
+
const reply = await this.transport.send(method, route2, body);
|
|
1730
1730
|
if (!reply.ok)
|
|
1731
1731
|
throw new MediaUploadError(
|
|
1732
|
-
`${method} ${
|
|
1732
|
+
`${method} ${route2} -> ${reply.status}`,
|
|
1733
1733
|
reply.status
|
|
1734
1734
|
);
|
|
1735
1735
|
return reply.text ? JSON.parse(reply.text) : {};
|
|
@@ -2082,7 +2082,7 @@ function click(button, count) {
|
|
|
2082
2082
|
modifiers: modifierChord(raw.text)
|
|
2083
2083
|
});
|
|
2084
2084
|
}
|
|
2085
|
-
var SCROLL_STEP_PX, NOT_EXECUTED, MAX_ERROR2, SCROLL_DIRECTIONS, MEMBERS, AnthropicComputer, AnthropicComputer20251124;
|
|
2085
|
+
var SCROLL_STEP_PX, NOT_EXECUTED, MAX_ERROR2, SCROLL_DIRECTIONS, IMAGE_PARTS, MEMBERS, AnthropicComputer, AnthropicComputer20251124;
|
|
2086
2086
|
var init_anthropic = __esm({
|
|
2087
2087
|
"src/worlds/nativeComputer/anthropic.ts"() {
|
|
2088
2088
|
"use strict";
|
|
@@ -2098,6 +2098,14 @@ var init_anthropic = __esm({
|
|
|
2098
2098
|
left: [-1, 0],
|
|
2099
2099
|
right: [1, 0]
|
|
2100
2100
|
};
|
|
2101
|
+
IMAGE_PARTS = {
|
|
2102
|
+
6: (data) => ({ type: "image-data", data, mediaType: "image/png" }),
|
|
2103
|
+
7: (data) => ({
|
|
2104
|
+
type: "file",
|
|
2105
|
+
mediaType: "image/png",
|
|
2106
|
+
data: { type: "data", data }
|
|
2107
|
+
})
|
|
2108
|
+
};
|
|
2101
2109
|
MEMBERS = {
|
|
2102
2110
|
screenshot: () => new ComputerAction("screenshot"),
|
|
2103
2111
|
zoom: (raw) => new ComputerAction("zoom", {
|
|
@@ -2207,15 +2215,17 @@ var init_anthropic = __esm({
|
|
|
2207
2215
|
];
|
|
2208
2216
|
return [{ type: "text", text: result.text ?? "OK" }];
|
|
2209
2217
|
}
|
|
2210
|
-
/** For `anthropic.tools.computerToolset_20260801(
|
|
2211
|
-
* (or `computer_20251124` with the legacy kind
|
|
2212
|
-
* and returns `{ type: "image", data }` or
|
|
2213
|
-
* into the tool result
|
|
2218
|
+
/** For `anthropic.tools.computerToolset_20260801(computer.aiSdk({ version: 7 }))`
|
|
2219
|
+
* (AI SDK 7 only), or `computer_20251124` with the legacy kind (AI SDK 6
|
|
2220
|
+
* and 7): `execute` runs one action and returns `{ type: "image", data }` or
|
|
2221
|
+
* text; `toModelOutput` turns that into the tool result in the part shape
|
|
2222
|
+
* of `options.version`. Calls run one at a time, and once a call fails the
|
|
2214
2223
|
* rest of that step's calls answer as not executed. */
|
|
2215
|
-
aiSdk() {
|
|
2224
|
+
aiSdk(options = {}) {
|
|
2225
|
+
const imagePart = _AnthropicComputer.imagePart(options);
|
|
2216
2226
|
let failedStep;
|
|
2217
|
-
const execute = (input,
|
|
2218
|
-
const step =
|
|
2227
|
+
const execute = (input, options2) => this.serial(async () => {
|
|
2228
|
+
const step = options2?.messages?.length;
|
|
2219
2229
|
if (step !== void 0 && step === failedStep)
|
|
2220
2230
|
throw new Error(NOT_EXECUTED);
|
|
2221
2231
|
try {
|
|
@@ -2227,7 +2237,7 @@ var init_anthropic = __esm({
|
|
|
2227
2237
|
});
|
|
2228
2238
|
return {
|
|
2229
2239
|
execute,
|
|
2230
|
-
toModelOutput: ({ output }) => _AnthropicComputer.
|
|
2240
|
+
toModelOutput: ({ output }) => _AnthropicComputer.modelOutput(output, imagePart)
|
|
2231
2241
|
};
|
|
2232
2242
|
}
|
|
2233
2243
|
static aiSdkOutput(result) {
|
|
@@ -2235,16 +2245,26 @@ var init_anthropic = __esm({
|
|
|
2235
2245
|
return { type: "image", data: result.image.toString("base64") };
|
|
2236
2246
|
return result.text ?? "OK";
|
|
2237
2247
|
}
|
|
2238
|
-
/**
|
|
2239
|
-
*
|
|
2240
|
-
|
|
2248
|
+
/** A screenshot as the image part of AI SDK `options.version`:
|
|
2249
|
+
* `image-data` for 6 (the default), `file` with `{ type: "data", data }`
|
|
2250
|
+
* for 7. */
|
|
2251
|
+
static aiSdkModelOutput(output, options = {}) {
|
|
2252
|
+
return _AnthropicComputer.modelOutput(
|
|
2253
|
+
output,
|
|
2254
|
+
_AnthropicComputer.imagePart(options)
|
|
2255
|
+
);
|
|
2256
|
+
}
|
|
2257
|
+
static imagePart({
|
|
2258
|
+
version = 6
|
|
2259
|
+
}) {
|
|
2260
|
+
if (Object.hasOwn(IMAGE_PARTS, version)) return IMAGE_PARTS[version];
|
|
2261
|
+
throw new Error(
|
|
2262
|
+
`unsupported AI SDK version ${version}; choose ${Object.keys(IMAGE_PARTS).join(" or ")}`
|
|
2263
|
+
);
|
|
2264
|
+
}
|
|
2265
|
+
static modelOutput(output, imagePart) {
|
|
2241
2266
|
if (typeof output === "string") return { type: "text", value: output };
|
|
2242
|
-
return {
|
|
2243
|
-
type: "content",
|
|
2244
|
-
value: [
|
|
2245
|
-
{ type: "image-data", data: output.data, mediaType: "image/png" }
|
|
2246
|
-
]
|
|
2247
|
-
};
|
|
2267
|
+
return { type: "content", value: [imagePart(output.data)] };
|
|
2248
2268
|
}
|
|
2249
2269
|
envelope(block2, content, isError = false) {
|
|
2250
2270
|
return {
|
|
@@ -2652,7 +2672,7 @@ var init_requestLedger = __esm({
|
|
|
2652
2672
|
"use strict";
|
|
2653
2673
|
init_worlds();
|
|
2654
2674
|
init_sessionContract();
|
|
2655
|
-
WORLD_REQUEST_VIAS = ["api", "ui", "tool"];
|
|
2675
|
+
WORLD_REQUEST_VIAS = ["api", "ui", "tool", "webhook"];
|
|
2656
2676
|
WorldRequestFilterError = class extends Error {
|
|
2657
2677
|
};
|
|
2658
2678
|
NOT_RECORDED = "This session's engine records no requests; only hosted World Host sessions do.";
|
|
@@ -3385,8 +3405,8 @@ var init_session2 = __esm({
|
|
|
3385
3405
|
const path51 = `/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/browser-events`;
|
|
3386
3406
|
const id = agentId ?? process.env.GATEWAY_AGENT_ID ?? `agent-${randomUUID().replace(/-/g, "").slice(0, 8)}`;
|
|
3387
3407
|
return new BrowserActionRecorder(
|
|
3388
|
-
async (
|
|
3389
|
-
await apiRequest(this.options, "POST", path51, { events });
|
|
3408
|
+
async (events2) => {
|
|
3409
|
+
await apiRequest(this.options, "POST", path51, { events: events2 });
|
|
3390
3410
|
},
|
|
3391
3411
|
id,
|
|
3392
3412
|
{
|
|
@@ -3584,13 +3604,13 @@ var init_session2 = __esm({
|
|
|
3584
3604
|
WorldRequestQuery.parse({ cursor: opts.cursor, limit: opts.limit ?? REQUEST_LOG_PAGE_MAX })
|
|
3585
3605
|
);
|
|
3586
3606
|
}
|
|
3587
|
-
page(
|
|
3607
|
+
page(route2, limit, cursor) {
|
|
3588
3608
|
const query2 = new URLSearchParams({ limit: String(limit) });
|
|
3589
3609
|
if (cursor) query2.set("cursor", cursor);
|
|
3590
3610
|
return apiRequest(
|
|
3591
3611
|
this.options,
|
|
3592
3612
|
"GET",
|
|
3593
|
-
`/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/${
|
|
3613
|
+
`/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/${route2}?${query2.toString()}`
|
|
3594
3614
|
);
|
|
3595
3615
|
}
|
|
3596
3616
|
/** The session's call log, oldest first: every tool call, seed, reset,
|
|
@@ -3817,12 +3837,12 @@ var init_taskGrades = __esm({
|
|
|
3817
3837
|
compact2({ sessionId, ...target })
|
|
3818
3838
|
);
|
|
3819
3839
|
}
|
|
3820
|
-
regrade(taskId,
|
|
3840
|
+
regrade(taskId, scope2 = {}) {
|
|
3821
3841
|
return apiRequest(
|
|
3822
3842
|
this.options,
|
|
3823
3843
|
"POST",
|
|
3824
3844
|
`${TASKS2}/${encodeURIComponent(taskId)}/regrade`,
|
|
3825
|
-
compact2({ ...
|
|
3845
|
+
compact2({ ...scope2 })
|
|
3826
3846
|
);
|
|
3827
3847
|
}
|
|
3828
3848
|
};
|
|
@@ -5258,7 +5278,7 @@ var require_package = __commonJS({
|
|
|
5258
5278
|
"package.json"(exports, module) {
|
|
5259
5279
|
module.exports = {
|
|
5260
5280
|
name: "@withgateway/sdk",
|
|
5261
|
-
version: "0.
|
|
5281
|
+
version: "0.6.0",
|
|
5262
5282
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
5263
5283
|
main: "./dist/index.js",
|
|
5264
5284
|
module: "./dist/index.mjs",
|
|
@@ -6040,13 +6060,13 @@ function reportFromResult(result) {
|
|
|
6040
6060
|
throw new Error(
|
|
6041
6061
|
`agent returned ${describeValue(result)}; ${RESULT_CONTRACT}`
|
|
6042
6062
|
);
|
|
6043
|
-
const { report, ...extra } = result;
|
|
6044
|
-
if (
|
|
6045
|
-
if (typeof
|
|
6063
|
+
const { report: report2, ...extra } = result;
|
|
6064
|
+
if (report2 === void 0 || report2 === null) return { report: null, extra };
|
|
6065
|
+
if (typeof report2 !== "string")
|
|
6046
6066
|
throw new Error(
|
|
6047
|
-
`agent returned a report of type ${describeValue(
|
|
6067
|
+
`agent returned a report of type ${describeValue(report2)}; ${RESULT_CONTRACT}`
|
|
6048
6068
|
);
|
|
6049
|
-
return { report, extra };
|
|
6069
|
+
return { report: report2, extra };
|
|
6050
6070
|
}
|
|
6051
6071
|
async function refuseUnreadTools(live) {
|
|
6052
6072
|
try {
|
|
@@ -6215,10 +6235,10 @@ var init_taskRun = __esm({
|
|
|
6215
6235
|
this.outcome.notes = run.notes;
|
|
6216
6236
|
this.files.writeManifest(run.manifest);
|
|
6217
6237
|
await this.callAgent(agent, run);
|
|
6218
|
-
const
|
|
6219
|
-
this.outcome.grade = await this.live.grade(
|
|
6238
|
+
const report2 = this.outcome.report;
|
|
6239
|
+
this.outcome.grade = await this.live.grade(report2 !== null ? { report: report2 } : {});
|
|
6220
6240
|
this.files.writeJson("grades.json", this.outcome.grade);
|
|
6221
|
-
if (
|
|
6241
|
+
if (report2) this.files.write("report.md", report2);
|
|
6222
6242
|
}
|
|
6223
6243
|
async callAgent(agent, run) {
|
|
6224
6244
|
try {
|
|
@@ -6533,6 +6553,112 @@ var init_requestLog = __esm({
|
|
|
6533
6553
|
}
|
|
6534
6554
|
});
|
|
6535
6555
|
|
|
6556
|
+
// src/worlds/webhooks.ts
|
|
6557
|
+
async function listWebhooks(options, sessionId, page = {}) {
|
|
6558
|
+
const query2 = new URLSearchParams({
|
|
6559
|
+
after: String(page.after ?? 0),
|
|
6560
|
+
limit: String(page.limit ?? WORLD_WEBHOOK_PAGE_MAX),
|
|
6561
|
+
tail: String(page.tail ?? false)
|
|
6562
|
+
});
|
|
6563
|
+
if (page.epoch) query2.set("epoch", page.epoch);
|
|
6564
|
+
return apiRequest(options, "GET", `${route(sessionId)}?${query2.toString()}`);
|
|
6565
|
+
}
|
|
6566
|
+
var WORLD_WEBHOOK_PAGE_MAX, FORWARD_TIMEOUT_MS, ERROR_CHARS, route, WorldWebhookForwarder;
|
|
6567
|
+
var init_webhooks = __esm({
|
|
6568
|
+
"src/worlds/webhooks.ts"() {
|
|
6569
|
+
"use strict";
|
|
6570
|
+
init_worlds();
|
|
6571
|
+
WORLD_WEBHOOK_PAGE_MAX = 100;
|
|
6572
|
+
FORWARD_TIMEOUT_MS = 1e4;
|
|
6573
|
+
ERROR_CHARS = 500;
|
|
6574
|
+
route = (sessionId) => `/api/public/world-sessions/${encodeURIComponent(sessionId)}/webhooks`;
|
|
6575
|
+
WorldWebhookForwarder = class {
|
|
6576
|
+
constructor(options, sessionId, forwardTo, opts = {}) {
|
|
6577
|
+
this.options = options;
|
|
6578
|
+
this.sessionId = sessionId;
|
|
6579
|
+
this.forwardTo = forwardTo;
|
|
6580
|
+
this.send = opts.fetch ?? fetch;
|
|
6581
|
+
}
|
|
6582
|
+
options;
|
|
6583
|
+
sessionId;
|
|
6584
|
+
forwardTo;
|
|
6585
|
+
after = 0;
|
|
6586
|
+
epoch = null;
|
|
6587
|
+
answers = [];
|
|
6588
|
+
send;
|
|
6589
|
+
get cursor() {
|
|
6590
|
+
return this.after;
|
|
6591
|
+
}
|
|
6592
|
+
/** Where forwarding begins: the deliveries the session still holds (`replay`), or only those it sends from now. */
|
|
6593
|
+
async start(replay) {
|
|
6594
|
+
if (replay) return null;
|
|
6595
|
+
const page = await this.poll([], { tail: true, limit: 1 });
|
|
6596
|
+
this.follow(page);
|
|
6597
|
+
return page;
|
|
6598
|
+
}
|
|
6599
|
+
/** One poll: the answers held so far sent, the next page forwarded. A poll that fails keeps its answers for the next. */
|
|
6600
|
+
async round() {
|
|
6601
|
+
const page = await this.withAnswers((answers) => this.poll(answers));
|
|
6602
|
+
const forwarded = [];
|
|
6603
|
+
for (const delivery of page.deliveries) {
|
|
6604
|
+
const answer = await this.forward(delivery);
|
|
6605
|
+
this.answers.push(answer);
|
|
6606
|
+
forwarded.push({ delivery, answer });
|
|
6607
|
+
}
|
|
6608
|
+
this.follow(page);
|
|
6609
|
+
return { page, forwarded };
|
|
6610
|
+
}
|
|
6611
|
+
/** Sends the answers still held; the cursor stays, so a delivery this poll returns is forwarded by the next round. */
|
|
6612
|
+
async settle() {
|
|
6613
|
+
if (this.answers.length === 0) return 0;
|
|
6614
|
+
const page = await this.withAnswers((answers) => this.poll(answers, { limit: 1 }));
|
|
6615
|
+
return page.answered;
|
|
6616
|
+
}
|
|
6617
|
+
follow(page) {
|
|
6618
|
+
this.after = page.next;
|
|
6619
|
+
this.epoch = page.epoch;
|
|
6620
|
+
}
|
|
6621
|
+
async withAnswers(poll) {
|
|
6622
|
+
const answers = this.answers.splice(0, WORLD_WEBHOOK_PAGE_MAX);
|
|
6623
|
+
try {
|
|
6624
|
+
return await poll(answers);
|
|
6625
|
+
} catch (error) {
|
|
6626
|
+
this.answers.unshift(...answers);
|
|
6627
|
+
throw error;
|
|
6628
|
+
}
|
|
6629
|
+
}
|
|
6630
|
+
poll(answers, opts = {}) {
|
|
6631
|
+
return apiRequest(this.options, "POST", route(this.sessionId), {
|
|
6632
|
+
after: this.after,
|
|
6633
|
+
epoch: this.epoch,
|
|
6634
|
+
tail: opts.tail ?? false,
|
|
6635
|
+
limit: opts.limit ?? WORLD_WEBHOOK_PAGE_MAX,
|
|
6636
|
+
subscriptions: false,
|
|
6637
|
+
answers
|
|
6638
|
+
});
|
|
6639
|
+
}
|
|
6640
|
+
async forward(delivery) {
|
|
6641
|
+
const started = Date.now();
|
|
6642
|
+
try {
|
|
6643
|
+
const reply = await this.send(this.forwardTo, {
|
|
6644
|
+
method: "POST",
|
|
6645
|
+
headers: delivery.headers,
|
|
6646
|
+
body: delivery.payload,
|
|
6647
|
+
redirect: "manual",
|
|
6648
|
+
signal: AbortSignal.timeout(FORWARD_TIMEOUT_MS)
|
|
6649
|
+
});
|
|
6650
|
+
await reply.arrayBuffer().catch(() => void 0);
|
|
6651
|
+
if (reply.status < 100 || reply.status > 599) throw new Error("the receiver answered an invalid HTTP status");
|
|
6652
|
+
return { id: delivery.id, status: reply.status, durationMs: Date.now() - started, error: null };
|
|
6653
|
+
} catch (error) {
|
|
6654
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
6655
|
+
return { id: delivery.id, status: 0, durationMs: Date.now() - started, error: message.slice(0, ERROR_CHARS) };
|
|
6656
|
+
}
|
|
6657
|
+
}
|
|
6658
|
+
};
|
|
6659
|
+
}
|
|
6660
|
+
});
|
|
6661
|
+
|
|
6536
6662
|
// src/worlds/checkoutTarget.ts
|
|
6537
6663
|
import * as fs2 from "fs";
|
|
6538
6664
|
import * as path3 from "path";
|
|
@@ -7343,20 +7469,20 @@ var init_hub = __esm({
|
|
|
7343
7469
|
function fmtScore(score) {
|
|
7344
7470
|
return score === null ? "no score" : score.toFixed(3);
|
|
7345
7471
|
}
|
|
7346
|
-
function buildMarkdown(
|
|
7472
|
+
function buildMarkdown(report2, minScore, source2) {
|
|
7347
7473
|
const lines = [];
|
|
7348
7474
|
lines.push(
|
|
7349
|
-
`### World validation ${
|
|
7475
|
+
`### World validation ${report2.ok ? "passed" : "failed"} \u2014 \`${report2.slug}@${report2.branch}\``
|
|
7350
7476
|
);
|
|
7351
7477
|
lines.push("");
|
|
7352
7478
|
const commitLink = source2?.repoUrl && source2?.commit ? `[\`${source2.commit.slice(0, 12)}\`](${source2.repoUrl}/commit/${source2.commit})` : null;
|
|
7353
7479
|
lines.push(
|
|
7354
|
-
`Ran the pull request's own world source` + (commitLink ? ` (${commitLink} on \`${
|
|
7480
|
+
`Ran the pull request's own world source` + (commitLink ? ` (${commitLink} on \`${report2.branch}\`` : ` (`) + `${commitLink ? ", " : ""}pinned as \`${report2.contentHash.slice(0, 12)}\`) through run config **${report2.runConfig.name}**` + (minScore !== null ? `, gating at score \u2265 ${minScore}.` : ".")
|
|
7355
7481
|
);
|
|
7356
7482
|
lines.push("");
|
|
7357
7483
|
lines.push("| Model | Status | Score | Run |");
|
|
7358
7484
|
lines.push("| --- | --- | ---: | --- |");
|
|
7359
|
-
for (const run of
|
|
7485
|
+
for (const run of report2.runs) {
|
|
7360
7486
|
const r = run.report;
|
|
7361
7487
|
const link = r?.url ? `[open](${r.url})` : "\u2014";
|
|
7362
7488
|
const status = run.failure ? `\u274C ${run.failure}` : `\u2705 ${r?.status ?? "COMPLETED"}`;
|
|
@@ -7364,7 +7490,7 @@ function buildMarkdown(report, minScore, source2) {
|
|
|
7364
7490
|
`| \`${run.model}\` | ${status} | ${fmtScore(r?.score ?? null)} | ${link} |`
|
|
7365
7491
|
);
|
|
7366
7492
|
}
|
|
7367
|
-
const taskRows =
|
|
7493
|
+
const taskRows = report2.runs.flatMap(
|
|
7368
7494
|
(run) => (run.report?.samples ?? []).map((sample3) => ({
|
|
7369
7495
|
model: run.model,
|
|
7370
7496
|
task: sample3.task ?? "?",
|
|
@@ -7457,9 +7583,9 @@ async function validateWorld(dir, opts) {
|
|
|
7457
7583
|
} catch {
|
|
7458
7584
|
projectId = null;
|
|
7459
7585
|
}
|
|
7460
|
-
const fallbackUrl = (
|
|
7461
|
-
if (
|
|
7462
|
-
const evaluationId =
|
|
7586
|
+
const fallbackUrl = (report2) => {
|
|
7587
|
+
if (report2.url) return report2.url;
|
|
7588
|
+
const evaluationId = report2.evaluations[0]?.id;
|
|
7463
7589
|
return projectId && evaluationId ? `${host}/project/${projectId}/environment/runs/${encodeURIComponent(evaluationId)}` : null;
|
|
7464
7590
|
};
|
|
7465
7591
|
const runs = [];
|
|
@@ -7474,28 +7600,28 @@ async function validateWorld(dir, opts) {
|
|
|
7474
7600
|
continue;
|
|
7475
7601
|
}
|
|
7476
7602
|
progress(`waiting on ${run.model} (run ${run.runId})\u2026`);
|
|
7477
|
-
let
|
|
7603
|
+
let report2 = null;
|
|
7478
7604
|
let failure2 = null;
|
|
7479
7605
|
try {
|
|
7480
|
-
|
|
7606
|
+
report2 = await waitForRun(run.runId, {
|
|
7481
7607
|
timeoutMinutes: opts.timeoutMinutes ?? 45,
|
|
7482
7608
|
options,
|
|
7483
7609
|
onTick: (r) => progress(
|
|
7484
7610
|
`\u2026${run.model}: ${r.status.toLowerCase()} (${r.shardsCompleted ?? 0}/${r.parallelism} shards)`
|
|
7485
7611
|
)
|
|
7486
7612
|
});
|
|
7487
|
-
|
|
7488
|
-
if (
|
|
7489
|
-
failure2 =
|
|
7613
|
+
report2 = { ...report2, url: fallbackUrl(report2) };
|
|
7614
|
+
if (report2.status.toUpperCase() !== "COMPLETED") {
|
|
7615
|
+
failure2 = report2.status;
|
|
7490
7616
|
} else if (minScore !== null) {
|
|
7491
|
-
if (
|
|
7492
|
-
else if (
|
|
7493
|
-
failure2 = `score ${fmtScore(
|
|
7617
|
+
if (report2.score === null) failure2 = "completed without a score";
|
|
7618
|
+
else if (report2.score < minScore)
|
|
7619
|
+
failure2 = `score ${fmtScore(report2.score)} < ${minScore}`;
|
|
7494
7620
|
}
|
|
7495
7621
|
} catch (error) {
|
|
7496
7622
|
failure2 = error instanceof Error ? error.message : String(error);
|
|
7497
7623
|
}
|
|
7498
|
-
runs.push({ model: run.model, runId: run.runId, report, failure: failure2 });
|
|
7624
|
+
runs.push({ model: run.model, runId: run.runId, report: report2, failure: failure2 });
|
|
7499
7625
|
}
|
|
7500
7626
|
const base = {
|
|
7501
7627
|
ok: runs.length > 0 && runs.every((r) => r.failure === null),
|
|
@@ -8814,8 +8940,8 @@ async function runtime(creds, request2, opts = {}) {
|
|
|
8814
8940
|
throw new CliError(
|
|
8815
8941
|
"This needs the schema runtime (the CLI bundles it) or platform credentials (`gateway auth login`). " + localRuntimeReason()
|
|
8816
8942
|
);
|
|
8817
|
-
const
|
|
8818
|
-
const res = await new PlatformTransport(creds).send("POST",
|
|
8943
|
+
const route2 = "/api/public/worlds/runtime";
|
|
8944
|
+
const res = await new PlatformTransport(creds).send("POST", route2, request2, {
|
|
8819
8945
|
timeoutMs: opts.timeoutMs ?? RUNTIME_TIMEOUT_MS
|
|
8820
8946
|
});
|
|
8821
8947
|
let payload = null;
|
|
@@ -8827,12 +8953,12 @@ async function runtime(creds, request2, opts = {}) {
|
|
|
8827
8953
|
const detail = detailFrom(payload);
|
|
8828
8954
|
if (detail) throw new BridgeRejected(detail);
|
|
8829
8955
|
if (!res.ok)
|
|
8830
|
-
throw new CliError(`POST ${
|
|
8831
|
-
if (payload === null) throw new CliError(`POST ${
|
|
8956
|
+
throw new CliError(`POST ${route2} (${request2.command}) -> ${res.status}: ${res.text.slice(0, 600)}`, 1);
|
|
8957
|
+
if (payload === null) throw new CliError(`POST ${route2} (${request2.command}) returned non-JSON`, 1);
|
|
8832
8958
|
return payload;
|
|
8833
8959
|
}
|
|
8834
|
-
function withoutFiles(
|
|
8835
|
-
const { files: _files, ...rest } =
|
|
8960
|
+
function withoutFiles(report2) {
|
|
8961
|
+
const { files: _files, ...rest } = report2;
|
|
8836
8962
|
return rest;
|
|
8837
8963
|
}
|
|
8838
8964
|
function sortedJson(value, indent = 2) {
|
|
@@ -9347,7 +9473,7 @@ async function forEachLimited(items, limit, fn) {
|
|
|
9347
9473
|
if (failure2) throw failure2;
|
|
9348
9474
|
}
|
|
9349
9475
|
async function waitForBatch(client5, batchId, opts = {}) {
|
|
9350
|
-
const
|
|
9476
|
+
const sleep7 = opts.sleep ?? client5.sleep;
|
|
9351
9477
|
let delay = opts.initialDelayMs ?? 1e3;
|
|
9352
9478
|
let last = "";
|
|
9353
9479
|
for (; ; ) {
|
|
@@ -9360,7 +9486,7 @@ async function waitForBatch(client5, batchId, opts = {}) {
|
|
|
9360
9486
|
if (isSettled(status)) return status;
|
|
9361
9487
|
if (opts.deadlineMs !== void 0 && (opts.now ?? Date.now)() >= opts.deadlineMs)
|
|
9362
9488
|
return status;
|
|
9363
|
-
await
|
|
9489
|
+
await sleep7(delay);
|
|
9364
9490
|
delay = Math.min(1e4, Math.round(delay * 1.5));
|
|
9365
9491
|
}
|
|
9366
9492
|
}
|
|
@@ -9404,10 +9530,10 @@ var init_batches = __esm({
|
|
|
9404
9530
|
sleepMs = (ms) => new Promise((resolve32) => setTimeout(resolve32, ms));
|
|
9405
9531
|
slugOf = (world) => world.split("@", 1)[0];
|
|
9406
9532
|
WorldDataApi = class {
|
|
9407
|
-
constructor(creds, slug,
|
|
9533
|
+
constructor(creds, slug, sleep7 = sleepMs) {
|
|
9408
9534
|
this.creds = creds;
|
|
9409
9535
|
this.slug = slug;
|
|
9410
|
-
this.sleep =
|
|
9536
|
+
this.sleep = sleep7;
|
|
9411
9537
|
this.base = `/api/public/worlds/${encodeURIComponent(slug)}/data`;
|
|
9412
9538
|
}
|
|
9413
9539
|
creds;
|
|
@@ -9873,25 +9999,25 @@ async function ingest(world, records2, options = {}) {
|
|
|
9873
9999
|
const scratch = fs11.mkdtempSync(path11.join(os2.tmpdir(), "gateway-ingest-"));
|
|
9874
10000
|
try {
|
|
9875
10001
|
const pulled = await pull2(world, path11.join(scratch, slug), options);
|
|
9876
|
-
let
|
|
10002
|
+
let report2;
|
|
9877
10003
|
let projected;
|
|
9878
10004
|
if (rows === null) {
|
|
9879
10005
|
const proven = await ingestLocalToolCalls2(pulled.dir, records2, { redact: "off", dryRun: true, mode, map }, creds);
|
|
9880
|
-
|
|
10006
|
+
report2 = reportOf(world, proven, redact2);
|
|
9881
10007
|
projected = proven.projected ?? {};
|
|
9882
10008
|
} else {
|
|
9883
10009
|
const proven = await checkLocalWorldData2(pulled.dir, rows, creds);
|
|
9884
|
-
|
|
10010
|
+
report2 = transformReport(world, records2.length, rows, stderr, { dryRun, redact: redact2, changed: false, kind: proven.kind, entityCounts: proven.entity_counts });
|
|
9885
10011
|
projected = rows;
|
|
9886
10012
|
}
|
|
9887
|
-
|
|
9888
|
-
if (dryRun ||
|
|
10013
|
+
report2.dryRun = dryRun;
|
|
10014
|
+
if (dryRun || report2.refusals.length || !Object.keys(projected).length) return report2;
|
|
9889
10015
|
const { pushRows: pushRows2 } = await Promise.resolve().then(() => (init_push(), push_exports));
|
|
9890
10016
|
const status = await pushRows2(creds, slug, projected, { mode, redact: redact2, message: options.message });
|
|
9891
|
-
|
|
9892
|
-
|
|
9893
|
-
if (status.entityCounts)
|
|
9894
|
-
return
|
|
10017
|
+
report2.batch = status;
|
|
10018
|
+
report2.changed = status.state === "applied" || status.state === "published";
|
|
10019
|
+
if (status.entityCounts) report2.entityCounts = status.entityCounts;
|
|
10020
|
+
return report2;
|
|
9895
10021
|
} finally {
|
|
9896
10022
|
fs11.rmSync(scratch, { recursive: true, force: true });
|
|
9897
10023
|
}
|
|
@@ -10052,7 +10178,7 @@ var init_dryRun = __esm({
|
|
|
10052
10178
|
/** Poll until the run settles or `timeoutSeconds` pass; the last verdict either way. */
|
|
10053
10179
|
async settle(runId, opts) {
|
|
10054
10180
|
const now = opts.now ?? Date.now;
|
|
10055
|
-
const
|
|
10181
|
+
const sleep7 = opts.sleep ?? ((ms) => new Promise((resolve32) => setTimeout(resolve32, ms)));
|
|
10056
10182
|
const deadline = now() + opts.timeoutSeconds * 1e3;
|
|
10057
10183
|
for (; ; ) {
|
|
10058
10184
|
const budget = Math.floor(
|
|
@@ -10062,7 +10188,7 @@ var init_dryRun = __esm({
|
|
|
10062
10188
|
const verdict = await this.status(runId, budget);
|
|
10063
10189
|
if (verdict.settled || now() >= deadline) return verdict;
|
|
10064
10190
|
opts.onProgress?.(verdict);
|
|
10065
|
-
if (now() - asked < 1e3) await
|
|
10191
|
+
if (now() - asked < 1e3) await sleep7(1e3);
|
|
10066
10192
|
}
|
|
10067
10193
|
}
|
|
10068
10194
|
};
|
|
@@ -10181,6 +10307,7 @@ __export(worlds_exports, {
|
|
|
10181
10307
|
VERIFIER_REWARD_PREFIX: () => VERIFIER_REWARD_PREFIX,
|
|
10182
10308
|
WHITESPACE: () => WHITESPACE,
|
|
10183
10309
|
WORLD_REQUEST_VIAS: () => WORLD_REQUEST_VIAS,
|
|
10310
|
+
WORLD_WEBHOOK_PAGE_MAX: () => WORLD_WEBHOOK_PAGE_MAX,
|
|
10184
10311
|
WorldBrowser: () => WorldBrowser,
|
|
10185
10312
|
WorldCallTooLarge: () => WorldCallTooLarge,
|
|
10186
10313
|
WorldEditClient: () => WorldEditClient,
|
|
@@ -10199,6 +10326,7 @@ __export(worlds_exports, {
|
|
|
10199
10326
|
WorldSurfaceUnavailable: () => WorldSurfaceUnavailable,
|
|
10200
10327
|
WorldTask: () => WorldTask,
|
|
10201
10328
|
WorldToolsUnread: () => WorldToolsUnread,
|
|
10329
|
+
WorldWebhookForwarder: () => WorldWebhookForwarder,
|
|
10202
10330
|
WriteTreeFilter: () => WriteTreeFilter,
|
|
10203
10331
|
aggregateTaskGrade: () => aggregateTaskGrade,
|
|
10204
10332
|
apiRequest: () => apiRequest,
|
|
@@ -10246,6 +10374,7 @@ __export(worlds_exports, {
|
|
|
10246
10374
|
listSessions: () => listSessions,
|
|
10247
10375
|
listTaskSessions: () => listTaskSessions,
|
|
10248
10376
|
listTasks: () => listTasks,
|
|
10377
|
+
listWebhooks: () => listWebhooks,
|
|
10249
10378
|
localTreeState: () => localTreeState,
|
|
10250
10379
|
messageOf: () => messageOf,
|
|
10251
10380
|
migrateProjectWorlds: () => migrateProjectWorlds,
|
|
@@ -10548,6 +10677,7 @@ var init_worlds = __esm({
|
|
|
10548
10677
|
init_surfaceDescriptor();
|
|
10549
10678
|
init_requestLog();
|
|
10550
10679
|
init_requestLedger();
|
|
10680
|
+
init_webhooks();
|
|
10551
10681
|
init_browserReconnect();
|
|
10552
10682
|
init_nativeComputer();
|
|
10553
10683
|
init_hub();
|
|
@@ -10739,9 +10869,9 @@ function resolveCredentials(hostFlag, secretKeyFlag) {
|
|
|
10739
10869
|
);
|
|
10740
10870
|
return { host, publicKey, secretKey };
|
|
10741
10871
|
}
|
|
10742
|
-
async function api(creds, method,
|
|
10743
|
-
const reply = await new PlatformTransport(creds).send(method,
|
|
10744
|
-
if (!reply.ok) throw new ApiError2(reply.status, method,
|
|
10872
|
+
async function api(creds, method, route2, body, init2 = {}) {
|
|
10873
|
+
const reply = await new PlatformTransport(creds).send(method, route2, body, init2);
|
|
10874
|
+
if (!reply.ok) throw new ApiError2(reply.status, method, route2, reply.text);
|
|
10745
10875
|
return reply.text ? JSON.parse(reply.text) : {};
|
|
10746
10876
|
}
|
|
10747
10877
|
function printJson(ctx, value) {
|
|
@@ -10757,12 +10887,12 @@ var init_config = __esm({
|
|
|
10757
10887
|
STORED_FIELDS = ["host", "public_key", "api_key"];
|
|
10758
10888
|
ENV_FILE_FORM = "GATEWAY_ENV_FILE=path loads a KEY=value file first: `KEY = value`, quoted values, `export KEY=value` and `#` comments are all accepted; the shell's environment wins.";
|
|
10759
10889
|
ApiError2 = class extends CliError {
|
|
10760
|
-
constructor(status, method,
|
|
10890
|
+
constructor(status, method, route2, text2) {
|
|
10761
10891
|
const body = parseErrorBody(text2, status);
|
|
10762
|
-
super(`${method} ${
|
|
10892
|
+
super(`${method} ${route2} -> ${status}: ${body.detail}`, 1);
|
|
10763
10893
|
this.status = status;
|
|
10764
10894
|
this.method = method;
|
|
10765
|
-
this.route =
|
|
10895
|
+
this.route = route2;
|
|
10766
10896
|
this.text = text2;
|
|
10767
10897
|
this.code = body.code;
|
|
10768
10898
|
}
|
|
@@ -10871,27 +11001,27 @@ function packagedFiles(name) {
|
|
|
10871
11001
|
return files;
|
|
10872
11002
|
}
|
|
10873
11003
|
function installSkill(destination, name, force = false) {
|
|
10874
|
-
const
|
|
11004
|
+
const report2 = { written: [], unchanged: [], conflicts: [] };
|
|
10875
11005
|
const planned = [];
|
|
10876
11006
|
for (const [relative6, source2] of Object.entries(packagedFiles(name))) {
|
|
10877
11007
|
const content = fs17.readFileSync(source2);
|
|
10878
11008
|
const target = path16.join(destination, relative6);
|
|
10879
|
-
if (fs17.existsSync(target) && fs17.readFileSync(target).equals(content))
|
|
10880
|
-
else if (fs17.existsSync(target) && !force)
|
|
11009
|
+
if (fs17.existsSync(target) && fs17.readFileSync(target).equals(content)) report2.unchanged.push(relative6);
|
|
11010
|
+
else if (fs17.existsSync(target) && !force) report2.conflicts.push(relative6);
|
|
10881
11011
|
else {
|
|
10882
11012
|
planned.push([target, content]);
|
|
10883
|
-
|
|
11013
|
+
report2.written.push(relative6);
|
|
10884
11014
|
}
|
|
10885
11015
|
}
|
|
10886
|
-
if (
|
|
10887
|
-
|
|
10888
|
-
return
|
|
11016
|
+
if (report2.conflicts.length) {
|
|
11017
|
+
report2.written = [];
|
|
11018
|
+
return report2;
|
|
10889
11019
|
}
|
|
10890
11020
|
for (const [target, content] of planned) {
|
|
10891
11021
|
fs17.mkdirSync(path16.dirname(target), { recursive: true });
|
|
10892
11022
|
fs17.writeFileSync(target, content);
|
|
10893
11023
|
}
|
|
10894
|
-
return
|
|
11024
|
+
return report2;
|
|
10895
11025
|
}
|
|
10896
11026
|
function printOrInstallSkill(ctx, name, install, force) {
|
|
10897
11027
|
const text2 = skillText(name);
|
|
@@ -10899,15 +11029,15 @@ function printOrInstallSkill(ctx, name, install, force) {
|
|
|
10899
11029
|
process.stdout.write(text2);
|
|
10900
11030
|
return;
|
|
10901
11031
|
}
|
|
10902
|
-
const
|
|
10903
|
-
if (
|
|
11032
|
+
const report2 = installSkill(install, name, force);
|
|
11033
|
+
if (report2.conflicts.length) {
|
|
10904
11034
|
ctx.stderr("Refusing to overwrite files that differ from the packaged skill:");
|
|
10905
|
-
for (const relative6 of
|
|
11035
|
+
for (const relative6 of report2.conflicts) ctx.stderr(` ${path16.join(install, relative6)}`);
|
|
10906
11036
|
ctx.stderr("Pass --force to replace them.");
|
|
10907
11037
|
return 1;
|
|
10908
11038
|
}
|
|
10909
|
-
for (const relative6 of
|
|
10910
|
-
for (const relative6 of
|
|
11039
|
+
for (const relative6 of report2.written) ctx.stdout(`wrote ${path16.join(install, relative6)}`);
|
|
11040
|
+
for (const relative6 of report2.unchanged) ctx.stdout(`unchanged ${path16.join(install, relative6)}`);
|
|
10911
11041
|
const step = NEXT_STEPS[name];
|
|
10912
11042
|
if (step) ctx.stdout(`next: ${step}`);
|
|
10913
11043
|
}
|
|
@@ -11013,8 +11143,8 @@ function credentials(args) {
|
|
|
11013
11143
|
function worldsOptions(creds) {
|
|
11014
11144
|
return { host: creds.host, publicKey: creds.publicKey, secretKey: creds.secretKey };
|
|
11015
11145
|
}
|
|
11016
|
-
async function rawRequest(creds, method,
|
|
11017
|
-
const reply = await new PlatformTransport(creds).send(method,
|
|
11146
|
+
async function rawRequest(creds, method, route2, body) {
|
|
11147
|
+
const reply = await new PlatformTransport(creds).send(method, route2, body);
|
|
11018
11148
|
return {
|
|
11019
11149
|
...reply,
|
|
11020
11150
|
json: () => reply.text ? JSON.parse(reply.text) : {}
|
|
@@ -11114,13 +11244,13 @@ var init_shared = __esm({
|
|
|
11114
11244
|
codePoints = (cell) => [...cell].length;
|
|
11115
11245
|
sleep4 = (ms) => new Promise((resolve32) => setTimeout(resolve32, ms));
|
|
11116
11246
|
SECRET_PROMPT = "Paste the value, then Ctrl-D:";
|
|
11117
|
-
REQUEST_LOG_NOTES = "The ledger holds the calls the platform brokered: tool calls, seeds, grades, resets. --requests appends the\nsession's entries in its world's request ledger as kind \"request\" lines, oldest first: every request the\nworld received (via api, ui or
|
|
11247
|
+
REQUEST_LOG_NOTES = "The ledger holds the calls the platform brokered: tool calls, seeds, grades, resets. --requests appends the\nsession's entries in its world's request ledger as kind \"request\" lines, oldest first: every request the\nworld received (via api, ui, tool or webhook) with its status, sizes and timing, kept after the session stops. Bodies\nstay in the ledger: `gateway worlds requests show <slug> <result.requestId>` reads one entry's. Reading them\nrecords nothing in the session. A session the World Host did not serve records none, and stderr says so; a\nsession the platform does not answer for fails the command (exit 1) and nothing is written.";
|
|
11118
11248
|
}
|
|
11119
11249
|
});
|
|
11120
11250
|
|
|
11121
11251
|
// src/cli/platform/connector.ts
|
|
11122
|
-
import * as
|
|
11123
|
-
import * as
|
|
11252
|
+
import * as fs32 from "fs";
|
|
11253
|
+
import * as path25 from "path";
|
|
11124
11254
|
function isCarriedTemplatePath(relative6) {
|
|
11125
11255
|
const slash = relative6.indexOf("/");
|
|
11126
11256
|
if (slash === -1) return WORLD_ARTIFACT_FILES.has(relative6);
|
|
@@ -11136,8 +11266,8 @@ function splitTemplateFiles(files) {
|
|
|
11136
11266
|
function walk2(root) {
|
|
11137
11267
|
const out = [];
|
|
11138
11268
|
const visit = (rel) => {
|
|
11139
|
-
const abs = rel ?
|
|
11140
|
-
for (const entry of
|
|
11269
|
+
const abs = rel ? path25.join(root, rel) : root;
|
|
11270
|
+
for (const entry of fs32.readdirSync(abs, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
11141
11271
|
const childRel = rel ? `${rel}/${entry.name}` : entry.name;
|
|
11142
11272
|
if (entry.isSymbolicLink()) continue;
|
|
11143
11273
|
if (entry.isDirectory()) {
|
|
@@ -11154,14 +11284,14 @@ function walk2(root) {
|
|
|
11154
11284
|
return out;
|
|
11155
11285
|
}
|
|
11156
11286
|
function readText3(root, relative6) {
|
|
11157
|
-
const bytes =
|
|
11287
|
+
const bytes = fs32.readFileSync(path25.join(root, relative6));
|
|
11158
11288
|
const text2 = bytes.toString("utf8");
|
|
11159
11289
|
if (Buffer.from(text2, "utf8").length !== bytes.length || text2.includes("\uFFFD"))
|
|
11160
11290
|
return null;
|
|
11161
11291
|
return text2;
|
|
11162
11292
|
}
|
|
11163
11293
|
function isBuildOutput2(relative6) {
|
|
11164
|
-
const name =
|
|
11294
|
+
const name = path25.basename(relative6);
|
|
11165
11295
|
if (BUILD_OUTPUT_NAMES.has(name)) return true;
|
|
11166
11296
|
for (const suffix of BUILD_OUTPUT_SUFFIXES)
|
|
11167
11297
|
if (name.endsWith(suffix)) return true;
|
|
@@ -11176,7 +11306,7 @@ function templatePath(relative6) {
|
|
|
11176
11306
|
return ROOT_CARRIED_FILES.has(relative6) ? relative6 : null;
|
|
11177
11307
|
if (parts2[0] === "schema") {
|
|
11178
11308
|
const name = parts2[parts2.length - 1];
|
|
11179
|
-
if (parts2.length !== 2 || !SUPPORTING_SUFFIXES.has(
|
|
11309
|
+
if (parts2.length !== 2 || !SUPPORTING_SUFFIXES.has(path25.extname(name)) || GENERATED_NAMES.has(name))
|
|
11180
11310
|
return null;
|
|
11181
11311
|
return name;
|
|
11182
11312
|
}
|
|
@@ -11185,7 +11315,7 @@ function templatePath(relative6) {
|
|
|
11185
11315
|
return null;
|
|
11186
11316
|
}
|
|
11187
11317
|
function collectTemplate(directory) {
|
|
11188
|
-
if (
|
|
11318
|
+
if (fs32.existsSync(path25.join(directory, "world.json"))) {
|
|
11189
11319
|
const files2 = {};
|
|
11190
11320
|
for (const relative6 of walk2(directory)) {
|
|
11191
11321
|
const text2 = readText3(directory, relative6);
|
|
@@ -11198,7 +11328,7 @@ function collectTemplate(directory) {
|
|
|
11198
11328
|
}
|
|
11199
11329
|
return { source: "template", files: files2, skipped: [] };
|
|
11200
11330
|
}
|
|
11201
|
-
if (!
|
|
11331
|
+
if (!fs32.existsSync(path25.join(directory, "schema", "world.json")))
|
|
11202
11332
|
throw new CliError(
|
|
11203
11333
|
`${directory}: neither a connector template (world.json) nor a world (schema/world.json)`,
|
|
11204
11334
|
1
|
|
@@ -11257,7 +11387,7 @@ function registerConnectorCommands(root) {
|
|
|
11257
11387
|
run: async (args, ctx) => {
|
|
11258
11388
|
const dir = args.positionals[0];
|
|
11259
11389
|
const gathered = collectTemplate(dir);
|
|
11260
|
-
const slug = arg.str(args, "slug") ??
|
|
11390
|
+
const slug = arg.str(args, "slug") ?? path25.basename(path25.resolve(dir));
|
|
11261
11391
|
const creds = credentials(args);
|
|
11262
11392
|
const files = Object.fromEntries(
|
|
11263
11393
|
Object.entries(gathered.files).map(([p, content]) => [
|
|
@@ -11372,7 +11502,7 @@ function registerConnectorCommands(root) {
|
|
|
11372
11502
|
run: async (args, ctx) => {
|
|
11373
11503
|
const slug = args.positionals[0];
|
|
11374
11504
|
const out = arg.str(args, "out") ?? slug;
|
|
11375
|
-
if (
|
|
11505
|
+
if (fs32.existsSync(out) && (!fs32.statSync(out).isDirectory() || fs32.readdirSync(out).length > 0))
|
|
11376
11506
|
throw new CliError(`${out}: must be a new or empty directory`, 1);
|
|
11377
11507
|
const pulled = await api(
|
|
11378
11508
|
credentials(args),
|
|
@@ -11386,9 +11516,9 @@ function registerConnectorCommands(root) {
|
|
|
11386
11516
|
`Refusing a template path outside the directory: ${relative6}`,
|
|
11387
11517
|
1
|
|
11388
11518
|
);
|
|
11389
|
-
const target =
|
|
11390
|
-
|
|
11391
|
-
|
|
11519
|
+
const target = path25.join(out, relative6);
|
|
11520
|
+
fs32.mkdirSync(path25.dirname(target), { recursive: true });
|
|
11521
|
+
fs32.writeFileSync(target, files[relative6]);
|
|
11392
11522
|
ctx.stdout(relative6);
|
|
11393
11523
|
}
|
|
11394
11524
|
ctx.stderr(
|
|
@@ -11551,8 +11681,8 @@ var init_connector = __esm({
|
|
|
11551
11681
|
|
|
11552
11682
|
// src/files/index.ts
|
|
11553
11683
|
import { createHash as createHash13 } from "crypto";
|
|
11554
|
-
import * as
|
|
11555
|
-
import * as
|
|
11684
|
+
import * as fs34 from "fs";
|
|
11685
|
+
import * as path27 from "path";
|
|
11556
11686
|
import { Readable, Transform } from "stream";
|
|
11557
11687
|
import { pipeline } from "stream/promises";
|
|
11558
11688
|
function isDriveRef(value) {
|
|
@@ -11592,9 +11722,9 @@ async function readFile(options = {}, filePath, limits = {}) {
|
|
|
11592
11722
|
async function downloadFile(options = {}, filePath, outPath, onProgress) {
|
|
11593
11723
|
const file = await getFile(options, filePath);
|
|
11594
11724
|
const res = await openDownload(file.url);
|
|
11595
|
-
|
|
11725
|
+
fs34.mkdirSync(path27.dirname(path27.resolve(outPath)), { recursive: true });
|
|
11596
11726
|
const source2 = Readable.fromWeb(res.body);
|
|
11597
|
-
await pipeline(source2, counting((n) => onProgress?.(n, file.sizeBytes)),
|
|
11727
|
+
await pipeline(source2, counting((n) => onProgress?.(n, file.sizeBytes)), fs34.createWriteStream(outPath));
|
|
11598
11728
|
return { ...file, out: outPath };
|
|
11599
11729
|
}
|
|
11600
11730
|
async function requestUpload(options = {}, body) {
|
|
@@ -11605,18 +11735,18 @@ async function confirmUpload(options = {}, fileId, ok = true) {
|
|
|
11605
11735
|
}
|
|
11606
11736
|
async function sha256Base64(localPath) {
|
|
11607
11737
|
const hash = createHash13("sha256");
|
|
11608
|
-
for await (const chunk of
|
|
11738
|
+
for await (const chunk of fs34.createReadStream(localPath)) hash.update(chunk);
|
|
11609
11739
|
return hash.digest("base64");
|
|
11610
11740
|
}
|
|
11611
11741
|
function contentTypeFor(name) {
|
|
11612
|
-
return CONTENT_TYPES[
|
|
11742
|
+
return CONTENT_TYPES[path27.extname(name).toLowerCase()] ?? "application/octet-stream";
|
|
11613
11743
|
}
|
|
11614
|
-
function counting(
|
|
11744
|
+
function counting(report2) {
|
|
11615
11745
|
let seen = 0;
|
|
11616
11746
|
return new Transform({
|
|
11617
11747
|
transform(chunk, _encoding, callback) {
|
|
11618
11748
|
seen += chunk.length;
|
|
11619
|
-
|
|
11749
|
+
report2(seen);
|
|
11620
11750
|
callback(null, chunk);
|
|
11621
11751
|
}
|
|
11622
11752
|
});
|
|
@@ -11636,7 +11766,7 @@ async function putPresigned(uploadUrl, body, headers) {
|
|
|
11636
11766
|
if (!res.ok) throw new Error(`upload failed: storage answered HTTP ${res.status}: ${(await res.text()).slice(0, 300)}`);
|
|
11637
11767
|
}
|
|
11638
11768
|
async function uploadFile(options = {}, localPath, targetPath, upload = {}) {
|
|
11639
|
-
const stat =
|
|
11769
|
+
const stat = fs34.statSync(localPath);
|
|
11640
11770
|
if (!stat.isFile()) throw new Error(`${localPath} is not a file`);
|
|
11641
11771
|
if (stat.size === 0) throw new Error(`${localPath} is empty; the drive refuses zero-byte uploads`);
|
|
11642
11772
|
const contentType = upload.contentType ?? contentTypeFor(localPath);
|
|
@@ -11644,7 +11774,7 @@ async function uploadFile(options = {}, localPath, targetPath, upload = {}) {
|
|
|
11644
11774
|
const target = drivePath(targetPath);
|
|
11645
11775
|
const granted = await requestUpload(options, { path: target, contentLength: stat.size, contentType, sha256: sha2563, ...upload.overwrite ? { overwrite: true } : {} });
|
|
11646
11776
|
try {
|
|
11647
|
-
const stream =
|
|
11777
|
+
const stream = fs34.createReadStream(localPath).pipe(counting((n) => upload.onProgress?.(n, stat.size)));
|
|
11648
11778
|
await putPresigned(granted.uploadUrl, Readable.toWeb(stream), { contentType, contentLength: stat.size, sha256: sha2563 });
|
|
11649
11779
|
} catch (error) {
|
|
11650
11780
|
await confirmUpload(options, granted.fileId, false).catch(() => void 0);
|
|
@@ -11879,8 +12009,8 @@ var init_publicUrl = __esm({
|
|
|
11879
12009
|
});
|
|
11880
12010
|
|
|
11881
12011
|
// src/cli/runtime/schemaOpenApi.ts
|
|
11882
|
-
import * as
|
|
11883
|
-
import * as
|
|
12012
|
+
import * as fs35 from "fs";
|
|
12013
|
+
import * as path28 from "path";
|
|
11884
12014
|
function platformCredentials(hostFlag, why) {
|
|
11885
12015
|
try {
|
|
11886
12016
|
return resolveCredentials(hostFlag);
|
|
@@ -11917,21 +12047,21 @@ async function initFromOpenApi(args, ctx, dir) {
|
|
|
11917
12047
|
...arg.list(args, "exclude").length ? { exclude: arg.list(args, "exclude") } : {},
|
|
11918
12048
|
...name ? { name } : {}
|
|
11919
12049
|
};
|
|
11920
|
-
const
|
|
11921
|
-
if (!
|
|
12050
|
+
const report2 = await runtime(creds, request2);
|
|
12051
|
+
if (!report2.written) {
|
|
11922
12052
|
ctx.stdout(
|
|
11923
|
-
sortedJson({ status: "ok", written: false, plan:
|
|
12053
|
+
sortedJson({ status: "ok", written: false, plan: report2.plan }, 0)
|
|
11924
12054
|
);
|
|
11925
12055
|
return;
|
|
11926
12056
|
}
|
|
11927
|
-
const files =
|
|
12057
|
+
const files = report2.files ?? [];
|
|
11928
12058
|
if (!files.length)
|
|
11929
12059
|
throw new CliError(
|
|
11930
12060
|
"The importer compiled the world but returned no files",
|
|
11931
12061
|
1
|
|
11932
12062
|
);
|
|
11933
12063
|
writeWorldFiles(dir, files);
|
|
11934
|
-
const { files: _files, ...rest } =
|
|
12064
|
+
const { files: _files, ...rest } = report2;
|
|
11935
12065
|
ctx.stdout(sortedJson({ ...rest, kind: "schema", api: "connector.toml" }, 0));
|
|
11936
12066
|
}
|
|
11937
12067
|
var OPENAPI_MAX_BYTES, FROM_OPENAPI_FLAGS, OpenApiSourceArg, LocalSource, UrlSource, DriveSource;
|
|
@@ -11995,12 +12125,12 @@ var init_schemaOpenApi = __esm({
|
|
|
11995
12125
|
};
|
|
11996
12126
|
LocalSource = class extends OpenApiSourceArg {
|
|
11997
12127
|
async bytes() {
|
|
11998
|
-
const abs =
|
|
11999
|
-
if (!
|
|
12128
|
+
const abs = path28.resolve(this.spelled);
|
|
12129
|
+
if (!fs35.existsSync(abs) || !fs35.statSync(abs).isFile())
|
|
12000
12130
|
throw new CliError(`--from-openapi ${this.spelled}: no such file`);
|
|
12001
|
-
const { size } =
|
|
12131
|
+
const { size } = fs35.statSync(abs);
|
|
12002
12132
|
if (size > OPENAPI_MAX_BYTES) throw this.tooBig(size);
|
|
12003
|
-
return
|
|
12133
|
+
return fs35.readFileSync(abs);
|
|
12004
12134
|
}
|
|
12005
12135
|
};
|
|
12006
12136
|
UrlSource = class extends OpenApiSourceArg {
|
|
@@ -12094,8 +12224,8 @@ __export(schema_exports, {
|
|
|
12094
12224
|
uiSection: () => uiSection,
|
|
12095
12225
|
withRowCounts: () => withRowCounts
|
|
12096
12226
|
});
|
|
12097
|
-
import * as
|
|
12098
|
-
import * as
|
|
12227
|
+
import * as fs36 from "fs";
|
|
12228
|
+
import * as path29 from "path";
|
|
12099
12229
|
function uiSection(toml) {
|
|
12100
12230
|
const start = /^\[ui\]\s*$/m.exec(toml);
|
|
12101
12231
|
if (!start) return {};
|
|
@@ -12112,16 +12242,16 @@ function uiSection(toml) {
|
|
|
12112
12242
|
return out;
|
|
12113
12243
|
}
|
|
12114
12244
|
function declareUi(dir) {
|
|
12115
|
-
const spec =
|
|
12116
|
-
if (!
|
|
12245
|
+
const spec = path29.join(dir, "connector.toml");
|
|
12246
|
+
if (!fs36.existsSync(spec))
|
|
12117
12247
|
throw new CliError(
|
|
12118
12248
|
`${dir} has no connector.toml: a ui shows the world's routes, and this world declares none. Add the vendor's routes first (\`gateway worlds connector route add\`), or start from a connector template.`
|
|
12119
12249
|
);
|
|
12120
|
-
const text2 =
|
|
12250
|
+
const text2 = fs36.readFileSync(spec, "utf8");
|
|
12121
12251
|
if (/^\[ui\]\s*$/m.test(text2)) return false;
|
|
12122
12252
|
const firstRoute = /^\[\[operations\]\]/m.exec(text2);
|
|
12123
12253
|
const next = firstRoute ? text2.slice(0, firstRoute.index) + UI_SECTION + "\n" + text2.slice(firstRoute.index) : text2.replace(/\n*$/, "\n") + "\n" + UI_SECTION;
|
|
12124
|
-
|
|
12254
|
+
fs36.writeFileSync(spec, next);
|
|
12125
12255
|
return true;
|
|
12126
12256
|
}
|
|
12127
12257
|
async function listTemplates(creds) {
|
|
@@ -12370,7 +12500,7 @@ function registerSchemaCommands(schema) {
|
|
|
12370
12500
|
],
|
|
12371
12501
|
notes: "The world is a gateway-world/1 tree: schema/world.json (entities), gateway-env.toml ([schema], [tools],\n[[tasks]]), tools/handlers.py, verifiers/*.sql, and connector.toml + api/handlers.py for its API surface.\nA shipped template arrives with its routes; a custom world declares its own with\n`gateway worlds connector route add`, which creates connector.toml on the first route. The output's\n`next` lists the commands in order.\nHave a vendor's Swagger/OpenAPI document and no world yet? `--from-openapi <path|drive:<path>|url>`\nwrites both from it: keyed schemas become entities, path+method pairs become routes; `--plan-only`\npreviews, `--include '/repos/{owner}/{repo}/issues*'` narrows a big spec. `connector conform` then\nchecks the served world back against the same document.",
|
|
12372
12502
|
run: async (args, ctx) => {
|
|
12373
|
-
const dir =
|
|
12503
|
+
const dir = path29.resolve(args.positionals[0]);
|
|
12374
12504
|
if (arg.str(args, "from-openapi")) return initFromOpenApi(args, ctx, dir);
|
|
12375
12505
|
assertEmptyTarget(dir);
|
|
12376
12506
|
const connector = arg.str(args, "connector") ?? "custom";
|
|
@@ -12382,7 +12512,7 @@ function registerSchemaCommands(schema) {
|
|
|
12382
12512
|
);
|
|
12383
12513
|
const hostFlag = arg.str(args, "host");
|
|
12384
12514
|
const workspace = connector.startsWith(WORKSPACE_PREFIX);
|
|
12385
|
-
let
|
|
12515
|
+
let report2;
|
|
12386
12516
|
let commit = null;
|
|
12387
12517
|
if (workspace) {
|
|
12388
12518
|
const slug = connector.slice(WORKSPACE_PREFIX.length);
|
|
@@ -12395,36 +12525,36 @@ function registerSchemaCommands(schema) {
|
|
|
12395
12525
|
const pulled = await pullWorkspaceTemplate(creds, slug);
|
|
12396
12526
|
commit = pulled.commit;
|
|
12397
12527
|
const { carried: carried2, contract } = splitTemplateFiles(pulled.files);
|
|
12398
|
-
|
|
12528
|
+
report2 = await runtime(creds, {
|
|
12399
12529
|
command: "init-template-files",
|
|
12400
12530
|
connector: slug,
|
|
12401
12531
|
files: contract,
|
|
12402
12532
|
...name ? { name } : {}
|
|
12403
12533
|
});
|
|
12404
|
-
|
|
12534
|
+
report2.files = [...report2.files ?? [], ...carried2];
|
|
12405
12535
|
} else {
|
|
12406
12536
|
const creds = localRuntime() ? null : platformCredentials2(
|
|
12407
12537
|
hostFlag,
|
|
12408
12538
|
`${connector} is a shipped template and scaffolds offline with the bundled runtime, but ${localRuntimeReason()} Without it the platform scaffolds it.`
|
|
12409
12539
|
);
|
|
12410
|
-
|
|
12540
|
+
report2 = await runtime(creds, {
|
|
12411
12541
|
command: "init-template",
|
|
12412
12542
|
connector,
|
|
12413
12543
|
...name ? { name } : {},
|
|
12414
12544
|
...withExampleTool ? { with_example_tool: true } : {}
|
|
12415
12545
|
});
|
|
12416
12546
|
}
|
|
12417
|
-
const files =
|
|
12547
|
+
const files = report2.files ?? [];
|
|
12418
12548
|
if (!files.length)
|
|
12419
12549
|
throw new CliError(
|
|
12420
12550
|
"The runtime compiled the world but returned no files",
|
|
12421
12551
|
1
|
|
12422
12552
|
);
|
|
12423
12553
|
writeWorldFiles(dir, files);
|
|
12424
|
-
const hasRoutes =
|
|
12554
|
+
const hasRoutes = fs36.existsSync(path29.join(dir, "connector.toml"));
|
|
12425
12555
|
const out = {
|
|
12426
12556
|
status: "ok",
|
|
12427
|
-
domain:
|
|
12557
|
+
domain: report2.domain,
|
|
12428
12558
|
kind: "schema",
|
|
12429
12559
|
api: hasRoutes ? "connector.toml" : null,
|
|
12430
12560
|
next: initNextSteps(args.positionals[0], { hasRoutes, blank: connector === "custom" })
|
|
@@ -12456,9 +12586,9 @@ function registerSchemaCommands(schema) {
|
|
|
12456
12586
|
notes: "With the bundled runtime (a python3 on this machine) the world is checked in place: its handlers are\nimported and every declared tool bound (`handler_execution.status: ok`), the verifiers run over the\ninitial state (`verifiers.<name>.initial_score`), and each `[dependencies]` entry with a `path` is\nopened beside it so a cross-world verifier runs too. On the platform the handlers report `not_run`.\n`tools` (top level and under handler_execution) is the declared handlers; `handler_execution.served`\nis every name `worlds call` answers: the handlers and a dependency's `alias.tool` (a route answers over HTTP).\nA stale tree says whether `schema compile` will succeed or refuse (rows written against the old contract).\nThe handler pass also reads every tools/*.py statically: a `store.<name>` off the store API is refused at\nfile:line with the available methods, before any handler is imported.\n" + STORE_API_NOTE
|
|
12457
12587
|
} : {},
|
|
12458
12588
|
run: async (args, ctx) => {
|
|
12459
|
-
const dir =
|
|
12589
|
+
const dir = path29.resolve(args.positionals[0]);
|
|
12460
12590
|
const creds = credentialsForRuntime(arg.str(args, "host"));
|
|
12461
|
-
const
|
|
12591
|
+
const report2 = await runtime(
|
|
12462
12592
|
creds,
|
|
12463
12593
|
command2 === "compile" ? { command: "compile", ...worldPayload(dir) } : {
|
|
12464
12594
|
command: "validate",
|
|
@@ -12466,9 +12596,9 @@ function registerSchemaCommands(schema) {
|
|
|
12466
12596
|
...localRuntime() ? { execute: true } : {}
|
|
12467
12597
|
}
|
|
12468
12598
|
);
|
|
12469
|
-
if (command2 === "compile" &&
|
|
12470
|
-
writeWorldFiles(dir,
|
|
12471
|
-
ctx.stdout(sortedJson(withoutFiles(
|
|
12599
|
+
if (command2 === "compile" && report2.files?.length)
|
|
12600
|
+
writeWorldFiles(dir, report2.files);
|
|
12601
|
+
ctx.stdout(sortedJson(withoutFiles(report2), 0));
|
|
12472
12602
|
}
|
|
12473
12603
|
});
|
|
12474
12604
|
}
|
|
@@ -12486,7 +12616,7 @@ function registerSchemaCommands(schema) {
|
|
|
12486
12616
|
],
|
|
12487
12617
|
notes: "`gateway worlds describe <dir|slug>` is the same view with row counts, and works on a platform slug.",
|
|
12488
12618
|
run: async (args, ctx) => {
|
|
12489
|
-
const dir =
|
|
12619
|
+
const dir = path29.resolve(args.positionals[0]);
|
|
12490
12620
|
const creds = credentialsForRuntime(arg.str(args, "host"));
|
|
12491
12621
|
const description = await describeLocalWorld(dir, creds);
|
|
12492
12622
|
if (arg.bool(args, "json"))
|
|
@@ -12525,19 +12655,19 @@ function registerSchemaCommands(schema) {
|
|
|
12525
12655
|
flags: [HOST_FLAG2],
|
|
12526
12656
|
notes: "Writes ui/static/{index.html, app.js, contract.json}: a dependency-free page that lists, reads, creates,\nupdates and deletes every entity through the world's own routes, with foreign keys linked. `schema compile`\nregenerates it as the contract changes; set `[ui] generated = false` to hand-write the directory instead.\n`worlds serve` mounts it at /__ui/; `worlds session open --surface ui,browser` serves it on the session's\nui origin and `worlds session browse` drives it. A world with no connector.toml has no routes for a ui to\ncall and is refused.",
|
|
12527
12657
|
run: async (args, ctx) => {
|
|
12528
|
-
const dir =
|
|
12658
|
+
const dir = path29.resolve(args.positionals[0]);
|
|
12529
12659
|
const declared = declareUi(dir);
|
|
12530
12660
|
const creds = credentialsForRuntime(arg.str(args, "host"));
|
|
12531
|
-
const
|
|
12661
|
+
const report2 = await runtime(creds, {
|
|
12532
12662
|
command: "compile",
|
|
12533
12663
|
files: readWorldFiles(dir)
|
|
12534
12664
|
});
|
|
12535
|
-
if (
|
|
12665
|
+
if (report2.files?.length) writeWorldFiles(dir, report2.files);
|
|
12536
12666
|
const ui = uiSection(
|
|
12537
|
-
|
|
12667
|
+
fs36.readFileSync(path29.join(dir, "connector.toml"), "utf8")
|
|
12538
12668
|
);
|
|
12539
12669
|
const staticDir = ui.static ?? "ui/static";
|
|
12540
|
-
const files = (
|
|
12670
|
+
const files = (report2.files ?? []).map((f) => f.path).filter((p) => p.startsWith(`${staticDir}/`));
|
|
12541
12671
|
ctx.stdout(
|
|
12542
12672
|
sortedJson(
|
|
12543
12673
|
{
|
|
@@ -12549,7 +12679,7 @@ function registerSchemaCommands(schema) {
|
|
|
12549
12679
|
generated: ui.generated !== "false"
|
|
12550
12680
|
},
|
|
12551
12681
|
files,
|
|
12552
|
-
domain:
|
|
12682
|
+
domain: report2.domain
|
|
12553
12683
|
},
|
|
12554
12684
|
0
|
|
12555
12685
|
)
|
|
@@ -12589,14 +12719,14 @@ function registerSchemaCommands(schema) {
|
|
|
12589
12719
|
from: arg.str(args, "from") ?? "captures",
|
|
12590
12720
|
...write ? { write: true } : {}
|
|
12591
12721
|
});
|
|
12592
|
-
const
|
|
12593
|
-
const changes =
|
|
12594
|
-
const compared = Object.values(
|
|
12722
|
+
const report2 = res.report ?? {};
|
|
12723
|
+
const changes = report2.changes ?? [];
|
|
12724
|
+
const compared = Object.values(report2.entities ?? {}).reduce(
|
|
12595
12725
|
(a, b) => a + b,
|
|
12596
12726
|
0
|
|
12597
12727
|
);
|
|
12598
12728
|
ctx.stdout(
|
|
12599
|
-
`reconciled from ${
|
|
12729
|
+
`reconciled from ${report2.source ?? "captures"}: ${compared} captured rows compared, ${changes.length} changes`
|
|
12600
12730
|
);
|
|
12601
12731
|
for (const c of changes)
|
|
12602
12732
|
ctx.stdout(` ${c.entity}.${c.field} ${c.change} ${c.detail}`);
|
|
@@ -12638,7 +12768,7 @@ var init_schema = __esm({
|
|
|
12638
12768
|
...description,
|
|
12639
12769
|
where: "local",
|
|
12640
12770
|
path: dir,
|
|
12641
|
-
on_platform: `gateway worlds describe ${
|
|
12771
|
+
on_platform: `gateway worlds describe ${path29.basename(dir)}@main`
|
|
12642
12772
|
});
|
|
12643
12773
|
enumValue = (value) => typeof value === "string" ? value : JSON.stringify(value);
|
|
12644
12774
|
}
|
|
@@ -15747,13 +15877,13 @@ var Pacer = class {
|
|
|
15747
15877
|
/** Waits until the interval since the tool's last call has passed; resolves to the
|
|
15748
15878
|
* seconds waited. `sleep`/`clock` are injectable for tests. */
|
|
15749
15879
|
async wait(name, intervalMs, opts = {}) {
|
|
15750
|
-
const
|
|
15880
|
+
const sleep7 = opts.sleep ?? ((seconds) => new Promise((resolve32) => setTimeout(resolve32, seconds * 1e3)));
|
|
15751
15881
|
const clock = opts.clock ?? (() => Date.now() / 1e3);
|
|
15752
15882
|
const now = clock();
|
|
15753
15883
|
const due = (this.last.get(name) ?? -Infinity) + intervalMs / 1e3;
|
|
15754
15884
|
const waited = Math.max(0, due - now);
|
|
15755
15885
|
this.last.set(name, Math.max(now, due));
|
|
15756
|
-
if (waited) await
|
|
15886
|
+
if (waited) await sleep7(waited);
|
|
15757
15887
|
return Math.round(waited * 1e3) / 1e3;
|
|
15758
15888
|
}
|
|
15759
15889
|
};
|
|
@@ -17126,10 +17256,10 @@ var HookRun = class _HookRun {
|
|
|
17126
17256
|
/** `run_end`: every handler sees the report and the artifacts; a deny (the alias
|
|
17127
17257
|
* outgoing scan found a real value) or a failed handler fails the run. Waits for the
|
|
17128
17258
|
* `async` handlers first. Findings are returned either way. */
|
|
17129
|
-
async end(
|
|
17259
|
+
async end(report2, artifacts = {}) {
|
|
17130
17260
|
await this.drain();
|
|
17131
17261
|
const event = this.event("run_end", "run_end", {
|
|
17132
|
-
report,
|
|
17262
|
+
report: report2,
|
|
17133
17263
|
artifacts: { ...artifacts }
|
|
17134
17264
|
});
|
|
17135
17265
|
const before = this.findings.length;
|
|
@@ -17431,16 +17561,16 @@ function readFieldKinds(file, cwd) {
|
|
|
17431
17561
|
if (!fs18.existsSync(target)) throw new CliError(`${target} not found (--field-kinds)`, 2);
|
|
17432
17562
|
return JSON.parse(fs18.readFileSync(target, "utf8"));
|
|
17433
17563
|
}
|
|
17434
|
-
function summaryLines(
|
|
17435
|
-
const body =
|
|
17436
|
-
const head =
|
|
17437
|
-
const findings =
|
|
17564
|
+
function summaryLines(report2, sampleSize) {
|
|
17565
|
+
const body = report2.toDict();
|
|
17566
|
+
const head = report2.ok ? `no detected leaks: ${body.census.total} identifier(s) checked across ${report2.recordsScanned} record(s)` : `${report2.findings.length} finding(s): ${body.leaked_identifiers} of ${body.census.total} identifiers reached the model (coverage ${body.coverage})`;
|
|
17567
|
+
const findings = report2.findings.map(
|
|
17438
17568
|
(f) => ` record ${f.record} ${f.tool.padEnd(24)} ${f.kind.padEnd(12)} ${f.source.padEnd(8)} ${f.prefix}\u2026`
|
|
17439
17569
|
);
|
|
17440
|
-
const sample3 =
|
|
17570
|
+
const sample3 = report2.reviewSample(sampleSize).map((s) => ` record ${s.record} ${s.tool}: ${s.text.slice(0, 160)}`);
|
|
17441
17571
|
return [
|
|
17442
17572
|
head,
|
|
17443
|
-
`detectors: ${
|
|
17573
|
+
`detectors: ${report2.detectors.join(", ")} (a value in no list and matching no pattern is invisible to them)`,
|
|
17444
17574
|
...findings,
|
|
17445
17575
|
...sample3.length > 0 ? ["review sample (shown to the model, nothing flagged; read these):", ...sample3] : []
|
|
17446
17576
|
];
|
|
@@ -17459,10 +17589,10 @@ function registerHooksAuditCommand(hooks) {
|
|
|
17459
17589
|
const target = args.positionals[0];
|
|
17460
17590
|
if (!target) throw new CliError("audit needs a run directory", 2);
|
|
17461
17591
|
const cwd = process.cwd();
|
|
17462
|
-
const
|
|
17463
|
-
if (arg.bool(args, "json")) printJson(ctx,
|
|
17464
|
-
else summaryLines(
|
|
17465
|
-
return
|
|
17592
|
+
const report2 = new AuditRunDir(target, cwd).audit(readFieldKinds(arg.str(args, "field-kinds"), cwd));
|
|
17593
|
+
if (arg.bool(args, "json")) printJson(ctx, report2.toDict());
|
|
17594
|
+
else summaryLines(report2, Number(arg.str(args, "sample") ?? 0)).forEach((line) => ctx.stdout(line));
|
|
17595
|
+
return report2.ok ? 0 : 1;
|
|
17466
17596
|
}
|
|
17467
17597
|
});
|
|
17468
17598
|
}
|
|
@@ -17808,8 +17938,8 @@ async function runCodingAgentHook(configFile, input, opts) {
|
|
|
17808
17938
|
note
|
|
17809
17939
|
};
|
|
17810
17940
|
}
|
|
17811
|
-
const
|
|
17812
|
-
const verdict = await run.end(
|
|
17941
|
+
const report2 = readLastAssistantText(input.transcript_path);
|
|
17942
|
+
const verdict = await run.end(report2, {});
|
|
17813
17943
|
if (!verdict.passed)
|
|
17814
17944
|
return {
|
|
17815
17945
|
output: {
|
|
@@ -17895,9 +18025,9 @@ function registerHooksCommands(root) {
|
|
|
17895
18025
|
run: async (args, ctx) => {
|
|
17896
18026
|
const file = args.positionals[0];
|
|
17897
18027
|
if (!file) throw new CliError("gateway hooks check <config>");
|
|
17898
|
-
let
|
|
18028
|
+
let report2;
|
|
17899
18029
|
try {
|
|
17900
|
-
|
|
18030
|
+
report2 = await checkHooks(file, {
|
|
17901
18031
|
event: arg.str(args, "event"),
|
|
17902
18032
|
tool: arg.str(args, "tool"),
|
|
17903
18033
|
input: readJsonFlag(args, "input"),
|
|
@@ -17910,16 +18040,16 @@ function registerHooksCommands(root) {
|
|
|
17910
18040
|
throw error;
|
|
17911
18041
|
}
|
|
17912
18042
|
if (arg.bool(args, "json")) {
|
|
17913
|
-
printJson(ctx,
|
|
17914
|
-
return
|
|
18043
|
+
printJson(ctx, report2);
|
|
18044
|
+
return report2.problems.length ? 1 : 0;
|
|
17915
18045
|
}
|
|
17916
18046
|
ctx.stdout(
|
|
17917
|
-
`${
|
|
18047
|
+
`${report2.config}: ${report2.rules} rule(s), ${report2.handlers} handler(s) \u2014 valid`
|
|
17918
18048
|
);
|
|
17919
18049
|
ctx.stdout(
|
|
17920
|
-
`sample: ${
|
|
18050
|
+
`sample: ${report2.event} ${report2.tool} ${JSON.stringify(report2.input)}`
|
|
17921
18051
|
);
|
|
17922
|
-
for (const rule of
|
|
18052
|
+
for (const rule of report2.outcomes) {
|
|
17923
18053
|
ctx.stdout(
|
|
17924
18054
|
`${rule.matched ? "fires " : "skips "} ${rule.position} matcher: ${rule.matcher}`
|
|
17925
18055
|
);
|
|
@@ -17935,9 +18065,9 @@ function registerHooksCommands(root) {
|
|
|
17935
18065
|
);
|
|
17936
18066
|
}
|
|
17937
18067
|
}
|
|
17938
|
-
if (
|
|
17939
|
-
ctx.stdout(`tools: ${
|
|
17940
|
-
for (const t of
|
|
18068
|
+
if (report2.tools.length) {
|
|
18069
|
+
ctx.stdout(`tools: ${report2.tools.length} declared`);
|
|
18070
|
+
for (const t of report2.tools) {
|
|
17941
18071
|
const params = t.parameters;
|
|
17942
18072
|
const fields = Object.keys(params.properties ?? {}).map(
|
|
17943
18073
|
(f) => params.required?.includes(f) ? f : `${f}?`
|
|
@@ -17947,8 +18077,8 @@ function registerHooksCommands(root) {
|
|
|
17947
18077
|
);
|
|
17948
18078
|
}
|
|
17949
18079
|
}
|
|
17950
|
-
if (
|
|
17951
|
-
const p =
|
|
18080
|
+
if (report2.probe) {
|
|
18081
|
+
const p = report2.probe;
|
|
17952
18082
|
if (p.error)
|
|
17953
18083
|
ctx.stdout(
|
|
17954
18084
|
`probe ${p.tool}: FAILED after ${p.elapsed}s \u2014 ${p.error}`
|
|
@@ -17964,8 +18094,8 @@ function registerHooksCommands(root) {
|
|
|
17964
18094
|
);
|
|
17965
18095
|
}
|
|
17966
18096
|
}
|
|
17967
|
-
if (
|
|
17968
|
-
for (const problem of
|
|
18097
|
+
if (report2.problems.length) {
|
|
18098
|
+
for (const problem of report2.problems)
|
|
17969
18099
|
ctx.stderr(`problem: ${problem}`);
|
|
17970
18100
|
return 1;
|
|
17971
18101
|
}
|
|
@@ -18236,7 +18366,7 @@ init_describe();
|
|
|
18236
18366
|
init_sandbox();
|
|
18237
18367
|
init_worlds();
|
|
18238
18368
|
init_validate();
|
|
18239
|
-
import * as
|
|
18369
|
+
import * as fs27 from "fs";
|
|
18240
18370
|
|
|
18241
18371
|
// src/cli/platform/environment.ts
|
|
18242
18372
|
init_config();
|
|
@@ -18738,8 +18868,8 @@ function editVerbSpecs() {
|
|
|
18738
18868
|
init_config();
|
|
18739
18869
|
init_router();
|
|
18740
18870
|
init_sandbox();
|
|
18741
|
-
import * as
|
|
18742
|
-
import * as
|
|
18871
|
+
import * as fs25 from "fs";
|
|
18872
|
+
import * as path20 from "path";
|
|
18743
18873
|
|
|
18744
18874
|
// src/cli/platform/rows.ts
|
|
18745
18875
|
init_router();
|
|
@@ -19070,8 +19200,8 @@ var ScanError = class extends Error {
|
|
|
19070
19200
|
};
|
|
19071
19201
|
var WS = /* @__PURE__ */ new Set([32, 10, 13, 9]);
|
|
19072
19202
|
var TopLevelScanner = class {
|
|
19073
|
-
constructor(
|
|
19074
|
-
this.events =
|
|
19203
|
+
constructor(events2) {
|
|
19204
|
+
this.events = events2;
|
|
19075
19205
|
}
|
|
19076
19206
|
events;
|
|
19077
19207
|
mode = "start";
|
|
@@ -19683,17 +19813,55 @@ var REDACT_FLAG = {
|
|
|
19683
19813
|
// src/cli/platform/sandboxVerbs.ts
|
|
19684
19814
|
init_shared();
|
|
19685
19815
|
|
|
19816
|
+
// src/cli/version.ts
|
|
19817
|
+
import * as fs24 from "fs";
|
|
19818
|
+
import * as path19 from "path";
|
|
19819
|
+
function cliVersion() {
|
|
19820
|
+
if (true) return "0.6.0";
|
|
19821
|
+
if (typeof __dirname !== "string") return "unknown";
|
|
19822
|
+
try {
|
|
19823
|
+
const pkg = JSON.parse(fs24.readFileSync(path19.resolve(__dirname, "../../package.json"), "utf8"));
|
|
19824
|
+
return pkg.version ?? "unknown";
|
|
19825
|
+
} catch {
|
|
19826
|
+
return "unknown";
|
|
19827
|
+
}
|
|
19828
|
+
}
|
|
19829
|
+
var CliRelease = class _CliRelease {
|
|
19830
|
+
constructor(version) {
|
|
19831
|
+
this.version = version;
|
|
19832
|
+
}
|
|
19833
|
+
version;
|
|
19834
|
+
static current() {
|
|
19835
|
+
return new _CliRelease(cliVersion());
|
|
19836
|
+
}
|
|
19837
|
+
olderThan(other) {
|
|
19838
|
+
const mine = _CliRelease.parts(this.version);
|
|
19839
|
+
const theirs = _CliRelease.parts(other);
|
|
19840
|
+
if (!mine || !theirs) return false;
|
|
19841
|
+
const index2 = mine.findIndex((part, at) => part !== theirs[at]);
|
|
19842
|
+
return index2 !== -1 && mine[index2] < theirs[index2];
|
|
19843
|
+
}
|
|
19844
|
+
staleNotice(platform) {
|
|
19845
|
+
if (!platform || !this.olderThan(platform)) return null;
|
|
19846
|
+
return `gateway ${this.version} is older than the platform's ${platform}; flags and verbs may be missing here: npm install -g @withgateway/sdk@latest`;
|
|
19847
|
+
}
|
|
19848
|
+
static parts(version) {
|
|
19849
|
+
const match = /^(\d+)\.(\d+)\.(\d+)/.exec(version);
|
|
19850
|
+
return match ? match.slice(1, 4).map(Number) : null;
|
|
19851
|
+
}
|
|
19852
|
+
};
|
|
19853
|
+
|
|
19686
19854
|
// src/cli/platform/sandboxImportReport.ts
|
|
19687
19855
|
init_config();
|
|
19688
19856
|
init_sandbox();
|
|
19689
19857
|
init_shared();
|
|
19690
19858
|
init_batches();
|
|
19691
19859
|
var SandboxImportReport = class {
|
|
19692
|
-
constructor(sandbox, creds, sandboxId,
|
|
19860
|
+
constructor(sandbox, creds, sandboxId, report2, ctx) {
|
|
19693
19861
|
this.sandbox = sandbox;
|
|
19694
19862
|
this.creds = creds;
|
|
19695
19863
|
this.sandboxId = sandboxId;
|
|
19696
|
-
this.report =
|
|
19864
|
+
this.report = report2;
|
|
19697
19865
|
this.ctx = ctx;
|
|
19698
19866
|
}
|
|
19699
19867
|
sandbox;
|
|
@@ -19804,7 +19972,7 @@ function assertWriteSize(bytes, filePath) {
|
|
|
19804
19972
|
);
|
|
19805
19973
|
}
|
|
19806
19974
|
function walk(dir, filter, rel, out) {
|
|
19807
|
-
for (const entry of
|
|
19975
|
+
for (const entry of fs25.readdirSync(path20.join(dir, rel), { withFileTypes: true })) {
|
|
19808
19976
|
const child = rel ? `${rel}/${entry.name}` : entry.name;
|
|
19809
19977
|
if (entry.isDirectory() && filter.skipsDirectory(entry.name)) out.skipped.push(`${child}/`);
|
|
19810
19978
|
else if (entry.isDirectory()) walk(dir, filter, child, out);
|
|
@@ -19818,7 +19986,7 @@ async function writeTree(args, ctx, sandboxId, target, dir) {
|
|
|
19818
19986
|
const { files, skipped } = walk(dir, new WriteTreeFilter(), "", { files: [], skipped: [] });
|
|
19819
19987
|
files.sort();
|
|
19820
19988
|
skipped.sort();
|
|
19821
|
-
for (const rel of files) assertWriteSize(
|
|
19989
|
+
for (const rel of files) assertWriteSize(fs25.statSync(path20.join(dir, rel)).size, rel);
|
|
19822
19990
|
if (skipped.length > 0)
|
|
19823
19991
|
ctx.stderr(
|
|
19824
19992
|
`skipped ${skipped.length} path${skipped.length === 1 ? "" : "s"} the platform never versions: ` + skipped.slice(0, SKIPPED_LISTED).join(", ") + (skipped.length > SKIPPED_LISTED ? ", \u2026" : "")
|
|
@@ -19827,15 +19995,15 @@ async function writeTree(args, ctx, sandboxId, target, dir) {
|
|
|
19827
19995
|
const written = [];
|
|
19828
19996
|
for (const rel of files)
|
|
19829
19997
|
written.push(
|
|
19830
|
-
await sandbox.write(sandboxId, target === "." ? rel : `${target}/${rel}`,
|
|
19998
|
+
await sandbox.write(sandboxId, target === "." ? rel : `${target}/${rel}`, fs25.readFileSync(path20.join(dir, rel)))
|
|
19831
19999
|
);
|
|
19832
20000
|
return written;
|
|
19833
20001
|
}
|
|
19834
20002
|
async function sourceBytes(from, content, stdin, filePath) {
|
|
19835
20003
|
if (content !== void 0) return Buffer.from(content, "utf8");
|
|
19836
20004
|
if (from === void 0) return Buffer.from(await stdin(), "utf8");
|
|
19837
|
-
assertWriteSize(
|
|
19838
|
-
return
|
|
20005
|
+
assertWriteSize(fs25.statSync(from).size, filePath);
|
|
20006
|
+
return fs25.readFileSync(from);
|
|
19839
20007
|
}
|
|
19840
20008
|
function client2(args) {
|
|
19841
20009
|
return new WorldSandboxClient(worldsOptions(credentials(args)));
|
|
@@ -20001,16 +20169,16 @@ function sandboxVerbSpecs() {
|
|
|
20001
20169
|
],
|
|
20002
20170
|
notes: "A new-world sandbox reports baseVersionId/baseContentHash null, branch main and pendingSlug; `check` runs the push gate the first commit will run.",
|
|
20003
20171
|
run: async (args, ctx) => {
|
|
20004
|
-
|
|
20005
|
-
|
|
20006
|
-
|
|
20007
|
-
|
|
20008
|
-
|
|
20009
|
-
arg.str(args, "new"),
|
|
20010
|
-
arg.str(args, "from")
|
|
20011
|
-
)
|
|
20172
|
+
const opened = await client2(args).open(
|
|
20173
|
+
openTarget(
|
|
20174
|
+
args.positionals[0],
|
|
20175
|
+
arg.str(args, "new"),
|
|
20176
|
+
arg.str(args, "from")
|
|
20012
20177
|
)
|
|
20013
20178
|
);
|
|
20179
|
+
printJson(ctx, opened);
|
|
20180
|
+
const stale = CliRelease.current().staleNotice(opened.cli?.version);
|
|
20181
|
+
if (stale) ctx.stderr(`warning: ${stale}`);
|
|
20014
20182
|
}
|
|
20015
20183
|
},
|
|
20016
20184
|
{
|
|
@@ -20076,7 +20244,7 @@ function sandboxVerbSpecs() {
|
|
|
20076
20244
|
const file = await client2(args).read(sandboxId, filePath);
|
|
20077
20245
|
const out = arg.str(args, "out");
|
|
20078
20246
|
if (out) {
|
|
20079
|
-
|
|
20247
|
+
fs25.writeFileSync(out, file.bytes);
|
|
20080
20248
|
printJson(ctx, { path: file.path, size: file.size, out });
|
|
20081
20249
|
return;
|
|
20082
20250
|
}
|
|
@@ -20106,7 +20274,7 @@ function sandboxVerbSpecs() {
|
|
|
20106
20274
|
const content = arg.str(args, "content");
|
|
20107
20275
|
if (from && content !== void 0)
|
|
20108
20276
|
throw new CliError("--from and --content are mutually exclusive");
|
|
20109
|
-
if (from &&
|
|
20277
|
+
if (from && fs25.statSync(from).isDirectory())
|
|
20110
20278
|
return printJson(ctx, await writeTree(args, ctx, sandboxId, filePath, from));
|
|
20111
20279
|
const bytes = await sourceBytes(from, content, () => ctx.stdin(), filePath);
|
|
20112
20280
|
assertWriteSize(bytes.length, filePath);
|
|
@@ -20268,7 +20436,7 @@ function sandboxVerbSpecs() {
|
|
|
20268
20436
|
run: async (args, ctx) => {
|
|
20269
20437
|
const [sandboxId, filePath] = args.positionals;
|
|
20270
20438
|
const sandbox = client2(args);
|
|
20271
|
-
const
|
|
20439
|
+
const report2 = new SandboxImportReport(
|
|
20272
20440
|
sandbox,
|
|
20273
20441
|
credentials(args),
|
|
20274
20442
|
sandboxId,
|
|
@@ -20291,9 +20459,9 @@ function sandboxVerbSpecs() {
|
|
|
20291
20459
|
})
|
|
20292
20460
|
);
|
|
20293
20461
|
} catch (error) {
|
|
20294
|
-
return
|
|
20462
|
+
return report2.refused(error);
|
|
20295
20463
|
}
|
|
20296
|
-
return
|
|
20464
|
+
return report2.answered(answer);
|
|
20297
20465
|
}
|
|
20298
20466
|
},
|
|
20299
20467
|
{
|
|
@@ -20324,8 +20492,8 @@ init_config();
|
|
|
20324
20492
|
init_router();
|
|
20325
20493
|
init_hub();
|
|
20326
20494
|
init_client();
|
|
20327
|
-
import * as
|
|
20328
|
-
import * as
|
|
20495
|
+
import * as fs26 from "fs";
|
|
20496
|
+
import * as path21 from "path";
|
|
20329
20497
|
init_shared();
|
|
20330
20498
|
var PULL_FORCE_FLAG = {
|
|
20331
20499
|
name: "force",
|
|
@@ -20358,7 +20526,7 @@ function bumpPostVersion(version) {
|
|
|
20358
20526
|
}
|
|
20359
20527
|
function readPyprojectVersion(dir) {
|
|
20360
20528
|
try {
|
|
20361
|
-
const text2 =
|
|
20529
|
+
const text2 = fs26.readFileSync(path21.join(dir, "pyproject.toml"), "utf8");
|
|
20362
20530
|
const section = /\[project\]([\s\S]*?)(\n\[|$)/.exec(text2)?.[1] ?? "";
|
|
20363
20531
|
return /\bversion\s*=\s*"([^"]+)"/.exec(section)?.[1];
|
|
20364
20532
|
} catch {
|
|
@@ -20366,10 +20534,10 @@ function readPyprojectVersion(dir) {
|
|
|
20366
20534
|
}
|
|
20367
20535
|
}
|
|
20368
20536
|
function updatePyprojectVersion(file, newVersion) {
|
|
20369
|
-
const content =
|
|
20537
|
+
const content = fs26.readFileSync(file, "utf8");
|
|
20370
20538
|
const updated = content.replace(/(\s*)version\s*=\s*["'][^"']*["']/, `$1version = "${newVersion}"`);
|
|
20371
20539
|
if (updated === content) throw new CliError("version line not found or unchanged in pyproject.toml", 1);
|
|
20372
|
-
|
|
20540
|
+
fs26.writeFileSync(file, updated);
|
|
20373
20541
|
}
|
|
20374
20542
|
function applyVersionBump(dir, args) {
|
|
20375
20543
|
const picked = ["auto-bump", "rc", "post"].filter((name) => arg.bool(args, name));
|
|
@@ -20378,11 +20546,11 @@ function applyVersionBump(dir, args) {
|
|
|
20378
20546
|
const current = readPyprojectVersion(dir);
|
|
20379
20547
|
if (!current)
|
|
20380
20548
|
throw new CliError(
|
|
20381
|
-
`--${picked[0]} needs a [project].version in ${
|
|
20549
|
+
`--${picked[0]} needs a [project].version in ${path21.join(dir, "pyproject.toml")} to bump; this dir has none.`,
|
|
20382
20550
|
1
|
|
20383
20551
|
);
|
|
20384
20552
|
const next = picked[0] === "auto-bump" ? bumpVersion(current) : picked[0] === "rc" ? bumpRcVersion(current) : bumpPostVersion(current);
|
|
20385
|
-
updatePyprojectVersion(
|
|
20553
|
+
updatePyprojectVersion(path21.join(dir, "pyproject.toml"), next);
|
|
20386
20554
|
return next;
|
|
20387
20555
|
}
|
|
20388
20556
|
var VERSION_ID_FLAG = { name: "version-id", help: "Version id (default: the main tip)." };
|
|
@@ -20452,7 +20620,7 @@ function versionVerbSpecs() {
|
|
|
20452
20620
|
"Push without --build-wheel, or build the wheel with the Python CLI."
|
|
20453
20621
|
);
|
|
20454
20622
|
const dir = args.positionals[0] ?? ".";
|
|
20455
|
-
if (!
|
|
20623
|
+
if (!fs26.existsSync(dir) || !fs26.statSync(dir).isDirectory()) throw new CliError(`Not a directory: ${dir}`, 1);
|
|
20456
20624
|
const options = worldsOptions(credentials(args));
|
|
20457
20625
|
applyVersionBump(dir, args);
|
|
20458
20626
|
await checkSchemaTreeBeforePush(dir);
|
|
@@ -20891,7 +21059,7 @@ function registerBenchCommands(root) {
|
|
|
20891
21059
|
await cancelRun(credentials(args), runId)
|
|
20892
21060
|
);
|
|
20893
21061
|
const options = worldsOptions(credentials(args));
|
|
20894
|
-
const
|
|
21062
|
+
const report2 = arg.bool(args, "wait") ? await waitForRun(runId, {
|
|
20895
21063
|
timeoutMinutes: arg.int(args, "timeout-min") ?? 45,
|
|
20896
21064
|
options,
|
|
20897
21065
|
onTick: (r) => ctx.stderr(
|
|
@@ -20899,22 +21067,22 @@ function registerBenchCommands(root) {
|
|
|
20899
21067
|
)
|
|
20900
21068
|
}) : await getRun(runId, options);
|
|
20901
21069
|
ctx.stdout(
|
|
20902
|
-
`${
|
|
21070
|
+
`${report2.id} ${report2.status}${report2.score !== null ? ` score=${report2.score.toFixed(3)}` : ""} (${report2.model ?? "?"} \xB7 ${report2.versionLabel ?? "?"} \xB7 x${report2.parallelism})`
|
|
20903
21071
|
);
|
|
20904
|
-
for (const sample3 of
|
|
21072
|
+
for (const sample3 of report2.samples) {
|
|
20905
21073
|
const subs = Object.entries(sample3.rewards).filter(([, v]) => typeof v === "number").map(([k, v]) => `${k}=${v.toFixed(2)}`).join(" ");
|
|
20906
21074
|
ctx.stdout(
|
|
20907
21075
|
` ${(sample3.reward ?? 0).toFixed(2)} ${sample3.task ?? "?"}${subs ? ` [${subs}]` : ""}`
|
|
20908
21076
|
);
|
|
20909
21077
|
}
|
|
20910
|
-
if (
|
|
20911
|
-
if (!
|
|
21078
|
+
if (report2.summary) ctx.stdout(` ${report2.summary}`);
|
|
21079
|
+
if (!report2.terminal) {
|
|
20912
21080
|
ctx.stderr(
|
|
20913
|
-
`run ${
|
|
21081
|
+
`run ${report2.id} is still ${report2.status.toLowerCase()}; pass --wait to poll it to a verdict`
|
|
20914
21082
|
);
|
|
20915
21083
|
return 0;
|
|
20916
21084
|
}
|
|
20917
|
-
return
|
|
21085
|
+
return report2.status.toUpperCase() === "COMPLETED" ? 0 : 1;
|
|
20918
21086
|
}
|
|
20919
21087
|
});
|
|
20920
21088
|
bench.command({
|
|
@@ -21102,7 +21270,7 @@ function registerBenchCommands(root) {
|
|
|
21102
21270
|
if (!runConfig)
|
|
21103
21271
|
throw new CliError("bench validate needs --run-config NAME");
|
|
21104
21272
|
const minScoreRaw = arg.str(args, "min-score");
|
|
21105
|
-
const
|
|
21273
|
+
const report2 = await validateWorld(args.positionals[0] ?? ".", {
|
|
21106
21274
|
slug: arg.str(args, "slug"),
|
|
21107
21275
|
runConfig,
|
|
21108
21276
|
branch: arg.str(args, "branch"),
|
|
@@ -21111,17 +21279,17 @@ function registerBenchCommands(root) {
|
|
|
21111
21279
|
onProgress: (line) => ctx.stderr(line),
|
|
21112
21280
|
options: worldsOptions(credentials(args))
|
|
21113
21281
|
});
|
|
21114
|
-
for (const run of
|
|
21282
|
+
for (const run of report2.runs) {
|
|
21115
21283
|
ctx.stdout(
|
|
21116
21284
|
`${run.model}: ${run.failure ? `FAIL \u2014 ${run.failure}` : "pass"}${run.report?.score != null ? ` score=${run.report.score.toFixed(3)}` : ""}${run.report?.url ? ` ${run.report.url}` : ""}`
|
|
21117
21285
|
);
|
|
21118
21286
|
}
|
|
21119
21287
|
const summaryFile = arg.str(args, "summary-file");
|
|
21120
|
-
if (summaryFile)
|
|
21288
|
+
if (summaryFile) fs27.writeFileSync(summaryFile, report2.markdown + "\n");
|
|
21121
21289
|
const stepSummary2 = process.env.GITHUB_STEP_SUMMARY;
|
|
21122
|
-
if (stepSummary2)
|
|
21123
|
-
ctx.stdout(
|
|
21124
|
-
return
|
|
21290
|
+
if (stepSummary2) fs27.appendFileSync(stepSummary2, report2.markdown + "\n");
|
|
21291
|
+
ctx.stdout(report2.ok ? "validation passed" : "validation FAILED");
|
|
21292
|
+
return report2.ok ? 0 : 1;
|
|
21125
21293
|
}
|
|
21126
21294
|
});
|
|
21127
21295
|
bench.command({
|
|
@@ -21312,13 +21480,13 @@ init_config();
|
|
|
21312
21480
|
init_router();
|
|
21313
21481
|
init_hub();
|
|
21314
21482
|
init_worlds();
|
|
21315
|
-
import * as
|
|
21316
|
-
import * as
|
|
21483
|
+
import * as fs38 from "fs";
|
|
21484
|
+
import * as path31 from "path";
|
|
21317
21485
|
|
|
21318
21486
|
// src/benchmarks/index.ts
|
|
21319
21487
|
init_worldDir();
|
|
21320
|
-
import * as
|
|
21321
|
-
import * as
|
|
21488
|
+
import * as fs28 from "fs";
|
|
21489
|
+
import * as path22 from "path";
|
|
21322
21490
|
var BENCHMARKS_SKILL = "benchmarks-getting-started";
|
|
21323
21491
|
var BENCHMARK_KINDS = ["world", "harbor", "verifiers", "image"];
|
|
21324
21492
|
function harborTaskDirs(dir) {
|
|
@@ -21359,9 +21527,9 @@ var SHAPE_LABELS = {
|
|
|
21359
21527
|
none: "not a world and not a benchmark package"
|
|
21360
21528
|
};
|
|
21361
21529
|
function declaredTasks(dir) {
|
|
21362
|
-
const file =
|
|
21363
|
-
if (!
|
|
21364
|
-
const toml =
|
|
21530
|
+
const file = path22.join(dir, "gateway-env.toml");
|
|
21531
|
+
if (!fs28.existsSync(file)) return [];
|
|
21532
|
+
const toml = fs28.readFileSync(file, "utf8");
|
|
21365
21533
|
const ids = [];
|
|
21366
21534
|
let inTask = false;
|
|
21367
21535
|
for (const raw of toml.split("\n")) {
|
|
@@ -21379,8 +21547,8 @@ function declaredTasks(dir) {
|
|
|
21379
21547
|
return ids;
|
|
21380
21548
|
}
|
|
21381
21549
|
function firstLine(file) {
|
|
21382
|
-
if (!
|
|
21383
|
-
const text2 =
|
|
21550
|
+
if (!fs28.existsSync(file)) return null;
|
|
21551
|
+
const text2 = fs28.readFileSync(file, "utf8").trim();
|
|
21384
21552
|
return text2 ? text2.split("\n")[0].trim() : null;
|
|
21385
21553
|
}
|
|
21386
21554
|
function importReport(dir, from) {
|
|
@@ -21388,12 +21556,12 @@ function importReport(dir, from) {
|
|
|
21388
21556
|
const tasks = [];
|
|
21389
21557
|
if (from === "harbor") {
|
|
21390
21558
|
for (const taskDir of harborTaskDirs(dir)) {
|
|
21391
|
-
const id =
|
|
21392
|
-
const tests =
|
|
21393
|
-
const grader =
|
|
21559
|
+
const id = path22.basename(taskDir);
|
|
21560
|
+
const tests = path22.join(dir, taskDir, "tests");
|
|
21561
|
+
const grader = fs28.existsSync(tests) ? fs28.readdirSync(tests).map((f) => `tests/${f}`).join(", ") || "tests/ (empty)" : "no tests/";
|
|
21394
21562
|
tasks.push({
|
|
21395
21563
|
id,
|
|
21396
|
-
prompt: firstLine(
|
|
21564
|
+
prompt: firstLine(path22.join(dir, taskDir, "instruction.md")),
|
|
21397
21565
|
grader,
|
|
21398
21566
|
expressible: false,
|
|
21399
21567
|
reason: `${grader} grades a container filesystem after the agent runs; a world task grades world state with SQL verifiers`
|
|
@@ -21402,7 +21570,7 @@ function importReport(dir, from) {
|
|
|
21402
21570
|
} else {
|
|
21403
21571
|
const pkg = verifiersPackage(dir);
|
|
21404
21572
|
if (pkg) {
|
|
21405
|
-
const source2 =
|
|
21573
|
+
const source2 = fs28.readFileSync(path22.join(dir, pkg.init), "utf8");
|
|
21406
21574
|
const rewards = [...source2.matchAll(/@vf\.reward[^\n]*\n\s*(?:async\s+)?def\s+(\w+)/g)].map((m) => m[1]);
|
|
21407
21575
|
const tasksets = [...source2.matchAll(/class\s+(\w+)\s*\(\s*(?:vf|v1|verifiers(?:\.v1)?)?\.?Taskset\s*[,)]/g)].map(
|
|
21408
21576
|
(m) => m[1]
|
|
@@ -21433,9 +21601,9 @@ function importReport(dir, from) {
|
|
|
21433
21601
|
// src/benchmarks/container.ts
|
|
21434
21602
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
21435
21603
|
import { createHash as createHash12 } from "crypto";
|
|
21436
|
-
import * as
|
|
21604
|
+
import * as fs29 from "fs";
|
|
21437
21605
|
import * as os4 from "os";
|
|
21438
|
-
import * as
|
|
21606
|
+
import * as path23 from "path";
|
|
21439
21607
|
var DEFAULT_IMAGE = "python:3.11-slim";
|
|
21440
21608
|
var REWARD_JSON = "/logs/verifier/reward.json";
|
|
21441
21609
|
var REWARD_TXT = "/logs/verifier/reward.txt";
|
|
@@ -21465,11 +21633,11 @@ timeout_sec = 120.0
|
|
|
21465
21633
|
var TEST_SH = '#!/bin/bash\n# The task owns its grading. The only contract the platform reads is the\n# named numeric metrics this script writes to /logs/verifier/reward.json;\n# `reward` is the headline (1.0 = pass), every other key a sub-reward.\nmkdir -p /logs/verifier\n\nfile_exists=0.0\ncontent_ok=0.0\nif [ -f /app/hello.txt ]; then\n file_exists=1.0\n if [ "$(tr -d \'\\n\' < /app/hello.txt)" = "Hello, Gateway!" ]; then\n content_ok=1.0\n fi\nfi\nreward=$content_ok\n\ncat > /logs/verifier/reward.json <<EOF\n{"reward": ${reward}, "file_exists": ${file_exists}, "content_ok": ${content_ok}}\nEOF\necho "reward=${reward} file_exists=${file_exists} content_ok=${content_ok}"\n';
|
|
21466
21634
|
var SOLVE_SH = "#!/bin/bash\n# The reference solution: what harbor's `oracle` agent runs, and what\n# `gateway benchmarks dry-run` runs before the tests. It must score 1.0.\nset -euo pipefail\nmkdir -p /app\nprintf 'Hello, Gateway!\\n' > /app/hello.txt\n";
|
|
21467
21635
|
function writeHarborScaffold(dir, opts = {}) {
|
|
21468
|
-
const name = opts.name ??
|
|
21636
|
+
const name = opts.name ?? path23.basename(path23.resolve(dir));
|
|
21469
21637
|
const task = opts.task ?? "hello-world";
|
|
21470
21638
|
const image = opts.image ?? DEFAULT_IMAGE;
|
|
21471
21639
|
const prompt = opts.prompt ?? HELLO_PROMPT;
|
|
21472
|
-
const taskDir =
|
|
21640
|
+
const taskDir = path23.join(dir, "tasks", task);
|
|
21473
21641
|
const files = {
|
|
21474
21642
|
"pyproject.toml": `[project]
|
|
21475
21643
|
name = "${name}"
|
|
@@ -21498,16 +21666,16 @@ WORKDIR /app
|
|
|
21498
21666
|
[`tasks/${task}/solution/solve.sh`]: SOLVE_SH
|
|
21499
21667
|
};
|
|
21500
21668
|
for (const [rel, content] of Object.entries(files)) {
|
|
21501
|
-
const target =
|
|
21502
|
-
|
|
21503
|
-
|
|
21504
|
-
if (rel.endsWith(".sh"))
|
|
21669
|
+
const target = path23.join(dir, rel);
|
|
21670
|
+
fs29.mkdirSync(path23.dirname(target), { recursive: true });
|
|
21671
|
+
fs29.writeFileSync(target, content);
|
|
21672
|
+
if (rel.endsWith(".sh")) fs29.chmodSync(target, 493);
|
|
21505
21673
|
}
|
|
21506
21674
|
void taskDir;
|
|
21507
21675
|
return { task, files: Object.keys(files) };
|
|
21508
21676
|
}
|
|
21509
21677
|
function writeVerifiersScaffold(dir, opts = {}) {
|
|
21510
|
-
const name = opts.name ??
|
|
21678
|
+
const name = opts.name ?? path23.basename(path23.resolve(dir));
|
|
21511
21679
|
const pkg = name.replace(/-/g, "_").replace(/[^A-Za-z0-9_]/g, "_");
|
|
21512
21680
|
const task = opts.task ?? "capital_of_france";
|
|
21513
21681
|
const files = {
|
|
@@ -21562,9 +21730,9 @@ Taskset), \`push\`, \`run\`, \`results\`; skill: \`gateway worlds skill benchmar
|
|
|
21562
21730
|
`
|
|
21563
21731
|
};
|
|
21564
21732
|
for (const [rel, content] of Object.entries(files)) {
|
|
21565
|
-
const target =
|
|
21566
|
-
|
|
21567
|
-
|
|
21733
|
+
const target = path23.join(dir, rel);
|
|
21734
|
+
fs29.mkdirSync(path23.dirname(target), { recursive: true });
|
|
21735
|
+
fs29.writeFileSync(target, content);
|
|
21568
21736
|
}
|
|
21569
21737
|
return { pkg, files: Object.keys(files) };
|
|
21570
21738
|
}
|
|
@@ -21595,7 +21763,7 @@ function readTomlScalars(text2) {
|
|
|
21595
21763
|
return out;
|
|
21596
21764
|
}
|
|
21597
21765
|
function readText2(file) {
|
|
21598
|
-
return
|
|
21766
|
+
return fs29.existsSync(file) ? fs29.readFileSync(file, "utf8") : null;
|
|
21599
21767
|
}
|
|
21600
21768
|
function checkTestScript(text2, rel) {
|
|
21601
21769
|
const problems = [];
|
|
@@ -21636,11 +21804,11 @@ function imageSourceReport(taskDir, ref, dockerfile) {
|
|
|
21636
21804
|
};
|
|
21637
21805
|
}
|
|
21638
21806
|
function validateHarborTask(dir, taskDir) {
|
|
21639
|
-
const full =
|
|
21640
|
-
const id =
|
|
21807
|
+
const full = path23.join(dir, taskDir);
|
|
21808
|
+
const id = path23.basename(taskDir);
|
|
21641
21809
|
const problems = [];
|
|
21642
21810
|
const warnings = [];
|
|
21643
|
-
const toml = readText2(
|
|
21811
|
+
const toml = readText2(path23.join(full, "task.toml"));
|
|
21644
21812
|
let ref = null;
|
|
21645
21813
|
let agent = null;
|
|
21646
21814
|
let verifier = null;
|
|
@@ -21653,11 +21821,11 @@ function validateHarborTask(dir, taskDir) {
|
|
|
21653
21821
|
agent = typeof parsed.agent?.timeout_sec === "number" ? parsed.agent.timeout_sec : null;
|
|
21654
21822
|
verifier = typeof parsed.verifier?.timeout_sec === "number" ? parsed.verifier.timeout_sec : null;
|
|
21655
21823
|
}
|
|
21656
|
-
const dockerfile = readText2(
|
|
21657
|
-
const composeRel = COMPOSE_RELS.find((rel) =>
|
|
21658
|
-
const compose = composeRel ? readText2(
|
|
21824
|
+
const dockerfile = readText2(path23.join(full, DOCKERFILE_REL));
|
|
21825
|
+
const composeRel = COMPOSE_RELS.find((rel) => fs29.existsSync(path23.join(full, rel))) ?? null;
|
|
21826
|
+
const compose = composeRel ? readText2(path23.join(full, composeRel)) : null;
|
|
21659
21827
|
const secrets = compose === null ? [] : composeRequiredNames(compose);
|
|
21660
|
-
const environment =
|
|
21828
|
+
const environment = fs29.existsSync(path23.join(full, "environment"));
|
|
21661
21829
|
const source2 = ref ? "docker_image" : dockerfile !== null ? "dockerfile" : null;
|
|
21662
21830
|
if (source2 === null && composeRel === null)
|
|
21663
21831
|
problems.push(`${taskDir}: no image \u2014 set [environment] docker_image in task.toml or add ${DOCKERFILE_REL}`);
|
|
@@ -21667,10 +21835,10 @@ function validateHarborTask(dir, taskDir) {
|
|
|
21667
21835
|
problems.push(...sources.problems);
|
|
21668
21836
|
warnings.push(...sources.warnings);
|
|
21669
21837
|
if (!environment) warnings.push(`${taskDir}/environment/ missing; harbor expects the directory (a Dockerfile, a compose file, or files to upload)`);
|
|
21670
|
-
const instruction = readText2(
|
|
21838
|
+
const instruction = readText2(path23.join(full, "instruction.md"));
|
|
21671
21839
|
if (instruction === null) problems.push(`${taskDir}/instruction.md missing (what the agent is told)`);
|
|
21672
21840
|
else if (!instruction.trim()) problems.push(`${taskDir}/instruction.md is empty`);
|
|
21673
|
-
const tests = readText2(
|
|
21841
|
+
const tests = readText2(path23.join(full, "tests", "test.sh"));
|
|
21674
21842
|
if (tests === null) problems.push(`${taskDir}/tests/test.sh missing (the grader; it must write ${REWARD_JSON})`);
|
|
21675
21843
|
else {
|
|
21676
21844
|
const checked = checkTestScript(tests, `${taskDir}/tests/test.sh`);
|
|
@@ -21678,17 +21846,17 @@ function validateHarborTask(dir, taskDir) {
|
|
|
21678
21846
|
warnings.push(...checked.warnings);
|
|
21679
21847
|
}
|
|
21680
21848
|
for (const sub of ["tests", "solution", "environment"]) {
|
|
21681
|
-
const linked =
|
|
21849
|
+
const linked = path23.join(full, sub);
|
|
21682
21850
|
let isLink = false;
|
|
21683
21851
|
try {
|
|
21684
|
-
isLink =
|
|
21852
|
+
isLink = fs29.lstatSync(linked).isSymbolicLink();
|
|
21685
21853
|
} catch {
|
|
21686
21854
|
isLink = false;
|
|
21687
21855
|
}
|
|
21688
21856
|
if (isLink)
|
|
21689
21857
|
problems.push(`${taskDir}/${sub} is a symlink (docker -v follows host symlinks, so whatever it points at would be mounted); make it a real directory`);
|
|
21690
21858
|
}
|
|
21691
|
-
const solution =
|
|
21859
|
+
const solution = fs29.existsSync(path23.join(full, "solution", "solve.sh"));
|
|
21692
21860
|
if (!solution) warnings.push(`${taskDir}/solution/solve.sh missing: dry-run and harbor's oracle agent have no reference solution to prove the grader with (the runner does not need it)`);
|
|
21693
21861
|
return {
|
|
21694
21862
|
id,
|
|
@@ -21711,7 +21879,7 @@ function validateHarbor(dir) {
|
|
|
21711
21879
|
const warnings = [];
|
|
21712
21880
|
const tasks = harborTaskDirs(dir).map((taskDir) => validateHarborTask(dir, taskDir));
|
|
21713
21881
|
if (tasks.length === 0) problems.push(`${dir} holds no harbor task (tasks/<name>/task.toml)`);
|
|
21714
|
-
if (!
|
|
21882
|
+
if (!fs29.existsSync(path23.join(dir, "pyproject.toml")))
|
|
21715
21883
|
warnings.push("no pyproject.toml: the slug is the directory name and the version is unrecorded (`benchmarks init --kind harbor` writes one)");
|
|
21716
21884
|
const detectedKind = detectEnvKind(dir);
|
|
21717
21885
|
if (detectedKind !== "harbor")
|
|
@@ -21728,8 +21896,8 @@ function validateVerifiers(dir) {
|
|
|
21728
21896
|
let info;
|
|
21729
21897
|
if (!pkg) problems.push(`${dir} is not a verifiers package (pyproject.toml plus a Python package with __init__.py)`);
|
|
21730
21898
|
else {
|
|
21731
|
-
const init2 =
|
|
21732
|
-
const source2 =
|
|
21899
|
+
const init2 = path23.join(dir, pkg.init);
|
|
21900
|
+
const source2 = fs29.readFileSync(init2, "utf8");
|
|
21733
21901
|
const read = inspectVerifiersSource(init2, source2);
|
|
21734
21902
|
if (read.syntaxError !== null) problems.push(`${pkg.init} does not parse: ${read.syntaxError}`);
|
|
21735
21903
|
if (read.fallback) warnings.push("python3 is not on PATH, so the package was read by pattern, not parsed: a SyntaxError would surface at dry-run");
|
|
@@ -21741,7 +21909,7 @@ function validateVerifiers(dir) {
|
|
|
21741
21909
|
seen.add(name);
|
|
21742
21910
|
}
|
|
21743
21911
|
const taskset = read.taskset;
|
|
21744
|
-
const pyproject =
|
|
21912
|
+
const pyproject = fs29.readFileSync(path23.join(dir, "pyproject.toml"), "utf8");
|
|
21745
21913
|
const v1 = /verifiers\s*(?:\[[^\]]*\])?\s*(?:>=|~=|==|>)\s*(?:0\.(?:[2-9]\d*|[1-9]\d+)|[1-9]\d*)/.test(pyproject) || /verifiers\.v1|from\s+verifiers\s+import\s+v1/.test(source2);
|
|
21746
21914
|
info = { name: pkg.name, init: pkg.init, taskset, rewards, v1 };
|
|
21747
21915
|
if (!v1) warnings.push("pyproject.toml pins no `verifiers>=0.2`: the runner will run it as a v0 (legacy `load_environment`) package");
|
|
@@ -21806,9 +21974,9 @@ function inspectVerifiersSource(init2, source2) {
|
|
|
21806
21974
|
var TMP_PLACEHOLDER = "<tmp>";
|
|
21807
21975
|
var LOGS_PLACEHOLDER = `${TMP_PLACEHOLDER}/logs`;
|
|
21808
21976
|
function treeSlug(dir) {
|
|
21809
|
-
const pyproject = readText2(
|
|
21977
|
+
const pyproject = readText2(path23.join(dir, "pyproject.toml"));
|
|
21810
21978
|
const name = pyproject === null ? void 0 : readTomlScalars(pyproject).project?.name;
|
|
21811
|
-
return typeof name === "string" && name ? name :
|
|
21979
|
+
return typeof name === "string" && name ? name : path23.basename(path23.resolve(dir));
|
|
21812
21980
|
}
|
|
21813
21981
|
var DOCKER_NAME_PREFIX = "gateway-benchmarks-dryrun";
|
|
21814
21982
|
var DOCKER_SAFE = /^[A-Za-z0-9 ._-]*$/;
|
|
@@ -21835,17 +22003,17 @@ ${volumes}
|
|
|
21835
22003
|
}
|
|
21836
22004
|
function harborRunPlan(dir, taskId, scratch = TMP_PLACEHOLDER) {
|
|
21837
22005
|
const dirs = harborTaskDirs(dir);
|
|
21838
|
-
const taskDir = taskId ? dirs.find((d) =>
|
|
22006
|
+
const taskDir = taskId ? dirs.find((d) => path23.basename(d) === taskId) : dirs[0];
|
|
21839
22007
|
if (!taskDir)
|
|
21840
22008
|
throw new Error(
|
|
21841
|
-
taskId ? `no task ${taskId} in ${dir}; tasks: ${dirs.map((d) =>
|
|
22009
|
+
taskId ? `no task ${taskId} in ${dir}; tasks: ${dirs.map((d) => path23.basename(d)).join(", ") || "none"}` : `${dir} holds no harbor task`
|
|
21842
22010
|
);
|
|
21843
22011
|
const validation = validateHarborTask(dir, taskDir);
|
|
21844
|
-
const full =
|
|
21845
|
-
const tag = dockerImageName(
|
|
22012
|
+
const full = path23.resolve(dir, taskDir);
|
|
22013
|
+
const tag = dockerImageName(path23.basename(path23.resolve(dir)), validation.id);
|
|
21846
22014
|
const logsDir = `${scratch}/logs`;
|
|
21847
|
-
const mounts = [{ host:
|
|
21848
|
-
if (validation.files.solution) mounts.push({ host:
|
|
22015
|
+
const mounts = [{ host: path23.join(full, "tests"), container: "/tests", mode: "ro" }];
|
|
22016
|
+
if (validation.files.solution) mounts.push({ host: path23.join(full, "solution"), container: "/solution", mode: "ro" });
|
|
21849
22017
|
mounts.push({ host: logsDir, container: "/logs", mode: "rw" });
|
|
21850
22018
|
const steps = [];
|
|
21851
22019
|
if (validation.files.solution)
|
|
@@ -21857,8 +22025,8 @@ function harborRunPlan(dir, taskId, scratch = TMP_PLACEHOLDER) {
|
|
|
21857
22025
|
const script = `mkdir -p /logs/verifier && ${steps.filter((s) => !s.command.startsWith("(")).map((s) => s.command).join(" && ")}`;
|
|
21858
22026
|
const commands = { run: [] };
|
|
21859
22027
|
if (validation.image.source === "dockerfile") {
|
|
21860
|
-
const dockerfile =
|
|
21861
|
-
commands.build = [bin, "build", "-t", tag, "-f", dockerfile,
|
|
22028
|
+
const dockerfile = path23.resolve(dir, validation.image.dockerfile);
|
|
22029
|
+
commands.build = [bin, "build", "-t", tag, "-f", dockerfile, path23.dirname(dockerfile)];
|
|
21862
22030
|
}
|
|
21863
22031
|
if (validation.image.source === "docker_image") commands.pull = [bin, "pull", "--quiet", validation.image.ref];
|
|
21864
22032
|
let compose = null;
|
|
@@ -21868,7 +22036,7 @@ function harborRunPlan(dir, taskId, scratch = TMP_PLACEHOLDER) {
|
|
|
21868
22036
|
for (const mount of mounts) commands.run.push("-v", `${mount.host}:${mount.container}${mount.mode === "ro" ? ":ro" : ""}`);
|
|
21869
22037
|
commands.run.push(uses ?? "<no image>", "bash", "-lc", script);
|
|
21870
22038
|
} else {
|
|
21871
|
-
const file =
|
|
22039
|
+
const file = path23.resolve(dir, validation.image.compose);
|
|
21872
22040
|
const base = `${scratch}/docker-compose.base.yaml`;
|
|
21873
22041
|
const project = tag;
|
|
21874
22042
|
compose = { file, base, project, secrets: validation.secrets };
|
|
@@ -21876,7 +22044,7 @@ function harborRunPlan(dir, taskId, scratch = TMP_PLACEHOLDER) {
|
|
|
21876
22044
|
commands.run = [...composeArgs, "run", "--rm", "main", "bash", "-lc", script];
|
|
21877
22045
|
commands.down = [...composeArgs, "down", "--volumes", "--remove-orphans"];
|
|
21878
22046
|
env.MAIN_IMAGE_NAME = uses ?? "";
|
|
21879
|
-
env.CONTEXT_DIR =
|
|
22047
|
+
env.CONTEXT_DIR = path23.join(full, "environment");
|
|
21880
22048
|
if (validation.image.ref) env.PREBUILT_IMAGE_NAME = validation.image.ref;
|
|
21881
22049
|
}
|
|
21882
22050
|
return {
|
|
@@ -21892,7 +22060,7 @@ function harborRunPlan(dir, taskId, scratch = TMP_PLACEHOLDER) {
|
|
|
21892
22060
|
commands,
|
|
21893
22061
|
reward: { file: REWARD_JSON, fallback: REWARD_TXT },
|
|
21894
22062
|
timeouts: { agent: validation.timeouts.agent ?? 300, verifier: validation.timeouts.verifier ?? 120 },
|
|
21895
|
-
runner: `harbor run -p ${
|
|
22063
|
+
runner: `harbor run -p ${path23.join(dir, "tasks")} -a mini-swe-agent -m <provider/model> -e docker -o <jobs> -k <rollouts> -n <concurrency> -y -q`,
|
|
21896
22064
|
validation
|
|
21897
22065
|
};
|
|
21898
22066
|
}
|
|
@@ -21929,11 +22097,11 @@ function dryRunHarbor(dir, plan) {
|
|
|
21929
22097
|
if (!image) return { executed: false, reason: "the task names no image", commands };
|
|
21930
22098
|
const secrets = plan.compose ? missingComposeSecrets(dir, plan.compose.secrets) : null;
|
|
21931
22099
|
if (secrets) return { executed: false, reason: secrets, commands };
|
|
21932
|
-
const scratch =
|
|
21933
|
-
const logs =
|
|
21934
|
-
|
|
22100
|
+
const scratch = fs29.mkdtempSync(path23.join(os4.tmpdir(), "gateway-benchmarks-dryrun-"));
|
|
22101
|
+
const logs = path23.join(scratch, "logs");
|
|
22102
|
+
fs29.mkdirSync(path23.join(logs, "verifier"), { recursive: true });
|
|
21935
22103
|
const place = (a) => a.split(TMP_PLACEHOLDER).join(scratch);
|
|
21936
|
-
if (plan.compose)
|
|
22104
|
+
if (plan.compose) fs29.writeFileSync(place(plan.compose.base), composeBase(image, plan.mounts.map((m) => ({ ...m, host: place(m.host) }))));
|
|
21937
22105
|
const outputs = [];
|
|
21938
22106
|
const spawnArgv = (argv, timeoutMs3) => {
|
|
21939
22107
|
commands.push(shellLine(argv));
|
|
@@ -21949,7 +22117,7 @@ function dryRunHarbor(dir, plan) {
|
|
|
21949
22117
|
return { executed: true, docker: docker.version, image, exitCode: pullStatus, output: outputs.join("\n"), commands, reason: notGraded("docker pull", pullStatus) };
|
|
21950
22118
|
const exitCode = spawnArgv(plan.commands.run.map(place), (plan.timeouts.agent + plan.timeouts.verifier) * 1e3);
|
|
21951
22119
|
if (plan.commands.down) spawnArgv(plan.commands.down.map(place), 5 * 6e4);
|
|
21952
|
-
const rewards = readReward(
|
|
22120
|
+
const rewards = readReward(path23.join(logs, "verifier"));
|
|
21953
22121
|
return {
|
|
21954
22122
|
executed: true,
|
|
21955
22123
|
docker: docker.version,
|
|
@@ -21963,7 +22131,7 @@ function dryRunHarbor(dir, plan) {
|
|
|
21963
22131
|
};
|
|
21964
22132
|
}
|
|
21965
22133
|
function readReward(verifierDir) {
|
|
21966
|
-
const json = readText2(
|
|
22134
|
+
const json = readText2(path23.join(verifierDir, "reward.json"));
|
|
21967
22135
|
if (json !== null) {
|
|
21968
22136
|
try {
|
|
21969
22137
|
const parsed = JSON.parse(json);
|
|
@@ -21974,7 +22142,7 @@ function readReward(verifierDir) {
|
|
|
21974
22142
|
return null;
|
|
21975
22143
|
}
|
|
21976
22144
|
}
|
|
21977
|
-
const txt = readText2(
|
|
22145
|
+
const txt = readText2(path23.join(verifierDir, "reward.txt"));
|
|
21978
22146
|
if (txt !== null && /^-?\d+(\.\d+)?\s*$/.test(txt)) return { reward: Number(txt.trim()) };
|
|
21979
22147
|
return null;
|
|
21980
22148
|
}
|
|
@@ -22002,9 +22170,9 @@ function verifiersDiscoverScript(bundle, pkg) {
|
|
|
22002
22170
|
}
|
|
22003
22171
|
function verifiersRunPlan(dir, validation, python = null) {
|
|
22004
22172
|
const pkg = validation.package;
|
|
22005
|
-
const name = pkg?.name ??
|
|
22173
|
+
const name = pkg?.name ?? path23.basename(path23.resolve(dir));
|
|
22006
22174
|
const bin = dockerBin();
|
|
22007
|
-
const tree =
|
|
22175
|
+
const tree = path23.resolve(dir);
|
|
22008
22176
|
return {
|
|
22009
22177
|
kind: "verifiers",
|
|
22010
22178
|
package: name,
|
|
@@ -22080,7 +22248,7 @@ init_router();
|
|
|
22080
22248
|
init_hub();
|
|
22081
22249
|
init_worlds();
|
|
22082
22250
|
init_dryRun();
|
|
22083
|
-
import * as
|
|
22251
|
+
import * as fs30 from "fs";
|
|
22084
22252
|
init_shared();
|
|
22085
22253
|
var META_RELPATH2 = ".gateway/.env-metadata.json";
|
|
22086
22254
|
function imageLabel(image) {
|
|
@@ -22198,7 +22366,7 @@ var HostedDryRunTarget = class _HostedDryRunTarget {
|
|
|
22198
22366
|
dir;
|
|
22199
22367
|
/** `slug`, `slug@ref`, or a dir that tracks a slug (`.gateway/.env-metadata.json`, the same file `push` writes). */
|
|
22200
22368
|
static async resolve(ref, opts, ctx, pushDir) {
|
|
22201
|
-
if (
|
|
22369
|
+
if (fs30.existsSync(ref) && fs30.statSync(ref).isDirectory())
|
|
22202
22370
|
return _HostedDryRunTarget.fromDir(ref, opts, ctx, pushDir);
|
|
22203
22371
|
const at = ref.indexOf("@");
|
|
22204
22372
|
if (at === -1)
|
|
@@ -22656,8 +22824,8 @@ init_client();
|
|
|
22656
22824
|
|
|
22657
22825
|
// src/cli/runtime/scaffoldVerifiers.ts
|
|
22658
22826
|
init_router();
|
|
22659
|
-
import * as
|
|
22660
|
-
import * as
|
|
22827
|
+
import * as fs31 from "fs";
|
|
22828
|
+
import * as path24 from "path";
|
|
22661
22829
|
var SCAFFOLD_VERIFIER = /^-- Scores 1\.0 once the world holds any (\S+) row; edit for real tasks\.\n/;
|
|
22662
22830
|
function scaffoldVerifier(entity) {
|
|
22663
22831
|
return `-- Scores 1.0 once the world holds any ${entity} row; edit for real tasks.
|
|
@@ -22667,15 +22835,15 @@ SELECT CASE WHEN COUNT(*) > 0 THEN 1.0 ELSE 0.0 END FROM "${entity}";
|
|
|
22667
22835
|
`;
|
|
22668
22836
|
}
|
|
22669
22837
|
function scaffoldVerifierEntity(file) {
|
|
22670
|
-
if (!
|
|
22671
|
-
const text2 =
|
|
22838
|
+
if (!fs31.existsSync(file)) return void 0;
|
|
22839
|
+
const text2 = fs31.readFileSync(file, "utf8");
|
|
22672
22840
|
const entity = SCAFFOLD_VERIFIER.exec(text2)?.[1];
|
|
22673
22841
|
return entity !== void 0 && text2 === scaffoldVerifier(entity) ? entity : void 0;
|
|
22674
22842
|
}
|
|
22675
22843
|
function verifierNames(dir) {
|
|
22676
|
-
const folder =
|
|
22677
|
-
if (!
|
|
22678
|
-
return
|
|
22844
|
+
const folder = path24.join(dir, "verifiers");
|
|
22845
|
+
if (!fs31.existsSync(folder)) return void 0;
|
|
22846
|
+
return fs31.readdirSync(folder).filter((f) => f.endsWith(".sql")).map((f) => f.slice(0, -4)).sort();
|
|
22679
22847
|
}
|
|
22680
22848
|
function verifierSql(name, entity, where) {
|
|
22681
22849
|
if (!/^[A-Za-z_][A-Za-z0-9_-]*$/.test(name)) throw new CliError(`Verifier names match [A-Za-z_][A-Za-z0-9_-]*, got ${JSON.stringify(name)}`);
|
|
@@ -22715,18 +22883,18 @@ function whereClauseDefect(clause) {
|
|
|
22715
22883
|
}
|
|
22716
22884
|
function addVerifier(dir, name, entity, where) {
|
|
22717
22885
|
const sql = verifierSql(name, entity, where);
|
|
22718
|
-
const file =
|
|
22719
|
-
if (
|
|
22886
|
+
const file = path24.join(dir, "verifiers", `${name}.sql`);
|
|
22887
|
+
if (fs31.existsSync(file))
|
|
22720
22888
|
throw new CliError(`verifiers/${name}.sql already exists (have: ${(verifierNames(dir) ?? []).join(", ")}); edit it, or pick another name`);
|
|
22721
|
-
|
|
22722
|
-
|
|
22889
|
+
fs31.mkdirSync(path24.dirname(file), { recursive: true });
|
|
22890
|
+
fs31.writeFileSync(file, sql);
|
|
22723
22891
|
return file;
|
|
22724
22892
|
}
|
|
22725
22893
|
function repointScaffoldVerifier(dir, entity, declared) {
|
|
22726
|
-
const file =
|
|
22894
|
+
const file = path24.join(dir, "verifiers", "state_present.sql");
|
|
22727
22895
|
const named2 = scaffoldVerifierEntity(file);
|
|
22728
22896
|
if (named2 === void 0 || declared.includes(named2)) return null;
|
|
22729
|
-
|
|
22897
|
+
fs31.writeFileSync(file, scaffoldVerifier(entity));
|
|
22730
22898
|
return file;
|
|
22731
22899
|
}
|
|
22732
22900
|
|
|
@@ -22737,8 +22905,8 @@ init_shared();
|
|
|
22737
22905
|
// src/cli/platform/worlds.ts
|
|
22738
22906
|
init_config();
|
|
22739
22907
|
init_router();
|
|
22740
|
-
import * as
|
|
22741
|
-
import * as
|
|
22908
|
+
import * as fs37 from "fs";
|
|
22909
|
+
import * as path30 from "path";
|
|
22742
22910
|
init_describe();
|
|
22743
22911
|
init_hub();
|
|
22744
22912
|
init_migrate();
|
|
@@ -22748,8 +22916,8 @@ init_shared();
|
|
|
22748
22916
|
// src/cli/worldTarget.ts
|
|
22749
22917
|
init_hub();
|
|
22750
22918
|
init_router();
|
|
22751
|
-
import
|
|
22752
|
-
import
|
|
22919
|
+
import fs33 from "fs";
|
|
22920
|
+
import path26 from "path";
|
|
22753
22921
|
var WorldTarget = class _WorldTarget {
|
|
22754
22922
|
constructor(token, side, slug, ref, dir) {
|
|
22755
22923
|
this.token = token;
|
|
@@ -22774,7 +22942,7 @@ var WorldTarget = class _WorldTarget {
|
|
|
22774
22942
|
if (_WorldTarget.isPathShaped(token)) {
|
|
22775
22943
|
if (!exists(token)) throw new CliError(`${token} is not a directory here`);
|
|
22776
22944
|
if (typed.length > 0) throw new CliError(hostedOnlyMessage(token, typed));
|
|
22777
|
-
return new _WorldTarget(token, "local",
|
|
22945
|
+
return new _WorldTarget(token, "local", path26.basename(path26.resolve(token)), void 0, path26.resolve(token));
|
|
22778
22946
|
}
|
|
22779
22947
|
if (!exists(token)) return new _WorldTarget(token, "hosted", token, void 0, void 0);
|
|
22780
22948
|
if (typed.length > 0) throw new CliError(hostedOnlyMessage(token, typed));
|
|
@@ -22784,7 +22952,7 @@ var WorldTarget = class _WorldTarget {
|
|
|
22784
22952
|
}
|
|
22785
22953
|
/** `.`, `..`, `./x`, `/abs`, `~/x`, `a/b`, `a\\b` name a path, never a slug. */
|
|
22786
22954
|
static isPathShaped(token) {
|
|
22787
|
-
return token.startsWith(".") || token.startsWith("~") || /[\\/]/.test(token) ||
|
|
22955
|
+
return token.startsWith(".") || token.startsWith("~") || /[\\/]/.test(token) || path26.isAbsolute(token);
|
|
22788
22956
|
}
|
|
22789
22957
|
get isLocal() {
|
|
22790
22958
|
return this.side === "local";
|
|
@@ -22792,18 +22960,18 @@ var WorldTarget = class _WorldTarget {
|
|
|
22792
22960
|
};
|
|
22793
22961
|
function hostedOnlyMessage(token, typed) {
|
|
22794
22962
|
const flags = typed.map((flag) => `--${flag}`).join(", ");
|
|
22795
|
-
const slug = readLocalMeta(token)?.slug ??
|
|
22963
|
+
const slug = readLocalMeta(token)?.slug ?? path26.basename(path26.resolve(token));
|
|
22796
22964
|
return `${token} is a directory here, and ${flags} only ${typed.length === 1 ? "applies" : "apply"} to a world on the platform. Name the platform world as ${slug}@main (slug@ref is never read as a path), or drop ${flags} to write the directory's tree.`;
|
|
22797
22965
|
}
|
|
22798
|
-
var isDirectory = (p) =>
|
|
22966
|
+
var isDirectory = (p) => fs33.existsSync(p) && fs33.statSync(p).isDirectory();
|
|
22799
22967
|
|
|
22800
22968
|
// src/cli/platform/worlds.ts
|
|
22801
22969
|
var WORLDS3 = "/api/public/worlds";
|
|
22802
22970
|
function collectFiles(directory) {
|
|
22803
|
-
if (!
|
|
22971
|
+
if (!fs37.existsSync(directory) || !fs37.statSync(directory).isDirectory())
|
|
22804
22972
|
throw new CliError(`${directory}: not a directory`, 1);
|
|
22805
22973
|
return walk2(directory).map((relative6) => {
|
|
22806
|
-
const bytes =
|
|
22974
|
+
const bytes = fs37.readFileSync(path30.join(directory, relative6));
|
|
22807
22975
|
const text2 = bytes.toString("utf8");
|
|
22808
22976
|
return Buffer.from(text2, "utf8").equals(bytes) && !text2.includes("\uFFFD") ? { path: relative6, content: text2 } : {
|
|
22809
22977
|
path: relative6,
|
|
@@ -22821,7 +22989,7 @@ async function describeLocalDirectory(dir, hostFlag) {
|
|
|
22821
22989
|
const counts = await showLocalWorldData2(dir, void 0, creds);
|
|
22822
22990
|
return describedLocally2(withRowCounts2(description, counts.entity_counts ?? {}), dir);
|
|
22823
22991
|
}
|
|
22824
|
-
var isDir = (candidate) =>
|
|
22992
|
+
var isDir = (candidate) => fs37.existsSync(candidate) && fs37.statSync(candidate).isDirectory();
|
|
22825
22993
|
function worldTreeFiles(from) {
|
|
22826
22994
|
if (classifyTree(from).shape !== "none") return collectFiles(from);
|
|
22827
22995
|
const files = collectFiles(from);
|
|
@@ -22929,7 +23097,7 @@ async function createOne(creds, body) {
|
|
|
22929
23097
|
return api(creds, "POST", WORLDS3, body, { timeoutMs: 6e5 });
|
|
22930
23098
|
}
|
|
22931
23099
|
async function runBatch(file, args, ctx) {
|
|
22932
|
-
const text2 = file === "-" ?
|
|
23100
|
+
const text2 = file === "-" ? fs37.readFileSync(0, "utf8") : fs37.readFileSync(file, "utf8");
|
|
22933
23101
|
const requests = text2.split("\n").map((line) => line.trim()).filter(Boolean).map(batchLine);
|
|
22934
23102
|
if (requests.length === 0)
|
|
22935
23103
|
throw new CliError("batch file holds no worlds", 1);
|
|
@@ -23126,21 +23294,21 @@ function registerWorldCommands(root) {
|
|
|
23126
23294
|
const options = worldsOptions(credentials(args));
|
|
23127
23295
|
const reports = slug ? [await migrateWorld(slug, { apply, force: arg.bool(args, "force") || void 0 }, options)] : (await migrateProjectWorlds({ apply }, options)).worlds;
|
|
23128
23296
|
if (arg.bool(args, "json")) printJson(ctx, slug ? reports[0] : { worlds: reports, applied: apply });
|
|
23129
|
-
else for (const
|
|
23297
|
+
else for (const report2 of reports) ctx.stdout(migrationLine(report2, apply));
|
|
23130
23298
|
if (!apply && reports.some((r) => !r.refusal && !r.unchanged))
|
|
23131
23299
|
ctx.stderr("dry run; add --apply to commit");
|
|
23132
23300
|
return reports.some((r) => r.refusal) ? 2 : 0;
|
|
23133
23301
|
}
|
|
23134
23302
|
});
|
|
23135
23303
|
}
|
|
23136
|
-
function migrationLine(
|
|
23137
|
-
if (
|
|
23138
|
-
return `${
|
|
23139
|
-
if (
|
|
23140
|
-
const head = `${
|
|
23141
|
-
if (
|
|
23142
|
-
return `${head} migrated as ${
|
|
23143
|
-
const plan =
|
|
23304
|
+
function migrationLine(report2, apply) {
|
|
23305
|
+
if (report2.refusal)
|
|
23306
|
+
return `${report2.slug}: ${report2.shape} -> refused (${report2.refusal.code}): ${report2.refusal.message}`;
|
|
23307
|
+
if (report2.unchanged) return `${report2.slug}: schema world already; nothing to migrate`;
|
|
23308
|
+
const head = `${report2.slug}: ${report2.shape} -> schema (${report2.files} files)`;
|
|
23309
|
+
if (report2.applied && report2.version)
|
|
23310
|
+
return `${head} migrated as ${report2.version.contentHash.slice(0, 12)}`;
|
|
23311
|
+
const plan = report2.actions.map((a) => `
|
|
23144
23312
|
- ${a}`).join("");
|
|
23145
23313
|
return apply ? `${head} unchanged (identical tree already the head)${plan}` : `${head} would:${plan}`;
|
|
23146
23314
|
}
|
|
@@ -23196,7 +23364,7 @@ function refuseKind(dir, classified, wanted, command2) {
|
|
|
23196
23364
|
);
|
|
23197
23365
|
}
|
|
23198
23366
|
function resolveKind(dir, args, command2) {
|
|
23199
|
-
if (!
|
|
23367
|
+
if (!fs38.existsSync(dir) || !fs38.statSync(dir).isDirectory()) throw new CliError(`Not a directory: ${dir}`, 1);
|
|
23200
23368
|
const classified = classifyTree(dir);
|
|
23201
23369
|
const actual = kindOfTree(classified);
|
|
23202
23370
|
const wanted = arg.str(args, "kind");
|
|
@@ -23206,7 +23374,7 @@ function resolveKind(dir, args, command2) {
|
|
|
23206
23374
|
}
|
|
23207
23375
|
function firstEntity(dir) {
|
|
23208
23376
|
try {
|
|
23209
|
-
const world = JSON.parse(
|
|
23377
|
+
const world = JSON.parse(fs38.readFileSync(path31.join(dir, "schema", "world.json"), "utf8"));
|
|
23210
23378
|
const entities = world["x-gateway"]?.entities ?? world.entities;
|
|
23211
23379
|
if (Array.isArray(entities)) return entities[0]?.name ?? null;
|
|
23212
23380
|
if (entities && typeof entities === "object") return Object.keys(entities)[0] ?? null;
|
|
@@ -23215,30 +23383,30 @@ function firstEntity(dir) {
|
|
|
23215
23383
|
return null;
|
|
23216
23384
|
}
|
|
23217
23385
|
function readConfig2(dir) {
|
|
23218
|
-
const file =
|
|
23219
|
-
if (!
|
|
23386
|
+
const file = path31.join(dir, BENCHMARK_CONFIG2);
|
|
23387
|
+
if (!fs38.existsSync(file)) return {};
|
|
23220
23388
|
try {
|
|
23221
|
-
return JSON.parse(
|
|
23389
|
+
return JSON.parse(fs38.readFileSync(file, "utf8"));
|
|
23222
23390
|
} catch {
|
|
23223
23391
|
throw new CliError(`${file} is not JSON`, 1);
|
|
23224
23392
|
}
|
|
23225
23393
|
}
|
|
23226
23394
|
function writeConfig2(dir, config) {
|
|
23227
|
-
|
|
23395
|
+
fs38.writeFileSync(path31.join(dir, BENCHMARK_CONFIG2), JSON.stringify({ ...config, note: "Defaults for `gateway benchmarks run` when --model / --rollouts are not given." }, null, 2) + "\n");
|
|
23228
23396
|
}
|
|
23229
|
-
function printValidation(ctx,
|
|
23230
|
-
ctx.stdout(`${
|
|
23231
|
-
for (const task of
|
|
23397
|
+
function printValidation(ctx, report2) {
|
|
23398
|
+
ctx.stdout(`${report2.dir}: ${report2.kind} benchmark \u2014 runner reads it as ${report2.detectedKind} \u2014 ${report2.ok ? "ok" : `${report2.problems.length + report2.tasks.reduce((n, t) => n + t.problems.length, 0)} problem(s)`}`);
|
|
23399
|
+
for (const task of report2.tasks) {
|
|
23232
23400
|
const image = imageLabel(task.image);
|
|
23233
23401
|
const secrets = task.secrets.length ? `; secrets ${task.secrets.join(", ")}` : "";
|
|
23234
23402
|
ctx.stdout(` ${task.problems.length ? "FAIL" : "ok "} ${task.id}: image ${image}${secrets}; instruction ${task.files.instruction ? "yes" : "MISSING"}; tests/test.sh ${task.files.tests ? "yes" : "MISSING"}; solution ${task.files.solution ? "yes" : "none"}`);
|
|
23235
23403
|
for (const problem of task.problems) ctx.stdout(` problem: ${problem}`);
|
|
23236
23404
|
for (const warning of task.warnings) ctx.stdout(` note: ${warning}`);
|
|
23237
23405
|
}
|
|
23238
|
-
if (
|
|
23239
|
-
ctx.stdout(` package ${
|
|
23240
|
-
for (const problem of
|
|
23241
|
-
for (const warning of
|
|
23406
|
+
if (report2.package)
|
|
23407
|
+
ctx.stdout(` package ${report2.package.name} (${report2.package.init}): ${report2.package.v1 ? "verifiers v1" : "verifiers v0"}; Taskset ${report2.package.taskset ?? "NONE"}; rewards ${report2.package.rewards.join(", ") || "none by name"}`);
|
|
23408
|
+
for (const problem of report2.problems) ctx.stdout(` problem: ${problem}`);
|
|
23409
|
+
for (const warning of report2.warnings) ctx.stdout(` note: ${warning}`);
|
|
23242
23410
|
}
|
|
23243
23411
|
function taskSummary(ids, shown2 = 5) {
|
|
23244
23412
|
const head = ids.slice(0, shown2).join(", ");
|
|
@@ -23307,7 +23475,7 @@ async function dryRunWorld(dir, task, opts = {}) {
|
|
|
23307
23475
|
};
|
|
23308
23476
|
if (!local)
|
|
23309
23477
|
return { ...base, note: `not executed: ${opts.plan ? "--plan" : localRuntimeReason() || "no bundled runtime"} \u2014 the steps above are what would run. ${base.note}` };
|
|
23310
|
-
const payload = await localBridge({ command: "dry-run", world:
|
|
23478
|
+
const payload = await localBridge({ command: "dry-run", world: path31.resolve(dir), task }, local);
|
|
23311
23479
|
const detail = detailFrom(payload);
|
|
23312
23480
|
if (detail) throw new BridgeRejected(detail);
|
|
23313
23481
|
const answer = payload;
|
|
@@ -23404,11 +23572,11 @@ proposals: \`gateway bench\`. Walkthrough: \`gateway worlds skill ${BENCHMARKS_S
|
|
|
23404
23572
|
"benchmarks init --kind image is not shipped: the benchmark runner has no hub engine for a bring-your-own image \u2014 its generic engine (deploy/benchmark-runner/engines/generic_runner.py) runs registry entries from benchmarks.json, not pushed versions, and `bench push --image` only records the ref on a world's server image. Shipping it needs an `image` kind in detect_env_kind, a runner branch that runs the version's imageRef through the generic engine and harvests a reward, and the harvest itself. Package the benchmark as a harbor task instead (`--kind harbor`: your image in [environment] docker_image, your grader in tests/test.sh).",
|
|
23405
23573
|
2
|
|
23406
23574
|
);
|
|
23407
|
-
if (
|
|
23575
|
+
if (fs38.existsSync(dir) && fs38.readdirSync(dir).length > 0)
|
|
23408
23576
|
throw new CliError(`${dir} is not empty; init writes a fresh ${kind} tree`, 1);
|
|
23409
23577
|
const models = arg.list(args, "model");
|
|
23410
23578
|
const rollouts = arg.int(args, "rollouts") ?? 1;
|
|
23411
|
-
const slug =
|
|
23579
|
+
const slug = path31.basename(path31.resolve(dir));
|
|
23412
23580
|
if (kind === "harbor") {
|
|
23413
23581
|
const scaffold = writeHarborScaffold(dir, {
|
|
23414
23582
|
name: arg.str(args, "name"),
|
|
@@ -23458,8 +23626,8 @@ proposals: \`gateway bench\`. Walkthrough: \`gateway worlds skill ${BENCHMARKS_S
|
|
|
23458
23626
|
if (verifiers.length === 0) {
|
|
23459
23627
|
const entity = firstEntity(dir);
|
|
23460
23628
|
if (!entity) throw new CliError(`${dir}: schema/world.json declares no entity to write a verifier for`, 1);
|
|
23461
|
-
|
|
23462
|
-
|
|
23629
|
+
fs38.mkdirSync(path31.join(dir, "verifiers"), { recursive: true });
|
|
23630
|
+
fs38.writeFileSync(path31.join(dir, "verifiers", "state_present.sql"), scaffoldVerifier(entity));
|
|
23463
23631
|
verifiers = ["state_present"];
|
|
23464
23632
|
}
|
|
23465
23633
|
const taskId = arg.str(args, "task") ?? "first_task";
|
|
@@ -23495,8 +23663,8 @@ proposals: \`gateway bench\`. Walkthrough: \`gateway worlds skill ${BENCHMARKS_S
|
|
|
23495
23663
|
const checked = await captureSub(root, ["worlds", "schema", "check", dir, ...host ? ["--host", host] : []], ctx);
|
|
23496
23664
|
ctx.stdout(checked.out);
|
|
23497
23665
|
if (checked.code !== 0) return checked.code;
|
|
23498
|
-
const
|
|
23499
|
-
const tasks = Array.isArray(
|
|
23666
|
+
const report3 = safeJson2(checked.out);
|
|
23667
|
+
const tasks = Array.isArray(report3.tasks) ? report3.tasks : [];
|
|
23500
23668
|
if (tasks.length === 0) {
|
|
23501
23669
|
ctx.stderr(`${dir} declares no [[tasks]]; a benchmark needs at least one: gateway worlds schema task add ${dir} <id> --prompt "..." --verifier <name>`);
|
|
23502
23670
|
return 2;
|
|
@@ -23504,11 +23672,11 @@ proposals: \`gateway bench\`. Walkthrough: \`gateway worlds skill ${BENCHMARKS_S
|
|
|
23504
23672
|
ctx.stderr(`benchmark ok (world): ${tasks.length} task(s): ${tasks.map((t) => t.id ?? "?").join(", ")}`);
|
|
23505
23673
|
return 0;
|
|
23506
23674
|
}
|
|
23507
|
-
const
|
|
23508
|
-
if (arg.bool(args, "json")) printJson(ctx,
|
|
23509
|
-
else printValidation(ctx,
|
|
23510
|
-
if (!
|
|
23511
|
-
ctx.stderr(`benchmark ok (${kind}): ${kind === "harbor" ? taskSummary(
|
|
23675
|
+
const report2 = kind === "harbor" ? validateHarbor(dir) : validateVerifiers(dir);
|
|
23676
|
+
if (arg.bool(args, "json")) printJson(ctx, report2);
|
|
23677
|
+
else printValidation(ctx, report2);
|
|
23678
|
+
if (!report2.ok) return 2;
|
|
23679
|
+
ctx.stderr(`benchmark ok (${kind}): ${kind === "harbor" ? taskSummary(report2.tasks.map((t) => t.id)) : `package ${report2.package?.name}`}; next: gateway benchmarks dry-run ${dir}`);
|
|
23512
23680
|
return 0;
|
|
23513
23681
|
};
|
|
23514
23682
|
benchmarks.command({
|
|
@@ -23627,12 +23795,12 @@ proposals: \`gateway bench\`. Walkthrough: \`gateway worlds skill ${BENCHMARKS_S
|
|
|
23627
23795
|
const force = arg.bool(args, "force");
|
|
23628
23796
|
const message = arg.str(args, "message");
|
|
23629
23797
|
const name = arg.str(args, "name");
|
|
23630
|
-
let
|
|
23798
|
+
let report2 = null;
|
|
23631
23799
|
if (kind !== "world") {
|
|
23632
|
-
|
|
23633
|
-
if (!
|
|
23800
|
+
report2 = kind === "harbor" ? validateHarbor(dir) : validateVerifiers(dir);
|
|
23801
|
+
if (!report2.ok)
|
|
23634
23802
|
throw new CliError(
|
|
23635
|
-
`benchmarks push: ${dir} does not validate (${[...
|
|
23803
|
+
`benchmarks push: ${dir} does not validate (${[...report2.problems, ...report2.tasks.flatMap((t) => t.problems)].slice(0, 3).join("; ")}); run \`gateway benchmarks validate ${dir}\``,
|
|
23636
23804
|
2
|
|
23637
23805
|
);
|
|
23638
23806
|
}
|
|
@@ -23646,7 +23814,7 @@ proposals: \`gateway bench\`. Walkthrough: \`gateway worlds skill ${BENCHMARKS_S
|
|
|
23646
23814
|
const existing = await existingSlug(creds, slug);
|
|
23647
23815
|
const incoming = kind === "world" ? "world" : "container";
|
|
23648
23816
|
if (existing?.substrate && existing.substrate !== incoming) refuseSlug(slug, existing, classified, incoming);
|
|
23649
|
-
const describe3 = kind === "harbor" ? `${
|
|
23817
|
+
const describe3 = kind === "harbor" ? `${report2.tasks.length} task(s)` : kind === "verifiers" ? `package ${report2.package?.name}` : `${tasks.length} task(s)`;
|
|
23650
23818
|
if (kind !== "world" || existing?.substrate === "world") {
|
|
23651
23819
|
const pushed = await push(dir, { slug, name, message, force, options: worldsOptions(creds) }).catch((err) => {
|
|
23652
23820
|
if (!branchMoved(err)) throw err;
|
|
@@ -23714,7 +23882,7 @@ before anything is sent); dispatch again for more. Never set max_tokens on the m
|
|
|
23714
23882
|
const dirFlag = arg.str(args, "dir");
|
|
23715
23883
|
const config = dirFlag ? readConfig2(dirFlag) : {};
|
|
23716
23884
|
if (dirFlag) {
|
|
23717
|
-
const owner = config.slug ??
|
|
23885
|
+
const owner = config.slug ?? path31.basename(path31.resolve(dirFlag));
|
|
23718
23886
|
if (owner !== slug)
|
|
23719
23887
|
throw new CliError(`benchmarks run: --dir ${dirFlag} is the benchmark \`${owner}\` (its benchmark.json), not \`${slug}\`; pass that benchmark's --dir, or --model and -k explicitly`, 2);
|
|
23720
23888
|
}
|
|
@@ -23748,17 +23916,17 @@ before anything is sent); dispatch again for more. Never set max_tokens on the m
|
|
|
23748
23916
|
const dir = args.positionals[0];
|
|
23749
23917
|
const from = arg.str(args, "from");
|
|
23750
23918
|
if (from !== "harbor" && from !== "verifiers") throw new CliError("benchmarks import needs --from harbor|verifiers");
|
|
23751
|
-
if (!
|
|
23752
|
-
const
|
|
23753
|
-
if (arg.bool(args, "json")) printJson(ctx,
|
|
23919
|
+
if (!fs38.existsSync(dir) || !fs38.statSync(dir).isDirectory()) throw new CliError(`Not a directory: ${dir}`, 1);
|
|
23920
|
+
const report2 = importReport(dir, from);
|
|
23921
|
+
if (arg.bool(args, "json")) printJson(ctx, report2);
|
|
23754
23922
|
else {
|
|
23755
|
-
ctx.stdout(`${dir}: ${SHAPE_LABELS[
|
|
23756
|
-
for (const task of
|
|
23923
|
+
ctx.stdout(`${dir}: ${SHAPE_LABELS[report2.shape]} \u2014 ${report2.tasks.length} ${from} task(s), ${report2.converted} converted, ${report2.refused} refused`);
|
|
23924
|
+
for (const task of report2.tasks)
|
|
23757
23925
|
ctx.stdout(` ${task.expressible ? "ok " : "refused"} ${task.id}: ${task.grader}${task.prompt ? ` \u2014 "${task.prompt.slice(0, 80)}"` : ""}
|
|
23758
23926
|
${task.reason}`);
|
|
23759
|
-
ctx.stdout(
|
|
23927
|
+
ctx.stdout(report2.note);
|
|
23760
23928
|
}
|
|
23761
|
-
return
|
|
23929
|
+
return report2.refused > 0 || report2.tasks.length === 0 ? 2 : 0;
|
|
23762
23930
|
}
|
|
23763
23931
|
});
|
|
23764
23932
|
}
|
|
@@ -23771,8 +23939,8 @@ init_config();
|
|
|
23771
23939
|
init_router();
|
|
23772
23940
|
init_checkoutTarget();
|
|
23773
23941
|
import { execFile } from "child_process";
|
|
23774
|
-
import * as
|
|
23775
|
-
import * as
|
|
23942
|
+
import * as fs40 from "fs";
|
|
23943
|
+
import * as path33 from "path";
|
|
23776
23944
|
|
|
23777
23945
|
// src/cli/platform/dashboards/dashboardClient.ts
|
|
23778
23946
|
init_config();
|
|
@@ -23806,8 +23974,8 @@ var DashboardClient = class {
|
|
|
23806
23974
|
// src/cli/platform/dashboards/dashboardDir.ts
|
|
23807
23975
|
init_router();
|
|
23808
23976
|
import { createHash as createHash14 } from "crypto";
|
|
23809
|
-
import * as
|
|
23810
|
-
import * as
|
|
23977
|
+
import * as fs39 from "fs";
|
|
23978
|
+
import * as path32 from "path";
|
|
23811
23979
|
var DASHBOARD_MANIFEST = "gateway-dashboard.json";
|
|
23812
23980
|
var RENDER_DIR = "render";
|
|
23813
23981
|
var TRANSFORM_FILE = "transform.js";
|
|
@@ -23820,14 +23988,14 @@ var DashboardDir = class _DashboardDir {
|
|
|
23820
23988
|
root;
|
|
23821
23989
|
manifest;
|
|
23822
23990
|
static at(root) {
|
|
23823
|
-
return new _DashboardDir(
|
|
23991
|
+
return new _DashboardDir(path32.resolve(root), _DashboardDir.readManifest(root));
|
|
23824
23992
|
}
|
|
23825
23993
|
static isDashboard(root) {
|
|
23826
23994
|
return _DashboardDir.readManifest(root) !== null;
|
|
23827
23995
|
}
|
|
23828
23996
|
static readManifest(root) {
|
|
23829
23997
|
try {
|
|
23830
|
-
const parsed = JSON.parse(
|
|
23998
|
+
const parsed = JSON.parse(fs39.readFileSync(path32.join(root, DASHBOARD_MANIFEST), "utf8"));
|
|
23831
23999
|
return typeof parsed?.id === "string" && typeof parsed.stamp === "string" ? parsed : null;
|
|
23832
24000
|
} catch {
|
|
23833
24001
|
return null;
|
|
@@ -23860,7 +24028,7 @@ var DashboardDir = class _DashboardDir {
|
|
|
23860
24028
|
const local = this.localFiles();
|
|
23861
24029
|
const files = [...local.entries()].filter(([rel]) => rel.startsWith(`${RENDER_DIR}/`)).map(([rel, content]) => ({ path: rel.slice(RENDER_DIR.length + 1), content }));
|
|
23862
24030
|
if (files.length === 0)
|
|
23863
|
-
throw new CliError(`no render files under ${
|
|
24031
|
+
throw new CliError(`no render files under ${path32.join(this.root, RENDER_DIR)} \u2014 nothing to push`, 2);
|
|
23864
24032
|
const entry = manifest.entrypoint ?? void 0;
|
|
23865
24033
|
return {
|
|
23866
24034
|
files,
|
|
@@ -23876,7 +24044,7 @@ var DashboardDir = class _DashboardDir {
|
|
|
23876
24044
|
}
|
|
23877
24045
|
/** Lay a pulled or created dashboard into the directory and record it. */
|
|
23878
24046
|
write(code) {
|
|
23879
|
-
|
|
24047
|
+
fs39.mkdirSync(this.root, { recursive: true });
|
|
23880
24048
|
for (const file of code.files) this.writeFile(`${RENDER_DIR}/${file.path}`, file.content);
|
|
23881
24049
|
if (code.transform !== null) this.writeFile(TRANSFORM_FILE, code.transform);
|
|
23882
24050
|
return this.record({ ...code, files: this.hashes() });
|
|
@@ -23896,7 +24064,7 @@ var DashboardDir = class _DashboardDir {
|
|
|
23896
24064
|
url: manifest.url,
|
|
23897
24065
|
files: manifest.files
|
|
23898
24066
|
};
|
|
23899
|
-
|
|
24067
|
+
fs39.writeFileSync(path32.join(this.root, DASHBOARD_MANIFEST), JSON.stringify(kept, null, 2) + "\n");
|
|
23900
24068
|
return new _DashboardDir(this.root, kept);
|
|
23901
24069
|
}
|
|
23902
24070
|
hashes() {
|
|
@@ -23907,33 +24075,33 @@ var DashboardDir = class _DashboardDir {
|
|
|
23907
24075
|
/** Every regular file under `render/` plus `transform.js`; hidden files are skipped, links refused. */
|
|
23908
24076
|
localFiles() {
|
|
23909
24077
|
const out = /* @__PURE__ */ new Map();
|
|
23910
|
-
const renderRoot =
|
|
23911
|
-
if (
|
|
23912
|
-
const transform =
|
|
23913
|
-
if (
|
|
24078
|
+
const renderRoot = path32.join(this.root, RENDER_DIR);
|
|
24079
|
+
if (fs39.existsSync(renderRoot)) this.walk(renderRoot, out);
|
|
24080
|
+
const transform = path32.join(this.root, TRANSFORM_FILE);
|
|
24081
|
+
if (fs39.existsSync(transform)) out.set(TRANSFORM_FILE, this.readRegular(transform));
|
|
23914
24082
|
return new Map([...out.entries()].sort(([a], [b]) => a.localeCompare(b)));
|
|
23915
24083
|
}
|
|
23916
24084
|
walk(dir, out) {
|
|
23917
|
-
for (const entry of
|
|
24085
|
+
for (const entry of fs39.readdirSync(dir, { withFileTypes: true })) {
|
|
23918
24086
|
if (entry.name.startsWith(".")) continue;
|
|
23919
|
-
const full =
|
|
24087
|
+
const full = path32.join(dir, entry.name);
|
|
23920
24088
|
if (entry.isDirectory()) this.walk(full, out);
|
|
23921
|
-
else out.set(
|
|
24089
|
+
else out.set(path32.relative(this.root, full).split(path32.sep).join("/"), this.readRegular(full));
|
|
23922
24090
|
}
|
|
23923
24091
|
}
|
|
23924
24092
|
readRegular(file) {
|
|
23925
|
-
if (!
|
|
24093
|
+
if (!fs39.lstatSync(file).isFile())
|
|
23926
24094
|
throw new CliError(`${file} is not a regular file (links are not followed) \u2014 replace it with the file itself`, 2);
|
|
23927
|
-
return
|
|
24095
|
+
return fs39.readFileSync(file, "utf8");
|
|
23928
24096
|
}
|
|
23929
24097
|
/** A server-named path lands under the directory or not at all (B4). */
|
|
23930
24098
|
writeFile(rel, content) {
|
|
23931
24099
|
const parts2 = rel.split("/");
|
|
23932
|
-
const escapes =
|
|
24100
|
+
const escapes = path32.isAbsolute(rel) || rel.includes("\\") || parts2.some((p) => p === ".." || p === "");
|
|
23933
24101
|
if (escapes) throw new CliError(`refusing to write ${JSON.stringify(rel)}: not a path inside the dashboard`, 1);
|
|
23934
|
-
const target =
|
|
23935
|
-
|
|
23936
|
-
|
|
24102
|
+
const target = path32.join(this.root, ...parts2);
|
|
24103
|
+
fs39.mkdirSync(path32.dirname(target), { recursive: true });
|
|
24104
|
+
fs39.writeFileSync(target, content);
|
|
23937
24105
|
}
|
|
23938
24106
|
};
|
|
23939
24107
|
function dashboardDirName(name) {
|
|
@@ -23989,7 +24157,7 @@ function checkout(ctx, code, landing2) {
|
|
|
23989
24157
|
url: code.url
|
|
23990
24158
|
});
|
|
23991
24159
|
}
|
|
23992
|
-
var looksLikePath = (value) => value === "." || value.includes("/") || value.includes(
|
|
24160
|
+
var looksLikePath = (value) => value === "." || value.includes("/") || value.includes(path33.sep) || fs40.existsSync(value);
|
|
23993
24161
|
function dashboardId(target) {
|
|
23994
24162
|
const candidate = target ?? ".";
|
|
23995
24163
|
if (!looksLikePath(candidate)) return candidate;
|
|
@@ -24132,7 +24300,7 @@ function registerDashboardCommands(root) {
|
|
|
24132
24300
|
taskId: arg.str(args, "task"),
|
|
24133
24301
|
includeHtml: out ? true : void 0
|
|
24134
24302
|
});
|
|
24135
|
-
if (out && rendered.html !== null)
|
|
24303
|
+
if (out && rendered.html !== null) fs40.writeFileSync(out, rendered.html);
|
|
24136
24304
|
const summary2 = {
|
|
24137
24305
|
success: rendered.success,
|
|
24138
24306
|
error: rendered.error,
|
|
@@ -24141,7 +24309,7 @@ function registerDashboardCommands(root) {
|
|
|
24141
24309
|
executionTimeMs: rendered.executionTimeMs,
|
|
24142
24310
|
url: rendered.url
|
|
24143
24311
|
};
|
|
24144
|
-
printJson(ctx, out ? { ...summary2, out:
|
|
24312
|
+
printJson(ctx, out ? { ...summary2, out: path33.resolve(out) } : summary2);
|
|
24145
24313
|
return rendered.success ? 0 : 1;
|
|
24146
24314
|
}
|
|
24147
24315
|
});
|
|
@@ -24165,9 +24333,9 @@ function registerDashboardCommands(root) {
|
|
|
24165
24333
|
init_config();
|
|
24166
24334
|
init_router();
|
|
24167
24335
|
init_hub();
|
|
24168
|
-
import * as
|
|
24336
|
+
import * as fs47 from "fs";
|
|
24169
24337
|
import * as os7 from "os";
|
|
24170
|
-
import * as
|
|
24338
|
+
import * as path39 from "path";
|
|
24171
24339
|
import { Readable as Readable2 } from "stream";
|
|
24172
24340
|
init_shared();
|
|
24173
24341
|
init_batches();
|
|
@@ -24512,14 +24680,14 @@ function pyDumpsPlain(value) {
|
|
|
24512
24680
|
|
|
24513
24681
|
// src/cli/platform/worldData/ingestMap.ts
|
|
24514
24682
|
init_router();
|
|
24515
|
-
import * as
|
|
24516
|
-
import * as
|
|
24683
|
+
import * as fs41 from "fs";
|
|
24684
|
+
import * as path34 from "path";
|
|
24517
24685
|
var MAP_FILE = "ingest.toml";
|
|
24518
24686
|
var MAP_KINDS = ["tool-call", "rows", "csv"];
|
|
24519
24687
|
var SAMPLE_WIDTH = 48;
|
|
24520
24688
|
function readMapping(file) {
|
|
24521
|
-
if (!
|
|
24522
|
-
const text2 =
|
|
24689
|
+
if (!fs41.existsSync(file) || !fs41.statSync(file).isFile()) throw new CliError(`no mapping file at ${file}`, 1);
|
|
24690
|
+
const text2 = fs41.readFileSync(file, "utf8");
|
|
24523
24691
|
try {
|
|
24524
24692
|
parseToml(text2);
|
|
24525
24693
|
} catch (error) {
|
|
@@ -24529,8 +24697,8 @@ function readMapping(file) {
|
|
|
24529
24697
|
return text2;
|
|
24530
24698
|
}
|
|
24531
24699
|
function worldMapping(dir) {
|
|
24532
|
-
const file =
|
|
24533
|
-
return
|
|
24700
|
+
const file = path34.join(dir, MAP_FILE);
|
|
24701
|
+
return fs41.existsSync(file) ? fs41.readFileSync(file, "utf8") : null;
|
|
24534
24702
|
}
|
|
24535
24703
|
var isObject10 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24536
24704
|
function sample2(value) {
|
|
@@ -24641,7 +24809,7 @@ function skeleton(records2, entities, kind, opts = {}) {
|
|
|
24641
24809
|
// src/cli/platform/worldData/records.ts
|
|
24642
24810
|
init_router();
|
|
24643
24811
|
init_ingest();
|
|
24644
|
-
import * as
|
|
24812
|
+
import * as fs42 from "fs";
|
|
24645
24813
|
var FROM = ["tool-calls", "traces", "rows", "csv"];
|
|
24646
24814
|
function readInputRecords(files, from, readText4, options = {}) {
|
|
24647
24815
|
const records2 = [];
|
|
@@ -24669,8 +24837,8 @@ function readInputRecords(files, from, readText4, options = {}) {
|
|
|
24669
24837
|
return records2;
|
|
24670
24838
|
}
|
|
24671
24839
|
var readFileText = (file) => {
|
|
24672
|
-
if (!
|
|
24673
|
-
return
|
|
24840
|
+
if (!fs42.existsSync(file) || !fs42.statSync(file).isFile()) throw new CliError(`Cannot read ${file}`, 1);
|
|
24841
|
+
return fs42.readFileSync(file, "utf8");
|
|
24674
24842
|
};
|
|
24675
24843
|
|
|
24676
24844
|
// src/cli/platform/data.ts
|
|
@@ -24678,15 +24846,15 @@ init_transform();
|
|
|
24678
24846
|
|
|
24679
24847
|
// src/cli/platform/worldData/manifest.ts
|
|
24680
24848
|
init_router();
|
|
24681
|
-
import * as
|
|
24682
|
-
import * as
|
|
24683
|
-
var MANIFEST_DIR =
|
|
24849
|
+
import * as fs43 from "fs";
|
|
24850
|
+
import * as path35 from "path";
|
|
24851
|
+
var MANIFEST_DIR = path35.join(".gateway", "imports");
|
|
24684
24852
|
function manifestDir(cwd = process.cwd()) {
|
|
24685
|
-
return
|
|
24853
|
+
return path35.join(cwd, MANIFEST_DIR);
|
|
24686
24854
|
}
|
|
24687
24855
|
function manifestPath(batchId, cwd = process.cwd()) {
|
|
24688
24856
|
if (!/^[A-Za-z0-9_-]+$/.test(batchId)) throw new CliError(`Not a batch id: ${batchId}`);
|
|
24689
|
-
return
|
|
24857
|
+
return path35.join(manifestDir(cwd), `${batchId}.json`);
|
|
24690
24858
|
}
|
|
24691
24859
|
var stamp = () => (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
24692
24860
|
function newManifest(fields) {
|
|
@@ -24695,18 +24863,18 @@ function newManifest(fields) {
|
|
|
24695
24863
|
}
|
|
24696
24864
|
function writeManifest(manifest, cwd = process.cwd()) {
|
|
24697
24865
|
const file = manifestPath(manifest.batchId, cwd);
|
|
24698
|
-
|
|
24699
|
-
const ignore =
|
|
24700
|
-
if (!
|
|
24866
|
+
fs43.mkdirSync(path35.dirname(file), { recursive: true });
|
|
24867
|
+
const ignore = path35.join(cwd, ".gateway", ".gitignore");
|
|
24868
|
+
if (!fs43.existsSync(ignore)) fs43.writeFileSync(ignore, "*\n");
|
|
24701
24869
|
manifest.updatedAt = stamp();
|
|
24702
24870
|
const tmp = `${file}.tmp`;
|
|
24703
|
-
|
|
24704
|
-
|
|
24871
|
+
fs43.writeFileSync(tmp, JSON.stringify(manifest, null, 1) + "\n");
|
|
24872
|
+
fs43.renameSync(tmp, file);
|
|
24705
24873
|
return file;
|
|
24706
24874
|
}
|
|
24707
24875
|
function readManifest(batchId, cwd = process.cwd()) {
|
|
24708
24876
|
try {
|
|
24709
|
-
const parsed = JSON.parse(
|
|
24877
|
+
const parsed = JSON.parse(fs43.readFileSync(manifestPath(batchId, cwd), "utf8"));
|
|
24710
24878
|
return parsed && parsed.version === 1 && parsed.batchId === batchId ? parsed : null;
|
|
24711
24879
|
} catch {
|
|
24712
24880
|
return null;
|
|
@@ -24720,9 +24888,9 @@ function uploadedEntry(manifest, ordinal, digest2) {
|
|
|
24720
24888
|
}
|
|
24721
24889
|
function listManifests(cwd = process.cwd()) {
|
|
24722
24890
|
const dir = manifestDir(cwd);
|
|
24723
|
-
if (!
|
|
24891
|
+
if (!fs43.existsSync(dir)) return [];
|
|
24724
24892
|
const out = [];
|
|
24725
|
-
for (const name of
|
|
24893
|
+
for (const name of fs43.readdirSync(dir)) {
|
|
24726
24894
|
if (!name.endsWith(".json")) continue;
|
|
24727
24895
|
const manifest = readManifest(name.slice(0, -5), cwd);
|
|
24728
24896
|
if (manifest) out.push(manifest);
|
|
@@ -24739,14 +24907,14 @@ init_describe();
|
|
|
24739
24907
|
|
|
24740
24908
|
// src/cli/platform/worldData/worldConfig.ts
|
|
24741
24909
|
init_router();
|
|
24742
|
-
import * as
|
|
24743
|
-
import * as
|
|
24910
|
+
import * as fs44 from "fs";
|
|
24911
|
+
import * as path36 from "path";
|
|
24744
24912
|
function loadWorldConfig(dir) {
|
|
24745
|
-
const worldFile = ["schema/world.json", "world.json"].map((p) =>
|
|
24913
|
+
const worldFile = ["schema/world.json", "world.json"].map((p) => path36.join(dir, p)).find((p) => fs44.existsSync(p));
|
|
24746
24914
|
if (!worldFile) throw new CliError(`${dir} has no schema/world.json; extract needs a schema world`, 1);
|
|
24747
24915
|
let document;
|
|
24748
24916
|
try {
|
|
24749
|
-
document = JSON.parse(
|
|
24917
|
+
document = JSON.parse(fs44.readFileSync(worldFile, "utf8"));
|
|
24750
24918
|
} catch {
|
|
24751
24919
|
throw new CliError(`${worldFile} is not valid JSON`, 1);
|
|
24752
24920
|
}
|
|
@@ -24758,8 +24926,8 @@ function loadWorldConfig(dir) {
|
|
|
24758
24926
|
const primaryKey = Array.isArray(entity.primary_key) ? entity.primary_key : [];
|
|
24759
24927
|
entities[name] = { primaryKey, fields: declaredFields(document, entity.schema) };
|
|
24760
24928
|
}
|
|
24761
|
-
const connectorFile =
|
|
24762
|
-
const spec =
|
|
24929
|
+
const connectorFile = path36.join(dir, "connector.toml");
|
|
24930
|
+
const spec = fs44.existsSync(connectorFile) ? readSpec(connectorFile) : readEnvPolicy(path36.join(dir, "gateway-env.toml"));
|
|
24763
24931
|
return { dir, slug: spec.slug, entities, redact: spec.redact, envelope: spec.envelope, hitsKey: spec.hitsKey, operations: spec.operations };
|
|
24764
24932
|
}
|
|
24765
24933
|
function declaredFields(document, schema) {
|
|
@@ -24777,7 +24945,7 @@ function declaredFields(document, schema) {
|
|
|
24777
24945
|
var NO_SPEC = { slug: null, redact: { hash: [], drop: [], preserve: [], round: {} }, envelope: "", hitsKey: "hits", operations: {} };
|
|
24778
24946
|
function readToml(file) {
|
|
24779
24947
|
try {
|
|
24780
|
-
return parseToml(
|
|
24948
|
+
return parseToml(fs44.readFileSync(file, "utf8"));
|
|
24781
24949
|
} catch (error) {
|
|
24782
24950
|
if (error instanceof TomlError) throw new CliError(`${file}: ${error.message}`, 1);
|
|
24783
24951
|
throw error;
|
|
@@ -24797,7 +24965,7 @@ function readSpec(file) {
|
|
|
24797
24965
|
};
|
|
24798
24966
|
}
|
|
24799
24967
|
function readEnvPolicy(file) {
|
|
24800
|
-
if (!
|
|
24968
|
+
if (!fs44.existsSync(file)) return NO_SPEC;
|
|
24801
24969
|
const raw = readToml(file);
|
|
24802
24970
|
if (raw.redact === void 0) return NO_SPEC;
|
|
24803
24971
|
const name = table2(raw.environment).name;
|
|
@@ -24837,21 +25005,21 @@ function rounding(value) {
|
|
|
24837
25005
|
init_config();
|
|
24838
25006
|
init_router();
|
|
24839
25007
|
init_hub();
|
|
24840
|
-
import * as
|
|
25008
|
+
import * as fs46 from "fs";
|
|
24841
25009
|
import * as os6 from "os";
|
|
24842
|
-
import * as
|
|
25010
|
+
import * as path38 from "path";
|
|
24843
25011
|
|
|
24844
25012
|
// src/cli/platform/worldData/driveIo.ts
|
|
24845
25013
|
init_files();
|
|
24846
25014
|
init_shared();
|
|
24847
|
-
import * as
|
|
25015
|
+
import * as fs45 from "fs";
|
|
24848
25016
|
import * as os5 from "os";
|
|
24849
|
-
import * as
|
|
25017
|
+
import * as path37 from "path";
|
|
24850
25018
|
async function stageDriveInputs(inputs, creds) {
|
|
24851
25019
|
if (!inputs.some(isDriveRef))
|
|
24852
25020
|
return { files: inputs, labels: {}, cleanup: () => void 0 };
|
|
24853
|
-
const scratch =
|
|
24854
|
-
const cleanup = () =>
|
|
25021
|
+
const scratch = fs45.mkdtempSync(path37.join(os5.tmpdir(), "gateway-drive-in-"));
|
|
25022
|
+
const cleanup = () => fs45.rmSync(scratch, { recursive: true, force: true });
|
|
24855
25023
|
const labels = {};
|
|
24856
25024
|
const files = [];
|
|
24857
25025
|
try {
|
|
@@ -24862,7 +25030,7 @@ async function stageDriveInputs(inputs, creds) {
|
|
|
24862
25030
|
continue;
|
|
24863
25031
|
}
|
|
24864
25032
|
const target = drivePath(input);
|
|
24865
|
-
const local =
|
|
25033
|
+
const local = path37.join(scratch, `${index2}-${path37.basename(target)}`);
|
|
24866
25034
|
await downloadFile(options, target, local);
|
|
24867
25035
|
labels[local] = `drive:${target}`;
|
|
24868
25036
|
files.push(local);
|
|
@@ -24885,10 +25053,10 @@ async function landInDrive(localFile, to, creds) {
|
|
|
24885
25053
|
});
|
|
24886
25054
|
}
|
|
24887
25055
|
function scratchFile(name) {
|
|
24888
|
-
const dir =
|
|
25056
|
+
const dir = fs45.mkdtempSync(path37.join(os5.tmpdir(), "gateway-drive-out-"));
|
|
24889
25057
|
return {
|
|
24890
|
-
file:
|
|
24891
|
-
cleanup: () =>
|
|
25058
|
+
file: path37.join(dir, name),
|
|
25059
|
+
cleanup: () => fs45.rmSync(dir, { recursive: true, force: true })
|
|
24892
25060
|
};
|
|
24893
25061
|
}
|
|
24894
25062
|
var TO_FLAG = {
|
|
@@ -24931,7 +25099,7 @@ var TreeImport = class _TreeImport {
|
|
|
24931
25099
|
/** The platform slug this directory would import into: its pulled metadata, else its name. */
|
|
24932
25100
|
get slug() {
|
|
24933
25101
|
const slug = readLocalMeta(this.dir)?.slug;
|
|
24934
|
-
return typeof slug === "string" && slug ? slug :
|
|
25102
|
+
return typeof slug === "string" && slug ? slug : path38.basename(path38.resolve(this.dir));
|
|
24935
25103
|
}
|
|
24936
25104
|
/** Import (or, `dryRun`, prove) the files; prints the report `data check` prints; the exit code. */
|
|
24937
25105
|
async run(dryRun) {
|
|
@@ -25004,7 +25172,7 @@ var TreeImport = class _TreeImport {
|
|
|
25004
25172
|
`${what} across ${paths.length} file(s) exceed the inline cap (${INLINE_ROWS} rows / ${INLINE_BYTES} bytes) a directory takes at once without the bundled runtime; install python3 (the runtime then streams the files in place, 4 MiB / 100000 rows), split the rows into smaller files, or import into the platform world \`${this.slug}\` (\`gateway worlds data import ${this.slug} <rows>\`), which streams them`,
|
|
25005
25173
|
1
|
|
25006
25174
|
);
|
|
25007
|
-
const size = paths.reduce((n, p) => n +
|
|
25175
|
+
const size = paths.reduce((n, p) => n + fs46.statSync(p).size, 0);
|
|
25008
25176
|
if (size > INLINE_BYTES) throw tooLarge(`${size} bytes`);
|
|
25009
25177
|
let count = 0;
|
|
25010
25178
|
for await (const _ of readRows(paths.map(fileInput), this.entity))
|
|
@@ -25026,8 +25194,8 @@ var TreeImport = class _TreeImport {
|
|
|
25026
25194
|
});
|
|
25027
25195
|
return 2;
|
|
25028
25196
|
}
|
|
25029
|
-
write(
|
|
25030
|
-
if (this.report !== void 0)
|
|
25197
|
+
write(report2) {
|
|
25198
|
+
if (this.report !== void 0) fs46.writeFileSync(this.report, report2);
|
|
25031
25199
|
}
|
|
25032
25200
|
};
|
|
25033
25201
|
var StagedPaths = class {
|
|
@@ -25040,13 +25208,13 @@ var StagedPaths = class {
|
|
|
25040
25208
|
async stage(ctx) {
|
|
25041
25209
|
for (const file of this.files) {
|
|
25042
25210
|
if (file === "-") {
|
|
25043
|
-
this.scratch ??=
|
|
25044
|
-
const stdin =
|
|
25045
|
-
|
|
25211
|
+
this.scratch ??= fs46.mkdtempSync(path38.join(os6.tmpdir(), "gateway-stdin-"));
|
|
25212
|
+
const stdin = path38.join(this.scratch, "stdin.rows");
|
|
25213
|
+
fs46.writeFileSync(stdin, await ctx.stdin());
|
|
25046
25214
|
this.list.push(stdin);
|
|
25047
25215
|
continue;
|
|
25048
25216
|
}
|
|
25049
|
-
if (!
|
|
25217
|
+
if (!fs46.existsSync(file) || !fs46.statSync(file).isFile()) throw new CliError(`Cannot read ${file}`, 1);
|
|
25050
25218
|
this.list.push(file);
|
|
25051
25219
|
}
|
|
25052
25220
|
}
|
|
@@ -25061,7 +25229,7 @@ var StagedPaths = class {
|
|
|
25061
25229
|
return total;
|
|
25062
25230
|
}
|
|
25063
25231
|
dispose() {
|
|
25064
|
-
if (this.scratch)
|
|
25232
|
+
if (this.scratch) fs46.rmSync(this.scratch, { recursive: true, force: true });
|
|
25065
25233
|
}
|
|
25066
25234
|
};
|
|
25067
25235
|
function refusalsFromBridge(detail) {
|
|
@@ -25120,11 +25288,11 @@ function registerDataReadCommands(data) {
|
|
|
25120
25288
|
slugOf(slug)
|
|
25121
25289
|
).get(batchId);
|
|
25122
25290
|
printJson(ctx, printableStatus(status));
|
|
25123
|
-
const
|
|
25124
|
-
if (
|
|
25125
|
-
const written = await writeRefusalReport(status,
|
|
25291
|
+
const report2 = arg.str(args, "report");
|
|
25292
|
+
if (report2 === void 0) return;
|
|
25293
|
+
const written = await writeRefusalReport(status, report2);
|
|
25126
25294
|
ctx.stderr(
|
|
25127
|
-
`${written} refusal${written === 1 ? "" : "s"} written to ${
|
|
25295
|
+
`${written} refusal${written === 1 ? "" : "s"} written to ${report2}`
|
|
25128
25296
|
);
|
|
25129
25297
|
}
|
|
25130
25298
|
});
|
|
@@ -25497,7 +25665,7 @@ primary key, the world's [redact] policy applied. Summary on stderr:
|
|
|
25497
25665
|
const file = local ?? scratch?.file ?? null;
|
|
25498
25666
|
try {
|
|
25499
25667
|
const input = source2 === "-" ? stdinInput(ctx) : fileInput(staged.files[0]);
|
|
25500
|
-
const sink = file ?
|
|
25668
|
+
const sink = file ? fs47.createWriteStream(file) : null;
|
|
25501
25669
|
const write = sink ? (line) => void sink.write(line + "\n") : (line) => ctx.stdout(line);
|
|
25502
25670
|
const summary2 = await extractRows(
|
|
25503
25671
|
input,
|
|
@@ -25972,7 +26140,7 @@ function rowInputs(files, ctx) {
|
|
|
25972
26140
|
if (files.filter((f) => f === "-").length > 1)
|
|
25973
26141
|
throw new CliError("stdin (-) can be read once");
|
|
25974
26142
|
for (const file of files) {
|
|
25975
|
-
if (file !== "-" && !(
|
|
26143
|
+
if (file !== "-" && !(fs47.existsSync(file) && fs47.statSync(file).isFile()))
|
|
25976
26144
|
throw new CliError(`Cannot read ${file}`, 1);
|
|
25977
26145
|
}
|
|
25978
26146
|
return files.map((f) => f === "-" ? stdinInput(ctx) : fileInput(f));
|
|
@@ -26231,11 +26399,11 @@ async function pullCalls(out, to, from, staged, args, ctx) {
|
|
|
26231
26399
|
const toStdout = out === "-";
|
|
26232
26400
|
if (toStdout) {
|
|
26233
26401
|
if (text2) process.stdout.write(text2);
|
|
26234
|
-
} else if (out)
|
|
26402
|
+
} else if (out) fs47.writeFileSync(out, text2);
|
|
26235
26403
|
let landed;
|
|
26236
26404
|
if (to) {
|
|
26237
26405
|
const scratch = out && !toStdout ? null : scratchFile("calls.jsonl");
|
|
26238
|
-
if (scratch)
|
|
26406
|
+
if (scratch) fs47.writeFileSync(scratch.file, text2);
|
|
26239
26407
|
try {
|
|
26240
26408
|
landed = `drive:${(await landInDrive(scratch?.file ?? out, to, credentials(args))).path}`;
|
|
26241
26409
|
} finally {
|
|
@@ -26292,20 +26460,20 @@ async function mapInitCommand(world, samples, args, ctx) {
|
|
|
26292
26460
|
delimiter: delimiterFlag(args) ?? void 0
|
|
26293
26461
|
});
|
|
26294
26462
|
const text2 = skeleton(records2, config.entities, kind, {
|
|
26295
|
-
sampleName: samples.map((f) =>
|
|
26463
|
+
sampleName: samples.map((f) => path39.basename(f)).join(", "),
|
|
26296
26464
|
entity: arg.str(args, "entity")
|
|
26297
26465
|
});
|
|
26298
|
-
const out = arg.str(args, "out") ?? (local ?
|
|
26466
|
+
const out = arg.str(args, "out") ?? (local ? path39.join(world, MAP_FILE) : "-");
|
|
26299
26467
|
if (out === "-") {
|
|
26300
26468
|
ctx.stdout(text2.replace(/\n$/, ""));
|
|
26301
26469
|
return 0;
|
|
26302
26470
|
}
|
|
26303
|
-
if (
|
|
26471
|
+
if (fs47.existsSync(out) && !arg.bool(args, "dry-run"))
|
|
26304
26472
|
throw new CliError(
|
|
26305
26473
|
`${out} exists; pass --out for another path, or move it first`,
|
|
26306
26474
|
1
|
|
26307
26475
|
);
|
|
26308
|
-
|
|
26476
|
+
fs47.writeFileSync(out, text2);
|
|
26309
26477
|
const fromFlag = from === "tool-calls" ? "" : ` --from ${from}`;
|
|
26310
26478
|
ctx.stderr(
|
|
26311
26479
|
`wrote ${out}: fill in the entity and fields, then run \`gateway worlds data ingest ${world} ${samples[0]}${fromFlag} --map ${out} --dry-run\``
|
|
@@ -26533,12 +26701,12 @@ async function ingestCommand(world, inputs, args, ctx, labels = {}) {
|
|
|
26533
26701
|
const full = out;
|
|
26534
26702
|
let code = full.refusals.length ? 2 : 0;
|
|
26535
26703
|
if (!local && !dryRun && !full.refusals.length && Object.keys(projected).length) {
|
|
26536
|
-
const scratch =
|
|
26537
|
-
|
|
26704
|
+
const scratch = fs47.mkdtempSync(
|
|
26705
|
+
path39.join(os7.tmpdir(), "gateway-ingest-rows-")
|
|
26538
26706
|
);
|
|
26539
26707
|
try {
|
|
26540
|
-
const rowsFile =
|
|
26541
|
-
|
|
26708
|
+
const rowsFile = path39.join(scratch, "rows.json");
|
|
26709
|
+
fs47.writeFileSync(rowsFile, JSON.stringify(projected));
|
|
26542
26710
|
code = await importBatch(
|
|
26543
26711
|
world,
|
|
26544
26712
|
[rowsFile],
|
|
@@ -26553,11 +26721,11 @@ async function ingestCommand(world, inputs, args, ctx, labels = {}) {
|
|
|
26553
26721
|
}
|
|
26554
26722
|
);
|
|
26555
26723
|
} finally {
|
|
26556
|
-
|
|
26724
|
+
fs47.rmSync(scratch, { recursive: true, force: true });
|
|
26557
26725
|
}
|
|
26558
26726
|
}
|
|
26559
26727
|
if (reportFile !== void 0)
|
|
26560
|
-
|
|
26728
|
+
fs47.writeFileSync(
|
|
26561
26729
|
reportFile,
|
|
26562
26730
|
full.refusals.map((r) => JSON.stringify(r) + "\n").join("")
|
|
26563
26731
|
);
|
|
@@ -26567,38 +26735,38 @@ async function ingestCommand(world, inputs, args, ctx, labels = {}) {
|
|
|
26567
26735
|
return code;
|
|
26568
26736
|
}
|
|
26569
26737
|
var pairs = (table3) => Object.entries(table3).sort().map(([key2, count]) => `${key2} ${count}`).join(", ");
|
|
26570
|
-
function renderIngest(
|
|
26571
|
-
const skipped = Object.values(
|
|
26738
|
+
function renderIngest(report2, ctx) {
|
|
26739
|
+
const skipped = Object.values(report2.skipped).reduce((n, c) => n + c, 0);
|
|
26572
26740
|
ctx.stdout(
|
|
26573
|
-
`${
|
|
26741
|
+
`${report2.records} records, ${report2.ingested} ingested, ${skipped} skipped, ${report2.refusals.length} refused` + (report2.dryRun ? " (dry run)" : "") + (report2.via ? ` \u2014 via ${report2.via}` : "")
|
|
26574
26742
|
);
|
|
26575
|
-
for (const [entity, count] of Object.entries(
|
|
26743
|
+
for (const [entity, count] of Object.entries(report2.rows).sort())
|
|
26576
26744
|
ctx.stdout(` ${entity}: ${count} rows`);
|
|
26577
|
-
if (
|
|
26578
|
-
if (skipped) ctx.stdout(` skipped: ${pairs(
|
|
26579
|
-
if (
|
|
26745
|
+
if (report2.note) ctx.stdout(` note: ${report2.note}`);
|
|
26746
|
+
if (skipped) ctx.stdout(` skipped: ${pairs(report2.skipped)}`);
|
|
26747
|
+
if (report2.unmatched && Object.keys(report2.unmatched).length)
|
|
26580
26748
|
ctx.stdout(
|
|
26581
|
-
` unmatched (no [[sources]] claimed them, skipped): ${pairs(
|
|
26749
|
+
` unmatched (no [[sources]] claimed them, skipped): ${pairs(report2.unmatched)}`
|
|
26582
26750
|
);
|
|
26583
|
-
if (
|
|
26751
|
+
if (report2.unknownTools && Object.keys(report2.unknownTools).length)
|
|
26584
26752
|
ctx.stdout(
|
|
26585
|
-
` not the world's operations (not converted): ${pairs(
|
|
26753
|
+
` not the world's operations (not converted): ${pairs(report2.unknownTools)}`
|
|
26586
26754
|
);
|
|
26587
|
-
if (
|
|
26588
|
-
ctx.stdout(` observations not converted: ${pairs(
|
|
26589
|
-
if (
|
|
26590
|
-
for (const source2 of
|
|
26591
|
-
for (const refusal of
|
|
26755
|
+
if (report2.notConverted && Object.keys(report2.notConverted).length)
|
|
26756
|
+
ctx.stdout(` observations not converted: ${pairs(report2.notConverted)}`);
|
|
26757
|
+
if (report2.filtered) ctx.stdout(` dropped by --tool: ${report2.filtered}`);
|
|
26758
|
+
for (const source2 of report2.sources ?? []) renderSource(source2, ctx);
|
|
26759
|
+
for (const refusal of report2.refusals)
|
|
26592
26760
|
ctx.stdout(
|
|
26593
26761
|
` refused [${refusal.index ?? "-"}] ${refusal.tool ?? refusal.pointer ?? "-"}: ${refusal.reason}`
|
|
26594
26762
|
);
|
|
26595
|
-
if (
|
|
26763
|
+
if (report2.batch)
|
|
26596
26764
|
ctx.stdout(
|
|
26597
|
-
` batch ${String(
|
|
26765
|
+
` batch ${String(report2.batch.batchId ?? "?")} ${String(report2.batch.state ?? "?")}` + (report2.batch.versionId ? ` -> version ${String(report2.batch.versionId)}` : "")
|
|
26598
26766
|
);
|
|
26599
|
-
if (
|
|
26600
|
-
ctx.stdout(` entity counts: ${pairs(
|
|
26601
|
-
if (
|
|
26767
|
+
if (report2.entityCounts)
|
|
26768
|
+
ctx.stdout(` entity counts: ${pairs(report2.entityCounts)}`);
|
|
26769
|
+
if (report2.redact !== "off") ctx.stdout(` redact: ${report2.redact}`);
|
|
26602
26770
|
}
|
|
26603
26771
|
function renderSource(source2, ctx) {
|
|
26604
26772
|
ctx.stdout(
|
|
@@ -26614,8 +26782,8 @@ function renderSource(source2, ctx) {
|
|
|
26614
26782
|
ctx.stdout(` ${entity} fields never set: ${fields.join(", ")}`);
|
|
26615
26783
|
}
|
|
26616
26784
|
async function pullWorld(slugRef, creds) {
|
|
26617
|
-
const target =
|
|
26618
|
-
|
|
26785
|
+
const target = path39.join(
|
|
26786
|
+
fs47.mkdtempSync(path39.join(os7.tmpdir(), "gateway-world-data-")),
|
|
26619
26787
|
slugOf(slugRef)
|
|
26620
26788
|
);
|
|
26621
26789
|
const pulled = await pull(slugRef, target, worldsOptions(creds));
|
|
@@ -26626,17 +26794,17 @@ async function pullWorld(slugRef, creds) {
|
|
|
26626
26794
|
init_config();
|
|
26627
26795
|
init_router();
|
|
26628
26796
|
init_shared();
|
|
26629
|
-
import * as
|
|
26630
|
-
import * as
|
|
26797
|
+
import * as fs48 from "fs";
|
|
26798
|
+
import * as path40 from "path";
|
|
26631
26799
|
function readDatasetItems(file) {
|
|
26632
|
-
const raw =
|
|
26633
|
-
const looksJson =
|
|
26800
|
+
const raw = fs48.readFileSync(file, "utf8").trim();
|
|
26801
|
+
const looksJson = path40.extname(file) === ".json" || raw.startsWith("{") || raw.startsWith("[");
|
|
26634
26802
|
if (looksJson) {
|
|
26635
26803
|
let data;
|
|
26636
26804
|
try {
|
|
26637
26805
|
data = JSON.parse(raw);
|
|
26638
26806
|
} catch (error) {
|
|
26639
|
-
if (
|
|
26807
|
+
if (path40.extname(file) === ".json") throw error;
|
|
26640
26808
|
data = void 0;
|
|
26641
26809
|
}
|
|
26642
26810
|
if (data !== void 0) {
|
|
@@ -26674,10 +26842,10 @@ function registerDatasetCommands(root) {
|
|
|
26674
26842
|
const file = args.positionals[0];
|
|
26675
26843
|
const name = arg.str(args, "name");
|
|
26676
26844
|
if (!name) throw new CliError("dataset upload needs --name");
|
|
26677
|
-
if (!
|
|
26845
|
+
if (!fs48.existsSync(file)) throw new CliError(`Error: File not found: ${file}`, 1);
|
|
26678
26846
|
const items = readDatasetItems(file);
|
|
26679
26847
|
if (items.length === 0) throw new CliError("Error: No items found in file.", 1);
|
|
26680
|
-
ctx.stdout(`Found ${items.length} items in ${
|
|
26848
|
+
ctx.stdout(`Found ${items.length} items in ${path40.basename(file)}`);
|
|
26681
26849
|
const creds = credentials(args);
|
|
26682
26850
|
const agent = arg.str(args, "agent");
|
|
26683
26851
|
if (agent) {
|
|
@@ -26713,8 +26881,8 @@ init_config();
|
|
|
26713
26881
|
init_router();
|
|
26714
26882
|
init_files();
|
|
26715
26883
|
init_shared();
|
|
26716
|
-
import * as
|
|
26717
|
-
import * as
|
|
26884
|
+
import * as fs49 from "fs";
|
|
26885
|
+
import * as path41 from "path";
|
|
26718
26886
|
var PATH_HELP = "Path in the drive, e.g. corpora/train.jsonl (a drive: prefix is accepted).";
|
|
26719
26887
|
var JSON_FLAG2 = { name: "json", help: "Print the platform's JSON instead of the summary.", boolean: true };
|
|
26720
26888
|
function registerFilesCommands(root) {
|
|
@@ -26790,7 +26958,7 @@ function registerFilesCommands(root) {
|
|
|
26790
26958
|
flags: [{ name: "out", help: "Local path to write (default the file's own name in the working directory)." }, HOST_FLAG],
|
|
26791
26959
|
run: async (args, ctx) => {
|
|
26792
26960
|
const target = drivePath(args.positionals[0]);
|
|
26793
|
-
const out = arg.str(args, "out") ??
|
|
26961
|
+
const out = arg.str(args, "out") ?? path41.basename(target);
|
|
26794
26962
|
const result = await downloadFile(worldsOptions(credentials(args)), target, out, progressReporter(ctx, `drive:${target}`));
|
|
26795
26963
|
ctx.stdout(`drive:${result.path} -> ${out} (${result.sizeBytes ?? "?"} bytes)`);
|
|
26796
26964
|
}
|
|
@@ -26850,7 +27018,7 @@ function registerFilesCommands(root) {
|
|
|
26850
27018
|
{ name: "to", help: "Drive path to save to, e.g. imports/products.csv." },
|
|
26851
27019
|
{
|
|
26852
27020
|
name: "header",
|
|
26853
|
-
help: 'Request header "Name: value" (repeatable). A value may name a project secret as {{secret:NAME}}; the platform expands it, the secret never reaches this machine.',
|
|
27021
|
+
help: 'Request header "Name: value" (repeatable). A value may name a project secret as {{secret:NAME}}; the platform expands it, the secret never reaches this machine, and it is sent only to the origins the secret lists.',
|
|
26854
27022
|
repeat: true
|
|
26855
27023
|
},
|
|
26856
27024
|
{ name: "content-type", help: "MIME type to record (default: the response's, else from the name)." },
|
|
@@ -26859,7 +27027,7 @@ function registerFilesCommands(root) {
|
|
|
26859
27027
|
JSON_FLAG2,
|
|
26860
27028
|
HOST_FLAG
|
|
26861
27029
|
],
|
|
26862
|
-
notes: "The platform fetches the URL (MCP twin download_url_to_drive, route POST /api/public/files/fetch): the bytes\nnever touch this machine
|
|
27030
|
+
notes: "The platform fetches the URL (MCP twin download_url_to_drive, route POST /api/public/files/fetch): the bytes\nnever touch this machine. A plain --header goes only to the URL's origin, never to a host a redirect points at;\none that names a project secret also follows a redirect to another origin that secret lists. The secret must\nexist and list the URL's origin (`gateway secret set NAME\n--allowed-origin <origin>`, or `gateway secret origins NAME <origin>`); the platform refuses an unknown secret,\none with no origins, an unlisted origin and a redirect to one by name, and never echoes an expanded\nvalue. An http:// URL is fetched with a plaintext warning.\n--local downloads here and uploads the bytes, for a URL the platform cannot reach.",
|
|
26863
27031
|
run: async (args, ctx) => {
|
|
26864
27032
|
const url = args.positionals[0];
|
|
26865
27033
|
const to = arg.str(args, "to");
|
|
@@ -26902,23 +27070,23 @@ function planUploads(inputs, to) {
|
|
|
26902
27070
|
const join39 = (...parts2) => parts2.filter(Boolean).join("/");
|
|
26903
27071
|
const plan = [];
|
|
26904
27072
|
for (const input of inputs) {
|
|
26905
|
-
if (!
|
|
26906
|
-
if (
|
|
26907
|
-
const root =
|
|
26908
|
-
for (const file of walk3(root)) plan.push({ local: file, path: join39(base,
|
|
27073
|
+
if (!fs49.existsSync(input)) throw new CliError(`${input} does not exist`, 1);
|
|
27074
|
+
if (fs49.statSync(input).isDirectory()) {
|
|
27075
|
+
const root = path41.resolve(input);
|
|
27076
|
+
for (const file of walk3(root)) plan.push({ local: file, path: join39(base, path41.basename(root), path41.relative(root, file).split(path41.sep).join("/")) });
|
|
26909
27077
|
continue;
|
|
26910
27078
|
}
|
|
26911
|
-
const oneFileNamedInFull = inputs.length === 1 && base !== "" && !to.endsWith("/") &&
|
|
26912
|
-
plan.push({ local: input, path: oneFileNamedInFull ? base : join39(base,
|
|
27079
|
+
const oneFileNamedInFull = inputs.length === 1 && base !== "" && !to.endsWith("/") && path41.extname(base) !== "";
|
|
27080
|
+
plan.push({ local: input, path: oneFileNamedInFull ? base : join39(base, path41.basename(input)) });
|
|
26913
27081
|
}
|
|
26914
27082
|
if (!plan.length) throw new CliError("nothing to upload: the directories are empty", 1);
|
|
26915
27083
|
return plan;
|
|
26916
27084
|
}
|
|
26917
27085
|
function walk3(dir) {
|
|
26918
27086
|
const out = [];
|
|
26919
|
-
for (const entry of
|
|
27087
|
+
for (const entry of fs49.readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
26920
27088
|
if (entry.name.startsWith(".")) continue;
|
|
26921
|
-
const full =
|
|
27089
|
+
const full = path41.join(dir, entry.name);
|
|
26922
27090
|
if (entry.isDirectory()) out.push(...walk3(full));
|
|
26923
27091
|
else if (entry.isFile()) out.push(full);
|
|
26924
27092
|
}
|
|
@@ -27168,10 +27336,10 @@ function registerReleaseCommands(root) {
|
|
|
27168
27336
|
init_router();
|
|
27169
27337
|
init_worlds();
|
|
27170
27338
|
init_shared();
|
|
27171
|
-
import * as
|
|
27339
|
+
import * as fs50 from "fs";
|
|
27172
27340
|
var NOT_RECORDED_EXIT = 3;
|
|
27173
27341
|
var FILTER_FLAGS = [
|
|
27174
|
-
{ name: "via", help: "Only requests that came in by this door: api, ui or
|
|
27342
|
+
{ name: "via", help: "Only requests that came in by this door: api, ui, tool or webhook." },
|
|
27175
27343
|
{ name: "operation", help: "Only requests to this operation (the route's or the tool's name)." },
|
|
27176
27344
|
{ name: "status", help: "Only responses with this status: a code (404) or a class (2xx, 4xx, 5xx)." },
|
|
27177
27345
|
{
|
|
@@ -27274,11 +27442,11 @@ var WorldRequestText = class _WorldRequestText {
|
|
|
27274
27442
|
return [(part.bodyBytes ?? 0) > 0 ? "(binary body not kept)" : "(no body)"];
|
|
27275
27443
|
}
|
|
27276
27444
|
};
|
|
27277
|
-
function queryOf(args,
|
|
27445
|
+
function queryOf(args, scope2 = {}) {
|
|
27278
27446
|
const limit = listLimit(arg.int(args, "limit"));
|
|
27279
27447
|
try {
|
|
27280
27448
|
return WorldRequestQuery.parse({
|
|
27281
|
-
...
|
|
27449
|
+
...scope2,
|
|
27282
27450
|
via: arg.str(args, "via"),
|
|
27283
27451
|
operation: arg.str(args, "operation"),
|
|
27284
27452
|
status: arg.str(args, "status"),
|
|
@@ -27355,7 +27523,7 @@ function registerRequestCommands(root) {
|
|
|
27355
27523
|
const [slug, requestId] = args.positionals;
|
|
27356
27524
|
const entry = await ledgerOf(args).get(slug, requestId);
|
|
27357
27525
|
const out = arg.str(args, "out");
|
|
27358
|
-
if (out)
|
|
27526
|
+
if (out) fs50.writeFileSync(out, `${WorldRequestText.json(entry)}
|
|
27359
27527
|
`);
|
|
27360
27528
|
emit(ctx, args, entry, () => WorldRequestText.entry(entry, !out), WorldRequestText.json);
|
|
27361
27529
|
if (!out) return;
|
|
@@ -27482,6 +27650,11 @@ function registerRunCommands(root) {
|
|
|
27482
27650
|
init_config();
|
|
27483
27651
|
init_router();
|
|
27484
27652
|
init_shared();
|
|
27653
|
+
var ORIGIN_HELP = "An https origin (https://host[:port]) a fetch header that uses this secret may be sent to; repeatable. A secret with none is never expanded into a `files fetch` header.";
|
|
27654
|
+
function originsLine(name, origins) {
|
|
27655
|
+
if (origins.length === 0) return `Secret '${name}' has no allowed origins: it is never sent in a fetch header.`;
|
|
27656
|
+
return `Secret '${name}' may be sent to: ${origins.join(", ")}`;
|
|
27657
|
+
}
|
|
27485
27658
|
function registerSecretCommands(root) {
|
|
27486
27659
|
const secret = root.group("secret", "Manage project secrets (encrypted env vars for agent containers).");
|
|
27487
27660
|
secret.command({
|
|
@@ -27492,6 +27665,7 @@ function registerSecretCommands(root) {
|
|
|
27492
27665
|
{ name: "value", short: "v", help: "Secret value. If omitted, it is read from stdin." },
|
|
27493
27666
|
{ name: "description", short: "d", help: "Human-readable description" },
|
|
27494
27667
|
{ name: "scope", help: "Scope: agent, worker, or both", default: "agent" },
|
|
27668
|
+
{ name: "allowed-origin", help: ORIGIN_HELP, repeat: true },
|
|
27495
27669
|
HOST_FLAG,
|
|
27496
27670
|
API_KEY_FLAG
|
|
27497
27671
|
],
|
|
@@ -27503,6 +27677,8 @@ function registerSecretCommands(root) {
|
|
|
27503
27677
|
const payload = { name, value, scope: arg.str(args, "scope") ?? "agent" };
|
|
27504
27678
|
const description = arg.str(args, "description");
|
|
27505
27679
|
if (description) payload.description = description;
|
|
27680
|
+
const origins = arg.list(args, "allowed-origin");
|
|
27681
|
+
if (origins.length) payload.allowedOrigins = origins;
|
|
27506
27682
|
const saved = await rawRequest(creds, "POST", "/api/public/secrets", payload);
|
|
27507
27683
|
if (!saved.ok) throw failed(saved.status, saved.text);
|
|
27508
27684
|
const data = saved.json();
|
|
@@ -27510,9 +27686,34 @@ function registerSecretCommands(root) {
|
|
|
27510
27686
|
ctx.stdout(`Secret '${data.name ?? name}' ${verb} (${data.displayValue ?? "****"})`);
|
|
27511
27687
|
}
|
|
27512
27688
|
});
|
|
27689
|
+
secret.command({
|
|
27690
|
+
name: "origins",
|
|
27691
|
+
help: "Set the origins a secret may be sent to in a `files fetch` header (replaces the list; the value is untouched).",
|
|
27692
|
+
positionals: [
|
|
27693
|
+
{ name: "name", help: "Secret name" },
|
|
27694
|
+
{ name: "origin", help: "https://host[:port], one or more", variadic: true }
|
|
27695
|
+
],
|
|
27696
|
+
flags: [
|
|
27697
|
+
{ name: "none", help: "Clear the list: the secret is then never sent in a fetch header.", boolean: true },
|
|
27698
|
+
HOST_FLAG,
|
|
27699
|
+
API_KEY_FLAG
|
|
27700
|
+
],
|
|
27701
|
+
run: async (args, ctx) => {
|
|
27702
|
+
const [name, ...origins] = args.positionals;
|
|
27703
|
+
const named2 = origins.length > 0;
|
|
27704
|
+
if (arg.bool(args, "none") === named2)
|
|
27705
|
+
throw new CliError("name at least one origin, or pass --none to clear the list (not both)", 2);
|
|
27706
|
+
const res = await rawRequest(credentials(args), "PUT", `/api/public/secrets/${encodeURIComponent(name)}`, {
|
|
27707
|
+
allowedOrigins: origins
|
|
27708
|
+
});
|
|
27709
|
+
if (!res.ok) throw failed(res.status, res.text);
|
|
27710
|
+
const data = res.json();
|
|
27711
|
+
ctx.stdout(originsLine(data.name ?? name, data.allowedOrigins ?? []));
|
|
27712
|
+
}
|
|
27713
|
+
});
|
|
27513
27714
|
secret.command({
|
|
27514
27715
|
name: "list",
|
|
27515
|
-
help: "List project secrets (names and
|
|
27716
|
+
help: "List project secrets (names, descriptions and allowed origins, not values).",
|
|
27516
27717
|
flags: [HOST_FLAG, API_KEY_FLAG],
|
|
27517
27718
|
run: async (args, ctx) => {
|
|
27518
27719
|
const res = await api(credentials(args), "GET", "/api/public/secrets");
|
|
@@ -27521,11 +27722,12 @@ function registerSecretCommands(root) {
|
|
|
27521
27722
|
ctx.stdout("No secrets configured. Run `gateway secret set <name>` to add one.");
|
|
27522
27723
|
return;
|
|
27523
27724
|
}
|
|
27524
|
-
ctx.stdout(`${"Name".padEnd(30)} ${"Scope".padEnd(10)} Description`);
|
|
27525
|
-
ctx.stdout("-".repeat(
|
|
27725
|
+
ctx.stdout(`${"Name".padEnd(30)} ${"Scope".padEnd(10)} ${"Description".padEnd(28)} Allowed origins`);
|
|
27726
|
+
ctx.stdout("-".repeat(100));
|
|
27526
27727
|
for (const s of secrets) {
|
|
27527
27728
|
const desc = (s.description ?? "").slice(0, 28);
|
|
27528
|
-
|
|
27729
|
+
const origins = (s.allowedOrigins ?? []).join(", ");
|
|
27730
|
+
ctx.stdout(`${(s.name ?? "").padEnd(30)} ${(s.scope ?? "").padEnd(10)} ${desc.padEnd(28)} ${origins}`.trimEnd());
|
|
27529
27731
|
}
|
|
27530
27732
|
}
|
|
27531
27733
|
});
|
|
@@ -27547,16 +27749,16 @@ init_config();
|
|
|
27547
27749
|
init_router();
|
|
27548
27750
|
init_worlds();
|
|
27549
27751
|
init_surfaceDescriptor();
|
|
27550
|
-
import * as
|
|
27752
|
+
import * as fs54 from "fs";
|
|
27551
27753
|
init_shared();
|
|
27552
27754
|
|
|
27553
27755
|
// src/cli/platform/task.ts
|
|
27554
|
-
import * as
|
|
27756
|
+
import * as fs53 from "fs";
|
|
27555
27757
|
|
|
27556
27758
|
// src/cli/agentModule.ts
|
|
27557
27759
|
init_router();
|
|
27558
|
-
import * as
|
|
27559
|
-
import * as
|
|
27760
|
+
import * as fs51 from "fs";
|
|
27761
|
+
import * as path42 from "path";
|
|
27560
27762
|
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
27561
27763
|
var JAVASCRIPT = [".js", ".mjs", ".cjs"];
|
|
27562
27764
|
var TYPESCRIPT = [".ts", ".mts", ".cts"];
|
|
@@ -27572,7 +27774,7 @@ var AgentModule = class _AgentModule {
|
|
|
27572
27774
|
static FORM = "file.mjs[#export] (.js/.mjs/.cjs, or .ts with tsx installed): the default export, or the export #name names";
|
|
27573
27775
|
static parse(spec) {
|
|
27574
27776
|
const hash = spec.lastIndexOf("#");
|
|
27575
|
-
if (hash === -1 ||
|
|
27777
|
+
if (hash === -1 || fs51.existsSync(spec)) return new _AgentModule(spec, spec, null);
|
|
27576
27778
|
return new _AgentModule(spec, spec.slice(0, hash), spec.slice(hash + 1) || null);
|
|
27577
27779
|
}
|
|
27578
27780
|
sessionAgent() {
|
|
@@ -27582,8 +27784,8 @@ var AgentModule = class _AgentModule {
|
|
|
27582
27784
|
return this.load("async (run) => report (see @withgateway/sdk/worlds TaskRun)");
|
|
27583
27785
|
}
|
|
27584
27786
|
async load(signature) {
|
|
27585
|
-
const abs =
|
|
27586
|
-
if (!
|
|
27787
|
+
const abs = path42.resolve(this.file);
|
|
27788
|
+
if (!fs51.existsSync(abs)) throw new CliError(`--agent ${this.spec} does not exist`);
|
|
27587
27789
|
await _AgentModule.prepare(abs);
|
|
27588
27790
|
const mod = await import(pathToFileURL2(abs).href);
|
|
27589
27791
|
const candidate = this.exportName ? mod[this.exportName] : _AgentModule.defaultOf(mod);
|
|
@@ -27601,7 +27803,7 @@ var AgentModule = class _AgentModule {
|
|
|
27601
27803
|
return candidate;
|
|
27602
27804
|
}
|
|
27603
27805
|
static async prepare(abs) {
|
|
27604
|
-
const ext =
|
|
27806
|
+
const ext = path42.extname(abs);
|
|
27605
27807
|
if (TYPESCRIPT.includes(ext)) return _AgentModule.registerTypeScript(abs);
|
|
27606
27808
|
if (JAVASCRIPT.includes(ext)) return;
|
|
27607
27809
|
throw new CliError(
|
|
@@ -27704,7 +27906,7 @@ init_shared();
|
|
|
27704
27906
|
|
|
27705
27907
|
// src/cli/platform/taskSpec.ts
|
|
27706
27908
|
init_router();
|
|
27707
|
-
import * as
|
|
27909
|
+
import * as fs52 from "fs";
|
|
27708
27910
|
var TASK_SPEC_HELP = `A task spec is JSON:
|
|
27709
27911
|
{"instruction": "<what the agent is told>",
|
|
27710
27912
|
"name": "<optional>",
|
|
@@ -27963,25 +28165,25 @@ var TaskSpecCheck = class {
|
|
|
27963
28165
|
this.grader(verifier, at);
|
|
27964
28166
|
this.crossChecks(verifier, at);
|
|
27965
28167
|
}
|
|
27966
|
-
scope(
|
|
27967
|
-
if (!isStringList(
|
|
28168
|
+
scope(scope2, at) {
|
|
28169
|
+
if (!isStringList(scope2) || scope2.length < 2)
|
|
27968
28170
|
return this.issue(
|
|
27969
28171
|
`${at}.scope lists two or more of the task's world aliases`
|
|
27970
28172
|
);
|
|
27971
|
-
if (new Set(
|
|
28173
|
+
if (new Set(scope2).size !== scope2.length)
|
|
27972
28174
|
this.issue(`${at}.scope lists each alias once`);
|
|
27973
|
-
this.scopeInWorlds(
|
|
27974
|
-
this.anchor(
|
|
28175
|
+
this.scopeInWorlds(scope2, at);
|
|
28176
|
+
this.anchor(scope2[0], at);
|
|
27975
28177
|
}
|
|
27976
|
-
scopeInWorlds(
|
|
28178
|
+
scopeInWorlds(scope2, at) {
|
|
27977
28179
|
const worlds = this.spec.worlds;
|
|
27978
|
-
if (worlds === void 0 &&
|
|
28180
|
+
if (worlds === void 0 && scope2[0] !== this.spec.name)
|
|
27979
28181
|
this.issue(
|
|
27980
|
-
`${at}.scope[0] is "${
|
|
28182
|
+
`${at}.scope[0] is "${scope2[0]}", so the task's name must be "${scope2[0]}": on a task without worlds a verifier runs on the session of its first scope alias`
|
|
27981
28183
|
);
|
|
27982
28184
|
if (!isRecord(worlds)) return;
|
|
27983
28185
|
const aliases = Object.keys(worlds);
|
|
27984
|
-
for (const alias of
|
|
28186
|
+
for (const alias of scope2.filter((a) => !aliases.includes(a)))
|
|
27985
28187
|
this.issue(
|
|
27986
28188
|
`${at}.scope names "${alias}", which is not one of worlds (${aliases.join(", ")})`
|
|
27987
28189
|
);
|
|
@@ -27996,15 +28198,15 @@ var TaskSpecCheck = class {
|
|
|
27996
28198
|
);
|
|
27997
28199
|
}
|
|
27998
28200
|
crossChecks(verifier, at) {
|
|
27999
|
-
const { scope, checks } = verifier;
|
|
28201
|
+
const { scope: scope2, checks } = verifier;
|
|
28000
28202
|
if (verifier.kind !== "assertions") return;
|
|
28001
|
-
if (!isStringList(
|
|
28203
|
+
if (!isStringList(scope2) || !Array.isArray(checks)) return;
|
|
28002
28204
|
checks.forEach((check, i) => {
|
|
28003
28205
|
const entity = isRecord(check) ? check.entity : void 0;
|
|
28004
28206
|
if (typeof entity !== "string" || !entity) return;
|
|
28005
|
-
if (entity.includes(".") &&
|
|
28207
|
+
if (entity.includes(".") && scope2.includes(entity.split(".")[0])) return;
|
|
28006
28208
|
this.issue(
|
|
28007
|
-
`${at}.checks[${i}].entity is "${entity}": a cross-world check names its entity as <alias>.<entity> (or <alias>.calls) with the alias in scope (${
|
|
28209
|
+
`${at}.checks[${i}].entity is "${entity}": a cross-world check names its entity as <alias>.<entity> (or <alias>.calls) with the alias in scope (${scope2.join(", ")})`
|
|
28008
28210
|
);
|
|
28009
28211
|
});
|
|
28010
28212
|
}
|
|
@@ -28015,7 +28217,7 @@ function taskSpecIssues(spec) {
|
|
|
28015
28217
|
function readTaskSpec(file, flag = "--spec") {
|
|
28016
28218
|
let parsed;
|
|
28017
28219
|
try {
|
|
28018
|
-
parsed = JSON.parse(
|
|
28220
|
+
parsed = JSON.parse(fs52.readFileSync(file, "utf8"));
|
|
28019
28221
|
} catch (error) {
|
|
28020
28222
|
throw new CliError(
|
|
28021
28223
|
`${flag} ${file}: ${error instanceof Error ? error.message : String(error)}`
|
|
@@ -28068,7 +28270,7 @@ function worldFromFlags(world, noWorld) {
|
|
|
28068
28270
|
}
|
|
28069
28271
|
function readJsonFile(file, what) {
|
|
28070
28272
|
try {
|
|
28071
|
-
return JSON.parse(
|
|
28273
|
+
return JSON.parse(fs53.readFileSync(file, "utf8"));
|
|
28072
28274
|
} catch (error) {
|
|
28073
28275
|
throw new CliError(
|
|
28074
28276
|
`${what} ${file}: ${error instanceof Error ? error.message : String(error)}`
|
|
@@ -28076,7 +28278,7 @@ function readJsonFile(file, what) {
|
|
|
28076
28278
|
}
|
|
28077
28279
|
}
|
|
28078
28280
|
function taskTarget(positional) {
|
|
28079
|
-
if (!
|
|
28281
|
+
if (!fs53.existsSync(positional)) return { kind: "id", taskId: positional };
|
|
28080
28282
|
const parsed = readJsonFile(positional, "task");
|
|
28081
28283
|
if (isTaskManifest(parsed)) return { kind: "manifest", manifest: parsed };
|
|
28082
28284
|
if (parsed && typeof parsed === "object" && typeof parsed.instruction === "string")
|
|
@@ -28098,7 +28300,7 @@ var TARGET_POSITIONAL2 = {
|
|
|
28098
28300
|
help: "Task id, or the manifest file `task up --out` wrote."
|
|
28099
28301
|
};
|
|
28100
28302
|
function emitManifest(ctx, manifest, out) {
|
|
28101
|
-
if (out)
|
|
28303
|
+
if (out) fs53.writeFileSync(out, JSON.stringify(manifest, null, 2) + "\n");
|
|
28102
28304
|
printJson(ctx, manifest);
|
|
28103
28305
|
if (out) ctx.stderr(`wrote the manifest to ${out}`);
|
|
28104
28306
|
}
|
|
@@ -28538,7 +28740,7 @@ function registerTaskCommands(root) {
|
|
|
28538
28740
|
const text2 = lines.join("\n") + (lines.length ? "\n" : "");
|
|
28539
28741
|
const out = arg.str(args, "out");
|
|
28540
28742
|
if (out) {
|
|
28541
|
-
|
|
28743
|
+
fs53.writeFileSync(out, text2);
|
|
28542
28744
|
ctx.stdout(
|
|
28543
28745
|
`wrote ${lines.length - requests} calls${wanted ? ` and ${requests} requests` : ""} from ${Object.keys(exported).length} worlds to ${out}`
|
|
28544
28746
|
);
|
|
@@ -28975,7 +29177,7 @@ source (bundled|stored|inline|none)/name/hash/id/version.
|
|
|
28975
29177
|
try {
|
|
28976
29178
|
const url = await browser.goto(arg.str(args, "path"));
|
|
28977
29179
|
const shot = arg.str(args, "screenshot");
|
|
28978
|
-
if (shot)
|
|
29180
|
+
if (shot) fs54.writeFileSync(shot, await browser.screenshot());
|
|
28979
29181
|
printJson(ctx, {
|
|
28980
29182
|
url,
|
|
28981
29183
|
title: await browser.title(),
|
|
@@ -29190,12 +29392,12 @@ world's [redact] policy over the rows first; --redact refuse rejects plaintext i
|
|
|
29190
29392
|
const out = arg.str(args, "out");
|
|
29191
29393
|
const to = arg.str(args, "to");
|
|
29192
29394
|
if (out) {
|
|
29193
|
-
|
|
29395
|
+
fs54.writeFileSync(out, text2);
|
|
29194
29396
|
ctx.stdout(`wrote ${counted2} to ${out}`);
|
|
29195
29397
|
} else if (!to && text2) process.stdout.write(text2);
|
|
29196
29398
|
if (!to) return;
|
|
29197
29399
|
const scratch = out ? null : scratchFile(`${sessionId}.calls.jsonl`);
|
|
29198
|
-
if (scratch)
|
|
29400
|
+
if (scratch) fs54.writeFileSync(scratch.file, text2);
|
|
29199
29401
|
try {
|
|
29200
29402
|
const landed = await landInDrive(scratch?.file ?? out, to, creds);
|
|
29201
29403
|
ctx.stdout(`wrote ${counted2} to drive:${landed.path}`);
|
|
@@ -29206,6 +29408,152 @@ world's [redact] policy over the rows first; --redact refuse rejects plaintext i
|
|
|
29206
29408
|
});
|
|
29207
29409
|
}
|
|
29208
29410
|
|
|
29411
|
+
// src/cli/platform/webhooks.ts
|
|
29412
|
+
init_router();
|
|
29413
|
+
init_worlds();
|
|
29414
|
+
init_webhooks();
|
|
29415
|
+
init_shared();
|
|
29416
|
+
var POLL_MS = 1e3;
|
|
29417
|
+
var POLL_MIN_MS = 100;
|
|
29418
|
+
var BACKOFF_MIN_MS = 1e3;
|
|
29419
|
+
var BACKOFF_MAX_MS = 3e4;
|
|
29420
|
+
var PASSING_STATUSES = /* @__PURE__ */ new Set([408, 429]);
|
|
29421
|
+
var PASSING_CONFLICTS = /* @__PURE__ */ new Set(["session_starting", "session_recovering"]);
|
|
29422
|
+
var POLL_MAX_MS = 36e5;
|
|
29423
|
+
function permanent(error) {
|
|
29424
|
+
if (!(error instanceof ApiError)) return false;
|
|
29425
|
+
const passing = error.status === 409 && PASSING_CONFLICTS.has(error.code ?? "");
|
|
29426
|
+
return error.status >= 400 && error.status < 500 && !PASSING_STATUSES.has(error.status) && !passing;
|
|
29427
|
+
}
|
|
29428
|
+
function events(list) {
|
|
29429
|
+
return list.length ? list.join(",") : "*";
|
|
29430
|
+
}
|
|
29431
|
+
function scope(values) {
|
|
29432
|
+
const narrowed = Object.entries(values).filter(([, held2]) => held2.length);
|
|
29433
|
+
return narrowed.map(([name, held2]) => `${name}=${held2.join(",")}`).join(" ") || "-";
|
|
29434
|
+
}
|
|
29435
|
+
function listingLines(listing) {
|
|
29436
|
+
if (!listing.declared) return ["This world declares no [webhooks]."];
|
|
29437
|
+
const rows = listing.subscriptions.map((sub) => [
|
|
29438
|
+
sub.url ?? "-",
|
|
29439
|
+
events(sub.events),
|
|
29440
|
+
scope(sub.scope),
|
|
29441
|
+
sub.enabled ? "on" : "off",
|
|
29442
|
+
String(sub.sent)
|
|
29443
|
+
]);
|
|
29444
|
+
if (rows.length === 0) return ["No webhooks registered."];
|
|
29445
|
+
const table3 = textTable(rows, ["URL", "EVENTS", "SCOPE", "STATE", "SENT"]);
|
|
29446
|
+
return listing.truncated ? [...table3, `(the first ${rows.length} subscriptions)`] : table3;
|
|
29447
|
+
}
|
|
29448
|
+
function forwardTarget(args) {
|
|
29449
|
+
const target = arg.str(args, "forward-to") ?? "";
|
|
29450
|
+
let url;
|
|
29451
|
+
try {
|
|
29452
|
+
url = new URL(target);
|
|
29453
|
+
} catch {
|
|
29454
|
+
throw new CliError("--forward-to must be an http(s) URL, e.g. http://localhost:3000/webhooks");
|
|
29455
|
+
}
|
|
29456
|
+
if (url.protocol !== "http:" && url.protocol !== "https:")
|
|
29457
|
+
throw new CliError("--forward-to must be an http(s) URL, e.g. http://localhost:3000/webhooks");
|
|
29458
|
+
if (url.username || url.password)
|
|
29459
|
+
throw new CliError("--forward-to carries no user:password; a receiver's own check reads the signature");
|
|
29460
|
+
return url.toString();
|
|
29461
|
+
}
|
|
29462
|
+
function forwardedLine(item) {
|
|
29463
|
+
const { delivery, answer } = item;
|
|
29464
|
+
const answered = answer.status ? String(answer.status) : `no answer (${answer.error ?? "unreachable"})`;
|
|
29465
|
+
return `${delivery.eventType} ${delivery.id} \u2192 ${answered} ${answer.durationMs} ms`;
|
|
29466
|
+
}
|
|
29467
|
+
function report(ctx, args, forwarded) {
|
|
29468
|
+
for (const item of forwarded)
|
|
29469
|
+
if (args.flags.json === true) ctx.stdout(JSON.stringify({ ...item.answer, eventType: item.delivery.eventType }));
|
|
29470
|
+
else ctx.stdout(forwardedLine(item));
|
|
29471
|
+
}
|
|
29472
|
+
var sleep5 = (ms, signal) => new Promise((wake) => {
|
|
29473
|
+
const timer = setTimeout(wake, ms);
|
|
29474
|
+
signal.addEventListener("abort", () => (clearTimeout(timer), wake()), { once: true });
|
|
29475
|
+
});
|
|
29476
|
+
async function listen(forwarder, ctx, args) {
|
|
29477
|
+
const stop = new AbortController();
|
|
29478
|
+
const halt = () => stop.abort();
|
|
29479
|
+
process.once("SIGINT", halt);
|
|
29480
|
+
process.once("SIGTERM", halt);
|
|
29481
|
+
const once = arg.bool(args, "once");
|
|
29482
|
+
const interval = arg.int(args, "interval-ms") ?? POLL_MS;
|
|
29483
|
+
let backoff = Math.max(interval, BACKOFF_MIN_MS);
|
|
29484
|
+
let started = false;
|
|
29485
|
+
try {
|
|
29486
|
+
while (!stop.signal.aborted) {
|
|
29487
|
+
let polled;
|
|
29488
|
+
try {
|
|
29489
|
+
if (!started) await forwarder.start(once || arg.bool(args, "replay"));
|
|
29490
|
+
started = true;
|
|
29491
|
+
polled = await forwarder.round();
|
|
29492
|
+
} catch (error) {
|
|
29493
|
+
if (once || permanent(error)) throw error;
|
|
29494
|
+
ctx.stderr(`poll failed (${error instanceof Error ? error.message : String(error)}); retrying in ${backoff} ms`);
|
|
29495
|
+
await sleep5(backoff, stop.signal);
|
|
29496
|
+
backoff = Math.min(backoff * 2, BACKOFF_MAX_MS);
|
|
29497
|
+
continue;
|
|
29498
|
+
}
|
|
29499
|
+
backoff = Math.max(interval, BACKOFF_MIN_MS);
|
|
29500
|
+
const { page, forwarded } = polled;
|
|
29501
|
+
if (page.reset) ctx.stderr("the session's feed started over (a restart or a move); forwarding from its start");
|
|
29502
|
+
if (page.missed) ctx.stderr(`${page.missed} delivery(ies) left the session's feed before they were read`);
|
|
29503
|
+
report(ctx, args, forwarded);
|
|
29504
|
+
if (once && !page.more) break;
|
|
29505
|
+
if (!page.more) await sleep5(interval, stop.signal);
|
|
29506
|
+
}
|
|
29507
|
+
} finally {
|
|
29508
|
+
process.off("SIGINT", halt);
|
|
29509
|
+
process.off("SIGTERM", halt);
|
|
29510
|
+
await forwarder.settle().catch((error) => {
|
|
29511
|
+
ctx.stderr(`the last answers were not sent: ${error instanceof Error ? error.message : String(error)}`);
|
|
29512
|
+
if (!stop.signal.aborted) throw error;
|
|
29513
|
+
});
|
|
29514
|
+
}
|
|
29515
|
+
}
|
|
29516
|
+
function registerWebhookCommands(root) {
|
|
29517
|
+
const session = root.group("worlds", "Build, seed, serve and run worlds.").group("session", "Live world sessions with api/ui/browser surfaces.");
|
|
29518
|
+
session.command({
|
|
29519
|
+
name: "webhooks",
|
|
29520
|
+
help: "The webhooks the session's world declares: each subscription and how many deliveries it was sent.",
|
|
29521
|
+
positionals: [{ name: "session_id", help: "Session id." }],
|
|
29522
|
+
flags: [JSON_OUTPUT_FLAG, HOST_FLAG],
|
|
29523
|
+
notes: "Only a World Host session's world sends webhooks; it declares them in connector.toml [webhooks].\nForward them to a receiver on this machine with `gateway worlds session listen <id> --forward-to <url>`.",
|
|
29524
|
+
run: async (args, ctx) => {
|
|
29525
|
+
const listing = await listWebhooks(worldsOptions(credentials(args)), args.positionals[0], {
|
|
29526
|
+
tail: true,
|
|
29527
|
+
limit: 1
|
|
29528
|
+
});
|
|
29529
|
+
emit(ctx, args, listing, () => listingLines(listing));
|
|
29530
|
+
}
|
|
29531
|
+
});
|
|
29532
|
+
session.command({
|
|
29533
|
+
name: "listen",
|
|
29534
|
+
help: "Forward every webhook the session's world sends to a URL, signed as the vendor signs it.",
|
|
29535
|
+
positionals: [{ name: "session_id", help: "Session id." }],
|
|
29536
|
+
flags: [
|
|
29537
|
+
{ name: "forward-to", help: "Where each delivery is POSTed: an http(s) URL (http://localhost:3000/webhooks)." },
|
|
29538
|
+
{ name: "replay", help: "Also forward the deliveries the session already holds (up to 500), not only new ones.", boolean: true },
|
|
29539
|
+
{ name: "interval-ms", help: "How long to wait between polls when nothing is new.", default: String(POLL_MS) },
|
|
29540
|
+
{ name: "once", help: "Forward every delivery the session holds now, then exit (implies --replay).", boolean: true },
|
|
29541
|
+
JSON_OUTPUT_FLAG,
|
|
29542
|
+
HOST_FLAG
|
|
29543
|
+
],
|
|
29544
|
+
notes: "Each delivery keeps its headers (svix-signature, X-Hub-Signature-256, ...) and exact body, so the receiver\nverifies it with the secret the world gave when the webhook was registered. The receiver's status goes back\nto the world's request ledger (`gateway worlds requests <slug> --via webhook`), once per delivery. Only deliveries\nsent from now are forwarded unless --replay; a Svix receiver refuses one older than about 5 minutes. Ctrl-C stops.",
|
|
29545
|
+
run: async (args, ctx) => {
|
|
29546
|
+
const target = forwardTarget(args);
|
|
29547
|
+
const interval = arg.int(args, "interval-ms") ?? POLL_MS;
|
|
29548
|
+
if (interval < POLL_MIN_MS || interval > POLL_MAX_MS)
|
|
29549
|
+
throw new CliError(`--interval-ms is from ${POLL_MIN_MS} to ${POLL_MAX_MS}`);
|
|
29550
|
+
const forwarder = new WorldWebhookForwarder(worldsOptions(credentials(args)), args.positionals[0], target);
|
|
29551
|
+
if (args.flags.json !== true) ctx.stderr(`forwarding ${args.positionals[0]} webhooks to ${target}`);
|
|
29552
|
+
await listen(forwarder, ctx, args);
|
|
29553
|
+
}
|
|
29554
|
+
});
|
|
29555
|
+
}
|
|
29556
|
+
|
|
29209
29557
|
// src/cli/platform/index.ts
|
|
29210
29558
|
init_skill();
|
|
29211
29559
|
|
|
@@ -29372,7 +29720,7 @@ function registerTaskEditVerbs(root) {
|
|
|
29372
29720
|
// src/cli/platform/taskGradeVerbs.ts
|
|
29373
29721
|
init_router();
|
|
29374
29722
|
init_worlds();
|
|
29375
|
-
import * as
|
|
29723
|
+
import * as fs55 from "fs";
|
|
29376
29724
|
init_shared();
|
|
29377
29725
|
var WHERE = {
|
|
29378
29726
|
live: "live",
|
|
@@ -29431,7 +29779,7 @@ function regradeRefusal(regrade) {
|
|
|
29431
29779
|
return null;
|
|
29432
29780
|
}
|
|
29433
29781
|
function trialTarget(positional, version) {
|
|
29434
|
-
if (!
|
|
29782
|
+
if (!fs55.existsSync(positional)) return { taskId: positional, ...version === void 0 ? {} : { version } };
|
|
29435
29783
|
if (version !== void 0) throw new CliError("--version goes with a task id, not a spec file");
|
|
29436
29784
|
return { spec: readTaskSpec(positional, "task") };
|
|
29437
29785
|
}
|
|
@@ -29588,7 +29936,7 @@ function registerTaskRunSet(root) {
|
|
|
29588
29936
|
// src/cli/platform/traces.ts
|
|
29589
29937
|
init_config();
|
|
29590
29938
|
init_router();
|
|
29591
|
-
import * as
|
|
29939
|
+
import * as fs56 from "fs";
|
|
29592
29940
|
|
|
29593
29941
|
// src/traces/index.ts
|
|
29594
29942
|
init_worlds();
|
|
@@ -29805,7 +30153,7 @@ function registerTracesCommands(root) {
|
|
|
29805
30153
|
const scratch = toDrive ? scratchFile("traces.jsonl") : null;
|
|
29806
30154
|
const file = toStdout ? null : scratch?.file ?? out;
|
|
29807
30155
|
try {
|
|
29808
|
-
const sink = file ?
|
|
30156
|
+
const sink = file ? fs56.createWriteStream(file) : null;
|
|
29809
30157
|
const write = (record) => {
|
|
29810
30158
|
const line = JSON.stringify(record) + "\n";
|
|
29811
30159
|
if (sink) sink.write(line);
|
|
@@ -29923,8 +30271,8 @@ function registerTracesCommands(root) {
|
|
|
29923
30271
|
});
|
|
29924
30272
|
}
|
|
29925
30273
|
function readFile2(file) {
|
|
29926
|
-
if (!
|
|
29927
|
-
return
|
|
30274
|
+
if (!fs56.existsSync(file)) throw new CliError(`${file} does not exist`, 1);
|
|
30275
|
+
return fs56.readFileSync(file, "utf8");
|
|
29928
30276
|
}
|
|
29929
30277
|
|
|
29930
30278
|
// src/cli/platform/worldData/chunks.ts
|
|
@@ -29970,8 +30318,8 @@ var TreeChunks = class _TreeChunks {
|
|
|
29970
30318
|
const paths = new StagedPaths(this.files);
|
|
29971
30319
|
try {
|
|
29972
30320
|
await paths.stage(this.ctx);
|
|
29973
|
-
const
|
|
29974
|
-
printJson(this.ctx,
|
|
30321
|
+
const report2 = await this.cut(paths.list);
|
|
30322
|
+
printJson(this.ctx, report2);
|
|
29975
30323
|
return 0;
|
|
29976
30324
|
} finally {
|
|
29977
30325
|
paths.dispose();
|
|
@@ -30111,6 +30459,7 @@ function registerPlatformCommands(root) {
|
|
|
30111
30459
|
registerWorldCommands(root);
|
|
30112
30460
|
registerSessionCommands(root);
|
|
30113
30461
|
registerRequestCommands(root);
|
|
30462
|
+
registerWebhookCommands(root);
|
|
30114
30463
|
registerTaskCommands(root);
|
|
30115
30464
|
registerTaskRunSet(root);
|
|
30116
30465
|
registerTaskEditVerbs(root);
|
|
@@ -30137,8 +30486,8 @@ init_router();
|
|
|
30137
30486
|
init_config();
|
|
30138
30487
|
init_local();
|
|
30139
30488
|
init_client();
|
|
30140
|
-
import * as
|
|
30141
|
-
import * as
|
|
30489
|
+
import * as fs57 from "fs";
|
|
30490
|
+
import * as path43 from "path";
|
|
30142
30491
|
var HOST_FLAG3 = {
|
|
30143
30492
|
name: "host",
|
|
30144
30493
|
help: "Platform host (default: GATEWAY_HOST or the saved login).",
|
|
@@ -30168,10 +30517,10 @@ function wireParams(params) {
|
|
|
30168
30517
|
return names.size === list.length ? Object.fromEntries(list) : list;
|
|
30169
30518
|
}
|
|
30170
30519
|
function requireConnectorToml(dir) {
|
|
30171
|
-
const file =
|
|
30172
|
-
if (!
|
|
30520
|
+
const file = path43.join(dir, "connector.toml");
|
|
30521
|
+
if (!fs57.existsSync(file))
|
|
30173
30522
|
throw new CliError(`${dir} holds no connector.toml`, 1);
|
|
30174
|
-
return
|
|
30523
|
+
return fs57.readFileSync(file, "utf8");
|
|
30175
30524
|
}
|
|
30176
30525
|
function renderConnection(spec) {
|
|
30177
30526
|
const lines = [`${spec.slug} ${spec.baseUrl} auth=${spec.auth}`];
|
|
@@ -30190,7 +30539,7 @@ function undeclaredParams(record) {
|
|
|
30190
30539
|
return [];
|
|
30191
30540
|
}
|
|
30192
30541
|
}
|
|
30193
|
-
var
|
|
30542
|
+
var sleep6 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
30194
30543
|
async function resolveEnvironmentId2(creds, ref) {
|
|
30195
30544
|
const listing = await api(
|
|
30196
30545
|
creds,
|
|
@@ -30205,7 +30554,7 @@ async function remoteCapture(creds, world, opts, ctx) {
|
|
|
30205
30554
|
const specText = requireConnectorToml(world);
|
|
30206
30555
|
const containerId = await resolveEnvironmentId2(
|
|
30207
30556
|
creds,
|
|
30208
|
-
opts.environment ??
|
|
30557
|
+
opts.environment ?? path43.basename(path43.resolve(world))
|
|
30209
30558
|
);
|
|
30210
30559
|
const base = `/api/public/environments/${encodeURIComponent(containerId)}`;
|
|
30211
30560
|
const params = wireParams(opts.params);
|
|
@@ -30242,7 +30591,7 @@ async function remoteCapture(creds, world, opts, ctx) {
|
|
|
30242
30591
|
`Remote capture still ${view.stage} after ${opts.timeoutSeconds}s; poll it with the request id ${requestId}`,
|
|
30243
30592
|
1
|
|
30244
30593
|
);
|
|
30245
|
-
await
|
|
30594
|
+
await sleep6(opts.pollMs ?? 5e3);
|
|
30246
30595
|
}
|
|
30247
30596
|
const slugPrefix = `worlds/${view.worldSlug}/`;
|
|
30248
30597
|
const written = [];
|
|
@@ -30262,18 +30611,18 @@ async function remoteCapture(creds, world, opts, ctx) {
|
|
|
30262
30611
|
const res = await fetch(info.url);
|
|
30263
30612
|
if (!res.ok)
|
|
30264
30613
|
throw new CliError(`download ${drivePath2} -> ${res.status}`, 1);
|
|
30265
|
-
const destination =
|
|
30266
|
-
|
|
30614
|
+
const destination = path43.join(world, relative6);
|
|
30615
|
+
fs57.mkdirSync(path43.dirname(destination), { recursive: true });
|
|
30267
30616
|
const bytes = Buffer.from(await res.arrayBuffer());
|
|
30268
|
-
|
|
30617
|
+
fs57.writeFileSync(destination, bytes);
|
|
30269
30618
|
written.push(relative6);
|
|
30270
30619
|
for (const name of undeclaredParams(bytes))
|
|
30271
30620
|
ctx.stderr(
|
|
30272
30621
|
`# note: ${name} is not declared by operation ${opts.op} in connector.toml; sent as given`
|
|
30273
30622
|
);
|
|
30274
30623
|
}
|
|
30275
|
-
const manifestPath2 =
|
|
30276
|
-
const existing =
|
|
30624
|
+
const manifestPath2 = path43.join(world, CAPTURES, MANIFEST);
|
|
30625
|
+
const existing = fs57.existsSync(manifestPath2) ? JSON.parse(fs57.readFileSync(manifestPath2, "utf8")) : [];
|
|
30277
30626
|
const known = new Set(
|
|
30278
30627
|
existing.map(
|
|
30279
30628
|
(e) => e && typeof e === "object" ? e.file : void 0
|
|
@@ -30286,13 +30635,14 @@ async function remoteCapture(creds, world, opts, ctx) {
|
|
|
30286
30635
|
existing.push(entry);
|
|
30287
30636
|
known.add(file);
|
|
30288
30637
|
}
|
|
30289
|
-
|
|
30290
|
-
|
|
30638
|
+
fs57.mkdirSync(path43.dirname(manifestPath2), { recursive: true });
|
|
30639
|
+
fs57.writeFileSync(manifestPath2, sortedJson(existing, 1) + "\n");
|
|
30291
30640
|
return written;
|
|
30292
30641
|
}
|
|
30642
|
+
var PASSING_SCHEMA_STATES = /* @__PURE__ */ new Set(["ok", "no-schema", "no-body"]);
|
|
30293
30643
|
function outcomeOk(outcome) {
|
|
30294
30644
|
if (typeof outcome.ok === "boolean") return outcome.ok;
|
|
30295
|
-
return outcome.documented && outcome.status != null && (outcome.expected ?? []).includes(String(outcome.status)) && (outcome.schema
|
|
30645
|
+
return outcome.documented && outcome.status != null && (outcome.expected ?? []).includes(String(outcome.status)) && PASSING_SCHEMA_STATES.has(outcome.schema ?? "");
|
|
30296
30646
|
}
|
|
30297
30647
|
function renderConformOutcome(outcome) {
|
|
30298
30648
|
const mark = !outcome.documented ? " ? " : outcomeOk(outcome) ? " ok " : " FAIL";
|
|
@@ -30314,7 +30664,7 @@ function registerConnectorCommands2(connector) {
|
|
|
30314
30664
|
],
|
|
30315
30665
|
flags: [HOST_FLAG3],
|
|
30316
30666
|
run: async (args, ctx) => {
|
|
30317
|
-
const dir =
|
|
30667
|
+
const dir = path43.resolve(args.positionals[0]);
|
|
30318
30668
|
requireConnectorToml(dir);
|
|
30319
30669
|
const creds = credentialsForRuntime(arg.str(args, "host"));
|
|
30320
30670
|
const res = await runtime(creds, {
|
|
@@ -30370,7 +30720,7 @@ and runs on this machine when a python3 >= ${MIN_PYTHON_LABEL} is installed (the
|
|
|
30370
30720
|
HOST_FLAG3
|
|
30371
30721
|
],
|
|
30372
30722
|
run: async (args, ctx) => {
|
|
30373
|
-
const dir =
|
|
30723
|
+
const dir = path43.resolve(args.positionals[0]);
|
|
30374
30724
|
const op = arg.str(args, "op");
|
|
30375
30725
|
if (!op) throw new CliError("capture needs --op");
|
|
30376
30726
|
if (!arg.bool(args, "remote")) {
|
|
@@ -30420,17 +30770,17 @@ and runs on this machine when a python3 >= ${MIN_PYTHON_LABEL} is installed (the
|
|
|
30420
30770
|
HOST_FLAG3
|
|
30421
30771
|
],
|
|
30422
30772
|
run: async (args, ctx) => {
|
|
30423
|
-
const dir =
|
|
30773
|
+
const dir = path43.resolve(args.positionals[0]);
|
|
30424
30774
|
const documents = arg.list(args, "openapi");
|
|
30425
30775
|
if (!documents.length)
|
|
30426
30776
|
throw new CliError("conform needs --openapi FILE (repeatable)");
|
|
30427
30777
|
requireConnectorToml(dir);
|
|
30428
30778
|
const openapi = documents.map((file) => {
|
|
30429
|
-
if (!
|
|
30779
|
+
if (!fs57.existsSync(file))
|
|
30430
30780
|
throw new CliError(`--openapi ${file} does not exist`);
|
|
30431
30781
|
return {
|
|
30432
|
-
path:
|
|
30433
|
-
content:
|
|
30782
|
+
path: path43.basename(file),
|
|
30783
|
+
content: fs57.readFileSync(file).toString("base64")
|
|
30434
30784
|
};
|
|
30435
30785
|
});
|
|
30436
30786
|
const limit = arg.int(args, "limit");
|
|
@@ -30441,14 +30791,14 @@ and runs on this machine when a python3 >= ${MIN_PYTHON_LABEL} is installed (the
|
|
|
30441
30791
|
openapi,
|
|
30442
30792
|
...limit !== void 0 ? { max_operations: limit } : {}
|
|
30443
30793
|
});
|
|
30444
|
-
const
|
|
30445
|
-
for (const outcome of
|
|
30794
|
+
const report2 = res.report ?? {};
|
|
30795
|
+
for (const outcome of report2.operations ?? report2.outcomes ?? [])
|
|
30446
30796
|
ctx.stdout(renderConformOutcome(outcome));
|
|
30447
|
-
const summary2 =
|
|
30797
|
+
const summary2 = report2.summary ?? {};
|
|
30448
30798
|
ctx.stdout(JSON.stringify(summary2));
|
|
30449
30799
|
const out = arg.str(args, "out");
|
|
30450
30800
|
if (out) {
|
|
30451
|
-
|
|
30801
|
+
fs57.writeFileSync(out, JSON.stringify(report2, null, 1) + "\n");
|
|
30452
30802
|
ctx.stdout(`report: ${out}`);
|
|
30453
30803
|
}
|
|
30454
30804
|
return Number(summary2.status_mismatch) || Number(summary2.schema_violations) ? 1 : 0;
|
|
@@ -30476,16 +30826,16 @@ and runs on this machine when a python3 >= ${MIN_PYTHON_LABEL} is installed (the
|
|
|
30476
30826
|
],
|
|
30477
30827
|
notes: "An ingest stops at the first row the contract refuses; --dry-run reports all of them at once, grouped\nby capture, entity and pointer, so a forty-capture world is fixed in one pass. Exit 2 when any row is refused.",
|
|
30478
30828
|
run: async (args, ctx) => {
|
|
30479
|
-
const dir =
|
|
30480
|
-
if (!
|
|
30829
|
+
const dir = path43.resolve(args.positionals[0]);
|
|
30830
|
+
if (!fs57.existsSync(path43.join(dir, CAPTURES)))
|
|
30481
30831
|
throw new CliError(
|
|
30482
30832
|
`${dir} holds no ${CAPTURES}/ \u2014 run \`connector capture --remote\` first`,
|
|
30483
30833
|
1
|
|
30484
30834
|
);
|
|
30485
30835
|
const batchId = arg.str(args, "batch-id");
|
|
30486
30836
|
const dryRun = arg.bool(args, "dry-run");
|
|
30487
|
-
const
|
|
30488
|
-
if (
|
|
30837
|
+
const report2 = arg.str(args, "report");
|
|
30838
|
+
if (report2 && !dryRun)
|
|
30489
30839
|
throw new CliError("--report belongs to `connector ingest --dry-run`");
|
|
30490
30840
|
const creds = credentialsForRuntime(arg.str(args, "host"));
|
|
30491
30841
|
if (dryRun) {
|
|
@@ -30507,12 +30857,12 @@ and runs on this machine when a python3 >= ${MIN_PYTHON_LABEL} is installed (the
|
|
|
30507
30857
|
ctx.stdout(
|
|
30508
30858
|
` ${refusal.capture ?? "?"} ${refusal.pointer}: ${refusal.detail}`
|
|
30509
30859
|
);
|
|
30510
|
-
if (
|
|
30511
|
-
|
|
30512
|
-
|
|
30860
|
+
if (report2) {
|
|
30861
|
+
fs57.writeFileSync(
|
|
30862
|
+
report2,
|
|
30513
30863
|
refusals.map((r) => JSON.stringify(r) + "\n").join("")
|
|
30514
30864
|
);
|
|
30515
|
-
ctx.stdout(`report: ${
|
|
30865
|
+
ctx.stdout(`report: ${report2}`);
|
|
30516
30866
|
}
|
|
30517
30867
|
return refusals.length ? 2 : 0;
|
|
30518
30868
|
}
|
|
@@ -30537,8 +30887,8 @@ and runs on this machine when a python3 >= ${MIN_PYTHON_LABEL} is installed (the
|
|
|
30537
30887
|
// src/cli/runtime/run.ts
|
|
30538
30888
|
init_router();
|
|
30539
30889
|
init_config();
|
|
30540
|
-
import * as
|
|
30541
|
-
import * as
|
|
30890
|
+
import * as fs58 from "fs";
|
|
30891
|
+
import * as path44 from "path";
|
|
30542
30892
|
init_shared();
|
|
30543
30893
|
init_worlds();
|
|
30544
30894
|
init_session2();
|
|
@@ -30552,11 +30902,11 @@ var HOST_FLAG4 = {
|
|
|
30552
30902
|
env: "GATEWAY_HOST"
|
|
30553
30903
|
};
|
|
30554
30904
|
function resolveTarget(target, versionFlag) {
|
|
30555
|
-
if (
|
|
30556
|
-
const dir =
|
|
30905
|
+
if (fs58.existsSync(target) && fs58.statSync(target).isDirectory()) {
|
|
30906
|
+
const dir = path44.resolve(target);
|
|
30557
30907
|
const meta = readLocalMeta(dir);
|
|
30558
30908
|
return {
|
|
30559
|
-
slug: meta?.slug ??
|
|
30909
|
+
slug: meta?.slug ?? path44.basename(dir),
|
|
30560
30910
|
ref: meta?.branch ?? null,
|
|
30561
30911
|
versionId: versionFlag ?? meta?.versionId ?? null,
|
|
30562
30912
|
dir
|
|
@@ -30784,8 +31134,8 @@ function registerRunCommands2(worlds) {
|
|
|
30784
31134
|
}
|
|
30785
31135
|
],
|
|
30786
31136
|
run: async (args, ctx) => {
|
|
30787
|
-
const dir =
|
|
30788
|
-
if (!
|
|
31137
|
+
const dir = path44.resolve(args.positionals[0]);
|
|
31138
|
+
if (!fs58.existsSync(dir) || !fs58.statSync(dir).isDirectory())
|
|
30789
31139
|
throw new CliError(`path is not a directory: ${args.positionals[0]}`);
|
|
30790
31140
|
const agentFile = arg.str(args, "agent");
|
|
30791
31141
|
const runConfig = arg.str(args, "run-config");
|
|
@@ -30813,7 +31163,7 @@ function registerRunCommands2(worlds) {
|
|
|
30813
31163
|
const summaryFile = arg.str(args, "summary-file");
|
|
30814
31164
|
const agent = agentFile ? await AgentModule.parse(agentFile).sessionAgent() : null;
|
|
30815
31165
|
if (runConfig) {
|
|
30816
|
-
const
|
|
31166
|
+
const report2 = await validateWorld(dir, {
|
|
30817
31167
|
slug,
|
|
30818
31168
|
runConfig,
|
|
30819
31169
|
branch,
|
|
@@ -30822,15 +31172,15 @@ function registerRunCommands2(worlds) {
|
|
|
30822
31172
|
onProgress: (line) => ctx.stderr(line),
|
|
30823
31173
|
options
|
|
30824
31174
|
});
|
|
30825
|
-
const { markdown, ...summary3 } =
|
|
31175
|
+
const { markdown, ...summary3 } = report2;
|
|
30826
31176
|
ctx.stdout(JSON.stringify(summary3, null, 2));
|
|
30827
31177
|
if (summaryFile)
|
|
30828
|
-
|
|
31178
|
+
fs58.writeFileSync(
|
|
30829
31179
|
summaryFile,
|
|
30830
31180
|
JSON.stringify(summary3, null, 2) + "\n"
|
|
30831
31181
|
);
|
|
30832
31182
|
appendStepSummary(markdown);
|
|
30833
|
-
return
|
|
31183
|
+
return report2.ok ? 0 : 1;
|
|
30834
31184
|
}
|
|
30835
31185
|
let pushed;
|
|
30836
31186
|
if (pinnedVersion) {
|
|
@@ -30876,7 +31226,7 @@ function registerRunCommands2(worlds) {
|
|
|
30876
31226
|
const out = { ...summary2, branch, contentHash: pushed.contentHash };
|
|
30877
31227
|
ctx.stdout(JSON.stringify(out, null, 2));
|
|
30878
31228
|
if (summaryFile)
|
|
30879
|
-
|
|
31229
|
+
fs58.writeFileSync(summaryFile, JSON.stringify(out, null, 2) + "\n");
|
|
30880
31230
|
const rows = [
|
|
30881
31231
|
["avg reward", summary2.mean === null ? "n/a" : summary2.mean.toFixed(3)],
|
|
30882
31232
|
["tasks", String(summary2.results.length)],
|
|
@@ -30904,8 +31254,8 @@ init_worlds();
|
|
|
30904
31254
|
init_session2();
|
|
30905
31255
|
init_hub();
|
|
30906
31256
|
init_local();
|
|
30907
|
-
import * as
|
|
30908
|
-
import * as
|
|
31257
|
+
import * as fs59 from "fs";
|
|
31258
|
+
import * as path45 from "path";
|
|
30909
31259
|
function registerServeCommand(worlds) {
|
|
30910
31260
|
worlds.command({
|
|
30911
31261
|
name: "serve",
|
|
@@ -30973,14 +31323,14 @@ GATEWAY_RUNTIME=platform forces the hosted path.`,
|
|
|
30973
31323
|
run: async (args, ctx) => {
|
|
30974
31324
|
const target = args.positionals[0];
|
|
30975
31325
|
const local = localRuntime();
|
|
30976
|
-
if (local &&
|
|
31326
|
+
if (local && fs59.existsSync(target) && fs59.statSync(target).isDirectory()) {
|
|
30977
31327
|
const port = arg.int(args, "port") ?? 8080;
|
|
30978
31328
|
if (!Number.isInteger(port) || port < 0 || port > 65535)
|
|
30979
31329
|
throw new CliError(
|
|
30980
31330
|
`--port must be a port number (got ${String(args.flags.port)})`
|
|
30981
31331
|
);
|
|
30982
31332
|
if (port !== 0) await assertPortFree(port);
|
|
30983
|
-
const argv = ["serve",
|
|
31333
|
+
const argv = ["serve", path45.resolve(target), "--port", String(port)];
|
|
30984
31334
|
const apiKey = arg.str(args, "api-key");
|
|
30985
31335
|
if (apiKey) argv.push("--api-key", apiKey);
|
|
30986
31336
|
const uiPort = arg.str(args, "ui-port");
|
|
@@ -30990,11 +31340,11 @@ GATEWAY_RUNTIME=platform forces the hosted path.`,
|
|
|
30990
31340
|
const task = arg.str(args, "task");
|
|
30991
31341
|
if (task) argv.push("--task", task);
|
|
30992
31342
|
ctx.stderr(
|
|
30993
|
-
`# serving ${
|
|
31343
|
+
`# serving ${path45.resolve(target)} on http://127.0.0.1:${port} (local runtime: ${local.python})`
|
|
30994
31344
|
);
|
|
30995
31345
|
return localModule(argv, local);
|
|
30996
31346
|
}
|
|
30997
|
-
if (!local &&
|
|
31347
|
+
if (!local && fs59.existsSync(target) && fs59.statSync(target).isDirectory())
|
|
30998
31348
|
ctx.stderr(
|
|
30999
31349
|
`# ${localRuntimeReason()}
|
|
31000
31350
|
# A local directory is served here only by the bundled Python runtime; without one the CLI can only open a hosted session of a world already published (gateway worlds create <slug> --from ${target}), which needs a login (gateway auth login).`
|
|
@@ -31007,17 +31357,17 @@ GATEWAY_RUNTIME=platform forces the hosted path.`,
|
|
|
31007
31357
|
};
|
|
31008
31358
|
let slugRef = target;
|
|
31009
31359
|
let versionId;
|
|
31010
|
-
if (
|
|
31011
|
-
const dir =
|
|
31360
|
+
if (fs59.existsSync(target) && fs59.statSync(target).isDirectory()) {
|
|
31361
|
+
const dir = path45.resolve(target);
|
|
31012
31362
|
const meta = readLocalMeta(dir);
|
|
31013
|
-
const slug = meta?.slug ??
|
|
31363
|
+
const slug = meta?.slug ?? path45.basename(dir);
|
|
31014
31364
|
slugRef = meta?.branch ? `${slug}@${meta.branch}` : slug;
|
|
31015
31365
|
versionId = meta?.versionId;
|
|
31016
31366
|
}
|
|
31017
31367
|
ctx.stderr(
|
|
31018
31368
|
"`worlds serve` runs a local session with the Python runtime; opening a hosted api-surface session instead."
|
|
31019
31369
|
);
|
|
31020
|
-
if (!local && !(
|
|
31370
|
+
if (!local && !(fs59.existsSync(target) && fs59.statSync(target).isDirectory())) ctx.stderr(`# ${localRuntimeReason()}`);
|
|
31021
31371
|
let scenario = arg.str(args, "scenario") ?? arg.str(args, "task");
|
|
31022
31372
|
if (!scenario) {
|
|
31023
31373
|
const world = await openWorld(slugRef, options);
|
|
@@ -31060,12 +31410,13 @@ init_shared();
|
|
|
31060
31410
|
init_local();
|
|
31061
31411
|
init_config();
|
|
31062
31412
|
init_client();
|
|
31063
|
-
import * as
|
|
31064
|
-
import * as
|
|
31065
|
-
|
|
31413
|
+
import * as fs60 from "fs";
|
|
31414
|
+
import * as path46 from "path";
|
|
31415
|
+
var PYTHON_MARKS = { passed: " ok ", skipped: "skip" };
|
|
31416
|
+
function renderWorldTestReport(report2) {
|
|
31066
31417
|
const lines = [];
|
|
31067
31418
|
let group = null;
|
|
31068
|
-
for (const c of
|
|
31419
|
+
for (const c of report2.cases ?? []) {
|
|
31069
31420
|
const own = c.group?.trim() || "";
|
|
31070
31421
|
if (own !== (group ?? "") || group === null) {
|
|
31071
31422
|
group = own;
|
|
@@ -31077,7 +31428,15 @@ function renderWorldTestReport(report) {
|
|
|
31077
31428
|
if (c.description) lines.push(` ${c.description}`);
|
|
31078
31429
|
for (const p of c.problems ?? []) lines.push(` ! ${p}`);
|
|
31079
31430
|
}
|
|
31080
|
-
const py =
|
|
31431
|
+
const py = report2.python;
|
|
31432
|
+
let pyGroup = null;
|
|
31433
|
+
for (const c of py?.cases ?? []) {
|
|
31434
|
+
if (c.group !== pyGroup) lines.push(`== ${c.group ?? "python tests"}`);
|
|
31435
|
+
pyGroup = c.group ?? null;
|
|
31436
|
+
lines.push(`${PYTHON_MARKS[c.status] ?? "FAIL"} ${c.name}`);
|
|
31437
|
+
for (const p of c.problems ?? []) lines.push(` ! ${p.split("\n")[0]}`);
|
|
31438
|
+
}
|
|
31439
|
+
if (py?.cases_omitted) lines.push(` \u2026 ${py.cases_omitted} more not shown`);
|
|
31081
31440
|
if (py && py.status !== "none") {
|
|
31082
31441
|
const detail = py.reason ?? (py.status === "skipped" ? "skipped" : `${py.tests ?? 0} tests, ${py.failures ?? 0} failures, ${py.errors ?? 0} errors`);
|
|
31083
31442
|
lines.push(
|
|
@@ -31097,7 +31456,7 @@ function registerTestCommand(worlds) {
|
|
|
31097
31456
|
positionals: [
|
|
31098
31457
|
{
|
|
31099
31458
|
name: "path",
|
|
31100
|
-
help: "World directory (a schema world, or its api bundle), or a platform slug[@
|
|
31459
|
+
help: "World directory (a schema world, or its api bundle), or a platform slug[@ref] (a branch, tag, semver or version id) to run the suite on the platform."
|
|
31101
31460
|
}
|
|
31102
31461
|
],
|
|
31103
31462
|
flags: [
|
|
@@ -31116,15 +31475,15 @@ function registerTestCommand(worlds) {
|
|
|
31116
31475
|
notes: 'A world\'s tests live in <world>/tests/ and run in order against ONE session of the world, so a case sees\nwhat the cases before it wrote. *.json files hold cases of two shapes:\n {name, tool: "send_message", args: {...}, expect} a tool call (root tools by name, a dependency\'s as alias.tool);\n {name, request: {method, path, query?, headers?, body?, auth?}, expect} an HTTP call on the vendor routes (connector.toml).\nexpect is {status?, json?, length?, contains?, headers?}; a refused call (unknown tool, arguments off the\nschema) answers 400 with {error, detail}; a handler that raises answers 500 with {error: its message}.\ntests/test_*.py run under pytest with WORLD_DIR, WORLD_URL, WORLD_API_KEY, WORLD_ADMIN_TOKEN (the session\'s\nkey to its /__world/* routes, sent as X-World-Admin-Token) and, for a world with [ui], WORLD_UI_URL (its\npage on its own origin) set; a Python without pytest FAILS the suite, it never skips it.\nNo tests/ directory passes as zero cases. With `[actions] on_push = ["tests"]` in gateway-env.toml the\nplatform runs the same suite on every push; `gateway bench tests <slug>` reads those runs. Exit 1 when any\ntest fails.',
|
|
31117
31476
|
run: async (args, ctx) => {
|
|
31118
31477
|
const target = args.positionals[0] ?? ".";
|
|
31119
|
-
const dir =
|
|
31120
|
-
if (!
|
|
31478
|
+
const dir = path46.resolve(target);
|
|
31479
|
+
if (!fs60.existsSync(dir) || !fs60.statSync(dir).isDirectory()) {
|
|
31121
31480
|
if (/[\/\\]/.test(target) || target.startsWith("."))
|
|
31122
31481
|
throw new CliError(`Not a directory: ${dir}`, 1);
|
|
31123
31482
|
const creds2 = resolveCredentials(arg.str(args, "host"));
|
|
31124
31483
|
const [slug, ref] = target.split("@");
|
|
31125
31484
|
const scenario2 = arg.str(args, "scenario");
|
|
31126
31485
|
const body = {
|
|
31127
|
-
...ref ? {
|
|
31486
|
+
...ref ? { ref } : {},
|
|
31128
31487
|
...scenario2 ? { scenario: scenario2 } : {}
|
|
31129
31488
|
};
|
|
31130
31489
|
const url = `/api/public/worlds/${encodeURIComponent(slug)}/tests`;
|
|
@@ -31160,7 +31519,7 @@ function registerTestCommand(worlds) {
|
|
|
31160
31519
|
if (++misses >= 5) throw error;
|
|
31161
31520
|
}
|
|
31162
31521
|
}
|
|
31163
|
-
const
|
|
31522
|
+
const report3 = run.report ?? {};
|
|
31164
31523
|
if (arg.bool(args, "json"))
|
|
31165
31524
|
ctx.stdout(
|
|
31166
31525
|
JSON.stringify(
|
|
@@ -31169,15 +31528,15 @@ function registerTestCommand(worlds) {
|
|
|
31169
31528
|
state: run.state,
|
|
31170
31529
|
trigger: run.trigger ?? null,
|
|
31171
31530
|
versionId: run.versionId,
|
|
31172
|
-
...
|
|
31531
|
+
...report3
|
|
31173
31532
|
},
|
|
31174
31533
|
null,
|
|
31175
31534
|
1
|
|
31176
31535
|
)
|
|
31177
31536
|
);
|
|
31178
31537
|
else {
|
|
31179
|
-
for (const line of renderWorldTestReport(
|
|
31180
|
-
const s = run.summary ??
|
|
31538
|
+
for (const line of renderWorldTestReport(report3)) ctx.stdout(line);
|
|
31539
|
+
const s = run.summary ?? report3.summary ?? {};
|
|
31181
31540
|
ctx.stdout(
|
|
31182
31541
|
`${run.state}: ${s.passed ?? 0} passed, ${s.failed ?? 0} failed, ${s.skipped ?? 0} skipped (run ${run.id}${run.trigger ? `, trigger ${run.trigger}` : ""}, on ${run.versionId})`
|
|
31183
31542
|
);
|
|
@@ -31185,7 +31544,7 @@ function registerTestCommand(worlds) {
|
|
|
31185
31544
|
}
|
|
31186
31545
|
const out2 = arg.str(args, "out");
|
|
31187
31546
|
if (out2)
|
|
31188
|
-
|
|
31547
|
+
fs60.writeFileSync(
|
|
31189
31548
|
out2,
|
|
31190
31549
|
JSON.stringify(
|
|
31191
31550
|
{
|
|
@@ -31193,7 +31552,7 @@ function registerTestCommand(worlds) {
|
|
|
31193
31552
|
state: run.state,
|
|
31194
31553
|
trigger: run.trigger ?? null,
|
|
31195
31554
|
versionId: run.versionId,
|
|
31196
|
-
...
|
|
31555
|
+
...report3
|
|
31197
31556
|
},
|
|
31198
31557
|
null,
|
|
31199
31558
|
1
|
|
@@ -31208,14 +31567,14 @@ function registerTestCommand(worlds) {
|
|
|
31208
31567
|
...worldPayload(dir),
|
|
31209
31568
|
...scenario ? { scenario } : {}
|
|
31210
31569
|
});
|
|
31211
|
-
const
|
|
31212
|
-
if (arg.bool(args, "json")) ctx.stdout(JSON.stringify(
|
|
31570
|
+
const report2 = res.report ?? {};
|
|
31571
|
+
if (arg.bool(args, "json")) ctx.stdout(JSON.stringify(report2, null, 1));
|
|
31213
31572
|
else {
|
|
31214
|
-
for (const line of renderWorldTestReport(
|
|
31215
|
-
const s =
|
|
31216
|
-
if (!(s.total ?? 0) && !(
|
|
31217
|
-
const tests =
|
|
31218
|
-
const state2 =
|
|
31573
|
+
for (const line of renderWorldTestReport(report2)) ctx.stdout(line);
|
|
31574
|
+
const s = report2.summary ?? {};
|
|
31575
|
+
if (!(s.total ?? 0) && !(report2.python?.files?.length ?? 0)) {
|
|
31576
|
+
const tests = path46.join(dir, "tests");
|
|
31577
|
+
const state2 = fs60.existsSync(tests) ? "holds none" : "does not exist";
|
|
31219
31578
|
ctx.stdout(`no cases: ${tests} ${state2} (see \`gateway worlds test --help\` for the shapes)`);
|
|
31220
31579
|
}
|
|
31221
31580
|
ctx.stdout(
|
|
@@ -31224,10 +31583,10 @@ function registerTestCommand(worlds) {
|
|
|
31224
31583
|
}
|
|
31225
31584
|
const out = arg.str(args, "out");
|
|
31226
31585
|
if (out) {
|
|
31227
|
-
|
|
31586
|
+
fs60.writeFileSync(out, JSON.stringify(report2, null, 1) + "\n");
|
|
31228
31587
|
ctx.stdout(`report: ${out}`);
|
|
31229
31588
|
}
|
|
31230
|
-
return
|
|
31589
|
+
return report2.summary?.status === "passed" ? 0 : 1;
|
|
31231
31590
|
}
|
|
31232
31591
|
});
|
|
31233
31592
|
}
|
|
@@ -31240,16 +31599,16 @@ init_shared();
|
|
|
31240
31599
|
init_local();
|
|
31241
31600
|
init_client();
|
|
31242
31601
|
init_storeContract();
|
|
31243
|
-
import * as
|
|
31244
|
-
import * as
|
|
31602
|
+
import * as fs61 from "fs";
|
|
31603
|
+
import * as path47 from "path";
|
|
31245
31604
|
function parseArgs2(raw, stdin) {
|
|
31246
31605
|
if (raw === void 0) return {};
|
|
31247
31606
|
let text2 = raw;
|
|
31248
31607
|
if (raw === "-") text2 = stdin;
|
|
31249
31608
|
else if (raw.startsWith("@")) {
|
|
31250
31609
|
const file = raw.slice(1);
|
|
31251
|
-
if (!
|
|
31252
|
-
text2 =
|
|
31610
|
+
if (!fs61.existsSync(file)) throw new CliError(`--args ${raw}: ${file} does not exist`);
|
|
31611
|
+
text2 = fs61.readFileSync(file, "utf8");
|
|
31253
31612
|
}
|
|
31254
31613
|
let value;
|
|
31255
31614
|
try {
|
|
@@ -31262,10 +31621,10 @@ function parseArgs2(raw, stdin) {
|
|
|
31262
31621
|
return value;
|
|
31263
31622
|
}
|
|
31264
31623
|
var SERVED_URL = /^https?:\/\//;
|
|
31265
|
-
function settleStatus(
|
|
31266
|
-
const code =
|
|
31267
|
-
|
|
31268
|
-
return
|
|
31624
|
+
function settleStatus(report2) {
|
|
31625
|
+
const code = report2.result.status;
|
|
31626
|
+
report2.status = code >= 200 && code < 300 ? "ok" : code >= 500 ? "error" : "refused";
|
|
31627
|
+
return report2;
|
|
31269
31628
|
}
|
|
31270
31629
|
async function sessionVerb(base, verb, body) {
|
|
31271
31630
|
let response;
|
|
@@ -31294,7 +31653,7 @@ function platformFailureBody(detail) {
|
|
|
31294
31653
|
}
|
|
31295
31654
|
async function callHosted(sessionId, tool, args, wants, options) {
|
|
31296
31655
|
const live = await attachSession(sessionId, options);
|
|
31297
|
-
const
|
|
31656
|
+
const report2 = {
|
|
31298
31657
|
status: "ok",
|
|
31299
31658
|
tools: (await live.toolkit()).specs.map((spec) => spec.name),
|
|
31300
31659
|
result: { status: 0, body: null }
|
|
@@ -31306,25 +31665,25 @@ async function callHosted(sessionId, tool, args, wants, options) {
|
|
|
31306
31665
|
if (mode !== void 0 && mode !== "append" && mode !== "replace")
|
|
31307
31666
|
throw new CliError("--seed mode must be append or replace");
|
|
31308
31667
|
const seeded = await live.seed(rows, mode ? { mode } : {});
|
|
31309
|
-
|
|
31668
|
+
report2.seed = seeded;
|
|
31310
31669
|
}
|
|
31311
31670
|
try {
|
|
31312
31671
|
const answer = await live.call(tool, args);
|
|
31313
|
-
|
|
31672
|
+
report2.result = isRouteAnswer(answer) ? answer : { status: 200, body: answer };
|
|
31314
31673
|
} catch (error) {
|
|
31315
31674
|
if (!(error instanceof WorldSessionCallError)) throw error;
|
|
31316
|
-
|
|
31675
|
+
report2.result = { status: 500, body: platformFailureBody(error.message) };
|
|
31317
31676
|
}
|
|
31318
|
-
if (wants.state)
|
|
31319
|
-
if (wants.grade)
|
|
31677
|
+
if (wants.state) report2.state = await live.state();
|
|
31678
|
+
if (wants.grade) report2.grade = await live.grade();
|
|
31320
31679
|
if (wants.close) {
|
|
31321
31680
|
await live.close();
|
|
31322
|
-
|
|
31681
|
+
report2.closed = true;
|
|
31323
31682
|
}
|
|
31324
|
-
return settleStatus(
|
|
31683
|
+
return settleStatus(report2);
|
|
31325
31684
|
}
|
|
31326
31685
|
function looksLikeSessionId(target) {
|
|
31327
|
-
return !target.includes("/") && !target.startsWith(".") && !
|
|
31686
|
+
return !target.includes("/") && !target.startsWith(".") && !fs61.existsSync(target);
|
|
31328
31687
|
}
|
|
31329
31688
|
async function callServed(base, tool, args, wants) {
|
|
31330
31689
|
const url = base.replace(/\/+$/, "");
|
|
@@ -31334,7 +31693,7 @@ async function callServed(base, tool, args, wants) {
|
|
|
31334
31693
|
`${url} is not a served world session: GET /__session/tools answered ${tools.status}.` + (tools.status === 401 || tools.status === 403 || tools.status === 404 ? " A hosted session's api url takes its own token and serves no /__session verbs \u2014 pass the sessionId `gateway worlds session open` printed instead." : ""),
|
|
31335
31694
|
1
|
|
31336
31695
|
);
|
|
31337
|
-
const
|
|
31696
|
+
const report2 = {
|
|
31338
31697
|
status: "ok",
|
|
31339
31698
|
tools: tools.body.tools,
|
|
31340
31699
|
result: { status: 0, body: null }
|
|
@@ -31343,18 +31702,18 @@ async function callServed(base, tool, args, wants) {
|
|
|
31343
31702
|
const seeded = await sessionVerb(url, "seed", wants.seed);
|
|
31344
31703
|
if (seeded.status !== 200)
|
|
31345
31704
|
throw new CliError(`POST /__session/seed answered ${seeded.status}: ${JSON.stringify(seeded.body)}`, 1);
|
|
31346
|
-
|
|
31705
|
+
report2.seed = seeded.body;
|
|
31347
31706
|
}
|
|
31348
31707
|
const answer = await sessionVerb(url, "call", { tool, args });
|
|
31349
|
-
|
|
31350
|
-
if (wants.state)
|
|
31351
|
-
if (wants.grade)
|
|
31708
|
+
report2.result = answer.status === 200 && answer.body && typeof answer.body === "object" && "status" in answer.body ? answer.body : { status: answer.status, body: answer.body };
|
|
31709
|
+
if (wants.state) report2.state = (await sessionVerb(url, "state")).body;
|
|
31710
|
+
if (wants.grade) report2.grade = (await sessionVerb(url, "grade", {})).body;
|
|
31352
31711
|
if (wants.close) {
|
|
31353
31712
|
const closed = await sessionVerb(url, "close", {});
|
|
31354
31713
|
if (closed.status !== 200) throw new CliError(`POST /__session/close answered ${closed.status}`, 1);
|
|
31355
|
-
|
|
31714
|
+
report2.closed = true;
|
|
31356
31715
|
}
|
|
31357
|
-
return settleStatus(
|
|
31716
|
+
return settleStatus(report2);
|
|
31358
31717
|
}
|
|
31359
31718
|
function registerCallCommand(worlds) {
|
|
31360
31719
|
worlds.command({
|
|
@@ -31415,14 +31774,14 @@ Examples:
|
|
|
31415
31774
|
throw new CliError(`--${flag} belongs to \`gateway worlds serve\`; the session at ${target} already has its own`);
|
|
31416
31775
|
const stdin2 = args.flags.args === "-" || args.flags.seed === "-" ? await ctx.stdin() : "";
|
|
31417
31776
|
const seedRaw2 = arg.str(args, "seed");
|
|
31418
|
-
const
|
|
31777
|
+
const report3 = await callServed(target, tool, parseArgs2(arg.str(args, "args"), stdin2), {
|
|
31419
31778
|
...seedRaw2 === void 0 ? {} : { seed: parseArgs2(seedRaw2, stdin2) },
|
|
31420
31779
|
state: arg.bool(args, "state"),
|
|
31421
31780
|
grade: arg.bool(args, "grade"),
|
|
31422
31781
|
close: arg.bool(args, "close")
|
|
31423
31782
|
});
|
|
31424
|
-
ctx.stdout(JSON.stringify(
|
|
31425
|
-
return
|
|
31783
|
+
ctx.stdout(JSON.stringify(report3, null, 2));
|
|
31784
|
+
return report3.result.status >= 200 && report3.result.status < 300 ? 0 : 1;
|
|
31426
31785
|
}
|
|
31427
31786
|
if (looksLikeSessionId(target)) {
|
|
31428
31787
|
for (const flag of ["task", "scenario"])
|
|
@@ -31431,7 +31790,7 @@ Examples:
|
|
|
31431
31790
|
const stdin2 = args.flags.args === "-" || args.flags.seed === "-" ? await ctx.stdin() : "";
|
|
31432
31791
|
const seedRaw2 = arg.str(args, "seed");
|
|
31433
31792
|
try {
|
|
31434
|
-
const
|
|
31793
|
+
const report3 = await callHosted(
|
|
31435
31794
|
target,
|
|
31436
31795
|
tool,
|
|
31437
31796
|
parseArgs2(arg.str(args, "args"), stdin2),
|
|
@@ -31443,8 +31802,8 @@ Examples:
|
|
|
31443
31802
|
},
|
|
31444
31803
|
worldsOptions(credentials(args))
|
|
31445
31804
|
);
|
|
31446
|
-
ctx.stdout(JSON.stringify(
|
|
31447
|
-
return
|
|
31805
|
+
ctx.stdout(JSON.stringify(report3, null, 2));
|
|
31806
|
+
return report3.result.status >= 200 && report3.result.status < 300 ? 0 : 1;
|
|
31448
31807
|
} catch (error) {
|
|
31449
31808
|
if (!(error instanceof WorldCallTooLarge)) throw error;
|
|
31450
31809
|
ctx.stdout(JSON.stringify(error.toJSON(), null, 2));
|
|
@@ -31452,8 +31811,8 @@ Examples:
|
|
|
31452
31811
|
}
|
|
31453
31812
|
}
|
|
31454
31813
|
if (arg.bool(args, "close")) throw new CliError("--close ends a served or hosted session; pass its url or id instead of a directory");
|
|
31455
|
-
const dir =
|
|
31456
|
-
if (!
|
|
31814
|
+
const dir = path47.resolve(target);
|
|
31815
|
+
if (!fs61.existsSync(dir) || !fs61.statSync(dir).isDirectory()) throw new CliError(`Not a directory: ${dir}`, 1);
|
|
31457
31816
|
const local = localRuntime();
|
|
31458
31817
|
if (!local)
|
|
31459
31818
|
throw new CliError(
|
|
@@ -31481,21 +31840,21 @@ Examples:
|
|
|
31481
31840
|
);
|
|
31482
31841
|
const detail = detailFrom(payload);
|
|
31483
31842
|
if (detail) throw new BridgeRejected(detail);
|
|
31484
|
-
const
|
|
31485
|
-
ctx.stdout(JSON.stringify(
|
|
31486
|
-
return
|
|
31843
|
+
const report2 = settleStatus(payload);
|
|
31844
|
+
ctx.stdout(JSON.stringify(report2, null, 2));
|
|
31845
|
+
return report2.result.status >= 200 && report2.result.status < 300 ? 0 : 1;
|
|
31487
31846
|
}
|
|
31488
31847
|
});
|
|
31489
31848
|
}
|
|
31490
31849
|
|
|
31491
31850
|
// src/cli/runtime/scaffold.ts
|
|
31492
31851
|
init_router();
|
|
31493
|
-
import * as
|
|
31494
|
-
import * as
|
|
31852
|
+
import * as fs65 from "fs";
|
|
31853
|
+
import * as path50 from "path";
|
|
31495
31854
|
|
|
31496
31855
|
// src/cli/runtime/scaffoldJson.ts
|
|
31497
31856
|
init_router();
|
|
31498
|
-
import * as
|
|
31857
|
+
import * as fs62 from "fs";
|
|
31499
31858
|
var PROPERTY_NAME = /^[A-Za-z_][A-Za-z0-9_-]*$/;
|
|
31500
31859
|
var isObject12 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31501
31860
|
function resolveObjectSchema(root, schema) {
|
|
@@ -31509,10 +31868,10 @@ function resolveObjectSchema(root, schema) {
|
|
|
31509
31868
|
return schema;
|
|
31510
31869
|
}
|
|
31511
31870
|
function readJsonFile2(file) {
|
|
31512
|
-
if (!
|
|
31871
|
+
if (!fs62.existsSync(file)) throw new CliError(`${file} does not exist; run \`gateway worlds schema init\` first`, 1);
|
|
31513
31872
|
let parsed;
|
|
31514
31873
|
try {
|
|
31515
|
-
parsed = JSON.parse(
|
|
31874
|
+
parsed = JSON.parse(fs62.readFileSync(file, "utf8"));
|
|
31516
31875
|
} catch (err) {
|
|
31517
31876
|
throw new CliError(`${file} is not valid JSON: ${err.message}`, 1);
|
|
31518
31877
|
}
|
|
@@ -31612,7 +31971,7 @@ function declaredRoutes(toml) {
|
|
|
31612
31971
|
const params = list("params");
|
|
31613
31972
|
if (params) current.params = params;
|
|
31614
31973
|
}
|
|
31615
|
-
for (const
|
|
31974
|
+
for (const route2 of routes) if (!route2.methods.length) route2.methods.push("GET");
|
|
31616
31975
|
return routes;
|
|
31617
31976
|
}
|
|
31618
31977
|
function removeRoute(toml, name) {
|
|
@@ -31690,10 +32049,10 @@ function addRoute(toml, spec, declaredEntities2, options = {}) {
|
|
|
31690
32049
|
`--action ${spec.api.action} writes, but --method GET reads; pass --method ${spec.api.action === "create" ? "POST" : spec.api.action === "update" ? "PATCH" : "DELETE"}`
|
|
31691
32050
|
);
|
|
31692
32051
|
const sameParams = (a, b) => a.length === b.length && [...a].sort().every((v, i) => v === [...b].sort()[i]);
|
|
31693
|
-
for (const
|
|
31694
|
-
if (
|
|
32052
|
+
for (const route2 of declaredRoutes(toml))
|
|
32053
|
+
if (route2.name !== spec.name && route2.path === spec.path && route2.methods.includes(spec.method) && sameParams(route2.params, spec.params))
|
|
31695
32054
|
throw new CliError(
|
|
31696
|
-
`${spec.method} ${spec.path} is already answered by operation ${
|
|
32055
|
+
`${spec.method} ${spec.path} is already answered by operation ${route2.name} with the same params; a second route there would never be reached \u2014 give it another path, method or --param, or --replace that one`
|
|
31697
32056
|
);
|
|
31698
32057
|
if (spec.entity !== void 0 && declaredEntities2 && !declaredEntities2.includes(spec.entity))
|
|
31699
32058
|
throw new CliError(
|
|
@@ -31739,8 +32098,8 @@ function declaredEntityShapes(root) {
|
|
|
31739
32098
|
|
|
31740
32099
|
// src/cli/runtime/scaffoldEntityRemove.ts
|
|
31741
32100
|
init_router();
|
|
31742
|
-
import * as
|
|
31743
|
-
import * as
|
|
32101
|
+
import * as fs63 from "fs";
|
|
32102
|
+
import * as path48 from "path";
|
|
31744
32103
|
var LOCAL_DEF = "#/$defs/";
|
|
31745
32104
|
function localRefs(value, found = /* @__PURE__ */ new Set()) {
|
|
31746
32105
|
if (Array.isArray(value)) value.forEach((item) => localRefs(item, found));
|
|
@@ -31774,8 +32133,8 @@ var EntityRemoval = class _EntityRemoval {
|
|
|
31774
32133
|
file;
|
|
31775
32134
|
root;
|
|
31776
32135
|
static open(dir) {
|
|
31777
|
-
const file =
|
|
31778
|
-
if (!
|
|
32136
|
+
const file = path48.join(dir, "schema", "world.json");
|
|
32137
|
+
if (!fs63.existsSync(file)) throw new CliError(`${dir} has no schema/world.json`);
|
|
31779
32138
|
return new _EntityRemoval(dir, file, readJsonFile2(file));
|
|
31780
32139
|
}
|
|
31781
32140
|
get entities() {
|
|
@@ -31785,8 +32144,8 @@ var EntityRemoval = class _EntityRemoval {
|
|
|
31785
32144
|
return gateway.entities;
|
|
31786
32145
|
}
|
|
31787
32146
|
read(rel) {
|
|
31788
|
-
const file =
|
|
31789
|
-
return
|
|
32147
|
+
const file = path48.join(this.dir, rel);
|
|
32148
|
+
return fs63.existsSync(file) ? fs63.readFileSync(file, "utf8") : void 0;
|
|
31790
32149
|
}
|
|
31791
32150
|
relationships(name) {
|
|
31792
32151
|
return Object.entries(this.entities).filter(([other]) => other !== name).filter(
|
|
@@ -31806,11 +32165,11 @@ var EntityRemoval = class _EntityRemoval {
|
|
|
31806
32165
|
return [...new Set(found)];
|
|
31807
32166
|
}
|
|
31808
32167
|
verifiers(name) {
|
|
31809
|
-
const placeholder =
|
|
31810
|
-
return (verifierNames(this.dir) ?? []).map((verifier) =>
|
|
32168
|
+
const placeholder = path48.join(this.dir, "verifiers", "state_present.sql");
|
|
32169
|
+
return (verifierNames(this.dir) ?? []).map((verifier) => path48.join(this.dir, "verifiers", `${verifier}.sql`)).filter((file) => !(file === placeholder && scaffoldVerifierEntity(file) === name)).filter((file) => sqlMentions(fs63.readFileSync(file, "utf8"), name)).map((file) => `verifiers/${path48.basename(file)} reads ${name}`);
|
|
31811
32170
|
}
|
|
31812
32171
|
data(name) {
|
|
31813
|
-
const text2 = this.read(
|
|
32172
|
+
const text2 = this.read(path48.join("data", "initial.json"));
|
|
31814
32173
|
if (text2 === void 0) return [];
|
|
31815
32174
|
const journal = this.journal(text2);
|
|
31816
32175
|
const rows = (journal.mutations ?? []).filter((m) => m.entity === name).length;
|
|
@@ -31864,7 +32223,7 @@ var EntityRemoval = class _EntityRemoval {
|
|
|
31864
32223
|
const defs = isObject12(this.root.$defs) ? this.root.$defs : {};
|
|
31865
32224
|
removedDefs.forEach((def) => delete defs[def]);
|
|
31866
32225
|
delete this.entities[name];
|
|
31867
|
-
|
|
32226
|
+
fs63.writeFileSync(this.file, JSON.stringify(this.root, null, 2) + "\n");
|
|
31868
32227
|
const remaining = Object.keys(this.entities).sort();
|
|
31869
32228
|
return { removedDefs, verifier: repointScaffoldVerifier(this.dir, remaining[0], remaining) };
|
|
31870
32229
|
}
|
|
@@ -31879,18 +32238,18 @@ function registerEntityRemove(entity) {
|
|
|
31879
32238
|
],
|
|
31880
32239
|
notes: "Nothing is written when the entity is still referenced: every connector.toml operation that answers from\nit, every verifiers/*.sql that reads it, rows of it in data/initial.json, a [dependencies.<alias>.entities]\nmap and another entity's relationship are named, one per line (exit 2). The world keeps at least one entity:\n`gateway worlds schema entity add` the replacement first. The untouched placeholder verifiers/state_present.sql\nis re-pointed at an entity that stays. Then `gateway worlds schema compile <path>` and `gateway worlds schema check <path>`.",
|
|
31881
32240
|
run: async (args, ctx) => {
|
|
31882
|
-
const dir =
|
|
32241
|
+
const dir = path48.resolve(args.positionals[0]);
|
|
31883
32242
|
const name = args.positionals[1];
|
|
31884
32243
|
const { removedDefs, verifier } = EntityRemoval.open(dir).remove(name);
|
|
31885
|
-
const rel =
|
|
32244
|
+
const rel = path48.relative(process.cwd(), dir) || ".";
|
|
31886
32245
|
ctx.stdout(
|
|
31887
32246
|
JSON.stringify(
|
|
31888
32247
|
{
|
|
31889
32248
|
status: "ok",
|
|
31890
32249
|
entity: name,
|
|
31891
32250
|
removedDefs,
|
|
31892
|
-
...verifier ? { verifier:
|
|
31893
|
-
file:
|
|
32251
|
+
...verifier ? { verifier: path48.relative(process.cwd(), verifier) || verifier } : {},
|
|
32252
|
+
file: path48.relative(process.cwd(), path48.join(dir, "schema", "world.json")),
|
|
31894
32253
|
next: [`gateway worlds schema compile ${rel}`, `gateway worlds schema check ${rel}`]
|
|
31895
32254
|
},
|
|
31896
32255
|
null,
|
|
@@ -31903,8 +32262,8 @@ function registerEntityRemove(entity) {
|
|
|
31903
32262
|
|
|
31904
32263
|
// src/cli/runtime/scaffoldHandlers.ts
|
|
31905
32264
|
init_router();
|
|
31906
|
-
import * as
|
|
31907
|
-
import * as
|
|
32265
|
+
import * as fs64 from "fs";
|
|
32266
|
+
import * as path49 from "path";
|
|
31908
32267
|
var PYTHON_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
31909
32268
|
var HANDLERS_FILE = "api/handlers.py";
|
|
31910
32269
|
var HEADER = '"""The world\'s own logic. Each connector.toml operation with action = "handler" calls the\nfunction it names here as fn(ctx, args, query, body), which answers (status, body) or a body;\n`ctx` reads and writes the store (rows, get, insert, update, delete) and mints ids and times."""\n';
|
|
@@ -31913,12 +32272,12 @@ var HandlerStub = class {
|
|
|
31913
32272
|
this.name = name;
|
|
31914
32273
|
if (!PYTHON_NAME.test(name))
|
|
31915
32274
|
throw new CliError(`--handler is a Python function name ([A-Za-z_][A-Za-z0-9_]*), got ${JSON.stringify(name)}`);
|
|
31916
|
-
this.file =
|
|
32275
|
+
this.file = path49.join(dir, HANDLERS_FILE);
|
|
31917
32276
|
}
|
|
31918
32277
|
name;
|
|
31919
32278
|
file;
|
|
31920
32279
|
get source() {
|
|
31921
|
-
return
|
|
32280
|
+
return fs64.existsSync(this.file) ? fs64.readFileSync(this.file, "utf8") : void 0;
|
|
31922
32281
|
}
|
|
31923
32282
|
get defined() {
|
|
31924
32283
|
const source2 = this.source ?? "";
|
|
@@ -31936,9 +32295,9 @@ var HandlerStub = class {
|
|
|
31936
32295
|
ensure() {
|
|
31937
32296
|
if (this.defined) return false;
|
|
31938
32297
|
const current = this.source;
|
|
31939
|
-
|
|
32298
|
+
fs64.mkdirSync(path49.dirname(this.file), { recursive: true });
|
|
31940
32299
|
const head = current === void 0 ? HEADER : current.replace(/\n*$/, "\n");
|
|
31941
|
-
|
|
32300
|
+
fs64.writeFileSync(this.file, `${head}
|
|
31942
32301
|
|
|
31943
32302
|
${this.stub()}`);
|
|
31944
32303
|
return true;
|
|
@@ -32218,11 +32577,11 @@ function removeDependency(toml, alias) {
|
|
|
32218
32577
|
return kept.join("\n") + "\n";
|
|
32219
32578
|
}
|
|
32220
32579
|
function dependencyServes(depDir) {
|
|
32221
|
-
const manifest =
|
|
32222
|
-
if (!
|
|
32223
|
-
const tools = manifestServedTools(
|
|
32224
|
-
const connector =
|
|
32225
|
-
const routes =
|
|
32580
|
+
const manifest = path50.join(depDir, "gateway-env.toml");
|
|
32581
|
+
if (!fs65.existsSync(manifest)) return void 0;
|
|
32582
|
+
const tools = manifestServedTools(fs65.readFileSync(manifest, "utf8"));
|
|
32583
|
+
const connector = path50.join(depDir, "connector.toml");
|
|
32584
|
+
const routes = fs65.existsSync(connector) ? declaredRoutes(fs65.readFileSync(connector, "utf8")).map((r) => r.name).filter(Boolean) : [];
|
|
32226
32585
|
return tools === void 0 ? void 0 : { tools, routes };
|
|
32227
32586
|
}
|
|
32228
32587
|
function addDependency(toml, spec, depServes, opts = {}) {
|
|
@@ -32235,7 +32594,7 @@ function addDependency(toml, spec, depServes, opts = {}) {
|
|
|
32235
32594
|
toml = removeDependency(toml, spec.alias);
|
|
32236
32595
|
}
|
|
32237
32596
|
if (!PIN.test(spec.pin)) throw new CliError(`--pin is <slug>@<ref>, got ${JSON.stringify(spec.pin)}`);
|
|
32238
|
-
if (
|
|
32597
|
+
if (path50.isAbsolute(spec.path)) throw new CliError("The dependency path is stored relative to the world");
|
|
32239
32598
|
if (depServes) {
|
|
32240
32599
|
const serves = Array.isArray(depServes) ? { tools: depServes, routes: [] } : depServes;
|
|
32241
32600
|
for (const tool of spec.tools)
|
|
@@ -32305,37 +32664,37 @@ function dependencyPath(toml, alias) {
|
|
|
32305
32664
|
return void 0;
|
|
32306
32665
|
}
|
|
32307
32666
|
function readManifest2(dir) {
|
|
32308
|
-
const file =
|
|
32309
|
-
if (!
|
|
32310
|
-
return { file, toml:
|
|
32667
|
+
const file = path50.join(dir, "gateway-env.toml");
|
|
32668
|
+
if (!fs65.existsSync(file)) throw new CliError(`${dir} holds no gateway-env.toml; run \`gateway worlds schema init\` first`, 1);
|
|
32669
|
+
return { file, toml: fs65.readFileSync(file, "utf8") };
|
|
32311
32670
|
}
|
|
32312
|
-
var toPosix = (p) => p.split(
|
|
32671
|
+
var toPosix = (p) => p.split(path50.sep).join("/");
|
|
32313
32672
|
var pinSlug = (name) => name.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^[^a-z0-9]+/, "") || "world";
|
|
32314
32673
|
function declaredEntities(dir) {
|
|
32315
|
-
const file =
|
|
32316
|
-
if (!
|
|
32674
|
+
const file = path50.join(dir, "schema", "world.json");
|
|
32675
|
+
if (!fs65.existsSync(file)) return void 0;
|
|
32317
32676
|
const gateway = readJsonFile2(file)["x-gateway"];
|
|
32318
32677
|
return isObject12(gateway) && isObject12(gateway.entities) ? Object.keys(gateway.entities) : [];
|
|
32319
32678
|
}
|
|
32320
32679
|
function worldEntityShapes(dir) {
|
|
32321
|
-
const file =
|
|
32322
|
-
return
|
|
32680
|
+
const file = path50.join(dir, "schema", "world.json");
|
|
32681
|
+
return fs65.existsSync(file) ? declaredEntityShapes(readJsonFile2(file)) : void 0;
|
|
32323
32682
|
}
|
|
32324
32683
|
function declaredHandlerTools(dir) {
|
|
32325
|
-
const file =
|
|
32326
|
-
if (!
|
|
32684
|
+
const file = path50.join(dir, "schema", "world.json");
|
|
32685
|
+
if (!fs65.existsSync(file)) return [];
|
|
32327
32686
|
const gateway = readJsonFile2(file)["x-gateway"];
|
|
32328
32687
|
return isObject12(gateway) && isObject12(gateway.tools) ? Object.keys(gateway.tools) : [];
|
|
32329
32688
|
}
|
|
32330
32689
|
var WORLD_SLUG = /^[a-z0-9][a-z0-9-]*$/;
|
|
32331
32690
|
function connectorTomlSkeleton(dir) {
|
|
32332
|
-
const manifest =
|
|
32333
|
-
if (!
|
|
32691
|
+
const manifest = path50.join(dir, "gateway-env.toml");
|
|
32692
|
+
if (!fs65.existsSync(dir))
|
|
32334
32693
|
throw new CliError(`${dir} does not exist; run \`gateway worlds schema init ${dir} --connector custom\` to start a world there`, 1);
|
|
32335
|
-
if (!
|
|
32694
|
+
if (!fs65.existsSync(manifest))
|
|
32336
32695
|
throw new CliError(`${dir} holds no connector.toml and no gateway-env.toml (not a world); run \`gateway worlds schema init ${dir} --connector custom\` first`, 1);
|
|
32337
|
-
const name = /^\s*name\s*=\s*"([^"]*)"/m.exec(
|
|
32338
|
-
const slug = name && WORLD_SLUG.test(name) ? name :
|
|
32696
|
+
const name = /^\s*name\s*=\s*"([^"]*)"/m.exec(fs65.readFileSync(manifest, "utf8"))?.[1];
|
|
32697
|
+
const slug = name && WORLD_SLUG.test(name) ? name : path50.basename(dir).toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "") || "world";
|
|
32339
32698
|
return [
|
|
32340
32699
|
`# ${slug}'s API surface: the HTTP routes the world serves beside its tools, from one`,
|
|
32341
32700
|
"# World Host session. Declare routes with `gateway worlds connector route add`; an",
|
|
@@ -32387,8 +32746,8 @@ function registerScaffoldCommands(worlds) {
|
|
|
32387
32746
|
],
|
|
32388
32747
|
notes: "Exactly one of --ref, --fields or --schema. The file is rewritten with two-space indentation;\nrun `gateway worlds schema compile <path>` afterwards (the compiled contract is stale until then), then\n`gateway worlds schema check <path>` for the full contract check.",
|
|
32389
32748
|
run: async (args, ctx) => {
|
|
32390
|
-
const dir =
|
|
32391
|
-
const file =
|
|
32749
|
+
const dir = path50.resolve(args.positionals[0]);
|
|
32750
|
+
const file = path50.join(dir, "schema", "world.json");
|
|
32392
32751
|
const root = readJsonFile2(file);
|
|
32393
32752
|
let inline;
|
|
32394
32753
|
const schemaFlag = arg.str(args, "schema");
|
|
@@ -32412,12 +32771,12 @@ function registerScaffoldCommands(worlds) {
|
|
|
32412
32771
|
unique: arg.list(args, "unique").map((u) => u.split(",").map((f) => f.trim()).filter(Boolean)),
|
|
32413
32772
|
relationships: arg.list(args, "relationship").map(parseRelationship)
|
|
32414
32773
|
});
|
|
32415
|
-
|
|
32416
|
-
const out = { status: "ok", entity: name, declaration, file:
|
|
32774
|
+
fs65.writeFileSync(file, JSON.stringify(document, null, 2) + "\n");
|
|
32775
|
+
const out = { status: "ok", entity: name, declaration, file: path50.relative(process.cwd(), file) || file };
|
|
32417
32776
|
if (def) out.def = def;
|
|
32418
32777
|
const verifier = repointScaffoldVerifier(dir, name, declaredEntities(dir) ?? []);
|
|
32419
32778
|
if (verifier) {
|
|
32420
|
-
out.verifier =
|
|
32779
|
+
out.verifier = path50.relative(process.cwd(), verifier) || verifier;
|
|
32421
32780
|
ctx.stderr(`# ${out.verifier} named an entity the catalog no longer declares; it now scores over ${name}`);
|
|
32422
32781
|
}
|
|
32423
32782
|
ctx.stdout(JSON.stringify(out, null, 2));
|
|
@@ -32437,7 +32796,7 @@ function registerScaffoldCommands(worlds) {
|
|
|
32437
32796
|
],
|
|
32438
32797
|
notes: "A verifier is one SQL statement returning one number in 0..1 (1.0 passed, 0.0 failed, in between partial\ncredit); each entity is a table named as in the catalog, each field a column. Edit the file freely, then\n`gateway worlds schema task add <path> <task> --verifier <name>` grades a task on it.",
|
|
32439
32798
|
run: async (args, ctx) => {
|
|
32440
|
-
const dir =
|
|
32799
|
+
const dir = path50.resolve(args.positionals[0]);
|
|
32441
32800
|
const name = args.positionals[1];
|
|
32442
32801
|
const entity2 = arg.str(args, "entity");
|
|
32443
32802
|
const declared = declaredEntities(dir);
|
|
@@ -32445,14 +32804,14 @@ function registerScaffoldCommands(worlds) {
|
|
|
32445
32804
|
if (!entity2) throw new CliError(`--entity is required: one of ${declared.join(", ") || "(declare one with `gateway worlds schema entity add` first)"}`);
|
|
32446
32805
|
if (!declared.includes(entity2)) throw new CliError(`Unknown entity ${entity2}; the world has ${declared.join(", ") || "none"}`);
|
|
32447
32806
|
const file = addVerifier(dir, name, entity2, arg.str(args, "where"));
|
|
32448
|
-
const rel =
|
|
32807
|
+
const rel = path50.relative(process.cwd(), dir) || ".";
|
|
32449
32808
|
ctx.stdout(
|
|
32450
32809
|
JSON.stringify(
|
|
32451
32810
|
{
|
|
32452
32811
|
status: "ok",
|
|
32453
32812
|
verifier: name,
|
|
32454
32813
|
entity: entity2,
|
|
32455
|
-
file:
|
|
32814
|
+
file: path50.relative(process.cwd(), file) || file,
|
|
32456
32815
|
next: `gateway worlds schema task add ${rel} <task_id> --prompt "<what the agent is told>" --verifier ${name}`
|
|
32457
32816
|
},
|
|
32458
32817
|
null,
|
|
@@ -32489,39 +32848,39 @@ function registerScaffoldCommands(worlds) {
|
|
|
32489
32848
|
],
|
|
32490
32849
|
notes: "The block is appended; existing text is untouched. `path` is written relative to the world so\n`schema check`, `test`, `serve` and `call` open the dependency here; the pin is what the platform\nresolves when both worlds are pushed. Then `gateway worlds schema check <path>` shows the link under\n`dependencies`, and `gateway worlds schema task add` grades it with --world <alias>=<verifier>.",
|
|
32491
32850
|
run: async (args, ctx) => {
|
|
32492
|
-
const dir =
|
|
32851
|
+
const dir = path50.resolve(args.positionals[0]);
|
|
32493
32852
|
const alias = args.positionals[1];
|
|
32494
32853
|
const depArg = args.positionals[2];
|
|
32495
|
-
const depDir =
|
|
32854
|
+
const depDir = path50.resolve(depArg);
|
|
32496
32855
|
const { file, toml } = readManifest2(dir);
|
|
32497
|
-
if (!
|
|
32498
|
-
const fromWorld =
|
|
32499
|
-
const hint = fromWorld !== depDir &&
|
|
32856
|
+
if (!fs65.existsSync(path50.join(depDir, "gateway-env.toml"))) {
|
|
32857
|
+
const fromWorld = path50.resolve(dir, depArg);
|
|
32858
|
+
const hint = fromWorld !== depDir && fs65.existsSync(path50.join(fromWorld, "gateway-env.toml")) ? `; paths resolve from your shell, not from the world: did you mean ${path50.relative(process.cwd(), fromWorld) || "."}?` : "";
|
|
32500
32859
|
throw new CliError(
|
|
32501
32860
|
`${depDir} holds no gateway-env.toml; the dependency must be a schema world (\`gateway worlds schema init\`)${hint}`,
|
|
32502
32861
|
1
|
|
32503
32862
|
);
|
|
32504
32863
|
}
|
|
32505
|
-
if (
|
|
32506
|
-
const depToml =
|
|
32864
|
+
if (path50.resolve(depDir) === dir) throw new CliError("A world cannot depend on itself");
|
|
32865
|
+
const depToml = fs65.readFileSync(path50.join(depDir, "gateway-env.toml"), "utf8");
|
|
32507
32866
|
if (declaredAliases(depToml).length)
|
|
32508
32867
|
throw new CliError(`${depDir} has [dependencies] of its own (${declaredAliases(depToml).join(", ")}); links nest one level`);
|
|
32509
32868
|
const task = arg.str(args, "task");
|
|
32510
|
-
if (task !== void 0 && !
|
|
32511
|
-
const have =
|
|
32869
|
+
if (task !== void 0 && !fs65.existsSync(path50.join(depDir, "scenarios", task))) {
|
|
32870
|
+
const have = fs65.existsSync(path50.join(depDir, "scenarios")) ? fs65.readdirSync(path50.join(depDir, "scenarios")) : [];
|
|
32512
32871
|
throw new CliError(`${depDir} has no scenarios/${task}/ (have: ${have.join(", ") || "none"})`);
|
|
32513
32872
|
}
|
|
32514
|
-
const rel = toPosix(
|
|
32873
|
+
const rel = toPosix(path50.relative(dir, depDir)) || ".";
|
|
32515
32874
|
const spec = {
|
|
32516
32875
|
alias,
|
|
32517
|
-
pin: arg.str(args, "pin") ?? `${pinSlug(manifestName(depToml) ??
|
|
32876
|
+
pin: arg.str(args, "pin") ?? `${pinSlug(manifestName(depToml) ?? path50.basename(depDir))}@main`,
|
|
32518
32877
|
path: rel.startsWith(".") ? rel : `./${rel}`,
|
|
32519
32878
|
task,
|
|
32520
32879
|
tools: arg.list(args, "tools").flatMap((t) => t.split(",")).map((t) => t.trim()).filter(Boolean),
|
|
32521
32880
|
entities: arg.list(args, "map").map(parseEntityMap)
|
|
32522
32881
|
};
|
|
32523
32882
|
const updated = addDependency(toml, spec, dependencyServes(depDir), { replace: arg.bool(args, "replace") });
|
|
32524
|
-
|
|
32883
|
+
fs65.writeFileSync(file, updated);
|
|
32525
32884
|
ctx.stdout(
|
|
32526
32885
|
JSON.stringify(
|
|
32527
32886
|
{
|
|
@@ -32532,8 +32891,8 @@ function registerScaffoldCommands(worlds) {
|
|
|
32532
32891
|
task: spec.task ?? null,
|
|
32533
32892
|
tools: spec.tools.map((t) => `${alias}.${t}`),
|
|
32534
32893
|
verifiers: (verifierNames(depDir) ?? []).map((v) => `${alias}/${v}`),
|
|
32535
|
-
file:
|
|
32536
|
-
next: `gateway worlds schema check ${
|
|
32894
|
+
file: path50.relative(process.cwd(), file) || file,
|
|
32895
|
+
next: `gateway worlds schema check ${path50.relative(process.cwd(), dir) || "."}`
|
|
32537
32896
|
},
|
|
32538
32897
|
null,
|
|
32539
32898
|
2
|
|
@@ -32564,7 +32923,7 @@ function registerScaffoldCommands(worlds) {
|
|
|
32564
32923
|
],
|
|
32565
32924
|
notes: "Verifiers are SQL files returning one number in 0..1; each becomes a key in `rewards` (`slack/state_present`\nfor a dependency's). Then `gateway worlds schema check <path>` lists the task, and\n`gateway worlds serve <path> --task <id>` opens a session on it.\nAn id that is already declared (benchmarks init pre-declares one graded by its placeholder verifier)\nis refused unless --replace, which swaps that block for this one.",
|
|
32566
32925
|
run: async (args, ctx) => {
|
|
32567
|
-
const dir =
|
|
32926
|
+
const dir = path50.resolve(args.positionals[0]);
|
|
32568
32927
|
const { file, toml } = readManifest2(dir);
|
|
32569
32928
|
const prompt = arg.str(args, "prompt");
|
|
32570
32929
|
if (prompt === void 0) throw new CliError("--prompt is required: what the agent is told");
|
|
@@ -32580,7 +32939,7 @@ function registerScaffoldCommands(worlds) {
|
|
|
32580
32939
|
const depVerifiers = {};
|
|
32581
32940
|
for (const alias of Object.keys(worlds2)) {
|
|
32582
32941
|
const rel = dependencyPath(toml, alias);
|
|
32583
|
-
if (rel !== void 0) depVerifiers[alias] = verifierNames(
|
|
32942
|
+
if (rel !== void 0) depVerifiers[alias] = verifierNames(path50.resolve(dir, rel));
|
|
32584
32943
|
}
|
|
32585
32944
|
const spec = {
|
|
32586
32945
|
id: args.positionals[1],
|
|
@@ -32594,7 +32953,7 @@ function registerScaffoldCommands(worlds) {
|
|
|
32594
32953
|
{ verifiers: verifierNames(dir), depVerifiers },
|
|
32595
32954
|
{ replace: arg.bool(args, "replace") }
|
|
32596
32955
|
);
|
|
32597
|
-
|
|
32956
|
+
fs65.writeFileSync(file, updated);
|
|
32598
32957
|
ctx.stdout(
|
|
32599
32958
|
JSON.stringify(
|
|
32600
32959
|
{
|
|
@@ -32604,11 +32963,11 @@ function registerScaffoldCommands(worlds) {
|
|
|
32604
32963
|
verifiers: spec.verifiers,
|
|
32605
32964
|
worlds: worlds2,
|
|
32606
32965
|
rewards: [...spec.verifiers, ...Object.entries(worlds2).flatMap(([a, names]) => names.map((n) => `${a}/${n}`))],
|
|
32607
|
-
file:
|
|
32966
|
+
file: path50.relative(process.cwd(), file) || file,
|
|
32608
32967
|
next: [
|
|
32609
|
-
`gateway worlds schema compile ${
|
|
32610
|
-
`gateway worlds schema check ${
|
|
32611
|
-
`gateway worlds serve ${
|
|
32968
|
+
`gateway worlds schema compile ${path50.relative(process.cwd(), dir) || "."} # a manifest edit invalidates the compiled contract`,
|
|
32969
|
+
`gateway worlds schema check ${path50.relative(process.cwd(), dir) || "."}`,
|
|
32970
|
+
`gateway worlds serve ${path50.relative(process.cwd(), dir) || "."} --task ${spec.id}`
|
|
32612
32971
|
]
|
|
32613
32972
|
},
|
|
32614
32973
|
null,
|
|
@@ -32659,9 +33018,9 @@ function registerScaffoldCommands(worlds) {
|
|
|
32659
33018
|
],
|
|
32660
33019
|
notes: "A schema world with no connector.toml yet gets one: [connector] slug from its [environment] name, a\nplaceholder base_url, then this route. That file is the world's API surface, served with its tools.\nExisting text is untouched; the block is appended. With --replace the block already declared under this\nname (and its [operations.api]) is removed first and the new one appended, every other byte kept.\n--entity must already be declared in schema/world.json (`gateway worlds schema entity add`). A create\nroute mints its entity's primary key (uuid, or int for an integer key) unless --body maps it or\n--generate names it, so a POST without an id is created rather than refused. --action handler\n--handler <fn> writes a 501 stub def <fn>(ctx, args, query, body) into api/handlers.py unless it is\ndefined there already. A new connector.toml starts with [auth] scheme = \"bearer\": the token a hosted\nsession hands the agent; `worlds serve` accepts the bearer --api-key pins (default `conform`). Then\n`gateway worlds connector validate <path>`.",
|
|
32661
33020
|
run: async (args, ctx) => {
|
|
32662
|
-
const dir =
|
|
32663
|
-
const file =
|
|
32664
|
-
const created = !
|
|
33021
|
+
const dir = path50.resolve(args.positionals[0]);
|
|
33022
|
+
const file = path50.join(dir, "connector.toml");
|
|
33023
|
+
const created = !fs65.existsSync(file);
|
|
32665
33024
|
const routePath = arg.str(args, "path");
|
|
32666
33025
|
if (routePath === void 0) throw new CliError("--path is required, e.g. --path /users");
|
|
32667
33026
|
const spec = {
|
|
@@ -32685,13 +33044,13 @@ function registerScaffoldCommands(worlds) {
|
|
|
32685
33044
|
};
|
|
32686
33045
|
const replace = arg.bool(args, "replace");
|
|
32687
33046
|
const handler = spec.api.action === "handler" && spec.api.handler ? new HandlerStub(dir, spec.api.handler) : void 0;
|
|
32688
|
-
const current = created ? connectorTomlSkeleton(dir) :
|
|
33047
|
+
const current = created ? connectorTomlSkeleton(dir) : fs65.readFileSync(file, "utf8");
|
|
32689
33048
|
const updated = addRoute(current, spec, declaredEntities(dir), {
|
|
32690
33049
|
replace,
|
|
32691
33050
|
handlerTools: declaredHandlerTools(dir),
|
|
32692
33051
|
entities: worldEntityShapes(dir)
|
|
32693
33052
|
});
|
|
32694
|
-
|
|
33053
|
+
fs65.writeFileSync(file, updated);
|
|
32695
33054
|
const written = handler?.ensure();
|
|
32696
33055
|
ctx.stdout(
|
|
32697
33056
|
JSON.stringify(
|
|
@@ -32704,7 +33063,7 @@ function registerScaffoldCommands(worlds) {
|
|
|
32704
33063
|
...replace ? { replaced: true } : {},
|
|
32705
33064
|
...created ? { created: true } : {},
|
|
32706
33065
|
...handler ? { handler: { file: HANDLERS_FILE, function: handler.name, written } } : {},
|
|
32707
|
-
file:
|
|
33066
|
+
file: path50.relative(process.cwd(), file) || file
|
|
32708
33067
|
},
|
|
32709
33068
|
null,
|
|
32710
33069
|
2
|
|
@@ -32738,20 +33097,6 @@ function registerRuntimeCommands(root) {
|
|
|
32738
33097
|
registerCallCommand(worlds);
|
|
32739
33098
|
}
|
|
32740
33099
|
|
|
32741
|
-
// src/cli/version.ts
|
|
32742
|
-
import * as fs65 from "fs";
|
|
32743
|
-
import * as path50 from "path";
|
|
32744
|
-
function cliVersion() {
|
|
32745
|
-
if (true) return "0.4.0";
|
|
32746
|
-
if (typeof __dirname !== "string") return "unknown";
|
|
32747
|
-
try {
|
|
32748
|
-
const pkg = JSON.parse(fs65.readFileSync(path50.resolve(__dirname, "../../package.json"), "utf8"));
|
|
32749
|
-
return pkg.version ?? "unknown";
|
|
32750
|
-
} catch {
|
|
32751
|
-
return "unknown";
|
|
32752
|
-
}
|
|
32753
|
-
}
|
|
32754
|
-
|
|
32755
33100
|
// src/cli/main.ts
|
|
32756
33101
|
init_transport();
|
|
32757
33102
|
function buildCli() {
|