@withgateway/sdk 0.9.1 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/index.d.mts +12 -4
- package/dist/agents/index.d.ts +12 -4
- package/dist/agents/index.js +30 -0
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/index.mjs +30 -0
- package/dist/agents/index.mjs.map +1 -1
- package/dist/cli.js +2291 -945
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +2290 -944
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs.map +1 -1
- package/dist/index.js +325 -184
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +324 -183
- package/dist/index.mjs.map +1 -1
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.js +1 -1
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +1 -1
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/worlds/index.d.mts +3 -1
- package/dist/worlds/index.d.ts +3 -1
- package/dist/worlds/index.js +178 -67
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +177 -66
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +1 -1
- package/runtime/gatewaysdk/environment/bundle_manifest.py +297 -9
- package/runtime/gatewaysdk/environment/factory_documents.py +670 -0
- package/runtime/gatewaysdk/environment/factory_rules.py +973 -0
- package/runtime/gatewaysdk/environment/factory_shapes.py +253 -0
- package/runtime/gatewaysdk/environment/factory_spine.py +1155 -0
- package/runtime/gatewaysdk/environment/factory_spine_shapes.py +480 -0
- package/runtime/gatewaysdk/environment/schema/admission.py +61 -59
- package/runtime/gatewaysdk/environment/schema/cast.py +133 -67
- package/runtime/gatewaysdk/environment/schema/compiler.py +16 -17
- package/runtime/gatewaysdk/environment/schema/handler_errors.py +58 -4
- package/runtime/gatewaysdk/environment/schema/host.py +21 -2
- package/runtime/gatewaysdk/environment/schema/host_control.py +3 -1
- package/runtime/gatewaysdk/environment/schema/host_loops.py +27 -4
- package/runtime/gatewaysdk/environment/schema/host_metrics.py +69 -0
- package/runtime/gatewaysdk/environment/schema/host_requests.py +21 -0
- package/runtime/gatewaysdk/environment/schema/host_session.py +7 -0
- package/runtime/gatewaysdk/environment/schema/host_versions.py +4 -0
- package/runtime/gatewaysdk/environment/schema/host_workers.py +172 -50
- package/runtime/gatewaysdk/environment/schema/ingest.py +12 -3
- package/runtime/gatewaysdk/environment/schema/mapping.py +1 -1
- package/runtime/gatewaysdk/environment/schema/measured_tests.py +187 -0
- package/runtime/gatewaysdk/environment/schema/platform.py +57 -3
- package/runtime/gatewaysdk/environment/schema/platform_query.py +4 -3
- package/runtime/gatewaysdk/environment/schema/platform_templates.py +105 -17
- package/runtime/gatewaysdk/environment/schema/process_memory.py +76 -0
- package/runtime/gatewaysdk/environment/schema/redaction.py +13 -0
- package/runtime/gatewaysdk/environment/schema/runtime.py +14 -0
- package/runtime/gatewaysdk/environment/schema/scaffold.py +21 -4
- package/runtime/gatewaysdk/environment/schema/shape_catalog.py +493 -0
- package/runtime/gatewaysdk/environment/schema/shape_declarations.py +219 -0
- package/runtime/gatewaysdk/environment/schema/skill.py +1 -0
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +1 -0
- package/runtime/gatewaysdk/environment/schema/skills/factory-orchestrator/SKILL.md +147 -0
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/ROWS.md +5 -1
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +4 -4
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +2 -2
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +1 -0
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/shape-catalog.md +59 -0
- package/runtime/gatewaysdk/environment/schema/validation.py +14 -0
- package/runtime/gatewaysdk/environment/schema/worker.py +7 -4
- package/runtime/gatewaysdk/environment/schema/worker_key.py +38 -0
- package/runtime/gatewaysdk/environment/schema/worker_peaks.py +38 -0
- package/runtime/gatewaysdk/environment/schema/worker_watch.py +50 -0
- package/runtime/gatewaysdk/environment/schema/workers.py +237 -68
- package/runtime/gatewaysdk/environment/schema/world_host.py +56 -62
- package/runtime/gatewaysdk/environment/schema/world_tests.py +3 -1
- package/skills/connector-schema-authoring/SKILL.md +1 -0
- package/skills/connector-schema-authoring/connector-worlds.md +1 -0
- package/skills/connector-schema-authoring/world-schema.md +7 -0
- package/skills/factory-orchestrator/SKILL.md +147 -0
- package/skills/world-data-ingestion/ROWS.md +5 -1
- package/skills/world-data-ingestion/SKILL.md +4 -4
- package/skills/worlds-getting-started/SKILL.md +2 -2
- package/skills/worlds-getting-started/references/cli-mcp-map.md +1 -0
- package/skills/worlds-getting-started/references/shape-catalog.md +59 -0
package/dist/index.js
CHANGED
|
@@ -204,10 +204,10 @@ var init_users = __esm({
|
|
|
204
204
|
totalItems: Number(meta.totalItems ?? rows.length)
|
|
205
205
|
};
|
|
206
206
|
}
|
|
207
|
-
async requestJson(method,
|
|
207
|
+
async requestJson(method, path18, payload) {
|
|
208
208
|
let response;
|
|
209
209
|
try {
|
|
210
|
-
response = await fetch(`${this.host}${
|
|
210
|
+
response = await fetch(`${this.host}${path18}`, {
|
|
211
211
|
method,
|
|
212
212
|
headers: {
|
|
213
213
|
Authorization: this.authHeader(),
|
|
@@ -218,17 +218,17 @@ var init_users = __esm({
|
|
|
218
218
|
});
|
|
219
219
|
} catch (error) {
|
|
220
220
|
throw new UserProfileError(
|
|
221
|
-
`${method} ${
|
|
221
|
+
`${method} ${path18} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
222
222
|
{ cause: error }
|
|
223
223
|
);
|
|
224
224
|
}
|
|
225
225
|
const text2 = await response.text();
|
|
226
226
|
if (!response.ok) {
|
|
227
227
|
throw new UserProfileError(
|
|
228
|
-
`${method} ${
|
|
228
|
+
`${method} ${path18} failed (${response.status}): ${text2.slice(0, 500)}`
|
|
229
229
|
);
|
|
230
230
|
}
|
|
231
|
-
this.log("%s %s -> %s", method,
|
|
231
|
+
this.log("%s %s -> %s", method, path18, response.status);
|
|
232
232
|
return safeJson4(text2);
|
|
233
233
|
}
|
|
234
234
|
authHeader() {
|
|
@@ -417,10 +417,10 @@ var init_scores = __esm({
|
|
|
417
417
|
metadata: signalMetadata
|
|
418
418
|
});
|
|
419
419
|
}
|
|
420
|
-
async request(method,
|
|
420
|
+
async request(method, path18, payload) {
|
|
421
421
|
let response;
|
|
422
422
|
try {
|
|
423
|
-
response = await fetch(`${this.host}${
|
|
423
|
+
response = await fetch(`${this.host}${path18}`, {
|
|
424
424
|
method,
|
|
425
425
|
headers: {
|
|
426
426
|
Authorization: this.authHeader(),
|
|
@@ -431,17 +431,17 @@ var init_scores = __esm({
|
|
|
431
431
|
});
|
|
432
432
|
} catch (error) {
|
|
433
433
|
throw new ScoreError(
|
|
434
|
-
`${method} ${
|
|
434
|
+
`${method} ${path18} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
435
435
|
{ cause: error }
|
|
436
436
|
);
|
|
437
437
|
}
|
|
438
438
|
const text2 = await response.text();
|
|
439
439
|
if (!response.ok) {
|
|
440
440
|
throw new ScoreError(
|
|
441
|
-
`${method} ${
|
|
441
|
+
`${method} ${path18} failed (${response.status}): ${text2.slice(0, 500)}`
|
|
442
442
|
);
|
|
443
443
|
}
|
|
444
|
-
this.log("%s %s -> %s", method,
|
|
444
|
+
this.log("%s %s -> %s", method, path18, response.status);
|
|
445
445
|
}
|
|
446
446
|
authHeader() {
|
|
447
447
|
return `Basic ${Buffer.from(`${this.publicKey}:${this.secretKey}`).toString(
|
|
@@ -581,8 +581,8 @@ function invalidFields(error) {
|
|
|
581
581
|
return issues.filter(
|
|
582
582
|
(issue) => issue !== null && typeof issue === "object" && typeof issue.message === "string"
|
|
583
583
|
).map((issue) => {
|
|
584
|
-
const
|
|
585
|
-
return
|
|
584
|
+
const path18 = Array.isArray(issue.path) ? issue.path.map(String).join(".") : "";
|
|
585
|
+
return path18 ? `${path18}: ${issue.message}` : issue.message;
|
|
586
586
|
}).join("; ");
|
|
587
587
|
}
|
|
588
588
|
var ApiError, DETAIL_LIMIT, EDGE_ANSWERS, EDGE_FAILURE, EDGE_PAGE;
|
|
@@ -590,9 +590,9 @@ var init_apiError = __esm({
|
|
|
590
590
|
"src/worlds/apiError.ts"() {
|
|
591
591
|
"use strict";
|
|
592
592
|
ApiError = class extends Error {
|
|
593
|
-
constructor(status, method,
|
|
593
|
+
constructor(status, method, path18, text2) {
|
|
594
594
|
const parsed = parseErrorBody(text2, status);
|
|
595
|
-
super(`${method} ${
|
|
595
|
+
super(`${method} ${path18} -> ${status}: ${parsed.detail}`);
|
|
596
596
|
this.status = status;
|
|
597
597
|
this.text = text2;
|
|
598
598
|
this.name = "ApiError";
|
|
@@ -1228,9 +1228,9 @@ function surfaceKinds(s) {
|
|
|
1228
1228
|
if (s.browser) kinds.push("browser");
|
|
1229
1229
|
return kinds;
|
|
1230
1230
|
}
|
|
1231
|
-
function uiUrl(ui,
|
|
1231
|
+
function uiUrl(ui, path18) {
|
|
1232
1232
|
const base = ui.url.replace(/\/+$/, "");
|
|
1233
|
-
const rel =
|
|
1233
|
+
const rel = path18.startsWith("/") ? path18 : `/${path18}`;
|
|
1234
1234
|
if (!ui.token) return base + rel;
|
|
1235
1235
|
const [beforeHash, hash] = splitHash(rel);
|
|
1236
1236
|
const joiner = beforeHash.includes("?") ? "&" : "?";
|
|
@@ -2648,13 +2648,13 @@ var init_screen = __esm({
|
|
|
2648
2648
|
});
|
|
2649
2649
|
}
|
|
2650
2650
|
async drag(action) {
|
|
2651
|
-
const
|
|
2652
|
-
if (
|
|
2651
|
+
const path18 = action.args.path ?? [];
|
|
2652
|
+
if (path18.length < 2) throw new Error("a drag needs at least two points");
|
|
2653
2653
|
return this.held(action.args.modifiers ?? [], async () => {
|
|
2654
|
-
await this.moveTo(
|
|
2654
|
+
await this.moveTo(path18[0]);
|
|
2655
2655
|
await this.page.mouse.down({ button: "left" });
|
|
2656
2656
|
try {
|
|
2657
|
-
for (const point2 of
|
|
2657
|
+
for (const point2 of path18.slice(1)) await this.moveTo(point2, DRAG_STEPS);
|
|
2658
2658
|
} finally {
|
|
2659
2659
|
await this.page.mouse.up({ button: "left" });
|
|
2660
2660
|
}
|
|
@@ -4488,17 +4488,17 @@ var init_session2 = __esm({
|
|
|
4488
4488
|
}
|
|
4489
4489
|
/** The reporter `browser()` uses; exposed for a page you drive yourself. */
|
|
4490
4490
|
browserRecorder(agentId) {
|
|
4491
|
-
const
|
|
4491
|
+
const path18 = `/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/browser-events`;
|
|
4492
4492
|
const id = agentId ?? process.env.GATEWAY_AGENT_ID ?? `agent-${(0, import_node_crypto2.randomUUID)().replace(/-/g, "").slice(0, 8)}`;
|
|
4493
4493
|
return new BrowserActionRecorder(
|
|
4494
4494
|
async (events) => {
|
|
4495
|
-
await apiRequest(this.options, "POST",
|
|
4495
|
+
await apiRequest(this.options, "POST", path18, { events });
|
|
4496
4496
|
},
|
|
4497
4497
|
id,
|
|
4498
4498
|
{
|
|
4499
4499
|
// Continue this agent's timeline where the platform has it, so a reopened id never re-numbers from zero.
|
|
4500
4500
|
resumeFrom: async () => {
|
|
4501
|
-
const summary = await apiRequest(this.options, "GET",
|
|
4501
|
+
const summary = await apiRequest(this.options, "GET", path18);
|
|
4502
4502
|
return summary.agents.find((a) => a.agentId === id)?.nextSeq ?? 0;
|
|
4503
4503
|
}
|
|
4504
4504
|
}
|
|
@@ -5451,8 +5451,8 @@ var init_taskRunDir = __esm({
|
|
|
5451
5451
|
path = __toESM(require("path"));
|
|
5452
5452
|
init_browser();
|
|
5453
5453
|
TaskRunDir = class {
|
|
5454
|
-
constructor(
|
|
5455
|
-
this.path =
|
|
5454
|
+
constructor(path18) {
|
|
5455
|
+
this.path = path18;
|
|
5456
5456
|
}
|
|
5457
5457
|
path;
|
|
5458
5458
|
writeManifest(manifest) {
|
|
@@ -5989,7 +5989,7 @@ var require_package = __commonJS({
|
|
|
5989
5989
|
"package.json"(exports2, module2) {
|
|
5990
5990
|
module2.exports = {
|
|
5991
5991
|
name: "@withgateway/sdk",
|
|
5992
|
-
version: "0.9.
|
|
5992
|
+
version: "0.9.3",
|
|
5993
5993
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
5994
5994
|
main: "./dist/index.js",
|
|
5995
5995
|
module: "./dist/index.mjs",
|
|
@@ -8459,7 +8459,7 @@ function rebaseConflicts(error) {
|
|
|
8459
8459
|
}
|
|
8460
8460
|
const conflicts = body?.conflicts;
|
|
8461
8461
|
if (!Array.isArray(conflicts)) return null;
|
|
8462
|
-
return conflicts.filter(isConflictPath).map(({ path:
|
|
8462
|
+
return conflicts.filter(isConflictPath).map(({ path: path18, reason }) => ({ path: path18, reason }));
|
|
8463
8463
|
}
|
|
8464
8464
|
function isConflictPath(value) {
|
|
8465
8465
|
const entry = value;
|
|
@@ -8584,8 +8584,8 @@ var init_sandbox = __esm({
|
|
|
8584
8584
|
this.options = options;
|
|
8585
8585
|
}
|
|
8586
8586
|
options;
|
|
8587
|
-
request(method,
|
|
8588
|
-
return apiRequest(this.options, method,
|
|
8587
|
+
request(method, path18, body) {
|
|
8588
|
+
return apiRequest(this.options, method, path18, body, {
|
|
8589
8589
|
timeoutMs: SANDBOX_REQUEST_TIMEOUT_MS
|
|
8590
8590
|
});
|
|
8591
8591
|
}
|
|
@@ -8715,13 +8715,16 @@ var init_sandbox = __esm({
|
|
|
8715
8715
|
});
|
|
8716
8716
|
|
|
8717
8717
|
// src/worlds/describe.ts
|
|
8718
|
-
async function describeWorld(slugRef, options = {}) {
|
|
8718
|
+
async function describeWorld(slugRef, options = {}, entity) {
|
|
8719
8719
|
const { slug, ref } = parseSlugRef(slugRef);
|
|
8720
|
-
const query =
|
|
8720
|
+
const query = new URLSearchParams();
|
|
8721
|
+
if (ref !== void 0) query.set("ref", ref);
|
|
8722
|
+
if (entity !== void 0) query.set("entity", entity);
|
|
8723
|
+
const search = query.toString() ? `?${query}` : "";
|
|
8721
8724
|
return apiRequest(
|
|
8722
8725
|
options,
|
|
8723
8726
|
"GET",
|
|
8724
|
-
`/api/public/worlds/${encodeURIComponent(slug)}${
|
|
8727
|
+
`/api/public/worlds/${encodeURIComponent(slug)}${search}`
|
|
8725
8728
|
);
|
|
8726
8729
|
}
|
|
8727
8730
|
var init_describe = __esm({
|
|
@@ -9644,8 +9647,8 @@ runpy.run_module('gatewaysdk.environment.schema',run_name='__main__')`;
|
|
|
9644
9647
|
});
|
|
9645
9648
|
|
|
9646
9649
|
// src/worlds/databaseEngines.ts
|
|
9647
|
-
function isWorldSnapshotOutput(
|
|
9648
|
-
return SNAPSHOT_OUTPUTS.has(
|
|
9650
|
+
function isWorldSnapshotOutput(path18) {
|
|
9651
|
+
return SNAPSHOT_OUTPUTS.has(path18.slice(path18.lastIndexOf("/") + 1));
|
|
9649
9652
|
}
|
|
9650
9653
|
var WORLD_DATABASE_ENGINES, DEFAULT_WORLD_DATABASE_ENGINE, WORLD_SNAPSHOT_FILE_PATH, WORLD_SNAPSHOT_SIDECAR_PATH, WORLD_SNAPSHOT_CONTENT_TYPE, SNAPSHOT_OUTPUTS;
|
|
9651
9654
|
var init_databaseEngines = __esm({
|
|
@@ -10255,6 +10258,80 @@ if (fn) {
|
|
|
10255
10258
|
}
|
|
10256
10259
|
});
|
|
10257
10260
|
|
|
10261
|
+
// src/cli/platform/worldData/manifest.ts
|
|
10262
|
+
function recordChunk(manifest, chunk) {
|
|
10263
|
+
manifest.chunks = [...manifest.chunks.filter((c) => c.ordinal !== chunk.ordinal), chunk].sort((a, b) => a.ordinal - b.ordinal);
|
|
10264
|
+
}
|
|
10265
|
+
function uploadedEntry(manifest, ordinal, digest) {
|
|
10266
|
+
return manifest.chunks.find((c) => c.ordinal === ordinal && c.digest === digest && c.uploaded) ?? null;
|
|
10267
|
+
}
|
|
10268
|
+
var fs11, path12, STEM, MANIFEST_DIR, stamp, sameInputs, ManifestShelf, IMPORT_MANIFESTS;
|
|
10269
|
+
var init_manifest = __esm({
|
|
10270
|
+
"src/cli/platform/worldData/manifest.ts"() {
|
|
10271
|
+
"use strict";
|
|
10272
|
+
fs11 = __toESM(require("fs"));
|
|
10273
|
+
path12 = __toESM(require("path"));
|
|
10274
|
+
init_router();
|
|
10275
|
+
STEM = /^[A-Za-z0-9_-]+$/;
|
|
10276
|
+
MANIFEST_DIR = path12.join(".gateway", "imports");
|
|
10277
|
+
stamp = () => (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
10278
|
+
sameInputs = (a, b) => a.length === b.length && a.every((x, i) => x === b[i]);
|
|
10279
|
+
ManifestShelf = class {
|
|
10280
|
+
constructor(dir, stem) {
|
|
10281
|
+
this.dir = dir;
|
|
10282
|
+
this.stem = stem;
|
|
10283
|
+
}
|
|
10284
|
+
dir;
|
|
10285
|
+
stem;
|
|
10286
|
+
dirIn(cwd = process.cwd()) {
|
|
10287
|
+
return path12.join(cwd, this.dir);
|
|
10288
|
+
}
|
|
10289
|
+
file(stem, cwd) {
|
|
10290
|
+
if (!STEM.test(stem)) throw new CliError(`Not a manifest name: ${stem}`);
|
|
10291
|
+
return path12.join(this.dirIn(cwd), `${stem}.json`);
|
|
10292
|
+
}
|
|
10293
|
+
// .gateway/ ignores itself so a manifest, which names hosts and inputs, never enters a repository.
|
|
10294
|
+
write(manifest, cwd = process.cwd()) {
|
|
10295
|
+
const file = this.file(this.stem(manifest), cwd);
|
|
10296
|
+
fs11.mkdirSync(path12.dirname(file), { recursive: true });
|
|
10297
|
+
const ignore = path12.join(cwd, ".gateway", ".gitignore");
|
|
10298
|
+
if (!fs11.existsSync(ignore)) fs11.writeFileSync(ignore, "*\n");
|
|
10299
|
+
manifest.updatedAt = stamp();
|
|
10300
|
+
const tmp = `${file}.tmp`;
|
|
10301
|
+
fs11.writeFileSync(tmp, JSON.stringify(manifest, null, 1) + "\n");
|
|
10302
|
+
fs11.renameSync(tmp, file);
|
|
10303
|
+
return file;
|
|
10304
|
+
}
|
|
10305
|
+
record(manifest, chunk, cwd = process.cwd()) {
|
|
10306
|
+
recordChunk(manifest, chunk);
|
|
10307
|
+
this.write(manifest, cwd);
|
|
10308
|
+
}
|
|
10309
|
+
read(stem, cwd = process.cwd()) {
|
|
10310
|
+
try {
|
|
10311
|
+
const parsed = JSON.parse(fs11.readFileSync(this.file(stem, cwd), "utf8"));
|
|
10312
|
+
return parsed && parsed.version === 1 && this.stem(parsed) === stem ? parsed : null;
|
|
10313
|
+
} catch {
|
|
10314
|
+
return null;
|
|
10315
|
+
}
|
|
10316
|
+
}
|
|
10317
|
+
list(cwd = process.cwd()) {
|
|
10318
|
+
const dir = this.dirIn(cwd);
|
|
10319
|
+
if (!fs11.existsSync(dir)) return [];
|
|
10320
|
+
const out = [];
|
|
10321
|
+
for (const name of fs11.readdirSync(dir)) {
|
|
10322
|
+
const manifest = name.endsWith(".json") ? this.read(name.slice(0, -5), cwd) : null;
|
|
10323
|
+
if (manifest) out.push(manifest);
|
|
10324
|
+
}
|
|
10325
|
+
return out.sort((a, b) => Number(a.updatedAt < b.updatedAt) - Number(a.updatedAt > b.updatedAt));
|
|
10326
|
+
}
|
|
10327
|
+
resumable(slug, inputs, cwd = process.cwd()) {
|
|
10328
|
+
return this.list(cwd).find((m) => !m.completed && m.slug === slug && sameInputs(m.inputs, inputs)) ?? null;
|
|
10329
|
+
}
|
|
10330
|
+
};
|
|
10331
|
+
IMPORT_MANIFESTS = new ManifestShelf(MANIFEST_DIR, (key2) => key2.batchId);
|
|
10332
|
+
}
|
|
10333
|
+
});
|
|
10334
|
+
|
|
10258
10335
|
// src/cli/platform/worldData/batches.ts
|
|
10259
10336
|
function isSettled(status) {
|
|
10260
10337
|
if (!TERMINAL_STATES.has(status.state)) return false;
|
|
@@ -10317,14 +10394,16 @@ function phaseLine(status) {
|
|
|
10317
10394
|
const phase = status.progress?.phase;
|
|
10318
10395
|
return phase ? `${status.state} (${phase})` : status.state;
|
|
10319
10396
|
}
|
|
10320
|
-
var import_node_crypto10,
|
|
10397
|
+
var import_node_crypto10, fs12, CHUNK_PARALLEL, TERMINAL_STATES, sleepMs, WorldDataApi, ChunkUploader;
|
|
10321
10398
|
var init_batches = __esm({
|
|
10322
10399
|
"src/cli/platform/worldData/batches.ts"() {
|
|
10323
10400
|
"use strict";
|
|
10324
10401
|
import_node_crypto10 = require("crypto");
|
|
10325
|
-
|
|
10402
|
+
fs12 = __toESM(require("fs"));
|
|
10326
10403
|
init_config();
|
|
10327
10404
|
init_router();
|
|
10405
|
+
init_manifest();
|
|
10406
|
+
CHUNK_PARALLEL = 4;
|
|
10328
10407
|
TERMINAL_STATES = /* @__PURE__ */ new Set([
|
|
10329
10408
|
"applied",
|
|
10330
10409
|
"refused",
|
|
@@ -10351,13 +10430,7 @@ var init_batches = __esm({
|
|
|
10351
10430
|
this.creds,
|
|
10352
10431
|
"POST",
|
|
10353
10432
|
`${this.base}/batches/${batchId}/chunks`,
|
|
10354
|
-
|
|
10355
|
-
ordinal: chunk.ordinal,
|
|
10356
|
-
digest: chunk.digest,
|
|
10357
|
-
bytes: chunk.bytes,
|
|
10358
|
-
rows: chunk.rows,
|
|
10359
|
-
...chunk.entity ? { entity: chunk.entity } : {}
|
|
10360
|
-
}
|
|
10433
|
+
chunk
|
|
10361
10434
|
);
|
|
10362
10435
|
}
|
|
10363
10436
|
async stageDrive(batchId, chunk) {
|
|
@@ -10413,6 +10486,23 @@ var init_batches = __esm({
|
|
|
10413
10486
|
message ? { message } : {}
|
|
10414
10487
|
);
|
|
10415
10488
|
}
|
|
10489
|
+
chunks(batchId) {
|
|
10490
|
+
return new ChunkUploader(
|
|
10491
|
+
{
|
|
10492
|
+
register: (chunk) => this.register(batchId, chunk),
|
|
10493
|
+
uploaded: (chunkId) => this.markUploaded(batchId, chunkId)
|
|
10494
|
+
},
|
|
10495
|
+
this.sleep
|
|
10496
|
+
);
|
|
10497
|
+
}
|
|
10498
|
+
};
|
|
10499
|
+
ChunkUploader = class {
|
|
10500
|
+
constructor(door, sleep5 = sleepMs) {
|
|
10501
|
+
this.door = door;
|
|
10502
|
+
this.sleep = sleep5;
|
|
10503
|
+
}
|
|
10504
|
+
door;
|
|
10505
|
+
sleep;
|
|
10416
10506
|
async put(uploadUrl, gz, signed) {
|
|
10417
10507
|
const headers = signed ?? uploadHeadersFor(gz);
|
|
10418
10508
|
const delays = [500, 1500, 4e3];
|
|
@@ -10439,17 +10529,15 @@ var init_batches = __esm({
|
|
|
10439
10529
|
await this.sleep(delays[attempt]);
|
|
10440
10530
|
}
|
|
10441
10531
|
}
|
|
10442
|
-
async upload(
|
|
10443
|
-
const registered = await this.register(
|
|
10444
|
-
|
|
10445
|
-
|
|
10446
|
-
|
|
10447
|
-
|
|
10448
|
-
|
|
10449
|
-
|
|
10450
|
-
|
|
10451
|
-
await this.markUploaded(batchId, registered.chunkId);
|
|
10452
|
-
}
|
|
10532
|
+
async upload(chunk) {
|
|
10533
|
+
const registered = await this.door.register({
|
|
10534
|
+
ordinal: chunk.ordinal,
|
|
10535
|
+
digest: chunk.digest,
|
|
10536
|
+
bytes: chunk.bytes,
|
|
10537
|
+
rows: chunk.rows,
|
|
10538
|
+
...chunk.entity ? { entity: chunk.entity } : {}
|
|
10539
|
+
});
|
|
10540
|
+
if (!registered.uploaded) await this.send(chunk, registered);
|
|
10453
10541
|
return {
|
|
10454
10542
|
ordinal: chunk.ordinal,
|
|
10455
10543
|
digest: chunk.digest,
|
|
@@ -10460,6 +10548,28 @@ var init_batches = __esm({
|
|
|
10460
10548
|
uploaded: true
|
|
10461
10549
|
};
|
|
10462
10550
|
}
|
|
10551
|
+
async send(chunk, registered) {
|
|
10552
|
+
if (!registered.uploadUrl)
|
|
10553
|
+
throw new CliError(
|
|
10554
|
+
`the server registered chunk ${chunk.ordinal} without an upload URL`,
|
|
10555
|
+
1
|
|
10556
|
+
);
|
|
10557
|
+
await this.put(registered.uploadUrl, chunk.gz, registered.uploadHeaders);
|
|
10558
|
+
await this.door.uploaded(registered.chunkId);
|
|
10559
|
+
}
|
|
10560
|
+
async uploadAll(chunks, kept, parallel, progress) {
|
|
10561
|
+
await forEachLimited(chunks, parallel, async (chunk) => {
|
|
10562
|
+
if (uploadedEntry(kept.manifest, chunk.ordinal, chunk.digest)) {
|
|
10563
|
+
progress(`chunk ${chunk.ordinal}: already uploaded (${chunk.rows} rows)`);
|
|
10564
|
+
return;
|
|
10565
|
+
}
|
|
10566
|
+
const entry = await this.upload(chunk);
|
|
10567
|
+
kept.shelf.record(kept.manifest, entry);
|
|
10568
|
+
progress(
|
|
10569
|
+
`chunk ${chunk.ordinal}: uploaded ${chunk.rows} rows, ${chunk.bytes} bytes (${entry.chunkId})`
|
|
10570
|
+
);
|
|
10571
|
+
});
|
|
10572
|
+
}
|
|
10463
10573
|
};
|
|
10464
10574
|
}
|
|
10465
10575
|
});
|
|
@@ -10595,11 +10705,12 @@ async function pushRows(creds, slug, rows, opts = {}) {
|
|
|
10595
10705
|
chunkRows: null,
|
|
10596
10706
|
entity: null
|
|
10597
10707
|
});
|
|
10708
|
+
const uploader = client2.chunks(opened.batchId);
|
|
10598
10709
|
await forEachLimited(
|
|
10599
10710
|
chunks,
|
|
10600
|
-
Math.max(1, opts.parallel ??
|
|
10711
|
+
Math.max(1, opts.parallel ?? CHUNK_PARALLEL),
|
|
10601
10712
|
async (chunk) => {
|
|
10602
|
-
await
|
|
10713
|
+
await uploader.upload(chunk);
|
|
10603
10714
|
}
|
|
10604
10715
|
);
|
|
10605
10716
|
await client2.complete(opened.batchId);
|
|
@@ -10637,7 +10748,7 @@ function parseToolCallRecord(raw) {
|
|
|
10637
10748
|
}
|
|
10638
10749
|
function readToolCallRecords(paths) {
|
|
10639
10750
|
const records = [];
|
|
10640
|
-
for (const file of paths) records.push(...toolCallRecordsIn(
|
|
10751
|
+
for (const file of paths) records.push(...toolCallRecordsIn(fs13.readFileSync(file, "utf8"), file));
|
|
10641
10752
|
return records;
|
|
10642
10753
|
}
|
|
10643
10754
|
function toolCallRecordsIn(text2, where) {
|
|
@@ -10673,7 +10784,7 @@ async function emit(sink, record) {
|
|
|
10673
10784
|
return;
|
|
10674
10785
|
}
|
|
10675
10786
|
if (typeof sink === "string") {
|
|
10676
|
-
|
|
10787
|
+
fs13.appendFileSync(sink, JSON.stringify(record) + "\n");
|
|
10677
10788
|
return;
|
|
10678
10789
|
}
|
|
10679
10790
|
if (typeof sink === "function") {
|
|
@@ -10755,7 +10866,7 @@ async function ingest(world, records, options = {}) {
|
|
|
10755
10866
|
const redact = options.redact ?? "off";
|
|
10756
10867
|
const mode = options.mode ?? "append";
|
|
10757
10868
|
const dryRun = Boolean(options.dryRun);
|
|
10758
|
-
const local =
|
|
10869
|
+
const local = fs13.existsSync(world) && fs13.statSync(world).isDirectory();
|
|
10759
10870
|
const creds = local ? await runtimeEndpoint(options) : platformEndpoint(options);
|
|
10760
10871
|
const map = options.map === void 0 ? void 0 : options.map;
|
|
10761
10872
|
let rows = null;
|
|
@@ -10772,9 +10883,9 @@ async function ingest(world, records, options = {}) {
|
|
|
10772
10883
|
if (!creds) throw new Error(GATEWAY_KEYS_MISSING);
|
|
10773
10884
|
const { pull: pull2 } = await Promise.resolve().then(() => (init_hub(), hub_exports));
|
|
10774
10885
|
const slug = world.split("@", 1)[0];
|
|
10775
|
-
const scratch =
|
|
10886
|
+
const scratch = fs13.mkdtempSync(path13.join(os3.tmpdir(), "gateway-ingest-"));
|
|
10776
10887
|
try {
|
|
10777
|
-
const pulled = await pull2(world,
|
|
10888
|
+
const pulled = await pull2(world, path13.join(scratch, slug), options);
|
|
10778
10889
|
let report;
|
|
10779
10890
|
let projected;
|
|
10780
10891
|
if (rows === null) {
|
|
@@ -10795,7 +10906,7 @@ async function ingest(world, records, options = {}) {
|
|
|
10795
10906
|
if (status.entityCounts) report.entityCounts = status.entityCounts;
|
|
10796
10907
|
return report;
|
|
10797
10908
|
} finally {
|
|
10798
|
-
|
|
10909
|
+
fs13.rmSync(scratch, { recursive: true, force: true });
|
|
10799
10910
|
}
|
|
10800
10911
|
}
|
|
10801
10912
|
async function ingestToolCalls(world, records, options = {}) {
|
|
@@ -10848,13 +10959,13 @@ async function sessionToolObservations(sessionId, options = {}) {
|
|
|
10848
10959
|
for (const observation of trace5.observations ?? []) out.push({ traceId: trace5.id ?? null, ...observation });
|
|
10849
10960
|
return out;
|
|
10850
10961
|
}
|
|
10851
|
-
var
|
|
10962
|
+
var fs13, os3, path13, isObject2, isoOf;
|
|
10852
10963
|
var init_ingest = __esm({
|
|
10853
10964
|
"src/worlds/ingest.ts"() {
|
|
10854
10965
|
"use strict";
|
|
10855
|
-
|
|
10966
|
+
fs13 = __toESM(require("fs"));
|
|
10856
10967
|
os3 = __toESM(require("os"));
|
|
10857
|
-
|
|
10968
|
+
path13 = __toESM(require("path"));
|
|
10858
10969
|
init_worlds();
|
|
10859
10970
|
init_platformEndpoint();
|
|
10860
10971
|
init_personalToken();
|
|
@@ -11263,8 +11374,8 @@ __export(worlds_exports, {
|
|
|
11263
11374
|
worldRequestsUnrecorded: () => worldRequestsUnrecorded,
|
|
11264
11375
|
writeLocalMeta: () => writeLocalMeta
|
|
11265
11376
|
});
|
|
11266
|
-
async function apiRequest(options, method,
|
|
11267
|
-
return new PlatformTransport(requirePlatformEndpoint(options)).json(method,
|
|
11377
|
+
async function apiRequest(options, method, path18, body, init3 = {}) {
|
|
11378
|
+
return new PlatformTransport(requirePlatformEndpoint(options)).json(method, path18, body, init3);
|
|
11268
11379
|
}
|
|
11269
11380
|
async function setEnvSecret(slug, key2, value, options = {}) {
|
|
11270
11381
|
return apiRequest(
|
|
@@ -12454,8 +12565,8 @@ var GatewayContext = class _GatewayContext {
|
|
|
12454
12565
|
}
|
|
12455
12566
|
return resolved;
|
|
12456
12567
|
}
|
|
12457
|
-
async requestJson(method,
|
|
12458
|
-
const response = await fetch(`${this.host}${
|
|
12568
|
+
async requestJson(method, path18, payload) {
|
|
12569
|
+
const response = await fetch(`${this.host}${path18}`, {
|
|
12459
12570
|
method,
|
|
12460
12571
|
headers: {
|
|
12461
12572
|
Authorization: this.authHeader(),
|
|
@@ -12466,7 +12577,7 @@ var GatewayContext = class _GatewayContext {
|
|
|
12466
12577
|
const text2 = await response.text();
|
|
12467
12578
|
const body = text2 ? safeJson(text2) : {};
|
|
12468
12579
|
if (!response.ok) {
|
|
12469
|
-
const message = typeof body.message === "string" ? body.message : `Gateway API ${response.status} on ${
|
|
12580
|
+
const message = typeof body.message === "string" ? body.message : `Gateway API ${response.status} on ${path18}`;
|
|
12470
12581
|
if (response.status === 409) {
|
|
12471
12582
|
throw new GatewayContextConflictError(
|
|
12472
12583
|
message,
|
|
@@ -12475,7 +12586,7 @@ var GatewayContext = class _GatewayContext {
|
|
|
12475
12586
|
}
|
|
12476
12587
|
throw new GatewayContextError(message);
|
|
12477
12588
|
}
|
|
12478
|
-
this.log("%s %s -> %s", method,
|
|
12589
|
+
this.log("%s %s -> %s", method, path18, response.status);
|
|
12479
12590
|
return body;
|
|
12480
12591
|
}
|
|
12481
12592
|
authHeader() {
|
|
@@ -12582,11 +12693,11 @@ function primaryPathForKind(kind, snapshot) {
|
|
|
12582
12693
|
const preferred = kind === "agent" ? "AGENTS.md" : kind === "prompt" ? "PROMPT.md" : kind === "skill" ? "SKILL.md" : "MEMORY.md";
|
|
12583
12694
|
if (readFile(snapshot, preferred)) return preferred;
|
|
12584
12695
|
return Object.entries(snapshot.files).find(
|
|
12585
|
-
([
|
|
12696
|
+
([path18, entry]) => entry.type === "file" && path18.endsWith(".md")
|
|
12586
12697
|
)?.[0] ?? null;
|
|
12587
12698
|
}
|
|
12588
|
-
function parseJsonFile(snapshot,
|
|
12589
|
-
const content = readFile(snapshot,
|
|
12699
|
+
function parseJsonFile(snapshot, path18) {
|
|
12700
|
+
const content = readFile(snapshot, path18);
|
|
12590
12701
|
if (!content) return {};
|
|
12591
12702
|
try {
|
|
12592
12703
|
const parsed = JSON.parse(content);
|
|
@@ -12595,8 +12706,8 @@ function parseJsonFile(snapshot, path17) {
|
|
|
12595
12706
|
return {};
|
|
12596
12707
|
}
|
|
12597
12708
|
}
|
|
12598
|
-
function readFile(snapshot,
|
|
12599
|
-
const entry = snapshot.files[
|
|
12709
|
+
function readFile(snapshot, path18) {
|
|
12710
|
+
const entry = snapshot.files[path18];
|
|
12600
12711
|
return entry?.type === "file" ? entry.content : null;
|
|
12601
12712
|
}
|
|
12602
12713
|
function provenanceFor(snapshot, label) {
|
|
@@ -12698,16 +12809,16 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
12698
12809
|
`/api/public/context/memory/${encodeIdentifier2(identifier)}${suffix}`
|
|
12699
12810
|
);
|
|
12700
12811
|
}
|
|
12701
|
-
async read(target,
|
|
12812
|
+
async read(target, path18, options = {}) {
|
|
12702
12813
|
const snapshot = typeof target === "string" ? await this.pull(target, options) : target;
|
|
12703
|
-
const file = snapshot.files[
|
|
12814
|
+
const file = snapshot.files[path18];
|
|
12704
12815
|
return file?.type === "file" ? file.content : null;
|
|
12705
12816
|
}
|
|
12706
|
-
async write(target,
|
|
12817
|
+
async write(target, path18, content, options = {}) {
|
|
12707
12818
|
const snapshot = typeof target === "string" ? await this.pull(target) : target;
|
|
12708
12819
|
return this.push(snapshot.repo.repoHandle, {
|
|
12709
12820
|
files: {
|
|
12710
|
-
[
|
|
12821
|
+
[path18]: {
|
|
12711
12822
|
content,
|
|
12712
12823
|
...options.mimeType ? { mimeType: options.mimeType } : {}
|
|
12713
12824
|
}
|
|
@@ -12717,10 +12828,10 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
12717
12828
|
...runtimeContextPayload2(options)
|
|
12718
12829
|
});
|
|
12719
12830
|
}
|
|
12720
|
-
async delete(target,
|
|
12831
|
+
async delete(target, path18, options = {}) {
|
|
12721
12832
|
const snapshot = typeof target === "string" ? await this.pull(target) : target;
|
|
12722
12833
|
return this.push(snapshot.repo.repoHandle, {
|
|
12723
|
-
files: { [
|
|
12834
|
+
files: { [path18]: null },
|
|
12724
12835
|
parentCommit: options.parentCommit ?? snapshot.commit.commitHash,
|
|
12725
12836
|
message: options.message,
|
|
12726
12837
|
...runtimeContextPayload2(options)
|
|
@@ -12733,8 +12844,8 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
12733
12844
|
payload
|
|
12734
12845
|
);
|
|
12735
12846
|
}
|
|
12736
|
-
async requestJson(method,
|
|
12737
|
-
const response = await fetch(`${this.host}${
|
|
12847
|
+
async requestJson(method, path18, payload) {
|
|
12848
|
+
const response = await fetch(`${this.host}${path18}`, {
|
|
12738
12849
|
method,
|
|
12739
12850
|
headers: {
|
|
12740
12851
|
Authorization: this.authHeader(),
|
|
@@ -12745,7 +12856,7 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
12745
12856
|
const text2 = await response.text();
|
|
12746
12857
|
const body = text2 ? safeJson2(text2) : {};
|
|
12747
12858
|
if (!response.ok) {
|
|
12748
|
-
const message = typeof body.message === "string" ? body.message : `Gateway API ${response.status} on ${
|
|
12859
|
+
const message = typeof body.message === "string" ? body.message : `Gateway API ${response.status} on ${path18}`;
|
|
12749
12860
|
if (response.status === 409) {
|
|
12750
12861
|
throw new GatewayMemoryConflictError(
|
|
12751
12862
|
message,
|
|
@@ -12754,7 +12865,7 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
12754
12865
|
}
|
|
12755
12866
|
throw new GatewayMemoryError(message);
|
|
12756
12867
|
}
|
|
12757
|
-
this.log("%s %s -> %s", method,
|
|
12868
|
+
this.log("%s %s -> %s", method, path18, response.status);
|
|
12758
12869
|
return body;
|
|
12759
12870
|
}
|
|
12760
12871
|
authHeader() {
|
|
@@ -12916,10 +13027,10 @@ var PersonasClient = class _PersonasClient {
|
|
|
12916
13027
|
done: Boolean(payload.done)
|
|
12917
13028
|
};
|
|
12918
13029
|
}
|
|
12919
|
-
async requestJson(method,
|
|
13030
|
+
async requestJson(method, path18, payload) {
|
|
12920
13031
|
let response;
|
|
12921
13032
|
try {
|
|
12922
|
-
response = await fetch(`${this.host}${
|
|
13033
|
+
response = await fetch(`${this.host}${path18}`, {
|
|
12923
13034
|
method,
|
|
12924
13035
|
headers: {
|
|
12925
13036
|
Authorization: this.authHeader(),
|
|
@@ -12930,7 +13041,7 @@ var PersonasClient = class _PersonasClient {
|
|
|
12930
13041
|
});
|
|
12931
13042
|
} catch (error) {
|
|
12932
13043
|
const reason = error instanceof Error ? error.message : String(error);
|
|
12933
|
-
throw new PersonaError(`${method} ${
|
|
13044
|
+
throw new PersonaError(`${method} ${path18} failed: ${reason}`, {
|
|
12934
13045
|
cause: error
|
|
12935
13046
|
});
|
|
12936
13047
|
}
|
|
@@ -12938,10 +13049,10 @@ var PersonasClient = class _PersonasClient {
|
|
|
12938
13049
|
if (!response.ok) {
|
|
12939
13050
|
const detail = text2.slice(0, 500);
|
|
12940
13051
|
throw new PersonaError(
|
|
12941
|
-
`${method} ${
|
|
13052
|
+
`${method} ${path18} failed (${response.status}): ${detail}`
|
|
12942
13053
|
);
|
|
12943
13054
|
}
|
|
12944
|
-
this.log("%s %s -> %s", method,
|
|
13055
|
+
this.log("%s %s -> %s", method, path18, response.status);
|
|
12945
13056
|
return safeJson3(text2);
|
|
12946
13057
|
}
|
|
12947
13058
|
authHeader() {
|
|
@@ -13166,10 +13277,10 @@ var SessionRecording = class _SessionRecording {
|
|
|
13166
13277
|
};
|
|
13167
13278
|
}
|
|
13168
13279
|
/** Dump the full session as a JSON fixture (for regression tests). */
|
|
13169
|
-
toFixture(
|
|
13170
|
-
(0, import_node_fs.mkdirSync)((0, import_node_path.dirname)(
|
|
13171
|
-
(0, import_node_fs.writeFileSync)(
|
|
13172
|
-
return
|
|
13280
|
+
toFixture(path18) {
|
|
13281
|
+
(0, import_node_fs.mkdirSync)((0, import_node_path.dirname)(path18), { recursive: true });
|
|
13282
|
+
(0, import_node_fs.writeFileSync)(path18, JSON.stringify(this.toJSON(), null, 2), "utf-8");
|
|
13283
|
+
return path18;
|
|
13173
13284
|
}
|
|
13174
13285
|
static fromApi(raw) {
|
|
13175
13286
|
return new _SessionRecording({
|
|
@@ -14200,8 +14311,8 @@ var GatewaySecurity = class _GatewaySecurity {
|
|
|
14200
14311
|
);
|
|
14201
14312
|
}
|
|
14202
14313
|
}
|
|
14203
|
-
async postJson(
|
|
14204
|
-
const response = await fetch(`${this.host}${
|
|
14314
|
+
async postJson(path18, payload) {
|
|
14315
|
+
const response = await fetch(`${this.host}${path18}`, {
|
|
14205
14316
|
method: "POST",
|
|
14206
14317
|
headers: {
|
|
14207
14318
|
Authorization: this.authHeader(),
|
|
@@ -14212,7 +14323,7 @@ var GatewaySecurity = class _GatewaySecurity {
|
|
|
14212
14323
|
if (!response.ok) {
|
|
14213
14324
|
const body = await response.text();
|
|
14214
14325
|
throw new GatewaySecurityError(
|
|
14215
|
-
`Gateway API ${response.status} on ${
|
|
14326
|
+
`Gateway API ${response.status} on ${path18}: ${body || response.statusText}`
|
|
14216
14327
|
);
|
|
14217
14328
|
}
|
|
14218
14329
|
return await response.json();
|
|
@@ -14310,8 +14421,8 @@ var AgentPatch = class _AgentPatch {
|
|
|
14310
14421
|
// src/agents/agent.ts
|
|
14311
14422
|
var AgentVersionConflictError = class extends ApiError {
|
|
14312
14423
|
currentVersionId;
|
|
14313
|
-
constructor(status, method,
|
|
14314
|
-
super(status, method,
|
|
14424
|
+
constructor(status, method, path18, text2) {
|
|
14425
|
+
super(status, method, path18, text2);
|
|
14315
14426
|
this.name = "AgentVersionConflictError";
|
|
14316
14427
|
this.currentVersionId = currentVersionOf(text2);
|
|
14317
14428
|
}
|
|
@@ -14481,8 +14592,8 @@ function freezeGrant(grant2) {
|
|
|
14481
14592
|
const only = grant2.only ? { only: Object.freeze([...grant2.only]) } : {};
|
|
14482
14593
|
return Object.freeze({ server: grant2.server, ...only });
|
|
14483
14594
|
}
|
|
14484
|
-
function pathText(
|
|
14485
|
-
return
|
|
14595
|
+
function pathText(path18) {
|
|
14596
|
+
return path18.length === 0 ? "definition" : path18.join(".");
|
|
14486
14597
|
}
|
|
14487
14598
|
function isRecord2(value) {
|
|
14488
14599
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -14541,38 +14652,38 @@ var DefinitionReader = class _DefinitionReader {
|
|
|
14541
14652
|
);
|
|
14542
14653
|
return grants.filter((grant2) => grant2 !== null);
|
|
14543
14654
|
}
|
|
14544
|
-
grant(entry,
|
|
14655
|
+
grant(entry, path18) {
|
|
14545
14656
|
if (typeof entry === "string") return { server: entry };
|
|
14546
|
-
if (!isRecord2(entry)) return this.refuse(
|
|
14547
|
-
this.unknownFields(entry, GRANT_FIELDS,
|
|
14548
|
-
const server = this.string(entry.server, [...
|
|
14657
|
+
if (!isRecord2(entry)) return this.refuse(path18, "invalid_type", "a server name or { server, only }", null);
|
|
14658
|
+
this.unknownFields(entry, GRANT_FIELDS, path18);
|
|
14659
|
+
const server = this.string(entry.server, [...path18, "server"]);
|
|
14549
14660
|
if (server === null) return null;
|
|
14550
|
-
return entry.only === void 0 ? { server } : { server, only: this.only(entry.only, [...
|
|
14661
|
+
return entry.only === void 0 ? { server } : { server, only: this.only(entry.only, [...path18, "only"]) };
|
|
14551
14662
|
}
|
|
14552
|
-
only(value,
|
|
14553
|
-
if (!Array.isArray(value)) return this.refuse(
|
|
14663
|
+
only(value, path18) {
|
|
14664
|
+
if (!Array.isArray(value)) return this.refuse(path18, "invalid_type", "a list of tool names", []);
|
|
14554
14665
|
if (value.length === 0)
|
|
14555
|
-
this.issue(
|
|
14556
|
-
const names = value.map((name, index2) => this.string(name, [...
|
|
14557
|
-
this.noRepeats(names, (index2) => [...
|
|
14666
|
+
this.issue(path18, "too_small", "names at least one tool; leave `only` out to grant the whole server");
|
|
14667
|
+
const names = value.map((name, index2) => this.string(name, [...path18, index2]));
|
|
14668
|
+
this.noRepeats(names, (index2) => [...path18, index2], "duplicate_tool", "this tool is already named");
|
|
14558
14669
|
return names.filter(isString).sort();
|
|
14559
14670
|
}
|
|
14560
|
-
string(value,
|
|
14671
|
+
string(value, path18) {
|
|
14561
14672
|
if (typeof value === "string") return value;
|
|
14562
|
-
return this.refuse(
|
|
14673
|
+
return this.refuse(path18, "invalid_type", "a string", null);
|
|
14563
14674
|
}
|
|
14564
|
-
optionalString(value,
|
|
14675
|
+
optionalString(value, path18) {
|
|
14565
14676
|
if (value === void 0) return void 0;
|
|
14566
|
-
return this.string(value,
|
|
14677
|
+
return this.string(value, path18) ?? void 0;
|
|
14567
14678
|
}
|
|
14568
|
-
bounded(value, bounds,
|
|
14569
|
-
if (value < bounds.min) this.issue(
|
|
14570
|
-
if (value > bounds.max) this.issue(
|
|
14679
|
+
bounded(value, bounds, path18, unit) {
|
|
14680
|
+
if (value < bounds.min) this.issue(path18, "too_small", `at least ${bounds.min} ${unit}`);
|
|
14681
|
+
if (value > bounds.max) this.issue(path18, "too_large", `at most ${bounds.max} ${unit}`);
|
|
14571
14682
|
}
|
|
14572
|
-
unknownFields(record, known,
|
|
14683
|
+
unknownFields(record, known, path18) {
|
|
14573
14684
|
for (const [key2, value] of Object.entries(record)) {
|
|
14574
14685
|
if (value !== void 0 && !known.has(key2))
|
|
14575
|
-
this.issue([...
|
|
14686
|
+
this.issue([...path18, key2], "unknown_field", "not a field of an agent definition");
|
|
14576
14687
|
}
|
|
14577
14688
|
}
|
|
14578
14689
|
noRepeats(values, pathOf, code, message) {
|
|
@@ -14583,11 +14694,11 @@ var DefinitionReader = class _DefinitionReader {
|
|
|
14583
14694
|
seen.add(value);
|
|
14584
14695
|
});
|
|
14585
14696
|
}
|
|
14586
|
-
issue(
|
|
14587
|
-
this.#issues.push({ path:
|
|
14697
|
+
issue(path18, code, message) {
|
|
14698
|
+
this.#issues.push({ path: path18, code, message });
|
|
14588
14699
|
}
|
|
14589
|
-
refuse(
|
|
14590
|
-
this.issue(
|
|
14700
|
+
refuse(path18, code, message, fallback) {
|
|
14701
|
+
this.issue(path18, code, message);
|
|
14591
14702
|
return fallback;
|
|
14592
14703
|
}
|
|
14593
14704
|
};
|
|
@@ -14695,12 +14806,12 @@ var Agents = class {
|
|
|
14695
14806
|
}
|
|
14696
14807
|
return builds;
|
|
14697
14808
|
}
|
|
14698
|
-
async conflictAware(method,
|
|
14809
|
+
async conflictAware(method, path18, body) {
|
|
14699
14810
|
try {
|
|
14700
|
-
return await this.#transport.json(method,
|
|
14811
|
+
return await this.#transport.json(method, path18, body);
|
|
14701
14812
|
} catch (error) {
|
|
14702
14813
|
if (error instanceof ApiError && error.code === "agent_version_conflict")
|
|
14703
|
-
throw new AgentVersionConflictError(error.status, method,
|
|
14814
|
+
throw new AgentVersionConflictError(error.status, method, path18, error.text);
|
|
14704
14815
|
throw error;
|
|
14705
14816
|
}
|
|
14706
14817
|
}
|
|
@@ -15211,6 +15322,35 @@ var AGENT_EFFORTS = ["low", "medium", "high", "xhigh"];
|
|
|
15211
15322
|
var TOOL_SERVERS = {
|
|
15212
15323
|
docs: ["search_docs"],
|
|
15213
15324
|
drive: ["get_drive_file", "list_drive_files", "save_drive_file"],
|
|
15325
|
+
factory: [
|
|
15326
|
+
"accept_factory_unit",
|
|
15327
|
+
"check_world_sandbox",
|
|
15328
|
+
"close_world_sandbox",
|
|
15329
|
+
"commit_world_sandbox",
|
|
15330
|
+
"describe_member",
|
|
15331
|
+
"diff_factory_revisions",
|
|
15332
|
+
"exec_in_world_sandbox",
|
|
15333
|
+
"generate_spine",
|
|
15334
|
+
"get_factory",
|
|
15335
|
+
"get_factory_data",
|
|
15336
|
+
"get_factory_revision",
|
|
15337
|
+
"get_spine",
|
|
15338
|
+
"get_spine_rows",
|
|
15339
|
+
"get_world_sandbox",
|
|
15340
|
+
"import_world_sandbox_data",
|
|
15341
|
+
"list_factory_revisions",
|
|
15342
|
+
"open_world_sandbox",
|
|
15343
|
+
"query_factory_data",
|
|
15344
|
+
"read_world_sandbox_file",
|
|
15345
|
+
"release_factory_data",
|
|
15346
|
+
"update_entity_graph",
|
|
15347
|
+
"update_ontology",
|
|
15348
|
+
"update_rules",
|
|
15349
|
+
"update_spine",
|
|
15350
|
+
"update_tests",
|
|
15351
|
+
"write_records",
|
|
15352
|
+
"write_world_sandbox_file"
|
|
15353
|
+
],
|
|
15214
15354
|
sandbox: [
|
|
15215
15355
|
"copy_file",
|
|
15216
15356
|
"execute_python",
|
|
@@ -15229,6 +15369,7 @@ var grant = (server) => (options = {}) => options.only ? { server, only: [...opt
|
|
|
15229
15369
|
var tools = Object.freeze({
|
|
15230
15370
|
sandbox: grant("sandbox"),
|
|
15231
15371
|
drive: grant("drive"),
|
|
15372
|
+
factory: grant("factory"),
|
|
15232
15373
|
web: grant("web"),
|
|
15233
15374
|
docs: grant("docs")
|
|
15234
15375
|
});
|
|
@@ -15258,8 +15399,8 @@ __export(files_exports, {
|
|
|
15258
15399
|
uploadFile: () => uploadFile
|
|
15259
15400
|
});
|
|
15260
15401
|
var import_node_crypto12 = require("crypto");
|
|
15261
|
-
var
|
|
15262
|
-
var
|
|
15402
|
+
var fs14 = __toESM(require("fs"));
|
|
15403
|
+
var path14 = __toESM(require("path"));
|
|
15263
15404
|
var import_node_stream = require("stream");
|
|
15264
15405
|
var import_promises = require("stream/promises");
|
|
15265
15406
|
init_worlds();
|
|
@@ -15311,9 +15452,9 @@ async function readFile2(options = {}, filePath, limits = {}) {
|
|
|
15311
15452
|
async function downloadFile(options = {}, filePath, outPath, onProgress) {
|
|
15312
15453
|
const file = await getFile(options, filePath);
|
|
15313
15454
|
const res = await openDownload(file.url);
|
|
15314
|
-
|
|
15455
|
+
fs14.mkdirSync(path14.dirname(path14.resolve(outPath)), { recursive: true });
|
|
15315
15456
|
const source = import_node_stream.Readable.fromWeb(res.body);
|
|
15316
|
-
await (0, import_promises.pipeline)(source, counting((n) => onProgress?.(n, file.sizeBytes)),
|
|
15457
|
+
await (0, import_promises.pipeline)(source, counting((n) => onProgress?.(n, file.sizeBytes)), fs14.createWriteStream(outPath));
|
|
15317
15458
|
return { ...file, out: outPath };
|
|
15318
15459
|
}
|
|
15319
15460
|
async function requestUpload(options = {}, body) {
|
|
@@ -15324,7 +15465,7 @@ async function confirmUpload(options = {}, fileId, ok = true) {
|
|
|
15324
15465
|
}
|
|
15325
15466
|
async function sha256Base64(localPath) {
|
|
15326
15467
|
const hash = (0, import_node_crypto12.createHash)("sha256");
|
|
15327
|
-
for await (const chunk of
|
|
15468
|
+
for await (const chunk of fs14.createReadStream(localPath)) hash.update(chunk);
|
|
15328
15469
|
return hash.digest("base64");
|
|
15329
15470
|
}
|
|
15330
15471
|
var CONTENT_TYPES = {
|
|
@@ -15360,7 +15501,7 @@ var CONTENT_TYPES = {
|
|
|
15360
15501
|
".mp4": "video/mp4"
|
|
15361
15502
|
};
|
|
15362
15503
|
function contentTypeFor(name) {
|
|
15363
|
-
return CONTENT_TYPES[
|
|
15504
|
+
return CONTENT_TYPES[path14.extname(name).toLowerCase()] ?? "application/octet-stream";
|
|
15364
15505
|
}
|
|
15365
15506
|
function counting(report) {
|
|
15366
15507
|
let seen = 0;
|
|
@@ -15387,7 +15528,7 @@ async function putPresigned(uploadUrl, body, headers) {
|
|
|
15387
15528
|
if (!res.ok) throw new Error(`upload failed: storage answered HTTP ${res.status}: ${(await res.text()).slice(0, 300)}`);
|
|
15388
15529
|
}
|
|
15389
15530
|
async function uploadFile(options = {}, localPath, targetPath, upload = {}) {
|
|
15390
|
-
const stat =
|
|
15531
|
+
const stat = fs14.statSync(localPath);
|
|
15391
15532
|
if (!stat.isFile()) throw new Error(`${localPath} is not a file`);
|
|
15392
15533
|
if (stat.size === 0) throw new Error(`${localPath} is empty; the drive refuses zero-byte uploads`);
|
|
15393
15534
|
const contentType = upload.contentType ?? contentTypeFor(localPath);
|
|
@@ -15395,7 +15536,7 @@ async function uploadFile(options = {}, localPath, targetPath, upload = {}) {
|
|
|
15395
15536
|
const target = drivePath(targetPath);
|
|
15396
15537
|
const granted = await requestUpload(options, { path: target, contentLength: stat.size, contentType, sha256: sha2562, ...upload.overwrite ? { overwrite: true } : {} });
|
|
15397
15538
|
try {
|
|
15398
|
-
const stream =
|
|
15539
|
+
const stream = fs14.createReadStream(localPath).pipe(counting((n) => upload.onProgress?.(n, stat.size)));
|
|
15399
15540
|
await putPresigned(granted.uploadUrl, import_node_stream.Readable.toWeb(stream), { contentType, contentLength: stat.size, sha256: sha2562 });
|
|
15400
15541
|
} catch (error) {
|
|
15401
15542
|
await confirmUpload(options, granted.fileId, false).catch(() => void 0);
|
|
@@ -16825,7 +16966,7 @@ function mirrorHandle(handle, identity) {
|
|
|
16825
16966
|
}
|
|
16826
16967
|
|
|
16827
16968
|
// src/hooks/config.ts
|
|
16828
|
-
var
|
|
16969
|
+
var fs15 = __toESM(require("fs"));
|
|
16829
16970
|
|
|
16830
16971
|
// src/cli/platform/worldData/toml.ts
|
|
16831
16972
|
var TomlDateTime = class {
|
|
@@ -16883,26 +17024,26 @@ var TomlReader = class {
|
|
|
16883
17024
|
if (header) return this.header(keyPath(header[1], line), line);
|
|
16884
17025
|
const eq = outsideQuotes(text2, "=");
|
|
16885
17026
|
if (eq === -1) throw new TomlError(`line ${line}: expected key = value`);
|
|
16886
|
-
const
|
|
17027
|
+
const path18 = keyPath(text2.slice(0, eq), line);
|
|
16887
17028
|
const [value, rest] = readValue(text2.slice(eq + 1), line);
|
|
16888
17029
|
if (stripBlank(rest)) throw new TomlError(`line ${line}: unexpected text after value`);
|
|
16889
|
-
assign(this.descend(this.current,
|
|
17030
|
+
assign(this.descend(this.current, path18.slice(0, -1), line, "key"), path18, value, line);
|
|
16890
17031
|
}
|
|
16891
|
-
header(
|
|
16892
|
-
const parent = this.descend(this.root,
|
|
16893
|
-
const name =
|
|
17032
|
+
header(path18, line) {
|
|
17033
|
+
const parent = this.descend(this.root, path18.slice(0, -1), line, "header");
|
|
17034
|
+
const name = path18.at(-1);
|
|
16894
17035
|
const table2 = own(parent, name) ?? newTable();
|
|
16895
17036
|
const fresh = isTomlTable(table2) && !INLINE.has(table2) && !this.byDottedKey.has(table2) && !this.defined.has(table2);
|
|
16896
|
-
if (!fresh) throw new TomlError(`line ${line}: [${
|
|
17037
|
+
if (!fresh) throw new TomlError(`line ${line}: [${path18.join(".")}] is defined twice`);
|
|
16897
17038
|
parent[name] = table2;
|
|
16898
17039
|
this.open(table2);
|
|
16899
17040
|
}
|
|
16900
|
-
arrayTable(
|
|
16901
|
-
const parent = this.descend(this.root,
|
|
16902
|
-
const name =
|
|
17041
|
+
arrayTable(path18, line) {
|
|
17042
|
+
const parent = this.descend(this.root, path18.slice(0, -1), line, "header");
|
|
17043
|
+
const name = path18.at(-1);
|
|
16903
17044
|
const existing = own(parent, name);
|
|
16904
17045
|
if (existing !== void 0 && !(Array.isArray(existing) && this.tableArrays.has(existing)))
|
|
16905
|
-
throw new TomlError(`line ${line}: ${
|
|
17046
|
+
throw new TomlError(`line ${line}: ${path18.join(".")} is not an array of tables`);
|
|
16906
17047
|
const list2 = existing ?? [];
|
|
16907
17048
|
this.tableArrays.add(list2);
|
|
16908
17049
|
parent[name] = list2;
|
|
@@ -16937,9 +17078,9 @@ var TomlReader = class {
|
|
|
16937
17078
|
return target;
|
|
16938
17079
|
}
|
|
16939
17080
|
};
|
|
16940
|
-
function assign(table2,
|
|
16941
|
-
const key2 =
|
|
16942
|
-
if (own(table2, key2) !== void 0) throw new TomlError(`line ${line}: key ${
|
|
17081
|
+
function assign(table2, path18, value, line) {
|
|
17082
|
+
const key2 = path18.at(-1);
|
|
17083
|
+
if (own(table2, key2) !== void 0) throw new TomlError(`line ${line}: key ${path18.join(".")} is defined twice`);
|
|
16943
17084
|
table2[key2] = value;
|
|
16944
17085
|
}
|
|
16945
17086
|
function inlineAt(table2, parts2, line) {
|
|
@@ -17149,9 +17290,9 @@ function readInlineTable(s, line) {
|
|
|
17149
17290
|
for (; ; ) {
|
|
17150
17291
|
const eq = outsideQuotes(rest, "=");
|
|
17151
17292
|
if (eq === -1) throw new TomlError(`line ${line}: expected key = value in inline table`);
|
|
17152
|
-
const
|
|
17293
|
+
const path18 = keyPath(rest.slice(0, eq), line);
|
|
17153
17294
|
const [value, after] = readValue(rest.slice(eq + 1), line);
|
|
17154
|
-
assign(inlineAt(table2,
|
|
17295
|
+
assign(inlineAt(table2, path18.slice(0, -1), line), path18, value, line);
|
|
17155
17296
|
rest = after.replace(/^[ \t]+/, "");
|
|
17156
17297
|
if (rest.startsWith("}")) {
|
|
17157
17298
|
INLINE.add(table2);
|
|
@@ -17392,9 +17533,9 @@ function alternatives(raw) {
|
|
|
17392
17533
|
if (!parts2.length || parts2.includes("*")) return [];
|
|
17393
17534
|
return parts2;
|
|
17394
17535
|
}
|
|
17395
|
-
function hasPath(node,
|
|
17536
|
+
function hasPath(node, path18) {
|
|
17396
17537
|
let current = node;
|
|
17397
|
-
for (const part of
|
|
17538
|
+
for (const part of path18.split(".")) {
|
|
17398
17539
|
if (current && typeof current === "object" && !Array.isArray(current) && part in current) {
|
|
17399
17540
|
current = current[part];
|
|
17400
17541
|
continue;
|
|
@@ -17435,7 +17576,7 @@ function matches(m, event) {
|
|
|
17435
17576
|
if (m.args.length) {
|
|
17436
17577
|
const haystacks = event.event === "pre_request" || event.event === "post_response" ? [event.request?.query, event.request?.body] : [event.toolInput];
|
|
17437
17578
|
const present = haystacks.filter((h) => h !== void 0 && h !== null);
|
|
17438
|
-
if (!m.args.every((
|
|
17579
|
+
if (!m.args.every((path18) => present.some((h) => hasPath(h, path18))))
|
|
17439
17580
|
return false;
|
|
17440
17581
|
}
|
|
17441
17582
|
return true;
|
|
@@ -17879,9 +18020,9 @@ function vendorOf(config, toolName) {
|
|
|
17879
18020
|
return void 0;
|
|
17880
18021
|
}
|
|
17881
18022
|
function loadHookConfig(file) {
|
|
17882
|
-
if (!
|
|
18023
|
+
if (!fs15.existsSync(file) || !fs15.statSync(file).isFile())
|
|
17883
18024
|
throw new HookConfigError(`${file}: no such file`);
|
|
17884
|
-
const text2 =
|
|
18025
|
+
const text2 = fs15.readFileSync(file, "utf8");
|
|
17885
18026
|
if (file.toLowerCase().endsWith(".json")) {
|
|
17886
18027
|
let data2;
|
|
17887
18028
|
try {
|
|
@@ -18270,8 +18411,8 @@ function parseHandler(event, raw, position) {
|
|
|
18270
18411
|
|
|
18271
18412
|
// src/hooks/handlers.ts
|
|
18272
18413
|
var import_node_child_process5 = require("child_process");
|
|
18273
|
-
var
|
|
18274
|
-
var
|
|
18414
|
+
var fs16 = __toESM(require("fs"));
|
|
18415
|
+
var path15 = __toESM(require("path"));
|
|
18275
18416
|
var import_node_url = require("url");
|
|
18276
18417
|
function parseStdout(text2, handler) {
|
|
18277
18418
|
const stripped = text2.trim();
|
|
@@ -18472,8 +18613,8 @@ var RecordHandler = class {
|
|
|
18472
18613
|
record.source = this.opts.source ?? null;
|
|
18473
18614
|
if (Array.isArray(this.sink)) this.sink.push(record);
|
|
18474
18615
|
else if (typeof this.sink === "string") {
|
|
18475
|
-
|
|
18476
|
-
|
|
18616
|
+
fs16.mkdirSync(path15.dirname(this.sink), { recursive: true });
|
|
18617
|
+
fs16.appendFileSync(this.sink, JSON.stringify(record) + "\n");
|
|
18477
18618
|
} else await this.sink(record);
|
|
18478
18619
|
return allow();
|
|
18479
18620
|
}
|
|
@@ -18683,7 +18824,7 @@ async function importCallable(target, cwd) {
|
|
|
18683
18824
|
const hash = target.lastIndexOf("#");
|
|
18684
18825
|
const modulePath = target.slice(0, hash);
|
|
18685
18826
|
const exportName = target.slice(hash + 1) || "default";
|
|
18686
|
-
const resolved = modulePath.startsWith(".") ||
|
|
18827
|
+
const resolved = modulePath.startsWith(".") || path15.isAbsolute(modulePath) ? (0, import_node_url.pathToFileURL)(path15.resolve(cwd, modulePath)).href : modulePath;
|
|
18687
18828
|
let module2;
|
|
18688
18829
|
try {
|
|
18689
18830
|
module2 = await import(resolved);
|
|
@@ -18746,8 +18887,8 @@ async function buildHandler(spec, aliases, opts) {
|
|
|
18746
18887
|
}
|
|
18747
18888
|
|
|
18748
18889
|
// src/hooks/live.ts
|
|
18749
|
-
var
|
|
18750
|
-
var
|
|
18890
|
+
var fs17 = __toESM(require("fs"));
|
|
18891
|
+
var path16 = __toESM(require("path"));
|
|
18751
18892
|
|
|
18752
18893
|
// src/hooks/vendorAuth.ts
|
|
18753
18894
|
var bearer = (auth, value) => ({
|
|
@@ -19231,9 +19372,9 @@ var CallableTool = class _CallableTool {
|
|
|
19231
19372
|
}
|
|
19232
19373
|
};
|
|
19233
19374
|
function readConnection(root) {
|
|
19234
|
-
const file =
|
|
19235
|
-
if (!
|
|
19236
|
-
const raw = parseToml(
|
|
19375
|
+
const file = path16.join(root, "connector.toml");
|
|
19376
|
+
if (!fs17.existsSync(file)) throw new Error(`no connector.toml at ${root}`);
|
|
19377
|
+
const raw = parseToml(fs17.readFileSync(file, "utf8"));
|
|
19237
19378
|
const connector = raw.connector ?? {};
|
|
19238
19379
|
const auth = raw.auth ?? { scheme: "none" };
|
|
19239
19380
|
const carrier = vendorAuth(auth);
|
|
@@ -19248,7 +19389,7 @@ function readConnection(root) {
|
|
|
19248
19389
|
};
|
|
19249
19390
|
}
|
|
19250
19391
|
return {
|
|
19251
|
-
slug: typeof connector.slug === "string" ? connector.slug :
|
|
19392
|
+
slug: typeof connector.slug === "string" ? connector.slug : path16.basename(root),
|
|
19252
19393
|
baseUrl: (typeof connector.base_url === "string" ? connector.base_url : "").replace(/\/+$/, ""),
|
|
19253
19394
|
scheme: carrier.scheme,
|
|
19254
19395
|
carrier,
|
|
@@ -19265,8 +19406,8 @@ var ConnectorTool = class {
|
|
|
19265
19406
|
this.spec = spec;
|
|
19266
19407
|
this.live = live;
|
|
19267
19408
|
let location = spec.options.connector;
|
|
19268
|
-
if (!
|
|
19269
|
-
const root =
|
|
19409
|
+
if (!path16.isAbsolute(location)) location = path16.resolve(baseDir, location);
|
|
19410
|
+
const root = fs17.existsSync(location) && fs17.statSync(location).isFile() ? path16.dirname(location) : location;
|
|
19270
19411
|
try {
|
|
19271
19412
|
this.connection = readConnection(root);
|
|
19272
19413
|
} catch (error) {
|
|
@@ -19419,16 +19560,16 @@ var Recorder = class {
|
|
|
19419
19560
|
}
|
|
19420
19561
|
file;
|
|
19421
19562
|
write(line) {
|
|
19422
|
-
|
|
19423
|
-
|
|
19563
|
+
fs17.mkdirSync(path16.dirname(this.file), { recursive: true });
|
|
19564
|
+
fs17.appendFileSync(this.file, canonical2(line) + "\n");
|
|
19424
19565
|
}
|
|
19425
19566
|
};
|
|
19426
19567
|
var Replay = class {
|
|
19427
19568
|
constructor(file) {
|
|
19428
19569
|
this.file = file;
|
|
19429
|
-
if (!
|
|
19570
|
+
if (!fs17.existsSync(file))
|
|
19430
19571
|
throw new LiveToolError(`replay: no recording at ${file}`);
|
|
19431
|
-
|
|
19572
|
+
fs17.readFileSync(file, "utf8").split(/\r?\n/).forEach((raw, index2) => {
|
|
19432
19573
|
if (!raw.trim()) return;
|
|
19433
19574
|
let line;
|
|
19434
19575
|
try {
|
|
@@ -19515,7 +19656,7 @@ var LiveTools = class _LiveTools {
|
|
|
19515
19656
|
...config.live.record ? { record: interpolatePath(config.live.record, run.runId, directory) } : {},
|
|
19516
19657
|
...config.live.replay ? { replay: interpolatePath(config.live.replay, run.runId, directory) } : {}
|
|
19517
19658
|
};
|
|
19518
|
-
return _LiveTools.create(run, live,
|
|
19659
|
+
return _LiveTools.create(run, live, path16.dirname(path16.resolve(file)));
|
|
19519
19660
|
}
|
|
19520
19661
|
/** The declared tools for a model. `openai`: `{type: "function", function: {name,
|
|
19521
19662
|
* description, parameters}}`; `anthropic`: `{name, description, input_schema}`. */
|
|
@@ -19841,8 +19982,8 @@ var RedactionAudit = class _RedactionAudit {
|
|
|
19841
19982
|
|
|
19842
19983
|
// src/hooks/run.ts
|
|
19843
19984
|
var import_node_crypto15 = require("crypto");
|
|
19844
|
-
var
|
|
19845
|
-
var
|
|
19985
|
+
var fs18 = __toESM(require("fs"));
|
|
19986
|
+
var path17 = __toESM(require("path"));
|
|
19846
19987
|
var BLOCKING_EVENTS = [
|
|
19847
19988
|
"pre_tool_call",
|
|
19848
19989
|
"pre_request",
|
|
@@ -19893,12 +20034,12 @@ var HookRun = class _HookRun {
|
|
|
19893
20034
|
declaredOnly: options.declaredOnly ?? config.aliasDeclaredOnly
|
|
19894
20035
|
});
|
|
19895
20036
|
this.cwd = options.cwd ?? process.cwd();
|
|
19896
|
-
this.runDir = options.runDir ??
|
|
20037
|
+
this.runDir = options.runDir ?? path17.join(this.cwd, "runs", this.runId);
|
|
19897
20038
|
const chosen = options.legend !== void 0 ? options.legend : config.aliasLegend;
|
|
19898
|
-
this.legendPath = chosen ?
|
|
20039
|
+
this.legendPath = chosen ? path17.resolve(this.cwd, interpolatePath(chosen, this.runId, this.runDir)) : null;
|
|
19899
20040
|
this.sessionId = options.session;
|
|
19900
20041
|
this.source = options.source;
|
|
19901
|
-
this.configDir = config.source ?
|
|
20042
|
+
this.configDir = config.source ? path17.dirname(path17.resolve(config.source)) : this.cwd;
|
|
19902
20043
|
}
|
|
19903
20044
|
/** Build from a parsed config (an object in the file's shape, or a `HookConfig`);
|
|
19904
20045
|
* handlers are constructed now, so a callable that does not import fails here. */
|
|
@@ -20308,8 +20449,8 @@ var HookRun = class _HookRun {
|
|
|
20308
20449
|
throw new Error(
|
|
20309
20450
|
"no legend path: set [alias] legend, pass legend to the run, or give a path"
|
|
20310
20451
|
);
|
|
20311
|
-
|
|
20312
|
-
|
|
20452
|
+
fs18.mkdirSync(path17.dirname(target), { recursive: true });
|
|
20453
|
+
fs18.writeFileSync(target, JSON.stringify(this.legend(), null, 2) + "\n");
|
|
20313
20454
|
return target;
|
|
20314
20455
|
}
|
|
20315
20456
|
writeLegendIfConfigured() {
|
|
@@ -20405,14 +20546,14 @@ var HookedSession = class {
|
|
|
20405
20546
|
* `apiHeaders()`), `pre_request` before it and `post_response` after. Returns
|
|
20406
20547
|
* `{status, body, headers}`; a 4xx/5xx is returned, not thrown, so the agent sees
|
|
20407
20548
|
* the vendor's own error shape (rewritten like any result). */
|
|
20408
|
-
async request(method,
|
|
20549
|
+
async request(method, path18, opts = {}) {
|
|
20409
20550
|
if (!this.inner.api && !this.requestFn)
|
|
20410
20551
|
throw new Error(
|
|
20411
20552
|
"this session has no api surface (pass requestFn for a transport of your own)"
|
|
20412
20553
|
);
|
|
20413
20554
|
let request = {
|
|
20414
20555
|
method: method.toUpperCase(),
|
|
20415
|
-
path:
|
|
20556
|
+
path: path18,
|
|
20416
20557
|
query: { ...opts.query ?? {} },
|
|
20417
20558
|
body: opts.body ?? null
|
|
20418
20559
|
};
|