@burdenoff/microfe-botmanor 2026.813.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 (160) hide show
  1. package/README.md +12 -0
  2. package/dist/botlit/BotlitRoutes.js +357 -0
  3. package/dist/botlit/BotlitRoutes.js.map +1 -0
  4. package/dist/botlit/BotmanorRoot.js +12 -0
  5. package/dist/botlit/BotmanorRoot.js.map +1 -0
  6. package/dist/botlit/BotmanorRootInner.js +101 -0
  7. package/dist/botlit/BotmanorRootInner.js.map +1 -0
  8. package/dist/botlit/components/Badge.js +39 -0
  9. package/dist/botlit/components/Badge.js.map +1 -0
  10. package/dist/botlit/components/Button.js +46 -0
  11. package/dist/botlit/components/Button.js.map +1 -0
  12. package/dist/botlit/components/Card.js +31 -0
  13. package/dist/botlit/components/Card.js.map +1 -0
  14. package/dist/botlit/components/ChannelSelectorSheet.js +130 -0
  15. package/dist/botlit/components/ChannelSelectorSheet.js.map +1 -0
  16. package/dist/botlit/components/EmptyState.js +35 -0
  17. package/dist/botlit/components/EmptyState.js.map +1 -0
  18. package/dist/botlit/components/ErrorState.js +33 -0
  19. package/dist/botlit/components/ErrorState.js.map +1 -0
  20. package/dist/botlit/components/Input.js +59 -0
  21. package/dist/botlit/components/Input.js.map +1 -0
  22. package/dist/botlit/components/PageLayout.js +34 -0
  23. package/dist/botlit/components/PageLayout.js.map +1 -0
  24. package/dist/botlit/components/QuotaExhaustedDialog.js +20 -0
  25. package/dist/botlit/components/QuotaExhaustedDialog.js.map +1 -0
  26. package/dist/botlit/components/RouteLoader.js +52 -0
  27. package/dist/botlit/components/RouteLoader.js.map +1 -0
  28. package/dist/botlit/components/VersionHistoryPanel.js +144 -0
  29. package/dist/botlit/components/VersionHistoryPanel.js.map +1 -0
  30. package/dist/botlit/components/WorkspaceRequired.js +70 -0
  31. package/dist/botlit/components/WorkspaceRequired.js.map +1 -0
  32. package/dist/botlit/hooks/index.js +16 -0
  33. package/dist/botlit/hooks/internal/mutationInput.js +16 -0
  34. package/dist/botlit/hooks/internal/mutationInput.js.map +1 -0
  35. package/dist/botlit/hooks/internal/workspaceGateway.js +99 -0
  36. package/dist/botlit/hooks/internal/workspaceGateway.js.map +1 -0
  37. package/dist/botlit/hooks/useA2A.js +184 -0
  38. package/dist/botlit/hooks/useA2A.js.map +1 -0
  39. package/dist/botlit/hooks/useAgents.js +469 -0
  40. package/dist/botlit/hooks/useAgents.js.map +1 -0
  41. package/dist/botlit/hooks/useBots.js +306 -0
  42. package/dist/botlit/hooks/useBots.js.map +1 -0
  43. package/dist/botlit/hooks/useBuckets.js +119 -0
  44. package/dist/botlit/hooks/useBuckets.js.map +1 -0
  45. package/dist/botlit/hooks/useChannels.js +213 -0
  46. package/dist/botlit/hooks/useChannels.js.map +1 -0
  47. package/dist/botlit/hooks/useConversations.js +64 -0
  48. package/dist/botlit/hooks/useConversations.js.map +1 -0
  49. package/dist/botlit/hooks/useExecutions.js +86 -0
  50. package/dist/botlit/hooks/useExecutions.js.map +1 -0
  51. package/dist/botlit/hooks/useKnowledgeBases.js +113 -0
  52. package/dist/botlit/hooks/useKnowledgeBases.js.map +1 -0
  53. package/dist/botlit/hooks/useLLMProviders.js +83 -0
  54. package/dist/botlit/hooks/useLLMProviders.js.map +1 -0
  55. package/dist/botlit/hooks/useMCPServers.js +134 -0
  56. package/dist/botlit/hooks/useMCPServers.js.map +1 -0
  57. package/dist/botlit/hooks/usePolicies.js +120 -0
  58. package/dist/botlit/hooks/usePolicies.js.map +1 -0
  59. package/dist/botlit/hooks/usePromptTemplates.js +161 -0
  60. package/dist/botlit/hooks/usePromptTemplates.js.map +1 -0
  61. package/dist/botlit/hooks/useRetrievalProfiles.js +146 -0
  62. package/dist/botlit/hooks/useRetrievalProfiles.js.map +1 -0
  63. package/dist/botlit/hooks/useSkills.js +132 -0
  64. package/dist/botlit/hooks/useSkills.js.map +1 -0
  65. package/dist/botlit/hooks/useStore.js +167 -0
  66. package/dist/botlit/hooks/useStore.js.map +1 -0
  67. package/dist/botlit/hooks/useUserPlatformConnection.js +172 -0
  68. package/dist/botlit/hooks/useUserPlatformConnection.js.map +1 -0
  69. package/dist/botlit/index.js +11 -0
  70. package/dist/botlit/pages/A2AAgentDetailPage.js +589 -0
  71. package/dist/botlit/pages/A2AAgentDetailPage.js.map +1 -0
  72. package/dist/botlit/pages/A2ARegistryPage.js +240 -0
  73. package/dist/botlit/pages/A2ARegistryPage.js.map +1 -0
  74. package/dist/botlit/pages/AgentBuilderPage.js +486 -0
  75. package/dist/botlit/pages/AgentBuilderPage.js.map +1 -0
  76. package/dist/botlit/pages/AgentDetailPage.js +517 -0
  77. package/dist/botlit/pages/AgentDetailPage.js.map +1 -0
  78. package/dist/botlit/pages/AgentsListPage.js +294 -0
  79. package/dist/botlit/pages/AgentsListPage.js.map +1 -0
  80. package/dist/botlit/pages/BotChannelsTab.js +530 -0
  81. package/dist/botlit/pages/BotChannelsTab.js.map +1 -0
  82. package/dist/botlit/pages/BotDetailPage.js +872 -0
  83. package/dist/botlit/pages/BotDetailPage.js.map +1 -0
  84. package/dist/botlit/pages/BotWorkflowTab.js +229 -0
  85. package/dist/botlit/pages/BotWorkflowTab.js.map +1 -0
  86. package/dist/botlit/pages/BotsListPage.js +313 -0
  87. package/dist/botlit/pages/BotsListPage.js.map +1 -0
  88. package/dist/botlit/pages/BucketsPage.js +604 -0
  89. package/dist/botlit/pages/BucketsPage.js.map +1 -0
  90. package/dist/botlit/pages/ChannelDetailPage.js +955 -0
  91. package/dist/botlit/pages/ChannelDetailPage.js.map +1 -0
  92. package/dist/botlit/pages/ChannelRoutesPage.js +218 -0
  93. package/dist/botlit/pages/ChannelRoutesPage.js.map +1 -0
  94. package/dist/botlit/pages/ChannelsPage.js +304 -0
  95. package/dist/botlit/pages/ChannelsPage.js.map +1 -0
  96. package/dist/botlit/pages/ChatPage.js +247 -0
  97. package/dist/botlit/pages/ChatPage.js.map +1 -0
  98. package/dist/botlit/pages/DashboardPage.js +318 -0
  99. package/dist/botlit/pages/DashboardPage.js.map +1 -0
  100. package/dist/botlit/pages/ExecutionDetailPage.js +313 -0
  101. package/dist/botlit/pages/ExecutionDetailPage.js.map +1 -0
  102. package/dist/botlit/pages/ExecutionsPage.js +294 -0
  103. package/dist/botlit/pages/ExecutionsPage.js.map +1 -0
  104. package/dist/botlit/pages/InstalledPackagesPage.js +619 -0
  105. package/dist/botlit/pages/InstalledPackagesPage.js.map +1 -0
  106. package/dist/botlit/pages/KnowledgeBaseDetailPage.js +473 -0
  107. package/dist/botlit/pages/KnowledgeBaseDetailPage.js.map +1 -0
  108. package/dist/botlit/pages/KnowledgeBasesPage.js +150 -0
  109. package/dist/botlit/pages/KnowledgeBasesPage.js.map +1 -0
  110. package/dist/botlit/pages/MCPServerDetailPage.js +550 -0
  111. package/dist/botlit/pages/MCPServerDetailPage.js.map +1 -0
  112. package/dist/botlit/pages/MCPServersPage.js +321 -0
  113. package/dist/botlit/pages/MCPServersPage.js.map +1 -0
  114. package/dist/botlit/pages/PoliciesPage.js +224 -0
  115. package/dist/botlit/pages/PoliciesPage.js.map +1 -0
  116. package/dist/botlit/pages/PolicyDetailPage.js +861 -0
  117. package/dist/botlit/pages/PolicyDetailPage.js.map +1 -0
  118. package/dist/botlit/pages/PromptStudioPage.js +236 -0
  119. package/dist/botlit/pages/PromptStudioPage.js.map +1 -0
  120. package/dist/botlit/pages/PromptTemplateDetailPage.js +812 -0
  121. package/dist/botlit/pages/PromptTemplateDetailPage.js.map +1 -0
  122. package/dist/botlit/pages/PromptTemplatesPage.js +269 -0
  123. package/dist/botlit/pages/PromptTemplatesPage.js.map +1 -0
  124. package/dist/botlit/pages/RetrievalProfileDetailPage.js +559 -0
  125. package/dist/botlit/pages/RetrievalProfileDetailPage.js.map +1 -0
  126. package/dist/botlit/pages/RetrievalProfilesPage.js +219 -0
  127. package/dist/botlit/pages/RetrievalProfilesPage.js.map +1 -0
  128. package/dist/botlit/pages/SettingsPage.js +655 -0
  129. package/dist/botlit/pages/SettingsPage.js.map +1 -0
  130. package/dist/botlit/pages/SkillDetailPage.js +778 -0
  131. package/dist/botlit/pages/SkillDetailPage.js.map +1 -0
  132. package/dist/botlit/pages/SkillsPage.js +206 -0
  133. package/dist/botlit/pages/SkillsPage.js.map +1 -0
  134. package/dist/botlit/pages/StorePackageDetailPage.js +462 -0
  135. package/dist/botlit/pages/StorePackageDetailPage.js.map +1 -0
  136. package/dist/botlit/pages/StorePage.js +315 -0
  137. package/dist/botlit/pages/StorePage.js.map +1 -0
  138. package/dist/botlit/providers/BotlitProvider.js +93 -0
  139. package/dist/botlit/providers/BotlitProvider.js.map +1 -0
  140. package/dist/botlit/store/botlitStore.js +101 -0
  141. package/dist/botlit/store/botlitStore.js.map +1 -0
  142. package/dist/botlit/utils/cn.js +10 -0
  143. package/dist/botlit/utils/cn.js.map +1 -0
  144. package/dist/botlit/utils/formatters.js +37 -0
  145. package/dist/botlit/utils/formatters.js.map +1 -0
  146. package/dist/botlit/utils/navigation.js +9 -0
  147. package/dist/botlit/utils/navigation.js.map +1 -0
  148. package/dist/botlit/utils/unions.js +14 -0
  149. package/dist/botlit/utils/unions.js.map +1 -0
  150. package/dist/generated/global-operations.js +66 -0
  151. package/dist/generated/global-operations.js.map +1 -0
  152. package/dist/generated/global-types.js +8 -0
  153. package/dist/generated/global-types.js.map +1 -0
  154. package/dist/generated/wspace-operations.js +1591 -0
  155. package/dist/generated/wspace-operations.js.map +1 -0
  156. package/dist/generated/wspace-types.js +12 -0
  157. package/dist/generated/wspace-types.js.map +1 -0
  158. package/dist/index.js +13 -0
  159. package/dist/utils/nativeBridge.js +2 -0
  160. package/package.json +133 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useChannels.js","names":[],"sources":["../../../src/botlit/hooks/useChannels.ts"],"sourcesContent":["/**\n * Channels Hooks\n * @module botlit/hooks\n *\n * Backed by the live `listChannelConnectors` / `listChannelRoutes` operations\n * (and their get/create/update/delete counterparts) on wspace-botlit-svc.\n *\n * Connectors are the platform integrations (Slack, web widget, webhook…).\n * Routes bind a location on a connector to a bot app.\n */\n\nimport { useCallback, useMemo } from 'react';\nimport {\n CreateChannelConnectorDocument,\n CreateChannelRouteDocument,\n DeleteChannelConnectorDocument,\n DeleteChannelRouteDocument,\n GetChannelConnectorDocument,\n GetChannelRouteDocument,\n ListChannelConnectorsDocument,\n ListChannelRoutesDocument,\n UpdateChannelConnectorDocument,\n UpdateChannelRouteDocument,\n type CreateChannelConnectorMutation,\n type CreateChannelRouteMutation,\n type DeleteChannelConnectorMutation,\n type DeleteChannelRouteMutation,\n type GetChannelConnectorQuery,\n type GetChannelRouteQuery,\n type ListChannelConnectorsQuery,\n type ListChannelRoutesQuery,\n type UpdateChannelConnectorMutation,\n type UpdateChannelRouteMutation,\n} from '../../generated/wspace-operations';\nimport type {\n CreateChannelConnectorInput,\n CreateChannelRouteInput,\n UpdateChannelConnectorInput,\n UpdateChannelRouteInput,\n} from '../../generated/wspace-types';\nimport type { ChannelFilter } 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 ChannelConnectorRecord {\n id: string;\n name: string;\n type: string;\n status: string;\n visibility: string;\n description?: string | null;\n bucketId?: string | null;\n credentialsRefId?: string | null;\n defaultPolicyBindings?: Record<string, unknown> | null;\n metadata?: Record<string, unknown> | null;\n revision: number;\n tags: string[];\n createdAt: string;\n updatedAt: string;\n createdById: string;\n updatedById: string;\n workspaceId: string;\n}\n\nexport interface ChannelRouteRecord {\n id: string;\n appId: string;\n connectorId: string;\n locationId: string;\n formatPolicyId?: string | null;\n policyBindings?: Record<string, unknown> | null;\n routingOverrides?: Record<string, unknown> | null;\n metadata?: Record<string, unknown> | null;\n revision: number;\n createdAt: string;\n updatedAt: string;\n workspaceId: string;\n}\n\n/** `CreateChannelConnectorInput` minus the `workspaceId` the hook supplies. */\nexport type CreateChannelConnectorVariables = Omit<\n GraphQLInput<CreateChannelConnectorInput>,\n 'workspaceId'\n>;\n\nexport interface UpdateChannelConnectorVariables {\n connectorId: string;\n input: GraphQLInput<UpdateChannelConnectorInput>;\n}\n\n/** `CreateChannelRouteInput` minus the `workspaceId` the hook supplies. */\nexport type CreateChannelRouteVariables = Omit<\n GraphQLInput<CreateChannelRouteInput>,\n 'workspaceId'\n>;\n\nexport interface UpdateChannelRouteVariables {\n routeId: string;\n input: GraphQLInput<UpdateChannelRouteInput>;\n}\n\nconst CREATE_CONNECTOR_FIELDS = fieldsOf<CreateChannelConnectorInput>({\n bucketId: true,\n credentialsRefId: true,\n defaultPolicyBindings: true,\n description: true,\n metadata: true,\n name: true,\n status: true,\n tags: true,\n type: true,\n visibility: true,\n workspaceId: true,\n});\n\nconst UPDATE_CONNECTOR_FIELDS = fieldsOf<UpdateChannelConnectorInput>({\n bucketId: true,\n credentialsRefId: true,\n defaultPolicyBindings: true,\n description: true,\n metadata: true,\n name: true,\n status: true,\n tags: true,\n visibility: true,\n});\n\nconst CREATE_ROUTE_FIELDS = fieldsOf<CreateChannelRouteInput>({\n appId: true,\n connectorId: true,\n formatPolicyId: true,\n locationId: true,\n metadata: true,\n policyBindings: true,\n routingOverrides: true,\n workspaceId: true,\n});\n\nconst UPDATE_ROUTE_FIELDS = fieldsOf<UpdateChannelRouteInput>({\n appId: true,\n formatPolicyId: true,\n locationId: true,\n metadata: true,\n policyBindings: true,\n routingOverrides: true,\n});\n\nconst NO_CONNECTORS: ChannelConnectorRecord[] = [];\nconst NO_ROUTES: ChannelRouteRecord[] = [];\n\nfunction selectConnectors(data: ListChannelConnectorsQuery | undefined): ChannelConnectorRecord[] {\n return data?.listChannelConnectors ?? NO_CONNECTORS;\n}\n\nfunction selectConnector(\n data: GetChannelConnectorQuery | undefined\n): ChannelConnectorRecord | null {\n return data?.getChannelConnector ?? null;\n}\n\nfunction selectRoutes(data: ListChannelRoutesQuery | undefined): ChannelRouteRecord[] {\n return data?.listChannelRoutes ?? NO_ROUTES;\n}\n\nfunction selectRoute(data: GetChannelRouteQuery | undefined): ChannelRouteRecord | null {\n return data?.getChannelRoute ?? null;\n}\n\n/**\n * Web-widget appearance settings.\n *\n * `ChannelConnector` has no widget column — the settings live under\n * `metadata.webWidget`, which is where the connector form writes them.\n */\nexport interface ChannelWidgetConfig {\n allowedOrigins: string[];\n primaryColor: string;\n fontFamily: string;\n starterPrompts: string[];\n}\n\nexport const WIDGET_METADATA_KEY = 'webWidget';\n\nconst DEFAULT_WIDGET_CONFIG: ChannelWidgetConfig = {\n allowedOrigins: [],\n primaryColor: '#3b82f6',\n fontFamily: 'Inter, sans-serif',\n starterPrompts: [],\n};\n\n/** Reads the widget settings back, or `undefined` when none were saved. */\nexport function readWidgetConfig(\n connector: Pick<ChannelConnectorRecord, 'metadata'>\n): ChannelWidgetConfig | undefined {\n const stored = connector.metadata?.[WIDGET_METADATA_KEY];\n if (typeof stored !== 'object' || stored === null || Array.isArray(stored)) return undefined;\n\n const source = stored as Record<string, unknown>;\n return {\n allowedOrigins: jsonStringList(source.allowedOrigins),\n primaryColor:\n typeof source.primaryColor === 'string'\n ? source.primaryColor\n : DEFAULT_WIDGET_CONFIG.primaryColor,\n fontFamily:\n typeof source.fontFamily === 'string' ? source.fontFamily : DEFAULT_WIDGET_CONFIG.fontFamily,\n starterPrompts: jsonStringList(source.starterPrompts),\n };\n}\n\nfunction jsonStringList(value: unknown): string[] {\n return Array.isArray(value)\n ? value.filter((entry): entry is string => typeof entry === 'string')\n : [];\n}\n\n/** Reads a display label the UI stashed on the route's free-form metadata. */\nexport function routeMetadataString(\n route: Pick<ChannelRouteRecord, 'metadata'>,\n key: string\n): string | undefined {\n const value = route.metadata?.[key];\n return typeof value === 'string' ? value : undefined;\n}\n\nexport const channelKeys = {\n all: ['channels'] as const,\n connectors: () => [...channelKeys.all, 'connectors'] as const,\n connectorList: (filter?: ChannelFilter) => [...channelKeys.connectors(), 'list', filter] as const,\n connectorDetail: (id: string) => [...channelKeys.connectors(), 'detail', id] as const,\n routes: () => [...channelKeys.all, 'routes'] as const,\n routeList: (connectorId?: string) => [...channelKeys.routes(), 'list', connectorId] as const,\n routeDetail: (id: string) => [...channelKeys.routes(), 'detail', id] as const,\n};\n\n// ============================================================================\n// Connectors\n// ============================================================================\n\nexport function useChannelConnectors(\n filter?: ChannelFilter\n): QueryResult<ChannelConnectorRecord[]> {\n const workspaceId = useWorkspaceId();\n const search = filter?.search;\n const type = filter?.type?.[0];\n const status = filter?.status?.[0];\n const bucketId = filter?.bucketId;\n\n const variables = useMemo(\n () => ({\n filters: {\n workspaceId,\n search: search || undefined,\n type,\n status,\n bucketId,\n },\n pagination: { limit: LIST_LIMIT, offset: 0 },\n }),\n [workspaceId, search, type, status, bucketId]\n );\n\n return useWorkspaceQuery<ListChannelConnectorsQuery, ChannelConnectorRecord[]>({\n document: ListChannelConnectorsDocument,\n variables,\n select: selectConnectors,\n fallback: NO_CONNECTORS,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load channel connectors',\n });\n}\n\nexport function useChannelConnector(\n connectorId: string | undefined\n): QueryResult<ChannelConnectorRecord | null> {\n const variables = useMemo(() => ({ id: connectorId ?? '' }), [connectorId]);\n\n return useWorkspaceQuery<GetChannelConnectorQuery, ChannelConnectorRecord | null>({\n document: GetChannelConnectorDocument,\n variables,\n select: selectConnector,\n fallback: null,\n enabled: Boolean(connectorId),\n errorMessage: 'Failed to load channel connector',\n });\n}\n\nexport function useCreateChannelConnector() {\n const workspaceId = useWorkspaceId();\n\n const variables = useCallback(\n (input: CreateChannelConnectorVariables) => ({\n input: buildMutationInput({ ...input, workspaceId }, CREATE_CONNECTOR_FIELDS),\n }),\n [workspaceId]\n );\n\n return useWorkspaceMutation<\n CreateChannelConnectorMutation,\n CreateChannelConnectorVariables,\n ChannelConnectorRecord\n >({\n document: CreateChannelConnectorDocument,\n variables,\n select: (data) => data?.createChannelConnector,\n errorMessage: 'Failed to create channel connector',\n });\n}\n\nexport function useUpdateChannelConnector() {\n return useWorkspaceMutation<\n UpdateChannelConnectorMutation,\n UpdateChannelConnectorVariables,\n ChannelConnectorRecord\n >({\n document: UpdateChannelConnectorDocument,\n variables: ({ connectorId, input }) => ({\n id: connectorId,\n input: buildMutationInput(input, UPDATE_CONNECTOR_FIELDS),\n }),\n select: (data) => data?.updateChannelConnector,\n errorMessage: 'Failed to update channel connector',\n });\n}\n\nexport function useDeleteChannelConnector() {\n return useWorkspaceMutation<DeleteChannelConnectorMutation, string, boolean>({\n document: DeleteChannelConnectorDocument,\n variables: (connectorId) => ({ id: connectorId }),\n select: (data) => data?.deleteChannelConnector,\n errorMessage: 'Failed to delete channel connector',\n });\n}\n\n// ============================================================================\n// Routes\n// ============================================================================\n\nexport function useChannelRoutes(connectorId?: string): QueryResult<ChannelRouteRecord[]> {\n const workspaceId = useWorkspaceId();\n\n const variables = useMemo(\n () => ({\n filters: { workspaceId, connectorId: connectorId || undefined },\n pagination: { limit: LIST_LIMIT, offset: 0 },\n }),\n [workspaceId, connectorId]\n );\n\n return useWorkspaceQuery<ListChannelRoutesQuery, ChannelRouteRecord[]>({\n document: ListChannelRoutesDocument,\n variables,\n select: selectRoutes,\n fallback: NO_ROUTES,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load channel routes',\n });\n}\n\n/** Routes bound to a specific bot app (Bot Detail → Channels tab). */\nexport function useBotChannelRoutes(botId: string | undefined): QueryResult<ChannelRouteRecord[]> {\n const workspaceId = useWorkspaceId();\n\n const variables = useMemo(\n () => ({\n filters: { workspaceId, appId: botId },\n pagination: { limit: LIST_LIMIT, offset: 0 },\n }),\n [workspaceId, botId]\n );\n\n return useWorkspaceQuery<ListChannelRoutesQuery, ChannelRouteRecord[]>({\n document: ListChannelRoutesDocument,\n variables,\n select: selectRoutes,\n fallback: NO_ROUTES,\n enabled: Boolean(workspaceId) && Boolean(botId),\n errorMessage: 'Failed to load channel routes for this bot',\n });\n}\n\nexport function useChannelRoute(\n routeId: string | undefined\n): QueryResult<ChannelRouteRecord | null> {\n const variables = useMemo(() => ({ id: routeId ?? '' }), [routeId]);\n\n return useWorkspaceQuery<GetChannelRouteQuery, ChannelRouteRecord | null>({\n document: GetChannelRouteDocument,\n variables,\n select: selectRoute,\n fallback: null,\n enabled: Boolean(routeId),\n errorMessage: 'Failed to load channel route',\n });\n}\n\nexport function useCreateChannelRoute() {\n const workspaceId = useWorkspaceId();\n\n const variables = useCallback(\n (input: CreateChannelRouteVariables) => ({\n input: buildMutationInput({ ...input, workspaceId }, CREATE_ROUTE_FIELDS),\n }),\n [workspaceId]\n );\n\n return useWorkspaceMutation<\n CreateChannelRouteMutation,\n CreateChannelRouteVariables,\n ChannelRouteRecord\n >({\n document: CreateChannelRouteDocument,\n variables,\n select: (data) => data?.createChannelRoute,\n errorMessage: 'Failed to create channel route',\n });\n}\n\nexport function useUpdateChannelRoute() {\n return useWorkspaceMutation<\n UpdateChannelRouteMutation,\n UpdateChannelRouteVariables,\n ChannelRouteRecord\n >({\n document: UpdateChannelRouteDocument,\n variables: ({ routeId, input }) => ({\n id: routeId,\n input: buildMutationInput(input, UPDATE_ROUTE_FIELDS),\n }),\n select: (data) => data?.updateChannelRoute,\n errorMessage: 'Failed to update channel route',\n });\n}\n\nexport function useDeleteChannelRoute() {\n return useWorkspaceMutation<DeleteChannelRouteMutation, string, boolean>({\n document: DeleteChannelRouteDocument,\n variables: (routeId) => ({ id: routeId }),\n select: (data) => data?.deleteChannelRoute,\n errorMessage: 'Failed to delete channel route',\n });\n}\n"],"mappings":";;;;;AAiDA,IAAM,IAAa,KA2Db,IAA0B,EAAsC;CACpE,UAAU;CACV,kBAAkB;CAClB,uBAAuB;CACvB,aAAa;CACb,UAAU;CACV,MAAM;CACN,QAAQ;CACR,MAAM;CACN,MAAM;CACN,YAAY;CACZ,aAAa;CACd,CAAC,EAEI,IAA0B,EAAsC;CACpE,UAAU;CACV,kBAAkB;CAClB,uB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,SAAS;IAAE;IAAa,aAAa,KAAe,KAAA;IAAW;GAC/D,YAAY;IAAE,OAAO;IAAY,QAAQ;IAAG;GAC7C,GACD,CAAC,GAAa,EAAY,CAC3B;EAKC,QAAQ;EACR,UAAU;EACV,SAAS,EAAQ;EACjB,cAAc;EACf,CAAC;;AAIJ,SAAgB,EAAoB,GAA8D;CAChG,IAAM,IAAc,GAAgB;AAUpC,QAAO,EAAgE;EACrE,UAAU;EACV,WAVgB,SACT;GACL,SAAS;IAAE;IAAa,OAAO;IAAO;GACtC,YAAY;IAAE,OAAO;IAAY,QAAQ;IAAG;GAC7C,GACD,CAAC,GAAa,EAAM,CACrB;EAKC,QAAQ;EACR,UAAU;EACV,SAAS,EAAQ,KAAgB,EAAQ;EACzC,cAAc;EACf,CAAC;;AAkBJ,SAAgB,IAAwB;CACtC,IAAM,IAAc,GAAgB;AASpC,QAAO,EAIL;EACA,UAAU;EACV,WAbgB,GACf,OAAwC,EACvC,OAAO,EAAmB;GAAE,GAAG;GAAO;GAAa,EAAE,EAAoB,EAC1E,GACD,CAAC,EAAY,CACd;EASC,SAAS,MAAS,GAAM;EACxB,cAAc;EACf,CAAC;;AAmBJ,SAAgB,IAAwB;AACtC,QAAO,EAAkE;EACvE,UAAU;EACV,YAAY,OAAa,EAAE,IAAI,GAAS;EACxC,SAAS,MAAS,GAAM;EACxB,cAAc;EACf,CAAC"}
@@ -0,0 +1,64 @@
1
+ import { useCallback as e, useState as t } from "react";
2
+ import { gql as n } from "@apollo/client";
3
+ import { useGatewayClient as r } from "@burdenoff/fe-libs/shared/graphql";
4
+ //#region src/botlit/hooks/useConversations.ts
5
+ var i = n`
6
+ mutation ChatWithAgent($input: ChatWithAgentInput!) {
7
+ chatWithAgent(input: $input) {
8
+ executionId
9
+ message
10
+ tokensUsed
11
+ model
12
+ conversationId
13
+ }
14
+ }
15
+ `;
16
+ function a(e) {
17
+ return e;
18
+ }
19
+ var o = [];
20
+ function s(e) {
21
+ return {
22
+ data: o,
23
+ loading: !1,
24
+ error: void 0
25
+ };
26
+ }
27
+ function c(e) {
28
+ return {
29
+ data: null,
30
+ loading: !1,
31
+ error: void 0
32
+ };
33
+ }
34
+ function l() {
35
+ let n = a(r("workspace")), [o, s] = t(!1), [c, l] = t(null);
36
+ return {
37
+ sendMessage: e(async (e) => {
38
+ s(!0), l(null);
39
+ try {
40
+ let t = (await n.mutate({
41
+ mutation: i,
42
+ variables: { input: {
43
+ conversationId: e.conversationId ?? null,
44
+ agentId: e.agentId,
45
+ message: e.content
46
+ } }
47
+ })).data?.chatWithAgent;
48
+ if (!t) throw Error("Failed to send message");
49
+ return t;
50
+ } catch (e) {
51
+ let t = e instanceof Error ? e : /* @__PURE__ */ Error("Failed to send message");
52
+ throw l(t), t;
53
+ } finally {
54
+ s(!1);
55
+ }
56
+ }, [n]),
57
+ isSending: o,
58
+ error: c
59
+ };
60
+ }
61
+ //#endregion
62
+ export { c as useConversation, s as useConversations, l as useSendMessage };
63
+
64
+ //# sourceMappingURL=useConversations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useConversations.js","names":[],"sources":["../../../src/botlit/hooks/useConversations.ts"],"sourcesContent":["import { gql, type ApolloClient } from '@apollo/client';\nimport { useCallback, useState } from 'react';\nimport { useGatewayClient } from '@burdenoff/fe-libs/shared/graphql';\n\nconst CHAT_WITH_AGENT_DOCUMENT = gql`\n mutation ChatWithAgent($input: ChatWithAgentInput!) {\n chatWithAgent(input: $input) {\n executionId\n message\n tokensUsed\n model\n conversationId\n }\n }\n`;\n\ntype WorkspaceClient = ApolloClient;\n\ninterface ChatResponse {\n executionId: string;\n message: string;\n tokensUsed?: number | null;\n model?: string | null;\n conversationId?: string | null;\n}\n\ninterface ChatWithAgentData {\n chatWithAgent: ChatResponse;\n}\n\nfunction getWorkspaceClient(client: unknown): WorkspaceClient {\n return client as WorkspaceClient;\n}\n\nexport const conversationKeys = {\n all: ['conversations'] as const,\n lists: () => [...conversationKeys.all, 'list'] as const,\n list: (filter?: Record<string, unknown>) => [...conversationKeys.lists(), filter] as const,\n details: () => [...conversationKeys.all, 'detail'] as const,\n detail: (id: string) => [...conversationKeys.details(), id] as const,\n};\n\n/**\n * Conversations moved to `microfe-conversations`; the Botlit routes redirect\n * there. These stubs keep the (unrouted) legacy pages compiling without\n * pretending to fetch anything.\n */\nconst NO_CONVERSATIONS: ConversationSummary[] = [];\n\nexport interface ConversationSummary {\n id: string;\n title: string;\n status: string;\n agentId?: string | null;\n messages: unknown[];\n updatedAt: string;\n}\n\nexport function useConversations(_filter?: Record<string, unknown>) {\n return { data: NO_CONVERSATIONS, loading: false, error: undefined };\n}\n\nexport function useConversation(_conversationId: string | undefined) {\n return { data: null, loading: false, error: undefined };\n}\n\nexport function useSendMessage() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [isSending, setIsSending] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const sendMessage = useCallback(\n async (input: { conversationId?: string; agentId: string; content: string }) => {\n setIsSending(true);\n setError(null);\n try {\n const result = await client.mutate<ChatWithAgentData>({\n mutation: CHAT_WITH_AGENT_DOCUMENT,\n variables: {\n input: {\n conversationId: input.conversationId ?? null,\n agentId: input.agentId,\n message: input.content,\n },\n },\n });\n\n const response = result.data?.chatWithAgent;\n if (!response) {\n throw new Error('Failed to send message');\n }\n\n return response;\n } catch (mutationError) {\n const nextError =\n mutationError instanceof Error ? mutationError : new Error('Failed to send message');\n setError(nextError);\n throw nextError;\n } finally {\n setIsSending(false);\n }\n },\n [client]\n );\n\n return {\n sendMessage,\n isSending,\n error,\n };\n}\n"],"mappings":";;;;AAIA,IAAM,IAA2B,CAAG;;;;;;;;;;;AA0BpC,SAAS,EAAmB,GAAkC;AAC5D,QAAO;;AAgBT,IAAM,IAA0C,EAAE;AAWlD,SAAgB,EAAiB,GAAmC;AAClE,QAAO;EAAE,MAAM;EAAkB,SAAS;EAAO,OAAO,KAAA;EAAW;;AAGrE,SAAgB,EAAgB,GAAqC;AACnE,QAAO;EAAE,MAAM;EAAM,SAAS;EAAO,OAAO,KAAA;EAAW;;AAGzD,SAAgB,IAAiB;CAC/B,IAAM,IAAS,EAAmB,EAAiB,YAAY,CAAC,EAC1D,CAAC,GAAW,KAAgB,EAAS,GAAM,EAC3C,CAAC,GAAO,KAAY,EAAuB,KAAK;AAoCtD,QAAO;EACL,aAnCkB,EAClB,OAAO,MAAyE;AAE9E,GADA,EAAa,GAAK,EAClB,EAAS,KAAK;AACd,OAAI;IAYF,IAAM,KAXS,MAAM,EAAO,OAA0B;KACpD,UAAU;KACV,WAAW,EACT,OAAO;MACL,gBAAgB,EAAM,kBAAkB;MACxC,SAAS,EAAM;MACf,SAAS,EAAM;MAChB,EACF;KACF,CAAC,EAEsB,MAAM;AAC9B,QAAI,CAAC,EACH,OAAU,MAAM,yBAAyB;AAG3C,WAAO;YACA,GAAe;IACtB,IAAM,IACJ,aAAyB,QAAQ,IAAgB,gBAAI,MAAM,yBAAyB;AAEtF,UADA,EAAS,EAAU,EACb;aACE;AACR,MAAa,GAAM;;KAGvB,CAAC,EAAO,CACT;EAIC;EACA;EACD"}
@@ -0,0 +1,86 @@
1
+ import { buildMutationInput as e, fieldsOf as t } from "./internal/mutationInput.js";
2
+ import { CreateExecutionDocument as n, GetExecutionDocument as r, ListExecutionsDocument as i } from "../../generated/wspace-operations.js";
3
+ import { useWorkspaceId as a, useWorkspaceMutation as o, useWorkspaceQuery as s } from "./internal/workspaceGateway.js";
4
+ import { useCallback as c, useMemo as l } from "react";
5
+ //#region src/botlit/hooks/useExecutions.ts
6
+ var u = 100, d = t({
7
+ agentId: !0,
8
+ appId: !0,
9
+ conversationId: !0,
10
+ input: !0,
11
+ metadata: !0,
12
+ type: !0,
13
+ workspaceId: !0
14
+ }), f = new Set(["COMPLETED"]), p = [];
15
+ function m(e, t) {
16
+ return e.id.toLowerCase().includes(t) || (e.agentId ?? "").toLowerCase().includes(t) || (e.appId ?? "").toLowerCase().includes(t) || e.input.toLowerCase().includes(t);
17
+ }
18
+ function h(e) {
19
+ let t = a(), n = e?.search?.trim().toLowerCase() ?? "", r = e?.status, o = r?.length === 1 ? r[0] : void 0, d = r?.join(",") ?? "", { agentId: f, appId: h, conversationId: g, type: _ } = e ?? {};
20
+ return s({
21
+ document: i,
22
+ variables: l(() => ({
23
+ filters: {
24
+ workspaceId: t,
25
+ status: o,
26
+ agentId: f,
27
+ appId: h,
28
+ conversationId: g,
29
+ type: _
30
+ },
31
+ pagination: {
32
+ limit: u,
33
+ offset: 0
34
+ }
35
+ }), [
36
+ t,
37
+ o,
38
+ f,
39
+ h,
40
+ g,
41
+ _
42
+ ]),
43
+ select: c((e) => {
44
+ let t = e?.listExecutions ?? p, r = d ? new Set(d.split(",")) : void 0, i = r && r.size > 1 ? t.filter((e) => r.has(e.status)) : t;
45
+ return n ? i.filter((e) => m(e, n)) : i;
46
+ }, [n, d]),
47
+ fallback: p,
48
+ enabled: !!t,
49
+ errorMessage: "Failed to load executions"
50
+ });
51
+ }
52
+ function g(e) {
53
+ return s({
54
+ document: r,
55
+ variables: l(() => ({ id: e ?? "" }), [e]),
56
+ select: (e) => e?.getExecution ?? null,
57
+ fallback: null,
58
+ enabled: !!e,
59
+ errorMessage: "Failed to load execution"
60
+ });
61
+ }
62
+ function _(e) {
63
+ let t = e.length, n = 0, r = 0, i = 0, a = 0, o = 0, s = 0;
64
+ for (let t of e) f.has(t.status) && (n += 1), (t.status === "FAILED" || t.status === "TIMEOUT") && (r += 1), typeof t.duration == "number" && (i += t.duration, a += 1), o += t.cost ?? 0, s += t.tokensUsed ?? 0;
65
+ return {
66
+ total: t,
67
+ succeeded: n,
68
+ failed: r,
69
+ successRate: t > 0 ? n / t : 0,
70
+ avgDurationMs: a > 0 ? i / a : 0,
71
+ totalCost: o,
72
+ totalTokens: s
73
+ };
74
+ }
75
+ function v() {
76
+ return o({
77
+ document: n,
78
+ variables: ({ input: t }) => ({ input: e(t, d) }),
79
+ select: (e) => e?.createExecution,
80
+ errorMessage: "Failed to start execution"
81
+ });
82
+ }
83
+ //#endregion
84
+ export { _ as summariseExecutions, v as useCreateExecution, g as useExecution, h as useExecutions };
85
+
86
+ //# sourceMappingURL=useExecutions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useExecutions.js","names":[],"sources":["../../../src/botlit/hooks/useExecutions.ts"],"sourcesContent":["/**\n * Executions Hooks\n * @module botlit/hooks\n *\n * Backed by the live `listExecutions` / `getExecution` / `getExecutionMetrics`\n * operations plus the `createExecution` / `updateExecutionStatus` mutations on\n * wspace-botlit-svc.\n *\n * Note on filtering: `ExecutionFilterInput` accepts a SINGLE status and has no\n * free-text field, so multi-status selections and search are narrowed on the\n * client over the fetched page.\n */\n\nimport { useCallback, useMemo } from 'react';\nimport {\n CreateExecutionDocument,\n GetExecutionDocument,\n GetExecutionMetricsDocument,\n ListExecutionsDocument,\n UpdateExecutionStatusDocument,\n type CreateExecutionMutation,\n type GetExecutionMetricsQuery,\n type GetExecutionQuery,\n type ListExecutionsQuery,\n type UpdateExecutionStatusMutation,\n} from '../../generated/wspace-operations';\nimport type { CreateExecutionInput } from '../../generated/wspace-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 ExecutionRecord {\n id: string;\n status: string;\n type: string;\n input: string;\n output?: string | null;\n agentId?: string | null;\n appId?: string | null;\n conversationId?: string | null;\n cost?: number | null;\n duration?: number | null;\n tokensUsed?: number | null;\n errorCode?: string | null;\n errorMessage?: string | null;\n errorDetails?: Record<string, unknown> | null;\n metadata?: Record<string, unknown> | null;\n completedAt?: string | null;\n createdAt: string;\n workspaceId: string;\n}\n\nexport interface ExecutionMetricsRecord {\n executionId: string;\n cost: number;\n inputTokens: number;\n outputTokens: number;\n totalTokens: number;\n ragChunks: number;\n toolCalls: number;\n}\n\nexport interface ExecutionsFilter {\n search?: string;\n status?: string[];\n agentId?: string;\n appId?: string;\n conversationId?: string;\n type?: string;\n}\n\nexport interface ExecutionMetricsFilter {\n agentId?: string;\n appId?: string;\n startDate?: string;\n endDate?: string;\n}\n\nexport interface CreateExecutionVariables {\n input: GraphQLInput<CreateExecutionInput>;\n}\n\nconst CREATE_EXECUTION_FIELDS = fieldsOf<CreateExecutionInput>({\n agentId: true,\n appId: true,\n conversationId: true,\n input: true,\n metadata: true,\n type: true,\n workspaceId: true,\n});\n\nexport interface UpdateExecutionStatusVariables {\n id: string;\n status: string;\n output?: string;\n error?: Record<string, unknown>;\n}\n\n/** Terminal statuses that count as a successful run. */\nconst SUCCESS_STATUSES = new Set(['COMPLETED']);\n\nconst NO_EXECUTIONS: ExecutionRecord[] = [];\n\nexport const executionKeys = {\n all: ['executions'] as const,\n lists: () => [...executionKeys.all, 'list'] as const,\n list: (filter?: ExecutionsFilter) => [...executionKeys.lists(), filter] as const,\n details: () => [...executionKeys.all, 'detail'] as const,\n detail: (id: string) => [...executionKeys.details(), id] as const,\n metrics: () => [...executionKeys.all, 'metrics'] as const,\n};\n\nfunction matchesSearch(execution: ExecutionRecord, needle: string): boolean {\n return (\n execution.id.toLowerCase().includes(needle) ||\n (execution.agentId ?? '').toLowerCase().includes(needle) ||\n (execution.appId ?? '').toLowerCase().includes(needle) ||\n execution.input.toLowerCase().includes(needle)\n );\n}\n\nexport function useExecutions(filter?: ExecutionsFilter): QueryResult<ExecutionRecord[]> {\n const workspaceId = useWorkspaceId();\n const search = filter?.search?.trim().toLowerCase() ?? '';\n const statuses = filter?.status;\n const singleStatus = statuses?.length === 1 ? statuses[0] : undefined;\n const statusKey = statuses?.join(',') ?? '';\n const { agentId, appId, conversationId, type } = filter ?? {};\n\n const variables = useMemo(\n () => ({\n filters: {\n workspaceId,\n status: singleStatus,\n agentId,\n appId,\n conversationId,\n type,\n },\n pagination: { limit: LIST_LIMIT, offset: 0 },\n }),\n [workspaceId, singleStatus, agentId, appId, conversationId, type]\n );\n\n const select = useCallback(\n (data: ListExecutionsQuery | undefined): ExecutionRecord[] => {\n const rows: ExecutionRecord[] = data?.listExecutions ?? NO_EXECUTIONS;\n const wanted = statusKey ? new Set(statusKey.split(',')) : undefined;\n const narrowed =\n // A single status is already applied server-side.\n wanted && wanted.size > 1 ? rows.filter((row) => wanted.has(row.status)) : rows;\n return search ? narrowed.filter((row) => matchesSearch(row, search)) : narrowed;\n },\n [search, statusKey]\n );\n\n return useWorkspaceQuery<ListExecutionsQuery, ExecutionRecord[]>({\n document: ListExecutionsDocument,\n variables,\n select,\n fallback: NO_EXECUTIONS,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load executions',\n });\n}\n\nexport function useExecution(executionId: string | undefined): QueryResult<ExecutionRecord | null> {\n const variables = useMemo(() => ({ id: executionId ?? '' }), [executionId]);\n\n return useWorkspaceQuery<GetExecutionQuery, ExecutionRecord | null>({\n document: GetExecutionDocument,\n variables,\n select: (data) => data?.getExecution ?? null,\n fallback: null,\n enabled: Boolean(executionId),\n errorMessage: 'Failed to load execution',\n });\n}\n\n/**\n * Token/cost metrics for the workspace, optionally narrowed to an agent, app or\n * date window. Returns `null` when the service has nothing recorded yet.\n */\nexport function useExecutionMetrics(\n filter?: ExecutionMetricsFilter\n): QueryResult<ExecutionMetricsRecord | null> {\n const workspaceId = useWorkspaceId();\n const { agentId, appId, startDate, endDate } = filter ?? {};\n\n const variables = useMemo(\n () => ({ filter: { workspaceId, agentId, appId, startDate, endDate } }),\n [workspaceId, agentId, appId, startDate, endDate]\n );\n\n return useWorkspaceQuery<GetExecutionMetricsQuery, ExecutionMetricsRecord | null>({\n document: GetExecutionMetricsDocument,\n variables,\n select: (data) => data?.getExecutionMetrics ?? null,\n fallback: null,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load execution metrics',\n });\n}\n\nexport interface ExecutionRollup {\n total: number;\n succeeded: number;\n failed: number;\n successRate: number;\n avgDurationMs: number;\n totalCost: number;\n totalTokens: number;\n}\n\n/**\n * Rolls a list of executions up into the headline numbers shown above the table.\n * Derived purely from the rows that were actually loaded — no server aggregate\n * exists for this, so callers must label it as such.\n */\nexport function summariseExecutions(executions: readonly ExecutionRecord[]): ExecutionRollup {\n const total = executions.length;\n let succeeded = 0;\n let failed = 0;\n let durationSum = 0;\n let durationCount = 0;\n let totalCost = 0;\n let totalTokens = 0;\n\n for (const execution of executions) {\n if (SUCCESS_STATUSES.has(execution.status)) succeeded += 1;\n if (execution.status === 'FAILED' || execution.status === 'TIMEOUT') failed += 1;\n if (typeof execution.duration === 'number') {\n durationSum += execution.duration;\n durationCount += 1;\n }\n totalCost += execution.cost ?? 0;\n totalTokens += execution.tokensUsed ?? 0;\n }\n\n return {\n total,\n succeeded,\n failed,\n successRate: total > 0 ? succeeded / total : 0,\n avgDurationMs: durationCount > 0 ? durationSum / durationCount : 0,\n totalCost,\n totalTokens,\n };\n}\n\nexport function useCreateExecution() {\n return useWorkspaceMutation<CreateExecutionMutation, CreateExecutionVariables, ExecutionRecord>({\n document: CreateExecutionDocument,\n variables: ({ input }) => ({ input: buildMutationInput(input, CREATE_EXECUTION_FIELDS) }),\n select: (data) => data?.createExecution,\n errorMessage: 'Failed to start execution',\n });\n}\n\nexport function useUpdateExecutionStatus() {\n return useWorkspaceMutation<\n UpdateExecutionStatusMutation,\n UpdateExecutionStatusVariables,\n ExecutionRecord\n >({\n document: UpdateExecutionStatusDocument,\n variables: ({ id, status, output, error }) => ({ id, status, output, error }),\n select: (data) => data?.updateExecutionStatus,\n errorMessage: 'Failed to update execution status',\n });\n}\n"],"mappings":";;;;;AAmCA,IAAM,IAAa,KAqDb,IAA0B,EAA+B;CAC7D,SAAS;CACT,OAAO;CACP,gBAAgB;CAChB,OAAO;CACP,UAAU;CACV,MAAM;CACN,aAAa;CACd,CAAC,EAUI,IAAmB,IAAI,IAAI,CAAC,YAAY,CAAC,EAEzC,IAAmC,EAAE;AAW3C,SAAS,EAAc,GAA4B,GAAyB;AAC1E,QACE,EAAU,G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CJ,SAAgB,EAAoB,GAAyD;CAC3F,IAAM,IAAQ,EAAW,QACrB,IAAY,GACZ,IAAS,GACT,IAAc,GACd,IAAgB,GAChB,IAAY,GACZ,IAAc;AAElB,MAAK,IAAM,KAAa,EAQtB,CAPI,EAAiB,IAAI,EAAU,OAAO,KAAE,KAAa,KACrD,EAAU,WAAW,YAAY,EAAU,WAAW,eAAW,KAAU,IAC3E,OAAO,EAAU,YAAa,aAChC,KAAe,EAAU,UACzB,KAAiB,IAEnB,KAAa,EAAU,QAAQ,GAC/B,KAAe,EAAU,cAAc;AAGzC,QAAO;EACL;EACA;EACA;EACA,aAAa,IAAQ,IAAI,IAAY,IAAQ;EAC7C,eAAe,IAAgB,IAAI,IAAc,IAAgB;EACjE;EACA;EACD;;AAGH,SAAgB,IAAqB;AACnC,QAAO,EAAyF;EAC9F,UAAU;EACV,YAAY,EAAE,gBAAa,EAAE,OAAO,EAAmB,GAAO,EAAwB,EAAE;EACxF,SAAS,MAAS,GAAM;EACxB,cAAc;EACf,CAAC"}
@@ -0,0 +1,113 @@
1
+ import { buildMutationInput as e, fieldsOf as t } from "./internal/mutationInput.js";
2
+ import { CreateKnowledgeBaseDocument as n, GetKnowledgeBaseDocument as r, ListKnowledgeBasesDocument as i, ListKnowledgeDocumentsDocument as a, RebuildKnowledgeBaseIndexDocument as o, UpdateKnowledgeBaseDocument as s } from "../../generated/wspace-operations.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";
5
+ //#region src/botlit/hooks/useKnowledgeBases.ts
6
+ var p = 100, m = t({
7
+ chunkOverlap: !0,
8
+ chunkSize: !0,
9
+ chunkingStrategy: !0,
10
+ description: !0,
11
+ embeddingDimensions: !0,
12
+ embeddingModel: !0,
13
+ metadata: !0,
14
+ name: !0,
15
+ workspaceId: !0
16
+ }), h = t({
17
+ chunkOverlap: !0,
18
+ chunkSize: !0,
19
+ chunkingStrategy: !0,
20
+ description: !0,
21
+ metadata: !0,
22
+ name: !0
23
+ }), g = [], _ = [];
24
+ function v(e) {
25
+ return e?.listKnowledgeBases ?? g;
26
+ }
27
+ function y(e) {
28
+ return e?.getKnowledgeBase ?? null;
29
+ }
30
+ function b(e) {
31
+ return e?.listKnowledgeDocuments ?? _;
32
+ }
33
+ function x(e) {
34
+ let t = c(), n = e?.search;
35
+ return u({
36
+ document: i,
37
+ variables: f(() => ({
38
+ filters: {
39
+ workspaceId: t,
40
+ search: n || void 0
41
+ },
42
+ pagination: {
43
+ limit: p,
44
+ offset: 0
45
+ }
46
+ }), [t, n]),
47
+ select: v,
48
+ fallback: g,
49
+ enabled: !!t,
50
+ errorMessage: "Failed to load knowledge bases"
51
+ });
52
+ }
53
+ function S(e) {
54
+ return u({
55
+ document: r,
56
+ variables: f(() => ({ id: e ?? "" }), [e]),
57
+ select: y,
58
+ fallback: null,
59
+ enabled: !!e,
60
+ errorMessage: "Failed to load knowledge base"
61
+ });
62
+ }
63
+ function C(e) {
64
+ return u({
65
+ document: a,
66
+ variables: f(() => ({
67
+ knowledgeBaseId: e ?? "",
68
+ pagination: {
69
+ limit: p,
70
+ offset: 0
71
+ }
72
+ }), [e]),
73
+ select: b,
74
+ fallback: _,
75
+ enabled: !!e,
76
+ errorMessage: "Failed to load knowledge documents"
77
+ });
78
+ }
79
+ function w() {
80
+ let t = c();
81
+ return l({
82
+ document: n,
83
+ variables: d((n) => ({ input: e({
84
+ ...n,
85
+ workspaceId: t
86
+ }, m) }), [t]),
87
+ select: (e) => e?.createKnowledgeBase,
88
+ errorMessage: "Failed to create knowledge base"
89
+ });
90
+ }
91
+ function T() {
92
+ return l({
93
+ document: s,
94
+ variables: ({ kbId: t, input: n }) => ({
95
+ id: t,
96
+ input: e(n, h)
97
+ }),
98
+ select: (e) => e?.updateKnowledgeBase,
99
+ errorMessage: "Failed to update knowledge base"
100
+ });
101
+ }
102
+ function E() {
103
+ return l({
104
+ document: o,
105
+ variables: (e) => ({ knowledgeBaseId: e }),
106
+ select: (e) => e?.rebuildKnowledgeBaseIndex,
107
+ errorMessage: "Failed to rebuild the knowledge base index"
108
+ });
109
+ }
110
+ //#endregion
111
+ export { w as useCreateKnowledgeBase, S as useKnowledgeBase, x as useKnowledgeBases, C as useKnowledgeDocuments, E as useRebuildKnowledgeBaseIndex, T as useUpdateKnowledgeBase };
112
+
113
+ //# sourceMappingURL=useKnowledgeBases.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useKnowledgeBases.js","names":[],"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 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,IAAM,IAAa,KAoDb,IAAmB,EAAmC;CAC1D,cAAc;CACd,WAAW;CACX,kBAAkB;CAClB,aAAa;CACb,qBAAqB;CACrB,gBAAgB;CA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O;GAAa,EAAE,EAAiB,EACvE,GACD,CAAC,EAAY,CACd;EASC,SAAS,MAAS,GAAM;EACxB,cAAc;EACf,CAAC;;AAGJ,SAAgB,IAAyB;AACvC,QAAO,EAIL;EACA,UAAU;EACV,YAAY,EAAE,SAAM,gBAAa;GAC/B,IAAI;GACJ,OAAO,EAAmB,GAAO,EAAiB;GACnD;EACD,SAAS,MAAS,GAAM;EACxB,cAAc;EACf,CAAC;;AAIJ,SAAgB,IAA+B;AAC7C,QAAO,EAAyE;EAC9E,UAAU;EACV,YAAY,OAAU,EAAE,iBAAiB,GAAM;EAC/C,SAAS,MAAS,GAAM;EACxB,cAAc;EACf,CAAC"}
@@ -0,0 +1,83 @@
1
+ import { buildMutationInput as e, fieldsOf as t } from "./internal/mutationInput.js";
2
+ import { CreateBotlitLlmProviderDocument as n, ListLlmModelsDocument as r, ListLlmProvidersDocument as i, UpdateLlmProviderDocument as a } from "../../generated/wspace-operations.js";
3
+ import { useWorkspaceId as o, useWorkspaceMutation as s, useWorkspaceQuery as c } from "./internal/workspaceGateway.js";
4
+ import { useCallback as l, useMemo as u } from "react";
5
+ //#region src/botlit/hooks/useLLMProviders.ts
6
+ var d = 50, f = [], p = [], m = t({
7
+ apiEndpoint: !0,
8
+ connectionId: !0,
9
+ credentials: !0,
10
+ metadata: !0,
11
+ name: !0,
12
+ type: !0,
13
+ workspaceId: !0
14
+ }), h = t({
15
+ apiEndpoint: !0,
16
+ connectionId: !0,
17
+ credentials: !0,
18
+ isActive: !0,
19
+ metadata: !0,
20
+ name: !0
21
+ });
22
+ function g() {
23
+ let e = o();
24
+ return c({
25
+ document: i,
26
+ variables: u(() => ({ pagination: {
27
+ limit: d,
28
+ offset: 0
29
+ } }), []),
30
+ select: (e) => e?.listLLMProviders ?? f,
31
+ fallback: f,
32
+ enabled: !!e,
33
+ errorMessage: "Failed to load LLM providers"
34
+ });
35
+ }
36
+ function _(e) {
37
+ let t = o(), n = e?.providerId;
38
+ return c({
39
+ document: r,
40
+ variables: u(() => ({
41
+ filters: n ? { providerId: n } : void 0,
42
+ pagination: {
43
+ limit: d,
44
+ offset: 0
45
+ }
46
+ }), [n]),
47
+ select: (e) => e?.listLLMModels ?? p,
48
+ fallback: p,
49
+ enabled: !!t,
50
+ errorMessage: "Failed to load LLM models"
51
+ });
52
+ }
53
+ function v() {
54
+ let t = o(), [r, i] = s({
55
+ document: n,
56
+ variables: (n) => ({ input: e({
57
+ ...n,
58
+ workspaceId: t
59
+ }, m) }),
60
+ select: (e) => e?.createBotlitLLMProvider,
61
+ errorMessage: "Failed to create the LLM provider"
62
+ }), [c, u] = s({
63
+ document: a,
64
+ variables: ({ providerId: t, input: n }) => ({
65
+ id: t,
66
+ input: e(n, h)
67
+ }),
68
+ select: (e) => e?.updateLLMProvider,
69
+ errorMessage: "Failed to update the LLM provider"
70
+ });
71
+ return {
72
+ configureProvider: l(async (e, t) => t ? c({
73
+ providerId: t,
74
+ input: e
75
+ }) : r(e), [r, c]),
76
+ isConfiguring: i.loading || u.loading,
77
+ error: i.error ?? u.error
78
+ };
79
+ }
80
+ //#endregion
81
+ export { v as useConfigureLLMProvider, _ as useLLMModels, g as useLLMProviders };
82
+
83
+ //# sourceMappingURL=useLLMProviders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLLMProviders.js","names":[],"sources":["../../../src/botlit/hooks/useLLMProviders.ts"],"sourcesContent":["/**\n * LLM Providers Hooks\n * @module botlit/hooks\n *\n * These go through the shell's workspace gateway client like every other Botlit\n * hook. They deliberately do NOT use the generated `useQuery`/`useMutation`\n * wrappers: `BotmanorRoot` only mounts an `<ApolloProvider>` in standalone mode,\n * so an Apollo React hook throws \"Could not find client in the context\" the\n * moment the MFE is mounted by an app shell — which is every production route.\n */\n\nimport { useCallback, useMemo } from 'react';\nimport {\n CreateBotlitLlmProviderDocument,\n DeleteLlmProviderDocument,\n GetLlmProviderDocument,\n ListLlmModelsDocument,\n ListLlmProvidersDocument,\n TestLlmConnectionDocument,\n UpdateLlmProviderDocument,\n type CreateBotlitLlmProviderMutation,\n type DeleteLlmProviderMutation,\n type GetLlmProviderQuery,\n type ListLlmModelsQuery,\n type ListLlmProvidersQuery,\n type TestLlmConnectionMutation,\n type UpdateLlmProviderMutation,\n} from '../../generated/wspace-operations';\nimport type {\n CreateBotlitLlmModelInput,\n CreateBotlitLlmProviderInput,\n UpdateBotlitLlmProviderInput,\n} from '../../generated/wspace-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 = 50;\n\nexport interface LLMProviderRecord {\n id: string;\n name: string;\n type: string;\n isActive: boolean;\n apiEndpoint?: string | null;\n credentialsHash?: string | null;\n connectionId?: string | null;\n metadata?: Record<string, unknown> | null;\n createdAt: string;\n updatedAt: string;\n workspaceId: string;\n}\n\nexport interface LLMModelRecord {\n id: string;\n name: string;\n modelId: string;\n providerId: string;\n contextWindow: number;\n maxOutputTokens: number;\n inputPricePerMToken: number;\n outputPricePerMToken: number;\n isActive: boolean;\n supportsStreaming: boolean;\n supportsFunctionCalling: boolean;\n supportsVision: boolean;\n createdAt: string;\n updatedAt: string;\n}\n\n/** `CreateBotlitLLMProviderInput` minus the `workspaceId` the hook supplies. */\nexport type ConfigureLLMProviderVariables = Omit<\n GraphQLInput<CreateBotlitLlmProviderInput>,\n 'workspaceId'\n>;\n\nconst NO_PROVIDERS: LLMProviderRecord[] = [];\nconst NO_MODELS: LLMModelRecord[] = [];\n\nconst CREATE_PROVIDER_FIELDS = fieldsOf<CreateBotlitLlmProviderInput>({\n apiEndpoint: true,\n connectionId: true,\n credentials: true,\n metadata: true,\n name: true,\n type: true,\n workspaceId: true,\n});\n\nconst UPDATE_PROVIDER_FIELDS = fieldsOf<UpdateBotlitLlmProviderInput>({\n apiEndpoint: true,\n connectionId: true,\n credentials: true,\n isActive: true,\n metadata: true,\n name: true,\n});\n\nexport const llmProviderKeys = {\n all: ['llmProviders'] as const,\n lists: () => [...llmProviderKeys.all, 'list'] as const,\n details: () => [...llmProviderKeys.all, 'detail'] as const,\n detail: (id: string) => [...llmProviderKeys.details(), id] as const,\n};\n\nexport function useLLMProviders(): QueryResult<LLMProviderRecord[]> {\n const workspaceId = useWorkspaceId();\n\n const variables = useMemo(() => ({ pagination: { limit: LIST_LIMIT, offset: 0 } }), []);\n\n return useWorkspaceQuery<ListLlmProvidersQuery, LLMProviderRecord[]>({\n document: ListLlmProvidersDocument,\n variables,\n select: (data) => data?.listLLMProviders ?? NO_PROVIDERS,\n fallback: NO_PROVIDERS,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load LLM providers',\n });\n}\n\nexport function useLLMProvider(\n providerId: string | undefined\n): QueryResult<LLMProviderRecord | null> {\n const variables = useMemo(() => ({ id: providerId ?? '' }), [providerId]);\n\n return useWorkspaceQuery<GetLlmProviderQuery, LLMProviderRecord | null>({\n document: GetLlmProviderDocument,\n variables,\n select: (data) => data?.getLLMProvider ?? null,\n fallback: null,\n enabled: Boolean(providerId),\n errorMessage: 'Failed to load LLM provider',\n });\n}\n\nexport function useLLMModels(filters?: { providerId?: string }): QueryResult<LLMModelRecord[]> {\n const workspaceId = useWorkspaceId();\n const providerId = filters?.providerId;\n\n const variables = useMemo(\n () => ({\n filters: providerId ? { providerId } : undefined,\n pagination: { limit: LIST_LIMIT, offset: 0 },\n }),\n [providerId]\n );\n\n return useWorkspaceQuery<ListLlmModelsQuery, LLMModelRecord[]>({\n document: ListLlmModelsDocument,\n variables,\n select: (data) => data?.listLLMModels ?? NO_MODELS,\n fallback: NO_MODELS,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load LLM models',\n });\n}\n\n/**\n * Creates a provider, or updates the one whose id the caller passes.\n * `UpdateBotlitLLMProviderInput` has no `type`/`workspaceId`, so the update\n * payload is projected onto the fields that input actually declares.\n */\nexport function useConfigureLLMProvider() {\n const workspaceId = useWorkspaceId();\n\n const [create, createState] = useWorkspaceMutation<\n CreateBotlitLlmProviderMutation,\n ConfigureLLMProviderVariables,\n LLMProviderRecord\n >({\n document: CreateBotlitLlmProviderDocument,\n variables: (input) => ({\n input: buildMutationInput({ ...input, workspaceId }, CREATE_PROVIDER_FIELDS),\n }),\n select: (data) => data?.createBotlitLLMProvider,\n errorMessage: 'Failed to create the LLM provider',\n });\n\n const [update, updateState] = useWorkspaceMutation<\n UpdateLlmProviderMutation,\n { providerId: string; input: ConfigureLLMProviderVariables },\n LLMProviderRecord\n >({\n document: UpdateLlmProviderDocument,\n variables: ({ providerId, input }) => ({\n id: providerId,\n input: buildMutationInput(input, UPDATE_PROVIDER_FIELDS),\n }),\n select: (data) => data?.updateLLMProvider,\n errorMessage: 'Failed to update the LLM provider',\n });\n\n const configureProvider = useCallback(\n async (input: ConfigureLLMProviderVariables, existingId?: string) =>\n existingId ? update({ providerId: existingId, input }) : create(input),\n [create, update]\n );\n\n return {\n configureProvider,\n isConfiguring: createState.loading || updateState.loading,\n error: createState.error ?? updateState.error,\n };\n}\n\nexport function useDeleteLLMProvider() {\n return useWorkspaceMutation<DeleteLlmProviderMutation, string, boolean>({\n document: DeleteLlmProviderDocument,\n variables: (providerId) => ({ id: providerId }),\n select: (data) => data?.deleteLLMProvider,\n errorMessage: 'Failed to delete the LLM provider',\n });\n}\n\nexport function useTestLLMConnection() {\n return useWorkspaceMutation<TestLlmConnectionMutation, string, boolean>({\n document: TestLlmConnectionDocument,\n variables: (providerId) => ({ id: providerId }),\n select: (data) => data?.testLlmConnection,\n errorMessage: 'Failed to test the LLM connection',\n });\n}\n\n/**\n * `createBotlitLLMModel` is not published on the supergraph — models are\n * catalogued by the service, so the UI cannot add custom ones yet.\n */\nexport function useCreateLLMModel() {\n const createModel = useCallback(async (_input: CreateBotlitLlmModelInput): Promise<never> => {\n throw new Error(\"Custom model creation isn't available yet.\");\n }, []);\n\n return { createModel, isCreating: false, error: undefined };\n}\n"],"mappings":";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C;AAQF,QAAO;EACL,mBAPwB,EACxB,OAAO,GAAsC,MAC3C,IAAa,EAAO;GAAE,YAAY;GAAY;GAAO,CAAC,GAAG,EAAO,EAAM,EACxE,CAAC,GAAQ,EAAO,CACjB;EAIC,eAAe,EAAY,WAAW,EAAY;EAClD,OAAO,EAAY,SAAS,EAAY;EACzC"}
@@ -0,0 +1,134 @@
1
+ import { buildMutationInput as e, fieldsOf as t } from "./internal/mutationInput.js";
2
+ import { CreateMcpConnectionDocument as n, DeleteMcpConnectionDocument as r, GetMcpConnectionDocument as i, ListMcpConnectionsDocument as a, ListMcpResourcesDocument as o, ListMcpToolsDocument as s, TestMcpConnectionDocument as c, UpdateMcpConnectionDocument as l } from "../../generated/wspace-operations.js";
3
+ import { useWorkspaceId as u, useWorkspaceMutation as d, useWorkspaceQuery as f } from "./internal/workspaceGateway.js";
4
+ import { useCallback as p, useMemo as m } from "react";
5
+ //#region src/botlit/hooks/useMCPServers.ts
6
+ var h = 100, g = t({
7
+ config: !0,
8
+ credentials: !0,
9
+ metadata: !0,
10
+ name: !0,
11
+ type: !0,
12
+ workspaceId: !0
13
+ }), _ = t({
14
+ config: !0,
15
+ credentials: !0,
16
+ metadata: !0,
17
+ name: !0
18
+ }), v = [], y = [], b = [];
19
+ function x(e) {
20
+ return e === "CONNECTED";
21
+ }
22
+ function S(e) {
23
+ let t = e.config?.url;
24
+ return typeof t == "string" ? t : void 0;
25
+ }
26
+ function C(e) {
27
+ let t = e.config?.description;
28
+ return typeof t == "string" ? t : void 0;
29
+ }
30
+ function w(e) {
31
+ return e?.listMCPConnections ?? v;
32
+ }
33
+ function T(e) {
34
+ return e?.getMCPConnection ?? null;
35
+ }
36
+ function E(e) {
37
+ return e?.listMCPTools ?? y;
38
+ }
39
+ function D(e) {
40
+ return e?.listMCPResources ?? b;
41
+ }
42
+ function O(e) {
43
+ let t = u(), n = e?.search?.trim().toLowerCase() ?? "";
44
+ return f({
45
+ document: a,
46
+ variables: m(() => ({
47
+ filters: { workspaceId: t },
48
+ pagination: {
49
+ limit: h,
50
+ offset: 0
51
+ }
52
+ }), [t]),
53
+ select: p((e) => {
54
+ let t = w(e);
55
+ return n ? t.filter((e) => e.name.toLowerCase().includes(n)) : t;
56
+ }, [n]),
57
+ fallback: v,
58
+ enabled: !!t,
59
+ errorMessage: "Failed to load MCP servers"
60
+ });
61
+ }
62
+ function k(e) {
63
+ return f({
64
+ document: i,
65
+ variables: m(() => ({ id: e ?? "" }), [e]),
66
+ select: T,
67
+ fallback: null,
68
+ enabled: !!e,
69
+ errorMessage: "Failed to load MCP server"
70
+ });
71
+ }
72
+ function A(e) {
73
+ return f({
74
+ document: s,
75
+ variables: m(() => ({ connectionId: e ?? "" }), [e]),
76
+ select: E,
77
+ fallback: y,
78
+ enabled: !!e,
79
+ errorMessage: "Failed to load MCP tools"
80
+ });
81
+ }
82
+ function j(e) {
83
+ return f({
84
+ document: o,
85
+ variables: m(() => ({ connectionId: e ?? "" }), [e]),
86
+ select: D,
87
+ fallback: b,
88
+ enabled: !!e,
89
+ errorMessage: "Failed to load MCP resources"
90
+ });
91
+ }
92
+ function M() {
93
+ let t = u();
94
+ return d({
95
+ document: n,
96
+ variables: p((n) => ({ input: e({
97
+ ...n,
98
+ workspaceId: t
99
+ }, g) }), [t]),
100
+ select: (e) => e?.createMCPConnection,
101
+ errorMessage: "Failed to connect MCP server"
102
+ });
103
+ }
104
+ function N() {
105
+ return d({
106
+ document: l,
107
+ variables: ({ serverId: t, input: n }) => ({
108
+ id: t,
109
+ input: e(n, _)
110
+ }),
111
+ select: (e) => e?.updateMCPConnection,
112
+ errorMessage: "Failed to update MCP server"
113
+ });
114
+ }
115
+ function P() {
116
+ return d({
117
+ document: r,
118
+ variables: (e) => ({ id: e }),
119
+ select: (e) => e?.deleteMCPConnection,
120
+ errorMessage: "Failed to disconnect MCP server"
121
+ });
122
+ }
123
+ function F() {
124
+ return d({
125
+ document: c,
126
+ variables: (e) => ({ id: e }),
127
+ select: (e) => e?.testMCPConnection,
128
+ errorMessage: "Failed to test MCP connection"
129
+ });
130
+ }
131
+ //#endregion
132
+ export { x as isMCPServerHealthy, C as mcpServerDescription, S as mcpServerEndpoint, M as useCreateMCPServer, P as useDeleteMCPServer, j as useMCPResources, k as useMCPServer, O as useMCPServers, A as useMCPTools, F as useTestMCPConnection, N as useUpdateMCPServer };
133
+
134
+ //# sourceMappingURL=useMCPServers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMCPServers.js","names":[],"sources":["../../../src/botlit/hooks/useMCPServers.ts"],"sourcesContent":["/**\n * MCP Servers Hooks\n * @module botlit/hooks\n *\n * Backed by the live `listMCPConnections` / `getMCPConnection` / `listMCPTools`\n * / `listMCPResources` operations and the create/update/delete/test mutations on\n * wspace-botlit-svc.\n *\n * The service models an MCP server as an `MCPConnection`: `type` is the\n * transport, `config` holds the endpoint, and `status` reports health.\n */\n\nimport { useCallback, useMemo } from 'react';\nimport {\n CreateMcpConnectionDocument,\n DeleteMcpConnectionDocument,\n GetMcpConnectionDocument,\n ListMcpConnectionsDocument,\n ListMcpResourcesDocument,\n ListMcpToolsDocument,\n TestMcpConnectionDocument,\n UpdateMcpConnectionDocument,\n type CreateMcpConnectionMutation,\n type DeleteMcpConnectionMutation,\n type GetMcpConnectionQuery,\n type ListMcpConnectionsQuery,\n type ListMcpResourcesQuery,\n type ListMcpToolsQuery,\n type TestMcpConnectionMutation,\n type UpdateMcpConnectionMutation,\n} from '../../generated/wspace-operations';\nimport type {\n CreateMcpConnectionInput,\n UpdateMcpConnectionInput,\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 MCPServerRecord {\n id: string;\n name: string;\n /** Transport / server kind, e.g. `HTTP_JSON`. */\n type: string;\n status: string;\n config: Record<string, unknown>;\n credentialsHash?: string | null;\n errorMessage?: string | null;\n lastConnectedAt?: string | null;\n lastErrorAt?: string | null;\n deletedAt?: 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 MCPToolRecord {\n name: string;\n description: string;\n inputSchema: Record<string, unknown>;\n}\n\nexport interface MCPResourceRecord {\n name: string;\n uri: string;\n description?: string | null;\n mimeType?: string | null;\n}\n\n/** `CreateMCPConnectionInput` minus the `workspaceId` the hook supplies. */\nexport type CreateMCPServerVariables = Omit<GraphQLInput<CreateMcpConnectionInput>, 'workspaceId'>;\n\nexport interface UpdateMCPServerVariables {\n serverId: string;\n input: GraphQLInput<UpdateMcpConnectionInput>;\n}\n\nconst CREATE_CONNECTION_FIELDS = fieldsOf<CreateMcpConnectionInput>({\n config: true,\n credentials: true,\n metadata: true,\n name: true,\n type: true,\n workspaceId: true,\n});\n\nconst UPDATE_CONNECTION_FIELDS = fieldsOf<UpdateMcpConnectionInput>({\n config: true,\n credentials: true,\n metadata: true,\n name: true,\n});\n\nconst NO_SERVERS: MCPServerRecord[] = [];\nconst NO_TOOLS: MCPToolRecord[] = [];\nconst NO_RESOURCES: MCPResourceRecord[] = [];\n\n/** `CONNECTED` is the only status that means the server is usable right now. */\nexport function isMCPServerHealthy(status: string | null | undefined): boolean {\n return status === 'CONNECTED';\n}\n\nexport function isMCPServerUnhealthy(status: string | null | undefined): boolean {\n return status === 'ERROR' || status === 'DISCONNECTED';\n}\n\n/** Endpoint the connection points at — the service stores it on the free-form config. */\nexport function mcpServerEndpoint(server: Pick<MCPServerRecord, 'config'>): string | undefined {\n const url = server.config?.url;\n return typeof url === 'string' ? url : undefined;\n}\n\n/** Optional human description the UI stores alongside the endpoint. */\nexport function mcpServerDescription(server: Pick<MCPServerRecord, 'config'>): string | undefined {\n const description = server.config?.description;\n return typeof description === 'string' ? description : undefined;\n}\n\nfunction selectServers(data: ListMcpConnectionsQuery | undefined): MCPServerRecord[] {\n return data?.listMCPConnections ?? NO_SERVERS;\n}\n\nfunction selectServer(data: GetMcpConnectionQuery | undefined): MCPServerRecord | null {\n return data?.getMCPConnection ?? null;\n}\n\nfunction selectTools(data: ListMcpToolsQuery | undefined): MCPToolRecord[] {\n return data?.listMCPTools ?? NO_TOOLS;\n}\n\nfunction selectResources(data: ListMcpResourcesQuery | undefined): MCPResourceRecord[] {\n return data?.listMCPResources ?? NO_RESOURCES;\n}\n\nexport const mcpServerKeys = {\n all: ['mcpServers'] as const,\n lists: () => [...mcpServerKeys.all, 'list'] as const,\n list: (filter?: BaseFilter) => [...mcpServerKeys.lists(), filter] as const,\n details: () => [...mcpServerKeys.all, 'detail'] as const,\n detail: (id: string) => [...mcpServerKeys.details(), id] as const,\n resources: (serverId?: string) => [...mcpServerKeys.all, 'resources', serverId] as const,\n tools: (serverId?: string) => [...mcpServerKeys.all, 'tools', serverId] as const,\n};\n\nexport function useMCPServers(filter?: BaseFilter): QueryResult<MCPServerRecord[]> {\n const workspaceId = useWorkspaceId();\n const search = filter?.search?.trim().toLowerCase() ?? '';\n\n const variables = useMemo(\n () => ({\n // MCPConnectionFilterInput has no free-text field — search is narrowed on the client.\n filters: { workspaceId },\n pagination: { limit: LIST_LIMIT, offset: 0 },\n }),\n [workspaceId]\n );\n\n const select = useCallback(\n (data: ListMcpConnectionsQuery | undefined): MCPServerRecord[] => {\n const rows = selectServers(data);\n if (!search) return rows;\n return rows.filter((row) => row.name.toLowerCase().includes(search));\n },\n [search]\n );\n\n return useWorkspaceQuery<ListMcpConnectionsQuery, MCPServerRecord[]>({\n document: ListMcpConnectionsDocument,\n variables,\n select,\n fallback: NO_SERVERS,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load MCP servers',\n });\n}\n\nexport function useMCPServer(serverId: string | undefined): QueryResult<MCPServerRecord | null> {\n const variables = useMemo(() => ({ id: serverId ?? '' }), [serverId]);\n\n return useWorkspaceQuery<GetMcpConnectionQuery, MCPServerRecord | null>({\n document: GetMcpConnectionDocument,\n variables,\n select: selectServer,\n fallback: null,\n enabled: Boolean(serverId),\n errorMessage: 'Failed to load MCP server',\n });\n}\n\nexport function useMCPTools(serverId: string | undefined): QueryResult<MCPToolRecord[]> {\n const variables = useMemo(() => ({ connectionId: serverId ?? '' }), [serverId]);\n\n return useWorkspaceQuery<ListMcpToolsQuery, MCPToolRecord[]>({\n document: ListMcpToolsDocument,\n variables,\n select: selectTools,\n fallback: NO_TOOLS,\n enabled: Boolean(serverId),\n errorMessage: 'Failed to load MCP tools',\n });\n}\n\nexport function useMCPResources(serverId: string | undefined): QueryResult<MCPResourceRecord[]> {\n const variables = useMemo(() => ({ connectionId: serverId ?? '' }), [serverId]);\n\n return useWorkspaceQuery<ListMcpResourcesQuery, MCPResourceRecord[]>({\n document: ListMcpResourcesDocument,\n variables,\n select: selectResources,\n fallback: NO_RESOURCES,\n enabled: Boolean(serverId),\n errorMessage: 'Failed to load MCP resources',\n });\n}\n\nexport function useCreateMCPServer() {\n const workspaceId = useWorkspaceId();\n\n const variables = useCallback(\n (input: CreateMCPServerVariables) => ({\n input: buildMutationInput({ ...input, workspaceId }, CREATE_CONNECTION_FIELDS),\n }),\n [workspaceId]\n );\n\n return useWorkspaceMutation<\n CreateMcpConnectionMutation,\n CreateMCPServerVariables,\n MCPServerRecord\n >({\n document: CreateMcpConnectionDocument,\n variables,\n select: (data) => data?.createMCPConnection,\n errorMessage: 'Failed to connect MCP server',\n });\n}\n\nexport function useUpdateMCPServer() {\n return useWorkspaceMutation<\n UpdateMcpConnectionMutation,\n UpdateMCPServerVariables,\n MCPServerRecord\n >({\n document: UpdateMcpConnectionDocument,\n variables: ({ serverId, input }) => ({\n id: serverId,\n input: buildMutationInput(input, UPDATE_CONNECTION_FIELDS),\n }),\n select: (data) => data?.updateMCPConnection,\n errorMessage: 'Failed to update MCP server',\n });\n}\n\nexport function useDeleteMCPServer() {\n return useWorkspaceMutation<DeleteMcpConnectionMutation, string, boolean>({\n document: DeleteMcpConnectionDocument,\n variables: (serverId) => ({ id: serverId }),\n select: (data) => data?.deleteMCPConnection,\n errorMessage: 'Failed to disconnect MCP server',\n });\n}\n\nexport function useTestMCPConnection() {\n return useWorkspaceMutation<TestMcpConnectionMutation, string, boolean>({\n document: TestMcpConnectionDocument,\n variables: (serverId) => ({ id: serverId }),\n select: (data) => data?.testMCPConnection,\n errorMessage: 'Failed to test MCP connection',\n });\n}\n"],"mappings":";;;;;AA4CA,IAAM,IAAa,KA2Cb,IAA2B,EAAmC;CAClE,QAAQ;CACR,aAAa;CACb,UAAU;CACV,MAAM;CACN,MAAM;CACN,aAAa;CACd,CAAC,EAEI,IAA2B,EAAmC;CAClE,QAAQ;CACR,aAAa;CACb,UAAU;CACV,MAAM;CACP,CAAC,EAEI,IAAgC,EAAE,EAClC,IAA4B,EAAE,EAC9B,IAAoC,EAAE;AAG5C,SAAgB,EAAmB,GAA4C;AAC7E,QAAO,MAAW;;AAQpB,SAAgB,EAAkB,GAA6D;CAC7F,IAAM,IAAM,EAAO,QAAQ;AAC3B,QAAO,OAAO,KAAQ,WAAW,IAAM,KAAA;;AAIzC,SAAgB,EAAqB,GAA6D;CAChG,IAAM,IAAc,EAAO,QAAQ;AACnC,QAAO,OAAO,KAAgB,WAAW,IAAc,KAAA;;AAGzD,SAAS,EAAc,GAA8D;AACnF,QAAO,GAAM,sBAAsB;;AAGrC,SAAS,EAAa,GAAiE;AACrF,QAAO,GAAM,oBAAoB;;AAGnC,SAAS,EAAY,GAAsD;AACzE,QAAO,GAAM,gBAAgB;;AAG/B,SAAS,EAAgB,GAA8D;AACrF,QAAO,GAAM,oBAAoB;;AAanC,SAAgB,EAAc,GAAqD;CACjF,IAAM,IAAc,GAAgB,EAC9B,IAAS,GAAQ,QAAQ,MAAM,CAAC,aAAa,IAAI;AAoBvD,QAAO,EAA8D;EACnE,UAAU;EACV,WApBgB,SACT;GAEL,SAAS,EAAE,gBAAa;GACxB,YAAY;I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