@mantyx/sdk 0.10.1 → 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.
- package/CHANGELOG.md +14 -0
- package/dist/a2a-server.cjs +9 -0
- package/dist/a2a-server.cjs.map +1 -1
- package/dist/a2a-server.d.cts +1 -1
- package/dist/a2a-server.d.ts +1 -1
- package/dist/a2a-server.js +1 -1
- package/dist/{chunk-XMUCELMH.js → chunk-2K4BGJGJ.js} +88 -9
- package/dist/chunk-2K4BGJGJ.js.map +1 -0
- package/dist/{client-CZUVldDx.d.cts → client-LQlx7iYY.d.cts} +217 -2
- package/dist/{client-CZUVldDx.d.ts → client-LQlx7iYY.d.ts} +217 -2
- package/dist/index.cjs +88 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/docs/agent-runs-protocol.md +450 -234
- package/docs/wire-protocol.md +525 -272
- package/package.json +1 -1
- package/dist/chunk-XMUCELMH.js.map +0 -1
- package/docs/oauth.md +0 -356
|
@@ -47,6 +47,30 @@ declare class MantyxToolError extends MantyxError {
|
|
|
47
47
|
readonly toolName: string;
|
|
48
48
|
constructor(toolName: string, message: string);
|
|
49
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
|
+
}
|
|
50
74
|
/**
|
|
51
75
|
* Optional triage attributes the runner attaches to terminal `error`
|
|
52
76
|
* events. Mirrors the wire fields described in
|
|
@@ -83,6 +107,17 @@ interface MantyxRunErrorInit {
|
|
|
83
107
|
* Informational; the SDK still owns the actual retry decision.
|
|
84
108
|
*/
|
|
85
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;
|
|
86
121
|
}
|
|
87
122
|
declare class MantyxRunError extends MantyxError {
|
|
88
123
|
readonly runId: string;
|
|
@@ -95,6 +130,12 @@ declare class MantyxRunError extends MantyxError {
|
|
|
95
130
|
readonly partialText: string | undefined;
|
|
96
131
|
/** See {@link MantyxRunErrorInit.retryable}. */
|
|
97
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;
|
|
98
139
|
constructor(runId: string, subtype: string, message: string, init?: MantyxRunErrorInit);
|
|
99
140
|
}
|
|
100
141
|
/**
|
|
@@ -802,6 +843,22 @@ interface AgentSpecBase {
|
|
|
802
843
|
* `docs/agent-runs-protocol.md` §4.7.
|
|
803
844
|
*/
|
|
804
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;
|
|
805
862
|
/**
|
|
806
863
|
* Flat string→string KV carried alongside the run / session for
|
|
807
864
|
* observability. Use it to tag runs with your own application identifiers
|
|
@@ -884,10 +941,116 @@ interface ToolBudget {
|
|
|
884
941
|
* entirely to keep the defaults.
|
|
885
942
|
*/
|
|
886
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";
|
|
958
|
+
/**
|
|
959
|
+
* Per-run token totals attached to terminal `result` / `error` events
|
|
960
|
+
* (and to the `GET /agent-runs/:runId` snapshot) by MANTYX ≥ 2026-09.
|
|
961
|
+
*
|
|
962
|
+
* Aggregated across every model invocation for the run. See
|
|
963
|
+
* `docs/agent-runs-protocol.md` §7.1 for the per-provider mapping and
|
|
964
|
+
* the relationship between buckets (`inputTokens` / `outputTokens` are
|
|
965
|
+
* the billable totals; `cachedTokens` and `reasoningTokens` are
|
|
966
|
+
* diagnostic breakdowns _inside_ those two totals, not separate
|
|
967
|
+
* additive buckets).
|
|
968
|
+
*
|
|
969
|
+
* Older servers omit the cost-attribution triple entirely; SDK callers
|
|
970
|
+
* detect "no usage data" by checking `result.model?.provider` is empty
|
|
971
|
+
* / undefined.
|
|
972
|
+
*/
|
|
973
|
+
interface RunTokenUsage {
|
|
974
|
+
/**
|
|
975
|
+
* Total billable input tokens — fresh prompt tokens plus the
|
|
976
|
+
* cached-read slice the provider still bills (at a discount) plus
|
|
977
|
+
* any cache-creation tokens plus tool-prompt tokens. Equal to the
|
|
978
|
+
* sum of every provider-reported input bucket for the run.
|
|
979
|
+
*/
|
|
980
|
+
inputTokens: number;
|
|
981
|
+
/**
|
|
982
|
+
* The discounted slice of `inputTokens` that came from a prompt
|
|
983
|
+
* cache hit (Anthropic prompt caching, OpenAI cached prompt, Gemini
|
|
984
|
+
* implicit cache). `0` when the provider doesn't report cache reads
|
|
985
|
+
* or the run didn't hit cache.
|
|
986
|
+
*/
|
|
987
|
+
cachedTokens: number;
|
|
988
|
+
/**
|
|
989
|
+
* Non-visible thinking tokens. **Already counted inside
|
|
990
|
+
* `outputTokens`** — surfaced separately so dashboards can break out
|
|
991
|
+
* "thinking cost" vs visible output. `0` when the model didn't
|
|
992
|
+
* reason or didn't report it.
|
|
993
|
+
*/
|
|
994
|
+
reasoningTokens: number;
|
|
995
|
+
/**
|
|
996
|
+
* All tokens the model emitted for this run, visible + reasoning.
|
|
997
|
+
* Matches the provider's "completion tokens" / "output tokens"
|
|
998
|
+
* billing line.
|
|
999
|
+
*/
|
|
1000
|
+
outputTokens: number;
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* The resolved model the platform stamped onto the run, surfaced on
|
|
1004
|
+
* terminal `result` / `error` events (and `GET /agent-runs/:runId`)
|
|
1005
|
+
* by MANTYX ≥ 2026-09. See `docs/agent-runs-protocol.md` §7.1.
|
|
1006
|
+
*/
|
|
1007
|
+
interface RunModelInfo {
|
|
1008
|
+
/**
|
|
1009
|
+
* Catalog id — the same string a caller would pass back as
|
|
1010
|
+
* `modelId` to re-select this exact entry (e.g. `"platform:demo"`,
|
|
1011
|
+
* `"provider:cmf…"`). Empty string against legacy fallbacks that
|
|
1012
|
+
* didn't synthesise a catalog id.
|
|
1013
|
+
*/
|
|
1014
|
+
id: string;
|
|
1015
|
+
/**
|
|
1016
|
+
* Lowercase provider id: `"openai"`, `"anthropic"`, `"google"`,
|
|
1017
|
+
* `"azure-openai"`. Empty string against legacy runners that don't
|
|
1018
|
+
* report usage data — SDK callers use that as the "no usage data"
|
|
1019
|
+
* signal.
|
|
1020
|
+
*/
|
|
1021
|
+
provider: string;
|
|
1022
|
+
/**
|
|
1023
|
+
* The model id the platform actually sent to the provider (e.g.
|
|
1024
|
+
* `"gpt-5.4-mini"`, `"claude-opus-4-7"`, `"gemini-2.5-pro"`).
|
|
1025
|
+
*/
|
|
1026
|
+
vendorModelId: string;
|
|
1027
|
+
/**
|
|
1028
|
+
* `"off" | "low" | "medium" | "high"`. Omitted when the provider
|
|
1029
|
+
* doesn't expose a reasoning-level knob or the run didn't request
|
|
1030
|
+
* one.
|
|
1031
|
+
*/
|
|
1032
|
+
reasoningEffort?: string;
|
|
1033
|
+
}
|
|
887
1034
|
interface RunResult {
|
|
888
1035
|
runId: string;
|
|
889
1036
|
text: string;
|
|
890
1037
|
events: RunEvent[];
|
|
1038
|
+
/**
|
|
1039
|
+
* Per-run token totals from the terminal event. Undefined against
|
|
1040
|
+
* MANTYX servers older than 2026-09 (the "no usage data" signal is
|
|
1041
|
+
* `result.model?.provider` being empty / undefined). See
|
|
1042
|
+
* {@link RunTokenUsage} and `docs/agent-runs-protocol.md` §7.1.
|
|
1043
|
+
*/
|
|
1044
|
+
tokens?: RunTokenUsage;
|
|
1045
|
+
/**
|
|
1046
|
+
* Total `engine.completeTurn(...)` invocations for the run,
|
|
1047
|
+
* including the failing call when a run errored mid-loop. A
|
|
1048
|
+
* single-shot run reports `1`; a tool loop is `>= 2`. Undefined
|
|
1049
|
+
* against legacy MANTYX servers.
|
|
1050
|
+
*/
|
|
1051
|
+
turns?: number;
|
|
1052
|
+
/** Resolved model that executed the run. See {@link RunModelInfo}. */
|
|
1053
|
+
model?: RunModelInfo;
|
|
891
1054
|
}
|
|
892
1055
|
interface RunEventBase {
|
|
893
1056
|
seq: number;
|
|
@@ -1031,11 +1194,44 @@ interface ToolBudgetExceededEvent extends RunEventBase {
|
|
|
1031
1194
|
*/
|
|
1032
1195
|
callIndex: number;
|
|
1033
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
|
+
}
|
|
1034
1221
|
interface ResultEvent extends RunEventBase {
|
|
1035
1222
|
type: "result";
|
|
1036
1223
|
subtype: string;
|
|
1037
1224
|
text?: string;
|
|
1038
1225
|
error?: string;
|
|
1226
|
+
/**
|
|
1227
|
+
* Per-run token totals. Present against MANTYX ≥ 2026-09 — see
|
|
1228
|
+
* {@link RunTokenUsage} and `docs/agent-runs-protocol.md` §7.1.
|
|
1229
|
+
*/
|
|
1230
|
+
tokens?: RunTokenUsage;
|
|
1231
|
+
/** Total model invocations for the run. See {@link RunResult.turns}. */
|
|
1232
|
+
turns?: number;
|
|
1233
|
+
/** Resolved model that executed the run. See {@link RunModelInfo}. */
|
|
1234
|
+
model?: RunModelInfo;
|
|
1039
1235
|
}
|
|
1040
1236
|
interface ErrorEvent extends RunEventBase {
|
|
1041
1237
|
type: "error";
|
|
@@ -1074,12 +1270,24 @@ interface ErrorEvent extends RunEventBase {
|
|
|
1074
1270
|
* Informational; the SDK still owns the actual retry decision.
|
|
1075
1271
|
*/
|
|
1076
1272
|
retryable?: boolean;
|
|
1273
|
+
/**
|
|
1274
|
+
* Per-run token totals. Present against MANTYX ≥ 2026-09 — see
|
|
1275
|
+
* {@link RunTokenUsage} and `docs/agent-runs-protocol.md` §7.1.
|
|
1276
|
+
* The pipeline counts the failing model call too, so a run that
|
|
1277
|
+
* threw on the first turn reports `turns: 1` with that call's
|
|
1278
|
+
* tokens already aggregated.
|
|
1279
|
+
*/
|
|
1280
|
+
tokens?: RunTokenUsage;
|
|
1281
|
+
/** Total model invocations for the run, including the failing call. */
|
|
1282
|
+
turns?: number;
|
|
1283
|
+
/** Resolved model that executed the run. See {@link RunModelInfo}. */
|
|
1284
|
+
model?: RunModelInfo;
|
|
1077
1285
|
}
|
|
1078
1286
|
interface CancelledEvent extends RunEventBase {
|
|
1079
1287
|
type: "cancelled";
|
|
1080
1288
|
reason?: string;
|
|
1081
1289
|
}
|
|
1082
|
-
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 & {
|
|
1083
1291
|
type: string;
|
|
1084
1292
|
[key: string]: unknown;
|
|
1085
1293
|
});
|
|
@@ -1222,6 +1430,12 @@ declare class AgentSession {
|
|
|
1222
1430
|
* and does not mutate the session's stored value.
|
|
1223
1431
|
*/
|
|
1224
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;
|
|
1225
1439
|
}): Promise<RunResult>;
|
|
1226
1440
|
stream(prompt: string, opts?: {
|
|
1227
1441
|
signal?: AbortSignal;
|
|
@@ -1230,6 +1444,7 @@ declare class AgentSession {
|
|
|
1230
1444
|
outputSchema?: OutputSchema;
|
|
1231
1445
|
loopDetection?: LoopDetection | false;
|
|
1232
1446
|
toolBudgets?: ToolBudgets;
|
|
1447
|
+
supervisor?: Supervisor | false;
|
|
1233
1448
|
}): AsyncGenerator<RunEvent, void, void>;
|
|
1234
1449
|
private buildSessionMessageBody;
|
|
1235
1450
|
history(): Promise<Array<{
|
|
@@ -1280,4 +1495,4 @@ interface LocalHandlers {
|
|
|
1280
1495
|
*/
|
|
1281
1496
|
declare function parseRunOutput<T = unknown>(result: RunResult, validator?: (value: unknown) => T): T;
|
|
1282
1497
|
|
|
1283
|
-
export { type
|
|
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 };
|
|
@@ -47,6 +47,30 @@ declare class MantyxToolError extends MantyxError {
|
|
|
47
47
|
readonly toolName: string;
|
|
48
48
|
constructor(toolName: string, message: string);
|
|
49
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
|
+
}
|
|
50
74
|
/**
|
|
51
75
|
* Optional triage attributes the runner attaches to terminal `error`
|
|
52
76
|
* events. Mirrors the wire fields described in
|
|
@@ -83,6 +107,17 @@ interface MantyxRunErrorInit {
|
|
|
83
107
|
* Informational; the SDK still owns the actual retry decision.
|
|
84
108
|
*/
|
|
85
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;
|
|
86
121
|
}
|
|
87
122
|
declare class MantyxRunError extends MantyxError {
|
|
88
123
|
readonly runId: string;
|
|
@@ -95,6 +130,12 @@ declare class MantyxRunError extends MantyxError {
|
|
|
95
130
|
readonly partialText: string | undefined;
|
|
96
131
|
/** See {@link MantyxRunErrorInit.retryable}. */
|
|
97
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;
|
|
98
139
|
constructor(runId: string, subtype: string, message: string, init?: MantyxRunErrorInit);
|
|
99
140
|
}
|
|
100
141
|
/**
|
|
@@ -802,6 +843,22 @@ interface AgentSpecBase {
|
|
|
802
843
|
* `docs/agent-runs-protocol.md` §4.7.
|
|
803
844
|
*/
|
|
804
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;
|
|
805
862
|
/**
|
|
806
863
|
* Flat string→string KV carried alongside the run / session for
|
|
807
864
|
* observability. Use it to tag runs with your own application identifiers
|
|
@@ -884,10 +941,116 @@ interface ToolBudget {
|
|
|
884
941
|
* entirely to keep the defaults.
|
|
885
942
|
*/
|
|
886
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";
|
|
958
|
+
/**
|
|
959
|
+
* Per-run token totals attached to terminal `result` / `error` events
|
|
960
|
+
* (and to the `GET /agent-runs/:runId` snapshot) by MANTYX ≥ 2026-09.
|
|
961
|
+
*
|
|
962
|
+
* Aggregated across every model invocation for the run. See
|
|
963
|
+
* `docs/agent-runs-protocol.md` §7.1 for the per-provider mapping and
|
|
964
|
+
* the relationship between buckets (`inputTokens` / `outputTokens` are
|
|
965
|
+
* the billable totals; `cachedTokens` and `reasoningTokens` are
|
|
966
|
+
* diagnostic breakdowns _inside_ those two totals, not separate
|
|
967
|
+
* additive buckets).
|
|
968
|
+
*
|
|
969
|
+
* Older servers omit the cost-attribution triple entirely; SDK callers
|
|
970
|
+
* detect "no usage data" by checking `result.model?.provider` is empty
|
|
971
|
+
* / undefined.
|
|
972
|
+
*/
|
|
973
|
+
interface RunTokenUsage {
|
|
974
|
+
/**
|
|
975
|
+
* Total billable input tokens — fresh prompt tokens plus the
|
|
976
|
+
* cached-read slice the provider still bills (at a discount) plus
|
|
977
|
+
* any cache-creation tokens plus tool-prompt tokens. Equal to the
|
|
978
|
+
* sum of every provider-reported input bucket for the run.
|
|
979
|
+
*/
|
|
980
|
+
inputTokens: number;
|
|
981
|
+
/**
|
|
982
|
+
* The discounted slice of `inputTokens` that came from a prompt
|
|
983
|
+
* cache hit (Anthropic prompt caching, OpenAI cached prompt, Gemini
|
|
984
|
+
* implicit cache). `0` when the provider doesn't report cache reads
|
|
985
|
+
* or the run didn't hit cache.
|
|
986
|
+
*/
|
|
987
|
+
cachedTokens: number;
|
|
988
|
+
/**
|
|
989
|
+
* Non-visible thinking tokens. **Already counted inside
|
|
990
|
+
* `outputTokens`** — surfaced separately so dashboards can break out
|
|
991
|
+
* "thinking cost" vs visible output. `0` when the model didn't
|
|
992
|
+
* reason or didn't report it.
|
|
993
|
+
*/
|
|
994
|
+
reasoningTokens: number;
|
|
995
|
+
/**
|
|
996
|
+
* All tokens the model emitted for this run, visible + reasoning.
|
|
997
|
+
* Matches the provider's "completion tokens" / "output tokens"
|
|
998
|
+
* billing line.
|
|
999
|
+
*/
|
|
1000
|
+
outputTokens: number;
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* The resolved model the platform stamped onto the run, surfaced on
|
|
1004
|
+
* terminal `result` / `error` events (and `GET /agent-runs/:runId`)
|
|
1005
|
+
* by MANTYX ≥ 2026-09. See `docs/agent-runs-protocol.md` §7.1.
|
|
1006
|
+
*/
|
|
1007
|
+
interface RunModelInfo {
|
|
1008
|
+
/**
|
|
1009
|
+
* Catalog id — the same string a caller would pass back as
|
|
1010
|
+
* `modelId` to re-select this exact entry (e.g. `"platform:demo"`,
|
|
1011
|
+
* `"provider:cmf…"`). Empty string against legacy fallbacks that
|
|
1012
|
+
* didn't synthesise a catalog id.
|
|
1013
|
+
*/
|
|
1014
|
+
id: string;
|
|
1015
|
+
/**
|
|
1016
|
+
* Lowercase provider id: `"openai"`, `"anthropic"`, `"google"`,
|
|
1017
|
+
* `"azure-openai"`. Empty string against legacy runners that don't
|
|
1018
|
+
* report usage data — SDK callers use that as the "no usage data"
|
|
1019
|
+
* signal.
|
|
1020
|
+
*/
|
|
1021
|
+
provider: string;
|
|
1022
|
+
/**
|
|
1023
|
+
* The model id the platform actually sent to the provider (e.g.
|
|
1024
|
+
* `"gpt-5.4-mini"`, `"claude-opus-4-7"`, `"gemini-2.5-pro"`).
|
|
1025
|
+
*/
|
|
1026
|
+
vendorModelId: string;
|
|
1027
|
+
/**
|
|
1028
|
+
* `"off" | "low" | "medium" | "high"`. Omitted when the provider
|
|
1029
|
+
* doesn't expose a reasoning-level knob or the run didn't request
|
|
1030
|
+
* one.
|
|
1031
|
+
*/
|
|
1032
|
+
reasoningEffort?: string;
|
|
1033
|
+
}
|
|
887
1034
|
interface RunResult {
|
|
888
1035
|
runId: string;
|
|
889
1036
|
text: string;
|
|
890
1037
|
events: RunEvent[];
|
|
1038
|
+
/**
|
|
1039
|
+
* Per-run token totals from the terminal event. Undefined against
|
|
1040
|
+
* MANTYX servers older than 2026-09 (the "no usage data" signal is
|
|
1041
|
+
* `result.model?.provider` being empty / undefined). See
|
|
1042
|
+
* {@link RunTokenUsage} and `docs/agent-runs-protocol.md` §7.1.
|
|
1043
|
+
*/
|
|
1044
|
+
tokens?: RunTokenUsage;
|
|
1045
|
+
/**
|
|
1046
|
+
* Total `engine.completeTurn(...)` invocations for the run,
|
|
1047
|
+
* including the failing call when a run errored mid-loop. A
|
|
1048
|
+
* single-shot run reports `1`; a tool loop is `>= 2`. Undefined
|
|
1049
|
+
* against legacy MANTYX servers.
|
|
1050
|
+
*/
|
|
1051
|
+
turns?: number;
|
|
1052
|
+
/** Resolved model that executed the run. See {@link RunModelInfo}. */
|
|
1053
|
+
model?: RunModelInfo;
|
|
891
1054
|
}
|
|
892
1055
|
interface RunEventBase {
|
|
893
1056
|
seq: number;
|
|
@@ -1031,11 +1194,44 @@ interface ToolBudgetExceededEvent extends RunEventBase {
|
|
|
1031
1194
|
*/
|
|
1032
1195
|
callIndex: number;
|
|
1033
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
|
+
}
|
|
1034
1221
|
interface ResultEvent extends RunEventBase {
|
|
1035
1222
|
type: "result";
|
|
1036
1223
|
subtype: string;
|
|
1037
1224
|
text?: string;
|
|
1038
1225
|
error?: string;
|
|
1226
|
+
/**
|
|
1227
|
+
* Per-run token totals. Present against MANTYX ≥ 2026-09 — see
|
|
1228
|
+
* {@link RunTokenUsage} and `docs/agent-runs-protocol.md` §7.1.
|
|
1229
|
+
*/
|
|
1230
|
+
tokens?: RunTokenUsage;
|
|
1231
|
+
/** Total model invocations for the run. See {@link RunResult.turns}. */
|
|
1232
|
+
turns?: number;
|
|
1233
|
+
/** Resolved model that executed the run. See {@link RunModelInfo}. */
|
|
1234
|
+
model?: RunModelInfo;
|
|
1039
1235
|
}
|
|
1040
1236
|
interface ErrorEvent extends RunEventBase {
|
|
1041
1237
|
type: "error";
|
|
@@ -1074,12 +1270,24 @@ interface ErrorEvent extends RunEventBase {
|
|
|
1074
1270
|
* Informational; the SDK still owns the actual retry decision.
|
|
1075
1271
|
*/
|
|
1076
1272
|
retryable?: boolean;
|
|
1273
|
+
/**
|
|
1274
|
+
* Per-run token totals. Present against MANTYX ≥ 2026-09 — see
|
|
1275
|
+
* {@link RunTokenUsage} and `docs/agent-runs-protocol.md` §7.1.
|
|
1276
|
+
* The pipeline counts the failing model call too, so a run that
|
|
1277
|
+
* threw on the first turn reports `turns: 1` with that call's
|
|
1278
|
+
* tokens already aggregated.
|
|
1279
|
+
*/
|
|
1280
|
+
tokens?: RunTokenUsage;
|
|
1281
|
+
/** Total model invocations for the run, including the failing call. */
|
|
1282
|
+
turns?: number;
|
|
1283
|
+
/** Resolved model that executed the run. See {@link RunModelInfo}. */
|
|
1284
|
+
model?: RunModelInfo;
|
|
1077
1285
|
}
|
|
1078
1286
|
interface CancelledEvent extends RunEventBase {
|
|
1079
1287
|
type: "cancelled";
|
|
1080
1288
|
reason?: string;
|
|
1081
1289
|
}
|
|
1082
|
-
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 & {
|
|
1083
1291
|
type: string;
|
|
1084
1292
|
[key: string]: unknown;
|
|
1085
1293
|
});
|
|
@@ -1222,6 +1430,12 @@ declare class AgentSession {
|
|
|
1222
1430
|
* and does not mutate the session's stored value.
|
|
1223
1431
|
*/
|
|
1224
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;
|
|
1225
1439
|
}): Promise<RunResult>;
|
|
1226
1440
|
stream(prompt: string, opts?: {
|
|
1227
1441
|
signal?: AbortSignal;
|
|
@@ -1230,6 +1444,7 @@ declare class AgentSession {
|
|
|
1230
1444
|
outputSchema?: OutputSchema;
|
|
1231
1445
|
loopDetection?: LoopDetection | false;
|
|
1232
1446
|
toolBudgets?: ToolBudgets;
|
|
1447
|
+
supervisor?: Supervisor | false;
|
|
1233
1448
|
}): AsyncGenerator<RunEvent, void, void>;
|
|
1234
1449
|
private buildSessionMessageBody;
|
|
1235
1450
|
history(): Promise<Array<{
|
|
@@ -1280,4 +1495,4 @@ interface LocalHandlers {
|
|
|
1280
1495
|
*/
|
|
1281
1496
|
declare function parseRunOutput<T = unknown>(result: RunResult, validator?: (value: unknown) => T): T;
|
|
1282
1497
|
|
|
1283
|
-
export { type
|
|
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 };
|