@mantyx/sdk 0.16.0 → 0.18.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.
@@ -0,0 +1,193 @@
1
+ import { ai as RunResult, M as MantyxClient, R as ReasoningLevel, s as LocalTool } from './client-CLT46vp5.js';
2
+
3
+ /** Scroll direction shared by `scroll_at` / `scroll_document`. */
4
+ type ScrollDirection = "up" | "down" | "left" | "right";
5
+ /** Pixel viewport of the controlled surface, used to denormalize coordinates. */
6
+ interface Viewport {
7
+ width: number;
8
+ height: number;
9
+ }
10
+ /** A captured screenshot, base64-encoded (no `data:` prefix). */
11
+ interface Screenshot {
12
+ /** Base64-encoded image bytes (no `data:` URL prefix). */
13
+ data: string;
14
+ /** Image MIME type, e.g. `"image/jpeg"` or `"image/png"`. */
15
+ mimeType: string;
16
+ /** Optional filename for the attachment; a default is generated otherwise. */
17
+ filename?: string;
18
+ }
19
+ /** Options forwarded to {@link BrowserController.typeTextAt}. */
20
+ interface TypeTextOptions {
21
+ /** Press Enter after typing. */
22
+ pressEnter: boolean;
23
+ /** Clear the field before typing. */
24
+ clearBeforeTyping: boolean;
25
+ }
26
+ /**
27
+ * The execution surface the computer-use tools drive. Coordinates passed to
28
+ * these methods are **already denormalized to pixels** against
29
+ * {@link viewport}. Implement this with Playwright, Puppeteer, a remote
30
+ * browser, a mobile driver, etc. For Playwright, use
31
+ * {@link PlaywrightController} from `@mantyx/sdk/playwright`.
32
+ *
33
+ * Every method may be sync or async. Methods for actions you exclude via
34
+ * {@link DefineComputerUseToolsOptions.excludeActions} are never called and
35
+ * can be omitted.
36
+ */
37
+ interface BrowserController {
38
+ /** Current pixel viewport. Used to denormalize the model's 0-1000 coords. */
39
+ viewport(): Viewport | Promise<Viewport>;
40
+ /** Capture the current screen. Called once per loop step. */
41
+ screenshot(): Screenshot | Promise<Screenshot>;
42
+ /** Current page URL, if meaningful for the environment. Optional. */
43
+ currentUrl?(): string | Promise<string>;
44
+ /** Navigate directly to a URL. */
45
+ navigate?(url: string): void | Promise<void>;
46
+ /** Click at a pixel coordinate. */
47
+ clickAt(x: number, y: number): void | Promise<void>;
48
+ /** Hover at a pixel coordinate. */
49
+ hoverAt?(x: number, y: number): void | Promise<void>;
50
+ /** Type `text` at a pixel coordinate. */
51
+ typeTextAt(x: number, y: number, text: string, opts: TypeTextOptions): void | Promise<void>;
52
+ /** Press a key or chord, e.g. `"Enter"` or `"Control+C"`. */
53
+ keyCombination?(keys: string): void | Promise<void>;
54
+ /** Scroll the element at a pixel coordinate by `magnitude` pixels. */
55
+ scrollAt?(x: number, y: number, direction: ScrollDirection, magnitude: number): void | Promise<void>;
56
+ /** Scroll the whole document. */
57
+ scrollDocument?(direction: ScrollDirection): void | Promise<void>;
58
+ /** Drag from one pixel coordinate to another. */
59
+ dragAndDrop?(x: number, y: number, destinationX: number, destinationY: number): void | Promise<void>;
60
+ /** Navigate back in history. */
61
+ goBack?(): void | Promise<void>;
62
+ /** Navigate forward in history. */
63
+ goForward?(): void | Promise<void>;
64
+ }
65
+ /**
66
+ * Convert a normalized coordinate (0-1000 grid, matching the convention used
67
+ * by GUI-control models) to an actual pixel value.
68
+ */
69
+ declare function denormalizeCoordinate(value: number, size: number): number;
70
+ /** The canonical computer-use action tool names. */
71
+ declare const COMPUTER_USE_ACTIONS: readonly ["navigate", "click_at", "hover_at", "type_text_at", "key_combination", "scroll_at", "scroll_document", "drag_and_drop", "go_back", "go_forward", "wait"];
72
+ type ComputerUseAction = (typeof COMPUTER_USE_ACTIONS)[number];
73
+ interface DefineComputerUseToolsOptions {
74
+ /**
75
+ * Predefined actions to omit (mirrors a dedicated model's
76
+ * `excluded_predefined_functions`). Useful when an environment cannot
77
+ * support an action, e.g. excluding `drag_and_drop` or the navigation
78
+ * actions for a kiosk.
79
+ */
80
+ excludeActions?: ComputerUseAction[];
81
+ /**
82
+ * Include a `request_confirmation` tool the model is told to call before
83
+ * consequential or irreversible actions. The returned promise/boolean from
84
+ * `confirm` decides whether the model is cleared to proceed. Defaults to
85
+ * `true`; when no `confirm` is supplied, confirmation requests are denied.
86
+ */
87
+ requestConfirmation?: boolean;
88
+ /**
89
+ * Human-in-the-loop gate invoked by the `request_confirmation` tool. Return
90
+ * `true` to allow the model to continue with the action it described.
91
+ */
92
+ confirm?: (reason: string) => boolean | Promise<boolean>;
93
+ }
94
+ /**
95
+ * Build the set of computer-use action tools bound to a
96
+ * {@link BrowserController}. Pass the result as `tools` on a session / run, or
97
+ * let {@link runComputerUse} wire everything for you.
98
+ */
99
+ declare function defineComputerUseTools(controller: BrowserController, opts?: DefineComputerUseToolsOptions): LocalTool[];
100
+ interface ComputerUseSystemPromptOptions {
101
+ /** Environment label injected into the prompt, e.g. `"web browser"`. */
102
+ environment?: string;
103
+ /** Extra task-specific context appended to the standard instructions. */
104
+ extraInstructions?: string;
105
+ /** Whether the `request_confirmation` tool is available (adds safety rules). */
106
+ requestConfirmation?: boolean;
107
+ }
108
+ /**
109
+ * Build the system prompt that drives the loop: it teaches the model the
110
+ * screenshot-per-step protocol, the 0-1000 coordinate grid, the one-action-per-turn
111
+ * discipline, when to stop, and the human-in-the-loop safety rules.
112
+ */
113
+ declare function buildComputerUseSystemPrompt(opts?: ComputerUseSystemPromptOptions): string;
114
+ /** One action the model invoked on a turn (derived from `local_tool_call` events). */
115
+ interface ComputerUseActionCall {
116
+ name: string;
117
+ input: Record<string, unknown>;
118
+ }
119
+ /** A single iteration of the computer-use loop. */
120
+ interface ComputerUseStep {
121
+ /** 1-based step index. */
122
+ step: number;
123
+ /** The screenshot sent to the model at the start of this step. */
124
+ screenshot: Screenshot;
125
+ /** The full run result for the turn. */
126
+ result: RunResult;
127
+ /** Actions the model invoked this turn (empty when it produced a final answer). */
128
+ actions: ComputerUseActionCall[];
129
+ }
130
+ interface RunComputerUseOptions {
131
+ /** MANTYX client used to open the session. */
132
+ client: MantyxClient;
133
+ /** The user's goal, sent on the first turn. */
134
+ goal: string;
135
+ /** Drives the actual UI actions and screenshots. */
136
+ controller: BrowserController;
137
+ /** Vision-capable model id (`modelId`). Omit to use the workspace default. */
138
+ model?: string;
139
+ /** Max loop iterations before stopping. Default 20. */
140
+ maxSteps?: number;
141
+ /** Override the generated system prompt entirely. */
142
+ systemPrompt?: string;
143
+ /** Tweaks for the generated system prompt (ignored when `systemPrompt` is set). */
144
+ systemPromptOptions?: ComputerUseSystemPromptOptions;
145
+ /** Actions to omit from the tool surface. */
146
+ excludeActions?: ComputerUseAction[];
147
+ /** Human-in-the-loop gate for `request_confirmation`. Omit to disable confirmations. */
148
+ confirm?: (reason: string) => boolean | Promise<boolean>;
149
+ /** Disable the `request_confirmation` tool entirely. Default false (it is included). */
150
+ disableConfirmation?: boolean;
151
+ /** Provider reasoning strength for the session. */
152
+ reasoningLevel?: ReasoningLevel;
153
+ /** Observability metadata stored on the session. */
154
+ metadata?: Record<string, string>;
155
+ /** Text sent alongside the screenshot on every turn after the first. */
156
+ continueText?: string;
157
+ /** Invoked after each step (await is honored), e.g. for logging. */
158
+ onStep?: (step: ComputerUseStep) => void | Promise<void>;
159
+ /** Streams assistant text deltas. */
160
+ onAssistantDelta?: (delta: string) => void;
161
+ /** Aborts the loop and the in-flight turn. */
162
+ signal?: AbortSignal;
163
+ }
164
+ interface ComputerUseResult {
165
+ /** The model's final plain-text answer (text of the last turn). */
166
+ finalText: string;
167
+ /** Every step taken, in order. */
168
+ steps: ComputerUseStep[];
169
+ /** The session that ran the loop (already ended). */
170
+ sessionId: string;
171
+ /** Why the loop stopped. */
172
+ stoppedReason: "completed" | "max_steps";
173
+ }
174
+ /** Pull the actions the model invoked this turn from the run's events. */
175
+ declare function extractActions(result: RunResult): ComputerUseActionCall[];
176
+ /**
177
+ * Run a model-agnostic computer-use loop: screenshot → send → one action →
178
+ * repeat, until the model answers in plain text or `maxSteps` is reached. The
179
+ * session is created internally and ended on return.
180
+ *
181
+ * @example
182
+ * const out = await runComputerUse({
183
+ * client,
184
+ * model: "google/gemini-3-flash",
185
+ * goal: "Find the cheapest 2-door smart fridge on the site and report its price.",
186
+ * controller: playwrightController, // implements BrowserController
187
+ * confirm: async (reason) => askOperator(reason),
188
+ * });
189
+ * console.log(out.finalText);
190
+ */
191
+ declare function runComputerUse(opts: RunComputerUseOptions): Promise<ComputerUseResult>;
192
+
193
+ export { type BrowserController as B, COMPUTER_USE_ACTIONS as C, type DefineComputerUseToolsOptions as D, type RunComputerUseOptions as R, type Screenshot as S, type TypeTextOptions as T, type Viewport as V, type ComputerUseAction as a, type ComputerUseActionCall as b, type ComputerUseResult as c, type ComputerUseStep as d, type ComputerUseSystemPromptOptions as e, type ScrollDirection as f, buildComputerUseSystemPrompt as g, defineComputerUseTools as h, denormalizeCoordinate as i, extractActions as j, runComputerUse as r };