@burdenoff/microfe-botmanor 2026.1201.3 → 2026.1203.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/GettingStartedChecklist.js +1 -1
- package/dist/botlit/components/GettingStartedChecklist.js.map +1 -1
- package/dist/botlit/hooks/useAgentApprovals.js +28 -17
- package/dist/botlit/hooks/useAgentApprovals.js.map +1 -1
- package/dist/botlit/hooks/useBotAgents.js +15 -11
- package/dist/botlit/hooks/useBotAgents.js.map +1 -1
- package/dist/botlit/hooks/useBots.js +36 -62
- package/dist/botlit/hooks/useBots.js.map +1 -1
- package/dist/botlit/hooks/useBuckets.js +31 -24
- package/dist/botlit/hooks/useBuckets.js.map +1 -1
- package/dist/botlit/hooks/useChannels.js +44 -30
- package/dist/botlit/hooks/useChannels.js.map +1 -1
- package/dist/botlit/hooks/useLLMProviders.js +8 -6
- package/dist/botlit/hooks/useLLMProviders.js.map +1 -1
- package/dist/botlit/hooks/useMCPServers.js +21 -17
- package/dist/botlit/hooks/useMCPServers.js.map +1 -1
- package/dist/botlit/hooks/usePromptTemplates.js +5 -3
- package/dist/botlit/hooks/usePromptTemplates.js.map +1 -1
- package/dist/botlit/hooks/useStorePublishing.js +20 -10
- package/dist/botlit/hooks/useStorePublishing.js.map +1 -1
- package/dist/botlit/hooks/useTemplates.js +35 -29
- package/dist/botlit/hooks/useTemplates.js.map +1 -1
- package/dist/botlit/pages/BotWorkflowTab.js +74 -65
- package/dist/botlit/pages/BotWorkflowTab.js.map +1 -1
- package/dist/generated/wspace-operations.d.ts +522 -3
- package/dist/generated/wspace-operations.js +281 -15
- package/dist/generated/wspace-operations.js.map +1 -1
- package/package.json +3 -3
|
@@ -30,7 +30,7 @@ var b = (e) => {
|
|
|
30
30
|
let b = t(), { navigateTo: x } = l(), S = n(), C = s !== null, w = d(() => ({ filters: { workspaceId: S } }), [S]), T = r({
|
|
31
31
|
document: e,
|
|
32
32
|
variables: w,
|
|
33
|
-
select: (e) => (e?.
|
|
33
|
+
select: (e) => (e?.listBotmanorKnowledgeBasesPage.total ?? 0) > 0,
|
|
34
34
|
fallback: !1,
|
|
35
35
|
enabled: !!S,
|
|
36
36
|
errorMessage: "Failed to check for knowledge bases"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GettingStartedChecklist.js","names":["GettingStartedChecklist","canCreateBots","useBotmanorPermissionDecision","BOTMANOR_PERMISSIONS","canReadRuns","ChecklistWithRuns","props","ChecklistBody","runs","useExecutionSummary","t","useTr","useBotlit","workspaceId","useWorkspaceId","hasRun","knowledgeVariables","useMemo","knowledge","useWorkspaceQuery","BotmanorGettingStartedKnowledgeDocument","data","providers","useLLMProviders","channels","useChannelOverview","state","isSetupComplete","steps","BookOpen","navigateTo","KeyRound","Bot","AppWindow","Radio","MessageSquare","step","NextSteps"],"sources":["../../../src/botlit/components/GettingStartedChecklist.tsx"],"sourcesContent":["/**\n * First-bot checklist on the dashboard (BOFF-15482)\n * @module botlit/components\n *\n * BotManor's setup order is not obvious: an agent answers from knowledge with\n * a model, and a bot puts agents in front of people through a channel. This\n * checklist walks a new workspace through that order. Every tick comes from\n * real data (counts and one-row reads), never from clicks, so it stays right\n * when someone else in the workspace does a step. It disappears once every\n * step is done and can be dismissed (per workspace) before that.\n */\n\nimport type { FC } from 'react';\nimport { useMemo } from 'react';\nimport { AppWindow, BookOpen, Bot, KeyRound, MessageSquare, Radio } from 'lucide-react';\nimport { NextSteps, type NextStep } from '@burdenoff/fe-libs/ui';\n\nimport {\n BotmanorGettingStartedKnowledgeDocument,\n type BotmanorGettingStartedKnowledgeQuery,\n} from '../../generated/wspace-operations';\nimport { useTr } from '../../shared/hooks/useTr';\nimport { useWorkspaceId, useWorkspaceQuery } from '../hooks/internal/workspaceGateway';\nimport { useChannelOverview } from '../hooks/useChannels';\nimport { useExecutionSummary } from '../hooks/useExecutions';\nimport { useLLMProviders } from '../hooks/useLLMProviders';\nimport { BOTMANOR_PERMISSIONS, useBotmanorPermissionDecision } from '../permissions';\nimport { useBotlit } from '../providers/BotlitProvider';\nimport { isSetupComplete, type GettingStartedState } from '../utils/gettingStarted';\n\nexport interface GettingStartedChecklistProps {\n /** True once the workspace has a bot (from the dashboard's exact counts). */\n hasBot: boolean;\n /** True once the workspace has an agent. */\n hasAgent: boolean;\n}\n\n/**\n * Members who cannot build bots have nothing to set up, so the checklist (and\n * every read behind it) is skipped for them. A member who cannot read runs\n * sees no \"test\" step, and the runs read is skipped too.\n */\nexport const GettingStartedChecklist: FC<GettingStartedChecklistProps> = (props) => {\n const canCreateBots =\n useBotmanorPermissionDecision(BOTMANOR_PERMISSIONS.APP_CREATE) === 'allowed';\n const canReadRuns =\n useBotmanorPermissionDecision(BOTMANOR_PERMISSIONS.EXECUTION_READ) === 'allowed';\n if (!canCreateBots) return null;\n return canReadRuns ? (\n <ChecklistWithRuns {...props} />\n ) : (\n <ChecklistBody {...props} hasRun={null} />\n );\n};\n\n/** Reads whether the workspace has any run yet. */\nconst ChecklistWithRuns: FC<GettingStartedChecklistProps> = (props) => {\n const runs = useExecutionSummary();\n return <ChecklistBody {...props} hasRun={(runs.data?.total ?? 0) > 0} />;\n};\n\nconst ChecklistBody: FC<\n GettingStartedChecklistProps & {\n /** Whether a run exists; null when the member cannot read runs. */\n hasRun: boolean | null;\n }\n> = ({ hasBot, hasAgent, hasRun }) => {\n const t = useTr();\n const { navigateTo } = useBotlit();\n const workspaceId = useWorkspaceId();\n const canReadRuns = hasRun !== null;\n\n const knowledgeVariables = useMemo(() => ({ filters: { workspaceId } }), [workspaceId]);\n const knowledge = useWorkspaceQuery<BotmanorGettingStartedKnowledgeQuery, boolean>({\n document: BotmanorGettingStartedKnowledgeDocument,\n variables: knowledgeVariables,\n select: (data) => (data?.
|
|
1
|
+
{"version":3,"file":"GettingStartedChecklist.js","names":["GettingStartedChecklist","canCreateBots","useBotmanorPermissionDecision","BOTMANOR_PERMISSIONS","canReadRuns","ChecklistWithRuns","props","ChecklistBody","runs","useExecutionSummary","t","useTr","useBotlit","workspaceId","useWorkspaceId","hasRun","knowledgeVariables","useMemo","knowledge","useWorkspaceQuery","BotmanorGettingStartedKnowledgeDocument","data","providers","useLLMProviders","channels","useChannelOverview","state","isSetupComplete","steps","BookOpen","navigateTo","KeyRound","Bot","AppWindow","Radio","MessageSquare","step","NextSteps"],"sources":["../../../src/botlit/components/GettingStartedChecklist.tsx"],"sourcesContent":["/**\n * First-bot checklist on the dashboard (BOFF-15482)\n * @module botlit/components\n *\n * BotManor's setup order is not obvious: an agent answers from knowledge with\n * a model, and a bot puts agents in front of people through a channel. This\n * checklist walks a new workspace through that order. Every tick comes from\n * real data (counts and one-row reads), never from clicks, so it stays right\n * when someone else in the workspace does a step. It disappears once every\n * step is done and can be dismissed (per workspace) before that.\n */\n\nimport type { FC } from 'react';\nimport { useMemo } from 'react';\nimport { AppWindow, BookOpen, Bot, KeyRound, MessageSquare, Radio } from 'lucide-react';\nimport { NextSteps, type NextStep } from '@burdenoff/fe-libs/ui';\n\nimport {\n BotmanorGettingStartedKnowledgeDocument,\n type BotmanorGettingStartedKnowledgeQuery,\n} from '../../generated/wspace-operations';\nimport { useTr } from '../../shared/hooks/useTr';\nimport { useWorkspaceId, useWorkspaceQuery } from '../hooks/internal/workspaceGateway';\nimport { useChannelOverview } from '../hooks/useChannels';\nimport { useExecutionSummary } from '../hooks/useExecutions';\nimport { useLLMProviders } from '../hooks/useLLMProviders';\nimport { BOTMANOR_PERMISSIONS, useBotmanorPermissionDecision } from '../permissions';\nimport { useBotlit } from '../providers/BotlitProvider';\nimport { isSetupComplete, type GettingStartedState } from '../utils/gettingStarted';\n\nexport interface GettingStartedChecklistProps {\n /** True once the workspace has a bot (from the dashboard's exact counts). */\n hasBot: boolean;\n /** True once the workspace has an agent. */\n hasAgent: boolean;\n}\n\n/**\n * Members who cannot build bots have nothing to set up, so the checklist (and\n * every read behind it) is skipped for them. A member who cannot read runs\n * sees no \"test\" step, and the runs read is skipped too.\n */\nexport const GettingStartedChecklist: FC<GettingStartedChecklistProps> = (props) => {\n const canCreateBots =\n useBotmanorPermissionDecision(BOTMANOR_PERMISSIONS.APP_CREATE) === 'allowed';\n const canReadRuns =\n useBotmanorPermissionDecision(BOTMANOR_PERMISSIONS.EXECUTION_READ) === 'allowed';\n if (!canCreateBots) return null;\n return canReadRuns ? (\n <ChecklistWithRuns {...props} />\n ) : (\n <ChecklistBody {...props} hasRun={null} />\n );\n};\n\n/** Reads whether the workspace has any run yet. */\nconst ChecklistWithRuns: FC<GettingStartedChecklistProps> = (props) => {\n const runs = useExecutionSummary();\n return <ChecklistBody {...props} hasRun={(runs.data?.total ?? 0) > 0} />;\n};\n\nconst ChecklistBody: FC<\n GettingStartedChecklistProps & {\n /** Whether a run exists; null when the member cannot read runs. */\n hasRun: boolean | null;\n }\n> = ({ hasBot, hasAgent, hasRun }) => {\n const t = useTr();\n const { navigateTo } = useBotlit();\n const workspaceId = useWorkspaceId();\n const canReadRuns = hasRun !== null;\n\n const knowledgeVariables = useMemo(() => ({ filters: { workspaceId } }), [workspaceId]);\n const knowledge = useWorkspaceQuery<BotmanorGettingStartedKnowledgeQuery, boolean>({\n document: BotmanorGettingStartedKnowledgeDocument,\n variables: knowledgeVariables,\n select: (data) => (data?.listBotmanorKnowledgeBasesPage.total ?? 0) > 0,\n fallback: false,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to check for knowledge bases',\n });\n const providers = useLLMProviders();\n const channels = useChannelOverview();\n\n const state: GettingStartedState = {\n hasKnowledge: knowledge.data,\n hasModel: providers.data.length > 0,\n hasAgent,\n hasBot,\n hasChannel: (channels.data?.connectorCount ?? 0) > 0,\n // A member who cannot read runs cannot see this step's result, so it is\n // left out (below) rather than blocking the checklist forever.\n hasRun: hasRun ?? true,\n };\n\n // A finished setup has nothing to suggest.\n if (isSetupComplete(state)) return null;\n\n const steps: NextStep[] = [\n {\n id: 'knowledge',\n label: t('botlit.dashboard.gettingStarted.knowledge', 'Add knowledge'),\n description: t(\n 'botlit.dashboard.gettingStarted.knowledgeDesc',\n 'Upload the documents and FAQs your bot should answer from.'\n ),\n icon: <BookOpen size={16} aria-hidden=\"true\" />,\n onClick: () => navigateTo('knowledge/new'),\n done: state.hasKnowledge,\n },\n {\n id: 'model',\n label: t('botlit.dashboard.gettingStarted.model', 'Connect a model provider'),\n description: t(\n 'botlit.dashboard.gettingStarted.modelDesc',\n 'Add the LLM provider and key your agents use to reply.'\n ),\n icon: <KeyRound size={16} aria-hidden=\"true\" />,\n onClick: () => navigateTo('settings'),\n done: state.hasModel,\n },\n {\n id: 'agent',\n label: t('botlit.dashboard.gettingStarted.agent', 'Create an agent'),\n description: t(\n 'botlit.dashboard.gettingStarted.agentDesc',\n 'Give it a model, instructions and your knowledge.'\n ),\n icon: <Bot size={16} aria-hidden=\"true\" />,\n onClick: () => navigateTo('agents/new'),\n done: state.hasAgent,\n },\n {\n id: 'bot',\n label: t('botlit.dashboard.gettingStarted.bot', 'Create a bot'),\n description: t(\n 'botlit.dashboard.gettingStarted.botDesc',\n 'Wrap your agent in a bot that people can talk to.'\n ),\n icon: <AppWindow size={16} aria-hidden=\"true\" />,\n onClick: () => navigateTo('bots/new'),\n done: state.hasBot,\n },\n {\n id: 'channel',\n label: t('botlit.dashboard.gettingStarted.channel', 'Connect a channel'),\n description: t(\n 'botlit.dashboard.gettingStarted.channelDesc',\n 'Put the bot on a website widget, Slack, Teams or another channel.'\n ),\n icon: <Radio size={16} aria-hidden=\"true\" />,\n onClick: () => navigateTo('channels/new'),\n done: state.hasChannel,\n },\n {\n id: 'test',\n label: t('botlit.dashboard.gettingStarted.test', 'Try it in chat'),\n description: t(\n 'botlit.dashboard.gettingStarted.testDesc',\n 'Send a first message and check the answer end to end.'\n ),\n icon: <MessageSquare size={16} aria-hidden=\"true\" />,\n onClick: () => navigateTo('chat'),\n done: state.hasRun,\n },\n ].filter((step) => step.id !== 'test' || canReadRuns);\n\n return (\n <div data-tour=\"botmanor-dashboard-getting-started\" data-testid=\"getting-started-checklist\">\n <NextSteps\n title={t('botlit.dashboard.gettingStarted.title', 'Get your first bot live')}\n storageKey={`botmanor-getting-started-${workspaceId ?? 'none'}`}\n steps={steps}\n />\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;AA0CA,IAAaA,KAA6D,MAAU;CAClF,IAAMC,IACJC,EAA8BC,EAAqB,UAAU,MAAM,WAC/DC,IACJF,EAA8BC,EAAqB,cAAc,MAAM;CAEzE,OADKF,IACEG,IACL,kBAACC,GAAD,EAAmB,GAAIC,EAAQ,CAAA,IAE/B,kBAACC,GAAD;EAAe,GAAID;EAAO,QAAQ;CAAO,CAAA,IAJhB;AAM7B,GAGMD,KAAuD,MAAU;CACrE,IAAMG,IAAOC,EAAoB;CACjC,OAAO,kBAACF,GAAD;EAAe,GAAID;EAAO,SAASE,EAAK,MAAM,SAAS,KAAK;CAAI,CAAA;AACzE,GAEMD,KAKD,EAAE,WAAQ,aAAU,gBAAa;CACpC,IAAMG,IAAIC,EAAM,GACV,EAAE,kBAAeC,EAAU,GAC3BC,IAAcC,EAAe,GAC7BV,IAAcW,MAAW,MAEzBC,IAAqBC,SAAe,EAAE,SAAS,EAAE,eAAY,EAAE,IAAI,CAACJ,CAAW,CAAC,GAChFK,IAAYC,EAAiE;EACjF,UAAUC;EACV,WAAWJ;EACX,SAAS,OAAUK,GAAM,+BAA+B,SAAS,KAAK;EACtE,UAAU;EACV,SAAS,EAAQR;EACjB,cAAc;CAChB,CAAC,GACKS,IAAYC,EAAgB,GAC5BC,IAAWC,EAAmB,GAE9BC,IAA6B;EACjC,cAAcR,EAAU;EACxB,UAAUI,EAAU,KAAK,SAAS;EAClC;EACA;EACA,aAAaE,EAAS,MAAM,kBAAkB,KAAK;EAGnD,QAAQT,KAAU;CACpB;CAGA,IAAIY,EAAgBD,CAAK,GAAG,OAAO;CAEnC,IAAME,IAAoB;EACxB;GACE,IAAI;GACJ,OAAOlB,EAAE,6CAA6C,eAAe;GACrE,a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C9D,UAAA,kBAACiC,GAAD;GACE,OAAO3B,EAAE,yCAAyC,yBAAyB;GAC3E,YAAY,4BAA4BG,KAAe;GAChD;EACR,CAAA;CACE,CAAA;AAET"}
|
|
@@ -24,10 +24,13 @@ var o = "\n id\n agentId\n versionId\n status\n requestedById\n requestNot
|
|
|
24
24
|
`, l = i`
|
|
25
25
|
query ListBotmanorAgentApprovalRequests(
|
|
26
26
|
$filter: BotmanorAgentApprovalFilterInput
|
|
27
|
-
$pagination:
|
|
27
|
+
$pagination: BotmanorOffsetPaginationInput
|
|
28
28
|
) {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
listBotmanorAgentApprovalRequestsPage(filter: $filter, pagination: $pagination) {
|
|
30
|
+
items {
|
|
31
|
+
${o}
|
|
32
|
+
}
|
|
33
|
+
nextOffset
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
36
|
`, u = i`
|
|
@@ -107,21 +110,29 @@ function g(i) {
|
|
|
107
110
|
else {
|
|
108
111
|
f(!0), h(void 0);
|
|
109
112
|
try {
|
|
110
|
-
let e =
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
let e = [], t = 0;
|
|
114
|
+
for (; t < 1e4;) {
|
|
115
|
+
let n = (await o.query({
|
|
116
|
+
query: l,
|
|
117
|
+
variables: {
|
|
118
|
+
filter: {
|
|
119
|
+
agentId: g || void 0,
|
|
120
|
+
status: _ || void 0
|
|
121
|
+
},
|
|
122
|
+
pagination: {
|
|
123
|
+
limit: 50,
|
|
124
|
+
offset: t
|
|
125
|
+
}
|
|
116
126
|
},
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
127
|
+
fetchPolicy: "network-only"
|
|
128
|
+
})).data?.listBotmanorAgentApprovalRequestsPage;
|
|
129
|
+
if (!n) break;
|
|
130
|
+
e.push(...n.items);
|
|
131
|
+
let r = n.nextOffset;
|
|
132
|
+
if (r === null || !Number.isSafeInteger(r) || r <= t) break;
|
|
133
|
+
t = r;
|
|
134
|
+
}
|
|
135
|
+
u(e);
|
|
125
136
|
} catch (e) {
|
|
126
137
|
h(m(e, "Failed to load activation requests"));
|
|
127
138
|
} finally {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAgentApprovals.js","names":["APPROVAL_REQUEST_FIELDS","GET_SETTINGS_DOCUMENT","UPDATE_SETTINGS_DOCUMENT","LIST_REQUESTS_DOCUMENT","REQUEST_ACTIVATION_DOCUMENT","APPROVE_DOCUMENT","REJECT_DOCUMENT","CANCEL_DOCUMENT","toError","error","fallback","useAgentApprovalSettings","client","useGatewayClient","useBotlit","data","setData","useState","loading","setLoading","saving","setSaving","setError","refetch","useCallback","workspaceId","result","queryError","useEffect","next","mutationError","useAgentApprovalRequests","filter","agentId","status","useAgentApprovalActions","pending","setPending","action","required","value","kind"],"sources":["../../../src/botlit/hooks/useAgentApprovals.ts"],"sourcesContent":["/**\n * Agent activation approval hooks (BOFF-9682).\n *\n * A workspace can require reviewer approval before an agent goes live. Builders\n * request activation; reviewers holding `botmanor-agent:approve` approve\n * (which publishes the agent's draft and sets it ACTIVE) or reject with a\n * reason. These hooks wrap the `*BotmanorAgentApproval*` fields of\n * wspace-botmanor-svc.\n */\nimport { gql, type ApolloClient } from '@apollo/client';\nimport { useCallback, useEffect, useState } from 'react';\nimport { useGatewayClient } from '@burdenoff/fe-libs/shared/graphql';\n\nimport { useBotlit } from '../providers/BotlitProvider';\n\nconst APPROVAL_REQUEST_FIELDS = `\n id\n agentId\n versionId\n status\n requestedById\n requestNote\n reviewerId\n decisionReason\n decidedAt\n isStale\n createdAt\n`;\n\nconst GET_SETTINGS_DOCUMENT = gql`\n query BotmanorAgentApprovalSettings {\n botmanorAgentApprovalSettings {\n workspaceId\n requireActivationApproval\n updatedAt\n updatedById\n }\n }\n`;\n\nconst UPDATE_SETTINGS_DOCUMENT = gql`\n mutation UpdateBotmanorAgentApprovalSettings($requireActivationApproval: Boolean!) {\n updateBotmanorAgentApprovalSettings(requireActivationApproval: $requireActivationApproval) {\n workspaceId\n requireActivationApproval\n updatedAt\n updatedById\n }\n }\n`;\n\nconst LIST_REQUESTS_DOCUMENT = gql`\n query ListBotmanorAgentApprovalRequests(\n $filter: BotmanorAgentApprovalFilterInput\n $pagination: PaginationInput\n ) {\n listBotmanorAgentApprovalRequests(filter: $filter, pagination: $pagination) {\n ${APPROVAL_REQUEST_FIELDS}\n }\n }\n`;\n\nconst REQUEST_ACTIVATION_DOCUMENT = gql`\n mutation RequestBotmanorAgentActivation($agentId: ID!, $note: String) {\n requestBotmanorAgentActivation(agentId: $agentId, note: $note) {\n ${APPROVAL_REQUEST_FIELDS}\n }\n }\n`;\n\nconst APPROVE_DOCUMENT = gql`\n mutation ApproveBotmanorAgentActivation($id: ID!, $reason: String) {\n approveBotmanorAgentActivation(id: $id, reason: $reason) {\n ${APPROVAL_REQUEST_FIELDS}\n }\n }\n`;\n\nconst REJECT_DOCUMENT = gql`\n mutation RejectBotmanorAgentActivation($id: ID!, $reason: String!) {\n rejectBotmanorAgentActivation(id: $id, reason: $reason) {\n ${APPROVAL_REQUEST_FIELDS}\n }\n }\n`;\n\nconst CANCEL_DOCUMENT = gql`\n mutation CancelBotmanorAgentActivationRequest($id: ID!) {\n cancelBotmanorAgentActivationRequest(id: $id) {\n ${APPROVAL_REQUEST_FIELDS}\n }\n }\n`;\n\nexport type AgentApprovalStatus = 'PENDING' | 'APPROVED' | 'REJECTED' | 'CANCELLED';\n\nexport interface AgentApprovalSettingsRecord {\n workspaceId: string;\n requireActivationApproval: boolean;\n updatedAt?: string | null;\n updatedById?: string | null;\n}\n\nexport interface AgentApprovalRequestRecord {\n id: string;\n agentId: string;\n versionId?: string | null;\n status: AgentApprovalStatus;\n requestedById: string;\n requestNote?: string | null;\n reviewerId?: string | null;\n decisionReason?: string | null;\n decidedAt?: string | null;\n isStale: boolean;\n createdAt: string;\n}\n\nexport interface AgentApprovalFilter {\n agentId?: string;\n status?: AgentApprovalStatus;\n}\n\nfunction toError(error: unknown, fallback: string): Error {\n return error instanceof Error ? error : new Error(fallback);\n}\n\n/** The workspace's approval requirement, with a setter for reviewers. */\nexport function useAgentApprovalSettings() {\n const client = useGatewayClient('workspace') as ApolloClient;\n const { workspaceId } = useBotlit();\n const [data, setData] = useState<AgentApprovalSettingsRecord | null>(null);\n const [loading, setLoading] = useState(false);\n const [saving, setSaving] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n\n const refetch = useCallback(async () => {\n if (!workspaceId) {\n setData(null);\n return;\n }\n setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<{\n botmanorAgentApprovalSettings: AgentApprovalSettingsRecord;\n }>({\n query: GET_SETTINGS_DOCUMENT,\n fetchPolicy: 'network-only',\n });\n setData(result.data?.botmanorAgentApprovalSettings ?? null);\n } catch (queryError) {\n setError(toError(queryError, 'Failed to load approval settings'));\n } finally {\n setLoading(false);\n }\n }, [client, workspaceId]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n const update = useCallback(\n async (requireActivationApproval: boolean) => {\n setSaving(true);\n try {\n const result = await client.mutate<{\n updateBotmanorAgentApprovalSettings: AgentApprovalSettingsRecord;\n }>({\n mutation: UPDATE_SETTINGS_DOCUMENT,\n variables: { requireActivationApproval },\n });\n const next = result.data?.updateBotmanorAgentApprovalSettings;\n if (!next) throw new Error('Failed to update approval settings');\n setData(next);\n return next;\n } catch (mutationError) {\n throw toError(mutationError, 'Failed to update approval settings');\n } finally {\n setSaving(false);\n }\n },\n [client]\n );\n\n return { data, loading, saving, error, refetch, update };\n}\n\n/** Activation requests in the workspace, newest first. */\nexport function useAgentApprovalRequests(filter: AgentApprovalFilter) {\n const client = useGatewayClient('workspace') as ApolloClient;\n const { workspaceId } = useBotlit();\n const [data, setData] = useState<AgentApprovalRequestRecord[]>([]);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n const { agentId, status } = filter;\n\n const refetch = useCallback(async () => {\n if (!workspaceId) {\n setData([]);\n return;\n }\n setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<{\n listBotmanorAgentApprovalRequests: AgentApprovalRequestRecord[];\n }>({\n query: LIST_REQUESTS_DOCUMENT,\n variables: {\n filter: { agentId: agentId || undefined, status: status || undefined },\n pagination: { limit: 50, offset: 0 },\n },\n fetchPolicy: 'network-only',\n });\n setData(result.data?.listBotmanorAgentApprovalRequests ?? []);\n } catch (queryError) {\n setError(toError(queryError, 'Failed to load activation requests'));\n } finally {\n setLoading(false);\n }\n }, [agentId, client, status, workspaceId]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\ntype ApprovalAction =\n | { kind: 'request'; agentId: string; note?: string }\n | { kind: 'approve'; id: string; reason?: string }\n | { kind: 'reject'; id: string; reason: string }\n | { kind: 'cancel'; id: string };\n\n/** Request, approve, reject or cancel an activation request. */\nexport function useAgentApprovalActions() {\n const client = useGatewayClient('workspace') as ApolloClient;\n const [pending, setPending] = useState<ApprovalAction['kind'] | null>(null);\n\n const run = useCallback(\n async (action: ApprovalAction): Promise<AgentApprovalRequestRecord> => {\n setPending(action.kind);\n try {\n switch (action.kind) {\n case 'request': {\n const result = await client.mutate<{\n requestBotmanorAgentActivation: AgentApprovalRequestRecord;\n }>({\n mutation: REQUEST_ACTIVATION_DOCUMENT,\n variables: { agentId: action.agentId, note: action.note?.trim() || undefined },\n });\n return required(result.data?.requestBotmanorAgentActivation, 'request');\n }\n case 'approve': {\n const result = await client.mutate<{\n approveBotmanorAgentActivation: AgentApprovalRequestRecord;\n }>({\n mutation: APPROVE_DOCUMENT,\n variables: { id: action.id, reason: action.reason?.trim() || undefined },\n });\n return required(result.data?.approveBotmanorAgentActivation, 'approve');\n }\n case 'reject': {\n const result = await client.mutate<{\n rejectBotmanorAgentActivation: AgentApprovalRequestRecord;\n }>({\n mutation: REJECT_DOCUMENT,\n variables: { id: action.id, reason: action.reason.trim() },\n });\n return required(result.data?.rejectBotmanorAgentActivation, 'reject');\n }\n case 'cancel': {\n const result = await client.mutate<{\n cancelBotmanorAgentActivationRequest: AgentApprovalRequestRecord;\n }>({\n mutation: CANCEL_DOCUMENT,\n variables: { id: action.id },\n });\n return required(result.data?.cancelBotmanorAgentActivationRequest, 'cancel');\n }\n }\n } catch (mutationError) {\n throw toError(mutationError, `Failed to ${action.kind} activation`);\n } finally {\n setPending(null);\n }\n },\n [client]\n );\n\n return { run, pending };\n}\n\nfunction required(\n value: AgentApprovalRequestRecord | undefined,\n kind: ApprovalAction['kind']\n): AgentApprovalRequestRecord {\n if (!value) throw new Error(`Failed to ${kind} activation`);\n return value;\n}\n"],"mappings":";;;;;AAeA,IAAMA,IAA0B,mJAc1BC,IAAwB,CAAG;;;;;;;;;GAW3BC,IAA2B,CAAG;;;;;;;;;GAW9BC,IAAyB,CAAG;;;;;;QAM1BH,EAAwB;;;GAK1BI,IAA8B,CAAG;;;QAG/BJ,EAAwB;;;GAK1BK,IAAmB,CAAG;;;QAGpBL,EAAwB;;;GAK1BM,IAAkB,CAAG;;;QAGnBN,EAAwB;;;GAK1BO,IAAkB,CAAG;;;QAGnBP,EAAwB;;;;AAiChC,SAASQ,EAAQ,GAAgB,GAAyB;CACxD,OAAOC,aAAiB,QAAQA,IAAY,MAAMC,CAAQ;AAC5D;AAGA,SAAgBC,IAA2B;CACzC,IAAMC,IAASC,EAAiB,WAAW,GACrC,EAAE,mBAAgBC,EAAU,GAC5B,CAACC,GAAMC,KAAWC,EAA6C,IAAI,GACnE,CAACC,GAASC,KAAcF,EAAS,EAAK,GACtC,CAACG,GAAQC,KAAaJ,EAAS,EAAK,GACpC,CAACR,GAAOa,KAAYL,EAA4B,GAEhDM,IAAUC,EAAY,YAAY;EACtC,IAAI,CAACC,GACH,EAAQ,IAAI;OAGd;GACA,AADAN,EAAW,EAAI,GACfG,EAAS,KAAA,CAAS;GAClB,IAAI;IACF,IA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O,GAAG;KAC7B,CAAC,EAAA,CACsB,MAAM,sCAAsC,QAAQ;IAE/E;GACF,SAASR,GAAe;IACtB,MAAMtB,EAAQsB,GAAe,aAAaQ,EAAO,KAAK,YAAY;GACpE,UAAU;IACR,EAAW,IAAI;GACjB;EACF,GACA,CAAC1B,CAAM,CAGA;EAAK;CAAQ;AACxB;AAEA,SAAS2B,EACP,GACA,GAC4B;CAC5B,IAAI,CAACC,GAAO,MAAU,MAAM,aAAaC,EAAK,YAAY;CAC1D,OAAOD;AACT"}
|
|
1
|
+
{"version":3,"file":"useAgentApprovals.js","names":["APPROVAL_REQUEST_FIELDS","GET_SETTINGS_DOCUMENT","UPDATE_SETTINGS_DOCUMENT","LIST_REQUESTS_DOCUMENT","REQUEST_ACTIVATION_DOCUMENT","APPROVE_DOCUMENT","REJECT_DOCUMENT","CANCEL_DOCUMENT","toError","error","fallback","useAgentApprovalSettings","client","useGatewayClient","useBotlit","data","setData","useState","loading","setLoading","saving","setSaving","setError","refetch","useCallback","workspaceId","result","queryError","useEffect","next","mutationError","useAgentApprovalRequests","filter","items","offset","page","agentId","status","nextOffset","useAgentApprovalActions","pending","setPending","action","required","value","kind"],"sources":["../../../src/botlit/hooks/useAgentApprovals.ts"],"sourcesContent":["/**\n * Agent activation approval hooks (BOFF-9682).\n *\n * A workspace can require reviewer approval before an agent goes live. Builders\n * request activation; reviewers holding `botmanor-agent:approve` approve\n * (which publishes the agent's draft and sets it ACTIVE) or reject with a\n * reason. These hooks wrap the `*BotmanorAgentApproval*` fields of\n * wspace-botmanor-svc.\n */\nimport { gql, type ApolloClient } from '@apollo/client';\nimport { useCallback, useEffect, useState } from 'react';\nimport { useGatewayClient } from '@burdenoff/fe-libs/shared/graphql';\n\nimport { useBotlit } from '../providers/BotlitProvider';\n\nconst APPROVAL_REQUEST_FIELDS = `\n id\n agentId\n versionId\n status\n requestedById\n requestNote\n reviewerId\n decisionReason\n decidedAt\n isStale\n createdAt\n`;\n\nconst GET_SETTINGS_DOCUMENT = gql`\n query BotmanorAgentApprovalSettings {\n botmanorAgentApprovalSettings {\n workspaceId\n requireActivationApproval\n updatedAt\n updatedById\n }\n }\n`;\n\nconst UPDATE_SETTINGS_DOCUMENT = gql`\n mutation UpdateBotmanorAgentApprovalSettings($requireActivationApproval: Boolean!) {\n updateBotmanorAgentApprovalSettings(requireActivationApproval: $requireActivationApproval) {\n workspaceId\n requireActivationApproval\n updatedAt\n updatedById\n }\n }\n`;\n\nconst LIST_REQUESTS_DOCUMENT = gql`\n query ListBotmanorAgentApprovalRequests(\n $filter: BotmanorAgentApprovalFilterInput\n $pagination: BotmanorOffsetPaginationInput\n ) {\n listBotmanorAgentApprovalRequestsPage(filter: $filter, pagination: $pagination) {\n items {\n ${APPROVAL_REQUEST_FIELDS}\n }\n nextOffset\n }\n }\n`;\n\nconst REQUEST_ACTIVATION_DOCUMENT = gql`\n mutation RequestBotmanorAgentActivation($agentId: ID!, $note: String) {\n requestBotmanorAgentActivation(agentId: $agentId, note: $note) {\n ${APPROVAL_REQUEST_FIELDS}\n }\n }\n`;\n\nconst APPROVE_DOCUMENT = gql`\n mutation ApproveBotmanorAgentActivation($id: ID!, $reason: String) {\n approveBotmanorAgentActivation(id: $id, reason: $reason) {\n ${APPROVAL_REQUEST_FIELDS}\n }\n }\n`;\n\nconst REJECT_DOCUMENT = gql`\n mutation RejectBotmanorAgentActivation($id: ID!, $reason: String!) {\n rejectBotmanorAgentActivation(id: $id, reason: $reason) {\n ${APPROVAL_REQUEST_FIELDS}\n }\n }\n`;\n\nconst CANCEL_DOCUMENT = gql`\n mutation CancelBotmanorAgentActivationRequest($id: ID!) {\n cancelBotmanorAgentActivationRequest(id: $id) {\n ${APPROVAL_REQUEST_FIELDS}\n }\n }\n`;\n\nexport type AgentApprovalStatus = 'PENDING' | 'APPROVED' | 'REJECTED' | 'CANCELLED';\n\nexport interface AgentApprovalSettingsRecord {\n workspaceId: string;\n requireActivationApproval: boolean;\n updatedAt?: string | null;\n updatedById?: string | null;\n}\n\nexport interface AgentApprovalRequestRecord {\n id: string;\n agentId: string;\n versionId?: string | null;\n status: AgentApprovalStatus;\n requestedById: string;\n requestNote?: string | null;\n reviewerId?: string | null;\n decisionReason?: string | null;\n decidedAt?: string | null;\n isStale: boolean;\n createdAt: string;\n}\n\nexport interface AgentApprovalFilter {\n agentId?: string;\n status?: AgentApprovalStatus;\n}\n\nfunction toError(error: unknown, fallback: string): Error {\n return error instanceof Error ? error : new Error(fallback);\n}\n\n/** The workspace's approval requirement, with a setter for reviewers. */\nexport function useAgentApprovalSettings() {\n const client = useGatewayClient('workspace') as ApolloClient;\n const { workspaceId } = useBotlit();\n const [data, setData] = useState<AgentApprovalSettingsRecord | null>(null);\n const [loading, setLoading] = useState(false);\n const [saving, setSaving] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n\n const refetch = useCallback(async () => {\n if (!workspaceId) {\n setData(null);\n return;\n }\n setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<{\n botmanorAgentApprovalSettings: AgentApprovalSettingsRecord;\n }>({\n query: GET_SETTINGS_DOCUMENT,\n fetchPolicy: 'network-only',\n });\n setData(result.data?.botmanorAgentApprovalSettings ?? null);\n } catch (queryError) {\n setError(toError(queryError, 'Failed to load approval settings'));\n } finally {\n setLoading(false);\n }\n }, [client, workspaceId]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n const update = useCallback(\n async (requireActivationApproval: boolean) => {\n setSaving(true);\n try {\n const result = await client.mutate<{\n updateBotmanorAgentApprovalSettings: AgentApprovalSettingsRecord;\n }>({\n mutation: UPDATE_SETTINGS_DOCUMENT,\n variables: { requireActivationApproval },\n });\n const next = result.data?.updateBotmanorAgentApprovalSettings;\n if (!next) throw new Error('Failed to update approval settings');\n setData(next);\n return next;\n } catch (mutationError) {\n throw toError(mutationError, 'Failed to update approval settings');\n } finally {\n setSaving(false);\n }\n },\n [client]\n );\n\n return { data, loading, saving, error, refetch, update };\n}\n\n/** Activation requests in the workspace, newest first. */\nexport function useAgentApprovalRequests(filter: AgentApprovalFilter) {\n const client = useGatewayClient('workspace') as ApolloClient;\n const { workspaceId } = useBotlit();\n const [data, setData] = useState<AgentApprovalRequestRecord[]>([]);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n const { agentId, status } = filter;\n\n const refetch = useCallback(async () => {\n if (!workspaceId) {\n setData([]);\n return;\n }\n setLoading(true);\n setError(undefined);\n try {\n const items: AgentApprovalRequestRecord[] = [];\n let offset = 0;\n while (offset < 10000) {\n const result = await client.query<{\n listBotmanorAgentApprovalRequestsPage: {\n items: AgentApprovalRequestRecord[];\n nextOffset: number | null;\n };\n }>({\n query: LIST_REQUESTS_DOCUMENT,\n variables: {\n filter: { agentId: agentId || undefined, status: status || undefined },\n pagination: { limit: 50, offset },\n },\n fetchPolicy: 'network-only',\n });\n const page = result.data?.listBotmanorAgentApprovalRequestsPage;\n if (!page) break;\n items.push(...page.items);\n const nextOffset: number | null = page.nextOffset;\n if (nextOffset === null || !Number.isSafeInteger(nextOffset) || nextOffset <= offset) {\n break;\n }\n offset = nextOffset;\n }\n setData(items);\n } catch (queryError) {\n setError(toError(queryError, 'Failed to load activation requests'));\n } finally {\n setLoading(false);\n }\n }, [agentId, client, status, workspaceId]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\ntype ApprovalAction =\n | { kind: 'request'; agentId: string; note?: string }\n | { kind: 'approve'; id: string; reason?: string }\n | { kind: 'reject'; id: string; reason: string }\n | { kind: 'cancel'; id: string };\n\n/** Request, approve, reject or cancel an activation request. */\nexport function useAgentApprovalActions() {\n const client = useGatewayClient('workspace') as ApolloClient;\n const [pending, setPending] = useState<ApprovalAction['kind'] | null>(null);\n\n const run = useCallback(\n async (action: ApprovalAction): Promise<AgentApprovalRequestRecord> => {\n setPending(action.kind);\n try {\n switch (action.kind) {\n case 'request': {\n const result = await client.mutate<{\n requestBotmanorAgentActivation: AgentApprovalRequestRecord;\n }>({\n mutation: REQUEST_ACTIVATION_DOCUMENT,\n variables: { agentId: action.agentId, note: action.note?.trim() || undefined },\n });\n return required(result.data?.requestBotmanorAgentActivation, 'request');\n }\n case 'approve': {\n const result = await client.mutate<{\n approveBotmanorAgentActivation: AgentApprovalRequestRecord;\n }>({\n mutation: APPROVE_DOCUMENT,\n variables: { id: action.id, reason: action.reason?.trim() || undefined },\n });\n return required(result.data?.approveBotmanorAgentActivation, 'approve');\n }\n case 'reject': {\n const result = await client.mutate<{\n rejectBotmanorAgentActivation: AgentApprovalRequestRecord;\n }>({\n mutation: REJECT_DOCUMENT,\n variables: { id: action.id, reason: action.reason.trim() },\n });\n return required(result.data?.rejectBotmanorAgentActivation, 'reject');\n }\n case 'cancel': {\n const result = await client.mutate<{\n cancelBotmanorAgentActivationRequest: AgentApprovalRequestRecord;\n }>({\n mutation: CANCEL_DOCUMENT,\n variables: { id: action.id },\n });\n return required(result.data?.cancelBotmanorAgentActivationRequest, 'cancel');\n }\n }\n } catch (mutationError) {\n throw toError(mutationError, `Failed to ${action.kind} activation`);\n } finally {\n setPending(null);\n }\n },\n [client]\n );\n\n return { run, pending };\n}\n\nfunction required(\n value: AgentApprovalRequestRecord | undefined,\n kind: ApprovalAction['kind']\n): AgentApprovalRequestRecord {\n if (!value) throw new Error(`Failed to ${kind} activation`);\n return value;\n}\n"],"mappings":";;;;;AAeA,IAAMA,IAA0B,mJAc1BC,IAAwB,CAAG;;;;;;;;;GAW3BC,IAA2B,CAAG;;;;;;;;;GAW9BC,IAAyB,CAAG;;;;;;;UAOxBH,EAAwB;;;;;GAO5BI,IAA8B,CAAG;;;QAG/BJ,EAAwB;;;GAK1BK,IAAmB,CAAG;;;QAGpBL,EAAwB;;;GAK1BM,IAAkB,CAAG;;;QAGnBN,EAAwB;;;GAK1BO,IAAkB,CAAG;;;QAGnBP,EAAwB;;;;AAiChC,SAASQ,EAAQ,GAAgB,GAAyB;CACxD,OAAOC,aAAiB,QAAQA,IAAY,MAAMC,CAAQ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AO,OAEzB;MACD,UAAUR;MACV,WAAW;OAAE,SAASsC,EAAO;OAAS,MAAMA,EAAO,MAAM,KAAK,KAAK,KAAA;MAAU;KAC/E,CAAC,EAAA,CACsB,MAAM,gCAAgC,SAAS;KAExE,KAAK,WAOH,OAAOC,GAAS,MANK/B,EAAO,OAEzB;MACD,UAAUP;MACV,WAAW;OAAE,IAAIqC,EAAO;OAAI,QAAQA,EAAO,QAAQ,KAAK,KAAK,KAAA;MAAU;KACzE,CAAC,EAAA,CACsB,MAAM,gCAAgC,SAAS;KAExE,KAAK,UAOH,OAAOC,GAAS,MANK/B,EAAO,OAEzB;MACD,UAAUN;MACV,WAAW;OAAE,IAAIoC,EAAO;OAAI,QAAQA,EAAO,OAAO,KAAK;MAAE;KAC3D,CAAC,EAAA,CACsB,MAAM,+BAA+B,QAAQ;KAEtE,KAAK,UAOH,OAAOC,GAAS,MANK/B,EAAO,OAEzB;MACD,UAAUL;MACV,WAAW,EAAE,IAAImC,EAAO,GAAG;KAC7B,CAAC,EAAA,CACsB,MAAM,sCAAsC,QAAQ;IAE/E;GACF,SAASZ,GAAe;IACtB,MAAMtB,EAAQsB,GAAe,aAAaY,EAAO,KAAK,YAAY;GACpE,UAAU;IACR,EAAW,IAAI;GACjB;EACF,GACA,CAAC9B,CAAM,CAGA;EAAK;CAAQ;AACxB;AAEA,SAAS+B,EACP,GACA,GAC4B;CAC5B,IAAI,CAACC,GAAO,MAAU,MAAM,aAAaC,EAAK,YAAY;CAC1D,OAAOD;AACT"}
|
|
@@ -7,16 +7,19 @@ import { gql as s } from "@apollo/client";
|
|
|
7
7
|
// src/botlit/hooks/useBotAgents.ts
|
|
8
8
|
var c = s`
|
|
9
9
|
query ListBotAgentLinks($filters: AppAgentFilterInput, $pagination: PaginationInput) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
listBotmanorAppAgentsPage(filters: $filters, pagination: $pagination) {
|
|
11
|
+
items {
|
|
12
|
+
id
|
|
13
|
+
appId
|
|
14
|
+
agentId
|
|
15
|
+
isActive
|
|
16
|
+
priority
|
|
17
|
+
triggerKeywords
|
|
18
|
+
intentPatterns
|
|
19
|
+
fallbackAgentId
|
|
20
|
+
timeout
|
|
21
|
+
}
|
|
22
|
+
nextOffset
|
|
20
23
|
}
|
|
21
24
|
}
|
|
22
25
|
`, l = s`
|
|
@@ -61,7 +64,8 @@ function m(e) {
|
|
|
61
64
|
document: c,
|
|
62
65
|
variables: i,
|
|
63
66
|
pageSize: f,
|
|
64
|
-
extractRows: (e) => e?.
|
|
67
|
+
extractRows: (e) => e?.listBotmanorAppAgentsPage?.items ?? p,
|
|
68
|
+
extractNextOffset: (e) => e?.listBotmanorAppAgentsPage?.nextOffset ?? null,
|
|
65
69
|
fallback: p,
|
|
66
70
|
enabled: !!(e && t),
|
|
67
71
|
errorMessage: "Failed to load the agents linked to this bot"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBotAgents.js","names":["LIST_APP_AGENTS_DOCUMENT","CREATE_APP_AGENT_DOCUMENT","UPDATE_APP_AGENT_DOCUMENT","DELETE_APP_AGENT_DOCUMENT","LINK_PAGE_SIZE","NO_LINKS","useBotAgentLinks","workspaceId","useWorkspaceId","variables","useMemo","botId","useAllPagesQuery","data","useLinkAgentToBot","useWorkspaceMutation","routing","useUpdateBotAgentLink","input","linkId","useUnlinkAgentFromBot","useBotKnowledgeBaseIds","links","bot","useBot","agents","useAgents","agentsError","hasMore","loadingMore","loadMore","linked","link","ids","agent","kbId"],"sources":["../../../src/botlit/hooks/useBotAgents.ts"],"sourcesContent":["/**\n * Bot-agent links (BOFF-12452)\n * @module botlit/hooks\n *\n * A bot reaches its agents through `AppAgent` links plus an optional default\n * agent. These hooks list a bot's links and add or remove one, so the bot's\n * Agents page can show only that bot's agents and a create-from-bot flow can\n * link what it creates. Setting the default agent is `useUpdateBot`.\n */\n\nimport { gql } from '@apollo/client';\nimport { useEffect, useMemo } from 'react';\n\nimport { useAgents } from './useAgents';\nimport { useBot } from './useBots';\nimport { useAllPagesQuery } from './internal/allPages';\nimport {\n useWorkspaceId,\n useWorkspaceMutation,\n type QueryResult,\n} from './internal/workspaceGateway';\n\nexport interface BotAgentLink {\n id: string;\n appId: string;\n agentId: string;\n isActive: boolean;\n priority: number;\n /** Keywords that route a message to this agent (KEYWORD-style routing). */\n triggerKeywords?: string[] | null;\n /** Regular-expression intents that route a message to this agent. */\n intentPatterns?: string[] | null;\n /** Agent that answers when this one fails or times out. */\n fallbackAgentId?: string | null;\n /** Seconds before the agent is considered to have timed out. */\n timeout?: number | null;\n}\n\ninterface ListAppAgentsData {\n
|
|
1
|
+
{"version":3,"file":"useBotAgents.js","names":["LIST_APP_AGENTS_DOCUMENT","CREATE_APP_AGENT_DOCUMENT","UPDATE_APP_AGENT_DOCUMENT","DELETE_APP_AGENT_DOCUMENT","LINK_PAGE_SIZE","NO_LINKS","useBotAgentLinks","workspaceId","useWorkspaceId","variables","useMemo","botId","useAllPagesQuery","data","useLinkAgentToBot","useWorkspaceMutation","routing","useUpdateBotAgentLink","input","linkId","useUnlinkAgentFromBot","useBotKnowledgeBaseIds","links","bot","useBot","agents","useAgents","agentsError","hasMore","loadingMore","loadMore","linked","link","ids","agent","kbId"],"sources":["../../../src/botlit/hooks/useBotAgents.ts"],"sourcesContent":["/**\n * Bot-agent links (BOFF-12452)\n * @module botlit/hooks\n *\n * A bot reaches its agents through `AppAgent` links plus an optional default\n * agent. These hooks list a bot's links and add or remove one, so the bot's\n * Agents page can show only that bot's agents and a create-from-bot flow can\n * link what it creates. Setting the default agent is `useUpdateBot`.\n */\n\nimport { gql } from '@apollo/client';\nimport { useEffect, useMemo } from 'react';\n\nimport { useAgents } from './useAgents';\nimport { useBot } from './useBots';\nimport { useAllPagesQuery } from './internal/allPages';\nimport {\n useWorkspaceId,\n useWorkspaceMutation,\n type QueryResult,\n} from './internal/workspaceGateway';\n\nexport interface BotAgentLink {\n id: string;\n appId: string;\n agentId: string;\n isActive: boolean;\n priority: number;\n /** Keywords that route a message to this agent (KEYWORD-style routing). */\n triggerKeywords?: string[] | null;\n /** Regular-expression intents that route a message to this agent. */\n intentPatterns?: string[] | null;\n /** Agent that answers when this one fails or times out. */\n fallbackAgentId?: string | null;\n /** Seconds before the agent is considered to have timed out. */\n timeout?: number | null;\n}\n\ninterface ListAppAgentsData {\n listBotmanorAppAgentsPage?: {\n items: BotAgentLink[];\n nextOffset: number | null;\n } | null;\n}\n\ninterface CreateAppAgentData {\n createAppAgent?: BotAgentLink | null;\n}\n\ninterface UpdateAppAgentData {\n updateAppAgent?: BotAgentLink | null;\n}\n\ninterface DeleteAppAgentData {\n deleteAppAgent?: boolean | null;\n}\n\nconst LIST_APP_AGENTS_DOCUMENT = gql`\n query ListBotAgentLinks($filters: AppAgentFilterInput, $pagination: PaginationInput) {\n listBotmanorAppAgentsPage(filters: $filters, pagination: $pagination) {\n items {\n id\n appId\n agentId\n isActive\n priority\n triggerKeywords\n intentPatterns\n fallbackAgentId\n timeout\n }\n nextOffset\n }\n }\n`;\n\nconst CREATE_APP_AGENT_DOCUMENT = gql`\n mutation LinkAgentToBot($input: CreateAppAgentInput!) {\n createAppAgent(input: $input) {\n id\n appId\n agentId\n isActive\n priority\n triggerKeywords\n intentPatterns\n fallbackAgentId\n timeout\n }\n }\n`;\n\nconst UPDATE_APP_AGENT_DOCUMENT = gql`\n mutation UpdateBotAgentLink($id: ID!, $input: UpdateAppAgentInput!) {\n updateAppAgent(id: $id, input: $input) {\n id\n appId\n agentId\n isActive\n priority\n triggerKeywords\n intentPatterns\n fallbackAgentId\n timeout\n }\n }\n`;\n\nconst DELETE_APP_AGENT_DOCUMENT = gql`\n mutation UnlinkAgentFromBot($id: ID!) {\n deleteAppAgent(id: $id)\n }\n`;\n\nconst LINK_PAGE_SIZE = 100;\nconst NO_LINKS: BotAgentLink[] = [];\n\n/**\n * Every agent linked to one bot. Disabled until there is a bot and a workspace.\n * It reads all pages (a bot can have more links than one page holds), and stays\n * `loading` until the last one is in, so a page never derives its list from a\n * partial set of links.\n */\nexport function useBotAgentLinks(botId: string | undefined): QueryResult<BotAgentLink[]> {\n const workspaceId = useWorkspaceId();\n const variables = useMemo(\n () => ({ filters: { appId: botId, workspaceId } }),\n [botId, workspaceId]\n );\n\n return useAllPagesQuery<ListAppAgentsData, BotAgentLink>({\n document: LIST_APP_AGENTS_DOCUMENT,\n variables,\n pageSize: LINK_PAGE_SIZE,\n extractRows: (data) => data?.listBotmanorAppAgentsPage?.items ?? NO_LINKS,\n extractNextOffset: (data) => data?.listBotmanorAppAgentsPage?.nextOffset ?? null,\n fallback: NO_LINKS,\n enabled: Boolean(botId && workspaceId),\n errorMessage: 'Failed to load the agents linked to this bot',\n });\n}\n\n/** Routing settings of one bot-agent link. */\nexport interface BotAgentRouting {\n priority?: number;\n triggerKeywords?: string[];\n intentPatterns?: string[];\n fallbackAgentId?: string | null;\n isActive?: boolean;\n}\n\nexport interface LinkAgentInput extends BotAgentRouting {\n botId: string;\n agentId: string;\n}\n\n/** Links an agent to a bot. */\nexport function useLinkAgentToBot() {\n const workspaceId = useWorkspaceId();\n return useWorkspaceMutation<CreateAppAgentData, LinkAgentInput, BotAgentLink>({\n document: CREATE_APP_AGENT_DOCUMENT,\n variables: ({ botId, agentId, ...routing }) => ({\n input: { appId: botId, agentId, workspaceId, ...routing },\n }),\n select: (data) => data?.createAppAgent ?? undefined,\n errorMessage: 'Failed to link the agent to the bot',\n });\n}\n\nexport interface UpdateLinkInput extends BotAgentRouting {\n linkId: string;\n}\n\n/** Changes the routing settings of a link. */\nexport function useUpdateBotAgentLink() {\n return useWorkspaceMutation<UpdateAppAgentData, UpdateLinkInput, BotAgentLink>({\n document: UPDATE_APP_AGENT_DOCUMENT,\n variables: ({ linkId, ...input }) => ({ id: linkId, input }),\n select: (data) => data?.updateAppAgent ?? undefined,\n errorMessage: 'Failed to update the agent routing',\n });\n}\n\n/** Removes a link (the agent itself is untouched). */\nexport function useUnlinkAgentFromBot() {\n return useWorkspaceMutation<DeleteAppAgentData, string, boolean>({\n document: DELETE_APP_AGENT_DOCUMENT,\n variables: (linkId) => ({ id: linkId }),\n select: (data) => data?.deleteAppAgent ?? undefined,\n errorMessage: 'Failed to remove the agent from the bot',\n });\n}\n\n/**\n * The knowledge bases a bot uses: the ones attached to the agents linked to it\n * (and to its default agent). A bot reaches knowledge only through its agents, so\n * this is what its knowledge page lists. Reads every page of agents, and is\n * `loading` until the links, the bot and every page are in.\n */\nexport function useBotKnowledgeBaseIds(botId: string | undefined): {\n ids: Set<string>;\n loading: boolean;\n error: Error | undefined;\n refetch: () => void;\n} {\n const links = useBotAgentLinks(botId);\n const bot = useBot(botId);\n // Only bot-scoped pages need the agents; the global list must not fetch them.\n const agents = useAgents(undefined, { enabled: Boolean(botId) });\n\n const { hasMore, loadingMore, loadMore, error: agentsError } = agents;\n useEffect(() => {\n if (botId && hasMore && !loadingMore && !agentsError) void loadMore();\n }, [botId, hasMore, loadingMore, agentsError, loadMore]);\n\n // Deactivated links are not used when the bot routes requests.\n const linked = new Set(links.data.filter((link) => link.isActive).map((link) => link.agentId));\n if (bot.data?.defaultAgentId) linked.add(bot.data.defaultAgentId);\n const ids = new Set<string>();\n for (const agent of agents.data) {\n if (linked.has(agent.id)) for (const kbId of agent.knowledgeBaseIds ?? []) ids.add(kbId);\n }\n\n return {\n ids,\n loading: links.loading || bot.loading || agents.loading || agents.loadingMore || agents.hasMore,\n error: links.error ?? bot.error ?? agents.error,\n refetch: () => {\n void links.refetch();\n void bot.refetch();\n void agents.refetch();\n },\n };\n}\n"],"mappings":";;;;;;;AAyDA,IAAMA,IAA2B,CAAG;;;;;;;;;;;;;;;;;GAmB9BC,IAA4B,CAAG;;;;;;;;;;;;;;GAgB/BC,IAA4B,CAAG;;;;;;;;;;;;;;GAgB/BC,IAA4B,CAAG;;;;GAM/BC,IAAiB,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,CAACC,KAAe,CAACF,KAAaG,EAAc;CACtE,GAAG;EAACnB;EAAOiB;EAASC;EAAaF;EAAaG;CAAQ,CAAC;CAGvD,IAAMC,IAAS,IAAI,IAAIT,EAAM,KAAK,QAAQ,MAASU,EAAK,QAAQ,CAAC,CAAC,KAAK,MAASA,EAAK,OAAO,CAAC;CAC7F,AAAIT,EAAI,MAAM,kBAAgBQ,EAAO,IAAIR,EAAI,KAAK,cAAc;CAChE,IAAMU,oBAAM,IAAI,IAAY;CAC5B,KAAK,IAAMC,KAAST,EAAO,MACzB,IAAIM,EAAO,IAAIG,EAAM,EAAE,GAAG,KAAK,IAAMC,KAAQD,EAAM,oBAAoB,CAAC,GAAG,EAAI,IAAIC,CAAI;CAGzF,OAAO;EACL;EACA,SAASb,EAAM,WAAWC,EAAI,WAAWE,EAAO,WAAWA,EAAO,eAAeA,EAAO;EACxF,OAAOH,EAAM,SAASC,EAAI,SAASE,EAAO;EAC1C,eAAe;GAGb,AAFAH,EAAW,QAAQ,GACnBC,EAAS,QAAQ,GACjBE,EAAY,QAAQ;EACtB;CACF;AACF"}
|
|
@@ -7,33 +7,6 @@ import { gql as d } from "@apollo/client";
|
|
|
7
7
|
import { useGatewayClient as f } from "@burdenoff/fe-libs/shared/graphql";
|
|
8
8
|
// src/botlit/hooks/useBots.ts
|
|
9
9
|
var p = d`
|
|
10
|
-
query ListBotApps($filters: BotAppFilterInput, $pagination: PaginationInput) {
|
|
11
|
-
listBotApps(filters: $filters, pagination: $pagination) {
|
|
12
|
-
id
|
|
13
|
-
name
|
|
14
|
-
slug
|
|
15
|
-
description
|
|
16
|
-
icon
|
|
17
|
-
type
|
|
18
|
-
status
|
|
19
|
-
visibility
|
|
20
|
-
routingStrategy
|
|
21
|
-
defaultAgentId
|
|
22
|
-
welcomeMessage
|
|
23
|
-
fallbackMessage
|
|
24
|
-
workflowId
|
|
25
|
-
executionCount
|
|
26
|
-
lastExecutedAt
|
|
27
|
-
tagIds
|
|
28
|
-
tags
|
|
29
|
-
createdAt
|
|
30
|
-
updatedAt
|
|
31
|
-
createdById
|
|
32
|
-
updatedById
|
|
33
|
-
workspaceId
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
`, m = d`
|
|
37
10
|
query GetBotApp($id: ID!) {
|
|
38
11
|
getBotApp(id: $id) {
|
|
39
12
|
id
|
|
@@ -60,7 +33,7 @@ var p = d`
|
|
|
60
33
|
workspaceId
|
|
61
34
|
}
|
|
62
35
|
}
|
|
63
|
-
`,
|
|
36
|
+
`, m = d`
|
|
64
37
|
mutation CreateBotApp($input: CreateBotAppInput!) {
|
|
65
38
|
createBotApp(input: $input) {
|
|
66
39
|
id
|
|
@@ -81,7 +54,7 @@ var p = d`
|
|
|
81
54
|
workspaceId
|
|
82
55
|
}
|
|
83
56
|
}
|
|
84
|
-
`,
|
|
57
|
+
`, h = d`
|
|
85
58
|
mutation UpdateBotApp($id: ID!, $input: UpdateBotAppInput!) {
|
|
86
59
|
updateBotApp(id: $id, input: $input) {
|
|
87
60
|
id
|
|
@@ -104,11 +77,11 @@ var p = d`
|
|
|
104
77
|
workspaceId
|
|
105
78
|
}
|
|
106
79
|
}
|
|
107
|
-
`,
|
|
80
|
+
`, g = d`
|
|
108
81
|
mutation DeleteBotApp($id: ID!) {
|
|
109
82
|
deleteBotApp(id: $id)
|
|
110
83
|
}
|
|
111
|
-
`,
|
|
84
|
+
`, _ = 100, v = [], y = r({
|
|
112
85
|
bucketId: !0,
|
|
113
86
|
context: !0,
|
|
114
87
|
defaultAgentId: !0,
|
|
@@ -127,10 +100,10 @@ var p = d`
|
|
|
127
100
|
welcomeMessage: !0,
|
|
128
101
|
workflowId: !0
|
|
129
102
|
});
|
|
130
|
-
function
|
|
103
|
+
function b(e) {
|
|
131
104
|
return e;
|
|
132
105
|
}
|
|
133
|
-
function
|
|
106
|
+
function x(e, t) {
|
|
134
107
|
if (e || t) return {
|
|
135
108
|
workspaceId: e,
|
|
136
109
|
search: t?.search,
|
|
@@ -139,34 +112,35 @@ function S(e, t) {
|
|
|
139
112
|
bucketId: t?.bucketId
|
|
140
113
|
};
|
|
141
114
|
}
|
|
142
|
-
function
|
|
143
|
-
let { workspaceId: r } = t(), i = l(() => ({ filters:
|
|
115
|
+
function S(n) {
|
|
116
|
+
let { workspaceId: r } = t(), i = l(() => ({ filters: x(r, n) }), [n, r]);
|
|
144
117
|
return a({
|
|
145
118
|
document: e,
|
|
146
119
|
variables: i,
|
|
147
|
-
pageSize:
|
|
120
|
+
pageSize: _,
|
|
148
121
|
extractRows: (e) => e?.listBotAppsPage.items ?? [],
|
|
149
122
|
extractNextOffset: (e) => e?.listBotAppsPage.nextOffset ?? null,
|
|
150
123
|
select: (e) => e,
|
|
151
|
-
fallback:
|
|
124
|
+
fallback: v,
|
|
152
125
|
enabled: !!r,
|
|
153
126
|
errorMessage: "Failed to load bots"
|
|
154
127
|
});
|
|
155
128
|
}
|
|
156
|
-
function
|
|
157
|
-
let { workspaceId:
|
|
129
|
+
function C() {
|
|
130
|
+
let { workspaceId: n } = t(), r = l(() => ({ filters: x(n) }), [n]);
|
|
158
131
|
return i({
|
|
159
|
-
document:
|
|
160
|
-
variables:
|
|
161
|
-
pageSize:
|
|
162
|
-
extractRows: (e) => e?.
|
|
132
|
+
document: e,
|
|
133
|
+
variables: r,
|
|
134
|
+
pageSize: _,
|
|
135
|
+
extractRows: (e) => e?.listBotAppsPage.items ?? [],
|
|
136
|
+
extractNextOffset: (e) => e?.listBotAppsPage.nextOffset ?? null,
|
|
163
137
|
select: (e) => e,
|
|
164
|
-
fallback:
|
|
165
|
-
enabled: !!
|
|
138
|
+
fallback: v,
|
|
139
|
+
enabled: !!n,
|
|
166
140
|
errorMessage: "Failed to load bots"
|
|
167
141
|
});
|
|
168
142
|
}
|
|
169
|
-
var
|
|
143
|
+
var w = d`
|
|
170
144
|
query GetBotAppCounts {
|
|
171
145
|
getBotAppCounts {
|
|
172
146
|
total
|
|
@@ -177,10 +151,10 @@ var T = d`
|
|
|
177
151
|
}
|
|
178
152
|
}
|
|
179
153
|
`;
|
|
180
|
-
function
|
|
154
|
+
function T(e = !0) {
|
|
181
155
|
let { workspaceId: n } = t(), r = l(() => ({}), []);
|
|
182
156
|
return o({
|
|
183
|
-
document:
|
|
157
|
+
document: w,
|
|
184
158
|
variables: r,
|
|
185
159
|
select: (e) => e?.getBotAppCounts ?? null,
|
|
186
160
|
fallback: null,
|
|
@@ -188,14 +162,14 @@ function E(e = !0) {
|
|
|
188
162
|
errorMessage: "Failed to load bot counts"
|
|
189
163
|
});
|
|
190
164
|
}
|
|
191
|
-
function
|
|
192
|
-
let t =
|
|
165
|
+
function E(e) {
|
|
166
|
+
let t = b(f("workspace")), [n, r] = u(null), [i, a] = u(!!e), [o, l] = u(), d = s(async () => {
|
|
193
167
|
if (!e) r(null), a(!1);
|
|
194
168
|
else {
|
|
195
169
|
a(!0), l(void 0);
|
|
196
170
|
try {
|
|
197
171
|
let n = await t.query({
|
|
198
|
-
query:
|
|
172
|
+
query: p,
|
|
199
173
|
variables: { id: e },
|
|
200
174
|
fetchPolicy: "network-only"
|
|
201
175
|
}), i = n.error;
|
|
@@ -217,8 +191,8 @@ function D(e) {
|
|
|
217
191
|
refetch: d
|
|
218
192
|
};
|
|
219
193
|
}
|
|
220
|
-
function
|
|
221
|
-
let e =
|
|
194
|
+
function D() {
|
|
195
|
+
let e = b(f("workspace")), [t, n] = u({
|
|
222
196
|
data: void 0,
|
|
223
197
|
loading: !1,
|
|
224
198
|
error: void 0
|
|
@@ -231,7 +205,7 @@ function O() {
|
|
|
231
205
|
});
|
|
232
206
|
try {
|
|
233
207
|
let r = (await e.mutate({
|
|
234
|
-
mutation:
|
|
208
|
+
mutation: m,
|
|
235
209
|
variables: { input: t }
|
|
236
210
|
})).data?.createBotApp;
|
|
237
211
|
if (!r) throw Error("Failed to create bot");
|
|
@@ -250,8 +224,8 @@ function O() {
|
|
|
250
224
|
}
|
|
251
225
|
}, [e]), t];
|
|
252
226
|
}
|
|
253
|
-
function
|
|
254
|
-
let e =
|
|
227
|
+
function O() {
|
|
228
|
+
let e = b(f("workspace")), [t, r] = u({
|
|
255
229
|
data: void 0,
|
|
256
230
|
loading: !1,
|
|
257
231
|
error: void 0
|
|
@@ -264,10 +238,10 @@ function k() {
|
|
|
264
238
|
});
|
|
265
239
|
try {
|
|
266
240
|
let a = (await e.mutate({
|
|
267
|
-
mutation:
|
|
241
|
+
mutation: h,
|
|
268
242
|
variables: {
|
|
269
243
|
id: t,
|
|
270
|
-
input: n(i,
|
|
244
|
+
input: n(i, y)
|
|
271
245
|
}
|
|
272
246
|
})).data?.updateBotApp;
|
|
273
247
|
if (!a) throw Error("Failed to update bot");
|
|
@@ -286,8 +260,8 @@ function k() {
|
|
|
286
260
|
}
|
|
287
261
|
}, [e]), t];
|
|
288
262
|
}
|
|
289
|
-
function
|
|
290
|
-
let e =
|
|
263
|
+
function k() {
|
|
264
|
+
let e = b(f("workspace")), [t, n] = u({
|
|
291
265
|
data: void 0,
|
|
292
266
|
loading: !1,
|
|
293
267
|
error: void 0
|
|
@@ -300,7 +274,7 @@ function A() {
|
|
|
300
274
|
});
|
|
301
275
|
try {
|
|
302
276
|
let r = (await e.mutate({
|
|
303
|
-
mutation:
|
|
277
|
+
mutation: g,
|
|
304
278
|
variables: { id: t }
|
|
305
279
|
})).data?.deleteBotApp ?? !1;
|
|
306
280
|
return n({
|
|
@@ -318,6 +292,6 @@ function A() {
|
|
|
318
292
|
}
|
|
319
293
|
}, [e]), t];
|
|
320
294
|
}
|
|
321
|
-
export {
|
|
295
|
+
export { C as useAllBots, E as useBot, T as useBotAppCounts, S as useBots, D as useCreateBot, k as useDeleteBot, O as useUpdateBot };
|
|
322
296
|
|
|
323
297
|
//# sourceMappingURL=useBots.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBots.js","names":["LIST_BOT_APPS_DOCUMENT","GET_BOT_APP_DOCUMENT","CREATE_BOT_APP_DOCUMENT","UPDATE_BOT_APP_DOCUMENT","DELETE_BOT_APP_DOCUMENT","LIST_PAGE_SIZE","NO_BOTS","UPDATE_BOT_APP_FIELDS","fieldsOf","getWorkspaceClient","client","buildBotFilter","workspaceId","filter","useBots","useBotlit","variables","useMemo","useWorkspacePaginatedQuery","ListBotAppsPageDocument","data","rows","useAllBots","useWorkspaceAllPagesQuery","GET_BOT_APP_COUNTS_DOCUMENT","useBotAppCounts","useWorkspaceQuery","enabled","useBot","useGatewayClient","setData","useState","loading","setLoading","botId","error","setError","refetch","useCallback","result","operationError","queryError","useEffect","useCreateBot","state","setState","createdBot","mutationError","useUpdateBot","updatedBot","buildMutationInput","input","useDeleteBot","deleted"],"sources":["../../../src/botlit/hooks/useBots.ts"],"sourcesContent":["import { gql, type ApolloClient } from '@apollo/client';\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport { useGatewayClient } from '@burdenoff/fe-libs/shared/graphql';\n\nimport {\n ListBotAppsPageDocument,\n type ListBotAppsPageQuery,\n} from '../../generated/wspace-operations';\nimport type { UpdateBotAppInput } from '../../generated/wspace-types';\nimport { useBotlit } from '../providers/BotlitProvider';\nimport type { BaseFilter } from '../types';\nimport { buildMutationInput, fieldsOf, type GraphQLInput } from './internal/mutationInput';\nimport {\n useWorkspaceAllPagesQuery,\n useWorkspacePaginatedQuery,\n useWorkspaceQuery,\n type PaginatedQueryResult,\n type QueryResult,\n} from './internal/workspaceGateway';\n\nconst LIST_BOT_APPS_DOCUMENT = gql`\n query ListBotApps($filters: BotAppFilterInput, $pagination: PaginationInput) {\n listBotApps(filters: $filters, pagination: $pagination) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n welcomeMessage\n fallbackMessage\n workflowId\n executionCount\n lastExecutedAt\n tagIds\n tags\n createdAt\n updatedAt\n createdById\n updatedById\n workspaceId\n }\n }\n`;\n\nconst GET_BOT_APP_DOCUMENT = gql`\n query GetBotApp($id: ID!) {\n getBotApp(id: $id) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n welcomeMessage\n fallbackMessage\n workflowId\n executionCount\n lastExecutedAt\n tagIds\n tags\n createdAt\n updatedAt\n createdById\n updatedById\n workspaceId\n }\n }\n`;\n\nconst CREATE_BOT_APP_DOCUMENT = gql`\n mutation CreateBotApp($input: CreateBotAppInput!) {\n createBotApp(input: $input) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n workflowId\n tagIds\n tags\n createdAt\n updatedAt\n workspaceId\n }\n }\n`;\n\nconst UPDATE_BOT_APP_DOCUMENT = gql`\n mutation UpdateBotApp($id: ID!, $input: UpdateBotAppInput!) {\n updateBotApp(id: $id, input: $input) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n welcomeMessage\n fallbackMessage\n workflowId\n tagIds\n tags\n updatedAt\n updatedById\n workspaceId\n }\n }\n`;\n\nconst DELETE_BOT_APP_DOCUMENT = gql`\n mutation DeleteBotApp($id: ID!) {\n deleteBotApp(id: $id)\n }\n`;\n\ntype WorkspaceClient = ApolloClient;\n\nexport interface BotAppRecord {\n id: string;\n name: string;\n slug: string;\n description?: string | null;\n icon?: string | null;\n type: string;\n status: string;\n visibility?: string | null;\n routingStrategy?: string | null;\n defaultAgentId?: string | null;\n welcomeMessage?: string | null;\n fallbackMessage?: string | null;\n /** Bound FluidGrids workflow definition id — the bot's designed behaviour. */\n workflowId?: string | null;\n executionCount?: number | null;\n lastExecutedAt?: string | null;\n tagIds?: string[] | null;\n /** Entity-owned universal tag records (JSON). */\n tags?: unknown;\n createdAt?: string | null;\n updatedAt?: string | null;\n createdById?: string | null;\n updatedById?: string | null;\n workspaceId?: string | null;\n}\n\ninterface ListBotAppsData {\n listBotApps: BotAppRecord[];\n}\n\nconst LIST_PAGE_SIZE = 100;\nconst NO_BOTS: BotAppRecord[] = [];\n\ninterface GetBotAppData {\n getBotApp: BotAppRecord | null;\n}\n\ninterface CreateBotAppData {\n createBotApp: BotAppRecord;\n}\n\ninterface UpdateBotAppData {\n updateBotApp: BotAppRecord;\n}\n\ninterface DeleteBotAppData {\n deleteBotApp: boolean;\n}\n\ninterface BotMutationState<T> {\n data: T | undefined;\n loading: boolean;\n error: Error | undefined;\n}\n\ninterface CreateBotInput {\n workspaceId: string;\n name: string;\n slug?: string;\n type: string;\n routingStrategy?: string;\n visibility?: string;\n description?: string;\n icon?: string;\n}\n\ninterface UpdateBotInput {\n botId: string;\n input: GraphQLInput<UpdateBotAppInput>;\n}\n\nconst UPDATE_BOT_APP_FIELDS = fieldsOf<UpdateBotAppInput>({\n bucketId: true,\n context: true,\n defaultAgentId: true,\n description: true,\n fallbackMessage: true,\n icon: true,\n metadata: true,\n name: true,\n routingStrategy: true,\n slug: true,\n status: true,\n tagIds: true,\n tags: true,\n type: true,\n visibility: true,\n welcomeMessage: true,\n workflowId: true,\n});\n\nfunction getWorkspaceClient(client: unknown): WorkspaceClient {\n return client as WorkspaceClient;\n}\n\nfunction buildBotFilter(\n workspaceId: string | undefined,\n filter?: BaseFilter\n): Record<string, unknown> | undefined {\n if (!workspaceId && !filter) return undefined;\n\n return {\n workspaceId,\n search: filter?.search,\n status: filter?.status?.[0],\n visibility: filter?.visibility?.[0],\n bucketId: filter?.bucketId,\n };\n}\n\nexport const botKeys = {\n all: ['bots'] as const,\n lists: () => [...botKeys.all, 'list'] as const,\n list: (filter?: BaseFilter) => [...botKeys.lists(), filter] as const,\n details: () => [...botKeys.all, 'detail'] as const,\n detail: (id: string) => [...botKeys.details(), id] as const,\n};\n\nexport function useBots(filter?: BaseFilter): PaginatedQueryResult<BotAppRecord[]> {\n const { workspaceId } = useBotlit();\n\n const variables = useMemo(\n () => ({ filters: buildBotFilter(workspaceId, filter) }),\n [filter, workspaceId]\n );\n\n return useWorkspacePaginatedQuery<ListBotAppsPageQuery, BotAppRecord, BotAppRecord[]>({\n document: ListBotAppsPageDocument,\n variables,\n pageSize: LIST_PAGE_SIZE,\n extractRows: (data) => data?.listBotAppsPage.items ?? [],\n extractNextOffset: (data) => data?.listBotAppsPage.nextOffset ?? null,\n select: (rows) => rows,\n fallback: NO_BOTS,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load bots',\n });\n}\n\n/**\n * Every bot of the workspace, all pages. For pickers that must offer each bot\n * (a route can point at any of them), where `useBots` stops at one page.\n */\nexport function useAllBots(): QueryResult<BotAppRecord[]> {\n const { workspaceId } = useBotlit();\n const variables = useMemo(() => ({ filters: buildBotFilter(workspaceId) }), [workspaceId]);\n\n return useWorkspaceAllPagesQuery<ListBotAppsData, BotAppRecord, BotAppRecord[]>({\n document: LIST_BOT_APPS_DOCUMENT,\n variables,\n pageSize: LIST_PAGE_SIZE,\n extractRows: (data) => data?.listBotApps ?? [],\n select: (rows) => rows,\n fallback: NO_BOTS,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load bots',\n });\n}\n\n/**\n * Exact bot counts by status for the workspace (BOFF-12426). Unlike `useBots`\n * this is not capped at one page, so it is the source for dashboard totals.\n * `total` counts every status; the dashboard shows `total - archived`.\n */\nexport interface BotAppCounts {\n total: number;\n draft: number;\n active: number;\n paused: number;\n archived: number;\n}\n\ninterface BotAppCountsData {\n getBotAppCounts?: BotAppCounts | null;\n}\n\nconst GET_BOT_APP_COUNTS_DOCUMENT = gql`\n query GetBotAppCounts {\n getBotAppCounts {\n total\n draft\n active\n paused\n archived\n }\n }\n`;\n\nexport function useBotAppCounts(enabled = true): QueryResult<BotAppCounts | null> {\n const { workspaceId } = useBotlit();\n const variables = useMemo(() => ({}), []);\n\n return useWorkspaceQuery<BotAppCountsData, BotAppCounts | null>({\n document: GET_BOT_APP_COUNTS_DOCUMENT,\n variables,\n select: (data) => data?.getBotAppCounts ?? null,\n fallback: null,\n enabled: enabled && Boolean(workspaceId),\n errorMessage: 'Failed to load bot counts',\n });\n}\n\nexport function useBot(botId: string | undefined) {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [data, setData] = useState<BotAppRecord | null>(null);\n // Loading from the first render when there is a bot to read, so a page that\n // depends on the bot never acts on \"no bot yet\" for the frame before the read.\n const [loading, setLoading] = useState(Boolean(botId));\n const [error, setError] = useState<Error | undefined>();\n\n const refetch = useCallback(async () => {\n if (!botId) {\n setData(null);\n setLoading(false);\n return;\n }\n\n setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<GetBotAppData>({\n query: GET_BOT_APP_DOCUMENT,\n variables: { id: botId },\n fetchPolicy: 'network-only',\n });\n // Apollo v4 resolves (not rejects) with `result.error` set on GraphQL errors.\n // Without this a FORBIDDEN read looked like \"bot not found\" (BOFF-12436).\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw operationError instanceof Error ? operationError : new Error('Failed to load bot');\n }\n setData(result.data?.getBotApp ?? null);\n } catch (queryError) {\n setData(null);\n setError(queryError instanceof Error ? queryError : new Error('Failed to load bot'));\n } finally {\n setLoading(false);\n }\n }, [botId, client]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\nexport function useCreateBot() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<BotMutationState<BotAppRecord>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const createBot = useCallback(\n async (input: CreateBotInput) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<CreateBotAppData>({\n mutation: CREATE_BOT_APP_DOCUMENT,\n variables: { input },\n });\n\n const createdBot = result.data?.createBotApp;\n if (!createdBot) {\n throw new Error('Failed to create bot');\n }\n\n setState({ data: createdBot, loading: false, error: undefined });\n return createdBot;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error ? mutationError : new Error('Failed to create bot');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [createBot, state] as const;\n}\n\nexport function useUpdateBot() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<BotMutationState<BotAppRecord>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const updateBot = useCallback(\n async ({ botId, input }: UpdateBotInput) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<UpdateBotAppData>({\n mutation: UPDATE_BOT_APP_DOCUMENT,\n variables: { id: botId, input: buildMutationInput(input, UPDATE_BOT_APP_FIELDS) },\n });\n\n const updatedBot = result.data?.updateBotApp;\n if (!updatedBot) {\n throw new Error('Failed to update bot');\n }\n\n setState({ data: updatedBot, loading: false, error: undefined });\n return updatedBot;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error ? mutationError : new Error('Failed to update bot');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [updateBot, state] as const;\n}\n\nexport function useDeleteBot() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<BotMutationState<boolean>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const deleteBot = useCallback(\n async (botId: string) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<DeleteBotAppData>({\n mutation: DELETE_BOT_APP_DOCUMENT,\n variables: { id: botId },\n });\n\n const deleted = result.data?.deleteBotApp ?? false;\n setState({ data: deleted, loading: false, error: undefined });\n return deleted;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error ? mutationError : new Error('Failed to delete bot');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [deleteBot, state] as const;\n}\n"],"mappings":";;;;;;;;AAoBA,IAAMA,IAAyB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6B5BC,IAAuB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6B1BC,IAA0B,CAAG;;;;;;;;;;;;;;;;;;;;;GAuB7BC,IAA0B,CAAG;;;;;;;;;;;;;;;;;;;;;;;GAyB7BC,IAA0B,CAAG;;;;GAuC7BC,IAAiB,KACjBC,IAA0B,CAAC,GAwC3BC,IAAwBC,EAA4B;CACxD,UAAU;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E,MAAM,KAAA;IAAW,SAAS;IAAO;GAAM,CAAC,GAC7CV;EACR;CACF,GACA,CAACzB,CAAM,CAGD,GAAWkC,CAAK;AAC1B;AAEA,SAAgBQ,IAAe;CAC7B,IAAM1C,IAASD,EAAmBoB,EAAiB,WAAW,CAAC,GACzD,CAACe,GAAOC,KAAYd,EAAoC;EAC5D,MAAM,KAAA;EACN,SAAS;EACT,OAAO,KAAA;CACT,CAAC;CAwBD,OAAO,CAtBWO,EAChB,OAAO,MAAkB;EACvB,EAAS;GAAE,MAAM,KAAA;GAAW,SAAS;GAAM,OAAO,KAAA;EAAU,CAAC;EAC7D,IAAI;GAMF,IAAMe,KAAU,MALK3C,EAAO,OAAyB;IACnD,UAAUN;IACV,WAAW,EAAE,IAAI8B,EAAM;GACzB,CAAC,EAAA,CAEsB,MAAM,gBAAgB;GAE7C,OADAW,EAAS;IAAE,MAAMQ;IAAS,SAAS;IAAO,OAAO,KAAA;GAAU,CAAC,GACrDA;EACT,SAASN,GAAe;GACtB,IAAMZ,IACJY,aAAyB,QAAQA,IAAgB,gBAAI,MAAM,sBAAsB;GAEnF,MADAF,EAAS;IAAE,MAAM,KAAA;IAAW,SAAS;IAAO;GAAM,CAAC,GAC7CV;EACR;CACF,GACA,CAACzB,CAAM,CAGD,GAAWkC,CAAK;AAC1B"}
|
|
1
|
+
{"version":3,"file":"useBots.js","names":["GET_BOT_APP_DOCUMENT","CREATE_BOT_APP_DOCUMENT","UPDATE_BOT_APP_DOCUMENT","DELETE_BOT_APP_DOCUMENT","LIST_PAGE_SIZE","NO_BOTS","UPDATE_BOT_APP_FIELDS","fieldsOf","getWorkspaceClient","client","buildBotFilter","workspaceId","filter","useBots","useBotlit","variables","useMemo","useWorkspacePaginatedQuery","ListBotAppsPageDocument","data","rows","useAllBots","useWorkspaceAllPagesQuery","GET_BOT_APP_COUNTS_DOCUMENT","useBotAppCounts","useWorkspaceQuery","enabled","useBot","useGatewayClient","setData","useState","loading","setLoading","botId","error","setError","refetch","useCallback","result","operationError","queryError","useEffect","useCreateBot","state","setState","createdBot","mutationError","useUpdateBot","updatedBot","buildMutationInput","input","useDeleteBot","deleted"],"sources":["../../../src/botlit/hooks/useBots.ts"],"sourcesContent":["import { gql, type ApolloClient } from '@apollo/client';\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport { useGatewayClient } from '@burdenoff/fe-libs/shared/graphql';\n\nimport {\n ListBotAppsPageDocument,\n type ListBotAppsPageQuery,\n} from '../../generated/wspace-operations';\nimport type { UpdateBotAppInput } from '../../generated/wspace-types';\nimport { useBotlit } from '../providers/BotlitProvider';\nimport type { BaseFilter } from '../types';\nimport { buildMutationInput, fieldsOf, type GraphQLInput } from './internal/mutationInput';\nimport {\n useWorkspaceAllPagesQuery,\n useWorkspacePaginatedQuery,\n useWorkspaceQuery,\n type PaginatedQueryResult,\n type QueryResult,\n} from './internal/workspaceGateway';\n\nconst GET_BOT_APP_DOCUMENT = gql`\n query GetBotApp($id: ID!) {\n getBotApp(id: $id) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n welcomeMessage\n fallbackMessage\n workflowId\n executionCount\n lastExecutedAt\n tagIds\n tags\n createdAt\n updatedAt\n createdById\n updatedById\n workspaceId\n }\n }\n`;\n\nconst CREATE_BOT_APP_DOCUMENT = gql`\n mutation CreateBotApp($input: CreateBotAppInput!) {\n createBotApp(input: $input) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n workflowId\n tagIds\n tags\n createdAt\n updatedAt\n workspaceId\n }\n }\n`;\n\nconst UPDATE_BOT_APP_DOCUMENT = gql`\n mutation UpdateBotApp($id: ID!, $input: UpdateBotAppInput!) {\n updateBotApp(id: $id, input: $input) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n welcomeMessage\n fallbackMessage\n workflowId\n tagIds\n tags\n updatedAt\n updatedById\n workspaceId\n }\n }\n`;\n\nconst DELETE_BOT_APP_DOCUMENT = gql`\n mutation DeleteBotApp($id: ID!) {\n deleteBotApp(id: $id)\n }\n`;\n\ntype WorkspaceClient = ApolloClient;\n\nexport interface BotAppRecord {\n id: string;\n name: string;\n slug: string;\n description?: string | null;\n icon?: string | null;\n type: string;\n status: string;\n visibility?: string | null;\n routingStrategy?: string | null;\n defaultAgentId?: string | null;\n welcomeMessage?: string | null;\n fallbackMessage?: string | null;\n /** Bound FluidGrids workflow definition id — the bot's designed behaviour. */\n workflowId?: string | null;\n executionCount?: number | null;\n lastExecutedAt?: string | null;\n tagIds?: string[] | null;\n /** Entity-owned universal tag records (JSON). */\n tags?: unknown;\n createdAt?: string | null;\n updatedAt?: string | null;\n createdById?: string | null;\n updatedById?: string | null;\n workspaceId?: string | null;\n}\n\nconst LIST_PAGE_SIZE = 100;\nconst NO_BOTS: BotAppRecord[] = [];\n\ninterface GetBotAppData {\n getBotApp: BotAppRecord | null;\n}\n\ninterface CreateBotAppData {\n createBotApp: BotAppRecord;\n}\n\ninterface UpdateBotAppData {\n updateBotApp: BotAppRecord;\n}\n\ninterface DeleteBotAppData {\n deleteBotApp: boolean;\n}\n\ninterface BotMutationState<T> {\n data: T | undefined;\n loading: boolean;\n error: Error | undefined;\n}\n\ninterface CreateBotInput {\n workspaceId: string;\n name: string;\n slug?: string;\n type: string;\n routingStrategy?: string;\n visibility?: string;\n description?: string;\n icon?: string;\n}\n\ninterface UpdateBotInput {\n botId: string;\n input: GraphQLInput<UpdateBotAppInput>;\n}\n\nconst UPDATE_BOT_APP_FIELDS = fieldsOf<UpdateBotAppInput>({\n bucketId: true,\n context: true,\n defaultAgentId: true,\n description: true,\n fallbackMessage: true,\n icon: true,\n metadata: true,\n name: true,\n routingStrategy: true,\n slug: true,\n status: true,\n tagIds: true,\n tags: true,\n type: true,\n visibility: true,\n welcomeMessage: true,\n workflowId: true,\n});\n\nfunction getWorkspaceClient(client: unknown): WorkspaceClient {\n return client as WorkspaceClient;\n}\n\nfunction buildBotFilter(\n workspaceId: string | undefined,\n filter?: BaseFilter\n): Record<string, unknown> | undefined {\n if (!workspaceId && !filter) return undefined;\n\n return {\n workspaceId,\n search: filter?.search,\n status: filter?.status?.[0],\n visibility: filter?.visibility?.[0],\n bucketId: filter?.bucketId,\n };\n}\n\nexport const botKeys = {\n all: ['bots'] as const,\n lists: () => [...botKeys.all, 'list'] as const,\n list: (filter?: BaseFilter) => [...botKeys.lists(), filter] as const,\n details: () => [...botKeys.all, 'detail'] as const,\n detail: (id: string) => [...botKeys.details(), id] as const,\n};\n\nexport function useBots(filter?: BaseFilter): PaginatedQueryResult<BotAppRecord[]> {\n const { workspaceId } = useBotlit();\n\n const variables = useMemo(\n () => ({ filters: buildBotFilter(workspaceId, filter) }),\n [filter, workspaceId]\n );\n\n return useWorkspacePaginatedQuery<ListBotAppsPageQuery, BotAppRecord, BotAppRecord[]>({\n document: ListBotAppsPageDocument,\n variables,\n pageSize: LIST_PAGE_SIZE,\n extractRows: (data) => data?.listBotAppsPage.items ?? [],\n extractNextOffset: (data) => data?.listBotAppsPage.nextOffset ?? null,\n select: (rows) => rows,\n fallback: NO_BOTS,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load bots',\n });\n}\n\n/**\n * Every bot of the workspace, all pages. For pickers that must offer each bot\n * (a route can point at any of them), where `useBots` stops at one page.\n */\nexport function useAllBots(): QueryResult<BotAppRecord[]> {\n const { workspaceId } = useBotlit();\n const variables = useMemo(() => ({ filters: buildBotFilter(workspaceId) }), [workspaceId]);\n\n return useWorkspaceAllPagesQuery<ListBotAppsPageQuery, BotAppRecord, BotAppRecord[]>({\n document: ListBotAppsPageDocument,\n variables,\n pageSize: LIST_PAGE_SIZE,\n extractRows: (data) => data?.listBotAppsPage.items ?? [],\n extractNextOffset: (data) => data?.listBotAppsPage.nextOffset ?? null,\n select: (rows) => rows,\n fallback: NO_BOTS,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load bots',\n });\n}\n\n/**\n * Exact bot counts by status for the workspace (BOFF-12426). Unlike `useBots`\n * this is not capped at one page, so it is the source for dashboard totals.\n * `total` counts every status; the dashboard shows `total - archived`.\n */\nexport interface BotAppCounts {\n total: number;\n draft: number;\n active: number;\n paused: number;\n archived: number;\n}\n\ninterface BotAppCountsData {\n getBotAppCounts?: BotAppCounts | null;\n}\n\nconst GET_BOT_APP_COUNTS_DOCUMENT = gql`\n query GetBotAppCounts {\n getBotAppCounts {\n total\n draft\n active\n paused\n archived\n }\n }\n`;\n\nexport function useBotAppCounts(enabled = true): QueryResult<BotAppCounts | null> {\n const { workspaceId } = useBotlit();\n const variables = useMemo(() => ({}), []);\n\n return useWorkspaceQuery<BotAppCountsData, BotAppCounts | null>({\n document: GET_BOT_APP_COUNTS_DOCUMENT,\n variables,\n select: (data) => data?.getBotAppCounts ?? null,\n fallback: null,\n enabled: enabled && Boolean(workspaceId),\n errorMessage: 'Failed to load bot counts',\n });\n}\n\nexport function useBot(botId: string | undefined) {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [data, setData] = useState<BotAppRecord | null>(null);\n // Loading from the first render when there is a bot to read, so a page that\n // depends on the bot never acts on \"no bot yet\" for the frame before the read.\n const [loading, setLoading] = useState(Boolean(botId));\n const [error, setError] = useState<Error | undefined>();\n\n const refetch = useCallback(async () => {\n if (!botId) {\n setData(null);\n setLoading(false);\n return;\n }\n\n setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<GetBotAppData>({\n query: GET_BOT_APP_DOCUMENT,\n variables: { id: botId },\n fetchPolicy: 'network-only',\n });\n // Apollo v4 resolves (not rejects) with `result.error` set on GraphQL errors.\n // Without this a FORBIDDEN read looked like \"bot not found\" (BOFF-12436).\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw operationError instanceof Error ? operationError : new Error('Failed to load bot');\n }\n setData(result.data?.getBotApp ?? null);\n } catch (queryError) {\n setData(null);\n setError(queryError instanceof Error ? queryError : new Error('Failed to load bot'));\n } finally {\n setLoading(false);\n }\n }, [botId, client]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\nexport function useCreateBot() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<BotMutationState<BotAppRecord>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const createBot = useCallback(\n async (input: CreateBotInput) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<CreateBotAppData>({\n mutation: CREATE_BOT_APP_DOCUMENT,\n variables: { input },\n });\n\n const createdBot = result.data?.createBotApp;\n if (!createdBot) {\n throw new Error('Failed to create bot');\n }\n\n setState({ data: createdBot, loading: false, error: undefined });\n return createdBot;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error ? mutationError : new Error('Failed to create bot');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [createBot, state] as const;\n}\n\nexport function useUpdateBot() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<BotMutationState<BotAppRecord>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const updateBot = useCallback(\n async ({ botId, input }: UpdateBotInput) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<UpdateBotAppData>({\n mutation: UPDATE_BOT_APP_DOCUMENT,\n variables: { id: botId, input: buildMutationInput(input, UPDATE_BOT_APP_FIELDS) },\n });\n\n const updatedBot = result.data?.updateBotApp;\n if (!updatedBot) {\n throw new Error('Failed to update bot');\n }\n\n setState({ data: updatedBot, loading: false, error: undefined });\n return updatedBot;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error ? mutationError : new Error('Failed to update bot');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [updateBot, state] as const;\n}\n\nexport function useDeleteBot() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<BotMutationState<boolean>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const deleteBot = useCallback(\n async (botId: string) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<DeleteBotAppData>({\n mutation: DELETE_BOT_APP_DOCUMENT,\n variables: { id: botId },\n });\n\n const deleted = result.data?.deleteBotApp ?? false;\n setState({ data: deleted, loading: false, error: undefined });\n return deleted;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error ? mutationError : new Error('Failed to delete bot');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [deleteBot, state] as const;\n}\n"],"mappings":";;;;;;;;AAoBA,IAAMA,IAAuB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6B1BC,IAA0B,CAAG;;;;;;;;;;;;;;;;;;;;;GAuB7BC,IAA0B,CAAG;;;;;;;;;;;;;;;;;;;;;;;GAyB7BC,IAA0B,CAAG;;;;GAmC7BC,IAAiB,KACjBC,IAA0B,CAAC,GAwC3BC,IAAwBC,EAA4B;CACxD,UAAU;CACV,SAAS;CACT,gBAAgB;CAChB,aAAa;CACb,iBAAiB;CACjB,MAAM;CACN,UAAU;CACV,MAAM;CACN,iBAAiB;CACjB,MAAM;CACN,QAAQ;CACR,QAAQ;CACR,MAAM;CACN,MAAM;CACN,YAAY;CACZ,gBAAgB;CAChB,YAAY;AACd,CAAC;AAED,SAASC,EAAmB,GAAkC;CAC5D,OAAOC;AACT;AAEA,SAASC,EACP,GACA,GACqC;CACrC,IAAKC,KAAgBC,GAErB,OAAO;EACL;EACA,QAAQA,GAAQ;EAChB,QAAQA,GAAQ,SAAS;EACzB,YAAYA,GAAQ,aAAa;EACjC,UAAUA,GAAQ;CACpB;AACF;AAUA,SAAgBC,EAAQ,GAA2D;CACjF,IAAM,EAAE,mBAAgBC,EAAU,GAE5BC,IAAYC,SACT,EAAE,SAASN,EAAeC,GAAaC,CAAM,EAAE,IACtD,CAACA,GAAQD,CAAW,CACtB;CAEA,OAAOM,EAA+E;EACpF,UAAUC;EACV;EACA,UAAUd;EACV,cAAc,MAASe,G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