@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/CHANGELOG.md +9 -2
- package/CONTRIBUTING.md +2 -8
- package/README.md +5 -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-36QXU6NV.js → chunk-TLKXNZYY.js} +153 -13
- package/dist/chunk-TLKXNZYY.js.map +1 -0
- package/dist/{client-C-jl6_nH.d.cts → client-fu11V4HX.d.cts} +177 -16
- package/dist/{client-C-jl6_nH.d.ts → client-fu11V4HX.d.ts} +177 -16
- package/dist/index.cjs +156 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/docs/agent-runs-protocol.md +165 -26
- package/docs/wire-protocol.md +157 -26
- package/package.json +1 -1
- package/dist/chunk-36QXU6NV.js.map +0 -1
package/dist/a2a-server.d.cts
CHANGED
|
@@ -2,7 +2,7 @@ import { AgentCard } from '@a2a-js/sdk';
|
|
|
2
2
|
export { AgentCard, Message, MessageSendParams, Task, TaskArtifactUpdateEvent, TaskStatusUpdateEvent } from '@a2a-js/sdk';
|
|
3
3
|
import { AgentExecutor, RequestContext, ExecutionEventBus } from '@a2a-js/sdk/server';
|
|
4
4
|
export { AgentExecutor, ExecutionEventBus, RequestContext } from '@a2a-js/sdk/server';
|
|
5
|
-
import { M as MantyxClient, T as ToolRef, R as ReasoningLevel, O as OutputSchema } from './client-
|
|
5
|
+
import { M as MantyxClient, T as ToolRef, R as ReasoningLevel, O as OutputSchema } from './client-fu11V4HX.cjs';
|
|
6
6
|
import 'zod';
|
|
7
7
|
|
|
8
8
|
/**
|
package/dist/a2a-server.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { AgentCard } from '@a2a-js/sdk';
|
|
|
2
2
|
export { AgentCard, Message, MessageSendParams, Task, TaskArtifactUpdateEvent, TaskStatusUpdateEvent } from '@a2a-js/sdk';
|
|
3
3
|
import { AgentExecutor, RequestContext, ExecutionEventBus } from '@a2a-js/sdk/server';
|
|
4
4
|
export { AgentExecutor, ExecutionEventBus, RequestContext } from '@a2a-js/sdk/server';
|
|
5
|
-
import { M as MantyxClient, T as ToolRef, R as ReasoningLevel, O as OutputSchema } from './client-
|
|
5
|
+
import { M as MantyxClient, T as ToolRef, R as ReasoningLevel, O as OutputSchema } from './client-fu11V4HX.js';
|
|
6
6
|
import 'zod';
|
|
7
7
|
|
|
8
8
|
/**
|
package/dist/a2a-server.js
CHANGED
|
@@ -594,6 +594,19 @@ function cryptoRandomId() {
|
|
|
594
594
|
|
|
595
595
|
// src/client.ts
|
|
596
596
|
var DEFAULT_BASE_URL = "https://app.mantyx.io";
|
|
597
|
+
function inputFileAttachment(opts) {
|
|
598
|
+
return { type: "input_file", ...opts };
|
|
599
|
+
}
|
|
600
|
+
function inputFileUrlAttachment(opts) {
|
|
601
|
+
return { type: "input_file_url", ...opts };
|
|
602
|
+
}
|
|
603
|
+
function planOnly(options = {}) {
|
|
604
|
+
return {
|
|
605
|
+
planOnly: true,
|
|
606
|
+
...options.steps !== void 0 ? { steps: options.steps } : {},
|
|
607
|
+
...options.brief !== void 0 ? { brief: options.brief } : {}
|
|
608
|
+
};
|
|
609
|
+
}
|
|
597
610
|
function buildQueryString(query) {
|
|
598
611
|
if (!query) return "";
|
|
599
612
|
const parts = [];
|
|
@@ -647,7 +660,8 @@ var MantyxClient = class {
|
|
|
647
660
|
path: "/agent-runs",
|
|
648
661
|
body: serializeAgentSpec(spec, {
|
|
649
662
|
prompt: spec.prompt,
|
|
650
|
-
messages: spec.messages
|
|
663
|
+
messages: spec.messages,
|
|
664
|
+
attachments: spec.attachments
|
|
651
665
|
})
|
|
652
666
|
});
|
|
653
667
|
return await this.driveRun(created.runId, handlers, {
|
|
@@ -659,6 +673,24 @@ var MantyxClient = class {
|
|
|
659
673
|
await closeMcpRefs(tools);
|
|
660
674
|
}
|
|
661
675
|
}
|
|
676
|
+
/**
|
|
677
|
+
* Plan-only run: classify (or accept caller `steps`) and return the
|
|
678
|
+
* structured checklist without executing the agent loop. Sugar for
|
|
679
|
+
* `runAgent({ ..., plan: planOnly({ steps, brief }) })`.
|
|
680
|
+
*
|
|
681
|
+
* The final checklist is on {@link RunResult.plan}; intermediate
|
|
682
|
+
* progress is available via `task_plan` events when streaming.
|
|
683
|
+
*/
|
|
684
|
+
async runPlan(spec) {
|
|
685
|
+
const { steps, brief, ...rest } = spec;
|
|
686
|
+
return this.runAgent({
|
|
687
|
+
...rest,
|
|
688
|
+
plan: planOnly({
|
|
689
|
+
...steps !== void 0 ? { steps } : {},
|
|
690
|
+
...brief !== void 0 ? { brief } : {}
|
|
691
|
+
})
|
|
692
|
+
});
|
|
693
|
+
}
|
|
662
694
|
async *streamAgent(spec) {
|
|
663
695
|
const tools = spec.tools ?? [];
|
|
664
696
|
await resolveLocalRefs(tools, { fetch: this.options.fetch });
|
|
@@ -669,7 +701,8 @@ var MantyxClient = class {
|
|
|
669
701
|
path: "/agent-runs",
|
|
670
702
|
body: serializeAgentSpec(spec, {
|
|
671
703
|
prompt: spec.prompt,
|
|
672
|
-
messages: spec.messages
|
|
704
|
+
messages: spec.messages,
|
|
705
|
+
attachments: spec.attachments
|
|
673
706
|
})
|
|
674
707
|
});
|
|
675
708
|
yield* this.streamRunEvents(created.runId, handlers, spec.signal);
|
|
@@ -773,6 +806,7 @@ var MantyxClient = class {
|
|
|
773
806
|
let tokens;
|
|
774
807
|
let turns;
|
|
775
808
|
let modelInfo;
|
|
809
|
+
let plan;
|
|
776
810
|
for await (const ev of this.streamRunEvents(runId, handlers, opts.signal)) {
|
|
777
811
|
collected.push(ev);
|
|
778
812
|
if (opts.onEvent) opts.onEvent(ev);
|
|
@@ -786,6 +820,10 @@ var MantyxClient = class {
|
|
|
786
820
|
modelInfo = parseRunModel(r.model) ?? modelInfo;
|
|
787
821
|
if (r.subtype === "success") {
|
|
788
822
|
finalText = typeof r.text === "string" ? r.text : "";
|
|
823
|
+
const parsedPlan = parseTaskPlan(r.plan);
|
|
824
|
+
if (parsedPlan !== void 0) {
|
|
825
|
+
plan = parsedPlan;
|
|
826
|
+
}
|
|
789
827
|
} else {
|
|
790
828
|
const errInit = {};
|
|
791
829
|
if (tokens !== void 0) errInit.tokens = tokens;
|
|
@@ -816,6 +854,7 @@ var MantyxClient = class {
|
|
|
816
854
|
if (tokens !== void 0) result.tokens = tokens;
|
|
817
855
|
if (turns !== void 0) result.turns = turns;
|
|
818
856
|
if (modelInfo !== void 0) result.model = modelInfo;
|
|
857
|
+
if (plan !== void 0) result.plan = plan;
|
|
819
858
|
return result;
|
|
820
859
|
}
|
|
821
860
|
async *streamRunEvents(runId, handlers, signal) {
|
|
@@ -1057,27 +1096,32 @@ var AgentSession = class {
|
|
|
1057
1096
|
this.handlers = handlers;
|
|
1058
1097
|
this.tools = tools ?? [];
|
|
1059
1098
|
}
|
|
1060
|
-
async send(
|
|
1099
|
+
async send(promptOrMessages, opts = {}) {
|
|
1061
1100
|
const created = await this.client.request({
|
|
1062
1101
|
method: "POST",
|
|
1063
1102
|
path: `/agent-sessions/${encodeURIComponent(this.id)}/messages`,
|
|
1064
|
-
body: this.buildSessionMessageBody(
|
|
1103
|
+
body: this.buildSessionMessageBody(promptOrMessages, opts)
|
|
1065
1104
|
});
|
|
1066
1105
|
return this.client.driveRun(created.runId, this.handlers, {
|
|
1067
1106
|
...opts.onAssistantDelta ? { onAssistantDelta: opts.onAssistantDelta } : {},
|
|
1068
1107
|
...opts.signal ? { signal: opts.signal } : {}
|
|
1069
1108
|
});
|
|
1070
1109
|
}
|
|
1071
|
-
async *stream(
|
|
1110
|
+
async *stream(promptOrMessages, opts = {}) {
|
|
1072
1111
|
const created = await this.client.request({
|
|
1073
1112
|
method: "POST",
|
|
1074
1113
|
path: `/agent-sessions/${encodeURIComponent(this.id)}/messages`,
|
|
1075
|
-
body: this.buildSessionMessageBody(
|
|
1114
|
+
body: this.buildSessionMessageBody(promptOrMessages, opts)
|
|
1076
1115
|
});
|
|
1077
1116
|
yield* this.client.streamRunEvents(created.runId, this.handlers, opts.signal);
|
|
1078
1117
|
}
|
|
1079
|
-
buildSessionMessageBody(
|
|
1080
|
-
const body =
|
|
1118
|
+
buildSessionMessageBody(promptOrMessages, opts) {
|
|
1119
|
+
const body = serializeTurnInput(
|
|
1120
|
+
typeof promptOrMessages === "string" ? { prompt: promptOrMessages, attachments: opts.attachments } : { messages: promptOrMessages }
|
|
1121
|
+
);
|
|
1122
|
+
if (!("prompt" in body) && !("messages" in body)) {
|
|
1123
|
+
throw new MantyxError("Either `prompt` or `messages` is required");
|
|
1124
|
+
}
|
|
1081
1125
|
if (this.tools.length > 0) body.tools = serializeToolRefs(this.tools);
|
|
1082
1126
|
if (opts.metadata && Object.keys(opts.metadata).length > 0) body.metadata = opts.metadata;
|
|
1083
1127
|
if (opts.reasoningLevel !== void 0) {
|
|
@@ -1095,8 +1139,24 @@ var AgentSession = class {
|
|
|
1095
1139
|
if (opts.supervisor !== void 0) {
|
|
1096
1140
|
body.supervisor = normalizeSupervisor(opts.supervisor);
|
|
1097
1141
|
}
|
|
1142
|
+
if (opts.plan !== void 0) {
|
|
1143
|
+
body.plan = normalizePlan(opts.plan);
|
|
1144
|
+
}
|
|
1098
1145
|
return body;
|
|
1099
1146
|
}
|
|
1147
|
+
/**
|
|
1148
|
+
* Plan-only session turn. Sugar for `send(prompt, { plan: planOnly(...) })`.
|
|
1149
|
+
*/
|
|
1150
|
+
async runPlan(promptOrMessages, opts = {}) {
|
|
1151
|
+
const { steps, brief, ...rest } = opts;
|
|
1152
|
+
return this.send(promptOrMessages, {
|
|
1153
|
+
...rest,
|
|
1154
|
+
plan: planOnly({
|
|
1155
|
+
...steps !== void 0 ? { steps } : {},
|
|
1156
|
+
...brief !== void 0 ? { brief } : {}
|
|
1157
|
+
})
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1100
1160
|
async history() {
|
|
1101
1161
|
const info = await this.client.getSessionInfo(this.id);
|
|
1102
1162
|
return info.messages;
|
|
@@ -1112,9 +1172,29 @@ var AgentSession = class {
|
|
|
1112
1172
|
}
|
|
1113
1173
|
}
|
|
1114
1174
|
};
|
|
1175
|
+
function serializeTurnInput(input) {
|
|
1176
|
+
if (input.messages !== void 0) {
|
|
1177
|
+
return { messages: input.messages };
|
|
1178
|
+
}
|
|
1179
|
+
if (input.prompt !== void 0) {
|
|
1180
|
+
if (input.attachments && input.attachments.length > 0) {
|
|
1181
|
+
return {
|
|
1182
|
+
messages: [{ role: "user", content: input.prompt, attachments: input.attachments }]
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
return { prompt: input.prompt };
|
|
1186
|
+
}
|
|
1187
|
+
return {};
|
|
1188
|
+
}
|
|
1189
|
+
function hasNonEmptySystemMessage(messages) {
|
|
1190
|
+
return messages?.some((m) => m.role === "system" && m.content.trim().length > 0) ?? false;
|
|
1191
|
+
}
|
|
1115
1192
|
function serializeAgentSpec(spec, extra = {}) {
|
|
1116
|
-
|
|
1117
|
-
|
|
1193
|
+
const messagesForIdentity = extra.messages ?? (extra.attachments?.length ? [{ role: "user", content: extra.prompt ?? "", attachments: extra.attachments }] : void 0);
|
|
1194
|
+
if (!spec.agentId && (typeof spec.systemPrompt !== "string" || spec.systemPrompt.length === 0) && !hasNonEmptySystemMessage(messagesForIdentity)) {
|
|
1195
|
+
throw new MantyxError(
|
|
1196
|
+
"Either `agentId`, `systemPrompt`, or a non-empty `system` message in `messages` is required"
|
|
1197
|
+
);
|
|
1118
1198
|
}
|
|
1119
1199
|
const body = {
|
|
1120
1200
|
tools: serializeToolRefs(spec.tools ?? [])
|
|
@@ -1138,10 +1218,12 @@ function serializeAgentSpec(spec, extra = {}) {
|
|
|
1138
1218
|
if (spec.supervisor !== void 0) {
|
|
1139
1219
|
body.supervisor = normalizeSupervisor(spec.supervisor);
|
|
1140
1220
|
}
|
|
1221
|
+
if (spec.plan !== void 0) {
|
|
1222
|
+
body.plan = normalizePlan(spec.plan);
|
|
1223
|
+
}
|
|
1141
1224
|
if (spec.budgets) body.budgets = spec.budgets;
|
|
1142
1225
|
if (spec.metadata && Object.keys(spec.metadata).length > 0) body.metadata = spec.metadata;
|
|
1143
|
-
|
|
1144
|
-
if (extra.messages !== void 0) body.messages = extra.messages;
|
|
1226
|
+
Object.assign(body, serializeTurnInput(extra));
|
|
1145
1227
|
return body;
|
|
1146
1228
|
}
|
|
1147
1229
|
function serializeToolRefs(tools) {
|
|
@@ -1357,6 +1439,61 @@ function normalizeSupervisor(value) {
|
|
|
1357
1439
|
}
|
|
1358
1440
|
return out;
|
|
1359
1441
|
}
|
|
1442
|
+
function normalizePlan(value) {
|
|
1443
|
+
if (value === true || value === false) return value;
|
|
1444
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1445
|
+
throw new MantyxError(
|
|
1446
|
+
`plan must be \`true\`, \`false\`, or an object { planOnly?, brief?, steps? }, got ${JSON.stringify(value)}`
|
|
1447
|
+
);
|
|
1448
|
+
}
|
|
1449
|
+
const out = {};
|
|
1450
|
+
if (value.planOnly !== void 0) {
|
|
1451
|
+
if (typeof value.planOnly !== "boolean") {
|
|
1452
|
+
throw new MantyxError(`plan.planOnly must be a boolean, got ${JSON.stringify(value.planOnly)}`);
|
|
1453
|
+
}
|
|
1454
|
+
out.planOnly = value.planOnly;
|
|
1455
|
+
}
|
|
1456
|
+
if (value.brief !== void 0) {
|
|
1457
|
+
if (typeof value.brief !== "string") {
|
|
1458
|
+
throw new MantyxError(`plan.brief must be a string, got ${JSON.stringify(value.brief)}`);
|
|
1459
|
+
}
|
|
1460
|
+
out.brief = value.brief;
|
|
1461
|
+
}
|
|
1462
|
+
if (value.steps !== void 0) {
|
|
1463
|
+
if (!Array.isArray(value.steps)) {
|
|
1464
|
+
throw new MantyxError(`plan.steps must be an array of strings, got ${JSON.stringify(value.steps)}`);
|
|
1465
|
+
}
|
|
1466
|
+
const steps = [];
|
|
1467
|
+
for (let i = 0; i < value.steps.length; i++) {
|
|
1468
|
+
const step = value.steps[i];
|
|
1469
|
+
if (typeof step !== "string") {
|
|
1470
|
+
throw new MantyxError(`plan.steps[${i}] must be a string, got ${JSON.stringify(step)}`);
|
|
1471
|
+
}
|
|
1472
|
+
steps.push(step);
|
|
1473
|
+
}
|
|
1474
|
+
out.steps = steps;
|
|
1475
|
+
}
|
|
1476
|
+
return out;
|
|
1477
|
+
}
|
|
1478
|
+
function parseTaskPlan(raw) {
|
|
1479
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
|
|
1480
|
+
const obj = raw;
|
|
1481
|
+
const stepsRaw = obj.steps;
|
|
1482
|
+
if (!Array.isArray(stepsRaw)) return void 0;
|
|
1483
|
+
const steps = [];
|
|
1484
|
+
for (const entry of stepsRaw) {
|
|
1485
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
1486
|
+
const row = entry;
|
|
1487
|
+
const title = row.title;
|
|
1488
|
+
const status = row.status;
|
|
1489
|
+
if (typeof title !== "string" || typeof status !== "string") continue;
|
|
1490
|
+
if (status !== "pending" && status !== "in_progress" && status !== "done") continue;
|
|
1491
|
+
steps.push({ title, status });
|
|
1492
|
+
}
|
|
1493
|
+
const briefRaw = obj.brief;
|
|
1494
|
+
const brief = typeof briefRaw === "string" && briefRaw ? briefRaw : void 0;
|
|
1495
|
+
return { steps, ...brief !== void 0 ? { brief } : {} };
|
|
1496
|
+
}
|
|
1360
1497
|
function normalizeToolBudgets(value) {
|
|
1361
1498
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1362
1499
|
throw new MantyxError(
|
|
@@ -1513,8 +1650,11 @@ export {
|
|
|
1513
1650
|
zodToJsonSchema,
|
|
1514
1651
|
toToolParametersWire,
|
|
1515
1652
|
DEFAULT_BASE_URL,
|
|
1653
|
+
inputFileAttachment,
|
|
1654
|
+
inputFileUrlAttachment,
|
|
1655
|
+
planOnly,
|
|
1516
1656
|
MantyxClient,
|
|
1517
1657
|
AgentSession,
|
|
1518
1658
|
parseRunOutput
|
|
1519
1659
|
};
|
|
1520
|
-
//# sourceMappingURL=chunk-
|
|
1660
|
+
//# sourceMappingURL=chunk-TLKXNZYY.js.map
|