@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/index.mjs
CHANGED
|
@@ -450,6 +450,115 @@ var init_scores = __esm({
|
|
|
450
450
|
}
|
|
451
451
|
});
|
|
452
452
|
|
|
453
|
+
// src/worlds/transport.ts
|
|
454
|
+
function platformTimeoutMs(env = process.env) {
|
|
455
|
+
const raw = env[PLATFORM_TIMEOUT_ENV];
|
|
456
|
+
if (raw === void 0 || raw === "") return PLATFORM_TIMEOUT_DEFAULT_MS;
|
|
457
|
+
const value = Number(raw);
|
|
458
|
+
if (Number.isInteger(value) && value > 0) return value;
|
|
459
|
+
throw new Error(`${PLATFORM_TIMEOUT_ENV} must be a positive whole number of milliseconds, not \`${raw}\`.`);
|
|
460
|
+
}
|
|
461
|
+
var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, PlatformTransport;
|
|
462
|
+
var init_transport = __esm({
|
|
463
|
+
"src/worlds/transport.ts"() {
|
|
464
|
+
"use strict";
|
|
465
|
+
PLATFORM_TIMEOUT_ENV = "GATEWAY_TIMEOUT_MS";
|
|
466
|
+
PLATFORM_TIMEOUT_DEFAULT_MS = 12e4;
|
|
467
|
+
CHECK_HOST = "Check GATEWAY_HOST (or --host) points at a running platform, then retry.";
|
|
468
|
+
RETRY = "Retry; if it repeats, check the network between here and the platform.";
|
|
469
|
+
CAUSES = {
|
|
470
|
+
ECONNREFUSED: { reason: "connection refused", next: CHECK_HOST },
|
|
471
|
+
ENOTFOUND: { reason: "DNS lookup failed", next: CHECK_HOST },
|
|
472
|
+
EAI_AGAIN: { reason: "DNS lookup failed", next: CHECK_HOST },
|
|
473
|
+
ETIMEDOUT: { reason: "connect timed out", next: CHECK_HOST },
|
|
474
|
+
UND_ERR_CONNECT_TIMEOUT: { reason: "connect timed out", next: CHECK_HOST },
|
|
475
|
+
EHOSTUNREACH: { reason: "host unreachable", next: CHECK_HOST },
|
|
476
|
+
ENETUNREACH: { reason: "network unreachable", next: RETRY },
|
|
477
|
+
ECONNRESET: { reason: "connection dropped", next: RETRY },
|
|
478
|
+
UND_ERR_SOCKET: { reason: "connection dropped", next: RETRY },
|
|
479
|
+
EPIPE: { reason: "connection dropped", next: RETRY }
|
|
480
|
+
};
|
|
481
|
+
UNKNOWN_CAUSE = { reason: "network error", next: CHECK_HOST };
|
|
482
|
+
TransportCause = class _TransportCause {
|
|
483
|
+
constructor(reason, detail, next) {
|
|
484
|
+
this.reason = reason;
|
|
485
|
+
this.detail = detail;
|
|
486
|
+
this.next = next;
|
|
487
|
+
}
|
|
488
|
+
reason;
|
|
489
|
+
detail;
|
|
490
|
+
next;
|
|
491
|
+
static timeout(timeoutMs) {
|
|
492
|
+
return new _TransportCause(
|
|
493
|
+
`timed out after ${timeoutMs / 1e3}s`,
|
|
494
|
+
null,
|
|
495
|
+
`Retry; if the platform is slow, raise ${PLATFORM_TIMEOUT_ENV} (milliseconds per request).`
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
static of(error) {
|
|
499
|
+
const cause = error instanceof Error && error.cause instanceof Error ? error.cause : void 0;
|
|
500
|
+
const code = cause && "code" in cause && typeof cause.code === "string" ? cause.code : null;
|
|
501
|
+
const message = cause?.message ?? (error instanceof Error ? error.message : String(error));
|
|
502
|
+
const known = code && CAUSES[code] || UNKNOWN_CAUSE;
|
|
503
|
+
return new _TransportCause(known.reason, code ? `${code}: ${message}` : message, known.next);
|
|
504
|
+
}
|
|
505
|
+
describe() {
|
|
506
|
+
return this.detail === null ? this.reason : `${this.reason} (${this.detail})`;
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
UnreachableError = class extends Error {
|
|
510
|
+
constructor(host, method, route, failure) {
|
|
511
|
+
super(`${method} ${route}: no answer from ${host}: ${failure.describe()}. ${failure.next}`);
|
|
512
|
+
this.host = host;
|
|
513
|
+
this.method = method;
|
|
514
|
+
this.route = route;
|
|
515
|
+
this.failure = failure;
|
|
516
|
+
this.name = "UnreachableError";
|
|
517
|
+
}
|
|
518
|
+
host;
|
|
519
|
+
method;
|
|
520
|
+
route;
|
|
521
|
+
failure;
|
|
522
|
+
};
|
|
523
|
+
PlatformTransport = class {
|
|
524
|
+
constructor(endpoint, timeoutMs = platformTimeoutMs()) {
|
|
525
|
+
this.endpoint = endpoint;
|
|
526
|
+
this.timeoutMs = timeoutMs;
|
|
527
|
+
}
|
|
528
|
+
endpoint;
|
|
529
|
+
timeoutMs;
|
|
530
|
+
/** A request that legitimately takes longer (a sandbox exec, a world create) waits its own budget; every other one waits the default. */
|
|
531
|
+
budget(ownMs) {
|
|
532
|
+
return Math.max(ownMs ?? 0, this.timeoutMs);
|
|
533
|
+
}
|
|
534
|
+
async send(method, route, body, opts = {}) {
|
|
535
|
+
const timeoutMs = this.budget(opts.timeoutMs);
|
|
536
|
+
const payload = body === void 0 ? {} : { body: JSON.stringify(body) };
|
|
537
|
+
const controller = new AbortController();
|
|
538
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
539
|
+
try {
|
|
540
|
+
const res = await fetch(`${this.endpoint.host}${route}`, {
|
|
541
|
+
method,
|
|
542
|
+
headers: {
|
|
543
|
+
"content-type": "application/json",
|
|
544
|
+
accept: "application/json",
|
|
545
|
+
authorization: "Basic " + Buffer.from(`${this.endpoint.publicKey}:${this.endpoint.secretKey}`).toString("base64")
|
|
546
|
+
},
|
|
547
|
+
...payload,
|
|
548
|
+
signal: controller.signal
|
|
549
|
+
});
|
|
550
|
+
return { status: res.status, ok: res.ok, text: await res.text() };
|
|
551
|
+
} catch (error) {
|
|
552
|
+
const cause = controller.signal.aborted ? TransportCause.timeout(timeoutMs) : TransportCause.of(error);
|
|
553
|
+
throw new UnreachableError(this.endpoint.host, method, route, cause);
|
|
554
|
+
} finally {
|
|
555
|
+
clearTimeout(timer);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
|
|
453
562
|
// src/worlds/browserReconnect.ts
|
|
454
563
|
async function closeConnection(c) {
|
|
455
564
|
await c.context.close();
|
|
@@ -2458,7 +2567,7 @@ var require_package = __commonJS({
|
|
|
2458
2567
|
"package.json"(exports, module) {
|
|
2459
2568
|
module.exports = {
|
|
2460
2569
|
name: "@withgateway/sdk",
|
|
2461
|
-
version: "0.2.
|
|
2570
|
+
version: "0.2.9",
|
|
2462
2571
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
2463
2572
|
main: "./dist/index.js",
|
|
2464
2573
|
module: "./dist/index.mjs",
|
|
@@ -4650,6 +4759,34 @@ function parseSlugRef(slugRef) {
|
|
|
4650
4759
|
if (at === -1) return { slug: slugRef };
|
|
4651
4760
|
return { slug: slugRef.slice(0, at), ref: slugRef.slice(at + 1) };
|
|
4652
4761
|
}
|
|
4762
|
+
function rebaseConflicts(error) {
|
|
4763
|
+
if (!(error instanceof ApiError) || error.status !== 409) return null;
|
|
4764
|
+
let body;
|
|
4765
|
+
try {
|
|
4766
|
+
body = JSON.parse(error.text);
|
|
4767
|
+
} catch {
|
|
4768
|
+
return null;
|
|
4769
|
+
}
|
|
4770
|
+
const conflicts = body?.conflicts;
|
|
4771
|
+
if (!Array.isArray(conflicts)) return null;
|
|
4772
|
+
return conflicts.filter(isConflictPath).map(({ path: path16, reason }) => ({ path: path16, reason }));
|
|
4773
|
+
}
|
|
4774
|
+
function isConflictPath(value) {
|
|
4775
|
+
const entry = value;
|
|
4776
|
+
return typeof entry?.path === "string" && typeof entry.reason === "string";
|
|
4777
|
+
}
|
|
4778
|
+
function uncommittedPaths(error) {
|
|
4779
|
+
if (!(error instanceof ApiError) || error.status !== 409 || error.code !== "sandbox_uncommitted") return null;
|
|
4780
|
+
let body;
|
|
4781
|
+
try {
|
|
4782
|
+
body = JSON.parse(error.text);
|
|
4783
|
+
} catch {
|
|
4784
|
+
return null;
|
|
4785
|
+
}
|
|
4786
|
+
const uncommitted = body?.uncommitted;
|
|
4787
|
+
if (!Array.isArray(uncommitted)) return null;
|
|
4788
|
+
return uncommitted.filter((p) => typeof p === "string");
|
|
4789
|
+
}
|
|
4653
4790
|
function listQuery(filter) {
|
|
4654
4791
|
const params = new URLSearchParams();
|
|
4655
4792
|
if (filter.status) params.set("status", filter.status);
|
|
@@ -4658,18 +4795,25 @@ function listQuery(filter) {
|
|
|
4658
4795
|
const qs3 = params.toString();
|
|
4659
4796
|
return qs3 ? `?${qs3}` : "";
|
|
4660
4797
|
}
|
|
4661
|
-
var isSandboxImportPending, sid, WorldSandboxClient;
|
|
4798
|
+
var isSandboxImportPending, sid, SANDBOXES, SANDBOX_REQUEST_TIMEOUT_MS, WorldSandboxClient;
|
|
4662
4799
|
var init_sandbox = __esm({
|
|
4663
4800
|
"src/worlds/sandbox.ts"() {
|
|
4664
4801
|
"use strict";
|
|
4665
4802
|
init_worlds();
|
|
4666
4803
|
isSandboxImportPending = (answer) => !("versionId" in answer);
|
|
4667
4804
|
sid = encodeURIComponent;
|
|
4805
|
+
SANDBOXES = "/api/public/benchmark-containers/sandboxes";
|
|
4806
|
+
SANDBOX_REQUEST_TIMEOUT_MS = 66e4;
|
|
4668
4807
|
WorldSandboxClient = class {
|
|
4669
4808
|
constructor(options = {}) {
|
|
4670
4809
|
this.options = options;
|
|
4671
4810
|
}
|
|
4672
4811
|
options;
|
|
4812
|
+
request(method, path16, body) {
|
|
4813
|
+
return apiRequest(this.options, method, path16, body, {
|
|
4814
|
+
timeoutMs: SANDBOX_REQUEST_TIMEOUT_MS
|
|
4815
|
+
});
|
|
4816
|
+
}
|
|
4673
4817
|
/**
|
|
4674
4818
|
* `{ slug, ref? }` opens a READY version; `{ new, from }` opens a sandbox on
|
|
4675
4819
|
* a world that does not exist yet (409 `world_exists` if the slug is taken,
|
|
@@ -4677,42 +4821,39 @@ var init_sandbox = __esm({
|
|
|
4677
4821
|
* creates the world on `main`.
|
|
4678
4822
|
*/
|
|
4679
4823
|
open(target) {
|
|
4680
|
-
return
|
|
4824
|
+
return this.request("POST", `${SANDBOXES}`, target);
|
|
4681
4825
|
}
|
|
4682
4826
|
status(sandboxId) {
|
|
4683
|
-
return
|
|
4827
|
+
return this.request("GET", `${SANDBOXES}/${sid(sandboxId)}`);
|
|
4684
4828
|
}
|
|
4685
4829
|
/** The project's sandboxes, newest first — how an agent finds one it left open. */
|
|
4686
4830
|
async list(filter = {}) {
|
|
4687
|
-
const res = await
|
|
4688
|
-
this.options,
|
|
4689
|
-
"GET",
|
|
4690
|
-
`/api/public/benchmark-containers/sandboxes${listQuery(filter)}`
|
|
4691
|
-
);
|
|
4831
|
+
const res = await this.request("GET", `${SANDBOXES}${listQuery(filter)}`);
|
|
4692
4832
|
return res.sandboxes;
|
|
4693
4833
|
}
|
|
4694
4834
|
async read(sandboxId, filePath) {
|
|
4695
|
-
const res = await
|
|
4696
|
-
this.options,
|
|
4835
|
+
const res = await this.request(
|
|
4697
4836
|
"GET",
|
|
4698
|
-
|
|
4837
|
+
`${SANDBOXES}/${sid(sandboxId)}/file?path=${encodeURIComponent(filePath)}`
|
|
4699
4838
|
);
|
|
4700
4839
|
return { path: res.path, size: res.size, bytes: Buffer.from(res.contentBase64, "base64") };
|
|
4701
4840
|
}
|
|
4702
4841
|
write(sandboxId, filePath, bytes) {
|
|
4703
|
-
return
|
|
4842
|
+
return this.request("PUT", `${SANDBOXES}/${sid(sandboxId)}/file`, {
|
|
4704
4843
|
path: filePath,
|
|
4705
4844
|
contentBase64: bytes.toString("base64")
|
|
4706
4845
|
});
|
|
4707
4846
|
}
|
|
4708
4847
|
exec(sandboxId, input) {
|
|
4709
|
-
return
|
|
4848
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/exec`, input);
|
|
4710
4849
|
}
|
|
4711
4850
|
check(sandboxId) {
|
|
4712
|
-
return
|
|
4851
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/check`, {});
|
|
4713
4852
|
}
|
|
4853
|
+
/** With `rebase`, a moved base is replayed onto; a 409 then names the conflicting paths (`rebaseConflicts`). */
|
|
4714
4854
|
commit(sandboxId, input) {
|
|
4715
|
-
|
|
4855
|
+
const { rebase, ...rest } = input;
|
|
4856
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/commit`, rebase ? { ...rest, rebase: true } : rest);
|
|
4716
4857
|
}
|
|
4717
4858
|
/**
|
|
4718
4859
|
* A rows file already in the sandbox tree into the PLATFORM world the
|
|
@@ -4721,10 +4862,11 @@ var init_sandbox = __esm({
|
|
|
4721
4862
|
* tree and never carries data.
|
|
4722
4863
|
*/
|
|
4723
4864
|
importData(sandboxId, input) {
|
|
4724
|
-
return
|
|
4865
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/import`, input);
|
|
4725
4866
|
}
|
|
4726
|
-
|
|
4727
|
-
|
|
4867
|
+
/** Uncommitted work is a 409 (`uncommittedPaths`) unless `force` discards it. */
|
|
4868
|
+
close(sandboxId, opts = {}) {
|
|
4869
|
+
return this.request("DELETE", `${SANDBOXES}/${sid(sandboxId)}`, opts.force ? { force: true } : void 0);
|
|
4728
4870
|
}
|
|
4729
4871
|
};
|
|
4730
4872
|
}
|
|
@@ -5256,48 +5398,19 @@ var init_router = __esm({
|
|
|
5256
5398
|
import * as fs6 from "fs";
|
|
5257
5399
|
import * as os from "os";
|
|
5258
5400
|
import * as path6 from "path";
|
|
5259
|
-
function transportDetail(error, timeoutMs) {
|
|
5260
|
-
if (error instanceof Error && error.name === "AbortError") return `timed out after ${Math.round(timeoutMs / 1e3)}s`;
|
|
5261
|
-
const cause = error instanceof Error && error.cause instanceof Error ? error.cause : void 0;
|
|
5262
|
-
const code = cause && "code" in cause && typeof cause.code === "string" ? `${cause.code}: ` : "";
|
|
5263
|
-
const message = cause?.message ?? (error instanceof Error ? error.message : String(error));
|
|
5264
|
-
return `${code}${message}`;
|
|
5265
|
-
}
|
|
5266
5401
|
async function api(creds, method, route, body, init3 = {}) {
|
|
5267
|
-
const
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
let res;
|
|
5271
|
-
try {
|
|
5272
|
-
res = await fetch(`${creds.host}${route}`, {
|
|
5273
|
-
method,
|
|
5274
|
-
headers: {
|
|
5275
|
-
"content-type": "application/json",
|
|
5276
|
-
accept: "application/json",
|
|
5277
|
-
authorization: "Basic " + Buffer.from(`${creds.publicKey}:${creds.secretKey}`).toString("base64")
|
|
5278
|
-
},
|
|
5279
|
-
...body === void 0 ? {} : { body: JSON.stringify(body) },
|
|
5280
|
-
signal: controller.signal
|
|
5281
|
-
});
|
|
5282
|
-
} catch (error) {
|
|
5283
|
-
clearTimeout(timer);
|
|
5284
|
-
throw new UnreachableError(creds.host, method, route, transportDetail(error, timeoutMs));
|
|
5285
|
-
}
|
|
5286
|
-
try {
|
|
5287
|
-
const text2 = await res.text();
|
|
5288
|
-
if (!res.ok) throw new ApiError(res.status, method, route, text2);
|
|
5289
|
-
return text2 ? JSON.parse(text2) : {};
|
|
5290
|
-
} finally {
|
|
5291
|
-
clearTimeout(timer);
|
|
5292
|
-
}
|
|
5402
|
+
const reply = await new PlatformTransport(creds).send(method, route, body, init3);
|
|
5403
|
+
if (!reply.ok) throw new ApiError2(reply.status, method, route, reply.text);
|
|
5404
|
+
return reply.text ? JSON.parse(reply.text) : {};
|
|
5293
5405
|
}
|
|
5294
|
-
var
|
|
5406
|
+
var ApiError2;
|
|
5295
5407
|
var init_config = __esm({
|
|
5296
5408
|
"src/cli/config.ts"() {
|
|
5297
5409
|
"use strict";
|
|
5298
5410
|
init_router();
|
|
5299
5411
|
init_worlds();
|
|
5300
|
-
|
|
5412
|
+
init_transport();
|
|
5413
|
+
ApiError2 = class extends CliError {
|
|
5301
5414
|
constructor(status, method, route, text2) {
|
|
5302
5415
|
const body = parseErrorBody(text2);
|
|
5303
5416
|
super(`${method} ${route} -> ${status}: ${body.detail}`, 1);
|
|
@@ -5313,19 +5426,6 @@ var init_config = __esm({
|
|
|
5313
5426
|
text;
|
|
5314
5427
|
code;
|
|
5315
5428
|
};
|
|
5316
|
-
UnreachableError = class extends CliError {
|
|
5317
|
-
constructor(host, method, route, detail) {
|
|
5318
|
-
super(`${method} ${route}: no answer from ${host} (${detail}). Check the host and the network, then retry.`, 1);
|
|
5319
|
-
this.host = host;
|
|
5320
|
-
this.method = method;
|
|
5321
|
-
this.route = route;
|
|
5322
|
-
this.detail = detail;
|
|
5323
|
-
}
|
|
5324
|
-
host;
|
|
5325
|
-
method;
|
|
5326
|
-
route;
|
|
5327
|
-
detail;
|
|
5328
|
-
};
|
|
5329
5429
|
}
|
|
5330
5430
|
});
|
|
5331
5431
|
|
|
@@ -5504,7 +5604,7 @@ var init_local = __esm({
|
|
|
5504
5604
|
"use strict";
|
|
5505
5605
|
init_router();
|
|
5506
5606
|
init_config();
|
|
5507
|
-
MIN_PYTHON = [3,
|
|
5607
|
+
MIN_PYTHON = [3, 12];
|
|
5508
5608
|
DIAGNOSTIC_TAIL = 600;
|
|
5509
5609
|
BRIDGE_BOOTSTRAP = `import sys,runpy,types,os
|
|
5510
5610
|
root=sys.argv[1]
|
|
@@ -5516,7 +5616,6 @@ runpy.run_module('gatewaysdk.environment.schema.platform',run_name='__main__')`;
|
|
|
5516
5616
|
PYTHON_CANDIDATES = [
|
|
5517
5617
|
"python3.13",
|
|
5518
5618
|
"python3.12",
|
|
5519
|
-
"python3.11",
|
|
5520
5619
|
"python3",
|
|
5521
5620
|
"python"
|
|
5522
5621
|
];
|
|
@@ -5628,53 +5727,41 @@ function runsLocally(request) {
|
|
|
5628
5727
|
async function runtime(creds, request, opts = {}) {
|
|
5629
5728
|
const local = localRuntime();
|
|
5630
5729
|
if (local && runsLocally(request)) {
|
|
5631
|
-
const
|
|
5632
|
-
const
|
|
5633
|
-
if (
|
|
5634
|
-
return
|
|
5730
|
+
const payload2 = await localBridge(request, local, opts);
|
|
5731
|
+
const detail2 = detailFrom(payload2);
|
|
5732
|
+
if (detail2) throw new BridgeRejected(detail2);
|
|
5733
|
+
return payload2;
|
|
5635
5734
|
}
|
|
5636
5735
|
if (!creds)
|
|
5637
5736
|
throw new CliError(
|
|
5638
5737
|
"This needs the schema runtime (the CLI bundles it) or platform credentials (`gateway auth login`). " + localRuntimeReason()
|
|
5639
5738
|
);
|
|
5640
|
-
const controller = new AbortController();
|
|
5641
|
-
const timer = setTimeout(() => controller.abort(), opts.timeoutMs ?? 18e4);
|
|
5642
5739
|
const route = "/api/public/worlds/runtime";
|
|
5740
|
+
const res = await new PlatformTransport(creds).send("POST", route, request, {
|
|
5741
|
+
timeoutMs: opts.timeoutMs ?? RUNTIME_TIMEOUT_MS
|
|
5742
|
+
});
|
|
5743
|
+
let payload = null;
|
|
5643
5744
|
try {
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
"content-type": "application/json",
|
|
5648
|
-
accept: "application/json",
|
|
5649
|
-
authorization: "Basic " + Buffer.from(`${creds.publicKey}:${creds.secretKey}`).toString("base64")
|
|
5650
|
-
},
|
|
5651
|
-
body: JSON.stringify(request),
|
|
5652
|
-
signal: controller.signal
|
|
5653
|
-
});
|
|
5654
|
-
const text2 = await res.text();
|
|
5655
|
-
let payload = null;
|
|
5656
|
-
try {
|
|
5657
|
-
payload = text2 ? JSON.parse(text2) : {};
|
|
5658
|
-
} catch {
|
|
5659
|
-
payload = null;
|
|
5660
|
-
}
|
|
5661
|
-
const detail = detailFrom(payload);
|
|
5662
|
-
if (detail) throw new BridgeRejected(detail);
|
|
5663
|
-
if (!res.ok)
|
|
5664
|
-
throw new CliError(`POST ${route} (${request.command}) -> ${res.status}: ${text2.slice(0, 600)}`, 1);
|
|
5665
|
-
if (payload === null) throw new CliError(`POST ${route} (${request.command}) returned non-JSON`, 1);
|
|
5666
|
-
return payload;
|
|
5667
|
-
} finally {
|
|
5668
|
-
clearTimeout(timer);
|
|
5745
|
+
payload = res.text ? JSON.parse(res.text) : {};
|
|
5746
|
+
} catch {
|
|
5747
|
+
payload = null;
|
|
5669
5748
|
}
|
|
5749
|
+
const detail = detailFrom(payload);
|
|
5750
|
+
if (detail) throw new BridgeRejected(detail);
|
|
5751
|
+
if (!res.ok)
|
|
5752
|
+
throw new CliError(`POST ${route} (${request.command}) -> ${res.status}: ${res.text.slice(0, 600)}`, 1);
|
|
5753
|
+
if (payload === null) throw new CliError(`POST ${route} (${request.command}) returned non-JSON`, 1);
|
|
5754
|
+
return payload;
|
|
5670
5755
|
}
|
|
5671
|
-
var MAX_WORLD_FILES, SKIP_DIRS, BUILD_OUTPUT, BridgeRejected, YAML_NAME;
|
|
5756
|
+
var MAX_WORLD_FILES, RUNTIME_TIMEOUT_MS, SKIP_DIRS, BUILD_OUTPUT, BridgeRejected, YAML_NAME;
|
|
5672
5757
|
var init_client = __esm({
|
|
5673
5758
|
"src/cli/runtime/client.ts"() {
|
|
5674
5759
|
"use strict";
|
|
5675
5760
|
init_router();
|
|
5676
5761
|
init_local();
|
|
5762
|
+
init_transport();
|
|
5677
5763
|
MAX_WORLD_FILES = 2e3;
|
|
5764
|
+
RUNTIME_TIMEOUT_MS = 18e4;
|
|
5678
5765
|
SKIP_DIRS = /* @__PURE__ */ new Set(["__pycache__", ".git", "node_modules", ".gateway"]);
|
|
5679
5766
|
BUILD_OUTPUT = /(^|\/)state\.(sqlite|json)$/;
|
|
5680
5767
|
BridgeRejected = class extends CliError {
|
|
@@ -6806,7 +6893,7 @@ var init_dryRun = __esm({
|
|
|
6806
6893
|
// src/worlds/index.ts
|
|
6807
6894
|
var worlds_exports = {};
|
|
6808
6895
|
__export(worlds_exports, {
|
|
6809
|
-
ApiError: () =>
|
|
6896
|
+
ApiError: () => ApiError,
|
|
6810
6897
|
BROWSER_GONE_PATTERNS: () => BROWSER_GONE_PATTERNS,
|
|
6811
6898
|
BROWSER_TIERS: () => BROWSER_TIERS,
|
|
6812
6899
|
BrowserActionRecorder: () => BrowserActionRecorder,
|
|
@@ -6832,8 +6919,12 @@ __export(worlds_exports, {
|
|
|
6832
6919
|
HostedDryRunClient: () => HostedDryRunClient,
|
|
6833
6920
|
IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
|
|
6834
6921
|
NO_GRADER_REASON: () => NO_GRADER_REASON,
|
|
6922
|
+
PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
6923
|
+
PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
|
|
6924
|
+
PlatformTransport: () => PlatformTransport,
|
|
6835
6925
|
PushSlugConflict: () => PushSlugConflict,
|
|
6836
6926
|
RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
|
|
6927
|
+
SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
|
|
6837
6928
|
SESSION_STATES: () => SESSION_STATES,
|
|
6838
6929
|
STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
|
|
6839
6930
|
STRIP_PREFIX: () => STRIP_PREFIX,
|
|
@@ -6842,6 +6933,8 @@ __export(worlds_exports, {
|
|
|
6842
6933
|
TRANSFORMS: () => TRANSFORMS,
|
|
6843
6934
|
TaskRun: () => TaskRun,
|
|
6844
6935
|
TaskSessions: () => TaskSessions,
|
|
6936
|
+
TransportCause: () => TransportCause,
|
|
6937
|
+
UnreachableError: () => UnreachableError,
|
|
6845
6938
|
VERIFIER_REWARD_PREFIX: () => VERIFIER_REWARD_PREFIX,
|
|
6846
6939
|
WHITESPACE: () => WHITESPACE,
|
|
6847
6940
|
WorldBrowser: () => WorldBrowser,
|
|
@@ -6909,6 +7002,7 @@ __export(worlds_exports, {
|
|
|
6909
7002
|
parseToolCallRecord: () => parseToolCallRecord,
|
|
6910
7003
|
parseTransform: () => parseTransform,
|
|
6911
7004
|
parseWorldTaskRefs: () => parseWorldTaskRefs,
|
|
7005
|
+
platformTimeoutMs: () => platformTimeoutMs,
|
|
6912
7006
|
preserveForm: () => preserveForm,
|
|
6913
7007
|
propose: () => propose,
|
|
6914
7008
|
pull: () => pull,
|
|
@@ -6920,6 +7014,7 @@ __export(worlds_exports, {
|
|
|
6920
7014
|
queryRowsSearch: () => queryRowsSearch,
|
|
6921
7015
|
readLocalMeta: () => readLocalMeta,
|
|
6922
7016
|
readToolCallRecords: () => readToolCallRecords,
|
|
7017
|
+
rebaseConflicts: () => rebaseConflicts,
|
|
6923
7018
|
redactActionArgs: () => redactActionArgs,
|
|
6924
7019
|
redactionOf: () => redactionOf,
|
|
6925
7020
|
releaseConnection: () => releaseConnection,
|
|
@@ -6942,6 +7037,7 @@ __export(worlds_exports, {
|
|
|
6942
7037
|
toolCallsFromObservations: () => toolCallsFromObservations,
|
|
6943
7038
|
uiEntryUrl: () => uiEntryUrl,
|
|
6944
7039
|
uiUrl: () => uiUrl,
|
|
7040
|
+
uncommittedPaths: () => uncommittedPaths,
|
|
6945
7041
|
updateTask: () => updateTask,
|
|
6946
7042
|
upsertRunConfig: () => upsertRunConfig,
|
|
6947
7043
|
validateTask: () => validateTask,
|
|
@@ -6980,19 +7076,10 @@ function parseErrorBody(text2, limit = 600) {
|
|
|
6980
7076
|
code: stableCode
|
|
6981
7077
|
};
|
|
6982
7078
|
}
|
|
6983
|
-
async function apiRequest(options, method, path16, body) {
|
|
6984
|
-
const
|
|
6985
|
-
|
|
6986
|
-
|
|
6987
|
-
headers: {
|
|
6988
|
-
"content-type": "application/json",
|
|
6989
|
-
authorization: "Basic " + Buffer.from(`${publicKey}:${secretKey}`).toString("base64")
|
|
6990
|
-
},
|
|
6991
|
-
...body === void 0 ? {} : { body: JSON.stringify(body) }
|
|
6992
|
-
});
|
|
6993
|
-
const text2 = await res.text();
|
|
6994
|
-
if (!res.ok) throw new ApiError2(res.status, method, path16, text2);
|
|
6995
|
-
return JSON.parse(text2);
|
|
7079
|
+
async function apiRequest(options, method, path16, body, init3 = {}) {
|
|
7080
|
+
const reply = await new PlatformTransport(resolveEnv(options)).send(method, path16, body, init3);
|
|
7081
|
+
if (!reply.ok) throw new ApiError(reply.status, method, path16, reply.text);
|
|
7082
|
+
return JSON.parse(reply.text);
|
|
6996
7083
|
}
|
|
6997
7084
|
async function setEnvSecret(slug, key2, value, options = {}) {
|
|
6998
7085
|
return apiRequest(
|
|
@@ -7168,10 +7255,12 @@ async function resolveWorld(slugRef, slug, ref, pin, options) {
|
|
|
7168
7255
|
}
|
|
7169
7256
|
return world;
|
|
7170
7257
|
}
|
|
7171
|
-
var
|
|
7258
|
+
var ApiError, WorldTask, WorldSet;
|
|
7172
7259
|
var init_worlds = __esm({
|
|
7173
7260
|
"src/worlds/index.ts"() {
|
|
7174
7261
|
"use strict";
|
|
7262
|
+
init_transport();
|
|
7263
|
+
init_transport();
|
|
7175
7264
|
init_session();
|
|
7176
7265
|
init_sessionList();
|
|
7177
7266
|
init_sessionContract();
|
|
@@ -7195,15 +7284,17 @@ var init_worlds = __esm({
|
|
|
7195
7284
|
init_sandbox();
|
|
7196
7285
|
init_editSessions();
|
|
7197
7286
|
init_dryRun();
|
|
7198
|
-
|
|
7199
|
-
constructor(status, method, path16,
|
|
7200
|
-
const parsed = parseErrorBody(
|
|
7287
|
+
ApiError = class extends Error {
|
|
7288
|
+
constructor(status, method, path16, text2) {
|
|
7289
|
+
const parsed = parseErrorBody(text2);
|
|
7201
7290
|
super(`${method} ${path16} -> ${status}: ${parsed.detail}`);
|
|
7202
7291
|
this.status = status;
|
|
7292
|
+
this.text = text2;
|
|
7203
7293
|
this.name = "ApiError";
|
|
7204
7294
|
this.code = parsed.code;
|
|
7205
7295
|
}
|
|
7206
7296
|
status;
|
|
7297
|
+
text;
|
|
7207
7298
|
code;
|
|
7208
7299
|
};
|
|
7209
7300
|
WorldTask = class {
|
|
@@ -14941,7 +15032,7 @@ var tracing = {
|
|
|
14941
15032
|
};
|
|
14942
15033
|
export {
|
|
14943
15034
|
AGENT_ID_KEY,
|
|
14944
|
-
|
|
15035
|
+
ApiError,
|
|
14945
15036
|
BROWSER_GONE_PATTERNS,
|
|
14946
15037
|
BROWSER_TIERS,
|
|
14947
15038
|
BrowserActionRecorder,
|
|
@@ -14986,9 +15077,12 @@ export {
|
|
|
14986
15077
|
HostedDryRunClient,
|
|
14987
15078
|
IDLE_WARNING_MINUTES,
|
|
14988
15079
|
NO_GRADER_REASON,
|
|
15080
|
+
PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
15081
|
+
PLATFORM_TIMEOUT_ENV,
|
|
14989
15082
|
Persona,
|
|
14990
15083
|
PersonaError,
|
|
14991
15084
|
PersonasClient,
|
|
15085
|
+
PlatformTransport,
|
|
14992
15086
|
PushSlugConflict,
|
|
14993
15087
|
RECOVER_BUDGET_MS,
|
|
14994
15088
|
REPLAY_ENVIRONMENT,
|
|
@@ -14998,6 +15092,7 @@ export {
|
|
|
14998
15092
|
ReplayReport,
|
|
14999
15093
|
ReplaySuite,
|
|
15000
15094
|
ReplayTask,
|
|
15095
|
+
SANDBOX_REQUEST_TIMEOUT_MS,
|
|
15001
15096
|
SESSION_STATES,
|
|
15002
15097
|
STATUS_WAIT_CAP_SECONDS,
|
|
15003
15098
|
STRIP_PREFIX,
|
|
@@ -15016,6 +15111,8 @@ export {
|
|
|
15016
15111
|
TaskSessions,
|
|
15017
15112
|
ToolStubRegistry,
|
|
15018
15113
|
TraceDiff,
|
|
15114
|
+
TransportCause,
|
|
15115
|
+
UnreachableError,
|
|
15019
15116
|
UserProfileError,
|
|
15020
15117
|
UsersClient,
|
|
15021
15118
|
VERIFIER_REWARD_PREFIX,
|
|
@@ -15110,6 +15207,7 @@ export {
|
|
|
15110
15207
|
parseTransform,
|
|
15111
15208
|
parseWorldTaskRefs,
|
|
15112
15209
|
personas,
|
|
15210
|
+
platformTimeoutMs,
|
|
15113
15211
|
preserveForm,
|
|
15114
15212
|
propose,
|
|
15115
15213
|
pull,
|
|
@@ -15121,6 +15219,7 @@ export {
|
|
|
15121
15219
|
queryRowsSearch,
|
|
15122
15220
|
readLocalMeta,
|
|
15123
15221
|
readToolCallRecords,
|
|
15222
|
+
rebaseConflicts,
|
|
15124
15223
|
redactActionArgs,
|
|
15125
15224
|
redactionOf,
|
|
15126
15225
|
registerArtifact,
|
|
@@ -15160,6 +15259,7 @@ export {
|
|
|
15160
15259
|
tracing,
|
|
15161
15260
|
uiEntryUrl,
|
|
15162
15261
|
uiUrl,
|
|
15262
|
+
uncommittedPaths,
|
|
15163
15263
|
updateTask,
|
|
15164
15264
|
upsertRunConfig,
|
|
15165
15265
|
users,
|