@mantyx/sdk 0.11.0 → 0.12.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.
@@ -843,6 +843,22 @@ interface AgentSpecBase {
843
843
  * `docs/agent-runs-protocol.md` §4.7.
844
844
  */
845
845
  toolBudgets?: ToolBudgets;
846
+ /**
847
+ * Run-supervisor (platform LLM judge). Periodically reviews the agent's
848
+ * transcript and may steer the run (`on_track`, `redirect`, `finalize`).
849
+ *
850
+ * Pass an object to override the review interval, or `false` to explicitly
851
+ * disable the platform judge for this run / session. When omitted on
852
+ * ephemeral API runs, MANTYX enables the supervisor (default interval `5`).
853
+ * SDK-only runs (`runAgent` without the HTTP API) keep the supervisor off
854
+ * unless you pass a value here. See `docs/agent-runs-protocol.md` §4.8.
855
+ *
856
+ * Each review emits an observability-only `supervisor` SSE event — including
857
+ * `on_track` checks — so the SDK can render supervisor activity. When
858
+ * `action` is `redirect` or `finalize`, the pipeline has already applied
859
+ * the verdict by the time the event arrives.
860
+ */
861
+ supervisor?: Supervisor | false;
846
862
  /**
847
863
  * Flat string→string KV carried alongside the run / session for
848
864
  * observability. Use it to tag runs with your own application identifiers
@@ -925,6 +941,20 @@ interface ToolBudget {
925
941
  * entirely to keep the defaults.
926
942
  */
927
943
  type ToolBudgets = Record<string, ToolBudget>;
944
+ /**
945
+ * Run-supervisor configuration. See {@link AgentSpecBase.supervisor} for the
946
+ * full semantics. Pass `false` (instead of an object) to disable the platform
947
+ * judge for the run / session.
948
+ *
949
+ * `interval` is optional; when omitted the MANTYX runtime default is **5**
950
+ * LLM calls between reviews. Server-side upper bound: `100`.
951
+ */
952
+ interface Supervisor {
953
+ /** LLM calls (`completeTurn` invocations) between supervisor reviews. */
954
+ interval?: number;
955
+ }
956
+ /** Verdict from a run-supervisor review. */
957
+ type SupervisorAction = "on_track" | "redirect" | "finalize";
928
958
  /**
929
959
  * Per-run token totals attached to terminal `result` / `error` events
930
960
  * (and to the `GET /agent-runs/:runId` snapshot) by MANTYX ≥ 2026-09.
@@ -1164,6 +1194,30 @@ interface ToolBudgetExceededEvent extends RunEventBase {
1164
1194
  */
1165
1195
  callIndex: number;
1166
1196
  }
1197
+ /**
1198
+ * Observability event fired on every run-supervisor review — including
1199
+ * `on_track` checks. When `action` is `redirect` or `finalize`, the pipeline
1200
+ * has already injected the steering message or forced a tools-disabled turn
1201
+ * by the time this event arrives; the SDK should render a status note and
1202
+ * keep consuming the stream.
1203
+ */
1204
+ interface SupervisorEvent extends RunEventBase {
1205
+ type: "supervisor";
1206
+ /** One of `"on_track"`, `"redirect"`, `"finalize"`. */
1207
+ action: SupervisorAction;
1208
+ /** One- or two-sentence explanation from the judge. */
1209
+ reason: string;
1210
+ /**
1211
+ * Present when `action === "redirect"`: the steering user message injected
1212
+ * into the conversation. Omitted for `on_track` / `finalize`.
1213
+ */
1214
+ redirect?: string;
1215
+ /**
1216
+ * Number of LLM calls completed when this review fired. Matches the
1217
+ * pipeline's `modelInvocations` counter at the check boundary.
1218
+ */
1219
+ llmCalls: number;
1220
+ }
1167
1221
  interface ResultEvent extends RunEventBase {
1168
1222
  type: "result";
1169
1223
  subtype: string;
@@ -1233,7 +1287,7 @@ interface CancelledEvent extends RunEventBase {
1233
1287
  type: "cancelled";
1234
1288
  reason?: string;
1235
1289
  }
1236
- type RunEvent = AssistantDeltaEvent | ThinkingDeltaEvent | AssistantMessageEvent | ServerToolResultEvent | LocalToolCallEvent | LocalToolResultInEvent | LoopDetectedEvent | ToolBudgetExceededEvent | ResultEvent | ErrorEvent | CancelledEvent | (RunEventBase & {
1290
+ type RunEvent = AssistantDeltaEvent | ThinkingDeltaEvent | AssistantMessageEvent | ServerToolResultEvent | LocalToolCallEvent | LocalToolResultInEvent | LoopDetectedEvent | ToolBudgetExceededEvent | SupervisorEvent | ResultEvent | ErrorEvent | CancelledEvent | (RunEventBase & {
1237
1291
  type: string;
1238
1292
  [key: string]: unknown;
1239
1293
  });
@@ -1376,6 +1430,12 @@ declare class AgentSession {
1376
1430
  * and does not mutate the session's stored value.
1377
1431
  */
1378
1432
  toolBudgets?: ToolBudgets;
1433
+ /**
1434
+ * Per-message override for `supervisor`. Applies only to this run
1435
+ * and does not mutate the session's stored value. Pass `false` to
1436
+ * disable the platform judge for this single turn.
1437
+ */
1438
+ supervisor?: Supervisor | false;
1379
1439
  }): Promise<RunResult>;
1380
1440
  stream(prompt: string, opts?: {
1381
1441
  signal?: AbortSignal;
@@ -1384,6 +1444,7 @@ declare class AgentSession {
1384
1444
  outputSchema?: OutputSchema;
1385
1445
  loopDetection?: LoopDetection | false;
1386
1446
  toolBudgets?: ToolBudgets;
1447
+ supervisor?: Supervisor | false;
1387
1448
  }): AsyncGenerator<RunEvent, void, void>;
1388
1449
  private buildSessionMessageBody;
1389
1450
  history(): Promise<Array<{
@@ -1434,4 +1495,4 @@ interface LocalHandlers {
1434
1495
  */
1435
1496
  declare function parseRunOutput<T = unknown>(result: RunResult, validator?: (value: unknown) => T): T;
1436
1497
 
1437
- export { type RunEvent as $, type A2AToolRef as A, MantyxOAuthError as B, type CancelledEvent as C, DEFAULT_BASE_URL as D, type ErrorEvent as E, MantyxParseError as F, type MantyxPluginToolRef as G, MantyxRunError as H, type MantyxRunErrorInit as I, type MantyxRunErrorModel as J, type MantyxRunErrorTokens as K, type LocalA2ATool as L, MantyxClient as M, MantyxScopeError as N, MantyxToolError as O, type MantyxToolRef as P, type McpToolRef as Q, type ReasoningLevel as R, type ModelCatalog as S, type ToolRef as T, type ModelInfo as U, type OAuthToken as V, type OutputSchema as W, type RefreshOptions as X, type RefreshTokenSourceOptions as Y, type ResultEvent as Z, type RevokeOptions as _, AgentSession as a, type RunEventBase as a0, type RunModelInfo as a1, type RunResult as a2, type RunSpec as a3, type RunTokenUsage as a4, type ServerToolResultEvent as a5, type SessionInfo as a6, type SessionSpec as a7, type ThinkingDeltaEvent as a8, type TokenRequestReason as a9, type TokenSource as aa, type ToolBudget as ab, type ToolBudgetExceededEvent as ac, type ToolBudgets as ad, type ZodLikeObject as ae, defineLocalA2A as af, defineLocalMcp as ag, defineLocalTool as ah, isLocalA2ATool as ai, isLocalMcpServer as aj, isLocalTool as ak, mantyxA2A as al, mantyxMcp as am, mantyxPluginTool as an, mantyxTool as ao, parseRunOutput as ap, type AgentSpecBase as b, type AssistantDeltaEvent as c, type AssistantMessageEvent as d, DEFAULT_OAUTH_BASE_URL as e, DEFAULT_REFRESH_SKEW_MS as f, type DefineLocalA2AOptions as g, type DefineLocalMcpOptions as h, type DefineLocalToolOptions as i, type LocalHandlers as j, type LocalMcpHttpTransport as k, type LocalMcpServer as l, type LocalMcpStdioTransport as m, type LocalTool as n, type LocalToolCallEvent as o, type LocalToolResultInEvent as p, type LoopDetectedEvent as q, type LoopDetection as r, type MantyxA2AOptions as s, MantyxAuthError as t, type MantyxClientOptions as u, MantyxError as v, type MantyxMcpOptions as w, MantyxNetworkError as x, MantyxOAuthClient as y, type MantyxOAuthClientOptions as z };
1498
+ export { type RunEvent as $, type A2AToolRef as A, MantyxOAuthError as B, type CancelledEvent as C, DEFAULT_BASE_URL as D, type ErrorEvent as E, MantyxParseError as F, type MantyxPluginToolRef as G, MantyxRunError as H, type MantyxRunErrorInit as I, type MantyxRunErrorModel as J, type MantyxRunErrorTokens as K, type LocalA2ATool as L, MantyxClient as M, MantyxScopeError as N, MantyxToolError as O, type MantyxToolRef as P, type McpToolRef as Q, type ReasoningLevel as R, type ModelCatalog as S, type ToolRef as T, type ModelInfo as U, type OAuthToken as V, type OutputSchema as W, type RefreshOptions as X, type RefreshTokenSourceOptions as Y, type ResultEvent as Z, type RevokeOptions as _, AgentSession as a, type RunEventBase as a0, type RunModelInfo as a1, type RunResult as a2, type RunSpec as a3, type RunTokenUsage as a4, type ServerToolResultEvent as a5, type SessionInfo as a6, type SessionSpec as a7, type Supervisor as a8, type SupervisorAction as a9, type SupervisorEvent as aa, type ThinkingDeltaEvent as ab, type TokenRequestReason as ac, type TokenSource as ad, type ToolBudget as ae, type ToolBudgetExceededEvent as af, type ToolBudgets as ag, type ZodLikeObject as ah, defineLocalA2A as ai, defineLocalMcp as aj, defineLocalTool as ak, isLocalA2ATool as al, isLocalMcpServer as am, isLocalTool as an, mantyxA2A as ao, mantyxMcp as ap, mantyxPluginTool as aq, mantyxTool as ar, parseRunOutput as as, type AgentSpecBase as b, type AssistantDeltaEvent as c, type AssistantMessageEvent as d, DEFAULT_OAUTH_BASE_URL as e, DEFAULT_REFRESH_SKEW_MS as f, type DefineLocalA2AOptions as g, type DefineLocalMcpOptions as h, type DefineLocalToolOptions as i, type LocalHandlers as j, type LocalMcpHttpTransport as k, type LocalMcpServer as l, type LocalMcpStdioTransport as m, type LocalTool as n, type LocalToolCallEvent as o, type LocalToolResultInEvent as p, type LoopDetectedEvent as q, type LoopDetection as r, type MantyxA2AOptions as s, MantyxAuthError as t, type MantyxClientOptions as u, MantyxError as v, type MantyxMcpOptions as w, MantyxNetworkError as x, MantyxOAuthClient as y, type MantyxOAuthClientOptions as z };
package/dist/index.cjs CHANGED
@@ -1102,6 +1102,9 @@ var AgentSession = class {
1102
1102
  if (opts.toolBudgets !== void 0) {
1103
1103
  body.toolBudgets = normalizeToolBudgets(opts.toolBudgets);
1104
1104
  }
1105
+ if (opts.supervisor !== void 0) {
1106
+ body.supervisor = normalizeSupervisor(opts.supervisor);
1107
+ }
1105
1108
  return body;
1106
1109
  }
1107
1110
  async history() {
@@ -1142,6 +1145,9 @@ function serializeAgentSpec(spec, extra = {}) {
1142
1145
  if (spec.toolBudgets !== void 0) {
1143
1146
  body.toolBudgets = normalizeToolBudgets(spec.toolBudgets);
1144
1147
  }
1148
+ if (spec.supervisor !== void 0) {
1149
+ body.supervisor = normalizeSupervisor(spec.supervisor);
1150
+ }
1145
1151
  if (spec.budgets) body.budgets = spec.budgets;
1146
1152
  if (spec.metadata && Object.keys(spec.metadata).length > 0) body.metadata = spec.metadata;
1147
1153
  if (extra.prompt !== void 0) body.prompt = extra.prompt;
@@ -1346,6 +1352,19 @@ function assertThreshold(label, value, min) {
1346
1352
  var TOOL_BUDGETS_MAX_ENTRIES = 32;
1347
1353
  var TOOL_BUDGET_MAX_NAME_LEN = 120;
1348
1354
  var TOOL_BUDGET_MAX_CALLS = 1e3;
1355
+ function normalizeSupervisor(value) {
1356
+ if (value === false) return false;
1357
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
1358
+ throw new MantyxError(
1359
+ `supervisor must be an object or the literal \`false\`, got ${JSON.stringify(value)}`
1360
+ );
1361
+ }
1362
+ const out = {};
1363
+ if (value.interval !== void 0) {
1364
+ out.interval = assertThreshold("supervisor.interval", value.interval, 1);
1365
+ }
1366
+ return out;
1367
+ }
1349
1368
  function normalizeToolBudgets(value) {
1350
1369
  if (!value || typeof value !== "object" || Array.isArray(value)) {
1351
1370
  throw new MantyxError(
@@ -1700,7 +1719,7 @@ function normalizeScope(scope) {
1700
1719
  }
1701
1720
 
1702
1721
  // src/version.ts
1703
- var SDK_VERSION = "0.11.0";
1722
+ var SDK_VERSION = "0.12.0";
1704
1723
  // Annotate the CommonJS export names for ESM import in node:
1705
1724
  0 && (module.exports = {
1706
1725
  AgentSession,