@mantyx/sdk 0.24.0 → 2026.9.2

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 (47) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/LICENSE +201 -0
  3. package/README.md +35 -12
  4. package/dist/a2a-server.cjs +11 -1
  5. package/dist/a2a-server.d.ts +2 -1
  6. package/dist/a2a-server.js +3 -2
  7. package/dist/{chunk-OUK6ZZ5H.js → chunk-XMNAWLMF.js} +75 -2
  8. package/dist/client.d.ts +59 -7
  9. package/dist/computer-use.d.ts +0 -1
  10. package/dist/errors.d.ts +13 -1
  11. package/dist/index.cjs +76 -3
  12. package/dist/index.d.ts +2 -2
  13. package/dist/index.js +2 -3
  14. package/dist/local-resolver.d.ts +0 -1
  15. package/dist/oauth.d.ts +0 -1
  16. package/dist/playwright.cjs +0 -1
  17. package/dist/playwright.d.ts +0 -1
  18. package/dist/playwright.js +0 -1
  19. package/dist/sse.d.ts +0 -1
  20. package/dist/structured-output.d.ts +11 -0
  21. package/dist/tools.d.ts +0 -1
  22. package/dist/version.d.ts +2 -3
  23. package/dist/zod-to-json-schema.d.ts +0 -1
  24. package/docs/agent-runs-protocol.md +238 -89
  25. package/docs/wire-protocol.md +201 -82
  26. package/package.json +17 -18
  27. package/CONTRIBUTING.md +0 -72
  28. package/EXTRACT.md +0 -70
  29. package/dist/a2a-server.cjs.map +0 -1
  30. package/dist/a2a-server.d.ts.map +0 -1
  31. package/dist/a2a-server.js.map +0 -1
  32. package/dist/chunk-OUK6ZZ5H.js.map +0 -1
  33. package/dist/client.d.ts.map +0 -1
  34. package/dist/computer-use.d.ts.map +0 -1
  35. package/dist/errors.d.ts.map +0 -1
  36. package/dist/index.cjs.map +0 -1
  37. package/dist/index.d.ts.map +0 -1
  38. package/dist/index.js.map +0 -1
  39. package/dist/local-resolver.d.ts.map +0 -1
  40. package/dist/oauth.d.ts.map +0 -1
  41. package/dist/playwright.cjs.map +0 -1
  42. package/dist/playwright.d.ts.map +0 -1
  43. package/dist/playwright.js.map +0 -1
  44. package/dist/sse.d.ts.map +0 -1
  45. package/dist/tools.d.ts.map +0 -1
  46. package/dist/version.d.ts.map +0 -1
  47. package/dist/zod-to-json-schema.d.ts.map +0 -1
@@ -118,6 +118,7 @@ short-circuit, etc.) see `agent-runs-protocol.md` §4.
118
118
  "outputSchema": {
119
119
  // optional; see §7
120
120
  "name": "weather_report", // defaults to "output"
121
+ "enforcement": "strict", // optional; "best_effort" (default) | "strict"
121
122
  "schema": {
122
123
  /* JSON Schema */
123
124
  },
@@ -423,21 +424,22 @@ Every event payload has the same envelope:
423
424
 
424
425
  The vocabulary (`EphemeralEventType` in `bus.ts`):
425
426
 
426
- | Type | Direction | Frequency | Purpose |
427
- | ---------------------- | --------- | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
428
- | `assistant_delta` | M → SDK | Many | Streamed assistant text token / chunk. |
429
- | `thinking_delta` | M → SDK | Many (iff `reasoningLevel > 0`) | Streamed extended-thinking text (provider redacts when policy requires). |
430
- | `tool_result` | M → SDK | Per server-resolved tool call | Informational — tells the SDK that MANTYX ran a server-resolved tool (`mantyx`, `mantyx_plugin`, `a2a`, `mcp`) and got a result. The SDK does not need to act on it. |
431
- | `local_tool_call` | M → SDK | Per client-resolved tool call | **Action required.** SDK must POST a tool-result. |
432
- | `local_tool_result_in` | M → SDK | Per client-resolved tool call | Informational mirror of the tool-result the SDK just posted, persisted for observability. Re-emitted to late subscribers so they can replay the conversation. |
433
- | `loop_detected` | M → SDK | 0–2× per run (soft nudge + optional hard cutoff) | Observability for the loop-detection guard (see §8). The server already substituted the synthetic skip + steering nudge — SDK clients render a status note (`looping — nudged` / `looping — gave up`) and otherwise leave the run alone. |
434
- | `tool_budget_exceeded` | M → SDK | Per intercepted tool call | Observability for per-tool call budgets (see §8). The synthetic `tool_result` carrying the "budget exceeded — pivot or finalize" body lands on the normal tool-result channel; this event is purely so SDK clients can surface a UI banner. |
427
+ | Type | Direction | Frequency | Purpose |
428
+ | ---------------------- | --------- | ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
429
+ | `assistant_delta` | M → SDK | Many | Streamed assistant text token / chunk. |
430
+ | `thinking_delta` | M → SDK | Many (iff `reasoningLevel > 0`) | Streamed extended-thinking text (provider redacts when policy requires). |
431
+ | `tool_result` | M → SDK | Per server-resolved tool call | Informational — tells the SDK that MANTYX ran a server-resolved tool (`mantyx`, `mantyx_plugin`, `a2a`, `mcp`) and got a result. The SDK does not need to act on it. |
432
+ | `tool_files` | M → SDK | Per server-resolved tool call that returns files | Informational metadata for files a server-resolved tool produced (see §4.2.1). Precedes the matching `tool_result`. Inline bytes are redacted from the stream; download via the admin route. |
433
+ | `local_tool_call` | M → SDK | Per client-resolved tool call | **Action required.** SDK must POST a tool-result. |
434
+ | `local_tool_result_in` | M → SDK | Per client-resolved tool call | Informational mirror of the tool-result the SDK just posted, persisted for observability. Re-emitted to late subscribers so they can replay the conversation. Any `files` carry only metadata on the wire (base64 `data` is redacted). |
435
+ | `loop_detected` | M → SDK | 0–2× per run (soft nudge + optional hard cutoff) | Observability for the loop-detection guard (see §8). The server already substituted the synthetic skip + steering nudge — SDK clients render a status note (`looping — nudged` / `looping — gave up`) and otherwise leave the run alone. |
436
+ | `tool_budget_exceeded` | M → SDK | Per intercepted tool call | Observability for per-tool call budgets (see §8). The synthetic `tool_result` carrying the "budget exceeded — pivot or finalize" body lands on the normal tool-result channel; this event is purely so SDK clients can surface a UI banner. |
435
437
  | `supervisor` | M → SDK | 0–N× per run (every `interval` LLM calls) | Run-supervisor check (see §4.7 / §8.4). Fired on **every** review — including `on_track` — so SDK clients can render supervisor activity. When the judge steers the run (`redirect` / `finalize`), the pipeline has already injected the steering message or forced a tools-disabled finalize turn. |
436
- | `task_plan` | M → SDK | 0–N× per run (iff `plan` set) | Observability for the in-product task plan (see §4.9 / §8.5). Emitted once after classify / caller-supplied plan, then again whenever the tracker advances step statuses. **Non-terminal.** For `planOnly` runs the final plan also rides on the terminal `result` under `data.plan`. |
437
- | `assistant_message` | M → SDK | 1× per turn | Final assistant message for the turn (concatenated, persistence-ready). |
438
- | `result` | M → SDK | 1× terminal | Successful completion. Carries the final assistant text and run summary. |
439
- | `error` | M → SDK | 1× terminal | Failure. Carries `error` (message), `code` / `errorClass` (category), `finishReason`, and an optional `partialText` salvage payload. See §4.7. |
440
- | `cancelled` | M → SDK | 1× terminal | Cancellation. Run was aborted via `POST /cancel`. |
438
+ | `task_plan` | M → SDK | 0–N× per run (iff `plan` set) | Observability for the in-product task plan (see §4.9 / §8.5). Emitted once after classify / caller-supplied plan, then again whenever the tracker advances step statuses. **Non-terminal.** For `planOnly` runs the final plan also rides on the terminal `result` under `data.plan`. |
439
+ | `assistant_message` | M → SDK | 1× per turn | Final assistant message for the turn (concatenated, persistence-ready). |
440
+ | `result` | M → SDK | 1× terminal | Successful completion. Carries the final assistant text and run summary. |
441
+ | `error` | M → SDK | 1× terminal | Failure. Carries `error` (message), `code` / `errorClass` (category), `finishReason`, and an optional `partialText` salvage payload. See §4.7. |
442
+ | `cancelled` | M → SDK | 1× terminal | Cancellation. Run was aborted via `POST /cancel`. |
441
443
 
442
444
  `result`, `error`, and `cancelled` are the **terminal** events — the SDK
443
445
  should close the SSE stream after one of them arrives.
@@ -470,6 +472,48 @@ progress text — it's not part of the canonical assistant response.
470
472
 
471
473
  Purely informational. The SDK does not respond.
472
474
 
475
+ ### 4.2.1 `tool_files` (server-resolved tool outputs)
476
+
477
+ Emitted when a **server-resolved** tool returns files alongside (or instead of)
478
+ text — e.g. a `mantyx` tool that renders a chart or exports a PDF. The bytes also
479
+ reach the model natively (as file parts), so this event is purely for
480
+ observability: it lets the Calls dashboard (and any SDK client that cares) list
481
+ and download a run's produced artifacts. It always precedes the matching
482
+ `tool_result` summary and shares its display `name`.
483
+
484
+ ```jsonc
485
+ {
486
+ "seq": 6,
487
+ "type": "tool_files",
488
+ "data": {
489
+ "name": "render_chart", // matches the paired tool_result `name`
490
+ "files": [
491
+ {
492
+ "filename": "chart.png",
493
+ "mimeType": "image/png",
494
+ "sizeBytes": 20480,
495
+ "storageKey": "chat-attachments/<tenant>/tool-results/<tool>/<uuid>.png",
496
+ },
497
+ ],
498
+ },
499
+ }
500
+ ```
501
+
502
+ | Field | Type | Notes |
503
+ | ------------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
504
+ | `filename` | string | Original filename. |
505
+ | `mimeType` | string | Content type. |
506
+ | `sizeBytes` | integer | Decoded byte length (`0` when only a pre-existing URI was available). |
507
+ | `storageKey` | string? | Object-store key when MANTYX persisted the bytes (the canonical case in production). Resolve via the admin download route; not a public URL. |
508
+ | `url` | string? | Public HTTPS URL when the tool itself returned a `file_uri` to a public file. |
509
+
510
+ When object storage is **not** configured (e.g. local dev), MANTYX inlines the
511
+ bytes as base64 on the persisted event row instead of a `storageKey`. That inline
512
+ `data` is **redacted from the SSE/stream payload** (only the metadata above is
513
+ sent); the bytes are served on demand by the admin download route. The
514
+ client-resolved equivalent (`local_tool_result_in.files`) is redacted the same
515
+ way.
516
+
473
517
  ### 4.3 `local_tool_call` (client-resolved tools)
474
518
 
475
519
  This is the workhorse event for SDK-implemented tools. Payload shape varies
@@ -703,14 +747,14 @@ See §8 for the wire-spec field that defines budgets.
703
747
  "data": { "action": "redirect", "phase": "reasoning", "reason": "Overthinking; looping on the same edge case.", "redirect": "Commit to the straightforward approach and answer.", "llmCalls": 7 } }
704
748
  ```
705
749
 
706
- | Field | Type | Notes |
707
- | ---------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
708
- | `action` | string | One of `"on_track"`, `"redirect"`, `"finalize"`. |
709
- | `reason` | string | One- or two-sentence explanation from the judge. |
710
- | `redirect` | string | Present when `action === "redirect"`: the steering message injected into the conversation (same text the agent sees as a user message). Omitted for `on_track` / `finalize`. |
711
- | `llmCalls` | integer | Number of LLM calls (`completeTurn` invocations) completed when this review fired. Matches the pipeline's `modelInvocations` counter at the check boundary. |
712
- | `phase` | string | Optional. `"turn_boundary"` (default cadence review) or `"reasoning"` (mid-turn review fired while a long reasoning span was still streaming). Absent is equivalent to `"turn_boundary"`. |
713
- | `model` | object | Optional. Resolved judge model (`{ id, provider, vendorModelId }`) — same shape as terminal `result.model` (§4.7.1). Present on platform-hosted runs for cost attribution and debug UIs. |
750
+ | Field | Type | Notes |
751
+ | ---------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
752
+ | `action` | string | One of `"on_track"`, `"redirect"`, `"finalize"`. |
753
+ | `reason` | string | One- or two-sentence explanation from the judge. |
754
+ | `redirect` | string | Present when `action === "redirect"`: the steering message injected into the conversation (same text the agent sees as a user message). Omitted for `on_track` / `finalize`. |
755
+ | `llmCalls` | integer | Number of LLM calls (`completeTurn` invocations) completed when this review fired. Matches the pipeline's `modelInvocations` counter at the check boundary. |
756
+ | `phase` | string | Optional. `"turn_boundary"` (default cadence review) or `"reasoning"` (mid-turn review fired while a long reasoning span was still streaming). Absent is equivalent to `"turn_boundary"`. |
757
+ | `model` | object | Optional. Resolved judge model (`{ id, provider, vendorModelId }`) — same shape as terminal `result.model` (§4.7.1). Present on platform-hosted runs for cost attribution and debug UIs. |
714
758
 
715
759
  Observability for the run-supervisor guard (see §8.4). The event fires on
716
760
  **every** check, not only when the judge intervenes — `on_track` reviews are
@@ -731,10 +775,16 @@ supervisor **off** on ephemeral API runs.
731
775
 
732
776
  ```jsonc
733
777
  // Every terminal `result` and `error` event also carries `tokens`, `turns`,
734
- // and `model` for cost attribution and dashboards — see §4.7.1.
778
+ // `model`, and `structuredOutput` — see below and §4.8.1.
735
779
  { "seq": 14, "type": "result", "data": {
736
- "ok": true,
780
+ "subtype": "success",
737
781
  "text": "...",
782
+ "structuredOutput": {
783
+ "schemaRequested": true,
784
+ "schemaEnforced": true,
785
+ "enforcementMechanism": "native_schema",
786
+ "unconstrainedFallbackOccurred": false
787
+ },
738
788
  "tokens": { "inputTokens": 1283, "cachedTokens": 512, "reasoningTokens": 96, "outputTokens": 240 },
739
789
  "turns": 3,
740
790
  "model": { "id": "platform:demo", "provider": "openai", "vendorModelId": "gpt-5.4-mini", "reasoningEffort": "low" }
@@ -746,6 +796,12 @@ supervisor **off** on ephemeral API runs.
746
796
  "finishReason": "max_tokens", // canonical lowercase stop reason
747
797
  "partialText": "{\n \"answer\":… (truncated JSON) …",
748
798
  "retryable": false, // optional; per-class retry hint
799
+ "structuredOutput": {
800
+ "schemaRequested": true,
801
+ "schemaEnforced": false,
802
+ "enforcementMechanism": "native_schema",
803
+ "unconstrainedFallbackOccurred": false
804
+ },
749
805
  "tokens": { "inputTokens": 8190, "cachedTokens": 0, "reasoningTokens": 0, "outputTokens": 1024 },
750
806
  "turns": 1,
751
807
  "model": { "id": "provider:cmf…", "provider": "google", "vendorModelId": "gemini-2.5-pro" }
@@ -760,14 +816,37 @@ SSE stream.
760
816
  with structured triage attributes when the failure carried a salvage path
761
817
  (typically truncation, upstream deadline, or max-budget-with-text):
762
818
 
763
- | Field | Type | Required | Notes |
764
- | -------------- | ------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
765
- | `error` | string | yes | Human-readable message (also persisted on `EphemeralAgentRun.error`). |
766
- | `code` | string | yes | Legacy alias for `errorClass`. Equals `errorClass` when present; otherwise a small lowercase token (`"error"`, `"invalid_spec"`, `"worker_error"`, …) the SDK can switch on. |
767
- | `errorClass` | string | no | Canonical category. One of `"rate_limit"`, `"overloaded"`, `"server"`, `"context_window"` (input too big), `"truncation"` (output budget exhausted), `"invalid_request"`, `"auth"`, `"timeout"`, `"local_timeout"`, `"upstream_deadline"`, `"unknown"`. New categories may land additively. |
768
- | `finishReason` | string\|null | no | Canonical lowercase stop reason normalized across providers (`"max_tokens"`, `"refusal"`, `"malformed_function_call"`, …). When present, mirrors the value on the last `assistant_message`. |
769
- | `partialText` | string | no | **Best-effort raw bytes** the model emitted before the failure. For `outputSchema` runs this is likely **incomplete JSON** that will fail `JSON.parse` — see §7 below. Also persisted on `EphemeralAgentRun.finalText` so the Calls UI can render it alongside a truncation banner. |
770
- | `retryable` | boolean | no | Coarse retry hint inherited from the pipeline's error classifier. Informational; the SDK still owns the actual retry decision. |
819
+ | Field | Type | Required | Notes |
820
+ | ------------------ | ------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
821
+ | `error` | string | yes | Human-readable message (also persisted on `EphemeralAgentRun.error`). |
822
+ | `code` | string | yes | Legacy alias for `errorClass`. Equals `errorClass` when present; otherwise a small lowercase token (`"error"`, `"invalid_spec"`, `"worker_error"`, …) the SDK can switch on. |
823
+ | `errorClass` | string | no | Canonical category. One of `"rate_limit"`, `"overloaded"`, `"server"`, `"context_window"` (input too big), `"truncation"` (output budget exhausted), `"invalid_request"`, `"auth"`, `"timeout"`, `"local_timeout"`, `"upstream_deadline"`, `"unknown"`. New categories may land additively. |
824
+ | `finishReason` | string\|null | no | Canonical lowercase stop reason normalized across providers (`"max_tokens"`, `"refusal"`, `"malformed_function_call"`, …). When present, mirrors the value on the last `assistant_message`. |
825
+ | `partialText` | string | no | **Best-effort raw bytes** the model emitted before the failure. For `outputSchema` runs this is likely **incomplete JSON** that will fail `JSON.parse` — see §7 below. Also persisted on `EphemeralAgentRun.finalText` so the Calls UI can render it alongside a truncation banner. |
826
+ | `retryable` | boolean | no | Coarse retry hint inherited from the pipeline's error classifier. Informational; the SDK still owns the actual retry decision. |
827
+ | `apiStatus` | integer | no | HTTP status returned by the model provider, when available. Preserved on structured-output schema rejection and other classified provider errors. |
828
+ | `apiCode` | string | no | Provider-specific error code, when available. This is distinct from MANTYX's canonical `code` / `errorClass`. |
829
+ | `structuredOutput` | object | yes | Actual structured-output execution state described below. New servers include it on terminal `result` and `error` events; SDKs treat omission as a legacy-server response. |
830
+
831
+ **`structuredOutput` execution metadata.** This block describes what the
832
+ runtime actually did, not merely what appeared in the request:
833
+
834
+ | Field | Type | Notes |
835
+ | ------------------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
836
+ | `schemaRequested` | boolean | `true` when the resolved run spec carried `outputSchema`. |
837
+ | `schemaEnforced` | boolean | `true` only when the successful provider call used a native schema, or the runtime captured the required synthetic final-result tool. |
838
+ | `enforcementMechanism` | string | `"native_schema"`, `"synthetic_tool"`, or `"none"`. On a rejection it records the attempted mechanism; after unconstrained fallback it is `"none"`. |
839
+ | `unconstrainedFallbackOccurred` | boolean | Run-level flag: `true` when any provider call retried or completed without the requested schema. Always `false` in strict mode. |
840
+
841
+ Without `outputSchema`, new servers emit
842
+ `{ schemaRequested: false, schemaEnforced: false, enforcementMechanism:
843
+ "none", unconstrainedFallbackOccurred: false }`.
844
+
845
+ `errorClass: "rate_limit"` specifically means the model provider throttled an
846
+ LLM request. The agent pipeline retries that provider failure before emitting a
847
+ terminal event. It is not the MANTYX Developer API HTTP limiter, which rejects
848
+ an incoming request immediately with HTTP 429 and
849
+ `code: "rate_limit_exceeded"` plus `Retry-After`.
771
850
 
772
851
  When `errorClass` is `"truncation"`, the `EphemeralAgentRun` row that the
773
852
  SDK can re-fetch via `GET /agent-runs/:runId` will have:
@@ -889,7 +968,7 @@ non-breaking since those return types were already objects).
889
968
  { "title": "Summarize the top drivers", "status": "pending" } ] } }
890
969
  ```
891
970
 
892
- | Field | Type | Notes |
971
+ | Field | Type | Notes |
893
972
  | ------- | ------ | ----------------------------------------------------------------------------------------------------- |
894
973
  | `brief` | string | Optional one-line summary of the overall objective. |
895
974
  | `steps` | array | Ordered checklist. Each `{ title, status }` where `status` is `"pending" \| "in_progress" \| "done"`. |
@@ -922,11 +1001,11 @@ Authorization: Bearer <api-key>
922
1001
  }
923
1002
  ```
924
1003
 
925
- | Field | Type | Required | Notes |
926
- | ----------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------ |
927
- | `toolUseId` | string | yes | Must match a pending `local_tool_call`'s id. |
928
- | `result` | string | one-of | Successful textual result (≤ 2 MB). For MCP tools, flatten content blocks to text. For A2A delegations, the peer's reply text. |
929
- | `error` | string | one-of | Human-readable failure message (≤ 8 KB). Surfaced to the model so it can recover. |
1004
+ | Field | Type | Required | Notes |
1005
+ | ----------- | ------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1006
+ | `toolUseId` | string | yes | Must match a pending `local_tool_call`'s id. |
1007
+ | `result` | string | one-of | Successful textual result (≤ 2 MB). For MCP tools, flatten content blocks to text. For A2A delegations, the peer's reply text. |
1008
+ | `error` | string | one-of | Human-readable failure message (≤ 8 KB). Surfaced to the model so it can recover. |
930
1009
  | `files` | array | no | Files the client-resolved tool produced, surfaced to the model on the next turn as native file parts (Anthropic / Gemini / Bedrock inside `tool_result`; OpenAI as a synthetic follow-up user turn). Each entry is `{ filename, mimeType, data }` with `data` base64 (no data-URL prefix). Only honored alongside `result`; ignored when `error` is set. `mimeType` must be an allowed attachment type. Up to 20 files; combined decoded bytes are capped (currently 5 MB), and large files are persisted to object storage and forwarded by reference. For bigger artifacts, upload out of band and reference a URL in `result`. |
931
1010
 
932
1011
  Server response codes:
@@ -972,22 +1051,41 @@ will include `thinking_delta` events alongside `assistant_delta`.
972
1051
 
973
1052
  ## 7. `outputSchema` (structured final reply)
974
1053
 
975
- `outputSchema` constrains the final assistant message to a JSON document
976
- conforming to a JSON Schema. When set, the run's terminal `result` event
977
- still carries the reply as `data.text: string`, but that string is
978
- guaranteed-parseable JSON matching the supplied schema.
1054
+ `outputSchema` asks the provider to constrain the final assistant message to a
1055
+ JSON document conforming to a JSON Schema. The terminal `result` event still
1056
+ carries the reply as `data.text: string`. Use `enforcement: "strict"` when a
1057
+ caller must fail instead of accepting a provider rejection, an unsupported
1058
+ provider, or an unconstrained result.
979
1059
 
980
1060
  ```jsonc
981
1061
  "outputSchema": {
982
1062
  "name": "weather_report", // optional; default "output"; /^[a-zA-Z0-9_-]{1,64}$/
983
- "schema": { /* JSON Schema */ } // required, root must be a JSON object
1063
+ "schema": { /* JSON Schema */ }, // required, root must be a JSON object
1064
+ "enforcement": "strict" // optional; default "best_effort"
984
1065
  }
985
1066
  ```
986
1067
 
987
- | Field | Type | Required | Notes |
988
- | -------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
989
- | `name` | string | no | Stable identifier passed to providers (OpenAI `text.format.name`, Anthropic synthetic-tool name). Defaults to `"output"`. |
990
- | `schema` | object | yes | JSON Schema for the assistant text. Root must be a JSON object — most providers reject array/scalar roots in structured-output mode. Passed through verbatim; MANTYX does not validate the schema's contents. |
1068
+ | Field | Type | Required | Notes |
1069
+ | ------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1070
+ | `name` | string | no | Stable identifier passed to providers (OpenAI `text.format.name`, Anthropic synthetic-tool name). Defaults to `"output"`. |
1071
+ | `schema` | object | yes | JSON Schema for the assistant text. Root must be a JSON object — most providers reject array/scalar roots in structured-output mode. Passed through verbatim; MANTYX does not validate the schema's contents. |
1072
+ | `enforcement` | string | no | `"best_effort"` (default) preserves the historical fallback behavior. `"strict"` requires actual enforcement and forbids an unconstrained retry. |
1073
+
1074
+ **Enforcement modes:**
1075
+
1076
+ - `best_effort` is the backward-compatible default. When OpenAI or Gemini
1077
+ rejects the schema request, MANTYX may memoize that incompatibility and retry
1078
+ without the schema. The run may still succeed; inspect
1079
+ `structuredOutput.schemaEnforced` and
1080
+ `unconstrainedFallbackOccurred` before treating it as provider compatibility.
1081
+ - `strict` never retries without the schema, never consults or writes the
1082
+ best-effort unsupported-schema memo, and never silently ignores the schema.
1083
+ Provider rejection terminates with
1084
+ `errorClass: "structured_output_schema_rejected"` while preserving
1085
+ `apiStatus`, `apiCode`, and the provider message. A provider/model with no
1086
+ enforcement path fails as `structured_output_not_supported`; bypassing a
1087
+ required synthetic final-result tool fails as
1088
+ `structured_output_not_enforced`.
991
1089
 
992
1090
  Per provider:
993
1091
 
@@ -998,13 +1096,23 @@ Per provider:
998
1096
  | Gemini ≤ 2.5 with no tools | Same as Gemini 3+: `responseMimeType: "application/json"` + `responseJsonSchema`. |
999
1097
  | Gemini ≤ 2.5 **with tools** | Synthetic `set_model_response` function declaration is injected; its `parametersJsonSchema` is the supplied schema. The system instruction is augmented to direct the model to call this tool with the final answer. The engine intercepts the call, hides it from the SDK, and surfaces the call's arguments as the assistant text (JSON-stringified). Sidesteps the API rejection ("Function calling with a response mime type: 'application/json' is unsupported") without round-tripping a 4xx. |
1000
1098
  | Anthropic / Bedrock-Anthropic | Synthetic `final_report` tool whose `input_schema` is the supplied schema; `tool_choice` is forced on the no-tools finishing turn. The tool's input is surfaced as the assistant text. |
1001
- | xAI Grok, others | Ignored — the model returns plain text. |
1099
+ | xAI Grok, others | Best effort may return plain text and reports `enforcementMechanism: "none"`. Strict mode fails explicitly instead of calling this a schema-enforced success. |
1002
1100
 
1003
1101
  The synthetic-tool paths (Gemini 2.5 + tools, Anthropic) are entirely
1004
1102
  internal: the SDK still receives `data.text: string` on the terminal
1005
1103
  `result` event and never sees a `local_tool_call` for `set_model_response`
1006
1104
  or `final_report`. They never appear in the tools array the SDK declared.
1007
1105
 
1106
+ Every terminal `result` and `error` includes the `structuredOutput` block from
1107
+ §4.8. A strict compatibility test succeeds only when `schemaRequested` and
1108
+ `schemaEnforced` are both `true`,
1109
+ `unconstrainedFallbackOccurred` is `false`, and the mechanism is the expected
1110
+ provider path.
1111
+
1112
+ `plan: { planOnly: true }` does not execute the agent loop and therefore cannot
1113
+ enforce a run-level output schema. Combining it with strict enforcement
1114
+ terminates explicitly as `structured_output_not_supported`.
1115
+
1008
1116
  Validation (server-side, `400 invalid_request` on violation):
1009
1117
 
1010
1118
  | Constraint | Limit |
@@ -1134,10 +1242,9 @@ entries are layered on top so per-run overrides win):
1134
1242
  | ---------------------------------------------------------------------------------------- | ------------------ |
1135
1243
  | `recall` (workspace memory hybrid search) | `4` |
1136
1244
  | `traverse` (memory graph BFS) | `3` |
1137
- | `hive_consult_ontology` (per-hive ontology read; same name across all three hives) | `4` |
1245
+ | `hive_consult_ontology` (per-hive ontology read; same name across both active hives) | `4` |
1138
1246
  | `hive_search_deals` / `_meetings` / `_companies` / `_people` (Sales Hive general search) | `5` |
1139
1247
  | `hive_search_tickets` / `_conversations` / `_accounts` (Customer Hive general search) | `5` |
1140
- | `hive_search_releases` / `_issues` (Product Hive general search) | `5` |
1141
1248
 
1142
1249
  Pass `"toolBudgets": {}` to start from a clean slate (no defaults applied
1143
1250
  on top — useful for runs that intentionally want unbounded research). When
@@ -1170,18 +1277,18 @@ An optional LLM **run supervisor** periodically reviews the agent's
1170
1277
  transcript (reasoning, tool calls, tool results, visible text) and may
1171
1278
  steer the run:
1172
1279
 
1173
- | Verdict | Server action |
1174
- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
1175
- | `on_track` | No-op — the run continues unchanged. |
1176
- | `redirect` | A steering **user message** is injected; tools stay available on the next turn. |
1177
- | `finalize` | The next turn is forced **tools-disabled** so the run lands a clean final answer (optionally prefaced by the supervisor's message). |
1280
+ | Verdict | Server action |
1281
+ | ---------- | ----------------------------------------------------------------------------------------------------------------------------------- |
1282
+ | `on_track` | No-op — the run continues unchanged. |
1283
+ | `redirect` | A steering **user message** is injected; tools stay available on the next turn. |
1284
+ | `finalize` | The next turn is forced **tools-disabled** so the run lands a clean final answer (optionally prefaced by the supervisor's message). |
1178
1285
 
1179
1286
  Reviews fire on two triggers:
1180
1287
 
1181
1288
  - **Cadence** — every **`interval` LLM calls** (`completeTurn` invocations),
1182
1289
  measured at the bottom of tool-emitting rounds (`phase: "turn_boundary"`).
1183
1290
  Default interval is **5** when the field is omitted.
1184
- - **Mid-turn reasoning** — while a *single* turn is still streaming reasoning,
1291
+ - **Mid-turn reasoning** — while a _single_ turn is still streaming reasoning,
1185
1292
  once the current reasoning span crosses **3000 characters or 30s** (whichever
1186
1293
  first), a `phase: "reasoning"` review runs on the in-progress reasoning. A
1187
1294
  `redirect` / `finalize` verdict **aborts the in-flight turn** and steers the
@@ -1206,13 +1313,13 @@ Reviews fire on two triggers:
1206
1313
  "supervisor": false // explicitly disable (same as omitting the field)
1207
1314
  ```
1208
1315
 
1209
- | Field | Type | Notes |
1210
- | ---------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
1211
- | (literal `true`) | `true` | Enables the run supervisor with platform defaults (`interval` 5, reasoning trigger 3000 chars / 30s, workspace judge model). |
1212
- | `interval` | integer ≥ 1 | Optional. Default **5** when omitted. Capped at **100** server-side. |
1213
- | `modelId` | string | Optional. Same selector grammar as top-level `modelId` (§2). When omitted, the platform resolves the judge model from the workspace default supervisor model, then the workspace default model. |
1214
- | `reasoningTrigger` | `false` \| `{ chars?, ms? }` | Optional. Mid-turn reasoning trigger. Defaults to `{ chars: 3000, ms: 30000 }`. `chars` capped at 50000, `ms` at 600000. Pass `false` to only review at tool-round boundaries. |
1215
- | (literal `false`) | `false` | Disables the run supervisor for this run. Loop detection and tool budgets still apply. |
1316
+ | Field | Type | Notes |
1317
+ | ------------------ | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1318
+ | (literal `true`) | `true` | Enables the run supervisor with platform defaults (`interval` 5, reasoning trigger 3000 chars / 30s, workspace judge model). |
1319
+ | `interval` | integer ≥ 1 | Optional. Default **5** when omitted. Capped at **100** server-side. |
1320
+ | `modelId` | string | Optional. Same selector grammar as top-level `modelId` (§2). When omitted, the platform resolves the judge model from the workspace default supervisor model, then the workspace default model. |
1321
+ | `reasoningTrigger` | `false` \| `{ chars?, ms? }` | Optional. Mid-turn reasoning trigger. Defaults to `{ chars: 3000, ms: 30000 }`. `chars` capped at 50000, `ms` at 600000. Pass `false` to only review at tool-round boundaries. |
1322
+ | (literal `false`) | `false` | Disables the run supervisor for this run. Loop detection and tool budgets still apply. |
1216
1323
 
1217
1324
  **Model resolution.** When the supervisor is enabled, the judge model is chosen in order:
1218
1325
 
@@ -1256,31 +1363,43 @@ features add extra LLM calls.
1256
1363
  "plan": false // (or omit) no planning — a plain run
1257
1364
  ```
1258
1365
 
1259
- | Form | Behavior |
1260
- | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
1261
- | omitted / `false` | No planning. Default. |
1262
- | `true` | Pre-flight classifier decides whether a multi-step plan is warranted. If so, a `task_plan` event is emitted, the checklist is injected into the user turn, and step statuses are tracked (advancing on tool activity and on each supervisor review) until the run ends. If the classifier declines, the run proceeds normally with no plan. |
1263
- | `{ steps, brief? }` | Caller-provided checklist used verbatim — **skips** the classifier (and its `MIN_STEPS` gate). Injected + tracked like the auto case. |
1264
- | `{ planOnly: true, steps? }` | Produce the plan (classifier when `steps` omitted, otherwise the provided checklist) and **terminate without executing the agent loop**. |
1366
+ | Form | Behavior |
1367
+ | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1368
+ | omitted / `false` | No planning. Default. |
1369
+ | `true` | Pre-flight classifier decides whether a multi-step plan is warranted. If so, a `task_plan` event is emitted, the checklist is injected into the user turn, and step statuses are tracked (advancing on tool activity and on each supervisor review) until the run ends. If the classifier declines, the run proceeds normally with no plan. |
1370
+ | `{ steps, brief? }` | Caller-provided checklist used verbatim — **skips** the classifier (and its `MIN_STEPS` gate). Injected + tracked like the auto case. |
1371
+ | `{ planOnly: true, steps? }` | Produce the plan (classifier when `steps` omitted, otherwise the provided checklist) and **terminate without executing the agent loop**. |
1265
1372
 
1266
- | Field | Type | Notes |
1267
- | ---------- | -------- | -------------------------------------------------------------------------------------------------------------------- |
1268
- | `planOnly` | boolean | Optional. When `true`, the run stops after producing the plan; the terminal `result` carries it under `data.plan`. |
1269
- | `brief` | string | Optional one-line objective for a caller-provided plan. Clamped server-side. |
1270
- | `steps` | string[] | Optional caller-provided checklist titles. Empty/omitted ⇒ auto-classify. Count and per-step length clamped server-side. |
1271
- | (literal `true`) | `true` | Auto pre-flight classifier + live tracking. |
1373
+ | Field | Type | Notes |
1374
+ | ---------------- | -------- | ------------------------------------------------------------------------------------------------------------------------ |
1375
+ | `planOnly` | boolean | Optional. When `true`, the run stops after producing the plan; the terminal `result` carries it under `data.plan`. |
1376
+ | `brief` | string | Optional one-line objective for a caller-provided plan. Clamped server-side. |
1377
+ | `steps` | string[] | Optional caller-provided checklist titles. Empty/omitted ⇒ auto-classify. Count and per-step length clamped server-side. |
1378
+ | (literal `true`) | `true` | Auto pre-flight classifier + live tracking. |
1272
1379
 
1273
1380
  **Plan-only terminal shape.** A `planOnly` run terminates with the normal
1274
1381
  terminal `result` event (§4.8), plus a structured `plan`:
1275
1382
 
1276
1383
  ```jsonc
1277
- { "seq": 5, "type": "result",
1278
- "data": { "subtype": "success",
1279
- "text": "Migrate the billing tables and backfill\n\n1. Snapshot current schema\n2. Apply migration\n3. Backfill rows\n4. Verify counts",
1280
- "plan": { "brief": "Migrate the billing tables and backfill",
1281
- "steps": [ { "title": "Snapshot current schema", "status": "pending" }, /* … */ ] },
1282
- "tokens": { /* zeroed — classifier usage is metered separately */ },
1283
- "turns": 0, "model": { "id": "…", "provider": "…", "vendorModelId": "…" } } }
1384
+ {
1385
+ "seq": 5,
1386
+ "type": "result",
1387
+ "data": {
1388
+ "subtype": "success",
1389
+ "text": "Migrate the billing tables and backfill\n\n1. Snapshot current schema\n2. Apply migration\n3. Backfill rows\n4. Verify counts",
1390
+ "plan": {
1391
+ "brief": "Migrate the billing tables and backfill",
1392
+ "steps": [
1393
+ { "title": "Snapshot current schema", "status": "pending" } /* … */,
1394
+ ],
1395
+ },
1396
+ "tokens": {
1397
+ /* zeroed — classifier usage is metered separately */
1398
+ },
1399
+ "turns": 0,
1400
+ "model": { "id": "…", "provider": "…", "vendorModelId": "…" },
1401
+ },
1402
+ }
1284
1403
  ```
1285
1404
 
1286
1405
  When the classifier declines in plan-only mode, `data.plan.steps` is `[]` and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mantyx/sdk",
3
- "version": "0.24.0",
3
+ "version": "2026.9.2",
4
4
  "description": "MANTYX as a hosted agent runtime: define ephemeral agents, mix server-side MANTYX tools with locally-executed tools, run them remotely.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -28,24 +28,14 @@
28
28
  "docs",
29
29
  "README.md",
30
30
  "CHANGELOG.md",
31
- "CONTRIBUTING.md",
32
- "EXTRACT.md"
31
+ "LICENSE"
33
32
  ],
34
- "scripts": {
35
- "sync-version": "node ../scripts/sync-version.mjs",
36
- "build": "tsup --config tsup.config.ts && tsc -p tsconfig.build.json",
37
- "dev": "tsup --config tsup.config.ts --watch",
38
- "typecheck": "tsc --noEmit",
39
- "test": "vitest run",
40
- "test:watch": "vitest",
41
- "prepublishOnly": "npm run build"
42
- },
43
33
  "engines": {
44
34
  "node": ">=18.17.0"
45
35
  },
46
36
  "dependencies": {
47
- "@modelcontextprotocol/sdk": "^1.29.0",
48
- "zod": "^4.4.3"
37
+ "@modelcontextprotocol/sdk": "^1.30.0",
38
+ "zod": "^4.6.5"
49
39
  },
50
40
  "peerDependencies": {
51
41
  "@a2a-js/sdk": "^0.3.0",
@@ -66,12 +56,12 @@
66
56
  "devDependencies": {
67
57
  "@a2a-js/sdk": "^0.3.14",
68
58
  "@types/express": "^5.0.6",
69
- "@types/node": "^26.1.1",
59
+ "@types/node": "^26.6.1",
70
60
  "express": "^5.2.1",
71
61
  "playwright": "^1.61.1",
72
62
  "tsup": "^8.5.1",
73
- "typescript": "^7.0.2",
74
- "vitest": "^4.1.10"
63
+ "typescript": "~7.0.2",
64
+ "vitest": "^4.1.11"
75
65
  },
76
66
  "keywords": [
77
67
  "mantyx",
@@ -85,5 +75,14 @@
85
75
  "license": "Apache-2.0",
86
76
  "publishConfig": {
87
77
  "access": "public"
78
+ },
79
+ "homepage": "https://mantyx-io.github.io/mantyx-sdk/",
80
+ "scripts": {
81
+ "sync-version": "node ../scripts/sync-version.mjs",
82
+ "build": "tsup --config tsup.config.ts && tsc -p tsconfig.build.json",
83
+ "dev": "tsup --config tsup.config.ts --watch",
84
+ "typecheck": "tsc --noEmit",
85
+ "test": "vitest run",
86
+ "test:watch": "vitest"
88
87
  }
89
- }
88
+ }
package/CONTRIBUTING.md DELETED
@@ -1,72 +0,0 @@
1
- # Contributing to `@mantyx/sdk`
2
-
3
- Thanks for considering a contribution! This SDK is a small, dependency-light
4
- client for the [MANTYX](https://mantyx.com) agent-runs HTTP/SSE protocol; the
5
- goal is to keep it that way.
6
-
7
- ## Ground rules
8
-
9
- 1. **Public-protocol only.** The SDK MUST NOT depend on any MANTYX-internal
10
- package, type, or repository layout. Anything it does is a side effect of
11
- sending HTTP requests against the public protocol documented in
12
- [`docs/agent-runs-protocol.md`](./docs/agent-runs-protocol.md).
13
- 2. **No `workspace:*`.** The SDK ships to npm as a standalone package. Pull
14
- requests that introduce a `workspace:*` dependency in `package.json` will
15
- not be merged.
16
- 3. **Tiny dep tree.** The only runtime dependency today is `zod`. Adding a
17
- new runtime dependency requires a strong justification.
18
- 4. **Standalone tests.** `pnpm test` must pass with `node_modules/` populated
19
- from this package's own `package.json`, with no MANTYX server running.
20
- 5. **Backwards compatibility.** Bump the SDK version per
21
- [SemVer](https://semver.org/spec/v2.0.0.html). Breaking changes need a
22
- major version bump and a `CHANGELOG.md` entry.
23
-
24
- ## Local setup
25
-
26
- ```bash
27
- pnpm install
28
- pnpm test
29
- pnpm typecheck
30
- pnpm build
31
- ```
32
-
33
- The repository is a pnpm monorepo, but this package is a leaf with no
34
- internal consumers, so it is safe to develop in isolation.
35
-
36
- ## Adding tests
37
-
38
- Tests live under [`test/`](./test) and use Vitest. Network calls are routed
39
- through the in-process mock server in
40
- [`test/helpers/mock-server.ts`](./test/helpers/mock-server.ts) — extend it
41
- when you need to exercise a new server behaviour rather than reaching out to
42
- a real MANTYX instance.
43
-
44
- When fixing a bug, prefer a regression test against the mock server. When
45
- adding a feature, add an example under [`examples/`](./examples) that
46
- exercises it end-to-end.
47
-
48
- ## Style
49
-
50
- - TypeScript strict mode. No `any` unless there's no choice.
51
- - Public types are re-exported from [`src/index.ts`](./src/index.ts). Keep
52
- the public surface minimal and well-typed.
53
- - Use `MantyxError` (and its subclasses) for thrown errors so callers can
54
- branch on `instanceof`.
55
- - Prefer the Web `fetch` / `ReadableStream` APIs over Node-only modules so
56
- the SDK keeps working in edge / browser-like runtimes.
57
-
58
- ## Pull requests
59
-
60
- 1. Fork and create a feature branch.
61
- 2. Add or update tests.
62
- 3. `pnpm test && pnpm typecheck && pnpm build`.
63
- 4. Use [Conventional Commits](https://www.conventionalcommits.org/) with scope `ts` — `CHANGELOG.md` is regenerated from git history on release (do not edit it by hand).
64
- 5. Open a PR. Describe the change and any protocol implications.
65
-
66
- ## Releasing
67
-
68
- Releases are handled by the shared **Publish** GitHub Actions workflow on `main` (lockstep across all three SDKs). See the [top-level CONTRIBUTING.md](../CONTRIBUTING.md#releasing). The npm tag is `vX.Y.Z`; do not publish or tag manually from this package.
69
-
70
- ## Code of Conduct
71
-
72
- Be kind. Assume good intent. Be patient with reviewers and maintainers.