@mantyx/sdk 0.14.0 → 0.15.1
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 +14 -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-XENCO3EF.js → chunk-YXTU725K.js} +103 -31
- package/dist/chunk-YXTU725K.js.map +1 -0
- package/dist/{client-Ct6G4TVc.d.cts → client-fu11V4HX.d.cts} +73 -16
- package/dist/{client-Ct6G4TVc.d.ts → client-fu11V4HX.d.ts} +73 -16
- package/dist/index.cjs +105 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/docs/agent-runs-protocol.md +79 -17
- package/docs/wire-protocol.md +56 -21
- package/package.json +1 -1
- package/dist/chunk-XENCO3EF.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
|
@@ -295,7 +295,20 @@ function parseEventBlock(block) {
|
|
|
295
295
|
|
|
296
296
|
// src/zod-to-json-schema.ts
|
|
297
297
|
import { z } from "zod";
|
|
298
|
+
function isZodSchema(value) {
|
|
299
|
+
if (!value || typeof value !== "object") return false;
|
|
300
|
+
const o = value;
|
|
301
|
+
return typeof o._def !== "undefined" || typeof o._zod !== "undefined";
|
|
302
|
+
}
|
|
298
303
|
function zodToJsonSchema(schema) {
|
|
304
|
+
const instance = schema;
|
|
305
|
+
if (typeof instance.toJSONSchema === "function") {
|
|
306
|
+
try {
|
|
307
|
+
const out = instance.toJSONSchema();
|
|
308
|
+
if (out && typeof out === "object") return out;
|
|
309
|
+
} catch {
|
|
310
|
+
}
|
|
311
|
+
}
|
|
299
312
|
const builtIn = z.toJSONSchema;
|
|
300
313
|
if (typeof builtIn === "function") {
|
|
301
314
|
try {
|
|
@@ -306,24 +319,40 @@ function zodToJsonSchema(schema) {
|
|
|
306
319
|
}
|
|
307
320
|
return convertNode(schema);
|
|
308
321
|
}
|
|
322
|
+
function schemaKind(def) {
|
|
323
|
+
if (!def) return void 0;
|
|
324
|
+
if (typeof def.typeName === "string") return def.typeName;
|
|
325
|
+
if (typeof def.type === "string") return def.type;
|
|
326
|
+
return void 0;
|
|
327
|
+
}
|
|
328
|
+
function isOptionalField(field) {
|
|
329
|
+
const kind = schemaKind(field._def);
|
|
330
|
+
return kind === "ZodOptional" || kind === "ZodDefault" || kind === "optional" || kind === "default";
|
|
331
|
+
}
|
|
309
332
|
function convertNode(schema) {
|
|
310
333
|
const def = schema._def;
|
|
311
|
-
const
|
|
312
|
-
switch (
|
|
334
|
+
const kind = schemaKind(def);
|
|
335
|
+
switch (kind) {
|
|
313
336
|
case "ZodString":
|
|
337
|
+
case "string":
|
|
314
338
|
return { type: "string" };
|
|
315
339
|
case "ZodNumber":
|
|
340
|
+
case "number":
|
|
316
341
|
return { type: "number" };
|
|
317
342
|
case "ZodBoolean":
|
|
343
|
+
case "boolean":
|
|
318
344
|
return { type: "boolean" };
|
|
319
345
|
case "ZodNull":
|
|
346
|
+
case "null":
|
|
320
347
|
return { type: "null" };
|
|
321
|
-
case "ZodLiteral":
|
|
322
|
-
|
|
348
|
+
case "ZodLiteral":
|
|
349
|
+
case "literal": {
|
|
350
|
+
const value = def?.value;
|
|
323
351
|
return { const: value, type: typeof value };
|
|
324
352
|
}
|
|
325
|
-
case "ZodEnum":
|
|
326
|
-
|
|
353
|
+
case "ZodEnum":
|
|
354
|
+
case "enum": {
|
|
355
|
+
const values = def?.values ?? [];
|
|
327
356
|
return { type: "string", enum: [...values] };
|
|
328
357
|
}
|
|
329
358
|
case "ZodArray": {
|
|
@@ -333,26 +362,35 @@ function convertNode(schema) {
|
|
|
333
362
|
items: inner ? convertNode(inner) : {}
|
|
334
363
|
};
|
|
335
364
|
}
|
|
365
|
+
case "array": {
|
|
366
|
+
const inner = def?.element;
|
|
367
|
+
return {
|
|
368
|
+
type: "array",
|
|
369
|
+
items: inner ? convertNode(inner) : {}
|
|
370
|
+
};
|
|
371
|
+
}
|
|
336
372
|
case "ZodOptional":
|
|
337
|
-
case "ZodNullable":
|
|
338
|
-
|
|
373
|
+
case "ZodNullable":
|
|
374
|
+
case "optional":
|
|
375
|
+
case "nullable": {
|
|
376
|
+
const inner = def?.innerType;
|
|
339
377
|
return inner ? convertNode(inner) : {};
|
|
340
378
|
}
|
|
341
|
-
case "ZodDefault":
|
|
342
|
-
|
|
379
|
+
case "ZodDefault":
|
|
380
|
+
case "default": {
|
|
381
|
+
const inner = def?.innerType;
|
|
343
382
|
return inner ? convertNode(inner) : {};
|
|
344
383
|
}
|
|
345
|
-
case "ZodObject":
|
|
346
|
-
|
|
384
|
+
case "ZodObject":
|
|
385
|
+
case "object": {
|
|
386
|
+
const shape = def?.shape;
|
|
347
387
|
const fields = typeof shape === "function" ? shape() : shape;
|
|
348
388
|
const properties = {};
|
|
349
389
|
const required = [];
|
|
350
390
|
if (fields) {
|
|
351
391
|
for (const [key, value] of Object.entries(fields)) {
|
|
352
392
|
properties[key] = convertNode(value);
|
|
353
|
-
|
|
354
|
-
const innerTypeName = innerDef?.typeName;
|
|
355
|
-
if (innerTypeName !== "ZodOptional" && innerTypeName !== "ZodDefault") {
|
|
393
|
+
if (!isOptionalField(value)) {
|
|
356
394
|
required.push(key);
|
|
357
395
|
}
|
|
358
396
|
}
|
|
@@ -367,7 +405,7 @@ function convertNode(schema) {
|
|
|
367
405
|
}
|
|
368
406
|
function toToolParametersWire(parameters) {
|
|
369
407
|
if (!parameters) return { type: "object", properties: {} };
|
|
370
|
-
if (
|
|
408
|
+
if (isZodSchema(parameters)) {
|
|
371
409
|
return zodToJsonSchema(parameters);
|
|
372
410
|
}
|
|
373
411
|
return parameters;
|
|
@@ -594,6 +632,12 @@ function cryptoRandomId() {
|
|
|
594
632
|
|
|
595
633
|
// src/client.ts
|
|
596
634
|
var DEFAULT_BASE_URL = "https://app.mantyx.io";
|
|
635
|
+
function inputFileAttachment(opts) {
|
|
636
|
+
return { type: "input_file", ...opts };
|
|
637
|
+
}
|
|
638
|
+
function inputFileUrlAttachment(opts) {
|
|
639
|
+
return { type: "input_file_url", ...opts };
|
|
640
|
+
}
|
|
597
641
|
function planOnly(options = {}) {
|
|
598
642
|
return {
|
|
599
643
|
planOnly: true,
|
|
@@ -654,7 +698,8 @@ var MantyxClient = class {
|
|
|
654
698
|
path: "/agent-runs",
|
|
655
699
|
body: serializeAgentSpec(spec, {
|
|
656
700
|
prompt: spec.prompt,
|
|
657
|
-
messages: spec.messages
|
|
701
|
+
messages: spec.messages,
|
|
702
|
+
attachments: spec.attachments
|
|
658
703
|
})
|
|
659
704
|
});
|
|
660
705
|
return await this.driveRun(created.runId, handlers, {
|
|
@@ -694,7 +739,8 @@ var MantyxClient = class {
|
|
|
694
739
|
path: "/agent-runs",
|
|
695
740
|
body: serializeAgentSpec(spec, {
|
|
696
741
|
prompt: spec.prompt,
|
|
697
|
-
messages: spec.messages
|
|
742
|
+
messages: spec.messages,
|
|
743
|
+
attachments: spec.attachments
|
|
698
744
|
})
|
|
699
745
|
});
|
|
700
746
|
yield* this.streamRunEvents(created.runId, handlers, spec.signal);
|
|
@@ -1088,27 +1134,32 @@ var AgentSession = class {
|
|
|
1088
1134
|
this.handlers = handlers;
|
|
1089
1135
|
this.tools = tools ?? [];
|
|
1090
1136
|
}
|
|
1091
|
-
async send(
|
|
1137
|
+
async send(promptOrMessages, opts = {}) {
|
|
1092
1138
|
const created = await this.client.request({
|
|
1093
1139
|
method: "POST",
|
|
1094
1140
|
path: `/agent-sessions/${encodeURIComponent(this.id)}/messages`,
|
|
1095
|
-
body: this.buildSessionMessageBody(
|
|
1141
|
+
body: this.buildSessionMessageBody(promptOrMessages, opts)
|
|
1096
1142
|
});
|
|
1097
1143
|
return this.client.driveRun(created.runId, this.handlers, {
|
|
1098
1144
|
...opts.onAssistantDelta ? { onAssistantDelta: opts.onAssistantDelta } : {},
|
|
1099
1145
|
...opts.signal ? { signal: opts.signal } : {}
|
|
1100
1146
|
});
|
|
1101
1147
|
}
|
|
1102
|
-
async *stream(
|
|
1148
|
+
async *stream(promptOrMessages, opts = {}) {
|
|
1103
1149
|
const created = await this.client.request({
|
|
1104
1150
|
method: "POST",
|
|
1105
1151
|
path: `/agent-sessions/${encodeURIComponent(this.id)}/messages`,
|
|
1106
|
-
body: this.buildSessionMessageBody(
|
|
1152
|
+
body: this.buildSessionMessageBody(promptOrMessages, opts)
|
|
1107
1153
|
});
|
|
1108
1154
|
yield* this.client.streamRunEvents(created.runId, this.handlers, opts.signal);
|
|
1109
1155
|
}
|
|
1110
|
-
buildSessionMessageBody(
|
|
1111
|
-
const body =
|
|
1156
|
+
buildSessionMessageBody(promptOrMessages, opts) {
|
|
1157
|
+
const body = serializeTurnInput(
|
|
1158
|
+
typeof promptOrMessages === "string" ? { prompt: promptOrMessages, attachments: opts.attachments } : { messages: promptOrMessages }
|
|
1159
|
+
);
|
|
1160
|
+
if (!("prompt" in body) && !("messages" in body)) {
|
|
1161
|
+
throw new MantyxError("Either `prompt` or `messages` is required");
|
|
1162
|
+
}
|
|
1112
1163
|
if (this.tools.length > 0) body.tools = serializeToolRefs(this.tools);
|
|
1113
1164
|
if (opts.metadata && Object.keys(opts.metadata).length > 0) body.metadata = opts.metadata;
|
|
1114
1165
|
if (opts.reasoningLevel !== void 0) {
|
|
@@ -1134,9 +1185,9 @@ var AgentSession = class {
|
|
|
1134
1185
|
/**
|
|
1135
1186
|
* Plan-only session turn. Sugar for `send(prompt, { plan: planOnly(...) })`.
|
|
1136
1187
|
*/
|
|
1137
|
-
async runPlan(
|
|
1188
|
+
async runPlan(promptOrMessages, opts = {}) {
|
|
1138
1189
|
const { steps, brief, ...rest } = opts;
|
|
1139
|
-
return this.send(
|
|
1190
|
+
return this.send(promptOrMessages, {
|
|
1140
1191
|
...rest,
|
|
1141
1192
|
plan: planOnly({
|
|
1142
1193
|
...steps !== void 0 ? { steps } : {},
|
|
@@ -1159,9 +1210,29 @@ var AgentSession = class {
|
|
|
1159
1210
|
}
|
|
1160
1211
|
}
|
|
1161
1212
|
};
|
|
1213
|
+
function serializeTurnInput(input) {
|
|
1214
|
+
if (input.messages !== void 0) {
|
|
1215
|
+
return { messages: input.messages };
|
|
1216
|
+
}
|
|
1217
|
+
if (input.prompt !== void 0) {
|
|
1218
|
+
if (input.attachments && input.attachments.length > 0) {
|
|
1219
|
+
return {
|
|
1220
|
+
messages: [{ role: "user", content: input.prompt, attachments: input.attachments }]
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
return { prompt: input.prompt };
|
|
1224
|
+
}
|
|
1225
|
+
return {};
|
|
1226
|
+
}
|
|
1227
|
+
function hasNonEmptySystemMessage(messages) {
|
|
1228
|
+
return messages?.some((m) => m.role === "system" && m.content.trim().length > 0) ?? false;
|
|
1229
|
+
}
|
|
1162
1230
|
function serializeAgentSpec(spec, extra = {}) {
|
|
1163
|
-
|
|
1164
|
-
|
|
1231
|
+
const messagesForIdentity = extra.messages ?? (extra.attachments?.length ? [{ role: "user", content: extra.prompt ?? "", attachments: extra.attachments }] : void 0);
|
|
1232
|
+
if (!spec.agentId && (typeof spec.systemPrompt !== "string" || spec.systemPrompt.length === 0) && !hasNonEmptySystemMessage(messagesForIdentity)) {
|
|
1233
|
+
throw new MantyxError(
|
|
1234
|
+
"Either `agentId`, `systemPrompt`, or a non-empty `system` message in `messages` is required"
|
|
1235
|
+
);
|
|
1165
1236
|
}
|
|
1166
1237
|
const body = {
|
|
1167
1238
|
tools: serializeToolRefs(spec.tools ?? [])
|
|
@@ -1190,8 +1261,7 @@ function serializeAgentSpec(spec, extra = {}) {
|
|
|
1190
1261
|
}
|
|
1191
1262
|
if (spec.budgets) body.budgets = spec.budgets;
|
|
1192
1263
|
if (spec.metadata && Object.keys(spec.metadata).length > 0) body.metadata = spec.metadata;
|
|
1193
|
-
|
|
1194
|
-
if (extra.messages !== void 0) body.messages = extra.messages;
|
|
1264
|
+
Object.assign(body, serializeTurnInput(extra));
|
|
1195
1265
|
return body;
|
|
1196
1266
|
}
|
|
1197
1267
|
function serializeToolRefs(tools) {
|
|
@@ -1618,9 +1688,11 @@ export {
|
|
|
1618
1688
|
zodToJsonSchema,
|
|
1619
1689
|
toToolParametersWire,
|
|
1620
1690
|
DEFAULT_BASE_URL,
|
|
1691
|
+
inputFileAttachment,
|
|
1692
|
+
inputFileUrlAttachment,
|
|
1621
1693
|
planOnly,
|
|
1622
1694
|
MantyxClient,
|
|
1623
1695
|
AgentSession,
|
|
1624
1696
|
parseRunOutput
|
|
1625
1697
|
};
|
|
1626
|
-
//# sourceMappingURL=chunk-
|
|
1698
|
+
//# sourceMappingURL=chunk-YXTU725K.js.map
|