@withgateway/sdk 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1798 -1713
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +2412 -2327
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.js +47 -31
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +43 -27
- package/dist/files/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +390 -287
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +375 -271
- package/dist/index.mjs.map +1 -1
- package/dist/traces/index.js +36 -20
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +32 -16
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.js +2 -1
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +2 -1
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/worlds/index.d.mts +26 -22
- package/dist/worlds/index.d.ts +26 -22
- package/dist/worlds/index.js +307 -203
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +297 -193
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +2 -1
- package/runtime/gatewaysdk/environment/_bundle.py +14 -24
- package/runtime/gatewaysdk/environment/schema/api.py +37 -18
- package/runtime/gatewaysdk/environment/schema/data.py +21 -19
- package/runtime/gatewaysdk/environment/schema/grading.py +225 -0
- package/runtime/gatewaysdk/environment/schema/host.py +156 -546
- package/runtime/gatewaysdk/environment/schema/ingest.py +3 -11
- package/runtime/gatewaysdk/environment/schema/local.py +32 -126
- package/runtime/gatewaysdk/environment/schema/platform.py +14 -22
- package/runtime/gatewaysdk/environment/schema/proof.py +237 -0
- package/runtime/gatewaysdk/environment/schema/runtime.py +686 -0
- package/runtime/gatewaysdk/environment/schema/skill.py +1 -0
- package/runtime/gatewaysdk/environment/schema/skills/hooks-getting-started/SKILL.md +6 -4
- package/runtime/gatewaysdk/environment/schema/tools_world.py +75 -23
- package/runtime/gatewaysdk/environment/schema/verbs.py +136 -0
- package/runtime/gatewaysdk/environment/schema/workers.py +14 -0
- package/runtime/gatewaysdk/environment/world.py +391 -0
- package/skills/hooks-getting-started/SKILL.md +6 -4
package/dist/index.mjs
CHANGED
|
@@ -181,10 +181,10 @@ var init_users = __esm({
|
|
|
181
181
|
totalItems: Number(meta.totalItems ?? rows.length)
|
|
182
182
|
};
|
|
183
183
|
}
|
|
184
|
-
async requestJson(method,
|
|
184
|
+
async requestJson(method, path14, payload) {
|
|
185
185
|
let response;
|
|
186
186
|
try {
|
|
187
|
-
response = await fetch(`${this.host}${
|
|
187
|
+
response = await fetch(`${this.host}${path14}`, {
|
|
188
188
|
method,
|
|
189
189
|
headers: {
|
|
190
190
|
Authorization: this.authHeader(),
|
|
@@ -195,17 +195,17 @@ var init_users = __esm({
|
|
|
195
195
|
});
|
|
196
196
|
} catch (error) {
|
|
197
197
|
throw new UserProfileError(
|
|
198
|
-
`${method} ${
|
|
198
|
+
`${method} ${path14} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
199
199
|
{ cause: error }
|
|
200
200
|
);
|
|
201
201
|
}
|
|
202
202
|
const text2 = await response.text();
|
|
203
203
|
if (!response.ok) {
|
|
204
204
|
throw new UserProfileError(
|
|
205
|
-
`${method} ${
|
|
205
|
+
`${method} ${path14} failed (${response.status}): ${text2.slice(0, 500)}`
|
|
206
206
|
);
|
|
207
207
|
}
|
|
208
|
-
this.log("%s %s -> %s", method,
|
|
208
|
+
this.log("%s %s -> %s", method, path14, response.status);
|
|
209
209
|
return safeJson4(text2);
|
|
210
210
|
}
|
|
211
211
|
authHeader() {
|
|
@@ -394,10 +394,10 @@ var init_scores = __esm({
|
|
|
394
394
|
metadata: signalMetadata
|
|
395
395
|
});
|
|
396
396
|
}
|
|
397
|
-
async request(method,
|
|
397
|
+
async request(method, path14, payload) {
|
|
398
398
|
let response;
|
|
399
399
|
try {
|
|
400
|
-
response = await fetch(`${this.host}${
|
|
400
|
+
response = await fetch(`${this.host}${path14}`, {
|
|
401
401
|
method,
|
|
402
402
|
headers: {
|
|
403
403
|
Authorization: this.authHeader(),
|
|
@@ -408,17 +408,17 @@ var init_scores = __esm({
|
|
|
408
408
|
});
|
|
409
409
|
} catch (error) {
|
|
410
410
|
throw new ScoreError(
|
|
411
|
-
`${method} ${
|
|
411
|
+
`${method} ${path14} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
412
412
|
{ cause: error }
|
|
413
413
|
);
|
|
414
414
|
}
|
|
415
415
|
const text2 = await response.text();
|
|
416
416
|
if (!response.ok) {
|
|
417
417
|
throw new ScoreError(
|
|
418
|
-
`${method} ${
|
|
418
|
+
`${method} ${path14} failed (${response.status}): ${text2.slice(0, 500)}`
|
|
419
419
|
);
|
|
420
420
|
}
|
|
421
|
-
this.log("%s %s -> %s", method,
|
|
421
|
+
this.log("%s %s -> %s", method, path14, response.status);
|
|
422
422
|
}
|
|
423
423
|
authHeader() {
|
|
424
424
|
return `Basic ${Buffer.from(`${this.publicKey}:${this.secretKey}`).toString(
|
|
@@ -449,9 +449,9 @@ function surfaceKinds(s) {
|
|
|
449
449
|
if (s.browser) kinds.push("browser");
|
|
450
450
|
return kinds;
|
|
451
451
|
}
|
|
452
|
-
function uiUrl(ui,
|
|
452
|
+
function uiUrl(ui, path14) {
|
|
453
453
|
const base = ui.url.replace(/\/+$/, "");
|
|
454
|
-
const rel =
|
|
454
|
+
const rel = path14.startsWith("/") ? path14 : `/${path14}`;
|
|
455
455
|
if (!ui.token) return base + rel;
|
|
456
456
|
const [beforeHash, hash] = splitHash(rel);
|
|
457
457
|
const joiner = beforeHash.includes("?") ? "&" : "?";
|
|
@@ -1009,12 +1009,13 @@ async function openSession(slugOrRef, taskOrOpts, positionalOpts = {}) {
|
|
|
1009
1009
|
);
|
|
1010
1010
|
const at = slugOrRef.indexOf("@");
|
|
1011
1011
|
const slug = at === -1 ? slugOrRef : slugOrRef.slice(0, at);
|
|
1012
|
+
const ref = at === -1 ? "" : slugOrRef.slice(at + 1);
|
|
1012
1013
|
const state2 = await apiRequest(
|
|
1013
1014
|
options,
|
|
1014
1015
|
"POST",
|
|
1015
1016
|
"/api/public/world-sessions",
|
|
1016
1017
|
{
|
|
1017
|
-
...opts.versionId ? { versionId: opts.versionId } : { slug },
|
|
1018
|
+
...opts.versionId ? { versionId: opts.versionId } : { slug, ...ref && { ref } },
|
|
1018
1019
|
task,
|
|
1019
1020
|
...opts.reuseWarm === void 0 ? {} : { reuseWarm: opts.reuseWarm },
|
|
1020
1021
|
...opts.surfaces?.length ? { surfaces: opts.surfaces } : {}
|
|
@@ -1212,18 +1213,18 @@ var init_session = __esm({
|
|
|
1212
1213
|
}
|
|
1213
1214
|
/** The reporter `browser()` uses; exposed for a page you drive yourself. */
|
|
1214
1215
|
browserRecorder(agentId) {
|
|
1215
|
-
const
|
|
1216
|
+
const path14 = `/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/browser-events`;
|
|
1216
1217
|
const id = agentId ?? process.env.GATEWAY_AGENT_ID ?? `agent-${randomUUID().replace(/-/g, "").slice(0, 8)}`;
|
|
1217
1218
|
return new BrowserActionRecorder(
|
|
1218
1219
|
async (events) => {
|
|
1219
|
-
await apiRequest(this.options, "POST",
|
|
1220
|
+
await apiRequest(this.options, "POST", path14, { events });
|
|
1220
1221
|
},
|
|
1221
1222
|
id,
|
|
1222
1223
|
{
|
|
1223
1224
|
// Continue this agent's timeline where the platform has it, so the
|
|
1224
1225
|
// same id reopened later never re-numbers from zero.
|
|
1225
1226
|
resumeFrom: async () => {
|
|
1226
|
-
const summary = await apiRequest(this.options, "GET",
|
|
1227
|
+
const summary = await apiRequest(this.options, "GET", path14);
|
|
1227
1228
|
return summary.agents.find((a) => a.agentId === id)?.nextSeq ?? 0;
|
|
1228
1229
|
}
|
|
1229
1230
|
}
|
|
@@ -1986,7 +1987,7 @@ var require_package = __commonJS({
|
|
|
1986
1987
|
"package.json"(exports, module) {
|
|
1987
1988
|
module.exports = {
|
|
1988
1989
|
name: "@withgateway/sdk",
|
|
1989
|
-
version: "0.2.
|
|
1990
|
+
version: "0.2.5",
|
|
1990
1991
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
1991
1992
|
main: "./dist/index.js",
|
|
1992
1993
|
module: "./dist/index.mjs",
|
|
@@ -2090,6 +2091,7 @@ var require_package = __commonJS({
|
|
|
2090
2091
|
"typecheck:examples": "tsc -p tsconfig.examples.json --noEmit",
|
|
2091
2092
|
test: "vitest",
|
|
2092
2093
|
"test:run": "vitest run",
|
|
2094
|
+
"test:integration": "vitest run --config vitest.integration.config.ts",
|
|
2093
2095
|
lint: "eslint src --ext .ts",
|
|
2094
2096
|
clean: "rm -rf dist",
|
|
2095
2097
|
example: "tsx examples/test-ab-experiment.ts",
|
|
@@ -3034,6 +3036,152 @@ var init_taskRun = __esm({
|
|
|
3034
3036
|
}
|
|
3035
3037
|
});
|
|
3036
3038
|
|
|
3039
|
+
// src/worlds/worldDir.ts
|
|
3040
|
+
import { createHash as createHash3 } from "crypto";
|
|
3041
|
+
import * as fs2 from "fs";
|
|
3042
|
+
import * as path2 from "path";
|
|
3043
|
+
var WORLD_MANIFEST, API_BUNDLE_MANIFEST, BUNDLED_WORLD_PREFIX, CONNECTOR_SPEC, PYPROJECT, WORLD_SCHEMA_MARKERS, WORLD_ROOT_MARKERS, BROAD_ROOT_MARKERS, SKIPPED_DIRS, V1_DEP, V1_IMPORT, V1_TASKSET, HARBOR_TASK, skippedDir, byCodePoint, WorldDir;
|
|
3044
|
+
var init_worldDir = __esm({
|
|
3045
|
+
"src/worlds/worldDir.ts"() {
|
|
3046
|
+
"use strict";
|
|
3047
|
+
WORLD_MANIFEST = "gateway-env.toml";
|
|
3048
|
+
API_BUNDLE_MANIFEST = "gateway-api-world.toml";
|
|
3049
|
+
BUNDLED_WORLD_PREFIX = "server/world/";
|
|
3050
|
+
CONNECTOR_SPEC = "connector.toml";
|
|
3051
|
+
PYPROJECT = "pyproject.toml";
|
|
3052
|
+
WORLD_SCHEMA_MARKERS = ["schema/world.json", "schema/runtime.json", "schema/lock.json"];
|
|
3053
|
+
WORLD_ROOT_MARKERS = [CONNECTOR_SPEC, ...WORLD_SCHEMA_MARKERS];
|
|
3054
|
+
BROAD_ROOT_MARKERS = [WORLD_MANIFEST, API_BUNDLE_MANIFEST];
|
|
3055
|
+
SKIPPED_DIRS = /* @__PURE__ */ new Set(["dist", "build", "outputs", "__pycache__"]);
|
|
3056
|
+
V1_DEP = /["']verifiers\s*(?:\[[^\]]*\])?\s*(?:>=|~=|==|>)\s*(?:0\.(?:[2-9]\d*|[1-9]\d+)|[1-9]\d*)/;
|
|
3057
|
+
V1_IMPORT = /^\s*(?:from\s+verifiers\.v1\s+import\b|from\s+verifiers\s+import\s+v1\b|import\s+verifiers\.v1\b)/m;
|
|
3058
|
+
V1_TASKSET = /class\s+\w+\s*\(\s*(?:(?:vf|v1|verifiers(?:\.v1)?)\.)?Taskset\s*[,)]/;
|
|
3059
|
+
HARBOR_TASK = /^(?:tasks\/)?([^/]+)\/task\.toml$/;
|
|
3060
|
+
skippedDir = (name) => name.startsWith(".") || SKIPPED_DIRS.has(name) || name.endsWith(".egg-info");
|
|
3061
|
+
byCodePoint = (a, b) => Buffer.compare(Buffer.from(a, "utf-8"), Buffer.from(b, "utf-8"));
|
|
3062
|
+
WorldDir = class _WorldDir {
|
|
3063
|
+
constructor(dir, worldRoot) {
|
|
3064
|
+
this.dir = dir;
|
|
3065
|
+
this.worldRoot = worldRoot;
|
|
3066
|
+
}
|
|
3067
|
+
pathsMemo;
|
|
3068
|
+
static open(dir) {
|
|
3069
|
+
const present = (rel) => fs2.existsSync(path2.join(dir, rel));
|
|
3070
|
+
const bundled = present(API_BUNDLE_MANIFEST) && WORLD_ROOT_MARKERS.some((m) => present(BUNDLED_WORLD_PREFIX + m));
|
|
3071
|
+
return new _WorldDir(dir, bundled ? BUNDLED_WORLD_PREFIX : "");
|
|
3072
|
+
}
|
|
3073
|
+
// ── Files ──────────────────────────────────────────────────────────────
|
|
3074
|
+
has(rel) {
|
|
3075
|
+
return fs2.existsSync(path2.join(this.dir, rel));
|
|
3076
|
+
}
|
|
3077
|
+
text(rel) {
|
|
3078
|
+
try {
|
|
3079
|
+
return fs2.readFileSync(path2.join(this.dir, rel), "utf-8");
|
|
3080
|
+
} catch {
|
|
3081
|
+
return null;
|
|
3082
|
+
}
|
|
3083
|
+
}
|
|
3084
|
+
/** A path under the authored world's root. */
|
|
3085
|
+
worldPath(rel) {
|
|
3086
|
+
return this.worldRoot + rel;
|
|
3087
|
+
}
|
|
3088
|
+
/** Every regular file the archive rules keep (`_archive.py`: no hidden,
|
|
3089
|
+
* dist, build, outputs, pycache or egg-info directories), as sorted
|
|
3090
|
+
* relpaths. Root files enter only when a Gateway manifest widens the root
|
|
3091
|
+
* or they are README.md, pyproject.toml or Python. */
|
|
3092
|
+
get archivePaths() {
|
|
3093
|
+
if (this.pathsMemo) return this.pathsMemo;
|
|
3094
|
+
const broad = BROAD_ROOT_MARKERS.some((m) => this.has(m));
|
|
3095
|
+
const out = [];
|
|
3096
|
+
const walk = (rel) => {
|
|
3097
|
+
for (const entry of fs2.readdirSync(rel ? path2.join(this.dir, rel) : this.dir, { withFileTypes: true })) {
|
|
3098
|
+
const child = rel ? `${rel}/${entry.name}` : entry.name;
|
|
3099
|
+
if (entry.isDirectory()) {
|
|
3100
|
+
if (!skippedDir(entry.name)) walk(child);
|
|
3101
|
+
} else if (entry.isFile() && !entry.name.startsWith(".")) {
|
|
3102
|
+
const rootKept = broad || ["README.md", PYPROJECT].includes(entry.name) || entry.name.endsWith(".py");
|
|
3103
|
+
if (rel || rootKept) out.push(child);
|
|
3104
|
+
}
|
|
3105
|
+
}
|
|
3106
|
+
};
|
|
3107
|
+
walk("");
|
|
3108
|
+
return this.pathsMemo = out.sort(byCodePoint);
|
|
3109
|
+
}
|
|
3110
|
+
/** A root `.gitignore` is present: the Python SDK honours it when
|
|
3111
|
+
* collecting, this package does not reimplement gitignore. */
|
|
3112
|
+
get hasRootGitignore() {
|
|
3113
|
+
return this.has(".gitignore");
|
|
3114
|
+
}
|
|
3115
|
+
/** SHA-256 over `utf8("file:" + relpath)` + bytes per archive path in
|
|
3116
|
+
* sorted order: the version's identity, byte-compatible with
|
|
3117
|
+
* `_archive.compute_content_hash` and Prime Intellect. */
|
|
3118
|
+
get contentHash() {
|
|
3119
|
+
const hasher = createHash3("sha256");
|
|
3120
|
+
for (const rel of this.archivePaths) {
|
|
3121
|
+
hasher.update(Buffer.from(`file:${rel}`, "utf-8"));
|
|
3122
|
+
hasher.update(fs2.readFileSync(path2.join(this.dir, rel)));
|
|
3123
|
+
}
|
|
3124
|
+
return hasher.digest("hex");
|
|
3125
|
+
}
|
|
3126
|
+
// ── Markers ────────────────────────────────────────────────────────────
|
|
3127
|
+
get isApiBundle() {
|
|
3128
|
+
return this.has(API_BUNDLE_MANIFEST);
|
|
3129
|
+
}
|
|
3130
|
+
get hasManifest() {
|
|
3131
|
+
return this.has(this.worldPath(WORLD_MANIFEST));
|
|
3132
|
+
}
|
|
3133
|
+
get hasSchemaMarker() {
|
|
3134
|
+
return WORLD_SCHEMA_MARKERS.some((m) => this.has(this.worldPath(m)));
|
|
3135
|
+
}
|
|
3136
|
+
/** Harbor task dirs, relative to the tree: `tasks/<name>` when a `tasks/`
|
|
3137
|
+
* dir holds them, else the root `<name>` dirs. */
|
|
3138
|
+
taskDirs() {
|
|
3139
|
+
const names = /* @__PURE__ */ new Set();
|
|
3140
|
+
for (const rel of this.archivePaths) {
|
|
3141
|
+
const m = HARBOR_TASK.exec(rel);
|
|
3142
|
+
if (m) names.add(rel.startsWith("tasks/") ? `tasks/${m[1]}` : m[1]);
|
|
3143
|
+
}
|
|
3144
|
+
const under = [...names].filter((n) => n.startsWith("tasks/"));
|
|
3145
|
+
return (under.length ? under : [...names]).sort();
|
|
3146
|
+
}
|
|
3147
|
+
/** The Python package of a verifiers tree (`<pkg>/__init__.py` or
|
|
3148
|
+
* `src/<pkg>/__init__.py`), or null. */
|
|
3149
|
+
pythonPackage() {
|
|
3150
|
+
if (!this.has(PYPROJECT)) return null;
|
|
3151
|
+
for (const base of ["", "src/"]) {
|
|
3152
|
+
const init3 = this.archivePaths.find((rel) => {
|
|
3153
|
+
const m = /^([^/]+)\/__init__\.py$/.exec(rel.startsWith(base) ? rel.slice(base.length) : "");
|
|
3154
|
+
return m !== null && m[1] !== "tests";
|
|
3155
|
+
});
|
|
3156
|
+
if (init3) return { name: init3.slice(base.length).split("/")[0], init: init3 };
|
|
3157
|
+
}
|
|
3158
|
+
return null;
|
|
3159
|
+
}
|
|
3160
|
+
/** The package targets the `verifiers.v1` API: read from the root
|
|
3161
|
+
* pyproject and every archived Python module. */
|
|
3162
|
+
get isVerifiersV1() {
|
|
3163
|
+
for (const rel of this.archivePaths) {
|
|
3164
|
+
if (rel !== PYPROJECT && !rel.endsWith(".py")) continue;
|
|
3165
|
+
const text2 = this.text(rel);
|
|
3166
|
+
if (text2 === null) continue;
|
|
3167
|
+
if (rel === PYPROJECT ? V1_DEP.test(text2) : V1_IMPORT.test(text2) || text2.includes("__all__") && V1_TASKSET.test(text2))
|
|
3168
|
+
return true;
|
|
3169
|
+
}
|
|
3170
|
+
return false;
|
|
3171
|
+
}
|
|
3172
|
+
// ── The answer ─────────────────────────────────────────────────────────
|
|
3173
|
+
/** The runner's kind (`detect_env_kind`): api / mock-tools win over
|
|
3174
|
+
* everything, a harbor task tree next, then the verifiers API version. */
|
|
3175
|
+
get kind() {
|
|
3176
|
+
if (this.isApiBundle) return "api";
|
|
3177
|
+
if (this.has(WORLD_MANIFEST)) return "mock-tools";
|
|
3178
|
+
if (this.taskDirs().length) return "harbor";
|
|
3179
|
+
return this.isVerifiersV1 ? "verifiers-v1" : "verifiers";
|
|
3180
|
+
}
|
|
3181
|
+
};
|
|
3182
|
+
}
|
|
3183
|
+
});
|
|
3184
|
+
|
|
3037
3185
|
// src/worlds/hub.ts
|
|
3038
3186
|
var hub_exports = {};
|
|
3039
3187
|
__export(hub_exports, {
|
|
@@ -3042,7 +3190,6 @@ __export(hub_exports, {
|
|
|
3042
3190
|
collectArchiveRelPaths: () => collectArchiveRelPaths,
|
|
3043
3191
|
computeContentHash: () => computeContentHash,
|
|
3044
3192
|
createRef: () => createRef,
|
|
3045
|
-
isIncludedInContentHash: () => isIncludedInContentHash,
|
|
3046
3193
|
localTreeState: () => localTreeState,
|
|
3047
3194
|
propose: () => propose,
|
|
3048
3195
|
pull: () => pull,
|
|
@@ -3052,57 +3199,22 @@ __export(hub_exports, {
|
|
|
3052
3199
|
snapshotTreeHashes: () => snapshotTreeHashes,
|
|
3053
3200
|
writeLocalMeta: () => writeLocalMeta
|
|
3054
3201
|
});
|
|
3055
|
-
import { createHash as
|
|
3202
|
+
import { createHash as createHash4 } from "crypto";
|
|
3056
3203
|
import { gzipSync, gunzipSync } from "zlib";
|
|
3057
|
-
import * as
|
|
3058
|
-
import * as
|
|
3059
|
-
function isExcludedDirComponent(component) {
|
|
3060
|
-
return component.startsWith(".") || ROOT_EXCLUDED_DIRS.has(component) || component.endsWith(".egg-info");
|
|
3061
|
-
}
|
|
3062
|
-
function isIncludedInContentHash(relPath, includeAllRootFiles) {
|
|
3063
|
-
const parts2 = relPath.split("/");
|
|
3064
|
-
const name = parts2[parts2.length - 1];
|
|
3065
|
-
const dirParts = parts2.slice(0, -1);
|
|
3066
|
-
if (name.startsWith(".")) return false;
|
|
3067
|
-
if (parts2.includes("__pycache__")) return false;
|
|
3068
|
-
if (dirParts.length === 0) {
|
|
3069
|
-
return includeAllRootFiles || name === "README.md" || name === "pyproject.toml" || BROAD_ROOT_MARKERS.includes(name) || name.endsWith(".py");
|
|
3070
|
-
}
|
|
3071
|
-
return !dirParts.some(isExcludedDirComponent);
|
|
3072
|
-
}
|
|
3204
|
+
import * as fs3 from "fs";
|
|
3205
|
+
import * as path3 from "path";
|
|
3073
3206
|
function collectArchiveRelPaths(dir) {
|
|
3074
|
-
|
|
3207
|
+
const world = WorldDir.open(dir);
|
|
3208
|
+
if (world.hasRootGitignore) {
|
|
3075
3209
|
throw new Error(
|
|
3076
3210
|
"This bundle has a root .gitignore, which the Python CLI honors via gitignore_parser. Reimplementing that imperfectly here would silently produce a different content hash, so the TS CLI refuses. Remove the .gitignore (or bake its effect into the tree) and retry."
|
|
3077
3211
|
);
|
|
3078
3212
|
}
|
|
3079
|
-
|
|
3080
|
-
const includeAllRootFiles = BROAD_ROOT_MARKERS.some(
|
|
3081
|
-
(marker) => fs2.existsSync(path2.join(dir, marker))
|
|
3082
|
-
);
|
|
3083
|
-
const walk = (rel) => {
|
|
3084
|
-
const abs = rel ? path2.join(dir, rel) : dir;
|
|
3085
|
-
for (const entry of fs2.readdirSync(abs, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
3086
|
-
const childRel = rel ? `${rel}/${entry.name}` : entry.name;
|
|
3087
|
-
if (entry.isDirectory()) {
|
|
3088
|
-
if (!isExcludedDirComponent(entry.name)) walk(childRel);
|
|
3089
|
-
} else if (entry.isFile()) {
|
|
3090
|
-
if (isIncludedInContentHash(childRel, includeAllRootFiles)) {
|
|
3091
|
-
out.push(childRel);
|
|
3092
|
-
}
|
|
3093
|
-
}
|
|
3094
|
-
}
|
|
3095
|
-
};
|
|
3096
|
-
walk("");
|
|
3097
|
-
return out.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
3213
|
+
return world.archivePaths;
|
|
3098
3214
|
}
|
|
3099
3215
|
function computeContentHash(dir) {
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
hasher.update(Buffer.from(`file:${relPath}`, "utf-8"));
|
|
3103
|
-
hasher.update(fs2.readFileSync(path2.join(dir, relPath)));
|
|
3104
|
-
}
|
|
3105
|
-
return hasher.digest("hex");
|
|
3216
|
+
collectArchiveRelPaths(dir);
|
|
3217
|
+
return WorldDir.open(dir).contentHash;
|
|
3106
3218
|
}
|
|
3107
3219
|
function octal(value, length) {
|
|
3108
3220
|
return Buffer.from(value.toString(8).padStart(length - 1, "0") + "\0", "ascii");
|
|
@@ -3150,14 +3262,14 @@ function tarMember(name, payload) {
|
|
|
3150
3262
|
function buildSourceTarball(dir) {
|
|
3151
3263
|
const parts2 = [];
|
|
3152
3264
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
3153
|
-
parts2.push(...tarMember(relPath,
|
|
3265
|
+
parts2.push(...tarMember(relPath, fs3.readFileSync(path3.join(dir, relPath))));
|
|
3154
3266
|
}
|
|
3155
3267
|
parts2.push(Buffer.alloc(1024));
|
|
3156
3268
|
return gzipSync(Buffer.concat(parts2), { level: 9 });
|
|
3157
3269
|
}
|
|
3158
3270
|
function readLocalMeta(dir) {
|
|
3159
3271
|
try {
|
|
3160
|
-
const raw =
|
|
3272
|
+
const raw = fs3.readFileSync(path3.join(dir, META_RELPATH), "utf-8");
|
|
3161
3273
|
const parsed = JSON.parse(raw);
|
|
3162
3274
|
return parsed && typeof parsed === "object" ? parsed : null;
|
|
3163
3275
|
} catch {
|
|
@@ -3168,16 +3280,16 @@ function pushSlug(dir, explicit) {
|
|
|
3168
3280
|
if (explicit) return explicit;
|
|
3169
3281
|
const meta = readLocalMeta(dir);
|
|
3170
3282
|
if (typeof meta?.slug === "string" && meta.slug) return meta.slug;
|
|
3171
|
-
return readPyproject(dir).name ??
|
|
3283
|
+
return readPyproject(dir).name ?? path3.basename(path3.resolve(dir));
|
|
3172
3284
|
}
|
|
3173
3285
|
function writeLocalMeta(dir, meta) {
|
|
3174
|
-
|
|
3175
|
-
|
|
3286
|
+
fs3.mkdirSync(path3.join(dir, ".gateway"), { recursive: true });
|
|
3287
|
+
fs3.writeFileSync(path3.join(dir, META_RELPATH), JSON.stringify(meta, null, 2));
|
|
3176
3288
|
}
|
|
3177
3289
|
function snapshotTreeHashes(dir) {
|
|
3178
3290
|
const out = {};
|
|
3179
3291
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
3180
|
-
out[relPath] =
|
|
3292
|
+
out[relPath] = createHash4("sha256").update(fs3.readFileSync(path3.join(dir, relPath))).digest("hex");
|
|
3181
3293
|
}
|
|
3182
3294
|
return out;
|
|
3183
3295
|
}
|
|
@@ -3195,7 +3307,7 @@ function localTreeState(dir) {
|
|
|
3195
3307
|
}
|
|
3196
3308
|
function readPyproject(dir) {
|
|
3197
3309
|
try {
|
|
3198
|
-
const text2 =
|
|
3310
|
+
const text2 = fs3.readFileSync(path3.join(dir, "pyproject.toml"), "utf-8");
|
|
3199
3311
|
const section = /\[project\]([\s\S]*?)(\n\[|$)/.exec(text2)?.[1] ?? "";
|
|
3200
3312
|
const name = /\bname\s*=\s*"([^"]+)"/.exec(section)?.[1];
|
|
3201
3313
|
const version = /\bversion\s*=\s*"([^"]+)"/.exec(section)?.[1];
|
|
@@ -3205,33 +3317,32 @@ function readPyproject(dir) {
|
|
|
3205
3317
|
}
|
|
3206
3318
|
}
|
|
3207
3319
|
function readWorldContractVersion(dir) {
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
}
|
|
3320
|
+
const world = WorldDir.open(dir);
|
|
3321
|
+
try {
|
|
3322
|
+
const parsed = JSON.parse(world.text(world.worldPath("schema/world.json")) ?? "");
|
|
3323
|
+
const pkg = parsed["x-gateway"]?.package;
|
|
3324
|
+
if (pkg?.version) return { name: pkg.id, version: pkg.version };
|
|
3325
|
+
} catch {
|
|
3215
3326
|
}
|
|
3216
3327
|
return {};
|
|
3217
3328
|
}
|
|
3218
3329
|
function buildFileManifest(dir) {
|
|
3219
3330
|
const entries = [];
|
|
3220
3331
|
const walk = (rel) => {
|
|
3221
|
-
const abs = rel ?
|
|
3222
|
-
for (const entry of
|
|
3332
|
+
const abs = rel ? path3.join(dir, rel) : dir;
|
|
3333
|
+
for (const entry of fs3.readdirSync(abs, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
3223
3334
|
const childRel = rel ? `${rel}/${entry.name}` : entry.name;
|
|
3224
3335
|
if (entry.isDirectory()) {
|
|
3225
3336
|
if (!SKIP_DIRS.has(entry.name) && !entry.name.endsWith(".egg-info")) {
|
|
3226
3337
|
walk(childRel);
|
|
3227
3338
|
}
|
|
3228
3339
|
} else if (entry.isFile()) {
|
|
3229
|
-
const payload =
|
|
3340
|
+
const payload = fs3.readFileSync(path3.join(dir, childRel));
|
|
3230
3341
|
entries.push({
|
|
3231
3342
|
path: childRel,
|
|
3232
3343
|
isDirectory: false,
|
|
3233
3344
|
size: payload.length,
|
|
3234
|
-
sha256:
|
|
3345
|
+
sha256: createHash4("sha256").update(payload).digest("hex")
|
|
3235
3346
|
});
|
|
3236
3347
|
}
|
|
3237
3348
|
}
|
|
@@ -3254,7 +3365,7 @@ async function putObject(url, data, shaB64) {
|
|
|
3254
3365
|
}
|
|
3255
3366
|
async function push(dir, opts = {}) {
|
|
3256
3367
|
const options = opts.options ?? {};
|
|
3257
|
-
if (!
|
|
3368
|
+
if (!fs3.statSync(dir).isDirectory()) throw new Error(`Not a directory: ${dir}`);
|
|
3258
3369
|
const localMeta = readLocalMeta(dir) ?? {};
|
|
3259
3370
|
const branch = opts.branch ?? localMeta.branch ?? DEFAULT_BRANCH;
|
|
3260
3371
|
const baseVersionId = opts.baseVersionId ?? localMeta.versionId ?? null;
|
|
@@ -3262,18 +3373,18 @@ async function push(dir, opts = {}) {
|
|
|
3262
3373
|
const pyproject = readPyproject(dir);
|
|
3263
3374
|
const contractVersion = pyproject.version ? void 0 : readWorldContractVersion(dir).version;
|
|
3264
3375
|
if (contractVersion) pyproject.version = contractVersion;
|
|
3265
|
-
const slug = opts.slug ?? localMeta.slug ?? pyproject.name ??
|
|
3376
|
+
const slug = opts.slug ?? localMeta.slug ?? pyproject.name ?? path3.basename(path3.resolve(dir));
|
|
3377
|
+
const metadata = {
|
|
3378
|
+
name: opts.name ?? pyproject.name ?? slug,
|
|
3379
|
+
...opts.description !== void 0 ? { description: opts.description } : {},
|
|
3380
|
+
...opts.tags !== void 0 ? { tags: opts.tags } : {},
|
|
3381
|
+
...opts.visibility ? { visibility: opts.visibility } : {}
|
|
3382
|
+
};
|
|
3266
3383
|
const resolve10 = await apiRequest(
|
|
3267
3384
|
options,
|
|
3268
3385
|
"POST",
|
|
3269
3386
|
"/api/public/benchmark-containers/resolve",
|
|
3270
|
-
{
|
|
3271
|
-
slug,
|
|
3272
|
-
name: opts.name ?? pyproject.name ?? slug,
|
|
3273
|
-
...opts.description ? { description: opts.description } : {},
|
|
3274
|
-
...opts.tags?.length ? { tags: opts.tags } : {},
|
|
3275
|
-
...opts.visibility ? { visibility: opts.visibility } : {}
|
|
3276
|
-
}
|
|
3387
|
+
{ slug, ...metadata }
|
|
3277
3388
|
);
|
|
3278
3389
|
const tarball = buildSourceTarball(dir);
|
|
3279
3390
|
const bundleSha256 = sha256b64(tarball);
|
|
@@ -3297,7 +3408,7 @@ async function push(dir, opts = {}) {
|
|
|
3297
3408
|
options,
|
|
3298
3409
|
"POST",
|
|
3299
3410
|
`/api/public/benchmark-containers/versions/${version.versionId}/finalize`,
|
|
3300
|
-
{ branch, baseVersionId, ...opts.force ? { force: true } : {} }
|
|
3411
|
+
{ branch, baseVersionId, ...opts.force ? { force: true } : {}, ...metadata }
|
|
3301
3412
|
);
|
|
3302
3413
|
writeLocalMeta(dir, {
|
|
3303
3414
|
...localMeta,
|
|
@@ -3342,9 +3453,9 @@ function extractBundle(bundle, dir) {
|
|
|
3342
3453
|
longName = null;
|
|
3343
3454
|
if (typeflag !== "0" && typeflag !== "") continue;
|
|
3344
3455
|
if (name.startsWith("/") || name.split("/").includes("..")) continue;
|
|
3345
|
-
const target =
|
|
3346
|
-
|
|
3347
|
-
|
|
3456
|
+
const target = path3.join(dir, name);
|
|
3457
|
+
fs3.mkdirSync(path3.dirname(target), { recursive: true });
|
|
3458
|
+
fs3.writeFileSync(target, body);
|
|
3348
3459
|
written++;
|
|
3349
3460
|
}
|
|
3350
3461
|
return written;
|
|
@@ -3360,13 +3471,13 @@ async function pull(slugRef, target, options = {}) {
|
|
|
3360
3471
|
if (!details.downloadUrl) {
|
|
3361
3472
|
throw new Error(`${slug}@${ref} resolved but has no uploaded bundle`);
|
|
3362
3473
|
}
|
|
3363
|
-
let dir = target ??
|
|
3474
|
+
let dir = target ?? path3.join(process.cwd(), slug);
|
|
3364
3475
|
if (!target) {
|
|
3365
3476
|
let i = 1;
|
|
3366
3477
|
const base = dir;
|
|
3367
|
-
while (
|
|
3478
|
+
while (fs3.existsSync(dir)) dir = `${base}-${i++}`;
|
|
3368
3479
|
}
|
|
3369
|
-
|
|
3480
|
+
fs3.mkdirSync(dir, { recursive: true });
|
|
3370
3481
|
const resp = await fetch(details.downloadUrl);
|
|
3371
3482
|
if (!resp.ok) throw new Error(`bundle download -> ${resp.status}`);
|
|
3372
3483
|
const bundle = Buffer.from(await resp.arrayBuffer());
|
|
@@ -3396,12 +3507,12 @@ async function propose(dir, opts) {
|
|
|
3396
3507
|
const state2 = localTreeState(dir);
|
|
3397
3508
|
if (state2.clean) throw new Error("Nothing to propose \u2014 the tree matches its base.");
|
|
3398
3509
|
const changes = state2.dirty.map((relPath) => {
|
|
3399
|
-
const abs =
|
|
3400
|
-
if (!
|
|
3510
|
+
const abs = path3.join(dir, relPath);
|
|
3511
|
+
if (!fs3.existsSync(abs)) return { path: relPath, action: "delete" };
|
|
3401
3512
|
return {
|
|
3402
3513
|
path: relPath,
|
|
3403
3514
|
action: "write",
|
|
3404
|
-
newContent:
|
|
3515
|
+
newContent: fs3.readFileSync(abs, "utf-8")
|
|
3405
3516
|
};
|
|
3406
3517
|
});
|
|
3407
3518
|
const res = await apiRequest(
|
|
@@ -3427,13 +3538,14 @@ async function createRef(slug, name, kind, versionId, options = {}) {
|
|
|
3427
3538
|
...versionId ? { versionId } : {}
|
|
3428
3539
|
});
|
|
3429
3540
|
}
|
|
3430
|
-
var DEFAULT_BRANCH, META_RELPATH, SKIP_DIRS,
|
|
3541
|
+
var DEFAULT_BRANCH, META_RELPATH, SKIP_DIRS, sha256b64;
|
|
3431
3542
|
var init_hub = __esm({
|
|
3432
3543
|
"src/worlds/hub.ts"() {
|
|
3433
3544
|
"use strict";
|
|
3434
3545
|
init_worlds();
|
|
3546
|
+
init_worldDir();
|
|
3435
3547
|
DEFAULT_BRANCH = "main";
|
|
3436
|
-
META_RELPATH =
|
|
3548
|
+
META_RELPATH = path3.join(".gateway", ".env-metadata.json");
|
|
3437
3549
|
SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
3438
3550
|
".git",
|
|
3439
3551
|
"__pycache__",
|
|
@@ -3444,9 +3556,7 @@ var init_hub = __esm({
|
|
|
3444
3556
|
"build",
|
|
3445
3557
|
"outputs"
|
|
3446
3558
|
]);
|
|
3447
|
-
|
|
3448
|
-
BROAD_ROOT_MARKERS = ["gateway-env.toml", "gateway-api-world.toml"];
|
|
3449
|
-
sha256b64 = (data) => createHash3("sha256").update(data).digest("base64");
|
|
3559
|
+
sha256b64 = (data) => createHash4("sha256").update(data).digest("base64");
|
|
3450
3560
|
}
|
|
3451
3561
|
});
|
|
3452
3562
|
|
|
@@ -3945,7 +4055,7 @@ var init_json = __esm({
|
|
|
3945
4055
|
});
|
|
3946
4056
|
|
|
3947
4057
|
// src/worlds/transforms.ts
|
|
3948
|
-
import { createHash as
|
|
4058
|
+
import { createHash as createHash5 } from "crypto";
|
|
3949
4059
|
function parseTransform(name) {
|
|
3950
4060
|
const simple = Object.prototype.hasOwnProperty.call(SIMPLE, name) ? SIMPLE[name] : void 0;
|
|
3951
4061
|
if (simple) return simple;
|
|
@@ -3969,8 +4079,8 @@ var init_transforms = __esm({
|
|
|
3969
4079
|
"use strict";
|
|
3970
4080
|
init_json();
|
|
3971
4081
|
WHITESPACE = " \n\r\f\v";
|
|
3972
|
-
WHITESPACE_EDGES =
|
|
3973
|
-
WHITESPACE_RUN =
|
|
4082
|
+
WHITESPACE_EDGES = new RegExp(`^[${WHITESPACE}]+|[${WHITESPACE}]+$`, "g");
|
|
4083
|
+
WHITESPACE_RUN = new RegExp(`[${WHITESPACE}]+`, "g");
|
|
3974
4084
|
NOT_DIGIT = /[^0-9]/g;
|
|
3975
4085
|
STRIP_PREFIX = "strip_prefix";
|
|
3976
4086
|
trim = (value) => value.replace(WHITESPACE_EDGES, "");
|
|
@@ -3983,7 +4093,7 @@ var init_transforms = __esm({
|
|
|
3983
4093
|
return at === -1 ? "" : value.slice(at + 1).toLowerCase();
|
|
3984
4094
|
};
|
|
3985
4095
|
stripPrefix = (prefix) => (value) => value.startsWith(prefix) ? value.slice(prefix.length) : value;
|
|
3986
|
-
hex = (algorithm, value) =>
|
|
4096
|
+
hex = (algorithm, value) => createHash5(algorithm).update(value, "utf8").digest("hex");
|
|
3987
4097
|
SIMPLE = {
|
|
3988
4098
|
lower: (value) => value.toLowerCase(),
|
|
3989
4099
|
upper: (value) => value.toUpperCase(),
|
|
@@ -4007,7 +4117,7 @@ var init_transforms = __esm({
|
|
|
4007
4117
|
});
|
|
4008
4118
|
|
|
4009
4119
|
// src/worlds/redaction.ts
|
|
4010
|
-
import { createHash as
|
|
4120
|
+
import { createHash as createHash6 } from "crypto";
|
|
4011
4121
|
function pyText(value) {
|
|
4012
4122
|
if (typeof value === "string") return value;
|
|
4013
4123
|
if (Number.isInteger(value)) return String(value);
|
|
@@ -4016,7 +4126,7 @@ function pyText(value) {
|
|
|
4016
4126
|
return pyFloatRepr(value);
|
|
4017
4127
|
}
|
|
4018
4128
|
function hashForm(slug, plaintext) {
|
|
4019
|
-
return "sha256:" +
|
|
4129
|
+
return "sha256:" + createHash6("sha256").update(`${slug}:${pyText(plaintext)}`, "utf8").digest("hex");
|
|
4020
4130
|
}
|
|
4021
4131
|
function preserveForm(slug, plaintext) {
|
|
4022
4132
|
const kind = typeof plaintext === "string" ? "str" : isInt(plaintext) ? "int" : "float";
|
|
@@ -4025,12 +4135,12 @@ function preserveForm(slug, plaintext) {
|
|
|
4025
4135
|
}
|
|
4026
4136
|
function shapeText(slug, text2, kind) {
|
|
4027
4137
|
const seed = Buffer.from(`${slug}:${text2}`, "utf8");
|
|
4028
|
-
let digest =
|
|
4138
|
+
let digest = createHash6("sha256").update(seed).digest();
|
|
4029
4139
|
let cursor = 0;
|
|
4030
4140
|
const out = [];
|
|
4031
4141
|
for (const char of text2) {
|
|
4032
4142
|
if (cursor === digest.length) {
|
|
4033
|
-
digest =
|
|
4143
|
+
digest = createHash6("sha256").update(Buffer.concat([digest, seed])).digest();
|
|
4034
4144
|
cursor = 0;
|
|
4035
4145
|
}
|
|
4036
4146
|
const byte = digest[cursor];
|
|
@@ -4078,8 +4188,9 @@ var init_redaction = __esm({
|
|
|
4078
4188
|
});
|
|
4079
4189
|
|
|
4080
4190
|
// src/worlds/query.ts
|
|
4081
|
-
function queryRowsSearch(entity, opts = {}) {
|
|
4191
|
+
function queryRowsSearch(entity, opts = {}, ref) {
|
|
4082
4192
|
const search = new URLSearchParams();
|
|
4193
|
+
if (ref) search.set("ref", ref);
|
|
4083
4194
|
search.set("entity", entity);
|
|
4084
4195
|
if (opts.where && Object.keys(opts.where).length) search.set("where", JSON.stringify(opts.where));
|
|
4085
4196
|
if (opts.limit !== void 0) search.set("limit", String(opts.limit));
|
|
@@ -4089,17 +4200,15 @@ function queryRowsSearch(entity, opts = {}) {
|
|
|
4089
4200
|
if (opts.compare) search.set("compare", "true");
|
|
4090
4201
|
return `?${search.toString()}`;
|
|
4091
4202
|
}
|
|
4092
|
-
async function queryRows(
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
`queryRows reads a world's head version: pass the slug without @ref (got ${slug})`
|
|
4096
|
-
);
|
|
4203
|
+
async function queryRows(slugRef, entity, opts = {}, options = {}) {
|
|
4204
|
+
const [slug, ref] = slugRef.split("@", 2);
|
|
4205
|
+
if (!slug || ref === "") throw new Error(`queryRows needs a slug, optionally slug@ref (got ${slugRef})`);
|
|
4097
4206
|
if (!entity) throw new Error("queryRows needs an entity");
|
|
4098
4207
|
if (opts.compare && !opts.across) throw new Error("queryRows: compare needs across");
|
|
4099
4208
|
return apiRequest(
|
|
4100
4209
|
options,
|
|
4101
4210
|
"GET",
|
|
4102
|
-
`/api/public/worlds/${encodeURIComponent(slug)}/data${queryRowsSearch(entity, opts)}`
|
|
4211
|
+
`/api/public/worlds/${encodeURIComponent(slug)}/data${queryRowsSearch(entity, opts, ref)}`
|
|
4103
4212
|
);
|
|
4104
4213
|
}
|
|
4105
4214
|
var init_query = __esm({
|
|
@@ -4155,9 +4264,9 @@ var init_router = __esm({
|
|
|
4155
4264
|
});
|
|
4156
4265
|
|
|
4157
4266
|
// src/cli/config.ts
|
|
4158
|
-
import * as
|
|
4267
|
+
import * as fs4 from "fs";
|
|
4159
4268
|
import * as os from "os";
|
|
4160
|
-
import * as
|
|
4269
|
+
import * as path4 from "path";
|
|
4161
4270
|
async function api(creds, method, route, body, init3 = {}) {
|
|
4162
4271
|
const controller = new AbortController();
|
|
4163
4272
|
const timer = setTimeout(() => controller.abort(), init3.timeoutMs ?? 12e4);
|
|
@@ -4198,9 +4307,9 @@ var init_config = __esm({
|
|
|
4198
4307
|
|
|
4199
4308
|
// src/cli/runtime/local.ts
|
|
4200
4309
|
import { spawn, spawnSync } from "child_process";
|
|
4201
|
-
import * as
|
|
4310
|
+
import * as fs5 from "fs";
|
|
4202
4311
|
import * as net from "net";
|
|
4203
|
-
import * as
|
|
4312
|
+
import * as path5 from "path";
|
|
4204
4313
|
function tailOf(output) {
|
|
4205
4314
|
return output.length > DIAGNOSTIC_TAIL ? `\u2026${output.slice(-DIAGNOSTIC_TAIL)}` : output;
|
|
4206
4315
|
}
|
|
@@ -4215,16 +4324,16 @@ function runtimeRoot() {
|
|
|
4215
4324
|
const candidates = [];
|
|
4216
4325
|
if (process.env.GATEWAY_RUNTIME_PATH)
|
|
4217
4326
|
candidates.push(process.env.GATEWAY_RUNTIME_PATH);
|
|
4218
|
-
const entry = process.argv[1] &&
|
|
4327
|
+
const entry = process.argv[1] && fs5.existsSync(process.argv[1]) ? path5.dirname(fs5.realpathSync(process.argv[1])) : null;
|
|
4219
4328
|
if (entry) {
|
|
4220
|
-
candidates.push(
|
|
4221
|
-
candidates.push(
|
|
4222
|
-
candidates.push(
|
|
4329
|
+
candidates.push(path5.resolve(entry, "..", "runtime"));
|
|
4330
|
+
candidates.push(path5.resolve(entry, "..", "..", "runtime"));
|
|
4331
|
+
candidates.push(path5.resolve(entry, "..", "..", "sdk", "src"));
|
|
4223
4332
|
}
|
|
4224
|
-
candidates.push(
|
|
4333
|
+
candidates.push(path5.resolve(process.cwd(), "runtime"));
|
|
4225
4334
|
for (const root of candidates)
|
|
4226
|
-
if (
|
|
4227
|
-
|
|
4335
|
+
if (fs5.existsSync(
|
|
4336
|
+
path5.join(root, "gatewaysdk", "environment", "schema", "platform.py")
|
|
4228
4337
|
))
|
|
4229
4338
|
return root;
|
|
4230
4339
|
return null;
|
|
@@ -4392,18 +4501,18 @@ runpy.run_module('gatewaysdk.environment.schema.platform',run_name='__main__')`;
|
|
|
4392
4501
|
});
|
|
4393
4502
|
|
|
4394
4503
|
// src/cli/runtime/client.ts
|
|
4395
|
-
import * as
|
|
4396
|
-
import * as
|
|
4504
|
+
import * as fs6 from "fs";
|
|
4505
|
+
import * as path6 from "path";
|
|
4397
4506
|
function isBuildOutput(relPath) {
|
|
4398
4507
|
return BUILD_OUTPUT.test(relPath);
|
|
4399
4508
|
}
|
|
4400
4509
|
function readWorldFiles(dir, opts = {}) {
|
|
4401
|
-
if (!
|
|
4510
|
+
if (!fs6.existsSync(dir) || !fs6.statSync(dir).isDirectory())
|
|
4402
4511
|
throw new CliError(`Not a directory: ${dir}`);
|
|
4403
4512
|
const out = [];
|
|
4404
4513
|
const walk = (rel) => {
|
|
4405
|
-
const abs = rel ?
|
|
4406
|
-
const entries =
|
|
4514
|
+
const abs = rel ? path6.join(dir, rel) : dir;
|
|
4515
|
+
const entries = fs6.readdirSync(abs, { withFileTypes: true });
|
|
4407
4516
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
4408
4517
|
for (const entry of entries) {
|
|
4409
4518
|
const childRel = rel ? `${rel}/${entry.name}` : entry.name;
|
|
@@ -4413,7 +4522,7 @@ function readWorldFiles(dir, opts = {}) {
|
|
|
4413
4522
|
if (!opts.buildOutputs && isBuildOutput(childRel)) continue;
|
|
4414
4523
|
out.push({
|
|
4415
4524
|
path: childRel,
|
|
4416
|
-
content:
|
|
4525
|
+
content: fs6.readFileSync(path6.join(dir, childRel)).toString("base64")
|
|
4417
4526
|
});
|
|
4418
4527
|
}
|
|
4419
4528
|
}
|
|
@@ -4428,19 +4537,19 @@ function assertSafeRelPath(rel) {
|
|
|
4428
4537
|
}
|
|
4429
4538
|
function writeWorldFiles(dir, files, opts = {}) {
|
|
4430
4539
|
for (const file of files) assertSafeRelPath(file.path);
|
|
4431
|
-
if (opts.clean &&
|
|
4540
|
+
if (opts.clean && fs6.existsSync(dir)) {
|
|
4432
4541
|
const keep = new Set(files.map((f) => f.path));
|
|
4433
4542
|
for (const existing of readWorldFiles(dir)) {
|
|
4434
|
-
if (!keep.has(existing.path))
|
|
4543
|
+
if (!keep.has(existing.path)) fs6.rmSync(path6.join(dir, existing.path));
|
|
4435
4544
|
}
|
|
4436
4545
|
pruneEmptyDirs(dir);
|
|
4437
4546
|
}
|
|
4438
|
-
|
|
4547
|
+
fs6.mkdirSync(dir, { recursive: true });
|
|
4439
4548
|
const written = [];
|
|
4440
4549
|
for (const file of files) {
|
|
4441
|
-
const target =
|
|
4442
|
-
|
|
4443
|
-
|
|
4550
|
+
const target = path6.join(dir, file.path);
|
|
4551
|
+
fs6.mkdirSync(path6.dirname(target), { recursive: true });
|
|
4552
|
+
fs6.writeFileSync(target, Buffer.from(file.content, "base64"));
|
|
4444
4553
|
written.push(file.path);
|
|
4445
4554
|
}
|
|
4446
4555
|
return written;
|
|
@@ -4448,14 +4557,14 @@ function writeWorldFiles(dir, files, opts = {}) {
|
|
|
4448
4557
|
function pruneEmptyDirs(root) {
|
|
4449
4558
|
const walk = (abs) => {
|
|
4450
4559
|
let empty = true;
|
|
4451
|
-
for (const entry of
|
|
4452
|
-
const child =
|
|
4560
|
+
for (const entry of fs6.readdirSync(abs, { withFileTypes: true })) {
|
|
4561
|
+
const child = path6.join(abs, entry.name);
|
|
4453
4562
|
if (entry.isDirectory()) {
|
|
4454
4563
|
if (SKIP_DIRS2.has(entry.name)) {
|
|
4455
4564
|
empty = false;
|
|
4456
4565
|
continue;
|
|
4457
4566
|
}
|
|
4458
|
-
if (walk(child))
|
|
4567
|
+
if (walk(child)) fs6.rmdirSync(child);
|
|
4459
4568
|
else empty = false;
|
|
4460
4569
|
} else empty = false;
|
|
4461
4570
|
}
|
|
@@ -4547,8 +4656,8 @@ __export(data_exports, {
|
|
|
4547
4656
|
queryLocalWorldDataAcross: () => queryLocalWorldDataAcross,
|
|
4548
4657
|
showLocalWorldData: () => showLocalWorldData
|
|
4549
4658
|
});
|
|
4550
|
-
import * as
|
|
4551
|
-
import * as
|
|
4659
|
+
import * as fs7 from "fs";
|
|
4660
|
+
import * as path7 from "path";
|
|
4552
4661
|
async function importLocalWorldData(dir, rows, opts, creds) {
|
|
4553
4662
|
const res = await runtime(creds, {
|
|
4554
4663
|
command: "import-data",
|
|
@@ -4574,7 +4683,7 @@ function dropBuildOutputs(dir) {
|
|
|
4574
4683
|
const dropped = [];
|
|
4575
4684
|
for (const file of readWorldFiles(dir, { buildOutputs: true })) {
|
|
4576
4685
|
if (!BUILD_OUTPUT2.test(file.path)) continue;
|
|
4577
|
-
|
|
4686
|
+
fs7.rmSync(path7.join(dir, file.path), { force: true });
|
|
4578
4687
|
dropped.push(file.path);
|
|
4579
4688
|
}
|
|
4580
4689
|
return dropped;
|
|
@@ -4585,6 +4694,7 @@ async function checkLocalWorldData(dir, rows, creds, opts = {}) {
|
|
|
4585
4694
|
files: readWorldFiles(dir),
|
|
4586
4695
|
rows,
|
|
4587
4696
|
mode: "append",
|
|
4697
|
+
dry_run: true,
|
|
4588
4698
|
...opts.redact && opts.redact !== "off" ? { redact: opts.redact } : {}
|
|
4589
4699
|
});
|
|
4590
4700
|
return {
|
|
@@ -4640,7 +4750,7 @@ async function queryLocalWorldDataAcross(dir, entity, where, opts) {
|
|
|
4640
4750
|
const payload = await localBridge(
|
|
4641
4751
|
{
|
|
4642
4752
|
command: "query",
|
|
4643
|
-
world:
|
|
4753
|
+
world: path7.resolve(dir),
|
|
4644
4754
|
entity,
|
|
4645
4755
|
across: true,
|
|
4646
4756
|
...opts.compare ? { compare: true } : {},
|
|
@@ -4711,9 +4821,9 @@ __export(transform_exports, {
|
|
|
4711
4821
|
transformRecords: () => transformRecords
|
|
4712
4822
|
});
|
|
4713
4823
|
import { spawn as spawn2 } from "child_process";
|
|
4714
|
-
import * as
|
|
4824
|
+
import * as fs8 from "fs";
|
|
4715
4825
|
import * as os2 from "os";
|
|
4716
|
-
import * as
|
|
4826
|
+
import * as path8 from "path";
|
|
4717
4827
|
import { createRequire } from "module";
|
|
4718
4828
|
function checkRows(value, where) {
|
|
4719
4829
|
if (!isObject(value)) throw new CliError(`${where} must return {entity: [rows]}; got ${value === null ? "null" : Array.isArray(value) ? "an array" : typeof value}`, 1);
|
|
@@ -4738,27 +4848,27 @@ function typescriptPrefix() {
|
|
|
4738
4848
|
}
|
|
4739
4849
|
}
|
|
4740
4850
|
function command(script, wrapperDir) {
|
|
4741
|
-
const suffix =
|
|
4851
|
+
const suffix = path8.extname(script).toLowerCase();
|
|
4742
4852
|
if (PYTHON_SUFFIXES.includes(suffix)) return { file: process.env.GATEWAY_PYTHON || "python3", args: ["-c", PY_WRAPPER, script] };
|
|
4743
4853
|
if (NODE_SUFFIXES.includes(suffix)) {
|
|
4744
|
-
const wrapper =
|
|
4745
|
-
|
|
4854
|
+
const wrapper = path8.join(wrapperDir, "transform-wrapper.mjs");
|
|
4855
|
+
fs8.writeFileSync(wrapper, NODE_WRAPPER);
|
|
4746
4856
|
const flags = suffix === ".ts" || suffix === ".mts" ? typescriptPrefix() : [];
|
|
4747
4857
|
return { file: process.env.GATEWAY_NODE || process.execPath, args: [...flags, wrapper, script] };
|
|
4748
4858
|
}
|
|
4749
|
-
throw new CliError(`${
|
|
4859
|
+
throw new CliError(`${path8.basename(script)}: a transform script is .py, .ts, .mjs, .js or .cjs`, 1);
|
|
4750
4860
|
}
|
|
4751
4861
|
async function runTransform(script, records, opts = {}) {
|
|
4752
|
-
if (!
|
|
4753
|
-
const resolved =
|
|
4754
|
-
const name =
|
|
4862
|
+
if (!fs8.existsSync(script) || !fs8.statSync(script).isFile()) throw new CliError(`no transform script at ${script}`, 1);
|
|
4863
|
+
const resolved = path8.resolve(script);
|
|
4864
|
+
const name = path8.basename(script);
|
|
4755
4865
|
const timeoutMs = opts.timeoutMs ?? DEFAULT_TRANSFORM_TIMEOUT_MS;
|
|
4756
|
-
const scratch =
|
|
4866
|
+
const scratch = fs8.mkdtempSync(path8.join(os2.tmpdir(), "gateway-transform-"));
|
|
4757
4867
|
try {
|
|
4758
4868
|
const { file, args } = command(resolved, scratch);
|
|
4759
4869
|
const env = Object.fromEntries(Object.entries(process.env).filter(([key2]) => !SCRUBBED.test(key2)));
|
|
4760
4870
|
const done = await new Promise((resolve10, reject) => {
|
|
4761
|
-
const child = spawn2(file, args, { cwd:
|
|
4871
|
+
const child = spawn2(file, args, { cwd: path8.dirname(resolved), env, stdio: ["pipe", "pipe", "pipe"] });
|
|
4762
4872
|
let stdout = "";
|
|
4763
4873
|
let stderr = "";
|
|
4764
4874
|
let timedOut = false;
|
|
@@ -4789,7 +4899,7 @@ async function runTransform(script, records, opts = {}) {
|
|
|
4789
4899
|
}
|
|
4790
4900
|
return { rows: checkRows(value, name), stderr: done.stderr };
|
|
4791
4901
|
} finally {
|
|
4792
|
-
|
|
4902
|
+
fs8.rmSync(scratch, { recursive: true, force: true });
|
|
4793
4903
|
}
|
|
4794
4904
|
}
|
|
4795
4905
|
async function transformRecords(transform, records, opts = {}) {
|
|
@@ -4881,13 +4991,18 @@ if (fn) {
|
|
|
4881
4991
|
});
|
|
4882
4992
|
|
|
4883
4993
|
// src/cli/platform/worldData/batches.ts
|
|
4884
|
-
import { createHash as
|
|
4885
|
-
import * as
|
|
4994
|
+
import { createHash as createHash7 } from "crypto";
|
|
4995
|
+
import * as fs9 from "fs";
|
|
4996
|
+
function isSettled(status) {
|
|
4997
|
+
if (!TERMINAL_STATES.has(status.state)) return false;
|
|
4998
|
+
if (status.state !== "applied") return true;
|
|
4999
|
+
return status.dryRun === true || status.publish !== "now" || !status.snapshotId;
|
|
5000
|
+
}
|
|
4886
5001
|
function uploadHeadersFor(gz) {
|
|
4887
5002
|
return {
|
|
4888
5003
|
"content-type": "application/gzip",
|
|
4889
5004
|
"content-length": String(gz.length),
|
|
4890
|
-
"x-amz-checksum-sha256":
|
|
5005
|
+
"x-amz-checksum-sha256": createHash7("sha256").update(gz).digest("base64")
|
|
4891
5006
|
};
|
|
4892
5007
|
}
|
|
4893
5008
|
async function forEachLimited(items, limit, fn) {
|
|
@@ -4924,7 +5039,7 @@ async function waitForBatch(client2, batchId, opts = {}) {
|
|
|
4924
5039
|
opts.onPhase?.(phase);
|
|
4925
5040
|
last = phase;
|
|
4926
5041
|
}
|
|
4927
|
-
if (
|
|
5042
|
+
if (isSettled(status)) return status;
|
|
4928
5043
|
await sleep3(delay);
|
|
4929
5044
|
delay = Math.min(1e4, Math.round(delay * 1.5));
|
|
4930
5045
|
}
|
|
@@ -5014,7 +5129,7 @@ var init_batches = __esm({
|
|
|
5014
5129
|
});
|
|
5015
5130
|
|
|
5016
5131
|
// src/cli/platform/worldData/chunker.ts
|
|
5017
|
-
import { createHash as
|
|
5132
|
+
import { createHash as createHash8 } from "crypto";
|
|
5018
5133
|
import { deflateRawSync } from "zlib";
|
|
5019
5134
|
function chunkLine(row, declared) {
|
|
5020
5135
|
if (declared !== null) return dumps(row.row) + "\n";
|
|
@@ -5049,12 +5164,12 @@ function finishChunk(ordinal, raw, rows, entity, firstRow = 0) {
|
|
|
5049
5164
|
const gz = gzipDeterministic(raw, { name: chunkName(ordinal) });
|
|
5050
5165
|
return {
|
|
5051
5166
|
ordinal,
|
|
5052
|
-
digest:
|
|
5167
|
+
digest: createHash8("sha256").update(gz).digest("hex"),
|
|
5053
5168
|
bytes: gz.length,
|
|
5054
5169
|
rows,
|
|
5055
5170
|
entity,
|
|
5056
5171
|
rawBytes: raw.length,
|
|
5057
|
-
contentSha256:
|
|
5172
|
+
contentSha256: createHash8("sha256").update(raw).digest("hex"),
|
|
5058
5173
|
firstRow,
|
|
5059
5174
|
gz
|
|
5060
5175
|
};
|
|
@@ -5137,9 +5252,9 @@ var init_push = __esm({
|
|
|
5137
5252
|
});
|
|
5138
5253
|
|
|
5139
5254
|
// src/worlds/ingest.ts
|
|
5140
|
-
import * as
|
|
5255
|
+
import * as fs10 from "fs";
|
|
5141
5256
|
import * as os3 from "os";
|
|
5142
|
-
import * as
|
|
5257
|
+
import * as path9 from "path";
|
|
5143
5258
|
function parseToolCallRecord(raw) {
|
|
5144
5259
|
const none = { record: null, skip: null };
|
|
5145
5260
|
if (!isObject2(raw)) return { ...none, refusal: "record is not an object" };
|
|
@@ -5160,7 +5275,7 @@ function parseToolCallRecord(raw) {
|
|
|
5160
5275
|
}
|
|
5161
5276
|
function readToolCallRecords(paths) {
|
|
5162
5277
|
const records = [];
|
|
5163
|
-
for (const file of paths) records.push(...toolCallRecordsIn(
|
|
5278
|
+
for (const file of paths) records.push(...toolCallRecordsIn(fs10.readFileSync(file, "utf8"), file));
|
|
5164
5279
|
return records;
|
|
5165
5280
|
}
|
|
5166
5281
|
function toolCallRecordsIn(text2, where) {
|
|
@@ -5196,7 +5311,7 @@ async function emit(sink, record) {
|
|
|
5196
5311
|
return;
|
|
5197
5312
|
}
|
|
5198
5313
|
if (typeof sink === "string") {
|
|
5199
|
-
|
|
5314
|
+
fs10.appendFileSync(sink, JSON.stringify(record) + "\n");
|
|
5200
5315
|
return;
|
|
5201
5316
|
}
|
|
5202
5317
|
if (typeof sink === "function") {
|
|
@@ -5227,14 +5342,6 @@ function captureToolCalls(tools, sink, opts = {}) {
|
|
|
5227
5342
|
}
|
|
5228
5343
|
return wrapped;
|
|
5229
5344
|
}
|
|
5230
|
-
function jsonish(value) {
|
|
5231
|
-
if (typeof value !== "string") return value;
|
|
5232
|
-
try {
|
|
5233
|
-
return JSON.parse(value);
|
|
5234
|
-
} catch {
|
|
5235
|
-
return value;
|
|
5236
|
-
}
|
|
5237
|
-
}
|
|
5238
5345
|
function toolCallsFromObservations(observations, opts = {}) {
|
|
5239
5346
|
const known = opts.tools ? new Set(opts.tools) : null;
|
|
5240
5347
|
const sinceMs = opts.since ? Date.parse(opts.since) : NaN;
|
|
@@ -5261,10 +5368,9 @@ function toolCallsFromObservations(observations, opts = {}) {
|
|
|
5261
5368
|
out.unknownTools[tool] = (out.unknownTools[tool] ?? 0) + 1;
|
|
5262
5369
|
continue;
|
|
5263
5370
|
}
|
|
5264
|
-
const
|
|
5265
|
-
const record = { tool, args: isObject2(input) ? input : {} };
|
|
5371
|
+
const record = { tool, args: isObject2(observation.input) ? observation.input : {} };
|
|
5266
5372
|
if (observation.level === "ERROR") record.error = observation.statusMessage || "ERROR";
|
|
5267
|
-
else record.result =
|
|
5373
|
+
else record.result = observation.output;
|
|
5268
5374
|
if (at !== void 0) record.at = at;
|
|
5269
5375
|
if (opts.session) record.session = opts.session;
|
|
5270
5376
|
record.source = `trace:${observation.traceId ?? "?"}/${observation.id ?? "?"}`;
|
|
@@ -5285,7 +5391,7 @@ async function ingest(world, records, options = {}) {
|
|
|
5285
5391
|
const mode = options.mode ?? "append";
|
|
5286
5392
|
const dryRun = Boolean(options.dryRun);
|
|
5287
5393
|
const creds = credentialsOf(options);
|
|
5288
|
-
const local =
|
|
5394
|
+
const local = fs10.existsSync(world) && fs10.statSync(world).isDirectory();
|
|
5289
5395
|
const map = options.map === void 0 ? void 0 : options.map;
|
|
5290
5396
|
let rows = null;
|
|
5291
5397
|
let stderr = "";
|
|
@@ -5301,9 +5407,9 @@ async function ingest(world, records, options = {}) {
|
|
|
5301
5407
|
if (!creds) throw new Error("Gateway keys missing: set GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY (or pass publicKey/secretKey).");
|
|
5302
5408
|
const { pull: pull2 } = await Promise.resolve().then(() => (init_hub(), hub_exports));
|
|
5303
5409
|
const slug = world.split("@", 1)[0];
|
|
5304
|
-
const scratch =
|
|
5410
|
+
const scratch = fs10.mkdtempSync(path9.join(os3.tmpdir(), "gateway-ingest-"));
|
|
5305
5411
|
try {
|
|
5306
|
-
const pulled = await pull2(world,
|
|
5412
|
+
const pulled = await pull2(world, path9.join(scratch, slug), options);
|
|
5307
5413
|
let report;
|
|
5308
5414
|
let projected;
|
|
5309
5415
|
if (rows === null) {
|
|
@@ -5324,7 +5430,7 @@ async function ingest(world, records, options = {}) {
|
|
|
5324
5430
|
if (status.entityCounts) report.entityCounts = status.entityCounts;
|
|
5325
5431
|
return report;
|
|
5326
5432
|
} finally {
|
|
5327
|
-
|
|
5433
|
+
fs10.rmSync(scratch, { recursive: true, force: true });
|
|
5328
5434
|
}
|
|
5329
5435
|
}
|
|
5330
5436
|
async function ingestToolCalls(world, records, options = {}) {
|
|
@@ -5434,7 +5540,6 @@ __export(worlds_exports, {
|
|
|
5434
5540
|
hashForm: () => hashForm,
|
|
5435
5541
|
ingest: () => ingest,
|
|
5436
5542
|
ingestToolCalls: () => ingestToolCalls,
|
|
5437
|
-
isIncludedInContentHash: () => isIncludedInContentHash,
|
|
5438
5543
|
isTaskIdRef: () => isTaskIdRef,
|
|
5439
5544
|
isTaskManifest: () => isTaskManifest,
|
|
5440
5545
|
isTaskSpec: () => isTaskSpec,
|
|
@@ -5500,9 +5605,9 @@ function resolveEnv(options) {
|
|
|
5500
5605
|
}
|
|
5501
5606
|
return { host: host.replace(/\/+$/, ""), publicKey, secretKey };
|
|
5502
5607
|
}
|
|
5503
|
-
async function apiRequest(options, method,
|
|
5608
|
+
async function apiRequest(options, method, path14, body) {
|
|
5504
5609
|
const { host, publicKey, secretKey } = resolveEnv(options);
|
|
5505
|
-
const res = await fetch(`${host}${
|
|
5610
|
+
const res = await fetch(`${host}${path14}`, {
|
|
5506
5611
|
method,
|
|
5507
5612
|
headers: {
|
|
5508
5613
|
"content-type": "application/json",
|
|
@@ -5511,7 +5616,7 @@ async function apiRequest(options, method, path13, body) {
|
|
|
5511
5616
|
...body === void 0 ? {} : { body: JSON.stringify(body) }
|
|
5512
5617
|
});
|
|
5513
5618
|
const text2 = await res.text();
|
|
5514
|
-
if (!res.ok) throw new ApiError2(res.status, method,
|
|
5619
|
+
if (!res.ok) throw new ApiError2(res.status, method, path14, text2.slice(0, 400));
|
|
5515
5620
|
return JSON.parse(text2);
|
|
5516
5621
|
}
|
|
5517
5622
|
async function setEnvSecret(slug, key2, value, options = {}) {
|
|
@@ -5682,8 +5787,8 @@ var init_worlds = __esm({
|
|
|
5682
5787
|
init_migrate();
|
|
5683
5788
|
init_ingest();
|
|
5684
5789
|
ApiError2 = class extends Error {
|
|
5685
|
-
constructor(status, method,
|
|
5686
|
-
super(`${method} ${
|
|
5790
|
+
constructor(status, method, path14, body) {
|
|
5791
|
+
super(`${method} ${path14} -> ${status}: ${body}`);
|
|
5687
5792
|
this.status = status;
|
|
5688
5793
|
this.name = "ApiError";
|
|
5689
5794
|
}
|
|
@@ -6323,8 +6428,8 @@ var GatewayContext = class _GatewayContext {
|
|
|
6323
6428
|
}
|
|
6324
6429
|
return resolved;
|
|
6325
6430
|
}
|
|
6326
|
-
async requestJson(method,
|
|
6327
|
-
const response = await fetch(`${this.host}${
|
|
6431
|
+
async requestJson(method, path14, payload) {
|
|
6432
|
+
const response = await fetch(`${this.host}${path14}`, {
|
|
6328
6433
|
method,
|
|
6329
6434
|
headers: {
|
|
6330
6435
|
Authorization: this.authHeader(),
|
|
@@ -6335,7 +6440,7 @@ var GatewayContext = class _GatewayContext {
|
|
|
6335
6440
|
const text2 = await response.text();
|
|
6336
6441
|
const body = text2 ? safeJson(text2) : {};
|
|
6337
6442
|
if (!response.ok) {
|
|
6338
|
-
const message = typeof body.message === "string" ? body.message : `Gateway API ${response.status} on ${
|
|
6443
|
+
const message = typeof body.message === "string" ? body.message : `Gateway API ${response.status} on ${path14}`;
|
|
6339
6444
|
if (response.status === 409) {
|
|
6340
6445
|
throw new GatewayContextConflictError(
|
|
6341
6446
|
message,
|
|
@@ -6344,7 +6449,7 @@ var GatewayContext = class _GatewayContext {
|
|
|
6344
6449
|
}
|
|
6345
6450
|
throw new GatewayContextError(message);
|
|
6346
6451
|
}
|
|
6347
|
-
this.log("%s %s -> %s", method,
|
|
6452
|
+
this.log("%s %s -> %s", method, path14, response.status);
|
|
6348
6453
|
return body;
|
|
6349
6454
|
}
|
|
6350
6455
|
authHeader() {
|
|
@@ -6451,11 +6556,11 @@ function primaryPathForKind(kind, snapshot) {
|
|
|
6451
6556
|
const preferred = kind === "agent" ? "AGENTS.md" : kind === "prompt" ? "PROMPT.md" : kind === "skill" ? "SKILL.md" : "MEMORY.md";
|
|
6452
6557
|
if (readFile(snapshot, preferred)) return preferred;
|
|
6453
6558
|
return Object.entries(snapshot.files).find(
|
|
6454
|
-
([
|
|
6559
|
+
([path14, entry]) => entry.type === "file" && path14.endsWith(".md")
|
|
6455
6560
|
)?.[0] ?? null;
|
|
6456
6561
|
}
|
|
6457
|
-
function parseJsonFile(snapshot,
|
|
6458
|
-
const content = readFile(snapshot,
|
|
6562
|
+
function parseJsonFile(snapshot, path14) {
|
|
6563
|
+
const content = readFile(snapshot, path14);
|
|
6459
6564
|
if (!content) return {};
|
|
6460
6565
|
try {
|
|
6461
6566
|
const parsed = JSON.parse(content);
|
|
@@ -6464,8 +6569,8 @@ function parseJsonFile(snapshot, path13) {
|
|
|
6464
6569
|
return {};
|
|
6465
6570
|
}
|
|
6466
6571
|
}
|
|
6467
|
-
function readFile(snapshot,
|
|
6468
|
-
const entry = snapshot.files[
|
|
6572
|
+
function readFile(snapshot, path14) {
|
|
6573
|
+
const entry = snapshot.files[path14];
|
|
6469
6574
|
return entry?.type === "file" ? entry.content : null;
|
|
6470
6575
|
}
|
|
6471
6576
|
function provenanceFor(snapshot, label) {
|
|
@@ -6567,16 +6672,16 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
6567
6672
|
`/api/public/context/memory/${encodeIdentifier2(identifier)}${suffix}`
|
|
6568
6673
|
);
|
|
6569
6674
|
}
|
|
6570
|
-
async read(target,
|
|
6675
|
+
async read(target, path14, options = {}) {
|
|
6571
6676
|
const snapshot = typeof target === "string" ? await this.pull(target, options) : target;
|
|
6572
|
-
const file = snapshot.files[
|
|
6677
|
+
const file = snapshot.files[path14];
|
|
6573
6678
|
return file?.type === "file" ? file.content : null;
|
|
6574
6679
|
}
|
|
6575
|
-
async write(target,
|
|
6680
|
+
async write(target, path14, content, options = {}) {
|
|
6576
6681
|
const snapshot = typeof target === "string" ? await this.pull(target) : target;
|
|
6577
6682
|
return this.push(snapshot.repo.repoHandle, {
|
|
6578
6683
|
files: {
|
|
6579
|
-
[
|
|
6684
|
+
[path14]: {
|
|
6580
6685
|
content,
|
|
6581
6686
|
...options.mimeType ? { mimeType: options.mimeType } : {}
|
|
6582
6687
|
}
|
|
@@ -6586,10 +6691,10 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
6586
6691
|
...runtimeContextPayload2(options)
|
|
6587
6692
|
});
|
|
6588
6693
|
}
|
|
6589
|
-
async delete(target,
|
|
6694
|
+
async delete(target, path14, options = {}) {
|
|
6590
6695
|
const snapshot = typeof target === "string" ? await this.pull(target) : target;
|
|
6591
6696
|
return this.push(snapshot.repo.repoHandle, {
|
|
6592
|
-
files: { [
|
|
6697
|
+
files: { [path14]: null },
|
|
6593
6698
|
parentCommit: options.parentCommit ?? snapshot.commit.commitHash,
|
|
6594
6699
|
message: options.message,
|
|
6595
6700
|
...runtimeContextPayload2(options)
|
|
@@ -6602,8 +6707,8 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
6602
6707
|
payload
|
|
6603
6708
|
);
|
|
6604
6709
|
}
|
|
6605
|
-
async requestJson(method,
|
|
6606
|
-
const response = await fetch(`${this.host}${
|
|
6710
|
+
async requestJson(method, path14, payload) {
|
|
6711
|
+
const response = await fetch(`${this.host}${path14}`, {
|
|
6607
6712
|
method,
|
|
6608
6713
|
headers: {
|
|
6609
6714
|
Authorization: this.authHeader(),
|
|
@@ -6614,7 +6719,7 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
6614
6719
|
const text2 = await response.text();
|
|
6615
6720
|
const body = text2 ? safeJson2(text2) : {};
|
|
6616
6721
|
if (!response.ok) {
|
|
6617
|
-
const message = typeof body.message === "string" ? body.message : `Gateway API ${response.status} on ${
|
|
6722
|
+
const message = typeof body.message === "string" ? body.message : `Gateway API ${response.status} on ${path14}`;
|
|
6618
6723
|
if (response.status === 409) {
|
|
6619
6724
|
throw new GatewayMemoryConflictError(
|
|
6620
6725
|
message,
|
|
@@ -6623,7 +6728,7 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
6623
6728
|
}
|
|
6624
6729
|
throw new GatewayMemoryError(message);
|
|
6625
6730
|
}
|
|
6626
|
-
this.log("%s %s -> %s", method,
|
|
6731
|
+
this.log("%s %s -> %s", method, path14, response.status);
|
|
6627
6732
|
return body;
|
|
6628
6733
|
}
|
|
6629
6734
|
authHeader() {
|
|
@@ -6785,10 +6890,10 @@ var PersonasClient = class _PersonasClient {
|
|
|
6785
6890
|
done: Boolean(payload.done)
|
|
6786
6891
|
};
|
|
6787
6892
|
}
|
|
6788
|
-
async requestJson(method,
|
|
6893
|
+
async requestJson(method, path14, payload) {
|
|
6789
6894
|
let response;
|
|
6790
6895
|
try {
|
|
6791
|
-
response = await fetch(`${this.host}${
|
|
6896
|
+
response = await fetch(`${this.host}${path14}`, {
|
|
6792
6897
|
method,
|
|
6793
6898
|
headers: {
|
|
6794
6899
|
Authorization: this.authHeader(),
|
|
@@ -6799,7 +6904,7 @@ var PersonasClient = class _PersonasClient {
|
|
|
6799
6904
|
});
|
|
6800
6905
|
} catch (error) {
|
|
6801
6906
|
const reason = error instanceof Error ? error.message : String(error);
|
|
6802
|
-
throw new PersonaError(`${method} ${
|
|
6907
|
+
throw new PersonaError(`${method} ${path14} failed: ${reason}`, {
|
|
6803
6908
|
cause: error
|
|
6804
6909
|
});
|
|
6805
6910
|
}
|
|
@@ -6807,10 +6912,10 @@ var PersonasClient = class _PersonasClient {
|
|
|
6807
6912
|
if (!response.ok) {
|
|
6808
6913
|
const detail = text2.slice(0, 500);
|
|
6809
6914
|
throw new PersonaError(
|
|
6810
|
-
`${method} ${
|
|
6915
|
+
`${method} ${path14} failed (${response.status}): ${detail}`
|
|
6811
6916
|
);
|
|
6812
6917
|
}
|
|
6813
|
-
this.log("%s %s -> %s", method,
|
|
6918
|
+
this.log("%s %s -> %s", method, path14, response.status);
|
|
6814
6919
|
return safeJson3(text2);
|
|
6815
6920
|
}
|
|
6816
6921
|
authHeader() {
|
|
@@ -7035,10 +7140,10 @@ var SessionRecording = class _SessionRecording {
|
|
|
7035
7140
|
};
|
|
7036
7141
|
}
|
|
7037
7142
|
/** Dump the full session as a JSON fixture (for regression tests). */
|
|
7038
|
-
toFixture(
|
|
7039
|
-
mkdirSync(dirname(
|
|
7040
|
-
writeFileSync(
|
|
7041
|
-
return
|
|
7143
|
+
toFixture(path14) {
|
|
7144
|
+
mkdirSync(dirname(path14), { recursive: true });
|
|
7145
|
+
writeFileSync(path14, JSON.stringify(this.toJSON(), null, 2), "utf-8");
|
|
7146
|
+
return path14;
|
|
7042
7147
|
}
|
|
7043
7148
|
static fromApi(raw) {
|
|
7044
7149
|
return new _SessionRecording({
|
|
@@ -8069,8 +8174,8 @@ var GatewaySecurity = class _GatewaySecurity {
|
|
|
8069
8174
|
);
|
|
8070
8175
|
}
|
|
8071
8176
|
}
|
|
8072
|
-
async postJson(
|
|
8073
|
-
const response = await fetch(`${this.host}${
|
|
8177
|
+
async postJson(path14, payload) {
|
|
8178
|
+
const response = await fetch(`${this.host}${path14}`, {
|
|
8074
8179
|
method: "POST",
|
|
8075
8180
|
headers: {
|
|
8076
8181
|
Authorization: this.authHeader(),
|
|
@@ -8081,7 +8186,7 @@ var GatewaySecurity = class _GatewaySecurity {
|
|
|
8081
8186
|
if (!response.ok) {
|
|
8082
8187
|
const body = await response.text();
|
|
8083
8188
|
throw new GatewaySecurityError(
|
|
8084
|
-
`Gateway API ${response.status} on ${
|
|
8189
|
+
`Gateway API ${response.status} on ${path14}: ${body || response.statusText}`
|
|
8085
8190
|
);
|
|
8086
8191
|
}
|
|
8087
8192
|
return await response.json();
|
|
@@ -8171,9 +8276,9 @@ __export(files_exports, {
|
|
|
8171
8276
|
uploadFile: () => uploadFile
|
|
8172
8277
|
});
|
|
8173
8278
|
init_worlds();
|
|
8174
|
-
import { createHash as
|
|
8175
|
-
import * as
|
|
8176
|
-
import * as
|
|
8279
|
+
import { createHash as createHash9 } from "crypto";
|
|
8280
|
+
import * as fs11 from "fs";
|
|
8281
|
+
import * as path10 from "path";
|
|
8177
8282
|
import { Readable, Transform } from "stream";
|
|
8178
8283
|
import { pipeline } from "stream/promises";
|
|
8179
8284
|
var DRIVE_PREFIX = "drive:";
|
|
@@ -8221,9 +8326,9 @@ async function readFile2(options = {}, filePath) {
|
|
|
8221
8326
|
async function downloadFile(options = {}, filePath, outPath, onProgress) {
|
|
8222
8327
|
const file = await getFile(options, filePath);
|
|
8223
8328
|
const res = await openDownload(file.url);
|
|
8224
|
-
|
|
8329
|
+
fs11.mkdirSync(path10.dirname(path10.resolve(outPath)), { recursive: true });
|
|
8225
8330
|
const source = Readable.fromWeb(res.body);
|
|
8226
|
-
await pipeline(source, counting((n) => onProgress?.(n, file.sizeBytes)),
|
|
8331
|
+
await pipeline(source, counting((n) => onProgress?.(n, file.sizeBytes)), fs11.createWriteStream(outPath));
|
|
8227
8332
|
return { ...file, out: outPath };
|
|
8228
8333
|
}
|
|
8229
8334
|
async function requestUpload(options = {}, body) {
|
|
@@ -8233,8 +8338,8 @@ async function confirmUpload(options = {}, fileId, ok = true) {
|
|
|
8233
8338
|
return apiRequest(options, "POST", `${BASE}/confirm`, { fileId, ok });
|
|
8234
8339
|
}
|
|
8235
8340
|
async function sha256Base64(localPath) {
|
|
8236
|
-
const hash =
|
|
8237
|
-
for await (const chunk of
|
|
8341
|
+
const hash = createHash9("sha256");
|
|
8342
|
+
for await (const chunk of fs11.createReadStream(localPath)) hash.update(chunk);
|
|
8238
8343
|
return hash.digest("base64");
|
|
8239
8344
|
}
|
|
8240
8345
|
var CONTENT_TYPES = {
|
|
@@ -8270,7 +8375,7 @@ var CONTENT_TYPES = {
|
|
|
8270
8375
|
".mp4": "video/mp4"
|
|
8271
8376
|
};
|
|
8272
8377
|
function contentTypeFor(name) {
|
|
8273
|
-
return CONTENT_TYPES[
|
|
8378
|
+
return CONTENT_TYPES[path10.extname(name).toLowerCase()] ?? "application/octet-stream";
|
|
8274
8379
|
}
|
|
8275
8380
|
function counting(report) {
|
|
8276
8381
|
let seen = 0;
|
|
@@ -8297,7 +8402,7 @@ async function putPresigned(uploadUrl, body, headers) {
|
|
|
8297
8402
|
if (!res.ok) throw new Error(`upload failed: storage answered HTTP ${res.status}: ${(await res.text()).slice(0, 300)}`);
|
|
8298
8403
|
}
|
|
8299
8404
|
async function uploadFile(options = {}, localPath, targetPath, upload = {}) {
|
|
8300
|
-
const stat =
|
|
8405
|
+
const stat = fs11.statSync(localPath);
|
|
8301
8406
|
if (!stat.isFile()) throw new Error(`${localPath} is not a file`);
|
|
8302
8407
|
if (stat.size === 0) throw new Error(`${localPath} is empty; the drive refuses zero-byte uploads`);
|
|
8303
8408
|
const contentType = upload.contentType ?? contentTypeFor(localPath);
|
|
@@ -8305,7 +8410,7 @@ async function uploadFile(options = {}, localPath, targetPath, upload = {}) {
|
|
|
8305
8410
|
const target = drivePath(targetPath);
|
|
8306
8411
|
const granted = await requestUpload(options, { path: target, contentLength: stat.size, contentType, sha256: sha2562, ...upload.overwrite ? { overwrite: true } : {} });
|
|
8307
8412
|
try {
|
|
8308
|
-
const stream =
|
|
8413
|
+
const stream = fs11.createReadStream(localPath).pipe(counting((n) => upload.onProgress?.(n, stat.size)));
|
|
8309
8414
|
await putPresigned(granted.uploadUrl, Readable.toWeb(stream), { contentType, contentLength: stat.size, sha256: sha2562 });
|
|
8310
8415
|
} catch (error) {
|
|
8311
8416
|
await confirmUpload(options, granted.fileId, false).catch(() => void 0);
|
|
@@ -8318,7 +8423,7 @@ async function uploadBytes(options = {}, bytes, targetPath, upload = {}) {
|
|
|
8318
8423
|
if (!bytes.length) throw new Error("nothing to upload: the content is empty");
|
|
8319
8424
|
const target = drivePath(targetPath);
|
|
8320
8425
|
const contentType = upload.contentType ?? contentTypeFor(target);
|
|
8321
|
-
const sha2562 =
|
|
8426
|
+
const sha2562 = createHash9("sha256").update(bytes).digest("base64");
|
|
8322
8427
|
const granted = await requestUpload(options, { path: target, contentLength: bytes.length, contentType, sha256: sha2562, ...upload.overwrite ? { overwrite: true } : {} });
|
|
8323
8428
|
try {
|
|
8324
8429
|
await putPresigned(granted.uploadUrl, new Uint8Array(bytes), { contentType, contentLength: bytes.length, sha256: sha2562 });
|
|
@@ -8511,7 +8616,7 @@ __export(hooks_exports, {
|
|
|
8511
8616
|
});
|
|
8512
8617
|
|
|
8513
8618
|
// src/hooks/alias.ts
|
|
8514
|
-
import { createHash as
|
|
8619
|
+
import { createHash as createHash10, createHmac, randomBytes as randomBytes2 } from "crypto";
|
|
8515
8620
|
var GIVEN = [
|
|
8516
8621
|
"John",
|
|
8517
8622
|
"Mary",
|
|
@@ -9280,9 +9385,9 @@ var AliasMap = class _AliasMap {
|
|
|
9280
9385
|
});
|
|
9281
9386
|
if (alias.role === "private") {
|
|
9282
9387
|
for (const slug of this.slugs) {
|
|
9283
|
-
const standIn = "sha256:" +
|
|
9388
|
+
const standIn = "sha256:" + createHash10("sha256").update(`${slug}:${canonical(alias.kind, alias.display)}`, "utf8").digest("hex");
|
|
9284
9389
|
alias.variants.push([
|
|
9285
|
-
"sha256:" +
|
|
9390
|
+
"sha256:" + createHash10("sha256").update(`${slug}:${alias.canonical}`, "utf8").digest("hex"),
|
|
9286
9391
|
standIn
|
|
9287
9392
|
]);
|
|
9288
9393
|
this.aliasDigests.add(standIn.toLowerCase());
|
|
@@ -9579,7 +9684,7 @@ function mirrorHandle(handle, identity) {
|
|
|
9579
9684
|
}
|
|
9580
9685
|
|
|
9581
9686
|
// src/hooks/config.ts
|
|
9582
|
-
import * as
|
|
9687
|
+
import * as fs12 from "fs";
|
|
9583
9688
|
|
|
9584
9689
|
// src/cli/platform/worldData/toml.ts
|
|
9585
9690
|
var TomlError = class extends Error {
|
|
@@ -9927,9 +10032,9 @@ function alternatives(raw) {
|
|
|
9927
10032
|
if (!parts2.length || parts2.includes("*")) return [];
|
|
9928
10033
|
return parts2;
|
|
9929
10034
|
}
|
|
9930
|
-
function hasPath(node,
|
|
10035
|
+
function hasPath(node, path14) {
|
|
9931
10036
|
let current = node;
|
|
9932
|
-
for (const part of
|
|
10037
|
+
for (const part of path14.split(".")) {
|
|
9933
10038
|
if (current && typeof current === "object" && !Array.isArray(current) && part in current) {
|
|
9934
10039
|
current = current[part];
|
|
9935
10040
|
continue;
|
|
@@ -9970,7 +10075,7 @@ function matches(m, event) {
|
|
|
9970
10075
|
if (m.args.length) {
|
|
9971
10076
|
const haystacks = event.event === "pre_request" || event.event === "post_response" ? [event.request?.query, event.request?.body] : [event.toolInput];
|
|
9972
10077
|
const present = haystacks.filter((h) => h !== void 0 && h !== null);
|
|
9973
|
-
if (!m.args.every((
|
|
10078
|
+
if (!m.args.every((path14) => present.some((h) => hasPath(h, path14))))
|
|
9974
10079
|
return false;
|
|
9975
10080
|
}
|
|
9976
10081
|
return true;
|
|
@@ -10413,9 +10518,9 @@ function vendorOf(config, toolName) {
|
|
|
10413
10518
|
return void 0;
|
|
10414
10519
|
}
|
|
10415
10520
|
function loadHookConfig(file) {
|
|
10416
|
-
if (!
|
|
10521
|
+
if (!fs12.existsSync(file) || !fs12.statSync(file).isFile())
|
|
10417
10522
|
throw new HookConfigError(`${file}: no such file`);
|
|
10418
|
-
const text2 =
|
|
10523
|
+
const text2 = fs12.readFileSync(file, "utf8");
|
|
10419
10524
|
if (file.toLowerCase().endsWith(".json")) {
|
|
10420
10525
|
let data2;
|
|
10421
10526
|
try {
|
|
@@ -10795,8 +10900,8 @@ function parseHandler(event, raw, position) {
|
|
|
10795
10900
|
|
|
10796
10901
|
// src/hooks/handlers.ts
|
|
10797
10902
|
import { spawn as spawn3 } from "child_process";
|
|
10798
|
-
import * as
|
|
10799
|
-
import * as
|
|
10903
|
+
import * as fs13 from "fs";
|
|
10904
|
+
import * as path11 from "path";
|
|
10800
10905
|
import { pathToFileURL } from "url";
|
|
10801
10906
|
function parseStdout(text2, handler) {
|
|
10802
10907
|
const stripped = text2.trim();
|
|
@@ -10990,8 +11095,8 @@ var RecordHandler = class {
|
|
|
10990
11095
|
record.source = this.opts.source ?? null;
|
|
10991
11096
|
if (Array.isArray(this.sink)) this.sink.push(record);
|
|
10992
11097
|
else if (typeof this.sink === "string") {
|
|
10993
|
-
|
|
10994
|
-
|
|
11098
|
+
fs13.mkdirSync(path11.dirname(this.sink), { recursive: true });
|
|
11099
|
+
fs13.appendFileSync(this.sink, JSON.stringify(record) + "\n");
|
|
10995
11100
|
} else await this.sink(record);
|
|
10996
11101
|
return allow();
|
|
10997
11102
|
}
|
|
@@ -11196,7 +11301,7 @@ async function importCallable(target, cwd) {
|
|
|
11196
11301
|
const hash = target.lastIndexOf("#");
|
|
11197
11302
|
const modulePath = target.slice(0, hash);
|
|
11198
11303
|
const exportName = target.slice(hash + 1) || "default";
|
|
11199
|
-
const resolved = modulePath.startsWith(".") ||
|
|
11304
|
+
const resolved = modulePath.startsWith(".") || path11.isAbsolute(modulePath) ? pathToFileURL(path11.resolve(cwd, modulePath)).href : modulePath;
|
|
11200
11305
|
let module;
|
|
11201
11306
|
try {
|
|
11202
11307
|
module = await import(resolved);
|
|
@@ -11259,8 +11364,8 @@ async function buildHandler(spec, aliases, opts) {
|
|
|
11259
11364
|
}
|
|
11260
11365
|
|
|
11261
11366
|
// src/hooks/live.ts
|
|
11262
|
-
import * as
|
|
11263
|
-
import * as
|
|
11367
|
+
import * as fs14 from "fs";
|
|
11368
|
+
import * as path12 from "path";
|
|
11264
11369
|
var USER_AGENT = "gateway-hooks/1 (+https://withgateway.ai)";
|
|
11265
11370
|
var TAGS = /<(script|style)[^>]*>.*?<\/\1>/gis;
|
|
11266
11371
|
var STRIP = /<[^>]+>/g;
|
|
@@ -11624,9 +11729,9 @@ var CallableTool = class _CallableTool {
|
|
|
11624
11729
|
}
|
|
11625
11730
|
};
|
|
11626
11731
|
function readConnection(root) {
|
|
11627
|
-
const file =
|
|
11628
|
-
if (!
|
|
11629
|
-
const raw = parseToml(
|
|
11732
|
+
const file = path12.join(root, "connector.toml");
|
|
11733
|
+
if (!fs14.existsSync(file)) throw new Error(`no connector.toml at ${root}`);
|
|
11734
|
+
const raw = parseToml(fs14.readFileSync(file, "utf8"));
|
|
11630
11735
|
const connector = raw.connector ?? {};
|
|
11631
11736
|
const auth = raw.auth ?? {};
|
|
11632
11737
|
const operations = {};
|
|
@@ -11640,7 +11745,7 @@ function readConnection(root) {
|
|
|
11640
11745
|
};
|
|
11641
11746
|
}
|
|
11642
11747
|
return {
|
|
11643
|
-
slug: connector.slug ??
|
|
11748
|
+
slug: connector.slug ?? path12.basename(root),
|
|
11644
11749
|
baseUrl: (connector.base_url ?? "").replace(/\/+$/, ""),
|
|
11645
11750
|
scheme: auth.scheme ?? "none",
|
|
11646
11751
|
...typeof auth.name === "string" ? { authName: auth.name } : {},
|
|
@@ -11657,8 +11762,8 @@ var ConnectorTool = class {
|
|
|
11657
11762
|
this.spec = spec;
|
|
11658
11763
|
this.live = live;
|
|
11659
11764
|
let location = spec.options.connector;
|
|
11660
|
-
if (!
|
|
11661
|
-
const root =
|
|
11765
|
+
if (!path12.isAbsolute(location)) location = path12.resolve(baseDir, location);
|
|
11766
|
+
const root = fs14.existsSync(location) && fs14.statSync(location).isFile() ? path12.dirname(location) : location;
|
|
11662
11767
|
try {
|
|
11663
11768
|
this.connection = readConnection(root);
|
|
11664
11769
|
} catch (error) {
|
|
@@ -11812,16 +11917,16 @@ var Recorder = class {
|
|
|
11812
11917
|
this.file = file;
|
|
11813
11918
|
}
|
|
11814
11919
|
write(line) {
|
|
11815
|
-
|
|
11816
|
-
|
|
11920
|
+
fs14.mkdirSync(path12.dirname(this.file), { recursive: true });
|
|
11921
|
+
fs14.appendFileSync(this.file, canonical2(line) + "\n");
|
|
11817
11922
|
}
|
|
11818
11923
|
};
|
|
11819
11924
|
var Replay = class {
|
|
11820
11925
|
constructor(file) {
|
|
11821
11926
|
this.file = file;
|
|
11822
|
-
if (!
|
|
11927
|
+
if (!fs14.existsSync(file))
|
|
11823
11928
|
throw new LiveToolError(`replay: no recording at ${file}`);
|
|
11824
|
-
|
|
11929
|
+
fs14.readFileSync(file, "utf8").split(/\r?\n/).forEach((raw, index2) => {
|
|
11825
11930
|
if (!raw.trim()) return;
|
|
11826
11931
|
let line;
|
|
11827
11932
|
try {
|
|
@@ -11905,7 +12010,7 @@ var LiveTools = class _LiveTools {
|
|
|
11905
12010
|
...config.live.record ? { record: interpolatePath(config.live.record, run.runId, directory) } : {},
|
|
11906
12011
|
...config.live.replay ? { replay: interpolatePath(config.live.replay, run.runId, directory) } : {}
|
|
11907
12012
|
};
|
|
11908
|
-
return _LiveTools.create(run, live,
|
|
12013
|
+
return _LiveTools.create(run, live, path12.dirname(path12.resolve(file)));
|
|
11909
12014
|
}
|
|
11910
12015
|
/** The declared tools for a model. `openai`: `{type: "function", function: {name,
|
|
11911
12016
|
* description, parameters}}`; `anthropic`: `{name, description, input_schema}`. */
|
|
@@ -12004,8 +12109,8 @@ var LiveTools = class _LiveTools {
|
|
|
12004
12109
|
|
|
12005
12110
|
// src/hooks/run.ts
|
|
12006
12111
|
import { randomBytes as randomBytes3 } from "crypto";
|
|
12007
|
-
import * as
|
|
12008
|
-
import * as
|
|
12112
|
+
import * as fs15 from "fs";
|
|
12113
|
+
import * as path13 from "path";
|
|
12009
12114
|
var BLOCKING_EVENTS = [
|
|
12010
12115
|
"pre_tool_call",
|
|
12011
12116
|
"pre_request",
|
|
@@ -12055,12 +12160,12 @@ var HookRun = class _HookRun {
|
|
|
12055
12160
|
mintInbound: options.mintInbound ?? config.aliasMintInbound
|
|
12056
12161
|
});
|
|
12057
12162
|
this.cwd = options.cwd ?? process.cwd();
|
|
12058
|
-
this.runDir = options.runDir ??
|
|
12163
|
+
this.runDir = options.runDir ?? path13.join(this.cwd, "runs", this.runId);
|
|
12059
12164
|
const chosen = options.legend !== void 0 ? options.legend : config.aliasLegend;
|
|
12060
|
-
this.legendPath = chosen ?
|
|
12165
|
+
this.legendPath = chosen ? path13.resolve(this.cwd, interpolatePath(chosen, this.runId, this.runDir)) : null;
|
|
12061
12166
|
this.sessionId = options.session;
|
|
12062
12167
|
this.source = options.source;
|
|
12063
|
-
this.configDir = config.source ?
|
|
12168
|
+
this.configDir = config.source ? path13.dirname(path13.resolve(config.source)) : this.cwd;
|
|
12064
12169
|
}
|
|
12065
12170
|
/** Build from a parsed config (an object in the file's shape, or a `HookConfig`);
|
|
12066
12171
|
* handlers are constructed now, so a callable that does not import fails here. */
|
|
@@ -12470,8 +12575,8 @@ var HookRun = class _HookRun {
|
|
|
12470
12575
|
throw new Error(
|
|
12471
12576
|
"no legend path: set [alias] legend, pass legend to the run, or give a path"
|
|
12472
12577
|
);
|
|
12473
|
-
|
|
12474
|
-
|
|
12578
|
+
fs15.mkdirSync(path13.dirname(target), { recursive: true });
|
|
12579
|
+
fs15.writeFileSync(target, JSON.stringify(this.legend(), null, 2) + "\n");
|
|
12475
12580
|
return target;
|
|
12476
12581
|
}
|
|
12477
12582
|
writeLegendIfConfigured() {
|
|
@@ -12563,14 +12668,14 @@ var HookedSession = class {
|
|
|
12563
12668
|
* `apiHeaders()`), `pre_request` before it and `post_response` after. Returns
|
|
12564
12669
|
* `{status, body, headers}`; a 4xx/5xx is returned, not thrown, so the agent sees
|
|
12565
12670
|
* the vendor's own error shape (rewritten like any result). */
|
|
12566
|
-
async request(method,
|
|
12671
|
+
async request(method, path14, opts = {}) {
|
|
12567
12672
|
if (!this.inner.api && !this.requestFn)
|
|
12568
12673
|
throw new Error(
|
|
12569
12674
|
"this session has no api surface (pass requestFn for a transport of your own)"
|
|
12570
12675
|
);
|
|
12571
12676
|
let request = {
|
|
12572
12677
|
method: method.toUpperCase(),
|
|
12573
|
-
path:
|
|
12678
|
+
path: path14,
|
|
12574
12679
|
query: { ...opts.query ?? {} },
|
|
12575
12680
|
body: opts.body ?? null
|
|
12576
12681
|
};
|
|
@@ -13051,7 +13156,6 @@ export {
|
|
|
13051
13156
|
identify,
|
|
13052
13157
|
ingest,
|
|
13053
13158
|
ingestToolCalls,
|
|
13054
|
-
isIncludedInContentHash,
|
|
13055
13159
|
isTaskIdRef,
|
|
13056
13160
|
isTaskManifest,
|
|
13057
13161
|
isTaskSpec,
|