@mailmodo/a2a 0.3.3 → 0.3.7
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 +385 -173
- package/dist/a2a_request_handler-1Isk3l-0.d.mts +49 -0
- package/dist/a2a_request_handler-BuP9LgXH.d.ts +49 -0
- package/dist/chunk-7JFJW6P6.mjs +38 -0
- package/dist/chunk-AZGEDUZX.mjs +261 -0
- package/dist/chunk-BNBEZNW7.mjs +122 -0
- package/dist/chunk-PHP7LM4Y.mjs +8 -0
- package/dist/client/index.d.mts +666 -0
- package/dist/client/index.d.ts +666 -0
- package/dist/client/index.js +1605 -0
- package/dist/client/index.mjs +1448 -0
- package/dist/extensions-DvruCIzw.d.mts +2589 -0
- package/dist/extensions-DvruCIzw.d.ts +2589 -0
- package/dist/index.d.mts +5 -2758
- package/dist/index.d.ts +5 -2758
- package/dist/index.js +28 -1637
- package/dist/index.mjs +9 -1628
- package/dist/server/express/index.d.mts +97 -0
- package/dist/server/express/index.d.ts +97 -0
- package/dist/server/express/index.js +994 -0
- package/dist/server/express/index.mjs +646 -0
- package/dist/server/index.d.mts +316 -0
- package/dist/server/index.d.ts +316 -0
- package/dist/server/index.js +1386 -0
- package/dist/server/index.mjs +1070 -0
- package/package.json +51 -22
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Request, Express, RequestHandler, ErrorRequestHandler } from 'express';
|
|
2
|
+
import { U as User, a as UnauthenticatedUser, A as A2ARequestHandler } from '../../a2a_request_handler-1Isk3l-0.mjs';
|
|
3
|
+
import { ae as AgentCard } from '../../extensions-DvruCIzw.mjs';
|
|
4
|
+
|
|
5
|
+
type UserBuilder = (req: Request) => Promise<User>;
|
|
6
|
+
declare const UserBuilder: {
|
|
7
|
+
noAuthentication: () => Promise<UnauthenticatedUser>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use specific middlewares ({@link jsonRpcHandler}, {@link agentCardHandler}) directly.
|
|
12
|
+
*/
|
|
13
|
+
declare class A2AExpressApp {
|
|
14
|
+
private requestHandler;
|
|
15
|
+
private userBuilder;
|
|
16
|
+
constructor(requestHandler: A2ARequestHandler, userBuilder?: UserBuilder);
|
|
17
|
+
/**
|
|
18
|
+
* Adds A2A routes to an existing Express app.
|
|
19
|
+
* @param app Optional existing Express app.
|
|
20
|
+
* @param baseUrl The base URL for A2A endpoints (e.g., "/a2a/api").
|
|
21
|
+
* @param middlewares Optional array of Express middlewares to apply to the A2A routes.
|
|
22
|
+
* @param agentCardPath Optional custom path for the agent card endpoint (defaults to .well-known/agent-card.json).
|
|
23
|
+
* @returns The Express app with A2A routes.
|
|
24
|
+
*/
|
|
25
|
+
setupRoutes(app: Express, baseUrl?: string, middlewares?: Array<RequestHandler | ErrorRequestHandler>, agentCardPath?: string): Express;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface JsonRpcHandlerOptions {
|
|
29
|
+
requestHandler: A2ARequestHandler;
|
|
30
|
+
userBuilder: UserBuilder;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Creates Express.js middleware to handle A2A JSON-RPC requests.
|
|
34
|
+
* @example
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* // Handle at root
|
|
38
|
+
* app.use(jsonRpcHandler({ requestHandler: a2aRequestHandler, userBuilder: UserBuilder.noAuthentication }));
|
|
39
|
+
* // or
|
|
40
|
+
* app.use('/a2a/json-rpc', jsonRpcHandler({ requestHandler: a2aRequestHandler, userBuilder: UserBuilder.noAuthentication }));
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
declare function jsonRpcHandler(options: JsonRpcHandlerOptions): RequestHandler;
|
|
44
|
+
|
|
45
|
+
interface AgentCardHandlerOptions {
|
|
46
|
+
agentCardProvider: AgentCardProvider;
|
|
47
|
+
}
|
|
48
|
+
type AgentCardProvider = {
|
|
49
|
+
getAgentCard(): Promise<AgentCard>;
|
|
50
|
+
} | (() => Promise<AgentCard>);
|
|
51
|
+
/**
|
|
52
|
+
* Creates Express.js middleware to handle agent card requests.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* // With an existing A2ARequestHandler instance:
|
|
57
|
+
* app.use('/.well-known/agent-card.json', agentCardHandler({ agentCardProvider: a2aRequestHandler }));
|
|
58
|
+
* // or with a factory lambda:
|
|
59
|
+
* app.use('/.well-known/agent-card.json', agentCardHandler({ agentCardProvider: async () => agentCard }));
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
declare function agentCardHandler(options: AgentCardHandlerOptions): RequestHandler;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Options for configuring the HTTP+JSON/REST handler.
|
|
66
|
+
*/
|
|
67
|
+
interface RestHandlerOptions {
|
|
68
|
+
requestHandler: A2ARequestHandler;
|
|
69
|
+
userBuilder: UserBuilder;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Creates Express.js middleware to handle A2A HTTP+JSON/REST requests.
|
|
73
|
+
*
|
|
74
|
+
* This handler implements the A2A REST API specification with snake_case
|
|
75
|
+
* field names, providing endpoints for:
|
|
76
|
+
* - Agent card retrieval (GET /v1/card)
|
|
77
|
+
* - Message sending with optional streaming (POST /v1/message:send|stream)
|
|
78
|
+
* - Task management (GET/POST /v1/tasks/:taskId:cancel|subscribe)
|
|
79
|
+
* - Push notification configuration
|
|
80
|
+
*
|
|
81
|
+
* The handler acts as an adapter layer, converting between REST format
|
|
82
|
+
* (snake_case) at the API boundary and internal TypeScript format (camelCase)
|
|
83
|
+
* for business logic.
|
|
84
|
+
*
|
|
85
|
+
* @param options - Configuration options including the request handler
|
|
86
|
+
* @returns Express router configured with all A2A REST endpoints
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const app = express();
|
|
91
|
+
* const requestHandler = new DefaultRequestHandler(...);
|
|
92
|
+
* app.use('/api/rest', restHandler({ requestHandler, userBuilder: UserBuilder.noAuthentication }));
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
declare function restHandler(options: RestHandlerOptions): RequestHandler;
|
|
96
|
+
|
|
97
|
+
export { A2AExpressApp, type AgentCardHandlerOptions, type AgentCardProvider, type JsonRpcHandlerOptions, type RestHandlerOptions, UserBuilder, agentCardHandler, jsonRpcHandler, restHandler };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Request, Express, RequestHandler, ErrorRequestHandler } from 'express';
|
|
2
|
+
import { U as User, a as UnauthenticatedUser, A as A2ARequestHandler } from '../../a2a_request_handler-BuP9LgXH.js';
|
|
3
|
+
import { ae as AgentCard } from '../../extensions-DvruCIzw.js';
|
|
4
|
+
|
|
5
|
+
type UserBuilder = (req: Request) => Promise<User>;
|
|
6
|
+
declare const UserBuilder: {
|
|
7
|
+
noAuthentication: () => Promise<UnauthenticatedUser>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use specific middlewares ({@link jsonRpcHandler}, {@link agentCardHandler}) directly.
|
|
12
|
+
*/
|
|
13
|
+
declare class A2AExpressApp {
|
|
14
|
+
private requestHandler;
|
|
15
|
+
private userBuilder;
|
|
16
|
+
constructor(requestHandler: A2ARequestHandler, userBuilder?: UserBuilder);
|
|
17
|
+
/**
|
|
18
|
+
* Adds A2A routes to an existing Express app.
|
|
19
|
+
* @param app Optional existing Express app.
|
|
20
|
+
* @param baseUrl The base URL for A2A endpoints (e.g., "/a2a/api").
|
|
21
|
+
* @param middlewares Optional array of Express middlewares to apply to the A2A routes.
|
|
22
|
+
* @param agentCardPath Optional custom path for the agent card endpoint (defaults to .well-known/agent-card.json).
|
|
23
|
+
* @returns The Express app with A2A routes.
|
|
24
|
+
*/
|
|
25
|
+
setupRoutes(app: Express, baseUrl?: string, middlewares?: Array<RequestHandler | ErrorRequestHandler>, agentCardPath?: string): Express;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface JsonRpcHandlerOptions {
|
|
29
|
+
requestHandler: A2ARequestHandler;
|
|
30
|
+
userBuilder: UserBuilder;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Creates Express.js middleware to handle A2A JSON-RPC requests.
|
|
34
|
+
* @example
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* // Handle at root
|
|
38
|
+
* app.use(jsonRpcHandler({ requestHandler: a2aRequestHandler, userBuilder: UserBuilder.noAuthentication }));
|
|
39
|
+
* // or
|
|
40
|
+
* app.use('/a2a/json-rpc', jsonRpcHandler({ requestHandler: a2aRequestHandler, userBuilder: UserBuilder.noAuthentication }));
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
declare function jsonRpcHandler(options: JsonRpcHandlerOptions): RequestHandler;
|
|
44
|
+
|
|
45
|
+
interface AgentCardHandlerOptions {
|
|
46
|
+
agentCardProvider: AgentCardProvider;
|
|
47
|
+
}
|
|
48
|
+
type AgentCardProvider = {
|
|
49
|
+
getAgentCard(): Promise<AgentCard>;
|
|
50
|
+
} | (() => Promise<AgentCard>);
|
|
51
|
+
/**
|
|
52
|
+
* Creates Express.js middleware to handle agent card requests.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* // With an existing A2ARequestHandler instance:
|
|
57
|
+
* app.use('/.well-known/agent-card.json', agentCardHandler({ agentCardProvider: a2aRequestHandler }));
|
|
58
|
+
* // or with a factory lambda:
|
|
59
|
+
* app.use('/.well-known/agent-card.json', agentCardHandler({ agentCardProvider: async () => agentCard }));
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
declare function agentCardHandler(options: AgentCardHandlerOptions): RequestHandler;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Options for configuring the HTTP+JSON/REST handler.
|
|
66
|
+
*/
|
|
67
|
+
interface RestHandlerOptions {
|
|
68
|
+
requestHandler: A2ARequestHandler;
|
|
69
|
+
userBuilder: UserBuilder;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Creates Express.js middleware to handle A2A HTTP+JSON/REST requests.
|
|
73
|
+
*
|
|
74
|
+
* This handler implements the A2A REST API specification with snake_case
|
|
75
|
+
* field names, providing endpoints for:
|
|
76
|
+
* - Agent card retrieval (GET /v1/card)
|
|
77
|
+
* - Message sending with optional streaming (POST /v1/message:send|stream)
|
|
78
|
+
* - Task management (GET/POST /v1/tasks/:taskId:cancel|subscribe)
|
|
79
|
+
* - Push notification configuration
|
|
80
|
+
*
|
|
81
|
+
* The handler acts as an adapter layer, converting between REST format
|
|
82
|
+
* (snake_case) at the API boundary and internal TypeScript format (camelCase)
|
|
83
|
+
* for business logic.
|
|
84
|
+
*
|
|
85
|
+
* @param options - Configuration options including the request handler
|
|
86
|
+
* @returns Express router configured with all A2A REST endpoints
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const app = express();
|
|
91
|
+
* const requestHandler = new DefaultRequestHandler(...);
|
|
92
|
+
* app.use('/api/rest', restHandler({ requestHandler, userBuilder: UserBuilder.noAuthentication }));
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
declare function restHandler(options: RestHandlerOptions): RequestHandler;
|
|
96
|
+
|
|
97
|
+
export { A2AExpressApp, type AgentCardHandlerOptions, type AgentCardProvider, type JsonRpcHandlerOptions, type RestHandlerOptions, UserBuilder, agentCardHandler, jsonRpcHandler, restHandler };
|