@mantyx/sdk 0.17.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.
@@ -381,6 +381,50 @@ type ZodLikeObject = z.ZodType<Record<string, unknown>> & {
381
381
  * integer in `0..100` (where `0` explicitly disables provider thinking).
382
382
  */
383
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;
384
428
  /**
385
429
  * Either a Zod schema (auto-converted to JSON Schema by the SDK) or a
386
430
  * pre-shaped JSON Schema object. Used for both `parameters` and the new
@@ -420,7 +464,7 @@ interface LocalTool<TArgs = Record<string, unknown>> {
420
464
  * `docs/agent-runs-protocol.md` §4.1.1.
421
465
  */
422
466
  readonly readOnly: boolean;
423
- readonly execute: (args: TArgs) => Promise<string> | string;
467
+ readonly execute: (args: TArgs) => Promise<LocalToolOutput> | LocalToolOutput;
424
468
  }
425
469
  interface DefineLocalToolOptions<T extends ZodLikeObject | undefined> {
426
470
  /** Lowercase alphanumeric + underscore, max 64 chars. */
@@ -444,7 +488,7 @@ interface DefineLocalToolOptions<T extends ZodLikeObject | undefined> {
444
488
  * {@link LocalTool.readOnly}.
445
489
  */
446
490
  readOnly?: boolean;
447
- execute: (args: T extends ZodLikeObject ? z.infer<T> : Record<string, unknown>) => Promise<string> | string;
491
+ execute: (args: T extends ZodLikeObject ? z.infer<T> : Record<string, unknown>) => Promise<LocalToolOutput> | LocalToolOutput;
448
492
  }
449
493
  declare function defineLocalTool<T extends ZodLikeObject | undefined>(opts: DefineLocalToolOptions<T>): LocalTool;
450
494
  interface MantyxToolRef {
@@ -1610,6 +1654,7 @@ declare class MantyxClient {
1610
1654
  postToolResult(runId: string, toolUseId: string, payload: {
1611
1655
  result?: string;
1612
1656
  error?: string;
1657
+ files?: ToolResultFile[];
1613
1658
  }): Promise<void>;
1614
1659
  cancelRun(runId: string): Promise<void>;
1615
1660
  /**
@@ -1781,4 +1826,4 @@ interface LocalHandlers {
1781
1826
  */
1782
1827
  declare function parseRunOutput<T = unknown>(result: RunResult, validator?: (value: unknown) => T): T;
1783
1828
 
1784
- export { type ModelCatalog as $, type A2AToolRef as A, MantyxError as B, type CancelledEvent as C, DEFAULT_BASE_URL as D, type ErrorEvent as E, type MantyxMcpOptions as F, MantyxNetworkError as G, MantyxOAuthClient as H, type InputFileAttachment as I, type MantyxOAuthClientOptions as J, MantyxOAuthError as K, type LocalA2ATool as L, MantyxClient as M, MantyxParseError as N, type OutputSchema as O, type MantyxPluginToolRef as P, MantyxRunError as Q, type ReasoningLevel as R, type MantyxRunErrorInit as S, type ToolRef as T, type MantyxRunErrorModel as U, type MantyxRunErrorTokens as V, MantyxScopeError as W, MantyxToolError as X, type MantyxToolRef as Y, type McpToolRef as Z, type MessageAttachment as _, AgentSession as a, type ModelInfo as a0, type OAuthToken as a1, type OutputSchemaValue as a2, type PlanOptions as a3, type PlanSpec as a4, type ReasoningTrigger as a5, type RefreshOptions as a6, type RefreshTokenSourceOptions as a7, type ResultEvent as a8, type RevokeOptions as a9, type ToolBudgetExceededEvent as aA, type ToolBudgets as aB, type UserMessageEvent as aC, type ZodLikeObject as aD, defineLocalA2A as aE, defineLocalMcp as aF, defineLocalTool as aG, inputFileAttachment as aH, inputFileUrlAttachment as aI, isLocalA2ATool as aJ, isLocalMcpServer as aK, isLocalTool as aL, mantyxA2A as aM, mantyxMcp as aN, mantyxPluginTool as aO, mantyxTool as aP, parseRunOutput as aQ, planOnly as aR, type RunEvent as aa, type RunEventBase as ab, type RunFeedbackInput as ac, type RunFeedbackResult as ad, type RunFeedbackVerdict as ae, type RunModelInfo as af, type RunResult as ag, type RunSpec as ah, type RunTokenUsage as ai, type ServerToolResultEvent as aj, type SessionInfo as ak, type SessionListResult as al, type SessionSpec as am, type SessionSummary as an, type Supervisor as ao, type SupervisorAction as ap, type SupervisorEvent as aq, type SupervisorPhase as ar, type TaskPlan as as, type TaskPlanEvent as at, type TaskPlanStep as au, type TaskPlanStepStatus as av, type ThinkingDeltaEvent as aw, type TokenRequestReason as ax, type TokenSource as ay, type ToolBudget as az, type AgentSpecBase as b, type AssistantDeltaEvent as c, type AssistantMessageEvent as d, type AttachmentMetadata as e, type ConversationMessage as f, DEFAULT_OAUTH_BASE_URL as g, DEFAULT_REFRESH_SKEW_MS as h, type DefineLocalA2AOptions as i, type DefineLocalMcpOptions as j, type DefineLocalToolOptions as k, type InputFileAttachmentMetadata as l, type InputFileUrlAttachment as m, type InputFileUrlAttachmentMetadata as n, type LocalHandlers as o, type LocalMcpHttpTransport as p, type LocalMcpServer as q, type LocalMcpStdioTransport as r, type LocalTool as s, type LocalToolCallEvent as t, type LocalToolResultInEvent as u, type LoopDetectedEvent as v, type LoopDetection as w, type MantyxA2AOptions as x, MantyxAuthError as y, type MantyxClientOptions as z };
1829
+ export { type McpToolRef as $, type A2AToolRef as A, MantyxAuthError as B, type CancelledEvent as C, DEFAULT_BASE_URL as D, type ErrorEvent as E, type MantyxClientOptions as F, MantyxError as G, type MantyxMcpOptions as H, type InputFileAttachment as I, MantyxNetworkError as J, MantyxOAuthClient as K, type LocalA2ATool as L, MantyxClient as M, type MantyxOAuthClientOptions as N, type OutputSchema as O, MantyxOAuthError as P, MantyxParseError as Q, type ReasoningLevel as R, type MantyxPluginToolRef as S, type ToolRef as T, MantyxRunError as U, type MantyxRunErrorInit as V, type MantyxRunErrorModel as W, type MantyxRunErrorTokens as X, MantyxScopeError as Y, MantyxToolError as Z, type MantyxToolRef as _, AgentSession as a, type MessageAttachment as a0, type ModelCatalog as a1, type ModelInfo as a2, type OAuthToken as a3, type OutputSchemaValue as a4, type PlanOptions as a5, type PlanSpec as a6, type ReasoningTrigger as a7, type RefreshOptions as a8, type RefreshTokenSourceOptions as a9, type TokenSource as aA, type ToolBudget as aB, type ToolBudgetExceededEvent as aC, type ToolBudgets as aD, type ToolResultFile as aE, type UserMessageEvent as aF, type ZodLikeObject as aG, defineLocalA2A as aH, defineLocalMcp as aI, defineLocalTool as aJ, inputFileAttachment as aK, inputFileUrlAttachment as aL, isLocalA2ATool as aM, isLocalMcpServer as aN, isLocalTool as aO, mantyxA2A as aP, mantyxMcp as aQ, mantyxPluginTool as aR, mantyxTool as aS, parseRunOutput as aT, planOnly as aU, type ResultEvent as aa, type RevokeOptions as ab, type RunEvent as ac, type RunEventBase as ad, type RunFeedbackInput as ae, type RunFeedbackResult as af, type RunFeedbackVerdict as ag, type RunModelInfo as ah, type RunResult as ai, type RunSpec as aj, type RunTokenUsage as ak, type ServerToolResultEvent as al, type SessionInfo as am, type SessionListResult as an, type SessionSpec as ao, type SessionSummary as ap, type Supervisor as aq, type SupervisorAction as ar, type SupervisorEvent as as, type SupervisorPhase as at, type TaskPlan as au, type TaskPlanEvent as av, type TaskPlanStep as aw, type TaskPlanStepStatus as ax, type ThinkingDeltaEvent as ay, type TokenRequestReason as az, type AgentSpecBase as b, type AssistantDeltaEvent as c, type AssistantMessageEvent as d, type AttachmentMetadata as e, type ConversationMessage as f, DEFAULT_OAUTH_BASE_URL as g, DEFAULT_REFRESH_SKEW_MS as h, type DefineLocalA2AOptions as i, type DefineLocalMcpOptions as j, type DefineLocalToolOptions as k, type InputFileAttachmentMetadata as l, type InputFileUrlAttachment as m, type InputFileUrlAttachmentMetadata as n, type LocalHandlers as o, type LocalMcpHttpTransport as p, type LocalMcpServer as q, type LocalMcpStdioTransport as r, type LocalTool as s, type LocalToolCallEvent as t, type LocalToolOutput as u, type LocalToolResult as v, type LocalToolResultInEvent as w, type LoopDetectedEvent as x, type LoopDetection as y, type MantyxA2AOptions as z };
@@ -381,6 +381,50 @@ type ZodLikeObject = z.ZodType<Record<string, unknown>> & {
381
381
  * integer in `0..100` (where `0` explicitly disables provider thinking).
382
382
  */
383
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;
384
428
  /**
385
429
  * Either a Zod schema (auto-converted to JSON Schema by the SDK) or a
386
430
  * pre-shaped JSON Schema object. Used for both `parameters` and the new
@@ -420,7 +464,7 @@ interface LocalTool<TArgs = Record<string, unknown>> {
420
464
  * `docs/agent-runs-protocol.md` §4.1.1.
421
465
  */
422
466
  readonly readOnly: boolean;
423
- readonly execute: (args: TArgs) => Promise<string> | string;
467
+ readonly execute: (args: TArgs) => Promise<LocalToolOutput> | LocalToolOutput;
424
468
  }
425
469
  interface DefineLocalToolOptions<T extends ZodLikeObject | undefined> {
426
470
  /** Lowercase alphanumeric + underscore, max 64 chars. */
@@ -444,7 +488,7 @@ interface DefineLocalToolOptions<T extends ZodLikeObject | undefined> {
444
488
  * {@link LocalTool.readOnly}.
445
489
  */
446
490
  readOnly?: boolean;
447
- execute: (args: T extends ZodLikeObject ? z.infer<T> : Record<string, unknown>) => Promise<string> | string;
491
+ execute: (args: T extends ZodLikeObject ? z.infer<T> : Record<string, unknown>) => Promise<LocalToolOutput> | LocalToolOutput;
448
492
  }
449
493
  declare function defineLocalTool<T extends ZodLikeObject | undefined>(opts: DefineLocalToolOptions<T>): LocalTool;
450
494
  interface MantyxToolRef {
@@ -1610,6 +1654,7 @@ declare class MantyxClient {
1610
1654
  postToolResult(runId: string, toolUseId: string, payload: {
1611
1655
  result?: string;
1612
1656
  error?: string;
1657
+ files?: ToolResultFile[];
1613
1658
  }): Promise<void>;
1614
1659
  cancelRun(runId: string): Promise<void>;
1615
1660
  /**
@@ -1781,4 +1826,4 @@ interface LocalHandlers {
1781
1826
  */
1782
1827
  declare function parseRunOutput<T = unknown>(result: RunResult, validator?: (value: unknown) => T): T;
1783
1828
 
1784
- export { type ModelCatalog as $, type A2AToolRef as A, MantyxError as B, type CancelledEvent as C, DEFAULT_BASE_URL as D, type ErrorEvent as E, type MantyxMcpOptions as F, MantyxNetworkError as G, MantyxOAuthClient as H, type InputFileAttachment as I, type MantyxOAuthClientOptions as J, MantyxOAuthError as K, type LocalA2ATool as L, MantyxClient as M, MantyxParseError as N, type OutputSchema as O, type MantyxPluginToolRef as P, MantyxRunError as Q, type ReasoningLevel as R, type MantyxRunErrorInit as S, type ToolRef as T, type MantyxRunErrorModel as U, type MantyxRunErrorTokens as V, MantyxScopeError as W, MantyxToolError as X, type MantyxToolRef as Y, type McpToolRef as Z, type MessageAttachment as _, AgentSession as a, type ModelInfo as a0, type OAuthToken as a1, type OutputSchemaValue as a2, type PlanOptions as a3, type PlanSpec as a4, type ReasoningTrigger as a5, type RefreshOptions as a6, type RefreshTokenSourceOptions as a7, type ResultEvent as a8, type RevokeOptions as a9, type ToolBudgetExceededEvent as aA, type ToolBudgets as aB, type UserMessageEvent as aC, type ZodLikeObject as aD, defineLocalA2A as aE, defineLocalMcp as aF, defineLocalTool as aG, inputFileAttachment as aH, inputFileUrlAttachment as aI, isLocalA2ATool as aJ, isLocalMcpServer as aK, isLocalTool as aL, mantyxA2A as aM, mantyxMcp as aN, mantyxPluginTool as aO, mantyxTool as aP, parseRunOutput as aQ, planOnly as aR, type RunEvent as aa, type RunEventBase as ab, type RunFeedbackInput as ac, type RunFeedbackResult as ad, type RunFeedbackVerdict as ae, type RunModelInfo as af, type RunResult as ag, type RunSpec as ah, type RunTokenUsage as ai, type ServerToolResultEvent as aj, type SessionInfo as ak, type SessionListResult as al, type SessionSpec as am, type SessionSummary as an, type Supervisor as ao, type SupervisorAction as ap, type SupervisorEvent as aq, type SupervisorPhase as ar, type TaskPlan as as, type TaskPlanEvent as at, type TaskPlanStep as au, type TaskPlanStepStatus as av, type ThinkingDeltaEvent as aw, type TokenRequestReason as ax, type TokenSource as ay, type ToolBudget as az, type AgentSpecBase as b, type AssistantDeltaEvent as c, type AssistantMessageEvent as d, type AttachmentMetadata as e, type ConversationMessage as f, DEFAULT_OAUTH_BASE_URL as g, DEFAULT_REFRESH_SKEW_MS as h, type DefineLocalA2AOptions as i, type DefineLocalMcpOptions as j, type DefineLocalToolOptions as k, type InputFileAttachmentMetadata as l, type InputFileUrlAttachment as m, type InputFileUrlAttachmentMetadata as n, type LocalHandlers as o, type LocalMcpHttpTransport as p, type LocalMcpServer as q, type LocalMcpStdioTransport as r, type LocalTool as s, type LocalToolCallEvent as t, type LocalToolResultInEvent as u, type LoopDetectedEvent as v, type LoopDetection as w, type MantyxA2AOptions as x, MantyxAuthError as y, type MantyxClientOptions as z };
1829
+ export { type McpToolRef as $, type A2AToolRef as A, MantyxAuthError as B, type CancelledEvent as C, DEFAULT_BASE_URL as D, type ErrorEvent as E, type MantyxClientOptions as F, MantyxError as G, type MantyxMcpOptions as H, type InputFileAttachment as I, MantyxNetworkError as J, MantyxOAuthClient as K, type LocalA2ATool as L, MantyxClient as M, type MantyxOAuthClientOptions as N, type OutputSchema as O, MantyxOAuthError as P, MantyxParseError as Q, type ReasoningLevel as R, type MantyxPluginToolRef as S, type ToolRef as T, MantyxRunError as U, type MantyxRunErrorInit as V, type MantyxRunErrorModel as W, type MantyxRunErrorTokens as X, MantyxScopeError as Y, MantyxToolError as Z, type MantyxToolRef as _, AgentSession as a, type MessageAttachment as a0, type ModelCatalog as a1, type ModelInfo as a2, type OAuthToken as a3, type OutputSchemaValue as a4, type PlanOptions as a5, type PlanSpec as a6, type ReasoningTrigger as a7, type RefreshOptions as a8, type RefreshTokenSourceOptions as a9, type TokenSource as aA, type ToolBudget as aB, type ToolBudgetExceededEvent as aC, type ToolBudgets as aD, type ToolResultFile as aE, type UserMessageEvent as aF, type ZodLikeObject as aG, defineLocalA2A as aH, defineLocalMcp as aI, defineLocalTool as aJ, inputFileAttachment as aK, inputFileUrlAttachment as aL, isLocalA2ATool as aM, isLocalMcpServer as aN, isLocalTool as aO, mantyxA2A as aP, mantyxMcp as aQ, mantyxPluginTool as aR, mantyxTool as aS, parseRunOutput as aT, planOnly as aU, type ResultEvent as aa, type RevokeOptions as ab, type RunEvent as ac, type RunEventBase as ad, type RunFeedbackInput as ae, type RunFeedbackResult as af, type RunFeedbackVerdict as ag, type RunModelInfo as ah, type RunResult as ai, type RunSpec as aj, type RunTokenUsage as ak, type ServerToolResultEvent as al, type SessionInfo as am, type SessionListResult as an, type SessionSpec as ao, type SessionSummary as ap, type Supervisor as aq, type SupervisorAction as ar, type SupervisorEvent as as, type SupervisorPhase as at, type TaskPlan as au, type TaskPlanEvent as av, type TaskPlanStep as aw, type TaskPlanStepStatus as ax, type ThinkingDeltaEvent as ay, type TokenRequestReason as az, type AgentSpecBase as b, type AssistantDeltaEvent as c, type AssistantMessageEvent as d, type AttachmentMetadata as e, type ConversationMessage as f, DEFAULT_OAUTH_BASE_URL as g, DEFAULT_REFRESH_SKEW_MS as h, type DefineLocalA2AOptions as i, type DefineLocalMcpOptions as j, type DefineLocalToolOptions as k, type InputFileAttachmentMetadata as l, type InputFileUrlAttachment as m, type InputFileUrlAttachmentMetadata as n, type LocalHandlers as o, type LocalMcpHttpTransport as p, type LocalMcpServer as q, type LocalMcpStdioTransport as r, type LocalTool as s, type LocalToolCallEvent as t, type LocalToolOutput as u, type LocalToolResult as v, type LocalToolResultInEvent as w, type LoopDetectedEvent as x, type LoopDetection as y, type MantyxA2AOptions as z };
@@ -1,4 +1,4 @@
1
- import { ag as RunResult, M as MantyxClient, R as ReasoningLevel, s as LocalTool } from './client-IjrvboaL.cjs';
1
+ import { ai as RunResult, M as MantyxClient, R as ReasoningLevel, s as LocalTool } from './client-CLT46vp5.cjs';
2
2
 
3
3
  /** Scroll direction shared by `scroll_at` / `scroll_document`. */
4
4
  type ScrollDirection = "up" | "down" | "left" | "right";
@@ -1,4 +1,4 @@
1
- import { ag as RunResult, M as MantyxClient, R as ReasoningLevel, s as LocalTool } from './client-IjrvboaL.js';
1
+ import { ai as RunResult, M as MantyxClient, R as ReasoningLevel, s as LocalTool } from './client-CLT46vp5.js';
2
2
 
3
3
  /** Scroll direction shared by `scroll_at` / `scroll_document`. */
4
4
  type ScrollDirection = "up" | "down" | "left" | "right";
package/dist/index.cjs CHANGED
@@ -291,6 +291,32 @@ function prefixedMcpToolName(serverName, toolName) {
291
291
  const prefix = `${serverName}_`;
292
292
  return toolName.startsWith(prefix) ? toolName : `${prefix}${toolName}`;
293
293
  }
294
+ function normalizeLocalToolOutput(out) {
295
+ if (typeof out === "string") return { result: out };
296
+ if (isLocalToolResult(out)) {
297
+ const files = sanitizeToolResultFiles(out.files);
298
+ const result = typeof out.result === "string" ? out.result : "";
299
+ return files ? { result, files } : { result };
300
+ }
301
+ return { result: JSON.stringify(out) };
302
+ }
303
+ function isLocalToolResult(out) {
304
+ if (out === null || typeof out !== "object" || Array.isArray(out)) return false;
305
+ const o = out;
306
+ return (typeof o.result === "string" || o.result === void 0) && ("files" in o || "result" in o);
307
+ }
308
+ function sanitizeToolResultFiles(files) {
309
+ if (!Array.isArray(files) || files.length === 0) return void 0;
310
+ const out = [];
311
+ for (const f of files) {
312
+ if (!f || typeof f !== "object") continue;
313
+ const file = f;
314
+ if (typeof file.filename === "string" && typeof file.mimeType === "string" && typeof file.data === "string") {
315
+ out.push({ filename: file.filename, mimeType: file.mimeType, data: file.data });
316
+ }
317
+ }
318
+ return out.length > 0 ? out : void 0;
319
+ }
294
320
 
295
321
  // src/local-resolver.ts
296
322
  async function resolveLocalRefs(tools, opts = { fetch: globalThis.fetch }) {
@@ -1018,6 +1044,7 @@ var MantyxClient = class {
1018
1044
  const kind = ev.kind ?? "local";
1019
1045
  try {
1020
1046
  let out;
1047
+ let files;
1021
1048
  if (kind === "a2a_local") {
1022
1049
  const tool = handlers.a2aTools.get(ev.name);
1023
1050
  if (!tool) {
@@ -1049,10 +1076,11 @@ var MantyxClient = class {
1049
1076
  return;
1050
1077
  }
1051
1078
  const args = handler.parameters ? handler.parameters.parse?.(ev.args) ?? ev.args : ev.args;
1052
- const result = await handler.execute(args);
1053
- out = typeof result === "string" ? result : JSON.stringify(result);
1079
+ const normalized = normalizeLocalToolOutput(await handler.execute(args));
1080
+ out = normalized.result;
1081
+ files = normalized.files;
1054
1082
  }
1055
- await this.postToolResult(runId, ev.toolUseId, { result: out });
1083
+ await this.postToolResult(runId, ev.toolUseId, files ? { result: out, files } : { result: out });
1056
1084
  } catch (err) {
1057
1085
  const message = err instanceof Error ? err.message : String(err);
1058
1086
  const handlerName = describeHandlerName(ev);
@@ -2371,7 +2399,7 @@ async function runComputerUse(opts) {
2371
2399
  }
2372
2400
 
2373
2401
  // src/version.ts
2374
- var SDK_VERSION = "0.17.0";
2402
+ var SDK_VERSION = "0.18.0";
2375
2403
  // Annotate the CommonJS export names for ESM import in node:
2376
2404
  0 && (module.exports = {
2377
2405
  AgentSession,