@hanphone/dsh-a2a 0.2.0 → 0.3.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/README.md +106 -106
- package/README.zh.md +50 -74
- package/cordis.patch.yml +4 -7
- package/lib/client.js +186 -73
- package/lib/index.js +1275 -868
- package/lib/types/api.d.ts +30 -23
- package/lib/types/api.d.ts.map +1 -1
- package/lib/types/api.js +56 -23
- package/lib/types/api.js.map +1 -1
- package/lib/types/client/index.d.ts +50 -19
- 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 +177 -272
- 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 +4 -0
- package/lib/types/server/a2a-server.d.ts.map +1 -1
- package/lib/types/server/a2a-server.js +6 -2
- 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 +20 -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/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 +32 -0
- package/lib/types/server/store.d.ts.map +1 -1
- package/lib/types/server/store.js +10 -0
- package/lib/types/server/store.js.map +1 -1
- package/lib/types/servers/inbound-manager.d.ts +154 -0
- package/lib/types/servers/inbound-manager.d.ts.map +1 -0
- package/lib/types/servers/inbound-manager.js +335 -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 +104 -40
- package/lib/types/service.d.ts.map +1 -1
- package/lib/types/service.js +36 -27
- package/lib/types/service.js.map +1 -1
- package/package.json +2 -2
- package/src/api.ts +65 -53
- package/src/client/index.ts +272 -148
- package/src/commands.ts +59 -43
- package/src/events.ts +14 -7
- package/src/index.ts +203 -310
- package/src/outbound/calls.ts +8 -6
- package/src/protocol.ts +204 -95
- package/src/server/a2a-server.ts +9 -2
- package/src/server/card.ts +13 -62
- package/src/server/exec/agent-runtime.ts +20 -2
- package/src/server/routes.ts +6 -4
- package/src/server/store.ts +42 -3
- package/src/servers/inbound-manager.ts +416 -0
- package/src/servers/outbound-manager.ts +289 -0
- package/src/service.ts +125 -40
- 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,27 +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 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 }
|
|
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 }
|
|
22
|
-
| { readonly action: 'identity.update'; readonly name?: string; readonly description?: string; readonly version?: string }
|
|
23
24
|
| { readonly action: 'inbound.close'; readonly id: string }
|
|
24
25
|
|
|
25
26
|
/** One snapshot of the whole plugin for the dashboard. */
|
|
26
27
|
export interface ApiSnapshot {
|
|
27
|
-
readonly server: {
|
|
28
|
-
readonly enabled: boolean
|
|
29
|
-
readonly cardUrl?: string
|
|
30
|
-
readonly skills: readonly string[]
|
|
31
|
-
readonly name?: string
|
|
32
|
-
readonly description?: string
|
|
33
|
-
readonly version?: string
|
|
34
|
-
readonly configured: boolean
|
|
35
|
-
}
|
|
36
|
-
readonly tasks: readonly unknown[]
|
|
37
|
-
readonly agents: readonly unknown[]
|
|
38
28
|
readonly inbounds: readonly unknown[]
|
|
29
|
+
readonly outbounds: readonly unknown[]
|
|
30
|
+
readonly tasks: readonly unknown[]
|
|
31
|
+
readonly peers: readonly unknown[]
|
|
39
32
|
}
|
|
40
33
|
|
|
41
34
|
function readBody(req: IncomingMessage): Promise<string> {
|
|
@@ -69,6 +62,11 @@ export async function handleApiRequest(
|
|
|
69
62
|
res.end('forbidden')
|
|
70
63
|
return
|
|
71
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
|
+
}
|
|
72
70
|
if (req.method === 'GET') {
|
|
73
71
|
json(res, 200, snapshotOf(impl))
|
|
74
72
|
return
|
|
@@ -90,51 +88,65 @@ export async function handleApiRequest(
|
|
|
90
88
|
}
|
|
91
89
|
|
|
92
90
|
function snapshotOf(impl: A2AServiceImpl): ApiSnapshot {
|
|
93
|
-
const status = impl.status() as {
|
|
94
|
-
server: {
|
|
95
|
-
enabled: boolean
|
|
96
|
-
cardUrl?: string
|
|
97
|
-
skills: readonly string[]
|
|
98
|
-
name?: string
|
|
99
|
-
description?: string
|
|
100
|
-
version?: string
|
|
101
|
-
configured: boolean
|
|
102
|
-
}
|
|
103
|
-
tasks: number
|
|
104
|
-
agents: readonly unknown[]
|
|
105
|
-
inbounds: readonly unknown[]
|
|
106
|
-
}
|
|
91
|
+
const status = impl.status() as { inbounds: readonly unknown[]; outbounds: readonly unknown[]; tasks: number; peers?: readonly unknown[] }
|
|
107
92
|
return {
|
|
108
|
-
server: status.server,
|
|
109
|
-
tasks: impl.listTasks() as readonly unknown[],
|
|
110
|
-
agents: impl.agents() as readonly unknown[],
|
|
111
93
|
inbounds: status.inbounds ?? [],
|
|
94
|
+
outbounds: status.outbounds ?? [],
|
|
95
|
+
tasks: impl.listTasks() as readonly unknown[],
|
|
96
|
+
// `status()` may already carry aggregated peers; fall back to the facade.
|
|
97
|
+
peers: (status.peers ?? impl.inbounds()) as readonly unknown[],
|
|
112
98
|
}
|
|
113
99
|
}
|
|
114
100
|
|
|
115
101
|
async function dispatch(payload: ApiAction, impl: A2AServiceImpl): Promise<{ readonly ok: boolean; readonly message: string }> {
|
|
116
102
|
switch (payload.action) {
|
|
117
|
-
case '
|
|
118
|
-
return impl.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
case '
|
|
128
|
-
return impl.
|
|
129
|
-
case '
|
|
130
|
-
return impl.
|
|
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.enabled !== undefined ? { enabled: payload.enabled } : {}),
|
|
112
|
+
})
|
|
113
|
+
case 'inbound.remove':
|
|
114
|
+
return impl.removeInboundServer(payload.id)
|
|
115
|
+
case 'inbound.enable':
|
|
116
|
+
return impl.setInboundServerEnabled(payload.id, true)
|
|
117
|
+
case 'inbound.disable':
|
|
118
|
+
return impl.setInboundServerEnabled(payload.id, false)
|
|
119
|
+
case 'inbound.update':
|
|
120
|
+
return impl.updateInboundServer(payload.id, {
|
|
121
|
+
...(payload.name !== undefined ? { name: payload.name } : {}),
|
|
122
|
+
...(payload.description !== undefined ? { description: payload.description } : {}),
|
|
123
|
+
...(payload.version !== undefined ? { version: payload.version } : {}),
|
|
124
|
+
...(payload.endpointPath !== undefined ? { endpointPath: payload.endpointPath } : {}),
|
|
125
|
+
...(payload.preset !== undefined ? { preset: payload.preset } : {}),
|
|
126
|
+
...(payload.authTokenEnv !== undefined ? { authTokenEnv: payload.authTokenEnv } : {}),
|
|
127
|
+
})
|
|
128
|
+
case 'outbound.create':
|
|
129
|
+
return impl.createOutboundServer({
|
|
130
|
+
name: payload.name,
|
|
131
|
+
agentCardUrl: payload.agentCardUrl,
|
|
132
|
+
...(payload.bearerTokenEnv !== undefined ? { bearerTokenEnv: payload.bearerTokenEnv } : {}),
|
|
133
|
+
...(payload.preset !== undefined ? { preset: payload.preset } : {}),
|
|
134
|
+
...(payload.enabled !== undefined ? { enabled: payload.enabled } : {}),
|
|
135
|
+
...(payload.timeoutMs !== undefined ? { timeoutMs: payload.timeoutMs } : {}),
|
|
136
|
+
})
|
|
137
|
+
case 'outbound.remove':
|
|
138
|
+
return impl.removeOutboundServer(payload.id)
|
|
139
|
+
case 'outbound.enable':
|
|
140
|
+
return impl.setOutboundServerEnabled(payload.id, true)
|
|
141
|
+
case 'outbound.disable':
|
|
142
|
+
return impl.setOutboundServerEnabled(payload.id, false)
|
|
143
|
+
case 'outbound.refresh':
|
|
144
|
+
return impl.refreshOutboundServer(payload.id)
|
|
131
145
|
case 'task.cancel':
|
|
132
146
|
return impl.cancelTask(payload.id)
|
|
133
|
-
case 'identity.update':
|
|
134
|
-
return impl.updateIdentity({ ...(payload.name !== undefined ? { name: payload.name } : {}), ...(payload.description !== undefined ? { description: payload.description } : {}), ...(payload.version !== undefined ? { version: payload.version } : {}) })
|
|
135
147
|
case 'inbound.close':
|
|
136
148
|
return impl.closeInbound(payload.id)
|
|
137
149
|
default:
|
|
138
150
|
return { ok: false, message: `unknown action ${String((payload as { action?: unknown }).action)}` }
|
|
139
151
|
}
|
|
140
|
-
}
|
|
152
|
+
}
|