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