@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.
- package/README.md +108 -58
- package/dist/browser/browser.d.ts +9 -0
- package/dist/browser/browser.js +10 -0
- package/dist/browser/client/a2a-client.d.ts +126 -0
- package/dist/browser/client/a2a-client.js +221 -0
- package/dist/browser/client/index.d.ts +1 -0
- package/dist/browser/client/index.js +1 -0
- package/dist/browser/services/a2a/helpers/message-builder.d.ts +12 -0
- package/dist/browser/services/a2a/helpers/message-builder.js +61 -0
- package/dist/browser/transport/rpc/parser.d.ts +15 -0
- package/dist/browser/transport/rpc/parser.js +48 -0
- package/dist/browser/transport/rpc/rpc-client.d.ts +80 -0
- package/dist/browser/transport/rpc/rpc-client.js +189 -0
- package/dist/browser/transport/streaming/event-stream.d.ts +25 -0
- package/dist/browser/transport/streaming/event-stream.js +99 -0
- package/dist/browser/types/ext.d.ts +13 -0
- package/dist/browser/types/ext.js +10 -0
- package/dist/browser/types/index.d.ts +4 -0
- package/dist/browser/types/index.js +4 -0
- package/dist/browser/types/interfaces/client.d.ts +135 -0
- package/dist/browser/types/interfaces/client.js +5 -0
- package/dist/browser/types/interfaces/index.d.ts +3 -0
- package/dist/browser/types/interfaces/index.js +3 -0
- package/dist/browser/types/interfaces/services/a2a/builder.d.ts +37 -0
- package/dist/browser/types/interfaces/services/a2a/builder.js +5 -0
- package/dist/browser/types/interfaces/services/a2a/context.d.ts +162 -0
- package/dist/browser/types/interfaces/services/a2a/context.js +5 -0
- package/dist/browser/types/interfaces/services/a2a/engine.d.ts +7 -0
- package/dist/browser/types/interfaces/services/a2a/engine.js +5 -0
- package/dist/browser/types/interfaces/services/a2a/index.d.ts +5 -0
- package/dist/browser/types/interfaces/services/a2a/index.js +5 -0
- package/dist/browser/types/interfaces/services/a2a/legacy.d.ts +93 -0
- package/dist/browser/types/interfaces/services/a2a/legacy.js +5 -0
- package/dist/browser/types/interfaces/services/a2a/service.d.ts +413 -0
- package/dist/browser/types/interfaces/services/a2a/service.js +5 -0
- package/dist/browser/types/interfaces/services/core/context/command.d.ts +25 -0
- package/dist/browser/types/interfaces/services/core/context/command.js +5 -0
- package/dist/browser/types/interfaces/services/core/context/context.d.ts +207 -0
- package/dist/browser/types/interfaces/services/core/context/context.js +5 -0
- package/dist/browser/types/interfaces/services/core/context/index.d.ts +3 -0
- package/dist/browser/types/interfaces/services/core/context/index.js +3 -0
- package/dist/browser/types/interfaces/services/core/context/types.d.ts +11 -0
- package/dist/browser/types/interfaces/services/core/context/types.js +5 -0
- package/dist/browser/types/interfaces/services/core/execution/engine.d.ts +106 -0
- package/dist/browser/types/interfaces/services/core/execution/engine.js +5 -0
- package/dist/browser/types/interfaces/services/core/execution/environment.d.ts +11 -0
- package/dist/browser/types/interfaces/services/core/execution/environment.js +5 -0
- package/dist/browser/types/interfaces/services/core/execution/execute.d.ts +7 -0
- package/dist/browser/types/interfaces/services/core/execution/execute.js +5 -0
- package/dist/browser/types/interfaces/services/core/execution/index.d.ts +3 -0
- package/dist/browser/types/interfaces/services/core/execution/index.js +3 -0
- package/dist/browser/types/interfaces/services/core/index.d.ts +4 -0
- package/dist/browser/types/interfaces/services/core/index.js +4 -0
- package/dist/browser/types/interfaces/services/core/managers/cancellation.d.ts +9 -0
- package/dist/browser/types/interfaces/services/core/managers/cancellation.js +5 -0
- package/dist/browser/types/interfaces/services/core/managers/connection.d.ts +9 -0
- package/dist/browser/types/interfaces/services/core/managers/connection.js +5 -0
- package/dist/browser/types/interfaces/services/core/managers/context.d.ts +17 -0
- package/dist/browser/types/interfaces/services/core/managers/context.js +5 -0
- package/dist/browser/types/interfaces/services/core/managers/event.d.ts +328 -0
- package/dist/browser/types/interfaces/services/core/managers/event.js +5 -0
- package/dist/browser/types/interfaces/services/core/managers/index.d.ts +6 -0
- package/dist/browser/types/interfaces/services/core/managers/index.js +6 -0
- package/dist/browser/types/interfaces/services/core/managers/stream.d.ts +217 -0
- package/dist/browser/types/interfaces/services/core/managers/stream.js +5 -0
- package/dist/browser/types/interfaces/services/core/managers/task.d.ts +9 -0
- package/dist/browser/types/interfaces/services/core/managers/task.js +1 -0
- package/dist/browser/types/interfaces/services/core/service.d.ts +115 -0
- package/dist/browser/types/interfaces/services/core/service.js +5 -0
- package/dist/browser/types/interfaces/services/index.d.ts +4 -0
- package/dist/browser/types/interfaces/services/index.js +4 -0
- package/dist/browser/types/interfaces/services/mcp/index.d.ts +1 -0
- package/dist/browser/types/interfaces/services/mcp/index.js +1 -0
- package/dist/browser/types/interfaces/services/mcp/service.d.ts +49 -0
- package/dist/browser/types/interfaces/services/mcp/service.js +5 -0
- package/dist/browser/types/interfaces/services/protocol.d.ts +33 -0
- package/dist/browser/types/interfaces/services/protocol.js +34 -0
- package/dist/browser/types/interfaces/storage.d.ts +8 -0
- package/dist/browser/types/interfaces/storage.js +5 -0
- package/dist/browser/types/schemas/a2a/agent.d.ts +2583 -0
- package/dist/browser/types/schemas/a2a/agent.js +323 -0
- package/dist/browser/types/schemas/a2a/auth.d.ts +908 -0
- package/dist/browser/types/schemas/a2a/auth.js +283 -0
- package/dist/browser/types/schemas/a2a/error.d.ts +396 -0
- package/dist/browser/types/schemas/a2a/error.js +163 -0
- package/dist/browser/types/schemas/a2a/index.d.ts +11 -0
- package/dist/browser/types/schemas/a2a/index.js +11 -0
- package/dist/browser/types/schemas/a2a/kind.d.ts +11 -0
- package/dist/browser/types/schemas/a2a/kind.js +20 -0
- package/dist/browser/types/schemas/a2a/message.d.ts +10343 -0
- package/dist/browser/types/schemas/a2a/message.js +130 -0
- package/dist/browser/types/schemas/a2a/notification.d.ts +1517 -0
- package/dist/browser/types/schemas/a2a/notification.js +203 -0
- package/dist/browser/types/schemas/a2a/parameters.d.ts +956 -0
- package/dist/browser/types/schemas/a2a/parameters.js +241 -0
- package/dist/browser/types/schemas/a2a/protocol.d.ts +14363 -0
- package/dist/browser/types/schemas/a2a/protocol.js +59 -0
- package/dist/browser/types/schemas/a2a/rpc.d.ts +182 -0
- package/dist/browser/types/schemas/a2a/rpc.js +126 -0
- package/dist/browser/types/schemas/a2a/task.d.ts +5886 -0
- package/dist/browser/types/schemas/a2a/task.js +134 -0
- package/dist/browser/types/schemas/a2a/transport.d.ts +31 -0
- package/dist/browser/types/schemas/a2a/transport.js +28 -0
- package/dist/browser/types/schemas/index.d.ts +1 -0
- package/dist/browser/types/schemas/index.js +1 -0
- package/dist/browser/types/utils/index.d.ts +1 -0
- package/dist/browser/types/utils/index.js +1 -0
- package/dist/browser/types/utils/transform.d.ts +64 -0
- package/dist/browser/types/utils/transform.js +35 -0
- package/dist/browser/utils/common/constants.d.ts +11 -0
- package/dist/browser/utils/common/constants.js +38 -0
- package/dist/browser/utils/common/errors.d.ts +24 -0
- package/dist/browser/utils/common/errors.js +42 -0
- package/dist/browser/utils/common/utils.d.ts +9 -0
- package/dist/browser/utils/common/utils.js +11 -0
- package/dist/browser/utils/logging/index.d.ts +2 -0
- package/dist/browser/utils/logging/index.js +2 -0
- package/dist/browser/utils/logging/log.d.ts +33 -0
- package/dist/browser/utils/logging/log.js +75 -0
- package/dist/browser/utils/logging/logger.d.ts +18 -0
- package/dist/browser/utils/logging/logger.js +18 -0
- package/dist/client/a2a-client.d.ts +2 -1
- package/dist/client/a2a-client.js +13 -4
- package/dist/server/express/errors.js +1 -1
- package/dist/server/express/middeware.d.ts +2 -2
- package/dist/server/express/middeware.js +26 -6
- package/dist/server/express/server.d.ts +26 -25
- package/dist/server/express/server.js +32 -6
- package/dist/services/a2a/factory/builder.d.ts +24 -24
- package/dist/services/a2a/factory/builder.js +6 -1
- package/dist/services/a2a/factory/service.js +2 -1
- package/dist/services/a2a/helpers/agentcard-builder.d.ts +7 -0
- package/dist/services/a2a/helpers/agentcard-builder.js +23 -0
- package/dist/services/a2a/helpers/history.d.ts +2 -0
- package/dist/services/a2a/helpers/history.js +3 -0
- package/dist/services/a2a/helpers/index.d.ts +3 -0
- package/dist/services/a2a/helpers/index.js +3 -0
- package/dist/services/a2a/methods/get-task.d.ts +46 -46
- package/dist/services/a2a/methods/get-task.js +2 -0
- package/dist/services/a2a/methods/send-message.js +18 -1
- package/dist/services/a2a/service.d.ts +154 -153
- package/dist/services/a2a/service.js +20 -6
- package/dist/services/mcp/service.js +0 -1
- package/dist/transport/rpc/parser.js +2 -2
- package/dist/transport/rpc/rpc-client.js +2 -2
- package/dist/transport/trpc/a2a/factory/router.d.ts +1084 -1084
- package/dist/transport/trpc/a2a/routes/info.d.ts +36 -36
- package/dist/transport/trpc/a2a/routes/message/route.d.ts +225 -225
- package/dist/transport/trpc/a2a/routes/tasks/route.d.ts +257 -257
- package/dist/transport/trpc/a2a/trpc.d.ts +120 -120
- package/dist/types/interfaces/services/a2a/service.d.ts +6 -1
- package/dist/types/schemas/a2a/agent.d.ts +818 -818
- package/dist/types/schemas/a2a/agent.js +1 -23
- package/dist/types/schemas/a2a/auth.d.ts +197 -197
- package/dist/types/schemas/a2a/auth.js +4 -19
- package/dist/types/schemas/a2a/error.d.ts +24 -24
- package/dist/types/schemas/a2a/message.d.ts +4499 -4499
- package/dist/types/schemas/a2a/message.js +2 -10
- package/dist/types/schemas/a2a/notification.d.ts +403 -403
- package/dist/types/schemas/a2a/notification.js +3 -7
- package/dist/types/schemas/a2a/parameters.d.ts +264 -264
- package/dist/types/schemas/a2a/parameters.js +1 -14
- package/dist/types/schemas/a2a/protocol.d.ts +5988 -5988
- package/dist/types/schemas/a2a/rpc.d.ts +20 -20
- package/dist/types/schemas/a2a/rpc.js +0 -5
- package/dist/types/schemas/a2a/task.d.ts +2513 -2513
- package/dist/types/schemas/a2a/task.js +10 -11
- package/dist/utils/common/constants.js +1 -1
- package/dist/utils/common/errors.d.ts +2 -1
- package/dist/utils/common/errors.js +2 -1
- package/dist/utils/common/schema-validation.d.ts +2 -0
- package/dist/utils/common/schema-validation.js +12 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- 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,
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
28
|
-
|
|
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 |
|
|
27
|
-
mimeType?: string |
|
|
28
|
-
uri?:
|
|
27
|
+
name?: string | undefined;
|
|
28
|
+
mimeType?: string | undefined;
|
|
29
|
+
uri?: undefined;
|
|
29
30
|
} | {
|
|
30
31
|
uri: string;
|
|
31
|
-
name?: string |
|
|
32
|
-
bytes?:
|
|
33
|
-
mimeType?: string |
|
|
32
|
+
name?: string | undefined;
|
|
33
|
+
bytes?: undefined;
|
|
34
|
+
mimeType?: string | undefined;
|
|
34
35
|
};
|
|
35
36
|
kind: "file";
|
|
36
|
-
metadata?: Record<string, unknown> |
|
|
37
|
+
metadata?: Record<string, unknown> | undefined;
|
|
37
38
|
} | {
|
|
38
39
|
text: string;
|
|
39
40
|
kind: "text";
|
|
40
|
-
metadata?: Record<string, unknown> |
|
|
41
|
+
metadata?: Record<string, unknown> | undefined;
|
|
41
42
|
} | {
|
|
42
43
|
data: Record<string, unknown>;
|
|
43
44
|
kind: "data";
|
|
44
|
-
metadata?: Record<string, unknown> |
|
|
45
|
+
metadata?: Record<string, unknown> | undefined;
|
|
45
46
|
})[];
|
|
46
47
|
messageId: string;
|
|
47
|
-
metadata?: Record<string, unknown> |
|
|
48
|
-
extensions?: string[] |
|
|
49
|
-
referenceTaskIds?: string[] |
|
|
50
|
-
taskId?: string |
|
|
51
|
-
contextId?: string |
|
|
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> |
|
|
54
|
+
metadata?: Record<string, unknown> | undefined;
|
|
54
55
|
configuration?: {
|
|
55
|
-
historyLength?: number |
|
|
56
|
+
historyLength?: number | undefined;
|
|
56
57
|
pushNotificationConfig?: {
|
|
57
58
|
url: string;
|
|
58
|
-
id?: string |
|
|
59
|
-
token?: string |
|
|
59
|
+
id?: string | undefined;
|
|
60
|
+
token?: string | undefined;
|
|
60
61
|
authentication?: {
|
|
61
62
|
schemes: string[];
|
|
62
|
-
credentials?: string |
|
|
63
|
-
} |
|
|
64
|
-
} |
|
|
65
|
-
acceptedOutputModes?: string[] |
|
|
66
|
-
blocking?: boolean |
|
|
67
|
-
} |
|
|
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
|
-
|
|
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,
|
|
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
|
|
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 |
|
|
286
|
-
mimeType?: string |
|
|
287
|
-
uri?:
|
|
285
|
+
name?: string | undefined;
|
|
286
|
+
mimeType?: string | undefined;
|
|
287
|
+
uri?: undefined;
|
|
288
288
|
} | {
|
|
289
289
|
uri: string;
|
|
290
|
-
name?: string |
|
|
291
|
-
bytes?:
|
|
292
|
-
mimeType?: string |
|
|
290
|
+
name?: string | undefined;
|
|
291
|
+
bytes?: undefined;
|
|
292
|
+
mimeType?: string | undefined;
|
|
293
293
|
};
|
|
294
294
|
kind: "file";
|
|
295
|
-
metadata?: Record<string, unknown> |
|
|
295
|
+
metadata?: Record<string, unknown> | undefined;
|
|
296
296
|
} | {
|
|
297
297
|
text: string;
|
|
298
298
|
kind: "text";
|
|
299
|
-
metadata?: Record<string, unknown> |
|
|
299
|
+
metadata?: Record<string, unknown> | undefined;
|
|
300
300
|
} | {
|
|
301
301
|
data: Record<string, unknown>;
|
|
302
302
|
kind: "data";
|
|
303
|
-
metadata?: Record<string, unknown> |
|
|
303
|
+
metadata?: Record<string, unknown> | undefined;
|
|
304
304
|
})[];
|
|
305
305
|
messageId: string;
|
|
306
|
-
metadata?: Record<string, unknown> |
|
|
307
|
-
extensions?: string[] |
|
|
308
|
-
referenceTaskIds?: string[] |
|
|
309
|
-
taskId?: string |
|
|
310
|
-
contextId?: string |
|
|
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> |
|
|
312
|
+
metadata?: Record<string, unknown> | undefined;
|
|
313
313
|
configuration?: {
|
|
314
|
-
historyLength?: number |
|
|
314
|
+
historyLength?: number | undefined;
|
|
315
315
|
pushNotificationConfig?: {
|
|
316
316
|
url: string;
|
|
317
|
-
id?: string |
|
|
318
|
-
token?: string |
|
|
317
|
+
id?: string | undefined;
|
|
318
|
+
token?: string | undefined;
|
|
319
319
|
authentication?: {
|
|
320
320
|
schemes: string[];
|
|
321
|
-
credentials?: string |
|
|
322
|
-
} |
|
|
323
|
-
} |
|
|
324
|
-
acceptedOutputModes?: string[] |
|
|
325
|
-
blocking?: boolean |
|
|
326
|
-
} |
|
|
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:
|
|
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
|
+
}
|
|
@@ -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 |
|
|
17
|
-
mimeType?: string |
|
|
18
|
-
uri?:
|
|
16
|
+
name?: string | undefined;
|
|
17
|
+
mimeType?: string | undefined;
|
|
18
|
+
uri?: undefined;
|
|
19
19
|
} | {
|
|
20
20
|
uri: string;
|
|
21
|
-
name?: string |
|
|
22
|
-
bytes?:
|
|
23
|
-
mimeType?: string |
|
|
21
|
+
name?: string | undefined;
|
|
22
|
+
bytes?: undefined;
|
|
23
|
+
mimeType?: string | undefined;
|
|
24
24
|
};
|
|
25
25
|
kind: "file";
|
|
26
|
-
metadata?: Record<string, unknown> |
|
|
26
|
+
metadata?: Record<string, unknown> | undefined;
|
|
27
27
|
} | {
|
|
28
28
|
text: string;
|
|
29
29
|
kind: "text";
|
|
30
|
-
metadata?: Record<string, unknown> |
|
|
30
|
+
metadata?: Record<string, unknown> | undefined;
|
|
31
31
|
} | {
|
|
32
32
|
data: Record<string, unknown>;
|
|
33
33
|
kind: "data";
|
|
34
|
-
metadata?: Record<string, unknown> |
|
|
34
|
+
metadata?: Record<string, unknown> | undefined;
|
|
35
35
|
})[];
|
|
36
36
|
messageId: string;
|
|
37
|
-
metadata?: Record<string, unknown> |
|
|
38
|
-
extensions?: string[] |
|
|
39
|
-
referenceTaskIds?: string[] |
|
|
40
|
-
taskId?: string |
|
|
41
|
-
contextId?: string |
|
|
42
|
-
} |
|
|
43
|
-
timestamp?: string |
|
|
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> |
|
|
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 |
|
|
55
|
-
mimeType?: string |
|
|
56
|
-
uri?:
|
|
54
|
+
name?: string | undefined;
|
|
55
|
+
mimeType?: string | undefined;
|
|
56
|
+
uri?: undefined;
|
|
57
57
|
} | {
|
|
58
58
|
uri: string;
|
|
59
|
-
name?: string |
|
|
60
|
-
bytes?:
|
|
61
|
-
mimeType?: string |
|
|
59
|
+
name?: string | undefined;
|
|
60
|
+
bytes?: undefined;
|
|
61
|
+
mimeType?: string | undefined;
|
|
62
62
|
};
|
|
63
63
|
kind: "file";
|
|
64
|
-
metadata?: Record<string, unknown> |
|
|
64
|
+
metadata?: Record<string, unknown> | undefined;
|
|
65
65
|
} | {
|
|
66
66
|
text: string;
|
|
67
67
|
kind: "text";
|
|
68
|
-
metadata?: Record<string, unknown> |
|
|
68
|
+
metadata?: Record<string, unknown> | undefined;
|
|
69
69
|
} | {
|
|
70
70
|
data: Record<string, unknown>;
|
|
71
71
|
kind: "data";
|
|
72
|
-
metadata?: Record<string, unknown> |
|
|
72
|
+
metadata?: Record<string, unknown> | undefined;
|
|
73
73
|
})[];
|
|
74
74
|
messageId: string;
|
|
75
|
-
metadata?: Record<string, unknown> |
|
|
76
|
-
extensions?: string[] |
|
|
77
|
-
referenceTaskIds?: string[] |
|
|
78
|
-
taskId?: string |
|
|
79
|
-
contextId?: string |
|
|
80
|
-
}[] |
|
|
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 |
|
|
87
|
-
mimeType?: string |
|
|
88
|
-
uri?:
|
|
86
|
+
name?: string | undefined;
|
|
87
|
+
mimeType?: string | undefined;
|
|
88
|
+
uri?: undefined;
|
|
89
89
|
} | {
|
|
90
90
|
uri: string;
|
|
91
|
-
name?: string |
|
|
92
|
-
bytes?:
|
|
93
|
-
mimeType?: string |
|
|
91
|
+
name?: string | undefined;
|
|
92
|
+
bytes?: undefined;
|
|
93
|
+
mimeType?: string | undefined;
|
|
94
94
|
};
|
|
95
95
|
kind: "file";
|
|
96
|
-
metadata?: Record<string, unknown> |
|
|
96
|
+
metadata?: Record<string, unknown> | undefined;
|
|
97
97
|
} | {
|
|
98
98
|
text: string;
|
|
99
99
|
kind: "text";
|
|
100
|
-
metadata?: Record<string, unknown> |
|
|
100
|
+
metadata?: Record<string, unknown> | undefined;
|
|
101
101
|
} | {
|
|
102
102
|
data: Record<string, unknown>;
|
|
103
103
|
kind: "data";
|
|
104
|
-
metadata?: Record<string, unknown> |
|
|
104
|
+
metadata?: Record<string, unknown> | undefined;
|
|
105
105
|
})[];
|
|
106
|
-
name?: string |
|
|
107
|
-
metadata?: Record<string, unknown> |
|
|
108
|
-
description?: string |
|
|
109
|
-
extension?: string[] |
|
|
110
|
-
}[] |
|
|
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
|
}
|