@mantyx/sdk 0.15.1 → 0.17.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/CHANGELOG.md +15 -0
- package/README.md +4 -1
- package/dist/a2a-server.cjs.map +1 -1
- package/dist/a2a-server.d.cts +1 -1
- package/dist/a2a-server.d.ts +1 -1
- package/dist/a2a-server.js +1 -1
- package/dist/{chunk-YXTU725K.js → chunk-DNJYOHTJ.js} +66 -8
- package/dist/chunk-DNJYOHTJ.js.map +1 -0
- package/dist/{client-fu11V4HX.d.cts → client-IjrvboaL.d.cts} +63 -2
- package/dist/{client-fu11V4HX.d.ts → client-IjrvboaL.d.ts} +63 -2
- package/dist/computer-use-B9eNnX_y.d.ts +193 -0
- package/dist/computer-use-yH7ohjLl.d.cts +193 -0
- package/dist/index.cjs +432 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +362 -2
- package/dist/index.js.map +1 -1
- package/dist/playwright.cjs +139 -0
- package/dist/playwright.cjs.map +1 -0
- package/dist/playwright.d.cts +88 -0
- package/dist/playwright.d.ts +88 -0
- package/dist/playwright.js +113 -0
- package/dist/playwright.js.map +1 -0
- package/docs/agent-runs-protocol.md +63 -10
- package/docs/wire-protocol.md +26 -6
- package/package.json +12 -2
- package/dist/chunk-YXTU725K.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
AgentSession: () => AgentSession,
|
|
34
|
+
COMPUTER_USE_ACTIONS: () => COMPUTER_USE_ACTIONS,
|
|
34
35
|
DEFAULT_BASE_URL: () => DEFAULT_BASE_URL,
|
|
35
36
|
DEFAULT_OAUTH_BASE_URL: () => DEFAULT_OAUTH_BASE_URL,
|
|
36
37
|
DEFAULT_REFRESH_SKEW_MS: () => DEFAULT_REFRESH_SKEW_MS,
|
|
@@ -45,9 +46,13 @@ __export(index_exports, {
|
|
|
45
46
|
MantyxScopeError: () => MantyxScopeError,
|
|
46
47
|
MantyxToolError: () => MantyxToolError,
|
|
47
48
|
SDK_VERSION: () => SDK_VERSION,
|
|
49
|
+
buildComputerUseSystemPrompt: () => buildComputerUseSystemPrompt,
|
|
50
|
+
defineComputerUseTools: () => defineComputerUseTools,
|
|
48
51
|
defineLocalA2A: () => defineLocalA2A,
|
|
49
52
|
defineLocalMcp: () => defineLocalMcp,
|
|
50
53
|
defineLocalTool: () => defineLocalTool,
|
|
54
|
+
denormalizeCoordinate: () => denormalizeCoordinate,
|
|
55
|
+
extractActions: () => extractActions,
|
|
51
56
|
inputFileAttachment: () => inputFileAttachment,
|
|
52
57
|
inputFileUrlAttachment: () => inputFileUrlAttachment,
|
|
53
58
|
isLocalA2ATool: () => isLocalA2ATool,
|
|
@@ -60,6 +65,7 @@ __export(index_exports, {
|
|
|
60
65
|
parseRunOutput: () => parseRunOutput,
|
|
61
66
|
planOnly: () => planOnly,
|
|
62
67
|
readSseStream: () => readSseStream,
|
|
68
|
+
runComputerUse: () => runComputerUse,
|
|
63
69
|
toToolParametersWire: () => toToolParametersWire,
|
|
64
70
|
zodToJsonSchema: () => zodToJsonSchema
|
|
65
71
|
});
|
|
@@ -168,6 +174,7 @@ function defineLocalTool(opts) {
|
|
|
168
174
|
parameters: opts.parameters,
|
|
169
175
|
outputSchema: opts.outputSchema,
|
|
170
176
|
longRunning: opts.longRunning ?? false,
|
|
177
|
+
readOnly: opts.readOnly ?? false,
|
|
171
178
|
execute: opts.execute
|
|
172
179
|
};
|
|
173
180
|
}
|
|
@@ -705,6 +712,7 @@ function inputFileAttachment(opts) {
|
|
|
705
712
|
function inputFileUrlAttachment(opts) {
|
|
706
713
|
return { type: "input_file_url", ...opts };
|
|
707
714
|
}
|
|
715
|
+
var RUN_FEEDBACK_EXPLANATION_MAX = 8e3;
|
|
708
716
|
function planOnly(options = {}) {
|
|
709
717
|
return {
|
|
710
718
|
planOnly: true,
|
|
@@ -1066,6 +1074,32 @@ var MantyxClient = class {
|
|
|
1066
1074
|
path: `/agent-runs/${encodeURIComponent(runId)}/cancel`
|
|
1067
1075
|
});
|
|
1068
1076
|
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Record thumbs up/down feedback on a run. Requires the `feedback:write`
|
|
1079
|
+
* OAuth scope (workspace API keys have implicit access). Idempotent per
|
|
1080
|
+
* run — the first call returns HTTP 201, updates return 200; both carry
|
|
1081
|
+
* the same response body. See `docs/agent-runs-protocol.md` §9a.
|
|
1082
|
+
*/
|
|
1083
|
+
async submitRunFeedback(runId, input) {
|
|
1084
|
+
if (input.verdict !== "UP" && input.verdict !== "DOWN") {
|
|
1085
|
+
throw new MantyxError(
|
|
1086
|
+
`feedback verdict must be "UP" or "DOWN", got ${JSON.stringify(input.verdict)}`
|
|
1087
|
+
);
|
|
1088
|
+
}
|
|
1089
|
+
if (input.explanation !== void 0 && input.explanation.length > RUN_FEEDBACK_EXPLANATION_MAX) {
|
|
1090
|
+
throw new MantyxError(
|
|
1091
|
+
`feedback explanation must be <= ${RUN_FEEDBACK_EXPLANATION_MAX} characters`
|
|
1092
|
+
);
|
|
1093
|
+
}
|
|
1094
|
+
const body = { verdict: input.verdict };
|
|
1095
|
+
if (input.explanation !== void 0) body.explanation = input.explanation;
|
|
1096
|
+
if (input.contentSnapshot !== void 0) body.contentSnapshot = input.contentSnapshot;
|
|
1097
|
+
return this.request({
|
|
1098
|
+
method: "POST",
|
|
1099
|
+
path: `/agent-runs/${encodeURIComponent(runId)}/feedback`,
|
|
1100
|
+
body
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1069
1103
|
// -------------------------------------------------------------- HTTP
|
|
1070
1104
|
absoluteUrl(path) {
|
|
1071
1105
|
return `${this.options.baseUrl}/api/v1/workspaces/${encodeURIComponent(this.options.workspaceSlug)}${path}`;
|
|
@@ -1345,7 +1379,8 @@ function serializeToolRefs(tools) {
|
|
|
1345
1379
|
description: t.description,
|
|
1346
1380
|
parameters: toToolParametersWire(t.parameters),
|
|
1347
1381
|
...t.outputSchema !== void 0 ? { outputSchema: toToolParametersWire(t.outputSchema) } : {},
|
|
1348
|
-
...t.longRunning ? { longRunning: true } : {}
|
|
1382
|
+
...t.longRunning ? { longRunning: true } : {},
|
|
1383
|
+
...t.readOnly ? { readOnly: true } : {}
|
|
1349
1384
|
};
|
|
1350
1385
|
case "a2a":
|
|
1351
1386
|
return {
|
|
@@ -1514,23 +1549,24 @@ function normalizeLoopDetection(value) {
|
|
|
1514
1549
|
}
|
|
1515
1550
|
return out;
|
|
1516
1551
|
}
|
|
1517
|
-
function assertThreshold(label, value, min) {
|
|
1552
|
+
function assertThreshold(label, value, min, max = LOOP_DETECTION_THRESHOLD_MAX) {
|
|
1518
1553
|
if (typeof value !== "number" || !Number.isFinite(value) || !Number.isInteger(value)) {
|
|
1519
1554
|
throw new MantyxError(`${label} must be an integer, got ${JSON.stringify(value)}`);
|
|
1520
1555
|
}
|
|
1521
1556
|
if (value < min) {
|
|
1522
1557
|
throw new MantyxError(`${label} must be >= ${min}, got ${value}`);
|
|
1523
1558
|
}
|
|
1524
|
-
if (value >
|
|
1525
|
-
throw new MantyxError(
|
|
1526
|
-
`${label} must be <= ${LOOP_DETECTION_THRESHOLD_MAX} (server-enforced), got ${value}`
|
|
1527
|
-
);
|
|
1559
|
+
if (value > max) {
|
|
1560
|
+
throw new MantyxError(`${label} must be <= ${max} (server-enforced), got ${value}`);
|
|
1528
1561
|
}
|
|
1529
1562
|
return value;
|
|
1530
1563
|
}
|
|
1531
1564
|
var TOOL_BUDGETS_MAX_ENTRIES = 32;
|
|
1532
1565
|
var TOOL_BUDGET_MAX_NAME_LEN = 120;
|
|
1533
1566
|
var TOOL_BUDGET_MAX_CALLS = 1e3;
|
|
1567
|
+
var SUPERVISOR_INTERVAL_MAX = 100;
|
|
1568
|
+
var SUPERVISOR_REASONING_CHARS_MAX = 5e4;
|
|
1569
|
+
var SUPERVISOR_REASONING_MS_MAX = 6e5;
|
|
1534
1570
|
function normalizeSupervisor(value) {
|
|
1535
1571
|
if (value === false) return false;
|
|
1536
1572
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
@@ -1540,7 +1576,35 @@ function normalizeSupervisor(value) {
|
|
|
1540
1576
|
}
|
|
1541
1577
|
const out = {};
|
|
1542
1578
|
if (value.interval !== void 0) {
|
|
1543
|
-
out.interval = assertThreshold("supervisor.interval", value.interval, 1);
|
|
1579
|
+
out.interval = assertThreshold("supervisor.interval", value.interval, 1, SUPERVISOR_INTERVAL_MAX);
|
|
1580
|
+
}
|
|
1581
|
+
if (value.reasoningTrigger !== void 0) {
|
|
1582
|
+
if (value.reasoningTrigger === false) {
|
|
1583
|
+
out.reasoningTrigger = false;
|
|
1584
|
+
} else if (!value.reasoningTrigger || typeof value.reasoningTrigger !== "object" || Array.isArray(value.reasoningTrigger)) {
|
|
1585
|
+
throw new MantyxError(
|
|
1586
|
+
`supervisor.reasoningTrigger must be \`false\` or an object { chars?, ms? }, got ${JSON.stringify(value.reasoningTrigger)}`
|
|
1587
|
+
);
|
|
1588
|
+
} else {
|
|
1589
|
+
const rt = {};
|
|
1590
|
+
if (value.reasoningTrigger.chars !== void 0) {
|
|
1591
|
+
rt.chars = assertThreshold(
|
|
1592
|
+
"supervisor.reasoningTrigger.chars",
|
|
1593
|
+
value.reasoningTrigger.chars,
|
|
1594
|
+
1,
|
|
1595
|
+
SUPERVISOR_REASONING_CHARS_MAX
|
|
1596
|
+
);
|
|
1597
|
+
}
|
|
1598
|
+
if (value.reasoningTrigger.ms !== void 0) {
|
|
1599
|
+
rt.ms = assertThreshold(
|
|
1600
|
+
"supervisor.reasoningTrigger.ms",
|
|
1601
|
+
value.reasoningTrigger.ms,
|
|
1602
|
+
1,
|
|
1603
|
+
SUPERVISOR_REASONING_MS_MAX
|
|
1604
|
+
);
|
|
1605
|
+
}
|
|
1606
|
+
out.reasoningTrigger = rt;
|
|
1607
|
+
}
|
|
1544
1608
|
}
|
|
1545
1609
|
return out;
|
|
1546
1610
|
}
|
|
@@ -1952,11 +2016,366 @@ function normalizeScope(scope) {
|
|
|
1952
2016
|
return joined.length > 0 ? joined : void 0;
|
|
1953
2017
|
}
|
|
1954
2018
|
|
|
2019
|
+
// src/computer-use.ts
|
|
2020
|
+
var import_zod2 = require("zod");
|
|
2021
|
+
function denormalizeCoordinate(value, size) {
|
|
2022
|
+
return Math.round(value / 1e3 * size);
|
|
2023
|
+
}
|
|
2024
|
+
var COMPUTER_USE_ACTIONS = [
|
|
2025
|
+
"navigate",
|
|
2026
|
+
"click_at",
|
|
2027
|
+
"hover_at",
|
|
2028
|
+
"type_text_at",
|
|
2029
|
+
"key_combination",
|
|
2030
|
+
"scroll_at",
|
|
2031
|
+
"scroll_document",
|
|
2032
|
+
"drag_and_drop",
|
|
2033
|
+
"go_back",
|
|
2034
|
+
"go_forward",
|
|
2035
|
+
"wait"
|
|
2036
|
+
];
|
|
2037
|
+
var WAIT_HINT = "Action performed. A fresh screenshot will be provided in the next message; do not call another action until you have seen it.";
|
|
2038
|
+
function defineComputerUseTools(controller, opts = {}) {
|
|
2039
|
+
const excluded = new Set(opts.excludeActions ?? []);
|
|
2040
|
+
const includeConfirm = opts.requestConfirmation ?? true;
|
|
2041
|
+
const px = async (x, y) => {
|
|
2042
|
+
const vp = await controller.viewport();
|
|
2043
|
+
return { x: denormalizeCoordinate(x, vp.width), y: denormalizeCoordinate(y, vp.height) };
|
|
2044
|
+
};
|
|
2045
|
+
const ack = async (note) => {
|
|
2046
|
+
let url;
|
|
2047
|
+
if (controller.currentUrl) {
|
|
2048
|
+
try {
|
|
2049
|
+
url = await controller.currentUrl();
|
|
2050
|
+
} catch {
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
return JSON.stringify({
|
|
2054
|
+
status: "ok",
|
|
2055
|
+
...note ? { note } : {},
|
|
2056
|
+
...url ? { url } : {},
|
|
2057
|
+
hint: WAIT_HINT
|
|
2058
|
+
});
|
|
2059
|
+
};
|
|
2060
|
+
const tools = [];
|
|
2061
|
+
const add = (action, build) => {
|
|
2062
|
+
if (!excluded.has(action)) tools.push(build());
|
|
2063
|
+
};
|
|
2064
|
+
add(
|
|
2065
|
+
"navigate",
|
|
2066
|
+
() => defineLocalTool({
|
|
2067
|
+
name: "navigate",
|
|
2068
|
+
description: "Navigate the browser directly to a URL.",
|
|
2069
|
+
parameters: import_zod2.z.object({ url: import_zod2.z.string().describe("Absolute URL to open.") }),
|
|
2070
|
+
execute: async ({ url }) => {
|
|
2071
|
+
if (!controller.navigate) return errorResult("navigate is not supported by this environment");
|
|
2072
|
+
await controller.navigate(url);
|
|
2073
|
+
return ack();
|
|
2074
|
+
}
|
|
2075
|
+
})
|
|
2076
|
+
);
|
|
2077
|
+
add(
|
|
2078
|
+
"click_at",
|
|
2079
|
+
() => defineLocalTool({
|
|
2080
|
+
name: "click_at",
|
|
2081
|
+
description: "Click at a coordinate. x and y are on a 0-1000 grid scaled to the screen.",
|
|
2082
|
+
parameters: import_zod2.z.object({
|
|
2083
|
+
x: import_zod2.z.number().describe("Horizontal coordinate, 0-1000."),
|
|
2084
|
+
y: import_zod2.z.number().describe("Vertical coordinate, 0-1000.")
|
|
2085
|
+
}),
|
|
2086
|
+
execute: async ({ x, y }) => {
|
|
2087
|
+
const p = await px(x, y);
|
|
2088
|
+
await controller.clickAt(p.x, p.y);
|
|
2089
|
+
return ack();
|
|
2090
|
+
}
|
|
2091
|
+
})
|
|
2092
|
+
);
|
|
2093
|
+
add(
|
|
2094
|
+
"hover_at",
|
|
2095
|
+
() => defineLocalTool({
|
|
2096
|
+
name: "hover_at",
|
|
2097
|
+
description: "Hover the mouse at a coordinate (useful to reveal menus). x and y are on a 0-1000 grid.",
|
|
2098
|
+
parameters: import_zod2.z.object({
|
|
2099
|
+
x: import_zod2.z.number().describe("Horizontal coordinate, 0-1000."),
|
|
2100
|
+
y: import_zod2.z.number().describe("Vertical coordinate, 0-1000.")
|
|
2101
|
+
}),
|
|
2102
|
+
execute: async ({ x, y }) => {
|
|
2103
|
+
if (!controller.hoverAt) return errorResult("hover_at is not supported by this environment");
|
|
2104
|
+
const p = await px(x, y);
|
|
2105
|
+
await controller.hoverAt(p.x, p.y);
|
|
2106
|
+
return ack();
|
|
2107
|
+
}
|
|
2108
|
+
})
|
|
2109
|
+
);
|
|
2110
|
+
add(
|
|
2111
|
+
"type_text_at",
|
|
2112
|
+
() => defineLocalTool({
|
|
2113
|
+
name: "type_text_at",
|
|
2114
|
+
description: "Type text at a coordinate. By default clears the field first and presses Enter after typing. x and y are on a 0-1000 grid.",
|
|
2115
|
+
parameters: import_zod2.z.object({
|
|
2116
|
+
x: import_zod2.z.number().describe("Horizontal coordinate, 0-1000."),
|
|
2117
|
+
y: import_zod2.z.number().describe("Vertical coordinate, 0-1000."),
|
|
2118
|
+
text: import_zod2.z.string().describe("Text to type."),
|
|
2119
|
+
press_enter: import_zod2.z.boolean().optional().describe("Press Enter after typing. Default true."),
|
|
2120
|
+
clear_before_typing: import_zod2.z.boolean().optional().describe("Clear the field before typing. Default true.")
|
|
2121
|
+
}),
|
|
2122
|
+
execute: async ({ x, y, text, press_enter, clear_before_typing }) => {
|
|
2123
|
+
const p = await px(x, y);
|
|
2124
|
+
await controller.typeTextAt(p.x, p.y, text, {
|
|
2125
|
+
pressEnter: press_enter ?? true,
|
|
2126
|
+
clearBeforeTyping: clear_before_typing ?? true
|
|
2127
|
+
});
|
|
2128
|
+
return ack();
|
|
2129
|
+
}
|
|
2130
|
+
})
|
|
2131
|
+
);
|
|
2132
|
+
add(
|
|
2133
|
+
"key_combination",
|
|
2134
|
+
() => defineLocalTool({
|
|
2135
|
+
name: "key_combination",
|
|
2136
|
+
description: 'Press a key or chord, e.g. "Enter", "Control+C", "Control+A". Useful for submitting or clipboard actions.',
|
|
2137
|
+
parameters: import_zod2.z.object({
|
|
2138
|
+
keys: import_zod2.z.string().describe('Key or chord, e.g. "Enter" or "Control+C".')
|
|
2139
|
+
}),
|
|
2140
|
+
execute: async ({ keys }) => {
|
|
2141
|
+
if (!controller.keyCombination)
|
|
2142
|
+
return errorResult("key_combination is not supported by this environment");
|
|
2143
|
+
await controller.keyCombination(keys);
|
|
2144
|
+
return ack();
|
|
2145
|
+
}
|
|
2146
|
+
})
|
|
2147
|
+
);
|
|
2148
|
+
add(
|
|
2149
|
+
"scroll_at",
|
|
2150
|
+
() => defineLocalTool({
|
|
2151
|
+
name: "scroll_at",
|
|
2152
|
+
description: "Scroll the area at a coordinate in a direction by a pixel magnitude (default 800). Coordinates are on a 0-1000 grid.",
|
|
2153
|
+
parameters: import_zod2.z.object({
|
|
2154
|
+
x: import_zod2.z.number().describe("Horizontal coordinate, 0-1000."),
|
|
2155
|
+
y: import_zod2.z.number().describe("Vertical coordinate, 0-1000."),
|
|
2156
|
+
direction: import_zod2.z.enum(["up", "down", "left", "right"]),
|
|
2157
|
+
magnitude: import_zod2.z.number().optional().describe("Scroll distance in pixels. Default 800.")
|
|
2158
|
+
}),
|
|
2159
|
+
execute: async ({ x, y, direction, magnitude }) => {
|
|
2160
|
+
if (!controller.scrollAt) return errorResult("scroll_at is not supported by this environment");
|
|
2161
|
+
const p = await px(x, y);
|
|
2162
|
+
await controller.scrollAt(p.x, p.y, direction, magnitude ?? 800);
|
|
2163
|
+
return ack();
|
|
2164
|
+
}
|
|
2165
|
+
})
|
|
2166
|
+
);
|
|
2167
|
+
add(
|
|
2168
|
+
"scroll_document",
|
|
2169
|
+
() => defineLocalTool({
|
|
2170
|
+
name: "scroll_document",
|
|
2171
|
+
description: 'Scroll the whole page "up", "down", "left", or "right".',
|
|
2172
|
+
parameters: import_zod2.z.object({ direction: import_zod2.z.enum(["up", "down", "left", "right"]) }),
|
|
2173
|
+
execute: async ({ direction }) => {
|
|
2174
|
+
if (!controller.scrollDocument)
|
|
2175
|
+
return errorResult("scroll_document is not supported by this environment");
|
|
2176
|
+
await controller.scrollDocument(direction);
|
|
2177
|
+
return ack();
|
|
2178
|
+
}
|
|
2179
|
+
})
|
|
2180
|
+
);
|
|
2181
|
+
add(
|
|
2182
|
+
"drag_and_drop",
|
|
2183
|
+
() => defineLocalTool({
|
|
2184
|
+
name: "drag_and_drop",
|
|
2185
|
+
description: "Drag from a starting coordinate and drop at a destination coordinate. All coordinates are on a 0-1000 grid.",
|
|
2186
|
+
parameters: import_zod2.z.object({
|
|
2187
|
+
x: import_zod2.z.number().describe("Start horizontal, 0-1000."),
|
|
2188
|
+
y: import_zod2.z.number().describe("Start vertical, 0-1000."),
|
|
2189
|
+
destination_x: import_zod2.z.number().describe("Destination horizontal, 0-1000."),
|
|
2190
|
+
destination_y: import_zod2.z.number().describe("Destination vertical, 0-1000.")
|
|
2191
|
+
}),
|
|
2192
|
+
execute: async ({ x, y, destination_x, destination_y }) => {
|
|
2193
|
+
if (!controller.dragAndDrop)
|
|
2194
|
+
return errorResult("drag_and_drop is not supported by this environment");
|
|
2195
|
+
const from = await px(x, y);
|
|
2196
|
+
const to = await px(destination_x, destination_y);
|
|
2197
|
+
await controller.dragAndDrop(from.x, from.y, to.x, to.y);
|
|
2198
|
+
return ack();
|
|
2199
|
+
}
|
|
2200
|
+
})
|
|
2201
|
+
);
|
|
2202
|
+
add(
|
|
2203
|
+
"go_back",
|
|
2204
|
+
() => defineLocalTool({
|
|
2205
|
+
name: "go_back",
|
|
2206
|
+
description: "Navigate to the previous page in history.",
|
|
2207
|
+
parameters: import_zod2.z.object({}),
|
|
2208
|
+
execute: async () => {
|
|
2209
|
+
if (!controller.goBack) return errorResult("go_back is not supported by this environment");
|
|
2210
|
+
await controller.goBack();
|
|
2211
|
+
return ack();
|
|
2212
|
+
}
|
|
2213
|
+
})
|
|
2214
|
+
);
|
|
2215
|
+
add(
|
|
2216
|
+
"go_forward",
|
|
2217
|
+
() => defineLocalTool({
|
|
2218
|
+
name: "go_forward",
|
|
2219
|
+
description: "Navigate to the next page in history.",
|
|
2220
|
+
parameters: import_zod2.z.object({}),
|
|
2221
|
+
execute: async () => {
|
|
2222
|
+
if (!controller.goForward)
|
|
2223
|
+
return errorResult("go_forward is not supported by this environment");
|
|
2224
|
+
await controller.goForward();
|
|
2225
|
+
return ack();
|
|
2226
|
+
}
|
|
2227
|
+
})
|
|
2228
|
+
);
|
|
2229
|
+
add(
|
|
2230
|
+
"wait",
|
|
2231
|
+
() => defineLocalTool({
|
|
2232
|
+
name: "wait",
|
|
2233
|
+
description: "Pause to let dynamic content load or animations finish.",
|
|
2234
|
+
parameters: import_zod2.z.object({
|
|
2235
|
+
seconds: import_zod2.z.number().optional().describe("Seconds to wait. Default 1, max 10.")
|
|
2236
|
+
}),
|
|
2237
|
+
execute: async ({ seconds }) => {
|
|
2238
|
+
const s = Math.min(Math.max(seconds ?? 1, 0), 10);
|
|
2239
|
+
await new Promise((resolve) => setTimeout(resolve, s * 1e3));
|
|
2240
|
+
return ack(`waited ${s}s`);
|
|
2241
|
+
}
|
|
2242
|
+
})
|
|
2243
|
+
);
|
|
2244
|
+
if (includeConfirm) {
|
|
2245
|
+
tools.push(
|
|
2246
|
+
defineLocalTool({
|
|
2247
|
+
name: "request_confirmation",
|
|
2248
|
+
description: "Ask the human operator to approve a consequential or irreversible action BEFORE performing it (e.g. submitting a form, sending a message, making a purchase, accepting terms, solving a CAPTCHA, logging in). Returns whether you are cleared to proceed.",
|
|
2249
|
+
parameters: import_zod2.z.object({
|
|
2250
|
+
reason: import_zod2.z.string().describe("What you are about to do and why confirmation is needed.")
|
|
2251
|
+
}),
|
|
2252
|
+
execute: async ({ reason }) => {
|
|
2253
|
+
const approved = opts.confirm ? await opts.confirm(reason) : false;
|
|
2254
|
+
return JSON.stringify({
|
|
2255
|
+
approved,
|
|
2256
|
+
...approved ? { note: "Operator approved. Proceed with the action, then stop and wait for the next screenshot." } : { note: "Operator denied. Do not perform the action; choose a different approach or stop and report back." }
|
|
2257
|
+
});
|
|
2258
|
+
}
|
|
2259
|
+
})
|
|
2260
|
+
);
|
|
2261
|
+
}
|
|
2262
|
+
return tools;
|
|
2263
|
+
}
|
|
2264
|
+
function errorResult(message) {
|
|
2265
|
+
return JSON.stringify({ status: "error", error: message });
|
|
2266
|
+
}
|
|
2267
|
+
function buildComputerUseSystemPrompt(opts = {}) {
|
|
2268
|
+
const environment = opts.environment ?? "web browser";
|
|
2269
|
+
const confirmation = opts.requestConfirmation ?? true;
|
|
2270
|
+
const lines = [
|
|
2271
|
+
`You are an agent that controls a ${environment} by looking at screenshots and taking UI actions.`,
|
|
2272
|
+
"",
|
|
2273
|
+
"Protocol:",
|
|
2274
|
+
`- Before every step you receive a screenshot of the current ${environment} as an image attachment. Study it carefully.`,
|
|
2275
|
+
"- Choose EXACTLY ONE action and call the matching tool. Coordinates use a 0-1000 grid (top-left is 0,0; bottom-right is 1000,1000), scaled automatically to the screen.",
|
|
2276
|
+
"- After the tool runs, STOP and wait. You will be given a new screenshot reflecting the result; only then decide the next action.",
|
|
2277
|
+
"- Do not chain multiple actions in one turn and do not guess what happened \u2014 always rely on the next screenshot.",
|
|
2278
|
+
"- Scroll to reveal content before concluding something is missing.",
|
|
2279
|
+
"",
|
|
2280
|
+
"Finishing:",
|
|
2281
|
+
"- When the task is complete (or you have gathered enough information to answer), reply with a plain-text final answer and DO NOT call any tool. That ends the session.",
|
|
2282
|
+
"- If you get stuck or cannot proceed, explain why in plain text without calling a tool."
|
|
2283
|
+
];
|
|
2284
|
+
if (confirmation) {
|
|
2285
|
+
lines.push(
|
|
2286
|
+
"",
|
|
2287
|
+
"Safety \u2014 you MUST call `request_confirmation` and wait for approval BEFORE any consequential or irreversible action, including:",
|
|
2288
|
+
"- Accepting terms of service, privacy policies, cookie banners, or other agreements.",
|
|
2289
|
+
"- Solving or bypassing CAPTCHAs or other human-verification checks.",
|
|
2290
|
+
"- Completing a purchase, moving money, or any financial transaction.",
|
|
2291
|
+
"- Sending an email or message, or posting content.",
|
|
2292
|
+
"- Logging into an account, or accessing/modifying sensitive personal data.",
|
|
2293
|
+
"- Downloading, saving, sharing, or transferring files or user data.",
|
|
2294
|
+
"For these, do all preparatory steps first, then call `request_confirmation` immediately BEFORE the final irreversible click. If denied, do not perform the action."
|
|
2295
|
+
);
|
|
2296
|
+
}
|
|
2297
|
+
if (opts.extraInstructions) {
|
|
2298
|
+
lines.push("", opts.extraInstructions);
|
|
2299
|
+
}
|
|
2300
|
+
return lines.join("\n");
|
|
2301
|
+
}
|
|
2302
|
+
var DEFAULT_CONTINUE_TEXT = "Here is the screen after your last action. Continue toward the goal, or give your final answer if the task is done.";
|
|
2303
|
+
function extractActions(result) {
|
|
2304
|
+
const actions = [];
|
|
2305
|
+
for (const ev of result.events) {
|
|
2306
|
+
if (ev.type === "local_tool_call") {
|
|
2307
|
+
const e = ev;
|
|
2308
|
+
actions.push({ name: e.name ?? "", input: e.args ?? {} });
|
|
2309
|
+
}
|
|
2310
|
+
}
|
|
2311
|
+
return actions;
|
|
2312
|
+
}
|
|
2313
|
+
function screenshotExtension(mimeType) {
|
|
2314
|
+
if (mimeType.includes("png")) return "png";
|
|
2315
|
+
if (mimeType.includes("webp")) return "webp";
|
|
2316
|
+
return "jpg";
|
|
2317
|
+
}
|
|
2318
|
+
async function runComputerUse(opts) {
|
|
2319
|
+
const maxSteps = opts.maxSteps ?? 20;
|
|
2320
|
+
if (maxSteps < 1) throw new Error("runComputerUse: maxSteps must be >= 1");
|
|
2321
|
+
const requestConfirmation = !opts.disableConfirmation;
|
|
2322
|
+
const tools = defineComputerUseTools(opts.controller, {
|
|
2323
|
+
...opts.excludeActions ? { excludeActions: opts.excludeActions } : {},
|
|
2324
|
+
requestConfirmation,
|
|
2325
|
+
...opts.confirm ? { confirm: opts.confirm } : {}
|
|
2326
|
+
});
|
|
2327
|
+
const systemPrompt = opts.systemPrompt ?? buildComputerUseSystemPrompt({
|
|
2328
|
+
...opts.systemPromptOptions ?? {},
|
|
2329
|
+
requestConfirmation
|
|
2330
|
+
});
|
|
2331
|
+
const session = await opts.client.createSession({
|
|
2332
|
+
systemPrompt,
|
|
2333
|
+
...opts.model ? { modelId: opts.model } : {},
|
|
2334
|
+
tools,
|
|
2335
|
+
...opts.reasoningLevel !== void 0 ? { reasoningLevel: opts.reasoningLevel } : {},
|
|
2336
|
+
...opts.metadata ? { metadata: opts.metadata } : {}
|
|
2337
|
+
});
|
|
2338
|
+
const steps = [];
|
|
2339
|
+
let finalText = "";
|
|
2340
|
+
let stoppedReason = "max_steps";
|
|
2341
|
+
try {
|
|
2342
|
+
for (let i = 0; i < maxSteps; i++) {
|
|
2343
|
+
const screenshot = await opts.controller.screenshot();
|
|
2344
|
+
const filename = screenshot.filename ?? `screenshot-${i + 1}.${screenshotExtension(screenshot.mimeType)}`;
|
|
2345
|
+
const attachment = inputFileAttachment({
|
|
2346
|
+
mimeType: screenshot.mimeType,
|
|
2347
|
+
filename,
|
|
2348
|
+
data: screenshot.data
|
|
2349
|
+
});
|
|
2350
|
+
const turnText = i === 0 ? opts.goal : opts.continueText ?? DEFAULT_CONTINUE_TEXT;
|
|
2351
|
+
const result = await session.send(turnText, {
|
|
2352
|
+
attachments: [attachment],
|
|
2353
|
+
...opts.onAssistantDelta ? { onAssistantDelta: opts.onAssistantDelta } : {},
|
|
2354
|
+
...opts.signal ? { signal: opts.signal } : {}
|
|
2355
|
+
});
|
|
2356
|
+
const actions = extractActions(result);
|
|
2357
|
+
const step = { step: i + 1, screenshot, result, actions };
|
|
2358
|
+
steps.push(step);
|
|
2359
|
+
finalText = result.text;
|
|
2360
|
+
if (opts.onStep) await opts.onStep(step);
|
|
2361
|
+
if (actions.length === 0) {
|
|
2362
|
+
stoppedReason = "completed";
|
|
2363
|
+
break;
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
return { finalText, steps, sessionId: session.id, stoppedReason };
|
|
2367
|
+
} finally {
|
|
2368
|
+
await session.end().catch(() => {
|
|
2369
|
+
});
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
|
|
1955
2373
|
// src/version.ts
|
|
1956
|
-
var SDK_VERSION = "0.
|
|
2374
|
+
var SDK_VERSION = "0.17.0";
|
|
1957
2375
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1958
2376
|
0 && (module.exports = {
|
|
1959
2377
|
AgentSession,
|
|
2378
|
+
COMPUTER_USE_ACTIONS,
|
|
1960
2379
|
DEFAULT_BASE_URL,
|
|
1961
2380
|
DEFAULT_OAUTH_BASE_URL,
|
|
1962
2381
|
DEFAULT_REFRESH_SKEW_MS,
|
|
@@ -1971,9 +2390,13 @@ var SDK_VERSION = "0.15.1";
|
|
|
1971
2390
|
MantyxScopeError,
|
|
1972
2391
|
MantyxToolError,
|
|
1973
2392
|
SDK_VERSION,
|
|
2393
|
+
buildComputerUseSystemPrompt,
|
|
2394
|
+
defineComputerUseTools,
|
|
1974
2395
|
defineLocalA2A,
|
|
1975
2396
|
defineLocalMcp,
|
|
1976
2397
|
defineLocalTool,
|
|
2398
|
+
denormalizeCoordinate,
|
|
2399
|
+
extractActions,
|
|
1977
2400
|
inputFileAttachment,
|
|
1978
2401
|
inputFileUrlAttachment,
|
|
1979
2402
|
isLocalA2ATool,
|
|
@@ -1986,6 +2409,7 @@ var SDK_VERSION = "0.15.1";
|
|
|
1986
2409
|
parseRunOutput,
|
|
1987
2410
|
planOnly,
|
|
1988
2411
|
readSseStream,
|
|
2412
|
+
runComputerUse,
|
|
1989
2413
|
toToolParametersWire,
|
|
1990
2414
|
zodToJsonSchema
|
|
1991
2415
|
});
|