@mantyx/sdk 0.16.0 → 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 +7 -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-EEVTNG4C.js → chunk-DNJYOHTJ.js} +31 -2
- package/dist/chunk-DNJYOHTJ.js.map +1 -0
- package/dist/{client-DgBXj6Dh.d.cts → client-IjrvboaL.d.cts} +42 -2
- package/dist/{client-DgBXj6Dh.d.ts → client-IjrvboaL.d.ts} +42 -2
- package/dist/computer-use-B9eNnX_y.d.ts +193 -0
- package/dist/computer-use-yH7ohjLl.d.cts +193 -0
- package/dist/index.cjs +397 -2
- 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 +46 -6
- package/package.json +12 -2
- package/dist/chunk-EEVTNG4C.js.map +0 -1
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/playwright.ts
|
|
21
|
+
var playwright_exports = {};
|
|
22
|
+
__export(playwright_exports, {
|
|
23
|
+
PlaywrightController: () => PlaywrightController,
|
|
24
|
+
scrollDelta: () => scrollDelta
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(playwright_exports);
|
|
27
|
+
var DEFAULT_WIDTH = 1440;
|
|
28
|
+
var DEFAULT_HEIGHT = 900;
|
|
29
|
+
var DEFAULT_QUALITY = 70;
|
|
30
|
+
var DEFAULT_SETTLE_MS = 5e3;
|
|
31
|
+
var PlaywrightController = class {
|
|
32
|
+
constructor(page, opts = {}) {
|
|
33
|
+
this.page = page;
|
|
34
|
+
this.width = opts.width ?? DEFAULT_WIDTH;
|
|
35
|
+
this.height = opts.height ?? DEFAULT_HEIGHT;
|
|
36
|
+
this.screenshotQuality = opts.screenshotQuality ?? DEFAULT_QUALITY;
|
|
37
|
+
this.screenshotType = opts.screenshotType ?? "jpeg";
|
|
38
|
+
this.settleTimeoutMs = opts.settleTimeoutMs ?? DEFAULT_SETTLE_MS;
|
|
39
|
+
}
|
|
40
|
+
page;
|
|
41
|
+
width;
|
|
42
|
+
height;
|
|
43
|
+
screenshotQuality;
|
|
44
|
+
screenshotType;
|
|
45
|
+
settleTimeoutMs;
|
|
46
|
+
viewport() {
|
|
47
|
+
return { width: this.width, height: this.height };
|
|
48
|
+
}
|
|
49
|
+
async screenshot() {
|
|
50
|
+
if (this.screenshotType === "png") {
|
|
51
|
+
const buf2 = await this.page.screenshot({ type: "png" });
|
|
52
|
+
return { data: buf2.toString("base64"), mimeType: "image/png" };
|
|
53
|
+
}
|
|
54
|
+
const buf = await this.page.screenshot({
|
|
55
|
+
type: "jpeg",
|
|
56
|
+
quality: this.screenshotQuality
|
|
57
|
+
});
|
|
58
|
+
return { data: buf.toString("base64"), mimeType: "image/jpeg" };
|
|
59
|
+
}
|
|
60
|
+
currentUrl() {
|
|
61
|
+
return this.page.url();
|
|
62
|
+
}
|
|
63
|
+
async navigate(url) {
|
|
64
|
+
await this.page.goto(url);
|
|
65
|
+
await this.settle();
|
|
66
|
+
}
|
|
67
|
+
async clickAt(x, y) {
|
|
68
|
+
await this.page.mouse.click(x, y);
|
|
69
|
+
await this.settle();
|
|
70
|
+
}
|
|
71
|
+
async hoverAt(x, y) {
|
|
72
|
+
await this.page.mouse.move(x, y);
|
|
73
|
+
}
|
|
74
|
+
async typeTextAt(x, y, text, opts) {
|
|
75
|
+
await this.page.mouse.click(x, y);
|
|
76
|
+
if (opts.clearBeforeTyping) {
|
|
77
|
+
await this.page.keyboard.press("ControlOrMeta+A");
|
|
78
|
+
await this.page.keyboard.press("Backspace");
|
|
79
|
+
}
|
|
80
|
+
await this.page.keyboard.type(text);
|
|
81
|
+
if (opts.pressEnter) await this.page.keyboard.press("Enter");
|
|
82
|
+
await this.settle();
|
|
83
|
+
}
|
|
84
|
+
async keyCombination(keys) {
|
|
85
|
+
await this.page.keyboard.press(keys.replace(/\s+/g, ""));
|
|
86
|
+
await this.settle();
|
|
87
|
+
}
|
|
88
|
+
async scrollAt(x, y, direction, magnitude) {
|
|
89
|
+
await this.page.mouse.move(x, y);
|
|
90
|
+
const [dx, dy] = scrollDelta(direction, magnitude);
|
|
91
|
+
await this.page.mouse.wheel(dx, dy);
|
|
92
|
+
await this.settle();
|
|
93
|
+
}
|
|
94
|
+
async scrollDocument(direction) {
|
|
95
|
+
const [dx, dy] = scrollDelta(direction, 800);
|
|
96
|
+
await this.page.mouse.wheel(dx, dy);
|
|
97
|
+
await this.settle();
|
|
98
|
+
}
|
|
99
|
+
async dragAndDrop(x, y, destX, destY) {
|
|
100
|
+
await this.page.mouse.move(x, y);
|
|
101
|
+
await this.page.mouse.down();
|
|
102
|
+
await this.page.mouse.move(destX, destY, { steps: 10 });
|
|
103
|
+
await this.page.mouse.up();
|
|
104
|
+
await this.settle();
|
|
105
|
+
}
|
|
106
|
+
async goBack() {
|
|
107
|
+
await this.page.goBack();
|
|
108
|
+
await this.settle();
|
|
109
|
+
}
|
|
110
|
+
async goForward() {
|
|
111
|
+
await this.page.goForward();
|
|
112
|
+
await this.settle();
|
|
113
|
+
}
|
|
114
|
+
async settle() {
|
|
115
|
+
if (this.settleTimeoutMs <= 0) return;
|
|
116
|
+
try {
|
|
117
|
+
await this.page.waitForLoadState("networkidle", { timeout: this.settleTimeoutMs });
|
|
118
|
+
} catch {
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
function scrollDelta(direction, magnitude) {
|
|
123
|
+
switch (direction) {
|
|
124
|
+
case "up":
|
|
125
|
+
return [0, -magnitude];
|
|
126
|
+
case "down":
|
|
127
|
+
return [0, magnitude];
|
|
128
|
+
case "left":
|
|
129
|
+
return [-magnitude, 0];
|
|
130
|
+
case "right":
|
|
131
|
+
return [magnitude, 0];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
135
|
+
0 && (module.exports = {
|
|
136
|
+
PlaywrightController,
|
|
137
|
+
scrollDelta
|
|
138
|
+
});
|
|
139
|
+
//# sourceMappingURL=playwright.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/playwright.ts"],"sourcesContent":["/**\n * Playwright-backed {@link BrowserController} for computer use.\n *\n * Loaded from a separate sub-export (`@mantyx/sdk/playwright`) so apps that\n * don't drive a browser never pay the Playwright bundle cost. Install the\n * optional peer dep first:\n *\n * npm install playwright\n * npx playwright install chromium\n *\n * @example\n * import { MantyxClient, runComputerUse } from \"@mantyx/sdk\";\n * import { PlaywrightController } from \"@mantyx/sdk/playwright\";\n * import { chromium } from \"playwright\";\n *\n * const browser = await chromium.launch();\n * const page = await (await browser.newContext()).newPage();\n * const controller = new PlaywrightController(page);\n *\n * const out = await runComputerUse({\n * client,\n * goal: \"Find the top story on news.ycombinator.com\",\n * controller,\n * });\n */\nimport type { Page } from \"playwright\";\nimport type {\n BrowserController,\n Screenshot,\n ScrollDirection,\n TypeTextOptions,\n Viewport,\n} from \"./computer-use.js\";\n\nexport interface PlaywrightControllerOptions {\n /**\n * Viewport width in pixels. Should match the browser context viewport so\n * denormalized coordinates from the model land on the right pixels.\n * Default `1440`.\n */\n width?: number;\n /**\n * Viewport height in pixels. Default `900`.\n */\n height?: number;\n /**\n * JPEG quality for screenshots (`0`–`100`). Ignored when\n * `screenshotType` is `\"png\"`. Default `70` — keeps inline attachments\n * well under the 5 MB cap.\n */\n screenshotQuality?: number;\n /** Screenshot format. Default `\"jpeg\"`. */\n screenshotType?: \"jpeg\" | \"png\";\n /**\n * Max milliseconds to wait for `networkidle` after navigation and UI\n * actions. Default `5000`. Set to `0` to skip waiting.\n */\n settleTimeoutMs?: number;\n}\n\nconst DEFAULT_WIDTH = 1440;\nconst DEFAULT_HEIGHT = 900;\nconst DEFAULT_QUALITY = 70;\nconst DEFAULT_SETTLE_MS = 5000;\n\n/**\n * A {@link BrowserController} backed by a Playwright `Page`. Coordinates\n * arrive already denormalized to pixels by the computer-use tools, so this\n * class drives Playwright directly.\n */\nexport class PlaywrightController implements BrowserController {\n private readonly width: number;\n private readonly height: number;\n private readonly screenshotQuality: number;\n private readonly screenshotType: \"jpeg\" | \"png\";\n private readonly settleTimeoutMs: number;\n\n constructor(\n private readonly page: Page,\n opts: PlaywrightControllerOptions = {},\n ) {\n this.width = opts.width ?? DEFAULT_WIDTH;\n this.height = opts.height ?? DEFAULT_HEIGHT;\n this.screenshotQuality = opts.screenshotQuality ?? DEFAULT_QUALITY;\n this.screenshotType = opts.screenshotType ?? \"jpeg\";\n this.settleTimeoutMs = opts.settleTimeoutMs ?? DEFAULT_SETTLE_MS;\n }\n\n viewport(): Viewport {\n return { width: this.width, height: this.height };\n }\n\n async screenshot(): Promise<Screenshot> {\n if (this.screenshotType === \"png\") {\n const buf = await this.page.screenshot({ type: \"png\" });\n return { data: buf.toString(\"base64\"), mimeType: \"image/png\" };\n }\n const buf = await this.page.screenshot({\n type: \"jpeg\",\n quality: this.screenshotQuality,\n });\n return { data: buf.toString(\"base64\"), mimeType: \"image/jpeg\" };\n }\n\n currentUrl(): string {\n return this.page.url();\n }\n\n async navigate(url: string): Promise<void> {\n await this.page.goto(url);\n await this.settle();\n }\n\n async clickAt(x: number, y: number): Promise<void> {\n await this.page.mouse.click(x, y);\n await this.settle();\n }\n\n async hoverAt(x: number, y: number): Promise<void> {\n await this.page.mouse.move(x, y);\n }\n\n async typeTextAt(x: number, y: number, text: string, opts: TypeTextOptions): Promise<void> {\n await this.page.mouse.click(x, y);\n if (opts.clearBeforeTyping) {\n await this.page.keyboard.press(\"ControlOrMeta+A\");\n await this.page.keyboard.press(\"Backspace\");\n }\n await this.page.keyboard.type(text);\n if (opts.pressEnter) await this.page.keyboard.press(\"Enter\");\n await this.settle();\n }\n\n async keyCombination(keys: string): Promise<void> {\n await this.page.keyboard.press(keys.replace(/\\s+/g, \"\"));\n await this.settle();\n }\n\n async scrollAt(\n x: number,\n y: number,\n direction: ScrollDirection,\n magnitude: number,\n ): Promise<void> {\n await this.page.mouse.move(x, y);\n const [dx, dy] = scrollDelta(direction, magnitude);\n await this.page.mouse.wheel(dx, dy);\n await this.settle();\n }\n\n async scrollDocument(direction: ScrollDirection): Promise<void> {\n const [dx, dy] = scrollDelta(direction, 800);\n await this.page.mouse.wheel(dx, dy);\n await this.settle();\n }\n\n async dragAndDrop(x: number, y: number, destX: number, destY: number): Promise<void> {\n await this.page.mouse.move(x, y);\n await this.page.mouse.down();\n await this.page.mouse.move(destX, destY, { steps: 10 });\n await this.page.mouse.up();\n await this.settle();\n }\n\n async goBack(): Promise<void> {\n await this.page.goBack();\n await this.settle();\n }\n\n async goForward(): Promise<void> {\n await this.page.goForward();\n await this.settle();\n }\n\n private async settle(): Promise<void> {\n if (this.settleTimeoutMs <= 0) return;\n try {\n await this.page.waitForLoadState(\"networkidle\", { timeout: this.settleTimeoutMs });\n } catch {\n // Best-effort; some pages never reach networkidle.\n }\n }\n}\n\n/** @internal Exported for unit tests. */\nexport function scrollDelta(direction: ScrollDirection, magnitude: number): [number, number] {\n switch (direction) {\n case \"up\":\n return [0, -magnitude];\n case \"down\":\n return [0, magnitude];\n case \"left\":\n return [-magnitude, 0];\n case \"right\":\n return [magnitude, 0];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA4DA,IAAM,gBAAgB;AACtB,IAAM,iBAAiB;AACvB,IAAM,kBAAkB;AACxB,IAAM,oBAAoB;AAOnB,IAAM,uBAAN,MAAwD;AAAA,EAO7D,YACmB,MACjB,OAAoC,CAAC,GACrC;AAFiB;AAGjB,SAAK,QAAQ,KAAK,SAAS;AAC3B,SAAK,SAAS,KAAK,UAAU;AAC7B,SAAK,oBAAoB,KAAK,qBAAqB;AACnD,SAAK,iBAAiB,KAAK,kBAAkB;AAC7C,SAAK,kBAAkB,KAAK,mBAAmB;AAAA,EACjD;AAAA,EARmB;AAAA,EAPF;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAajB,WAAqB;AACnB,WAAO,EAAE,OAAO,KAAK,OAAO,QAAQ,KAAK,OAAO;AAAA,EAClD;AAAA,EAEA,MAAM,aAAkC;AACtC,QAAI,KAAK,mBAAmB,OAAO;AACjC,YAAMA,OAAM,MAAM,KAAK,KAAK,WAAW,EAAE,MAAM,MAAM,CAAC;AACtD,aAAO,EAAE,MAAMA,KAAI,SAAS,QAAQ,GAAG,UAAU,YAAY;AAAA,IAC/D;AACA,UAAM,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Viewport, S as Screenshot, T as TypeTextOptions, f as ScrollDirection } from './computer-use-yH7ohjLl.cjs';
|
|
3
|
+
import './client-IjrvboaL.cjs';
|
|
4
|
+
import 'zod';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Playwright-backed {@link BrowserController} for computer use.
|
|
8
|
+
*
|
|
9
|
+
* Loaded from a separate sub-export (`@mantyx/sdk/playwright`) so apps that
|
|
10
|
+
* don't drive a browser never pay the Playwright bundle cost. Install the
|
|
11
|
+
* optional peer dep first:
|
|
12
|
+
*
|
|
13
|
+
* npm install playwright
|
|
14
|
+
* npx playwright install chromium
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* import { MantyxClient, runComputerUse } from "@mantyx/sdk";
|
|
18
|
+
* import { PlaywrightController } from "@mantyx/sdk/playwright";
|
|
19
|
+
* import { chromium } from "playwright";
|
|
20
|
+
*
|
|
21
|
+
* const browser = await chromium.launch();
|
|
22
|
+
* const page = await (await browser.newContext()).newPage();
|
|
23
|
+
* const controller = new PlaywrightController(page);
|
|
24
|
+
*
|
|
25
|
+
* const out = await runComputerUse({
|
|
26
|
+
* client,
|
|
27
|
+
* goal: "Find the top story on news.ycombinator.com",
|
|
28
|
+
* controller,
|
|
29
|
+
* });
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
interface PlaywrightControllerOptions {
|
|
33
|
+
/**
|
|
34
|
+
* Viewport width in pixels. Should match the browser context viewport so
|
|
35
|
+
* denormalized coordinates from the model land on the right pixels.
|
|
36
|
+
* Default `1440`.
|
|
37
|
+
*/
|
|
38
|
+
width?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Viewport height in pixels. Default `900`.
|
|
41
|
+
*/
|
|
42
|
+
height?: number;
|
|
43
|
+
/**
|
|
44
|
+
* JPEG quality for screenshots (`0`–`100`). Ignored when
|
|
45
|
+
* `screenshotType` is `"png"`. Default `70` — keeps inline attachments
|
|
46
|
+
* well under the 5 MB cap.
|
|
47
|
+
*/
|
|
48
|
+
screenshotQuality?: number;
|
|
49
|
+
/** Screenshot format. Default `"jpeg"`. */
|
|
50
|
+
screenshotType?: "jpeg" | "png";
|
|
51
|
+
/**
|
|
52
|
+
* Max milliseconds to wait for `networkidle` after navigation and UI
|
|
53
|
+
* actions. Default `5000`. Set to `0` to skip waiting.
|
|
54
|
+
*/
|
|
55
|
+
settleTimeoutMs?: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A {@link BrowserController} backed by a Playwright `Page`. Coordinates
|
|
59
|
+
* arrive already denormalized to pixels by the computer-use tools, so this
|
|
60
|
+
* class drives Playwright directly.
|
|
61
|
+
*/
|
|
62
|
+
declare class PlaywrightController implements BrowserController {
|
|
63
|
+
private readonly page;
|
|
64
|
+
private readonly width;
|
|
65
|
+
private readonly height;
|
|
66
|
+
private readonly screenshotQuality;
|
|
67
|
+
private readonly screenshotType;
|
|
68
|
+
private readonly settleTimeoutMs;
|
|
69
|
+
constructor(page: Page, opts?: PlaywrightControllerOptions);
|
|
70
|
+
viewport(): Viewport;
|
|
71
|
+
screenshot(): Promise<Screenshot>;
|
|
72
|
+
currentUrl(): string;
|
|
73
|
+
navigate(url: string): Promise<void>;
|
|
74
|
+
clickAt(x: number, y: number): Promise<void>;
|
|
75
|
+
hoverAt(x: number, y: number): Promise<void>;
|
|
76
|
+
typeTextAt(x: number, y: number, text: string, opts: TypeTextOptions): Promise<void>;
|
|
77
|
+
keyCombination(keys: string): Promise<void>;
|
|
78
|
+
scrollAt(x: number, y: number, direction: ScrollDirection, magnitude: number): Promise<void>;
|
|
79
|
+
scrollDocument(direction: ScrollDirection): Promise<void>;
|
|
80
|
+
dragAndDrop(x: number, y: number, destX: number, destY: number): Promise<void>;
|
|
81
|
+
goBack(): Promise<void>;
|
|
82
|
+
goForward(): Promise<void>;
|
|
83
|
+
private settle;
|
|
84
|
+
}
|
|
85
|
+
/** @internal Exported for unit tests. */
|
|
86
|
+
declare function scrollDelta(direction: ScrollDirection, magnitude: number): [number, number];
|
|
87
|
+
|
|
88
|
+
export { PlaywrightController, type PlaywrightControllerOptions, scrollDelta };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Page } from 'playwright';
|
|
2
|
+
import { B as BrowserController, V as Viewport, S as Screenshot, T as TypeTextOptions, f as ScrollDirection } from './computer-use-B9eNnX_y.js';
|
|
3
|
+
import './client-IjrvboaL.js';
|
|
4
|
+
import 'zod';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Playwright-backed {@link BrowserController} for computer use.
|
|
8
|
+
*
|
|
9
|
+
* Loaded from a separate sub-export (`@mantyx/sdk/playwright`) so apps that
|
|
10
|
+
* don't drive a browser never pay the Playwright bundle cost. Install the
|
|
11
|
+
* optional peer dep first:
|
|
12
|
+
*
|
|
13
|
+
* npm install playwright
|
|
14
|
+
* npx playwright install chromium
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* import { MantyxClient, runComputerUse } from "@mantyx/sdk";
|
|
18
|
+
* import { PlaywrightController } from "@mantyx/sdk/playwright";
|
|
19
|
+
* import { chromium } from "playwright";
|
|
20
|
+
*
|
|
21
|
+
* const browser = await chromium.launch();
|
|
22
|
+
* const page = await (await browser.newContext()).newPage();
|
|
23
|
+
* const controller = new PlaywrightController(page);
|
|
24
|
+
*
|
|
25
|
+
* const out = await runComputerUse({
|
|
26
|
+
* client,
|
|
27
|
+
* goal: "Find the top story on news.ycombinator.com",
|
|
28
|
+
* controller,
|
|
29
|
+
* });
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
interface PlaywrightControllerOptions {
|
|
33
|
+
/**
|
|
34
|
+
* Viewport width in pixels. Should match the browser context viewport so
|
|
35
|
+
* denormalized coordinates from the model land on the right pixels.
|
|
36
|
+
* Default `1440`.
|
|
37
|
+
*/
|
|
38
|
+
width?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Viewport height in pixels. Default `900`.
|
|
41
|
+
*/
|
|
42
|
+
height?: number;
|
|
43
|
+
/**
|
|
44
|
+
* JPEG quality for screenshots (`0`–`100`). Ignored when
|
|
45
|
+
* `screenshotType` is `"png"`. Default `70` — keeps inline attachments
|
|
46
|
+
* well under the 5 MB cap.
|
|
47
|
+
*/
|
|
48
|
+
screenshotQuality?: number;
|
|
49
|
+
/** Screenshot format. Default `"jpeg"`. */
|
|
50
|
+
screenshotType?: "jpeg" | "png";
|
|
51
|
+
/**
|
|
52
|
+
* Max milliseconds to wait for `networkidle` after navigation and UI
|
|
53
|
+
* actions. Default `5000`. Set to `0` to skip waiting.
|
|
54
|
+
*/
|
|
55
|
+
settleTimeoutMs?: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A {@link BrowserController} backed by a Playwright `Page`. Coordinates
|
|
59
|
+
* arrive already denormalized to pixels by the computer-use tools, so this
|
|
60
|
+
* class drives Playwright directly.
|
|
61
|
+
*/
|
|
62
|
+
declare class PlaywrightController implements BrowserController {
|
|
63
|
+
private readonly page;
|
|
64
|
+
private readonly width;
|
|
65
|
+
private readonly height;
|
|
66
|
+
private readonly screenshotQuality;
|
|
67
|
+
private readonly screenshotType;
|
|
68
|
+
private readonly settleTimeoutMs;
|
|
69
|
+
constructor(page: Page, opts?: PlaywrightControllerOptions);
|
|
70
|
+
viewport(): Viewport;
|
|
71
|
+
screenshot(): Promise<Screenshot>;
|
|
72
|
+
currentUrl(): string;
|
|
73
|
+
navigate(url: string): Promise<void>;
|
|
74
|
+
clickAt(x: number, y: number): Promise<void>;
|
|
75
|
+
hoverAt(x: number, y: number): Promise<void>;
|
|
76
|
+
typeTextAt(x: number, y: number, text: string, opts: TypeTextOptions): Promise<void>;
|
|
77
|
+
keyCombination(keys: string): Promise<void>;
|
|
78
|
+
scrollAt(x: number, y: number, direction: ScrollDirection, magnitude: number): Promise<void>;
|
|
79
|
+
scrollDocument(direction: ScrollDirection): Promise<void>;
|
|
80
|
+
dragAndDrop(x: number, y: number, destX: number, destY: number): Promise<void>;
|
|
81
|
+
goBack(): Promise<void>;
|
|
82
|
+
goForward(): Promise<void>;
|
|
83
|
+
private settle;
|
|
84
|
+
}
|
|
85
|
+
/** @internal Exported for unit tests. */
|
|
86
|
+
declare function scrollDelta(direction: ScrollDirection, magnitude: number): [number, number];
|
|
87
|
+
|
|
88
|
+
export { PlaywrightController, type PlaywrightControllerOptions, scrollDelta };
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// src/playwright.ts
|
|
2
|
+
var DEFAULT_WIDTH = 1440;
|
|
3
|
+
var DEFAULT_HEIGHT = 900;
|
|
4
|
+
var DEFAULT_QUALITY = 70;
|
|
5
|
+
var DEFAULT_SETTLE_MS = 5e3;
|
|
6
|
+
var PlaywrightController = class {
|
|
7
|
+
constructor(page, opts = {}) {
|
|
8
|
+
this.page = page;
|
|
9
|
+
this.width = opts.width ?? DEFAULT_WIDTH;
|
|
10
|
+
this.height = opts.height ?? DEFAULT_HEIGHT;
|
|
11
|
+
this.screenshotQuality = opts.screenshotQuality ?? DEFAULT_QUALITY;
|
|
12
|
+
this.screenshotType = opts.screenshotType ?? "jpeg";
|
|
13
|
+
this.settleTimeoutMs = opts.settleTimeoutMs ?? DEFAULT_SETTLE_MS;
|
|
14
|
+
}
|
|
15
|
+
page;
|
|
16
|
+
width;
|
|
17
|
+
height;
|
|
18
|
+
screenshotQuality;
|
|
19
|
+
screenshotType;
|
|
20
|
+
settleTimeoutMs;
|
|
21
|
+
viewport() {
|
|
22
|
+
return { width: this.width, height: this.height };
|
|
23
|
+
}
|
|
24
|
+
async screenshot() {
|
|
25
|
+
if (this.screenshotType === "png") {
|
|
26
|
+
const buf2 = await this.page.screenshot({ type: "png" });
|
|
27
|
+
return { data: buf2.toString("base64"), mimeType: "image/png" };
|
|
28
|
+
}
|
|
29
|
+
const buf = await this.page.screenshot({
|
|
30
|
+
type: "jpeg",
|
|
31
|
+
quality: this.screenshotQuality
|
|
32
|
+
});
|
|
33
|
+
return { data: buf.toString("base64"), mimeType: "image/jpeg" };
|
|
34
|
+
}
|
|
35
|
+
currentUrl() {
|
|
36
|
+
return this.page.url();
|
|
37
|
+
}
|
|
38
|
+
async navigate(url) {
|
|
39
|
+
await this.page.goto(url);
|
|
40
|
+
await this.settle();
|
|
41
|
+
}
|
|
42
|
+
async clickAt(x, y) {
|
|
43
|
+
await this.page.mouse.click(x, y);
|
|
44
|
+
await this.settle();
|
|
45
|
+
}
|
|
46
|
+
async hoverAt(x, y) {
|
|
47
|
+
await this.page.mouse.move(x, y);
|
|
48
|
+
}
|
|
49
|
+
async typeTextAt(x, y, text, opts) {
|
|
50
|
+
await this.page.mouse.click(x, y);
|
|
51
|
+
if (opts.clearBeforeTyping) {
|
|
52
|
+
await this.page.keyboard.press("ControlOrMeta+A");
|
|
53
|
+
await this.page.keyboard.press("Backspace");
|
|
54
|
+
}
|
|
55
|
+
await this.page.keyboard.type(text);
|
|
56
|
+
if (opts.pressEnter) await this.page.keyboard.press("Enter");
|
|
57
|
+
await this.settle();
|
|
58
|
+
}
|
|
59
|
+
async keyCombination(keys) {
|
|
60
|
+
await this.page.keyboard.press(keys.replace(/\s+/g, ""));
|
|
61
|
+
await this.settle();
|
|
62
|
+
}
|
|
63
|
+
async scrollAt(x, y, direction, magnitude) {
|
|
64
|
+
await this.page.mouse.move(x, y);
|
|
65
|
+
const [dx, dy] = scrollDelta(direction, magnitude);
|
|
66
|
+
await this.page.mouse.wheel(dx, dy);
|
|
67
|
+
await this.settle();
|
|
68
|
+
}
|
|
69
|
+
async scrollDocument(direction) {
|
|
70
|
+
const [dx, dy] = scrollDelta(direction, 800);
|
|
71
|
+
await this.page.mouse.wheel(dx, dy);
|
|
72
|
+
await this.settle();
|
|
73
|
+
}
|
|
74
|
+
async dragAndDrop(x, y, destX, destY) {
|
|
75
|
+
await this.page.mouse.move(x, y);
|
|
76
|
+
await this.page.mouse.down();
|
|
77
|
+
await this.page.mouse.move(destX, destY, { steps: 10 });
|
|
78
|
+
await this.page.mouse.up();
|
|
79
|
+
await this.settle();
|
|
80
|
+
}
|
|
81
|
+
async goBack() {
|
|
82
|
+
await this.page.goBack();
|
|
83
|
+
await this.settle();
|
|
84
|
+
}
|
|
85
|
+
async goForward() {
|
|
86
|
+
await this.page.goForward();
|
|
87
|
+
await this.settle();
|
|
88
|
+
}
|
|
89
|
+
async settle() {
|
|
90
|
+
if (this.settleTimeoutMs <= 0) return;
|
|
91
|
+
try {
|
|
92
|
+
await this.page.waitForLoadState("networkidle", { timeout: this.settleTimeoutMs });
|
|
93
|
+
} catch {
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
function scrollDelta(direction, magnitude) {
|
|
98
|
+
switch (direction) {
|
|
99
|
+
case "up":
|
|
100
|
+
return [0, -magnitude];
|
|
101
|
+
case "down":
|
|
102
|
+
return [0, magnitude];
|
|
103
|
+
case "left":
|
|
104
|
+
return [-magnitude, 0];
|
|
105
|
+
case "right":
|
|
106
|
+
return [magnitude, 0];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export {
|
|
110
|
+
PlaywrightController,
|
|
111
|
+
scrollDelta
|
|
112
|
+
};
|
|
113
|
+
//# sourceMappingURL=playwright.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/playwright.ts"],"sourcesContent":["/**\n * Playwright-backed {@link BrowserController} for computer use.\n *\n * Loaded from a separate sub-export (`@mantyx/sdk/playwright`) so apps that\n * don't drive a browser never pay the Playwright bundle cost. Install the\n * optional peer dep first:\n *\n * npm install playwright\n * npx playwright install chromium\n *\n * @example\n * import { MantyxClient, runComputerUse } from \"@mantyx/sdk\";\n * import { PlaywrightController } from \"@mantyx/sdk/playwright\";\n * import { chromium } from \"playwright\";\n *\n * const browser = await chromium.launch();\n * const page = await (await browser.newContext()).newPage();\n * const controller = new PlaywrightController(page);\n *\n * const out = await runComputerUse({\n * client,\n * goal: \"Find the top story on news.ycombinator.com\",\n * controller,\n * });\n */\nimport type { Page } from \"playwright\";\nimport type {\n BrowserController,\n Screenshot,\n ScrollDirection,\n TypeTextOptions,\n Viewport,\n} from \"./computer-use.js\";\n\nexport interface PlaywrightControllerOptions {\n /**\n * Viewport width in pixels. Should match the browser context viewport so\n * denormalized coordinates from the model land on the right pixels.\n * Default `1440`.\n */\n width?: number;\n /**\n * Viewport height in pixels. Default `900`.\n */\n height?: number;\n /**\n * JPEG quality for screenshots (`0`–`100`). Ignored when\n * `screenshotType` is `\"png\"`. Default `70` — keeps inline attachments\n * well under the 5 MB cap.\n */\n screenshotQuality?: number;\n /** Screenshot format. Default `\"jpeg\"`. */\n screenshotType?: \"jpeg\" | \"png\";\n /**\n * Max milliseconds to wait for `networkidle` after navigation and UI\n * actions. Default `5000`. Set to `0` to skip waiting.\n */\n settleTimeoutMs?: number;\n}\n\nconst DEFAULT_WIDTH = 1440;\nconst DEFAULT_HEIGHT = 900;\nconst DEFAULT_QUALITY = 70;\nconst DEFAULT_SETTLE_MS = 5000;\n\n/**\n * A {@link BrowserController} backed by a Playwright `Page`. Coordinates\n * arrive already denormalized to pixels by the computer-use tools, so this\n * class drives Playwright directly.\n */\nexport class PlaywrightController implements BrowserController {\n private readonly width: number;\n private readonly height: number;\n private readonly screenshotQuality: number;\n private readonly screenshotType: \"jpeg\" | \"png\";\n private readonly settleTimeoutMs: number;\n\n constructor(\n private readonly page: Page,\n opts: PlaywrightControllerOptions = {},\n ) {\n this.width = opts.width ?? DEFAULT_WIDTH;\n this.height = opts.height ?? DEFAULT_HEIGHT;\n this.screenshotQuality = opts.screenshotQuality ?? DEFAULT_QUALITY;\n this.screenshotType = opts.screenshotType ?? \"jpeg\";\n this.settleTimeoutMs = opts.settleTimeoutMs ?? DEFAULT_SETTLE_MS;\n }\n\n viewport(): Viewport {\n return { width: this.width, height: this.height };\n }\n\n async screenshot(): Promise<Screenshot> {\n if (this.screenshotType === \"png\") {\n const buf = await this.page.screenshot({ type: \"png\" });\n return { data: buf.toString(\"base64\"), mimeType: \"image/png\" };\n }\n const buf = await this.page.screenshot({\n type: \"jpeg\",\n quality: this.screenshotQuality,\n });\n return { data: buf.toString(\"base64\"), mimeType: \"image/jpeg\" };\n }\n\n currentUrl(): string {\n return this.page.url();\n }\n\n async navigate(url: string): Promise<void> {\n await this.page.goto(url);\n await this.settle();\n }\n\n async clickAt(x: number, y: number): Promise<void> {\n await this.page.mouse.click(x, y);\n await this.settle();\n }\n\n async hoverAt(x: number, y: number): Promise<void> {\n await this.page.mouse.move(x, y);\n }\n\n async typeTextAt(x: number, y: number, text: string, opts: TypeTextOptions): Promise<void> {\n await this.page.mouse.click(x, y);\n if (opts.clearBeforeTyping) {\n await this.page.keyboard.press(\"ControlOrMeta+A\");\n await this.page.keyboard.press(\"Backspace\");\n }\n await this.page.keyboard.type(text);\n if (opts.pressEnter) await this.page.keyboard.press(\"Enter\");\n await this.settle();\n }\n\n async keyCombination(keys: string): Promise<void> {\n await this.page.keyboard.press(keys.replace(/\\s+/g, \"\"));\n await this.settle();\n }\n\n async scrollAt(\n x: number,\n y: number,\n direction: ScrollDirection,\n magnitude: number,\n ): Promise<void> {\n await this.page.mouse.move(x, y);\n const [dx, dy] = scrollDelta(direction, magnitude);\n await this.page.mouse.wheel(dx, dy);\n await this.settle();\n }\n\n async scrollDocument(direction: ScrollDirection): Promise<void> {\n const [dx, dy] = scrollDelta(direction, 800);\n await this.page.mouse.wheel(dx, dy);\n await this.settle();\n }\n\n async dragAndDrop(x: number, y: number, destX: number, destY: number): Promise<void> {\n await this.page.mouse.move(x, y);\n await this.page.mouse.down();\n await this.page.mouse.move(destX, destY, { steps: 10 });\n await this.page.mouse.up();\n await this.settle();\n }\n\n async goBack(): Promise<void> {\n await this.page.goBack();\n await this.settle();\n }\n\n async goForward(): Promise<void> {\n await this.page.goForward();\n await this.settle();\n }\n\n private async settle(): Promise<void> {\n if (this.settleTimeoutMs <= 0) return;\n try {\n await this.page.waitForLoadState(\"networkidle\", { timeout: this.settleTimeoutMs });\n } catch {\n // Best-effort; some pages never reach networkidle.\n }\n }\n}\n\n/** @internal Exported for unit tests. */\nexport function scrollDelta(direction: ScrollDirection, magnitude: number): [number, number] {\n switch (direction) {\n case \"up\":\n return [0, -magnitude];\n case \"down\":\n return [0, magnitude];\n case \"left\":\n return [-magnitude, 0];\n case \"right\":\n return [magnitude, 0];\n }\n}\n"],"mappings":";AA4DA,IAAM,gBAAgB;AACtB,IAAM,iBAAiB;AACvB,IAAM,kBAAkB;AACxB,IAAM,oBAAoB;AAOnB,IAAM,uBAAN,MAAwD;AAAA,EAO7D,YACmB,MACjB,OAAoC,CAAC,GACrC;AAFiB;AAGjB,SAAK,QAAQ,KAAK,SAAS;AAC3B,SAAK,SAAS,KAAK,UAAU;AAC7B,SAAK,oBAAoB,KAAK,qBAAqB;AACnD,SAAK,iBAAiB,KAAK,kBAAkB;AAC7C,SAAK,kBAAkB,KAAK,mBAAmB;AAAA,EACjD;AAAA,EARmB;AAAA,EAPF;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAajB,WAAqB;AACnB,WAAO,EAAE,OAAO,KAAK,OAAO,QAAQ,KAAK,OAAO;AAAA,EAClD;AAAA,EAEA,MAAM,aAAkC;AACtC,QAAI,KAAK,mBAAmB,OAAO;AACjC,YAAMA,OAAM,MAAM,KAAK,KAAK,WAAW,EAAE,MAAM,MAAM,CAAC;AACtD,aAAO,EAAE,MAAMA,KAAI,SAAS,QAAQ,GAAG,UAAU,YAAY;AAAA,IAC/D;AACA,UAAM,MAAM,MAAM,KAAK,KAAK,WAAW;AAAA,MACrC,MAAM;AAAA,MACN,SAAS,KAAK;AAAA,IAChB,CAAC;AACD,WAAO,EAAE,MAAM,IAAI,SAAS,QAAQ,GAAG,UAAU,aAAa;AAAA,EAChE;AAAA,EAEA,aAAqB;AACnB,WAAO,KAAK,KAAK,IAAI;AAAA,EACvB;AAAA,EAEA,MAAM,SAAS,KAA4B;AACzC,UAAM,KAAK,KAAK,KAAK,GAAG;AACxB,UAAM,KAAK,OAAO;AAAA,EACpB;AAAA,EA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AAK,MAAM,KAAK;AAC3B,UAAM,KAAK,KAAK,MAAM,KAAK,OAAO,OAAO,EAAE,OAAO,GAAG,CAAC;AACtD,UAAM,KAAK,KAAK,MAAM,GAAG;AACzB,UAAM,KAAK,OAAO;AAAA,EACpB;AAAA,EAEA,MAAM,SAAwB;AAC5B,UAAM,KAAK,KAAK,OAAO;AACvB,UAAM,KAAK,OAAO;AAAA,EACpB;AAAA,EAEA,MAAM,YAA2B;AAC/B,UAAM,KAAK,KAAK,UAAU;AAC1B,UAAM,KAAK,OAAO;AAAA,EACpB;AAAA,EAEA,MAAc,SAAwB;AACpC,QAAI,KAAK,mBAAmB,EAAG;AAC/B,QAAI;AACF,YAAM,KAAK,KAAK,iBAAiB,eAAe,EAAE,SAAS,KAAK,gBAAgB,CAAC;AAAA,IACnF,QAAQ;AAAA,IAER;AAAA,EACF;AACF;AAGO,SAAS,YAAY,WAA4B,WAAqC;AAC3F,UAAQ,WAAW;AAAA,IACjB,KAAK;AACH,aAAO,CAAC,GAAG,CAAC,SAAS;AAAA,IACvB,KAAK;AACH,aAAO,CAAC,GAAG,SAAS;AAAA,IACtB,KAAK;AACH,aAAO,CAAC,CAAC,WAAW,CAAC;AAAA,IACvB,KAAK;AACH,aAAO,CAAC,WAAW,CAAC;AAAA,EACxB;AACF;","names":["buf"]}
|
|
@@ -28,7 +28,7 @@ array:
|
|
|
28
28
|
| --------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
29
29
|
| `mantyx` | server | A workspace `Tool` row referenced by id (HTTP / Code / Plugin). |
|
|
30
30
|
| `mantyx_plugin` | server | A platform plugin tool referenced by name. |
|
|
31
|
-
| `local` | client | A custom tool defined and executed in the SDK's process. Carries `parameters` (input JSON Schema) plus optional `outputSchema` (return-value JSON Schema) and `
|
|
31
|
+
| `local` | client | A custom tool defined and executed in the SDK's process. Carries `parameters` (input JSON Schema) plus optional `outputSchema` (return-value JSON Schema), `longRunning`, and `readOnly` (parallel-batch) flags — see §4.1.1. |
|
|
32
32
|
| `a2a` | server | A _remote_ Agent2Agent peer MANTYX can reach; invoked via `message/send` and the reply is surfaced as the tool result. |
|
|
33
33
|
| `a2a_local` | client | An A2A peer MANTYX **cannot** reach. SDK resolves the [Agent Card](https://google.github.io/A2A/specification/#agent-card) locally and ships it inline; MANTYX uses it for the model description and routes calls back to the SDK over SSE. |
|
|
34
34
|
| `mcp` | server | A _remote_ MCP server (Streamable HTTP). At run start MANTYX lists the catalog and exposes every tool as `<server>_<tool>` (subject to `toolFilter`). |
|
|
@@ -123,6 +123,7 @@ two differences:
|
|
|
123
123
|
| `GET .../agent-runs/{runId}/stream` | `runs:read` |
|
|
124
124
|
| `POST .../agent-runs/{runId}/cancel` | `runs:write` |
|
|
125
125
|
| `POST .../agent-runs/{runId}/tool-results` | `runs:write` |
|
|
126
|
+
| `POST .../agent-runs/{runId}/feedback` | `feedback:write` |
|
|
126
127
|
| `POST .../agent-sessions` | `sessions:write` |
|
|
127
128
|
| `GET .../agent-sessions` | `sessions:read` |
|
|
128
129
|
| `GET .../agent-sessions/{sessionId}` | `sessions:read` |
|
|
@@ -281,6 +282,7 @@ The agent spec is the body shape used by `POST /agent-runs` and `POST
|
|
|
281
282
|
"required": ["bytes"],
|
|
282
283
|
},
|
|
283
284
|
"longRunning": false, // optional — default false
|
|
285
|
+
"readOnly": false, // optional — default false; true ⇒ may run in parallel with other reads
|
|
284
286
|
},
|
|
285
287
|
{
|
|
286
288
|
"kind": "a2a",
|
|
@@ -476,12 +478,14 @@ for the SDK to POST a tool-result.
|
|
|
476
478
|
| `parameters` | no | JSON Schema for the tool's input. Must be a `type: "object"` schema with `properties`; non-object roots are coerced to an empty object schema server-side. Forwarded **verbatim** to the LLM provider so nested constraints (`array.items`, `enum`, `anyOf`, numeric formats, …) survive. Args that fail server-side validation produce a structured `tool_input_invalid` tool result the model can recover from instead of crashing the call. |
|
|
477
479
|
| `outputSchema` | no | JSON Schema for the structured value the tool returns. When present, forwarded to providers that accept per-tool response schemas (Gemini's `responseJsonSchema` on the FunctionDeclaration); other engines surface it through the description and rely on host-side validation. Helps the model emit follow-up arguments that round-trip cleanly. Must be an object schema; non-object roots are dropped server-side. |
|
|
478
480
|
| `longRunning` | no | When `true`, MANTYX appends a stable hint to the model-facing description so every provider treats the tool as long-running:<br>_"NOTE: This is a long-running operation. Do not call this tool again if it has already returned an intermediate or pending status."_<br>Useful for tools that return `pending` and rely on SDK-side polling — without the hint the model routinely fires repeat calls and burns turns. Pure declarative — MANTYX does not change scheduling. |
|
|
481
|
+
| `readOnly` | no | When `true`, the tool may run **in parallel** with other read-only tools the model emits in the same turn — MANTYX publishes every such `local_tool_call` concurrently and resolves them together, instead of one-at-a-time in model-emit order. Set this only for side-effect-free tools whose results don't depend on each other, and make sure your SDK can service several outstanding `local_tool_call` events at once (each carries its own `toolUseId`; post a tool-result per id in any order). Mutating tools (the default, `false`) stay strictly sequential. |
|
|
479
482
|
|
|
480
|
-
The `outputSchema` and `
|
|
481
|
-
protocol v1: SDKs that don't ship them keep working unchanged.
|
|
482
|
-
without per-tool response-schema support (OpenAI, Anthropic,
|
|
483
|
-
Grok) accept the new fields silently — the schema is treated as a
|
|
484
|
-
description hint and host-side validation still runs.
|
|
483
|
+
The `outputSchema`, `longRunning`, and `readOnly` fields are **additive**
|
|
484
|
+
since wire protocol v1: SDKs that don't ship them keep working unchanged.
|
|
485
|
+
Providers without per-tool response-schema support (OpenAI, Anthropic,
|
|
486
|
+
Bedrock, Grok) accept the new fields silently — the schema is treated as a
|
|
487
|
+
description hint and host-side validation still runs. `readOnly` defaults to
|
|
488
|
+
`false`, so omitting it preserves the original sequential behavior.
|
|
485
489
|
|
|
486
490
|
### 4.2 A2A tool refs
|
|
487
491
|
|
|
@@ -1067,6 +1071,7 @@ GET /api/v1/workspaces/{slug}/agent-runs/{runId}
|
|
|
1067
1071
|
GET /api/v1/workspaces/{slug}/agent-runs/{runId}/stream
|
|
1068
1072
|
POST /api/v1/workspaces/{slug}/agent-runs/{runId}/tool-results
|
|
1069
1073
|
POST /api/v1/workspaces/{slug}/agent-runs/{runId}/cancel
|
|
1074
|
+
POST /api/v1/workspaces/{slug}/agent-runs/{runId}/feedback
|
|
1070
1075
|
```
|
|
1071
1076
|
|
|
1072
1077
|
`POST /agent-runs` returns `202 Accepted` immediately:
|
|
@@ -1465,6 +1470,41 @@ Idempotent. The run will produce a terminal `cancelled` event on the SSE
|
|
|
1465
1470
|
stream. In-flight `tool-results` posted after cancellation are accepted with
|
|
1466
1471
|
`200 OK` but ignored.
|
|
1467
1472
|
|
|
1473
|
+
## 9a. Run feedback
|
|
1474
|
+
|
|
1475
|
+
```
|
|
1476
|
+
POST /api/v1/workspaces/{slug}/agent-runs/{runId}/feedback
|
|
1477
|
+
```
|
|
1478
|
+
|
|
1479
|
+
Record thumbs up/down feedback on a completed (or in-flight) run — the same
|
|
1480
|
+
`ReplyFeedback` signal the web product collects on chat replies and artifacts,
|
|
1481
|
+
extended to ephemeral SDK runs. Requires the `feedback:write` scope.
|
|
1482
|
+
|
|
1483
|
+
Request body:
|
|
1484
|
+
|
|
1485
|
+
```jsonc
|
|
1486
|
+
{
|
|
1487
|
+
"verdict": "UP", // "UP" | "DOWN" (required)
|
|
1488
|
+
"explanation": "Nailed it", // optional free-text note (≤ 8000 chars)
|
|
1489
|
+
"contentSnapshot": "..." // optional; defaults to the run's finalText
|
|
1490
|
+
}
|
|
1491
|
+
```
|
|
1492
|
+
|
|
1493
|
+
The feedback is **idempotent per run**: one verdict per `(workspace, run)`. A
|
|
1494
|
+
repeated call updates the existing row (last-write-wins) and returns `200`; the
|
|
1495
|
+
first call returns `201`. Response:
|
|
1496
|
+
|
|
1497
|
+
```jsonc
|
|
1498
|
+
{ "id": "fb_…", "verdict": "UP", "targetKind": "agent_run", "agentRunId": "run_…" }
|
|
1499
|
+
```
|
|
1500
|
+
|
|
1501
|
+
The author is attributed to the calling workspace **API key** (`apiKeyId`); OAuth
|
|
1502
|
+
tokens leave the author null. Recorded feedback surfaces in the workspace
|
|
1503
|
+
**API feedback** dashboard (Developer area) and the read-only
|
|
1504
|
+
`GET .../reply-feedback` listing (scope `feedback:read`; **agent-run feedback
|
|
1505
|
+
only** — in-product chat and artifact feedback is workspace-admin only). Unknown
|
|
1506
|
+
runs return `404 { "error": "Run not found" }`.
|
|
1507
|
+
|
|
1468
1508
|
## 10. Errors
|
|
1469
1509
|
|
|
1470
1510
|
All non-2xx responses use this body shape:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mantyx/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "MANTYX as a hosted agent runtime: define ephemeral agents, mix server-side MANTYX tools with locally-executed tools, run them remotely.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
"types": "./dist/a2a-server.d.ts",
|
|
17
17
|
"import": "./dist/a2a-server.js",
|
|
18
18
|
"require": "./dist/a2a-server.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./playwright": {
|
|
21
|
+
"types": "./dist/playwright.d.ts",
|
|
22
|
+
"import": "./dist/playwright.js",
|
|
23
|
+
"require": "./dist/playwright.cjs"
|
|
19
24
|
}
|
|
20
25
|
},
|
|
21
26
|
"files": [
|
|
@@ -44,7 +49,8 @@
|
|
|
44
49
|
},
|
|
45
50
|
"peerDependencies": {
|
|
46
51
|
"@a2a-js/sdk": "^0.3.0",
|
|
47
|
-
"express": "^4.0.0 || ^5.0.0"
|
|
52
|
+
"express": "^4.0.0 || ^5.0.0",
|
|
53
|
+
"playwright": "^1.40.0"
|
|
48
54
|
},
|
|
49
55
|
"peerDependenciesMeta": {
|
|
50
56
|
"@a2a-js/sdk": {
|
|
@@ -52,6 +58,9 @@
|
|
|
52
58
|
},
|
|
53
59
|
"express": {
|
|
54
60
|
"optional": true
|
|
61
|
+
},
|
|
62
|
+
"playwright": {
|
|
63
|
+
"optional": true
|
|
55
64
|
}
|
|
56
65
|
},
|
|
57
66
|
"devDependencies": {
|
|
@@ -59,6 +68,7 @@
|
|
|
59
68
|
"@types/express": "^5.0.0",
|
|
60
69
|
"@types/node": "^22.0.0",
|
|
61
70
|
"express": "^5.0.0",
|
|
71
|
+
"playwright": "^1.48.0",
|
|
62
72
|
"tsup": "^8.3.0",
|
|
63
73
|
"typescript": "^5.6.0",
|
|
64
74
|
"vitest": "^2.1.0"
|