@withgateway/sdk 0.2.8 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -8
- package/dist/cli.js +332 -163
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +332 -163
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.js +119 -15
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +119 -15
- 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 +229 -120
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +220 -120
- package/dist/index.mjs.map +1 -1
- package/dist/traces/index.js +119 -15
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +119 -15
- 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 +78 -9
- package/dist/worlds/index.d.ts +78 -9
- package/dist/worlds/index.js +219 -119
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +220 -120
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +1 -1
- package/runtime/gatewaysdk/environment/_toml.py +3 -10
- package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +3 -3
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +1 -1
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +11 -11
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +3 -2
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +5 -1
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/new-world-sandbox.md +5 -3
- package/runtime/gatewaysdk/environment/schema/store.py +15 -6
- package/skills/benchmarks-getting-started/SKILL.md +3 -3
- package/skills/connector-schema-authoring/SKILL.md +1 -1
- package/skills/connector-schema-authoring/world-schema.md +1 -1
- package/skills/worlds-getting-started/SKILL.md +11 -11
- package/skills/worlds-getting-started/references/cli-mcp-map.md +3 -2
- package/skills/worlds-getting-started/references/gotchas.md +5 -1
- package/skills/worlds-getting-started/references/new-world-sandbox.md +5 -3
package/dist/worlds/index.mjs
CHANGED
|
@@ -28,6 +28,115 @@ var __export = (target, all) => {
|
|
|
28
28
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
+
// src/worlds/transport.ts
|
|
32
|
+
function platformTimeoutMs(env = process.env) {
|
|
33
|
+
const raw = env[PLATFORM_TIMEOUT_ENV];
|
|
34
|
+
if (raw === void 0 || raw === "") return PLATFORM_TIMEOUT_DEFAULT_MS;
|
|
35
|
+
const value = Number(raw);
|
|
36
|
+
if (Number.isInteger(value) && value > 0) return value;
|
|
37
|
+
throw new Error(`${PLATFORM_TIMEOUT_ENV} must be a positive whole number of milliseconds, not \`${raw}\`.`);
|
|
38
|
+
}
|
|
39
|
+
var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, PlatformTransport;
|
|
40
|
+
var init_transport = __esm({
|
|
41
|
+
"src/worlds/transport.ts"() {
|
|
42
|
+
"use strict";
|
|
43
|
+
PLATFORM_TIMEOUT_ENV = "GATEWAY_TIMEOUT_MS";
|
|
44
|
+
PLATFORM_TIMEOUT_DEFAULT_MS = 12e4;
|
|
45
|
+
CHECK_HOST = "Check GATEWAY_HOST (or --host) points at a running platform, then retry.";
|
|
46
|
+
RETRY = "Retry; if it repeats, check the network between here and the platform.";
|
|
47
|
+
CAUSES = {
|
|
48
|
+
ECONNREFUSED: { reason: "connection refused", next: CHECK_HOST },
|
|
49
|
+
ENOTFOUND: { reason: "DNS lookup failed", next: CHECK_HOST },
|
|
50
|
+
EAI_AGAIN: { reason: "DNS lookup failed", next: CHECK_HOST },
|
|
51
|
+
ETIMEDOUT: { reason: "connect timed out", next: CHECK_HOST },
|
|
52
|
+
UND_ERR_CONNECT_TIMEOUT: { reason: "connect timed out", next: CHECK_HOST },
|
|
53
|
+
EHOSTUNREACH: { reason: "host unreachable", next: CHECK_HOST },
|
|
54
|
+
ENETUNREACH: { reason: "network unreachable", next: RETRY },
|
|
55
|
+
ECONNRESET: { reason: "connection dropped", next: RETRY },
|
|
56
|
+
UND_ERR_SOCKET: { reason: "connection dropped", next: RETRY },
|
|
57
|
+
EPIPE: { reason: "connection dropped", next: RETRY }
|
|
58
|
+
};
|
|
59
|
+
UNKNOWN_CAUSE = { reason: "network error", next: CHECK_HOST };
|
|
60
|
+
TransportCause = class _TransportCause {
|
|
61
|
+
constructor(reason, detail, next) {
|
|
62
|
+
this.reason = reason;
|
|
63
|
+
this.detail = detail;
|
|
64
|
+
this.next = next;
|
|
65
|
+
}
|
|
66
|
+
reason;
|
|
67
|
+
detail;
|
|
68
|
+
next;
|
|
69
|
+
static timeout(timeoutMs) {
|
|
70
|
+
return new _TransportCause(
|
|
71
|
+
`timed out after ${timeoutMs / 1e3}s`,
|
|
72
|
+
null,
|
|
73
|
+
`Retry; if the platform is slow, raise ${PLATFORM_TIMEOUT_ENV} (milliseconds per request).`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
static of(error) {
|
|
77
|
+
const cause = error instanceof Error && error.cause instanceof Error ? error.cause : void 0;
|
|
78
|
+
const code = cause && "code" in cause && typeof cause.code === "string" ? cause.code : null;
|
|
79
|
+
const message = cause?.message ?? (error instanceof Error ? error.message : String(error));
|
|
80
|
+
const known = code && CAUSES[code] || UNKNOWN_CAUSE;
|
|
81
|
+
return new _TransportCause(known.reason, code ? `${code}: ${message}` : message, known.next);
|
|
82
|
+
}
|
|
83
|
+
describe() {
|
|
84
|
+
return this.detail === null ? this.reason : `${this.reason} (${this.detail})`;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
UnreachableError = class extends Error {
|
|
88
|
+
constructor(host, method, route, failure) {
|
|
89
|
+
super(`${method} ${route}: no answer from ${host}: ${failure.describe()}. ${failure.next}`);
|
|
90
|
+
this.host = host;
|
|
91
|
+
this.method = method;
|
|
92
|
+
this.route = route;
|
|
93
|
+
this.failure = failure;
|
|
94
|
+
this.name = "UnreachableError";
|
|
95
|
+
}
|
|
96
|
+
host;
|
|
97
|
+
method;
|
|
98
|
+
route;
|
|
99
|
+
failure;
|
|
100
|
+
};
|
|
101
|
+
PlatformTransport = class {
|
|
102
|
+
constructor(endpoint, timeoutMs = platformTimeoutMs()) {
|
|
103
|
+
this.endpoint = endpoint;
|
|
104
|
+
this.timeoutMs = timeoutMs;
|
|
105
|
+
}
|
|
106
|
+
endpoint;
|
|
107
|
+
timeoutMs;
|
|
108
|
+
/** A request that legitimately takes longer (a sandbox exec, a world create) waits its own budget; every other one waits the default. */
|
|
109
|
+
budget(ownMs) {
|
|
110
|
+
return Math.max(ownMs ?? 0, this.timeoutMs);
|
|
111
|
+
}
|
|
112
|
+
async send(method, route, body, opts = {}) {
|
|
113
|
+
const timeoutMs = this.budget(opts.timeoutMs);
|
|
114
|
+
const payload = body === void 0 ? {} : { body: JSON.stringify(body) };
|
|
115
|
+
const controller = new AbortController();
|
|
116
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
117
|
+
try {
|
|
118
|
+
const res = await fetch(`${this.endpoint.host}${route}`, {
|
|
119
|
+
method,
|
|
120
|
+
headers: {
|
|
121
|
+
"content-type": "application/json",
|
|
122
|
+
accept: "application/json",
|
|
123
|
+
authorization: "Basic " + Buffer.from(`${this.endpoint.publicKey}:${this.endpoint.secretKey}`).toString("base64")
|
|
124
|
+
},
|
|
125
|
+
...payload,
|
|
126
|
+
signal: controller.signal
|
|
127
|
+
});
|
|
128
|
+
return { status: res.status, ok: res.ok, text: await res.text() };
|
|
129
|
+
} catch (error) {
|
|
130
|
+
const cause = controller.signal.aborted ? TransportCause.timeout(timeoutMs) : TransportCause.of(error);
|
|
131
|
+
throw new UnreachableError(this.endpoint.host, method, route, cause);
|
|
132
|
+
} finally {
|
|
133
|
+
clearTimeout(timer);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
31
140
|
// src/worlds/browserReconnect.ts
|
|
32
141
|
async function closeConnection(c) {
|
|
33
142
|
await c.context.close();
|
|
@@ -2419,7 +2528,7 @@ var require_package = __commonJS({
|
|
|
2419
2528
|
"package.json"(exports, module) {
|
|
2420
2529
|
module.exports = {
|
|
2421
2530
|
name: "@withgateway/sdk",
|
|
2422
|
-
version: "0.2.
|
|
2531
|
+
version: "0.2.9",
|
|
2423
2532
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
2424
2533
|
main: "./dist/index.js",
|
|
2425
2534
|
module: "./dist/index.mjs",
|
|
@@ -4524,6 +4633,34 @@ function parseSlugRef(slugRef) {
|
|
|
4524
4633
|
if (at === -1) return { slug: slugRef };
|
|
4525
4634
|
return { slug: slugRef.slice(0, at), ref: slugRef.slice(at + 1) };
|
|
4526
4635
|
}
|
|
4636
|
+
function rebaseConflicts(error) {
|
|
4637
|
+
if (!(error instanceof ApiError) || error.status !== 409) return null;
|
|
4638
|
+
let body;
|
|
4639
|
+
try {
|
|
4640
|
+
body = JSON.parse(error.text);
|
|
4641
|
+
} catch {
|
|
4642
|
+
return null;
|
|
4643
|
+
}
|
|
4644
|
+
const conflicts = body?.conflicts;
|
|
4645
|
+
if (!Array.isArray(conflicts)) return null;
|
|
4646
|
+
return conflicts.filter(isConflictPath).map(({ path: path12, reason }) => ({ path: path12, reason }));
|
|
4647
|
+
}
|
|
4648
|
+
function isConflictPath(value) {
|
|
4649
|
+
const entry = value;
|
|
4650
|
+
return typeof entry?.path === "string" && typeof entry.reason === "string";
|
|
4651
|
+
}
|
|
4652
|
+
function uncommittedPaths(error) {
|
|
4653
|
+
if (!(error instanceof ApiError) || error.status !== 409 || error.code !== "sandbox_uncommitted") return null;
|
|
4654
|
+
let body;
|
|
4655
|
+
try {
|
|
4656
|
+
body = JSON.parse(error.text);
|
|
4657
|
+
} catch {
|
|
4658
|
+
return null;
|
|
4659
|
+
}
|
|
4660
|
+
const uncommitted = body?.uncommitted;
|
|
4661
|
+
if (!Array.isArray(uncommitted)) return null;
|
|
4662
|
+
return uncommitted.filter((p) => typeof p === "string");
|
|
4663
|
+
}
|
|
4527
4664
|
function listQuery(filter) {
|
|
4528
4665
|
const params = new URLSearchParams();
|
|
4529
4666
|
if (filter.status) params.set("status", filter.status);
|
|
@@ -4532,18 +4669,25 @@ function listQuery(filter) {
|
|
|
4532
4669
|
const qs = params.toString();
|
|
4533
4670
|
return qs ? `?${qs}` : "";
|
|
4534
4671
|
}
|
|
4535
|
-
var isSandboxImportPending, sid, WorldSandboxClient;
|
|
4672
|
+
var isSandboxImportPending, sid, SANDBOXES, SANDBOX_REQUEST_TIMEOUT_MS, WorldSandboxClient;
|
|
4536
4673
|
var init_sandbox = __esm({
|
|
4537
4674
|
"src/worlds/sandbox.ts"() {
|
|
4538
4675
|
"use strict";
|
|
4539
4676
|
init_worlds();
|
|
4540
4677
|
isSandboxImportPending = (answer) => !("versionId" in answer);
|
|
4541
4678
|
sid = encodeURIComponent;
|
|
4679
|
+
SANDBOXES = "/api/public/benchmark-containers/sandboxes";
|
|
4680
|
+
SANDBOX_REQUEST_TIMEOUT_MS = 66e4;
|
|
4542
4681
|
WorldSandboxClient = class {
|
|
4543
4682
|
constructor(options = {}) {
|
|
4544
4683
|
this.options = options;
|
|
4545
4684
|
}
|
|
4546
4685
|
options;
|
|
4686
|
+
request(method, path12, body) {
|
|
4687
|
+
return apiRequest(this.options, method, path12, body, {
|
|
4688
|
+
timeoutMs: SANDBOX_REQUEST_TIMEOUT_MS
|
|
4689
|
+
});
|
|
4690
|
+
}
|
|
4547
4691
|
/**
|
|
4548
4692
|
* `{ slug, ref? }` opens a READY version; `{ new, from }` opens a sandbox on
|
|
4549
4693
|
* a world that does not exist yet (409 `world_exists` if the slug is taken,
|
|
@@ -4551,42 +4695,39 @@ var init_sandbox = __esm({
|
|
|
4551
4695
|
* creates the world on `main`.
|
|
4552
4696
|
*/
|
|
4553
4697
|
open(target) {
|
|
4554
|
-
return
|
|
4698
|
+
return this.request("POST", `${SANDBOXES}`, target);
|
|
4555
4699
|
}
|
|
4556
4700
|
status(sandboxId) {
|
|
4557
|
-
return
|
|
4701
|
+
return this.request("GET", `${SANDBOXES}/${sid(sandboxId)}`);
|
|
4558
4702
|
}
|
|
4559
4703
|
/** The project's sandboxes, newest first — how an agent finds one it left open. */
|
|
4560
4704
|
async list(filter = {}) {
|
|
4561
|
-
const res = await
|
|
4562
|
-
this.options,
|
|
4563
|
-
"GET",
|
|
4564
|
-
`/api/public/benchmark-containers/sandboxes${listQuery(filter)}`
|
|
4565
|
-
);
|
|
4705
|
+
const res = await this.request("GET", `${SANDBOXES}${listQuery(filter)}`);
|
|
4566
4706
|
return res.sandboxes;
|
|
4567
4707
|
}
|
|
4568
4708
|
async read(sandboxId, filePath) {
|
|
4569
|
-
const res = await
|
|
4570
|
-
this.options,
|
|
4709
|
+
const res = await this.request(
|
|
4571
4710
|
"GET",
|
|
4572
|
-
|
|
4711
|
+
`${SANDBOXES}/${sid(sandboxId)}/file?path=${encodeURIComponent(filePath)}`
|
|
4573
4712
|
);
|
|
4574
4713
|
return { path: res.path, size: res.size, bytes: Buffer.from(res.contentBase64, "base64") };
|
|
4575
4714
|
}
|
|
4576
4715
|
write(sandboxId, filePath, bytes) {
|
|
4577
|
-
return
|
|
4716
|
+
return this.request("PUT", `${SANDBOXES}/${sid(sandboxId)}/file`, {
|
|
4578
4717
|
path: filePath,
|
|
4579
4718
|
contentBase64: bytes.toString("base64")
|
|
4580
4719
|
});
|
|
4581
4720
|
}
|
|
4582
4721
|
exec(sandboxId, input) {
|
|
4583
|
-
return
|
|
4722
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/exec`, input);
|
|
4584
4723
|
}
|
|
4585
4724
|
check(sandboxId) {
|
|
4586
|
-
return
|
|
4725
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/check`, {});
|
|
4587
4726
|
}
|
|
4727
|
+
/** With `rebase`, a moved base is replayed onto; a 409 then names the conflicting paths (`rebaseConflicts`). */
|
|
4588
4728
|
commit(sandboxId, input) {
|
|
4589
|
-
|
|
4729
|
+
const { rebase, ...rest } = input;
|
|
4730
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/commit`, rebase ? { ...rest, rebase: true } : rest);
|
|
4590
4731
|
}
|
|
4591
4732
|
/**
|
|
4592
4733
|
* A rows file already in the sandbox tree into the PLATFORM world the
|
|
@@ -4595,10 +4736,11 @@ var init_sandbox = __esm({
|
|
|
4595
4736
|
* tree and never carries data.
|
|
4596
4737
|
*/
|
|
4597
4738
|
importData(sandboxId, input) {
|
|
4598
|
-
return
|
|
4739
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/import`, input);
|
|
4599
4740
|
}
|
|
4600
|
-
|
|
4601
|
-
|
|
4741
|
+
/** Uncommitted work is a 409 (`uncommittedPaths`) unless `force` discards it. */
|
|
4742
|
+
close(sandboxId, opts = {}) {
|
|
4743
|
+
return this.request("DELETE", `${SANDBOXES}/${sid(sandboxId)}`, opts.force ? { force: true } : void 0);
|
|
4602
4744
|
}
|
|
4603
4745
|
};
|
|
4604
4746
|
}
|
|
@@ -5130,48 +5272,19 @@ var init_router = __esm({
|
|
|
5130
5272
|
import * as fs6 from "fs";
|
|
5131
5273
|
import * as os from "os";
|
|
5132
5274
|
import * as path6 from "path";
|
|
5133
|
-
function transportDetail(error, timeoutMs) {
|
|
5134
|
-
if (error instanceof Error && error.name === "AbortError") return `timed out after ${Math.round(timeoutMs / 1e3)}s`;
|
|
5135
|
-
const cause = error instanceof Error && error.cause instanceof Error ? error.cause : void 0;
|
|
5136
|
-
const code = cause && "code" in cause && typeof cause.code === "string" ? `${cause.code}: ` : "";
|
|
5137
|
-
const message = cause?.message ?? (error instanceof Error ? error.message : String(error));
|
|
5138
|
-
return `${code}${message}`;
|
|
5139
|
-
}
|
|
5140
5275
|
async function api(creds, method, route, body, init2 = {}) {
|
|
5141
|
-
const
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
let res;
|
|
5145
|
-
try {
|
|
5146
|
-
res = await fetch(`${creds.host}${route}`, {
|
|
5147
|
-
method,
|
|
5148
|
-
headers: {
|
|
5149
|
-
"content-type": "application/json",
|
|
5150
|
-
accept: "application/json",
|
|
5151
|
-
authorization: "Basic " + Buffer.from(`${creds.publicKey}:${creds.secretKey}`).toString("base64")
|
|
5152
|
-
},
|
|
5153
|
-
...body === void 0 ? {} : { body: JSON.stringify(body) },
|
|
5154
|
-
signal: controller.signal
|
|
5155
|
-
});
|
|
5156
|
-
} catch (error) {
|
|
5157
|
-
clearTimeout(timer);
|
|
5158
|
-
throw new UnreachableError(creds.host, method, route, transportDetail(error, timeoutMs));
|
|
5159
|
-
}
|
|
5160
|
-
try {
|
|
5161
|
-
const text2 = await res.text();
|
|
5162
|
-
if (!res.ok) throw new ApiError(res.status, method, route, text2);
|
|
5163
|
-
return text2 ? JSON.parse(text2) : {};
|
|
5164
|
-
} finally {
|
|
5165
|
-
clearTimeout(timer);
|
|
5166
|
-
}
|
|
5276
|
+
const reply = await new PlatformTransport(creds).send(method, route, body, init2);
|
|
5277
|
+
if (!reply.ok) throw new ApiError2(reply.status, method, route, reply.text);
|
|
5278
|
+
return reply.text ? JSON.parse(reply.text) : {};
|
|
5167
5279
|
}
|
|
5168
|
-
var
|
|
5280
|
+
var ApiError2;
|
|
5169
5281
|
var init_config = __esm({
|
|
5170
5282
|
"src/cli/config.ts"() {
|
|
5171
5283
|
"use strict";
|
|
5172
5284
|
init_router();
|
|
5173
5285
|
init_worlds();
|
|
5174
|
-
|
|
5286
|
+
init_transport();
|
|
5287
|
+
ApiError2 = class extends CliError {
|
|
5175
5288
|
constructor(status, method, route, text2) {
|
|
5176
5289
|
const body = parseErrorBody(text2);
|
|
5177
5290
|
super(`${method} ${route} -> ${status}: ${body.detail}`, 1);
|
|
@@ -5187,19 +5300,6 @@ var init_config = __esm({
|
|
|
5187
5300
|
text;
|
|
5188
5301
|
code;
|
|
5189
5302
|
};
|
|
5190
|
-
UnreachableError = class extends CliError {
|
|
5191
|
-
constructor(host, method, route, detail) {
|
|
5192
|
-
super(`${method} ${route}: no answer from ${host} (${detail}). Check the host and the network, then retry.`, 1);
|
|
5193
|
-
this.host = host;
|
|
5194
|
-
this.method = method;
|
|
5195
|
-
this.route = route;
|
|
5196
|
-
this.detail = detail;
|
|
5197
|
-
}
|
|
5198
|
-
host;
|
|
5199
|
-
method;
|
|
5200
|
-
route;
|
|
5201
|
-
detail;
|
|
5202
|
-
};
|
|
5203
5303
|
}
|
|
5204
5304
|
});
|
|
5205
5305
|
|
|
@@ -5378,7 +5478,7 @@ var init_local = __esm({
|
|
|
5378
5478
|
"use strict";
|
|
5379
5479
|
init_router();
|
|
5380
5480
|
init_config();
|
|
5381
|
-
MIN_PYTHON = [3,
|
|
5481
|
+
MIN_PYTHON = [3, 12];
|
|
5382
5482
|
DIAGNOSTIC_TAIL = 600;
|
|
5383
5483
|
BRIDGE_BOOTSTRAP = `import sys,runpy,types,os
|
|
5384
5484
|
root=sys.argv[1]
|
|
@@ -5390,7 +5490,6 @@ runpy.run_module('gatewaysdk.environment.schema.platform',run_name='__main__')`;
|
|
|
5390
5490
|
PYTHON_CANDIDATES = [
|
|
5391
5491
|
"python3.13",
|
|
5392
5492
|
"python3.12",
|
|
5393
|
-
"python3.11",
|
|
5394
5493
|
"python3",
|
|
5395
5494
|
"python"
|
|
5396
5495
|
];
|
|
@@ -5502,53 +5601,41 @@ function runsLocally(request) {
|
|
|
5502
5601
|
async function runtime(creds, request, opts = {}) {
|
|
5503
5602
|
const local = localRuntime();
|
|
5504
5603
|
if (local && runsLocally(request)) {
|
|
5505
|
-
const
|
|
5506
|
-
const
|
|
5507
|
-
if (
|
|
5508
|
-
return
|
|
5604
|
+
const payload2 = await localBridge(request, local, opts);
|
|
5605
|
+
const detail2 = detailFrom(payload2);
|
|
5606
|
+
if (detail2) throw new BridgeRejected(detail2);
|
|
5607
|
+
return payload2;
|
|
5509
5608
|
}
|
|
5510
5609
|
if (!creds)
|
|
5511
5610
|
throw new CliError(
|
|
5512
5611
|
"This needs the schema runtime (the CLI bundles it) or platform credentials (`gateway auth login`). " + localRuntimeReason()
|
|
5513
5612
|
);
|
|
5514
|
-
const controller = new AbortController();
|
|
5515
|
-
const timer = setTimeout(() => controller.abort(), opts.timeoutMs ?? 18e4);
|
|
5516
5613
|
const route = "/api/public/worlds/runtime";
|
|
5614
|
+
const res = await new PlatformTransport(creds).send("POST", route, request, {
|
|
5615
|
+
timeoutMs: opts.timeoutMs ?? RUNTIME_TIMEOUT_MS
|
|
5616
|
+
});
|
|
5617
|
+
let payload = null;
|
|
5517
5618
|
try {
|
|
5518
|
-
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
"content-type": "application/json",
|
|
5522
|
-
accept: "application/json",
|
|
5523
|
-
authorization: "Basic " + Buffer.from(`${creds.publicKey}:${creds.secretKey}`).toString("base64")
|
|
5524
|
-
},
|
|
5525
|
-
body: JSON.stringify(request),
|
|
5526
|
-
signal: controller.signal
|
|
5527
|
-
});
|
|
5528
|
-
const text2 = await res.text();
|
|
5529
|
-
let payload = null;
|
|
5530
|
-
try {
|
|
5531
|
-
payload = text2 ? JSON.parse(text2) : {};
|
|
5532
|
-
} catch {
|
|
5533
|
-
payload = null;
|
|
5534
|
-
}
|
|
5535
|
-
const detail = detailFrom(payload);
|
|
5536
|
-
if (detail) throw new BridgeRejected(detail);
|
|
5537
|
-
if (!res.ok)
|
|
5538
|
-
throw new CliError(`POST ${route} (${request.command}) -> ${res.status}: ${text2.slice(0, 600)}`, 1);
|
|
5539
|
-
if (payload === null) throw new CliError(`POST ${route} (${request.command}) returned non-JSON`, 1);
|
|
5540
|
-
return payload;
|
|
5541
|
-
} finally {
|
|
5542
|
-
clearTimeout(timer);
|
|
5619
|
+
payload = res.text ? JSON.parse(res.text) : {};
|
|
5620
|
+
} catch {
|
|
5621
|
+
payload = null;
|
|
5543
5622
|
}
|
|
5623
|
+
const detail = detailFrom(payload);
|
|
5624
|
+
if (detail) throw new BridgeRejected(detail);
|
|
5625
|
+
if (!res.ok)
|
|
5626
|
+
throw new CliError(`POST ${route} (${request.command}) -> ${res.status}: ${res.text.slice(0, 600)}`, 1);
|
|
5627
|
+
if (payload === null) throw new CliError(`POST ${route} (${request.command}) returned non-JSON`, 1);
|
|
5628
|
+
return payload;
|
|
5544
5629
|
}
|
|
5545
|
-
var MAX_WORLD_FILES, SKIP_DIRS, BUILD_OUTPUT, BridgeRejected, YAML_NAME;
|
|
5630
|
+
var MAX_WORLD_FILES, RUNTIME_TIMEOUT_MS, SKIP_DIRS, BUILD_OUTPUT, BridgeRejected, YAML_NAME;
|
|
5546
5631
|
var init_client = __esm({
|
|
5547
5632
|
"src/cli/runtime/client.ts"() {
|
|
5548
5633
|
"use strict";
|
|
5549
5634
|
init_router();
|
|
5550
5635
|
init_local();
|
|
5636
|
+
init_transport();
|
|
5551
5637
|
MAX_WORLD_FILES = 2e3;
|
|
5638
|
+
RUNTIME_TIMEOUT_MS = 18e4;
|
|
5552
5639
|
SKIP_DIRS = /* @__PURE__ */ new Set(["__pycache__", ".git", "node_modules", ".gateway"]);
|
|
5553
5640
|
BUILD_OUTPUT = /(^|\/)state\.(sqlite|json)$/;
|
|
5554
5641
|
BridgeRejected = class extends CliError {
|
|
@@ -6680,7 +6767,7 @@ var init_dryRun = __esm({
|
|
|
6680
6767
|
// src/worlds/index.ts
|
|
6681
6768
|
var worlds_exports = {};
|
|
6682
6769
|
__export(worlds_exports, {
|
|
6683
|
-
ApiError: () =>
|
|
6770
|
+
ApiError: () => ApiError,
|
|
6684
6771
|
BROWSER_GONE_PATTERNS: () => BROWSER_GONE_PATTERNS,
|
|
6685
6772
|
BROWSER_TIERS: () => BROWSER_TIERS,
|
|
6686
6773
|
BrowserActionRecorder: () => BrowserActionRecorder,
|
|
@@ -6706,8 +6793,12 @@ __export(worlds_exports, {
|
|
|
6706
6793
|
HostedDryRunClient: () => HostedDryRunClient,
|
|
6707
6794
|
IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
|
|
6708
6795
|
NO_GRADER_REASON: () => NO_GRADER_REASON,
|
|
6796
|
+
PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
6797
|
+
PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
|
|
6798
|
+
PlatformTransport: () => PlatformTransport,
|
|
6709
6799
|
PushSlugConflict: () => PushSlugConflict,
|
|
6710
6800
|
RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
|
|
6801
|
+
SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
|
|
6711
6802
|
SESSION_STATES: () => SESSION_STATES,
|
|
6712
6803
|
STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
|
|
6713
6804
|
STRIP_PREFIX: () => STRIP_PREFIX,
|
|
@@ -6716,6 +6807,8 @@ __export(worlds_exports, {
|
|
|
6716
6807
|
TRANSFORMS: () => TRANSFORMS,
|
|
6717
6808
|
TaskRun: () => TaskRun,
|
|
6718
6809
|
TaskSessions: () => TaskSessions,
|
|
6810
|
+
TransportCause: () => TransportCause,
|
|
6811
|
+
UnreachableError: () => UnreachableError,
|
|
6719
6812
|
VERIFIER_REWARD_PREFIX: () => VERIFIER_REWARD_PREFIX,
|
|
6720
6813
|
WHITESPACE: () => WHITESPACE,
|
|
6721
6814
|
WorldBrowser: () => WorldBrowser,
|
|
@@ -6783,6 +6876,7 @@ __export(worlds_exports, {
|
|
|
6783
6876
|
parseToolCallRecord: () => parseToolCallRecord,
|
|
6784
6877
|
parseTransform: () => parseTransform,
|
|
6785
6878
|
parseWorldTaskRefs: () => parseWorldTaskRefs,
|
|
6879
|
+
platformTimeoutMs: () => platformTimeoutMs,
|
|
6786
6880
|
preserveForm: () => preserveForm,
|
|
6787
6881
|
propose: () => propose,
|
|
6788
6882
|
pull: () => pull,
|
|
@@ -6794,6 +6888,7 @@ __export(worlds_exports, {
|
|
|
6794
6888
|
queryRowsSearch: () => queryRowsSearch,
|
|
6795
6889
|
readLocalMeta: () => readLocalMeta,
|
|
6796
6890
|
readToolCallRecords: () => readToolCallRecords,
|
|
6891
|
+
rebaseConflicts: () => rebaseConflicts,
|
|
6797
6892
|
redactActionArgs: () => redactActionArgs,
|
|
6798
6893
|
redactionOf: () => redactionOf,
|
|
6799
6894
|
releaseConnection: () => releaseConnection,
|
|
@@ -6816,6 +6911,7 @@ __export(worlds_exports, {
|
|
|
6816
6911
|
toolCallsFromObservations: () => toolCallsFromObservations,
|
|
6817
6912
|
uiEntryUrl: () => uiEntryUrl,
|
|
6818
6913
|
uiUrl: () => uiUrl,
|
|
6914
|
+
uncommittedPaths: () => uncommittedPaths,
|
|
6819
6915
|
updateTask: () => updateTask,
|
|
6820
6916
|
upsertRunConfig: () => upsertRunConfig,
|
|
6821
6917
|
validateTask: () => validateTask,
|
|
@@ -6854,19 +6950,10 @@ function parseErrorBody(text2, limit = 600) {
|
|
|
6854
6950
|
code: stableCode
|
|
6855
6951
|
};
|
|
6856
6952
|
}
|
|
6857
|
-
async function apiRequest(options, method, path12, body) {
|
|
6858
|
-
const
|
|
6859
|
-
|
|
6860
|
-
|
|
6861
|
-
headers: {
|
|
6862
|
-
"content-type": "application/json",
|
|
6863
|
-
authorization: "Basic " + Buffer.from(`${publicKey}:${secretKey}`).toString("base64")
|
|
6864
|
-
},
|
|
6865
|
-
...body === void 0 ? {} : { body: JSON.stringify(body) }
|
|
6866
|
-
});
|
|
6867
|
-
const text2 = await res.text();
|
|
6868
|
-
if (!res.ok) throw new ApiError2(res.status, method, path12, text2);
|
|
6869
|
-
return JSON.parse(text2);
|
|
6953
|
+
async function apiRequest(options, method, path12, body, init2 = {}) {
|
|
6954
|
+
const reply = await new PlatformTransport(resolveEnv(options)).send(method, path12, body, init2);
|
|
6955
|
+
if (!reply.ok) throw new ApiError(reply.status, method, path12, reply.text);
|
|
6956
|
+
return JSON.parse(reply.text);
|
|
6870
6957
|
}
|
|
6871
6958
|
async function setEnvSecret(slug, key, value, options = {}) {
|
|
6872
6959
|
return apiRequest(
|
|
@@ -7042,9 +7129,11 @@ async function resolveWorld(slugRef, slug, ref, pin, options) {
|
|
|
7042
7129
|
}
|
|
7043
7130
|
return world;
|
|
7044
7131
|
}
|
|
7045
|
-
var
|
|
7132
|
+
var ApiError, WorldTask, WorldSet;
|
|
7046
7133
|
var init_worlds = __esm({
|
|
7047
7134
|
"src/worlds/index.ts"() {
|
|
7135
|
+
init_transport();
|
|
7136
|
+
init_transport();
|
|
7048
7137
|
init_session();
|
|
7049
7138
|
init_sessionList();
|
|
7050
7139
|
init_sessionContract();
|
|
@@ -7068,15 +7157,17 @@ var init_worlds = __esm({
|
|
|
7068
7157
|
init_sandbox();
|
|
7069
7158
|
init_editSessions();
|
|
7070
7159
|
init_dryRun();
|
|
7071
|
-
|
|
7072
|
-
constructor(status, method, path12,
|
|
7073
|
-
const parsed = parseErrorBody(
|
|
7160
|
+
ApiError = class extends Error {
|
|
7161
|
+
constructor(status, method, path12, text2) {
|
|
7162
|
+
const parsed = parseErrorBody(text2);
|
|
7074
7163
|
super(`${method} ${path12} -> ${status}: ${parsed.detail}`);
|
|
7075
7164
|
this.status = status;
|
|
7165
|
+
this.text = text2;
|
|
7076
7166
|
this.name = "ApiError";
|
|
7077
7167
|
this.code = parsed.code;
|
|
7078
7168
|
}
|
|
7079
7169
|
status;
|
|
7170
|
+
text;
|
|
7080
7171
|
code;
|
|
7081
7172
|
};
|
|
7082
7173
|
WorldTask = class {
|
|
@@ -7155,7 +7246,7 @@ var init_worlds = __esm({
|
|
|
7155
7246
|
});
|
|
7156
7247
|
init_worlds();
|
|
7157
7248
|
export {
|
|
7158
|
-
|
|
7249
|
+
ApiError,
|
|
7159
7250
|
BROWSER_GONE_PATTERNS,
|
|
7160
7251
|
BROWSER_TIERS,
|
|
7161
7252
|
BrowserActionRecorder,
|
|
@@ -7181,8 +7272,12 @@ export {
|
|
|
7181
7272
|
HostedDryRunClient,
|
|
7182
7273
|
IDLE_WARNING_MINUTES,
|
|
7183
7274
|
NO_GRADER_REASON,
|
|
7275
|
+
PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
7276
|
+
PLATFORM_TIMEOUT_ENV,
|
|
7277
|
+
PlatformTransport,
|
|
7184
7278
|
PushSlugConflict,
|
|
7185
7279
|
RECOVER_BUDGET_MS,
|
|
7280
|
+
SANDBOX_REQUEST_TIMEOUT_MS,
|
|
7186
7281
|
SESSION_STATES,
|
|
7187
7282
|
STATUS_WAIT_CAP_SECONDS,
|
|
7188
7283
|
STRIP_PREFIX,
|
|
@@ -7191,6 +7286,8 @@ export {
|
|
|
7191
7286
|
TRANSFORMS,
|
|
7192
7287
|
TaskRun,
|
|
7193
7288
|
TaskSessions,
|
|
7289
|
+
TransportCause,
|
|
7290
|
+
UnreachableError,
|
|
7194
7291
|
VERIFIER_REWARD_PREFIX,
|
|
7195
7292
|
WHITESPACE,
|
|
7196
7293
|
WorldBrowser,
|
|
@@ -7258,6 +7355,7 @@ export {
|
|
|
7258
7355
|
parseToolCallRecord,
|
|
7259
7356
|
parseTransform,
|
|
7260
7357
|
parseWorldTaskRefs,
|
|
7358
|
+
platformTimeoutMs,
|
|
7261
7359
|
preserveForm,
|
|
7262
7360
|
propose,
|
|
7263
7361
|
pull,
|
|
@@ -7269,6 +7367,7 @@ export {
|
|
|
7269
7367
|
queryRowsSearch,
|
|
7270
7368
|
readLocalMeta,
|
|
7271
7369
|
readToolCallRecords,
|
|
7370
|
+
rebaseConflicts,
|
|
7272
7371
|
redactActionArgs,
|
|
7273
7372
|
redactionOf,
|
|
7274
7373
|
releaseConnection,
|
|
@@ -7291,6 +7390,7 @@ export {
|
|
|
7291
7390
|
toolCallsFromObservations,
|
|
7292
7391
|
uiEntryUrl,
|
|
7293
7392
|
uiUrl,
|
|
7393
|
+
uncommittedPaths,
|
|
7294
7394
|
updateTask,
|
|
7295
7395
|
upsertRunConfig,
|
|
7296
7396
|
validateTask,
|