@burdenoff/microfe-botmanor 2026.1120.5 → 2026.1120.7

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 (44) hide show
  1. package/dist/botlit/components/AssistantChannelPanel.js +3 -3
  2. package/dist/botlit/components/AssistantChannelPanel.js.map +1 -1
  3. package/dist/botlit/components/ChannelRoutesPanel.d.ts +9 -0
  4. package/dist/botlit/components/ChannelRoutesPanel.js +275 -0
  5. package/dist/botlit/components/ChannelRoutesPanel.js.map +1 -0
  6. package/dist/botlit/components/CreateChannelRouteDialog.d.ts +13 -0
  7. package/dist/botlit/components/CreateChannelRouteDialog.js +188 -0
  8. package/dist/botlit/components/CreateChannelRouteDialog.js.map +1 -0
  9. package/dist/botlit/hooks/index.d.ts +3 -3
  10. package/dist/botlit/hooks/index.js +19 -19
  11. package/dist/botlit/hooks/useAssistantChat.d.ts +32 -0
  12. package/dist/botlit/hooks/useAssistantChat.js +98 -0
  13. package/dist/botlit/hooks/useAssistantChat.js.map +1 -0
  14. package/dist/botlit/hooks/useBots.d.ts +5 -0
  15. package/dist/botlit/hooks/useBots.js +63 -50
  16. package/dist/botlit/hooks/useBots.js.map +1 -1
  17. package/dist/botlit/hooks/useChannels.d.ts +49 -23
  18. package/dist/botlit/hooks/useChannels.js +141 -135
  19. package/dist/botlit/hooks/useChannels.js.map +1 -1
  20. package/dist/botlit/pages/BotChannelsTab.js +12 -3
  21. package/dist/botlit/pages/BotChannelsTab.js.map +1 -1
  22. package/dist/botlit/pages/ChannelDetailPage.js +642 -776
  23. package/dist/botlit/pages/ChannelDetailPage.js.map +1 -1
  24. package/dist/botlit/pages/ChannelRoutesPage.js +22 -208
  25. package/dist/botlit/pages/ChannelRoutesPage.js.map +1 -1
  26. package/dist/botlit/pages/ChannelsPage.js +314 -251
  27. package/dist/botlit/pages/ChannelsPage.js.map +1 -1
  28. package/dist/botlit/pages/ChatPage.js +207 -83
  29. package/dist/botlit/pages/ChatPage.js.map +1 -1
  30. package/dist/botlit/utils/assistantAvailability.d.ts +34 -0
  31. package/dist/botlit/utils/assistantAvailability.js +24 -0
  32. package/dist/botlit/utils/assistantAvailability.js.map +1 -0
  33. package/dist/botlit/utils/channelConnectors.d.ts +13 -0
  34. package/dist/botlit/utils/channelConnectors.js +21 -1
  35. package/dist/botlit/utils/channelConnectors.js.map +1 -1
  36. package/dist/botlit/utils/errors.d.ts +8 -0
  37. package/dist/botlit/utils/errors.js +21 -1
  38. package/dist/botlit/utils/errors.js.map +1 -1
  39. package/dist/generated/wspace-operations.d.ts +200 -12
  40. package/dist/generated/wspace-operations.js +153 -110
  41. package/dist/generated/wspace-operations.js.map +1 -1
  42. package/dist/generated/wspace-types.d.ts +40 -0
  43. package/dist/generated/wspace-types.js.map +1 -1
  44. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"useBots.js","names":["LIST_BOT_APPS_DOCUMENT","GET_BOT_APP_DOCUMENT","CREATE_BOT_APP_DOCUMENT","UPDATE_BOT_APP_DOCUMENT","DELETE_BOT_APP_DOCUMENT","LIST_PAGE_SIZE","NO_BOTS","UPDATE_BOT_APP_FIELDS","fieldsOf","getWorkspaceClient","client","buildBotFilter","workspaceId","filter","useBots","useBotlit","variables","useMemo","useWorkspacePaginatedQuery","data","rows","GET_BOT_APP_COUNTS_DOCUMENT","useBotAppCounts","useWorkspaceQuery","enabled","useBot","useGatewayClient","setData","useState","loading","setLoading","botId","error","setError","refetch","useCallback","result","operationError","queryError","useEffect","useCreateBot","state","setState","createdBot","mutationError","useUpdateBot","updatedBot","buildMutationInput","input","useDeleteBot","deleted"],"sources":["../../../src/botlit/hooks/useBots.ts"],"sourcesContent":["import { gql, type ApolloClient } from '@apollo/client';\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport { useGatewayClient } from '@burdenoff/fe-libs/shared/graphql';\n\nimport type { UpdateBotAppInput } from '../../generated/wspace-types';\nimport { useBotlit } from '../providers/BotlitProvider';\nimport type { BaseFilter } from '../types';\nimport { buildMutationInput, fieldsOf, type GraphQLInput } from './internal/mutationInput';\nimport {\n useWorkspacePaginatedQuery,\n useWorkspaceQuery,\n type PaginatedQueryResult,\n type QueryResult,\n} from './internal/workspaceGateway';\n\nconst LIST_BOT_APPS_DOCUMENT = gql`\n query ListBotApps($filters: BotAppFilterInput, $pagination: PaginationInput) {\n listBotApps(filters: $filters, pagination: $pagination) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n welcomeMessage\n fallbackMessage\n workflowId\n executionCount\n lastExecutedAt\n tagIds\n tags\n createdAt\n updatedAt\n createdById\n updatedById\n workspaceId\n }\n }\n`;\n\nconst GET_BOT_APP_DOCUMENT = gql`\n query GetBotApp($id: ID!) {\n getBotApp(id: $id) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n welcomeMessage\n fallbackMessage\n workflowId\n executionCount\n lastExecutedAt\n tagIds\n tags\n createdAt\n updatedAt\n createdById\n updatedById\n workspaceId\n }\n }\n`;\n\nconst CREATE_BOT_APP_DOCUMENT = gql`\n mutation CreateBotApp($input: CreateBotAppInput!) {\n createBotApp(input: $input) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n workflowId\n tagIds\n tags\n createdAt\n updatedAt\n workspaceId\n }\n }\n`;\n\nconst UPDATE_BOT_APP_DOCUMENT = gql`\n mutation UpdateBotApp($id: ID!, $input: UpdateBotAppInput!) {\n updateBotApp(id: $id, input: $input) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n welcomeMessage\n fallbackMessage\n workflowId\n tagIds\n tags\n updatedAt\n updatedById\n workspaceId\n }\n }\n`;\n\nconst DELETE_BOT_APP_DOCUMENT = gql`\n mutation DeleteBotApp($id: ID!) {\n deleteBotApp(id: $id)\n }\n`;\n\ntype WorkspaceClient = ApolloClient;\n\nexport interface BotAppRecord {\n id: string;\n name: string;\n slug: string;\n description?: string | null;\n icon?: string | null;\n type: string;\n status: string;\n visibility?: string | null;\n routingStrategy?: string | null;\n defaultAgentId?: string | null;\n welcomeMessage?: string | null;\n fallbackMessage?: string | null;\n /** Bound FluidGrids workflow definition id — the bot's designed behaviour. */\n workflowId?: string | null;\n executionCount?: number | null;\n lastExecutedAt?: string | null;\n tagIds?: string[] | null;\n /** Entity-owned universal tag records (JSON). */\n tags?: unknown;\n createdAt?: string | null;\n updatedAt?: string | null;\n createdById?: string | null;\n updatedById?: string | null;\n workspaceId?: string | null;\n}\n\ninterface ListBotAppsData {\n listBotApps: BotAppRecord[];\n}\n\nconst LIST_PAGE_SIZE = 100;\nconst NO_BOTS: BotAppRecord[] = [];\n\ninterface GetBotAppData {\n getBotApp: BotAppRecord | null;\n}\n\ninterface CreateBotAppData {\n createBotApp: BotAppRecord;\n}\n\ninterface UpdateBotAppData {\n updateBotApp: BotAppRecord;\n}\n\ninterface DeleteBotAppData {\n deleteBotApp: boolean;\n}\n\ninterface BotMutationState<T> {\n data: T | undefined;\n loading: boolean;\n error: Error | undefined;\n}\n\ninterface CreateBotInput {\n workspaceId: string;\n name: string;\n slug?: string;\n type: string;\n routingStrategy?: string;\n visibility?: string;\n description?: string;\n icon?: string;\n}\n\ninterface UpdateBotInput {\n botId: string;\n input: GraphQLInput<UpdateBotAppInput>;\n}\n\nconst UPDATE_BOT_APP_FIELDS = fieldsOf<UpdateBotAppInput>({\n bucketId: true,\n context: true,\n defaultAgentId: true,\n description: true,\n fallbackMessage: true,\n icon: true,\n metadata: true,\n name: true,\n routingStrategy: true,\n slug: true,\n status: true,\n tagIds: true,\n tags: true,\n type: true,\n visibility: true,\n welcomeMessage: true,\n workflowId: true,\n});\n\nfunction getWorkspaceClient(client: unknown): WorkspaceClient {\n return client as WorkspaceClient;\n}\n\nfunction buildBotFilter(\n workspaceId: string | undefined,\n filter?: BaseFilter\n): Record<string, unknown> | undefined {\n if (!workspaceId && !filter) return undefined;\n\n return {\n workspaceId,\n search: filter?.search,\n status: filter?.status?.[0],\n visibility: filter?.visibility?.[0],\n bucketId: filter?.bucketId,\n };\n}\n\nexport const botKeys = {\n all: ['bots'] as const,\n lists: () => [...botKeys.all, 'list'] as const,\n list: (filter?: BaseFilter) => [...botKeys.lists(), filter] as const,\n details: () => [...botKeys.all, 'detail'] as const,\n detail: (id: string) => [...botKeys.details(), id] as const,\n};\n\nexport function useBots(filter?: BaseFilter): PaginatedQueryResult<BotAppRecord[]> {\n const { workspaceId } = useBotlit();\n\n const variables = useMemo(\n () => ({ filters: buildBotFilter(workspaceId, filter) }),\n [filter, workspaceId]\n );\n\n return useWorkspacePaginatedQuery<ListBotAppsData, BotAppRecord, BotAppRecord[]>({\n document: LIST_BOT_APPS_DOCUMENT,\n variables,\n pageSize: LIST_PAGE_SIZE,\n extractRows: (data) => data?.listBotApps ?? [],\n select: (rows) => rows,\n fallback: NO_BOTS,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load bots',\n });\n}\n\n/**\n * Exact bot counts by status for the workspace (BOFF-12426). Unlike `useBots`\n * this is not capped at one page, so it is the source for dashboard totals.\n * `total` counts every status; the dashboard shows `total - archived`.\n */\nexport interface BotAppCounts {\n total: number;\n draft: number;\n active: number;\n paused: number;\n archived: number;\n}\n\ninterface BotAppCountsData {\n getBotAppCounts?: BotAppCounts | null;\n}\n\nconst GET_BOT_APP_COUNTS_DOCUMENT = gql`\n query GetBotAppCounts {\n getBotAppCounts {\n total\n draft\n active\n paused\n archived\n }\n }\n`;\n\nexport function useBotAppCounts(enabled = true): QueryResult<BotAppCounts | null> {\n const { workspaceId } = useBotlit();\n const variables = useMemo(() => ({}), []);\n\n return useWorkspaceQuery<BotAppCountsData, BotAppCounts | null>({\n document: GET_BOT_APP_COUNTS_DOCUMENT,\n variables,\n select: (data) => data?.getBotAppCounts ?? null,\n fallback: null,\n enabled: enabled && Boolean(workspaceId),\n errorMessage: 'Failed to load bot counts',\n });\n}\n\nexport function useBot(botId: string | undefined) {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [data, setData] = useState<BotAppRecord | null>(null);\n // Loading from the first render when there is a bot to read, so a page that\n // depends on the bot never acts on \"no bot yet\" for the frame before the read.\n const [loading, setLoading] = useState(Boolean(botId));\n const [error, setError] = useState<Error | undefined>();\n\n const refetch = useCallback(async () => {\n if (!botId) {\n setData(null);\n setLoading(false);\n return;\n }\n\n setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<GetBotAppData>({\n query: GET_BOT_APP_DOCUMENT,\n variables: { id: botId },\n fetchPolicy: 'network-only',\n });\n // Apollo v4 resolves (not rejects) with `result.error` set on GraphQL errors.\n // Without this a FORBIDDEN read looked like \"bot not found\" (BOFF-12436).\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw operationError instanceof Error ? operationError : new Error('Failed to load bot');\n }\n setData(result.data?.getBotApp ?? null);\n } catch (queryError) {\n setData(null);\n setError(queryError instanceof Error ? queryError : new Error('Failed to load bot'));\n } finally {\n setLoading(false);\n }\n }, [botId, client]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\nexport function useCreateBot() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<BotMutationState<BotAppRecord>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const createBot = useCallback(\n async (input: CreateBotInput) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<CreateBotAppData>({\n mutation: CREATE_BOT_APP_DOCUMENT,\n variables: { input },\n });\n\n const createdBot = result.data?.createBotApp;\n if (!createdBot) {\n throw new Error('Failed to create bot');\n }\n\n setState({ data: createdBot, loading: false, error: undefined });\n return createdBot;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error ? mutationError : new Error('Failed to create bot');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [createBot, state] as const;\n}\n\nexport function useUpdateBot() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<BotMutationState<BotAppRecord>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const updateBot = useCallback(\n async ({ botId, input }: UpdateBotInput) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<UpdateBotAppData>({\n mutation: UPDATE_BOT_APP_DOCUMENT,\n variables: { id: botId, input: buildMutationInput(input, UPDATE_BOT_APP_FIELDS) },\n });\n\n const updatedBot = result.data?.updateBotApp;\n if (!updatedBot) {\n throw new Error('Failed to update bot');\n }\n\n setState({ data: updatedBot, loading: false, error: undefined });\n return updatedBot;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error ? mutationError : new Error('Failed to update bot');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [updateBot, state] as const;\n}\n\nexport function useDeleteBot() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<BotMutationState<boolean>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const deleteBot = useCallback(\n async (botId: string) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<DeleteBotAppData>({\n mutation: DELETE_BOT_APP_DOCUMENT,\n variables: { id: botId },\n });\n\n const deleted = result.data?.deleteBotApp ?? false;\n setState({ data: deleted, loading: false, error: undefined });\n return deleted;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error ? mutationError : new Error('Failed to delete bot');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [deleteBot, state] as const;\n}\n"],"mappings":";;;;;;;AAeA,IAAMA,IAAyB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6B5BC,IAAuB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6B1BC,IAA0B,CAAG;;;;;;;;;;;;;;;;;;;;;GAuB7BC,IAA0B,CAAG;;;;;;;;;;;;;;;;;;;;;;;GAyB7BC,IAA0B,CAAG;;;;GAuC7BC,IAAiB,KACj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ChB,OAAO,MAAkB;EACvB,EAAS;GAAE,MAAM,KAAA;GAAW,SAAS;GAAM,OAAO,KAAA;EAAU,CAAC;EAC7D,IAAI;GAMF,IAAMe,KAAU,MALKxC,EAAO,OAAyB;IACnD,UAAUN;IACV,WAAW,EAAE,IAAI2B,EAAM;GACzB,CAAC,EAAA,CAEsB,MAAM,gBAAgB;GAE7C,OADAW,EAAS;IAAE,MAAMQ;IAAS,SAAS;IAAO,OAAO,KAAA;GAAU,CAAC,GACrDA;EACT,SAASN,GAAe;GACtB,IAAMZ,IACJY,aAAyB,QAAQA,IAAgB,gBAAI,MAAM,sBAAsB;GAEnF,MADAF,EAAS;IAAE,MAAM,KAAA;IAAW,SAAS;IAAO;GAAM,CAAC,GAC7CV;EACR;CACF,GACA,CAACtB,CAAM,CAGD,GAAW+B,CAAK;AAC1B"}
1
+ {"version":3,"file":"useBots.js","names":["LIST_BOT_APPS_DOCUMENT","GET_BOT_APP_DOCUMENT","CREATE_BOT_APP_DOCUMENT","UPDATE_BOT_APP_DOCUMENT","DELETE_BOT_APP_DOCUMENT","LIST_PAGE_SIZE","NO_BOTS","UPDATE_BOT_APP_FIELDS","fieldsOf","getWorkspaceClient","client","buildBotFilter","workspaceId","filter","useBots","useBotlit","variables","useMemo","useWorkspacePaginatedQuery","data","rows","useAllBots","useWorkspaceAllPagesQuery","GET_BOT_APP_COUNTS_DOCUMENT","useBotAppCounts","useWorkspaceQuery","enabled","useBot","useGatewayClient","setData","useState","loading","setLoading","botId","error","setError","refetch","useCallback","result","operationError","queryError","useEffect","useCreateBot","state","setState","createdBot","mutationError","useUpdateBot","updatedBot","buildMutationInput","input","useDeleteBot","deleted"],"sources":["../../../src/botlit/hooks/useBots.ts"],"sourcesContent":["import { gql, type ApolloClient } from '@apollo/client';\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport { useGatewayClient } from '@burdenoff/fe-libs/shared/graphql';\n\nimport type { UpdateBotAppInput } from '../../generated/wspace-types';\nimport { useBotlit } from '../providers/BotlitProvider';\nimport type { BaseFilter } from '../types';\nimport { buildMutationInput, fieldsOf, type GraphQLInput } from './internal/mutationInput';\nimport {\n useWorkspaceAllPagesQuery,\n useWorkspacePaginatedQuery,\n useWorkspaceQuery,\n type PaginatedQueryResult,\n type QueryResult,\n} from './internal/workspaceGateway';\n\nconst LIST_BOT_APPS_DOCUMENT = gql`\n query ListBotApps($filters: BotAppFilterInput, $pagination: PaginationInput) {\n listBotApps(filters: $filters, pagination: $pagination) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n welcomeMessage\n fallbackMessage\n workflowId\n executionCount\n lastExecutedAt\n tagIds\n tags\n createdAt\n updatedAt\n createdById\n updatedById\n workspaceId\n }\n }\n`;\n\nconst GET_BOT_APP_DOCUMENT = gql`\n query GetBotApp($id: ID!) {\n getBotApp(id: $id) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n welcomeMessage\n fallbackMessage\n workflowId\n executionCount\n lastExecutedAt\n tagIds\n tags\n createdAt\n updatedAt\n createdById\n updatedById\n workspaceId\n }\n }\n`;\n\nconst CREATE_BOT_APP_DOCUMENT = gql`\n mutation CreateBotApp($input: CreateBotAppInput!) {\n createBotApp(input: $input) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n workflowId\n tagIds\n tags\n createdAt\n updatedAt\n workspaceId\n }\n }\n`;\n\nconst UPDATE_BOT_APP_DOCUMENT = gql`\n mutation UpdateBotApp($id: ID!, $input: UpdateBotAppInput!) {\n updateBotApp(id: $id, input: $input) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n welcomeMessage\n fallbackMessage\n workflowId\n tagIds\n tags\n updatedAt\n updatedById\n workspaceId\n }\n }\n`;\n\nconst DELETE_BOT_APP_DOCUMENT = gql`\n mutation DeleteBotApp($id: ID!) {\n deleteBotApp(id: $id)\n }\n`;\n\ntype WorkspaceClient = ApolloClient;\n\nexport interface BotAppRecord {\n id: string;\n name: string;\n slug: string;\n description?: string | null;\n icon?: string | null;\n type: string;\n status: string;\n visibility?: string | null;\n routingStrategy?: string | null;\n defaultAgentId?: string | null;\n welcomeMessage?: string | null;\n fallbackMessage?: string | null;\n /** Bound FluidGrids workflow definition id — the bot's designed behaviour. */\n workflowId?: string | null;\n executionCount?: number | null;\n lastExecutedAt?: string | null;\n tagIds?: string[] | null;\n /** Entity-owned universal tag records (JSON). */\n tags?: unknown;\n createdAt?: string | null;\n updatedAt?: string | null;\n createdById?: string | null;\n updatedById?: string | null;\n workspaceId?: string | null;\n}\n\ninterface ListBotAppsData {\n listBotApps: BotAppRecord[];\n}\n\nconst LIST_PAGE_SIZE = 100;\nconst NO_BOTS: BotAppRecord[] = [];\n\ninterface GetBotAppData {\n getBotApp: BotAppRecord | null;\n}\n\ninterface CreateBotAppData {\n createBotApp: BotAppRecord;\n}\n\ninterface UpdateBotAppData {\n updateBotApp: BotAppRecord;\n}\n\ninterface DeleteBotAppData {\n deleteBotApp: boolean;\n}\n\ninterface BotMutationState<T> {\n data: T | undefined;\n loading: boolean;\n error: Error | undefined;\n}\n\ninterface CreateBotInput {\n workspaceId: string;\n name: string;\n slug?: string;\n type: string;\n routingStrategy?: string;\n visibility?: string;\n description?: string;\n icon?: string;\n}\n\ninterface UpdateBotInput {\n botId: string;\n input: GraphQLInput<UpdateBotAppInput>;\n}\n\nconst UPDATE_BOT_APP_FIELDS = fieldsOf<UpdateBotAppInput>({\n bucketId: true,\n context: true,\n defaultAgentId: true,\n description: true,\n fallbackMessage: true,\n icon: true,\n metadata: true,\n name: true,\n routingStrategy: true,\n slug: true,\n status: true,\n tagIds: true,\n tags: true,\n type: true,\n visibility: true,\n welcomeMessage: true,\n workflowId: true,\n});\n\nfunction getWorkspaceClient(client: unknown): WorkspaceClient {\n return client as WorkspaceClient;\n}\n\nfunction buildBotFilter(\n workspaceId: string | undefined,\n filter?: BaseFilter\n): Record<string, unknown> | undefined {\n if (!workspaceId && !filter) return undefined;\n\n return {\n workspaceId,\n search: filter?.search,\n status: filter?.status?.[0],\n visibility: filter?.visibility?.[0],\n bucketId: filter?.bucketId,\n };\n}\n\nexport const botKeys = {\n all: ['bots'] as const,\n lists: () => [...botKeys.all, 'list'] as const,\n list: (filter?: BaseFilter) => [...botKeys.lists(), filter] as const,\n details: () => [...botKeys.all, 'detail'] as const,\n detail: (id: string) => [...botKeys.details(), id] as const,\n};\n\nexport function useBots(filter?: BaseFilter): PaginatedQueryResult<BotAppRecord[]> {\n const { workspaceId } = useBotlit();\n\n const variables = useMemo(\n () => ({ filters: buildBotFilter(workspaceId, filter) }),\n [filter, workspaceId]\n );\n\n return useWorkspacePaginatedQuery<ListBotAppsData, BotAppRecord, BotAppRecord[]>({\n document: LIST_BOT_APPS_DOCUMENT,\n variables,\n pageSize: LIST_PAGE_SIZE,\n extractRows: (data) => data?.listBotApps ?? [],\n select: (rows) => rows,\n fallback: NO_BOTS,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load bots',\n });\n}\n\n/**\n * Every bot of the workspace, all pages. For pickers that must offer each bot\n * (a route can point at any of them), where `useBots` stops at one page.\n */\nexport function useAllBots(): QueryResult<BotAppRecord[]> {\n const { workspaceId } = useBotlit();\n const variables = useMemo(() => ({ filters: buildBotFilter(workspaceId) }), [workspaceId]);\n\n return useWorkspaceAllPagesQuery<ListBotAppsData, BotAppRecord, BotAppRecord[]>({\n document: LIST_BOT_APPS_DOCUMENT,\n variables,\n pageSize: LIST_PAGE_SIZE,\n extractRows: (data) => data?.listBotApps ?? [],\n select: (rows) => rows,\n fallback: NO_BOTS,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load bots',\n });\n}\n\n/**\n * Exact bot counts by status for the workspace (BOFF-12426). Unlike `useBots`\n * this is not capped at one page, so it is the source for dashboard totals.\n * `total` counts every status; the dashboard shows `total - archived`.\n */\nexport interface BotAppCounts {\n total: number;\n draft: number;\n active: number;\n paused: number;\n archived: number;\n}\n\ninterface BotAppCountsData {\n getBotAppCounts?: BotAppCounts | null;\n}\n\nconst GET_BOT_APP_COUNTS_DOCUMENT = gql`\n query GetBotAppCounts {\n getBotAppCounts {\n total\n draft\n active\n paused\n archived\n }\n }\n`;\n\nexport function useBotAppCounts(enabled = true): QueryResult<BotAppCounts | null> {\n const { workspaceId } = useBotlit();\n const variables = useMemo(() => ({}), []);\n\n return useWorkspaceQuery<BotAppCountsData, BotAppCounts | null>({\n document: GET_BOT_APP_COUNTS_DOCUMENT,\n variables,\n select: (data) => data?.getBotAppCounts ?? null,\n fallback: null,\n enabled: enabled && Boolean(workspaceId),\n errorMessage: 'Failed to load bot counts',\n });\n}\n\nexport function useBot(botId: string | undefined) {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [data, setData] = useState<BotAppRecord | null>(null);\n // Loading from the first render when there is a bot to read, so a page that\n // depends on the bot never acts on \"no bot yet\" for the frame before the read.\n const [loading, setLoading] = useState(Boolean(botId));\n const [error, setError] = useState<Error | undefined>();\n\n const refetch = useCallback(async () => {\n if (!botId) {\n setData(null);\n setLoading(false);\n return;\n }\n\n setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<GetBotAppData>({\n query: GET_BOT_APP_DOCUMENT,\n variables: { id: botId },\n fetchPolicy: 'network-only',\n });\n // Apollo v4 resolves (not rejects) with `result.error` set on GraphQL errors.\n // Without this a FORBIDDEN read looked like \"bot not found\" (BOFF-12436).\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw operationError instanceof Error ? operationError : new Error('Failed to load bot');\n }\n setData(result.data?.getBotApp ?? null);\n } catch (queryError) {\n setData(null);\n setError(queryError instanceof Error ? queryError : new Error('Failed to load bot'));\n } finally {\n setLoading(false);\n }\n }, [botId, client]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\nexport function useCreateBot() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<BotMutationState<BotAppRecord>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const createBot = useCallback(\n async (input: CreateBotInput) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<CreateBotAppData>({\n mutation: CREATE_BOT_APP_DOCUMENT,\n variables: { input },\n });\n\n const createdBot = result.data?.createBotApp;\n if (!createdBot) {\n throw new Error('Failed to create bot');\n }\n\n setState({ data: createdBot, loading: false, error: undefined });\n return createdBot;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error ? mutationError : new Error('Failed to create bot');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [createBot, state] as const;\n}\n\nexport function useUpdateBot() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<BotMutationState<BotAppRecord>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const updateBot = useCallback(\n async ({ botId, input }: UpdateBotInput) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<UpdateBotAppData>({\n mutation: UPDATE_BOT_APP_DOCUMENT,\n variables: { id: botId, input: buildMutationInput(input, UPDATE_BOT_APP_FIELDS) },\n });\n\n const updatedBot = result.data?.updateBotApp;\n if (!updatedBot) {\n throw new Error('Failed to update bot');\n }\n\n setState({ data: updatedBot, loading: false, error: undefined });\n return updatedBot;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error ? mutationError : new Error('Failed to update bot');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [updateBot, state] as const;\n}\n\nexport function useDeleteBot() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<BotMutationState<boolean>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const deleteBot = useCallback(\n async (botId: string) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<DeleteBotAppData>({\n mutation: DELETE_BOT_APP_DOCUMENT,\n variables: { id: botId },\n });\n\n const deleted = result.data?.deleteBotApp ?? false;\n setState({ data: deleted, loading: false, error: undefined });\n return deleted;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error ? mutationError : new Error('Failed to delete bot');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [deleteBot, state] as const;\n}\n"],"mappings":";;;;;;;AAgBA,IAAMA,IAAyB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6B5BC,IAAuB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6B1BC,IAA0B,CAAG;;;;;;;;;;;;;;;;;;;;;GAuB7BC,IAA0B,CAAG;;;;;;;;;;;;;;;;;;;;;;;GAyB7BC,IAA0B,CAAG;;;;GAuC7BC,IAAiB,KACjBC,IAA0B,CAAC,GAwC3BC,IAAwBC,EAA4B;CACxD,UAAU;CACV,SAAS;CACT,gBAAgB;CAChB,aAAa;CACb,iBAAiB;CACjB,MAAM;CACN,UAAU;CACV,MAAM;CACN,iBAAiB;CACjB,MAAM;CACN,QAAQ;CACR,QAAQ;CACR,MAAM;CACN,MAAM;CACN,YAAY;CACZ,gBAAgB;CAChB,YAAY;AACd,CAAC;AAED,SAASC,EAAmB,GAAkC;CAC5D,OAAOC;AACT;AAEA,SAASC,EACP,GACA,GACqC;CACrC,IAAKC,KAAgBC,GAErB,OAAO;EACL;EACA,QAAQA,GAAQ;EAChB,QAAQA,GAAQ,SAAS;EACzB,YAAYA,GAAQ,aAAa;EACjC,UAAUA,GAAQ;CACpB;AACF;AAUA,SAAgBC,EAAQ,GAA2D;CACjF,IAAM,EAAE,mBAAgBC,EAAU,GAE5BC,IAAYC,SACT,EAAE,SAASN,EAAeC,GAAaC,CAAM,EAAE,IACtD,CAACA,GAAQD,CAAW,CACtB;CAEA,OAAOM,EAA0E;EAC/E,UAAUlB;EACV;EACA,UAAUK;EACV,cAAc,MAASc,GAAM,eAAe,CAAC;EAC7C,SAAS,MAASC;EAClB,UAAUd;EACV,SAAS,EAAQM;EACjB,cAAc;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CACF,GACA,CAACxB,CAAM,CAGD,GAAWiC,CAAK;AAC1B"}
@@ -1,7 +1,7 @@
1
1
  import { CreateChannelConnectorInput, CreateChannelRouteInput, UpdateChannelConnectorInput, UpdateChannelRouteInput } from '../../generated/wspace-types';
2
2
  import { ChannelFilter } from '../types';
3
3
  import { GraphQLInput } from './internal/mutationInput';
4
- import { QueryResult } from './internal/workspaceGateway';
4
+ import { PaginatedQueryResult, QueryResult } from './internal/workspaceGateway';
5
5
  export interface ChannelConnectorRecord {
6
6
  id: string;
7
7
  name: string;
@@ -13,6 +13,9 @@ export interface ChannelConnectorRecord {
13
13
  credentialsRefId?: string | null;
14
14
  defaultPolicyBindings?: Record<string, unknown> | null;
15
15
  metadata?: Record<string, unknown> | null;
16
+ /** Inbound messages no live route answered (BOFF-12566). */
17
+ unroutedMessageCount: number;
18
+ lastUnroutedAt?: string | null;
16
19
  revision: number;
17
20
  tags: string[];
18
21
  createdAt: string;
@@ -26,9 +29,8 @@ export interface ChannelRouteRecord {
26
29
  appId: string;
27
30
  connectorId: string;
28
31
  locationId: string;
29
- formatPolicyId?: string | null;
30
- policyBindings?: Record<string, unknown> | null;
31
- routingOverrides?: Record<string, unknown> | null;
32
+ /** An inactive route is ignored by inbound routing (BOFF-12566). */
33
+ isActive: boolean;
32
34
  metadata?: Record<string, unknown> | null;
33
35
  revision: number;
34
36
  createdAt: string;
@@ -41,27 +43,19 @@ export interface UpdateChannelConnectorVariables {
41
43
  connectorId: string;
42
44
  input: GraphQLInput<UpdateChannelConnectorInput>;
43
45
  }
46
+ /**
47
+ * Route fields channel routing never applies. They are deprecated in the
48
+ * schema and the service refuses a value (BOFF-12567), so they are never sent.
49
+ */
50
+ type UnappliedRouteField = 'policyBindings' | 'formatPolicyId' | 'routingOverrides';
51
+ type SupportedCreateRouteInput = Omit<CreateChannelRouteInput, UnappliedRouteField>;
52
+ type SupportedUpdateRouteInput = Omit<UpdateChannelRouteInput, UnappliedRouteField>;
44
53
  /** `CreateChannelRouteInput` minus the `workspaceId` the hook supplies. */
45
- export type CreateChannelRouteVariables = Omit<GraphQLInput<CreateChannelRouteInput>, 'workspaceId'>;
54
+ export type CreateChannelRouteVariables = Omit<GraphQLInput<SupportedCreateRouteInput>, 'workspaceId'>;
46
55
  export interface UpdateChannelRouteVariables {
47
56
  routeId: string;
48
- input: GraphQLInput<UpdateChannelRouteInput>;
49
- }
50
- /**
51
- * Web-widget appearance settings.
52
- *
53
- * `ChannelConnector` has no widget column — the settings live under
54
- * `metadata.webWidget`, which is where the connector form writes them.
55
- */
56
- export interface ChannelWidgetConfig {
57
- allowedOrigins: string[];
58
- primaryColor: string;
59
- fontFamily: string;
60
- starterPrompts: string[];
57
+ input: GraphQLInput<SupportedUpdateRouteInput>;
61
58
  }
62
- export declare const WIDGET_METADATA_KEY = "webWidget";
63
- /** Reads the widget settings back, or `undefined` when none were saved. */
64
- export declare function readWidgetConfig(connector: Pick<ChannelConnectorRecord, 'metadata'>): ChannelWidgetConfig | undefined;
65
59
  /** Reads a display label the UI stashed on the route's free-form metadata. */
66
60
  export declare function routeMetadataString(route: Pick<ChannelRouteRecord, 'metadata'>, key: string): string | undefined;
67
61
  export declare const channelKeys: {
@@ -73,7 +67,12 @@ export declare const channelKeys: {
73
67
  routeList: (connectorId?: string) => readonly ["channels", "routes", "list", string | undefined];
74
68
  routeDetail: (id: string) => readonly ["channels", "routes", "detail", string];
75
69
  };
76
- export declare function useChannelConnectors(filter?: ChannelFilter): QueryResult<ChannelConnectorRecord[]>;
70
+ /**
71
+ * Connectors of the workspace, one page at a time (BOFF-12569): `loadMore`
72
+ * reaches every row past the first page. Search, type, status and bucket
73
+ * filters are applied by the service.
74
+ */
75
+ export declare function useChannelConnectors(filter?: ChannelFilter): PaginatedQueryResult<ChannelConnectorRecord[]>;
77
76
  export declare function useChannelConnector(connectorId: string | undefined): QueryResult<ChannelConnectorRecord | null>;
78
77
  /**
79
78
  * Every connector of the workspace, all pages (BOFF-15360). For pickers that
@@ -89,7 +88,33 @@ export declare function useFindChannelConnector(): (channelId: string) => Promis
89
88
  export declare function useCreateChannelConnector(): readonly [(input: CreateChannelConnectorVariables) => Promise<ChannelConnectorRecord>, import('./internal/workspaceGateway').MutationState<ChannelConnectorRecord>];
90
89
  export declare function useUpdateChannelConnector(): readonly [(input: UpdateChannelConnectorVariables) => Promise<ChannelConnectorRecord>, import('./internal/workspaceGateway').MutationState<ChannelConnectorRecord>];
91
90
  export declare function useDeleteChannelConnector(): readonly [(input: string) => Promise<boolean>, import('./internal/workspaceGateway').MutationState<boolean>];
92
- export declare function useChannelRoutes(connectorId?: string): QueryResult<ChannelRouteRecord[]>;
91
+ export interface ChannelRouteListFilter {
92
+ connectorId?: string;
93
+ /** Only routes that are on (true) or off (false); all when undefined. */
94
+ isActive?: boolean;
95
+ }
96
+ /**
97
+ * Routes of the workspace (optionally of one connector), one page at a time
98
+ * (BOFF-12569): `loadMore` reaches every row past the first page.
99
+ */
100
+ export declare function useChannelRoutes(filter?: ChannelRouteListFilter): PaginatedQueryResult<ChannelRouteRecord[]>;
101
+ /**
102
+ * Every route of the workspace (or of one connector), all pages. For derived
103
+ * figures that must not stop at the first page, such as route counts.
104
+ */
105
+ export declare function useAllChannelRoutes(connectorId?: string): QueryResult<ChannelRouteRecord[]>;
106
+ export interface ChannelOverview {
107
+ connectorCount: number;
108
+ activeConnectorCount: number;
109
+ routeCount: number;
110
+ activeRouteCount: number;
111
+ unroutedMessageCount: number;
112
+ }
113
+ /**
114
+ * The workspace's real channel totals from the service (BOFF-12569), so tab
115
+ * counts and "Active routes" never depend on how many rows were loaded.
116
+ */
117
+ export declare function useChannelOverview(): QueryResult<ChannelOverview | null>;
93
118
  /** Routes bound to a specific bot app (Bot Detail → Channels tab). */
94
119
  /**
95
120
  * Every route of one bot, all pages: the Channels tab derives which
@@ -100,3 +125,4 @@ export declare function useChannelRoute(routeId: string | undefined): QueryResul
100
125
  export declare function useCreateChannelRoute(): readonly [(input: CreateChannelRouteVariables) => Promise<ChannelRouteRecord>, import('./internal/workspaceGateway').MutationState<ChannelRouteRecord>];
101
126
  export declare function useUpdateChannelRoute(): readonly [(input: UpdateChannelRouteVariables) => Promise<ChannelRouteRecord>, import('./internal/workspaceGateway').MutationState<ChannelRouteRecord>];
102
127
  export declare function useDeleteChannelRoute(): readonly [(input: string) => Promise<boolean>, import('./internal/workspaceGateway').MutationState<boolean>];
128
+ export {};
@@ -1,9 +1,9 @@
1
- import { CreateChannelConnectorDocument as e, CreateChannelRouteDocument as t, DeleteChannelConnectorDocument as n, DeleteChannelRouteDocument as r, GetChannelConnectorDocument as i, ListChannelConnectorsDocument as a, ListChannelRoutesDocument as o, UpdateChannelConnectorDocument as s } from "../../generated/wspace-operations.js";
2
- import { buildMutationInput as c, fieldsOf as l } from "./internal/mutationInput.js";
3
- import { useWorkspaceAllPagesQuery as u, useWorkspaceClient as d, useWorkspaceId as f, useWorkspaceMutation as p, useWorkspaceQuery as m } from "./internal/workspaceGateway.js";
4
- import { useCallback as h, useMemo as g } from "react";
1
+ import { ChannelOverviewDocument as e, CreateChannelConnectorDocument as t, CreateChannelRouteDocument as n, DeleteChannelConnectorDocument as r, DeleteChannelRouteDocument as i, GetChannelConnectorDocument as a, ListChannelConnectorsDocument as o, ListChannelRoutesDocument as s, UpdateChannelConnectorDocument as c, UpdateChannelRouteDocument as l } from "../../generated/wspace-operations.js";
2
+ import { buildMutationInput as u, fieldsOf as d } from "./internal/mutationInput.js";
3
+ import { useWorkspaceAllPagesQuery as f, useWorkspaceClient as p, useWorkspaceId as m, useWorkspaceMutation as h, useWorkspacePaginatedQuery as g, useWorkspaceQuery as _ } from "./internal/workspaceGateway.js";
4
+ import { useCallback as v, useMemo as y } from "react";
5
5
  // src/botlit/hooks/useChannels.ts
6
- var _ = 100, v = l({
6
+ var b = 100, x = d({
7
7
  bucketId: !0,
8
8
  credentialsRefId: !0,
9
9
  defaultPolicyBindings: !0,
@@ -15,7 +15,7 @@ var _ = 100, v = l({
15
15
  type: !0,
16
16
  visibility: !0,
17
17
  workspaceId: !0
18
- }), y = l({
18
+ }), S = d({
19
19
  bucketId: !0,
20
20
  credentialsRefId: !0,
21
21
  defaultPolicyBindings: !0,
@@ -25,221 +25,227 @@ var _ = 100, v = l({
25
25
  status: !0,
26
26
  tags: !0,
27
27
  visibility: !0
28
- }), b = l({
28
+ }), C = d({
29
29
  appId: !0,
30
30
  connectorId: !0,
31
- formatPolicyId: !0,
31
+ isActive: !0,
32
32
  locationId: !0,
33
33
  metadata: !0,
34
- policyBindings: !0,
35
- routingOverrides: !0,
36
34
  workspaceId: !0
37
- });
38
- l({
35
+ }), w = d({
39
36
  appId: !0,
40
- formatPolicyId: !0,
37
+ isActive: !0,
41
38
  locationId: !0,
42
- metadata: !0,
43
- policyBindings: !0,
44
- routingOverrides: !0
45
- });
46
- var x = [], S = [];
47
- function C(e) {
48
- return e?.listChannelConnectors ?? x;
49
- }
50
- function w(e) {
51
- return e?.getChannelConnector ?? null;
52
- }
53
- function T(e) {
54
- return e?.listChannelRoutes ?? S;
55
- }
56
- var E = "webWidget", D = {
57
- allowedOrigins: [],
58
- primaryColor: "#3b82f6",
59
- fontFamily: "Inter, sans-serif",
60
- starterPrompts: []
61
- };
62
- function O(e) {
63
- let t = e.metadata?.[E];
64
- if (typeof t != "object" || !t || Array.isArray(t)) return;
65
- let n = t;
66
- return {
67
- allowedOrigins: k(n.allowedOrigins),
68
- primaryColor: typeof n.primaryColor == "string" ? n.primaryColor : D.primaryColor,
69
- fontFamily: typeof n.fontFamily == "string" ? n.fontFamily : D.fontFamily,
70
- starterPrompts: k(n.starterPrompts)
71
- };
72
- }
39
+ metadata: !0
40
+ }), T = [], E = [], D = (e) => e, O = (e) => e;
73
41
  function k(e) {
74
- return Array.isArray(e) ? e.filter((e) => typeof e == "string") : [];
42
+ return e?.listChannelConnectors ?? T;
75
43
  }
76
- function A(e, t) {
44
+ function A(e) {
45
+ return e?.getChannelConnector ?? null;
46
+ }
47
+ function j(e, t) {
77
48
  let n = e.metadata?.[t];
78
49
  return typeof n == "string" ? n : void 0;
79
50
  }
80
- function j(e) {
81
- let t = f(), n = e?.search, r = e?.type?.[0], i = e?.status?.[0], o = e?.bucketId, s = g(() => ({
82
- filters: {
83
- workspaceId: t,
84
- search: n || void 0,
85
- type: r,
86
- status: i,
87
- bucketId: o
88
- },
89
- pagination: {
90
- limit: _,
91
- offset: 0
92
- }
93
- }), [
51
+ function M(e) {
52
+ let t = m(), n = e?.search, r = e?.type?.[0], i = e?.status?.[0], a = e?.bucketId, s = y(() => ({ filters: {
53
+ workspaceId: t,
54
+ search: n || void 0,
55
+ type: r,
56
+ status: i,
57
+ bucketId: a
58
+ } }), [
94
59
  t,
95
60
  n,
96
61
  r,
97
62
  i,
98
- o
63
+ a
99
64
  ]);
100
- return m({
101
- document: a,
65
+ return g({
66
+ document: o,
102
67
  variables: s,
103
- select: C,
104
- fallback: x,
68
+ pageSize: b,
69
+ extractRows: (e) => e?.listChannelConnectors ?? T,
70
+ select: D,
71
+ fallback: T,
105
72
  enabled: !!t,
106
73
  errorMessage: "Failed to load channel connectors"
107
74
  });
108
75
  }
109
- function M(e) {
110
- let t = g(() => ({ id: e ?? "" }), [e]);
111
- return m({
112
- document: i,
76
+ function N(e) {
77
+ let t = y(() => ({ id: e ?? "" }), [e]);
78
+ return _({
79
+ document: a,
113
80
  variables: t,
114
- select: w,
81
+ select: A,
115
82
  fallback: null,
116
83
  enabled: !!e,
117
84
  errorMessage: "Failed to load channel connector"
118
85
  });
119
86
  }
120
- var N = (e) => e, P = (e) => e;
121
- function F() {
122
- let e = f(), t = g(() => ({ filters: { workspaceId: e } }), [e]);
123
- return u({
124
- document: a,
87
+ function P() {
88
+ let e = m(), t = y(() => ({ filters: { workspaceId: e } }), [e]);
89
+ return f({
90
+ document: o,
125
91
  variables: t,
126
- pageSize: _,
127
- extractRows: (e) => e?.listChannelConnectors ?? x,
128
- select: N,
129
- fallback: x,
92
+ pageSize: b,
93
+ extractRows: (e) => e?.listChannelConnectors ?? T,
94
+ select: D,
95
+ fallback: T,
130
96
  enabled: !!e,
131
97
  errorMessage: "Failed to load channel connectors"
132
98
  });
133
99
  }
134
- function I() {
135
- let e = d(), t = f();
136
- return h(async (n) => {
137
- for (let r = 0;; r += _) {
100
+ function F() {
101
+ let e = p(), t = m();
102
+ return v(async (n) => {
103
+ for (let r = 0;; r += b) {
138
104
  let i = await e.query({
139
- query: a,
105
+ query: o,
140
106
  variables: {
141
107
  filters: { workspaceId: t },
142
108
  pagination: {
143
- limit: _,
109
+ limit: b,
144
110
  offset: r
145
111
  }
146
112
  },
147
113
  fetchPolicy: "network-only"
148
- }), o = i.error;
149
- if (o != null) throw o;
150
- let s = C(i.data ?? void 0), c = s.find((e) => e.credentialsRefId === n);
114
+ }), a = i.error;
115
+ if (a != null) throw a;
116
+ let s = k(i.data ?? void 0), c = s.find((e) => e.credentialsRefId === n);
151
117
  if (c) return c;
152
- if (s.length < _) return null;
118
+ if (s.length < b) return null;
153
119
  }
154
120
  }, [e, t]);
155
121
  }
156
- function L() {
157
- let t = f(), n = h((e) => ({ input: c({
158
- ...e,
159
- workspaceId: t
160
- }, v) }), [t]);
161
- return p({
162
- document: e,
122
+ function I() {
123
+ let e = m(), n = v((t) => ({ input: u({
124
+ ...t,
125
+ workspaceId: e
126
+ }, x) }), [e]);
127
+ return h({
128
+ document: t,
163
129
  variables: n,
164
130
  select: (e) => e?.createChannelConnector,
165
131
  errorMessage: "Failed to create channel connector"
166
132
  });
167
133
  }
168
- function R() {
169
- return p({
170
- document: s,
134
+ function L() {
135
+ return h({
136
+ document: c,
171
137
  variables: ({ connectorId: e, input: t }) => ({
172
138
  id: e,
173
- input: c(t, y)
139
+ input: u(t, S)
174
140
  }),
175
141
  select: (e) => e?.updateChannelConnector,
176
142
  errorMessage: "Failed to update channel connector"
177
143
  });
178
144
  }
179
- function z() {
180
- return p({
181
- document: n,
145
+ function R() {
146
+ return h({
147
+ document: r,
182
148
  variables: (e) => ({ id: e }),
183
149
  select: (e) => e?.deleteChannelConnector,
184
150
  errorMessage: "Failed to delete channel connector"
185
151
  });
186
152
  }
153
+ function z(e) {
154
+ let t = m(), n = e?.connectorId, r = e?.isActive, i = y(() => ({ filters: {
155
+ workspaceId: t,
156
+ connectorId: n || void 0,
157
+ isActive: r
158
+ } }), [
159
+ t,
160
+ n,
161
+ r
162
+ ]);
163
+ return g({
164
+ document: s,
165
+ variables: i,
166
+ pageSize: b,
167
+ extractRows: (e) => e?.listChannelRoutes ?? E,
168
+ select: O,
169
+ fallback: E,
170
+ enabled: !!t,
171
+ errorMessage: "Failed to load channel routes"
172
+ });
173
+ }
187
174
  function B(e) {
188
- let t = f(), n = g(() => ({
189
- filters: {
190
- workspaceId: t,
191
- connectorId: e || void 0
192
- },
193
- pagination: {
194
- limit: _,
195
- offset: 0
196
- }
197
- }), [t, e]);
198
- return m({
199
- document: o,
175
+ let t = m(), n = y(() => ({ filters: {
176
+ workspaceId: t,
177
+ connectorId: e || void 0
178
+ } }), [t, e]);
179
+ return f({
180
+ document: s,
200
181
  variables: n,
201
- select: T,
202
- fallback: S,
182
+ pageSize: b,
183
+ extractRows: (e) => e?.listChannelRoutes ?? E,
184
+ select: O,
185
+ fallback: E,
203
186
  enabled: !!t,
204
187
  errorMessage: "Failed to load channel routes"
205
188
  });
206
189
  }
207
- function V(e) {
208
- let t = f(), n = g(() => ({ filters: {
190
+ var V = null;
191
+ function H() {
192
+ let t = m(), n = y(() => ({ workspaceId: t }), [t]);
193
+ return _({
194
+ document: e,
195
+ variables: n,
196
+ select: (e) => e?.channelOverview ?? null,
197
+ fallback: V,
198
+ enabled: !!t,
199
+ errorMessage: "Failed to load channel totals"
200
+ });
201
+ }
202
+ function U(e) {
203
+ let t = m(), n = y(() => ({ filters: {
209
204
  workspaceId: t,
210
205
  appId: e
211
206
  } }), [t, e]);
212
- return u({
213
- document: o,
207
+ return f({
208
+ document: s,
214
209
  variables: n,
215
- pageSize: _,
216
- extractRows: (e) => e?.listChannelRoutes ?? S,
217
- select: P,
218
- fallback: S,
210
+ pageSize: b,
211
+ extractRows: (e) => e?.listChannelRoutes ?? E,
212
+ select: O,
213
+ fallback: E,
219
214
  enabled: !!t && !!e,
220
215
  errorMessage: "Failed to load channel routes for this bot"
221
216
  });
222
217
  }
223
- function H() {
224
- let e = f(), n = h((t) => ({ input: c({
218
+ function W() {
219
+ let e = m(), t = v((t) => ({ input: u({
225
220
  ...t,
226
221
  workspaceId: e
227
- }, b) }), [e]);
228
- return p({
229
- document: t,
230
- variables: n,
222
+ }, C) }), [e]);
223
+ return h({
224
+ document: n,
225
+ variables: t,
231
226
  select: (e) => e?.createChannelRoute,
232
227
  errorMessage: "Failed to create channel route"
233
228
  });
234
229
  }
235
- function U() {
236
- return p({
237
- document: r,
230
+ function G() {
231
+ return h({
232
+ document: l,
233
+ variables: ({ routeId: e, input: t }) => ({
234
+ id: e,
235
+ input: u(t, w)
236
+ }),
237
+ select: (e) => e?.updateChannelRoute,
238
+ errorMessage: "Failed to update channel route"
239
+ });
240
+ }
241
+ function K() {
242
+ return h({
243
+ document: i,
238
244
  variables: (e) => ({ id: e }),
239
245
  select: (e) => e?.deleteChannelRoute,
240
246
  errorMessage: "Failed to delete channel route"
241
247
  });
242
248
  }
243
- export { E as WIDGET_METADATA_KEY, O as readWidgetConfig, A as routeMetadataString, F as useAllChannelConnectors, V as useBotChannelRoutes, M as useChannelConnector, j as useChannelConnectors, B as useChannelRoutes, L as useCreateChannelConnector, H as useCreateChannelRoute, z as useDeleteChannelConnector, U as useDeleteChannelRoute, I as useFindChannelConnector, R as useUpdateChannelConnector };
249
+ export { j as routeMetadataString, P as useAllChannelConnectors, B as useAllChannelRoutes, U as useBotChannelRoutes, N as useChannelConnector, M as useChannelConnectors, H as useChannelOverview, z as useChannelRoutes, I as useCreateChannelConnector, W as useCreateChannelRoute, R as useDeleteChannelConnector, K as useDeleteChannelRoute, F as useFindChannelConnector, L as useUpdateChannelConnector, G as useUpdateChannelRoute };
244
250
 
245
251
  //# sourceMappingURL=useChannels.js.map