@withgateway/sdk 0.9.1 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/index.d.mts +12 -4
- package/dist/agents/index.d.ts +12 -4
- package/dist/agents/index.js +30 -0
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/index.mjs +30 -0
- package/dist/agents/index.mjs.map +1 -1
- package/dist/cli.js +2291 -945
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +2290 -944
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs.map +1 -1
- package/dist/index.js +325 -184
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +324 -183
- package/dist/index.mjs.map +1 -1
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.js +1 -1
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +1 -1
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/worlds/index.d.mts +3 -1
- package/dist/worlds/index.d.ts +3 -1
- package/dist/worlds/index.js +178 -67
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +177 -66
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +1 -1
- package/runtime/gatewaysdk/environment/bundle_manifest.py +297 -9
- package/runtime/gatewaysdk/environment/factory_documents.py +670 -0
- package/runtime/gatewaysdk/environment/factory_rules.py +973 -0
- package/runtime/gatewaysdk/environment/factory_shapes.py +253 -0
- package/runtime/gatewaysdk/environment/factory_spine.py +1155 -0
- package/runtime/gatewaysdk/environment/factory_spine_shapes.py +480 -0
- package/runtime/gatewaysdk/environment/schema/admission.py +61 -59
- package/runtime/gatewaysdk/environment/schema/cast.py +133 -67
- package/runtime/gatewaysdk/environment/schema/compiler.py +16 -17
- package/runtime/gatewaysdk/environment/schema/handler_errors.py +58 -4
- package/runtime/gatewaysdk/environment/schema/host.py +21 -2
- package/runtime/gatewaysdk/environment/schema/host_control.py +3 -1
- package/runtime/gatewaysdk/environment/schema/host_loops.py +27 -4
- package/runtime/gatewaysdk/environment/schema/host_metrics.py +69 -0
- package/runtime/gatewaysdk/environment/schema/host_requests.py +21 -0
- package/runtime/gatewaysdk/environment/schema/host_session.py +7 -0
- package/runtime/gatewaysdk/environment/schema/host_versions.py +4 -0
- package/runtime/gatewaysdk/environment/schema/host_workers.py +172 -50
- package/runtime/gatewaysdk/environment/schema/ingest.py +12 -3
- package/runtime/gatewaysdk/environment/schema/mapping.py +1 -1
- package/runtime/gatewaysdk/environment/schema/measured_tests.py +187 -0
- package/runtime/gatewaysdk/environment/schema/platform.py +57 -3
- package/runtime/gatewaysdk/environment/schema/platform_query.py +4 -3
- package/runtime/gatewaysdk/environment/schema/platform_templates.py +105 -17
- package/runtime/gatewaysdk/environment/schema/process_memory.py +76 -0
- package/runtime/gatewaysdk/environment/schema/redaction.py +13 -0
- package/runtime/gatewaysdk/environment/schema/runtime.py +14 -0
- package/runtime/gatewaysdk/environment/schema/scaffold.py +21 -4
- package/runtime/gatewaysdk/environment/schema/shape_catalog.py +493 -0
- package/runtime/gatewaysdk/environment/schema/shape_declarations.py +219 -0
- package/runtime/gatewaysdk/environment/schema/skill.py +1 -0
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +1 -0
- package/runtime/gatewaysdk/environment/schema/skills/factory-orchestrator/SKILL.md +147 -0
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/ROWS.md +5 -1
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +4 -4
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +2 -2
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +1 -0
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/shape-catalog.md +59 -0
- package/runtime/gatewaysdk/environment/schema/validation.py +14 -0
- package/runtime/gatewaysdk/environment/schema/worker.py +7 -4
- package/runtime/gatewaysdk/environment/schema/worker_key.py +38 -0
- package/runtime/gatewaysdk/environment/schema/worker_peaks.py +38 -0
- package/runtime/gatewaysdk/environment/schema/worker_watch.py +50 -0
- package/runtime/gatewaysdk/environment/schema/workers.py +237 -68
- package/runtime/gatewaysdk/environment/schema/world_host.py +56 -62
- package/runtime/gatewaysdk/environment/schema/world_tests.py +3 -1
- package/skills/connector-schema-authoring/SKILL.md +1 -0
- package/skills/connector-schema-authoring/connector-worlds.md +1 -0
- package/skills/connector-schema-authoring/world-schema.md +7 -0
- package/skills/factory-orchestrator/SKILL.md +147 -0
- package/skills/world-data-ingestion/ROWS.md +5 -1
- package/skills/world-data-ingestion/SKILL.md +4 -4
- package/skills/worlds-getting-started/SKILL.md +2 -2
- package/skills/worlds-getting-started/references/cli-mcp-map.md +1 -0
- package/skills/worlds-getting-started/references/shape-catalog.md +59 -0
package/dist/worlds/index.d.mts
CHANGED
|
@@ -3339,12 +3339,14 @@ type WorldDescription = {
|
|
|
3339
3339
|
members?: WorldBundleMember[];
|
|
3340
3340
|
entities: WorldEntity[];
|
|
3341
3341
|
redact: RedactPolicy | null;
|
|
3342
|
+
/** The world's shape catalog (`conformance/world-shape-catalogs.json` pins its document); null with no data model, or when the runtime could not read it. */
|
|
3343
|
+
catalog?: Record<string, unknown> | null;
|
|
3342
3344
|
};
|
|
3343
3345
|
/** The world at `slug@ref`, described — `ref` is the one grammar shared with
|
|
3344
3346
|
* pull/checkout/sandbox (`latest` | branch | tag | semver | version id | hash
|
|
3345
3347
|
* prefix); a bare slug describes the head of `main`. An unknown ref is the
|
|
3346
3348
|
* route's 404, never the head. */
|
|
3347
|
-
declare function describeWorld(slugRef: string, options?: WorldsClientOptions): Promise<WorldDescription>;
|
|
3349
|
+
declare function describeWorld(slugRef: string, options?: WorldsClientOptions, entity?: string): Promise<WorldDescription>;
|
|
3348
3350
|
|
|
3349
3351
|
/**
|
|
3350
3352
|
* Named plaintext transforms for cross-world entity mappings.
|
package/dist/worlds/index.d.ts
CHANGED
|
@@ -3339,12 +3339,14 @@ type WorldDescription = {
|
|
|
3339
3339
|
members?: WorldBundleMember[];
|
|
3340
3340
|
entities: WorldEntity[];
|
|
3341
3341
|
redact: RedactPolicy | null;
|
|
3342
|
+
/** The world's shape catalog (`conformance/world-shape-catalogs.json` pins its document); null with no data model, or when the runtime could not read it. */
|
|
3343
|
+
catalog?: Record<string, unknown> | null;
|
|
3342
3344
|
};
|
|
3343
3345
|
/** The world at `slug@ref`, described — `ref` is the one grammar shared with
|
|
3344
3346
|
* pull/checkout/sandbox (`latest` | branch | tag | semver | version id | hash
|
|
3345
3347
|
* prefix); a bare slug describes the head of `main`. An unknown ref is the
|
|
3346
3348
|
* route's 404, never the head. */
|
|
3347
|
-
declare function describeWorld(slugRef: string, options?: WorldsClientOptions): Promise<WorldDescription>;
|
|
3349
|
+
declare function describeWorld(slugRef: string, options?: WorldsClientOptions, entity?: string): Promise<WorldDescription>;
|
|
3348
3350
|
|
|
3349
3351
|
/**
|
|
3350
3352
|
* Named plaintext transforms for cross-world entity mappings.
|
package/dist/worlds/index.js
CHANGED
|
@@ -159,8 +159,8 @@ function invalidFields(error) {
|
|
|
159
159
|
return issues.filter(
|
|
160
160
|
(issue) => issue !== null && typeof issue === "object" && typeof issue.message === "string"
|
|
161
161
|
).map((issue) => {
|
|
162
|
-
const
|
|
163
|
-
return
|
|
162
|
+
const path14 = Array.isArray(issue.path) ? issue.path.map(String).join(".") : "";
|
|
163
|
+
return path14 ? `${path14}: ${issue.message}` : issue.message;
|
|
164
164
|
}).join("; ");
|
|
165
165
|
}
|
|
166
166
|
var ApiError, DETAIL_LIMIT, EDGE_ANSWERS, EDGE_FAILURE, EDGE_PAGE;
|
|
@@ -168,9 +168,9 @@ var init_apiError = __esm({
|
|
|
168
168
|
"src/worlds/apiError.ts"() {
|
|
169
169
|
"use strict";
|
|
170
170
|
ApiError = class extends Error {
|
|
171
|
-
constructor(status, method,
|
|
171
|
+
constructor(status, method, path14, text2) {
|
|
172
172
|
const parsed = parseErrorBody(text2, status);
|
|
173
|
-
super(`${method} ${
|
|
173
|
+
super(`${method} ${path14} -> ${status}: ${parsed.detail}`);
|
|
174
174
|
this.status = status;
|
|
175
175
|
this.text = text2;
|
|
176
176
|
this.name = "ApiError";
|
|
@@ -806,9 +806,9 @@ function surfaceKinds(s) {
|
|
|
806
806
|
if (s.browser) kinds.push("browser");
|
|
807
807
|
return kinds;
|
|
808
808
|
}
|
|
809
|
-
function uiUrl(ui,
|
|
809
|
+
function uiUrl(ui, path14) {
|
|
810
810
|
const base = ui.url.replace(/\/+$/, "");
|
|
811
|
-
const rel =
|
|
811
|
+
const rel = path14.startsWith("/") ? path14 : `/${path14}`;
|
|
812
812
|
if (!ui.token) return base + rel;
|
|
813
813
|
const [beforeHash, hash] = splitHash(rel);
|
|
814
814
|
const joiner = beforeHash.includes("?") ? "&" : "?";
|
|
@@ -2226,13 +2226,13 @@ var init_screen = __esm({
|
|
|
2226
2226
|
});
|
|
2227
2227
|
}
|
|
2228
2228
|
async drag(action) {
|
|
2229
|
-
const
|
|
2230
|
-
if (
|
|
2229
|
+
const path14 = action.args.path ?? [];
|
|
2230
|
+
if (path14.length < 2) throw new Error("a drag needs at least two points");
|
|
2231
2231
|
return this.held(action.args.modifiers ?? [], async () => {
|
|
2232
|
-
await this.moveTo(
|
|
2232
|
+
await this.moveTo(path14[0]);
|
|
2233
2233
|
await this.page.mouse.down({ button: "left" });
|
|
2234
2234
|
try {
|
|
2235
|
-
for (const point2 of
|
|
2235
|
+
for (const point2 of path14.slice(1)) await this.moveTo(point2, DRAG_STEPS);
|
|
2236
2236
|
} finally {
|
|
2237
2237
|
await this.page.mouse.up({ button: "left" });
|
|
2238
2238
|
}
|
|
@@ -4066,17 +4066,17 @@ var init_session2 = __esm({
|
|
|
4066
4066
|
}
|
|
4067
4067
|
/** The reporter `browser()` uses; exposed for a page you drive yourself. */
|
|
4068
4068
|
browserRecorder(agentId) {
|
|
4069
|
-
const
|
|
4069
|
+
const path14 = `/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/browser-events`;
|
|
4070
4070
|
const id = agentId ?? process.env.GATEWAY_AGENT_ID ?? `agent-${(0, import_node_crypto2.randomUUID)().replace(/-/g, "").slice(0, 8)}`;
|
|
4071
4071
|
return new BrowserActionRecorder(
|
|
4072
4072
|
async (events) => {
|
|
4073
|
-
await apiRequest(this.options, "POST",
|
|
4073
|
+
await apiRequest(this.options, "POST", path14, { events });
|
|
4074
4074
|
},
|
|
4075
4075
|
id,
|
|
4076
4076
|
{
|
|
4077
4077
|
// Continue this agent's timeline where the platform has it, so a reopened id never re-numbers from zero.
|
|
4078
4078
|
resumeFrom: async () => {
|
|
4079
|
-
const summary = await apiRequest(this.options, "GET",
|
|
4079
|
+
const summary = await apiRequest(this.options, "GET", path14);
|
|
4080
4080
|
return summary.agents.find((a) => a.agentId === id)?.nextSeq ?? 0;
|
|
4081
4081
|
}
|
|
4082
4082
|
}
|
|
@@ -5029,8 +5029,8 @@ var init_taskRunDir = __esm({
|
|
|
5029
5029
|
path = __toESM(require("path"));
|
|
5030
5030
|
init_browser();
|
|
5031
5031
|
TaskRunDir = class {
|
|
5032
|
-
constructor(
|
|
5033
|
-
this.path =
|
|
5032
|
+
constructor(path14) {
|
|
5033
|
+
this.path = path14;
|
|
5034
5034
|
}
|
|
5035
5035
|
path;
|
|
5036
5036
|
writeManifest(manifest) {
|
|
@@ -5429,10 +5429,10 @@ var init_users = __esm({
|
|
|
5429
5429
|
totalItems: Number(meta.totalItems ?? rows.length)
|
|
5430
5430
|
};
|
|
5431
5431
|
}
|
|
5432
|
-
async requestJson(method,
|
|
5432
|
+
async requestJson(method, path14, payload) {
|
|
5433
5433
|
let response;
|
|
5434
5434
|
try {
|
|
5435
|
-
response = await fetch(`${this.host}${
|
|
5435
|
+
response = await fetch(`${this.host}${path14}`, {
|
|
5436
5436
|
method,
|
|
5437
5437
|
headers: {
|
|
5438
5438
|
Authorization: this.authHeader(),
|
|
@@ -5443,17 +5443,17 @@ var init_users = __esm({
|
|
|
5443
5443
|
});
|
|
5444
5444
|
} catch (error) {
|
|
5445
5445
|
throw new UserProfileError(
|
|
5446
|
-
`${method} ${
|
|
5446
|
+
`${method} ${path14} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
5447
5447
|
{ cause: error }
|
|
5448
5448
|
);
|
|
5449
5449
|
}
|
|
5450
5450
|
const text2 = await response.text();
|
|
5451
5451
|
if (!response.ok) {
|
|
5452
5452
|
throw new UserProfileError(
|
|
5453
|
-
`${method} ${
|
|
5453
|
+
`${method} ${path14} failed (${response.status}): ${text2.slice(0, 500)}`
|
|
5454
5454
|
);
|
|
5455
5455
|
}
|
|
5456
|
-
this.log("%s %s -> %s", method,
|
|
5456
|
+
this.log("%s %s -> %s", method, path14, response.status);
|
|
5457
5457
|
return safeJson(text2);
|
|
5458
5458
|
}
|
|
5459
5459
|
authHeader() {
|
|
@@ -5898,10 +5898,10 @@ var init_scores = __esm({
|
|
|
5898
5898
|
metadata: signalMetadata
|
|
5899
5899
|
});
|
|
5900
5900
|
}
|
|
5901
|
-
async request(method,
|
|
5901
|
+
async request(method, path14, payload) {
|
|
5902
5902
|
let response;
|
|
5903
5903
|
try {
|
|
5904
|
-
response = await fetch(`${this.host}${
|
|
5904
|
+
response = await fetch(`${this.host}${path14}`, {
|
|
5905
5905
|
method,
|
|
5906
5906
|
headers: {
|
|
5907
5907
|
Authorization: this.authHeader(),
|
|
@@ -5912,17 +5912,17 @@ var init_scores = __esm({
|
|
|
5912
5912
|
});
|
|
5913
5913
|
} catch (error) {
|
|
5914
5914
|
throw new ScoreError(
|
|
5915
|
-
`${method} ${
|
|
5915
|
+
`${method} ${path14} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
5916
5916
|
{ cause: error }
|
|
5917
5917
|
);
|
|
5918
5918
|
}
|
|
5919
5919
|
const text2 = await response.text();
|
|
5920
5920
|
if (!response.ok) {
|
|
5921
5921
|
throw new ScoreError(
|
|
5922
|
-
`${method} ${
|
|
5922
|
+
`${method} ${path14} failed (${response.status}): ${text2.slice(0, 500)}`
|
|
5923
5923
|
);
|
|
5924
5924
|
}
|
|
5925
|
-
this.log("%s %s -> %s", method,
|
|
5925
|
+
this.log("%s %s -> %s", method, path14, response.status);
|
|
5926
5926
|
}
|
|
5927
5927
|
authHeader() {
|
|
5928
5928
|
return `Basic ${Buffer.from(`${this.publicKey}:${this.secretKey}`).toString(
|
|
@@ -5950,7 +5950,7 @@ var require_package = __commonJS({
|
|
|
5950
5950
|
"package.json"(exports2, module2) {
|
|
5951
5951
|
module2.exports = {
|
|
5952
5952
|
name: "@withgateway/sdk",
|
|
5953
|
-
version: "0.9.
|
|
5953
|
+
version: "0.9.3",
|
|
5954
5954
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
5955
5955
|
main: "./dist/index.js",
|
|
5956
5956
|
module: "./dist/index.mjs",
|
|
@@ -8333,7 +8333,7 @@ function rebaseConflicts(error) {
|
|
|
8333
8333
|
}
|
|
8334
8334
|
const conflicts = body?.conflicts;
|
|
8335
8335
|
if (!Array.isArray(conflicts)) return null;
|
|
8336
|
-
return conflicts.filter(isConflictPath).map(({ path:
|
|
8336
|
+
return conflicts.filter(isConflictPath).map(({ path: path14, reason }) => ({ path: path14, reason }));
|
|
8337
8337
|
}
|
|
8338
8338
|
function isConflictPath(value) {
|
|
8339
8339
|
const entry = value;
|
|
@@ -8458,8 +8458,8 @@ var init_sandbox = __esm({
|
|
|
8458
8458
|
this.options = options;
|
|
8459
8459
|
}
|
|
8460
8460
|
options;
|
|
8461
|
-
request(method,
|
|
8462
|
-
return apiRequest(this.options, method,
|
|
8461
|
+
request(method, path14, body) {
|
|
8462
|
+
return apiRequest(this.options, method, path14, body, {
|
|
8463
8463
|
timeoutMs: SANDBOX_REQUEST_TIMEOUT_MS
|
|
8464
8464
|
});
|
|
8465
8465
|
}
|
|
@@ -8589,13 +8589,16 @@ var init_sandbox = __esm({
|
|
|
8589
8589
|
});
|
|
8590
8590
|
|
|
8591
8591
|
// src/worlds/describe.ts
|
|
8592
|
-
async function describeWorld(slugRef, options = {}) {
|
|
8592
|
+
async function describeWorld(slugRef, options = {}, entity) {
|
|
8593
8593
|
const { slug, ref } = parseSlugRef(slugRef);
|
|
8594
|
-
const query =
|
|
8594
|
+
const query = new URLSearchParams();
|
|
8595
|
+
if (ref !== void 0) query.set("ref", ref);
|
|
8596
|
+
if (entity !== void 0) query.set("entity", entity);
|
|
8597
|
+
const search = query.toString() ? `?${query}` : "";
|
|
8595
8598
|
return apiRequest(
|
|
8596
8599
|
options,
|
|
8597
8600
|
"GET",
|
|
8598
|
-
`/api/public/worlds/${encodeURIComponent(slug)}${
|
|
8601
|
+
`/api/public/worlds/${encodeURIComponent(slug)}${search}`
|
|
8599
8602
|
);
|
|
8600
8603
|
}
|
|
8601
8604
|
var init_describe = __esm({
|
|
@@ -9518,8 +9521,8 @@ runpy.run_module('gatewaysdk.environment.schema',run_name='__main__')`;
|
|
|
9518
9521
|
});
|
|
9519
9522
|
|
|
9520
9523
|
// src/worlds/databaseEngines.ts
|
|
9521
|
-
function isWorldSnapshotOutput(
|
|
9522
|
-
return SNAPSHOT_OUTPUTS.has(
|
|
9524
|
+
function isWorldSnapshotOutput(path14) {
|
|
9525
|
+
return SNAPSHOT_OUTPUTS.has(path14.slice(path14.lastIndexOf("/") + 1));
|
|
9523
9526
|
}
|
|
9524
9527
|
var WORLD_DATABASE_ENGINES, DEFAULT_WORLD_DATABASE_ENGINE, WORLD_SNAPSHOT_FILE_PATH, WORLD_SNAPSHOT_SIDECAR_PATH, WORLD_SNAPSHOT_CONTENT_TYPE, SNAPSHOT_OUTPUTS;
|
|
9525
9528
|
var init_databaseEngines = __esm({
|
|
@@ -10129,6 +10132,80 @@ if (fn) {
|
|
|
10129
10132
|
}
|
|
10130
10133
|
});
|
|
10131
10134
|
|
|
10135
|
+
// src/cli/platform/worldData/manifest.ts
|
|
10136
|
+
function recordChunk(manifest, chunk) {
|
|
10137
|
+
manifest.chunks = [...manifest.chunks.filter((c) => c.ordinal !== chunk.ordinal), chunk].sort((a, b) => a.ordinal - b.ordinal);
|
|
10138
|
+
}
|
|
10139
|
+
function uploadedEntry(manifest, ordinal, digest) {
|
|
10140
|
+
return manifest.chunks.find((c) => c.ordinal === ordinal && c.digest === digest && c.uploaded) ?? null;
|
|
10141
|
+
}
|
|
10142
|
+
var fs11, path12, STEM, MANIFEST_DIR, stamp, sameInputs, ManifestShelf, IMPORT_MANIFESTS;
|
|
10143
|
+
var init_manifest = __esm({
|
|
10144
|
+
"src/cli/platform/worldData/manifest.ts"() {
|
|
10145
|
+
"use strict";
|
|
10146
|
+
fs11 = __toESM(require("fs"));
|
|
10147
|
+
path12 = __toESM(require("path"));
|
|
10148
|
+
init_router();
|
|
10149
|
+
STEM = /^[A-Za-z0-9_-]+$/;
|
|
10150
|
+
MANIFEST_DIR = path12.join(".gateway", "imports");
|
|
10151
|
+
stamp = () => (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
10152
|
+
sameInputs = (a, b) => a.length === b.length && a.every((x, i) => x === b[i]);
|
|
10153
|
+
ManifestShelf = class {
|
|
10154
|
+
constructor(dir, stem) {
|
|
10155
|
+
this.dir = dir;
|
|
10156
|
+
this.stem = stem;
|
|
10157
|
+
}
|
|
10158
|
+
dir;
|
|
10159
|
+
stem;
|
|
10160
|
+
dirIn(cwd = process.cwd()) {
|
|
10161
|
+
return path12.join(cwd, this.dir);
|
|
10162
|
+
}
|
|
10163
|
+
file(stem, cwd) {
|
|
10164
|
+
if (!STEM.test(stem)) throw new CliError(`Not a manifest name: ${stem}`);
|
|
10165
|
+
return path12.join(this.dirIn(cwd), `${stem}.json`);
|
|
10166
|
+
}
|
|
10167
|
+
// .gateway/ ignores itself so a manifest, which names hosts and inputs, never enters a repository.
|
|
10168
|
+
write(manifest, cwd = process.cwd()) {
|
|
10169
|
+
const file = this.file(this.stem(manifest), cwd);
|
|
10170
|
+
fs11.mkdirSync(path12.dirname(file), { recursive: true });
|
|
10171
|
+
const ignore = path12.join(cwd, ".gateway", ".gitignore");
|
|
10172
|
+
if (!fs11.existsSync(ignore)) fs11.writeFileSync(ignore, "*\n");
|
|
10173
|
+
manifest.updatedAt = stamp();
|
|
10174
|
+
const tmp = `${file}.tmp`;
|
|
10175
|
+
fs11.writeFileSync(tmp, JSON.stringify(manifest, null, 1) + "\n");
|
|
10176
|
+
fs11.renameSync(tmp, file);
|
|
10177
|
+
return file;
|
|
10178
|
+
}
|
|
10179
|
+
record(manifest, chunk, cwd = process.cwd()) {
|
|
10180
|
+
recordChunk(manifest, chunk);
|
|
10181
|
+
this.write(manifest, cwd);
|
|
10182
|
+
}
|
|
10183
|
+
read(stem, cwd = process.cwd()) {
|
|
10184
|
+
try {
|
|
10185
|
+
const parsed = JSON.parse(fs11.readFileSync(this.file(stem, cwd), "utf8"));
|
|
10186
|
+
return parsed && parsed.version === 1 && this.stem(parsed) === stem ? parsed : null;
|
|
10187
|
+
} catch {
|
|
10188
|
+
return null;
|
|
10189
|
+
}
|
|
10190
|
+
}
|
|
10191
|
+
list(cwd = process.cwd()) {
|
|
10192
|
+
const dir = this.dirIn(cwd);
|
|
10193
|
+
if (!fs11.existsSync(dir)) return [];
|
|
10194
|
+
const out = [];
|
|
10195
|
+
for (const name of fs11.readdirSync(dir)) {
|
|
10196
|
+
const manifest = name.endsWith(".json") ? this.read(name.slice(0, -5), cwd) : null;
|
|
10197
|
+
if (manifest) out.push(manifest);
|
|
10198
|
+
}
|
|
10199
|
+
return out.sort((a, b) => Number(a.updatedAt < b.updatedAt) - Number(a.updatedAt > b.updatedAt));
|
|
10200
|
+
}
|
|
10201
|
+
resumable(slug, inputs, cwd = process.cwd()) {
|
|
10202
|
+
return this.list(cwd).find((m) => !m.completed && m.slug === slug && sameInputs(m.inputs, inputs)) ?? null;
|
|
10203
|
+
}
|
|
10204
|
+
};
|
|
10205
|
+
IMPORT_MANIFESTS = new ManifestShelf(MANIFEST_DIR, (key) => key.batchId);
|
|
10206
|
+
}
|
|
10207
|
+
});
|
|
10208
|
+
|
|
10132
10209
|
// src/cli/platform/worldData/batches.ts
|
|
10133
10210
|
function isSettled(status) {
|
|
10134
10211
|
if (!TERMINAL_STATES.has(status.state)) return false;
|
|
@@ -10191,14 +10268,16 @@ function phaseLine(status) {
|
|
|
10191
10268
|
const phase = status.progress?.phase;
|
|
10192
10269
|
return phase ? `${status.state} (${phase})` : status.state;
|
|
10193
10270
|
}
|
|
10194
|
-
var import_node_crypto10,
|
|
10271
|
+
var import_node_crypto10, fs12, CHUNK_PARALLEL, TERMINAL_STATES, sleepMs, WorldDataApi, ChunkUploader;
|
|
10195
10272
|
var init_batches = __esm({
|
|
10196
10273
|
"src/cli/platform/worldData/batches.ts"() {
|
|
10197
10274
|
"use strict";
|
|
10198
10275
|
import_node_crypto10 = require("crypto");
|
|
10199
|
-
|
|
10276
|
+
fs12 = __toESM(require("fs"));
|
|
10200
10277
|
init_config();
|
|
10201
10278
|
init_router();
|
|
10279
|
+
init_manifest();
|
|
10280
|
+
CHUNK_PARALLEL = 4;
|
|
10202
10281
|
TERMINAL_STATES = /* @__PURE__ */ new Set([
|
|
10203
10282
|
"applied",
|
|
10204
10283
|
"refused",
|
|
@@ -10225,13 +10304,7 @@ var init_batches = __esm({
|
|
|
10225
10304
|
this.creds,
|
|
10226
10305
|
"POST",
|
|
10227
10306
|
`${this.base}/batches/${batchId}/chunks`,
|
|
10228
|
-
|
|
10229
|
-
ordinal: chunk.ordinal,
|
|
10230
|
-
digest: chunk.digest,
|
|
10231
|
-
bytes: chunk.bytes,
|
|
10232
|
-
rows: chunk.rows,
|
|
10233
|
-
...chunk.entity ? { entity: chunk.entity } : {}
|
|
10234
|
-
}
|
|
10307
|
+
chunk
|
|
10235
10308
|
);
|
|
10236
10309
|
}
|
|
10237
10310
|
async stageDrive(batchId, chunk) {
|
|
@@ -10287,6 +10360,23 @@ var init_batches = __esm({
|
|
|
10287
10360
|
message ? { message } : {}
|
|
10288
10361
|
);
|
|
10289
10362
|
}
|
|
10363
|
+
chunks(batchId) {
|
|
10364
|
+
return new ChunkUploader(
|
|
10365
|
+
{
|
|
10366
|
+
register: (chunk) => this.register(batchId, chunk),
|
|
10367
|
+
uploaded: (chunkId) => this.markUploaded(batchId, chunkId)
|
|
10368
|
+
},
|
|
10369
|
+
this.sleep
|
|
10370
|
+
);
|
|
10371
|
+
}
|
|
10372
|
+
};
|
|
10373
|
+
ChunkUploader = class {
|
|
10374
|
+
constructor(door, sleep4 = sleepMs) {
|
|
10375
|
+
this.door = door;
|
|
10376
|
+
this.sleep = sleep4;
|
|
10377
|
+
}
|
|
10378
|
+
door;
|
|
10379
|
+
sleep;
|
|
10290
10380
|
async put(uploadUrl, gz, signed) {
|
|
10291
10381
|
const headers = signed ?? uploadHeadersFor(gz);
|
|
10292
10382
|
const delays = [500, 1500, 4e3];
|
|
@@ -10313,17 +10403,15 @@ var init_batches = __esm({
|
|
|
10313
10403
|
await this.sleep(delays[attempt]);
|
|
10314
10404
|
}
|
|
10315
10405
|
}
|
|
10316
|
-
async upload(
|
|
10317
|
-
const registered = await this.register(
|
|
10318
|
-
|
|
10319
|
-
|
|
10320
|
-
|
|
10321
|
-
|
|
10322
|
-
|
|
10323
|
-
|
|
10324
|
-
|
|
10325
|
-
await this.markUploaded(batchId, registered.chunkId);
|
|
10326
|
-
}
|
|
10406
|
+
async upload(chunk) {
|
|
10407
|
+
const registered = await this.door.register({
|
|
10408
|
+
ordinal: chunk.ordinal,
|
|
10409
|
+
digest: chunk.digest,
|
|
10410
|
+
bytes: chunk.bytes,
|
|
10411
|
+
rows: chunk.rows,
|
|
10412
|
+
...chunk.entity ? { entity: chunk.entity } : {}
|
|
10413
|
+
});
|
|
10414
|
+
if (!registered.uploaded) await this.send(chunk, registered);
|
|
10327
10415
|
return {
|
|
10328
10416
|
ordinal: chunk.ordinal,
|
|
10329
10417
|
digest: chunk.digest,
|
|
@@ -10334,6 +10422,28 @@ var init_batches = __esm({
|
|
|
10334
10422
|
uploaded: true
|
|
10335
10423
|
};
|
|
10336
10424
|
}
|
|
10425
|
+
async send(chunk, registered) {
|
|
10426
|
+
if (!registered.uploadUrl)
|
|
10427
|
+
throw new CliError(
|
|
10428
|
+
`the server registered chunk ${chunk.ordinal} without an upload URL`,
|
|
10429
|
+
1
|
|
10430
|
+
);
|
|
10431
|
+
await this.put(registered.uploadUrl, chunk.gz, registered.uploadHeaders);
|
|
10432
|
+
await this.door.uploaded(registered.chunkId);
|
|
10433
|
+
}
|
|
10434
|
+
async uploadAll(chunks, kept, parallel, progress) {
|
|
10435
|
+
await forEachLimited(chunks, parallel, async (chunk) => {
|
|
10436
|
+
if (uploadedEntry(kept.manifest, chunk.ordinal, chunk.digest)) {
|
|
10437
|
+
progress(`chunk ${chunk.ordinal}: already uploaded (${chunk.rows} rows)`);
|
|
10438
|
+
return;
|
|
10439
|
+
}
|
|
10440
|
+
const entry = await this.upload(chunk);
|
|
10441
|
+
kept.shelf.record(kept.manifest, entry);
|
|
10442
|
+
progress(
|
|
10443
|
+
`chunk ${chunk.ordinal}: uploaded ${chunk.rows} rows, ${chunk.bytes} bytes (${entry.chunkId})`
|
|
10444
|
+
);
|
|
10445
|
+
});
|
|
10446
|
+
}
|
|
10337
10447
|
};
|
|
10338
10448
|
}
|
|
10339
10449
|
});
|
|
@@ -10469,11 +10579,12 @@ async function pushRows(creds, slug, rows, opts = {}) {
|
|
|
10469
10579
|
chunkRows: null,
|
|
10470
10580
|
entity: null
|
|
10471
10581
|
});
|
|
10582
|
+
const uploader = client.chunks(opened.batchId);
|
|
10472
10583
|
await forEachLimited(
|
|
10473
10584
|
chunks,
|
|
10474
|
-
Math.max(1, opts.parallel ??
|
|
10585
|
+
Math.max(1, opts.parallel ?? CHUNK_PARALLEL),
|
|
10475
10586
|
async (chunk) => {
|
|
10476
|
-
await
|
|
10587
|
+
await uploader.upload(chunk);
|
|
10477
10588
|
}
|
|
10478
10589
|
);
|
|
10479
10590
|
await client.complete(opened.batchId);
|
|
@@ -10511,7 +10622,7 @@ function parseToolCallRecord(raw) {
|
|
|
10511
10622
|
}
|
|
10512
10623
|
function readToolCallRecords(paths) {
|
|
10513
10624
|
const records = [];
|
|
10514
|
-
for (const file of paths) records.push(...toolCallRecordsIn(
|
|
10625
|
+
for (const file of paths) records.push(...toolCallRecordsIn(fs13.readFileSync(file, "utf8"), file));
|
|
10515
10626
|
return records;
|
|
10516
10627
|
}
|
|
10517
10628
|
function toolCallRecordsIn(text2, where) {
|
|
@@ -10547,7 +10658,7 @@ async function emit(sink, record) {
|
|
|
10547
10658
|
return;
|
|
10548
10659
|
}
|
|
10549
10660
|
if (typeof sink === "string") {
|
|
10550
|
-
|
|
10661
|
+
fs13.appendFileSync(sink, JSON.stringify(record) + "\n");
|
|
10551
10662
|
return;
|
|
10552
10663
|
}
|
|
10553
10664
|
if (typeof sink === "function") {
|
|
@@ -10629,7 +10740,7 @@ async function ingest(world, records, options = {}) {
|
|
|
10629
10740
|
const redact = options.redact ?? "off";
|
|
10630
10741
|
const mode = options.mode ?? "append";
|
|
10631
10742
|
const dryRun = Boolean(options.dryRun);
|
|
10632
|
-
const local =
|
|
10743
|
+
const local = fs13.existsSync(world) && fs13.statSync(world).isDirectory();
|
|
10633
10744
|
const creds = local ? await runtimeEndpoint(options) : platformEndpoint(options);
|
|
10634
10745
|
const map = options.map === void 0 ? void 0 : options.map;
|
|
10635
10746
|
let rows = null;
|
|
@@ -10646,9 +10757,9 @@ async function ingest(world, records, options = {}) {
|
|
|
10646
10757
|
if (!creds) throw new Error(GATEWAY_KEYS_MISSING);
|
|
10647
10758
|
const { pull: pull2 } = await Promise.resolve().then(() => (init_hub(), hub_exports));
|
|
10648
10759
|
const slug = world.split("@", 1)[0];
|
|
10649
|
-
const scratch =
|
|
10760
|
+
const scratch = fs13.mkdtempSync(path13.join(os3.tmpdir(), "gateway-ingest-"));
|
|
10650
10761
|
try {
|
|
10651
|
-
const pulled = await pull2(world,
|
|
10762
|
+
const pulled = await pull2(world, path13.join(scratch, slug), options);
|
|
10652
10763
|
let report;
|
|
10653
10764
|
let projected;
|
|
10654
10765
|
if (rows === null) {
|
|
@@ -10669,7 +10780,7 @@ async function ingest(world, records, options = {}) {
|
|
|
10669
10780
|
if (status.entityCounts) report.entityCounts = status.entityCounts;
|
|
10670
10781
|
return report;
|
|
10671
10782
|
} finally {
|
|
10672
|
-
|
|
10783
|
+
fs13.rmSync(scratch, { recursive: true, force: true });
|
|
10673
10784
|
}
|
|
10674
10785
|
}
|
|
10675
10786
|
async function ingestToolCalls(world, records, options = {}) {
|
|
@@ -10722,13 +10833,13 @@ async function sessionToolObservations(sessionId, options = {}) {
|
|
|
10722
10833
|
for (const observation of trace3.observations ?? []) out.push({ traceId: trace3.id ?? null, ...observation });
|
|
10723
10834
|
return out;
|
|
10724
10835
|
}
|
|
10725
|
-
var
|
|
10836
|
+
var fs13, os3, path13, isObject2, isoOf;
|
|
10726
10837
|
var init_ingest = __esm({
|
|
10727
10838
|
"src/worlds/ingest.ts"() {
|
|
10728
10839
|
"use strict";
|
|
10729
|
-
|
|
10840
|
+
fs13 = __toESM(require("fs"));
|
|
10730
10841
|
os3 = __toESM(require("os"));
|
|
10731
|
-
|
|
10842
|
+
path13 = __toESM(require("path"));
|
|
10732
10843
|
init_worlds();
|
|
10733
10844
|
init_platformEndpoint();
|
|
10734
10845
|
init_personalToken();
|
|
@@ -11138,8 +11249,8 @@ __export(worlds_exports, {
|
|
|
11138
11249
|
writeLocalMeta: () => writeLocalMeta
|
|
11139
11250
|
});
|
|
11140
11251
|
module.exports = __toCommonJS(worlds_exports);
|
|
11141
|
-
async function apiRequest(options, method,
|
|
11142
|
-
return new PlatformTransport(requirePlatformEndpoint(options)).json(method,
|
|
11252
|
+
async function apiRequest(options, method, path14, body, init2 = {}) {
|
|
11253
|
+
return new PlatformTransport(requirePlatformEndpoint(options)).json(method, path14, body, init2);
|
|
11143
11254
|
}
|
|
11144
11255
|
async function setEnvSecret(slug, key, value, options = {}) {
|
|
11145
11256
|
return apiRequest(
|