@artinet/sdk 0.6.1 → 0.6.3
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/dist/create/create.js
CHANGED
|
@@ -301,9 +301,31 @@ export class AgentFactory {
|
|
|
301
301
|
logger.info("sendMessage: Sending message: ", {
|
|
302
302
|
agent: agent_and_message.agent.constructor.name,
|
|
303
303
|
});
|
|
304
|
-
const messageSendParams = describe.messageSendParams(agent_and_message.message ?? context.userMessage);
|
|
304
|
+
const messageSendParams = describe.messageSendParams(agent_and_message.message ?? structuredClone(context.userMessage));
|
|
305
305
|
if (args) {
|
|
306
|
-
|
|
306
|
+
/**We extract the parts of the first A2A protocol object we encounter in the args */
|
|
307
|
+
if (args.task || args.message || args.update) {
|
|
308
|
+
const parts = [];
|
|
309
|
+
if (args.message) {
|
|
310
|
+
parts.push(...(A2A.MessageSchema.safeParse(args.message).data?.parts ?? []));
|
|
311
|
+
}
|
|
312
|
+
if (args.task) {
|
|
313
|
+
parts.push(...(A2A.TaskSchema.safeParse(args.task).data?.status?.message
|
|
314
|
+
?.parts ?? []));
|
|
315
|
+
}
|
|
316
|
+
if (args.update) {
|
|
317
|
+
parts.push(...(A2A.TaskStatusUpdateEventSchema.safeParse(args.update).data
|
|
318
|
+
?.status?.message?.parts ?? []));
|
|
319
|
+
parts.push(...(A2A.TaskArtifactUpdateEventSchema.safeParse(args.update).data
|
|
320
|
+
?.artifact?.parts ?? []));
|
|
321
|
+
}
|
|
322
|
+
parts.forEach((part) => {
|
|
323
|
+
messageSendParams.message.parts.unshift(part);
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
messageSendParams.message.parts.unshift(describe.part.data({ ...args }));
|
|
328
|
+
}
|
|
307
329
|
}
|
|
308
330
|
const response = await agent_and_message.agent
|
|
309
331
|
.sendMessage(messageSendParams)
|
|
@@ -317,7 +339,6 @@ export class AgentFactory {
|
|
|
317
339
|
const task = response
|
|
318
340
|
? describe.task({
|
|
319
341
|
...response,
|
|
320
|
-
state: A2A.TaskState.working,
|
|
321
342
|
taskId: context.taskId,
|
|
322
343
|
contextId: context.contextId,
|
|
323
344
|
})
|
|
@@ -36,6 +36,10 @@ export const handleTaskUpdate = async ({ context, task, update, }) => {
|
|
|
36
36
|
cause: validated,
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
+
//TODO: Enforce State Transitions
|
|
40
|
+
if (validated.status?.message) {
|
|
41
|
+
updateHistory(task, validated.status.message);
|
|
42
|
+
}
|
|
39
43
|
task = { ...task, ...validated };
|
|
40
44
|
if (context.userMessage) {
|
|
41
45
|
updateHistory(task, context.userMessage);
|
|
@@ -6,9 +6,10 @@ import { A2A } from "../../../types/index.js";
|
|
|
6
6
|
/**
|
|
7
7
|
* Extracts the content of an agent response.
|
|
8
8
|
* @param input - The input event.
|
|
9
|
+
* @param legacy - Whether to use the legacy content extraction logic.
|
|
9
10
|
* @returns The content of the input event.
|
|
10
11
|
*/
|
|
11
|
-
export declare function extractTextContent(input: A2A.Update): string | undefined;
|
|
12
|
+
export declare function extractTextContent(input: A2A.Update, legacy?: boolean): string | undefined;
|
|
12
13
|
/**
|
|
13
14
|
* @deprecated Use extractTextContent instead.
|
|
14
15
|
*/
|
|
@@ -6,19 +6,27 @@ import { getParts } from "./part.js";
|
|
|
6
6
|
/**
|
|
7
7
|
* Extracts the content of an agent response.
|
|
8
8
|
* @param input - The input event.
|
|
9
|
+
* @param legacy - Whether to use the legacy content extraction logic.
|
|
9
10
|
* @returns The content of the input event.
|
|
10
11
|
*/
|
|
11
|
-
export function extractTextContent(input) {
|
|
12
|
+
export function extractTextContent(input, legacy = true) {
|
|
12
13
|
const parts = getParts(input?.parts ??
|
|
13
14
|
input?.status?.message?.parts ??
|
|
14
15
|
input?.status?.message?.parts ??
|
|
15
16
|
input?.artifact?.parts ??
|
|
16
17
|
[]);
|
|
17
|
-
|
|
18
|
-
parts.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
if (legacy) {
|
|
19
|
+
return (parts.text ??
|
|
20
|
+
parts.file?.map((file) => file.bytes).join("\n") ??
|
|
21
|
+
parts.file?.map((file) => file.uri).join("\n") ??
|
|
22
|
+
parts.data?.map((data) => JSON.stringify(data)).join("\n") ??
|
|
23
|
+
undefined);
|
|
24
|
+
}
|
|
25
|
+
return parts.text && parts.text !== ""
|
|
26
|
+
? parts.text
|
|
27
|
+
: parts.file?.map((file) => file.bytes ?? file.uri).join("\n") ??
|
|
28
|
+
parts.data?.map((data) => JSON.stringify(data)).join("\n") ??
|
|
29
|
+
undefined;
|
|
22
30
|
}
|
|
23
31
|
/**
|
|
24
32
|
* @deprecated Use extractTextContent instead.
|
|
@@ -16,7 +16,11 @@ export const getParts = (parts) => {
|
|
|
16
16
|
const fileParts = parts.filter((part) => part.kind === "file");
|
|
17
17
|
const dataParts = parts.filter((part) => part.kind === "data");
|
|
18
18
|
return {
|
|
19
|
-
text: textParts
|
|
19
|
+
text: textParts
|
|
20
|
+
.map((part) => part.text)
|
|
21
|
+
.filter((text) => text !== undefined && text !== null && text !== "")
|
|
22
|
+
.join(" ")
|
|
23
|
+
.trim(),
|
|
20
24
|
file: fileParts.map((part) => part.file),
|
|
21
25
|
data: dataParts.map((part) => part.data),
|
|
22
26
|
};
|