@mantyx/sdk 0.22.0 → 0.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/a2a-server.cjs.map +1 -1
  3. package/dist/a2a-server.d.ts +13 -16
  4. package/dist/a2a-server.d.ts.map +1 -0
  5. package/dist/a2a-server.js +1 -1
  6. package/dist/{chunk-5NKXV5XZ.js → chunk-STB4Z6F4.js} +25 -3
  7. package/dist/chunk-STB4Z6F4.js.map +1 -0
  8. package/dist/{client-C7TzTpNW.d.ts → client.d.ts} +83 -831
  9. package/dist/client.d.ts.map +1 -0
  10. package/dist/{computer-use-4QzI3lGU.d.ts → computer-use.d.ts} +21 -22
  11. package/dist/computer-use.d.ts.map +1 -0
  12. package/dist/errors.d.ts +153 -0
  13. package/dist/errors.d.ts.map +1 -0
  14. package/dist/index.cjs +25 -3
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.ts +44 -55
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +2 -2
  19. package/dist/index.js.map +1 -1
  20. package/dist/local-resolver.d.ts +49 -0
  21. package/dist/local-resolver.d.ts.map +1 -0
  22. package/dist/oauth.d.ts +189 -0
  23. package/dist/oauth.d.ts.map +1 -0
  24. package/dist/playwright.d.ts +6 -11
  25. package/dist/playwright.d.ts.map +1 -0
  26. package/dist/sse.d.ts +27 -0
  27. package/dist/sse.d.ts.map +1 -0
  28. package/dist/tools.d.ts +426 -0
  29. package/dist/tools.d.ts.map +1 -0
  30. package/dist/version.d.ts +5 -0
  31. package/dist/version.d.ts.map +1 -0
  32. package/dist/zod-to-json-schema.d.ts +25 -0
  33. package/dist/zod-to-json-schema.d.ts.map +1 -0
  34. package/package.json +11 -11
  35. package/dist/a2a-server.d.cts +0 -176
  36. package/dist/chunk-5NKXV5XZ.js.map +0 -1
  37. package/dist/client-C7TzTpNW.d.cts +0 -2033
  38. package/dist/computer-use-1m6E_VIl.d.cts +0 -193
  39. package/dist/index.d.cts +0 -61
  40. package/dist/playwright.d.cts +0 -88
@@ -1,193 +0,0 @@
1
- import { aC as RunResult, M as MantyxClient, R as ReasoningLevel, V as LocalTool } from './client-C7TzTpNW.cjs';
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 };
package/dist/index.d.cts DELETED
@@ -1,61 +0,0 @@
1
- export { A as A2AToolRef, a as AgentEvalOverrides, b as AgentSession, c as AgentSpecBase, d as AssistantDeltaEvent, e as AssistantMessageEvent, f as AttachmentMetadata, C as CancelledEvent, g as ConversationMessage, h as CreateEvalRunRequest, D as DEFAULT_BASE_URL, i as DEFAULT_OAUTH_BASE_URL, j as DEFAULT_REFRESH_SKEW_MS, k as DefineLocalA2AOptions, l as DefineLocalMcpOptions, m as DefineLocalToolOptions, E as ErrorEvent, n as EvalCase, o as EvalCaseResult, p as EvalDatasetDetail, q as EvalDatasetList, r as EvalDatasetSummary, s as EvalRunAccepted, t as EvalRunCompare, u as EvalRunCompareCase, v as EvalRunCompareSide, w as EvalRunDetail, x as EvalRunEvent, y as EvalRunList, z as EvalRunStatus, B as EvalRunSummary, I as InlineEvalCaseSpec, F as InlineEvalDatasetSpec, G as InputFileAttachment, H as InputFileAttachmentMetadata, J as InputFileUrlAttachment, K as InputFileUrlAttachmentMetadata, L as ListEvalRunsOptions, N as LocalA2ATool, P as LocalHandlers, Q as LocalMcpHttpTransport, S as LocalMcpServer, U as LocalMcpStdioTransport, V as LocalTool, W as LocalToolCallEvent, X as LocalToolOutput, Y as LocalToolResult, Z as LocalToolResultInEvent, _ as LoopDetectedEvent, $ as LoopDetection, a0 as MantyxA2AOptions, a1 as MantyxAuthError, M as MantyxClient, a2 as MantyxClientOptions, a3 as MantyxError, a4 as MantyxMcpOptions, a5 as MantyxNetworkError, a6 as MantyxOAuthClient, a7 as MantyxOAuthClientOptions, a8 as MantyxOAuthError, a9 as MantyxParseError, aa as MantyxPluginToolRef, ab as MantyxRunError, ac as MantyxRunErrorInit, ad as MantyxRunErrorModel, ae as MantyxRunErrorTokens, af as MantyxScopeError, ag as MantyxToolError, ah as MantyxToolRef, ai as McpToolRef, aj as MessageAttachment, ak as ModelCatalog, al as ModelInfo, am as OAuthToken, O as OutputSchema, an as OutputSchemaValue, ao as PlanOptions, ap as PlanSpec, R as ReasoningLevel, aq as ReasoningTrigger, ar as RefreshOptions, as as RefreshTokenSourceOptions, at as ResultEvent, au as RevokeOptions, av as RunEvalOptions, aw as RunEvent, ax as RunEventBase, ay as RunFeedbackInput, az as RunFeedbackResult, aA as RunFeedbackVerdict, aB as RunModelInfo, aC as RunResult, aD as RunSpec, aE as RunTokenUsage, aF as ServerToolResultEvent, aG as SessionInfo, aH as SessionListResult, aI as SessionSpec, aJ as SessionSummary, aK as Supervisor, aL as SupervisorAction, aM as SupervisorEvent, aN as SupervisorPhase, aO as TaskPlan, aP as TaskPlanEvent, aQ as TaskPlanStep, aR as TaskPlanStepStatus, aS as ThinkingDeltaEvent, aT as TokenRequestReason, aU as TokenSource, aV as ToolBudget, aW as ToolBudgetExceededEvent, aX as ToolBudgets, T as ToolRef, aY as ToolResultFile, aZ as UserMessageEvent, a_ as ZodLikeObject, a$ as defineLocalA2A, b0 as defineLocalMcp, b1 as defineLocalTool, b2 as inputFileAttachment, b3 as inputFileUrlAttachment, b4 as isLocalA2ATool, b5 as isLocalMcpServer, b6 as isLocalTool, b7 as mantyxA2A, b8 as mantyxMcp, b9 as mantyxPluginTool, ba as mantyxTool, bb as parseRunOutput, bc as planOnly } from './client-C7TzTpNW.cjs';
2
- export { B as BrowserController, C as COMPUTER_USE_ACTIONS, a as ComputerUseAction, b as ComputerUseActionCall, c as ComputerUseResult, d as ComputerUseStep, e as ComputerUseSystemPromptOptions, D as DefineComputerUseToolsOptions, R as RunComputerUseOptions, S as Screenshot, f as ScrollDirection, T as TypeTextOptions, V as Viewport, g as buildComputerUseSystemPrompt, h as defineComputerUseTools, i as denormalizeCoordinate, j as extractActions, r as runComputerUse } from './computer-use-1m6E_VIl.cjs';
3
- import { z } from 'zod';
4
-
5
- /**
6
- * Lightweight Zod → JSON Schema converter for tool parameter definitions.
7
- *
8
- * Resolution order:
9
- * 1. `schema.toJSONSchema()` on the instance (Zod v4; works across package
10
- * copies when the user's `zod` and the SDK's `zod` are different installs)
11
- * 2. `z.toJSONSchema(schema)` from the SDK's `zod` import (Zod v4, same copy)
12
- * 3. Hand-rolled walker for Zod v3 `typeName` and Zod v4 `_def.type`
13
- *
14
- * The output is a JSON-Schema-shaped object with `type: "object"`, `properties`,
15
- * and `required`. The MANTYX server feeds this to LLM providers verbatim, so
16
- * unsupported zod features (effects, transforms, intersections) degrade to a
17
- * permissive `"object"` description rather than failing.
18
- */
19
-
20
- type JsonSchema = Record<string, unknown>;
21
- declare function zodToJsonSchema(schema: z.ZodType<unknown>): JsonSchema;
22
- /**
23
- * Coerce a JSON-Schema-shaped value into a wire object suitable for the
24
- * MANTYX local-tool definition payload. Accepts either a Zod schema or an
25
- * already-shaped JSON Schema object.
26
- */
27
- declare function toToolParametersWire(parameters: z.ZodType<unknown> | JsonSchema | undefined): JsonSchema;
28
-
29
- /**
30
- * Minimal Server-Sent Events parser.
31
- *
32
- * Reads a `ReadableStream<Uint8Array>` (the body of a `fetch()` response) and
33
- * yields parsed events with `id`, `event` and `data` fields. We deliberately
34
- * keep this dependency-free instead of pulling in `eventsource` / `eventsource-parser`
35
- * so the SDK has the smallest possible install footprint.
36
- *
37
- * Reconnect/replay is handled at a higher layer using `Last-Event-ID` (the
38
- * default for browsers' `EventSource`) plus a `?lastSeq=` query param so curl
39
- * users and SSE-via-fetch consumers both work.
40
- */
41
- interface SseEvent {
42
- id?: string;
43
- event?: string;
44
- data: string;
45
- }
46
- interface SseStreamOptions {
47
- /** AbortSignal for cancellation. */
48
- signal?: AbortSignal;
49
- }
50
- /**
51
- * Async generator yielding parsed SSE events from a fetch response body.
52
- * Comment frames (`:keep-alive`) are dropped.
53
- */
54
- declare function readSseStream(body: ReadableStream<Uint8Array> | null, opts?: SseStreamOptions): AsyncGenerator<SseEvent, void, void>;
55
-
56
- /**
57
- * Release version — synced from repo root VERSION (`npm run sync-version`).
58
- */
59
- declare const SDK_VERSION = "0.22.0";
60
-
61
- export { SDK_VERSION, type SseEvent, type SseStreamOptions, readSseStream, toToolParametersWire, zodToJsonSchema };
@@ -1,88 +0,0 @@
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-1m6E_VIl.cjs';
3
- import './client-C7TzTpNW.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 };