@axiom-lattice/gateway 8.4.0 → 10.0.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 (64) hide show
  1. package/dist/{a2a-TDZ3TT6H.mjs → a2a-YLKZE5JG.mjs} +6 -4
  2. package/dist/{a2a-standard-INVCUSAW.mjs → a2a-standard-NOAVPYXJ.mjs} +42 -127
  3. package/dist/a2a-standard-NOAVPYXJ.mjs.map +1 -0
  4. package/dist/chunk-NYYSBNDG.mjs +575 -0
  5. package/dist/chunk-NYYSBNDG.mjs.map +1 -0
  6. package/dist/{chunk-2SR4F3ZD.mjs → chunk-PHWGCRW2.mjs} +2 -1
  7. package/dist/{chunk-2SR4F3ZD.mjs.map → chunk-PHWGCRW2.mjs.map} +1 -1
  8. package/dist/{chunk-W3YH4S6G.mjs → chunk-SIMEG2JT.mjs} +19 -2
  9. package/dist/chunk-SIMEG2JT.mjs.map +1 -0
  10. package/dist/embed/{embed-page-AgentDetailSideApp-TQEJK6ZF.js → embed-page-AgentDetailSideApp-X5HKDN3N.js} +1 -1
  11. package/dist/embed/embed-page-AgentGovernanceWorkbench-MFXL7BOW.js +1 -0
  12. package/dist/embed/{embed-page-LangfuseDashboard-7OANGQXY.js → embed-page-LangfuseDashboard-NPYFMKK3.js} +1 -1
  13. package/dist/embed/{embed-page-MessageGraph-KJPQWTHE.js → embed-page-MessageGraph-JUCEXYLU.js} +1 -1
  14. package/dist/embed/{embed-page-ReactChart-2CAIM4JD.js → embed-page-ReactChart-2QJ3QRBH.js} +1 -1
  15. package/dist/embed/{embed-page-SkillFlow-243MXRXC.js → embed-page-SkillFlow-PFEXQ75Z.js} +1 -1
  16. package/dist/embed/{embed-page-TasksSideApp-OA7CULHS.js → embed-page-TasksSideApp-SBHVHNVT.js} +1 -1
  17. package/dist/embed/{embed-page-ThreadMaintenancePanel-Z4424X3J.js → embed-page-ThreadMaintenancePanel-LCCRUA75.js} +1 -1
  18. package/dist/embed/{embed-page-TopologyRuntimeView-THTCZUS7.js → embed-page-TopologyRuntimeView-ATA23XXF.js} +1 -1
  19. package/dist/embed/embed-page-WorkflowAutomationView-OVGOUVXH.js +3 -0
  20. package/dist/embed/embed-page-chunk-7F5BSMP3.js +211 -0
  21. package/dist/embed/embed-page-chunk-HLBQ5JKL.js +6968 -0
  22. package/dist/embed/{embed-page-chunk-RKQJBKN2.js → embed-page-chunk-HUH33Z2E.js} +1 -1
  23. package/dist/embed/embed-page-chunk-LZ4ITV3M.js +242 -0
  24. package/dist/embed/{embed-page-chunk-LDQGH44H.js → embed-page-chunk-ODTY6SE7.js} +1 -1
  25. package/dist/embed/embed-page-chunk-Q7Z7MHOM.js +76 -0
  26. package/dist/embed/embed-page-chunk-QOPHOXA7.js +3 -0
  27. package/dist/embed/{embed-page-chunk-FZX4A32D.js → embed-page-chunk-RFF7S4H5.js} +5 -5
  28. package/dist/embed/{embed-page-chunk-L2EGVVJS.js → embed-page-chunk-VNRFN74K.js} +1 -1
  29. package/dist/embed/{embed-page-chunk-JMP7EQEF.js → embed-page-chunk-WE6PZS2N.js} +1 -1
  30. package/dist/embed/{embed-page-en-DNDGCPMA.js → embed-page-en-4HTY4XK4.js} +1 -1
  31. package/dist/embed/embed-page-en-KZQZS4JN.js +1 -0
  32. package/dist/embed/embed-page-en-VHD2WUUG.js +1 -0
  33. package/dist/embed/embed-page-zh-A7DSGF6P.js +1 -0
  34. package/dist/embed/embed-page-zh-KSZOJPOV.js +1 -0
  35. package/dist/embed/{embed-page-zh-2H4EB3F3.js → embed-page-zh-UHTZEW5G.js} +1 -1
  36. package/dist/embed/embed-page.js +1 -1
  37. package/dist/embed/mcp-app-page.js +76 -15
  38. package/dist/index.js +1699 -1498
  39. package/dist/index.js.map +1 -1
  40. package/dist/index.mjs +241 -382
  41. package/dist/index.mjs.map +1 -1
  42. package/dist/{open-27ZPLBIW.mjs → open-PCOORPQ5.mjs} +63 -16
  43. package/dist/open-PCOORPQ5.mjs.map +1 -0
  44. package/dist/{open-exposure-BPLYUIX6.mjs → open-exposure-HGYT5VFC.mjs} +5 -6
  45. package/dist/open-exposure-HGYT5VFC.mjs.map +1 -0
  46. package/package.json +18 -13
  47. package/dist/a2a-standard-INVCUSAW.mjs.map +0 -1
  48. package/dist/chunk-OBODBHIS.mjs +0 -230
  49. package/dist/chunk-OBODBHIS.mjs.map +0 -1
  50. package/dist/chunk-W3YH4S6G.mjs.map +0 -1
  51. package/dist/embed/embed-page-AgentGovernanceWorkbench-II2MRGCG.js +0 -1
  52. package/dist/embed/embed-page-WorkflowAutomationView-YDIDG35E.js +0 -3
  53. package/dist/embed/embed-page-chunk-7ULTMRM2.js +0 -211
  54. package/dist/embed/embed-page-chunk-OMN6G52V.js +0 -3
  55. package/dist/embed/embed-page-chunk-VYS3TAK4.js +0 -242
  56. package/dist/embed/embed-page-chunk-W5OP2CZG.js +0 -15
  57. package/dist/embed/embed-page-chunk-Z6KWW64I.js +0 -6837
  58. package/dist/embed/embed-page-en-D4M3DPFT.js +0 -1
  59. package/dist/embed/embed-page-en-JOTELYAL.js +0 -1
  60. package/dist/embed/embed-page-zh-BPO6ZSJM.js +0 -1
  61. package/dist/embed/embed-page-zh-NEXLMDHF.js +0 -1
  62. package/dist/open-27ZPLBIW.mjs.map +0 -1
  63. package/dist/open-exposure-BPLYUIX6.mjs.map +0 -1
  64. /package/dist/{a2a-TDZ3TT6H.mjs.map → a2a-YLKZE5JG.mjs.map} +0 -0
@@ -1,230 +0,0 @@
1
- import {
2
- A2AAuthError
3
- } from "./chunk-LCM4OQTI.mjs";
4
-
5
- // src/routes/a2a.ts
6
- import { getStoreLattice, getReplicaId } from "@axiom-lattice/core";
7
-
8
- // src/services/a2aKeySync.ts
9
- var A2A_KEY_CHANGED_TOPIC = "a2a-key-changed";
10
- async function publishA2AKeyChanged(outbox, owner, tenantId) {
11
- if (!tenantId) return;
12
- try {
13
- await outbox.append({
14
- topic: A2A_KEY_CHANGED_TOPIC,
15
- payload: { tenantId },
16
- originReplicaId: owner
17
- });
18
- } catch {
19
- }
20
- }
21
- async function handleA2AKeyChanged(payload, reload) {
22
- const tenantId = payload?.tenantId;
23
- if (typeof tenantId !== "string" || tenantId.length === 0) return;
24
- await reload();
25
- }
26
-
27
- // src/routes/a2a.ts
28
- var _a2aKeyStore = null;
29
- var _a2aAuthService = null;
30
- function setA2AKeyStore(store) {
31
- _a2aKeyStore = store;
32
- }
33
- function setA2AAuthService(service) {
34
- _a2aAuthService = service;
35
- }
36
- async function refreshStoreKeyMap() {
37
- if (_a2aAuthService) await _a2aAuthService.refresh();
38
- }
39
- function broadcastA2AKeyChanged(tenantId) {
40
- if (!tenantId) return;
41
- try {
42
- const outbox = getStoreLattice("default", "outbox").store;
43
- void publishA2AKeyChanged(outbox, getReplicaId(), tenantId);
44
- } catch {
45
- }
46
- }
47
- async function requireTenantSession(request, reply) {
48
- if (!getUserTenantId(request)) {
49
- await reply.status(401).send({ success: false, error: "Unauthorized" });
50
- }
51
- }
52
- async function authorizeKeyMutation(request, reply) {
53
- if (!_a2aKeyStore) {
54
- await reply.status(501).send({ error: "Key store not configured" });
55
- return null;
56
- }
57
- const record = await _a2aKeyStore.findById(request.params.id);
58
- if (!record) {
59
- await reply.status(404).send({ success: false, error: "A2A API key not found" });
60
- return null;
61
- }
62
- if (record.tenantId !== getUserTenantId(request)) {
63
- await reply.status(403).send({ success: false, error: "Forbidden" });
64
- return null;
65
- }
66
- return record;
67
- }
68
- function getUserTenantId(request) {
69
- return request.user?.tenantId;
70
- }
71
- async function handleApiKeyList(request, reply) {
72
- if (!_a2aKeyStore) {
73
- reply.status(501).send({ error: "Key store not configured" });
74
- return;
75
- }
76
- const records = await _a2aKeyStore.list({
77
- tenantId: getUserTenantId(request),
78
- limit: request.query.limit ? parseInt(request.query.limit, 10) : void 0,
79
- offset: request.query.offset ? parseInt(request.query.offset, 10) : void 0
80
- });
81
- reply.status(200).send({
82
- success: true,
83
- data: {
84
- records: records.map((r) => ({ ...r, key: r.key.slice(0, 8) + "..." })),
85
- total: records.length
86
- }
87
- });
88
- }
89
- async function handleApiKeyCreate(request, reply) {
90
- if (!_a2aKeyStore || !_a2aAuthService) {
91
- reply.status(501).send({ error: "Key store not configured" });
92
- return;
93
- }
94
- const body = request.body;
95
- const tenantId = getUserTenantId(request);
96
- try {
97
- const record = await _a2aAuthService.createKeyScoped({
98
- tenantId,
99
- projectId: body.projectId,
100
- assistantIds: body.assistantIds,
101
- grants: body.grants,
102
- label: body.label
103
- });
104
- await refreshStoreKeyMap();
105
- broadcastA2AKeyChanged(tenantId);
106
- reply.status(201).send({ success: true, data: record });
107
- } catch (err) {
108
- if (err instanceof A2AAuthError) {
109
- reply.status(err.statusCode).send({ success: false, error: err.message });
110
- return;
111
- }
112
- request.log.error({ err }, "a2a:keys:create");
113
- reply.status(500).send({ success: false, error: "Failed to create key" });
114
- }
115
- }
116
- async function handleApiKeyUpdate(request, reply) {
117
- if (!_a2aKeyStore || !_a2aAuthService) {
118
- reply.status(501).send({ error: "Key store not configured" });
119
- return;
120
- }
121
- if (!await authorizeKeyMutation(request, reply)) return;
122
- const body = request.body;
123
- const tenantId = getUserTenantId(request);
124
- try {
125
- const record = await _a2aAuthService.updateKeyScoped(
126
- request.params.id,
127
- tenantId,
128
- {
129
- label: body.label,
130
- projectId: body.projectId,
131
- assistantIds: body.assistantIds,
132
- grants: body.grants
133
- }
134
- );
135
- await refreshStoreKeyMap();
136
- broadcastA2AKeyChanged(tenantId);
137
- reply.status(200).send({ success: true, data: record });
138
- } catch (err) {
139
- if (err instanceof A2AAuthError) {
140
- reply.status(err.statusCode).send({ success: false, error: err.message });
141
- return;
142
- }
143
- request.log.error({ err }, "a2a:keys:update");
144
- reply.status(500).send({ success: false, error: "Failed to update key" });
145
- }
146
- }
147
- async function handleApiKeyDelete(request, reply) {
148
- const record = await authorizeKeyMutation(request, reply);
149
- if (!record) return;
150
- await _a2aKeyStore.delete(request.params.id);
151
- await refreshStoreKeyMap();
152
- broadcastA2AKeyChanged(record.tenantId);
153
- reply.status(200).send({ success: true });
154
- }
155
- async function handleApiKeyDisable(request, reply) {
156
- const record = await authorizeKeyMutation(request, reply);
157
- if (!record) return;
158
- await _a2aKeyStore.disable(request.params.id);
159
- await refreshStoreKeyMap();
160
- broadcastA2AKeyChanged(record.tenantId);
161
- reply.status(200).send({ success: true });
162
- }
163
- async function handleApiKeyEnable(request, reply) {
164
- const record = await authorizeKeyMutation(request, reply);
165
- if (!record) return;
166
- await _a2aKeyStore.enable(request.params.id);
167
- await refreshStoreKeyMap();
168
- broadcastA2AKeyChanged(record.tenantId);
169
- reply.status(200).send({ success: true });
170
- }
171
- async function handleApiKeyRotate(request, reply) {
172
- const record = await authorizeKeyMutation(request, reply);
173
- if (!record) return;
174
- const rotated = await _a2aKeyStore.rotate(request.params.id);
175
- await refreshStoreKeyMap();
176
- broadcastA2AKeyChanged(record.tenantId);
177
- reply.status(200).send({ success: true, data: rotated });
178
- }
179
- function registerA2ARoutes(app) {
180
- const options = { preHandler: requireTenantSession };
181
- for (const base of ["/api/keys", "/api/a2a/keys"]) {
182
- app.get(
183
- base,
184
- options,
185
- handleApiKeyList
186
- );
187
- app.post(
188
- base,
189
- options,
190
- handleApiKeyCreate
191
- );
192
- app.delete(
193
- `${base}/:id`,
194
- options,
195
- handleApiKeyDelete
196
- );
197
- app.post(
198
- `${base}/:id/disable`,
199
- options,
200
- handleApiKeyDisable
201
- );
202
- app.post(
203
- `${base}/:id/enable`,
204
- options,
205
- handleApiKeyEnable
206
- );
207
- app.post(
208
- `${base}/:id/rotate`,
209
- options,
210
- handleApiKeyRotate
211
- );
212
- app.patch(
213
- `${base}/:id`,
214
- options,
215
- handleApiKeyUpdate
216
- );
217
- }
218
- }
219
-
220
- export {
221
- A2A_KEY_CHANGED_TOPIC,
222
- publishA2AKeyChanged,
223
- handleA2AKeyChanged,
224
- setA2AKeyStore,
225
- setA2AAuthService,
226
- refreshStoreKeyMap,
227
- broadcastA2AKeyChanged,
228
- registerA2ARoutes
229
- };
230
- //# sourceMappingURL=chunk-OBODBHIS.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/routes/a2a.ts","../src/services/a2aKeySync.ts"],"sourcesContent":["import type { FastifyInstance, FastifyRequest, FastifyReply } from \"fastify\";\nimport type {\n A2AApiKeyRecord,\n A2AApiKeyStore,\n CreateA2AApiKeyInput,\n OutboxStore,\n} from \"@axiom-lattice/protocols\";\nimport { getStoreLattice, getReplicaId } from \"@axiom-lattice/core\";\nimport { A2AAuthError } from \"../services/a2a/A2AAuthService\";\nimport type { A2AAuthService } from \"../services/a2a/A2AAuthService\";\nimport { publishA2AKeyChanged } from \"../services/a2aKeySync\";\n\n// ─── Key Store ────────────────────────────────────────────────────────────\n\nlet _a2aKeyStore: A2AApiKeyStore | null = null;\nlet _a2aAuthService: A2AAuthService | null = null;\n\n/** Inject the A2A key store used by the keys management routes. */\nexport function setA2AKeyStore(store: A2AApiKeyStore): void {\n _a2aKeyStore = store;\n}\n\n/** Inject the A2A auth service used to create keys and refresh the key cache. */\nexport function setA2AAuthService(service: A2AAuthService): void {\n _a2aAuthService = service;\n}\n\n/**\n * Reload cached key maps after a keys CRUD mutation. Delegates to the auth\n * service's key-map cache so authentication reflects the latest keys without\n * hitting the store on every request.\n */\nexport async function refreshStoreKeyMap(): Promise<void> {\n if (_a2aAuthService) await _a2aAuthService.refresh();\n}\n\n/**\n * Best-effort broadcast of an A2A key change so peer replicas reload their key map.\n *\n * @param tenantId Tenant whose keys changed.\n * @remarks Fire-and-forget; never affects the request outcome.\n */\nexport function broadcastA2AKeyChanged(tenantId: string | undefined): void {\n if (!tenantId) return;\n try {\n const outbox = getStoreLattice(\"default\", \"outbox\").store as OutboxStore;\n void publishA2AKeyChanged(outbox, getReplicaId(), tenantId);\n } catch {\n // Best-effort: startup load / the next change corrects a miss.\n }\n}\n\ninterface RequestWithUser extends FastifyRequest {\n user?: { id: string; tenantId?: string };\n}\n\nasync function requireTenantSession(\n request: FastifyRequest,\n reply: FastifyReply,\n): Promise<void> {\n if (!getUserTenantId(request)) {\n await reply.status(401).send({ success: false, error: \"Unauthorized\" });\n }\n}\n\nasync function authorizeKeyMutation(\n request: FastifyRequest<{ Params: { id: string } }>,\n reply: FastifyReply,\n): Promise<A2AApiKeyRecord | null> {\n if (!_a2aKeyStore) {\n await reply.status(501).send({ error: \"Key store not configured\" });\n return null;\n }\n const record = await _a2aKeyStore.findById(request.params.id);\n if (!record) {\n await reply.status(404).send({ success: false, error: \"A2A API key not found\" });\n return null;\n }\n if (record.tenantId !== getUserTenantId(request)) {\n await reply.status(403).send({ success: false, error: \"Forbidden\" });\n return null;\n }\n return record;\n}\n\nfunction getUserTenantId(request: FastifyRequest): string | undefined {\n return (request as RequestWithUser).user?.tenantId;\n}\n\n// ─── API Key Management Handlers ─────────────────────────────────────────\n\nasync function handleApiKeyList(\n request: FastifyRequest<{ Querystring: { tenantId?: string; limit?: string; offset?: string } }>,\n reply: FastifyReply,\n): Promise<void> {\n if (!_a2aKeyStore) {\n reply.status(501).send({ error: \"Key store not configured\" });\n return;\n }\n\n const records = await _a2aKeyStore.list({\n tenantId: getUserTenantId(request),\n limit: request.query.limit ? parseInt(request.query.limit, 10) : undefined,\n offset: request.query.offset ? parseInt(request.query.offset, 10) : undefined,\n });\n\n reply.status(200).send({\n success: true,\n data: {\n records: records.map((r) => ({ ...r, key: r.key.slice(0, 8) + \"...\" })),\n total: records.length,\n },\n });\n}\n\nasync function handleApiKeyCreate(\n request: FastifyRequest<{ Body: Partial<CreateA2AApiKeyInput> }>,\n reply: FastifyReply,\n): Promise<void> {\n if (!_a2aKeyStore || !_a2aAuthService) {\n reply.status(501).send({ error: \"Key store not configured\" });\n return;\n }\n\n const body = request.body as Partial<CreateA2AApiKeyInput>;\n const tenantId = getUserTenantId(request)!;\n\n try {\n const record = await _a2aAuthService.createKeyScoped({\n tenantId,\n projectId: body.projectId,\n assistantIds: body.assistantIds,\n grants: body.grants,\n label: body.label,\n });\n await refreshStoreKeyMap();\n broadcastA2AKeyChanged(tenantId);\n reply.status(201).send({ success: true, data: record });\n } catch (err) {\n if (err instanceof A2AAuthError) {\n reply.status(err.statusCode).send({ success: false, error: err.message });\n return;\n }\n request.log.error({ err }, \"a2a:keys:create\");\n reply.status(500).send({ success: false, error: \"Failed to create key\" });\n }\n}\n\nasync function handleApiKeyUpdate(\n request: FastifyRequest<{ Params: { id: string }; Body: Partial<CreateA2AApiKeyInput> }>,\n reply: FastifyReply,\n): Promise<void> {\n if (!_a2aKeyStore || !_a2aAuthService) {\n reply.status(501).send({ error: \"Key store not configured\" });\n return;\n }\n if (!(await authorizeKeyMutation(request, reply))) return;\n\n const body = request.body as Partial<CreateA2AApiKeyInput>;\n const tenantId = getUserTenantId(request)!;\n try {\n const record = await _a2aAuthService.updateKeyScoped(\n request.params.id,\n tenantId,\n {\n label: body.label,\n projectId: body.projectId,\n assistantIds: body.assistantIds,\n grants: body.grants,\n },\n );\n await refreshStoreKeyMap();\n broadcastA2AKeyChanged(tenantId);\n reply.status(200).send({ success: true, data: record });\n } catch (err) {\n if (err instanceof A2AAuthError) {\n reply.status(err.statusCode).send({ success: false, error: err.message });\n return;\n }\n request.log.error({ err }, \"a2a:keys:update\");\n reply.status(500).send({ success: false, error: \"Failed to update key\" });\n }\n}\n\nasync function handleApiKeyDelete(\n request: FastifyRequest<{ Params: { id: string } }>,\n reply: FastifyReply,\n): Promise<void> {\n const record = await authorizeKeyMutation(request, reply);\n if (!record) return;\n\n await _a2aKeyStore!.delete(request.params.id);\n await refreshStoreKeyMap();\n broadcastA2AKeyChanged(record.tenantId);\n\n reply.status(200).send({ success: true });\n}\n\nasync function handleApiKeyDisable(\n request: FastifyRequest<{ Params: { id: string } }>,\n reply: FastifyReply,\n): Promise<void> {\n const record = await authorizeKeyMutation(request, reply);\n if (!record) return;\n\n await _a2aKeyStore!.disable(request.params.id);\n await refreshStoreKeyMap();\n broadcastA2AKeyChanged(record.tenantId);\n\n reply.status(200).send({ success: true });\n}\n\nasync function handleApiKeyEnable(\n request: FastifyRequest<{ Params: { id: string } }>,\n reply: FastifyReply,\n): Promise<void> {\n const record = await authorizeKeyMutation(request, reply);\n if (!record) return;\n\n await _a2aKeyStore!.enable(request.params.id);\n await refreshStoreKeyMap();\n broadcastA2AKeyChanged(record.tenantId);\n\n reply.status(200).send({ success: true });\n}\n\nasync function handleApiKeyRotate(\n request: FastifyRequest<{ Params: { id: string } }>,\n reply: FastifyReply,\n): Promise<void> {\n const record = await authorizeKeyMutation(request, reply);\n if (!record) return;\n\n const rotated = await _a2aKeyStore!.rotate(request.params.id);\n await refreshStoreKeyMap();\n broadcastA2AKeyChanged(record.tenantId);\n\n reply.status(200).send({ success: true, data: rotated });\n}\n\n// ─── Route Registration ───────────────────────────────────────────────────\n\n/**\n * Register the API key management routes.\n *\n * `/api/keys` is the canonical unified surface; `/api/a2a/keys` remains as a\n * backward-compatible alias for existing clients.\n */\nexport function registerA2ARoutes(app: FastifyInstance): void {\n const options = { preHandler: requireTenantSession };\n for (const base of [\"/api/keys\", \"/api/a2a/keys\"]) {\n app.get<{ Querystring: { tenantId?: string; limit?: string; offset?: string } }>(\n base,\n options,\n handleApiKeyList,\n );\n\n app.post<{ Body: Partial<CreateA2AApiKeyInput> }>(\n base,\n options,\n handleApiKeyCreate,\n );\n\n app.delete<{ Params: { id: string } }>(\n `${base}/:id`,\n options,\n handleApiKeyDelete,\n );\n\n app.post<{ Params: { id: string } }>(\n `${base}/:id/disable`,\n options,\n handleApiKeyDisable,\n );\n\n app.post<{ Params: { id: string } }>(\n `${base}/:id/enable`,\n options,\n handleApiKeyEnable,\n );\n\n app.post<{ Params: { id: string } }>(\n `${base}/:id/rotate`,\n options,\n handleApiKeyRotate,\n );\n app.patch<{ Params: { id: string }; Body: Partial<CreateA2AApiKeyInput> }>(\n `${base}/:id`,\n options,\n handleApiKeyUpdate,\n );\n }\n}\n","import type { OutboxStore } from \"@axiom-lattice/protocols\";\n\n/** Outbox topic carrying cross-replica A2A API-key invalidation. */\nexport const A2A_KEY_CHANGED_TOPIC = \"a2a-key-changed\";\n\n/**\n * Best-effort publish of an A2A key change to the durable outbox.\n *\n * @param outbox Shared outbox store.\n * @param owner This replica id (recorded as the event origin).\n * @param tenantId Tenant whose keys changed.\n * @remarks Never throws; peers fall back to startup load / the next change.\n */\nexport async function publishA2AKeyChanged(\n outbox: OutboxStore,\n owner: string,\n tenantId: string,\n): Promise<void> {\n if (!tenantId) return;\n try {\n await outbox.append({\n topic: A2A_KEY_CHANGED_TOPIC,\n payload: { tenantId },\n originReplicaId: owner,\n });\n } catch {\n // Best-effort: startup load / the next change corrects a miss.\n }\n}\n\n/**\n * Reloads this replica's key map after a foreign key change.\n *\n * @param payload Outbox payload, expected to carry a non-empty `tenantId`.\n * @param reload Store-backed reload callback (refreshes the global key map).\n */\nexport async function handleA2AKeyChanged(\n payload: unknown,\n reload: () => Promise<void>,\n): Promise<void> {\n const tenantId = (payload as { tenantId?: unknown } | null)?.tenantId;\n if (typeof tenantId !== \"string\" || tenantId.length === 0) return;\n await reload();\n}\n"],"mappings":"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","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/services/a2a/A2AAgentCardBuilder.ts"],"sourcesContent":["import type { AgentCard, A2ASkill, AgentMiddlewareConfig } from \"@axiom-lattice/protocols\";\n\n/** Minimal assistant shape needed to derive a card from its own definition. */\nexport interface CardAssistant {\n id: string;\n name: string;\n description?: string;\n graphDefinition?: {\n middleware?: AgentMiddlewareConfig[];\n } | null;\n}\n\n/**\n * Parameters for building a per-assistant A2A AgentCard.\n */\nexport interface BuildAgentCardParams {\n assistant: CardAssistant;\n /** Gateway origin, e.g. \"https://gw.example.com\". */\n baseUrl: string;\n /** Optional JSON-RPC endpoint path override (official `/a2a/:id` alias). */\n jsonRpcPath?: string;\n /** Advertise push notification support; defaults to `true`. */\n pushNotifications?: boolean;\n}\n\n/**\n * Derive the card's advertised skills from the agent's own definition: every\n * enabled middleware contributes a skill (id = middleware type, name/description\n * from its config). No manual `a2aExposure` declaration — the card reflects\n * what the agent is actually built from.\n */\nexport function deriveAgentSkills(assistant: CardAssistant): A2ASkill[] {\n const enabled = assistant.graphDefinition?.middleware?.filter((m) => m.enabled) ?? [];\n return enabled.map((m) => ({\n id: m.type || m.id,\n name: m.name || m.type || m.id,\n description: m.description || \"\",\n tags: [],\n examples: [],\n }));\n}\n\n/**\n * Build an A2A 0.3 AgentCard (discovery document) for a single assistant.\n *\n * `url` points at the assistant's JSON-RPC endpoint (also advertised via\n * `additionalInterfaces`). Skills are derived from the agent definition;\n * input/output modes default to text.\n */\nexport function buildAgentCardForAssistant(params: BuildAgentCardParams): AgentCard {\n const { assistant, baseUrl } = params;\n const jsonRpcUrl = `${baseUrl}${\n params.jsonRpcPath ?? `/api/a2a/agents/${assistant.id}/jsonrpc`\n }`;\n\n return {\n name: assistant.name,\n description: assistant.description ?? \"\",\n url: jsonRpcUrl,\n protocolVersion: \"0.3.0\",\n version: \"1.0.0\",\n supportsAuthenticatedExtendedCard: true,\n defaultInputModes: [\"text\"],\n defaultOutputModes: [\"text\"],\n capabilities: {\n streaming: true,\n pushNotifications: params.pushNotifications ?? true,\n stateTransitionHistory: true,\n extensions: [\n {\n uri: \"https://axiom-lattice.dev/a2a/extensions/push-notifications-experimental\",\n description:\n \"Push notifications are experimental and best-effort. Delivery is at-most-once; clients should poll tasks/get or use tasks/resubscribe for reliability.\",\n params: {\n experimental: true,\n reliable: false,\n delivery: \"at-most-once\",\n },\n required: false,\n },\n ],\n },\n skills: deriveAgentSkills(assistant),\n additionalInterfaces: [{ transport: \"JSONRPC\", url: jsonRpcUrl }],\n securitySchemes: {\n bearer: {\n type: \"http\",\n scheme: \"Bearer\",\n description: \"API key sent as an Authorization Bearer token\",\n },\n apiKeyHeader: {\n type: \"apiKey\",\n in: \"header\",\n name: \"x-api-key\",\n description: \"API key sent via the x-api-key header\",\n },\n },\n security: [{ bearer: [] }, { apiKeyHeader: [] }],\n };\n}\n"],"mappings":";AA+BO,SAAS,kBAAkB,WAAsC;AACtE,QAAM,UAAU,UAAU,iBAAiB,YAAY,OAAO,CAAC,MAAM,EAAE,OAAO,KAAK,CAAC;AACpF,SAAO,QAAQ,IAAI,CAAC,OAAO;AAAA,IACzB,IAAI,EAAE,QAAQ,EAAE;AAAA,IAChB,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE;AAAA,IAC5B,aAAa,EAAE,eAAe;AAAA,IAC9B,MAAM,CAAC;AAAA,IACP,UAAU,CAAC;AAAA,EACb,EAAE;AACJ;AASO,SAAS,2BAA2B,QAAyC;AAClF,QAAM,EAAE,WAAW,QAAQ,IAAI;AAC/B,QAAM,aAAa,GAAG,OAAO,GAC3B,OAAO,eAAe,mBAAmB,UAAU,EAAE,UACvD;AAEA,SAAO;AAAA,IACL,MAAM,UAAU;AAAA,IAChB,aAAa,UAAU,eAAe;AAAA,IACtC,KAAK;AAAA,IACL,iBAAiB;AAAA,IACjB,SAAS;AAAA,IACT,mCAAmC;AAAA,IACnC,mBAAmB,CAAC,MAAM;AAAA,IAC1B,oBAAoB,CAAC,MAAM;AAAA,IAC3B,cAAc;AAAA,MACZ,WAAW;AAAA,MACX,mBAAmB,OAAO,qBAAqB;AAAA,MAC/C,wBAAwB;AAAA,MACxB,YAAY;AAAA,QACV;AAAA,UACE,KAAK;AAAA,UACL,aACE;AAAA,UACF,QAAQ;AAAA,YACN,cAAc;AAAA,YACd,UAAU;AAAA,YACV,UAAU;AAAA,UACZ;AAAA,UACA,UAAU;AAAA,QACZ;AAAA,MACF;AAAA,IACF;AAAA,IACA,QAAQ,kBAAkB,SAAS;AAAA,IACnC,sBAAsB,CAAC,EAAE,WAAW,WAAW,KAAK,WAAW,CAAC;AAAA,IAChE,iBAAiB;AAAA,MACf,QAAQ;AAAA,QACN,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,aAAa;AAAA,MACf;AAAA,MACA,cAAc;AAAA,QACZ,MAAM;AAAA,QACN,IAAI;AAAA,QACJ,MAAM;AAAA,QACN,aAAa;AAAA,MACf;AAAA,IACF;AAAA,IACA,UAAU,CAAC,EAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,cAAc,CAAC,EAAE,CAAC;AAAA,EACjD;AACF;","names":[]}
@@ -1 +0,0 @@
1
- import{a as Ie,b as Re,c as vt,d as xt,e as wt,f as Tt,g as It,h as St,i as Ft,j as Pt,k as Rt}from"./embed-page-chunk-VYS3TAK4.js";import{a as _e}from"./embed-page-chunk-OMN6G52V.js";import"./embed-page-chunk-RKQJBKN2.js";import"./embed-page-chunk-L2EGVVJS.js";import"./embed-page-chunk-FE6KYRCO.js";import{b as Oe,e as Ve,f as ft,g as yt,h as ht,i as Ct,l as At,m as bt}from"./embed-page-chunk-DJKD2PHO.js";import"./embed-page-chunk-D7YTSCUO.js";import{a as ct,b as dt,c as gt,d as pt,e as mt}from"./embed-page-chunk-SV2BM3WO.js";import"./embed-page-chunk-S4XZPBRM.js";import"./embed-page-chunk-LDQGH44H.js";import{T as kt,e as lt,h as ut,r as Ne}from"./embed-page-chunk-Z6KWW64I.js";import{i as rt}from"./embed-page-chunk-7ULTMRM2.js";import{a as me}from"./embed-page-chunk-JMP7EQEF.js";import{o as Ze}from"./embed-page-chunk-FZX4A32D.js";import{C as et,La as st,Q as tt,U as nt,ba as at,n as Te,oa as ot,ua as it}from"./embed-page-chunk-F7ZUYG42.js";import{k as z}from"./embed-page-chunk-W5OP2CZG.js";import{a as E}from"./embed-page-chunk-QV7QAJ4N.js";import"./embed-page-chunk-VW3NF5NT.js";import"./embed-page-chunk-34RWKVD7.js";import{Ja as Xe,Q as Je,g as Ye,na as Pe,za as Qe}from"./embed-page-chunk-B2KNZ3EW.js";import{Da as R,Ia as V,Ka as Le,La as w,Ma as pe,Sa as $e,Za as we,_ as W,_a as We,bb as X,fa as xe,ha as je,na as Fe,ua as Be,va as Ue,xa as qe,za as He}from"./embed-page-chunk-F7TA3LRH.js";import{a as ge}from"./embed-page-chunk-R5QL57JJ.js";import"./embed-page-chunk-QOWM3LMZ.js";import"./embed-page-chunk-EUOOO2LS.js";import"./embed-page-chunk-5JDQ456X.js";import{f as I}from"./embed-page-chunk-QBTAJ2YI.js";var h=I(ge());var te=I(ge());var Z=I(ge());var Dt=I(ge());var se=I(E()),Mt=60,Et=72,Ge=(0,Dt.memo)(({data:i})=>{let l=Ie(i.type),f=Math.min(12+Math.sqrt(i.subAgentCount)*10,48);return(0,se.jsxs)("div",{style:{display:"flex",flexDirection:"column",alignItems:"center"},children:[(0,se.jsx)(Ve,{type:"target",position:Oe.Top,style:{left:"50%",top:"50%",transform:"translate(-50%, -50%)",background:"transparent",border:"none",width:0,height:0},isConnectable:!1}),(0,se.jsx)("div",{title:i.label,style:{width:f,height:f,borderRadius:"50%",background:Re(l.color),display:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontSize:Math.max(10,f*.4),fontWeight:600,cursor:"pointer",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"},children:i.label.charAt(0).toUpperCase()}),(0,se.jsx)("div",{style:{fontSize:11,maxWidth:120,textAlign:"center",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",marginTop:4},children:i.label}),(0,se.jsx)(Ve,{type:"source",position:Oe.Top,style:{left:"50%",top:"50%",transform:"translate(-50%, -50%)",background:"transparent",border:"none",width:0,height:0},isConnectable:!1})]})});Ge.displayName="AgentGraphNode";var ee=I(E()),en=({assistants:i,onNodeClick:l})=>{let[f,c,u]=ht([]),[o,e,C]=Ct([]),[r,m]=(0,Z.useState)(null),S=(0,Z.useMemo)(()=>({agent:Ge}),[]),M=(0,Z.useMemo)(()=>wt(i),[i]);(0,Z.useEffect)(()=>{let v=M.nodes.map(g=>({id:g.id})),P=M.edges.map(g=>({source:g.source,target:g.target})),D=new Map(M.nodes.map(g=>[g.id,g])),$=pt(v).force("link",gt(P).id(g=>g.id).distance(80)).force("charge",mt().strength(-220)).force("center",ct(0,0)).force("collide",dt(45)).stop();for(let g=0;g<300;g++)$.tick();let j=v.map(g=>({id:g.id,type:"agent",data:D.get(g.id),position:{x:g.x-Mt/2,y:g.y-Et/2}})),a=M.edges.map(g=>({id:`e${g.source}-${g.target}`,source:g.source,target:g.target,style:{stroke:"#1677ff",strokeWidth:2},type:"straight"}));c(j),e(a)},[M,c,e]);let H=(0,Z.useMemo)(()=>r===null?f:f.map(v=>{let P=v.id===r||o.some(D=>D.source===r&&D.target===v.id||D.target===r&&D.source===v.id);return{...v,style:{opacity:P?1:.2,transition:"opacity 0.2s ease"}}}),[f,o,r]),d=(0,Z.useMemo)(()=>r===null?o.map(v=>({...v,style:{stroke:"#1677ff",strokeWidth:1.5,opacity:.25,transition:"opacity 0.2s ease"}})):o.map(v=>{let P=v.source===r||v.target===r;return{...v,style:{stroke:"#1677ff",strokeWidth:P?2.5:1,opacity:P?1:.04,transition:"opacity 0.2s ease"}}}),[o,r]);return(0,ee.jsx)("div",{style:{width:"100%",height:"100%",background:"#fafafa",position:"relative"},children:(0,ee.jsxs)(yt,{nodes:H,edges:d,onNodesChange:u,onEdgesChange:C,onNodeMouseEnter:(v,P)=>m(P.id),onNodeMouseLeave:()=>m(null),onNodeClick:(v,P)=>l?.(String(P.id)),nodeTypes:S,fitView:!0,fitViewOptions:{padding:.25},children:[(0,ee.jsx)(At,{color:"#eee",gap:20}),(0,ee.jsx)(bt,{})]})})},Kt=i=>(0,ee.jsx)(ft,{children:(0,ee.jsx)(en,{...i})});var T=I(E()),tn=[{key:"all",labelKey:"governance.list.tab.all"},{key:"capability",labelKey:"governance.list.tab.capability"},{key:"orchestrator",labelKey:"governance.list.tab.orchestrator"},{key:"workflow",labelKey:"governance.list.tab.workflow"}],Bt=({items:i,assistants:l=[],loading:f,onItemClick:c,onOpenPlayground:u,onOpenEval:o,onCreate:e,onDelete:C})=>{let r=z(),[m,S]=(0,te.useState)("all"),[M,H]=(0,te.useState)(null),[d,v]=(0,te.useState)(null),P=(0,te.useMemo)(()=>{let a=new Set;return i.forEach(g=>g.tags.forEach(U=>a.add(U))),Array.from(a).map(g=>({value:g,label:g}))},[i]),D=(0,te.useMemo)(()=>i.filter(a=>!(m!=="all"&&a.type!==m||M&&!a.tags.includes(M)||d&&a.status!==d)),[i,m,M,d]),$=[{key:"edit",icon:it,label:r("common.edit"),onClick:a=>c(a.id)},{key:"playground",icon:et,label:r("governance.list.action.playground"),onClick:a=>u(a.id)},{key:"eval",icon:nt,label:r("governance.list.action.eval"),onClick:a=>o(a.id)}];C&&$.push({key:"delete",icon:st,label:r("common.delete"),danger:!0,onClick:a=>C(a.id)});let j=(0,te.useMemo)(()=>[{mode:"graph",icon:ot,label:r("governance.list.viewMode.graph"),render:()=>(0,T.jsx)(Kt,{assistants:l,onNodeClick:c})}],[l,c,r]);return(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)("span",{"data-testid":"agent-list-state","data-loading":String(f),"data-count":D.length,hidden:!0,"aria-hidden":"true"}),(0,T.jsx)(lt,{title:r("governance.list.title"),itemName:"common.item.agent",items:D,loading:f,keyExtractor:a=>a.id,tabs:tn.map(a=>({key:a.key,label:r(a.labelKey)})),activeTab:m,onTabChange:a=>S(a),headerLeft:(0,T.jsxs)("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[(0,T.jsx)(Ne,{value:M,onChange:H,options:P,placeholder:r("governance.list.filter.domain"),allLabel:r("governance.list.filter.allDomains")}),(0,T.jsx)(Ne,{value:d,onChange:v,options:[{value:"enabled",label:r("governance.list.status.enabled")},{value:"draft",label:r("governance.list.status.draft")},{value:"disabled",label:r("governance.list.status.disabled")}],placeholder:r("governance.list.filter.status"),allLabel:r("governance.list.filter.allStatuses")})]}),renderIcon:a=>{let g=Re(Ie(a.type).color);return(0,T.jsx)("div",{title:r("governance.list.typeIconTitle",{type:a.type}),style:{width:32,height:32,borderRadius:8,background:`${g}1A`,color:g,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:(0,T.jsx)(Te,{size:18})})},renderPrimary:a=>(0,T.jsx)("span",{"data-testid":"agent-name","data-agent-id":a.id,children:a.name}),renderSecondary:a=>a.description||void 0,renderDetails:a=>(0,T.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,T.jsxs)("div",{style:{display:"flex",gap:4,flexWrap:"wrap",alignItems:"center"},children:[a.tags.map(g=>(0,T.jsx)(we,{color:"magenta",style:{margin:0,borderRadius:10,border:"none"},children:g},g)),(0,T.jsx)(we,{color:Ie(a.type).color,style:{margin:0,borderRadius:10,border:"none"},children:a.type})]}),(0,T.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0},children:[(0,T.jsx)(je,{title:r("governance.list.statusTooltip",{status:a.status}),children:(0,T.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:vt(a.status),display:"inline-block",cursor:"help"}})}),(0,T.jsx)("span",{style:{fontSize:12,color:"#8c8c8c"},children:a.version})]})]}),itemActions:$,actionsStyle:"icon",actionsPosition:"hover",onItemClick:a=>c(a.id),createLabel:r("governance.list.create"),onCreateClick:e,viewModeExtensions:j,emptyIcon:(0,T.jsx)(Te,{size:48,style:{opacity:.5}}),emptyTitle:r("governance.list.emptyTitle"),emptyDescription:r("governance.list.emptyDescription")})]})};var A=I(ge());var re=I(ge());var ue=I(E()),{Text:nn}=X,Lt=({onSelect:i,value:l,placeholder:f})=>{let c=z(),u=f??c("chatConfig.parentAgent.selectPlaceholder"),[o,e]=(0,re.useState)([]),[C,r]=(0,re.useState)(!1),{get:m}=me(),S=(0,re.useCallback)(async()=>{r(!0);try{let d=await m("/api/assistants");d.success&&e(d.data?.records||[])}catch(d){console.error("Failed to fetch assistants:",d)}finally{r(!1)}},[m]);return(0,re.useEffect)(()=>{S()},[S]),(0,ue.jsx)(xe,{showSearch:!0,allowClear:!0,value:l,placeholder:u,loading:C,onChange:d=>{if(!d){i(null);return}let v=o.find(P=>P.id===d);i(v||null)},onDropdownVisibleChange:d=>{d&&S()},optionFilterProp:"label",style:{width:"100%"},options:o.map(d=>({value:d.id,label:d.name||d.id,description:d.description})),optionRender:d=>(0,ue.jsxs)("div",{children:[(0,ue.jsx)("div",{children:d.label}),d.data.description&&(0,ue.jsx)(nn,{type:"secondary",style:{fontSize:12},children:d.data.description})]})})};var L=I(E()),{Text:Nt}=X,Ot=({subAgentKeys:i,decisions:l,onChange:f})=>{let{token:c}=We.useToken(),u=z(),o=(C,r)=>{let m=l.map(S=>S.originalKey===C?{...S,clone:r,cloneKey:r?`${C}_clone`:void 0}:S);f(m)},e=(C,r)=>{let m=l.map(S=>S.originalKey===C?{...S,cloneKey:r}:S);f(m)};return i.length===0?null:(0,L.jsxs)("div",{children:[(0,L.jsx)(Nt,{type:"secondary",style:{display:"block",marginBottom:8},children:u("chatConfig.subAgentInherit.hint")}),(0,L.jsx)(Le,{size:"small",bordered:!0,dataSource:l,style:{borderRadius:c.borderRadius},renderItem:C=>(0,L.jsxs)(Le.Item,{style:{display:"flex",flexDirection:"column",alignItems:"stretch",gap:8,padding:"8px 16px"},children:[(0,L.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,L.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[C.clone?(0,L.jsx)(Pe,{style:{color:c.colorPrimary}}):(0,L.jsx)(Qe,{style:{color:c.colorTextSecondary}}),(0,L.jsx)(Nt,{style:{fontFamily:"monospace"},children:C.originalKey})]}),(0,L.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,L.jsx)(we,{color:C.clone?"blue":"default",children:C.clone?u("chatConfig.subAgentInherit.clone"):u("chatConfig.subAgentInherit.reuse")}),(0,L.jsx)($e,{size:"small",checked:C.clone,onChange:r=>o(C.originalKey,r)})]})]}),C.clone&&(0,L.jsx)(V,{size:"small",placeholder:u("chatConfig.subAgentInherit.cloneKeyPlaceholder"),value:C.cloneKey,onChange:r=>e(C.originalKey,r.target.value),style:{fontFamily:"monospace",fontSize:12},addonBefore:u("chatConfig.keyValue.key")})]})})]})};function Vt(i,l){return i.mode!=="local"||i.templateKey||typeof i.executable=="string"&&i.executable.trim().length>0?null:l?l("chat.config.executableRequired"):"Choose a template or enter a custom executable"}var n=I(E()),{TextArea:_t}=V,{Text:ne}=X,Gt="/.well-known/agent-card.json",an=[{value:"http://",label:"http://"},{value:"https://",label:"https://"}],on={react:"chatConfig.createAssistant.typeDesc.react",deep_agent:"chatConfig.createAssistant.typeDesc.deepAgent",processing:"chatConfig.createAssistant.typeDesc.processing",a2a_remote:"chatConfig.createAssistant.typeDesc.a2aRemote"};function zt(i,l,f="https://"){let c=String(i??"").trim();if(!c)return"";let u=l==="http://"||l==="https://"?l:f,e=(/^https?:\/\//i.test(c)?c:`${u}${c.replace(/^\/+/,"")}`).replace(/\/+$/,"");return e.endsWith(Gt)?e:`${e}${Gt}`}function sn(i){try{return new URL(i).port||void 0}catch{return}}function rn(i){return i.some(l=>l==="--port"||l==="-p"||/^--port=/.test(l)||/^-p=/.test(l))}function jt(i,l){let f=[...i.args],c=sn(l);return c&&!rn(f)&&f.push("--port",c),{...i,args:f,...i.env?{env:{...i.env}}:{}}}var Ut=({open:i,onCancel:l,onSuccess:f,initialMode:c,initialValues:u})=>{let[o]=R.useForm(),e=z(),[C,r]=(0,A.useState)(!1),[m,S]=(0,A.useState)("learn"),[M,H]=(0,A.useState)(""),[d,v]=(0,A.useState)(null),[P,D]=(0,A.useState)([]),$=R.useWatch("type",o)||"react",j=$==="a2a_remote",[a,g]=(0,A.useState)("remote"),[U,fe]=(0,A.useState)(void 0),[le,ye]=(0,A.useState)([]),[Se,ce]=(0,A.useState)(!1),ae=(0,A.useRef)(0),[oe,ie]=(0,A.useState)(!1),[De,Y]=(0,A.useState)(!1),{get:N,post:J,put:he}=me(),Me=Ze("agent-architect"),{workspaceId:Ce,trainingProjects:Q,loading:de}=rt(),[Ee,Ae]=(0,A.useState)(null),Ke=JSON.stringify(u??null),K=Q.find(t=>t.id===Ee)??Q[0]??null,[be,ke]=(0,A.useState)([]),p=(0,A.useCallback)(()=>{v(null),D([])},[]),b=(0,A.useCallback)(()=>{o.resetFields(),p(),S("learn"),H(""),ke([]),Ae(null),g("remote"),fe(void 0),ye([]),Y(!1),ie(!1)},[o,p]);(0,A.useEffect)(()=>{if(i){b(),S(c??"learn");let t=u?.a2aMode;(t==="remote"||t==="local")&&g(t),o.setFieldsValue({type:"react",agentCardProtocol:"https://",a2aMode:"remote",timeout:3e5,...u})}},[i,o,c,Ke,b]),(0,A.useEffect)(()=>{let t=++ae.current,s=!0;return i&&j?(o.setFieldValue("prompt",""),a==="local"?(ce(!0),N("/api/local-a2a/templates").then(k=>{s&&t===ae.current&&k?.data?.records&&ye(k.data.records)}).catch(()=>{s&&t===ae.current&&ye([])}).finally(()=>{s&&t===ae.current&&ce(!1)})):ce(!1)):ce(!1),()=>{s=!1,ae.current+=1}},[o,j,a,N,i]);let x=le.find(t=>t.key===U),q=(0,A.useCallback)(()=>{let t=Vt({mode:a,templateKey:U,executable:o.getFieldValue("commandExecutable")},e);return t?(Y(!0),o.setFields([{name:"commandExecutable",errors:[t]}]),w.warning(t),!1):!0},[a,U,o,e]);(0,A.useEffect)(()=>{x&&o.setFieldsValue({agentCardProtocol:"http://"})},[o,x]);let ve=(0,A.useCallback)(async()=>{if(!q())return;let t=zt(o.getFieldValue("agentCardUrl"),o.getFieldValue("agentCardProtocol"),a==="local"?"http://":"https://");if(!t){w.warning(e("chatConfig.createAssistant.a2aUrlWarning"));return}ie(!0);try{let s={agentCardUrl:t,apiKey:o.getFieldValue("apiKey")};if(a==="local"){let y=x;if(y)s.localRuntime={label:o.getFieldValue("name")||void 0,agentCardUrl:t,command:jt(y.command,t)};else{let B=o.getFieldValue("commandArgs")||"",G=B?B.split(/\s+/).filter(Boolean):[],F=String(o.getFieldValue(["command","cwd"])||"").trim();s.localRuntime={label:o.getFieldValue("name")||void 0,agentCardUrl:t,command:{executable:String(o.getFieldValue("commandExecutable")||"").trim(),args:G,...F?{cwd:F}:{}}}}}let k=await J("/api/a2a/test-connection",s);if(k.data?.reachable){let y=k.data.agentCard;w.success(e("chatConfig.createAssistant.connectedTo",{name:k.data.agentName||t}))}else w.error(k.data?.error||e("chatConfig.createAssistant.connectionFailed"))}catch{w.error(e("chatConfig.createAssistant.connectionTestFailed"))}finally{ie(!1)}},[o,J,a,x,q,e]),$t=(0,A.useCallback)(t=>{if(v(t),!t){o.resetFields(["key","name","description","type","prompt"]),D([]);return}let s=typeof t.graphDefinition=="object"&&t.graphDefinition!==null?t.graphDefinition:{},k=s.key||t.id,y=t.name||s.name||"";o.setFieldsValue({key:`${k}_ext`,name:y?`${y} (Extended)`:"",description:t.description||s.description||"",type:s.type||"react",prompt:s.prompt||""});let B=s.subAgents||[];D(B.map(G=>({originalKey:G,clone:!1})))},[o]),Wt=async(t,s)=>{let k=await N(`/api/assistants/${t}`);if(!k.success)throw new Error(e("chatConfig.createAssistant.cloneFetchFailed",{key:t}));let y=k.data,B=typeof y.graphDefinition=="object"?y.graphDefinition:{},G={id:s,name:`${y.name} (Clone)`,description:y.description||"",graphDefinition:{...B,key:s,name:`${y.name} (Clone)`}},F=await J("/api/assistants",G);if(!F.success)throw new Error(F.message||e("chatConfig.createAssistant.cloneFailed",{key:t}));return F.data},Zt=t=>{let s={id:t.key,name:t.name,description:t.description||"",graphDefinition:{key:t.key,name:t.name,description:t.description||"",type:t.type,prompt:t.prompt||"",tools:[],skills:[],subAgents:t.type==="deep_agent"||t.type==="processing"?[]:void 0,middleware:[]}};if(t.type==="a2a_remote"&&(s.graphDefinition.agentCardUrl=zt(t.agentCardUrl,t.agentCardProtocol,(t.a2aMode||a)==="local"?"http://":"https://"),t.apiKey&&(s.graphDefinition.apiKey=t.apiKey),t.timeout&&(s.graphDefinition.timeout=t.timeout),(t.a2aMode||a)==="local")){let k=x;if(k)s.graphDefinition.localRuntime={label:t.name||void 0,agentCardUrl:s.graphDefinition.agentCardUrl,command:jt(k.command,s.graphDefinition.agentCardUrl)};else{let y=t.commandArgs||"",B=y?y.split(/\s+/).filter(Boolean):[],G=String(t.command?.cwd||"").trim();s.graphDefinition.localRuntime={label:t.name||void 0,agentCardUrl:s.graphDefinition.agentCardUrl,command:{executable:String(t.commandExecutable||"").trim(),args:B,...G?{cwd:G}:{}}}}}return s},Yt=async(t,s)=>{if(!d)throw new Error(e("chatConfig.createAssistant.noParentAgent"));let k=P.filter(F=>F.clone);for(let F of k){if(!F.cloneKey||!F.cloneKey.trim())throw new Error(e("chatConfig.createAssistant.cloneKeyRequired",{key:F.originalKey}));if(!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(F.cloneKey))throw new Error(e("chatConfig.createAssistant.cloneKeyInvalid",{key:F.cloneKey,originalKey:F.originalKey}))}let y=[];for(let F of P)if(F.clone){let Xt=await Wt(F.originalKey,F.cloneKey);s.push(Xt),y.push(F.cloneKey)}else y.push(F.originalKey);let B=typeof d.graphDefinition=="object"?d.graphDefinition:{},G={key:t.key,name:t.name,description:t.description||"",extendsAgent:d.id,type:t.type||B.type};return t.prompt&&t.prompt!==B.prompt&&(G.prompt=t.prompt),(y.length>0||B.subAgents&&B.subAgents.length>0)&&(G.subAgents=y),{id:t.key,name:t.name,description:t.description||"",graphDefinition:G}},Jt=async()=>{if(m==="learn"){let t=M.trim();if(!t){w.error(e("chatConfig.createAssistant.trainingGoalRequired"));return}if(!K){w.error(e("chatConfig.createAssistant.noTrainingProject"));return}r(!0);try{let s=`agent-${It(t+Date.now())}`,k=await J("/api/assistants",{id:s,name:s,graphDefinition:{key:s,name:s,description:"",type:"react",prompt:"To be trained",metadata:{trainingProjectId:K.id,learningPlaceholder:"true",architectureStatus:"undecided"}}});if(!k.data)throw new Error(e("chatConfig.createAssistant.agentCreateFailed"));let{roundTaskId:y}=await Ft({goal:t,targetAgentId:s,workspaceId:Ce??void 0,projectId:K.id,existingThreadId:St(Me.tenantId,s),files:be,post:J,put:he});w.success(e("chatConfig.createAssistant.agentCreated")),H(""),ke([]),S("learn"),f?.(k.data,{initialMessage:Pt({goal:t,roundTaskId:y,targetAgentId:s,targetMode:"placeholder",files:be,projectId:K.id,workspaceId:K.workspaceId??Ce??void 0}),projectId:K.id,initialMessageCustomRunConfig:{execution:{taskId:y}}}),l()}catch(s){w.error(s instanceof Error?s.message:e("chatConfig.createAssistant.agentCreateFailed"))}finally{r(!1)}return}try{if(m==="scratch"&&j&&!q())return;let t=await o.validateFields();r(!0);let s=[],k=m==="scratch"?Zt(t):await Yt(t,s),y=await J("/api/assistants",k);if(y.success){w.success(m==="extend"?e("chatConfig.createAssistant.createdByExtending",{name:d?.name??""}):e("chatConfig.createAssistant.created")),b();for(let B of s)f?.(B);f?.(y.data),l()}else w.error(y.message||e("chatConfig.createAssistant.createFailed"))}catch(t){if(t?.errorFields){let s={key:e("chatConfig.createAssistant.field.key"),name:e("chatConfig.createAssistant.field.name"),description:e("chatConfig.createAssistant.field.description"),prompt:e("chatConfig.createAssistant.field.systemPrompt")},k=t.errorFields.map(y=>s[String((y.name??[])[0])]??String((y.name??[])[0])).filter(Boolean);w.warning(k.length>0?e("chatConfig.createAssistant.requiredFields",{fields:[...new Set(k)].join(", ")}):e("chatConfig.createAssistant.requiredFieldsGeneric"));return}w.error(t.message||e("chatConfig.createAssistant.createError"))}finally{r(!1)}},ze=d?.graphDefinition?.subAgents||[],Qt=m==="extend"&&d&&ze.length>0;return(0,n.jsxs)(pe,{title:e("chatConfig.createAssistant.title"),open:i,onCancel:()=>{b(),l()},footer:[(0,n.jsx)(W,{onClick:()=>{b(),l()},children:e("common.cancel")},"cancel"),(0,n.jsx)(W,{type:"primary",icon:m==="extend"?(0,n.jsx)(Pe,{}):m==="learn"?(0,n.jsx)(Je,{}):(0,n.jsx)(Xe,{}),loading:C,disabled:m==="learn"&&(de||!K),onClick:Jt,children:e(m==="extend"?"chatConfig.createAssistant.createExtend":m==="learn"?"chatConfig.createAssistant.startLearning":"common.create")},"submit")],width:760,children:[m==="extend"&&(0,n.jsxs)("div",{style:{marginBottom:20},children:[(0,n.jsx)(ne,{type:"secondary",style:{display:"block",marginBottom:8},children:e("chatConfig.createAssistant.parentAgent")}),(0,n.jsx)(Lt,{value:d?.id,onSelect:$t}),d&&(0,n.jsx)(ne,{type:"secondary",style:{display:"block",marginTop:4,fontSize:12},children:e("chatConfig.createAssistant.inheritHint")})]}),m==="extend"&&d&&(0,n.jsx)(Be,{style:{margin:"12px 0"}}),m==="learn"&&(0,n.jsxs)("div",{children:[(0,n.jsx)(ne,{style:{display:"block",marginBottom:8},children:e("chatConfig.createAssistant.learnHint")}),(0,n.jsx)(V.TextArea,{rows:3,value:M,onChange:t=>H(t.target.value),placeholder:e("chatConfig.createAssistant.learnGoalPlaceholder")}),K&&(0,n.jsxs)("div",{style:{marginTop:12},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,marginBottom:8},children:[(0,n.jsx)(ne,{type:"secondary",children:e("chatConfig.createAssistant.referenceFiles")}),(0,n.jsx)(_e,{project:K,projects:Q,value:K?.id??null,onChange:Ae,loading:de})]}),(0,n.jsx)(Tt,{projectId:K.id,value:be,onChange:ke}),(0,n.jsx)(ne,{type:"secondary",style:{display:"block",marginTop:6,fontSize:12},children:e("chatConfig.createAssistant.referenceFilesHint")})]}),!K&&!de&&(0,n.jsx)("div",{style:{marginTop:12},children:(0,n.jsx)(_e,{project:K,projects:Q,value:null,onChange:Ae,loading:de})})]}),m!=="learn"&&(0,n.jsxs)(R,{form:o,layout:"vertical",autoComplete:"off",initialValues:{type:"react",agentCardProtocol:"https://",a2aMode:"remote"},children:[(0,n.jsx)(R.Item,{name:"key",label:e("chatConfig.createAssistant.field.key"),rules:[{required:!0,message:e("chatConfig.createAssistant.validation.keyRequired")},{pattern:/^[a-zA-Z][a-zA-Z0-9_-]*$/,message:e("chatConfig.createAssistant.validation.keyPattern")}],style:{marginBottom:16},children:(0,n.jsx)(V,{placeholder:e("chatConfig.createAssistant.keyPlaceholder")})}),(0,n.jsx)(R.Item,{name:"name",label:e("chatConfig.createAssistant.field.name"),rules:[{required:!0,message:e("chatConfig.createAssistant.validation.nameRequired")}],style:{marginBottom:16},children:(0,n.jsx)(V,{placeholder:e("chatConfig.createAssistant.namePlaceholder")})}),(0,n.jsx)(R.Item,{name:"description",label:e("chatConfig.createAssistant.field.description"),rules:[{required:!0,message:e("chatConfig.createAssistant.validation.descriptionRequired")}],style:{marginBottom:16},children:(0,n.jsx)(_t,{placeholder:e("chatConfig.createAssistant.descriptionPlaceholder"),autoSize:{minRows:2,maxRows:4}})}),(0,n.jsx)(R.Item,{name:"type",label:e("chatConfig.createAssistant.field.agentType"),rules:[{required:!0}],style:{marginBottom:16},children:(0,n.jsx)(Ue,{options:[{value:"react",label:e("chatConfig.agentType.executor")},{value:"deep_agent",label:e("chatConfig.agentType.orchestrator")},{value:"processing",label:e("chatConfig.agentType.workflow")},{value:"a2a_remote",label:e("chatConfig.agentType.a2aRemote")}],block:!0})}),(0,n.jsx)(ne,{type:"secondary",style:{fontSize:12,display:"block",marginTop:-12,marginBottom:16,lineHeight:1.5},children:e(on[$]??"chatConfig.createAssistant.typeDesc.react")}),j&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(R.Item,{label:e("chatConfig.createAssistant.field.connectionMode"),style:{marginBottom:16},children:(0,n.jsxs)(Fe.Group,{value:a,onChange:t=>{let s=t.target.value;g(s),o.setFieldValue("a2aMode",s),s==="local"&&o.setFieldValue("agentCardProtocol","http://"),fe(void 0)},optionType:"button",buttonStyle:"solid",children:[(0,n.jsx)(Fe.Button,{value:"remote",children:e("chatConfig.createAssistant.mode.remoteUrl")}),(0,n.jsx)(Fe.Button,{value:"local",children:e("chatConfig.createAssistant.mode.localManaged")})]})}),(0,n.jsx)(R.Item,{name:"a2aMode",noStyle:!0,hidden:!0,children:(0,n.jsx)(V,{})}),a==="local"&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(R.Item,{label:e("chatConfig.createAssistant.field.template"),style:{marginBottom:16},children:(0,n.jsx)(xe,{placeholder:e("chatConfig.createAssistant.templatePlaceholder"),allowClear:!0,loading:Se,value:U,onChange:t=>{fe(t),t&&Y(!1)},options:le.map(t=>({value:t.key,label:t.name||t.key})),notFoundContent:Se?void 0:(0,n.jsx)(ne,{type:"secondary",style:{padding:8,display:"block"},children:e("chatConfig.createAssistant.noTemplates")})})}),!U&&(0,n.jsx)(n.Fragment,{children:De?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(R.Item,{name:"commandExecutable",label:e("chatConfig.createAssistant.field.executable"),rules:[{required:!0,whitespace:!0,message:e("chatConfig.createAssistant.validation.executableRequired")}],style:{marginBottom:16},children:(0,n.jsx)(V,{placeholder:e("chatConfig.createAssistant.executablePlaceholder")})}),(0,n.jsx)(R.Item,{name:"commandArgs",label:e("chatConfig.createAssistant.field.arguments"),style:{marginBottom:16},children:(0,n.jsx)(V,{placeholder:e("chatConfig.createAssistant.argumentsPlaceholder")})}),(0,n.jsx)(R.Item,{name:["command","cwd"],label:e("chatConfig.createAssistant.field.workingDirectory"),style:{marginBottom:16},children:(0,n.jsx)(V,{placeholder:e("chatConfig.createAssistant.workingDirectoryPlaceholder")})}),(0,n.jsx)(W,{type:"link",onClick:()=>{Y(!1),o.setFieldsValue({commandExecutable:"",commandArgs:"",command:{cwd:void 0}})},style:{padding:0,marginBottom:16,display:"block"},children:e("chatConfig.createAssistant.hideCustomCommand")})]}):(0,n.jsx)(W,{type:"link",onClick:()=>Y(!0),style:{padding:0,marginBottom:16,display:"block"},children:e("chatConfig.createAssistant.customCommand")})})]}),(0,n.jsx)(R.Item,{label:e("chatConfig.createAssistant.field.agentCardUrl"),required:!0,style:{marginBottom:16},children:(0,n.jsxs)(He.Compact,{style:{width:"100%"},children:[(0,n.jsx)(R.Item,{name:"agentCardProtocol",noStyle:!0,children:(0,n.jsx)(xe,{style:{width:100},options:an})}),(0,n.jsx)(R.Item,{name:"agentCardUrl",noStyle:!0,rules:[{required:!0,message:e("chatConfig.createAssistant.validation.urlRequired")}],children:(0,n.jsx)(V,{placeholder:a==="local"?"localhost:4301":"host:port or full URL"})}),(0,n.jsx)(W,{icon:(0,n.jsx)(Ye,{}),onClick:ve,loading:oe,children:e("chatConfig.connection.action.test")})]})}),a==="remote"&&(0,n.jsx)(R.Item,{name:"apiKey",label:e("chatConfig.createAssistant.field.apiKeyOptional"),style:{marginBottom:16},children:(0,n.jsx)(V.Password,{placeholder:e("chatConfig.createAssistant.apiKeyPlaceholder")})}),(0,n.jsx)(R.Item,{name:"timeout",label:e("chatConfig.createAssistant.field.timeout"),style:{marginBottom:16},initialValue:3e5,children:(0,n.jsx)(qe,{min:1e3,max:36e5,style:{width:"100%"},placeholder:"300000"})})]}),!j&&(0,n.jsx)(R.Item,{name:"prompt",label:e(m==="extend"&&d?"chatConfig.createAssistant.field.systemPromptInherit":"chatConfig.createAssistant.field.systemPrompt"),rules:m==="scratch"?[{required:!0,message:e("chatConfig.createAssistant.validation.systemPromptRequired")}]:[],children:(0,n.jsx)(_t,{placeholder:e(m==="extend"&&d?"chatConfig.createAssistant.systemPromptInheritPlaceholder":"chatConfig.createAssistant.systemPromptPlaceholder"),autoSize:{minRows:4,maxRows:8},style:{fontFamily:"monospace",fontSize:13,lineHeight:1.6}})})]}),Qt&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(Be,{style:{margin:"12px 0"}}),(0,n.jsx)(ne,{strong:!0,style:{display:"block",marginBottom:8},children:e("chatConfig.createAssistant.subAgents")}),(0,n.jsx)(Ot,{subAgentKeys:ze,decisions:P,onChange:D})]})]})};var O=I(E()),{Paragraph:ln,Text:qt}=X,cn=[{key:"manual",icon:Te,titleKey:"governance.creation.manual.title",descriptionKey:"governance.creation.manual.description"},{key:"external",icon:tt,titleKey:"governance.creation.external.title",descriptionKey:"governance.creation.external.description"},{key:"learn",icon:at,titleKey:"governance.creation.learn.title",descriptionKey:"governance.creation.learn.description"}],Ht=({open:i,onCancel:l,onSelectMethod:f,focusTriggerAfterClose:c=!0})=>{let u=z();return(0,O.jsx)(pe,{title:u("governance.creation.title"),open:i,onCancel:l,footer:null,width:560,centered:!0,destroyOnHidden:!0,focusTriggerAfterClose:c,children:(0,O.jsxs)("div",{style:{padding:"8px 4px 4px"},children:[(0,O.jsx)(ln,{style:{color:"#595959",fontSize:15,margin:"8px 0 24px"},children:u("governance.creation.subtitle")}),(0,O.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:cn.map(o=>{let e=o.icon,C=u(o.titleKey);return(0,O.jsxs)(W,{type:"default",onClick:()=>f(o.key),"aria-label":C,style:{display:"flex",flexDirection:"row",alignItems:"center",gap:16,width:"100%",minHeight:88,height:"auto",padding:16,borderRadius:16,textAlign:"left",whiteSpace:"normal"},children:[(0,O.jsx)("div",{style:{width:40,height:40,borderRadius:12,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:"#6366f1",background:"#eeeeff"},children:(0,O.jsx)(e,{size:19})}),(0,O.jsxs)("div",{style:{minWidth:0},children:[(0,O.jsx)(qt,{strong:!0,style:{display:"block",fontSize:15,marginBottom:3},children:C}),(0,O.jsx)(qt,{style:{color:"#737373",lineHeight:1.5},children:u(o.descriptionKey)})]})]},o.key)})}),(0,O.jsx)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,flexWrap:"wrap",marginTop:24},children:(0,O.jsx)(W,{onClick:l,children:u("governance.creation.notNow")})})]})})};var _=I(E()),dn=i=>{let l=i;if(typeof i=="string")try{l=JSON.parse(i)}catch{return{}}return l!==null&&typeof l=="object"&&!Array.isArray(l)?l:{}},ka=()=>{let{get:i,del:l,put:f}=me(),c=z(),[u,o]=(0,h.useState)([]),[e,C]=(0,h.useState)(!1),[r,m]=(0,h.useState)(null),[S,M]=(0,h.useState)("graph"),[H,d]=(0,h.useState)(null),[v,P]=(0,h.useState)(null),[D,$]=(0,h.useState)(null),[j,a]=(0,h.useState)(!1),[g,U]=(0,h.useState)(!0),[fe,le]=(0,h.useState)(!1),[ye,Se]=(0,h.useState)("learn"),[ce,ae]=(0,h.useState)({}),[oe,ie]=(0,h.useState)(null),[De,Y]=(0,h.useState)(!1),N=(0,h.useCallback)(async()=>{C(!0);try{let p=await i("/api/assistants");p.success&&p.data?.records&&o(p.data.records)}catch{w.error(c("governance.workbench.loadFailed"))}finally{C(!1)}},[i,c]);(0,h.useEffect)(()=>{N()},[N]);let J=h.default.useMemo(()=>xt(u),[u]),he=u.find(p=>p.id===r)??null,Me=(0,h.useCallback)((p,b="graph")=>{m(p),M(b),d(null),$(null)},[]),Ce=ut(),Q=(0,h.useCallback)((p,b)=>{let x=u.find(q=>q.id===p)?.name??c("governance.workbench.agentFallback");Ce({component_key:"agent_detail_side_app",data:{assistantId:p,initialTab:b},message:x})},[u,Ce,c]),de=(0,h.useCallback)(()=>{U(!0),a(!0)},[]),Ee=(0,h.useCallback)(p=>{let x={manual:{mode:"scratch",values:{}},external:{mode:"scratch",values:{type:"a2a_remote"}},learn:{mode:"learn",values:{}}}[p];Se(x.mode),ae(x.values),U(!1),a(!1),le(!0)},[]),Ae=(0,h.useCallback)(async(p,b)=>{let x=dn(p.graphDefinition),q;try{q=await f(`/api/assistants/${p.id}`,{name:b.name!==void 0?b.name:p.name,description:b.description!==void 0?b.description:p.description,graphDefinition:{...x,...b}})}catch(ve){throw w.error(c("governance.detail.saveFailed")),ve}if(!q.success)throw w.error(c("governance.detail.saveFailed")),new Error("Failed to save agent");w.success(c("common.saved")),N()},[f,N,c]),Ke=(0,h.useCallback)(p=>{o(b=>b.map(x=>x.id===p.id?p:x))},[]),K=(0,h.useCallback)(p=>{ie(p)},[]),be=(0,h.useCallback)(async()=>{if(oe){Y(!0);try{(await l(`/api/assistants/${oe}`)).success?(w.success(c("governance.detail.deleted")),o(b=>b.filter(x=>x.id!==oe)),N(),ie(null)):w.error(c("governance.detail.deleteFailed"))}catch{w.error(c("governance.detail.deleteFailed"))}finally{Y(!1)}}},[oe,l,N,c]),ke=(0,h.useCallback)(async p=>{if(!(await l(`/api/assistants/${p}`)).success)throw new Error("Failed to delete agent");w.success(c("governance.detail.deleted")),o(x=>x.filter(q=>q.id!==p)),N()},[l,N,c]);return(0,_.jsxs)("div",{style:{height:"100%",background:"#fafafa",overflow:"hidden"},children:[he?(0,_.jsx)(kt,{defaultProjectId:D??void 0,children:(0,_.jsx)(Rt,{assistant:he,allAssistants:u,onBack:()=>m(null),onDeleted:ke,onSave:Ae,onAssistantUpdated:Ke,onAgentListInvalidated:N,initialTab:S,initialMessage:H,initialMessageCustomRunConfig:v,initialProjectId:D})},he.id):(0,_.jsx)(_.Fragment,{children:(0,_.jsx)(Bt,{items:J,assistants:u,loading:e,onItemClick:p=>Q(p,"graph"),onOpenPlayground:p=>Q(p,"playground"),onOpenEval:p=>Q(p,"eval"),onCreate:de,onDelete:K})}),(0,_.jsx)(Ht,{open:j,onCancel:()=>{U(!0),a(!1)},onSelectMethod:Ee,focusTriggerAfterClose:g}),(0,_.jsx)(Ut,{open:fe,initialMode:ye,initialValues:ce,onCancel:()=>le(!1),onSuccess:(p,b)=>{le(!1),o(x=>x.some(ve=>ve.id===p.id)?x:[p,...x]),Me(p.id,"graph"),d(b?.initialMessage??null),P(b?.initialMessageCustomRunConfig??null),$(b?.projectId??null),N()}}),(0,_.jsx)(pe,{title:c("governance.deleteAgent"),open:oe!==null,onCancel:()=>ie(null),onOk:be,okText:c("common.delete"),okButtonProps:{danger:!0,loading:De},cancelText:c("common.cancel"),children:(0,_.jsx)("p",{children:c("governance.delete.irreversible")})})]})};export{ka as AgentGovernanceWorkbench};
@@ -1,3 +0,0 @@
1
- import{a as $e,b as Ge}from"./embed-page-chunk-OMN6G52V.js";import{b as Ue,c as be}from"./embed-page-chunk-RKQJBKN2.js";import"./embed-page-chunk-FE6KYRCO.js";import{f as Ye}from"./embed-page-chunk-DJKD2PHO.js";import"./embed-page-chunk-S4XZPBRM.js";import{S as Ke,j as He}from"./embed-page-chunk-Z6KWW64I.js";import{i as ee}from"./embed-page-chunk-7ULTMRM2.js";import{a as te}from"./embed-page-chunk-JMP7EQEF.js";import"./embed-page-chunk-FZX4A32D.js";import{Ea as q,Ha as ue,I as ce,Ja as Ne,O as pe,Ra as me,Sa as Z,Ta as qe,Y as je,_ as ge,aa as fe,fa as Ee,ia as _e,l as Oe,na as Fe,o as de,t as Pe,za as Be}from"./embed-page-chunk-F7ZUYG42.js";import{k as P}from"./embed-page-chunk-W5OP2CZG.js";import{a as E}from"./embed-page-chunk-QV7QAJ4N.js";import"./embed-page-chunk-VW3NF5NT.js";import"./embed-page-chunk-34RWKVD7.js";import{Ba as De,G as Te,Ja as le,Ra as Le,sa as Me}from"./embed-page-chunk-B2KNZ3EW.js";import{Da as X,Ia as J,Ja as ae,Ma as V,Oa as Ae,_ as $,ba as G,bb as Q,ha as U,qa as Ie}from"./embed-page-chunk-F7TA3LRH.js";import{a as se}from"./embed-page-chunk-R5QL57JJ.js";import"./embed-page-chunk-QOWM3LMZ.js";import"./embed-page-chunk-EUOOO2LS.js";import"./embed-page-chunk-5JDQ456X.js";import{f as A}from"./embed-page-chunk-QBTAJ2YI.js";var i=A(se());var oe=A(se());var j=A(E());function gt(r){let n=r.split(/[\n\r.。;;!!??]+/).filter(Boolean)[0]?.trim()||"";return n=n.replace(/[,,]+$/,"").trim(),n.length>50&&(n=n.slice(0,50)),n||(n=r.slice(0,50).trim()),n}function ft(r){let t=5381;for(let n=0;n<r.length;n++)t=(t<<5)+t+r.charCodeAt(n)>>>0;return t.toString(36).slice(0,6)}var we=({open:r,onCancel:t,onCreated:n,type:f="processing"})=>{let{post:D}=te(),l=P(),{trainingProjects:u,loading:w}=ee(),[g,m]=(0,oe.useState)(null),[y]=X.useForm(),b=u.find(h=>h.id===g)??u[0]??null;(0,oe.useEffect)(()=>{r&&(y.resetFields(),m(null))},[r,y]);let S=async()=>{if(f==="workflow"&&!b)return;let k=((await y.validateFields()).purpose||"").trim(),z=gt(k),I=`wf-${ft(k+Date.now())}`,p=f==="workflow"?{key:I,name:z,description:k,type:"workflow",prompt:"Complete the assigned task accurately and concisely.",metadata:{trainingProjectId:b?.id},workflowYaml:`name: ${I}
2
- steps: []
3
- `}:{key:I,name:z,description:k,type:"processing",prompt:`You are the orchestrator for workflow "${z}". Purpose: ${k}. Follow the topology to delegate tasks to sub-agents.`,tools:[],skills:[],subAgents:[],middleware:[{id:"topology",type:"topology",name:l("chatConfig.workflow.middleware.topologyName"),description:l("chatConfig.workflow.middleware.topologyDescription"),enabled:!0,config:{edges:[]}}]};await D("/api/assistants",{id:I,name:z,description:k,graphDefinition:p}),y.resetFields(),n(I,k,f==="workflow"?b?.id:void 0)};return(0,j.jsx)(V,{title:l(f==="workflow"?"chatConfig.workflow.create.title":"chatConfig.workflow.create.titleProcessing"),open:r,onCancel:t,onOk:S,okText:l("common.create"),okButtonProps:{disabled:f==="workflow"&&(w||!b)},destroyOnClose:!0,children:(0,j.jsxs)(X,{form:y,layout:"vertical",initialValues:{purpose:""},children:[(0,j.jsx)(X.Item,{name:"purpose",label:l("chatConfig.workflow.field.purpose"),rules:[{required:!0,message:l("chatConfig.workflow.validation.purposeRequired")}],children:(0,j.jsx)(J.TextArea,{placeholder:l("chatConfig.workflow.field.purposePlaceholder"),rows:4})}),f==="workflow"&&(0,j.jsx)($e,{project:b,projects:u,value:b?.id??null,onChange:m,loading:w})]})})};var Ve=A(se());var e=A(E()),{Text:ye}=Q;function ut(r){if(!r||typeof r!="object")return null;let t=r;return{modelKey:t.modelKey||t.model||void 0,tools:Array.isArray(t.tools)?t.tools:[],middleware:Array.isArray(t.middleware)?t.middleware.filter(n=>n&&typeof n=="object"&&n.type):[],subAgents:Array.isArray(t.subAgents)?t.subAgents:[],skillCategories:Array.isArray(t.skillCategories)?t.skillCategories:[],runConfig:t.runConfig&&typeof t.runConfig=="object"?t.runConfig:void 0}}var mt={filesystem:(0,e.jsx)(je,{size:12}),code_eval:(0,e.jsx)(Ne,{size:12}),browser:(0,e.jsx)(fe,{size:12}),sql:(0,e.jsx)(pe,{size:12}),skill:(0,e.jsx)(ue,{size:12}),http:(0,e.jsx)(_e,{size:12}),scheduler:(0,e.jsx)(ce,{size:12}),metrics:(0,e.jsx)(Oe,{size:12}),topology:(0,e.jsx)(ge,{size:12}),ask_user_to_clarify:(0,e.jsx)(Fe,{size:12}),widget:(0,e.jsx)(de,{size:12}),date:(0,e.jsx)(Pe,{size:12}),task:(0,e.jsx)(ge,{size:12}),custom:(0,e.jsx)(Be,{size:12}),claw:(0,e.jsx)(q,{size:12}),collection:(0,e.jsx)(Ee,{size:12})},bt={filesystem:{bg:"rgba(34,197,94,0.08)",text:"#16a34a",border:"rgba(34,197,94,0.2)"},code_eval:{bg:"rgba(99,102,241,0.08)",text:"#4f46e5",border:"rgba(99,102,241,0.2)"},browser:{bg:"rgba(59,130,246,0.08)",text:"#2563eb",border:"rgba(59,130,246,0.2)"},sql:{bg:"rgba(249,115,22,0.08)",text:"#ea580c",border:"rgba(249,115,22,0.2)"},skill:{bg:"rgba(168,85,247,0.08)",text:"#9333ea",border:"rgba(168,85,247,0.2)"},http:{bg:"rgba(20,184,166,0.08)",text:"#0d9488",border:"rgba(20,184,166,0.2)"},scheduler:{bg:"rgba(245,158,11,0.08)",text:"#d97706",border:"rgba(245,158,11,0.2)"},metrics:{bg:"rgba(236,72,153,0.08)",text:"#db2777",border:"rgba(236,72,153,0.2)"},topology:{bg:"rgba(99,102,241,0.08)",text:"#4f46e5",border:"rgba(99,102,241,0.2)"},ask_user_to_clarify:{bg:"rgba(245,158,11,0.08)",text:"#d97706",border:"rgba(245,158,11,0.2)"},widget:{bg:"rgba(20,184,166,0.08)",text:"#0d9488",border:"rgba(20,184,166,0.2)"},date:{bg:"rgba(139,92,246,0.08)",text:"#7c3aed",border:"rgba(139,92,246,0.2)"},task:{bg:"rgba(99,102,241,0.08)",text:"#4f46e5",border:"rgba(99,102,241,0.2)"},custom:{bg:"rgba(107,114,128,0.08)",text:"#4b5563",border:"rgba(107,114,128,0.2)"},claw:{bg:"rgba(107,114,128,0.08)",text:"#4b5563",border:"rgba(107,114,128,0.2)"},collection:{bg:"rgba(6,182,212,0.08)",text:"#0891b2",border:"rgba(6,182,212,0.2)"}},wt={bg:"rgba(107,114,128,0.08)",text:"#4b5563",border:"rgba(107,114,128,0.2)"};function yt(r){let t=r.split(/[_-]+/).filter(Boolean);return t.length===1?t[0].slice(0,2).toUpperCase():t.map(n=>n[0]).join("").toUpperCase().slice(0,2)}var Xe=[{bg:"rgba(99,102,241,0.1)",text:"#6366f1"},{bg:"rgba(34,197,94,0.1)",text:"#22c55e"},{bg:"rgba(245,158,11,0.1)",text:"#f59e0b"},{bg:"rgba(59,130,246,0.1)",text:"#3b82f6"},{bg:"rgba(239,68,68,0.1)",text:"#ef4444"},{bg:"rgba(168,85,247,0.1)",text:"#a855f7"},{bg:"rgba(20,184,166,0.1)",text:"#14b8a6"},{bg:"rgba(236,72,153,0.1)",text:"#ec4899"}];function Je(r){return Xe[r%Xe.length]}var H=({icon:r,label:t,count:n,children:f})=>(0,e.jsxs)("div",{style:{marginBottom:10},children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:6},children:[(0,e.jsx)("span",{style:{color:"#6366f1",display:"flex",alignItems:"center"},children:r}),(0,e.jsx)(ye,{strong:!0,style:{fontSize:11,color:"#52525b",textTransform:"uppercase",letterSpacing:"0.3px"},children:t}),(0,e.jsx)("span",{style:{fontSize:9,fontWeight:600,color:"#a1a1aa",background:"rgba(0,0,0,0.04)",borderRadius:8,padding:"1px 6px",lineHeight:"16px"},children:n})]}),f]}),Qe=({graphDef:r})=>{let t=P(),n=(0,Ve.useMemo)(()=>ut(r),[r]);if(!n)return null;let f=n.middleware.filter(l=>l.enabled!==!1),D=!1;return n.tools.length===0&&f.length===0&&n.subAgents.length===0?null:(0,e.jsx)("div",{style:{pointerEvents:"auto"},children:(0,e.jsxs)("div",{style:{background:"rgba(255,255,255,0.5)",borderRadius:8,width:250,transition:"all 0.25s ease",overflow:"hidden"},children:[(0,e.jsx)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",background:"rgba(99,102,241,0.02)",borderBottom:"1px solid rgba(0,0,0,0.03)"},children:(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,e.jsx)("div",{style:{width:24,height:24,borderRadius:6,background:"rgba(99,102,241,0.05)",display:"flex",alignItems:"center",justifyContent:"center",color:"#6366f1"},children:(0,e.jsx)(q,{size:13})}),(0,e.jsx)(ye,{strong:!0,style:{fontSize:12,color:"#1a1a1a"},children:t("chat.environment.title")})]})}),(0,e.jsxs)("div",{style:{padding:"10px 12px 12px",maxHeight:"calc(60vh - 48px)",overflowY:"auto"},children:[n.tools.length>0&&(0,e.jsx)(H,{icon:(0,e.jsx)(qe,{size:12}),label:t("chat.environment.tools"),count:n.tools.length,children:(0,e.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:n.tools.map((l,u)=>{let w=Je(u);return(0,e.jsx)(U,{title:l,placement:"top",children:(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",borderRadius:6,fontSize:10,fontWeight:500,color:w.text,background:w.bg,cursor:"default",whiteSpace:"nowrap",lineHeight:"16px"},children:[(0,e.jsx)("span",{style:{fontWeight:700,fontSize:9,opacity:.7},children:yt(l)}),(0,e.jsx)("span",{children:l})]})},l)})})}),f.length>0&&(0,e.jsx)(H,{icon:(0,e.jsx)(de,{size:12}),label:t("chat.environment.capabilities"),count:f.length,children:(0,e.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:f.map(l=>{let u=bt[l.type]||wt,w=mt[l.type]||(0,e.jsx)(q,{size:12});return(0,e.jsx)(U,{title:l.name||l.type,placement:"top",children:(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",borderRadius:6,fontSize:10,fontWeight:500,color:u.text,background:u.bg,border:`1px solid ${u.border}`,cursor:"default",whiteSpace:"nowrap",lineHeight:"16px"},children:[w,(0,e.jsx)("span",{children:l.name||l.type})]})},l.type)})})}),n.subAgents.length>0&&(0,e.jsx)(H,{icon:(0,e.jsx)(me,{size:12}),label:t("chat.environment.subAgents"),count:n.subAgents.length,children:(0,e.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:n.subAgents.map((l,u)=>{let w=Je(u+3);return(0,e.jsx)(U,{title:l,placement:"top",children:(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",borderRadius:6,fontSize:10,fontWeight:500,color:w.text,background:w.bg,cursor:"default",whiteSpace:"nowrap",lineHeight:"16px"},children:[(0,e.jsx)(me,{size:10}),(0,e.jsx)("span",{children:l})]})},l)})})}),(n.modelKey||n.runConfig)&&(0,e.jsx)(H,{icon:(0,e.jsx)(ce,{size:12}),label:t("chat.environment.runtime"),count:n.modelKey?1:0,children:(0,e.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:[n.modelKey&&(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",borderRadius:6,fontSize:10,fontWeight:500,color:"#4f46e5",background:"rgba(99,102,241,0.08)",border:"1px solid rgba(99,102,241,0.2)",cursor:"default",whiteSpace:"nowrap",lineHeight:"16px"},children:[(0,e.jsx)(q,{size:10}),(0,e.jsx)("span",{children:t("chat.environment.model",{model:n.modelKey})})]}),!!n.runConfig?.databaseKey&&(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",borderRadius:6,fontSize:10,fontWeight:500,color:"#ea580c",background:"rgba(249,115,22,0.08)",border:"1px solid rgba(249,115,22,0.2)",cursor:"default",whiteSpace:"nowrap",lineHeight:"16px"},children:[(0,e.jsx)(pe,{size:10}),(0,e.jsx)("span",{children:t("chat.environment.db",{db:String(n.runConfig?.databaseKey)})})]}),n.skillCategories&&n.skillCategories.length>0&&(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",borderRadius:6,fontSize:10,fontWeight:500,color:"#9333ea",background:"rgba(168,85,247,0.08)",border:"1px solid rgba(168,85,247,0.2)",cursor:"default",whiteSpace:"nowrap",lineHeight:"16px"},children:[(0,e.jsx)(ue,{size:10}),(0,e.jsx)("span",{children:t("chat.environment.skills",{skills:n.skillCategories.join(", ")})})]})]})}),D&&(0,e.jsx)(H,{icon:(0,e.jsx)(fe,{size:12}),label:t("chat.environment.channels"),count:0,children:(0,e.jsx)(ye,{type:"secondary",style:{fontSize:10,fontStyle:"italic"},children:t("chat.environment.noChannels")})})]})]})})};var o=A(E()),{Text:Y}=Q,ht=300;function Ze(r){if(typeof r=="string")try{let t=JSON.parse(r);return t&&typeof t=="object"&&!Array.isArray(t)?t:null}catch{return null}return r&&typeof r=="object"&&!Array.isArray(r)?r:null}function kt(r){let t=null;if(typeof r=="string")try{t=JSON.parse(r)}catch{return null}else r&&typeof r=="object"&&(t=r);if(!t)return null;if(t.type!=="workflow")return console.warn("[extractDSL] type is not 'workflow':",t.type),null;if(typeof t.workflowYaml!="string")return console.warn("[extractDSL] workflowYaml not found or not a string, keys:",Object.keys(t)),null;try{return be(t.workflowYaml)}catch(n){return console.error("[extractDSL] expandWorkflow failed:",n.message,n),null}}function xt({workflows:r,selectedId:t,onSelect:n,onCreate:f,onDelete:D,dsl:l,agentNameMap:u,onSpecClick:w,environmentConfig:g}){let m=P(),y=r.find(p=>p.id===t),[b,S]=(0,i.useState)(!0),[h,k]=(0,i.useState)(""),z=(0,i.useMemo)(()=>{let p=h.trim().toLowerCase();return p?r.filter(x=>x.name.toLowerCase().includes(p)||x.description.toLowerCase().includes(p)):r},[r,h]);(0,i.useEffect)(()=>{t?S(!1):(S(!0),k(""))},[t]);let I=p=>{n(p),S(!1)};return(0,o.jsx)("div",{style:{display:"flex",height:"100%",width:"100%"},children:(0,o.jsxs)("div",{style:{flex:1,position:"relative"},children:[y?(0,o.jsxs)(o.Fragment,{children:[l?(0,o.jsx)(Ue,{dsl:l,agentNameMap:u}):(0,o.jsx)("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:(0,o.jsx)(ae,{tip:m("chatWorkspace.workflowAutomation.loadingDsl")})}),!b&&(0,o.jsx)("div",{style:{position:"absolute",top:12,left:12,zIndex:10},children:(0,o.jsx)($,{type:"default",icon:(0,o.jsx)(De,{}),onClick:()=>S(!0),style:{width:32,height:32,borderRadius:10,boxShadow:"0 2px 12px rgba(0,0,0,0.08)",border:"1px solid #f0f0f0",background:"rgba(255,255,255,0.95)",color:"#6366f1",display:"flex",alignItems:"center",justifyContent:"center"}})}),(0,o.jsxs)("div",{style:{position:"absolute",top:12,left:b?12:56,zIndex:10,display:"flex",alignItems:"center",gap:6,height:32,padding:"0 14px",background:"rgba(255,255,255,0.95)",borderRadius:10,boxShadow:"0 2px 12px rgba(0,0,0,0.08)",border:"1px solid #f0f0f0"},children:[(0,o.jsx)(Z,{size:16,color:"#6366f1"}),(0,o.jsx)(Y,{strong:!0,style:{fontSize:13},children:y.name}),(0,o.jsx)(Me,{style:{color:"#6366f1",cursor:"pointer",fontSize:15},onClick:w})]}),(0,o.jsx)("div",{style:{position:"absolute",top:12,right:12,zIndex:10,display:"flex",alignItems:"center",height:32,padding:"0 14px",background:"rgba(255,255,255,0.95)",borderRadius:10,boxShadow:"0 2px 12px rgba(0,0,0,0.08)",border:"1px solid #f0f0f0"},children:(0,o.jsx)(Ae,{title:m("chatWorkspace.workflowAutomation.deleteTitle"),description:m("chatWorkspace.workflowAutomation.deleteBody"),onConfirm:()=>D(y.id),okText:m("common.delete"),cancelText:m("common.cancel"),okButtonProps:{danger:!0},children:(0,o.jsx)(Te,{style:{color:"#ff4d4f",cursor:"pointer",fontSize:15}})})}),!b&&(0,o.jsx)("div",{style:{position:"absolute",top:52,left:b?12:56,zIndex:20},children:(0,o.jsx)(Qe,{graphDef:g},y.id)})]}):(0,o.jsx)("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:(0,o.jsx)(G,{description:m("chatWorkspace.workflowAutomation.selectWorkflow")})}),b&&(0,o.jsxs)(o.Fragment,{children:[t&&(0,o.jsx)("div",{onClick:()=>S(!1),style:{position:"absolute",inset:0,zIndex:25,background:"transparent"}}),(0,o.jsxs)(Ie,{size:"small",title:(0,o.jsx)(Y,{strong:!0,style:{fontSize:15,color:"#1a1a1a"},children:m("chatWorkspace.workflowAutomation.title")}),extra:(0,o.jsx)($,{type:"text",size:"small",icon:(0,o.jsx)(le,{}),onClick:f,style:{color:"#6366f1"}}),styles:{body:{padding:"12px 16px 16px"},header:{padding:"14px 16px 10px",borderBottom:"1px solid rgba(0,0,0,0.04)"}},style:{position:"absolute",left:16,top:t?56:48,bottom:16,width:300,zIndex:30,borderRadius:16,boxShadow:"0 4px 24px rgba(0,0,0,0.12)",border:"1px solid #f0f0f0",overflow:"auto",background:"rgba(255, 255, 255, 0.92)"},children:[(0,o.jsx)("div",{style:{marginBottom:12},children:(0,o.jsx)(J,{prefix:(0,o.jsx)(Le,{style:{color:"#bbb"}}),placeholder:m("chatWorkspace.workflowAutomation.filterPlaceholder"),value:h,onChange:p=>k(p.target.value),allowClear:!0,size:"small",style:{borderRadius:10,border:"1px solid rgba(0,0,0,0.06)"}})}),z.length===0?(0,o.jsxs)("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"32px 16px",color:"#bbb"},children:[(0,o.jsx)(Z,{size:28,style:{marginBottom:10,opacity:.4}}),(0,o.jsx)(Y,{type:"secondary",style:{fontSize:13},children:h.trim()?m("chatWorkspace.workflowAutomation.noMatch"):m("chatWorkspace.workflowAutomation.emptyTitle")})]}):z.map(p=>{let x=t===p.id;return(0,o.jsxs)("div",{onClick:()=>I(p.id),style:{display:"flex",alignItems:"center",gap:12,padding:"13px 15px",borderRadius:12,cursor:"pointer",transition:"all 0.2s ease",background:x?"rgba(99, 102, 241, 0.07)":"rgba(255, 255, 255, 0.5)",border:x?"1px solid rgba(99, 102, 241, 0.25)":"1px solid transparent",marginBottom:6},onMouseEnter:R=>{x||(R.currentTarget.style.background="rgba(255, 255, 255, 0.92)",R.currentTarget.style.boxShadow="0 2px 8px rgba(0,0,0,0.05)",R.currentTarget.style.transform="translateY(-1px)",R.currentTarget.style.borderColor="rgba(0,0,0,0.06)")},onMouseLeave:R=>{x||(R.currentTarget.style.background="rgba(255, 255, 255, 0.5)",R.currentTarget.style.boxShadow="none",R.currentTarget.style.transform="translateY(0)",R.currentTarget.style.borderColor="transparent")},children:[(0,o.jsx)("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:38,height:38,borderRadius:10,background:x?"rgba(99, 102, 241, 0.12)":"rgba(0, 0, 0, 0.04)",flexShrink:0,transition:"background 0.2s ease"},children:(0,o.jsx)(Z,{size:18,color:x?"#6366f1":"#888"})}),(0,o.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,o.jsx)(Y,{strong:!0,ellipsis:{tooltip:p.name},style:{fontSize:14,color:x?"#6366f1":"#1a1a1a",transition:"color 0.2s ease"},children:p.name}),p.description&&(0,o.jsx)("div",{style:{fontSize:12,color:"#999",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",marginTop:3,lineHeight:"18px"},children:p.description})]})]},p.id)})]})]})]})})}var vt=()=>{let r=P(),{get:t,del:n}=te(),{workspaceId:f,trainingProjects:D,loading:l}=ee(),[u,w]=(0,i.useState)([]),[g,m]=(0,i.useState)(null),[y,b]=(0,i.useState)(null),[S,h]=(0,i.useState)(null),[k,z]=(0,i.useState)([]),[I,p]=(0,i.useState)(new Map),x=(0,i.useCallback)(async()=>{try{let s=await t("/api/assistants");if(s.success&&s.data?.records){let c=[],a=new Map;for(let d of s.data.records){if(d.id&&d.name){let v=typeof d.graphDefinition=="object"&&d.graphDefinition!==null?d.graphDefinition:void 0;a.set(d.id,{name:d.name,type:v?.type??"unknown"})}if(d.graphDefinition)if(typeof d.graphDefinition=="string")try{c.push(JSON.parse(d.graphDefinition))}catch{}else typeof d.graphDefinition=="object"&&c.push(d.graphDefinition)}z(c),p(a)}}catch{}},[t]),[R,he]=(0,i.useState)(!0),[ne,et]=(0,i.useState)(420),_=(0,i.useRef)(null),[tt,ot]=(0,i.useState)(!0),[ke,xe]=(0,i.useState)(null),[nt,ve]=(0,i.useState)(!1),[Ce,F]=(0,i.useState)(!1),[rt,Se]=(0,i.useState)(null),it=(0,i.useMemo)(()=>["create_workflow","update_workflow","validate_workflow","create_agent","update_agent","delete_agent"],[]),T=(0,i.useCallback)(async()=>{let s=await t("/api/assistants");if(s.success&&s.data?.records){let c=s.data.records.filter(a=>(Ze(a.graphDefinition)??void 0)?.type==="workflow").map(a=>{let d=Ze(a.graphDefinition)??void 0,v=typeof d?.workflowYaml=="string"?d.workflowYaml:"",B=d?.metadata,N=0;try{N=be(v).nodes.filter(W=>W.type!=="terminal").length}catch{}return{id:a.id,name:a.name,description:a.description||"",type:"workflow",stepCount:N,trainingProjectId:typeof B?.trainingProjectId=="string"?B.trainingProjectId:void 0}});w(c)}xe(null)},[t]),K=(0,i.useCallback)(async s=>{try{let c=await t(`/api/assistants/${s}`);if(c.success&&c.data){let a=c.data.graphDefinition,d=kt(a);if(b(d),!a)h(null);else if(typeof a=="string")try{h(JSON.parse(a))}catch{h(null)}else h(typeof a=="object"?a:null)}}catch{b(null),h(null)}},[t]);(0,i.useEffect)(()=>{let s=!1;return(async()=>{try{await T(),await x()}catch(a){s||xe(a instanceof Error?a.message:r("chatWorkspace.workflowAutomation.loadFailed"))}finally{s||ot(!1)}})(),()=>{s=!0}},[T]),(0,i.useEffect)(()=>{g?K(g):b(null)},[g,K]);let st=(0,i.useCallback)(s=>{s.preventDefault(),_.current={startX:s.clientX,startWidth:ne}},[ne]);(0,i.useEffect)(()=>{let s=a=>{if(!_.current)return;let d=_.current.startX-a.clientX,v=Math.min(900,Math.max(400,_.current.startWidth+d));et(v)},c=()=>{_.current=null};return window.addEventListener("mousemove",s),window.addEventListener("mouseup",c),()=>{window.removeEventListener("mousemove",s),window.removeEventListener("mouseup",c)}},[]);let L=(0,i.useRef)(null),Re=(0,i.useRef)({fetchWorkflows:T,fetchDSL:K});Re.current={fetchWorkflows:T,fetchDSL:K};let We=(0,i.useRef)(g);We.current=g;let at=(0,i.useCallback)(()=>{L.current&&clearTimeout(L.current),L.current=setTimeout(()=>{L.current=null;let{fetchWorkflows:s,fetchDSL:c}=Re.current;s().catch(d=>{console.warn("Failed to refresh workflows:",d)});let a=We.current;a&&c(a).catch(d=>{console.warn("Failed to refresh workflow DSL:",d)})},ht)},[]);(0,i.useEffect)(()=>()=>{L.current&&(clearTimeout(L.current),L.current=null)},[]);let lt=(0,i.useCallback)(s=>{m(s)},[]),ze=(0,i.useCallback)((s,c,a)=>{F(!1),T().then(()=>{m(s),a&&w(d=>d.map(v=>v.id===s?{...v,trainingProjectId:a}:v)),c&&Se({requestId:s,content:c})})},[T]),dt=(0,i.useCallback)(async s=>{await n(`/api/assistants/${s}`),g===s&&m(null),await T()},[n,T,g]),O=(0,i.useMemo)(()=>u.find(s=>s.id===g)||null,[u,g]),re=O?.trainingProjectId??D[0]?.id??null,ct=(0,i.useMemo)(()=>g&&O?{id:g,name:O.name,type:"workflow"}:null,[g,O]),pt=(0,i.useMemo)(()=>{let s=y?.nodes.filter(C=>C.type!=="terminal"&&C.ref).map(C=>C.ref).filter((C,W,M)=>M.indexOf(C)===W)??[];if(s.length===0)return S;let c=k.filter(C=>{let W=C.key;return W&&s.includes(W)});if(c.length===0)return S;let a={...S??{}},d=new Set(a.tools??[]),v=[...a.middleware??[]],B=new Set(a.subAgents??[]),N=new Set(v.map(C=>C.type).filter(Boolean));for(let C of c){let W=C;for(let M of W.tools??[])d.add(M);for(let M of W.middleware??[]){let ie=M.type;ie&&!N.has(ie)&&(v.push(M),N.add(ie))}for(let M of W.subAgents??[])B.add(M)}return a.tools=Array.from(d),a.middleware=v,a.subAgents=Array.from(B),a},[y,S,k]);return tt?(0,o.jsx)("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:(0,o.jsx)(ae,{size:"large",tip:r("chatWorkspace.workflowAutomation.loading")})}):ke?(0,o.jsx)(G,{description:ke}):u.length===0?(0,o.jsxs)("div",{style:{width:"100%",height:"100%"},children:[(0,o.jsx)(we,{open:Ce,onCancel:()=>F(!1),onCreated:ze,type:"workflow"}),(0,o.jsx)(G,{description:r("chatWorkspace.workflowAutomation.noDefinitions"),children:(0,o.jsx)($,{type:"primary",icon:(0,o.jsx)(le,{}),onClick:()=>F(!0),children:r("chatWorkspace.workflowAutomation.createWorkflow")})})]}):(0,o.jsxs)("div",{style:{width:"100%",height:"100%"},children:[(0,o.jsx)(we,{open:Ce,onCancel:()=>F(!1),onCreated:ze,type:"workflow"}),(0,o.jsx)(V,{title:O?.name,open:nt,onCancel:()=>ve(!1),footer:null,width:"85vw",centered:!0,styles:{body:{maxHeight:"calc(85vh - 120px)",overflow:"auto",padding:"12px 24px 24px"}},children:O?.description?(0,o.jsx)(He,{content:O.description}):(0,o.jsx)(Y,{type:"secondary",children:r("chatWorkspace.workflowAutomation.noDescription")})}),(0,o.jsx)(Ye,{children:(0,o.jsxs)("div",{style:{height:"100%",width:"100%",position:"relative",overflow:"hidden"},children:[(0,o.jsx)(xt,{workflows:u,selectedId:g,onSelect:lt,onCreate:()=>F(!0),onDelete:dt,dsl:y,agentNameMap:I,onSpecClick:()=>ve(!0),environmentConfig:pt}),!R&&g&&(0,o.jsx)("div",{style:{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",zIndex:20},children:(0,o.jsx)("div",{onClick:()=>he(!0),style:{writingMode:"vertical-rl",textOrientation:"mixed",padding:"16px 8px",background:"#6366f1",color:"#fff",borderRadius:"8px 0 0 8px",cursor:"pointer",fontSize:12,fontWeight:500,userSelect:"none"},children:r("chatWorkspace.workflowAutomation.copilot")})}),R&&g&&re&&!l&&(0,o.jsxs)("div",{style:{position:"absolute",right:16,top:48,bottom:12,zIndex:15,width:ne,borderRadius:16,overflow:"hidden",boxShadow:"0 4px 24px rgba(0,0,0,0.12)"},children:[(0,o.jsx)("div",{onMouseDown:st,style:{position:"absolute",left:0,top:0,bottom:0,width:6,cursor:"ew-resize",zIndex:2,background:"transparent"}}),(0,o.jsx)(Ke,{defaultWorkspaceId:f??void 0,defaultProjectId:re??void 0,children:(0,o.jsx)(Ge,{workflowContext:ct,onClose:()=>he(!1),onToolCompleted:s=>{it.includes(s)&&at()},initialMessageRequest:rt,onInitialMessageSubmitted:s=>Se(c=>c?.requestId===s?null:c)})},`${f??"default"}:${re??"default"}`)]})]})})]})},Qt=vt;export{vt as WorkflowAutomationView,Qt as default};