@mantyx/sdk 2026.11.6 → 2026.11.7
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 +23 -0
- package/README.md +10 -59
- package/dist/a2a-server.cjs +2 -4
- package/dist/a2a-server.d.ts +5 -8
- package/dist/a2a-server.js +3 -5
- package/dist/{chunk-4WXIAVUB.js → chunk-HZGH34UW.js} +2 -198
- package/dist/client.d.ts +4 -199
- package/dist/decisions.d.ts +1 -1
- package/dist/index.cjs +3 -201
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -6
- package/dist/tools.d.ts +1 -13
- package/dist/version.d.ts +1 -1
- package/docs/agent-runs-protocol.md +92 -169
- package/docs/wire-protocol.md +37 -65
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -30,6 +30,29 @@ and new releases use calendar versions (`YYYY.M.RELEASE`). Historical versions r
|
|
|
30
30
|
|
|
31
31
|
### Removed
|
|
32
32
|
|
|
33
|
+
- **Breaking:** everything that depended on the MANTYX agent workspace is gone.
|
|
34
|
+
MANTYX is a developer platform: agents are defined inline on each call.
|
|
35
|
+
- Persisted agents: `agentId` on `runAgent` / `streamAgent` / `runPlan` /
|
|
36
|
+
`createSession` specs (`AgentSpecBase.agentId`) and on
|
|
37
|
+
`MantyxAgentSpec` (`@mantyx/sdk/a2a-server`). `systemPrompt` (or a
|
|
38
|
+
non-empty `system` message in `messages`) is required again.
|
|
39
|
+
- Stored and plugin tool refs: `mantyxTool`, `mantyxPluginTool`,
|
|
40
|
+
`MantyxToolRef`, `MantyxPluginToolRef` and the `mantyx` / `mantyx_plugin`
|
|
41
|
+
wire kinds. `ToolRef` is now `local | a2a | a2a_local | mcp | mcp_local`.
|
|
42
|
+
- Evals: `listEvalDatasets`, `getEvalDataset`, `createEvalRun`,
|
|
43
|
+
`listEvalRuns`, `compareEvalRuns`, `getEvalRun`, `streamEvalRun`,
|
|
44
|
+
`cancelEvalRun`, `runEval` and every `Eval*` type (`EvalRunStatus`,
|
|
45
|
+
`InlineEvalCaseSpec`, `InlineEvalDatasetSpec`, `AgentEvalOverrides`,
|
|
46
|
+
`CreateEvalRunRequest`, `EvalDatasetSummary`, `EvalDatasetList`,
|
|
47
|
+
`EvalCase`, `EvalDatasetDetail`, `EvalRunAccepted`, `EvalRunSummary`,
|
|
48
|
+
`EvalCaseResult`, `EvalRunDetail`, `EvalRunList`, `EvalRunCompareSide`,
|
|
49
|
+
`EvalRunCompareCase`, `EvalRunCompare`, `EvalRunEvent`,
|
|
50
|
+
`ListEvalRunsOptions`, `RunEvalOptions`).
|
|
51
|
+
- The `agent-by-id` and `mixed-tools` examples.
|
|
52
|
+
- The server now ignores a stray `agentId` (the request then fails with
|
|
53
|
+
`400` unless it carries a system prompt) and rejects `mantyx` /
|
|
54
|
+
`mantyx_plugin` tool refs with `400`.
|
|
55
|
+
|
|
33
56
|
- Experimental `newLoop` opt-in for the reviewed harness loop. Agent runs use the existing loop.
|
|
34
57
|
|
|
35
58
|
### Changed
|
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# @mantyx/sdk
|
|
2
2
|
|
|
3
3
|
The official TypeScript SDK for the [MANTYX](https://mantyx.com) agent
|
|
4
|
-
runtime. Define
|
|
4
|
+
runtime. Define agents inline that mix server-resolved tools with
|
|
5
5
|
locally-executed tools, run them remotely, and stream events back into your
|
|
6
6
|
process.
|
|
7
7
|
|
|
8
8
|
- LLM loop runs on MANTYX (BYOK or platform-hosted models).
|
|
9
|
-
- Server-resolved tools (`
|
|
10
|
-
|
|
9
|
+
- Server-resolved tools (`a2a`, `mcp`) execute inside MANTYX — remote
|
|
10
|
+
Agent2Agent peers and remote MCP servers that MANTYX dials for you.
|
|
11
11
|
- Client-resolved tools (`local`, `a2a_local`, `mcp_local`) execute inside
|
|
12
12
|
*your* process; the SDK shuttles inputs and outputs over an SSE stream +
|
|
13
13
|
a tool-result POST.
|
|
@@ -43,7 +43,7 @@ transports). The MCP SDK is loaded lazily — apps that never use
|
|
|
43
43
|
```ts
|
|
44
44
|
import { z } from "zod";
|
|
45
45
|
import fs from "node:fs/promises";
|
|
46
|
-
import { MantyxClient, defineLocalTool
|
|
46
|
+
import { MantyxClient, defineLocalTool } from "@mantyx/sdk";
|
|
47
47
|
|
|
48
48
|
const client = new MantyxClient({
|
|
49
49
|
// Use *either* `apiKey` (workspace API key, token prefix `mantyx_`) or
|
|
@@ -67,8 +67,6 @@ const result = await client.runAgent({
|
|
|
67
67
|
parameters: z.object({ path: z.string() }),
|
|
68
68
|
execute: async ({ path }) => fs.readFile(path, "utf8"),
|
|
69
69
|
}),
|
|
70
|
-
// Reference to an existing MANTYX workspace tool.
|
|
71
|
-
mantyxTool("tool_cm6abc123"),
|
|
72
70
|
],
|
|
73
71
|
});
|
|
74
72
|
|
|
@@ -79,47 +77,6 @@ The SDK opens an SSE stream to MANTYX, listens for `local_tool_call` events,
|
|
|
79
77
|
runs the matching local handler, and POSTs the result back. The server keeps
|
|
80
78
|
running the agent loop until it produces a final reply.
|
|
81
79
|
|
|
82
|
-
## Triggering a persisted MANTYX agent
|
|
83
|
-
|
|
84
|
-
Pass `agentId` to run an agent that already exists in your workspace. The
|
|
85
|
-
server hydrates the agent's system prompt, model, and server-side tools
|
|
86
|
-
(memory, skills, plugin tools, …) from the `Agent` row at run time. Anything
|
|
87
|
-
you pass in `tools` is **merged on top** — typically `local` tools you want
|
|
88
|
-
the agent to be able to call back into for this specific run.
|
|
89
|
-
|
|
90
|
-
```ts
|
|
91
|
-
import { defineLocalTool, MantyxClient } from "@mantyx/sdk";
|
|
92
|
-
import { z } from "zod";
|
|
93
|
-
|
|
94
|
-
const client = new MantyxClient({ apiKey: "...", workspaceSlug: "acme" });
|
|
95
|
-
|
|
96
|
-
const result = await client.runAgent({
|
|
97
|
-
agentId: "agent_cm6abc123", // workspace agent id
|
|
98
|
-
prompt: "Pull the latest deploy logs and summarise them.",
|
|
99
|
-
tools: [
|
|
100
|
-
defineLocalTool({
|
|
101
|
-
name: "read_local_file",
|
|
102
|
-
parameters: z.object({ path: z.string() }),
|
|
103
|
-
execute: ({ path }) => readFileSync(path, "utf8"),
|
|
104
|
-
}),
|
|
105
|
-
],
|
|
106
|
-
});
|
|
107
|
-
console.log(result.text);
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
Notes:
|
|
111
|
-
|
|
112
|
-
- `systemPrompt` becomes optional when `agentId` is set; if both are sent,
|
|
113
|
-
the agent's stored prompt wins.
|
|
114
|
-
- `modelId` is also optional: omit it to use the agent's configured LLM
|
|
115
|
-
provider, or pass it to override the model for this run.
|
|
116
|
-
- The API key must be authorized for the agent (an empty `agentIds` allowlist
|
|
117
|
-
on the key counts as "all agents in the workspace"). Otherwise the call
|
|
118
|
-
returns `403`.
|
|
119
|
-
|
|
120
|
-
The same `agentId` field works on `client.createSession({ ... })` for
|
|
121
|
-
multi-turn conversations against a persisted agent.
|
|
122
|
-
|
|
123
80
|
## Agent2Agent delegation
|
|
124
81
|
|
|
125
82
|
Hand a turn off to another agent — either a remote peer MANTYX dials directly
|
|
@@ -165,15 +122,12 @@ caches the resolved card on the tool ref for the duration of the run /
|
|
|
165
122
|
session — re-construct the ref to force a refetch.
|
|
166
123
|
|
|
167
124
|
> **Headers and secrets.** The `headers` you pass to `mantyxA2A` are forwarded
|
|
168
|
-
> as-is.
|
|
169
|
-
> `ExternalAgent` instead — those headers support `{{secret:NAME}}`
|
|
170
|
-
> placeholders. Use `mantyxA2A` for short-lived, per-run tokens minted by
|
|
171
|
-
> your application.
|
|
125
|
+
> as-is. Prefer short-lived, per-run tokens minted by your application.
|
|
172
126
|
|
|
173
127
|
### Exposing an agent over A2A
|
|
174
128
|
|
|
175
|
-
The inverse direction also works: wrap a MANTYX agent
|
|
176
|
-
|
|
129
|
+
The inverse direction also works: wrap a MANTYX agent spec and serve it as an
|
|
130
|
+
Agent2Agent peer using the official
|
|
177
131
|
[`@a2a-js/sdk`](https://www.npmjs.com/package/@a2a-js/sdk) library. Other
|
|
178
132
|
agents can then discover it at `/.well-known/agent-card.json` and call
|
|
179
133
|
`message/send` over JSON-RPC — including MANTYX agents elsewhere in your
|
|
@@ -188,7 +142,7 @@ const client = new MantyxClient({ apiKey: "...", workspaceSlug: "acme" });
|
|
|
188
142
|
|
|
189
143
|
const handle = await serveAgentOverA2A({
|
|
190
144
|
client,
|
|
191
|
-
agent: {
|
|
145
|
+
agent: { systemPrompt: "You are Acme's support agent." }, // plus modelId, tools, …
|
|
192
146
|
port: 4000,
|
|
193
147
|
agentCard: AgentCard.fromJSON({
|
|
194
148
|
name: "Acme Support",
|
|
@@ -298,7 +252,7 @@ await client.runAgent({
|
|
|
298
252
|
|
|
299
253
|
| Form | Values | Notes |
|
|
300
254
|
| ------------ | -------------------------------------------- | ----- |
|
|
301
|
-
| String | `"off"`, `"low"`, `"medium"`, `"high"` | Snaps to
|
|
255
|
+
| String | `"off"`, `"low"`, `"medium"`, `"high"` | Snaps to fixed anchors: off=0, low=30, medium=50, high=80. |
|
|
302
256
|
| Number | integer `0`–`100` | `0` explicitly disables provider thinking on reasoning models. |
|
|
303
257
|
|
|
304
258
|
The server maps this onto each LLM's native dial — `reasoning.effort` for
|
|
@@ -475,7 +429,7 @@ the dashboard by it (Agent runs → "Metadata" filter):
|
|
|
475
429
|
await client.runAgent({
|
|
476
430
|
systemPrompt: "...",
|
|
477
431
|
prompt: "...",
|
|
478
|
-
metadata: { customer: "acme", env: "prod",
|
|
432
|
+
metadata: { customer: "acme", env: "prod", feature: "support_triage" },
|
|
479
433
|
});
|
|
480
434
|
|
|
481
435
|
// Session — every run created via `session.send` inherits these tags
|
|
@@ -588,8 +542,6 @@ Opt-in multi-step checklists. Pass `plan: true` (auto-classify + live tracking)
|
|
|
588
542
|
| `defineLocalTool(opts)` | Define a local tool with a Zod parameter schema and handler. |
|
|
589
543
|
| `defineLocalA2A(opts)` | Local Agent2Agent peer — pass an `agentCardUrl`; the SDK fetches the card and speaks `message/send` for you. |
|
|
590
544
|
| `defineLocalMcp(opts)` | Local MCP server — pass either a Streamable HTTP `url` or an stdio `command`; the SDK runs `Initialize` + `tools/list` + `tools/call` for you. |
|
|
591
|
-
| `mantyxTool(id)` | Reference an existing MANTYX tool by id. |
|
|
592
|
-
| `mantyxPluginTool(name)` | Reference an installed platform plugin tool by name. |
|
|
593
545
|
| `mantyxA2A(opts)` | Remote Agent2Agent peer reachable from MANTYX (server-resolved). |
|
|
594
546
|
| `mantyxMcp(opts)` | Remote MCP server (Streamable HTTP) MANTYX dials and proxies for you. |
|
|
595
547
|
|
|
@@ -679,7 +631,6 @@ Self-contained example projects live under [`examples/`](./examples/):
|
|
|
679
631
|
|
|
680
632
|
- `examples/oneshot-local-tool` — minimal one-shot run with a local tool.
|
|
681
633
|
- `examples/session-chat` — interactive REPL on top of a session.
|
|
682
|
-
- `examples/mixed-tools` — combines local, MANTYX, and plugin tools.
|
|
683
634
|
- `examples/streaming` — token streaming to stdout.
|
|
684
635
|
- `examples/list-models` — model catalog + pick-and-run.
|
|
685
636
|
- `examples/a2a-tools` — remote (`mantyxA2A`) + local (`defineLocalA2A`) Agent2Agent peers.
|
package/dist/a2a-server.cjs
CHANGED
|
@@ -319,7 +319,6 @@ function extractText(message) {
|
|
|
319
319
|
}
|
|
320
320
|
function specForRun(spec) {
|
|
321
321
|
const out = {};
|
|
322
|
-
if (spec.agentId) out.agentId = spec.agentId;
|
|
323
322
|
if (spec.systemPrompt) out.systemPrompt = spec.systemPrompt;
|
|
324
323
|
if (spec.modelId) out.modelId = spec.modelId;
|
|
325
324
|
if (spec.tools) out.tools = spec.tools;
|
|
@@ -333,7 +332,6 @@ function specForRun(spec) {
|
|
|
333
332
|
}
|
|
334
333
|
function specForSession(spec, contextId) {
|
|
335
334
|
const out = {};
|
|
336
|
-
if (spec.agentId) out.agentId = spec.agentId;
|
|
337
335
|
if (spec.systemPrompt) out.systemPrompt = spec.systemPrompt;
|
|
338
336
|
if (spec.modelId) out.modelId = spec.modelId;
|
|
339
337
|
if (spec.tools) out.tools = spec.tools;
|
|
@@ -348,9 +346,9 @@ function specForSession(spec, contextId) {
|
|
|
348
346
|
return out;
|
|
349
347
|
}
|
|
350
348
|
function validateAgentSpec(spec) {
|
|
351
|
-
if (!spec.
|
|
349
|
+
if (!spec.systemPrompt || spec.systemPrompt.length === 0) {
|
|
352
350
|
throw new MantyxError(
|
|
353
|
-
"MantyxAgentExecutor: `agent.
|
|
351
|
+
"MantyxAgentExecutor: `agent.systemPrompt` is required"
|
|
354
352
|
);
|
|
355
353
|
}
|
|
356
354
|
}
|
package/dist/a2a-server.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ import type { OpenRouterProviderPreferences } from "./client.js";
|
|
|
22
22
|
* const server = await serveAgentOverA2A({
|
|
23
23
|
* client,
|
|
24
24
|
* port: 4000,
|
|
25
|
-
* agent: {
|
|
25
|
+
* agent: { systemPrompt: "You are Acme's support agent." },
|
|
26
26
|
* agentCard: AgentCard.fromJSON({
|
|
27
27
|
* name: "Acme Support",
|
|
28
28
|
* description: "Answers billing and account questions.",
|
|
@@ -46,16 +46,13 @@ import type { ReasoningLevel, ToolRef } from "./tools.js";
|
|
|
46
46
|
* Description of the MANTYX agent that should answer A2A requests.
|
|
47
47
|
*
|
|
48
48
|
* Mirrors the existing `runAgent` / `createSession` argument shape:
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* agent inline.
|
|
49
|
+
* `systemPrompt` (with optional `modelId`, `tools`, …) defines the agent
|
|
50
|
+
* inline.
|
|
52
51
|
*
|
|
53
|
-
*
|
|
52
|
+
* `systemPrompt` is required.
|
|
54
53
|
*/
|
|
55
54
|
export interface MantyxAgentSpec {
|
|
56
|
-
/**
|
|
57
|
-
agentId?: string;
|
|
58
|
-
/** System prompt for an inline / ephemeral agent. Mutually exclusive with `agentId`. */
|
|
55
|
+
/** System prompt for the inline agent. Required. */
|
|
59
56
|
systemPrompt?: string;
|
|
60
57
|
modelId?: string;
|
|
61
58
|
tools?: ToolRef[];
|
package/dist/a2a-server.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MantyxError,
|
|
3
3
|
MantyxRunError
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-HZGH34UW.js";
|
|
5
5
|
|
|
6
6
|
// src/a2a-server.ts
|
|
7
7
|
import {
|
|
@@ -235,7 +235,6 @@ function extractText(message) {
|
|
|
235
235
|
}
|
|
236
236
|
function specForRun(spec) {
|
|
237
237
|
const out = {};
|
|
238
|
-
if (spec.agentId) out.agentId = spec.agentId;
|
|
239
238
|
if (spec.systemPrompt) out.systemPrompt = spec.systemPrompt;
|
|
240
239
|
if (spec.modelId) out.modelId = spec.modelId;
|
|
241
240
|
if (spec.tools) out.tools = spec.tools;
|
|
@@ -249,7 +248,6 @@ function specForRun(spec) {
|
|
|
249
248
|
}
|
|
250
249
|
function specForSession(spec, contextId) {
|
|
251
250
|
const out = {};
|
|
252
|
-
if (spec.agentId) out.agentId = spec.agentId;
|
|
253
251
|
if (spec.systemPrompt) out.systemPrompt = spec.systemPrompt;
|
|
254
252
|
if (spec.modelId) out.modelId = spec.modelId;
|
|
255
253
|
if (spec.tools) out.tools = spec.tools;
|
|
@@ -264,9 +262,9 @@ function specForSession(spec, contextId) {
|
|
|
264
262
|
return out;
|
|
265
263
|
}
|
|
266
264
|
function validateAgentSpec(spec) {
|
|
267
|
-
if (!spec.
|
|
265
|
+
if (!spec.systemPrompt || spec.systemPrompt.length === 0) {
|
|
268
266
|
throw new MantyxError(
|
|
269
|
-
"MantyxAgentExecutor: `agent.
|
|
267
|
+
"MantyxAgentExecutor: `agent.systemPrompt` is required"
|
|
270
268
|
);
|
|
271
269
|
}
|
|
272
270
|
}
|
|
@@ -115,20 +115,6 @@ function defineLocalTool(opts) {
|
|
|
115
115
|
execute: opts.execute
|
|
116
116
|
};
|
|
117
117
|
}
|
|
118
|
-
function mantyxTool(id) {
|
|
119
|
-
if (typeof id !== "string" || id.length === 0) {
|
|
120
|
-
throw new Error("mantyxTool(id): id must be a non-empty string");
|
|
121
|
-
}
|
|
122
|
-
return { kind: "mantyx", id };
|
|
123
|
-
}
|
|
124
|
-
function mantyxPluginTool(name) {
|
|
125
|
-
if (typeof name !== "string" || !name.startsWith("@") || !name.includes("/")) {
|
|
126
|
-
throw new Error(
|
|
127
|
-
`mantyxPluginTool(name): expected "@plugin-slug/tool-name", got ${JSON.stringify(name)}`
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
return { kind: "mantyx_plugin", name };
|
|
131
|
-
}
|
|
132
118
|
function mantyxA2A(opts) {
|
|
133
119
|
assertToolName(opts.name);
|
|
134
120
|
if (typeof opts.agentCardUrl !== "string" || opts.agentCardUrl.length === 0) {
|
|
@@ -698,7 +684,6 @@ function inputFileUrlAttachment(opts) {
|
|
|
698
684
|
return { type: "input_file_url", ...opts };
|
|
699
685
|
}
|
|
700
686
|
var RUN_FEEDBACK_EXPLANATION_MAX = 8e3;
|
|
701
|
-
var EVAL_TERMINAL_STATUSES = /* @__PURE__ */ new Set(["succeeded", "failed", "cancelled"]);
|
|
702
687
|
function planOnly(options = {}) {
|
|
703
688
|
return {
|
|
704
689
|
planOnly: true,
|
|
@@ -1153,138 +1138,6 @@ var MantyxClient = class {
|
|
|
1153
1138
|
body
|
|
1154
1139
|
});
|
|
1155
1140
|
}
|
|
1156
|
-
// --------------------------------------------------------------- Evals
|
|
1157
|
-
async listEvalDatasets() {
|
|
1158
|
-
return this.request({
|
|
1159
|
-
method: "GET",
|
|
1160
|
-
path: "/eval-datasets"
|
|
1161
|
-
});
|
|
1162
|
-
}
|
|
1163
|
-
async getEvalDataset(datasetId) {
|
|
1164
|
-
return this.request({
|
|
1165
|
-
method: "GET",
|
|
1166
|
-
path: `/eval-datasets/${encodeURIComponent(datasetId)}`
|
|
1167
|
-
});
|
|
1168
|
-
}
|
|
1169
|
-
async createEvalRun(spec) {
|
|
1170
|
-
const tools = spec.tools ?? [];
|
|
1171
|
-
if (tools.length > 0) {
|
|
1172
|
-
await resolveLocalRefs(tools, { fetch: this.options.fetch });
|
|
1173
|
-
}
|
|
1174
|
-
return this.request({
|
|
1175
|
-
method: "POST",
|
|
1176
|
-
path: "/eval-runs",
|
|
1177
|
-
body: serializeCreateEvalRunRequest(spec)
|
|
1178
|
-
});
|
|
1179
|
-
}
|
|
1180
|
-
async listEvalRuns(options = {}) {
|
|
1181
|
-
const params = new URLSearchParams();
|
|
1182
|
-
if (options.datasetId) params.set("datasetId", options.datasetId);
|
|
1183
|
-
if (options.agentId) params.set("agentId", options.agentId);
|
|
1184
|
-
if (options.status) params.set("status", options.status);
|
|
1185
|
-
if (options.limit !== void 0) params.set("limit", String(options.limit));
|
|
1186
|
-
if (options.offset !== void 0) params.set("offset", String(options.offset));
|
|
1187
|
-
const qs = params.toString();
|
|
1188
|
-
return this.request({
|
|
1189
|
-
method: "GET",
|
|
1190
|
-
path: qs ? `/eval-runs?${qs}` : "/eval-runs"
|
|
1191
|
-
});
|
|
1192
|
-
}
|
|
1193
|
-
async compareEvalRuns(runA, runB) {
|
|
1194
|
-
const params = new URLSearchParams({ a: runA, b: runB });
|
|
1195
|
-
return this.request({
|
|
1196
|
-
method: "GET",
|
|
1197
|
-
path: `/eval-runs/compare?${params}`
|
|
1198
|
-
});
|
|
1199
|
-
}
|
|
1200
|
-
async getEvalRun(runId) {
|
|
1201
|
-
return this.request({
|
|
1202
|
-
method: "GET",
|
|
1203
|
-
path: `/eval-runs/${encodeURIComponent(runId)}`
|
|
1204
|
-
});
|
|
1205
|
-
}
|
|
1206
|
-
async *streamEvalRun(runId, signal) {
|
|
1207
|
-
const url = this.absoluteUrl(`/eval-runs/${encodeURIComponent(runId)}/stream`);
|
|
1208
|
-
const res = await this.openSseStream(url, 0, signal);
|
|
1209
|
-
try {
|
|
1210
|
-
for await (const frame of readSseStream(res.body, { signal })) {
|
|
1211
|
-
if (!frame.data) continue;
|
|
1212
|
-
let parsed;
|
|
1213
|
-
try {
|
|
1214
|
-
parsed = JSON.parse(frame.data);
|
|
1215
|
-
} catch (err) {
|
|
1216
|
-
throw new MantyxParseError(
|
|
1217
|
-
`invalid eval SSE JSON: ${frame.data.slice(0, 200)}`,
|
|
1218
|
-
frame.data,
|
|
1219
|
-
{ cause: err }
|
|
1220
|
-
);
|
|
1221
|
-
}
|
|
1222
|
-
yield parsed;
|
|
1223
|
-
if (parsed.type === "run_completed" || parsed.type === "run_error" || parsed.type === "run_cancelled") {
|
|
1224
|
-
return;
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
} finally {
|
|
1228
|
-
await res.body?.cancel().catch(() => void 0);
|
|
1229
|
-
}
|
|
1230
|
-
}
|
|
1231
|
-
async cancelEvalRun(runId) {
|
|
1232
|
-
return this.request({
|
|
1233
|
-
method: "POST",
|
|
1234
|
-
path: `/eval-runs/${encodeURIComponent(runId)}/cancel`
|
|
1235
|
-
});
|
|
1236
|
-
}
|
|
1237
|
-
/**
|
|
1238
|
-
* Start an eval run and block until it reaches a terminal status.
|
|
1239
|
-
* Tails the SSE stream for live `onEvent` callbacks while polling
|
|
1240
|
-
* `getEvalRun` until `status` is terminal.
|
|
1241
|
-
*/
|
|
1242
|
-
async runEval(spec, options = {}) {
|
|
1243
|
-
const tools = options.tools ?? spec.tools ?? [];
|
|
1244
|
-
if (tools.length > 0) {
|
|
1245
|
-
await resolveLocalRefs(tools, { fetch: this.options.fetch });
|
|
1246
|
-
}
|
|
1247
|
-
const handlers = collectLocalHandlers(tools);
|
|
1248
|
-
try {
|
|
1249
|
-
const accepted = await this.createEvalRun({
|
|
1250
|
-
...spec,
|
|
1251
|
-
...tools.length > 0 ? { tools } : {}
|
|
1252
|
-
});
|
|
1253
|
-
const pollMs = options.pollIntervalMs ?? 1e3;
|
|
1254
|
-
const streamDone = (async () => {
|
|
1255
|
-
try {
|
|
1256
|
-
for await (const ev of this.streamEvalRun(accepted.runId, options.signal)) {
|
|
1257
|
-
if (ev.type === "local_tool_call" && tools.length > 0) {
|
|
1258
|
-
const record = ev;
|
|
1259
|
-
const nested = typeof record.data === "object" && record.data !== null && !Array.isArray(record.data) ? record.data : void 0;
|
|
1260
|
-
const agentRunId = typeof record.agentRunId === "string" ? record.agentRunId : typeof nested?.agentRunId === "string" ? nested.agentRunId : "";
|
|
1261
|
-
if (agentRunId) {
|
|
1262
|
-
const localEv = evalEventToLocalToolCall(ev);
|
|
1263
|
-
await this.dispatchLocalTool(agentRunId, localEv, handlers);
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
options.onEvent?.(ev);
|
|
1267
|
-
}
|
|
1268
|
-
} catch (err) {
|
|
1269
|
-
if (!(err instanceof MantyxNetworkError)) throw err;
|
|
1270
|
-
}
|
|
1271
|
-
})();
|
|
1272
|
-
try {
|
|
1273
|
-
while (true) {
|
|
1274
|
-
if (options.signal?.aborted) {
|
|
1275
|
-
throw new MantyxNetworkError("eval run wait aborted", { cause: options.signal.reason });
|
|
1276
|
-
}
|
|
1277
|
-
const detail = await this.getEvalRun(accepted.runId);
|
|
1278
|
-
if (EVAL_TERMINAL_STATUSES.has(detail.status)) return detail;
|
|
1279
|
-
await sleep(pollMs);
|
|
1280
|
-
}
|
|
1281
|
-
} finally {
|
|
1282
|
-
await streamDone.catch(() => void 0);
|
|
1283
|
-
}
|
|
1284
|
-
} finally {
|
|
1285
|
-
await closeMcpRefs(tools);
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
1141
|
// -------------------------------------------------------------- HTTP
|
|
1289
1142
|
absoluteUrl(path) {
|
|
1290
1143
|
return `${this.options.baseUrl}/api/v1/workspaces/${encodeURIComponent(this.options.workspaceSlug)}${path}`;
|
|
@@ -1549,16 +1402,15 @@ function hasNonEmptySystemMessage(messages) {
|
|
|
1549
1402
|
}
|
|
1550
1403
|
function serializeAgentSpec(spec, extra = {}) {
|
|
1551
1404
|
const messagesForIdentity = extra.messages ?? (extra.attachments?.length ? [{ role: "user", content: extra.prompt ?? "", attachments: extra.attachments }] : void 0);
|
|
1552
|
-
if (
|
|
1405
|
+
if ((typeof spec.systemPrompt !== "string" || spec.systemPrompt.length === 0) && !hasNonEmptySystemMessage(messagesForIdentity)) {
|
|
1553
1406
|
throw new MantyxError(
|
|
1554
|
-
"
|
|
1407
|
+
"`systemPrompt` or a non-empty `system` message in `messages` is required"
|
|
1555
1408
|
);
|
|
1556
1409
|
}
|
|
1557
1410
|
const body = {
|
|
1558
1411
|
tools: serializeToolRefs(spec.tools ?? [])
|
|
1559
1412
|
};
|
|
1560
1413
|
if (typeof spec.systemPrompt === "string") body.systemPrompt = spec.systemPrompt;
|
|
1561
|
-
if (spec.agentId) body.agentId = spec.agentId;
|
|
1562
1414
|
if (spec.name) body.name = spec.name;
|
|
1563
1415
|
if (spec.modelId) body.modelId = spec.modelId;
|
|
1564
1416
|
if (spec.fallbackModelId) body.fallbackModelId = spec.fallbackModelId;
|
|
@@ -1586,55 +1438,9 @@ function serializeAgentSpec(spec, extra = {}) {
|
|
|
1586
1438
|
Object.assign(body, serializeTurnInput(extra));
|
|
1587
1439
|
return body;
|
|
1588
1440
|
}
|
|
1589
|
-
function serializeCreateEvalRunRequest(spec) {
|
|
1590
|
-
const hasDataset = spec.datasetId !== void 0 || spec.dataset !== void 0;
|
|
1591
|
-
const hasAgent = spec.agentId !== void 0 || spec.agent !== void 0;
|
|
1592
|
-
if (!hasDataset) {
|
|
1593
|
-
throw new MantyxError("createEvalRun requires exactly one of `datasetId` or `dataset`");
|
|
1594
|
-
}
|
|
1595
|
-
if (spec.datasetId !== void 0 && spec.dataset !== void 0) {
|
|
1596
|
-
throw new MantyxError("createEvalRun accepts only one of `datasetId` or `dataset`");
|
|
1597
|
-
}
|
|
1598
|
-
if (!hasAgent) {
|
|
1599
|
-
throw new MantyxError("createEvalRun requires exactly one of `agentId` or `agent`");
|
|
1600
|
-
}
|
|
1601
|
-
if (spec.agentId !== void 0 && spec.agent !== void 0) {
|
|
1602
|
-
throw new MantyxError("createEvalRun accepts only one of `agentId` or `agent`");
|
|
1603
|
-
}
|
|
1604
|
-
const body = {};
|
|
1605
|
-
if (spec.datasetId) body.datasetId = spec.datasetId;
|
|
1606
|
-
if (spec.dataset) body.dataset = spec.dataset;
|
|
1607
|
-
if (spec.agentId) body.agentId = spec.agentId;
|
|
1608
|
-
if (spec.agent) body.agent = serializeAgentSpec(spec.agent);
|
|
1609
|
-
if (spec.tools && spec.tools.length > 0 && spec.agentId) {
|
|
1610
|
-
body.tools = serializeToolRefs(spec.tools);
|
|
1611
|
-
}
|
|
1612
|
-
if (spec.modelId) body.modelId = spec.modelId;
|
|
1613
|
-
if (spec.overrides) body.overrides = spec.overrides;
|
|
1614
|
-
return body;
|
|
1615
|
-
}
|
|
1616
|
-
function evalEventToLocalToolCall(ev) {
|
|
1617
|
-
const data = ev.data && typeof ev.data === "object" && !Array.isArray(ev.data) ? ev.data : ev;
|
|
1618
|
-
return {
|
|
1619
|
-
type: "local_tool_call",
|
|
1620
|
-
seq: 0,
|
|
1621
|
-
toolUseId: String(data.toolUseId ?? ""),
|
|
1622
|
-
name: String(data.name ?? ""),
|
|
1623
|
-
args: data.args ?? {},
|
|
1624
|
-
...typeof data.kind === "string" ? { kind: data.kind } : {},
|
|
1625
|
-
...data.agentCard !== void 0 ? { agentCard: data.agentCard } : {},
|
|
1626
|
-
...typeof data.mcpServer === "string" ? { mcpServer: data.mcpServer } : {},
|
|
1627
|
-
...typeof data.mcpToolName === "string" ? { mcpToolName: data.mcpToolName } : {},
|
|
1628
|
-
...data.mcpServerInfo !== void 0 ? { mcpServerInfo: data.mcpServerInfo } : {}
|
|
1629
|
-
};
|
|
1630
|
-
}
|
|
1631
1441
|
function serializeToolRefs(tools) {
|
|
1632
1442
|
return tools.map((t) => {
|
|
1633
1443
|
switch (t.kind) {
|
|
1634
|
-
case "mantyx":
|
|
1635
|
-
return { kind: "mantyx", id: t.id };
|
|
1636
|
-
case "mantyx_plugin":
|
|
1637
|
-
return { kind: "mantyx_plugin", name: t.name };
|
|
1638
1444
|
case "local":
|
|
1639
1445
|
return {
|
|
1640
1446
|
kind: "local",
|
|
@@ -2156,8 +1962,6 @@ export {
|
|
|
2156
1962
|
MantyxRunError,
|
|
2157
1963
|
MantyxParseError,
|
|
2158
1964
|
defineLocalTool,
|
|
2159
|
-
mantyxTool,
|
|
2160
|
-
mantyxPluginTool,
|
|
2161
1965
|
mantyxA2A,
|
|
2162
1966
|
defineLocalA2A,
|
|
2163
1967
|
mantyxMcp,
|