@burdenoff/microfe-botmanor 2026.1002.1 → 2026.1007.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.
- package/dist/botlit/components/AssistantChannelPanel.js +109 -0
- package/dist/botlit/components/AssistantChannelPanel.js.map +1 -0
- package/dist/botlit/components/AssistantRuntimeSetupPanel.js +76 -0
- package/dist/botlit/components/AssistantRuntimeSetupPanel.js.map +1 -0
- package/dist/botlit/components/AssistantWebsitePanel.js +196 -0
- package/dist/botlit/components/AssistantWebsitePanel.js.map +1 -0
- package/dist/botlit/components/KnowledgeSourceImportPanel.js +135 -0
- package/dist/botlit/components/KnowledgeSourceImportPanel.js.map +1 -0
- package/dist/botlit/hooks/useAgents.js +12 -12
- package/dist/botlit/hooks/useAgents.js.map +1 -1
- package/dist/botlit/hooks/useAssistantChannels.js +76 -0
- package/dist/botlit/hooks/useAssistantChannels.js.map +1 -0
- package/dist/botlit/hooks/useAssistantRuntimeSetup.js +112 -0
- package/dist/botlit/hooks/useAssistantRuntimeSetup.js.map +1 -0
- package/dist/botlit/hooks/useAssistantWebsites.js +85 -0
- package/dist/botlit/hooks/useAssistantWebsites.js.map +1 -0
- package/dist/botlit/hooks/useKnowledgeBases.js +1 -0
- package/dist/botlit/hooks/useKnowledgeBases.js.map +1 -1
- package/dist/botlit/hooks/useKnowledgeSourceImports.js +86 -0
- package/dist/botlit/hooks/useKnowledgeSourceImports.js.map +1 -0
- package/dist/botlit/hooks/useLLMProviders.js +2 -2
- package/dist/botlit/hooks/useLLMProviders.js.map +1 -1
- package/dist/botlit/pages/AgentDetailPage.js +180 -158
- package/dist/botlit/pages/AgentDetailPage.js.map +1 -1
- package/dist/botlit/pages/ChatPage.js +58 -238
- package/dist/botlit/pages/ChatPage.js.map +1 -1
- package/dist/botlit/pages/KnowledgeBaseDetailPage.js +162 -160
- package/dist/botlit/pages/KnowledgeBaseDetailPage.js.map +1 -1
- package/dist/generated/global-types.js.map +1 -1
- package/dist/generated/wspace-operations.js +11 -11
- package/dist/generated/wspace-operations.js.map +1 -1
- package/dist/generated/wspace-types.js.map +1 -1
- package/package.json +3 -3
|
@@ -29,8 +29,8 @@ var l = s`
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
`, u = s`
|
|
32
|
-
query
|
|
33
|
-
|
|
32
|
+
query GetBotmanorAgent($id: ID!) {
|
|
33
|
+
getBotmanorAgent(id: $id) {
|
|
34
34
|
id
|
|
35
35
|
name
|
|
36
36
|
slug
|
|
@@ -63,8 +63,8 @@ var l = s`
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
`, d = s`
|
|
66
|
-
mutation
|
|
67
|
-
|
|
66
|
+
mutation CreateBotmanorAgent($input: CreateBotmanorAgentInput!) {
|
|
67
|
+
createBotmanorAgent(input: $input) {
|
|
68
68
|
id
|
|
69
69
|
name
|
|
70
70
|
slug
|
|
@@ -85,8 +85,8 @@ var l = s`
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
`, f = s`
|
|
88
|
-
mutation
|
|
89
|
-
|
|
88
|
+
mutation UpdateBotmanorAgent($id: ID!, $input: UpdateBotmanorAgentInput!) {
|
|
89
|
+
updateBotmanorAgent(id: $id, input: $input) {
|
|
90
90
|
id
|
|
91
91
|
name
|
|
92
92
|
slug
|
|
@@ -112,8 +112,8 @@ var l = s`
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
`, p = s`
|
|
115
|
-
mutation
|
|
116
|
-
|
|
115
|
+
mutation DeleteBotmanorAgent($id: ID!) {
|
|
116
|
+
deleteBotmanorAgent(id: $id)
|
|
117
117
|
}
|
|
118
118
|
`, m = s`
|
|
119
119
|
query ListAgentVersions($agentId: ID!, $pagination: PaginationInput) {
|
|
@@ -239,7 +239,7 @@ function x(e) {
|
|
|
239
239
|
query: u,
|
|
240
240
|
variables: { id: e },
|
|
241
241
|
fetchPolicy: "network-only"
|
|
242
|
-
})).data?.
|
|
242
|
+
})).data?.getBotmanorAgent ?? null);
|
|
243
243
|
} catch (e) {
|
|
244
244
|
f(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load agent"));
|
|
245
245
|
} finally {
|
|
@@ -271,7 +271,7 @@ function S() {
|
|
|
271
271
|
let r = (await e.mutate({
|
|
272
272
|
mutation: d,
|
|
273
273
|
variables: { input: t }
|
|
274
|
-
})).data?.
|
|
274
|
+
})).data?.createBotmanorAgent;
|
|
275
275
|
if (!r) throw Error("Failed to create agent");
|
|
276
276
|
return n({
|
|
277
277
|
data: r,
|
|
@@ -307,7 +307,7 @@ function C() {
|
|
|
307
307
|
id: n,
|
|
308
308
|
input: t(r, _)
|
|
309
309
|
}
|
|
310
|
-
})).data?.
|
|
310
|
+
})).data?.updateBotmanorAgent;
|
|
311
311
|
if (!a) throw Error("Failed to update agent");
|
|
312
312
|
return i({
|
|
313
313
|
data: a,
|
|
@@ -340,7 +340,7 @@ function w() {
|
|
|
340
340
|
let r = (await e.mutate({
|
|
341
341
|
mutation: p,
|
|
342
342
|
variables: { id: t }
|
|
343
|
-
})).data?.
|
|
343
|
+
})).data?.deleteBotmanorAgent ?? !1;
|
|
344
344
|
return n({
|
|
345
345
|
data: r,
|
|
346
346
|
loading: !1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAgents.js","names":[],"sources":["../../../src/botlit/hooks/useAgents.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 { UpdateBotlitAgentInput } from '../../generated/wspace-types';\nimport { useBotlit } from '../providers/BotlitProvider';\nimport type { BaseFilter } from '../types';\nimport { buildMutationInput, fieldsOf, type GraphQLInput } from './internal/mutationInput';\n\nconst LIST_AGENTS_DOCUMENT = gql`\n query ListAgents($filters: AgentFilterInput, $pagination: PaginationInput) {\n listAgents(filters: $filters, pagination: $pagination) {\n id\n name\n slug\n description\n type\n status\n visibility\n capabilities\n llmModelId\n bucketId\n executionCount\n lastExecutedAt\n specialization\n tagIds\n createdAt\n updatedAt\n createdById\n updatedById\n workspaceId\n }\n }\n`;\n\nconst GET_AGENT_DOCUMENT = gql`\n query GetBotlitAgent($id: ID!) {\n getBotlitAgent(id: $id) {\n id\n name\n slug\n description\n type\n status\n visibility\n capabilities\n llmModelId\n bucketId\n currentVersionId\n draftVersionId\n executionCount\n lastExecutedAt\n specialization\n systemPrompt\n temperature\n maxTokens\n maxConcurrentExecutions\n knowledgeBaseIds\n mcpConnectionIds\n workflowIds\n tagIds\n metadata\n createdAt\n updatedAt\n createdById\n updatedById\n workspaceId\n }\n }\n`;\n\nconst CREATE_AGENT_DOCUMENT = gql`\n mutation CreateBotlitAgent($input: CreateBotlitAgentInput!) {\n createBotlitAgent(input: $input) {\n id\n name\n slug\n description\n type\n status\n visibility\n capabilities\n llmModelId\n systemPrompt\n temperature\n maxTokens\n maxConcurrentExecutions\n tagIds\n createdAt\n updatedAt\n workspaceId\n }\n }\n`;\n\nconst UPDATE_AGENT_DOCUMENT = gql`\n mutation UpdateBotlitAgent($id: ID!, $input: UpdateBotlitAgentInput!) {\n updateBotlitAgent(id: $id, input: $input) {\n id\n name\n slug\n description\n type\n status\n visibility\n capabilities\n llmModelId\n systemPrompt\n temperature\n maxTokens\n maxConcurrentExecutions\n knowledgeBaseIds\n mcpConnectionIds\n workflowIds\n tagIds\n metadata\n createdAt\n updatedAt\n updatedById\n workspaceId\n }\n }\n`;\n\nconst DELETE_AGENT_DOCUMENT = gql`\n mutation DeleteBotlitAgent($id: ID!) {\n deleteBotlitAgent(id: $id)\n }\n`;\n\n// BOFF-4381: agent version history, publish, and rollback.\nconst LIST_AGENT_VERSIONS_DOCUMENT = gql`\n query ListAgentVersions($agentId: ID!, $pagination: PaginationInput) {\n listAgentVersions(agentId: $agentId, pagination: $pagination) {\n id\n agentId\n version\n status\n changelog\n config\n createdById\n createdAt\n publishedById\n publishedAt\n }\n }\n`;\n\nconst PUBLISH_AGENT_VERSION_DOCUMENT = gql`\n mutation PublishAgentVersion($agentId: ID!, $versionId: ID!, $changelog: String) {\n publishAgentVersion(agentId: $agentId, versionId: $versionId, changelog: $changelog) {\n id\n agentId\n version\n status\n changelog\n publishedById\n publishedAt\n }\n }\n`;\n\nconst ROLLBACK_AGENT_VERSION_DOCUMENT = gql`\n mutation RollbackAgentVersion($agentId: ID!, $targetVersionId: ID!) {\n rollbackAgentVersion(agentId: $agentId, targetVersionId: $targetVersionId) {\n id\n agentId\n version\n status\n changelog\n publishedById\n publishedAt\n }\n }\n`;\n\ntype WorkspaceClient = ApolloClient;\n\nexport interface AgentRecord {\n id: string;\n name: string;\n slug: string;\n description?: string | null;\n type: string;\n status: string;\n visibility?: string | null;\n capabilities?: string[] | null;\n llmModelId?: string | null;\n bucketId?: string | null;\n currentVersionId?: string | null;\n draftVersionId?: string | null;\n executionCount?: number | null;\n lastExecutedAt?: string | null;\n specialization?: string | null;\n systemPrompt?: string | null;\n temperature?: number | null;\n maxTokens?: number | null;\n maxConcurrentExecutions?: number | null;\n knowledgeBaseIds?: string[] | null;\n mcpConnectionIds?: string[] | null;\n workflowIds?: string[] | null;\n tagIds?: string[] | null;\n metadata?: Record<string, unknown> | null;\n createdAt?: string | null;\n updatedAt?: string | null;\n createdById?: string | null;\n updatedById?: string | null;\n workspaceId?: string | null;\n}\n\ninterface ListAgentsData {\n listAgents: AgentRecord[];\n}\n\ninterface GetAgentData {\n getBotlitAgent: AgentRecord | null;\n}\n\ninterface CreateAgentData {\n createBotlitAgent: AgentRecord;\n}\n\ninterface UpdateAgentData {\n updateBotlitAgent: AgentRecord;\n}\n\ninterface DeleteAgentData {\n deleteBotlitAgent: boolean;\n}\n\nexport interface AgentVersionRecord {\n id: string;\n agentId: string;\n version: string;\n status: 'DRAFT' | 'PUBLISHED' | 'HISTORICAL';\n changelog?: string | null;\n config?: Record<string, unknown> | null;\n createdById?: string | null;\n createdAt?: string | null;\n publishedById?: string | null;\n publishedAt?: string | null;\n}\n\ninterface ListAgentVersionsData {\n listAgentVersions: AgentVersionRecord[];\n}\n\ninterface PublishAgentVersionData {\n publishAgentVersion: AgentVersionRecord;\n}\n\ninterface RollbackAgentVersionData {\n rollbackAgentVersion: AgentVersionRecord;\n}\n\ninterface AgentMutationState<T> {\n data: T | undefined;\n loading: boolean;\n error: Error | undefined;\n}\n\ninterface CreateAgentInput {\n workspaceId: string;\n name: string;\n slug?: string;\n description?: string;\n type: string;\n systemPrompt: string;\n temperature?: number;\n maxTokens?: number;\n capabilities?: string[];\n llmModelId?: string;\n}\n\ninterface UpdateAgentInput {\n agentId: string;\n input: GraphQLInput<UpdateBotlitAgentInput>;\n}\n\nconst UPDATE_AGENT_FIELDS = fieldsOf<UpdateBotlitAgentInput>({\n bucketId: true,\n capabilities: true,\n context: true,\n description: true,\n knowledgeBaseIds: true,\n llmModelId: true,\n maxConcurrentExecutions: true,\n maxTokens: true,\n mcpConnectionIds: true,\n metadata: true,\n name: true,\n slug: true,\n specialization: true,\n status: true,\n systemPrompt: true,\n tagIds: true,\n tags: true,\n temperature: true,\n type: true,\n visibility: true,\n workflowIds: true,\n});\n\nfunction getWorkspaceClient(client: unknown): WorkspaceClient {\n return client as WorkspaceClient;\n}\n\nfunction buildAgentFilter(\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 agentKeys = {\n all: ['agents'] as const,\n lists: () => [...agentKeys.all, 'list'] as const,\n list: (filter?: BaseFilter) => [...agentKeys.lists(), filter] as const,\n details: () => [...agentKeys.all, 'detail'] as const,\n detail: (id: string) => [...agentKeys.details(), id] as const,\n};\n\nexport function useAgents(filter?: BaseFilter) {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const { workspaceId } = useBotlit();\n const [data, setData] = useState<AgentRecord[]>([]);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n\n const variables = useMemo(\n () => ({\n filters: buildAgentFilter(workspaceId, filter),\n pagination: { limit: 100, offset: 0 },\n }),\n [filter, workspaceId]\n );\n\n const refetch = useCallback(async () => {\n if (!workspaceId) {\n setData([]);\n return;\n }\n\n setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<ListAgentsData>({\n query: LIST_AGENTS_DOCUMENT,\n variables,\n fetchPolicy: 'network-only',\n });\n setData(result.data?.listAgents ?? []);\n } catch (queryError) {\n setError(queryError instanceof Error ? queryError : new Error('Failed to load agents'));\n } finally {\n setLoading(false);\n }\n }, [client, variables, workspaceId]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\nexport function useAgent(agentId: string | undefined) {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [data, setData] = useState<AgentRecord | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n\n const refetch = useCallback(async () => {\n if (!agentId) {\n setData(null);\n return;\n }\n\n setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<GetAgentData>({\n query: GET_AGENT_DOCUMENT,\n variables: { id: agentId },\n fetchPolicy: 'network-only',\n });\n setData(result.data?.getBotlitAgent ?? null);\n } catch (queryError) {\n setError(queryError instanceof Error ? queryError : new Error('Failed to load agent'));\n } finally {\n setLoading(false);\n }\n }, [agentId, client]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\nexport function useCreateAgent() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<AgentMutationState<AgentRecord>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const createAgent = useCallback(\n async (input: CreateAgentInput) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<CreateAgentData>({\n mutation: CREATE_AGENT_DOCUMENT,\n variables: { input },\n });\n\n const createdAgent = result.data?.createBotlitAgent;\n if (!createdAgent) {\n throw new Error('Failed to create agent');\n }\n\n setState({ data: createdAgent, loading: false, error: undefined });\n return createdAgent;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error ? mutationError : new Error('Failed to create agent');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [createAgent, state] as const;\n}\n\nexport function useUpdateAgent() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<AgentMutationState<AgentRecord>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const updateAgent = useCallback(\n async ({ agentId, input }: UpdateAgentInput) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<UpdateAgentData>({\n mutation: UPDATE_AGENT_DOCUMENT,\n variables: { id: agentId, input: buildMutationInput(input, UPDATE_AGENT_FIELDS) },\n });\n\n const updatedAgent = result.data?.updateBotlitAgent;\n if (!updatedAgent) {\n throw new Error('Failed to update agent');\n }\n\n setState({ data: updatedAgent, loading: false, error: undefined });\n return updatedAgent;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error ? mutationError : new Error('Failed to update agent');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [updateAgent, state] as const;\n}\n\nexport function useDeleteAgent() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<AgentMutationState<boolean>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const deleteAgent = useCallback(\n async (agentId: string) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<DeleteAgentData>({\n mutation: DELETE_AGENT_DOCUMENT,\n variables: { id: agentId },\n });\n\n const deleted = result.data?.deleteBotlitAgent ?? 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 agent');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [deleteAgent, state] as const;\n}\n\n// ============================================================================\n// VERSIONING (BOFF-4381) — version history, publish, rollback\n// ============================================================================\n\nexport function useAgentVersions(agentId: string | undefined) {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [data, setData] = useState<AgentVersionRecord[]>([]);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n\n const refetch = useCallback(async () => {\n if (!agentId) {\n setData([]);\n return;\n }\n\n setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<ListAgentVersionsData>({\n query: LIST_AGENT_VERSIONS_DOCUMENT,\n variables: { agentId, pagination: { limit: 50, offset: 0 } },\n fetchPolicy: 'network-only',\n });\n const versions = result.data?.listAgentVersions ?? [];\n // Newest first, regardless of what the server returned.\n setData(\n [...versions].sort((a, b) =>\n a.createdAt && b.createdAt ? b.createdAt.localeCompare(a.createdAt) : 0\n )\n );\n } catch (queryError) {\n setError(\n queryError instanceof Error ? queryError : new Error('Failed to load agent versions')\n );\n } finally {\n setLoading(false);\n }\n }, [agentId, client]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\nexport function usePublishAgentVersion() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<AgentMutationState<AgentVersionRecord>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const publishAgentVersion = useCallback(\n async ({\n agentId,\n versionId,\n changelog,\n }: {\n agentId: string;\n versionId: string;\n changelog?: string;\n }) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<PublishAgentVersionData>({\n mutation: PUBLISH_AGENT_VERSION_DOCUMENT,\n variables: { agentId, versionId, changelog: changelog?.trim() || undefined },\n });\n\n const published = result.data?.publishAgentVersion;\n if (!published) {\n throw new Error('Failed to publish agent version');\n }\n\n setState({ data: published, loading: false, error: undefined });\n return published;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error\n ? mutationError\n : new Error('Failed to publish agent version');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [publishAgentVersion, state] as const;\n}\n\nexport function useRollbackAgentVersion() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<AgentMutationState<AgentVersionRecord>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const rollbackAgentVersion = useCallback(\n async ({ agentId, targetVersionId }: { agentId: string; targetVersionId: string }) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<RollbackAgentVersionData>({\n mutation: ROLLBACK_AGENT_VERSION_DOCUMENT,\n variables: { agentId, targetVersionId },\n });\n\n const rolledBack = result.data?.rollbackAgentVersion;\n if (!rolledBack) {\n throw new Error('Failed to roll back agent version');\n }\n\n setState({ data: rolledBack, loading: false, error: undefined });\n return rolledBack;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error\n ? mutationError\n : new Error('Failed to roll back agent version');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [rollbackAgentVersion, state] as const;\n}\n"],"mappings":";;;;;;AASA,IAAM,IAAuB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;GA0B1B,IAAqB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCxB,IAAwB,CAAG;;;;;;;;;;;;;;;;;;;;;;GAwB3B,IAAwB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6B3B,IAAwB,CAAG;;;;GAO3B,IAA+B,CAAG;;;;;;;;;;;;;;;GAiBlC,IAAiC,CAAG;;;;;;;;;;;;GAcpC,IAAkC,CAAG;;;;;;;;;;;;GAqHrC,IAAsB,EAAiC;CAC3D,UAAU;CACV,cAAc;CACd,SAAS;CACT,aAAa;CACb,kBAAkB;CAClB,YAAY;CACZ,yBAAyB;CACzB,WAAW;CACX,kBAAkB;CAClB,UAAU;CACV,MAAM;CACN,MAAM;CACN,gBAAgB;CAChB,QAAQ;CACR,cAA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["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 { UpdateBotmanorAgentInput } from '../../generated/wspace-types';\nimport { useBotlit } from '../providers/BotlitProvider';\nimport type { BaseFilter } from '../types';\nimport { buildMutationInput, fieldsOf, type GraphQLInput } from './internal/mutationInput';\n\nconst LIST_AGENTS_DOCUMENT = gql`\n query ListAgents($filters: AgentFilterInput, $pagination: PaginationInput) {\n listAgents(filters: $filters, pagination: $pagination) {\n id\n name\n slug\n description\n type\n status\n visibility\n capabilities\n llmModelId\n bucketId\n executionCount\n lastExecutedAt\n specialization\n tagIds\n createdAt\n updatedAt\n createdById\n updatedById\n workspaceId\n }\n }\n`;\n\nconst GET_AGENT_DOCUMENT = gql`\n query GetBotmanorAgent($id: ID!) {\n getBotmanorAgent(id: $id) {\n id\n name\n slug\n description\n type\n status\n visibility\n capabilities\n llmModelId\n bucketId\n currentVersionId\n draftVersionId\n executionCount\n lastExecutedAt\n specialization\n systemPrompt\n temperature\n maxTokens\n maxConcurrentExecutions\n knowledgeBaseIds\n mcpConnectionIds\n workflowIds\n tagIds\n metadata\n createdAt\n updatedAt\n createdById\n updatedById\n workspaceId\n }\n }\n`;\n\nconst CREATE_AGENT_DOCUMENT = gql`\n mutation CreateBotmanorAgent($input: CreateBotmanorAgentInput!) {\n createBotmanorAgent(input: $input) {\n id\n name\n slug\n description\n type\n status\n visibility\n capabilities\n llmModelId\n systemPrompt\n temperature\n maxTokens\n maxConcurrentExecutions\n tagIds\n createdAt\n updatedAt\n workspaceId\n }\n }\n`;\n\nconst UPDATE_AGENT_DOCUMENT = gql`\n mutation UpdateBotmanorAgent($id: ID!, $input: UpdateBotmanorAgentInput!) {\n updateBotmanorAgent(id: $id, input: $input) {\n id\n name\n slug\n description\n type\n status\n visibility\n capabilities\n llmModelId\n systemPrompt\n temperature\n maxTokens\n maxConcurrentExecutions\n knowledgeBaseIds\n mcpConnectionIds\n workflowIds\n tagIds\n metadata\n createdAt\n updatedAt\n updatedById\n workspaceId\n }\n }\n`;\n\nconst DELETE_AGENT_DOCUMENT = gql`\n mutation DeleteBotmanorAgent($id: ID!) {\n deleteBotmanorAgent(id: $id)\n }\n`;\n\n// BOFF-4381: agent version history, publish, and rollback.\nconst LIST_AGENT_VERSIONS_DOCUMENT = gql`\n query ListAgentVersions($agentId: ID!, $pagination: PaginationInput) {\n listAgentVersions(agentId: $agentId, pagination: $pagination) {\n id\n agentId\n version\n status\n changelog\n config\n createdById\n createdAt\n publishedById\n publishedAt\n }\n }\n`;\n\nconst PUBLISH_AGENT_VERSION_DOCUMENT = gql`\n mutation PublishAgentVersion($agentId: ID!, $versionId: ID!, $changelog: String) {\n publishAgentVersion(agentId: $agentId, versionId: $versionId, changelog: $changelog) {\n id\n agentId\n version\n status\n changelog\n publishedById\n publishedAt\n }\n }\n`;\n\nconst ROLLBACK_AGENT_VERSION_DOCUMENT = gql`\n mutation RollbackAgentVersion($agentId: ID!, $targetVersionId: ID!) {\n rollbackAgentVersion(agentId: $agentId, targetVersionId: $targetVersionId) {\n id\n agentId\n version\n status\n changelog\n publishedById\n publishedAt\n }\n }\n`;\n\ntype WorkspaceClient = ApolloClient;\n\nexport interface AgentRecord {\n id: string;\n name: string;\n slug: string;\n description?: string | null;\n type: string;\n status: string;\n visibility?: string | null;\n capabilities?: string[] | null;\n llmModelId?: string | null;\n bucketId?: string | null;\n currentVersionId?: string | null;\n draftVersionId?: string | null;\n executionCount?: number | null;\n lastExecutedAt?: string | null;\n specialization?: string | null;\n systemPrompt?: string | null;\n temperature?: number | null;\n maxTokens?: number | null;\n maxConcurrentExecutions?: number | null;\n knowledgeBaseIds?: string[] | null;\n mcpConnectionIds?: string[] | null;\n workflowIds?: string[] | null;\n tagIds?: string[] | null;\n metadata?: Record<string, unknown> | null;\n createdAt?: string | null;\n updatedAt?: string | null;\n createdById?: string | null;\n updatedById?: string | null;\n workspaceId?: string | null;\n}\n\ninterface ListAgentsData {\n listAgents: AgentRecord[];\n}\n\ninterface GetAgentData {\n getBotmanorAgent: AgentRecord | null;\n}\n\ninterface CreateAgentData {\n createBotmanorAgent: AgentRecord;\n}\n\ninterface UpdateAgentData {\n updateBotmanorAgent: AgentRecord;\n}\n\ninterface DeleteAgentData {\n deleteBotmanorAgent: boolean;\n}\n\nexport interface AgentVersionRecord {\n id: string;\n agentId: string;\n version: string;\n status: 'DRAFT' | 'PUBLISHED' | 'HISTORICAL';\n changelog?: string | null;\n config?: Record<string, unknown> | null;\n createdById?: string | null;\n createdAt?: string | null;\n publishedById?: string | null;\n publishedAt?: string | null;\n}\n\ninterface ListAgentVersionsData {\n listAgentVersions: AgentVersionRecord[];\n}\n\ninterface PublishAgentVersionData {\n publishAgentVersion: AgentVersionRecord;\n}\n\ninterface RollbackAgentVersionData {\n rollbackAgentVersion: AgentVersionRecord;\n}\n\ninterface AgentMutationState<T> {\n data: T | undefined;\n loading: boolean;\n error: Error | undefined;\n}\n\ninterface CreateAgentInput {\n workspaceId: string;\n name: string;\n slug?: string;\n description?: string;\n type: string;\n systemPrompt: string;\n temperature?: number;\n maxTokens?: number;\n capabilities?: string[];\n llmModelId?: string;\n}\n\ninterface UpdateAgentInput {\n agentId: string;\n input: GraphQLInput<UpdateBotmanorAgentInput>;\n}\n\nconst UPDATE_AGENT_FIELDS = fieldsOf<UpdateBotmanorAgentInput>({\n bucketId: true,\n capabilities: true,\n context: true,\n description: true,\n knowledgeBaseIds: true,\n llmModelId: true,\n maxConcurrentExecutions: true,\n maxTokens: true,\n mcpConnectionIds: true,\n metadata: true,\n name: true,\n slug: true,\n specialization: true,\n status: true,\n systemPrompt: true,\n tagIds: true,\n tags: true,\n temperature: true,\n type: true,\n visibility: true,\n workflowIds: true,\n});\n\nfunction getWorkspaceClient(client: unknown): WorkspaceClient {\n return client as WorkspaceClient;\n}\n\nfunction buildAgentFilter(\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 agentKeys = {\n all: ['agents'] as const,\n lists: () => [...agentKeys.all, 'list'] as const,\n list: (filter?: BaseFilter) => [...agentKeys.lists(), filter] as const,\n details: () => [...agentKeys.all, 'detail'] as const,\n detail: (id: string) => [...agentKeys.details(), id] as const,\n};\n\nexport function useAgents(filter?: BaseFilter) {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const { workspaceId } = useBotlit();\n const [data, setData] = useState<AgentRecord[]>([]);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n\n const variables = useMemo(\n () => ({\n filters: buildAgentFilter(workspaceId, filter),\n pagination: { limit: 100, offset: 0 },\n }),\n [filter, workspaceId]\n );\n\n const refetch = useCallback(async () => {\n if (!workspaceId) {\n setData([]);\n return;\n }\n\n setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<ListAgentsData>({\n query: LIST_AGENTS_DOCUMENT,\n variables,\n fetchPolicy: 'network-only',\n });\n setData(result.data?.listAgents ?? []);\n } catch (queryError) {\n setError(queryError instanceof Error ? queryError : new Error('Failed to load agents'));\n } finally {\n setLoading(false);\n }\n }, [client, variables, workspaceId]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\nexport function useAgent(agentId: string | undefined) {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [data, setData] = useState<AgentRecord | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n\n const refetch = useCallback(async () => {\n if (!agentId) {\n setData(null);\n return;\n }\n\n setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<GetAgentData>({\n query: GET_AGENT_DOCUMENT,\n variables: { id: agentId },\n fetchPolicy: 'network-only',\n });\n setData(result.data?.getBotmanorAgent ?? null);\n } catch (queryError) {\n setError(queryError instanceof Error ? queryError : new Error('Failed to load agent'));\n } finally {\n setLoading(false);\n }\n }, [agentId, client]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\nexport function useCreateAgent() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<AgentMutationState<AgentRecord>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const createAgent = useCallback(\n async (input: CreateAgentInput) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<CreateAgentData>({\n mutation: CREATE_AGENT_DOCUMENT,\n variables: { input },\n });\n\n const createdAgent = result.data?.createBotmanorAgent;\n if (!createdAgent) {\n throw new Error('Failed to create agent');\n }\n\n setState({ data: createdAgent, loading: false, error: undefined });\n return createdAgent;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error ? mutationError : new Error('Failed to create agent');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [createAgent, state] as const;\n}\n\nexport function useUpdateAgent() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<AgentMutationState<AgentRecord>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const updateAgent = useCallback(\n async ({ agentId, input }: UpdateAgentInput) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<UpdateAgentData>({\n mutation: UPDATE_AGENT_DOCUMENT,\n variables: { id: agentId, input: buildMutationInput(input, UPDATE_AGENT_FIELDS) },\n });\n\n const updatedAgent = result.data?.updateBotmanorAgent;\n if (!updatedAgent) {\n throw new Error('Failed to update agent');\n }\n\n setState({ data: updatedAgent, loading: false, error: undefined });\n return updatedAgent;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error ? mutationError : new Error('Failed to update agent');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [updateAgent, state] as const;\n}\n\nexport function useDeleteAgent() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<AgentMutationState<boolean>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const deleteAgent = useCallback(\n async (agentId: string) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<DeleteAgentData>({\n mutation: DELETE_AGENT_DOCUMENT,\n variables: { id: agentId },\n });\n\n const deleted = result.data?.deleteBotmanorAgent ?? 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 agent');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [deleteAgent, state] as const;\n}\n\n// ============================================================================\n// VERSIONING (BOFF-4381) — version history, publish, rollback\n// ============================================================================\n\nexport function useAgentVersions(agentId: string | undefined) {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [data, setData] = useState<AgentVersionRecord[]>([]);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n\n const refetch = useCallback(async () => {\n if (!agentId) {\n setData([]);\n return;\n }\n\n setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<ListAgentVersionsData>({\n query: LIST_AGENT_VERSIONS_DOCUMENT,\n variables: { agentId, pagination: { limit: 50, offset: 0 } },\n fetchPolicy: 'network-only',\n });\n const versions = result.data?.listAgentVersions ?? [];\n // Newest first, regardless of what the server returned.\n setData(\n [...versions].sort((a, b) =>\n a.createdAt && b.createdAt ? b.createdAt.localeCompare(a.createdAt) : 0\n )\n );\n } catch (queryError) {\n setError(\n queryError instanceof Error ? queryError : new Error('Failed to load agent versions')\n );\n } finally {\n setLoading(false);\n }\n }, [agentId, client]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\nexport function usePublishAgentVersion() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<AgentMutationState<AgentVersionRecord>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const publishAgentVersion = useCallback(\n async ({\n agentId,\n versionId,\n changelog,\n }: {\n agentId: string;\n versionId: string;\n changelog?: string;\n }) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<PublishAgentVersionData>({\n mutation: PUBLISH_AGENT_VERSION_DOCUMENT,\n variables: { agentId, versionId, changelog: changelog?.trim() || undefined },\n });\n\n const published = result.data?.publishAgentVersion;\n if (!published) {\n throw new Error('Failed to publish agent version');\n }\n\n setState({ data: published, loading: false, error: undefined });\n return published;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error\n ? mutationError\n : new Error('Failed to publish agent version');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [publishAgentVersion, state] as const;\n}\n\nexport function useRollbackAgentVersion() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<AgentMutationState<AgentVersionRecord>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const rollbackAgentVersion = useCallback(\n async ({ agentId, targetVersionId }: { agentId: string; targetVersionId: string }) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<RollbackAgentVersionData>({\n mutation: ROLLBACK_AGENT_VERSION_DOCUMENT,\n variables: { agentId, targetVersionId },\n });\n\n const rolledBack = result.data?.rollbackAgentVersion;\n if (!rolledBack) {\n throw new Error('Failed to roll back agent version');\n }\n\n setState({ data: rolledBack, loading: false, error: undefined });\n return rolledBack;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error\n ? mutationError\n : new Error('Failed to roll back agent version');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [rollbackAgentVersion, state] as const;\n}\n"],"mappings":";;;;;;AASA,IAAM,IAAuB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;GA0B1B,IAAqB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCxB,IAAwB,CAAG;;;;;;;;;;;;;;;;;;;;;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,MAAM;AAChC,OAAI,CAAC,EACH,OAAU,MAAM,oCAAoC;AAItD,UADA,EAAS;IAAE,MAAM;IAAY,SAAS;IAAO,OAAO,KAAA;IAAW,CAAC,EACzD;WACA,GAAe;GACtB,IAAM,IACJ,aAAyB,QACrB,IACA,gBAAI,MAAM,oCAAoC;AAEpD,SADA,EAAS;IAAE,MAAM,KAAA;IAAW,SAAS;IAAO;IAAO,CAAC,EAC9C;;IAGV,CAAC,EAAO,CACT,EAE6B,EAAM"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { useBotlit as e } from "../providers/BotlitProvider.js";
|
|
2
|
+
import { gql as t } from "@apollo/client";
|
|
3
|
+
import { useGatewayClient as n } from "@burdenoff/fe-libs/shared/graphql";
|
|
4
|
+
import { useMutation as r, useQuery as i, useQueryClient as a } from "@tanstack/react-query";
|
|
5
|
+
//#region src/botlit/hooks/useAssistantChannels.ts
|
|
6
|
+
var o = t`
|
|
7
|
+
query AssistantChannelPublications {
|
|
8
|
+
assistantChannelInstallations {
|
|
9
|
+
id
|
|
10
|
+
workspaceId
|
|
11
|
+
routeId
|
|
12
|
+
publicationId
|
|
13
|
+
enabled
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
`, s = t`
|
|
17
|
+
mutation ConfigureAssistantChannel($routeId: ID!, $publicationId: ID!) {
|
|
18
|
+
configureAssistantChannel(routeId: $routeId, publicationId: $publicationId) {
|
|
19
|
+
id
|
|
20
|
+
workspaceId
|
|
21
|
+
routeId
|
|
22
|
+
publicationId
|
|
23
|
+
enabled
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
`, c = t`
|
|
27
|
+
mutation DisableAssistantChannel($id: ID!) {
|
|
28
|
+
disableAssistantChannel(id: $id)
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
function l() {
|
|
32
|
+
let t = n("workspace"), l = a(), { workspaceId: u, currentUser: d } = e(), f = [
|
|
33
|
+
"botmanor-assistant-channels",
|
|
34
|
+
u,
|
|
35
|
+
d?.id
|
|
36
|
+
];
|
|
37
|
+
return {
|
|
38
|
+
installations: i({
|
|
39
|
+
queryKey: f,
|
|
40
|
+
enabled: !!(u && d?.id),
|
|
41
|
+
retry: !1,
|
|
42
|
+
queryFn: async () => {
|
|
43
|
+
let e = (await t.query({
|
|
44
|
+
query: o,
|
|
45
|
+
fetchPolicy: "no-cache"
|
|
46
|
+
})).data?.assistantChannelInstallations;
|
|
47
|
+
if (!e || e.length > 100 || e.some((e) => e.workspaceId !== u)) throw Error("Channel publications unavailable");
|
|
48
|
+
return e;
|
|
49
|
+
}
|
|
50
|
+
}),
|
|
51
|
+
configure: r({
|
|
52
|
+
mutationFn: async (e) => {
|
|
53
|
+
let n = (await t.mutate({
|
|
54
|
+
mutation: s,
|
|
55
|
+
variables: e
|
|
56
|
+
})).data?.configureAssistantChannel;
|
|
57
|
+
if (!n || n.workspaceId !== u || n.routeId !== e.routeId || n.publicationId !== e.publicationId) throw Error("Channel publication unavailable");
|
|
58
|
+
return n;
|
|
59
|
+
},
|
|
60
|
+
onSuccess: () => l.invalidateQueries({ queryKey: f })
|
|
61
|
+
}),
|
|
62
|
+
disable: r({
|
|
63
|
+
mutationFn: async (e) => {
|
|
64
|
+
if (!(await t.mutate({
|
|
65
|
+
mutation: c,
|
|
66
|
+
variables: { id: e }
|
|
67
|
+
})).data?.disableAssistantChannel) throw Error("Channel revocation unavailable");
|
|
68
|
+
},
|
|
69
|
+
onSuccess: () => l.invalidateQueries({ queryKey: f })
|
|
70
|
+
})
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { l as useAssistantChannels };
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=useAssistantChannels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAssistantChannels.js","names":[],"sources":["../../../src/botlit/hooks/useAssistantChannels.ts"],"sourcesContent":["import { gql } from '@apollo/client';\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';\nimport { useGatewayClient } from '@burdenoff/fe-libs/shared/graphql';\nimport { useBotlit } from '../providers/BotlitProvider';\n\ninterface Installation {\n id: string;\n workspaceId: string;\n routeId: string;\n publicationId: string;\n enabled: boolean;\n}\nconst LIST = gql`\n query AssistantChannelPublications {\n assistantChannelInstallations {\n id\n workspaceId\n routeId\n publicationId\n enabled\n }\n }\n`;\nconst CONFIGURE = gql`\n mutation ConfigureAssistantChannel($routeId: ID!, $publicationId: ID!) {\n configureAssistantChannel(routeId: $routeId, publicationId: $publicationId) {\n id\n workspaceId\n routeId\n publicationId\n enabled\n }\n }\n`;\nconst DISABLE = gql`\n mutation DisableAssistantChannel($id: ID!) {\n disableAssistantChannel(id: $id)\n }\n`;\nexport function useAssistantChannels() {\n const client = useGatewayClient('workspace'),\n cache = useQueryClient(),\n { workspaceId, currentUser } = useBotlit();\n const key = ['botmanor-assistant-channels', workspaceId, currentUser?.id];\n const installations = useQuery({\n queryKey: key,\n enabled: Boolean(workspaceId && currentUser?.id),\n retry: false,\n queryFn: async () => {\n const response = await client.query<{ assistantChannelInstallations: Installation[] }>({\n query: LIST,\n fetchPolicy: 'no-cache',\n });\n const rows = response.data?.assistantChannelInstallations;\n if (!rows || rows.length > 100 || rows.some((row) => row.workspaceId !== workspaceId))\n throw new Error('Channel publications unavailable');\n return rows;\n },\n });\n const configure = useMutation({\n mutationFn: async (input: { routeId: string; publicationId: string }) => {\n const response = await client.mutate<{ configureAssistantChannel: Installation }>({\n mutation: CONFIGURE,\n variables: input,\n });\n const row = response.data?.configureAssistantChannel;\n if (\n !row ||\n row.workspaceId !== workspaceId ||\n row.routeId !== input.routeId ||\n row.publicationId !== input.publicationId\n )\n throw new Error('Channel publication unavailable');\n return row;\n },\n onSuccess: () => cache.invalidateQueries({ queryKey: key }),\n });\n const disable = useMutation({\n mutationFn: async (id: string) => {\n const response = await client.mutate<{ disableAssistantChannel: boolean }>({\n mutation: DISABLE,\n variables: { id },\n });\n if (!response.data?.disableAssistantChannel)\n throw new Error('Channel revocation unavailable');\n },\n onSuccess: () => cache.invalidateQueries({ queryKey: key }),\n });\n return { installations, configure, disable };\n}\n"],"mappings":";;;;;AAYA,IAAM,IAAO,CAAG;;;;;;;;;;GAWV,IAAY,CAAG;;;;;;;;;;GAWf,IAAU,CAAG;;;;;AAKnB,SAAgB,IAAuB;CACrC,IAAM,IAAS,EAAiB,YAAY,EAC1C,IAAQ,GAAgB,EACxB,EAAE,gBAAa,mBAAgB,GAAW,EACtC,IAAM;EAAC;EAA+B;EAAa,GAAa;EAAG;AA6CzE,QAAO;EAAE,eA5Ca,EAAS;GAC7B,UAAU;GACV,SAAS,GAAQ,KAAe,GAAa;GAC7C,OAAO;GACP,SAAS,YAAY;IAKnB,IAAM,KAJW,MAAM,EAAO,MAAyD;KACrF,OAAO;KACP,aAAa;KACd,CAAC,EACoB,MAAM;AAC5B,QAAI,CAAC,KAAQ,EAAK,SAAS,OAAO,EAAK,MAAM,MAAQ,EAAI,gBAAgB,EAAY,CACnF,OAAU,MAAM,mCAAmC;AACrD,WAAO;;GAEV,CAAC;EA8BsB,WA7BN,EAAY;GAC5B,YAAY,OAAO,MAAsD;IAKvE,IAAM,KAJW,MAAM,EAAO,OAAoD;KAChF,UAAU;KACV,WAAW;KACZ,CAAC,EACmB,MAAM;AAC3B,QACE,CAAC,KACD,EAAI,gBAAgB,KACpB,EAAI,YAAY,EAAM,WACtB,EAAI,kBAAkB,EAAM,cAE5B,OAAU,MAAM,kCAAkC;AACpD,WAAO;;GAET,iBAAiB,EAAM,kBAAkB,EAAE,UAAU,GAAK,CAAC;GAC5D,CAAC;EAYiC,SAXnB,EAAY;GAC1B,YAAY,OAAO,MAAe;AAKhC,QAAI,EAJa,MAAM,EAAO,OAA6C;KACzE,UAAU;KACV,WAAW,EAAE,OAAI;KAClB,CAAC,EACY,MAAM,wBAClB,OAAU,MAAM,iCAAiC;;GAErD,iBAAiB,EAAM,kBAAkB,EAAE,UAAU,GAAK,CAAC;GAC5D,CAAC;EAC0C"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { useBotlit as e } from "../providers/BotlitProvider.js";
|
|
2
|
+
import { gql as t } from "@apollo/client";
|
|
3
|
+
import { useGatewayClient as n } from "@burdenoff/fe-libs/shared/graphql";
|
|
4
|
+
import { useMutation as r, useQuery as i } from "@tanstack/react-query";
|
|
5
|
+
//#region src/botlit/hooks/useAssistantRuntimeSetup.ts
|
|
6
|
+
var a = t`
|
|
7
|
+
query AssistantWorkflowProvider {
|
|
8
|
+
getProviderByKey(key: "burdenoff") {
|
|
9
|
+
id
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
`, o = t`
|
|
13
|
+
query AssistantWorkflowConnections($providerId: ID!, $offset: Int!) {
|
|
14
|
+
getConnections(
|
|
15
|
+
filter: { providerId: $providerId, status: ACTIVE }
|
|
16
|
+
pagination: { limit: 100, offset: $offset }
|
|
17
|
+
) {
|
|
18
|
+
hasMore
|
|
19
|
+
items {
|
|
20
|
+
id
|
|
21
|
+
name
|
|
22
|
+
workspaceId
|
|
23
|
+
status
|
|
24
|
+
provider {
|
|
25
|
+
key
|
|
26
|
+
}
|
|
27
|
+
authMethod {
|
|
28
|
+
authType
|
|
29
|
+
isEnabled
|
|
30
|
+
isConfigured
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
`, s = t`
|
|
36
|
+
mutation ConfigureAssistantRuntime($agentId: ID!, $connectionId: ID!) {
|
|
37
|
+
configureAssistantRuntime(agentId: $agentId, connectionId: $connectionId) {
|
|
38
|
+
agentId
|
|
39
|
+
courseId
|
|
40
|
+
inferenceWorkflowId
|
|
41
|
+
recoveryWorkflowId
|
|
42
|
+
recoveryScheduleId
|
|
43
|
+
ingestionWorkflowId
|
|
44
|
+
protocolVersion
|
|
45
|
+
ready
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
function c(t) {
|
|
50
|
+
let c = n("workspace"), { workspaceId: l, currentUser: u } = e();
|
|
51
|
+
return {
|
|
52
|
+
connections: i({
|
|
53
|
+
queryKey: [
|
|
54
|
+
"botmanor-assistant-connections",
|
|
55
|
+
l,
|
|
56
|
+
u?.id
|
|
57
|
+
],
|
|
58
|
+
enabled: !!(l && u?.id),
|
|
59
|
+
retry: !1,
|
|
60
|
+
queryFn: async () => {
|
|
61
|
+
let e = (await c.query({
|
|
62
|
+
query: a,
|
|
63
|
+
fetchPolicy: "no-cache"
|
|
64
|
+
})).data?.getProviderByKey?.id;
|
|
65
|
+
if (!e) return [];
|
|
66
|
+
let t = [];
|
|
67
|
+
for (let n = 0; n < 500; n += 100) {
|
|
68
|
+
let r = (await c.query({
|
|
69
|
+
query: o,
|
|
70
|
+
variables: {
|
|
71
|
+
providerId: e,
|
|
72
|
+
offset: n
|
|
73
|
+
},
|
|
74
|
+
fetchPolicy: "no-cache"
|
|
75
|
+
})).data?.getConnections;
|
|
76
|
+
if (!r || r.items.length > 100) throw Error("Connections unavailable");
|
|
77
|
+
for (let e of r.items) e.workspaceId === l && e.status === "ACTIVE" && e.provider.key === "burdenoff" && e.authMethod?.authType === "SERVICE_ACCOUNT" && e.authMethod.isEnabled && e.authMethod.isConfigured && t.push({
|
|
78
|
+
id: e.id,
|
|
79
|
+
name: e.name
|
|
80
|
+
});
|
|
81
|
+
if (!r.hasMore) return t;
|
|
82
|
+
}
|
|
83
|
+
throw Error("Connection list exceeds the supported limit");
|
|
84
|
+
}
|
|
85
|
+
}),
|
|
86
|
+
configure: r({
|
|
87
|
+
mutationKey: [
|
|
88
|
+
"botmanor-assistant-runtime",
|
|
89
|
+
l,
|
|
90
|
+
u?.id,
|
|
91
|
+
t
|
|
92
|
+
],
|
|
93
|
+
retry: !1,
|
|
94
|
+
mutationFn: async (e) => {
|
|
95
|
+
if (!l || !u?.id) throw Error("Sign in to configure an assistant");
|
|
96
|
+
let n = (await c.mutate({
|
|
97
|
+
mutation: s,
|
|
98
|
+
variables: {
|
|
99
|
+
agentId: t,
|
|
100
|
+
connectionId: e
|
|
101
|
+
}
|
|
102
|
+
})).data?.configureAssistantRuntime;
|
|
103
|
+
if (!n || n.agentId !== t || n.protocolVersion !== 2 || !n.inferenceWorkflowId || !n.recoveryWorkflowId || !n.recoveryScheduleId || typeof n.ready != "boolean") throw Error("Runtime configuration unavailable");
|
|
104
|
+
return n;
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
export { c as useAssistantRuntimeSetup };
|
|
111
|
+
|
|
112
|
+
//# sourceMappingURL=useAssistantRuntimeSetup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAssistantRuntimeSetup.js","names":[],"sources":["../../../src/botlit/hooks/useAssistantRuntimeSetup.ts"],"sourcesContent":["import { gql } from '@apollo/client';\nimport { useMutation, useQuery } from '@tanstack/react-query';\nimport { useGatewayClient } from '@burdenoff/fe-libs/shared/graphql';\nimport { useBotlit } from '../providers/BotlitProvider';\n\ninterface Connection {\n id: string;\n name: string;\n workspaceId: string | null;\n status: string;\n provider: { key: string };\n authMethod: { authType: string; isEnabled: boolean; isConfigured: boolean } | null;\n}\nexport interface AssistantRuntimeConfiguration {\n agentId: string;\n courseId: string | null;\n inferenceWorkflowId: string;\n recoveryWorkflowId: string;\n recoveryScheduleId: string;\n ingestionWorkflowId: string | null;\n protocolVersion: number;\n ready: boolean;\n}\nconst PROVIDER = gql`\n query AssistantWorkflowProvider {\n getProviderByKey(key: \"burdenoff\") {\n id\n }\n }\n`;\nconst CONNECTIONS = gql`\n query AssistantWorkflowConnections($providerId: ID!, $offset: Int!) {\n getConnections(\n filter: { providerId: $providerId, status: ACTIVE }\n pagination: { limit: 100, offset: $offset }\n ) {\n hasMore\n items {\n id\n name\n workspaceId\n status\n provider {\n key\n }\n authMethod {\n authType\n isEnabled\n isConfigured\n }\n }\n }\n }\n`;\nconst CONFIGURE = gql`\n mutation ConfigureAssistantRuntime($agentId: ID!, $connectionId: ID!) {\n configureAssistantRuntime(agentId: $agentId, connectionId: $connectionId) {\n agentId\n courseId\n inferenceWorkflowId\n recoveryWorkflowId\n recoveryScheduleId\n ingestionWorkflowId\n protocolVersion\n ready\n }\n }\n`;\n\nexport function useAssistantRuntimeSetup(agentId: string) {\n const client = useGatewayClient('workspace');\n const { workspaceId, currentUser } = useBotlit();\n const connections = useQuery({\n queryKey: ['botmanor-assistant-connections', workspaceId, currentUser?.id],\n enabled: Boolean(workspaceId && currentUser?.id),\n retry: false,\n queryFn: async () => {\n const provider = await client.query<{ getProviderByKey: { id: string } | null }>({\n query: PROVIDER,\n fetchPolicy: 'no-cache',\n });\n const providerId = provider.data?.getProviderByKey?.id;\n if (!providerId) return [];\n const result: Array<{ id: string; name: string }> = [];\n for (let offset = 0; offset < 500; offset += 100) {\n const page = await client.query<{\n getConnections: { hasMore: boolean; items: Connection[] };\n }>({\n query: CONNECTIONS,\n variables: { providerId, offset },\n fetchPolicy: 'no-cache',\n });\n const data = page.data?.getConnections;\n if (!data || data.items.length > 100) throw new Error('Connections unavailable');\n for (const connection of data.items) {\n if (\n connection.workspaceId === workspaceId &&\n connection.status === 'ACTIVE' &&\n connection.provider.key === 'burdenoff' &&\n connection.authMethod?.authType === 'SERVICE_ACCOUNT' &&\n connection.authMethod.isEnabled &&\n connection.authMethod.isConfigured\n )\n result.push({ id: connection.id, name: connection.name });\n }\n if (!data.hasMore) return result;\n }\n throw new Error('Connection list exceeds the supported limit');\n },\n });\n const configure = useMutation({\n mutationKey: ['botmanor-assistant-runtime', workspaceId, currentUser?.id, agentId],\n retry: false,\n mutationFn: async (connectionId: string) => {\n if (!workspaceId || !currentUser?.id) throw new Error('Sign in to configure an assistant');\n const result = await client.mutate<{\n configureAssistantRuntime: AssistantRuntimeConfiguration;\n }>({\n mutation: CONFIGURE,\n variables: { agentId, connectionId },\n });\n const configured = result.data?.configureAssistantRuntime;\n if (\n !configured ||\n configured.agentId !== agentId ||\n configured.protocolVersion !== 2 ||\n !configured.inferenceWorkflowId ||\n !configured.recoveryWorkflowId ||\n !configured.recoveryScheduleId ||\n typeof configured.ready !== 'boolean'\n )\n throw new Error('Runtime configuration unavailable');\n return configured;\n },\n });\n return { connections, configure };\n}\n"],"mappings":";;;;;AAuBA,IAAM,IAAW,CAAG;;;;;;GAOd,IAAc,CAAG;;;;;;;;;;;;;;;;;;;;;;;GAwBjB,IAAY,CAAG;;;;;;;;;;;;;;AAerB,SAAgB,EAAyB,GAAiB;CACxD,IAAM,IAAS,EAAiB,YAAY,EACtC,EAAE,gBAAa,mBAAgB,GAAW;AAgEhD,QAAO;EAAE,aA/DW,EAAS;GAC3B,UAAU;IAAC;IAAkC;IAAa,GAAa;IAAG;GAC1E,SAAS,GAAQ,KAAe,GAAa;GAC7C,OAAO;GACP,SAAS,YAAY;IAKnB,IAAM,KAJW,MAAM,EAAO,MAAmD;KAC/E,OAAO;KACP,aAAa;KACd,CAAC,EAC0B,MAAM,kBAAkB;AACpD,QAAI,CAAC,EAAY,QAAO,EAAE;IAC1B,IAAM,IAA8C,EAAE;AACtD,SAAK,IAAI,IAAS,GAAG,IAAS,KAAK,KAAU,KAAK;KAQhD,IAAM,KAPO,MAAM,EAAO,MAEvB;MACD,OAAO;MACP,WAAW;OAAE;OAAY;OAAQ;MACjC,aAAa;MACd,CAAC,EACgB,MAAM;AACxB,SAAI,CAAC,KAAQ,EAAK,MAAM,SAAS,IAAK,OAAU,MAAM,0BAA0B;AAChF,UAAK,IAAM,KAAc,EAAK,MAC5B,CACE,EAAW,gBAAgB,KAC3B,EAAW,WAAW,YACtB,EAAW,SAAS,QAAQ,eAC5B,EAAW,YAAY,aAAa,qBACpC,EAAW,WAAW,aACtB,EAAW,WAAW,gBAEtB,EAAO,KAAK;MAAE,IAAI,EAAW;MAAI,MAAM,EAAW;MAAM,CAAC;AAE7D,SAAI,CAAC,EAAK,QAAS,QAAO;;AAE5B,UAAU,MAAM,8CAA8C;;GAEjE,CAAC;EA0BoB,WAzBJ,EAAY;GAC5B,aAAa;IAAC;IAA8B;IAAa,GAAa;IAAI;IAAQ;GAClF,OAAO;GACP,YAAY,OAAO,MAAyB;AAC1C,QAAI,CAAC,KAAe,CAAC,GAAa,GAAI,OAAU,MAAM,oCAAoC;IAO1F,IAAM,KANS,MAAM,EAAO,OAEzB;KACD,UAAU;KACV,WAAW;MAAE;MAAS;MAAc;KACrC,CAAC,EACwB,MAAM;AAChC,QACE,CAAC,KACD,EAAW,YAAY,KACvB,EAAW,oBAAoB,KAC/B,CAAC,EAAW,uBACZ,CAAC,EAAW,sBACZ,CAAC,EAAW,sBACZ,OAAO,EAAW,SAAU,UAE5B,OAAU,MAAM,oCAAoC;AACtD,WAAO;;GAEV,CAAC;EAC+B"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { useBotlit as e } from "../providers/BotlitProvider.js";
|
|
2
|
+
import { gql as t } from "@apollo/client";
|
|
3
|
+
import { useGatewayClient as n } from "@burdenoff/fe-libs/shared/graphql";
|
|
4
|
+
import { useMutation as r, useQuery as i, useQueryClient as a } from "@tanstack/react-query";
|
|
5
|
+
//#region src/botlit/hooks/useAssistantWebsites.ts
|
|
6
|
+
var o = t`
|
|
7
|
+
query AssistantWebsites($agentId: ID!) {
|
|
8
|
+
assistantWebsiteInstallations(agentId: $agentId) {
|
|
9
|
+
id
|
|
10
|
+
workspaceId
|
|
11
|
+
agentId
|
|
12
|
+
name
|
|
13
|
+
allowedOrigins
|
|
14
|
+
approvedKnowledgeBaseIds
|
|
15
|
+
enabled
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
`, s = t`
|
|
19
|
+
mutation PublishAssistantWebsite($input: PublishAssistantWebsiteInput!) {
|
|
20
|
+
publishAssistantWebsite(input: $input) {
|
|
21
|
+
id
|
|
22
|
+
workspaceId
|
|
23
|
+
agentId
|
|
24
|
+
name
|
|
25
|
+
allowedOrigins
|
|
26
|
+
approvedKnowledgeBaseIds
|
|
27
|
+
enabled
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
`, c = t`
|
|
31
|
+
mutation DisableAssistantWebsite($id: ID!) {
|
|
32
|
+
disableAssistantWebsite(id: $id)
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
35
|
+
function l(t) {
|
|
36
|
+
let l = n("workspace"), u = a(), { workspaceId: d, currentUser: f } = e(), p = [
|
|
37
|
+
"botmanor-assistant-websites",
|
|
38
|
+
d,
|
|
39
|
+
f?.id,
|
|
40
|
+
t
|
|
41
|
+
];
|
|
42
|
+
return {
|
|
43
|
+
installations: i({
|
|
44
|
+
queryKey: p,
|
|
45
|
+
enabled: !!(d && f?.id),
|
|
46
|
+
retry: !1,
|
|
47
|
+
queryFn: async () => {
|
|
48
|
+
let e = (await l.query({
|
|
49
|
+
query: o,
|
|
50
|
+
variables: { agentId: t },
|
|
51
|
+
fetchPolicy: "no-cache"
|
|
52
|
+
})).data?.assistantWebsiteInstallations;
|
|
53
|
+
if (!e || e.length > 100 || e.some((e) => e.workspaceId !== d || e.agentId !== t)) throw Error("Website publications unavailable");
|
|
54
|
+
return e;
|
|
55
|
+
}
|
|
56
|
+
}),
|
|
57
|
+
publish: r({
|
|
58
|
+
mutationFn: async (e) => {
|
|
59
|
+
let n = (await l.mutate({
|
|
60
|
+
mutation: s,
|
|
61
|
+
variables: { input: {
|
|
62
|
+
...e,
|
|
63
|
+
agentId: t
|
|
64
|
+
} }
|
|
65
|
+
})).data?.publishAssistantWebsite;
|
|
66
|
+
if (!n || n.workspaceId !== d || n.agentId !== t) throw Error("Website publication unavailable");
|
|
67
|
+
return n;
|
|
68
|
+
},
|
|
69
|
+
onSuccess: () => u.invalidateQueries({ queryKey: p })
|
|
70
|
+
}),
|
|
71
|
+
disable: r({
|
|
72
|
+
mutationFn: async (e) => {
|
|
73
|
+
if ((await l.mutate({
|
|
74
|
+
mutation: c,
|
|
75
|
+
variables: { id: e }
|
|
76
|
+
})).data?.disableAssistantWebsite !== !0) throw Error("Website revocation unavailable");
|
|
77
|
+
},
|
|
78
|
+
onSuccess: () => u.invalidateQueries({ queryKey: p })
|
|
79
|
+
})
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
export { l as useAssistantWebsites };
|
|
84
|
+
|
|
85
|
+
//# sourceMappingURL=useAssistantWebsites.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAssistantWebsites.js","names":[],"sources":["../../../src/botlit/hooks/useAssistantWebsites.ts"],"sourcesContent":["import { gql } from '@apollo/client';\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';\nimport { useGatewayClient } from '@burdenoff/fe-libs/shared/graphql';\nimport { useBotlit } from '../providers/BotlitProvider';\n\nexport interface AssistantWebsiteInstallation {\n id: string;\n workspaceId: string;\n agentId: string;\n name: string;\n allowedOrigins: string[];\n approvedKnowledgeBaseIds: string[];\n enabled: boolean;\n}\nconst LIST = gql`\n query AssistantWebsites($agentId: ID!) {\n assistantWebsiteInstallations(agentId: $agentId) {\n id\n workspaceId\n agentId\n name\n allowedOrigins\n approvedKnowledgeBaseIds\n enabled\n }\n }\n`;\nconst PUBLISH = gql`\n mutation PublishAssistantWebsite($input: PublishAssistantWebsiteInput!) {\n publishAssistantWebsite(input: $input) {\n id\n workspaceId\n agentId\n name\n allowedOrigins\n approvedKnowledgeBaseIds\n enabled\n }\n }\n`;\nconst DISABLE = gql`\n mutation DisableAssistantWebsite($id: ID!) {\n disableAssistantWebsite(id: $id)\n }\n`;\n\nexport function useAssistantWebsites(agentId: string) {\n const client = useGatewayClient('workspace'),\n cache = useQueryClient(),\n { workspaceId, currentUser } = useBotlit();\n const key = ['botmanor-assistant-websites', workspaceId, currentUser?.id, agentId];\n const installations = useQuery({\n queryKey: key,\n enabled: Boolean(workspaceId && currentUser?.id),\n retry: false,\n queryFn: async () => {\n const response = await client.query<{\n assistantWebsiteInstallations: AssistantWebsiteInstallation[];\n }>({ query: LIST, variables: { agentId }, fetchPolicy: 'no-cache' });\n const rows = response.data?.assistantWebsiteInstallations;\n if (\n !rows ||\n rows.length > 100 ||\n rows.some((row) => row.workspaceId !== workspaceId || row.agentId !== agentId)\n )\n throw new Error('Website publications unavailable');\n return rows;\n },\n });\n const publish = useMutation({\n mutationFn: async (input: {\n name: string;\n allowedOrigins: string[];\n approvedKnowledgeBaseIds: string[];\n }) => {\n const response = await client.mutate<{\n publishAssistantWebsite: AssistantWebsiteInstallation;\n }>({ mutation: PUBLISH, variables: { input: { ...input, agentId } } });\n const row = response.data?.publishAssistantWebsite;\n if (!row || row.workspaceId !== workspaceId || row.agentId !== agentId)\n throw new Error('Website publication unavailable');\n return row;\n },\n onSuccess: () => cache.invalidateQueries({ queryKey: key }),\n });\n const disable = useMutation({\n mutationFn: async (id: string) => {\n const response = await client.mutate<{ disableAssistantWebsite: boolean }>({\n mutation: DISABLE,\n variables: { id },\n });\n if (response.data?.disableAssistantWebsite !== true)\n throw new Error('Website revocation unavailable');\n },\n onSuccess: () => cache.invalidateQueries({ queryKey: key }),\n });\n return { installations, publish, disable };\n}\n"],"mappings":";;;;;AAcA,IAAM,IAAO,CAAG;;;;;;;;;;;;GAaV,IAAU,CAAG;;;;;;;;;;;;GAab,IAAU,CAAG;;;;;AAMnB,SAAgB,EAAqB,GAAiB;CACpD,IAAM,IAAS,EAAiB,YAAY,EAC1C,IAAQ,GAAgB,EACxB,EAAE,gBAAa,mBAAgB,GAAW,EACtC,IAAM;EAAC;EAA+B;EAAa,GAAa;EAAI;EAAQ;AA8ClF,QAAO;EAAE,eA7Ca,EAAS;GAC7B,UAAU;GACV,SAAS,GAAQ,KAAe,GAAa;GAC7C,OAAO;GACP,SAAS,YAAY;IAInB,IAAM,KAHW,MAAM,EAAO,MAE3B;KAAE,OAAO;KAAM,WAAW,EAAE,YAAS;KAAE,aAAa;KAAY,CAAC,EAC9C,MAAM;AAC5B,QACE,CAAC,KACD,EAAK,SAAS,OACd,EAAK,MAAM,MAAQ,EAAI,gBAAgB,KAAe,EAAI,YAAY,EAAQ,CAE9E,OAAU,MAAM,mCAAmC;AACrD,WAAO;;GAEV,CAAC;EA4BsB,SA3BR,EAAY;GAC1B,YAAY,OAAO,MAIb;IAIJ,IAAM,KAHW,MAAM,EAAO,OAE3B;KAAE,UAAU;KAAS,WAAW,EAAE,OAAO;MAAE,GAAG;MAAO;MAAS,EAAE;KAAE,CAAC,EACjD,MAAM;AAC3B,QAAI,CAAC,KAAO,EAAI,gBAAgB,KAAe,EAAI,YAAY,EAC7D,OAAU,MAAM,kCAAkC;AACpD,WAAO;;GAET,iBAAiB,EAAM,kBAAkB,EAAE,UAAU,GAAK,CAAC;GAC5D,CAAC;EAY+B,SAXjB,EAAY;GAC1B,YAAY,OAAO,MAAe;AAKhC,SAJiB,MAAM,EAAO,OAA6C;KACzE,UAAU;KACV,WAAW,EAAE,OAAI;KAClB,CAAC,EACW,MAAM,4BAA4B,GAC7C,OAAU,MAAM,iCAAiC;;GAErD,iBAAiB,EAAM,kBAAkB,EAAE,UAAU,GAAK,CAAC;GAC5D,CAAC;EACwC"}
|
|
@@ -1 +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;CAChB,UAAU;CACV,MAAM;
|
|
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 // 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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AAK,CACP;EAKC,QAAQ;EACR,UAAU;EACV,SAAS,EAAQ;EACjB,cAAc;EACf,CAAC;;AAGJ,SAAgB,IAAyB;CACvC,IAAM,IAAc,GAAgB;AASpC,QAAO,EAIL;EACA,UAAU;EACV,WAbgB,GACf,OAAyC,EACxC,OAAO,EAAmB;GAAE,GAAG;GAAO;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,86 @@
|
|
|
1
|
+
import { useBotlit as e } from "../providers/BotlitProvider.js";
|
|
2
|
+
import { gql as t } from "@apollo/client";
|
|
3
|
+
import { useGatewayClient as n } from "@burdenoff/fe-libs/shared/graphql";
|
|
4
|
+
import { useMutation as r, useQuery as i, useQueryClient as a } from "@tanstack/react-query";
|
|
5
|
+
//#region src/botlit/hooks/useKnowledgeSourceImports.ts
|
|
6
|
+
var o = t`
|
|
7
|
+
query KnowledgeSourceImports($knowledgeBaseId: ID!) {
|
|
8
|
+
knowledgeSourceImports(knowledgeBaseId: $knowledgeBaseId) {
|
|
9
|
+
id
|
|
10
|
+
knowledgeBaseId
|
|
11
|
+
title
|
|
12
|
+
status
|
|
13
|
+
failureCount
|
|
14
|
+
errorCode
|
|
15
|
+
documentId
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
`, s = t`
|
|
19
|
+
mutation QueueKnowledgeSource($input: QueueKnowledgeSourceInput!) {
|
|
20
|
+
queueKnowledgeSource(input: $input) {
|
|
21
|
+
id
|
|
22
|
+
knowledgeBaseId
|
|
23
|
+
title
|
|
24
|
+
status
|
|
25
|
+
failureCount
|
|
26
|
+
errorCode
|
|
27
|
+
documentId
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
`, c = t`
|
|
31
|
+
mutation RetryKnowledgeSourceImport($id: ID!) {
|
|
32
|
+
retryKnowledgeSourceImport(id: $id)
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
35
|
+
function l(t) {
|
|
36
|
+
let l = n("workspace"), u = a(), { workspaceId: d, currentUser: f } = e(), p = [
|
|
37
|
+
"botmanor-knowledge-source-imports",
|
|
38
|
+
d,
|
|
39
|
+
f?.id,
|
|
40
|
+
t
|
|
41
|
+
];
|
|
42
|
+
return {
|
|
43
|
+
imports: i({
|
|
44
|
+
queryKey: p,
|
|
45
|
+
enabled: !!(d && f?.id && t),
|
|
46
|
+
retry: !1,
|
|
47
|
+
refetchInterval: (e) => e.state.data?.some((e) => ["READY", "PROCESSING"].includes(e.status)) ? 5e3 : !1,
|
|
48
|
+
queryFn: async () => {
|
|
49
|
+
let e = (await l.query({
|
|
50
|
+
query: o,
|
|
51
|
+
variables: { knowledgeBaseId: t },
|
|
52
|
+
fetchPolicy: "no-cache"
|
|
53
|
+
})).data?.knowledgeSourceImports;
|
|
54
|
+
if (!e || e.length > 100 || e.some((e) => e.knowledgeBaseId !== t)) throw Error("Knowledge imports unavailable");
|
|
55
|
+
return e;
|
|
56
|
+
}
|
|
57
|
+
}),
|
|
58
|
+
queue: r({
|
|
59
|
+
mutationFn: async (e) => {
|
|
60
|
+
let n = (await l.mutate({
|
|
61
|
+
mutation: s,
|
|
62
|
+
variables: { input: {
|
|
63
|
+
...e,
|
|
64
|
+
knowledgeBaseId: t
|
|
65
|
+
} }
|
|
66
|
+
})).data?.queueKnowledgeSource;
|
|
67
|
+
if (!n || n.knowledgeBaseId !== t) throw Error("Knowledge admission unavailable");
|
|
68
|
+
return n;
|
|
69
|
+
},
|
|
70
|
+
onSuccess: () => u.invalidateQueries({ queryKey: p })
|
|
71
|
+
}),
|
|
72
|
+
retry: r({
|
|
73
|
+
mutationFn: async (e) => {
|
|
74
|
+
if (!(await l.mutate({
|
|
75
|
+
mutation: c,
|
|
76
|
+
variables: { id: e }
|
|
77
|
+
})).data?.retryKnowledgeSourceImport) throw Error("Knowledge recovery unavailable");
|
|
78
|
+
},
|
|
79
|
+
onSuccess: () => u.invalidateQueries({ queryKey: p })
|
|
80
|
+
})
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
export { l as useKnowledgeSourceImports };
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=useKnowledgeSourceImports.js.map
|