@elqnt/agents 3.4.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +6 -0
  2. package/SKILL.md +724 -0
  3. package/dist/{agent-models-D6WgsFMZ.d.mts → agent-models-B-wTMdwF.d.mts} +44 -9
  4. package/dist/{agent-models-D6WgsFMZ.d.ts → agent-models-B-wTMdwF.d.ts} +44 -9
  5. package/dist/api/index.d.mts +6 -6
  6. package/dist/api/index.d.ts +6 -6
  7. package/dist/api/index.js +3 -4
  8. package/dist/api/index.js.map +1 -1
  9. package/dist/api/index.mjs +1 -2
  10. package/dist/api/server.d.mts +3 -3
  11. package/dist/api/server.d.ts +3 -3
  12. package/dist/api/server.js +6 -8
  13. package/dist/api/server.js.map +1 -1
  14. package/dist/api/server.mjs +5 -7
  15. package/dist/api/server.mjs.map +1 -1
  16. package/dist/{chunk-XQ7LOAN3.js → chunk-2FZZW4O4.js} +7 -5
  17. package/dist/chunk-2FZZW4O4.js.map +1 -0
  18. package/dist/{chunk-3EHE4O57.mjs → chunk-6FKG2JBT.mjs} +1 -3
  19. package/dist/{chunk-3EHE4O57.mjs.map → chunk-6FKG2JBT.mjs.map} +1 -1
  20. package/dist/{chunk-TY57JG3P.mjs → chunk-CCQNGD3U.mjs} +5 -3
  21. package/dist/chunk-CCQNGD3U.mjs.map +1 -0
  22. package/dist/{chunk-ZS7DRNCT.js → chunk-DQATIIAV.js} +2 -4
  23. package/dist/chunk-DQATIIAV.js.map +1 -0
  24. package/dist/{chunk-L5FLJB3H.mjs → chunk-NHIVBTLU.mjs} +5 -7
  25. package/dist/chunk-NHIVBTLU.mjs.map +1 -0
  26. package/dist/{chunk-3PFZRJ4A.js → chunk-QH234LAO.js} +6 -8
  27. package/dist/chunk-QH234LAO.js.map +1 -0
  28. package/dist/{chunk-2JDVRL35.js → chunk-QXMZEZRM.js} +2 -4
  29. package/dist/chunk-QXMZEZRM.js.map +1 -0
  30. package/dist/{chunk-HYR7PXFU.mjs → chunk-YQFBZW6F.mjs} +1 -3
  31. package/dist/{chunk-HYR7PXFU.mjs.map → chunk-YQFBZW6F.mjs.map} +1 -1
  32. package/dist/hooks/index.d.mts +354 -142
  33. package/dist/hooks/index.d.ts +354 -142
  34. package/dist/hooks/index.js +1094 -6
  35. package/dist/hooks/index.js.map +1 -1
  36. package/dist/hooks/index.mjs +1107 -19
  37. package/dist/hooks/index.mjs.map +1 -1
  38. package/dist/index.d.mts +2 -4
  39. package/dist/index.d.ts +2 -4
  40. package/dist/index.js +5 -35
  41. package/dist/index.js.map +1 -1
  42. package/dist/index.mjs +8 -38
  43. package/dist/models/index.d.mts +2 -2
  44. package/dist/models/index.d.ts +2 -2
  45. package/dist/models/index.js +6 -3
  46. package/dist/models/index.js.map +1 -1
  47. package/dist/models/index.mjs +5 -2
  48. package/dist/{sandbox-DOxoM2Ge.d.ts → sandbox-Djb8gA7e.d.mts} +32 -2
  49. package/dist/{sandbox-DOxoM2Ge.d.mts → sandbox-Djb8gA7e.d.ts} +32 -2
  50. package/dist/transport/index.d.mts +3 -3
  51. package/dist/transport/index.d.ts +3 -3
  52. package/dist/transport/index.js +3 -4
  53. package/dist/transport/index.js.map +1 -1
  54. package/dist/transport/index.mjs +1 -2
  55. package/dist/{types-BBPz_6kK.d.ts → types-BzNzXaqk.d.ts} +2 -2
  56. package/dist/{types-BtfxlyHk.d.mts → types-CSyY6Qv7.d.mts} +2 -2
  57. package/dist/utils/index.d.mts +1 -1
  58. package/dist/utils/index.d.ts +1 -1
  59. package/dist/utils/index.js +3 -4
  60. package/dist/utils/index.js.map +1 -1
  61. package/dist/utils/index.mjs +1 -2
  62. package/package.json +9 -8
  63. package/dist/chunk-2JDVRL35.js.map +0 -1
  64. package/dist/chunk-3PFZRJ4A.js.map +0 -1
  65. package/dist/chunk-43FTKGM6.mjs +0 -1114
  66. package/dist/chunk-43FTKGM6.mjs.map +0 -1
  67. package/dist/chunk-L5FLJB3H.mjs.map +0 -1
  68. package/dist/chunk-RG42SHBX.js +0 -1114
  69. package/dist/chunk-RG42SHBX.js.map +0 -1
  70. package/dist/chunk-TY57JG3P.mjs.map +0 -1
  71. package/dist/chunk-XQ7LOAN3.js.map +0 -1
  72. package/dist/chunk-ZS7DRNCT.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/eloquent/eloquent/packages/@elqnt/agents/dist/hooks/index.js"],"names":[],"mappings":"AAAA,qFAAY;AACZ,YAAY;AACZ;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,uDAA6B;AAC7B,gCAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,62BAAC","file":"/home/runner/work/eloquent/eloquent/packages/@elqnt/agents/dist/hooks/index.js"}
1
+ {"version":3,"sources":["/home/runner/work/eloquent/eloquent/packages/@elqnt/agents/dist/hooks/index.js","../../hooks/use-agents.ts","../../hooks/use-options-ref.ts","../../hooks/use-skills.ts","../../hooks/use-sub-agents.ts","../../hooks/use-tool-definitions.ts","../../hooks/use-agent-jobs.ts","../../hooks/use-widgets.ts","../../hooks/use-skill-user-config.ts","../../hooks/use-analytics.ts","../../hooks/use-integrations.ts","../../hooks/use-sandbox.ts","../../hooks/use-structured-output.ts","../../hooks/use-scheduler-tasks.ts","../../hooks/use-scheduler-schedules.ts","../../hooks/use-background-agents.ts"],"names":["useMemo","useRef","bgStatus","bgMessage"],"mappings":"AAAA,ylBAAY;AACZ;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC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PH,EAAAA;AACL,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACG,EAAA;AACP;AfilBkB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/eloquent/eloquent/packages/@elqnt/agents/dist/hooks/index.js","sourcesContent":[null,"\"use client\";\n\nimport { useCallback, useMemo, useState } from \"react\";\nimport type { ApiClientOptions } from \"@elqnt/api-client\";\nimport { useApiAsync } from \"@elqnt/api-client/hooks\";\nimport type { Agent, AgentSummary } from \"../models\";\nimport {\n listAgentsApi,\n listAgentsSummaryApi,\n getAgentApi,\n createAgentApi,\n updateAgentApi,\n deleteAgentApi,\n getDefaultAgentApi,\n exportAgentApi,\n importAgentApi,\n} from \"../api\";\nimport { useOptionsRef } from \"./use-options-ref\";\n\nexport type UseAgentsOptions = ApiClientOptions;\n\n/**\n * The exact, stable return surface of `useAgents`.\n *\n * This is the agent/consumer **contract**: the only methods that exist on the\n * agents hook. Every method is imperative and DOES NOT throw — on failure it\n * resolves to the documented default (`[]`, `null`, `false`) and sets `error`.\n *\n * `exportAgent` follows the same no-throw contract: it returns the exported\n * `Agent`, or `null` on failure (with `error` set). As a documented\n * **side-effect** it also triggers a browser JSON download when an agent is\n * returned. See `SKILL.md`.\n */\nexport interface UseAgentsReturn {\n /** OR of all in-flight method loading flags. */\n loading: boolean;\n /** First non-null method error, else null. */\n error: string | null;\n\n /** GET /api/v1/agents — default []. */\n listAgents: () => Promise<Agent[]>;\n /** GET /api/v1/agents/summary — default []. */\n listAgentSummaries: () => Promise<AgentSummary[]>;\n /** GET /api/v1/agents/{agentId} — default null. */\n getAgent: (agentId: string) => Promise<Agent | null>;\n /** POST /api/v1/agents, body Partial<Agent> — created agent, or null on error. */\n createAgent: (agent: Partial<Agent>) => Promise<Agent | null>;\n /** PUT /api/v1/agents/{agentId}, body Partial<Agent> — updated agent, or null on error. */\n updateAgent: (agentId: string, agent: Partial<Agent>) => Promise<Agent | null>;\n /** DELETE /api/v1/agents/{agentId} — true on success. */\n deleteAgent: (agentId: string) => Promise<boolean>;\n /** GET /api/v1/agents/default — default null. */\n getDefaultAgent: () => Promise<Agent | null>;\n /**\n * GET /api/v1/agents/{agentId}/export — returns the exported Agent, or null\n * on error (non-throwing). Side-effect: triggers a JSON download when an\n * agent is returned.\n */\n exportAgent: (agentId: string) => Promise<Agent | null>;\n /** POST /api/v1/agents/import, body Agent — imported agent, or null on error. */\n importAgent: (agent: Agent) => Promise<Agent | null>;\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): UseAgentsReturn {\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 [exportLoading, setExportLoading] = useState(false);\n const [exportError, setExportError] = useState<string | null>(null);\n\n // Documented side-effect: trigger a browser JSON download for an agent.\n // Kept separate from the data path so the data path stays non-throwing.\n const downloadAgentJson = (agent: Agent) => {\n const json = JSON.stringify(agent, null, 2);\n const blob = new Blob([json], { type: \"application/json\" });\n const url = URL.createObjectURL(blob);\n const a = document.createElement(\"a\");\n a.href = url;\n a.download = `${agent.name || \"agent\"}.agent.json`;\n a.click();\n URL.revokeObjectURL(url);\n };\n\n const exportAgent = useCallback(async (agentId: string): Promise<Agent | null> => {\n setExportLoading(true);\n setExportError(null);\n try {\n const agent = await exportAgentApi(agentId, optionsRef.current);\n downloadAgentJson(agent);\n return agent;\n } catch (err) {\n setExportError(err instanceof Error ? err.message : \"Failed to export agent\");\n return null;\n } finally {\n setExportLoading(false);\n }\n // optionsRef is stable; downloadAgentJson is a pure helper.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const { execute: importAgent, loading: importLoading, error: importError } = useApiAsync(\n (agent: Agent) => importAgentApi(agent, optionsRef.current),\n (data) => data.agent || null,\n null as Agent | null\n );\n\n const loading = listLoading || listSummaryLoading || getLoading || createLoading || updateLoading || deleteLoading || defaultLoading || exportLoading || importLoading;\n const error = listError || listSummaryError || getError || createError || updateError || deleteError || defaultError || exportError || importError;\n\n return useMemo(\n () => ({\n loading,\n error,\n listAgents,\n listAgentSummaries,\n getAgent,\n createAgent,\n updateAgent,\n deleteAgent,\n getDefaultAgent,\n exportAgent,\n importAgent,\n }),\n [loading, error, listAgents, listAgentSummaries, getAgent, createAgent, updateAgent, deleteAgent, getDefaultAgent, exportAgent, importAgent]\n );\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","\"use client\";\n\nimport { useMemo } from \"react\";\nimport type { ApiClientOptions } from \"@elqnt/api-client\";\nimport type { Skill } from \"../models\";\nimport {\n listSkillsApi,\n getSkillApi,\n createSkillApi,\n updateSkillApi,\n deleteSkillApi,\n getSkillCategoriesApi,\n} from \"../api\";\nimport { useApiAsync } from \"@elqnt/api-client/hooks\";\nimport { useOptionsRef } from \"./use-options-ref\";\n\nexport type UseSkillsOptions = ApiClientOptions;\n\n/**\n * The exact, stable return surface of `useSkills` (the standalone catalog\n * `Skill` CRUD, keyed by name in v2). Imperative, non-throwing — on failure a\n * method resolves to its default (`[]`, `null`, `false`) and sets `error`.\n * See `SKILL.md`.\n */\nexport interface UseSkillsReturn {\n /** OR of all in-flight method loading flags. */\n loading: boolean;\n /** First non-null method error, else null. */\n error: string | null;\n\n /** GET /api/v1/skills — default []. */\n listSkills: () => Promise<Skill[]>;\n /** GET /api/v1/skills/{skillId} — default null. */\n getSkill: (skillId: string) => Promise<Skill | null>;\n /** POST /api/v1/skills, body Partial<Skill> — created skill, or null on error. */\n createSkill: (skill: Partial<Skill>) => Promise<Skill | null>;\n /** PUT /api/v1/skills/{skillId}, body Partial<Skill> — updated skill, or null on error. */\n updateSkill: (skillId: string, skill: Partial<Skill>) => Promise<Skill | null>;\n /** DELETE /api/v1/skills/{skillId} — true on success. */\n deleteSkill: (skillId: string) => Promise<boolean>;\n /** GET /api/v1/skills/categories — default []. */\n getCategories: () => Promise<string[]>;\n}\n\n/**\n * Hook for skill CRUD operations\n */\nexport function useSkills(options: UseSkillsOptions): UseSkillsReturn {\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","\"use client\";\n\nimport { useMemo } from \"react\";\nimport type { ApiClientOptions } from \"@elqnt/api-client\";\nimport type { SubAgent } from \"../models\";\nimport {\n listSubAgentsApi,\n getSubAgentApi,\n createSubAgentApi,\n updateSubAgentApi,\n deleteSubAgentApi,\n} from \"../api\";\nimport { useApiAsync } from \"@elqnt/api-client/hooks\";\nimport { useOptionsRef } from \"./use-options-ref\";\n\nexport type UseSubAgentsOptions = ApiClientOptions;\n\n/**\n * The exact, stable return surface of `useSubAgents`. Imperative, non-throwing —\n * on failure a method resolves to its default (`[]`, `null`, `false`) and sets\n * `error`. See `SKILL.md`.\n */\nexport interface UseSubAgentsReturn {\n /** OR of all in-flight method loading flags. */\n loading: boolean;\n /** First non-null method error, else null. */\n error: string | null;\n\n /** GET /api/v1/subagents — default []. */\n listSubAgents: () => Promise<SubAgent[]>;\n /** GET /api/v1/subagents/{subAgentId} — default null. */\n getSubAgent: (subAgentId: string) => Promise<SubAgent | null>;\n /** POST /api/v1/subagents, body { subAgent } — created sub-agent, or null on error. */\n createSubAgent: (subAgent: Partial<SubAgent>) => Promise<SubAgent | null>;\n /** PUT /api/v1/subagents/{subAgentId}, body { subAgent } — updated sub-agent, or null on error. */\n updateSubAgent: (subAgentId: string, subAgent: Partial<SubAgent>) => Promise<SubAgent | null>;\n /** DELETE /api/v1/subagents/{subAgentId} — true on success. */\n deleteSubAgent: (subAgentId: string) => Promise<boolean>;\n}\n\n/**\n * Hook for sub-agent CRUD operations\n */\nexport function useSubAgents(options: UseSubAgentsOptions): UseSubAgentsReturn {\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","\"use client\";\n\nimport { useMemo } from \"react\";\nimport type { ApiClientOptions } from \"@elqnt/api-client\";\nimport type { ToolDefinition } from \"../models\";\nimport {\n listToolDefinitionsApi,\n getToolDefinitionApi,\n createToolDefinitionApi,\n updateToolDefinitionApi,\n deleteToolDefinitionApi,\n getToolDefinitionsByIdsApi,\n} from \"../api\";\nimport { useApiAsync } from \"@elqnt/api-client/hooks\";\nimport { useOptionsRef } from \"./use-options-ref\";\n\nexport type UseToolDefinitionsOptions = ApiClientOptions;\n\n/**\n * The exact, stable return surface of `useToolDefinitions` (abstract tool\n * templates agents customize into `AgentTool`s). Imperative, non-throwing —\n * on failure a method resolves to its default (`[]`, `null`, `false`) and sets\n * `error`. See `SKILL.md`.\n */\nexport interface UseToolDefinitionsReturn {\n /** OR of all in-flight method loading flags. */\n loading: boolean;\n /** First non-null method error, else null. */\n error: string | null;\n\n /** GET /api/v1/tool-definitions — default []. */\n listToolDefinitions: () => Promise<ToolDefinition[]>;\n /** GET /api/v1/tool-definitions/{toolDefId} — default null. */\n getToolDefinition: (toolDefId: string) => Promise<ToolDefinition | null>;\n /** POST /api/v1/tool-definitions/by-ids, body { ids } — default []. */\n getToolDefinitionsByIds: (ids: string[]) => Promise<ToolDefinition[]>;\n /** POST /api/v1/tool-definitions, body Partial<ToolDefinition> — created def, or null on error. */\n createToolDefinition: (toolDefinition: Partial<ToolDefinition>) => Promise<ToolDefinition | null>;\n /** PUT /api/v1/tool-definitions/{toolDefId}, body Partial<ToolDefinition> — updated def, or null on error. */\n updateToolDefinition: (\n toolDefId: string,\n toolDefinition: Partial<ToolDefinition>,\n ) => Promise<ToolDefinition | null>;\n /** DELETE /api/v1/tool-definitions/{toolDefId} — true on success. */\n deleteToolDefinition: (toolDefId: string) => Promise<boolean>;\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: UseToolDefinitionsOptions): UseToolDefinitionsReturn {\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","\"use client\";\n\nimport { useMemo } from \"react\";\nimport type { ApiClientOptions } from \"@elqnt/api-client\";\nimport type { AgentJob } from \"../models\";\nimport {\n listAgentJobsApi,\n getAgentJobApi,\n createAgentJobApi,\n updateAgentJobApi,\n deleteAgentJobApi,\n pauseAgentJobApi,\n resumeAgentJobApi,\n} from \"../api\";\nimport { useApiAsync } from \"@elqnt/api-client/hooks\";\nimport { useOptionsRef } from \"./use-options-ref\";\n\nexport type UseAgentJobsOptions = ApiClientOptions;\n\n/**\n * The exact, stable return surface of `useAgentJobs`. Imperative, non-throwing —\n * on failure each method resolves to the documented default and sets `error`.\n */\nexport interface UseAgentJobsReturn {\n /** OR of all in-flight method loading flags. */\n loading: boolean;\n /** First non-null method error, else null. */\n error: string | null;\n\n /** GET /api/v1/agent-jobs — default []. */\n listAgentJobs: () => Promise<AgentJob[]>;\n /** GET /api/v1/agent-jobs/{jobId} — default null. */\n getAgentJob: (jobId: string) => Promise<AgentJob | null>;\n /** POST /api/v1/agent-jobs — created job, or null on error. */\n createAgentJob: (job: Partial<AgentJob>) => Promise<AgentJob | null>;\n /** PUT /api/v1/agent-jobs/{jobId} — updated job, or null on error. */\n updateAgentJob: (jobId: string, job: Partial<AgentJob>) => Promise<AgentJob | null>;\n /** DELETE /api/v1/agent-jobs/{jobId} — true on success. */\n deleteAgentJob: (jobId: string) => Promise<boolean>;\n /** POST /api/v1/agent-jobs/{jobId}/pause — paused job, or null on error. */\n pauseAgentJob: (jobId: string) => Promise<AgentJob | null>;\n /** POST /api/v1/agent-jobs/{jobId}/resume — resumed job, or null on error. */\n resumeAgentJob: (jobId: string) => Promise<AgentJob | null>;\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: UseAgentJobsOptions): UseAgentJobsReturn {\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","\"use client\";\n\nimport { useMemo } from \"react\";\nimport type { ApiClientOptions } from \"@elqnt/api-client\";\nimport type { AgentWidget } from \"../models\";\nimport {\n listWidgetsApi,\n getWidgetApi,\n createWidgetApi,\n updateWidgetApi,\n deleteWidgetApi,\n getDefaultWidgetApi,\n setDefaultWidgetApi,\n} from \"../api\";\nimport { useApiAsync } from \"@elqnt/api-client/hooks\";\nimport { useOptionsRef } from \"./use-options-ref\";\n\nexport interface UseWidgetsOptions extends ApiClientOptions {\n agentId: string;\n}\n\n/**\n * The exact, stable return surface of `useWidgets` (chat-widget CRUD for one\n * agent; the agent is fixed by `options.agentId`). Imperative, non-throwing —\n * on failure a method resolves to its default (`[]`, `null`, `false`) and sets\n * `error`. See `SKILL.md`.\n */\nexport interface UseWidgetsReturn {\n /** OR of all in-flight method loading flags. */\n loading: boolean;\n /** First non-null method error, else null. */\n error: string | null;\n\n /** GET /api/v1/agents/{agentId}/widgets — default []. */\n listWidgets: () => Promise<AgentWidget[]>;\n /** GET /api/v1/widgets/{widgetId} — default null. */\n getWidget: (widgetId: string) => Promise<AgentWidget | null>;\n /** GET /api/v1/agents/{agentId}/widgets/default — default null. */\n getDefaultWidget: () => Promise<AgentWidget | null>;\n /** POST /api/v1/agents/{agentId}/widgets, body { widget } — created widget, or null on error. */\n createWidget: (widget: Partial<AgentWidget>) => Promise<AgentWidget | null>;\n /** PUT /api/v1/widgets/{widgetId}, body { widget } — updated widget, or null on error. */\n updateWidget: (widgetId: string, widget: Partial<AgentWidget>) => Promise<AgentWidget | null>;\n /** DELETE /api/v1/widgets/{widgetId} — true on success. */\n deleteWidget: (widgetId: string) => Promise<boolean>;\n /** POST /api/v1/widgets/{widgetId}/default, body { agentId } — true on success. */\n setDefaultWidget: (widgetId: string) => Promise<boolean>;\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): UseWidgetsReturn {\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","\"use client\";\n\nimport { useMemo } from \"react\";\nimport type { ApiClientOptions } from \"@elqnt/api-client\";\nimport type { SkillUserConfig, ResolveSkillConfigResponse } from \"../models\";\nimport {\n getSkillUserConfigApi,\n updateSkillUserConfigApi,\n deleteSkillUserConfigApi,\n listSkillUserConfigsApi,\n resolveSkillConfigApi,\n} from \"../api\";\nimport { useApiAsync } from \"@elqnt/api-client/hooks\";\nimport { useOptionsRef } from \"./use-options-ref\";\n\nexport type UseSkillUserConfigOptions = ApiClientOptions;\n\n/**\n * The exact, stable return surface of `useSkillUserConfig`. Imperative,\n * non-throwing — on failure each method resolves to the documented default\n * (`null` / `false` / `[]`) and sets `error`.\n */\nexport interface UseSkillUserConfigReturn {\n /** OR of all in-flight method loading flags. */\n loading: boolean;\n /** First non-null method error, else null. */\n error: string | null;\n\n /** GET .../skills/{skillId}/user-config — default null. */\n getSkillUserConfig: (skillId: string, agentId?: string) => Promise<SkillUserConfig | null>;\n /** PUT .../skills/{skillId}/user-config — config or null on error. */\n updateSkillUserConfig: (\n skillId: string,\n data: {\n enabled?: boolean;\n displayOrder?: number;\n config?: Record<string, unknown>;\n agentId?: string;\n },\n ) => Promise<SkillUserConfig | null>;\n /** DELETE .../skills/{skillId}/user-config — true on success. */\n deleteSkillUserConfig: (skillId: string, agentId?: string) => Promise<boolean>;\n /** GET .../skills/user-configs — default []. */\n listSkillUserConfigs: (params?: {\n agentId?: string;\n limit?: number;\n offset?: number;\n }) => Promise<SkillUserConfig[]>;\n /** GET .../skills/{skillId}/resolve — default null. */\n resolveSkillConfig: (\n skillId: string,\n agentId: string,\n ) => Promise<ResolveSkillConfigResponse | null>;\n}\n\n/**\n * Hook for skill user configuration operations\n *\n * @example\n * ```tsx\n * const { loading, error, getSkillUserConfig, updateSkillUserConfig } = useSkillUserConfig({\n * baseUrl: apiGatewayUrl,\n * orgId: selectedOrgId,\n * });\n *\n * const config = await getSkillUserConfig(skillId);\n * await updateSkillUserConfig(skillId, { enabled: true });\n * ```\n */\nexport function useSkillUserConfig(\n options: UseSkillUserConfigOptions,\n): UseSkillUserConfigReturn {\n const optionsRef = useOptionsRef(options);\n\n const { execute: getSkillUserConfig, loading: getLoading, error: getError } = useApiAsync(\n (skillId: string, agentId?: string) =>\n getSkillUserConfigApi(skillId, { ...optionsRef.current, agentId }),\n (data) => data.userConfig || null,\n null as SkillUserConfig | null\n );\n\n const { execute: updateSkillUserConfig, loading: updateLoading, error: updateError } = useApiAsync(\n (\n skillId: string,\n data: { enabled?: boolean; displayOrder?: number; config?: Record<string, unknown>; agentId?: string }\n ) => updateSkillUserConfigApi(skillId, data, optionsRef.current),\n (data) => data.userConfig || null,\n null as SkillUserConfig | null\n );\n\n const { execute: deleteSkillUserConfig, loading: deleteLoading, error: deleteError } = useApiAsync(\n (skillId: string, agentId?: string) =>\n deleteSkillUserConfigApi(skillId, { ...optionsRef.current, agentId }),\n () => true,\n false\n );\n\n const { execute: listSkillUserConfigs, loading: listLoading, error: listError } = useApiAsync(\n (params?: { agentId?: string; limit?: number; offset?: number }) =>\n listSkillUserConfigsApi({ ...optionsRef.current, ...params }),\n (data) => data.userConfigs || [],\n [] as SkillUserConfig[]\n );\n\n const { execute: resolveSkillConfig, loading: resolveLoading, error: resolveError } = useApiAsync(\n (skillId: string, agentId: string) => resolveSkillConfigApi(skillId, agentId, optionsRef.current),\n (data) => data,\n null as ResolveSkillConfigResponse | null\n );\n\n const loading = getLoading || updateLoading || deleteLoading || listLoading || resolveLoading;\n const error = getError || updateError || deleteError || listError || resolveError;\n\n return useMemo(\n () => ({\n loading,\n error,\n getSkillUserConfig,\n updateSkillUserConfig,\n deleteSkillUserConfig,\n listSkillUserConfigs,\n resolveSkillConfig,\n }),\n [loading, error, getSkillUserConfig, updateSkillUserConfig, deleteSkillUserConfig, listSkillUserConfigs, resolveSkillConfig]\n );\n}\n","\"use client\";\n\nimport { useMemo } from \"react\";\nimport type { ApiClientOptions } from \"@elqnt/api-client\";\nimport {\n getAgentChatsAnalyticsApi,\n getAgentCSATAnalyticsApi,\n getAgentListAnalyticsApi,\n getTaskOutcomesApi,\n type DateFilter,\n} from \"../api\";\nimport { useApiAsync } from \"@elqnt/api-client/hooks\";\nimport { useOptionsRef } from \"./use-options-ref\";\n\nexport type UseAnalyticsOptions = ApiClientOptions;\n\n/**\n * The exact, stable return surface of `useAnalytics`. Imperative, non-throwing —\n * on failure each method resolves to `[]` and sets `error`.\n */\nexport interface UseAnalyticsReturn {\n /** OR of all in-flight method loading flags. */\n loading: boolean;\n /** First non-null method error, else null. */\n error: string | null;\n\n /** POST /api/v1/agents/analytics/chats — default []. */\n getAgentChatsAnalytics: (params: {\n date_filter: DateFilter;\n agent_id?: string;\n }) => Promise<unknown[]>;\n /** POST /api/v1/agents/analytics/csat — default []. */\n getAgentCSATAnalytics: (params: {\n date_filter: DateFilter;\n agent_id?: string;\n }) => Promise<unknown[]>;\n /** GET /api/v1/agents/analytics/list — default []. */\n getAgentListAnalytics: () => Promise<unknown[]>;\n /** POST /api/v1/agents/analytics/task-outcomes — default []. */\n getTaskOutcomes: (params: { date_filter: DateFilter }) => Promise<unknown[]>;\n}\n\n/**\n * Hook for agent analytics operations\n *\n * @example\n * ```tsx\n * const { loading, error, getAgentChatsAnalytics, getAgentCSATAnalytics } = useAnalytics({\n * baseUrl: apiGatewayUrl,\n * orgId: selectedOrgId,\n * });\n *\n * const chatsData = await getAgentChatsAnalytics({ from: '2024-01-01', to: '2024-12-31' });\n * ```\n */\nexport function useAnalytics(options: UseAnalyticsOptions): UseAnalyticsReturn {\n const optionsRef = useOptionsRef(options);\n\n const { execute: getAgentChatsAnalytics, loading: chatsLoading, error: chatsError } = useApiAsync(\n (params: { date_filter: DateFilter; agent_id?: string }) =>\n getAgentChatsAnalyticsApi(params, optionsRef.current),\n (data) => data.data,\n [] as unknown[]\n );\n\n const { execute: getAgentCSATAnalytics, loading: csatLoading, error: csatError } = useApiAsync(\n (params: { date_filter: DateFilter; agent_id?: string }) =>\n getAgentCSATAnalyticsApi(params, optionsRef.current),\n (data) => data.data,\n [] as unknown[]\n );\n\n const { execute: getAgentListAnalytics, loading: listLoading, error: listError } = useApiAsync(\n () => getAgentListAnalyticsApi(optionsRef.current),\n (data) => data.data,\n [] as unknown[]\n );\n\n const { execute: getTaskOutcomes, loading: taskLoading, error: taskError } = useApiAsync(\n (params: { date_filter: DateFilter }) => getTaskOutcomesApi(params, optionsRef.current),\n (data) => data.data,\n [] as unknown[]\n );\n\n const loading = chatsLoading || csatLoading || listLoading || taskLoading;\n const error = chatsError || csatError || listError || taskError;\n\n return useMemo(\n () => ({\n loading,\n error,\n getAgentChatsAnalytics,\n getAgentCSATAnalytics,\n getAgentListAnalytics,\n getTaskOutcomes,\n }),\n [loading, error, getAgentChatsAnalytics, getAgentCSATAnalytics, getAgentListAnalytics, getTaskOutcomes]\n );\n}\n","\"use client\";\n\nimport { useMemo } from \"react\";\nimport type { ApiClientOptions } from \"@elqnt/api-client\";\nimport type { UserIntegration, IntegrationProviderTS, IntegrationTypeTS } from \"../models\";\nimport {\n listIntegrationsApi,\n getIntegrationApi,\n connectIntegrationApi,\n disconnectIntegrationApi,\n refreshIntegrationApi,\n updateIntegrationTriageApi,\n runEmailTriageApi,\n} from \"../api\";\nimport { useApiAsync } from \"@elqnt/api-client/hooks\";\nimport { useOptionsRef } from \"./use-options-ref\";\n\nexport type UseIntegrationsOptions = ApiClientOptions;\n\n/**\n * The exact, stable return surface of `useIntegrations`. Imperative,\n * non-throwing — on failure each method resolves to the documented default\n * (`[]` / `null` / `false`) and sets `error`.\n */\nexport interface UseIntegrationsReturn {\n /** OR of all in-flight method loading flags. */\n loading: boolean;\n /** First non-null method error, else null. */\n error: string | null;\n\n /** GET /api/v1/integrations — default []. */\n listIntegrations: () => Promise<UserIntegration[]>;\n /** GET /api/v1/integrations/{provider}/{type} — default null. */\n getIntegration: (\n provider: IntegrationProviderTS,\n integrationType: IntegrationTypeTS,\n ) => Promise<UserIntegration | null>;\n /** POST /api/v1/integrations/connect — { authUrl, state } or null on error. */\n connectIntegration: (params: {\n provider: IntegrationProviderTS;\n integrationType: IntegrationTypeTS;\n redirectUri: string;\n }) => Promise<{ authUrl: string; state: string } | null>;\n /** POST /api/v1/integrations/disconnect — true on success. */\n disconnectIntegration: (params: {\n provider: IntegrationProviderTS;\n integrationType: IntegrationTypeTS;\n }) => Promise<boolean>;\n /** POST /api/v1/integrations/refresh — integration or null on error. */\n refreshIntegration: (params: {\n provider: IntegrationProviderTS;\n integrationType: IntegrationTypeTS;\n }) => Promise<UserIntegration | null>;\n /** POST /api/v1/integrations/triage — integration or null on error. */\n updateTriage: (params: {\n provider: IntegrationProviderTS;\n integrationType: IntegrationTypeTS;\n triageEnabled: boolean;\n }) => Promise<UserIntegration | null>;\n /** POST /api/v1/integrations/triage/run — { success, emailsFound, instancesCreated } or null on error. */\n runEmailTriage: () => Promise<{\n success: boolean;\n emailsFound: number;\n instancesCreated: number;\n } | null>;\n}\n\n/**\n * Hook for user integration operations (OAuth connections)\n *\n * @example\n * ```tsx\n * const { loading, error, listIntegrations, connectIntegration, disconnectIntegration } = useIntegrations({\n * baseUrl: apiGatewayUrl,\n * orgId: selectedOrgId,\n * });\n *\n * const integrations = await listIntegrations();\n * const { auth_url } = await connectIntegration({ provider: 'google', integrationType: 'email', redirectUri: '/callback' });\n * ```\n */\nexport function useIntegrations(options: UseIntegrationsOptions): UseIntegrationsReturn {\n const optionsRef = useOptionsRef(options);\n\n const { execute: listIntegrations, loading: listLoading, error: listError } = useApiAsync(\n () => listIntegrationsApi(optionsRef.current),\n (data) => data.integrations,\n [] as UserIntegration[]\n );\n\n const { execute: getIntegration, loading: getLoading, error: getError } = useApiAsync(\n (provider: IntegrationProviderTS, integrationType: IntegrationTypeTS) =>\n getIntegrationApi(provider, integrationType, optionsRef.current),\n (data) => data.integration || null,\n null as UserIntegration | null\n );\n\n const { execute: connectIntegration, loading: connectLoading, error: connectError } = useApiAsync(\n (params: { provider: IntegrationProviderTS; integrationType: IntegrationTypeTS; redirectUri: string }) =>\n connectIntegrationApi(params, optionsRef.current),\n (data) => ({ authUrl: data.auth_url, state: data.state }),\n null as { authUrl: string; state: string } | null\n );\n\n const { execute: disconnectIntegration, loading: disconnectLoading, error: disconnectError } = useApiAsync(\n (params: { provider: IntegrationProviderTS; integrationType: IntegrationTypeTS }) =>\n disconnectIntegrationApi(params, optionsRef.current),\n () => true,\n false\n );\n\n const { execute: refreshIntegration, loading: refreshLoading, error: refreshError } = useApiAsync(\n (params: { provider: IntegrationProviderTS; integrationType: IntegrationTypeTS }) =>\n refreshIntegrationApi(params, optionsRef.current),\n (data) => data.integration || null,\n null as UserIntegration | null\n );\n\n const { execute: updateTriage, loading: updateTriageLoading, error: updateTriageError } = useApiAsync(\n (params: { provider: IntegrationProviderTS; integrationType: IntegrationTypeTS; triageEnabled: boolean }) =>\n updateIntegrationTriageApi(params, optionsRef.current),\n (data) => data.integration || null,\n null as UserIntegration | null\n );\n\n const { execute: runEmailTriage, loading: runTriageLoading, error: runTriageError } = useApiAsync(\n () => runEmailTriageApi(optionsRef.current),\n (data) => ({ success: data.success, emailsFound: data.emails_found, instancesCreated: data.instances_created }),\n null as { success: boolean; emailsFound: number; instancesCreated: number } | null\n );\n\n const loading = listLoading || getLoading || connectLoading || disconnectLoading || refreshLoading || updateTriageLoading || runTriageLoading;\n const error = listError || getError || connectError || disconnectError || refreshError || updateTriageError || runTriageError;\n\n return useMemo(\n () => ({\n loading,\n error,\n listIntegrations,\n getIntegration,\n connectIntegration,\n disconnectIntegration,\n refreshIntegration,\n updateTriage,\n runEmailTriage,\n }),\n [loading, error, listIntegrations, getIntegration, connectIntegration, disconnectIntegration, refreshIntegration, updateTriage, runEmailTriage]\n );\n}\n","\"use client\";\n\nimport { useMemo } from \"react\";\nimport type { ApiClientOptions } from \"@elqnt/api-client\";\nimport type { Sandbox, CreateSandboxRequest } from \"../models\";\nimport {\n createSandboxApi,\n getSandboxApi,\n updateSandboxApi,\n listSandboxesApi,\n deleteSandboxApi,\n} from \"../api\";\nimport { useApiAsync } from \"@elqnt/api-client/hooks\";\nimport { useOptionsRef } from \"./use-options-ref\";\n\nexport type UseSandboxOptions = ApiClientOptions;\n\n/** Result of a create/update sandbox call (id + url + optional record). */\nexport interface SandboxMutationResult {\n id: string;\n url: string;\n sandbox?: Sandbox;\n}\n\n/**\n * The exact, stable return surface of `useSandbox`. Imperative, non-throwing —\n * on failure each method resolves to the documented default and sets `error`.\n */\nexport interface UseSandboxReturn {\n /** OR of all in-flight method loading flags. */\n loading: boolean;\n /** First non-null method error, else null. */\n error: string | null;\n\n /** POST /api/v1/sandboxes — { id, url, sandbox? } or null on error. */\n createSandbox: (\n request: Omit<CreateSandboxRequest, \"orgId\">,\n ) => Promise<SandboxMutationResult | null>;\n /** GET /api/v1/sandboxes/{sandboxId} — default null. */\n getSandbox: (sandboxId: string) => Promise<Sandbox | null>;\n /** PUT /api/v1/sandboxes/{sandboxId} — { id, url, sandbox? } or null on error. */\n updateSandbox: (\n sandboxId: string,\n request: { prompt: string; title?: string },\n ) => Promise<SandboxMutationResult | null>;\n /** GET /api/v1/sandboxes — { sandboxes, total }; default { sandboxes: [], total: 0 }. */\n listSandboxes: (limit?: number) => Promise<{ sandboxes: Sandbox[]; total: number }>;\n /** DELETE /api/v1/sandboxes/{sandboxId} — true on success. */\n deleteSandbox: (sandboxId: string) => Promise<boolean>;\n}\n\n/**\n * Hook for sandbox operations (AI-generated HTML sandboxes)\n *\n * @example\n * ```tsx\n * const { createSandbox, getSandbox, listSandboxes, loading, error } = useSandbox({\n * baseUrl: apiGatewayUrl,\n * orgId: selectedOrgId,\n * });\n *\n * const result = await createSandbox({ prompt: \"Create a bar chart showing sales data\" });\n * console.log(result.url); // sandbox URL\n * ```\n */\nexport function useSandbox(options: UseSandboxOptions): UseSandboxReturn {\n const optionsRef = useOptionsRef(options);\n\n const { execute: createSandbox, loading: createLoading, error: createError } = useApiAsync(\n (request: Omit<CreateSandboxRequest, \"orgId\">) => createSandboxApi(request, optionsRef.current),\n (data) => ({ id: data.id, url: data.url, sandbox: data.sandbox }),\n null as { id: string; url: string; sandbox?: Sandbox } | null\n );\n\n const { execute: getSandbox, loading: getLoading, error: getError } = useApiAsync(\n (sandboxId: string) => getSandboxApi(sandboxId, optionsRef.current),\n (data) => data.sandbox || null,\n null as Sandbox | null\n );\n\n const { execute: updateSandbox, loading: updateLoading, error: updateError } = useApiAsync(\n (sandboxId: string, request: { prompt: string; title?: string }) =>\n updateSandboxApi(sandboxId, request, optionsRef.current),\n (data) => ({ id: data.id, url: data.url, sandbox: data.sandbox }),\n null as { id: string; url: string; sandbox?: Sandbox } | null\n );\n\n const { execute: listSandboxes, loading: listLoading, error: listError } = useApiAsync(\n (limit?: number) => listSandboxesApi({ ...optionsRef.current, limit }),\n (data) => ({ sandboxes: data.sandboxes, total: data.total }),\n { sandboxes: [] as Sandbox[], total: 0 }\n );\n\n const { execute: deleteSandbox, loading: deleteLoading, error: deleteError } = useApiAsync(\n (sandboxId: string) => deleteSandboxApi(sandboxId, optionsRef.current),\n (data) => data.success,\n false\n );\n\n const loading = createLoading || getLoading || updateLoading || listLoading || deleteLoading;\n const error = createError || getError || updateError || listError || deleteError;\n\n return useMemo(\n () => ({\n loading,\n error,\n createSandbox,\n getSandbox,\n updateSandbox,\n listSandboxes,\n deleteSandbox,\n }),\n [loading, error, createSandbox, getSandbox, updateSandbox, listSandboxes, deleteSandbox]\n );\n}\n","\"use client\";\n\nimport { useMemo } from \"react\";\nimport type { ApiClientOptions } from \"@elqnt/api-client\";\nimport { useApiAsync } from \"@elqnt/api-client/hooks\";\nimport { structuredOutputApi } from \"../api\";\nimport type { StructuredOutputRequest, StructuredOutputResponse } from \"../models\";\nimport { useOptionsRef } from \"./use-options-ref\";\n\nexport type UseStructuredOutputOptions = ApiClientOptions;\n\n/**\n * The exact, stable return surface of `useStructuredOutput`. One-shot,\n * non-throwing — `run` resolves to the structured response, or `null` on\n * failure (with `error` set).\n */\nexport interface UseStructuredOutputReturn<T = unknown> {\n /** POST /api/v1/structured-output — typed response, or null on error. */\n run: (request: StructuredOutputRequest) => Promise<StructuredOutputResponse<T> | null>;\n /** True while a request is in flight. */\n loading: boolean;\n /** Last error message, else null. */\n error: string | null;\n /** Clears the current error. */\n clearError: () => void;\n}\n\n/**\n * Hook for the one-shot structured-output LLM primitive.\n *\n * @example\n * ```tsx\n * const { run, loading, error, data } = useStructuredOutput<{ title: string }>({\n * baseUrl: apiGatewayUrl,\n * orgId: selectedOrgId,\n * });\n *\n * await run({\n * provider: \"anthropic\",\n * model: \"claude-sonnet-4-6\",\n * userPrompt: \"Give me a title for a slide about onboarding.\",\n * schema: { type: \"object\", properties: { title: { type: \"string\" } }, required: [\"title\"] },\n * schemaName: \"slide_title\",\n * maxTokens: 256,\n * });\n * ```\n */\nexport function useStructuredOutput<T = unknown>(\n options: UseStructuredOutputOptions,\n): UseStructuredOutputReturn<T> {\n const optionsRef = useOptionsRef(options);\n\n const { execute: run, loading, error, clearError } = useApiAsync(\n (request: StructuredOutputRequest) => structuredOutputApi<T>(request, optionsRef.current),\n (resp: StructuredOutputResponse<T>) => resp,\n null as StructuredOutputResponse<T> | null\n );\n\n return useMemo(\n () => ({ run, loading, error, clearError }),\n [run, loading, error, clearError]\n );\n}\n","\"use client\";\n\nimport { useMemo } from \"react\";\nimport type { ApiClientOptions } from \"@elqnt/api-client\";\nimport {\n listSchedulerTasksApi,\n createSchedulerTaskApi,\n getSchedulerTaskApi,\n updateSchedulerTaskApi,\n deleteSchedulerTaskApi,\n snoozeSchedulerTaskApi,\n completeSchedulerTaskApi,\n startSchedulerTaskApi,\n type SchedulerTask,\n} from \"../api\";\nimport { useApiAsync } from \"@elqnt/api-client/hooks\";\nimport { useOptionsRef } from \"./use-options-ref\";\n\nexport type UseSchedulerTasksOptions = ApiClientOptions;\n\n/**\n * The exact, stable return surface of `useSchedulerTasks`. Imperative,\n * non-throwing — on failure each method resolves to the documented default\n * (`[]` / `null` / `false`) and sets `error`.\n */\nexport interface UseSchedulerTasksReturn {\n /** OR of all in-flight method loading flags. */\n loading: boolean;\n /** First non-null method error, else null. */\n error: string | null;\n\n /** GET /api/v1/scheduler/tasks — default []. */\n listTasks: (params?: {\n status?: string;\n limit?: number;\n offset?: number;\n }) => Promise<SchedulerTask[]>;\n /** POST /api/v1/scheduler/tasks — created task, or null on error. */\n createTask: (task: Partial<SchedulerTask>) => Promise<SchedulerTask | null>;\n /** GET /api/v1/scheduler/tasks/{taskId} — default null. */\n getTask: (taskId: string) => Promise<SchedulerTask | null>;\n /** PUT /api/v1/scheduler/tasks/{taskId} — updated task, or null on error. */\n updateTask: (taskId: string, task: Partial<SchedulerTask>) => Promise<SchedulerTask | null>;\n /** DELETE /api/v1/scheduler/tasks/{taskId} — true on success. */\n deleteTask: (taskId: string) => Promise<boolean>;\n /** POST /api/v1/scheduler/tasks/{taskId}/snooze — task or null on error. */\n snoozeTask: (\n taskId: string,\n delay: { amount: number; unit: string },\n ) => Promise<SchedulerTask | null>;\n /** POST /api/v1/scheduler/tasks/{taskId}/complete — task or null on error. */\n completeTask: (taskId: string) => Promise<SchedulerTask | null>;\n /** POST /api/v1/scheduler/tasks/{taskId}/start — task or null on error. */\n startTask: (taskId: string) => Promise<SchedulerTask | null>;\n}\n\n/**\n * Hook for scheduler task operations\n *\n * @example\n * ```tsx\n * const { listTasks, createTask, snoozeTask, loading, error } = useSchedulerTasks({\n * baseUrl: apiGatewayUrl,\n * orgId: selectedOrgId,\n * });\n *\n * const tasks = await listTasks();\n * await snoozeTask(taskId, { amount: 30, unit: \"minutes\" });\n * ```\n */\nexport function useSchedulerTasks(options: UseSchedulerTasksOptions): UseSchedulerTasksReturn {\n const optionsRef = useOptionsRef(options);\n\n const { execute: listTasks, loading: listLoading, error: listError } = useApiAsync(\n (params?: { status?: string; limit?: number; offset?: number }) =>\n listSchedulerTasksApi({ ...optionsRef.current, ...params }),\n (data) => data.tasks,\n [] as SchedulerTask[]\n );\n\n const { execute: createTask, loading: createLoading, error: createError } = useApiAsync(\n (task: Partial<SchedulerTask>) => createSchedulerTaskApi(task, optionsRef.current),\n (data) => data.task || null,\n null as SchedulerTask | null\n );\n\n const { execute: getTask, loading: getLoading, error: getError } = useApiAsync(\n (taskId: string) => getSchedulerTaskApi(taskId, optionsRef.current),\n (data) => data.task || null,\n null as SchedulerTask | null\n );\n\n const { execute: updateTask, loading: updateLoading, error: updateError } = useApiAsync(\n (taskId: string, task: Partial<SchedulerTask>) =>\n updateSchedulerTaskApi(taskId, task, optionsRef.current),\n (data) => data.task || null,\n null as SchedulerTask | null\n );\n\n const { execute: deleteTask, loading: deleteLoading, error: deleteError } = useApiAsync(\n (taskId: string) => deleteSchedulerTaskApi(taskId, optionsRef.current),\n (data) => data.success,\n false\n );\n\n const { execute: snoozeTask, loading: snoozeLoading, error: snoozeError } = useApiAsync(\n (taskId: string, delay: { amount: number; unit: string }) =>\n snoozeSchedulerTaskApi(taskId, delay, optionsRef.current),\n (data) => data.task || null,\n null as SchedulerTask | null\n );\n\n const { execute: completeTask, loading: completeLoading, error: completeError } = useApiAsync(\n (taskId: string) => completeSchedulerTaskApi(taskId, optionsRef.current),\n (data) => data.task || null,\n null as SchedulerTask | null\n );\n\n const { execute: startTask, loading: startLoading, error: startError } = useApiAsync(\n (taskId: string) => startSchedulerTaskApi(taskId, optionsRef.current),\n (data) => data.task || null,\n null as SchedulerTask | null\n );\n\n const loading = listLoading || createLoading || getLoading || updateLoading || deleteLoading || snoozeLoading || completeLoading || startLoading;\n const error = listError || createError || getError || updateError || deleteError || snoozeError || completeError || startError;\n\n return useMemo(\n () => ({\n loading,\n error,\n listTasks,\n createTask,\n getTask,\n updateTask,\n deleteTask,\n snoozeTask,\n completeTask,\n startTask,\n }),\n [loading, error, listTasks, createTask, getTask, updateTask, deleteTask, snoozeTask, completeTask, startTask]\n );\n}\n","\"use client\";\n\nimport { useMemo } from \"react\";\nimport type { ApiClientOptions } from \"@elqnt/api-client\";\nimport {\n listSchedulesApi,\n createScheduleApi,\n getScheduleApi,\n updateScheduleApi,\n deleteScheduleApi,\n pauseScheduleApi,\n resumeScheduleApi,\n runScheduleApi,\n type SchedulerSchedule,\n} from \"../api\";\nimport { useApiAsync } from \"@elqnt/api-client/hooks\";\nimport { useOptionsRef } from \"./use-options-ref\";\n\nexport type UseSchedulerSchedulesOptions = ApiClientOptions;\n\n/**\n * The exact, stable return surface of `useSchedulerSchedules`. Imperative,\n * non-throwing — on failure each method resolves to the documented default\n * (`[]` / `null` / `false`) and sets `error`.\n */\nexport interface UseSchedulerSchedulesReturn {\n /** OR of all in-flight method loading flags. */\n loading: boolean;\n /** First non-null method error, else null. */\n error: string | null;\n\n /** GET /api/v1/scheduler/schedules — default []. */\n listSchedules: (params?: {\n status?: string;\n limit?: number;\n offset?: number;\n }) => Promise<SchedulerSchedule[]>;\n /** POST /api/v1/scheduler/schedules — created schedule, or null on error. */\n createSchedule: (schedule: Partial<SchedulerSchedule>) => Promise<SchedulerSchedule | null>;\n /** GET /api/v1/scheduler/schedules/{scheduleId} — default null. */\n getSchedule: (scheduleId: string) => Promise<SchedulerSchedule | null>;\n /** PUT /api/v1/scheduler/schedules/{scheduleId} — updated schedule, or null on error. */\n updateSchedule: (\n scheduleId: string,\n schedule: Partial<SchedulerSchedule>,\n ) => Promise<SchedulerSchedule | null>;\n /** DELETE /api/v1/scheduler/schedules/{scheduleId} — true on success. */\n deleteSchedule: (scheduleId: string) => Promise<boolean>;\n /** POST /api/v1/scheduler/schedules/{scheduleId}/pause — schedule or null on error. */\n pauseSchedule: (scheduleId: string) => Promise<SchedulerSchedule | null>;\n /** POST /api/v1/scheduler/schedules/{scheduleId}/resume — schedule or null on error. */\n resumeSchedule: (scheduleId: string) => Promise<SchedulerSchedule | null>;\n /** POST /api/v1/scheduler/schedules/{scheduleId}/run — schedule or null on error. */\n runSchedule: (scheduleId: string) => Promise<SchedulerSchedule | null>;\n}\n\n/**\n * Hook for scheduler schedule operations (recurring jobs)\n *\n * @example\n * ```tsx\n * const { listSchedules, createSchedule, pauseSchedule, loading, error } = useSchedulerSchedules({\n * baseUrl: apiGatewayUrl,\n * orgId: selectedOrgId,\n * });\n *\n * const schedules = await listSchedules();\n * await pauseSchedule(scheduleId);\n * ```\n */\nexport function useSchedulerSchedules(\n options: UseSchedulerSchedulesOptions,\n): UseSchedulerSchedulesReturn {\n const optionsRef = useOptionsRef(options);\n\n const { execute: listSchedules, loading: listLoading, error: listError } = useApiAsync(\n (params?: { status?: string; limit?: number; offset?: number }) =>\n listSchedulesApi({ ...optionsRef.current, ...params }),\n (data) => data.schedules,\n [] as SchedulerSchedule[]\n );\n\n const { execute: createSchedule, loading: createLoading, error: createError } = useApiAsync(\n (schedule: Partial<SchedulerSchedule>) => createScheduleApi(schedule, optionsRef.current),\n (data) => data.schedule || null,\n null as SchedulerSchedule | null\n );\n\n const { execute: getSchedule, loading: getLoading, error: getError } = useApiAsync(\n (scheduleId: string) => getScheduleApi(scheduleId, optionsRef.current),\n (data) => data.schedule || null,\n null as SchedulerSchedule | null\n );\n\n const { execute: updateSchedule, loading: updateLoading, error: updateError } = useApiAsync(\n (scheduleId: string, schedule: Partial<SchedulerSchedule>) =>\n updateScheduleApi(scheduleId, schedule, optionsRef.current),\n (data) => data.schedule || null,\n null as SchedulerSchedule | null\n );\n\n const { execute: deleteSchedule, loading: deleteLoading, error: deleteError } = useApiAsync(\n (scheduleId: string) => deleteScheduleApi(scheduleId, optionsRef.current),\n (data) => data.success,\n false\n );\n\n const { execute: pauseSchedule, loading: pauseLoading, error: pauseError } = useApiAsync(\n (scheduleId: string) => pauseScheduleApi(scheduleId, optionsRef.current),\n (data) => data.schedule || null,\n null as SchedulerSchedule | null\n );\n\n const { execute: resumeSchedule, loading: resumeLoading, error: resumeError } = useApiAsync(\n (scheduleId: string) => resumeScheduleApi(scheduleId, optionsRef.current),\n (data) => data.schedule || null,\n null as SchedulerSchedule | null\n );\n\n const { execute: runSchedule, loading: runLoading, error: runError } = useApiAsync(\n (scheduleId: string) => runScheduleApi(scheduleId, optionsRef.current),\n (data) => data.schedule || null,\n null as SchedulerSchedule | null\n );\n\n const loading = listLoading || createLoading || getLoading || updateLoading || deleteLoading || pauseLoading || resumeLoading || runLoading;\n const error = listError || createError || getError || updateError || deleteError || pauseError || resumeError || runError;\n\n return useMemo(\n () => ({\n loading,\n error,\n listSchedules,\n createSchedule,\n getSchedule,\n updateSchedule,\n deleteSchedule,\n pauseSchedule,\n resumeSchedule,\n runSchedule,\n }),\n [loading, error, listSchedules, createSchedule, getSchedule, updateSchedule, deleteSchedule, pauseSchedule, resumeSchedule, runSchedule]\n );\n}\n","\"use client\";\n\nimport { useState, useEffect, useRef, useCallback, useMemo } from \"react\";\nimport type { ApiClientOptions } from \"@elqnt/api-client\";\nimport type { AgentSummary, TriggerBackgroundAgentRequest, TriggerBackgroundAgentResponse, BackgroundAgentStatusResponse, AgentStatusUpdate } from \"../models\";\nimport {\n listAgentsSummaryApi,\n triggerBackgroundAgentApi,\n checkBackgroundAgentStatusApi,\n} from \"../api\";\nimport type { ChatMessage, Attachment } from \"@elqnt/chat/models\";\nimport { createBGAgentTransport } from \"../transport/sse\";\nimport type { BGAgentTransport, BackgroundAgentProgressEvent } from \"../transport/types\";\nimport { useApiAsync } from \"@elqnt/api-client/hooks\";\nimport { useOptionsRef } from \"./use-options-ref\";\n\n/** Live state accumulated from SSE events for a single background agent */\nexport interface BGAgentLiveState {\n status: \"running\" | \"completed\" | \"failed\";\n progressLog: string[];\n latestMessage: string;\n result?: string;\n error?: string;\n}\n\n/** Options for useBackgroundAgents hook */\nexport interface UseBackgroundAgentsOptions extends ApiClientOptions {\n /** Chat service URL for SSE streaming (e.g., wss://chat.example.com or https://chat.example.com) */\n chatServiceUrl?: string;\n /** User ID (typically email) for chat operations */\n userId?: string;\n}\n\n/** Background status reported by the agent via report_status tool */\nexport type BackgroundStatus = \"processing\" | \"completed\" | \"failed\";\n\n/** Watched chat state with messages */\nexport interface WatchedChatState {\n chatKey: string;\n messages: ChatMessage[];\n status: \"loading\" | \"active\" | \"completed\" | \"error\";\n /** Background agent status (from report_status tool) */\n backgroundStatus?: BackgroundStatus;\n /** Background agent status message (from report_status tool) */\n backgroundStatusMessage?: string;\n /** History of all status updates for inline display */\n statusHistory: AgentStatusUpdate[];\n title?: string;\n metadata?: Record<string, unknown>;\n error?: string;\n}\n\n/**\n * The exact, stable return surface of `useBackgroundAgents`.\n *\n * This is a **realtime** hook (the allowed shape deviation): it holds SSE\n * connection/stream state (`liveStates`, `watchedChats`) alongside the standard\n * `{ loading, error, ...actions }`. The imperative methods are non-throwing — on\n * failure they resolve to the documented default and set `error` (or log).\n */\nexport interface UseBackgroundAgentsReturn {\n /** Live SSE-accumulated state per streamed jobId. */\n liveStates: Record<string, BGAgentLiveState>;\n /** Open an SSE stream for a job's progress (job runs via the jobs API). */\n streamJob: (jobId: string) => void;\n /** Create a background task via the chat system — returns chatKey, or null on error. */\n createTask: (prompt: string, attachments?: Attachment[]) => Promise<string | null>;\n /** Watch a chat for realtime updates via SSE. */\n watchChat: (chatKey: string) => Promise<void>;\n /** Stop watching a chat and tear down its SSE connection. */\n unwatchChat: (chatKey: string) => void;\n /** Live state per watched chatKey. */\n watchedChats: Record<string, WatchedChatState>;\n /** POST /api/v1/agents/background/trigger — response, or null on error. */\n triggerAgent: (\n request: Pick<\n TriggerBackgroundAgentRequest,\n \"name\" | \"prompt\" | \"agentName\" | \"context\" | \"enableSSE\" | \"description\"\n >,\n ) => Promise<TriggerBackgroundAgentResponse | null>;\n /** GET /api/v1/agents/background/{jobId}/status — response, or null on error. */\n checkStatus: (jobId: string) => Promise<BackgroundAgentStatusResponse | null>;\n /** GET /api/v1/agents/summary — default []. */\n listAgentSummaries: () => Promise<AgentSummary[]>;\n /** OR of the imperative methods' in-flight loading flags. */\n loading: boolean;\n /** First non-null imperative-method error, else null. */\n error: string | null;\n}\n\n/**\n * Hook for triggering background agents, streaming progress via SSE, and checking status.\n *\n * @example\n * ```tsx\n * const { startChat, sendMessage } = useChatContext();\n * const { liveStates, createTask, streamJob, checkStatus } = useBackgroundAgents({\n * baseUrl: apiGatewayUrl,\n * orgId: selectedOrgId,\n * startChat,\n * sendMessage,\n * });\n *\n * // Create a background task (simplified flow using chat)\n * const chatKey = await createTask(\"Analyze the quarterly report\");\n *\n * // Or trigger via jobs API (PostgreSQL-backed)\n * const result = await triggerAgent({ name: \"Analysis\", prompt: \"...\", agentName: \"Research Agent\" });\n * if (result?.jobId) streamJob(result.jobId);\n * ```\n */\nexport function useBackgroundAgents(\n options: UseBackgroundAgentsOptions,\n): UseBackgroundAgentsReturn {\n const optionsRef = useOptionsRef(options);\n const [liveStates, setLiveStates] = useState<Record<string, BGAgentLiveState>>({});\n const [watchedChats, setWatchedChats] = useState<Record<string, WatchedChatState>>({});\n const transportRef = useRef<BGAgentTransport | null>(null);\n const sseRef = useRef<EventSource | null>(null);\n const watchedChatKeyRef = useRef<string | null>(null);\n\n // Initialize transport once\n useEffect(() => {\n const transport = createBGAgentTransport();\n transport.connect({ streamBaseUrl: optionsRef.current.baseUrl });\n transportRef.current = transport;\n return () => {\n transport.disconnect();\n transportRef.current = null;\n };\n }, []);\n\n // Track which jobIds already have handlers registered\n const subscribedJobsRef = useRef<Set<string>>(new Set());\n\n // Stream a job's progress via SSE\n const streamJob = useCallback((jobId: string) => {\n const transport = transportRef.current;\n if (!transport) return;\n\n // Skip if already subscribed (prevents duplicate handlers)\n if (subscribedJobsRef.current.has(jobId)) return;\n subscribedJobsRef.current.add(jobId);\n\n // Initialize live state\n setLiveStates((prev) => ({\n ...prev,\n [jobId]: prev[jobId] || { status: \"running\", progressLog: [], latestMessage: \"Starting...\" },\n }));\n\n // Subscribe to events for this job\n transport.on(\"bg_agent.round\", (event: BackgroundAgentProgressEvent) => {\n if (event.jobId !== jobId || !event.content) return;\n setLiveStates((prev) => {\n const cur = prev[jobId] || { status: \"running\" as const, progressLog: [], latestMessage: \"\" };\n return {\n ...prev,\n [jobId]: { ...cur, status: \"running\", progressLog: [...cur.progressLog, event.content!], latestMessage: event.content! },\n };\n });\n });\n\n transport.on(\"bg_agent.completed\", (event: BackgroundAgentProgressEvent) => {\n if (event.jobId !== jobId) return;\n subscribedJobsRef.current.delete(jobId);\n setLiveStates((prev) => ({\n ...prev,\n [jobId]: { ...(prev[jobId] || { progressLog: [], latestMessage: \"\" }), status: \"completed\", result: event.result, latestMessage: event.result || \"Completed\" },\n }));\n });\n\n transport.on(\"bg_agent.failed\", (event: BackgroundAgentProgressEvent) => {\n if (event.jobId !== jobId) return;\n subscribedJobsRef.current.delete(jobId);\n setLiveStates((prev) => ({\n ...prev,\n [jobId]: { ...(prev[jobId] || { progressLog: [], latestMessage: \"\" }), status: \"failed\", error: event.error, latestMessage: event.error || \"Failed\" },\n }));\n });\n\n // Open the SSE stream\n transport.streamJob(jobId);\n }, []);\n\n // Trigger a background agent\n const { execute: triggerAgent, loading: triggerLoading, error: triggerError } = useApiAsync(\n (request: Pick<TriggerBackgroundAgentRequest, \"name\" | \"prompt\" | \"agentName\" | \"context\" | \"enableSSE\" | \"description\">) =>\n triggerBackgroundAgentApi(request, optionsRef.current),\n (data) => data as TriggerBackgroundAgentResponse,\n null as TriggerBackgroundAgentResponse | null\n );\n\n // Check status\n const { execute: checkStatus, loading: statusLoading, error: statusError } = useApiAsync(\n (jobId: string) => checkBackgroundAgentStatusApi(jobId, optionsRef.current),\n (data) => data as BackgroundAgentStatusResponse,\n null as BackgroundAgentStatusResponse | null\n );\n\n // List agent summaries (for agent picker in \"New\" dialog)\n const { execute: listAgentSummaries, loading: summaryLoading, error: summaryError } = useApiAsync(\n () => listAgentsSummaryApi(optionsRef.current),\n (data) => data.agents || [],\n [] as AgentSummary[]\n );\n\n // Create a background task using the chat system (simplified flow, no PostgreSQL)\n // Calls the chat service directly (not through API Gateway)\n const createTask = useCallback(async (prompt: string, attachments?: Attachment[]): Promise<string | null> => {\n const { chatServiceUrl, orgId, userId } = optionsRef.current;\n if (!chatServiceUrl) {\n console.error(\"chatServiceUrl is required for createTask\");\n return null;\n }\n if (!userId) {\n console.error(\"userId is required for createTask\");\n return null;\n }\n\n try {\n // Create chat with background_agent by name and background flag\n // Direct call to chat service (same pattern as regular chat)\n // Include userId and userEmail in metadata for integration tools (email, calendar, etc.)\n const createResponse = await fetch(`${chatServiceUrl}/create`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n orgId,\n userId,\n metadata: {\n agentName: \"background_agent\",\n background: true,\n userId: userId,\n userEmail: userId,\n originalPrompt: prompt,\n },\n }),\n });\n\n if (!createResponse.ok) {\n const errorText = await createResponse.text();\n console.error(\"Failed to create background chat:\", errorText);\n return null;\n }\n\n const createData = await createResponse.json();\n // Chat service wraps response in { success: true, data: { chatKey: \"...\" } }\n const chatKey = createData.data?.chatKey || createData.chatKey;\n\n if (!chatKey) {\n console.error(\"No chatKey returned from create\");\n return null;\n }\n\n // Send the user's prompt as the first message\n // Direct call to chat service\n const sendResponse = await fetch(`${chatServiceUrl}/send`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n orgId,\n userId,\n chatKey,\n message: {\n role: \"user\",\n content: prompt,\n attachments: attachments || undefined,\n },\n }),\n });\n\n if (!sendResponse.ok) {\n const errorText = await sendResponse.text();\n console.error(\"Failed to send message:\", errorText);\n // Still return chatKey since chat was created\n }\n\n return chatKey;\n } catch (err) {\n console.error(\"Failed to create background task:\", err);\n return null;\n }\n }, []);\n\n // Watch a chat for updates via SSE\n // Calls the chat service directly (not through API Gateway)\n const watchChat = useCallback(async (chatKey: string): Promise<void> => {\n const { chatServiceUrl, orgId, userId } = optionsRef.current;\n\n if (!chatServiceUrl) {\n console.error(\"chatServiceUrl is required for watchChat\");\n return;\n }\n if (!userId) {\n console.error(\"userId is required for watchChat\");\n return;\n }\n\n // Close existing SSE connection if watching a different chat\n if (sseRef.current && watchedChatKeyRef.current !== chatKey) {\n sseRef.current.close();\n sseRef.current = null;\n }\n\n watchedChatKeyRef.current = chatKey;\n\n // Set loading state\n setWatchedChats((prev) => ({\n ...prev,\n [chatKey]: { chatKey, messages: [], status: \"loading\", statusHistory: [] },\n }));\n\n try {\n // Load the chat data directly from chat service (same pattern as regular chat)\n const loadResponse = await fetch(`${chatServiceUrl}/load`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ orgId, chatKey, userId }),\n });\n\n if (!loadResponse.ok) {\n const errorText = await loadResponse.text();\n setWatchedChats((prev) => ({\n ...prev,\n [chatKey]: { chatKey, messages: [], status: \"error\", statusHistory: [], error: errorText || \"Failed to load chat\" },\n }));\n return;\n }\n\n const loadData = await loadResponse.json();\n // Chat service wraps response in { success: true, data: { chat: {...} } }\n const chat = loadData.data?.chat || loadData.chat;\n\n if (!chat) {\n setWatchedChats((prev) => ({\n ...prev,\n [chatKey]: { chatKey, messages: [], status: \"error\", statusHistory: [], error: \"No chat data returned\" },\n }));\n return;\n }\n\n // Extract background status from chat metadata if available\n const bgStatus = chat.metadata?.backgroundStatus as BackgroundStatus | undefined;\n const bgMessage = chat.metadata?.backgroundStatusMessage as string | undefined;\n\n // Determine initial status based on background status\n let initialStatus: WatchedChatState[\"status\"] = \"active\";\n if (bgStatus === \"completed\") initialStatus = \"completed\";\n else if (bgStatus === \"failed\") initialStatus = \"error\";\n\n // Initialize status history (will be populated from SSE events)\n const initialStatusHistory: AgentStatusUpdate[] = [];\n\n setWatchedChats((prev) => ({\n ...prev,\n [chatKey]: {\n chatKey,\n messages: chat.messages || [],\n status: initialStatus,\n title: chat.title,\n metadata: chat.metadata as Record<string, unknown>,\n backgroundStatus: bgStatus,\n backgroundStatusMessage: bgMessage,\n statusHistory: initialStatusHistory,\n },\n }));\n\n // Connect to SSE for real-time updates (direct to chat service)\n const sseUrl = `${chatServiceUrl}/stream?orgId=${orgId}&userId=${userId}&chatId=${chatKey}&clientType=customer`;\n const sse = new EventSource(sseUrl);\n sseRef.current = sse;\n\n // Helper to process SSE event data\n const processEventData = (data: Record<string, unknown>) => {\n console.log(\"[useBackgroundAgents] SSE event received:\", data.type, data);\n // Handle new message events\n if (data.type === \"message\" && data.message) {\n setWatchedChats((prev) => {\n const current = prev[chatKey];\n if (!current) return prev;\n // Avoid duplicate messages\n const msg = data.message as ChatMessage;\n const exists = current.messages.some((m) => m.id === msg.id);\n if (exists) return prev;\n return {\n ...prev,\n [chatKey]: {\n ...current,\n messages: [...current.messages, msg],\n },\n };\n });\n }\n // Handle background status updates from report_status tool\n const eventData = data.data as Record<string, unknown> | undefined;\n if (data.type === \"agent_context_update\" && eventData?.backgroundStatus) {\n const bgStatus = eventData.backgroundStatus as BackgroundStatus;\n const bgMessage = eventData.backgroundStatusMessage as string | undefined;\n const timestamp = Date.now();\n console.log(\"[useBackgroundAgents] Background status update:\", bgStatus, bgMessage);\n setWatchedChats((prev) => {\n const current = prev[chatKey];\n if (!current) return prev;\n // Update background status and auto-set completion status\n const newStatus: WatchedChatState[\"status\"] =\n bgStatus === \"completed\" ? \"completed\" :\n bgStatus === \"failed\" ? \"error\" :\n current.status;\n // Add to status history (avoid duplicates by checking last entry)\n const newHistory = [...current.statusHistory];\n const lastEntry = newHistory[newHistory.length - 1];\n if (!lastEntry || lastEntry.message !== bgMessage || lastEntry.status !== bgStatus) {\n newHistory.push({\n status: bgStatus,\n message: bgMessage || \"\",\n timestamp,\n });\n }\n return {\n ...prev,\n [chatKey]: {\n ...current,\n status: newStatus,\n backgroundStatus: bgStatus,\n backgroundStatusMessage: bgMessage,\n statusHistory: newHistory,\n },\n };\n });\n }\n // Handle explicit chat completion (fallback)\n if (data.type === \"chat_ended\" || data.type === \"agent_done\") {\n setWatchedChats((prev) => ({\n ...prev,\n [chatKey]: { ...prev[chatKey], status: \"completed\" },\n }));\n }\n };\n\n // Default message handler (for events without custom event type)\n sse.onmessage = (event) => {\n try {\n const data = JSON.parse(event.data);\n processEventData(data);\n } catch (err) {\n console.error(\"Failed to parse SSE event:\", err);\n }\n };\n\n // Handler for custom event types (backend sends events with `event: agent_context_update`)\n // Note: EventSource requires separate listeners for custom event types\n const customEventTypes = [\"agent_context_update\", \"message\", \"chat_ended\", \"agent_done\"];\n for (const eventType of customEventTypes) {\n sse.addEventListener(eventType, (event) => {\n try {\n const data = JSON.parse((event as MessageEvent).data);\n processEventData(data);\n } catch (err) {\n console.error(`Failed to parse SSE ${eventType} event:`, err);\n }\n });\n }\n\n sse.onerror = () => {\n // SSE will auto-reconnect, but log the error\n console.warn(\"SSE connection error for chat:\", chatKey);\n };\n } catch (err) {\n console.error(\"Failed to watch chat:\", err);\n setWatchedChats((prev) => ({\n ...prev,\n [chatKey]: { chatKey, messages: [], status: \"error\", statusHistory: [], error: String(err) },\n }));\n }\n }, []);\n\n // Stop watching a chat\n const unwatchChat = useCallback((chatKey: string) => {\n if (watchedChatKeyRef.current === chatKey && sseRef.current) {\n sseRef.current.close();\n sseRef.current = null;\n watchedChatKeyRef.current = null;\n }\n setWatchedChats((prev) => {\n const next = { ...prev };\n delete next[chatKey];\n return next;\n });\n }, []);\n\n // Cleanup SSE on unmount\n useEffect(() => {\n return () => {\n if (sseRef.current) {\n sseRef.current.close();\n sseRef.current = null;\n }\n };\n }, []);\n\n const loading = triggerLoading || statusLoading || summaryLoading;\n const error = triggerError || statusError || summaryError;\n\n return useMemo(() => ({\n liveStates,\n streamJob,\n createTask,\n watchChat,\n unwatchChat,\n watchedChats,\n triggerAgent,\n checkStatus,\n listAgentSummaries,\n loading,\n error,\n }), [liveStates, streamJob, createTask, watchChat, unwatchChat, watchedChats, triggerAgent, checkStatus, listAgentSummaries, loading, error]);\n}\n"]}