@withgateway/sdk 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/cli.js +1497 -712
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1500 -715
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.js +34 -0
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +34 -0
- package/dist/files/index.mjs.map +1 -1
- package/dist/{index-DAb-FCMg.d.ts → index-CBqbB_0J.d.ts} +2 -12
- package/dist/{index-D6oi1TWE.d.mts → index-D-AMnAMa.d.mts} +2 -12
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +173 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +171 -50
- package/dist/index.mjs.map +1 -1
- package/dist/traces/index.js +34 -0
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +34 -0
- 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 +39 -20
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +39 -20
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/worlds/index.d.mts +66 -18
- package/dist/worlds/index.d.ts +66 -18
- package/dist/worlds/index.js +171 -50
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +171 -50
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +1 -1
- package/runtime/gatewaysdk/environment/schema/api.py +7 -8
- package/runtime/gatewaysdk/environment/schema/cast.py +31 -4
- package/runtime/gatewaysdk/environment/schema/platform.py +1 -7
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +3 -3
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +2 -2
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +6 -6
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +1 -1
- package/skills/connector-schema-authoring/SKILL.md +3 -3
- package/skills/connector-schema-authoring/connector-worlds.md +12 -5
- package/skills/connector-schema-authoring/world-schema.md +8 -0
- package/skills/world-data-ingestion/SKILL.md +2 -2
- package/skills/worlds-getting-started/SKILL.md +6 -6
- package/skills/worlds-getting-started/references/cli-mcp-map.md +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -118,24 +118,24 @@ function looksLikeFlag(token, known) {
|
|
|
118
118
|
const name = token.replace(/^--?/, "").split("=")[0];
|
|
119
119
|
return known.has(name);
|
|
120
120
|
}
|
|
121
|
-
function usageLine(
|
|
121
|
+
function usageLine(path49, spec) {
|
|
122
122
|
const pos = (spec.positionals ?? []).map(
|
|
123
123
|
(p) => p.variadic ? `<${p.name}...>` : p.optional ? `[${p.name}]` : `<${p.name}>`
|
|
124
124
|
).join(" ");
|
|
125
|
-
return `${
|
|
125
|
+
return `${path49.join(" ")} ${pos}`.trim();
|
|
126
126
|
}
|
|
127
|
-
function helpFor(
|
|
127
|
+
function helpFor(path49, node) {
|
|
128
128
|
if (node instanceof CommandGroup) {
|
|
129
|
-
const lines2 = [`${
|
|
129
|
+
const lines2 = [`${path49.join(" ")} \u2014 ${node.help}`, ""];
|
|
130
130
|
for (const [name, g] of node.groups)
|
|
131
131
|
lines2.push(` ${name.padEnd(16)} ${g.help}`);
|
|
132
132
|
for (const [name, c] of node.commands)
|
|
133
133
|
lines2.push(` ${name.padEnd(16)} ${c.help}`);
|
|
134
134
|
if (node.notes) lines2.push("", node.notes);
|
|
135
|
-
lines2.push("", `Run '${
|
|
135
|
+
lines2.push("", `Run '${path49.join(" ")} <command> --help' for details.`);
|
|
136
136
|
return lines2.join("\n");
|
|
137
137
|
}
|
|
138
|
-
const lines = [usageLine(
|
|
138
|
+
const lines = [usageLine(path49, node), "", ` ${node.help}`];
|
|
139
139
|
const pos = node.positionals ?? [];
|
|
140
140
|
if (pos.length) {
|
|
141
141
|
lines.push("", "Arguments:");
|
|
@@ -160,12 +160,12 @@ function helpFor(path44, node) {
|
|
|
160
160
|
}
|
|
161
161
|
async function dispatch(root, argv, ctx) {
|
|
162
162
|
let node = root;
|
|
163
|
-
const
|
|
163
|
+
const path49 = [root.name];
|
|
164
164
|
let i = 0;
|
|
165
165
|
while (i < argv.length) {
|
|
166
166
|
const token = argv[i];
|
|
167
167
|
if (token === "--help" || token === "-h") {
|
|
168
|
-
ctx.stdout(helpFor(
|
|
168
|
+
ctx.stdout(helpFor(path49, node));
|
|
169
169
|
return 0;
|
|
170
170
|
}
|
|
171
171
|
if (node === root && root.version !== void 0 && (token === "--version" || token === "-V")) {
|
|
@@ -175,7 +175,7 @@ async function dispatch(root, argv, ctx) {
|
|
|
175
175
|
const group = node.groups.get(token);
|
|
176
176
|
if (group) {
|
|
177
177
|
node = group;
|
|
178
|
-
|
|
178
|
+
path49.push(token);
|
|
179
179
|
i++;
|
|
180
180
|
continue;
|
|
181
181
|
}
|
|
@@ -183,7 +183,7 @@ async function dispatch(root, argv, ctx) {
|
|
|
183
183
|
if (command2) {
|
|
184
184
|
const rest = argv.slice(i + 1);
|
|
185
185
|
if (rest.includes("--help") || rest.includes("-h")) {
|
|
186
|
-
ctx.stdout(helpFor([...
|
|
186
|
+
ctx.stdout(helpFor([...path49, token], command2));
|
|
187
187
|
return 0;
|
|
188
188
|
}
|
|
189
189
|
try {
|
|
@@ -200,13 +200,13 @@ async function dispatch(root, argv, ctx) {
|
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
ctx.stderr(
|
|
203
|
-
`Unknown command '${token}' under '${
|
|
203
|
+
`Unknown command '${token}' under '${path49.join(" ")}'.
|
|
204
204
|
|
|
205
|
-
${helpFor(
|
|
205
|
+
${helpFor(path49, node)}`
|
|
206
206
|
);
|
|
207
207
|
return 2;
|
|
208
208
|
}
|
|
209
|
-
ctx.stdout(helpFor(
|
|
209
|
+
ctx.stdout(helpFor(path49, node));
|
|
210
210
|
return node === root ? 0 : 2;
|
|
211
211
|
}
|
|
212
212
|
var CommandGroup, JSON_FLAG, JSON_OUTPUT_FLAG, CliError, arg;
|
|
@@ -556,9 +556,9 @@ function surfaceKinds(s) {
|
|
|
556
556
|
if (s.browser) kinds.push("browser");
|
|
557
557
|
return kinds;
|
|
558
558
|
}
|
|
559
|
-
function uiUrl(ui,
|
|
559
|
+
function uiUrl(ui, path49) {
|
|
560
560
|
const base = ui.url.replace(/\/+$/, "");
|
|
561
|
-
const rel =
|
|
561
|
+
const rel = path49.startsWith("/") ? path49 : `/${path49}`;
|
|
562
562
|
if (!ui.token) return base + rel;
|
|
563
563
|
const [beforeHash, hash] = splitHash(rel);
|
|
564
564
|
const joiner = beforeHash.includes("?") ? "&" : "?";
|
|
@@ -752,8 +752,8 @@ var init_browser = __esm({
|
|
|
752
752
|
}
|
|
753
753
|
resolveBase() {
|
|
754
754
|
if (this.base === null) {
|
|
755
|
-
const
|
|
756
|
-
this.base =
|
|
755
|
+
const resolve32 = this.opts.resumeFrom ?? (async () => 0);
|
|
756
|
+
this.base = resolve32().then((n) => {
|
|
757
757
|
if (!Number.isInteger(n) || n < 0)
|
|
758
758
|
throw new Error(
|
|
759
759
|
`browser event base seq must be a non-negative integer, got ${String(n)}`
|
|
@@ -1453,13 +1453,13 @@ var init_screen = __esm({
|
|
|
1453
1453
|
});
|
|
1454
1454
|
}
|
|
1455
1455
|
async drag(action) {
|
|
1456
|
-
const
|
|
1457
|
-
if (
|
|
1456
|
+
const path49 = action.args.path ?? [];
|
|
1457
|
+
if (path49.length < 2) throw new Error("a drag needs at least two points");
|
|
1458
1458
|
return this.held(action.args.modifiers ?? [], async () => {
|
|
1459
|
-
await this.moveTo(
|
|
1459
|
+
await this.moveTo(path49[0]);
|
|
1460
1460
|
await this.page.mouse.down({ button: "left" });
|
|
1461
1461
|
try {
|
|
1462
|
-
for (const point2 of
|
|
1462
|
+
for (const point2 of path49.slice(1)) await this.moveTo(point2, DRAG_STEPS);
|
|
1463
1463
|
} finally {
|
|
1464
1464
|
await this.page.mouse.up({ button: "left" });
|
|
1465
1465
|
}
|
|
@@ -2478,9 +2478,9 @@ function getCurrentWorldSessionId() {
|
|
|
2478
2478
|
return currentWorldSessionStorage.getStore();
|
|
2479
2479
|
}
|
|
2480
2480
|
function runIn(storage, value, fn) {
|
|
2481
|
-
return new Promise((
|
|
2481
|
+
return new Promise((resolve32, reject) => {
|
|
2482
2482
|
storage.run(value, () => {
|
|
2483
|
-
Promise.resolve().then(fn).then(
|
|
2483
|
+
Promise.resolve().then(fn).then(resolve32, reject);
|
|
2484
2484
|
});
|
|
2485
2485
|
});
|
|
2486
2486
|
}
|
|
@@ -2898,18 +2898,18 @@ var init_session2 = __esm({
|
|
|
2898
2898
|
}
|
|
2899
2899
|
/** The reporter `browser()` uses; exposed for a page you drive yourself. */
|
|
2900
2900
|
browserRecorder(agentId) {
|
|
2901
|
-
const
|
|
2901
|
+
const path49 = `/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/browser-events`;
|
|
2902
2902
|
const id = agentId ?? process.env.GATEWAY_AGENT_ID ?? `agent-${randomUUID().replace(/-/g, "").slice(0, 8)}`;
|
|
2903
2903
|
return new BrowserActionRecorder(
|
|
2904
2904
|
async (events) => {
|
|
2905
|
-
await apiRequest(this.options, "POST",
|
|
2905
|
+
await apiRequest(this.options, "POST", path49, { events });
|
|
2906
2906
|
},
|
|
2907
2907
|
id,
|
|
2908
2908
|
{
|
|
2909
2909
|
// Continue this agent's timeline where the platform has it, so the
|
|
2910
2910
|
// same id reopened later never re-numbers from zero.
|
|
2911
2911
|
resumeFrom: async () => {
|
|
2912
|
-
const summary2 = await apiRequest(this.options, "GET",
|
|
2912
|
+
const summary2 = await apiRequest(this.options, "GET", path49);
|
|
2913
2913
|
return summary2.agents.find((a) => a.agentId === id)?.nextSeq ?? 0;
|
|
2914
2914
|
}
|
|
2915
2915
|
}
|
|
@@ -3295,6 +3295,28 @@ var init_tasks = __esm({
|
|
|
3295
3295
|
}
|
|
3296
3296
|
});
|
|
3297
3297
|
|
|
3298
|
+
// src/worlds/surfaceDescriptor.ts
|
|
3299
|
+
function surfaceDescriptor(s) {
|
|
3300
|
+
return {
|
|
3301
|
+
surfaces: surfaceKinds(s),
|
|
3302
|
+
...s.api ? { api: { url: s.api.url, ...s.api.token ? { token: s.api.token } : {} } } : {},
|
|
3303
|
+
...s.ui ? { ui: { url: s.ui.url, entry: uiEntryUrl(s.ui), apiPath: s.ui.apiPath ?? null } } : {},
|
|
3304
|
+
...s.browser ? {
|
|
3305
|
+
browser: {
|
|
3306
|
+
wsUrl: s.browser.wsUrl,
|
|
3307
|
+
viewport: s.browser.viewport,
|
|
3308
|
+
...s.browser.tier ? { tier: s.browser.tier } : {}
|
|
3309
|
+
}
|
|
3310
|
+
} : {}
|
|
3311
|
+
};
|
|
3312
|
+
}
|
|
3313
|
+
var init_surfaceDescriptor = __esm({
|
|
3314
|
+
"src/worlds/surfaceDescriptor.ts"() {
|
|
3315
|
+
"use strict";
|
|
3316
|
+
init_browser();
|
|
3317
|
+
}
|
|
3318
|
+
});
|
|
3319
|
+
|
|
3298
3320
|
// src/worlds/taskSessions.ts
|
|
3299
3321
|
function aggregateTaskGrade(worlds) {
|
|
3300
3322
|
const rewards = {};
|
|
@@ -3445,6 +3467,7 @@ var init_taskSessions = __esm({
|
|
|
3445
3467
|
"use strict";
|
|
3446
3468
|
init_worlds();
|
|
3447
3469
|
init_browser();
|
|
3470
|
+
init_surfaceDescriptor();
|
|
3448
3471
|
init_session2();
|
|
3449
3472
|
TASK_SESSIONS = "/api/public/world-task-sessions";
|
|
3450
3473
|
VERIFIER_REWARD_PREFIX = "x.";
|
|
@@ -3456,18 +3479,7 @@ var init_taskSessions = __esm({
|
|
|
3456
3479
|
sessionId: state2.sessionId,
|
|
3457
3480
|
ready: state2.ready,
|
|
3458
3481
|
state: state2.state,
|
|
3459
|
-
|
|
3460
|
-
...s.api ? {
|
|
3461
|
-
api: { url: s.api.url, ...s.api.token ? { token: s.api.token } : {} }
|
|
3462
|
-
} : {},
|
|
3463
|
-
...s.ui ? {
|
|
3464
|
-
ui: {
|
|
3465
|
-
url: s.ui.url,
|
|
3466
|
-
entry: uiEntryUrl(s.ui),
|
|
3467
|
-
apiPath: s.ui.apiPath ?? null
|
|
3468
|
-
}
|
|
3469
|
-
} : {},
|
|
3470
|
-
...s.browser ? { browser: { wsUrl: s.browser.wsUrl, viewport: s.browser.viewport } } : {}
|
|
3482
|
+
...surfaceDescriptor(s)
|
|
3471
3483
|
});
|
|
3472
3484
|
TaskSessions = class {
|
|
3473
3485
|
constructor(taskId, taskVersion, name, instruction, sessions, worlds, hash = null) {
|
|
@@ -3646,6 +3658,49 @@ var init_evals = __esm({
|
|
|
3646
3658
|
}
|
|
3647
3659
|
});
|
|
3648
3660
|
|
|
3661
|
+
// src/tracing/prerequisites.ts
|
|
3662
|
+
function getEnv(key2) {
|
|
3663
|
+
const value = process.env[key2];
|
|
3664
|
+
return value ? value : void 0;
|
|
3665
|
+
}
|
|
3666
|
+
function isGatewayConfigured() {
|
|
3667
|
+
return !!(getEnv(GATEWAY_ENV.HOST) && getEnv(GATEWAY_ENV.PUBLIC_KEY) && getEnv(GATEWAY_ENV.SECRET_KEY));
|
|
3668
|
+
}
|
|
3669
|
+
var GATEWAY_ENV, OPENTELEMETRY_PEERS, MODULE_NOT_FOUND, OpenTelemetryMissing;
|
|
3670
|
+
var init_prerequisites = __esm({
|
|
3671
|
+
"src/tracing/prerequisites.ts"() {
|
|
3672
|
+
"use strict";
|
|
3673
|
+
GATEWAY_ENV = {
|
|
3674
|
+
HOST: "GATEWAY_HOST",
|
|
3675
|
+
PUBLIC_KEY: "GATEWAY_PUBLIC_KEY",
|
|
3676
|
+
SECRET_KEY: "GATEWAY_SECRET_KEY",
|
|
3677
|
+
ENDPOINT: "GATEWAY_OTLP_ENDPOINT"
|
|
3678
|
+
};
|
|
3679
|
+
OPENTELEMETRY_PEERS = [
|
|
3680
|
+
"@opentelemetry/api",
|
|
3681
|
+
"@opentelemetry/exporter-trace-otlp-http",
|
|
3682
|
+
"@opentelemetry/resources",
|
|
3683
|
+
"@opentelemetry/sdk-trace-base",
|
|
3684
|
+
"@opentelemetry/sdk-trace-node"
|
|
3685
|
+
];
|
|
3686
|
+
MODULE_NOT_FOUND = /* @__PURE__ */ new Set(["MODULE_NOT_FOUND", "ERR_MODULE_NOT_FOUND"]);
|
|
3687
|
+
OpenTelemetryMissing = class _OpenTelemetryMissing extends Error {
|
|
3688
|
+
constructor() {
|
|
3689
|
+
super(
|
|
3690
|
+
`OpenTelemetry packages not found. Install them with:
|
|
3691
|
+
npm install ${OPENTELEMETRY_PEERS.join(" ")}`
|
|
3692
|
+
);
|
|
3693
|
+
this.name = "OpenTelemetryMissing";
|
|
3694
|
+
}
|
|
3695
|
+
static explains(error) {
|
|
3696
|
+
if (error instanceof _OpenTelemetryMissing) return true;
|
|
3697
|
+
const { code, message } = error ?? {};
|
|
3698
|
+
return MODULE_NOT_FOUND.has(String(code)) && String(message).includes("@opentelemetry/");
|
|
3699
|
+
}
|
|
3700
|
+
};
|
|
3701
|
+
}
|
|
3702
|
+
});
|
|
3703
|
+
|
|
3649
3704
|
// src/users/index.ts
|
|
3650
3705
|
function parseEvent(payload) {
|
|
3651
3706
|
return {
|
|
@@ -3808,10 +3863,10 @@ var init_users = __esm({
|
|
|
3808
3863
|
totalItems: Number(meta.totalItems ?? rows.length)
|
|
3809
3864
|
};
|
|
3810
3865
|
}
|
|
3811
|
-
async requestJson(method,
|
|
3866
|
+
async requestJson(method, path49, payload) {
|
|
3812
3867
|
let response;
|
|
3813
3868
|
try {
|
|
3814
|
-
response = await fetch(`${this.host}${
|
|
3869
|
+
response = await fetch(`${this.host}${path49}`, {
|
|
3815
3870
|
method,
|
|
3816
3871
|
headers: {
|
|
3817
3872
|
Authorization: this.authHeader(),
|
|
@@ -3822,17 +3877,17 @@ var init_users = __esm({
|
|
|
3822
3877
|
});
|
|
3823
3878
|
} catch (error) {
|
|
3824
3879
|
throw new UserProfileError(
|
|
3825
|
-
`${method} ${
|
|
3880
|
+
`${method} ${path49} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
3826
3881
|
{ cause: error }
|
|
3827
3882
|
);
|
|
3828
3883
|
}
|
|
3829
3884
|
const text2 = await response.text();
|
|
3830
3885
|
if (!response.ok) {
|
|
3831
3886
|
throw new UserProfileError(
|
|
3832
|
-
`${method} ${
|
|
3887
|
+
`${method} ${path49} failed (${response.status}): ${text2.slice(0, 500)}`
|
|
3833
3888
|
);
|
|
3834
3889
|
}
|
|
3835
|
-
this.log("%s %s -> %s", method,
|
|
3890
|
+
this.log("%s %s -> %s", method, path49, response.status);
|
|
3836
3891
|
return safeJson(text2);
|
|
3837
3892
|
}
|
|
3838
3893
|
authHeader() {
|
|
@@ -4128,14 +4183,14 @@ function coerceSignalValue(value) {
|
|
|
4128
4183
|
return { numericValue: value, inferredType: "NUMERIC" };
|
|
4129
4184
|
}
|
|
4130
4185
|
async function success(name, value = true, options = {}) {
|
|
4131
|
-
let
|
|
4186
|
+
let client5;
|
|
4132
4187
|
try {
|
|
4133
|
-
|
|
4188
|
+
client5 = ScoresClient.fromEnv();
|
|
4134
4189
|
} catch (error) {
|
|
4135
4190
|
console.warn(`[gateway.scores] success '${name}' skipped`, error);
|
|
4136
4191
|
return;
|
|
4137
4192
|
}
|
|
4138
|
-
await
|
|
4193
|
+
await client5.success(name, value, options);
|
|
4139
4194
|
}
|
|
4140
4195
|
var SUCCESS_SIGNAL_KEY, SUCCESS_METRIC_NAME_KEY, AGENT_ID_KEY, ScoreError, ScoresClient, scores;
|
|
4141
4196
|
var init_scores = __esm({
|
|
@@ -4277,10 +4332,10 @@ var init_scores = __esm({
|
|
|
4277
4332
|
metadata: signalMetadata
|
|
4278
4333
|
});
|
|
4279
4334
|
}
|
|
4280
|
-
async request(method,
|
|
4335
|
+
async request(method, path49, payload) {
|
|
4281
4336
|
let response;
|
|
4282
4337
|
try {
|
|
4283
|
-
response = await fetch(`${this.host}${
|
|
4338
|
+
response = await fetch(`${this.host}${path49}`, {
|
|
4284
4339
|
method,
|
|
4285
4340
|
headers: {
|
|
4286
4341
|
Authorization: this.authHeader(),
|
|
@@ -4291,17 +4346,17 @@ var init_scores = __esm({
|
|
|
4291
4346
|
});
|
|
4292
4347
|
} catch (error) {
|
|
4293
4348
|
throw new ScoreError(
|
|
4294
|
-
`${method} ${
|
|
4349
|
+
`${method} ${path49} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
4295
4350
|
{ cause: error }
|
|
4296
4351
|
);
|
|
4297
4352
|
}
|
|
4298
4353
|
const text2 = await response.text();
|
|
4299
4354
|
if (!response.ok) {
|
|
4300
4355
|
throw new ScoreError(
|
|
4301
|
-
`${method} ${
|
|
4356
|
+
`${method} ${path49} failed (${response.status}): ${text2.slice(0, 500)}`
|
|
4302
4357
|
);
|
|
4303
4358
|
}
|
|
4304
|
-
this.log("%s %s -> %s", method,
|
|
4359
|
+
this.log("%s %s -> %s", method, path49, response.status);
|
|
4305
4360
|
}
|
|
4306
4361
|
authHeader() {
|
|
4307
4362
|
return `Basic ${Buffer.from(`${this.publicKey}:${this.secretKey}`).toString(
|
|
@@ -4329,7 +4384,7 @@ var require_package = __commonJS({
|
|
|
4329
4384
|
"package.json"(exports, module) {
|
|
4330
4385
|
module.exports = {
|
|
4331
4386
|
name: "@withgateway/sdk",
|
|
4332
|
-
version: "0.3.
|
|
4387
|
+
version: "0.3.1",
|
|
4333
4388
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
4334
4389
|
main: "./dist/index.js",
|
|
4335
4390
|
module: "./dist/index.mjs",
|
|
@@ -4738,10 +4793,6 @@ __export(init_exports, {
|
|
|
4738
4793
|
isInitialized: () => isInitialized,
|
|
4739
4794
|
shutdown: () => shutdown
|
|
4740
4795
|
});
|
|
4741
|
-
function getEnv(key2) {
|
|
4742
|
-
const value = process.env[key2];
|
|
4743
|
-
return value ? value : void 0;
|
|
4744
|
-
}
|
|
4745
4796
|
function log(message, ...args) {
|
|
4746
4797
|
if (state.debug) {
|
|
4747
4798
|
console.log(`[gatewaysdk.tracing] ${message}`, ...args);
|
|
@@ -4751,10 +4802,10 @@ function warn(message, ...args) {
|
|
|
4751
4802
|
console.warn(`[gatewaysdk.tracing] ${message}`, ...args);
|
|
4752
4803
|
}
|
|
4753
4804
|
function buildProvider(config, logFn) {
|
|
4754
|
-
const host = config.host ?? getEnv(
|
|
4755
|
-
const publicKey = config.publicKey ?? getEnv(
|
|
4756
|
-
const secretKey = config.secretKey ?? getEnv(
|
|
4757
|
-
const endpoint = config.endpoint ?? getEnv(
|
|
4805
|
+
const host = config.host ?? getEnv(GATEWAY_ENV.HOST);
|
|
4806
|
+
const publicKey = config.publicKey ?? getEnv(GATEWAY_ENV.PUBLIC_KEY);
|
|
4807
|
+
const secretKey = config.secretKey ?? getEnv(GATEWAY_ENV.SECRET_KEY);
|
|
4808
|
+
const endpoint = config.endpoint ?? getEnv(GATEWAY_ENV.ENDPOINT) ?? (host ? `${host.replace(/\/$/, "")}${DEFAULT_OTLP_PATH}` : void 0);
|
|
4758
4809
|
const missing = [];
|
|
4759
4810
|
if (!host) missing.push("host (or GATEWAY_HOST env var)");
|
|
4760
4811
|
if (!publicKey) missing.push("publicKey (or GATEWAY_PUBLIC_KEY env var)");
|
|
@@ -4791,9 +4842,7 @@ function buildProvider(config, logFn) {
|
|
|
4791
4842
|
ATTR_SERVICE_NAME = "service.name";
|
|
4792
4843
|
}
|
|
4793
4844
|
} catch {
|
|
4794
|
-
throw new
|
|
4795
|
-
"OpenTelemetry packages not found. Install them with:\nnpm install @opentelemetry/sdk-trace-node @opentelemetry/sdk-trace-base @opentelemetry/exporter-trace-otlp-http @opentelemetry/resources"
|
|
4796
|
-
);
|
|
4845
|
+
throw new OpenTelemetryMissing();
|
|
4797
4846
|
}
|
|
4798
4847
|
const resourceAttrs = {
|
|
4799
4848
|
[ATTR_SERVICE_NAME]: config.serviceName ?? "gatewaysdk-tracing"
|
|
@@ -4999,13 +5048,7 @@ async function shutdown() {
|
|
|
4999
5048
|
function isInitialized() {
|
|
5000
5049
|
return state.initialized;
|
|
5001
5050
|
}
|
|
5002
|
-
|
|
5003
|
-
const host = getEnv(ENV_VARS.HOST);
|
|
5004
|
-
const publicKey = getEnv(ENV_VARS.PUBLIC_KEY);
|
|
5005
|
-
const secretKey = getEnv(ENV_VARS.SECRET_KEY);
|
|
5006
|
-
return !!(host && publicKey && secretKey);
|
|
5007
|
-
}
|
|
5008
|
-
var ENV_VARS, DEFAULT_OTLP_PATH, state;
|
|
5051
|
+
var DEFAULT_OTLP_PATH, state;
|
|
5009
5052
|
var init_init = __esm({
|
|
5010
5053
|
"src/tracing/init.ts"() {
|
|
5011
5054
|
"use strict";
|
|
@@ -5014,12 +5057,8 @@ var init_init = __esm({
|
|
|
5014
5057
|
init_session();
|
|
5015
5058
|
init_scores();
|
|
5016
5059
|
init_build();
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
PUBLIC_KEY: "GATEWAY_PUBLIC_KEY",
|
|
5020
|
-
SECRET_KEY: "GATEWAY_SECRET_KEY",
|
|
5021
|
-
ENDPOINT: "GATEWAY_OTLP_ENDPOINT"
|
|
5022
|
-
};
|
|
5060
|
+
init_prerequisites();
|
|
5061
|
+
init_prerequisites();
|
|
5023
5062
|
DEFAULT_OTLP_PATH = "/api/public/otel/v1/traces";
|
|
5024
5063
|
state = {
|
|
5025
5064
|
initialized: false,
|
|
@@ -5028,6 +5067,45 @@ var init_init = __esm({
|
|
|
5028
5067
|
}
|
|
5029
5068
|
});
|
|
5030
5069
|
|
|
5070
|
+
// src/worlds/taskTracing.ts
|
|
5071
|
+
var TaskTracing;
|
|
5072
|
+
var init_taskTracing = __esm({
|
|
5073
|
+
"src/worlds/taskTracing.ts"() {
|
|
5074
|
+
"use strict";
|
|
5075
|
+
init_prerequisites();
|
|
5076
|
+
TaskTracing = class _TaskTracing {
|
|
5077
|
+
constructor(load = () => Promise.resolve().then(() => (init_init(), init_exports))) {
|
|
5078
|
+
this.load = load;
|
|
5079
|
+
}
|
|
5080
|
+
load;
|
|
5081
|
+
static warned = false;
|
|
5082
|
+
async start(requested) {
|
|
5083
|
+
if (!requested || !isGatewayConfigured()) return false;
|
|
5084
|
+
try {
|
|
5085
|
+
(await this.load()).init();
|
|
5086
|
+
return true;
|
|
5087
|
+
} catch (error) {
|
|
5088
|
+
_TaskTracing.warnOnce(error);
|
|
5089
|
+
return false;
|
|
5090
|
+
}
|
|
5091
|
+
}
|
|
5092
|
+
static warnOnce(error) {
|
|
5093
|
+
if (_TaskTracing.warned) return;
|
|
5094
|
+
_TaskTracing.warned = true;
|
|
5095
|
+
console.warn(
|
|
5096
|
+
`[gatewaysdk.tracing] Task runs in this process are not traced. ${_TaskTracing.reason(error)}
|
|
5097
|
+
Pass --no-trace (trace: false) to run untraced without this warning.`
|
|
5098
|
+
);
|
|
5099
|
+
}
|
|
5100
|
+
static reason(error) {
|
|
5101
|
+
if (OpenTelemetryMissing.explains(error))
|
|
5102
|
+
return new OpenTelemetryMissing().message;
|
|
5103
|
+
return error instanceof Error ? error.message : String(error);
|
|
5104
|
+
}
|
|
5105
|
+
};
|
|
5106
|
+
}
|
|
5107
|
+
});
|
|
5108
|
+
|
|
5031
5109
|
// src/worlds/taskRun.ts
|
|
5032
5110
|
import { randomBytes } from "crypto";
|
|
5033
5111
|
import * as fs from "fs";
|
|
@@ -5143,18 +5221,7 @@ async function runTask(ref, agent, opts) {
|
|
|
5143
5221
|
const started = Date.now();
|
|
5144
5222
|
try {
|
|
5145
5223
|
await live.ready();
|
|
5146
|
-
|
|
5147
|
-
if (opts.trace !== false) {
|
|
5148
|
-
try {
|
|
5149
|
-
const { isGatewayConfigured: isGatewayConfigured2, init: init2 } = await Promise.resolve().then(() => (init_init(), init_exports));
|
|
5150
|
-
if (isGatewayConfigured2()) {
|
|
5151
|
-
init2();
|
|
5152
|
-
traced = true;
|
|
5153
|
-
}
|
|
5154
|
-
} catch {
|
|
5155
|
-
traced = false;
|
|
5156
|
-
}
|
|
5157
|
-
}
|
|
5224
|
+
const traced = await new TaskTracing().start(opts.trace !== false);
|
|
5158
5225
|
const taskRun = new TaskRun(
|
|
5159
5226
|
runId,
|
|
5160
5227
|
live.instruction ?? "",
|
|
@@ -5242,6 +5309,7 @@ var init_taskRun = __esm({
|
|
|
5242
5309
|
init_evals();
|
|
5243
5310
|
init_session2();
|
|
5244
5311
|
init_taskSessions();
|
|
5312
|
+
init_taskTracing();
|
|
5245
5313
|
TaskRun = class {
|
|
5246
5314
|
constructor(runId, instruction, model, sessions, manifest) {
|
|
5247
5315
|
this.runId = runId;
|
|
@@ -5340,9 +5408,9 @@ var init_checkoutProvenance = __esm({
|
|
|
5340
5408
|
static withoutCredentials(url) {
|
|
5341
5409
|
return url.replace(/^([a-z][a-z0-9+.-]*:\/\/)[^@/]+@/i, "$1");
|
|
5342
5410
|
}
|
|
5343
|
-
withPr(
|
|
5411
|
+
withPr(checkout2) {
|
|
5344
5412
|
const pr = this.pullRequest();
|
|
5345
|
-
return pr ? { ...
|
|
5413
|
+
return pr ? { ...checkout2, pr } : checkout2;
|
|
5346
5414
|
}
|
|
5347
5415
|
pullRequest() {
|
|
5348
5416
|
const url = this.env.GATEWAY_PR_URL;
|
|
@@ -5445,6 +5513,52 @@ var init_setRun = __esm({
|
|
|
5445
5513
|
}
|
|
5446
5514
|
});
|
|
5447
5515
|
|
|
5516
|
+
// src/worlds/requestLog.ts
|
|
5517
|
+
var WorldRequestLog;
|
|
5518
|
+
var init_requestLog = __esm({
|
|
5519
|
+
"src/worlds/requestLog.ts"() {
|
|
5520
|
+
"use strict";
|
|
5521
|
+
WorldRequestLog = class _WorldRequestLog {
|
|
5522
|
+
constructor(requests) {
|
|
5523
|
+
this.requests = requests;
|
|
5524
|
+
}
|
|
5525
|
+
requests;
|
|
5526
|
+
static async read(session) {
|
|
5527
|
+
const state2 = await session.state();
|
|
5528
|
+
const calls = state2?.calls;
|
|
5529
|
+
if (!Array.isArray(calls)) return null;
|
|
5530
|
+
return new _WorldRequestLog(calls.filter((c) => typeof c === "object" && c !== null));
|
|
5531
|
+
}
|
|
5532
|
+
/** How many older requests the world no longer keeps (its log is bounded): the gap
|
|
5533
|
+
* before the first entry it still holds. */
|
|
5534
|
+
get dropped() {
|
|
5535
|
+
const first = Number(this.requests[0]?.seq) || 1;
|
|
5536
|
+
return Math.max(0, first - 1);
|
|
5537
|
+
}
|
|
5538
|
+
/** Each request in the shape of a ledger line, `kind: "request"`, so one JSONL
|
|
5539
|
+
* file holds both. */
|
|
5540
|
+
asCalls() {
|
|
5541
|
+
return this.requests.map((r) => ({
|
|
5542
|
+
seq: Number(r.seq) || 0,
|
|
5543
|
+
kind: "request",
|
|
5544
|
+
tool: r.operation ?? null,
|
|
5545
|
+
args: {
|
|
5546
|
+
method: r.method ?? null,
|
|
5547
|
+
path: r.path ?? null,
|
|
5548
|
+
args: r.args ?? null,
|
|
5549
|
+
query: r.query ?? null,
|
|
5550
|
+
body: r.body ?? null,
|
|
5551
|
+
via: r.via ?? null
|
|
5552
|
+
},
|
|
5553
|
+
result: { status: r.status ?? null, rows: r.rows ?? null, found: r.found ?? null },
|
|
5554
|
+
error: null,
|
|
5555
|
+
completedAt: r.at ?? null
|
|
5556
|
+
}));
|
|
5557
|
+
}
|
|
5558
|
+
};
|
|
5559
|
+
}
|
|
5560
|
+
});
|
|
5561
|
+
|
|
5448
5562
|
// src/worlds/checkoutTarget.ts
|
|
5449
5563
|
import * as fs2 from "fs";
|
|
5450
5564
|
import * as path2 from "path";
|
|
@@ -6061,7 +6175,7 @@ async function push(dir, opts = {}) {
|
|
|
6061
6175
|
...opts.tags !== void 0 ? { tags: opts.tags } : {},
|
|
6062
6176
|
...opts.visibility ? { visibility: opts.visibility } : {}
|
|
6063
6177
|
};
|
|
6064
|
-
const
|
|
6178
|
+
const resolve32 = await apiRequest(
|
|
6065
6179
|
options,
|
|
6066
6180
|
"POST",
|
|
6067
6181
|
"/api/public/benchmark-containers/resolve",
|
|
@@ -6070,7 +6184,7 @@ async function push(dir, opts = {}) {
|
|
|
6070
6184
|
const tarball = buildSourceTarball(dir);
|
|
6071
6185
|
const bundleSha256 = sha256b64(tarball);
|
|
6072
6186
|
const version = await apiRequest(options, "POST", "/api/public/benchmark-containers/versions", {
|
|
6073
|
-
containerId:
|
|
6187
|
+
containerId: resolve32.containerId,
|
|
6074
6188
|
contentHash,
|
|
6075
6189
|
bundleSha256,
|
|
6076
6190
|
bundleSizeBytes: tarball.length,
|
|
@@ -6109,7 +6223,7 @@ async function push(dir, opts = {}) {
|
|
|
6109
6223
|
baseFiles: snapshotTreeHashes(dir)
|
|
6110
6224
|
});
|
|
6111
6225
|
return {
|
|
6112
|
-
containerId:
|
|
6226
|
+
containerId: resolve32.containerId,
|
|
6113
6227
|
slug,
|
|
6114
6228
|
versionId: version.versionId,
|
|
6115
6229
|
contentHash,
|
|
@@ -6134,7 +6248,7 @@ async function pull(slugRef, target, options = {}, opts = {}) {
|
|
|
6134
6248
|
const at = slugRef.indexOf("@");
|
|
6135
6249
|
const slug = at === -1 ? slugRef : slugRef.slice(0, at);
|
|
6136
6250
|
const ref = at === -1 ? "latest" : slugRef.slice(at + 1);
|
|
6137
|
-
const
|
|
6251
|
+
const landing2 = CheckoutTarget.resolve(slug, target, {
|
|
6138
6252
|
cwd: process.cwd(),
|
|
6139
6253
|
force: opts.force ?? false,
|
|
6140
6254
|
state: localTreeState
|
|
@@ -6154,9 +6268,9 @@ async function pull(slugRef, target, options = {}, opts = {}) {
|
|
|
6154
6268
|
`bundle integrity check failed for ${slug}@${ref}: downloaded sha256 != recorded bundleSha256`
|
|
6155
6269
|
);
|
|
6156
6270
|
}
|
|
6157
|
-
const dir =
|
|
6271
|
+
const dir = landing2.dir;
|
|
6158
6272
|
fs5.mkdirSync(dir, { recursive: true });
|
|
6159
|
-
|
|
6273
|
+
landing2.clear();
|
|
6160
6274
|
const files = extractBundle(bundle, dir);
|
|
6161
6275
|
writeLocalMeta(dir, {
|
|
6162
6276
|
slug,
|
|
@@ -6449,7 +6563,7 @@ function rebaseConflicts(error) {
|
|
|
6449
6563
|
}
|
|
6450
6564
|
const conflicts = body?.conflicts;
|
|
6451
6565
|
if (!Array.isArray(conflicts)) return null;
|
|
6452
|
-
return conflicts.filter(isConflictPath).map(({ path:
|
|
6566
|
+
return conflicts.filter(isConflictPath).map(({ path: path49, reason }) => ({ path: path49, reason }));
|
|
6453
6567
|
}
|
|
6454
6568
|
function isConflictPath(value) {
|
|
6455
6569
|
const entry = value;
|
|
@@ -6489,8 +6603,8 @@ var init_sandbox = __esm({
|
|
|
6489
6603
|
this.options = options;
|
|
6490
6604
|
}
|
|
6491
6605
|
options;
|
|
6492
|
-
request(method,
|
|
6493
|
-
return apiRequest(this.options, method,
|
|
6606
|
+
request(method, path49, body) {
|
|
6607
|
+
return apiRequest(this.options, method, path49, body, {
|
|
6494
6608
|
timeoutMs: SANDBOX_REQUEST_TIMEOUT_MS
|
|
6495
6609
|
});
|
|
6496
6610
|
}
|
|
@@ -7078,6 +7192,7 @@ var init_migrate = __esm({
|
|
|
7078
7192
|
// src/cli/runtime/local.ts
|
|
7079
7193
|
var local_exports = {};
|
|
7080
7194
|
__export(local_exports, {
|
|
7195
|
+
MIN_PYTHON_LABEL: () => MIN_PYTHON_LABEL,
|
|
7081
7196
|
assertPortFree: () => assertPortFree,
|
|
7082
7197
|
credentialsForRuntime: () => credentialsForRuntime,
|
|
7083
7198
|
findPython: () => findPython,
|
|
@@ -7206,7 +7321,7 @@ function localPythonHasYaml(python) {
|
|
|
7206
7321
|
}
|
|
7207
7322
|
async function localBridge(request, local, opts = {}) {
|
|
7208
7323
|
const input = JSON.stringify(request);
|
|
7209
|
-
return await new Promise((
|
|
7324
|
+
return await new Promise((resolve32, reject) => {
|
|
7210
7325
|
const child = spawn(
|
|
7211
7326
|
local.python,
|
|
7212
7327
|
["-I", "-B", "-c", BRIDGE_BOOTSTRAP, local.root],
|
|
@@ -7251,7 +7366,7 @@ async function localBridge(request, local, opts = {}) {
|
|
|
7251
7366
|
payload = null;
|
|
7252
7367
|
}
|
|
7253
7368
|
if (payload && typeof payload === "object") {
|
|
7254
|
-
|
|
7369
|
+
resolve32(payload);
|
|
7255
7370
|
return;
|
|
7256
7371
|
}
|
|
7257
7372
|
reject(
|
|
@@ -7280,10 +7395,10 @@ function portOwner(port) {
|
|
|
7280
7395
|
return `pid ${pid}${command2 ? ` (${command2})` : ""}`;
|
|
7281
7396
|
}
|
|
7282
7397
|
async function assertPortFree(port, host = "127.0.0.1") {
|
|
7283
|
-
const taken = await new Promise((
|
|
7398
|
+
const taken = await new Promise((resolve32) => {
|
|
7284
7399
|
const probe = net.createServer();
|
|
7285
|
-
probe.once("error", () =>
|
|
7286
|
-
probe.listen(port, host, () => probe.close(() =>
|
|
7400
|
+
probe.once("error", () => resolve32(true));
|
|
7401
|
+
probe.listen(port, host, () => probe.close(() => resolve32(false)));
|
|
7287
7402
|
});
|
|
7288
7403
|
if (!taken) return;
|
|
7289
7404
|
const owner = portOwner(port);
|
|
@@ -7293,7 +7408,7 @@ async function assertPortFree(port, host = "127.0.0.1") {
|
|
|
7293
7408
|
);
|
|
7294
7409
|
}
|
|
7295
7410
|
async function localModule(argv, local, opts = {}) {
|
|
7296
|
-
return await new Promise((
|
|
7411
|
+
return await new Promise((resolve32, reject) => {
|
|
7297
7412
|
const child = spawn(
|
|
7298
7413
|
local.python,
|
|
7299
7414
|
["-B", "-c", MODULE_BOOTSTRAP, local.root, ...argv],
|
|
@@ -7326,7 +7441,7 @@ async function localModule(argv, local, opts = {}) {
|
|
|
7326
7441
|
});
|
|
7327
7442
|
child.on("close", (code, signal) => {
|
|
7328
7443
|
release();
|
|
7329
|
-
|
|
7444
|
+
resolve32(code ?? (signal ? 130 : 1));
|
|
7330
7445
|
});
|
|
7331
7446
|
});
|
|
7332
7447
|
}
|
|
@@ -7338,13 +7453,14 @@ function credentialsForRuntime(hostFlag) {
|
|
|
7338
7453
|
throw error;
|
|
7339
7454
|
}
|
|
7340
7455
|
}
|
|
7341
|
-
var MIN_PYTHON, DIAGNOSTIC_TAIL, BRIDGE_BOOTSTRAP, MODULE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
|
|
7456
|
+
var MIN_PYTHON, MIN_PYTHON_LABEL, DIAGNOSTIC_TAIL, BRIDGE_BOOTSTRAP, MODULE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
|
|
7342
7457
|
var init_local = __esm({
|
|
7343
7458
|
"src/cli/runtime/local.ts"() {
|
|
7344
7459
|
"use strict";
|
|
7345
7460
|
init_router();
|
|
7346
7461
|
init_config();
|
|
7347
7462
|
MIN_PYTHON = [3, 12];
|
|
7463
|
+
MIN_PYTHON_LABEL = MIN_PYTHON.join(".");
|
|
7348
7464
|
DIAGNOSTIC_TAIL = 600;
|
|
7349
7465
|
BRIDGE_BOOTSTRAP = `import sys,runpy,types,os
|
|
7350
7466
|
root=sys.argv[1]
|
|
@@ -7847,7 +7963,7 @@ async function runTransform(script, records2, opts = {}) {
|
|
|
7847
7963
|
try {
|
|
7848
7964
|
const { file, args } = command(resolved, scratch);
|
|
7849
7965
|
const env = Object.fromEntries(Object.entries(process.env).filter(([key2]) => !SCRUBBED.test(key2)));
|
|
7850
|
-
const done = await new Promise((
|
|
7966
|
+
const done = await new Promise((resolve32, reject) => {
|
|
7851
7967
|
const child = spawn2(file, args, { cwd: path9.dirname(resolved), env, stdio: ["pipe", "pipe", "pipe"] });
|
|
7852
7968
|
let stdout = "";
|
|
7853
7969
|
let stderr = "";
|
|
@@ -7864,7 +7980,7 @@ async function runTransform(script, records2, opts = {}) {
|
|
|
7864
7980
|
});
|
|
7865
7981
|
child.on("close", (code) => {
|
|
7866
7982
|
clearTimeout(timer);
|
|
7867
|
-
|
|
7983
|
+
resolve32({ code, stdout, stderr, timedOut });
|
|
7868
7984
|
});
|
|
7869
7985
|
child.stdin.on("error", () => void 0);
|
|
7870
7986
|
child.stdin.end(records2.map((record) => JSON.stringify(record) + "\n").join(""));
|
|
@@ -8008,12 +8124,12 @@ async function forEachLimited(items, limit, fn) {
|
|
|
8008
8124
|
await Promise.all(inFlight);
|
|
8009
8125
|
if (failure) throw failure;
|
|
8010
8126
|
}
|
|
8011
|
-
async function waitForBatch(
|
|
8012
|
-
const sleep4 = opts.sleep ??
|
|
8127
|
+
async function waitForBatch(client5, batchId, opts = {}) {
|
|
8128
|
+
const sleep4 = opts.sleep ?? client5.sleep;
|
|
8013
8129
|
let delay = opts.initialDelayMs ?? 1e3;
|
|
8014
8130
|
let last = "";
|
|
8015
8131
|
for (; ; ) {
|
|
8016
|
-
const status = await
|
|
8132
|
+
const status = await client5.get(batchId);
|
|
8017
8133
|
const phase = phaseLine(status);
|
|
8018
8134
|
if (phase !== last) {
|
|
8019
8135
|
opts.onPhase?.(phase);
|
|
@@ -8061,7 +8177,7 @@ var init_batches = __esm({
|
|
|
8061
8177
|
"published",
|
|
8062
8178
|
"failed"
|
|
8063
8179
|
]);
|
|
8064
|
-
sleepMs = (ms) => new Promise((
|
|
8180
|
+
sleepMs = (ms) => new Promise((resolve32) => setTimeout(resolve32, ms));
|
|
8065
8181
|
slugOf = (world) => world.split("@", 1)[0];
|
|
8066
8182
|
WorldDataApi = class {
|
|
8067
8183
|
constructor(creds, slug, sleep4 = sleepMs) {
|
|
@@ -8333,8 +8449,8 @@ __export(push_exports, {
|
|
|
8333
8449
|
pushRows: () => pushRows
|
|
8334
8450
|
});
|
|
8335
8451
|
async function pushRows(creds, slug, rows, opts = {}) {
|
|
8336
|
-
const
|
|
8337
|
-
const opened = await
|
|
8452
|
+
const client5 = opts.sleep ? new WorldDataApi(creds, slug, opts.sleep) : new WorldDataApi(creds, slug);
|
|
8453
|
+
const opened = await client5.open({
|
|
8338
8454
|
mode: opts.mode ?? "append",
|
|
8339
8455
|
merge: "upsert",
|
|
8340
8456
|
...opts.redact && opts.redact !== "off" ? { redact: opts.redact } : {},
|
|
@@ -8351,10 +8467,10 @@ async function pushRows(creds, slug, rows, opts = {}) {
|
|
|
8351
8467
|
})();
|
|
8352
8468
|
const chunks = buildChunks(tagged, { chunkBytes: opts.chunkBytes ?? DEFAULT_CHUNK_BYTES, chunkRows: null, entity: null });
|
|
8353
8469
|
await forEachLimited(chunks, Math.max(1, opts.parallel ?? 4), async (chunk) => {
|
|
8354
|
-
await
|
|
8470
|
+
await client5.upload(opened.batchId, chunk);
|
|
8355
8471
|
});
|
|
8356
|
-
await
|
|
8357
|
-
return waitForBatch(
|
|
8472
|
+
await client5.complete(opened.batchId);
|
|
8473
|
+
return waitForBatch(client5, opened.batchId, { initialDelayMs: pollMs() });
|
|
8358
8474
|
}
|
|
8359
8475
|
function pollMs() {
|
|
8360
8476
|
const raw = Number(process.env.GATEWAY_WORLD_DATA_POLL_MS ?? 1e3);
|
|
@@ -8717,7 +8833,7 @@ var init_dryRun = __esm({
|
|
|
8717
8833
|
/** Poll until the run settles or `timeoutSeconds` pass; the last verdict either way. */
|
|
8718
8834
|
async settle(runId, opts) {
|
|
8719
8835
|
const now = opts.now ?? Date.now;
|
|
8720
|
-
const sleep4 = opts.sleep ?? ((ms) => new Promise((
|
|
8836
|
+
const sleep4 = opts.sleep ?? ((ms) => new Promise((resolve32) => setTimeout(resolve32, ms)));
|
|
8721
8837
|
const deadline = now() + opts.timeoutSeconds * 1e3;
|
|
8722
8838
|
for (; ; ) {
|
|
8723
8839
|
const budget = Math.floor(
|
|
@@ -8830,6 +8946,7 @@ __export(worlds_exports, {
|
|
|
8830
8946
|
WorldBrowser: () => WorldBrowser,
|
|
8831
8947
|
WorldCallTooLarge: () => WorldCallTooLarge,
|
|
8832
8948
|
WorldEditClient: () => WorldEditClient,
|
|
8949
|
+
WorldRequestLog: () => WorldRequestLog,
|
|
8833
8950
|
WorldSandboxClient: () => WorldSandboxClient,
|
|
8834
8951
|
WorldSession: () => WorldSession,
|
|
8835
8952
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
@@ -8923,6 +9040,7 @@ __export(worlds_exports, {
|
|
|
8923
9040
|
shapeText: () => shapeText,
|
|
8924
9041
|
snapshotTreeHashes: () => snapshotTreeHashes,
|
|
8925
9042
|
storedForms: () => storedForms,
|
|
9043
|
+
surfaceDescriptor: () => surfaceDescriptor,
|
|
8926
9044
|
surfaceKinds: () => surfaceKinds,
|
|
8927
9045
|
taskLabel: () => taskLabel,
|
|
8928
9046
|
toolCallRecordsIn: () => toolCallRecordsIn,
|
|
@@ -8968,9 +9086,9 @@ function parseErrorBody(text2, limit = 600) {
|
|
|
8968
9086
|
code: stableCode
|
|
8969
9087
|
};
|
|
8970
9088
|
}
|
|
8971
|
-
async function apiRequest(options, method,
|
|
8972
|
-
const reply = await new PlatformTransport(resolveEnv(options)).send(method,
|
|
8973
|
-
if (!reply.ok) throw new ApiError(reply.status, method,
|
|
9089
|
+
async function apiRequest(options, method, path49, body, init2 = {}) {
|
|
9090
|
+
const reply = await new PlatformTransport(resolveEnv(options)).send(method, path49, body, init2);
|
|
9091
|
+
if (!reply.ok) throw new ApiError(reply.status, method, path49, reply.text);
|
|
8974
9092
|
return JSON.parse(reply.text);
|
|
8975
9093
|
}
|
|
8976
9094
|
async function setEnvSecret(slug, key2, value, options = {}) {
|
|
@@ -9065,7 +9183,7 @@ async function waitForRun(runId, opts = {}) {
|
|
|
9065
9183
|
);
|
|
9066
9184
|
opts.onTick?.(run);
|
|
9067
9185
|
await new Promise(
|
|
9068
|
-
(
|
|
9186
|
+
(resolve32) => setTimeout(resolve32, (opts.intervalSeconds ?? 20) * 1e3)
|
|
9069
9187
|
);
|
|
9070
9188
|
}
|
|
9071
9189
|
}
|
|
@@ -9164,6 +9282,8 @@ var init_worlds = __esm({
|
|
|
9164
9282
|
init_checkoutProvenance();
|
|
9165
9283
|
init_evals();
|
|
9166
9284
|
init_browser();
|
|
9285
|
+
init_surfaceDescriptor();
|
|
9286
|
+
init_requestLog();
|
|
9167
9287
|
init_browserReconnect();
|
|
9168
9288
|
init_nativeComputer();
|
|
9169
9289
|
init_hub();
|
|
@@ -9178,9 +9298,9 @@ var init_worlds = __esm({
|
|
|
9178
9298
|
init_editSessions();
|
|
9179
9299
|
init_dryRun();
|
|
9180
9300
|
ApiError = class extends Error {
|
|
9181
|
-
constructor(status, method,
|
|
9301
|
+
constructor(status, method, path49, text2) {
|
|
9182
9302
|
const parsed = parseErrorBody(text2);
|
|
9183
|
-
super(`${method} ${
|
|
9303
|
+
super(`${method} ${path49} -> ${status}: ${parsed.detail}`);
|
|
9184
9304
|
this.status = status;
|
|
9185
9305
|
this.text = text2;
|
|
9186
9306
|
this.name = "ApiError";
|
|
@@ -9482,21 +9602,21 @@ function listFiles(dir, rel = "") {
|
|
|
9482
9602
|
function packagedFiles(name) {
|
|
9483
9603
|
const directory = skillDir(name);
|
|
9484
9604
|
const files = {};
|
|
9485
|
-
for (const
|
|
9605
|
+
for (const relative6 of listFiles(directory)) files[`.claude/skills/${name}/${relative6}`] = path15.join(directory, relative6);
|
|
9486
9606
|
for (const agent of SKILL_AGENTS[name] ?? []) files[`.claude/agents/${agent}`] = path15.join(skillsRoot(), "agents", agent);
|
|
9487
9607
|
return files;
|
|
9488
9608
|
}
|
|
9489
9609
|
function installSkill(destination, name, force = false) {
|
|
9490
9610
|
const report = { written: [], unchanged: [], conflicts: [] };
|
|
9491
9611
|
const planned = [];
|
|
9492
|
-
for (const [
|
|
9612
|
+
for (const [relative6, source2] of Object.entries(packagedFiles(name))) {
|
|
9493
9613
|
const content = fs17.readFileSync(source2);
|
|
9494
|
-
const target = path15.join(destination,
|
|
9495
|
-
if (fs17.existsSync(target) && fs17.readFileSync(target).equals(content)) report.unchanged.push(
|
|
9496
|
-
else if (fs17.existsSync(target) && !force) report.conflicts.push(
|
|
9614
|
+
const target = path15.join(destination, relative6);
|
|
9615
|
+
if (fs17.existsSync(target) && fs17.readFileSync(target).equals(content)) report.unchanged.push(relative6);
|
|
9616
|
+
else if (fs17.existsSync(target) && !force) report.conflicts.push(relative6);
|
|
9497
9617
|
else {
|
|
9498
9618
|
planned.push([target, content]);
|
|
9499
|
-
report.written.push(
|
|
9619
|
+
report.written.push(relative6);
|
|
9500
9620
|
}
|
|
9501
9621
|
}
|
|
9502
9622
|
if (report.conflicts.length) {
|
|
@@ -9518,12 +9638,12 @@ function printOrInstallSkill(ctx, name, install, force) {
|
|
|
9518
9638
|
const report = installSkill(install, name, force);
|
|
9519
9639
|
if (report.conflicts.length) {
|
|
9520
9640
|
ctx.stderr("Refusing to overwrite files that differ from the packaged skill:");
|
|
9521
|
-
for (const
|
|
9641
|
+
for (const relative6 of report.conflicts) ctx.stderr(` ${path15.join(install, relative6)}`);
|
|
9522
9642
|
ctx.stderr("Pass --force to replace them.");
|
|
9523
9643
|
return 1;
|
|
9524
9644
|
}
|
|
9525
|
-
for (const
|
|
9526
|
-
for (const
|
|
9645
|
+
for (const relative6 of report.written) ctx.stdout(`wrote ${path15.join(install, relative6)}`);
|
|
9646
|
+
for (const relative6 of report.unchanged) ctx.stdout(`unchanged ${path15.join(install, relative6)}`);
|
|
9527
9647
|
const step = NEXT_STEPS[name];
|
|
9528
9648
|
if (step) ctx.stdout(`next: ${step}`);
|
|
9529
9649
|
}
|
|
@@ -9669,10 +9789,10 @@ ${equivalent}`);
|
|
|
9669
9789
|
return 2;
|
|
9670
9790
|
}
|
|
9671
9791
|
function appendStepSummary(text2) {
|
|
9672
|
-
const
|
|
9673
|
-
if (!
|
|
9792
|
+
const path49 = process.env.GITHUB_STEP_SUMMARY;
|
|
9793
|
+
if (!path49) return;
|
|
9674
9794
|
try {
|
|
9675
|
-
fs20.appendFileSync(
|
|
9795
|
+
fs20.appendFileSync(path49, text2 + "\n\n");
|
|
9676
9796
|
} catch {
|
|
9677
9797
|
}
|
|
9678
9798
|
}
|
|
@@ -9680,7 +9800,14 @@ function printDeprecations(ctx, deprecations) {
|
|
|
9680
9800
|
for (const notice of deprecations ?? [])
|
|
9681
9801
|
ctx.stderr(`deprecated (${notice.code}): ${notice.message} Instead: ${notice.replacement}`);
|
|
9682
9802
|
}
|
|
9683
|
-
|
|
9803
|
+
async function requestLines(session, ctx, label) {
|
|
9804
|
+
const log2 = await WorldRequestLog.read(session);
|
|
9805
|
+
if (!log2) ctx.stderr(`# ${label} keeps no request log (a world without HTTP routes, or not on the World Host)`);
|
|
9806
|
+
if (log2?.dropped)
|
|
9807
|
+
ctx.stderr(`# ${label}: the world keeps its newest requests only; ${log2.dropped} older ones are gone (WORLDS_CALL_LOG_MAX)`);
|
|
9808
|
+
return log2?.asCalls() ?? [];
|
|
9809
|
+
}
|
|
9810
|
+
var HOST_FLAG, API_KEY_FLAG, BROWSER_TIER_FLAG, LIST_LIMIT_MAX, sleep2, SECRET_PROMPT, REQUEST_LOG_NOTES;
|
|
9684
9811
|
var init_shared = __esm({
|
|
9685
9812
|
"src/cli/platform/shared.ts"() {
|
|
9686
9813
|
"use strict";
|
|
@@ -9703,18 +9830,19 @@ var init_shared = __esm({
|
|
|
9703
9830
|
help: "Browser capacity for a World Host session: standard (spot, may be reclaimed) or premium (on-demand). Default: the organization's setting."
|
|
9704
9831
|
};
|
|
9705
9832
|
LIST_LIMIT_MAX = 200;
|
|
9706
|
-
sleep2 = (ms) => new Promise((
|
|
9833
|
+
sleep2 = (ms) => new Promise((resolve32) => setTimeout(resolve32, ms));
|
|
9707
9834
|
SECRET_PROMPT = "Paste the value, then Ctrl-D:";
|
|
9835
|
+
REQUEST_LOG_NOTES = "The ledger holds the calls the platform brokered: tool calls, seeds, grades, resets. --requests appends the\nworld's own request log as kind \"request\" lines: the `calls` its grader reads, every route request (the\nbrowser's and a direct api.url client's included) with `via`, the newest WORLDS_CALL_LOG_MAX (5000) of them;\nstderr says when older ones are gone. It is read from the live session with one\n`state` call, which the ledger records like any other; export before you close. A world that keeps no request\nlog is named on stderr; a session that cannot answer fails the command (exit 1) and nothing is written.";
|
|
9708
9836
|
}
|
|
9709
9837
|
});
|
|
9710
9838
|
|
|
9711
9839
|
// src/cli/platform/connector.ts
|
|
9712
|
-
import * as
|
|
9713
|
-
import * as
|
|
9714
|
-
function isCarriedTemplatePath(
|
|
9715
|
-
const slash =
|
|
9716
|
-
if (slash === -1) return WORLD_ARTIFACT_FILES.has(
|
|
9717
|
-
return WORLD_ARTIFACT_DIRS.has(
|
|
9840
|
+
import * as fs31 from "fs";
|
|
9841
|
+
import * as path22 from "path";
|
|
9842
|
+
function isCarriedTemplatePath(relative6) {
|
|
9843
|
+
const slash = relative6.indexOf("/");
|
|
9844
|
+
if (slash === -1) return WORLD_ARTIFACT_FILES.has(relative6);
|
|
9845
|
+
return WORLD_ARTIFACT_DIRS.has(relative6.slice(0, slash));
|
|
9718
9846
|
}
|
|
9719
9847
|
function splitTemplateFiles(files) {
|
|
9720
9848
|
const kept = files.filter((file) => !CONNECTOR_ONLY_FILES.has(file.path));
|
|
@@ -9726,8 +9854,8 @@ function splitTemplateFiles(files) {
|
|
|
9726
9854
|
function walk(root) {
|
|
9727
9855
|
const out = [];
|
|
9728
9856
|
const visit = (rel) => {
|
|
9729
|
-
const abs = rel ?
|
|
9730
|
-
for (const entry of
|
|
9857
|
+
const abs = rel ? path22.join(root, rel) : root;
|
|
9858
|
+
for (const entry of fs31.readdirSync(abs, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
9731
9859
|
const childRel = rel ? `${rel}/${entry.name}` : entry.name;
|
|
9732
9860
|
if (entry.isSymbolicLink()) continue;
|
|
9733
9861
|
if (entry.isDirectory()) {
|
|
@@ -9743,66 +9871,66 @@ function walk(root) {
|
|
|
9743
9871
|
visit("");
|
|
9744
9872
|
return out;
|
|
9745
9873
|
}
|
|
9746
|
-
function readText3(root,
|
|
9747
|
-
const bytes =
|
|
9874
|
+
function readText3(root, relative6) {
|
|
9875
|
+
const bytes = fs31.readFileSync(path22.join(root, relative6));
|
|
9748
9876
|
const text2 = bytes.toString("utf8");
|
|
9749
9877
|
if (Buffer.from(text2, "utf8").length !== bytes.length || text2.includes("\uFFFD"))
|
|
9750
9878
|
return null;
|
|
9751
9879
|
return text2;
|
|
9752
9880
|
}
|
|
9753
|
-
function isBuildOutput2(
|
|
9754
|
-
const name =
|
|
9881
|
+
function isBuildOutput2(relative6) {
|
|
9882
|
+
const name = path22.basename(relative6);
|
|
9755
9883
|
if (BUILD_OUTPUT_NAMES.has(name)) return true;
|
|
9756
9884
|
for (const suffix of BUILD_OUTPUT_SUFFIXES)
|
|
9757
9885
|
if (name.endsWith(suffix)) return true;
|
|
9758
9886
|
return false;
|
|
9759
9887
|
}
|
|
9760
|
-
function templatePath(
|
|
9761
|
-
const parts2 =
|
|
9762
|
-
if (WORLD_SKIPPED_DIRS.has(parts2[0]) || WORLD_SKIPPED_FILES.has(
|
|
9888
|
+
function templatePath(relative6) {
|
|
9889
|
+
const parts2 = relative6.split("/");
|
|
9890
|
+
if (WORLD_SKIPPED_DIRS.has(parts2[0]) || WORLD_SKIPPED_FILES.has(relative6))
|
|
9763
9891
|
return null;
|
|
9764
|
-
if (isBuildOutput2(
|
|
9892
|
+
if (isBuildOutput2(relative6)) return null;
|
|
9765
9893
|
if (parts2.length === 1)
|
|
9766
|
-
return ROOT_CARRIED_FILES.has(
|
|
9894
|
+
return ROOT_CARRIED_FILES.has(relative6) ? relative6 : null;
|
|
9767
9895
|
if (parts2[0] === "schema") {
|
|
9768
9896
|
const name = parts2[parts2.length - 1];
|
|
9769
|
-
if (parts2.length !== 2 || !SUPPORTING_SUFFIXES.has(
|
|
9897
|
+
if (parts2.length !== 2 || !SUPPORTING_SUFFIXES.has(path22.extname(name)) || GENERATED_NAMES.has(name))
|
|
9770
9898
|
return null;
|
|
9771
9899
|
return name;
|
|
9772
9900
|
}
|
|
9773
|
-
if (
|
|
9774
|
-
if (WORLD_CARRIED_DIRS.has(parts2[0])) return
|
|
9901
|
+
if (relative6 === "tools/handlers.py") return "handlers.py";
|
|
9902
|
+
if (WORLD_CARRIED_DIRS.has(parts2[0])) return relative6;
|
|
9775
9903
|
return null;
|
|
9776
9904
|
}
|
|
9777
9905
|
function collectTemplate(directory) {
|
|
9778
|
-
if (
|
|
9906
|
+
if (fs31.existsSync(path22.join(directory, "world.json"))) {
|
|
9779
9907
|
const files2 = {};
|
|
9780
|
-
for (const
|
|
9781
|
-
const text2 = readText3(directory,
|
|
9908
|
+
for (const relative6 of walk(directory)) {
|
|
9909
|
+
const text2 = readText3(directory, relative6);
|
|
9782
9910
|
if (text2 === null)
|
|
9783
9911
|
throw new CliError(
|
|
9784
|
-
`${
|
|
9912
|
+
`${relative6} is not UTF-8 text; a connector template holds text files only`,
|
|
9785
9913
|
1
|
|
9786
9914
|
);
|
|
9787
|
-
files2[
|
|
9915
|
+
files2[relative6] = text2;
|
|
9788
9916
|
}
|
|
9789
9917
|
return { source: "template", files: files2, skipped: [] };
|
|
9790
9918
|
}
|
|
9791
|
-
if (!
|
|
9919
|
+
if (!fs31.existsSync(path22.join(directory, "schema", "world.json")))
|
|
9792
9920
|
throw new CliError(
|
|
9793
9921
|
`${directory}: neither a connector template (world.json) nor a world (schema/world.json)`,
|
|
9794
9922
|
1
|
|
9795
9923
|
);
|
|
9796
9924
|
const files = {};
|
|
9797
9925
|
const skipped = [];
|
|
9798
|
-
for (const
|
|
9799
|
-
const target = templatePath(
|
|
9926
|
+
for (const relative6 of walk(directory)) {
|
|
9927
|
+
const target = templatePath(relative6);
|
|
9800
9928
|
if (target === null) {
|
|
9801
|
-
skipped.push(
|
|
9929
|
+
skipped.push(relative6);
|
|
9802
9930
|
continue;
|
|
9803
9931
|
}
|
|
9804
|
-
const text2 = readText3(directory,
|
|
9805
|
-
if (text2 === null) skipped.push(`${
|
|
9932
|
+
const text2 = readText3(directory, relative6);
|
|
9933
|
+
if (text2 === null) skipped.push(`${relative6} (not UTF-8 text)`);
|
|
9806
9934
|
else files[target] = text2;
|
|
9807
9935
|
}
|
|
9808
9936
|
return { source: "world", files, skipped };
|
|
@@ -9855,7 +9983,7 @@ function registerConnectorCommands(root) {
|
|
|
9855
9983
|
run: async (args, ctx) => {
|
|
9856
9984
|
const dir = args.positionals[0];
|
|
9857
9985
|
const gathered = collectTemplate(dir);
|
|
9858
|
-
const slug = arg.str(args, "slug") ??
|
|
9986
|
+
const slug = arg.str(args, "slug") ?? path22.basename(path22.resolve(dir));
|
|
9859
9987
|
const creds = credentials(args);
|
|
9860
9988
|
const files = Object.fromEntries(
|
|
9861
9989
|
Object.entries(gathered.files).map(([p, content]) => [
|
|
@@ -9970,7 +10098,7 @@ function registerConnectorCommands(root) {
|
|
|
9970
10098
|
run: async (args, ctx) => {
|
|
9971
10099
|
const slug = args.positionals[0];
|
|
9972
10100
|
const out = arg.str(args, "out") ?? slug;
|
|
9973
|
-
if (
|
|
10101
|
+
if (fs31.existsSync(out) && (!fs31.statSync(out).isDirectory() || fs31.readdirSync(out).length > 0))
|
|
9974
10102
|
throw new CliError(`${out}: must be a new or empty directory`, 1);
|
|
9975
10103
|
const pulled = await api(
|
|
9976
10104
|
credentials(args),
|
|
@@ -9978,16 +10106,16 @@ function registerConnectorCommands(root) {
|
|
|
9978
10106
|
oneRoute(slug, { version: arg.str(args, "version") })
|
|
9979
10107
|
);
|
|
9980
10108
|
const files = flattenFiles(slug, pulled);
|
|
9981
|
-
for (const
|
|
9982
|
-
if (
|
|
10109
|
+
for (const relative6 of Object.keys(files).sort()) {
|
|
10110
|
+
if (relative6.startsWith("/") || relative6.split("/").includes(".."))
|
|
9983
10111
|
throw new CliError(
|
|
9984
|
-
`Refusing a template path outside the directory: ${
|
|
10112
|
+
`Refusing a template path outside the directory: ${relative6}`,
|
|
9985
10113
|
1
|
|
9986
10114
|
);
|
|
9987
|
-
const target =
|
|
9988
|
-
|
|
9989
|
-
|
|
9990
|
-
ctx.stdout(
|
|
10115
|
+
const target = path22.join(out, relative6);
|
|
10116
|
+
fs31.mkdirSync(path22.dirname(target), { recursive: true });
|
|
10117
|
+
fs31.writeFileSync(target, files[relative6]);
|
|
10118
|
+
ctx.stdout(relative6);
|
|
9991
10119
|
}
|
|
9992
10120
|
ctx.stderr(
|
|
9993
10121
|
`# ${slug} @ ${pulled.commit?.commitHash ?? pulled.commit?.id ?? ""} -> ${out}`
|
|
@@ -10149,8 +10277,8 @@ var init_connector = __esm({
|
|
|
10149
10277
|
|
|
10150
10278
|
// src/files/index.ts
|
|
10151
10279
|
import { createHash as createHash12 } from "crypto";
|
|
10152
|
-
import * as
|
|
10153
|
-
import * as
|
|
10280
|
+
import * as fs33 from "fs";
|
|
10281
|
+
import * as path24 from "path";
|
|
10154
10282
|
import { Readable, Transform } from "stream";
|
|
10155
10283
|
import { pipeline } from "stream/promises";
|
|
10156
10284
|
function isDriveRef(value) {
|
|
@@ -10190,9 +10318,9 @@ async function readFile(options = {}, filePath, limits = {}) {
|
|
|
10190
10318
|
async function downloadFile(options = {}, filePath, outPath, onProgress) {
|
|
10191
10319
|
const file = await getFile(options, filePath);
|
|
10192
10320
|
const res = await openDownload(file.url);
|
|
10193
|
-
|
|
10321
|
+
fs33.mkdirSync(path24.dirname(path24.resolve(outPath)), { recursive: true });
|
|
10194
10322
|
const source2 = Readable.fromWeb(res.body);
|
|
10195
|
-
await pipeline(source2, counting((n) => onProgress?.(n, file.sizeBytes)),
|
|
10323
|
+
await pipeline(source2, counting((n) => onProgress?.(n, file.sizeBytes)), fs33.createWriteStream(outPath));
|
|
10196
10324
|
return { ...file, out: outPath };
|
|
10197
10325
|
}
|
|
10198
10326
|
async function requestUpload(options = {}, body) {
|
|
@@ -10203,11 +10331,11 @@ async function confirmUpload(options = {}, fileId, ok = true) {
|
|
|
10203
10331
|
}
|
|
10204
10332
|
async function sha256Base64(localPath) {
|
|
10205
10333
|
const hash = createHash12("sha256");
|
|
10206
|
-
for await (const chunk of
|
|
10334
|
+
for await (const chunk of fs33.createReadStream(localPath)) hash.update(chunk);
|
|
10207
10335
|
return hash.digest("base64");
|
|
10208
10336
|
}
|
|
10209
10337
|
function contentTypeFor(name) {
|
|
10210
|
-
return CONTENT_TYPES[
|
|
10338
|
+
return CONTENT_TYPES[path24.extname(name).toLowerCase()] ?? "application/octet-stream";
|
|
10211
10339
|
}
|
|
10212
10340
|
function counting(report) {
|
|
10213
10341
|
let seen = 0;
|
|
@@ -10234,37 +10362,37 @@ async function putPresigned(uploadUrl, body, headers) {
|
|
|
10234
10362
|
if (!res.ok) throw new Error(`upload failed: storage answered HTTP ${res.status}: ${(await res.text()).slice(0, 300)}`);
|
|
10235
10363
|
}
|
|
10236
10364
|
async function uploadFile(options = {}, localPath, targetPath, upload = {}) {
|
|
10237
|
-
const stat =
|
|
10365
|
+
const stat = fs33.statSync(localPath);
|
|
10238
10366
|
if (!stat.isFile()) throw new Error(`${localPath} is not a file`);
|
|
10239
10367
|
if (stat.size === 0) throw new Error(`${localPath} is empty; the drive refuses zero-byte uploads`);
|
|
10240
10368
|
const contentType = upload.contentType ?? contentTypeFor(localPath);
|
|
10241
|
-
const
|
|
10369
|
+
const sha2563 = await sha256Base64(localPath);
|
|
10242
10370
|
const target = drivePath(targetPath);
|
|
10243
|
-
const granted = await requestUpload(options, { path: target, contentLength: stat.size, contentType, sha256:
|
|
10371
|
+
const granted = await requestUpload(options, { path: target, contentLength: stat.size, contentType, sha256: sha2563, ...upload.overwrite ? { overwrite: true } : {} });
|
|
10244
10372
|
try {
|
|
10245
|
-
const stream =
|
|
10246
|
-
await putPresigned(granted.uploadUrl, Readable.toWeb(stream), { contentType, contentLength: stat.size, sha256:
|
|
10373
|
+
const stream = fs33.createReadStream(localPath).pipe(counting((n) => upload.onProgress?.(n, stat.size)));
|
|
10374
|
+
await putPresigned(granted.uploadUrl, Readable.toWeb(stream), { contentType, contentLength: stat.size, sha256: sha2563 });
|
|
10247
10375
|
} catch (error) {
|
|
10248
10376
|
await confirmUpload(options, granted.fileId, false).catch(() => void 0);
|
|
10249
10377
|
throw error;
|
|
10250
10378
|
}
|
|
10251
10379
|
const confirmed = await confirmUpload(options, granted.fileId, true);
|
|
10252
|
-
return { path: confirmed.path, fileId: granted.fileId, sizeBytes: stat.size, sha256:
|
|
10380
|
+
return { path: confirmed.path, fileId: granted.fileId, sizeBytes: stat.size, sha256: sha2563, contentType };
|
|
10253
10381
|
}
|
|
10254
10382
|
async function uploadBytes(options = {}, bytes, targetPath, upload = {}) {
|
|
10255
10383
|
if (!bytes.length) throw new Error("nothing to upload: the content is empty");
|
|
10256
10384
|
const target = drivePath(targetPath);
|
|
10257
10385
|
const contentType = upload.contentType ?? contentTypeFor(target);
|
|
10258
|
-
const
|
|
10259
|
-
const granted = await requestUpload(options, { path: target, contentLength: bytes.length, contentType, sha256:
|
|
10386
|
+
const sha2563 = createHash12("sha256").update(bytes).digest("base64");
|
|
10387
|
+
const granted = await requestUpload(options, { path: target, contentLength: bytes.length, contentType, sha256: sha2563, ...upload.overwrite ? { overwrite: true } : {} });
|
|
10260
10388
|
try {
|
|
10261
|
-
await putPresigned(granted.uploadUrl, new Uint8Array(bytes), { contentType, contentLength: bytes.length, sha256:
|
|
10389
|
+
await putPresigned(granted.uploadUrl, new Uint8Array(bytes), { contentType, contentLength: bytes.length, sha256: sha2563 });
|
|
10262
10390
|
} catch (error) {
|
|
10263
10391
|
await confirmUpload(options, granted.fileId, false).catch(() => void 0);
|
|
10264
10392
|
throw error;
|
|
10265
10393
|
}
|
|
10266
10394
|
const confirmed = await confirmUpload(options, granted.fileId, true);
|
|
10267
|
-
return { path: confirmed.path, fileId: granted.fileId, sizeBytes: bytes.length, sha256:
|
|
10395
|
+
return { path: confirmed.path, fileId: granted.fileId, sizeBytes: bytes.length, sha256: sha2563, contentType };
|
|
10268
10396
|
}
|
|
10269
10397
|
async function deleteFile(options = {}, filePath) {
|
|
10270
10398
|
return apiRequest(options, "DELETE", `${BASE}${qs({ path: drivePath(filePath) })}`);
|
|
@@ -10410,8 +10538,8 @@ var init_publicUrl = __esm({
|
|
|
10410
10538
|
{ base: ip4("192.168.0.0"), bits: 16 }
|
|
10411
10539
|
];
|
|
10412
10540
|
PublicUrl = class {
|
|
10413
|
-
constructor(
|
|
10414
|
-
this.resolve =
|
|
10541
|
+
constructor(resolve32 = (host) => lookup(host, { all: true }), doFetch = (url, init2) => fetch(url, init2)) {
|
|
10542
|
+
this.resolve = resolve32;
|
|
10415
10543
|
this.doFetch = doFetch;
|
|
10416
10544
|
}
|
|
10417
10545
|
resolve;
|
|
@@ -10477,8 +10605,8 @@ var init_publicUrl = __esm({
|
|
|
10477
10605
|
});
|
|
10478
10606
|
|
|
10479
10607
|
// src/cli/runtime/schemaOpenApi.ts
|
|
10480
|
-
import * as
|
|
10481
|
-
import * as
|
|
10608
|
+
import * as fs34 from "fs";
|
|
10609
|
+
import * as path25 from "path";
|
|
10482
10610
|
function platformCredentials(hostFlag, why) {
|
|
10483
10611
|
try {
|
|
10484
10612
|
return resolveCredentials(hostFlag);
|
|
@@ -10593,12 +10721,12 @@ var init_schemaOpenApi = __esm({
|
|
|
10593
10721
|
};
|
|
10594
10722
|
LocalSource = class extends OpenApiSourceArg {
|
|
10595
10723
|
async bytes() {
|
|
10596
|
-
const abs =
|
|
10597
|
-
if (!
|
|
10724
|
+
const abs = path25.resolve(this.spelled);
|
|
10725
|
+
if (!fs34.existsSync(abs) || !fs34.statSync(abs).isFile())
|
|
10598
10726
|
throw new CliError(`--from-openapi ${this.spelled}: no such file`);
|
|
10599
|
-
const { size } =
|
|
10727
|
+
const { size } = fs34.statSync(abs);
|
|
10600
10728
|
if (size > OPENAPI_MAX_BYTES) throw this.tooBig(size);
|
|
10601
|
-
return
|
|
10729
|
+
return fs34.readFileSync(abs);
|
|
10602
10730
|
}
|
|
10603
10731
|
};
|
|
10604
10732
|
UrlSource = class extends OpenApiSourceArg {
|
|
@@ -10692,8 +10820,8 @@ __export(schema_exports, {
|
|
|
10692
10820
|
uiSection: () => uiSection,
|
|
10693
10821
|
withRowCounts: () => withRowCounts
|
|
10694
10822
|
});
|
|
10695
|
-
import * as
|
|
10696
|
-
import * as
|
|
10823
|
+
import * as fs35 from "fs";
|
|
10824
|
+
import * as path26 from "path";
|
|
10697
10825
|
function uiSection(toml) {
|
|
10698
10826
|
const start = /^\[ui\]\s*$/m.exec(toml);
|
|
10699
10827
|
if (!start) return {};
|
|
@@ -10710,16 +10838,16 @@ function uiSection(toml) {
|
|
|
10710
10838
|
return out;
|
|
10711
10839
|
}
|
|
10712
10840
|
function declareUi(dir) {
|
|
10713
|
-
const spec =
|
|
10714
|
-
if (!
|
|
10841
|
+
const spec = path26.join(dir, "connector.toml");
|
|
10842
|
+
if (!fs35.existsSync(spec))
|
|
10715
10843
|
throw new CliError(
|
|
10716
10844
|
`${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.`
|
|
10717
10845
|
);
|
|
10718
|
-
const text2 =
|
|
10846
|
+
const text2 = fs35.readFileSync(spec, "utf8");
|
|
10719
10847
|
if (/^\[ui\]\s*$/m.test(text2)) return false;
|
|
10720
10848
|
const firstRoute = /^\[\[operations\]\]/m.exec(text2);
|
|
10721
10849
|
const next = firstRoute ? text2.slice(0, firstRoute.index) + UI_SECTION + "\n" + text2.slice(firstRoute.index) : text2.replace(/\n*$/, "\n") + "\n" + UI_SECTION;
|
|
10722
|
-
|
|
10850
|
+
fs35.writeFileSync(spec, next);
|
|
10723
10851
|
return true;
|
|
10724
10852
|
}
|
|
10725
10853
|
async function listTemplates(creds) {
|
|
@@ -10754,7 +10882,8 @@ function initNextSteps(dir, shape) {
|
|
|
10754
10882
|
const steps = [];
|
|
10755
10883
|
if (shape.blank)
|
|
10756
10884
|
steps.push(
|
|
10757
|
-
`gateway worlds schema entity add ${dir} <entity> --fields id:string,name:string --key id
|
|
10885
|
+
`gateway worlds schema entity add ${dir} <entity> --fields id:string,name:string --key id`,
|
|
10886
|
+
`gateway worlds schema entity remove ${dir} records # the example entity, once yours is declared`
|
|
10758
10887
|
);
|
|
10759
10888
|
if (!shape.hasRoutes)
|
|
10760
10889
|
steps.push(
|
|
@@ -10832,6 +10961,12 @@ function whereLine(description) {
|
|
|
10832
10961
|
return `where: platform${description.versionId ? `, version ${String(description.versionId)}` : ""}`;
|
|
10833
10962
|
return null;
|
|
10834
10963
|
}
|
|
10964
|
+
function fieldLine(field2) {
|
|
10965
|
+
const optional = field2.required ? "" : "?";
|
|
10966
|
+
const allowed = Array.isArray(field2.enum) ? ` one of: ${field2.enum.map(enumValue).join(" | ")}` : "";
|
|
10967
|
+
const tag = field2.redaction ? ` [${String(field2.redaction)}]` : "";
|
|
10968
|
+
return `${String(field2.name)}: ${String(field2.type ?? "any")}${optional}${allowed}${tag}`;
|
|
10969
|
+
}
|
|
10835
10970
|
function renderDescription(description) {
|
|
10836
10971
|
const lines = [];
|
|
10837
10972
|
const domain = description.domainId ?? description.slug ?? "(no $id)";
|
|
@@ -10847,12 +10982,8 @@ function renderDescription(description) {
|
|
|
10847
10982
|
const pk = Array.isArray(entity.primaryKey) ? entity.primaryKey.join(", ") : "";
|
|
10848
10983
|
const rows = typeof entity.rowCount === "number" ? ` (rows: ${entity.rowCount})` : "";
|
|
10849
10984
|
lines.push(` ${String(entity.name)}${pk ? ` (pk: ${pk})` : ""}${rows}`);
|
|
10850
|
-
for (const field2 of Array.isArray(entity.fields) ? entity.fields : [])
|
|
10851
|
-
|
|
10852
|
-
lines.push(
|
|
10853
|
-
` ${String(field2.name)}: ${String(field2.type ?? "any")}${field2.required ? "" : "?"}${tag}`
|
|
10854
|
-
);
|
|
10855
|
-
}
|
|
10985
|
+
for (const field2 of Array.isArray(entity.fields) ? entity.fields : [])
|
|
10986
|
+
lines.push(` ${fieldLine(field2)}`);
|
|
10856
10987
|
if (Array.isArray(entity.relationships) && entity.relationships.length)
|
|
10857
10988
|
lines.push(
|
|
10858
10989
|
` relationships: ${entity.relationships.map(relationshipText).join(", ")}`
|
|
@@ -10963,7 +11094,7 @@ function registerSchemaCommands(schema) {
|
|
|
10963
11094
|
],
|
|
10964
11095
|
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.",
|
|
10965
11096
|
run: async (args, ctx) => {
|
|
10966
|
-
const dir =
|
|
11097
|
+
const dir = path26.resolve(args.positionals[0]);
|
|
10967
11098
|
if (arg.str(args, "from-openapi")) return initFromOpenApi(args, ctx, dir);
|
|
10968
11099
|
assertEmptyTarget(dir);
|
|
10969
11100
|
const connector = arg.str(args, "connector") ?? "custom";
|
|
@@ -11014,7 +11145,7 @@ function registerSchemaCommands(schema) {
|
|
|
11014
11145
|
1
|
|
11015
11146
|
);
|
|
11016
11147
|
writeWorldFiles(dir, files);
|
|
11017
|
-
const hasRoutes =
|
|
11148
|
+
const hasRoutes = fs35.existsSync(path26.join(dir, "connector.toml"));
|
|
11018
11149
|
const out = {
|
|
11019
11150
|
status: "ok",
|
|
11020
11151
|
domain: report.domain,
|
|
@@ -11049,7 +11180,7 @@ function registerSchemaCommands(schema) {
|
|
|
11049
11180
|
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: handlers plus connector routes and a dependency's `alias.tool`.\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
|
|
11050
11181
|
} : {},
|
|
11051
11182
|
run: async (args, ctx) => {
|
|
11052
|
-
const dir =
|
|
11183
|
+
const dir = path26.resolve(args.positionals[0]);
|
|
11053
11184
|
const creds = credentialsForRuntime(arg.str(args, "host"));
|
|
11054
11185
|
const report = await runtime(
|
|
11055
11186
|
creds,
|
|
@@ -11079,7 +11210,7 @@ function registerSchemaCommands(schema) {
|
|
|
11079
11210
|
],
|
|
11080
11211
|
notes: "`gateway worlds describe <dir|slug>` is the same view with row counts, and works on a platform slug.",
|
|
11081
11212
|
run: async (args, ctx) => {
|
|
11082
|
-
const dir =
|
|
11213
|
+
const dir = path26.resolve(args.positionals[0]);
|
|
11083
11214
|
const creds = credentialsForRuntime(arg.str(args, "host"));
|
|
11084
11215
|
const description = await describeLocalWorld(dir, creds);
|
|
11085
11216
|
if (arg.bool(args, "json"))
|
|
@@ -11118,7 +11249,7 @@ function registerSchemaCommands(schema) {
|
|
|
11118
11249
|
flags: [HOST_FLAG2],
|
|
11119
11250
|
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.",
|
|
11120
11251
|
run: async (args, ctx) => {
|
|
11121
|
-
const dir =
|
|
11252
|
+
const dir = path26.resolve(args.positionals[0]);
|
|
11122
11253
|
const declared = declareUi(dir);
|
|
11123
11254
|
const creds = credentialsForRuntime(arg.str(args, "host"));
|
|
11124
11255
|
const report = await runtime(creds, {
|
|
@@ -11127,7 +11258,7 @@ function registerSchemaCommands(schema) {
|
|
|
11127
11258
|
});
|
|
11128
11259
|
if (report.files?.length) writeWorldFiles(dir, report.files);
|
|
11129
11260
|
const ui = uiSection(
|
|
11130
|
-
|
|
11261
|
+
fs35.readFileSync(path26.join(dir, "connector.toml"), "utf8")
|
|
11131
11262
|
);
|
|
11132
11263
|
const staticDir = ui.static ?? "ui/static";
|
|
11133
11264
|
const files = (report.files ?? []).map((f) => f.path).filter((p) => p.startsWith(`${staticDir}/`));
|
|
@@ -11201,7 +11332,7 @@ function registerSchemaCommands(schema) {
|
|
|
11201
11332
|
}
|
|
11202
11333
|
});
|
|
11203
11334
|
}
|
|
11204
|
-
var HOST_FLAG2, UI_SECTION, WORKSPACE_PREFIX, describedOnPlatform, describedLocally;
|
|
11335
|
+
var HOST_FLAG2, UI_SECTION, WORKSPACE_PREFIX, describedOnPlatform, describedLocally, enumValue;
|
|
11205
11336
|
var init_schema = __esm({
|
|
11206
11337
|
"src/cli/runtime/schema.ts"() {
|
|
11207
11338
|
"use strict";
|
|
@@ -11231,8 +11362,9 @@ var init_schema = __esm({
|
|
|
11231
11362
|
...description,
|
|
11232
11363
|
where: "local",
|
|
11233
11364
|
path: dir,
|
|
11234
|
-
on_platform: `gateway worlds describe ${
|
|
11365
|
+
on_platform: `gateway worlds describe ${path26.basename(dir)}@main`
|
|
11235
11366
|
});
|
|
11367
|
+
enumValue = (value) => typeof value === "string" ? value : JSON.stringify(value);
|
|
11236
11368
|
}
|
|
11237
11369
|
});
|
|
11238
11370
|
|
|
@@ -11304,8 +11436,8 @@ var standingAlone = /* @__PURE__ */ new Map();
|
|
|
11304
11436
|
function standingAlonePattern(needle) {
|
|
11305
11437
|
let pattern = standingAlone.get(needle);
|
|
11306
11438
|
if (pattern === void 0) {
|
|
11307
|
-
const
|
|
11308
|
-
pattern = new RegExp(`(?<![A-Za-z0-9])${
|
|
11439
|
+
const escaped2 = needle.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
11440
|
+
pattern = new RegExp(`(?<![A-Za-z0-9])${escaped2}(?![A-Za-z0-9])`, "gi");
|
|
11309
11441
|
standingAlone.set(needle, pattern);
|
|
11310
11442
|
}
|
|
11311
11443
|
return pattern;
|
|
@@ -12814,17 +12946,17 @@ function splitTopLevel(text2) {
|
|
|
12814
12946
|
const parts2 = [];
|
|
12815
12947
|
let depth = 0;
|
|
12816
12948
|
let current = "";
|
|
12817
|
-
let
|
|
12949
|
+
let escaped2 = false;
|
|
12818
12950
|
let inClass = false;
|
|
12819
12951
|
for (const char of text2) {
|
|
12820
|
-
if (
|
|
12952
|
+
if (escaped2) {
|
|
12821
12953
|
current += char;
|
|
12822
|
-
|
|
12954
|
+
escaped2 = false;
|
|
12823
12955
|
continue;
|
|
12824
12956
|
}
|
|
12825
12957
|
if (char === "\\") {
|
|
12826
12958
|
current += char;
|
|
12827
|
-
|
|
12959
|
+
escaped2 = true;
|
|
12828
12960
|
continue;
|
|
12829
12961
|
}
|
|
12830
12962
|
if (inClass) {
|
|
@@ -12851,9 +12983,9 @@ function alternatives(raw) {
|
|
|
12851
12983
|
if (!parts2.length || parts2.includes("*")) return [];
|
|
12852
12984
|
return parts2;
|
|
12853
12985
|
}
|
|
12854
|
-
function hasPath(node,
|
|
12986
|
+
function hasPath(node, path49) {
|
|
12855
12987
|
let current = node;
|
|
12856
|
-
for (const part of
|
|
12988
|
+
for (const part of path49.split(".")) {
|
|
12857
12989
|
if (current && typeof current === "object" && !Array.isArray(current) && part in current) {
|
|
12858
12990
|
current = current[part];
|
|
12859
12991
|
continue;
|
|
@@ -12894,7 +13026,7 @@ function matches(m, event) {
|
|
|
12894
13026
|
if (m.args.length) {
|
|
12895
13027
|
const haystacks = event.event === "pre_request" || event.event === "post_response" ? [event.request?.query, event.request?.body] : [event.toolInput];
|
|
12896
13028
|
const present = haystacks.filter((h) => h !== void 0 && h !== null);
|
|
12897
|
-
if (!m.args.every((
|
|
13029
|
+
if (!m.args.every((path49) => present.some((h) => hasPath(h, path49))))
|
|
12898
13030
|
return false;
|
|
12899
13031
|
}
|
|
12900
13032
|
return true;
|
|
@@ -13760,7 +13892,7 @@ var CommandHandler = class {
|
|
|
13760
13892
|
run(event) {
|
|
13761
13893
|
const input = JSON.stringify(eventToJson(event));
|
|
13762
13894
|
const exec = this.opts.args !== void 0;
|
|
13763
|
-
return new Promise((
|
|
13895
|
+
return new Promise((resolve32, reject) => {
|
|
13764
13896
|
let child;
|
|
13765
13897
|
try {
|
|
13766
13898
|
child = exec ? spawn3(this.command, this.opts.args, {
|
|
@@ -13821,7 +13953,7 @@ var CommandHandler = class {
|
|
|
13821
13953
|
return;
|
|
13822
13954
|
}
|
|
13823
13955
|
try {
|
|
13824
|
-
|
|
13956
|
+
resolve32(
|
|
13825
13957
|
parseStdout(Buffer.concat(out).toString("utf8"), this.describe())
|
|
13826
13958
|
);
|
|
13827
13959
|
} catch (error) {
|
|
@@ -14225,7 +14357,7 @@ var Pacer = class {
|
|
|
14225
14357
|
/** Waits until the interval since the tool's last call has passed; resolves to the
|
|
14226
14358
|
* seconds waited. `sleep`/`clock` are injectable for tests. */
|
|
14227
14359
|
async wait(name, intervalMs, opts = {}) {
|
|
14228
|
-
const sleep4 = opts.sleep ?? ((seconds) => new Promise((
|
|
14360
|
+
const sleep4 = opts.sleep ?? ((seconds) => new Promise((resolve32) => setTimeout(resolve32, seconds * 1e3)));
|
|
14229
14361
|
const clock = opts.clock ?? (() => Date.now() / 1e3);
|
|
14230
14362
|
const now = clock();
|
|
14231
14363
|
const due = (this.last.get(name) ?? -Infinity) + intervalMs / 1e3;
|
|
@@ -15750,14 +15882,14 @@ var HookedSession = class {
|
|
|
15750
15882
|
* `apiHeaders()`), `pre_request` before it and `post_response` after. Returns
|
|
15751
15883
|
* `{status, body, headers}`; a 4xx/5xx is returned, not thrown, so the agent sees
|
|
15752
15884
|
* the vendor's own error shape (rewritten like any result). */
|
|
15753
|
-
async request(method,
|
|
15885
|
+
async request(method, path49, opts = {}) {
|
|
15754
15886
|
if (!this.inner.api && !this.requestFn)
|
|
15755
15887
|
throw new Error(
|
|
15756
15888
|
"this session has no api surface (pass requestFn for a transport of your own)"
|
|
15757
15889
|
);
|
|
15758
15890
|
let request = {
|
|
15759
15891
|
method: method.toUpperCase(),
|
|
15760
|
-
path:
|
|
15892
|
+
path: path49,
|
|
15761
15893
|
query: { ...opts.query ?? {} },
|
|
15762
15894
|
body: opts.body ?? null
|
|
15763
15895
|
};
|
|
@@ -17772,13 +17904,13 @@ function decodeKey(text2) {
|
|
|
17772
17904
|
var LINE_CAP = 1024 * 1024;
|
|
17773
17905
|
var refuse = (message) => new CliError(message, 1);
|
|
17774
17906
|
var isGzName = (name) => /\.gz$/i.test(name);
|
|
17775
|
-
var csvNeedsEntity = (
|
|
17776
|
-
function fileInput(
|
|
17907
|
+
var csvNeedsEntity = (path49) => `${path49} is a CSV; say which entity its columns fill with --entity (the header row names the fields; cells are cast by the entity's schema \u2014 integer, number, boolean, array, object \u2014 and an empty cell is null)`;
|
|
17908
|
+
function fileInput(path49) {
|
|
17777
17909
|
return {
|
|
17778
|
-
name:
|
|
17910
|
+
name: path49,
|
|
17779
17911
|
open: () => {
|
|
17780
|
-
const raw = fs22.createReadStream(
|
|
17781
|
-
return isGzName(
|
|
17912
|
+
const raw = fs22.createReadStream(path49);
|
|
17913
|
+
return isGzName(path49) ? raw.pipe(createGunzip()) : raw;
|
|
17782
17914
|
}
|
|
17783
17915
|
};
|
|
17784
17916
|
}
|
|
@@ -17822,8 +17954,8 @@ function openBytes(input) {
|
|
|
17822
17954
|
return new ByteReader(stream, input.name);
|
|
17823
17955
|
}
|
|
17824
17956
|
async function* readOne(input, entity, options) {
|
|
17825
|
-
const
|
|
17826
|
-
if (isDelimitedName(
|
|
17957
|
+
const path49 = input.name;
|
|
17958
|
+
if (isDelimitedName(path49)) {
|
|
17827
17959
|
yield* csvTaggedRows(input, entity, options);
|
|
17828
17960
|
return;
|
|
17829
17961
|
}
|
|
@@ -17837,30 +17969,30 @@ async function* readOne(input, entity, options) {
|
|
|
17837
17969
|
if (!opened) return;
|
|
17838
17970
|
if (opened.kind === "other")
|
|
17839
17971
|
throw refuse(
|
|
17840
|
-
`${
|
|
17972
|
+
`${path49} is neither a JSON object of entity -> rows nor an array of rows`
|
|
17841
17973
|
);
|
|
17842
17974
|
if (opened.kind === "array") {
|
|
17843
17975
|
if (entity === void 0)
|
|
17844
17976
|
throw refuse(
|
|
17845
|
-
`${
|
|
17977
|
+
`${path49} is a bare array; say which entity it holds with --entity`
|
|
17846
17978
|
);
|
|
17847
|
-
for await (const { value, where } of streamValues(opened.bytes,
|
|
17979
|
+
for await (const { value, where } of streamValues(opened.bytes, path49))
|
|
17848
17980
|
yield { entity, row: rowObject(value, where), where };
|
|
17849
17981
|
return;
|
|
17850
17982
|
}
|
|
17851
17983
|
if (opened.kind === "lines") {
|
|
17852
|
-
yield* jsonlRows(opened.lines,
|
|
17984
|
+
yield* jsonlRows(opened.lines, path49, entity);
|
|
17853
17985
|
return;
|
|
17854
17986
|
}
|
|
17855
|
-
const values = streamValues(opened.bytes,
|
|
17987
|
+
const values = streamValues(opened.bytes, path49, {
|
|
17856
17988
|
key: (key2, isArray) => {
|
|
17857
17989
|
if (!isArray)
|
|
17858
17990
|
throw refuse(
|
|
17859
|
-
`${
|
|
17991
|
+
`${path49}: ${key2} must map to an array of rows (JSONL lines are {"entity", "row"})`
|
|
17860
17992
|
);
|
|
17861
17993
|
if (entity !== void 0 && key2 !== entity)
|
|
17862
17994
|
throw refuse(
|
|
17863
|
-
`${
|
|
17995
|
+
`${path49} maps entities; drop --entity or make the file a bare array`
|
|
17864
17996
|
);
|
|
17865
17997
|
}
|
|
17866
17998
|
});
|
|
@@ -17868,29 +18000,29 @@ async function* readOne(input, entity, options) {
|
|
|
17868
18000
|
yield { entity: key2, row: rowObject(value, where), where };
|
|
17869
18001
|
}
|
|
17870
18002
|
async function* csvTaggedRows(input, entity, options) {
|
|
17871
|
-
const
|
|
17872
|
-
if (entity === void 0) throw refuse(csvNeedsEntity(
|
|
18003
|
+
const path49 = input.name;
|
|
18004
|
+
if (entity === void 0) throw refuse(csvNeedsEntity(path49));
|
|
17873
18005
|
const caster = options.casters?.(entity) ?? TEXT_CASTER;
|
|
17874
|
-
const delimiter = csvDelimiter(
|
|
18006
|
+
const delimiter = csvDelimiter(path49, options.delimiter);
|
|
17875
18007
|
for await (const { record, number } of csvRecords(
|
|
17876
18008
|
openBytes(input).remaining(),
|
|
17877
|
-
|
|
18009
|
+
path49,
|
|
17878
18010
|
delimiter
|
|
17879
18011
|
)) {
|
|
17880
|
-
const where = `${
|
|
18012
|
+
const where = `${path49}:${number}`;
|
|
17881
18013
|
yield { entity, row: caster.row(record, where), where };
|
|
17882
18014
|
}
|
|
17883
18015
|
}
|
|
17884
|
-
async function* streamValues(bytes,
|
|
18016
|
+
async function* streamValues(bytes, path49, hooks = {}) {
|
|
17885
18017
|
const queue = [];
|
|
17886
|
-
const whereOf = (key2, index2) => key2 === null ? `${
|
|
18018
|
+
const whereOf = (key2, index2) => key2 === null ? `${path49}[${index2}]` : `${path49}:${key2}[${index2}]`;
|
|
17887
18019
|
const scanner = new TopLevelScanner({
|
|
17888
18020
|
key: (key2, isArray) => hooks.key?.(key2, isArray),
|
|
17889
18021
|
element: (key2, text2, index2) => {
|
|
17890
18022
|
const where = whereOf(key2, index2);
|
|
17891
18023
|
queue.push({ key: key2, value: parseElement(text2, where), index: index2, where });
|
|
17892
18024
|
},
|
|
17893
|
-
other: (key2, text2) => hooks.other?.(key2, parseElement(text2, `${
|
|
18025
|
+
other: (key2, text2) => hooks.other?.(key2, parseElement(text2, `${path49}:${key2}`))
|
|
17894
18026
|
});
|
|
17895
18027
|
try {
|
|
17896
18028
|
for await (const chunk of bytes) {
|
|
@@ -17901,7 +18033,7 @@ async function* streamValues(bytes, path44, hooks = {}) {
|
|
|
17901
18033
|
} catch (error) {
|
|
17902
18034
|
if (error instanceof ScanError)
|
|
17903
18035
|
throw refuse(
|
|
17904
|
-
`${error.open ? whereOf(error.open.key, error.open.index) :
|
|
18036
|
+
`${error.open ? whereOf(error.open.key, error.open.index) : path49}: not valid JSON`
|
|
17905
18037
|
);
|
|
17906
18038
|
throw error;
|
|
17907
18039
|
}
|
|
@@ -17914,7 +18046,7 @@ function parseElement(text2, where) {
|
|
|
17914
18046
|
throw refuse(`${where}: not valid JSON`);
|
|
17915
18047
|
}
|
|
17916
18048
|
}
|
|
17917
|
-
async function* jsonlRows(lines,
|
|
18049
|
+
async function* jsonlRows(lines, path49, entity) {
|
|
17918
18050
|
let number = 0;
|
|
17919
18051
|
for await (const raw of lines) {
|
|
17920
18052
|
number++;
|
|
@@ -17924,9 +18056,9 @@ async function* jsonlRows(lines, path44, entity) {
|
|
|
17924
18056
|
try {
|
|
17925
18057
|
item = parseJson(line);
|
|
17926
18058
|
} catch {
|
|
17927
|
-
throw refuse(`${
|
|
18059
|
+
throw refuse(`${path49}:${number} is not JSON`);
|
|
17928
18060
|
}
|
|
17929
|
-
const where = `${
|
|
18061
|
+
const where = `${path49}:${number}`;
|
|
17930
18062
|
if (entity !== void 0) {
|
|
17931
18063
|
yield { entity, row: rowObject(item, where), where };
|
|
17932
18064
|
continue;
|
|
@@ -17950,8 +18082,8 @@ var isWs = (c) => c === 32 || c === 10 || c === 13 || c === 9;
|
|
|
17950
18082
|
var BOM = Buffer.from([239, 187, 191]);
|
|
17951
18083
|
var ByteReader = class {
|
|
17952
18084
|
// bytes of leading whitespace (and a BOM) already skipped
|
|
17953
|
-
constructor(stream,
|
|
17954
|
-
this.path =
|
|
18085
|
+
constructor(stream, path49) {
|
|
18086
|
+
this.path = path49;
|
|
17955
18087
|
this.iterator = stream[Symbol.asyncIterator]();
|
|
17956
18088
|
}
|
|
17957
18089
|
path;
|
|
@@ -18048,9 +18180,9 @@ var ByteReader = class {
|
|
|
18048
18180
|
// src/cli/platform/rows.ts
|
|
18049
18181
|
function parseRows(paths, entity, options = {}) {
|
|
18050
18182
|
const rows = {};
|
|
18051
|
-
for (const
|
|
18052
|
-
const text2 = readText(
|
|
18053
|
-
const parsed = isDelimitedName(
|
|
18183
|
+
for (const path49 of paths) {
|
|
18184
|
+
const text2 = readText(path49);
|
|
18185
|
+
const parsed = isDelimitedName(path49) ? csvRowsIn(text2, path49, entity, options) : rowsIn(text2, path49, entity);
|
|
18054
18186
|
for (const [name, listed2] of Object.entries(parsed)) {
|
|
18055
18187
|
(rows[name] ??= []).push(...listed2);
|
|
18056
18188
|
}
|
|
@@ -18060,32 +18192,32 @@ function parseRows(paths, entity, options = {}) {
|
|
|
18060
18192
|
function refuse2(message) {
|
|
18061
18193
|
return new CliError(message, 1);
|
|
18062
18194
|
}
|
|
18063
|
-
function readText(
|
|
18195
|
+
function readText(path49) {
|
|
18064
18196
|
try {
|
|
18065
|
-
const bytes = fs23.readFileSync(
|
|
18066
|
-
return (isGzName(
|
|
18197
|
+
const bytes = fs23.readFileSync(path49);
|
|
18198
|
+
return (isGzName(path49) ? gunzipSync2(bytes) : bytes).toString("utf8");
|
|
18067
18199
|
} catch {
|
|
18068
|
-
throw refuse2(`Cannot read ${
|
|
18200
|
+
throw refuse2(`Cannot read ${path49} as UTF-8 text`);
|
|
18069
18201
|
}
|
|
18070
18202
|
}
|
|
18071
|
-
function csvRowsIn(text2,
|
|
18072
|
-
if (entity === void 0) throw refuse2(csvNeedsEntity(
|
|
18203
|
+
function csvRowsIn(text2, path49, entity, options) {
|
|
18204
|
+
if (entity === void 0) throw refuse2(csvNeedsEntity(path49));
|
|
18073
18205
|
const caster = options.casters?.(entity) ?? TEXT_CASTER;
|
|
18074
|
-
const records2 = parseCsv(text2,
|
|
18206
|
+
const records2 = parseCsv(text2, path49, csvDelimiter(path49, options.delimiter));
|
|
18075
18207
|
return {
|
|
18076
18208
|
[entity]: records2.map(
|
|
18077
|
-
(record, index2) => plainValue(caster.row(record, `${
|
|
18209
|
+
(record, index2) => plainValue(caster.row(record, `${path49}:${index2 + 2}`))
|
|
18078
18210
|
)
|
|
18079
18211
|
};
|
|
18080
18212
|
}
|
|
18081
|
-
function rowsIn(text2,
|
|
18213
|
+
function rowsIn(text2, path49, entity) {
|
|
18082
18214
|
const stripped = text2.trim();
|
|
18083
18215
|
if (!stripped) return {};
|
|
18084
18216
|
let document;
|
|
18085
18217
|
try {
|
|
18086
18218
|
document = JSON.parse(stripped);
|
|
18087
18219
|
} catch {
|
|
18088
|
-
return jsonlRows2(stripped,
|
|
18220
|
+
return jsonlRows2(stripped, path49, entity);
|
|
18089
18221
|
}
|
|
18090
18222
|
if (isObject8(document)) {
|
|
18091
18223
|
if (entity !== void 0) {
|
|
@@ -18093,20 +18225,20 @@ function rowsIn(text2, path44, entity) {
|
|
|
18093
18225
|
if (keys.length === 1 && keys[0] === entity && Array.isArray(document[entity])) {
|
|
18094
18226
|
return {
|
|
18095
18227
|
[entity]: document[entity].map(
|
|
18096
|
-
(row, i) => rowObject2(row, `${
|
|
18228
|
+
(row, i) => rowObject2(row, `${path49}:${entity}[${i}]`)
|
|
18097
18229
|
)
|
|
18098
18230
|
};
|
|
18099
18231
|
}
|
|
18100
|
-
return jsonlRows2(stripped,
|
|
18232
|
+
return jsonlRows2(stripped, path49, entity);
|
|
18101
18233
|
}
|
|
18102
18234
|
const out = {};
|
|
18103
18235
|
for (const [name, listed2] of Object.entries(document)) {
|
|
18104
18236
|
if (!Array.isArray(listed2))
|
|
18105
18237
|
throw refuse2(
|
|
18106
|
-
`${
|
|
18238
|
+
`${path49}: ${name} must map to an array of rows (JSONL lines are {"entity", "row"})`
|
|
18107
18239
|
);
|
|
18108
18240
|
out[name] = listed2.map(
|
|
18109
|
-
(row, index2) => rowObject2(row, `${
|
|
18241
|
+
(row, index2) => rowObject2(row, `${path49}:${name}[${index2}]`)
|
|
18110
18242
|
);
|
|
18111
18243
|
}
|
|
18112
18244
|
return out;
|
|
@@ -18114,19 +18246,19 @@ function rowsIn(text2, path44, entity) {
|
|
|
18114
18246
|
if (Array.isArray(document)) {
|
|
18115
18247
|
if (entity === void 0)
|
|
18116
18248
|
throw refuse2(
|
|
18117
|
-
`${
|
|
18249
|
+
`${path49} is a bare array; say which entity it holds with --entity`
|
|
18118
18250
|
);
|
|
18119
18251
|
return {
|
|
18120
18252
|
[entity]: document.map(
|
|
18121
|
-
(row, index2) => rowObject2(row, `${
|
|
18253
|
+
(row, index2) => rowObject2(row, `${path49}[${index2}]`)
|
|
18122
18254
|
)
|
|
18123
18255
|
};
|
|
18124
18256
|
}
|
|
18125
18257
|
throw refuse2(
|
|
18126
|
-
`${
|
|
18258
|
+
`${path49} is neither a JSON object of entity -> rows nor an array of rows`
|
|
18127
18259
|
);
|
|
18128
18260
|
}
|
|
18129
|
-
function jsonlRows2(text2,
|
|
18261
|
+
function jsonlRows2(text2, path49, entity) {
|
|
18130
18262
|
const out = {};
|
|
18131
18263
|
const lines = text2.split(/\r?\n/);
|
|
18132
18264
|
for (let index2 = 0; index2 < lines.length; index2++) {
|
|
@@ -18137,9 +18269,9 @@ function jsonlRows2(text2, path44, entity) {
|
|
|
18137
18269
|
try {
|
|
18138
18270
|
item = JSON.parse(line);
|
|
18139
18271
|
} catch {
|
|
18140
|
-
throw refuse2(`${
|
|
18272
|
+
throw refuse2(`${path49}:${number} is not JSON`);
|
|
18141
18273
|
}
|
|
18142
|
-
const where = `${
|
|
18274
|
+
const where = `${path49}:${number}`;
|
|
18143
18275
|
if (entity !== void 0) {
|
|
18144
18276
|
(out[entity] ??= []).push(rowObject2(item, where));
|
|
18145
18277
|
continue;
|
|
@@ -19434,12 +19566,12 @@ function registerBenchCommands(root) {
|
|
|
19434
19566
|
const creds = credentials(args);
|
|
19435
19567
|
const runId = arg.str(args, "run");
|
|
19436
19568
|
if (runId) {
|
|
19437
|
-
const
|
|
19569
|
+
const one2 = await api(
|
|
19438
19570
|
creds,
|
|
19439
19571
|
"GET",
|
|
19440
19572
|
`/api/public/worlds/${encodeURIComponent(slug)}/tests/${encodeURIComponent(runId)}`
|
|
19441
19573
|
);
|
|
19442
|
-
printJson(ctx,
|
|
19574
|
+
printJson(ctx, one2.run);
|
|
19443
19575
|
return 0;
|
|
19444
19576
|
}
|
|
19445
19577
|
const limit = arg.int(args, "limit");
|
|
@@ -19576,8 +19708,8 @@ init_config();
|
|
|
19576
19708
|
init_router();
|
|
19577
19709
|
init_hub();
|
|
19578
19710
|
init_worlds();
|
|
19579
|
-
import * as
|
|
19580
|
-
import * as
|
|
19711
|
+
import * as fs37 from "fs";
|
|
19712
|
+
import * as path28 from "path";
|
|
19581
19713
|
|
|
19582
19714
|
// src/benchmarks/index.ts
|
|
19583
19715
|
init_worldDir();
|
|
@@ -20654,9 +20786,9 @@ async function hostedDryRun(args, ctx, creds, pushDir) {
|
|
|
20654
20786
|
ctx.stderr(
|
|
20655
20787
|
`target ${target.slug}${target.ref ? `@${target.ref}` : ""} (${target.source}) \xB7 task ${task} \xB7 hosted, harbor oracle`
|
|
20656
20788
|
);
|
|
20657
|
-
const
|
|
20789
|
+
const client5 = new HostedDryRunClient(worldsOptions(creds));
|
|
20658
20790
|
const containerId = target.containerId ?? await resolveEnvironmentId(creds, target.slug);
|
|
20659
|
-
const dispatched = await
|
|
20791
|
+
const dispatched = await client5.dispatch({
|
|
20660
20792
|
containerId,
|
|
20661
20793
|
task,
|
|
20662
20794
|
...listed2.versionId ? { versionId: listed2.versionId } : {}
|
|
@@ -20668,7 +20800,7 @@ async function hostedDryRun(args, ctx, creds, pushDir) {
|
|
|
20668
20800
|
return 0;
|
|
20669
20801
|
}
|
|
20670
20802
|
const timeoutSeconds = arg.int(args, "wait-timeout") ?? 1200;
|
|
20671
|
-
const verdict = await
|
|
20803
|
+
const verdict = await client5.settle(dispatched.runId, {
|
|
20672
20804
|
timeoutSeconds,
|
|
20673
20805
|
onProgress: (v) => ctx.stderr(`# ${dispatched.task}: ${progressLine(v)}`)
|
|
20674
20806
|
});
|
|
@@ -20917,14 +21049,92 @@ function printProvider(ctx, providers, only) {
|
|
|
20917
21049
|
|
|
20918
21050
|
// src/cli/platform/benchmarks.ts
|
|
20919
21051
|
init_client();
|
|
21052
|
+
|
|
21053
|
+
// src/cli/runtime/scaffoldVerifiers.ts
|
|
21054
|
+
init_router();
|
|
21055
|
+
import * as fs30 from "fs";
|
|
21056
|
+
import * as path21 from "path";
|
|
21057
|
+
var SCAFFOLD_VERIFIER = /^-- Scores 1\.0 once the world holds any (\S+) row; edit for real tasks\.\n/;
|
|
21058
|
+
function scaffoldVerifier(entity) {
|
|
21059
|
+
return `-- Scores 1.0 once the world holds any ${entity} row; edit for real tasks.
|
|
21060
|
+
-- It names the ${entity} entity: rename or remove that entity and \`gateway worlds schema check\`
|
|
21061
|
+
-- refuses this file until the FROM is edited or the file is deleted with it.
|
|
21062
|
+
SELECT CASE WHEN COUNT(*) > 0 THEN 1.0 ELSE 0.0 END FROM "${entity}";
|
|
21063
|
+
`;
|
|
21064
|
+
}
|
|
21065
|
+
function scaffoldVerifierEntity(file) {
|
|
21066
|
+
if (!fs30.existsSync(file)) return void 0;
|
|
21067
|
+
const text2 = fs30.readFileSync(file, "utf8");
|
|
21068
|
+
const entity = SCAFFOLD_VERIFIER.exec(text2)?.[1];
|
|
21069
|
+
return entity !== void 0 && text2 === scaffoldVerifier(entity) ? entity : void 0;
|
|
21070
|
+
}
|
|
21071
|
+
function verifierNames(dir) {
|
|
21072
|
+
const folder = path21.join(dir, "verifiers");
|
|
21073
|
+
if (!fs30.existsSync(folder)) return void 0;
|
|
21074
|
+
return fs30.readdirSync(folder).filter((f) => f.endsWith(".sql")).map((f) => f.slice(0, -4)).sort();
|
|
21075
|
+
}
|
|
21076
|
+
function verifierSql(name, entity, where) {
|
|
21077
|
+
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)}`);
|
|
21078
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(entity)) throw new CliError(`Entity names match [A-Za-z_][A-Za-z0-9_]*, got ${JSON.stringify(entity)}`);
|
|
21079
|
+
if (where === void 0) return scaffoldVerifier(entity);
|
|
21080
|
+
const clause = where.trim();
|
|
21081
|
+
if (!clause) throw new CliError("--where is a SQL condition over the entity's columns; it cannot be empty");
|
|
21082
|
+
const defect = whereClauseDefect(clause);
|
|
21083
|
+
if (defect)
|
|
21084
|
+
throw new CliError(
|
|
21085
|
+
`--where ${JSON.stringify(clause)} cannot be a SQL condition: ${defect}. The file would fail \`gateway worlds schema check\` at once; fix the condition here instead.`
|
|
21086
|
+
);
|
|
21087
|
+
return `-- ${name}: scores 1.0 once a ${entity} row satisfies the condition; edit for real tasks.
|
|
21088
|
+
-- A verifier is one SQL statement returning one number in 0..1 (0.5 is partial credit).
|
|
21089
|
+
SELECT CASE WHEN COUNT(*) > 0 THEN 1.0 ELSE 0.0 END FROM "${entity}" WHERE ${clause};
|
|
21090
|
+
`;
|
|
21091
|
+
}
|
|
21092
|
+
function whereClauseDefect(clause) {
|
|
21093
|
+
let depth = 0;
|
|
21094
|
+
let quote;
|
|
21095
|
+
for (const ch of clause) {
|
|
21096
|
+
if (quote) {
|
|
21097
|
+
if (ch === quote) quote = void 0;
|
|
21098
|
+
continue;
|
|
21099
|
+
}
|
|
21100
|
+
if (ch === "'" || ch === '"') quote = ch;
|
|
21101
|
+
else if (ch === "(") depth += 1;
|
|
21102
|
+
else if (ch === ")") depth -= 1;
|
|
21103
|
+
else if (ch === ";") return "a `;` would end the statement early; a verifier is one SQL statement";
|
|
21104
|
+
if (depth < 0) return "a `)` closes a parenthesis that was never opened";
|
|
21105
|
+
}
|
|
21106
|
+
if (quote) return `a ${quote} quote is never closed`;
|
|
21107
|
+
if (depth > 0) return `${depth} parenthes${depth === 1 ? "is is" : "es are"} never closed`;
|
|
21108
|
+
if (/(?:^|[\s(])(?:AND|OR|NOT|IN|IS|LIKE|BETWEEN)$/i.test(clause) || /[=<>!+\-*/,(]$/.test(clause))
|
|
21109
|
+
return "it ends in an operator with nothing after it";
|
|
21110
|
+
return void 0;
|
|
21111
|
+
}
|
|
21112
|
+
function addVerifier(dir, name, entity, where) {
|
|
21113
|
+
const sql = verifierSql(name, entity, where);
|
|
21114
|
+
const file = path21.join(dir, "verifiers", `${name}.sql`);
|
|
21115
|
+
if (fs30.existsSync(file))
|
|
21116
|
+
throw new CliError(`verifiers/${name}.sql already exists (have: ${(verifierNames(dir) ?? []).join(", ")}); edit it, or pick another name`);
|
|
21117
|
+
fs30.mkdirSync(path21.dirname(file), { recursive: true });
|
|
21118
|
+
fs30.writeFileSync(file, sql);
|
|
21119
|
+
return file;
|
|
21120
|
+
}
|
|
21121
|
+
function repointScaffoldVerifier(dir, entity, declared) {
|
|
21122
|
+
const file = path21.join(dir, "verifiers", "state_present.sql");
|
|
21123
|
+
const named2 = scaffoldVerifierEntity(file);
|
|
21124
|
+
if (named2 === void 0 || declared.includes(named2)) return null;
|
|
21125
|
+
fs30.writeFileSync(file, scaffoldVerifier(entity));
|
|
21126
|
+
return file;
|
|
21127
|
+
}
|
|
21128
|
+
|
|
21129
|
+
// src/cli/platform/benchmarks.ts
|
|
20920
21130
|
init_local();
|
|
20921
21131
|
init_shared();
|
|
20922
21132
|
|
|
20923
21133
|
// src/cli/platform/worlds.ts
|
|
20924
21134
|
init_config();
|
|
20925
21135
|
init_router();
|
|
20926
|
-
import * as
|
|
20927
|
-
import * as
|
|
21136
|
+
import * as fs36 from "fs";
|
|
21137
|
+
import * as path27 from "path";
|
|
20928
21138
|
init_describe();
|
|
20929
21139
|
init_hub();
|
|
20930
21140
|
init_migrate();
|
|
@@ -20934,8 +21144,8 @@ init_shared();
|
|
|
20934
21144
|
// src/cli/worldTarget.ts
|
|
20935
21145
|
init_hub();
|
|
20936
21146
|
init_router();
|
|
20937
|
-
import
|
|
20938
|
-
import
|
|
21147
|
+
import fs32 from "fs";
|
|
21148
|
+
import path23 from "path";
|
|
20939
21149
|
var WorldTarget = class _WorldTarget {
|
|
20940
21150
|
constructor(token, side, slug, ref, dir) {
|
|
20941
21151
|
this.token = token;
|
|
@@ -20960,7 +21170,7 @@ var WorldTarget = class _WorldTarget {
|
|
|
20960
21170
|
if (_WorldTarget.isPathShaped(token)) {
|
|
20961
21171
|
if (!exists(token)) throw new CliError(`${token} is not a directory here`);
|
|
20962
21172
|
if (typed.length > 0) throw new CliError(hostedOnlyMessage(token, typed));
|
|
20963
|
-
return new _WorldTarget(token, "local",
|
|
21173
|
+
return new _WorldTarget(token, "local", path23.basename(path23.resolve(token)), void 0, path23.resolve(token));
|
|
20964
21174
|
}
|
|
20965
21175
|
if (!exists(token)) return new _WorldTarget(token, "hosted", token, void 0, void 0);
|
|
20966
21176
|
if (typed.length > 0) throw new CliError(hostedOnlyMessage(token, typed));
|
|
@@ -20970,7 +21180,7 @@ var WorldTarget = class _WorldTarget {
|
|
|
20970
21180
|
}
|
|
20971
21181
|
/** `.`, `..`, `./x`, `/abs`, `~/x`, `a/b`, `a\\b` name a path, never a slug. */
|
|
20972
21182
|
static isPathShaped(token) {
|
|
20973
|
-
return token.startsWith(".") || token.startsWith("~") || /[\\/]/.test(token) ||
|
|
21183
|
+
return token.startsWith(".") || token.startsWith("~") || /[\\/]/.test(token) || path23.isAbsolute(token);
|
|
20974
21184
|
}
|
|
20975
21185
|
get isLocal() {
|
|
20976
21186
|
return this.side === "local";
|
|
@@ -20978,21 +21188,21 @@ var WorldTarget = class _WorldTarget {
|
|
|
20978
21188
|
};
|
|
20979
21189
|
function hostedOnlyMessage(token, typed) {
|
|
20980
21190
|
const flags = typed.map((flag) => `--${flag}`).join(", ");
|
|
20981
|
-
const slug = readLocalMeta(token)?.slug ??
|
|
21191
|
+
const slug = readLocalMeta(token)?.slug ?? path23.basename(path23.resolve(token));
|
|
20982
21192
|
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.`;
|
|
20983
21193
|
}
|
|
20984
|
-
var isDirectory = (p) =>
|
|
21194
|
+
var isDirectory = (p) => fs32.existsSync(p) && fs32.statSync(p).isDirectory();
|
|
20985
21195
|
|
|
20986
21196
|
// src/cli/platform/worlds.ts
|
|
20987
21197
|
var WORLDS2 = "/api/public/worlds";
|
|
20988
21198
|
function collectFiles(directory) {
|
|
20989
|
-
if (!
|
|
21199
|
+
if (!fs36.existsSync(directory) || !fs36.statSync(directory).isDirectory())
|
|
20990
21200
|
throw new CliError(`${directory}: not a directory`, 1);
|
|
20991
|
-
return walk(directory).map((
|
|
20992
|
-
const bytes =
|
|
21201
|
+
return walk(directory).map((relative6) => {
|
|
21202
|
+
const bytes = fs36.readFileSync(path27.join(directory, relative6));
|
|
20993
21203
|
const text2 = bytes.toString("utf8");
|
|
20994
|
-
return Buffer.from(text2, "utf8").equals(bytes) && !text2.includes("\uFFFD") ? { path:
|
|
20995
|
-
path:
|
|
21204
|
+
return Buffer.from(text2, "utf8").equals(bytes) && !text2.includes("\uFFFD") ? { path: relative6, content: text2 } : {
|
|
21205
|
+
path: relative6,
|
|
20996
21206
|
content: bytes.toString("base64"),
|
|
20997
21207
|
encoding: "base64"
|
|
20998
21208
|
};
|
|
@@ -21007,7 +21217,7 @@ async function describeLocalDirectory(dir, hostFlag) {
|
|
|
21007
21217
|
const counts = await showLocalWorldData2(dir, void 0, creds);
|
|
21008
21218
|
return describedLocally2(withRowCounts2(description, counts.entity_counts ?? {}), dir);
|
|
21009
21219
|
}
|
|
21010
|
-
var isDir = (candidate) =>
|
|
21220
|
+
var isDir = (candidate) => fs36.existsSync(candidate) && fs36.statSync(candidate).isDirectory();
|
|
21011
21221
|
function worldTreeFiles(from) {
|
|
21012
21222
|
if (classifyTree(from).shape !== "none") return collectFiles(from);
|
|
21013
21223
|
const files = collectFiles(from);
|
|
@@ -21115,7 +21325,7 @@ async function createOne(creds, body) {
|
|
|
21115
21325
|
return api(creds, "POST", WORLDS2, body, { timeoutMs: 6e5 });
|
|
21116
21326
|
}
|
|
21117
21327
|
async function runBatch(file, args, ctx) {
|
|
21118
|
-
const text2 = file === "-" ?
|
|
21328
|
+
const text2 = file === "-" ? fs36.readFileSync(0, "utf8") : fs36.readFileSync(file, "utf8");
|
|
21119
21329
|
const requests = text2.split("\n").map((line) => line.trim()).filter(Boolean).map(batchLine);
|
|
21120
21330
|
if (requests.length === 0)
|
|
21121
21331
|
throw new CliError("batch file holds no worlds", 1);
|
|
@@ -21382,7 +21592,7 @@ function refuseKind(dir, classified, wanted, command2) {
|
|
|
21382
21592
|
);
|
|
21383
21593
|
}
|
|
21384
21594
|
function resolveKind(dir, args, command2) {
|
|
21385
|
-
if (!
|
|
21595
|
+
if (!fs37.existsSync(dir) || !fs37.statSync(dir).isDirectory()) throw new CliError(`Not a directory: ${dir}`, 1);
|
|
21386
21596
|
const classified = classifyTree(dir);
|
|
21387
21597
|
const actual = kindOfTree(classified);
|
|
21388
21598
|
const wanted = arg.str(args, "kind");
|
|
@@ -21392,7 +21602,7 @@ function resolveKind(dir, args, command2) {
|
|
|
21392
21602
|
}
|
|
21393
21603
|
function firstEntity(dir) {
|
|
21394
21604
|
try {
|
|
21395
|
-
const world = JSON.parse(
|
|
21605
|
+
const world = JSON.parse(fs37.readFileSync(path28.join(dir, "schema", "world.json"), "utf8"));
|
|
21396
21606
|
const entities = world["x-gateway"]?.entities ?? world.entities;
|
|
21397
21607
|
if (Array.isArray(entities)) return entities[0]?.name ?? null;
|
|
21398
21608
|
if (entities && typeof entities === "object") return Object.keys(entities)[0] ?? null;
|
|
@@ -21400,22 +21610,17 @@ function firstEntity(dir) {
|
|
|
21400
21610
|
}
|
|
21401
21611
|
return null;
|
|
21402
21612
|
}
|
|
21403
|
-
function verifierNames(dir) {
|
|
21404
|
-
const folder = path27.join(dir, "verifiers");
|
|
21405
|
-
if (!fs36.existsSync(folder)) return [];
|
|
21406
|
-
return fs36.readdirSync(folder).filter((f) => f.endsWith(".sql")).map((f) => f.slice(0, -4)).sort();
|
|
21407
|
-
}
|
|
21408
21613
|
function readConfig2(dir) {
|
|
21409
|
-
const file =
|
|
21410
|
-
if (!
|
|
21614
|
+
const file = path28.join(dir, BENCHMARK_CONFIG2);
|
|
21615
|
+
if (!fs37.existsSync(file)) return {};
|
|
21411
21616
|
try {
|
|
21412
|
-
return JSON.parse(
|
|
21617
|
+
return JSON.parse(fs37.readFileSync(file, "utf8"));
|
|
21413
21618
|
} catch {
|
|
21414
21619
|
throw new CliError(`${file} is not JSON`, 1);
|
|
21415
21620
|
}
|
|
21416
21621
|
}
|
|
21417
21622
|
function writeConfig2(dir, config) {
|
|
21418
|
-
|
|
21623
|
+
fs37.writeFileSync(path28.join(dir, BENCHMARK_CONFIG2), JSON.stringify({ ...config, note: "Defaults for `gateway benchmarks run` when --model / --rollouts are not given." }, null, 2) + "\n");
|
|
21419
21624
|
}
|
|
21420
21625
|
function printValidation(ctx, report) {
|
|
21421
21626
|
ctx.stdout(`${report.dir}: ${report.kind} benchmark \u2014 runner reads it as ${report.detectedKind} \u2014 ${report.ok ? "ok" : `${report.problems.length + report.tasks.reduce((n, t) => n + t.problems.length, 0)} problem(s)`}`);
|
|
@@ -21498,7 +21703,7 @@ async function dryRunWorld(dir, task, opts = {}) {
|
|
|
21498
21703
|
};
|
|
21499
21704
|
if (!local)
|
|
21500
21705
|
return { ...base, note: `not executed: ${opts.plan ? "--plan" : localRuntimeReason() || "no bundled runtime"} \u2014 the steps above are what would run. ${base.note}` };
|
|
21501
|
-
const payload = await localBridge({ command: "dry-run", world:
|
|
21706
|
+
const payload = await localBridge({ command: "dry-run", world: path28.resolve(dir), task }, local);
|
|
21502
21707
|
const detail = detailFrom(payload);
|
|
21503
21708
|
if (detail) throw new BridgeRejected(detail);
|
|
21504
21709
|
const answer = payload;
|
|
@@ -21595,11 +21800,11 @@ proposals: \`gateway bench\`. Walkthrough: \`gateway worlds skill ${BENCHMARKS_S
|
|
|
21595
21800
|
"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).",
|
|
21596
21801
|
2
|
|
21597
21802
|
);
|
|
21598
|
-
if (
|
|
21803
|
+
if (fs37.existsSync(dir) && fs37.readdirSync(dir).length > 0)
|
|
21599
21804
|
throw new CliError(`${dir} is not empty; init writes a fresh ${kind} tree`, 1);
|
|
21600
21805
|
const models = arg.list(args, "model");
|
|
21601
21806
|
const rollouts = arg.int(args, "rollouts") ?? 1;
|
|
21602
|
-
const slug =
|
|
21807
|
+
const slug = path28.basename(path28.resolve(dir));
|
|
21603
21808
|
if (kind === "harbor") {
|
|
21604
21809
|
const scaffold = writeHarborScaffold(dir, {
|
|
21605
21810
|
name: arg.str(args, "name"),
|
|
@@ -21645,17 +21850,12 @@ proposals: \`gateway bench\`. Walkthrough: \`gateway worlds skill ${BENCHMARKS_S
|
|
|
21645
21850
|
if (host) initArgs.push("--host", host);
|
|
21646
21851
|
const init2 = await captureSub(root, initArgs, ctx);
|
|
21647
21852
|
if (init2.code !== 0) return init2.code;
|
|
21648
|
-
let verifiers = verifierNames(dir);
|
|
21853
|
+
let verifiers = verifierNames(dir) ?? [];
|
|
21649
21854
|
if (verifiers.length === 0) {
|
|
21650
21855
|
const entity = firstEntity(dir);
|
|
21651
21856
|
if (!entity) throw new CliError(`${dir}: schema/world.json declares no entity to write a verifier for`, 1);
|
|
21652
|
-
|
|
21653
|
-
|
|
21654
|
-
path27.join(dir, "verifiers", "state_present.sql"),
|
|
21655
|
-
`-- Scores 1.0 once the world holds any ${entity} row; edit for real tasks.
|
|
21656
|
-
SELECT CASE WHEN COUNT(*) > 0 THEN 1.0 ELSE 0.0 END FROM "${entity}";
|
|
21657
|
-
`
|
|
21658
|
-
);
|
|
21857
|
+
fs37.mkdirSync(path28.join(dir, "verifiers"), { recursive: true });
|
|
21858
|
+
fs37.writeFileSync(path28.join(dir, "verifiers", "state_present.sql"), scaffoldVerifier(entity));
|
|
21659
21859
|
verifiers = ["state_present"];
|
|
21660
21860
|
}
|
|
21661
21861
|
const taskId = arg.str(args, "task") ?? "first_task";
|
|
@@ -21910,7 +22110,7 @@ before anything is sent); dispatch again for more. Never set max_tokens on the m
|
|
|
21910
22110
|
const dirFlag = arg.str(args, "dir");
|
|
21911
22111
|
const config = dirFlag ? readConfig2(dirFlag) : {};
|
|
21912
22112
|
if (dirFlag) {
|
|
21913
|
-
const owner = config.slug ??
|
|
22113
|
+
const owner = config.slug ?? path28.basename(path28.resolve(dirFlag));
|
|
21914
22114
|
if (owner !== slug)
|
|
21915
22115
|
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);
|
|
21916
22116
|
}
|
|
@@ -21944,7 +22144,7 @@ before anything is sent); dispatch again for more. Never set max_tokens on the m
|
|
|
21944
22144
|
const dir = args.positionals[0];
|
|
21945
22145
|
const from = arg.str(args, "from");
|
|
21946
22146
|
if (from !== "harbor" && from !== "verifiers") throw new CliError("benchmarks import needs --from harbor|verifiers");
|
|
21947
|
-
if (!
|
|
22147
|
+
if (!fs37.existsSync(dir) || !fs37.statSync(dir).isDirectory()) throw new CliError(`Not a directory: ${dir}`, 1);
|
|
21948
22148
|
const report = importReport(dir, from);
|
|
21949
22149
|
if (arg.bool(args, "json")) printJson(ctx, report);
|
|
21950
22150
|
else {
|
|
@@ -21962,13 +22162,408 @@ before anything is sent); dispatch again for more. Never set max_tokens on the m
|
|
|
21962
22162
|
// src/cli/platform/index.ts
|
|
21963
22163
|
init_connector();
|
|
21964
22164
|
|
|
22165
|
+
// src/cli/platform/dashboards.ts
|
|
22166
|
+
init_config();
|
|
22167
|
+
init_router();
|
|
22168
|
+
init_checkoutTarget();
|
|
22169
|
+
import { execFile } from "child_process";
|
|
22170
|
+
import * as fs39 from "fs";
|
|
22171
|
+
import * as path30 from "path";
|
|
22172
|
+
|
|
22173
|
+
// src/cli/platform/dashboards/dashboardClient.ts
|
|
22174
|
+
init_config();
|
|
22175
|
+
init_shared();
|
|
22176
|
+
var one = (id) => `/api/public/dashboards/${encodeURIComponent(id)}`;
|
|
22177
|
+
var DashboardClient = class {
|
|
22178
|
+
constructor(creds) {
|
|
22179
|
+
this.creds = creds;
|
|
22180
|
+
}
|
|
22181
|
+
creds;
|
|
22182
|
+
list(limit) {
|
|
22183
|
+
return api(this.creds, "GET", `/api/public/dashboards${query({ limit })}`);
|
|
22184
|
+
}
|
|
22185
|
+
create(body) {
|
|
22186
|
+
return api(this.creds, "POST", "/api/public/dashboards", body);
|
|
22187
|
+
}
|
|
22188
|
+
pull(id) {
|
|
22189
|
+
return api(this.creds, "GET", `${one(id)}`);
|
|
22190
|
+
}
|
|
22191
|
+
push(id, body) {
|
|
22192
|
+
return api(this.creds, "PUT", `${one(id)}/code`, body);
|
|
22193
|
+
}
|
|
22194
|
+
testTransform(id, body) {
|
|
22195
|
+
return api(this.creds, "POST", `${one(id)}/test-transform`, body);
|
|
22196
|
+
}
|
|
22197
|
+
render(id, body) {
|
|
22198
|
+
return api(this.creds, "POST", `${one(id)}/render`, body);
|
|
22199
|
+
}
|
|
22200
|
+
};
|
|
22201
|
+
|
|
22202
|
+
// src/cli/platform/dashboards/dashboardDir.ts
|
|
22203
|
+
init_router();
|
|
22204
|
+
import { createHash as createHash13 } from "crypto";
|
|
22205
|
+
import * as fs38 from "fs";
|
|
22206
|
+
import * as path29 from "path";
|
|
22207
|
+
var DASHBOARD_MANIFEST = "gateway-dashboard.json";
|
|
22208
|
+
var RENDER_DIR = "render";
|
|
22209
|
+
var TRANSFORM_FILE = "transform.js";
|
|
22210
|
+
var sha2562 = (text2) => createHash13("sha256").update(text2, "utf8").digest("hex");
|
|
22211
|
+
var DashboardDir = class _DashboardDir {
|
|
22212
|
+
constructor(root, manifest) {
|
|
22213
|
+
this.root = root;
|
|
22214
|
+
this.manifest = manifest;
|
|
22215
|
+
}
|
|
22216
|
+
root;
|
|
22217
|
+
manifest;
|
|
22218
|
+
static at(root) {
|
|
22219
|
+
return new _DashboardDir(path29.resolve(root), _DashboardDir.readManifest(root));
|
|
22220
|
+
}
|
|
22221
|
+
static isDashboard(root) {
|
|
22222
|
+
return _DashboardDir.readManifest(root) !== null;
|
|
22223
|
+
}
|
|
22224
|
+
static readManifest(root) {
|
|
22225
|
+
try {
|
|
22226
|
+
const parsed = JSON.parse(fs38.readFileSync(path29.join(root, DASHBOARD_MANIFEST), "utf8"));
|
|
22227
|
+
return typeof parsed?.id === "string" && typeof parsed.stamp === "string" ? parsed : null;
|
|
22228
|
+
} catch {
|
|
22229
|
+
return null;
|
|
22230
|
+
}
|
|
22231
|
+
}
|
|
22232
|
+
tracked() {
|
|
22233
|
+
if (this.manifest) return this.manifest;
|
|
22234
|
+
throw new CliError(
|
|
22235
|
+
`${this.root} is not a dashboard directory (no ${DASHBOARD_MANIFEST}). Run \`gateway dashboards pull <id>\` or \`gateway dashboards create <name>\` first.`,
|
|
22236
|
+
2
|
|
22237
|
+
);
|
|
22238
|
+
}
|
|
22239
|
+
/** The directory as `CheckoutTarget` reads a checkout: its identity, its base, its edits. */
|
|
22240
|
+
state() {
|
|
22241
|
+
const base = this.manifest?.files;
|
|
22242
|
+
if (!this.manifest || !base) return { meta: null, dirty: [], clean: false };
|
|
22243
|
+
const now = this.hashes();
|
|
22244
|
+
const dirty = /* @__PURE__ */ new Set();
|
|
22245
|
+
for (const [rel, hash] of Object.entries(now)) if (base[rel] !== hash) dirty.add(rel);
|
|
22246
|
+
for (const rel of Object.keys(base)) if (!(rel in now)) dirty.add(rel);
|
|
22247
|
+
return {
|
|
22248
|
+
meta: { slug: this.manifest.id, baseFiles: base },
|
|
22249
|
+
dirty: [...dirty].sort(),
|
|
22250
|
+
clean: dirty.size === 0
|
|
22251
|
+
};
|
|
22252
|
+
}
|
|
22253
|
+
/** What a push sends: the render files (paths relative to `render/`), the entrypoint and the transform. */
|
|
22254
|
+
source() {
|
|
22255
|
+
const manifest = this.tracked();
|
|
22256
|
+
const local = this.localFiles();
|
|
22257
|
+
const files = [...local.entries()].filter(([rel]) => rel.startsWith(`${RENDER_DIR}/`)).map(([rel, content]) => ({ path: rel.slice(RENDER_DIR.length + 1), content }));
|
|
22258
|
+
if (files.length === 0)
|
|
22259
|
+
throw new CliError(`no render files under ${path29.join(this.root, RENDER_DIR)} \u2014 nothing to push`, 2);
|
|
22260
|
+
const entry = manifest.entrypoint ?? void 0;
|
|
22261
|
+
return {
|
|
22262
|
+
files,
|
|
22263
|
+
entrypoint: files.some((file) => file.path === entry) ? entry : void 0,
|
|
22264
|
+
transform: local.get(TRANSFORM_FILE) ?? null
|
|
22265
|
+
};
|
|
22266
|
+
}
|
|
22267
|
+
/** The local transform, or a usage error when there is none to test. */
|
|
22268
|
+
transform() {
|
|
22269
|
+
const transform = this.localFiles().get(TRANSFORM_FILE);
|
|
22270
|
+
if (transform !== void 0) return transform;
|
|
22271
|
+
throw new CliError(`no ${TRANSFORM_FILE} in ${this.root} \u2014 nothing to test`, 2);
|
|
22272
|
+
}
|
|
22273
|
+
/** Lay a pulled or created dashboard into the directory and record it. */
|
|
22274
|
+
write(code) {
|
|
22275
|
+
fs38.mkdirSync(this.root, { recursive: true });
|
|
22276
|
+
for (const file of code.files) this.writeFile(`${RENDER_DIR}/${file.path}`, file.content);
|
|
22277
|
+
if (code.transform !== null) this.writeFile(TRANSFORM_FILE, code.transform);
|
|
22278
|
+
return this.record({ ...code, files: this.hashes() });
|
|
22279
|
+
}
|
|
22280
|
+
/** After a push: the new stamp and the files as they now stand on the platform. */
|
|
22281
|
+
pushed(result) {
|
|
22282
|
+
const manifest = this.tracked();
|
|
22283
|
+
return this.record({ ...manifest, ...result, files: this.hashes() });
|
|
22284
|
+
}
|
|
22285
|
+
record(manifest) {
|
|
22286
|
+
const kept = {
|
|
22287
|
+
id: manifest.id,
|
|
22288
|
+
name: manifest.name,
|
|
22289
|
+
kind: manifest.kind,
|
|
22290
|
+
entrypoint: manifest.entrypoint,
|
|
22291
|
+
stamp: manifest.stamp,
|
|
22292
|
+
url: manifest.url,
|
|
22293
|
+
files: manifest.files
|
|
22294
|
+
};
|
|
22295
|
+
fs38.writeFileSync(path29.join(this.root, DASHBOARD_MANIFEST), JSON.stringify(kept, null, 2) + "\n");
|
|
22296
|
+
return new _DashboardDir(this.root, kept);
|
|
22297
|
+
}
|
|
22298
|
+
hashes() {
|
|
22299
|
+
const out = {};
|
|
22300
|
+
for (const [rel, content] of this.localFiles()) out[rel] = sha2562(content);
|
|
22301
|
+
return out;
|
|
22302
|
+
}
|
|
22303
|
+
/** Every regular file under `render/` plus `transform.js`; hidden files are skipped, links refused. */
|
|
22304
|
+
localFiles() {
|
|
22305
|
+
const out = /* @__PURE__ */ new Map();
|
|
22306
|
+
const renderRoot = path29.join(this.root, RENDER_DIR);
|
|
22307
|
+
if (fs38.existsSync(renderRoot)) this.walk(renderRoot, out);
|
|
22308
|
+
const transform = path29.join(this.root, TRANSFORM_FILE);
|
|
22309
|
+
if (fs38.existsSync(transform)) out.set(TRANSFORM_FILE, this.readRegular(transform));
|
|
22310
|
+
return new Map([...out.entries()].sort(([a], [b]) => a.localeCompare(b)));
|
|
22311
|
+
}
|
|
22312
|
+
walk(dir, out) {
|
|
22313
|
+
for (const entry of fs38.readdirSync(dir, { withFileTypes: true })) {
|
|
22314
|
+
if (entry.name.startsWith(".")) continue;
|
|
22315
|
+
const full = path29.join(dir, entry.name);
|
|
22316
|
+
if (entry.isDirectory()) this.walk(full, out);
|
|
22317
|
+
else out.set(path29.relative(this.root, full).split(path29.sep).join("/"), this.readRegular(full));
|
|
22318
|
+
}
|
|
22319
|
+
}
|
|
22320
|
+
readRegular(file) {
|
|
22321
|
+
if (!fs38.lstatSync(file).isFile())
|
|
22322
|
+
throw new CliError(`${file} is not a regular file (links are not followed) \u2014 replace it with the file itself`, 2);
|
|
22323
|
+
return fs38.readFileSync(file, "utf8");
|
|
22324
|
+
}
|
|
22325
|
+
/** A server-named path lands under the directory or not at all (B4). */
|
|
22326
|
+
writeFile(rel, content) {
|
|
22327
|
+
const parts2 = rel.split("/");
|
|
22328
|
+
const escapes = path29.isAbsolute(rel) || rel.includes("\\") || parts2.some((p) => p === ".." || p === "");
|
|
22329
|
+
if (escapes) throw new CliError(`refusing to write ${JSON.stringify(rel)}: not a path inside the dashboard`, 1);
|
|
22330
|
+
const target = path29.join(this.root, ...parts2);
|
|
22331
|
+
fs38.mkdirSync(path29.dirname(target), { recursive: true });
|
|
22332
|
+
fs38.writeFileSync(target, content);
|
|
22333
|
+
}
|
|
22334
|
+
};
|
|
22335
|
+
function dashboardDirName(name) {
|
|
22336
|
+
const slug = name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
22337
|
+
return slug || "dashboard";
|
|
22338
|
+
}
|
|
22339
|
+
|
|
22340
|
+
// src/cli/platform/dashboards.ts
|
|
22341
|
+
init_shared();
|
|
22342
|
+
var TARGET_FLAG = { name: "target", short: "t", help: "Directory to write (defaults to ./<name>)." };
|
|
22343
|
+
var FORCE_FLAG = {
|
|
22344
|
+
name: "force",
|
|
22345
|
+
help: "Overwrite an explicit --target that has local edits or holds another dashboard.",
|
|
22346
|
+
boolean: true
|
|
22347
|
+
};
|
|
22348
|
+
var DIR_POSITIONAL = {
|
|
22349
|
+
name: "dir",
|
|
22350
|
+
help: "A dashboard directory (default: the current directory).",
|
|
22351
|
+
optional: true
|
|
22352
|
+
};
|
|
22353
|
+
var TARGET_POSITIONAL = {
|
|
22354
|
+
name: "target",
|
|
22355
|
+
help: "A dashboard directory or a dashboard id (default: the current directory).",
|
|
22356
|
+
optional: true
|
|
22357
|
+
};
|
|
22358
|
+
var client3 = (args) => new DashboardClient(credentials(args));
|
|
22359
|
+
function landing(identity, name, args) {
|
|
22360
|
+
const target = arg.str(args, "target");
|
|
22361
|
+
try {
|
|
22362
|
+
return CheckoutTarget.resolve(target === void 0 ? dashboardDirName(name) : identity, target, {
|
|
22363
|
+
cwd: process.cwd(),
|
|
22364
|
+
force: arg.bool(args, "force"),
|
|
22365
|
+
state: (dir) => DashboardDir.at(dir).state()
|
|
22366
|
+
});
|
|
22367
|
+
} catch (error) {
|
|
22368
|
+
if (error instanceof CheckoutRefusedError) throw new CliError(error.message, 1);
|
|
22369
|
+
throw error;
|
|
22370
|
+
}
|
|
22371
|
+
}
|
|
22372
|
+
function checkout(ctx, code, landing2) {
|
|
22373
|
+
landing2.clear();
|
|
22374
|
+
DashboardDir.at(landing2.dir).write(code);
|
|
22375
|
+
if (code.compiledOnly)
|
|
22376
|
+
ctx.stderr(
|
|
22377
|
+
"warning: this dashboard's render exists only as compiled code; add render/index.ts (exporting render) and push to replace it"
|
|
22378
|
+
);
|
|
22379
|
+
printJson(ctx, {
|
|
22380
|
+
id: code.id,
|
|
22381
|
+
name: code.name,
|
|
22382
|
+
kind: code.kind,
|
|
22383
|
+
dir: landing2.dir,
|
|
22384
|
+
files: code.files.map((file) => `render/${file.path}`).concat(code.transform === null ? [] : ["transform.js"]),
|
|
22385
|
+
url: code.url
|
|
22386
|
+
});
|
|
22387
|
+
}
|
|
22388
|
+
var looksLikePath = (value) => value === "." || value.includes("/") || value.includes(path30.sep) || fs39.existsSync(value);
|
|
22389
|
+
function dashboardId(target) {
|
|
22390
|
+
const candidate = target ?? ".";
|
|
22391
|
+
if (!looksLikePath(candidate)) return candidate;
|
|
22392
|
+
return DashboardDir.at(candidate).tracked().id;
|
|
22393
|
+
}
|
|
22394
|
+
function launch(url, args) {
|
|
22395
|
+
if (arg.bool(args, "no-launch") || process.env.GATEWAY_NO_BROWSER || !process.stdout.isTTY) return;
|
|
22396
|
+
const opener = { darwin: "open", linux: "xdg-open" }[process.platform];
|
|
22397
|
+
if (opener) execFile(opener, [url], () => void 0);
|
|
22398
|
+
}
|
|
22399
|
+
function registerDashboardCommands(root) {
|
|
22400
|
+
const dashboards = root.group(
|
|
22401
|
+
"dashboards",
|
|
22402
|
+
"Design dashboards as code: pull one into a directory, edit its TypeScript render files and transform, push it back."
|
|
22403
|
+
);
|
|
22404
|
+
dashboards.notes = [
|
|
22405
|
+
"A dashboard directory holds gateway-dashboard.json, render/ (the TypeScript render files; the entrypoint",
|
|
22406
|
+
"exports render(ctx) returning HTML) and an optional transform.js. The code-design agent's checks run on every push.",
|
|
22407
|
+
"",
|
|
22408
|
+
" gateway dashboards create 'Support review' # a working starter in ./support-review",
|
|
22409
|
+
" cd support-review && $EDITOR render/index.ts",
|
|
22410
|
+
" gateway dashboards push # refused, with every problem, if it does not compile",
|
|
22411
|
+
" gateway dashboards render # renders it on real data and prints the app URL"
|
|
22412
|
+
].join("\n");
|
|
22413
|
+
dashboards.command({
|
|
22414
|
+
name: "list",
|
|
22415
|
+
help: "List the project's dashboards, newest first.",
|
|
22416
|
+
flags: [{ name: "limit", help: "Most dashboards to return (1\u2013200, default 50)." }, JSON_OUTPUT_FLAG, HOST_FLAG],
|
|
22417
|
+
run: async (args, ctx) => {
|
|
22418
|
+
const limit = listLimit(arg.int(args, "limit"));
|
|
22419
|
+
const listed2 = await client3(args).list(limit);
|
|
22420
|
+
emit(
|
|
22421
|
+
ctx,
|
|
22422
|
+
args,
|
|
22423
|
+
listed2,
|
|
22424
|
+
() => listed2.data.length === 0 ? ["No dashboards yet. Run `gateway dashboards create <name>`."] : listed2.data.map((d) => `${d.id} ${d.kind.padEnd(11)} ${d.name}`)
|
|
22425
|
+
);
|
|
22426
|
+
}
|
|
22427
|
+
});
|
|
22428
|
+
dashboards.command({
|
|
22429
|
+
name: "create",
|
|
22430
|
+
help: "Create a dashboard (from working starter code unless --template empty) and check it out into a directory.",
|
|
22431
|
+
positionals: [{ name: "name", help: "Dashboard name, unique in the project." }],
|
|
22432
|
+
flags: [
|
|
22433
|
+
{ name: "description", help: "One line on what it shows." },
|
|
22434
|
+
{ name: "task-set", help: "Render each task of this task set (id) instead of sessions." },
|
|
22435
|
+
{ name: "environment", help: "Render this environment (id) instead of sessions." },
|
|
22436
|
+
{ name: "template", help: "starter (default) or empty." },
|
|
22437
|
+
TARGET_FLAG,
|
|
22438
|
+
FORCE_FLAG,
|
|
22439
|
+
HOST_FLAG
|
|
22440
|
+
],
|
|
22441
|
+
output: "json",
|
|
22442
|
+
run: async (args, ctx) => {
|
|
22443
|
+
const template = arg.str(args, "template") ?? "starter";
|
|
22444
|
+
if (template !== "starter" && template !== "empty")
|
|
22445
|
+
throw new CliError(`--template must be starter or empty, not \`${template}\`.`, 2);
|
|
22446
|
+
if (arg.str(args, "task-set") && arg.str(args, "environment"))
|
|
22447
|
+
throw new CliError("pass --task-set or --environment, not both.", 2);
|
|
22448
|
+
const name = args.positionals[0];
|
|
22449
|
+
const where = landing(name, name, args);
|
|
22450
|
+
const body = {
|
|
22451
|
+
name,
|
|
22452
|
+
template,
|
|
22453
|
+
description: arg.str(args, "description"),
|
|
22454
|
+
taskSetId: arg.str(args, "task-set"),
|
|
22455
|
+
environmentId: arg.str(args, "environment")
|
|
22456
|
+
};
|
|
22457
|
+
checkout(ctx, await client3(args).create(body), where);
|
|
22458
|
+
}
|
|
22459
|
+
});
|
|
22460
|
+
dashboards.command({
|
|
22461
|
+
name: "pull",
|
|
22462
|
+
help: "Check a dashboard's code out into a directory: render/, transform.js and gateway-dashboard.json.",
|
|
22463
|
+
positionals: [{ name: "id", help: "Dashboard id (from `gateway dashboards list`)." }],
|
|
22464
|
+
flags: [TARGET_FLAG, FORCE_FLAG, HOST_FLAG],
|
|
22465
|
+
output: "json",
|
|
22466
|
+
run: async (args, ctx) => {
|
|
22467
|
+
const code = await client3(args).pull(args.positionals[0]);
|
|
22468
|
+
checkout(ctx, code, landing(code.id, code.name, args));
|
|
22469
|
+
}
|
|
22470
|
+
});
|
|
22471
|
+
dashboards.command({
|
|
22472
|
+
name: "push",
|
|
22473
|
+
help: "Replace the dashboard's code with the directory's files, refused (nothing written) if it does not compile or changed since your pull.",
|
|
22474
|
+
positionals: [DIR_POSITIONAL],
|
|
22475
|
+
flags: [
|
|
22476
|
+
{ name: "dry-run", help: "Check the code and the stamp without writing.", boolean: true },
|
|
22477
|
+
{ name: "force", help: "Overwrite even if the dashboard changed since your pull.", boolean: true },
|
|
22478
|
+
HOST_FLAG
|
|
22479
|
+
],
|
|
22480
|
+
output: "json",
|
|
22481
|
+
run: async (args, ctx) => {
|
|
22482
|
+
const dir = DashboardDir.at(args.positionals[0] ?? ".");
|
|
22483
|
+
const manifest = dir.tracked();
|
|
22484
|
+
const dryRun = arg.bool(args, "dry-run");
|
|
22485
|
+
const pushed = await client3(args).push(manifest.id, {
|
|
22486
|
+
...dir.source(),
|
|
22487
|
+
baseStamp: manifest.stamp,
|
|
22488
|
+
force: arg.bool(args, "force") || void 0,
|
|
22489
|
+
dryRun: dryRun || void 0
|
|
22490
|
+
});
|
|
22491
|
+
if (!dryRun) dir.pushed(pushed);
|
|
22492
|
+
printJson(ctx, pushed);
|
|
22493
|
+
}
|
|
22494
|
+
});
|
|
22495
|
+
dashboards.command({
|
|
22496
|
+
name: "test-transform",
|
|
22497
|
+
help: "Run the directory's transform.js against a real session and print its output and shape; nothing is saved.",
|
|
22498
|
+
positionals: [DIR_POSITIONAL],
|
|
22499
|
+
flags: [{ name: "session", help: "Session id (default: the newest session the dashboard matches)." }, HOST_FLAG],
|
|
22500
|
+
output: "json",
|
|
22501
|
+
run: async (args, ctx) => {
|
|
22502
|
+
const dir = DashboardDir.at(args.positionals[0] ?? ".");
|
|
22503
|
+
const tested = await client3(args).testTransform(dir.tracked().id, {
|
|
22504
|
+
transform: dir.transform(),
|
|
22505
|
+
sessionId: arg.str(args, "session")
|
|
22506
|
+
});
|
|
22507
|
+
printJson(ctx, tested);
|
|
22508
|
+
return tested.success ? 0 : 1;
|
|
22509
|
+
}
|
|
22510
|
+
});
|
|
22511
|
+
dashboards.command({
|
|
22512
|
+
name: "render",
|
|
22513
|
+
help: "Render the pushed dashboard on real data and print whether it rendered and the app URL. Exit 1 when it did not.",
|
|
22514
|
+
positionals: [TARGET_POSITIONAL],
|
|
22515
|
+
flags: [
|
|
22516
|
+
{ name: "session", help: "Session id for a session dashboard (default: the newest matching session)." },
|
|
22517
|
+
{ name: "task-set", help: "Task set id for a task dashboard (default: its bound task set)." },
|
|
22518
|
+
{ name: "task", help: "Task id for a task dashboard (default: the first task)." },
|
|
22519
|
+
{ name: "out", help: "Also write the rendered HTML to this file." },
|
|
22520
|
+
HOST_FLAG
|
|
22521
|
+
],
|
|
22522
|
+
output: "json",
|
|
22523
|
+
run: async (args, ctx) => {
|
|
22524
|
+
const out = arg.str(args, "out");
|
|
22525
|
+
const rendered = await client3(args).render(dashboardId(args.positionals[0]), {
|
|
22526
|
+
sessionId: arg.str(args, "session"),
|
|
22527
|
+
taskSetId: arg.str(args, "task-set"),
|
|
22528
|
+
taskId: arg.str(args, "task"),
|
|
22529
|
+
includeHtml: out ? true : void 0
|
|
22530
|
+
});
|
|
22531
|
+
if (out && rendered.html !== null) fs39.writeFileSync(out, rendered.html);
|
|
22532
|
+
const summary2 = {
|
|
22533
|
+
success: rendered.success,
|
|
22534
|
+
error: rendered.error,
|
|
22535
|
+
kind: rendered.kind,
|
|
22536
|
+
target: rendered.target,
|
|
22537
|
+
executionTimeMs: rendered.executionTimeMs,
|
|
22538
|
+
url: rendered.url
|
|
22539
|
+
};
|
|
22540
|
+
printJson(ctx, out ? { ...summary2, out: path30.resolve(out) } : summary2);
|
|
22541
|
+
return rendered.success ? 0 : 1;
|
|
22542
|
+
}
|
|
22543
|
+
});
|
|
22544
|
+
dashboards.command({
|
|
22545
|
+
name: "open",
|
|
22546
|
+
help: "Print the app URL of a dashboard and open it in the browser when run from a terminal.",
|
|
22547
|
+
positionals: [TARGET_POSITIONAL],
|
|
22548
|
+
flags: [
|
|
22549
|
+
{ name: "no-launch", help: "Print the URL only (also when GATEWAY_NO_BROWSER is set or stdout is not a terminal).", boolean: true },
|
|
22550
|
+
HOST_FLAG
|
|
22551
|
+
],
|
|
22552
|
+
run: async (args, ctx) => {
|
|
22553
|
+
const code = await client3(args).pull(dashboardId(args.positionals[0]));
|
|
22554
|
+
ctx.stdout(code.url);
|
|
22555
|
+
launch(code.url, args);
|
|
22556
|
+
}
|
|
22557
|
+
});
|
|
22558
|
+
}
|
|
22559
|
+
|
|
21965
22560
|
// src/cli/platform/data.ts
|
|
21966
22561
|
init_config();
|
|
21967
22562
|
init_router();
|
|
21968
22563
|
init_hub();
|
|
21969
|
-
import * as
|
|
22564
|
+
import * as fs46 from "fs";
|
|
21970
22565
|
import * as os7 from "os";
|
|
21971
|
-
import * as
|
|
22566
|
+
import * as path36 from "path";
|
|
21972
22567
|
import { Readable as Readable2 } from "stream";
|
|
21973
22568
|
init_shared();
|
|
21974
22569
|
init_batches();
|
|
@@ -22259,9 +22854,9 @@ function objects(value) {
|
|
|
22259
22854
|
if (isObject(value)) return [value];
|
|
22260
22855
|
return [];
|
|
22261
22856
|
}
|
|
22262
|
-
function dig(value,
|
|
22857
|
+
function dig(value, path49) {
|
|
22263
22858
|
let at = value;
|
|
22264
|
-
for (const part of
|
|
22859
|
+
for (const part of path49.split(".").filter(Boolean)) {
|
|
22265
22860
|
if (!isObject(at) || !at.has(part)) return null;
|
|
22266
22861
|
at = at.get(part);
|
|
22267
22862
|
}
|
|
@@ -22279,11 +22874,11 @@ function shaped2(slug, item) {
|
|
|
22279
22874
|
if (typeof item === "string") return shapeText(slug, item, "str");
|
|
22280
22875
|
return new JsonNumber(shapeText(slug, pyStr(item), item.isFloat ? "float" : "int"));
|
|
22281
22876
|
}
|
|
22282
|
-
function redact(value, policy, slug,
|
|
22877
|
+
function redact(value, policy, slug, path49 = "") {
|
|
22283
22878
|
if (isObject(value)) {
|
|
22284
22879
|
const out = /* @__PURE__ */ new Map();
|
|
22285
22880
|
for (const [key2, item] of value) {
|
|
22286
|
-
const here =
|
|
22881
|
+
const here = path49 ? `${path49}.${key2}` : key2;
|
|
22287
22882
|
if (named(key2, here, policy.drop)) continue;
|
|
22288
22883
|
if (named(key2, here, policy.hash) && item !== null) out.set(key2, digest(slug, item));
|
|
22289
22884
|
else if (named(key2, here, policy.preserve) && item !== null) out.set(key2, shaped2(slug, item));
|
|
@@ -22292,7 +22887,7 @@ function redact(value, policy, slug, path44 = "") {
|
|
|
22292
22887
|
}
|
|
22293
22888
|
return out;
|
|
22294
22889
|
}
|
|
22295
|
-
if (Array.isArray(value)) return value.map((item) => redact(item, policy, slug,
|
|
22890
|
+
if (Array.isArray(value)) return value.map((item) => redact(item, policy, slug, path49 ? `${path49}.*` : "*"));
|
|
22296
22891
|
return value;
|
|
22297
22892
|
}
|
|
22298
22893
|
function pyDumpsPlain(value) {
|
|
@@ -22306,14 +22901,14 @@ function pyDumpsPlain(value) {
|
|
|
22306
22901
|
|
|
22307
22902
|
// src/cli/platform/worldData/ingestMap.ts
|
|
22308
22903
|
init_router();
|
|
22309
|
-
import * as
|
|
22310
|
-
import * as
|
|
22904
|
+
import * as fs40 from "fs";
|
|
22905
|
+
import * as path31 from "path";
|
|
22311
22906
|
var MAP_FILE = "ingest.toml";
|
|
22312
22907
|
var MAP_KINDS = ["tool-call", "rows", "csv"];
|
|
22313
22908
|
var SAMPLE_WIDTH = 48;
|
|
22314
22909
|
function readMapping(file) {
|
|
22315
|
-
if (!
|
|
22316
|
-
const text2 =
|
|
22910
|
+
if (!fs40.existsSync(file) || !fs40.statSync(file).isFile()) throw new CliError(`no mapping file at ${file}`, 1);
|
|
22911
|
+
const text2 = fs40.readFileSync(file, "utf8");
|
|
22317
22912
|
try {
|
|
22318
22913
|
parseToml(text2);
|
|
22319
22914
|
} catch (error) {
|
|
@@ -22323,8 +22918,8 @@ function readMapping(file) {
|
|
|
22323
22918
|
return text2;
|
|
22324
22919
|
}
|
|
22325
22920
|
function worldMapping(dir) {
|
|
22326
|
-
const file =
|
|
22327
|
-
return
|
|
22921
|
+
const file = path31.join(dir, MAP_FILE);
|
|
22922
|
+
return fs40.existsSync(file) ? fs40.readFileSync(file, "utf8") : null;
|
|
22328
22923
|
}
|
|
22329
22924
|
var isObject10 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22330
22925
|
function sample2(value) {
|
|
@@ -22435,7 +23030,7 @@ function skeleton(records2, entities, kind, opts = {}) {
|
|
|
22435
23030
|
// src/cli/platform/worldData/records.ts
|
|
22436
23031
|
init_router();
|
|
22437
23032
|
init_ingest();
|
|
22438
|
-
import * as
|
|
23033
|
+
import * as fs41 from "fs";
|
|
22439
23034
|
var FROM = ["tool-calls", "traces", "rows", "csv"];
|
|
22440
23035
|
function readInputRecords(files, from, readText4, options = {}) {
|
|
22441
23036
|
const records2 = [];
|
|
@@ -22463,8 +23058,8 @@ function readInputRecords(files, from, readText4, options = {}) {
|
|
|
22463
23058
|
return records2;
|
|
22464
23059
|
}
|
|
22465
23060
|
var readFileText = (file) => {
|
|
22466
|
-
if (!
|
|
22467
|
-
return
|
|
23061
|
+
if (!fs41.existsSync(file) || !fs41.statSync(file).isFile()) throw new CliError(`Cannot read ${file}`, 1);
|
|
23062
|
+
return fs41.readFileSync(file, "utf8");
|
|
22468
23063
|
};
|
|
22469
23064
|
|
|
22470
23065
|
// src/cli/platform/data.ts
|
|
@@ -22472,15 +23067,15 @@ init_transform();
|
|
|
22472
23067
|
|
|
22473
23068
|
// src/cli/platform/worldData/manifest.ts
|
|
22474
23069
|
init_router();
|
|
22475
|
-
import * as
|
|
22476
|
-
import * as
|
|
22477
|
-
var MANIFEST_DIR =
|
|
23070
|
+
import * as fs42 from "fs";
|
|
23071
|
+
import * as path32 from "path";
|
|
23072
|
+
var MANIFEST_DIR = path32.join(".gateway", "imports");
|
|
22478
23073
|
function manifestDir(cwd = process.cwd()) {
|
|
22479
|
-
return
|
|
23074
|
+
return path32.join(cwd, MANIFEST_DIR);
|
|
22480
23075
|
}
|
|
22481
23076
|
function manifestPath(batchId, cwd = process.cwd()) {
|
|
22482
23077
|
if (!/^[A-Za-z0-9_-]+$/.test(batchId)) throw new CliError(`Not a batch id: ${batchId}`);
|
|
22483
|
-
return
|
|
23078
|
+
return path32.join(manifestDir(cwd), `${batchId}.json`);
|
|
22484
23079
|
}
|
|
22485
23080
|
var stamp = () => (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
22486
23081
|
function newManifest(fields) {
|
|
@@ -22489,18 +23084,18 @@ function newManifest(fields) {
|
|
|
22489
23084
|
}
|
|
22490
23085
|
function writeManifest(manifest, cwd = process.cwd()) {
|
|
22491
23086
|
const file = manifestPath(manifest.batchId, cwd);
|
|
22492
|
-
|
|
22493
|
-
const ignore =
|
|
22494
|
-
if (!
|
|
23087
|
+
fs42.mkdirSync(path32.dirname(file), { recursive: true });
|
|
23088
|
+
const ignore = path32.join(cwd, ".gateway", ".gitignore");
|
|
23089
|
+
if (!fs42.existsSync(ignore)) fs42.writeFileSync(ignore, "*\n");
|
|
22495
23090
|
manifest.updatedAt = stamp();
|
|
22496
23091
|
const tmp = `${file}.tmp`;
|
|
22497
|
-
|
|
22498
|
-
|
|
23092
|
+
fs42.writeFileSync(tmp, JSON.stringify(manifest, null, 1) + "\n");
|
|
23093
|
+
fs42.renameSync(tmp, file);
|
|
22499
23094
|
return file;
|
|
22500
23095
|
}
|
|
22501
23096
|
function readManifest(batchId, cwd = process.cwd()) {
|
|
22502
23097
|
try {
|
|
22503
|
-
const parsed = JSON.parse(
|
|
23098
|
+
const parsed = JSON.parse(fs42.readFileSync(manifestPath(batchId, cwd), "utf8"));
|
|
22504
23099
|
return parsed && parsed.version === 1 && parsed.batchId === batchId ? parsed : null;
|
|
22505
23100
|
} catch {
|
|
22506
23101
|
return null;
|
|
@@ -22514,9 +23109,9 @@ function uploadedEntry(manifest, ordinal, digest2) {
|
|
|
22514
23109
|
}
|
|
22515
23110
|
function listManifests(cwd = process.cwd()) {
|
|
22516
23111
|
const dir = manifestDir(cwd);
|
|
22517
|
-
if (!
|
|
23112
|
+
if (!fs42.existsSync(dir)) return [];
|
|
22518
23113
|
const out = [];
|
|
22519
|
-
for (const name of
|
|
23114
|
+
for (const name of fs42.readdirSync(dir)) {
|
|
22520
23115
|
if (!name.endsWith(".json")) continue;
|
|
22521
23116
|
const manifest = readManifest(name.slice(0, -5), cwd);
|
|
22522
23117
|
if (manifest) out.push(manifest);
|
|
@@ -22533,14 +23128,14 @@ init_describe();
|
|
|
22533
23128
|
|
|
22534
23129
|
// src/cli/platform/worldData/worldConfig.ts
|
|
22535
23130
|
init_router();
|
|
22536
|
-
import * as
|
|
22537
|
-
import * as
|
|
23131
|
+
import * as fs43 from "fs";
|
|
23132
|
+
import * as path33 from "path";
|
|
22538
23133
|
function loadWorldConfig(dir) {
|
|
22539
|
-
const worldFile = ["schema/world.json", "world.json"].map((p) =>
|
|
23134
|
+
const worldFile = ["schema/world.json", "world.json"].map((p) => path33.join(dir, p)).find((p) => fs43.existsSync(p));
|
|
22540
23135
|
if (!worldFile) throw new CliError(`${dir} has no schema/world.json; extract needs a schema world`, 1);
|
|
22541
23136
|
let document;
|
|
22542
23137
|
try {
|
|
22543
|
-
document = JSON.parse(
|
|
23138
|
+
document = JSON.parse(fs43.readFileSync(worldFile, "utf8"));
|
|
22544
23139
|
} catch {
|
|
22545
23140
|
throw new CliError(`${worldFile} is not valid JSON`, 1);
|
|
22546
23141
|
}
|
|
@@ -22552,8 +23147,8 @@ function loadWorldConfig(dir) {
|
|
|
22552
23147
|
const primaryKey = Array.isArray(entity.primary_key) ? entity.primary_key : [];
|
|
22553
23148
|
entities[name] = { primaryKey, fields: declaredFields(document, entity.schema) };
|
|
22554
23149
|
}
|
|
22555
|
-
const connectorFile =
|
|
22556
|
-
const spec =
|
|
23150
|
+
const connectorFile = path33.join(dir, "connector.toml");
|
|
23151
|
+
const spec = fs43.existsSync(connectorFile) ? readSpec(connectorFile) : readEnvPolicy(path33.join(dir, "gateway-env.toml"));
|
|
22557
23152
|
return { dir, slug: spec.slug, entities, redact: spec.redact, envelope: spec.envelope, hitsKey: spec.hitsKey, operations: spec.operations };
|
|
22558
23153
|
}
|
|
22559
23154
|
function declaredFields(document, schema) {
|
|
@@ -22571,7 +23166,7 @@ function declaredFields(document, schema) {
|
|
|
22571
23166
|
var NO_SPEC = { slug: null, redact: { hash: [], drop: [], preserve: [], round: {} }, envelope: "", hitsKey: "hits", operations: {} };
|
|
22572
23167
|
function readToml(file) {
|
|
22573
23168
|
try {
|
|
22574
|
-
return parseToml(
|
|
23169
|
+
return parseToml(fs43.readFileSync(file, "utf8"));
|
|
22575
23170
|
} catch (error) {
|
|
22576
23171
|
if (error instanceof TomlError) throw new CliError(`${file}: ${error.message}`, 1);
|
|
22577
23172
|
throw error;
|
|
@@ -22591,7 +23186,7 @@ function readSpec(file) {
|
|
|
22591
23186
|
};
|
|
22592
23187
|
}
|
|
22593
23188
|
function readEnvPolicy(file) {
|
|
22594
|
-
if (!
|
|
23189
|
+
if (!fs43.existsSync(file)) return NO_SPEC;
|
|
22595
23190
|
const raw = readToml(file);
|
|
22596
23191
|
if (raw.redact === void 0) return NO_SPEC;
|
|
22597
23192
|
const name = table3(raw.environment).name;
|
|
@@ -22631,21 +23226,21 @@ function rounding(value) {
|
|
|
22631
23226
|
init_config();
|
|
22632
23227
|
init_router();
|
|
22633
23228
|
init_hub();
|
|
22634
|
-
import * as
|
|
23229
|
+
import * as fs45 from "fs";
|
|
22635
23230
|
import * as os6 from "os";
|
|
22636
|
-
import * as
|
|
23231
|
+
import * as path35 from "path";
|
|
22637
23232
|
|
|
22638
23233
|
// src/cli/platform/worldData/driveIo.ts
|
|
22639
23234
|
init_files();
|
|
22640
23235
|
init_shared();
|
|
22641
|
-
import * as
|
|
23236
|
+
import * as fs44 from "fs";
|
|
22642
23237
|
import * as os5 from "os";
|
|
22643
|
-
import * as
|
|
23238
|
+
import * as path34 from "path";
|
|
22644
23239
|
async function stageDriveInputs(inputs, creds) {
|
|
22645
23240
|
if (!inputs.some(isDriveRef))
|
|
22646
23241
|
return { files: inputs, labels: {}, cleanup: () => void 0 };
|
|
22647
|
-
const scratch =
|
|
22648
|
-
const cleanup = () =>
|
|
23242
|
+
const scratch = fs44.mkdtempSync(path34.join(os5.tmpdir(), "gateway-drive-in-"));
|
|
23243
|
+
const cleanup = () => fs44.rmSync(scratch, { recursive: true, force: true });
|
|
22649
23244
|
const labels = {};
|
|
22650
23245
|
const files = [];
|
|
22651
23246
|
try {
|
|
@@ -22656,7 +23251,7 @@ async function stageDriveInputs(inputs, creds) {
|
|
|
22656
23251
|
continue;
|
|
22657
23252
|
}
|
|
22658
23253
|
const target = drivePath(input);
|
|
22659
|
-
const local =
|
|
23254
|
+
const local = path34.join(scratch, `${index2}-${path34.basename(target)}`);
|
|
22660
23255
|
await downloadFile(options, target, local);
|
|
22661
23256
|
labels[local] = `drive:${target}`;
|
|
22662
23257
|
files.push(local);
|
|
@@ -22679,10 +23274,10 @@ async function landInDrive(localFile, to, creds) {
|
|
|
22679
23274
|
});
|
|
22680
23275
|
}
|
|
22681
23276
|
function scratchFile(name) {
|
|
22682
|
-
const dir =
|
|
23277
|
+
const dir = fs44.mkdtempSync(path34.join(os5.tmpdir(), "gateway-drive-out-"));
|
|
22683
23278
|
return {
|
|
22684
|
-
file:
|
|
22685
|
-
cleanup: () =>
|
|
23279
|
+
file: path34.join(dir, name),
|
|
23280
|
+
cleanup: () => fs44.rmSync(dir, { recursive: true, force: true })
|
|
22686
23281
|
};
|
|
22687
23282
|
}
|
|
22688
23283
|
var TO_FLAG = {
|
|
@@ -22725,7 +23320,7 @@ var TreeImport = class _TreeImport {
|
|
|
22725
23320
|
/** The platform slug this directory would import into: its pulled metadata, else its name. */
|
|
22726
23321
|
get slug() {
|
|
22727
23322
|
const slug = readLocalMeta(this.dir)?.slug;
|
|
22728
|
-
return typeof slug === "string" && slug ? slug :
|
|
23323
|
+
return typeof slug === "string" && slug ? slug : path35.basename(path35.resolve(this.dir));
|
|
22729
23324
|
}
|
|
22730
23325
|
/** Import (or, `dryRun`, prove) the files; prints the report `data check` prints; the exit code. */
|
|
22731
23326
|
async run(dryRun) {
|
|
@@ -22798,7 +23393,7 @@ var TreeImport = class _TreeImport {
|
|
|
22798
23393
|
`${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`,
|
|
22799
23394
|
1
|
|
22800
23395
|
);
|
|
22801
|
-
const size = paths.reduce((n, p) => n +
|
|
23396
|
+
const size = paths.reduce((n, p) => n + fs45.statSync(p).size, 0);
|
|
22802
23397
|
if (size > INLINE_BYTES) throw tooLarge(`${size} bytes`);
|
|
22803
23398
|
let count = 0;
|
|
22804
23399
|
for await (const _ of readRows(paths.map(fileInput), this.entity))
|
|
@@ -22821,7 +23416,7 @@ var TreeImport = class _TreeImport {
|
|
|
22821
23416
|
return 2;
|
|
22822
23417
|
}
|
|
22823
23418
|
write(report) {
|
|
22824
|
-
if (this.report !== void 0)
|
|
23419
|
+
if (this.report !== void 0) fs45.writeFileSync(this.report, report);
|
|
22825
23420
|
}
|
|
22826
23421
|
};
|
|
22827
23422
|
var StagedPaths = class {
|
|
@@ -22834,13 +23429,13 @@ var StagedPaths = class {
|
|
|
22834
23429
|
async stage(ctx) {
|
|
22835
23430
|
for (const file of this.files) {
|
|
22836
23431
|
if (file === "-") {
|
|
22837
|
-
this.scratch ??=
|
|
22838
|
-
const stdin =
|
|
22839
|
-
|
|
23432
|
+
this.scratch ??= fs45.mkdtempSync(path35.join(os6.tmpdir(), "gateway-stdin-"));
|
|
23433
|
+
const stdin = path35.join(this.scratch, "stdin.rows");
|
|
23434
|
+
fs45.writeFileSync(stdin, await ctx.stdin());
|
|
22840
23435
|
this.list.push(stdin);
|
|
22841
23436
|
continue;
|
|
22842
23437
|
}
|
|
22843
|
-
if (!
|
|
23438
|
+
if (!fs45.existsSync(file) || !fs45.statSync(file).isFile()) throw new CliError(`Cannot read ${file}`, 1);
|
|
22844
23439
|
this.list.push(file);
|
|
22845
23440
|
}
|
|
22846
23441
|
}
|
|
@@ -22855,7 +23450,7 @@ var StagedPaths = class {
|
|
|
22855
23450
|
return total;
|
|
22856
23451
|
}
|
|
22857
23452
|
dispose() {
|
|
22858
|
-
if (this.scratch)
|
|
23453
|
+
if (this.scratch) fs45.rmSync(this.scratch, { recursive: true, force: true });
|
|
22859
23454
|
}
|
|
22860
23455
|
};
|
|
22861
23456
|
function refusalsFromBridge(detail) {
|
|
@@ -22951,13 +23546,13 @@ async function rowsOrRefuse(source2, files) {
|
|
|
22951
23546
|
yield* source2;
|
|
22952
23547
|
})();
|
|
22953
23548
|
}
|
|
22954
|
-
async function stageDriveChunks(
|
|
22955
|
-
for (const [ordinal,
|
|
22956
|
-
const entry = await
|
|
23549
|
+
async function stageDriveChunks(client5, batchId, drive, entity, manifest, progress) {
|
|
23550
|
+
for (const [ordinal, path49] of drive.entries()) {
|
|
23551
|
+
const entry = await client5.stageDrive(batchId, { ordinal, path: path49, entity });
|
|
22957
23552
|
recordChunk(manifest, entry);
|
|
22958
23553
|
writeManifest(manifest);
|
|
22959
23554
|
progress(
|
|
22960
|
-
`chunk ${ordinal}: drive:${
|
|
23555
|
+
`chunk ${ordinal}: drive:${path49} staged on the platform, ${entry.bytes} bytes (${entry.chunkId})`
|
|
22961
23556
|
);
|
|
22962
23557
|
}
|
|
22963
23558
|
return drive.length;
|
|
@@ -23216,7 +23811,7 @@ primary key, the world's [redact] policy applied. Summary on stderr:
|
|
|
23216
23811
|
const file = local ?? scratch?.file ?? null;
|
|
23217
23812
|
try {
|
|
23218
23813
|
const input = source2 === "-" ? stdinInput(ctx) : fileInput(staged.files[0]);
|
|
23219
|
-
const sink = file ?
|
|
23814
|
+
const sink = file ? fs46.createWriteStream(file) : null;
|
|
23220
23815
|
const write = sink ? (line) => void sink.write(line + "\n") : (line) => ctx.stdout(line);
|
|
23221
23816
|
const summary2 = await extractRows(
|
|
23222
23817
|
input,
|
|
@@ -23231,8 +23826,8 @@ primary key, the world's [redact] policy applied. Summary on stderr:
|
|
|
23231
23826
|
);
|
|
23232
23827
|
if (sink)
|
|
23233
23828
|
await new Promise(
|
|
23234
|
-
(
|
|
23235
|
-
(error) => error ? reject(error) :
|
|
23829
|
+
(resolve32, reject) => sink.end(
|
|
23830
|
+
(error) => error ? reject(error) : resolve32()
|
|
23236
23831
|
)
|
|
23237
23832
|
);
|
|
23238
23833
|
if (Object.keys(staged.labels).length)
|
|
@@ -23690,7 +24285,7 @@ function rowInputs(files, ctx) {
|
|
|
23690
24285
|
if (files.filter((f) => f === "-").length > 1)
|
|
23691
24286
|
throw new CliError("stdin (-) can be read once");
|
|
23692
24287
|
for (const file of files) {
|
|
23693
|
-
if (file !== "-" && !(
|
|
24288
|
+
if (file !== "-" && !(fs46.existsSync(file) && fs46.statSync(file).isFile()))
|
|
23694
24289
|
throw new CliError(`Cannot read ${file}`, 1);
|
|
23695
24290
|
}
|
|
23696
24291
|
return files.map((f) => f === "-" ? stdinInput(ctx) : fileInput(f));
|
|
@@ -23714,7 +24309,7 @@ async function importBatch(world, files, args, ctx, purpose, onStatus, labels =
|
|
|
23714
24309
|
const named2 = inputLabels(files, labels);
|
|
23715
24310
|
const creds = credentials(args);
|
|
23716
24311
|
const flags = importFlags(args, purpose);
|
|
23717
|
-
const
|
|
24312
|
+
const client5 = new WorldDataApi(creds, slug);
|
|
23718
24313
|
const progress = (line) => {
|
|
23719
24314
|
if (showProgress()) ctx.stderr(line);
|
|
23720
24315
|
};
|
|
@@ -23746,7 +24341,7 @@ async function importBatch(world, files, args, ctx, purpose, onStatus, labels =
|
|
|
23746
24341
|
);
|
|
23747
24342
|
let manifest;
|
|
23748
24343
|
if (resumable) {
|
|
23749
|
-
const status2 = await
|
|
24344
|
+
const status2 = await client5.get(resumable.batchId);
|
|
23750
24345
|
if (status2.state !== "open" && status2.state !== "uploading")
|
|
23751
24346
|
throw new CliError(
|
|
23752
24347
|
`batch ${resumable.batchId} is ${status2.state}; only an open or uploading batch resumes`,
|
|
@@ -23757,7 +24352,7 @@ async function importBatch(world, files, args, ctx, purpose, onStatus, labels =
|
|
|
23757
24352
|
`resuming batch ${manifest.batchId} (${manifest.chunks.length} chunks recorded)`
|
|
23758
24353
|
);
|
|
23759
24354
|
} else {
|
|
23760
|
-
const opened = await
|
|
24355
|
+
const opened = await client5.open({
|
|
23761
24356
|
mode: plan.mode,
|
|
23762
24357
|
merge: plan.merge,
|
|
23763
24358
|
...plan.redact && plan.redact !== "off" ? { redact: plan.redact } : {},
|
|
@@ -23789,7 +24384,7 @@ async function importBatch(world, files, args, ctx, purpose, onStatus, labels =
|
|
|
23789
24384
|
}
|
|
23790
24385
|
const batchId = manifest.batchId;
|
|
23791
24386
|
const staged = await stageDriveChunks(
|
|
23792
|
-
|
|
24387
|
+
client5,
|
|
23793
24388
|
batchId,
|
|
23794
24389
|
drive,
|
|
23795
24390
|
plan.entity,
|
|
@@ -23810,14 +24405,14 @@ async function importBatch(world, files, args, ctx, purpose, onStatus, labels =
|
|
|
23810
24405
|
progress(`chunk ${chunk.ordinal}: already uploaded (${chunk.rows} rows)`);
|
|
23811
24406
|
return;
|
|
23812
24407
|
}
|
|
23813
|
-
const entry = await
|
|
24408
|
+
const entry = await client5.upload(batchId, chunk);
|
|
23814
24409
|
recordChunk(manifest, entry);
|
|
23815
24410
|
writeManifest(manifest);
|
|
23816
24411
|
progress(
|
|
23817
24412
|
`chunk ${chunk.ordinal}: uploaded ${chunk.rows} rows, ${chunk.bytes} bytes (${entry.chunkId})`
|
|
23818
24413
|
);
|
|
23819
24414
|
});
|
|
23820
|
-
await
|
|
24415
|
+
await client5.complete(batchId);
|
|
23821
24416
|
manifest.completed = true;
|
|
23822
24417
|
writeManifest(manifest);
|
|
23823
24418
|
progress(`batch ${batchId} complete: ${manifest.chunks.length} chunks`);
|
|
@@ -23826,7 +24421,7 @@ async function importBatch(world, files, args, ctx, purpose, onStatus, labels =
|
|
|
23826
24421
|
else ctx.stdout(JSON.stringify({ batchId, state: "queued" }));
|
|
23827
24422
|
return 0;
|
|
23828
24423
|
}
|
|
23829
|
-
const status = await waitForBatch(
|
|
24424
|
+
const status = await waitForBatch(client5, batchId, {
|
|
23830
24425
|
onPhase: (line) => progress(line),
|
|
23831
24426
|
initialDelayMs: pollMs2()
|
|
23832
24427
|
});
|
|
@@ -23953,11 +24548,11 @@ async function pullCalls(out, to, from, staged, args, ctx) {
|
|
|
23953
24548
|
const toStdout = out === "-";
|
|
23954
24549
|
if (toStdout) {
|
|
23955
24550
|
if (text2) process.stdout.write(text2);
|
|
23956
|
-
} else if (out)
|
|
24551
|
+
} else if (out) fs46.writeFileSync(out, text2);
|
|
23957
24552
|
let landed;
|
|
23958
24553
|
if (to) {
|
|
23959
24554
|
const scratch = out && !toStdout ? null : scratchFile("calls.jsonl");
|
|
23960
|
-
if (scratch)
|
|
24555
|
+
if (scratch) fs46.writeFileSync(scratch.file, text2);
|
|
23961
24556
|
try {
|
|
23962
24557
|
landed = `drive:${(await landInDrive(scratch?.file ?? out, to, credentials(args))).path}`;
|
|
23963
24558
|
} finally {
|
|
@@ -24014,20 +24609,20 @@ async function mapInitCommand(world, samples, args, ctx) {
|
|
|
24014
24609
|
delimiter: delimiterFlag(args) ?? void 0
|
|
24015
24610
|
});
|
|
24016
24611
|
const text2 = skeleton(records2, config.entities, kind, {
|
|
24017
|
-
sampleName: samples.map((f) =>
|
|
24612
|
+
sampleName: samples.map((f) => path36.basename(f)).join(", "),
|
|
24018
24613
|
entity: arg.str(args, "entity")
|
|
24019
24614
|
});
|
|
24020
|
-
const out = arg.str(args, "out") ?? (local ?
|
|
24615
|
+
const out = arg.str(args, "out") ?? (local ? path36.join(world, MAP_FILE) : "-");
|
|
24021
24616
|
if (out === "-") {
|
|
24022
24617
|
ctx.stdout(text2.replace(/\n$/, ""));
|
|
24023
24618
|
return 0;
|
|
24024
24619
|
}
|
|
24025
|
-
if (
|
|
24620
|
+
if (fs46.existsSync(out) && !arg.bool(args, "dry-run"))
|
|
24026
24621
|
throw new CliError(
|
|
24027
24622
|
`${out} exists; pass --out for another path, or move it first`,
|
|
24028
24623
|
1
|
|
24029
24624
|
);
|
|
24030
|
-
|
|
24625
|
+
fs46.writeFileSync(out, text2);
|
|
24031
24626
|
const fromFlag = from === "tool-calls" ? "" : ` --from ${from}`;
|
|
24032
24627
|
ctx.stderr(
|
|
24033
24628
|
`wrote ${out}: fill in the entity and fields, then run \`gateway worlds data ingest ${world} ${samples[0]}${fromFlag} --map ${out} --dry-run\``
|
|
@@ -24255,12 +24850,12 @@ async function ingestCommand(world, inputs, args, ctx, labels = {}) {
|
|
|
24255
24850
|
const full = out;
|
|
24256
24851
|
let code = full.refusals.length ? 2 : 0;
|
|
24257
24852
|
if (!local && !dryRun && !full.refusals.length && Object.keys(projected).length) {
|
|
24258
|
-
const scratch =
|
|
24259
|
-
|
|
24853
|
+
const scratch = fs46.mkdtempSync(
|
|
24854
|
+
path36.join(os7.tmpdir(), "gateway-ingest-rows-")
|
|
24260
24855
|
);
|
|
24261
24856
|
try {
|
|
24262
|
-
const rowsFile =
|
|
24263
|
-
|
|
24857
|
+
const rowsFile = path36.join(scratch, "rows.json");
|
|
24858
|
+
fs46.writeFileSync(rowsFile, JSON.stringify(projected));
|
|
24264
24859
|
code = await importBatch(
|
|
24265
24860
|
world,
|
|
24266
24861
|
[rowsFile],
|
|
@@ -24275,11 +24870,11 @@ async function ingestCommand(world, inputs, args, ctx, labels = {}) {
|
|
|
24275
24870
|
}
|
|
24276
24871
|
);
|
|
24277
24872
|
} finally {
|
|
24278
|
-
|
|
24873
|
+
fs46.rmSync(scratch, { recursive: true, force: true });
|
|
24279
24874
|
}
|
|
24280
24875
|
}
|
|
24281
24876
|
if (reportFile !== void 0)
|
|
24282
|
-
|
|
24877
|
+
fs46.writeFileSync(
|
|
24283
24878
|
reportFile,
|
|
24284
24879
|
full.refusals.map((r) => JSON.stringify(r) + "\n").join("")
|
|
24285
24880
|
);
|
|
@@ -24336,8 +24931,8 @@ function renderSource(source2, ctx) {
|
|
|
24336
24931
|
ctx.stdout(` ${entity} fields never set: ${fields.join(", ")}`);
|
|
24337
24932
|
}
|
|
24338
24933
|
async function pullWorld(slugRef, creds) {
|
|
24339
|
-
const target =
|
|
24340
|
-
|
|
24934
|
+
const target = path36.join(
|
|
24935
|
+
fs46.mkdtempSync(path36.join(os7.tmpdir(), "gateway-world-data-")),
|
|
24341
24936
|
slugOf(slugRef)
|
|
24342
24937
|
);
|
|
24343
24938
|
const pulled = await pull(slugRef, target, worldsOptions(creds));
|
|
@@ -24348,17 +24943,17 @@ async function pullWorld(slugRef, creds) {
|
|
|
24348
24943
|
init_config();
|
|
24349
24944
|
init_router();
|
|
24350
24945
|
init_shared();
|
|
24351
|
-
import * as
|
|
24352
|
-
import * as
|
|
24946
|
+
import * as fs47 from "fs";
|
|
24947
|
+
import * as path37 from "path";
|
|
24353
24948
|
function readDatasetItems(file) {
|
|
24354
|
-
const raw =
|
|
24355
|
-
const looksJson =
|
|
24949
|
+
const raw = fs47.readFileSync(file, "utf8").trim();
|
|
24950
|
+
const looksJson = path37.extname(file) === ".json" || raw.startsWith("{") || raw.startsWith("[");
|
|
24356
24951
|
if (looksJson) {
|
|
24357
24952
|
let data;
|
|
24358
24953
|
try {
|
|
24359
24954
|
data = JSON.parse(raw);
|
|
24360
24955
|
} catch (error) {
|
|
24361
|
-
if (
|
|
24956
|
+
if (path37.extname(file) === ".json") throw error;
|
|
24362
24957
|
data = void 0;
|
|
24363
24958
|
}
|
|
24364
24959
|
if (data !== void 0) {
|
|
@@ -24396,10 +24991,10 @@ function registerDatasetCommands(root) {
|
|
|
24396
24991
|
const file = args.positionals[0];
|
|
24397
24992
|
const name = arg.str(args, "name");
|
|
24398
24993
|
if (!name) throw new CliError("dataset upload needs --name");
|
|
24399
|
-
if (!
|
|
24994
|
+
if (!fs47.existsSync(file)) throw new CliError(`Error: File not found: ${file}`, 1);
|
|
24400
24995
|
const items = readDatasetItems(file);
|
|
24401
24996
|
if (items.length === 0) throw new CliError("Error: No items found in file.", 1);
|
|
24402
|
-
ctx.stdout(`Found ${items.length} items in ${
|
|
24997
|
+
ctx.stdout(`Found ${items.length} items in ${path37.basename(file)}`);
|
|
24403
24998
|
const creds = credentials(args);
|
|
24404
24999
|
const agent = arg.str(args, "agent");
|
|
24405
25000
|
if (agent) {
|
|
@@ -24435,8 +25030,8 @@ init_config();
|
|
|
24435
25030
|
init_router();
|
|
24436
25031
|
init_files();
|
|
24437
25032
|
init_shared();
|
|
24438
|
-
import * as
|
|
24439
|
-
import * as
|
|
25033
|
+
import * as fs48 from "fs";
|
|
25034
|
+
import * as path38 from "path";
|
|
24440
25035
|
var PATH_HELP = "Path in the drive, e.g. corpora/train.jsonl (a drive: prefix is accepted).";
|
|
24441
25036
|
var JSON_FLAG2 = { name: "json", help: "Print the platform's JSON instead of the summary.", boolean: true };
|
|
24442
25037
|
function registerFilesCommands(root) {
|
|
@@ -24512,7 +25107,7 @@ function registerFilesCommands(root) {
|
|
|
24512
25107
|
flags: [{ name: "out", help: "Local path to write (default the file's own name in the working directory)." }, HOST_FLAG],
|
|
24513
25108
|
run: async (args, ctx) => {
|
|
24514
25109
|
const target = drivePath(args.positionals[0]);
|
|
24515
|
-
const out = arg.str(args, "out") ??
|
|
25110
|
+
const out = arg.str(args, "out") ?? path38.basename(target);
|
|
24516
25111
|
const result = await downloadFile(worldsOptions(credentials(args)), target, out, progressReporter(ctx, `drive:${target}`));
|
|
24517
25112
|
ctx.stdout(`drive:${result.path} -> ${out} (${result.sizeBytes ?? "?"} bytes)`);
|
|
24518
25113
|
}
|
|
@@ -24621,26 +25216,26 @@ function registerFilesCommands(root) {
|
|
|
24621
25216
|
}
|
|
24622
25217
|
function planUploads(inputs, to) {
|
|
24623
25218
|
const base = to ? drivePath(to).replace(/\/+$/, "") : "";
|
|
24624
|
-
const
|
|
25219
|
+
const join37 = (...parts2) => parts2.filter(Boolean).join("/");
|
|
24625
25220
|
const plan = [];
|
|
24626
25221
|
for (const input of inputs) {
|
|
24627
|
-
if (!
|
|
24628
|
-
if (
|
|
24629
|
-
const root =
|
|
24630
|
-
for (const file of walk2(root)) plan.push({ local: file, path:
|
|
25222
|
+
if (!fs48.existsSync(input)) throw new CliError(`${input} does not exist`, 1);
|
|
25223
|
+
if (fs48.statSync(input).isDirectory()) {
|
|
25224
|
+
const root = path38.resolve(input);
|
|
25225
|
+
for (const file of walk2(root)) plan.push({ local: file, path: join37(base, path38.basename(root), path38.relative(root, file).split(path38.sep).join("/")) });
|
|
24631
25226
|
continue;
|
|
24632
25227
|
}
|
|
24633
|
-
const oneFileNamedInFull = inputs.length === 1 && base !== "" && !to.endsWith("/") &&
|
|
24634
|
-
plan.push({ local: input, path: oneFileNamedInFull ? base :
|
|
25228
|
+
const oneFileNamedInFull = inputs.length === 1 && base !== "" && !to.endsWith("/") && path38.extname(base) !== "";
|
|
25229
|
+
plan.push({ local: input, path: oneFileNamedInFull ? base : join37(base, path38.basename(input)) });
|
|
24635
25230
|
}
|
|
24636
25231
|
if (!plan.length) throw new CliError("nothing to upload: the directories are empty", 1);
|
|
24637
25232
|
return plan;
|
|
24638
25233
|
}
|
|
24639
25234
|
function walk2(dir) {
|
|
24640
25235
|
const out = [];
|
|
24641
|
-
for (const entry of
|
|
25236
|
+
for (const entry of fs48.readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
24642
25237
|
if (entry.name.startsWith(".")) continue;
|
|
24643
|
-
const full =
|
|
25238
|
+
const full = path38.join(dir, entry.name);
|
|
24644
25239
|
if (entry.isDirectory()) out.push(...walk2(full));
|
|
24645
25240
|
else if (entry.isFile()) out.push(full);
|
|
24646
25241
|
}
|
|
@@ -25055,14 +25650,15 @@ function registerSecretCommands(root) {
|
|
|
25055
25650
|
init_config();
|
|
25056
25651
|
init_router();
|
|
25057
25652
|
init_worlds();
|
|
25058
|
-
|
|
25653
|
+
init_surfaceDescriptor();
|
|
25654
|
+
import * as fs52 from "fs";
|
|
25059
25655
|
init_shared();
|
|
25060
25656
|
|
|
25061
25657
|
// src/cli/platform/task.ts
|
|
25062
25658
|
init_config();
|
|
25063
25659
|
init_router();
|
|
25064
|
-
import * as
|
|
25065
|
-
import * as
|
|
25660
|
+
import * as fs51 from "fs";
|
|
25661
|
+
import * as path40 from "path";
|
|
25066
25662
|
import { pathToFileURL as pathToFileURL3 } from "url";
|
|
25067
25663
|
|
|
25068
25664
|
// src/cli/runtime/run.ts
|
|
@@ -25073,8 +25669,8 @@ init_session2();
|
|
|
25073
25669
|
init_hub();
|
|
25074
25670
|
init_validate();
|
|
25075
25671
|
init_client();
|
|
25076
|
-
import * as
|
|
25077
|
-
import * as
|
|
25672
|
+
import * as fs49 from "fs";
|
|
25673
|
+
import * as path39 from "path";
|
|
25078
25674
|
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
25079
25675
|
|
|
25080
25676
|
// src/cli/rewardGate.ts
|
|
@@ -25144,9 +25740,9 @@ var toOptions = (creds) => ({
|
|
|
25144
25740
|
secretKey: creds.secretKey
|
|
25145
25741
|
});
|
|
25146
25742
|
async function loadAgent(file) {
|
|
25147
|
-
const abs =
|
|
25148
|
-
if (!
|
|
25149
|
-
const ext =
|
|
25743
|
+
const abs = path39.resolve(file);
|
|
25744
|
+
if (!fs49.existsSync(abs)) throw new CliError(`--agent ${file} does not exist`);
|
|
25745
|
+
const ext = path39.extname(abs);
|
|
25150
25746
|
if (ext === ".ts" || ext === ".mts" || ext === ".cts")
|
|
25151
25747
|
await registerTypeScriptLoader(abs);
|
|
25152
25748
|
else if (![".js", ".mjs", ".cjs"].includes(ext))
|
|
@@ -25190,11 +25786,11 @@ async function registerTypeScriptLoader(agentPath) {
|
|
|
25190
25786
|
);
|
|
25191
25787
|
}
|
|
25192
25788
|
function resolveTarget(target, versionFlag) {
|
|
25193
|
-
if (
|
|
25194
|
-
const dir =
|
|
25789
|
+
if (fs49.existsSync(target) && fs49.statSync(target).isDirectory()) {
|
|
25790
|
+
const dir = path39.resolve(target);
|
|
25195
25791
|
const meta = readLocalMeta(dir);
|
|
25196
25792
|
return {
|
|
25197
|
-
slug: meta?.slug ??
|
|
25793
|
+
slug: meta?.slug ?? path39.basename(dir),
|
|
25198
25794
|
ref: meta?.branch ?? null,
|
|
25199
25795
|
versionId: versionFlag ?? meta?.versionId ?? null,
|
|
25200
25796
|
dir
|
|
@@ -25217,10 +25813,10 @@ function openTargetWorld(target, options) {
|
|
|
25217
25813
|
);
|
|
25218
25814
|
}
|
|
25219
25815
|
async function resolveTasks(target, args, creds) {
|
|
25220
|
-
const
|
|
25816
|
+
const one2 = arg.str(args, "task");
|
|
25221
25817
|
const all = arg.bool(args, "all");
|
|
25222
|
-
if (!
|
|
25223
|
-
const pinned =
|
|
25818
|
+
if (!one2 && !all) throw new CliError("pass --task <name> or --all");
|
|
25819
|
+
const pinned = one2 && !all ? [one2] : null;
|
|
25224
25820
|
if (pinned && (target.versionId || !target.ref))
|
|
25225
25821
|
return { tasks: pinned, versionId: target.versionId };
|
|
25226
25822
|
const world = await openTargetWorld(target, toOptions(creds));
|
|
@@ -25335,7 +25931,7 @@ function writeStepSummary(title, rows) {
|
|
|
25335
25931
|
...rows.map(([k, v]) => `| ${k} | ${v} |`)
|
|
25336
25932
|
];
|
|
25337
25933
|
try {
|
|
25338
|
-
|
|
25934
|
+
fs49.appendFileSync(summaryPath, lines.join("\n") + "\n\n");
|
|
25339
25935
|
} catch {
|
|
25340
25936
|
}
|
|
25341
25937
|
}
|
|
@@ -25424,8 +26020,8 @@ function registerRunCommands2(worlds) {
|
|
|
25424
26020
|
}
|
|
25425
26021
|
],
|
|
25426
26022
|
run: async (args, ctx) => {
|
|
25427
|
-
const dir =
|
|
25428
|
-
if (!
|
|
26023
|
+
const dir = path39.resolve(args.positionals[0]);
|
|
26024
|
+
if (!fs49.existsSync(dir) || !fs49.statSync(dir).isDirectory())
|
|
25429
26025
|
throw new CliError(`path is not a directory: ${args.positionals[0]}`);
|
|
25430
26026
|
const agentFile = arg.str(args, "agent");
|
|
25431
26027
|
const runConfig = arg.str(args, "run-config");
|
|
@@ -25464,14 +26060,14 @@ function registerRunCommands2(worlds) {
|
|
|
25464
26060
|
const { markdown, ...summary3 } = report;
|
|
25465
26061
|
ctx.stdout(JSON.stringify(summary3, null, 2));
|
|
25466
26062
|
if (summaryFile)
|
|
25467
|
-
|
|
26063
|
+
fs49.writeFileSync(
|
|
25468
26064
|
summaryFile,
|
|
25469
26065
|
JSON.stringify(summary3, null, 2) + "\n"
|
|
25470
26066
|
);
|
|
25471
26067
|
const stepSummary2 = process.env.GITHUB_STEP_SUMMARY;
|
|
25472
26068
|
if (stepSummary2) {
|
|
25473
26069
|
try {
|
|
25474
|
-
|
|
26070
|
+
fs49.appendFileSync(stepSummary2, markdown + "\n\n");
|
|
25475
26071
|
} catch {
|
|
25476
26072
|
}
|
|
25477
26073
|
}
|
|
@@ -25522,7 +26118,7 @@ function registerRunCommands2(worlds) {
|
|
|
25522
26118
|
const out = { ...summary2, branch, contentHash: pushed.contentHash };
|
|
25523
26119
|
ctx.stdout(JSON.stringify(out, null, 2));
|
|
25524
26120
|
if (summaryFile)
|
|
25525
|
-
|
|
26121
|
+
fs49.writeFileSync(summaryFile, JSON.stringify(out, null, 2) + "\n");
|
|
25526
26122
|
const rows = [
|
|
25527
26123
|
["avg reward", summary2.mean === null ? "n/a" : summary2.mean.toFixed(3)],
|
|
25528
26124
|
["tasks", String(summary2.results.length)],
|
|
@@ -25549,7 +26145,7 @@ init_shared();
|
|
|
25549
26145
|
|
|
25550
26146
|
// src/cli/platform/taskSpec.ts
|
|
25551
26147
|
init_router();
|
|
25552
|
-
import * as
|
|
26148
|
+
import * as fs50 from "fs";
|
|
25553
26149
|
var TASK_SPEC_HELP = 'A task spec is JSON:\n {"instruction": "<what the agent is told>",\n "name": "<optional>",\n "seed": {"mode": "append|replace", "rows": {"<entity>": [{...row}, ...]}}, # rows go UNDER seed.rows\n "grader": {"kind": "assertions", "checks": [{"entity": "<entity>", "where": {"<field>": <scalar>},\n "assert": "exists|absent|count|all|any",\n "count": {"eq"|"gte"|"lte": <n>}, # assert: count\n "field": "<field>", "op": "eq|neq|in|gt|gte|lt|lte|contains", "value": <scalar>}]} # assert: all|any\n | {"kind": "python", "source": "<verify.py body>", "timeoutSeconds"?: <n>}\n | {"kind": "rubric", "rubric": "<what the judge looks for>", "criteria"?: [{"id", "description", "weight"?}]},\n "tools": ["<tool>", ...], # optional allow-list\n "metadata": {...}, # optional, echoed back\n "worlds": {"<alias>": {"slug": "<world>", "ref"?: "<branch|tag|version id>", "seed"?, "grader"?, "tools"?}}, # multi-world: one session per alias\n "verifiers": [{"name": "<name>", "scope": ["<alias>", "<alias>", ...], "kind": "assertions|python", "checks"|"source": ...}]} # cross-world: entities as <alias>.<entity>, call logs as <alias>.calls\nWithout seed the session starts on the version\'s base data; without grader `grade` answers reward: null.\nWith worlds, seed/grader/tools live under each alias (not at the top level) and `worlds task up` opens the sessions.\nWithout worlds, a verifier runs on the session named by its first scope alias, so "name" must be that alias.';
|
|
25554
26150
|
var SPEC_KEYS = /* @__PURE__ */ new Set([
|
|
25555
26151
|
"name",
|
|
@@ -25832,7 +26428,7 @@ function taskSpecIssues(spec) {
|
|
|
25832
26428
|
function readTaskSpec(file, flag = "--spec") {
|
|
25833
26429
|
let parsed;
|
|
25834
26430
|
try {
|
|
25835
|
-
parsed = JSON.parse(
|
|
26431
|
+
parsed = JSON.parse(fs50.readFileSync(file, "utf8"));
|
|
25836
26432
|
} catch (error) {
|
|
25837
26433
|
throw new CliError(
|
|
25838
26434
|
`${flag} ${file}: ${error instanceof Error ? error.message : String(error)}`
|
|
@@ -25881,9 +26477,9 @@ async function loadTaskAgent(spec) {
|
|
|
25881
26477
|
const hash = spec.indexOf("#");
|
|
25882
26478
|
const file = hash === -1 ? spec : spec.slice(0, hash);
|
|
25883
26479
|
const exportName = hash === -1 ? void 0 : spec.slice(hash + 1);
|
|
25884
|
-
const abs =
|
|
25885
|
-
if (!
|
|
25886
|
-
const ext =
|
|
26480
|
+
const abs = path40.resolve(file);
|
|
26481
|
+
if (!fs51.existsSync(abs)) throw new CliError(`--agent ${spec} does not exist`);
|
|
26482
|
+
const ext = path40.extname(abs);
|
|
25887
26483
|
if (ext === ".ts" || ext === ".mts" || ext === ".cts")
|
|
25888
26484
|
await registerTypeScriptLoader(abs);
|
|
25889
26485
|
else if (![".js", ".mjs", ".cjs"].includes(ext))
|
|
@@ -25908,7 +26504,7 @@ function worldFromFlags(world, noWorld) {
|
|
|
25908
26504
|
}
|
|
25909
26505
|
function readJsonFile(file, what) {
|
|
25910
26506
|
try {
|
|
25911
|
-
return JSON.parse(
|
|
26507
|
+
return JSON.parse(fs51.readFileSync(file, "utf8"));
|
|
25912
26508
|
} catch (error) {
|
|
25913
26509
|
throw new CliError(
|
|
25914
26510
|
`${what} ${file}: ${error instanceof Error ? error.message : String(error)}`
|
|
@@ -25916,7 +26512,7 @@ function readJsonFile(file, what) {
|
|
|
25916
26512
|
}
|
|
25917
26513
|
}
|
|
25918
26514
|
function taskTarget(positional) {
|
|
25919
|
-
if (!
|
|
26515
|
+
if (!fs51.existsSync(positional)) return { kind: "id", taskId: positional };
|
|
25920
26516
|
const parsed = readJsonFile(positional, "task");
|
|
25921
26517
|
if (isTaskManifest(parsed)) return { kind: "manifest", manifest: parsed };
|
|
25922
26518
|
if (parsed && typeof parsed === "object" && typeof parsed.instruction === "string")
|
|
@@ -25933,12 +26529,12 @@ async function attachTarget(target, options) {
|
|
|
25933
26529
|
"a spec file has no sessions to act on; pass the task id or the manifest `task up` printed"
|
|
25934
26530
|
);
|
|
25935
26531
|
}
|
|
25936
|
-
var
|
|
26532
|
+
var TARGET_POSITIONAL2 = {
|
|
25937
26533
|
name: "task",
|
|
25938
26534
|
help: "Task id, or the manifest file `task up --out` wrote."
|
|
25939
26535
|
};
|
|
25940
26536
|
function emitManifest(ctx, manifest, out) {
|
|
25941
|
-
if (out)
|
|
26537
|
+
if (out) fs51.writeFileSync(out, JSON.stringify(manifest, null, 2) + "\n");
|
|
25942
26538
|
printJson(ctx, manifest);
|
|
25943
26539
|
if (out) ctx.stderr(`wrote the manifest to ${out}`);
|
|
25944
26540
|
}
|
|
@@ -26230,7 +26826,7 @@ function registerTaskCommands(root) {
|
|
|
26230
26826
|
task.command({
|
|
26231
26827
|
name: "down",
|
|
26232
26828
|
help: "Close every session of a task.",
|
|
26233
|
-
positionals: [
|
|
26829
|
+
positionals: [TARGET_POSITIONAL2],
|
|
26234
26830
|
flags: [
|
|
26235
26831
|
{
|
|
26236
26832
|
name: "keep-warm",
|
|
@@ -26289,7 +26885,7 @@ function registerTaskCommands(root) {
|
|
|
26289
26885
|
name: "status",
|
|
26290
26886
|
output: "json",
|
|
26291
26887
|
help: "Where every world of a task answers, and whether each is ready.",
|
|
26292
|
-
positionals: [
|
|
26888
|
+
positionals: [TARGET_POSITIONAL2],
|
|
26293
26889
|
flags: [HOST_FLAG],
|
|
26294
26890
|
notes: "Prints the same manifest `task up` did, read back from the platform. With a task id, lists that stored task's live\nsessions; an alias that is up twice is refused \u2014 pass the manifest.",
|
|
26295
26891
|
run: async (args, ctx) => {
|
|
@@ -26309,7 +26905,7 @@ function registerTaskCommands(root) {
|
|
|
26309
26905
|
task.command({
|
|
26310
26906
|
name: "grade",
|
|
26311
26907
|
help: "Grade every world of a task; prints per-world rewards and the aggregate.",
|
|
26312
|
-
positionals: [
|
|
26908
|
+
positionals: [TARGET_POSITIONAL2],
|
|
26313
26909
|
flags: [
|
|
26314
26910
|
{
|
|
26315
26911
|
name: "timeout",
|
|
@@ -26332,20 +26928,32 @@ function registerTaskCommands(root) {
|
|
|
26332
26928
|
});
|
|
26333
26929
|
task.command({
|
|
26334
26930
|
name: "export",
|
|
26335
|
-
help: "Every world's call
|
|
26336
|
-
positionals: [
|
|
26931
|
+
help: "Every world's call ledger as JSONL, one {world, seq, kind, tool, args, result, error, completedAt} per line; --requests appends each world's own request log.",
|
|
26932
|
+
positionals: [TARGET_POSITIONAL2],
|
|
26337
26933
|
flags: [
|
|
26338
26934
|
{ name: "out", help: "Write the JSONL here instead of stdout." },
|
|
26935
|
+
{
|
|
26936
|
+
name: "requests",
|
|
26937
|
+
help: 'Also append the world\'s own request log (kind "request"), read from the live session with one `state` call.',
|
|
26938
|
+
boolean: true
|
|
26939
|
+
},
|
|
26339
26940
|
HOST_FLAG
|
|
26340
26941
|
],
|
|
26341
|
-
notes: "Each line carries `world`, the alias whose session it came from; within a world, oldest first. The same records\n`session export` writes, prefixed so one file holds the whole task
|
|
26942
|
+
notes: "Each line carries `world`, the alias whose session it came from; within a world, oldest first. The same records\n`session export` writes, prefixed so one file holds the whole task.\n" + REQUEST_LOG_NOTES,
|
|
26342
26943
|
run: async (args, ctx) => {
|
|
26343
26944
|
const live = await attachTarget(
|
|
26344
26945
|
taskTarget(args.positionals[0]),
|
|
26345
26946
|
worldsOptions(credentials(args))
|
|
26346
26947
|
);
|
|
26347
26948
|
const exported = await live.export();
|
|
26949
|
+
const wanted = arg.bool(args, "requests");
|
|
26348
26950
|
const lines = [];
|
|
26951
|
+
let requests = 0;
|
|
26952
|
+
for (const [alias, session] of Object.entries(live.sessions)) {
|
|
26953
|
+
const logged = wanted ? await requestLines(session, ctx, alias) : [];
|
|
26954
|
+
requests += logged.length;
|
|
26955
|
+
exported[alias] = [...exported[alias] ?? [], ...logged];
|
|
26956
|
+
}
|
|
26349
26957
|
for (const [alias, calls] of Object.entries(exported))
|
|
26350
26958
|
for (const call3 of calls)
|
|
26351
26959
|
lines.push(
|
|
@@ -26363,9 +26971,9 @@ function registerTaskCommands(root) {
|
|
|
26363
26971
|
const text2 = lines.join("\n") + (lines.length ? "\n" : "");
|
|
26364
26972
|
const out = arg.str(args, "out");
|
|
26365
26973
|
if (out) {
|
|
26366
|
-
|
|
26974
|
+
fs51.writeFileSync(out, text2);
|
|
26367
26975
|
ctx.stdout(
|
|
26368
|
-
`wrote ${lines.length} calls from ${Object.keys(exported).length} worlds to ${out}`
|
|
26976
|
+
`wrote ${lines.length - requests} calls${wanted ? ` and ${requests} requests` : ""} from ${Object.keys(exported).length} worlds to ${out}`
|
|
26369
26977
|
);
|
|
26370
26978
|
} else if (text2) process.stdout.write(text2);
|
|
26371
26979
|
}
|
|
@@ -26526,30 +27134,9 @@ var EXPORT_KEYS = [
|
|
|
26526
27134
|
"tool"
|
|
26527
27135
|
];
|
|
26528
27136
|
async function surfacesJson(session) {
|
|
26529
|
-
const s = await session.surfaces();
|
|
26530
27137
|
return {
|
|
26531
27138
|
sessionId: session.sessionId,
|
|
26532
|
-
surfaces
|
|
26533
|
-
...s.api ? {
|
|
26534
|
-
api: {
|
|
26535
|
-
url: s.api.url,
|
|
26536
|
-
...s.api.token ? { token: s.api.token } : {}
|
|
26537
|
-
}
|
|
26538
|
-
} : {},
|
|
26539
|
-
...s.ui ? {
|
|
26540
|
-
ui: {
|
|
26541
|
-
url: s.ui.url,
|
|
26542
|
-
entry: uiEntryUrl(s.ui),
|
|
26543
|
-
apiPath: s.ui.apiPath ?? null
|
|
26544
|
-
}
|
|
26545
|
-
} : {},
|
|
26546
|
-
...s.browser ? {
|
|
26547
|
-
browser: {
|
|
26548
|
-
wsUrl: s.browser.wsUrl,
|
|
26549
|
-
viewport: s.browser.viewport,
|
|
26550
|
-
...s.browser.tier ? { tier: s.browser.tier } : {}
|
|
26551
|
-
}
|
|
26552
|
-
} : {}
|
|
27139
|
+
...surfaceDescriptor(await session.surfaces())
|
|
26553
27140
|
};
|
|
26554
27141
|
}
|
|
26555
27142
|
var sessionRoute = (id) => `/api/public/world-sessions/${encodeURIComponent(id)}`;
|
|
@@ -26750,7 +27337,7 @@ source (bundled|stored|inline|none)/name/hash/id/version.
|
|
|
26750
27337
|
});
|
|
26751
27338
|
session.command({
|
|
26752
27339
|
name: "list",
|
|
26753
|
-
help: "The project's
|
|
27340
|
+
help: "The project's sessions in every state, from provisioning to stopped, newest first \u2014 find one to attach to. The live ones are RUNNING and IDLE (`--state RUNNING`, `--state IDLE`). One line each: id, state, world, task, last used. A batch run's shard containers are not sessions and never appear.",
|
|
26754
27341
|
flags: [
|
|
26755
27342
|
{
|
|
26756
27343
|
name: "state",
|
|
@@ -26774,7 +27361,7 @@ source (bundled|stored|inline|none)/name/hash/id/version.
|
|
|
26774
27361
|
ctx,
|
|
26775
27362
|
args,
|
|
26776
27363
|
{ sessions },
|
|
26777
|
-
() => sessions.length === 0 ? ["No
|
|
27364
|
+
() => sessions.length === 0 ? ["No sessions. Open one with `gateway worlds session open <slug>`."] : sessions.map(
|
|
26778
27365
|
(s) => `${s.sessionId} ${s.state.padEnd(12)} ${s.slug} task=${s.taskName ?? "-"} lastUsed=${s.lastUsedAt}`
|
|
26779
27366
|
)
|
|
26780
27367
|
);
|
|
@@ -26806,7 +27393,7 @@ source (bundled|stored|inline|none)/name/hash/id/version.
|
|
|
26806
27393
|
try {
|
|
26807
27394
|
const url = await browser.goto(arg.str(args, "path"));
|
|
26808
27395
|
const shot = arg.str(args, "screenshot");
|
|
26809
|
-
if (shot)
|
|
27396
|
+
if (shot) fs52.writeFileSync(shot, await browser.screenshot());
|
|
26810
27397
|
printJson(ctx, {
|
|
26811
27398
|
url,
|
|
26812
27399
|
title: await browser.title(),
|
|
@@ -26955,13 +27542,19 @@ world's [redact] policy over the rows first; --redact refuse rejects plaintext i
|
|
|
26955
27542
|
});
|
|
26956
27543
|
session.command({
|
|
26957
27544
|
name: "export",
|
|
26958
|
-
help: "The session's call
|
|
27545
|
+
help: "The session's call ledger as JSONL, one {seq, kind, tool, args, result, error, completedAt} per line, oldest first: the calls the platform brokered (tool calls, seeds, grades, resets); --requests appends the world's own request log.",
|
|
26959
27546
|
positionals: [{ name: "session_id", help: "Session id." }],
|
|
26960
27547
|
flags: [
|
|
26961
27548
|
{ name: "out", help: "Write the JSONL here instead of stdout." },
|
|
27549
|
+
{
|
|
27550
|
+
name: "requests",
|
|
27551
|
+
help: 'Also append the world\'s own request log (kind "request"), read from the live session with one `state` call.',
|
|
27552
|
+
boolean: true
|
|
27553
|
+
},
|
|
26962
27554
|
TO_FLAG,
|
|
26963
27555
|
HOST_FLAG
|
|
26964
27556
|
],
|
|
27557
|
+
notes: REQUEST_LOG_NOTES,
|
|
26965
27558
|
run: async (args, ctx) => {
|
|
26966
27559
|
const sessionId = args.positionals[0];
|
|
26967
27560
|
const creds = credentials(args);
|
|
@@ -26978,26 +27571,29 @@ world's [redact] policy over the rows first; --redact refuse rejects plaintext i
|
|
|
26978
27571
|
calls.push(...page.calls);
|
|
26979
27572
|
cursor = page.nextCursor ?? void 0;
|
|
26980
27573
|
} while (cursor);
|
|
26981
|
-
const
|
|
27574
|
+
const requests = arg.bool(args, "requests") ? await requestLines(await attachSession(sessionId, worldsOptions(creds)), ctx, sessionId) : void 0;
|
|
27575
|
+
const ledger = calls.map(
|
|
26982
27576
|
(call3) => JSON.stringify(
|
|
26983
27577
|
Object.fromEntries(
|
|
26984
27578
|
EXPORT_KEYS.map((key2) => [key2, call3[key2] ?? null])
|
|
26985
27579
|
)
|
|
26986
27580
|
)
|
|
26987
27581
|
);
|
|
27582
|
+
const lines = [...ledger, ...(requests ?? []).map((line) => JSON.stringify(line))];
|
|
26988
27583
|
const text2 = lines.join("\n") + (lines.length ? "\n" : "");
|
|
27584
|
+
const counted = `${ledger.length} calls${requests ? ` and ${requests.length} requests` : ""}`;
|
|
26989
27585
|
const out = arg.str(args, "out");
|
|
26990
27586
|
const to = arg.str(args, "to");
|
|
26991
27587
|
if (out) {
|
|
26992
|
-
|
|
26993
|
-
ctx.stdout(`wrote ${
|
|
27588
|
+
fs52.writeFileSync(out, text2);
|
|
27589
|
+
ctx.stdout(`wrote ${counted} to ${out}`);
|
|
26994
27590
|
} else if (!to && text2) process.stdout.write(text2);
|
|
26995
27591
|
if (!to) return;
|
|
26996
27592
|
const scratch = out ? null : scratchFile(`${sessionId}.calls.jsonl`);
|
|
26997
|
-
if (scratch)
|
|
27593
|
+
if (scratch) fs52.writeFileSync(scratch.file, text2);
|
|
26998
27594
|
try {
|
|
26999
27595
|
const landed = await landInDrive(scratch?.file ?? out, to, creds);
|
|
27000
|
-
ctx.stdout(`wrote ${
|
|
27596
|
+
ctx.stdout(`wrote ${counted} to drive:${landed.path}`);
|
|
27001
27597
|
} finally {
|
|
27002
27598
|
scratch?.cleanup();
|
|
27003
27599
|
}
|
|
@@ -27054,7 +27650,7 @@ function taskEditTarget(positional, version) {
|
|
|
27054
27650
|
)
|
|
27055
27651
|
};
|
|
27056
27652
|
}
|
|
27057
|
-
function
|
|
27653
|
+
function client4(args) {
|
|
27058
27654
|
return new TaskEditClient(worldsOptions(credentials(args)));
|
|
27059
27655
|
}
|
|
27060
27656
|
async function call2(run) {
|
|
@@ -27086,7 +27682,7 @@ function registerTaskEditVerbs(root) {
|
|
|
27086
27682
|
args.positionals[0],
|
|
27087
27683
|
arg.int(args, "task-version")
|
|
27088
27684
|
);
|
|
27089
|
-
printJson(ctx, await call2(() =>
|
|
27685
|
+
printJson(ctx, await call2(() => client4(args).status(task)));
|
|
27090
27686
|
}
|
|
27091
27687
|
});
|
|
27092
27688
|
edit.command({
|
|
@@ -27117,7 +27713,7 @@ function registerTaskEditVerbs(root) {
|
|
|
27117
27713
|
printJson(
|
|
27118
27714
|
ctx,
|
|
27119
27715
|
await call2(
|
|
27120
|
-
() =>
|
|
27716
|
+
() => client4(args).close(task, {
|
|
27121
27717
|
requireAll: arg.bool(args, "require-all") || void 0,
|
|
27122
27718
|
force: arg.bool(args, "force") || void 0,
|
|
27123
27719
|
message: arg.str(args, "message")
|
|
@@ -27157,7 +27753,7 @@ function registerTaskEditVerbs(root) {
|
|
|
27157
27753
|
printJson(
|
|
27158
27754
|
ctx,
|
|
27159
27755
|
await call2(
|
|
27160
|
-
() =>
|
|
27756
|
+
() => client4(args).rollback(task, {
|
|
27161
27757
|
groupId,
|
|
27162
27758
|
force: arg.bool(args, "force") || void 0,
|
|
27163
27759
|
message: arg.str(args, "message")
|
|
@@ -27254,7 +27850,7 @@ function registerTaskRunSet(root) {
|
|
|
27254
27850
|
// src/cli/platform/traces.ts
|
|
27255
27851
|
init_config();
|
|
27256
27852
|
init_router();
|
|
27257
|
-
import * as
|
|
27853
|
+
import * as fs53 from "fs";
|
|
27258
27854
|
|
|
27259
27855
|
// src/traces/index.ts
|
|
27260
27856
|
init_worlds();
|
|
@@ -27471,7 +28067,7 @@ function registerTracesCommands(root) {
|
|
|
27471
28067
|
const scratch = toDrive ? scratchFile("traces.jsonl") : null;
|
|
27472
28068
|
const file = toStdout ? null : scratch?.file ?? out;
|
|
27473
28069
|
try {
|
|
27474
|
-
const sink = file ?
|
|
28070
|
+
const sink = file ? fs53.createWriteStream(file) : null;
|
|
27475
28071
|
const write = (record) => {
|
|
27476
28072
|
const line = JSON.stringify(record) + "\n";
|
|
27477
28073
|
if (sink) sink.write(line);
|
|
@@ -27479,7 +28075,7 @@ function registerTracesCommands(root) {
|
|
|
27479
28075
|
};
|
|
27480
28076
|
const limit = arg.int(args, "limit");
|
|
27481
28077
|
const summary2 = await exportTraces(worldsOptions(creds), filtersOf(args), { observations: arg.bool(args, "observations"), type, max: limit }, write);
|
|
27482
|
-
if (sink) await new Promise((
|
|
28078
|
+
if (sink) await new Promise((resolve32, reject) => sink.end((error) => error ? reject(error) : resolve32()));
|
|
27483
28079
|
const what = `${summary2.traces} traces${arg.bool(args, "observations") ? ` (${summary2.observations} observations)` : ""}`;
|
|
27484
28080
|
if (toDrive) ctx.stderr(`wrote ${what} to drive:${(await landInDrive(file, toDrive, creds)).path}`);
|
|
27485
28081
|
else ctx.stderr(toStdout ? `wrote ${what}` : `wrote ${what} to ${out}`);
|
|
@@ -27589,8 +28185,8 @@ function registerTracesCommands(root) {
|
|
|
27589
28185
|
});
|
|
27590
28186
|
}
|
|
27591
28187
|
function readFile2(file) {
|
|
27592
|
-
if (!
|
|
27593
|
-
return
|
|
28188
|
+
if (!fs53.existsSync(file)) throw new CliError(`${file} does not exist`, 1);
|
|
28189
|
+
return fs53.readFileSync(file, "utf8");
|
|
27594
28190
|
}
|
|
27595
28191
|
|
|
27596
28192
|
// src/cli/platform/worldData/chunks.ts
|
|
@@ -27789,6 +28385,7 @@ function registerPlatformCommands(root) {
|
|
|
27789
28385
|
registerReleaseCommands(root);
|
|
27790
28386
|
registerTracesCommands(root);
|
|
27791
28387
|
registerFilesCommands(root);
|
|
28388
|
+
registerDashboardCommands(root);
|
|
27792
28389
|
registerPythonOnlyCommands(root);
|
|
27793
28390
|
}
|
|
27794
28391
|
|
|
@@ -27800,8 +28397,8 @@ init_router();
|
|
|
27800
28397
|
init_config();
|
|
27801
28398
|
init_local();
|
|
27802
28399
|
init_client();
|
|
27803
|
-
import * as
|
|
27804
|
-
import * as
|
|
28400
|
+
import * as fs54 from "fs";
|
|
28401
|
+
import * as path41 from "path";
|
|
27805
28402
|
var HOST_FLAG4 = {
|
|
27806
28403
|
name: "host",
|
|
27807
28404
|
help: "Platform host (default: GATEWAY_HOST or the saved login).",
|
|
@@ -27831,10 +28428,10 @@ function wireParams(params) {
|
|
|
27831
28428
|
return names.size === list.length ? Object.fromEntries(list) : list;
|
|
27832
28429
|
}
|
|
27833
28430
|
function requireConnectorToml(dir) {
|
|
27834
|
-
const file =
|
|
27835
|
-
if (!
|
|
28431
|
+
const file = path41.join(dir, "connector.toml");
|
|
28432
|
+
if (!fs54.existsSync(file))
|
|
27836
28433
|
throw new CliError(`${dir} holds no connector.toml`, 1);
|
|
27837
|
-
return
|
|
28434
|
+
return fs54.readFileSync(file, "utf8");
|
|
27838
28435
|
}
|
|
27839
28436
|
function renderConnection(spec) {
|
|
27840
28437
|
const lines = [`${spec.slug} ${spec.baseUrl} auth=${spec.auth}`];
|
|
@@ -27868,7 +28465,7 @@ async function remoteCapture(creds, world, opts, ctx) {
|
|
|
27868
28465
|
const specText = requireConnectorToml(world);
|
|
27869
28466
|
const containerId = await resolveEnvironmentId2(
|
|
27870
28467
|
creds,
|
|
27871
|
-
opts.environment ??
|
|
28468
|
+
opts.environment ?? path41.basename(path41.resolve(world))
|
|
27872
28469
|
);
|
|
27873
28470
|
const base = `/api/public/environments/${encodeURIComponent(containerId)}`;
|
|
27874
28471
|
const params = wireParams(opts.params);
|
|
@@ -27911,8 +28508,8 @@ async function remoteCapture(creds, world, opts, ctx) {
|
|
|
27911
28508
|
const written = [];
|
|
27912
28509
|
for (const file of view.files ?? []) {
|
|
27913
28510
|
const drivePath2 = String(file.path);
|
|
27914
|
-
const
|
|
27915
|
-
if (!
|
|
28511
|
+
const relative6 = drivePath2.startsWith(slugPrefix) ? drivePath2.slice(slugPrefix.length) : drivePath2;
|
|
28512
|
+
if (!relative6.startsWith(`${CAPTURES}/`) || relative6.split("/").includes(".."))
|
|
27916
28513
|
throw new CliError(
|
|
27917
28514
|
`Refusing a capture outside ${CAPTURES}/: ${drivePath2}`,
|
|
27918
28515
|
1
|
|
@@ -27925,18 +28522,18 @@ async function remoteCapture(creds, world, opts, ctx) {
|
|
|
27925
28522
|
const res = await fetch(info.url);
|
|
27926
28523
|
if (!res.ok)
|
|
27927
28524
|
throw new CliError(`download ${drivePath2} -> ${res.status}`, 1);
|
|
27928
|
-
const destination =
|
|
27929
|
-
|
|
28525
|
+
const destination = path41.join(world, relative6);
|
|
28526
|
+
fs54.mkdirSync(path41.dirname(destination), { recursive: true });
|
|
27930
28527
|
const bytes = Buffer.from(await res.arrayBuffer());
|
|
27931
|
-
|
|
27932
|
-
written.push(
|
|
28528
|
+
fs54.writeFileSync(destination, bytes);
|
|
28529
|
+
written.push(relative6);
|
|
27933
28530
|
for (const name of undeclaredParams(bytes))
|
|
27934
28531
|
ctx.stderr(
|
|
27935
28532
|
`# note: ${name} is not declared by operation ${opts.op} in connector.toml; sent as given`
|
|
27936
28533
|
);
|
|
27937
28534
|
}
|
|
27938
|
-
const manifestPath2 =
|
|
27939
|
-
const existing =
|
|
28535
|
+
const manifestPath2 = path41.join(world, CAPTURES, MANIFEST);
|
|
28536
|
+
const existing = fs54.existsSync(manifestPath2) ? JSON.parse(fs54.readFileSync(manifestPath2, "utf8")) : [];
|
|
27940
28537
|
const known = new Set(
|
|
27941
28538
|
existing.map(
|
|
27942
28539
|
(e) => e && typeof e === "object" ? e.file : void 0
|
|
@@ -27949,8 +28546,8 @@ async function remoteCapture(creds, world, opts, ctx) {
|
|
|
27949
28546
|
existing.push(entry);
|
|
27950
28547
|
known.add(file);
|
|
27951
28548
|
}
|
|
27952
|
-
|
|
27953
|
-
|
|
28549
|
+
fs54.mkdirSync(path41.dirname(manifestPath2), { recursive: true });
|
|
28550
|
+
fs54.writeFileSync(manifestPath2, sortedJson(existing, 1) + "\n");
|
|
27954
28551
|
return written;
|
|
27955
28552
|
}
|
|
27956
28553
|
function outcomeOk(outcome) {
|
|
@@ -27977,7 +28574,7 @@ function registerConnectorCommands2(connector) {
|
|
|
27977
28574
|
],
|
|
27978
28575
|
flags: [HOST_FLAG4],
|
|
27979
28576
|
run: async (args, ctx) => {
|
|
27980
|
-
const dir =
|
|
28577
|
+
const dir = path41.resolve(args.positionals[0]);
|
|
27981
28578
|
requireConnectorToml(dir);
|
|
27982
28579
|
const creds = credentialsForRuntime(arg.str(args, "host"));
|
|
27983
28580
|
const res = await runtime(creds, {
|
|
@@ -27996,7 +28593,10 @@ function registerConnectorCommands2(connector) {
|
|
|
27996
28593
|
connector.command({
|
|
27997
28594
|
name: "capture",
|
|
27998
28595
|
help: "Call the live connection once (following its cursor) and record every page under captures/.",
|
|
27999
|
-
notes:
|
|
28596
|
+
notes: `The platform makes the calls (--remote) \u2014 from the pod whose IP the vendor allow-listed, with the
|
|
28597
|
+
credential held as the environment's secret (\`gateway secret set\`) \u2014 and the redacted pages land in
|
|
28598
|
+
captures/ here, ready for \`connector ingest\`. A local capture runs the vendor call from this machine
|
|
28599
|
+
and runs on this machine when a python3 >= ${MIN_PYTHON_LABEL} is installed (the CLI bundles the runtime).`,
|
|
28000
28600
|
positionals: [
|
|
28001
28601
|
{ name: "path", help: "World directory holding connector.toml" }
|
|
28002
28602
|
],
|
|
@@ -28030,14 +28630,14 @@ function registerConnectorCommands2(connector) {
|
|
|
28030
28630
|
HOST_FLAG4
|
|
28031
28631
|
],
|
|
28032
28632
|
run: async (args, ctx) => {
|
|
28033
|
-
const dir =
|
|
28633
|
+
const dir = path41.resolve(args.positionals[0]);
|
|
28034
28634
|
const op = arg.str(args, "op");
|
|
28035
28635
|
if (!op) throw new CliError("capture needs --op");
|
|
28036
28636
|
if (!arg.bool(args, "remote")) {
|
|
28037
28637
|
const local = localRuntime();
|
|
28038
28638
|
if (!local)
|
|
28039
28639
|
throw new CliError(
|
|
28040
|
-
`local capture runs the vendor call from this machine and needs python3 >=
|
|
28640
|
+
`local capture runs the vendor call from this machine and needs python3 >= ${MIN_PYTHON_LABEL} (the CLI bundles the runtime). ${localRuntimeReason()} Or use --remote to capture from the platform.`
|
|
28041
28641
|
);
|
|
28042
28642
|
const argv = ["connector-capture", dir, "--op", op];
|
|
28043
28643
|
for (const pair3 of arg.list(args, "arg")) argv.push("--arg", pair3);
|
|
@@ -28080,17 +28680,17 @@ function registerConnectorCommands2(connector) {
|
|
|
28080
28680
|
HOST_FLAG4
|
|
28081
28681
|
],
|
|
28082
28682
|
run: async (args, ctx) => {
|
|
28083
|
-
const dir =
|
|
28683
|
+
const dir = path41.resolve(args.positionals[0]);
|
|
28084
28684
|
const documents = arg.list(args, "openapi");
|
|
28085
28685
|
if (!documents.length)
|
|
28086
28686
|
throw new CliError("conform needs --openapi FILE (repeatable)");
|
|
28087
28687
|
requireConnectorToml(dir);
|
|
28088
28688
|
const openapi = documents.map((file) => {
|
|
28089
|
-
if (!
|
|
28689
|
+
if (!fs54.existsSync(file))
|
|
28090
28690
|
throw new CliError(`--openapi ${file} does not exist`);
|
|
28091
28691
|
return {
|
|
28092
|
-
path:
|
|
28093
|
-
content:
|
|
28692
|
+
path: path41.basename(file),
|
|
28693
|
+
content: fs54.readFileSync(file).toString("base64")
|
|
28094
28694
|
};
|
|
28095
28695
|
});
|
|
28096
28696
|
const limit = arg.int(args, "limit");
|
|
@@ -28108,7 +28708,7 @@ function registerConnectorCommands2(connector) {
|
|
|
28108
28708
|
ctx.stdout(JSON.stringify(summary2));
|
|
28109
28709
|
const out = arg.str(args, "out");
|
|
28110
28710
|
if (out) {
|
|
28111
|
-
|
|
28711
|
+
fs54.writeFileSync(out, JSON.stringify(report, null, 1) + "\n");
|
|
28112
28712
|
ctx.stdout(`report: ${out}`);
|
|
28113
28713
|
}
|
|
28114
28714
|
return Number(summary2.status_mismatch) || Number(summary2.schema_violations) ? 1 : 0;
|
|
@@ -28136,8 +28736,8 @@ function registerConnectorCommands2(connector) {
|
|
|
28136
28736
|
],
|
|
28137
28737
|
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.",
|
|
28138
28738
|
run: async (args, ctx) => {
|
|
28139
|
-
const dir =
|
|
28140
|
-
if (!
|
|
28739
|
+
const dir = path41.resolve(args.positionals[0]);
|
|
28740
|
+
if (!fs54.existsSync(path41.join(dir, CAPTURES)))
|
|
28141
28741
|
throw new CliError(
|
|
28142
28742
|
`${dir} holds no ${CAPTURES}/ \u2014 run \`connector capture --remote\` first`,
|
|
28143
28743
|
1
|
|
@@ -28168,7 +28768,7 @@ function registerConnectorCommands2(connector) {
|
|
|
28168
28768
|
` ${refusal.capture ?? "?"} ${refusal.pointer}: ${refusal.detail}`
|
|
28169
28769
|
);
|
|
28170
28770
|
if (report) {
|
|
28171
|
-
|
|
28771
|
+
fs54.writeFileSync(
|
|
28172
28772
|
report,
|
|
28173
28773
|
refusals.map((r) => JSON.stringify(r) + "\n").join("")
|
|
28174
28774
|
);
|
|
@@ -28201,13 +28801,37 @@ init_worlds();
|
|
|
28201
28801
|
init_session2();
|
|
28202
28802
|
init_hub();
|
|
28203
28803
|
init_local();
|
|
28204
|
-
import * as
|
|
28205
|
-
import * as
|
|
28804
|
+
import * as fs55 from "fs";
|
|
28805
|
+
import * as path42 from "path";
|
|
28206
28806
|
function registerServeCommand(worlds) {
|
|
28207
28807
|
worlds.command({
|
|
28208
28808
|
name: "serve",
|
|
28209
28809
|
help: "Serve one session of the world here (bundled runtime + python3): its tools over HTTP, the vendor routes when it has them, its ui on its own port when it declares one; or open a hosted api session when no Python is installed.",
|
|
28210
|
-
notes:
|
|
28810
|
+
notes: `With a python3 >= ${MIN_PYTHON_LABEL} on this machine the CLI serves the world here from its bundled runtime
|
|
28811
|
+
(the same files the platform runs), on --port, in the foreground, as ONE session with state that
|
|
28812
|
+
lasts until you stop it or a client closes it. Every schema world gets the session verbs (loopback,
|
|
28813
|
+
no credential), the surface an outside agent acts on:
|
|
28814
|
+
GET /__session/task {task, prompt, tools, verifiers, worlds: {alias: [verifiers]}}
|
|
28815
|
+
GET /__session/tools what it serves: the tools and the connector.toml operations (a dependency's tools as alias.tool)
|
|
28816
|
+
POST /__session/call {tool, args} -> {status, body}, as a hosted session answers; an operation by name too
|
|
28817
|
+
GET /__session/state rows per entity (a dependency's under worlds.<alias>)
|
|
28818
|
+
POST /__session/grade {reward, rewards}: the root's verifiers by name, a dependency's as alias/name
|
|
28819
|
+
POST /__session/seed {rows: {entity: [row, ...]}, mode?: append|replace} (a dependency's entity as alias.entity; a
|
|
28820
|
+
bare {entity: [row, ...]} is taken as rows); POST /__session/reset back to the start
|
|
28821
|
+
POST /__session/close end the session; this command returns
|
|
28822
|
+
--task <id> opens the session on one of the world's tasks: its prompt is in the banner and at
|
|
28823
|
+
/__session/task, its verifiers grade, and each dependency starts in the scenario its link's \`task\`
|
|
28824
|
+
names. \`gateway worlds call <url> <tool> [--grade] [--close]\` acts on the session from another shell.
|
|
28825
|
+
A world with a connector.toml serves its vendor routes beside them, and with \`[ui]\` its page on its own
|
|
28826
|
+
port (--ui-port, default the port after --port) at /, the layout the host serves it in, so a frontend
|
|
28827
|
+
built for the root works unchanged; the same page is at /__ui/ on --port. The page's api_path calls are
|
|
28828
|
+
answered with the pin; the bare routes still need it. \`[dependencies]\` entries with
|
|
28829
|
+
a \`path\` open beside the root. A --port another process holds is refused by name (its pid when lsof
|
|
28830
|
+
can see it): this serve never answers from another server. The runtime closes when the process that
|
|
28831
|
+
started it is gone, so a killed CLI leaves no server on the port. Without a python3 it does what \`gateway worlds session open <slug>
|
|
28832
|
+
--task <scenario> --surface api --no-wait\` does: the platform serves the world's vendor API for one
|
|
28833
|
+
session, and the session id + api url are printed. Close it with \`gateway worlds session close <id>\`.
|
|
28834
|
+
GATEWAY_RUNTIME=platform forces the hosted path.`,
|
|
28211
28835
|
positionals: [
|
|
28212
28836
|
{
|
|
28213
28837
|
name: "path",
|
|
@@ -28234,7 +28858,7 @@ function registerServeCommand(worlds) {
|
|
|
28234
28858
|
},
|
|
28235
28859
|
{
|
|
28236
28860
|
name: "api-key",
|
|
28237
|
-
help: "Pin the credential the local server accepts (a hosted session carries its own)."
|
|
28861
|
+
help: "Pin the credential the local server accepts (default `conform`; a hosted session carries its own)."
|
|
28238
28862
|
},
|
|
28239
28863
|
{
|
|
28240
28864
|
name: "host",
|
|
@@ -28245,14 +28869,14 @@ function registerServeCommand(worlds) {
|
|
|
28245
28869
|
run: async (args, ctx) => {
|
|
28246
28870
|
const target = args.positionals[0];
|
|
28247
28871
|
const local = localRuntime();
|
|
28248
|
-
if (local &&
|
|
28872
|
+
if (local && fs55.existsSync(target) && fs55.statSync(target).isDirectory()) {
|
|
28249
28873
|
const port = arg.int(args, "port") ?? 8080;
|
|
28250
28874
|
if (!Number.isInteger(port) || port < 0 || port > 65535)
|
|
28251
28875
|
throw new CliError(
|
|
28252
28876
|
`--port must be a port number (got ${String(args.flags.port)})`
|
|
28253
28877
|
);
|
|
28254
28878
|
if (port !== 0) await assertPortFree(port);
|
|
28255
|
-
const argv = ["serve",
|
|
28879
|
+
const argv = ["serve", path42.resolve(target), "--port", String(port)];
|
|
28256
28880
|
const apiKey = arg.str(args, "api-key");
|
|
28257
28881
|
if (apiKey) argv.push("--api-key", apiKey);
|
|
28258
28882
|
const uiPort = arg.str(args, "ui-port");
|
|
@@ -28262,11 +28886,11 @@ function registerServeCommand(worlds) {
|
|
|
28262
28886
|
const task = arg.str(args, "task");
|
|
28263
28887
|
if (task) argv.push("--task", task);
|
|
28264
28888
|
ctx.stderr(
|
|
28265
|
-
`# serving ${
|
|
28889
|
+
`# serving ${path42.resolve(target)} on http://127.0.0.1:${port} (local runtime: ${local.python})`
|
|
28266
28890
|
);
|
|
28267
28891
|
return localModule(argv, local);
|
|
28268
28892
|
}
|
|
28269
|
-
if (!local &&
|
|
28893
|
+
if (!local && fs55.existsSync(target) && fs55.statSync(target).isDirectory())
|
|
28270
28894
|
ctx.stderr(
|
|
28271
28895
|
`# ${localRuntimeReason()}
|
|
28272
28896
|
# 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).`
|
|
@@ -28279,17 +28903,17 @@ function registerServeCommand(worlds) {
|
|
|
28279
28903
|
};
|
|
28280
28904
|
let slugRef = target;
|
|
28281
28905
|
let versionId;
|
|
28282
|
-
if (
|
|
28283
|
-
const dir =
|
|
28906
|
+
if (fs55.existsSync(target) && fs55.statSync(target).isDirectory()) {
|
|
28907
|
+
const dir = path42.resolve(target);
|
|
28284
28908
|
const meta = readLocalMeta(dir);
|
|
28285
|
-
const slug = meta?.slug ??
|
|
28909
|
+
const slug = meta?.slug ?? path42.basename(dir);
|
|
28286
28910
|
slugRef = meta?.branch ? `${slug}@${meta.branch}` : slug;
|
|
28287
28911
|
versionId = meta?.versionId;
|
|
28288
28912
|
}
|
|
28289
28913
|
ctx.stderr(
|
|
28290
28914
|
"`worlds serve` runs a local session with the Python runtime; opening a hosted api-surface session instead."
|
|
28291
28915
|
);
|
|
28292
|
-
if (!local && !(
|
|
28916
|
+
if (!local && !(fs55.existsSync(target) && fs55.statSync(target).isDirectory())) ctx.stderr(`# ${localRuntimeReason()}`);
|
|
28293
28917
|
let scenario = arg.str(args, "scenario") ?? arg.str(args, "task");
|
|
28294
28918
|
if (!scenario) {
|
|
28295
28919
|
const world = await openWorld(slugRef, options);
|
|
@@ -28332,8 +28956,8 @@ init_shared();
|
|
|
28332
28956
|
init_local();
|
|
28333
28957
|
init_config();
|
|
28334
28958
|
init_client();
|
|
28335
|
-
import * as
|
|
28336
|
-
import * as
|
|
28959
|
+
import * as fs56 from "fs";
|
|
28960
|
+
import * as path43 from "path";
|
|
28337
28961
|
function renderWorldTestReport(report) {
|
|
28338
28962
|
const lines = [];
|
|
28339
28963
|
let group = null;
|
|
@@ -28351,7 +28975,7 @@ function renderWorldTestReport(report) {
|
|
|
28351
28975
|
}
|
|
28352
28976
|
const py = report.python;
|
|
28353
28977
|
if (py && py.status !== "none") {
|
|
28354
|
-
const detail = py.status === "skipped" ?
|
|
28978
|
+
const detail = py.reason ?? (py.status === "skipped" ? "skipped" : `${py.tests ?? 0} tests, ${py.failures ?? 0} failures, ${py.errors ?? 0} errors`);
|
|
28355
28979
|
lines.push(
|
|
28356
28980
|
`${py.status === "passed" ? " ok " : py.status === "skipped" ? "skip" : "FAIL"} python tests (${(py.files ?? []).join(", ")}) ${detail}`
|
|
28357
28981
|
);
|
|
@@ -28388,8 +29012,8 @@ function registerTestCommand(worlds) {
|
|
|
28388
29012
|
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 and\nWORLD_API_KEY set (a Python without pytest FAILS the suite, it never skips it). No tests/ directory passes as\nzero cases. With `[actions] on_push = ["tests"]` in gateway-env.toml the platform runs the same suite on\nevery push; `gateway bench tests <slug>` reads those runs. Exit 1 when any test fails.',
|
|
28389
29013
|
run: async (args, ctx) => {
|
|
28390
29014
|
const target = args.positionals[0] ?? ".";
|
|
28391
|
-
const dir =
|
|
28392
|
-
if (!
|
|
29015
|
+
const dir = path43.resolve(target);
|
|
29016
|
+
if (!fs56.existsSync(dir) || !fs56.statSync(dir).isDirectory()) {
|
|
28393
29017
|
if (/[\/\\]/.test(target) || target.startsWith("."))
|
|
28394
29018
|
throw new CliError(`Not a directory: ${dir}`, 1);
|
|
28395
29019
|
const creds2 = resolveCredentials(arg.str(args, "host"));
|
|
@@ -28420,7 +29044,7 @@ function registerTestCommand(worlds) {
|
|
|
28420
29044
|
`Test run ${run.id} still ${run.state} after 15 minutes`,
|
|
28421
29045
|
1
|
|
28422
29046
|
);
|
|
28423
|
-
await new Promise((
|
|
29047
|
+
await new Promise((resolve32) => setTimeout(resolve32, 2e3));
|
|
28424
29048
|
try {
|
|
28425
29049
|
run = (await api(
|
|
28426
29050
|
creds2,
|
|
@@ -28439,6 +29063,7 @@ function registerTestCommand(worlds) {
|
|
|
28439
29063
|
{
|
|
28440
29064
|
runId: run.id,
|
|
28441
29065
|
state: run.state,
|
|
29066
|
+
trigger: run.trigger ?? null,
|
|
28442
29067
|
versionId: run.versionId,
|
|
28443
29068
|
...report2
|
|
28444
29069
|
},
|
|
@@ -28450,18 +29075,19 @@ function registerTestCommand(worlds) {
|
|
|
28450
29075
|
for (const line of renderWorldTestReport(report2)) ctx.stdout(line);
|
|
28451
29076
|
const s = run.summary ?? report2.summary ?? {};
|
|
28452
29077
|
ctx.stdout(
|
|
28453
|
-
`${run.state}: ${s.passed ?? 0} passed, ${s.failed ?? 0} failed, ${s.skipped ?? 0} skipped (run ${run.id} on ${run.versionId})`
|
|
29078
|
+
`${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})`
|
|
28454
29079
|
);
|
|
28455
29080
|
if (run.error) ctx.stdout(`error: ${run.error}`);
|
|
28456
29081
|
}
|
|
28457
29082
|
const out2 = arg.str(args, "out");
|
|
28458
29083
|
if (out2)
|
|
28459
|
-
|
|
29084
|
+
fs56.writeFileSync(
|
|
28460
29085
|
out2,
|
|
28461
29086
|
JSON.stringify(
|
|
28462
29087
|
{
|
|
28463
29088
|
runId: run.id,
|
|
28464
29089
|
state: run.state,
|
|
29090
|
+
trigger: run.trigger ?? null,
|
|
28465
29091
|
versionId: run.versionId,
|
|
28466
29092
|
...report2
|
|
28467
29093
|
},
|
|
@@ -28484,8 +29110,8 @@ function registerTestCommand(worlds) {
|
|
|
28484
29110
|
for (const line of renderWorldTestReport(report)) ctx.stdout(line);
|
|
28485
29111
|
const s = report.summary ?? {};
|
|
28486
29112
|
if (!(s.total ?? 0) && !(report.python?.files?.length ?? 0)) {
|
|
28487
|
-
const tests =
|
|
28488
|
-
const state2 =
|
|
29113
|
+
const tests = path43.join(dir, "tests");
|
|
29114
|
+
const state2 = fs56.existsSync(tests) ? "holds none" : "does not exist";
|
|
28489
29115
|
ctx.stdout(`no cases: ${tests} ${state2} (see \`gateway worlds test --help\` for the shapes)`);
|
|
28490
29116
|
}
|
|
28491
29117
|
ctx.stdout(
|
|
@@ -28494,7 +29120,7 @@ function registerTestCommand(worlds) {
|
|
|
28494
29120
|
}
|
|
28495
29121
|
const out = arg.str(args, "out");
|
|
28496
29122
|
if (out) {
|
|
28497
|
-
|
|
29123
|
+
fs56.writeFileSync(out, JSON.stringify(report, null, 1) + "\n");
|
|
28498
29124
|
ctx.stdout(`report: ${out}`);
|
|
28499
29125
|
}
|
|
28500
29126
|
return report.summary?.status === "passed" ? 0 : 1;
|
|
@@ -28510,16 +29136,16 @@ init_shared();
|
|
|
28510
29136
|
init_local();
|
|
28511
29137
|
init_client();
|
|
28512
29138
|
init_storeContract();
|
|
28513
|
-
import * as
|
|
28514
|
-
import * as
|
|
29139
|
+
import * as fs57 from "fs";
|
|
29140
|
+
import * as path44 from "path";
|
|
28515
29141
|
function parseArgs2(raw, stdin) {
|
|
28516
29142
|
if (raw === void 0) return {};
|
|
28517
29143
|
let text2 = raw;
|
|
28518
29144
|
if (raw === "-") text2 = stdin;
|
|
28519
29145
|
else if (raw.startsWith("@")) {
|
|
28520
29146
|
const file = raw.slice(1);
|
|
28521
|
-
if (!
|
|
28522
|
-
text2 =
|
|
29147
|
+
if (!fs57.existsSync(file)) throw new CliError(`--args ${raw}: ${file} does not exist`);
|
|
29148
|
+
text2 = fs57.readFileSync(file, "utf8");
|
|
28523
29149
|
}
|
|
28524
29150
|
let value;
|
|
28525
29151
|
try {
|
|
@@ -28594,7 +29220,7 @@ async function callHosted(sessionId, tool, args, wants, options) {
|
|
|
28594
29220
|
return settleStatus(report);
|
|
28595
29221
|
}
|
|
28596
29222
|
function looksLikeSessionId(target) {
|
|
28597
|
-
return !target.includes("/") && !target.startsWith(".") && !
|
|
29223
|
+
return !target.includes("/") && !target.startsWith(".") && !fs57.existsSync(target);
|
|
28598
29224
|
}
|
|
28599
29225
|
async function callServed(base, tool, args, wants) {
|
|
28600
29226
|
const url = base.replace(/\/+$/, "");
|
|
@@ -28653,7 +29279,14 @@ function registerCallCommand(worlds) {
|
|
|
28653
29279
|
{ name: "close", help: "On a served session (url) or a hosted one (id): end it after the call.", boolean: true },
|
|
28654
29280
|
HOST_FLAG
|
|
28655
29281
|
],
|
|
28656
|
-
notes:
|
|
29282
|
+
notes: `The world is opened in place, so \`[dependencies]\` entries with a \`path\` open beside it and their tools
|
|
29283
|
+
answer as alias.tool; a pin without a path is refused here (add path = "../<dir>"). The world's handlers
|
|
29284
|
+
run on this machine through the bundled runtime (a python3 >= ${MIN_PYTHON_LABEL}); the platform never runs them for you.
|
|
29285
|
+
Exit 0 when the tool answered 2xx, 1 otherwise: a refused call (unknown tool, arguments off the schema, a
|
|
29286
|
+
tool outside --task's allow-list) prints the refusal. A handler's own bug (an AttributeError, TypeError or
|
|
29287
|
+
NameError \u2014 say store.upsert, which does not exist) is a 400 {error: "handler", detail, handler}; anything
|
|
29288
|
+
else the handler raises is a 500 {error: "engine", detail, handler}. Never a bare exception string.
|
|
29289
|
+
` + STORE_API_NOTE + `
|
|
28657
29290
|
With a url (the \`url\` \`gateway worlds serve <dir> --task <id>\` prints) the call goes to THAT session over
|
|
28658
29291
|
POST /__session/call, so state carries from call to call, --state/--grade read it, and --close ends it;
|
|
28659
29292
|
--task and --scenario belong to the serve. This is the outside-agent path: any HTTP client does the same.
|
|
@@ -28713,8 +29346,8 @@ Examples:
|
|
|
28713
29346
|
}
|
|
28714
29347
|
}
|
|
28715
29348
|
if (arg.bool(args, "close")) throw new CliError("--close ends a served or hosted session; pass its url or id instead of a directory");
|
|
28716
|
-
const dir =
|
|
28717
|
-
if (!
|
|
29349
|
+
const dir = path44.resolve(target);
|
|
29350
|
+
if (!fs57.existsSync(dir) || !fs57.statSync(dir).isDirectory()) throw new CliError(`Not a directory: ${dir}`, 1);
|
|
28718
29351
|
const local = localRuntime();
|
|
28719
29352
|
if (!local)
|
|
28720
29353
|
throw new CliError(
|
|
@@ -28751,12 +29384,12 @@ Examples:
|
|
|
28751
29384
|
|
|
28752
29385
|
// src/cli/runtime/scaffold.ts
|
|
28753
29386
|
init_router();
|
|
28754
|
-
import * as
|
|
28755
|
-
import * as
|
|
29387
|
+
import * as fs61 from "fs";
|
|
29388
|
+
import * as path47 from "path";
|
|
28756
29389
|
|
|
28757
29390
|
// src/cli/runtime/scaffoldJson.ts
|
|
28758
29391
|
init_router();
|
|
28759
|
-
import * as
|
|
29392
|
+
import * as fs58 from "fs";
|
|
28760
29393
|
var PROPERTY_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
28761
29394
|
var isObject12 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
28762
29395
|
function resolveObjectSchema(root, schema) {
|
|
@@ -28770,10 +29403,10 @@ function resolveObjectSchema(root, schema) {
|
|
|
28770
29403
|
return schema;
|
|
28771
29404
|
}
|
|
28772
29405
|
function readJsonFile2(file) {
|
|
28773
|
-
if (!
|
|
29406
|
+
if (!fs58.existsSync(file)) throw new CliError(`${file} does not exist; run \`gateway worlds schema init\` first`, 1);
|
|
28774
29407
|
let parsed;
|
|
28775
29408
|
try {
|
|
28776
|
-
parsed = JSON.parse(
|
|
29409
|
+
parsed = JSON.parse(fs58.readFileSync(file, "utf8"));
|
|
28777
29410
|
} catch (err) {
|
|
28778
29411
|
throw new CliError(`${file} is not valid JSON: ${err.message}`, 1);
|
|
28779
29412
|
}
|
|
@@ -28798,7 +29431,7 @@ function keyGenerators(spec, entities) {
|
|
|
28798
29431
|
return { [field2]: type === "integer" ? "int" : "uuid" };
|
|
28799
29432
|
}
|
|
28800
29433
|
var tomlString = (value) => JSON.stringify(value);
|
|
28801
|
-
var pathArgs = (
|
|
29434
|
+
var pathArgs = (path49) => [...path49.matchAll(PATH_ARGUMENT)].map((m) => m[1]);
|
|
28802
29435
|
function unboundPathArgs(spec, entities) {
|
|
28803
29436
|
if (spec.api.action === "handler") return [];
|
|
28804
29437
|
const fields = entities?.[spec.entity ?? ""]?.fields ?? [];
|
|
@@ -28998,6 +29631,214 @@ function declaredEntityShapes(root) {
|
|
|
28998
29631
|
return shapes;
|
|
28999
29632
|
}
|
|
29000
29633
|
|
|
29634
|
+
// src/cli/runtime/scaffoldEntityRemove.ts
|
|
29635
|
+
init_router();
|
|
29636
|
+
import * as fs59 from "fs";
|
|
29637
|
+
import * as path45 from "path";
|
|
29638
|
+
var LOCAL_DEF = "#/$defs/";
|
|
29639
|
+
function localRefs(value, found = /* @__PURE__ */ new Set()) {
|
|
29640
|
+
if (Array.isArray(value)) value.forEach((item) => localRefs(item, found));
|
|
29641
|
+
if (!isObject12(value)) return found;
|
|
29642
|
+
for (const [key2, child] of Object.entries(value)) {
|
|
29643
|
+
if (key2 === "$ref" && typeof child === "string" && child.startsWith(LOCAL_DEF)) found.add(child.slice(LOCAL_DEF.length));
|
|
29644
|
+
else localRefs(child, found);
|
|
29645
|
+
}
|
|
29646
|
+
return found;
|
|
29647
|
+
}
|
|
29648
|
+
function closure(start, defs) {
|
|
29649
|
+
const reached = /* @__PURE__ */ new Set();
|
|
29650
|
+
const pending = [...start];
|
|
29651
|
+
while (pending.length) {
|
|
29652
|
+
const name = pending.pop();
|
|
29653
|
+
if (reached.has(name)) continue;
|
|
29654
|
+
reached.add(name);
|
|
29655
|
+
pending.push(...localRefs(defs[name]));
|
|
29656
|
+
}
|
|
29657
|
+
return reached;
|
|
29658
|
+
}
|
|
29659
|
+
var escaped = (text2) => text2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
29660
|
+
var sqlMentions = (sql, name) => new RegExp(`(^|[^A-Za-z0-9_])"?${escaped(name)}"?([^A-Za-z0-9_]|$)`, "i").test(sql.replace(/--[^\n]*/g, ""));
|
|
29661
|
+
var EntityRemoval = class _EntityRemoval {
|
|
29662
|
+
constructor(dir, file, root) {
|
|
29663
|
+
this.dir = dir;
|
|
29664
|
+
this.file = file;
|
|
29665
|
+
this.root = root;
|
|
29666
|
+
}
|
|
29667
|
+
dir;
|
|
29668
|
+
file;
|
|
29669
|
+
root;
|
|
29670
|
+
static open(dir) {
|
|
29671
|
+
const file = path45.join(dir, "schema", "world.json");
|
|
29672
|
+
if (!fs59.existsSync(file)) throw new CliError(`${dir} has no schema/world.json`);
|
|
29673
|
+
return new _EntityRemoval(dir, file, readJsonFile2(file));
|
|
29674
|
+
}
|
|
29675
|
+
get entities() {
|
|
29676
|
+
const gateway = this.root["x-gateway"];
|
|
29677
|
+
if (!isObject12(gateway) || !isObject12(gateway.entities))
|
|
29678
|
+
throw new CliError("schema/world.json is not a gateway-world/1 root: it has no x-gateway.entities");
|
|
29679
|
+
return gateway.entities;
|
|
29680
|
+
}
|
|
29681
|
+
read(rel) {
|
|
29682
|
+
const file = path45.join(this.dir, rel);
|
|
29683
|
+
return fs59.existsSync(file) ? fs59.readFileSync(file, "utf8") : void 0;
|
|
29684
|
+
}
|
|
29685
|
+
relationships(name) {
|
|
29686
|
+
return Object.entries(this.entities).filter(([other]) => other !== name).filter(
|
|
29687
|
+
([, declaration]) => isObject12(declaration) && Array.isArray(declaration.relationships) ? declaration.relationships.some((r) => isObject12(r) && r.target === name) : false
|
|
29688
|
+
).map(([other]) => `entity ${other} relates to ${name}`);
|
|
29689
|
+
}
|
|
29690
|
+
routes(name) {
|
|
29691
|
+
const found = [];
|
|
29692
|
+
let operation;
|
|
29693
|
+
let named2 = false;
|
|
29694
|
+
for (const line of (this.read("connector.toml") ?? "").split("\n").map((l) => l.trim())) {
|
|
29695
|
+
if (line === "[[operations]]") [operation, named2] = [void 0, false];
|
|
29696
|
+
const key2 = /^(name|entity)\s*=\s*["']([^"']*)["']/.exec(line);
|
|
29697
|
+
if (key2?.[1] === "name" && !named2) [operation, named2] = [key2[2], true];
|
|
29698
|
+
if (key2?.[1] === "entity" && key2[2] === name) found.push(`connector.toml operation ${operation ?? "?"} answers from ${name}`);
|
|
29699
|
+
}
|
|
29700
|
+
return [...new Set(found)];
|
|
29701
|
+
}
|
|
29702
|
+
verifiers(name) {
|
|
29703
|
+
const placeholder = path45.join(this.dir, "verifiers", "state_present.sql");
|
|
29704
|
+
return (verifierNames(this.dir) ?? []).map((verifier) => path45.join(this.dir, "verifiers", `${verifier}.sql`)).filter((file) => !(file === placeholder && scaffoldVerifierEntity(file) === name)).filter((file) => sqlMentions(fs59.readFileSync(file, "utf8"), name)).map((file) => `verifiers/${path45.basename(file)} reads ${name}`);
|
|
29705
|
+
}
|
|
29706
|
+
data(name) {
|
|
29707
|
+
const text2 = this.read(path45.join("data", "initial.json"));
|
|
29708
|
+
if (text2 === void 0) return [];
|
|
29709
|
+
const journal = this.journal(text2);
|
|
29710
|
+
const rows = (journal.mutations ?? []).filter((m) => m.entity === name).length;
|
|
29711
|
+
return rows ? [`data/initial.json holds ${rows} ${name} row(s)`] : [];
|
|
29712
|
+
}
|
|
29713
|
+
journal(text2) {
|
|
29714
|
+
try {
|
|
29715
|
+
return JSON.parse(text2);
|
|
29716
|
+
} catch {
|
|
29717
|
+
throw new CliError("data/initial.json is not valid JSON; fix it before removing an entity");
|
|
29718
|
+
}
|
|
29719
|
+
}
|
|
29720
|
+
dependencyMaps(name) {
|
|
29721
|
+
const found = [];
|
|
29722
|
+
let section;
|
|
29723
|
+
for (const line of (this.read("gateway-env.toml") ?? "").split("\n").map((l) => l.trim())) {
|
|
29724
|
+
if (line.startsWith("[")) section = /^\[(dependencies\.[^.\]]+\.entities)\]$/.exec(line)?.[1];
|
|
29725
|
+
if (section && line.startsWith(`"${name}.`)) found.push(`gateway-env.toml [${section}] maps ${name}`);
|
|
29726
|
+
}
|
|
29727
|
+
return [...new Set(found)];
|
|
29728
|
+
}
|
|
29729
|
+
references(name) {
|
|
29730
|
+
return [
|
|
29731
|
+
...this.relationships(name),
|
|
29732
|
+
...this.routes(name),
|
|
29733
|
+
...this.verifiers(name),
|
|
29734
|
+
...this.data(name),
|
|
29735
|
+
...this.dependencyMaps(name)
|
|
29736
|
+
];
|
|
29737
|
+
}
|
|
29738
|
+
prunableDefs(name) {
|
|
29739
|
+
const defs = isObject12(this.root.$defs) ? this.root.$defs : {};
|
|
29740
|
+
const { $defs: _defs, ...rest } = this.root;
|
|
29741
|
+
const kept = structuredClone(rest);
|
|
29742
|
+
delete kept["x-gateway"].entities[name];
|
|
29743
|
+
const keep = closure(localRefs(kept), defs);
|
|
29744
|
+
return [...closure(localRefs(this.entities[name]), defs)].filter((def) => !keep.has(def) && def in defs).sort();
|
|
29745
|
+
}
|
|
29746
|
+
remove(name) {
|
|
29747
|
+
const declared = Object.keys(this.entities);
|
|
29748
|
+
if (!declared.includes(name)) throw new CliError(`Unknown entity ${name}; the world has ${declared.join(", ") || "none"}`);
|
|
29749
|
+
if (declared.length === 1)
|
|
29750
|
+
throw new CliError(
|
|
29751
|
+
`${name} is the world's only entity; declare the one that replaces it first (\`gateway worlds schema entity add\`)`
|
|
29752
|
+
);
|
|
29753
|
+
const blockers = this.references(name);
|
|
29754
|
+
if (blockers.length)
|
|
29755
|
+
throw new CliError(`${name} is still in use; remove these references first:
|
|
29756
|
+
${blockers.join("\n ")}`);
|
|
29757
|
+
const removedDefs = this.prunableDefs(name);
|
|
29758
|
+
const defs = isObject12(this.root.$defs) ? this.root.$defs : {};
|
|
29759
|
+
removedDefs.forEach((def) => delete defs[def]);
|
|
29760
|
+
delete this.entities[name];
|
|
29761
|
+
fs59.writeFileSync(this.file, JSON.stringify(this.root, null, 2) + "\n");
|
|
29762
|
+
const remaining = Object.keys(this.entities).sort();
|
|
29763
|
+
return { removedDefs, verifier: repointScaffoldVerifier(this.dir, remaining[0], remaining) };
|
|
29764
|
+
}
|
|
29765
|
+
};
|
|
29766
|
+
function registerEntityRemove(entity) {
|
|
29767
|
+
entity.command({
|
|
29768
|
+
name: "remove",
|
|
29769
|
+
help: "Remove one entity from schema/world.json, with the $defs only it used; refused while a route, verifier, row or relationship needs it.",
|
|
29770
|
+
positionals: [
|
|
29771
|
+
{ name: "path", help: "World directory holding schema/world.json" },
|
|
29772
|
+
{ name: "entity", help: "Entity name, e.g. records (the custom scaffold's example)" }
|
|
29773
|
+
],
|
|
29774
|
+
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>`.",
|
|
29775
|
+
run: async (args, ctx) => {
|
|
29776
|
+
const dir = path45.resolve(args.positionals[0]);
|
|
29777
|
+
const name = args.positionals[1];
|
|
29778
|
+
const { removedDefs, verifier } = EntityRemoval.open(dir).remove(name);
|
|
29779
|
+
const rel = path45.relative(process.cwd(), dir) || ".";
|
|
29780
|
+
ctx.stdout(
|
|
29781
|
+
JSON.stringify(
|
|
29782
|
+
{
|
|
29783
|
+
status: "ok",
|
|
29784
|
+
entity: name,
|
|
29785
|
+
removedDefs,
|
|
29786
|
+
...verifier ? { verifier: path45.relative(process.cwd(), verifier) || verifier } : {},
|
|
29787
|
+
file: path45.relative(process.cwd(), path45.join(dir, "schema", "world.json")),
|
|
29788
|
+
next: [`gateway worlds schema compile ${rel}`, `gateway worlds schema check ${rel}`]
|
|
29789
|
+
},
|
|
29790
|
+
null,
|
|
29791
|
+
2
|
|
29792
|
+
)
|
|
29793
|
+
);
|
|
29794
|
+
}
|
|
29795
|
+
});
|
|
29796
|
+
}
|
|
29797
|
+
|
|
29798
|
+
// src/cli/runtime/scaffoldHandlers.ts
|
|
29799
|
+
init_router();
|
|
29800
|
+
import * as fs60 from "fs";
|
|
29801
|
+
import * as path46 from "path";
|
|
29802
|
+
var PYTHON_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
29803
|
+
var HANDLERS_FILE = "api/handlers.py";
|
|
29804
|
+
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';
|
|
29805
|
+
var HandlerStub = class {
|
|
29806
|
+
constructor(dir, name) {
|
|
29807
|
+
this.name = name;
|
|
29808
|
+
if (!PYTHON_NAME.test(name))
|
|
29809
|
+
throw new CliError(`--handler is a Python function name ([A-Za-z_][A-Za-z0-9_]*), got ${JSON.stringify(name)}`);
|
|
29810
|
+
this.file = path46.join(dir, HANDLERS_FILE);
|
|
29811
|
+
}
|
|
29812
|
+
name;
|
|
29813
|
+
file;
|
|
29814
|
+
get source() {
|
|
29815
|
+
return fs60.existsSync(this.file) ? fs60.readFileSync(this.file, "utf8") : void 0;
|
|
29816
|
+
}
|
|
29817
|
+
get defined() {
|
|
29818
|
+
const source2 = this.source ?? "";
|
|
29819
|
+
const imported = [...source2.matchAll(/^from\s+\S+\s+import\s+(\([^)]*\)|[^\n]*)/gm)].some(
|
|
29820
|
+
(m) => new RegExp(`\\b${this.name}\\b`).test(m[1])
|
|
29821
|
+
);
|
|
29822
|
+
return imported || new RegExp(`^(?:(?:async\\s+)?def\\s+${this.name}\\s*\\(|${this.name}\\s*=)`, "m").test(source2);
|
|
29823
|
+
}
|
|
29824
|
+
stub() {
|
|
29825
|
+
return `def ${this.name}(ctx, args, query, body):
|
|
29826
|
+
return 501, {"error": "not_implemented", "detail": "${this.name} in ${HANDLERS_FILE} is a stub"}
|
|
29827
|
+
`;
|
|
29828
|
+
}
|
|
29829
|
+
/** Writes the stub unless the function exists; true when it wrote. */
|
|
29830
|
+
ensure() {
|
|
29831
|
+
if (this.defined) return false;
|
|
29832
|
+
const current = this.source;
|
|
29833
|
+
fs60.mkdirSync(path46.dirname(this.file), { recursive: true });
|
|
29834
|
+
const head = current === void 0 ? HEADER : current.replace(/\n*$/, "\n");
|
|
29835
|
+
fs60.writeFileSync(this.file, `${head}
|
|
29836
|
+
|
|
29837
|
+
${this.stub()}`);
|
|
29838
|
+
return true;
|
|
29839
|
+
}
|
|
29840
|
+
};
|
|
29841
|
+
|
|
29001
29842
|
// src/cli/runtime/scaffold.ts
|
|
29002
29843
|
var ENTITY_NAME = /^[A-Za-z][A-Za-z0-9_]*$/;
|
|
29003
29844
|
var MAX_ENTITY_NAME = 64;
|
|
@@ -29271,11 +30112,11 @@ function removeDependency(toml, alias) {
|
|
|
29271
30112
|
return kept.join("\n") + "\n";
|
|
29272
30113
|
}
|
|
29273
30114
|
function dependencyServes(depDir) {
|
|
29274
|
-
const manifest =
|
|
29275
|
-
if (!
|
|
29276
|
-
const tools = manifestServedTools(
|
|
29277
|
-
const connector =
|
|
29278
|
-
const routes =
|
|
30115
|
+
const manifest = path47.join(depDir, "gateway-env.toml");
|
|
30116
|
+
if (!fs61.existsSync(manifest)) return void 0;
|
|
30117
|
+
const tools = manifestServedTools(fs61.readFileSync(manifest, "utf8"));
|
|
30118
|
+
const connector = path47.join(depDir, "connector.toml");
|
|
30119
|
+
const routes = fs61.existsSync(connector) ? declaredRoutes(fs61.readFileSync(connector, "utf8")).map((r) => r.name).filter(Boolean) : [];
|
|
29279
30120
|
return tools === void 0 ? void 0 : { tools, routes };
|
|
29280
30121
|
}
|
|
29281
30122
|
function addDependency(toml, spec, depServes, opts = {}) {
|
|
@@ -29288,7 +30129,7 @@ function addDependency(toml, spec, depServes, opts = {}) {
|
|
|
29288
30129
|
toml = removeDependency(toml, spec.alias);
|
|
29289
30130
|
}
|
|
29290
30131
|
if (!PIN.test(spec.pin)) throw new CliError(`--pin is <slug>@<ref>, got ${JSON.stringify(spec.pin)}`);
|
|
29291
|
-
if (
|
|
30132
|
+
if (path47.isAbsolute(spec.path)) throw new CliError("The dependency path is stored relative to the world");
|
|
29292
30133
|
if (depServes) {
|
|
29293
30134
|
const serves = Array.isArray(depServes) ? { tools: depServes, routes: [] } : depServes;
|
|
29294
30135
|
for (const tool of spec.tools)
|
|
@@ -29358,42 +30199,37 @@ function dependencyPath(toml, alias) {
|
|
|
29358
30199
|
return void 0;
|
|
29359
30200
|
}
|
|
29360
30201
|
function readManifest2(dir) {
|
|
29361
|
-
const file =
|
|
29362
|
-
if (!
|
|
29363
|
-
return { file, toml:
|
|
30202
|
+
const file = path47.join(dir, "gateway-env.toml");
|
|
30203
|
+
if (!fs61.existsSync(file)) throw new CliError(`${dir} holds no gateway-env.toml; run \`gateway worlds schema init\` first`, 1);
|
|
30204
|
+
return { file, toml: fs61.readFileSync(file, "utf8") };
|
|
29364
30205
|
}
|
|
29365
|
-
|
|
29366
|
-
const folder = path42.join(dir, "verifiers");
|
|
29367
|
-
if (!fs56.existsSync(folder)) return void 0;
|
|
29368
|
-
return fs56.readdirSync(folder).filter((f) => f.endsWith(".sql")).map((f) => f.slice(0, -4)).sort();
|
|
29369
|
-
}
|
|
29370
|
-
var toPosix = (p) => p.split(path42.sep).join("/");
|
|
30206
|
+
var toPosix = (p) => p.split(path47.sep).join("/");
|
|
29371
30207
|
var pinSlug = (name) => name.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^[^a-z0-9]+/, "") || "world";
|
|
29372
30208
|
function declaredEntities(dir) {
|
|
29373
|
-
const file =
|
|
29374
|
-
if (!
|
|
30209
|
+
const file = path47.join(dir, "schema", "world.json");
|
|
30210
|
+
if (!fs61.existsSync(file)) return void 0;
|
|
29375
30211
|
const gateway = readJsonFile2(file)["x-gateway"];
|
|
29376
30212
|
return isObject12(gateway) && isObject12(gateway.entities) ? Object.keys(gateway.entities) : [];
|
|
29377
30213
|
}
|
|
29378
30214
|
function worldEntityShapes(dir) {
|
|
29379
|
-
const file =
|
|
29380
|
-
return
|
|
30215
|
+
const file = path47.join(dir, "schema", "world.json");
|
|
30216
|
+
return fs61.existsSync(file) ? declaredEntityShapes(readJsonFile2(file)) : void 0;
|
|
29381
30217
|
}
|
|
29382
30218
|
function declaredHandlerTools(dir) {
|
|
29383
|
-
const file =
|
|
29384
|
-
if (!
|
|
30219
|
+
const file = path47.join(dir, "schema", "world.json");
|
|
30220
|
+
if (!fs61.existsSync(file)) return [];
|
|
29385
30221
|
const gateway = readJsonFile2(file)["x-gateway"];
|
|
29386
30222
|
return isObject12(gateway) && isObject12(gateway.tools) ? Object.keys(gateway.tools) : [];
|
|
29387
30223
|
}
|
|
29388
30224
|
var WORLD_SLUG = /^[a-z0-9][a-z0-9-]*$/;
|
|
29389
30225
|
function connectorTomlSkeleton(dir) {
|
|
29390
|
-
const manifest =
|
|
29391
|
-
if (!
|
|
30226
|
+
const manifest = path47.join(dir, "gateway-env.toml");
|
|
30227
|
+
if (!fs61.existsSync(dir))
|
|
29392
30228
|
throw new CliError(`${dir} does not exist; run \`gateway worlds schema init ${dir} --connector custom\` to start a world there`, 1);
|
|
29393
|
-
if (!
|
|
30229
|
+
if (!fs61.existsSync(manifest))
|
|
29394
30230
|
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);
|
|
29395
|
-
const name = /^\s*name\s*=\s*"([^"]*)"/m.exec(
|
|
29396
|
-
const slug = name && WORLD_SLUG.test(name) ? name :
|
|
30231
|
+
const name = /^\s*name\s*=\s*"([^"]*)"/m.exec(fs61.readFileSync(manifest, "utf8"))?.[1];
|
|
30232
|
+
const slug = name && WORLD_SLUG.test(name) ? name : path47.basename(dir).toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "") || "world";
|
|
29397
30233
|
return [
|
|
29398
30234
|
`# ${slug}'s API surface: the HTTP routes the world serves beside its tools, from one`,
|
|
29399
30235
|
"# World Host session. Declare routes with `gateway worlds connector route add`; an",
|
|
@@ -29401,70 +30237,14 @@ function connectorTomlSkeleton(dir) {
|
|
|
29401
30237
|
"[connector]",
|
|
29402
30238
|
`slug = "${slug}"`,
|
|
29403
30239
|
`base_url = "https://${slug}.example"`,
|
|
30240
|
+
"",
|
|
30241
|
+
"# A hosted session's api token is a bearer; `gateway worlds serve` accepts the one --api-key pins (default `conform`).",
|
|
30242
|
+
"[auth]",
|
|
30243
|
+
'scheme = "bearer"',
|
|
30244
|
+
`secret_env = "${slug.toUpperCase().replace(/[^A-Z0-9]+/g, "_")}_API_KEY"`,
|
|
29404
30245
|
""
|
|
29405
30246
|
].join("\n");
|
|
29406
30247
|
}
|
|
29407
|
-
var SCAFFOLD_VERIFIER = /^-- Scores 1\.0 once the world holds any (\S+) row; edit for real tasks\.\n/;
|
|
29408
|
-
function scaffoldVerifier(entity) {
|
|
29409
|
-
return `-- Scores 1.0 once the world holds any ${entity} row; edit for real tasks.
|
|
29410
|
-
SELECT CASE WHEN COUNT(*) > 0 THEN 1.0 ELSE 0.0 END FROM "${entity}";
|
|
29411
|
-
`;
|
|
29412
|
-
}
|
|
29413
|
-
function verifierSql(name, entity, where) {
|
|
29414
|
-
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)}`);
|
|
29415
|
-
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(entity)) throw new CliError(`Entity names match [A-Za-z_][A-Za-z0-9_]*, got ${JSON.stringify(entity)}`);
|
|
29416
|
-
if (where === void 0) return scaffoldVerifier(entity);
|
|
29417
|
-
const clause = where.trim();
|
|
29418
|
-
if (!clause) throw new CliError("--where is a SQL condition over the entity's columns; it cannot be empty");
|
|
29419
|
-
const defect = whereClauseDefect(clause);
|
|
29420
|
-
if (defect)
|
|
29421
|
-
throw new CliError(
|
|
29422
|
-
`--where ${JSON.stringify(clause)} cannot be a SQL condition: ${defect}. The file would fail \`gateway worlds schema check\` at once; fix the condition here instead.`
|
|
29423
|
-
);
|
|
29424
|
-
return `-- ${name}: scores 1.0 once a ${entity} row satisfies the condition; edit for real tasks.
|
|
29425
|
-
-- A verifier is one SQL statement returning one number in 0..1 (0.5 is partial credit).
|
|
29426
|
-
SELECT CASE WHEN COUNT(*) > 0 THEN 1.0 ELSE 0.0 END FROM "${entity}" WHERE ${clause};
|
|
29427
|
-
`;
|
|
29428
|
-
}
|
|
29429
|
-
function whereClauseDefect(clause) {
|
|
29430
|
-
let depth = 0;
|
|
29431
|
-
let quote;
|
|
29432
|
-
for (const ch of clause) {
|
|
29433
|
-
if (quote) {
|
|
29434
|
-
if (ch === quote) quote = void 0;
|
|
29435
|
-
continue;
|
|
29436
|
-
}
|
|
29437
|
-
if (ch === "'" || ch === '"') quote = ch;
|
|
29438
|
-
else if (ch === "(") depth += 1;
|
|
29439
|
-
else if (ch === ")") depth -= 1;
|
|
29440
|
-
else if (ch === ";") return "a `;` would end the statement early; a verifier is one SQL statement";
|
|
29441
|
-
if (depth < 0) return "a `)` closes a parenthesis that was never opened";
|
|
29442
|
-
}
|
|
29443
|
-
if (quote) return `a ${quote} quote is never closed`;
|
|
29444
|
-
if (depth > 0) return `${depth} parenthes${depth === 1 ? "is is" : "es are"} never closed`;
|
|
29445
|
-
if (/(?:^|[\s(])(?:AND|OR|NOT|IN|IS|LIKE|BETWEEN)$/i.test(clause) || /[=<>!+\-*/,(]$/.test(clause))
|
|
29446
|
-
return "it ends in an operator with nothing after it";
|
|
29447
|
-
return void 0;
|
|
29448
|
-
}
|
|
29449
|
-
function addVerifier(dir, name, entity, where) {
|
|
29450
|
-
const sql = verifierSql(name, entity, where);
|
|
29451
|
-
const file = path42.join(dir, "verifiers", `${name}.sql`);
|
|
29452
|
-
if (fs56.existsSync(file))
|
|
29453
|
-
throw new CliError(`verifiers/${name}.sql already exists (have: ${(verifierNames2(dir) ?? []).join(", ")}); edit it, or pick another name`);
|
|
29454
|
-
fs56.mkdirSync(path42.dirname(file), { recursive: true });
|
|
29455
|
-
fs56.writeFileSync(file, sql);
|
|
29456
|
-
return file;
|
|
29457
|
-
}
|
|
29458
|
-
function repointScaffoldVerifier(dir, entity, declared) {
|
|
29459
|
-
const file = path42.join(dir, "verifiers", "state_present.sql");
|
|
29460
|
-
if (!fs56.existsSync(file)) return null;
|
|
29461
|
-
const text2 = fs56.readFileSync(file, "utf8");
|
|
29462
|
-
const match = SCAFFOLD_VERIFIER.exec(text2);
|
|
29463
|
-
if (!match || text2 !== scaffoldVerifier(match[1])) return null;
|
|
29464
|
-
if (declared.includes(match[1])) return null;
|
|
29465
|
-
fs56.writeFileSync(file, scaffoldVerifier(entity));
|
|
29466
|
-
return file;
|
|
29467
|
-
}
|
|
29468
30248
|
function parsePairs(values, flag) {
|
|
29469
30249
|
const out = {};
|
|
29470
30250
|
for (const item of values) {
|
|
@@ -29479,7 +30259,8 @@ function registerScaffoldCommands(worlds) {
|
|
|
29479
30259
|
"schema",
|
|
29480
30260
|
"Compile and check gateway-world/1 contracts (the runtime runs on the platform)."
|
|
29481
30261
|
);
|
|
29482
|
-
schema.group("entity", "Declare entities in schema/world.json without hand-editing the catalog.")
|
|
30262
|
+
const entity = schema.group("entity", "Declare or remove entities in schema/world.json without hand-editing the catalog.");
|
|
30263
|
+
entity.command({
|
|
29483
30264
|
name: "add",
|
|
29484
30265
|
help: "Declare one entity in schema/world.json: its payload, primary key, unique keys and relationships.",
|
|
29485
30266
|
positionals: [
|
|
@@ -29500,8 +30281,8 @@ function registerScaffoldCommands(worlds) {
|
|
|
29500
30281
|
],
|
|
29501
30282
|
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.",
|
|
29502
30283
|
run: async (args, ctx) => {
|
|
29503
|
-
const dir =
|
|
29504
|
-
const file =
|
|
30284
|
+
const dir = path47.resolve(args.positionals[0]);
|
|
30285
|
+
const file = path47.join(dir, "schema", "world.json");
|
|
29505
30286
|
const root = readJsonFile2(file);
|
|
29506
30287
|
let inline;
|
|
29507
30288
|
const schemaFlag = arg.str(args, "schema");
|
|
@@ -29525,17 +30306,18 @@ function registerScaffoldCommands(worlds) {
|
|
|
29525
30306
|
unique: arg.list(args, "unique").map((u) => u.split(",").map((f) => f.trim()).filter(Boolean)),
|
|
29526
30307
|
relationships: arg.list(args, "relationship").map(parseRelationship)
|
|
29527
30308
|
});
|
|
29528
|
-
|
|
29529
|
-
const out = { status: "ok", entity: name, declaration, file:
|
|
30309
|
+
fs61.writeFileSync(file, JSON.stringify(document, null, 2) + "\n");
|
|
30310
|
+
const out = { status: "ok", entity: name, declaration, file: path47.relative(process.cwd(), file) || file };
|
|
29530
30311
|
if (def) out.def = def;
|
|
29531
30312
|
const verifier = repointScaffoldVerifier(dir, name, declaredEntities(dir) ?? []);
|
|
29532
30313
|
if (verifier) {
|
|
29533
|
-
out.verifier =
|
|
30314
|
+
out.verifier = path47.relative(process.cwd(), verifier) || verifier;
|
|
29534
30315
|
ctx.stderr(`# ${out.verifier} named an entity the catalog no longer declares; it now scores over ${name}`);
|
|
29535
30316
|
}
|
|
29536
30317
|
ctx.stdout(JSON.stringify(out, null, 2));
|
|
29537
30318
|
}
|
|
29538
30319
|
});
|
|
30320
|
+
registerEntityRemove(entity);
|
|
29539
30321
|
schema.group("verifier", "Write verifiers/<name>.sql: the SQL that grades a task on the world's end state.").command({
|
|
29540
30322
|
name: "add",
|
|
29541
30323
|
help: "Scaffold one verifier: a SQL statement over an entity's table returning 1.0 when a row satisfies --where (or any row exists).",
|
|
@@ -29549,22 +30331,22 @@ function registerScaffoldCommands(worlds) {
|
|
|
29549
30331
|
],
|
|
29550
30332
|
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.",
|
|
29551
30333
|
run: async (args, ctx) => {
|
|
29552
|
-
const dir =
|
|
30334
|
+
const dir = path47.resolve(args.positionals[0]);
|
|
29553
30335
|
const name = args.positionals[1];
|
|
29554
|
-
const
|
|
30336
|
+
const entity2 = arg.str(args, "entity");
|
|
29555
30337
|
const declared = declaredEntities(dir);
|
|
29556
30338
|
if (declared === void 0) throw new CliError(`${dir} has no schema/world.json; run \`gateway worlds schema init ${args.positionals[0]} --connector custom\` first`);
|
|
29557
|
-
if (!
|
|
29558
|
-
if (!declared.includes(
|
|
29559
|
-
const file = addVerifier(dir, name,
|
|
29560
|
-
const rel =
|
|
30339
|
+
if (!entity2) throw new CliError(`--entity is required: one of ${declared.join(", ") || "(declare one with `gateway worlds schema entity add` first)"}`);
|
|
30340
|
+
if (!declared.includes(entity2)) throw new CliError(`Unknown entity ${entity2}; the world has ${declared.join(", ") || "none"}`);
|
|
30341
|
+
const file = addVerifier(dir, name, entity2, arg.str(args, "where"));
|
|
30342
|
+
const rel = path47.relative(process.cwd(), dir) || ".";
|
|
29561
30343
|
ctx.stdout(
|
|
29562
30344
|
JSON.stringify(
|
|
29563
30345
|
{
|
|
29564
30346
|
status: "ok",
|
|
29565
30347
|
verifier: name,
|
|
29566
|
-
entity,
|
|
29567
|
-
file:
|
|
30348
|
+
entity: entity2,
|
|
30349
|
+
file: path47.relative(process.cwd(), file) || file,
|
|
29568
30350
|
next: `gateway worlds schema task add ${rel} <task_id> --prompt "<what the agent is told>" --verifier ${name}`
|
|
29569
30351
|
},
|
|
29570
30352
|
null,
|
|
@@ -29601,39 +30383,39 @@ function registerScaffoldCommands(worlds) {
|
|
|
29601
30383
|
],
|
|
29602
30384
|
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>.",
|
|
29603
30385
|
run: async (args, ctx) => {
|
|
29604
|
-
const dir =
|
|
30386
|
+
const dir = path47.resolve(args.positionals[0]);
|
|
29605
30387
|
const alias = args.positionals[1];
|
|
29606
30388
|
const depArg = args.positionals[2];
|
|
29607
|
-
const depDir =
|
|
30389
|
+
const depDir = path47.resolve(depArg);
|
|
29608
30390
|
const { file, toml } = readManifest2(dir);
|
|
29609
|
-
if (!
|
|
29610
|
-
const fromWorld =
|
|
29611
|
-
const hint = fromWorld !== depDir &&
|
|
30391
|
+
if (!fs61.existsSync(path47.join(depDir, "gateway-env.toml"))) {
|
|
30392
|
+
const fromWorld = path47.resolve(dir, depArg);
|
|
30393
|
+
const hint = fromWorld !== depDir && fs61.existsSync(path47.join(fromWorld, "gateway-env.toml")) ? `; paths resolve from your shell, not from the world: did you mean ${path47.relative(process.cwd(), fromWorld) || "."}?` : "";
|
|
29612
30394
|
throw new CliError(
|
|
29613
30395
|
`${depDir} holds no gateway-env.toml; the dependency must be a schema world (\`gateway worlds schema init\`)${hint}`,
|
|
29614
30396
|
1
|
|
29615
30397
|
);
|
|
29616
30398
|
}
|
|
29617
|
-
if (
|
|
29618
|
-
const depToml =
|
|
30399
|
+
if (path47.resolve(depDir) === dir) throw new CliError("A world cannot depend on itself");
|
|
30400
|
+
const depToml = fs61.readFileSync(path47.join(depDir, "gateway-env.toml"), "utf8");
|
|
29619
30401
|
if (declaredAliases(depToml).length)
|
|
29620
30402
|
throw new CliError(`${depDir} has [dependencies] of its own (${declaredAliases(depToml).join(", ")}); links nest one level`);
|
|
29621
30403
|
const task = arg.str(args, "task");
|
|
29622
|
-
if (task !== void 0 && !
|
|
29623
|
-
const have =
|
|
30404
|
+
if (task !== void 0 && !fs61.existsSync(path47.join(depDir, "scenarios", task))) {
|
|
30405
|
+
const have = fs61.existsSync(path47.join(depDir, "scenarios")) ? fs61.readdirSync(path47.join(depDir, "scenarios")) : [];
|
|
29624
30406
|
throw new CliError(`${depDir} has no scenarios/${task}/ (have: ${have.join(", ") || "none"})`);
|
|
29625
30407
|
}
|
|
29626
|
-
const rel = toPosix(
|
|
30408
|
+
const rel = toPosix(path47.relative(dir, depDir)) || ".";
|
|
29627
30409
|
const spec = {
|
|
29628
30410
|
alias,
|
|
29629
|
-
pin: arg.str(args, "pin") ?? `${pinSlug(manifestName(depToml) ??
|
|
30411
|
+
pin: arg.str(args, "pin") ?? `${pinSlug(manifestName(depToml) ?? path47.basename(depDir))}@main`,
|
|
29630
30412
|
path: rel.startsWith(".") ? rel : `./${rel}`,
|
|
29631
30413
|
task,
|
|
29632
30414
|
tools: arg.list(args, "tools").flatMap((t) => t.split(",")).map((t) => t.trim()).filter(Boolean),
|
|
29633
30415
|
entities: arg.list(args, "map").map(parseEntityMap)
|
|
29634
30416
|
};
|
|
29635
30417
|
const updated = addDependency(toml, spec, dependencyServes(depDir), { replace: arg.bool(args, "replace") });
|
|
29636
|
-
|
|
30418
|
+
fs61.writeFileSync(file, updated);
|
|
29637
30419
|
ctx.stdout(
|
|
29638
30420
|
JSON.stringify(
|
|
29639
30421
|
{
|
|
@@ -29643,9 +30425,9 @@ function registerScaffoldCommands(worlds) {
|
|
|
29643
30425
|
path: spec.path,
|
|
29644
30426
|
task: spec.task ?? null,
|
|
29645
30427
|
tools: spec.tools.map((t) => `${alias}.${t}`),
|
|
29646
|
-
verifiers: (
|
|
29647
|
-
file:
|
|
29648
|
-
next: `gateway worlds schema check ${
|
|
30428
|
+
verifiers: (verifierNames(depDir) ?? []).map((v) => `${alias}/${v}`),
|
|
30429
|
+
file: path47.relative(process.cwd(), file) || file,
|
|
30430
|
+
next: `gateway worlds schema check ${path47.relative(process.cwd(), dir) || "."}`
|
|
29649
30431
|
},
|
|
29650
30432
|
null,
|
|
29651
30433
|
2
|
|
@@ -29676,7 +30458,7 @@ function registerScaffoldCommands(worlds) {
|
|
|
29676
30458
|
],
|
|
29677
30459
|
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.",
|
|
29678
30460
|
run: async (args, ctx) => {
|
|
29679
|
-
const dir =
|
|
30461
|
+
const dir = path47.resolve(args.positionals[0]);
|
|
29680
30462
|
const { file, toml } = readManifest2(dir);
|
|
29681
30463
|
const prompt = arg.str(args, "prompt");
|
|
29682
30464
|
if (prompt === void 0) throw new CliError("--prompt is required: what the agent is told");
|
|
@@ -29692,7 +30474,7 @@ function registerScaffoldCommands(worlds) {
|
|
|
29692
30474
|
const depVerifiers = {};
|
|
29693
30475
|
for (const alias of Object.keys(worlds2)) {
|
|
29694
30476
|
const rel = dependencyPath(toml, alias);
|
|
29695
|
-
if (rel !== void 0) depVerifiers[alias] =
|
|
30477
|
+
if (rel !== void 0) depVerifiers[alias] = verifierNames(path47.resolve(dir, rel));
|
|
29696
30478
|
}
|
|
29697
30479
|
const spec = {
|
|
29698
30480
|
id: args.positionals[1],
|
|
@@ -29703,10 +30485,10 @@ function registerScaffoldCommands(worlds) {
|
|
|
29703
30485
|
const updated = addTask(
|
|
29704
30486
|
toml,
|
|
29705
30487
|
spec,
|
|
29706
|
-
{ verifiers:
|
|
30488
|
+
{ verifiers: verifierNames(dir), depVerifiers },
|
|
29707
30489
|
{ replace: arg.bool(args, "replace") }
|
|
29708
30490
|
);
|
|
29709
|
-
|
|
30491
|
+
fs61.writeFileSync(file, updated);
|
|
29710
30492
|
ctx.stdout(
|
|
29711
30493
|
JSON.stringify(
|
|
29712
30494
|
{
|
|
@@ -29716,11 +30498,11 @@ function registerScaffoldCommands(worlds) {
|
|
|
29716
30498
|
verifiers: spec.verifiers,
|
|
29717
30499
|
worlds: worlds2,
|
|
29718
30500
|
rewards: [...spec.verifiers, ...Object.entries(worlds2).flatMap(([a, names]) => names.map((n) => `${a}/${n}`))],
|
|
29719
|
-
file:
|
|
30501
|
+
file: path47.relative(process.cwd(), file) || file,
|
|
29720
30502
|
next: [
|
|
29721
|
-
`gateway worlds schema compile ${
|
|
29722
|
-
`gateway worlds schema check ${
|
|
29723
|
-
`gateway worlds serve ${
|
|
30503
|
+
`gateway worlds schema compile ${path47.relative(process.cwd(), dir) || "."} # a manifest edit invalidates the compiled contract`,
|
|
30504
|
+
`gateway worlds schema check ${path47.relative(process.cwd(), dir) || "."}`,
|
|
30505
|
+
`gateway worlds serve ${path47.relative(process.cwd(), dir) || "."} --task ${spec.id}`
|
|
29724
30506
|
]
|
|
29725
30507
|
},
|
|
29726
30508
|
null,
|
|
@@ -29769,11 +30551,11 @@ function registerScaffoldCommands(worlds) {
|
|
|
29769
30551
|
{ name: "handler", help: "Function in api/handlers.py (with --action handler)." },
|
|
29770
30552
|
{ name: "replace", help: "Rewrite the existing [[operations]] block of this name instead of refusing it.", boolean: true }
|
|
29771
30553
|
],
|
|
29772
|
-
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. Then\n`gateway worlds connector validate <path>`.",
|
|
30554
|
+
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>`.",
|
|
29773
30555
|
run: async (args, ctx) => {
|
|
29774
|
-
const dir =
|
|
29775
|
-
const file =
|
|
29776
|
-
const created = !
|
|
30556
|
+
const dir = path47.resolve(args.positionals[0]);
|
|
30557
|
+
const file = path47.join(dir, "connector.toml");
|
|
30558
|
+
const created = !fs61.existsSync(file);
|
|
29777
30559
|
const routePath = arg.str(args, "path");
|
|
29778
30560
|
if (routePath === void 0) throw new CliError("--path is required, e.g. --path /users");
|
|
29779
30561
|
const spec = {
|
|
@@ -29796,13 +30578,15 @@ function registerScaffoldCommands(worlds) {
|
|
|
29796
30578
|
}
|
|
29797
30579
|
};
|
|
29798
30580
|
const replace = arg.bool(args, "replace");
|
|
29799
|
-
const
|
|
30581
|
+
const handler = spec.api.action === "handler" && spec.api.handler ? new HandlerStub(dir, spec.api.handler) : void 0;
|
|
30582
|
+
const current = created ? connectorTomlSkeleton(dir) : fs61.readFileSync(file, "utf8");
|
|
29800
30583
|
const updated = addRoute(current, spec, declaredEntities(dir), {
|
|
29801
30584
|
replace,
|
|
29802
30585
|
handlerTools: declaredHandlerTools(dir),
|
|
29803
30586
|
entities: worldEntityShapes(dir)
|
|
29804
30587
|
});
|
|
29805
|
-
|
|
30588
|
+
fs61.writeFileSync(file, updated);
|
|
30589
|
+
const written = handler?.ensure();
|
|
29806
30590
|
ctx.stdout(
|
|
29807
30591
|
JSON.stringify(
|
|
29808
30592
|
{
|
|
@@ -29813,7 +30597,8 @@ function registerScaffoldCommands(worlds) {
|
|
|
29813
30597
|
entity: spec.entity ?? null,
|
|
29814
30598
|
...replace ? { replaced: true } : {},
|
|
29815
30599
|
...created ? { created: true } : {},
|
|
29816
|
-
file:
|
|
30600
|
+
...handler ? { handler: { file: HANDLERS_FILE, function: handler.name, written } } : {},
|
|
30601
|
+
file: path47.relative(process.cwd(), file) || file
|
|
29817
30602
|
},
|
|
29818
30603
|
null,
|
|
29819
30604
|
2
|
|
@@ -29848,13 +30633,13 @@ function registerRuntimeCommands(root) {
|
|
|
29848
30633
|
}
|
|
29849
30634
|
|
|
29850
30635
|
// src/cli/version.ts
|
|
29851
|
-
import * as
|
|
29852
|
-
import * as
|
|
30636
|
+
import * as fs62 from "fs";
|
|
30637
|
+
import * as path48 from "path";
|
|
29853
30638
|
function cliVersion() {
|
|
29854
|
-
if (true) return "0.3.
|
|
30639
|
+
if (true) return "0.3.1";
|
|
29855
30640
|
if (typeof __dirname !== "string") return "unknown";
|
|
29856
30641
|
try {
|
|
29857
|
-
const pkg = JSON.parse(
|
|
30642
|
+
const pkg = JSON.parse(fs62.readFileSync(path48.resolve(__dirname, "../../package.json"), "utf8"));
|
|
29858
30643
|
return pkg.version ?? "unknown";
|
|
29859
30644
|
} catch {
|
|
29860
30645
|
return "unknown";
|