@mantyx/sdk 0.22.0 → 0.23.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +10 -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-OUK6ZZ5H.js} +87 -14
  7. package/dist/chunk-OUK6ZZ5H.js.map +1 -0
  8. package/dist/{client-C7TzTpNW.d.ts → client.d.ts} +131 -840
  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 +88 -14
  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 +4 -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/docs/agent-runs-protocol.md +52 -16
  35. package/package.json +11 -11
  36. package/dist/a2a-server.d.cts +0 -176
  37. package/dist/chunk-5NKXV5XZ.js.map +0 -1
  38. package/dist/client-C7TzTpNW.d.cts +0 -2033
  39. package/dist/computer-use-1m6E_VIl.d.cts +0 -193
  40. package/dist/index.d.cts +0 -61
  41. package/dist/playwright.d.cts +0 -88
@@ -1,807 +1,60 @@
1
- import { z } from 'zod';
2
-
3
- /**
4
- * Error types raised by the MANTYX SDK.
5
- */
6
- declare class MantyxError extends Error {
7
- readonly code: string;
8
- readonly status: number | undefined;
9
- readonly hint: string | undefined;
10
- constructor(message: string, opts?: {
11
- code?: string;
12
- status?: number;
13
- hint?: string;
14
- });
15
- }
16
- declare class MantyxNetworkError extends MantyxError {
17
- constructor(message: string, opts?: {
18
- cause?: unknown;
19
- });
20
- }
21
- declare class MantyxAuthError extends MantyxError {
22
- constructor(message?: string);
23
- }
24
- /**
25
- * Raised on `403 insufficient_scope`, returned when an OAuth access token
26
- * is missing one of the scopes a route demands (see
27
- * `docs/agent-runs-protocol.md` §2.2 for the per-endpoint table).
28
- *
29
- * `requiredScopes` carries the verbatim `required` value from the
30
- * server's response — a single scope for most routes, an array when the
31
- * route demands more than one. The SDK is expected to surface this so
32
- * callers can drive a re-consent flow (e.g. "please re-authorise the
33
- * app with `sessions:write` enabled").
34
- *
35
- * Workspace API keys never trip this error — they carry no granular
36
- * scopes. It is OAuth-only.
37
- */
38
- declare class MantyxScopeError extends MantyxError {
39
- /**
40
- * Scope(s) the route demanded. Always at least one entry; usually
41
- * exactly one. New routes may demand more scopes in the future.
42
- */
43
- readonly requiredScopes: readonly string[];
44
- constructor(message: string, requiredScopes: readonly string[]);
45
- }
46
- declare class MantyxToolError extends MantyxError {
47
- readonly toolName: string;
48
- constructor(toolName: string, message: string);
49
- }
50
- /**
51
- * Per-run token totals attached to terminal `result` / `error`
52
- * events. See `docs/agent-runs-protocol.md` §7.1 for the per-provider
53
- * mapping and the relationship between buckets. Re-exported from
54
- * `client.ts` so error consumers can pattern-match the triple without
55
- * a second import.
56
- */
57
- interface MantyxRunErrorTokens {
58
- inputTokens: number;
59
- cachedTokens: number;
60
- reasoningTokens: number;
61
- outputTokens: number;
62
- }
63
- /**
64
- * Resolved model that executed the run. Surfaced on terminal events
65
- * by MANTYX ≥ 2026-09. See `docs/agent-runs-protocol.md` §7.1. The
66
- * `provider` empty / undefined is the "no usage data" sentinel.
67
- */
68
- interface MantyxRunErrorModel {
69
- id: string;
70
- provider: string;
71
- vendorModelId: string;
72
- reasoningEffort?: string;
73
- }
74
- /**
75
- * Optional triage attributes the runner attaches to terminal `error`
76
- * events. Mirrors the wire fields described in
77
- * `docs/agent-runs-protocol.md` §7 ("error event payload fields") so SDK
78
- * callers can render structured UI status notes ("model truncated — JSON
79
- * likely incomplete") and drive retry policy without re-parsing the
80
- * human-readable `message`.
81
- */
82
- interface MantyxRunErrorInit {
83
- /**
84
- * Canonical category of failure. One of `"rate_limit"`, `"overloaded"`,
85
- * `"server"`, `"context_window"`, `"truncation"`, `"invalid_request"`,
86
- * `"auth"`, `"timeout"`, `"local_timeout"`, `"upstream_deadline"`,
87
- * `"unknown"`. New categories may land additively — callers should
88
- * default-branch to `"unknown"` for unrecognized values.
89
- */
90
- errorClass?: string;
91
- /**
92
- * Canonical lowercase stop reason normalized across providers
93
- * (`"max_tokens"`, `"refusal"`, `"malformed_function_call"`, …). When
94
- * present, mirrors the value carried on the last `assistant_message`
95
- * event preceding the failure.
96
- */
97
- finishReason?: string | null;
98
- /**
99
- * **Best-effort raw bytes** the model emitted before the failure. For
100
- * `outputSchema` runs this is likely **incomplete JSON** that will
101
- * fail `JSON.parse` — treat it as diagnostic data, never as a
102
- * schema-conformant reply.
103
- */
104
- partialText?: string;
105
- /**
106
- * Coarse retry hint inherited from the pipeline's error classifier.
107
- * Informational; the SDK still owns the actual retry decision.
108
- */
109
- retryable?: boolean;
110
- /**
111
- * Per-run token totals from the terminal event. Present against
112
- * MANTYX ≥ 2026-09 — see {@link MantyxRunErrorTokens} and
113
- * `docs/agent-runs-protocol.md` §7.1. Includes the failing model
114
- * call's usage when the run errored mid-loop.
115
- */
116
- tokens?: MantyxRunErrorTokens;
117
- /** Total model invocations for the run, including the failing call. */
118
- turns?: number;
119
- /** Resolved model that executed the run. See {@link MantyxRunErrorModel}. */
120
- model?: MantyxRunErrorModel;
121
- }
122
- declare class MantyxRunError extends MantyxError {
123
- readonly runId: string;
124
- readonly subtype: string;
125
- /** See {@link MantyxRunErrorInit.errorClass}. */
126
- readonly errorClass: string | undefined;
127
- /** See {@link MantyxRunErrorInit.finishReason}. */
128
- readonly finishReason: string | null | undefined;
129
- /** See {@link MantyxRunErrorInit.partialText}. */
130
- readonly partialText: string | undefined;
131
- /** See {@link MantyxRunErrorInit.retryable}. */
132
- readonly retryable: boolean | undefined;
133
- /** See {@link MantyxRunErrorInit.tokens}. */
134
- readonly tokens: MantyxRunErrorTokens | undefined;
135
- /** See {@link MantyxRunErrorInit.turns}. */
136
- readonly turns: number | undefined;
137
- /** See {@link MantyxRunErrorInit.model}. */
138
- readonly model: MantyxRunErrorModel | undefined;
139
- constructor(runId: string, subtype: string, message: string, init?: MantyxRunErrorInit);
140
- }
141
- /**
142
- * Thrown by {@link parseRunOutput} when the run's terminal text was supposed
143
- * to be a JSON document (because `outputSchema` was set on the spec) but
144
- * either failed to JSON.parse or failed the user-supplied validator.
145
- *
146
- * The original `text` is preserved on the `text` field so callers can log
147
- * the raw model output for debugging.
148
- */
149
- declare class MantyxParseError extends MantyxError {
150
- readonly text: string;
151
- constructor(message: string, text: string, opts?: {
152
- cause?: unknown;
153
- });
154
- }
155
-
156
- /**
157
- * MANTYX OAuth 2.0 refresh client: trade a stored refresh token for
158
- * short-lived access tokens, revoke tokens at sign-out, and expose
159
- * a {@link TokenSource} the {@link MantyxClient} HTTP layer calls
160
- * before every request (and again on 401).
161
- *
162
- * The library is intentionally **refresh-only**. It assumes the caller
163
- * already obtained the refresh token through their own sign-in flow
164
- * (Authorization Code + PKCE in a browser, native redirect, server-
165
- * side exchange — whatever fits the host application). The SDK does
166
- * not drive consent, does not initiate auth-code exchanges, and does
167
- * not bundle PKCE helpers.
168
- *
169
- * Wire contract (`docs/oauth.md`):
170
- *
171
- * - Token endpoint: `POST <baseUrl>/api/oauth/token`, form-encoded,
172
- * `grant_type=refresh_token`. Echoes back the same `refresh_token`
173
- * the client sent (refresh tokens are persistent and non-rotating).
174
- * - Revoke endpoint: `POST <baseUrl>/api/oauth/revoke`, form-encoded.
175
- * - Access tokens (`mantyx_at_…`) live 1 hour (`expires_in: 3600`).
176
- * - Refresh tokens (`mantyx_rt_…`) are long-lived; the caller persists
177
- * them once at first sign-in (encrypted at rest) and the SDK re-mints
178
- * access tokens from the same value on demand.
179
- */
180
-
181
- declare const DEFAULT_OAUTH_BASE_URL = "https://app.mantyx.io";
182
- /** Skew (ms) before `expiresAt` at which a TokenSource will pre-emptively refresh. Default 60s. */
183
- declare const DEFAULT_REFRESH_SKEW_MS = 60000;
184
- /**
185
- * Raised on a non-2xx response from `POST /api/oauth/token` or
186
- * `POST /api/oauth/revoke`. Carries the RFC 6749 `error` discriminator
187
- * (`"invalid_grant"`, `"invalid_client"`, `"unsupported_grant_type"`,
188
- * …) and the optional `error_description` so callers can branch on
189
- * machine-readable values without parsing the human message.
190
- *
191
- * `invalid_grant` from the refresh path specifically signals that the
192
- * refresh token has been revoked (or the OAuth grant / application
193
- * was deleted). The SDK never loops on this — callers should route
194
- * the user back to a fresh sign-in.
195
- */
196
- declare class MantyxOAuthError extends MantyxError {
197
- readonly oauthError: string;
198
- readonly oauthErrorDescription: string | undefined;
199
- constructor(oauthError: string, oauthErrorDescription: string | undefined, status: number);
200
- }
201
- /**
202
- * Decoded `POST /api/oauth/token` response, augmented with an absolute
203
- * `expiresAt` timestamp the SDK uses to decide when to refresh.
204
- *
205
- * On the refresh grant the response's `refreshToken` is identical to
206
- * the value the client just sent (refresh tokens never rotate). The
207
- * field is surfaced for symmetry with whatever the calling app's
208
- * sign-in flow already does.
209
- */
210
- interface OAuthToken {
211
- readonly accessToken: string;
212
- readonly refreshToken: string | undefined;
213
- readonly tokenType: string;
214
- readonly expiresIn: number;
215
- /** Absolute Unix-ms timestamp set when the SDK parsed the response. */
216
- readonly expiresAt: number;
217
- readonly scope: string | undefined;
218
- }
219
- /** Why the SDK asked the {@link TokenSource} for the current access token. */
220
- type TokenRequestReason = "initial" | "expired" | "unauthorized";
221
- /**
222
- * A `TokenSource` produces the current access token on demand. The
223
- * {@link MantyxClient} HTTP layer calls it before every request. When
224
- * called with `reason: "unauthorized"` the source MUST force a refresh
225
- * (do not return a cached value); this is how the SDK recovers from
226
- * 401s caused by a token that the server already invalidated.
227
- *
228
- * Implementations should be safe to call from many concurrent requests.
229
- */
230
- type TokenSource = (reason?: TokenRequestReason) => Promise<string>;
231
- /** Caller-supplied options for `MantyxOAuthClient`. */
232
- interface MantyxOAuthClientOptions {
233
- /**
234
- * OAuth `client_id` issued at app registration (token prefix
235
- * `mantyx_oa_`).
236
- */
237
- clientId: string;
238
- /**
239
- * OAuth `client_secret` issued at app registration (token prefix
240
- * `mantyx_oas_`). Every MANTYX OAuth app is a confidential client,
241
- * so this is always required for token + revoke calls. Treat as a
242
- * deployment secret — do not bundle into browser builds.
243
- */
244
- clientSecret: string;
245
- /**
246
- * Origin of the MANTYX deployment. Defaults to `https://app.mantyx.io`.
247
- * The OAuth endpoints are mounted at `<baseUrl>/api/oauth/...`.
248
- */
249
- baseUrl?: string;
250
- /** Optional `fetch` override (e.g. node-fetch wrapper). Default: global `fetch`. */
251
- fetch?: typeof fetch;
252
- /** Default per-request timeout in milliseconds. Default: 30s. */
253
- timeoutMs?: number;
254
- }
255
- interface RefreshOptions {
256
- refreshToken: string;
257
- /**
258
- * Optional scope narrowing. Must be a subset of the scopes already
259
- * granted to the refresh token (server enforces this). Useful when
260
- * an SDK consumer wants a short-scope access token for a specific
261
- * sub-operation.
262
- */
263
- scope?: string | readonly string[];
264
- }
265
- interface RevokeOptions {
266
- token: string;
267
- }
268
- interface RefreshTokenSourceOptions {
269
- refreshToken: string;
270
- /** Optional scope narrowing applied on every refresh. */
271
- scope?: string | readonly string[];
272
- /**
273
- * How many ms before `expiresAt` the source proactively refreshes.
274
- * Defaults to {@link DEFAULT_REFRESH_SKEW_MS} (60s).
275
- */
276
- refreshSkewMs?: number;
277
- /**
278
- * Optional initial access token + expiry to seed the source's cache
279
- * with (e.g. the token already in hand from the host application's
280
- * sign-in flow). When omitted, the source mints one on the first
281
- * call.
282
- */
283
- initialToken?: OAuthToken;
284
- }
285
- /**
286
- * Refresh-only wrapper around the MANTYX OAuth 2.0 authorization-server
287
- * endpoints. App-scoped (one per `{clientId, clientSecret}` pair);
288
- * construct independently of {@link MantyxClient}, then either call
289
- * {@link refresh} / {@link revoke} directly or hand a `TokenSource`
290
- * produced by {@link refreshTokenSource} to `MantyxClient` for fully
291
- * transparent refresh on every request.
292
- *
293
- * The client deliberately does **not** drive the authorization-code
294
- * exchange or any other "initiate sign-in" grant. The caller is
295
- * expected to obtain the refresh token through their own consent flow
296
- * and persist it before constructing this client.
297
- */
298
- declare class MantyxOAuthClient {
299
- readonly clientId: string;
300
- readonly baseUrl: string;
301
- private readonly clientSecret;
302
- private readonly fetchImpl;
303
- private readonly timeoutMs;
304
- constructor(opts: MantyxOAuthClientOptions);
305
- /**
306
- * Mint a fresh access token from a stored refresh token. The
307
- * returned `refreshToken` is identical to the input — refresh
308
- * tokens are persistent and non-rotating, so the field is
309
- * surfaced only for symmetry with the response shape.
310
- *
311
- * On `400 invalid_grant` the refresh token has been revoked (or its
312
- * grant / app was deleted); the SDK surfaces a
313
- * {@link MantyxOAuthError} and callers must drive a fresh sign-in.
314
- */
315
- refresh(opts: RefreshOptions): Promise<OAuthToken>;
316
- /**
317
- * Revoke an access or refresh token (RFC 7009). The server always
318
- * returns 200, even for unknown tokens. Revoking a **refresh**
319
- * token kills the refresh and every live access token tied to its
320
- * grant; revoking an **access** token kills only that one.
321
- */
322
- revoke(opts: RevokeOptions): Promise<void>;
323
- /**
324
- * Build a long-lived {@link TokenSource} that re-mints access
325
- * tokens from the supplied refresh token. Pass the returned source
326
- * to `new MantyxClient({ tokenSource, workspaceSlug, ... })`. The
327
- * source caches the access token in-memory and refreshes
328
- * proactively when the cached value is within `refreshSkewMs` of
329
- * `expiresAt`, or eagerly when `MantyxClient` reports a 401.
330
- *
331
- * Pass `initialToken` if the calling app already has a non-expired
332
- * access token in hand (e.g. straight out of the sign-in flow) to
333
- * avoid an extra round-trip on the first request.
334
- */
335
- refreshTokenSource(opts: RefreshTokenSourceOptions): TokenSource;
336
- /**
337
- * POST `application/x-www-form-urlencoded` to `/api/oauth/token` and
338
- * decode the {@link OAuthToken} response. Always injects `client_id`
339
- * + `client_secret` from the constructor.
340
- */
341
- private token;
342
- private formPost;
343
- }
344
-
345
- /**
346
- * Public tool helpers for the MANTYX SDK.
347
- *
348
- * Server-resolved (executed by MANTYX):
349
- * mantyxTool(id) → existing workspace `Tool` row by id
350
- * mantyxPluginTool(name) → built-in plugin tool by `@plugin/tool` name
351
- * mantyxA2A({...}) → remote Agent2Agent peer, dialed by MANTYX
352
- * mantyxMcp({...}) → remote MCP server (Streamable HTTP), proxied by MANTYX
353
- *
354
- * Client-resolved (executed in this process; the SDK shuttles inputs and
355
- * outputs over the agent loop):
356
- * defineLocalTool({...}) → generic local tool with a Zod parameter schema
357
- * defineLocalA2A({...}) → A2A peer the SDK can reach but MANTYX cannot —
358
- * pass an `agentCardUrl`; the SDK fetches the
359
- * Agent Card and speaks A2A `message/send` for you.
360
- * defineLocalMcp({...}) → MCP server the SDK manages — pass either a
361
- * Streamable HTTP `url` or a stdio
362
- * `command`; the SDK runs `Initialize` +
363
- * `tools/list` and forwards `tools/call` for you.
364
- *
365
- * The server emits a `local_tool_call` event for every client-resolved
366
- * invocation. The event carries a `kind` discriminator (`"local"` is implied
367
- * when omitted, `"a2a_local"` and `"mcp_local"` are explicit) so the SDK can
368
- * dispatch to the right handler.
369
- */
370
-
371
- type ZodLikeObject = z.ZodType<Record<string, unknown>> & {
372
- _def?: unknown;
373
- parse?: (value: unknown) => unknown;
374
- };
375
- /**
376
- * Provider-thinking knob, mapped server-side onto each LLM's native dial:
377
- * `reasoning.effort` (OpenAI), `thinkingConfig.thinkingLevel` / `thinkingBudget`
378
- * (Gemini), or extended-thinking budget (Anthropic / Bedrock-Anthropic).
379
- *
380
- * Pass either a string anchor (`"off" | "low" | "medium" | "high"`) or an
381
- * integer in `0..100` (where `0` explicitly disables provider thinking).
382
- */
383
- type ReasoningLevel = "off" | "low" | "medium" | "high" | number;
384
- /**
385
- * A file produced by a client-resolved tool, returned alongside the textual
386
- * `result`. The bytes are surfaced to the model on the next turn as native
387
- * file parts (Anthropic / Gemini / Bedrock inside the `tool_result`; OpenAI
388
- * as a synthetic follow-up user turn) — the same pipeline used by
389
- * server-resolved tools that return files.
390
- *
391
- * Limits (enforced server-side): up to 20 files per result, `mimeType` must
392
- * be an allowed attachment type, and the combined decoded size is capped
393
- * (currently 5 MB). Files over the inline threshold are persisted to object
394
- * storage and forwarded by reference. For larger artifacts, upload them out
395
- * of band and reference a URL in `result` instead. See
396
- * `docs/agent-runs-protocol.md` §8 and `docs/wire-protocol.md` §4.
397
- */
398
- interface ToolResultFile {
399
- /** Display filename surfaced to the model (e.g. `"chart.png"`). */
400
- filename: string;
401
- /** Allowed attachment MIME type (e.g. `"image/png"`, `"text/plain"`). */
402
- mimeType: string;
403
- /** Base64-encoded file bytes — **no** `data:` URL prefix. */
404
- data: string;
405
- }
406
- /**
407
- * Rich return value for a {@link LocalTool}'s `execute`. Return this (instead
408
- * of a bare string) when the tool needs to hand files back to the model in
409
- * addition to — or instead of — its textual result.
410
- *
411
- * `result` is the same string a tool would normally return; omit it (or pass
412
- * the empty string) when the files are the whole payload. `files` is ignored
413
- * when the tool throws — errors are surfaced to the model as a tool-error
414
- * response with no attachments.
415
- */
416
- interface LocalToolResult {
417
- /** Textual result. Optional when `files` carries the payload. */
418
- result?: string;
419
- /** Files to surface to the model on the next turn. */
420
- files?: ToolResultFile[];
421
- }
422
- /**
423
- * What a {@link LocalTool}'s `execute` may return: a bare string (the common
424
- * case) or a {@link LocalToolResult} carrying files. Non-string, non-result
425
- * values are JSON-serialized by the SDK before being posted back.
426
- */
427
- type LocalToolOutput = string | LocalToolResult;
428
- /**
429
- * Either a Zod schema (auto-converted to JSON Schema by the SDK) or a
430
- * pre-shaped JSON Schema object. Used for both `parameters` and the new
431
- * `outputSchema` field — same conversion path either way.
432
- */
433
- type LocalToolSchemaInput = ZodLikeObject | Record<string, unknown>;
434
- interface LocalTool<TArgs = Record<string, unknown>> {
435
- readonly kind: "local";
436
- readonly name: string;
437
- readonly description: string;
438
- readonly parameters: ZodLikeObject | undefined;
439
- /**
440
- * Optional JSON Schema (or Zod schema, auto-converted) describing the
441
- * tool's structured return value. Forwarded to providers with per-tool
442
- * response schemas (Gemini's `responseJsonSchema` on the
443
- * FunctionDeclaration); other engines surface it through the description
444
- * and rely on host-side validation. The model uses it to plan follow-up
445
- * arguments more reliably. See `docs/wire-protocol.md` §3.1.
446
- */
447
- readonly outputSchema: LocalToolSchemaInput | undefined;
448
- /**
449
- * When `true`, MANTYX appends a stable hint to the model-facing
450
- * description telling the model not to re-issue calls while a previous
451
- * invocation is still pending. Useful for tools that may yield a
452
- * `pending` / status response and the SDK polls on its own; without the
453
- * hint, models routinely fire repeat calls and waste turns. Pure
454
- * declarative — MANTYX does not change scheduling.
455
- */
456
- readonly longRunning: boolean;
457
- /**
458
- * When `true`, this tool may run **in parallel** with other read-only
459
- * tools the model emits in the same turn: MANTYX publishes every such
460
- * `local_tool_call` concurrently and resolves them together instead of
461
- * one-at-a-time in model-emit order. Set this only for side-effect-free
462
- * tools whose results don't depend on each other. Mutating tools (the
463
- * default, `false`) stay strictly sequential. See
464
- * `docs/agent-runs-protocol.md` §4.1.1.
465
- */
466
- readonly readOnly: boolean;
467
- /**
468
- * When `true`, the tool's result is **persisted with the session and
469
- * replayed to the model on later turns** — reconstructed as a
470
- * `tool_use` + `tool_result` pair in its original place in the
471
- * transcript. Only meaningful for session-scoped runs. Keep outputs
472
- * small (text only, ~8 KB cap). See `docs/agent-runs-protocol.md`
473
- * §4.1.1.
474
- */
475
- readonly retain: boolean;
476
- readonly execute: (args: TArgs) => Promise<LocalToolOutput> | LocalToolOutput;
477
- }
478
- interface DefineLocalToolOptions<T extends ZodLikeObject | undefined> {
479
- /** Lowercase alphanumeric + underscore, max 64 chars. */
480
- name: string;
481
- description?: string;
482
- parameters?: T;
483
- /**
484
- * Optional JSON Schema (or Zod schema) describing the tool's return
485
- * value. See {@link LocalTool.outputSchema}.
486
- */
487
- outputSchema?: LocalToolSchemaInput;
488
- /**
489
- * Annotate the tool as long-running so the model doesn't double-call
490
- * while a previous invocation is still pending. See
491
- * {@link LocalTool.longRunning}.
492
- */
493
- longRunning?: boolean;
494
- /**
495
- * Mark the tool as read-only so MANTYX may run it in parallel with other
496
- * read-only tools the model emits in the same turn. See
497
- * {@link LocalTool.readOnly}.
498
- */
499
- readOnly?: boolean;
500
- /**
501
- * Persist the tool result across session turns so follow-ups can
502
- * reference values the model can no longer recompute. See
503
- * {@link LocalTool.retain}.
504
- */
505
- retain?: boolean;
506
- execute: (args: T extends ZodLikeObject ? z.infer<T> : Record<string, unknown>) => Promise<LocalToolOutput> | LocalToolOutput;
507
- }
508
- declare function defineLocalTool<T extends ZodLikeObject | undefined>(opts: DefineLocalToolOptions<T>): LocalTool;
509
- interface MantyxToolRef {
510
- readonly kind: "mantyx";
511
- readonly id: string;
512
- }
513
- interface MantyxPluginToolRef {
514
- readonly kind: "mantyx_plugin";
515
- readonly name: string;
516
- }
517
- declare function mantyxTool(id: string): MantyxToolRef;
518
- declare function mantyxPluginTool(name: string): MantyxPluginToolRef;
519
- /**
520
- * Reference to a remote Agent2Agent peer reachable from MANTYX (server-resolved).
521
- * MANTYX dials `agentCardUrl` over A2A's `message/send` RPC and forwards the
522
- * remote agent's reply as the tool result.
523
- */
524
- interface A2AToolRef {
525
- readonly kind: "a2a";
526
- readonly name: string;
527
- readonly description?: string;
528
- readonly agentCardUrl: string;
529
- readonly headers?: Record<string, string>;
530
- readonly contextId?: string;
531
- }
532
- interface MantyxA2AOptions {
533
- /** Tool name surfaced to the model; must match `^[a-zA-Z0-9_]{1,64}$`. */
534
- name: string;
535
- description?: string;
536
- /** Remote Agent Card URL (`/.well-known/agent-card.json`) or JSON-RPC root. */
537
- agentCardUrl: string;
538
- /** Per-request HTTP headers (typically `Authorization`). */
539
- headers?: Record<string, string>;
540
- /** Optional A2A `contextId` to thread multiple delegations. */
541
- contextId?: string;
542
- }
543
- declare function mantyxA2A(opts: MantyxA2AOptions): A2AToolRef;
544
- /**
545
- * Local A2A peer — the SDK fetches the Agent Card from `agentCardUrl` on
546
- * the first run, ships the resolved card with the spec, and speaks A2A
547
- * `message/send` to `agentCard.url` whenever MANTYX emits a
548
- * `local_tool_call` for this tool. You only supply the URL.
549
- *
550
- * The model addresses this tool by `name` and always passes
551
- * `{ message: string }` as arguments.
552
- *
553
- * Resolution is lazy: the card is fetched on the first `runAgent` /
554
- * `streamAgent` / `createSession` (or `session.send`) call and cached on
555
- * the tool ref for the rest of the process lifetime. Re-construct the ref
556
- * to force a refetch.
557
- */
558
- interface LocalA2ATool {
559
- readonly kind: "a2a_local";
560
- readonly name: string;
561
- /** Where the SDK fetches the Agent Card from. Cached after the first hit. */
562
- readonly agentCardUrl: string;
563
- /**
564
- * Headers used for **both** the card fetch and every `message/send` POST
565
- * (typically `Authorization` for intranet peers).
566
- */
567
- readonly headers: Record<string, string> | undefined;
568
- /**
569
- * Internal cache of the resolved Agent Card. Populated lazily by the
570
- * client on the first run; not part of the user contract.
571
- * @internal
572
- */
573
- _resolvedCard?: ResolvedAgentCard;
574
- }
575
- /** Internal: the snapshot of a resolved A2A Agent Card. */
576
- interface ResolvedAgentCard {
577
- /** Required by the A2A spec; used for the synthesized tool description. */
578
- readonly name: string;
579
- /** Peer's A2A endpoint — where the SDK POSTs `message/send`. */
580
- readonly url?: string;
581
- /** Anything else the peer publishes; forwarded verbatim onto the wire. */
582
- readonly [k: string]: unknown;
583
- }
584
- interface DefineLocalA2AOptions {
585
- /** Tool name surfaced to the model. Must match `^[a-zA-Z0-9_]{1,64}$`. */
586
- name: string;
587
- /**
588
- * URL of the peer's Agent Card (`/.well-known/agent-card.json` is the
589
- * conventional path). The SDK fetches this on the first run, parses it,
590
- * and ships the resolved card with the spec. The resolved card's `url`
591
- * field is then used as the `message/send` target.
592
- */
593
- agentCardUrl: string;
594
- /**
595
- * Headers attached to **both** the card fetch and every `message/send`
596
- * POST (typically `Authorization` for intranet peers).
597
- */
598
- headers?: Record<string, string>;
599
- }
600
- declare function defineLocalA2A(opts: DefineLocalA2AOptions): LocalA2ATool;
601
- /**
602
- * Reference to a remote MCP server (Streamable HTTP) discovered + proxied by
603
- * MANTYX. Each tool in the catalog is exposed to the model as `<name>_<tool>`.
604
- */
605
- interface McpToolRef {
606
- readonly kind: "mcp";
607
- readonly name: string;
608
- readonly url: string;
609
- readonly headers?: Record<string, string>;
610
- readonly toolFilter?: string[];
611
- }
612
- interface MantyxMcpOptions {
613
- /** Server label; used to prefix every discovered tool. */
614
- name: string;
615
- /** Streamable HTTP MCP endpoint. */
616
- url: string;
617
- headers?: Record<string, string>;
618
- /** Optional allowlist of MCP tool names. */
619
- toolFilter?: string[];
620
- }
621
- declare function mantyxMcp(opts: MantyxMcpOptions): McpToolRef;
622
- /**
623
- * Streamable HTTP transport spec for {@link defineLocalMcp}.
624
- */
625
- interface LocalMcpHttpTransport {
626
- /** Streamable HTTP MCP endpoint (e.g. `http://localhost:8080/mcp`). */
627
- url: string;
628
- /** HTTP headers sent on every MCP request (typically `Authorization`). */
629
- headers?: Record<string, string>;
630
- }
631
- /**
632
- * stdio transport spec for {@link defineLocalMcp}. The SDK spawns the
633
- * specified executable with the given arguments and speaks JSON-RPC over
634
- * its stdin/stdout streams.
635
- */
636
- interface LocalMcpStdioTransport {
637
- /** Executable to launch (e.g. `mcp-server-filesystem`, `node`, `uvx`). */
638
- command: string;
639
- /** Arguments passed verbatim. */
640
- args?: string[];
641
- /** Environment variables for the child process. Inherited if undefined. */
642
- env?: Record<string, string>;
643
- /** Working directory for the child process. */
644
- cwd?: string;
645
- }
646
- /**
647
- * Local MCP server — the SDK manages the entire MCP lifecycle for you.
648
- *
649
- * Pass either a Streamable HTTP `url` or an stdio `command` (mutually
650
- * exclusive). On the first run, the SDK opens the transport, runs MCP's
651
- * `Initialize` (capturing the `Implementation` block) and `tools/list`
652
- * (capturing the catalog), and ships both inline as part of the spec. On
653
- * every `local_tool_call` with `kind: "mcp_local"` the SDK forwards the
654
- * call to MCP `tools/call` on the cached connection and POSTs the
655
- * flattened text response back to MANTYX.
656
- *
657
- * Connections are reused across runs and across messages within a session
658
- * and closed on `runAgent` completion / `session.end()`.
659
- */
660
- interface LocalMcpServer {
661
- readonly kind: "mcp_local";
662
- readonly name: string;
663
- /** One-of with {@link stdio} — the transport spec is mutually exclusive. */
664
- readonly http: LocalMcpHttpTransport | undefined;
665
- /** One-of with {@link http} — the transport spec is mutually exclusive. */
666
- readonly stdio: LocalMcpStdioTransport | undefined;
667
- /**
668
- * Internal cache of the resolved MCP client + catalog. Populated lazily
669
- * by the run driver on the first run; not part of the user contract.
670
- * @internal
671
- */
672
- _resolved?: ResolvedMcpServer;
673
- }
674
- /**
675
- * Internal: the live MCP client + the snapshot the SDK ships on the wire.
676
- */
677
- interface ResolvedMcpServer {
678
- /** The MCP `Implementation` block from `Initialize`. */
679
- readonly serverInfo: {
680
- name: string;
681
- version?: string;
682
- [k: string]: unknown;
683
- };
684
- /** Verbatim `tools/list` output. */
685
- readonly tools: ReadonlyArray<{
686
- readonly name: string;
687
- readonly description?: string;
688
- readonly inputSchema: Record<string, unknown>;
689
- readonly annotations?: Record<string, unknown>;
690
- readonly [k: string]: unknown;
691
- }>;
692
- /**
693
- * The live MCP client. Used by the run driver to call `tools/call`. The
694
- * concrete type depends on the transport — kept loose so this header
695
- * file doesn't have to import the MCP SDK type.
696
- */
697
- readonly client: McpClientLike;
698
- /** Closes the MCP transport (idempotent). */
699
- readonly close: () => Promise<void>;
700
- }
701
- /** Minimal interface this SDK uses against an MCP client. */
702
- interface McpClientLike {
703
- callTool(params: {
704
- name: string;
705
- arguments?: Record<string, unknown>;
706
- }): Promise<{
707
- content?: Array<{
708
- type: string;
709
- text?: string;
710
- [k: string]: unknown;
711
- }>;
712
- isError?: boolean;
713
- [k: string]: unknown;
714
- }>;
715
- }
716
- interface DefineLocalMcpOptions {
717
- /**
718
- * Server label echoed back as `mcpServer` on every `local_tool_call`. The
719
- * SDK auto-prefixes each discovered tool's wire-level `name` with
720
- * `<this>_` so the model sees a non-colliding `<server>_<tool>` surface
721
- * — mirroring how MANTYX prefixes for `kind: "mcp"`.
722
- */
723
- name: string;
724
- /**
725
- * Streamable HTTP transport. Mutually exclusive with {@link command}.
726
- */
727
- url?: string;
728
- /**
729
- * Headers attached to every MCP request when using the HTTP transport.
730
- */
731
- headers?: Record<string, string>;
732
- /**
733
- * stdio transport: executable to launch. Mutually exclusive with
734
- * {@link url}.
735
- */
736
- command?: string;
737
- /** Arguments for the stdio child process. */
738
- args?: string[];
739
- /** Environment variables for the stdio child process. */
740
- env?: Record<string, string>;
741
- /** Working directory for the stdio child process. */
742
- cwd?: string;
743
- }
744
- declare function defineLocalMcp(opts: DefineLocalMcpOptions): LocalMcpServer;
745
- type ToolRef = MantyxToolRef | MantyxPluginToolRef | LocalTool | A2AToolRef | LocalA2ATool | McpToolRef | LocalMcpServer;
746
- declare function isLocalTool(t: ToolRef): t is LocalTool;
747
- declare function isLocalA2ATool(t: ToolRef): t is LocalA2ATool;
748
- declare function isLocalMcpServer(t: ToolRef): t is LocalMcpServer;
749
-
750
- declare const DEFAULT_BASE_URL = "https://app.mantyx.io";
1
+ import type { TokenSource } from "./oauth.js";
2
+ import type { LocalA2ATool, LocalMcpServer, LocalTool, LocalToolSchemaInput, ReasoningLevel, ToolRef, ToolResultFile } from "./tools.js";
3
+ export declare const DEFAULT_BASE_URL = "https://app.mantyx.io";
751
4
  /** Inline file bytes for a user message (base64, no data-URL prefix). */
752
- interface InputFileAttachment {
5
+ export interface InputFileAttachment {
753
6
  type: "input_file";
754
7
  mimeType: string;
755
8
  filename: string;
756
9
  data: string;
757
10
  }
758
11
  /** HTTPS URL the provider fetches as a user-message file input. */
759
- interface InputFileUrlAttachment {
12
+ export interface InputFileUrlAttachment {
760
13
  type: "input_file_url";
761
14
  url: string;
762
15
  mimeType?: string;
763
16
  filename?: string;
764
17
  }
765
18
  /** File input attached to a user message on `POST /agent-runs` or session turns. */
766
- type MessageAttachment = InputFileAttachment | InputFileUrlAttachment;
19
+ export type MessageAttachment = InputFileAttachment | InputFileUrlAttachment;
767
20
  /** Metadata for an inline file on replay-only `user_message` frames (no bytes). */
768
- interface InputFileAttachmentMetadata {
21
+ export interface InputFileAttachmentMetadata {
769
22
  type: "input_file";
770
23
  mimeType: string;
771
24
  filename: string;
772
25
  size: number;
773
26
  }
774
27
  /** Metadata for a URL file on replay-only `user_message` frames. */
775
- interface InputFileUrlAttachmentMetadata {
28
+ export interface InputFileUrlAttachmentMetadata {
776
29
  type: "input_file_url";
777
30
  url: string;
778
31
  mimeType?: string;
779
32
  filename?: string;
780
33
  }
781
34
  /** Attachment metadata on session-event `user_message` replay frames. */
782
- type AttachmentMetadata = InputFileAttachmentMetadata | InputFileUrlAttachmentMetadata;
35
+ export type AttachmentMetadata = InputFileAttachmentMetadata | InputFileUrlAttachmentMetadata;
783
36
  /** One entry in a multi-role `messages` array. */
784
- interface ConversationMessage {
37
+ export interface ConversationMessage {
785
38
  role: "user" | "assistant" | "system";
786
39
  content: string;
787
40
  attachments?: MessageAttachment[];
788
41
  }
789
42
  /** Build an inline file attachment for the last user message in a run. */
790
- declare function inputFileAttachment(opts: {
43
+ export declare function inputFileAttachment(opts: {
791
44
  mimeType: string;
792
45
  filename: string;
793
46
  data: string;
794
47
  }): InputFileAttachment;
795
48
  /** Build a URL file attachment for the last user message in a run. */
796
- declare function inputFileUrlAttachment(opts: {
49
+ export declare function inputFileUrlAttachment(opts: {
797
50
  url: string;
798
51
  mimeType?: string;
799
52
  filename?: string;
800
53
  }): InputFileUrlAttachment;
801
54
  /** Thumbs up/down verdict for {@link MantyxClient.submitRunFeedback}. */
802
- type RunFeedbackVerdict = "UP" | "DOWN";
55
+ export type RunFeedbackVerdict = "UP" | "DOWN";
803
56
  /** Body for `POST /agent-runs/:runId/feedback`. See §9a. */
804
- interface RunFeedbackInput {
57
+ export interface RunFeedbackInput {
805
58
  verdict: RunFeedbackVerdict;
806
59
  /** Optional free-text note (≤ 8000 characters). */
807
60
  explanation?: string;
@@ -809,16 +62,16 @@ interface RunFeedbackInput {
809
62
  contentSnapshot?: string;
810
63
  }
811
64
  /** Response from `POST /agent-runs/:runId/feedback`. */
812
- interface RunFeedbackResult {
65
+ export interface RunFeedbackResult {
813
66
  id: string;
814
67
  verdict: RunFeedbackVerdict;
815
68
  targetKind: string;
816
69
  agentRunId: string;
817
70
  }
818
71
  /** Terminal statuses for {@link EvalRunDetail} and {@link EvalRunSummary}. */
819
- type EvalRunStatus = "queued" | "running" | "succeeded" | "failed" | "cancelled";
72
+ export type EvalRunStatus = "queued" | "running" | "succeeded" | "failed" | "cancelled";
820
73
  /** One case in an inline eval dataset (`POST /eval-runs` `dataset`). */
821
- interface InlineEvalCaseSpec {
74
+ export interface InlineEvalCaseSpec {
822
75
  name?: string;
823
76
  input: {
824
77
  role?: "user";
@@ -830,13 +83,13 @@ interface InlineEvalCaseSpec {
830
83
  tags?: string[];
831
84
  }
832
85
  /** Inline eval dataset blob (`POST /eval-runs` `dataset`). */
833
- interface InlineEvalDatasetSpec {
86
+ export interface InlineEvalDatasetSpec {
834
87
  name?: string;
835
88
  toolMocks?: Record<string, unknown>;
836
89
  cases: InlineEvalCaseSpec[];
837
90
  }
838
91
  /** Saved-agent overrides on `POST /eval-runs` (ignored for inline `agent`). */
839
- interface AgentEvalOverrides {
92
+ export interface AgentEvalOverrides {
840
93
  systemPrompt?: string;
841
94
  systemPromptAppend?: string;
842
95
  model?: string;
@@ -847,7 +100,7 @@ interface AgentEvalOverrides {
847
100
  disabledMocks?: string[];
848
101
  }
849
102
  /** Body for `POST /eval-runs`. Exactly one of `datasetId`/`dataset` and `agentId`/`agent`. */
850
- interface CreateEvalRunRequest {
103
+ export interface CreateEvalRunRequest {
851
104
  datasetId?: string;
852
105
  dataset?: InlineEvalDatasetSpec;
853
106
  agentId?: string;
@@ -857,7 +110,7 @@ interface CreateEvalRunRequest {
857
110
  modelId?: string;
858
111
  overrides?: AgentEvalOverrides;
859
112
  }
860
- interface EvalDatasetSummary {
113
+ export interface EvalDatasetSummary {
861
114
  id: string;
862
115
  name: string;
863
116
  description: string | null;
@@ -866,10 +119,10 @@ interface EvalDatasetSummary {
866
119
  createdAt: string;
867
120
  updatedAt: string;
868
121
  }
869
- interface EvalDatasetList {
122
+ export interface EvalDatasetList {
870
123
  datasets: EvalDatasetSummary[];
871
124
  }
872
- interface EvalCase {
125
+ export interface EvalCase {
873
126
  id: string;
874
127
  name: string;
875
128
  input: Record<string, unknown>;
@@ -879,7 +132,7 @@ interface EvalCase {
879
132
  createdAt: string;
880
133
  updatedAt: string;
881
134
  }
882
- interface EvalDatasetDetail {
135
+ export interface EvalDatasetDetail {
883
136
  id: string;
884
137
  name: string;
885
138
  description: string | null;
@@ -888,12 +141,12 @@ interface EvalDatasetDetail {
888
141
  createdAt: string;
889
142
  updatedAt: string;
890
143
  }
891
- interface EvalRunAccepted {
144
+ export interface EvalRunAccepted {
892
145
  runId: string;
893
146
  status: string;
894
147
  streamUrl: string;
895
148
  }
896
- interface EvalRunSummary {
149
+ export interface EvalRunSummary {
897
150
  id: string;
898
151
  datasetId: string;
899
152
  datasetName: string;
@@ -911,7 +164,7 @@ interface EvalRunSummary {
911
164
  finishedAt: string | null;
912
165
  createdAt: string;
913
166
  }
914
- interface EvalCaseResult {
167
+ export interface EvalCaseResult {
915
168
  id: string;
916
169
  caseId: string;
917
170
  case: EvalCase;
@@ -925,18 +178,18 @@ interface EvalCaseResult {
925
178
  error: string | null;
926
179
  createdAt: string;
927
180
  }
928
- interface EvalRunDetail extends EvalRunSummary {
181
+ export interface EvalRunDetail extends EvalRunSummary {
929
182
  inlineAgentSpec: Record<string, unknown> | null;
930
183
  agentSpecSnapshot: Record<string, unknown> | null;
931
184
  updatedAt: string;
932
185
  results: EvalCaseResult[];
933
186
  }
934
- interface EvalRunList {
187
+ export interface EvalRunList {
935
188
  runs: EvalRunSummary[];
936
189
  limit: number;
937
190
  offset: number;
938
191
  }
939
- interface EvalRunCompareSide {
192
+ export interface EvalRunCompareSide {
940
193
  id: string;
941
194
  agentId: string | null;
942
195
  inlineAgent: boolean;
@@ -952,14 +205,14 @@ interface EvalRunCompareSide {
952
205
  finishedAt: string | null;
953
206
  createdAt: string;
954
207
  }
955
- interface EvalRunCompareCase {
208
+ export interface EvalRunCompareCase {
956
209
  caseId: string;
957
210
  caseName: string;
958
211
  caseInput: Record<string, unknown> | null;
959
212
  a: Record<string, unknown> | null;
960
213
  b: Record<string, unknown> | null;
961
214
  }
962
- interface EvalRunCompare {
215
+ export interface EvalRunCompare {
963
216
  datasetId: string;
964
217
  datasetName: string;
965
218
  runA: EvalRunCompareSide;
@@ -967,18 +220,18 @@ interface EvalRunCompare {
967
220
  cases: EvalRunCompareCase[];
968
221
  }
969
222
  /** One SSE frame from `GET /eval-runs/:runId/stream`. */
970
- interface EvalRunEvent {
223
+ export interface EvalRunEvent {
971
224
  type: string;
972
225
  [key: string]: unknown;
973
226
  }
974
- interface ListEvalRunsOptions {
227
+ export interface ListEvalRunsOptions {
975
228
  datasetId?: string;
976
229
  agentId?: string;
977
230
  status?: EvalRunStatus | string;
978
231
  limit?: number;
979
232
  offset?: number;
980
233
  }
981
- interface RunEvalOptions {
234
+ export interface RunEvalOptions {
982
235
  /** Client-resolved tools to register for the eval run. */
983
236
  tools?: ToolRef[];
984
237
  /** Called for each SSE frame while the run is in flight. */
@@ -987,7 +240,7 @@ interface RunEvalOptions {
987
240
  pollIntervalMs?: number;
988
241
  signal?: AbortSignal;
989
242
  }
990
- interface MantyxClientOptions {
243
+ export interface MantyxClientOptions {
991
244
  /**
992
245
  * Workspace API key (token prefix `mantyx_`) **or** a MANTYX OAuth 2.0
993
246
  * access token (token prefix `mantyx_at_`). The server resolves either
@@ -1055,7 +308,7 @@ interface MantyxClientOptions {
1055
308
  /** Default per-request timeout in milliseconds. Default: 60s. */
1056
309
  timeoutMs?: number;
1057
310
  }
1058
- interface ModelInfo {
311
+ export interface ModelInfo {
1059
312
  id: string;
1060
313
  label: string;
1061
314
  provider: string;
@@ -1068,11 +321,11 @@ interface ModelInfo {
1068
321
  cacheReadPer1MUsd: number | null;
1069
322
  } | null;
1070
323
  }
1071
- interface ModelCatalog {
324
+ export interface ModelCatalog {
1072
325
  models: ModelInfo[];
1073
326
  defaultModelId: string | null;
1074
327
  }
1075
- interface AgentSpecBase {
328
+ export interface AgentSpecBase {
1076
329
  name?: string;
1077
330
  /**
1078
331
  * Reference to a persisted MANTYX agent in this workspace. When set, the
@@ -1177,14 +430,17 @@ interface AgentSpecBase {
1177
430
  /**
1178
431
  * In-product **task plan** — live checklist emitted as `task_plan` SSE
1179
432
  * events and (for `planOnly` runs) returned on the terminal `result`.
1180
- * Opt-in: every planned run pays for at least one classifier LLM call.
433
+ * Opt-in: exposes the host `update_task_plan` tool so the executing agent
434
+ * owns the checklist (no separate classifier/tracker LLM on executed runs).
1181
435
  *
1182
- * - `true` — auto-classify; track step statuses during the run when warranted.
1183
- * - `{ steps?, brief? }` — caller-provided checklist (skips the classifier).
436
+ * - `"auto"` / `true` — agent decides during its first turn whether to plan.
437
+ * - `"required"` — agent must initialize a plan before substantive tools.
438
+ * - `{ mode?, steps?, brief? }` — caller-seeded checklist (`mode` defaults
439
+ * to `"auto"`; use `"required"` to enforce).
1184
440
  * - `{ planOnly: true, steps?, brief? }` — produce the plan and **stop**
1185
441
  * without executing the agent loop; read the final checklist from
1186
442
  * {@link RunResult.plan}.
1187
- * - `false` — no planning (default when omitted).
443
+ * - `"off"` / `false` — no planning (default when omitted).
1188
444
  *
1189
445
  * See `docs/agent-runs-protocol.md` §4.9. Prefer {@link MantyxClient.runPlan}
1190
446
  * for plan-only runs.
@@ -1203,7 +459,7 @@ interface AgentSpecBase {
1203
459
  */
1204
460
  metadata?: Record<string, string>;
1205
461
  }
1206
- interface RunSpec extends AgentSpecBase {
462
+ export interface RunSpec extends AgentSpecBase {
1207
463
  prompt?: string;
1208
464
  messages?: ConversationMessage[];
1209
465
  /**
@@ -1220,20 +476,20 @@ interface RunSpec extends AgentSpecBase {
1220
476
  /** Aborts the run on the client and best-effort cancels server-side. */
1221
477
  signal?: AbortSignal;
1222
478
  }
1223
- type SessionSpec = AgentSpecBase;
479
+ export type SessionSpec = AgentSpecBase;
1224
480
  /**
1225
481
  * Either a Zod schema (auto-converted to JSON Schema by the SDK) or a
1226
482
  * pre-shaped JSON Schema object. Mirrors {@link LocalToolSchemaInput} and
1227
483
  * Go's `OutputSchema.Schema any` (struct reflection) — pass your
1228
484
  * source-of-truth schema and the SDK serialises it for the wire.
1229
485
  */
1230
- type OutputSchemaValue = LocalToolSchemaInput;
486
+ export type OutputSchemaValue = LocalToolSchemaInput;
1231
487
  /**
1232
488
  * Constrains the final assistant text to a JSON document matching a
1233
489
  * JSON Schema. See {@link AgentSpecBase.outputSchema} for the full
1234
490
  * semantics.
1235
491
  */
1236
- interface OutputSchema {
492
+ export interface OutputSchema {
1237
493
  /** Optional. Defaults to `"output"`. Must match `/^[a-zA-Z0-9_-]{1,64}$/`. */
1238
494
  name?: string;
1239
495
  /** Required. Zod schema or JSON Schema describing the final assistant text. Root must be a JSON object. */
@@ -1246,7 +502,7 @@ interface OutputSchema {
1246
502
  * Both fields are optional; omitted ones inherit the MANTYX runtime
1247
503
  * defaults (`consecutiveThreshold: 3`, `hardCutoffThreshold: 6`).
1248
504
  */
1249
- interface LoopDetection {
505
+ export interface LoopDetection {
1250
506
  /**
1251
507
  * Number of identical consecutive tool-call batches that triggers the
1252
508
  * **soft nudge** — the pipeline injects a steering message ("either
@@ -1267,7 +523,7 @@ interface LoopDetection {
1267
523
  * Per-tool call cap. See {@link AgentSpecBase.toolBudgets} for the full
1268
524
  * semantics.
1269
525
  */
1270
- interface ToolBudget {
526
+ export interface ToolBudget {
1271
527
  /**
1272
528
  * Hard cap on executed calls per run. `0` disables the tool entirely
1273
529
  * (every attempt returns the synthetic "budget exceeded" body on the
@@ -1282,7 +538,7 @@ interface ToolBudget {
1282
538
  * from a clean slate (no runtime defaults applied on top); omit the field
1283
539
  * entirely to keep the defaults.
1284
540
  */
1285
- type ToolBudgets = Record<string, ToolBudget>;
541
+ export type ToolBudgets = Record<string, ToolBudget>;
1286
542
  /**
1287
543
  * Run-supervisor configuration. See {@link AgentSpecBase.supervisor} for the
1288
544
  * full semantics. Pass `false` (instead of an object) to disable the platform
@@ -1295,27 +551,31 @@ type ToolBudgets = Record<string, ToolBudget>;
1295
551
  * `{ chars: 3000, ms: 30000 }`). Pass `false` to only review at tool-round
1296
552
  * boundaries.
1297
553
  */
1298
- interface Supervisor {
554
+ export interface Supervisor {
1299
555
  /** LLM calls (`completeTurn` invocations) between supervisor reviews. */
1300
556
  interval?: number;
1301
557
  /** Mid-turn reasoning trigger, or `false` to disable. */
1302
558
  reasoningTrigger?: ReasoningTrigger | false;
1303
559
  }
1304
560
  /** Mid-turn supervisor review trigger (reasoning span length / duration). */
1305
- interface ReasoningTrigger {
561
+ export interface ReasoningTrigger {
1306
562
  /** Reasoning characters per span before review. Default `3000`, max `50000`. */
1307
563
  chars?: number;
1308
564
  /** Milliseconds per reasoning span before review. Default `30000`, max `600000`. */
1309
565
  ms?: number;
1310
566
  }
1311
567
  /** Verdict from a run-supervisor review. */
1312
- type SupervisorAction = "on_track" | "redirect" | "finalize";
568
+ export type SupervisorAction = "on_track" | "redirect" | "finalize";
1313
569
  /** When a supervisor review fired relative to the model turn. */
1314
- type SupervisorPhase = "turn_boundary" | "reasoning";
570
+ export type SupervisorPhase = "turn_boundary" | "reasoning";
571
+ /** Planning mode for a run. See `docs/agent-runs-protocol.md` §4.9. */
572
+ export type PlanMode = "off" | "auto" | "required";
1315
573
  /** Status of one step in an in-product task plan. */
1316
- type TaskPlanStepStatus = "pending" | "in_progress" | "done";
574
+ export type TaskPlanStepStatus = "pending" | "in_progress" | "done" | "blocked" | "skipped";
1317
575
  /** One checklist row in a {@link TaskPlan}. */
1318
- interface TaskPlanStep {
576
+ export interface TaskPlanStep {
577
+ /** Stable step id (v2 task plans). */
578
+ id?: string;
1319
579
  title: string;
1320
580
  status: TaskPlanStepStatus;
1321
581
  }
@@ -1323,30 +583,47 @@ interface TaskPlanStep {
1323
583
  * Structured task plan surfaced on `task_plan` events and (for plan-only runs)
1324
584
  * on {@link RunResult.plan}. See `docs/agent-runs-protocol.md` §4.9.
1325
585
  */
1326
- interface TaskPlan {
586
+ export interface TaskPlan {
587
+ /** Wire format version (`2` on agent-owned plans). */
588
+ v?: number;
589
+ /** Stable id for idempotent snapshot application. */
590
+ planId?: string;
591
+ /** Monotonic revision per {@link planId}. */
592
+ revision?: number;
593
+ /** Active planning mode (`auto` | `required`). */
594
+ mode?: PlanMode;
595
+ /** Who produced the plan (`agent` | `caller`). */
596
+ source?: string;
1327
597
  /** Optional one-line objective summary. */
1328
598
  brief?: string;
1329
599
  steps: TaskPlanStep[];
1330
600
  }
601
+ /** One transition in a v2 `task_plan` event. */
602
+ export interface TaskPlanTransition {
603
+ kind: string;
604
+ stepId?: string;
605
+ }
1331
606
  /**
1332
- * Caller-supplied plan options. Pass `true` / `false` at the top level via
1333
- * {@link PlanSpec} for auto-classify / disable.
607
+ * Caller-supplied plan options. Pass `"auto"` / `"required"` / `true` / `false`
608
+ * at the top level via {@link PlanSpec}, or set {@link mode} on the object.
1334
609
  */
1335
- interface PlanOptions {
610
+ export interface PlanOptions {
611
+ /** `off` | `auto` | `required`. Defaults to `auto`. */
612
+ mode?: PlanMode;
1336
613
  /** When `true`, produce the plan and terminate without executing the agent loop. */
1337
614
  planOnly?: boolean;
1338
615
  /** One-line objective for a caller-provided plan. Clamped server-side. */
1339
616
  brief?: string;
1340
- /** Caller-provided checklist titles. Omit to let the classifier decide. */
617
+ /** Caller-provided checklist titles. */
1341
618
  steps?: string[];
1342
619
  }
1343
- /** `true` (auto-classify) | options object | `false` (disable). */
1344
- type PlanSpec = boolean | PlanOptions;
620
+ /** `"off"` | `"auto"` | `"required"` | `true`/`false` aliases | options object. */
621
+ export type PlanSpec = boolean | PlanMode | PlanOptions;
1345
622
  /**
1346
623
  * Build a {@link PlanSpec} for plan-only runs. Equivalent to
1347
624
  * `{ planOnly: true, steps?, brief? }`.
1348
625
  */
1349
- declare function planOnly(options?: {
626
+ export declare function planOnly(options?: {
1350
627
  steps?: string[];
1351
628
  brief?: string;
1352
629
  }): PlanOptions;
@@ -1365,7 +642,7 @@ declare function planOnly(options?: {
1365
642
  * detect "no usage data" by checking `result.model?.provider` is empty
1366
643
  * / undefined.
1367
644
  */
1368
- interface RunTokenUsage {
645
+ export interface RunTokenUsage {
1369
646
  /**
1370
647
  * Total billable input tokens — fresh prompt tokens plus the
1371
648
  * cached-read slice the provider still bills (at a discount) plus
@@ -1399,7 +676,7 @@ interface RunTokenUsage {
1399
676
  * terminal `result` / `error` events (and `GET /agent-runs/:runId`)
1400
677
  * by MANTYX ≥ 2026-09. See `docs/agent-runs-protocol.md` §7.1.
1401
678
  */
1402
- interface RunModelInfo {
679
+ export interface RunModelInfo {
1403
680
  /**
1404
681
  * Catalog id — the same string a caller would pass back as
1405
682
  * `modelId` to re-select this exact entry (e.g. `"platform:demo"`,
@@ -1426,7 +703,7 @@ interface RunModelInfo {
1426
703
  */
1427
704
  reasoningEffort?: string;
1428
705
  }
1429
- interface RunResult {
706
+ export interface RunResult {
1430
707
  runId: string;
1431
708
  text: string;
1432
709
  events: RunEvent[];
@@ -1453,19 +730,19 @@ interface RunResult {
1453
730
  */
1454
731
  plan?: TaskPlan;
1455
732
  }
1456
- interface RunEventBase {
733
+ export interface RunEventBase {
1457
734
  seq: number;
1458
735
  type: string;
1459
736
  }
1460
- interface AssistantDeltaEvent extends RunEventBase {
737
+ export interface AssistantDeltaEvent extends RunEventBase {
1461
738
  type: "assistant_delta";
1462
739
  text: string;
1463
740
  }
1464
- interface ThinkingDeltaEvent extends RunEventBase {
741
+ export interface ThinkingDeltaEvent extends RunEventBase {
1465
742
  type: "thinking_delta";
1466
743
  text: string;
1467
744
  }
1468
- interface AssistantMessageEvent extends RunEventBase {
745
+ export interface AssistantMessageEvent extends RunEventBase {
1469
746
  type: "assistant_message";
1470
747
  /**
1471
748
  * Full assistant text for this turn (concatenation of every preceding
@@ -1496,7 +773,7 @@ interface AssistantMessageEvent extends RunEventBase {
1496
773
  input: Record<string, unknown>;
1497
774
  }>;
1498
775
  }
1499
- interface ServerToolResultEvent extends RunEventBase {
776
+ export interface ServerToolResultEvent extends RunEventBase {
1500
777
  type: "tool_result";
1501
778
  name: string;
1502
779
  args?: Record<string, unknown>;
@@ -1504,7 +781,7 @@ interface ServerToolResultEvent extends RunEventBase {
1504
781
  summary?: string;
1505
782
  phase?: "start" | "end";
1506
783
  }
1507
- interface LocalToolCallEvent extends RunEventBase {
784
+ export interface LocalToolCallEvent extends RunEventBase {
1508
785
  type: "local_tool_call";
1509
786
  toolUseId: string;
1510
787
  /**
@@ -1552,7 +829,7 @@ interface LocalToolCallEvent extends RunEventBase {
1552
829
  [k: string]: unknown;
1553
830
  };
1554
831
  }
1555
- interface LocalToolResultInEvent extends RunEventBase {
832
+ export interface LocalToolResultInEvent extends RunEventBase {
1556
833
  type: "local_tool_result_in";
1557
834
  toolUseId: string;
1558
835
  result?: string;
@@ -1567,7 +844,7 @@ interface LocalToolResultInEvent extends RunEventBase {
1567
844
  * `hardCutoff: false` is the soft nudge round; `true` is the forced
1568
845
  * finalise. The same run may emit one of each.
1569
846
  */
1570
- interface LoopDetectedEvent extends RunEventBase {
847
+ export interface LoopDetectedEvent extends RunEventBase {
1571
848
  type: "loop_detected";
1572
849
  /** Length of the identical-batch streak that just tripped the threshold. */
1573
850
  consecutiveCount: number;
@@ -1583,7 +860,7 @@ interface LoopDetectedEvent extends RunEventBase {
1583
860
  * event to render UI banners (`memory budget exhausted` etc.) without
1584
861
  * re-parsing tool-result bodies.
1585
862
  */
1586
- interface ToolBudgetExceededEvent extends RunEventBase {
863
+ export interface ToolBudgetExceededEvent extends RunEventBase {
1587
864
  type: "tool_budget_exceeded";
1588
865
  /** Logical tool name (matches the key in `spec.toolBudgets`). */
1589
866
  tool: string;
@@ -1602,7 +879,7 @@ interface ToolBudgetExceededEvent extends RunEventBase {
1602
879
  * by the time this event arrives; the SDK should render a status note and
1603
880
  * keep consuming the stream.
1604
881
  */
1605
- interface SupervisorEvent extends RunEventBase {
882
+ export interface SupervisorEvent extends RunEventBase {
1606
883
  type: "supervisor";
1607
884
  /** One of `"on_track"`, `"redirect"`, `"finalize"`. */
1608
885
  action: SupervisorAction;
@@ -1628,13 +905,26 @@ interface SupervisorEvent extends RunEventBase {
1628
905
  /**
1629
906
  * Live checklist update for an in-product task plan. Non-terminal — the run
1630
907
  * continues until `result` / `error` / `cancelled`. See §4.9.
908
+ *
909
+ * Prefer {@link plan} (canonical v2 snapshot). {@link brief} and {@link steps}
910
+ * are mirrored at the top level for pre-v2 clients.
1631
911
  */
1632
- interface TaskPlanEvent extends RunEventBase {
912
+ export interface TaskPlanEvent extends RunEventBase {
1633
913
  type: "task_plan";
914
+ /** Canonical post-transition snapshot (v2). */
915
+ plan?: TaskPlan;
916
+ v?: number;
917
+ planId?: string;
918
+ revision?: number;
919
+ mode?: PlanMode;
920
+ source?: string;
921
+ transition?: TaskPlanTransition;
922
+ transitionIndex?: number;
923
+ transitionCount?: number;
1634
924
  brief?: string;
1635
- steps: TaskPlanStep[];
925
+ steps?: TaskPlanStep[];
1636
926
  }
1637
- interface ResultEvent extends RunEventBase {
927
+ export interface ResultEvent extends RunEventBase {
1638
928
  type: "result";
1639
929
  subtype: string;
1640
930
  text?: string;
@@ -1651,7 +941,7 @@ interface ResultEvent extends RunEventBase {
1651
941
  /** Resolved model that executed the run. See {@link RunModelInfo}. */
1652
942
  model?: RunModelInfo;
1653
943
  }
1654
- interface ErrorEvent extends RunEventBase {
944
+ export interface ErrorEvent extends RunEventBase {
1655
945
  type: "error";
1656
946
  /** Human-readable failure message. */
1657
947
  error: string;
@@ -1701,7 +991,7 @@ interface ErrorEvent extends RunEventBase {
1701
991
  /** Resolved model that executed the run. See {@link RunModelInfo}. */
1702
992
  model?: RunModelInfo;
1703
993
  }
1704
- interface CancelledEvent extends RunEventBase {
994
+ export interface CancelledEvent extends RunEventBase {
1705
995
  type: "cancelled";
1706
996
  reason?: string;
1707
997
  }
@@ -1711,17 +1001,17 @@ interface CancelledEvent extends RunEventBase {
1711
1001
  * never emits this — the client already knows the prompt it sent — but
1712
1002
  * conversation restoration needs it to rebuild the user side of the thread.
1713
1003
  */
1714
- interface UserMessageEvent extends RunEventBase {
1004
+ export interface UserMessageEvent extends RunEventBase {
1715
1005
  type: "user_message";
1716
1006
  text: string;
1717
1007
  /** Present on session-event replay when the user turn carried file inputs. */
1718
1008
  attachments?: AttachmentMetadata[];
1719
1009
  }
1720
- type RunEvent = AssistantDeltaEvent | ThinkingDeltaEvent | AssistantMessageEvent | UserMessageEvent | ServerToolResultEvent | LocalToolCallEvent | LocalToolResultInEvent | LoopDetectedEvent | ToolBudgetExceededEvent | SupervisorEvent | TaskPlanEvent | ResultEvent | ErrorEvent | CancelledEvent | (RunEventBase & {
1010
+ export type RunEvent = AssistantDeltaEvent | ThinkingDeltaEvent | AssistantMessageEvent | UserMessageEvent | ServerToolResultEvent | LocalToolCallEvent | LocalToolResultInEvent | LoopDetectedEvent | ToolBudgetExceededEvent | SupervisorEvent | TaskPlanEvent | ResultEvent | ErrorEvent | CancelledEvent | (RunEventBase & {
1721
1011
  type: string;
1722
1012
  [key: string]: unknown;
1723
1013
  });
1724
- interface SessionInfo {
1014
+ export interface SessionInfo {
1725
1015
  id: string;
1726
1016
  name: string;
1727
1017
  status: "active" | "ended";
@@ -1734,7 +1024,7 @@ interface SessionInfo {
1734
1024
  metadata: Record<string, string>;
1735
1025
  }
1736
1026
  /** One row from {@link MantyxClient.listSessions}. */
1737
- interface SessionSummary {
1027
+ export interface SessionSummary {
1738
1028
  sessionId: string;
1739
1029
  /** ISO 8601 creation timestamp. */
1740
1030
  creationDate: string;
@@ -1746,13 +1036,13 @@ interface SessionSummary {
1746
1036
  status: "active" | "ended";
1747
1037
  }
1748
1038
  /** Paginated result of {@link MantyxClient.listSessions}. */
1749
- interface SessionListResult {
1039
+ export interface SessionListResult {
1750
1040
  total: number;
1751
1041
  limit: number;
1752
1042
  offset: number;
1753
1043
  sessions: SessionSummary[];
1754
1044
  }
1755
- declare class MantyxClient {
1045
+ export declare class MantyxClient {
1756
1046
  readonly options: Required<Pick<MantyxClientOptions, "workspaceSlug" | "baseUrl">> & {
1757
1047
  /**
1758
1048
  * Single resolved bearer credential — either a workspace API key
@@ -1904,7 +1194,7 @@ declare class MantyxClient {
1904
1194
  private requestWithRetry;
1905
1195
  private errorFromResponse;
1906
1196
  }
1907
- declare class AgentSession {
1197
+ export declare class AgentSession {
1908
1198
  readonly id: string;
1909
1199
  readonly client: MantyxClient;
1910
1200
  private readonly handlers;
@@ -1990,7 +1280,7 @@ declare class AgentSession {
1990
1280
  end(): Promise<void>;
1991
1281
  }
1992
1282
  /** Internal registry of client-resolved handlers, indexed by `kind`. */
1993
- interface LocalHandlers {
1283
+ export interface LocalHandlers {
1994
1284
  /** `kind: "local"` — generic local tools, indexed by tool name. */
1995
1285
  localTools: Map<string, LocalTool>;
1996
1286
  /** `kind: "a2a_local"` — local A2A peers, indexed by tool name. */
@@ -1998,6 +1288,8 @@ interface LocalHandlers {
1998
1288
  /** `kind: "mcp_local"` — local MCP servers, indexed by server name. */
1999
1289
  mcpServers: Map<string, LocalMcpServer>;
2000
1290
  }
1291
+ /** Parse a `task_plan` event payload, preferring the canonical v2 `plan` field. */
1292
+ export declare function taskPlanFromEventData(data: Record<string, unknown>): TaskPlan | undefined;
2001
1293
  /**
2002
1294
  * Parse the terminal text of a `RunResult` as JSON.
2003
1295
  *
@@ -2028,6 +1320,5 @@ interface LocalHandlers {
2028
1320
  * // ^? { city: string; temperature_c: number }
2029
1321
  * ```
2030
1322
  */
2031
- declare function parseRunOutput<T = unknown>(result: RunResult, validator?: (value: unknown) => T): T;
2032
-
2033
- export { type LoopDetection as $, type A2AToolRef as A, type EvalRunSummary as B, type CancelledEvent as C, DEFAULT_BASE_URL as D, type ErrorEvent as E, type InlineEvalDatasetSpec as F, type InputFileAttachment as G, type InputFileAttachmentMetadata as H, type InlineEvalCaseSpec as I, type InputFileUrlAttachment as J, type InputFileUrlAttachmentMetadata as K, type ListEvalRunsOptions as L, MantyxClient as M, type LocalA2ATool as N, type OutputSchema as O, type LocalHandlers as P, type LocalMcpHttpTransport as Q, type ReasoningLevel as R, type LocalMcpServer as S, type ToolRef as T, type LocalMcpStdioTransport as U, type LocalTool as V, type LocalToolCallEvent as W, type LocalToolOutput as X, type LocalToolResult as Y, type LocalToolResultInEvent as Z, type LoopDetectedEvent as _, type AgentEvalOverrides as a, defineLocalA2A as a$, type MantyxA2AOptions as a0, MantyxAuthError as a1, type MantyxClientOptions as a2, MantyxError as a3, type MantyxMcpOptions as a4, MantyxNetworkError as a5, MantyxOAuthClient as a6, type MantyxOAuthClientOptions as a7, MantyxOAuthError as a8, MantyxParseError as a9, type RunFeedbackVerdict as aA, type RunModelInfo as aB, type RunResult as aC, type RunSpec as aD, type RunTokenUsage as aE, type ServerToolResultEvent as aF, type SessionInfo as aG, type SessionListResult as aH, type SessionSpec as aI, type SessionSummary as aJ, type Supervisor as aK, type SupervisorAction as aL, type SupervisorEvent as aM, type SupervisorPhase as aN, type TaskPlan as aO, type TaskPlanEvent as aP, type TaskPlanStep as aQ, type TaskPlanStepStatus as aR, type ThinkingDeltaEvent as aS, type TokenRequestReason as aT, type TokenSource as aU, type ToolBudget as aV, type ToolBudgetExceededEvent as aW, type ToolBudgets as aX, type ToolResultFile as aY, type UserMessageEvent as aZ, type ZodLikeObject as a_, type MantyxPluginToolRef as aa, MantyxRunError as ab, type MantyxRunErrorInit as ac, type MantyxRunErrorModel as ad, type MantyxRunErrorTokens as ae, MantyxScopeError as af, MantyxToolError as ag, type MantyxToolRef as ah, type McpToolRef as ai, type MessageAttachment as aj, type ModelCatalog as ak, type ModelInfo as al, type OAuthToken as am, type OutputSchemaValue as an, type PlanOptions as ao, type PlanSpec as ap, type ReasoningTrigger as aq, type RefreshOptions as ar, type RefreshTokenSourceOptions as as, type ResultEvent as at, type RevokeOptions as au, type RunEvalOptions as av, type RunEvent as aw, type RunEventBase as ax, type RunFeedbackInput as ay, type RunFeedbackResult as az, AgentSession as b, defineLocalMcp as b0, defineLocalTool as b1, inputFileAttachment as b2, inputFileUrlAttachment as b3, isLocalA2ATool as b4, isLocalMcpServer as b5, isLocalTool as b6, mantyxA2A as b7, mantyxMcp as b8, mantyxPluginTool as b9, mantyxTool as ba, parseRunOutput as bb, planOnly as bc, type AgentSpecBase as c, type AssistantDeltaEvent as d, type AssistantMessageEvent as e, type AttachmentMetadata as f, type ConversationMessage as g, type CreateEvalRunRequest as h, DEFAULT_OAUTH_BASE_URL as i, DEFAULT_REFRESH_SKEW_MS as j, type DefineLocalA2AOptions as k, type DefineLocalMcpOptions as l, type DefineLocalToolOptions as m, type EvalCase as n, type EvalCaseResult as o, type EvalDatasetDetail as p, type EvalDatasetList as q, type EvalDatasetSummary as r, type EvalRunAccepted as s, type EvalRunCompare as t, type EvalRunCompareCase as u, type EvalRunCompareSide as v, type EvalRunDetail as w, type EvalRunEvent as x, type EvalRunList as y, type EvalRunStatus as z };
1323
+ export declare function parseRunOutput<T = unknown>(result: RunResult, validator?: (value: unknown) => T): T;
1324
+ //# sourceMappingURL=client.d.ts.map