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