@withgateway/sdk 0.4.0 → 0.9.1
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 +573 -0
- package/dist/agents/index.d.ts +573 -0
- package/dist/agents/index.js +1443 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/index.mjs +1394 -0
- package/dist/agents/index.mjs.map +1 -0
- package/dist/apiError-DHpfbmdx.d.mts +17 -0
- package/dist/apiError-DHpfbmdx.d.ts +17 -0
- package/dist/cli.js +5655 -1890
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +5769 -2005
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.d.mts +3 -1
- package/dist/files/index.d.ts +3 -1
- package/dist/files/index.js +418 -120
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +418 -120
- package/dist/files/index.mjs.map +1 -1
- package/dist/hooks/index.js +346 -136
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +346 -136
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/{index-DUHmS74p.d.ts → index-DIN14Lhg.d.ts} +27 -4
- package/dist/{index-mJhG3vZU.d.mts → index-DuB-eQ0Z.d.mts} +27 -4
- package/dist/index.d.mts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +2862 -438
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2820 -431
- package/dist/index.mjs.map +1 -1
- package/dist/media-CQUC7TkS.d.mts +39 -0
- package/dist/media-DQnBloaX.d.ts +39 -0
- package/dist/replay/index.d.mts +1 -1
- package/dist/replay/index.d.ts +1 -1
- package/dist/replay/index.js.map +1 -1
- package/dist/replay/index.mjs.map +1 -1
- package/dist/traces/index.d.mts +3 -1
- package/dist/traces/index.d.ts +3 -1
- package/dist/traces/index.js +418 -120
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +418 -120
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.d.mts +3 -2
- package/dist/tracing/index.d.ts +3 -2
- package/dist/tracing/index.js +257 -16
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +257 -16
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/transport-CpRe7zgd.d.mts +123 -0
- package/dist/transport-CpRe7zgd.d.ts +123 -0
- package/dist/worlds/index.d.mts +2086 -1749
- package/dist/worlds/index.d.ts +2086 -1749
- package/dist/worlds/index.js +1471 -269
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +1466 -265
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +6 -1
- package/runtime/gatewaysdk/environment/_bundle.py +4 -6
- package/runtime/gatewaysdk/environment/_world.py +24 -1
- package/runtime/gatewaysdk/environment/bundle_manifest.py +243 -0
- package/runtime/gatewaysdk/environment/runtime.py +45 -2
- package/runtime/gatewaysdk/environment/schema/__main__.py +2 -2
- package/runtime/gatewaysdk/environment/schema/_slack_fidelity.py +8 -23
- package/runtime/gatewaysdk/environment/schema/api.py +27 -7
- package/runtime/gatewaysdk/environment/schema/assertions.py +7 -1
- package/runtime/gatewaysdk/environment/schema/bundle_runtime.py +2 -0
- package/runtime/gatewaysdk/environment/schema/call_capture.py +13 -1
- package/runtime/gatewaysdk/environment/schema/call_log.py +66 -0
- package/runtime/gatewaysdk/environment/schema/call_redaction.py +6 -0
- package/runtime/gatewaysdk/environment/schema/compiler.py +4 -1
- package/runtime/gatewaysdk/environment/schema/conform.py +32 -8
- package/runtime/gatewaysdk/environment/schema/connector.py +5 -0
- package/runtime/gatewaysdk/environment/schema/connectors/custom/handlers.py +2 -1
- package/runtime/gatewaysdk/environment/schema/connectors/github/api/handlers.py +217 -58
- package/runtime/gatewaysdk/environment/schema/connectors/github/connector.toml +9 -19
- package/runtime/gatewaysdk/environment/schema/connectors/github/scenarios/default/seed/github_webhooks.json +10 -2
- package/runtime/gatewaysdk/environment/schema/connectors/github/tests/webhooks.json +47 -0
- package/runtime/gatewaysdk/environment/schema/connectors/github/world.json +21 -0
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/api/handlers.py +185 -18
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/connector.toml +29 -14
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/provenance.json +43 -12
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/scenarios/default/seed/jamf_webhooks.json +2 -2
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/scope.toml +4 -17
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/tests/webhooks.json +107 -0
- package/runtime/gatewaysdk/environment/schema/connectors/jamf/vendor-openapi.json +1 -1
- package/runtime/gatewaysdk/environment/schema/connectors/linear/api/handlers.py +85 -1
- package/runtime/gatewaysdk/environment/schema/connectors/linear/connector.toml +19 -31
- package/runtime/gatewaysdk/environment/schema/connectors/linear/provenance.json +18 -8
- package/runtime/gatewaysdk/environment/schema/connectors/linear/scenarios/default/seed/webhooks.json +19 -3
- package/runtime/gatewaysdk/environment/schema/connectors/linear/tests/test_webhooks.py +71 -0
- package/runtime/gatewaysdk/environment/schema/database/base.py +2 -2
- package/runtime/gatewaysdk/environment/schema/database/guard.py +2 -1
- package/runtime/gatewaysdk/environment/schema/handler_errors.py +27 -1
- package/runtime/gatewaysdk/environment/schema/host.py +74 -11
- package/runtime/gatewaysdk/environment/schema/host_browser.py +48 -0
- package/runtime/gatewaysdk/environment/schema/host_control.py +33 -2
- package/runtime/gatewaysdk/environment/schema/host_handoff.py +4 -1
- package/runtime/gatewaysdk/environment/schema/host_requests.py +14 -0
- package/runtime/gatewaysdk/environment/schema/host_session.py +13 -2
- package/runtime/gatewaysdk/environment/schema/host_surfaces.py +6 -0
- package/runtime/gatewaysdk/environment/schema/host_versions.py +96 -19
- package/runtime/gatewaysdk/environment/schema/journal.py +10 -4
- package/runtime/gatewaysdk/environment/schema/local.py +33 -7
- package/runtime/gatewaysdk/environment/schema/openapi_schemas.py +20 -5
- package/runtime/gatewaysdk/environment/schema/page_checks.py +123 -0
- package/runtime/gatewaysdk/environment/schema/platform.py +33 -480
- package/runtime/gatewaysdk/environment/schema/platform_templates.py +332 -0
- package/runtime/gatewaysdk/environment/schema/request_ledger.py +4 -1
- package/runtime/gatewaysdk/environment/schema/run_parameters.py +25 -0
- package/runtime/gatewaysdk/environment/schema/runtime.py +49 -4
- package/runtime/gatewaysdk/environment/schema/scaffold.py +369 -218
- package/runtime/gatewaysdk/environment/schema/session_files.py +13 -2
- package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +1 -1
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/CONNECTORS.md +3 -3
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +20 -24
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +11 -11
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +9 -9
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +45 -12
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +40 -9
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/journal-checks.md +17 -2
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/new-world-sandbox.md +1 -1
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/ui-map.md +3 -2
- package/runtime/gatewaysdk/environment/schema/slack.py +55 -10
- package/runtime/gatewaysdk/environment/schema/snapshot.py +30 -4
- package/runtime/gatewaysdk/environment/schema/tasks.py +25 -2
- package/runtime/gatewaysdk/environment/schema/template_record.py +131 -0
- package/runtime/gatewaysdk/environment/schema/tools_world.py +26 -5
- package/runtime/gatewaysdk/environment/schema/ui.py +54 -33
- package/runtime/gatewaysdk/environment/schema/ui_interactions.py +419 -0
- package/runtime/gatewaysdk/environment/schema/ui_recorder.js +895 -0
- package/runtime/gatewaysdk/environment/schema/ui_replay.py +366 -0
- package/runtime/gatewaysdk/environment/schema/ui_replay_record.LICENSE +25 -0
- package/runtime/gatewaysdk/environment/schema/ui_replay_record.js +109 -0
- package/runtime/gatewaysdk/environment/schema/validation.py +10 -1
- package/runtime/gatewaysdk/environment/schema/verbs.py +6 -0
- package/runtime/gatewaysdk/environment/schema/webhooks.py +687 -0
- package/runtime/gatewaysdk/environment/schema/worker.py +5 -1
- package/runtime/gatewaysdk/environment/schema/workers.py +8 -1
- package/runtime/gatewaysdk/environment/schema/world_host.py +64 -18
- package/runtime/gatewaysdk/environment/schema/world_tests.py +74 -0
- package/runtime/gatewaysdk/environment/secret_values.py +1 -1
- package/runtime/gatewaysdk/environment/world.py +34 -43
- package/runtime/gatewaysdk/environment/world_session_contract.py +7 -34
- package/skills/benchmarks-getting-started/SKILL.md +1 -1
- package/skills/connector-schema-authoring/CONNECTORS.md +3 -3
- package/skills/connector-schema-authoring/SKILL.md +20 -24
- package/skills/connector-schema-authoring/connector-worlds.md +155 -13
- package/skills/connector-schema-authoring/world-schema.md +36 -29
- package/skills/world-data-ingestion/SKILL.md +11 -11
- package/skills/worlds-getting-started/SKILL.md +9 -9
- package/skills/worlds-getting-started/references/cli-mcp-map.md +45 -12
- package/skills/worlds-getting-started/references/gotchas.md +40 -9
- package/skills/worlds-getting-started/references/journal-checks.md +17 -2
- package/skills/worlds-getting-started/references/new-world-sandbox.md +1 -1
- package/skills/worlds-getting-started/references/ui-map.md +3 -2
- package/dist/media-BIApiPzS.d.mts +0 -102
- package/dist/media-BIApiPzS.d.ts +0 -102
package/dist/worlds/index.js
CHANGED
|
@@ -42,13 +42,77 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
42
42
|
));
|
|
43
43
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
44
44
|
|
|
45
|
+
// src/worlds/personalToken.ts
|
|
46
|
+
var TOKEN_NOT_PERSONAL, TOKEN_NEEDS_PROJECT, TOKEN_NEEDS_HOST, TOKEN_OTHER_HOST, TOKEN_BESIDE_KEYS, TOKEN_FILING, TOKEN_KEYS_ONLY, PERSONAL, PROJECT, ENV_KEYS, PersonalTokenRefused, bare, PersonalToken;
|
|
47
|
+
var init_personalToken = __esm({
|
|
48
|
+
"src/worlds/personalToken.ts"() {
|
|
49
|
+
"use strict";
|
|
50
|
+
TOKEN_NOT_PERSONAL = "GATEWAY_TOKEN takes a personal access token: pat_ followed by letters and digits only.";
|
|
51
|
+
TOKEN_NEEDS_PROJECT = "GATEWAY_TOKEN acts in the project GATEWAY_PROJECT_ID names: set it to the official project's id (letters, digits, - and _).";
|
|
52
|
+
TOKEN_NEEDS_HOST = "GATEWAY_TOKEN goes only to the host GATEWAY_HOST names: set GATEWAY_HOST.";
|
|
53
|
+
TOKEN_OTHER_HOST = "GATEWAY_TOKEN goes only to the host GATEWAY_HOST names, and this call names another host: point the call at GATEWAY_HOST or unset GATEWAY_TOKEN.";
|
|
54
|
+
TOKEN_BESIDE_KEYS = "GATEWAY_TOKEN is set beside a project key (GATEWAY_PUBLIC_KEY, GATEWAY_SECRET_KEY, GATEWAY_API_KEY or a key passed in): unset one of them. Neither replaces the other.";
|
|
55
|
+
TOKEN_FILING = "Filing an evaluation takes your project's key pair, not GATEWAY_TOKEN: unset it (an official world runs once copied into your own project).";
|
|
56
|
+
TOKEN_KEYS_ONLY = "Task-run tracing exports with a project key pair (GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY), not GATEWAY_TOKEN.";
|
|
57
|
+
PERSONAL = /^pat_[A-Za-z0-9]+$/;
|
|
58
|
+
PROJECT = /^[A-Za-z0-9_-]+$/;
|
|
59
|
+
ENV_KEYS = ["GATEWAY_PUBLIC_KEY", "GATEWAY_SECRET_KEY", "GATEWAY_API_KEY"];
|
|
60
|
+
PersonalTokenRefused = class extends Error {
|
|
61
|
+
};
|
|
62
|
+
bare = (host) => host.replace(/\/+$/, "");
|
|
63
|
+
PersonalToken = class _PersonalToken {
|
|
64
|
+
constructor(value, project, host) {
|
|
65
|
+
this.value = value;
|
|
66
|
+
this.project = project;
|
|
67
|
+
this.host = host;
|
|
68
|
+
}
|
|
69
|
+
value;
|
|
70
|
+
project;
|
|
71
|
+
host;
|
|
72
|
+
static fromEnv(env, request = {}) {
|
|
73
|
+
const value = env.GATEWAY_TOKEN;
|
|
74
|
+
if (!value) return null;
|
|
75
|
+
if (request.keys || ENV_KEYS.some((name) => env[name])) throw new PersonalTokenRefused(TOKEN_BESIDE_KEYS);
|
|
76
|
+
const host = bare(env.GATEWAY_HOST ?? "");
|
|
77
|
+
if (!host) throw new PersonalTokenRefused(TOKEN_NEEDS_HOST);
|
|
78
|
+
if (request.host && bare(request.host) !== host) throw new PersonalTokenRefused(TOKEN_OTHER_HOST);
|
|
79
|
+
if (!PERSONAL.test(value)) throw new PersonalTokenRefused(TOKEN_NOT_PERSONAL);
|
|
80
|
+
const project = env.GATEWAY_PROJECT_ID ?? "";
|
|
81
|
+
if (!PROJECT.test(project)) throw new PersonalTokenRefused(TOKEN_NEEDS_PROJECT);
|
|
82
|
+
return new _PersonalToken(value, project, host);
|
|
83
|
+
}
|
|
84
|
+
toJSON() {
|
|
85
|
+
return { project: this.project, host: this.host };
|
|
86
|
+
}
|
|
87
|
+
[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
|
|
88
|
+
return `PersonalToken { project: ${this.project}, host: ${this.host} }`;
|
|
89
|
+
}
|
|
90
|
+
static scrubbed(env) {
|
|
91
|
+
return Object.fromEntries(Object.entries(env).filter(([key]) => key !== "GATEWAY_TOKEN"));
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
45
97
|
// src/worlds/platformEndpoint.ts
|
|
46
98
|
function platformEndpoint(options) {
|
|
99
|
+
if (options.token)
|
|
100
|
+
return {
|
|
101
|
+
host: (options.host ?? options.token.host).replace(/\/+$/, ""),
|
|
102
|
+
publicKey: options.publicKey ?? "",
|
|
103
|
+
secretKey: options.secretKey ?? "",
|
|
104
|
+
token: options.token
|
|
105
|
+
};
|
|
106
|
+
const token = PersonalToken.fromEnv(process.env, {
|
|
107
|
+
host: options.host,
|
|
108
|
+
keys: Boolean(options.publicKey || options.secretKey)
|
|
109
|
+
});
|
|
110
|
+
if (token) return { host: token.host, publicKey: "", secretKey: "", token };
|
|
111
|
+
const host = (options.host ?? process.env.GATEWAY_HOST ?? DEFAULT_HOST).replace(/\/+$/, "");
|
|
47
112
|
const publicKey = options.publicKey ?? process.env.GATEWAY_PUBLIC_KEY;
|
|
48
113
|
const secretKey = options.secretKey ?? process.env.GATEWAY_SECRET_KEY;
|
|
49
114
|
if (!publicKey || !secretKey) return null;
|
|
50
|
-
|
|
51
|
-
return { host: host.replace(/\/+$/, ""), publicKey, secretKey };
|
|
115
|
+
return { host, publicKey, secretKey };
|
|
52
116
|
}
|
|
53
117
|
function requirePlatformEndpoint(options) {
|
|
54
118
|
const endpoint = platformEndpoint(options);
|
|
@@ -59,11 +123,74 @@ var DEFAULT_HOST, GATEWAY_KEYS_MISSING;
|
|
|
59
123
|
var init_platformEndpoint = __esm({
|
|
60
124
|
"src/worlds/platformEndpoint.ts"() {
|
|
61
125
|
"use strict";
|
|
126
|
+
init_personalToken();
|
|
62
127
|
DEFAULT_HOST = "https://withgateway.ai";
|
|
63
128
|
GATEWAY_KEYS_MISSING = "Gateway keys missing: set GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY (or pass publicKey/secretKey).";
|
|
64
129
|
}
|
|
65
130
|
});
|
|
66
131
|
|
|
132
|
+
// src/worlds/apiError.ts
|
|
133
|
+
function edgeAnswer(text2, status) {
|
|
134
|
+
if (status !== void 0 && status >= 500) return EDGE_ANSWERS[status] ?? EDGE_FAILURE;
|
|
135
|
+
return /^\s*</.test(text2) ? EDGE_PAGE : null;
|
|
136
|
+
}
|
|
137
|
+
function parseErrorBody(text2, status) {
|
|
138
|
+
const raw = { detail: text2.slice(0, DETAIL_LIMIT), code: null };
|
|
139
|
+
let parsed;
|
|
140
|
+
try {
|
|
141
|
+
parsed = JSON.parse(text2);
|
|
142
|
+
} catch {
|
|
143
|
+
return { detail: (edgeAnswer(text2, status) ?? text2).slice(0, DETAIL_LIMIT), code: null };
|
|
144
|
+
}
|
|
145
|
+
if (parsed === null || typeof parsed !== "object") return raw;
|
|
146
|
+
const { message, code, error } = parsed;
|
|
147
|
+
const stableCode = typeof code === "string" ? code : null;
|
|
148
|
+
if (typeof message !== "string") return { ...raw, code: stableCode };
|
|
149
|
+
const fields = invalidFields(error);
|
|
150
|
+
const said = fields ? `${message}: ${fields}` : message;
|
|
151
|
+
if (stableCode === null) return { detail: said.slice(0, DETAIL_LIMIT), code: null };
|
|
152
|
+
return {
|
|
153
|
+
detail: `${said} (${stableCode})`.slice(0, DETAIL_LIMIT),
|
|
154
|
+
code: stableCode
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function invalidFields(error) {
|
|
158
|
+
const issues = Array.isArray(error) ? error : [];
|
|
159
|
+
return issues.filter(
|
|
160
|
+
(issue) => issue !== null && typeof issue === "object" && typeof issue.message === "string"
|
|
161
|
+
).map((issue) => {
|
|
162
|
+
const path13 = Array.isArray(issue.path) ? issue.path.map(String).join(".") : "";
|
|
163
|
+
return path13 ? `${path13}: ${issue.message}` : issue.message;
|
|
164
|
+
}).join("; ");
|
|
165
|
+
}
|
|
166
|
+
var ApiError, DETAIL_LIMIT, EDGE_ANSWERS, EDGE_FAILURE, EDGE_PAGE;
|
|
167
|
+
var init_apiError = __esm({
|
|
168
|
+
"src/worlds/apiError.ts"() {
|
|
169
|
+
"use strict";
|
|
170
|
+
ApiError = class extends Error {
|
|
171
|
+
constructor(status, method, path13, text2) {
|
|
172
|
+
const parsed = parseErrorBody(text2, status);
|
|
173
|
+
super(`${method} ${path13} -> ${status}: ${parsed.detail}`);
|
|
174
|
+
this.status = status;
|
|
175
|
+
this.text = text2;
|
|
176
|
+
this.name = "ApiError";
|
|
177
|
+
this.code = parsed.code;
|
|
178
|
+
}
|
|
179
|
+
status;
|
|
180
|
+
text;
|
|
181
|
+
code;
|
|
182
|
+
};
|
|
183
|
+
DETAIL_LIMIT = 600;
|
|
184
|
+
EDGE_ANSWERS = {
|
|
185
|
+
502: "Bad Gateway from the load balancer in front of the platform, not the platform's answer: the web server dropped the connection or restarted mid-request. Retry; if it repeats, the platform is restarting or overloaded.",
|
|
186
|
+
503: "Service Unavailable from the load balancer in front of the platform, not the platform's answer: no web server was ready to take the request (a deploy or a restart). Retry in a minute.",
|
|
187
|
+
504: "Gateway Time-out from the load balancer in front of the platform, not the platform's answer: the request sent nothing back within the load balancer's idle timeout (60 s unless the deployment raises it: Helm ingress.idleTimeoutSeconds) and was cut there, though the platform may still be running it. Check what it changed before you retry."
|
|
188
|
+
};
|
|
189
|
+
EDGE_FAILURE = "The platform failed without its JSON error body: a proxy in front of it answered, or the server stopped before its error handler ran. Retry; if it repeats, report the request and the time.";
|
|
190
|
+
EDGE_PAGE = "An HTML page answered instead of the platform's JSON: a proxy in front of the platform, or the configured host is not the platform.";
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
|
|
67
194
|
// src/worlds/transport.ts
|
|
68
195
|
function platformTimeoutMs(env = process.env) {
|
|
69
196
|
const raw = env[PLATFORM_TIMEOUT_ENV];
|
|
@@ -72,10 +199,20 @@ function platformTimeoutMs(env = process.env) {
|
|
|
72
199
|
if (Number.isInteger(value) && value > 0) return value;
|
|
73
200
|
throw new Error(`${PLATFORM_TIMEOUT_ENV} must be a positive whole number of milliseconds, not \`${raw}\`.`);
|
|
74
201
|
}
|
|
75
|
-
|
|
202
|
+
function platformAuthorization(endpoint, url) {
|
|
203
|
+
const { token } = endpoint;
|
|
204
|
+
if (!token)
|
|
205
|
+
return { authorization: "Basic " + Buffer.from(`${endpoint.publicKey}:${endpoint.secretKey}`).toString("base64") };
|
|
206
|
+
if (endpoint.publicKey || endpoint.secretKey) throw new PersonalTokenRefused(TOKEN_BESIDE_KEYS);
|
|
207
|
+
if (!url.startsWith(`${token.host}/`)) throw new PersonalTokenRefused(TOKEN_OTHER_HOST);
|
|
208
|
+
return { authorization: `Bearer ${token.value}`, "x-gateway-project": token.project };
|
|
209
|
+
}
|
|
210
|
+
var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, FETCH_LIMIT, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, sleep, RetryPolicy, Attempt, PLATFORM_STREAM_IDLE_MS, REFUSAL_TEXT_LIMIT, KEYED_REDIRECTS, PlatformTransport, StreamWatch, PlatformStream;
|
|
76
211
|
var init_transport = __esm({
|
|
77
212
|
"src/worlds/transport.ts"() {
|
|
78
213
|
"use strict";
|
|
214
|
+
init_apiError();
|
|
215
|
+
init_personalToken();
|
|
79
216
|
PLATFORM_TIMEOUT_ENV = "GATEWAY_TIMEOUT_MS";
|
|
80
217
|
PLATFORM_TIMEOUT_DEFAULT_MS = 12e4;
|
|
81
218
|
CHECK_HOST = "Check GATEWAY_HOST (or --host) points at a running platform, then retry.";
|
|
@@ -115,6 +252,13 @@ var init_transport = __esm({
|
|
|
115
252
|
`Retry; if the platform is slow, raise ${PLATFORM_TIMEOUT_ENV} (milliseconds per request).`
|
|
116
253
|
);
|
|
117
254
|
}
|
|
255
|
+
static idle(idleMs) {
|
|
256
|
+
return new _TransportCause(
|
|
257
|
+
`no data for ${idleMs / 1e3}s`,
|
|
258
|
+
null,
|
|
259
|
+
"The stream resumes from its last event; if it repeats, check the network between here and the platform."
|
|
260
|
+
);
|
|
261
|
+
}
|
|
118
262
|
static of(error) {
|
|
119
263
|
const cause = error instanceof Error && error.cause instanceof Error ? error.cause : void 0;
|
|
120
264
|
const code = cause && "code" in cause && typeof cause.code === "string" ? cause.code : null;
|
|
@@ -127,11 +271,11 @@ var init_transport = __esm({
|
|
|
127
271
|
}
|
|
128
272
|
};
|
|
129
273
|
UnreachableError = class extends Error {
|
|
130
|
-
constructor(host, method,
|
|
131
|
-
super(`${method} ${
|
|
274
|
+
constructor(host, method, route2, failure) {
|
|
275
|
+
super(`${method} ${route2}: no answer from ${host}: ${failure.describe()}. ${failure.next}`);
|
|
132
276
|
this.host = host;
|
|
133
277
|
this.method = method;
|
|
134
|
-
this.route =
|
|
278
|
+
this.route = route2;
|
|
135
279
|
this.failure = failure;
|
|
136
280
|
this.name = "UnreachableError";
|
|
137
281
|
}
|
|
@@ -190,45 +334,277 @@ var init_transport = __esm({
|
|
|
190
334
|
throw this.error;
|
|
191
335
|
}
|
|
192
336
|
};
|
|
337
|
+
PLATFORM_STREAM_IDLE_MS = 6e4;
|
|
338
|
+
REFUSAL_TEXT_LIMIT = 64 * 1024;
|
|
339
|
+
KEYED_REDIRECTS = "manual";
|
|
193
340
|
PlatformTransport = class {
|
|
341
|
+
#endpoint;
|
|
342
|
+
#timeoutMs;
|
|
194
343
|
constructor(endpoint, timeoutMs = platformTimeoutMs()) {
|
|
195
|
-
this
|
|
196
|
-
this
|
|
344
|
+
this.#endpoint = endpoint;
|
|
345
|
+
this.#timeoutMs = timeoutMs;
|
|
197
346
|
}
|
|
198
|
-
endpoint;
|
|
199
|
-
timeoutMs;
|
|
200
347
|
/** A request that legitimately takes longer (a sandbox exec, a world create) waits its own budget; every other one waits the default. */
|
|
201
348
|
budget(ownMs) {
|
|
202
|
-
return Math.max(ownMs ?? 0, this
|
|
349
|
+
return Math.max(ownMs ?? 0, this.#timeoutMs);
|
|
203
350
|
}
|
|
204
|
-
|
|
351
|
+
/** One request; the caller's `signal` aborts it in flight and throws the signal's reason, never an `UnreachableError`. */
|
|
352
|
+
async send(method, route2, body, opts = {}) {
|
|
205
353
|
const timeoutMs = this.budget(opts.timeoutMs);
|
|
206
|
-
return (opts.retry ?? RetryPolicy.NONE).run(() => this.once(method,
|
|
354
|
+
return (opts.retry ?? RetryPolicy.NONE).run(() => this.once(method, route2, body, timeoutMs, opts.signal));
|
|
355
|
+
}
|
|
356
|
+
/** `send`, then the 2xx body as JSON; any other answer throws `ApiError` with its status and stable `code`. */
|
|
357
|
+
async json(method, route2, body, opts = {}) {
|
|
358
|
+
const reply = await this.send(method, route2, body, opts);
|
|
359
|
+
if (!reply.ok) throw new ApiError(reply.status, method, route2, reply.text);
|
|
360
|
+
return JSON.parse(reply.text);
|
|
361
|
+
}
|
|
362
|
+
/** The streaming twin of `send` for a `GET` event stream: nothing is buffered, `after` travels as `Last-Event-ID`, and each wait for the platform (the headers, every chunk) may last `idleMs` (default 60 s) instead of the request budget. */
|
|
363
|
+
async stream(route2, opts = {}) {
|
|
364
|
+
const watch = new StreamWatch(opts.signal, opts.idleMs ?? PLATFORM_STREAM_IDLE_MS, this.#endpoint.host, route2);
|
|
365
|
+
const headers = this.headers(route2, "text/event-stream", opts.after ? { "last-event-id": opts.after } : {});
|
|
366
|
+
try {
|
|
367
|
+
const response = await watch.within(
|
|
368
|
+
() => fetch(this.url(route2), { method: "GET", headers, signal: watch.signal, redirect: KEYED_REDIRECTS })
|
|
369
|
+
);
|
|
370
|
+
return new PlatformStream(response, watch);
|
|
371
|
+
} catch (error) {
|
|
372
|
+
watch.close();
|
|
373
|
+
throw error;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
url(route2) {
|
|
377
|
+
return `${this.#endpoint.host}${route2}`;
|
|
378
|
+
}
|
|
379
|
+
headers(route2, accept, extra = {}) {
|
|
380
|
+
return {
|
|
381
|
+
"content-type": "application/json",
|
|
382
|
+
accept,
|
|
383
|
+
...platformAuthorization(this.#endpoint, this.url(route2)),
|
|
384
|
+
...extra
|
|
385
|
+
};
|
|
207
386
|
}
|
|
208
|
-
async once(method,
|
|
387
|
+
async once(method, route2, body, timeoutMs, caller) {
|
|
388
|
+
if (caller?.aborted) throw caller.reason;
|
|
209
389
|
const payload = body === void 0 ? {} : { body: JSON.stringify(body) };
|
|
390
|
+
const headers = this.headers(route2, "application/json");
|
|
210
391
|
const controller = new AbortController();
|
|
211
392
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
393
|
+
const relay = () => controller.abort(caller?.reason);
|
|
394
|
+
caller?.addEventListener("abort", relay, { once: true });
|
|
212
395
|
try {
|
|
213
|
-
const res = await fetch(
|
|
396
|
+
const res = await fetch(this.url(route2), {
|
|
214
397
|
method,
|
|
215
|
-
headers
|
|
216
|
-
"content-type": "application/json",
|
|
217
|
-
accept: "application/json",
|
|
218
|
-
authorization: "Basic " + Buffer.from(`${this.endpoint.publicKey}:${this.endpoint.secretKey}`).toString("base64")
|
|
219
|
-
},
|
|
398
|
+
headers,
|
|
220
399
|
...payload,
|
|
221
|
-
signal: controller.signal
|
|
400
|
+
signal: controller.signal,
|
|
401
|
+
redirect: KEYED_REDIRECTS
|
|
222
402
|
});
|
|
223
403
|
return { status: res.status, ok: res.ok, text: await res.text() };
|
|
224
404
|
} catch (error) {
|
|
405
|
+
if (caller?.aborted) throw caller.reason;
|
|
225
406
|
const cause = controller.signal.aborted ? TransportCause.timeout(timeoutMs) : TransportCause.of(error);
|
|
226
|
-
throw new UnreachableError(this
|
|
407
|
+
throw new UnreachableError(this.#endpoint.host, method, route2, cause);
|
|
227
408
|
} finally {
|
|
228
409
|
clearTimeout(timer);
|
|
410
|
+
caller?.removeEventListener("abort", relay);
|
|
229
411
|
}
|
|
230
412
|
}
|
|
231
413
|
};
|
|
414
|
+
StreamWatch = class {
|
|
415
|
+
constructor(caller, idleMs, host, route2) {
|
|
416
|
+
this.idleMs = idleMs;
|
|
417
|
+
this.host = host;
|
|
418
|
+
this.route = route2;
|
|
419
|
+
this.#caller = caller;
|
|
420
|
+
caller?.addEventListener("abort", this.#relay, { once: true });
|
|
421
|
+
if (caller?.aborted) this.#relay();
|
|
422
|
+
}
|
|
423
|
+
idleMs;
|
|
424
|
+
host;
|
|
425
|
+
route;
|
|
426
|
+
#controller = new AbortController();
|
|
427
|
+
#caller;
|
|
428
|
+
#relay = () => this.#controller.abort(this.#caller?.reason);
|
|
429
|
+
#idled = false;
|
|
430
|
+
get signal() {
|
|
431
|
+
return this.#controller.signal;
|
|
432
|
+
}
|
|
433
|
+
async within(wait) {
|
|
434
|
+
const timer = setTimeout(() => this.idle(), this.idleMs);
|
|
435
|
+
try {
|
|
436
|
+
return await wait();
|
|
437
|
+
} catch (error) {
|
|
438
|
+
throw this.failure(error);
|
|
439
|
+
} finally {
|
|
440
|
+
clearTimeout(timer);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
close() {
|
|
444
|
+
this.#caller?.removeEventListener("abort", this.#relay);
|
|
445
|
+
this.#controller.abort();
|
|
446
|
+
}
|
|
447
|
+
idle() {
|
|
448
|
+
this.#idled = true;
|
|
449
|
+
this.#controller.abort();
|
|
450
|
+
}
|
|
451
|
+
failure(error) {
|
|
452
|
+
if (this.#caller?.aborted) return this.#caller.reason;
|
|
453
|
+
const cause = this.#idled ? TransportCause.idle(this.idleMs) : TransportCause.of(error);
|
|
454
|
+
return new UnreachableError(this.host, "GET", this.route, cause);
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
PlatformStream = class {
|
|
458
|
+
#response;
|
|
459
|
+
#watch;
|
|
460
|
+
constructor(response, watch) {
|
|
461
|
+
this.#response = response;
|
|
462
|
+
this.#watch = watch;
|
|
463
|
+
}
|
|
464
|
+
get status() {
|
|
465
|
+
return this.#response.status;
|
|
466
|
+
}
|
|
467
|
+
get ok() {
|
|
468
|
+
return this.#response.ok;
|
|
469
|
+
}
|
|
470
|
+
/** The body as text, for a refusal: at most the first 64 KiB of characters; closes the stream. */
|
|
471
|
+
async text() {
|
|
472
|
+
const decoder = new TextDecoder();
|
|
473
|
+
let text2 = "";
|
|
474
|
+
for await (const chunk of this.chunks()) {
|
|
475
|
+
text2 += decoder.decode(chunk, { stream: true });
|
|
476
|
+
if (text2.length >= REFUSAL_TEXT_LIMIT) return text2.slice(0, REFUSAL_TEXT_LIMIT);
|
|
477
|
+
}
|
|
478
|
+
return text2 + decoder.decode();
|
|
479
|
+
}
|
|
480
|
+
/** The body's bytes as they arrive; the idle budget runs only while waiting for the platform, never while the caller holds a chunk. */
|
|
481
|
+
async *chunks() {
|
|
482
|
+
const reader = this.#response.body?.getReader();
|
|
483
|
+
try {
|
|
484
|
+
for (; ; ) {
|
|
485
|
+
const next = reader ? await this.#watch.within(() => reader.read()) : { done: true };
|
|
486
|
+
if (next.done) return;
|
|
487
|
+
yield next.value;
|
|
488
|
+
}
|
|
489
|
+
} finally {
|
|
490
|
+
this.close();
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
close() {
|
|
494
|
+
this.#watch.close();
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
// src/worlds/credentialField.ts
|
|
501
|
+
function isCredentialField(described) {
|
|
502
|
+
const words = described.replace(SPACES, " ").replace(/^ | $/g, "");
|
|
503
|
+
return SECRET_FIELD.some((prefix) => words.startsWith(prefix)) || SECRET_KEY.test(words);
|
|
504
|
+
}
|
|
505
|
+
function credentialTexts(pairs) {
|
|
506
|
+
return pairs.filter(([, text2]) => text2 !== null && text2 !== void 0).filter(([described]) => isCredentialField(String(described))).map(([, text2]) => String(text2));
|
|
507
|
+
}
|
|
508
|
+
function isTextField(described) {
|
|
509
|
+
return described !== "" && !NOT_TEXT.some((prefix) => described.startsWith(prefix));
|
|
510
|
+
}
|
|
511
|
+
function redactActionArgs(action, args) {
|
|
512
|
+
const secretField = action === "browser_type" && SECRET_KEY.test(String(args.selector ?? ""));
|
|
513
|
+
return Object.fromEntries(
|
|
514
|
+
Object.entries(args).map(([key, value]) => [
|
|
515
|
+
key,
|
|
516
|
+
redactedArg(key, value, secretField)
|
|
517
|
+
])
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
function redactedArg(key, value, secretField) {
|
|
521
|
+
if (value === null || value === void 0) return null;
|
|
522
|
+
if (typeof value === "boolean" || typeof value === "number") return value;
|
|
523
|
+
if (typeof value !== "string") return "[omitted]";
|
|
524
|
+
if (SECRET_KEY.test(key) || SECRET_VALUE.test(value) || secretField && key === "text")
|
|
525
|
+
return "[redacted]";
|
|
526
|
+
return value.length <= EVENT_MAX_STRING ? value : value.slice(0, EVENT_MAX_STRING) + "\u2026";
|
|
527
|
+
}
|
|
528
|
+
var SECRET_KEY, DESCRIBE_FIELD_JS, FIELD_VALUE_JS, FIELDS, SHORTEST_WITHHELD, WITHHELD_TEXT, SPACES, LINE_BREAK, TRIM, describeField, readFieldValue, readEditables, UNREADABLE, SECRET_FIELD, NOT_TEXT, escapeRegExp, urlForms, forms, CredentialText, EVENT_MAX_STRING, SECRET_VALUE;
|
|
529
|
+
var init_credentialField = __esm({
|
|
530
|
+
"src/worlds/credentialField.ts"() {
|
|
531
|
+
"use strict";
|
|
532
|
+
SECRET_KEY = /pass(word|wd|code|phrase)|pass(?![a-z])|secret|token(?!s)|(api|private)[-_ ]?key|authorization|cookie|one[-_ ]?time[-_ ]?(code|password)|(verification|security|recovery|backup)[-_ ]?codes?|security[-_ ]?answers?|social[-_ ]?security|(card|account|routing)[-_ ]?(number|no\b)|cc-(number|csc|exp)|(^|[-_ #.\["'=(])(otp|totp|mfa|2fa|pin|cvv|cvc|ssn|iban)([-_ \]"'):.,*]|$)/i;
|
|
533
|
+
DESCRIBE_FIELD_JS = "(e) => { if (!e) return ''; if (e.tagName === 'IFRAME' || e.tagName === 'FRAME') return 'frame'; const root = e.getRootNode(); const byIds = (at) => (at.getAttribute('aria-labelledby') || '').split(/\\s+/).map((id) => (id && root.getElementById ? root.getElementById(id) : null)).map((label) => (label ? label.textContent : '')).join(' '); const labels = e.labels ? [...e.labels].map((label) => label.textContent) : []; const context = []; for (let at = e.parentElement; at; at = at.parentElement) { const legend = at.tagName === 'FIELDSET' ? at.querySelector('legend') : null; context.push(at.getAttribute('aria-label'), byIds(at), legend ? legend.textContent : ''); } const names = [e.getAttribute('aria-label'), byIds(e), ...labels, e.getAttribute('placeholder'), e.getAttribute('title'), ...context]; if (e.tagName === 'SELECT') return ['select', e.name, e.id, ...names].filter(Boolean).join(' '); if (!(e.tagName === 'INPUT' || e.tagName === 'TEXTAREA' || e.isContentEditable)) return 'opaque'; return [e.type, e.name, e.id, e.getAttribute('autocomplete'), ...names].filter(Boolean).join(' '); }";
|
|
534
|
+
FIELD_VALUE_JS = "(e) => { if (e.tagName === 'SELECT') return [...e.selectedOptions].map((o) => o.text).join('\\n'); if (e.tagName === 'INPUT' || e.tagName === 'TEXTAREA') return e.value; return e.isContentEditable ? e.innerText : null; }";
|
|
535
|
+
FIELDS = "input:not([type=button]):not([type=submit]):not([type=reset]):not([type=image]):not([type=checkbox]):not([type=radio]):not([type=file]), textarea, select, [contenteditable]:not([contenteditable=false])";
|
|
536
|
+
SHORTEST_WITHHELD = 4;
|
|
537
|
+
WITHHELD_TEXT = "[redacted]";
|
|
538
|
+
SPACES = /[ \t\n\r\f\v]+/g;
|
|
539
|
+
LINE_BREAK = /\r\n|\r|\n/;
|
|
540
|
+
TRIM = /^[ \t\n\r\f\v]+|[ \t\n\r\f\v]+$/g;
|
|
541
|
+
describeField = new Function(
|
|
542
|
+
"e",
|
|
543
|
+
`return (${DESCRIBE_FIELD_JS})(e);`
|
|
544
|
+
);
|
|
545
|
+
readFieldValue = new Function(
|
|
546
|
+
"e",
|
|
547
|
+
`return (${FIELD_VALUE_JS})(e);`
|
|
548
|
+
);
|
|
549
|
+
readEditables = new Function(
|
|
550
|
+
"elements",
|
|
551
|
+
`return elements.map((e) => [(${DESCRIBE_FIELD_JS})(e), (${FIELD_VALUE_JS})(e)]);`
|
|
552
|
+
);
|
|
553
|
+
UNREADABLE = "unreadable";
|
|
554
|
+
SECRET_FIELD = ["password", "frame", "opaque", UNREADABLE];
|
|
555
|
+
NOT_TEXT = ["opaque", "frame", "select"];
|
|
556
|
+
escapeRegExp = (text2) => text2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
557
|
+
urlForms = (text2) => {
|
|
558
|
+
let component;
|
|
559
|
+
try {
|
|
560
|
+
component = encodeURIComponent(text2);
|
|
561
|
+
} catch {
|
|
562
|
+
return [];
|
|
563
|
+
}
|
|
564
|
+
const form = component.replace(
|
|
565
|
+
/[!'()~]/g,
|
|
566
|
+
(c) => "%" + c.charCodeAt(0).toString(16).toUpperCase()
|
|
567
|
+
).replace(/%20/g, "+");
|
|
568
|
+
return [component, component.replace(/%20/g, "+"), form];
|
|
569
|
+
};
|
|
570
|
+
forms = (text2) => {
|
|
571
|
+
const written = [
|
|
572
|
+
text2,
|
|
573
|
+
text2.replace(SPACES, " "),
|
|
574
|
+
JSON.stringify(text2).slice(1, -1)
|
|
575
|
+
];
|
|
576
|
+
return [
|
|
577
|
+
...written,
|
|
578
|
+
...written.map((form) => form.replaceAll("'", "''")),
|
|
579
|
+
...urlForms(text2)
|
|
580
|
+
];
|
|
581
|
+
};
|
|
582
|
+
CredentialText = class {
|
|
583
|
+
pattern;
|
|
584
|
+
constructor(secrets) {
|
|
585
|
+
const texts = secrets.map((secret) => String(secret).replace(TRIM, ""));
|
|
586
|
+
const lines = texts.flatMap(
|
|
587
|
+
(text2) => text2.split(LINE_BREAK).map((line) => line.replace(TRIM, ""))
|
|
588
|
+
);
|
|
589
|
+
const whole = new Set(
|
|
590
|
+
[...texts, ...lines].filter(
|
|
591
|
+
(text2) => [...text2].length >= SHORTEST_WITHHELD
|
|
592
|
+
)
|
|
593
|
+
);
|
|
594
|
+
const withheld = [
|
|
595
|
+
...new Set([...whole].flatMap((text2) => forms(text2)))
|
|
596
|
+
].sort((a, b) => b.length - a.length);
|
|
597
|
+
this.pattern = withheld.length === 0 ? null : new RegExp(
|
|
598
|
+
`(?<![A-Za-z0-9])(?:${withheld.map(escapeRegExp).join("|")})(?![A-Za-z0-9])`,
|
|
599
|
+
"g"
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
withhold(text2) {
|
|
603
|
+
return this.pattern === null ? text2 : text2.replace(this.pattern, WITHHELD_TEXT);
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
EVENT_MAX_STRING = 500;
|
|
607
|
+
SECRET_VALUE = /^((sk|pk|ghp|xox[abp])[-_][-_A-Za-z0-9]{8,}|AKIA[0-9A-Z]{12,}|Bearer [-_.A-Za-z0-9]{8,})/;
|
|
232
608
|
}
|
|
233
609
|
});
|
|
234
610
|
|
|
@@ -245,6 +621,25 @@ function isBrowserGone(error) {
|
|
|
245
621
|
if (PAGE_NETWORK_ERROR.test(message)) return false;
|
|
246
622
|
return BROWSER_GONE_PATTERNS.some((p) => p.test(message));
|
|
247
623
|
}
|
|
624
|
+
function scrubError(error, scrub) {
|
|
625
|
+
const seen = /* @__PURE__ */ new Set();
|
|
626
|
+
let at = error;
|
|
627
|
+
while (at instanceof Error && !seen.has(at)) {
|
|
628
|
+
seen.add(at);
|
|
629
|
+
at.message = scrub(at.message);
|
|
630
|
+
at.stack = at.stack && scrub(at.stack);
|
|
631
|
+
scrubOwnText(at, scrub);
|
|
632
|
+
at = at.cause;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
function scrubOwnText(error, scrub) {
|
|
636
|
+
for (const key of Object.keys(error)) {
|
|
637
|
+
const value = error[key];
|
|
638
|
+
if (typeof value === "string") error[key] = scrub(value);
|
|
639
|
+
if (Array.isArray(value) && value.every((item) => typeof item === "string"))
|
|
640
|
+
error[key] = value.map((item) => scrub(item));
|
|
641
|
+
}
|
|
642
|
+
}
|
|
248
643
|
function refusalIsTransient(error) {
|
|
249
644
|
const { status, code } = error;
|
|
250
645
|
if (typeof status !== "number") return true;
|
|
@@ -281,11 +676,17 @@ var init_browserReconnect = __esm({
|
|
|
281
676
|
].sort((a, b) => b.length - a.length);
|
|
282
677
|
}
|
|
283
678
|
scrub(text2) {
|
|
284
|
-
const
|
|
679
|
+
const bare2 = this.secrets.reduce(
|
|
285
680
|
(out, secret) => out.split(secret).join(REDACTED),
|
|
286
681
|
text2
|
|
287
682
|
);
|
|
288
|
-
return
|
|
683
|
+
return bare2.replace(TOKEN_QUERY_VALUE, `$1${REDACTED}`);
|
|
684
|
+
}
|
|
685
|
+
/** Scrub `error` and the errors it was raised from, in place: the message,
|
|
686
|
+
* the stack and every other own text property, Playwright's `log` call log
|
|
687
|
+
* included. */
|
|
688
|
+
scrubError(error) {
|
|
689
|
+
scrubError(error, (text2) => this.scrub(text2));
|
|
289
690
|
}
|
|
290
691
|
};
|
|
291
692
|
BrowserReconnected = class extends Error {
|
|
@@ -437,22 +838,6 @@ function capabilityLabel(url) {
|
|
|
437
838
|
}
|
|
438
839
|
return CAPABILITY_HOST.exec(host)?.[1] ?? null;
|
|
439
840
|
}
|
|
440
|
-
function redactActionArgs(action, args) {
|
|
441
|
-
const secretField = action === "browser_type" && SECRET_KEY.test(String(args.selector ?? ""));
|
|
442
|
-
const out = {};
|
|
443
|
-
for (const [key, value] of Object.entries(args)) {
|
|
444
|
-
if (value === null || value === void 0) out[key] = null;
|
|
445
|
-
else if (typeof value === "boolean" || typeof value === "number")
|
|
446
|
-
out[key] = value;
|
|
447
|
-
else if (typeof value === "string") {
|
|
448
|
-
if (SECRET_KEY.test(key) || SECRET_VALUE.test(value) || secretField && key === "text")
|
|
449
|
-
out[key] = "[redacted]";
|
|
450
|
-
else
|
|
451
|
-
out[key] = value.length <= EVENT_MAX_STRING ? value : value.slice(0, EVENT_MAX_STRING) + "\u2026";
|
|
452
|
-
} else out[key] = "[omitted]";
|
|
453
|
-
}
|
|
454
|
-
return out;
|
|
455
|
-
}
|
|
456
841
|
async function loadPlaywright() {
|
|
457
842
|
try {
|
|
458
843
|
const name = "playwright";
|
|
@@ -514,62 +899,14 @@ async function openBrowser(surfaces, opts = {}) {
|
|
|
514
899
|
scrubber
|
|
515
900
|
);
|
|
516
901
|
}
|
|
517
|
-
|
|
518
|
-
const maxText = opts.maxText ?? 2e4;
|
|
519
|
-
const observe = async (selector = "body") => {
|
|
520
|
-
const text2 = await browser.text(selector);
|
|
521
|
-
return {
|
|
522
|
-
url: browser.url,
|
|
523
|
-
title: await browser.title(),
|
|
524
|
-
text: text2.slice(0, maxText),
|
|
525
|
-
truncated: text2.length > maxText
|
|
526
|
-
};
|
|
527
|
-
};
|
|
528
|
-
const impls = {
|
|
529
|
-
browser_goto: async (a) => {
|
|
530
|
-
await browser.goto(typeof a.path === "string" ? a.path : void 0);
|
|
531
|
-
return observe();
|
|
532
|
-
},
|
|
533
|
-
browser_click: async (a) => {
|
|
534
|
-
await browser.click(str(a.selector, ""));
|
|
535
|
-
return observe();
|
|
536
|
-
},
|
|
537
|
-
browser_type: async (a) => {
|
|
538
|
-
await browser.type(str(a.selector, ""), String(a.text ?? ""));
|
|
539
|
-
return { ok: true, url: browser.url };
|
|
540
|
-
},
|
|
541
|
-
browser_press: async (a) => {
|
|
542
|
-
await browser.press(str(a.key, "Enter"));
|
|
543
|
-
return observe();
|
|
544
|
-
},
|
|
545
|
-
browser_scroll: async (a) => {
|
|
546
|
-
await browser.scroll(typeof a.dy === "number" ? a.dy : 600);
|
|
547
|
-
return { ok: true, url: browser.url };
|
|
548
|
-
},
|
|
549
|
-
browser_screenshot: async (a) => ({
|
|
550
|
-
image_base64: await browser.screenshotBase64(a.full_page === true),
|
|
551
|
-
url: browser.url
|
|
552
|
-
}),
|
|
553
|
-
browser_read: async (a) => observe(str(a.selector, "body")),
|
|
554
|
-
browser_back: async () => {
|
|
555
|
-
await browser.back();
|
|
556
|
-
return observe();
|
|
557
|
-
}
|
|
558
|
-
};
|
|
559
|
-
const specs = COMPUTER_USE_SPECS.map((s) => ({ ...s }));
|
|
560
|
-
return {
|
|
561
|
-
schemas: specs.map((spec) => schemaFromSignature(spec)),
|
|
562
|
-
impls,
|
|
563
|
-
specs
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
var SURFACE_KINDS, PLATFORM_SESSION_HEADER, SESSION_AUTH_MODES, BROWSER_TIERS, DEFAULT_VIEWPORT, SETTLE_TIMEOUT_MS, SETTLE_QUIET_MS, SETTLE_POLL_MS, EVENT_BATCH_SIZE, EVENT_FLUSH_INTERVAL_MS, EVENT_MAX_RETRIES, EVENT_SCREENSHOT_QUALITY, EVENT_MAX_STRING, SECRET_KEY, SECRET_VALUE, WorldSurfaceUnavailable, UI_TOKEN_QUERY, CAPABILITY_HOST, BrowserActionRecorder, WorldBrowser, COMPUTER_USE_SPECS, str;
|
|
902
|
+
var SURFACE_KINDS, FIELD_PROBE_TIMEOUT_MS, PLATFORM_SESSION_HEADER, SESSION_AUTH_MODES, BROWSER_TIERS, DEFAULT_VIEWPORT, SETTLE_TIMEOUT_MS, SETTLE_QUIET_MS, SETTLE_POLL_MS, EVENT_BATCH_SIZE, EVENT_FLUSH_INTERVAL_MS, EVENT_MAX_RETRIES, EVENT_SCREENSHOT_QUALITY, WorldSurfaceUnavailable, UI_TOKEN_QUERY, CAPABILITY_HOST, BrowserActionRecorder, WorldBrowser;
|
|
567
903
|
var init_browser = __esm({
|
|
568
904
|
"src/worlds/browser.ts"() {
|
|
569
905
|
"use strict";
|
|
570
|
-
|
|
906
|
+
init_credentialField();
|
|
571
907
|
init_browserReconnect();
|
|
572
908
|
SURFACE_KINDS = ["tools", "api", "ui", "browser"];
|
|
909
|
+
FIELD_PROBE_TIMEOUT_MS = 2e3;
|
|
573
910
|
PLATFORM_SESSION_HEADER = "X-World-Session";
|
|
574
911
|
SESSION_AUTH_MODES = ["vendor", "open"];
|
|
575
912
|
BROWSER_TIERS = ["standard", "premium"];
|
|
@@ -581,9 +918,6 @@ var init_browser = __esm({
|
|
|
581
918
|
EVENT_FLUSH_INTERVAL_MS = 1e3;
|
|
582
919
|
EVENT_MAX_RETRIES = 3;
|
|
583
920
|
EVENT_SCREENSHOT_QUALITY = 60;
|
|
584
|
-
EVENT_MAX_STRING = 500;
|
|
585
|
-
SECRET_KEY = /pass(word|wd)?|secret|token|api[-_]?key|authorization|cookie|(^|[-_ #.\["'=])(otp|pin|cvv|ssn)([-_ \]"']|$)/i;
|
|
586
|
-
SECRET_VALUE = /^((sk|pk|ghp|xox[abp])[-_][-_A-Za-z0-9]{8,}|AKIA[0-9A-Z]{12,}|Bearer [-_.A-Za-z0-9]{8,})/;
|
|
587
921
|
WorldSurfaceUnavailable = class extends Error {
|
|
588
922
|
constructor(surface, reason) {
|
|
589
923
|
super(`World surface '${surface}' is unavailable: ${reason}`);
|
|
@@ -706,6 +1040,8 @@ var init_browser = __esm({
|
|
|
706
1040
|
recorder;
|
|
707
1041
|
reconnector;
|
|
708
1042
|
scrubber;
|
|
1043
|
+
typed = [];
|
|
1044
|
+
typedText = new CredentialText([]);
|
|
709
1045
|
current;
|
|
710
1046
|
inflight = 0;
|
|
711
1047
|
lastNetwork = Date.now();
|
|
@@ -719,10 +1055,20 @@ var init_browser = __esm({
|
|
|
719
1055
|
get agentId() {
|
|
720
1056
|
return this.recorder?.agentId ?? null;
|
|
721
1057
|
}
|
|
722
|
-
/** `text` with this session's credentials (UI token, browser address)
|
|
1058
|
+
/** `text` with this session's credentials (UI token, browser address) and
|
|
1059
|
+
* the credentials typed into it removed. */
|
|
723
1060
|
scrub(text2) {
|
|
1061
|
+
return this.typedText.withhold(this.scrubber.scrub(text2));
|
|
1062
|
+
}
|
|
1063
|
+
/** `text` with this session's credentials removed and nothing else
|
|
1064
|
+
* changed: for text that is compared and never leaves the process. */
|
|
1065
|
+
scrubSession(text2) {
|
|
724
1066
|
return this.scrubber.scrub(text2);
|
|
725
1067
|
}
|
|
1068
|
+
/** Every credential typed into this browser by `type`. */
|
|
1069
|
+
get typedCredentials() {
|
|
1070
|
+
return [...this.typed];
|
|
1071
|
+
}
|
|
726
1072
|
watchNetwork(page) {
|
|
727
1073
|
page.on("request", () => {
|
|
728
1074
|
this.inflight += 1;
|
|
@@ -766,7 +1112,7 @@ var init_browser = __esm({
|
|
|
766
1112
|
async recover(reconnector, cause) {
|
|
767
1113
|
const started = Date.now();
|
|
768
1114
|
const message = cause instanceof Error ? cause.message : String(cause);
|
|
769
|
-
const args = { cause: this.
|
|
1115
|
+
const args = { cause: this.scrub(message).slice(0, 200) };
|
|
770
1116
|
let result;
|
|
771
1117
|
try {
|
|
772
1118
|
result = await reconnector.recover(cause, (c) => this.adopt(c));
|
|
@@ -801,7 +1147,9 @@ var init_browser = __esm({
|
|
|
801
1147
|
}
|
|
802
1148
|
/** Run one action and report it: the event carries what was asked,
|
|
803
1149
|
* whether it worked, and the screen after — for failures too, so a
|
|
804
|
-
* reviewer sees what the agent saw when the selector did not match.
|
|
1150
|
+
* reviewer sees what the agent saw when the selector did not match. The
|
|
1151
|
+
* error it throws keeps no session credential and no credential typed into
|
|
1152
|
+
* this browser, which Playwright's call log would quote. */
|
|
805
1153
|
async act(action, args, fn, onLoss = "report") {
|
|
806
1154
|
const started = Date.now();
|
|
807
1155
|
try {
|
|
@@ -809,6 +1157,7 @@ var init_browser = __esm({
|
|
|
809
1157
|
await this.report(action, args, started, null);
|
|
810
1158
|
return result;
|
|
811
1159
|
} catch (error) {
|
|
1160
|
+
this.scrubError(error);
|
|
812
1161
|
await this.report(action, args, started, error);
|
|
813
1162
|
throw error;
|
|
814
1163
|
}
|
|
@@ -817,7 +1166,7 @@ var init_browser = __esm({
|
|
|
817
1166
|
async report(action, args, started, failure) {
|
|
818
1167
|
const recorder = this.recorder;
|
|
819
1168
|
if (!recorder) return;
|
|
820
|
-
const error = failure === null ? null : this.
|
|
1169
|
+
const error = failure === null ? null : this.scrub(
|
|
821
1170
|
failure instanceof Error ? `${failure.name}: ${failure.message}` : String(failure)
|
|
822
1171
|
).slice(0, 4e3);
|
|
823
1172
|
recorder.record({
|
|
@@ -830,7 +1179,7 @@ var init_browser = __esm({
|
|
|
830
1179
|
Object.fromEntries(
|
|
831
1180
|
Object.entries(args).map(([key, value]) => [
|
|
832
1181
|
key,
|
|
833
|
-
typeof value === "string" ? this.
|
|
1182
|
+
typeof value === "string" ? this.scrub(value) : value
|
|
834
1183
|
])
|
|
835
1184
|
)
|
|
836
1185
|
),
|
|
@@ -849,8 +1198,8 @@ var init_browser = __esm({
|
|
|
849
1198
|
screenshot: null
|
|
850
1199
|
};
|
|
851
1200
|
try {
|
|
852
|
-
out.url = this.
|
|
853
|
-
out.title = this.
|
|
1201
|
+
out.url = this.scrub(this.page.url());
|
|
1202
|
+
out.title = this.scrub(await this.page.title());
|
|
854
1203
|
const jpeg = await this.page.screenshot({
|
|
855
1204
|
type: "jpeg",
|
|
856
1205
|
quality: EVENT_SCREENSHOT_QUALITY
|
|
@@ -887,7 +1236,7 @@ var init_browser = __esm({
|
|
|
887
1236
|
async () => {
|
|
888
1237
|
await this.page.goto(target, { waitUntil: "load" });
|
|
889
1238
|
await this.settle();
|
|
890
|
-
return this.
|
|
1239
|
+
return this.url;
|
|
891
1240
|
},
|
|
892
1241
|
// Navigating again lands on the same page: safe to replay.
|
|
893
1242
|
"retry"
|
|
@@ -897,7 +1246,7 @@ var init_browser = __esm({
|
|
|
897
1246
|
return this.act("browser_back", {}, async () => {
|
|
898
1247
|
await this.page.goBack({ waitUntil: "load" });
|
|
899
1248
|
await this.settle();
|
|
900
|
-
return this.
|
|
1249
|
+
return this.url;
|
|
901
1250
|
});
|
|
902
1251
|
}
|
|
903
1252
|
/** Wait for the page to finish reacting to an action. `load` alone is not
|
|
@@ -916,19 +1265,54 @@ var init_browser = __esm({
|
|
|
916
1265
|
await this.page.waitForTimeout(SETTLE_POLL_MS);
|
|
917
1266
|
}
|
|
918
1267
|
}
|
|
919
|
-
async click(selector) {
|
|
1268
|
+
async click(selector, opts = {}) {
|
|
920
1269
|
await this.act("browser_click", { selector }, async () => {
|
|
921
|
-
await this.page.click(selector);
|
|
1270
|
+
await this.page.click(selector, { timeout: opts.timeoutMs });
|
|
922
1271
|
await this.settle();
|
|
923
1272
|
});
|
|
924
1273
|
}
|
|
925
|
-
|
|
1274
|
+
/** Replace the field's value with `text`. `opts.credential` is whether the
|
|
1275
|
+
* field takes one, when the caller already probed it; a credential is
|
|
1276
|
+
* withheld from the event and from any error. */
|
|
1277
|
+
async type(selector, text2, opts = {}) {
|
|
1278
|
+
const secret = opts.credential ?? await this.credentialField(selector);
|
|
1279
|
+
if (secret) this.typed.push(text2);
|
|
1280
|
+
this.typedText = new CredentialText(this.typed);
|
|
926
1281
|
await this.act(
|
|
927
1282
|
"browser_type",
|
|
928
|
-
{ selector, text: text2 },
|
|
929
|
-
() => this.page.fill(selector, text2)
|
|
1283
|
+
{ selector, text: secret ? "[redacted]" : text2 },
|
|
1284
|
+
() => this.page.fill(selector, text2, { timeout: opts.timeoutMs })
|
|
930
1285
|
);
|
|
931
1286
|
}
|
|
1287
|
+
/** `DESCRIBE_FIELD_JS` of the element `selector` finds, or `UNREADABLE`. */
|
|
1288
|
+
async describeField(selector) {
|
|
1289
|
+
try {
|
|
1290
|
+
const described = await this.page.locator(selector).evaluate(describeField, void 0, { timeout: FIELD_PROBE_TIMEOUT_MS });
|
|
1291
|
+
return String(described ?? "");
|
|
1292
|
+
} catch {
|
|
1293
|
+
return UNREADABLE;
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
/** Whether the field `selector` finds takes a credential; one it cannot
|
|
1297
|
+
* read counts. */
|
|
1298
|
+
async credentialField(selector) {
|
|
1299
|
+
return isCredentialField(await this.describeField(selector));
|
|
1300
|
+
}
|
|
1301
|
+
/** What the field `selector` finds holds (`FIELD_VALUE_JS`), or null when
|
|
1302
|
+
* it cannot be read. */
|
|
1303
|
+
async fieldValue(selector) {
|
|
1304
|
+
try {
|
|
1305
|
+
const value = await this.page.locator(selector).evaluate(readFieldValue, void 0, { timeout: FIELD_PROBE_TIMEOUT_MS });
|
|
1306
|
+
return value === null || value === void 0 ? null : String(value);
|
|
1307
|
+
} catch {
|
|
1308
|
+
return null;
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
/** Take this session's credentials out of `error` and the errors it came
|
|
1312
|
+
* from, in place. */
|
|
1313
|
+
scrubError(error) {
|
|
1314
|
+
scrubError(error, (text2) => this.scrub(text2));
|
|
1315
|
+
}
|
|
932
1316
|
async press(key) {
|
|
933
1317
|
await this.act("browser_press", { key }, async () => {
|
|
934
1318
|
await this.page.keyboard.press(key);
|
|
@@ -951,41 +1335,549 @@ var init_browser = __esm({
|
|
|
951
1335
|
async screenshotBase64(fullPage = false) {
|
|
952
1336
|
return (await this.screenshot(fullPage)).toString("base64");
|
|
953
1337
|
}
|
|
1338
|
+
/** The visible text of `selector`'s element, without what any field on the
|
|
1339
|
+
* page that takes a credential holds. */
|
|
954
1340
|
async text(selector = "body") {
|
|
955
|
-
|
|
1341
|
+
const withheld = new CredentialText(await this.credentialTexts());
|
|
1342
|
+
return withheld.withhold(
|
|
1343
|
+
await this.resilient(() => this.page.innerText(selector), "retry")
|
|
1344
|
+
);
|
|
1345
|
+
}
|
|
1346
|
+
/** What each field on the page that takes a credential holds: an input's
|
|
1347
|
+
* or textarea's value, a select's chosen option, a contenteditable's text. */
|
|
1348
|
+
async credentialTexts() {
|
|
1349
|
+
return this.resilient(async () => {
|
|
1350
|
+
const pairs = await this.page.locator(FIELDS).evaluateAll(readEditables);
|
|
1351
|
+
return credentialTexts(pairs);
|
|
1352
|
+
}, "retry");
|
|
1353
|
+
}
|
|
1354
|
+
/** Wait until the element `selector` finds could be clicked, without
|
|
1355
|
+
* clicking it. */
|
|
1356
|
+
async actionable(selector) {
|
|
1357
|
+
await this.resilient(() => this.page.locator(selector).click({ trial: true }), "retry");
|
|
1358
|
+
}
|
|
1359
|
+
async ariaSnapshot() {
|
|
1360
|
+
return this.resilient(async () => {
|
|
1361
|
+
if (!this.page.ariaSnapshot)
|
|
1362
|
+
throw new TypeError("this Playwright has no page.ariaSnapshot");
|
|
1363
|
+
return this.page.ariaSnapshot({ mode: "ai" });
|
|
1364
|
+
}, "retry");
|
|
956
1365
|
}
|
|
957
1366
|
async html() {
|
|
958
1367
|
return this.resilient(() => this.page.content(), "retry");
|
|
959
1368
|
}
|
|
960
1369
|
get url() {
|
|
961
|
-
return this.page.url();
|
|
1370
|
+
return withoutUiToken(this.page.url());
|
|
1371
|
+
}
|
|
1372
|
+
async title() {
|
|
1373
|
+
return this.resilient(() => this.page.title(), "retry");
|
|
1374
|
+
}
|
|
1375
|
+
async close() {
|
|
1376
|
+
try {
|
|
1377
|
+
await this.teardown();
|
|
1378
|
+
} finally {
|
|
1379
|
+
await this.recorder?.close();
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
};
|
|
1383
|
+
}
|
|
1384
|
+
});
|
|
1385
|
+
|
|
1386
|
+
// src/worlds/pageState.ts
|
|
1387
|
+
function selectorRef(selector) {
|
|
1388
|
+
if (selector.includes("aria-ref"))
|
|
1389
|
+
throw new PageStateError(
|
|
1390
|
+
"aria-ref selectors are not taken: pass ref=\u2026 from browser_snapshot"
|
|
1391
|
+
);
|
|
1392
|
+
return REF_SELECTOR.exec(selector.replace(/^ +| +$/g, ""))?.[1] ?? null;
|
|
1393
|
+
}
|
|
1394
|
+
var DEFAULT_MAX_CHARS, REF_ACT_TIMEOUT_MS, STEADY_READS, NEEDS_PLAYWRIGHT, CHANGED, LINE_KEY, ATTRIBUTES, FOCUS, STATES, ROLE, REF, REF_SELECTOR, EDITABLE_ROLES, VALUE_KEYS, WITHHELD, PageStateError, AriaLine, Touched, sameLines, deeper, PageState, PageObserver;
|
|
1395
|
+
var init_pageState = __esm({
|
|
1396
|
+
"src/worlds/pageState.ts"() {
|
|
1397
|
+
"use strict";
|
|
1398
|
+
init_credentialField();
|
|
1399
|
+
DEFAULT_MAX_CHARS = 2e4;
|
|
1400
|
+
REF_ACT_TIMEOUT_MS = 2e3;
|
|
1401
|
+
STEADY_READS = 4;
|
|
1402
|
+
NEEDS_PLAYWRIGHT = "browser_snapshot needs Playwright 1.59 or newer (npm install playwright@latest)";
|
|
1403
|
+
CHANGED = "the page changed since the last browser_snapshot: take a new one (a page that never holds still can be driven with text= or CSS selectors)";
|
|
1404
|
+
LINE_KEY = /^ *- ('(?:[^']|'')*'|.*?)(:(?: .*)?)?$/s;
|
|
1405
|
+
ATTRIBUTES = /(?: \[[^[\]]*\])*$/;
|
|
1406
|
+
FOCUS = / \[active\]/g;
|
|
1407
|
+
STATES = / \[(?:checked(?:=mixed)?|expanded|pressed(?:=mixed)?|selected)\]/g;
|
|
1408
|
+
ROLE = /^[a-z]+/;
|
|
1409
|
+
REF = /\[ref=((?:f[0-9]+)?e[0-9]+)\]/g;
|
|
1410
|
+
REF_SELECTOR = /^ref=((?:f[0-9]+)?e[0-9]+)$/;
|
|
1411
|
+
EDITABLE_ROLES = /* @__PURE__ */ new Set([
|
|
1412
|
+
"textbox",
|
|
1413
|
+
"searchbox",
|
|
1414
|
+
"combobox",
|
|
1415
|
+
"spinbutton",
|
|
1416
|
+
"slider"
|
|
1417
|
+
]);
|
|
1418
|
+
VALUE_KEYS = /* @__PURE__ */ new Set(["text", "/placeholder"]);
|
|
1419
|
+
WITHHELD = ": [redacted]";
|
|
1420
|
+
PageStateError = class extends Error {
|
|
1421
|
+
name = "PageStateError";
|
|
1422
|
+
};
|
|
1423
|
+
AriaLine = class _AriaLine {
|
|
1424
|
+
constructor(text2, indent, key = "", attributes = "", rest = "") {
|
|
1425
|
+
this.text = text2;
|
|
1426
|
+
this.indent = indent;
|
|
1427
|
+
this.key = key;
|
|
1428
|
+
this.attributes = attributes;
|
|
1429
|
+
this.rest = rest;
|
|
1430
|
+
}
|
|
1431
|
+
text;
|
|
1432
|
+
indent;
|
|
1433
|
+
key;
|
|
1434
|
+
attributes;
|
|
1435
|
+
rest;
|
|
1436
|
+
static parse(text2) {
|
|
1437
|
+
const indent = text2.length - text2.replace(/^ +/, "").length;
|
|
1438
|
+
const found = LINE_KEY.exec(text2);
|
|
1439
|
+
if (!found) return new _AriaLine(text2, indent);
|
|
1440
|
+
const key = found[1].startsWith("'") ? found[1].slice(1, -1).replaceAll("''", "'") : found[1];
|
|
1441
|
+
return new _AriaLine(
|
|
1442
|
+
text2,
|
|
1443
|
+
indent,
|
|
1444
|
+
key,
|
|
1445
|
+
ATTRIBUTES.exec(key)?.[0] ?? "",
|
|
1446
|
+
found[2] ?? ""
|
|
1447
|
+
);
|
|
1448
|
+
}
|
|
1449
|
+
static parseAll(aria) {
|
|
1450
|
+
return aria === "" ? [] : aria.split("\n").map((text2) => _AriaLine.parse(text2));
|
|
1451
|
+
}
|
|
1452
|
+
get refs() {
|
|
1453
|
+
return [...this.attributes.matchAll(REF)].map((ref) => ref[1]);
|
|
1454
|
+
}
|
|
1455
|
+
get disabled() {
|
|
1456
|
+
return this.attributes.includes("[disabled]");
|
|
1457
|
+
}
|
|
1458
|
+
get editable() {
|
|
1459
|
+
const role = ROLE.exec(this.key)?.[0];
|
|
1460
|
+
return role !== void 0 && EDITABLE_ROLES.has(role);
|
|
1461
|
+
}
|
|
1462
|
+
/** A value line: a field's text, or the placeholder it shows. */
|
|
1463
|
+
get value() {
|
|
1464
|
+
return VALUE_KEYS.has(this.key);
|
|
1465
|
+
}
|
|
1466
|
+
get states() {
|
|
1467
|
+
return this.attributes.match(STATES) ?? [];
|
|
1468
|
+
}
|
|
1469
|
+
get namedLikeCredential() {
|
|
1470
|
+
return SECRET_KEY.test(
|
|
1471
|
+
this.key.slice(0, this.key.length - this.attributes.length)
|
|
1472
|
+
);
|
|
1473
|
+
}
|
|
1474
|
+
/** Whether every value in and under this line is withheld. A field is,
|
|
1475
|
+
* when it is named like a credential or sits in something that is, has no
|
|
1476
|
+
* ref to probe, or `describe` reads it as a credential field. Any other
|
|
1477
|
+
* line is, when it is named like a credential and holds typed text (a
|
|
1478
|
+
* contenteditable), or has no ref to tell. */
|
|
1479
|
+
async credentialField(describe2, withinCredential) {
|
|
1480
|
+
if (this.editable)
|
|
1481
|
+
return this.credentialFieldInput(describe2, withinCredential);
|
|
1482
|
+
if (!this.namedLikeCredential) return false;
|
|
1483
|
+
if (this.refs.length === 0) return true;
|
|
1484
|
+
return isTextField(await describe2(this.refs[0]));
|
|
1485
|
+
}
|
|
1486
|
+
async credentialFieldInput(describe2, withinCredential) {
|
|
1487
|
+
if (withinCredential || this.namedLikeCredential) return true;
|
|
1488
|
+
if (this.refs.length === 0) return true;
|
|
1489
|
+
return isCredentialField(await describe2(this.refs[0]));
|
|
1490
|
+
}
|
|
1491
|
+
/** The line as shown: `withholding` applied to its text, while its refs and
|
|
1492
|
+
* states are still read from the attribute run Playwright wrote, so a
|
|
1493
|
+
* withheld name cannot join that run. */
|
|
1494
|
+
withheldBy(withhold) {
|
|
1495
|
+
return new _AriaLine(
|
|
1496
|
+
this.withholding(withhold),
|
|
1497
|
+
this.indent,
|
|
1498
|
+
this.key,
|
|
1499
|
+
this.attributes,
|
|
1500
|
+
this.rest
|
|
1501
|
+
);
|
|
1502
|
+
}
|
|
1503
|
+
/** The line with `withhold` applied to its name and value, its attribute
|
|
1504
|
+
* run (refs, states, levels) as Playwright wrote it. */
|
|
1505
|
+
withholding(withhold) {
|
|
1506
|
+
const at = this.attributes ? this.text.lastIndexOf(
|
|
1507
|
+
this.attributes,
|
|
1508
|
+
this.text.length - this.rest.length - this.attributes.length
|
|
1509
|
+
) : -1;
|
|
1510
|
+
if (at < 0) return withhold(this.text);
|
|
1511
|
+
const end = at + this.attributes.length;
|
|
1512
|
+
return withhold(this.text.slice(0, at)) + this.attributes + withhold(this.text.slice(end));
|
|
1513
|
+
}
|
|
1514
|
+
/** The line with its own value replaced, keeping the key as Playwright
|
|
1515
|
+
* wrote it. */
|
|
1516
|
+
get withheld() {
|
|
1517
|
+
if (this.key === "/placeholder" || !this.rest.startsWith(": "))
|
|
1518
|
+
return this.text;
|
|
1519
|
+
return this.text.slice(0, this.text.length - this.rest.length) + WITHHELD;
|
|
1520
|
+
}
|
|
1521
|
+
};
|
|
1522
|
+
Touched = class _Touched {
|
|
1523
|
+
constructor(clicked = /* @__PURE__ */ new Map(), typed = /* @__PURE__ */ new Map()) {
|
|
1524
|
+
this.clicked = clicked;
|
|
1525
|
+
this.typed = typed;
|
|
1526
|
+
}
|
|
1527
|
+
clicked;
|
|
1528
|
+
typed;
|
|
1529
|
+
afterClick(ref, states) {
|
|
1530
|
+
return new _Touched(new Map([...this.clicked, [ref, states]]), this.typed);
|
|
1531
|
+
}
|
|
1532
|
+
afterTyping(ref, text2) {
|
|
1533
|
+
return new _Touched(this.clicked, new Map([...this.typed, [ref, text2]]));
|
|
1534
|
+
}
|
|
1535
|
+
/** The snapshot's lines as the page should now read them. */
|
|
1536
|
+
expected(lines) {
|
|
1537
|
+
return this.compared(lines, (line) => this.leftByClick(line));
|
|
1538
|
+
}
|
|
1539
|
+
/** A fresh read's lines, in the same form. */
|
|
1540
|
+
actual(lines) {
|
|
1541
|
+
return this.compared(lines, (line) => line.states);
|
|
1542
|
+
}
|
|
1543
|
+
compared(lines, states) {
|
|
1544
|
+
const out = [];
|
|
1545
|
+
let typedAt = null;
|
|
1546
|
+
for (const line of lines) {
|
|
1547
|
+
if (typedAt !== null && line.indent > typedAt && line.value) continue;
|
|
1548
|
+
typedAt = this.isTyped(line) ? line.indent : null;
|
|
1549
|
+
out.push(this.comparedLine(line, states(line)));
|
|
1550
|
+
}
|
|
1551
|
+
return out;
|
|
1552
|
+
}
|
|
1553
|
+
isTyped(line) {
|
|
1554
|
+
return line.refs.some((ref) => this.typed.has(ref));
|
|
1555
|
+
}
|
|
1556
|
+
clickedRef(line) {
|
|
1557
|
+
return line.refs.find((ref) => this.clicked.has(ref));
|
|
1558
|
+
}
|
|
1559
|
+
leftByClick(line) {
|
|
1560
|
+
const ref = this.clickedRef(line);
|
|
1561
|
+
return ref === void 0 ? line.states : this.clicked.get(ref);
|
|
1562
|
+
}
|
|
1563
|
+
comparedLine(line, states) {
|
|
1564
|
+
if (this.isTyped(line))
|
|
1565
|
+
return (" ".repeat(line.indent) + "- " + line.key).replace(FOCUS, "");
|
|
1566
|
+
if (this.clickedRef(line) !== void 0)
|
|
1567
|
+
return line.text.replace(FOCUS, "").replace(STATES, "") + states.join("");
|
|
1568
|
+
return line.text.replace(FOCUS, "");
|
|
1569
|
+
}
|
|
1570
|
+
};
|
|
1571
|
+
sameLines = (a, b) => a.length === b.length && a.every((line, at) => line === b[at]);
|
|
1572
|
+
deeper = (line, below) => below !== null && line.indent > below ? below : null;
|
|
1573
|
+
PageState = class _PageState {
|
|
1574
|
+
constructor(url, title, snapshot, refs, disabled, truncated, credentials = /* @__PURE__ */ new Set()) {
|
|
1575
|
+
this.url = url;
|
|
1576
|
+
this.title = title;
|
|
1577
|
+
this.snapshot = snapshot;
|
|
1578
|
+
this.refs = refs;
|
|
1579
|
+
this.disabled = disabled;
|
|
1580
|
+
this.truncated = truncated;
|
|
1581
|
+
this.credentials = credentials;
|
|
1582
|
+
}
|
|
1583
|
+
url;
|
|
1584
|
+
title;
|
|
1585
|
+
snapshot;
|
|
1586
|
+
refs;
|
|
1587
|
+
disabled;
|
|
1588
|
+
truncated;
|
|
1589
|
+
credentials;
|
|
1590
|
+
static parse(aria, opts) {
|
|
1591
|
+
return _PageState.ofLines(AriaLine.parseAll(aria), opts);
|
|
1592
|
+
}
|
|
1593
|
+
static ofLines(lines, opts) {
|
|
1594
|
+
const maxChars = opts.maxChars ?? DEFAULT_MAX_CHARS;
|
|
1595
|
+
const shown = [];
|
|
1596
|
+
let size = 0;
|
|
1597
|
+
for (const line of lines) {
|
|
1598
|
+
const width = [...line.text].length + 1;
|
|
1599
|
+
if (size + width > maxChars) break;
|
|
1600
|
+
size += width;
|
|
1601
|
+
shown.push(line);
|
|
1602
|
+
}
|
|
1603
|
+
return new _PageState(
|
|
1604
|
+
opts.url,
|
|
1605
|
+
opts.title,
|
|
1606
|
+
shown.map((line) => line.text).join("\n"),
|
|
1607
|
+
new Set(shown.flatMap((line) => line.refs)),
|
|
1608
|
+
new Set(
|
|
1609
|
+
shown.filter((line) => line.disabled).flatMap((line) => line.refs)
|
|
1610
|
+
),
|
|
1611
|
+
shown.length < lines.length,
|
|
1612
|
+
opts.credentials ?? /* @__PURE__ */ new Set()
|
|
1613
|
+
);
|
|
1614
|
+
}
|
|
1615
|
+
/** `aria` with credential values withheld: every value in and under a
|
|
1616
|
+
* credential field (see `AriaLine.credentialField`; `describe` is
|
|
1617
|
+
* `DESCRIBE_FIELD_JS` of a ref's element), the placeholder aside, and the
|
|
1618
|
+
* value of any line named like a credential. Names, roles and refs stay. */
|
|
1619
|
+
static async redacted(aria, describe2) {
|
|
1620
|
+
const out = [];
|
|
1621
|
+
const withheld = [];
|
|
1622
|
+
let withheldBelow = null;
|
|
1623
|
+
let credentialBelow = null;
|
|
1624
|
+
for (const line of AriaLine.parseAll(aria)) {
|
|
1625
|
+
withheldBelow = deeper(line, withheldBelow);
|
|
1626
|
+
credentialBelow = deeper(line, credentialBelow);
|
|
1627
|
+
if (withheldBelow === null && await line.credentialField(describe2, credentialBelow !== null))
|
|
1628
|
+
withheldBelow = line.indent;
|
|
1629
|
+
if (credentialBelow === null && line.namedLikeCredential)
|
|
1630
|
+
credentialBelow = line.indent;
|
|
1631
|
+
const hidden = withheldBelow !== null || line.namedLikeCredential;
|
|
1632
|
+
out.push(hidden ? line.withheld : line.text);
|
|
1633
|
+
if (hidden) withheld.push(...line.refs);
|
|
1634
|
+
}
|
|
1635
|
+
return { snapshot: out.join("\n"), withheld: new Set(withheld) };
|
|
1636
|
+
}
|
|
1637
|
+
target(ref) {
|
|
1638
|
+
if (!this.refs.has(ref))
|
|
1639
|
+
throw new PageStateError(
|
|
1640
|
+
`ref=${ref} is not in the last browser_snapshot: take a new one`
|
|
1641
|
+
);
|
|
1642
|
+
if (this.disabled.has(ref))
|
|
1643
|
+
throw new PageStateError(`ref=${ref} is disabled`);
|
|
1644
|
+
return `aria-ref=${ref}`;
|
|
1645
|
+
}
|
|
1646
|
+
observation() {
|
|
1647
|
+
return {
|
|
1648
|
+
url: this.url,
|
|
1649
|
+
title: this.title,
|
|
1650
|
+
snapshot: this.snapshot,
|
|
1651
|
+
truncated: this.truncated
|
|
1652
|
+
};
|
|
1653
|
+
}
|
|
1654
|
+
};
|
|
1655
|
+
PageObserver = class {
|
|
1656
|
+
constructor(browser, maxChars = DEFAULT_MAX_CHARS) {
|
|
1657
|
+
this.browser = browser;
|
|
1658
|
+
this.maxChars = maxChars;
|
|
1659
|
+
}
|
|
1660
|
+
browser;
|
|
1661
|
+
maxChars;
|
|
1662
|
+
last = null;
|
|
1663
|
+
seen = [];
|
|
1664
|
+
seenUrl = "";
|
|
1665
|
+
touched = new Touched();
|
|
1666
|
+
turn = Promise.resolve();
|
|
1667
|
+
async snapshot() {
|
|
1668
|
+
return this.inTurn(() => this.takeSnapshot());
|
|
1669
|
+
}
|
|
1670
|
+
async click(selector) {
|
|
1671
|
+
return this.inTurn(() => this.clickOnce(selector));
|
|
1672
|
+
}
|
|
1673
|
+
async type(selector, text2) {
|
|
1674
|
+
return this.inTurn(() => this.typeOnce(selector, text2));
|
|
1675
|
+
}
|
|
1676
|
+
/** One call at a time, so a tool call a model made in parallel cannot act
|
|
1677
|
+
* between another's checks and its action. */
|
|
1678
|
+
inTurn(fn) {
|
|
1679
|
+
const run = this.turn.then(fn, fn);
|
|
1680
|
+
this.turn = run.catch(() => void 0);
|
|
1681
|
+
return run;
|
|
1682
|
+
}
|
|
1683
|
+
async takeSnapshot() {
|
|
1684
|
+
const aria = this.browser.scrubSession(await this.steady());
|
|
1685
|
+
const shown = await PageState.redacted(
|
|
1686
|
+
aria,
|
|
1687
|
+
(ref) => this.browser.describeField(`aria-ref=${ref}`)
|
|
1688
|
+
);
|
|
1689
|
+
const secrets = new CredentialText([
|
|
1690
|
+
...await this.withheldValues(shown),
|
|
1691
|
+
...await this.browser.credentialTexts(),
|
|
1692
|
+
...this.browser.typedCredentials
|
|
1693
|
+
]);
|
|
1694
|
+
const lines = AriaLine.parseAll(shown.snapshot).map(
|
|
1695
|
+
(line) => line.withheldBy((text2) => secrets.withhold(text2))
|
|
1696
|
+
);
|
|
1697
|
+
this.last = PageState.ofLines(lines, {
|
|
1698
|
+
url: this.url(),
|
|
1699
|
+
title: this.browser.scrub(await this.browser.title()),
|
|
1700
|
+
maxChars: this.maxChars,
|
|
1701
|
+
credentials: shown.withheld
|
|
1702
|
+
});
|
|
1703
|
+
this.seen = AriaLine.parseAll(aria);
|
|
1704
|
+
this.seenUrl = this.browser.scrubSession(this.browser.url);
|
|
1705
|
+
this.touched = new Touched();
|
|
1706
|
+
return this.last;
|
|
1707
|
+
}
|
|
1708
|
+
/** The values of the fields the redaction withheld: a page may repeat them
|
|
1709
|
+
* in another line's name (a row or cell named from its content, a label
|
|
1710
|
+
* that wraps the field). */
|
|
1711
|
+
async withheldValues(shown) {
|
|
1712
|
+
const refs = AriaLine.parseAll(shown.snapshot).filter((line) => line.editable).flatMap((line) => line.refs).filter((ref) => shown.withheld.has(ref));
|
|
1713
|
+
const values = [];
|
|
1714
|
+
for (const ref of refs)
|
|
1715
|
+
values.push(await this.browser.fieldValue(`aria-ref=${ref}`) ?? "");
|
|
1716
|
+
return values;
|
|
1717
|
+
}
|
|
1718
|
+
async clickOnce(selector) {
|
|
1719
|
+
const ref = selectorRef(selector);
|
|
1720
|
+
if (ref === null) return this.browser.click(selector);
|
|
1721
|
+
const [, target] = this.target(ref);
|
|
1722
|
+
await this.ready(target);
|
|
1723
|
+
await this.browser.click(target, { timeoutMs: REF_ACT_TIMEOUT_MS });
|
|
1724
|
+
const left = (await this.now()).find((line) => line.refs.includes(ref));
|
|
1725
|
+
if (left) this.touched = this.touched.afterClick(ref, left.states);
|
|
1726
|
+
}
|
|
1727
|
+
async typeOnce(selector, text2) {
|
|
1728
|
+
const ref = selectorRef(selector);
|
|
1729
|
+
if (ref === null) return this.browser.type(selector, text2);
|
|
1730
|
+
const [last, target] = this.target(ref);
|
|
1731
|
+
const credential = last.credentials.has(ref) || await this.browser.credentialField(target);
|
|
1732
|
+
await this.ready(target);
|
|
1733
|
+
await this.browser.type(target, text2, {
|
|
1734
|
+
timeoutMs: REF_ACT_TIMEOUT_MS,
|
|
1735
|
+
credential
|
|
1736
|
+
});
|
|
1737
|
+
this.touched = this.touched.afterTyping(ref, text2);
|
|
962
1738
|
}
|
|
963
|
-
|
|
964
|
-
|
|
1739
|
+
target(ref) {
|
|
1740
|
+
if (this.last === null)
|
|
1741
|
+
throw new PageStateError(
|
|
1742
|
+
"ref=\u2026 selectors come from browser_snapshot: take one first"
|
|
1743
|
+
);
|
|
1744
|
+
return [this.last, this.last.target(ref)];
|
|
1745
|
+
}
|
|
1746
|
+
async ready(target) {
|
|
1747
|
+
await this.still();
|
|
1748
|
+
await this.browser.actionable(target);
|
|
1749
|
+
await this.still();
|
|
1750
|
+
}
|
|
1751
|
+
/** A page still rendering when it is read would refuse the model's next
|
|
1752
|
+
* ref, so the snapshot it is shown is one that read the same before and
|
|
1753
|
+
* after the page settled again. */
|
|
1754
|
+
async steady() {
|
|
1755
|
+
const untouched = new Touched();
|
|
1756
|
+
let aria = await this.read();
|
|
1757
|
+
for (let read = 1; read < STEADY_READS; read++) {
|
|
1758
|
+
await this.browser.settle();
|
|
1759
|
+
const again = await this.read();
|
|
1760
|
+
if (sameLines(
|
|
1761
|
+
untouched.actual(AriaLine.parseAll(again)),
|
|
1762
|
+
untouched.actual(AriaLine.parseAll(aria))
|
|
1763
|
+
))
|
|
1764
|
+
return again;
|
|
1765
|
+
aria = again;
|
|
1766
|
+
}
|
|
1767
|
+
return aria;
|
|
965
1768
|
}
|
|
966
|
-
async
|
|
1769
|
+
async read() {
|
|
967
1770
|
try {
|
|
968
|
-
await this.
|
|
969
|
-
}
|
|
970
|
-
|
|
1771
|
+
return await this.browser.ariaSnapshot();
|
|
1772
|
+
} catch (error) {
|
|
1773
|
+
if (error instanceof TypeError)
|
|
1774
|
+
throw new PageStateError(NEEDS_PLAYWRIGHT);
|
|
1775
|
+
throw error;
|
|
971
1776
|
}
|
|
972
1777
|
}
|
|
1778
|
+
url() {
|
|
1779
|
+
return this.browser.scrub(this.browser.url);
|
|
1780
|
+
}
|
|
1781
|
+
async now() {
|
|
1782
|
+
return AriaLine.parseAll(this.browser.scrubSession(await this.read()));
|
|
1783
|
+
}
|
|
1784
|
+
async still() {
|
|
1785
|
+
if (this.browser.scrubSession(this.browser.url) !== this.seenUrl || !sameLines(
|
|
1786
|
+
this.touched.actual(await this.now()),
|
|
1787
|
+
this.touched.expected(this.seen)
|
|
1788
|
+
))
|
|
1789
|
+
throw new PageStateError(CHANGED);
|
|
1790
|
+
for (const [ref, text2] of this.touched.typed)
|
|
1791
|
+
if (await this.browser.fieldValue(`aria-ref=${ref}`) !== text2)
|
|
1792
|
+
throw new PageStateError(CHANGED);
|
|
1793
|
+
}
|
|
1794
|
+
};
|
|
1795
|
+
}
|
|
1796
|
+
});
|
|
1797
|
+
|
|
1798
|
+
// src/worlds/browserTools.ts
|
|
1799
|
+
function computerUseToolkit(browser, opts = {}) {
|
|
1800
|
+
const maxText = opts.maxText ?? DEFAULT_MAX_CHARS;
|
|
1801
|
+
const pages = new PageObserver(browser, maxText);
|
|
1802
|
+
const observe = async (selector = "body") => {
|
|
1803
|
+
const text2 = browser.scrub(await browser.text(selector));
|
|
1804
|
+
return {
|
|
1805
|
+
url: browser.scrub(browser.url),
|
|
1806
|
+
title: browser.scrub(await browser.title()),
|
|
1807
|
+
text: text2.slice(0, maxText),
|
|
1808
|
+
truncated: text2.length > maxText
|
|
973
1809
|
};
|
|
1810
|
+
};
|
|
1811
|
+
const impls = {
|
|
1812
|
+
browser_goto: async (a) => {
|
|
1813
|
+
await browser.goto(typeof a.path === "string" ? a.path : void 0);
|
|
1814
|
+
return observe();
|
|
1815
|
+
},
|
|
1816
|
+
browser_snapshot: async () => (await pages.snapshot()).observation(),
|
|
1817
|
+
browser_click: async (a) => {
|
|
1818
|
+
await pages.click(str(a.selector, ""));
|
|
1819
|
+
return observe();
|
|
1820
|
+
},
|
|
1821
|
+
browser_type: async (a) => {
|
|
1822
|
+
await pages.type(str(a.selector, ""), String(a.text ?? ""));
|
|
1823
|
+
return { ok: true, url: browser.scrub(browser.url) };
|
|
1824
|
+
},
|
|
1825
|
+
browser_press: async (a) => {
|
|
1826
|
+
await browser.press(str(a.key, "Enter"));
|
|
1827
|
+
return observe();
|
|
1828
|
+
},
|
|
1829
|
+
browser_scroll: async (a) => {
|
|
1830
|
+
await browser.scroll(typeof a.dy === "number" ? a.dy : 600);
|
|
1831
|
+
return { ok: true, url: browser.scrub(browser.url) };
|
|
1832
|
+
},
|
|
1833
|
+
browser_screenshot: async (a) => ({
|
|
1834
|
+
image_base64: await browser.screenshotBase64(a.full_page === true),
|
|
1835
|
+
url: browser.scrub(browser.url)
|
|
1836
|
+
}),
|
|
1837
|
+
browser_read: async (a) => observe(str(a.selector, "body")),
|
|
1838
|
+
browser_back: async () => {
|
|
1839
|
+
await browser.back();
|
|
1840
|
+
return observe();
|
|
1841
|
+
}
|
|
1842
|
+
};
|
|
1843
|
+
const specs = COMPUTER_USE_SPECS.map((s) => ({ ...s }));
|
|
1844
|
+
return {
|
|
1845
|
+
schemas: specs.map((spec) => schemaFromSignature(spec)),
|
|
1846
|
+
impls: Object.fromEntries(
|
|
1847
|
+
Object.entries(impls).map(([name, impl]) => [
|
|
1848
|
+
name,
|
|
1849
|
+
scrubbingErrors(browser, impl)
|
|
1850
|
+
])
|
|
1851
|
+
),
|
|
1852
|
+
specs
|
|
1853
|
+
};
|
|
1854
|
+
}
|
|
1855
|
+
var COMPUTER_USE_SPECS, scrubbingErrors, str;
|
|
1856
|
+
var init_browserTools = __esm({
|
|
1857
|
+
"src/worlds/browserTools.ts"() {
|
|
1858
|
+
"use strict";
|
|
1859
|
+
init_pageState();
|
|
1860
|
+
init_session2();
|
|
974
1861
|
COMPUTER_USE_SPECS = [
|
|
975
1862
|
{
|
|
976
1863
|
name: "browser_goto",
|
|
977
1864
|
signature: "browser_goto(path=None)",
|
|
978
1865
|
doc: "Open a page of the world's UI. `path` is a UI path like /customers, a full URL, or omitted for the entry page. Returns the URL and page text."
|
|
979
1866
|
},
|
|
1867
|
+
{
|
|
1868
|
+
name: "browser_snapshot",
|
|
1869
|
+
signature: "browser_snapshot()",
|
|
1870
|
+
doc: "The page as an accessibility tree, one line per element with its role, name and [ref=e3]. To act on an element, pass `ref=e3` as the selector of browser_click or browser_type. Returns {url, title, snapshot, truncated}."
|
|
1871
|
+
},
|
|
980
1872
|
{
|
|
981
1873
|
name: "browser_click",
|
|
982
1874
|
signature: "browser_click(selector)",
|
|
983
|
-
doc: "Click an element by Playwright selector (CSS, `text=Refund`, `role=button[name=Save]`). Returns the page text after the click."
|
|
1875
|
+
doc: "Click an element by `ref=e3` from the last browser_snapshot, or by Playwright selector (CSS, `text=Refund`, `role=button[name=Save]`). Returns the page text after the click."
|
|
984
1876
|
},
|
|
985
1877
|
{
|
|
986
1878
|
name: "browser_type",
|
|
987
1879
|
signature: "browser_type(selector, text)",
|
|
988
|
-
doc: "Replace the value of an input/textarea found by selector with `text`."
|
|
1880
|
+
doc: "Replace the value of an input/textarea, found by `ref=e3` or by selector, with `text`."
|
|
989
1881
|
},
|
|
990
1882
|
{
|
|
991
1883
|
name: "browser_press",
|
|
@@ -1013,6 +1905,14 @@ var init_browser = __esm({
|
|
|
1013
1905
|
doc: "Go back one page in history."
|
|
1014
1906
|
}
|
|
1015
1907
|
];
|
|
1908
|
+
scrubbingErrors = (browser, impl) => async (args) => {
|
|
1909
|
+
try {
|
|
1910
|
+
return await impl(args);
|
|
1911
|
+
} catch (error) {
|
|
1912
|
+
browser.scrubError(error);
|
|
1913
|
+
throw error;
|
|
1914
|
+
}
|
|
1915
|
+
};
|
|
1016
1916
|
str = (v, fallback) => typeof v === "string" && v.length > 0 ? v : fallback;
|
|
1017
1917
|
}
|
|
1018
1918
|
});
|
|
@@ -1157,13 +2057,12 @@ function isNativePage(page) {
|
|
|
1157
2057
|
const mouse = candidate?.mouse;
|
|
1158
2058
|
return typeof candidate?.context === "function" && NATIVE_METHODS.every((m) => typeof mouse?.[m] === "function");
|
|
1159
2059
|
}
|
|
1160
|
-
var FOCUSED_FIELD_JS,
|
|
2060
|
+
var FOCUSED_FIELD_JS, DRAG_STEPS, PNG_SIGNATURE, NATIVE_METHODS, Screen;
|
|
1161
2061
|
var init_screen = __esm({
|
|
1162
2062
|
"src/worlds/nativeComputer/screen.ts"() {
|
|
1163
2063
|
"use strict";
|
|
1164
|
-
|
|
1165
|
-
FOCUSED_FIELD_JS =
|
|
1166
|
-
SECRET_FOCUS = ["password", "frame", "opaque"];
|
|
2064
|
+
init_credentialField();
|
|
2065
|
+
FOCUSED_FIELD_JS = `(() => { let e = document.activeElement; const inner = (el) => (el.shadowRoot && el.shadowRoot.activeElement) || (el.contentDocument && el.contentDocument.activeElement); while (e && inner(e)) e = inner(e); return (${DESCRIBE_FIELD_JS})(e); })()`;
|
|
1167
2066
|
DRAG_STEPS = 5;
|
|
1168
2067
|
PNG_SIGNATURE = Buffer.from([
|
|
1169
2068
|
137,
|
|
@@ -1254,7 +2153,7 @@ var init_screen = __esm({
|
|
|
1254
2153
|
} catch {
|
|
1255
2154
|
return true;
|
|
1256
2155
|
}
|
|
1257
|
-
return
|
|
2156
|
+
return isCredentialField(described);
|
|
1258
2157
|
}
|
|
1259
2158
|
/** CDP renders a clip at the page's device pixel ratio as well as its
|
|
1260
2159
|
* `scale` (a Retina host doubles it), so a capture of the wrong width
|
|
@@ -1485,11 +2384,11 @@ var init_media = __esm({
|
|
|
1485
2384
|
status
|
|
1486
2385
|
);
|
|
1487
2386
|
}
|
|
1488
|
-
async send(method,
|
|
1489
|
-
const reply = await this.transport.send(method,
|
|
2387
|
+
async send(method, route2, body) {
|
|
2388
|
+
const reply = await this.transport.send(method, route2, body);
|
|
1490
2389
|
if (!reply.ok)
|
|
1491
2390
|
throw new MediaUploadError(
|
|
1492
|
-
`${method} ${
|
|
2391
|
+
`${method} ${route2} -> ${reply.status}`,
|
|
1493
2392
|
reply.status
|
|
1494
2393
|
);
|
|
1495
2394
|
return reply.text ? JSON.parse(reply.text) : {};
|
|
@@ -1842,7 +2741,7 @@ function click(button, count) {
|
|
|
1842
2741
|
modifiers: modifierChord(raw.text)
|
|
1843
2742
|
});
|
|
1844
2743
|
}
|
|
1845
|
-
var SCROLL_STEP_PX, NOT_EXECUTED, MAX_ERROR2, SCROLL_DIRECTIONS, MEMBERS, AnthropicComputer, AnthropicComputer20251124;
|
|
2744
|
+
var SCROLL_STEP_PX, NOT_EXECUTED, MAX_ERROR2, SCROLL_DIRECTIONS, IMAGE_PARTS, MEMBERS, AnthropicComputer, AnthropicComputer20251124;
|
|
1846
2745
|
var init_anthropic = __esm({
|
|
1847
2746
|
"src/worlds/nativeComputer/anthropic.ts"() {
|
|
1848
2747
|
"use strict";
|
|
@@ -1858,6 +2757,14 @@ var init_anthropic = __esm({
|
|
|
1858
2757
|
left: [-1, 0],
|
|
1859
2758
|
right: [1, 0]
|
|
1860
2759
|
};
|
|
2760
|
+
IMAGE_PARTS = {
|
|
2761
|
+
6: (data) => ({ type: "image-data", data, mediaType: "image/png" }),
|
|
2762
|
+
7: (data) => ({
|
|
2763
|
+
type: "file",
|
|
2764
|
+
mediaType: "image/png",
|
|
2765
|
+
data: { type: "data", data }
|
|
2766
|
+
})
|
|
2767
|
+
};
|
|
1861
2768
|
MEMBERS = {
|
|
1862
2769
|
screenshot: () => new ComputerAction("screenshot"),
|
|
1863
2770
|
zoom: (raw) => new ComputerAction("zoom", {
|
|
@@ -1967,15 +2874,17 @@ var init_anthropic = __esm({
|
|
|
1967
2874
|
];
|
|
1968
2875
|
return [{ type: "text", text: result.text ?? "OK" }];
|
|
1969
2876
|
}
|
|
1970
|
-
/** For `anthropic.tools.computerToolset_20260801(
|
|
1971
|
-
* (or `computer_20251124` with the legacy kind
|
|
1972
|
-
* and returns `{ type: "image", data }` or
|
|
1973
|
-
* into the tool result
|
|
2877
|
+
/** For `anthropic.tools.computerToolset_20260801(computer.aiSdk({ version: 7 }))`
|
|
2878
|
+
* (AI SDK 7 only), or `computer_20251124` with the legacy kind (AI SDK 6
|
|
2879
|
+
* and 7): `execute` runs one action and returns `{ type: "image", data }` or
|
|
2880
|
+
* text; `toModelOutput` turns that into the tool result in the part shape
|
|
2881
|
+
* of `options.version`. Calls run one at a time, and once a call fails the
|
|
1974
2882
|
* rest of that step's calls answer as not executed. */
|
|
1975
|
-
aiSdk() {
|
|
2883
|
+
aiSdk(options = {}) {
|
|
2884
|
+
const imagePart = _AnthropicComputer.imagePart(options);
|
|
1976
2885
|
let failedStep;
|
|
1977
|
-
const execute = (input,
|
|
1978
|
-
const step =
|
|
2886
|
+
const execute = (input, options2) => this.serial(async () => {
|
|
2887
|
+
const step = options2?.messages?.length;
|
|
1979
2888
|
if (step !== void 0 && step === failedStep)
|
|
1980
2889
|
throw new Error(NOT_EXECUTED);
|
|
1981
2890
|
try {
|
|
@@ -1987,7 +2896,7 @@ var init_anthropic = __esm({
|
|
|
1987
2896
|
});
|
|
1988
2897
|
return {
|
|
1989
2898
|
execute,
|
|
1990
|
-
toModelOutput: ({ output }) => _AnthropicComputer.
|
|
2899
|
+
toModelOutput: ({ output }) => _AnthropicComputer.modelOutput(output, imagePart)
|
|
1991
2900
|
};
|
|
1992
2901
|
}
|
|
1993
2902
|
static aiSdkOutput(result) {
|
|
@@ -1995,16 +2904,26 @@ var init_anthropic = __esm({
|
|
|
1995
2904
|
return { type: "image", data: result.image.toString("base64") };
|
|
1996
2905
|
return result.text ?? "OK";
|
|
1997
2906
|
}
|
|
1998
|
-
/**
|
|
1999
|
-
*
|
|
2000
|
-
|
|
2907
|
+
/** A screenshot as the image part of AI SDK `options.version`:
|
|
2908
|
+
* `image-data` for 6 (the default), `file` with `{ type: "data", data }`
|
|
2909
|
+
* for 7. */
|
|
2910
|
+
static aiSdkModelOutput(output, options = {}) {
|
|
2911
|
+
return _AnthropicComputer.modelOutput(
|
|
2912
|
+
output,
|
|
2913
|
+
_AnthropicComputer.imagePart(options)
|
|
2914
|
+
);
|
|
2915
|
+
}
|
|
2916
|
+
static imagePart({
|
|
2917
|
+
version = 6
|
|
2918
|
+
}) {
|
|
2919
|
+
if (Object.hasOwn(IMAGE_PARTS, version)) return IMAGE_PARTS[version];
|
|
2920
|
+
throw new Error(
|
|
2921
|
+
`unsupported AI SDK version ${version}; choose ${Object.keys(IMAGE_PARTS).join(" or ")}`
|
|
2922
|
+
);
|
|
2923
|
+
}
|
|
2924
|
+
static modelOutput(output, imagePart) {
|
|
2001
2925
|
if (typeof output === "string") return { type: "text", value: output };
|
|
2002
|
-
return {
|
|
2003
|
-
type: "content",
|
|
2004
|
-
value: [
|
|
2005
|
-
{ type: "image-data", data: output.data, mediaType: "image/png" }
|
|
2006
|
-
]
|
|
2007
|
-
};
|
|
2926
|
+
return { type: "content", value: [imagePart(output.data)] };
|
|
2008
2927
|
}
|
|
2009
2928
|
envelope(block, content, isError = false) {
|
|
2010
2929
|
return {
|
|
@@ -2412,7 +3331,7 @@ var init_requestLedger = __esm({
|
|
|
2412
3331
|
"use strict";
|
|
2413
3332
|
init_worlds();
|
|
2414
3333
|
init_sessionContract();
|
|
2415
|
-
WORLD_REQUEST_VIAS = ["api", "ui", "tool"];
|
|
3334
|
+
WORLD_REQUEST_VIAS = ["api", "ui", "tool", "webhook", "page"];
|
|
2416
3335
|
WorldRequestFilterError = class extends Error {
|
|
2417
3336
|
};
|
|
2418
3337
|
NOT_RECORDED = "This session's engine records no requests; only hosted World Host sessions do.";
|
|
@@ -2920,7 +3839,8 @@ async function openSession(slugOrRef, taskOrOpts = {}, positionalOpts = {}) {
|
|
|
2920
3839
|
...opts.reuseWarm === void 0 ? {} : { reuseWarm: opts.reuseWarm },
|
|
2921
3840
|
...opts.surfaces?.length ? { surfaces: opts.surfaces } : {},
|
|
2922
3841
|
...opts.browserTier === void 0 ? {} : { browserTier: opts.browserTier },
|
|
2923
|
-
...opts.auth === void 0 ? {} : { auth: opts.auth }
|
|
3842
|
+
...opts.auth === void 0 ? {} : { auth: opts.auth },
|
|
3843
|
+
...opts.worldState === void 0 ? {} : { worldState: opts.worldState }
|
|
2924
3844
|
}
|
|
2925
3845
|
);
|
|
2926
3846
|
return new WorldSession(state2.sessionId, state2, options);
|
|
@@ -3008,6 +3928,7 @@ var init_session2 = __esm({
|
|
|
3008
3928
|
import_node_crypto2 = require("crypto");
|
|
3009
3929
|
init_worlds();
|
|
3010
3930
|
init_browser();
|
|
3931
|
+
init_browserTools();
|
|
3011
3932
|
init_nativeComputer();
|
|
3012
3933
|
init_sessionContract();
|
|
3013
3934
|
init_toolSchema();
|
|
@@ -3073,6 +3994,9 @@ var init_session2 = __esm({
|
|
|
3073
3994
|
get versionId() {
|
|
3074
3995
|
return this.current.versionId;
|
|
3075
3996
|
}
|
|
3997
|
+
get worldState() {
|
|
3998
|
+
return this.current.worldState ?? null;
|
|
3999
|
+
}
|
|
3076
4000
|
/** Whether the session answered ready as of the last state read (the open,
|
|
3077
4001
|
* a `status()`, or the poll inside `ready()`); no request is made. */
|
|
3078
4002
|
get isReady() {
|
|
@@ -3344,13 +4268,13 @@ var init_session2 = __esm({
|
|
|
3344
4268
|
WorldRequestQuery.parse({ cursor: opts.cursor, limit: opts.limit ?? REQUEST_LOG_PAGE_MAX })
|
|
3345
4269
|
);
|
|
3346
4270
|
}
|
|
3347
|
-
page(
|
|
4271
|
+
page(route2, limit, cursor) {
|
|
3348
4272
|
const query = new URLSearchParams({ limit: String(limit) });
|
|
3349
4273
|
if (cursor) query.set("cursor", cursor);
|
|
3350
4274
|
return apiRequest(
|
|
3351
4275
|
this.options,
|
|
3352
4276
|
"GET",
|
|
3353
|
-
`/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/${
|
|
4277
|
+
`/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/${route2}?${query.toString()}`
|
|
3354
4278
|
);
|
|
3355
4279
|
}
|
|
3356
4280
|
/** The session's call log, oldest first: every tool call, seed, reset,
|
|
@@ -3442,6 +4366,7 @@ var init_session2 = __esm({
|
|
|
3442
4366
|
"surfaces",
|
|
3443
4367
|
"browserTier",
|
|
3444
4368
|
"auth",
|
|
4369
|
+
"worldState",
|
|
3445
4370
|
"options"
|
|
3446
4371
|
]);
|
|
3447
4372
|
isOpenSessionOptions = (value) => typeof value === "object" && value !== null && Object.keys(value).every((key) => OPEN_SESSION_OPTION_KEYS.has(key));
|
|
@@ -3685,7 +4610,8 @@ async function openTask(ref, opts = {}) {
|
|
|
3685
4610
|
task,
|
|
3686
4611
|
...opts.reuseWarm === void 0 ? {} : { reuseWarm: opts.reuseWarm },
|
|
3687
4612
|
...opts.surfaces?.length ? { surfaces: opts.surfaces } : {},
|
|
3688
|
-
...opts.browserTier === void 0 ? {} : { browserTier: opts.browserTier }
|
|
4613
|
+
...opts.browserTier === void 0 ? {} : { browserTier: opts.browserTier },
|
|
4614
|
+
...opts.worldStates === void 0 ? {} : { worldStates: opts.worldStates }
|
|
3689
4615
|
}
|
|
3690
4616
|
);
|
|
3691
4617
|
return fromResponse(answer, options);
|
|
@@ -3943,16 +4869,22 @@ var init_evals = __esm({
|
|
|
3943
4869
|
"src/worlds/evals.ts"() {
|
|
3944
4870
|
"use strict";
|
|
3945
4871
|
init_worlds();
|
|
4872
|
+
init_personalToken();
|
|
4873
|
+
init_platformEndpoint();
|
|
3946
4874
|
init_transport();
|
|
3947
4875
|
EVALUATIONS = "/api/public/benchmark-containers/evaluations";
|
|
3948
|
-
GatewayEvalsClient = class {
|
|
4876
|
+
GatewayEvalsClient = class _GatewayEvalsClient {
|
|
3949
4877
|
constructor(options = {}, retry = RetryPolicy.FILING) {
|
|
3950
4878
|
this.options = options;
|
|
3951
4879
|
this.retry = retry;
|
|
4880
|
+
_GatewayEvalsClient.refuseToken(options);
|
|
3952
4881
|
}
|
|
3953
4882
|
options;
|
|
3954
4883
|
retry;
|
|
3955
4884
|
keyed = /* @__PURE__ */ new Set();
|
|
4885
|
+
static refuseToken(options) {
|
|
4886
|
+
if (platformEndpoint(options)?.token) throw new PersonalTokenRefused(TOKEN_FILING);
|
|
4887
|
+
}
|
|
3956
4888
|
async createEvaluation(versionId, opts = {}) {
|
|
3957
4889
|
const body = { versionId };
|
|
3958
4890
|
if (opts.model !== void 0) body.model = opts.model;
|
|
@@ -5018,7 +5950,7 @@ var require_package = __commonJS({
|
|
|
5018
5950
|
"package.json"(exports2, module2) {
|
|
5019
5951
|
module2.exports = {
|
|
5020
5952
|
name: "@withgateway/sdk",
|
|
5021
|
-
version: "0.
|
|
5953
|
+
version: "0.9.1",
|
|
5022
5954
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
5023
5955
|
main: "./dist/index.js",
|
|
5024
5956
|
module: "./dist/index.mjs",
|
|
@@ -5099,6 +6031,11 @@ var require_package = __commonJS({
|
|
|
5099
6031
|
import: "./dist/hooks/index.mjs",
|
|
5100
6032
|
require: "./dist/hooks/index.js"
|
|
5101
6033
|
},
|
|
6034
|
+
"./agents": {
|
|
6035
|
+
types: "./dist/agents/index.d.ts",
|
|
6036
|
+
import: "./dist/agents/index.mjs",
|
|
6037
|
+
require: "./dist/agents/index.js"
|
|
6038
|
+
},
|
|
5102
6039
|
"./cli": {
|
|
5103
6040
|
types: "./dist/cli.d.ts",
|
|
5104
6041
|
import: "./dist/cli.mjs",
|
|
@@ -5707,6 +6644,7 @@ var init_taskTracing = __esm({
|
|
|
5707
6644
|
"use strict";
|
|
5708
6645
|
init_prerequisites();
|
|
5709
6646
|
init_platformEndpoint();
|
|
6647
|
+
init_personalToken();
|
|
5710
6648
|
HOST_WITH_AUTHORITY = /^[a-z][a-z0-9+.-]*:\/\/[^/\\?#@\s]+(\/|$)/i;
|
|
5711
6649
|
TRACING_HELD_ELSEWHERE = "Tracing in this process already sends spans to another destination or with other keys (an earlier run, or the agent's own tracing.init()), so this run's spans would not reach its own project.";
|
|
5712
6650
|
TaskTracing = class _TaskTracing {
|
|
@@ -5718,8 +6656,9 @@ var init_taskTracing = __esm({
|
|
|
5718
6656
|
static target = null;
|
|
5719
6657
|
async start(requested, options) {
|
|
5720
6658
|
if (!requested) return false;
|
|
5721
|
-
|
|
6659
|
+
let endpoint = null;
|
|
5722
6660
|
try {
|
|
6661
|
+
endpoint = platformEndpoint(options);
|
|
5723
6662
|
await this.initOnce(_TaskTracing.config(endpoint));
|
|
5724
6663
|
return true;
|
|
5725
6664
|
} catch (error) {
|
|
@@ -5741,6 +6680,7 @@ var init_taskTracing = __esm({
|
|
|
5741
6680
|
}
|
|
5742
6681
|
static config(endpoint) {
|
|
5743
6682
|
if (!endpoint) throw new Error(GATEWAY_KEYS_MISSING);
|
|
6683
|
+
if (endpoint.token) throw new Error(TOKEN_KEYS_ONLY);
|
|
5744
6684
|
return { ...endpoint, endpoint: _TaskTracing.destination(endpoint) };
|
|
5745
6685
|
}
|
|
5746
6686
|
// B1: a saved login's keys go to their own host only. The redirect is compared as text, never parsed:
|
|
@@ -5771,7 +6711,9 @@ Pass --no-trace (trace: false) to run untraced without this warning.`
|
|
|
5771
6711
|
static reason(error, endpoint) {
|
|
5772
6712
|
if (OpenTelemetryMissing.explains(error)) return new OpenTelemetryMissing().message;
|
|
5773
6713
|
const message = error instanceof Error ? error.message : String(error);
|
|
5774
|
-
const keys =
|
|
6714
|
+
const keys = [endpoint?.publicKey, endpoint?.secretKey, endpoint?.token?.value].filter(
|
|
6715
|
+
(key) => Boolean(key)
|
|
6716
|
+
);
|
|
5775
6717
|
return keys.reduce((text2, key) => text2.split(key).join("[redacted]"), message);
|
|
5776
6718
|
}
|
|
5777
6719
|
};
|
|
@@ -5816,13 +6758,15 @@ async function refuseUnreadTools(live) {
|
|
|
5816
6758
|
}
|
|
5817
6759
|
}
|
|
5818
6760
|
async function runTask(ref, agent, opts) {
|
|
5819
|
-
const runId = `wtr-${(0, import_node_crypto4.randomBytes)(6).toString("hex")}`;
|
|
5820
6761
|
const options = opts.options ?? {};
|
|
6762
|
+
if (opts.file !== false) GatewayEvalsClient.refuseToken(options);
|
|
6763
|
+
const runId = `wtr-${(0, import_node_crypto4.randomBytes)(6).toString("hex")}`;
|
|
5821
6764
|
const opening = new TaskOpening(
|
|
5822
6765
|
openTask(ref, {
|
|
5823
6766
|
surfaces: opts.surfaces,
|
|
5824
6767
|
reuseWarm: opts.reuseWarm,
|
|
5825
6768
|
browserTier: opts.browserTier,
|
|
6769
|
+
worldStates: opts.worldStates,
|
|
5826
6770
|
options
|
|
5827
6771
|
}).then(async (live) => {
|
|
5828
6772
|
await refuseUnreadTools(live);
|
|
@@ -6104,6 +7048,7 @@ var init_checkoutProvenance = __esm({
|
|
|
6104
7048
|
// src/worlds/setRun.ts
|
|
6105
7049
|
async function runSet(datasetId, agent, opts) {
|
|
6106
7050
|
const options = opts.options ?? {};
|
|
7051
|
+
GatewayEvalsClient.refuseToken(options);
|
|
6107
7052
|
const git = opts.git === void 0 ? CheckoutProvenance.read() : opts.git;
|
|
6108
7053
|
const opened = await apiRequest(options, "POST", SET_RUNS, {
|
|
6109
7054
|
datasetId,
|
|
@@ -6119,6 +7064,7 @@ var init_setRun = __esm({
|
|
|
6119
7064
|
"use strict";
|
|
6120
7065
|
init_worlds();
|
|
6121
7066
|
init_checkoutProvenance();
|
|
7067
|
+
init_evals();
|
|
6122
7068
|
init_runSignals();
|
|
6123
7069
|
init_taskRun();
|
|
6124
7070
|
SET_RUNS = "/api/public/set-runs";
|
|
@@ -6293,6 +7239,112 @@ var init_requestLog = __esm({
|
|
|
6293
7239
|
}
|
|
6294
7240
|
});
|
|
6295
7241
|
|
|
7242
|
+
// src/worlds/webhooks.ts
|
|
7243
|
+
async function listWebhooks(options, sessionId, page = {}) {
|
|
7244
|
+
const query = new URLSearchParams({
|
|
7245
|
+
after: String(page.after ?? 0),
|
|
7246
|
+
limit: String(page.limit ?? WORLD_WEBHOOK_PAGE_MAX),
|
|
7247
|
+
tail: String(page.tail ?? false)
|
|
7248
|
+
});
|
|
7249
|
+
if (page.epoch) query.set("epoch", page.epoch);
|
|
7250
|
+
return apiRequest(options, "GET", `${route(sessionId)}?${query.toString()}`);
|
|
7251
|
+
}
|
|
7252
|
+
var WORLD_WEBHOOK_PAGE_MAX, FORWARD_TIMEOUT_MS, ERROR_CHARS, route, WorldWebhookForwarder;
|
|
7253
|
+
var init_webhooks = __esm({
|
|
7254
|
+
"src/worlds/webhooks.ts"() {
|
|
7255
|
+
"use strict";
|
|
7256
|
+
init_worlds();
|
|
7257
|
+
WORLD_WEBHOOK_PAGE_MAX = 100;
|
|
7258
|
+
FORWARD_TIMEOUT_MS = 1e4;
|
|
7259
|
+
ERROR_CHARS = 500;
|
|
7260
|
+
route = (sessionId) => `/api/public/world-sessions/${encodeURIComponent(sessionId)}/webhooks`;
|
|
7261
|
+
WorldWebhookForwarder = class {
|
|
7262
|
+
constructor(options, sessionId, forwardTo, opts = {}) {
|
|
7263
|
+
this.options = options;
|
|
7264
|
+
this.sessionId = sessionId;
|
|
7265
|
+
this.forwardTo = forwardTo;
|
|
7266
|
+
this.send = opts.fetch ?? fetch;
|
|
7267
|
+
}
|
|
7268
|
+
options;
|
|
7269
|
+
sessionId;
|
|
7270
|
+
forwardTo;
|
|
7271
|
+
after = 0;
|
|
7272
|
+
epoch = null;
|
|
7273
|
+
answers = [];
|
|
7274
|
+
send;
|
|
7275
|
+
get cursor() {
|
|
7276
|
+
return this.after;
|
|
7277
|
+
}
|
|
7278
|
+
/** Where forwarding begins: the deliveries the session still holds (`replay`), or only those it sends from now. */
|
|
7279
|
+
async start(replay) {
|
|
7280
|
+
if (replay) return null;
|
|
7281
|
+
const page = await this.poll([], { tail: true, limit: 1 });
|
|
7282
|
+
this.follow(page);
|
|
7283
|
+
return page;
|
|
7284
|
+
}
|
|
7285
|
+
/** One poll: the answers held so far sent, the next page forwarded. A poll that fails keeps its answers for the next. */
|
|
7286
|
+
async round() {
|
|
7287
|
+
const page = await this.withAnswers((answers) => this.poll(answers));
|
|
7288
|
+
const forwarded = [];
|
|
7289
|
+
for (const delivery of page.deliveries) {
|
|
7290
|
+
const answer = await this.forward(delivery);
|
|
7291
|
+
this.answers.push(answer);
|
|
7292
|
+
forwarded.push({ delivery, answer });
|
|
7293
|
+
}
|
|
7294
|
+
this.follow(page);
|
|
7295
|
+
return { page, forwarded };
|
|
7296
|
+
}
|
|
7297
|
+
/** Sends the answers still held; the cursor stays, so a delivery this poll returns is forwarded by the next round. */
|
|
7298
|
+
async settle() {
|
|
7299
|
+
if (this.answers.length === 0) return 0;
|
|
7300
|
+
const page = await this.withAnswers((answers) => this.poll(answers, { limit: 1 }));
|
|
7301
|
+
return page.answered;
|
|
7302
|
+
}
|
|
7303
|
+
follow(page) {
|
|
7304
|
+
this.after = page.next;
|
|
7305
|
+
this.epoch = page.epoch;
|
|
7306
|
+
}
|
|
7307
|
+
async withAnswers(poll) {
|
|
7308
|
+
const answers = this.answers.splice(0, WORLD_WEBHOOK_PAGE_MAX);
|
|
7309
|
+
try {
|
|
7310
|
+
return await poll(answers);
|
|
7311
|
+
} catch (error) {
|
|
7312
|
+
this.answers.unshift(...answers);
|
|
7313
|
+
throw error;
|
|
7314
|
+
}
|
|
7315
|
+
}
|
|
7316
|
+
poll(answers, opts = {}) {
|
|
7317
|
+
return apiRequest(this.options, "POST", route(this.sessionId), {
|
|
7318
|
+
after: this.after,
|
|
7319
|
+
epoch: this.epoch,
|
|
7320
|
+
tail: opts.tail ?? false,
|
|
7321
|
+
limit: opts.limit ?? WORLD_WEBHOOK_PAGE_MAX,
|
|
7322
|
+
subscriptions: false,
|
|
7323
|
+
answers
|
|
7324
|
+
});
|
|
7325
|
+
}
|
|
7326
|
+
async forward(delivery) {
|
|
7327
|
+
const started = Date.now();
|
|
7328
|
+
try {
|
|
7329
|
+
const reply = await this.send(this.forwardTo, {
|
|
7330
|
+
method: "POST",
|
|
7331
|
+
headers: delivery.headers,
|
|
7332
|
+
body: delivery.payload,
|
|
7333
|
+
redirect: "manual",
|
|
7334
|
+
signal: AbortSignal.timeout(FORWARD_TIMEOUT_MS)
|
|
7335
|
+
});
|
|
7336
|
+
await reply.arrayBuffer().catch(() => void 0);
|
|
7337
|
+
if (reply.status < 100 || reply.status > 599) throw new Error("the receiver answered an invalid HTTP status");
|
|
7338
|
+
return { id: delivery.id, status: reply.status, durationMs: Date.now() - started, error: null };
|
|
7339
|
+
} catch (error) {
|
|
7340
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
7341
|
+
return { id: delivery.id, status: 0, durationMs: Date.now() - started, error: message.slice(0, ERROR_CHARS) };
|
|
7342
|
+
}
|
|
7343
|
+
}
|
|
7344
|
+
};
|
|
7345
|
+
}
|
|
7346
|
+
});
|
|
7347
|
+
|
|
6296
7348
|
// src/worlds/checkoutTarget.ts
|
|
6297
7349
|
var fs2, path3, CheckoutRefusedError, NAMED_EDITS, CheckoutTarget;
|
|
6298
7350
|
var init_checkoutTarget = __esm({
|
|
@@ -6397,7 +7449,7 @@ var init_checkoutTarget = __esm({
|
|
|
6397
7449
|
});
|
|
6398
7450
|
|
|
6399
7451
|
// src/worlds/worldDir.ts
|
|
6400
|
-
var import_node_crypto5, fs3, path4, WORLD_MANIFEST, API_BUNDLE_MANIFEST, BUNDLED_WORLD_PREFIX, CONNECTOR_SPEC, PYPROJECT, BENCHMARK_CONFIG, WORLD_SCHEMA_MARKERS, WORLD_ROOT_MARKERS, BROAD_ROOT_MARKERS, SKIPPED_DIRS, V1_DEP, V1_IMPORT, V1_TASKSET, HARBOR_TASK, skippedDir, byCodePoint, WorldDir;
|
|
7452
|
+
var import_node_crypto5, fs3, path4, WORLD_MANIFEST, API_BUNDLE_MANIFEST, BUNDLE_MANIFEST, BUNDLED_WORLD_PREFIX, CONNECTOR_SPEC, PYPROJECT, BENCHMARK_CONFIG, WORLD_SCHEMA_MARKERS, WORLD_ROOT_MARKERS, BROAD_ROOT_MARKERS, SKIPPED_DIRS, V1_DEP, V1_IMPORT, V1_TASKSET, HARBOR_TASK, skippedDir, byCodePoint, WorldDir;
|
|
6401
7453
|
var init_worldDir = __esm({
|
|
6402
7454
|
"src/worlds/worldDir.ts"() {
|
|
6403
7455
|
"use strict";
|
|
@@ -6406,13 +7458,14 @@ var init_worldDir = __esm({
|
|
|
6406
7458
|
path4 = __toESM(require("path"));
|
|
6407
7459
|
WORLD_MANIFEST = "gateway-env.toml";
|
|
6408
7460
|
API_BUNDLE_MANIFEST = "gateway-api-world.toml";
|
|
7461
|
+
BUNDLE_MANIFEST = "gateway-bundle.toml";
|
|
6409
7462
|
BUNDLED_WORLD_PREFIX = "server/world/";
|
|
6410
7463
|
CONNECTOR_SPEC = "connector.toml";
|
|
6411
7464
|
PYPROJECT = "pyproject.toml";
|
|
6412
7465
|
BENCHMARK_CONFIG = "benchmark.json";
|
|
6413
7466
|
WORLD_SCHEMA_MARKERS = ["schema/world.json", "schema/runtime.json", "schema/lock.json"];
|
|
6414
7467
|
WORLD_ROOT_MARKERS = [CONNECTOR_SPEC, ...WORLD_SCHEMA_MARKERS];
|
|
6415
|
-
BROAD_ROOT_MARKERS = [WORLD_MANIFEST, API_BUNDLE_MANIFEST, BENCHMARK_CONFIG];
|
|
7468
|
+
BROAD_ROOT_MARKERS = [WORLD_MANIFEST, API_BUNDLE_MANIFEST, BENCHMARK_CONFIG, BUNDLE_MANIFEST];
|
|
6416
7469
|
SKIPPED_DIRS = /* @__PURE__ */ new Set(["dist", "build", "outputs", "__pycache__", "node_modules"]);
|
|
6417
7470
|
V1_DEP = /["']verifiers\s*(?:\[[^\]]*\])?\s*(?:>=|~=|==|>)\s*(?:0\.(?:[2-9]\d*|[1-9]\d+)|[1-9]\d*)/;
|
|
6418
7471
|
V1_IMPORT = /^\s*(?:from\s+verifiers\.v1\s+import\b|from\s+verifiers\s+import\s+v1\b|import\s+verifiers\.v1\b)/m;
|
|
@@ -6433,7 +7486,6 @@ var init_worldDir = __esm({
|
|
|
6433
7486
|
const bundled = present(API_BUNDLE_MANIFEST) && WORLD_ROOT_MARKERS.some((m) => present(BUNDLED_WORLD_PREFIX + m));
|
|
6434
7487
|
return new _WorldDir(dir, bundled ? BUNDLED_WORLD_PREFIX : "");
|
|
6435
7488
|
}
|
|
6436
|
-
// ── Files ──────────────────────────────────────────────────────────────
|
|
6437
7489
|
has(rel) {
|
|
6438
7490
|
return fs3.existsSync(path4.join(this.dir, rel));
|
|
6439
7491
|
}
|
|
@@ -6444,15 +7496,9 @@ var init_worldDir = __esm({
|
|
|
6444
7496
|
return null;
|
|
6445
7497
|
}
|
|
6446
7498
|
}
|
|
6447
|
-
/** A path under the authored world's root. */
|
|
6448
7499
|
worldPath(rel) {
|
|
6449
7500
|
return this.worldRoot + rel;
|
|
6450
7501
|
}
|
|
6451
|
-
/** Every regular file the archive rules keep (`_archive.py`: no hidden,
|
|
6452
|
-
* dist, build, outputs, pycache, node_modules or egg-info directories), as
|
|
6453
|
-
* sorted relpaths. Root files enter only when a Gateway manifest or
|
|
6454
|
-
* benchmark.json widens the root, or they are README.md, pyproject.toml or
|
|
6455
|
-
* Python. */
|
|
6456
7502
|
get archivePaths() {
|
|
6457
7503
|
if (this.pathsMemo) return this.pathsMemo;
|
|
6458
7504
|
const broad = BROAD_ROOT_MARKERS.some((m) => this.has(m));
|
|
@@ -6471,11 +7517,6 @@ var init_worldDir = __esm({
|
|
|
6471
7517
|
walk("");
|
|
6472
7518
|
return this.pathsMemo = out.sort(byCodePoint);
|
|
6473
7519
|
}
|
|
6474
|
-
/** What the archive rules leave out, collapsed to the entry that decided
|
|
6475
|
-
* it: a pruned directory counts its files once, a dropped root file is
|
|
6476
|
-
* named. Dot entries (`.git/`, `.gateway/`, `.gitignore`) are the one
|
|
6477
|
-
* universal convention and stay unreported. `push` prints the rest so
|
|
6478
|
-
* nothing disappears silently. */
|
|
6479
7520
|
get exclusions() {
|
|
6480
7521
|
const kept = new Set(this.archivePaths);
|
|
6481
7522
|
const out = [];
|
|
@@ -6498,14 +7539,11 @@ var init_worldDir = __esm({
|
|
|
6498
7539
|
}
|
|
6499
7540
|
return out;
|
|
6500
7541
|
}
|
|
6501
|
-
/**
|
|
6502
|
-
* collecting, this package does not reimplement gitignore. */
|
|
7542
|
+
/** The Python SDK honours a root `.gitignore` when collecting; this package does not reimplement gitignore. */
|
|
6503
7543
|
get hasRootGitignore() {
|
|
6504
7544
|
return this.has(".gitignore");
|
|
6505
7545
|
}
|
|
6506
|
-
/**
|
|
6507
|
-
* sorted order: the version's identity, byte-compatible with
|
|
6508
|
-
* `_archive.compute_content_hash` and Prime Intellect. */
|
|
7546
|
+
/** The version's identity, byte-compatible with the Python SDK's `compute_content_hash` and Prime Intellect's hub. */
|
|
6509
7547
|
get contentHash() {
|
|
6510
7548
|
const hasher = (0, import_node_crypto5.createHash)("sha256");
|
|
6511
7549
|
for (const rel of this.archivePaths) {
|
|
@@ -6514,18 +7552,18 @@ var init_worldDir = __esm({
|
|
|
6514
7552
|
}
|
|
6515
7553
|
return hasher.digest("hex");
|
|
6516
7554
|
}
|
|
6517
|
-
// ── Markers ────────────────────────────────────────────────────────────
|
|
6518
7555
|
get isApiBundle() {
|
|
6519
7556
|
return this.has(API_BUNDLE_MANIFEST);
|
|
6520
7557
|
}
|
|
7558
|
+
get isWorldBundle() {
|
|
7559
|
+
return this.has(BUNDLE_MANIFEST);
|
|
7560
|
+
}
|
|
6521
7561
|
get hasManifest() {
|
|
6522
7562
|
return this.has(this.worldPath(WORLD_MANIFEST));
|
|
6523
7563
|
}
|
|
6524
7564
|
get hasSchemaMarker() {
|
|
6525
7565
|
return WORLD_SCHEMA_MARKERS.some((m) => this.has(this.worldPath(m)));
|
|
6526
7566
|
}
|
|
6527
|
-
/** Harbor task dirs, relative to the tree: `tasks/<name>` when a `tasks/`
|
|
6528
|
-
* dir holds them, else the root `<name>` dirs. */
|
|
6529
7567
|
taskDirs() {
|
|
6530
7568
|
const names = /* @__PURE__ */ new Set();
|
|
6531
7569
|
for (const rel of this.archivePaths) {
|
|
@@ -6535,8 +7573,6 @@ var init_worldDir = __esm({
|
|
|
6535
7573
|
const under = [...names].filter((n) => n.startsWith("tasks/"));
|
|
6536
7574
|
return (under.length ? under : [...names]).sort();
|
|
6537
7575
|
}
|
|
6538
|
-
/** The Python package of a verifiers tree (`<pkg>/__init__.py` or
|
|
6539
|
-
* `src/<pkg>/__init__.py`), or null. */
|
|
6540
7576
|
pythonPackage() {
|
|
6541
7577
|
if (!this.has(PYPROJECT)) return null;
|
|
6542
7578
|
for (const base of ["", "src/"]) {
|
|
@@ -6548,8 +7584,6 @@ var init_worldDir = __esm({
|
|
|
6548
7584
|
}
|
|
6549
7585
|
return null;
|
|
6550
7586
|
}
|
|
6551
|
-
/** The package targets the `verifiers.v1` API: read from the root
|
|
6552
|
-
* pyproject and every archived Python module. */
|
|
6553
7587
|
get isVerifiersV1() {
|
|
6554
7588
|
for (const rel of this.archivePaths) {
|
|
6555
7589
|
if (rel !== PYPROJECT && !rel.endsWith(".py")) continue;
|
|
@@ -6560,11 +7594,9 @@ var init_worldDir = __esm({
|
|
|
6560
7594
|
}
|
|
6561
7595
|
return false;
|
|
6562
7596
|
}
|
|
6563
|
-
// ── The answer ─────────────────────────────────────────────────────────
|
|
6564
|
-
/** The runner's kind (`detect_env_kind`): api / mock-tools win over
|
|
6565
|
-
* everything, a harbor task tree next, then the verifiers API version. */
|
|
6566
7597
|
get kind() {
|
|
6567
7598
|
if (this.isApiBundle) return "api";
|
|
7599
|
+
if (this.isWorldBundle) return "bundle";
|
|
6568
7600
|
if (this.has(WORLD_MANIFEST)) return "mock-tools";
|
|
6569
7601
|
if (this.taskDirs().length) return "harbor";
|
|
6570
7602
|
return this.isVerifiersV1 ? "verifiers-v1" : "verifiers";
|
|
@@ -6902,8 +7934,7 @@ async function push(dir, opts = {}) {
|
|
|
6902
7934
|
const metadata = {
|
|
6903
7935
|
...opts.name !== void 0 ? { name: opts.name } : {},
|
|
6904
7936
|
...opts.description !== void 0 ? { description: opts.description } : {},
|
|
6905
|
-
...opts.tags !== void 0 ? { tags: opts.tags } : {}
|
|
6906
|
-
...opts.visibility ? { visibility: opts.visibility } : {}
|
|
7937
|
+
...opts.tags !== void 0 ? { tags: opts.tags } : {}
|
|
6907
7938
|
};
|
|
6908
7939
|
const resolve7 = await apiRequest(
|
|
6909
7940
|
options,
|
|
@@ -7435,7 +8466,7 @@ var init_sandbox = __esm({
|
|
|
7435
8466
|
/**
|
|
7436
8467
|
* `{ slug, ref? }` opens a READY version; `{ new, from }` opens a sandbox on
|
|
7437
8468
|
* a world that does not exist yet (409 `world_exists` if the slug is taken,
|
|
7438
|
-
* 400 naming the
|
|
8469
|
+
* 400 naming the official templates if `from` is unknown). Its first commit
|
|
7439
8470
|
* creates the world on `main`.
|
|
7440
8471
|
*/
|
|
7441
8472
|
open(target) {
|
|
@@ -8080,6 +9111,7 @@ var CliError;
|
|
|
8080
9111
|
var init_router = __esm({
|
|
8081
9112
|
"src/cli/router.ts"() {
|
|
8082
9113
|
"use strict";
|
|
9114
|
+
init_personalToken();
|
|
8083
9115
|
CliError = class extends Error {
|
|
8084
9116
|
constructor(message, exitCode = 2) {
|
|
8085
9117
|
super(message);
|
|
@@ -8091,12 +9123,52 @@ var init_router = __esm({
|
|
|
8091
9123
|
});
|
|
8092
9124
|
|
|
8093
9125
|
// src/cli/config.ts
|
|
8094
|
-
|
|
8095
|
-
|
|
8096
|
-
|
|
9126
|
+
function configPath() {
|
|
9127
|
+
return path7.join(process.env.GATEWAY_CONFIG_DIR || path7.join(os.homedir(), ".gateway"), "config.json");
|
|
9128
|
+
}
|
|
9129
|
+
function readConfig() {
|
|
9130
|
+
let stored;
|
|
9131
|
+
try {
|
|
9132
|
+
stored = JSON.parse(fs6.readFileSync(configPath(), "utf8"));
|
|
9133
|
+
} catch {
|
|
9134
|
+
return {};
|
|
9135
|
+
}
|
|
9136
|
+
const record = stored ?? {};
|
|
9137
|
+
return Object.fromEntries(STORED_FIELDS.filter((f) => typeof record[f] === "string").map((f) => [f, record[f]]));
|
|
9138
|
+
}
|
|
9139
|
+
function personalToken(request = {}) {
|
|
9140
|
+
try {
|
|
9141
|
+
return PersonalToken.fromEnv(process.env, request);
|
|
9142
|
+
} catch (error) {
|
|
9143
|
+
if (error instanceof PersonalTokenRefused) throw new CliError(error.message);
|
|
9144
|
+
throw error;
|
|
9145
|
+
}
|
|
9146
|
+
}
|
|
9147
|
+
function resolveCredentials(hostFlag, secretKeyFlag) {
|
|
9148
|
+
const token = personalToken({ host: hostFlag || void 0, keys: Boolean(secretKeyFlag) });
|
|
9149
|
+
if (token) return { host: token.host, publicKey: "", secretKey: "", token };
|
|
9150
|
+
const stored = readConfig();
|
|
9151
|
+
const explicitHost = (hostFlag || process.env.GATEWAY_HOST || "").replace(/\/+$/, "");
|
|
9152
|
+
const host = explicitHost || (stored.host ?? "").replace(/\/+$/, "");
|
|
9153
|
+
if (!host)
|
|
9154
|
+
throw new CredentialsMissing(
|
|
9155
|
+
"Host not configured. Pass --host, set GATEWAY_HOST, or run `gateway auth login`."
|
|
9156
|
+
);
|
|
9157
|
+
const login = host === (stored.host ?? "").replace(/\/+$/, "") ? stored : {};
|
|
9158
|
+
const publicKey = process.env.GATEWAY_PUBLIC_KEY || login.public_key || "";
|
|
9159
|
+
const secretKey = secretKeyFlag || process.env.GATEWAY_SECRET_KEY || process.env.GATEWAY_API_KEY || login.api_key || "";
|
|
9160
|
+
if (!publicKey || !secretKey)
|
|
9161
|
+
throw new CredentialsMissing(
|
|
9162
|
+
"API key not configured. Set GATEWAY_PUBLIC_KEY and GATEWAY_SECRET_KEY, or run `gateway auth login`."
|
|
9163
|
+
);
|
|
9164
|
+
return { host, publicKey, secretKey };
|
|
9165
|
+
}
|
|
9166
|
+
async function api(creds, method, route2, body, init2 = {}) {
|
|
9167
|
+
const reply = await new PlatformTransport(creds).send(method, route2, body, init2);
|
|
9168
|
+
if (!reply.ok) throw new ApiError2(reply.status, method, route2, reply.text);
|
|
8097
9169
|
return reply.text ? JSON.parse(reply.text) : {};
|
|
8098
9170
|
}
|
|
8099
|
-
var fs6, os, path7, ApiError2;
|
|
9171
|
+
var fs6, os, path7, STORED_FIELDS, CredentialsMissing, ApiError2;
|
|
8100
9172
|
var init_config = __esm({
|
|
8101
9173
|
"src/cli/config.ts"() {
|
|
8102
9174
|
"use strict";
|
|
@@ -8105,14 +9177,18 @@ var init_config = __esm({
|
|
|
8105
9177
|
path7 = __toESM(require("path"));
|
|
8106
9178
|
init_router();
|
|
8107
9179
|
init_worlds();
|
|
9180
|
+
init_personalToken();
|
|
8108
9181
|
init_transport();
|
|
9182
|
+
STORED_FIELDS = ["host", "public_key", "api_key"];
|
|
9183
|
+
CredentialsMissing = class extends CliError {
|
|
9184
|
+
};
|
|
8109
9185
|
ApiError2 = class extends CliError {
|
|
8110
|
-
constructor(status, method,
|
|
9186
|
+
constructor(status, method, route2, text2) {
|
|
8111
9187
|
const body = parseErrorBody(text2, status);
|
|
8112
|
-
super(`${method} ${
|
|
9188
|
+
super(`${method} ${route2} -> ${status}: ${body.detail}`, 1);
|
|
8113
9189
|
this.status = status;
|
|
8114
9190
|
this.method = method;
|
|
8115
|
-
this.route =
|
|
9191
|
+
this.route = route2;
|
|
8116
9192
|
this.text = text2;
|
|
8117
9193
|
this.code = body.code;
|
|
8118
9194
|
}
|
|
@@ -8125,7 +9201,37 @@ var init_config = __esm({
|
|
|
8125
9201
|
}
|
|
8126
9202
|
});
|
|
8127
9203
|
|
|
9204
|
+
// src/worlds/isolatedPython.ts
|
|
9205
|
+
function isolatedPython(python, args, timeout) {
|
|
9206
|
+
return (0, import_node_child_process2.spawnSync)(python, ["-I", ...args], { encoding: "utf8", timeout, env: PersonalToken.scrubbed(process.env) });
|
|
9207
|
+
}
|
|
9208
|
+
var import_node_child_process2;
|
|
9209
|
+
var init_isolatedPython = __esm({
|
|
9210
|
+
"src/worlds/isolatedPython.ts"() {
|
|
9211
|
+
"use strict";
|
|
9212
|
+
import_node_child_process2 = require("child_process");
|
|
9213
|
+
init_personalToken();
|
|
9214
|
+
}
|
|
9215
|
+
});
|
|
9216
|
+
|
|
8128
9217
|
// src/cli/runtime/local.ts
|
|
9218
|
+
var local_exports = {};
|
|
9219
|
+
__export(local_exports, {
|
|
9220
|
+
MIN_PYTHON_LABEL: () => MIN_PYTHON_LABEL,
|
|
9221
|
+
assertPortFree: () => assertPortFree,
|
|
9222
|
+
credentialsForRuntime: () => credentialsForRuntime,
|
|
9223
|
+
findPython: () => findPython,
|
|
9224
|
+
localBridge: () => localBridge,
|
|
9225
|
+
localModule: () => localModule,
|
|
9226
|
+
localPythonHasYaml: () => localPythonHasYaml,
|
|
9227
|
+
localRuntime: () => localRuntime,
|
|
9228
|
+
localRuntimeReason: () => localRuntimeReason,
|
|
9229
|
+
portOwner: () => portOwner,
|
|
9230
|
+
pythonAdvice: () => pythonAdvice,
|
|
9231
|
+
resetPythonCache: () => resetPythonCache,
|
|
9232
|
+
runtimeMode: () => runtimeMode,
|
|
9233
|
+
runtimeRoot: () => runtimeRoot
|
|
9234
|
+
});
|
|
8129
9235
|
function forwardedEnv() {
|
|
8130
9236
|
return Object.fromEntries(
|
|
8131
9237
|
FORWARDED_ENV.flatMap((name) => {
|
|
@@ -8162,12 +9268,12 @@ function runtimeRoot() {
|
|
|
8162
9268
|
return root;
|
|
8163
9269
|
return null;
|
|
8164
9270
|
}
|
|
9271
|
+
function resetPythonCache() {
|
|
9272
|
+
pythonCache = void 0;
|
|
9273
|
+
pythonProbes = [];
|
|
9274
|
+
}
|
|
8165
9275
|
function probeVersion(name) {
|
|
8166
|
-
const probe = (
|
|
8167
|
-
name,
|
|
8168
|
-
["-c", "import sys;print(sys.version_info[0],sys.version_info[1])"],
|
|
8169
|
-
{ encoding: "utf8", timeout: 1e4 }
|
|
8170
|
-
);
|
|
9276
|
+
const probe = isolatedPython(name, ["-c", "import sys;print(sys.version_info[0],sys.version_info[1])"], 1e4);
|
|
8171
9277
|
if (probe.status !== 0) return null;
|
|
8172
9278
|
const [major, minor] = probe.stdout.trim().split(/\s+/).map(Number);
|
|
8173
9279
|
return Number.isInteger(major) && Number.isInteger(minor) ? `${major}.${minor}` : null;
|
|
@@ -8177,7 +9283,7 @@ function atLeastMinimum(version) {
|
|
|
8177
9283
|
return major > MIN_PYTHON[0] || major === MIN_PYTHON[0] && minor >= MIN_PYTHON[1];
|
|
8178
9284
|
}
|
|
8179
9285
|
function uvPython() {
|
|
8180
|
-
const found = (0,
|
|
9286
|
+
const found = (0, import_node_child_process3.spawnSync)("uv", UV_FIND, { encoding: "utf8", timeout: 1e4, env: PersonalToken.scrubbed(process.env) });
|
|
8181
9287
|
if (found.status !== 0) return null;
|
|
8182
9288
|
const line = found.stdout.trim().split(/\r?\n/)[0] ?? "";
|
|
8183
9289
|
return line || null;
|
|
@@ -8236,12 +9342,12 @@ function localRuntime() {
|
|
|
8236
9342
|
return { python, root };
|
|
8237
9343
|
}
|
|
8238
9344
|
function localPythonHasYaml(python) {
|
|
8239
|
-
return (
|
|
9345
|
+
return isolatedPython(python, ["-c", "import yaml"], 1e4).status === 0;
|
|
8240
9346
|
}
|
|
8241
9347
|
async function localBridge(request, local, opts = {}) {
|
|
8242
9348
|
const input = JSON.stringify(request);
|
|
8243
9349
|
return await new Promise((resolve7, reject) => {
|
|
8244
|
-
const child = (0,
|
|
9350
|
+
const child = (0, import_node_child_process3.spawn)(
|
|
8245
9351
|
local.python,
|
|
8246
9352
|
["-I", "-B", "-c", BRIDGE_BOOTSTRAP, local.root],
|
|
8247
9353
|
{
|
|
@@ -8297,16 +9403,92 @@ async function localBridge(request, local, opts = {}) {
|
|
|
8297
9403
|
child.stdin.end(input);
|
|
8298
9404
|
});
|
|
8299
9405
|
}
|
|
8300
|
-
|
|
9406
|
+
function portOwner(port) {
|
|
9407
|
+
const found = (0, import_node_child_process3.spawnSync)("lsof", ["-nP", `-iTCP:${port}`, "-sTCP:LISTEN", "-Fpc"], {
|
|
9408
|
+
encoding: "utf8",
|
|
9409
|
+
timeout: 5e3
|
|
9410
|
+
});
|
|
9411
|
+
if (found.error || found.status !== 0) return null;
|
|
9412
|
+
let pid = null;
|
|
9413
|
+
let command2 = null;
|
|
9414
|
+
for (const line of found.stdout.split("\n")) {
|
|
9415
|
+
if (line.startsWith("p") && pid === null) pid = line.slice(1);
|
|
9416
|
+
else if (line.startsWith("c") && pid !== null && command2 === null) command2 = line.slice(1);
|
|
9417
|
+
}
|
|
9418
|
+
if (pid === null) return null;
|
|
9419
|
+
return `pid ${pid}${command2 ? ` (${command2})` : ""}`;
|
|
9420
|
+
}
|
|
9421
|
+
async function assertPortFree(port, host = "127.0.0.1") {
|
|
9422
|
+
const taken = await new Promise((resolve7) => {
|
|
9423
|
+
const probe = net.createServer();
|
|
9424
|
+
probe.once("error", () => resolve7(true));
|
|
9425
|
+
probe.listen(port, host, () => probe.close(() => resolve7(false)));
|
|
9426
|
+
});
|
|
9427
|
+
if (!taken) return;
|
|
9428
|
+
const owner = portOwner(port);
|
|
9429
|
+
throw new CliError(
|
|
9430
|
+
`port ${port} on ${host} is already in use${owner ? ` by ${owner}` : ""}; nothing was served there \u2014 pass another --port, or stop that server first`,
|
|
9431
|
+
1
|
|
9432
|
+
);
|
|
9433
|
+
}
|
|
9434
|
+
async function localModule(argv, local, opts = {}) {
|
|
9435
|
+
return await new Promise((resolve7, reject) => {
|
|
9436
|
+
const child = (0, import_node_child_process3.spawn)(
|
|
9437
|
+
local.python,
|
|
9438
|
+
["-B", "-c", MODULE_BOOTSTRAP, local.root, ...argv],
|
|
9439
|
+
{
|
|
9440
|
+
stdio: "inherit",
|
|
9441
|
+
cwd: opts.cwd,
|
|
9442
|
+
env: { ...PersonalToken.scrubbed(process.env), ...opts.env }
|
|
9443
|
+
}
|
|
9444
|
+
);
|
|
9445
|
+
const forward = (signal) => () => {
|
|
9446
|
+
if (child.exitCode === null && child.signalCode === null) child.kill(signal);
|
|
9447
|
+
};
|
|
9448
|
+
const handlers = [
|
|
9449
|
+
["SIGINT", forward("SIGINT")],
|
|
9450
|
+
["SIGTERM", forward("SIGTERM")],
|
|
9451
|
+
["SIGHUP", forward("SIGHUP")]
|
|
9452
|
+
];
|
|
9453
|
+
for (const [signal, handler] of handlers) process.on(signal, handler);
|
|
9454
|
+
const release = () => {
|
|
9455
|
+
for (const [signal, handler] of handlers) process.off(signal, handler);
|
|
9456
|
+
};
|
|
9457
|
+
child.on("error", (error) => {
|
|
9458
|
+
release();
|
|
9459
|
+
reject(
|
|
9460
|
+
new CliError(
|
|
9461
|
+
`local runtime could not start (${local.python}): ${error.message}`,
|
|
9462
|
+
1
|
|
9463
|
+
)
|
|
9464
|
+
);
|
|
9465
|
+
});
|
|
9466
|
+
child.on("close", (code, signal) => {
|
|
9467
|
+
release();
|
|
9468
|
+
resolve7(code ?? (signal ? 130 : 1));
|
|
9469
|
+
});
|
|
9470
|
+
});
|
|
9471
|
+
}
|
|
9472
|
+
function credentialsForRuntime(hostFlag) {
|
|
9473
|
+
try {
|
|
9474
|
+
return resolveCredentials(hostFlag);
|
|
9475
|
+
} catch (error) {
|
|
9476
|
+
if (error instanceof CliError && localRuntime()) return null;
|
|
9477
|
+
throw error;
|
|
9478
|
+
}
|
|
9479
|
+
}
|
|
9480
|
+
var import_node_child_process3, fs7, net, path8, MIN_PYTHON, MIN_PYTHON_LABEL, DIAGNOSTIC_TAIL, FORWARDED_ENV, BRIDGE_BOOTSTRAP, MODULE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
|
|
8301
9481
|
var init_local = __esm({
|
|
8302
9482
|
"src/cli/runtime/local.ts"() {
|
|
8303
9483
|
"use strict";
|
|
8304
|
-
|
|
9484
|
+
import_node_child_process3 = require("child_process");
|
|
8305
9485
|
fs7 = __toESM(require("fs"));
|
|
8306
9486
|
net = __toESM(require("net"));
|
|
8307
9487
|
path8 = __toESM(require("path"));
|
|
8308
9488
|
init_router();
|
|
8309
9489
|
init_config();
|
|
9490
|
+
init_isolatedPython();
|
|
9491
|
+
init_personalToken();
|
|
8310
9492
|
MIN_PYTHON = [3, 12];
|
|
8311
9493
|
MIN_PYTHON_LABEL = MIN_PYTHON.join(".");
|
|
8312
9494
|
DIAGNOSTIC_TAIL = 600;
|
|
@@ -8317,6 +9499,13 @@ package=types.ModuleType('gatewaysdk')
|
|
|
8317
9499
|
package.__path__=[os.path.join(root,'gatewaysdk')]
|
|
8318
9500
|
sys.modules['gatewaysdk']=package
|
|
8319
9501
|
runpy.run_module('gatewaysdk.environment.schema.platform',run_name='__main__')`;
|
|
9502
|
+
MODULE_BOOTSTRAP = `import sys,runpy,types,os
|
|
9503
|
+
root=sys.argv[1]
|
|
9504
|
+
package=types.ModuleType('gatewaysdk')
|
|
9505
|
+
package.__path__=[os.path.join(root,'gatewaysdk')]
|
|
9506
|
+
sys.modules['gatewaysdk']=package
|
|
9507
|
+
sys.argv=['gateway worlds']+sys.argv[2:]
|
|
9508
|
+
runpy.run_module('gatewaysdk.environment.schema',run_name='__main__')`;
|
|
8320
9509
|
pythonProbes = [];
|
|
8321
9510
|
PYTHON_CANDIDATES = [
|
|
8322
9511
|
"python3.13",
|
|
@@ -8463,8 +9652,8 @@ async function runtime(creds, request, opts = {}) {
|
|
|
8463
9652
|
throw new CliError(
|
|
8464
9653
|
"This needs the schema runtime (the CLI bundles it) or platform credentials (`gateway auth login`). " + localRuntimeReason()
|
|
8465
9654
|
);
|
|
8466
|
-
const
|
|
8467
|
-
const res = await new PlatformTransport(creds).send("POST",
|
|
9655
|
+
const route2 = "/api/public/worlds/runtime";
|
|
9656
|
+
const res = await new PlatformTransport(creds).send("POST", route2, request, {
|
|
8468
9657
|
timeoutMs: opts.timeoutMs ?? RUNTIME_TIMEOUT_MS
|
|
8469
9658
|
});
|
|
8470
9659
|
let payload = null;
|
|
@@ -8476,8 +9665,8 @@ async function runtime(creds, request, opts = {}) {
|
|
|
8476
9665
|
const detail = detailFrom(payload);
|
|
8477
9666
|
if (detail) throw new BridgeRejected(detail);
|
|
8478
9667
|
if (!res.ok)
|
|
8479
|
-
throw new CliError(`POST ${
|
|
8480
|
-
if (payload === null) throw new CliError(`POST ${
|
|
9668
|
+
throw new CliError(`POST ${route2} (${request.command}) -> ${res.status}: ${res.text.slice(0, 600)}`, 1);
|
|
9669
|
+
if (payload === null) throw new CliError(`POST ${route2} (${request.command}) returned non-JSON`, 1);
|
|
8481
9670
|
return payload;
|
|
8482
9671
|
}
|
|
8483
9672
|
var fs8, path9, MAX_WORLD_FILES, RUNTIME_TIMEOUT_MS, SKIP_DIRS, BridgeRejected, YAML_NAME, YAML_NEEDS_PYYAML, YAML_NOT_ON_PLATFORM, RuntimeRoute;
|
|
@@ -8812,7 +10001,7 @@ async function runTransform(script, records, opts = {}) {
|
|
|
8812
10001
|
const { file, args } = command(resolved, scratch);
|
|
8813
10002
|
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !SCRUBBED.test(key)));
|
|
8814
10003
|
const done = await new Promise((resolve7, reject) => {
|
|
8815
|
-
const child = (0,
|
|
10004
|
+
const child = (0, import_node_child_process4.spawn)(file, args, { cwd: path11.dirname(resolved), env, stdio: ["pipe", "pipe", "pipe"] });
|
|
8816
10005
|
let stdout = "";
|
|
8817
10006
|
let stderr = "";
|
|
8818
10007
|
let timedOut = false;
|
|
@@ -8850,11 +10039,11 @@ async function transformRecords(transform, records, opts = {}) {
|
|
|
8850
10039
|
if (typeof transform === "function") return { rows: checkRows(await transform(records), "transform(records)"), stderr: "" };
|
|
8851
10040
|
return runTransform(transform, records, opts);
|
|
8852
10041
|
}
|
|
8853
|
-
var
|
|
10042
|
+
var import_node_child_process4, fs10, os2, path11, import_node_module, import_meta, DEFAULT_TRANSFORM_TIMEOUT_MS, NODE_SUFFIXES, PYTHON_SUFFIXES, SCRUBBED, PY_WRAPPER, NODE_WRAPPER, isObject, tail;
|
|
8854
10043
|
var init_transform = __esm({
|
|
8855
10044
|
"src/cli/platform/worldData/transform.ts"() {
|
|
8856
10045
|
"use strict";
|
|
8857
|
-
|
|
10046
|
+
import_node_child_process4 = require("child_process");
|
|
8858
10047
|
fs10 = __toESM(require("fs"));
|
|
8859
10048
|
os2 = __toESM(require("os"));
|
|
8860
10049
|
path11 = __toESM(require("path"));
|
|
@@ -9425,14 +10614,23 @@ function toolCallsFromObservations(observations, opts = {}) {
|
|
|
9425
10614
|
}
|
|
9426
10615
|
return out;
|
|
9427
10616
|
}
|
|
10617
|
+
async function runtimeEndpoint(options) {
|
|
10618
|
+
try {
|
|
10619
|
+
return platformEndpoint(options);
|
|
10620
|
+
} catch (error) {
|
|
10621
|
+
const { localRuntime: localRuntime2 } = await Promise.resolve().then(() => (init_local(), local_exports));
|
|
10622
|
+
if (error instanceof PersonalTokenRefused && localRuntime2()) return null;
|
|
10623
|
+
throw error;
|
|
10624
|
+
}
|
|
10625
|
+
}
|
|
9428
10626
|
async function ingest(world, records, options = {}) {
|
|
9429
10627
|
const { ingestLocalToolCalls: ingestLocalToolCalls2, importLocalWorldData: importLocalWorldData2, checkLocalWorldData: checkLocalWorldData2 } = await Promise.resolve().then(() => (init_data(), data_exports));
|
|
9430
10628
|
if (options.transform !== void 0 && options.map !== void 0) throw new Error("records go through one of transform, map");
|
|
9431
10629
|
const redact = options.redact ?? "off";
|
|
9432
10630
|
const mode = options.mode ?? "append";
|
|
9433
10631
|
const dryRun = Boolean(options.dryRun);
|
|
9434
|
-
const creds = platformEndpoint(options);
|
|
9435
10632
|
const local = fs12.existsSync(world) && fs12.statSync(world).isDirectory();
|
|
10633
|
+
const creds = local ? await runtimeEndpoint(options) : platformEndpoint(options);
|
|
9436
10634
|
const map = options.map === void 0 ? void 0 : options.map;
|
|
9437
10635
|
let rows = null;
|
|
9438
10636
|
let stderr = "";
|
|
@@ -9533,6 +10731,7 @@ var init_ingest = __esm({
|
|
|
9533
10731
|
path12 = __toESM(require("path"));
|
|
9534
10732
|
init_worlds();
|
|
9535
10733
|
init_platformEndpoint();
|
|
10734
|
+
init_personalToken();
|
|
9536
10735
|
isObject2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9537
10736
|
isoOf = (value) => value instanceof Date ? value.toISOString() : typeof value === "string" ? value : void 0;
|
|
9538
10737
|
}
|
|
@@ -9590,6 +10789,38 @@ var init_editSessions = __esm({
|
|
|
9590
10789
|
}
|
|
9591
10790
|
});
|
|
9592
10791
|
|
|
10792
|
+
// src/worlds/states.ts
|
|
10793
|
+
var WORLDS3, refQuery, WorldStateClient;
|
|
10794
|
+
var init_states = __esm({
|
|
10795
|
+
"src/worlds/states.ts"() {
|
|
10796
|
+
"use strict";
|
|
10797
|
+
init_worlds();
|
|
10798
|
+
WORLDS3 = "/api/public/worlds";
|
|
10799
|
+
refQuery = (ref) => ref ? `?${new URLSearchParams({ ref })}` : "";
|
|
10800
|
+
WorldStateClient = class {
|
|
10801
|
+
constructor(options = {}) {
|
|
10802
|
+
this.options = options;
|
|
10803
|
+
}
|
|
10804
|
+
options;
|
|
10805
|
+
list(slug) {
|
|
10806
|
+
return apiRequest(this.options, "GET", `${WORLDS3}/${encodeURIComponent(slug)}/states`);
|
|
10807
|
+
}
|
|
10808
|
+
show(slug, name, ref) {
|
|
10809
|
+
return apiRequest(this.options, "GET", `${WORLDS3}/${encodeURIComponent(slug)}/states/${encodeURIComponent(name)}` + refQuery(ref));
|
|
10810
|
+
}
|
|
10811
|
+
create(slug, input) {
|
|
10812
|
+
return apiRequest(this.options, "POST", `${WORLDS3}/${encodeURIComponent(slug)}/states`, input);
|
|
10813
|
+
}
|
|
10814
|
+
delete(slug, name) {
|
|
10815
|
+
return apiRequest(this.options, "DELETE", `${WORLDS3}/${encodeURIComponent(slug)}/states/${encodeURIComponent(name)}`);
|
|
10816
|
+
}
|
|
10817
|
+
pull(slug, name, ref) {
|
|
10818
|
+
return apiRequest(this.options, "GET", `${WORLDS3}/${encodeURIComponent(slug)}/states/${encodeURIComponent(name)}/pull` + refQuery(ref));
|
|
10819
|
+
}
|
|
10820
|
+
};
|
|
10821
|
+
}
|
|
10822
|
+
});
|
|
10823
|
+
|
|
9593
10824
|
// src/worlds/dryRun.ts
|
|
9594
10825
|
var DRY_RUN_KIND, DRY_RUN_AGENT, STATUS_WAIT_CAP_SECONDS, cid, HostedDryRunClient, DryRunOutcome;
|
|
9595
10826
|
var init_dryRun = __esm({
|
|
@@ -9723,9 +10954,14 @@ __export(worlds_exports, {
|
|
|
9723
10954
|
OpenAIComputer: () => OpenAIComputer,
|
|
9724
10955
|
OpenAIPreviewComputer: () => OpenAIPreviewComputer,
|
|
9725
10956
|
PLATFORM_SESSION_HEADER: () => PLATFORM_SESSION_HEADER,
|
|
10957
|
+
PLATFORM_STREAM_IDLE_MS: () => PLATFORM_STREAM_IDLE_MS,
|
|
9726
10958
|
PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
9727
10959
|
PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
|
|
10960
|
+
PageObserver: () => PageObserver,
|
|
10961
|
+
PageState: () => PageState,
|
|
10962
|
+
PageStateError: () => PageStateError,
|
|
9728
10963
|
PendingSafetyChecks: () => PendingSafetyChecks,
|
|
10964
|
+
PlatformStream: () => PlatformStream,
|
|
9729
10965
|
PlatformTransport: () => PlatformTransport,
|
|
9730
10966
|
PushSlugConflict: () => PushSlugConflict,
|
|
9731
10967
|
RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
|
|
@@ -9762,6 +10998,7 @@ __export(worlds_exports, {
|
|
|
9762
10998
|
VERIFIER_REWARD_PREFIX: () => VERIFIER_REWARD_PREFIX,
|
|
9763
10999
|
WHITESPACE: () => WHITESPACE,
|
|
9764
11000
|
WORLD_REQUEST_VIAS: () => WORLD_REQUEST_VIAS,
|
|
11001
|
+
WORLD_WEBHOOK_PAGE_MAX: () => WORLD_WEBHOOK_PAGE_MAX,
|
|
9765
11002
|
WorldBrowser: () => WorldBrowser,
|
|
9766
11003
|
WorldCallTooLarge: () => WorldCallTooLarge,
|
|
9767
11004
|
WorldEditClient: () => WorldEditClient,
|
|
@@ -9777,9 +11014,11 @@ __export(worlds_exports, {
|
|
|
9777
11014
|
WorldSessionOpenFailed: () => WorldSessionOpenFailed,
|
|
9778
11015
|
WorldSessionTimeout: () => WorldSessionTimeout,
|
|
9779
11016
|
WorldSet: () => WorldSet,
|
|
11017
|
+
WorldStateClient: () => WorldStateClient,
|
|
9780
11018
|
WorldSurfaceUnavailable: () => WorldSurfaceUnavailable,
|
|
9781
11019
|
WorldTask: () => WorldTask,
|
|
9782
11020
|
WorldToolsUnread: () => WorldToolsUnread,
|
|
11021
|
+
WorldWebhookForwarder: () => WorldWebhookForwarder,
|
|
9783
11022
|
WriteTreeFilter: () => WriteTreeFilter,
|
|
9784
11023
|
aggregateTaskGrade: () => aggregateTaskGrade,
|
|
9785
11024
|
apiRequest: () => apiRequest,
|
|
@@ -9827,6 +11066,7 @@ __export(worlds_exports, {
|
|
|
9827
11066
|
listSessions: () => listSessions,
|
|
9828
11067
|
listTaskSessions: () => listTaskSessions,
|
|
9829
11068
|
listTasks: () => listTasks,
|
|
11069
|
+
listWebhooks: () => listWebhooks,
|
|
9830
11070
|
localTreeState: () => localTreeState,
|
|
9831
11071
|
messageOf: () => messageOf,
|
|
9832
11072
|
migrateProjectWorlds: () => migrateProjectWorlds,
|
|
@@ -9842,6 +11082,7 @@ __export(worlds_exports, {
|
|
|
9842
11082
|
parseToolCallRecord: () => parseToolCallRecord,
|
|
9843
11083
|
parseTransform: () => parseTransform,
|
|
9844
11084
|
parseWorldTaskRefs: () => parseWorldTaskRefs,
|
|
11085
|
+
platformAuthorization: () => platformAuthorization,
|
|
9845
11086
|
platformTimeoutMs: () => platformTimeoutMs,
|
|
9846
11087
|
playwrightKey: () => playwrightKey,
|
|
9847
11088
|
preserveForm: () => preserveForm,
|
|
@@ -9868,6 +11109,7 @@ __export(worlds_exports, {
|
|
|
9868
11109
|
runSet: () => runSet,
|
|
9869
11110
|
runTask: () => runTask,
|
|
9870
11111
|
schemaFromSignature: () => schemaFromSignature,
|
|
11112
|
+
scrubError: () => scrubError,
|
|
9871
11113
|
serializeCallBody: () => serializeCallBody,
|
|
9872
11114
|
sessionToolObservations: () => sessionToolObservations,
|
|
9873
11115
|
setEnvSecret: () => setEnvSecret,
|
|
@@ -9896,43 +11138,8 @@ __export(worlds_exports, {
|
|
|
9896
11138
|
writeLocalMeta: () => writeLocalMeta
|
|
9897
11139
|
});
|
|
9898
11140
|
module.exports = __toCommonJS(worlds_exports);
|
|
9899
|
-
function edgeAnswer(text2, status) {
|
|
9900
|
-
if (status !== void 0 && status >= 500) return EDGE_ANSWERS[status] ?? EDGE_FAILURE;
|
|
9901
|
-
return /^\s*</.test(text2) ? EDGE_PAGE : null;
|
|
9902
|
-
}
|
|
9903
|
-
function parseErrorBody(text2, status) {
|
|
9904
|
-
const raw = { detail: text2.slice(0, DETAIL_LIMIT), code: null };
|
|
9905
|
-
let parsed;
|
|
9906
|
-
try {
|
|
9907
|
-
parsed = JSON.parse(text2);
|
|
9908
|
-
} catch {
|
|
9909
|
-
return { detail: (edgeAnswer(text2, status) ?? text2).slice(0, DETAIL_LIMIT), code: null };
|
|
9910
|
-
}
|
|
9911
|
-
if (parsed === null || typeof parsed !== "object") return raw;
|
|
9912
|
-
const { message, code, error } = parsed;
|
|
9913
|
-
const stableCode = typeof code === "string" ? code : null;
|
|
9914
|
-
if (typeof message !== "string") return { ...raw, code: stableCode };
|
|
9915
|
-
const fields = invalidFields(error);
|
|
9916
|
-
const said = fields ? `${message}: ${fields}` : message;
|
|
9917
|
-
if (stableCode === null) return { detail: said.slice(0, DETAIL_LIMIT), code: null };
|
|
9918
|
-
return {
|
|
9919
|
-
detail: `${said} (${stableCode})`.slice(0, DETAIL_LIMIT),
|
|
9920
|
-
code: stableCode
|
|
9921
|
-
};
|
|
9922
|
-
}
|
|
9923
|
-
function invalidFields(error) {
|
|
9924
|
-
const issues = Array.isArray(error) ? error : [];
|
|
9925
|
-
return issues.filter(
|
|
9926
|
-
(issue) => issue !== null && typeof issue === "object" && typeof issue.message === "string"
|
|
9927
|
-
).map((issue) => {
|
|
9928
|
-
const path13 = Array.isArray(issue.path) ? issue.path.map(String).join(".") : "";
|
|
9929
|
-
return path13 ? `${path13}: ${issue.message}` : issue.message;
|
|
9930
|
-
}).join("; ");
|
|
9931
|
-
}
|
|
9932
11141
|
async function apiRequest(options, method, path13, body, init2 = {}) {
|
|
9933
|
-
|
|
9934
|
-
if (!reply.ok) throw new ApiError(reply.status, method, path13, reply.text);
|
|
9935
|
-
return JSON.parse(reply.text);
|
|
11142
|
+
return new PlatformTransport(requirePlatformEndpoint(options)).json(method, path13, body, init2);
|
|
9936
11143
|
}
|
|
9937
11144
|
async function setEnvSecret(slug, key, value, options = {}) {
|
|
9938
11145
|
return apiRequest(
|
|
@@ -10107,11 +11314,12 @@ async function resolveWorld(slugRef, slug, ref, pin, options) {
|
|
|
10107
11314
|
}
|
|
10108
11315
|
return world;
|
|
10109
11316
|
}
|
|
10110
|
-
var
|
|
11317
|
+
var WorldTask, WorldSet;
|
|
10111
11318
|
var init_worlds = __esm({
|
|
10112
11319
|
"src/worlds/index.ts"() {
|
|
10113
11320
|
init_platformEndpoint();
|
|
10114
11321
|
init_transport();
|
|
11322
|
+
init_apiError();
|
|
10115
11323
|
init_transport();
|
|
10116
11324
|
init_session2();
|
|
10117
11325
|
init_grade();
|
|
@@ -10126,9 +11334,12 @@ var init_worlds = __esm({
|
|
|
10126
11334
|
init_checkoutProvenance();
|
|
10127
11335
|
init_evals();
|
|
10128
11336
|
init_browser();
|
|
11337
|
+
init_browserTools();
|
|
11338
|
+
init_pageState();
|
|
10129
11339
|
init_surfaceDescriptor();
|
|
10130
11340
|
init_requestLog();
|
|
10131
11341
|
init_requestLedger();
|
|
11342
|
+
init_webhooks();
|
|
10132
11343
|
init_browserReconnect();
|
|
10133
11344
|
init_nativeComputer();
|
|
10134
11345
|
init_hub();
|
|
@@ -10141,29 +11352,9 @@ var init_worlds = __esm({
|
|
|
10141
11352
|
init_ingest();
|
|
10142
11353
|
init_sandbox();
|
|
10143
11354
|
init_editSessions();
|
|
11355
|
+
init_states();
|
|
10144
11356
|
init_dryRun();
|
|
10145
11357
|
init_worldNotice();
|
|
10146
|
-
ApiError = class extends Error {
|
|
10147
|
-
constructor(status, method, path13, text2) {
|
|
10148
|
-
const parsed = parseErrorBody(text2, status);
|
|
10149
|
-
super(`${method} ${path13} -> ${status}: ${parsed.detail}`);
|
|
10150
|
-
this.status = status;
|
|
10151
|
-
this.text = text2;
|
|
10152
|
-
this.name = "ApiError";
|
|
10153
|
-
this.code = parsed.code;
|
|
10154
|
-
}
|
|
10155
|
-
status;
|
|
10156
|
-
text;
|
|
10157
|
-
code;
|
|
10158
|
-
};
|
|
10159
|
-
DETAIL_LIMIT = 600;
|
|
10160
|
-
EDGE_ANSWERS = {
|
|
10161
|
-
502: "Bad Gateway from the load balancer in front of the platform, not the platform's answer: the web server dropped the connection or restarted mid-request. Retry; if it repeats, the platform is restarting or overloaded.",
|
|
10162
|
-
503: "Service Unavailable from the load balancer in front of the platform, not the platform's answer: no web server was ready to take the request (a deploy or a restart). Retry in a minute.",
|
|
10163
|
-
504: "Gateway Time-out from the load balancer in front of the platform, not the platform's answer: the request sent nothing back within the load balancer's idle timeout (60 s unless the deployment raises it: Helm ingress.idleTimeoutSeconds) and was cut there, though the platform may still be running it. Check what it changed before you retry."
|
|
10164
|
-
};
|
|
10165
|
-
EDGE_FAILURE = "The platform failed without its JSON error body: a proxy in front of it answered, or the server stopped before its error handler ran. Retry; if it repeats, report the request and the time.";
|
|
10166
|
-
EDGE_PAGE = "An HTML page answered instead of the platform's JSON: a proxy in front of the platform, or the configured host is not the platform.";
|
|
10167
11358
|
WorldTask = class {
|
|
10168
11359
|
constructor(world, name, variant) {
|
|
10169
11360
|
this.world = world;
|
|
@@ -10273,9 +11464,14 @@ init_worlds();
|
|
|
10273
11464
|
OpenAIComputer,
|
|
10274
11465
|
OpenAIPreviewComputer,
|
|
10275
11466
|
PLATFORM_SESSION_HEADER,
|
|
11467
|
+
PLATFORM_STREAM_IDLE_MS,
|
|
10276
11468
|
PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
10277
11469
|
PLATFORM_TIMEOUT_ENV,
|
|
11470
|
+
PageObserver,
|
|
11471
|
+
PageState,
|
|
11472
|
+
PageStateError,
|
|
10278
11473
|
PendingSafetyChecks,
|
|
11474
|
+
PlatformStream,
|
|
10279
11475
|
PlatformTransport,
|
|
10280
11476
|
PushSlugConflict,
|
|
10281
11477
|
RECOVER_BUDGET_MS,
|
|
@@ -10312,6 +11508,7 @@ init_worlds();
|
|
|
10312
11508
|
VERIFIER_REWARD_PREFIX,
|
|
10313
11509
|
WHITESPACE,
|
|
10314
11510
|
WORLD_REQUEST_VIAS,
|
|
11511
|
+
WORLD_WEBHOOK_PAGE_MAX,
|
|
10315
11512
|
WorldBrowser,
|
|
10316
11513
|
WorldCallTooLarge,
|
|
10317
11514
|
WorldEditClient,
|
|
@@ -10327,9 +11524,11 @@ init_worlds();
|
|
|
10327
11524
|
WorldSessionOpenFailed,
|
|
10328
11525
|
WorldSessionTimeout,
|
|
10329
11526
|
WorldSet,
|
|
11527
|
+
WorldStateClient,
|
|
10330
11528
|
WorldSurfaceUnavailable,
|
|
10331
11529
|
WorldTask,
|
|
10332
11530
|
WorldToolsUnread,
|
|
11531
|
+
WorldWebhookForwarder,
|
|
10333
11532
|
WriteTreeFilter,
|
|
10334
11533
|
aggregateTaskGrade,
|
|
10335
11534
|
apiRequest,
|
|
@@ -10377,6 +11576,7 @@ init_worlds();
|
|
|
10377
11576
|
listSessions,
|
|
10378
11577
|
listTaskSessions,
|
|
10379
11578
|
listTasks,
|
|
11579
|
+
listWebhooks,
|
|
10380
11580
|
localTreeState,
|
|
10381
11581
|
messageOf,
|
|
10382
11582
|
migrateProjectWorlds,
|
|
@@ -10392,6 +11592,7 @@ init_worlds();
|
|
|
10392
11592
|
parseToolCallRecord,
|
|
10393
11593
|
parseTransform,
|
|
10394
11594
|
parseWorldTaskRefs,
|
|
11595
|
+
platformAuthorization,
|
|
10395
11596
|
platformTimeoutMs,
|
|
10396
11597
|
playwrightKey,
|
|
10397
11598
|
preserveForm,
|
|
@@ -10418,6 +11619,7 @@ init_worlds();
|
|
|
10418
11619
|
runSet,
|
|
10419
11620
|
runTask,
|
|
10420
11621
|
schemaFromSignature,
|
|
11622
|
+
scrubError,
|
|
10421
11623
|
serializeCallBody,
|
|
10422
11624
|
sessionToolObservations,
|
|
10423
11625
|
setEnvSecret,
|