@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/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
- throw new MantyxRunError(runId, r.subtype, r.error ?? r.subtype);
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
- throw new MantyxRunError(runId, subtype, e.error, {
791
- ...e.errorClass !== void 0 ? { errorClass: e.errorClass } : {},
792
- ...e.finishReason !== void 0 ? { finishReason: e.finishReason } : {},
793
- ...typeof e.partialText === "string" ? { partialText: e.partialText } : {},
794
- ...typeof e.retryable === "boolean" ? { retryable: e.retryable } : {}
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
- return { runId, text: finalText, events: collected };
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`);
@@ -1073,6 +1102,9 @@ var AgentSession = class {
1073
1102
  if (opts.toolBudgets !== void 0) {
1074
1103
  body.toolBudgets = normalizeToolBudgets(opts.toolBudgets);
1075
1104
  }
1105
+ if (opts.supervisor !== void 0) {
1106
+ body.supervisor = normalizeSupervisor(opts.supervisor);
1107
+ }
1076
1108
  return body;
1077
1109
  }
1078
1110
  async history() {
@@ -1113,6 +1145,9 @@ function serializeAgentSpec(spec, extra = {}) {
1113
1145
  if (spec.toolBudgets !== void 0) {
1114
1146
  body.toolBudgets = normalizeToolBudgets(spec.toolBudgets);
1115
1147
  }
1148
+ if (spec.supervisor !== void 0) {
1149
+ body.supervisor = normalizeSupervisor(spec.supervisor);
1150
+ }
1116
1151
  if (spec.budgets) body.budgets = spec.budgets;
1117
1152
  if (spec.metadata && Object.keys(spec.metadata).length > 0) body.metadata = spec.metadata;
1118
1153
  if (extra.prompt !== void 0) body.prompt = extra.prompt;
@@ -1317,6 +1352,19 @@ function assertThreshold(label, value, min) {
1317
1352
  var TOOL_BUDGETS_MAX_ENTRIES = 32;
1318
1353
  var TOOL_BUDGET_MAX_NAME_LEN = 120;
1319
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
+ }
1320
1368
  function normalizeToolBudgets(value) {
1321
1369
  if (!value || typeof value !== "object" || Array.isArray(value)) {
1322
1370
  throw new MantyxError(
@@ -1384,6 +1432,37 @@ function parseRunOutput(result, validator) {
1384
1432
  function sleep(ms) {
1385
1433
  return new Promise((r) => setTimeout(r, ms));
1386
1434
  }
1435
+ function parseRunTokens(value) {
1436
+ if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
1437
+ const v = value;
1438
+ return {
1439
+ inputTokens: toNonNegativeInt(v.inputTokens),
1440
+ cachedTokens: toNonNegativeInt(v.cachedTokens),
1441
+ reasoningTokens: toNonNegativeInt(v.reasoningTokens),
1442
+ outputTokens: toNonNegativeInt(v.outputTokens)
1443
+ };
1444
+ }
1445
+ function parseRunTurns(value) {
1446
+ if (typeof value !== "number" || !Number.isFinite(value)) return void 0;
1447
+ return Math.max(0, Math.trunc(value));
1448
+ }
1449
+ function parseRunModel(value) {
1450
+ if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
1451
+ const v = value;
1452
+ const out = {
1453
+ id: typeof v.id === "string" ? v.id : "",
1454
+ provider: typeof v.provider === "string" ? v.provider : "",
1455
+ vendorModelId: typeof v.vendorModelId === "string" ? v.vendorModelId : ""
1456
+ };
1457
+ if (typeof v.reasoningEffort === "string" && v.reasoningEffort.length > 0) {
1458
+ out.reasoningEffort = v.reasoningEffort;
1459
+ }
1460
+ return out;
1461
+ }
1462
+ function toNonNegativeInt(value) {
1463
+ if (typeof value !== "number" || !Number.isFinite(value)) return 0;
1464
+ return Math.max(0, Math.trunc(value));
1465
+ }
1387
1466
  function resolveCredential(opts) {
1388
1467
  const apiKey = typeof opts.apiKey === "string" ? opts.apiKey : "";
1389
1468
  const accessToken = typeof opts.accessToken === "string" ? opts.accessToken : "";
@@ -1640,7 +1719,7 @@ function normalizeScope(scope) {
1640
1719
  }
1641
1720
 
1642
1721
  // src/version.ts
1643
- var SDK_VERSION = "0.10.1";
1722
+ var SDK_VERSION = "0.12.0";
1644
1723
  // Annotate the CommonJS export names for ESM import in node:
1645
1724
  0 && (module.exports = {
1646
1725
  AgentSession,