@keycardai/a2a 0.1.0
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 +110 -0
- package/dist/cjs/auth.d.ts +48 -0
- package/dist/cjs/auth.d.ts.map +1 -0
- package/dist/cjs/auth.js +90 -0
- package/dist/cjs/auth.js.map +1 -0
- package/dist/cjs/config.d.ts +35 -0
- package/dist/cjs/config.d.ts.map +1 -0
- package/dist/cjs/config.js +19 -0
- package/dist/cjs/config.js.map +1 -0
- package/dist/cjs/delegation.d.ts +56 -0
- package/dist/cjs/delegation.d.ts.map +1 -0
- package/dist/cjs/delegation.js +124 -0
- package/dist/cjs/delegation.js.map +1 -0
- package/dist/cjs/discovery.d.ts +30 -0
- package/dist/cjs/discovery.d.ts.map +1 -0
- package/dist/cjs/discovery.js +90 -0
- package/dist/cjs/discovery.js.map +1 -0
- package/dist/cjs/index.d.ts +14 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +34 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/server.d.ts +32 -0
- package/dist/cjs/server.d.ts.map +1 -0
- package/dist/cjs/server.js +53 -0
- package/dist/cjs/server.js.map +1 -0
- package/dist/cjs/types.d.ts +84 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +21 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/auth.d.ts +48 -0
- package/dist/esm/auth.d.ts.map +1 -0
- package/dist/esm/auth.js +84 -0
- package/dist/esm/auth.js.map +1 -0
- package/dist/esm/config.d.ts +35 -0
- package/dist/esm/config.d.ts.map +1 -0
- package/dist/esm/config.js +14 -0
- package/dist/esm/config.js.map +1 -0
- package/dist/esm/delegation.d.ts +56 -0
- package/dist/esm/delegation.d.ts.map +1 -0
- package/dist/esm/delegation.js +120 -0
- package/dist/esm/delegation.js.map +1 -0
- package/dist/esm/discovery.d.ts +30 -0
- package/dist/esm/discovery.d.ts.map +1 -0
- package/dist/esm/discovery.js +86 -0
- package/dist/esm/discovery.js.map +1 -0
- package/dist/esm/index.d.ts +14 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/server.d.ts +32 -0
- package/dist/esm/server.d.ts.map +1 -0
- package/dist/esm/server.js +47 -0
- package/dist/esm/server.js.map +1 -0
- package/dist/esm/types.d.ts +84 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +18 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _DelegationClient_instances, _DelegationClient_config, _DelegationClient_tokenClient, _DelegationClient_discovery, _DelegationClient_getDelegationToken, _DelegationClient_sendMessage;
|
|
13
|
+
import { TokenExchangeClient } from "@keycardai/oauth/tokenExchange";
|
|
14
|
+
import { ClientSecret } from "@keycardai/oauth/server/clientSecret";
|
|
15
|
+
import { ServiceDiscovery } from "./discovery.js";
|
|
16
|
+
import { getAuthServerUrl } from "./config.js";
|
|
17
|
+
const A2A_JSONRPC_PATH = "/a2a/jsonrpc";
|
|
18
|
+
const A2A_PROTOCOL_VERSION = "0.3";
|
|
19
|
+
const A2A_VERSION_HEADER = "x-a2a-protocol-version";
|
|
20
|
+
/**
|
|
21
|
+
* Client for delegating tasks to remote A2A agent services with
|
|
22
|
+
* Keycard token exchange.
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* const client = new DelegationClient(config);
|
|
26
|
+
*
|
|
27
|
+
* // Inside your AgentExecutor.execute():
|
|
28
|
+
* const auth = getKeycardAuth(requestContext);
|
|
29
|
+
* const result = await client.invokeService(targetUrl, "summarize this", {
|
|
30
|
+
* subjectToken: auth!.token,
|
|
31
|
+
* });
|
|
32
|
+
* eventBus.publish(result.message);
|
|
33
|
+
* eventBus.finished();
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* Python equivalent: `keycardai.a2a.DelegationClient`
|
|
37
|
+
*/
|
|
38
|
+
export class DelegationClient {
|
|
39
|
+
constructor(config, options) {
|
|
40
|
+
_DelegationClient_instances.add(this);
|
|
41
|
+
_DelegationClient_config.set(this, void 0);
|
|
42
|
+
_DelegationClient_tokenClient.set(this, void 0);
|
|
43
|
+
_DelegationClient_discovery.set(this, void 0);
|
|
44
|
+
__classPrivateFieldSet(this, _DelegationClient_config, config, "f");
|
|
45
|
+
__classPrivateFieldSet(this, _DelegationClient_discovery, options?.discovery ?? new ServiceDiscovery(), "f");
|
|
46
|
+
__classPrivateFieldSet(this, _DelegationClient_tokenClient, new TokenExchangeClient(getAuthServerUrl(config), {
|
|
47
|
+
credential: new ClientSecret(config.clientId, config.clientSecret),
|
|
48
|
+
}), "f");
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Discover, authenticate, and invoke a remote A2A agent in one call.
|
|
52
|
+
*/
|
|
53
|
+
async invokeService(serviceUrl, task, options) {
|
|
54
|
+
const agentCard = await __classPrivateFieldGet(this, _DelegationClient_discovery, "f").getServiceCard(serviceUrl);
|
|
55
|
+
const delegationToken = await __classPrivateFieldGet(this, _DelegationClient_instances, "m", _DelegationClient_getDelegationToken).call(this, serviceUrl, options.subjectToken);
|
|
56
|
+
const message = buildUserMessage(task, options.metadata);
|
|
57
|
+
const jsonrpcUrl = buildJsonrpcUrl(serviceUrl, agentCard);
|
|
58
|
+
const responseMessage = await __classPrivateFieldGet(this, _DelegationClient_instances, "m", _DelegationClient_sendMessage).call(this, jsonrpcUrl, message, delegationToken, options.timeoutMs);
|
|
59
|
+
return { message: responseMessage, agentCard };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
_DelegationClient_config = new WeakMap(), _DelegationClient_tokenClient = new WeakMap(), _DelegationClient_discovery = new WeakMap(), _DelegationClient_instances = new WeakSet(), _DelegationClient_getDelegationToken = async function _DelegationClient_getDelegationToken(targetUrl, subjectToken) {
|
|
63
|
+
const response = await __classPrivateFieldGet(this, _DelegationClient_tokenClient, "f").exchangeToken({
|
|
64
|
+
subjectToken,
|
|
65
|
+
subjectTokenType: "urn:ietf:params:oauth:token-type:access_token",
|
|
66
|
+
resource: targetUrl,
|
|
67
|
+
});
|
|
68
|
+
return response.accessToken;
|
|
69
|
+
}, _DelegationClient_sendMessage = async function _DelegationClient_sendMessage(jsonrpcUrl, message, bearerToken, timeoutMs = 30_000) {
|
|
70
|
+
const requestBody = {
|
|
71
|
+
jsonrpc: "2.0",
|
|
72
|
+
id: crypto.randomUUID(),
|
|
73
|
+
method: "message/send",
|
|
74
|
+
params: { message },
|
|
75
|
+
};
|
|
76
|
+
const response = await fetch(jsonrpcUrl, {
|
|
77
|
+
method: "POST",
|
|
78
|
+
headers: {
|
|
79
|
+
"Content-Type": "application/json",
|
|
80
|
+
Accept: "application/json",
|
|
81
|
+
Authorization: `Bearer ${bearerToken}`,
|
|
82
|
+
[A2A_VERSION_HEADER]: A2A_PROTOCOL_VERSION,
|
|
83
|
+
},
|
|
84
|
+
body: JSON.stringify(requestBody),
|
|
85
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
86
|
+
});
|
|
87
|
+
if (!response.ok) {
|
|
88
|
+
throw new Error(`DelegationClient: A2A request to "${jsonrpcUrl}" failed (HTTP ${response.status})`);
|
|
89
|
+
}
|
|
90
|
+
let body;
|
|
91
|
+
try {
|
|
92
|
+
body = await response.json();
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
throw new Error(`DelegationClient: response from "${jsonrpcUrl}" is not valid JSON`);
|
|
96
|
+
}
|
|
97
|
+
const envelope = body;
|
|
98
|
+
if (!envelope.result?.message) {
|
|
99
|
+
throw new Error(`DelegationClient: A2A error from "${jsonrpcUrl}": ${envelope.error?.message ?? "unknown error"}`);
|
|
100
|
+
}
|
|
101
|
+
return envelope.result.message;
|
|
102
|
+
};
|
|
103
|
+
function buildUserMessage(text, metadata) {
|
|
104
|
+
return {
|
|
105
|
+
messageId: crypto.randomUUID(),
|
|
106
|
+
role: "user",
|
|
107
|
+
parts: [{ kind: "text", text }],
|
|
108
|
+
...(metadata ? { metadata } : {}),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function buildJsonrpcUrl(serviceUrl, agentCard) {
|
|
112
|
+
// agentCard.url IS the JSONRPC endpoint per the A2A spec — use it directly.
|
|
113
|
+
// Do not append A2A_JSONRPC_PATH: the agent card is built with getJsonrpcUrl()
|
|
114
|
+
// which already includes /a2a/jsonrpc, so appending would double the path.
|
|
115
|
+
if (agentCard.url) {
|
|
116
|
+
return agentCard.url;
|
|
117
|
+
}
|
|
118
|
+
return `${serviceUrl.replace(/\/$/, "")}${A2A_JSONRPC_PATH}`;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=delegation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegation.js","sourceRoot":"","sources":["../../src/delegation.ts"],"names":[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|
|
5
|
+
*
|
|
6
|
+
* Python equivalent: `keycardai.a2a.ServiceDiscovery`
|
|
7
|
+
*/
|
|
8
|
+
export declare class ServiceDiscovery {
|
|
9
|
+
#private;
|
|
10
|
+
constructor(options?: {
|
|
11
|
+
cacheTtlMs?: number;
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* Fetch the agent card from the given service URL.
|
|
15
|
+
* Validates that the card has a `name` field.
|
|
16
|
+
*/
|
|
17
|
+
discoverService(serviceUrl: string): Promise<AgentCard>;
|
|
18
|
+
/**
|
|
19
|
+
* Return a cached agent card, fetching if absent or expired.
|
|
20
|
+
*/
|
|
21
|
+
getServiceCard(serviceUrl: string, options?: {
|
|
22
|
+
forceRefresh?: boolean;
|
|
23
|
+
}): Promise<AgentCard>;
|
|
24
|
+
clearCache(): void;
|
|
25
|
+
getCacheStats(): {
|
|
26
|
+
size: number;
|
|
27
|
+
keys: string[];
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=discovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../src/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAU7C;;;;GAIG;AACH,qBAAa,gBAAgB;;gBAIf,OAAO,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE;IAI7C;;;OAGG;IACG,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAqB7D;;OAEG;IACG,cAAc,CAClB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,OAAO,CAAA;KAAE,GACnC,OAAO,CAAC,SAAS,CAAC;IAWrB,UAAU,IAAI,IAAI;IAIlB,aAAa,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE;CAGlD"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _ServiceDiscovery_cacheTtlMs, _ServiceDiscovery_cache;
|
|
13
|
+
const DEFAULT_CACHE_TTL_MS = 15 * 60 * 1000; // 15 minutes
|
|
14
|
+
const AGENT_CARD_PATH = "/.well-known/agent-card.json";
|
|
15
|
+
/**
|
|
16
|
+
* Fetches and caches agent cards from remote A2A services.
|
|
17
|
+
*
|
|
18
|
+
* Python equivalent: `keycardai.a2a.ServiceDiscovery`
|
|
19
|
+
*/
|
|
20
|
+
export class ServiceDiscovery {
|
|
21
|
+
constructor(options) {
|
|
22
|
+
_ServiceDiscovery_cacheTtlMs.set(this, void 0);
|
|
23
|
+
_ServiceDiscovery_cache.set(this, new Map());
|
|
24
|
+
__classPrivateFieldSet(this, _ServiceDiscovery_cacheTtlMs, options?.cacheTtlMs ?? DEFAULT_CACHE_TTL_MS, "f");
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Fetch the agent card from the given service URL.
|
|
28
|
+
* Validates that the card has a `name` field.
|
|
29
|
+
*/
|
|
30
|
+
async discoverService(serviceUrl) {
|
|
31
|
+
const cardUrl = buildAgentCardUrl(serviceUrl);
|
|
32
|
+
const response = await fetch(cardUrl, {
|
|
33
|
+
headers: { Accept: "application/json" },
|
|
34
|
+
signal: AbortSignal.timeout(10_000),
|
|
35
|
+
});
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
throw new Error(`ServiceDiscovery: failed to fetch agent card from "${cardUrl}" (HTTP ${response.status})`);
|
|
38
|
+
}
|
|
39
|
+
let card;
|
|
40
|
+
try {
|
|
41
|
+
card = await response.json();
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
throw new Error(`ServiceDiscovery: agent card at "${cardUrl}" is not valid JSON`);
|
|
45
|
+
}
|
|
46
|
+
validateAgentCard(card, cardUrl);
|
|
47
|
+
return card;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Return a cached agent card, fetching if absent or expired.
|
|
51
|
+
*/
|
|
52
|
+
async getServiceCard(serviceUrl, options) {
|
|
53
|
+
const key = normalizeUrl(serviceUrl);
|
|
54
|
+
const cached = __classPrivateFieldGet(this, _ServiceDiscovery_cache, "f").get(key);
|
|
55
|
+
if (!options?.forceRefresh && cached && Date.now() < cached.expiresAt) {
|
|
56
|
+
return cached.card;
|
|
57
|
+
}
|
|
58
|
+
const card = await this.discoverService(serviceUrl);
|
|
59
|
+
__classPrivateFieldGet(this, _ServiceDiscovery_cache, "f").set(key, { card, expiresAt: Date.now() + __classPrivateFieldGet(this, _ServiceDiscovery_cacheTtlMs, "f") });
|
|
60
|
+
return card;
|
|
61
|
+
}
|
|
62
|
+
clearCache() {
|
|
63
|
+
__classPrivateFieldGet(this, _ServiceDiscovery_cache, "f").clear();
|
|
64
|
+
}
|
|
65
|
+
getCacheStats() {
|
|
66
|
+
return { size: __classPrivateFieldGet(this, _ServiceDiscovery_cache, "f").size, keys: Array.from(__classPrivateFieldGet(this, _ServiceDiscovery_cache, "f").keys()) };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
_ServiceDiscovery_cacheTtlMs = new WeakMap(), _ServiceDiscovery_cache = new WeakMap();
|
|
70
|
+
function buildAgentCardUrl(serviceUrl) {
|
|
71
|
+
const base = serviceUrl.endsWith("/") ? serviceUrl.slice(0, -1) : serviceUrl;
|
|
72
|
+
return `${base}${AGENT_CARD_PATH}`;
|
|
73
|
+
}
|
|
74
|
+
function normalizeUrl(url) {
|
|
75
|
+
return url.endsWith("/") ? url.slice(0, -1) : url;
|
|
76
|
+
}
|
|
77
|
+
function validateAgentCard(card, url) {
|
|
78
|
+
if (!card || typeof card !== "object" || Array.isArray(card)) {
|
|
79
|
+
throw new Error(`ServiceDiscovery: agent card at "${url}" is not a JSON object`);
|
|
80
|
+
}
|
|
81
|
+
const obj = card;
|
|
82
|
+
if (typeof obj.name !== "string" || !obj.name) {
|
|
83
|
+
throw new Error(`ServiceDiscovery: agent card at "${url}" is missing required field "name"`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=discovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../src/discovery.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,MAAM,oBAAoB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa;AAC1D,MAAM,eAAe,GAAG,8BAA8B,CAAC;AAOvD;;;;GAIG;AACH,MAAM,OAAO,gBAAgB;IAI3B,YAAY,OAAiC;QAH7C,+CAAoB;QACpB,kCAAS,IAAI,GAAG,EAAsB,EAAC;QAGrC,uBAAA,IAAI,gCAAe,OAAO,EAAE,UAAU,IAAI,oBAAoB,MAAA,CAAC;IACjE,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,eAAe,CAAC,UA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
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { KeycardUser, keycardUserBuilder, getKeycardAuth } from "./auth.js";
|
|
2
|
+
export type { KeycardUserBuilderOptions } from "./auth.js";
|
|
3
|
+
export { createKeycardRequestHandler, buildAgentCard } from "./server.js";
|
|
4
|
+
export type { AgentExecutor, RequestContext, ExecutionEventBus } from "./server.js";
|
|
5
|
+
export { InMemoryTaskStore } from "./server.js";
|
|
6
|
+
export type { AgentServiceConfig } from "./config.js";
|
|
7
|
+
export { getAgentCardUrl, getJsonrpcUrl, getAuthServerUrl } from "./config.js";
|
|
8
|
+
export { ServiceDiscovery } from "./discovery.js";
|
|
9
|
+
export { DelegationClient } from "./delegation.js";
|
|
10
|
+
export type { DelegationResult, InvokeOptions } from "./delegation.js";
|
|
11
|
+
export { agentCardHandler, jsonRpcHandler, restHandler, UserBuilder, } from "@a2a-js/sdk/server/express";
|
|
12
|
+
export type { AgentCard, Message, Task } from "@a2a-js/sdk";
|
|
13
|
+
export { DefaultRequestHandler } from "@a2a-js/sdk/server";
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC5E,YAAY,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAG3D,OAAO,EAAE,2BAA2B,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC1E,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,YAAY,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGlD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIvE,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,WAAW,GACZ,MAAM,4BAA4B,CAAC;AAGpC,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Keycard auth adapter for @a2a-js/sdk
|
|
2
|
+
export { KeycardUser, keycardUserBuilder, getKeycardAuth } from "./auth.js";
|
|
3
|
+
// Server convenience helpers (thin wrappers over @a2a-js/sdk)
|
|
4
|
+
export { createKeycardRequestHandler, buildAgentCard } from "./server.js";
|
|
5
|
+
export { InMemoryTaskStore } from "./server.js";
|
|
6
|
+
export { getAgentCardUrl, getJsonrpcUrl, getAuthServerUrl } from "./config.js";
|
|
7
|
+
// Discovery
|
|
8
|
+
export { ServiceDiscovery } from "./discovery.js";
|
|
9
|
+
// Delegation client
|
|
10
|
+
export { DelegationClient } from "./delegation.js";
|
|
11
|
+
// Re-export the SDK's Express handlers and UserBuilder so customers
|
|
12
|
+
// import from one place.
|
|
13
|
+
export { agentCardHandler, jsonRpcHandler, restHandler, UserBuilder, } from "@a2a-js/sdk/server/express";
|
|
14
|
+
export { DefaultRequestHandler } from "@a2a-js/sdk/server";
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG5E,8DAA8D;AAC9D,OAAO,EAAE,2BAA2B,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIhD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/E,YAAY;AACZ,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,oBAAoB;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAGnD,oEAAoE;AACpE,yBAAyB;AACzB,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,WAAW,GACZ,MAAM,4BAA4B,CAAC;AAIpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "module"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DefaultRequestHandler, type AgentExecutor, type TaskStore } from "@a2a-js/sdk/server";
|
|
2
|
+
import type { AgentCard } from "@a2a-js/sdk";
|
|
3
|
+
import type { AgentServiceConfig } from "./config.js";
|
|
4
|
+
export type { AgentExecutor, RequestContext, ExecutionEventBus } from "@a2a-js/sdk/server";
|
|
5
|
+
export { InMemoryTaskStore } from "@a2a-js/sdk/server";
|
|
6
|
+
/**
|
|
7
|
+
* Creates a `DefaultRequestHandler` from `@a2a-js/sdk` pre-wired with a
|
|
8
|
+
* `KeycardUser`-aware agent card and the provided executor.
|
|
9
|
+
*
|
|
10
|
+
* Pass the returned handler to the SDK's Express adapters alongside a
|
|
11
|
+
* `keycardUserBuilder` for auth:
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* const requestHandler = createKeycardRequestHandler(executor, config, agentCard);
|
|
15
|
+
* const userBuilder = keycardUserBuilder({ issuer: "https://zone.keycard.cloud" });
|
|
16
|
+
*
|
|
17
|
+
* app.get("/.well-known/agent-card.json", agentCardHandler({ agentCardProvider: requestHandler }));
|
|
18
|
+
* app.post("/a2a/jsonrpc", jsonRpcHandler({ requestHandler, userBuilder }));
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Python equivalent: the composition of `create_agent_card_server`,
|
|
22
|
+
* `serve_agent`, and the `KeycardServerCallContextBuilder` from `keycardai-a2a`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createKeycardRequestHandler(executor: AgentExecutor, agentCard: AgentCard, options?: {
|
|
25
|
+
taskStore?: TaskStore;
|
|
26
|
+
}): DefaultRequestHandler;
|
|
27
|
+
/**
|
|
28
|
+
* Build an `AgentCard` from an `AgentServiceConfig` for use with
|
|
29
|
+
* `createKeycardRequestHandler`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function buildAgentCard(config: AgentServiceConfig): AgentCard;
|
|
32
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EAErB,KAAK,aAAa,EAClB,KAAK,SAAS,EACf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGtD,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC3F,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,aAAa,EACvB,SAAS,EAAE,SAAS,EACpB,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,SAAS,CAAA;CAAE,GAClC,qBAAqB,CAMvB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,kBAAkB,GAAG,SAAS,CAiBpE"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { DefaultRequestHandler, InMemoryTaskStore, } from "@a2a-js/sdk/server";
|
|
2
|
+
import { getJsonrpcUrl } from "./config.js";
|
|
3
|
+
export { InMemoryTaskStore } from "@a2a-js/sdk/server";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a `DefaultRequestHandler` from `@a2a-js/sdk` pre-wired with a
|
|
6
|
+
* `KeycardUser`-aware agent card and the provided executor.
|
|
7
|
+
*
|
|
8
|
+
* Pass the returned handler to the SDK's Express adapters alongside a
|
|
9
|
+
* `keycardUserBuilder` for auth:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* const requestHandler = createKeycardRequestHandler(executor, config, agentCard);
|
|
13
|
+
* const userBuilder = keycardUserBuilder({ issuer: "https://zone.keycard.cloud" });
|
|
14
|
+
*
|
|
15
|
+
* app.get("/.well-known/agent-card.json", agentCardHandler({ agentCardProvider: requestHandler }));
|
|
16
|
+
* app.post("/a2a/jsonrpc", jsonRpcHandler({ requestHandler, userBuilder }));
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Python equivalent: the composition of `create_agent_card_server`,
|
|
20
|
+
* `serve_agent`, and the `KeycardServerCallContextBuilder` from `keycardai-a2a`.
|
|
21
|
+
*/
|
|
22
|
+
export function createKeycardRequestHandler(executor, agentCard, options) {
|
|
23
|
+
return new DefaultRequestHandler(agentCard, options?.taskStore ?? new InMemoryTaskStore(), executor);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Build an `AgentCard` from an `AgentServiceConfig` for use with
|
|
27
|
+
* `createKeycardRequestHandler`.
|
|
28
|
+
*/
|
|
29
|
+
export function buildAgentCard(config) {
|
|
30
|
+
return {
|
|
31
|
+
name: config.serviceName,
|
|
32
|
+
description: config.description ?? "",
|
|
33
|
+
url: getJsonrpcUrl(config),
|
|
34
|
+
version: "0.1",
|
|
35
|
+
protocolVersion: "0.3",
|
|
36
|
+
capabilities: {},
|
|
37
|
+
defaultInputModes: ["text/plain"],
|
|
38
|
+
defaultOutputModes: ["text/plain"],
|
|
39
|
+
skills: config.skills?.map((s) => ({
|
|
40
|
+
id: s.id,
|
|
41
|
+
name: s.name,
|
|
42
|
+
description: s.description,
|
|
43
|
+
tags: s.tags ?? [],
|
|
44
|
+
})) ?? [],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,iBAAiB,GAGlB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,2BAA2B,CACzC,QAAuB,EACvB,SAAoB,EACpB,OAAmC;IAEnC,OAAO,IAAI,qBAAqB,CAC9B,SAAS,EACT,OAAO,EAAE,SAAS,IAAI,IAAI,iBAAiB,EAAE,EAC7C,QAAQ,CACT,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,MAA0B;IACvD,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,WAAW;QACxB,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,EAAE;QACrC,GAAG,EAAE,aAAa,CAAC,MAAM,CAAC;QAC1B,OAAO,EAAE,KAAK;QACd,eAAe,EAAE,KAAK;QACtB,YAAY,EAAE,EAAE;QAChB,iBAAiB,EAAE,CAAC,YAAY,CAAC;QACjC,kBAAkB,EAAE,CAAC,YAAY,CAAC;QAClC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACjC,EAAE,EAAE,CAAC,CAAC,EAAE;YACR,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,WAAW,EAAE,CAAC,CAAC,WAAW;YAC1B,IAAI,EAAE,CAAC,CAAC,IAAI,IAAI,EAAE;SACnB,CAAC,CAAC,IAAI,EAAE;KACV,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A2A (Agent-to-Agent) protocol types.
|
|
3
|
+
* Reference: https://google.github.io/A2A
|
|
4
|
+
*/
|
|
5
|
+
export interface AgentSkill {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
tags?: readonly string[];
|
|
10
|
+
}
|
|
11
|
+
export interface AgentCapabilities {
|
|
12
|
+
streaming?: boolean;
|
|
13
|
+
pushNotifications?: boolean;
|
|
14
|
+
stateTransitionHistory?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Agent card served at `GET /.well-known/agent-card.json`.
|
|
18
|
+
* Describes the agent's identity, capabilities, and endpoint.
|
|
19
|
+
*/
|
|
20
|
+
export interface AgentCard {
|
|
21
|
+
name: string;
|
|
22
|
+
description?: string;
|
|
23
|
+
url: string;
|
|
24
|
+
version: string;
|
|
25
|
+
capabilities?: AgentCapabilities;
|
|
26
|
+
skills?: AgentSkill[];
|
|
27
|
+
defaultInputModes?: readonly string[];
|
|
28
|
+
defaultOutputModes?: readonly string[];
|
|
29
|
+
}
|
|
30
|
+
export interface TextPart {
|
|
31
|
+
type: "text";
|
|
32
|
+
text: string;
|
|
33
|
+
}
|
|
34
|
+
export interface DataPart {
|
|
35
|
+
type: "data";
|
|
36
|
+
data: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
export type Part = TextPart | DataPart;
|
|
39
|
+
export type MessageRole = "user" | "agent";
|
|
40
|
+
export interface A2AMessage {
|
|
41
|
+
messageId: string;
|
|
42
|
+
role: MessageRole;
|
|
43
|
+
parts: readonly Part[];
|
|
44
|
+
metadata?: Record<string, unknown>;
|
|
45
|
+
}
|
|
46
|
+
export interface A2ARequest {
|
|
47
|
+
jsonrpc: "2.0";
|
|
48
|
+
id: string;
|
|
49
|
+
method: "message/send";
|
|
50
|
+
params: {
|
|
51
|
+
message: A2AMessage;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export interface A2ASuccessResponse {
|
|
55
|
+
jsonrpc: "2.0";
|
|
56
|
+
id: string;
|
|
57
|
+
result: {
|
|
58
|
+
message: A2AMessage;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export interface A2AErrorResponse {
|
|
62
|
+
jsonrpc: "2.0";
|
|
63
|
+
id: string;
|
|
64
|
+
error: {
|
|
65
|
+
code: number;
|
|
66
|
+
message: string;
|
|
67
|
+
data?: unknown;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export type A2AResponse = A2ASuccessResponse | A2AErrorResponse;
|
|
71
|
+
export declare const A2A_JSONRPC_VERSION: "2.0";
|
|
72
|
+
export declare const A2A_PROTOCOL_VERSION: "1.0";
|
|
73
|
+
export declare const A2A_VERSION_HEADER: "x-a2a-protocol-version";
|
|
74
|
+
export declare const A2A_JSONRPC_PATH: "/a2a/jsonrpc";
|
|
75
|
+
export declare const A2A_AGENT_CARD_PATH: "/.well-known/agent-card.json";
|
|
76
|
+
export declare const A2A_ERROR_CODES: {
|
|
77
|
+
readonly PARSE_ERROR: -32700;
|
|
78
|
+
readonly INVALID_REQUEST: -32600;
|
|
79
|
+
readonly METHOD_NOT_FOUND: -32601;
|
|
80
|
+
readonly INVALID_PARAMS: -32602;
|
|
81
|
+
readonly INTERNAL_ERROR: -32603;
|
|
82
|
+
readonly UNAUTHORIZED: -32001;
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WA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,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,cAAc,CAAC;IACvB,MAAM,EAAE;QACN,OAAO,EAAE,UAAU,CAAC;KACrB,CAAC;CACH;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE;QACN,OAAO,EAAE,UAAU,CAAC;KACrB,CAAC;CACH;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,OAAO,CAAC;KAChB,CAAC;CACH;AAED,MAAM,MAAM,WAAW,GAAG,kBAAkB,GAAG,gBAAgB,CAAC;AAEhE,eAAO,MAAM,mBAAmB,EAAG,KAAc,CAAC;AAClD,eAAO,MAAM,oBAAoB,EAAG,KAAc,CAAC;AACnD,eAAO,MAAM,kBAAkB,EAAG,wBAAiC,CAAC;AACpE,eAAO,MAAM,gBAAgB,EAAG,cAAuB,CAAC;AACxD,eAAO,MAAM,mBAAmB,EAAG,8BAAuC,CAAC;AAE3E,eAAO,MAAM,eAAe;;;;;;;CAOlB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A2A (Agent-to-Agent) protocol types.
|
|
3
|
+
* Reference: https://google.github.io/A2A
|
|
4
|
+
*/
|
|
5
|
+
export const A2A_JSONRPC_VERSION = "2.0";
|
|
6
|
+
export const A2A_PROTOCOL_VERSION = "1.0";
|
|
7
|
+
export const A2A_VERSION_HEADER = "x-a2a-protocol-version";
|
|
8
|
+
export const A2A_JSONRPC_PATH = "/a2a/jsonrpc";
|
|
9
|
+
export const A2A_AGENT_CARD_PATH = "/.well-known/agent-card.json";
|
|
10
|
+
export const A2A_ERROR_CODES = {
|
|
11
|
+
PARSE_ERROR: -32700,
|
|
12
|
+
INVALID_REQUEST: -32600,
|
|
13
|
+
METHOD_NOT_FOUND: -32601,
|
|
14
|
+
INVALID_PARAMS: -32602,
|
|
15
|
+
INTERNAL_ERROR: -32603,
|
|
16
|
+
UNAUTHORIZED: -32001,
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAwFH,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAc,CAAC;AAClD,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAc,CAAC;AACnD,MAAM,CAAC,MAAM,kBAAkB,GAAG,wBAAiC,CAAC;AACpE,MAAM,CAAC,MAAM,gBAAgB,GAAG,cAAuB,CAAC;AACxD,MAAM,CAAC,MAAM,mBAAmB,GAAG,8BAAuC,CAAC;AAE3E,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,WAAW,EAAE,CAAC,KAAK;IACnB,eAAe,EAAE,CAAC,KAAK;IACvB,gBAAgB,EAAE,CAAC,KAAK;IACxB,cAAc,EAAE,CAAC,KAAK;IACtB,cAAc,EAAE,CAAC,KAAK;IACtB,YAAY,EAAE,CAAC,KAAK;CACZ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@keycardai/a2a",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "[Preview] Keycard auth integration for Agent-to-Agent (A2A) protocol servers and clients",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/keycardai/typescript-sdk.git",
|
|
9
|
+
"directory": "packages/a2a"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/esm/index.js",
|
|
15
|
+
"require": "./dist/cjs/index.js",
|
|
16
|
+
"types": "./dist/esm/index.d.ts"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"typesVersions": {
|
|
23
|
+
"*": {
|
|
24
|
+
"*": [
|
|
25
|
+
"./dist/esm/*"
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "pnpm run build:esm && pnpm run build:cjs",
|
|
31
|
+
"build:esm": "tsc -p tsconfig.prod.json && echo '{\"type\": \"module\"}' > dist/esm/package.json",
|
|
32
|
+
"build:cjs": "tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json",
|
|
33
|
+
"test": "NODE_OPTIONS='--experimental-vm-modules' jest",
|
|
34
|
+
"typecheck": "tsc --noEmit",
|
|
35
|
+
"clean": "rm -rf dist"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@a2a-js/sdk": "^0.3.13",
|
|
39
|
+
"@keycardai/express": "workspace:*",
|
|
40
|
+
"@keycardai/oauth": "workspace:*"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"express": ">=4.0.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@jest/globals": "^30.0.4",
|
|
47
|
+
"@types/express": "^5.0.3",
|
|
48
|
+
"@types/supertest": "^6.0.3",
|
|
49
|
+
"express": "^5.0.0",
|
|
50
|
+
"jest": "^30.0.4",
|
|
51
|
+
"supertest": "^7.1.1",
|
|
52
|
+
"ts-jest": "^29.4.0",
|
|
53
|
+
"typescript": "^5.8.3"
|
|
54
|
+
}
|
|
55
|
+
}
|