@burdenoff/microfe-botmanor 2026.1109.1 → 2026.1110.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 (73) hide show
  1. package/dist/botlit/BotlitRoutes.js +34 -45
  2. package/dist/botlit/BotlitRoutes.js.map +1 -1
  3. package/dist/botlit/components/Badge.js +2 -2
  4. package/dist/botlit/components/Badge.js.map +1 -1
  5. package/dist/botlit/components/ChannelSelectorSheet.js +4 -4
  6. package/dist/botlit/components/ChannelSelectorSheet.js.map +1 -1
  7. package/dist/botlit/components/LoadMore.d.ts +9 -0
  8. package/dist/botlit/components/LoadMore.js +22 -0
  9. package/dist/botlit/components/LoadMore.js.map +1 -0
  10. package/dist/botlit/components/index.d.ts +1 -0
  11. package/dist/botlit/hooks/index.d.ts +1 -2
  12. package/dist/botlit/hooks/index.js +15 -16
  13. package/dist/botlit/hooks/internal/workspaceGateway.d.ts +47 -0
  14. package/dist/botlit/hooks/internal/workspaceGateway.js +59 -1
  15. package/dist/botlit/hooks/internal/workspaceGateway.js.map +1 -1
  16. package/dist/botlit/hooks/useAgents.d.ts +2 -6
  17. package/dist/botlit/hooks/useAgents.js +71 -95
  18. package/dist/botlit/hooks/useAgents.js.map +1 -1
  19. package/dist/botlit/hooks/useBots.d.ts +2 -6
  20. package/dist/botlit/hooks/useBots.js +51 -75
  21. package/dist/botlit/hooks/useBots.js.map +1 -1
  22. package/dist/botlit/hooks/useBuckets.d.ts +5 -0
  23. package/dist/botlit/hooks/useBuckets.js +72 -38
  24. package/dist/botlit/hooks/useBuckets.js.map +1 -1
  25. package/dist/botlit/hooks/useExecutions.d.ts +2 -2
  26. package/dist/botlit/hooks/useExecutions.js +30 -34
  27. package/dist/botlit/hooks/useExecutions.js.map +1 -1
  28. package/dist/botlit/hooks/useStore.d.ts +3 -3
  29. package/dist/botlit/hooks/useStore.js +41 -50
  30. package/dist/botlit/hooks/useStore.js.map +1 -1
  31. package/dist/botlit/index.d.ts +0 -1
  32. package/dist/botlit/index.js +5 -6
  33. package/dist/botlit/pages/A2AAgentDetailPage.js +1 -1
  34. package/dist/botlit/pages/A2AAgentDetailPage.js.map +1 -1
  35. package/dist/botlit/pages/AgentDetailPage.js +1 -1
  36. package/dist/botlit/pages/AgentDetailPage.js.map +1 -1
  37. package/dist/botlit/pages/AgentsListPage.js +157 -156
  38. package/dist/botlit/pages/AgentsListPage.js.map +1 -1
  39. package/dist/botlit/pages/BotChannelsTab.js +24 -24
  40. package/dist/botlit/pages/BotChannelsTab.js.map +1 -1
  41. package/dist/botlit/pages/BotsListPage.js +147 -146
  42. package/dist/botlit/pages/BotsListPage.js.map +1 -1
  43. package/dist/botlit/pages/BucketDetailPage.d.ts +2 -0
  44. package/dist/botlit/pages/BucketDetailPage.js +251 -0
  45. package/dist/botlit/pages/BucketDetailPage.js.map +1 -0
  46. package/dist/botlit/pages/BucketsPage.js +3 -3
  47. package/dist/botlit/pages/BucketsPage.js.map +1 -1
  48. package/dist/botlit/pages/ChannelDetailPage.js +2 -2
  49. package/dist/botlit/pages/ChannelDetailPage.js.map +1 -1
  50. package/dist/botlit/pages/ExecutionsPage.js +141 -134
  51. package/dist/botlit/pages/ExecutionsPage.js.map +1 -1
  52. package/dist/botlit/pages/InstalledPackagesPage.js +43 -36
  53. package/dist/botlit/pages/InstalledPackagesPage.js.map +1 -1
  54. package/dist/botlit/pages/MCPServersPage.js +1 -1
  55. package/dist/botlit/pages/MCPServersPage.js.map +1 -1
  56. package/dist/botlit/pages/SettingsPage.js +2 -2
  57. package/dist/botlit/pages/SettingsPage.js.map +1 -1
  58. package/dist/botlit/pages/SkillDetailPage.js +1 -1
  59. package/dist/botlit/pages/SkillDetailPage.js.map +1 -1
  60. package/dist/botlit/pages/StorePackageDetailPage.js +1 -1
  61. package/dist/botlit/pages/StorePackageDetailPage.js.map +1 -1
  62. package/dist/botlit/pages/StorePage.js +150 -143
  63. package/dist/botlit/pages/StorePage.js.map +1 -1
  64. package/dist/botlit/pages/index.d.ts +1 -2
  65. package/dist/generated/wspace-operations.js +67 -67
  66. package/dist/generated/wspace-operations.js.map +1 -1
  67. package/dist/index.js +5 -6
  68. package/package.json +1 -1
  69. package/dist/botlit/hooks/useConversations.d.ts +0 -42
  70. package/dist/botlit/hooks/useConversations.js +0 -63
  71. package/dist/botlit/hooks/useConversations.js.map +0 -1
  72. package/dist/botlit/pages/ConversationDetailPage.d.ts +0 -2
  73. package/dist/botlit/pages/ConversationsPage.d.ts +0 -2
@@ -1,19 +1,18 @@
1
1
  import { useBots as e } from "./useBots.js";
2
- import "./useAgents.js";
2
+ import { useAgents as t } from "./useAgents.js";
3
3
  import "./useKnowledgeBases.js";
4
- import { useRetrievalProfiles as t } from "./useRetrievalProfiles.js";
5
- import { isMCPServerHealthy as n, mcpServerDescription as r, mcpServerEndpoint as i, useCreateMCPServer as a, useDeleteMCPServer as o, useMCPResources as s, useMCPServer as c, useMCPTools as l, useTestMCPConnection as u, useUpdateMCPServer as d, useUpdateMCPTool as f } from "./useMCPServers.js";
6
- import { a2aAgentSkillCount as p, useA2AAgents as m } from "./useA2A.js";
7
- import { routeMetadataString as h, useBotChannelRoutes as g, useChannelConnector as _, useChannelConnectors as v, useChannelRoutes as y, useCreateChannelConnector as b, useCreateChannelRoute as x, useDeleteChannelConnector as S, useDeleteChannelRoute as C, useUpdateChannelConnector as w } from "./useChannels.js";
8
- import { useCreatePolicy as T, useDeletePolicy as E, usePolicies as D, usePolicy as O, useUpdatePolicy as k } from "./usePolicies.js";
9
- import { useApplyRetention as A, useRetentionStatus as j } from "./useRetention.js";
10
- import { useCreateSkill as M, useDeleteSkill as N, useSkill as P, useSkills as F, useUpdateSkill as I } from "./useSkills.js";
11
- import { promptTemplateVariables as L, useCreatePromptTemplate as R, useDeletePromptTemplate as z, usePromptTemplate as B, usePromptTemplates as V, useRenderPromptTemplate as H, useUpdatePromptTemplate as U } from "./usePromptTemplates.js";
12
- import { summariseExecutions as W, useExecutions as G } from "./useExecutions.js";
13
- import { useBucketTree as K, useBuckets as q, useCreateBucket as J, useDeleteBucket as Y, useUpdateBucket as X } from "./useBuckets.js";
14
- import { storePackageDescription as Z, storePackageName as Q, useInstallPackage as $, useInstalledPackages as ee, usePinPackageVersion as te, useStorePackage as ne, useStorePackages as re, useUninstallPackage as ie, useUpdateInstalledPackage as ae } from "./useStore.js";
15
- import "./useConversations.js";
4
+ import { useRetrievalProfiles as n } from "./useRetrievalProfiles.js";
5
+ import { isMCPServerHealthy as r, mcpServerDescription as i, mcpServerEndpoint as a, useCreateMCPServer as o, useDeleteMCPServer as s, useMCPResources as c, useMCPServer as l, useMCPTools as u, useTestMCPConnection as d, useUpdateMCPServer as f, useUpdateMCPTool as p } from "./useMCPServers.js";
6
+ import { a2aAgentSkillCount as m, useA2AAgents as h } from "./useA2A.js";
7
+ import { routeMetadataString as g, useBotChannelRoutes as _, useChannelConnector as v, useChannelConnectors as y, useChannelRoutes as b, useCreateChannelConnector as x, useCreateChannelRoute as S, useDeleteChannelConnector as C, useDeleteChannelRoute as w, useUpdateChannelConnector as T } from "./useChannels.js";
8
+ import { useCreatePolicy as E, useDeletePolicy as D, usePolicies as O, usePolicy as k, useUpdatePolicy as A } from "./usePolicies.js";
9
+ import { useApplyRetention as j, useRetentionStatus as M } from "./useRetention.js";
10
+ import { useCreateSkill as N, useDeleteSkill as P, useSkill as F, useSkills as I, useUpdateSkill as L } from "./useSkills.js";
11
+ import { promptTemplateVariables as R, useCreatePromptTemplate as z, useDeletePromptTemplate as B, usePromptTemplate as V, usePromptTemplates as H, useRenderPromptTemplate as U, useUpdatePromptTemplate as W } from "./usePromptTemplates.js";
12
+ import { summariseExecutions as G, useExecutions as K } from "./useExecutions.js";
13
+ import { useBucket as q, useBucketTree as J, useBuckets as Y, useChildBuckets as X, useCreateBucket as Z, useDeleteBucket as Q, useUpdateBucket as $ } from "./useBuckets.js";
14
+ import { storePackageDescription as ee, storePackageName as te, useInstallPackage as ne, useInstalledPackages as re, usePinPackageVersion as ie, useStorePackage as ae, useStorePackages as oe, useUninstallPackage as se, useUpdateInstalledPackage as ce } from "./useStore.js";
16
15
  import "./useLLMProviders.js";
17
- import { useInitiateSlackConnect as oe, useLinkIntegrationConnection as se, useMyUserPlatformConnection as ce, useRevokeSlackConnection as le, useToggleSlackNotifications as ue } from "./useUserPlatformConnection.js";
18
- import { useConfigureSupervisor as de, useRunSupervisorNow as fe, useSupervisorConfig as pe, useSupervisorRuns as me } from "./useAiOperations.js";
19
- export { p as a2aAgentSkillCount, n as isMCPServerHealthy, r as mcpServerDescription, i as mcpServerEndpoint, L as promptTemplateVariables, h as routeMetadataString, Z as storePackageDescription, Q as storePackageName, W as summariseExecutions, m as useA2AAgents, A as useApplyRetention, g as useBotChannelRoutes, e as useBots, K as useBucketTree, q as useBuckets, _ as useChannelConnector, v as useChannelConnectors, y as useChannelRoutes, de as useConfigureSupervisor, J as useCreateBucket, b as useCreateChannelConnector, x as useCreateChannelRoute, a as useCreateMCPServer, T as useCreatePolicy, R as useCreatePromptTemplate, M as useCreateSkill, Y as useDeleteBucket, S as useDeleteChannelConnector, C as useDeleteChannelRoute, o as useDeleteMCPServer, E as useDeletePolicy, z as useDeletePromptTemplate, N as useDeleteSkill, G as useExecutions, oe as useInitiateSlackConnect, $ as useInstallPackage, ee as useInstalledPackages, se as useLinkIntegrationConnection, s as useMCPResources, c as useMCPServer, l as useMCPTools, ce as useMyUserPlatformConnection, te as usePinPackageVersion, D as usePolicies, O as usePolicy, B as usePromptTemplate, V as usePromptTemplates, H as useRenderPromptTemplate, j as useRetentionStatus, t as useRetrievalProfiles, le as useRevokeSlackConnection, fe as useRunSupervisorNow, P as useSkill, F as useSkills, ne as useStorePackage, re as useStorePackages, pe as useSupervisorConfig, me as useSupervisorRuns, u as useTestMCPConnection, ue as useToggleSlackNotifications, ie as useUninstallPackage, X as useUpdateBucket, w as useUpdateChannelConnector, ae as useUpdateInstalledPackage, d as useUpdateMCPServer, f as useUpdateMCPTool, k as useUpdatePolicy, U as useUpdatePromptTemplate, I as useUpdateSkill };
16
+ import { useInitiateSlackConnect as le, useLinkIntegrationConnection as ue, useMyUserPlatformConnection as de, useRevokeSlackConnection as fe, useToggleSlackNotifications as pe } from "./useUserPlatformConnection.js";
17
+ import { useConfigureSupervisor as me, useRunSupervisorNow as he, useSupervisorConfig as ge, useSupervisorRuns as _e } from "./useAiOperations.js";
18
+ export { m as a2aAgentSkillCount, r as isMCPServerHealthy, i as mcpServerDescription, a as mcpServerEndpoint, R as promptTemplateVariables, g as routeMetadataString, ee as storePackageDescription, te as storePackageName, G as summariseExecutions, h as useA2AAgents, t as useAgents, j as useApplyRetention, _ as useBotChannelRoutes, e as useBots, q as useBucket, J as useBucketTree, Y as useBuckets, v as useChannelConnector, y as useChannelConnectors, b as useChannelRoutes, X as useChildBuckets, me as useConfigureSupervisor, Z as useCreateBucket, x as useCreateChannelConnector, S as useCreateChannelRoute, o as useCreateMCPServer, E as useCreatePolicy, z as useCreatePromptTemplate, N as useCreateSkill, Q as useDeleteBucket, C as useDeleteChannelConnector, w as useDeleteChannelRoute, s as useDeleteMCPServer, D as useDeletePolicy, B as useDeletePromptTemplate, P as useDeleteSkill, K as useExecutions, le as useInitiateSlackConnect, ne as useInstallPackage, re as useInstalledPackages, ue as useLinkIntegrationConnection, c as useMCPResources, l as useMCPServer, u as useMCPTools, de as useMyUserPlatformConnection, ie as usePinPackageVersion, O as usePolicies, k as usePolicy, V as usePromptTemplate, H as usePromptTemplates, U as useRenderPromptTemplate, M as useRetentionStatus, n as useRetrievalProfiles, fe as useRevokeSlackConnection, he as useRunSupervisorNow, F as useSkill, I as useSkills, ae as useStorePackage, oe as useStorePackages, ge as useSupervisorConfig, _e as useSupervisorRuns, d as useTestMCPConnection, pe as useToggleSlackNotifications, se as useUninstallPackage, $ as useUpdateBucket, T as useUpdateChannelConnector, ce as useUpdateInstalledPackage, f as useUpdateMCPServer, p as useUpdateMCPTool, A as useUpdatePolicy, W as useUpdatePromptTemplate, L as useUpdateSkill };
@@ -11,6 +11,21 @@ export interface QueryResult<T> {
11
11
  error: Error | undefined;
12
12
  refetch: () => Promise<void>;
13
13
  }
14
+ export interface PaginatedQueryResult<T> extends QueryResult<T> {
15
+ /** True while the next page is being appended. */
16
+ loadingMore: boolean;
17
+ /**
18
+ * True when the most recent page came back full, i.e. another page may
19
+ * exist. False before the first page resolves and once a short page
20
+ * (or an empty one) marks the end of the list.
21
+ */
22
+ hasMore: boolean;
23
+ /**
24
+ * Fetches the next page (current row count as offset) and appends it.
25
+ * No-op while a fetch is in flight or when `hasMore` is false.
26
+ */
27
+ loadMore: () => Promise<void>;
28
+ }
14
29
  export interface MutationState<T> {
15
30
  data: T | undefined;
16
31
  loading: boolean;
@@ -36,6 +51,38 @@ export interface WorkspaceQueryOptions<TData, TResult> {
36
51
  * collection apart from a failed request.
37
52
  */
38
53
  export declare function useWorkspaceQuery<TData, TResult>(options: WorkspaceQueryOptions<TData, TResult>): QueryResult<TResult>;
54
+ export interface WorkspacePaginatedQueryOptions<TData, TRow, TResult> {
55
+ /** Generated GraphQL document (see `src/generated/wspace-operations.ts`). */
56
+ document: DocumentNode;
57
+ /**
58
+ * Base variables (filters, ids, …) WITHOUT `pagination` — the hook adds
59
+ * `{ limit: pageSize, offset }` per fetch. Must be referentially stable;
60
+ * a new identity resets the accumulation back to page one.
61
+ */
62
+ variables: Record<string, unknown> | undefined;
63
+ /** Page size for each fetch. */
64
+ pageSize: number;
65
+ /** Extracts the raw row list from a page payload; missing data yields []. */
66
+ extractRows: (data: TData | undefined) => TRow[] | undefined;
67
+ /** Projects the ACCUMULATED raw rows onto the record shape the UI consumes. */
68
+ select: (rows: TRow[]) => TResult;
69
+ /** Value held while disabled or before the first successful read. */
70
+ fallback: TResult;
71
+ /** When false the request is skipped (e.g. no workspace id yet). */
72
+ enabled: boolean;
73
+ /** Used when the thrown value is not an Error. */
74
+ errorMessage: string;
75
+ }
76
+ /**
77
+ * Offset-paginated variant of `useWorkspaceQuery` for unbounded lists.
78
+ *
79
+ * `refetch()` restarts at offset 0 and REPLACES the accumulated rows;
80
+ * `loadMore()` fetches the next page and appends it. A page that returns
81
+ * fewer rows than `pageSize` marks the list exhausted (`hasMore` false).
82
+ * `select` runs over the accumulated raw rows, so client-side narrowing
83
+ * (e.g. executions search) sees every loaded page, not just the last one.
84
+ */
85
+ export declare function useWorkspacePaginatedQuery<TData, TRow, TResult>(options: WorkspacePaginatedQueryOptions<TData, TRow, TResult>): PaginatedQueryResult<TResult>;
39
86
  export interface WorkspaceMutationOptions<TData, TInput, TResult> {
40
87
  /** Generated GraphQL document (see `src/generated/wspace-operations.ts`). */
41
88
  document: DocumentNode;
@@ -57,6 +57,64 @@ function f(e) {
57
57
  };
58
58
  }
59
59
  function p(e) {
60
+ let { document: t, variables: i, pageSize: s, enabled: l, errorMessage: f } = e, p = c(), m = d(e.select), h = d(e.extractRows), [g, _] = o([]), v = a([]), [y, b] = o(e.fallback), [x, S] = o(!1), [C, w] = o(!1), [T, E] = o(!0), [D, O] = o(), k = n((e) => {
61
+ v.current = e, _(e), b(m.current(e));
62
+ }, [m]), A = n(async (e, n) => {
63
+ n ? w(!0) : S(!0), O(void 0);
64
+ try {
65
+ let r = await p.query({
66
+ query: t,
67
+ variables: {
68
+ ...i,
69
+ pagination: {
70
+ limit: s,
71
+ offset: e
72
+ }
73
+ },
74
+ fetchPolicy: "network-only"
75
+ }), a = r.error;
76
+ if (a != null) throw u(a, f);
77
+ let o = h.current(r.data ?? void 0) ?? [];
78
+ k(n ? [...v.current, ...o] : o), E(o.length < s);
79
+ } catch (e) {
80
+ O(u(e, f));
81
+ } finally {
82
+ n ? w(!1) : S(!1);
83
+ }
84
+ }, [
85
+ p,
86
+ t,
87
+ i,
88
+ s,
89
+ f,
90
+ h,
91
+ k
92
+ ]), j = n(async () => {
93
+ l ? await A(0, !1) : (k([]), E(!0), O(void 0));
94
+ }, [
95
+ l,
96
+ A,
97
+ k
98
+ ]), M = n(async () => {
99
+ l && !T && await A(v.current.length, !0);
100
+ }, [
101
+ l,
102
+ T,
103
+ A
104
+ ]);
105
+ return r(() => {
106
+ j();
107
+ }, [j]), {
108
+ data: y,
109
+ loading: x,
110
+ loadingMore: C,
111
+ hasMore: !T,
112
+ error: D,
113
+ refetch: j,
114
+ loadMore: M
115
+ };
116
+ }
117
+ function m(e) {
60
118
  let { document: t, errorMessage: r } = e, i = c(), a = d(e.variables), s = d(e.select), [l, f] = o({
61
119
  data: void 0,
62
120
  loading: !1,
@@ -97,6 +155,6 @@ function p(e) {
97
155
  a
98
156
  ]), l];
99
157
  }
100
- export { c as useWorkspaceClient, l as useWorkspaceId, p as useWorkspaceMutation, f as useWorkspaceQuery };
158
+ export { c as useWorkspaceClient, l as useWorkspaceId, m as useWorkspaceMutation, p as useWorkspacePaginatedQuery, f as useWorkspaceQuery };
101
159
 
102
160
  //# sourceMappingURL=workspaceGateway.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"workspaceGateway.js","names":["useWorkspaceClient","useGatewayClient","useWorkspaceId","useBotlit","toError","message","extractGraphqlFailureMessage","cause","fallbackMessage","useLatest","ref","useRef","value","useLayoutEffect","useWorkspaceQuery","options","client","selectRef","fallbackRef","data","setData","useState","loading","setLoading","error","setError","refetch","useCallback","enabled","result","document","operationError","errorMessage","queryError","variables","useEffect","useWorkspaceMutation","variablesRef","state","setState","input","selected","mutationError","failure"],"sources":["../../../../src/botlit/hooks/internal/workspaceGateway.ts"],"sourcesContent":["/**\n * Workspace gateway hook primitives\n * @module botlit/hooks/internal\n *\n * Every BotManor hook talks to the workspace public gateway through the Apollo\n * client the shell installs (`useGatewayClient('workspace')`) — never through a\n * client of its own. These primitives capture the exact shape used by the\n * reference hooks (`useAgents`, `useBots`): `network-only` reads, an explicit\n * `Error` in state rather than a thrown promise, and a `refetch` the caller can\n * run after a mutation.\n */\n\nimport type { ApolloClient, DocumentNode } from '@apollo/client';\nimport { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';\nimport { useGatewayClient } from '@burdenoff/fe-libs/shared/graphql';\n\nimport { useBotlit } from '../../providers/BotlitProvider';\nimport { extractGraphqlFailureMessage } from '../../utils/errors';\n\nexport type WorkspaceClient = ApolloClient;\n\n/** Apollo client for the workspace gateway, provided by the host shell. */\nexport function useWorkspaceClient(): WorkspaceClient {\n return useGatewayClient('workspace');\n}\n\n/** Current workspace id from the BotManor context (undefined until the shell resolves it). */\nexport function useWorkspaceId(): string | undefined {\n return useBotlit().workspaceId;\n}\n\nexport interface QueryResult<T> {\n data: T;\n loading: boolean;\n /** Set only when the request FAILED. An empty `data` with no `error` means \"no records yet\". */\n error: Error | undefined;\n refetch: () => Promise<void>;\n}\n\nexport interface MutationState<T> {\n data: T | undefined;\n loading: boolean;\n error: Error | undefined;\n}\n\n/**\n * Normalises any mutation failure to an Error with the server's\n * user-actionable message where one exists.\n *\n * Apollo Client v4 does not reject with a plain Error: failures arrive as\n * `{ networkError }` / `{ graphQLErrors }` objects, and the batched fetch\n * layer attaches the structured GraphQL errors as `.errors` on the\n * networkError. `extractGraphqlFailureMessage` unwraps all of those; only\n * when nothing user-actionable is present do we fall back to the hook's\n * generic `errorMessage`.\n */\nfunction toError(cause: unknown, fallbackMessage: string): Error {\n const message = extractGraphqlFailureMessage(cause);\n if (message) {\n // Preserve the original rejection on the chain so error monitoring can\n // still reach the structured GraphQL errors (extensions.code, requestId…).\n return new Error(message, { cause });\n }\n if (cause instanceof Error) return cause;\n return new Error(fallbackMessage, { cause });\n}\n\n/** Keeps a mutable ref pointing at the latest value without re-running effects. */\nfunction useLatest<T>(value: T): { readonly current: T } {\n const ref = useRef(value);\n useLayoutEffect(() => {\n ref.current = value;\n }, [value]);\n return ref;\n}\n\nexport interface WorkspaceQueryOptions<TData, TResult> {\n /** Generated GraphQL document (see `src/generated/wspace-operations.ts`). */\n document: DocumentNode;\n /** Must be referentially stable — memoize at the call site. */\n variables: Record<string, unknown> | undefined;\n /** Projects the raw payload onto the record shape the UI consumes. */\n select: (data: TData | undefined) => TResult;\n /** Value held while disabled or before the first successful read. */\n fallback: TResult;\n /** When false the request is skipped (e.g. no workspace id / no entity id yet). */\n enabled: boolean;\n /** Used when the thrown value is not an Error. */\n errorMessage: string;\n}\n\n/**\n * Reads from the workspace gateway and keeps `{ data, loading, error, refetch }`\n * in sync. `error` is reserved for real failures so callers can tell an empty\n * collection apart from a failed request.\n */\nexport function useWorkspaceQuery<TData, TResult>(\n options: WorkspaceQueryOptions<TData, TResult>\n): QueryResult<TResult> {\n const { document, variables, enabled, errorMessage } = options;\n const client = useWorkspaceClient();\n const selectRef = useLatest(options.select);\n const fallbackRef = useLatest(options.fallback);\n\n const [data, setData] = useState<TResult>(options.fallback);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n\n const refetch = useCallback(async () => {\n if (!enabled) {\n setData(fallbackRef.current);\n setError(undefined);\n return;\n }\n\n setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<TData>({\n query: document,\n variables,\n fetchPolicy: 'network-only',\n });\n // Apollo v4 resolves (not rejects) with `result.error` set on GraphQL\n // errors — same handling as useWorkspaceMutation.\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw toError(operationError, errorMessage);\n }\n setData(selectRef.current(result.data ?? undefined));\n } catch (queryError) {\n setData(fallbackRef.current);\n setError(toError(queryError, errorMessage));\n } finally {\n setLoading(false);\n }\n // fallbackRef/selectRef are stable refs by construction\n }, [client, document, variables, enabled, errorMessage, fallbackRef, selectRef]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\nexport interface WorkspaceMutationOptions<TData, TInput, TResult> {\n /** Generated GraphQL document (see `src/generated/wspace-operations.ts`). */\n document: DocumentNode;\n /** Maps the caller's input onto GraphQL variables. */\n variables: (input: TInput) => Record<string, unknown>;\n /** Projects the raw payload onto the record shape the UI consumes. */\n select: (data: TData | undefined) => TResult | undefined;\n /** Thrown (and stored) when the payload is missing or the request fails. */\n errorMessage: string;\n}\n\n/**\n * Writes to the workspace gateway. Returns the `[mutate, state]` tuple used by\n * the reference hooks. `mutate` REJECTS on failure so callers cannot mistake a\n * failed write for a successful one.\n */\nexport function useWorkspaceMutation<TData, TInput, TResult>(\n options: WorkspaceMutationOptions<TData, TInput, TResult>\n): readonly [(input: TInput) => Promise<TResult>, MutationState<TResult>] {\n const { document, errorMessage } = options;\n const client = useWorkspaceClient();\n const variablesRef = useLatest(options.variables);\n const selectRef = useLatest(options.select);\n\n const [state, setState] = useState<MutationState<TResult>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const mutate = useCallback(\n async (input: TInput): Promise<TResult> => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<TData>({\n mutation: document,\n variables: variablesRef.current(input),\n });\n // Apollo v4 does not reject on GraphQL errors by default: the mutation\n // RESOLVES with `data` undefined and the failure on `result.error`\n // (CombinedGraphQLErrors / networkError). Surface it like a rejection\n // so callers see the server's field-level message, not the fallback.\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw toError(operationError, errorMessage);\n }\n const selected = selectRef.current(result.data ?? undefined);\n if (selected === undefined) {\n throw new Error(errorMessage);\n }\n setState({ data: selected, loading: false, error: undefined });\n return selected;\n } catch (mutationError) {\n const failure = toError(mutationError, errorMessage);\n setState({ data: undefined, loading: false, error: failure });\n throw failure;\n }\n },\n [client, document, errorMessage, selectRef, variablesRef]\n );\n\n return [mutate, state] as const;\n}\n"],"mappings":";;;;;AAsBA,SAAgBA,IAAsC;CACpD,OAAOC,EAAiB,WAAW;AACrC;AAGA,SAAgBC,IAAqC;CACnD,OAAOC,EAAU,CAAC,CAAC;AACrB;AA2BA,SAASC,EAAQ,GAAgB,GAAgC;CAC/D,IAAMC,IAAUC,EAA6BC,CAAK;CAOlD,OANIF,IAGS,MAAMA,GAAS,EAAE,SAAM,CAAC,IAEjCE,aAAiB,QAAcA,IACxB,MAAMC,GAAiB,EAAE,SAAM,CAAC;AAC7C;AAGA,SAASC,EAA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AQ,SAAS,GAC1CE,IAAYR,EAAUM,EAAQ,MAAM,GAEpC,CAACuB,GAAOC,KAAYlB,EAAiC;EACzD,MAAM,KAAA;EACN,SAAS;EACT,OAAO,KAAA;CACT,CAAC;CAiCD,OAAO,CA/BQM,EACb,OAAO,MAAoC;EACzC,EAAS;GAAE,MAAM,KAAA;GAAW,SAAS;GAAM,OAAO,KAAA;EAAU,CAAC;EAC7D,IAAI;GACF,IAAME,IAAS,MAAMb,EAAO,OAAc;IACxC,UAAUc;IACV,WAAWO,EAAa,QAAQG,CAAK;GACvC,CAAC,GAKKT,IAAkBF,EAA+B;GACvD,IAAIE,KAAkB,MACpB,MAAM3B,EAAQ2B,GAAgBC,CAAY;GAE5C,IAAMS,IAAWxB,EAAU,QAAQY,EAAO,QAAQ,KAAA,CAAS;GAC3D,IAAIY,MAAa,KAAA,GACf,MAAU,MAAMT,CAAY;GAG9B,OADAO,EAAS;IAAE,MAAME;IAAU,SAAS;IAAO,OAAO,KAAA;GAAU,CAAC,GACtDA;EACT,SAASC,GAAe;GACtB,IAAMC,IAAUvC,EAAQsC,GAAeV,CAAY;GAEnD,MADAO,EAAS;IAAE,MAAM,KAAA;IAAW,SAAS;IAAO,OAAOI;GAAQ,CAAC,GACtDA;EACR;CACF,GACA;EAAC3B;EAAQc;EAAUE;EAAcf;EAAWoB;CAAY,CAGlD,GAAQC,CAAK;AACvB"}
1
+ {"version":3,"file":"workspaceGateway.js","names":["useWorkspaceClient","useGatewayClient","useWorkspaceId","useBotlit","toError","message","extractGraphqlFailureMessage","cause","fallbackMessage","useLatest","ref","useRef","value","useLayoutEffect","useWorkspaceQuery","options","client","selectRef","fallbackRef","data","setData","useState","loading","setLoading","error","setError","refetch","useCallback","enabled","result","document","operationError","errorMessage","queryError","variables","useEffect","useWorkspacePaginatedQuery","extractRowsRef","rows","setRows","rowsRef","loadingMore","setLoadingMore","exhausted","setExhausted","replaceRows","next","fetchPage","append","pageSize","pageRows","loadMore","useWorkspaceMutation","variablesRef","state","setState","input","selected","mutationError","failure"],"sources":["../../../../src/botlit/hooks/internal/workspaceGateway.ts"],"sourcesContent":["/**\n * Workspace gateway hook primitives\n * @module botlit/hooks/internal\n *\n * Every BotManor hook talks to the workspace public gateway through the Apollo\n * client the shell installs (`useGatewayClient('workspace')`) — never through a\n * client of its own. These primitives capture the exact shape used by the\n * reference hooks (`useAgents`, `useBots`): `network-only` reads, an explicit\n * `Error` in state rather than a thrown promise, and a `refetch` the caller can\n * run after a mutation.\n */\n\nimport type { ApolloClient, DocumentNode } from '@apollo/client';\nimport { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';\nimport { useGatewayClient } from '@burdenoff/fe-libs/shared/graphql';\n\nimport { useBotlit } from '../../providers/BotlitProvider';\nimport { extractGraphqlFailureMessage } from '../../utils/errors';\n\nexport type WorkspaceClient = ApolloClient;\n\n/** Apollo client for the workspace gateway, provided by the host shell. */\nexport function useWorkspaceClient(): WorkspaceClient {\n return useGatewayClient('workspace');\n}\n\n/** Current workspace id from the BotManor context (undefined until the shell resolves it). */\nexport function useWorkspaceId(): string | undefined {\n return useBotlit().workspaceId;\n}\n\nexport interface QueryResult<T> {\n data: T;\n loading: boolean;\n /** Set only when the request FAILED. An empty `data` with no `error` means \"no records yet\". */\n error: Error | undefined;\n refetch: () => Promise<void>;\n}\n\nexport interface PaginatedQueryResult<T> extends QueryResult<T> {\n /** True while the next page is being appended. */\n loadingMore: boolean;\n /**\n * True when the most recent page came back full, i.e. another page may\n * exist. False before the first page resolves and once a short page\n * (or an empty one) marks the end of the list.\n */\n hasMore: boolean;\n /**\n * Fetches the next page (current row count as offset) and appends it.\n * No-op while a fetch is in flight or when `hasMore` is false.\n */\n loadMore: () => Promise<void>;\n}\n\nexport interface MutationState<T> {\n data: T | undefined;\n loading: boolean;\n error: Error | undefined;\n}\n\n/**\n * Normalises any mutation failure to an Error with the server's\n * user-actionable message where one exists.\n *\n * Apollo Client v4 does not reject with a plain Error: failures arrive as\n * `{ networkError }` / `{ graphQLErrors }` objects, and the batched fetch\n * layer attaches the structured GraphQL errors as `.errors` on the\n * networkError. `extractGraphqlFailureMessage` unwraps all of those; only\n * when nothing user-actionable is present do we fall back to the hook's\n * generic `errorMessage`.\n */\nfunction toError(cause: unknown, fallbackMessage: string): Error {\n const message = extractGraphqlFailureMessage(cause);\n if (message) {\n // Preserve the original rejection on the chain so error monitoring can\n // still reach the structured GraphQL errors (extensions.code, requestId…).\n return new Error(message, { cause });\n }\n if (cause instanceof Error) return cause;\n return new Error(fallbackMessage, { cause });\n}\n\n/** Keeps a mutable ref pointing at the latest value without re-running effects. */\nfunction useLatest<T>(value: T): { readonly current: T } {\n const ref = useRef(value);\n useLayoutEffect(() => {\n ref.current = value;\n }, [value]);\n return ref;\n}\n\nexport interface WorkspaceQueryOptions<TData, TResult> {\n /** Generated GraphQL document (see `src/generated/wspace-operations.ts`). */\n document: DocumentNode;\n /** Must be referentially stable — memoize at the call site. */\n variables: Record<string, unknown> | undefined;\n /** Projects the raw payload onto the record shape the UI consumes. */\n select: (data: TData | undefined) => TResult;\n /** Value held while disabled or before the first successful read. */\n fallback: TResult;\n /** When false the request is skipped (e.g. no workspace id / no entity id yet). */\n enabled: boolean;\n /** Used when the thrown value is not an Error. */\n errorMessage: string;\n}\n\n/**\n * Reads from the workspace gateway and keeps `{ data, loading, error, refetch }`\n * in sync. `error` is reserved for real failures so callers can tell an empty\n * collection apart from a failed request.\n */\nexport function useWorkspaceQuery<TData, TResult>(\n options: WorkspaceQueryOptions<TData, TResult>\n): QueryResult<TResult> {\n const { document, variables, enabled, errorMessage } = options;\n const client = useWorkspaceClient();\n const selectRef = useLatest(options.select);\n const fallbackRef = useLatest(options.fallback);\n\n const [data, setData] = useState<TResult>(options.fallback);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n\n const refetch = useCallback(async () => {\n if (!enabled) {\n setData(fallbackRef.current);\n setError(undefined);\n return;\n }\n\n setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<TData>({\n query: document,\n variables,\n fetchPolicy: 'network-only',\n });\n // Apollo v4 resolves (not rejects) with `result.error` set on GraphQL\n // errors — same handling as useWorkspaceMutation.\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw toError(operationError, errorMessage);\n }\n setData(selectRef.current(result.data ?? undefined));\n } catch (queryError) {\n setData(fallbackRef.current);\n setError(toError(queryError, errorMessage));\n } finally {\n setLoading(false);\n }\n // fallbackRef/selectRef are stable refs by construction\n }, [client, document, variables, enabled, errorMessage, fallbackRef, selectRef]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\nexport interface WorkspacePaginatedQueryOptions<TData, TRow, TResult> {\n /** Generated GraphQL document (see `src/generated/wspace-operations.ts`). */\n document: DocumentNode;\n /**\n * Base variables (filters, ids, …) WITHOUT `pagination` — the hook adds\n * `{ limit: pageSize, offset }` per fetch. Must be referentially stable;\n * a new identity resets the accumulation back to page one.\n */\n variables: Record<string, unknown> | undefined;\n /** Page size for each fetch. */\n pageSize: number;\n /** Extracts the raw row list from a page payload; missing data yields []. */\n extractRows: (data: TData | undefined) => TRow[] | undefined;\n /** Projects the ACCUMULATED raw rows onto the record shape the UI consumes. */\n select: (rows: TRow[]) => TResult;\n /** Value held while disabled or before the first successful read. */\n fallback: TResult;\n /** When false the request is skipped (e.g. no workspace id yet). */\n enabled: boolean;\n /** Used when the thrown value is not an Error. */\n errorMessage: string;\n}\n\n/**\n * Offset-paginated variant of `useWorkspaceQuery` for unbounded lists.\n *\n * `refetch()` restarts at offset 0 and REPLACES the accumulated rows;\n * `loadMore()` fetches the next page and appends it. A page that returns\n * fewer rows than `pageSize` marks the list exhausted (`hasMore` false).\n * `select` runs over the accumulated raw rows, so client-side narrowing\n * (e.g. executions search) sees every loaded page, not just the last one.\n */\nexport function useWorkspacePaginatedQuery<TData, TRow, TResult>(\n options: WorkspacePaginatedQueryOptions<TData, TRow, TResult>\n): PaginatedQueryResult<TResult> {\n const { document, variables, pageSize, enabled, errorMessage } = options;\n const client = useWorkspaceClient();\n const selectRef = useLatest(options.select);\n const extractRowsRef = useLatest(options.extractRows);\n\n const [rows, setRows] = useState<TRow[]>([]);\n const rowsRef = useRef<TRow[]>([]);\n const [data, setData] = useState<TResult>(options.fallback);\n const [loading, setLoading] = useState(false);\n const [loadingMore, setLoadingMore] = useState(false);\n const [exhausted, setExhausted] = useState(true);\n const [error, setError] = useState<Error | undefined>();\n\n const replaceRows = useCallback(\n (next: TRow[]) => {\n rowsRef.current = next;\n setRows(next);\n setData(selectRef.current(next));\n },\n [selectRef]\n );\n\n const fetchPage = useCallback(\n async (offset: number, append: boolean) => {\n if (append) setLoadingMore(true);\n else setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<TData>({\n query: document,\n variables: { ...variables, pagination: { limit: pageSize, offset } },\n fetchPolicy: 'network-only',\n });\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw toError(operationError, errorMessage);\n }\n const pageRows = extractRowsRef.current(result.data ?? undefined) ?? [];\n replaceRows(append ? [...rowsRef.current, ...pageRows] : pageRows);\n setExhausted(pageRows.length < pageSize);\n } catch (queryError) {\n setError(toError(queryError, errorMessage));\n } finally {\n if (append) setLoadingMore(false);\n else setLoading(false);\n }\n },\n [client, document, variables, pageSize, errorMessage, extractRowsRef, replaceRows]\n );\n\n const refetch = useCallback(async () => {\n if (!enabled) {\n replaceRows([]);\n setExhausted(true);\n setError(undefined);\n return;\n }\n await fetchPage(0, false);\n }, [enabled, fetchPage, replaceRows]);\n\n const loadMore = useCallback(async () => {\n if (!enabled || exhausted) return;\n await fetchPage(rowsRef.current.length, true);\n }, [enabled, exhausted, fetchPage]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, loadingMore, hasMore: !exhausted, error, refetch, loadMore };\n}\n\nexport interface WorkspaceMutationOptions<TData, TInput, TResult> {\n /** Generated GraphQL document (see `src/generated/wspace-operations.ts`). */\n document: DocumentNode;\n /** Maps the caller's input onto GraphQL variables. */\n variables: (input: TInput) => Record<string, unknown>;\n /** Projects the raw payload onto the record shape the UI consumes. */\n select: (data: TData | undefined) => TResult | undefined;\n /** Thrown (and stored) when the payload is missing or the request fails. */\n errorMessage: string;\n}\n\n/**\n * Writes to the workspace gateway. Returns the `[mutate, state]` tuple used by\n * the reference hooks. `mutate` REJECTS on failure so callers cannot mistake a\n * failed write for a successful one.\n */\nexport function useWorkspaceMutation<TData, TInput, TResult>(\n options: WorkspaceMutationOptions<TData, TInput, TResult>\n): readonly [(input: TInput) => Promise<TResult>, MutationState<TResult>] {\n const { document, errorMessage } = options;\n const client = useWorkspaceClient();\n const variablesRef = useLatest(options.variables);\n const selectRef = useLatest(options.select);\n\n const [state, setState] = useState<MutationState<TResult>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const mutate = useCallback(\n async (input: TInput): Promise<TResult> => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<TData>({\n mutation: document,\n variables: variablesRef.current(input),\n });\n // Apollo v4 does not reject on GraphQL errors by default: the mutation\n // RESOLVES with `data` undefined and the failure on `result.error`\n // (CombinedGraphQLErrors / networkError). Surface it like a rejection\n // so callers see the server's field-level message, not the fallback.\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw toError(operationError, errorMessage);\n }\n const selected = selectRef.current(result.data ?? undefined);\n if (selected === undefined) {\n throw new Error(errorMessage);\n }\n setState({ data: selected, loading: false, error: undefined });\n return selected;\n } catch (mutationError) {\n const failure = toError(mutationError, errorMessage);\n setState({ data: undefined, loading: false, error: failure });\n throw failure;\n }\n },\n [client, document, errorMessage, selectRef, variablesRef]\n );\n\n return [mutate, state] as const;\n}\n"],"mappings":";;;;;AAsBA,SAAgBA,IAAsC;CACpD,OAAOC,EAAiB,WAAW;AACrC;AAGA,SAAgBC,IAAqC;CACnD,OAAOC,EAAU,CAAC,CAAC;AACrB;AA2CA,SAASC,EAAQ,GAAgB,GAAgC;CAC/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AE5C,IAAMyB,IAAWxC,EAAU,QAAQY,EAAO,QAAQ,KAAA,CAAS;GAC3D,IAAI4B,MAAa,KAAA,GACf,MAAU,MAAMzB,CAAY;GAG9B,OADAuB,EAAS;IAAE,MAAME;IAAU,SAAS;IAAO,OAAO,KAAA;GAAU,CAAC,GACtDA;EACT,SAASC,GAAe;GACtB,IAAMC,IAAUvD,EAAQsD,GAAe1B,CAAY;GAEnD,MADAuB,EAAS;IAAE,MAAM,KAAA;IAAW,SAAS;IAAO,OAAOI;GAAQ,CAAC,GACtDA;EACR;CACF,GACA;EAAC3C;EAAQc;EAAUE;EAAcf;EAAWoC;CAAY,CAGlD,GAAQC,CAAK;AACvB"}
@@ -1,6 +1,7 @@
1
1
  import { UpdateBotmanorAgentInput } from '../../generated/wspace-types';
2
2
  import { BaseFilter } from '../types';
3
3
  import { GraphQLInput } from './internal/mutationInput';
4
+ import { PaginatedQueryResult } from './internal/workspaceGateway';
4
5
  export interface AgentRecord {
5
6
  id: string;
6
7
  name: string;
@@ -72,12 +73,7 @@ export declare const agentKeys: {
72
73
  details: () => readonly ["agents", "detail"];
73
74
  detail: (id: string) => readonly ["agents", "detail", string];
74
75
  };
75
- export declare function useAgents(filter?: BaseFilter): {
76
- data: AgentRecord[];
77
- loading: boolean;
78
- error: Error | undefined;
79
- refetch: () => Promise<void>;
80
- };
76
+ export declare function useAgents(filter?: BaseFilter): PaginatedQueryResult<AgentRecord[]>;
81
77
  export declare function useAgent(agentId: string | undefined): {
82
78
  data: AgentRecord | null;
83
79
  loading: boolean;
@@ -1,10 +1,11 @@
1
1
  import { useBotlit as e } from "../providers/BotlitProvider.js";
2
2
  import { buildMutationInput as t, fieldsOf as n } from "./internal/mutationInput.js";
3
- import { useCallback as r, useEffect as i, useMemo as a, useState as o } from "react";
4
- import { gql as s } from "@apollo/client";
5
- import { useGatewayClient as c } from "@burdenoff/fe-libs/shared/graphql";
3
+ import { useWorkspacePaginatedQuery as r } from "./internal/workspaceGateway.js";
4
+ import { useCallback as i, useEffect as a, useMemo as o, useState as s } from "react";
5
+ import { gql as c } from "@apollo/client";
6
+ import { useGatewayClient as l } from "@burdenoff/fe-libs/shared/graphql";
6
7
  // src/botlit/hooks/useAgents.ts
7
- var l = s`
8
+ var u = c`
8
9
  query ListBotmanorAgents($filters: BotmanorAgentFilterInput, $pagination: PaginationInput) {
9
10
  listBotmanorAgents(filters: $filters, pagination: $pagination) {
10
11
  id
@@ -28,7 +29,7 @@ var l = s`
28
29
  workspaceId
29
30
  }
30
31
  }
31
- `, u = s`
32
+ `, d = c`
32
33
  query GetBotmanorAgent($id: ID!) {
33
34
  getBotmanorAgent(id: $id) {
34
35
  id
@@ -62,7 +63,7 @@ var l = s`
62
63
  workspaceId
63
64
  }
64
65
  }
65
- `, d = s`
66
+ `, f = c`
66
67
  mutation CreateBotmanorAgent($input: CreateBotmanorAgentInput!) {
67
68
  createBotmanorAgent(input: $input) {
68
69
  id
@@ -84,7 +85,7 @@ var l = s`
84
85
  workspaceId
85
86
  }
86
87
  }
87
- `, f = s`
88
+ `, p = c`
88
89
  mutation UpdateBotmanorAgent($id: ID!, $input: UpdateBotmanorAgentInput!) {
89
90
  updateBotmanorAgent(id: $id, input: $input) {
90
91
  id
@@ -111,11 +112,11 @@ var l = s`
111
112
  workspaceId
112
113
  }
113
114
  }
114
- `, p = s`
115
+ `, m = c`
115
116
  mutation DeleteBotmanorAgent($id: ID!) {
116
117
  deleteBotmanorAgent(id: $id)
117
118
  }
118
- `, m = s`
119
+ `, h = c`
119
120
  query ListAgentVersions($agentId: ID!, $pagination: PaginationInput) {
120
121
  listAgentVersions(agentId: $agentId, pagination: $pagination) {
121
122
  id
@@ -130,7 +131,7 @@ var l = s`
130
131
  publishedAt
131
132
  }
132
133
  }
133
- `, h = s`
134
+ `, g = c`
134
135
  mutation PublishAgentVersion($agentId: ID!, $versionId: ID!, $changelog: String) {
135
136
  publishAgentVersion(agentId: $agentId, versionId: $versionId, changelog: $changelog) {
136
137
  id
@@ -142,7 +143,7 @@ var l = s`
142
143
  publishedAt
143
144
  }
144
145
  }
145
- `, g = s`
146
+ `, _ = c`
146
147
  mutation RollbackAgentVersion($agentId: ID!, $targetVersionId: ID!) {
147
148
  rollbackAgentVersion(agentId: $agentId, targetVersionId: $targetVersionId) {
148
149
  id
@@ -154,7 +155,7 @@ var l = s`
154
155
  publishedAt
155
156
  }
156
157
  }
157
- `, _ = n({
158
+ `, v = 100, y = [], b = n({
158
159
  bucketId: !0,
159
160
  capabilities: !0,
160
161
  context: !0,
@@ -177,10 +178,10 @@ var l = s`
177
178
  visibility: !0,
178
179
  workflowIds: !0
179
180
  });
180
- function v(e) {
181
+ function x(e) {
181
182
  return e;
182
183
  }
183
- function y(e, t) {
184
+ function S(e, t) {
184
185
  if (e || t) return {
185
186
  workspaceId: e,
186
187
  search: t?.search,
@@ -189,79 +190,54 @@ function y(e, t) {
189
190
  bucketId: t?.bucketId
190
191
  };
191
192
  }
192
- function b(t) {
193
- let n = v(c("workspace")), { workspaceId: s } = e(), [u, d] = o([]), [f, p] = o(!1), [m, h] = o(), g = a(() => ({
194
- filters: y(s, t),
195
- pagination: {
196
- limit: 100,
197
- offset: 0
198
- }
199
- }), [t, s]), _ = r(async () => {
200
- if (!s) d([]);
201
- else {
202
- p(!0), h(void 0);
203
- try {
204
- let e = await n.query({
205
- query: l,
206
- variables: g,
207
- fetchPolicy: "network-only"
208
- });
209
- d(e.data?.listBotmanorAgents ?? []);
210
- } catch (e) {
211
- h(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load agents"));
212
- } finally {
213
- p(!1);
214
- }
215
- }
216
- }, [
217
- n,
218
- g,
219
- s
220
- ]);
221
- return i(() => {
222
- _();
223
- }, [_]), {
224
- data: u,
225
- loading: f,
226
- error: m,
227
- refetch: _
228
- };
193
+ function C(t) {
194
+ let { workspaceId: n } = e(), i = o(() => ({ filters: S(n, t) }), [t, n]);
195
+ return r({
196
+ document: u,
197
+ variables: i,
198
+ pageSize: v,
199
+ extractRows: (e) => e?.listBotmanorAgents ?? [],
200
+ select: (e) => e,
201
+ fallback: y,
202
+ enabled: !!n,
203
+ errorMessage: "Failed to load agents"
204
+ });
229
205
  }
230
- function x(e) {
231
- let t = v(c("workspace")), [n, a] = o(null), [s, l] = o(!1), [d, f] = o(), p = r(async () => {
232
- if (!e) a(null);
206
+ function w(e) {
207
+ let t = x(l("workspace")), [n, r] = s(null), [o, c] = s(!1), [u, f] = s(), p = i(async () => {
208
+ if (!e) r(null);
233
209
  else {
234
- l(!0), f(void 0);
210
+ c(!0), f(void 0);
235
211
  try {
236
212
  let n = await t.query({
237
- query: u,
213
+ query: d,
238
214
  variables: { id: e },
239
215
  fetchPolicy: "network-only"
240
216
  });
241
- a(n.data?.getBotmanorAgent ?? null);
217
+ r(n.data?.getBotmanorAgent ?? null);
242
218
  } catch (e) {
243
219
  f(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load agent"));
244
220
  } finally {
245
- l(!1);
221
+ c(!1);
246
222
  }
247
223
  }
248
224
  }, [e, t]);
249
- return i(() => {
225
+ return a(() => {
250
226
  p();
251
227
  }, [p]), {
252
228
  data: n,
253
- loading: s,
254
- error: d,
229
+ loading: o,
230
+ error: u,
255
231
  refetch: p
256
232
  };
257
233
  }
258
- function S() {
259
- let e = v(c("workspace")), [t, n] = o({
234
+ function T() {
235
+ let e = x(l("workspace")), [t, n] = s({
260
236
  data: void 0,
261
237
  loading: !1,
262
238
  error: void 0
263
239
  });
264
- return [r(async (t) => {
240
+ return [i(async (t) => {
265
241
  n({
266
242
  data: void 0,
267
243
  loading: !0,
@@ -269,7 +245,7 @@ function S() {
269
245
  });
270
246
  try {
271
247
  let r = (await e.mutate({
272
- mutation: d,
248
+ mutation: f,
273
249
  variables: { input: t }
274
250
  })).data?.createBotmanorAgent;
275
251
  if (!r) throw Error("Failed to create agent");
@@ -288,35 +264,35 @@ function S() {
288
264
  }
289
265
  }, [e]), t];
290
266
  }
291
- function C() {
292
- let e = v(c("workspace")), [n, i] = o({
267
+ function E() {
268
+ let e = x(l("workspace")), [n, r] = s({
293
269
  data: void 0,
294
270
  loading: !1,
295
271
  error: void 0
296
272
  });
297
- return [r(async ({ agentId: n, input: r }) => {
298
- i({
273
+ return [i(async ({ agentId: n, input: i }) => {
274
+ r({
299
275
  data: void 0,
300
276
  loading: !0,
301
277
  error: void 0
302
278
  });
303
279
  try {
304
280
  let a = (await e.mutate({
305
- mutation: f,
281
+ mutation: p,
306
282
  variables: {
307
283
  id: n,
308
- input: t(r, _)
284
+ input: t(i, b)
309
285
  }
310
286
  })).data?.updateBotmanorAgent;
311
287
  if (!a) throw Error("Failed to update agent");
312
- return i({
288
+ return r({
313
289
  data: a,
314
290
  loading: !1,
315
291
  error: void 0
316
292
  }), a;
317
293
  } catch (e) {
318
294
  let t = e instanceof Error ? e : /* @__PURE__ */ Error("Failed to update agent");
319
- throw i({
295
+ throw r({
320
296
  data: void 0,
321
297
  loading: !1,
322
298
  error: t
@@ -324,13 +300,13 @@ function C() {
324
300
  }
325
301
  }, [e]), n];
326
302
  }
327
- function w() {
328
- let e = v(c("workspace")), [t, n] = o({
303
+ function D() {
304
+ let e = x(l("workspace")), [t, n] = s({
329
305
  data: void 0,
330
306
  loading: !1,
331
307
  error: void 0
332
308
  });
333
- return [r(async (t) => {
309
+ return [i(async (t) => {
334
310
  n({
335
311
  data: void 0,
336
312
  loading: !0,
@@ -338,7 +314,7 @@ function w() {
338
314
  });
339
315
  try {
340
316
  let r = (await e.mutate({
341
- mutation: p,
317
+ mutation: m,
342
318
  variables: { id: t }
343
319
  })).data?.deleteBotmanorAgent ?? !1;
344
320
  return n({
@@ -356,14 +332,14 @@ function w() {
356
332
  }
357
333
  }, [e]), t];
358
334
  }
359
- function T(e) {
360
- let t = v(c("workspace")), [n, a] = o([]), [s, l] = o(!1), [u, d] = o(), f = r(async () => {
361
- if (!e) a([]);
335
+ function O(e) {
336
+ let t = x(l("workspace")), [n, r] = s([]), [o, c] = s(!1), [u, d] = s(), f = i(async () => {
337
+ if (!e) r([]);
362
338
  else {
363
- l(!0), d(void 0);
339
+ c(!0), d(void 0);
364
340
  try {
365
341
  let n = (await t.query({
366
- query: m,
342
+ query: h,
367
343
  variables: {
368
344
  agentId: e,
369
345
  pagination: {
@@ -373,30 +349,30 @@ function T(e) {
373
349
  },
374
350
  fetchPolicy: "network-only"
375
351
  })).data?.listAgentVersions ?? [];
376
- a([...n].sort((e, t) => e.createdAt && t.createdAt ? t.createdAt.localeCompare(e.createdAt) : 0));
352
+ r([...n].sort((e, t) => e.createdAt && t.createdAt ? t.createdAt.localeCompare(e.createdAt) : 0));
377
353
  } catch (e) {
378
354
  d(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load agent versions"));
379
355
  } finally {
380
- l(!1);
356
+ c(!1);
381
357
  }
382
358
  }
383
359
  }, [e, t]);
384
- return i(() => {
360
+ return a(() => {
385
361
  f();
386
362
  }, [f]), {
387
363
  data: n,
388
- loading: s,
364
+ loading: o,
389
365
  error: u,
390
366
  refetch: f
391
367
  };
392
368
  }
393
- function E() {
394
- let e = v(c("workspace")), [t, n] = o({
369
+ function k() {
370
+ let e = x(l("workspace")), [t, n] = s({
395
371
  data: void 0,
396
372
  loading: !1,
397
373
  error: void 0
398
374
  });
399
- return [r(async ({ agentId: t, versionId: r, changelog: i }) => {
375
+ return [i(async ({ agentId: t, versionId: r, changelog: i }) => {
400
376
  n({
401
377
  data: void 0,
402
378
  loading: !0,
@@ -404,7 +380,7 @@ function E() {
404
380
  });
405
381
  try {
406
382
  let a = (await e.mutate({
407
- mutation: h,
383
+ mutation: g,
408
384
  variables: {
409
385
  agentId: t,
410
386
  versionId: r,
@@ -427,13 +403,13 @@ function E() {
427
403
  }
428
404
  }, [e]), t];
429
405
  }
430
- function D() {
431
- let e = v(c("workspace")), [t, n] = o({
406
+ function A() {
407
+ let e = x(l("workspace")), [t, n] = s({
432
408
  data: void 0,
433
409
  loading: !1,
434
410
  error: void 0
435
411
  });
436
- return [r(async ({ agentId: t, targetVersionId: r }) => {
412
+ return [i(async ({ agentId: t, targetVersionId: r }) => {
437
413
  n({
438
414
  data: void 0,
439
415
  loading: !0,
@@ -441,7 +417,7 @@ function D() {
441
417
  });
442
418
  try {
443
419
  let i = (await e.mutate({
444
- mutation: g,
420
+ mutation: _,
445
421
  variables: {
446
422
  agentId: t,
447
423
  targetVersionId: r
@@ -463,6 +439,6 @@ function D() {
463
439
  }
464
440
  }, [e]), t];
465
441
  }
466
- export { x as useAgent, T as useAgentVersions, b as useAgents, S as useCreateAgent, w as useDeleteAgent, E as usePublishAgentVersion, D as useRollbackAgentVersion, C as useUpdateAgent };
442
+ export { w as useAgent, O as useAgentVersions, C as useAgents, T as useCreateAgent, D as useDeleteAgent, k as usePublishAgentVersion, A as useRollbackAgentVersion, E as useUpdateAgent };
467
443
 
468
444
  //# sourceMappingURL=useAgents.js.map