@withgateway/sdk 0.2.9 → 0.3.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/README.md +5 -1
- package/dist/cli.js +3812 -1158
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +3796 -1142
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.d.mts +1 -0
- package/dist/files/index.d.ts +1 -0
- package/dist/files/index.js +1358 -21
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +1356 -13
- package/dist/files/index.mjs.map +1 -1
- package/dist/{index-BO2SNSgy.d.ts → index-CBqbB_0J.d.ts} +95 -46
- package/dist/{index-Cz8Q6Keo.d.mts → index-D-AMnAMa.d.mts} +95 -46
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1942 -177
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1890 -146
- package/dist/index.mjs.map +1 -1
- package/dist/media-CbcAfQvd.d.mts +83 -0
- package/dist/media-CbcAfQvd.d.ts +83 -0
- package/dist/traces/index.d.mts +1 -0
- package/dist/traces/index.d.ts +1 -0
- package/dist/traces/index.js +1355 -18
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +1353 -10
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.d.mts +2 -1
- package/dist/tracing/index.d.ts +2 -1
- package/dist/tracing/index.js +550 -30
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +539 -29
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/worlds/index.d.mts +648 -80
- package/dist/worlds/index.d.ts +648 -80
- package/dist/worlds/index.js +1875 -145
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +1861 -131
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +1 -1
- package/runtime/gatewaysdk/environment/schema/api.py +43 -62
- package/runtime/gatewaysdk/environment/schema/cast.py +31 -4
- package/runtime/gatewaysdk/environment/schema/grading.py +1 -5
- package/runtime/gatewaysdk/environment/schema/host.py +53 -90
- package/runtime/gatewaysdk/environment/schema/local.py +15 -7
- package/runtime/gatewaysdk/environment/schema/platform.py +1 -7
- package/runtime/gatewaysdk/environment/schema/runtime.py +9 -9
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +3 -3
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +2 -2
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +13 -13
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +2 -1
- package/runtime/gatewaysdk/environment/schema/tasks.py +25 -1
- package/skills/connector-schema-authoring/SKILL.md +3 -3
- package/skills/connector-schema-authoring/connector-worlds.md +12 -5
- package/skills/connector-schema-authoring/world-schema.md +8 -0
- package/skills/world-data-ingestion/SKILL.md +2 -2
- package/skills/worlds-getting-started/SKILL.md +13 -13
- package/skills/worlds-getting-started/references/cli-mcp-map.md +2 -1
package/dist/worlds/index.js
CHANGED
|
@@ -334,7 +334,7 @@ function withoutUiToken(url) {
|
|
|
334
334
|
const [beforeHash, hash] = splitHash(url);
|
|
335
335
|
const q = beforeHash.indexOf("?");
|
|
336
336
|
if (q < 0) return url;
|
|
337
|
-
const kept = beforeHash.slice(q + 1).split("&").filter((
|
|
337
|
+
const kept = beforeHash.slice(q + 1).split("&").filter((pair2) => pair2 !== "" && pair2.split("=")[0] !== UI_TOKEN_QUERY);
|
|
338
338
|
return beforeHash.slice(0, q) + (kept.length ? `?${kept.join("&")}` : "") + hash;
|
|
339
339
|
}
|
|
340
340
|
function splitHash(url) {
|
|
@@ -469,7 +469,7 @@ var SURFACE_KINDS, BROWSER_TIERS, DEFAULT_VIEWPORT, SETTLE_TIMEOUT_MS, SETTLE_QU
|
|
|
469
469
|
var init_browser = __esm({
|
|
470
470
|
"src/worlds/browser.ts"() {
|
|
471
471
|
"use strict";
|
|
472
|
-
|
|
472
|
+
init_session2();
|
|
473
473
|
init_browserReconnect();
|
|
474
474
|
SURFACE_KINDS = ["tools", "api", "ui", "browser"];
|
|
475
475
|
BROWSER_TIERS = ["standard", "premium"];
|
|
@@ -615,6 +615,10 @@ var init_browser = __esm({
|
|
|
615
615
|
get agentId() {
|
|
616
616
|
return this.recorder?.agentId ?? null;
|
|
617
617
|
}
|
|
618
|
+
/** `text` with this session's credentials (UI token, browser address) removed. */
|
|
619
|
+
scrub(text2) {
|
|
620
|
+
return this.scrubber.scrub(text2);
|
|
621
|
+
}
|
|
618
622
|
watchNetwork(page) {
|
|
619
623
|
page.on("request", () => {
|
|
620
624
|
this.inflight += 1;
|
|
@@ -896,8 +900,1271 @@ var init_browser = __esm({
|
|
|
896
900
|
signature: "browser_back()",
|
|
897
901
|
doc: "Go back one page in history."
|
|
898
902
|
}
|
|
899
|
-
];
|
|
900
|
-
str = (v, fallback) => typeof v === "string" && v.length > 0 ? v : fallback;
|
|
903
|
+
];
|
|
904
|
+
str = (v, fallback) => typeof v === "string" && v.length > 0 ? v : fallback;
|
|
905
|
+
}
|
|
906
|
+
});
|
|
907
|
+
|
|
908
|
+
// src/worlds/nativeComputer/actions.ts
|
|
909
|
+
function toNumber(value) {
|
|
910
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
911
|
+
throw new Error(`not a number: ${JSON.stringify(value) ?? String(value)}`);
|
|
912
|
+
return value;
|
|
913
|
+
}
|
|
914
|
+
function toInt(value) {
|
|
915
|
+
return Math.trunc(toNumber(value));
|
|
916
|
+
}
|
|
917
|
+
var ACTION_NAMES, SECRET_TEXT, BOUNDS, ComputerAction;
|
|
918
|
+
var init_actions = __esm({
|
|
919
|
+
"src/worlds/nativeComputer/actions.ts"() {
|
|
920
|
+
"use strict";
|
|
921
|
+
ACTION_NAMES = [
|
|
922
|
+
"screenshot",
|
|
923
|
+
"zoom",
|
|
924
|
+
"click",
|
|
925
|
+
"move",
|
|
926
|
+
"mouse_down",
|
|
927
|
+
"mouse_up",
|
|
928
|
+
"drag",
|
|
929
|
+
"scroll",
|
|
930
|
+
"type",
|
|
931
|
+
"key",
|
|
932
|
+
"hold_key",
|
|
933
|
+
"wait",
|
|
934
|
+
"cursor_position",
|
|
935
|
+
"history"
|
|
936
|
+
];
|
|
937
|
+
SECRET_TEXT = "[redacted]";
|
|
938
|
+
BOUNDS = {
|
|
939
|
+
seconds: [0, 300],
|
|
940
|
+
repeat: [1, 100],
|
|
941
|
+
count: [1, 3],
|
|
942
|
+
dx: [-1e4, 1e4],
|
|
943
|
+
dy: [-1e4, 1e4]
|
|
944
|
+
};
|
|
945
|
+
ComputerAction = class {
|
|
946
|
+
constructor(name, args = {}) {
|
|
947
|
+
this.name = name;
|
|
948
|
+
this.args = args;
|
|
949
|
+
if (!ACTION_NAMES.includes(name))
|
|
950
|
+
throw new Error(`unknown computer action: ${name}`);
|
|
951
|
+
for (const [key, [low, high]] of Object.entries(BOUNDS)) {
|
|
952
|
+
const value = args[key];
|
|
953
|
+
if (value !== void 0 && !(Number(value) >= low && Number(value) <= high))
|
|
954
|
+
throw new Error(
|
|
955
|
+
`${name} ${key} must be between ${low} and ${high}, got ${String(value)}`
|
|
956
|
+
);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
name;
|
|
960
|
+
args;
|
|
961
|
+
/** Flat arguments for the browser timeline and the trace: lists become
|
|
962
|
+
* `"x,y"` strings, and typed text is withheld when it went into a
|
|
963
|
+
* credential field. */
|
|
964
|
+
recordArgs(secretText) {
|
|
965
|
+
const out = {};
|
|
966
|
+
for (const [key, value] of Object.entries(this.args))
|
|
967
|
+
out[key] = Array.isArray(value) ? value.flat().join(",") : value;
|
|
968
|
+
if (secretText && "text" in out) out.text = SECRET_TEXT;
|
|
969
|
+
return out;
|
|
970
|
+
}
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
});
|
|
974
|
+
|
|
975
|
+
// src/worlds/nativeComputer/display.ts
|
|
976
|
+
var FIT_STEP, Display;
|
|
977
|
+
var init_display = __esm({
|
|
978
|
+
"src/worlds/nativeComputer/display.ts"() {
|
|
979
|
+
"use strict";
|
|
980
|
+
FIT_STEP = 0.98;
|
|
981
|
+
Display = class _Display {
|
|
982
|
+
constructor(width, height, viewportWidth, viewportHeight) {
|
|
983
|
+
this.width = width;
|
|
984
|
+
this.height = height;
|
|
985
|
+
this.viewportWidth = viewportWidth;
|
|
986
|
+
this.viewportHeight = viewportHeight;
|
|
987
|
+
}
|
|
988
|
+
width;
|
|
989
|
+
height;
|
|
990
|
+
viewportWidth;
|
|
991
|
+
viewportHeight;
|
|
992
|
+
/** `size` when the caller names one; otherwise the largest downscale of the
|
|
993
|
+
* viewport (at most 1:1) that `fits` the provider's limits. */
|
|
994
|
+
static forViewport(viewport, size, fits = () => true) {
|
|
995
|
+
const { width, height } = viewport;
|
|
996
|
+
if (size) return _Display.sized(size[0], size[1], width, height);
|
|
997
|
+
let scale = 1;
|
|
998
|
+
while (!fits(Math.round(width * scale), Math.round(height * scale)))
|
|
999
|
+
scale *= FIT_STEP;
|
|
1000
|
+
return new _Display(
|
|
1001
|
+
Math.round(width * scale),
|
|
1002
|
+
Math.round(height * scale),
|
|
1003
|
+
width,
|
|
1004
|
+
height
|
|
1005
|
+
);
|
|
1006
|
+
}
|
|
1007
|
+
/** A caller's display keeps the viewport's shape: screenshots are scaled
|
|
1008
|
+
* uniformly, so another aspect ratio would map clicks off the image. */
|
|
1009
|
+
static sized(width, height, viewportWidth, viewportHeight) {
|
|
1010
|
+
if (width <= 0 || height <= 0)
|
|
1011
|
+
throw new Error(`display ${width}x${height} must be positive`);
|
|
1012
|
+
const sameShape = width * viewportHeight / viewportWidth;
|
|
1013
|
+
if (Math.abs(sameShape - height) > 1)
|
|
1014
|
+
throw new Error(
|
|
1015
|
+
`display ${width}x${height} must keep the viewport's aspect ratio (${viewportWidth}x${viewportHeight}); try ${width}x${Math.round(sameShape)}`
|
|
1016
|
+
);
|
|
1017
|
+
return new _Display(width, height, viewportWidth, viewportHeight);
|
|
1018
|
+
}
|
|
1019
|
+
get scaled() {
|
|
1020
|
+
return this.width !== this.viewportWidth || this.height !== this.viewportHeight;
|
|
1021
|
+
}
|
|
1022
|
+
get scale() {
|
|
1023
|
+
return Math.min(
|
|
1024
|
+
this.width / this.viewportWidth,
|
|
1025
|
+
this.height / this.viewportHeight
|
|
1026
|
+
);
|
|
1027
|
+
}
|
|
1028
|
+
toPage(x, y) {
|
|
1029
|
+
return [
|
|
1030
|
+
x * this.viewportWidth / this.width,
|
|
1031
|
+
y * this.viewportHeight / this.height
|
|
1032
|
+
];
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
});
|
|
1037
|
+
|
|
1038
|
+
// src/worlds/nativeComputer/screen.ts
|
|
1039
|
+
function pngWidth(png) {
|
|
1040
|
+
if (png.length < 24 || !png.subarray(0, 8).equals(PNG_SIGNATURE)) return null;
|
|
1041
|
+
return png.readUInt32BE(16);
|
|
1042
|
+
}
|
|
1043
|
+
function isNativePage(page) {
|
|
1044
|
+
const candidate = page;
|
|
1045
|
+
const mouse = candidate?.mouse;
|
|
1046
|
+
return typeof candidate?.context === "function" && NATIVE_METHODS.every((m) => typeof mouse?.[m] === "function");
|
|
1047
|
+
}
|
|
1048
|
+
var FOCUSED_FIELD_JS, SECRET_FOCUS, DRAG_STEPS, PNG_SIGNATURE, NATIVE_METHODS, Screen;
|
|
1049
|
+
var init_screen = __esm({
|
|
1050
|
+
"src/worlds/nativeComputer/screen.ts"() {
|
|
1051
|
+
"use strict";
|
|
1052
|
+
init_browser();
|
|
1053
|
+
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); if (!e) return ''; if (e.tagName === 'IFRAME' || e.tagName === 'FRAME') return 'frame'; if (!(e.tagName === 'INPUT' || e.tagName === 'TEXTAREA' || e.isContentEditable)) return 'opaque'; return [e.type, e.name, e.id, e.getAttribute('autocomplete')].filter(Boolean).join(' '); })()";
|
|
1054
|
+
SECRET_FOCUS = ["password", "frame", "opaque"];
|
|
1055
|
+
DRAG_STEPS = 5;
|
|
1056
|
+
PNG_SIGNATURE = Buffer.from([
|
|
1057
|
+
137,
|
|
1058
|
+
80,
|
|
1059
|
+
78,
|
|
1060
|
+
71,
|
|
1061
|
+
13,
|
|
1062
|
+
10,
|
|
1063
|
+
26,
|
|
1064
|
+
10
|
|
1065
|
+
]);
|
|
1066
|
+
NATIVE_METHODS = ["move", "click", "down", "up", "wheel"];
|
|
1067
|
+
Screen = class {
|
|
1068
|
+
constructor(browser, display) {
|
|
1069
|
+
this.browser = browser;
|
|
1070
|
+
this.display = display;
|
|
1071
|
+
}
|
|
1072
|
+
browser;
|
|
1073
|
+
display;
|
|
1074
|
+
cursor = [0, 0];
|
|
1075
|
+
pixelRatio = 1;
|
|
1076
|
+
handlers = {
|
|
1077
|
+
screenshot: async () => ({ image: await this.screenshot() }),
|
|
1078
|
+
zoom: (a) => this.zoom(a),
|
|
1079
|
+
click: (a) => this.click(a),
|
|
1080
|
+
move: (a) => this.held(a.args.modifiers ?? [], () => this.moveTo(this.point(a))),
|
|
1081
|
+
mouse_down: async (a) => {
|
|
1082
|
+
await this.page.mouse.down({ button: a.args.button ?? "left" });
|
|
1083
|
+
return {};
|
|
1084
|
+
},
|
|
1085
|
+
mouse_up: async (a) => {
|
|
1086
|
+
await this.page.mouse.up({ button: a.args.button ?? "left" });
|
|
1087
|
+
return {};
|
|
1088
|
+
},
|
|
1089
|
+
drag: (a) => this.drag(a),
|
|
1090
|
+
scroll: (a) => this.scroll(a),
|
|
1091
|
+
type: async (a) => {
|
|
1092
|
+
await this.page.keyboard.type(a.args.text ?? "");
|
|
1093
|
+
return {};
|
|
1094
|
+
},
|
|
1095
|
+
key: (a) => this.key(a),
|
|
1096
|
+
hold_key: (a) => this.held(
|
|
1097
|
+
a.args.keys ?? [],
|
|
1098
|
+
() => this.page.waitForTimeout((a.args.seconds ?? 0) * 1e3)
|
|
1099
|
+
),
|
|
1100
|
+
wait: async (a) => {
|
|
1101
|
+
await this.page.waitForTimeout((a.args.seconds ?? 0) * 1e3);
|
|
1102
|
+
return {};
|
|
1103
|
+
},
|
|
1104
|
+
cursor_position: async () => ({
|
|
1105
|
+
text: `X=${this.cursor[0]}, Y=${this.cursor[1]}`
|
|
1106
|
+
}),
|
|
1107
|
+
history: async (a) => {
|
|
1108
|
+
const navigate = {
|
|
1109
|
+
back: () => this.page.goBack(),
|
|
1110
|
+
forward: () => this.page.goForward()
|
|
1111
|
+
};
|
|
1112
|
+
await navigate[a.args.direction ?? "back"]();
|
|
1113
|
+
return {};
|
|
1114
|
+
}
|
|
1115
|
+
};
|
|
1116
|
+
/** The live page (a new object after a reconnect), as pixel-level Playwright. */
|
|
1117
|
+
get page() {
|
|
1118
|
+
const page = this.browser.page;
|
|
1119
|
+
if (!isNativePage(page))
|
|
1120
|
+
throw new Error(
|
|
1121
|
+
"native computer use needs a Playwright page (mouse.move/click/down/up/wheel, context())"
|
|
1122
|
+
);
|
|
1123
|
+
return page;
|
|
1124
|
+
}
|
|
1125
|
+
run(action) {
|
|
1126
|
+
return this.handlers[action.name](action);
|
|
1127
|
+
}
|
|
1128
|
+
/** A PNG of the viewport at the model's display size. */
|
|
1129
|
+
async screenshot() {
|
|
1130
|
+
if (!this.display.scaled) return this.page.screenshot({ type: "png" });
|
|
1131
|
+
const { viewportWidth: width, viewportHeight: height } = this.display;
|
|
1132
|
+
return this.capture({ x: 0, y: 0, width, height }, this.display.scale);
|
|
1133
|
+
}
|
|
1134
|
+
/** Whether keystrokes go to a credential field (a password input, or one
|
|
1135
|
+
* named like a token, key or PIN), looking through shadow roots and
|
|
1136
|
+
* same-origin frames. An unreadable page, a cross-origin frame or a focus
|
|
1137
|
+
* that is not a text field (a closed shadow root's host) counts as one. */
|
|
1138
|
+
async focusedFieldIsSecret() {
|
|
1139
|
+
let described;
|
|
1140
|
+
try {
|
|
1141
|
+
described = String(await this.page.evaluate(FOCUSED_FIELD_JS) ?? "");
|
|
1142
|
+
} catch {
|
|
1143
|
+
return true;
|
|
1144
|
+
}
|
|
1145
|
+
return SECRET_FOCUS.some((prefix) => described.startsWith(prefix)) || SECRET_KEY.test(described);
|
|
1146
|
+
}
|
|
1147
|
+
/** CDP renders a clip at the page's device pixel ratio as well as its
|
|
1148
|
+
* `scale` (a Retina host doubles it), so a capture of the wrong width
|
|
1149
|
+
* measures that ratio and is taken once more, corrected. */
|
|
1150
|
+
async capture(clip, scale) {
|
|
1151
|
+
const wanted = Math.round(clip.width * scale);
|
|
1152
|
+
const png = await this.cdpCapture(clip, scale / this.pixelRatio);
|
|
1153
|
+
const width = pngWidth(png);
|
|
1154
|
+
if (width === null || Math.abs(width - wanted) <= 1) return png;
|
|
1155
|
+
this.pixelRatio *= width / wanted;
|
|
1156
|
+
return this.cdpCapture(clip, scale / this.pixelRatio);
|
|
1157
|
+
}
|
|
1158
|
+
async cdpCapture(clip, scale) {
|
|
1159
|
+
const page = this.page;
|
|
1160
|
+
const session = await page.context().newCDPSession(page);
|
|
1161
|
+
try {
|
|
1162
|
+
const shot = await session.send("Page.captureScreenshot", {
|
|
1163
|
+
format: "png",
|
|
1164
|
+
clip: { ...clip, scale }
|
|
1165
|
+
});
|
|
1166
|
+
return Buffer.from(shot.data, "base64");
|
|
1167
|
+
} finally {
|
|
1168
|
+
await session.detach();
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
point(action) {
|
|
1172
|
+
const { x, y } = action.args;
|
|
1173
|
+
return x === void 0 || y === void 0 ? this.cursor : [x, y];
|
|
1174
|
+
}
|
|
1175
|
+
async moveTo(point2, steps = 1) {
|
|
1176
|
+
const [x, y] = this.display.toPage(point2[0], point2[1]);
|
|
1177
|
+
await this.page.mouse.move(x, y, { steps });
|
|
1178
|
+
this.cursor = point2;
|
|
1179
|
+
}
|
|
1180
|
+
async held(modifiers, fn) {
|
|
1181
|
+
for (const key of modifiers) await this.page.keyboard.down(key);
|
|
1182
|
+
try {
|
|
1183
|
+
await fn();
|
|
1184
|
+
} finally {
|
|
1185
|
+
for (const key of [...modifiers].reverse())
|
|
1186
|
+
await this.page.keyboard.up(key);
|
|
1187
|
+
}
|
|
1188
|
+
return {};
|
|
1189
|
+
}
|
|
1190
|
+
async zoom(action) {
|
|
1191
|
+
const [x0, y0, x1, y1] = action.args.region ?? [0, 0, 0, 0];
|
|
1192
|
+
const [left, top] = this.display.toPage(x0, y0);
|
|
1193
|
+
const [right, bottom] = this.display.toPage(x1, y1);
|
|
1194
|
+
if (right <= left || bottom <= top)
|
|
1195
|
+
throw new Error("zoom region must have x1 > x0 and y1 > y0");
|
|
1196
|
+
const width = right - left;
|
|
1197
|
+
const height = bottom - top;
|
|
1198
|
+
const scale = Math.min(
|
|
1199
|
+
this.display.width / width,
|
|
1200
|
+
this.display.height / height
|
|
1201
|
+
);
|
|
1202
|
+
return {
|
|
1203
|
+
image: await this.capture({ x: left, y: top, width, height }, scale)
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1206
|
+
async click(action) {
|
|
1207
|
+
const point2 = this.point(action);
|
|
1208
|
+
return this.held(action.args.modifiers ?? [], async () => {
|
|
1209
|
+
await this.moveTo(point2);
|
|
1210
|
+
const [x, y] = this.display.toPage(point2[0], point2[1]);
|
|
1211
|
+
await this.page.mouse.click(x, y, {
|
|
1212
|
+
button: action.args.button ?? "left",
|
|
1213
|
+
clickCount: action.args.count ?? 1
|
|
1214
|
+
});
|
|
1215
|
+
});
|
|
1216
|
+
}
|
|
1217
|
+
async drag(action) {
|
|
1218
|
+
const path12 = action.args.path ?? [];
|
|
1219
|
+
if (path12.length < 2) throw new Error("a drag needs at least two points");
|
|
1220
|
+
return this.held(action.args.modifiers ?? [], async () => {
|
|
1221
|
+
await this.moveTo(path12[0]);
|
|
1222
|
+
await this.page.mouse.down({ button: "left" });
|
|
1223
|
+
try {
|
|
1224
|
+
for (const point2 of path12.slice(1)) await this.moveTo(point2, DRAG_STEPS);
|
|
1225
|
+
} finally {
|
|
1226
|
+
await this.page.mouse.up({ button: "left" });
|
|
1227
|
+
}
|
|
1228
|
+
});
|
|
1229
|
+
}
|
|
1230
|
+
async scroll(action) {
|
|
1231
|
+
await this.moveTo(this.point(action));
|
|
1232
|
+
const scale = this.display.scale;
|
|
1233
|
+
return this.held(
|
|
1234
|
+
action.args.modifiers ?? [],
|
|
1235
|
+
() => this.page.mouse.wheel(
|
|
1236
|
+
(action.args.dx ?? 0) / scale,
|
|
1237
|
+
(action.args.dy ?? 0) / scale
|
|
1238
|
+
)
|
|
1239
|
+
);
|
|
1240
|
+
}
|
|
1241
|
+
async key(action) {
|
|
1242
|
+
const combo = (action.args.keys ?? []).join("+");
|
|
1243
|
+
for (let i = 0; i < (action.args.repeat ?? 1); i += 1)
|
|
1244
|
+
await this.page.keyboard.press(combo);
|
|
1245
|
+
return {};
|
|
1246
|
+
}
|
|
1247
|
+
};
|
|
1248
|
+
}
|
|
1249
|
+
});
|
|
1250
|
+
|
|
1251
|
+
// src/tracing/media.ts
|
|
1252
|
+
async function putBytes(url, data, headers) {
|
|
1253
|
+
const controller = new AbortController();
|
|
1254
|
+
const timer = setTimeout(() => controller.abort(), PUT_TIMEOUT_MS);
|
|
1255
|
+
try {
|
|
1256
|
+
const res = await fetch(url, {
|
|
1257
|
+
method: "PUT",
|
|
1258
|
+
body: new Uint8Array(data),
|
|
1259
|
+
headers,
|
|
1260
|
+
signal: controller.signal
|
|
1261
|
+
});
|
|
1262
|
+
return {
|
|
1263
|
+
status: res.status,
|
|
1264
|
+
error: res.ok ? null : (await res.text()).slice(0, MAX_UPLOAD_ERROR)
|
|
1265
|
+
};
|
|
1266
|
+
} catch (error) {
|
|
1267
|
+
return {
|
|
1268
|
+
status: NETWORK_FAILURE_STATUS,
|
|
1269
|
+
error: error instanceof Error ? error.name : "Error"
|
|
1270
|
+
};
|
|
1271
|
+
} finally {
|
|
1272
|
+
clearTimeout(timer);
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
var import_node_crypto, MEDIA_PATH, MAX_MEDIA_BYTES, PUT_TIMEOUT_MS, MAX_UPLOAD_ERROR, NETWORK_FAILURE_STATUS, MediaUploadError, MediaReference, MediaUploader;
|
|
1276
|
+
var init_media = __esm({
|
|
1277
|
+
"src/tracing/media.ts"() {
|
|
1278
|
+
"use strict";
|
|
1279
|
+
import_node_crypto = require("crypto");
|
|
1280
|
+
init_transport();
|
|
1281
|
+
MEDIA_PATH = "/api/public/media";
|
|
1282
|
+
MAX_MEDIA_BYTES = 5 * 1024 * 1024;
|
|
1283
|
+
PUT_TIMEOUT_MS = 3e4;
|
|
1284
|
+
MAX_UPLOAD_ERROR = 500;
|
|
1285
|
+
NETWORK_FAILURE_STATUS = 599;
|
|
1286
|
+
MediaUploadError = class extends Error {
|
|
1287
|
+
constructor(message, status) {
|
|
1288
|
+
super(message);
|
|
1289
|
+
this.status = status;
|
|
1290
|
+
this.name = "MediaUploadError";
|
|
1291
|
+
}
|
|
1292
|
+
status;
|
|
1293
|
+
};
|
|
1294
|
+
MediaReference = class {
|
|
1295
|
+
constructor(mediaId, contentType) {
|
|
1296
|
+
this.mediaId = mediaId;
|
|
1297
|
+
this.contentType = contentType;
|
|
1298
|
+
}
|
|
1299
|
+
mediaId;
|
|
1300
|
+
contentType;
|
|
1301
|
+
toString() {
|
|
1302
|
+
return `@@@langfuseMedia:type=${this.contentType}|id=${this.mediaId}|source=bytes@@@`;
|
|
1303
|
+
}
|
|
1304
|
+
};
|
|
1305
|
+
MediaUploader = class _MediaUploader {
|
|
1306
|
+
constructor(transport, put = putBytes, maxBytes = MAX_MEDIA_BYTES) {
|
|
1307
|
+
this.transport = transport;
|
|
1308
|
+
this.put = put;
|
|
1309
|
+
this.maxBytes = maxBytes;
|
|
1310
|
+
}
|
|
1311
|
+
transport;
|
|
1312
|
+
put;
|
|
1313
|
+
maxBytes;
|
|
1314
|
+
/** The uploader for `GATEWAY_HOST` / `GATEWAY_PUBLIC_KEY` /
|
|
1315
|
+
* `GATEWAY_SECRET_KEY` (the keys tracing exports with); null when any is unset. */
|
|
1316
|
+
static fromEnv(env = process.env) {
|
|
1317
|
+
const host = env.GATEWAY_HOST;
|
|
1318
|
+
const publicKey = env.GATEWAY_PUBLIC_KEY;
|
|
1319
|
+
const secretKey = env.GATEWAY_SECRET_KEY;
|
|
1320
|
+
if (!host || !publicKey || !secretKey) return null;
|
|
1321
|
+
return new _MediaUploader(
|
|
1322
|
+
new PlatformTransport({
|
|
1323
|
+
host: host.replace(/\/$/, ""),
|
|
1324
|
+
publicKey,
|
|
1325
|
+
secretKey
|
|
1326
|
+
})
|
|
1327
|
+
);
|
|
1328
|
+
}
|
|
1329
|
+
/** Store `data` linked to the trace (and observation) and return its reference. */
|
|
1330
|
+
async upload(data, link) {
|
|
1331
|
+
if (data.length > this.maxBytes)
|
|
1332
|
+
throw new MediaUploadError(
|
|
1333
|
+
`media is ${data.length} bytes, over the ${this.maxBytes}-byte cap`
|
|
1334
|
+
);
|
|
1335
|
+
const sha256Hash = (0, import_node_crypto.createHash)("sha256").update(data).digest("base64");
|
|
1336
|
+
const answer = await this.send("POST", MEDIA_PATH, {
|
|
1337
|
+
traceId: link.traceId,
|
|
1338
|
+
observationId: link.observationId,
|
|
1339
|
+
contentType: link.contentType,
|
|
1340
|
+
contentLength: data.length,
|
|
1341
|
+
sha256Hash,
|
|
1342
|
+
field: link.field
|
|
1343
|
+
});
|
|
1344
|
+
if (typeof answer.mediaId !== "string" || !answer.mediaId)
|
|
1345
|
+
throw new MediaUploadError(
|
|
1346
|
+
"POST /api/public/media answered without a mediaId"
|
|
1347
|
+
);
|
|
1348
|
+
const reference = new MediaReference(answer.mediaId, link.contentType);
|
|
1349
|
+
if (answer.uploadUrl)
|
|
1350
|
+
await this.store(reference, answer.uploadUrl, data, sha256Hash);
|
|
1351
|
+
return reference;
|
|
1352
|
+
}
|
|
1353
|
+
async store(reference, url, data, sha256Hash) {
|
|
1354
|
+
const started = Date.now();
|
|
1355
|
+
const { status, error } = await this.put(url, data, {
|
|
1356
|
+
"Content-Type": reference.contentType,
|
|
1357
|
+
"x-amz-checksum-sha256": sha256Hash,
|
|
1358
|
+
"x-ms-blob-type": "BlockBlob"
|
|
1359
|
+
});
|
|
1360
|
+
await this.send(
|
|
1361
|
+
"PATCH",
|
|
1362
|
+
`${MEDIA_PATH}/${encodeURIComponent(reference.mediaId)}`,
|
|
1363
|
+
{
|
|
1364
|
+
uploadedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1365
|
+
uploadHttpStatus: status,
|
|
1366
|
+
uploadHttpError: error,
|
|
1367
|
+
uploadTimeMs: Date.now() - started
|
|
1368
|
+
}
|
|
1369
|
+
);
|
|
1370
|
+
if (status < 200 || status >= 300)
|
|
1371
|
+
throw new MediaUploadError(
|
|
1372
|
+
`media storage refused the upload (HTTP ${status})`,
|
|
1373
|
+
status
|
|
1374
|
+
);
|
|
1375
|
+
}
|
|
1376
|
+
async send(method, route, body) {
|
|
1377
|
+
const reply = await this.transport.send(method, route, body);
|
|
1378
|
+
if (!reply.ok)
|
|
1379
|
+
throw new MediaUploadError(
|
|
1380
|
+
`${method} ${route} -> ${reply.status}`,
|
|
1381
|
+
reply.status
|
|
1382
|
+
);
|
|
1383
|
+
return reply.text ? JSON.parse(reply.text) : {};
|
|
1384
|
+
}
|
|
1385
|
+
};
|
|
1386
|
+
}
|
|
1387
|
+
});
|
|
1388
|
+
|
|
1389
|
+
// src/worlds/nativeComputer/trace.ts
|
|
1390
|
+
function loadOtelApi() {
|
|
1391
|
+
if (otelApi !== void 0) return otelApi;
|
|
1392
|
+
try {
|
|
1393
|
+
otelApi = require("@opentelemetry/api");
|
|
1394
|
+
} catch {
|
|
1395
|
+
otelApi = null;
|
|
1396
|
+
}
|
|
1397
|
+
return otelApi;
|
|
1398
|
+
}
|
|
1399
|
+
function errorText(error) {
|
|
1400
|
+
return error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
1401
|
+
}
|
|
1402
|
+
function errorName(error) {
|
|
1403
|
+
return error instanceof Error ? error.name : "Error";
|
|
1404
|
+
}
|
|
1405
|
+
var SPAN_PREFIX, MAX_UPLOAD_FAILURES, TRACER_NAME, MAX_ERROR, otelApi, ActionTracer;
|
|
1406
|
+
var init_trace = __esm({
|
|
1407
|
+
"src/worlds/nativeComputer/trace.ts"() {
|
|
1408
|
+
"use strict";
|
|
1409
|
+
init_media();
|
|
1410
|
+
SPAN_PREFIX = "computer.";
|
|
1411
|
+
MAX_UPLOAD_FAILURES = 3;
|
|
1412
|
+
TRACER_NAME = "@withgateway/sdk";
|
|
1413
|
+
MAX_ERROR = 1e3;
|
|
1414
|
+
ActionTracer = class _ActionTracer {
|
|
1415
|
+
constructor(media, warn2 = (m) => console.warn(m)) {
|
|
1416
|
+
this.media = media;
|
|
1417
|
+
this.warn = warn2;
|
|
1418
|
+
}
|
|
1419
|
+
media;
|
|
1420
|
+
warn;
|
|
1421
|
+
failures = 0;
|
|
1422
|
+
warned = false;
|
|
1423
|
+
static fromEnv() {
|
|
1424
|
+
return new _ActionTracer(MediaUploader.fromEnv());
|
|
1425
|
+
}
|
|
1426
|
+
/** `args` are already redacted. A failure's status goes through `scrub`:
|
|
1427
|
+
* browser errors quote the session's ws URL and UI token. */
|
|
1428
|
+
async span(action, args, run, capture, scrub) {
|
|
1429
|
+
const otel = loadOtelApi();
|
|
1430
|
+
if (!otel) return run();
|
|
1431
|
+
const { SpanStatusCode, trace: trace3 } = otel;
|
|
1432
|
+
const attributes = {
|
|
1433
|
+
"gateway.observation.type": "tool",
|
|
1434
|
+
"tool.name": SPAN_PREFIX + action.name,
|
|
1435
|
+
"gateway.observation.input": JSON.stringify({
|
|
1436
|
+
action: action.name,
|
|
1437
|
+
...args
|
|
1438
|
+
})
|
|
1439
|
+
};
|
|
1440
|
+
return trace3.getTracer(TRACER_NAME).startActiveSpan(
|
|
1441
|
+
SPAN_PREFIX + action.name,
|
|
1442
|
+
{ attributes },
|
|
1443
|
+
async (span) => {
|
|
1444
|
+
try {
|
|
1445
|
+
const result = await run();
|
|
1446
|
+
await this.finish(span, result, capture);
|
|
1447
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
1448
|
+
return result;
|
|
1449
|
+
} catch (error) {
|
|
1450
|
+
span.setStatus({
|
|
1451
|
+
code: SpanStatusCode.ERROR,
|
|
1452
|
+
message: scrub(errorText(error)).slice(0, MAX_ERROR)
|
|
1453
|
+
});
|
|
1454
|
+
throw error;
|
|
1455
|
+
} finally {
|
|
1456
|
+
span.end();
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
);
|
|
1460
|
+
}
|
|
1461
|
+
async finish(span, result, capture) {
|
|
1462
|
+
if (!span.isRecording()) return;
|
|
1463
|
+
const output = {
|
|
1464
|
+
screenshot: await this.screenshot(span, result, capture)
|
|
1465
|
+
};
|
|
1466
|
+
if (result.text !== void 0) output.text = result.text;
|
|
1467
|
+
span.setAttribute("gateway.observation.output", JSON.stringify(output));
|
|
1468
|
+
}
|
|
1469
|
+
async screenshot(span, result, capture) {
|
|
1470
|
+
let png;
|
|
1471
|
+
try {
|
|
1472
|
+
png = result.image ?? await capture();
|
|
1473
|
+
} catch (error) {
|
|
1474
|
+
return `[screenshot unavailable: ${errorName(error)}]`;
|
|
1475
|
+
}
|
|
1476
|
+
return this.reference(png, span);
|
|
1477
|
+
}
|
|
1478
|
+
async reference(png, span) {
|
|
1479
|
+
if (!this.media)
|
|
1480
|
+
return "[screenshot not uploaded: GATEWAY_HOST / GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY unset]";
|
|
1481
|
+
if (this.failures >= MAX_UPLOAD_FAILURES)
|
|
1482
|
+
return "[screenshot not uploaded: uploads disabled after repeated failures]";
|
|
1483
|
+
const { traceId, spanId } = span.spanContext();
|
|
1484
|
+
try {
|
|
1485
|
+
const reference = await this.media.upload(png, {
|
|
1486
|
+
contentType: "image/png",
|
|
1487
|
+
traceId,
|
|
1488
|
+
observationId: spanId,
|
|
1489
|
+
field: "output"
|
|
1490
|
+
});
|
|
1491
|
+
this.failures = 0;
|
|
1492
|
+
return reference.toString();
|
|
1493
|
+
} catch (error) {
|
|
1494
|
+
return this.failed(error);
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
failed(error) {
|
|
1498
|
+
this.failures += 1;
|
|
1499
|
+
if (!this.warned) {
|
|
1500
|
+
this.warned = true;
|
|
1501
|
+
this.warn(
|
|
1502
|
+
`native computer: screenshot upload failed (${errorName(error)}: ${error instanceof Error ? error.message : String(error)}); spans keep going without it`
|
|
1503
|
+
);
|
|
1504
|
+
}
|
|
1505
|
+
return `[screenshot not uploaded: ${errorName(error)}]`;
|
|
1506
|
+
}
|
|
1507
|
+
};
|
|
1508
|
+
}
|
|
1509
|
+
});
|
|
1510
|
+
|
|
1511
|
+
// src/worlds/nativeComputer/base.ts
|
|
1512
|
+
function readField(item, ...names) {
|
|
1513
|
+
const record = item ?? {};
|
|
1514
|
+
return names.map((name) => record[name]).find((value) => value !== void 0 && value !== null);
|
|
1515
|
+
}
|
|
1516
|
+
var REPLAYABLE, SETTLING, EVENT_PREFIX, NativeComputer;
|
|
1517
|
+
var init_base = __esm({
|
|
1518
|
+
"src/worlds/nativeComputer/base.ts"() {
|
|
1519
|
+
"use strict";
|
|
1520
|
+
init_browser();
|
|
1521
|
+
init_actions();
|
|
1522
|
+
init_display();
|
|
1523
|
+
init_screen();
|
|
1524
|
+
init_trace();
|
|
1525
|
+
REPLAYABLE = /* @__PURE__ */ new Set(["screenshot", "zoom", "cursor_position", "wait"]);
|
|
1526
|
+
SETTLING = /* @__PURE__ */ new Set(["click", "mouse_up", "drag", "key", "history"]);
|
|
1527
|
+
EVENT_PREFIX = "computer_";
|
|
1528
|
+
NativeComputer = class _NativeComputer {
|
|
1529
|
+
constructor(browser, options = {}) {
|
|
1530
|
+
this.browser = browser;
|
|
1531
|
+
const kind = this.constructor;
|
|
1532
|
+
this.display = Display.forViewport(
|
|
1533
|
+
browser.viewport,
|
|
1534
|
+
options.display,
|
|
1535
|
+
(w, h) => kind.fits(w, h)
|
|
1536
|
+
);
|
|
1537
|
+
this.screen = new Screen(browser, this.display);
|
|
1538
|
+
this.tracer = options.tracer ?? ActionTracer.fromEnv();
|
|
1539
|
+
}
|
|
1540
|
+
browser;
|
|
1541
|
+
static kinds = /* @__PURE__ */ new Map();
|
|
1542
|
+
display;
|
|
1543
|
+
screen;
|
|
1544
|
+
tracer;
|
|
1545
|
+
queue = Promise.resolve();
|
|
1546
|
+
static register(provider, kind) {
|
|
1547
|
+
_NativeComputer.kinds.set(provider, kind);
|
|
1548
|
+
}
|
|
1549
|
+
static get providers() {
|
|
1550
|
+
return [..._NativeComputer.kinds.keys()].sort();
|
|
1551
|
+
}
|
|
1552
|
+
static forProvider(provider, browser, options = {}) {
|
|
1553
|
+
const Kind = _NativeComputer.kinds.get(provider);
|
|
1554
|
+
if (!Kind)
|
|
1555
|
+
throw new Error(
|
|
1556
|
+
`unknown computer-use provider '${provider}'; choose from ${_NativeComputer.providers.join(", ")}`
|
|
1557
|
+
);
|
|
1558
|
+
return new Kind(browser, options);
|
|
1559
|
+
}
|
|
1560
|
+
/** Whether a screenshot of this size is within the provider's limits. */
|
|
1561
|
+
static fits(_width, _height) {
|
|
1562
|
+
return true;
|
|
1563
|
+
}
|
|
1564
|
+
/** Run one provider-shaped action (an OpenAI action object, or an Anthropic
|
|
1565
|
+
* `{ action: "left_click", ... }` input) and return what it produced: the
|
|
1566
|
+
* door for any agent framework that hands actions over one at a time. */
|
|
1567
|
+
executeAction(raw) {
|
|
1568
|
+
return this.perform(this.parse(raw));
|
|
1569
|
+
}
|
|
1570
|
+
/** Run one action on the page: reported on the session's browser timeline
|
|
1571
|
+
* and, when tracing is on, as a span with the screen after. */
|
|
1572
|
+
async perform(action) {
|
|
1573
|
+
const secret = action.name === "type" && await this.screen.focusedFieldIsSecret();
|
|
1574
|
+
const event = EVENT_PREFIX + action.name;
|
|
1575
|
+
const args = redactActionArgs(event, action.recordArgs(secret));
|
|
1576
|
+
return this.tracer.span(
|
|
1577
|
+
action,
|
|
1578
|
+
args,
|
|
1579
|
+
() => this.browser.act(
|
|
1580
|
+
event,
|
|
1581
|
+
args,
|
|
1582
|
+
() => this.runOnScreen(action),
|
|
1583
|
+
this.onLoss(action)
|
|
1584
|
+
),
|
|
1585
|
+
() => this.screen.screenshot(),
|
|
1586
|
+
(text2) => this.browser.scrub(text2)
|
|
1587
|
+
);
|
|
1588
|
+
}
|
|
1589
|
+
async performAll(actions) {
|
|
1590
|
+
const results = [];
|
|
1591
|
+
for (const action of actions) results.push(await this.perform(action));
|
|
1592
|
+
return results;
|
|
1593
|
+
}
|
|
1594
|
+
/** The screen as the model sees it, as a traced `screenshot` action. */
|
|
1595
|
+
async screenshot() {
|
|
1596
|
+
return (await this.perform(new ComputerAction("screenshot"))).image ?? Buffer.alloc(0);
|
|
1597
|
+
}
|
|
1598
|
+
/** Run `fn` after every earlier call made through here: the AI SDK starts a
|
|
1599
|
+
* step's tool calls concurrently, but one screen takes one action at a time. */
|
|
1600
|
+
serial(fn) {
|
|
1601
|
+
const next = this.queue.then(fn, fn);
|
|
1602
|
+
this.queue = next.catch(() => void 0);
|
|
1603
|
+
return next;
|
|
1604
|
+
}
|
|
1605
|
+
async runOnScreen(action) {
|
|
1606
|
+
const result = await this.screen.run(action);
|
|
1607
|
+
if (SETTLING.has(action.name)) await this.browser.settle();
|
|
1608
|
+
return result;
|
|
1609
|
+
}
|
|
1610
|
+
onLoss(action) {
|
|
1611
|
+
return REPLAYABLE.has(action.name) ? "retry" : "report";
|
|
1612
|
+
}
|
|
1613
|
+
};
|
|
1614
|
+
}
|
|
1615
|
+
});
|
|
1616
|
+
|
|
1617
|
+
// src/worlds/nativeComputer/keys.ts
|
|
1618
|
+
function playwrightKey(token) {
|
|
1619
|
+
return KEY_NAMES[token.toLowerCase()] ?? token;
|
|
1620
|
+
}
|
|
1621
|
+
function letterOrName(key) {
|
|
1622
|
+
return /^[a-zA-Z]$/.test(key) ? key.toLowerCase() : playwrightKey(key);
|
|
1623
|
+
}
|
|
1624
|
+
function modifierChord(text2) {
|
|
1625
|
+
return typeof text2 === "string" && text2 ? [...KeyChord.fromXdotool(text2).keys] : [];
|
|
1626
|
+
}
|
|
1627
|
+
function modifierKeys(keys) {
|
|
1628
|
+
return Array.isArray(keys) && keys.length > 0 ? [...KeyChord.fromKeys(keys.map(String)).keys] : [];
|
|
1629
|
+
}
|
|
1630
|
+
var F_KEYS, KEY_NAMES, KeyChord;
|
|
1631
|
+
var init_keys = __esm({
|
|
1632
|
+
"src/worlds/nativeComputer/keys.ts"() {
|
|
1633
|
+
"use strict";
|
|
1634
|
+
F_KEYS = Object.fromEntries(
|
|
1635
|
+
Array.from({ length: 12 }, (_, i) => [`f${i + 1}`, `F${i + 1}`])
|
|
1636
|
+
);
|
|
1637
|
+
KEY_NAMES = {
|
|
1638
|
+
return: "Enter",
|
|
1639
|
+
enter: "Enter",
|
|
1640
|
+
kp_enter: "Enter",
|
|
1641
|
+
esc: "Escape",
|
|
1642
|
+
escape: "Escape",
|
|
1643
|
+
tab: "Tab",
|
|
1644
|
+
space: "Space",
|
|
1645
|
+
backspace: "Backspace",
|
|
1646
|
+
delete: "Delete",
|
|
1647
|
+
del: "Delete",
|
|
1648
|
+
insert: "Insert",
|
|
1649
|
+
home: "Home",
|
|
1650
|
+
end: "End",
|
|
1651
|
+
pageup: "PageUp",
|
|
1652
|
+
page_up: "PageUp",
|
|
1653
|
+
prior: "PageUp",
|
|
1654
|
+
pagedown: "PageDown",
|
|
1655
|
+
page_down: "PageDown",
|
|
1656
|
+
next: "PageDown",
|
|
1657
|
+
up: "ArrowUp",
|
|
1658
|
+
arrowup: "ArrowUp",
|
|
1659
|
+
down: "ArrowDown",
|
|
1660
|
+
arrowdown: "ArrowDown",
|
|
1661
|
+
left: "ArrowLeft",
|
|
1662
|
+
arrowleft: "ArrowLeft",
|
|
1663
|
+
right: "ArrowRight",
|
|
1664
|
+
arrowright: "ArrowRight",
|
|
1665
|
+
ctrl: "Control",
|
|
1666
|
+
control: "Control",
|
|
1667
|
+
shift: "Shift",
|
|
1668
|
+
alt: "Alt",
|
|
1669
|
+
option: "Alt",
|
|
1670
|
+
super: "Meta",
|
|
1671
|
+
meta: "Meta",
|
|
1672
|
+
cmd: "Meta",
|
|
1673
|
+
command: "Meta",
|
|
1674
|
+
win: "Meta",
|
|
1675
|
+
capslock: "CapsLock",
|
|
1676
|
+
caps_lock: "CapsLock",
|
|
1677
|
+
plus: "+",
|
|
1678
|
+
minus: "-",
|
|
1679
|
+
...F_KEYS
|
|
1680
|
+
};
|
|
1681
|
+
KeyChord = class _KeyChord {
|
|
1682
|
+
constructor(keys) {
|
|
1683
|
+
this.keys = keys;
|
|
1684
|
+
if (keys.length === 0)
|
|
1685
|
+
throw new Error("a key action needs at least one key");
|
|
1686
|
+
}
|
|
1687
|
+
keys;
|
|
1688
|
+
/** `ctrl+shift+t` / `Return`: Anthropic's vocabulary, case kept. */
|
|
1689
|
+
static fromXdotool(text2) {
|
|
1690
|
+
return new _KeyChord(
|
|
1691
|
+
text2.trim().split("+").filter(Boolean).map(playwrightKey)
|
|
1692
|
+
);
|
|
1693
|
+
}
|
|
1694
|
+
/** `["CTRL", "A"]`: OpenAI's vocabulary. A lone letter is the unshifted key. */
|
|
1695
|
+
static fromKeys(keys) {
|
|
1696
|
+
return new _KeyChord(keys.map(letterOrName));
|
|
1697
|
+
}
|
|
1698
|
+
/** What `page.keyboard.press` takes: `Control+a`. */
|
|
1699
|
+
get combo() {
|
|
1700
|
+
return this.keys.join("+");
|
|
1701
|
+
}
|
|
1702
|
+
};
|
|
1703
|
+
}
|
|
1704
|
+
});
|
|
1705
|
+
|
|
1706
|
+
// src/worlds/nativeComputer/anthropic.ts
|
|
1707
|
+
function required(raw, key) {
|
|
1708
|
+
const value = raw[key];
|
|
1709
|
+
if (value === void 0 || value === null)
|
|
1710
|
+
throw new Error(`${String(raw.action)} needs ${key}`);
|
|
1711
|
+
return value;
|
|
1712
|
+
}
|
|
1713
|
+
function pair(raw, key) {
|
|
1714
|
+
const value = required(raw, key);
|
|
1715
|
+
return [toInt(value[0]), toInt(value[1])];
|
|
1716
|
+
}
|
|
1717
|
+
function point(raw) {
|
|
1718
|
+
if (raw.coordinate === void 0 || raw.coordinate === null) return {};
|
|
1719
|
+
const [x, y] = pair(raw, "coordinate");
|
|
1720
|
+
return { x, y };
|
|
1721
|
+
}
|
|
1722
|
+
function chord(raw) {
|
|
1723
|
+
return [...KeyChord.fromXdotool(String(required(raw, "text"))).keys];
|
|
1724
|
+
}
|
|
1725
|
+
function click(button, count) {
|
|
1726
|
+
return (raw) => new ComputerAction("click", {
|
|
1727
|
+
...point(raw),
|
|
1728
|
+
button,
|
|
1729
|
+
count,
|
|
1730
|
+
modifiers: modifierChord(raw.text)
|
|
1731
|
+
});
|
|
1732
|
+
}
|
|
1733
|
+
var SCROLL_STEP_PX, NOT_EXECUTED, MAX_ERROR2, SCROLL_DIRECTIONS, MEMBERS, AnthropicComputer, AnthropicComputer20251124;
|
|
1734
|
+
var init_anthropic = __esm({
|
|
1735
|
+
"src/worlds/nativeComputer/anthropic.ts"() {
|
|
1736
|
+
"use strict";
|
|
1737
|
+
init_actions();
|
|
1738
|
+
init_base();
|
|
1739
|
+
init_keys();
|
|
1740
|
+
SCROLL_STEP_PX = 100;
|
|
1741
|
+
NOT_EXECUTED = "Not executed: an earlier computer action in this turn failed.";
|
|
1742
|
+
MAX_ERROR2 = 1e3;
|
|
1743
|
+
SCROLL_DIRECTIONS = {
|
|
1744
|
+
up: [0, -1],
|
|
1745
|
+
down: [0, 1],
|
|
1746
|
+
left: [-1, 0],
|
|
1747
|
+
right: [1, 0]
|
|
1748
|
+
};
|
|
1749
|
+
MEMBERS = {
|
|
1750
|
+
screenshot: () => new ComputerAction("screenshot"),
|
|
1751
|
+
zoom: (raw) => new ComputerAction("zoom", {
|
|
1752
|
+
region: required(raw, "region").map(toInt)
|
|
1753
|
+
}),
|
|
1754
|
+
left_click: click("left", 1),
|
|
1755
|
+
right_click: click("right", 1),
|
|
1756
|
+
middle_click: click("middle", 1),
|
|
1757
|
+
double_click: click("left", 2),
|
|
1758
|
+
triple_click: click("left", 3),
|
|
1759
|
+
left_click_drag: (raw) => new ComputerAction("drag", {
|
|
1760
|
+
path: [pair(raw, "start_coordinate"), pair(raw, "coordinate")],
|
|
1761
|
+
modifiers: modifierChord(raw.text)
|
|
1762
|
+
}),
|
|
1763
|
+
mouse_move: (raw) => {
|
|
1764
|
+
const [x, y] = pair(raw, "coordinate");
|
|
1765
|
+
return new ComputerAction("move", { x, y });
|
|
1766
|
+
},
|
|
1767
|
+
left_mouse_down: () => new ComputerAction("mouse_down", { button: "left" }),
|
|
1768
|
+
left_mouse_up: () => new ComputerAction("mouse_up", { button: "left" }),
|
|
1769
|
+
cursor_position: () => new ComputerAction("cursor_position"),
|
|
1770
|
+
scroll: (raw) => {
|
|
1771
|
+
const direction = String(raw.scroll_direction ?? "down");
|
|
1772
|
+
if (!Object.hasOwn(SCROLL_DIRECTIONS, direction))
|
|
1773
|
+
throw new Error(
|
|
1774
|
+
`scroll_direction must be one of ${Object.keys(SCROLL_DIRECTIONS).join(", ")}`
|
|
1775
|
+
);
|
|
1776
|
+
const [dx, dy] = SCROLL_DIRECTIONS[direction];
|
|
1777
|
+
const amount = toInt(raw.scroll_amount ?? 1) * SCROLL_STEP_PX;
|
|
1778
|
+
return new ComputerAction("scroll", {
|
|
1779
|
+
...point(raw),
|
|
1780
|
+
dx: dx * amount,
|
|
1781
|
+
dy: dy * amount,
|
|
1782
|
+
modifiers: modifierChord(raw.text)
|
|
1783
|
+
});
|
|
1784
|
+
},
|
|
1785
|
+
type: (raw) => new ComputerAction("type", { text: String(required(raw, "text")) }),
|
|
1786
|
+
key: (raw) => new ComputerAction("key", {
|
|
1787
|
+
keys: chord(raw),
|
|
1788
|
+
repeat: toInt(raw.repeat ?? 1)
|
|
1789
|
+
}),
|
|
1790
|
+
hold_key: (raw) => new ComputerAction("hold_key", {
|
|
1791
|
+
keys: chord(raw),
|
|
1792
|
+
seconds: toNumber(required(raw, "duration"))
|
|
1793
|
+
}),
|
|
1794
|
+
wait: (raw) => new ComputerAction("wait", { seconds: toNumber(raw.duration ?? 1) })
|
|
1795
|
+
};
|
|
1796
|
+
AnthropicComputer = class _AnthropicComputer extends NativeComputer {
|
|
1797
|
+
static TOOL_TYPE = "computer_toolset_20260801";
|
|
1798
|
+
static TOOLSET = "computer";
|
|
1799
|
+
static BETA = null;
|
|
1800
|
+
static MAX_LONG_EDGE = 2576;
|
|
1801
|
+
static MAX_VISUAL_TOKENS = 4784;
|
|
1802
|
+
static PATCH_PX = 28;
|
|
1803
|
+
static fits(width, height) {
|
|
1804
|
+
const tokens = Math.ceil(width / this.PATCH_PX) * Math.ceil(height / this.PATCH_PX);
|
|
1805
|
+
return Math.max(width, height) <= this.MAX_LONG_EDGE && tokens <= this.MAX_VISUAL_TOKENS;
|
|
1806
|
+
}
|
|
1807
|
+
tool() {
|
|
1808
|
+
return { type: _AnthropicComputer.TOOL_TYPE };
|
|
1809
|
+
}
|
|
1810
|
+
/** Whether a content block is a call to this computer. */
|
|
1811
|
+
owns(block) {
|
|
1812
|
+
return readField(block, "type") === "tool_use" && readField(block, "toolset_name") === _AnthropicComputer.TOOLSET;
|
|
1813
|
+
}
|
|
1814
|
+
member(block) {
|
|
1815
|
+
return [
|
|
1816
|
+
String(readField(block, "name")),
|
|
1817
|
+
{ ...readField(block, "input") ?? {} }
|
|
1818
|
+
];
|
|
1819
|
+
}
|
|
1820
|
+
parse(raw) {
|
|
1821
|
+
const name = String(readField(raw, "action"));
|
|
1822
|
+
const parser = Object.hasOwn(MEMBERS, name) ? MEMBERS[name] : void 0;
|
|
1823
|
+
if (!parser) throw new Error(`unknown computer action: ${name}`);
|
|
1824
|
+
return parser(raw);
|
|
1825
|
+
}
|
|
1826
|
+
/** Run every computer `tool_use` in a response's content, in order, and
|
|
1827
|
+
* return one `tool_result` per block. Other blocks are skipped. */
|
|
1828
|
+
async execute(content) {
|
|
1829
|
+
const results = [];
|
|
1830
|
+
let failed = false;
|
|
1831
|
+
for (const block of content) {
|
|
1832
|
+
if (!this.owns(block)) continue;
|
|
1833
|
+
if (failed) {
|
|
1834
|
+
results.push(this.envelope(block, NOT_EXECUTED, true));
|
|
1835
|
+
continue;
|
|
1836
|
+
}
|
|
1837
|
+
const [result, blockFailed] = await this.runBlock(block);
|
|
1838
|
+
results.push(result);
|
|
1839
|
+
failed = blockFailed;
|
|
1840
|
+
}
|
|
1841
|
+
return results;
|
|
1842
|
+
}
|
|
1843
|
+
/** The content an `ActionResult` goes back to the model as. */
|
|
1844
|
+
static content(result) {
|
|
1845
|
+
if (result.image)
|
|
1846
|
+
return [
|
|
1847
|
+
{
|
|
1848
|
+
type: "image",
|
|
1849
|
+
source: {
|
|
1850
|
+
type: "base64",
|
|
1851
|
+
media_type: "image/png",
|
|
1852
|
+
data: result.image.toString("base64")
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
];
|
|
1856
|
+
return [{ type: "text", text: result.text ?? "OK" }];
|
|
1857
|
+
}
|
|
1858
|
+
/** For `anthropic.tools.computerToolset_20260801({ ...computer.aiSdk() })`
|
|
1859
|
+
* (or `computer_20251124` with the legacy kind): `execute` runs one action
|
|
1860
|
+
* and returns `{ type: "image", data }` or text; `toModelOutput` turns that
|
|
1861
|
+
* into the tool result. Calls run one at a time, and once a call fails the
|
|
1862
|
+
* rest of that step's calls answer as not executed. */
|
|
1863
|
+
aiSdk() {
|
|
1864
|
+
let failedStep;
|
|
1865
|
+
const execute = (input, options) => this.serial(async () => {
|
|
1866
|
+
const step = options?.messages?.length;
|
|
1867
|
+
if (step !== void 0 && step === failedStep)
|
|
1868
|
+
throw new Error(NOT_EXECUTED);
|
|
1869
|
+
try {
|
|
1870
|
+
return _AnthropicComputer.aiSdkOutput(await this.executeAction(input));
|
|
1871
|
+
} catch (error) {
|
|
1872
|
+
failedStep = step;
|
|
1873
|
+
throw error instanceof Error ? new Error(this.browser.scrub(error.message)) : error;
|
|
1874
|
+
}
|
|
1875
|
+
});
|
|
1876
|
+
return {
|
|
1877
|
+
execute,
|
|
1878
|
+
toModelOutput: ({ output }) => _AnthropicComputer.aiSdkModelOutput(output)
|
|
1879
|
+
};
|
|
1880
|
+
}
|
|
1881
|
+
static aiSdkOutput(result) {
|
|
1882
|
+
if (result.image)
|
|
1883
|
+
return { type: "image", data: result.image.toString("base64") };
|
|
1884
|
+
return result.text ?? "OK";
|
|
1885
|
+
}
|
|
1886
|
+
/** `image-data` is what AI SDK 6's Anthropic provider turns into an image
|
|
1887
|
+
* block; AI SDK 7 still accepts it (and converts it to a `file` part). */
|
|
1888
|
+
static aiSdkModelOutput(output) {
|
|
1889
|
+
if (typeof output === "string") return { type: "text", value: output };
|
|
1890
|
+
return {
|
|
1891
|
+
type: "content",
|
|
1892
|
+
value: [
|
|
1893
|
+
{ type: "image-data", data: output.data, mediaType: "image/png" }
|
|
1894
|
+
]
|
|
1895
|
+
};
|
|
1896
|
+
}
|
|
1897
|
+
envelope(block, content, isError = false) {
|
|
1898
|
+
return {
|
|
1899
|
+
type: "tool_result",
|
|
1900
|
+
tool_use_id: String(readField(block, "id")),
|
|
1901
|
+
toolset_name: _AnthropicComputer.TOOLSET,
|
|
1902
|
+
content,
|
|
1903
|
+
...isError ? { is_error: true } : {}
|
|
1904
|
+
};
|
|
1905
|
+
}
|
|
1906
|
+
async runBlock(block) {
|
|
1907
|
+
const [name, payload] = this.member(block);
|
|
1908
|
+
try {
|
|
1909
|
+
const result = await this.executeAction({ ...payload, action: name });
|
|
1910
|
+
return [this.envelope(block, _AnthropicComputer.content(result)), false];
|
|
1911
|
+
} catch (error) {
|
|
1912
|
+
const detail = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
1913
|
+
return [
|
|
1914
|
+
this.envelope(
|
|
1915
|
+
block,
|
|
1916
|
+
this.browser.scrub(`Error: ${detail}`).slice(0, MAX_ERROR2),
|
|
1917
|
+
true
|
|
1918
|
+
),
|
|
1919
|
+
true
|
|
1920
|
+
];
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
};
|
|
1924
|
+
AnthropicComputer20251124 = class _AnthropicComputer20251124 extends AnthropicComputer {
|
|
1925
|
+
static TOOL_TYPE = "computer_20251124";
|
|
1926
|
+
static BETA = "computer-use-2025-11-24";
|
|
1927
|
+
static MAX_LONG_EDGE = 1568;
|
|
1928
|
+
static MAX_PIXELS = 115e4;
|
|
1929
|
+
static fits(width, height) {
|
|
1930
|
+
return Math.max(width, height) <= this.MAX_LONG_EDGE && width * height <= this.MAX_PIXELS;
|
|
1931
|
+
}
|
|
1932
|
+
tool() {
|
|
1933
|
+
return {
|
|
1934
|
+
type: _AnthropicComputer20251124.TOOL_TYPE,
|
|
1935
|
+
name: AnthropicComputer.TOOLSET,
|
|
1936
|
+
display_width_px: this.display.width,
|
|
1937
|
+
display_height_px: this.display.height,
|
|
1938
|
+
enable_zoom: true
|
|
1939
|
+
};
|
|
1940
|
+
}
|
|
1941
|
+
owns(block) {
|
|
1942
|
+
return readField(block, "type") === "tool_use" && readField(block, "name") === AnthropicComputer.TOOLSET;
|
|
1943
|
+
}
|
|
1944
|
+
member(block) {
|
|
1945
|
+
const { action, ...payload } = readField(block, "input") ?? {};
|
|
1946
|
+
return [String(action ?? ""), payload];
|
|
1947
|
+
}
|
|
1948
|
+
envelope(block, content, isError = false) {
|
|
1949
|
+
const { toolset_name: _dropped, ...rest } = super.envelope(
|
|
1950
|
+
block,
|
|
1951
|
+
content,
|
|
1952
|
+
isError
|
|
1953
|
+
);
|
|
1954
|
+
return rest;
|
|
1955
|
+
}
|
|
1956
|
+
};
|
|
1957
|
+
NativeComputer.register("anthropic", AnthropicComputer);
|
|
1958
|
+
NativeComputer.register(
|
|
1959
|
+
"anthropic-computer-20251124",
|
|
1960
|
+
AnthropicComputer20251124
|
|
1961
|
+
);
|
|
1962
|
+
}
|
|
1963
|
+
});
|
|
1964
|
+
|
|
1965
|
+
// src/worlds/nativeComputer/openai.ts
|
|
1966
|
+
function safetyCheck(raw) {
|
|
1967
|
+
const check = { id: String(readField(raw, "id") ?? "") };
|
|
1968
|
+
const code = readField(raw, "code");
|
|
1969
|
+
const message = readField(raw, "message");
|
|
1970
|
+
if (code !== void 0) check.code = String(code);
|
|
1971
|
+
if (message !== void 0) check.message = String(message);
|
|
1972
|
+
return check;
|
|
1973
|
+
}
|
|
1974
|
+
function dataUrl(png) {
|
|
1975
|
+
return `data:image/png;base64,${png.toString("base64")}`;
|
|
1976
|
+
}
|
|
1977
|
+
function xy(raw) {
|
|
1978
|
+
return {
|
|
1979
|
+
x: toInt(readField(raw, "x") ?? 0),
|
|
1980
|
+
y: toInt(readField(raw, "y") ?? 0)
|
|
1981
|
+
};
|
|
1982
|
+
}
|
|
1983
|
+
function held(raw) {
|
|
1984
|
+
return modifierKeys(readField(raw, "keys"));
|
|
1985
|
+
}
|
|
1986
|
+
var WAIT_SECONDS, BUTTONS, HISTORY_BUTTONS, PendingSafetyChecks, ACTIONS, OpenAIComputer, OpenAIPreviewComputer;
|
|
1987
|
+
var init_openai = __esm({
|
|
1988
|
+
"src/worlds/nativeComputer/openai.ts"() {
|
|
1989
|
+
"use strict";
|
|
1990
|
+
init_actions();
|
|
1991
|
+
init_base();
|
|
1992
|
+
init_keys();
|
|
1993
|
+
WAIT_SECONDS = 1;
|
|
1994
|
+
BUTTONS = {
|
|
1995
|
+
left: "left",
|
|
1996
|
+
right: "right",
|
|
1997
|
+
wheel: "middle",
|
|
1998
|
+
middle: "middle"
|
|
1999
|
+
};
|
|
2000
|
+
HISTORY_BUTTONS = /* @__PURE__ */ new Set(["back", "forward"]);
|
|
2001
|
+
PendingSafetyChecks = class extends Error {
|
|
2002
|
+
constructor(callId, checks) {
|
|
2003
|
+
const listed = checks.map((c) => `${c.code ?? "check"}: ${c.message ?? ""}`.trim()).join("; ");
|
|
2004
|
+
super(
|
|
2005
|
+
`computer_call ${callId} needs ${checks.length} safety check(s) acknowledged: ${listed}`
|
|
2006
|
+
);
|
|
2007
|
+
this.callId = callId;
|
|
2008
|
+
this.checks = checks;
|
|
2009
|
+
this.name = "PendingSafetyChecks";
|
|
2010
|
+
}
|
|
2011
|
+
callId;
|
|
2012
|
+
checks;
|
|
2013
|
+
};
|
|
2014
|
+
ACTIONS = {
|
|
2015
|
+
click: (raw) => {
|
|
2016
|
+
const button = String(readField(raw, "button") ?? "left");
|
|
2017
|
+
if (HISTORY_BUTTONS.has(button))
|
|
2018
|
+
return new ComputerAction("history", {
|
|
2019
|
+
direction: button
|
|
2020
|
+
});
|
|
2021
|
+
if (!Object.hasOwn(BUTTONS, button))
|
|
2022
|
+
throw new Error(`unknown mouse button: ${button}`);
|
|
2023
|
+
return new ComputerAction("click", {
|
|
2024
|
+
...xy(raw),
|
|
2025
|
+
button: BUTTONS[button],
|
|
2026
|
+
count: 1,
|
|
2027
|
+
modifiers: held(raw)
|
|
2028
|
+
});
|
|
2029
|
+
},
|
|
2030
|
+
double_click: (raw) => new ComputerAction("click", {
|
|
2031
|
+
...xy(raw),
|
|
2032
|
+
button: "left",
|
|
2033
|
+
count: 2,
|
|
2034
|
+
modifiers: held(raw)
|
|
2035
|
+
}),
|
|
2036
|
+
drag: (raw) => new ComputerAction("drag", {
|
|
2037
|
+
path: (readField(raw, "path") ?? []).map(
|
|
2038
|
+
(p) => [toInt(readField(p, "x")), toInt(readField(p, "y"))]
|
|
2039
|
+
),
|
|
2040
|
+
modifiers: held(raw)
|
|
2041
|
+
}),
|
|
2042
|
+
keypress: (raw) => new ComputerAction("key", {
|
|
2043
|
+
keys: [
|
|
2044
|
+
...KeyChord.fromKeys(readField(raw, "keys") ?? []).keys
|
|
2045
|
+
],
|
|
2046
|
+
repeat: 1
|
|
2047
|
+
}),
|
|
2048
|
+
move: (raw) => new ComputerAction("move", { ...xy(raw), modifiers: held(raw) }),
|
|
2049
|
+
scroll: (raw) => new ComputerAction("scroll", {
|
|
2050
|
+
...xy(raw),
|
|
2051
|
+
dx: toInt(readField(raw, "scroll_x", "scrollX") ?? 0),
|
|
2052
|
+
dy: toInt(readField(raw, "scroll_y", "scrollY") ?? 0),
|
|
2053
|
+
modifiers: held(raw)
|
|
2054
|
+
}),
|
|
2055
|
+
type: (raw) => new ComputerAction("type", { text: String(readField(raw, "text") ?? "") }),
|
|
2056
|
+
wait: () => new ComputerAction("wait", { seconds: WAIT_SECONDS }),
|
|
2057
|
+
screenshot: () => new ComputerAction("screenshot")
|
|
2058
|
+
};
|
|
2059
|
+
OpenAIComputer = class _OpenAIComputer extends NativeComputer {
|
|
2060
|
+
tool() {
|
|
2061
|
+
return { type: "computer" };
|
|
2062
|
+
}
|
|
2063
|
+
owns(item) {
|
|
2064
|
+
return readField(item, "type") === "computer_call";
|
|
2065
|
+
}
|
|
2066
|
+
parse(raw) {
|
|
2067
|
+
const kind = String(readField(raw, "type"));
|
|
2068
|
+
const parser = Object.hasOwn(ACTIONS, kind) ? ACTIONS[kind] : void 0;
|
|
2069
|
+
if (!parser) throw new Error(`unknown computer action: ${kind}`);
|
|
2070
|
+
return parser(raw);
|
|
2071
|
+
}
|
|
2072
|
+
static actionsOf(call) {
|
|
2073
|
+
const batch = readField(call, "actions");
|
|
2074
|
+
if (Array.isArray(batch)) return batch;
|
|
2075
|
+
const single = readField(call, "action");
|
|
2076
|
+
return single === void 0 ? [] : [single];
|
|
2077
|
+
}
|
|
2078
|
+
/** Run a `computer_call`'s actions and return its `computer_call_output`.
|
|
2079
|
+
* Throws `PendingSafetyChecks` (before anything runs) while a check the
|
|
2080
|
+
* model raised is not in `acknowledged`. */
|
|
2081
|
+
async execute(call, acknowledged = []) {
|
|
2082
|
+
const callId = String(readField(call, "call_id", "callId"));
|
|
2083
|
+
const checks = (readField(
|
|
2084
|
+
call,
|
|
2085
|
+
"pending_safety_checks",
|
|
2086
|
+
"pendingSafetyChecks"
|
|
2087
|
+
) ?? []).map(safetyCheck);
|
|
2088
|
+
const png = await this.runCall(
|
|
2089
|
+
callId,
|
|
2090
|
+
_OpenAIComputer.actionsOf(call),
|
|
2091
|
+
checks,
|
|
2092
|
+
acknowledged
|
|
2093
|
+
);
|
|
2094
|
+
return {
|
|
2095
|
+
type: "computer_call_output",
|
|
2096
|
+
call_id: callId,
|
|
2097
|
+
output: {
|
|
2098
|
+
type: "computer_screenshot",
|
|
2099
|
+
image_url: dataUrl(png),
|
|
2100
|
+
detail: "original"
|
|
2101
|
+
},
|
|
2102
|
+
...checks.length > 0 ? { acknowledged_safety_checks: checks } : {}
|
|
2103
|
+
};
|
|
2104
|
+
}
|
|
2105
|
+
/** For `openai.tools.computer({ ...computer.aiSdk() })`: `execute` runs a
|
|
2106
|
+
* call's `actions` and returns the screenshot output. A call with pending
|
|
2107
|
+
* safety checks asks for approval first (`needsApproval`), so the AI SDK's
|
|
2108
|
+
* approval flow puts them in front of a person; once approved, `execute`
|
|
2109
|
+
* acknowledges them. */
|
|
2110
|
+
aiSdk() {
|
|
2111
|
+
return {
|
|
2112
|
+
needsApproval: (input) => (input.pendingSafetyChecks ?? []).length > 0,
|
|
2113
|
+
execute: (input) => this.serial(async () => {
|
|
2114
|
+
const checks = (input.pendingSafetyChecks ?? []).map(safetyCheck);
|
|
2115
|
+
const png = await this.runCall(
|
|
2116
|
+
"ai-sdk",
|
|
2117
|
+
input.actions ?? [],
|
|
2118
|
+
checks,
|
|
2119
|
+
checks
|
|
2120
|
+
);
|
|
2121
|
+
return {
|
|
2122
|
+
output: { type: "computer_screenshot", imageUrl: dataUrl(png) },
|
|
2123
|
+
...checks.length > 0 ? { acknowledgedSafetyChecks: checks } : {}
|
|
2124
|
+
};
|
|
2125
|
+
})
|
|
2126
|
+
};
|
|
2127
|
+
}
|
|
2128
|
+
/** The batch's actions, run after the safety checks clear; the screen after them. */
|
|
2129
|
+
async runCall(callId, rawActions, checks, acknowledged) {
|
|
2130
|
+
const cleared = new Set(acknowledged.map((c) => safetyCheck(c).id));
|
|
2131
|
+
const waiting = checks.filter((c) => !c.id || !cleared.has(c.id));
|
|
2132
|
+
if (waiting.length > 0) throw new PendingSafetyChecks(callId, waiting);
|
|
2133
|
+
const actions = rawActions.map((raw) => this.parse(raw));
|
|
2134
|
+
const results = await this.performAll(actions);
|
|
2135
|
+
const last = actions.at(-1);
|
|
2136
|
+
if (last?.name === "screenshot")
|
|
2137
|
+
return results.at(-1)?.image ?? Buffer.alloc(0);
|
|
2138
|
+
return this.screenshot();
|
|
2139
|
+
}
|
|
2140
|
+
};
|
|
2141
|
+
OpenAIPreviewComputer = class extends OpenAIComputer {
|
|
2142
|
+
tool() {
|
|
2143
|
+
return {
|
|
2144
|
+
type: "computer_use_preview",
|
|
2145
|
+
display_width: this.display.width,
|
|
2146
|
+
display_height: this.display.height,
|
|
2147
|
+
environment: "browser"
|
|
2148
|
+
};
|
|
2149
|
+
}
|
|
2150
|
+
};
|
|
2151
|
+
NativeComputer.register("openai", OpenAIComputer);
|
|
2152
|
+
NativeComputer.register("openai-preview", OpenAIPreviewComputer);
|
|
2153
|
+
}
|
|
2154
|
+
});
|
|
2155
|
+
|
|
2156
|
+
// src/worlds/nativeComputer/index.ts
|
|
2157
|
+
var init_nativeComputer = __esm({
|
|
2158
|
+
"src/worlds/nativeComputer/index.ts"() {
|
|
2159
|
+
"use strict";
|
|
2160
|
+
init_actions();
|
|
2161
|
+
init_base();
|
|
2162
|
+
init_display();
|
|
2163
|
+
init_keys();
|
|
2164
|
+
init_screen();
|
|
2165
|
+
init_trace();
|
|
2166
|
+
init_anthropic();
|
|
2167
|
+
init_openai();
|
|
901
2168
|
}
|
|
902
2169
|
});
|
|
903
2170
|
|
|
@@ -954,6 +2221,75 @@ var init_sessionContract = __esm({
|
|
|
954
2221
|
}
|
|
955
2222
|
});
|
|
956
2223
|
|
|
2224
|
+
// src/tracing/session.ts
|
|
2225
|
+
var session_exports = {};
|
|
2226
|
+
__export(session_exports, {
|
|
2227
|
+
SESSION_ID_ATTRIBUTE: () => SESSION_ID_ATTRIBUTE,
|
|
2228
|
+
SessionSpanProcessor: () => SessionSpanProcessor,
|
|
2229
|
+
WORLD_SESSION_ID_ATTRIBUTE: () => WORLD_SESSION_ID_ATTRIBUTE,
|
|
2230
|
+
getAmbientSessionId: () => getAmbientSessionId,
|
|
2231
|
+
getCurrentWorldSessionId: () => getCurrentWorldSessionId,
|
|
2232
|
+
withSession: () => withSession,
|
|
2233
|
+
withWorldSession: () => withWorldSession
|
|
2234
|
+
});
|
|
2235
|
+
function getAmbientSessionId() {
|
|
2236
|
+
return currentSessionStorage.getStore();
|
|
2237
|
+
}
|
|
2238
|
+
function getCurrentWorldSessionId() {
|
|
2239
|
+
return currentWorldSessionStorage.getStore();
|
|
2240
|
+
}
|
|
2241
|
+
function runIn(storage, value, fn) {
|
|
2242
|
+
return new Promise((resolve7, reject) => {
|
|
2243
|
+
storage.run(value, () => {
|
|
2244
|
+
Promise.resolve().then(fn).then(resolve7, reject);
|
|
2245
|
+
});
|
|
2246
|
+
});
|
|
2247
|
+
}
|
|
2248
|
+
function withSession(sessionId, fn) {
|
|
2249
|
+
return runIn(currentSessionStorage, sessionId, fn);
|
|
2250
|
+
}
|
|
2251
|
+
function withWorldSession(worldSessionId, fn) {
|
|
2252
|
+
return runIn(
|
|
2253
|
+
currentWorldSessionStorage,
|
|
2254
|
+
worldSessionId,
|
|
2255
|
+
() => withSession(worldSessionId, fn)
|
|
2256
|
+
);
|
|
2257
|
+
}
|
|
2258
|
+
var import_async_hooks, SESSION_ID_ATTRIBUTE, WORLD_SESSION_ID_ATTRIBUTE, processStorage, currentSessionStorage, currentWorldSessionStorage, SessionSpanProcessor;
|
|
2259
|
+
var init_session = __esm({
|
|
2260
|
+
"src/tracing/session.ts"() {
|
|
2261
|
+
"use strict";
|
|
2262
|
+
import_async_hooks = require("async_hooks");
|
|
2263
|
+
SESSION_ID_ATTRIBUTE = "gateway.session.id";
|
|
2264
|
+
WORLD_SESSION_ID_ATTRIBUTE = "gateway.trace.metadata.world_session_id";
|
|
2265
|
+
processStorage = (name) => {
|
|
2266
|
+
const key = /* @__PURE__ */ Symbol.for(`@withgateway/sdk/${name}`);
|
|
2267
|
+
const slots = globalThis;
|
|
2268
|
+
slots[key] ??= new import_async_hooks.AsyncLocalStorage();
|
|
2269
|
+
return slots[key];
|
|
2270
|
+
};
|
|
2271
|
+
currentSessionStorage = processStorage("session-storage");
|
|
2272
|
+
currentWorldSessionStorage = processStorage("world-session-storage");
|
|
2273
|
+
SessionSpanProcessor = class {
|
|
2274
|
+
onStart(span, _parentContext) {
|
|
2275
|
+
const worldSessionId = getCurrentWorldSessionId();
|
|
2276
|
+
if (worldSessionId)
|
|
2277
|
+
span.setAttribute(WORLD_SESSION_ID_ATTRIBUTE, worldSessionId);
|
|
2278
|
+
const sessionId = getAmbientSessionId();
|
|
2279
|
+
if (!sessionId || span.attributes?.[SESSION_ID_ATTRIBUTE] !== void 0)
|
|
2280
|
+
return;
|
|
2281
|
+
span.setAttribute(SESSION_ID_ATTRIBUTE, sessionId);
|
|
2282
|
+
}
|
|
2283
|
+
onEnd(_span) {
|
|
2284
|
+
}
|
|
2285
|
+
async shutdown() {
|
|
2286
|
+
}
|
|
2287
|
+
async forceFlush() {
|
|
2288
|
+
}
|
|
2289
|
+
};
|
|
2290
|
+
}
|
|
2291
|
+
});
|
|
2292
|
+
|
|
957
2293
|
// src/worlds/taskRef.ts
|
|
958
2294
|
var isTaskIdRef, isTaskSpec, taskLabel, assertTaskRef;
|
|
959
2295
|
var init_taskRef = __esm({
|
|
@@ -978,8 +2314,8 @@ var init_taskRef = __esm({
|
|
|
978
2314
|
});
|
|
979
2315
|
|
|
980
2316
|
// src/worlds/session.ts
|
|
981
|
-
var
|
|
982
|
-
__export(
|
|
2317
|
+
var session_exports2 = {};
|
|
2318
|
+
__export(session_exports2, {
|
|
983
2319
|
WorldSession: () => WorldSession,
|
|
984
2320
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
985
2321
|
WorldSessionTimeout: () => WorldSessionTimeout,
|
|
@@ -1032,7 +2368,7 @@ function schemaFromSignature(spec) {
|
|
|
1032
2368
|
};
|
|
1033
2369
|
const inside = /\(([\s\S]*)\)\s*$/.exec(spec.signature.trim())?.[1] ?? "";
|
|
1034
2370
|
const properties = {};
|
|
1035
|
-
const
|
|
2371
|
+
const required2 = [];
|
|
1036
2372
|
const params = [];
|
|
1037
2373
|
let depth = 0;
|
|
1038
2374
|
let current = "";
|
|
@@ -1053,7 +2389,7 @@ function schemaFromSignature(spec) {
|
|
|
1053
2389
|
if (!name) continue;
|
|
1054
2390
|
if (eq === -1) {
|
|
1055
2391
|
properties[name] = { type: "string" };
|
|
1056
|
-
|
|
2392
|
+
required2.push(name);
|
|
1057
2393
|
continue;
|
|
1058
2394
|
}
|
|
1059
2395
|
const value = param.slice(eq + 1).trim();
|
|
@@ -1067,7 +2403,7 @@ function schemaFromSignature(spec) {
|
|
|
1067
2403
|
function: {
|
|
1068
2404
|
name: modelToolName(spec.name),
|
|
1069
2405
|
description: spec.doc ?? spec.name,
|
|
1070
|
-
parameters: { type: "object", properties, required }
|
|
2406
|
+
parameters: { type: "object", properties, required: required2 }
|
|
1071
2407
|
}
|
|
1072
2408
|
};
|
|
1073
2409
|
}
|
|
@@ -1136,13 +2472,16 @@ async function runSessions(opts) {
|
|
|
1136
2472
|
task = taskLabel(taskRef, session.taskInfo);
|
|
1137
2473
|
await session.ready();
|
|
1138
2474
|
const toolkit = await session.toolkit();
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
2475
|
+
const live = session;
|
|
2476
|
+
await live.withTraceContext(
|
|
2477
|
+
() => opts.agent({
|
|
2478
|
+
session: live,
|
|
2479
|
+
toolkit,
|
|
2480
|
+
instruction: live.instruction ?? (isTaskSpec(taskRef) ? taskRef.instruction : task),
|
|
2481
|
+
task,
|
|
2482
|
+
taskRef
|
|
2483
|
+
})
|
|
2484
|
+
);
|
|
1146
2485
|
const graded = await session.grade();
|
|
1147
2486
|
const result = {
|
|
1148
2487
|
task,
|
|
@@ -1179,14 +2518,16 @@ async function runSessions(opts) {
|
|
|
1179
2518
|
passed: failed === 0 && (opts.failUnder === void 0 || mean >= opts.failUnder)
|
|
1180
2519
|
};
|
|
1181
2520
|
}
|
|
1182
|
-
var
|
|
1183
|
-
var
|
|
2521
|
+
var import_node_crypto2, READY_TIMEOUT_MS, READY_POLL_MS, CALL_TIMEOUT_MS, CALL_POLL_MS, JUDGED_GRADE_TIMEOUT_MS, JUDGED_GRADE_POLL_MS, EXPORT_PAGE, sleep, modelToolName, WorldSessionTimeout, WorldSessionCallError, WorldSession, OPEN_SESSION_OPTION_KEYS, isOpenSessionOptions;
|
|
2522
|
+
var init_session2 = __esm({
|
|
1184
2523
|
"src/worlds/session.ts"() {
|
|
1185
2524
|
"use strict";
|
|
1186
|
-
|
|
2525
|
+
import_node_crypto2 = require("crypto");
|
|
1187
2526
|
init_worlds();
|
|
1188
2527
|
init_browser();
|
|
2528
|
+
init_nativeComputer();
|
|
1189
2529
|
init_sessionContract();
|
|
2530
|
+
init_session();
|
|
1190
2531
|
init_taskRef();
|
|
1191
2532
|
init_taskRef();
|
|
1192
2533
|
READY_TIMEOUT_MS = 10 * 6e4;
|
|
@@ -1320,7 +2661,7 @@ var init_session = __esm({
|
|
|
1320
2661
|
/** The reporter `browser()` uses; exposed for a page you drive yourself. */
|
|
1321
2662
|
browserRecorder(agentId) {
|
|
1322
2663
|
const path12 = `/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/browser-events`;
|
|
1323
|
-
const id = agentId ?? process.env.GATEWAY_AGENT_ID ?? `agent-${(0,
|
|
2664
|
+
const id = agentId ?? process.env.GATEWAY_AGENT_ID ?? `agent-${(0, import_node_crypto2.randomUUID)().replace(/-/g, "").slice(0, 8)}`;
|
|
1324
2665
|
return new BrowserActionRecorder(
|
|
1325
2666
|
async (events) => {
|
|
1326
2667
|
await apiRequest(this.options, "POST", path12, { events });
|
|
@@ -1340,6 +2681,12 @@ var init_session = __esm({
|
|
|
1340
2681
|
computerUseTools(browser) {
|
|
1341
2682
|
return computerUseToolkit(browser);
|
|
1342
2683
|
}
|
|
2684
|
+
/** The browser as a provider's own pixel-based computer-use tool: `anthropic`
|
|
2685
|
+
* (`computer_toolset_20260801`), `openai` (Responses `computer`),
|
|
2686
|
+
* `anthropic-computer-20251124` or `openai-preview`. See `nativeComputer/`. */
|
|
2687
|
+
nativeComputer(browser, provider = "anthropic", options = {}) {
|
|
2688
|
+
return NativeComputer.forProvider(provider, browser, options);
|
|
2689
|
+
}
|
|
1343
2690
|
/** The session's latest platform state (one request, no waiting). */
|
|
1344
2691
|
async status() {
|
|
1345
2692
|
const fresh = await apiRequest(
|
|
@@ -1574,6 +2921,21 @@ var init_session = __esm({
|
|
|
1574
2921
|
{ keepWarm: opts.keepWarm ?? false }
|
|
1575
2922
|
);
|
|
1576
2923
|
}
|
|
2924
|
+
/**
|
|
2925
|
+
* Run `fn` as work inside this session: spans it records take `sessionId`
|
|
2926
|
+
* as their session id and carry `world_session_id` trace metadata, so the
|
|
2927
|
+
* agent's traces land in the same session as the platform's traces of this
|
|
2928
|
+
* session's tool calls. A `withSession()` block inside still wins for the
|
|
2929
|
+
* session id. No effect before `tracing.init()`. `runSessions` wraps each
|
|
2930
|
+
* agent call in it.
|
|
2931
|
+
*
|
|
2932
|
+
* ```typescript
|
|
2933
|
+
* await session.withTraceContext(() => myAgent(toolkit, session.instruction));
|
|
2934
|
+
* ```
|
|
2935
|
+
*/
|
|
2936
|
+
withTraceContext(fn) {
|
|
2937
|
+
return withWorldSession(this.sessionId, fn);
|
|
2938
|
+
}
|
|
1577
2939
|
};
|
|
1578
2940
|
OPEN_SESSION_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
1579
2941
|
"task",
|
|
@@ -1695,6 +3057,28 @@ var init_tasks = __esm({
|
|
|
1695
3057
|
}
|
|
1696
3058
|
});
|
|
1697
3059
|
|
|
3060
|
+
// src/worlds/surfaceDescriptor.ts
|
|
3061
|
+
function surfaceDescriptor(s) {
|
|
3062
|
+
return {
|
|
3063
|
+
surfaces: surfaceKinds(s),
|
|
3064
|
+
...s.api ? { api: { url: s.api.url, ...s.api.token ? { token: s.api.token } : {} } } : {},
|
|
3065
|
+
...s.ui ? { ui: { url: s.ui.url, entry: uiEntryUrl(s.ui), apiPath: s.ui.apiPath ?? null } } : {},
|
|
3066
|
+
...s.browser ? {
|
|
3067
|
+
browser: {
|
|
3068
|
+
wsUrl: s.browser.wsUrl,
|
|
3069
|
+
viewport: s.browser.viewport,
|
|
3070
|
+
...s.browser.tier ? { tier: s.browser.tier } : {}
|
|
3071
|
+
}
|
|
3072
|
+
} : {}
|
|
3073
|
+
};
|
|
3074
|
+
}
|
|
3075
|
+
var init_surfaceDescriptor = __esm({
|
|
3076
|
+
"src/worlds/surfaceDescriptor.ts"() {
|
|
3077
|
+
"use strict";
|
|
3078
|
+
init_browser();
|
|
3079
|
+
}
|
|
3080
|
+
});
|
|
3081
|
+
|
|
1698
3082
|
// src/worlds/taskSessions.ts
|
|
1699
3083
|
function aggregateTaskGrade(worlds) {
|
|
1700
3084
|
const rewards = {};
|
|
@@ -1723,7 +3107,11 @@ function fromResponse(answer, options) {
|
|
|
1723
3107
|
const worlds = {};
|
|
1724
3108
|
for (const [alias, state2] of Object.entries(answer.sessions)) {
|
|
1725
3109
|
sessions[alias] = new WorldSession(state2.sessionId, state2, options);
|
|
1726
|
-
worlds[alias] = {
|
|
3110
|
+
worlds[alias] = {
|
|
3111
|
+
slug: state2.slug,
|
|
3112
|
+
ref: state2.ref,
|
|
3113
|
+
private: state2.private ?? null
|
|
3114
|
+
};
|
|
1727
3115
|
}
|
|
1728
3116
|
return new TaskSessions(
|
|
1729
3117
|
answer.taskId,
|
|
@@ -1797,6 +3185,7 @@ async function attachTask(taskId, options = {}) {
|
|
|
1797
3185
|
{
|
|
1798
3186
|
slug: row.slug ?? "",
|
|
1799
3187
|
ref: null,
|
|
3188
|
+
private: null,
|
|
1800
3189
|
versionId: row.versionId,
|
|
1801
3190
|
sessionId: row.sessionId,
|
|
1802
3191
|
ready: row.ready,
|
|
@@ -1826,7 +3215,7 @@ async function attachManifest(manifest, options = {}) {
|
|
|
1826
3215
|
Object.fromEntries(
|
|
1827
3216
|
Object.entries(manifest.sessions).map(([alias, entry]) => [
|
|
1828
3217
|
alias,
|
|
1829
|
-
{ slug: entry.slug, ref: entry.ref }
|
|
3218
|
+
{ slug: entry.slug, ref: entry.ref, private: entry.private ?? null }
|
|
1830
3219
|
])
|
|
1831
3220
|
)
|
|
1832
3221
|
);
|
|
@@ -1840,28 +3229,19 @@ var init_taskSessions = __esm({
|
|
|
1840
3229
|
"use strict";
|
|
1841
3230
|
init_worlds();
|
|
1842
3231
|
init_browser();
|
|
1843
|
-
|
|
3232
|
+
init_surfaceDescriptor();
|
|
3233
|
+
init_session2();
|
|
1844
3234
|
TASK_SESSIONS = "/api/public/world-task-sessions";
|
|
1845
3235
|
VERIFIER_REWARD_PREFIX = "x.";
|
|
1846
3236
|
manifestSession = (s, state2, world) => ({
|
|
1847
3237
|
slug: world.slug,
|
|
1848
3238
|
ref: world.ref,
|
|
3239
|
+
private: world.private,
|
|
1849
3240
|
versionId: state2.versionId,
|
|
1850
3241
|
sessionId: state2.sessionId,
|
|
1851
3242
|
ready: state2.ready,
|
|
1852
3243
|
state: state2.state,
|
|
1853
|
-
|
|
1854
|
-
...s.api ? {
|
|
1855
|
-
api: { url: s.api.url, ...s.api.token ? { token: s.api.token } : {} }
|
|
1856
|
-
} : {},
|
|
1857
|
-
...s.ui ? {
|
|
1858
|
-
ui: {
|
|
1859
|
-
url: s.ui.url,
|
|
1860
|
-
entry: uiEntryUrl(s.ui),
|
|
1861
|
-
apiPath: s.ui.apiPath ?? null
|
|
1862
|
-
}
|
|
1863
|
-
} : {},
|
|
1864
|
-
...s.browser ? { browser: { wsUrl: s.browser.wsUrl, viewport: s.browser.viewport } } : {}
|
|
3244
|
+
...surfaceDescriptor(s)
|
|
1865
3245
|
});
|
|
1866
3246
|
TaskSessions = class {
|
|
1867
3247
|
constructor(taskId, taskVersion, name, instruction, sessions, worlds, hash = null) {
|
|
@@ -1880,10 +3260,10 @@ var init_taskSessions = __esm({
|
|
|
1880
3260
|
sessions;
|
|
1881
3261
|
worlds;
|
|
1882
3262
|
hash;
|
|
1883
|
-
/** This alias's
|
|
1884
|
-
*
|
|
3263
|
+
/** This alias's world as recorded at open/attach — what a `TaskRun`
|
|
3264
|
+
* filing needs to name, without exposing the whole map. */
|
|
1885
3265
|
worldRef(alias) {
|
|
1886
|
-
return this.worlds[alias] ?? { slug: "", ref: null };
|
|
3266
|
+
return this.worlds[alias] ?? { slug: "", ref: null, private: null };
|
|
1887
3267
|
}
|
|
1888
3268
|
/** The aliases, in the spec's order. */
|
|
1889
3269
|
get aliases() {
|
|
@@ -2040,6 +3420,49 @@ var init_evals = __esm({
|
|
|
2040
3420
|
}
|
|
2041
3421
|
});
|
|
2042
3422
|
|
|
3423
|
+
// src/tracing/prerequisites.ts
|
|
3424
|
+
function getEnv(key) {
|
|
3425
|
+
const value = process.env[key];
|
|
3426
|
+
return value ? value : void 0;
|
|
3427
|
+
}
|
|
3428
|
+
function isGatewayConfigured() {
|
|
3429
|
+
return !!(getEnv(GATEWAY_ENV.HOST) && getEnv(GATEWAY_ENV.PUBLIC_KEY) && getEnv(GATEWAY_ENV.SECRET_KEY));
|
|
3430
|
+
}
|
|
3431
|
+
var GATEWAY_ENV, OPENTELEMETRY_PEERS, MODULE_NOT_FOUND, OpenTelemetryMissing;
|
|
3432
|
+
var init_prerequisites = __esm({
|
|
3433
|
+
"src/tracing/prerequisites.ts"() {
|
|
3434
|
+
"use strict";
|
|
3435
|
+
GATEWAY_ENV = {
|
|
3436
|
+
HOST: "GATEWAY_HOST",
|
|
3437
|
+
PUBLIC_KEY: "GATEWAY_PUBLIC_KEY",
|
|
3438
|
+
SECRET_KEY: "GATEWAY_SECRET_KEY",
|
|
3439
|
+
ENDPOINT: "GATEWAY_OTLP_ENDPOINT"
|
|
3440
|
+
};
|
|
3441
|
+
OPENTELEMETRY_PEERS = [
|
|
3442
|
+
"@opentelemetry/api",
|
|
3443
|
+
"@opentelemetry/exporter-trace-otlp-http",
|
|
3444
|
+
"@opentelemetry/resources",
|
|
3445
|
+
"@opentelemetry/sdk-trace-base",
|
|
3446
|
+
"@opentelemetry/sdk-trace-node"
|
|
3447
|
+
];
|
|
3448
|
+
MODULE_NOT_FOUND = /* @__PURE__ */ new Set(["MODULE_NOT_FOUND", "ERR_MODULE_NOT_FOUND"]);
|
|
3449
|
+
OpenTelemetryMissing = class _OpenTelemetryMissing extends Error {
|
|
3450
|
+
constructor() {
|
|
3451
|
+
super(
|
|
3452
|
+
`OpenTelemetry packages not found. Install them with:
|
|
3453
|
+
npm install ${OPENTELEMETRY_PEERS.join(" ")}`
|
|
3454
|
+
);
|
|
3455
|
+
this.name = "OpenTelemetryMissing";
|
|
3456
|
+
}
|
|
3457
|
+
static explains(error) {
|
|
3458
|
+
if (error instanceof _OpenTelemetryMissing) return true;
|
|
3459
|
+
const { code, message } = error ?? {};
|
|
3460
|
+
return MODULE_NOT_FOUND.has(String(code)) && String(message).includes("@opentelemetry/");
|
|
3461
|
+
}
|
|
3462
|
+
};
|
|
3463
|
+
}
|
|
3464
|
+
});
|
|
3465
|
+
|
|
2043
3466
|
// src/users/index.ts
|
|
2044
3467
|
function parseEvent(payload) {
|
|
2045
3468
|
return {
|
|
@@ -2253,15 +3676,15 @@ function resolveUserId() {
|
|
|
2253
3676
|
const envUser = process.env.GATEWAY_USER_ID?.trim();
|
|
2254
3677
|
return envUser ? envUser : void 0;
|
|
2255
3678
|
}
|
|
2256
|
-
var
|
|
3679
|
+
var import_async_hooks2, import_api, USER_ID_ATTRIBUTE, currentUserStorage, IdentitySpanProcessor;
|
|
2257
3680
|
var init_identity = __esm({
|
|
2258
3681
|
"src/tracing/identity.ts"() {
|
|
2259
3682
|
"use strict";
|
|
2260
|
-
|
|
3683
|
+
import_async_hooks2 = require("async_hooks");
|
|
2261
3684
|
import_api = require("@opentelemetry/api");
|
|
2262
3685
|
init_users();
|
|
2263
3686
|
USER_ID_ATTRIBUTE = "gateway.user.id";
|
|
2264
|
-
currentUserStorage = new
|
|
3687
|
+
currentUserStorage = new import_async_hooks2.AsyncLocalStorage();
|
|
2265
3688
|
IdentitySpanProcessor = class {
|
|
2266
3689
|
onStart(span, _parentContext) {
|
|
2267
3690
|
const userId = resolveUserId();
|
|
@@ -2279,43 +3702,224 @@ var init_identity = __esm({
|
|
|
2279
3702
|
}
|
|
2280
3703
|
});
|
|
2281
3704
|
|
|
2282
|
-
// src/tracing/
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
}
|
|
2290
|
-
|
|
2291
|
-
return
|
|
3705
|
+
// src/tracing/secrets.ts
|
|
3706
|
+
function jsonOrUndefined(text2) {
|
|
3707
|
+
let parsed;
|
|
3708
|
+
try {
|
|
3709
|
+
parsed = JSON.parse(text2);
|
|
3710
|
+
} catch {
|
|
3711
|
+
return void 0;
|
|
3712
|
+
}
|
|
3713
|
+
if (typeof parsed === "string") return parsed;
|
|
3714
|
+
return parsed !== null && typeof parsed === "object" ? parsed : void 0;
|
|
2292
3715
|
}
|
|
2293
|
-
function
|
|
2294
|
-
return
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
3716
|
+
function encodings(value) {
|
|
3717
|
+
return [value, percentEncoded(value), JSON.stringify(value).slice(1, -1)];
|
|
3718
|
+
}
|
|
3719
|
+
function percentEncoded(value) {
|
|
3720
|
+
try {
|
|
3721
|
+
return encodeURIComponent(value);
|
|
3722
|
+
} catch {
|
|
3723
|
+
return value;
|
|
3724
|
+
}
|
|
3725
|
+
}
|
|
3726
|
+
function union(sets) {
|
|
3727
|
+
return new Set(sets.flatMap((set) => [...set]));
|
|
3728
|
+
}
|
|
3729
|
+
function leaves(value) {
|
|
3730
|
+
if (typeof value === "string") {
|
|
3731
|
+
return [...value].length >= MIN_SECRET_LENGTH ? /* @__PURE__ */ new Set([value]) : /* @__PURE__ */ new Set();
|
|
3732
|
+
}
|
|
3733
|
+
if (Array.isArray(value)) return union(value.map(leaves));
|
|
3734
|
+
if (value === null || typeof value !== "object") return /* @__PURE__ */ new Set();
|
|
3735
|
+
return union(Object.values(value).map(leaves));
|
|
3736
|
+
}
|
|
3737
|
+
function sameAttributes(before, after) {
|
|
3738
|
+
const keys = Object.keys(before);
|
|
3739
|
+
if (keys.length !== Object.keys(after).length) return false;
|
|
3740
|
+
return keys.every(
|
|
3741
|
+
(key) => before[key] === after[key] || sameArray(before[key], after[key])
|
|
3742
|
+
);
|
|
3743
|
+
}
|
|
3744
|
+
function sameArray(before, after) {
|
|
3745
|
+
if (!Array.isArray(before) || !Array.isArray(after)) return false;
|
|
3746
|
+
return before.length === after.length && before.every((item, i) => item === after[i]);
|
|
3747
|
+
}
|
|
3748
|
+
function scrubbedRead(reads, property) {
|
|
3749
|
+
return typeof property === "string" && property in reads ? reads[property] : void 0;
|
|
3750
|
+
}
|
|
3751
|
+
function viewOf(span, reads) {
|
|
3752
|
+
const view = new Proxy(span, {
|
|
3753
|
+
get(target, property) {
|
|
3754
|
+
const read = scrubbedRead(reads, property);
|
|
3755
|
+
if (read) return read();
|
|
3756
|
+
const value = Reflect.get(target, property, target);
|
|
3757
|
+
if (typeof value !== "function") return value;
|
|
3758
|
+
return (...args) => {
|
|
3759
|
+
const result = value.apply(target, args);
|
|
3760
|
+
return result === target ? view : result;
|
|
3761
|
+
};
|
|
3762
|
+
},
|
|
3763
|
+
getOwnPropertyDescriptor(target, property) {
|
|
3764
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, property);
|
|
3765
|
+
const read = scrubbedRead(reads, property);
|
|
3766
|
+
if (!read || !descriptor || !("value" in descriptor)) return descriptor;
|
|
3767
|
+
return { ...descriptor, value: read() };
|
|
3768
|
+
}
|
|
2298
3769
|
});
|
|
3770
|
+
return view;
|
|
2299
3771
|
}
|
|
2300
|
-
var
|
|
2301
|
-
var
|
|
2302
|
-
"src/tracing/
|
|
3772
|
+
var SECRET_KEYS, REDACTED2, MIN_SECRET_LENGTH, SpanSecrets, SPAN_SECRETS, SecretRedactingSpanProcessor;
|
|
3773
|
+
var init_secrets = __esm({
|
|
3774
|
+
"src/tracing/secrets.ts"() {
|
|
2303
3775
|
"use strict";
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
3776
|
+
SECRET_KEYS = /* @__PURE__ */ new Set([
|
|
3777
|
+
"authorization_token",
|
|
3778
|
+
"authorizationToken"
|
|
3779
|
+
]);
|
|
3780
|
+
REDACTED2 = "[redacted: holds a credential]";
|
|
3781
|
+
MIN_SECRET_LENGTH = 8;
|
|
3782
|
+
SpanSecrets = class {
|
|
3783
|
+
constructor(keys = SECRET_KEYS) {
|
|
3784
|
+
this.keys = keys;
|
|
3785
|
+
}
|
|
3786
|
+
keys;
|
|
3787
|
+
isSecret(key) {
|
|
3788
|
+
return this.keys.has(key);
|
|
3789
|
+
}
|
|
3790
|
+
drops(attribute) {
|
|
3791
|
+
return this.mentions(attribute);
|
|
3792
|
+
}
|
|
3793
|
+
strip(value) {
|
|
3794
|
+
if (typeof value === "string") return this.stripNested(value);
|
|
3795
|
+
if (Array.isArray(value)) return value.map((item) => this.strip(item));
|
|
3796
|
+
if (value === null || typeof value !== "object") return value;
|
|
3797
|
+
return Object.fromEntries(
|
|
3798
|
+
Object.entries(value).filter(([key]) => !this.isSecret(key)).map(([key, item]) => [key, this.strip(item)])
|
|
3799
|
+
);
|
|
3800
|
+
}
|
|
3801
|
+
scrubAttribute(value) {
|
|
3802
|
+
try {
|
|
3803
|
+
return this.scrubbedValue(value);
|
|
3804
|
+
} catch {
|
|
3805
|
+
return Array.isArray(value) ? [REDACTED2] : REDACTED2;
|
|
2312
3806
|
}
|
|
2313
3807
|
}
|
|
2314
|
-
|
|
3808
|
+
scrubbedValue(value) {
|
|
3809
|
+
if (typeof value === "string") return this.scrubbedText(value);
|
|
3810
|
+
if (!Array.isArray(value)) return value;
|
|
3811
|
+
const results = value.map(
|
|
3812
|
+
(item) => typeof item === "string" ? this.cleaned(item) : { text: item, removed: /* @__PURE__ */ new Set() }
|
|
3813
|
+
);
|
|
3814
|
+
const removed = new Set(results.flatMap((r) => [...r.removed]));
|
|
3815
|
+
const scrubbed = results.map((r) => r.text);
|
|
3816
|
+
const withheld = scrubbed.some(
|
|
3817
|
+
(item) => typeof item === "string" && this.carries(item, removed)
|
|
3818
|
+
);
|
|
3819
|
+
return withheld ? [REDACTED2] : scrubbed;
|
|
2315
3820
|
}
|
|
2316
|
-
|
|
3821
|
+
scrubAttributes(attributes) {
|
|
3822
|
+
return Object.fromEntries(
|
|
3823
|
+
Object.entries(attributes).filter(([key]) => !this.drops(key)).map(([key, value]) => [key, this.scrubAttribute(value)])
|
|
3824
|
+
);
|
|
2317
3825
|
}
|
|
2318
|
-
|
|
3826
|
+
mentions(text2) {
|
|
3827
|
+
return [...this.keys].some((key) => text2.includes(key));
|
|
3828
|
+
}
|
|
3829
|
+
scrubbedText(text2) {
|
|
3830
|
+
const { text: cleaned, removed } = this.cleaned(text2);
|
|
3831
|
+
return this.carries(cleaned, removed) ? REDACTED2 : cleaned;
|
|
3832
|
+
}
|
|
3833
|
+
cleaned(text2) {
|
|
3834
|
+
if (!this.mentions(text2)) return { text: text2, removed: /* @__PURE__ */ new Set() };
|
|
3835
|
+
const parsed = jsonOrUndefined(text2);
|
|
3836
|
+
if (parsed === void 0) return { text: REDACTED2, removed: /* @__PURE__ */ new Set() };
|
|
3837
|
+
return {
|
|
3838
|
+
text: JSON.stringify(this.strip(parsed)),
|
|
3839
|
+
removed: this.removed(parsed)
|
|
3840
|
+
};
|
|
3841
|
+
}
|
|
3842
|
+
carries(text2, removed) {
|
|
3843
|
+
if (text2 === REDACTED2 || this.mentions(text2)) return true;
|
|
3844
|
+
return [...removed].some(
|
|
3845
|
+
(value) => encodings(value).some((form) => text2.includes(form))
|
|
3846
|
+
);
|
|
3847
|
+
}
|
|
3848
|
+
removed(value) {
|
|
3849
|
+
if (typeof value === "string") {
|
|
3850
|
+
const nested = this.mentions(value) ? jsonOrUndefined(value) : void 0;
|
|
3851
|
+
return nested === void 0 ? /* @__PURE__ */ new Set() : this.removed(nested);
|
|
3852
|
+
}
|
|
3853
|
+
if (Array.isArray(value)) return union(value.map((v) => this.removed(v)));
|
|
3854
|
+
if (value === null || typeof value !== "object") return /* @__PURE__ */ new Set();
|
|
3855
|
+
return union(
|
|
3856
|
+
Object.entries(value).map(
|
|
3857
|
+
([key, item]) => this.isSecret(key) ? leaves(item) : this.removed(item)
|
|
3858
|
+
)
|
|
3859
|
+
);
|
|
3860
|
+
}
|
|
3861
|
+
stripNested(text2) {
|
|
3862
|
+
if (!this.mentions(text2)) return text2;
|
|
3863
|
+
const parsed = jsonOrUndefined(text2);
|
|
3864
|
+
if (parsed === void 0) return text2;
|
|
3865
|
+
return JSON.stringify(this.strip(parsed));
|
|
3866
|
+
}
|
|
3867
|
+
};
|
|
3868
|
+
SPAN_SECRETS = new SpanSecrets();
|
|
3869
|
+
SecretRedactingSpanProcessor = class {
|
|
3870
|
+
constructor(inner, secrets = SPAN_SECRETS) {
|
|
3871
|
+
this.inner = inner;
|
|
3872
|
+
this.secrets = secrets;
|
|
3873
|
+
}
|
|
3874
|
+
inner;
|
|
3875
|
+
secrets;
|
|
3876
|
+
views = /* @__PURE__ */ new WeakMap();
|
|
3877
|
+
onStart(span, parentContext) {
|
|
3878
|
+
this.inner.onStart(this.viewFor(span), parentContext);
|
|
3879
|
+
}
|
|
3880
|
+
onEnd(span) {
|
|
3881
|
+
const view = this.viewFor(span);
|
|
3882
|
+
try {
|
|
3883
|
+
void [view.attributes, view.events, view.status];
|
|
3884
|
+
} catch (error) {
|
|
3885
|
+
console.warn(
|
|
3886
|
+
`[gatewaysdk.tracing] Dropped span "${span.name}": could not redact it: ${error?.name}`
|
|
3887
|
+
);
|
|
3888
|
+
return;
|
|
3889
|
+
}
|
|
3890
|
+
this.inner.onEnd(view);
|
|
3891
|
+
}
|
|
3892
|
+
viewFor(span) {
|
|
3893
|
+
const known = this.views.get(span);
|
|
3894
|
+
if (known) return known;
|
|
3895
|
+
const view = viewOf(span, {
|
|
3896
|
+
attributes: () => this.scrubbedAttributes(span.attributes),
|
|
3897
|
+
events: () => span.events.map((event) => this.scrubbedEvent(event)),
|
|
3898
|
+
status: () => this.scrubbedStatus(span.status)
|
|
3899
|
+
});
|
|
3900
|
+
this.views.set(span, view);
|
|
3901
|
+
return view;
|
|
3902
|
+
}
|
|
3903
|
+
forceFlush() {
|
|
3904
|
+
return this.inner.forceFlush();
|
|
3905
|
+
}
|
|
3906
|
+
shutdown() {
|
|
3907
|
+
return this.inner.shutdown();
|
|
3908
|
+
}
|
|
3909
|
+
scrubbedAttributes(attributes) {
|
|
3910
|
+
const clean = this.secrets.scrubAttributes(attributes);
|
|
3911
|
+
return sameAttributes(attributes, clean) ? attributes : clean;
|
|
3912
|
+
}
|
|
3913
|
+
scrubbedStatus(status) {
|
|
3914
|
+
if (!status.message) return status;
|
|
3915
|
+
const message = this.secrets.scrubAttribute(status.message);
|
|
3916
|
+
return message === status.message ? status : { ...status, message };
|
|
3917
|
+
}
|
|
3918
|
+
scrubbedEvent(event) {
|
|
3919
|
+
if (!event.attributes) return event;
|
|
3920
|
+
const attributes = this.scrubbedAttributes(event.attributes);
|
|
3921
|
+
if (attributes === event.attributes) return event;
|
|
3922
|
+
return { ...event, attributes };
|
|
2319
3923
|
}
|
|
2320
3924
|
};
|
|
2321
3925
|
}
|
|
@@ -2542,7 +4146,7 @@ var require_package = __commonJS({
|
|
|
2542
4146
|
"package.json"(exports2, module2) {
|
|
2543
4147
|
module2.exports = {
|
|
2544
4148
|
name: "@withgateway/sdk",
|
|
2545
|
-
version: "0.
|
|
4149
|
+
version: "0.3.1",
|
|
2546
4150
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
2547
4151
|
main: "./dist/index.js",
|
|
2548
4152
|
module: "./dist/index.mjs",
|
|
@@ -2753,7 +4357,7 @@ function canonicalJson(value) {
|
|
|
2753
4357
|
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonicalJson(v)}`).join(",")}}`;
|
|
2754
4358
|
}
|
|
2755
4359
|
function sha256(text2) {
|
|
2756
|
-
return `sha256:${(0,
|
|
4360
|
+
return `sha256:${(0, import_node_crypto3.createHash)("sha256").update(text2).digest("hex")}`;
|
|
2757
4361
|
}
|
|
2758
4362
|
function getRegisteredTools() {
|
|
2759
4363
|
return [...registeredTools.values()].sort(
|
|
@@ -2928,11 +4532,11 @@ async function registerBuild(params) {
|
|
|
2928
4532
|
);
|
|
2929
4533
|
}
|
|
2930
4534
|
}
|
|
2931
|
-
var
|
|
4535
|
+
var import_node_crypto3, registeredTools, registeredPrompts, registeredSkills, registeredArtifacts, activeBuilds;
|
|
2932
4536
|
var init_build = __esm({
|
|
2933
4537
|
"src/build/index.ts"() {
|
|
2934
4538
|
"use strict";
|
|
2935
|
-
|
|
4539
|
+
import_node_crypto3 = require("crypto");
|
|
2936
4540
|
registeredTools = /* @__PURE__ */ new Map();
|
|
2937
4541
|
registeredPrompts = /* @__PURE__ */ new Map();
|
|
2938
4542
|
registeredSkills = /* @__PURE__ */ new Map();
|
|
@@ -2951,10 +4555,6 @@ __export(init_exports, {
|
|
|
2951
4555
|
isInitialized: () => isInitialized,
|
|
2952
4556
|
shutdown: () => shutdown
|
|
2953
4557
|
});
|
|
2954
|
-
function getEnv(key) {
|
|
2955
|
-
const value = process.env[key];
|
|
2956
|
-
return value ? value : void 0;
|
|
2957
|
-
}
|
|
2958
4558
|
function log(message, ...args) {
|
|
2959
4559
|
if (state.debug) {
|
|
2960
4560
|
console.log(`[gatewaysdk.tracing] ${message}`, ...args);
|
|
@@ -2964,10 +4564,10 @@ function warn(message, ...args) {
|
|
|
2964
4564
|
console.warn(`[gatewaysdk.tracing] ${message}`, ...args);
|
|
2965
4565
|
}
|
|
2966
4566
|
function buildProvider(config, logFn) {
|
|
2967
|
-
const host = config.host ?? getEnv(
|
|
2968
|
-
const publicKey = config.publicKey ?? getEnv(
|
|
2969
|
-
const secretKey = config.secretKey ?? getEnv(
|
|
2970
|
-
const endpoint = config.endpoint ?? getEnv(
|
|
4567
|
+
const host = config.host ?? getEnv(GATEWAY_ENV.HOST);
|
|
4568
|
+
const publicKey = config.publicKey ?? getEnv(GATEWAY_ENV.PUBLIC_KEY);
|
|
4569
|
+
const secretKey = config.secretKey ?? getEnv(GATEWAY_ENV.SECRET_KEY);
|
|
4570
|
+
const endpoint = config.endpoint ?? getEnv(GATEWAY_ENV.ENDPOINT) ?? (host ? `${host.replace(/\/$/, "")}${DEFAULT_OTLP_PATH}` : void 0);
|
|
2971
4571
|
const missing = [];
|
|
2972
4572
|
if (!host) missing.push("host (or GATEWAY_HOST env var)");
|
|
2973
4573
|
if (!publicKey) missing.push("publicKey (or GATEWAY_PUBLIC_KEY env var)");
|
|
@@ -3004,9 +4604,7 @@ function buildProvider(config, logFn) {
|
|
|
3004
4604
|
ATTR_SERVICE_NAME = "service.name";
|
|
3005
4605
|
}
|
|
3006
4606
|
} catch {
|
|
3007
|
-
throw new
|
|
3008
|
-
"OpenTelemetry packages not found. Install them with:\nnpm install @opentelemetry/sdk-trace-node @opentelemetry/sdk-trace-base @opentelemetry/exporter-trace-otlp-http @opentelemetry/resources"
|
|
3009
|
-
);
|
|
4607
|
+
throw new OpenTelemetryMissing();
|
|
3010
4608
|
}
|
|
3011
4609
|
const resourceAttrs = {
|
|
3012
4610
|
[ATTR_SERVICE_NAME]: config.serviceName ?? "gatewaysdk-tracing"
|
|
@@ -3062,7 +4660,7 @@ function buildProvider(config, logFn) {
|
|
|
3062
4660
|
const spanProcessors = [];
|
|
3063
4661
|
if (config.customSpanProcessors) {
|
|
3064
4662
|
for (const sp of config.customSpanProcessors) {
|
|
3065
|
-
spanProcessors.push(sp);
|
|
4663
|
+
spanProcessors.push(new SecretRedactingSpanProcessor(sp));
|
|
3066
4664
|
logFn(
|
|
3067
4665
|
"Added custom span processor: %s",
|
|
3068
4666
|
sp.constructor?.name ?? "unknown"
|
|
@@ -3081,7 +4679,11 @@ function buildProvider(config, logFn) {
|
|
|
3081
4679
|
if (config.batch?.maxExportBatchSize) {
|
|
3082
4680
|
batchConfig.maxExportBatchSize = config.batch.maxExportBatchSize;
|
|
3083
4681
|
}
|
|
3084
|
-
spanProcessors.push(
|
|
4682
|
+
spanProcessors.push(
|
|
4683
|
+
new SecretRedactingSpanProcessor(
|
|
4684
|
+
new BatchSpanProcessor(exporter, batchConfig)
|
|
4685
|
+
)
|
|
4686
|
+
);
|
|
3085
4687
|
let provider = new NodeTracerProvider({
|
|
3086
4688
|
resource: createResource(resourceAttrs)
|
|
3087
4689
|
});
|
|
@@ -3208,26 +4810,17 @@ async function shutdown() {
|
|
|
3208
4810
|
function isInitialized() {
|
|
3209
4811
|
return state.initialized;
|
|
3210
4812
|
}
|
|
3211
|
-
|
|
3212
|
-
const host = getEnv(ENV_VARS.HOST);
|
|
3213
|
-
const publicKey = getEnv(ENV_VARS.PUBLIC_KEY);
|
|
3214
|
-
const secretKey = getEnv(ENV_VARS.SECRET_KEY);
|
|
3215
|
-
return !!(host && publicKey && secretKey);
|
|
3216
|
-
}
|
|
3217
|
-
var ENV_VARS, DEFAULT_OTLP_PATH, state;
|
|
4813
|
+
var DEFAULT_OTLP_PATH, state;
|
|
3218
4814
|
var init_init = __esm({
|
|
3219
4815
|
"src/tracing/init.ts"() {
|
|
3220
4816
|
"use strict";
|
|
3221
4817
|
init_identity();
|
|
3222
|
-
|
|
4818
|
+
init_secrets();
|
|
4819
|
+
init_session();
|
|
3223
4820
|
init_scores();
|
|
3224
4821
|
init_build();
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
PUBLIC_KEY: "GATEWAY_PUBLIC_KEY",
|
|
3228
|
-
SECRET_KEY: "GATEWAY_SECRET_KEY",
|
|
3229
|
-
ENDPOINT: "GATEWAY_OTLP_ENDPOINT"
|
|
3230
|
-
};
|
|
4822
|
+
init_prerequisites();
|
|
4823
|
+
init_prerequisites();
|
|
3231
4824
|
DEFAULT_OTLP_PATH = "/api/public/otel/v1/traces";
|
|
3232
4825
|
state = {
|
|
3233
4826
|
initialized: false,
|
|
@@ -3236,6 +4829,45 @@ var init_init = __esm({
|
|
|
3236
4829
|
}
|
|
3237
4830
|
});
|
|
3238
4831
|
|
|
4832
|
+
// src/worlds/taskTracing.ts
|
|
4833
|
+
var TaskTracing;
|
|
4834
|
+
var init_taskTracing = __esm({
|
|
4835
|
+
"src/worlds/taskTracing.ts"() {
|
|
4836
|
+
"use strict";
|
|
4837
|
+
init_prerequisites();
|
|
4838
|
+
TaskTracing = class _TaskTracing {
|
|
4839
|
+
constructor(load = () => Promise.resolve().then(() => (init_init(), init_exports))) {
|
|
4840
|
+
this.load = load;
|
|
4841
|
+
}
|
|
4842
|
+
load;
|
|
4843
|
+
static warned = false;
|
|
4844
|
+
async start(requested) {
|
|
4845
|
+
if (!requested || !isGatewayConfigured()) return false;
|
|
4846
|
+
try {
|
|
4847
|
+
(await this.load()).init();
|
|
4848
|
+
return true;
|
|
4849
|
+
} catch (error) {
|
|
4850
|
+
_TaskTracing.warnOnce(error);
|
|
4851
|
+
return false;
|
|
4852
|
+
}
|
|
4853
|
+
}
|
|
4854
|
+
static warnOnce(error) {
|
|
4855
|
+
if (_TaskTracing.warned) return;
|
|
4856
|
+
_TaskTracing.warned = true;
|
|
4857
|
+
console.warn(
|
|
4858
|
+
`[gatewaysdk.tracing] Task runs in this process are not traced. ${_TaskTracing.reason(error)}
|
|
4859
|
+
Pass --no-trace (trace: false) to run untraced without this warning.`
|
|
4860
|
+
);
|
|
4861
|
+
}
|
|
4862
|
+
static reason(error) {
|
|
4863
|
+
if (OpenTelemetryMissing.explains(error))
|
|
4864
|
+
return new OpenTelemetryMissing().message;
|
|
4865
|
+
return error instanceof Error ? error.message : String(error);
|
|
4866
|
+
}
|
|
4867
|
+
};
|
|
4868
|
+
}
|
|
4869
|
+
});
|
|
4870
|
+
|
|
3239
4871
|
// src/worlds/taskRun.ts
|
|
3240
4872
|
function worldRef(live, alias) {
|
|
3241
4873
|
const { slug, ref } = live.worldRef(alias);
|
|
@@ -3334,7 +4966,7 @@ function reportFromResult(result) {
|
|
|
3334
4966
|
return { report, extra };
|
|
3335
4967
|
}
|
|
3336
4968
|
async function runTask(ref, agent, opts) {
|
|
3337
|
-
const runId = `wtr-${(0,
|
|
4969
|
+
const runId = `wtr-${(0, import_node_crypto4.randomBytes)(6).toString("hex")}`;
|
|
3338
4970
|
const outDir = opts.outDir ?? "runs";
|
|
3339
4971
|
const runDir = path.join(outDir, runId);
|
|
3340
4972
|
fs.mkdirSync(runDir, { recursive: true });
|
|
@@ -3348,18 +4980,7 @@ async function runTask(ref, agent, opts) {
|
|
|
3348
4980
|
const started = Date.now();
|
|
3349
4981
|
try {
|
|
3350
4982
|
await live.ready();
|
|
3351
|
-
|
|
3352
|
-
if (opts.trace !== false) {
|
|
3353
|
-
try {
|
|
3354
|
-
const { isGatewayConfigured: isGatewayConfigured2, init: init2 } = await Promise.resolve().then(() => (init_init(), init_exports));
|
|
3355
|
-
if (isGatewayConfigured2()) {
|
|
3356
|
-
init2();
|
|
3357
|
-
traced = true;
|
|
3358
|
-
}
|
|
3359
|
-
} catch {
|
|
3360
|
-
traced = false;
|
|
3361
|
-
}
|
|
3362
|
-
}
|
|
4983
|
+
const traced = await new TaskTracing().start(opts.trace !== false);
|
|
3363
4984
|
const taskRun = new TaskRun(
|
|
3364
4985
|
runId,
|
|
3365
4986
|
live.instruction ?? "",
|
|
@@ -3372,7 +4993,7 @@ async function runTask(ref, agent, opts) {
|
|
|
3372
4993
|
let extra = {};
|
|
3373
4994
|
try {
|
|
3374
4995
|
const invoke = () => agent(taskRun);
|
|
3375
|
-
const result = traced ? await (await Promise.resolve().then(() => (
|
|
4996
|
+
const result = traced ? await (await Promise.resolve().then(() => (init_session(), session_exports))).withSession(runId, invoke) : await invoke();
|
|
3376
4997
|
({ report, extra } = reportFromResult(result));
|
|
3377
4998
|
} catch (error) {
|
|
3378
4999
|
const message = (error instanceof Error ? error.message : String(error)) || "Unknown error";
|
|
@@ -3439,17 +5060,18 @@ async function runTask(ref, agent, opts) {
|
|
|
3439
5060
|
}
|
|
3440
5061
|
}
|
|
3441
5062
|
}
|
|
3442
|
-
var
|
|
5063
|
+
var import_node_crypto4, fs, path, TaskRun, describeValue, RESULT_CONTRACT;
|
|
3443
5064
|
var init_taskRun = __esm({
|
|
3444
5065
|
"src/worlds/taskRun.ts"() {
|
|
3445
5066
|
"use strict";
|
|
3446
|
-
|
|
5067
|
+
import_node_crypto4 = require("crypto");
|
|
3447
5068
|
fs = __toESM(require("fs"));
|
|
3448
5069
|
path = __toESM(require("path"));
|
|
3449
5070
|
init_browser();
|
|
3450
5071
|
init_evals();
|
|
3451
|
-
|
|
5072
|
+
init_session2();
|
|
3452
5073
|
init_taskSessions();
|
|
5074
|
+
init_taskTracing();
|
|
3453
5075
|
TaskRun = class {
|
|
3454
5076
|
constructor(runId, instruction, model, sessions, manifest) {
|
|
3455
5077
|
this.runId = runId;
|
|
@@ -3653,6 +5275,52 @@ var init_setRun = __esm({
|
|
|
3653
5275
|
}
|
|
3654
5276
|
});
|
|
3655
5277
|
|
|
5278
|
+
// src/worlds/requestLog.ts
|
|
5279
|
+
var WorldRequestLog;
|
|
5280
|
+
var init_requestLog = __esm({
|
|
5281
|
+
"src/worlds/requestLog.ts"() {
|
|
5282
|
+
"use strict";
|
|
5283
|
+
WorldRequestLog = class _WorldRequestLog {
|
|
5284
|
+
constructor(requests) {
|
|
5285
|
+
this.requests = requests;
|
|
5286
|
+
}
|
|
5287
|
+
requests;
|
|
5288
|
+
static async read(session) {
|
|
5289
|
+
const state2 = await session.state();
|
|
5290
|
+
const calls = state2?.calls;
|
|
5291
|
+
if (!Array.isArray(calls)) return null;
|
|
5292
|
+
return new _WorldRequestLog(calls.filter((c) => typeof c === "object" && c !== null));
|
|
5293
|
+
}
|
|
5294
|
+
/** How many older requests the world no longer keeps (its log is bounded): the gap
|
|
5295
|
+
* before the first entry it still holds. */
|
|
5296
|
+
get dropped() {
|
|
5297
|
+
const first = Number(this.requests[0]?.seq) || 1;
|
|
5298
|
+
return Math.max(0, first - 1);
|
|
5299
|
+
}
|
|
5300
|
+
/** Each request in the shape of a ledger line, `kind: "request"`, so one JSONL
|
|
5301
|
+
* file holds both. */
|
|
5302
|
+
asCalls() {
|
|
5303
|
+
return this.requests.map((r) => ({
|
|
5304
|
+
seq: Number(r.seq) || 0,
|
|
5305
|
+
kind: "request",
|
|
5306
|
+
tool: r.operation ?? null,
|
|
5307
|
+
args: {
|
|
5308
|
+
method: r.method ?? null,
|
|
5309
|
+
path: r.path ?? null,
|
|
5310
|
+
args: r.args ?? null,
|
|
5311
|
+
query: r.query ?? null,
|
|
5312
|
+
body: r.body ?? null,
|
|
5313
|
+
via: r.via ?? null
|
|
5314
|
+
},
|
|
5315
|
+
result: { status: r.status ?? null, rows: r.rows ?? null, found: r.found ?? null },
|
|
5316
|
+
error: null,
|
|
5317
|
+
completedAt: r.at ?? null
|
|
5318
|
+
}));
|
|
5319
|
+
}
|
|
5320
|
+
};
|
|
5321
|
+
}
|
|
5322
|
+
});
|
|
5323
|
+
|
|
3656
5324
|
// src/worlds/checkoutTarget.ts
|
|
3657
5325
|
var fs2, path2, CheckoutRefusedError, NAMED_EDITS, CheckoutTarget;
|
|
3658
5326
|
var init_checkoutTarget = __esm({
|
|
@@ -3757,11 +5425,11 @@ var init_checkoutTarget = __esm({
|
|
|
3757
5425
|
});
|
|
3758
5426
|
|
|
3759
5427
|
// src/worlds/worldDir.ts
|
|
3760
|
-
var
|
|
5428
|
+
var import_node_crypto5, fs3, path3, 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;
|
|
3761
5429
|
var init_worldDir = __esm({
|
|
3762
5430
|
"src/worlds/worldDir.ts"() {
|
|
3763
5431
|
"use strict";
|
|
3764
|
-
|
|
5432
|
+
import_node_crypto5 = require("crypto");
|
|
3765
5433
|
fs3 = __toESM(require("fs"));
|
|
3766
5434
|
path3 = __toESM(require("path"));
|
|
3767
5435
|
WORLD_MANIFEST = "gateway-env.toml";
|
|
@@ -3867,7 +5535,7 @@ var init_worldDir = __esm({
|
|
|
3867
5535
|
* sorted order: the version's identity, byte-compatible with
|
|
3868
5536
|
* `_archive.compute_content_hash` and Prime Intellect. */
|
|
3869
5537
|
get contentHash() {
|
|
3870
|
-
const hasher = (0,
|
|
5538
|
+
const hasher = (0, import_node_crypto5.createHash)("sha256");
|
|
3871
5539
|
for (const rel of this.archivePaths) {
|
|
3872
5540
|
hasher.update(Buffer.from(`file:${rel}`, "utf-8"));
|
|
3873
5541
|
hasher.update(fs3.readFileSync(path3.join(this.dir, rel)));
|
|
@@ -4171,7 +5839,7 @@ function writeLocalMeta(dir, meta) {
|
|
|
4171
5839
|
function snapshotTreeHashes(dir) {
|
|
4172
5840
|
const out = {};
|
|
4173
5841
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
4174
|
-
out[relPath] = (0,
|
|
5842
|
+
out[relPath] = (0, import_node_crypto6.createHash)("sha256").update(fs5.readFileSync(path5.join(dir, relPath))).digest("hex");
|
|
4175
5843
|
}
|
|
4176
5844
|
return out;
|
|
4177
5845
|
}
|
|
@@ -4217,7 +5885,7 @@ function buildFileManifest(dir) {
|
|
|
4217
5885
|
path: relPath,
|
|
4218
5886
|
isDirectory: false,
|
|
4219
5887
|
size: payload.length,
|
|
4220
|
-
sha256: (0,
|
|
5888
|
+
sha256: (0, import_node_crypto6.createHash)("sha256").update(payload).digest("hex")
|
|
4221
5889
|
};
|
|
4222
5890
|
});
|
|
4223
5891
|
}
|
|
@@ -4416,11 +6084,11 @@ async function createRef(slug, name, kind, versionId, options = {}) {
|
|
|
4416
6084
|
...versionId ? { versionId } : {}
|
|
4417
6085
|
});
|
|
4418
6086
|
}
|
|
4419
|
-
var
|
|
6087
|
+
var import_node_crypto6, import_node_zlib2, fs5, path5, DEFAULT_BRANCH, META_RELPATH, FILE_MODE, MINTED_SUFFIX, PushSlugConflict, sha256b64, DetachedPushError;
|
|
4420
6088
|
var init_hub = __esm({
|
|
4421
6089
|
"src/worlds/hub.ts"() {
|
|
4422
6090
|
"use strict";
|
|
4423
|
-
|
|
6091
|
+
import_node_crypto6 = require("crypto");
|
|
4424
6092
|
import_node_zlib2 = require("zlib");
|
|
4425
6093
|
fs5 = __toESM(require("fs"));
|
|
4426
6094
|
path5 = __toESM(require("path"));
|
|
@@ -4446,7 +6114,7 @@ var init_hub = __esm({
|
|
|
4446
6114
|
tracked;
|
|
4447
6115
|
declared;
|
|
4448
6116
|
};
|
|
4449
|
-
sha256b64 = (data) => (0,
|
|
6117
|
+
sha256b64 = (data) => (0, import_node_crypto6.createHash)("sha256").update(data).digest("base64");
|
|
4450
6118
|
DetachedPushError = class extends Error {
|
|
4451
6119
|
constructor(dir, tag) {
|
|
4452
6120
|
super(
|
|
@@ -5090,11 +6758,11 @@ function applyTransforms(value, chain) {
|
|
|
5090
6758
|
for (const step of steps) out = step(out);
|
|
5091
6759
|
return out;
|
|
5092
6760
|
}
|
|
5093
|
-
var
|
|
6761
|
+
var import_node_crypto7, WHITESPACE, WHITESPACE_EDGES, WHITESPACE_RUN, NOT_DIGIT, STRIP_PREFIX, trim, emailLocalPart, emailDomain, stripPrefix, hex, SIMPLE, TRANSFORMS, text;
|
|
5094
6762
|
var init_transforms = __esm({
|
|
5095
6763
|
"src/worlds/transforms.ts"() {
|
|
5096
6764
|
"use strict";
|
|
5097
|
-
|
|
6765
|
+
import_node_crypto7 = require("crypto");
|
|
5098
6766
|
init_json();
|
|
5099
6767
|
WHITESPACE = " \n\r\f\v";
|
|
5100
6768
|
WHITESPACE_EDGES = new RegExp(`^[${WHITESPACE}]+|[${WHITESPACE}]+$`, "g");
|
|
@@ -5111,7 +6779,7 @@ var init_transforms = __esm({
|
|
|
5111
6779
|
return at === -1 ? "" : value.slice(at + 1).toLowerCase();
|
|
5112
6780
|
};
|
|
5113
6781
|
stripPrefix = (prefix) => (value) => value.startsWith(prefix) ? value.slice(prefix.length) : value;
|
|
5114
|
-
hex = (algorithm, value) => (0,
|
|
6782
|
+
hex = (algorithm, value) => (0, import_node_crypto7.createHash)(algorithm).update(value, "utf8").digest("hex");
|
|
5115
6783
|
SIMPLE = {
|
|
5116
6784
|
lower: (value) => value.toLowerCase(),
|
|
5117
6785
|
upper: (value) => value.toUpperCase(),
|
|
@@ -5143,7 +6811,7 @@ function pyText(value) {
|
|
|
5143
6811
|
return pyFloatRepr(value);
|
|
5144
6812
|
}
|
|
5145
6813
|
function hashForm(slug, plaintext) {
|
|
5146
|
-
return "sha256:" + (0,
|
|
6814
|
+
return "sha256:" + (0, import_node_crypto8.createHash)("sha256").update(`${slug}:${pyText(plaintext)}`, "utf8").digest("hex");
|
|
5147
6815
|
}
|
|
5148
6816
|
function preserveForm(slug, plaintext) {
|
|
5149
6817
|
const kind = typeof plaintext === "string" ? "str" : isInt(plaintext) ? "int" : "float";
|
|
@@ -5152,12 +6820,12 @@ function preserveForm(slug, plaintext) {
|
|
|
5152
6820
|
}
|
|
5153
6821
|
function shapeText(slug, text2, kind) {
|
|
5154
6822
|
const seed = Buffer.from(`${slug}:${text2}`, "utf8");
|
|
5155
|
-
let digest = (0,
|
|
6823
|
+
let digest = (0, import_node_crypto8.createHash)("sha256").update(seed).digest();
|
|
5156
6824
|
let cursor = 0;
|
|
5157
6825
|
const out = [];
|
|
5158
6826
|
for (const char of text2) {
|
|
5159
6827
|
if (cursor === digest.length) {
|
|
5160
|
-
digest = (0,
|
|
6828
|
+
digest = (0, import_node_crypto8.createHash)("sha256").update(Buffer.concat([digest, seed])).digest();
|
|
5161
6829
|
cursor = 0;
|
|
5162
6830
|
}
|
|
5163
6831
|
const byte = digest[cursor];
|
|
@@ -5194,11 +6862,11 @@ function storedForms(world, field2, plaintext, transform) {
|
|
|
5194
6862
|
if (policy !== null) return [roundForm(plaintext, world.redact.round[field2])];
|
|
5195
6863
|
return [plaintext];
|
|
5196
6864
|
}
|
|
5197
|
-
var
|
|
6865
|
+
var import_node_crypto8, isInt;
|
|
5198
6866
|
var init_redaction = __esm({
|
|
5199
6867
|
"src/worlds/redaction.ts"() {
|
|
5200
6868
|
"use strict";
|
|
5201
|
-
|
|
6869
|
+
import_node_crypto8 = require("crypto");
|
|
5202
6870
|
init_json();
|
|
5203
6871
|
init_transforms();
|
|
5204
6872
|
isInt = (value) => typeof value === "number" && Number.isInteger(value);
|
|
@@ -5482,7 +7150,7 @@ async function localBridge(request, local, opts = {}) {
|
|
|
5482
7150
|
child.stdin.end(input);
|
|
5483
7151
|
});
|
|
5484
7152
|
}
|
|
5485
|
-
var import_node_child_process2, fs7, net, path7, MIN_PYTHON, DIAGNOSTIC_TAIL, BRIDGE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
|
|
7153
|
+
var import_node_child_process2, fs7, net, path7, MIN_PYTHON, MIN_PYTHON_LABEL, DIAGNOSTIC_TAIL, BRIDGE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
|
|
5486
7154
|
var init_local = __esm({
|
|
5487
7155
|
"src/cli/runtime/local.ts"() {
|
|
5488
7156
|
"use strict";
|
|
@@ -5493,6 +7161,7 @@ var init_local = __esm({
|
|
|
5493
7161
|
init_router();
|
|
5494
7162
|
init_config();
|
|
5495
7163
|
MIN_PYTHON = [3, 12];
|
|
7164
|
+
MIN_PYTHON_LABEL = MIN_PYTHON.join(".");
|
|
5496
7165
|
DIAGNOSTIC_TAIL = 600;
|
|
5497
7166
|
BRIDGE_BOOTSTRAP = `import sys,runpy,types,os
|
|
5498
7167
|
root=sys.argv[1]
|
|
@@ -6067,7 +7736,7 @@ function uploadHeadersFor(gz) {
|
|
|
6067
7736
|
return {
|
|
6068
7737
|
"content-type": "application/gzip",
|
|
6069
7738
|
"content-length": String(gz.length),
|
|
6070
|
-
"x-amz-checksum-sha256": (0,
|
|
7739
|
+
"x-amz-checksum-sha256": (0, import_node_crypto9.createHash)("sha256").update(gz).digest("base64")
|
|
6071
7740
|
};
|
|
6072
7741
|
}
|
|
6073
7742
|
async function forEachLimited(items, limit, fn) {
|
|
@@ -6113,11 +7782,11 @@ function phaseLine(status) {
|
|
|
6113
7782
|
const phase = status.progress?.phase;
|
|
6114
7783
|
return phase ? `${status.state} (${phase})` : status.state;
|
|
6115
7784
|
}
|
|
6116
|
-
var
|
|
7785
|
+
var import_node_crypto9, fs11, TERMINAL_STATES, sleepMs, WorldDataApi;
|
|
6117
7786
|
var init_batches = __esm({
|
|
6118
7787
|
"src/cli/platform/worldData/batches.ts"() {
|
|
6119
7788
|
"use strict";
|
|
6120
|
-
|
|
7789
|
+
import_node_crypto9 = require("crypto");
|
|
6121
7790
|
fs11 = __toESM(require("fs"));
|
|
6122
7791
|
init_config();
|
|
6123
7792
|
init_router();
|
|
@@ -6311,12 +7980,12 @@ function finishChunk(ordinal, raw, rows, entity, firstRow = 0) {
|
|
|
6311
7980
|
const gz = gzipDeterministic(raw, { name: chunkName(ordinal) });
|
|
6312
7981
|
return {
|
|
6313
7982
|
ordinal,
|
|
6314
|
-
digest: (0,
|
|
7983
|
+
digest: (0, import_node_crypto10.createHash)("sha256").update(gz).digest("hex"),
|
|
6315
7984
|
bytes: gz.length,
|
|
6316
7985
|
rows,
|
|
6317
7986
|
entity,
|
|
6318
7987
|
rawBytes: raw.length,
|
|
6319
|
-
contentSha256: (0,
|
|
7988
|
+
contentSha256: (0, import_node_crypto10.createHash)("sha256").update(raw).digest("hex"),
|
|
6320
7989
|
firstRow,
|
|
6321
7990
|
gz
|
|
6322
7991
|
};
|
|
@@ -6356,11 +8025,11 @@ function crc32(data) {
|
|
|
6356
8025
|
crc = table[(crc ^ data[i]) & 255] ^ crc >>> 8;
|
|
6357
8026
|
return (crc ^ 4294967295) >>> 0;
|
|
6358
8027
|
}
|
|
6359
|
-
var
|
|
8028
|
+
var import_node_crypto10, import_node_zlib3, DEFAULT_CHUNK_BYTES, GZIP_LEVEL, chunkName, table;
|
|
6360
8029
|
var init_chunker = __esm({
|
|
6361
8030
|
"src/cli/platform/worldData/chunker.ts"() {
|
|
6362
8031
|
"use strict";
|
|
6363
|
-
|
|
8032
|
+
import_node_crypto10 = require("crypto");
|
|
6364
8033
|
import_node_zlib3 = require("zlib");
|
|
6365
8034
|
init_json();
|
|
6366
8035
|
DEFAULT_CHUNK_BYTES = 64 * 1024 * 1024;
|
|
@@ -6655,7 +8324,7 @@ var init_ingest = __esm({
|
|
|
6655
8324
|
});
|
|
6656
8325
|
|
|
6657
8326
|
// src/worlds/editSessions.ts
|
|
6658
|
-
var WORLDS, WorldEditClient;
|
|
8327
|
+
var WORLDS, WorldEditClient, TASK_EDITS, TaskEditClient;
|
|
6659
8328
|
var init_editSessions = __esm({
|
|
6660
8329
|
"src/worlds/editSessions.ts"() {
|
|
6661
8330
|
"use strict";
|
|
@@ -6687,6 +8356,22 @@ var init_editSessions = __esm({
|
|
|
6687
8356
|
return apiRequest(this.options, "POST", `${WORLDS}/${encodeURIComponent(slug)}/edits/rollback`, input);
|
|
6688
8357
|
}
|
|
6689
8358
|
};
|
|
8359
|
+
TASK_EDITS = "/api/public/world-task-edits";
|
|
8360
|
+
TaskEditClient = class {
|
|
8361
|
+
constructor(options = {}) {
|
|
8362
|
+
this.options = options;
|
|
8363
|
+
}
|
|
8364
|
+
options;
|
|
8365
|
+
status(task) {
|
|
8366
|
+
return apiRequest(this.options, "POST", `${TASK_EDITS}/status`, { task });
|
|
8367
|
+
}
|
|
8368
|
+
close(task, input = {}) {
|
|
8369
|
+
return apiRequest(this.options, "POST", `${TASK_EDITS}/close`, { task, ...input });
|
|
8370
|
+
}
|
|
8371
|
+
rollback(task, input) {
|
|
8372
|
+
return apiRequest(this.options, "POST", `${TASK_EDITS}/rollback`, { task, ...input });
|
|
8373
|
+
}
|
|
8374
|
+
};
|
|
6690
8375
|
}
|
|
6691
8376
|
});
|
|
6692
8377
|
|
|
@@ -6782,6 +8467,10 @@ var init_dryRun = __esm({
|
|
|
6782
8467
|
// src/worlds/index.ts
|
|
6783
8468
|
var worlds_exports = {};
|
|
6784
8469
|
__export(worlds_exports, {
|
|
8470
|
+
ACTION_NAMES: () => ACTION_NAMES,
|
|
8471
|
+
ActionTracer: () => ActionTracer,
|
|
8472
|
+
AnthropicComputer: () => AnthropicComputer,
|
|
8473
|
+
AnthropicComputer20251124: () => AnthropicComputer20251124,
|
|
6785
8474
|
ApiError: () => ApiError,
|
|
6786
8475
|
BROWSER_GONE_PATTERNS: () => BROWSER_GONE_PATTERNS,
|
|
6787
8476
|
BROWSER_TIERS: () => BROWSER_TIERS,
|
|
@@ -6793,11 +8482,13 @@ __export(worlds_exports, {
|
|
|
6793
8482
|
CALL_BODY_LIMIT_LABEL: () => CALL_BODY_LIMIT_LABEL,
|
|
6794
8483
|
COMPUTER_USE_SPECS: () => COMPUTER_USE_SPECS,
|
|
6795
8484
|
CheckoutProvenance: () => CheckoutProvenance,
|
|
8485
|
+
ComputerAction: () => ComputerAction,
|
|
6796
8486
|
DEFAULT_BRANCH: () => DEFAULT_BRANCH,
|
|
6797
8487
|
DEFAULT_VIEWPORT: () => DEFAULT_VIEWPORT,
|
|
6798
8488
|
DRY_RUN_AGENT: () => DRY_RUN_AGENT,
|
|
6799
8489
|
DRY_RUN_KIND: () => DRY_RUN_KIND,
|
|
6800
8490
|
DetachedPushError: () => DetachedPushError,
|
|
8491
|
+
Display: () => Display,
|
|
6801
8492
|
DryRunOutcome: () => DryRunOutcome,
|
|
6802
8493
|
EVENT_BATCH_SIZE: () => EVENT_BATCH_SIZE,
|
|
6803
8494
|
EVENT_FLUSH_INTERVAL_MS: () => EVENT_FLUSH_INTERVAL_MS,
|
|
@@ -6807,19 +8498,30 @@ __export(worlds_exports, {
|
|
|
6807
8498
|
GatewayEvalsClient: () => GatewayEvalsClient,
|
|
6808
8499
|
HostedDryRunClient: () => HostedDryRunClient,
|
|
6809
8500
|
IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
|
|
8501
|
+
KEY_NAMES: () => KEY_NAMES,
|
|
8502
|
+
KeyChord: () => KeyChord,
|
|
8503
|
+
NOT_EXECUTED: () => NOT_EXECUTED,
|
|
6810
8504
|
NO_GRADER_REASON: () => NO_GRADER_REASON,
|
|
8505
|
+
NativeComputer: () => NativeComputer,
|
|
8506
|
+
OpenAIComputer: () => OpenAIComputer,
|
|
8507
|
+
OpenAIPreviewComputer: () => OpenAIPreviewComputer,
|
|
6811
8508
|
PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
6812
8509
|
PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
|
|
8510
|
+
PendingSafetyChecks: () => PendingSafetyChecks,
|
|
6813
8511
|
PlatformTransport: () => PlatformTransport,
|
|
6814
8512
|
PushSlugConflict: () => PushSlugConflict,
|
|
6815
8513
|
RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
|
|
6816
8514
|
SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
|
|
8515
|
+
SECRET_KEY: () => SECRET_KEY,
|
|
6817
8516
|
SESSION_STATES: () => SESSION_STATES,
|
|
8517
|
+
SPAN_PREFIX: () => SPAN_PREFIX,
|
|
6818
8518
|
STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
|
|
6819
8519
|
STRIP_PREFIX: () => STRIP_PREFIX,
|
|
6820
8520
|
SURFACE_KINDS: () => SURFACE_KINDS,
|
|
8521
|
+
Screen: () => Screen,
|
|
6821
8522
|
SecretScrubber: () => SecretScrubber,
|
|
6822
8523
|
TRANSFORMS: () => TRANSFORMS,
|
|
8524
|
+
TaskEditClient: () => TaskEditClient,
|
|
6823
8525
|
TaskRun: () => TaskRun,
|
|
6824
8526
|
TaskSessions: () => TaskSessions,
|
|
6825
8527
|
TransportCause: () => TransportCause,
|
|
@@ -6829,6 +8531,7 @@ __export(worlds_exports, {
|
|
|
6829
8531
|
WorldBrowser: () => WorldBrowser,
|
|
6830
8532
|
WorldCallTooLarge: () => WorldCallTooLarge,
|
|
6831
8533
|
WorldEditClient: () => WorldEditClient,
|
|
8534
|
+
WorldRequestLog: () => WorldRequestLog,
|
|
6832
8535
|
WorldSandboxClient: () => WorldSandboxClient,
|
|
6833
8536
|
WorldSession: () => WorldSession,
|
|
6834
8537
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
@@ -6892,6 +8595,7 @@ __export(worlds_exports, {
|
|
|
6892
8595
|
parseTransform: () => parseTransform,
|
|
6893
8596
|
parseWorldTaskRefs: () => parseWorldTaskRefs,
|
|
6894
8597
|
platformTimeoutMs: () => platformTimeoutMs,
|
|
8598
|
+
playwrightKey: () => playwrightKey,
|
|
6895
8599
|
preserveForm: () => preserveForm,
|
|
6896
8600
|
propose: () => propose,
|
|
6897
8601
|
pull: () => pull,
|
|
@@ -6901,6 +8605,7 @@ __export(worlds_exports, {
|
|
|
6901
8605
|
pyText: () => pyText,
|
|
6902
8606
|
queryRows: () => queryRows,
|
|
6903
8607
|
queryRowsSearch: () => queryRowsSearch,
|
|
8608
|
+
readField: () => readField,
|
|
6904
8609
|
readLocalMeta: () => readLocalMeta,
|
|
6905
8610
|
readToolCallRecords: () => readToolCallRecords,
|
|
6906
8611
|
rebaseConflicts: () => rebaseConflicts,
|
|
@@ -6920,6 +8625,7 @@ __export(worlds_exports, {
|
|
|
6920
8625
|
shapeText: () => shapeText,
|
|
6921
8626
|
snapshotTreeHashes: () => snapshotTreeHashes,
|
|
6922
8627
|
storedForms: () => storedForms,
|
|
8628
|
+
surfaceDescriptor: () => surfaceDescriptor,
|
|
6923
8629
|
surfaceKinds: () => surfaceKinds,
|
|
6924
8630
|
taskLabel: () => taskLabel,
|
|
6925
8631
|
toolCallRecordsIn: () => toolCallRecordsIn,
|
|
@@ -7150,7 +8856,7 @@ var init_worlds = __esm({
|
|
|
7150
8856
|
"src/worlds/index.ts"() {
|
|
7151
8857
|
init_transport();
|
|
7152
8858
|
init_transport();
|
|
7153
|
-
|
|
8859
|
+
init_session2();
|
|
7154
8860
|
init_sessionList();
|
|
7155
8861
|
init_sessionContract();
|
|
7156
8862
|
init_taskRef();
|
|
@@ -7161,7 +8867,10 @@ var init_worlds = __esm({
|
|
|
7161
8867
|
init_checkoutProvenance();
|
|
7162
8868
|
init_evals();
|
|
7163
8869
|
init_browser();
|
|
8870
|
+
init_surfaceDescriptor();
|
|
8871
|
+
init_requestLog();
|
|
7164
8872
|
init_browserReconnect();
|
|
8873
|
+
init_nativeComputer();
|
|
7165
8874
|
init_hub();
|
|
7166
8875
|
init_validate();
|
|
7167
8876
|
init_describe();
|
|
@@ -7228,7 +8937,7 @@ var init_worlds = __esm({
|
|
|
7228
8937
|
* worlds/session.ts.
|
|
7229
8938
|
*/
|
|
7230
8939
|
async open(task, opts = {}) {
|
|
7231
|
-
const { openSession: openSession2 } = await Promise.resolve().then(() => (
|
|
8940
|
+
const { openSession: openSession2 } = await Promise.resolve().then(() => (init_session2(), session_exports2));
|
|
7232
8941
|
return openSession2(this.slug, {
|
|
7233
8942
|
task,
|
|
7234
8943
|
versionId: this.version.versionId,
|
|
@@ -7263,6 +8972,10 @@ var init_worlds = __esm({
|
|
|
7263
8972
|
init_worlds();
|
|
7264
8973
|
// Annotate the CommonJS export names for ESM import in node:
|
|
7265
8974
|
0 && (module.exports = {
|
|
8975
|
+
ACTION_NAMES,
|
|
8976
|
+
ActionTracer,
|
|
8977
|
+
AnthropicComputer,
|
|
8978
|
+
AnthropicComputer20251124,
|
|
7266
8979
|
ApiError,
|
|
7267
8980
|
BROWSER_GONE_PATTERNS,
|
|
7268
8981
|
BROWSER_TIERS,
|
|
@@ -7274,11 +8987,13 @@ init_worlds();
|
|
|
7274
8987
|
CALL_BODY_LIMIT_LABEL,
|
|
7275
8988
|
COMPUTER_USE_SPECS,
|
|
7276
8989
|
CheckoutProvenance,
|
|
8990
|
+
ComputerAction,
|
|
7277
8991
|
DEFAULT_BRANCH,
|
|
7278
8992
|
DEFAULT_VIEWPORT,
|
|
7279
8993
|
DRY_RUN_AGENT,
|
|
7280
8994
|
DRY_RUN_KIND,
|
|
7281
8995
|
DetachedPushError,
|
|
8996
|
+
Display,
|
|
7282
8997
|
DryRunOutcome,
|
|
7283
8998
|
EVENT_BATCH_SIZE,
|
|
7284
8999
|
EVENT_FLUSH_INTERVAL_MS,
|
|
@@ -7288,19 +9003,30 @@ init_worlds();
|
|
|
7288
9003
|
GatewayEvalsClient,
|
|
7289
9004
|
HostedDryRunClient,
|
|
7290
9005
|
IDLE_WARNING_MINUTES,
|
|
9006
|
+
KEY_NAMES,
|
|
9007
|
+
KeyChord,
|
|
9008
|
+
NOT_EXECUTED,
|
|
7291
9009
|
NO_GRADER_REASON,
|
|
9010
|
+
NativeComputer,
|
|
9011
|
+
OpenAIComputer,
|
|
9012
|
+
OpenAIPreviewComputer,
|
|
7292
9013
|
PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
7293
9014
|
PLATFORM_TIMEOUT_ENV,
|
|
9015
|
+
PendingSafetyChecks,
|
|
7294
9016
|
PlatformTransport,
|
|
7295
9017
|
PushSlugConflict,
|
|
7296
9018
|
RECOVER_BUDGET_MS,
|
|
7297
9019
|
SANDBOX_REQUEST_TIMEOUT_MS,
|
|
9020
|
+
SECRET_KEY,
|
|
7298
9021
|
SESSION_STATES,
|
|
9022
|
+
SPAN_PREFIX,
|
|
7299
9023
|
STATUS_WAIT_CAP_SECONDS,
|
|
7300
9024
|
STRIP_PREFIX,
|
|
7301
9025
|
SURFACE_KINDS,
|
|
9026
|
+
Screen,
|
|
7302
9027
|
SecretScrubber,
|
|
7303
9028
|
TRANSFORMS,
|
|
9029
|
+
TaskEditClient,
|
|
7304
9030
|
TaskRun,
|
|
7305
9031
|
TaskSessions,
|
|
7306
9032
|
TransportCause,
|
|
@@ -7310,6 +9036,7 @@ init_worlds();
|
|
|
7310
9036
|
WorldBrowser,
|
|
7311
9037
|
WorldCallTooLarge,
|
|
7312
9038
|
WorldEditClient,
|
|
9039
|
+
WorldRequestLog,
|
|
7313
9040
|
WorldSandboxClient,
|
|
7314
9041
|
WorldSession,
|
|
7315
9042
|
WorldSessionCallError,
|
|
@@ -7373,6 +9100,7 @@ init_worlds();
|
|
|
7373
9100
|
parseTransform,
|
|
7374
9101
|
parseWorldTaskRefs,
|
|
7375
9102
|
platformTimeoutMs,
|
|
9103
|
+
playwrightKey,
|
|
7376
9104
|
preserveForm,
|
|
7377
9105
|
propose,
|
|
7378
9106
|
pull,
|
|
@@ -7382,6 +9110,7 @@ init_worlds();
|
|
|
7382
9110
|
pyText,
|
|
7383
9111
|
queryRows,
|
|
7384
9112
|
queryRowsSearch,
|
|
9113
|
+
readField,
|
|
7385
9114
|
readLocalMeta,
|
|
7386
9115
|
readToolCallRecords,
|
|
7387
9116
|
rebaseConflicts,
|
|
@@ -7401,6 +9130,7 @@ init_worlds();
|
|
|
7401
9130
|
shapeText,
|
|
7402
9131
|
snapshotTreeHashes,
|
|
7403
9132
|
storedForms,
|
|
9133
|
+
surfaceDescriptor,
|
|
7404
9134
|
surfaceKinds,
|
|
7405
9135
|
taskLabel,
|
|
7406
9136
|
toolCallRecordsIn,
|