@burdenoff/microfe-botmanor 2026.1115.2 → 2026.1116.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 (39) 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/useAgents.d.ts +24 -3
  11. package/dist/botlit/hooks/useAgents.js +158 -109
  12. package/dist/botlit/hooks/useAgents.js.map +1 -1
  13. package/dist/botlit/hooks/useBotAgents.d.ts +23 -0
  14. package/dist/botlit/hooks/useBotAgents.js +69 -0
  15. package/dist/botlit/hooks/useBotAgents.js.map +1 -0
  16. package/dist/botlit/hooks/useBots.js +2 -2
  17. package/dist/botlit/hooks/useBots.js.map +1 -1
  18. package/dist/botlit/hooks/useKnowledgeBases.js +40 -44
  19. package/dist/botlit/hooks/useKnowledgeBases.js.map +1 -1
  20. package/dist/botlit/hooks/useMCPServers.js +53 -57
  21. package/dist/botlit/hooks/useMCPServers.js.map +1 -1
  22. package/dist/botlit/pages/AgentBuilderPage.js +832 -425
  23. package/dist/botlit/pages/AgentBuilderPage.js.map +1 -1
  24. package/dist/botlit/pages/AgentDetailPage.js +407 -325
  25. package/dist/botlit/pages/AgentDetailPage.js.map +1 -1
  26. package/dist/botlit/pages/AgentsListPage.js +487 -291
  27. package/dist/botlit/pages/AgentsListPage.js.map +1 -1
  28. package/dist/botlit/types/index.d.ts +4 -1
  29. package/dist/botlit/utils/agentDelete.d.ts +5 -0
  30. package/dist/botlit/utils/agentDelete.js +15 -0
  31. package/dist/botlit/utils/agentDelete.js.map +1 -0
  32. package/dist/botlit/utils/agentSettings.d.ts +77 -0
  33. package/dist/botlit/utils/agentSettings.js +78 -0
  34. package/dist/botlit/utils/agentSettings.js.map +1 -0
  35. package/dist/generated/wspace-operations.d.ts +4 -0
  36. package/dist/generated/wspace-operations.js.map +1 -1
  37. package/dist/generated/wspace-types.d.ts +43 -0
  38. package/dist/generated/wspace-types.js.map +1 -1
  39. package/package.json +1 -1
@@ -0,0 +1,69 @@
1
+ import { useAllPagesQuery as e } from "./internal/allPages.js";
2
+ import { useWorkspaceId as t, useWorkspaceMutation as n } from "./internal/workspaceGateway.js";
3
+ import { useMemo as r } from "react";
4
+ import { gql as i } from "@apollo/client";
5
+ // src/botlit/hooks/useBotAgents.ts
6
+ var a = i`
7
+ query ListBotAgentLinks($filters: AppAgentFilterInput, $pagination: PaginationInput) {
8
+ listAppAgents(filters: $filters, pagination: $pagination) {
9
+ id
10
+ appId
11
+ agentId
12
+ isActive
13
+ priority
14
+ }
15
+ }
16
+ `, o = i`
17
+ mutation LinkAgentToBot($input: CreateAppAgentInput!) {
18
+ createAppAgent(input: $input) {
19
+ id
20
+ appId
21
+ agentId
22
+ isActive
23
+ priority
24
+ }
25
+ }
26
+ `, s = i`
27
+ mutation UnlinkAgentFromBot($id: ID!) {
28
+ deleteAppAgent(id: $id)
29
+ }
30
+ `, c = 100, l = [];
31
+ function u(n) {
32
+ let i = t(), o = r(() => ({ filters: {
33
+ appId: n,
34
+ workspaceId: i
35
+ } }), [n, i]);
36
+ return e({
37
+ document: a,
38
+ variables: o,
39
+ pageSize: c,
40
+ extractRows: (e) => e?.listAppAgents ?? l,
41
+ fallback: l,
42
+ enabled: !!(n && i),
43
+ errorMessage: "Failed to load the agents linked to this bot"
44
+ });
45
+ }
46
+ function d() {
47
+ let e = t();
48
+ return n({
49
+ document: o,
50
+ variables: ({ botId: t, agentId: n }) => ({ input: {
51
+ appId: t,
52
+ agentId: n,
53
+ workspaceId: e
54
+ } }),
55
+ select: (e) => e?.createAppAgent ?? void 0,
56
+ errorMessage: "Failed to link the agent to the bot"
57
+ });
58
+ }
59
+ function f() {
60
+ return n({
61
+ document: s,
62
+ variables: (e) => ({ id: e }),
63
+ select: (e) => e?.deleteAppAgent ?? void 0,
64
+ errorMessage: "Failed to remove the agent from the bot"
65
+ });
66
+ }
67
+ export { u as useBotAgentLinks, d as useLinkAgentToBot, f as useUnlinkAgentFromBot };
68
+
69
+ //# sourceMappingURL=useBotAgents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBotAgents.js","names":["LIST_APP_AGENTS_DOCUMENT","CREATE_APP_AGENT_DOCUMENT","DELETE_APP_AGENT_DOCUMENT","LINK_PAGE_SIZE","NO_LINKS","useBotAgentLinks","workspaceId","useWorkspaceId","variables","useMemo","botId","useAllPagesQuery","data","useLinkAgentToBot","useWorkspaceMutation","useUnlinkAgentFromBot","linkId"],"sources":["../../../src/botlit/hooks/useBotAgents.ts"],"sourcesContent":["/**\n * Bot-agent links (BOFF-12452)\n * @module botlit/hooks\n *\n * A bot reaches its agents through `AppAgent` links plus an optional default\n * agent. These hooks list a bot's links and add or remove one, so the bot's\n * Agents page can show only that bot's agents and a create-from-bot flow can\n * link what it creates. Setting the default agent is `useUpdateBot`.\n */\n\nimport { gql } from '@apollo/client';\nimport { useMemo } from 'react';\n\nimport { useAllPagesQuery } from './internal/allPages';\nimport {\n useWorkspaceId,\n useWorkspaceMutation,\n type QueryResult,\n} from './internal/workspaceGateway';\n\nexport interface BotAgentLink {\n id: string;\n appId: string;\n agentId: string;\n isActive: boolean;\n priority: number;\n}\n\ninterface ListAppAgentsData {\n listAppAgents?: BotAgentLink[] | null;\n}\n\ninterface CreateAppAgentData {\n createAppAgent?: BotAgentLink | null;\n}\n\ninterface DeleteAppAgentData {\n deleteAppAgent?: boolean | null;\n}\n\nconst LIST_APP_AGENTS_DOCUMENT = gql`\n query ListBotAgentLinks($filters: AppAgentFilterInput, $pagination: PaginationInput) {\n listAppAgents(filters: $filters, pagination: $pagination) {\n id\n appId\n agentId\n isActive\n priority\n }\n }\n`;\n\nconst CREATE_APP_AGENT_DOCUMENT = gql`\n mutation LinkAgentToBot($input: CreateAppAgentInput!) {\n createAppAgent(input: $input) {\n id\n appId\n agentId\n isActive\n priority\n }\n }\n`;\n\nconst DELETE_APP_AGENT_DOCUMENT = gql`\n mutation UnlinkAgentFromBot($id: ID!) {\n deleteAppAgent(id: $id)\n }\n`;\n\nconst LINK_PAGE_SIZE = 100;\nconst NO_LINKS: BotAgentLink[] = [];\n\n/**\n * Every agent linked to one bot. Disabled until there is a bot and a workspace.\n * It reads all pages (a bot can have more links than one page holds), and stays\n * `loading` until the last one is in, so a page never derives its list from a\n * partial set of links.\n */\nexport function useBotAgentLinks(botId: string | undefined): QueryResult<BotAgentLink[]> {\n const workspaceId = useWorkspaceId();\n const variables = useMemo(\n () => ({ filters: { appId: botId, workspaceId } }),\n [botId, workspaceId]\n );\n\n return useAllPagesQuery<ListAppAgentsData, BotAgentLink>({\n document: LIST_APP_AGENTS_DOCUMENT,\n variables,\n pageSize: LINK_PAGE_SIZE,\n extractRows: (data) => data?.listAppAgents ?? NO_LINKS,\n fallback: NO_LINKS,\n enabled: Boolean(botId && workspaceId),\n errorMessage: 'Failed to load the agents linked to this bot',\n });\n}\n\nexport interface LinkAgentInput {\n botId: string;\n agentId: string;\n}\n\n/** Links an agent to a bot. */\nexport function useLinkAgentToBot() {\n const workspaceId = useWorkspaceId();\n return useWorkspaceMutation<CreateAppAgentData, LinkAgentInput, BotAgentLink>({\n document: CREATE_APP_AGENT_DOCUMENT,\n variables: ({ botId, agentId }) => ({ input: { appId: botId, agentId, workspaceId } }),\n select: (data) => data?.createAppAgent ?? undefined,\n errorMessage: 'Failed to link the agent to the bot',\n });\n}\n\n/** Removes a link (the agent itself is untouched). */\nexport function useUnlinkAgentFromBot() {\n return useWorkspaceMutation<DeleteAppAgentData, string, boolean>({\n document: DELETE_APP_AGENT_DOCUMENT,\n variables: (linkId) => ({ id: linkId }),\n select: (data) => data?.deleteAppAgent ?? undefined,\n errorMessage: 'Failed to remove the agent from the bot',\n });\n}\n"],"mappings":";;;;;AAwCA,IAAMA,IAA2B,CAAG;;;;;;;;;;GAY9BC,IAA4B,CAAG;;;;;;;;;;GAY/BC,IAA4B,CAAG;;;;GAM/BC,IAAiB,KACjBC,IAA2B,CAAC;AAQlC,SAAgBC,EAAiB,GAAwD;CACvF,IAAMC,IAAcC,EAAe,GAC7BC,IAAYC,SACT,EAAE,SAAS;EAAE,OAAOC;EAAO;CAAY,EAAE,IAChD,CAACA,GAAOJ,CAAW,CACrB;CAEA,OAAOK,EAAkD;EACvD,UAAUX;EACV;EACA,UAAUG;EACV,cAAc,MAASS,GAAM,iBAAiBR;EAC9C,UAAUA;EACV,SAAS,GAAQM,KAASJ;EAC1B,cAAc;CAChB,CAAC;AACH;AAQA,SAAgBO,IAAoB;CAClC,IAAMP,IAAcC,EAAe;CACnC,OAAOO,EAAuE;EAC5E,UAAUb;EACV,YAAY,EAAE,UAAO,kBAAe,EAAE,OAAO;GAAE,OAAOS;GAAO;GAAS;EAAY,EAAE;EACpF,SAAS,MAASE,GAAM,kBAAkB,KAAA;EAC1C,cAAc;CAChB,CAAC;AACH;AAGA,SAAgBG,IAAwB;CACtC,OAAOD,EAA0D;EAC/D,UAAUZ;EACV,YAAY,OAAY,EAAE,IAAIc,EAAO;EACrC,SAAS,MAASJ,GAAM,kBAAkB,KAAA;EAC1C,cAAc;CAChB,CAAC;AACH"}
@@ -170,8 +170,8 @@ function C(t = !0) {
170
170
  });
171
171
  }
172
172
  function w(e) {
173
- let t = y(u("workspace")), [n, r] = c(null), [i, s] = c(!1), [l, d] = c(), p = a(async () => {
174
- if (!e) r(null);
173
+ let t = y(u("workspace")), [n, r] = c(null), [i, s] = c(!!e), [l, d] = c(), p = a(async () => {
174
+ if (!e) r(null), s(!1);
175
175
  else {
176
176
  s(!0), d(void 0);
177
177
  try {
@@ -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","error","setError","refetch","useCallback","botId","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 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 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 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 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 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 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 const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n\n const refetch = useCallback(async () => {\n if (!botId) {\n setData(null);\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;;;;;;;;;;;;;;;;;;;;;;;;;;GA4B5BC,IAAuB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;GA4B1BC,IAA0B,CAAG;;;;;;;;;;;;;;;;;;;;GAsB7BC,IAA0B,CAAG;;;;;;;;;;;;;;;;;;;;;;GAwB7BC,IAA0B,CAAG;;;;GAqC7BC,IAAiB,KACjBC,IAA0B,CAAC,GAuC3BC,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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_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 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 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 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 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 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 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;;;;;;;;;;;;;;;;;;;;;;;;;;GA4B5BC,IAAuB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;GA4B1BC,IAA0B,CAAG;;;;;;;;;;;;;;;;;;;;GAsB7BC,IAA0B,CAAG;;;;;;;;;;;;;;;;;;;;;;GAwB7BC,IAA0B,CAAG;;;;GAqC7BC,IAAiB,KACjBC,IAA0B,CAAC,GAuC3BC,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;CAChB,CAAC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AAY,SAAS;IAAO,OAAO,KAAA;GAAU,CAAC,GACxDA;EACT,SAASF,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;AAEA,SAAgBQ,IAAe;CAC7B,IAAMvC,IAASD,EAAmBiB,EAAiB,WAAW,CAAC,GACzD,CAACe,GAAOC,KAAYd,EAAoC;EAC5D,MAAM,KAAA;EACN,SAAS;EACT,OAAO,KAAA;CACT,CAAC;CAwBD,OAAO,CAtBWO,EAChB,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,9 +1,10 @@
1
1
  import { CreateKnowledgeBaseDocument as e, GetKnowledgeBaseDocument as t, ListKnowledgeBasesDocument as n, ListKnowledgeDocumentsDocument as r, RebuildKnowledgeBaseIndexDocument as i, UpdateKnowledgeBaseDocument as a } from "../../generated/wspace-operations.js";
2
- import { buildMutationInput as o, fieldsOf as s } from "./internal/mutationInput.js";
3
- import { useWorkspaceId as c, useWorkspaceMutation as l, useWorkspaceQuery as u } from "./internal/workspaceGateway.js";
4
- import { useCallback as d, useMemo as f } from "react";
2
+ import { useAllPagesQuery as o } from "./internal/allPages.js";
3
+ import { buildMutationInput as s, fieldsOf as c } from "./internal/mutationInput.js";
4
+ import { useWorkspaceId as l, useWorkspaceMutation as u, useWorkspaceQuery as d } from "./internal/workspaceGateway.js";
5
+ import { useCallback as f, useMemo as p } from "react";
5
6
  // src/botlit/hooks/useKnowledgeBases.ts
6
- var p = 100, m = s({
7
+ var m = 100, h = c({
7
8
  chunkOverlap: !0,
8
9
  chunkSize: !0,
9
10
  chunkingStrategy: !0,
@@ -14,102 +15,97 @@ var p = 100, m = s({
14
15
  name: !0,
15
16
  vectorStoreDriver: !0,
16
17
  workspaceId: !0
17
- }), h = s({
18
+ }), g = c({
18
19
  chunkOverlap: !0,
19
20
  chunkSize: !0,
20
21
  chunkingStrategy: !0,
21
22
  description: !0,
22
23
  metadata: !0,
23
24
  name: !0
24
- }), g = [], _ = [];
25
- function v(e) {
26
- return e?.listKnowledgeBases ?? g;
27
- }
25
+ }), _ = [], v = [];
28
26
  function y(e) {
29
- return e?.getKnowledgeBase ?? null;
27
+ return e?.listKnowledgeBases ?? _;
30
28
  }
31
29
  function b(e) {
32
- return e?.listKnowledgeDocuments ?? _;
30
+ return e?.getKnowledgeBase ?? null;
33
31
  }
34
32
  function x(e) {
35
- let t = c(), r = e?.search, i = f(() => ({
36
- filters: {
37
- workspaceId: t,
38
- search: r || void 0
39
- },
40
- pagination: {
41
- limit: p,
42
- offset: 0
43
- }
44
- }), [t, r]);
45
- return u({
33
+ return e?.listKnowledgeDocuments ?? v;
34
+ }
35
+ function S(e) {
36
+ let t = l(), r = e?.search, i = p(() => ({ filters: {
37
+ workspaceId: t,
38
+ search: r || void 0
39
+ } }), [t, r]);
40
+ return o({
46
41
  document: n,
47
42
  variables: i,
48
- select: v,
49
- fallback: g,
43
+ pageSize: m,
44
+ extractRows: y,
45
+ fallback: _,
50
46
  enabled: !!t,
51
47
  errorMessage: "Failed to load knowledge bases"
52
48
  });
53
49
  }
54
- function S(e) {
55
- let n = f(() => ({ id: e ?? "" }), [e]);
56
- return u({
50
+ function C(e) {
51
+ let n = p(() => ({ id: e ?? "" }), [e]);
52
+ return d({
57
53
  document: t,
58
54
  variables: n,
59
- select: y,
55
+ select: b,
60
56
  fallback: null,
61
57
  enabled: !!e,
62
58
  errorMessage: "Failed to load knowledge base"
63
59
  });
64
60
  }
65
- function C(e) {
66
- let t = f(() => ({
61
+ function w(e) {
62
+ let t = p(() => ({
67
63
  knowledgeBaseId: e ?? "",
68
64
  pagination: {
69
- limit: p,
65
+ limit: m,
70
66
  offset: 0
71
67
  }
72
68
  }), [e]);
73
- return u({
69
+ return d({
74
70
  document: r,
75
71
  variables: t,
76
- select: b,
77
- fallback: _,
72
+ select: x,
73
+ fallback: v,
78
74
  enabled: !!e,
79
75
  errorMessage: "Failed to load knowledge documents"
80
76
  });
81
77
  }
82
- function w() {
83
- let t = c(), n = d((e) => ({ input: o({
78
+ function T() {
79
+ let t = l(), n = f((e) => ({ input: s({
84
80
  ...e,
85
81
  workspaceId: t
86
- }, m) }), [t]);
87
- return l({
82
+ }, h) }), [t]);
83
+ return u({
88
84
  document: e,
89
85
  variables: n,
90
86
  select: (e) => e?.createKnowledgeBase,
91
87
  errorMessage: "Failed to create knowledge base"
92
88
  });
93
89
  }
94
- function T() {
95
- return l({
90
+ function E() {
91
+ return u({
96
92
  document: a,
97
93
  variables: ({ kbId: e, input: t }) => ({
98
94
  id: e,
99
- input: o(t, h)
95
+ input: s(t, g)
100
96
  }),
101
97
  select: (e) => e?.updateKnowledgeBase,
102
98
  errorMessage: "Failed to update knowledge base"
103
99
  });
104
100
  }
105
- function E() {
106
- return l({
101
+ function D() {
102
+ return u({
107
103
  document: i,
108
104
  variables: (e) => ({ knowledgeBaseId: e }),
109
105
  select: (e) => e?.rebuildKnowledgeBaseIndex,
110
106
  errorMessage: "Failed to rebuild the knowledge base index"
111
107
  });
112
108
  }
113
- export { w as useCreateKnowledgeBase, S as useKnowledgeBase, x as useKnowledgeBases, C as useKnowledgeDocuments, E as useRebuildKnowledgeBaseIndex, T as useUpdateKnowledgeBase };
109
+ export { T as useCreateKnowledgeBase, C as useKnowledgeBase, S as useKnowledgeBases, w as useKnowledgeDocuments, D as useRebuildKnowledgeBaseIndex, E as useUpdateKnowledgeBase };
114
110
 
115
111
  //# sourceMappingURL=useKnowledgeBases.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useKnowledgeBases.js","names":["LIST_LIMIT","CREATE_KB_FIELDS","fieldsOf","UPDATE_KB_FIELDS","NO_KNOWLEDGE_BASES","NO_DOCUMENTS","selectKnowledgeBases","data","selectKnowledgeBase","selectDocuments","useKnowledgeBases","workspaceId","useWorkspaceId","search","filter","variables","useMemo","useWorkspaceQuery","ListKnowledgeBasesDocument","useKnowledgeBase","kbId","GetKnowledgeBaseDocument","useKnowledgeDocuments","ListKnowledgeDocumentsDocument","useCreateKnowledgeBase","useCallback","buildMutationInput","input","useWorkspaceMutation","CreateKnowledgeBaseDocument","useUpdateKnowledgeBase","UpdateKnowledgeBaseDocument","useRebuildKnowledgeBaseIndex","RebuildKnowledgeBaseIndexDocument"],"sources":["../../../src/botlit/hooks/useKnowledgeBases.ts"],"sourcesContent":["/**\n * Knowledge Bases Hooks\n * @module botlit/hooks\n *\n * Backed by the live `listKnowledgeBases` / `getKnowledgeBase` /\n * `listKnowledgeDocuments` operations and the create/update/delete mutations on\n * wspace-botlit-svc.\n */\n\nimport { useCallback, useMemo } from 'react';\nimport {\n CreateKnowledgeBaseDocument,\n DeleteKnowledgeBaseDocument,\n GetKnowledgeBaseDocument,\n ListKnowledgeBasesDocument,\n ListKnowledgeDocumentsDocument,\n RebuildKnowledgeBaseIndexDocument,\n UpdateKnowledgeBaseDocument,\n type CreateKnowledgeBaseMutation,\n type DeleteKnowledgeBaseMutation,\n type GetKnowledgeBaseQuery,\n type ListKnowledgeBasesQuery,\n type ListKnowledgeDocumentsQuery,\n type RebuildKnowledgeBaseIndexMutation,\n type UpdateKnowledgeBaseMutation,\n} from '../../generated/wspace-operations';\nimport type {\n CreateKnowledgeBaseInput,\n UpdateKnowledgeBaseInput,\n} from '../../generated/wspace-types';\nimport type { BaseFilter } from '../types';\nimport { buildMutationInput, fieldsOf, type GraphQLInput } from './internal/mutationInput';\nimport {\n useWorkspaceId,\n useWorkspaceMutation,\n useWorkspaceQuery,\n type QueryResult,\n} from './internal/workspaceGateway';\n\nconst LIST_LIMIT = 100;\n\nexport interface KnowledgeBaseRecord {\n id: string;\n name: string;\n description?: string | null;\n indexStatus: string;\n embeddingModel: string;\n embeddingDimensions: number;\n chunkingStrategy: string;\n chunkSize: number;\n chunkOverlap: number;\n totalDocuments: number;\n totalChunks: number;\n vectorCount: number;\n lastIndexedAt?: string | null;\n metadata?: Record<string, unknown> | null;\n createdAt: string;\n updatedAt: string;\n createdById: string;\n updatedById: string;\n workspaceId: string;\n}\n\nexport interface KnowledgeDocumentRecord {\n id: string;\n knowledgeBaseId: string;\n title: string;\n fileId: string;\n status: string;\n chunkCount: number;\n processingError?: string | null;\n processedAt?: string | null;\n addedAt: string;\n addedById: string;\n updatedAt: string;\n}\n\n/**\n * `CreateKnowledgeBaseInput` minus the `workspaceId` the hook supplies.\n * `embeddingModel`/`embeddingDimensions` are required by the service.\n */\nexport type CreateKnowledgeBaseVariables = Omit<\n GraphQLInput<CreateKnowledgeBaseInput>,\n 'workspaceId'\n>;\n\nexport interface UpdateKnowledgeBaseVariables {\n kbId: string;\n input: GraphQLInput<UpdateKnowledgeBaseInput>;\n}\n\nconst CREATE_KB_FIELDS = fieldsOf<CreateKnowledgeBaseInput>({\n chunkOverlap: true,\n chunkSize: true,\n chunkingStrategy: true,\n description: true,\n embeddingDimensions: true,\n embeddingModel: true,\n metadata: true,\n name: true,\n // Optional: the service picks the environment default when omitted.\n vectorStoreDriver: true,\n workspaceId: true,\n});\n\nconst UPDATE_KB_FIELDS = fieldsOf<UpdateKnowledgeBaseInput>({\n chunkOverlap: true,\n chunkSize: true,\n chunkingStrategy: true,\n description: true,\n metadata: true,\n name: true,\n});\n\nconst NO_KNOWLEDGE_BASES: KnowledgeBaseRecord[] = [];\nconst NO_DOCUMENTS: KnowledgeDocumentRecord[] = [];\n\nfunction selectKnowledgeBases(data: ListKnowledgeBasesQuery | undefined): KnowledgeBaseRecord[] {\n return data?.listKnowledgeBases ?? NO_KNOWLEDGE_BASES;\n}\n\nfunction selectKnowledgeBase(data: GetKnowledgeBaseQuery | undefined): KnowledgeBaseRecord | null {\n return data?.getKnowledgeBase ?? null;\n}\n\nfunction selectDocuments(data: ListKnowledgeDocumentsQuery | undefined): KnowledgeDocumentRecord[] {\n return data?.listKnowledgeDocuments ?? NO_DOCUMENTS;\n}\n\nexport const knowledgeBaseKeys = {\n all: ['knowledgeBases'] as const,\n lists: () => [...knowledgeBaseKeys.all, 'list'] as const,\n list: (filter?: BaseFilter) => [...knowledgeBaseKeys.lists(), filter] as const,\n details: () => [...knowledgeBaseKeys.all, 'detail'] as const,\n detail: (id: string) => [...knowledgeBaseKeys.details(), id] as const,\n documents: (kbId: string) => [...knowledgeBaseKeys.detail(kbId), 'documents'] as const,\n};\n\nexport function useKnowledgeBases(filter?: BaseFilter): QueryResult<KnowledgeBaseRecord[]> {\n const workspaceId = useWorkspaceId();\n const search = filter?.search;\n\n const variables = useMemo(\n () => ({\n filters: { workspaceId, search: search || undefined },\n pagination: { limit: LIST_LIMIT, offset: 0 },\n }),\n [workspaceId, search]\n );\n\n return useWorkspaceQuery<ListKnowledgeBasesQuery, KnowledgeBaseRecord[]>({\n document: ListKnowledgeBasesDocument,\n variables,\n select: selectKnowledgeBases,\n fallback: NO_KNOWLEDGE_BASES,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load knowledge bases',\n });\n}\n\nexport function useKnowledgeBase(\n kbId: string | undefined\n): QueryResult<KnowledgeBaseRecord | null> {\n const variables = useMemo(() => ({ id: kbId ?? '' }), [kbId]);\n\n return useWorkspaceQuery<GetKnowledgeBaseQuery, KnowledgeBaseRecord | null>({\n document: GetKnowledgeBaseDocument,\n variables,\n select: selectKnowledgeBase,\n fallback: null,\n enabled: Boolean(kbId),\n errorMessage: 'Failed to load knowledge base',\n });\n}\n\nexport function useKnowledgeDocuments(\n kbId: string | undefined\n): QueryResult<KnowledgeDocumentRecord[]> {\n const variables = useMemo(\n () => ({ knowledgeBaseId: kbId ?? '', pagination: { limit: LIST_LIMIT, offset: 0 } }),\n [kbId]\n );\n\n return useWorkspaceQuery<ListKnowledgeDocumentsQuery, KnowledgeDocumentRecord[]>({\n document: ListKnowledgeDocumentsDocument,\n variables,\n select: selectDocuments,\n fallback: NO_DOCUMENTS,\n enabled: Boolean(kbId),\n errorMessage: 'Failed to load knowledge documents',\n });\n}\n\nexport function useCreateKnowledgeBase() {\n const workspaceId = useWorkspaceId();\n\n const variables = useCallback(\n (input: CreateKnowledgeBaseVariables) => ({\n input: buildMutationInput({ ...input, workspaceId }, CREATE_KB_FIELDS),\n }),\n [workspaceId]\n );\n\n return useWorkspaceMutation<\n CreateKnowledgeBaseMutation,\n CreateKnowledgeBaseVariables,\n { id: string; name: string; workspaceId: string }\n >({\n document: CreateKnowledgeBaseDocument,\n variables,\n select: (data) => data?.createKnowledgeBase,\n errorMessage: 'Failed to create knowledge base',\n });\n}\n\nexport function useUpdateKnowledgeBase() {\n return useWorkspaceMutation<\n UpdateKnowledgeBaseMutation,\n UpdateKnowledgeBaseVariables,\n { id: string; name: string; indexStatus: string }\n >({\n document: UpdateKnowledgeBaseDocument,\n variables: ({ kbId, input }) => ({\n id: kbId,\n input: buildMutationInput(input, UPDATE_KB_FIELDS),\n }),\n select: (data) => data?.updateKnowledgeBase,\n errorMessage: 'Failed to update knowledge base',\n });\n}\n\n/** Re-indexes every document in the knowledge base (`rebuildKnowledgeBaseIndex`). */\nexport function useRebuildKnowledgeBaseIndex() {\n return useWorkspaceMutation<RebuildKnowledgeBaseIndexMutation, string, boolean>({\n document: RebuildKnowledgeBaseIndexDocument,\n variables: (kbId) => ({ knowledgeBaseId: kbId }),\n select: (data) => data?.rebuildKnowledgeBaseIndex,\n errorMessage: 'Failed to rebuild the knowledge base index',\n });\n}\n\nexport function useDeleteKnowledgeBase() {\n return useWorkspaceMutation<DeleteKnowledgeBaseMutation, string, boolean>({\n document: DeleteKnowledgeBaseDocument,\n variables: (kbId) => ({ id: kbId }),\n select: (data) => data?.deleteKnowledgeBase,\n errorMessage: 'Failed to delete knowledge base',\n });\n}\n"],"mappings":";;;;;AAuCA,IAAMA,IAAa,KAoDbC,IAAmBC,EAAmC;CAC1D,cAAc;CACd,WAAW;CACX,kBAAkB;CAClB,aAAa;CACb,qBAAqB;CACrB,gBAAgB;CAChB,UAAU;CACV,MAAM;CAEN,mBAAmB;CACnB,aAAa;AACf,CAAC,GAEKC,IAAmBD,EAAmC;CAC1D,cAAc;CACd,WAAW;CACX,kBAAkB;CAClB,aAAa;CACb,UAAU;CACV,MAAM;AACR,CAAC,GAEKE,IAA4C,CAAC,GAC7CC,IAA0C,CAAC;AAEjD,SAASC,EAAqB,GAAkE;CAC9F,OAAOC,GAAM,sBAAsBH;AACrC;AAEA,SAASI,EAAoB,GAAqE;CAChG,OAAOD,GAAM,oBAAoB;AACnC;AAEA,SAASE,EAAgB,GAA0E;CACjG,OAAOF,GAAM,0BAA0BF;AACzC;AAWA,SAAgBK,EAAkB,GAAyD;CACzF,IAAMC,IAAcC,EAAe,GAC7BC,IAASC,GAAQ,QAEjBC,IAAYC,SACT;EACL,SAAS;GAAE;GAAa,QAAQH,KAAU,KAAA;EAAU;EACpD,YAAY;GAAE,OAAOb;GAAY,QAAQ;EAAE;CAC7C,IACA,CAACW,GAAaE,CAAM,CACtB;CAEA,OAAOI,EAAkE;EACvE,UAAUC;EACV;EACA,QAAQZ;EACR,UAAUF;EACV,SAAS,EAAQO;EACjB,cAAc;CAChB,CAAC;AACH;AAEA,SAAgBQ,EACd,GACyC;CACzC,IAAMJ,IAAYC,SAAe,EAAE,IAAII,KAAQ,GAAG,IAAI,CAACA,CAAI,CAAC;CAE5D,OAAOH,EAAqE;EAC1E,UAAUI;EACV;EACA,QAAQb;EACR,UAAU;EACV,SAAS,EAAQY;EACjB,cAAc;CAChB,CAAC;AACH;AAEA,SAAgBE,EACd,GACwC;CACxC,IAAMP,IAAYC,SACT;EAAE,iBAAiBI,KAAQ;EAAI,YAAY;GAAE,OAAOpB;GAAY,QAAQ;EAAE;CAAE,IACnF,CAACoB,CAAI,CACP;CAEA,OAAOH,EAA0E;EAC/E,UAAUM;EACV;EACA,QAAQd;EACR,UAAUJ;EACV,SAAS,EAAQe;EACjB,cAAc;CAChB,CAAC;AACH;AAEA,SAAgBI,IAAyB;CACvC,IAAMb,IAAcC,EAAe,GAE7BG,IAAYU,GACf,OAAyC,EACxC,OAAOC,EAAmB;EAAE,GAAGC;EAAO;CAAY,GAAG1B,CAAgB,EACvE,IACA,CAACU,CAAW,CACd;CAEA,OAAOiB,EAIL;EACA,UAAUC;EACV;EACA,SAAS,MAAStB,GAAM;EACxB,cAAc;CAChB,CAAC;AACH;AAEA,SAAgBuB,IAAyB;CACvC,OAAOF,EAIL;EACA,UAAUG;EACV,YAAY,EAAE,SAAM,gBAAa;GAC/B,IAAIX;GACJ,OAAOM,EAAmBC,GAAOxB,CAAgB;EACnD;EACA,SAAS,MAASI,GAAM;EACxB,cAAc;CAChB,CAAC;AACH;AAGA,SAAgByB,IAA+B;CAC7C,OAAOJ,EAAyE;EAC9E,UAAUK;EACV,YAAY,OAAU,EAAE,iBAAiBb,EAAK;EAC9C,SAAS,MAASb,GAAM;EACxB,cAAc;CAChB,CAAC;AACH"}
1
+ {"version":3,"file":"useKnowledgeBases.js","names":["LIST_LIMIT","CREATE_KB_FIELDS","fieldsOf","UPDATE_KB_FIELDS","NO_KNOWLEDGE_BASES","NO_DOCUMENTS","selectKnowledgeBases","data","selectKnowledgeBase","selectDocuments","useKnowledgeBases","workspaceId","useWorkspaceId","search","filter","variables","useMemo","useAllPagesQuery","ListKnowledgeBasesDocument","useKnowledgeBase","kbId","useWorkspaceQuery","GetKnowledgeBaseDocument","useKnowledgeDocuments","ListKnowledgeDocumentsDocument","useCreateKnowledgeBase","useCallback","buildMutationInput","input","useWorkspaceMutation","CreateKnowledgeBaseDocument","useUpdateKnowledgeBase","UpdateKnowledgeBaseDocument","useRebuildKnowledgeBaseIndex","RebuildKnowledgeBaseIndexDocument"],"sources":["../../../src/botlit/hooks/useKnowledgeBases.ts"],"sourcesContent":["/**\n * Knowledge Bases Hooks\n * @module botlit/hooks\n *\n * Backed by the live `listKnowledgeBases` / `getKnowledgeBase` /\n * `listKnowledgeDocuments` operations and the create/update/delete mutations on\n * wspace-botlit-svc.\n */\n\nimport { useCallback, useMemo } from 'react';\nimport {\n CreateKnowledgeBaseDocument,\n DeleteKnowledgeBaseDocument,\n GetKnowledgeBaseDocument,\n ListKnowledgeBasesDocument,\n ListKnowledgeDocumentsDocument,\n RebuildKnowledgeBaseIndexDocument,\n UpdateKnowledgeBaseDocument,\n type CreateKnowledgeBaseMutation,\n type DeleteKnowledgeBaseMutation,\n type GetKnowledgeBaseQuery,\n type ListKnowledgeBasesQuery,\n type ListKnowledgeDocumentsQuery,\n type RebuildKnowledgeBaseIndexMutation,\n type UpdateKnowledgeBaseMutation,\n} from '../../generated/wspace-operations';\nimport type {\n CreateKnowledgeBaseInput,\n UpdateKnowledgeBaseInput,\n} from '../../generated/wspace-types';\nimport type { BaseFilter } from '../types';\nimport { useAllPagesQuery } from './internal/allPages';\nimport { buildMutationInput, fieldsOf, type GraphQLInput } from './internal/mutationInput';\nimport {\n useWorkspaceId,\n useWorkspaceMutation,\n useWorkspaceQuery,\n type QueryResult,\n} from './internal/workspaceGateway';\n\nconst LIST_LIMIT = 100;\n\nexport interface KnowledgeBaseRecord {\n id: string;\n name: string;\n description?: string | null;\n indexStatus: string;\n embeddingModel: string;\n embeddingDimensions: number;\n chunkingStrategy: string;\n chunkSize: number;\n chunkOverlap: number;\n totalDocuments: number;\n totalChunks: number;\n vectorCount: number;\n lastIndexedAt?: string | null;\n metadata?: Record<string, unknown> | null;\n createdAt: string;\n updatedAt: string;\n createdById: string;\n updatedById: string;\n workspaceId: string;\n}\n\nexport interface KnowledgeDocumentRecord {\n id: string;\n knowledgeBaseId: string;\n title: string;\n fileId: string;\n status: string;\n chunkCount: number;\n processingError?: string | null;\n processedAt?: string | null;\n addedAt: string;\n addedById: string;\n updatedAt: string;\n}\n\n/**\n * `CreateKnowledgeBaseInput` minus the `workspaceId` the hook supplies.\n * `embeddingModel`/`embeddingDimensions` are required by the service.\n */\nexport type CreateKnowledgeBaseVariables = Omit<\n GraphQLInput<CreateKnowledgeBaseInput>,\n 'workspaceId'\n>;\n\nexport interface UpdateKnowledgeBaseVariables {\n kbId: string;\n input: GraphQLInput<UpdateKnowledgeBaseInput>;\n}\n\nconst CREATE_KB_FIELDS = fieldsOf<CreateKnowledgeBaseInput>({\n chunkOverlap: true,\n chunkSize: true,\n chunkingStrategy: true,\n description: true,\n embeddingDimensions: true,\n embeddingModel: true,\n metadata: true,\n name: true,\n // Optional: the service picks the environment default when omitted.\n vectorStoreDriver: true,\n workspaceId: true,\n});\n\nconst UPDATE_KB_FIELDS = fieldsOf<UpdateKnowledgeBaseInput>({\n chunkOverlap: true,\n chunkSize: true,\n chunkingStrategy: true,\n description: true,\n metadata: true,\n name: true,\n});\n\nconst NO_KNOWLEDGE_BASES: KnowledgeBaseRecord[] = [];\nconst NO_DOCUMENTS: KnowledgeDocumentRecord[] = [];\n\nfunction selectKnowledgeBases(data: ListKnowledgeBasesQuery | undefined): KnowledgeBaseRecord[] {\n return data?.listKnowledgeBases ?? NO_KNOWLEDGE_BASES;\n}\n\nfunction selectKnowledgeBase(data: GetKnowledgeBaseQuery | undefined): KnowledgeBaseRecord | null {\n return data?.getKnowledgeBase ?? null;\n}\n\nfunction selectDocuments(data: ListKnowledgeDocumentsQuery | undefined): KnowledgeDocumentRecord[] {\n return data?.listKnowledgeDocuments ?? NO_DOCUMENTS;\n}\n\nexport const knowledgeBaseKeys = {\n all: ['knowledgeBases'] as const,\n lists: () => [...knowledgeBaseKeys.all, 'list'] as const,\n list: (filter?: BaseFilter) => [...knowledgeBaseKeys.lists(), filter] as const,\n details: () => [...knowledgeBaseKeys.all, 'detail'] as const,\n detail: (id: string) => [...knowledgeBaseKeys.details(), id] as const,\n documents: (kbId: string) => [...knowledgeBaseKeys.detail(kbId), 'documents'] as const,\n};\n\nexport function useKnowledgeBases(filter?: BaseFilter): QueryResult<KnowledgeBaseRecord[]> {\n const workspaceId = useWorkspaceId();\n const search = filter?.search;\n\n const variables = useMemo(\n () => ({\n filters: { workspaceId, search: search || undefined },\n }),\n [workspaceId, search]\n );\n\n // Every page: pickers and lookups need the whole list, not the first 100.\n return useAllPagesQuery<ListKnowledgeBasesQuery, KnowledgeBaseRecord>({\n document: ListKnowledgeBasesDocument,\n variables,\n pageSize: LIST_LIMIT,\n extractRows: selectKnowledgeBases,\n fallback: NO_KNOWLEDGE_BASES,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load knowledge bases',\n });\n}\n\nexport function useKnowledgeBase(\n kbId: string | undefined\n): QueryResult<KnowledgeBaseRecord | null> {\n const variables = useMemo(() => ({ id: kbId ?? '' }), [kbId]);\n\n return useWorkspaceQuery<GetKnowledgeBaseQuery, KnowledgeBaseRecord | null>({\n document: GetKnowledgeBaseDocument,\n variables,\n select: selectKnowledgeBase,\n fallback: null,\n enabled: Boolean(kbId),\n errorMessage: 'Failed to load knowledge base',\n });\n}\n\nexport function useKnowledgeDocuments(\n kbId: string | undefined\n): QueryResult<KnowledgeDocumentRecord[]> {\n const variables = useMemo(\n () => ({ knowledgeBaseId: kbId ?? '', pagination: { limit: LIST_LIMIT, offset: 0 } }),\n [kbId]\n );\n\n return useWorkspaceQuery<ListKnowledgeDocumentsQuery, KnowledgeDocumentRecord[]>({\n document: ListKnowledgeDocumentsDocument,\n variables,\n select: selectDocuments,\n fallback: NO_DOCUMENTS,\n enabled: Boolean(kbId),\n errorMessage: 'Failed to load knowledge documents',\n });\n}\n\nexport function useCreateKnowledgeBase() {\n const workspaceId = useWorkspaceId();\n\n const variables = useCallback(\n (input: CreateKnowledgeBaseVariables) => ({\n input: buildMutationInput({ ...input, workspaceId }, CREATE_KB_FIELDS),\n }),\n [workspaceId]\n );\n\n return useWorkspaceMutation<\n CreateKnowledgeBaseMutation,\n CreateKnowledgeBaseVariables,\n { id: string; name: string; workspaceId: string }\n >({\n document: CreateKnowledgeBaseDocument,\n variables,\n select: (data) => data?.createKnowledgeBase,\n errorMessage: 'Failed to create knowledge base',\n });\n}\n\nexport function useUpdateKnowledgeBase() {\n return useWorkspaceMutation<\n UpdateKnowledgeBaseMutation,\n UpdateKnowledgeBaseVariables,\n { id: string; name: string; indexStatus: string }\n >({\n document: UpdateKnowledgeBaseDocument,\n variables: ({ kbId, input }) => ({\n id: kbId,\n input: buildMutationInput(input, UPDATE_KB_FIELDS),\n }),\n select: (data) => data?.updateKnowledgeBase,\n errorMessage: 'Failed to update knowledge base',\n });\n}\n\n/** Re-indexes every document in the knowledge base (`rebuildKnowledgeBaseIndex`). */\nexport function useRebuildKnowledgeBaseIndex() {\n return useWorkspaceMutation<RebuildKnowledgeBaseIndexMutation, string, boolean>({\n document: RebuildKnowledgeBaseIndexDocument,\n variables: (kbId) => ({ knowledgeBaseId: kbId }),\n select: (data) => data?.rebuildKnowledgeBaseIndex,\n errorMessage: 'Failed to rebuild the knowledge base index',\n });\n}\n\nexport function useDeleteKnowledgeBase() {\n return useWorkspaceMutation<DeleteKnowledgeBaseMutation, string, boolean>({\n document: DeleteKnowledgeBaseDocument,\n variables: (kbId) => ({ id: kbId }),\n select: (data) => data?.deleteKnowledgeBase,\n errorMessage: 'Failed to delete knowledge base',\n });\n}\n"],"mappings":";;;;;;AAwCA,IAAMA,IAAa,KAoDbC,IAAmBC,EAAmC;CAC1D,cAAc;CACd,WAAW;CACX,kBAAkB;CACl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vC,IAAMd,IAAcC,EAAe,GAE7BG,IAAYW,GACf,OAAyC,EACxC,OAAOC,EAAmB;EAAE,GAAGC;EAAO;CAAY,GAAG3B,CAAgB,EACvE,IACA,CAACU,CAAW,CACd;CAEA,OAAOkB,EAIL;EACA,UAAUC;EACV;EACA,SAAS,MAASvB,GAAM;EACxB,cAAc;CAChB,CAAC;AACH;AAEA,SAAgBwB,IAAyB;CACvC,OAAOF,EAIL;EACA,UAAUG;EACV,YAAY,EAAE,SAAM,gBAAa;GAC/B,IAAIZ;GACJ,OAAOO,EAAmBC,GAAOzB,CAAgB;EACnD;EACA,SAAS,MAASI,GAAM;EACxB,cAAc;CAChB,CAAC;AACH;AAGA,SAAgB0B,IAA+B;CAC7C,OAAOJ,EAAyE;EAC9E,UAAUK;EACV,YAAY,OAAU,EAAE,iBAAiBd,EAAK;EAC9C,SAAS,MAASb,GAAM;EACxB,cAAc;CAChB,CAAC;AACH"}
@@ -1,138 +1,134 @@
1
1
  import { CreateMcpConnectionDocument as e, DeleteMcpConnectionDocument as t, GetMcpConnectionDocument as n, ListMcpConnectionsDocument as r, ListMcpResourcesDocument as i, ListMcpToolsDocument as a, TestMcpConnectionDocument as o, UpdateMcpConnectionDocument as s, UpdateMcpToolDocument as c } from "../../generated/wspace-operations.js";
2
- import { buildMutationInput as l, fieldsOf as u } from "./internal/mutationInput.js";
3
- import { useWorkspaceId as d, useWorkspaceMutation as f, useWorkspaceQuery as p } from "./internal/workspaceGateway.js";
4
- import { useCallback as m, useMemo as h } from "react";
2
+ import { useAllPagesQuery as l } from "./internal/allPages.js";
3
+ import { buildMutationInput as u, fieldsOf as d } from "./internal/mutationInput.js";
4
+ import { useWorkspaceId as f, useWorkspaceMutation as p, useWorkspaceQuery as m } from "./internal/workspaceGateway.js";
5
+ import { useCallback as h, useMemo as g } from "react";
5
6
  // src/botlit/hooks/useMCPServers.ts
6
- var g = 100, _ = u({
7
+ var _ = 100, v = d({
7
8
  config: !0,
8
9
  credentials: !0,
9
10
  metadata: !0,
10
11
  name: !0,
11
12
  type: !0,
12
13
  workspaceId: !0
13
- }), v = u({
14
+ }), y = d({
14
15
  config: !0,
15
16
  credentials: !0,
16
17
  metadata: !0,
17
18
  name: !0
18
- }), y = [], b = [], x = [];
19
- function S(e) {
19
+ }), b = [], x = [], S = [];
20
+ function C(e) {
20
21
  return e === "CONNECTED";
21
22
  }
22
- function C(e) {
23
+ function w(e) {
23
24
  let t = e.config?.url;
24
25
  return typeof t == "string" ? t : void 0;
25
26
  }
26
- function w(e) {
27
+ function T(e) {
27
28
  let t = e.config?.description;
28
29
  return typeof t == "string" ? t : void 0;
29
30
  }
30
- function T(e) {
31
- return e?.listMCPConnections ?? y;
32
- }
33
31
  function E(e) {
34
- return e?.getMCPConnection ?? null;
32
+ return e?.listMCPConnections ?? b;
35
33
  }
36
34
  function D(e) {
37
- return e?.listMCPTools ?? b;
35
+ return e?.getMCPConnection ?? null;
38
36
  }
39
37
  function O(e) {
40
- return e?.listMCPResources ?? x;
38
+ return e?.listMCPTools ?? x;
41
39
  }
42
40
  function k(e) {
43
- let t = d(), n = e?.search?.trim().toLowerCase() ?? "", i = h(() => ({
44
- filters: { workspaceId: t },
45
- pagination: {
46
- limit: g,
47
- offset: 0
48
- }
49
- }), [t]), a = m((e) => {
50
- let t = T(e);
51
- return n ? t.filter((e) => e.name.toLowerCase().includes(n)) : t;
52
- }, [n]);
53
- return p({
41
+ return e?.listMCPResources ?? S;
42
+ }
43
+ function A(e) {
44
+ let t = f(), n = e?.search?.trim().toLowerCase() ?? "", i = g(() => ({ filters: { workspaceId: t } }), [t]), a = l({
54
45
  document: r,
55
46
  variables: i,
56
- select: a,
57
- fallback: y,
47
+ pageSize: _,
48
+ extractRows: E,
49
+ fallback: b,
58
50
  enabled: !!t,
59
51
  errorMessage: "Failed to load MCP servers"
60
- });
52
+ }), o = g(() => n ? a.data.filter((e) => e.name.toLowerCase().includes(n)) : a.data, [a.data, n]);
53
+ return {
54
+ ...a,
55
+ data: o
56
+ };
61
57
  }
62
- function A(e) {
63
- let t = h(() => ({ id: e ?? "" }), [e]);
64
- return p({
58
+ function j(e) {
59
+ let t = g(() => ({ id: e ?? "" }), [e]);
60
+ return m({
65
61
  document: n,
66
62
  variables: t,
67
- select: E,
63
+ select: D,
68
64
  fallback: null,
69
65
  enabled: !!e,
70
66
  errorMessage: "Failed to load MCP server"
71
67
  });
72
68
  }
73
- function j(e) {
74
- let t = h(() => ({ connectionId: e ?? "" }), [e]);
75
- return p({
69
+ function M(e) {
70
+ let t = g(() => ({ connectionId: e ?? "" }), [e]);
71
+ return m({
76
72
  document: a,
77
73
  variables: t,
78
- select: D,
79
- fallback: b,
74
+ select: O,
75
+ fallback: x,
80
76
  enabled: !!e,
81
77
  errorMessage: "Failed to load MCP tools"
82
78
  });
83
79
  }
84
- function M(e) {
85
- let t = h(() => ({ connectionId: e ?? "" }), [e]);
86
- return p({
80
+ function N(e) {
81
+ let t = g(() => ({ connectionId: e ?? "" }), [e]);
82
+ return m({
87
83
  document: i,
88
84
  variables: t,
89
- select: O,
90
- fallback: x,
85
+ select: k,
86
+ fallback: S,
91
87
  enabled: !!e,
92
88
  errorMessage: "Failed to load MCP resources"
93
89
  });
94
90
  }
95
- function N() {
96
- let t = d(), n = m((e) => ({ input: l({
91
+ function P() {
92
+ let t = f(), n = h((e) => ({ input: u({
97
93
  ...e,
98
94
  workspaceId: t
99
- }, _) }), [t]);
100
- return f({
95
+ }, v) }), [t]);
96
+ return p({
101
97
  document: e,
102
98
  variables: n,
103
99
  select: (e) => e?.createMCPConnection,
104
100
  errorMessage: "Failed to connect MCP server"
105
101
  });
106
102
  }
107
- function P() {
108
- return f({
103
+ function F() {
104
+ return p({
109
105
  document: s,
110
106
  variables: ({ serverId: e, input: t }) => ({
111
107
  id: e,
112
- input: l(t, v)
108
+ input: u(t, y)
113
109
  }),
114
110
  select: (e) => e?.updateMCPConnection,
115
111
  errorMessage: "Failed to update MCP server"
116
112
  });
117
113
  }
118
- function F() {
119
- return f({
114
+ function I() {
115
+ return p({
120
116
  document: t,
121
117
  variables: (e) => ({ id: e }),
122
118
  select: (e) => e?.deleteMCPConnection,
123
119
  errorMessage: "Failed to disconnect MCP server"
124
120
  });
125
121
  }
126
- function I() {
127
- return f({
122
+ function L() {
123
+ return p({
128
124
  document: o,
129
125
  variables: (e) => ({ id: e }),
130
126
  select: (e) => e?.testMCPConnection,
131
127
  errorMessage: "Failed to test MCP connection"
132
128
  });
133
129
  }
134
- function L() {
135
- return f({
130
+ function R() {
131
+ return p({
136
132
  document: c,
137
133
  variables: ({ toolId: e, input: t }) => ({
138
134
  id: e,
@@ -142,6 +138,6 @@ function L() {
142
138
  errorMessage: "Failed to update MCP tool risk level"
143
139
  });
144
140
  }
145
- export { S as isMCPServerHealthy, w as mcpServerDescription, C as mcpServerEndpoint, N as useCreateMCPServer, F as useDeleteMCPServer, M as useMCPResources, A as useMCPServer, k as useMCPServers, j as useMCPTools, I as useTestMCPConnection, P as useUpdateMCPServer, L as useUpdateMCPTool };
141
+ export { C as isMCPServerHealthy, T as mcpServerDescription, w as mcpServerEndpoint, P as useCreateMCPServer, I as useDeleteMCPServer, N as useMCPResources, j as useMCPServer, A as useMCPServers, M as useMCPTools, L as useTestMCPConnection, F as useUpdateMCPServer, R as useUpdateMCPTool };
146
142
 
147
143
  //# sourceMappingURL=useMCPServers.js.map