@mantyx/sdk 0.13.0 → 0.15.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
@@ -48,6 +48,8 @@ __export(index_exports, {
48
48
  defineLocalA2A: () => defineLocalA2A,
49
49
  defineLocalMcp: () => defineLocalMcp,
50
50
  defineLocalTool: () => defineLocalTool,
51
+ inputFileAttachment: () => inputFileAttachment,
52
+ inputFileUrlAttachment: () => inputFileUrlAttachment,
51
53
  isLocalA2ATool: () => isLocalA2ATool,
52
54
  isLocalMcpServer: () => isLocalMcpServer,
53
55
  isLocalTool: () => isLocalTool,
@@ -56,6 +58,7 @@ __export(index_exports, {
56
58
  mantyxPluginTool: () => mantyxPluginTool,
57
59
  mantyxTool: () => mantyxTool,
58
60
  parseRunOutput: () => parseRunOutput,
61
+ planOnly: () => planOnly,
59
62
  readSseStream: () => readSseStream,
60
63
  toToolParametersWire: () => toToolParametersWire,
61
64
  zodToJsonSchema: () => zodToJsonSchema
@@ -658,6 +661,19 @@ function toToolParametersWire(parameters) {
658
661
 
659
662
  // src/client.ts
660
663
  var DEFAULT_BASE_URL = "https://app.mantyx.io";
664
+ function inputFileAttachment(opts) {
665
+ return { type: "input_file", ...opts };
666
+ }
667
+ function inputFileUrlAttachment(opts) {
668
+ return { type: "input_file_url", ...opts };
669
+ }
670
+ function planOnly(options = {}) {
671
+ return {
672
+ planOnly: true,
673
+ ...options.steps !== void 0 ? { steps: options.steps } : {},
674
+ ...options.brief !== void 0 ? { brief: options.brief } : {}
675
+ };
676
+ }
661
677
  function buildQueryString(query) {
662
678
  if (!query) return "";
663
679
  const parts = [];
@@ -711,7 +727,8 @@ var MantyxClient = class {
711
727
  path: "/agent-runs",
712
728
  body: serializeAgentSpec(spec, {
713
729
  prompt: spec.prompt,
714
- messages: spec.messages
730
+ messages: spec.messages,
731
+ attachments: spec.attachments
715
732
  })
716
733
  });
717
734
  return await this.driveRun(created.runId, handlers, {
@@ -723,6 +740,24 @@ var MantyxClient = class {
723
740
  await closeMcpRefs(tools);
724
741
  }
725
742
  }
743
+ /**
744
+ * Plan-only run: classify (or accept caller `steps`) and return the
745
+ * structured checklist without executing the agent loop. Sugar for
746
+ * `runAgent({ ..., plan: planOnly({ steps, brief }) })`.
747
+ *
748
+ * The final checklist is on {@link RunResult.plan}; intermediate
749
+ * progress is available via `task_plan` events when streaming.
750
+ */
751
+ async runPlan(spec) {
752
+ const { steps, brief, ...rest } = spec;
753
+ return this.runAgent({
754
+ ...rest,
755
+ plan: planOnly({
756
+ ...steps !== void 0 ? { steps } : {},
757
+ ...brief !== void 0 ? { brief } : {}
758
+ })
759
+ });
760
+ }
726
761
  async *streamAgent(spec) {
727
762
  const tools = spec.tools ?? [];
728
763
  await resolveLocalRefs(tools, { fetch: this.options.fetch });
@@ -733,7 +768,8 @@ var MantyxClient = class {
733
768
  path: "/agent-runs",
734
769
  body: serializeAgentSpec(spec, {
735
770
  prompt: spec.prompt,
736
- messages: spec.messages
771
+ messages: spec.messages,
772
+ attachments: spec.attachments
737
773
  })
738
774
  });
739
775
  yield* this.streamRunEvents(created.runId, handlers, spec.signal);
@@ -837,6 +873,7 @@ var MantyxClient = class {
837
873
  let tokens;
838
874
  let turns;
839
875
  let modelInfo;
876
+ let plan;
840
877
  for await (const ev of this.streamRunEvents(runId, handlers, opts.signal)) {
841
878
  collected.push(ev);
842
879
  if (opts.onEvent) opts.onEvent(ev);
@@ -850,6 +887,10 @@ var MantyxClient = class {
850
887
  modelInfo = parseRunModel(r.model) ?? modelInfo;
851
888
  if (r.subtype === "success") {
852
889
  finalText = typeof r.text === "string" ? r.text : "";
890
+ const parsedPlan = parseTaskPlan(r.plan);
891
+ if (parsedPlan !== void 0) {
892
+ plan = parsedPlan;
893
+ }
853
894
  } else {
854
895
  const errInit = {};
855
896
  if (tokens !== void 0) errInit.tokens = tokens;
@@ -880,6 +921,7 @@ var MantyxClient = class {
880
921
  if (tokens !== void 0) result.tokens = tokens;
881
922
  if (turns !== void 0) result.turns = turns;
882
923
  if (modelInfo !== void 0) result.model = modelInfo;
924
+ if (plan !== void 0) result.plan = plan;
883
925
  return result;
884
926
  }
885
927
  async *streamRunEvents(runId, handlers, signal) {
@@ -1121,27 +1163,32 @@ var AgentSession = class {
1121
1163
  this.handlers = handlers;
1122
1164
  this.tools = tools ?? [];
1123
1165
  }
1124
- async send(prompt, opts = {}) {
1166
+ async send(promptOrMessages, opts = {}) {
1125
1167
  const created = await this.client.request({
1126
1168
  method: "POST",
1127
1169
  path: `/agent-sessions/${encodeURIComponent(this.id)}/messages`,
1128
- body: this.buildSessionMessageBody(prompt, opts)
1170
+ body: this.buildSessionMessageBody(promptOrMessages, opts)
1129
1171
  });
1130
1172
  return this.client.driveRun(created.runId, this.handlers, {
1131
1173
  ...opts.onAssistantDelta ? { onAssistantDelta: opts.onAssistantDelta } : {},
1132
1174
  ...opts.signal ? { signal: opts.signal } : {}
1133
1175
  });
1134
1176
  }
1135
- async *stream(prompt, opts = {}) {
1177
+ async *stream(promptOrMessages, opts = {}) {
1136
1178
  const created = await this.client.request({
1137
1179
  method: "POST",
1138
1180
  path: `/agent-sessions/${encodeURIComponent(this.id)}/messages`,
1139
- body: this.buildSessionMessageBody(prompt, opts)
1181
+ body: this.buildSessionMessageBody(promptOrMessages, opts)
1140
1182
  });
1141
1183
  yield* this.client.streamRunEvents(created.runId, this.handlers, opts.signal);
1142
1184
  }
1143
- buildSessionMessageBody(prompt, opts) {
1144
- const body = { prompt };
1185
+ buildSessionMessageBody(promptOrMessages, opts) {
1186
+ const body = serializeTurnInput(
1187
+ typeof promptOrMessages === "string" ? { prompt: promptOrMessages, attachments: opts.attachments } : { messages: promptOrMessages }
1188
+ );
1189
+ if (!("prompt" in body) && !("messages" in body)) {
1190
+ throw new MantyxError("Either `prompt` or `messages` is required");
1191
+ }
1145
1192
  if (this.tools.length > 0) body.tools = serializeToolRefs(this.tools);
1146
1193
  if (opts.metadata && Object.keys(opts.metadata).length > 0) body.metadata = opts.metadata;
1147
1194
  if (opts.reasoningLevel !== void 0) {
@@ -1159,8 +1206,24 @@ var AgentSession = class {
1159
1206
  if (opts.supervisor !== void 0) {
1160
1207
  body.supervisor = normalizeSupervisor(opts.supervisor);
1161
1208
  }
1209
+ if (opts.plan !== void 0) {
1210
+ body.plan = normalizePlan(opts.plan);
1211
+ }
1162
1212
  return body;
1163
1213
  }
1214
+ /**
1215
+ * Plan-only session turn. Sugar for `send(prompt, { plan: planOnly(...) })`.
1216
+ */
1217
+ async runPlan(promptOrMessages, opts = {}) {
1218
+ const { steps, brief, ...rest } = opts;
1219
+ return this.send(promptOrMessages, {
1220
+ ...rest,
1221
+ plan: planOnly({
1222
+ ...steps !== void 0 ? { steps } : {},
1223
+ ...brief !== void 0 ? { brief } : {}
1224
+ })
1225
+ });
1226
+ }
1164
1227
  async history() {
1165
1228
  const info = await this.client.getSessionInfo(this.id);
1166
1229
  return info.messages;
@@ -1176,9 +1239,29 @@ var AgentSession = class {
1176
1239
  }
1177
1240
  }
1178
1241
  };
1242
+ function serializeTurnInput(input) {
1243
+ if (input.messages !== void 0) {
1244
+ return { messages: input.messages };
1245
+ }
1246
+ if (input.prompt !== void 0) {
1247
+ if (input.attachments && input.attachments.length > 0) {
1248
+ return {
1249
+ messages: [{ role: "user", content: input.prompt, attachments: input.attachments }]
1250
+ };
1251
+ }
1252
+ return { prompt: input.prompt };
1253
+ }
1254
+ return {};
1255
+ }
1256
+ function hasNonEmptySystemMessage(messages) {
1257
+ return messages?.some((m) => m.role === "system" && m.content.trim().length > 0) ?? false;
1258
+ }
1179
1259
  function serializeAgentSpec(spec, extra = {}) {
1180
- if (!spec.agentId && (typeof spec.systemPrompt !== "string" || spec.systemPrompt.length === 0)) {
1181
- throw new MantyxError("Either `agentId` or `systemPrompt` is required");
1260
+ const messagesForIdentity = extra.messages ?? (extra.attachments?.length ? [{ role: "user", content: extra.prompt ?? "", attachments: extra.attachments }] : void 0);
1261
+ if (!spec.agentId && (typeof spec.systemPrompt !== "string" || spec.systemPrompt.length === 0) && !hasNonEmptySystemMessage(messagesForIdentity)) {
1262
+ throw new MantyxError(
1263
+ "Either `agentId`, `systemPrompt`, or a non-empty `system` message in `messages` is required"
1264
+ );
1182
1265
  }
1183
1266
  const body = {
1184
1267
  tools: serializeToolRefs(spec.tools ?? [])
@@ -1202,10 +1285,12 @@ function serializeAgentSpec(spec, extra = {}) {
1202
1285
  if (spec.supervisor !== void 0) {
1203
1286
  body.supervisor = normalizeSupervisor(spec.supervisor);
1204
1287
  }
1288
+ if (spec.plan !== void 0) {
1289
+ body.plan = normalizePlan(spec.plan);
1290
+ }
1205
1291
  if (spec.budgets) body.budgets = spec.budgets;
1206
1292
  if (spec.metadata && Object.keys(spec.metadata).length > 0) body.metadata = spec.metadata;
1207
- if (extra.prompt !== void 0) body.prompt = extra.prompt;
1208
- if (extra.messages !== void 0) body.messages = extra.messages;
1293
+ Object.assign(body, serializeTurnInput(extra));
1209
1294
  return body;
1210
1295
  }
1211
1296
  function serializeToolRefs(tools) {
@@ -1421,6 +1506,61 @@ function normalizeSupervisor(value) {
1421
1506
  }
1422
1507
  return out;
1423
1508
  }
1509
+ function normalizePlan(value) {
1510
+ if (value === true || value === false) return value;
1511
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
1512
+ throw new MantyxError(
1513
+ `plan must be \`true\`, \`false\`, or an object { planOnly?, brief?, steps? }, got ${JSON.stringify(value)}`
1514
+ );
1515
+ }
1516
+ const out = {};
1517
+ if (value.planOnly !== void 0) {
1518
+ if (typeof value.planOnly !== "boolean") {
1519
+ throw new MantyxError(`plan.planOnly must be a boolean, got ${JSON.stringify(value.planOnly)}`);
1520
+ }
1521
+ out.planOnly = value.planOnly;
1522
+ }
1523
+ if (value.brief !== void 0) {
1524
+ if (typeof value.brief !== "string") {
1525
+ throw new MantyxError(`plan.brief must be a string, got ${JSON.stringify(value.brief)}`);
1526
+ }
1527
+ out.brief = value.brief;
1528
+ }
1529
+ if (value.steps !== void 0) {
1530
+ if (!Array.isArray(value.steps)) {
1531
+ throw new MantyxError(`plan.steps must be an array of strings, got ${JSON.stringify(value.steps)}`);
1532
+ }
1533
+ const steps = [];
1534
+ for (let i = 0; i < value.steps.length; i++) {
1535
+ const step = value.steps[i];
1536
+ if (typeof step !== "string") {
1537
+ throw new MantyxError(`plan.steps[${i}] must be a string, got ${JSON.stringify(step)}`);
1538
+ }
1539
+ steps.push(step);
1540
+ }
1541
+ out.steps = steps;
1542
+ }
1543
+ return out;
1544
+ }
1545
+ function parseTaskPlan(raw) {
1546
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
1547
+ const obj = raw;
1548
+ const stepsRaw = obj.steps;
1549
+ if (!Array.isArray(stepsRaw)) return void 0;
1550
+ const steps = [];
1551
+ for (const entry of stepsRaw) {
1552
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
1553
+ const row = entry;
1554
+ const title = row.title;
1555
+ const status = row.status;
1556
+ if (typeof title !== "string" || typeof status !== "string") continue;
1557
+ if (status !== "pending" && status !== "in_progress" && status !== "done") continue;
1558
+ steps.push({ title, status });
1559
+ }
1560
+ const briefRaw = obj.brief;
1561
+ const brief = typeof briefRaw === "string" && briefRaw ? briefRaw : void 0;
1562
+ return { steps, ...brief !== void 0 ? { brief } : {} };
1563
+ }
1424
1564
  function normalizeToolBudgets(value) {
1425
1565
  if (!value || typeof value !== "object" || Array.isArray(value)) {
1426
1566
  throw new MantyxError(
@@ -1775,7 +1915,7 @@ function normalizeScope(scope) {
1775
1915
  }
1776
1916
 
1777
1917
  // src/version.ts
1778
- var SDK_VERSION = "0.13.0";
1918
+ var SDK_VERSION = "0.15.0";
1779
1919
  // Annotate the CommonJS export names for ESM import in node:
1780
1920
  0 && (module.exports = {
1781
1921
  AgentSession,
@@ -1796,6 +1936,8 @@ var SDK_VERSION = "0.13.0";
1796
1936
  defineLocalA2A,
1797
1937
  defineLocalMcp,
1798
1938
  defineLocalTool,
1939
+ inputFileAttachment,
1940
+ inputFileUrlAttachment,
1799
1941
  isLocalA2ATool,
1800
1942
  isLocalMcpServer,
1801
1943
  isLocalTool,
@@ -1804,6 +1946,7 @@ var SDK_VERSION = "0.13.0";
1804
1946
  mantyxPluginTool,
1805
1947
  mantyxTool,
1806
1948
  parseRunOutput,
1949
+ planOnly,
1807
1950
  readSseStream,
1808
1951
  toToolParametersWire,
1809
1952
  zodToJsonSchema