@mantyx/sdk 0.10.1 → 0.11.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 +7 -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-DR625E6B.js} +69 -9
- package/dist/chunk-DR625E6B.js.map +1 -0
- package/dist/{client-CZUVldDx.d.cts → client-Byb0Zdo7.d.cts} +155 -1
- package/dist/{client-CZUVldDx.d.ts → client-Byb0Zdo7.d.ts} +155 -1
- package/dist/index.cjs +69 -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 +373 -220
- package/docs/wire-protocol.md +415 -252
- 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
|
/**
|
|
@@ -884,10 +925,102 @@ interface ToolBudget {
|
|
|
884
925
|
* entirely to keep the defaults.
|
|
885
926
|
*/
|
|
886
927
|
type ToolBudgets = Record<string, ToolBudget>;
|
|
928
|
+
/**
|
|
929
|
+
* Per-run token totals attached to terminal `result` / `error` events
|
|
930
|
+
* (and to the `GET /agent-runs/:runId` snapshot) by MANTYX ≥ 2026-09.
|
|
931
|
+
*
|
|
932
|
+
* Aggregated across every model invocation for the run. See
|
|
933
|
+
* `docs/agent-runs-protocol.md` §7.1 for the per-provider mapping and
|
|
934
|
+
* the relationship between buckets (`inputTokens` / `outputTokens` are
|
|
935
|
+
* the billable totals; `cachedTokens` and `reasoningTokens` are
|
|
936
|
+
* diagnostic breakdowns _inside_ those two totals, not separate
|
|
937
|
+
* additive buckets).
|
|
938
|
+
*
|
|
939
|
+
* Older servers omit the cost-attribution triple entirely; SDK callers
|
|
940
|
+
* detect "no usage data" by checking `result.model?.provider` is empty
|
|
941
|
+
* / undefined.
|
|
942
|
+
*/
|
|
943
|
+
interface RunTokenUsage {
|
|
944
|
+
/**
|
|
945
|
+
* Total billable input tokens — fresh prompt tokens plus the
|
|
946
|
+
* cached-read slice the provider still bills (at a discount) plus
|
|
947
|
+
* any cache-creation tokens plus tool-prompt tokens. Equal to the
|
|
948
|
+
* sum of every provider-reported input bucket for the run.
|
|
949
|
+
*/
|
|
950
|
+
inputTokens: number;
|
|
951
|
+
/**
|
|
952
|
+
* The discounted slice of `inputTokens` that came from a prompt
|
|
953
|
+
* cache hit (Anthropic prompt caching, OpenAI cached prompt, Gemini
|
|
954
|
+
* implicit cache). `0` when the provider doesn't report cache reads
|
|
955
|
+
* or the run didn't hit cache.
|
|
956
|
+
*/
|
|
957
|
+
cachedTokens: number;
|
|
958
|
+
/**
|
|
959
|
+
* Non-visible thinking tokens. **Already counted inside
|
|
960
|
+
* `outputTokens`** — surfaced separately so dashboards can break out
|
|
961
|
+
* "thinking cost" vs visible output. `0` when the model didn't
|
|
962
|
+
* reason or didn't report it.
|
|
963
|
+
*/
|
|
964
|
+
reasoningTokens: number;
|
|
965
|
+
/**
|
|
966
|
+
* All tokens the model emitted for this run, visible + reasoning.
|
|
967
|
+
* Matches the provider's "completion tokens" / "output tokens"
|
|
968
|
+
* billing line.
|
|
969
|
+
*/
|
|
970
|
+
outputTokens: number;
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* The resolved model the platform stamped onto the run, surfaced on
|
|
974
|
+
* terminal `result` / `error` events (and `GET /agent-runs/:runId`)
|
|
975
|
+
* by MANTYX ≥ 2026-09. See `docs/agent-runs-protocol.md` §7.1.
|
|
976
|
+
*/
|
|
977
|
+
interface RunModelInfo {
|
|
978
|
+
/**
|
|
979
|
+
* Catalog id — the same string a caller would pass back as
|
|
980
|
+
* `modelId` to re-select this exact entry (e.g. `"platform:demo"`,
|
|
981
|
+
* `"provider:cmf…"`). Empty string against legacy fallbacks that
|
|
982
|
+
* didn't synthesise a catalog id.
|
|
983
|
+
*/
|
|
984
|
+
id: string;
|
|
985
|
+
/**
|
|
986
|
+
* Lowercase provider id: `"openai"`, `"anthropic"`, `"google"`,
|
|
987
|
+
* `"azure-openai"`. Empty string against legacy runners that don't
|
|
988
|
+
* report usage data — SDK callers use that as the "no usage data"
|
|
989
|
+
* signal.
|
|
990
|
+
*/
|
|
991
|
+
provider: string;
|
|
992
|
+
/**
|
|
993
|
+
* The model id the platform actually sent to the provider (e.g.
|
|
994
|
+
* `"gpt-5.4-mini"`, `"claude-opus-4-7"`, `"gemini-2.5-pro"`).
|
|
995
|
+
*/
|
|
996
|
+
vendorModelId: string;
|
|
997
|
+
/**
|
|
998
|
+
* `"off" | "low" | "medium" | "high"`. Omitted when the provider
|
|
999
|
+
* doesn't expose a reasoning-level knob or the run didn't request
|
|
1000
|
+
* one.
|
|
1001
|
+
*/
|
|
1002
|
+
reasoningEffort?: string;
|
|
1003
|
+
}
|
|
887
1004
|
interface RunResult {
|
|
888
1005
|
runId: string;
|
|
889
1006
|
text: string;
|
|
890
1007
|
events: RunEvent[];
|
|
1008
|
+
/**
|
|
1009
|
+
* Per-run token totals from the terminal event. Undefined against
|
|
1010
|
+
* MANTYX servers older than 2026-09 (the "no usage data" signal is
|
|
1011
|
+
* `result.model?.provider` being empty / undefined). See
|
|
1012
|
+
* {@link RunTokenUsage} and `docs/agent-runs-protocol.md` §7.1.
|
|
1013
|
+
*/
|
|
1014
|
+
tokens?: RunTokenUsage;
|
|
1015
|
+
/**
|
|
1016
|
+
* Total `engine.completeTurn(...)` invocations for the run,
|
|
1017
|
+
* including the failing call when a run errored mid-loop. A
|
|
1018
|
+
* single-shot run reports `1`; a tool loop is `>= 2`. Undefined
|
|
1019
|
+
* against legacy MANTYX servers.
|
|
1020
|
+
*/
|
|
1021
|
+
turns?: number;
|
|
1022
|
+
/** Resolved model that executed the run. See {@link RunModelInfo}. */
|
|
1023
|
+
model?: RunModelInfo;
|
|
891
1024
|
}
|
|
892
1025
|
interface RunEventBase {
|
|
893
1026
|
seq: number;
|
|
@@ -1036,6 +1169,15 @@ interface ResultEvent extends RunEventBase {
|
|
|
1036
1169
|
subtype: string;
|
|
1037
1170
|
text?: string;
|
|
1038
1171
|
error?: string;
|
|
1172
|
+
/**
|
|
1173
|
+
* Per-run token totals. Present against MANTYX ≥ 2026-09 — see
|
|
1174
|
+
* {@link RunTokenUsage} and `docs/agent-runs-protocol.md` §7.1.
|
|
1175
|
+
*/
|
|
1176
|
+
tokens?: RunTokenUsage;
|
|
1177
|
+
/** Total model invocations for the run. See {@link RunResult.turns}. */
|
|
1178
|
+
turns?: number;
|
|
1179
|
+
/** Resolved model that executed the run. See {@link RunModelInfo}. */
|
|
1180
|
+
model?: RunModelInfo;
|
|
1039
1181
|
}
|
|
1040
1182
|
interface ErrorEvent extends RunEventBase {
|
|
1041
1183
|
type: "error";
|
|
@@ -1074,6 +1216,18 @@ interface ErrorEvent extends RunEventBase {
|
|
|
1074
1216
|
* Informational; the SDK still owns the actual retry decision.
|
|
1075
1217
|
*/
|
|
1076
1218
|
retryable?: boolean;
|
|
1219
|
+
/**
|
|
1220
|
+
* Per-run token totals. Present against MANTYX ≥ 2026-09 — see
|
|
1221
|
+
* {@link RunTokenUsage} and `docs/agent-runs-protocol.md` §7.1.
|
|
1222
|
+
* The pipeline counts the failing model call too, so a run that
|
|
1223
|
+
* threw on the first turn reports `turns: 1` with that call's
|
|
1224
|
+
* tokens already aggregated.
|
|
1225
|
+
*/
|
|
1226
|
+
tokens?: RunTokenUsage;
|
|
1227
|
+
/** Total model invocations for the run, including the failing call. */
|
|
1228
|
+
turns?: number;
|
|
1229
|
+
/** Resolved model that executed the run. See {@link RunModelInfo}. */
|
|
1230
|
+
model?: RunModelInfo;
|
|
1077
1231
|
}
|
|
1078
1232
|
interface CancelledEvent extends RunEventBase {
|
|
1079
1233
|
type: "cancelled";
|
|
@@ -1280,4 +1434,4 @@ interface LocalHandlers {
|
|
|
1280
1434
|
*/
|
|
1281
1435
|
declare function parseRunOutput<T = unknown>(result: RunResult, validator?: (value: unknown) => T): T;
|
|
1282
1436
|
|
|
1283
|
-
export { type
|
|
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 };
|
|
@@ -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
|
/**
|
|
@@ -884,10 +925,102 @@ interface ToolBudget {
|
|
|
884
925
|
* entirely to keep the defaults.
|
|
885
926
|
*/
|
|
886
927
|
type ToolBudgets = Record<string, ToolBudget>;
|
|
928
|
+
/**
|
|
929
|
+
* Per-run token totals attached to terminal `result` / `error` events
|
|
930
|
+
* (and to the `GET /agent-runs/:runId` snapshot) by MANTYX ≥ 2026-09.
|
|
931
|
+
*
|
|
932
|
+
* Aggregated across every model invocation for the run. See
|
|
933
|
+
* `docs/agent-runs-protocol.md` §7.1 for the per-provider mapping and
|
|
934
|
+
* the relationship between buckets (`inputTokens` / `outputTokens` are
|
|
935
|
+
* the billable totals; `cachedTokens` and `reasoningTokens` are
|
|
936
|
+
* diagnostic breakdowns _inside_ those two totals, not separate
|
|
937
|
+
* additive buckets).
|
|
938
|
+
*
|
|
939
|
+
* Older servers omit the cost-attribution triple entirely; SDK callers
|
|
940
|
+
* detect "no usage data" by checking `result.model?.provider` is empty
|
|
941
|
+
* / undefined.
|
|
942
|
+
*/
|
|
943
|
+
interface RunTokenUsage {
|
|
944
|
+
/**
|
|
945
|
+
* Total billable input tokens — fresh prompt tokens plus the
|
|
946
|
+
* cached-read slice the provider still bills (at a discount) plus
|
|
947
|
+
* any cache-creation tokens plus tool-prompt tokens. Equal to the
|
|
948
|
+
* sum of every provider-reported input bucket for the run.
|
|
949
|
+
*/
|
|
950
|
+
inputTokens: number;
|
|
951
|
+
/**
|
|
952
|
+
* The discounted slice of `inputTokens` that came from a prompt
|
|
953
|
+
* cache hit (Anthropic prompt caching, OpenAI cached prompt, Gemini
|
|
954
|
+
* implicit cache). `0` when the provider doesn't report cache reads
|
|
955
|
+
* or the run didn't hit cache.
|
|
956
|
+
*/
|
|
957
|
+
cachedTokens: number;
|
|
958
|
+
/**
|
|
959
|
+
* Non-visible thinking tokens. **Already counted inside
|
|
960
|
+
* `outputTokens`** — surfaced separately so dashboards can break out
|
|
961
|
+
* "thinking cost" vs visible output. `0` when the model didn't
|
|
962
|
+
* reason or didn't report it.
|
|
963
|
+
*/
|
|
964
|
+
reasoningTokens: number;
|
|
965
|
+
/**
|
|
966
|
+
* All tokens the model emitted for this run, visible + reasoning.
|
|
967
|
+
* Matches the provider's "completion tokens" / "output tokens"
|
|
968
|
+
* billing line.
|
|
969
|
+
*/
|
|
970
|
+
outputTokens: number;
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* The resolved model the platform stamped onto the run, surfaced on
|
|
974
|
+
* terminal `result` / `error` events (and `GET /agent-runs/:runId`)
|
|
975
|
+
* by MANTYX ≥ 2026-09. See `docs/agent-runs-protocol.md` §7.1.
|
|
976
|
+
*/
|
|
977
|
+
interface RunModelInfo {
|
|
978
|
+
/**
|
|
979
|
+
* Catalog id — the same string a caller would pass back as
|
|
980
|
+
* `modelId` to re-select this exact entry (e.g. `"platform:demo"`,
|
|
981
|
+
* `"provider:cmf…"`). Empty string against legacy fallbacks that
|
|
982
|
+
* didn't synthesise a catalog id.
|
|
983
|
+
*/
|
|
984
|
+
id: string;
|
|
985
|
+
/**
|
|
986
|
+
* Lowercase provider id: `"openai"`, `"anthropic"`, `"google"`,
|
|
987
|
+
* `"azure-openai"`. Empty string against legacy runners that don't
|
|
988
|
+
* report usage data — SDK callers use that as the "no usage data"
|
|
989
|
+
* signal.
|
|
990
|
+
*/
|
|
991
|
+
provider: string;
|
|
992
|
+
/**
|
|
993
|
+
* The model id the platform actually sent to the provider (e.g.
|
|
994
|
+
* `"gpt-5.4-mini"`, `"claude-opus-4-7"`, `"gemini-2.5-pro"`).
|
|
995
|
+
*/
|
|
996
|
+
vendorModelId: string;
|
|
997
|
+
/**
|
|
998
|
+
* `"off" | "low" | "medium" | "high"`. Omitted when the provider
|
|
999
|
+
* doesn't expose a reasoning-level knob or the run didn't request
|
|
1000
|
+
* one.
|
|
1001
|
+
*/
|
|
1002
|
+
reasoningEffort?: string;
|
|
1003
|
+
}
|
|
887
1004
|
interface RunResult {
|
|
888
1005
|
runId: string;
|
|
889
1006
|
text: string;
|
|
890
1007
|
events: RunEvent[];
|
|
1008
|
+
/**
|
|
1009
|
+
* Per-run token totals from the terminal event. Undefined against
|
|
1010
|
+
* MANTYX servers older than 2026-09 (the "no usage data" signal is
|
|
1011
|
+
* `result.model?.provider` being empty / undefined). See
|
|
1012
|
+
* {@link RunTokenUsage} and `docs/agent-runs-protocol.md` §7.1.
|
|
1013
|
+
*/
|
|
1014
|
+
tokens?: RunTokenUsage;
|
|
1015
|
+
/**
|
|
1016
|
+
* Total `engine.completeTurn(...)` invocations for the run,
|
|
1017
|
+
* including the failing call when a run errored mid-loop. A
|
|
1018
|
+
* single-shot run reports `1`; a tool loop is `>= 2`. Undefined
|
|
1019
|
+
* against legacy MANTYX servers.
|
|
1020
|
+
*/
|
|
1021
|
+
turns?: number;
|
|
1022
|
+
/** Resolved model that executed the run. See {@link RunModelInfo}. */
|
|
1023
|
+
model?: RunModelInfo;
|
|
891
1024
|
}
|
|
892
1025
|
interface RunEventBase {
|
|
893
1026
|
seq: number;
|
|
@@ -1036,6 +1169,15 @@ interface ResultEvent extends RunEventBase {
|
|
|
1036
1169
|
subtype: string;
|
|
1037
1170
|
text?: string;
|
|
1038
1171
|
error?: string;
|
|
1172
|
+
/**
|
|
1173
|
+
* Per-run token totals. Present against MANTYX ≥ 2026-09 — see
|
|
1174
|
+
* {@link RunTokenUsage} and `docs/agent-runs-protocol.md` §7.1.
|
|
1175
|
+
*/
|
|
1176
|
+
tokens?: RunTokenUsage;
|
|
1177
|
+
/** Total model invocations for the run. See {@link RunResult.turns}. */
|
|
1178
|
+
turns?: number;
|
|
1179
|
+
/** Resolved model that executed the run. See {@link RunModelInfo}. */
|
|
1180
|
+
model?: RunModelInfo;
|
|
1039
1181
|
}
|
|
1040
1182
|
interface ErrorEvent extends RunEventBase {
|
|
1041
1183
|
type: "error";
|
|
@@ -1074,6 +1216,18 @@ interface ErrorEvent extends RunEventBase {
|
|
|
1074
1216
|
* Informational; the SDK still owns the actual retry decision.
|
|
1075
1217
|
*/
|
|
1076
1218
|
retryable?: boolean;
|
|
1219
|
+
/**
|
|
1220
|
+
* Per-run token totals. Present against MANTYX ≥ 2026-09 — see
|
|
1221
|
+
* {@link RunTokenUsage} and `docs/agent-runs-protocol.md` §7.1.
|
|
1222
|
+
* The pipeline counts the failing model call too, so a run that
|
|
1223
|
+
* threw on the first turn reports `turns: 1` with that call's
|
|
1224
|
+
* tokens already aggregated.
|
|
1225
|
+
*/
|
|
1226
|
+
tokens?: RunTokenUsage;
|
|
1227
|
+
/** Total model invocations for the run, including the failing call. */
|
|
1228
|
+
turns?: number;
|
|
1229
|
+
/** Resolved model that executed the run. See {@link RunModelInfo}. */
|
|
1230
|
+
model?: RunModelInfo;
|
|
1077
1231
|
}
|
|
1078
1232
|
interface CancelledEvent extends RunEventBase {
|
|
1079
1233
|
type: "cancelled";
|
|
@@ -1280,4 +1434,4 @@ interface LocalHandlers {
|
|
|
1280
1434
|
*/
|
|
1281
1435
|
declare function parseRunOutput<T = unknown>(result: RunResult, validator?: (value: unknown) => T): T;
|
|
1282
1436
|
|
|
1283
|
-
export { type
|
|
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 };
|
package/dist/index.cjs
CHANGED
|
@@ -123,6 +123,12 @@ var MantyxRunError = class extends MantyxError {
|
|
|
123
123
|
partialText;
|
|
124
124
|
/** See {@link MantyxRunErrorInit.retryable}. */
|
|
125
125
|
retryable;
|
|
126
|
+
/** See {@link MantyxRunErrorInit.tokens}. */
|
|
127
|
+
tokens;
|
|
128
|
+
/** See {@link MantyxRunErrorInit.turns}. */
|
|
129
|
+
turns;
|
|
130
|
+
/** See {@link MantyxRunErrorInit.model}. */
|
|
131
|
+
model;
|
|
126
132
|
constructor(runId, subtype, message, init = {}) {
|
|
127
133
|
super(message, { code: subtype });
|
|
128
134
|
this.name = "MantyxRunError";
|
|
@@ -132,6 +138,9 @@ var MantyxRunError = class extends MantyxError {
|
|
|
132
138
|
this.finishReason = init.finishReason;
|
|
133
139
|
this.partialText = init.partialText;
|
|
134
140
|
this.retryable = init.retryable;
|
|
141
|
+
this.tokens = init.tokens;
|
|
142
|
+
this.turns = init.turns;
|
|
143
|
+
this.model = init.model;
|
|
135
144
|
}
|
|
136
145
|
};
|
|
137
146
|
var MantyxParseError = class extends MantyxError {
|
|
@@ -771,6 +780,9 @@ var MantyxClient = class {
|
|
|
771
780
|
async driveRun(runId, handlers, opts = {}) {
|
|
772
781
|
const collected = [];
|
|
773
782
|
let finalText = "";
|
|
783
|
+
let tokens;
|
|
784
|
+
let turns;
|
|
785
|
+
let modelInfo;
|
|
774
786
|
for await (const ev of this.streamRunEvents(runId, handlers, opts.signal)) {
|
|
775
787
|
collected.push(ev);
|
|
776
788
|
if (opts.onEvent) opts.onEvent(ev);
|
|
@@ -779,25 +791,42 @@ var MantyxClient = class {
|
|
|
779
791
|
}
|
|
780
792
|
if (ev.type === "result") {
|
|
781
793
|
const r = ev;
|
|
794
|
+
tokens = parseRunTokens(r.tokens) ?? tokens;
|
|
795
|
+
turns = parseRunTurns(r.turns) ?? turns;
|
|
796
|
+
modelInfo = parseRunModel(r.model) ?? modelInfo;
|
|
782
797
|
if (r.subtype === "success") {
|
|
783
798
|
finalText = typeof r.text === "string" ? r.text : "";
|
|
784
799
|
} else {
|
|
785
|
-
|
|
800
|
+
const errInit = {};
|
|
801
|
+
if (tokens !== void 0) errInit.tokens = tokens;
|
|
802
|
+
if (turns !== void 0) errInit.turns = turns;
|
|
803
|
+
if (modelInfo !== void 0) errInit.model = modelInfo;
|
|
804
|
+
throw new MantyxRunError(runId, r.subtype, r.error ?? r.subtype, errInit);
|
|
786
805
|
}
|
|
787
806
|
} else if (ev.type === "error") {
|
|
788
807
|
const e = ev;
|
|
789
808
|
const subtype = e.errorClass ?? e.code ?? "error";
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
809
|
+
const errInit = {};
|
|
810
|
+
if (e.errorClass !== void 0) errInit.errorClass = e.errorClass;
|
|
811
|
+
if (e.finishReason !== void 0) errInit.finishReason = e.finishReason;
|
|
812
|
+
if (typeof e.partialText === "string") errInit.partialText = e.partialText;
|
|
813
|
+
if (typeof e.retryable === "boolean") errInit.retryable = e.retryable;
|
|
814
|
+
const errTokens = parseRunTokens(e.tokens);
|
|
815
|
+
if (errTokens !== void 0) errInit.tokens = errTokens;
|
|
816
|
+
const errTurns = parseRunTurns(e.turns);
|
|
817
|
+
if (errTurns !== void 0) errInit.turns = errTurns;
|
|
818
|
+
const errModel = parseRunModel(e.model);
|
|
819
|
+
if (errModel !== void 0) errInit.model = errModel;
|
|
820
|
+
throw new MantyxRunError(runId, subtype, e.error, errInit);
|
|
796
821
|
} else if (ev.type === "cancelled") {
|
|
797
822
|
throw new MantyxRunError(runId, "cancelled", "Run was cancelled");
|
|
798
823
|
}
|
|
799
824
|
}
|
|
800
|
-
|
|
825
|
+
const result = { runId, text: finalText, events: collected };
|
|
826
|
+
if (tokens !== void 0) result.tokens = tokens;
|
|
827
|
+
if (turns !== void 0) result.turns = turns;
|
|
828
|
+
if (modelInfo !== void 0) result.model = modelInfo;
|
|
829
|
+
return result;
|
|
801
830
|
}
|
|
802
831
|
async *streamRunEvents(runId, handlers, signal) {
|
|
803
832
|
const url = this.absoluteUrl(`/agent-runs/${encodeURIComponent(runId)}/stream`);
|
|
@@ -1384,6 +1413,37 @@ function parseRunOutput(result, validator) {
|
|
|
1384
1413
|
function sleep(ms) {
|
|
1385
1414
|
return new Promise((r) => setTimeout(r, ms));
|
|
1386
1415
|
}
|
|
1416
|
+
function parseRunTokens(value) {
|
|
1417
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
1418
|
+
const v = value;
|
|
1419
|
+
return {
|
|
1420
|
+
inputTokens: toNonNegativeInt(v.inputTokens),
|
|
1421
|
+
cachedTokens: toNonNegativeInt(v.cachedTokens),
|
|
1422
|
+
reasoningTokens: toNonNegativeInt(v.reasoningTokens),
|
|
1423
|
+
outputTokens: toNonNegativeInt(v.outputTokens)
|
|
1424
|
+
};
|
|
1425
|
+
}
|
|
1426
|
+
function parseRunTurns(value) {
|
|
1427
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return void 0;
|
|
1428
|
+
return Math.max(0, Math.trunc(value));
|
|
1429
|
+
}
|
|
1430
|
+
function parseRunModel(value) {
|
|
1431
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
1432
|
+
const v = value;
|
|
1433
|
+
const out = {
|
|
1434
|
+
id: typeof v.id === "string" ? v.id : "",
|
|
1435
|
+
provider: typeof v.provider === "string" ? v.provider : "",
|
|
1436
|
+
vendorModelId: typeof v.vendorModelId === "string" ? v.vendorModelId : ""
|
|
1437
|
+
};
|
|
1438
|
+
if (typeof v.reasoningEffort === "string" && v.reasoningEffort.length > 0) {
|
|
1439
|
+
out.reasoningEffort = v.reasoningEffort;
|
|
1440
|
+
}
|
|
1441
|
+
return out;
|
|
1442
|
+
}
|
|
1443
|
+
function toNonNegativeInt(value) {
|
|
1444
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return 0;
|
|
1445
|
+
return Math.max(0, Math.trunc(value));
|
|
1446
|
+
}
|
|
1387
1447
|
function resolveCredential(opts) {
|
|
1388
1448
|
const apiKey = typeof opts.apiKey === "string" ? opts.apiKey : "";
|
|
1389
1449
|
const accessToken = typeof opts.accessToken === "string" ? opts.accessToken : "";
|
|
@@ -1640,7 +1700,7 @@ function normalizeScope(scope) {
|
|
|
1640
1700
|
}
|
|
1641
1701
|
|
|
1642
1702
|
// src/version.ts
|
|
1643
|
-
var SDK_VERSION = "0.
|
|
1703
|
+
var SDK_VERSION = "0.11.0";
|
|
1644
1704
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1645
1705
|
0 && (module.exports = {
|
|
1646
1706
|
AgentSession,
|