@a2a-wrapper/core 1.2.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 +186 -0
- package/dist/cli/scaffold.d.ts +237 -0
- package/dist/cli/scaffold.d.ts.map +1 -0
- package/dist/cli/scaffold.js +241 -0
- package/dist/cli/scaffold.js.map +1 -0
- package/dist/config/loader.d.ts +100 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +130 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/types.d.ts +317 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +17 -0
- package/dist/config/types.js.map +1 -0
- package/dist/events/event-publisher.d.ts +205 -0
- package/dist/events/event-publisher.d.ts.map +1 -0
- package/dist/events/event-publisher.js +317 -0
- package/dist/events/event-publisher.js.map +1 -0
- package/dist/executor/types.d.ts +164 -0
- package/dist/executor/types.d.ts.map +1 -0
- package/dist/executor/types.js +30 -0
- package/dist/executor/types.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/server/agent-card.d.ts +66 -0
- package/dist/server/agent-card.d.ts.map +1 -0
- package/dist/server/agent-card.js +114 -0
- package/dist/server/agent-card.js.map +1 -0
- package/dist/server/factory.d.ts +159 -0
- package/dist/server/factory.d.ts.map +1 -0
- package/dist/server/factory.js +167 -0
- package/dist/server/factory.js.map +1 -0
- package/dist/session/base-session-manager.d.ts +218 -0
- package/dist/session/base-session-manager.d.ts.map +1 -0
- package/dist/session/base-session-manager.js +222 -0
- package/dist/session/base-session-manager.js.map +1 -0
- package/dist/utils/deep-merge.d.ts +83 -0
- package/dist/utils/deep-merge.d.ts.map +1 -0
- package/dist/utils/deep-merge.js +108 -0
- package/dist/utils/deep-merge.js.map +1 -0
- package/dist/utils/deferred.d.ts +97 -0
- package/dist/utils/deferred.d.ts.map +1 -0
- package/dist/utils/deferred.js +83 -0
- package/dist/utils/deferred.js.map +1 -0
- package/dist/utils/logger.d.ts +186 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +244 -0
- package/dist/utils/logger.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module executor/types
|
|
3
|
+
*
|
|
4
|
+
* Defines the {@link A2AExecutor} interface — the contract that every wrapper
|
|
5
|
+
* project's executor must satisfy in order to plug into the shared A2A server
|
|
6
|
+
* infrastructure provided by `@a2a-wrapper/core`.
|
|
7
|
+
*
|
|
8
|
+
* The interface is structurally compatible with the `AgentExecutor` type
|
|
9
|
+
* exported by `@a2a-js/sdk/server`, so implementations can be passed directly
|
|
10
|
+
* to `DefaultRequestHandler` without an adapter layer. It extends the SDK
|
|
11
|
+
* contract with lifecycle hooks (`initialize`, `shutdown`) and optional
|
|
12
|
+
* context-file operations (`getContextContent`, `buildContext`) that are
|
|
13
|
+
* common across all current wrapper projects.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import type { A2AExecutor } from "@a2a-wrapper/core";
|
|
18
|
+
*
|
|
19
|
+
* class MyExecutor implements A2AExecutor {
|
|
20
|
+
* async initialize() { // connect to backend }
|
|
21
|
+
* async shutdown() { // release resources }
|
|
22
|
+
* async execute(ctx, bus) { // handle A2A task }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @see {@link https://github.com/a2a-js/a2a-js | @a2a-js/sdk} for the
|
|
27
|
+
* upstream `AgentExecutor` and `RequestContext` definitions.
|
|
28
|
+
*/
|
|
29
|
+
import type { RequestContext, ExecutionEventBus } from "@a2a-js/sdk/server";
|
|
30
|
+
/**
|
|
31
|
+
* Contract that every wrapper project's executor must satisfy.
|
|
32
|
+
*
|
|
33
|
+
* `A2AExecutor` is the single integration point between the shared server
|
|
34
|
+
* infrastructure (`createA2AServer`, `createCli`) and the backend-specific
|
|
35
|
+
* logic each wrapper project provides. Implementations are responsible for:
|
|
36
|
+
*
|
|
37
|
+
* 1. **Lifecycle** — allocating and releasing backend resources via
|
|
38
|
+
* {@link initialize} and {@link shutdown}.
|
|
39
|
+
* 2. **Task execution** — translating an inbound A2A request into backend
|
|
40
|
+
* calls and publishing progress / artifact events via {@link execute}.
|
|
41
|
+
* 3. **Cancellation** *(optional)* — aborting a running task when the client
|
|
42
|
+
* sends a cancel request via {@link cancelTask}.
|
|
43
|
+
* 4. **Context management** *(optional)* — reading or building a domain
|
|
44
|
+
* context file that enriches the backend's system prompt via
|
|
45
|
+
* {@link getContextContent} and {@link buildContext}.
|
|
46
|
+
*
|
|
47
|
+
* The `execute` and `cancelTask` signatures are intentionally identical to
|
|
48
|
+
* those on `AgentExecutor` from `@a2a-js/sdk/server`, ensuring that any
|
|
49
|
+
* `A2AExecutor` instance (with `cancelTask` implemented) is structurally
|
|
50
|
+
* assignable to the SDK type and can be passed directly to
|
|
51
|
+
* `DefaultRequestHandler`.
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* CMMI Level 5 — This interface is the primary extension point for new
|
|
55
|
+
* wrapper projects. Adding a new backend requires only implementing this
|
|
56
|
+
* interface; no changes to `@a2a-wrapper/core` are necessary.
|
|
57
|
+
*/
|
|
58
|
+
export interface A2AExecutor {
|
|
59
|
+
/**
|
|
60
|
+
* Perform asynchronous startup logic.
|
|
61
|
+
*
|
|
62
|
+
* Called once by the server factory after the executor is constructed and
|
|
63
|
+
* before the HTTP server begins accepting requests. Typical work includes
|
|
64
|
+
* establishing backend connections, running health checks, registering MCP
|
|
65
|
+
* servers, and pre-loading configuration or context files.
|
|
66
|
+
*
|
|
67
|
+
* @returns A promise that resolves when the executor is fully ready to
|
|
68
|
+
* handle requests. The server will not start listening until this
|
|
69
|
+
* promise settles.
|
|
70
|
+
*
|
|
71
|
+
* @throws If initialization fails, the promise should reject with a
|
|
72
|
+
* descriptive error. The server factory will propagate the error and
|
|
73
|
+
* prevent the server from starting.
|
|
74
|
+
*/
|
|
75
|
+
initialize(): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Release all resources held by the executor.
|
|
78
|
+
*
|
|
79
|
+
* Called once during graceful shutdown (SIGINT / SIGTERM) after the HTTP
|
|
80
|
+
* server has stopped accepting new connections. Implementations should
|
|
81
|
+
* close backend connections, cancel in-flight requests, stop timers, and
|
|
82
|
+
* perform any other cleanup necessary to avoid resource leaks.
|
|
83
|
+
*
|
|
84
|
+
* @returns A promise that resolves when all resources have been released.
|
|
85
|
+
*/
|
|
86
|
+
shutdown(): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Execute an A2A task request.
|
|
89
|
+
*
|
|
90
|
+
* This is the core method required by the `@a2a-js/sdk/server`
|
|
91
|
+
* `AgentExecutor` interface. The server framework calls it for every
|
|
92
|
+
* inbound `message/send` or `message/stream` JSON-RPC request.
|
|
93
|
+
*
|
|
94
|
+
* Implementations should:
|
|
95
|
+
* 1. Extract the user message and any reference tasks from `ctx`.
|
|
96
|
+
* 2. Forward the request to the backend system.
|
|
97
|
+
* 3. Publish progress status events and artifact events on `bus` as
|
|
98
|
+
* results arrive from the backend.
|
|
99
|
+
* 4. Publish a final status event (`completed`, `failed`, or `canceled`)
|
|
100
|
+
* before the returned promise resolves.
|
|
101
|
+
*
|
|
102
|
+
* @param ctx - The request context containing the user message, task ID,
|
|
103
|
+
* context ID, and optional reference tasks. Provided by the A2A SDK's
|
|
104
|
+
* `DefaultRequestHandler`.
|
|
105
|
+
* @param bus - The event bus for publishing `TaskStatusUpdateEvent` and
|
|
106
|
+
* `TaskArtifactUpdateEvent` instances back to the client.
|
|
107
|
+
*
|
|
108
|
+
* @returns A promise that resolves when execution is complete and all
|
|
109
|
+
* events have been published.
|
|
110
|
+
*/
|
|
111
|
+
execute(ctx: RequestContext, bus: ExecutionEventBus): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Cancel a running task.
|
|
114
|
+
*
|
|
115
|
+
* Called when the client sends a `tasks/cancel` JSON-RPC request.
|
|
116
|
+
* Implementations should abort any in-flight backend work for the given
|
|
117
|
+
* task and publish a final `canceled` status event on the bus.
|
|
118
|
+
*
|
|
119
|
+
* This method is optional. If not implemented, the server will report
|
|
120
|
+
* that cancellation is not supported for the task.
|
|
121
|
+
*
|
|
122
|
+
* @param taskId - The unique identifier of the task to cancel.
|
|
123
|
+
* @param bus - The event bus for publishing the final `canceled` status
|
|
124
|
+
* event.
|
|
125
|
+
*
|
|
126
|
+
* @returns A promise that resolves once cancellation is complete and the
|
|
127
|
+
* status event has been published.
|
|
128
|
+
*/
|
|
129
|
+
cancelTask?(taskId: string, bus: ExecutionEventBus): Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* Read the pre-built domain context file content.
|
|
132
|
+
*
|
|
133
|
+
* Returns the current contents of the context file that was previously
|
|
134
|
+
* generated by {@link buildContext}, or `null` if no context file exists.
|
|
135
|
+
* The server factory exposes this via the `GET /context` route so that
|
|
136
|
+
* clients can inspect the active context.
|
|
137
|
+
*
|
|
138
|
+
* This method is optional. Executors that do not support context files
|
|
139
|
+
* may omit it entirely.
|
|
140
|
+
*
|
|
141
|
+
* @returns A promise resolving to the context file content as a string,
|
|
142
|
+
* or `null` if no context file is available.
|
|
143
|
+
*/
|
|
144
|
+
getContextContent?(): Promise<string | null>;
|
|
145
|
+
/**
|
|
146
|
+
* Build or refresh the domain context file.
|
|
147
|
+
*
|
|
148
|
+
* Generates a context file that enriches the backend's system prompt with
|
|
149
|
+
* domain-specific knowledge (e.g., repository structure, API docs). The
|
|
150
|
+
* server factory exposes this via the `POST /context/build` route.
|
|
151
|
+
*
|
|
152
|
+
* This method is optional. Executors that do not support context building
|
|
153
|
+
* may omit it entirely.
|
|
154
|
+
*
|
|
155
|
+
* @param prompt - An optional prompt or instruction to guide context
|
|
156
|
+
* generation. When omitted, the executor should use its default
|
|
157
|
+
* context-building strategy.
|
|
158
|
+
*
|
|
159
|
+
* @returns A promise resolving to the generated context content as a
|
|
160
|
+
* string.
|
|
161
|
+
*/
|
|
162
|
+
buildContext?(prompt?: string): Promise<string>;
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/executor/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;;;;;;;;;;;OAeG;IACH,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5B;;;;;;;;;OASG;IACH,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1B;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,OAAO,CAAC,GAAG,EAAE,cAAc,EAAE,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpE;;;;;;;;;;;;;;;;OAgBG;IACH,UAAU,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnE;;;;;;;;;;;;;OAaG;IACH,iBAAiB,CAAC,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAE7C;;;;;;;;;;;;;;;;OAgBG;IACH,YAAY,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACjD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module executor/types
|
|
3
|
+
*
|
|
4
|
+
* Defines the {@link A2AExecutor} interface — the contract that every wrapper
|
|
5
|
+
* project's executor must satisfy in order to plug into the shared A2A server
|
|
6
|
+
* infrastructure provided by `@a2a-wrapper/core`.
|
|
7
|
+
*
|
|
8
|
+
* The interface is structurally compatible with the `AgentExecutor` type
|
|
9
|
+
* exported by `@a2a-js/sdk/server`, so implementations can be passed directly
|
|
10
|
+
* to `DefaultRequestHandler` without an adapter layer. It extends the SDK
|
|
11
|
+
* contract with lifecycle hooks (`initialize`, `shutdown`) and optional
|
|
12
|
+
* context-file operations (`getContextContent`, `buildContext`) that are
|
|
13
|
+
* common across all current wrapper projects.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import type { A2AExecutor } from "@a2a-wrapper/core";
|
|
18
|
+
*
|
|
19
|
+
* class MyExecutor implements A2AExecutor {
|
|
20
|
+
* async initialize() { // connect to backend }
|
|
21
|
+
* async shutdown() { // release resources }
|
|
22
|
+
* async execute(ctx, bus) { // handle A2A task }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @see {@link https://github.com/a2a-js/a2a-js | @a2a-js/sdk} for the
|
|
27
|
+
* upstream `AgentExecutor` and `RequestContext` definitions.
|
|
28
|
+
*/
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/executor/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @a2a-wrapper/core — Public API
|
|
3
|
+
*
|
|
4
|
+
* Barrel export for the shared A2A wrapper infrastructure package. Every
|
|
5
|
+
* symbol re-exported here is part of the public API surface and is covered
|
|
6
|
+
* by semantic versioning guarantees.
|
|
7
|
+
*
|
|
8
|
+
* Wrapper projects should import exclusively from `@a2a-wrapper/core`
|
|
9
|
+
* rather than reaching into internal module paths. This allows the core
|
|
10
|
+
* package to reorganise internals without breaking downstream consumers.
|
|
11
|
+
*
|
|
12
|
+
* A2A SDK types that wrapper projects commonly reference are re-exported
|
|
13
|
+
* here behind core-owned names. This isolates downstream code from SDK
|
|
14
|
+
* major-version upgrades — only this barrel file needs updating when the
|
|
15
|
+
* SDK ships breaking type changes.
|
|
16
|
+
*
|
|
17
|
+
* @module @a2a-wrapper/core
|
|
18
|
+
* @packageDocumentation
|
|
19
|
+
*/
|
|
20
|
+
export { LogLevel, Logger, createLogger } from "./utils/logger.js";
|
|
21
|
+
export { type Deferred, createDeferred, sleep } from "./utils/deferred.js";
|
|
22
|
+
export { deepMerge, substituteEnvTokens } from "./utils/deep-merge.js";
|
|
23
|
+
export type { SkillConfig, AgentCardConfig, ServerConfig, SessionConfig, BaseFeatureFlags, TimeoutConfig, LoggingConfig, BaseMcpServerConfig, BaseAgentConfig, } from "./config/types.js";
|
|
24
|
+
export { loadConfigFile, resolveConfig } from "./config/loader.js";
|
|
25
|
+
export { publishStatus, publishFinalArtifact, publishStreamingChunk, publishLastChunkMarker, publishTraceArtifact, publishThoughtArtifact, } from "./events/event-publisher.js";
|
|
26
|
+
export { buildAgentCard, type BuildAgentCardInput } from "./server/agent-card.js";
|
|
27
|
+
export { createA2AServer, type ServerOptions, type ServerHandle, } from "./server/factory.js";
|
|
28
|
+
export { BaseSessionManager, type SessionEntry } from "./session/base-session-manager.js";
|
|
29
|
+
export type { A2AExecutor } from "./executor/types.js";
|
|
30
|
+
export { createCli, type CliOptions, parseCommonArgs, type CommonArgsResult, } from "./cli/scaffold.js";
|
|
31
|
+
/** @see {@link https://github.com/a2a-js/a2a-js | @a2a-js/sdk} */
|
|
32
|
+
export type { AgentCard } from "@a2a-js/sdk";
|
|
33
|
+
/** @see {@link https://github.com/a2a-js/a2a-js | @a2a-js/sdk} */
|
|
34
|
+
export type { TaskState, TaskStatusUpdateEvent, TaskArtifactUpdateEvent } from "@a2a-js/sdk";
|
|
35
|
+
/** @see {@link https://github.com/a2a-js/a2a-js | @a2a-js/sdk/server} */
|
|
36
|
+
export type { ExecutionEventBus, RequestContext } from "@a2a-js/sdk/server";
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,KAAK,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAIvE,YAAY,EACV,WAAW,EACX,eAAe,EACf,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAInE,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AAIrC,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAElF,OAAO,EACL,eAAe,EACf,KAAK,aAAa,EAClB,KAAK,YAAY,GAClB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EAAE,kBAAkB,EAAE,KAAK,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAI1F,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIvD,OAAO,EACL,SAAS,EACT,KAAK,UAAU,EACf,eAAe,EACf,KAAK,gBAAgB,GACtB,MAAM,mBAAmB,CAAC;AAS3B,kEAAkE;AAClE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,kEAAkE;AAClE,YAAY,EAAE,SAAS,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE7F,yEAAyE;AACzE,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @a2a-wrapper/core — Public API
|
|
3
|
+
*
|
|
4
|
+
* Barrel export for the shared A2A wrapper infrastructure package. Every
|
|
5
|
+
* symbol re-exported here is part of the public API surface and is covered
|
|
6
|
+
* by semantic versioning guarantees.
|
|
7
|
+
*
|
|
8
|
+
* Wrapper projects should import exclusively from `@a2a-wrapper/core`
|
|
9
|
+
* rather than reaching into internal module paths. This allows the core
|
|
10
|
+
* package to reorganise internals without breaking downstream consumers.
|
|
11
|
+
*
|
|
12
|
+
* A2A SDK types that wrapper projects commonly reference are re-exported
|
|
13
|
+
* here behind core-owned names. This isolates downstream code from SDK
|
|
14
|
+
* major-version upgrades — only this barrel file needs updating when the
|
|
15
|
+
* SDK ships breaking type changes.
|
|
16
|
+
*
|
|
17
|
+
* @module @a2a-wrapper/core
|
|
18
|
+
* @packageDocumentation
|
|
19
|
+
*/
|
|
20
|
+
// ─── Utilities ──────────────────────────────────────────────────────────────
|
|
21
|
+
export { LogLevel, Logger, createLogger } from "./utils/logger.js";
|
|
22
|
+
export { createDeferred, sleep } from "./utils/deferred.js";
|
|
23
|
+
export { deepMerge, substituteEnvTokens } from "./utils/deep-merge.js";
|
|
24
|
+
export { loadConfigFile, resolveConfig } from "./config/loader.js";
|
|
25
|
+
// ─── Events ─────────────────────────────────────────────────────────────────
|
|
26
|
+
export { publishStatus, publishFinalArtifact, publishStreamingChunk, publishLastChunkMarker, publishTraceArtifact, publishThoughtArtifact, } from "./events/event-publisher.js";
|
|
27
|
+
// ─── Server ─────────────────────────────────────────────────────────────────
|
|
28
|
+
export { buildAgentCard } from "./server/agent-card.js";
|
|
29
|
+
export { createA2AServer, } from "./server/factory.js";
|
|
30
|
+
// ─── Session ────────────────────────────────────────────────────────────────
|
|
31
|
+
export { BaseSessionManager } from "./session/base-session-manager.js";
|
|
32
|
+
// ─── CLI ────────────────────────────────────────────────────────────────────
|
|
33
|
+
export { createCli, parseCommonArgs, } from "./cli/scaffold.js";
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,+EAA+E;AAE/E,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAiB,cAAc,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAgBvE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnE,+EAA+E;AAE/E,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AAErC,+EAA+E;AAE/E,OAAO,EAAE,cAAc,EAA4B,MAAM,wBAAwB,CAAC;AAElF,OAAO,EACL,eAAe,GAGhB,MAAM,qBAAqB,CAAC;AAE7B,+EAA+E;AAE/E,OAAO,EAAE,kBAAkB,EAAqB,MAAM,mCAAmC,CAAC;AAM1F,+EAA+E;AAE/E,OAAO,EACL,SAAS,EAET,eAAe,GAEhB,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Card Builder
|
|
3
|
+
*
|
|
4
|
+
* Constructs an A2A-spec-compliant {@link AgentCard} from resolved
|
|
5
|
+
* {@link AgentCardConfig} and {@link ServerConfig} sections. This module
|
|
6
|
+
* is the single source of truth for agent card construction across all
|
|
7
|
+
* wrapper projects, ensuring consistent endpoint URL computation,
|
|
8
|
+
* capability flag mapping, and skill serialization.
|
|
9
|
+
*
|
|
10
|
+
* Ported from `a2a-copilot/src/server/agent-card.ts` with the following
|
|
11
|
+
* changes for core-package reuse:
|
|
12
|
+
*
|
|
13
|
+
* 1. Accepts `{ agentCard, server }` instead of a full `AgentConfig`.
|
|
14
|
+
* 2. No logger dependency — the core package does not own a singleton logger.
|
|
15
|
+
* 3. `stateTransitionHistory` is always `false` (removed in A2A v1.0).
|
|
16
|
+
*
|
|
17
|
+
* @module server/agent-card
|
|
18
|
+
*/
|
|
19
|
+
import type { AgentCard } from "@a2a-js/sdk";
|
|
20
|
+
import type { AgentCardConfig, ServerConfig } from "../config/types.js";
|
|
21
|
+
/**
|
|
22
|
+
* Input shape accepted by {@link buildAgentCard}.
|
|
23
|
+
*
|
|
24
|
+
* Only the `agentCard` and `server` configuration sections are required to
|
|
25
|
+
* construct a complete agent card. This keeps the builder decoupled from
|
|
26
|
+
* backend-specific configuration and session/timeout settings.
|
|
27
|
+
*/
|
|
28
|
+
export interface BuildAgentCardInput {
|
|
29
|
+
/** Agent identity and capability configuration. */
|
|
30
|
+
agentCard: AgentCardConfig;
|
|
31
|
+
/** Server networking configuration used to compute endpoint URLs. */
|
|
32
|
+
server: ServerConfig;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Constructs an A2A {@link AgentCard} from resolved configuration.
|
|
36
|
+
*
|
|
37
|
+
* Computes endpoint URLs from the `server` section, maps capability flags
|
|
38
|
+
* and skills from the `agentCard` section, and advertises both JSON-RPC and
|
|
39
|
+
* REST transports via `additionalInterfaces`.
|
|
40
|
+
*
|
|
41
|
+
* Key behaviors:
|
|
42
|
+
* - `stateTransitionHistory` is always set to `false` regardless of input,
|
|
43
|
+
* because this capability was removed in the A2A v1.0 specification.
|
|
44
|
+
* - The primary `url` field points to the JSON-RPC endpoint for backward
|
|
45
|
+
* compatibility with v0.3.x clients.
|
|
46
|
+
* - `protocolVersion` defaults to `"0.3.0"` when not explicitly configured.
|
|
47
|
+
* - `supportsAuthenticatedExtendedCard` is always `false` unless explicitly
|
|
48
|
+
* configured otherwise in a future extension.
|
|
49
|
+
*
|
|
50
|
+
* @param config - Object containing `agentCard` and `server` configuration
|
|
51
|
+
* sections. See {@link BuildAgentCardInput} for the expected shape.
|
|
52
|
+
* @returns A fully populated {@link AgentCard} ready to be served at
|
|
53
|
+
* `/.well-known/agent-card.json`.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* import { buildAgentCard } from "@a2a-wrapper/core";
|
|
58
|
+
*
|
|
59
|
+
* const card = buildAgentCard({
|
|
60
|
+
* agentCard: { name: "My Agent", description: "Does things" },
|
|
61
|
+
* server: { port: 3000, advertiseHost: "localhost" },
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function buildAgentCard(config: BuildAgentCardInput): AgentCard;
|
|
66
|
+
//# sourceMappingURL=agent-card.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-card.d.ts","sourceRoot":"","sources":["../../src/server/agent-card.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAe,MAAM,oBAAoB,CAAC;AAErF;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,mDAAmD;IACnD,SAAS,EAAE,eAAe,CAAC;IAC3B,qEAAqE;IACrE,MAAM,EAAE,YAAY,CAAC;CACtB;AAuBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,mBAAmB,GAAG,SAAS,CA6CrE"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Card Builder
|
|
3
|
+
*
|
|
4
|
+
* Constructs an A2A-spec-compliant {@link AgentCard} from resolved
|
|
5
|
+
* {@link AgentCardConfig} and {@link ServerConfig} sections. This module
|
|
6
|
+
* is the single source of truth for agent card construction across all
|
|
7
|
+
* wrapper projects, ensuring consistent endpoint URL computation,
|
|
8
|
+
* capability flag mapping, and skill serialization.
|
|
9
|
+
*
|
|
10
|
+
* Ported from `a2a-copilot/src/server/agent-card.ts` with the following
|
|
11
|
+
* changes for core-package reuse:
|
|
12
|
+
*
|
|
13
|
+
* 1. Accepts `{ agentCard, server }` instead of a full `AgentConfig`.
|
|
14
|
+
* 2. No logger dependency — the core package does not own a singleton logger.
|
|
15
|
+
* 3. `stateTransitionHistory` is always `false` (removed in A2A v1.0).
|
|
16
|
+
*
|
|
17
|
+
* @module server/agent-card
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Maps a {@link SkillConfig} to the A2A `AgentSkill` shape expected by the SDK.
|
|
21
|
+
*
|
|
22
|
+
* The `examples` field is included only when the source array is non-empty,
|
|
23
|
+
* keeping the serialized agent card minimal.
|
|
24
|
+
*
|
|
25
|
+
* @param skill - The skill configuration to transform.
|
|
26
|
+
* @returns An object conforming to the A2A `AgentSkill` interface.
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
function mapSkill(skill) {
|
|
31
|
+
return {
|
|
32
|
+
id: skill.id,
|
|
33
|
+
name: skill.name,
|
|
34
|
+
description: skill.description,
|
|
35
|
+
tags: skill.tags ?? [],
|
|
36
|
+
...(skill.examples?.length ? { examples: skill.examples } : {}),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Constructs an A2A {@link AgentCard} from resolved configuration.
|
|
41
|
+
*
|
|
42
|
+
* Computes endpoint URLs from the `server` section, maps capability flags
|
|
43
|
+
* and skills from the `agentCard` section, and advertises both JSON-RPC and
|
|
44
|
+
* REST transports via `additionalInterfaces`.
|
|
45
|
+
*
|
|
46
|
+
* Key behaviors:
|
|
47
|
+
* - `stateTransitionHistory` is always set to `false` regardless of input,
|
|
48
|
+
* because this capability was removed in the A2A v1.0 specification.
|
|
49
|
+
* - The primary `url` field points to the JSON-RPC endpoint for backward
|
|
50
|
+
* compatibility with v0.3.x clients.
|
|
51
|
+
* - `protocolVersion` defaults to `"0.3.0"` when not explicitly configured.
|
|
52
|
+
* - `supportsAuthenticatedExtendedCard` is always `false` unless explicitly
|
|
53
|
+
* configured otherwise in a future extension.
|
|
54
|
+
*
|
|
55
|
+
* @param config - Object containing `agentCard` and `server` configuration
|
|
56
|
+
* sections. See {@link BuildAgentCardInput} for the expected shape.
|
|
57
|
+
* @returns A fully populated {@link AgentCard} ready to be served at
|
|
58
|
+
* `/.well-known/agent-card.json`.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* import { buildAgentCard } from "@a2a-wrapper/core";
|
|
63
|
+
*
|
|
64
|
+
* const card = buildAgentCard({
|
|
65
|
+
* agentCard: { name: "My Agent", description: "Does things" },
|
|
66
|
+
* server: { port: 3000, advertiseHost: "localhost" },
|
|
67
|
+
* });
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export function buildAgentCard(config) {
|
|
71
|
+
const { agentCard, server } = config;
|
|
72
|
+
const host = server.advertiseHost ?? server.hostname ?? "localhost";
|
|
73
|
+
const port = server.port ?? 3000;
|
|
74
|
+
// Use configured protocol; defaults to "http" for local dev.
|
|
75
|
+
// Set advertiseProtocol: "https" in config for production deployments.
|
|
76
|
+
const proto = server.advertiseProtocol ?? "http";
|
|
77
|
+
const baseUrl = `${proto}://${host}:${port}`;
|
|
78
|
+
const jsonRpcUrl = `${baseUrl}/a2a/jsonrpc`;
|
|
79
|
+
const restUrl = `${baseUrl}/a2a/rest`;
|
|
80
|
+
const card = {
|
|
81
|
+
name: agentCard.name,
|
|
82
|
+
description: agentCard.description,
|
|
83
|
+
// Primary endpoint (v0.3.x required field; retained for backward compat with
|
|
84
|
+
// v0.3.x clients and the current SDK, which still reads this field).
|
|
85
|
+
url: jsonRpcUrl,
|
|
86
|
+
...(agentCard.provider
|
|
87
|
+
? { provider: { organization: agentCard.provider.organization, url: agentCard.provider.url ?? "" } }
|
|
88
|
+
: {}),
|
|
89
|
+
version: agentCard.version ?? "1.0.0",
|
|
90
|
+
capabilities: {
|
|
91
|
+
streaming: agentCard.streaming ?? true,
|
|
92
|
+
pushNotifications: agentCard.pushNotifications ?? false,
|
|
93
|
+
// stateTransitionHistory was removed in A2A v1.0 as unimplemented.
|
|
94
|
+
// We advertise false so v0.3.x clients that check this flag don't expect history.
|
|
95
|
+
stateTransitionHistory: false,
|
|
96
|
+
},
|
|
97
|
+
// Retain protocolVersion for v0.3.x client backward compatibility.
|
|
98
|
+
// When the SDK ships v1.0 types this moves into additionalInterfaces[].protocolVersion.
|
|
99
|
+
protocolVersion: agentCard.protocolVersion ?? "0.3.0",
|
|
100
|
+
skills: (agentCard.skills ?? []).map(mapSkill),
|
|
101
|
+
defaultInputModes: agentCard.defaultInputModes ?? ["text"],
|
|
102
|
+
defaultOutputModes: agentCard.defaultOutputModes ?? ["text"],
|
|
103
|
+
// additionalInterfaces: advertise all supported transports so that v1.0-aware
|
|
104
|
+
// clients can discover the REST endpoint and future protocol versions.
|
|
105
|
+
additionalInterfaces: [
|
|
106
|
+
{ transport: "JSONRPC", url: jsonRpcUrl },
|
|
107
|
+
{ transport: "REST", url: restUrl },
|
|
108
|
+
],
|
|
109
|
+
// Do not advertise an authenticated extended card unless explicitly configured.
|
|
110
|
+
supportsAuthenticatedExtendedCard: false,
|
|
111
|
+
};
|
|
112
|
+
return card;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=agent-card.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-card.js","sourceRoot":"","sources":["../../src/server/agent-card.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAmBH;;;;;;;;;;GAUG;AACH,SAAS,QAAQ,CAAC,KAAkB;IAClC,OAAO;QACL,EAAE,EAAE,KAAK,CAAC,EAAE;QACZ,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,EAAE;QACtB,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChE,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,cAAc,CAAC,MAA2B;IACxD,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IACrC,MAAM,IAAI,GAAG,MAAM,CAAC,aAAa,IAAI,MAAM,CAAC,QAAQ,IAAI,WAAW,CAAC;IACpE,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,IAAI,CAAC;IACjC,6DAA6D;IAC7D,uEAAuE;IACvE,MAAM,KAAK,GAAG,MAAM,CAAC,iBAAiB,IAAI,MAAM,CAAC;IACjD,MAAM,OAAO,GAAG,GAAG,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;IAC7C,MAAM,UAAU,GAAG,GAAG,OAAO,cAAc,CAAC;IAC5C,MAAM,OAAO,GAAG,GAAG,OAAO,WAAW,CAAC;IAEtC,MAAM,IAAI,GAAc;QACtB,IAAI,EAAE,SAAS,CAAC,IAAI;QACpB,WAAW,EAAE,SAAS,CAAC,WAAW;QAClC,6EAA6E;QAC7E,qEAAqE;QACrE,GAAG,EAAE,UAAU;QACf,GAAG,CAAC,SAAS,CAAC,QAAQ;YACpB,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,YAAY,EAAE,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE,SAAS,CAAC,QAAQ,CAAC,GAAG,IAAI,EAAE,EAAE,EAAE;YACpG,CAAC,CAAC,EAAE,CAAC;QACP,OAAO,EAAE,SAAS,CAAC,OAAO,IAAI,OAAO;QACrC,YAAY,EAAE;YACZ,SAAS,EAAE,SAAS,CAAC,SAAS,IAAI,IAAI;YACtC,iBAAiB,EAAE,SAAS,CAAC,iBAAiB,IAAI,KAAK;YACvD,mEAAmE;YACnE,kFAAkF;YAClF,sBAAsB,EAAE,KAAK;SAC9B;QACD,mEAAmE;QACnE,wFAAwF;QACxF,eAAe,EAAE,SAAS,CAAC,eAAe,IAAI,OAAO;QACrD,MAAM,EAAE,CAAC,SAAS,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC;QAC9C,iBAAiB,EAAE,SAAS,CAAC,iBAAiB,IAAI,CAAC,MAAM,CAAC;QAC1D,kBAAkB,EAAE,SAAS,CAAC,kBAAkB,IAAI,CAAC,MAAM,CAAC;QAC5D,8EAA8E;QAC9E,uEAAuE;QACvE,oBAAoB,EAAE;YACpB,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,UAAU,EAAE;YACzC,EAAE,SAAS,EAAE,MAAM,EAAK,GAAG,EAAE,OAAO,EAAE;SACvC;QACD,gFAAgF;QAChF,iCAAiC,EAAE,KAAK;KACzC,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A2A Server Factory
|
|
3
|
+
*
|
|
4
|
+
* Creates, wires, and starts an Express-based A2A HTTP server with all
|
|
5
|
+
* standard protocol routes. This module is the single entry point for
|
|
6
|
+
* server bootstrapping across all wrapper projects, ensuring consistent
|
|
7
|
+
* route registration, middleware ordering, and lifecycle management.
|
|
8
|
+
*
|
|
9
|
+
* Ported from `a2a-copilot/src/server/index.ts` and
|
|
10
|
+
* `a2a-opencode/src/server/index.ts` with the following changes for
|
|
11
|
+
* core-package reuse:
|
|
12
|
+
*
|
|
13
|
+
* 1. Accepts a generic `executorFactory` callback instead of importing a
|
|
14
|
+
* concrete executor class — the core package has zero knowledge of any
|
|
15
|
+
* specific backend.
|
|
16
|
+
* 2. Supports an optional {@link ServerOptions.registerRoutes} hook so that
|
|
17
|
+
* wrapper projects can mount custom routes (e.g. `/context`, `/mcp/status`)
|
|
18
|
+
* before the server starts listening.
|
|
19
|
+
* 3. The `A2A-Version` response header value is configurable via
|
|
20
|
+
* {@link ServerOptions.protocolVersion} (default `"0.3"`).
|
|
21
|
+
* 4. Wrapper-specific routes (context API, MCP status) are **not** included —
|
|
22
|
+
* those belong in each wrapper's `registerRoutes` hook.
|
|
23
|
+
*
|
|
24
|
+
* @module server/factory
|
|
25
|
+
*/
|
|
26
|
+
import { type Express } from "express";
|
|
27
|
+
import type { BaseAgentConfig } from "../config/types.js";
|
|
28
|
+
/**
|
|
29
|
+
* Minimal executor contract required by the server factory.
|
|
30
|
+
*
|
|
31
|
+
* Every wrapper project implements this interface with its backend-specific
|
|
32
|
+
* logic (e.g. `CopilotExecutor`, `OpenCodeExecutor`). The server factory
|
|
33
|
+
* calls {@link initialize} during startup and {@link shutdown} during
|
|
34
|
+
* graceful teardown.
|
|
35
|
+
*
|
|
36
|
+
* The `execute` and `cancelTask` methods are inherited from the SDK's
|
|
37
|
+
* `AgentExecutor` type and are invoked by {@link DefaultRequestHandler}
|
|
38
|
+
* when processing A2A JSON-RPC / REST requests.
|
|
39
|
+
*/
|
|
40
|
+
export interface A2AExecutor {
|
|
41
|
+
/**
|
|
42
|
+
* Perform asynchronous startup logic (e.g. connect to backend, register
|
|
43
|
+
* MCP servers, warm caches). Called once before the HTTP server begins
|
|
44
|
+
* accepting requests.
|
|
45
|
+
*/
|
|
46
|
+
initialize(): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Perform graceful cleanup (e.g. close backend connections, flush buffers).
|
|
49
|
+
* Called when the server is shutting down.
|
|
50
|
+
*/
|
|
51
|
+
shutdown(): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Optional customization hooks for the A2A server.
|
|
55
|
+
*
|
|
56
|
+
* Wrapper projects pass these options to {@link createA2AServer} to inject
|
|
57
|
+
* custom routes and override protocol-level defaults without modifying the
|
|
58
|
+
* core server wiring.
|
|
59
|
+
*/
|
|
60
|
+
export interface ServerOptions {
|
|
61
|
+
/**
|
|
62
|
+
* A2A protocol version advertised in the `A2A-Version` response header.
|
|
63
|
+
*
|
|
64
|
+
* This value is sent on **every** HTTP response so that clients can
|
|
65
|
+
* detect the server's protocol level. Future A2A spec versions can be
|
|
66
|
+
* supported by changing this single value.
|
|
67
|
+
*
|
|
68
|
+
* @default "0.3"
|
|
69
|
+
*/
|
|
70
|
+
protocolVersion?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Hook invoked after standard routes are registered but **before** the
|
|
73
|
+
* server starts listening. Use this to mount wrapper-specific endpoints
|
|
74
|
+
* (e.g. `/context`, `/context/build`, `/mcp/status`).
|
|
75
|
+
*
|
|
76
|
+
* @param app - The Express application instance.
|
|
77
|
+
* @param executor - The initialized executor, available for route handlers
|
|
78
|
+
* that need to delegate to the backend.
|
|
79
|
+
*/
|
|
80
|
+
registerRoutes?: (app: Express, executor: A2AExecutor) => void;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Handle returned by {@link createA2AServer} for lifecycle management.
|
|
84
|
+
*
|
|
85
|
+
* Callers use this handle to access the Express app (e.g. for supertest),
|
|
86
|
+
* the underlying HTTP server, the initialized executor, and a `shutdown`
|
|
87
|
+
* method for graceful teardown.
|
|
88
|
+
*/
|
|
89
|
+
export interface ServerHandle {
|
|
90
|
+
/** The Express application instance with all routes registered. */
|
|
91
|
+
app: Express;
|
|
92
|
+
/** The Node.js HTTP server returned by `app.listen()`. */
|
|
93
|
+
server: ReturnType<Express["listen"]>;
|
|
94
|
+
/** The initialized backend executor. */
|
|
95
|
+
executor: A2AExecutor;
|
|
96
|
+
/**
|
|
97
|
+
* Gracefully shut down the server and executor.
|
|
98
|
+
*
|
|
99
|
+
* Closes the HTTP server so no new connections are accepted, then
|
|
100
|
+
* calls `executor.shutdown()` for backend cleanup.
|
|
101
|
+
*/
|
|
102
|
+
shutdown(): Promise<void>;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Create, wire, and start an A2A-compliant Express server.
|
|
106
|
+
*
|
|
107
|
+
* This function is the primary entry point for all wrapper projects. It:
|
|
108
|
+
*
|
|
109
|
+
* 1. Instantiates the backend executor via the supplied `executorFactory`.
|
|
110
|
+
* 2. Builds the static agent card from resolved configuration.
|
|
111
|
+
* 3. Creates the A2A SDK request handler with an in-memory task store.
|
|
112
|
+
* 4. Mounts middleware and standard routes:
|
|
113
|
+
* - `A2A-Version` response header on every response.
|
|
114
|
+
* - `GET /health` — health check endpoint.
|
|
115
|
+
* - `GET /.well-known/agent-card.json` — dynamic agent card with URL
|
|
116
|
+
* rewriting for reverse proxy compatibility.
|
|
117
|
+
* - Legacy agent card paths (`.well-known/agent.json`,
|
|
118
|
+
* `.well-known/agent-json`).
|
|
119
|
+
* - `POST /a2a/jsonrpc` — JSON-RPC transport.
|
|
120
|
+
* - `/a2a/rest` — REST transport.
|
|
121
|
+
* 5. Invokes the optional `registerRoutes` hook for wrapper-specific routes.
|
|
122
|
+
* 6. Starts listening on the configured hostname and port.
|
|
123
|
+
* 7. Returns a {@link ServerHandle} for lifecycle management.
|
|
124
|
+
*
|
|
125
|
+
* @typeParam T - The full configuration type, extending {@link BaseAgentConfig}.
|
|
126
|
+
* The generic parameter ensures the `executorFactory` receives the same
|
|
127
|
+
* fully-resolved config type that the wrapper project defined.
|
|
128
|
+
*
|
|
129
|
+
* @param config - Fully resolved configuration with all fields populated.
|
|
130
|
+
* @param executorFactory - Factory function that creates the backend-specific
|
|
131
|
+
* executor from the resolved config. The server factory
|
|
132
|
+
* calls `executor.initialize()` before registering routes.
|
|
133
|
+
* @param options - Optional server customization (protocol version,
|
|
134
|
+
* custom route hooks).
|
|
135
|
+
* @returns A promise resolving to a {@link ServerHandle} once the server is
|
|
136
|
+
* listening and ready to accept requests.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* import { createA2AServer } from "@a2a-wrapper/core";
|
|
141
|
+
* import { MyExecutor } from "./my-executor.js";
|
|
142
|
+
*
|
|
143
|
+
* const handle = await createA2AServer(
|
|
144
|
+
* resolvedConfig,
|
|
145
|
+
* (cfg) => new MyExecutor(cfg),
|
|
146
|
+
* {
|
|
147
|
+
* protocolVersion: "0.3",
|
|
148
|
+
* registerRoutes: (app, executor) => {
|
|
149
|
+
* app.get("/custom", (_req, res) => res.json({ ok: true }));
|
|
150
|
+
* },
|
|
151
|
+
* },
|
|
152
|
+
* );
|
|
153
|
+
*
|
|
154
|
+
* // Graceful shutdown on SIGTERM
|
|
155
|
+
* process.on("SIGTERM", () => handle.shutdown());
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export declare function createA2AServer<T extends BaseAgentConfig<unknown>>(config: Required<T>, executorFactory: (config: Required<T>) => A2AExecutor, options?: ServerOptions): Promise<ServerHandle>;
|
|
159
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/server/factory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAgB,EAAE,KAAK,OAAO,EAAuB,MAAM,SAAS,CAAC;AASrE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAK1D;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5B;;;OAGG;IACH,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAID;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;;;;OAQG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;;;;;;OAQG;IACH,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,KAAK,IAAI,CAAC;CAChE;AAID;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B,mEAAmE;IACnE,GAAG,EAAE,OAAO,CAAC;IAEb,0DAA0D;IAC1D,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEtC,wCAAwC;IACxC,QAAQ,EAAE,WAAW,CAAC;IAEtB;;;;;OAKG;IACH,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,wBAAsB,eAAe,CAAC,CAAC,SAAS,eAAe,CAAC,OAAO,CAAC,EACtE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,EACnB,eAAe,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,WAAW,EACrD,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,YAAY,CAAC,CAwGvB"}
|