@artinet/sdk 0.5.16 → 0.5.18

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.
Files changed (175) hide show
  1. package/README.md +108 -58
  2. package/dist/browser/browser.d.ts +9 -0
  3. package/dist/browser/browser.js +10 -0
  4. package/dist/browser/client/a2a-client.d.ts +126 -0
  5. package/dist/browser/client/a2a-client.js +221 -0
  6. package/dist/browser/client/index.d.ts +1 -0
  7. package/dist/browser/client/index.js +1 -0
  8. package/dist/browser/services/a2a/helpers/message-builder.d.ts +12 -0
  9. package/dist/browser/services/a2a/helpers/message-builder.js +61 -0
  10. package/dist/browser/transport/rpc/parser.d.ts +15 -0
  11. package/dist/browser/transport/rpc/parser.js +48 -0
  12. package/dist/browser/transport/rpc/rpc-client.d.ts +80 -0
  13. package/dist/browser/transport/rpc/rpc-client.js +189 -0
  14. package/dist/browser/transport/streaming/event-stream.d.ts +25 -0
  15. package/dist/browser/transport/streaming/event-stream.js +99 -0
  16. package/dist/browser/types/ext.d.ts +13 -0
  17. package/dist/browser/types/ext.js +10 -0
  18. package/dist/browser/types/index.d.ts +4 -0
  19. package/dist/browser/types/index.js +4 -0
  20. package/dist/browser/types/interfaces/client.d.ts +135 -0
  21. package/dist/browser/types/interfaces/client.js +5 -0
  22. package/dist/browser/types/interfaces/index.d.ts +3 -0
  23. package/dist/browser/types/interfaces/index.js +3 -0
  24. package/dist/browser/types/interfaces/services/a2a/builder.d.ts +37 -0
  25. package/dist/browser/types/interfaces/services/a2a/builder.js +5 -0
  26. package/dist/browser/types/interfaces/services/a2a/context.d.ts +162 -0
  27. package/dist/browser/types/interfaces/services/a2a/context.js +5 -0
  28. package/dist/browser/types/interfaces/services/a2a/engine.d.ts +7 -0
  29. package/dist/browser/types/interfaces/services/a2a/engine.js +5 -0
  30. package/dist/browser/types/interfaces/services/a2a/index.d.ts +5 -0
  31. package/dist/browser/types/interfaces/services/a2a/index.js +5 -0
  32. package/dist/browser/types/interfaces/services/a2a/legacy.d.ts +93 -0
  33. package/dist/browser/types/interfaces/services/a2a/legacy.js +5 -0
  34. package/dist/browser/types/interfaces/services/a2a/service.d.ts +413 -0
  35. package/dist/browser/types/interfaces/services/a2a/service.js +5 -0
  36. package/dist/browser/types/interfaces/services/core/context/command.d.ts +25 -0
  37. package/dist/browser/types/interfaces/services/core/context/command.js +5 -0
  38. package/dist/browser/types/interfaces/services/core/context/context.d.ts +207 -0
  39. package/dist/browser/types/interfaces/services/core/context/context.js +5 -0
  40. package/dist/browser/types/interfaces/services/core/context/index.d.ts +3 -0
  41. package/dist/browser/types/interfaces/services/core/context/index.js +3 -0
  42. package/dist/browser/types/interfaces/services/core/context/types.d.ts +11 -0
  43. package/dist/browser/types/interfaces/services/core/context/types.js +5 -0
  44. package/dist/browser/types/interfaces/services/core/execution/engine.d.ts +106 -0
  45. package/dist/browser/types/interfaces/services/core/execution/engine.js +5 -0
  46. package/dist/browser/types/interfaces/services/core/execution/environment.d.ts +11 -0
  47. package/dist/browser/types/interfaces/services/core/execution/environment.js +5 -0
  48. package/dist/browser/types/interfaces/services/core/execution/execute.d.ts +7 -0
  49. package/dist/browser/types/interfaces/services/core/execution/execute.js +5 -0
  50. package/dist/browser/types/interfaces/services/core/execution/index.d.ts +3 -0
  51. package/dist/browser/types/interfaces/services/core/execution/index.js +3 -0
  52. package/dist/browser/types/interfaces/services/core/index.d.ts +4 -0
  53. package/dist/browser/types/interfaces/services/core/index.js +4 -0
  54. package/dist/browser/types/interfaces/services/core/managers/cancellation.d.ts +9 -0
  55. package/dist/browser/types/interfaces/services/core/managers/cancellation.js +5 -0
  56. package/dist/browser/types/interfaces/services/core/managers/connection.d.ts +9 -0
  57. package/dist/browser/types/interfaces/services/core/managers/connection.js +5 -0
  58. package/dist/browser/types/interfaces/services/core/managers/context.d.ts +17 -0
  59. package/dist/browser/types/interfaces/services/core/managers/context.js +5 -0
  60. package/dist/browser/types/interfaces/services/core/managers/event.d.ts +328 -0
  61. package/dist/browser/types/interfaces/services/core/managers/event.js +5 -0
  62. package/dist/browser/types/interfaces/services/core/managers/index.d.ts +6 -0
  63. package/dist/browser/types/interfaces/services/core/managers/index.js +6 -0
  64. package/dist/browser/types/interfaces/services/core/managers/stream.d.ts +217 -0
  65. package/dist/browser/types/interfaces/services/core/managers/stream.js +5 -0
  66. package/dist/browser/types/interfaces/services/core/managers/task.d.ts +9 -0
  67. package/dist/browser/types/interfaces/services/core/managers/task.js +1 -0
  68. package/dist/browser/types/interfaces/services/core/service.d.ts +115 -0
  69. package/dist/browser/types/interfaces/services/core/service.js +5 -0
  70. package/dist/browser/types/interfaces/services/index.d.ts +4 -0
  71. package/dist/browser/types/interfaces/services/index.js +4 -0
  72. package/dist/browser/types/interfaces/services/mcp/index.d.ts +1 -0
  73. package/dist/browser/types/interfaces/services/mcp/index.js +1 -0
  74. package/dist/browser/types/interfaces/services/mcp/service.d.ts +49 -0
  75. package/dist/browser/types/interfaces/services/mcp/service.js +5 -0
  76. package/dist/browser/types/interfaces/services/protocol.d.ts +33 -0
  77. package/dist/browser/types/interfaces/services/protocol.js +34 -0
  78. package/dist/browser/types/interfaces/storage.d.ts +8 -0
  79. package/dist/browser/types/interfaces/storage.js +5 -0
  80. package/dist/browser/types/schemas/a2a/agent.d.ts +2583 -0
  81. package/dist/browser/types/schemas/a2a/agent.js +323 -0
  82. package/dist/browser/types/schemas/a2a/auth.d.ts +908 -0
  83. package/dist/browser/types/schemas/a2a/auth.js +283 -0
  84. package/dist/browser/types/schemas/a2a/error.d.ts +396 -0
  85. package/dist/browser/types/schemas/a2a/error.js +163 -0
  86. package/dist/browser/types/schemas/a2a/index.d.ts +11 -0
  87. package/dist/browser/types/schemas/a2a/index.js +11 -0
  88. package/dist/browser/types/schemas/a2a/kind.d.ts +11 -0
  89. package/dist/browser/types/schemas/a2a/kind.js +20 -0
  90. package/dist/browser/types/schemas/a2a/message.d.ts +10343 -0
  91. package/dist/browser/types/schemas/a2a/message.js +130 -0
  92. package/dist/browser/types/schemas/a2a/notification.d.ts +1517 -0
  93. package/dist/browser/types/schemas/a2a/notification.js +203 -0
  94. package/dist/browser/types/schemas/a2a/parameters.d.ts +956 -0
  95. package/dist/browser/types/schemas/a2a/parameters.js +241 -0
  96. package/dist/browser/types/schemas/a2a/protocol.d.ts +14363 -0
  97. package/dist/browser/types/schemas/a2a/protocol.js +59 -0
  98. package/dist/browser/types/schemas/a2a/rpc.d.ts +182 -0
  99. package/dist/browser/types/schemas/a2a/rpc.js +126 -0
  100. package/dist/browser/types/schemas/a2a/task.d.ts +5886 -0
  101. package/dist/browser/types/schemas/a2a/task.js +134 -0
  102. package/dist/browser/types/schemas/a2a/transport.d.ts +31 -0
  103. package/dist/browser/types/schemas/a2a/transport.js +28 -0
  104. package/dist/browser/types/schemas/index.d.ts +1 -0
  105. package/dist/browser/types/schemas/index.js +1 -0
  106. package/dist/browser/types/utils/index.d.ts +1 -0
  107. package/dist/browser/types/utils/index.js +1 -0
  108. package/dist/browser/types/utils/transform.d.ts +64 -0
  109. package/dist/browser/types/utils/transform.js +35 -0
  110. package/dist/browser/utils/common/constants.d.ts +11 -0
  111. package/dist/browser/utils/common/constants.js +38 -0
  112. package/dist/browser/utils/common/errors.d.ts +24 -0
  113. package/dist/browser/utils/common/errors.js +42 -0
  114. package/dist/browser/utils/common/utils.d.ts +9 -0
  115. package/dist/browser/utils/common/utils.js +11 -0
  116. package/dist/browser/utils/logging/index.d.ts +2 -0
  117. package/dist/browser/utils/logging/index.js +2 -0
  118. package/dist/browser/utils/logging/log.d.ts +33 -0
  119. package/dist/browser/utils/logging/log.js +75 -0
  120. package/dist/browser/utils/logging/logger.d.ts +18 -0
  121. package/dist/browser/utils/logging/logger.js +18 -0
  122. package/dist/client/a2a-client.d.ts +2 -1
  123. package/dist/client/a2a-client.js +13 -4
  124. package/dist/server/express/errors.js +1 -1
  125. package/dist/server/express/middeware.d.ts +2 -2
  126. package/dist/server/express/middeware.js +26 -6
  127. package/dist/server/express/server.d.ts +26 -25
  128. package/dist/server/express/server.js +32 -6
  129. package/dist/services/a2a/factory/builder.d.ts +24 -24
  130. package/dist/services/a2a/factory/builder.js +6 -1
  131. package/dist/services/a2a/factory/service.js +2 -1
  132. package/dist/services/a2a/helpers/agentcard-builder.d.ts +7 -0
  133. package/dist/services/a2a/helpers/agentcard-builder.js +23 -0
  134. package/dist/services/a2a/helpers/history.d.ts +2 -0
  135. package/dist/services/a2a/helpers/history.js +3 -0
  136. package/dist/services/a2a/helpers/index.d.ts +3 -0
  137. package/dist/services/a2a/helpers/index.js +3 -0
  138. package/dist/services/a2a/methods/get-task.d.ts +46 -46
  139. package/dist/services/a2a/methods/get-task.js +2 -0
  140. package/dist/services/a2a/methods/send-message.js +18 -1
  141. package/dist/services/a2a/service.d.ts +154 -153
  142. package/dist/services/a2a/service.js +20 -6
  143. package/dist/services/mcp/service.js +0 -1
  144. package/dist/transport/rpc/parser.js +2 -2
  145. package/dist/transport/rpc/rpc-client.js +2 -2
  146. package/dist/transport/trpc/a2a/factory/router.d.ts +1084 -1084
  147. package/dist/transport/trpc/a2a/routes/info.d.ts +36 -36
  148. package/dist/transport/trpc/a2a/routes/message/route.d.ts +225 -225
  149. package/dist/transport/trpc/a2a/routes/tasks/route.d.ts +257 -257
  150. package/dist/transport/trpc/a2a/trpc.d.ts +120 -120
  151. package/dist/types/interfaces/services/a2a/service.d.ts +6 -1
  152. package/dist/types/schemas/a2a/agent.d.ts +818 -818
  153. package/dist/types/schemas/a2a/agent.js +1 -23
  154. package/dist/types/schemas/a2a/auth.d.ts +197 -197
  155. package/dist/types/schemas/a2a/auth.js +4 -19
  156. package/dist/types/schemas/a2a/error.d.ts +24 -24
  157. package/dist/types/schemas/a2a/message.d.ts +4499 -4499
  158. package/dist/types/schemas/a2a/message.js +2 -10
  159. package/dist/types/schemas/a2a/notification.d.ts +403 -403
  160. package/dist/types/schemas/a2a/notification.js +3 -7
  161. package/dist/types/schemas/a2a/parameters.d.ts +264 -264
  162. package/dist/types/schemas/a2a/parameters.js +1 -14
  163. package/dist/types/schemas/a2a/protocol.d.ts +5988 -5988
  164. package/dist/types/schemas/a2a/rpc.d.ts +20 -20
  165. package/dist/types/schemas/a2a/rpc.js +0 -5
  166. package/dist/types/schemas/a2a/task.d.ts +2513 -2513
  167. package/dist/types/schemas/a2a/task.js +10 -11
  168. package/dist/utils/common/constants.js +1 -1
  169. package/dist/utils/common/errors.d.ts +2 -1
  170. package/dist/utils/common/errors.js +2 -1
  171. package/dist/utils/common/schema-validation.d.ts +2 -0
  172. package/dist/utils/common/schema-validation.js +12 -0
  173. package/dist/utils/index.d.ts +1 -0
  174. package/dist/utils/index.js +1 -0
  175. package/package.json +20 -17
@@ -2,9 +2,10 @@
2
2
  * Copyright 2025 The Artinet Project
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import { executeJsonRpcRequest, executeGetRequest, executeStreamEvents, } from "../transport/index.js";
6
- import { INTERNAL_ERROR } from "../utils/index.js";
7
- import { logError } from "../utils/logging/index.js";
5
+ import { executeJsonRpcRequest, executeGetRequest, } from "../transport/rpc/rpc-client.js";
6
+ import { executeStreamEvents } from "../transport/streaming/event-stream.js";
7
+ import { INTERNAL_ERROR } from "../utils/common/errors.js";
8
+ import { logError } from "../utils/logging/log.js";
8
9
  import { createMessageSendParams } from "../services/a2a/helpers/message-builder.js";
9
10
  /**
10
11
  * A2AClient is the main client class for interacting with Agent2Agent (A2A) protocol-compliant services.
@@ -16,6 +17,7 @@ export class A2AClient {
16
17
  customHeaders = {};
17
18
  fallbackPath;
18
19
  agentUrl;
20
+ mergePath;
19
21
  /**
20
22
  * Creates a new A2AClient instance.
21
23
  * @param baseUrl The base URL for the A2A server.
@@ -30,11 +32,12 @@ export class A2AClient {
30
32
  * const card = await client.agentCard();
31
33
  * console.log(card);
32
34
  */
33
- constructor(baseUrl, headers = {}, fallbackPath) {
35
+ constructor(baseUrl, headers = {}, fallbackPath, mergePath = false) {
34
36
  this.baseUrl = typeof baseUrl === "string" ? new URL(baseUrl) : baseUrl;
35
37
  this.customHeaders = headers;
36
38
  this.fallbackPath = fallbackPath ?? "/agent-card";
37
39
  this.agentUrl = this.baseUrl;
40
+ this.mergePath = mergePath;
38
41
  }
39
42
  /**
40
43
  * Retrieves the AgentCard from the A2A server.
@@ -47,6 +50,9 @@ export class A2AClient {
47
50
  }
48
51
  // Standard location for agent cards
49
52
  const wellKnownUrl = new URL("/.well-known/agent-card.json", this.baseUrl);
53
+ if (this.mergePath) {
54
+ wellKnownUrl.pathname = this.baseUrl.pathname + wellKnownUrl.pathname;
55
+ }
50
56
  try {
51
57
  try {
52
58
  if (!URL.canParse(wellKnownUrl)) {
@@ -60,6 +66,9 @@ export class A2AClient {
60
66
  }
61
67
  catch (error) {
62
68
  const fallbackUrl = new URL(this.fallbackPath, this.baseUrl);
69
+ if (this.mergePath) {
70
+ fallbackUrl.pathname = this.baseUrl.pathname + fallbackUrl.pathname;
71
+ }
63
72
  const fallbackCard = await executeGetRequest(fallbackUrl, this.customHeaders, "agent card (fallback)");
64
73
  if (!fallbackCard.name ||
65
74
  fallbackCard.name === null ||
@@ -13,7 +13,7 @@ export const errorHandler = (err, req, res, _) => {
13
13
  if (res.headersSent) {
14
14
  headersSent = true;
15
15
  }
16
- logError("errorHandler", JSON.stringify(err), err);
16
+ logError("errorHandler", JSON.stringify(err, null, 2), err);
17
17
  let reqId = null;
18
18
  try {
19
19
  if (req.body && typeof req.body === "object" && "id" in req.body) {
@@ -3,5 +3,5 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
  import { NextFunction, Request, Response } from "express";
6
- import { A2AServiceInterface } from "../../types/index.js";
7
- export declare function jsonRPCMiddleware(service: A2AServiceInterface, req: Request, res: Response, next: NextFunction): Promise<void>;
6
+ import { A2AServiceInterface, AgentCard } from "../../types/index.js";
7
+ export declare function jsonRPCMiddleware(service: A2AServiceInterface, req: Request, res: Response, next: NextFunction, extendedAgentCard?: AgentCard): Promise<void>;
@@ -2,7 +2,7 @@
2
2
  * Copyright 2025 The Artinet Project
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import { PUSH_NOTIFICATION_NOT_SUPPORTED, INVALID_REQUEST, INVALID_PARAMS, METHOD_NOT_FOUND, } from "../../utils/index.js";
5
+ import { PUSH_NOTIFICATION_NOT_SUPPORTED, INVALID_REQUEST, INVALID_PARAMS, METHOD_NOT_FOUND, AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED, } from "../../utils/index.js";
6
6
  import { logError } from "../../utils/logging/index.js";
7
7
  const isValidMethod = (method) => {
8
8
  return (method &&
@@ -12,8 +12,15 @@ const isValidMethod = (method) => {
12
12
  typeof method === "string");
13
13
  };
14
14
  const checkParams = (params, method) => {
15
- if (!params ||
16
- (typeof params === "object" && Object.keys(params).length === 0)) {
15
+ if (!params || (typeof params !== "object" && !Array.isArray(params))) {
16
+ throw INVALID_PARAMS({
17
+ data: {
18
+ message: "Invalid params",
19
+ method,
20
+ },
21
+ });
22
+ }
23
+ else if (typeof params === "object" && Object.keys(params).length === 0) {
17
24
  throw INVALID_PARAMS({
18
25
  data: {
19
26
  message: "No params provided",
@@ -22,10 +29,10 @@ const checkParams = (params, method) => {
22
29
  });
23
30
  }
24
31
  };
25
- export async function jsonRPCMiddleware(service, req, res, next) {
32
+ export async function jsonRPCMiddleware(service, req, res, next, extendedAgentCard) {
26
33
  const { method, params, id, jsonrpc } = req.body;
27
- // Validate JSON-RPC format
28
- if (jsonrpc !== "2.0" || !id) {
34
+ if (jsonrpc !== "2.0" ||
35
+ (id && typeof id !== "string" && typeof id !== "number" && id !== null)) {
29
36
  res.json({
30
37
  jsonrpc: "2.0",
31
38
  id: id || null,
@@ -98,6 +105,19 @@ export async function jsonRPCMiddleware(service, req, res, next) {
98
105
  },
99
106
  });
100
107
  }
108
+ case "agent/getAuthenticatedExtendedCard": {
109
+ if (!extendedAgentCard ||
110
+ service.agentCard.supportsAuthenticatedExtendedCard !== true) {
111
+ throw AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED({
112
+ data: {
113
+ message: "Authenticated Extended Card is not configured",
114
+ method,
115
+ },
116
+ });
117
+ }
118
+ result = extendedAgentCard;
119
+ break;
120
+ }
101
121
  default:
102
122
  throw METHOD_NOT_FOUND({
103
123
  data: {
@@ -3,12 +3,13 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
  import express from "express";
6
- import { Agent, FactoryParams as CreateAgentParams } from "../../types/index.js";
6
+ import { Agent, AgentCard, FactoryParams as CreateAgentParams } from "../../types/index.js";
7
7
  import { CorsOptions } from "cors";
8
8
  export interface ServerParams {
9
9
  app?: express.Express;
10
10
  corsOptions?: CorsOptions;
11
11
  basePath?: string;
12
+ extendedAgentCard?: AgentCard;
12
13
  }
13
14
  export declare function createAgentServer(params: ServerParams & {
14
15
  agent: Agent | CreateAgentParams;
@@ -23,48 +24,48 @@ export declare function createAgentServer(params: ServerParams & {
23
24
  parts: ({
24
25
  file: {
25
26
  bytes: string;
26
- name?: string | null | undefined;
27
- mimeType?: string | null | undefined;
28
- uri?: null | undefined;
27
+ name?: string | undefined;
28
+ mimeType?: string | undefined;
29
+ uri?: undefined;
29
30
  } | {
30
31
  uri: string;
31
- name?: string | null | undefined;
32
- bytes?: null | undefined;
33
- mimeType?: string | null | undefined;
32
+ name?: string | undefined;
33
+ bytes?: undefined;
34
+ mimeType?: string | undefined;
34
35
  };
35
36
  kind: "file";
36
- metadata?: Record<string, unknown> | null | undefined;
37
+ metadata?: Record<string, unknown> | undefined;
37
38
  } | {
38
39
  text: string;
39
40
  kind: "text";
40
- metadata?: Record<string, unknown> | null | undefined;
41
+ metadata?: Record<string, unknown> | undefined;
41
42
  } | {
42
43
  data: Record<string, unknown>;
43
44
  kind: "data";
44
- metadata?: Record<string, unknown> | null | undefined;
45
+ metadata?: Record<string, unknown> | undefined;
45
46
  })[];
46
47
  messageId: string;
47
- metadata?: Record<string, unknown> | null | undefined;
48
- extensions?: string[] | null | undefined;
49
- referenceTaskIds?: string[] | null | undefined;
50
- taskId?: string | null | undefined;
51
- contextId?: string | null | undefined;
48
+ metadata?: Record<string, unknown> | undefined;
49
+ extensions?: string[] | undefined;
50
+ referenceTaskIds?: string[] | undefined;
51
+ taskId?: string | undefined;
52
+ contextId?: string | undefined;
52
53
  };
53
- metadata?: Record<string, unknown> | null | undefined;
54
+ metadata?: Record<string, unknown> | undefined;
54
55
  configuration?: {
55
- historyLength?: number | null | undefined;
56
+ historyLength?: number | undefined;
56
57
  pushNotificationConfig?: {
57
58
  url: string;
58
- id?: string | null | undefined;
59
- token?: string | null | undefined;
59
+ id?: string | undefined;
60
+ token?: string | undefined;
60
61
  authentication?: {
61
62
  schemes: string[];
62
- credentials?: string | null | undefined;
63
- } | null | undefined;
64
- } | null | undefined;
65
- acceptedOutputModes?: string[] | null | undefined;
66
- blocking?: boolean | null | undefined;
67
- } | null | undefined;
63
+ credentials?: string | undefined;
64
+ } | undefined;
65
+ } | undefined;
66
+ acceptedOutputModes?: string[] | undefined;
67
+ blocking?: boolean | undefined;
68
+ } | undefined;
68
69
  }, import("../../types/index.js").TaskAndHistory, import("../../types/index.js").UpdateEvent>;
69
70
  };
70
71
  export type ExpressAgentServer = ReturnType<typeof createAgentServer>;
@@ -3,11 +3,27 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
  import express from "express";
6
- import { INVALID_REQUEST } from "../../utils/index.js";
6
+ import { INVALID_REQUEST, PARSE_ERROR } from "../../utils/index.js";
7
7
  import { createAgent } from "../../services/index.js";
8
8
  import cors from "cors";
9
9
  import { jsonRPCMiddleware } from "./middeware.js";
10
10
  import { errorHandler } from "./errors.js";
11
+ function rpcParser(req, res, next) {
12
+ express.json()(req, res, (err) => {
13
+ if (err) {
14
+ if (err instanceof SyntaxError &&
15
+ "status" in err &&
16
+ err.status === 400 &&
17
+ "body" in err) {
18
+ return next(PARSE_ERROR({
19
+ data: err.message,
20
+ }));
21
+ }
22
+ return next(err);
23
+ }
24
+ next();
25
+ });
26
+ }
11
27
  function ensureAgent(agentOrParams) {
12
28
  if (agentOrParams &&
13
29
  typeof agentOrParams === "object" &&
@@ -40,9 +56,19 @@ function ensureAgent(agentOrParams) {
40
56
  export function createAgentServer(params) {
41
57
  const { app = express(), basePath = "/", agentCardPath = "/.well-known/agent-card.json", agent, } = params;
42
58
  const agentInstance = ensureAgent(agent);
43
- app.use(express.json());
44
59
  app.use(cors(params.corsOptions));
45
- app.get(agentCardPath, (_, res) => {
60
+ if (agentCardPath !== "/.well-known/agent-card.json") {
61
+ // mount at the root for compliance with RFC8615 standard
62
+ app.use("/.well-known/agent-card.json", (_, res) => {
63
+ res.json(agentInstance.agentCard);
64
+ });
65
+ }
66
+ app.use(agentCardPath, (_, res) => {
67
+ // mount at the custom path
68
+ res.json(agentInstance.agentCard);
69
+ });
70
+ // mount at the old agent card path for backwards compatibility
71
+ app.use("/.well-known/agent.json", (_, res) => {
46
72
  res.json(agentInstance.agentCard);
47
73
  });
48
74
  /**
@@ -51,10 +77,10 @@ export function createAgentServer(params) {
51
77
  * transport layer.
52
78
  */
53
79
  //a standard express middleware to handle json-rpc requests
54
- app.post(basePath, express.json(), async (req, res, next) => {
80
+ app.post(basePath, rpcParser, async (req, res, next) => {
55
81
  const { jsonrpc } = req.body;
56
82
  if (jsonrpc === "2.0") {
57
- return await jsonRPCMiddleware(agentInstance, req, res, next);
83
+ return await jsonRPCMiddleware(agentInstance, req, res, next, params.extendedAgentCard);
58
84
  }
59
85
  next(INVALID_REQUEST({ data: { message: "Invalid JSON-RPC request" } }));
60
86
  });
@@ -73,7 +99,7 @@ export function createAgentServer(params) {
73
99
  },
74
100
  })
75
101
  );
76
- * we could also just use trpc directly or any other transport layer
102
+ * we could also use trpc directly or any other transport layer
77
103
  */
78
104
  return { app, agent: agentInstance };
79
105
  }
@@ -282,48 +282,48 @@ export declare const AgentBuilder: () => EngineBuilder<{
282
282
  parts: ({
283
283
  file: {
284
284
  bytes: string;
285
- name?: string | null | undefined;
286
- mimeType?: string | null | undefined;
287
- uri?: null | undefined;
285
+ name?: string | undefined;
286
+ mimeType?: string | undefined;
287
+ uri?: undefined;
288
288
  } | {
289
289
  uri: string;
290
- name?: string | null | undefined;
291
- bytes?: null | undefined;
292
- mimeType?: string | null | undefined;
290
+ name?: string | undefined;
291
+ bytes?: undefined;
292
+ mimeType?: string | undefined;
293
293
  };
294
294
  kind: "file";
295
- metadata?: Record<string, unknown> | null | undefined;
295
+ metadata?: Record<string, unknown> | undefined;
296
296
  } | {
297
297
  text: string;
298
298
  kind: "text";
299
- metadata?: Record<string, unknown> | null | undefined;
299
+ metadata?: Record<string, unknown> | undefined;
300
300
  } | {
301
301
  data: Record<string, unknown>;
302
302
  kind: "data";
303
- metadata?: Record<string, unknown> | null | undefined;
303
+ metadata?: Record<string, unknown> | undefined;
304
304
  })[];
305
305
  messageId: string;
306
- metadata?: Record<string, unknown> | null | undefined;
307
- extensions?: string[] | null | undefined;
308
- referenceTaskIds?: string[] | null | undefined;
309
- taskId?: string | null | undefined;
310
- contextId?: string | null | undefined;
306
+ metadata?: Record<string, unknown> | undefined;
307
+ extensions?: string[] | undefined;
308
+ referenceTaskIds?: string[] | undefined;
309
+ taskId?: string | undefined;
310
+ contextId?: string | undefined;
311
311
  };
312
- metadata?: Record<string, unknown> | null | undefined;
312
+ metadata?: Record<string, unknown> | undefined;
313
313
  configuration?: {
314
- historyLength?: number | null | undefined;
314
+ historyLength?: number | undefined;
315
315
  pushNotificationConfig?: {
316
316
  url: string;
317
- id?: string | null | undefined;
318
- token?: string | null | undefined;
317
+ id?: string | undefined;
318
+ token?: string | undefined;
319
319
  authentication?: {
320
320
  schemes: string[];
321
- credentials?: string | null | undefined;
322
- } | null | undefined;
323
- } | null | undefined;
324
- acceptedOutputModes?: string[] | null | undefined;
325
- blocking?: boolean | null | undefined;
326
- } | null | undefined;
321
+ credentials?: string | undefined;
322
+ } | undefined;
323
+ } | undefined;
324
+ acceptedOutputModes?: string[] | undefined;
325
+ blocking?: boolean | undefined;
326
+ } | undefined;
327
327
  }, []>;
328
328
  /**
329
329
  * Creates an agent execution engine from a list of workflow steps.
@@ -299,6 +299,7 @@ export function createAgentExecutor(stepsList) {
299
299
  }
300
300
  const taskStarted = SUBMITTED_UPDATE(taskId, contextId);
301
301
  yield taskStarted;
302
+ let finalState = TaskState.completed;
302
303
  const finalMessage = {
303
304
  taskId: taskId,
304
305
  contextId: contextId,
@@ -308,6 +309,10 @@ export function createAgentExecutor(stepsList) {
308
309
  parts: [],
309
310
  };
310
311
  for (const step of stepsList) {
312
+ if (context.isCancelled()) {
313
+ finalState = TaskState.canceled;
314
+ break;
315
+ }
311
316
  const ret = await step.step({ ...stepArgs });
312
317
  let parts = [];
313
318
  if (Array.isArray(ret)) {
@@ -350,7 +355,7 @@ export function createAgentExecutor(stepsList) {
350
355
  id: taskId,
351
356
  contextId: contextId,
352
357
  status: {
353
- state: TaskState.completed,
358
+ state: finalState,
354
359
  timestamp: new Date().toISOString(),
355
360
  message: finalMessage,
356
361
  },
@@ -5,7 +5,8 @@
5
5
  import { A2AService } from "../service.js";
6
6
  import { ContextManager, ConnectionManager, CancellationManager, TaskManager, } from "../managers/index.js";
7
7
  import { createMethods } from "./method.js";
8
+ import { createAgentCard } from "../helpers/agentcard-builder.js";
8
9
  export function createService(params) {
9
- return new A2AService(params.agentCard, params.engine, params.contexts ?? new ContextManager(), params.connections ?? new ConnectionManager(), params.cancellations ?? new CancellationManager(), params.tasks ?? new TaskManager(), createMethods(params.methods), params.events);
10
+ return new A2AService(createAgentCard(params.agentCard), params.engine, params.contexts ?? new ContextManager(), params.connections ?? new ConnectionManager(), params.cancellations ?? new CancellationManager(), params.tasks ?? new TaskManager(), createMethods(params.methods), params.events, params.enforceParamValidation ?? false);
10
11
  }
11
12
  export const createAgent = createService;
@@ -0,0 +1,7 @@
1
+ import { AgentCard, AgentCardParams } from "../../../types/index.js";
2
+ export declare class AgentCardBuilder {
3
+ agentCard: AgentCard;
4
+ constructor(agentCard: Partial<AgentCard> & Required<Pick<AgentCard, "name">>);
5
+ valueOf(): AgentCard;
6
+ }
7
+ export declare function createAgentCard(agentCard: AgentCardParams): AgentCard;
@@ -0,0 +1,23 @@
1
+ export class AgentCardBuilder {
2
+ agentCard;
3
+ constructor(agentCard) {
4
+ this.agentCard = {
5
+ ...agentCard,
6
+ protocolVersion: agentCard.protocolVersion ?? "0.3.0",
7
+ description: agentCard.description ?? "An agent that can use the A2A protocol.",
8
+ url: agentCard.url ?? "https://localhost:3000/a2a",
9
+ version: agentCard.version ?? "0.0.0",
10
+ capabilities: agentCard.capabilities ?? {},
11
+ defaultInputModes: agentCard.defaultInputModes ?? [],
12
+ defaultOutputModes: agentCard.defaultOutputModes ?? [],
13
+ skills: agentCard.skills ?? [],
14
+ preferredTransport: agentCard.preferredTransport ?? "JSONRPC",
15
+ };
16
+ }
17
+ valueOf() {
18
+ return this.agentCard;
19
+ }
20
+ }
21
+ export function createAgentCard(agentCard) {
22
+ return new AgentCardBuilder(typeof agentCard === "string" ? { name: agentCard } : agentCard).valueOf();
23
+ }
@@ -0,0 +1,2 @@
1
+ import { Message, Task } from "../../../types/index.js";
2
+ export declare function getLatestHistory(task: Task, length?: number): Message[];
@@ -0,0 +1,3 @@
1
+ export function getLatestHistory(task, length) {
2
+ return length ? task.history?.slice(-length) ?? [] : task.history ?? [];
3
+ }
@@ -1,3 +1,6 @@
1
1
  export * from "./part.js";
2
2
  export * from "./content.js";
3
3
  export * from "./message-builder.js";
4
+ export * from "./agentcard-builder.js";
5
+ export * from "./history.js";
6
+ export * from "../../../utils/common/schema-validation.js";
@@ -1,3 +1,6 @@
1
1
  export * from "./part.js";
2
2
  export * from "./content.js";
3
3
  export * from "./message-builder.js";
4
+ export * from "./agentcard-builder.js";
5
+ export * from "./history.js";
6
+ export * from "../../../utils/common/schema-validation.js";
@@ -13,100 +13,100 @@ export declare function getTask(input: TaskQueryParams, params: Omit<MethodParam
13
13
  parts: ({
14
14
  file: {
15
15
  bytes: string;
16
- name?: string | null | undefined;
17
- mimeType?: string | null | undefined;
18
- uri?: null | undefined;
16
+ name?: string | undefined;
17
+ mimeType?: string | undefined;
18
+ uri?: undefined;
19
19
  } | {
20
20
  uri: string;
21
- name?: string | null | undefined;
22
- bytes?: null | undefined;
23
- mimeType?: string | null | undefined;
21
+ name?: string | undefined;
22
+ bytes?: undefined;
23
+ mimeType?: string | undefined;
24
24
  };
25
25
  kind: "file";
26
- metadata?: Record<string, unknown> | null | undefined;
26
+ metadata?: Record<string, unknown> | undefined;
27
27
  } | {
28
28
  text: string;
29
29
  kind: "text";
30
- metadata?: Record<string, unknown> | null | undefined;
30
+ metadata?: Record<string, unknown> | undefined;
31
31
  } | {
32
32
  data: Record<string, unknown>;
33
33
  kind: "data";
34
- metadata?: Record<string, unknown> | null | undefined;
34
+ metadata?: Record<string, unknown> | undefined;
35
35
  })[];
36
36
  messageId: string;
37
- metadata?: Record<string, unknown> | null | undefined;
38
- extensions?: string[] | null | undefined;
39
- referenceTaskIds?: string[] | null | undefined;
40
- taskId?: string | null | undefined;
41
- contextId?: string | null | undefined;
42
- } | null | undefined;
43
- timestamp?: string | null | undefined;
37
+ metadata?: Record<string, unknown> | undefined;
38
+ extensions?: string[] | undefined;
39
+ referenceTaskIds?: string[] | undefined;
40
+ taskId?: string | undefined;
41
+ contextId?: string | undefined;
42
+ } | undefined;
43
+ timestamp?: string | undefined;
44
44
  };
45
45
  kind: "task";
46
46
  contextId: string;
47
- metadata?: Record<string, unknown> | null | undefined;
47
+ metadata?: Record<string, unknown> | undefined;
48
48
  history?: {
49
49
  role: "user" | "agent";
50
50
  kind: "message";
51
51
  parts: ({
52
52
  file: {
53
53
  bytes: string;
54
- name?: string | null | undefined;
55
- mimeType?: string | null | undefined;
56
- uri?: null | undefined;
54
+ name?: string | undefined;
55
+ mimeType?: string | undefined;
56
+ uri?: undefined;
57
57
  } | {
58
58
  uri: string;
59
- name?: string | null | undefined;
60
- bytes?: null | undefined;
61
- mimeType?: string | null | undefined;
59
+ name?: string | undefined;
60
+ bytes?: undefined;
61
+ mimeType?: string | undefined;
62
62
  };
63
63
  kind: "file";
64
- metadata?: Record<string, unknown> | null | undefined;
64
+ metadata?: Record<string, unknown> | undefined;
65
65
  } | {
66
66
  text: string;
67
67
  kind: "text";
68
- metadata?: Record<string, unknown> | null | undefined;
68
+ metadata?: Record<string, unknown> | undefined;
69
69
  } | {
70
70
  data: Record<string, unknown>;
71
71
  kind: "data";
72
- metadata?: Record<string, unknown> | null | undefined;
72
+ metadata?: Record<string, unknown> | undefined;
73
73
  })[];
74
74
  messageId: string;
75
- metadata?: Record<string, unknown> | null | undefined;
76
- extensions?: string[] | null | undefined;
77
- referenceTaskIds?: string[] | null | undefined;
78
- taskId?: string | null | undefined;
79
- contextId?: string | null | undefined;
80
- }[] | null | undefined;
75
+ metadata?: Record<string, unknown> | undefined;
76
+ extensions?: string[] | undefined;
77
+ referenceTaskIds?: string[] | undefined;
78
+ taskId?: string | undefined;
79
+ contextId?: string | undefined;
80
+ }[] | undefined;
81
81
  artifacts?: {
82
82
  artifactId: string;
83
83
  parts: ({
84
84
  file: {
85
85
  bytes: string;
86
- name?: string | null | undefined;
87
- mimeType?: string | null | undefined;
88
- uri?: null | undefined;
86
+ name?: string | undefined;
87
+ mimeType?: string | undefined;
88
+ uri?: undefined;
89
89
  } | {
90
90
  uri: string;
91
- name?: string | null | undefined;
92
- bytes?: null | undefined;
93
- mimeType?: string | null | undefined;
91
+ name?: string | undefined;
92
+ bytes?: undefined;
93
+ mimeType?: string | undefined;
94
94
  };
95
95
  kind: "file";
96
- metadata?: Record<string, unknown> | null | undefined;
96
+ metadata?: Record<string, unknown> | undefined;
97
97
  } | {
98
98
  text: string;
99
99
  kind: "text";
100
- metadata?: Record<string, unknown> | null | undefined;
100
+ metadata?: Record<string, unknown> | undefined;
101
101
  } | {
102
102
  data: Record<string, unknown>;
103
103
  kind: "data";
104
- metadata?: Record<string, unknown> | null | undefined;
104
+ metadata?: Record<string, unknown> | undefined;
105
105
  })[];
106
- name?: string | null | undefined;
107
- metadata?: Record<string, unknown> | null | undefined;
108
- description?: string | null | undefined;
109
- extension?: string[] | null | undefined;
110
- }[] | null | undefined;
106
+ name?: string | undefined;
107
+ metadata?: Record<string, unknown> | undefined;
108
+ description?: string | undefined;
109
+ extension?: string[] | undefined;
110
+ }[] | undefined;
111
111
  }>;
112
112
  export type GetTaskMethod = typeof getTask;
@@ -3,6 +3,7 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
  import { TASK_NOT_FOUND } from "../../../utils/index.js";
6
+ import { getLatestHistory } from "../helpers/index.js";
6
7
  export async function getTask(input, params) {
7
8
  const { service } = params;
8
9
  const state = await service.getState(input.id);
@@ -10,5 +11,6 @@ export async function getTask(input, params) {
10
11
  if (!task) {
11
12
  throw TASK_NOT_FOUND({ taskId: input.id });
12
13
  }
14
+ task.history = getLatestHistory(task, input.historyLength);
13
15
  return task;
14
16
  }