agentfootprint 9.66.0 → 9.68.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.
Files changed (36) hide show
  1. package/dist/adapters/hosting/a2aWire.js +172 -0
  2. package/dist/adapters/hosting/a2aWire.js.map +1 -0
  3. package/dist/adapters/hosting/agentCoreA2A.js +173 -0
  4. package/dist/adapters/hosting/agentCoreA2A.js.map +1 -0
  5. package/dist/adapters/mcp/agentcore.js +156 -0
  6. package/dist/adapters/mcp/agentcore.js.map +1 -0
  7. package/dist/esm/adapters/hosting/a2aWire.d.ts +110 -0
  8. package/dist/esm/adapters/hosting/a2aWire.js +166 -0
  9. package/dist/esm/adapters/hosting/a2aWire.js.map +1 -0
  10. package/dist/esm/adapters/hosting/agentCoreA2A.d.ts +95 -0
  11. package/dist/esm/adapters/hosting/agentCoreA2A.js +168 -0
  12. package/dist/esm/adapters/hosting/agentCoreA2A.js.map +1 -0
  13. package/dist/esm/adapters/mcp/agentcore.d.ts +143 -0
  14. package/dist/esm/adapters/mcp/agentcore.js +149 -0
  15. package/dist/esm/adapters/mcp/agentcore.js.map +1 -0
  16. package/dist/esm/hosting-providers.d.ts +19 -0
  17. package/dist/esm/hosting-providers.js +19 -0
  18. package/dist/esm/hosting-providers.js.map +1 -1
  19. package/dist/esm/tool-providers/index.d.ts +2 -0
  20. package/dist/esm/tool-providers/index.js +5 -0
  21. package/dist/esm/tool-providers/index.js.map +1 -1
  22. package/dist/hosting-providers.js +35 -1
  23. package/dist/hosting-providers.js.map +1 -1
  24. package/dist/tool-providers/index.js +13 -1
  25. package/dist/tool-providers/index.js.map +1 -1
  26. package/dist/types/adapters/hosting/a2aWire.d.ts +111 -0
  27. package/dist/types/adapters/hosting/a2aWire.d.ts.map +1 -0
  28. package/dist/types/adapters/hosting/agentCoreA2A.d.ts +96 -0
  29. package/dist/types/adapters/hosting/agentCoreA2A.d.ts.map +1 -0
  30. package/dist/types/adapters/mcp/agentcore.d.ts +144 -0
  31. package/dist/types/adapters/mcp/agentcore.d.ts.map +1 -0
  32. package/dist/types/hosting-providers.d.ts +19 -0
  33. package/dist/types/hosting-providers.d.ts.map +1 -1
  34. package/dist/types/tool-providers/index.d.ts +2 -0
  35. package/dist/types/tool-providers/index.d.ts.map +1 -1
  36. package/package.json +1 -1
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ /**
3
+ * adapters/hosting/a2aWire — the A2A protocol, as an `HttpWire`.
4
+ *
5
+ * ── What this is ─────────────────────────────────────────────────────────────
6
+ * **A2A** (agent-to-agent) is an open protocol for one agent calling another:
7
+ * JSON-RPC 2.0 over HTTP, a `message/send` method carrying text parts, a result
8
+ * carrying artifacts, and a discovery document — the **agent card** — that says
9
+ * what the agent is and what it can do. It is nobody's product; several
10
+ * runtimes speak it, so it lives here on its own and the runtimes that host it
11
+ * configure this rather than reimplement it.
12
+ *
13
+ * ── The subset, stated plainly ───────────────────────────────────────────────
14
+ * One method: `message/send`, text parts only. Deliberately NOT carried:
15
+ * `message/stream` and the rest of the task lifecycle (`tasks/get`,
16
+ * `tasks/cancel`, push notifications), non-text parts, and multi-turn task
17
+ * state. An agent card built here therefore declares `streaming: false` by
18
+ * default — advertising a capability this wire cannot honour is how a caller
19
+ * finds out by hanging.
20
+ *
21
+ * ── Why it fits `httpHost` without changing it ───────────────────────────────
22
+ * JSON-RPC's one hard requirement on a reply is that it ECHOES the request's
23
+ * `id`. That is possible here only because `HttpWire`'s body methods receive
24
+ * the request that produced them — a seam added for a different protocol
25
+ * entirely, and the reason this one needed no new machinery.
26
+ *
27
+ * @example A2A on paths of your own choosing
28
+ * httpHost({
29
+ * name: 'myA2AHost',
30
+ * wire: a2aWire({ card: { name: 'triage', description: '…', version: '1.0.0' } }),
31
+ * invokePath: '/',
32
+ * healthPath: '/health',
33
+ * });
34
+ */
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.a2aWire = exports.a2aAgentCardDocument = exports.readA2AMessageText = exports.JSONRPC_INTERNAL_ERROR = exports.JSONRPC_INVALID_PARAMS = exports.JSONRPC_METHOD_NOT_FOUND = exports.A2A_SEND_METHOD = exports.A2A_AGENT_CARD_PATH = exports.A2A_PROTOCOL_VERSION = void 0;
37
+ const errors_js_1 = require("../../hosting/errors.js");
38
+ /** The A2A protocol revision this wire's documents declare. */
39
+ exports.A2A_PROTOCOL_VERSION = '0.3.0';
40
+ /** Where the A2A specification puts an agent's discovery document. */
41
+ exports.A2A_AGENT_CARD_PATH = '/.well-known/agent-card.json';
42
+ /** The one method this wire carries. */
43
+ exports.A2A_SEND_METHOD = 'message/send';
44
+ /**
45
+ * JSON-RPC's own reserved codes, the two this wire can raise.
46
+ *
47
+ * `-32601` is "method not found" and `-32602` is "invalid params" — both from
48
+ * the JSON-RPC specification rather than from A2A or any runtime, which is why
49
+ * they are the only numbers this neutral file knows. A runtime's own error
50
+ * codes belong to that runtime's adapter.
51
+ */
52
+ exports.JSONRPC_METHOD_NOT_FOUND = -32601;
53
+ exports.JSONRPC_INVALID_PARAMS = -32602;
54
+ exports.JSONRPC_INTERNAL_ERROR = -32603;
55
+ function isRecord(value) {
56
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
57
+ }
58
+ /** The request's JSON-RPC id, echoed onto every reply. `null` is legal and distinct from absent. */
59
+ function requestId(facts) {
60
+ const id = facts?.body.id;
61
+ return typeof id === 'string' || typeof id === 'number' ? id : null;
62
+ }
63
+ /**
64
+ * The text of one A2A message — every part concatenated, refusing what is not text.
65
+ *
66
+ * A non-text part is refused rather than skipped for the reason every dialect
67
+ * in this library refuses rather than skips: an answer produced from the parts
68
+ * that happened to be understood is a wrong answer delivered confidently.
69
+ */
70
+ function readA2AMessageText(message) {
71
+ if (!isRecord(message)) {
72
+ throw new errors_js_1.WireRequestRefusal('invalid_params', 'params.message must be an object', 400);
73
+ }
74
+ const parts = message.parts;
75
+ if (!Array.isArray(parts) || parts.length === 0) {
76
+ throw new errors_js_1.WireRequestRefusal('invalid_params', 'params.message.parts must be a non-empty array', 400);
77
+ }
78
+ const text = [];
79
+ for (const part of parts) {
80
+ if (!isRecord(part) || part.kind !== 'text' || typeof part.text !== 'string') {
81
+ const kind = isRecord(part) && typeof part.kind === 'string' ? part.kind : 'unknown';
82
+ throw new errors_js_1.WireRequestRefusal('unsupported_part', `this agent carries text parts only; '${kind}' parts are not supported`, 400);
83
+ }
84
+ text.push(part.text);
85
+ }
86
+ return text.join('');
87
+ }
88
+ exports.readA2AMessageText = readA2AMessageText;
89
+ /**
90
+ * The agent card document, as the protocol prints it.
91
+ *
92
+ * Exported on its own because a deployment often has to serve the card from
93
+ * somewhere this wire does not own — a CDN, a route in a framework, a runtime's
94
+ * own discovery API — and the document should be built once, here, rather than
95
+ * hand-copied into each of those places.
96
+ */
97
+ function a2aAgentCardDocument(card) {
98
+ return {
99
+ name: card.name,
100
+ description: card.description,
101
+ version: card.version,
102
+ ...(card.url !== undefined && { url: card.url }),
103
+ protocolVersion: exports.A2A_PROTOCOL_VERSION,
104
+ preferredTransport: 'JSONRPC',
105
+ capabilities: { streaming: card.streaming === true },
106
+ defaultInputModes: card.defaultInputModes ?? ['text'],
107
+ defaultOutputModes: card.defaultOutputModes ?? ['text'],
108
+ skills: (card.skills ?? []).map((s) => ({
109
+ id: s.id,
110
+ name: s.name,
111
+ description: s.description,
112
+ tags: s.tags ?? [],
113
+ })),
114
+ };
115
+ }
116
+ exports.a2aAgentCardDocument = a2aAgentCardDocument;
117
+ /** An `HttpWire` speaking A2A's `message/send`. */
118
+ function a2aWire(options) {
119
+ const health = options.health ?? { status: 'ok' };
120
+ const name = options.name ?? 'a2aWire';
121
+ const codeFor = options.errorCodeFor ?? (() => exports.JSONRPC_INTERNAL_ERROR);
122
+ const envelope = (facts, body) => ({
123
+ jsonrpc: '2.0',
124
+ id: requestId(facts),
125
+ ...body,
126
+ });
127
+ return {
128
+ readRequest(facts) {
129
+ const { body } = facts;
130
+ if (body.jsonrpc !== '2.0') {
131
+ throw new errors_js_1.WireRequestRefusal('invalid_request', `${name}: every request must carry "jsonrpc": "2.0"`, 400);
132
+ }
133
+ if (body.method !== exports.A2A_SEND_METHOD) {
134
+ // Named rather than ignored: a caller using a method this agent does
135
+ // not implement learns which one it does, instead of receiving an
136
+ // empty answer to a question that was never asked.
137
+ throw new errors_js_1.WireRequestRefusal('method_not_found', `${name}: only '${exports.A2A_SEND_METHOD}' is implemented; received '${String(body.method)}'`, 404);
138
+ }
139
+ const params = isRecord(body.params) ? body.params : undefined;
140
+ const input = readA2AMessageText(params?.message);
141
+ if (input.trim() === '') {
142
+ throw new errors_js_1.WireRequestRefusal('invalid_params', `${name}: message text must not be empty`, 400);
143
+ }
144
+ // A2A carries no session of its own — the transport hosting it does, and
145
+ // the runtime adapter reads it from wherever that transport puts it.
146
+ return { input };
147
+ },
148
+ health: () => health,
149
+ output: (output, facts) => envelope(facts, {
150
+ result: {
151
+ artifacts: [
152
+ {
153
+ artifactId: String(facts?.body.id ?? 'artifact'),
154
+ name: 'agent_response',
155
+ parts: [{ kind: 'text', text: output }],
156
+ },
157
+ ],
158
+ },
159
+ }),
160
+ chunk: (text) => ({ kind: 'text', text }),
161
+ failure: (message, code, facts, origin) => envelope(facts, {
162
+ error: {
163
+ code: codeFor(code),
164
+ // A thrown exception's words are the author's note to their own logs.
165
+ // A refusal this library authored was written to be read.
166
+ message: origin === 'threw' ? 'The agent could not complete this request.' : message,
167
+ },
168
+ }),
169
+ };
170
+ }
171
+ exports.a2aWire = a2aWire;
172
+ //# sourceMappingURL=a2aWire.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"a2aWire.js","sourceRoot":"","sources":["../../../src/adapters/hosting/a2aWire.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;;;AAEH,uDAA6D;AAG7D,+DAA+D;AAClD,QAAA,oBAAoB,GAAG,OAAO,CAAC;AAE5C,sEAAsE;AACzD,QAAA,mBAAmB,GAAG,8BAA8B,CAAC;AAElE,wC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AC;YAClD,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;gBACxB,MAAM,IAAI,8BAAkB,CAC1B,gBAAgB,EAChB,GAAG,IAAI,kCAAkC,EACzC,GAAG,CACJ,CAAC;YACJ,CAAC;YACD,yEAAyE;YACzE,qEAAqE;YACrE,OAAO,EAAE,KAAK,EAAE,CAAC;QACnB,CAAC;QAED,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM;QAEpB,MAAM,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CACxB,QAAQ,CAAC,KAAK,EAAE;YACd,MAAM,EAAE;gBACN,SAAS,EAAE;oBACT;wBACE,UAAU,EAAE,MAAM,CAAE,KAAK,EAAE,IAAI,CAAC,EAAyB,IAAI,UAAU,CAAC;wBACxE,IAAI,EAAE,gBAAgB;wBACtB,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;qBACxC;iBACF;aACF;SACF,CAAC;QAEJ,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QAEzC,OAAO,EAAE,CAAC,OAAe,EAAE,IAAa,EAAE,KAAwB,EAAE,MAAsB,EAAE,EAAE,CAC5F,QAAQ,CAAC,KAAK,EAAE;YACd,KAAK,EAAE;gBACL,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC;gBACnB,sEAAsE;gBACtE,0DAA0D;gBAC1D,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,4CAA4C,CAAC,CAAC,CAAC,OAAO;aACrF;SACF,CAAC;KACL,CAAC;AACJ,CAAC;AAxED,0BAwEC"}
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ /**
3
+ * adapters/hosting/agentCoreA2A — an agentfootprint agent as an AWS Bedrock
4
+ * **AgentCore A2A** server, callable by other agents.
5
+ *
6
+ * ── The split, again ─────────────────────────────────────────────────────────
7
+ * Two different things are needed, and only one is Amazon's:
8
+ *
9
+ * • The **A2A protocol** — JSON-RPC 2.0, `message/send`, artifacts, the agent
10
+ * card. An open protocol several runtimes speak, so it lives in
11
+ * `a2aWire.ts` with no vendor in it.
12
+ * • The **container contract** — port 9000 (not 8080, and not 8000: each
13
+ * protocol gets its own), the agent mounted at `/`, `GET /ping` answering
14
+ * `{"status":"Healthy"}`, the session id arriving in
15
+ * `X-Amzn-Bedrock-AgentCore-Runtime-Session-Id`, and a table of JSON-RPC
16
+ * error codes that are this runtime's exceptions rather than A2A's. That
17
+ * IS Amazon's, and it is what this file supplies.
18
+ *
19
+ * ── One deviation you must know about ────────────────────────────────────────
20
+ * The A2A specification delivers JSON-RPC errors over HTTP 200. **AgentCore
21
+ * does not** — it returns the real status code (409, 404, …) with the JSON-RPC
22
+ * error body. That is a fact about the platform in front of your container, so
23
+ * a CLIENT must parse the error body even on a non-2xx response; see
24
+ * `agentCoreA2AErrorCode` for the table this host mirrors on the way out.
25
+ *
26
+ * ── What is NOT provided ─────────────────────────────────────────────────────
27
+ * `message/stream` and the task lifecycle. The agent card this host serves
28
+ * therefore declares `streaming: false` unless you overrule it, because a card
29
+ * that advertises streaming to a wire that cannot stream is a caller left
30
+ * waiting. AWS's own sample card says `true`; ours says what is true of ours.
31
+ *
32
+ * @example An agent other agents can call
33
+ * import { agentCoreA2AHost, memorySessions, standingAgent } from 'agentfootprint/hosting';
34
+ *
35
+ * const handle = await standingAgent({
36
+ * agent,
37
+ * sessions: memorySessions(),
38
+ * host: agentCoreA2AHost({
39
+ * card: { name: 'triage', description: 'Triages SAN alerts.', version: '1.0.0' },
40
+ * }),
41
+ * });
42
+ * process.on('SIGTERM', () => void handle.close());
43
+ */
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.agentCoreA2AHost = exports.agentCoreA2AErrorCode = exports.AGENTCORE_SESSION_HEADER = exports.AGENTCORE_PING_PATH = exports.AGENTCORE_A2A_INVOKE_PATH = exports.DEFAULT_AGENTCORE_A2A_PORT = void 0;
46
+ const httpHost_js_1 = require("../../hosting/httpHost.js");
47
+ const a2aWire_js_1 = require("./a2aWire.js");
48
+ /** The port an AgentCore A2A server is expected on — its own, not HTTP's or MCP's. */
49
+ exports.DEFAULT_AGENTCORE_A2A_PORT = 9000;
50
+ /** A2A mounts the agent at the root. */
51
+ exports.AGENTCORE_A2A_INVOKE_PATH = '/';
52
+ /** The runtime's health path for every protocol. */
53
+ exports.AGENTCORE_PING_PATH = '/ping';
54
+ /** Where the platform puts the caller's session. */
55
+ exports.AGENTCORE_SESSION_HEADER = 'X-Amzn-Bedrock-AgentCore-Runtime-Session-Id';
56
+ /**
57
+ * AgentCore's own JSON-RPC error codes, mapped from this library's refusal codes.
58
+ *
59
+ * These numbers are the RUNTIME's exception table, not A2A's: `-32051`
60
+ * ResourceNotFound, `-32052` Validation, `-32053` Throttling and
61
+ * ServiceQuotaExceeded, `-32054` Conflict and RetryableConflict, `-32055`
62
+ * RuntimeClientError, `-32603` anything else. A client reads them to decide
63
+ * whether to retry — `-32054` with "Session operation in progress" is the one
64
+ * that must be retried with backoff, and A2A clients do not do that on their
65
+ * own.
66
+ *
67
+ * Exported so a client built against this host can share one table with it
68
+ * rather than keep a second copy that drifts.
69
+ */
70
+ function agentCoreA2AErrorCode(code) {
71
+ switch (code) {
72
+ case 'ERR_SESSION_NOT_FOUND':
73
+ case 'ERR_ARTIFACT_NOT_FOUND':
74
+ return -32051;
75
+ case 'ERR_INVALID_WIRE_OP':
76
+ case 'ERR_DECISION_REQUIRED':
77
+ case 'ERR_ARTIFACT_SESSION_REQUIRED':
78
+ case 'invalid_request':
79
+ case 'invalid_params':
80
+ case 'unsupported_part':
81
+ return -32052;
82
+ case 'ERR_ADMISSION_REFUSED':
83
+ case 'ERR_REQUEST_TOO_LARGE':
84
+ return -32053;
85
+ case 'ERR_CONCURRENT_RUN':
86
+ case 'ERR_HOST_CLOSED':
87
+ case 'ERR_AWAITING_DECISION':
88
+ case 'ERR_PAUSE_NOT_CARRIED':
89
+ return -32054;
90
+ case 'method_not_found':
91
+ // JSON-RPC's own "method not found" is -32601, but this runtime reports a
92
+ // route it cannot resolve as ResourceNotFound. The platform's table wins
93
+ // inside the platform's container.
94
+ return -32051;
95
+ default:
96
+ return -32603;
97
+ }
98
+ }
99
+ exports.agentCoreA2AErrorCode = agentCoreA2AErrorCode;
100
+ const DEFAULT_MAX_BODY_BYTES = 1_048_576;
101
+ /**
102
+ * An {@link HttpHost} serving AgentCore's A2A container contract.
103
+ *
104
+ * `httpHost` keeps its own promises — draining, aborting on disconnect, failing
105
+ * a handler that throws or answers nothing — and this supplies the protocol,
106
+ * the paths, the port, the session header and the error table.
107
+ */
108
+ function agentCoreA2AHost(options) {
109
+ const { server, onUnhandled, hostname, card } = options;
110
+ const cardDocument = JSON.stringify((0, a2aWire_js_1.a2aAgentCardDocument)(card));
111
+ /** The discovery document, served before anything falls through to the caller. */
112
+ const serveCard = (req, res) => {
113
+ const path = (req.url ?? '').split('?')[0];
114
+ if (req.method === 'GET' && path === a2aWire_js_1.A2A_AGENT_CARD_PATH) {
115
+ res.writeHead(200, {
116
+ 'content-type': 'application/json',
117
+ 'content-length': Buffer.byteLength(cardDocument),
118
+ });
119
+ res.end(cardDocument);
120
+ return;
121
+ }
122
+ // Not the card: the caller's own routes, if they have any. Chaining rather
123
+ // than consuming the slot — an adapter that took `onUnhandled` for itself
124
+ // would silently remove a seam the host documents as the consumer's.
125
+ if (onUnhandled) {
126
+ onUnhandled(req, res);
127
+ return;
128
+ }
129
+ res.writeHead(404, { 'content-type': 'application/json' });
130
+ res.end(JSON.stringify({ error: `no route for ${req.method ?? '?'} ${path}` }));
131
+ };
132
+ const socket = server
133
+ ? { server }
134
+ : {
135
+ port: options.port ?? exports.DEFAULT_AGENTCORE_A2A_PORT,
136
+ ...(hostname === undefined ? {} : { hostname }),
137
+ onUnhandled: serveCard,
138
+ };
139
+ const protocol = (0, a2aWire_js_1.a2aWire)({
140
+ card,
141
+ // The runtime's health contract, not A2A's — A2A has no /ping at all.
142
+ health: { status: 'Healthy' },
143
+ errorCodeFor: agentCoreA2AErrorCode,
144
+ name: 'agentCoreA2AHost',
145
+ });
146
+ return (0, httpHost_js_1.httpHost)({
147
+ name: 'agentCoreA2AHost',
148
+ wire: {
149
+ ...protocol,
150
+ // The one thing the protocol does not carry and the platform does: which
151
+ // conversation this call belongs to, in a header of the runtime's own.
152
+ readRequest(facts) {
153
+ const base = protocol.readRequest(facts);
154
+ const sessionId = (0, httpHost_js_1.headerValue)(facts, exports.AGENTCORE_SESSION_HEADER);
155
+ return { ...base, ...(sessionId !== undefined && { sessionId }) };
156
+ },
157
+ },
158
+ invokePath: exports.AGENTCORE_A2A_INVOKE_PATH,
159
+ healthPath: exports.AGENTCORE_PING_PATH,
160
+ // NOT `['streaming']`, which is this file's default. `message/send` has
161
+ // nowhere to put a chunk: a caller gets one JSON-RPC reply and nothing
162
+ // before it. Declaring streaming anyway would make `requireCapability`
163
+ // pass for a host that cannot honour it, and would contradict the agent
164
+ // card, which says `streaming: false` for the same reason. The host
165
+ // conformance suite catches exactly this — it asserts chunks IF AND ONLY IF
166
+ // the capability is declared, and it caught it here.
167
+ capabilities: [],
168
+ maxBodyBytes: options.maxBodyBytes ?? DEFAULT_MAX_BODY_BYTES,
169
+ ...socket,
170
+ });
171
+ }
172
+ exports.agentCoreA2AHost = agentCoreA2AHost;
173
+ //# sourceMappingURL=agentCoreA2A.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agentCoreA2A.js","sourceRoot":"","sources":["../../../src/adapters/hosting/agentCoreA2A.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;;;AAIH,2DAAiF;AACjF,6CAKsB;AAEtB,sFAAsF;AACzE,QAAA,0BAA0B,GAAG,IAAI,CAAC;AAE/C,wCAAwC;AAC3B,QAAA,yBAAyB,GAAG,GAAG,CAAC;A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AkB;KACzB,CAAC,CAAC;IAEH,OAAO,IAAA,sBAAQ,EAAC;QACd,IAAI,EAAE,kBAAkB;QACxB,IAAI,EAAE;YACJ,GAAG,QAAQ;YACX,yEAAyE;YACzE,uEAAuE;YACvE,WAAW,CAAC,KAAK;gBACf,MAAM,IAAI,GAAG,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;gBACzC,MAAM,SAAS,GAAG,IAAA,yBAAW,EAAC,KAAK,EAAE,gCAAwB,CAAC,CAAC;gBAC/D,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,CAAC,SAAS,KAAK,SAAS,IAAI,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;YACpE,CAAC;SACF;QACD,UAAU,EAAE,iCAAyB;QACrC,UAAU,EAAE,2BAAmB;QAC/B,wEAAwE;QACxE,uEAAuE;QACvE,uEAAuE;QACvE,wEAAwE;QACxE,oEAAoE;QACpE,4EAA4E;QAC5E,qDAAqD;QACrD,YAAY,EAAE,EAAE;QAChB,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,sBAAsB;QAC5D,GAAG,MAAM;KACV,CAAC,CAAC;AACL,CAAC;AAnED,4CAmEC"}
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ /**
3
+ * adapters/mcp/agentcore — reaching an AWS Bedrock **AgentCore Gateway**.
4
+ *
5
+ * ── What lives here, and why it is one file ──────────────────────────────────
6
+ * A Gateway is an MCP server, and `mcpClient` + `gatewayTransport` already know
7
+ * how to talk to one of those. Neither knows — and neither should learn — the
8
+ * handful of facts that are AgentCore's alone: the hostname its endpoints take,
9
+ * the name of the tool that searches its catalogue, the header that groups a
10
+ * caller's requests into one policy session, and the service name a SigV4
11
+ * signature is computed against. Those four facts are this file, and this file
12
+ * is the only place in the library that holds them.
13
+ *
14
+ * `gatewayTransport` says of itself: *"Nothing here is vendor-specific."* That
15
+ * stays true precisely because this exists next to it.
16
+ *
17
+ * ── What it does NOT do ──────────────────────────────────────────────────────
18
+ * It does not manage a Gateway. Creating one, adding targets, attaching a
19
+ * policy engine, enabling semantic search — all control-plane operations on
20
+ * `bedrock-agentcore-control`, all things an operator does once with the
21
+ * console, the CLI or their IaC. This is the CLIENT side: an agent using a
22
+ * gateway somebody already stood up.
23
+ *
24
+ * @example An agent whose tools come from a Gateway
25
+ * import { mcpClient } from 'agentfootprint/providers';
26
+ * import { agentCoreGatewayTransport } from 'agentfootprint/providers';
27
+ * import { agentCoreIdentity } from 'agentfootprint/security';
28
+ *
29
+ * const gateway = await mcpClient({
30
+ * name: 'gateway',
31
+ * transport: agentCoreGatewayTransport({
32
+ * gatewayId: 'my-gateway-a1b2c3d4e5',
33
+ * region: 'us-east-1',
34
+ * credentials: agentCoreIdentity({ region: 'us-east-1' }),
35
+ * }),
36
+ * });
37
+ * const tools = await gateway.tools();
38
+ */
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.hasGatewaySearch = exports.gatewaySearchTool = exports.agentCoreGatewayTransport = exports.agentCoreGatewayUrl = exports.AGENTCORE_SIGV4_SERVICE = exports.AGENTCORE_POLICY_SESSION_HEADER = exports.AGENTCORE_GATEWAY_SEARCH_TOOL = void 0;
41
+ const gatewayTransport_js_1 = require("../../lib/mcp/gatewayTransport.js");
42
+ /**
43
+ * The Gateway's built-in semantic tool search, by its exact wire name.
44
+ *
45
+ * It is an ordinary MCP tool — `tools/call` with `{ query }` — that returns the
46
+ * catalogue entries closest to a natural-language description. It matters at
47
+ * the scale where listing every tool into a prompt stops being sensible.
48
+ *
49
+ * **It can only be enabled when the Gateway is CREATED**, never afterwards, so
50
+ * its absence from a catalogue is a fact about that gateway rather than a
51
+ * transient condition to retry.
52
+ */
53
+ exports.AGENTCORE_GATEWAY_SEARCH_TOOL = 'x_amz_bedrock_agentcore_search';
54
+ /**
55
+ * The header that groups a caller's requests into ONE policy session.
56
+ *
57
+ * AgentCore's temporal policies decide on SEQUENCES of actions — "not after
58
+ * three refunds", "only once this was approved" — and a sequence needs a
59
+ * boundary. This header is that boundary, and without it every request is its
60
+ * own history of one, which quietly makes every sequence rule unenforceable.
61
+ */
62
+ exports.AGENTCORE_POLICY_SESSION_HEADER = 'x-amzn-bedrock-agentcore-policy-session-id';
63
+ /** The service name a SigV4 signature for a Gateway is computed against. */
64
+ exports.AGENTCORE_SIGV4_SERVICE = 'bedrock-agentcore';
65
+ /**
66
+ * The MCP endpoint of a Gateway.
67
+ *
68
+ * `https://{gatewayId}.gateway.bedrock-agentcore.{region}.amazonaws.com/mcp` —
69
+ * a shape nobody remembers correctly, which is the entire reason it is a
70
+ * function and not a line in a README.
71
+ */
72
+ function agentCoreGatewayUrl(options) {
73
+ const { gatewayId, region } = options;
74
+ if (!gatewayId || !region) {
75
+ throw new TypeError('agentCoreGatewayUrl: both `gatewayId` and `region` are required — the endpoint hostname ' +
76
+ 'is built from the two.');
77
+ }
78
+ return `https://${gatewayId}.gateway.bedrock-agentcore.${region}.amazonaws.com/mcp`;
79
+ }
80
+ exports.agentCoreGatewayUrl = agentCoreGatewayUrl;
81
+ /**
82
+ * An MCP transport pointed at an AgentCore Gateway.
83
+ *
84
+ * A configuration of {@link gatewayTransport}: the endpoint built from your
85
+ * gateway's id and region, and — when you name one — the policy session header
86
+ * stamped on every request. Token vending, the once-and-dropped secrecy rule
87
+ * and the rotation behaviour are all the neutral transport's, unchanged.
88
+ */
89
+ function agentCoreGatewayTransport(options) {
90
+ const { policySessionId, fetch: innerFetch } = options;
91
+ // The header is stamped in the `fetch` seam rather than in `headers` because
92
+ // the seam runs per request. That is what lets the session id come from a
93
+ // function, which is what keeps two people on one transport in two sessions.
94
+ const stampPolicySession = policySessionId === undefined
95
+ ? innerFetch
96
+ : async (input, init) => {
97
+ const id = typeof policySessionId === 'function' ? policySessionId() : policySessionId;
98
+ const next = id === undefined || id === ''
99
+ ? init
100
+ : {
101
+ ...init,
102
+ headers: {
103
+ ...init?.headers,
104
+ [exports.AGENTCORE_POLICY_SESSION_HEADER]: id,
105
+ },
106
+ };
107
+ return innerFetch ? innerFetch(input, next) : globalThis.fetch(input, next);
108
+ };
109
+ return (0, gatewayTransport_js_1.gatewayTransport)({
110
+ url: agentCoreGatewayUrl(options),
111
+ credentials: options.credentials,
112
+ ...(options.service !== undefined && { service: options.service }),
113
+ ...(options.scopes !== undefined && { scopes: options.scopes }),
114
+ ...(options.mode !== undefined && { mode: options.mode }),
115
+ ...(options.headers !== undefined && { headers: options.headers }),
116
+ ...(stampPolicySession !== undefined && { fetch: stampPolicySession }),
117
+ });
118
+ }
119
+ exports.agentCoreGatewayTransport = agentCoreGatewayTransport;
120
+ /**
121
+ * The Gateway's semantic search tool, if this gateway has one.
122
+ *
123
+ * Returns `undefined` rather than throwing, because absence is a legitimate and
124
+ * PERMANENT answer: semantic search is enabled when a Gateway is created and
125
+ * cannot be turned on afterwards, so there is nothing to retry.
126
+ *
127
+ * ── Why this finds the tool instead of calling it ────────────────────────────
128
+ * The obvious convenience would be `search(gateway, 'refund an order')`, and it
129
+ * is deliberately not here. Executing a tool needs a `ToolExecutionContext` —
130
+ * the call id, the iteration, the credential seam, the artifact store — and
131
+ * that object belongs to the agent loop. A helper would have to invent one,
132
+ * and a call made on an invented context is a call that appears in no trace:
133
+ * the model would be handed a shortlist nobody can later explain the origin of,
134
+ * which is the opposite of what this library is for.
135
+ *
136
+ * So the search tool is registered like any other tool, the model calls it when
137
+ * the catalogue is too large to reason about, and that call is an ordinary
138
+ * tool call in the trace — visible, attributable, and replayable.
139
+ *
140
+ * @example Give the model the catalogue's own search
141
+ * const tools = await gateway.tools();
142
+ * const search = gatewaySearchTool(tools);
143
+ * Agent.create({ provider, model })
144
+ * .tools(search ? [search] : tools) // search it, or list it
145
+ * .build();
146
+ */
147
+ function gatewaySearchTool(tools) {
148
+ return tools.find((t) => t.schema.name === exports.AGENTCORE_GATEWAY_SEARCH_TOOL);
149
+ }
150
+ exports.gatewaySearchTool = gatewaySearchTool;
151
+ /** Whether this gateway's catalogue can be searched rather than listed. */
152
+ function hasGatewaySearch(tools) {
153
+ return gatewaySearchTool(tools) !== undefined;
154
+ }
155
+ exports.hasGatewaySearch = hasGatewaySearch;
156
+ //# sourceMappingURL=agentcore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agentcore.js","sourceRoot":"","sources":["../../../src/adapters/mcp/agentcore.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;;;AAEH,2EAAqF;AAKrF;;;;;;;;;;GAUG;AACU,QAAA,6BAA6B,GAAG,gCAAgC,CAAC;AAE9E;;;;;;;GAOG;AACU,QAAA,+BAA+B,GAAG,4CAA4C,CAAC;AAE5F,4EAA4E;AAC/D,QAAA,uBAAuB,GAAG,mBAAmB,CAAC;AAS3D;;;;;;GAMG;AACH,SAAgB,mBAAmB,CAAC,OAAmC;IACrE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IACtC,IAAI,CAAC,SAAS,IAAI,CAAC,MAAM,EAAE,CAAC;QAC1B,MAAM,IAAI,SAAS,CACjB,0FAA0F;YACxF,wBAAwB,CAC3B,CAAC;IACJ,CAAC;IACD,OAAO,WAAW,SAAS,8BAA8B,MAAM,oBAAoB,CAAC;AACtF,CAAC;AATD,kDASC;AA6BD;;;;;;;GAOG;AACH,SAAgB,yBAAyB,CACvC,OAAyC;IAEzC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAEvD,6EAA6E;IAC7E,0EAA0E;IAC1E,6EAA6E;IAC7E,MAAM,kBAAkB,GACtB,eAAe,KAAK,SAAS;QAC3B,CAAC,CAAC,UAAU;QACZ,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YACpB,MAAM,EAAE,GAAG,OAAO,eAAe,KAAK,UAAU,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC;YACvF,MAAM,IAAI,GACR,EAAE,KAAK,SAAS,I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AAED,2EAA2E;AAC3E,SAAgB,gBAAgB,CAAC,KAAsB;IACrD,OAAO,iBAAiB,CAAC,KAAK,CAAC,KAAK,SAAS,CAAC;AAChD,CAAC;AAFD,4CAEC"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * adapters/hosting/a2aWire — the A2A protocol, as an `HttpWire`.
3
+ *
4
+ * ── What this is ─────────────────────────────────────────────────────────────
5
+ * **A2A** (agent-to-agent) is an open protocol for one agent calling another:
6
+ * JSON-RPC 2.0 over HTTP, a `message/send` method carrying text parts, a result
7
+ * carrying artifacts, and a discovery document — the **agent card** — that says
8
+ * what the agent is and what it can do. It is nobody's product; several
9
+ * runtimes speak it, so it lives here on its own and the runtimes that host it
10
+ * configure this rather than reimplement it.
11
+ *
12
+ * ── The subset, stated plainly ───────────────────────────────────────────────
13
+ * One method: `message/send`, text parts only. Deliberately NOT carried:
14
+ * `message/stream` and the rest of the task lifecycle (`tasks/get`,
15
+ * `tasks/cancel`, push notifications), non-text parts, and multi-turn task
16
+ * state. An agent card built here therefore declares `streaming: false` by
17
+ * default — advertising a capability this wire cannot honour is how a caller
18
+ * finds out by hanging.
19
+ *
20
+ * ── Why it fits `httpHost` without changing it ───────────────────────────────
21
+ * JSON-RPC's one hard requirement on a reply is that it ECHOES the request's
22
+ * `id`. That is possible here only because `HttpWire`'s body methods receive
23
+ * the request that produced them — a seam added for a different protocol
24
+ * entirely, and the reason this one needed no new machinery.
25
+ *
26
+ * @example A2A on paths of your own choosing
27
+ * httpHost({
28
+ * name: 'myA2AHost',
29
+ * wire: a2aWire({ card: { name: 'triage', description: '…', version: '1.0.0' } }),
30
+ * invokePath: '/',
31
+ * healthPath: '/health',
32
+ * });
33
+ */
34
+ import type { HttpWire } from '../../hosting/httpHost.js';
35
+ /** The A2A protocol revision this wire's documents declare. */
36
+ export declare const A2A_PROTOCOL_VERSION = "0.3.0";
37
+ /** Where the A2A specification puts an agent's discovery document. */
38
+ export declare const A2A_AGENT_CARD_PATH = "/.well-known/agent-card.json";
39
+ /** The one method this wire carries. */
40
+ export declare const A2A_SEND_METHOD = "message/send";
41
+ /**
42
+ * JSON-RPC's own reserved codes, the two this wire can raise.
43
+ *
44
+ * `-32601` is "method not found" and `-32602` is "invalid params" — both from
45
+ * the JSON-RPC specification rather than from A2A or any runtime, which is why
46
+ * they are the only numbers this neutral file knows. A runtime's own error
47
+ * codes belong to that runtime's adapter.
48
+ */
49
+ export declare const JSONRPC_METHOD_NOT_FOUND = -32601;
50
+ export declare const JSONRPC_INVALID_PARAMS = -32602;
51
+ export declare const JSONRPC_INTERNAL_ERROR = -32603;
52
+ /** One skill an agent card advertises. */
53
+ export interface A2ASkill {
54
+ readonly id: string;
55
+ readonly name: string;
56
+ readonly description: string;
57
+ readonly tags?: readonly string[];
58
+ }
59
+ /** The agent card this wire serves — what another agent reads to decide to call yours. */
60
+ export interface A2AAgentCard {
61
+ readonly name: string;
62
+ readonly description: string;
63
+ readonly version: string;
64
+ /** Where callers reach this agent. A runtime that mounts the agent behind its
65
+ * own URL fills this in; left out, the card simply omits it. */
66
+ readonly url?: string;
67
+ /** Default `false` — see the module note on why this wire does not claim it. */
68
+ readonly streaming?: boolean;
69
+ readonly defaultInputModes?: readonly string[];
70
+ readonly defaultOutputModes?: readonly string[];
71
+ readonly skills?: readonly A2ASkill[];
72
+ }
73
+ export interface A2AWireOptions {
74
+ /** The agent card. Required: A2A discovery is not optional in the protocol. */
75
+ readonly card: A2AAgentCard;
76
+ /** Body for the health probe. Default `{ status: 'ok' }`. */
77
+ readonly health?: unknown;
78
+ /**
79
+ * Map a refusal's stable code onto the numeric JSON-RPC code this deployment
80
+ * reports. Absent, everything that is not a malformed request is
81
+ * `-32603` (internal error) — the JSON-RPC catch-all.
82
+ *
83
+ * A runtime with its own published code table passes one; that table is the
84
+ * runtime's, and this file does not carry anybody's.
85
+ */
86
+ readonly errorCodeFor?: (code: string | undefined) => number;
87
+ /** Name used in refusal messages. Default `'a2aWire'`. */
88
+ readonly name?: string;
89
+ }
90
+ type JsonObject = Readonly<Record<string, unknown>>;
91
+ /**
92
+ * The text of one A2A message — every part concatenated, refusing what is not text.
93
+ *
94
+ * A non-text part is refused rather than skipped for the reason every dialect
95
+ * in this library refuses rather than skips: an answer produced from the parts
96
+ * that happened to be understood is a wrong answer delivered confidently.
97
+ */
98
+ export declare function readA2AMessageText(message: unknown): string;
99
+ /**
100
+ * The agent card document, as the protocol prints it.
101
+ *
102
+ * Exported on its own because a deployment often has to serve the card from
103
+ * somewhere this wire does not own — a CDN, a route in a framework, a runtime's
104
+ * own discovery API — and the document should be built once, here, rather than
105
+ * hand-copied into each of those places.
106
+ */
107
+ export declare function a2aAgentCardDocument(card: A2AAgentCard): JsonObject;
108
+ /** An `HttpWire` speaking A2A's `message/send`. */
109
+ export declare function a2aWire(options: A2AWireOptions): HttpWire;
110
+ export {};