@mantyx/sdk 0.20.0 → 0.22.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/CHANGELOG.md +18 -0
- package/dist/a2a-server.cjs.map +1 -1
- package/dist/a2a-server.d.cts +1 -1
- package/dist/a2a-server.d.ts +1 -1
- package/dist/a2a-server.js +1 -1
- package/dist/{chunk-ZOFQ5AN6.js → chunk-5NKXV5XZ.js} +91 -24
- package/dist/chunk-5NKXV5XZ.js.map +1 -0
- package/dist/{client-D4-MQANp.d.cts → client-C7TzTpNW.d.cts} +4 -0
- package/dist/{client-D4-MQANp.d.ts → client-C7TzTpNW.d.ts} +4 -0
- package/dist/{computer-use-D4hBi1Tm.d.cts → computer-use-1m6E_VIl.d.cts} +1 -1
- package/dist/{computer-use-DUFbgsSU.d.ts → computer-use-4QzI3lGU.d.ts} +1 -1
- package/dist/index.cjs +91 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/playwright.d.cts +2 -2
- package/dist/playwright.d.ts +2 -2
- package/package.json +1 -1
- package/dist/chunk-ZOFQ5AN6.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1092,11 +1092,23 @@ var MantyxClient = class {
|
|
|
1092
1092
|
}
|
|
1093
1093
|
}
|
|
1094
1094
|
async postToolResult(runId, toolUseId, payload) {
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1095
|
+
const path = `/agent-runs/${encodeURIComponent(runId)}/tool-results`;
|
|
1096
|
+
const body = { toolUseId, ...payload };
|
|
1097
|
+
for (let attempt = 0; attempt < TOOL_RESULT_POST_MAX_ATTEMPTS; attempt++) {
|
|
1098
|
+
try {
|
|
1099
|
+
await this.request({
|
|
1100
|
+
method: "POST",
|
|
1101
|
+
path,
|
|
1102
|
+
body
|
|
1103
|
+
});
|
|
1104
|
+
return;
|
|
1105
|
+
} catch (err) {
|
|
1106
|
+
if (attempt === TOOL_RESULT_POST_MAX_ATTEMPTS - 1 || !isToolResultPostRetryable(err)) {
|
|
1107
|
+
return;
|
|
1108
|
+
}
|
|
1109
|
+
await sleep(toolResultPostBackoffMs(attempt));
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1100
1112
|
}
|
|
1101
1113
|
async cancelRun(runId) {
|
|
1102
1114
|
await this.request({
|
|
@@ -1144,6 +1156,10 @@ var MantyxClient = class {
|
|
|
1144
1156
|
});
|
|
1145
1157
|
}
|
|
1146
1158
|
async createEvalRun(spec) {
|
|
1159
|
+
const tools = spec.tools ?? [];
|
|
1160
|
+
if (tools.length > 0) {
|
|
1161
|
+
await resolveLocalRefs(tools, { fetch: this.options.fetch });
|
|
1162
|
+
}
|
|
1147
1163
|
return this.request({
|
|
1148
1164
|
method: "POST",
|
|
1149
1165
|
path: "/eval-runs",
|
|
@@ -1213,28 +1229,49 @@ var MantyxClient = class {
|
|
|
1213
1229
|
* `getEvalRun` until `status` is terminal.
|
|
1214
1230
|
*/
|
|
1215
1231
|
async runEval(spec, options = {}) {
|
|
1216
|
-
const
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
options.onEvent?.(ev);
|
|
1222
|
-
}
|
|
1223
|
-
} catch (err) {
|
|
1224
|
-
if (!(err instanceof MantyxNetworkError)) throw err;
|
|
1225
|
-
}
|
|
1226
|
-
})();
|
|
1232
|
+
const tools = options.tools ?? spec.tools ?? [];
|
|
1233
|
+
if (tools.length > 0) {
|
|
1234
|
+
await resolveLocalRefs(tools, { fetch: this.options.fetch });
|
|
1235
|
+
}
|
|
1236
|
+
const handlers = collectLocalHandlers(tools);
|
|
1227
1237
|
try {
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1238
|
+
const accepted = await this.createEvalRun({
|
|
1239
|
+
...spec,
|
|
1240
|
+
...tools.length > 0 ? { tools } : {}
|
|
1241
|
+
});
|
|
1242
|
+
const pollMs = options.pollIntervalMs ?? 1e3;
|
|
1243
|
+
const streamDone = (async () => {
|
|
1244
|
+
try {
|
|
1245
|
+
for await (const ev of this.streamEvalRun(accepted.runId, options.signal)) {
|
|
1246
|
+
if (ev.type === "local_tool_call" && tools.length > 0) {
|
|
1247
|
+
const record = ev;
|
|
1248
|
+
const nested = typeof record.data === "object" && record.data !== null && !Array.isArray(record.data) ? record.data : void 0;
|
|
1249
|
+
const agentRunId = typeof record.agentRunId === "string" ? record.agentRunId : typeof nested?.agentRunId === "string" ? nested.agentRunId : "";
|
|
1250
|
+
if (agentRunId) {
|
|
1251
|
+
const localEv = evalEventToLocalToolCall(ev);
|
|
1252
|
+
void this.dispatchLocalTool(agentRunId, localEv, handlers).catch(() => void 0);
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
options.onEvent?.(ev);
|
|
1256
|
+
}
|
|
1257
|
+
} catch (err) {
|
|
1258
|
+
if (!(err instanceof MantyxNetworkError)) throw err;
|
|
1259
|
+
}
|
|
1260
|
+
})();
|
|
1261
|
+
try {
|
|
1262
|
+
while (true) {
|
|
1263
|
+
if (options.signal?.aborted) {
|
|
1264
|
+
throw new MantyxNetworkError("eval run wait aborted", { cause: options.signal.reason });
|
|
1265
|
+
}
|
|
1266
|
+
const detail = await this.getEvalRun(accepted.runId);
|
|
1267
|
+
if (EVAL_TERMINAL_STATUSES.has(detail.status)) return detail;
|
|
1268
|
+
await sleep(pollMs);
|
|
1231
1269
|
}
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
await sleep(pollMs);
|
|
1270
|
+
} finally {
|
|
1271
|
+
await streamDone.catch(() => void 0);
|
|
1235
1272
|
}
|
|
1236
1273
|
} finally {
|
|
1237
|
-
await
|
|
1274
|
+
await closeMcpRefs(tools);
|
|
1238
1275
|
}
|
|
1239
1276
|
}
|
|
1240
1277
|
// -------------------------------------------------------------- HTTP
|
|
@@ -1522,10 +1559,28 @@ function serializeCreateEvalRunRequest(spec) {
|
|
|
1522
1559
|
if (spec.dataset) body.dataset = spec.dataset;
|
|
1523
1560
|
if (spec.agentId) body.agentId = spec.agentId;
|
|
1524
1561
|
if (spec.agent) body.agent = serializeAgentSpec(spec.agent);
|
|
1562
|
+
if (spec.tools && spec.tools.length > 0 && spec.agentId) {
|
|
1563
|
+
body.tools = serializeToolRefs(spec.tools);
|
|
1564
|
+
}
|
|
1525
1565
|
if (spec.modelId) body.modelId = spec.modelId;
|
|
1526
1566
|
if (spec.overrides) body.overrides = spec.overrides;
|
|
1527
1567
|
return body;
|
|
1528
1568
|
}
|
|
1569
|
+
function evalEventToLocalToolCall(ev) {
|
|
1570
|
+
const data = ev.data && typeof ev.data === "object" && !Array.isArray(ev.data) ? ev.data : ev;
|
|
1571
|
+
return {
|
|
1572
|
+
type: "local_tool_call",
|
|
1573
|
+
seq: 0,
|
|
1574
|
+
toolUseId: String(data.toolUseId ?? ""),
|
|
1575
|
+
name: String(data.name ?? ""),
|
|
1576
|
+
args: data.args ?? {},
|
|
1577
|
+
...typeof data.kind === "string" ? { kind: data.kind } : {},
|
|
1578
|
+
...data.agentCard !== void 0 ? { agentCard: data.agentCard } : {},
|
|
1579
|
+
...typeof data.mcpServer === "string" ? { mcpServer: data.mcpServer } : {},
|
|
1580
|
+
...typeof data.mcpToolName === "string" ? { mcpToolName: data.mcpToolName } : {},
|
|
1581
|
+
...data.mcpServerInfo !== void 0 ? { mcpServerInfo: data.mcpServerInfo } : {}
|
|
1582
|
+
};
|
|
1583
|
+
}
|
|
1529
1584
|
function serializeToolRefs(tools) {
|
|
1530
1585
|
return tools.map((t) => {
|
|
1531
1586
|
switch (t.kind) {
|
|
@@ -1892,6 +1947,18 @@ function parseRunOutput(result, validator) {
|
|
|
1892
1947
|
function sleep(ms) {
|
|
1893
1948
|
return new Promise((r) => setTimeout(r, ms));
|
|
1894
1949
|
}
|
|
1950
|
+
var TOOL_RESULT_POST_MAX_ATTEMPTS = 6;
|
|
1951
|
+
function toolResultPostBackoffMs(attempt) {
|
|
1952
|
+
return Math.min(500 * 2 ** attempt, 8e3);
|
|
1953
|
+
}
|
|
1954
|
+
function isToolResultPostRetryable(err) {
|
|
1955
|
+
if (err instanceof MantyxNetworkError) return true;
|
|
1956
|
+
if (err instanceof MantyxError && typeof err.status === "number") {
|
|
1957
|
+
if (err.status === 429) return true;
|
|
1958
|
+
if (err.status >= 500) return true;
|
|
1959
|
+
}
|
|
1960
|
+
return false;
|
|
1961
|
+
}
|
|
1895
1962
|
function parseRunTokens(value) {
|
|
1896
1963
|
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
1897
1964
|
const v = value;
|
|
@@ -2533,7 +2600,7 @@ async function runComputerUse(opts) {
|
|
|
2533
2600
|
}
|
|
2534
2601
|
|
|
2535
2602
|
// src/version.ts
|
|
2536
|
-
var SDK_VERSION = "0.
|
|
2603
|
+
var SDK_VERSION = "0.22.0";
|
|
2537
2604
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2538
2605
|
0 && (module.exports = {
|
|
2539
2606
|
AgentSession,
|