@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/worlds/index.mjs
CHANGED
|
@@ -27,9 +27,9 @@ function surfaceKinds(s) {
|
|
|
27
27
|
if (s.browser) kinds.push("browser");
|
|
28
28
|
return kinds;
|
|
29
29
|
}
|
|
30
|
-
function uiUrl(ui,
|
|
30
|
+
function uiUrl(ui, path10) {
|
|
31
31
|
const base = ui.url.replace(/\/+$/, "");
|
|
32
|
-
const rel =
|
|
32
|
+
const rel = path10.startsWith("/") ? path10 : `/${path10}`;
|
|
33
33
|
if (!ui.token) return base + rel;
|
|
34
34
|
const [beforeHash, hash] = splitHash(rel);
|
|
35
35
|
const joiner = beforeHash.includes("?") ? "&" : "?";
|
|
@@ -587,12 +587,13 @@ async function openSession(slugOrRef, taskOrOpts, positionalOpts = {}) {
|
|
|
587
587
|
);
|
|
588
588
|
const at = slugOrRef.indexOf("@");
|
|
589
589
|
const slug = at === -1 ? slugOrRef : slugOrRef.slice(0, at);
|
|
590
|
+
const ref = at === -1 ? "" : slugOrRef.slice(at + 1);
|
|
590
591
|
const state2 = await apiRequest(
|
|
591
592
|
options,
|
|
592
593
|
"POST",
|
|
593
594
|
"/api/public/world-sessions",
|
|
594
595
|
{
|
|
595
|
-
...opts.versionId ? { versionId: opts.versionId } : { slug },
|
|
596
|
+
...opts.versionId ? { versionId: opts.versionId } : { slug, ...ref && { ref } },
|
|
596
597
|
task,
|
|
597
598
|
...opts.reuseWarm === void 0 ? {} : { reuseWarm: opts.reuseWarm },
|
|
598
599
|
...opts.surfaces?.length ? { surfaces: opts.surfaces } : {}
|
|
@@ -790,18 +791,18 @@ var init_session = __esm({
|
|
|
790
791
|
}
|
|
791
792
|
/** The reporter `browser()` uses; exposed for a page you drive yourself. */
|
|
792
793
|
browserRecorder(agentId) {
|
|
793
|
-
const
|
|
794
|
+
const path10 = `/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/browser-events`;
|
|
794
795
|
const id = agentId ?? process.env.GATEWAY_AGENT_ID ?? `agent-${randomUUID().replace(/-/g, "").slice(0, 8)}`;
|
|
795
796
|
return new BrowserActionRecorder(
|
|
796
797
|
async (events) => {
|
|
797
|
-
await apiRequest(this.options, "POST",
|
|
798
|
+
await apiRequest(this.options, "POST", path10, { events });
|
|
798
799
|
},
|
|
799
800
|
id,
|
|
800
801
|
{
|
|
801
802
|
// Continue this agent's timeline where the platform has it, so the
|
|
802
803
|
// same id reopened later never re-numbers from zero.
|
|
803
804
|
resumeFrom: async () => {
|
|
804
|
-
const summary = await apiRequest(this.options, "GET",
|
|
805
|
+
const summary = await apiRequest(this.options, "GET", path10);
|
|
805
806
|
return summary.agents.find((a) => a.agentId === id)?.nextSeq ?? 0;
|
|
806
807
|
}
|
|
807
808
|
}
|
|
@@ -1607,10 +1608,10 @@ var init_users = __esm({
|
|
|
1607
1608
|
totalItems: Number(meta.totalItems ?? rows.length)
|
|
1608
1609
|
};
|
|
1609
1610
|
}
|
|
1610
|
-
async requestJson(method,
|
|
1611
|
+
async requestJson(method, path10, payload) {
|
|
1611
1612
|
let response;
|
|
1612
1613
|
try {
|
|
1613
|
-
response = await fetch(`${this.host}${
|
|
1614
|
+
response = await fetch(`${this.host}${path10}`, {
|
|
1614
1615
|
method,
|
|
1615
1616
|
headers: {
|
|
1616
1617
|
Authorization: this.authHeader(),
|
|
@@ -1621,17 +1622,17 @@ var init_users = __esm({
|
|
|
1621
1622
|
});
|
|
1622
1623
|
} catch (error) {
|
|
1623
1624
|
throw new UserProfileError(
|
|
1624
|
-
`${method} ${
|
|
1625
|
+
`${method} ${path10} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
1625
1626
|
{ cause: error }
|
|
1626
1627
|
);
|
|
1627
1628
|
}
|
|
1628
1629
|
const text2 = await response.text();
|
|
1629
1630
|
if (!response.ok) {
|
|
1630
1631
|
throw new UserProfileError(
|
|
1631
|
-
`${method} ${
|
|
1632
|
+
`${method} ${path10} failed (${response.status}): ${text2.slice(0, 500)}`
|
|
1632
1633
|
);
|
|
1633
1634
|
}
|
|
1634
|
-
this.log("%s %s -> %s", method,
|
|
1635
|
+
this.log("%s %s -> %s", method, path10, response.status);
|
|
1635
1636
|
return safeJson(text2);
|
|
1636
1637
|
}
|
|
1637
1638
|
authHeader() {
|
|
@@ -1895,10 +1896,10 @@ var init_scores = __esm({
|
|
|
1895
1896
|
metadata: signalMetadata
|
|
1896
1897
|
});
|
|
1897
1898
|
}
|
|
1898
|
-
async request(method,
|
|
1899
|
+
async request(method, path10, payload) {
|
|
1899
1900
|
let response;
|
|
1900
1901
|
try {
|
|
1901
|
-
response = await fetch(`${this.host}${
|
|
1902
|
+
response = await fetch(`${this.host}${path10}`, {
|
|
1902
1903
|
method,
|
|
1903
1904
|
headers: {
|
|
1904
1905
|
Authorization: this.authHeader(),
|
|
@@ -1909,17 +1910,17 @@ var init_scores = __esm({
|
|
|
1909
1910
|
});
|
|
1910
1911
|
} catch (error) {
|
|
1911
1912
|
throw new ScoreError(
|
|
1912
|
-
`${method} ${
|
|
1913
|
+
`${method} ${path10} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
1913
1914
|
{ cause: error }
|
|
1914
1915
|
);
|
|
1915
1916
|
}
|
|
1916
1917
|
const text2 = await response.text();
|
|
1917
1918
|
if (!response.ok) {
|
|
1918
1919
|
throw new ScoreError(
|
|
1919
|
-
`${method} ${
|
|
1920
|
+
`${method} ${path10} failed (${response.status}): ${text2.slice(0, 500)}`
|
|
1920
1921
|
);
|
|
1921
1922
|
}
|
|
1922
|
-
this.log("%s %s -> %s", method,
|
|
1923
|
+
this.log("%s %s -> %s", method, path10, response.status);
|
|
1923
1924
|
}
|
|
1924
1925
|
authHeader() {
|
|
1925
1926
|
return `Basic ${Buffer.from(`${this.publicKey}:${this.secretKey}`).toString(
|
|
@@ -1947,7 +1948,7 @@ var require_package = __commonJS({
|
|
|
1947
1948
|
"package.json"(exports, module) {
|
|
1948
1949
|
module.exports = {
|
|
1949
1950
|
name: "@withgateway/sdk",
|
|
1950
|
-
version: "0.2.
|
|
1951
|
+
version: "0.2.5",
|
|
1951
1952
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
1952
1953
|
main: "./dist/index.js",
|
|
1953
1954
|
module: "./dist/index.mjs",
|
|
@@ -2051,6 +2052,7 @@ var require_package = __commonJS({
|
|
|
2051
2052
|
"typecheck:examples": "tsc -p tsconfig.examples.json --noEmit",
|
|
2052
2053
|
test: "vitest",
|
|
2053
2054
|
"test:run": "vitest run",
|
|
2055
|
+
"test:integration": "vitest run --config vitest.integration.config.ts",
|
|
2054
2056
|
lint: "eslint src --ext .ts",
|
|
2055
2057
|
clean: "rm -rf dist",
|
|
2056
2058
|
example: "tsx examples/test-ab-experiment.ts",
|
|
@@ -2908,6 +2910,152 @@ var init_taskRun = __esm({
|
|
|
2908
2910
|
}
|
|
2909
2911
|
});
|
|
2910
2912
|
|
|
2913
|
+
// src/worlds/worldDir.ts
|
|
2914
|
+
import { createHash as createHash2 } from "crypto";
|
|
2915
|
+
import * as fs2 from "fs";
|
|
2916
|
+
import * as path2 from "path";
|
|
2917
|
+
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;
|
|
2918
|
+
var init_worldDir = __esm({
|
|
2919
|
+
"src/worlds/worldDir.ts"() {
|
|
2920
|
+
"use strict";
|
|
2921
|
+
WORLD_MANIFEST = "gateway-env.toml";
|
|
2922
|
+
API_BUNDLE_MANIFEST = "gateway-api-world.toml";
|
|
2923
|
+
BUNDLED_WORLD_PREFIX = "server/world/";
|
|
2924
|
+
CONNECTOR_SPEC = "connector.toml";
|
|
2925
|
+
PYPROJECT = "pyproject.toml";
|
|
2926
|
+
WORLD_SCHEMA_MARKERS = ["schema/world.json", "schema/runtime.json", "schema/lock.json"];
|
|
2927
|
+
WORLD_ROOT_MARKERS = [CONNECTOR_SPEC, ...WORLD_SCHEMA_MARKERS];
|
|
2928
|
+
BROAD_ROOT_MARKERS = [WORLD_MANIFEST, API_BUNDLE_MANIFEST];
|
|
2929
|
+
SKIPPED_DIRS = /* @__PURE__ */ new Set(["dist", "build", "outputs", "__pycache__"]);
|
|
2930
|
+
V1_DEP = /["']verifiers\s*(?:\[[^\]]*\])?\s*(?:>=|~=|==|>)\s*(?:0\.(?:[2-9]\d*|[1-9]\d+)|[1-9]\d*)/;
|
|
2931
|
+
V1_IMPORT = /^\s*(?:from\s+verifiers\.v1\s+import\b|from\s+verifiers\s+import\s+v1\b|import\s+verifiers\.v1\b)/m;
|
|
2932
|
+
V1_TASKSET = /class\s+\w+\s*\(\s*(?:(?:vf|v1|verifiers(?:\.v1)?)\.)?Taskset\s*[,)]/;
|
|
2933
|
+
HARBOR_TASK = /^(?:tasks\/)?([^/]+)\/task\.toml$/;
|
|
2934
|
+
skippedDir = (name) => name.startsWith(".") || SKIPPED_DIRS.has(name) || name.endsWith(".egg-info");
|
|
2935
|
+
byCodePoint = (a, b) => Buffer.compare(Buffer.from(a, "utf-8"), Buffer.from(b, "utf-8"));
|
|
2936
|
+
WorldDir = class _WorldDir {
|
|
2937
|
+
constructor(dir, worldRoot) {
|
|
2938
|
+
this.dir = dir;
|
|
2939
|
+
this.worldRoot = worldRoot;
|
|
2940
|
+
}
|
|
2941
|
+
pathsMemo;
|
|
2942
|
+
static open(dir) {
|
|
2943
|
+
const present = (rel) => fs2.existsSync(path2.join(dir, rel));
|
|
2944
|
+
const bundled = present(API_BUNDLE_MANIFEST) && WORLD_ROOT_MARKERS.some((m) => present(BUNDLED_WORLD_PREFIX + m));
|
|
2945
|
+
return new _WorldDir(dir, bundled ? BUNDLED_WORLD_PREFIX : "");
|
|
2946
|
+
}
|
|
2947
|
+
// ── Files ──────────────────────────────────────────────────────────────
|
|
2948
|
+
has(rel) {
|
|
2949
|
+
return fs2.existsSync(path2.join(this.dir, rel));
|
|
2950
|
+
}
|
|
2951
|
+
text(rel) {
|
|
2952
|
+
try {
|
|
2953
|
+
return fs2.readFileSync(path2.join(this.dir, rel), "utf-8");
|
|
2954
|
+
} catch {
|
|
2955
|
+
return null;
|
|
2956
|
+
}
|
|
2957
|
+
}
|
|
2958
|
+
/** A path under the authored world's root. */
|
|
2959
|
+
worldPath(rel) {
|
|
2960
|
+
return this.worldRoot + rel;
|
|
2961
|
+
}
|
|
2962
|
+
/** Every regular file the archive rules keep (`_archive.py`: no hidden,
|
|
2963
|
+
* dist, build, outputs, pycache or egg-info directories), as sorted
|
|
2964
|
+
* relpaths. Root files enter only when a Gateway manifest widens the root
|
|
2965
|
+
* or they are README.md, pyproject.toml or Python. */
|
|
2966
|
+
get archivePaths() {
|
|
2967
|
+
if (this.pathsMemo) return this.pathsMemo;
|
|
2968
|
+
const broad = BROAD_ROOT_MARKERS.some((m) => this.has(m));
|
|
2969
|
+
const out = [];
|
|
2970
|
+
const walk = (rel) => {
|
|
2971
|
+
for (const entry of fs2.readdirSync(rel ? path2.join(this.dir, rel) : this.dir, { withFileTypes: true })) {
|
|
2972
|
+
const child = rel ? `${rel}/${entry.name}` : entry.name;
|
|
2973
|
+
if (entry.isDirectory()) {
|
|
2974
|
+
if (!skippedDir(entry.name)) walk(child);
|
|
2975
|
+
} else if (entry.isFile() && !entry.name.startsWith(".")) {
|
|
2976
|
+
const rootKept = broad || ["README.md", PYPROJECT].includes(entry.name) || entry.name.endsWith(".py");
|
|
2977
|
+
if (rel || rootKept) out.push(child);
|
|
2978
|
+
}
|
|
2979
|
+
}
|
|
2980
|
+
};
|
|
2981
|
+
walk("");
|
|
2982
|
+
return this.pathsMemo = out.sort(byCodePoint);
|
|
2983
|
+
}
|
|
2984
|
+
/** A root `.gitignore` is present: the Python SDK honours it when
|
|
2985
|
+
* collecting, this package does not reimplement gitignore. */
|
|
2986
|
+
get hasRootGitignore() {
|
|
2987
|
+
return this.has(".gitignore");
|
|
2988
|
+
}
|
|
2989
|
+
/** SHA-256 over `utf8("file:" + relpath)` + bytes per archive path in
|
|
2990
|
+
* sorted order: the version's identity, byte-compatible with
|
|
2991
|
+
* `_archive.compute_content_hash` and Prime Intellect. */
|
|
2992
|
+
get contentHash() {
|
|
2993
|
+
const hasher = createHash2("sha256");
|
|
2994
|
+
for (const rel of this.archivePaths) {
|
|
2995
|
+
hasher.update(Buffer.from(`file:${rel}`, "utf-8"));
|
|
2996
|
+
hasher.update(fs2.readFileSync(path2.join(this.dir, rel)));
|
|
2997
|
+
}
|
|
2998
|
+
return hasher.digest("hex");
|
|
2999
|
+
}
|
|
3000
|
+
// ── Markers ────────────────────────────────────────────────────────────
|
|
3001
|
+
get isApiBundle() {
|
|
3002
|
+
return this.has(API_BUNDLE_MANIFEST);
|
|
3003
|
+
}
|
|
3004
|
+
get hasManifest() {
|
|
3005
|
+
return this.has(this.worldPath(WORLD_MANIFEST));
|
|
3006
|
+
}
|
|
3007
|
+
get hasSchemaMarker() {
|
|
3008
|
+
return WORLD_SCHEMA_MARKERS.some((m) => this.has(this.worldPath(m)));
|
|
3009
|
+
}
|
|
3010
|
+
/** Harbor task dirs, relative to the tree: `tasks/<name>` when a `tasks/`
|
|
3011
|
+
* dir holds them, else the root `<name>` dirs. */
|
|
3012
|
+
taskDirs() {
|
|
3013
|
+
const names = /* @__PURE__ */ new Set();
|
|
3014
|
+
for (const rel of this.archivePaths) {
|
|
3015
|
+
const m = HARBOR_TASK.exec(rel);
|
|
3016
|
+
if (m) names.add(rel.startsWith("tasks/") ? `tasks/${m[1]}` : m[1]);
|
|
3017
|
+
}
|
|
3018
|
+
const under = [...names].filter((n) => n.startsWith("tasks/"));
|
|
3019
|
+
return (under.length ? under : [...names]).sort();
|
|
3020
|
+
}
|
|
3021
|
+
/** The Python package of a verifiers tree (`<pkg>/__init__.py` or
|
|
3022
|
+
* `src/<pkg>/__init__.py`), or null. */
|
|
3023
|
+
pythonPackage() {
|
|
3024
|
+
if (!this.has(PYPROJECT)) return null;
|
|
3025
|
+
for (const base of ["", "src/"]) {
|
|
3026
|
+
const init2 = this.archivePaths.find((rel) => {
|
|
3027
|
+
const m = /^([^/]+)\/__init__\.py$/.exec(rel.startsWith(base) ? rel.slice(base.length) : "");
|
|
3028
|
+
return m !== null && m[1] !== "tests";
|
|
3029
|
+
});
|
|
3030
|
+
if (init2) return { name: init2.slice(base.length).split("/")[0], init: init2 };
|
|
3031
|
+
}
|
|
3032
|
+
return null;
|
|
3033
|
+
}
|
|
3034
|
+
/** The package targets the `verifiers.v1` API: read from the root
|
|
3035
|
+
* pyproject and every archived Python module. */
|
|
3036
|
+
get isVerifiersV1() {
|
|
3037
|
+
for (const rel of this.archivePaths) {
|
|
3038
|
+
if (rel !== PYPROJECT && !rel.endsWith(".py")) continue;
|
|
3039
|
+
const text2 = this.text(rel);
|
|
3040
|
+
if (text2 === null) continue;
|
|
3041
|
+
if (rel === PYPROJECT ? V1_DEP.test(text2) : V1_IMPORT.test(text2) || text2.includes("__all__") && V1_TASKSET.test(text2))
|
|
3042
|
+
return true;
|
|
3043
|
+
}
|
|
3044
|
+
return false;
|
|
3045
|
+
}
|
|
3046
|
+
// ── The answer ─────────────────────────────────────────────────────────
|
|
3047
|
+
/** The runner's kind (`detect_env_kind`): api / mock-tools win over
|
|
3048
|
+
* everything, a harbor task tree next, then the verifiers API version. */
|
|
3049
|
+
get kind() {
|
|
3050
|
+
if (this.isApiBundle) return "api";
|
|
3051
|
+
if (this.has(WORLD_MANIFEST)) return "mock-tools";
|
|
3052
|
+
if (this.taskDirs().length) return "harbor";
|
|
3053
|
+
return this.isVerifiersV1 ? "verifiers-v1" : "verifiers";
|
|
3054
|
+
}
|
|
3055
|
+
};
|
|
3056
|
+
}
|
|
3057
|
+
});
|
|
3058
|
+
|
|
2911
3059
|
// src/worlds/hub.ts
|
|
2912
3060
|
var hub_exports = {};
|
|
2913
3061
|
__export(hub_exports, {
|
|
@@ -2916,7 +3064,6 @@ __export(hub_exports, {
|
|
|
2916
3064
|
collectArchiveRelPaths: () => collectArchiveRelPaths,
|
|
2917
3065
|
computeContentHash: () => computeContentHash,
|
|
2918
3066
|
createRef: () => createRef,
|
|
2919
|
-
isIncludedInContentHash: () => isIncludedInContentHash,
|
|
2920
3067
|
localTreeState: () => localTreeState,
|
|
2921
3068
|
propose: () => propose,
|
|
2922
3069
|
pull: () => pull,
|
|
@@ -2926,57 +3073,22 @@ __export(hub_exports, {
|
|
|
2926
3073
|
snapshotTreeHashes: () => snapshotTreeHashes,
|
|
2927
3074
|
writeLocalMeta: () => writeLocalMeta
|
|
2928
3075
|
});
|
|
2929
|
-
import { createHash as
|
|
3076
|
+
import { createHash as createHash3 } from "crypto";
|
|
2930
3077
|
import { gzipSync, gunzipSync } from "zlib";
|
|
2931
|
-
import * as
|
|
2932
|
-
import * as
|
|
2933
|
-
function isExcludedDirComponent(component) {
|
|
2934
|
-
return component.startsWith(".") || ROOT_EXCLUDED_DIRS.has(component) || component.endsWith(".egg-info");
|
|
2935
|
-
}
|
|
2936
|
-
function isIncludedInContentHash(relPath, includeAllRootFiles) {
|
|
2937
|
-
const parts = relPath.split("/");
|
|
2938
|
-
const name = parts[parts.length - 1];
|
|
2939
|
-
const dirParts = parts.slice(0, -1);
|
|
2940
|
-
if (name.startsWith(".")) return false;
|
|
2941
|
-
if (parts.includes("__pycache__")) return false;
|
|
2942
|
-
if (dirParts.length === 0) {
|
|
2943
|
-
return includeAllRootFiles || name === "README.md" || name === "pyproject.toml" || BROAD_ROOT_MARKERS.includes(name) || name.endsWith(".py");
|
|
2944
|
-
}
|
|
2945
|
-
return !dirParts.some(isExcludedDirComponent);
|
|
2946
|
-
}
|
|
3078
|
+
import * as fs3 from "fs";
|
|
3079
|
+
import * as path3 from "path";
|
|
2947
3080
|
function collectArchiveRelPaths(dir) {
|
|
2948
|
-
|
|
3081
|
+
const world = WorldDir.open(dir);
|
|
3082
|
+
if (world.hasRootGitignore) {
|
|
2949
3083
|
throw new Error(
|
|
2950
3084
|
"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."
|
|
2951
3085
|
);
|
|
2952
3086
|
}
|
|
2953
|
-
|
|
2954
|
-
const includeAllRootFiles = BROAD_ROOT_MARKERS.some(
|
|
2955
|
-
(marker) => fs2.existsSync(path2.join(dir, marker))
|
|
2956
|
-
);
|
|
2957
|
-
const walk = (rel) => {
|
|
2958
|
-
const abs = rel ? path2.join(dir, rel) : dir;
|
|
2959
|
-
for (const entry of fs2.readdirSync(abs, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
2960
|
-
const childRel = rel ? `${rel}/${entry.name}` : entry.name;
|
|
2961
|
-
if (entry.isDirectory()) {
|
|
2962
|
-
if (!isExcludedDirComponent(entry.name)) walk(childRel);
|
|
2963
|
-
} else if (entry.isFile()) {
|
|
2964
|
-
if (isIncludedInContentHash(childRel, includeAllRootFiles)) {
|
|
2965
|
-
out.push(childRel);
|
|
2966
|
-
}
|
|
2967
|
-
}
|
|
2968
|
-
}
|
|
2969
|
-
};
|
|
2970
|
-
walk("");
|
|
2971
|
-
return out.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
3087
|
+
return world.archivePaths;
|
|
2972
3088
|
}
|
|
2973
3089
|
function computeContentHash(dir) {
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
hasher.update(Buffer.from(`file:${relPath}`, "utf-8"));
|
|
2977
|
-
hasher.update(fs2.readFileSync(path2.join(dir, relPath)));
|
|
2978
|
-
}
|
|
2979
|
-
return hasher.digest("hex");
|
|
3090
|
+
collectArchiveRelPaths(dir);
|
|
3091
|
+
return WorldDir.open(dir).contentHash;
|
|
2980
3092
|
}
|
|
2981
3093
|
function octal(value, length) {
|
|
2982
3094
|
return Buffer.from(value.toString(8).padStart(length - 1, "0") + "\0", "ascii");
|
|
@@ -3024,14 +3136,14 @@ function tarMember(name, payload) {
|
|
|
3024
3136
|
function buildSourceTarball(dir) {
|
|
3025
3137
|
const parts = [];
|
|
3026
3138
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
3027
|
-
parts.push(...tarMember(relPath,
|
|
3139
|
+
parts.push(...tarMember(relPath, fs3.readFileSync(path3.join(dir, relPath))));
|
|
3028
3140
|
}
|
|
3029
3141
|
parts.push(Buffer.alloc(1024));
|
|
3030
3142
|
return gzipSync(Buffer.concat(parts), { level: 9 });
|
|
3031
3143
|
}
|
|
3032
3144
|
function readLocalMeta(dir) {
|
|
3033
3145
|
try {
|
|
3034
|
-
const raw =
|
|
3146
|
+
const raw = fs3.readFileSync(path3.join(dir, META_RELPATH), "utf-8");
|
|
3035
3147
|
const parsed = JSON.parse(raw);
|
|
3036
3148
|
return parsed && typeof parsed === "object" ? parsed : null;
|
|
3037
3149
|
} catch {
|
|
@@ -3042,16 +3154,16 @@ function pushSlug(dir, explicit) {
|
|
|
3042
3154
|
if (explicit) return explicit;
|
|
3043
3155
|
const meta = readLocalMeta(dir);
|
|
3044
3156
|
if (typeof meta?.slug === "string" && meta.slug) return meta.slug;
|
|
3045
|
-
return readPyproject(dir).name ??
|
|
3157
|
+
return readPyproject(dir).name ?? path3.basename(path3.resolve(dir));
|
|
3046
3158
|
}
|
|
3047
3159
|
function writeLocalMeta(dir, meta) {
|
|
3048
|
-
|
|
3049
|
-
|
|
3160
|
+
fs3.mkdirSync(path3.join(dir, ".gateway"), { recursive: true });
|
|
3161
|
+
fs3.writeFileSync(path3.join(dir, META_RELPATH), JSON.stringify(meta, null, 2));
|
|
3050
3162
|
}
|
|
3051
3163
|
function snapshotTreeHashes(dir) {
|
|
3052
3164
|
const out = {};
|
|
3053
3165
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
3054
|
-
out[relPath] =
|
|
3166
|
+
out[relPath] = createHash3("sha256").update(fs3.readFileSync(path3.join(dir, relPath))).digest("hex");
|
|
3055
3167
|
}
|
|
3056
3168
|
return out;
|
|
3057
3169
|
}
|
|
@@ -3069,7 +3181,7 @@ function localTreeState(dir) {
|
|
|
3069
3181
|
}
|
|
3070
3182
|
function readPyproject(dir) {
|
|
3071
3183
|
try {
|
|
3072
|
-
const text2 =
|
|
3184
|
+
const text2 = fs3.readFileSync(path3.join(dir, "pyproject.toml"), "utf-8");
|
|
3073
3185
|
const section = /\[project\]([\s\S]*?)(\n\[|$)/.exec(text2)?.[1] ?? "";
|
|
3074
3186
|
const name = /\bname\s*=\s*"([^"]+)"/.exec(section)?.[1];
|
|
3075
3187
|
const version = /\bversion\s*=\s*"([^"]+)"/.exec(section)?.[1];
|
|
@@ -3079,33 +3191,32 @@ function readPyproject(dir) {
|
|
|
3079
3191
|
}
|
|
3080
3192
|
}
|
|
3081
3193
|
function readWorldContractVersion(dir) {
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
}
|
|
3194
|
+
const world = WorldDir.open(dir);
|
|
3195
|
+
try {
|
|
3196
|
+
const parsed = JSON.parse(world.text(world.worldPath("schema/world.json")) ?? "");
|
|
3197
|
+
const pkg = parsed["x-gateway"]?.package;
|
|
3198
|
+
if (pkg?.version) return { name: pkg.id, version: pkg.version };
|
|
3199
|
+
} catch {
|
|
3089
3200
|
}
|
|
3090
3201
|
return {};
|
|
3091
3202
|
}
|
|
3092
3203
|
function buildFileManifest(dir) {
|
|
3093
3204
|
const entries = [];
|
|
3094
3205
|
const walk = (rel) => {
|
|
3095
|
-
const abs = rel ?
|
|
3096
|
-
for (const entry of
|
|
3206
|
+
const abs = rel ? path3.join(dir, rel) : dir;
|
|
3207
|
+
for (const entry of fs3.readdirSync(abs, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
3097
3208
|
const childRel = rel ? `${rel}/${entry.name}` : entry.name;
|
|
3098
3209
|
if (entry.isDirectory()) {
|
|
3099
3210
|
if (!SKIP_DIRS.has(entry.name) && !entry.name.endsWith(".egg-info")) {
|
|
3100
3211
|
walk(childRel);
|
|
3101
3212
|
}
|
|
3102
3213
|
} else if (entry.isFile()) {
|
|
3103
|
-
const payload =
|
|
3214
|
+
const payload = fs3.readFileSync(path3.join(dir, childRel));
|
|
3104
3215
|
entries.push({
|
|
3105
3216
|
path: childRel,
|
|
3106
3217
|
isDirectory: false,
|
|
3107
3218
|
size: payload.length,
|
|
3108
|
-
sha256:
|
|
3219
|
+
sha256: createHash3("sha256").update(payload).digest("hex")
|
|
3109
3220
|
});
|
|
3110
3221
|
}
|
|
3111
3222
|
}
|
|
@@ -3128,7 +3239,7 @@ async function putObject(url, data, shaB64) {
|
|
|
3128
3239
|
}
|
|
3129
3240
|
async function push(dir, opts = {}) {
|
|
3130
3241
|
const options = opts.options ?? {};
|
|
3131
|
-
if (!
|
|
3242
|
+
if (!fs3.statSync(dir).isDirectory()) throw new Error(`Not a directory: ${dir}`);
|
|
3132
3243
|
const localMeta = readLocalMeta(dir) ?? {};
|
|
3133
3244
|
const branch = opts.branch ?? localMeta.branch ?? DEFAULT_BRANCH;
|
|
3134
3245
|
const baseVersionId = opts.baseVersionId ?? localMeta.versionId ?? null;
|
|
@@ -3136,18 +3247,18 @@ async function push(dir, opts = {}) {
|
|
|
3136
3247
|
const pyproject = readPyproject(dir);
|
|
3137
3248
|
const contractVersion = pyproject.version ? void 0 : readWorldContractVersion(dir).version;
|
|
3138
3249
|
if (contractVersion) pyproject.version = contractVersion;
|
|
3139
|
-
const slug = opts.slug ?? localMeta.slug ?? pyproject.name ??
|
|
3250
|
+
const slug = opts.slug ?? localMeta.slug ?? pyproject.name ?? path3.basename(path3.resolve(dir));
|
|
3251
|
+
const metadata = {
|
|
3252
|
+
name: opts.name ?? pyproject.name ?? slug,
|
|
3253
|
+
...opts.description !== void 0 ? { description: opts.description } : {},
|
|
3254
|
+
...opts.tags !== void 0 ? { tags: opts.tags } : {},
|
|
3255
|
+
...opts.visibility ? { visibility: opts.visibility } : {}
|
|
3256
|
+
};
|
|
3140
3257
|
const resolve6 = await apiRequest(
|
|
3141
3258
|
options,
|
|
3142
3259
|
"POST",
|
|
3143
3260
|
"/api/public/benchmark-containers/resolve",
|
|
3144
|
-
{
|
|
3145
|
-
slug,
|
|
3146
|
-
name: opts.name ?? pyproject.name ?? slug,
|
|
3147
|
-
...opts.description ? { description: opts.description } : {},
|
|
3148
|
-
...opts.tags?.length ? { tags: opts.tags } : {},
|
|
3149
|
-
...opts.visibility ? { visibility: opts.visibility } : {}
|
|
3150
|
-
}
|
|
3261
|
+
{ slug, ...metadata }
|
|
3151
3262
|
);
|
|
3152
3263
|
const tarball = buildSourceTarball(dir);
|
|
3153
3264
|
const bundleSha256 = sha256b64(tarball);
|
|
@@ -3171,7 +3282,7 @@ async function push(dir, opts = {}) {
|
|
|
3171
3282
|
options,
|
|
3172
3283
|
"POST",
|
|
3173
3284
|
`/api/public/benchmark-containers/versions/${version.versionId}/finalize`,
|
|
3174
|
-
{ branch, baseVersionId, ...opts.force ? { force: true } : {} }
|
|
3285
|
+
{ branch, baseVersionId, ...opts.force ? { force: true } : {}, ...metadata }
|
|
3175
3286
|
);
|
|
3176
3287
|
writeLocalMeta(dir, {
|
|
3177
3288
|
...localMeta,
|
|
@@ -3216,9 +3327,9 @@ function extractBundle(bundle, dir) {
|
|
|
3216
3327
|
longName = null;
|
|
3217
3328
|
if (typeflag !== "0" && typeflag !== "") continue;
|
|
3218
3329
|
if (name.startsWith("/") || name.split("/").includes("..")) continue;
|
|
3219
|
-
const target =
|
|
3220
|
-
|
|
3221
|
-
|
|
3330
|
+
const target = path3.join(dir, name);
|
|
3331
|
+
fs3.mkdirSync(path3.dirname(target), { recursive: true });
|
|
3332
|
+
fs3.writeFileSync(target, body);
|
|
3222
3333
|
written++;
|
|
3223
3334
|
}
|
|
3224
3335
|
return written;
|
|
@@ -3234,13 +3345,13 @@ async function pull(slugRef, target, options = {}) {
|
|
|
3234
3345
|
if (!details.downloadUrl) {
|
|
3235
3346
|
throw new Error(`${slug}@${ref} resolved but has no uploaded bundle`);
|
|
3236
3347
|
}
|
|
3237
|
-
let dir = target ??
|
|
3348
|
+
let dir = target ?? path3.join(process.cwd(), slug);
|
|
3238
3349
|
if (!target) {
|
|
3239
3350
|
let i = 1;
|
|
3240
3351
|
const base = dir;
|
|
3241
|
-
while (
|
|
3352
|
+
while (fs3.existsSync(dir)) dir = `${base}-${i++}`;
|
|
3242
3353
|
}
|
|
3243
|
-
|
|
3354
|
+
fs3.mkdirSync(dir, { recursive: true });
|
|
3244
3355
|
const resp = await fetch(details.downloadUrl);
|
|
3245
3356
|
if (!resp.ok) throw new Error(`bundle download -> ${resp.status}`);
|
|
3246
3357
|
const bundle = Buffer.from(await resp.arrayBuffer());
|
|
@@ -3270,12 +3381,12 @@ async function propose(dir, opts) {
|
|
|
3270
3381
|
const state2 = localTreeState(dir);
|
|
3271
3382
|
if (state2.clean) throw new Error("Nothing to propose \u2014 the tree matches its base.");
|
|
3272
3383
|
const changes = state2.dirty.map((relPath) => {
|
|
3273
|
-
const abs =
|
|
3274
|
-
if (!
|
|
3384
|
+
const abs = path3.join(dir, relPath);
|
|
3385
|
+
if (!fs3.existsSync(abs)) return { path: relPath, action: "delete" };
|
|
3275
3386
|
return {
|
|
3276
3387
|
path: relPath,
|
|
3277
3388
|
action: "write",
|
|
3278
|
-
newContent:
|
|
3389
|
+
newContent: fs3.readFileSync(abs, "utf-8")
|
|
3279
3390
|
};
|
|
3280
3391
|
});
|
|
3281
3392
|
const res = await apiRequest(
|
|
@@ -3301,13 +3412,14 @@ async function createRef(slug, name, kind, versionId, options = {}) {
|
|
|
3301
3412
|
...versionId ? { versionId } : {}
|
|
3302
3413
|
});
|
|
3303
3414
|
}
|
|
3304
|
-
var DEFAULT_BRANCH, META_RELPATH, SKIP_DIRS,
|
|
3415
|
+
var DEFAULT_BRANCH, META_RELPATH, SKIP_DIRS, sha256b64;
|
|
3305
3416
|
var init_hub = __esm({
|
|
3306
3417
|
"src/worlds/hub.ts"() {
|
|
3307
3418
|
"use strict";
|
|
3308
3419
|
init_worlds();
|
|
3420
|
+
init_worldDir();
|
|
3309
3421
|
DEFAULT_BRANCH = "main";
|
|
3310
|
-
META_RELPATH =
|
|
3422
|
+
META_RELPATH = path3.join(".gateway", ".env-metadata.json");
|
|
3311
3423
|
SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
3312
3424
|
".git",
|
|
3313
3425
|
"__pycache__",
|
|
@@ -3318,9 +3430,7 @@ var init_hub = __esm({
|
|
|
3318
3430
|
"build",
|
|
3319
3431
|
"outputs"
|
|
3320
3432
|
]);
|
|
3321
|
-
|
|
3322
|
-
BROAD_ROOT_MARKERS = ["gateway-env.toml", "gateway-api-world.toml"];
|
|
3323
|
-
sha256b64 = (data) => createHash2("sha256").update(data).digest("base64");
|
|
3433
|
+
sha256b64 = (data) => createHash3("sha256").update(data).digest("base64");
|
|
3324
3434
|
}
|
|
3325
3435
|
});
|
|
3326
3436
|
|
|
@@ -3819,7 +3929,7 @@ var init_json = __esm({
|
|
|
3819
3929
|
});
|
|
3820
3930
|
|
|
3821
3931
|
// src/worlds/transforms.ts
|
|
3822
|
-
import { createHash as
|
|
3932
|
+
import { createHash as createHash4 } from "crypto";
|
|
3823
3933
|
function parseTransform(name) {
|
|
3824
3934
|
const simple = Object.prototype.hasOwnProperty.call(SIMPLE, name) ? SIMPLE[name] : void 0;
|
|
3825
3935
|
if (simple) return simple;
|
|
@@ -3843,8 +3953,8 @@ var init_transforms = __esm({
|
|
|
3843
3953
|
"use strict";
|
|
3844
3954
|
init_json();
|
|
3845
3955
|
WHITESPACE = " \n\r\f\v";
|
|
3846
|
-
WHITESPACE_EDGES =
|
|
3847
|
-
WHITESPACE_RUN =
|
|
3956
|
+
WHITESPACE_EDGES = new RegExp(`^[${WHITESPACE}]+|[${WHITESPACE}]+$`, "g");
|
|
3957
|
+
WHITESPACE_RUN = new RegExp(`[${WHITESPACE}]+`, "g");
|
|
3848
3958
|
NOT_DIGIT = /[^0-9]/g;
|
|
3849
3959
|
STRIP_PREFIX = "strip_prefix";
|
|
3850
3960
|
trim = (value) => value.replace(WHITESPACE_EDGES, "");
|
|
@@ -3857,7 +3967,7 @@ var init_transforms = __esm({
|
|
|
3857
3967
|
return at === -1 ? "" : value.slice(at + 1).toLowerCase();
|
|
3858
3968
|
};
|
|
3859
3969
|
stripPrefix = (prefix) => (value) => value.startsWith(prefix) ? value.slice(prefix.length) : value;
|
|
3860
|
-
hex = (algorithm, value) =>
|
|
3970
|
+
hex = (algorithm, value) => createHash4(algorithm).update(value, "utf8").digest("hex");
|
|
3861
3971
|
SIMPLE = {
|
|
3862
3972
|
lower: (value) => value.toLowerCase(),
|
|
3863
3973
|
upper: (value) => value.toUpperCase(),
|
|
@@ -3881,7 +3991,7 @@ var init_transforms = __esm({
|
|
|
3881
3991
|
});
|
|
3882
3992
|
|
|
3883
3993
|
// src/worlds/redaction.ts
|
|
3884
|
-
import { createHash as
|
|
3994
|
+
import { createHash as createHash5 } from "crypto";
|
|
3885
3995
|
function pyText(value) {
|
|
3886
3996
|
if (typeof value === "string") return value;
|
|
3887
3997
|
if (Number.isInteger(value)) return String(value);
|
|
@@ -3890,7 +4000,7 @@ function pyText(value) {
|
|
|
3890
4000
|
return pyFloatRepr(value);
|
|
3891
4001
|
}
|
|
3892
4002
|
function hashForm(slug, plaintext) {
|
|
3893
|
-
return "sha256:" +
|
|
4003
|
+
return "sha256:" + createHash5("sha256").update(`${slug}:${pyText(plaintext)}`, "utf8").digest("hex");
|
|
3894
4004
|
}
|
|
3895
4005
|
function preserveForm(slug, plaintext) {
|
|
3896
4006
|
const kind = typeof plaintext === "string" ? "str" : isInt(plaintext) ? "int" : "float";
|
|
@@ -3899,12 +4009,12 @@ function preserveForm(slug, plaintext) {
|
|
|
3899
4009
|
}
|
|
3900
4010
|
function shapeText(slug, text2, kind) {
|
|
3901
4011
|
const seed = Buffer.from(`${slug}:${text2}`, "utf8");
|
|
3902
|
-
let digest =
|
|
4012
|
+
let digest = createHash5("sha256").update(seed).digest();
|
|
3903
4013
|
let cursor = 0;
|
|
3904
4014
|
const out = [];
|
|
3905
4015
|
for (const char of text2) {
|
|
3906
4016
|
if (cursor === digest.length) {
|
|
3907
|
-
digest =
|
|
4017
|
+
digest = createHash5("sha256").update(Buffer.concat([digest, seed])).digest();
|
|
3908
4018
|
cursor = 0;
|
|
3909
4019
|
}
|
|
3910
4020
|
const byte = digest[cursor];
|
|
@@ -3952,8 +4062,9 @@ var init_redaction = __esm({
|
|
|
3952
4062
|
});
|
|
3953
4063
|
|
|
3954
4064
|
// src/worlds/query.ts
|
|
3955
|
-
function queryRowsSearch(entity, opts = {}) {
|
|
4065
|
+
function queryRowsSearch(entity, opts = {}, ref) {
|
|
3956
4066
|
const search = new URLSearchParams();
|
|
4067
|
+
if (ref) search.set("ref", ref);
|
|
3957
4068
|
search.set("entity", entity);
|
|
3958
4069
|
if (opts.where && Object.keys(opts.where).length) search.set("where", JSON.stringify(opts.where));
|
|
3959
4070
|
if (opts.limit !== void 0) search.set("limit", String(opts.limit));
|
|
@@ -3963,17 +4074,15 @@ function queryRowsSearch(entity, opts = {}) {
|
|
|
3963
4074
|
if (opts.compare) search.set("compare", "true");
|
|
3964
4075
|
return `?${search.toString()}`;
|
|
3965
4076
|
}
|
|
3966
|
-
async function queryRows(
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
`queryRows reads a world's head version: pass the slug without @ref (got ${slug})`
|
|
3970
|
-
);
|
|
4077
|
+
async function queryRows(slugRef, entity, opts = {}, options = {}) {
|
|
4078
|
+
const [slug, ref] = slugRef.split("@", 2);
|
|
4079
|
+
if (!slug || ref === "") throw new Error(`queryRows needs a slug, optionally slug@ref (got ${slugRef})`);
|
|
3971
4080
|
if (!entity) throw new Error("queryRows needs an entity");
|
|
3972
4081
|
if (opts.compare && !opts.across) throw new Error("queryRows: compare needs across");
|
|
3973
4082
|
return apiRequest(
|
|
3974
4083
|
options,
|
|
3975
4084
|
"GET",
|
|
3976
|
-
`/api/public/worlds/${encodeURIComponent(slug)}/data${queryRowsSearch(entity, opts)}`
|
|
4085
|
+
`/api/public/worlds/${encodeURIComponent(slug)}/data${queryRowsSearch(entity, opts, ref)}`
|
|
3977
4086
|
);
|
|
3978
4087
|
}
|
|
3979
4088
|
var init_query = __esm({
|
|
@@ -4029,9 +4138,9 @@ var init_router = __esm({
|
|
|
4029
4138
|
});
|
|
4030
4139
|
|
|
4031
4140
|
// src/cli/config.ts
|
|
4032
|
-
import * as
|
|
4141
|
+
import * as fs4 from "fs";
|
|
4033
4142
|
import * as os from "os";
|
|
4034
|
-
import * as
|
|
4143
|
+
import * as path4 from "path";
|
|
4035
4144
|
async function api(creds, method, route, body, init2 = {}) {
|
|
4036
4145
|
const controller = new AbortController();
|
|
4037
4146
|
const timer = setTimeout(() => controller.abort(), init2.timeoutMs ?? 12e4);
|
|
@@ -4072,9 +4181,9 @@ var init_config = __esm({
|
|
|
4072
4181
|
|
|
4073
4182
|
// src/cli/runtime/local.ts
|
|
4074
4183
|
import { spawn, spawnSync } from "child_process";
|
|
4075
|
-
import * as
|
|
4184
|
+
import * as fs5 from "fs";
|
|
4076
4185
|
import * as net from "net";
|
|
4077
|
-
import * as
|
|
4186
|
+
import * as path5 from "path";
|
|
4078
4187
|
function tailOf(output) {
|
|
4079
4188
|
return output.length > DIAGNOSTIC_TAIL ? `\u2026${output.slice(-DIAGNOSTIC_TAIL)}` : output;
|
|
4080
4189
|
}
|
|
@@ -4089,16 +4198,16 @@ function runtimeRoot() {
|
|
|
4089
4198
|
const candidates = [];
|
|
4090
4199
|
if (process.env.GATEWAY_RUNTIME_PATH)
|
|
4091
4200
|
candidates.push(process.env.GATEWAY_RUNTIME_PATH);
|
|
4092
|
-
const entry = process.argv[1] &&
|
|
4201
|
+
const entry = process.argv[1] && fs5.existsSync(process.argv[1]) ? path5.dirname(fs5.realpathSync(process.argv[1])) : null;
|
|
4093
4202
|
if (entry) {
|
|
4094
|
-
candidates.push(
|
|
4095
|
-
candidates.push(
|
|
4096
|
-
candidates.push(
|
|
4203
|
+
candidates.push(path5.resolve(entry, "..", "runtime"));
|
|
4204
|
+
candidates.push(path5.resolve(entry, "..", "..", "runtime"));
|
|
4205
|
+
candidates.push(path5.resolve(entry, "..", "..", "sdk", "src"));
|
|
4097
4206
|
}
|
|
4098
|
-
candidates.push(
|
|
4207
|
+
candidates.push(path5.resolve(process.cwd(), "runtime"));
|
|
4099
4208
|
for (const root of candidates)
|
|
4100
|
-
if (
|
|
4101
|
-
|
|
4209
|
+
if (fs5.existsSync(
|
|
4210
|
+
path5.join(root, "gatewaysdk", "environment", "schema", "platform.py")
|
|
4102
4211
|
))
|
|
4103
4212
|
return root;
|
|
4104
4213
|
return null;
|
|
@@ -4266,18 +4375,18 @@ runpy.run_module('gatewaysdk.environment.schema.platform',run_name='__main__')`;
|
|
|
4266
4375
|
});
|
|
4267
4376
|
|
|
4268
4377
|
// src/cli/runtime/client.ts
|
|
4269
|
-
import * as
|
|
4270
|
-
import * as
|
|
4378
|
+
import * as fs6 from "fs";
|
|
4379
|
+
import * as path6 from "path";
|
|
4271
4380
|
function isBuildOutput(relPath) {
|
|
4272
4381
|
return BUILD_OUTPUT.test(relPath);
|
|
4273
4382
|
}
|
|
4274
4383
|
function readWorldFiles(dir, opts = {}) {
|
|
4275
|
-
if (!
|
|
4384
|
+
if (!fs6.existsSync(dir) || !fs6.statSync(dir).isDirectory())
|
|
4276
4385
|
throw new CliError(`Not a directory: ${dir}`);
|
|
4277
4386
|
const out = [];
|
|
4278
4387
|
const walk = (rel) => {
|
|
4279
|
-
const abs = rel ?
|
|
4280
|
-
const entries =
|
|
4388
|
+
const abs = rel ? path6.join(dir, rel) : dir;
|
|
4389
|
+
const entries = fs6.readdirSync(abs, { withFileTypes: true });
|
|
4281
4390
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
4282
4391
|
for (const entry of entries) {
|
|
4283
4392
|
const childRel = rel ? `${rel}/${entry.name}` : entry.name;
|
|
@@ -4287,7 +4396,7 @@ function readWorldFiles(dir, opts = {}) {
|
|
|
4287
4396
|
if (!opts.buildOutputs && isBuildOutput(childRel)) continue;
|
|
4288
4397
|
out.push({
|
|
4289
4398
|
path: childRel,
|
|
4290
|
-
content:
|
|
4399
|
+
content: fs6.readFileSync(path6.join(dir, childRel)).toString("base64")
|
|
4291
4400
|
});
|
|
4292
4401
|
}
|
|
4293
4402
|
}
|
|
@@ -4302,19 +4411,19 @@ function assertSafeRelPath(rel) {
|
|
|
4302
4411
|
}
|
|
4303
4412
|
function writeWorldFiles(dir, files, opts = {}) {
|
|
4304
4413
|
for (const file of files) assertSafeRelPath(file.path);
|
|
4305
|
-
if (opts.clean &&
|
|
4414
|
+
if (opts.clean && fs6.existsSync(dir)) {
|
|
4306
4415
|
const keep = new Set(files.map((f) => f.path));
|
|
4307
4416
|
for (const existing of readWorldFiles(dir)) {
|
|
4308
|
-
if (!keep.has(existing.path))
|
|
4417
|
+
if (!keep.has(existing.path)) fs6.rmSync(path6.join(dir, existing.path));
|
|
4309
4418
|
}
|
|
4310
4419
|
pruneEmptyDirs(dir);
|
|
4311
4420
|
}
|
|
4312
|
-
|
|
4421
|
+
fs6.mkdirSync(dir, { recursive: true });
|
|
4313
4422
|
const written = [];
|
|
4314
4423
|
for (const file of files) {
|
|
4315
|
-
const target =
|
|
4316
|
-
|
|
4317
|
-
|
|
4424
|
+
const target = path6.join(dir, file.path);
|
|
4425
|
+
fs6.mkdirSync(path6.dirname(target), { recursive: true });
|
|
4426
|
+
fs6.writeFileSync(target, Buffer.from(file.content, "base64"));
|
|
4318
4427
|
written.push(file.path);
|
|
4319
4428
|
}
|
|
4320
4429
|
return written;
|
|
@@ -4322,14 +4431,14 @@ function writeWorldFiles(dir, files, opts = {}) {
|
|
|
4322
4431
|
function pruneEmptyDirs(root) {
|
|
4323
4432
|
const walk = (abs) => {
|
|
4324
4433
|
let empty = true;
|
|
4325
|
-
for (const entry of
|
|
4326
|
-
const child =
|
|
4434
|
+
for (const entry of fs6.readdirSync(abs, { withFileTypes: true })) {
|
|
4435
|
+
const child = path6.join(abs, entry.name);
|
|
4327
4436
|
if (entry.isDirectory()) {
|
|
4328
4437
|
if (SKIP_DIRS2.has(entry.name)) {
|
|
4329
4438
|
empty = false;
|
|
4330
4439
|
continue;
|
|
4331
4440
|
}
|
|
4332
|
-
if (walk(child))
|
|
4441
|
+
if (walk(child)) fs6.rmdirSync(child);
|
|
4333
4442
|
else empty = false;
|
|
4334
4443
|
} else empty = false;
|
|
4335
4444
|
}
|
|
@@ -4421,8 +4530,8 @@ __export(data_exports, {
|
|
|
4421
4530
|
queryLocalWorldDataAcross: () => queryLocalWorldDataAcross,
|
|
4422
4531
|
showLocalWorldData: () => showLocalWorldData
|
|
4423
4532
|
});
|
|
4424
|
-
import * as
|
|
4425
|
-
import * as
|
|
4533
|
+
import * as fs7 from "fs";
|
|
4534
|
+
import * as path7 from "path";
|
|
4426
4535
|
async function importLocalWorldData(dir, rows, opts, creds) {
|
|
4427
4536
|
const res = await runtime(creds, {
|
|
4428
4537
|
command: "import-data",
|
|
@@ -4448,7 +4557,7 @@ function dropBuildOutputs(dir) {
|
|
|
4448
4557
|
const dropped = [];
|
|
4449
4558
|
for (const file of readWorldFiles(dir, { buildOutputs: true })) {
|
|
4450
4559
|
if (!BUILD_OUTPUT2.test(file.path)) continue;
|
|
4451
|
-
|
|
4560
|
+
fs7.rmSync(path7.join(dir, file.path), { force: true });
|
|
4452
4561
|
dropped.push(file.path);
|
|
4453
4562
|
}
|
|
4454
4563
|
return dropped;
|
|
@@ -4459,6 +4568,7 @@ async function checkLocalWorldData(dir, rows, creds, opts = {}) {
|
|
|
4459
4568
|
files: readWorldFiles(dir),
|
|
4460
4569
|
rows,
|
|
4461
4570
|
mode: "append",
|
|
4571
|
+
dry_run: true,
|
|
4462
4572
|
...opts.redact && opts.redact !== "off" ? { redact: opts.redact } : {}
|
|
4463
4573
|
});
|
|
4464
4574
|
return {
|
|
@@ -4514,7 +4624,7 @@ async function queryLocalWorldDataAcross(dir, entity, where, opts) {
|
|
|
4514
4624
|
const payload = await localBridge(
|
|
4515
4625
|
{
|
|
4516
4626
|
command: "query",
|
|
4517
|
-
world:
|
|
4627
|
+
world: path7.resolve(dir),
|
|
4518
4628
|
entity,
|
|
4519
4629
|
across: true,
|
|
4520
4630
|
...opts.compare ? { compare: true } : {},
|
|
@@ -4585,9 +4695,9 @@ __export(transform_exports, {
|
|
|
4585
4695
|
transformRecords: () => transformRecords
|
|
4586
4696
|
});
|
|
4587
4697
|
import { spawn as spawn2 } from "child_process";
|
|
4588
|
-
import * as
|
|
4698
|
+
import * as fs8 from "fs";
|
|
4589
4699
|
import * as os2 from "os";
|
|
4590
|
-
import * as
|
|
4700
|
+
import * as path8 from "path";
|
|
4591
4701
|
import { createRequire } from "module";
|
|
4592
4702
|
function checkRows(value, where) {
|
|
4593
4703
|
if (!isObject(value)) throw new CliError(`${where} must return {entity: [rows]}; got ${value === null ? "null" : Array.isArray(value) ? "an array" : typeof value}`, 1);
|
|
@@ -4612,27 +4722,27 @@ function typescriptPrefix() {
|
|
|
4612
4722
|
}
|
|
4613
4723
|
}
|
|
4614
4724
|
function command(script, wrapperDir) {
|
|
4615
|
-
const suffix =
|
|
4725
|
+
const suffix = path8.extname(script).toLowerCase();
|
|
4616
4726
|
if (PYTHON_SUFFIXES.includes(suffix)) return { file: process.env.GATEWAY_PYTHON || "python3", args: ["-c", PY_WRAPPER, script] };
|
|
4617
4727
|
if (NODE_SUFFIXES.includes(suffix)) {
|
|
4618
|
-
const wrapper =
|
|
4619
|
-
|
|
4728
|
+
const wrapper = path8.join(wrapperDir, "transform-wrapper.mjs");
|
|
4729
|
+
fs8.writeFileSync(wrapper, NODE_WRAPPER);
|
|
4620
4730
|
const flags = suffix === ".ts" || suffix === ".mts" ? typescriptPrefix() : [];
|
|
4621
4731
|
return { file: process.env.GATEWAY_NODE || process.execPath, args: [...flags, wrapper, script] };
|
|
4622
4732
|
}
|
|
4623
|
-
throw new CliError(`${
|
|
4733
|
+
throw new CliError(`${path8.basename(script)}: a transform script is .py, .ts, .mjs, .js or .cjs`, 1);
|
|
4624
4734
|
}
|
|
4625
4735
|
async function runTransform(script, records, opts = {}) {
|
|
4626
|
-
if (!
|
|
4627
|
-
const resolved =
|
|
4628
|
-
const name =
|
|
4736
|
+
if (!fs8.existsSync(script) || !fs8.statSync(script).isFile()) throw new CliError(`no transform script at ${script}`, 1);
|
|
4737
|
+
const resolved = path8.resolve(script);
|
|
4738
|
+
const name = path8.basename(script);
|
|
4629
4739
|
const timeoutMs = opts.timeoutMs ?? DEFAULT_TRANSFORM_TIMEOUT_MS;
|
|
4630
|
-
const scratch =
|
|
4740
|
+
const scratch = fs8.mkdtempSync(path8.join(os2.tmpdir(), "gateway-transform-"));
|
|
4631
4741
|
try {
|
|
4632
4742
|
const { file, args } = command(resolved, scratch);
|
|
4633
4743
|
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !SCRUBBED.test(key)));
|
|
4634
4744
|
const done = await new Promise((resolve6, reject) => {
|
|
4635
|
-
const child = spawn2(file, args, { cwd:
|
|
4745
|
+
const child = spawn2(file, args, { cwd: path8.dirname(resolved), env, stdio: ["pipe", "pipe", "pipe"] });
|
|
4636
4746
|
let stdout = "";
|
|
4637
4747
|
let stderr = "";
|
|
4638
4748
|
let timedOut = false;
|
|
@@ -4663,7 +4773,7 @@ async function runTransform(script, records, opts = {}) {
|
|
|
4663
4773
|
}
|
|
4664
4774
|
return { rows: checkRows(value, name), stderr: done.stderr };
|
|
4665
4775
|
} finally {
|
|
4666
|
-
|
|
4776
|
+
fs8.rmSync(scratch, { recursive: true, force: true });
|
|
4667
4777
|
}
|
|
4668
4778
|
}
|
|
4669
4779
|
async function transformRecords(transform, records, opts = {}) {
|
|
@@ -4755,13 +4865,18 @@ if (fn) {
|
|
|
4755
4865
|
});
|
|
4756
4866
|
|
|
4757
4867
|
// src/cli/platform/worldData/batches.ts
|
|
4758
|
-
import { createHash as
|
|
4759
|
-
import * as
|
|
4868
|
+
import { createHash as createHash6 } from "crypto";
|
|
4869
|
+
import * as fs9 from "fs";
|
|
4870
|
+
function isSettled(status) {
|
|
4871
|
+
if (!TERMINAL_STATES.has(status.state)) return false;
|
|
4872
|
+
if (status.state !== "applied") return true;
|
|
4873
|
+
return status.dryRun === true || status.publish !== "now" || !status.snapshotId;
|
|
4874
|
+
}
|
|
4760
4875
|
function uploadHeadersFor(gz) {
|
|
4761
4876
|
return {
|
|
4762
4877
|
"content-type": "application/gzip",
|
|
4763
4878
|
"content-length": String(gz.length),
|
|
4764
|
-
"x-amz-checksum-sha256":
|
|
4879
|
+
"x-amz-checksum-sha256": createHash6("sha256").update(gz).digest("base64")
|
|
4765
4880
|
};
|
|
4766
4881
|
}
|
|
4767
4882
|
async function forEachLimited(items, limit, fn) {
|
|
@@ -4798,7 +4913,7 @@ async function waitForBatch(client, batchId, opts = {}) {
|
|
|
4798
4913
|
opts.onPhase?.(phase);
|
|
4799
4914
|
last = phase;
|
|
4800
4915
|
}
|
|
4801
|
-
if (
|
|
4916
|
+
if (isSettled(status)) return status;
|
|
4802
4917
|
await sleep2(delay);
|
|
4803
4918
|
delay = Math.min(1e4, Math.round(delay * 1.5));
|
|
4804
4919
|
}
|
|
@@ -4888,7 +5003,7 @@ var init_batches = __esm({
|
|
|
4888
5003
|
});
|
|
4889
5004
|
|
|
4890
5005
|
// src/cli/platform/worldData/chunker.ts
|
|
4891
|
-
import { createHash as
|
|
5006
|
+
import { createHash as createHash7 } from "crypto";
|
|
4892
5007
|
import { deflateRawSync } from "zlib";
|
|
4893
5008
|
function chunkLine(row, declared) {
|
|
4894
5009
|
if (declared !== null) return dumps(row.row) + "\n";
|
|
@@ -4923,12 +5038,12 @@ function finishChunk(ordinal, raw, rows, entity, firstRow = 0) {
|
|
|
4923
5038
|
const gz = gzipDeterministic(raw, { name: chunkName(ordinal) });
|
|
4924
5039
|
return {
|
|
4925
5040
|
ordinal,
|
|
4926
|
-
digest:
|
|
5041
|
+
digest: createHash7("sha256").update(gz).digest("hex"),
|
|
4927
5042
|
bytes: gz.length,
|
|
4928
5043
|
rows,
|
|
4929
5044
|
entity,
|
|
4930
5045
|
rawBytes: raw.length,
|
|
4931
|
-
contentSha256:
|
|
5046
|
+
contentSha256: createHash7("sha256").update(raw).digest("hex"),
|
|
4932
5047
|
firstRow,
|
|
4933
5048
|
gz
|
|
4934
5049
|
};
|
|
@@ -5011,9 +5126,9 @@ var init_push = __esm({
|
|
|
5011
5126
|
});
|
|
5012
5127
|
|
|
5013
5128
|
// src/worlds/ingest.ts
|
|
5014
|
-
import * as
|
|
5129
|
+
import * as fs10 from "fs";
|
|
5015
5130
|
import * as os3 from "os";
|
|
5016
|
-
import * as
|
|
5131
|
+
import * as path9 from "path";
|
|
5017
5132
|
function parseToolCallRecord(raw) {
|
|
5018
5133
|
const none = { record: null, skip: null };
|
|
5019
5134
|
if (!isObject2(raw)) return { ...none, refusal: "record is not an object" };
|
|
@@ -5034,7 +5149,7 @@ function parseToolCallRecord(raw) {
|
|
|
5034
5149
|
}
|
|
5035
5150
|
function readToolCallRecords(paths) {
|
|
5036
5151
|
const records = [];
|
|
5037
|
-
for (const file of paths) records.push(...toolCallRecordsIn(
|
|
5152
|
+
for (const file of paths) records.push(...toolCallRecordsIn(fs10.readFileSync(file, "utf8"), file));
|
|
5038
5153
|
return records;
|
|
5039
5154
|
}
|
|
5040
5155
|
function toolCallRecordsIn(text2, where) {
|
|
@@ -5070,7 +5185,7 @@ async function emit(sink, record) {
|
|
|
5070
5185
|
return;
|
|
5071
5186
|
}
|
|
5072
5187
|
if (typeof sink === "string") {
|
|
5073
|
-
|
|
5188
|
+
fs10.appendFileSync(sink, JSON.stringify(record) + "\n");
|
|
5074
5189
|
return;
|
|
5075
5190
|
}
|
|
5076
5191
|
if (typeof sink === "function") {
|
|
@@ -5101,14 +5216,6 @@ function captureToolCalls(tools, sink, opts = {}) {
|
|
|
5101
5216
|
}
|
|
5102
5217
|
return wrapped;
|
|
5103
5218
|
}
|
|
5104
|
-
function jsonish(value) {
|
|
5105
|
-
if (typeof value !== "string") return value;
|
|
5106
|
-
try {
|
|
5107
|
-
return JSON.parse(value);
|
|
5108
|
-
} catch {
|
|
5109
|
-
return value;
|
|
5110
|
-
}
|
|
5111
|
-
}
|
|
5112
5219
|
function toolCallsFromObservations(observations, opts = {}) {
|
|
5113
5220
|
const known = opts.tools ? new Set(opts.tools) : null;
|
|
5114
5221
|
const sinceMs = opts.since ? Date.parse(opts.since) : NaN;
|
|
@@ -5135,10 +5242,9 @@ function toolCallsFromObservations(observations, opts = {}) {
|
|
|
5135
5242
|
out.unknownTools[tool] = (out.unknownTools[tool] ?? 0) + 1;
|
|
5136
5243
|
continue;
|
|
5137
5244
|
}
|
|
5138
|
-
const
|
|
5139
|
-
const record = { tool, args: isObject2(input) ? input : {} };
|
|
5245
|
+
const record = { tool, args: isObject2(observation.input) ? observation.input : {} };
|
|
5140
5246
|
if (observation.level === "ERROR") record.error = observation.statusMessage || "ERROR";
|
|
5141
|
-
else record.result =
|
|
5247
|
+
else record.result = observation.output;
|
|
5142
5248
|
if (at !== void 0) record.at = at;
|
|
5143
5249
|
if (opts.session) record.session = opts.session;
|
|
5144
5250
|
record.source = `trace:${observation.traceId ?? "?"}/${observation.id ?? "?"}`;
|
|
@@ -5159,7 +5265,7 @@ async function ingest(world, records, options = {}) {
|
|
|
5159
5265
|
const mode = options.mode ?? "append";
|
|
5160
5266
|
const dryRun = Boolean(options.dryRun);
|
|
5161
5267
|
const creds = credentialsOf(options);
|
|
5162
|
-
const local =
|
|
5268
|
+
const local = fs10.existsSync(world) && fs10.statSync(world).isDirectory();
|
|
5163
5269
|
const map = options.map === void 0 ? void 0 : options.map;
|
|
5164
5270
|
let rows = null;
|
|
5165
5271
|
let stderr = "";
|
|
@@ -5175,9 +5281,9 @@ async function ingest(world, records, options = {}) {
|
|
|
5175
5281
|
if (!creds) throw new Error("Gateway keys missing: set GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY (or pass publicKey/secretKey).");
|
|
5176
5282
|
const { pull: pull2 } = await Promise.resolve().then(() => (init_hub(), hub_exports));
|
|
5177
5283
|
const slug = world.split("@", 1)[0];
|
|
5178
|
-
const scratch =
|
|
5284
|
+
const scratch = fs10.mkdtempSync(path9.join(os3.tmpdir(), "gateway-ingest-"));
|
|
5179
5285
|
try {
|
|
5180
|
-
const pulled = await pull2(world,
|
|
5286
|
+
const pulled = await pull2(world, path9.join(scratch, slug), options);
|
|
5181
5287
|
let report;
|
|
5182
5288
|
let projected;
|
|
5183
5289
|
if (rows === null) {
|
|
@@ -5198,7 +5304,7 @@ async function ingest(world, records, options = {}) {
|
|
|
5198
5304
|
if (status.entityCounts) report.entityCounts = status.entityCounts;
|
|
5199
5305
|
return report;
|
|
5200
5306
|
} finally {
|
|
5201
|
-
|
|
5307
|
+
fs10.rmSync(scratch, { recursive: true, force: true });
|
|
5202
5308
|
}
|
|
5203
5309
|
}
|
|
5204
5310
|
async function ingestToolCalls(world, records, options = {}) {
|
|
@@ -5308,7 +5414,6 @@ __export(worlds_exports, {
|
|
|
5308
5414
|
hashForm: () => hashForm,
|
|
5309
5415
|
ingest: () => ingest,
|
|
5310
5416
|
ingestToolCalls: () => ingestToolCalls,
|
|
5311
|
-
isIncludedInContentHash: () => isIncludedInContentHash,
|
|
5312
5417
|
isTaskIdRef: () => isTaskIdRef,
|
|
5313
5418
|
isTaskManifest: () => isTaskManifest,
|
|
5314
5419
|
isTaskSpec: () => isTaskSpec,
|
|
@@ -5374,9 +5479,9 @@ function resolveEnv(options) {
|
|
|
5374
5479
|
}
|
|
5375
5480
|
return { host: host.replace(/\/+$/, ""), publicKey, secretKey };
|
|
5376
5481
|
}
|
|
5377
|
-
async function apiRequest(options, method,
|
|
5482
|
+
async function apiRequest(options, method, path10, body) {
|
|
5378
5483
|
const { host, publicKey, secretKey } = resolveEnv(options);
|
|
5379
|
-
const res = await fetch(`${host}${
|
|
5484
|
+
const res = await fetch(`${host}${path10}`, {
|
|
5380
5485
|
method,
|
|
5381
5486
|
headers: {
|
|
5382
5487
|
"content-type": "application/json",
|
|
@@ -5385,7 +5490,7 @@ async function apiRequest(options, method, path9, body) {
|
|
|
5385
5490
|
...body === void 0 ? {} : { body: JSON.stringify(body) }
|
|
5386
5491
|
});
|
|
5387
5492
|
const text2 = await res.text();
|
|
5388
|
-
if (!res.ok) throw new ApiError2(res.status, method,
|
|
5493
|
+
if (!res.ok) throw new ApiError2(res.status, method, path10, text2.slice(0, 400));
|
|
5389
5494
|
return JSON.parse(text2);
|
|
5390
5495
|
}
|
|
5391
5496
|
async function setEnvSecret(slug, key, value, options = {}) {
|
|
@@ -5555,8 +5660,8 @@ var init_worlds = __esm({
|
|
|
5555
5660
|
init_migrate();
|
|
5556
5661
|
init_ingest();
|
|
5557
5662
|
ApiError2 = class extends Error {
|
|
5558
|
-
constructor(status, method,
|
|
5559
|
-
super(`${method} ${
|
|
5663
|
+
constructor(status, method, path10, body) {
|
|
5664
|
+
super(`${method} ${path10} -> ${status}: ${body}`);
|
|
5560
5665
|
this.status = status;
|
|
5561
5666
|
this.name = "ApiError";
|
|
5562
5667
|
}
|
|
@@ -5671,7 +5776,6 @@ export {
|
|
|
5671
5776
|
hashForm,
|
|
5672
5777
|
ingest,
|
|
5673
5778
|
ingestToolCalls,
|
|
5674
|
-
isIncludedInContentHash,
|
|
5675
5779
|
isTaskIdRef,
|
|
5676
5780
|
isTaskManifest,
|
|
5677
5781
|
isTaskSpec,
|