@elqnt/agents 3.2.0 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/{agent-models-C36pvpUb.d.mts → agent-models-DLQlC7N6.d.mts} +143 -2
  2. package/dist/{agent-models-C36pvpUb.d.ts → agent-models-DLQlC7N6.d.ts} +143 -2
  3. package/dist/api/index.d.mts +52 -5
  4. package/dist/api/index.d.ts +52 -5
  5. package/dist/api/index.js +12 -2
  6. package/dist/api/index.js.map +1 -1
  7. package/dist/api/index.mjs +11 -1
  8. package/dist/api/server.d.mts +4 -2
  9. package/dist/api/server.d.ts +4 -2
  10. package/dist/api/server.js +9 -1
  11. package/dist/api/server.js.map +1 -1
  12. package/dist/api/server.mjs +8 -0
  13. package/dist/api/server.mjs.map +1 -1
  14. package/dist/chunk-2JDVRL35.js +133 -0
  15. package/dist/chunk-2JDVRL35.js.map +1 -0
  16. package/dist/{chunk-V5GHDXSW.mjs → chunk-2QL3LLC3.mjs} +457 -153
  17. package/dist/chunk-2QL3LLC3.mjs.map +1 -0
  18. package/dist/chunk-3EHE4O57.mjs +133 -0
  19. package/dist/chunk-3EHE4O57.mjs.map +1 -0
  20. package/dist/{chunk-TPQS2XAW.js → chunk-3VM5TCJR.js} +8 -2
  21. package/dist/chunk-3VM5TCJR.js.map +1 -0
  22. package/dist/chunk-AF4QJD73.js +1075 -0
  23. package/dist/chunk-AF4QJD73.js.map +1 -0
  24. package/dist/{chunk-IUKM3T2S.js → chunk-BH2FIDFK.js} +49 -2
  25. package/dist/chunk-BH2FIDFK.js.map +1 -0
  26. package/dist/{chunk-FR422IHO.mjs → chunk-GOHHT3ET.mjs} +48 -1
  27. package/dist/chunk-GOHHT3ET.mjs.map +1 -0
  28. package/dist/{chunk-SXYTVNKJ.mjs → chunk-ZK27UGO6.mjs} +7 -1
  29. package/dist/{chunk-SXYTVNKJ.mjs.map → chunk-ZK27UGO6.mjs.map} +1 -1
  30. package/dist/hooks/index.d.mts +127 -70
  31. package/dist/hooks/index.d.ts +127 -70
  32. package/dist/hooks/index.js +4 -5
  33. package/dist/hooks/index.js.map +1 -1
  34. package/dist/hooks/index.mjs +5 -6
  35. package/dist/index.d.mts +6 -4
  36. package/dist/index.d.ts +6 -4
  37. package/dist/index.js +19 -4
  38. package/dist/index.js.map +1 -1
  39. package/dist/index.mjs +22 -7
  40. package/dist/models/index.d.mts +2 -2
  41. package/dist/models/index.d.ts +2 -2
  42. package/dist/models/index.js +8 -2
  43. package/dist/models/index.js.map +1 -1
  44. package/dist/models/index.mjs +7 -1
  45. package/dist/{sandbox-BHeWPjLU.d.mts → sandbox-DOxoM2Ge.d.mts} +1 -0
  46. package/dist/{sandbox-BHeWPjLU.d.ts → sandbox-DOxoM2Ge.d.ts} +1 -0
  47. package/dist/transport/index.d.mts +36 -0
  48. package/dist/transport/index.d.ts +36 -0
  49. package/dist/transport/index.js +8 -0
  50. package/dist/transport/index.js.map +1 -0
  51. package/dist/transport/index.mjs +8 -0
  52. package/dist/transport/index.mjs.map +1 -0
  53. package/dist/types-C2qd5f-E.d.mts +51 -0
  54. package/dist/types-k9PszCzt.d.ts +51 -0
  55. package/dist/utils/index.d.mts +1 -1
  56. package/dist/utils/index.d.ts +1 -1
  57. package/package.json +10 -4
  58. package/dist/chunk-FR422IHO.mjs.map +0 -1
  59. package/dist/chunk-IUKM3T2S.js.map +0 -1
  60. package/dist/chunk-RGVWAFZP.js +0 -771
  61. package/dist/chunk-RGVWAFZP.js.map +0 -1
  62. package/dist/chunk-TPQS2XAW.js.map +0 -1
  63. package/dist/chunk-V5GHDXSW.mjs.map +0 -1
@@ -1,63 +1,12 @@
1
- import { ApiResponse, ApiClientOptions } from '@elqnt/api-client';
2
- import { Z as AgentJob, A as Agent, aF as AgentSummary, dw as SkillUserConfig, dd as ResolveSkillConfigResponse, dk as Skill, dO as SubAgent, e9 as ToolDefinition, aY as AgentWidget } from '../agent-models-C36pvpUb.mjs';
3
- import { ba as UserIntegration, ap as IntegrationProviderTS, aA as IntegrationTypeTS, h as CreateSandboxRequest, aW as Sandbox } from '../sandbox-BHeWPjLU.mjs';
4
- import { DateFilter, SchedulerSchedule, SchedulerTask } from '../api/index.mjs';
1
+ import { ApiClientOptions } from '@elqnt/api-client';
2
+ import { A as Agent, aI as AgentSummary, ds as Skill, dV as SubAgent, eh as ToolDefinition, Z as AgentJob, a$ as AgentWidget, dD as SkillUserConfig, dk as ResolveSkillConfigResponse, aB as AgentStatusUpdate, eG as TriggerBackgroundAgentRequest, eH as TriggerBackgroundAgentResponse, bc as BackgroundAgentStatusResponse } from '../agent-models-DLQlC7N6.mjs';
3
+ export { ba as BackgroundAgentProgressEvent } from '../agent-models-DLQlC7N6.mjs';
4
+ import { DateFilter, SchedulerTask, SchedulerSchedule } from '../api/index.mjs';
5
+ import { ba as UserIntegration, ap as IntegrationProviderTS, aA as IntegrationTypeTS, h as CreateSandboxRequest, aW as Sandbox } from '../sandbox-DOxoM2Ge.mjs';
6
+ import { ChatMessage, Attachment } from '@elqnt/chat/models';
7
+ export { B as BGAgentTransport, a as BGAgentTransportConfig } from '../types-C2qd5f-E.mjs';
5
8
  import '@elqnt/types';
6
9
 
7
- interface UseAsyncOptions {
8
- onError?: (error: string) => void;
9
- }
10
- interface UseAsyncReturn<TResult, TArgs extends unknown[] = []> {
11
- execute: (...args: TArgs) => Promise<TResult>;
12
- loading: boolean;
13
- error: string | null;
14
- clearError: () => void;
15
- }
16
- /**
17
- * Generic async hook for any promise-returning function.
18
- * Uses a request counter to properly track concurrent requests.
19
- */
20
- declare function useAsync<TResult, TArgs extends unknown[] = []>(asyncFn: (...args: TArgs) => Promise<TResult>, options?: UseAsyncOptions): UseAsyncReturn<TResult, TArgs>;
21
- /**
22
- * Specialized async hook for API operations that return ApiResponse.
23
- * Automatically extracts data and handles API errors.
24
- *
25
- * @param asyncFn - Function that returns ApiResponse<TResponse>
26
- * @param extractor - Function to extract the desired result from response data
27
- * @param defaultValue - Default value to return on error
28
- * @param options - Optional configuration
29
- *
30
- * @example
31
- * ```tsx
32
- * const { execute: listAgents, loading, error } = useApiAsync(
33
- * () => listAgentsApi(optionsRef.current),
34
- * (data) => data.agents,
35
- * []
36
- * );
37
- * ```
38
- */
39
- declare function useApiAsync<TResponse, TResult, TArgs extends unknown[] = []>(asyncFn: (...args: TArgs) => Promise<ApiResponse<TResponse>>, extractor: (data: TResponse) => TResult, defaultValue: TResult, options?: UseAsyncOptions): UseAsyncReturn<TResult, TArgs>;
40
-
41
- /**
42
- * Creates a ref that stays synchronized with the provided options.
43
- * Useful for accessing current options values in callbacks without
44
- * causing re-renders or stale closure issues.
45
- *
46
- * @param options - The options object to track
47
- * @returns A ref that always contains the latest options
48
- *
49
- * @example
50
- * ```tsx
51
- * const optionsRef = useOptionsRef(options);
52
- *
53
- * const fetchData = useCallback(async () => {
54
- * // Always has the latest options, no stale closure
55
- * const result = await api.fetch(optionsRef.current);
56
- * }, []); // No need to include options in deps
57
- * ```
58
- */
59
- declare function useOptionsRef<T>(options: T): React.MutableRefObject<T>;
60
-
61
10
  type UseAgentsOptions = ApiClientOptions;
62
11
  /**
63
12
  * Hook for agent CRUD operations
@@ -83,10 +32,12 @@ declare function useAgents(options: UseAgentsOptions): {
83
32
  deleteAgent: (agentId: string) => Promise<boolean>;
84
33
  getDefaultAgent: () => Promise<Agent | null>;
85
34
  };
35
+
36
+ type UseSkillsOptions = ApiClientOptions;
86
37
  /**
87
38
  * Hook for skill CRUD operations
88
39
  */
89
- declare function useSkills(options: UseAgentsOptions): {
40
+ declare function useSkills(options: UseSkillsOptions): {
90
41
  loading: boolean;
91
42
  error: string | null;
92
43
  listSkills: () => Promise<Skill[]>;
@@ -96,10 +47,12 @@ declare function useSkills(options: UseAgentsOptions): {
96
47
  deleteSkill: (skillId: string) => Promise<boolean>;
97
48
  getCategories: () => Promise<string[]>;
98
49
  };
50
+
51
+ type UseSubAgentsOptions = ApiClientOptions;
99
52
  /**
100
53
  * Hook for sub-agent CRUD operations
101
54
  */
102
- declare function useSubAgents(options: UseAgentsOptions): {
55
+ declare function useSubAgents(options: UseSubAgentsOptions): {
103
56
  loading: boolean;
104
57
  error: string | null;
105
58
  listSubAgents: () => Promise<SubAgent[]>;
@@ -108,6 +61,8 @@ declare function useSubAgents(options: UseAgentsOptions): {
108
61
  updateSubAgent: (subAgentId: string, subAgent: Partial<SubAgent>) => Promise<SubAgent | null>;
109
62
  deleteSubAgent: (subAgentId: string) => Promise<boolean>;
110
63
  };
64
+
65
+ type UseToolDefinitionsOptions = ApiClientOptions;
111
66
  /**
112
67
  * Hook for tool definition CRUD operations
113
68
  *
@@ -121,7 +76,7 @@ declare function useSubAgents(options: UseAgentsOptions): {
121
76
  * const toolDefs = await listToolDefinitions();
122
77
  * ```
123
78
  */
124
- declare function useToolDefinitions(options: UseAgentsOptions): {
79
+ declare function useToolDefinitions(options: UseToolDefinitionsOptions): {
125
80
  loading: boolean;
126
81
  error: string | null;
127
82
  listToolDefinitions: () => Promise<ToolDefinition[]>;
@@ -131,6 +86,8 @@ declare function useToolDefinitions(options: UseAgentsOptions): {
131
86
  updateToolDefinition: (toolDefId: string, toolDefinition: Partial<ToolDefinition>) => Promise<ToolDefinition | null>;
132
87
  deleteToolDefinition: (toolDefId: string) => Promise<boolean>;
133
88
  };
89
+
90
+ type UseAgentJobsOptions = ApiClientOptions;
134
91
  /**
135
92
  * Hook for agent job CRUD operations
136
93
  *
@@ -145,7 +102,7 @@ declare function useToolDefinitions(options: UseAgentsOptions): {
145
102
  * await pauseAgentJob(jobId);
146
103
  * ```
147
104
  */
148
- declare function useAgentJobs(options: UseAgentsOptions): {
105
+ declare function useAgentJobs(options: UseAgentJobsOptions): {
149
106
  loading: boolean;
150
107
  error: string | null;
151
108
  listAgentJobs: () => Promise<AgentJob[]>;
@@ -156,7 +113,8 @@ declare function useAgentJobs(options: UseAgentsOptions): {
156
113
  pauseAgentJob: (jobId: string) => Promise<AgentJob | null>;
157
114
  resumeAgentJob: (jobId: string) => Promise<AgentJob | null>;
158
115
  };
159
- interface UseWidgetsOptions extends UseAgentsOptions {
116
+
117
+ interface UseWidgetsOptions extends ApiClientOptions {
160
118
  agentId: string;
161
119
  }
162
120
  /**
@@ -184,6 +142,8 @@ declare function useWidgets(options: UseWidgetsOptions): {
184
142
  deleteWidget: (widgetId: string) => Promise<boolean>;
185
143
  setDefaultWidget: (widgetId: string) => Promise<boolean>;
186
144
  };
145
+
146
+ type UseSkillUserConfigOptions = ApiClientOptions;
187
147
  /**
188
148
  * Hook for skill user configuration operations
189
149
  *
@@ -198,7 +158,7 @@ declare function useWidgets(options: UseWidgetsOptions): {
198
158
  * await updateSkillUserConfig(skillId, { enabled: true });
199
159
  * ```
200
160
  */
201
- declare function useSkillUserConfig(options: UseAgentsOptions): {
161
+ declare function useSkillUserConfig(options: UseSkillUserConfigOptions): {
202
162
  loading: boolean;
203
163
  error: string | null;
204
164
  getSkillUserConfig: (skillId: string, agentId?: string | undefined) => Promise<SkillUserConfig | null>;
@@ -216,6 +176,8 @@ declare function useSkillUserConfig(options: UseAgentsOptions): {
216
176
  } | undefined) => Promise<SkillUserConfig[]>;
217
177
  resolveSkillConfig: (skillId: string, agentId: string) => Promise<ResolveSkillConfigResponse | null>;
218
178
  };
179
+
180
+ type UseAnalyticsOptions = ApiClientOptions;
219
181
  /**
220
182
  * Hook for agent analytics operations
221
183
  *
@@ -229,7 +191,7 @@ declare function useSkillUserConfig(options: UseAgentsOptions): {
229
191
  * const chatsData = await getAgentChatsAnalytics({ from: '2024-01-01', to: '2024-12-31' });
230
192
  * ```
231
193
  */
232
- declare function useAnalytics(options: UseAgentsOptions): {
194
+ declare function useAnalytics(options: UseAnalyticsOptions): {
233
195
  loading: boolean;
234
196
  error: string | null;
235
197
  getAgentChatsAnalytics: (params: {
@@ -245,6 +207,8 @@ declare function useAnalytics(options: UseAgentsOptions): {
245
207
  date_filter: DateFilter;
246
208
  }) => Promise<unknown[]>;
247
209
  };
210
+
211
+ type UseIntegrationsOptions = ApiClientOptions;
248
212
  /**
249
213
  * Hook for user integration operations (OAuth connections)
250
214
  *
@@ -259,7 +223,7 @@ declare function useAnalytics(options: UseAgentsOptions): {
259
223
  * const { auth_url } = await connectIntegration({ provider: 'google', integrationType: 'email', redirectUri: '/callback' });
260
224
  * ```
261
225
  */
262
- declare function useIntegrations(options: UseAgentsOptions): {
226
+ declare function useIntegrations(options: UseIntegrationsOptions): {
263
227
  loading: boolean;
264
228
  error: string | null;
265
229
  listIntegrations: () => Promise<UserIntegration[]>;
@@ -291,6 +255,8 @@ declare function useIntegrations(options: UseAgentsOptions): {
291
255
  instancesCreated: number;
292
256
  } | null>;
293
257
  };
258
+
259
+ type UseSandboxOptions = ApiClientOptions;
294
260
  /**
295
261
  * Hook for sandbox operations (AI-generated HTML sandboxes)
296
262
  *
@@ -305,7 +271,7 @@ declare function useIntegrations(options: UseAgentsOptions): {
305
271
  * console.log(result.url); // sandbox URL
306
272
  * ```
307
273
  */
308
- declare function useSandbox(options: UseAgentsOptions): {
274
+ declare function useSandbox(options: UseSandboxOptions): {
309
275
  loading: boolean;
310
276
  error: string | null;
311
277
  createSandbox: (request: Omit<CreateSandboxRequest, "orgId">) => Promise<{
@@ -328,6 +294,8 @@ declare function useSandbox(options: UseAgentsOptions): {
328
294
  }>;
329
295
  deleteSandbox: (sandboxId: string) => Promise<boolean>;
330
296
  };
297
+
298
+ type UseSchedulerTasksOptions = ApiClientOptions;
331
299
  /**
332
300
  * Hook for scheduler task operations
333
301
  *
@@ -342,7 +310,7 @@ declare function useSandbox(options: UseAgentsOptions): {
342
310
  * await snoozeTask(taskId, { amount: 30, unit: "minutes" });
343
311
  * ```
344
312
  */
345
- declare function useSchedulerTasks(options: UseAgentsOptions): {
313
+ declare function useSchedulerTasks(options: UseSchedulerTasksOptions): {
346
314
  loading: boolean;
347
315
  error: string | null;
348
316
  listTasks: (params?: {
@@ -361,6 +329,8 @@ declare function useSchedulerTasks(options: UseAgentsOptions): {
361
329
  completeTask: (taskId: string) => Promise<SchedulerTask | null>;
362
330
  startTask: (taskId: string) => Promise<SchedulerTask | null>;
363
331
  };
332
+
333
+ type UseSchedulerSchedulesOptions = ApiClientOptions;
364
334
  /**
365
335
  * Hook for scheduler schedule operations (recurring jobs)
366
336
  *
@@ -375,7 +345,7 @@ declare function useSchedulerTasks(options: UseAgentsOptions): {
375
345
  * await pauseSchedule(scheduleId);
376
346
  * ```
377
347
  */
378
- declare function useSchedulerSchedules(options: UseAgentsOptions): {
348
+ declare function useSchedulerSchedules(options: UseSchedulerSchedulesOptions): {
379
349
  loading: boolean;
380
350
  error: string | null;
381
351
  listSchedules: (params?: {
@@ -392,4 +362,91 @@ declare function useSchedulerSchedules(options: UseAgentsOptions): {
392
362
  runSchedule: (scheduleId: string) => Promise<SchedulerSchedule | null>;
393
363
  };
394
364
 
395
- export { type UseAgentsOptions, type UseAsyncOptions, type UseAsyncReturn, type UseWidgetsOptions, useAgentJobs, useAgents, useAnalytics, useApiAsync, useAsync, useIntegrations, useOptionsRef, useSandbox, useSchedulerSchedules, useSchedulerTasks, useSkillUserConfig, useSkills, useSubAgents, useToolDefinitions, useWidgets };
365
+ /** Live state accumulated from SSE events for a single background agent */
366
+ interface BGAgentLiveState {
367
+ status: "running" | "completed" | "failed";
368
+ progressLog: string[];
369
+ latestMessage: string;
370
+ result?: string;
371
+ error?: string;
372
+ }
373
+ /** Options for useBackgroundAgents hook */
374
+ interface UseBackgroundAgentsOptions extends ApiClientOptions {
375
+ /** Chat service URL for SSE streaming (e.g., wss://chat.example.com or https://chat.example.com) */
376
+ chatServiceUrl?: string;
377
+ /** User ID (typically email) for chat operations */
378
+ userId?: string;
379
+ }
380
+ /** Background status reported by the agent via report_status tool */
381
+ type BackgroundStatus = "processing" | "completed" | "failed";
382
+ /** Watched chat state with messages */
383
+ interface WatchedChatState {
384
+ chatKey: string;
385
+ messages: ChatMessage[];
386
+ status: "loading" | "active" | "completed" | "error";
387
+ /** Background agent status (from report_status tool) */
388
+ backgroundStatus?: BackgroundStatus;
389
+ /** Background agent status message (from report_status tool) */
390
+ backgroundStatusMessage?: string;
391
+ /** History of all status updates for inline display */
392
+ statusHistory: AgentStatusUpdate[];
393
+ title?: string;
394
+ metadata?: Record<string, unknown>;
395
+ error?: string;
396
+ }
397
+ /**
398
+ * Hook for triggering background agents, streaming progress via SSE, and checking status.
399
+ *
400
+ * @example
401
+ * ```tsx
402
+ * const { startChat, sendMessage } = useChatContext();
403
+ * const { liveStates, createTask, streamJob, checkStatus } = useBackgroundAgents({
404
+ * baseUrl: apiGatewayUrl,
405
+ * orgId: selectedOrgId,
406
+ * startChat,
407
+ * sendMessage,
408
+ * });
409
+ *
410
+ * // Create a background task (simplified flow using chat)
411
+ * const chatKey = await createTask("Analyze the quarterly report");
412
+ *
413
+ * // Or trigger via jobs API (PostgreSQL-backed)
414
+ * const result = await triggerAgent({ name: "Analysis", prompt: "...", agentName: "Research Agent" });
415
+ * if (result?.jobId) streamJob(result.jobId);
416
+ * ```
417
+ */
418
+ declare function useBackgroundAgents(options: UseBackgroundAgentsOptions): {
419
+ liveStates: Record<string, BGAgentLiveState>;
420
+ streamJob: (jobId: string) => void;
421
+ createTask: (prompt: string, attachments?: Attachment[]) => Promise<string | null>;
422
+ watchChat: (chatKey: string) => Promise<void>;
423
+ unwatchChat: (chatKey: string) => void;
424
+ watchedChats: Record<string, WatchedChatState>;
425
+ triggerAgent: (request: Pick<TriggerBackgroundAgentRequest, "name" | "prompt" | "agentName" | "context" | "enableSSE" | "description">) => Promise<TriggerBackgroundAgentResponse | null>;
426
+ checkStatus: (jobId: string) => Promise<BackgroundAgentStatusResponse | null>;
427
+ listAgentSummaries: () => Promise<AgentSummary[]>;
428
+ loading: boolean;
429
+ error: string | null;
430
+ };
431
+
432
+ /**
433
+ * Creates a ref that stays synchronized with the provided options.
434
+ * Useful for accessing current options values in callbacks without
435
+ * causing re-renders or stale closure issues.
436
+ *
437
+ * @param options - The options object to track
438
+ * @returns A ref that always contains the latest options
439
+ *
440
+ * @example
441
+ * ```tsx
442
+ * const optionsRef = useOptionsRef(options);
443
+ *
444
+ * const fetchData = useCallback(async () => {
445
+ * // Always has the latest options, no stale closure
446
+ * const result = await api.fetch(optionsRef.current);
447
+ * }, []); // No need to include options in deps
448
+ * ```
449
+ */
450
+ declare function useOptionsRef<T>(options: T): React.MutableRefObject<T>;
451
+
452
+ export { type BGAgentLiveState, type BackgroundStatus, type UseAgentJobsOptions, type UseAgentsOptions, type UseAnalyticsOptions, type UseBackgroundAgentsOptions, type UseIntegrationsOptions, type UseSandboxOptions, type UseSchedulerSchedulesOptions, type UseSchedulerTasksOptions, type UseSkillUserConfigOptions, type UseSkillsOptions, type UseSubAgentsOptions, type UseToolDefinitionsOptions, type UseWidgetsOptions, type WatchedChatState, useAgentJobs, useAgents, useAnalytics, useBackgroundAgents, useIntegrations, useOptionsRef, useSandbox, useSchedulerSchedules, useSchedulerTasks, useSkillUserConfig, useSkills, useSubAgents, useToolDefinitions, useWidgets };
@@ -1,63 +1,12 @@
1
- import { ApiResponse, ApiClientOptions } from '@elqnt/api-client';
2
- import { Z as AgentJob, A as Agent, aF as AgentSummary, dw as SkillUserConfig, dd as ResolveSkillConfigResponse, dk as Skill, dO as SubAgent, e9 as ToolDefinition, aY as AgentWidget } from '../agent-models-C36pvpUb.js';
3
- import { ba as UserIntegration, ap as IntegrationProviderTS, aA as IntegrationTypeTS, h as CreateSandboxRequest, aW as Sandbox } from '../sandbox-BHeWPjLU.js';
4
- import { DateFilter, SchedulerSchedule, SchedulerTask } from '../api/index.js';
1
+ import { ApiClientOptions } from '@elqnt/api-client';
2
+ import { A as Agent, aI as AgentSummary, ds as Skill, dV as SubAgent, eh as ToolDefinition, Z as AgentJob, a$ as AgentWidget, dD as SkillUserConfig, dk as ResolveSkillConfigResponse, aB as AgentStatusUpdate, eG as TriggerBackgroundAgentRequest, eH as TriggerBackgroundAgentResponse, bc as BackgroundAgentStatusResponse } from '../agent-models-DLQlC7N6.js';
3
+ export { ba as BackgroundAgentProgressEvent } from '../agent-models-DLQlC7N6.js';
4
+ import { DateFilter, SchedulerTask, SchedulerSchedule } from '../api/index.js';
5
+ import { ba as UserIntegration, ap as IntegrationProviderTS, aA as IntegrationTypeTS, h as CreateSandboxRequest, aW as Sandbox } from '../sandbox-DOxoM2Ge.js';
6
+ import { ChatMessage, Attachment } from '@elqnt/chat/models';
7
+ export { B as BGAgentTransport, a as BGAgentTransportConfig } from '../types-k9PszCzt.js';
5
8
  import '@elqnt/types';
6
9
 
7
- interface UseAsyncOptions {
8
- onError?: (error: string) => void;
9
- }
10
- interface UseAsyncReturn<TResult, TArgs extends unknown[] = []> {
11
- execute: (...args: TArgs) => Promise<TResult>;
12
- loading: boolean;
13
- error: string | null;
14
- clearError: () => void;
15
- }
16
- /**
17
- * Generic async hook for any promise-returning function.
18
- * Uses a request counter to properly track concurrent requests.
19
- */
20
- declare function useAsync<TResult, TArgs extends unknown[] = []>(asyncFn: (...args: TArgs) => Promise<TResult>, options?: UseAsyncOptions): UseAsyncReturn<TResult, TArgs>;
21
- /**
22
- * Specialized async hook for API operations that return ApiResponse.
23
- * Automatically extracts data and handles API errors.
24
- *
25
- * @param asyncFn - Function that returns ApiResponse<TResponse>
26
- * @param extractor - Function to extract the desired result from response data
27
- * @param defaultValue - Default value to return on error
28
- * @param options - Optional configuration
29
- *
30
- * @example
31
- * ```tsx
32
- * const { execute: listAgents, loading, error } = useApiAsync(
33
- * () => listAgentsApi(optionsRef.current),
34
- * (data) => data.agents,
35
- * []
36
- * );
37
- * ```
38
- */
39
- declare function useApiAsync<TResponse, TResult, TArgs extends unknown[] = []>(asyncFn: (...args: TArgs) => Promise<ApiResponse<TResponse>>, extractor: (data: TResponse) => TResult, defaultValue: TResult, options?: UseAsyncOptions): UseAsyncReturn<TResult, TArgs>;
40
-
41
- /**
42
- * Creates a ref that stays synchronized with the provided options.
43
- * Useful for accessing current options values in callbacks without
44
- * causing re-renders or stale closure issues.
45
- *
46
- * @param options - The options object to track
47
- * @returns A ref that always contains the latest options
48
- *
49
- * @example
50
- * ```tsx
51
- * const optionsRef = useOptionsRef(options);
52
- *
53
- * const fetchData = useCallback(async () => {
54
- * // Always has the latest options, no stale closure
55
- * const result = await api.fetch(optionsRef.current);
56
- * }, []); // No need to include options in deps
57
- * ```
58
- */
59
- declare function useOptionsRef<T>(options: T): React.MutableRefObject<T>;
60
-
61
10
  type UseAgentsOptions = ApiClientOptions;
62
11
  /**
63
12
  * Hook for agent CRUD operations
@@ -83,10 +32,12 @@ declare function useAgents(options: UseAgentsOptions): {
83
32
  deleteAgent: (agentId: string) => Promise<boolean>;
84
33
  getDefaultAgent: () => Promise<Agent | null>;
85
34
  };
35
+
36
+ type UseSkillsOptions = ApiClientOptions;
86
37
  /**
87
38
  * Hook for skill CRUD operations
88
39
  */
89
- declare function useSkills(options: UseAgentsOptions): {
40
+ declare function useSkills(options: UseSkillsOptions): {
90
41
  loading: boolean;
91
42
  error: string | null;
92
43
  listSkills: () => Promise<Skill[]>;
@@ -96,10 +47,12 @@ declare function useSkills(options: UseAgentsOptions): {
96
47
  deleteSkill: (skillId: string) => Promise<boolean>;
97
48
  getCategories: () => Promise<string[]>;
98
49
  };
50
+
51
+ type UseSubAgentsOptions = ApiClientOptions;
99
52
  /**
100
53
  * Hook for sub-agent CRUD operations
101
54
  */
102
- declare function useSubAgents(options: UseAgentsOptions): {
55
+ declare function useSubAgents(options: UseSubAgentsOptions): {
103
56
  loading: boolean;
104
57
  error: string | null;
105
58
  listSubAgents: () => Promise<SubAgent[]>;
@@ -108,6 +61,8 @@ declare function useSubAgents(options: UseAgentsOptions): {
108
61
  updateSubAgent: (subAgentId: string, subAgent: Partial<SubAgent>) => Promise<SubAgent | null>;
109
62
  deleteSubAgent: (subAgentId: string) => Promise<boolean>;
110
63
  };
64
+
65
+ type UseToolDefinitionsOptions = ApiClientOptions;
111
66
  /**
112
67
  * Hook for tool definition CRUD operations
113
68
  *
@@ -121,7 +76,7 @@ declare function useSubAgents(options: UseAgentsOptions): {
121
76
  * const toolDefs = await listToolDefinitions();
122
77
  * ```
123
78
  */
124
- declare function useToolDefinitions(options: UseAgentsOptions): {
79
+ declare function useToolDefinitions(options: UseToolDefinitionsOptions): {
125
80
  loading: boolean;
126
81
  error: string | null;
127
82
  listToolDefinitions: () => Promise<ToolDefinition[]>;
@@ -131,6 +86,8 @@ declare function useToolDefinitions(options: UseAgentsOptions): {
131
86
  updateToolDefinition: (toolDefId: string, toolDefinition: Partial<ToolDefinition>) => Promise<ToolDefinition | null>;
132
87
  deleteToolDefinition: (toolDefId: string) => Promise<boolean>;
133
88
  };
89
+
90
+ type UseAgentJobsOptions = ApiClientOptions;
134
91
  /**
135
92
  * Hook for agent job CRUD operations
136
93
  *
@@ -145,7 +102,7 @@ declare function useToolDefinitions(options: UseAgentsOptions): {
145
102
  * await pauseAgentJob(jobId);
146
103
  * ```
147
104
  */
148
- declare function useAgentJobs(options: UseAgentsOptions): {
105
+ declare function useAgentJobs(options: UseAgentJobsOptions): {
149
106
  loading: boolean;
150
107
  error: string | null;
151
108
  listAgentJobs: () => Promise<AgentJob[]>;
@@ -156,7 +113,8 @@ declare function useAgentJobs(options: UseAgentsOptions): {
156
113
  pauseAgentJob: (jobId: string) => Promise<AgentJob | null>;
157
114
  resumeAgentJob: (jobId: string) => Promise<AgentJob | null>;
158
115
  };
159
- interface UseWidgetsOptions extends UseAgentsOptions {
116
+
117
+ interface UseWidgetsOptions extends ApiClientOptions {
160
118
  agentId: string;
161
119
  }
162
120
  /**
@@ -184,6 +142,8 @@ declare function useWidgets(options: UseWidgetsOptions): {
184
142
  deleteWidget: (widgetId: string) => Promise<boolean>;
185
143
  setDefaultWidget: (widgetId: string) => Promise<boolean>;
186
144
  };
145
+
146
+ type UseSkillUserConfigOptions = ApiClientOptions;
187
147
  /**
188
148
  * Hook for skill user configuration operations
189
149
  *
@@ -198,7 +158,7 @@ declare function useWidgets(options: UseWidgetsOptions): {
198
158
  * await updateSkillUserConfig(skillId, { enabled: true });
199
159
  * ```
200
160
  */
201
- declare function useSkillUserConfig(options: UseAgentsOptions): {
161
+ declare function useSkillUserConfig(options: UseSkillUserConfigOptions): {
202
162
  loading: boolean;
203
163
  error: string | null;
204
164
  getSkillUserConfig: (skillId: string, agentId?: string | undefined) => Promise<SkillUserConfig | null>;
@@ -216,6 +176,8 @@ declare function useSkillUserConfig(options: UseAgentsOptions): {
216
176
  } | undefined) => Promise<SkillUserConfig[]>;
217
177
  resolveSkillConfig: (skillId: string, agentId: string) => Promise<ResolveSkillConfigResponse | null>;
218
178
  };
179
+
180
+ type UseAnalyticsOptions = ApiClientOptions;
219
181
  /**
220
182
  * Hook for agent analytics operations
221
183
  *
@@ -229,7 +191,7 @@ declare function useSkillUserConfig(options: UseAgentsOptions): {
229
191
  * const chatsData = await getAgentChatsAnalytics({ from: '2024-01-01', to: '2024-12-31' });
230
192
  * ```
231
193
  */
232
- declare function useAnalytics(options: UseAgentsOptions): {
194
+ declare function useAnalytics(options: UseAnalyticsOptions): {
233
195
  loading: boolean;
234
196
  error: string | null;
235
197
  getAgentChatsAnalytics: (params: {
@@ -245,6 +207,8 @@ declare function useAnalytics(options: UseAgentsOptions): {
245
207
  date_filter: DateFilter;
246
208
  }) => Promise<unknown[]>;
247
209
  };
210
+
211
+ type UseIntegrationsOptions = ApiClientOptions;
248
212
  /**
249
213
  * Hook for user integration operations (OAuth connections)
250
214
  *
@@ -259,7 +223,7 @@ declare function useAnalytics(options: UseAgentsOptions): {
259
223
  * const { auth_url } = await connectIntegration({ provider: 'google', integrationType: 'email', redirectUri: '/callback' });
260
224
  * ```
261
225
  */
262
- declare function useIntegrations(options: UseAgentsOptions): {
226
+ declare function useIntegrations(options: UseIntegrationsOptions): {
263
227
  loading: boolean;
264
228
  error: string | null;
265
229
  listIntegrations: () => Promise<UserIntegration[]>;
@@ -291,6 +255,8 @@ declare function useIntegrations(options: UseAgentsOptions): {
291
255
  instancesCreated: number;
292
256
  } | null>;
293
257
  };
258
+
259
+ type UseSandboxOptions = ApiClientOptions;
294
260
  /**
295
261
  * Hook for sandbox operations (AI-generated HTML sandboxes)
296
262
  *
@@ -305,7 +271,7 @@ declare function useIntegrations(options: UseAgentsOptions): {
305
271
  * console.log(result.url); // sandbox URL
306
272
  * ```
307
273
  */
308
- declare function useSandbox(options: UseAgentsOptions): {
274
+ declare function useSandbox(options: UseSandboxOptions): {
309
275
  loading: boolean;
310
276
  error: string | null;
311
277
  createSandbox: (request: Omit<CreateSandboxRequest, "orgId">) => Promise<{
@@ -328,6 +294,8 @@ declare function useSandbox(options: UseAgentsOptions): {
328
294
  }>;
329
295
  deleteSandbox: (sandboxId: string) => Promise<boolean>;
330
296
  };
297
+
298
+ type UseSchedulerTasksOptions = ApiClientOptions;
331
299
  /**
332
300
  * Hook for scheduler task operations
333
301
  *
@@ -342,7 +310,7 @@ declare function useSandbox(options: UseAgentsOptions): {
342
310
  * await snoozeTask(taskId, { amount: 30, unit: "minutes" });
343
311
  * ```
344
312
  */
345
- declare function useSchedulerTasks(options: UseAgentsOptions): {
313
+ declare function useSchedulerTasks(options: UseSchedulerTasksOptions): {
346
314
  loading: boolean;
347
315
  error: string | null;
348
316
  listTasks: (params?: {
@@ -361,6 +329,8 @@ declare function useSchedulerTasks(options: UseAgentsOptions): {
361
329
  completeTask: (taskId: string) => Promise<SchedulerTask | null>;
362
330
  startTask: (taskId: string) => Promise<SchedulerTask | null>;
363
331
  };
332
+
333
+ type UseSchedulerSchedulesOptions = ApiClientOptions;
364
334
  /**
365
335
  * Hook for scheduler schedule operations (recurring jobs)
366
336
  *
@@ -375,7 +345,7 @@ declare function useSchedulerTasks(options: UseAgentsOptions): {
375
345
  * await pauseSchedule(scheduleId);
376
346
  * ```
377
347
  */
378
- declare function useSchedulerSchedules(options: UseAgentsOptions): {
348
+ declare function useSchedulerSchedules(options: UseSchedulerSchedulesOptions): {
379
349
  loading: boolean;
380
350
  error: string | null;
381
351
  listSchedules: (params?: {
@@ -392,4 +362,91 @@ declare function useSchedulerSchedules(options: UseAgentsOptions): {
392
362
  runSchedule: (scheduleId: string) => Promise<SchedulerSchedule | null>;
393
363
  };
394
364
 
395
- export { type UseAgentsOptions, type UseAsyncOptions, type UseAsyncReturn, type UseWidgetsOptions, useAgentJobs, useAgents, useAnalytics, useApiAsync, useAsync, useIntegrations, useOptionsRef, useSandbox, useSchedulerSchedules, useSchedulerTasks, useSkillUserConfig, useSkills, useSubAgents, useToolDefinitions, useWidgets };
365
+ /** Live state accumulated from SSE events for a single background agent */
366
+ interface BGAgentLiveState {
367
+ status: "running" | "completed" | "failed";
368
+ progressLog: string[];
369
+ latestMessage: string;
370
+ result?: string;
371
+ error?: string;
372
+ }
373
+ /** Options for useBackgroundAgents hook */
374
+ interface UseBackgroundAgentsOptions extends ApiClientOptions {
375
+ /** Chat service URL for SSE streaming (e.g., wss://chat.example.com or https://chat.example.com) */
376
+ chatServiceUrl?: string;
377
+ /** User ID (typically email) for chat operations */
378
+ userId?: string;
379
+ }
380
+ /** Background status reported by the agent via report_status tool */
381
+ type BackgroundStatus = "processing" | "completed" | "failed";
382
+ /** Watched chat state with messages */
383
+ interface WatchedChatState {
384
+ chatKey: string;
385
+ messages: ChatMessage[];
386
+ status: "loading" | "active" | "completed" | "error";
387
+ /** Background agent status (from report_status tool) */
388
+ backgroundStatus?: BackgroundStatus;
389
+ /** Background agent status message (from report_status tool) */
390
+ backgroundStatusMessage?: string;
391
+ /** History of all status updates for inline display */
392
+ statusHistory: AgentStatusUpdate[];
393
+ title?: string;
394
+ metadata?: Record<string, unknown>;
395
+ error?: string;
396
+ }
397
+ /**
398
+ * Hook for triggering background agents, streaming progress via SSE, and checking status.
399
+ *
400
+ * @example
401
+ * ```tsx
402
+ * const { startChat, sendMessage } = useChatContext();
403
+ * const { liveStates, createTask, streamJob, checkStatus } = useBackgroundAgents({
404
+ * baseUrl: apiGatewayUrl,
405
+ * orgId: selectedOrgId,
406
+ * startChat,
407
+ * sendMessage,
408
+ * });
409
+ *
410
+ * // Create a background task (simplified flow using chat)
411
+ * const chatKey = await createTask("Analyze the quarterly report");
412
+ *
413
+ * // Or trigger via jobs API (PostgreSQL-backed)
414
+ * const result = await triggerAgent({ name: "Analysis", prompt: "...", agentName: "Research Agent" });
415
+ * if (result?.jobId) streamJob(result.jobId);
416
+ * ```
417
+ */
418
+ declare function useBackgroundAgents(options: UseBackgroundAgentsOptions): {
419
+ liveStates: Record<string, BGAgentLiveState>;
420
+ streamJob: (jobId: string) => void;
421
+ createTask: (prompt: string, attachments?: Attachment[]) => Promise<string | null>;
422
+ watchChat: (chatKey: string) => Promise<void>;
423
+ unwatchChat: (chatKey: string) => void;
424
+ watchedChats: Record<string, WatchedChatState>;
425
+ triggerAgent: (request: Pick<TriggerBackgroundAgentRequest, "name" | "prompt" | "agentName" | "context" | "enableSSE" | "description">) => Promise<TriggerBackgroundAgentResponse | null>;
426
+ checkStatus: (jobId: string) => Promise<BackgroundAgentStatusResponse | null>;
427
+ listAgentSummaries: () => Promise<AgentSummary[]>;
428
+ loading: boolean;
429
+ error: string | null;
430
+ };
431
+
432
+ /**
433
+ * Creates a ref that stays synchronized with the provided options.
434
+ * Useful for accessing current options values in callbacks without
435
+ * causing re-renders or stale closure issues.
436
+ *
437
+ * @param options - The options object to track
438
+ * @returns A ref that always contains the latest options
439
+ *
440
+ * @example
441
+ * ```tsx
442
+ * const optionsRef = useOptionsRef(options);
443
+ *
444
+ * const fetchData = useCallback(async () => {
445
+ * // Always has the latest options, no stale closure
446
+ * const result = await api.fetch(optionsRef.current);
447
+ * }, []); // No need to include options in deps
448
+ * ```
449
+ */
450
+ declare function useOptionsRef<T>(options: T): React.MutableRefObject<T>;
451
+
452
+ export { type BGAgentLiveState, type BackgroundStatus, type UseAgentJobsOptions, type UseAgentsOptions, type UseAnalyticsOptions, type UseBackgroundAgentsOptions, type UseIntegrationsOptions, type UseSandboxOptions, type UseSchedulerSchedulesOptions, type UseSchedulerTasksOptions, type UseSkillUserConfigOptions, type UseSkillsOptions, type UseSubAgentsOptions, type UseToolDefinitionsOptions, type UseWidgetsOptions, type WatchedChatState, useAgentJobs, useAgents, useAnalytics, useBackgroundAgents, useIntegrations, useOptionsRef, useSandbox, useSchedulerSchedules, useSchedulerTasks, useSkillUserConfig, useSkills, useSubAgents, useToolDefinitions, useWidgets };