@elqnt/agents 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{agent-models-C36pvpUb.d.mts → agent-models-DLQlC7N6.d.mts} +143 -2
- package/dist/{agent-models-C36pvpUb.d.ts → agent-models-DLQlC7N6.d.ts} +143 -2
- package/dist/api/index.d.mts +67 -5
- package/dist/api/index.d.ts +67 -5
- package/dist/api/index.js +18 -2
- package/dist/api/index.js.map +1 -1
- package/dist/api/index.mjs +17 -1
- package/dist/api/server.d.mts +10 -2
- package/dist/api/server.d.ts +10 -2
- package/dist/api/server.js +16 -1
- package/dist/api/server.js.map +1 -1
- package/dist/api/server.mjs +15 -0
- package/dist/api/server.mjs.map +1 -1
- package/dist/chunk-2JDVRL35.js +133 -0
- package/dist/chunk-2JDVRL35.js.map +1 -0
- package/dist/chunk-3EHE4O57.mjs +133 -0
- package/dist/chunk-3EHE4O57.mjs.map +1 -0
- package/dist/{chunk-FR422IHO.mjs → chunk-BT33DRUI.mjs} +67 -1
- package/dist/chunk-BT33DRUI.mjs.map +1 -0
- package/dist/{chunk-SXYTVNKJ.mjs → chunk-JCPMUFOP.mjs} +7 -1
- package/dist/{chunk-SXYTVNKJ.mjs.map → chunk-JCPMUFOP.mjs.map} +1 -1
- package/dist/{chunk-IUKM3T2S.js → chunk-KA7N4YTF.js} +69 -3
- package/dist/chunk-KA7N4YTF.js.map +1 -0
- package/dist/{chunk-V5GHDXSW.mjs → chunk-MNFZXJ2Y.mjs} +500 -157
- package/dist/chunk-MNFZXJ2Y.mjs.map +1 -0
- package/dist/chunk-PKLT6GDN.js +1114 -0
- package/dist/chunk-PKLT6GDN.js.map +1 -0
- package/dist/{chunk-TPQS2XAW.js → chunk-VGWUFWOE.js} +8 -2
- package/dist/chunk-VGWUFWOE.js.map +1 -0
- package/dist/hooks/index.d.mts +158 -70
- package/dist/hooks/index.d.ts +158 -70
- package/dist/hooks/index.js +4 -3
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +7 -6
- package/dist/index.d.mts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +27 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -7
- package/dist/models/index.d.mts +3 -2
- package/dist/models/index.d.ts +3 -2
- package/dist/models/index.js +8 -2
- package/dist/models/index.js.map +1 -1
- package/dist/models/index.mjs +7 -1
- package/dist/{sandbox-BHeWPjLU.d.mts → sandbox-DOxoM2Ge.d.mts} +1 -0
- package/dist/{sandbox-BHeWPjLU.d.ts → sandbox-DOxoM2Ge.d.ts} +1 -0
- package/dist/structured-Bs0IjwLD.d.mts +35 -0
- package/dist/structured-Bs0IjwLD.d.ts +35 -0
- package/dist/transport/index.d.mts +36 -0
- package/dist/transport/index.d.ts +36 -0
- package/dist/transport/index.js +8 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/index.mjs +8 -0
- package/dist/transport/index.mjs.map +1 -0
- package/dist/types-C2qd5f-E.d.mts +51 -0
- package/dist/types-k9PszCzt.d.ts +51 -0
- package/dist/utils/index.d.mts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/package.json +11 -5
- package/dist/chunk-FR422IHO.mjs.map +0 -1
- package/dist/chunk-IUKM3T2S.js.map +0 -1
- package/dist/chunk-RGVWAFZP.js +0 -771
- package/dist/chunk-RGVWAFZP.js.map +0 -1
- package/dist/chunk-TPQS2XAW.js.map +0 -1
- package/dist/chunk-V5GHDXSW.mjs.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
|
+
checkBackgroundAgentStatusApi,
|
|
3
4
|
completeSchedulerTaskApi,
|
|
4
5
|
connectIntegrationApi,
|
|
5
6
|
createAgentApi,
|
|
@@ -22,6 +23,7 @@ import {
|
|
|
22
23
|
deleteToolDefinitionApi,
|
|
23
24
|
deleteWidgetApi,
|
|
24
25
|
disconnectIntegrationApi,
|
|
26
|
+
exportAgentApi,
|
|
25
27
|
getAgentApi,
|
|
26
28
|
getAgentCSATAnalyticsApi,
|
|
27
29
|
getAgentChatsAnalyticsApi,
|
|
@@ -41,6 +43,7 @@ import {
|
|
|
41
43
|
getToolDefinitionApi,
|
|
42
44
|
getToolDefinitionsByIdsApi,
|
|
43
45
|
getWidgetApi,
|
|
46
|
+
importAgentApi,
|
|
44
47
|
listAgentJobsApi,
|
|
45
48
|
listAgentsApi,
|
|
46
49
|
listAgentsSummaryApi,
|
|
@@ -64,6 +67,8 @@ import {
|
|
|
64
67
|
setDefaultWidgetApi,
|
|
65
68
|
snoozeSchedulerTaskApi,
|
|
66
69
|
startSchedulerTaskApi,
|
|
70
|
+
structuredOutputApi,
|
|
71
|
+
triggerBackgroundAgentApi,
|
|
67
72
|
updateAgentApi,
|
|
68
73
|
updateAgentJobApi,
|
|
69
74
|
updateIntegrationTriageApi,
|
|
@@ -75,87 +80,26 @@ import {
|
|
|
75
80
|
updateSubAgentApi,
|
|
76
81
|
updateToolDefinitionApi,
|
|
77
82
|
updateWidgetApi
|
|
78
|
-
} from "./chunk-
|
|
83
|
+
} from "./chunk-BT33DRUI.mjs";
|
|
84
|
+
import {
|
|
85
|
+
createBGAgentTransport
|
|
86
|
+
} from "./chunk-3EHE4O57.mjs";
|
|
79
87
|
|
|
80
|
-
// hooks/
|
|
88
|
+
// hooks/use-agents.ts
|
|
81
89
|
import { useMemo } from "react";
|
|
82
|
-
|
|
83
|
-
// hooks/use-async.ts
|
|
84
|
-
import { useState, useCallback, useRef } from "react";
|
|
85
|
-
function useAsync(asyncFn, options) {
|
|
86
|
-
const [error, setError] = useState(null);
|
|
87
|
-
const requestCountRef = useRef(0);
|
|
88
|
-
const [loading, setLoading] = useState(false);
|
|
89
|
-
const execute = useCallback(
|
|
90
|
-
async (...args) => {
|
|
91
|
-
requestCountRef.current += 1;
|
|
92
|
-
setLoading(true);
|
|
93
|
-
setError(null);
|
|
94
|
-
try {
|
|
95
|
-
return await asyncFn(...args);
|
|
96
|
-
} catch (err) {
|
|
97
|
-
const message = err instanceof Error ? err.message : "An error occurred";
|
|
98
|
-
setError(message);
|
|
99
|
-
options?.onError?.(message);
|
|
100
|
-
throw err;
|
|
101
|
-
} finally {
|
|
102
|
-
requestCountRef.current -= 1;
|
|
103
|
-
if (requestCountRef.current === 0) {
|
|
104
|
-
setLoading(false);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
[asyncFn, options]
|
|
109
|
-
);
|
|
110
|
-
const clearError = useCallback(() => setError(null), []);
|
|
111
|
-
return { execute, loading, error, clearError };
|
|
112
|
-
}
|
|
113
|
-
function useApiAsync(asyncFn, extractor, defaultValue, options) {
|
|
114
|
-
const [error, setError] = useState(null);
|
|
115
|
-
const requestCountRef = useRef(0);
|
|
116
|
-
const [loading, setLoading] = useState(false);
|
|
117
|
-
const execute = useCallback(
|
|
118
|
-
async (...args) => {
|
|
119
|
-
requestCountRef.current += 1;
|
|
120
|
-
setLoading(true);
|
|
121
|
-
setError(null);
|
|
122
|
-
try {
|
|
123
|
-
const response = await asyncFn(...args);
|
|
124
|
-
if (response.error) {
|
|
125
|
-
setError(response.error);
|
|
126
|
-
options?.onError?.(response.error);
|
|
127
|
-
return defaultValue;
|
|
128
|
-
}
|
|
129
|
-
return response.data ? extractor(response.data) : defaultValue;
|
|
130
|
-
} catch (err) {
|
|
131
|
-
const message = err instanceof Error ? err.message : "An error occurred";
|
|
132
|
-
setError(message);
|
|
133
|
-
options?.onError?.(message);
|
|
134
|
-
return defaultValue;
|
|
135
|
-
} finally {
|
|
136
|
-
requestCountRef.current -= 1;
|
|
137
|
-
if (requestCountRef.current === 0) {
|
|
138
|
-
setLoading(false);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
},
|
|
142
|
-
[asyncFn, extractor, defaultValue, options]
|
|
143
|
-
);
|
|
144
|
-
const clearError = useCallback(() => setError(null), []);
|
|
145
|
-
return { execute, loading, error, clearError };
|
|
146
|
-
}
|
|
90
|
+
import { useApiAsync } from "@elqnt/api-client/hooks";
|
|
147
91
|
|
|
148
92
|
// hooks/use-options-ref.ts
|
|
149
|
-
import { useRef
|
|
93
|
+
import { useRef, useEffect } from "react";
|
|
150
94
|
function useOptionsRef(options) {
|
|
151
|
-
const optionsRef =
|
|
95
|
+
const optionsRef = useRef(options);
|
|
152
96
|
useEffect(() => {
|
|
153
97
|
optionsRef.current = options;
|
|
154
98
|
}, [options]);
|
|
155
99
|
return optionsRef;
|
|
156
100
|
}
|
|
157
101
|
|
|
158
|
-
// hooks/
|
|
102
|
+
// hooks/use-agents.ts
|
|
159
103
|
function useAgents(options) {
|
|
160
104
|
const optionsRef = useOptionsRef(options);
|
|
161
105
|
const { execute: listAgents, loading: listLoading, error: listError } = useApiAsync(
|
|
@@ -193,8 +137,25 @@ function useAgents(options) {
|
|
|
193
137
|
(data) => data.agent || null,
|
|
194
138
|
null
|
|
195
139
|
);
|
|
196
|
-
const
|
|
197
|
-
|
|
140
|
+
const exportAgent = async (agentId) => {
|
|
141
|
+
const agent = await exportAgentApi(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 } = useApiAsync(
|
|
153
|
+
(agent) => importAgentApi(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;
|
|
198
159
|
return useMemo(
|
|
199
160
|
() => ({
|
|
200
161
|
loading,
|
|
@@ -205,46 +166,52 @@ function useAgents(options) {
|
|
|
205
166
|
createAgent,
|
|
206
167
|
updateAgent,
|
|
207
168
|
deleteAgent,
|
|
208
|
-
getDefaultAgent
|
|
169
|
+
getDefaultAgent,
|
|
170
|
+
exportAgent,
|
|
171
|
+
importAgent
|
|
209
172
|
}),
|
|
210
|
-
[loading, error, listAgents, listAgentSummaries, getAgent, createAgent, updateAgent, deleteAgent, getDefaultAgent]
|
|
173
|
+
[loading, error, listAgents, listAgentSummaries, getAgent, createAgent, updateAgent, deleteAgent, getDefaultAgent, exportAgent, importAgent]
|
|
211
174
|
);
|
|
212
175
|
}
|
|
176
|
+
|
|
177
|
+
// hooks/use-skills.ts
|
|
178
|
+
import { useMemo as useMemo2 } from "react";
|
|
179
|
+
import { useApiAsync as useApiAsync2 } from "@elqnt/api-client/hooks";
|
|
213
180
|
function useSkills(options) {
|
|
214
181
|
const optionsRef = useOptionsRef(options);
|
|
215
|
-
const { execute: listSkills, loading: listLoading, error: listError } =
|
|
182
|
+
const { execute: listSkills, loading: listLoading, error: listError } = useApiAsync2(
|
|
216
183
|
() => listSkillsApi(optionsRef.current),
|
|
217
184
|
(data) => data.skills,
|
|
218
185
|
[]
|
|
219
186
|
);
|
|
220
|
-
const { execute: getSkill, loading: getLoading, error: getError } =
|
|
187
|
+
const { execute: getSkill, loading: getLoading, error: getError } = useApiAsync2(
|
|
221
188
|
(skillId) => getSkillApi(skillId, optionsRef.current),
|
|
222
189
|
(data) => data.skill || null,
|
|
223
190
|
null
|
|
224
191
|
);
|
|
225
|
-
const { execute: createSkill, loading: createLoading, error: createError } =
|
|
192
|
+
const { execute: createSkill, loading: createLoading, error: createError } = useApiAsync2(
|
|
226
193
|
(skill) => createSkillApi(skill, optionsRef.current),
|
|
227
194
|
(data) => data.skill || null,
|
|
228
195
|
null
|
|
229
196
|
);
|
|
230
|
-
const { execute: updateSkill, loading: updateLoading, error: updateError } =
|
|
197
|
+
const { execute: updateSkill, loading: updateLoading, error: updateError } = useApiAsync2(
|
|
231
198
|
(skillId, skill) => updateSkillApi(skillId, skill, optionsRef.current),
|
|
232
199
|
(data) => data.skill || null,
|
|
233
200
|
null
|
|
234
201
|
);
|
|
235
|
-
const { execute: deleteSkill, loading: deleteLoading, error: deleteError } =
|
|
202
|
+
const { execute: deleteSkill, loading: deleteLoading, error: deleteError } = useApiAsync2(
|
|
236
203
|
(skillId) => deleteSkillApi(skillId, optionsRef.current),
|
|
237
204
|
() => true,
|
|
238
205
|
false
|
|
239
206
|
);
|
|
240
|
-
const { execute: getCategories, loading: categoriesLoading, error: categoriesError } =
|
|
207
|
+
const { execute: getCategories, loading: categoriesLoading, error: categoriesError } = useApiAsync2(
|
|
241
208
|
() => getSkillCategoriesApi(optionsRef.current),
|
|
242
209
|
(data) => data.categories,
|
|
243
210
|
[]
|
|
244
211
|
);
|
|
245
212
|
const loading = listLoading || getLoading || createLoading || updateLoading || deleteLoading || categoriesLoading;
|
|
246
213
|
const error = listError || getError || createError || updateError || deleteError || categoriesError;
|
|
247
|
-
return
|
|
214
|
+
return useMemo2(
|
|
248
215
|
() => ({
|
|
249
216
|
loading,
|
|
250
217
|
error,
|
|
@@ -258,36 +225,40 @@ function useSkills(options) {
|
|
|
258
225
|
[loading, error, listSkills, getSkill, createSkill, updateSkill, deleteSkill, getCategories]
|
|
259
226
|
);
|
|
260
227
|
}
|
|
228
|
+
|
|
229
|
+
// hooks/use-sub-agents.ts
|
|
230
|
+
import { useMemo as useMemo3 } from "react";
|
|
231
|
+
import { useApiAsync as useApiAsync3 } from "@elqnt/api-client/hooks";
|
|
261
232
|
function useSubAgents(options) {
|
|
262
233
|
const optionsRef = useOptionsRef(options);
|
|
263
|
-
const { execute: listSubAgents, loading: listLoading, error: listError } =
|
|
234
|
+
const { execute: listSubAgents, loading: listLoading, error: listError } = useApiAsync3(
|
|
264
235
|
() => listSubAgentsApi(optionsRef.current),
|
|
265
236
|
(data) => data.subAgents,
|
|
266
237
|
[]
|
|
267
238
|
);
|
|
268
|
-
const { execute: getSubAgent, loading: getLoading, error: getError } =
|
|
239
|
+
const { execute: getSubAgent, loading: getLoading, error: getError } = useApiAsync3(
|
|
269
240
|
(subAgentId) => getSubAgentApi(subAgentId, optionsRef.current),
|
|
270
241
|
(data) => data.subAgent || null,
|
|
271
242
|
null
|
|
272
243
|
);
|
|
273
|
-
const { execute: createSubAgent, loading: createLoading, error: createError } =
|
|
244
|
+
const { execute: createSubAgent, loading: createLoading, error: createError } = useApiAsync3(
|
|
274
245
|
(subAgent) => createSubAgentApi(subAgent, optionsRef.current),
|
|
275
246
|
(data) => data.subAgent || null,
|
|
276
247
|
null
|
|
277
248
|
);
|
|
278
|
-
const { execute: updateSubAgent, loading: updateLoading, error: updateError } =
|
|
249
|
+
const { execute: updateSubAgent, loading: updateLoading, error: updateError } = useApiAsync3(
|
|
279
250
|
(subAgentId, subAgent) => updateSubAgentApi(subAgentId, subAgent, optionsRef.current),
|
|
280
251
|
(data) => data.subAgent || null,
|
|
281
252
|
null
|
|
282
253
|
);
|
|
283
|
-
const { execute: deleteSubAgent, loading: deleteLoading, error: deleteError } =
|
|
254
|
+
const { execute: deleteSubAgent, loading: deleteLoading, error: deleteError } = useApiAsync3(
|
|
284
255
|
(subAgentId) => deleteSubAgentApi(subAgentId, optionsRef.current),
|
|
285
256
|
() => true,
|
|
286
257
|
false
|
|
287
258
|
);
|
|
288
259
|
const loading = listLoading || getLoading || createLoading || updateLoading || deleteLoading;
|
|
289
260
|
const error = listError || getError || createError || updateError || deleteError;
|
|
290
|
-
return
|
|
261
|
+
return useMemo3(
|
|
291
262
|
() => ({
|
|
292
263
|
loading,
|
|
293
264
|
error,
|
|
@@ -300,41 +271,45 @@ function useSubAgents(options) {
|
|
|
300
271
|
[loading, error, listSubAgents, getSubAgent, createSubAgent, updateSubAgent, deleteSubAgent]
|
|
301
272
|
);
|
|
302
273
|
}
|
|
274
|
+
|
|
275
|
+
// hooks/use-tool-definitions.ts
|
|
276
|
+
import { useMemo as useMemo4 } from "react";
|
|
277
|
+
import { useApiAsync as useApiAsync4 } from "@elqnt/api-client/hooks";
|
|
303
278
|
function useToolDefinitions(options) {
|
|
304
279
|
const optionsRef = useOptionsRef(options);
|
|
305
|
-
const { execute: listToolDefinitions, loading: listLoading, error: listError } =
|
|
280
|
+
const { execute: listToolDefinitions, loading: listLoading, error: listError } = useApiAsync4(
|
|
306
281
|
() => listToolDefinitionsApi(optionsRef.current),
|
|
307
282
|
(data) => data.toolDefinitions,
|
|
308
283
|
[]
|
|
309
284
|
);
|
|
310
|
-
const { execute: getToolDefinition, loading: getLoading, error: getError } =
|
|
285
|
+
const { execute: getToolDefinition, loading: getLoading, error: getError } = useApiAsync4(
|
|
311
286
|
(toolDefId) => getToolDefinitionApi(toolDefId, optionsRef.current),
|
|
312
287
|
(data) => data.toolDefinition || null,
|
|
313
288
|
null
|
|
314
289
|
);
|
|
315
|
-
const { execute: getToolDefinitionsByIds, loading: getByIdsLoading, error: getByIdsError } =
|
|
290
|
+
const { execute: getToolDefinitionsByIds, loading: getByIdsLoading, error: getByIdsError } = useApiAsync4(
|
|
316
291
|
(ids) => getToolDefinitionsByIdsApi(ids, optionsRef.current),
|
|
317
292
|
(data) => data.toolDefinitions,
|
|
318
293
|
[]
|
|
319
294
|
);
|
|
320
|
-
const { execute: createToolDefinition, loading: createLoading, error: createError } =
|
|
295
|
+
const { execute: createToolDefinition, loading: createLoading, error: createError } = useApiAsync4(
|
|
321
296
|
(toolDefinition) => createToolDefinitionApi(toolDefinition, optionsRef.current),
|
|
322
297
|
(data) => data.toolDefinition || null,
|
|
323
298
|
null
|
|
324
299
|
);
|
|
325
|
-
const { execute: updateToolDefinition, loading: updateLoading, error: updateError } =
|
|
300
|
+
const { execute: updateToolDefinition, loading: updateLoading, error: updateError } = useApiAsync4(
|
|
326
301
|
(toolDefId, toolDefinition) => updateToolDefinitionApi(toolDefId, toolDefinition, optionsRef.current),
|
|
327
302
|
(data) => data.toolDefinition || null,
|
|
328
303
|
null
|
|
329
304
|
);
|
|
330
|
-
const { execute: deleteToolDefinition, loading: deleteLoading, error: deleteError } =
|
|
305
|
+
const { execute: deleteToolDefinition, loading: deleteLoading, error: deleteError } = useApiAsync4(
|
|
331
306
|
(toolDefId) => deleteToolDefinitionApi(toolDefId, optionsRef.current),
|
|
332
307
|
() => true,
|
|
333
308
|
false
|
|
334
309
|
);
|
|
335
310
|
const loading = listLoading || getLoading || getByIdsLoading || createLoading || updateLoading || deleteLoading;
|
|
336
311
|
const error = listError || getError || getByIdsError || createError || updateError || deleteError;
|
|
337
|
-
return
|
|
312
|
+
return useMemo4(
|
|
338
313
|
() => ({
|
|
339
314
|
loading,
|
|
340
315
|
error,
|
|
@@ -348,46 +323,50 @@ function useToolDefinitions(options) {
|
|
|
348
323
|
[loading, error, listToolDefinitions, getToolDefinition, getToolDefinitionsByIds, createToolDefinition, updateToolDefinition, deleteToolDefinition]
|
|
349
324
|
);
|
|
350
325
|
}
|
|
326
|
+
|
|
327
|
+
// hooks/use-agent-jobs.ts
|
|
328
|
+
import { useMemo as useMemo5 } from "react";
|
|
329
|
+
import { useApiAsync as useApiAsync5 } from "@elqnt/api-client/hooks";
|
|
351
330
|
function useAgentJobs(options) {
|
|
352
331
|
const optionsRef = useOptionsRef(options);
|
|
353
|
-
const { execute: listAgentJobs, loading: listLoading, error: listError } =
|
|
332
|
+
const { execute: listAgentJobs, loading: listLoading, error: listError } = useApiAsync5(
|
|
354
333
|
() => listAgentJobsApi(optionsRef.current),
|
|
355
334
|
(data) => data.jobs,
|
|
356
335
|
[]
|
|
357
336
|
);
|
|
358
|
-
const { execute: getAgentJob, loading: getLoading, error: getError } =
|
|
337
|
+
const { execute: getAgentJob, loading: getLoading, error: getError } = useApiAsync5(
|
|
359
338
|
(jobId) => getAgentJobApi(jobId, optionsRef.current),
|
|
360
339
|
(data) => data.job || null,
|
|
361
340
|
null
|
|
362
341
|
);
|
|
363
|
-
const { execute: createAgentJob, loading: createLoading, error: createError } =
|
|
342
|
+
const { execute: createAgentJob, loading: createLoading, error: createError } = useApiAsync5(
|
|
364
343
|
(job) => createAgentJobApi(job, optionsRef.current),
|
|
365
344
|
(data) => data.job || null,
|
|
366
345
|
null
|
|
367
346
|
);
|
|
368
|
-
const { execute: updateAgentJob, loading: updateLoading, error: updateError } =
|
|
347
|
+
const { execute: updateAgentJob, loading: updateLoading, error: updateError } = useApiAsync5(
|
|
369
348
|
(jobId, job) => updateAgentJobApi(jobId, job, optionsRef.current),
|
|
370
349
|
(data) => data.job || null,
|
|
371
350
|
null
|
|
372
351
|
);
|
|
373
|
-
const { execute: deleteAgentJob, loading: deleteLoading, error: deleteError } =
|
|
352
|
+
const { execute: deleteAgentJob, loading: deleteLoading, error: deleteError } = useApiAsync5(
|
|
374
353
|
(jobId) => deleteAgentJobApi(jobId, optionsRef.current),
|
|
375
354
|
() => true,
|
|
376
355
|
false
|
|
377
356
|
);
|
|
378
|
-
const { execute: pauseAgentJob, loading: pauseLoading, error: pauseError } =
|
|
357
|
+
const { execute: pauseAgentJob, loading: pauseLoading, error: pauseError } = useApiAsync5(
|
|
379
358
|
(jobId) => pauseAgentJobApi(jobId, optionsRef.current),
|
|
380
359
|
(data) => data.job || null,
|
|
381
360
|
null
|
|
382
361
|
);
|
|
383
|
-
const { execute: resumeAgentJob, loading: resumeLoading, error: resumeError } =
|
|
362
|
+
const { execute: resumeAgentJob, loading: resumeLoading, error: resumeError } = useApiAsync5(
|
|
384
363
|
(jobId) => resumeAgentJobApi(jobId, optionsRef.current),
|
|
385
364
|
(data) => data.job || null,
|
|
386
365
|
null
|
|
387
366
|
);
|
|
388
367
|
const loading = listLoading || getLoading || createLoading || updateLoading || deleteLoading || pauseLoading || resumeLoading;
|
|
389
368
|
const error = listError || getError || createError || updateError || deleteError || pauseError || resumeError;
|
|
390
|
-
return
|
|
369
|
+
return useMemo5(
|
|
391
370
|
() => ({
|
|
392
371
|
loading,
|
|
393
372
|
error,
|
|
@@ -402,46 +381,50 @@ function useAgentJobs(options) {
|
|
|
402
381
|
[loading, error, listAgentJobs, getAgentJob, createAgentJob, updateAgentJob, deleteAgentJob, pauseAgentJob, resumeAgentJob]
|
|
403
382
|
);
|
|
404
383
|
}
|
|
384
|
+
|
|
385
|
+
// hooks/use-widgets.ts
|
|
386
|
+
import { useMemo as useMemo6 } from "react";
|
|
387
|
+
import { useApiAsync as useApiAsync6 } from "@elqnt/api-client/hooks";
|
|
405
388
|
function useWidgets(options) {
|
|
406
389
|
const optionsRef = useOptionsRef(options);
|
|
407
|
-
const { execute: listWidgets, loading: listLoading, error: listError } =
|
|
390
|
+
const { execute: listWidgets, loading: listLoading, error: listError } = useApiAsync6(
|
|
408
391
|
() => listWidgetsApi(optionsRef.current.agentId, optionsRef.current),
|
|
409
392
|
(data) => data.widgets,
|
|
410
393
|
[]
|
|
411
394
|
);
|
|
412
|
-
const { execute: getWidget, loading: getLoading, error: getError } =
|
|
395
|
+
const { execute: getWidget, loading: getLoading, error: getError } = useApiAsync6(
|
|
413
396
|
(widgetId) => getWidgetApi(widgetId, optionsRef.current),
|
|
414
397
|
(data) => data.widget || null,
|
|
415
398
|
null
|
|
416
399
|
);
|
|
417
|
-
const { execute: getDefaultWidget, loading: defaultLoading, error: defaultError } =
|
|
400
|
+
const { execute: getDefaultWidget, loading: defaultLoading, error: defaultError } = useApiAsync6(
|
|
418
401
|
() => getDefaultWidgetApi(optionsRef.current.agentId, optionsRef.current),
|
|
419
402
|
(data) => data.widget || null,
|
|
420
403
|
null
|
|
421
404
|
);
|
|
422
|
-
const { execute: createWidget, loading: createLoading, error: createError } =
|
|
405
|
+
const { execute: createWidget, loading: createLoading, error: createError } = useApiAsync6(
|
|
423
406
|
(widget) => createWidgetApi(optionsRef.current.agentId, widget, optionsRef.current),
|
|
424
407
|
(data) => data.widget || null,
|
|
425
408
|
null
|
|
426
409
|
);
|
|
427
|
-
const { execute: updateWidget, loading: updateLoading, error: updateError } =
|
|
410
|
+
const { execute: updateWidget, loading: updateLoading, error: updateError } = useApiAsync6(
|
|
428
411
|
(widgetId, widget) => updateWidgetApi(widgetId, widget, optionsRef.current),
|
|
429
412
|
(data) => data.widget || null,
|
|
430
413
|
null
|
|
431
414
|
);
|
|
432
|
-
const { execute: deleteWidget, loading: deleteLoading, error: deleteError } =
|
|
415
|
+
const { execute: deleteWidget, loading: deleteLoading, error: deleteError } = useApiAsync6(
|
|
433
416
|
(widgetId) => deleteWidgetApi(widgetId, optionsRef.current),
|
|
434
417
|
() => true,
|
|
435
418
|
false
|
|
436
419
|
);
|
|
437
|
-
const { execute: setDefaultWidget, loading: setDefaultLoading, error: setDefaultError } =
|
|
420
|
+
const { execute: setDefaultWidget, loading: setDefaultLoading, error: setDefaultError } = useApiAsync6(
|
|
438
421
|
(widgetId) => setDefaultWidgetApi(widgetId, optionsRef.current.agentId, optionsRef.current),
|
|
439
422
|
() => true,
|
|
440
423
|
false
|
|
441
424
|
);
|
|
442
425
|
const loading = listLoading || getLoading || defaultLoading || createLoading || updateLoading || deleteLoading || setDefaultLoading;
|
|
443
426
|
const error = listError || getError || defaultError || createError || updateError || deleteError || setDefaultError;
|
|
444
|
-
return
|
|
427
|
+
return useMemo6(
|
|
445
428
|
() => ({
|
|
446
429
|
loading,
|
|
447
430
|
error,
|
|
@@ -456,36 +439,40 @@ function useWidgets(options) {
|
|
|
456
439
|
[loading, error, listWidgets, getWidget, getDefaultWidget, createWidget, updateWidget, deleteWidget, setDefaultWidget]
|
|
457
440
|
);
|
|
458
441
|
}
|
|
442
|
+
|
|
443
|
+
// hooks/use-skill-user-config.ts
|
|
444
|
+
import { useMemo as useMemo7 } from "react";
|
|
445
|
+
import { useApiAsync as useApiAsync7 } from "@elqnt/api-client/hooks";
|
|
459
446
|
function useSkillUserConfig(options) {
|
|
460
447
|
const optionsRef = useOptionsRef(options);
|
|
461
|
-
const { execute: getSkillUserConfig, loading: getLoading, error: getError } =
|
|
448
|
+
const { execute: getSkillUserConfig, loading: getLoading, error: getError } = useApiAsync7(
|
|
462
449
|
(skillId, agentId) => getSkillUserConfigApi(skillId, { ...optionsRef.current, agentId }),
|
|
463
450
|
(data) => data.userConfig || null,
|
|
464
451
|
null
|
|
465
452
|
);
|
|
466
|
-
const { execute: updateSkillUserConfig, loading: updateLoading, error: updateError } =
|
|
453
|
+
const { execute: updateSkillUserConfig, loading: updateLoading, error: updateError } = useApiAsync7(
|
|
467
454
|
(skillId, data) => updateSkillUserConfigApi(skillId, data, optionsRef.current),
|
|
468
455
|
(data) => data.userConfig || null,
|
|
469
456
|
null
|
|
470
457
|
);
|
|
471
|
-
const { execute: deleteSkillUserConfig, loading: deleteLoading, error: deleteError } =
|
|
458
|
+
const { execute: deleteSkillUserConfig, loading: deleteLoading, error: deleteError } = useApiAsync7(
|
|
472
459
|
(skillId, agentId) => deleteSkillUserConfigApi(skillId, { ...optionsRef.current, agentId }),
|
|
473
460
|
() => true,
|
|
474
461
|
false
|
|
475
462
|
);
|
|
476
|
-
const { execute: listSkillUserConfigs, loading: listLoading, error: listError } =
|
|
463
|
+
const { execute: listSkillUserConfigs, loading: listLoading, error: listError } = useApiAsync7(
|
|
477
464
|
(params) => listSkillUserConfigsApi({ ...optionsRef.current, ...params }),
|
|
478
465
|
(data) => data.userConfigs || [],
|
|
479
466
|
[]
|
|
480
467
|
);
|
|
481
|
-
const { execute: resolveSkillConfig, loading: resolveLoading, error: resolveError } =
|
|
468
|
+
const { execute: resolveSkillConfig, loading: resolveLoading, error: resolveError } = useApiAsync7(
|
|
482
469
|
(skillId, agentId) => resolveSkillConfigApi(skillId, agentId, optionsRef.current),
|
|
483
470
|
(data) => data,
|
|
484
471
|
null
|
|
485
472
|
);
|
|
486
473
|
const loading = getLoading || updateLoading || deleteLoading || listLoading || resolveLoading;
|
|
487
474
|
const error = getError || updateError || deleteError || listError || resolveError;
|
|
488
|
-
return
|
|
475
|
+
return useMemo7(
|
|
489
476
|
() => ({
|
|
490
477
|
loading,
|
|
491
478
|
error,
|
|
@@ -498,31 +485,35 @@ function useSkillUserConfig(options) {
|
|
|
498
485
|
[loading, error, getSkillUserConfig, updateSkillUserConfig, deleteSkillUserConfig, listSkillUserConfigs, resolveSkillConfig]
|
|
499
486
|
);
|
|
500
487
|
}
|
|
488
|
+
|
|
489
|
+
// hooks/use-analytics.ts
|
|
490
|
+
import { useMemo as useMemo8 } from "react";
|
|
491
|
+
import { useApiAsync as useApiAsync8 } from "@elqnt/api-client/hooks";
|
|
501
492
|
function useAnalytics(options) {
|
|
502
493
|
const optionsRef = useOptionsRef(options);
|
|
503
|
-
const { execute: getAgentChatsAnalytics, loading: chatsLoading, error: chatsError } =
|
|
494
|
+
const { execute: getAgentChatsAnalytics, loading: chatsLoading, error: chatsError } = useApiAsync8(
|
|
504
495
|
(params) => getAgentChatsAnalyticsApi(params, optionsRef.current),
|
|
505
496
|
(data) => data.data,
|
|
506
497
|
[]
|
|
507
498
|
);
|
|
508
|
-
const { execute: getAgentCSATAnalytics, loading: csatLoading, error: csatError } =
|
|
499
|
+
const { execute: getAgentCSATAnalytics, loading: csatLoading, error: csatError } = useApiAsync8(
|
|
509
500
|
(params) => getAgentCSATAnalyticsApi(params, optionsRef.current),
|
|
510
501
|
(data) => data.data,
|
|
511
502
|
[]
|
|
512
503
|
);
|
|
513
|
-
const { execute: getAgentListAnalytics, loading: listLoading, error: listError } =
|
|
504
|
+
const { execute: getAgentListAnalytics, loading: listLoading, error: listError } = useApiAsync8(
|
|
514
505
|
() => getAgentListAnalyticsApi(optionsRef.current),
|
|
515
506
|
(data) => data.data,
|
|
516
507
|
[]
|
|
517
508
|
);
|
|
518
|
-
const { execute: getTaskOutcomes, loading: taskLoading, error: taskError } =
|
|
509
|
+
const { execute: getTaskOutcomes, loading: taskLoading, error: taskError } = useApiAsync8(
|
|
519
510
|
(params) => getTaskOutcomesApi(params, optionsRef.current),
|
|
520
511
|
(data) => data.data,
|
|
521
512
|
[]
|
|
522
513
|
);
|
|
523
514
|
const loading = chatsLoading || csatLoading || listLoading || taskLoading;
|
|
524
515
|
const error = chatsError || csatError || listError || taskError;
|
|
525
|
-
return
|
|
516
|
+
return useMemo8(
|
|
526
517
|
() => ({
|
|
527
518
|
loading,
|
|
528
519
|
error,
|
|
@@ -534,46 +525,50 @@ function useAnalytics(options) {
|
|
|
534
525
|
[loading, error, getAgentChatsAnalytics, getAgentCSATAnalytics, getAgentListAnalytics, getTaskOutcomes]
|
|
535
526
|
);
|
|
536
527
|
}
|
|
528
|
+
|
|
529
|
+
// hooks/use-integrations.ts
|
|
530
|
+
import { useMemo as useMemo9 } from "react";
|
|
531
|
+
import { useApiAsync as useApiAsync9 } from "@elqnt/api-client/hooks";
|
|
537
532
|
function useIntegrations(options) {
|
|
538
533
|
const optionsRef = useOptionsRef(options);
|
|
539
|
-
const { execute: listIntegrations, loading: listLoading, error: listError } =
|
|
534
|
+
const { execute: listIntegrations, loading: listLoading, error: listError } = useApiAsync9(
|
|
540
535
|
() => listIntegrationsApi(optionsRef.current),
|
|
541
536
|
(data) => data.integrations,
|
|
542
537
|
[]
|
|
543
538
|
);
|
|
544
|
-
const { execute: getIntegration, loading: getLoading, error: getError } =
|
|
539
|
+
const { execute: getIntegration, loading: getLoading, error: getError } = useApiAsync9(
|
|
545
540
|
(provider, integrationType) => getIntegrationApi(provider, integrationType, optionsRef.current),
|
|
546
541
|
(data) => data.integration || null,
|
|
547
542
|
null
|
|
548
543
|
);
|
|
549
|
-
const { execute: connectIntegration, loading: connectLoading, error: connectError } =
|
|
544
|
+
const { execute: connectIntegration, loading: connectLoading, error: connectError } = useApiAsync9(
|
|
550
545
|
(params) => connectIntegrationApi(params, optionsRef.current),
|
|
551
546
|
(data) => ({ authUrl: data.auth_url, state: data.state }),
|
|
552
547
|
null
|
|
553
548
|
);
|
|
554
|
-
const { execute: disconnectIntegration, loading: disconnectLoading, error: disconnectError } =
|
|
549
|
+
const { execute: disconnectIntegration, loading: disconnectLoading, error: disconnectError } = useApiAsync9(
|
|
555
550
|
(params) => disconnectIntegrationApi(params, optionsRef.current),
|
|
556
551
|
() => true,
|
|
557
552
|
false
|
|
558
553
|
);
|
|
559
|
-
const { execute: refreshIntegration, loading: refreshLoading, error: refreshError } =
|
|
554
|
+
const { execute: refreshIntegration, loading: refreshLoading, error: refreshError } = useApiAsync9(
|
|
560
555
|
(params) => refreshIntegrationApi(params, optionsRef.current),
|
|
561
556
|
(data) => data.integration || null,
|
|
562
557
|
null
|
|
563
558
|
);
|
|
564
|
-
const { execute: updateTriage, loading: updateTriageLoading, error: updateTriageError } =
|
|
559
|
+
const { execute: updateTriage, loading: updateTriageLoading, error: updateTriageError } = useApiAsync9(
|
|
565
560
|
(params) => updateIntegrationTriageApi(params, optionsRef.current),
|
|
566
561
|
(data) => data.integration || null,
|
|
567
562
|
null
|
|
568
563
|
);
|
|
569
|
-
const { execute: runEmailTriage, loading: runTriageLoading, error: runTriageError } =
|
|
564
|
+
const { execute: runEmailTriage, loading: runTriageLoading, error: runTriageError } = useApiAsync9(
|
|
570
565
|
() => runEmailTriageApi(optionsRef.current),
|
|
571
566
|
(data) => ({ success: data.success, emailsFound: data.emails_found, instancesCreated: data.instances_created }),
|
|
572
567
|
null
|
|
573
568
|
);
|
|
574
569
|
const loading = listLoading || getLoading || connectLoading || disconnectLoading || refreshLoading || updateTriageLoading || runTriageLoading;
|
|
575
570
|
const error = listError || getError || connectError || disconnectError || refreshError || updateTriageError || runTriageError;
|
|
576
|
-
return
|
|
571
|
+
return useMemo9(
|
|
577
572
|
() => ({
|
|
578
573
|
loading,
|
|
579
574
|
error,
|
|
@@ -588,36 +583,40 @@ function useIntegrations(options) {
|
|
|
588
583
|
[loading, error, listIntegrations, getIntegration, connectIntegration, disconnectIntegration, refreshIntegration, updateTriage, runEmailTriage]
|
|
589
584
|
);
|
|
590
585
|
}
|
|
586
|
+
|
|
587
|
+
// hooks/use-sandbox.ts
|
|
588
|
+
import { useMemo as useMemo10 } from "react";
|
|
589
|
+
import { useApiAsync as useApiAsync10 } from "@elqnt/api-client/hooks";
|
|
591
590
|
function useSandbox(options) {
|
|
592
591
|
const optionsRef = useOptionsRef(options);
|
|
593
|
-
const { execute: createSandbox, loading: createLoading, error: createError } =
|
|
592
|
+
const { execute: createSandbox, loading: createLoading, error: createError } = useApiAsync10(
|
|
594
593
|
(request) => createSandboxApi(request, optionsRef.current),
|
|
595
594
|
(data) => ({ id: data.id, url: data.url, sandbox: data.sandbox }),
|
|
596
595
|
null
|
|
597
596
|
);
|
|
598
|
-
const { execute: getSandbox, loading: getLoading, error: getError } =
|
|
597
|
+
const { execute: getSandbox, loading: getLoading, error: getError } = useApiAsync10(
|
|
599
598
|
(sandboxId) => getSandboxApi(sandboxId, optionsRef.current),
|
|
600
599
|
(data) => data.sandbox || null,
|
|
601
600
|
null
|
|
602
601
|
);
|
|
603
|
-
const { execute: updateSandbox, loading: updateLoading, error: updateError } =
|
|
602
|
+
const { execute: updateSandbox, loading: updateLoading, error: updateError } = useApiAsync10(
|
|
604
603
|
(sandboxId, request) => updateSandboxApi(sandboxId, request, optionsRef.current),
|
|
605
604
|
(data) => ({ id: data.id, url: data.url, sandbox: data.sandbox }),
|
|
606
605
|
null
|
|
607
606
|
);
|
|
608
|
-
const { execute: listSandboxes, loading: listLoading, error: listError } =
|
|
607
|
+
const { execute: listSandboxes, loading: listLoading, error: listError } = useApiAsync10(
|
|
609
608
|
(limit) => listSandboxesApi({ ...optionsRef.current, limit }),
|
|
610
609
|
(data) => ({ sandboxes: data.sandboxes, total: data.total }),
|
|
611
610
|
{ sandboxes: [], total: 0 }
|
|
612
611
|
);
|
|
613
|
-
const { execute: deleteSandbox, loading: deleteLoading, error: deleteError } =
|
|
612
|
+
const { execute: deleteSandbox, loading: deleteLoading, error: deleteError } = useApiAsync10(
|
|
614
613
|
(sandboxId) => deleteSandboxApi(sandboxId, optionsRef.current),
|
|
615
614
|
(data) => data.success,
|
|
616
615
|
false
|
|
617
616
|
);
|
|
618
617
|
const loading = createLoading || getLoading || updateLoading || listLoading || deleteLoading;
|
|
619
618
|
const error = createError || getError || updateError || listError || deleteError;
|
|
620
|
-
return
|
|
619
|
+
return useMemo10(
|
|
621
620
|
() => ({
|
|
622
621
|
loading,
|
|
623
622
|
error,
|
|
@@ -630,51 +629,71 @@ function useSandbox(options) {
|
|
|
630
629
|
[loading, error, createSandbox, getSandbox, updateSandbox, listSandboxes, deleteSandbox]
|
|
631
630
|
);
|
|
632
631
|
}
|
|
632
|
+
|
|
633
|
+
// hooks/use-structured-output.ts
|
|
634
|
+
import { useMemo as useMemo11 } from "react";
|
|
635
|
+
import { useApiAsync as useApiAsync11 } from "@elqnt/api-client/hooks";
|
|
636
|
+
function useStructuredOutput(options) {
|
|
637
|
+
const optionsRef = useOptionsRef(options);
|
|
638
|
+
const { execute: run, loading, error, clearError } = useApiAsync11(
|
|
639
|
+
(request) => structuredOutputApi(request, optionsRef.current),
|
|
640
|
+
(resp) => resp,
|
|
641
|
+
null
|
|
642
|
+
);
|
|
643
|
+
return useMemo11(
|
|
644
|
+
() => ({ run, loading, error, clearError }),
|
|
645
|
+
[run, loading, error, clearError]
|
|
646
|
+
);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// hooks/use-scheduler-tasks.ts
|
|
650
|
+
import { useMemo as useMemo12 } from "react";
|
|
651
|
+
import { useApiAsync as useApiAsync12 } from "@elqnt/api-client/hooks";
|
|
633
652
|
function useSchedulerTasks(options) {
|
|
634
653
|
const optionsRef = useOptionsRef(options);
|
|
635
|
-
const { execute: listTasks, loading: listLoading, error: listError } =
|
|
654
|
+
const { execute: listTasks, loading: listLoading, error: listError } = useApiAsync12(
|
|
636
655
|
(params) => listSchedulerTasksApi({ ...optionsRef.current, ...params }),
|
|
637
656
|
(data) => data.tasks,
|
|
638
657
|
[]
|
|
639
658
|
);
|
|
640
|
-
const { execute: createTask, loading: createLoading, error: createError } =
|
|
659
|
+
const { execute: createTask, loading: createLoading, error: createError } = useApiAsync12(
|
|
641
660
|
(task) => createSchedulerTaskApi(task, optionsRef.current),
|
|
642
661
|
(data) => data.task || null,
|
|
643
662
|
null
|
|
644
663
|
);
|
|
645
|
-
const { execute: getTask, loading: getLoading, error: getError } =
|
|
664
|
+
const { execute: getTask, loading: getLoading, error: getError } = useApiAsync12(
|
|
646
665
|
(taskId) => getSchedulerTaskApi(taskId, optionsRef.current),
|
|
647
666
|
(data) => data.task || null,
|
|
648
667
|
null
|
|
649
668
|
);
|
|
650
|
-
const { execute: updateTask, loading: updateLoading, error: updateError } =
|
|
669
|
+
const { execute: updateTask, loading: updateLoading, error: updateError } = useApiAsync12(
|
|
651
670
|
(taskId, task) => updateSchedulerTaskApi(taskId, task, optionsRef.current),
|
|
652
671
|
(data) => data.task || null,
|
|
653
672
|
null
|
|
654
673
|
);
|
|
655
|
-
const { execute: deleteTask, loading: deleteLoading, error: deleteError } =
|
|
674
|
+
const { execute: deleteTask, loading: deleteLoading, error: deleteError } = useApiAsync12(
|
|
656
675
|
(taskId) => deleteSchedulerTaskApi(taskId, optionsRef.current),
|
|
657
676
|
(data) => data.success,
|
|
658
677
|
false
|
|
659
678
|
);
|
|
660
|
-
const { execute: snoozeTask, loading: snoozeLoading, error: snoozeError } =
|
|
679
|
+
const { execute: snoozeTask, loading: snoozeLoading, error: snoozeError } = useApiAsync12(
|
|
661
680
|
(taskId, delay) => snoozeSchedulerTaskApi(taskId, delay, optionsRef.current),
|
|
662
681
|
(data) => data.task || null,
|
|
663
682
|
null
|
|
664
683
|
);
|
|
665
|
-
const { execute: completeTask, loading: completeLoading, error: completeError } =
|
|
684
|
+
const { execute: completeTask, loading: completeLoading, error: completeError } = useApiAsync12(
|
|
666
685
|
(taskId) => completeSchedulerTaskApi(taskId, optionsRef.current),
|
|
667
686
|
(data) => data.task || null,
|
|
668
687
|
null
|
|
669
688
|
);
|
|
670
|
-
const { execute: startTask, loading: startLoading, error: startError } =
|
|
689
|
+
const { execute: startTask, loading: startLoading, error: startError } = useApiAsync12(
|
|
671
690
|
(taskId) => startSchedulerTaskApi(taskId, optionsRef.current),
|
|
672
691
|
(data) => data.task || null,
|
|
673
692
|
null
|
|
674
693
|
);
|
|
675
694
|
const loading = listLoading || createLoading || getLoading || updateLoading || deleteLoading || snoozeLoading || completeLoading || startLoading;
|
|
676
695
|
const error = listError || createError || getError || updateError || deleteError || snoozeError || completeError || startError;
|
|
677
|
-
return
|
|
696
|
+
return useMemo12(
|
|
678
697
|
() => ({
|
|
679
698
|
loading,
|
|
680
699
|
error,
|
|
@@ -690,51 +709,55 @@ function useSchedulerTasks(options) {
|
|
|
690
709
|
[loading, error, listTasks, createTask, getTask, updateTask, deleteTask, snoozeTask, completeTask, startTask]
|
|
691
710
|
);
|
|
692
711
|
}
|
|
712
|
+
|
|
713
|
+
// hooks/use-scheduler-schedules.ts
|
|
714
|
+
import { useMemo as useMemo13 } from "react";
|
|
715
|
+
import { useApiAsync as useApiAsync13 } from "@elqnt/api-client/hooks";
|
|
693
716
|
function useSchedulerSchedules(options) {
|
|
694
717
|
const optionsRef = useOptionsRef(options);
|
|
695
|
-
const { execute: listSchedules, loading: listLoading, error: listError } =
|
|
718
|
+
const { execute: listSchedules, loading: listLoading, error: listError } = useApiAsync13(
|
|
696
719
|
(params) => listSchedulesApi({ ...optionsRef.current, ...params }),
|
|
697
720
|
(data) => data.schedules,
|
|
698
721
|
[]
|
|
699
722
|
);
|
|
700
|
-
const { execute: createSchedule, loading: createLoading, error: createError } =
|
|
723
|
+
const { execute: createSchedule, loading: createLoading, error: createError } = useApiAsync13(
|
|
701
724
|
(schedule) => createScheduleApi(schedule, optionsRef.current),
|
|
702
725
|
(data) => data.schedule || null,
|
|
703
726
|
null
|
|
704
727
|
);
|
|
705
|
-
const { execute: getSchedule, loading: getLoading, error: getError } =
|
|
728
|
+
const { execute: getSchedule, loading: getLoading, error: getError } = useApiAsync13(
|
|
706
729
|
(scheduleId) => getScheduleApi(scheduleId, optionsRef.current),
|
|
707
730
|
(data) => data.schedule || null,
|
|
708
731
|
null
|
|
709
732
|
);
|
|
710
|
-
const { execute: updateSchedule, loading: updateLoading, error: updateError } =
|
|
733
|
+
const { execute: updateSchedule, loading: updateLoading, error: updateError } = useApiAsync13(
|
|
711
734
|
(scheduleId, schedule) => updateScheduleApi(scheduleId, schedule, optionsRef.current),
|
|
712
735
|
(data) => data.schedule || null,
|
|
713
736
|
null
|
|
714
737
|
);
|
|
715
|
-
const { execute: deleteSchedule, loading: deleteLoading, error: deleteError } =
|
|
738
|
+
const { execute: deleteSchedule, loading: deleteLoading, error: deleteError } = useApiAsync13(
|
|
716
739
|
(scheduleId) => deleteScheduleApi(scheduleId, optionsRef.current),
|
|
717
740
|
(data) => data.success,
|
|
718
741
|
false
|
|
719
742
|
);
|
|
720
|
-
const { execute: pauseSchedule, loading: pauseLoading, error: pauseError } =
|
|
743
|
+
const { execute: pauseSchedule, loading: pauseLoading, error: pauseError } = useApiAsync13(
|
|
721
744
|
(scheduleId) => pauseScheduleApi(scheduleId, optionsRef.current),
|
|
722
745
|
(data) => data.schedule || null,
|
|
723
746
|
null
|
|
724
747
|
);
|
|
725
|
-
const { execute: resumeSchedule, loading: resumeLoading, error: resumeError } =
|
|
748
|
+
const { execute: resumeSchedule, loading: resumeLoading, error: resumeError } = useApiAsync13(
|
|
726
749
|
(scheduleId) => resumeScheduleApi(scheduleId, optionsRef.current),
|
|
727
750
|
(data) => data.schedule || null,
|
|
728
751
|
null
|
|
729
752
|
);
|
|
730
|
-
const { execute: runSchedule, loading: runLoading, error: runError } =
|
|
753
|
+
const { execute: runSchedule, loading: runLoading, error: runError } = useApiAsync13(
|
|
731
754
|
(scheduleId) => runScheduleApi(scheduleId, optionsRef.current),
|
|
732
755
|
(data) => data.schedule || null,
|
|
733
756
|
null
|
|
734
757
|
);
|
|
735
758
|
const loading = listLoading || createLoading || getLoading || updateLoading || deleteLoading || pauseLoading || resumeLoading || runLoading;
|
|
736
759
|
const error = listError || createError || getError || updateError || deleteError || pauseError || resumeError || runError;
|
|
737
|
-
return
|
|
760
|
+
return useMemo13(
|
|
738
761
|
() => ({
|
|
739
762
|
loading,
|
|
740
763
|
error,
|
|
@@ -751,9 +774,327 @@ function useSchedulerSchedules(options) {
|
|
|
751
774
|
);
|
|
752
775
|
}
|
|
753
776
|
|
|
777
|
+
// hooks/use-background-agents.ts
|
|
778
|
+
import { useState, useEffect as useEffect2, useRef as useRef2, useCallback, useMemo as useMemo14 } from "react";
|
|
779
|
+
import { useApiAsync as useApiAsync14 } from "@elqnt/api-client/hooks";
|
|
780
|
+
function useBackgroundAgents(options) {
|
|
781
|
+
const optionsRef = useOptionsRef(options);
|
|
782
|
+
const [liveStates, setLiveStates] = useState({});
|
|
783
|
+
const [watchedChats, setWatchedChats] = useState({});
|
|
784
|
+
const transportRef = useRef2(null);
|
|
785
|
+
const sseRef = useRef2(null);
|
|
786
|
+
const watchedChatKeyRef = useRef2(null);
|
|
787
|
+
useEffect2(() => {
|
|
788
|
+
const transport = createBGAgentTransport();
|
|
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 = useRef2(/* @__PURE__ */ new Set());
|
|
797
|
+
const streamJob = useCallback((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 } = useApiAsync14(
|
|
835
|
+
(request) => triggerBackgroundAgentApi(request, optionsRef.current),
|
|
836
|
+
(data) => data,
|
|
837
|
+
null
|
|
838
|
+
);
|
|
839
|
+
const { execute: checkStatus, loading: statusLoading, error: statusError } = useApiAsync14(
|
|
840
|
+
(jobId) => checkBackgroundAgentStatusApi(jobId, optionsRef.current),
|
|
841
|
+
(data) => data,
|
|
842
|
+
null
|
|
843
|
+
);
|
|
844
|
+
const { execute: listAgentSummaries, loading: summaryLoading, error: summaryError } = useApiAsync14(
|
|
845
|
+
() => listAgentsSummaryApi(optionsRef.current),
|
|
846
|
+
(data) => data.agents || [],
|
|
847
|
+
[]
|
|
848
|
+
);
|
|
849
|
+
const createTask = useCallback(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 = createData.data?.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 = useCallback(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 = loadData.data?.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 = chat.metadata?.backgroundStatus;
|
|
953
|
+
const bgMessage = chat.metadata?.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" && eventData?.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 = useCallback((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
|
+
useEffect2(() => {
|
|
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 useMemo14(() => ({
|
|
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
|
+
|
|
754
1097
|
export {
|
|
755
|
-
useAsync,
|
|
756
|
-
useApiAsync,
|
|
757
1098
|
useOptionsRef,
|
|
758
1099
|
useAgents,
|
|
759
1100
|
useSkills,
|
|
@@ -765,7 +1106,9 @@ export {
|
|
|
765
1106
|
useAnalytics,
|
|
766
1107
|
useIntegrations,
|
|
767
1108
|
useSandbox,
|
|
1109
|
+
useStructuredOutput,
|
|
768
1110
|
useSchedulerTasks,
|
|
769
|
-
useSchedulerSchedules
|
|
1111
|
+
useSchedulerSchedules,
|
|
1112
|
+
useBackgroundAgents
|
|
770
1113
|
};
|
|
771
|
-
//# sourceMappingURL=chunk-
|
|
1114
|
+
//# sourceMappingURL=chunk-MNFZXJ2Y.mjs.map
|