@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.
Files changed (88) hide show
  1. package/README.md +133 -87
  2. package/README.zh.md +64 -87
  3. package/cordis.patch.yml +4 -7
  4. package/lib/client.js +228 -36
  5. package/lib/index.js +1271 -625
  6. package/lib/types/api.d.ts +43 -13
  7. package/lib/types/api.d.ts.map +1 -1
  8. package/lib/types/api.js +60 -20
  9. package/lib/types/api.js.map +1 -1
  10. package/lib/types/client/index.d.ts +50 -14
  11. package/lib/types/client/index.d.ts.map +1 -1
  12. package/lib/types/commands.d.ts +4 -2
  13. package/lib/types/commands.d.ts.map +1 -1
  14. package/lib/types/commands.js +59 -46
  15. package/lib/types/commands.js.map +1 -1
  16. package/lib/types/events.d.ts +32 -9
  17. package/lib/types/events.d.ts.map +1 -1
  18. package/lib/types/index.d.ts +21 -32
  19. package/lib/types/index.d.ts.map +1 -1
  20. package/lib/types/index.js +178 -213
  21. package/lib/types/index.js.map +1 -1
  22. package/lib/types/outbound/calls.d.ts.map +1 -1
  23. package/lib/types/outbound/calls.js +8 -6
  24. package/lib/types/outbound/calls.js.map +1 -1
  25. package/lib/types/protocol.d.ts +174 -109
  26. package/lib/types/protocol.d.ts.map +1 -1
  27. package/lib/types/protocol.js +58 -34
  28. package/lib/types/protocol.js.map +1 -1
  29. package/lib/types/server/a2a-server.d.ts +7 -1
  30. package/lib/types/server/a2a-server.d.ts.map +1 -1
  31. package/lib/types/server/a2a-server.js +11 -3
  32. package/lib/types/server/a2a-server.js.map +1 -1
  33. package/lib/types/server/card.d.ts +6 -30
  34. package/lib/types/server/card.d.ts.map +1 -1
  35. package/lib/types/server/card.js +13 -49
  36. package/lib/types/server/card.js.map +1 -1
  37. package/lib/types/server/exec/agent-runtime.d.ts +3 -0
  38. package/lib/types/server/exec/agent-runtime.d.ts.map +1 -1
  39. package/lib/types/server/exec/agent-runtime.js +2 -1
  40. package/lib/types/server/exec/agent-runtime.js.map +1 -1
  41. package/lib/types/server/identity.d.ts +38 -0
  42. package/lib/types/server/identity.d.ts.map +1 -0
  43. package/lib/types/server/identity.js +89 -0
  44. package/lib/types/server/identity.js.map +1 -0
  45. package/lib/types/server/inbound-registry.d.ts +60 -0
  46. package/lib/types/server/inbound-registry.d.ts.map +1 -0
  47. package/lib/types/server/inbound-registry.js +86 -0
  48. package/lib/types/server/inbound-registry.js.map +1 -0
  49. package/lib/types/server/routes.d.ts +5 -1
  50. package/lib/types/server/routes.d.ts.map +1 -1
  51. package/lib/types/server/routes.js +9 -5
  52. package/lib/types/server/routes.js.map +1 -1
  53. package/lib/types/server/store.d.ts +37 -1
  54. package/lib/types/server/store.d.ts.map +1 -1
  55. package/lib/types/server/store.js +14 -0
  56. package/lib/types/server/store.js.map +1 -1
  57. package/lib/types/servers/inbound-manager.d.ts +131 -0
  58. package/lib/types/servers/inbound-manager.d.ts.map +1 -0
  59. package/lib/types/servers/inbound-manager.js +312 -0
  60. package/lib/types/servers/inbound-manager.js.map +1 -0
  61. package/lib/types/servers/outbound-manager.d.ts +129 -0
  62. package/lib/types/servers/outbound-manager.d.ts.map +1 -0
  63. package/lib/types/servers/outbound-manager.js +238 -0
  64. package/lib/types/servers/outbound-manager.js.map +1 -0
  65. package/lib/types/service.d.ts +108 -23
  66. package/lib/types/service.d.ts.map +1 -1
  67. package/lib/types/service.js +39 -18
  68. package/lib/types/service.js.map +1 -1
  69. package/package.json +3 -3
  70. package/src/api.ts +70 -31
  71. package/src/client/index.ts +339 -81
  72. package/src/commands.ts +59 -43
  73. package/src/events.ts +14 -7
  74. package/src/index.ts +204 -249
  75. package/src/outbound/calls.ts +8 -6
  76. package/src/protocol.ts +204 -95
  77. package/src/server/a2a-server.ts +16 -4
  78. package/src/server/card.ts +13 -62
  79. package/src/server/exec/agent-runtime.ts +5 -2
  80. package/src/server/identity.ts +109 -0
  81. package/src/server/inbound-registry.ts +129 -0
  82. package/src/server/routes.ts +6 -4
  83. package/src/server/store.ts +50 -4
  84. package/src/servers/inbound-manager.ts +385 -0
  85. package/src/servers/outbound-manager.ts +289 -0
  86. package/src/service.ts +136 -28
  87. package/lib/tsconfig.client.tsbuildinfo +0 -1
  88. 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 toggle, outbound
4
- * agent management, task view). The browser half talks only to this route;
5
- * it carries no protocol knowledge. Loopback-only by default so the
6
- * dashboard cannot be driven from the wire.
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: 'server.enable' | 'server.disable' }
19
- | { readonly action: 'agent.add'; readonly name: string; readonly agentCardUrl: string; readonly bearerTokenEnv?: string }
20
- | { readonly action: 'agent.remove' | 'agent.enable' | 'agent.disable' | 'agent.refresh'; readonly id: string }
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 server: { readonly enabled: boolean; readonly cardUrl?: string; readonly skills: readonly string[] }
28
+ readonly inbounds: readonly unknown[]
29
+ readonly outbounds: readonly unknown[]
26
30
  readonly tasks: readonly unknown[]
27
- readonly agents: readonly unknown[]
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
- server: status.server,
93
+ inbounds: status.inbounds ?? [],
94
+ outbounds: status.outbounds ?? [],
89
95
  tasks: impl.listTasks() as readonly unknown[],
90
- agents: impl.agents() as readonly unknown[],
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 'server.enable':
97
- return impl.enableServer(true)
98
- case 'server.disable':
99
- return impl.enableServer(false)
100
- case 'agent.add':
101
- return impl.addAgent({ name: payload.name, agentCardUrl: payload.agentCardUrl, ...(payload.bearerTokenEnv ? { bearerTokenEnv: payload.bearerTokenEnv } : {}) })
102
- case 'agent.remove':
103
- return impl.removeAgent(payload.id)
104
- case 'agent.enable':
105
- return impl.setAgentEnabled(payload.id, true)
106
- case 'agent.disable':
107
- return impl.setAgentEnabled(payload.id, false)
108
- case 'agent.refresh':
109
- return impl.refreshAgentCard(payload.id)
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
+ }