@elqnt/agents 3.1.0 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +40 -0
  2. package/dist/{agent-models-C36pvpUb.d.mts → agent-models-DLQlC7N6.d.mts} +143 -2
  3. package/dist/{agent-models-C36pvpUb.d.ts → agent-models-DLQlC7N6.d.ts} +143 -2
  4. package/dist/api/index.d.mts +227 -5
  5. package/dist/api/index.d.ts +227 -5
  6. package/dist/api/index.js +54 -2
  7. package/dist/api/index.js.map +1 -1
  8. package/dist/api/index.mjs +53 -1
  9. package/dist/api/server.d.mts +4 -2
  10. package/dist/api/server.d.ts +4 -2
  11. package/dist/api/server.js +9 -1
  12. package/dist/api/server.js.map +1 -1
  13. package/dist/api/server.mjs +8 -0
  14. package/dist/api/server.mjs.map +1 -1
  15. package/dist/chunk-2JDVRL35.js +133 -0
  16. package/dist/chunk-2JDVRL35.js.map +1 -0
  17. package/dist/chunk-2QL3LLC3.mjs +1075 -0
  18. package/dist/chunk-2QL3LLC3.mjs.map +1 -0
  19. package/dist/chunk-3EHE4O57.mjs +133 -0
  20. package/dist/chunk-3EHE4O57.mjs.map +1 -0
  21. package/dist/{chunk-TPQS2XAW.js → chunk-3VM5TCJR.js} +8 -2
  22. package/dist/chunk-3VM5TCJR.js.map +1 -0
  23. package/dist/chunk-AF4QJD73.js +1075 -0
  24. package/dist/chunk-AF4QJD73.js.map +1 -0
  25. package/dist/{chunk-RAA5NKA7.js → chunk-BH2FIDFK.js} +224 -2
  26. package/dist/chunk-BH2FIDFK.js.map +1 -0
  27. package/dist/{chunk-NF6PGOXP.mjs → chunk-GOHHT3ET.mjs} +224 -2
  28. package/dist/chunk-GOHHT3ET.mjs.map +1 -0
  29. package/dist/{chunk-SXYTVNKJ.mjs → chunk-ZK27UGO6.mjs} +7 -1
  30. package/dist/{chunk-SXYTVNKJ.mjs.map → chunk-ZK27UGO6.mjs.map} +1 -1
  31. package/dist/hooks/index.d.mts +224 -67
  32. package/dist/hooks/index.d.ts +224 -67
  33. package/dist/hooks/index.js +8 -3
  34. package/dist/hooks/index.js.map +1 -1
  35. package/dist/hooks/index.mjs +11 -6
  36. package/dist/index.d.mts +7 -5
  37. package/dist/index.d.ts +7 -5
  38. package/dist/index.js +67 -4
  39. package/dist/index.js.map +1 -1
  40. package/dist/index.mjs +70 -7
  41. package/dist/models/index.d.mts +3 -131
  42. package/dist/models/index.d.ts +3 -131
  43. package/dist/models/index.js +8 -2
  44. package/dist/models/index.js.map +1 -1
  45. package/dist/models/index.mjs +7 -1
  46. package/dist/{integration-21IuOOeV.d.mts → sandbox-DOxoM2Ge.d.mts} +132 -1
  47. package/dist/{integration-21IuOOeV.d.ts → sandbox-DOxoM2Ge.d.ts} +132 -1
  48. package/dist/transport/index.d.mts +36 -0
  49. package/dist/transport/index.d.ts +36 -0
  50. package/dist/transport/index.js +8 -0
  51. package/dist/transport/index.js.map +1 -0
  52. package/dist/transport/index.mjs +8 -0
  53. package/dist/transport/index.mjs.map +1 -0
  54. package/dist/types-C2qd5f-E.d.mts +51 -0
  55. package/dist/types-k9PszCzt.d.ts +51 -0
  56. package/dist/utils/index.d.mts +1 -1
  57. package/dist/utils/index.d.ts +1 -1
  58. package/package.json +10 -4
  59. package/dist/chunk-NF6PGOXP.mjs.map +0 -1
  60. package/dist/chunk-RAA5NKA7.js.map +0 -1
  61. package/dist/chunk-RWFVHX2J.js +0 -585
  62. package/dist/chunk-RWFVHX2J.js.map +0 -1
  63. package/dist/chunk-TPQS2XAW.js.map +0 -1
  64. package/dist/chunk-X4MSBDTZ.mjs +0 -585
  65. package/dist/chunk-X4MSBDTZ.mjs.map +0 -1
@@ -0,0 +1,1075 @@
1
+ "use client";
2
+ import {
3
+ checkBackgroundAgentStatusApi,
4
+ completeSchedulerTaskApi,
5
+ connectIntegrationApi,
6
+ createAgentApi,
7
+ createAgentJobApi,
8
+ createSandboxApi,
9
+ createScheduleApi,
10
+ createSchedulerTaskApi,
11
+ createSkillApi,
12
+ createSubAgentApi,
13
+ createToolDefinitionApi,
14
+ createWidgetApi,
15
+ deleteAgentApi,
16
+ deleteAgentJobApi,
17
+ deleteSandboxApi,
18
+ deleteScheduleApi,
19
+ deleteSchedulerTaskApi,
20
+ deleteSkillApi,
21
+ deleteSkillUserConfigApi,
22
+ deleteSubAgentApi,
23
+ deleteToolDefinitionApi,
24
+ deleteWidgetApi,
25
+ disconnectIntegrationApi,
26
+ getAgentApi,
27
+ getAgentCSATAnalyticsApi,
28
+ getAgentChatsAnalyticsApi,
29
+ getAgentJobApi,
30
+ getAgentListAnalyticsApi,
31
+ getDefaultAgentApi,
32
+ getDefaultWidgetApi,
33
+ getIntegrationApi,
34
+ getSandboxApi,
35
+ getScheduleApi,
36
+ getSchedulerTaskApi,
37
+ getSkillApi,
38
+ getSkillCategoriesApi,
39
+ getSkillUserConfigApi,
40
+ getSubAgentApi,
41
+ getTaskOutcomesApi,
42
+ getToolDefinitionApi,
43
+ getToolDefinitionsByIdsApi,
44
+ getWidgetApi,
45
+ listAgentJobsApi,
46
+ listAgentsApi,
47
+ listAgentsSummaryApi,
48
+ listIntegrationsApi,
49
+ listSandboxesApi,
50
+ listSchedulerTasksApi,
51
+ listSchedulesApi,
52
+ listSkillUserConfigsApi,
53
+ listSkillsApi,
54
+ listSubAgentsApi,
55
+ listToolDefinitionsApi,
56
+ listWidgetsApi,
57
+ pauseAgentJobApi,
58
+ pauseScheduleApi,
59
+ refreshIntegrationApi,
60
+ resolveSkillConfigApi,
61
+ resumeAgentJobApi,
62
+ resumeScheduleApi,
63
+ runEmailTriageApi,
64
+ runScheduleApi,
65
+ setDefaultWidgetApi,
66
+ snoozeSchedulerTaskApi,
67
+ startSchedulerTaskApi,
68
+ triggerBackgroundAgentApi,
69
+ updateAgentApi,
70
+ updateAgentJobApi,
71
+ updateIntegrationTriageApi,
72
+ updateSandboxApi,
73
+ updateScheduleApi,
74
+ updateSchedulerTaskApi,
75
+ updateSkillApi,
76
+ updateSkillUserConfigApi,
77
+ updateSubAgentApi,
78
+ updateToolDefinitionApi,
79
+ updateWidgetApi
80
+ } from "./chunk-GOHHT3ET.mjs";
81
+ import {
82
+ createBGAgentTransport
83
+ } from "./chunk-3EHE4O57.mjs";
84
+
85
+ // hooks/use-agents.ts
86
+ import { useMemo } from "react";
87
+ import { useApiAsync } from "@elqnt/api-client/hooks";
88
+
89
+ // hooks/use-options-ref.ts
90
+ import { useRef, useEffect } from "react";
91
+ function useOptionsRef(options) {
92
+ const optionsRef = useRef(options);
93
+ useEffect(() => {
94
+ optionsRef.current = options;
95
+ }, [options]);
96
+ return optionsRef;
97
+ }
98
+
99
+ // hooks/use-agents.ts
100
+ function useAgents(options) {
101
+ const optionsRef = useOptionsRef(options);
102
+ const { execute: listAgents, loading: listLoading, error: listError } = useApiAsync(
103
+ () => listAgentsApi(optionsRef.current),
104
+ (data) => data.agents,
105
+ []
106
+ );
107
+ const { execute: listAgentSummaries, loading: listSummaryLoading, error: listSummaryError } = useApiAsync(
108
+ () => listAgentsSummaryApi(optionsRef.current),
109
+ (data) => data.agents,
110
+ []
111
+ );
112
+ const { execute: getAgent, loading: getLoading, error: getError } = useApiAsync(
113
+ (agentId) => getAgentApi(agentId, optionsRef.current),
114
+ (data) => data.agent || null,
115
+ null
116
+ );
117
+ const { execute: createAgent, loading: createLoading, error: createError } = useApiAsync(
118
+ (agent) => createAgentApi(agent, optionsRef.current),
119
+ (data) => data.agent || null,
120
+ null
121
+ );
122
+ const { execute: updateAgent, loading: updateLoading, error: updateError } = useApiAsync(
123
+ (agentId, agent) => updateAgentApi(agentId, agent, optionsRef.current),
124
+ (data) => data.agent || null,
125
+ null
126
+ );
127
+ const { execute: deleteAgent, loading: deleteLoading, error: deleteError } = useApiAsync(
128
+ (agentId) => deleteAgentApi(agentId, optionsRef.current),
129
+ () => true,
130
+ false
131
+ );
132
+ const { execute: getDefaultAgent, loading: defaultLoading, error: defaultError } = useApiAsync(
133
+ () => getDefaultAgentApi(optionsRef.current),
134
+ (data) => data.agent || null,
135
+ null
136
+ );
137
+ const loading = listLoading || listSummaryLoading || getLoading || createLoading || updateLoading || deleteLoading || defaultLoading;
138
+ const error = listError || listSummaryError || getError || createError || updateError || deleteError || defaultError;
139
+ return useMemo(
140
+ () => ({
141
+ loading,
142
+ error,
143
+ listAgents,
144
+ listAgentSummaries,
145
+ getAgent,
146
+ createAgent,
147
+ updateAgent,
148
+ deleteAgent,
149
+ getDefaultAgent
150
+ }),
151
+ [loading, error, listAgents, listAgentSummaries, getAgent, createAgent, updateAgent, deleteAgent, getDefaultAgent]
152
+ );
153
+ }
154
+
155
+ // hooks/use-skills.ts
156
+ import { useMemo as useMemo2 } from "react";
157
+ import { useApiAsync as useApiAsync2 } from "@elqnt/api-client/hooks";
158
+ function useSkills(options) {
159
+ const optionsRef = useOptionsRef(options);
160
+ const { execute: listSkills, loading: listLoading, error: listError } = useApiAsync2(
161
+ () => listSkillsApi(optionsRef.current),
162
+ (data) => data.skills,
163
+ []
164
+ );
165
+ const { execute: getSkill, loading: getLoading, error: getError } = useApiAsync2(
166
+ (skillId) => getSkillApi(skillId, optionsRef.current),
167
+ (data) => data.skill || null,
168
+ null
169
+ );
170
+ const { execute: createSkill, loading: createLoading, error: createError } = useApiAsync2(
171
+ (skill) => createSkillApi(skill, optionsRef.current),
172
+ (data) => data.skill || null,
173
+ null
174
+ );
175
+ const { execute: updateSkill, loading: updateLoading, error: updateError } = useApiAsync2(
176
+ (skillId, skill) => updateSkillApi(skillId, skill, optionsRef.current),
177
+ (data) => data.skill || null,
178
+ null
179
+ );
180
+ const { execute: deleteSkill, loading: deleteLoading, error: deleteError } = useApiAsync2(
181
+ (skillId) => deleteSkillApi(skillId, optionsRef.current),
182
+ () => true,
183
+ false
184
+ );
185
+ const { execute: getCategories, loading: categoriesLoading, error: categoriesError } = useApiAsync2(
186
+ () => getSkillCategoriesApi(optionsRef.current),
187
+ (data) => data.categories,
188
+ []
189
+ );
190
+ const loading = listLoading || getLoading || createLoading || updateLoading || deleteLoading || categoriesLoading;
191
+ const error = listError || getError || createError || updateError || deleteError || categoriesError;
192
+ return useMemo2(
193
+ () => ({
194
+ loading,
195
+ error,
196
+ listSkills,
197
+ getSkill,
198
+ createSkill,
199
+ updateSkill,
200
+ deleteSkill,
201
+ getCategories
202
+ }),
203
+ [loading, error, listSkills, getSkill, createSkill, updateSkill, deleteSkill, getCategories]
204
+ );
205
+ }
206
+
207
+ // hooks/use-sub-agents.ts
208
+ import { useMemo as useMemo3 } from "react";
209
+ import { useApiAsync as useApiAsync3 } from "@elqnt/api-client/hooks";
210
+ function useSubAgents(options) {
211
+ const optionsRef = useOptionsRef(options);
212
+ const { execute: listSubAgents, loading: listLoading, error: listError } = useApiAsync3(
213
+ () => listSubAgentsApi(optionsRef.current),
214
+ (data) => data.subAgents,
215
+ []
216
+ );
217
+ const { execute: getSubAgent, loading: getLoading, error: getError } = useApiAsync3(
218
+ (subAgentId) => getSubAgentApi(subAgentId, optionsRef.current),
219
+ (data) => data.subAgent || null,
220
+ null
221
+ );
222
+ const { execute: createSubAgent, loading: createLoading, error: createError } = useApiAsync3(
223
+ (subAgent) => createSubAgentApi(subAgent, optionsRef.current),
224
+ (data) => data.subAgent || null,
225
+ null
226
+ );
227
+ const { execute: updateSubAgent, loading: updateLoading, error: updateError } = useApiAsync3(
228
+ (subAgentId, subAgent) => updateSubAgentApi(subAgentId, subAgent, optionsRef.current),
229
+ (data) => data.subAgent || null,
230
+ null
231
+ );
232
+ const { execute: deleteSubAgent, loading: deleteLoading, error: deleteError } = useApiAsync3(
233
+ (subAgentId) => deleteSubAgentApi(subAgentId, optionsRef.current),
234
+ () => true,
235
+ false
236
+ );
237
+ const loading = listLoading || getLoading || createLoading || updateLoading || deleteLoading;
238
+ const error = listError || getError || createError || updateError || deleteError;
239
+ return useMemo3(
240
+ () => ({
241
+ loading,
242
+ error,
243
+ listSubAgents,
244
+ getSubAgent,
245
+ createSubAgent,
246
+ updateSubAgent,
247
+ deleteSubAgent
248
+ }),
249
+ [loading, error, listSubAgents, getSubAgent, createSubAgent, updateSubAgent, deleteSubAgent]
250
+ );
251
+ }
252
+
253
+ // hooks/use-tool-definitions.ts
254
+ import { useMemo as useMemo4 } from "react";
255
+ import { useApiAsync as useApiAsync4 } from "@elqnt/api-client/hooks";
256
+ function useToolDefinitions(options) {
257
+ const optionsRef = useOptionsRef(options);
258
+ const { execute: listToolDefinitions, loading: listLoading, error: listError } = useApiAsync4(
259
+ () => listToolDefinitionsApi(optionsRef.current),
260
+ (data) => data.toolDefinitions,
261
+ []
262
+ );
263
+ const { execute: getToolDefinition, loading: getLoading, error: getError } = useApiAsync4(
264
+ (toolDefId) => getToolDefinitionApi(toolDefId, optionsRef.current),
265
+ (data) => data.toolDefinition || null,
266
+ null
267
+ );
268
+ const { execute: getToolDefinitionsByIds, loading: getByIdsLoading, error: getByIdsError } = useApiAsync4(
269
+ (ids) => getToolDefinitionsByIdsApi(ids, optionsRef.current),
270
+ (data) => data.toolDefinitions,
271
+ []
272
+ );
273
+ const { execute: createToolDefinition, loading: createLoading, error: createError } = useApiAsync4(
274
+ (toolDefinition) => createToolDefinitionApi(toolDefinition, optionsRef.current),
275
+ (data) => data.toolDefinition || null,
276
+ null
277
+ );
278
+ const { execute: updateToolDefinition, loading: updateLoading, error: updateError } = useApiAsync4(
279
+ (toolDefId, toolDefinition) => updateToolDefinitionApi(toolDefId, toolDefinition, optionsRef.current),
280
+ (data) => data.toolDefinition || null,
281
+ null
282
+ );
283
+ const { execute: deleteToolDefinition, loading: deleteLoading, error: deleteError } = useApiAsync4(
284
+ (toolDefId) => deleteToolDefinitionApi(toolDefId, optionsRef.current),
285
+ () => true,
286
+ false
287
+ );
288
+ const loading = listLoading || getLoading || getByIdsLoading || createLoading || updateLoading || deleteLoading;
289
+ const error = listError || getError || getByIdsError || createError || updateError || deleteError;
290
+ return useMemo4(
291
+ () => ({
292
+ loading,
293
+ error,
294
+ listToolDefinitions,
295
+ getToolDefinition,
296
+ getToolDefinitionsByIds,
297
+ createToolDefinition,
298
+ updateToolDefinition,
299
+ deleteToolDefinition
300
+ }),
301
+ [loading, error, listToolDefinitions, getToolDefinition, getToolDefinitionsByIds, createToolDefinition, updateToolDefinition, deleteToolDefinition]
302
+ );
303
+ }
304
+
305
+ // hooks/use-agent-jobs.ts
306
+ import { useMemo as useMemo5 } from "react";
307
+ import { useApiAsync as useApiAsync5 } from "@elqnt/api-client/hooks";
308
+ function useAgentJobs(options) {
309
+ const optionsRef = useOptionsRef(options);
310
+ const { execute: listAgentJobs, loading: listLoading, error: listError } = useApiAsync5(
311
+ () => listAgentJobsApi(optionsRef.current),
312
+ (data) => data.jobs,
313
+ []
314
+ );
315
+ const { execute: getAgentJob, loading: getLoading, error: getError } = useApiAsync5(
316
+ (jobId) => getAgentJobApi(jobId, optionsRef.current),
317
+ (data) => data.job || null,
318
+ null
319
+ );
320
+ const { execute: createAgentJob, loading: createLoading, error: createError } = useApiAsync5(
321
+ (job) => createAgentJobApi(job, optionsRef.current),
322
+ (data) => data.job || null,
323
+ null
324
+ );
325
+ const { execute: updateAgentJob, loading: updateLoading, error: updateError } = useApiAsync5(
326
+ (jobId, job) => updateAgentJobApi(jobId, job, optionsRef.current),
327
+ (data) => data.job || null,
328
+ null
329
+ );
330
+ const { execute: deleteAgentJob, loading: deleteLoading, error: deleteError } = useApiAsync5(
331
+ (jobId) => deleteAgentJobApi(jobId, optionsRef.current),
332
+ () => true,
333
+ false
334
+ );
335
+ const { execute: pauseAgentJob, loading: pauseLoading, error: pauseError } = useApiAsync5(
336
+ (jobId) => pauseAgentJobApi(jobId, optionsRef.current),
337
+ (data) => data.job || null,
338
+ null
339
+ );
340
+ const { execute: resumeAgentJob, loading: resumeLoading, error: resumeError } = useApiAsync5(
341
+ (jobId) => resumeAgentJobApi(jobId, optionsRef.current),
342
+ (data) => data.job || null,
343
+ null
344
+ );
345
+ const loading = listLoading || getLoading || createLoading || updateLoading || deleteLoading || pauseLoading || resumeLoading;
346
+ const error = listError || getError || createError || updateError || deleteError || pauseError || resumeError;
347
+ return useMemo5(
348
+ () => ({
349
+ loading,
350
+ error,
351
+ listAgentJobs,
352
+ getAgentJob,
353
+ createAgentJob,
354
+ updateAgentJob,
355
+ deleteAgentJob,
356
+ pauseAgentJob,
357
+ resumeAgentJob
358
+ }),
359
+ [loading, error, listAgentJobs, getAgentJob, createAgentJob, updateAgentJob, deleteAgentJob, pauseAgentJob, resumeAgentJob]
360
+ );
361
+ }
362
+
363
+ // hooks/use-widgets.ts
364
+ import { useMemo as useMemo6 } from "react";
365
+ import { useApiAsync as useApiAsync6 } from "@elqnt/api-client/hooks";
366
+ function useWidgets(options) {
367
+ const optionsRef = useOptionsRef(options);
368
+ const { execute: listWidgets, loading: listLoading, error: listError } = useApiAsync6(
369
+ () => listWidgetsApi(optionsRef.current.agentId, optionsRef.current),
370
+ (data) => data.widgets,
371
+ []
372
+ );
373
+ const { execute: getWidget, loading: getLoading, error: getError } = useApiAsync6(
374
+ (widgetId) => getWidgetApi(widgetId, optionsRef.current),
375
+ (data) => data.widget || null,
376
+ null
377
+ );
378
+ const { execute: getDefaultWidget, loading: defaultLoading, error: defaultError } = useApiAsync6(
379
+ () => getDefaultWidgetApi(optionsRef.current.agentId, optionsRef.current),
380
+ (data) => data.widget || null,
381
+ null
382
+ );
383
+ const { execute: createWidget, loading: createLoading, error: createError } = useApiAsync6(
384
+ (widget) => createWidgetApi(optionsRef.current.agentId, widget, optionsRef.current),
385
+ (data) => data.widget || null,
386
+ null
387
+ );
388
+ const { execute: updateWidget, loading: updateLoading, error: updateError } = useApiAsync6(
389
+ (widgetId, widget) => updateWidgetApi(widgetId, widget, optionsRef.current),
390
+ (data) => data.widget || null,
391
+ null
392
+ );
393
+ const { execute: deleteWidget, loading: deleteLoading, error: deleteError } = useApiAsync6(
394
+ (widgetId) => deleteWidgetApi(widgetId, optionsRef.current),
395
+ () => true,
396
+ false
397
+ );
398
+ const { execute: setDefaultWidget, loading: setDefaultLoading, error: setDefaultError } = useApiAsync6(
399
+ (widgetId) => setDefaultWidgetApi(widgetId, optionsRef.current.agentId, optionsRef.current),
400
+ () => true,
401
+ false
402
+ );
403
+ const loading = listLoading || getLoading || defaultLoading || createLoading || updateLoading || deleteLoading || setDefaultLoading;
404
+ const error = listError || getError || defaultError || createError || updateError || deleteError || setDefaultError;
405
+ return useMemo6(
406
+ () => ({
407
+ loading,
408
+ error,
409
+ listWidgets,
410
+ getWidget,
411
+ getDefaultWidget,
412
+ createWidget,
413
+ updateWidget,
414
+ deleteWidget,
415
+ setDefaultWidget
416
+ }),
417
+ [loading, error, listWidgets, getWidget, getDefaultWidget, createWidget, updateWidget, deleteWidget, setDefaultWidget]
418
+ );
419
+ }
420
+
421
+ // hooks/use-skill-user-config.ts
422
+ import { useMemo as useMemo7 } from "react";
423
+ import { useApiAsync as useApiAsync7 } from "@elqnt/api-client/hooks";
424
+ function useSkillUserConfig(options) {
425
+ const optionsRef = useOptionsRef(options);
426
+ const { execute: getSkillUserConfig, loading: getLoading, error: getError } = useApiAsync7(
427
+ (skillId, agentId) => getSkillUserConfigApi(skillId, { ...optionsRef.current, agentId }),
428
+ (data) => data.userConfig || null,
429
+ null
430
+ );
431
+ const { execute: updateSkillUserConfig, loading: updateLoading, error: updateError } = useApiAsync7(
432
+ (skillId, data) => updateSkillUserConfigApi(skillId, data, optionsRef.current),
433
+ (data) => data.userConfig || null,
434
+ null
435
+ );
436
+ const { execute: deleteSkillUserConfig, loading: deleteLoading, error: deleteError } = useApiAsync7(
437
+ (skillId, agentId) => deleteSkillUserConfigApi(skillId, { ...optionsRef.current, agentId }),
438
+ () => true,
439
+ false
440
+ );
441
+ const { execute: listSkillUserConfigs, loading: listLoading, error: listError } = useApiAsync7(
442
+ (params) => listSkillUserConfigsApi({ ...optionsRef.current, ...params }),
443
+ (data) => data.userConfigs || [],
444
+ []
445
+ );
446
+ const { execute: resolveSkillConfig, loading: resolveLoading, error: resolveError } = useApiAsync7(
447
+ (skillId, agentId) => resolveSkillConfigApi(skillId, agentId, optionsRef.current),
448
+ (data) => data,
449
+ null
450
+ );
451
+ const loading = getLoading || updateLoading || deleteLoading || listLoading || resolveLoading;
452
+ const error = getError || updateError || deleteError || listError || resolveError;
453
+ return useMemo7(
454
+ () => ({
455
+ loading,
456
+ error,
457
+ getSkillUserConfig,
458
+ updateSkillUserConfig,
459
+ deleteSkillUserConfig,
460
+ listSkillUserConfigs,
461
+ resolveSkillConfig
462
+ }),
463
+ [loading, error, getSkillUserConfig, updateSkillUserConfig, deleteSkillUserConfig, listSkillUserConfigs, resolveSkillConfig]
464
+ );
465
+ }
466
+
467
+ // hooks/use-analytics.ts
468
+ import { useMemo as useMemo8 } from "react";
469
+ import { useApiAsync as useApiAsync8 } from "@elqnt/api-client/hooks";
470
+ function useAnalytics(options) {
471
+ const optionsRef = useOptionsRef(options);
472
+ const { execute: getAgentChatsAnalytics, loading: chatsLoading, error: chatsError } = useApiAsync8(
473
+ (params) => getAgentChatsAnalyticsApi(params, optionsRef.current),
474
+ (data) => data.data,
475
+ []
476
+ );
477
+ const { execute: getAgentCSATAnalytics, loading: csatLoading, error: csatError } = useApiAsync8(
478
+ (params) => getAgentCSATAnalyticsApi(params, optionsRef.current),
479
+ (data) => data.data,
480
+ []
481
+ );
482
+ const { execute: getAgentListAnalytics, loading: listLoading, error: listError } = useApiAsync8(
483
+ () => getAgentListAnalyticsApi(optionsRef.current),
484
+ (data) => data.data,
485
+ []
486
+ );
487
+ const { execute: getTaskOutcomes, loading: taskLoading, error: taskError } = useApiAsync8(
488
+ (params) => getTaskOutcomesApi(params, optionsRef.current),
489
+ (data) => data.data,
490
+ []
491
+ );
492
+ const loading = chatsLoading || csatLoading || listLoading || taskLoading;
493
+ const error = chatsError || csatError || listError || taskError;
494
+ return useMemo8(
495
+ () => ({
496
+ loading,
497
+ error,
498
+ getAgentChatsAnalytics,
499
+ getAgentCSATAnalytics,
500
+ getAgentListAnalytics,
501
+ getTaskOutcomes
502
+ }),
503
+ [loading, error, getAgentChatsAnalytics, getAgentCSATAnalytics, getAgentListAnalytics, getTaskOutcomes]
504
+ );
505
+ }
506
+
507
+ // hooks/use-integrations.ts
508
+ import { useMemo as useMemo9 } from "react";
509
+ import { useApiAsync as useApiAsync9 } from "@elqnt/api-client/hooks";
510
+ function useIntegrations(options) {
511
+ const optionsRef = useOptionsRef(options);
512
+ const { execute: listIntegrations, loading: listLoading, error: listError } = useApiAsync9(
513
+ () => listIntegrationsApi(optionsRef.current),
514
+ (data) => data.integrations,
515
+ []
516
+ );
517
+ const { execute: getIntegration, loading: getLoading, error: getError } = useApiAsync9(
518
+ (provider, integrationType) => getIntegrationApi(provider, integrationType, optionsRef.current),
519
+ (data) => data.integration || null,
520
+ null
521
+ );
522
+ const { execute: connectIntegration, loading: connectLoading, error: connectError } = useApiAsync9(
523
+ (params) => connectIntegrationApi(params, optionsRef.current),
524
+ (data) => ({ authUrl: data.auth_url, state: data.state }),
525
+ null
526
+ );
527
+ const { execute: disconnectIntegration, loading: disconnectLoading, error: disconnectError } = useApiAsync9(
528
+ (params) => disconnectIntegrationApi(params, optionsRef.current),
529
+ () => true,
530
+ false
531
+ );
532
+ const { execute: refreshIntegration, loading: refreshLoading, error: refreshError } = useApiAsync9(
533
+ (params) => refreshIntegrationApi(params, optionsRef.current),
534
+ (data) => data.integration || null,
535
+ null
536
+ );
537
+ const { execute: updateTriage, loading: updateTriageLoading, error: updateTriageError } = useApiAsync9(
538
+ (params) => updateIntegrationTriageApi(params, optionsRef.current),
539
+ (data) => data.integration || null,
540
+ null
541
+ );
542
+ const { execute: runEmailTriage, loading: runTriageLoading, error: runTriageError } = useApiAsync9(
543
+ () => runEmailTriageApi(optionsRef.current),
544
+ (data) => ({ success: data.success, emailsFound: data.emails_found, instancesCreated: data.instances_created }),
545
+ null
546
+ );
547
+ const loading = listLoading || getLoading || connectLoading || disconnectLoading || refreshLoading || updateTriageLoading || runTriageLoading;
548
+ const error = listError || getError || connectError || disconnectError || refreshError || updateTriageError || runTriageError;
549
+ return useMemo9(
550
+ () => ({
551
+ loading,
552
+ error,
553
+ listIntegrations,
554
+ getIntegration,
555
+ connectIntegration,
556
+ disconnectIntegration,
557
+ refreshIntegration,
558
+ updateTriage,
559
+ runEmailTriage
560
+ }),
561
+ [loading, error, listIntegrations, getIntegration, connectIntegration, disconnectIntegration, refreshIntegration, updateTriage, runEmailTriage]
562
+ );
563
+ }
564
+
565
+ // hooks/use-sandbox.ts
566
+ import { useMemo as useMemo10 } from "react";
567
+ import { useApiAsync as useApiAsync10 } from "@elqnt/api-client/hooks";
568
+ function useSandbox(options) {
569
+ const optionsRef = useOptionsRef(options);
570
+ const { execute: createSandbox, loading: createLoading, error: createError } = useApiAsync10(
571
+ (request) => createSandboxApi(request, optionsRef.current),
572
+ (data) => ({ id: data.id, url: data.url, sandbox: data.sandbox }),
573
+ null
574
+ );
575
+ const { execute: getSandbox, loading: getLoading, error: getError } = useApiAsync10(
576
+ (sandboxId) => getSandboxApi(sandboxId, optionsRef.current),
577
+ (data) => data.sandbox || null,
578
+ null
579
+ );
580
+ const { execute: updateSandbox, loading: updateLoading, error: updateError } = useApiAsync10(
581
+ (sandboxId, request) => updateSandboxApi(sandboxId, request, optionsRef.current),
582
+ (data) => ({ id: data.id, url: data.url, sandbox: data.sandbox }),
583
+ null
584
+ );
585
+ const { execute: listSandboxes, loading: listLoading, error: listError } = useApiAsync10(
586
+ (limit) => listSandboxesApi({ ...optionsRef.current, limit }),
587
+ (data) => ({ sandboxes: data.sandboxes, total: data.total }),
588
+ { sandboxes: [], total: 0 }
589
+ );
590
+ const { execute: deleteSandbox, loading: deleteLoading, error: deleteError } = useApiAsync10(
591
+ (sandboxId) => deleteSandboxApi(sandboxId, optionsRef.current),
592
+ (data) => data.success,
593
+ false
594
+ );
595
+ const loading = createLoading || getLoading || updateLoading || listLoading || deleteLoading;
596
+ const error = createError || getError || updateError || listError || deleteError;
597
+ return useMemo10(
598
+ () => ({
599
+ loading,
600
+ error,
601
+ createSandbox,
602
+ getSandbox,
603
+ updateSandbox,
604
+ listSandboxes,
605
+ deleteSandbox
606
+ }),
607
+ [loading, error, createSandbox, getSandbox, updateSandbox, listSandboxes, deleteSandbox]
608
+ );
609
+ }
610
+
611
+ // hooks/use-scheduler-tasks.ts
612
+ import { useMemo as useMemo11 } from "react";
613
+ import { useApiAsync as useApiAsync11 } from "@elqnt/api-client/hooks";
614
+ function useSchedulerTasks(options) {
615
+ const optionsRef = useOptionsRef(options);
616
+ const { execute: listTasks, loading: listLoading, error: listError } = useApiAsync11(
617
+ (params) => listSchedulerTasksApi({ ...optionsRef.current, ...params }),
618
+ (data) => data.tasks,
619
+ []
620
+ );
621
+ const { execute: createTask, loading: createLoading, error: createError } = useApiAsync11(
622
+ (task) => createSchedulerTaskApi(task, optionsRef.current),
623
+ (data) => data.task || null,
624
+ null
625
+ );
626
+ const { execute: getTask, loading: getLoading, error: getError } = useApiAsync11(
627
+ (taskId) => getSchedulerTaskApi(taskId, optionsRef.current),
628
+ (data) => data.task || null,
629
+ null
630
+ );
631
+ const { execute: updateTask, loading: updateLoading, error: updateError } = useApiAsync11(
632
+ (taskId, task) => updateSchedulerTaskApi(taskId, task, optionsRef.current),
633
+ (data) => data.task || null,
634
+ null
635
+ );
636
+ const { execute: deleteTask, loading: deleteLoading, error: deleteError } = useApiAsync11(
637
+ (taskId) => deleteSchedulerTaskApi(taskId, optionsRef.current),
638
+ (data) => data.success,
639
+ false
640
+ );
641
+ const { execute: snoozeTask, loading: snoozeLoading, error: snoozeError } = useApiAsync11(
642
+ (taskId, delay) => snoozeSchedulerTaskApi(taskId, delay, optionsRef.current),
643
+ (data) => data.task || null,
644
+ null
645
+ );
646
+ const { execute: completeTask, loading: completeLoading, error: completeError } = useApiAsync11(
647
+ (taskId) => completeSchedulerTaskApi(taskId, optionsRef.current),
648
+ (data) => data.task || null,
649
+ null
650
+ );
651
+ const { execute: startTask, loading: startLoading, error: startError } = useApiAsync11(
652
+ (taskId) => startSchedulerTaskApi(taskId, optionsRef.current),
653
+ (data) => data.task || null,
654
+ null
655
+ );
656
+ const loading = listLoading || createLoading || getLoading || updateLoading || deleteLoading || snoozeLoading || completeLoading || startLoading;
657
+ const error = listError || createError || getError || updateError || deleteError || snoozeError || completeError || startError;
658
+ return useMemo11(
659
+ () => ({
660
+ loading,
661
+ error,
662
+ listTasks,
663
+ createTask,
664
+ getTask,
665
+ updateTask,
666
+ deleteTask,
667
+ snoozeTask,
668
+ completeTask,
669
+ startTask
670
+ }),
671
+ [loading, error, listTasks, createTask, getTask, updateTask, deleteTask, snoozeTask, completeTask, startTask]
672
+ );
673
+ }
674
+
675
+ // hooks/use-scheduler-schedules.ts
676
+ import { useMemo as useMemo12 } from "react";
677
+ import { useApiAsync as useApiAsync12 } from "@elqnt/api-client/hooks";
678
+ function useSchedulerSchedules(options) {
679
+ const optionsRef = useOptionsRef(options);
680
+ const { execute: listSchedules, loading: listLoading, error: listError } = useApiAsync12(
681
+ (params) => listSchedulesApi({ ...optionsRef.current, ...params }),
682
+ (data) => data.schedules,
683
+ []
684
+ );
685
+ const { execute: createSchedule, loading: createLoading, error: createError } = useApiAsync12(
686
+ (schedule) => createScheduleApi(schedule, optionsRef.current),
687
+ (data) => data.schedule || null,
688
+ null
689
+ );
690
+ const { execute: getSchedule, loading: getLoading, error: getError } = useApiAsync12(
691
+ (scheduleId) => getScheduleApi(scheduleId, optionsRef.current),
692
+ (data) => data.schedule || null,
693
+ null
694
+ );
695
+ const { execute: updateSchedule, loading: updateLoading, error: updateError } = useApiAsync12(
696
+ (scheduleId, schedule) => updateScheduleApi(scheduleId, schedule, optionsRef.current),
697
+ (data) => data.schedule || null,
698
+ null
699
+ );
700
+ const { execute: deleteSchedule, loading: deleteLoading, error: deleteError } = useApiAsync12(
701
+ (scheduleId) => deleteScheduleApi(scheduleId, optionsRef.current),
702
+ (data) => data.success,
703
+ false
704
+ );
705
+ const { execute: pauseSchedule, loading: pauseLoading, error: pauseError } = useApiAsync12(
706
+ (scheduleId) => pauseScheduleApi(scheduleId, optionsRef.current),
707
+ (data) => data.schedule || null,
708
+ null
709
+ );
710
+ const { execute: resumeSchedule, loading: resumeLoading, error: resumeError } = useApiAsync12(
711
+ (scheduleId) => resumeScheduleApi(scheduleId, optionsRef.current),
712
+ (data) => data.schedule || null,
713
+ null
714
+ );
715
+ const { execute: runSchedule, loading: runLoading, error: runError } = useApiAsync12(
716
+ (scheduleId) => runScheduleApi(scheduleId, optionsRef.current),
717
+ (data) => data.schedule || null,
718
+ null
719
+ );
720
+ const loading = listLoading || createLoading || getLoading || updateLoading || deleteLoading || pauseLoading || resumeLoading || runLoading;
721
+ const error = listError || createError || getError || updateError || deleteError || pauseError || resumeError || runError;
722
+ return useMemo12(
723
+ () => ({
724
+ loading,
725
+ error,
726
+ listSchedules,
727
+ createSchedule,
728
+ getSchedule,
729
+ updateSchedule,
730
+ deleteSchedule,
731
+ pauseSchedule,
732
+ resumeSchedule,
733
+ runSchedule
734
+ }),
735
+ [loading, error, listSchedules, createSchedule, getSchedule, updateSchedule, deleteSchedule, pauseSchedule, resumeSchedule, runSchedule]
736
+ );
737
+ }
738
+
739
+ // hooks/use-background-agents.ts
740
+ import { useState, useEffect as useEffect2, useRef as useRef2, useCallback, useMemo as useMemo13 } from "react";
741
+ import { useApiAsync as useApiAsync13 } from "@elqnt/api-client/hooks";
742
+ function useBackgroundAgents(options) {
743
+ const optionsRef = useOptionsRef(options);
744
+ const [liveStates, setLiveStates] = useState({});
745
+ const [watchedChats, setWatchedChats] = useState({});
746
+ const transportRef = useRef2(null);
747
+ const sseRef = useRef2(null);
748
+ const watchedChatKeyRef = useRef2(null);
749
+ useEffect2(() => {
750
+ const transport = createBGAgentTransport();
751
+ transport.connect({ streamBaseUrl: optionsRef.current.baseUrl });
752
+ transportRef.current = transport;
753
+ return () => {
754
+ transport.disconnect();
755
+ transportRef.current = null;
756
+ };
757
+ }, []);
758
+ const subscribedJobsRef = useRef2(/* @__PURE__ */ new Set());
759
+ const streamJob = useCallback((jobId) => {
760
+ const transport = transportRef.current;
761
+ if (!transport) return;
762
+ if (subscribedJobsRef.current.has(jobId)) return;
763
+ subscribedJobsRef.current.add(jobId);
764
+ setLiveStates((prev) => ({
765
+ ...prev,
766
+ [jobId]: prev[jobId] || { status: "running", progressLog: [], latestMessage: "Starting..." }
767
+ }));
768
+ transport.on("bg_agent.round", (event) => {
769
+ if (event.jobId !== jobId || !event.content) return;
770
+ setLiveStates((prev) => {
771
+ const cur = prev[jobId] || { status: "running", progressLog: [], latestMessage: "" };
772
+ return {
773
+ ...prev,
774
+ [jobId]: { ...cur, status: "running", progressLog: [...cur.progressLog, event.content], latestMessage: event.content }
775
+ };
776
+ });
777
+ });
778
+ transport.on("bg_agent.completed", (event) => {
779
+ if (event.jobId !== jobId) return;
780
+ subscribedJobsRef.current.delete(jobId);
781
+ setLiveStates((prev) => ({
782
+ ...prev,
783
+ [jobId]: { ...prev[jobId] || { progressLog: [], latestMessage: "" }, status: "completed", result: event.result, latestMessage: event.result || "Completed" }
784
+ }));
785
+ });
786
+ transport.on("bg_agent.failed", (event) => {
787
+ if (event.jobId !== jobId) return;
788
+ subscribedJobsRef.current.delete(jobId);
789
+ setLiveStates((prev) => ({
790
+ ...prev,
791
+ [jobId]: { ...prev[jobId] || { progressLog: [], latestMessage: "" }, status: "failed", error: event.error, latestMessage: event.error || "Failed" }
792
+ }));
793
+ });
794
+ transport.streamJob(jobId);
795
+ }, []);
796
+ const { execute: triggerAgent, loading: triggerLoading, error: triggerError } = useApiAsync13(
797
+ (request) => triggerBackgroundAgentApi(request, optionsRef.current),
798
+ (data) => data,
799
+ null
800
+ );
801
+ const { execute: checkStatus, loading: statusLoading, error: statusError } = useApiAsync13(
802
+ (jobId) => checkBackgroundAgentStatusApi(jobId, optionsRef.current),
803
+ (data) => data,
804
+ null
805
+ );
806
+ const { execute: listAgentSummaries, loading: summaryLoading, error: summaryError } = useApiAsync13(
807
+ () => listAgentsSummaryApi(optionsRef.current),
808
+ (data) => data.agents || [],
809
+ []
810
+ );
811
+ const createTask = useCallback(async (prompt, attachments) => {
812
+ const { chatServiceUrl, orgId, userId } = optionsRef.current;
813
+ if (!chatServiceUrl) {
814
+ console.error("chatServiceUrl is required for createTask");
815
+ return null;
816
+ }
817
+ if (!userId) {
818
+ console.error("userId is required for createTask");
819
+ return null;
820
+ }
821
+ try {
822
+ const createResponse = await fetch(`${chatServiceUrl}/create`, {
823
+ method: "POST",
824
+ headers: { "Content-Type": "application/json" },
825
+ body: JSON.stringify({
826
+ orgId,
827
+ userId,
828
+ metadata: {
829
+ agentName: "background_agent",
830
+ background: true,
831
+ userId,
832
+ userEmail: userId,
833
+ originalPrompt: prompt
834
+ }
835
+ })
836
+ });
837
+ if (!createResponse.ok) {
838
+ const errorText = await createResponse.text();
839
+ console.error("Failed to create background chat:", errorText);
840
+ return null;
841
+ }
842
+ const createData = await createResponse.json();
843
+ const chatKey = createData.data?.chatKey || createData.chatKey;
844
+ if (!chatKey) {
845
+ console.error("No chatKey returned from create");
846
+ return null;
847
+ }
848
+ const sendResponse = await fetch(`${chatServiceUrl}/send`, {
849
+ method: "POST",
850
+ headers: { "Content-Type": "application/json" },
851
+ body: JSON.stringify({
852
+ orgId,
853
+ userId,
854
+ chatKey,
855
+ message: {
856
+ role: "user",
857
+ content: prompt,
858
+ attachments: attachments || void 0
859
+ }
860
+ })
861
+ });
862
+ if (!sendResponse.ok) {
863
+ const errorText = await sendResponse.text();
864
+ console.error("Failed to send message:", errorText);
865
+ }
866
+ return chatKey;
867
+ } catch (err) {
868
+ console.error("Failed to create background task:", err);
869
+ return null;
870
+ }
871
+ }, []);
872
+ const watchChat = useCallback(async (chatKey) => {
873
+ const { chatServiceUrl, orgId, userId } = optionsRef.current;
874
+ if (!chatServiceUrl) {
875
+ console.error("chatServiceUrl is required for watchChat");
876
+ return;
877
+ }
878
+ if (!userId) {
879
+ console.error("userId is required for watchChat");
880
+ return;
881
+ }
882
+ if (sseRef.current && watchedChatKeyRef.current !== chatKey) {
883
+ sseRef.current.close();
884
+ sseRef.current = null;
885
+ }
886
+ watchedChatKeyRef.current = chatKey;
887
+ setWatchedChats((prev) => ({
888
+ ...prev,
889
+ [chatKey]: { chatKey, messages: [], status: "loading", statusHistory: [] }
890
+ }));
891
+ try {
892
+ const loadResponse = await fetch(`${chatServiceUrl}/load`, {
893
+ method: "POST",
894
+ headers: { "Content-Type": "application/json" },
895
+ body: JSON.stringify({ orgId, chatKey, userId })
896
+ });
897
+ if (!loadResponse.ok) {
898
+ const errorText = await loadResponse.text();
899
+ setWatchedChats((prev) => ({
900
+ ...prev,
901
+ [chatKey]: { chatKey, messages: [], status: "error", statusHistory: [], error: errorText || "Failed to load chat" }
902
+ }));
903
+ return;
904
+ }
905
+ const loadData = await loadResponse.json();
906
+ const chat = loadData.data?.chat || loadData.chat;
907
+ if (!chat) {
908
+ setWatchedChats((prev) => ({
909
+ ...prev,
910
+ [chatKey]: { chatKey, messages: [], status: "error", statusHistory: [], error: "No chat data returned" }
911
+ }));
912
+ return;
913
+ }
914
+ const bgStatus = chat.metadata?.backgroundStatus;
915
+ const bgMessage = chat.metadata?.backgroundStatusMessage;
916
+ let initialStatus = "active";
917
+ if (bgStatus === "completed") initialStatus = "completed";
918
+ else if (bgStatus === "failed") initialStatus = "error";
919
+ const initialStatusHistory = [];
920
+ setWatchedChats((prev) => ({
921
+ ...prev,
922
+ [chatKey]: {
923
+ chatKey,
924
+ messages: chat.messages || [],
925
+ status: initialStatus,
926
+ title: chat.title,
927
+ metadata: chat.metadata,
928
+ backgroundStatus: bgStatus,
929
+ backgroundStatusMessage: bgMessage,
930
+ statusHistory: initialStatusHistory
931
+ }
932
+ }));
933
+ const sseUrl = `${chatServiceUrl}/stream?orgId=${orgId}&userId=${userId}&chatId=${chatKey}&clientType=customer`;
934
+ const sse = new EventSource(sseUrl);
935
+ sseRef.current = sse;
936
+ const processEventData = (data) => {
937
+ console.log("[useBackgroundAgents] SSE event received:", data.type, data);
938
+ if (data.type === "message" && data.message) {
939
+ setWatchedChats((prev) => {
940
+ const current = prev[chatKey];
941
+ if (!current) return prev;
942
+ const msg = data.message;
943
+ const exists = current.messages.some((m) => m.id === msg.id);
944
+ if (exists) return prev;
945
+ return {
946
+ ...prev,
947
+ [chatKey]: {
948
+ ...current,
949
+ messages: [...current.messages, msg]
950
+ }
951
+ };
952
+ });
953
+ }
954
+ const eventData = data.data;
955
+ if (data.type === "agent_context_update" && eventData?.backgroundStatus) {
956
+ const bgStatus2 = eventData.backgroundStatus;
957
+ const bgMessage2 = eventData.backgroundStatusMessage;
958
+ const timestamp = Date.now();
959
+ console.log("[useBackgroundAgents] Background status update:", bgStatus2, bgMessage2);
960
+ setWatchedChats((prev) => {
961
+ const current = prev[chatKey];
962
+ if (!current) return prev;
963
+ const newStatus = bgStatus2 === "completed" ? "completed" : bgStatus2 === "failed" ? "error" : current.status;
964
+ const newHistory = [...current.statusHistory];
965
+ const lastEntry = newHistory[newHistory.length - 1];
966
+ if (!lastEntry || lastEntry.message !== bgMessage2 || lastEntry.status !== bgStatus2) {
967
+ newHistory.push({
968
+ status: bgStatus2,
969
+ message: bgMessage2 || "",
970
+ timestamp
971
+ });
972
+ }
973
+ return {
974
+ ...prev,
975
+ [chatKey]: {
976
+ ...current,
977
+ status: newStatus,
978
+ backgroundStatus: bgStatus2,
979
+ backgroundStatusMessage: bgMessage2,
980
+ statusHistory: newHistory
981
+ }
982
+ };
983
+ });
984
+ }
985
+ if (data.type === "chat_ended" || data.type === "agent_done") {
986
+ setWatchedChats((prev) => ({
987
+ ...prev,
988
+ [chatKey]: { ...prev[chatKey], status: "completed" }
989
+ }));
990
+ }
991
+ };
992
+ sse.onmessage = (event) => {
993
+ try {
994
+ const data = JSON.parse(event.data);
995
+ processEventData(data);
996
+ } catch (err) {
997
+ console.error("Failed to parse SSE event:", err);
998
+ }
999
+ };
1000
+ const customEventTypes = ["agent_context_update", "message", "chat_ended", "agent_done"];
1001
+ for (const eventType of customEventTypes) {
1002
+ sse.addEventListener(eventType, (event) => {
1003
+ try {
1004
+ const data = JSON.parse(event.data);
1005
+ processEventData(data);
1006
+ } catch (err) {
1007
+ console.error(`Failed to parse SSE ${eventType} event:`, err);
1008
+ }
1009
+ });
1010
+ }
1011
+ sse.onerror = () => {
1012
+ console.warn("SSE connection error for chat:", chatKey);
1013
+ };
1014
+ } catch (err) {
1015
+ console.error("Failed to watch chat:", err);
1016
+ setWatchedChats((prev) => ({
1017
+ ...prev,
1018
+ [chatKey]: { chatKey, messages: [], status: "error", statusHistory: [], error: String(err) }
1019
+ }));
1020
+ }
1021
+ }, []);
1022
+ const unwatchChat = useCallback((chatKey) => {
1023
+ if (watchedChatKeyRef.current === chatKey && sseRef.current) {
1024
+ sseRef.current.close();
1025
+ sseRef.current = null;
1026
+ watchedChatKeyRef.current = null;
1027
+ }
1028
+ setWatchedChats((prev) => {
1029
+ const next = { ...prev };
1030
+ delete next[chatKey];
1031
+ return next;
1032
+ });
1033
+ }, []);
1034
+ useEffect2(() => {
1035
+ return () => {
1036
+ if (sseRef.current) {
1037
+ sseRef.current.close();
1038
+ sseRef.current = null;
1039
+ }
1040
+ };
1041
+ }, []);
1042
+ const loading = triggerLoading || statusLoading || summaryLoading;
1043
+ const error = triggerError || statusError || summaryError;
1044
+ return useMemo13(() => ({
1045
+ liveStates,
1046
+ streamJob,
1047
+ createTask,
1048
+ watchChat,
1049
+ unwatchChat,
1050
+ watchedChats,
1051
+ triggerAgent,
1052
+ checkStatus,
1053
+ listAgentSummaries,
1054
+ loading,
1055
+ error
1056
+ }), [liveStates, streamJob, createTask, watchChat, unwatchChat, watchedChats, triggerAgent, checkStatus, listAgentSummaries, loading, error]);
1057
+ }
1058
+
1059
+ export {
1060
+ useOptionsRef,
1061
+ useAgents,
1062
+ useSkills,
1063
+ useSubAgents,
1064
+ useToolDefinitions,
1065
+ useAgentJobs,
1066
+ useWidgets,
1067
+ useSkillUserConfig,
1068
+ useAnalytics,
1069
+ useIntegrations,
1070
+ useSandbox,
1071
+ useSchedulerTasks,
1072
+ useSchedulerSchedules,
1073
+ useBackgroundAgents
1074
+ };
1075
+ //# sourceMappingURL=chunk-2QL3LLC3.mjs.map