@artinet/sdk 0.6.1 → 0.6.2

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.
@@ -301,9 +301,24 @@ 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
- messageSendParams.message.parts.unshift(describe.part.data({ ...args }));
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 = A2A.MessageSchema.safeParse(args.message).data?.parts ??
309
+ A2A.TaskSchema.safeParse(args.task).data?.status?.message?.parts ??
310
+ A2A.TaskStatusUpdateEventSchema.safeParse(args.update).data?.status
311
+ ?.message?.parts ??
312
+ A2A.TaskArtifactUpdateEventSchema.safeParse(args.update).data
313
+ ?.artifact?.parts ??
314
+ [];
315
+ parts.forEach((part) => {
316
+ messageSendParams.message.parts.unshift(part);
317
+ });
318
+ }
319
+ else {
320
+ messageSendParams.message.parts.unshift(describe.part.data({ ...args }));
321
+ }
307
322
  }
308
323
  const response = await agent_and_message.agent
309
324
  .sendMessage(messageSendParams)
@@ -317,7 +332,6 @@ export class AgentFactory {
317
332
  const task = response
318
333
  ? describe.task({
319
334
  ...response,
320
- state: A2A.TaskState.working,
321
335
  taskId: context.taskId,
322
336
  contextId: context.contextId,
323
337
  })
@@ -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
- return (parts.text ??
18
- parts.file.map((file) => file.bytes).join("\n") ??
19
- parts.file.map((file) => file.uri).join("\n") ??
20
- parts.data.map((data) => JSON.stringify(data)).join("\n") ??
21
- undefined);
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.map((part) => part.text).join(" "),
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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artinet/sdk",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "A TypeScript SDK for building collaborative AI agents.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",