@axiom-lattice/cli-a2a 0.1.1
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/.turbo/turbo-build.log +51 -0
- package/CHANGELOG.md +7 -0
- package/LICENSE +201 -0
- package/README.md +290 -0
- package/__tests__/opencode-executor.test.ts +159 -0
- package/agents/opencode-example/config.json +64 -0
- package/dist/bridge-7ZUDKCZT.mjs +271 -0
- package/dist/bridge-7ZUDKCZT.mjs.map +1 -0
- package/dist/chunk-35NFMGMS.mjs +27 -0
- package/dist/chunk-35NFMGMS.mjs.map +1 -0
- package/dist/chunk-G7AGL2QA.mjs +284 -0
- package/dist/chunk-G7AGL2QA.mjs.map +1 -0
- package/dist/chunk-LXL47XMZ.mjs +43 -0
- package/dist/chunk-LXL47XMZ.mjs.map +1 -0
- package/dist/chunk-NQIDRU47.mjs +178 -0
- package/dist/chunk-NQIDRU47.mjs.map +1 -0
- package/dist/chunk-VSZ3DACI.mjs +179 -0
- package/dist/chunk-VSZ3DACI.mjs.map +1 -0
- package/dist/chunk-VZEH3EPJ.mjs +56 -0
- package/dist/chunk-VZEH3EPJ.mjs.map +1 -0
- package/dist/chunk-WNCDOYZS.mjs +187 -0
- package/dist/chunk-WNCDOYZS.mjs.map +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +1562 -0
- package/dist/cli.js.map +1 -0
- package/dist/cli.mjs +293 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/executor-OWPVDUXH.mjs +11 -0
- package/dist/executor-OWPVDUXH.mjs.map +1 -0
- package/dist/executor-RVBGAWUF.mjs +11 -0
- package/dist/executor-RVBGAWUF.mjs.map +1 -0
- package/dist/executor-XWHWUVQ3.mjs +11 -0
- package/dist/executor-XWHWUVQ3.mjs.map +1 -0
- package/dist/executors-QIIKBUMJ.mjs +15 -0
- package/dist/executors-QIIKBUMJ.mjs.map +1 -0
- package/dist/index.d.mts +295 -0
- package/dist/index.d.ts +295 -0
- package/dist/index.js +942 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +44 -0
- package/dist/index.mjs.map +1 -0
- package/jest.config.js +16 -0
- package/package.json +63 -0
- package/src/bridge.ts +355 -0
- package/src/cli.ts +384 -0
- package/src/config/defaults.ts +109 -0
- package/src/config/index.ts +16 -0
- package/src/config/loader.ts +121 -0
- package/src/config/types.ts +163 -0
- package/src/executors/claude/client.ts +138 -0
- package/src/executors/claude/executor.ts +111 -0
- package/src/executors/codex/client.ts +139 -0
- package/src/executors/codex/executor.ts +118 -0
- package/src/executors/events.ts +117 -0
- package/src/executors/index.ts +54 -0
- package/src/executors/opencode/client.ts +149 -0
- package/src/executors/opencode/executor.ts +112 -0
- package/src/index.ts +54 -0
- package/src/logger.ts +78 -0
- package/src/server/agent-card.ts +51 -0
- package/src/server/index.ts +124 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A2A HTTP Server
|
|
3
|
+
*
|
|
4
|
+
* Creates an Express server with standard A2A endpoints:
|
|
5
|
+
* - GET /.well-known/agent-card.json → Agent Card
|
|
6
|
+
* - POST /a2a/jsonrpc → JSON-RPC transport
|
|
7
|
+
* - POST /a2a/rest → REST transport
|
|
8
|
+
* - GET /health → Health check
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import express, { type RequestHandler } from 'express';
|
|
12
|
+
import { AGENT_CARD_PATH } from '@a2a-js/sdk';
|
|
13
|
+
import { DefaultRequestHandler, InMemoryTaskStore } from '@a2a-js/sdk/server';
|
|
14
|
+
import {
|
|
15
|
+
jsonRpcHandler,
|
|
16
|
+
restHandler,
|
|
17
|
+
UserBuilder,
|
|
18
|
+
} from '@a2a-js/sdk/server/express';
|
|
19
|
+
|
|
20
|
+
import type { AgentConfig } from '../config/types.js';
|
|
21
|
+
import { buildAgentCard } from './agent-card.js';
|
|
22
|
+
import { createExecutor } from '../executors/index.js';
|
|
23
|
+
import { logger } from '../logger.js';
|
|
24
|
+
|
|
25
|
+
const log = logger.child('server');
|
|
26
|
+
|
|
27
|
+
// ─── Types ──────────────────────────────────────────────────────────────────
|
|
28
|
+
|
|
29
|
+
export interface ServerHandle {
|
|
30
|
+
app: ReturnType<typeof express>;
|
|
31
|
+
server: ReturnType<ReturnType<typeof express>['listen']>;
|
|
32
|
+
shutdown(): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ─── Server Factory ─────────────────────────────────────────────────────────
|
|
36
|
+
|
|
37
|
+
export async function createA2AServer(config: Required<AgentConfig>): Promise<ServerHandle> {
|
|
38
|
+
const srv = config.server;
|
|
39
|
+
const port = srv.port ?? 3000;
|
|
40
|
+
const hostname = srv.hostname ?? '0.0.0.0';
|
|
41
|
+
const advertiseHost = srv.advertiseHost ?? 'localhost';
|
|
42
|
+
const advertiseProto = srv.advertiseProtocol ?? 'http';
|
|
43
|
+
|
|
44
|
+
// 1. Create executor
|
|
45
|
+
const executor = createExecutor(config);
|
|
46
|
+
await executor.initialize();
|
|
47
|
+
|
|
48
|
+
// 2. Build agent card
|
|
49
|
+
const agentCard = buildAgentCard(config);
|
|
50
|
+
|
|
51
|
+
// 3. A2A request handler
|
|
52
|
+
const taskStore = new InMemoryTaskStore();
|
|
53
|
+
const requestHandler = new DefaultRequestHandler(agentCard, taskStore, executor);
|
|
54
|
+
|
|
55
|
+
// 4. Express app
|
|
56
|
+
const app = express();
|
|
57
|
+
|
|
58
|
+
// A2A-Version header
|
|
59
|
+
app.use((_req, res, next) => {
|
|
60
|
+
res.setHeader('A2A-Version', '0.3');
|
|
61
|
+
next();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Health check
|
|
65
|
+
app.get('/health', (_req, res) => {
|
|
66
|
+
res.json({ status: 'healthy', agent: agentCard.name, provider: config.provider });
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Agent card — dynamic URL rewriting for reverse proxy support
|
|
70
|
+
const serveAgentCard: RequestHandler = (req, res) => {
|
|
71
|
+
const host = req.headers.host || `${advertiseHost}:${port}`;
|
|
72
|
+
const proto = (req.headers['x-forwarded-proto'] as string) || advertiseProto;
|
|
73
|
+
const dynamicBase = `${proto}://${host}`;
|
|
74
|
+
res.json({
|
|
75
|
+
...agentCard,
|
|
76
|
+
url: `${dynamicBase}/a2a/jsonrpc`,
|
|
77
|
+
additionalInterfaces: [
|
|
78
|
+
{ transport: 'JSONRPC', url: `${dynamicBase}/a2a/jsonrpc` },
|
|
79
|
+
{ transport: 'REST', url: `${dynamicBase}/a2a/rest` },
|
|
80
|
+
],
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
app.get(`/${AGENT_CARD_PATH}`, serveAgentCard);
|
|
85
|
+
app.get('/.well-known/agent.json', serveAgentCard);
|
|
86
|
+
app.get('/.well-known/agent-json', serveAgentCard);
|
|
87
|
+
|
|
88
|
+
// A2A transport handlers
|
|
89
|
+
app.use('/a2a/jsonrpc', jsonRpcHandler({ requestHandler, userBuilder: UserBuilder.noAuthentication }));
|
|
90
|
+
app.use('/a2a/rest', restHandler({ requestHandler, userBuilder: UserBuilder.noAuthentication }));
|
|
91
|
+
|
|
92
|
+
// 5. Start listening
|
|
93
|
+
const httpServer = app.listen(port, hostname, () => {
|
|
94
|
+
log.info('A2A server started', { bind: hostname, port, proto: advertiseProto });
|
|
95
|
+
|
|
96
|
+
const banner = [
|
|
97
|
+
'',
|
|
98
|
+
'╔══════════════════════════════════════════════════════════════╗',
|
|
99
|
+
`║ CLI A2A Gateway — ${config.provider.padEnd(28)}║`,
|
|
100
|
+
'╠══════════════════════════════════════════════════════════════╣',
|
|
101
|
+
`║ Agent: ${agentCard.name}`,
|
|
102
|
+
`║ Bind: ${hostname}:${port}`,
|
|
103
|
+
`║ Agent Card: ${advertiseProto}://${advertiseHost}:${port}/${AGENT_CARD_PATH}`,
|
|
104
|
+
`║ JSON-RPC: ${advertiseProto}://${advertiseHost}:${port}/a2a/jsonrpc`,
|
|
105
|
+
`║ REST: ${advertiseProto}://${advertiseHost}:${port}/a2a/rest`,
|
|
106
|
+
`║ Health: ${advertiseProto}://${advertiseHost}:${port}/health`,
|
|
107
|
+
'╠══════════════════════════════════════════════════════════════╣',
|
|
108
|
+
'║ Ready. Press Ctrl+C to stop. ║',
|
|
109
|
+
'╚══════════════════════════════════════════════════════════════╝',
|
|
110
|
+
].join('\n');
|
|
111
|
+
console.log(banner);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// 6. Return handle
|
|
115
|
+
return {
|
|
116
|
+
app,
|
|
117
|
+
server: httpServer,
|
|
118
|
+
async shutdown() {
|
|
119
|
+
httpServer.close();
|
|
120
|
+
await executor.shutdown();
|
|
121
|
+
log.info('Server shut down');
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "preserve",
|
|
5
|
+
"lib": ["ES2020"],
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"rootDir": "./src",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"moduleResolution": "Bundler",
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"resolveJsonModule": true,
|
|
14
|
+
"declaration": true,
|
|
15
|
+
"declarationMap": true,
|
|
16
|
+
"types": ["node", "jest"],
|
|
17
|
+
"sourceMap": true
|
|
18
|
+
},
|
|
19
|
+
"include": ["src/**/*.ts"],
|
|
20
|
+
"exclude": ["node_modules", "dist", "__tests__"]
|
|
21
|
+
}
|