@burdenoff/microfe-botmanor 2026.1117.2 → 2026.1118.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/dist/botlit/BotlitRoutes.js +59 -55
  2. package/dist/botlit/BotlitRoutes.js.map +1 -1
  3. package/dist/botlit/components/AgentA2APanel.d.ts +13 -0
  4. package/dist/botlit/components/AgentA2APanel.js +149 -0
  5. package/dist/botlit/components/AgentA2APanel.js.map +1 -0
  6. package/dist/botlit/components/BotAgentsPanel.d.ts +15 -0
  7. package/dist/botlit/components/BotAgentsPanel.js +341 -0
  8. package/dist/botlit/components/BotAgentsPanel.js.map +1 -0
  9. package/dist/botlit/components/BotFormFields.d.ts +4 -0
  10. package/dist/botlit/components/BotFormFields.js +108 -74
  11. package/dist/botlit/components/BotFormFields.js.map +1 -1
  12. package/dist/botlit/components/BotRoutingSummary.d.ts +13 -0
  13. package/dist/botlit/components/BotRoutingSummary.js +126 -0
  14. package/dist/botlit/components/BotRoutingSummary.js.map +1 -0
  15. package/dist/botlit/components/BotVersionHistoryPanel.d.ts +8 -0
  16. package/dist/botlit/components/BotVersionHistoryPanel.js +172 -0
  17. package/dist/botlit/components/BotVersionHistoryPanel.js.map +1 -0
  18. package/dist/botlit/components/CreateFromTemplate.d.ts +12 -0
  19. package/dist/botlit/components/CreateFromTemplate.js +129 -0
  20. package/dist/botlit/components/CreateFromTemplate.js.map +1 -0
  21. package/dist/botlit/components/EntityTags.d.ts +24 -0
  22. package/dist/botlit/components/EntityTags.js +72 -0
  23. package/dist/botlit/components/EntityTags.js.map +1 -0
  24. package/dist/botlit/components/GuardrailPoliciesPanel.d.ts +10 -0
  25. package/dist/botlit/components/GuardrailPoliciesPanel.js +91 -0
  26. package/dist/botlit/components/GuardrailPoliciesPanel.js.map +1 -0
  27. package/dist/botlit/hooks/useA2AConnections.d.ts +21 -0
  28. package/dist/botlit/hooks/useA2AConnections.js +82 -0
  29. package/dist/botlit/hooks/useA2AConnections.js.map +1 -0
  30. package/dist/botlit/hooks/useAgentTestChat.d.ts +29 -0
  31. package/dist/botlit/hooks/useAgentTestChat.js +35 -0
  32. package/dist/botlit/hooks/useAgentTestChat.js.map +1 -0
  33. package/dist/botlit/hooks/useAgents.d.ts +3 -0
  34. package/dist/botlit/hooks/useAgents.js +4 -0
  35. package/dist/botlit/hooks/useAgents.js.map +1 -1
  36. package/dist/botlit/hooks/useBotAgents.d.ts +22 -1
  37. package/dist/botlit/hooks/useBotAgents.js +46 -12
  38. package/dist/botlit/hooks/useBotAgents.js.map +1 -1
  39. package/dist/botlit/hooks/useBotVersions.d.ts +25 -0
  40. package/dist/botlit/hooks/useBotVersions.js +69 -0
  41. package/dist/botlit/hooks/useBotVersions.js.map +1 -0
  42. package/dist/botlit/hooks/useBots.d.ts +3 -0
  43. package/dist/botlit/hooks/useBots.js +4 -0
  44. package/dist/botlit/hooks/useBots.js.map +1 -1
  45. package/dist/botlit/hooks/useLLMProviders.js +40 -32
  46. package/dist/botlit/hooks/useLLMProviders.js.map +1 -1
  47. package/dist/botlit/hooks/useTemplates.d.ts +19 -0
  48. package/dist/botlit/hooks/useTemplates.js +71 -0
  49. package/dist/botlit/hooks/useTemplates.js.map +1 -0
  50. package/dist/botlit/pages/AgentBuilderPage.js +388 -347
  51. package/dist/botlit/pages/AgentBuilderPage.js.map +1 -1
  52. package/dist/botlit/pages/AgentDetailPage.js +237 -247
  53. package/dist/botlit/pages/AgentDetailPage.js.map +1 -1
  54. package/dist/botlit/pages/AgentTestChatPage.d.ts +2 -0
  55. package/dist/botlit/pages/AgentTestChatPage.js +176 -0
  56. package/dist/botlit/pages/AgentTestChatPage.js.map +1 -0
  57. package/dist/botlit/pages/AgentsListPage.js +2 -2
  58. package/dist/botlit/pages/AgentsListPage.js.map +1 -1
  59. package/dist/botlit/pages/BotDetailPage.js +398 -447
  60. package/dist/botlit/pages/BotDetailPage.js.map +1 -1
  61. package/dist/botlit/pages/ChatPage.js +19 -12
  62. package/dist/botlit/pages/ChatPage.js.map +1 -1
  63. package/dist/botlit/pages/SettingsPage.d.ts +7 -0
  64. package/dist/botlit/pages/SettingsPage.js +120 -85
  65. package/dist/botlit/pages/SettingsPage.js.map +1 -1
  66. package/dist/botlit/pages/index.d.ts +1 -0
  67. package/dist/botlit/utils/botRouting.d.ts +42 -0
  68. package/dist/botlit/utils/botRouting.js +52 -0
  69. package/dist/botlit/utils/botRouting.js.map +1 -0
  70. package/dist/generated/wspace-operations.js +41 -43
  71. package/dist/generated/wspace-operations.js.map +1 -1
  72. package/package.json +1 -1
@@ -0,0 +1,69 @@
1
+ import { useWorkspaceMutation as e, useWorkspaceQuery as t } from "./internal/workspaceGateway.js";
2
+ import { useMemo as n } from "react";
3
+ import { gql as r } from "@apollo/client";
4
+ // src/botlit/hooks/useBotVersions.ts
5
+ var i = "\n id\n botAppId\n version\n status\n changelog\n createdAt\n publishedAt\n", a = r`
6
+ query ListBotAppVersions($botAppId: ID!, $pagination: PaginationInput) {
7
+ listBotAppVersions(botAppId: $botAppId, pagination: $pagination) {
8
+ ${i}
9
+ }
10
+ }
11
+ `, o = r`
12
+ mutation PublishBotAppVersion($botAppId: ID!, $versionId: ID!, $changelog: String) {
13
+ publishBotAppVersion(botAppId: $botAppId, versionId: $versionId, changelog: $changelog) {
14
+ ${i}
15
+ }
16
+ }
17
+ `, s = r`
18
+ mutation RollbackBotAppVersion($botAppId: ID!, $targetVersionId: ID!) {
19
+ rollbackBotAppVersion(botAppId: $botAppId, targetVersionId: $targetVersionId) {
20
+ ${i}
21
+ }
22
+ }
23
+ `, c = [];
24
+ function l(e) {
25
+ return [...e].sort((e, t) => e.createdAt && t.createdAt ? t.createdAt.localeCompare(e.createdAt) : 0);
26
+ }
27
+ function u(e) {
28
+ let r = n(() => ({
29
+ botAppId: e,
30
+ pagination: {
31
+ limit: 50,
32
+ offset: 0
33
+ }
34
+ }), [e]);
35
+ return t({
36
+ document: a,
37
+ variables: r,
38
+ select: (e) => l(e?.listBotAppVersions ?? c),
39
+ fallback: c,
40
+ enabled: !!e,
41
+ errorMessage: "Failed to load bot versions"
42
+ });
43
+ }
44
+ function d() {
45
+ return e({
46
+ document: o,
47
+ variables: ({ botId: e, versionId: t, changelog: n }) => ({
48
+ botAppId: e,
49
+ versionId: t,
50
+ changelog: n?.trim() || void 0
51
+ }),
52
+ select: (e) => e?.publishBotAppVersion ?? void 0,
53
+ errorMessage: "Failed to publish the bot version"
54
+ });
55
+ }
56
+ function f() {
57
+ return e({
58
+ document: s,
59
+ variables: ({ botId: e, targetVersionId: t }) => ({
60
+ botAppId: e,
61
+ targetVersionId: t
62
+ }),
63
+ select: (e) => e?.rollbackBotAppVersion ?? void 0,
64
+ errorMessage: "Failed to roll back the bot version"
65
+ });
66
+ }
67
+ export { l as sortVersionsNewestFirst, u as useBotVersions, d as usePublishBotVersion, f as useRollbackBotVersion };
68
+
69
+ //# sourceMappingURL=useBotVersions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBotVersions.js","names":["VERSION_FIELDS","LIST_BOT_APP_VERSIONS_DOCUMENT","PUBLISH_BOT_APP_VERSION_DOCUMENT","ROLLBACK_BOT_APP_VERSION_DOCUMENT","NO_VERSIONS","sortVersionsNewestFirst","versions","a","b","useBotVersions","variables","useMemo","botId","useWorkspaceQuery","data","usePublishBotVersion","useWorkspaceMutation","changelog","useRollbackBotVersion"],"sources":["../../../src/botlit/hooks/useBotVersions.ts"],"sourcesContent":["/**\n * Bot app version history (BOFF-15360)\n * @module botlit/hooks\n *\n * A bot keeps a DRAFT version that every configuration change rewrites, a\n * PUBLISHED version that is live, and HISTORICAL ones. These hooks list the\n * versions of one bot, publish its draft with a changelog and roll back to an\n * earlier version (the server records the rollback as a new published version).\n */\n\nimport { gql } from '@apollo/client';\nimport { useMemo } from 'react';\n\nimport {\n useWorkspaceMutation,\n useWorkspaceQuery,\n type QueryResult,\n} from './internal/workspaceGateway';\n\nexport type BotVersionStatus = 'DRAFT' | 'PUBLISHED' | 'HISTORICAL';\n\nexport interface BotVersionRecord {\n id: string;\n botAppId: string;\n version: string;\n status: BotVersionStatus | string;\n changelog?: string | null;\n createdAt?: string | null;\n publishedAt?: string | null;\n}\n\ninterface ListBotAppVersionsData {\n listBotAppVersions?: BotVersionRecord[] | null;\n}\n\ninterface PublishBotAppVersionData {\n publishBotAppVersion?: BotVersionRecord | null;\n}\n\ninterface RollbackBotAppVersionData {\n rollbackBotAppVersion?: BotVersionRecord | null;\n}\n\nconst VERSION_FIELDS = `\n id\n botAppId\n version\n status\n changelog\n createdAt\n publishedAt\n`;\n\nconst LIST_BOT_APP_VERSIONS_DOCUMENT = gql`\n query ListBotAppVersions($botAppId: ID!, $pagination: PaginationInput) {\n listBotAppVersions(botAppId: $botAppId, pagination: $pagination) {\n ${VERSION_FIELDS}\n }\n }\n`;\n\nconst PUBLISH_BOT_APP_VERSION_DOCUMENT = gql`\n mutation PublishBotAppVersion($botAppId: ID!, $versionId: ID!, $changelog: String) {\n publishBotAppVersion(botAppId: $botAppId, versionId: $versionId, changelog: $changelog) {\n ${VERSION_FIELDS}\n }\n }\n`;\n\nconst ROLLBACK_BOT_APP_VERSION_DOCUMENT = gql`\n mutation RollbackBotAppVersion($botAppId: ID!, $targetVersionId: ID!) {\n rollbackBotAppVersion(botAppId: $botAppId, targetVersionId: $targetVersionId) {\n ${VERSION_FIELDS}\n }\n }\n`;\n\nconst NO_VERSIONS: BotVersionRecord[] = [];\n\n/** Newest first, whatever order the server returned. */\nexport function sortVersionsNewestFirst(versions: readonly BotVersionRecord[]): BotVersionRecord[] {\n return [...versions].sort((a, b) =>\n a.createdAt && b.createdAt ? b.createdAt.localeCompare(a.createdAt) : 0\n );\n}\n\nexport function useBotVersions(botId: string | undefined): QueryResult<BotVersionRecord[]> {\n const variables = useMemo(\n () => ({ botAppId: botId, pagination: { limit: 50, offset: 0 } }),\n [botId]\n );\n return useWorkspaceQuery<ListBotAppVersionsData, BotVersionRecord[]>({\n document: LIST_BOT_APP_VERSIONS_DOCUMENT,\n variables,\n select: (data) => sortVersionsNewestFirst(data?.listBotAppVersions ?? NO_VERSIONS),\n fallback: NO_VERSIONS,\n enabled: Boolean(botId),\n errorMessage: 'Failed to load bot versions',\n });\n}\n\nexport interface PublishBotVersionInput {\n botId: string;\n versionId: string;\n changelog?: string;\n}\n\nexport function usePublishBotVersion() {\n return useWorkspaceMutation<PublishBotAppVersionData, PublishBotVersionInput, BotVersionRecord>({\n document: PUBLISH_BOT_APP_VERSION_DOCUMENT,\n variables: ({ botId, versionId, changelog }) => ({\n botAppId: botId,\n versionId,\n changelog: changelog?.trim() || undefined,\n }),\n select: (data) => data?.publishBotAppVersion ?? undefined,\n errorMessage: 'Failed to publish the bot version',\n });\n}\n\nexport interface RollbackBotVersionInput {\n botId: string;\n targetVersionId: string;\n}\n\nexport function useRollbackBotVersion() {\n return useWorkspaceMutation<RollbackBotAppVersionData, RollbackBotVersionInput, BotVersionRecord>(\n {\n document: ROLLBACK_BOT_APP_VERSION_DOCUMENT,\n variables: ({ botId, targetVersionId }) => ({ botAppId: botId, targetVersionId }),\n select: (data) => data?.rollbackBotAppVersion ?? undefined,\n errorMessage: 'Failed to roll back the bot version',\n }\n );\n}\n"],"mappings":";;;;AA2CA,IAAMA,IAAiB,sFAUjBC,IAAiC,CAAG;;;QAGlCD,EAAe;;;GAKjBE,IAAmC,CAAG;;;QAGpCF,EAAe;;;GAKjBG,IAAoC,CAAG;;;QAGrCH,EAAe;;;GAKjBI,IAAkC,CAAC;AAGzC,SAAgBC,EAAwB,GAA2D;CACjG,OAAO,CAAC,GAAGC,CAAQ,CAAC,CAAC,MAAM,GAAG,MAC5BC,EAAE,aAAaC,EAAE,YAAYA,EAAE,UAAU,cAAcD,EAAE,SAAS,IAAI,CACxE;AACF;AAEA,SAAgBE,EAAe,GAA4D;CACzF,IAAMC,IAAYC,SACT;EAAE,UAAUC;EAAO,YAAY;GAAE,OAAO;GAAI,QAAQ;EAAE;CAAE,IAC/D,CAACA,CAAK,CACR;CACA,OAAOC,EAA8D;EACnE,UAAUZ;EACV;EACA,SAAS,MAASI,EAAwBS,GAAM,sBAAsBV,CAAW;EACjF,UAAUA;EACV,SAAS,EAAQQ;EACjB,cAAc;CAChB,CAAC;AACH;AAQA,SAAgBG,IAAuB;CACrC,OAAOC,EAAyF;EAC9F,UAAUd;EACV,YAAY,EAAE,UAAO,cAAW,oBAAiB;GAC/C,UAAUU;GACV;GACA,WAAWK,GAAW,KAAK,KAAK,KAAA;EAClC;EACA,SAAS,MAASH,GAAM,wBAAwB,KAAA;EAChD,cAAc;CAChB,CAAC;AACH;AAOA,SAAgBI,IAAwB;CACtC,OAAOF,EACL;EACE,UAAUb;EACV,YAAY,EAAE,UAAO,0BAAuB;GAAE,UAAUS;GAAO;EAAgB;EAC/E,SAAS,MAASE,GAAM,yBAAyB,KAAA;EACjD,cAAc;CAChB,CACF;AACF"}
@@ -20,6 +20,8 @@ export interface BotAppRecord {
20
20
  executionCount?: number | null;
21
21
  lastExecutedAt?: string | null;
22
22
  tagIds?: string[] | null;
23
+ /** Entity-owned universal tag records (JSON). */
24
+ tags?: unknown;
23
25
  createdAt?: string | null;
24
26
  updatedAt?: string | null;
25
27
  createdById?: string | null;
@@ -37,6 +39,7 @@ interface CreateBotInput {
37
39
  slug?: string;
38
40
  type: string;
39
41
  routingStrategy?: string;
42
+ visibility?: string;
40
43
  description?: string;
41
44
  icon?: string;
42
45
  }
@@ -24,6 +24,7 @@ var d = l`
24
24
  executionCount
25
25
  lastExecutedAt
26
26
  tagIds
27
+ tags
27
28
  createdAt
28
29
  updatedAt
29
30
  createdById
@@ -50,6 +51,7 @@ var d = l`
50
51
  executionCount
51
52
  lastExecutedAt
52
53
  tagIds
54
+ tags
53
55
  createdAt
54
56
  updatedAt
55
57
  createdById
@@ -72,6 +74,7 @@ var d = l`
72
74
  defaultAgentId
73
75
  workflowId
74
76
  tagIds
77
+ tags
75
78
  createdAt
76
79
  updatedAt
77
80
  workspaceId
@@ -94,6 +97,7 @@ var d = l`
94
97
  fallbackMessage
95
98
  workflowId
96
99
  tagIds
100
+ tags
97
101
  updatedAt
98
102
  updatedById
99
103
  workspaceId
@@ -1 +1 @@
1
- {"version":3,"file":"useBots.js","names":["LIST_BOT_APPS_DOCUMENT","GET_BOT_APP_DOCUMENT","CREATE_BOT_APP_DOCUMENT","UPDATE_BOT_APP_DOCUMENT","DELETE_BOT_APP_DOCUMENT","LIST_PAGE_SIZE","NO_BOTS","UPDATE_BOT_APP_FIELDS","fieldsOf","getWorkspaceClient","client","buildBotFilter","workspaceId","filter","useBots","useBotlit","variables","useMemo","useWorkspacePaginatedQuery","data","rows","GET_BOT_APP_COUNTS_DOCUMENT","useBotAppCounts","useWorkspaceQuery","enabled","useBot","useGatewayClient","setData","useState","loading","setLoading","botId","error","setError","refetch","useCallback","result","operationError","queryError","useEffect","useCreateBot","state","setState","createdBot","mutationError","useUpdateBot","updatedBot","buildMutationInput","input","useDeleteBot","deleted"],"sources":["../../../src/botlit/hooks/useBots.ts"],"sourcesContent":["import { gql, type ApolloClient } from '@apollo/client';\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport { useGatewayClient } from '@burdenoff/fe-libs/shared/graphql';\n\nimport type { UpdateBotAppInput } from '../../generated/wspace-types';\nimport { useBotlit } from '../providers/BotlitProvider';\nimport type { BaseFilter } from '../types';\nimport { buildMutationInput, fieldsOf, type GraphQLInput } from './internal/mutationInput';\nimport {\n useWorkspacePaginatedQuery,\n useWorkspaceQuery,\n type PaginatedQueryResult,\n type QueryResult,\n} from './internal/workspaceGateway';\n\nconst LIST_BOT_APPS_DOCUMENT = gql`\n query ListBotApps($filters: BotAppFilterInput, $pagination: PaginationInput) {\n listBotApps(filters: $filters, pagination: $pagination) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n welcomeMessage\n fallbackMessage\n workflowId\n executionCount\n lastExecutedAt\n tagIds\n createdAt\n updatedAt\n createdById\n updatedById\n workspaceId\n }\n }\n`;\n\nconst GET_BOT_APP_DOCUMENT = gql`\n query GetBotApp($id: ID!) {\n getBotApp(id: $id) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n welcomeMessage\n fallbackMessage\n workflowId\n executionCount\n lastExecutedAt\n tagIds\n createdAt\n updatedAt\n createdById\n updatedById\n workspaceId\n }\n }\n`;\n\nconst CREATE_BOT_APP_DOCUMENT = gql`\n mutation CreateBotApp($input: CreateBotAppInput!) {\n createBotApp(input: $input) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n workflowId\n tagIds\n createdAt\n updatedAt\n workspaceId\n }\n }\n`;\n\nconst UPDATE_BOT_APP_DOCUMENT = gql`\n mutation UpdateBotApp($id: ID!, $input: UpdateBotAppInput!) {\n updateBotApp(id: $id, input: $input) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n welcomeMessage\n fallbackMessage\n workflowId\n tagIds\n updatedAt\n updatedById\n workspaceId\n }\n }\n`;\n\nconst DELETE_BOT_APP_DOCUMENT = gql`\n mutation DeleteBotApp($id: ID!) {\n deleteBotApp(id: $id)\n }\n`;\n\ntype WorkspaceClient = ApolloClient;\n\nexport interface BotAppRecord {\n id: string;\n name: string;\n slug: string;\n description?: string | null;\n icon?: string | null;\n type: string;\n status: string;\n visibility?: string | null;\n routingStrategy?: string | null;\n defaultAgentId?: string | null;\n welcomeMessage?: string | null;\n fallbackMessage?: string | null;\n /** Bound FluidGrids workflow definition id — the bot's designed behaviour. */\n workflowId?: string | null;\n executionCount?: number | null;\n lastExecutedAt?: string | null;\n tagIds?: string[] | null;\n createdAt?: string | null;\n updatedAt?: string | null;\n createdById?: string | null;\n updatedById?: string | null;\n workspaceId?: string | null;\n}\n\ninterface ListBotAppsData {\n listBotApps: BotAppRecord[];\n}\n\nconst LIST_PAGE_SIZE = 100;\nconst NO_BOTS: BotAppRecord[] = [];\n\ninterface GetBotAppData {\n getBotApp: BotAppRecord | null;\n}\n\ninterface CreateBotAppData {\n createBotApp: BotAppRecord;\n}\n\ninterface UpdateBotAppData {\n updateBotApp: BotAppRecord;\n}\n\ninterface DeleteBotAppData {\n deleteBotApp: boolean;\n}\n\ninterface BotMutationState<T> {\n data: T | undefined;\n loading: boolean;\n error: Error | undefined;\n}\n\ninterface CreateBotInput {\n workspaceId: string;\n name: string;\n slug?: string;\n type: string;\n routingStrategy?: string;\n description?: string;\n icon?: string;\n}\n\ninterface UpdateBotInput {\n botId: string;\n input: GraphQLInput<UpdateBotAppInput>;\n}\n\nconst UPDATE_BOT_APP_FIELDS = fieldsOf<UpdateBotAppInput>({\n bucketId: true,\n context: true,\n defaultAgentId: true,\n description: true,\n fallbackMessage: true,\n icon: true,\n metadata: true,\n name: true,\n routingStrategy: true,\n slug: true,\n status: true,\n tagIds: true,\n tags: true,\n type: true,\n visibility: true,\n welcomeMessage: true,\n workflowId: true,\n});\n\nfunction getWorkspaceClient(client: unknown): WorkspaceClient {\n return client as WorkspaceClient;\n}\n\nfunction buildBotFilter(\n workspaceId: string | undefined,\n filter?: BaseFilter\n): Record<string, unknown> | undefined {\n if (!workspaceId && !filter) return undefined;\n\n return {\n workspaceId,\n search: filter?.search,\n status: filter?.status?.[0],\n visibility: filter?.visibility?.[0],\n bucketId: filter?.bucketId,\n };\n}\n\nexport const botKeys = {\n all: ['bots'] as const,\n lists: () => [...botKeys.all, 'list'] as const,\n list: (filter?: BaseFilter) => [...botKeys.lists(), filter] as const,\n details: () => [...botKeys.all, 'detail'] as const,\n detail: (id: string) => [...botKeys.details(), id] as const,\n};\n\nexport function useBots(filter?: BaseFilter): PaginatedQueryResult<BotAppRecord[]> {\n const { workspaceId } = useBotlit();\n\n const variables = useMemo(\n () => ({ filters: buildBotFilter(workspaceId, filter) }),\n [filter, workspaceId]\n );\n\n return useWorkspacePaginatedQuery<ListBotAppsData, BotAppRecord, BotAppRecord[]>({\n document: LIST_BOT_APPS_DOCUMENT,\n variables,\n pageSize: LIST_PAGE_SIZE,\n extractRows: (data) => data?.listBotApps ?? [],\n select: (rows) => rows,\n fallback: NO_BOTS,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load bots',\n });\n}\n\n/**\n * Exact bot counts by status for the workspace (BOFF-12426). Unlike `useBots`\n * this is not capped at one page, so it is the source for dashboard totals.\n * `total` counts every status; the dashboard shows `total - archived`.\n */\nexport interface BotAppCounts {\n total: number;\n draft: number;\n active: number;\n paused: number;\n archived: number;\n}\n\ninterface BotAppCountsData {\n getBotAppCounts?: BotAppCounts | null;\n}\n\nconst GET_BOT_APP_COUNTS_DOCUMENT = gql`\n query GetBotAppCounts {\n getBotAppCounts {\n total\n draft\n active\n paused\n archived\n }\n }\n`;\n\nexport function useBotAppCounts(enabled = true): QueryResult<BotAppCounts | null> {\n const { workspaceId } = useBotlit();\n const variables = useMemo(() => ({}), []);\n\n return useWorkspaceQuery<BotAppCountsData, BotAppCounts | null>({\n document: GET_BOT_APP_COUNTS_DOCUMENT,\n variables,\n select: (data) => data?.getBotAppCounts ?? null,\n fallback: null,\n enabled: enabled && Boolean(workspaceId),\n errorMessage: 'Failed to load bot counts',\n });\n}\n\nexport function useBot(botId: string | undefined) {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [data, setData] = useState<BotAppRecord | null>(null);\n // Loading from the first render when there is a bot to read, so a page that\n // depends on the bot never acts on \"no bot yet\" for the frame before the read.\n const [loading, setLoading] = useState(Boolean(botId));\n const [error, setError] = useState<Error | undefined>();\n\n const refetch = useCallback(async () => {\n if (!botId) {\n setData(null);\n setLoading(false);\n return;\n }\n\n setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<GetBotAppData>({\n query: GET_BOT_APP_DOCUMENT,\n variables: { id: botId },\n fetchPolicy: 'network-only',\n });\n // Apollo v4 resolves (not rejects) with `result.error` set on GraphQL errors.\n // Without this a FORBIDDEN read looked like \"bot not found\" (BOFF-12436).\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw operationError instanceof Error ? operationError : new Error('Failed to load bot');\n }\n setData(result.data?.getBotApp ?? null);\n } catch (queryError) {\n setData(null);\n setError(queryError instanceof Error ? queryError : new Error('Failed to load bot'));\n } finally {\n setLoading(false);\n }\n }, [botId, client]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\nexport function useCreateBot() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<BotMutationState<BotAppRecord>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const createBot = useCallback(\n async (input: CreateBotInput) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<CreateBotAppData>({\n mutation: CREATE_BOT_APP_DOCUMENT,\n variables: { input },\n });\n\n const createdBot = result.data?.createBotApp;\n if (!createdBot) {\n throw new Error('Failed to create bot');\n }\n\n setState({ data: createdBot, loading: false, error: undefined });\n return createdBot;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error ? mutationError : new Error('Failed to create bot');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [createBot, state] as const;\n}\n\nexport function useUpdateBot() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<BotMutationState<BotAppRecord>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const updateBot = useCallback(\n async ({ botId, input }: UpdateBotInput) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<UpdateBotAppData>({\n mutation: UPDATE_BOT_APP_DOCUMENT,\n variables: { id: botId, input: buildMutationInput(input, UPDATE_BOT_APP_FIELDS) },\n });\n\n const updatedBot = result.data?.updateBotApp;\n if (!updatedBot) {\n throw new Error('Failed to update bot');\n }\n\n setState({ data: updatedBot, loading: false, error: undefined });\n return updatedBot;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error ? mutationError : new Error('Failed to update bot');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [updateBot, state] as const;\n}\n\nexport function useDeleteBot() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<BotMutationState<boolean>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const deleteBot = useCallback(\n async (botId: string) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<DeleteBotAppData>({\n mutation: DELETE_BOT_APP_DOCUMENT,\n variables: { id: botId },\n });\n\n const deleted = result.data?.deleteBotApp ?? false;\n setState({ data: deleted, loading: false, error: undefined });\n return deleted;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error ? mutationError : new Error('Failed to delete bot');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [deleteBot, state] as const;\n}\n"],"mappings":";;;;;;;AAeA,IAAMA,IAAyB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;GA4B5BC,IAAuB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;GA4B1BC,IAA0B,CAAG;;;;;;;;;;;;;;;;;;;;GAsB7BC,IAA0B,CAAG;;;;;;;;;;;;;;;;;;;;;;GAwB7BC,IAA0B,CAAG;;;;GAqC7BC,IAAiB,KACjBC,IAA0B,CAAC,GAuC3BC,IAAwBC,EAA4B;CACxD,UAAU;CACV,SAAS;CACT,gBAAgB;CAChB,aAAa;CACb,iBAAiB;CACjB,MAAM;CACN,UAAU;CACV,MAAM;CACN,iBAAiB;CACjB,MAAM;CACN,QAAQ;CACR,QAAQ;CACR,MAAM;CACN,MAAM;CACN,YAAY;CACZ,gBAAgB;CAChB,YAAY;AACd,CAAC;AAED,SAASC,EAAmB,GAAkC;CAC5D,OAAOC;AACT;AAEA,SAASC,EACP,GACA,GACqC;CACrC,IAAKC,KAAgBC,GAErB,OAAO;EACL;EACA,QAAQA,GAAQ;EAChB,QAAQA,GAAQ,SAAS;EACzB,YAAYA,GAAQ,aAAa;EACjC,UAAUA,GAAQ;CACpB;AACF;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CACF,GACA,CAACtB,CAAM,CAGD,GAAW+B,CAAK;AAC1B"}
1
+ {"version":3,"file":"useBots.js","names":["LIST_BOT_APPS_DOCUMENT","GET_BOT_APP_DOCUMENT","CREATE_BOT_APP_DOCUMENT","UPDATE_BOT_APP_DOCUMENT","DELETE_BOT_APP_DOCUMENT","LIST_PAGE_SIZE","NO_BOTS","UPDATE_BOT_APP_FIELDS","fieldsOf","getWorkspaceClient","client","buildBotFilter","workspaceId","filter","useBots","useBotlit","variables","useMemo","useWorkspacePaginatedQuery","data","rows","GET_BOT_APP_COUNTS_DOCUMENT","useBotAppCounts","useWorkspaceQuery","enabled","useBot","useGatewayClient","setData","useState","loading","setLoading","botId","error","setError","refetch","useCallback","result","operationError","queryError","useEffect","useCreateBot","state","setState","createdBot","mutationError","useUpdateBot","updatedBot","buildMutationInput","input","useDeleteBot","deleted"],"sources":["../../../src/botlit/hooks/useBots.ts"],"sourcesContent":["import { gql, type ApolloClient } from '@apollo/client';\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport { useGatewayClient } from '@burdenoff/fe-libs/shared/graphql';\n\nimport type { UpdateBotAppInput } from '../../generated/wspace-types';\nimport { useBotlit } from '../providers/BotlitProvider';\nimport type { BaseFilter } from '../types';\nimport { buildMutationInput, fieldsOf, type GraphQLInput } from './internal/mutationInput';\nimport {\n useWorkspacePaginatedQuery,\n useWorkspaceQuery,\n type PaginatedQueryResult,\n type QueryResult,\n} from './internal/workspaceGateway';\n\nconst LIST_BOT_APPS_DOCUMENT = gql`\n query ListBotApps($filters: BotAppFilterInput, $pagination: PaginationInput) {\n listBotApps(filters: $filters, pagination: $pagination) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n welcomeMessage\n fallbackMessage\n workflowId\n executionCount\n lastExecutedAt\n tagIds\n tags\n createdAt\n updatedAt\n createdById\n updatedById\n workspaceId\n }\n }\n`;\n\nconst GET_BOT_APP_DOCUMENT = gql`\n query GetBotApp($id: ID!) {\n getBotApp(id: $id) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n welcomeMessage\n fallbackMessage\n workflowId\n executionCount\n lastExecutedAt\n tagIds\n tags\n createdAt\n updatedAt\n createdById\n updatedById\n workspaceId\n }\n }\n`;\n\nconst CREATE_BOT_APP_DOCUMENT = gql`\n mutation CreateBotApp($input: CreateBotAppInput!) {\n createBotApp(input: $input) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n workflowId\n tagIds\n tags\n createdAt\n updatedAt\n workspaceId\n }\n }\n`;\n\nconst UPDATE_BOT_APP_DOCUMENT = gql`\n mutation UpdateBotApp($id: ID!, $input: UpdateBotAppInput!) {\n updateBotApp(id: $id, input: $input) {\n id\n name\n slug\n description\n icon\n type\n status\n visibility\n routingStrategy\n defaultAgentId\n welcomeMessage\n fallbackMessage\n workflowId\n tagIds\n tags\n updatedAt\n updatedById\n workspaceId\n }\n }\n`;\n\nconst DELETE_BOT_APP_DOCUMENT = gql`\n mutation DeleteBotApp($id: ID!) {\n deleteBotApp(id: $id)\n }\n`;\n\ntype WorkspaceClient = ApolloClient;\n\nexport interface BotAppRecord {\n id: string;\n name: string;\n slug: string;\n description?: string | null;\n icon?: string | null;\n type: string;\n status: string;\n visibility?: string | null;\n routingStrategy?: string | null;\n defaultAgentId?: string | null;\n welcomeMessage?: string | null;\n fallbackMessage?: string | null;\n /** Bound FluidGrids workflow definition id — the bot's designed behaviour. */\n workflowId?: string | null;\n executionCount?: number | null;\n lastExecutedAt?: string | null;\n tagIds?: string[] | null;\n /** Entity-owned universal tag records (JSON). */\n tags?: unknown;\n createdAt?: string | null;\n updatedAt?: string | null;\n createdById?: string | null;\n updatedById?: string | null;\n workspaceId?: string | null;\n}\n\ninterface ListBotAppsData {\n listBotApps: BotAppRecord[];\n}\n\nconst LIST_PAGE_SIZE = 100;\nconst NO_BOTS: BotAppRecord[] = [];\n\ninterface GetBotAppData {\n getBotApp: BotAppRecord | null;\n}\n\ninterface CreateBotAppData {\n createBotApp: BotAppRecord;\n}\n\ninterface UpdateBotAppData {\n updateBotApp: BotAppRecord;\n}\n\ninterface DeleteBotAppData {\n deleteBotApp: boolean;\n}\n\ninterface BotMutationState<T> {\n data: T | undefined;\n loading: boolean;\n error: Error | undefined;\n}\n\ninterface CreateBotInput {\n workspaceId: string;\n name: string;\n slug?: string;\n type: string;\n routingStrategy?: string;\n visibility?: string;\n description?: string;\n icon?: string;\n}\n\ninterface UpdateBotInput {\n botId: string;\n input: GraphQLInput<UpdateBotAppInput>;\n}\n\nconst UPDATE_BOT_APP_FIELDS = fieldsOf<UpdateBotAppInput>({\n bucketId: true,\n context: true,\n defaultAgentId: true,\n description: true,\n fallbackMessage: true,\n icon: true,\n metadata: true,\n name: true,\n routingStrategy: true,\n slug: true,\n status: true,\n tagIds: true,\n tags: true,\n type: true,\n visibility: true,\n welcomeMessage: true,\n workflowId: true,\n});\n\nfunction getWorkspaceClient(client: unknown): WorkspaceClient {\n return client as WorkspaceClient;\n}\n\nfunction buildBotFilter(\n workspaceId: string | undefined,\n filter?: BaseFilter\n): Record<string, unknown> | undefined {\n if (!workspaceId && !filter) return undefined;\n\n return {\n workspaceId,\n search: filter?.search,\n status: filter?.status?.[0],\n visibility: filter?.visibility?.[0],\n bucketId: filter?.bucketId,\n };\n}\n\nexport const botKeys = {\n all: ['bots'] as const,\n lists: () => [...botKeys.all, 'list'] as const,\n list: (filter?: BaseFilter) => [...botKeys.lists(), filter] as const,\n details: () => [...botKeys.all, 'detail'] as const,\n detail: (id: string) => [...botKeys.details(), id] as const,\n};\n\nexport function useBots(filter?: BaseFilter): PaginatedQueryResult<BotAppRecord[]> {\n const { workspaceId } = useBotlit();\n\n const variables = useMemo(\n () => ({ filters: buildBotFilter(workspaceId, filter) }),\n [filter, workspaceId]\n );\n\n return useWorkspacePaginatedQuery<ListBotAppsData, BotAppRecord, BotAppRecord[]>({\n document: LIST_BOT_APPS_DOCUMENT,\n variables,\n pageSize: LIST_PAGE_SIZE,\n extractRows: (data) => data?.listBotApps ?? [],\n select: (rows) => rows,\n fallback: NO_BOTS,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load bots',\n });\n}\n\n/**\n * Exact bot counts by status for the workspace (BOFF-12426). Unlike `useBots`\n * this is not capped at one page, so it is the source for dashboard totals.\n * `total` counts every status; the dashboard shows `total - archived`.\n */\nexport interface BotAppCounts {\n total: number;\n draft: number;\n active: number;\n paused: number;\n archived: number;\n}\n\ninterface BotAppCountsData {\n getBotAppCounts?: BotAppCounts | null;\n}\n\nconst GET_BOT_APP_COUNTS_DOCUMENT = gql`\n query GetBotAppCounts {\n getBotAppCounts {\n total\n draft\n active\n paused\n archived\n }\n }\n`;\n\nexport function useBotAppCounts(enabled = true): QueryResult<BotAppCounts | null> {\n const { workspaceId } = useBotlit();\n const variables = useMemo(() => ({}), []);\n\n return useWorkspaceQuery<BotAppCountsData, BotAppCounts | null>({\n document: GET_BOT_APP_COUNTS_DOCUMENT,\n variables,\n select: (data) => data?.getBotAppCounts ?? null,\n fallback: null,\n enabled: enabled && Boolean(workspaceId),\n errorMessage: 'Failed to load bot counts',\n });\n}\n\nexport function useBot(botId: string | undefined) {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [data, setData] = useState<BotAppRecord | null>(null);\n // Loading from the first render when there is a bot to read, so a page that\n // depends on the bot never acts on \"no bot yet\" for the frame before the read.\n const [loading, setLoading] = useState(Boolean(botId));\n const [error, setError] = useState<Error | undefined>();\n\n const refetch = useCallback(async () => {\n if (!botId) {\n setData(null);\n setLoading(false);\n return;\n }\n\n setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<GetBotAppData>({\n query: GET_BOT_APP_DOCUMENT,\n variables: { id: botId },\n fetchPolicy: 'network-only',\n });\n // Apollo v4 resolves (not rejects) with `result.error` set on GraphQL errors.\n // Without this a FORBIDDEN read looked like \"bot not found\" (BOFF-12436).\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw operationError instanceof Error ? operationError : new Error('Failed to load bot');\n }\n setData(result.data?.getBotApp ?? null);\n } catch (queryError) {\n setData(null);\n setError(queryError instanceof Error ? queryError : new Error('Failed to load bot'));\n } finally {\n setLoading(false);\n }\n }, [botId, client]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\nexport function useCreateBot() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<BotMutationState<BotAppRecord>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const createBot = useCallback(\n async (input: CreateBotInput) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<CreateBotAppData>({\n mutation: CREATE_BOT_APP_DOCUMENT,\n variables: { input },\n });\n\n const createdBot = result.data?.createBotApp;\n if (!createdBot) {\n throw new Error('Failed to create bot');\n }\n\n setState({ data: createdBot, loading: false, error: undefined });\n return createdBot;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error ? mutationError : new Error('Failed to create bot');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [createBot, state] as const;\n}\n\nexport function useUpdateBot() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<BotMutationState<BotAppRecord>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const updateBot = useCallback(\n async ({ botId, input }: UpdateBotInput) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<UpdateBotAppData>({\n mutation: UPDATE_BOT_APP_DOCUMENT,\n variables: { id: botId, input: buildMutationInput(input, UPDATE_BOT_APP_FIELDS) },\n });\n\n const updatedBot = result.data?.updateBotApp;\n if (!updatedBot) {\n throw new Error('Failed to update bot');\n }\n\n setState({ data: updatedBot, loading: false, error: undefined });\n return updatedBot;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error ? mutationError : new Error('Failed to update bot');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [updateBot, state] as const;\n}\n\nexport function useDeleteBot() {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [state, setState] = useState<BotMutationState<boolean>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const deleteBot = useCallback(\n async (botId: string) => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<DeleteBotAppData>({\n mutation: DELETE_BOT_APP_DOCUMENT,\n variables: { id: botId },\n });\n\n const deleted = result.data?.deleteBotApp ?? false;\n setState({ data: deleted, loading: false, error: undefined });\n return deleted;\n } catch (mutationError) {\n const error =\n mutationError instanceof Error ? mutationError : new Error('Failed to delete bot');\n setState({ data: undefined, loading: false, error });\n throw error;\n }\n },\n [client]\n );\n\n return [deleteBot, state] as const;\n}\n"],"mappings":";;;;;;;AAeA,IAAMA,IAAyB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6B5BC,IAAuB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6B1BC,IAA0B,CAAG;;;;;;;;;;;;;;;;;;;;;GAuB7BC,IAA0B,CAAG;;;;;;;;;;;;;;;;;;;;;;;GAyB7BC,IAA0B,CAAG;;;;GAuC7BC,IAAiB,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;A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ACF,GACA,CAACtB,CAAM,CAGD,GAAW+B,CAAK;AAC1B"}
@@ -1,11 +1,11 @@
1
1
  import { useBotlit as e } from "../providers/BotlitProvider.js";
2
- import { CreateBotmanorLlmModelDocument as t, CreateBotmanorLlmProviderDocument as n, ListBotmanorLlmModelsDocument as r, ListBotmanorLlmProvidersDocument as i, UpdateBotmanorLlmProviderDocument as a } from "../../generated/wspace-operations.js";
3
- import { buildMutationInput as o, fieldsOf as s } from "./internal/mutationInput.js";
4
- import { useWorkspaceClient as c, useWorkspaceId as l, useWorkspaceMutation as u } from "./internal/workspaceGateway.js";
5
- import { useCallback as d } from "react";
6
- import { useQuery as f } from "@tanstack/react-query";
2
+ import { CreateBotmanorLlmModelDocument as t, CreateBotmanorLlmProviderDocument as n, ListBotmanorLlmModelsDocument as r, ListBotmanorLlmProvidersDocument as i, TestLlmConnectionDocument as a, UpdateBotmanorLlmProviderDocument as o } from "../../generated/wspace-operations.js";
3
+ import { buildMutationInput as s, fieldsOf as c } from "./internal/mutationInput.js";
4
+ import { useWorkspaceClient as l, useWorkspaceId as u, useWorkspaceMutation as d } from "./internal/workspaceGateway.js";
5
+ import { useCallback as f } from "react";
6
+ import { useQuery as p } from "@tanstack/react-query";
7
7
  // src/botlit/hooks/useLLMProviders.ts
8
- var p = 50, m = [], h = [], g = s({
8
+ var m = 50, h = [], g = [], _ = c({
9
9
  apiEndpoint: !0,
10
10
  connectionId: !0,
11
11
  credentials: !0,
@@ -13,7 +13,7 @@ var p = 50, m = [], h = [], g = s({
13
13
  name: !0,
14
14
  type: !0,
15
15
  workspaceId: !0
16
- }), _ = s({
16
+ }), v = c({
17
17
  apiEndpoint: !0,
18
18
  connectionId: !0,
19
19
  credentials: !0,
@@ -21,12 +21,12 @@ var p = 50, m = [], h = [], g = s({
21
21
  metadata: !0,
22
22
  name: !0
23
23
  });
24
- function v(t, n, r, i, a) {
25
- let o = c(), { workspaceId: s, currentUser: l } = e(), u = f({
24
+ function y(t, n, r, i, a) {
25
+ let o = l(), { workspaceId: s, currentUser: c } = e(), u = p({
26
26
  queryKey: [
27
27
  "botmanor-llm-catalog",
28
28
  s,
29
- l?.id,
29
+ c?.id,
30
30
  n,
31
31
  a
32
32
  ],
@@ -34,22 +34,22 @@ function v(t, n, r, i, a) {
34
34
  retry: !1,
35
35
  queryFn: async () => {
36
36
  let e = [];
37
- for (let n = 0; n < 1e4; n += p) {
37
+ for (let n = 0; n < 1e4; n += m) {
38
38
  let i = await o.query({
39
39
  query: t,
40
40
  fetchPolicy: "network-only",
41
41
  variables: {
42
42
  filters: a ? { providerId: a } : void 0,
43
43
  pagination: {
44
- limit: p,
44
+ limit: m,
45
45
  offset: n
46
46
  }
47
47
  }
48
48
  });
49
49
  if (!i.data) throw Error("Model catalog unavailable");
50
50
  let s = r(i.data);
51
- if (!Array.isArray(s) || s.length > p) throw Error("Model catalog unavailable");
52
- if (e.push(...s), s.length < p) return e;
51
+ if (!Array.isArray(s) || s.length > m) throw Error("Model catalog unavailable");
52
+ if (e.push(...s), s.length < m) return e;
53
53
  }
54
54
  throw Error("Model catalog exceeds the supported limit");
55
55
  }
@@ -63,43 +63,51 @@ function v(t, n, r, i, a) {
63
63
  }
64
64
  };
65
65
  }
66
- function y() {
67
- return v(i, "providers", (e) => e?.listBotmanorLLMProviders ?? m, m);
66
+ function b() {
67
+ return y(i, "providers", (e) => e?.listBotmanorLLMProviders ?? h, h);
68
68
  }
69
- function b(e) {
70
- return v(r, "models", (e) => e?.listBotmanorLLMModels ?? h, h, e?.providerId);
69
+ function x(e) {
70
+ return y(r, "models", (e) => e?.listBotmanorLLMModels ?? g, g, e?.providerId);
71
71
  }
72
- function x() {
73
- let e = l(), [t, r] = u({
72
+ function S() {
73
+ let e = u(), [t, r] = d({
74
74
  document: n,
75
- variables: (t) => ({ input: o({
75
+ variables: (t) => ({ input: s({
76
76
  ...t,
77
77
  workspaceId: e
78
- }, g) }),
78
+ }, _) }),
79
79
  select: (e) => e?.createBotmanorLLMProvider,
80
80
  errorMessage: "Failed to create the LLM provider"
81
- }), [i, s] = u({
82
- document: a,
81
+ }), [i, a] = d({
82
+ document: o,
83
83
  variables: ({ providerId: e, input: t }) => ({
84
84
  id: e,
85
- input: o(t, _)
85
+ input: s(t, v)
86
86
  }),
87
87
  select: (e) => e?.updateBotmanorLLMProvider,
88
88
  errorMessage: "Failed to update the LLM provider"
89
89
  });
90
90
  return {
91
- configureProvider: d(async (e, n) => n ? i({
91
+ configureProvider: f(async (e, n) => n ? i({
92
92
  providerId: n,
93
93
  input: e
94
94
  }) : t(e), [t, i]),
95
- isConfiguring: r.loading || s.loading,
96
- error: r.error ?? s.error
95
+ isConfiguring: r.loading || a.loading,
96
+ error: r.error ?? a.error
97
97
  };
98
98
  }
99
- function S() {
100
- let [e, n] = u({
99
+ function C() {
100
+ return d({
101
+ document: a,
102
+ variables: (e) => ({ id: e }),
103
+ select: (e) => e?.testLlmConnection,
104
+ errorMessage: "Failed to test the LLM connection"
105
+ });
106
+ }
107
+ function w() {
108
+ let [e, n] = d({
101
109
  document: t,
102
- variables: (e) => ({ input: o(e, s({
110
+ variables: (e) => ({ input: s(e, c({
103
111
  providerId: !0,
104
112
  name: !0,
105
113
  modelId: !0,
@@ -121,6 +129,6 @@ function S() {
121
129
  error: n.error
122
130
  };
123
131
  }
124
- export { x as useConfigureLLMProvider, S as useCreateLLMModel, b as useLLMModels, y as useLLMProviders };
132
+ export { S as useConfigureLLMProvider, w as useCreateLLMModel, x as useLLMModels, b as useLLMProviders, C as useTestLLMConnection };
125
133
 
126
134
  //# sourceMappingURL=useLLMProviders.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useLLMProviders.js","names":["LIST_LIMIT","NO_PROVIDERS","NO_MODELS","CREATE_PROVIDER_FIELDS","fieldsOf","UPDATE_PROVIDER_FIELDS","useLLMList","client","useWorkspaceClient","useBotlit","query","useQuery","workspaceId","currentUser","kind","providerId","records","offset","result","document","page","select","fallback","useLLMProviders","ListBotmanorLlmProvidersDocument","data","useLLMModels","ListBotmanorLlmModelsDocument","filters","useConfigureLLMProvider","useWorkspaceId","create","createState","useWorkspaceMutation","CreateBotmanorLlmProviderDocument","buildMutationInput","input","update","updateState","UpdateBotmanorLlmProviderDocument","useCallback","existingId","useCreateLLMModel","createModel","state","CreateBotmanorLlmModelDocument"],"sources":["../../../src/botlit/hooks/useLLMProviders.ts"],"sourcesContent":["/**\n * LLM Providers Hooks\n * @module botlit/hooks\n *\n * These go through the shell's workspace gateway client like every other BotManor\n * hook. They deliberately do NOT use the generated `useQuery`/`useMutation`\n * wrappers: `BotmanorRoot` only mounts an `<ApolloProvider>` in standalone mode,\n * so an Apollo React hook throws \"Could not find client in the context\" the\n * moment the MFE is mounted by an app shell — which is every production route.\n */\n\nimport { useCallback, useMemo } from 'react';\nimport type { DocumentNode } from 'graphql';\nimport { useQuery } from '@tanstack/react-query';\nimport { useBotlit } from '../providers/BotlitProvider';\nimport {\n CreateBotmanorLlmProviderDocument,\n CreateBotmanorLlmModelDocument,\n DeleteLlmProviderDocument,\n GetBotmanorLlmProviderDocument,\n ListBotmanorLlmModelsDocument,\n ListBotmanorLlmProvidersDocument,\n TestLlmConnectionDocument,\n UpdateBotmanorLlmProviderDocument,\n type CreateBotmanorLlmProviderMutation,\n type CreateBotmanorLlmModelMutation,\n type DeleteLlmProviderMutation,\n type GetBotmanorLlmProviderQuery,\n type ListBotmanorLlmModelsQuery,\n type ListBotmanorLlmProvidersQuery,\n type TestLlmConnectionMutation,\n type UpdateBotmanorLlmProviderMutation,\n} from '../../generated/wspace-operations';\nimport type {\n CreateBotmanorLlmModelInput,\n CreateBotmanorLlmProviderInput,\n UpdateBotmanorLlmProviderInput,\n} from '../../generated/wspace-types';\nimport { buildMutationInput, fieldsOf, type GraphQLInput } from './internal/mutationInput';\nimport {\n useWorkspaceId,\n useWorkspaceClient,\n useWorkspaceMutation,\n useWorkspaceQuery,\n type QueryResult,\n} from './internal/workspaceGateway';\n\nconst LIST_LIMIT = 50;\n\nexport interface LLMProviderRecord {\n id: string;\n name: string;\n type: string;\n isActive: boolean;\n apiEndpoint?: string | null;\n credentialsHash?: string | null;\n connectionId?: string | null;\n metadata?: Record<string, unknown> | null;\n createdAt: string;\n updatedAt: string;\n workspaceId: string;\n}\n\nexport interface LLMModelRecord {\n id: string;\n name: string;\n modelId: string;\n providerId: string;\n contextWindow: number;\n maxOutputTokens: number;\n inputPricePerMToken: number;\n outputPricePerMToken: number;\n isActive: boolean;\n supportsStreaming: boolean;\n supportsFunctionCalling: boolean;\n supportsVision: boolean;\n metadata?: Record<string, unknown> | null;\n createdAt: string;\n updatedAt: string;\n}\n\n/** `CreateBotmanorLLMProviderInput` minus the `workspaceId` the hook supplies. */\nexport type ConfigureLLMProviderVariables = Omit<\n GraphQLInput<CreateBotmanorLlmProviderInput>,\n 'workspaceId'\n> & { isActive?: boolean };\n\nconst NO_PROVIDERS: LLMProviderRecord[] = [];\nconst NO_MODELS: LLMModelRecord[] = [];\n\nconst CREATE_PROVIDER_FIELDS = fieldsOf<CreateBotmanorLlmProviderInput>({\n apiEndpoint: true,\n connectionId: true,\n credentials: true,\n metadata: true,\n name: true,\n type: true,\n workspaceId: true,\n});\n\nconst UPDATE_PROVIDER_FIELDS = fieldsOf<UpdateBotmanorLlmProviderInput>({\n apiEndpoint: true,\n connectionId: true,\n credentials: true,\n isActive: true,\n metadata: true,\n name: true,\n});\n\nexport const llmProviderKeys = {\n all: ['llmProviders'] as const,\n lists: () => [...llmProviderKeys.all, 'list'] as const,\n details: () => [...llmProviderKeys.all, 'detail'] as const,\n detail: (id: string) => [...llmProviderKeys.details(), id] as const,\n};\n\nfunction useLLMList<TData, TRecord>(\n document: DocumentNode,\n kind: string,\n select: (data: TData | undefined) => TRecord[],\n fallback: TRecord[],\n providerId?: string\n): QueryResult<TRecord[]> {\n const client = useWorkspaceClient();\n const { workspaceId, currentUser } = useBotlit();\n const query = useQuery({\n queryKey: ['botmanor-llm-catalog', workspaceId, currentUser?.id, kind, providerId],\n enabled: Boolean(workspaceId),\n retry: false,\n queryFn: async () => {\n const records: TRecord[] = [];\n for (let offset = 0; offset < 10000; offset += LIST_LIMIT) {\n const result = await client.query<TData>({\n query: document,\n fetchPolicy: 'network-only',\n variables: {\n filters: providerId ? { providerId } : undefined,\n pagination: { limit: LIST_LIMIT, offset },\n },\n });\n if (!result.data) throw new Error('Model catalog unavailable');\n const page = select(result.data);\n if (!Array.isArray(page) || page.length > LIST_LIMIT)\n throw new Error('Model catalog unavailable');\n records.push(...page);\n if (page.length < LIST_LIMIT) return records;\n }\n throw new Error('Model catalog exceeds the supported limit');\n },\n });\n return {\n data: query.data ?? fallback,\n loading: query.isFetching,\n error: query.error ?? undefined,\n refetch: async () => {\n await query.refetch();\n },\n };\n}\n\nexport function useLLMProviders(): QueryResult<LLMProviderRecord[]> {\n return useLLMList<ListBotmanorLlmProvidersQuery, LLMProviderRecord>(\n ListBotmanorLlmProvidersDocument,\n 'providers',\n (data) => data?.listBotmanorLLMProviders ?? NO_PROVIDERS,\n NO_PROVIDERS\n );\n}\n\nexport function useLLMProvider(\n providerId: string | undefined\n): QueryResult<LLMProviderRecord | null> {\n const variables = useMemo(() => ({ id: providerId ?? '' }), [providerId]);\n\n return useWorkspaceQuery<GetBotmanorLlmProviderQuery, LLMProviderRecord | null>({\n document: GetBotmanorLlmProviderDocument,\n variables,\n select: (data) => data?.getBotmanorLLMProvider ?? null,\n fallback: null,\n enabled: Boolean(providerId),\n errorMessage: 'Failed to load LLM provider',\n });\n}\n\nexport function useLLMModels(filters?: { providerId?: string }): QueryResult<LLMModelRecord[]> {\n return useLLMList<ListBotmanorLlmModelsQuery, LLMModelRecord>(\n ListBotmanorLlmModelsDocument,\n 'models',\n (data) => data?.listBotmanorLLMModels ?? NO_MODELS,\n NO_MODELS,\n filters?.providerId\n );\n}\n\n/**\n * Creates a provider, or updates the one whose id the caller passes.\n * `UpdateBotmanorLLMProviderInput` has no `type`/`workspaceId`, so the update\n * payload is projected onto the fields that input actually declares.\n */\nexport function useConfigureLLMProvider() {\n const workspaceId = useWorkspaceId();\n\n const [create, createState] = useWorkspaceMutation<\n CreateBotmanorLlmProviderMutation,\n ConfigureLLMProviderVariables,\n LLMProviderRecord\n >({\n document: CreateBotmanorLlmProviderDocument,\n variables: (input) => ({\n input: buildMutationInput({ ...input, workspaceId }, CREATE_PROVIDER_FIELDS),\n }),\n select: (data) => data?.createBotmanorLLMProvider,\n errorMessage: 'Failed to create the LLM provider',\n });\n\n const [update, updateState] = useWorkspaceMutation<\n UpdateBotmanorLlmProviderMutation,\n { providerId: string; input: ConfigureLLMProviderVariables },\n LLMProviderRecord\n >({\n document: UpdateBotmanorLlmProviderDocument,\n variables: ({ providerId, input }) => ({\n id: providerId,\n input: buildMutationInput(input, UPDATE_PROVIDER_FIELDS),\n }),\n select: (data) => data?.updateBotmanorLLMProvider,\n errorMessage: 'Failed to update the LLM provider',\n });\n\n const configureProvider = useCallback(\n async (input: ConfigureLLMProviderVariables, existingId?: string) =>\n existingId ? update({ providerId: existingId, input }) : create(input),\n [create, update]\n );\n\n return {\n configureProvider,\n isConfiguring: createState.loading || updateState.loading,\n error: createState.error ?? updateState.error,\n };\n}\n\nexport function useDeleteLLMProvider() {\n return useWorkspaceMutation<DeleteLlmProviderMutation, string, boolean>({\n document: DeleteLlmProviderDocument,\n variables: (providerId) => ({ id: providerId }),\n select: (data) => data?.deleteLLMProvider,\n errorMessage: 'Failed to delete the LLM provider',\n });\n}\n\nexport function useTestLLMConnection() {\n return useWorkspaceMutation<TestLlmConnectionMutation, string, boolean>({\n document: TestLlmConnectionDocument,\n variables: (providerId) => ({ id: providerId }),\n select: (data) => data?.testLlmConnection,\n errorMessage: 'Failed to test the LLM connection',\n });\n}\n\n/** Register models through the same authenticated workspace gateway as providers. */\nexport function useCreateLLMModel() {\n const [createModel, state] = useWorkspaceMutation<\n CreateBotmanorLlmModelMutation,\n CreateBotmanorLlmModelInput,\n LLMModelRecord\n >({\n document: CreateBotmanorLlmModelDocument,\n variables: (input) => ({\n input: buildMutationInput(\n input,\n fieldsOf<CreateBotmanorLlmModelInput>({\n providerId: true,\n name: true,\n modelId: true,\n contextWindow: true,\n maxOutputTokens: true,\n inputPricePerMToken: true,\n outputPricePerMToken: true,\n supportsStreaming: true,\n supportsFunctionCalling: true,\n supportsVision: true,\n metadata: true,\n })\n ),\n }),\n select: (data) => data?.createBotmanorLLMModel,\n errorMessage: 'Failed to register the model',\n });\n return { createModel, isCreating: state.loading, error: state.error };\n}\n"],"mappings":";;;;;;;AA+CA,IAAMA,IAAa,IAwCbC,IAAoC,CAAC,GACrCC,IAA8B,CAAC,GAE/BC,IAAyBC,EAAyC;CACtE,aAAa;CACb,cAAc;CACd,aAAa;CACb,UAAU;CACV,MAAM;CACN,MAAM;CACN,aAAa;AACf,CAAC,GAEKC,IAAyBD,EAAyC;CACtE,aAAa;CACb,cAAc;CACd,aAAa;CACb,UAAU;CACV,UAAU;CACV,MAAM;AACR,CAAC;AASD,SAASE,EACP,GACA,GACA,GACA,GACA,GACwB;CACxB,IAAMC,IAASC,EAAmB,GAC5B,EAAE,gBAAa,mBAAgBC,EAAU,GACzCC,IAAQC,EAAS;EACrB,UAAU;GAAC;GAAwBC;GAAaC,GAAa;GAAIC;GAAMC;EAAU;EACjF,SAAS,EAAQH;EACjB,OAAO;EACP,SAAS,YAAY;GACnB,IAAMI,IAAqB,CAAC;GAC5B,KAAK,IAAIC,IAAS,GAAGA,IAAS,KAAO,KAAUjB,GAAY;IACzD,IAAMkB,IAAS,MAAMX,EAAO,MAAa;KACvC,OAAOY;KACP,aAAa;KACb,WAAW;MACT,SAASJ,IAAa,EAAE,cAAW,IAAI,KAAA;MACvC,YAAY;OAAE,OAAOf;OAAY;MAAO;KAC1C;IACF,CAAC;IACD,IAAI,CAACkB,EAAO,MAAM,MAAU,MAAM,2BAA2B;IAC7D,IAAME,IAAOC,EAAOH,EAAO,IAAI;IAC/B,IAAI,CAAC,MAAM,QAAQE,CAAI,KAAKA,EAAK,SAASpB,GACxC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B,OAAOV,EACLC,GACAhC,EAAsC;GACpC,YAAY;GACZ,MAAM;GACN,SAAS;GACT,eAAe;GACf,iBAAiB;GACjB,qBAAqB;GACrB,sBAAsB;GACtB,mBAAmB;GACnB,yBAAyB;GACzB,gBAAgB;GAChB,UAAU;EACZ,CAAC,CACH,EACF;EACA,SAAS,MAASqB,GAAM;EACxB,cAAc;CAChB,CAAC;CACD,OAAO;EAAE;EAAa,YAAYmB,EAAM;EAAS,OAAOA,EAAM;CAAM;AACtE"}
1
+ {"version":3,"file":"useLLMProviders.js","names":["LIST_LIMIT","NO_PROVIDERS","NO_MODELS","CREATE_PROVIDER_FIELDS","fieldsOf","UPDATE_PROVIDER_FIELDS","useLLMList","client","useWorkspaceClient","useBotlit","query","useQuery","workspaceId","currentUser","kind","providerId","records","offset","result","document","page","select","fallback","useLLMProviders","ListBotmanorLlmProvidersDocument","data","useLLMModels","ListBotmanorLlmModelsDocument","filters","useConfigureLLMProvider","useWorkspaceId","create","createState","useWorkspaceMutation","CreateBotmanorLlmProviderDocument","buildMutationInput","input","update","updateState","UpdateBotmanorLlmProviderDocument","useCallback","existingId","useTestLLMConnection","TestLlmConnectionDocument","useCreateLLMModel","createModel","state","CreateBotmanorLlmModelDocument"],"sources":["../../../src/botlit/hooks/useLLMProviders.ts"],"sourcesContent":["/**\n * LLM Providers Hooks\n * @module botlit/hooks\n *\n * These go through the shell's workspace gateway client like every other BotManor\n * hook. They deliberately do NOT use the generated `useQuery`/`useMutation`\n * wrappers: `BotmanorRoot` only mounts an `<ApolloProvider>` in standalone mode,\n * so an Apollo React hook throws \"Could not find client in the context\" the\n * moment the MFE is mounted by an app shell — which is every production route.\n */\n\nimport { useCallback, useMemo } from 'react';\nimport type { DocumentNode } from 'graphql';\nimport { useQuery } from '@tanstack/react-query';\nimport { useBotlit } from '../providers/BotlitProvider';\nimport {\n CreateBotmanorLlmProviderDocument,\n CreateBotmanorLlmModelDocument,\n DeleteLlmProviderDocument,\n GetBotmanorLlmProviderDocument,\n ListBotmanorLlmModelsDocument,\n ListBotmanorLlmProvidersDocument,\n TestLlmConnectionDocument,\n UpdateBotmanorLlmProviderDocument,\n type CreateBotmanorLlmProviderMutation,\n type CreateBotmanorLlmModelMutation,\n type DeleteLlmProviderMutation,\n type GetBotmanorLlmProviderQuery,\n type ListBotmanorLlmModelsQuery,\n type ListBotmanorLlmProvidersQuery,\n type TestLlmConnectionMutation,\n type UpdateBotmanorLlmProviderMutation,\n} from '../../generated/wspace-operations';\nimport type {\n CreateBotmanorLlmModelInput,\n CreateBotmanorLlmProviderInput,\n UpdateBotmanorLlmProviderInput,\n} from '../../generated/wspace-types';\nimport { buildMutationInput, fieldsOf, type GraphQLInput } from './internal/mutationInput';\nimport {\n useWorkspaceId,\n useWorkspaceClient,\n useWorkspaceMutation,\n useWorkspaceQuery,\n type QueryResult,\n} from './internal/workspaceGateway';\n\nconst LIST_LIMIT = 50;\n\nexport interface LLMProviderRecord {\n id: string;\n name: string;\n type: string;\n isActive: boolean;\n apiEndpoint?: string | null;\n credentialsHash?: string | null;\n connectionId?: string | null;\n metadata?: Record<string, unknown> | null;\n createdAt: string;\n updatedAt: string;\n workspaceId: string;\n}\n\nexport interface LLMModelRecord {\n id: string;\n name: string;\n modelId: string;\n providerId: string;\n contextWindow: number;\n maxOutputTokens: number;\n inputPricePerMToken: number;\n outputPricePerMToken: number;\n isActive: boolean;\n supportsStreaming: boolean;\n supportsFunctionCalling: boolean;\n supportsVision: boolean;\n metadata?: Record<string, unknown> | null;\n createdAt: string;\n updatedAt: string;\n}\n\n/** `CreateBotmanorLLMProviderInput` minus the `workspaceId` the hook supplies. */\nexport type ConfigureLLMProviderVariables = Omit<\n GraphQLInput<CreateBotmanorLlmProviderInput>,\n 'workspaceId'\n> & { isActive?: boolean };\n\nconst NO_PROVIDERS: LLMProviderRecord[] = [];\nconst NO_MODELS: LLMModelRecord[] = [];\n\nconst CREATE_PROVIDER_FIELDS = fieldsOf<CreateBotmanorLlmProviderInput>({\n apiEndpoint: true,\n connectionId: true,\n credentials: true,\n metadata: true,\n name: true,\n type: true,\n workspaceId: true,\n});\n\nconst UPDATE_PROVIDER_FIELDS = fieldsOf<UpdateBotmanorLlmProviderInput>({\n apiEndpoint: true,\n connectionId: true,\n credentials: true,\n isActive: true,\n metadata: true,\n name: true,\n});\n\nexport const llmProviderKeys = {\n all: ['llmProviders'] as const,\n lists: () => [...llmProviderKeys.all, 'list'] as const,\n details: () => [...llmProviderKeys.all, 'detail'] as const,\n detail: (id: string) => [...llmProviderKeys.details(), id] as const,\n};\n\nfunction useLLMList<TData, TRecord>(\n document: DocumentNode,\n kind: string,\n select: (data: TData | undefined) => TRecord[],\n fallback: TRecord[],\n providerId?: string\n): QueryResult<TRecord[]> {\n const client = useWorkspaceClient();\n const { workspaceId, currentUser } = useBotlit();\n const query = useQuery({\n queryKey: ['botmanor-llm-catalog', workspaceId, currentUser?.id, kind, providerId],\n enabled: Boolean(workspaceId),\n retry: false,\n queryFn: async () => {\n const records: TRecord[] = [];\n for (let offset = 0; offset < 10000; offset += LIST_LIMIT) {\n const result = await client.query<TData>({\n query: document,\n fetchPolicy: 'network-only',\n variables: {\n filters: providerId ? { providerId } : undefined,\n pagination: { limit: LIST_LIMIT, offset },\n },\n });\n if (!result.data) throw new Error('Model catalog unavailable');\n const page = select(result.data);\n if (!Array.isArray(page) || page.length > LIST_LIMIT)\n throw new Error('Model catalog unavailable');\n records.push(...page);\n if (page.length < LIST_LIMIT) return records;\n }\n throw new Error('Model catalog exceeds the supported limit');\n },\n });\n return {\n data: query.data ?? fallback,\n loading: query.isFetching,\n error: query.error ?? undefined,\n refetch: async () => {\n await query.refetch();\n },\n };\n}\n\nexport function useLLMProviders(): QueryResult<LLMProviderRecord[]> {\n return useLLMList<ListBotmanorLlmProvidersQuery, LLMProviderRecord>(\n ListBotmanorLlmProvidersDocument,\n 'providers',\n (data) => data?.listBotmanorLLMProviders ?? NO_PROVIDERS,\n NO_PROVIDERS\n );\n}\n\nexport function useLLMProvider(\n providerId: string | undefined\n): QueryResult<LLMProviderRecord | null> {\n const variables = useMemo(() => ({ id: providerId ?? '' }), [providerId]);\n\n return useWorkspaceQuery<GetBotmanorLlmProviderQuery, LLMProviderRecord | null>({\n document: GetBotmanorLlmProviderDocument,\n variables,\n select: (data) => data?.getBotmanorLLMProvider ?? null,\n fallback: null,\n enabled: Boolean(providerId),\n errorMessage: 'Failed to load LLM provider',\n });\n}\n\nexport function useLLMModels(filters?: { providerId?: string }): QueryResult<LLMModelRecord[]> {\n return useLLMList<ListBotmanorLlmModelsQuery, LLMModelRecord>(\n ListBotmanorLlmModelsDocument,\n 'models',\n (data) => data?.listBotmanorLLMModels ?? NO_MODELS,\n NO_MODELS,\n filters?.providerId\n );\n}\n\n/**\n * Creates a provider, or updates the one whose id the caller passes.\n * `UpdateBotmanorLLMProviderInput` has no `type`/`workspaceId`, so the update\n * payload is projected onto the fields that input actually declares.\n */\nexport function useConfigureLLMProvider() {\n const workspaceId = useWorkspaceId();\n\n const [create, createState] = useWorkspaceMutation<\n CreateBotmanorLlmProviderMutation,\n ConfigureLLMProviderVariables,\n LLMProviderRecord\n >({\n document: CreateBotmanorLlmProviderDocument,\n variables: (input) => ({\n input: buildMutationInput({ ...input, workspaceId }, CREATE_PROVIDER_FIELDS),\n }),\n select: (data) => data?.createBotmanorLLMProvider,\n errorMessage: 'Failed to create the LLM provider',\n });\n\n const [update, updateState] = useWorkspaceMutation<\n UpdateBotmanorLlmProviderMutation,\n { providerId: string; input: ConfigureLLMProviderVariables },\n LLMProviderRecord\n >({\n document: UpdateBotmanorLlmProviderDocument,\n variables: ({ providerId, input }) => ({\n id: providerId,\n input: buildMutationInput(input, UPDATE_PROVIDER_FIELDS),\n }),\n select: (data) => data?.updateBotmanorLLMProvider,\n errorMessage: 'Failed to update the LLM provider',\n });\n\n const configureProvider = useCallback(\n async (input: ConfigureLLMProviderVariables, existingId?: string) =>\n existingId ? update({ providerId: existingId, input }) : create(input),\n [create, update]\n );\n\n return {\n configureProvider,\n isConfiguring: createState.loading || updateState.loading,\n error: createState.error ?? updateState.error,\n };\n}\n\nexport function useDeleteLLMProvider() {\n return useWorkspaceMutation<DeleteLlmProviderMutation, string, boolean>({\n document: DeleteLlmProviderDocument,\n variables: (providerId) => ({ id: providerId }),\n select: (data) => data?.deleteLLMProvider,\n errorMessage: 'Failed to delete the LLM provider',\n });\n}\n\nexport function useTestLLMConnection() {\n return useWorkspaceMutation<TestLlmConnectionMutation, string, boolean>({\n document: TestLlmConnectionDocument,\n variables: (providerId) => ({ id: providerId }),\n select: (data) => data?.testLlmConnection,\n errorMessage: 'Failed to test the LLM connection',\n });\n}\n\n/** Register models through the same authenticated workspace gateway as providers. */\nexport function useCreateLLMModel() {\n const [createModel, state] = useWorkspaceMutation<\n CreateBotmanorLlmModelMutation,\n CreateBotmanorLlmModelInput,\n LLMModelRecord\n >({\n document: CreateBotmanorLlmModelDocument,\n variables: (input) => ({\n input: buildMutationInput(\n input,\n fieldsOf<CreateBotmanorLlmModelInput>({\n providerId: true,\n name: true,\n modelId: true,\n contextWindow: true,\n maxOutputTokens: true,\n inputPricePerMToken: true,\n outputPricePerMToken: true,\n supportsStreaming: true,\n supportsFunctionCalling: true,\n supportsVision: true,\n metadata: true,\n })\n ),\n }),\n select: (data) => data?.createBotmanorLLMModel,\n errorMessage: 'Failed to register the model',\n });\n return { createModel, isCreating: state.loading, error: state.error };\n}\n"],"mappings":";;;;;;;AA+CA,IAAMA,IAAa,IAwCbC,IAAoC,CAAC,GACrCC,IAA8B,CAAC,GAE/BC,IAAyBC,EAAyC;CACtE,aAAa;CACb,cAAc;CACd,aAAa;CACb,UAAU;CACV,MAAM;CACN,MAAM;CACN,aAAa;AACf,CAAC,GAEKC,IAAyBD,EAAyC;CACtE,aAAa;CACb,cAAc;CACd,aAAa;CACb,UAAU;CACV,UAAU;CACV,MAAM;AACR,CAAC;AASD,SAASE,EACP,GACA,GACA,GACA,GACA,GACwB;CACxB,IAAMC,IAASC,EAAmB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EAAY,GAAGjC,CAAsB,EAC7E;EACA,SAAS,MAASsB,GAAM;EACxB,cAAc;CAChB,CAAC,GAEK,CAACY,GAAQC,KAAeL,EAI5B;EACA,UAAUM;EACV,YAAY,EAAE,eAAY,gBAAa;GACrC,IAAIxB;GACJ,OAAOoB,EAAmBC,GAAO/B,CAAsB;EACzD;EACA,SAAS,MAASoB,GAAM;EACxB,cAAc;CAChB,CAAC;CAQD,OAAO;EACL,mBAPwBe,EACxB,OAAO,GAAsC,MAC3CC,IAAaJ,EAAO;GAAE,YAAYI;GAAY;EAAM,CAAC,IAAIV,EAAOK,CAAK,GACvE,CAACL,GAAQM,CAAM,CAIf;EACA,eAAeL,EAAY,WAAWM,EAAY;EAClD,OAAON,EAAY,SAASM,EAAY;CAC1C;AACF;AAWA,SAAgBI,IAAuB;CACrC,OAAOT,EAAiE;EACtE,UAAUU;EACV,YAAY,OAAgB,EAAE,IAAI5B,EAAW;EAC7C,SAAS,MAASU,GAAM;EACxB,cAAc;CAChB,CAAC;AACH;AAGA,SAAgBmB,IAAoB;CAClC,IAAM,CAACC,GAAaC,KAASb,EAI3B;EACA,UAAUc;EACV,YAAY,OAAW,EACrB,OAAOZ,EACLC,GACAhC,EAAsC;GACpC,YAAY;GACZ,MAAM;GACN,SAAS;GACT,eAAe;GACf,iBAAiB;GACjB,qBAAqB;GACrB,sBAAsB;GACtB,mBAAmB;GACnB,yBAAyB;GACzB,gBAAgB;GAChB,UAAU;EACZ,CAAC,CACH,EACF;EACA,SAAS,MAASqB,GAAM;EACxB,cAAc;CAChB,CAAC;CACD,OAAO;EAAE;EAAa,YAAYqB,EAAM;EAAS,OAAOA,EAAM;CAAM;AACtE"}
@@ -0,0 +1,19 @@
1
+ import { QueryResult } from './internal/workspaceGateway';
2
+ export interface TemplateRecord {
3
+ id: string;
4
+ name: string;
5
+ description?: string | null;
6
+ category?: string | null;
7
+ }
8
+ interface CreatedRecord {
9
+ id: string;
10
+ name: string;
11
+ }
12
+ export type TemplateKind = 'bot' | 'agent';
13
+ export declare function useTemplates(kind: TemplateKind): QueryResult<TemplateRecord[]>;
14
+ export interface CreateFromTemplateInput {
15
+ name: string;
16
+ templateId: string;
17
+ }
18
+ export declare function useCreateFromTemplate(kind: TemplateKind): readonly [(input: CreateFromTemplateInput) => Promise<CreatedRecord>, import('./internal/workspaceGateway').MutationState<CreatedRecord>];
19
+ export {};
@@ -0,0 +1,71 @@
1
+ import { useWorkspaceId as e, useWorkspaceMutation as t, useWorkspaceQuery as n } from "./internal/workspaceGateway.js";
2
+ import { useMemo as r } from "react";
3
+ import { gql as i } from "@apollo/client";
4
+ // src/botlit/hooks/useTemplates.ts
5
+ var a = i`
6
+ query ListBotTemplates($pagination: PaginationInput) {
7
+ listAppTemplates(pagination: $pagination) {
8
+ id
9
+ name
10
+ description
11
+ category
12
+ }
13
+ }
14
+ `, o = i`
15
+ query ListAgentTemplatesForCreate($pagination: PaginationInput) {
16
+ listAgentTemplates(pagination: $pagination) {
17
+ id
18
+ name
19
+ description
20
+ category
21
+ }
22
+ }
23
+ `, s = i`
24
+ mutation CreateBotFromTemplate($name: String!, $templateId: ID!, $workspaceId: ID!) {
25
+ createAppFromTemplate(name: $name, templateId: $templateId, workspaceId: $workspaceId) {
26
+ id
27
+ name
28
+ }
29
+ }
30
+ `, c = i`
31
+ mutation CreateAgentFromTemplate($name: String!, $templateId: ID!, $workspaceId: ID!) {
32
+ createBotmanorAgentFromTemplate(
33
+ name: $name
34
+ templateId: $templateId
35
+ workspaceId: $workspaceId
36
+ ) {
37
+ id
38
+ name
39
+ }
40
+ }
41
+ `, l = [], u = { pagination: {
42
+ limit: 100,
43
+ offset: 0
44
+ } };
45
+ function d(t) {
46
+ let i = e(), s = r(() => u, []);
47
+ return n({
48
+ document: t === "bot" ? a : o,
49
+ variables: s,
50
+ select: (e) => (t === "bot" ? e?.listAppTemplates : e?.listAgentTemplates) ?? l,
51
+ fallback: l,
52
+ enabled: !!i,
53
+ errorMessage: "Failed to load templates"
54
+ });
55
+ }
56
+ function f(n) {
57
+ let r = e();
58
+ return t({
59
+ document: n === "bot" ? s : c,
60
+ variables: ({ name: e, templateId: t }) => ({
61
+ name: e.trim(),
62
+ templateId: t,
63
+ workspaceId: r
64
+ }),
65
+ select: (e) => (n === "bot" ? e?.createAppFromTemplate : e?.createBotmanorAgentFromTemplate) ?? void 0,
66
+ errorMessage: n === "bot" ? "Failed to create the bot from the template" : "Failed to create the agent from the template"
67
+ });
68
+ }
69
+ export { f as useCreateFromTemplate, d as useTemplates };
70
+
71
+ //# sourceMappingURL=useTemplates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTemplates.js","names":["LIST_APP_TEMPLATES_DOCUMENT","LIST_AGENT_TEMPLATES_DOCUMENT","CREATE_APP_FROM_TEMPLATE_DOCUMENT","CREATE_AGENT_FROM_TEMPLATE_DOCUMENT","NO_TEMPLATES","PAGE","useTemplates","workspaceId","useWorkspaceId","variables","useMemo","useWorkspaceQuery","kind","data","useCreateFromTemplate","useWorkspaceMutation","name"],"sources":["../../../src/botlit/hooks/useTemplates.ts"],"sourcesContent":["/**\n * App and agent templates (BOFF-15360)\n * @module botlit/hooks\n *\n * Every workspace is provisioned with a starter catalogue of bot (app) and\n * agent templates. These hooks list them and create a bot or an agent from one\n * in a single step, the \"Create from template\" flow on the create pages.\n */\n\nimport { gql } from '@apollo/client';\nimport { useMemo } from 'react';\n\nimport {\n useWorkspaceId,\n useWorkspaceMutation,\n useWorkspaceQuery,\n type QueryResult,\n} from './internal/workspaceGateway';\n\nexport interface TemplateRecord {\n id: string;\n name: string;\n description?: string | null;\n category?: string | null;\n}\n\ninterface ListAppTemplatesData {\n listAppTemplates?: TemplateRecord[] | null;\n}\n\ninterface ListAgentTemplatesData {\n listAgentTemplates?: TemplateRecord[] | null;\n}\n\ninterface CreatedRecord {\n id: string;\n name: string;\n}\n\ninterface CreateAppFromTemplateData {\n createAppFromTemplate?: CreatedRecord | null;\n}\n\ninterface CreateAgentFromTemplateData {\n createBotmanorAgentFromTemplate?: CreatedRecord | null;\n}\n\nconst LIST_APP_TEMPLATES_DOCUMENT = gql`\n query ListBotTemplates($pagination: PaginationInput) {\n listAppTemplates(pagination: $pagination) {\n id\n name\n description\n category\n }\n }\n`;\n\nconst LIST_AGENT_TEMPLATES_DOCUMENT = gql`\n query ListAgentTemplatesForCreate($pagination: PaginationInput) {\n listAgentTemplates(pagination: $pagination) {\n id\n name\n description\n category\n }\n }\n`;\n\nconst CREATE_APP_FROM_TEMPLATE_DOCUMENT = gql`\n mutation CreateBotFromTemplate($name: String!, $templateId: ID!, $workspaceId: ID!) {\n createAppFromTemplate(name: $name, templateId: $templateId, workspaceId: $workspaceId) {\n id\n name\n }\n }\n`;\n\nconst CREATE_AGENT_FROM_TEMPLATE_DOCUMENT = gql`\n mutation CreateAgentFromTemplate($name: String!, $templateId: ID!, $workspaceId: ID!) {\n createBotmanorAgentFromTemplate(\n name: $name\n templateId: $templateId\n workspaceId: $workspaceId\n ) {\n id\n name\n }\n }\n`;\n\nconst NO_TEMPLATES: TemplateRecord[] = [];\nconst PAGE = { pagination: { limit: 100, offset: 0 } };\n\nexport type TemplateKind = 'bot' | 'agent';\n\nexport function useTemplates(kind: TemplateKind): QueryResult<TemplateRecord[]> {\n const workspaceId = useWorkspaceId();\n const variables = useMemo(() => PAGE, []);\n return useWorkspaceQuery<ListAppTemplatesData & ListAgentTemplatesData, TemplateRecord[]>({\n document: kind === 'bot' ? LIST_APP_TEMPLATES_DOCUMENT : LIST_AGENT_TEMPLATES_DOCUMENT,\n variables,\n select: (data) =>\n (kind === 'bot' ? data?.listAppTemplates : data?.listAgentTemplates) ?? NO_TEMPLATES,\n fallback: NO_TEMPLATES,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load templates',\n });\n}\n\nexport interface CreateFromTemplateInput {\n name: string;\n templateId: string;\n}\n\nexport function useCreateFromTemplate(kind: TemplateKind) {\n const workspaceId = useWorkspaceId();\n return useWorkspaceMutation<\n CreateAppFromTemplateData & CreateAgentFromTemplateData,\n CreateFromTemplateInput,\n CreatedRecord\n >({\n document:\n kind === 'bot' ? CREATE_APP_FROM_TEMPLATE_DOCUMENT : CREATE_AGENT_FROM_TEMPLATE_DOCUMENT,\n variables: ({ name, templateId }) => ({ name: name.trim(), templateId, workspaceId }),\n select: (data) =>\n (kind === 'bot' ? data?.createAppFromTemplate : data?.createBotmanorAgentFromTemplate) ??\n undefined,\n errorMessage:\n kind === 'bot'\n ? 'Failed to create the bot from the template'\n : 'Failed to create the agent from the template',\n });\n}\n"],"mappings":";;;;AA+CA,IAAMA,IAA8B,CAAG;;;;;;;;;GAWjCC,IAAgC,CAAG;;;;;;;;;GAWnCC,IAAoC,CAAG;;;;;;;GASvCC,IAAsC,CAAG;;;;;;;;;;;GAazCC,IAAiC,CAAC,GAClCC,IAAO,EAAE,YAAY;CAAE,OAAO;CAAK,QAAQ;AAAE,EAAE;AAIrD,SAAgBC,EAAa,GAAmD;CAC9E,IAAMC,IAAcC,EAAe,GAC7BC,IAAYC,QAAcL,GAAM,CAAC,CAAC;CACxC,OAAOM,EAAmF;EACxF,UAAUC,MAAS,QAAQZ,IAA8BC;EACzD;EACA,SAAS,OACNW,MAAS,QAAQC,GAAM,mBAAmBA,GAAM,uBAAuBT;EAC1E,UAAUA;EACV,SAAS,EAAQG;EACjB,cAAc;CAChB,CAAC;AACH;AAOA,SAAgBO,EAAsB,GAAoB;CACxD,IAAMP,IAAcC,EAAe;CACnC,OAAOO,EAIL;EACA,UACEH,MAAS,QAAQV,IAAoCC;EACvD,YAAY,EAAE,SAAM,qBAAkB;GAAE,MAAMa,EAAK,KAAK;GAAG;GAAY;EAAY;EACnF,SAAS,OACNJ,MAAS,QAAQC,GAAM,wBAAwBA,GAAM,oCACtD,KAAA;EACF,cACED,MAAS,QACL,+CACA;CACR,CAAC;AACH"}