@hanphone/dsh-a2a 0.1.0 → 0.3.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 +133 -87
- package/README.zh.md +64 -87
- package/cordis.patch.yml +4 -7
- package/lib/client.js +228 -36
- package/lib/index.js +1271 -625
- package/lib/types/api.d.ts +43 -13
- package/lib/types/api.d.ts.map +1 -1
- package/lib/types/api.js +60 -20
- package/lib/types/api.js.map +1 -1
- package/lib/types/client/index.d.ts +50 -14
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/commands.d.ts +4 -2
- package/lib/types/commands.d.ts.map +1 -1
- package/lib/types/commands.js +59 -46
- package/lib/types/commands.js.map +1 -1
- package/lib/types/events.d.ts +32 -9
- package/lib/types/events.d.ts.map +1 -1
- package/lib/types/index.d.ts +21 -32
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +178 -213
- package/lib/types/index.js.map +1 -1
- package/lib/types/outbound/calls.d.ts.map +1 -1
- package/lib/types/outbound/calls.js +8 -6
- package/lib/types/outbound/calls.js.map +1 -1
- package/lib/types/protocol.d.ts +174 -109
- package/lib/types/protocol.d.ts.map +1 -1
- package/lib/types/protocol.js +58 -34
- package/lib/types/protocol.js.map +1 -1
- package/lib/types/server/a2a-server.d.ts +7 -1
- package/lib/types/server/a2a-server.d.ts.map +1 -1
- package/lib/types/server/a2a-server.js +11 -3
- package/lib/types/server/a2a-server.js.map +1 -1
- package/lib/types/server/card.d.ts +6 -30
- package/lib/types/server/card.d.ts.map +1 -1
- package/lib/types/server/card.js +13 -49
- package/lib/types/server/card.js.map +1 -1
- package/lib/types/server/exec/agent-runtime.d.ts +3 -0
- package/lib/types/server/exec/agent-runtime.d.ts.map +1 -1
- package/lib/types/server/exec/agent-runtime.js +2 -1
- package/lib/types/server/exec/agent-runtime.js.map +1 -1
- package/lib/types/server/identity.d.ts +38 -0
- package/lib/types/server/identity.d.ts.map +1 -0
- package/lib/types/server/identity.js +89 -0
- package/lib/types/server/identity.js.map +1 -0
- package/lib/types/server/inbound-registry.d.ts +60 -0
- package/lib/types/server/inbound-registry.d.ts.map +1 -0
- package/lib/types/server/inbound-registry.js +86 -0
- package/lib/types/server/inbound-registry.js.map +1 -0
- package/lib/types/server/routes.d.ts +5 -1
- package/lib/types/server/routes.d.ts.map +1 -1
- package/lib/types/server/routes.js +9 -5
- package/lib/types/server/routes.js.map +1 -1
- package/lib/types/server/store.d.ts +37 -1
- package/lib/types/server/store.d.ts.map +1 -1
- package/lib/types/server/store.js +14 -0
- package/lib/types/server/store.js.map +1 -1
- package/lib/types/servers/inbound-manager.d.ts +131 -0
- package/lib/types/servers/inbound-manager.d.ts.map +1 -0
- package/lib/types/servers/inbound-manager.js +312 -0
- package/lib/types/servers/inbound-manager.js.map +1 -0
- package/lib/types/servers/outbound-manager.d.ts +129 -0
- package/lib/types/servers/outbound-manager.d.ts.map +1 -0
- package/lib/types/servers/outbound-manager.js +238 -0
- package/lib/types/servers/outbound-manager.js.map +1 -0
- package/lib/types/service.d.ts +108 -23
- package/lib/types/service.d.ts.map +1 -1
- package/lib/types/service.js +39 -18
- package/lib/types/service.js.map +1 -1
- package/package.json +3 -3
- package/src/api.ts +70 -31
- package/src/client/index.ts +339 -81
- package/src/commands.ts +59 -43
- package/src/events.ts +14 -7
- package/src/index.ts +204 -249
- package/src/outbound/calls.ts +8 -6
- package/src/protocol.ts +204 -95
- package/src/server/a2a-server.ts +16 -4
- package/src/server/card.ts +13 -62
- package/src/server/exec/agent-runtime.ts +5 -2
- package/src/server/identity.ts +109 -0
- package/src/server/inbound-registry.ts +129 -0
- package/src/server/routes.ts +6 -4
- package/src/server/store.ts +50 -4
- package/src/servers/inbound-manager.ts +385 -0
- package/src/servers/outbound-manager.ts +289 -0
- package/src/service.ts +136 -28
- package/lib/tsconfig.client.tsbuildinfo +0 -1
- package/lib/tsconfig.tsbuildinfo +0 -1
package/src/api.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* GUI control API for the A2A settings dashboard: one `GET /a2a/api`
|
|
3
|
-
* snapshot plus `POST /a2a/api` control actions (server
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* snapshot plus `POST /a2a/api` control actions (inbound/outbound server
|
|
4
|
+
* CRUD + enable/disable, task view/cancel) and `GET /a2a/api/presets` for the
|
|
5
|
+
* preset roster the pickers need. The browser half talks only to this route;
|
|
6
|
+
* it carries no protocol knowledge. Loopback-only by default so the dashboard
|
|
7
|
+
* cannot be driven from the wire.
|
|
7
8
|
*
|
|
8
9
|
* The route body is bound to the same `A2AServiceImpl` facade the `/a2a`
|
|
9
10
|
* command surface uses, so GUI actions and commands cannot disagree.
|
|
@@ -15,16 +16,19 @@ import type { A2AServiceImpl } from './service.ts'
|
|
|
15
16
|
|
|
16
17
|
/** Control actions the dashboard can issue. */
|
|
17
18
|
export type ApiAction =
|
|
18
|
-
| { readonly action: '
|
|
19
|
-
| { readonly action: '
|
|
20
|
-
| { readonly action: '
|
|
19
|
+
| { readonly action: 'inbound.create'; readonly name: string; readonly description: string; readonly version: string; readonly endpointPath?: string; readonly preset?: string; readonly authTokenEnv?: string; readonly skills?: readonly { id: string; name: string; description?: string }[]; readonly enabled?: boolean }
|
|
20
|
+
| { readonly action: 'inbound.remove' | 'inbound.enable' | 'inbound.disable' | 'inbound.update'; readonly id: string; readonly name?: string; readonly description?: string; readonly version?: string; readonly endpointPath?: string; readonly preset?: string; readonly authTokenEnv?: string; readonly skills?: readonly { id: string; name: string; description?: string }[] }
|
|
21
|
+
| { readonly action: 'outbound.create'; readonly name: string; readonly agentCardUrl: string; readonly bearerTokenEnv?: string; readonly preset?: string; readonly enabled?: boolean; readonly timeoutMs?: number }
|
|
22
|
+
| { readonly action: 'outbound.remove' | 'outbound.enable' | 'outbound.disable' | 'outbound.refresh'; readonly id: string }
|
|
21
23
|
| { readonly action: 'task.cancel'; readonly id: string }
|
|
24
|
+
| { readonly action: 'inbound.close'; readonly id: string }
|
|
22
25
|
|
|
23
26
|
/** One snapshot of the whole plugin for the dashboard. */
|
|
24
27
|
export interface ApiSnapshot {
|
|
25
|
-
readonly
|
|
28
|
+
readonly inbounds: readonly unknown[]
|
|
29
|
+
readonly outbounds: readonly unknown[]
|
|
26
30
|
readonly tasks: readonly unknown[]
|
|
27
|
-
readonly
|
|
31
|
+
readonly peers: readonly unknown[]
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
function readBody(req: IncomingMessage): Promise<string> {
|
|
@@ -58,6 +62,11 @@ export async function handleApiRequest(
|
|
|
58
62
|
res.end('forbidden')
|
|
59
63
|
return
|
|
60
64
|
}
|
|
65
|
+
const path = (req.url ?? '').split('?')[0] ?? ''
|
|
66
|
+
if (req.method === 'GET' && path === '/a2a/api/presets') {
|
|
67
|
+
json(res, 200, await impl.presets())
|
|
68
|
+
return
|
|
69
|
+
}
|
|
61
70
|
if (req.method === 'GET') {
|
|
62
71
|
json(res, 200, snapshotOf(impl))
|
|
63
72
|
return
|
|
@@ -79,37 +88,67 @@ export async function handleApiRequest(
|
|
|
79
88
|
}
|
|
80
89
|
|
|
81
90
|
function snapshotOf(impl: A2AServiceImpl): ApiSnapshot {
|
|
82
|
-
const status = impl.status() as {
|
|
83
|
-
server: { enabled: boolean; cardUrl?: string; skills: readonly string[] }
|
|
84
|
-
tasks: number
|
|
85
|
-
agents: readonly unknown[]
|
|
86
|
-
}
|
|
91
|
+
const status = impl.status() as { inbounds: readonly unknown[]; outbounds: readonly unknown[]; tasks: number; peers?: readonly unknown[] }
|
|
87
92
|
return {
|
|
88
|
-
|
|
93
|
+
inbounds: status.inbounds ?? [],
|
|
94
|
+
outbounds: status.outbounds ?? [],
|
|
89
95
|
tasks: impl.listTasks() as readonly unknown[],
|
|
90
|
-
|
|
96
|
+
// `status()` may already carry aggregated peers; fall back to the facade.
|
|
97
|
+
peers: (status.peers ?? impl.inbounds()) as readonly unknown[],
|
|
91
98
|
}
|
|
92
99
|
}
|
|
93
100
|
|
|
94
101
|
async function dispatch(payload: ApiAction, impl: A2AServiceImpl): Promise<{ readonly ok: boolean; readonly message: string }> {
|
|
95
102
|
switch (payload.action) {
|
|
96
|
-
case '
|
|
97
|
-
return impl.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
103
|
+
case 'inbound.create':
|
|
104
|
+
return impl.createInboundServer({
|
|
105
|
+
name: payload.name,
|
|
106
|
+
description: payload.description,
|
|
107
|
+
version: payload.version,
|
|
108
|
+
...(payload.endpointPath !== undefined ? { endpointPath: payload.endpointPath } : {}),
|
|
109
|
+
...(payload.preset !== undefined ? { preset: payload.preset } : {}),
|
|
110
|
+
...(payload.authTokenEnv !== undefined ? { authTokenEnv: payload.authTokenEnv } : {}),
|
|
111
|
+
...(payload.skills !== undefined ? { skills: payload.skills } : {}),
|
|
112
|
+
...(payload.enabled !== undefined ? { enabled: payload.enabled } : {}),
|
|
113
|
+
})
|
|
114
|
+
case 'inbound.remove':
|
|
115
|
+
return impl.removeInboundServer(payload.id)
|
|
116
|
+
case 'inbound.enable':
|
|
117
|
+
return impl.setInboundServerEnabled(payload.id, true)
|
|
118
|
+
case 'inbound.disable':
|
|
119
|
+
return impl.setInboundServerEnabled(payload.id, false)
|
|
120
|
+
case 'inbound.update':
|
|
121
|
+
return impl.updateInboundServer(payload.id, {
|
|
122
|
+
...(payload.name !== undefined ? { name: payload.name } : {}),
|
|
123
|
+
...(payload.description !== undefined ? { description: payload.description } : {}),
|
|
124
|
+
...(payload.version !== undefined ? { version: payload.version } : {}),
|
|
125
|
+
...(payload.endpointPath !== undefined ? { endpointPath: payload.endpointPath } : {}),
|
|
126
|
+
...(payload.preset !== undefined ? { preset: payload.preset } : {}),
|
|
127
|
+
...(payload.authTokenEnv !== undefined ? { authTokenEnv: payload.authTokenEnv } : {}),
|
|
128
|
+
...(payload.skills !== undefined ? { skills: payload.skills } : {}),
|
|
129
|
+
})
|
|
130
|
+
case 'outbound.create':
|
|
131
|
+
return impl.createOutboundServer({
|
|
132
|
+
name: payload.name,
|
|
133
|
+
agentCardUrl: payload.agentCardUrl,
|
|
134
|
+
...(payload.bearerTokenEnv !== undefined ? { bearerTokenEnv: payload.bearerTokenEnv } : {}),
|
|
135
|
+
...(payload.preset !== undefined ? { preset: payload.preset } : {}),
|
|
136
|
+
...(payload.enabled !== undefined ? { enabled: payload.enabled } : {}),
|
|
137
|
+
...(payload.timeoutMs !== undefined ? { timeoutMs: payload.timeoutMs } : {}),
|
|
138
|
+
})
|
|
139
|
+
case 'outbound.remove':
|
|
140
|
+
return impl.removeOutboundServer(payload.id)
|
|
141
|
+
case 'outbound.enable':
|
|
142
|
+
return impl.setOutboundServerEnabled(payload.id, true)
|
|
143
|
+
case 'outbound.disable':
|
|
144
|
+
return impl.setOutboundServerEnabled(payload.id, false)
|
|
145
|
+
case 'outbound.refresh':
|
|
146
|
+
return impl.refreshOutboundServer(payload.id)
|
|
110
147
|
case 'task.cancel':
|
|
111
148
|
return impl.cancelTask(payload.id)
|
|
149
|
+
case 'inbound.close':
|
|
150
|
+
return impl.closeInbound(payload.id)
|
|
112
151
|
default:
|
|
113
152
|
return { ok: false, message: `unknown action ${String((payload as { action?: unknown }).action)}` }
|
|
114
153
|
}
|
|
115
|
-
}
|
|
154
|
+
}
|