@mantyx/sdk 0.12.0 → 0.13.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.
@@ -886,6 +886,13 @@ interface RunSpec extends AgentSpecBase {
886
886
  signal?: AbortSignal;
887
887
  }
888
888
  type SessionSpec = AgentSpecBase;
889
+ /**
890
+ * Either a Zod schema (auto-converted to JSON Schema by the SDK) or a
891
+ * pre-shaped JSON Schema object. Mirrors {@link LocalToolSchemaInput} and
892
+ * Go's `OutputSchema.Schema any` (struct reflection) — pass your
893
+ * source-of-truth schema and the SDK serialises it for the wire.
894
+ */
895
+ type OutputSchemaValue = LocalToolSchemaInput;
889
896
  /**
890
897
  * Constrains the final assistant text to a JSON document matching a
891
898
  * JSON Schema. See {@link AgentSpecBase.outputSchema} for the full
@@ -894,8 +901,8 @@ type SessionSpec = AgentSpecBase;
894
901
  interface OutputSchema {
895
902
  /** Optional. Defaults to `"output"`. Must match `/^[a-zA-Z0-9_-]{1,64}$/`. */
896
903
  name?: string;
897
- /** Required. JSON Schema describing the final assistant text. Root must be a JSON object. */
898
- schema: Record<string, unknown>;
904
+ /** Required. Zod schema or JSON Schema describing the final assistant text. Root must be a JSON object. */
905
+ schema: OutputSchemaValue;
899
906
  }
900
907
  /**
901
908
  * Loop-detection thresholds. See {@link AgentSpecBase.loopDetection} for the
@@ -1287,7 +1294,17 @@ interface CancelledEvent extends RunEventBase {
1287
1294
  type: "cancelled";
1288
1295
  reason?: string;
1289
1296
  }
1290
- type RunEvent = AssistantDeltaEvent | ThinkingDeltaEvent | AssistantMessageEvent | ServerToolResultEvent | LocalToolCallEvent | LocalToolResultInEvent | LoopDetectedEvent | ToolBudgetExceededEvent | SupervisorEvent | ResultEvent | ErrorEvent | CancelledEvent | (RunEventBase & {
1297
+ /**
1298
+ * Replay/restore-only frame returned by {@link MantyxClient.getSessionEvents}
1299
+ * (and the `GET /agent-sessions/:id/events` endpoint). The live SSE stream
1300
+ * never emits this — the client already knows the prompt it sent — but
1301
+ * conversation restoration needs it to rebuild the user side of the thread.
1302
+ */
1303
+ interface UserMessageEvent extends RunEventBase {
1304
+ type: "user_message";
1305
+ text: string;
1306
+ }
1307
+ type RunEvent = AssistantDeltaEvent | ThinkingDeltaEvent | AssistantMessageEvent | UserMessageEvent | ServerToolResultEvent | LocalToolCallEvent | LocalToolResultInEvent | LoopDetectedEvent | ToolBudgetExceededEvent | SupervisorEvent | ResultEvent | ErrorEvent | CancelledEvent | (RunEventBase & {
1291
1308
  type: string;
1292
1309
  [key: string]: unknown;
1293
1310
  });
@@ -1306,6 +1323,25 @@ interface SessionInfo {
1306
1323
  /** Metadata that was attached to the session at create time, returned for observability. */
1307
1324
  metadata: Record<string, string>;
1308
1325
  }
1326
+ /** One row from {@link MantyxClient.listSessions}. */
1327
+ interface SessionSummary {
1328
+ sessionId: string;
1329
+ /** ISO 8601 creation timestamp. */
1330
+ creationDate: string;
1331
+ /** ISO 8601 timestamp of the most recent message run. */
1332
+ lastInteractionDate: string;
1333
+ /** Best-effort label derived from the first user prompt (sessions have no title). */
1334
+ summary: string;
1335
+ metadata: Record<string, string>;
1336
+ status: "active" | "ended";
1337
+ }
1338
+ /** Paginated result of {@link MantyxClient.listSessions}. */
1339
+ interface SessionListResult {
1340
+ total: number;
1341
+ limit: number;
1342
+ offset: number;
1343
+ sessions: SessionSummary[];
1344
+ }
1309
1345
  declare class MantyxClient {
1310
1346
  readonly options: Required<Pick<MantyxClientOptions, "workspaceSlug" | "baseUrl">> & {
1311
1347
  /**
@@ -1350,6 +1386,29 @@ declare class MantyxClient {
1350
1386
  }): Promise<AgentSession>;
1351
1387
  endSession(sessionId: string): Promise<void>;
1352
1388
  getSessionInfo(sessionId: string): Promise<SessionInfo>;
1389
+ /**
1390
+ * List the workspace's sessions, most-recently-used first. Filter by the
1391
+ * metadata you attached at create time so you can find earlier sessions by
1392
+ * your own identifiers (customer id, environment, …). Multiple metadata
1393
+ * entries are AND-combined server-side.
1394
+ */
1395
+ listSessions(opts?: {
1396
+ metadata?: Record<string, string>;
1397
+ status?: "active" | "ended";
1398
+ limit?: number;
1399
+ offset?: number;
1400
+ }): Promise<SessionListResult>;
1401
+ /**
1402
+ * Fetch a session's conversation as realtime-style event frames so a UI can
1403
+ * restore the thread through the same handler it uses for the live stream.
1404
+ * Returns `user_message` / `assistant_message` frames (see the wire protocol
1405
+ * §6.2). Pass `lastMessages` to fetch only the most recent turns, or
1406
+ * `full: true` for the entire history (the default).
1407
+ */
1408
+ getSessionEvents(sessionId: string, opts?: {
1409
+ full?: boolean;
1410
+ lastMessages?: number;
1411
+ }): Promise<RunEvent[]>;
1353
1412
  /** Drive an existing run to completion (collect events, dispatch local tools). */
1354
1413
  driveRun(runId: string, handlers: LocalHandlers, opts?: {
1355
1414
  onAssistantDelta?: (delta: string) => void;
@@ -1389,6 +1448,11 @@ declare class MantyxClient {
1389
1448
  method: string;
1390
1449
  path: string;
1391
1450
  body?: unknown;
1451
+ /**
1452
+ * Optional query params. Array values are repeated (`?k=a&k=b`); `undefined`
1453
+ * entries are dropped. Used by the list endpoints (e.g. repeated `metadata`).
1454
+ */
1455
+ query?: Record<string, string | string[] | number | undefined>;
1392
1456
  timeoutMs?: number;
1393
1457
  }): Promise<T>;
1394
1458
  private requestWithRetry;
@@ -1495,4 +1559,4 @@ interface LocalHandlers {
1495
1559
  */
1496
1560
  declare function parseRunOutput<T = unknown>(result: RunResult, validator?: (value: unknown) => T): T;
1497
1561
 
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 };
1562
+ export { type RevokeOptions 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, type OutputSchema as O, MantyxToolError as P, type MantyxToolRef as Q, type ReasoningLevel as R, type McpToolRef as S, type ToolRef as T, type ModelCatalog as U, type ModelInfo as V, type OAuthToken as W, type OutputSchemaValue as X, type RefreshOptions as Y, type RefreshTokenSourceOptions as Z, type ResultEvent as _, AgentSession as a, type RunEvent as a0, type RunEventBase as a1, type RunModelInfo as a2, type RunResult as a3, type RunSpec as a4, type RunTokenUsage as a5, type ServerToolResultEvent as a6, type SessionInfo as a7, type SessionListResult as a8, type SessionSpec as a9, type SessionSummary as aa, type Supervisor as ab, type SupervisorAction as ac, type SupervisorEvent as ad, type ThinkingDeltaEvent as ae, type TokenRequestReason as af, type TokenSource as ag, type ToolBudget as ah, type ToolBudgetExceededEvent as ai, type ToolBudgets as aj, type UserMessageEvent as ak, type ZodLikeObject as al, defineLocalA2A as am, defineLocalMcp as an, defineLocalTool as ao, isLocalA2ATool as ap, isLocalMcpServer as aq, isLocalTool as ar, mantyxA2A as as, mantyxMcp as at, mantyxPluginTool as au, mantyxTool as av, parseRunOutput as aw, 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
@@ -658,6 +658,19 @@ function toToolParametersWire(parameters) {
658
658
 
659
659
  // src/client.ts
660
660
  var DEFAULT_BASE_URL = "https://app.mantyx.io";
661
+ function buildQueryString(query) {
662
+ if (!query) return "";
663
+ const parts = [];
664
+ for (const [key, value] of Object.entries(query)) {
665
+ if (value === void 0) continue;
666
+ const values = Array.isArray(value) ? value : [value];
667
+ for (const v of values) {
668
+ if (v === void 0) continue;
669
+ parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(v))}`);
670
+ }
671
+ }
672
+ return parts.length > 0 ? `?${parts.join("&")}` : "";
673
+ }
661
674
  var MantyxClient = class {
662
675
  options;
663
676
  constructor(opts) {
@@ -775,6 +788,47 @@ var MantyxClient = class {
775
788
  path: `/agent-sessions/${encodeURIComponent(sessionId)}`
776
789
  });
777
790
  }
791
+ /**
792
+ * List the workspace's sessions, most-recently-used first. Filter by the
793
+ * metadata you attached at create time so you can find earlier sessions by
794
+ * your own identifiers (customer id, environment, …). Multiple metadata
795
+ * entries are AND-combined server-side.
796
+ */
797
+ async listSessions(opts = {}) {
798
+ const query = {};
799
+ if (opts.metadata) {
800
+ const pairs = Object.entries(opts.metadata).map(([k, v]) => `${k}:${v}`);
801
+ if (pairs.length > 0) query.metadata = pairs;
802
+ }
803
+ if (opts.status) query.status = opts.status;
804
+ if (typeof opts.limit === "number") query.limit = opts.limit;
805
+ if (typeof opts.offset === "number") query.offset = opts.offset;
806
+ return this.request({
807
+ method: "GET",
808
+ path: "/agent-sessions",
809
+ query
810
+ });
811
+ }
812
+ /**
813
+ * Fetch a session's conversation as realtime-style event frames so a UI can
814
+ * restore the thread through the same handler it uses for the live stream.
815
+ * Returns `user_message` / `assistant_message` frames (see the wire protocol
816
+ * §6.2). Pass `lastMessages` to fetch only the most recent turns, or
817
+ * `full: true` for the entire history (the default).
818
+ */
819
+ async getSessionEvents(sessionId, opts = {}) {
820
+ const query = {};
821
+ if (opts.full) query.full = "1";
822
+ else if (typeof opts.lastMessages === "number") {
823
+ query.lastMessages = opts.lastMessages;
824
+ }
825
+ const res = await this.request({
826
+ method: "GET",
827
+ path: `/agent-sessions/${encodeURIComponent(sessionId)}/events`,
828
+ query
829
+ });
830
+ return res.events ?? [];
831
+ }
778
832
  // ----------------------------------------------------------- Internals
779
833
  /** Drive an existing run to completion (collect events, dispatch local tools). */
780
834
  async driveRun(runId, handlers, opts = {}) {
@@ -993,7 +1047,7 @@ var MantyxClient = class {
993
1047
  return this.requestWithRetry(args, "initial");
994
1048
  }
995
1049
  async requestWithRetry(args, reason) {
996
- const url = this.absoluteUrl(args.path);
1050
+ const url = this.absoluteUrl(args.path) + buildQueryString(args.query);
997
1051
  const ctrl = new AbortController();
998
1052
  const t = setTimeout(() => ctrl.abort(), args.timeoutMs ?? this.options.timeoutMs);
999
1053
  try {
@@ -1283,10 +1337,12 @@ function normalizeOutputSchema(value) {
1283
1337
  }
1284
1338
  out.name = value.name;
1285
1339
  }
1286
- const schema = value.schema;
1340
+ const schema = toToolParametersWire(
1341
+ value.schema
1342
+ );
1287
1343
  if (!schema || typeof schema !== "object" || Array.isArray(schema)) {
1288
1344
  throw new MantyxError(
1289
- `outputSchema.schema must be a non-null JSON object (the JSON Schema root)`
1345
+ `outputSchema.schema must be a Zod schema or a non-null JSON object (the JSON Schema root)`
1290
1346
  );
1291
1347
  }
1292
1348
  out.schema = schema;
@@ -1719,7 +1775,7 @@ function normalizeScope(scope) {
1719
1775
  }
1720
1776
 
1721
1777
  // src/version.ts
1722
- var SDK_VERSION = "0.12.0";
1778
+ var SDK_VERSION = "0.13.0";
1723
1779
  // Annotate the CommonJS export names for ESM import in node:
1724
1780
  0 && (module.exports = {
1725
1781
  AgentSession,