@burdenoff/microfe-botmanor 2026.1115.2 → 2026.1117.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 (53) hide show
  1. package/dist/botlit/components/BotFormFields.js +66 -87
  2. package/dist/botlit/components/BotFormFields.js.map +1 -1
  3. package/dist/botlit/components/EmojiPicker.d.ts +20 -0
  4. package/dist/botlit/components/EmojiPicker.js +42 -0
  5. package/dist/botlit/components/EmojiPicker.js.map +1 -0
  6. package/dist/botlit/components/index.d.ts +1 -0
  7. package/dist/botlit/hooks/internal/allPages.d.ts +2 -0
  8. package/dist/botlit/hooks/internal/allPages.js +25 -0
  9. package/dist/botlit/hooks/internal/allPages.js.map +1 -0
  10. package/dist/botlit/hooks/internal/workspaceGateway.js +33 -32
  11. package/dist/botlit/hooks/internal/workspaceGateway.js.map +1 -1
  12. package/dist/botlit/hooks/useAgents.d.ts +26 -3
  13. package/dist/botlit/hooks/useAgents.js +160 -110
  14. package/dist/botlit/hooks/useAgents.js.map +1 -1
  15. package/dist/botlit/hooks/useBotAgents.d.ts +35 -0
  16. package/dist/botlit/hooks/useBotAgents.js +95 -0
  17. package/dist/botlit/hooks/useBotAgents.js.map +1 -0
  18. package/dist/botlit/hooks/useBots.js +2 -2
  19. package/dist/botlit/hooks/useBots.js.map +1 -1
  20. package/dist/botlit/hooks/useKnowledgeBases.d.ts +13 -0
  21. package/dist/botlit/hooks/useKnowledgeBases.js +77 -58
  22. package/dist/botlit/hooks/useKnowledgeBases.js.map +1 -1
  23. package/dist/botlit/hooks/useMCPServers.js +53 -57
  24. package/dist/botlit/hooks/useMCPServers.js.map +1 -1
  25. package/dist/botlit/pages/AgentBuilderPage.js +848 -425
  26. package/dist/botlit/pages/AgentBuilderPage.js.map +1 -1
  27. package/dist/botlit/pages/AgentDetailPage.js +629 -518
  28. package/dist/botlit/pages/AgentDetailPage.js.map +1 -1
  29. package/dist/botlit/pages/AgentsListPage.js +487 -291
  30. package/dist/botlit/pages/AgentsListPage.js.map +1 -1
  31. package/dist/botlit/pages/KnowledgeBaseDetailPage.js +519 -265
  32. package/dist/botlit/pages/KnowledgeBaseDetailPage.js.map +1 -1
  33. package/dist/botlit/pages/KnowledgeBasesPage.js +269 -130
  34. package/dist/botlit/pages/KnowledgeBasesPage.js.map +1 -1
  35. package/dist/botlit/types/index.d.ts +4 -1
  36. package/dist/botlit/utils/agentDelete.d.ts +5 -0
  37. package/dist/botlit/utils/agentDelete.js +15 -0
  38. package/dist/botlit/utils/agentDelete.js.map +1 -0
  39. package/dist/botlit/utils/agentSettings.d.ts +77 -0
  40. package/dist/botlit/utils/agentSettings.js +78 -0
  41. package/dist/botlit/utils/agentSettings.js.map +1 -0
  42. package/dist/botlit/utils/kbDelete.d.ts +5 -0
  43. package/dist/botlit/utils/kbDelete.js +11 -0
  44. package/dist/botlit/utils/kbDelete.js.map +1 -0
  45. package/dist/botlit/utils/kbSettings.d.ts +41 -0
  46. package/dist/botlit/utils/kbSettings.js +60 -0
  47. package/dist/botlit/utils/kbSettings.js.map +1 -0
  48. package/dist/generated/wspace-operations.d.ts +75 -0
  49. package/dist/generated/wspace-operations.js +60 -48
  50. package/dist/generated/wspace-operations.js.map +1 -1
  51. package/dist/generated/wspace-types.d.ts +66 -0
  52. package/dist/generated/wspace-types.js.map +1 -1
  53. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"workspaceGateway.js","names":["useWorkspaceClient","useGatewayClient","useWorkspaceId","useBotlit","toError","message","extractGraphqlFailureMessage","cause","fallbackMessage","useLatest","ref","useRef","value","useLayoutEffect","useWorkspaceQuery","options","client","selectRef","fallbackRef","data","setData","useState","loading","setLoading","error","setError","refetch","useCallback","enabled","result","document","operationError","errorMessage","queryError","variables","useEffect","useWorkspacePaginatedQuery","extractRowsRef","rows","setRows","rowsRef","loadingMore","setLoadingMore","exhausted","setExhausted","replaceRows","next","fetchPage","append","pageSize","pageRows","loadMore","useWorkspaceMutation","variablesRef","state","setState","input","selected","mutationError","failure"],"sources":["../../../../src/botlit/hooks/internal/workspaceGateway.ts"],"sourcesContent":["/**\n * Workspace gateway hook primitives\n * @module botlit/hooks/internal\n *\n * Every BotManor hook talks to the workspace public gateway through the Apollo\n * client the shell installs (`useGatewayClient('workspace')`) — never through a\n * client of its own. These primitives capture the exact shape used by the\n * reference hooks (`useAgents`, `useBots`): `network-only` reads, an explicit\n * `Error` in state rather than a thrown promise, and a `refetch` the caller can\n * run after a mutation.\n */\n\nimport type { ApolloClient, DocumentNode } from '@apollo/client';\nimport { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';\nimport { useGatewayClient } from '@burdenoff/fe-libs/shared/graphql';\n\nimport { useBotlit } from '../../providers/BotlitProvider';\nimport { extractGraphqlFailureMessage } from '../../utils/errors';\n\nexport type WorkspaceClient = ApolloClient;\n\n/** Apollo client for the workspace gateway, provided by the host shell. */\nexport function useWorkspaceClient(): WorkspaceClient {\n return useGatewayClient('workspace');\n}\n\n/** Current workspace id from the BotManor context (undefined until the shell resolves it). */\nexport function useWorkspaceId(): string | undefined {\n return useBotlit().workspaceId;\n}\n\nexport interface QueryResult<T> {\n data: T;\n loading: boolean;\n /** Set only when the request FAILED. An empty `data` with no `error` means \"no records yet\". */\n error: Error | undefined;\n refetch: () => Promise<void>;\n}\n\nexport interface PaginatedQueryResult<T> extends QueryResult<T> {\n /** True while the next page is being appended. */\n loadingMore: boolean;\n /**\n * True when the most recent page came back full, i.e. another page may\n * exist. False before the first page resolves and once a short page\n * (or an empty one) marks the end of the list.\n */\n hasMore: boolean;\n /**\n * Fetches the next page (current row count as offset) and appends it.\n * No-op while a fetch is in flight or when `hasMore` is false.\n */\n loadMore: () => Promise<void>;\n}\n\nexport interface MutationState<T> {\n data: T | undefined;\n loading: boolean;\n error: Error | undefined;\n}\n\n/**\n * Normalises any mutation failure to an Error with the server's\n * user-actionable message where one exists.\n *\n * Apollo Client v4 does not reject with a plain Error: failures arrive as\n * `{ networkError }` / `{ graphQLErrors }` objects, and the batched fetch\n * layer attaches the structured GraphQL errors as `.errors` on the\n * networkError. `extractGraphqlFailureMessage` unwraps all of those; only\n * when nothing user-actionable is present do we fall back to the hook's\n * generic `errorMessage`.\n */\nfunction toError(cause: unknown, fallbackMessage: string): Error {\n const message = extractGraphqlFailureMessage(cause);\n if (message) {\n // Preserve the original rejection on the chain so error monitoring can\n // still reach the structured GraphQL errors (extensions.code, requestId…).\n return new Error(message, { cause });\n }\n if (cause instanceof Error) return cause;\n return new Error(fallbackMessage, { cause });\n}\n\n/** Keeps a mutable ref pointing at the latest value without re-running effects. */\nfunction useLatest<T>(value: T): { readonly current: T } {\n const ref = useRef(value);\n useLayoutEffect(() => {\n ref.current = value;\n }, [value]);\n return ref;\n}\n\nexport interface WorkspaceQueryOptions<TData, TResult> {\n /** Generated GraphQL document (see `src/generated/wspace-operations.ts`). */\n document: DocumentNode;\n /** Must be referentially stable — memoize at the call site. */\n variables: Record<string, unknown> | undefined;\n /** Projects the raw payload onto the record shape the UI consumes. */\n select: (data: TData | undefined) => TResult;\n /** Value held while disabled or before the first successful read. */\n fallback: TResult;\n /** When false the request is skipped (e.g. no workspace id / no entity id yet). */\n enabled: boolean;\n /** Used when the thrown value is not an Error. */\n errorMessage: string;\n}\n\n/**\n * Reads from the workspace gateway and keeps `{ data, loading, error, refetch }`\n * in sync. `error` is reserved for real failures so callers can tell an empty\n * collection apart from a failed request.\n */\nexport function useWorkspaceQuery<TData, TResult>(\n options: WorkspaceQueryOptions<TData, TResult>\n): QueryResult<TResult> {\n const { document, variables, enabled, errorMessage } = options;\n const client = useWorkspaceClient();\n const selectRef = useLatest(options.select);\n const fallbackRef = useLatest(options.fallback);\n\n const [data, setData] = useState<TResult>(options.fallback);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n\n const refetch = useCallback(async () => {\n if (!enabled) {\n setData(fallbackRef.current);\n setError(undefined);\n return;\n }\n\n setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<TData>({\n query: document,\n variables,\n fetchPolicy: 'network-only',\n });\n // Apollo v4 resolves (not rejects) with `result.error` set on GraphQL\n // errors — same handling as useWorkspaceMutation.\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw toError(operationError, errorMessage);\n }\n setData(selectRef.current(result.data ?? undefined));\n } catch (queryError) {\n setData(fallbackRef.current);\n setError(toError(queryError, errorMessage));\n } finally {\n setLoading(false);\n }\n // fallbackRef/selectRef are stable refs by construction\n }, [client, document, variables, enabled, errorMessage, fallbackRef, selectRef]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\nexport interface WorkspacePaginatedQueryOptions<TData, TRow, TResult> {\n /** Generated GraphQL document (see `src/generated/wspace-operations.ts`). */\n document: DocumentNode;\n /**\n * Base variables (filters, ids, …) WITHOUT `pagination` — the hook adds\n * `{ limit: pageSize, offset }` per fetch. Must be referentially stable;\n * a new identity resets the accumulation back to page one.\n */\n variables: Record<string, unknown> | undefined;\n /** Page size for each fetch. */\n pageSize: number;\n /** Extracts the raw row list from a page payload; missing data yields []. */\n extractRows: (data: TData | undefined) => TRow[] | undefined;\n /** Projects the ACCUMULATED raw rows onto the record shape the UI consumes. */\n select: (rows: TRow[]) => TResult;\n /** Value held while disabled or before the first successful read. */\n fallback: TResult;\n /** When false the request is skipped (e.g. no workspace id yet). */\n enabled: boolean;\n /** Used when the thrown value is not an Error. */\n errorMessage: string;\n}\n\n/**\n * Offset-paginated variant of `useWorkspaceQuery` for unbounded lists.\n *\n * `refetch()` restarts at offset 0 and REPLACES the accumulated rows;\n * `loadMore()` fetches the next page and appends it. A page that returns\n * fewer rows than `pageSize` marks the list exhausted (`hasMore` false).\n * `select` runs over the accumulated raw rows, so client-side narrowing\n * (e.g. executions search) sees every loaded page, not just the last one.\n */\nexport function useWorkspacePaginatedQuery<TData, TRow, TResult>(\n options: WorkspacePaginatedQueryOptions<TData, TRow, TResult>\n): PaginatedQueryResult<TResult> {\n const { document, variables, pageSize, enabled, errorMessage } = options;\n const client = useWorkspaceClient();\n const selectRef = useLatest(options.select);\n const extractRowsRef = useLatest(options.extractRows);\n\n const [rows, setRows] = useState<TRow[]>([]);\n const rowsRef = useRef<TRow[]>([]);\n const [data, setData] = useState<TResult>(options.fallback);\n const [loading, setLoading] = useState(false);\n const [loadingMore, setLoadingMore] = useState(false);\n const [exhausted, setExhausted] = useState(true);\n const [error, setError] = useState<Error | undefined>();\n\n const replaceRows = useCallback(\n (next: TRow[]) => {\n rowsRef.current = next;\n setRows(next);\n setData(selectRef.current(next));\n },\n [selectRef]\n );\n\n const fetchPage = useCallback(\n async (offset: number, append: boolean) => {\n if (append) setLoadingMore(true);\n else setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<TData>({\n query: document,\n variables: { ...variables, pagination: { limit: pageSize, offset } },\n fetchPolicy: 'network-only',\n });\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw toError(operationError, errorMessage);\n }\n const pageRows = extractRowsRef.current(result.data ?? undefined) ?? [];\n replaceRows(append ? [...rowsRef.current, ...pageRows] : pageRows);\n setExhausted(pageRows.length < pageSize);\n } catch (queryError) {\n setError(toError(queryError, errorMessage));\n } finally {\n if (append) setLoadingMore(false);\n else setLoading(false);\n }\n },\n [client, document, variables, pageSize, errorMessage, extractRowsRef, replaceRows]\n );\n\n const refetch = useCallback(async () => {\n if (!enabled) {\n replaceRows([]);\n setExhausted(true);\n setError(undefined);\n return;\n }\n await fetchPage(0, false);\n }, [enabled, fetchPage, replaceRows]);\n\n const loadMore = useCallback(async () => {\n if (!enabled || exhausted) return;\n await fetchPage(rowsRef.current.length, true);\n }, [enabled, exhausted, fetchPage]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, loadingMore, hasMore: !exhausted, error, refetch, loadMore };\n}\n\nexport interface WorkspaceMutationOptions<TData, TInput, TResult> {\n /** Generated GraphQL document (see `src/generated/wspace-operations.ts`). */\n document: DocumentNode;\n /** Maps the caller's input onto GraphQL variables. */\n variables: (input: TInput) => Record<string, unknown>;\n /** Projects the raw payload onto the record shape the UI consumes. */\n select: (data: TData | undefined) => TResult | undefined;\n /** Thrown (and stored) when the payload is missing or the request fails. */\n errorMessage: string;\n}\n\n/**\n * Writes to the workspace gateway. Returns the `[mutate, state]` tuple used by\n * the reference hooks. `mutate` REJECTS on failure so callers cannot mistake a\n * failed write for a successful one.\n */\nexport function useWorkspaceMutation<TData, TInput, TResult>(\n options: WorkspaceMutationOptions<TData, TInput, TResult>\n): readonly [(input: TInput) => Promise<TResult>, MutationState<TResult>] {\n const { document, errorMessage } = options;\n const client = useWorkspaceClient();\n const variablesRef = useLatest(options.variables);\n const selectRef = useLatest(options.select);\n\n const [state, setState] = useState<MutationState<TResult>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const mutate = useCallback(\n async (input: TInput): Promise<TResult> => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<TData>({\n mutation: document,\n variables: variablesRef.current(input),\n });\n // Apollo v4 does not reject on GraphQL errors by default: the mutation\n // RESOLVES with `data` undefined and the failure on `result.error`\n // (CombinedGraphQLErrors / networkError). Surface it like a rejection\n // so callers see the server's field-level message, not the fallback.\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw toError(operationError, errorMessage);\n }\n const selected = selectRef.current(result.data ?? undefined);\n if (selected === undefined) {\n throw new Error(errorMessage);\n }\n setState({ data: selected, loading: false, error: undefined });\n return selected;\n } catch (mutationError) {\n const failure = toError(mutationError, errorMessage);\n setState({ data: undefined, loading: false, error: failure });\n throw failure;\n }\n },\n [client, document, errorMessage, selectRef, variablesRef]\n );\n\n return [mutate, state] as const;\n}\n"],"mappings":";;;;;AAsBA,SAAgBA,IAAsC;CACpD,OAAOC,EAAiB,WAAW;AACrC;AAGA,SAAgBC,IAAqC;CACnD,OAAOC,EAAU,CAAC,CAAC;AACrB;AA2CA,SAASC,EAAQ,GAAgB,GAAgC;CAC/D,I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C,IAAMyB,IAAWxC,EAAU,QAAQY,EAAO,QAAQ,KAAA,CAAS;GAC3D,IAAI4B,MAAa,KAAA,GACf,MAAU,MAAMzB,CAAY;GAG9B,OADAuB,EAAS;IAAE,MAAME;IAAU,SAAS;IAAO,OAAO,KAAA;GAAU,CAAC,GACtDA;EACT,SAASC,GAAe;GACtB,IAAMC,IAAUvD,EAAQsD,GAAe1B,CAAY;GAEnD,MADAuB,EAAS;IAAE,MAAM,KAAA;IAAW,SAAS;IAAO,OAAOI;GAAQ,CAAC,GACtDA;EACR;CACF,GACA;EAAC3C;EAAQc;EAAUE;EAAcf;EAAWoC;CAAY,CAGlD,GAAQC,CAAK;AACvB"}
1
+ {"version":3,"file":"workspaceGateway.js","names":["useWorkspaceClient","useGatewayClient","useWorkspaceId","useBotlit","toError","message","extractGraphqlFailureMessage","cause","fallbackMessage","useLatest","ref","useRef","value","useLayoutEffect","useWorkspaceQuery","options","client","selectRef","fallbackRef","data","setData","useState","loading","setLoading","error","setError","refetch","useCallback","enabled","result","document","operationError","errorMessage","queryError","variables","useEffect","NO_ROWS","useWorkspacePaginatedQuery","extractRowsRef","rows","setRows","rowsRef","loadingMore","setLoadingMore","exhausted","setExhausted","replaceRows","next","fetchPage","append","pageSize","pageRows","loadMore","useWorkspaceMutation","variablesRef","state","setState","input","selected","mutationError","failure"],"sources":["../../../../src/botlit/hooks/internal/workspaceGateway.ts"],"sourcesContent":["/**\n * Workspace gateway hook primitives\n * @module botlit/hooks/internal\n *\n * Every BotManor hook talks to the workspace public gateway through the Apollo\n * client the shell installs (`useGatewayClient('workspace')`) — never through a\n * client of its own. These primitives capture the exact shape used by the\n * reference hooks (`useAgents`, `useBots`): `network-only` reads, an explicit\n * `Error` in state rather than a thrown promise, and a `refetch` the caller can\n * run after a mutation.\n */\n\nimport type { ApolloClient, DocumentNode } from '@apollo/client';\nimport { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';\nimport { useGatewayClient } from '@burdenoff/fe-libs/shared/graphql';\n\nimport { useBotlit } from '../../providers/BotlitProvider';\nimport { extractGraphqlFailureMessage } from '../../utils/errors';\n\nexport type WorkspaceClient = ApolloClient;\n\n/** Apollo client for the workspace gateway, provided by the host shell. */\nexport function useWorkspaceClient(): WorkspaceClient {\n return useGatewayClient('workspace');\n}\n\n/** Current workspace id from the BotManor context (undefined until the shell resolves it). */\nexport function useWorkspaceId(): string | undefined {\n return useBotlit().workspaceId;\n}\n\nexport interface QueryResult<T> {\n data: T;\n loading: boolean;\n /** Set only when the request FAILED. An empty `data` with no `error` means \"no records yet\". */\n error: Error | undefined;\n refetch: () => Promise<void>;\n}\n\nexport interface PaginatedQueryResult<T> extends QueryResult<T> {\n /** True while the next page is being appended. */\n loadingMore: boolean;\n /**\n * True when the most recent page came back full, i.e. another page may\n * exist. False before the first page resolves and once a short page\n * (or an empty one) marks the end of the list.\n */\n hasMore: boolean;\n /**\n * Fetches the next page (current row count as offset) and appends it.\n * No-op while a fetch is in flight or when `hasMore` is false.\n */\n loadMore: () => Promise<void>;\n}\n\nexport interface MutationState<T> {\n data: T | undefined;\n loading: boolean;\n error: Error | undefined;\n}\n\n/**\n * Normalises any mutation failure to an Error with the server's\n * user-actionable message where one exists.\n *\n * Apollo Client v4 does not reject with a plain Error: failures arrive as\n * `{ networkError }` / `{ graphQLErrors }` objects, and the batched fetch\n * layer attaches the structured GraphQL errors as `.errors` on the\n * networkError. `extractGraphqlFailureMessage` unwraps all of those; only\n * when nothing user-actionable is present do we fall back to the hook's\n * generic `errorMessage`.\n */\nfunction toError(cause: unknown, fallbackMessage: string): Error {\n const message = extractGraphqlFailureMessage(cause);\n if (message) {\n // Preserve the original rejection on the chain so error monitoring can\n // still reach the structured GraphQL errors (extensions.code, requestId…).\n return new Error(message, { cause });\n }\n if (cause instanceof Error) return cause;\n return new Error(fallbackMessage, { cause });\n}\n\n/** Keeps a mutable ref pointing at the latest value without re-running effects. */\nfunction useLatest<T>(value: T): { readonly current: T } {\n const ref = useRef(value);\n useLayoutEffect(() => {\n ref.current = value;\n }, [value]);\n return ref;\n}\n\nexport interface WorkspaceQueryOptions<TData, TResult> {\n /** Generated GraphQL document (see `src/generated/wspace-operations.ts`). */\n document: DocumentNode;\n /** Must be referentially stable — memoize at the call site. */\n variables: Record<string, unknown> | undefined;\n /** Projects the raw payload onto the record shape the UI consumes. */\n select: (data: TData | undefined) => TResult;\n /** Value held while disabled or before the first successful read. */\n fallback: TResult;\n /** When false the request is skipped (e.g. no workspace id / no entity id yet). */\n enabled: boolean;\n /** Used when the thrown value is not an Error. */\n errorMessage: string;\n}\n\n/**\n * Reads from the workspace gateway and keeps `{ data, loading, error, refetch }`\n * in sync. `error` is reserved for real failures so callers can tell an empty\n * collection apart from a failed request.\n */\nexport function useWorkspaceQuery<TData, TResult>(\n options: WorkspaceQueryOptions<TData, TResult>\n): QueryResult<TResult> {\n const { document, variables, enabled, errorMessage } = options;\n const client = useWorkspaceClient();\n const selectRef = useLatest(options.select);\n const fallbackRef = useLatest(options.fallback);\n\n const [data, setData] = useState<TResult>(options.fallback);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n\n const refetch = useCallback(async () => {\n if (!enabled) {\n setData(fallbackRef.current);\n setError(undefined);\n return;\n }\n\n setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<TData>({\n query: document,\n variables,\n fetchPolicy: 'network-only',\n });\n // Apollo v4 resolves (not rejects) with `result.error` set on GraphQL\n // errors — same handling as useWorkspaceMutation.\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw toError(operationError, errorMessage);\n }\n setData(selectRef.current(result.data ?? undefined));\n } catch (queryError) {\n setData(fallbackRef.current);\n setError(toError(queryError, errorMessage));\n } finally {\n setLoading(false);\n }\n // fallbackRef/selectRef are stable refs by construction\n }, [client, document, variables, enabled, errorMessage, fallbackRef, selectRef]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\n/** Shared empty page, so a disabled paginated query keeps one stable value. */\nconst NO_ROWS: never[] = [];\n\nexport interface WorkspacePaginatedQueryOptions<TData, TRow, TResult> {\n /** Generated GraphQL document (see `src/generated/wspace-operations.ts`). */\n document: DocumentNode;\n /**\n * Base variables (filters, ids, …) WITHOUT `pagination` — the hook adds\n * `{ limit: pageSize, offset }` per fetch. Must be referentially stable;\n * a new identity resets the accumulation back to page one.\n */\n variables: Record<string, unknown> | undefined;\n /** Page size for each fetch. */\n pageSize: number;\n /** Extracts the raw row list from a page payload; missing data yields []. */\n extractRows: (data: TData | undefined) => TRow[] | undefined;\n /** Projects the ACCUMULATED raw rows onto the record shape the UI consumes. */\n select: (rows: TRow[]) => TResult;\n /** Value held while disabled or before the first successful read. */\n fallback: TResult;\n /** When false the request is skipped (e.g. no workspace id yet). */\n enabled: boolean;\n /** Used when the thrown value is not an Error. */\n errorMessage: string;\n}\n\n/**\n * Offset-paginated variant of `useWorkspaceQuery` for unbounded lists.\n *\n * `refetch()` restarts at offset 0 and REPLACES the accumulated rows;\n * `loadMore()` fetches the next page and appends it. A page that returns\n * fewer rows than `pageSize` marks the list exhausted (`hasMore` false).\n * `select` runs over the accumulated raw rows, so client-side narrowing\n * (e.g. executions search) sees every loaded page, not just the last one.\n */\nexport function useWorkspacePaginatedQuery<TData, TRow, TResult>(\n options: WorkspacePaginatedQueryOptions<TData, TRow, TResult>\n): PaginatedQueryResult<TResult> {\n const { document, variables, pageSize, enabled, errorMessage } = options;\n const client = useWorkspaceClient();\n const selectRef = useLatest(options.select);\n const extractRowsRef = useLatest(options.extractRows);\n\n const [rows, setRows] = useState<TRow[]>([]);\n const rowsRef = useRef<TRow[]>([]);\n const [data, setData] = useState<TResult>(options.fallback);\n const [loading, setLoading] = useState(false);\n const [loadingMore, setLoadingMore] = useState(false);\n const [exhausted, setExhausted] = useState(true);\n const [error, setError] = useState<Error | undefined>();\n\n const replaceRows = useCallback(\n (next: TRow[]) => {\n rowsRef.current = next;\n setRows(next);\n setData(selectRef.current(next));\n },\n [selectRef]\n );\n\n const fetchPage = useCallback(\n async (offset: number, append: boolean) => {\n if (append) setLoadingMore(true);\n else setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<TData>({\n query: document,\n variables: { ...variables, pagination: { limit: pageSize, offset } },\n fetchPolicy: 'network-only',\n });\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw toError(operationError, errorMessage);\n }\n const pageRows = extractRowsRef.current(result.data ?? undefined) ?? [];\n replaceRows(append ? [...rowsRef.current, ...pageRows] : pageRows);\n setExhausted(pageRows.length < pageSize);\n } catch (queryError) {\n setError(toError(queryError, errorMessage));\n } finally {\n if (append) setLoadingMore(false);\n else setLoading(false);\n }\n },\n [client, document, variables, pageSize, errorMessage, extractRowsRef, replaceRows]\n );\n\n const refetch = useCallback(async () => {\n if (!enabled) {\n // The same empty list every time: a disabled query must not change state, or a\n // caller whose client identity changes per render would refetch forever.\n replaceRows(NO_ROWS);\n setExhausted(true);\n setError(undefined);\n return;\n }\n await fetchPage(0, false);\n }, [enabled, fetchPage, replaceRows]);\n\n const loadMore = useCallback(async () => {\n if (!enabled || exhausted) return;\n await fetchPage(rowsRef.current.length, true);\n }, [enabled, exhausted, fetchPage]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, loadingMore, hasMore: !exhausted, error, refetch, loadMore };\n}\n\nexport interface WorkspaceMutationOptions<TData, TInput, TResult> {\n /** Generated GraphQL document (see `src/generated/wspace-operations.ts`). */\n document: DocumentNode;\n /** Maps the caller's input onto GraphQL variables. */\n variables: (input: TInput) => Record<string, unknown>;\n /** Projects the raw payload onto the record shape the UI consumes. */\n select: (data: TData | undefined) => TResult | undefined;\n /** Thrown (and stored) when the payload is missing or the request fails. */\n errorMessage: string;\n}\n\n/**\n * Writes to the workspace gateway. Returns the `[mutate, state]` tuple used by\n * the reference hooks. `mutate` REJECTS on failure so callers cannot mistake a\n * failed write for a successful one.\n */\nexport function useWorkspaceMutation<TData, TInput, TResult>(\n options: WorkspaceMutationOptions<TData, TInput, TResult>\n): readonly [(input: TInput) => Promise<TResult>, MutationState<TResult>] {\n const { document, errorMessage } = options;\n const client = useWorkspaceClient();\n const variablesRef = useLatest(options.variables);\n const selectRef = useLatest(options.select);\n\n const [state, setState] = useState<MutationState<TResult>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const mutate = useCallback(\n async (input: TInput): Promise<TResult> => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<TData>({\n mutation: document,\n variables: variablesRef.current(input),\n });\n // Apollo v4 does not reject on GraphQL errors by default: the mutation\n // RESOLVES with `data` undefined and the failure on `result.error`\n // (CombinedGraphQLErrors / networkError). Surface it like a rejection\n // so callers see the server's field-level message, not the fallback.\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw toError(operationError, errorMessage);\n }\n const selected = selectRef.current(result.data ?? undefined);\n if (selected === undefined) {\n throw new Error(errorMessage);\n }\n setState({ data: selected, loading: false, error: undefined });\n return selected;\n } catch (mutationError) {\n const failure = toError(mutationError, errorMessage);\n setState({ data: undefined, loading: false, error: failure });\n throw failure;\n }\n },\n [client, document, errorMessage, selectRef, variablesRef]\n );\n\n return [mutate, state] as const;\n}\n"],"mappings":";;;;;AAsBA,SAAgBA,IAAsC;CACpD,OAAOC,EAAiB,WAAW;AACrC;AAGA,SAAgBC,IAAqC;CACnD,OAAOC,EAAU,CAAC,CAAC;AACrB;AA2CA,SAASC,EAAQ,GAAgB,GAAgC;CAC/D,IAAMC,IAAUC,EAA6BC,CAAK;CAOlD,OANIF,IAGS,MAAMA,GAAS,EAAE,SAAM,CAAC,IAEjCE,aAAiB,QAAcA,IACxB,MAAMC,GAAiB,EAAE,SAAM,CAAC;AAC7C;AAGA,SAASC,EAAa,GAAmC;CACvD,IAAMC,IAAMC,EAAOC,CAAK;CAIxB,OAHAC,QAAsB;EACpB,EAAI,UAAUD;CAChB,GAAG,CAACA,CAAK,CAAC,GACHF;AACT;AAsBA,SAAgBI,EAC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E,MAAM,KAAA;IAAW,SAAS;IAAO,OAAOI;GAAQ,CAAC,GACtDA;EACR;CACF,GACA;EAAC5C;EAAQc;EAAUE;EAAcf;EAAWqC;CAAY,CAGlD,GAAQC,CAAK;AACvB"}
@@ -1,5 +1,5 @@
1
1
  import { UpdateBotmanorAgentInput } from '../../generated/wspace-types';
2
- import { BaseFilter } from '../types';
2
+ import { AgentFilter } from '../types';
3
3
  import { GraphQLInput } from './internal/mutationInput';
4
4
  import { PaginatedQueryResult, QueryResult } from './internal/workspaceGateway';
5
5
  export interface AgentRecord {
@@ -7,6 +7,8 @@ export interface AgentRecord {
7
7
  name: string;
8
8
  slug: string;
9
9
  description?: string | null;
10
+ /** Emoji chosen for the agent; null means the default. */
11
+ avatar?: string | null;
10
12
  type: string;
11
13
  status: string;
12
14
  visibility?: string | null;
@@ -55,12 +57,16 @@ interface CreateAgentInput {
55
57
  name: string;
56
58
  slug?: string;
57
59
  description?: string;
60
+ avatar?: string;
58
61
  type: string;
59
62
  systemPrompt: string;
60
63
  temperature?: number;
61
64
  maxTokens?: number;
65
+ maxConcurrentExecutions?: number;
62
66
  capabilities?: string[];
63
67
  llmModelId?: string;
68
+ knowledgeBaseIds?: string[];
69
+ mcpConnectionIds?: string[];
64
70
  }
65
71
  interface UpdateAgentInput {
66
72
  agentId: string;
@@ -69,11 +75,13 @@ interface UpdateAgentInput {
69
75
  export declare const agentKeys: {
70
76
  all: readonly ["agents"];
71
77
  lists: () => readonly ["agents", "list"];
72
- list: (filter?: BaseFilter) => readonly ["agents", "list", BaseFilter | undefined];
78
+ list: (filter?: AgentFilter) => readonly ["agents", "list", AgentFilter | undefined];
73
79
  details: () => readonly ["agents", "detail"];
74
80
  detail: (id: string) => readonly ["agents", "detail", string];
75
81
  };
76
- export declare function useAgents(filter?: BaseFilter): PaginatedQueryResult<AgentRecord[]>;
82
+ export declare function useAgents(filter?: AgentFilter, options?: {
83
+ enabled?: boolean;
84
+ }): PaginatedQueryResult<AgentRecord[]>;
77
85
  /**
78
86
  * Exact agent counts by status for the workspace (BOFF-12426). Unlike
79
87
  * `useAgents` this is not capped at one page, so it is the source for
@@ -88,6 +96,21 @@ export interface AgentCounts {
88
96
  archived: number;
89
97
  }
90
98
  export declare function useAgentCounts(enabled?: boolean): QueryResult<AgentCounts | null>;
99
+ /** What still uses an agent, shown in the delete confirmation (BOFF-12457). */
100
+ export interface AgentUsage {
101
+ bots: Array<{
102
+ id: string;
103
+ name: string;
104
+ isDefault: boolean;
105
+ }>;
106
+ a2aConnections: Array<{
107
+ id: string;
108
+ name: string;
109
+ }>;
110
+ workflowIds: string[];
111
+ }
112
+ /** Returns a function that reads what uses an agent. Reads fresh every time, because a delete is about to rely on it. */
113
+ export declare function useLoadAgentUsage(): (agentId: string) => Promise<AgentUsage>;
91
114
  export declare function useAgent(agentId: string | undefined): {
92
115
  data: AgentRecord | null;
93
116
  loading: boolean;
@@ -1,17 +1,19 @@
1
1
  import { useBotlit as e } from "../providers/BotlitProvider.js";
2
- import { buildMutationInput as t, fieldsOf as n } from "./internal/mutationInput.js";
3
- import { useWorkspacePaginatedQuery as r, useWorkspaceQuery as i } from "./internal/workspaceGateway.js";
4
- import { useCallback as a, useEffect as o, useMemo as s, useState as c } from "react";
5
- import { gql as l } from "@apollo/client";
6
- import { useGatewayClient as u } from "@burdenoff/fe-libs/shared/graphql";
2
+ import { graphqlErrorMessage as t } from "../utils/errors.js";
3
+ import { buildMutationInput as n, fieldsOf as r } from "./internal/mutationInput.js";
4
+ import { useWorkspacePaginatedQuery as i, useWorkspaceQuery as a } from "./internal/workspaceGateway.js";
5
+ import { useCallback as o, useEffect as s, useMemo as c, useState as l } from "react";
6
+ import { gql as u } from "@apollo/client";
7
+ import { useGatewayClient as d } from "@burdenoff/fe-libs/shared/graphql";
7
8
  // src/botlit/hooks/useAgents.ts
8
- var d = l`
9
+ var f = u`
9
10
  query ListBotmanorAgents($filters: BotmanorAgentFilterInput, $pagination: PaginationInput) {
10
11
  listBotmanorAgents(filters: $filters, pagination: $pagination) {
11
12
  id
12
13
  name
13
14
  slug
14
15
  description
16
+ avatar
15
17
  type
16
18
  status
17
19
  visibility
@@ -22,6 +24,7 @@ var d = l`
22
24
  lastExecutedAt
23
25
  specialization
24
26
  tagIds
27
+ knowledgeBaseIds
25
28
  createdAt
26
29
  updatedAt
27
30
  createdById
@@ -29,13 +32,14 @@ var d = l`
29
32
  workspaceId
30
33
  }
31
34
  }
32
- `, f = l`
35
+ `, p = u`
33
36
  query GetBotmanorAgent($id: ID!) {
34
37
  getBotmanorAgent(id: $id) {
35
38
  id
36
39
  name
37
40
  slug
38
41
  description
42
+ avatar
39
43
  type
40
44
  status
41
45
  visibility
@@ -63,13 +67,14 @@ var d = l`
63
67
  workspaceId
64
68
  }
65
69
  }
66
- `, p = l`
70
+ `, m = u`
67
71
  mutation CreateBotmanorAgent($input: CreateBotmanorAgentInput!) {
68
72
  createBotmanorAgent(input: $input) {
69
73
  id
70
74
  name
71
75
  slug
72
76
  description
77
+ avatar
73
78
  type
74
79
  status
75
80
  visibility
@@ -85,13 +90,14 @@ var d = l`
85
90
  workspaceId
86
91
  }
87
92
  }
88
- `, m = l`
93
+ `, h = u`
89
94
  mutation UpdateBotmanorAgent($id: ID!, $input: UpdateBotmanorAgentInput!) {
90
95
  updateBotmanorAgent(id: $id, input: $input) {
91
96
  id
92
97
  name
93
98
  slug
94
99
  description
100
+ avatar
95
101
  type
96
102
  status
97
103
  visibility
@@ -112,11 +118,11 @@ var d = l`
112
118
  workspaceId
113
119
  }
114
120
  }
115
- `, h = l`
121
+ `, g = u`
116
122
  mutation DeleteBotmanorAgent($id: ID!) {
117
123
  deleteBotmanorAgent(id: $id)
118
124
  }
119
- `, g = l`
125
+ `, _ = u`
120
126
  query ListAgentVersions($agentId: ID!, $pagination: PaginationInput) {
121
127
  listAgentVersions(agentId: $agentId, pagination: $pagination) {
122
128
  id
@@ -131,7 +137,7 @@ var d = l`
131
137
  publishedAt
132
138
  }
133
139
  }
134
- `, _ = l`
140
+ `, v = u`
135
141
  mutation PublishAgentVersion($agentId: ID!, $versionId: ID!, $changelog: String) {
136
142
  publishAgentVersion(agentId: $agentId, versionId: $versionId, changelog: $changelog) {
137
143
  id
@@ -143,7 +149,7 @@ var d = l`
143
149
  publishedAt
144
150
  }
145
151
  }
146
- `, v = l`
152
+ `, y = u`
147
153
  mutation RollbackAgentVersion($agentId: ID!, $targetVersionId: ID!) {
148
154
  rollbackAgentVersion(agentId: $agentId, targetVersionId: $targetVersionId) {
149
155
  id
@@ -155,7 +161,8 @@ var d = l`
155
161
  publishedAt
156
162
  }
157
163
  }
158
- `, y = 100, b = [], x = n({
164
+ `, b = 100, x = [], S = r({
165
+ avatar: !0,
159
166
  bucketId: !0,
160
167
  capabilities: !0,
161
168
  context: !0,
@@ -178,10 +185,14 @@ var d = l`
178
185
  visibility: !0,
179
186
  workflowIds: !0
180
187
  });
181
- function S(e) {
188
+ function C(e, n) {
189
+ let r = e.error;
190
+ if (r != null) throw Error(t(r, n), { cause: r });
191
+ }
192
+ function w(e) {
182
193
  return e;
183
194
  }
184
- function C(e, t) {
195
+ function T(e, t) {
185
196
  if (e || t) return {
186
197
  workspaceId: e,
187
198
  search: t?.search,
@@ -190,20 +201,20 @@ function C(e, t) {
190
201
  bucketId: t?.bucketId
191
202
  };
192
203
  }
193
- function w(t) {
194
- let { workspaceId: n } = e(), i = s(() => ({ filters: C(n, t) }), [t, n]);
195
- return r({
196
- document: d,
197
- variables: i,
198
- pageSize: y,
204
+ function E(t, n) {
205
+ let { workspaceId: r } = e(), a = c(() => ({ filters: T(r, t) }), [t, r]);
206
+ return i({
207
+ document: f,
208
+ variables: a,
209
+ pageSize: b,
199
210
  extractRows: (e) => e?.listBotmanorAgents ?? [],
200
211
  select: (e) => e,
201
- fallback: b,
202
- enabled: !!n,
212
+ fallback: x,
213
+ enabled: !!r && n?.enabled !== !1,
203
214
  errorMessage: "Failed to load agents"
204
215
  });
205
216
  }
206
- var T = l`
217
+ var D = u`
207
218
  query GetBotmanorAgentCounts {
208
219
  getBotmanorAgentCounts {
209
220
  total
@@ -215,10 +226,10 @@ var T = l`
215
226
  }
216
227
  }
217
228
  `;
218
- function E(t = !0) {
219
- let { workspaceId: n } = e(), r = s(() => ({}), []);
220
- return i({
221
- document: T,
229
+ function O(t = !0) {
230
+ let { workspaceId: n } = e(), r = c(() => ({}), []);
231
+ return a({
232
+ document: D,
222
233
  variables: r,
223
234
  select: (e) => e?.getBotmanorAgentCounts ?? null,
224
235
  fallback: null,
@@ -226,143 +237,182 @@ function E(t = !0) {
226
237
  errorMessage: "Failed to load agent counts"
227
238
  });
228
239
  }
229
- function D(e) {
230
- let t = S(u("workspace")), [n, r] = c(null), [i, s] = c(!1), [l, d] = c(), p = a(async () => {
231
- if (!e) r(null);
240
+ var k = u`
241
+ query GetBotmanorAgentUsage($id: ID!) {
242
+ getBotmanorAgentUsage(id: $id) {
243
+ bots {
244
+ id
245
+ name
246
+ isDefault
247
+ }
248
+ a2aConnections {
249
+ id
250
+ name
251
+ }
252
+ workflowIds
253
+ }
254
+ }
255
+ `;
256
+ function A() {
257
+ let e = w(d("workspace"));
258
+ return o(async (t) => {
259
+ let n = await e.query({
260
+ query: k,
261
+ variables: { id: t },
262
+ fetchPolicy: "network-only"
263
+ }), r = n.error;
264
+ if (r != null) throw r instanceof Error ? r : /* @__PURE__ */ Error("Failed to load agent usage");
265
+ return n.data?.getBotmanorAgentUsage ?? {
266
+ bots: [],
267
+ a2aConnections: [],
268
+ workflowIds: []
269
+ };
270
+ }, [e]);
271
+ }
272
+ function j(e) {
273
+ let t = w(d("workspace")), [n, r] = l(null), [i, a] = l(!!e), [c, u] = l(), f = o(async () => {
274
+ if (!e) r(null), a(!1);
232
275
  else {
233
- s(!0), d(void 0);
276
+ a(!0), u(void 0);
234
277
  try {
235
278
  let n = await t.query({
236
- query: f,
279
+ query: p,
237
280
  variables: { id: e },
238
281
  fetchPolicy: "network-only"
239
- });
282
+ }), i = n.error;
283
+ if (i != null) throw i instanceof Error ? i : /* @__PURE__ */ Error("Failed to load agent");
240
284
  r(n.data?.getBotmanorAgent ?? null);
241
285
  } catch (e) {
242
- d(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load agent"));
286
+ r(null), u(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load agent"));
243
287
  } finally {
244
- s(!1);
288
+ a(!1);
245
289
  }
246
290
  }
247
291
  }, [e, t]);
248
- return o(() => {
249
- p();
250
- }, [p]), {
292
+ return s(() => {
293
+ f();
294
+ }, [f]), {
251
295
  data: n,
252
296
  loading: i,
253
- error: l,
254
- refetch: p
297
+ error: c,
298
+ refetch: f
255
299
  };
256
300
  }
257
- function O() {
258
- let e = S(u("workspace")), [t, n] = c({
301
+ function M() {
302
+ let e = w(d("workspace")), [n, r] = l({
259
303
  data: void 0,
260
304
  loading: !1,
261
305
  error: void 0
262
306
  });
263
- return [a(async (t) => {
264
- n({
307
+ return [o(async (n) => {
308
+ r({
265
309
  data: void 0,
266
310
  loading: !0,
267
311
  error: void 0
268
312
  });
269
313
  try {
270
- let r = (await e.mutate({
271
- mutation: p,
272
- variables: { input: t }
273
- })).data?.createBotmanorAgent;
274
- if (!r) throw Error("Failed to create agent");
275
- return n({
276
- data: r,
314
+ let t = await e.mutate({
315
+ mutation: m,
316
+ variables: { input: n }
317
+ });
318
+ C(t, "Failed to create agent");
319
+ let i = t.data?.createBotmanorAgent;
320
+ if (!i) throw Error("Failed to create agent");
321
+ return r({
322
+ data: i,
277
323
  loading: !1,
278
324
  error: void 0
279
- }), r;
325
+ }), i;
280
326
  } catch (e) {
281
- let t = e instanceof Error ? e : /* @__PURE__ */ Error("Failed to create agent");
282
- throw n({
327
+ let n = Error(t(e, "Failed to create agent"), { cause: e });
328
+ throw r({
283
329
  data: void 0,
284
330
  loading: !1,
285
- error: t
286
- }), t;
331
+ error: n
332
+ }), n;
287
333
  }
288
- }, [e]), t];
334
+ }, [e]), n];
289
335
  }
290
- function k() {
291
- let e = S(u("workspace")), [n, r] = c({
336
+ function N() {
337
+ let e = w(d("workspace")), [r, i] = l({
292
338
  data: void 0,
293
339
  loading: !1,
294
340
  error: void 0
295
341
  });
296
- return [a(async ({ agentId: n, input: i }) => {
297
- r({
342
+ return [o(async ({ agentId: r, input: a }) => {
343
+ i({
298
344
  data: void 0,
299
345
  loading: !0,
300
346
  error: void 0
301
347
  });
302
348
  try {
303
- let a = (await e.mutate({
304
- mutation: m,
349
+ let t = await e.mutate({
350
+ mutation: h,
305
351
  variables: {
306
- id: n,
307
- input: t(i, x)
352
+ id: r,
353
+ input: n(a, S)
308
354
  }
309
- })).data?.updateBotmanorAgent;
310
- if (!a) throw Error("Failed to update agent");
311
- return r({
312
- data: a,
355
+ });
356
+ C(t, "Failed to update agent");
357
+ let o = t.data?.updateBotmanorAgent;
358
+ if (!o) throw Error("Failed to update agent");
359
+ return i({
360
+ data: o,
313
361
  loading: !1,
314
362
  error: void 0
315
- }), a;
363
+ }), o;
316
364
  } catch (e) {
317
- let t = e instanceof Error ? e : /* @__PURE__ */ Error("Failed to update agent");
318
- throw r({
365
+ let n = Error(t(e, "Failed to update agent"), { cause: e });
366
+ throw i({
319
367
  data: void 0,
320
368
  loading: !1,
321
- error: t
322
- }), t;
369
+ error: n
370
+ }), n;
323
371
  }
324
- }, [e]), n];
372
+ }, [e]), r];
325
373
  }
326
- function A() {
327
- let e = S(u("workspace")), [t, n] = c({
374
+ function P() {
375
+ let e = w(d("workspace")), [n, r] = l({
328
376
  data: void 0,
329
377
  loading: !1,
330
378
  error: void 0
331
379
  });
332
- return [a(async (t) => {
333
- n({
380
+ return [o(async (n) => {
381
+ r({
334
382
  data: void 0,
335
383
  loading: !0,
336
384
  error: void 0
337
385
  });
338
386
  try {
339
- let r = (await e.mutate({
340
- mutation: h,
341
- variables: { id: t }
342
- })).data?.deleteBotmanorAgent ?? !1;
343
- return n({
344
- data: r,
387
+ let t = await e.mutate({
388
+ mutation: g,
389
+ variables: { id: n }
390
+ });
391
+ C(t, "Failed to delete agent");
392
+ let i = t.data?.deleteBotmanorAgent ?? !1;
393
+ return r({
394
+ data: i,
345
395
  loading: !1,
346
396
  error: void 0
347
- }), r;
397
+ }), i;
348
398
  } catch (e) {
349
- let t = e instanceof Error ? e : /* @__PURE__ */ Error("Failed to delete agent");
350
- throw n({
399
+ let n = Error(t(e, "Failed to delete agent"), { cause: e });
400
+ throw r({
351
401
  data: void 0,
352
402
  loading: !1,
353
- error: t
354
- }), t;
403
+ error: n
404
+ }), n;
355
405
  }
356
- }, [e]), t];
406
+ }, [e]), n];
357
407
  }
358
- function j(e) {
359
- let t = S(u("workspace")), [n, r] = c([]), [i, s] = c(!1), [l, d] = c(), f = a(async () => {
408
+ function F(e) {
409
+ let t = w(d("workspace")), [n, r] = l([]), [i, a] = l(!1), [c, u] = l(), f = o(async () => {
360
410
  if (!e) r([]);
361
411
  else {
362
- s(!0), d(void 0);
412
+ a(!0), u(void 0);
363
413
  try {
364
414
  let n = (await t.query({
365
- query: g,
415
+ query: _,
366
416
  variables: {
367
417
  agentId: e,
368
418
  pagination: {
@@ -374,28 +424,28 @@ function j(e) {
374
424
  })).data?.listAgentVersions ?? [];
375
425
  r([...n].sort((e, t) => e.createdAt && t.createdAt ? t.createdAt.localeCompare(e.createdAt) : 0));
376
426
  } catch (e) {
377
- d(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load agent versions"));
427
+ u(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load agent versions"));
378
428
  } finally {
379
- s(!1);
429
+ a(!1);
380
430
  }
381
431
  }
382
432
  }, [e, t]);
383
- return o(() => {
433
+ return s(() => {
384
434
  f();
385
435
  }, [f]), {
386
436
  data: n,
387
437
  loading: i,
388
- error: l,
438
+ error: c,
389
439
  refetch: f
390
440
  };
391
441
  }
392
- function M() {
393
- let e = S(u("workspace")), [t, n] = c({
442
+ function I() {
443
+ let e = w(d("workspace")), [t, n] = l({
394
444
  data: void 0,
395
445
  loading: !1,
396
446
  error: void 0
397
447
  });
398
- return [a(async ({ agentId: t, versionId: r, changelog: i }) => {
448
+ return [o(async ({ agentId: t, versionId: r, changelog: i }) => {
399
449
  n({
400
450
  data: void 0,
401
451
  loading: !0,
@@ -403,7 +453,7 @@ function M() {
403
453
  });
404
454
  try {
405
455
  let a = (await e.mutate({
406
- mutation: _,
456
+ mutation: v,
407
457
  variables: {
408
458
  agentId: t,
409
459
  versionId: r,
@@ -426,13 +476,13 @@ function M() {
426
476
  }
427
477
  }, [e]), t];
428
478
  }
429
- function N() {
430
- let e = S(u("workspace")), [t, n] = c({
479
+ function L() {
480
+ let e = w(d("workspace")), [t, n] = l({
431
481
  data: void 0,
432
482
  loading: !1,
433
483
  error: void 0
434
484
  });
435
- return [a(async ({ agentId: t, targetVersionId: r }) => {
485
+ return [o(async ({ agentId: t, targetVersionId: r }) => {
436
486
  n({
437
487
  data: void 0,
438
488
  loading: !0,
@@ -440,7 +490,7 @@ function N() {
440
490
  });
441
491
  try {
442
492
  let i = (await e.mutate({
443
- mutation: v,
493
+ mutation: y,
444
494
  variables: {
445
495
  agentId: t,
446
496
  targetVersionId: r
@@ -462,6 +512,6 @@ function N() {
462
512
  }
463
513
  }, [e]), t];
464
514
  }
465
- export { D as useAgent, E as useAgentCounts, j as useAgentVersions, w as useAgents, O as useCreateAgent, A as useDeleteAgent, M as usePublishAgentVersion, N as useRollbackAgentVersion, k as useUpdateAgent };
515
+ export { j as useAgent, O as useAgentCounts, F as useAgentVersions, E as useAgents, M as useCreateAgent, P as useDeleteAgent, A as useLoadAgentUsage, I as usePublishAgentVersion, L as useRollbackAgentVersion, N as useUpdateAgent };
466
516
 
467
517
  //# sourceMappingURL=useAgents.js.map