@elqnt/agents 2.1.1 → 3.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.
- package/dist/{agent-models-mCYzjfGp.d.mts → agent-models-BdtFKjV3.d.mts} +7 -9
- package/dist/{agent-models-mCYzjfGp.d.ts → agent-models-BdtFKjV3.d.ts} +7 -9
- package/dist/api/index.d.mts +40 -3
- package/dist/api/index.d.ts +40 -3
- package/dist/api/index.js +30 -2
- package/dist/api/index.js.map +1 -1
- package/dist/api/index.mjs +29 -1
- package/dist/api/server.d.mts +146 -0
- package/dist/api/server.d.ts +146 -0
- package/dist/api/server.js +226 -0
- package/dist/api/server.js.map +1 -0
- package/dist/api/server.mjs +226 -0
- package/dist/api/server.mjs.map +1 -0
- package/dist/{chunk-SWJ66D7X.js → chunk-44A5L2IY.js} +92 -2
- package/dist/chunk-44A5L2IY.js.map +1 -0
- package/dist/{chunk-K3OAYHF3.js → chunk-ADOBVUUS.js} +73 -2
- package/dist/chunk-ADOBVUUS.js.map +1 -0
- package/dist/{chunk-3VJNDDME.mjs → chunk-EUELXX27.mjs} +92 -2
- package/dist/chunk-EUELXX27.mjs.map +1 -0
- package/dist/{chunk-SZP2G5I7.mjs → chunk-O3FM26FT.mjs} +73 -2
- package/dist/chunk-O3FM26FT.mjs.map +1 -0
- package/dist/chunk-RTUQ7WKT.mjs +434 -0
- package/dist/chunk-RTUQ7WKT.mjs.map +1 -0
- package/dist/chunk-VVYOTEM2.js +434 -0
- package/dist/chunk-VVYOTEM2.js.map +1 -0
- package/dist/hooks/index.d.mts +134 -5
- package/dist/hooks/index.d.ts +134 -5
- package/dist/hooks/index.js +15 -3
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +16 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +130 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +131 -5
- package/dist/models/index.d.mts +880 -2
- package/dist/models/index.d.ts +880 -2
- package/dist/models/index.js +88 -2
- package/dist/models/index.js.map +1 -1
- package/dist/models/index.mjs +87 -1
- package/package.json +20 -17
- package/dist/chunk-3VJNDDME.mjs.map +0 -1
- package/dist/chunk-K3OAYHF3.js.map +0 -1
- package/dist/chunk-O2SYQSU2.mjs +0 -398
- package/dist/chunk-O2SYQSU2.mjs.map +0 -1
- package/dist/chunk-RPXANLP2.js +0 -398
- package/dist/chunk-RPXANLP2.js.map +0 -1
- package/dist/chunk-SWJ66D7X.js.map +0 -1
- package/dist/chunk-SZP2G5I7.mjs.map +0 -1
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
createAgentApi,
|
|
4
|
+
createAgentJobApi,
|
|
5
|
+
createSkillApi,
|
|
6
|
+
createSubAgentApi,
|
|
7
|
+
createToolDefinitionApi,
|
|
8
|
+
createWidgetApi,
|
|
9
|
+
deleteAgentApi,
|
|
10
|
+
deleteAgentJobApi,
|
|
11
|
+
deleteSkillApi,
|
|
12
|
+
deleteSubAgentApi,
|
|
13
|
+
deleteToolDefinitionApi,
|
|
14
|
+
deleteWidgetApi,
|
|
15
|
+
getAgentApi,
|
|
16
|
+
getAgentJobApi,
|
|
17
|
+
getDefaultAgentApi,
|
|
18
|
+
getDefaultWidgetApi,
|
|
19
|
+
getSkillApi,
|
|
20
|
+
getSkillCategoriesApi,
|
|
21
|
+
getSubAgentApi,
|
|
22
|
+
getToolDefinitionApi,
|
|
23
|
+
getToolDefinitionsByIdsApi,
|
|
24
|
+
getWidgetApi,
|
|
25
|
+
listAgentJobsApi,
|
|
26
|
+
listAgentsApi,
|
|
27
|
+
listAgentsSummaryApi,
|
|
28
|
+
listSkillsApi,
|
|
29
|
+
listSubAgentsApi,
|
|
30
|
+
listToolDefinitionsApi,
|
|
31
|
+
listWidgetsApi,
|
|
32
|
+
pauseAgentJobApi,
|
|
33
|
+
resumeAgentJobApi,
|
|
34
|
+
setDefaultWidgetApi,
|
|
35
|
+
updateAgentApi,
|
|
36
|
+
updateAgentJobApi,
|
|
37
|
+
updateSkillApi,
|
|
38
|
+
updateSubAgentApi,
|
|
39
|
+
updateToolDefinitionApi,
|
|
40
|
+
updateWidgetApi
|
|
41
|
+
} from "./chunk-O3FM26FT.mjs";
|
|
42
|
+
|
|
43
|
+
// hooks/index.ts
|
|
44
|
+
import { useMemo } from "react";
|
|
45
|
+
|
|
46
|
+
// hooks/use-async.ts
|
|
47
|
+
import { useState, useCallback, useRef } from "react";
|
|
48
|
+
function useAsync(asyncFn, options) {
|
|
49
|
+
const [error, setError] = useState(null);
|
|
50
|
+
const requestCountRef = useRef(0);
|
|
51
|
+
const [loading, setLoading] = useState(false);
|
|
52
|
+
const execute = useCallback(
|
|
53
|
+
async (...args) => {
|
|
54
|
+
requestCountRef.current += 1;
|
|
55
|
+
setLoading(true);
|
|
56
|
+
setError(null);
|
|
57
|
+
try {
|
|
58
|
+
return await asyncFn(...args);
|
|
59
|
+
} catch (err) {
|
|
60
|
+
const message = err instanceof Error ? err.message : "An error occurred";
|
|
61
|
+
setError(message);
|
|
62
|
+
options?.onError?.(message);
|
|
63
|
+
throw err;
|
|
64
|
+
} finally {
|
|
65
|
+
requestCountRef.current -= 1;
|
|
66
|
+
if (requestCountRef.current === 0) {
|
|
67
|
+
setLoading(false);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
[asyncFn, options]
|
|
72
|
+
);
|
|
73
|
+
const clearError = useCallback(() => setError(null), []);
|
|
74
|
+
return { execute, loading, error, clearError };
|
|
75
|
+
}
|
|
76
|
+
function useApiAsync(asyncFn, extractor, defaultValue, options) {
|
|
77
|
+
const [error, setError] = useState(null);
|
|
78
|
+
const requestCountRef = useRef(0);
|
|
79
|
+
const [loading, setLoading] = useState(false);
|
|
80
|
+
const execute = useCallback(
|
|
81
|
+
async (...args) => {
|
|
82
|
+
requestCountRef.current += 1;
|
|
83
|
+
setLoading(true);
|
|
84
|
+
setError(null);
|
|
85
|
+
try {
|
|
86
|
+
const response = await asyncFn(...args);
|
|
87
|
+
if (response.error) {
|
|
88
|
+
setError(response.error);
|
|
89
|
+
options?.onError?.(response.error);
|
|
90
|
+
return defaultValue;
|
|
91
|
+
}
|
|
92
|
+
return response.data ? extractor(response.data) : defaultValue;
|
|
93
|
+
} catch (err) {
|
|
94
|
+
const message = err instanceof Error ? err.message : "An error occurred";
|
|
95
|
+
setError(message);
|
|
96
|
+
options?.onError?.(message);
|
|
97
|
+
return defaultValue;
|
|
98
|
+
} finally {
|
|
99
|
+
requestCountRef.current -= 1;
|
|
100
|
+
if (requestCountRef.current === 0) {
|
|
101
|
+
setLoading(false);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
[asyncFn, extractor, defaultValue, options]
|
|
106
|
+
);
|
|
107
|
+
const clearError = useCallback(() => setError(null), []);
|
|
108
|
+
return { execute, loading, error, clearError };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// hooks/use-options-ref.ts
|
|
112
|
+
import { useRef as useRef2, useEffect } from "react";
|
|
113
|
+
function useOptionsRef(options) {
|
|
114
|
+
const optionsRef = useRef2(options);
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
optionsRef.current = options;
|
|
117
|
+
}, [options]);
|
|
118
|
+
return optionsRef;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// hooks/index.ts
|
|
122
|
+
function useAgents(options) {
|
|
123
|
+
const optionsRef = useOptionsRef(options);
|
|
124
|
+
const { execute: listAgents, loading: listLoading, error: listError } = useApiAsync(
|
|
125
|
+
() => listAgentsApi(optionsRef.current),
|
|
126
|
+
(data) => data.agents,
|
|
127
|
+
[]
|
|
128
|
+
);
|
|
129
|
+
const { execute: listAgentSummaries, loading: listSummaryLoading, error: listSummaryError } = useApiAsync(
|
|
130
|
+
() => listAgentsSummaryApi(optionsRef.current),
|
|
131
|
+
(data) => data.agents,
|
|
132
|
+
[]
|
|
133
|
+
);
|
|
134
|
+
const { execute: getAgent, loading: getLoading, error: getError } = useApiAsync(
|
|
135
|
+
(agentId) => getAgentApi(agentId, optionsRef.current),
|
|
136
|
+
(data) => data.agent || null,
|
|
137
|
+
null
|
|
138
|
+
);
|
|
139
|
+
const { execute: createAgent, loading: createLoading, error: createError } = useApiAsync(
|
|
140
|
+
(agent) => createAgentApi(agent, optionsRef.current),
|
|
141
|
+
(data) => data.agent || null,
|
|
142
|
+
null
|
|
143
|
+
);
|
|
144
|
+
const { execute: updateAgent, loading: updateLoading, error: updateError } = useApiAsync(
|
|
145
|
+
(agentId, agent) => updateAgentApi(agentId, agent, optionsRef.current),
|
|
146
|
+
(data) => data.agent || null,
|
|
147
|
+
null
|
|
148
|
+
);
|
|
149
|
+
const { execute: deleteAgent, loading: deleteLoading, error: deleteError } = useApiAsync(
|
|
150
|
+
(agentId) => deleteAgentApi(agentId, optionsRef.current),
|
|
151
|
+
() => true,
|
|
152
|
+
false
|
|
153
|
+
);
|
|
154
|
+
const { execute: getDefaultAgent, loading: defaultLoading, error: defaultError } = useApiAsync(
|
|
155
|
+
() => getDefaultAgentApi(optionsRef.current),
|
|
156
|
+
(data) => data.agent || null,
|
|
157
|
+
null
|
|
158
|
+
);
|
|
159
|
+
const loading = listLoading || listSummaryLoading || getLoading || createLoading || updateLoading || deleteLoading || defaultLoading;
|
|
160
|
+
const error = listError || listSummaryError || getError || createError || updateError || deleteError || defaultError;
|
|
161
|
+
return useMemo(
|
|
162
|
+
() => ({
|
|
163
|
+
loading,
|
|
164
|
+
error,
|
|
165
|
+
listAgents,
|
|
166
|
+
listAgentSummaries,
|
|
167
|
+
getAgent,
|
|
168
|
+
createAgent,
|
|
169
|
+
updateAgent,
|
|
170
|
+
deleteAgent,
|
|
171
|
+
getDefaultAgent
|
|
172
|
+
}),
|
|
173
|
+
[loading, error, listAgents, listAgentSummaries, getAgent, createAgent, updateAgent, deleteAgent, getDefaultAgent]
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
function useSkills(options) {
|
|
177
|
+
const optionsRef = useOptionsRef(options);
|
|
178
|
+
const { execute: listSkills, loading: listLoading, error: listError } = useApiAsync(
|
|
179
|
+
() => listSkillsApi(optionsRef.current),
|
|
180
|
+
(data) => data.skills,
|
|
181
|
+
[]
|
|
182
|
+
);
|
|
183
|
+
const { execute: getSkill, loading: getLoading, error: getError } = useApiAsync(
|
|
184
|
+
(skillId) => getSkillApi(skillId, optionsRef.current),
|
|
185
|
+
(data) => data.skill || null,
|
|
186
|
+
null
|
|
187
|
+
);
|
|
188
|
+
const { execute: createSkill, loading: createLoading, error: createError } = useApiAsync(
|
|
189
|
+
(skill) => createSkillApi(skill, optionsRef.current),
|
|
190
|
+
(data) => data.skill || null,
|
|
191
|
+
null
|
|
192
|
+
);
|
|
193
|
+
const { execute: updateSkill, loading: updateLoading, error: updateError } = useApiAsync(
|
|
194
|
+
(skillId, skill) => updateSkillApi(skillId, skill, optionsRef.current),
|
|
195
|
+
(data) => data.skill || null,
|
|
196
|
+
null
|
|
197
|
+
);
|
|
198
|
+
const { execute: deleteSkill, loading: deleteLoading, error: deleteError } = useApiAsync(
|
|
199
|
+
(skillId) => deleteSkillApi(skillId, optionsRef.current),
|
|
200
|
+
() => true,
|
|
201
|
+
false
|
|
202
|
+
);
|
|
203
|
+
const { execute: getCategories, loading: categoriesLoading, error: categoriesError } = useApiAsync(
|
|
204
|
+
() => getSkillCategoriesApi(optionsRef.current),
|
|
205
|
+
(data) => data.categories,
|
|
206
|
+
[]
|
|
207
|
+
);
|
|
208
|
+
const loading = listLoading || getLoading || createLoading || updateLoading || deleteLoading || categoriesLoading;
|
|
209
|
+
const error = listError || getError || createError || updateError || deleteError || categoriesError;
|
|
210
|
+
return useMemo(
|
|
211
|
+
() => ({
|
|
212
|
+
loading,
|
|
213
|
+
error,
|
|
214
|
+
listSkills,
|
|
215
|
+
getSkill,
|
|
216
|
+
createSkill,
|
|
217
|
+
updateSkill,
|
|
218
|
+
deleteSkill,
|
|
219
|
+
getCategories
|
|
220
|
+
}),
|
|
221
|
+
[loading, error, listSkills, getSkill, createSkill, updateSkill, deleteSkill, getCategories]
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
function useSubAgents(options) {
|
|
225
|
+
const optionsRef = useOptionsRef(options);
|
|
226
|
+
const { execute: listSubAgents, loading: listLoading, error: listError } = useApiAsync(
|
|
227
|
+
() => listSubAgentsApi(optionsRef.current),
|
|
228
|
+
(data) => data.subAgents,
|
|
229
|
+
[]
|
|
230
|
+
);
|
|
231
|
+
const { execute: getSubAgent, loading: getLoading, error: getError } = useApiAsync(
|
|
232
|
+
(subAgentId) => getSubAgentApi(subAgentId, optionsRef.current),
|
|
233
|
+
(data) => data.subAgent || null,
|
|
234
|
+
null
|
|
235
|
+
);
|
|
236
|
+
const { execute: createSubAgent, loading: createLoading, error: createError } = useApiAsync(
|
|
237
|
+
(subAgent) => createSubAgentApi(subAgent, optionsRef.current),
|
|
238
|
+
(data) => data.subAgent || null,
|
|
239
|
+
null
|
|
240
|
+
);
|
|
241
|
+
const { execute: updateSubAgent, loading: updateLoading, error: updateError } = useApiAsync(
|
|
242
|
+
(subAgentId, subAgent) => updateSubAgentApi(subAgentId, subAgent, optionsRef.current),
|
|
243
|
+
(data) => data.subAgent || null,
|
|
244
|
+
null
|
|
245
|
+
);
|
|
246
|
+
const { execute: deleteSubAgent, loading: deleteLoading, error: deleteError } = useApiAsync(
|
|
247
|
+
(subAgentId) => deleteSubAgentApi(subAgentId, optionsRef.current),
|
|
248
|
+
() => true,
|
|
249
|
+
false
|
|
250
|
+
);
|
|
251
|
+
const loading = listLoading || getLoading || createLoading || updateLoading || deleteLoading;
|
|
252
|
+
const error = listError || getError || createError || updateError || deleteError;
|
|
253
|
+
return useMemo(
|
|
254
|
+
() => ({
|
|
255
|
+
loading,
|
|
256
|
+
error,
|
|
257
|
+
listSubAgents,
|
|
258
|
+
getSubAgent,
|
|
259
|
+
createSubAgent,
|
|
260
|
+
updateSubAgent,
|
|
261
|
+
deleteSubAgent
|
|
262
|
+
}),
|
|
263
|
+
[loading, error, listSubAgents, getSubAgent, createSubAgent, updateSubAgent, deleteSubAgent]
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
function useToolDefinitions(options) {
|
|
267
|
+
const optionsRef = useOptionsRef(options);
|
|
268
|
+
const { execute: listToolDefinitions, loading: listLoading, error: listError } = useApiAsync(
|
|
269
|
+
() => listToolDefinitionsApi(optionsRef.current),
|
|
270
|
+
(data) => data.toolDefinitions,
|
|
271
|
+
[]
|
|
272
|
+
);
|
|
273
|
+
const { execute: getToolDefinition, loading: getLoading, error: getError } = useApiAsync(
|
|
274
|
+
(toolDefId) => getToolDefinitionApi(toolDefId, optionsRef.current),
|
|
275
|
+
(data) => data.toolDefinition || null,
|
|
276
|
+
null
|
|
277
|
+
);
|
|
278
|
+
const { execute: getToolDefinitionsByIds, loading: getByIdsLoading, error: getByIdsError } = useApiAsync(
|
|
279
|
+
(ids) => getToolDefinitionsByIdsApi(ids, optionsRef.current),
|
|
280
|
+
(data) => data.toolDefinitions,
|
|
281
|
+
[]
|
|
282
|
+
);
|
|
283
|
+
const { execute: createToolDefinition, loading: createLoading, error: createError } = useApiAsync(
|
|
284
|
+
(toolDefinition) => createToolDefinitionApi(toolDefinition, optionsRef.current),
|
|
285
|
+
(data) => data.toolDefinition || null,
|
|
286
|
+
null
|
|
287
|
+
);
|
|
288
|
+
const { execute: updateToolDefinition, loading: updateLoading, error: updateError } = useApiAsync(
|
|
289
|
+
(toolDefId, toolDefinition) => updateToolDefinitionApi(toolDefId, toolDefinition, optionsRef.current),
|
|
290
|
+
(data) => data.toolDefinition || null,
|
|
291
|
+
null
|
|
292
|
+
);
|
|
293
|
+
const { execute: deleteToolDefinition, loading: deleteLoading, error: deleteError } = useApiAsync(
|
|
294
|
+
(toolDefId) => deleteToolDefinitionApi(toolDefId, optionsRef.current),
|
|
295
|
+
() => true,
|
|
296
|
+
false
|
|
297
|
+
);
|
|
298
|
+
const loading = listLoading || getLoading || getByIdsLoading || createLoading || updateLoading || deleteLoading;
|
|
299
|
+
const error = listError || getError || getByIdsError || createError || updateError || deleteError;
|
|
300
|
+
return useMemo(
|
|
301
|
+
() => ({
|
|
302
|
+
loading,
|
|
303
|
+
error,
|
|
304
|
+
listToolDefinitions,
|
|
305
|
+
getToolDefinition,
|
|
306
|
+
getToolDefinitionsByIds,
|
|
307
|
+
createToolDefinition,
|
|
308
|
+
updateToolDefinition,
|
|
309
|
+
deleteToolDefinition
|
|
310
|
+
}),
|
|
311
|
+
[loading, error, listToolDefinitions, getToolDefinition, getToolDefinitionsByIds, createToolDefinition, updateToolDefinition, deleteToolDefinition]
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
function useAgentJobs(options) {
|
|
315
|
+
const optionsRef = useOptionsRef(options);
|
|
316
|
+
const { execute: listAgentJobs, loading: listLoading, error: listError } = useApiAsync(
|
|
317
|
+
() => listAgentJobsApi(optionsRef.current),
|
|
318
|
+
(data) => data.jobs,
|
|
319
|
+
[]
|
|
320
|
+
);
|
|
321
|
+
const { execute: getAgentJob, loading: getLoading, error: getError } = useApiAsync(
|
|
322
|
+
(jobId) => getAgentJobApi(jobId, optionsRef.current),
|
|
323
|
+
(data) => data.job || null,
|
|
324
|
+
null
|
|
325
|
+
);
|
|
326
|
+
const { execute: createAgentJob, loading: createLoading, error: createError } = useApiAsync(
|
|
327
|
+
(job) => createAgentJobApi(job, optionsRef.current),
|
|
328
|
+
(data) => data.job || null,
|
|
329
|
+
null
|
|
330
|
+
);
|
|
331
|
+
const { execute: updateAgentJob, loading: updateLoading, error: updateError } = useApiAsync(
|
|
332
|
+
(jobId, job) => updateAgentJobApi(jobId, job, optionsRef.current),
|
|
333
|
+
(data) => data.job || null,
|
|
334
|
+
null
|
|
335
|
+
);
|
|
336
|
+
const { execute: deleteAgentJob, loading: deleteLoading, error: deleteError } = useApiAsync(
|
|
337
|
+
(jobId) => deleteAgentJobApi(jobId, optionsRef.current),
|
|
338
|
+
() => true,
|
|
339
|
+
false
|
|
340
|
+
);
|
|
341
|
+
const { execute: pauseAgentJob, loading: pauseLoading, error: pauseError } = useApiAsync(
|
|
342
|
+
(jobId) => pauseAgentJobApi(jobId, optionsRef.current),
|
|
343
|
+
(data) => data.job || null,
|
|
344
|
+
null
|
|
345
|
+
);
|
|
346
|
+
const { execute: resumeAgentJob, loading: resumeLoading, error: resumeError } = useApiAsync(
|
|
347
|
+
(jobId) => resumeAgentJobApi(jobId, optionsRef.current),
|
|
348
|
+
(data) => data.job || null,
|
|
349
|
+
null
|
|
350
|
+
);
|
|
351
|
+
const loading = listLoading || getLoading || createLoading || updateLoading || deleteLoading || pauseLoading || resumeLoading;
|
|
352
|
+
const error = listError || getError || createError || updateError || deleteError || pauseError || resumeError;
|
|
353
|
+
return useMemo(
|
|
354
|
+
() => ({
|
|
355
|
+
loading,
|
|
356
|
+
error,
|
|
357
|
+
listAgentJobs,
|
|
358
|
+
getAgentJob,
|
|
359
|
+
createAgentJob,
|
|
360
|
+
updateAgentJob,
|
|
361
|
+
deleteAgentJob,
|
|
362
|
+
pauseAgentJob,
|
|
363
|
+
resumeAgentJob
|
|
364
|
+
}),
|
|
365
|
+
[loading, error, listAgentJobs, getAgentJob, createAgentJob, updateAgentJob, deleteAgentJob, pauseAgentJob, resumeAgentJob]
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
function useWidgets(options) {
|
|
369
|
+
const optionsRef = useOptionsRef(options);
|
|
370
|
+
const { execute: listWidgets, loading: listLoading, error: listError } = useApiAsync(
|
|
371
|
+
() => listWidgetsApi(optionsRef.current.agentId, optionsRef.current),
|
|
372
|
+
(data) => data.widgets,
|
|
373
|
+
[]
|
|
374
|
+
);
|
|
375
|
+
const { execute: getWidget, loading: getLoading, error: getError } = useApiAsync(
|
|
376
|
+
(widgetId) => getWidgetApi(widgetId, optionsRef.current),
|
|
377
|
+
(data) => data.widget || null,
|
|
378
|
+
null
|
|
379
|
+
);
|
|
380
|
+
const { execute: getDefaultWidget, loading: defaultLoading, error: defaultError } = useApiAsync(
|
|
381
|
+
() => getDefaultWidgetApi(optionsRef.current.agentId, optionsRef.current),
|
|
382
|
+
(data) => data.widget || null,
|
|
383
|
+
null
|
|
384
|
+
);
|
|
385
|
+
const { execute: createWidget, loading: createLoading, error: createError } = useApiAsync(
|
|
386
|
+
(widget) => createWidgetApi(optionsRef.current.agentId, widget, optionsRef.current),
|
|
387
|
+
(data) => data.widget || null,
|
|
388
|
+
null
|
|
389
|
+
);
|
|
390
|
+
const { execute: updateWidget, loading: updateLoading, error: updateError } = useApiAsync(
|
|
391
|
+
(widgetId, widget) => updateWidgetApi(widgetId, widget, optionsRef.current),
|
|
392
|
+
(data) => data.widget || null,
|
|
393
|
+
null
|
|
394
|
+
);
|
|
395
|
+
const { execute: deleteWidget, loading: deleteLoading, error: deleteError } = useApiAsync(
|
|
396
|
+
(widgetId) => deleteWidgetApi(widgetId, optionsRef.current),
|
|
397
|
+
() => true,
|
|
398
|
+
false
|
|
399
|
+
);
|
|
400
|
+
const { execute: setDefaultWidget, loading: setDefaultLoading, error: setDefaultError } = useApiAsync(
|
|
401
|
+
(widgetId) => setDefaultWidgetApi(widgetId, optionsRef.current.agentId, optionsRef.current),
|
|
402
|
+
() => true,
|
|
403
|
+
false
|
|
404
|
+
);
|
|
405
|
+
const loading = listLoading || getLoading || defaultLoading || createLoading || updateLoading || deleteLoading || setDefaultLoading;
|
|
406
|
+
const error = listError || getError || defaultError || createError || updateError || deleteError || setDefaultError;
|
|
407
|
+
return useMemo(
|
|
408
|
+
() => ({
|
|
409
|
+
loading,
|
|
410
|
+
error,
|
|
411
|
+
listWidgets,
|
|
412
|
+
getWidget,
|
|
413
|
+
getDefaultWidget,
|
|
414
|
+
createWidget,
|
|
415
|
+
updateWidget,
|
|
416
|
+
deleteWidget,
|
|
417
|
+
setDefaultWidget
|
|
418
|
+
}),
|
|
419
|
+
[loading, error, listWidgets, getWidget, getDefaultWidget, createWidget, updateWidget, deleteWidget, setDefaultWidget]
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export {
|
|
424
|
+
useAsync,
|
|
425
|
+
useApiAsync,
|
|
426
|
+
useOptionsRef,
|
|
427
|
+
useAgents,
|
|
428
|
+
useSkills,
|
|
429
|
+
useSubAgents,
|
|
430
|
+
useToolDefinitions,
|
|
431
|
+
useAgentJobs,
|
|
432
|
+
useWidgets
|
|
433
|
+
};
|
|
434
|
+
//# sourceMappingURL=chunk-RTUQ7WKT.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../hooks/index.ts","../hooks/use-async.ts","../hooks/use-options-ref.ts"],"sourcesContent":["\"use client\";\n\n/**\n * Agent hooks for React applications\n *\n * Provides React hooks for agent CRUD operations with loading/error states.\n *\n * @packageDocumentation\n */\n\nimport { useMemo } from \"react\";\nimport type { ApiClientOptions } from \"@elqnt/api-client\";\nimport type { Agent, AgentSummary, Skill, SubAgent, ToolDefinition, AgentJob, AgentWidget } from \"../models\";\nimport {\n // Agents\n listAgentsApi,\n listAgentsSummaryApi,\n getAgentApi,\n createAgentApi,\n updateAgentApi,\n deleteAgentApi,\n getDefaultAgentApi,\n // Skills\n listSkillsApi,\n getSkillApi,\n createSkillApi,\n updateSkillApi,\n deleteSkillApi,\n getSkillCategoriesApi,\n // Sub-Agents\n listSubAgentsApi,\n getSubAgentApi,\n createSubAgentApi,\n updateSubAgentApi,\n deleteSubAgentApi,\n // Tool Definitions\n listToolDefinitionsApi,\n getToolDefinitionApi,\n createToolDefinitionApi,\n updateToolDefinitionApi,\n deleteToolDefinitionApi,\n getToolDefinitionsByIdsApi,\n // Agent Jobs\n listAgentJobsApi,\n getAgentJobApi,\n createAgentJobApi,\n updateAgentJobApi,\n deleteAgentJobApi,\n pauseAgentJobApi,\n resumeAgentJobApi,\n // Widgets\n listWidgetsApi,\n getWidgetApi,\n createWidgetApi,\n updateWidgetApi,\n deleteWidgetApi,\n getDefaultWidgetApi,\n setDefaultWidgetApi,\n} from \"../api\";\nimport { useApiAsync } from \"./use-async\";\nimport { useOptionsRef } from \"./use-options-ref\";\n\n// =============================================================================\n// TYPES\n// =============================================================================\n\nexport type UseAgentsOptions = ApiClientOptions;\n\n// =============================================================================\n// USE AGENTS HOOK\n// =============================================================================\n\n/**\n * Hook for agent CRUD operations\n *\n * @example\n * ```tsx\n * const { loading, error, listAgents, createAgent } = useAgents({\n * baseUrl: apiGatewayUrl,\n * orgId: selectedOrgId,\n * });\n *\n * const agents = await listAgents();\n * ```\n */\nexport function useAgents(options: UseAgentsOptions) {\n const optionsRef = useOptionsRef(options);\n\n const { execute: listAgents, loading: listLoading, error: listError } = useApiAsync(\n () => listAgentsApi(optionsRef.current),\n (data) => data.agents,\n [] as Agent[]\n );\n\n const { execute: listAgentSummaries, loading: listSummaryLoading, error: listSummaryError } = useApiAsync(\n () => listAgentsSummaryApi(optionsRef.current),\n (data) => data.agents,\n [] as AgentSummary[]\n );\n\n const { execute: getAgent, loading: getLoading, error: getError } = useApiAsync(\n (agentId: string) => getAgentApi(agentId, optionsRef.current),\n (data) => data.agent || null,\n null as Agent | null\n );\n\n const { execute: createAgent, loading: createLoading, error: createError } = useApiAsync(\n (agent: Partial<Agent>) => createAgentApi(agent, optionsRef.current),\n (data) => data.agent || null,\n null as Agent | null\n );\n\n const { execute: updateAgent, loading: updateLoading, error: updateError } = useApiAsync(\n (agentId: string, agent: Partial<Agent>) => updateAgentApi(agentId, agent, optionsRef.current),\n (data) => data.agent || null,\n null as Agent | null\n );\n\n const { execute: deleteAgent, loading: deleteLoading, error: deleteError } = useApiAsync(\n (agentId: string) => deleteAgentApi(agentId, optionsRef.current),\n () => true,\n false\n );\n\n const { execute: getDefaultAgent, loading: defaultLoading, error: defaultError } = useApiAsync(\n () => getDefaultAgentApi(optionsRef.current),\n (data) => data.agent || null,\n null as Agent | null\n );\n\n const loading = listLoading || listSummaryLoading || getLoading || createLoading || updateLoading || deleteLoading || defaultLoading;\n const error = listError || listSummaryError || getError || createError || updateError || deleteError || defaultError;\n\n return useMemo(\n () => ({\n loading,\n error,\n listAgents,\n listAgentSummaries,\n getAgent,\n createAgent,\n updateAgent,\n deleteAgent,\n getDefaultAgent,\n }),\n [loading, error, listAgents, listAgentSummaries, getAgent, createAgent, updateAgent, deleteAgent, getDefaultAgent]\n );\n}\n\n// =============================================================================\n// USE SKILLS HOOK\n// =============================================================================\n\n/**\n * Hook for skill CRUD operations\n */\nexport function useSkills(options: UseAgentsOptions) {\n const optionsRef = useOptionsRef(options);\n\n const { execute: listSkills, loading: listLoading, error: listError } = useApiAsync(\n () => listSkillsApi(optionsRef.current),\n (data) => data.skills,\n [] as Skill[]\n );\n\n const { execute: getSkill, loading: getLoading, error: getError } = useApiAsync(\n (skillId: string) => getSkillApi(skillId, optionsRef.current),\n (data) => data.skill || null,\n null as Skill | null\n );\n\n const { execute: createSkill, loading: createLoading, error: createError } = useApiAsync(\n (skill: Partial<Skill>) => createSkillApi(skill, optionsRef.current),\n (data) => data.skill || null,\n null as Skill | null\n );\n\n const { execute: updateSkill, loading: updateLoading, error: updateError } = useApiAsync(\n (skillId: string, skill: Partial<Skill>) => updateSkillApi(skillId, skill, optionsRef.current),\n (data) => data.skill || null,\n null as Skill | null\n );\n\n const { execute: deleteSkill, loading: deleteLoading, error: deleteError } = useApiAsync(\n (skillId: string) => deleteSkillApi(skillId, optionsRef.current),\n () => true,\n false\n );\n\n const { execute: getCategories, loading: categoriesLoading, error: categoriesError } = useApiAsync(\n () => getSkillCategoriesApi(optionsRef.current),\n (data) => data.categories,\n [] as string[]\n );\n\n const loading = listLoading || getLoading || createLoading || updateLoading || deleteLoading || categoriesLoading;\n const error = listError || getError || createError || updateError || deleteError || categoriesError;\n\n return useMemo(\n () => ({\n loading,\n error,\n listSkills,\n getSkill,\n createSkill,\n updateSkill,\n deleteSkill,\n getCategories,\n }),\n [loading, error, listSkills, getSkill, createSkill, updateSkill, deleteSkill, getCategories]\n );\n}\n\n// =============================================================================\n// USE SUB-AGENTS HOOK\n// =============================================================================\n\n/**\n * Hook for sub-agent CRUD operations\n */\nexport function useSubAgents(options: UseAgentsOptions) {\n const optionsRef = useOptionsRef(options);\n\n const { execute: listSubAgents, loading: listLoading, error: listError } = useApiAsync(\n () => listSubAgentsApi(optionsRef.current),\n (data) => data.subAgents,\n [] as SubAgent[]\n );\n\n const { execute: getSubAgent, loading: getLoading, error: getError } = useApiAsync(\n (subAgentId: string) => getSubAgentApi(subAgentId, optionsRef.current),\n (data) => data.subAgent || null,\n null as SubAgent | null\n );\n\n const { execute: createSubAgent, loading: createLoading, error: createError } = useApiAsync(\n (subAgent: Partial<SubAgent>) => createSubAgentApi(subAgent, optionsRef.current),\n (data) => data.subAgent || null,\n null as SubAgent | null\n );\n\n const { execute: updateSubAgent, loading: updateLoading, error: updateError } = useApiAsync(\n (subAgentId: string, subAgent: Partial<SubAgent>) => updateSubAgentApi(subAgentId, subAgent, optionsRef.current),\n (data) => data.subAgent || null,\n null as SubAgent | null\n );\n\n const { execute: deleteSubAgent, loading: deleteLoading, error: deleteError } = useApiAsync(\n (subAgentId: string) => deleteSubAgentApi(subAgentId, optionsRef.current),\n () => true,\n false\n );\n\n const loading = listLoading || getLoading || createLoading || updateLoading || deleteLoading;\n const error = listError || getError || createError || updateError || deleteError;\n\n return useMemo(\n () => ({\n loading,\n error,\n listSubAgents,\n getSubAgent,\n createSubAgent,\n updateSubAgent,\n deleteSubAgent,\n }),\n [loading, error, listSubAgents, getSubAgent, createSubAgent, updateSubAgent, deleteSubAgent]\n );\n}\n\n// =============================================================================\n// USE TOOL DEFINITIONS HOOK\n// =============================================================================\n\n/**\n * Hook for tool definition CRUD operations\n *\n * @example\n * ```tsx\n * const { loading, error, listToolDefinitions, createToolDefinition } = useToolDefinitions({\n * baseUrl: apiGatewayUrl,\n * orgId: selectedOrgId,\n * });\n *\n * const toolDefs = await listToolDefinitions();\n * ```\n */\nexport function useToolDefinitions(options: UseAgentsOptions) {\n const optionsRef = useOptionsRef(options);\n\n const { execute: listToolDefinitions, loading: listLoading, error: listError } = useApiAsync(\n () => listToolDefinitionsApi(optionsRef.current),\n (data) => data.toolDefinitions,\n [] as ToolDefinition[]\n );\n\n const { execute: getToolDefinition, loading: getLoading, error: getError } = useApiAsync(\n (toolDefId: string) => getToolDefinitionApi(toolDefId, optionsRef.current),\n (data) => data.toolDefinition || null,\n null as ToolDefinition | null\n );\n\n const { execute: getToolDefinitionsByIds, loading: getByIdsLoading, error: getByIdsError } = useApiAsync(\n (ids: string[]) => getToolDefinitionsByIdsApi(ids, optionsRef.current),\n (data) => data.toolDefinitions,\n [] as ToolDefinition[]\n );\n\n const { execute: createToolDefinition, loading: createLoading, error: createError } = useApiAsync(\n (toolDefinition: Partial<ToolDefinition>) => createToolDefinitionApi(toolDefinition, optionsRef.current),\n (data) => data.toolDefinition || null,\n null as ToolDefinition | null\n );\n\n const { execute: updateToolDefinition, loading: updateLoading, error: updateError } = useApiAsync(\n (toolDefId: string, toolDefinition: Partial<ToolDefinition>) => updateToolDefinitionApi(toolDefId, toolDefinition, optionsRef.current),\n (data) => data.toolDefinition || null,\n null as ToolDefinition | null\n );\n\n const { execute: deleteToolDefinition, loading: deleteLoading, error: deleteError } = useApiAsync(\n (toolDefId: string) => deleteToolDefinitionApi(toolDefId, optionsRef.current),\n () => true,\n false\n );\n\n const loading = listLoading || getLoading || getByIdsLoading || createLoading || updateLoading || deleteLoading;\n const error = listError || getError || getByIdsError || createError || updateError || deleteError;\n\n return useMemo(\n () => ({\n loading,\n error,\n listToolDefinitions,\n getToolDefinition,\n getToolDefinitionsByIds,\n createToolDefinition,\n updateToolDefinition,\n deleteToolDefinition,\n }),\n [loading, error, listToolDefinitions, getToolDefinition, getToolDefinitionsByIds, createToolDefinition, updateToolDefinition, deleteToolDefinition]\n );\n}\n\n// =============================================================================\n// USE AGENT JOBS HOOK\n// =============================================================================\n\n/**\n * Hook for agent job CRUD operations\n *\n * @example\n * ```tsx\n * const { loading, error, listAgentJobs, createAgentJob, pauseAgentJob } = useAgentJobs({\n * baseUrl: apiGatewayUrl,\n * orgId: selectedOrgId,\n * });\n *\n * const jobs = await listAgentJobs();\n * await pauseAgentJob(jobId);\n * ```\n */\nexport function useAgentJobs(options: UseAgentsOptions) {\n const optionsRef = useOptionsRef(options);\n\n const { execute: listAgentJobs, loading: listLoading, error: listError } = useApiAsync(\n () => listAgentJobsApi(optionsRef.current),\n (data) => data.jobs,\n [] as AgentJob[]\n );\n\n const { execute: getAgentJob, loading: getLoading, error: getError } = useApiAsync(\n (jobId: string) => getAgentJobApi(jobId, optionsRef.current),\n (data) => data.job || null,\n null as AgentJob | null\n );\n\n const { execute: createAgentJob, loading: createLoading, error: createError } = useApiAsync(\n (job: Partial<AgentJob>) => createAgentJobApi(job, optionsRef.current),\n (data) => data.job || null,\n null as AgentJob | null\n );\n\n const { execute: updateAgentJob, loading: updateLoading, error: updateError } = useApiAsync(\n (jobId: string, job: Partial<AgentJob>) => updateAgentJobApi(jobId, job, optionsRef.current),\n (data) => data.job || null,\n null as AgentJob | null\n );\n\n const { execute: deleteAgentJob, loading: deleteLoading, error: deleteError } = useApiAsync(\n (jobId: string) => deleteAgentJobApi(jobId, optionsRef.current),\n () => true,\n false\n );\n\n const { execute: pauseAgentJob, loading: pauseLoading, error: pauseError } = useApiAsync(\n (jobId: string) => pauseAgentJobApi(jobId, optionsRef.current),\n (data) => data.job || null,\n null as AgentJob | null\n );\n\n const { execute: resumeAgentJob, loading: resumeLoading, error: resumeError } = useApiAsync(\n (jobId: string) => resumeAgentJobApi(jobId, optionsRef.current),\n (data) => data.job || null,\n null as AgentJob | null\n );\n\n const loading = listLoading || getLoading || createLoading || updateLoading || deleteLoading || pauseLoading || resumeLoading;\n const error = listError || getError || createError || updateError || deleteError || pauseError || resumeError;\n\n return useMemo(\n () => ({\n loading,\n error,\n listAgentJobs,\n getAgentJob,\n createAgentJob,\n updateAgentJob,\n deleteAgentJob,\n pauseAgentJob,\n resumeAgentJob,\n }),\n [loading, error, listAgentJobs, getAgentJob, createAgentJob, updateAgentJob, deleteAgentJob, pauseAgentJob, resumeAgentJob]\n );\n}\n\n// =============================================================================\n// USE WIDGETS HOOK\n// =============================================================================\n\nexport interface UseWidgetsOptions extends UseAgentsOptions {\n agentId: string;\n}\n\n/**\n * Hook for widget CRUD operations\n *\n * @example\n * ```tsx\n * const { loading, error, listWidgets, createWidget } = useWidgets({\n * baseUrl: apiGatewayUrl,\n * orgId: selectedOrgId,\n * agentId: selectedAgentId,\n * });\n *\n * const widgets = await listWidgets();\n * ```\n */\nexport function useWidgets(options: UseWidgetsOptions) {\n const optionsRef = useOptionsRef(options);\n\n const { execute: listWidgets, loading: listLoading, error: listError } = useApiAsync(\n () => listWidgetsApi(optionsRef.current.agentId, optionsRef.current),\n (data) => data.widgets,\n [] as AgentWidget[]\n );\n\n const { execute: getWidget, loading: getLoading, error: getError } = useApiAsync(\n (widgetId: string) => getWidgetApi(widgetId, optionsRef.current),\n (data) => data.widget || null,\n null as AgentWidget | null\n );\n\n const { execute: getDefaultWidget, loading: defaultLoading, error: defaultError } = useApiAsync(\n () => getDefaultWidgetApi(optionsRef.current.agentId, optionsRef.current),\n (data) => data.widget || null,\n null as AgentWidget | null\n );\n\n const { execute: createWidget, loading: createLoading, error: createError } = useApiAsync(\n (widget: Partial<AgentWidget>) => createWidgetApi(optionsRef.current.agentId, widget, optionsRef.current),\n (data) => data.widget || null,\n null as AgentWidget | null\n );\n\n const { execute: updateWidget, loading: updateLoading, error: updateError } = useApiAsync(\n (widgetId: string, widget: Partial<AgentWidget>) => updateWidgetApi(widgetId, widget, optionsRef.current),\n (data) => data.widget || null,\n null as AgentWidget | null\n );\n\n const { execute: deleteWidget, loading: deleteLoading, error: deleteError } = useApiAsync(\n (widgetId: string) => deleteWidgetApi(widgetId, optionsRef.current),\n () => true,\n false\n );\n\n const { execute: setDefaultWidget, loading: setDefaultLoading, error: setDefaultError } = useApiAsync(\n (widgetId: string) => setDefaultWidgetApi(widgetId, optionsRef.current.agentId, optionsRef.current),\n () => true,\n false\n );\n\n const loading = listLoading || getLoading || defaultLoading || createLoading || updateLoading || deleteLoading || setDefaultLoading;\n const error = listError || getError || defaultError || createError || updateError || deleteError || setDefaultError;\n\n return useMemo(\n () => ({\n loading,\n error,\n listWidgets,\n getWidget,\n getDefaultWidget,\n createWidget,\n updateWidget,\n deleteWidget,\n setDefaultWidget,\n }),\n [loading, error, listWidgets, getWidget, getDefaultWidget, createWidget, updateWidget, deleteWidget, setDefaultWidget]\n );\n}\n\n// =============================================================================\n// EXPORTS\n// =============================================================================\n\n// Re-export hook utilities for advanced usage\nexport { useApiAsync, useAsync } from \"./use-async\";\nexport { useOptionsRef } from \"./use-options-ref\";\nexport type { UseAsyncOptions, UseAsyncReturn } from \"./use-async\";\n","\"use client\";\n\n/**\n * Async operation utilities for React hooks\n *\n * Provides a generic pattern for handling async operations with loading/error states.\n * Uses a request counter for accurate concurrent loading state.\n */\n\nimport { useState, useCallback, useRef } from \"react\";\nimport type { ApiResponse } from \"@elqnt/api-client\";\n\nexport interface UseAsyncOptions {\n onError?: (error: string) => void;\n}\n\nexport interface UseAsyncReturn<TResult, TArgs extends unknown[] = []> {\n execute: (...args: TArgs) => Promise<TResult>;\n loading: boolean;\n error: string | null;\n clearError: () => void;\n}\n\n/**\n * Generic async hook for any promise-returning function.\n * Uses a request counter to properly track concurrent requests.\n */\nexport function useAsync<TResult, TArgs extends unknown[] = []>(\n asyncFn: (...args: TArgs) => Promise<TResult>,\n options?: UseAsyncOptions\n): UseAsyncReturn<TResult, TArgs> {\n const [error, setError] = useState<string | null>(null);\n const requestCountRef = useRef(0);\n const [loading, setLoading] = useState(false);\n\n const execute = useCallback(\n async (...args: TArgs): Promise<TResult> => {\n requestCountRef.current += 1;\n setLoading(true);\n setError(null);\n\n try {\n return await asyncFn(...args);\n } catch (err) {\n const message = err instanceof Error ? err.message : \"An error occurred\";\n setError(message);\n options?.onError?.(message);\n throw err;\n } finally {\n requestCountRef.current -= 1;\n if (requestCountRef.current === 0) {\n setLoading(false);\n }\n }\n },\n [asyncFn, options]\n );\n\n const clearError = useCallback(() => setError(null), []);\n\n return { execute, loading, error, clearError };\n}\n\n/**\n * Specialized async hook for API operations that return ApiResponse.\n * Automatically extracts data and handles API errors.\n *\n * @param asyncFn - Function that returns ApiResponse<TResponse>\n * @param extractor - Function to extract the desired result from response data\n * @param defaultValue - Default value to return on error\n * @param options - Optional configuration\n *\n * @example\n * ```tsx\n * const { execute: listAgents, loading, error } = useApiAsync(\n * () => listAgentsApi(optionsRef.current),\n * (data) => data.agents,\n * []\n * );\n * ```\n */\nexport function useApiAsync<TResponse, TResult, TArgs extends unknown[] = []>(\n asyncFn: (...args: TArgs) => Promise<ApiResponse<TResponse>>,\n extractor: (data: TResponse) => TResult,\n defaultValue: TResult,\n options?: UseAsyncOptions\n): UseAsyncReturn<TResult, TArgs> {\n const [error, setError] = useState<string | null>(null);\n const requestCountRef = useRef(0);\n const [loading, setLoading] = useState(false);\n\n const execute = useCallback(\n async (...args: TArgs): Promise<TResult> => {\n requestCountRef.current += 1;\n setLoading(true);\n setError(null);\n\n try {\n const response = await asyncFn(...args);\n if (response.error) {\n setError(response.error);\n options?.onError?.(response.error);\n return defaultValue;\n }\n return response.data ? extractor(response.data) : defaultValue;\n } catch (err) {\n const message = err instanceof Error ? err.message : \"An error occurred\";\n setError(message);\n options?.onError?.(message);\n return defaultValue;\n } finally {\n requestCountRef.current -= 1;\n if (requestCountRef.current === 0) {\n setLoading(false);\n }\n }\n },\n [asyncFn, extractor, defaultValue, options]\n );\n\n const clearError = useCallback(() => setError(null), []);\n\n return { execute, loading, error, clearError };\n}\n","\"use client\";\n\n/**\n * Options reference utility for React hooks\n *\n * Keeps a mutable ref synchronized with options to avoid\n * stale closures in callbacks while preventing unnecessary re-renders.\n */\n\nimport { useRef, useEffect } from \"react\";\n\n/**\n * Creates a ref that stays synchronized with the provided options.\n * Useful for accessing current options values in callbacks without\n * causing re-renders or stale closure issues.\n *\n * @param options - The options object to track\n * @returns A ref that always contains the latest options\n *\n * @example\n * ```tsx\n * const optionsRef = useOptionsRef(options);\n *\n * const fetchData = useCallback(async () => {\n * // Always has the latest options, no stale closure\n * const result = await api.fetch(optionsRef.current);\n * }, []); // No need to include options in deps\n * ```\n */\nexport function useOptionsRef<T>(options: T): React.MutableRefObject<T> {\n const optionsRef = useRef(options);\n\n useEffect(() => {\n optionsRef.current = options;\n }, [options]);\n\n return optionsRef;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,SAAS,eAAe;;;ACDxB,SAAS,UAAU,aAAa,cAAc;AAkBvC,SAAS,SACd,SACA,SACgC;AAChC,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAwB,IAAI;AACtD,QAAM,kBAAkB,OAAO,CAAC;AAChC,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,KAAK;AAE5C,QAAM,UAAU;AAAA,IACd,UAAU,SAAkC;AAC1C,sBAAgB,WAAW;AAC3B,iBAAW,IAAI;AACf,eAAS,IAAI;AAEb,UAAI;AACF,eAAO,MAAM,QAAQ,GAAG,IAAI;AAAA,MAC9B,SAAS,KAAK;AACZ,cAAM,UAAU,eAAe,QAAQ,IAAI,UAAU;AACrD,iBAAS,OAAO;AAChB,iBAAS,UAAU,OAAO;AAC1B,cAAM;AAAA,MACR,UAAE;AACA,wBAAgB,WAAW;AAC3B,YAAI,gBAAgB,YAAY,GAAG;AACjC,qBAAW,KAAK;AAAA,QAClB;AAAA,MACF;AAAA,IACF;AAAA,IACA,CAAC,SAAS,OAAO;AAAA,EACnB;AAEA,QAAM,aAAa,YAAY,MAAM,SAAS,IAAI,GAAG,CAAC,CAAC;AAEvD,SAAO,EAAE,SAAS,SAAS,OAAO,WAAW;AAC/C;AAoBO,SAAS,YACd,SACA,WACA,cACA,SACgC;AAChC,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAwB,IAAI;AACtD,QAAM,kB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