@mantyx/sdk 0.12.0 → 0.14.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
@@ -56,6 +56,7 @@ __export(index_exports, {
56
56
  mantyxPluginTool: () => mantyxPluginTool,
57
57
  mantyxTool: () => mantyxTool,
58
58
  parseRunOutput: () => parseRunOutput,
59
+ planOnly: () => planOnly,
59
60
  readSseStream: () => readSseStream,
60
61
  toToolParametersWire: () => toToolParametersWire,
61
62
  zodToJsonSchema: () => zodToJsonSchema
@@ -658,6 +659,26 @@ function toToolParametersWire(parameters) {
658
659
 
659
660
  // src/client.ts
660
661
  var DEFAULT_BASE_URL = "https://app.mantyx.io";
662
+ function planOnly(options = {}) {
663
+ return {
664
+ planOnly: true,
665
+ ...options.steps !== void 0 ? { steps: options.steps } : {},
666
+ ...options.brief !== void 0 ? { brief: options.brief } : {}
667
+ };
668
+ }
669
+ function buildQueryString(query) {
670
+ if (!query) return "";
671
+ const parts = [];
672
+ for (const [key, value] of Object.entries(query)) {
673
+ if (value === void 0) continue;
674
+ const values = Array.isArray(value) ? value : [value];
675
+ for (const v of values) {
676
+ if (v === void 0) continue;
677
+ parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(v))}`);
678
+ }
679
+ }
680
+ return parts.length > 0 ? `?${parts.join("&")}` : "";
681
+ }
661
682
  var MantyxClient = class {
662
683
  options;
663
684
  constructor(opts) {
@@ -710,6 +731,24 @@ var MantyxClient = class {
710
731
  await closeMcpRefs(tools);
711
732
  }
712
733
  }
734
+ /**
735
+ * Plan-only run: classify (or accept caller `steps`) and return the
736
+ * structured checklist without executing the agent loop. Sugar for
737
+ * `runAgent({ ..., plan: planOnly({ steps, brief }) })`.
738
+ *
739
+ * The final checklist is on {@link RunResult.plan}; intermediate
740
+ * progress is available via `task_plan` events when streaming.
741
+ */
742
+ async runPlan(spec) {
743
+ const { steps, brief, ...rest } = spec;
744
+ return this.runAgent({
745
+ ...rest,
746
+ plan: planOnly({
747
+ ...steps !== void 0 ? { steps } : {},
748
+ ...brief !== void 0 ? { brief } : {}
749
+ })
750
+ });
751
+ }
713
752
  async *streamAgent(spec) {
714
753
  const tools = spec.tools ?? [];
715
754
  await resolveLocalRefs(tools, { fetch: this.options.fetch });
@@ -775,6 +814,47 @@ var MantyxClient = class {
775
814
  path: `/agent-sessions/${encodeURIComponent(sessionId)}`
776
815
  });
777
816
  }
817
+ /**
818
+ * List the workspace's sessions, most-recently-used first. Filter by the
819
+ * metadata you attached at create time so you can find earlier sessions by
820
+ * your own identifiers (customer id, environment, …). Multiple metadata
821
+ * entries are AND-combined server-side.
822
+ */
823
+ async listSessions(opts = {}) {
824
+ const query = {};
825
+ if (opts.metadata) {
826
+ const pairs = Object.entries(opts.metadata).map(([k, v]) => `${k}:${v}`);
827
+ if (pairs.length > 0) query.metadata = pairs;
828
+ }
829
+ if (opts.status) query.status = opts.status;
830
+ if (typeof opts.limit === "number") query.limit = opts.limit;
831
+ if (typeof opts.offset === "number") query.offset = opts.offset;
832
+ return this.request({
833
+ method: "GET",
834
+ path: "/agent-sessions",
835
+ query
836
+ });
837
+ }
838
+ /**
839
+ * Fetch a session's conversation as realtime-style event frames so a UI can
840
+ * restore the thread through the same handler it uses for the live stream.
841
+ * Returns `user_message` / `assistant_message` frames (see the wire protocol
842
+ * §6.2). Pass `lastMessages` to fetch only the most recent turns, or
843
+ * `full: true` for the entire history (the default).
844
+ */
845
+ async getSessionEvents(sessionId, opts = {}) {
846
+ const query = {};
847
+ if (opts.full) query.full = "1";
848
+ else if (typeof opts.lastMessages === "number") {
849
+ query.lastMessages = opts.lastMessages;
850
+ }
851
+ const res = await this.request({
852
+ method: "GET",
853
+ path: `/agent-sessions/${encodeURIComponent(sessionId)}/events`,
854
+ query
855
+ });
856
+ return res.events ?? [];
857
+ }
778
858
  // ----------------------------------------------------------- Internals
779
859
  /** Drive an existing run to completion (collect events, dispatch local tools). */
780
860
  async driveRun(runId, handlers, opts = {}) {
@@ -783,6 +863,7 @@ var MantyxClient = class {
783
863
  let tokens;
784
864
  let turns;
785
865
  let modelInfo;
866
+ let plan;
786
867
  for await (const ev of this.streamRunEvents(runId, handlers, opts.signal)) {
787
868
  collected.push(ev);
788
869
  if (opts.onEvent) opts.onEvent(ev);
@@ -796,6 +877,10 @@ var MantyxClient = class {
796
877
  modelInfo = parseRunModel(r.model) ?? modelInfo;
797
878
  if (r.subtype === "success") {
798
879
  finalText = typeof r.text === "string" ? r.text : "";
880
+ const parsedPlan = parseTaskPlan(r.plan);
881
+ if (parsedPlan !== void 0) {
882
+ plan = parsedPlan;
883
+ }
799
884
  } else {
800
885
  const errInit = {};
801
886
  if (tokens !== void 0) errInit.tokens = tokens;
@@ -826,6 +911,7 @@ var MantyxClient = class {
826
911
  if (tokens !== void 0) result.tokens = tokens;
827
912
  if (turns !== void 0) result.turns = turns;
828
913
  if (modelInfo !== void 0) result.model = modelInfo;
914
+ if (plan !== void 0) result.plan = plan;
829
915
  return result;
830
916
  }
831
917
  async *streamRunEvents(runId, handlers, signal) {
@@ -993,7 +1079,7 @@ var MantyxClient = class {
993
1079
  return this.requestWithRetry(args, "initial");
994
1080
  }
995
1081
  async requestWithRetry(args, reason) {
996
- const url = this.absoluteUrl(args.path);
1082
+ const url = this.absoluteUrl(args.path) + buildQueryString(args.query);
997
1083
  const ctrl = new AbortController();
998
1084
  const t = setTimeout(() => ctrl.abort(), args.timeoutMs ?? this.options.timeoutMs);
999
1085
  try {
@@ -1105,8 +1191,24 @@ var AgentSession = class {
1105
1191
  if (opts.supervisor !== void 0) {
1106
1192
  body.supervisor = normalizeSupervisor(opts.supervisor);
1107
1193
  }
1194
+ if (opts.plan !== void 0) {
1195
+ body.plan = normalizePlan(opts.plan);
1196
+ }
1108
1197
  return body;
1109
1198
  }
1199
+ /**
1200
+ * Plan-only session turn. Sugar for `send(prompt, { plan: planOnly(...) })`.
1201
+ */
1202
+ async runPlan(prompt, opts = {}) {
1203
+ const { steps, brief, ...rest } = opts;
1204
+ return this.send(prompt, {
1205
+ ...rest,
1206
+ plan: planOnly({
1207
+ ...steps !== void 0 ? { steps } : {},
1208
+ ...brief !== void 0 ? { brief } : {}
1209
+ })
1210
+ });
1211
+ }
1110
1212
  async history() {
1111
1213
  const info = await this.client.getSessionInfo(this.id);
1112
1214
  return info.messages;
@@ -1148,6 +1250,9 @@ function serializeAgentSpec(spec, extra = {}) {
1148
1250
  if (spec.supervisor !== void 0) {
1149
1251
  body.supervisor = normalizeSupervisor(spec.supervisor);
1150
1252
  }
1253
+ if (spec.plan !== void 0) {
1254
+ body.plan = normalizePlan(spec.plan);
1255
+ }
1151
1256
  if (spec.budgets) body.budgets = spec.budgets;
1152
1257
  if (spec.metadata && Object.keys(spec.metadata).length > 0) body.metadata = spec.metadata;
1153
1258
  if (extra.prompt !== void 0) body.prompt = extra.prompt;
@@ -1283,10 +1388,12 @@ function normalizeOutputSchema(value) {
1283
1388
  }
1284
1389
  out.name = value.name;
1285
1390
  }
1286
- const schema = value.schema;
1391
+ const schema = toToolParametersWire(
1392
+ value.schema
1393
+ );
1287
1394
  if (!schema || typeof schema !== "object" || Array.isArray(schema)) {
1288
1395
  throw new MantyxError(
1289
- `outputSchema.schema must be a non-null JSON object (the JSON Schema root)`
1396
+ `outputSchema.schema must be a Zod schema or a non-null JSON object (the JSON Schema root)`
1290
1397
  );
1291
1398
  }
1292
1399
  out.schema = schema;
@@ -1365,6 +1472,61 @@ function normalizeSupervisor(value) {
1365
1472
  }
1366
1473
  return out;
1367
1474
  }
1475
+ function normalizePlan(value) {
1476
+ if (value === true || value === false) return value;
1477
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
1478
+ throw new MantyxError(
1479
+ `plan must be \`true\`, \`false\`, or an object { planOnly?, brief?, steps? }, got ${JSON.stringify(value)}`
1480
+ );
1481
+ }
1482
+ const out = {};
1483
+ if (value.planOnly !== void 0) {
1484
+ if (typeof value.planOnly !== "boolean") {
1485
+ throw new MantyxError(`plan.planOnly must be a boolean, got ${JSON.stringify(value.planOnly)}`);
1486
+ }
1487
+ out.planOnly = value.planOnly;
1488
+ }
1489
+ if (value.brief !== void 0) {
1490
+ if (typeof value.brief !== "string") {
1491
+ throw new MantyxError(`plan.brief must be a string, got ${JSON.stringify(value.brief)}`);
1492
+ }
1493
+ out.brief = value.brief;
1494
+ }
1495
+ if (value.steps !== void 0) {
1496
+ if (!Array.isArray(value.steps)) {
1497
+ throw new MantyxError(`plan.steps must be an array of strings, got ${JSON.stringify(value.steps)}`);
1498
+ }
1499
+ const steps = [];
1500
+ for (let i = 0; i < value.steps.length; i++) {
1501
+ const step = value.steps[i];
1502
+ if (typeof step !== "string") {
1503
+ throw new MantyxError(`plan.steps[${i}] must be a string, got ${JSON.stringify(step)}`);
1504
+ }
1505
+ steps.push(step);
1506
+ }
1507
+ out.steps = steps;
1508
+ }
1509
+ return out;
1510
+ }
1511
+ function parseTaskPlan(raw) {
1512
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
1513
+ const obj = raw;
1514
+ const stepsRaw = obj.steps;
1515
+ if (!Array.isArray(stepsRaw)) return void 0;
1516
+ const steps = [];
1517
+ for (const entry of stepsRaw) {
1518
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
1519
+ const row = entry;
1520
+ const title = row.title;
1521
+ const status = row.status;
1522
+ if (typeof title !== "string" || typeof status !== "string") continue;
1523
+ if (status !== "pending" && status !== "in_progress" && status !== "done") continue;
1524
+ steps.push({ title, status });
1525
+ }
1526
+ const briefRaw = obj.brief;
1527
+ const brief = typeof briefRaw === "string" && briefRaw ? briefRaw : void 0;
1528
+ return { steps, ...brief !== void 0 ? { brief } : {} };
1529
+ }
1368
1530
  function normalizeToolBudgets(value) {
1369
1531
  if (!value || typeof value !== "object" || Array.isArray(value)) {
1370
1532
  throw new MantyxError(
@@ -1719,7 +1881,7 @@ function normalizeScope(scope) {
1719
1881
  }
1720
1882
 
1721
1883
  // src/version.ts
1722
- var SDK_VERSION = "0.12.0";
1884
+ var SDK_VERSION = "0.14.0";
1723
1885
  // Annotate the CommonJS export names for ESM import in node:
1724
1886
  0 && (module.exports = {
1725
1887
  AgentSession,
@@ -1748,6 +1910,7 @@ var SDK_VERSION = "0.12.0";
1748
1910
  mantyxPluginTool,
1749
1911
  mantyxTool,
1750
1912
  parseRunOutput,
1913
+ planOnly,
1751
1914
  readSseStream,
1752
1915
  toToolParametersWire,
1753
1916
  zodToJsonSchema