@artinet/sdk 0.5.15 → 0.5.16
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/README.md
CHANGED
|
@@ -71,7 +71,9 @@ It has [serveral template projects](https://github.com/the-artinet-project/creat
|
|
|
71
71
|
- The examples folder will be removed in favor of [`create-agent`](https://github.com/the-artinet-project/create-agent).
|
|
72
72
|
- In `Task` the `contextId` field is now required (inline with the A2A spec).
|
|
73
73
|
- In `AgentSkill` the `tag` field is now required (inline with the A2A spec).
|
|
74
|
-
- Optional fields in Agent2Agent
|
|
74
|
+
- Optional fields in Agent2Agent Zod schemas are now nullable for better interoperability.
|
|
75
|
+
- The `EngineBuilder` constructor is now protected and open for extension.
|
|
76
|
+
- `AgentBuilder` will now throw an error if it recieves an invalid `FilePart`.
|
|
75
77
|
|
|
76
78
|
## Installation
|
|
77
79
|
|
|
@@ -140,11 +140,11 @@ type OutArgsOf<O> = O extends StepOutputWithForwardArgs<any, infer A> ? A : [];
|
|
|
140
140
|
export declare class EngineBuilder<TCommand extends MessageSendParams = MessageSendParams, TInboundArgs extends readonly unknown[] = []> implements StepBuilder<TCommand, TInboundArgs> {
|
|
141
141
|
private steps;
|
|
142
142
|
/**
|
|
143
|
-
*
|
|
143
|
+
* Protected constructor to enforce factory method usage.
|
|
144
144
|
*
|
|
145
145
|
* @param steps - Initial steps array
|
|
146
146
|
*/
|
|
147
|
-
|
|
147
|
+
protected constructor(steps?: Array<StepWithKind<TCommand, any, any, any, any, any>>);
|
|
148
148
|
/**
|
|
149
149
|
* Creates a new EngineBuilder instance.
|
|
150
150
|
*
|
|
@@ -18,6 +18,7 @@ import { TaskState, } from "../../../types/index.js";
|
|
|
18
18
|
import { createAgent } from "./service.js";
|
|
19
19
|
import { v4 as uuidv4 } from "uuid";
|
|
20
20
|
import { getContent } from "../helpers/content.js";
|
|
21
|
+
import { SUBMITTED_UPDATE, WORKING_UPDATE } from "../../../utils/index.js";
|
|
21
22
|
/**
|
|
22
23
|
* Fluent builder for constructing A2A agent execution engines.
|
|
23
24
|
*
|
|
@@ -50,7 +51,7 @@ export class EngineBuilder {
|
|
|
50
51
|
//@typescript-eslint/no-explicit-any
|
|
51
52
|
steps = [];
|
|
52
53
|
/**
|
|
53
|
-
*
|
|
54
|
+
* Protected constructor to enforce factory method usage.
|
|
54
55
|
*
|
|
55
56
|
* @param steps - Initial steps array
|
|
56
57
|
*/
|
|
@@ -231,23 +232,27 @@ const partToMessagePart = (kind, part) => {
|
|
|
231
232
|
}
|
|
232
233
|
case "file": {
|
|
233
234
|
const filePart = part;
|
|
234
|
-
|
|
235
|
-
|
|
235
|
+
if (filePart.uri) {
|
|
236
|
+
return {
|
|
236
237
|
kind: "file",
|
|
237
238
|
file: {
|
|
238
239
|
uri: filePart.uri,
|
|
239
240
|
name: filePart.name,
|
|
240
241
|
mimeType: filePart.mimeType,
|
|
241
242
|
},
|
|
242
|
-
}
|
|
243
|
-
: {
|
|
244
|
-
kind: "file",
|
|
245
|
-
file: {
|
|
246
|
-
bytes: filePart.bytes ?? "",
|
|
247
|
-
name: filePart.name,
|
|
248
|
-
mimeType: filePart.mimeType,
|
|
249
|
-
},
|
|
250
243
|
};
|
|
244
|
+
}
|
|
245
|
+
if (!filePart.bytes) {
|
|
246
|
+
throw new Error("File bytes are required when uri is not provided");
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
kind: "file",
|
|
250
|
+
file: {
|
|
251
|
+
bytes: filePart.bytes,
|
|
252
|
+
name: filePart.name,
|
|
253
|
+
mimeType: filePart.mimeType,
|
|
254
|
+
},
|
|
255
|
+
};
|
|
251
256
|
}
|
|
252
257
|
case "data": {
|
|
253
258
|
return { kind: "data", data: part };
|
|
@@ -287,21 +292,12 @@ export function createAgentExecutor(stepsList) {
|
|
|
287
292
|
content: content,
|
|
288
293
|
args: [],
|
|
289
294
|
};
|
|
290
|
-
const contextId = context.contextId
|
|
291
|
-
const taskId = context.State().task.id
|
|
295
|
+
const contextId = context.contextId;
|
|
296
|
+
const taskId = context.State().task.id;
|
|
292
297
|
if (!contextId || !taskId) {
|
|
293
298
|
throw new Error("Context ID and task ID are required");
|
|
294
299
|
}
|
|
295
|
-
const taskStarted =
|
|
296
|
-
taskId: taskId,
|
|
297
|
-
contextId: contextId,
|
|
298
|
-
kind: "status-update",
|
|
299
|
-
status: {
|
|
300
|
-
state: TaskState.submitted,
|
|
301
|
-
timestamp: new Date().toISOString(),
|
|
302
|
-
},
|
|
303
|
-
final: false,
|
|
304
|
-
};
|
|
300
|
+
const taskStarted = SUBMITTED_UPDATE(taskId, contextId);
|
|
305
301
|
yield taskStarted;
|
|
306
302
|
const finalMessage = {
|
|
307
303
|
taskId: taskId,
|
|
@@ -316,65 +312,35 @@ export function createAgentExecutor(stepsList) {
|
|
|
316
312
|
let parts = [];
|
|
317
313
|
if (Array.isArray(ret)) {
|
|
318
314
|
parts = ret.map((part) => partToMessagePart(step.kind, part));
|
|
319
|
-
const taskStatusUpdate = {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
timestamp: new Date().toISOString(),
|
|
326
|
-
message: {
|
|
327
|
-
messageId: uuidv4(),
|
|
328
|
-
kind: "message",
|
|
329
|
-
role: "agent",
|
|
330
|
-
parts: parts,
|
|
331
|
-
},
|
|
332
|
-
},
|
|
333
|
-
final: false,
|
|
334
|
-
};
|
|
315
|
+
const taskStatusUpdate = WORKING_UPDATE(taskId, contextId, {
|
|
316
|
+
messageId: uuidv4(),
|
|
317
|
+
kind: "message",
|
|
318
|
+
role: "agent",
|
|
319
|
+
parts: parts,
|
|
320
|
+
});
|
|
335
321
|
yield taskStatusUpdate;
|
|
336
322
|
}
|
|
337
|
-
else if (typeof ret === "object") {
|
|
323
|
+
else if (ret !== null && typeof ret === "object") {
|
|
338
324
|
parts = Array.isArray(ret.parts)
|
|
339
325
|
? ret.parts.map((part) => partToMessagePart(step.kind, part))
|
|
340
326
|
: [partToMessagePart(step.kind, ret.parts)];
|
|
341
|
-
const taskStatusUpdate = {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
timestamp: new Date().toISOString(),
|
|
348
|
-
message: {
|
|
349
|
-
messageId: uuidv4(),
|
|
350
|
-
kind: "message",
|
|
351
|
-
role: "agent",
|
|
352
|
-
parts: parts,
|
|
353
|
-
},
|
|
354
|
-
},
|
|
355
|
-
final: false,
|
|
356
|
-
};
|
|
327
|
+
const taskStatusUpdate = WORKING_UPDATE(taskId, contextId, {
|
|
328
|
+
messageId: uuidv4(),
|
|
329
|
+
kind: "message",
|
|
330
|
+
role: "agent",
|
|
331
|
+
parts: parts,
|
|
332
|
+
});
|
|
357
333
|
yield taskStatusUpdate;
|
|
358
334
|
stepArgs.args = ret.args;
|
|
359
335
|
}
|
|
360
336
|
else {
|
|
361
337
|
parts = [partToMessagePart(step.kind, ret)];
|
|
362
|
-
const taskStatusUpdate = {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
timestamp: new Date().toISOString(),
|
|
369
|
-
message: {
|
|
370
|
-
messageId: uuidv4(),
|
|
371
|
-
kind: "message",
|
|
372
|
-
role: "agent",
|
|
373
|
-
parts: parts,
|
|
374
|
-
},
|
|
375
|
-
},
|
|
376
|
-
final: false,
|
|
377
|
-
};
|
|
338
|
+
const taskStatusUpdate = WORKING_UPDATE(taskId, contextId, {
|
|
339
|
+
messageId: uuidv4(),
|
|
340
|
+
kind: "message",
|
|
341
|
+
role: "agent",
|
|
342
|
+
parts: parts,
|
|
343
|
+
});
|
|
378
344
|
yield taskStatusUpdate;
|
|
379
345
|
}
|
|
380
346
|
finalMessage.parts.push(...parts);
|