@withgateway/sdk 0.2.9 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +2355 -486
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +2335 -466
- 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 +1324 -21
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +1322 -13
- package/dist/files/index.mjs.map +1 -1
- package/dist/{index-Cz8Q6Keo.d.mts → index-D6oi1TWE.d.mts} +93 -34
- package/dist/{index-BO2SNSgy.d.ts → index-DAb-FCMg.d.ts} +93 -34
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1758 -116
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1720 -97
- 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 +1321 -18
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +1319 -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 +512 -11
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +501 -10
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/worlds/index.d.mts +583 -63
- package/dist/worlds/index.d.ts +583 -63
- package/dist/worlds/index.js +1703 -94
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +1689 -80
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +1 -1
- package/runtime/gatewaysdk/environment/schema/api.py +38 -56
- 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/runtime.py +9 -9
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +7 -7
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +1 -0
- package/runtime/gatewaysdk/environment/schema/tasks.py +25 -1
- package/skills/worlds-getting-started/SKILL.md +7 -7
- package/skills/worlds-getting-started/references/cli-mcp-map.md +1 -0
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;
|
|
@@ -901,6 +905,1269 @@ var init_browser = __esm({
|
|
|
901
905
|
}
|
|
902
906
|
});
|
|
903
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();
|
|
2168
|
+
}
|
|
2169
|
+
});
|
|
2170
|
+
|
|
904
2171
|
// src/worlds/sessionContract.ts
|
|
905
2172
|
function serializeCallBody(body) {
|
|
906
2173
|
const text2 = JSON.stringify(body);
|
|
@@ -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",
|
|
@@ -1723,7 +3085,11 @@ function fromResponse(answer, options) {
|
|
|
1723
3085
|
const worlds = {};
|
|
1724
3086
|
for (const [alias, state2] of Object.entries(answer.sessions)) {
|
|
1725
3087
|
sessions[alias] = new WorldSession(state2.sessionId, state2, options);
|
|
1726
|
-
worlds[alias] = {
|
|
3088
|
+
worlds[alias] = {
|
|
3089
|
+
slug: state2.slug,
|
|
3090
|
+
ref: state2.ref,
|
|
3091
|
+
private: state2.private ?? null
|
|
3092
|
+
};
|
|
1727
3093
|
}
|
|
1728
3094
|
return new TaskSessions(
|
|
1729
3095
|
answer.taskId,
|
|
@@ -1797,6 +3163,7 @@ async function attachTask(taskId, options = {}) {
|
|
|
1797
3163
|
{
|
|
1798
3164
|
slug: row.slug ?? "",
|
|
1799
3165
|
ref: null,
|
|
3166
|
+
private: null,
|
|
1800
3167
|
versionId: row.versionId,
|
|
1801
3168
|
sessionId: row.sessionId,
|
|
1802
3169
|
ready: row.ready,
|
|
@@ -1826,7 +3193,7 @@ async function attachManifest(manifest, options = {}) {
|
|
|
1826
3193
|
Object.fromEntries(
|
|
1827
3194
|
Object.entries(manifest.sessions).map(([alias, entry]) => [
|
|
1828
3195
|
alias,
|
|
1829
|
-
{ slug: entry.slug, ref: entry.ref }
|
|
3196
|
+
{ slug: entry.slug, ref: entry.ref, private: entry.private ?? null }
|
|
1830
3197
|
])
|
|
1831
3198
|
)
|
|
1832
3199
|
);
|
|
@@ -1840,12 +3207,13 @@ var init_taskSessions = __esm({
|
|
|
1840
3207
|
"use strict";
|
|
1841
3208
|
init_worlds();
|
|
1842
3209
|
init_browser();
|
|
1843
|
-
|
|
3210
|
+
init_session2();
|
|
1844
3211
|
TASK_SESSIONS = "/api/public/world-task-sessions";
|
|
1845
3212
|
VERIFIER_REWARD_PREFIX = "x.";
|
|
1846
3213
|
manifestSession = (s, state2, world) => ({
|
|
1847
3214
|
slug: world.slug,
|
|
1848
3215
|
ref: world.ref,
|
|
3216
|
+
private: world.private,
|
|
1849
3217
|
versionId: state2.versionId,
|
|
1850
3218
|
sessionId: state2.sessionId,
|
|
1851
3219
|
ready: state2.ready,
|
|
@@ -1880,10 +3248,10 @@ var init_taskSessions = __esm({
|
|
|
1880
3248
|
sessions;
|
|
1881
3249
|
worlds;
|
|
1882
3250
|
hash;
|
|
1883
|
-
/** This alias's
|
|
1884
|
-
*
|
|
3251
|
+
/** This alias's world as recorded at open/attach — what a `TaskRun`
|
|
3252
|
+
* filing needs to name, without exposing the whole map. */
|
|
1885
3253
|
worldRef(alias) {
|
|
1886
|
-
return this.worlds[alias] ?? { slug: "", ref: null };
|
|
3254
|
+
return this.worlds[alias] ?? { slug: "", ref: null, private: null };
|
|
1887
3255
|
}
|
|
1888
3256
|
/** The aliases, in the spec's order. */
|
|
1889
3257
|
get aliases() {
|
|
@@ -2253,15 +3621,15 @@ function resolveUserId() {
|
|
|
2253
3621
|
const envUser = process.env.GATEWAY_USER_ID?.trim();
|
|
2254
3622
|
return envUser ? envUser : void 0;
|
|
2255
3623
|
}
|
|
2256
|
-
var
|
|
3624
|
+
var import_async_hooks2, import_api, USER_ID_ATTRIBUTE, currentUserStorage, IdentitySpanProcessor;
|
|
2257
3625
|
var init_identity = __esm({
|
|
2258
3626
|
"src/tracing/identity.ts"() {
|
|
2259
3627
|
"use strict";
|
|
2260
|
-
|
|
3628
|
+
import_async_hooks2 = require("async_hooks");
|
|
2261
3629
|
import_api = require("@opentelemetry/api");
|
|
2262
3630
|
init_users();
|
|
2263
3631
|
USER_ID_ATTRIBUTE = "gateway.user.id";
|
|
2264
|
-
currentUserStorage = new
|
|
3632
|
+
currentUserStorage = new import_async_hooks2.AsyncLocalStorage();
|
|
2265
3633
|
IdentitySpanProcessor = class {
|
|
2266
3634
|
onStart(span, _parentContext) {
|
|
2267
3635
|
const userId = resolveUserId();
|
|
@@ -2279,43 +3647,224 @@ var init_identity = __esm({
|
|
|
2279
3647
|
}
|
|
2280
3648
|
});
|
|
2281
3649
|
|
|
2282
|
-
// src/tracing/
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
}
|
|
2290
|
-
|
|
2291
|
-
return
|
|
3650
|
+
// src/tracing/secrets.ts
|
|
3651
|
+
function jsonOrUndefined(text2) {
|
|
3652
|
+
let parsed;
|
|
3653
|
+
try {
|
|
3654
|
+
parsed = JSON.parse(text2);
|
|
3655
|
+
} catch {
|
|
3656
|
+
return void 0;
|
|
3657
|
+
}
|
|
3658
|
+
if (typeof parsed === "string") return parsed;
|
|
3659
|
+
return parsed !== null && typeof parsed === "object" ? parsed : void 0;
|
|
2292
3660
|
}
|
|
2293
|
-
function
|
|
2294
|
-
return
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
3661
|
+
function encodings(value) {
|
|
3662
|
+
return [value, percentEncoded(value), JSON.stringify(value).slice(1, -1)];
|
|
3663
|
+
}
|
|
3664
|
+
function percentEncoded(value) {
|
|
3665
|
+
try {
|
|
3666
|
+
return encodeURIComponent(value);
|
|
3667
|
+
} catch {
|
|
3668
|
+
return value;
|
|
3669
|
+
}
|
|
3670
|
+
}
|
|
3671
|
+
function union(sets) {
|
|
3672
|
+
return new Set(sets.flatMap((set) => [...set]));
|
|
3673
|
+
}
|
|
3674
|
+
function leaves(value) {
|
|
3675
|
+
if (typeof value === "string") {
|
|
3676
|
+
return [...value].length >= MIN_SECRET_LENGTH ? /* @__PURE__ */ new Set([value]) : /* @__PURE__ */ new Set();
|
|
3677
|
+
}
|
|
3678
|
+
if (Array.isArray(value)) return union(value.map(leaves));
|
|
3679
|
+
if (value === null || typeof value !== "object") return /* @__PURE__ */ new Set();
|
|
3680
|
+
return union(Object.values(value).map(leaves));
|
|
3681
|
+
}
|
|
3682
|
+
function sameAttributes(before, after) {
|
|
3683
|
+
const keys = Object.keys(before);
|
|
3684
|
+
if (keys.length !== Object.keys(after).length) return false;
|
|
3685
|
+
return keys.every(
|
|
3686
|
+
(key) => before[key] === after[key] || sameArray(before[key], after[key])
|
|
3687
|
+
);
|
|
3688
|
+
}
|
|
3689
|
+
function sameArray(before, after) {
|
|
3690
|
+
if (!Array.isArray(before) || !Array.isArray(after)) return false;
|
|
3691
|
+
return before.length === after.length && before.every((item, i) => item === after[i]);
|
|
3692
|
+
}
|
|
3693
|
+
function scrubbedRead(reads, property) {
|
|
3694
|
+
return typeof property === "string" && property in reads ? reads[property] : void 0;
|
|
3695
|
+
}
|
|
3696
|
+
function viewOf(span, reads) {
|
|
3697
|
+
const view = new Proxy(span, {
|
|
3698
|
+
get(target, property) {
|
|
3699
|
+
const read = scrubbedRead(reads, property);
|
|
3700
|
+
if (read) return read();
|
|
3701
|
+
const value = Reflect.get(target, property, target);
|
|
3702
|
+
if (typeof value !== "function") return value;
|
|
3703
|
+
return (...args) => {
|
|
3704
|
+
const result = value.apply(target, args);
|
|
3705
|
+
return result === target ? view : result;
|
|
3706
|
+
};
|
|
3707
|
+
},
|
|
3708
|
+
getOwnPropertyDescriptor(target, property) {
|
|
3709
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, property);
|
|
3710
|
+
const read = scrubbedRead(reads, property);
|
|
3711
|
+
if (!read || !descriptor || !("value" in descriptor)) return descriptor;
|
|
3712
|
+
return { ...descriptor, value: read() };
|
|
3713
|
+
}
|
|
2298
3714
|
});
|
|
3715
|
+
return view;
|
|
2299
3716
|
}
|
|
2300
|
-
var
|
|
2301
|
-
var
|
|
2302
|
-
"src/tracing/
|
|
3717
|
+
var SECRET_KEYS, REDACTED2, MIN_SECRET_LENGTH, SpanSecrets, SPAN_SECRETS, SecretRedactingSpanProcessor;
|
|
3718
|
+
var init_secrets = __esm({
|
|
3719
|
+
"src/tracing/secrets.ts"() {
|
|
2303
3720
|
"use strict";
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
3721
|
+
SECRET_KEYS = /* @__PURE__ */ new Set([
|
|
3722
|
+
"authorization_token",
|
|
3723
|
+
"authorizationToken"
|
|
3724
|
+
]);
|
|
3725
|
+
REDACTED2 = "[redacted: holds a credential]";
|
|
3726
|
+
MIN_SECRET_LENGTH = 8;
|
|
3727
|
+
SpanSecrets = class {
|
|
3728
|
+
constructor(keys = SECRET_KEYS) {
|
|
3729
|
+
this.keys = keys;
|
|
3730
|
+
}
|
|
3731
|
+
keys;
|
|
3732
|
+
isSecret(key) {
|
|
3733
|
+
return this.keys.has(key);
|
|
3734
|
+
}
|
|
3735
|
+
drops(attribute) {
|
|
3736
|
+
return this.mentions(attribute);
|
|
3737
|
+
}
|
|
3738
|
+
strip(value) {
|
|
3739
|
+
if (typeof value === "string") return this.stripNested(value);
|
|
3740
|
+
if (Array.isArray(value)) return value.map((item) => this.strip(item));
|
|
3741
|
+
if (value === null || typeof value !== "object") return value;
|
|
3742
|
+
return Object.fromEntries(
|
|
3743
|
+
Object.entries(value).filter(([key]) => !this.isSecret(key)).map(([key, item]) => [key, this.strip(item)])
|
|
3744
|
+
);
|
|
3745
|
+
}
|
|
3746
|
+
scrubAttribute(value) {
|
|
3747
|
+
try {
|
|
3748
|
+
return this.scrubbedValue(value);
|
|
3749
|
+
} catch {
|
|
3750
|
+
return Array.isArray(value) ? [REDACTED2] : REDACTED2;
|
|
2312
3751
|
}
|
|
2313
3752
|
}
|
|
2314
|
-
|
|
3753
|
+
scrubbedValue(value) {
|
|
3754
|
+
if (typeof value === "string") return this.scrubbedText(value);
|
|
3755
|
+
if (!Array.isArray(value)) return value;
|
|
3756
|
+
const results = value.map(
|
|
3757
|
+
(item) => typeof item === "string" ? this.cleaned(item) : { text: item, removed: /* @__PURE__ */ new Set() }
|
|
3758
|
+
);
|
|
3759
|
+
const removed = new Set(results.flatMap((r) => [...r.removed]));
|
|
3760
|
+
const scrubbed = results.map((r) => r.text);
|
|
3761
|
+
const withheld = scrubbed.some(
|
|
3762
|
+
(item) => typeof item === "string" && this.carries(item, removed)
|
|
3763
|
+
);
|
|
3764
|
+
return withheld ? [REDACTED2] : scrubbed;
|
|
2315
3765
|
}
|
|
2316
|
-
|
|
3766
|
+
scrubAttributes(attributes) {
|
|
3767
|
+
return Object.fromEntries(
|
|
3768
|
+
Object.entries(attributes).filter(([key]) => !this.drops(key)).map(([key, value]) => [key, this.scrubAttribute(value)])
|
|
3769
|
+
);
|
|
2317
3770
|
}
|
|
2318
|
-
|
|
3771
|
+
mentions(text2) {
|
|
3772
|
+
return [...this.keys].some((key) => text2.includes(key));
|
|
3773
|
+
}
|
|
3774
|
+
scrubbedText(text2) {
|
|
3775
|
+
const { text: cleaned, removed } = this.cleaned(text2);
|
|
3776
|
+
return this.carries(cleaned, removed) ? REDACTED2 : cleaned;
|
|
3777
|
+
}
|
|
3778
|
+
cleaned(text2) {
|
|
3779
|
+
if (!this.mentions(text2)) return { text: text2, removed: /* @__PURE__ */ new Set() };
|
|
3780
|
+
const parsed = jsonOrUndefined(text2);
|
|
3781
|
+
if (parsed === void 0) return { text: REDACTED2, removed: /* @__PURE__ */ new Set() };
|
|
3782
|
+
return {
|
|
3783
|
+
text: JSON.stringify(this.strip(parsed)),
|
|
3784
|
+
removed: this.removed(parsed)
|
|
3785
|
+
};
|
|
3786
|
+
}
|
|
3787
|
+
carries(text2, removed) {
|
|
3788
|
+
if (text2 === REDACTED2 || this.mentions(text2)) return true;
|
|
3789
|
+
return [...removed].some(
|
|
3790
|
+
(value) => encodings(value).some((form) => text2.includes(form))
|
|
3791
|
+
);
|
|
3792
|
+
}
|
|
3793
|
+
removed(value) {
|
|
3794
|
+
if (typeof value === "string") {
|
|
3795
|
+
const nested = this.mentions(value) ? jsonOrUndefined(value) : void 0;
|
|
3796
|
+
return nested === void 0 ? /* @__PURE__ */ new Set() : this.removed(nested);
|
|
3797
|
+
}
|
|
3798
|
+
if (Array.isArray(value)) return union(value.map((v) => this.removed(v)));
|
|
3799
|
+
if (value === null || typeof value !== "object") return /* @__PURE__ */ new Set();
|
|
3800
|
+
return union(
|
|
3801
|
+
Object.entries(value).map(
|
|
3802
|
+
([key, item]) => this.isSecret(key) ? leaves(item) : this.removed(item)
|
|
3803
|
+
)
|
|
3804
|
+
);
|
|
3805
|
+
}
|
|
3806
|
+
stripNested(text2) {
|
|
3807
|
+
if (!this.mentions(text2)) return text2;
|
|
3808
|
+
const parsed = jsonOrUndefined(text2);
|
|
3809
|
+
if (parsed === void 0) return text2;
|
|
3810
|
+
return JSON.stringify(this.strip(parsed));
|
|
3811
|
+
}
|
|
3812
|
+
};
|
|
3813
|
+
SPAN_SECRETS = new SpanSecrets();
|
|
3814
|
+
SecretRedactingSpanProcessor = class {
|
|
3815
|
+
constructor(inner, secrets = SPAN_SECRETS) {
|
|
3816
|
+
this.inner = inner;
|
|
3817
|
+
this.secrets = secrets;
|
|
3818
|
+
}
|
|
3819
|
+
inner;
|
|
3820
|
+
secrets;
|
|
3821
|
+
views = /* @__PURE__ */ new WeakMap();
|
|
3822
|
+
onStart(span, parentContext) {
|
|
3823
|
+
this.inner.onStart(this.viewFor(span), parentContext);
|
|
3824
|
+
}
|
|
3825
|
+
onEnd(span) {
|
|
3826
|
+
const view = this.viewFor(span);
|
|
3827
|
+
try {
|
|
3828
|
+
void [view.attributes, view.events, view.status];
|
|
3829
|
+
} catch (error) {
|
|
3830
|
+
console.warn(
|
|
3831
|
+
`[gatewaysdk.tracing] Dropped span "${span.name}": could not redact it: ${error?.name}`
|
|
3832
|
+
);
|
|
3833
|
+
return;
|
|
3834
|
+
}
|
|
3835
|
+
this.inner.onEnd(view);
|
|
3836
|
+
}
|
|
3837
|
+
viewFor(span) {
|
|
3838
|
+
const known = this.views.get(span);
|
|
3839
|
+
if (known) return known;
|
|
3840
|
+
const view = viewOf(span, {
|
|
3841
|
+
attributes: () => this.scrubbedAttributes(span.attributes),
|
|
3842
|
+
events: () => span.events.map((event) => this.scrubbedEvent(event)),
|
|
3843
|
+
status: () => this.scrubbedStatus(span.status)
|
|
3844
|
+
});
|
|
3845
|
+
this.views.set(span, view);
|
|
3846
|
+
return view;
|
|
3847
|
+
}
|
|
3848
|
+
forceFlush() {
|
|
3849
|
+
return this.inner.forceFlush();
|
|
3850
|
+
}
|
|
3851
|
+
shutdown() {
|
|
3852
|
+
return this.inner.shutdown();
|
|
3853
|
+
}
|
|
3854
|
+
scrubbedAttributes(attributes) {
|
|
3855
|
+
const clean = this.secrets.scrubAttributes(attributes);
|
|
3856
|
+
return sameAttributes(attributes, clean) ? attributes : clean;
|
|
3857
|
+
}
|
|
3858
|
+
scrubbedStatus(status) {
|
|
3859
|
+
if (!status.message) return status;
|
|
3860
|
+
const message = this.secrets.scrubAttribute(status.message);
|
|
3861
|
+
return message === status.message ? status : { ...status, message };
|
|
3862
|
+
}
|
|
3863
|
+
scrubbedEvent(event) {
|
|
3864
|
+
if (!event.attributes) return event;
|
|
3865
|
+
const attributes = this.scrubbedAttributes(event.attributes);
|
|
3866
|
+
if (attributes === event.attributes) return event;
|
|
3867
|
+
return { ...event, attributes };
|
|
2319
3868
|
}
|
|
2320
3869
|
};
|
|
2321
3870
|
}
|
|
@@ -2542,7 +4091,7 @@ var require_package = __commonJS({
|
|
|
2542
4091
|
"package.json"(exports2, module2) {
|
|
2543
4092
|
module2.exports = {
|
|
2544
4093
|
name: "@withgateway/sdk",
|
|
2545
|
-
version: "0.
|
|
4094
|
+
version: "0.3.0",
|
|
2546
4095
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
2547
4096
|
main: "./dist/index.js",
|
|
2548
4097
|
module: "./dist/index.mjs",
|
|
@@ -2753,7 +4302,7 @@ function canonicalJson(value) {
|
|
|
2753
4302
|
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonicalJson(v)}`).join(",")}}`;
|
|
2754
4303
|
}
|
|
2755
4304
|
function sha256(text2) {
|
|
2756
|
-
return `sha256:${(0,
|
|
4305
|
+
return `sha256:${(0, import_node_crypto3.createHash)("sha256").update(text2).digest("hex")}`;
|
|
2757
4306
|
}
|
|
2758
4307
|
function getRegisteredTools() {
|
|
2759
4308
|
return [...registeredTools.values()].sort(
|
|
@@ -2928,11 +4477,11 @@ async function registerBuild(params) {
|
|
|
2928
4477
|
);
|
|
2929
4478
|
}
|
|
2930
4479
|
}
|
|
2931
|
-
var
|
|
4480
|
+
var import_node_crypto3, registeredTools, registeredPrompts, registeredSkills, registeredArtifacts, activeBuilds;
|
|
2932
4481
|
var init_build = __esm({
|
|
2933
4482
|
"src/build/index.ts"() {
|
|
2934
4483
|
"use strict";
|
|
2935
|
-
|
|
4484
|
+
import_node_crypto3 = require("crypto");
|
|
2936
4485
|
registeredTools = /* @__PURE__ */ new Map();
|
|
2937
4486
|
registeredPrompts = /* @__PURE__ */ new Map();
|
|
2938
4487
|
registeredSkills = /* @__PURE__ */ new Map();
|
|
@@ -3062,7 +4611,7 @@ function buildProvider(config, logFn) {
|
|
|
3062
4611
|
const spanProcessors = [];
|
|
3063
4612
|
if (config.customSpanProcessors) {
|
|
3064
4613
|
for (const sp of config.customSpanProcessors) {
|
|
3065
|
-
spanProcessors.push(sp);
|
|
4614
|
+
spanProcessors.push(new SecretRedactingSpanProcessor(sp));
|
|
3066
4615
|
logFn(
|
|
3067
4616
|
"Added custom span processor: %s",
|
|
3068
4617
|
sp.constructor?.name ?? "unknown"
|
|
@@ -3081,7 +4630,11 @@ function buildProvider(config, logFn) {
|
|
|
3081
4630
|
if (config.batch?.maxExportBatchSize) {
|
|
3082
4631
|
batchConfig.maxExportBatchSize = config.batch.maxExportBatchSize;
|
|
3083
4632
|
}
|
|
3084
|
-
spanProcessors.push(
|
|
4633
|
+
spanProcessors.push(
|
|
4634
|
+
new SecretRedactingSpanProcessor(
|
|
4635
|
+
new BatchSpanProcessor(exporter, batchConfig)
|
|
4636
|
+
)
|
|
4637
|
+
);
|
|
3085
4638
|
let provider = new NodeTracerProvider({
|
|
3086
4639
|
resource: createResource(resourceAttrs)
|
|
3087
4640
|
});
|
|
@@ -3219,7 +4772,8 @@ var init_init = __esm({
|
|
|
3219
4772
|
"src/tracing/init.ts"() {
|
|
3220
4773
|
"use strict";
|
|
3221
4774
|
init_identity();
|
|
3222
|
-
|
|
4775
|
+
init_secrets();
|
|
4776
|
+
init_session();
|
|
3223
4777
|
init_scores();
|
|
3224
4778
|
init_build();
|
|
3225
4779
|
ENV_VARS = {
|
|
@@ -3334,7 +4888,7 @@ function reportFromResult(result) {
|
|
|
3334
4888
|
return { report, extra };
|
|
3335
4889
|
}
|
|
3336
4890
|
async function runTask(ref, agent, opts) {
|
|
3337
|
-
const runId = `wtr-${(0,
|
|
4891
|
+
const runId = `wtr-${(0, import_node_crypto4.randomBytes)(6).toString("hex")}`;
|
|
3338
4892
|
const outDir = opts.outDir ?? "runs";
|
|
3339
4893
|
const runDir = path.join(outDir, runId);
|
|
3340
4894
|
fs.mkdirSync(runDir, { recursive: true });
|
|
@@ -3372,7 +4926,7 @@ async function runTask(ref, agent, opts) {
|
|
|
3372
4926
|
let extra = {};
|
|
3373
4927
|
try {
|
|
3374
4928
|
const invoke = () => agent(taskRun);
|
|
3375
|
-
const result = traced ? await (await Promise.resolve().then(() => (
|
|
4929
|
+
const result = traced ? await (await Promise.resolve().then(() => (init_session(), session_exports))).withSession(runId, invoke) : await invoke();
|
|
3376
4930
|
({ report, extra } = reportFromResult(result));
|
|
3377
4931
|
} catch (error) {
|
|
3378
4932
|
const message = (error instanceof Error ? error.message : String(error)) || "Unknown error";
|
|
@@ -3439,16 +4993,16 @@ async function runTask(ref, agent, opts) {
|
|
|
3439
4993
|
}
|
|
3440
4994
|
}
|
|
3441
4995
|
}
|
|
3442
|
-
var
|
|
4996
|
+
var import_node_crypto4, fs, path, TaskRun, describeValue, RESULT_CONTRACT;
|
|
3443
4997
|
var init_taskRun = __esm({
|
|
3444
4998
|
"src/worlds/taskRun.ts"() {
|
|
3445
4999
|
"use strict";
|
|
3446
|
-
|
|
5000
|
+
import_node_crypto4 = require("crypto");
|
|
3447
5001
|
fs = __toESM(require("fs"));
|
|
3448
5002
|
path = __toESM(require("path"));
|
|
3449
5003
|
init_browser();
|
|
3450
5004
|
init_evals();
|
|
3451
|
-
|
|
5005
|
+
init_session2();
|
|
3452
5006
|
init_taskSessions();
|
|
3453
5007
|
TaskRun = class {
|
|
3454
5008
|
constructor(runId, instruction, model, sessions, manifest) {
|
|
@@ -3757,11 +5311,11 @@ var init_checkoutTarget = __esm({
|
|
|
3757
5311
|
});
|
|
3758
5312
|
|
|
3759
5313
|
// src/worlds/worldDir.ts
|
|
3760
|
-
var
|
|
5314
|
+
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
5315
|
var init_worldDir = __esm({
|
|
3762
5316
|
"src/worlds/worldDir.ts"() {
|
|
3763
5317
|
"use strict";
|
|
3764
|
-
|
|
5318
|
+
import_node_crypto5 = require("crypto");
|
|
3765
5319
|
fs3 = __toESM(require("fs"));
|
|
3766
5320
|
path3 = __toESM(require("path"));
|
|
3767
5321
|
WORLD_MANIFEST = "gateway-env.toml";
|
|
@@ -3867,7 +5421,7 @@ var init_worldDir = __esm({
|
|
|
3867
5421
|
* sorted order: the version's identity, byte-compatible with
|
|
3868
5422
|
* `_archive.compute_content_hash` and Prime Intellect. */
|
|
3869
5423
|
get contentHash() {
|
|
3870
|
-
const hasher = (0,
|
|
5424
|
+
const hasher = (0, import_node_crypto5.createHash)("sha256");
|
|
3871
5425
|
for (const rel of this.archivePaths) {
|
|
3872
5426
|
hasher.update(Buffer.from(`file:${rel}`, "utf-8"));
|
|
3873
5427
|
hasher.update(fs3.readFileSync(path3.join(this.dir, rel)));
|
|
@@ -4171,7 +5725,7 @@ function writeLocalMeta(dir, meta) {
|
|
|
4171
5725
|
function snapshotTreeHashes(dir) {
|
|
4172
5726
|
const out = {};
|
|
4173
5727
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
4174
|
-
out[relPath] = (0,
|
|
5728
|
+
out[relPath] = (0, import_node_crypto6.createHash)("sha256").update(fs5.readFileSync(path5.join(dir, relPath))).digest("hex");
|
|
4175
5729
|
}
|
|
4176
5730
|
return out;
|
|
4177
5731
|
}
|
|
@@ -4217,7 +5771,7 @@ function buildFileManifest(dir) {
|
|
|
4217
5771
|
path: relPath,
|
|
4218
5772
|
isDirectory: false,
|
|
4219
5773
|
size: payload.length,
|
|
4220
|
-
sha256: (0,
|
|
5774
|
+
sha256: (0, import_node_crypto6.createHash)("sha256").update(payload).digest("hex")
|
|
4221
5775
|
};
|
|
4222
5776
|
});
|
|
4223
5777
|
}
|
|
@@ -4416,11 +5970,11 @@ async function createRef(slug, name, kind, versionId, options = {}) {
|
|
|
4416
5970
|
...versionId ? { versionId } : {}
|
|
4417
5971
|
});
|
|
4418
5972
|
}
|
|
4419
|
-
var
|
|
5973
|
+
var import_node_crypto6, import_node_zlib2, fs5, path5, DEFAULT_BRANCH, META_RELPATH, FILE_MODE, MINTED_SUFFIX, PushSlugConflict, sha256b64, DetachedPushError;
|
|
4420
5974
|
var init_hub = __esm({
|
|
4421
5975
|
"src/worlds/hub.ts"() {
|
|
4422
5976
|
"use strict";
|
|
4423
|
-
|
|
5977
|
+
import_node_crypto6 = require("crypto");
|
|
4424
5978
|
import_node_zlib2 = require("zlib");
|
|
4425
5979
|
fs5 = __toESM(require("fs"));
|
|
4426
5980
|
path5 = __toESM(require("path"));
|
|
@@ -4446,7 +6000,7 @@ var init_hub = __esm({
|
|
|
4446
6000
|
tracked;
|
|
4447
6001
|
declared;
|
|
4448
6002
|
};
|
|
4449
|
-
sha256b64 = (data) => (0,
|
|
6003
|
+
sha256b64 = (data) => (0, import_node_crypto6.createHash)("sha256").update(data).digest("base64");
|
|
4450
6004
|
DetachedPushError = class extends Error {
|
|
4451
6005
|
constructor(dir, tag) {
|
|
4452
6006
|
super(
|
|
@@ -5090,11 +6644,11 @@ function applyTransforms(value, chain) {
|
|
|
5090
6644
|
for (const step of steps) out = step(out);
|
|
5091
6645
|
return out;
|
|
5092
6646
|
}
|
|
5093
|
-
var
|
|
6647
|
+
var import_node_crypto7, WHITESPACE, WHITESPACE_EDGES, WHITESPACE_RUN, NOT_DIGIT, STRIP_PREFIX, trim, emailLocalPart, emailDomain, stripPrefix, hex, SIMPLE, TRANSFORMS, text;
|
|
5094
6648
|
var init_transforms = __esm({
|
|
5095
6649
|
"src/worlds/transforms.ts"() {
|
|
5096
6650
|
"use strict";
|
|
5097
|
-
|
|
6651
|
+
import_node_crypto7 = require("crypto");
|
|
5098
6652
|
init_json();
|
|
5099
6653
|
WHITESPACE = " \n\r\f\v";
|
|
5100
6654
|
WHITESPACE_EDGES = new RegExp(`^[${WHITESPACE}]+|[${WHITESPACE}]+$`, "g");
|
|
@@ -5111,7 +6665,7 @@ var init_transforms = __esm({
|
|
|
5111
6665
|
return at === -1 ? "" : value.slice(at + 1).toLowerCase();
|
|
5112
6666
|
};
|
|
5113
6667
|
stripPrefix = (prefix) => (value) => value.startsWith(prefix) ? value.slice(prefix.length) : value;
|
|
5114
|
-
hex = (algorithm, value) => (0,
|
|
6668
|
+
hex = (algorithm, value) => (0, import_node_crypto7.createHash)(algorithm).update(value, "utf8").digest("hex");
|
|
5115
6669
|
SIMPLE = {
|
|
5116
6670
|
lower: (value) => value.toLowerCase(),
|
|
5117
6671
|
upper: (value) => value.toUpperCase(),
|
|
@@ -5143,7 +6697,7 @@ function pyText(value) {
|
|
|
5143
6697
|
return pyFloatRepr(value);
|
|
5144
6698
|
}
|
|
5145
6699
|
function hashForm(slug, plaintext) {
|
|
5146
|
-
return "sha256:" + (0,
|
|
6700
|
+
return "sha256:" + (0, import_node_crypto8.createHash)("sha256").update(`${slug}:${pyText(plaintext)}`, "utf8").digest("hex");
|
|
5147
6701
|
}
|
|
5148
6702
|
function preserveForm(slug, plaintext) {
|
|
5149
6703
|
const kind = typeof plaintext === "string" ? "str" : isInt(plaintext) ? "int" : "float";
|
|
@@ -5152,12 +6706,12 @@ function preserveForm(slug, plaintext) {
|
|
|
5152
6706
|
}
|
|
5153
6707
|
function shapeText(slug, text2, kind) {
|
|
5154
6708
|
const seed = Buffer.from(`${slug}:${text2}`, "utf8");
|
|
5155
|
-
let digest = (0,
|
|
6709
|
+
let digest = (0, import_node_crypto8.createHash)("sha256").update(seed).digest();
|
|
5156
6710
|
let cursor = 0;
|
|
5157
6711
|
const out = [];
|
|
5158
6712
|
for (const char of text2) {
|
|
5159
6713
|
if (cursor === digest.length) {
|
|
5160
|
-
digest = (0,
|
|
6714
|
+
digest = (0, import_node_crypto8.createHash)("sha256").update(Buffer.concat([digest, seed])).digest();
|
|
5161
6715
|
cursor = 0;
|
|
5162
6716
|
}
|
|
5163
6717
|
const byte = digest[cursor];
|
|
@@ -5194,11 +6748,11 @@ function storedForms(world, field2, plaintext, transform) {
|
|
|
5194
6748
|
if (policy !== null) return [roundForm(plaintext, world.redact.round[field2])];
|
|
5195
6749
|
return [plaintext];
|
|
5196
6750
|
}
|
|
5197
|
-
var
|
|
6751
|
+
var import_node_crypto8, isInt;
|
|
5198
6752
|
var init_redaction = __esm({
|
|
5199
6753
|
"src/worlds/redaction.ts"() {
|
|
5200
6754
|
"use strict";
|
|
5201
|
-
|
|
6755
|
+
import_node_crypto8 = require("crypto");
|
|
5202
6756
|
init_json();
|
|
5203
6757
|
init_transforms();
|
|
5204
6758
|
isInt = (value) => typeof value === "number" && Number.isInteger(value);
|
|
@@ -6067,7 +7621,7 @@ function uploadHeadersFor(gz) {
|
|
|
6067
7621
|
return {
|
|
6068
7622
|
"content-type": "application/gzip",
|
|
6069
7623
|
"content-length": String(gz.length),
|
|
6070
|
-
"x-amz-checksum-sha256": (0,
|
|
7624
|
+
"x-amz-checksum-sha256": (0, import_node_crypto9.createHash)("sha256").update(gz).digest("base64")
|
|
6071
7625
|
};
|
|
6072
7626
|
}
|
|
6073
7627
|
async function forEachLimited(items, limit, fn) {
|
|
@@ -6113,11 +7667,11 @@ function phaseLine(status) {
|
|
|
6113
7667
|
const phase = status.progress?.phase;
|
|
6114
7668
|
return phase ? `${status.state} (${phase})` : status.state;
|
|
6115
7669
|
}
|
|
6116
|
-
var
|
|
7670
|
+
var import_node_crypto9, fs11, TERMINAL_STATES, sleepMs, WorldDataApi;
|
|
6117
7671
|
var init_batches = __esm({
|
|
6118
7672
|
"src/cli/platform/worldData/batches.ts"() {
|
|
6119
7673
|
"use strict";
|
|
6120
|
-
|
|
7674
|
+
import_node_crypto9 = require("crypto");
|
|
6121
7675
|
fs11 = __toESM(require("fs"));
|
|
6122
7676
|
init_config();
|
|
6123
7677
|
init_router();
|
|
@@ -6311,12 +7865,12 @@ function finishChunk(ordinal, raw, rows, entity, firstRow = 0) {
|
|
|
6311
7865
|
const gz = gzipDeterministic(raw, { name: chunkName(ordinal) });
|
|
6312
7866
|
return {
|
|
6313
7867
|
ordinal,
|
|
6314
|
-
digest: (0,
|
|
7868
|
+
digest: (0, import_node_crypto10.createHash)("sha256").update(gz).digest("hex"),
|
|
6315
7869
|
bytes: gz.length,
|
|
6316
7870
|
rows,
|
|
6317
7871
|
entity,
|
|
6318
7872
|
rawBytes: raw.length,
|
|
6319
|
-
contentSha256: (0,
|
|
7873
|
+
contentSha256: (0, import_node_crypto10.createHash)("sha256").update(raw).digest("hex"),
|
|
6320
7874
|
firstRow,
|
|
6321
7875
|
gz
|
|
6322
7876
|
};
|
|
@@ -6356,11 +7910,11 @@ function crc32(data) {
|
|
|
6356
7910
|
crc = table[(crc ^ data[i]) & 255] ^ crc >>> 8;
|
|
6357
7911
|
return (crc ^ 4294967295) >>> 0;
|
|
6358
7912
|
}
|
|
6359
|
-
var
|
|
7913
|
+
var import_node_crypto10, import_node_zlib3, DEFAULT_CHUNK_BYTES, GZIP_LEVEL, chunkName, table;
|
|
6360
7914
|
var init_chunker = __esm({
|
|
6361
7915
|
"src/cli/platform/worldData/chunker.ts"() {
|
|
6362
7916
|
"use strict";
|
|
6363
|
-
|
|
7917
|
+
import_node_crypto10 = require("crypto");
|
|
6364
7918
|
import_node_zlib3 = require("zlib");
|
|
6365
7919
|
init_json();
|
|
6366
7920
|
DEFAULT_CHUNK_BYTES = 64 * 1024 * 1024;
|
|
@@ -6655,7 +8209,7 @@ var init_ingest = __esm({
|
|
|
6655
8209
|
});
|
|
6656
8210
|
|
|
6657
8211
|
// src/worlds/editSessions.ts
|
|
6658
|
-
var WORLDS, WorldEditClient;
|
|
8212
|
+
var WORLDS, WorldEditClient, TASK_EDITS, TaskEditClient;
|
|
6659
8213
|
var init_editSessions = __esm({
|
|
6660
8214
|
"src/worlds/editSessions.ts"() {
|
|
6661
8215
|
"use strict";
|
|
@@ -6687,6 +8241,22 @@ var init_editSessions = __esm({
|
|
|
6687
8241
|
return apiRequest(this.options, "POST", `${WORLDS}/${encodeURIComponent(slug)}/edits/rollback`, input);
|
|
6688
8242
|
}
|
|
6689
8243
|
};
|
|
8244
|
+
TASK_EDITS = "/api/public/world-task-edits";
|
|
8245
|
+
TaskEditClient = class {
|
|
8246
|
+
constructor(options = {}) {
|
|
8247
|
+
this.options = options;
|
|
8248
|
+
}
|
|
8249
|
+
options;
|
|
8250
|
+
status(task) {
|
|
8251
|
+
return apiRequest(this.options, "POST", `${TASK_EDITS}/status`, { task });
|
|
8252
|
+
}
|
|
8253
|
+
close(task, input = {}) {
|
|
8254
|
+
return apiRequest(this.options, "POST", `${TASK_EDITS}/close`, { task, ...input });
|
|
8255
|
+
}
|
|
8256
|
+
rollback(task, input) {
|
|
8257
|
+
return apiRequest(this.options, "POST", `${TASK_EDITS}/rollback`, { task, ...input });
|
|
8258
|
+
}
|
|
8259
|
+
};
|
|
6690
8260
|
}
|
|
6691
8261
|
});
|
|
6692
8262
|
|
|
@@ -6782,6 +8352,10 @@ var init_dryRun = __esm({
|
|
|
6782
8352
|
// src/worlds/index.ts
|
|
6783
8353
|
var worlds_exports = {};
|
|
6784
8354
|
__export(worlds_exports, {
|
|
8355
|
+
ACTION_NAMES: () => ACTION_NAMES,
|
|
8356
|
+
ActionTracer: () => ActionTracer,
|
|
8357
|
+
AnthropicComputer: () => AnthropicComputer,
|
|
8358
|
+
AnthropicComputer20251124: () => AnthropicComputer20251124,
|
|
6785
8359
|
ApiError: () => ApiError,
|
|
6786
8360
|
BROWSER_GONE_PATTERNS: () => BROWSER_GONE_PATTERNS,
|
|
6787
8361
|
BROWSER_TIERS: () => BROWSER_TIERS,
|
|
@@ -6793,11 +8367,13 @@ __export(worlds_exports, {
|
|
|
6793
8367
|
CALL_BODY_LIMIT_LABEL: () => CALL_BODY_LIMIT_LABEL,
|
|
6794
8368
|
COMPUTER_USE_SPECS: () => COMPUTER_USE_SPECS,
|
|
6795
8369
|
CheckoutProvenance: () => CheckoutProvenance,
|
|
8370
|
+
ComputerAction: () => ComputerAction,
|
|
6796
8371
|
DEFAULT_BRANCH: () => DEFAULT_BRANCH,
|
|
6797
8372
|
DEFAULT_VIEWPORT: () => DEFAULT_VIEWPORT,
|
|
6798
8373
|
DRY_RUN_AGENT: () => DRY_RUN_AGENT,
|
|
6799
8374
|
DRY_RUN_KIND: () => DRY_RUN_KIND,
|
|
6800
8375
|
DetachedPushError: () => DetachedPushError,
|
|
8376
|
+
Display: () => Display,
|
|
6801
8377
|
DryRunOutcome: () => DryRunOutcome,
|
|
6802
8378
|
EVENT_BATCH_SIZE: () => EVENT_BATCH_SIZE,
|
|
6803
8379
|
EVENT_FLUSH_INTERVAL_MS: () => EVENT_FLUSH_INTERVAL_MS,
|
|
@@ -6807,19 +8383,30 @@ __export(worlds_exports, {
|
|
|
6807
8383
|
GatewayEvalsClient: () => GatewayEvalsClient,
|
|
6808
8384
|
HostedDryRunClient: () => HostedDryRunClient,
|
|
6809
8385
|
IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
|
|
8386
|
+
KEY_NAMES: () => KEY_NAMES,
|
|
8387
|
+
KeyChord: () => KeyChord,
|
|
8388
|
+
NOT_EXECUTED: () => NOT_EXECUTED,
|
|
6810
8389
|
NO_GRADER_REASON: () => NO_GRADER_REASON,
|
|
8390
|
+
NativeComputer: () => NativeComputer,
|
|
8391
|
+
OpenAIComputer: () => OpenAIComputer,
|
|
8392
|
+
OpenAIPreviewComputer: () => OpenAIPreviewComputer,
|
|
6811
8393
|
PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
6812
8394
|
PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
|
|
8395
|
+
PendingSafetyChecks: () => PendingSafetyChecks,
|
|
6813
8396
|
PlatformTransport: () => PlatformTransport,
|
|
6814
8397
|
PushSlugConflict: () => PushSlugConflict,
|
|
6815
8398
|
RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
|
|
6816
8399
|
SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
|
|
8400
|
+
SECRET_KEY: () => SECRET_KEY,
|
|
6817
8401
|
SESSION_STATES: () => SESSION_STATES,
|
|
8402
|
+
SPAN_PREFIX: () => SPAN_PREFIX,
|
|
6818
8403
|
STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
|
|
6819
8404
|
STRIP_PREFIX: () => STRIP_PREFIX,
|
|
6820
8405
|
SURFACE_KINDS: () => SURFACE_KINDS,
|
|
8406
|
+
Screen: () => Screen,
|
|
6821
8407
|
SecretScrubber: () => SecretScrubber,
|
|
6822
8408
|
TRANSFORMS: () => TRANSFORMS,
|
|
8409
|
+
TaskEditClient: () => TaskEditClient,
|
|
6823
8410
|
TaskRun: () => TaskRun,
|
|
6824
8411
|
TaskSessions: () => TaskSessions,
|
|
6825
8412
|
TransportCause: () => TransportCause,
|
|
@@ -6892,6 +8479,7 @@ __export(worlds_exports, {
|
|
|
6892
8479
|
parseTransform: () => parseTransform,
|
|
6893
8480
|
parseWorldTaskRefs: () => parseWorldTaskRefs,
|
|
6894
8481
|
platformTimeoutMs: () => platformTimeoutMs,
|
|
8482
|
+
playwrightKey: () => playwrightKey,
|
|
6895
8483
|
preserveForm: () => preserveForm,
|
|
6896
8484
|
propose: () => propose,
|
|
6897
8485
|
pull: () => pull,
|
|
@@ -6901,6 +8489,7 @@ __export(worlds_exports, {
|
|
|
6901
8489
|
pyText: () => pyText,
|
|
6902
8490
|
queryRows: () => queryRows,
|
|
6903
8491
|
queryRowsSearch: () => queryRowsSearch,
|
|
8492
|
+
readField: () => readField,
|
|
6904
8493
|
readLocalMeta: () => readLocalMeta,
|
|
6905
8494
|
readToolCallRecords: () => readToolCallRecords,
|
|
6906
8495
|
rebaseConflicts: () => rebaseConflicts,
|
|
@@ -7150,7 +8739,7 @@ var init_worlds = __esm({
|
|
|
7150
8739
|
"src/worlds/index.ts"() {
|
|
7151
8740
|
init_transport();
|
|
7152
8741
|
init_transport();
|
|
7153
|
-
|
|
8742
|
+
init_session2();
|
|
7154
8743
|
init_sessionList();
|
|
7155
8744
|
init_sessionContract();
|
|
7156
8745
|
init_taskRef();
|
|
@@ -7162,6 +8751,7 @@ var init_worlds = __esm({
|
|
|
7162
8751
|
init_evals();
|
|
7163
8752
|
init_browser();
|
|
7164
8753
|
init_browserReconnect();
|
|
8754
|
+
init_nativeComputer();
|
|
7165
8755
|
init_hub();
|
|
7166
8756
|
init_validate();
|
|
7167
8757
|
init_describe();
|
|
@@ -7228,7 +8818,7 @@ var init_worlds = __esm({
|
|
|
7228
8818
|
* worlds/session.ts.
|
|
7229
8819
|
*/
|
|
7230
8820
|
async open(task, opts = {}) {
|
|
7231
|
-
const { openSession: openSession2 } = await Promise.resolve().then(() => (
|
|
8821
|
+
const { openSession: openSession2 } = await Promise.resolve().then(() => (init_session2(), session_exports2));
|
|
7232
8822
|
return openSession2(this.slug, {
|
|
7233
8823
|
task,
|
|
7234
8824
|
versionId: this.version.versionId,
|
|
@@ -7263,6 +8853,10 @@ var init_worlds = __esm({
|
|
|
7263
8853
|
init_worlds();
|
|
7264
8854
|
// Annotate the CommonJS export names for ESM import in node:
|
|
7265
8855
|
0 && (module.exports = {
|
|
8856
|
+
ACTION_NAMES,
|
|
8857
|
+
ActionTracer,
|
|
8858
|
+
AnthropicComputer,
|
|
8859
|
+
AnthropicComputer20251124,
|
|
7266
8860
|
ApiError,
|
|
7267
8861
|
BROWSER_GONE_PATTERNS,
|
|
7268
8862
|
BROWSER_TIERS,
|
|
@@ -7274,11 +8868,13 @@ init_worlds();
|
|
|
7274
8868
|
CALL_BODY_LIMIT_LABEL,
|
|
7275
8869
|
COMPUTER_USE_SPECS,
|
|
7276
8870
|
CheckoutProvenance,
|
|
8871
|
+
ComputerAction,
|
|
7277
8872
|
DEFAULT_BRANCH,
|
|
7278
8873
|
DEFAULT_VIEWPORT,
|
|
7279
8874
|
DRY_RUN_AGENT,
|
|
7280
8875
|
DRY_RUN_KIND,
|
|
7281
8876
|
DetachedPushError,
|
|
8877
|
+
Display,
|
|
7282
8878
|
DryRunOutcome,
|
|
7283
8879
|
EVENT_BATCH_SIZE,
|
|
7284
8880
|
EVENT_FLUSH_INTERVAL_MS,
|
|
@@ -7288,19 +8884,30 @@ init_worlds();
|
|
|
7288
8884
|
GatewayEvalsClient,
|
|
7289
8885
|
HostedDryRunClient,
|
|
7290
8886
|
IDLE_WARNING_MINUTES,
|
|
8887
|
+
KEY_NAMES,
|
|
8888
|
+
KeyChord,
|
|
8889
|
+
NOT_EXECUTED,
|
|
7291
8890
|
NO_GRADER_REASON,
|
|
8891
|
+
NativeComputer,
|
|
8892
|
+
OpenAIComputer,
|
|
8893
|
+
OpenAIPreviewComputer,
|
|
7292
8894
|
PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
7293
8895
|
PLATFORM_TIMEOUT_ENV,
|
|
8896
|
+
PendingSafetyChecks,
|
|
7294
8897
|
PlatformTransport,
|
|
7295
8898
|
PushSlugConflict,
|
|
7296
8899
|
RECOVER_BUDGET_MS,
|
|
7297
8900
|
SANDBOX_REQUEST_TIMEOUT_MS,
|
|
8901
|
+
SECRET_KEY,
|
|
7298
8902
|
SESSION_STATES,
|
|
8903
|
+
SPAN_PREFIX,
|
|
7299
8904
|
STATUS_WAIT_CAP_SECONDS,
|
|
7300
8905
|
STRIP_PREFIX,
|
|
7301
8906
|
SURFACE_KINDS,
|
|
8907
|
+
Screen,
|
|
7302
8908
|
SecretScrubber,
|
|
7303
8909
|
TRANSFORMS,
|
|
8910
|
+
TaskEditClient,
|
|
7304
8911
|
TaskRun,
|
|
7305
8912
|
TaskSessions,
|
|
7306
8913
|
TransportCause,
|
|
@@ -7373,6 +8980,7 @@ init_worlds();
|
|
|
7373
8980
|
parseTransform,
|
|
7374
8981
|
parseWorldTaskRefs,
|
|
7375
8982
|
platformTimeoutMs,
|
|
8983
|
+
playwrightKey,
|
|
7376
8984
|
preserveForm,
|
|
7377
8985
|
propose,
|
|
7378
8986
|
pull,
|
|
@@ -7382,6 +8990,7 @@ init_worlds();
|
|
|
7382
8990
|
pyText,
|
|
7383
8991
|
queryRows,
|
|
7384
8992
|
queryRowsSearch,
|
|
8993
|
+
readField,
|
|
7385
8994
|
readLocalMeta,
|
|
7386
8995
|
readToolCallRecords,
|
|
7387
8996
|
rebaseConflicts,
|