@burdenoff/microfe-botmanor 2026.1109.2 → 2026.1110.2

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 (52) hide show
  1. package/dist/botlit/components/Badge.js +2 -2
  2. package/dist/botlit/components/Badge.js.map +1 -1
  3. package/dist/botlit/components/ChannelSelectorSheet.js +4 -4
  4. package/dist/botlit/components/ChannelSelectorSheet.js.map +1 -1
  5. package/dist/botlit/components/LoadMore.d.ts +9 -0
  6. package/dist/botlit/components/LoadMore.js +22 -0
  7. package/dist/botlit/components/LoadMore.js.map +1 -0
  8. package/dist/botlit/components/index.d.ts +1 -0
  9. package/dist/botlit/hooks/internal/workspaceGateway.d.ts +47 -0
  10. package/dist/botlit/hooks/internal/workspaceGateway.js +59 -1
  11. package/dist/botlit/hooks/internal/workspaceGateway.js.map +1 -1
  12. package/dist/botlit/hooks/useAgents.d.ts +2 -6
  13. package/dist/botlit/hooks/useAgents.js +71 -95
  14. package/dist/botlit/hooks/useAgents.js.map +1 -1
  15. package/dist/botlit/hooks/useBots.d.ts +2 -6
  16. package/dist/botlit/hooks/useBots.js +51 -75
  17. package/dist/botlit/hooks/useBots.js.map +1 -1
  18. package/dist/botlit/hooks/useExecutions.d.ts +2 -2
  19. package/dist/botlit/hooks/useExecutions.js +30 -34
  20. package/dist/botlit/hooks/useExecutions.js.map +1 -1
  21. package/dist/botlit/hooks/useStore.d.ts +3 -3
  22. package/dist/botlit/hooks/useStore.js +41 -50
  23. package/dist/botlit/hooks/useStore.js.map +1 -1
  24. package/dist/botlit/pages/A2AAgentDetailPage.js +1 -1
  25. package/dist/botlit/pages/A2AAgentDetailPage.js.map +1 -1
  26. package/dist/botlit/pages/AgentDetailPage.js +1 -1
  27. package/dist/botlit/pages/AgentDetailPage.js.map +1 -1
  28. package/dist/botlit/pages/AgentsListPage.js +157 -156
  29. package/dist/botlit/pages/AgentsListPage.js.map +1 -1
  30. package/dist/botlit/pages/BotChannelsTab.js +24 -24
  31. package/dist/botlit/pages/BotChannelsTab.js.map +1 -1
  32. package/dist/botlit/pages/BotsListPage.js +147 -146
  33. package/dist/botlit/pages/BotsListPage.js.map +1 -1
  34. package/dist/botlit/pages/BucketsPage.js +3 -3
  35. package/dist/botlit/pages/BucketsPage.js.map +1 -1
  36. package/dist/botlit/pages/ChannelDetailPage.js +2 -2
  37. package/dist/botlit/pages/ChannelDetailPage.js.map +1 -1
  38. package/dist/botlit/pages/ExecutionsPage.js +141 -134
  39. package/dist/botlit/pages/ExecutionsPage.js.map +1 -1
  40. package/dist/botlit/pages/InstalledPackagesPage.js +43 -36
  41. package/dist/botlit/pages/InstalledPackagesPage.js.map +1 -1
  42. package/dist/botlit/pages/MCPServersPage.js +1 -1
  43. package/dist/botlit/pages/MCPServersPage.js.map +1 -1
  44. package/dist/botlit/pages/SettingsPage.js +2 -2
  45. package/dist/botlit/pages/SettingsPage.js.map +1 -1
  46. package/dist/botlit/pages/SkillDetailPage.js +1 -1
  47. package/dist/botlit/pages/SkillDetailPage.js.map +1 -1
  48. package/dist/botlit/pages/StorePackageDetailPage.js +1 -1
  49. package/dist/botlit/pages/StorePackageDetailPage.js.map +1 -1
  50. package/dist/botlit/pages/StorePage.js +150 -143
  51. package/dist/botlit/pages/StorePage.js.map +1 -1
  52. package/package.json +1 -1
@@ -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/useBots.ts
7
- var l = s`
8
+ var u = c`
8
9
  query ListBotApps($filters: BotAppFilterInput, $pagination: PaginationInput) {
9
10
  listBotApps(filters: $filters, pagination: $pagination) {
10
11
  id
@@ -30,7 +31,7 @@ var l = s`
30
31
  workspaceId
31
32
  }
32
33
  }
33
- `, u = s`
34
+ `, d = c`
34
35
  query GetBotApp($id: ID!) {
35
36
  getBotApp(id: $id) {
36
37
  id
@@ -56,7 +57,7 @@ var l = s`
56
57
  workspaceId
57
58
  }
58
59
  }
59
- `, d = s`
60
+ `, f = c`
60
61
  mutation CreateBotApp($input: CreateBotAppInput!) {
61
62
  createBotApp(input: $input) {
62
63
  id
@@ -76,7 +77,7 @@ var l = s`
76
77
  workspaceId
77
78
  }
78
79
  }
79
- `, f = s`
80
+ `, p = c`
80
81
  mutation UpdateBotApp($id: ID!, $input: UpdateBotAppInput!) {
81
82
  updateBotApp(id: $id, input: $input) {
82
83
  id
@@ -98,11 +99,11 @@ var l = s`
98
99
  workspaceId
99
100
  }
100
101
  }
101
- `, p = s`
102
+ `, m = c`
102
103
  mutation DeleteBotApp($id: ID!) {
103
104
  deleteBotApp(id: $id)
104
105
  }
105
- `, m = n({
106
+ `, h = 100, g = [], _ = n({
106
107
  bucketId: !0,
107
108
  context: !0,
108
109
  defaultAgentId: !0,
@@ -121,10 +122,10 @@ var l = s`
121
122
  welcomeMessage: !0,
122
123
  workflowId: !0
123
124
  });
124
- function h(e) {
125
+ function v(e) {
125
126
  return e;
126
127
  }
127
- function g(e, t) {
128
+ function y(e, t) {
128
129
  if (e || t) return {
129
130
  workspaceId: e,
130
131
  search: t?.search,
@@ -133,79 +134,54 @@ function g(e, t) {
133
134
  bucketId: t?.bucketId
134
135
  };
135
136
  }
136
- function _(t) {
137
- let n = h(c("workspace")), { workspaceId: s } = e(), [u, d] = o([]), [f, p] = o(!1), [m, _] = o(), v = a(() => ({
138
- filters: g(s, t),
139
- pagination: {
140
- limit: 100,
141
- offset: 0
142
- }
143
- }), [t, s]), y = r(async () => {
144
- if (!s) d([]);
145
- else {
146
- p(!0), _(void 0);
147
- try {
148
- let e = await n.query({
149
- query: l,
150
- variables: v,
151
- fetchPolicy: "network-only"
152
- });
153
- d(e.data?.listBotApps ?? []);
154
- } catch (e) {
155
- _(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load bots"));
156
- } finally {
157
- p(!1);
158
- }
159
- }
160
- }, [
161
- n,
162
- v,
163
- s
164
- ]);
165
- return i(() => {
166
- y();
167
- }, [y]), {
168
- data: u,
169
- loading: f,
170
- error: m,
171
- refetch: y
172
- };
137
+ function b(t) {
138
+ let { workspaceId: n } = e(), i = o(() => ({ filters: y(n, t) }), [t, n]);
139
+ return r({
140
+ document: u,
141
+ variables: i,
142
+ pageSize: h,
143
+ extractRows: (e) => e?.listBotApps ?? [],
144
+ select: (e) => e,
145
+ fallback: g,
146
+ enabled: !!n,
147
+ errorMessage: "Failed to load bots"
148
+ });
173
149
  }
174
- function v(e) {
175
- let t = h(c("workspace")), [n, a] = o(null), [s, l] = o(!1), [d, f] = o(), p = r(async () => {
176
- if (!e) a(null);
150
+ function x(e) {
151
+ let t = v(l("workspace")), [n, r] = s(null), [o, c] = s(!1), [u, f] = s(), p = i(async () => {
152
+ if (!e) r(null);
177
153
  else {
178
- l(!0), f(void 0);
154
+ c(!0), f(void 0);
179
155
  try {
180
156
  let n = await t.query({
181
- query: u,
157
+ query: d,
182
158
  variables: { id: e },
183
159
  fetchPolicy: "network-only"
184
160
  });
185
- a(n.data?.getBotApp ?? null);
161
+ r(n.data?.getBotApp ?? null);
186
162
  } catch (e) {
187
163
  f(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load bot"));
188
164
  } finally {
189
- l(!1);
165
+ c(!1);
190
166
  }
191
167
  }
192
168
  }, [e, t]);
193
- return i(() => {
169
+ return a(() => {
194
170
  p();
195
171
  }, [p]), {
196
172
  data: n,
197
- loading: s,
198
- error: d,
173
+ loading: o,
174
+ error: u,
199
175
  refetch: p
200
176
  };
201
177
  }
202
- function y() {
203
- let e = h(c("workspace")), [t, n] = o({
178
+ function S() {
179
+ let e = v(l("workspace")), [t, n] = s({
204
180
  data: void 0,
205
181
  loading: !1,
206
182
  error: void 0
207
183
  });
208
- return [r(async (t) => {
184
+ return [i(async (t) => {
209
185
  n({
210
186
  data: void 0,
211
187
  loading: !0,
@@ -213,7 +189,7 @@ function y() {
213
189
  });
214
190
  try {
215
191
  let r = (await e.mutate({
216
- mutation: d,
192
+ mutation: f,
217
193
  variables: { input: t }
218
194
  })).data?.createBotApp;
219
195
  if (!r) throw Error("Failed to create bot");
@@ -232,35 +208,35 @@ function y() {
232
208
  }
233
209
  }, [e]), t];
234
210
  }
235
- function b() {
236
- let e = h(c("workspace")), [n, i] = o({
211
+ function C() {
212
+ let e = v(l("workspace")), [n, r] = s({
237
213
  data: void 0,
238
214
  loading: !1,
239
215
  error: void 0
240
216
  });
241
- return [r(async ({ botId: n, input: r }) => {
242
- i({
217
+ return [i(async ({ botId: n, input: i }) => {
218
+ r({
243
219
  data: void 0,
244
220
  loading: !0,
245
221
  error: void 0
246
222
  });
247
223
  try {
248
224
  let a = (await e.mutate({
249
- mutation: f,
225
+ mutation: p,
250
226
  variables: {
251
227
  id: n,
252
- input: t(r, m)
228
+ input: t(i, _)
253
229
  }
254
230
  })).data?.updateBotApp;
255
231
  if (!a) throw Error("Failed to update bot");
256
- return i({
232
+ return r({
257
233
  data: a,
258
234
  loading: !1,
259
235
  error: void 0
260
236
  }), a;
261
237
  } catch (e) {
262
238
  let t = e instanceof Error ? e : /* @__PURE__ */ Error("Failed to update bot");
263
- throw i({
239
+ throw r({
264
240
  data: void 0,
265
241
  loading: !1,
266
242
  error: t
@@ -268,13 +244,13 @@ function b() {
268
244
  }
269
245
  }, [e]), n];
270
246
  }
271
- function x() {
272
- let e = h(c("workspace")), [t, n] = o({
247
+ function w() {
248
+ let e = v(l("workspace")), [t, n] = s({
273
249
  data: void 0,
274
250
  loading: !1,
275
251
  error: void 0
276
252
  });
277
- return [r(async (t) => {
253
+ return [i(async (t) => {
278
254
  n({
279
255
  data: void 0,
280
256
  loading: !0,
@@ -282,7 +258,7 @@ function x() {
282
258
  });
283
259
  try {
284
260
  let r = (await e.mutate({
285
- mutation: p,
261
+ mutation: m,
286
262
  variables: { id: t }
287
263
  })).data?.deleteBotApp ?? !1;
288
264
  return n({
@@ -300,6 +276,6 @@ function x() {
300
276
  }
301
277
  }, [e]), t];
302
278
  }
303
- export { v as useBot, _ as useBots, y as useCreateBot, x as useDeleteBot, b as useUpdateBot };
279
+ export { x as useBot, b as useBots, S as useCreateBot, w as useDeleteBot, C as useUpdateBot };
304
280
 
305
281
  //# sourceMappingURL=useBots.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useBots.js","names":["LIST_BOT_APPS_DOCUMENT","GET_BOT_APP_DOCUMENT","CREATE_BOT_APP_DOCUMENT","UPDATE_BOT_APP_DOCUMENT","DELETE_BOT_APP_DOCUMENT","UPDATE_BOT_APP_FIELDS","fieldsOf","getWorkspaceClient","client","buildBotFilter","workspaceId","filter","useBots","useGatewayClient","useBotlit","data","setData","useState","loading","setLoading","error","setError","variables","useMemo","refetch","useCallback","result","queryError","useEffect","useBot","botId","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';\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\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) {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const { workspaceId } = useBotlit();\n const [data, setData] = useState<BotAppRecord[]>([]);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n\n const variables = useMemo(\n () => ({ filters: buildBotFilter(workspaceId, filter), pagination: { limit: 100, offset: 0 } }),\n [filter, workspaceId]\n );\n\n const refetch = useCallback(async () => {\n if (!workspaceId) {\n setData([]);\n return;\n }\n\n setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<ListBotAppsData>({\n query: LIST_BOT_APPS_DOCUMENT,\n variables,\n fetchPolicy: 'network-only',\n });\n setData(result.data?.listBotApps ?? []);\n } catch (queryError) {\n setError(queryError instanceof Error ? queryError : new Error('Failed to load bots'));\n } finally {\n setLoading(false);\n }\n }, [client, variables, workspaceId]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\nexport function useBot(botId: string | undefined) {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [data, setData] = useState<BotAppRecord | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n\n const refetch = useCallback(async () => {\n if (!botId) {\n setData(null);\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 setData(result.data?.getBotApp ?? null);\n } catch (queryError) {\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":";;;;;;AASA,IAAMA,IAAyB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;GA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AAO;GAAM,CAAC,GAC7Cb;EACR;CACF,GACA,CAACZ,CAAM,CAGD,GAAWwB,CAAK;AAC1B;AAEA,SAAgBQ,IAAe;CAC7B,IAAMhC,IAASD,EAAmBM,EAAiB,WAAW,CAAC,GACzD,CAACmB,GAAOC,KAAYhB,EAAoC;EAC5D,MAAM,KAAA;EACN,SAAS;EACT,OAAO,KAAA;CACT,CAAC;CAwBD,OAAO,CAtBWQ,EAChB,OAAO,MAAkB;EACvB,EAAS;GAAE,MAAM,KAAA;GAAW,SAAS;GAAM,OAAO,KAAA;EAAU,CAAC;EAC7D,IAAI;GAMF,IAAMgB,KAAU,MALKjC,EAAO,OAAyB;IACnD,UAAUJ;IACV,WAAW,EAAE,IAAI0B,EAAM;GACzB,CAAC,EAAA,CAEsB,MAAM,gBAAgB;GAE7C,OADAG,EAAS;IAAE,MAAMQ;IAAS,SAAS;IAAO,OAAO,KAAA;GAAU,CAAC,GACrDA;EACT,SAASN,GAAe;GACtB,IAAMf,IACJe,aAAyB,QAAQA,IAAgB,gBAAI,MAAM,sBAAsB;GAEnF,MADAF,EAAS;IAAE,MAAM,KAAA;IAAW,SAAS;IAAO;GAAM,CAAC,GAC7Cb;EACR;CACF,GACA,CAACZ,CAAM,CAGD,GAAWwB,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","useBot","useGatewayClient","setData","useState","loading","setLoading","error","setError","refetch","useCallback","botId","result","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 { useWorkspacePaginatedQuery, type PaginatedQueryResult } 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\nexport function useBot(botId: string | undefined) {\n const client = getWorkspaceClient(useGatewayClient('workspace'));\n const [data, setData] = useState<BotAppRecord | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n\n const refetch = useCallback(async () => {\n if (!botId) {\n setData(null);\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 setData(result.data?.getBotApp ?? null);\n } catch (queryError) {\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":";;;;;;;AAUA,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;AAUA,SAAgBC,EAAQ,GAA2D;CACjF,IAAM,EAAE,mBAAgBC,EAAU,GAE5BC,IAAYC,SACT,EAAE,SAASN,EAAeC,GAAaC,CAAM,EAAE,IACtD,CAACA,GAAQD,CAAW,CACtB;CAEA,OAAOM,EAA0E;EAC/E,UAAUlB;EACV;EACA,UAAUK;EACV,cAAc,MAASc,GAAM,eAAe,CAAC;EAC7C,SAAS,MAASC;EAClB,UAAUd;E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OAAO,CAtBWM,EAChB,OAAO,MAAkB;EACvB,EAAS;GAAE,MAAM,KAAA;GAAW,SAAS;GAAM,OAAO,KAAA;EAAU,CAAC;EAC7D,IAAI;GAMF,IAAMe,KAAU,MALKnC,EAAO,OAAyB;IACnD,UAAUN;IACV,WAAW,EAAE,IAAI2B,EAAM;GACzB,CAAC,EAAA,CAEsB,MAAM,gBAAgB;GAE7C,OADAM,EAAS;IAAE,MAAMQ;IAAS,SAAS;IAAO,OAAO,KAAA;GAAU,CAAC,GACrDA;EACT,SAASN,GAAe;GACtB,IAAMZ,IACJY,aAAyB,QAAQA,IAAgB,gBAAI,MAAM,sBAAsB;GAEnF,MADAF,EAAS;IAAE,MAAM,KAAA;IAAW,SAAS;IAAO;GAAM,CAAC,GAC7CV;EACR;CACF,GACA,CAACjB,CAAM,CAGD,GAAW0B,CAAK;AAC1B"}
@@ -1,6 +1,6 @@
1
1
  import { CreateExecutionInput, ExecutionStatus } from '../../generated/wspace-types';
2
2
  import { GraphQLInput } from './internal/mutationInput';
3
- import { QueryResult } from './internal/workspaceGateway';
3
+ import { PaginatedQueryResult, QueryResult } from './internal/workspaceGateway';
4
4
  export interface ExecutionRecord {
5
5
  id: string;
6
6
  status: string;
@@ -61,7 +61,7 @@ export declare const executionKeys: {
61
61
  detail: (id: string) => readonly ["executions", "detail", string];
62
62
  metrics: () => readonly ["executions", "metrics"];
63
63
  };
64
- export declare function useExecutions(filter?: ExecutionsFilter): QueryResult<ExecutionRecord[]>;
64
+ export declare function useExecutions(filter?: ExecutionsFilter): PaginatedQueryResult<ExecutionRecord[]>;
65
65
  export declare function useExecution(executionId: string | undefined): QueryResult<ExecutionRecord | null>;
66
66
  /**
67
67
  * Token/cost metrics for the workspace, optionally narrowed to an agent, app or
@@ -1,9 +1,9 @@
1
1
  import { CreateExecutionDocument as e, GetExecutionDocument as t, ListExecutionsDocument as n } from "../../generated/wspace-operations.js";
2
2
  import { buildMutationInput as r, fieldsOf as i } from "./internal/mutationInput.js";
3
- import { useWorkspaceId as a, useWorkspaceMutation as o, useWorkspaceQuery as s } from "./internal/workspaceGateway.js";
4
- import { useCallback as c, useMemo as l } from "react";
3
+ import { useWorkspaceId as a, useWorkspaceMutation as o, useWorkspacePaginatedQuery as s, useWorkspaceQuery as c } from "./internal/workspaceGateway.js";
4
+ import { useCallback as l, useMemo as u } from "react";
5
5
  // src/botlit/hooks/useExecutions.ts
6
- var u = 100, d = i({
6
+ var d = 100, f = i({
7
7
  agentId: !0,
8
8
  appId: !0,
9
9
  conversationId: !0,
@@ -11,47 +11,43 @@ var u = 100, d = i({
11
11
  metadata: !0,
12
12
  type: !0,
13
13
  workspaceId: !0
14
- }), f = /* @__PURE__ */ new Set(["COMPLETED"]), p = [];
15
- function m(e, t) {
14
+ }), p = /* @__PURE__ */ new Set(["COMPLETED"]), m = [];
15
+ function h(e, t) {
16
16
  return e.id.toLowerCase().includes(t) || (e.agentId ?? "").toLowerCase().includes(t) || (e.appId ?? "").toLowerCase().includes(t) || e.input.toLowerCase().includes(t);
17
17
  }
18
- function h(e) {
19
- let t = a(), r = e?.search?.trim().toLowerCase() ?? "", i = e?.status, o = i?.length === 1 ? i[0] : void 0, d = i?.join(",") ?? "", { agentId: f, appId: h, conversationId: g, type: _ } = e ?? {}, v = l(() => ({
20
- filters: {
21
- workspaceId: t,
22
- status: o,
23
- agentId: f,
24
- appId: h,
25
- conversationId: g,
26
- type: _
27
- },
28
- pagination: {
29
- limit: u,
30
- offset: 0
31
- }
32
- }), [
18
+ function g(e) {
19
+ let t = a(), r = e?.search?.trim().toLowerCase() ?? "", i = e?.status, o = i?.length === 1 ? i[0] : void 0, c = i?.join(",") ?? "", { agentId: f, appId: p, conversationId: g, type: _ } = e ?? {}, v = u(() => ({ filters: {
20
+ workspaceId: t,
21
+ status: o,
22
+ agentId: f,
23
+ appId: p,
24
+ conversationId: g,
25
+ type: _
26
+ } }), [
33
27
  t,
34
28
  o,
35
29
  f,
36
- h,
30
+ p,
37
31
  g,
38
32
  _
39
- ]), y = c((e) => {
40
- let t = e?.listExecutions ?? p, n = d ? new Set(d.split(",")) : void 0, i = n && n.size > 1 ? t.filter((e) => n.has(e.status)) : t;
41
- return r ? i.filter((e) => m(e, r)) : i;
42
- }, [r, d]);
33
+ ]), y = l((e) => {
34
+ let t = c ? new Set(c.split(",")) : void 0, n = t && t.size > 1 ? e.filter((e) => t.has(e.status)) : e;
35
+ return r ? n.filter((e) => h(e, r)) : n;
36
+ }, [r, c]);
43
37
  return s({
44
38
  document: n,
45
39
  variables: v,
40
+ pageSize: d,
41
+ extractRows: (e) => e?.listExecutions ?? m,
46
42
  select: y,
47
- fallback: p,
43
+ fallback: m,
48
44
  enabled: !!t,
49
45
  errorMessage: "Failed to load executions"
50
46
  });
51
47
  }
52
- function g(e) {
53
- let n = l(() => ({ id: e ?? "" }), [e]);
54
- return s({
48
+ function _(e) {
49
+ let n = u(() => ({ id: e ?? "" }), [e]);
50
+ return c({
55
51
  document: t,
56
52
  variables: n,
57
53
  select: (e) => e?.getExecution ?? null,
@@ -60,9 +56,9 @@ function g(e) {
60
56
  errorMessage: "Failed to load execution"
61
57
  });
62
58
  }
63
- function _(e) {
59
+ function v(e) {
64
60
  let t = e.length, n = 0, r = 0, i = 0, a = 0, o = 0, s = 0;
65
- for (let t of e) f.has(t.status) && (n += 1), (t.status === "FAILED" || t.status === "TIMEOUT") && (r += 1), typeof t.duration == "number" && (i += t.duration, a += 1), o += t.cost ?? 0, s += t.tokensUsed ?? 0;
61
+ for (let t of e) p.has(t.status) && (n += 1), (t.status === "FAILED" || t.status === "TIMEOUT") && (r += 1), typeof t.duration == "number" && (i += t.duration, a += 1), o += t.cost ?? 0, s += t.tokensUsed ?? 0;
66
62
  return {
67
63
  total: t,
68
64
  succeeded: n,
@@ -73,14 +69,14 @@ function _(e) {
73
69
  totalTokens: s
74
70
  };
75
71
  }
76
- function v() {
72
+ function y() {
77
73
  return o({
78
74
  document: e,
79
- variables: ({ input: e }) => ({ input: r(e, d) }),
75
+ variables: ({ input: e }) => ({ input: r(e, f) }),
80
76
  select: (e) => e?.createExecution,
81
77
  errorMessage: "Failed to start execution"
82
78
  });
83
79
  }
84
- export { _ as summariseExecutions, v as useCreateExecution, g as useExecution, h as useExecutions };
80
+ export { v as summariseExecutions, y as useCreateExecution, _ as useExecution, g as useExecutions };
85
81
 
86
82
  //# sourceMappingURL=useExecutions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useExecutions.js","names":["LIST_LIMIT","CREATE_EXECUTION_FIELDS","fieldsOf","SUCCESS_STATUSES","NO_EXECUTIONS","matchesSearch","execution","needle","useExecutions","workspaceId","useWorkspaceId","search","filter","statuses","singleStatus","statusKey","variables","useMemo","agentId","appId","conversationId","type","select","useCallback","rows","data","wanted","narrowed","row","useWorkspaceQuery","ListExecutionsDocument","useExecution","executionId","GetExecutionDocument","summariseExecutions","total","executions","succeeded","failed","durationSum","durationCount","totalCost","totalTokens","useCreateExecution","useWorkspaceMutation","CreateExecutionDocument","buildMutationInput","input"],"sources":["../../../src/botlit/hooks/useExecutions.ts"],"sourcesContent":["/**\n * Executions Hooks\n * @module botlit/hooks\n *\n * Backed by the live `listExecutions` / `getExecution` / `getExecutionMetrics`\n * operations plus the `createExecution` / `updateExecutionStatus` mutations on\n * wspace-botlit-svc.\n *\n * Note on filtering: `ExecutionFilterInput` accepts a SINGLE status and has no\n * free-text field, so multi-status selections and search are narrowed on the\n * client over the fetched page.\n */\n\nimport { useCallback, useMemo } from 'react';\nimport {\n CreateExecutionDocument,\n GetExecutionDocument,\n GetExecutionMetricsDocument,\n ListExecutionsDocument,\n UpdateExecutionStatusDocument,\n type CreateExecutionMutation,\n type GetExecutionMetricsQuery,\n type GetExecutionQuery,\n type ListExecutionsQuery,\n type UpdateExecutionStatusMutation,\n} from '../../generated/wspace-operations';\nimport type { CreateExecutionInput, ExecutionStatus } from '../../generated/wspace-types';\nimport { buildMutationInput, fieldsOf, type GraphQLInput } from './internal/mutationInput';\nimport {\n useWorkspaceId,\n useWorkspaceMutation,\n useWorkspaceQuery,\n type QueryResult,\n} from './internal/workspaceGateway';\n\nconst LIST_LIMIT = 100;\n\nexport interface ExecutionRecord {\n id: string;\n status: string;\n type: string;\n input: string;\n output?: string | null;\n agentId?: string | null;\n appId?: string | null;\n conversationId?: string | null;\n cost?: number | null;\n duration?: number | null;\n tokensUsed?: number | null;\n errorCode?: string | null;\n errorMessage?: string | null;\n errorDetails?: Record<string, unknown> | null;\n metadata?: Record<string, unknown> | null;\n completedAt?: string | null;\n createdAt: string;\n workspaceId: string;\n}\n\nexport interface ExecutionMetricsRecord {\n executionId: string;\n cost: number;\n inputTokens: number;\n outputTokens: number;\n totalTokens: number;\n ragChunks: number;\n toolCalls: number;\n}\n\nexport interface ExecutionsFilter {\n search?: string;\n status?: string[];\n agentId?: string;\n appId?: string;\n conversationId?: string;\n type?: string;\n}\n\nexport interface ExecutionMetricsFilter {\n agentId?: string;\n appId?: string;\n startDate?: string;\n endDate?: string;\n}\n\nexport interface CreateExecutionVariables {\n input: GraphQLInput<CreateExecutionInput>;\n}\n\nconst CREATE_EXECUTION_FIELDS = fieldsOf<CreateExecutionInput>({\n agentId: true,\n appId: true,\n conversationId: true,\n input: true,\n metadata: true,\n type: true,\n workspaceId: true,\n});\n\nexport interface UpdateExecutionStatusVariables {\n id: string;\n status: ExecutionStatus;\n output?: string;\n error?: Record<string, unknown>;\n}\n\n/** Terminal statuses that count as a successful run. */\nconst SUCCESS_STATUSES = new Set(['COMPLETED']);\n\nconst NO_EXECUTIONS: ExecutionRecord[] = [];\n\nexport const executionKeys = {\n all: ['executions'] as const,\n lists: () => [...executionKeys.all, 'list'] as const,\n list: (filter?: ExecutionsFilter) => [...executionKeys.lists(), filter] as const,\n details: () => [...executionKeys.all, 'detail'] as const,\n detail: (id: string) => [...executionKeys.details(), id] as const,\n metrics: () => [...executionKeys.all, 'metrics'] as const,\n};\n\nfunction matchesSearch(execution: ExecutionRecord, needle: string): boolean {\n return (\n execution.id.toLowerCase().includes(needle) ||\n (execution.agentId ?? '').toLowerCase().includes(needle) ||\n (execution.appId ?? '').toLowerCase().includes(needle) ||\n execution.input.toLowerCase().includes(needle)\n );\n}\n\nexport function useExecutions(filter?: ExecutionsFilter): QueryResult<ExecutionRecord[]> {\n const workspaceId = useWorkspaceId();\n const search = filter?.search?.trim().toLowerCase() ?? '';\n const statuses = filter?.status;\n const singleStatus = statuses?.length === 1 ? statuses[0] : undefined;\n const statusKey = statuses?.join(',') ?? '';\n const { agentId, appId, conversationId, type } = filter ?? {};\n\n const variables = useMemo(\n () => ({\n filters: {\n workspaceId,\n status: singleStatus,\n agentId,\n appId,\n conversationId,\n type,\n },\n pagination: { limit: LIST_LIMIT, offset: 0 },\n }),\n [workspaceId, singleStatus, agentId, appId, conversationId, type]\n );\n\n const select = useCallback(\n (data: ListExecutionsQuery | undefined): ExecutionRecord[] => {\n const rows: ExecutionRecord[] = data?.listExecutions ?? NO_EXECUTIONS;\n const wanted = statusKey ? new Set(statusKey.split(',')) : undefined;\n const narrowed =\n // A single status is already applied server-side.\n wanted && wanted.size > 1 ? rows.filter((row) => wanted.has(row.status)) : rows;\n return search ? narrowed.filter((row) => matchesSearch(row, search)) : narrowed;\n },\n [search, statusKey]\n );\n\n return useWorkspaceQuery<ListExecutionsQuery, ExecutionRecord[]>({\n document: ListExecutionsDocument,\n variables,\n select,\n fallback: NO_EXECUTIONS,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load executions',\n });\n}\n\nexport function useExecution(executionId: string | undefined): QueryResult<ExecutionRecord | null> {\n const variables = useMemo(() => ({ id: executionId ?? '' }), [executionId]);\n\n return useWorkspaceQuery<GetExecutionQuery, ExecutionRecord | null>({\n document: GetExecutionDocument,\n variables,\n select: (data) => data?.getExecution ?? null,\n fallback: null,\n enabled: Boolean(executionId),\n errorMessage: 'Failed to load execution',\n });\n}\n\n/**\n * Token/cost metrics for the workspace, optionally narrowed to an agent, app or\n * date window. Returns `null` when the service has nothing recorded yet.\n */\nexport function useExecutionMetrics(\n filter?: ExecutionMetricsFilter\n): QueryResult<ExecutionMetricsRecord | null> {\n const workspaceId = useWorkspaceId();\n const { agentId, appId, startDate, endDate } = filter ?? {};\n\n const variables = useMemo(\n () => ({ filter: { workspaceId, agentId, appId, startDate, endDate } }),\n [workspaceId, agentId, appId, startDate, endDate]\n );\n\n return useWorkspaceQuery<GetExecutionMetricsQuery, ExecutionMetricsRecord | null>({\n document: GetExecutionMetricsDocument,\n variables,\n select: (data) => data?.getExecutionMetrics ?? null,\n fallback: null,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load execution metrics',\n });\n}\n\nexport interface ExecutionRollup {\n total: number;\n succeeded: number;\n failed: number;\n successRate: number;\n avgDurationMs: number;\n totalCost: number;\n totalTokens: number;\n}\n\n/**\n * Rolls a list of executions up into the headline numbers shown above the table.\n * Derived purely from the rows that were actually loaded — no server aggregate\n * exists for this, so callers must label it as such.\n */\nexport function summariseExecutions(executions: readonly ExecutionRecord[]): ExecutionRollup {\n const total = executions.length;\n let succeeded = 0;\n let failed = 0;\n let durationSum = 0;\n let durationCount = 0;\n let totalCost = 0;\n let totalTokens = 0;\n\n for (const execution of executions) {\n if (SUCCESS_STATUSES.has(execution.status)) succeeded += 1;\n if (execution.status === 'FAILED' || execution.status === 'TIMEOUT') failed += 1;\n if (typeof execution.duration === 'number') {\n durationSum += execution.duration;\n durationCount += 1;\n }\n totalCost += execution.cost ?? 0;\n totalTokens += execution.tokensUsed ?? 0;\n }\n\n return {\n total,\n succeeded,\n failed,\n successRate: total > 0 ? succeeded / total : 0,\n avgDurationMs: durationCount > 0 ? durationSum / durationCount : 0,\n totalCost,\n totalTokens,\n };\n}\n\nexport function useCreateExecution() {\n return useWorkspaceMutation<CreateExecutionMutation, CreateExecutionVariables, ExecutionRecord>({\n document: CreateExecutionDocument,\n variables: ({ input }) => ({ input: buildMutationInput(input, CREATE_EXECUTION_FIELDS) }),\n select: (data) => data?.createExecution,\n errorMessage: 'Failed to start execution',\n });\n}\n\nexport function useUpdateExecutionStatus() {\n return useWorkspaceMutation<\n UpdateExecutionStatusMutation,\n UpdateExecutionStatusVariables,\n ExecutionRecord\n >({\n document: UpdateExecutionStatusDocument,\n variables: ({ id, status, output, error }) => ({\n id,\n input: {\n status,\n output,\n // The subgraph takes the failure as a message plus a JSON detail blob\n // (UpdateExecutionStatusInput); pass the caller's object through whole.\n errorMessage: typeof error?.message === 'string' ? error.message : undefined,\n errorDetails: error,\n },\n }),\n select: (data) => data?.updateExecutionStatus,\n errorMessage: 'Failed to update execution status',\n });\n}\n"],"mappings":";;;;;AAmCA,IAAMA,IAAa,KAqDbC,IAA0BC,EAA+B;CAC7D,SAAS;CACT,OAAO;CACP,gBAAgB;CAChB,OAAO;CACP,UAAU;CACV,MAAM;CACN,aAAa;AACf,CAAC,GAUKC,oBAAmB,IAAI,IAAI,CAAC,WAAW,CAAC,GAExCC,IAAmC,CAAC;AAW1C,SAASC,EAAc,GAA4B,GAAyB;CAC1E,OACEC,EAAU,GAAG,YAAY,CAAC,CAAC,SAASC,CAAM,MACzCD,EAAU,WAAW,GAAA,CAAI,YAAY,CAAC,CAAC,SAASC,CAAM,MACtDD,EAAU,SAAS,GAAA,CAAI,YAAY,CAAC,CAAC,SAASC,CAAM,KACrDD,EAAU,MAAM,YAAY,CAAC,CAAC,SAASC,CAAM;AAEjD;AAEA,SAAgBC,EAAc,GAA2D;CACvF,IAAMC,IAAcC,EAAe,GAC7BC,IAASC,GAAQ,QAAQ,KAAK,CAAC,CAAC,YAAY,KAAK,IACjDC,IAAWD,GAAQ,QACnBE,IAAeD,GAAU,WAAW,IAAIA,EAAS,KAAK,KAAA,GACtDE,IAAYF,GAAU,KAAK,GAAG,KAAK,IACnC,EAAE,YAAS,UAAO,mBAAgB,YAASD,KAAU,CAAC,GAEtDI,IAAYC,SACT;EACL,SAAS;GACP;GACA,QAAQH;GACR;GACA;GACA;GACA;EACF;EACA,YAAY;GAAE,OAAOd;GAAY,QAAQ;EAAE;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IAAID,IAAcC,IAAgB;EACjE;EACA;CACF;AACF;AAEA,SAAgBG,IAAqB;CACnC,OAAOC,EAAyF;EAC9F,UAAUC;EACV,YAAY,EAAE,gBAAa,EAAE,OAAOC,EAAmBC,GAAO9C,CAAuB,EAAE;EACvF,SAAS,MAASwB,GAAM;EACxB,cAAc;CAChB,CAAC;AACH"}
1
+ {"version":3,"file":"useExecutions.js","names":["LIST_LIMIT","CREATE_EXECUTION_FIELDS","fieldsOf","SUCCESS_STATUSES","NO_EXECUTIONS","matchesSearch","execution","needle","useExecutions","workspaceId","useWorkspaceId","search","filter","statuses","singleStatus","statusKey","variables","useMemo","agentId","appId","conversationId","type","select","useCallback","wanted","narrowed","rows","row","useWorkspacePaginatedQuery","ListExecutionsDocument","data","useExecution","executionId","useWorkspaceQuery","GetExecutionDocument","summariseExecutions","total","executions","succeeded","failed","durationSum","durationCount","totalCost","totalTokens","useCreateExecution","useWorkspaceMutation","CreateExecutionDocument","buildMutationInput","input"],"sources":["../../../src/botlit/hooks/useExecutions.ts"],"sourcesContent":["/**\n * Executions Hooks\n * @module botlit/hooks\n *\n * Backed by the live `listExecutions` / `getExecution` / `getExecutionMetrics`\n * operations plus the `createExecution` / `updateExecutionStatus` mutations on\n * wspace-botlit-svc.\n *\n * Note on filtering: `ExecutionFilterInput` accepts a SINGLE status and has no\n * free-text field, so multi-status selections and search are narrowed on the\n * client over every loaded page (see `loadMore`).\n */\n\nimport { useCallback, useMemo } from 'react';\nimport {\n CreateExecutionDocument,\n GetExecutionDocument,\n GetExecutionMetricsDocument,\n ListExecutionsDocument,\n UpdateExecutionStatusDocument,\n type CreateExecutionMutation,\n type GetExecutionMetricsQuery,\n type GetExecutionQuery,\n type ListExecutionsQuery,\n type UpdateExecutionStatusMutation,\n} from '../../generated/wspace-operations';\nimport type { CreateExecutionInput, ExecutionStatus } from '../../generated/wspace-types';\nimport { buildMutationInput, fieldsOf, type GraphQLInput } from './internal/mutationInput';\nimport {\n useWorkspaceId,\n useWorkspaceMutation,\n useWorkspacePaginatedQuery,\n useWorkspaceQuery,\n type PaginatedQueryResult,\n type QueryResult,\n} from './internal/workspaceGateway';\n\nconst LIST_LIMIT = 100;\n\nexport interface ExecutionRecord {\n id: string;\n status: string;\n type: string;\n input: string;\n output?: string | null;\n agentId?: string | null;\n appId?: string | null;\n conversationId?: string | null;\n cost?: number | null;\n duration?: number | null;\n tokensUsed?: number | null;\n errorCode?: string | null;\n errorMessage?: string | null;\n errorDetails?: Record<string, unknown> | null;\n metadata?: Record<string, unknown> | null;\n completedAt?: string | null;\n createdAt: string;\n workspaceId: string;\n}\n\nexport interface ExecutionMetricsRecord {\n executionId: string;\n cost: number;\n inputTokens: number;\n outputTokens: number;\n totalTokens: number;\n ragChunks: number;\n toolCalls: number;\n}\n\nexport interface ExecutionsFilter {\n search?: string;\n status?: string[];\n agentId?: string;\n appId?: string;\n conversationId?: string;\n type?: string;\n}\n\nexport interface ExecutionMetricsFilter {\n agentId?: string;\n appId?: string;\n startDate?: string;\n endDate?: string;\n}\n\nexport interface CreateExecutionVariables {\n input: GraphQLInput<CreateExecutionInput>;\n}\n\nconst CREATE_EXECUTION_FIELDS = fieldsOf<CreateExecutionInput>({\n agentId: true,\n appId: true,\n conversationId: true,\n input: true,\n metadata: true,\n type: true,\n workspaceId: true,\n});\n\nexport interface UpdateExecutionStatusVariables {\n id: string;\n status: ExecutionStatus;\n output?: string;\n error?: Record<string, unknown>;\n}\n\n/** Terminal statuses that count as a successful run. */\nconst SUCCESS_STATUSES = new Set(['COMPLETED']);\n\nconst NO_EXECUTIONS: ExecutionRecord[] = [];\n\nexport const executionKeys = {\n all: ['executions'] as const,\n lists: () => [...executionKeys.all, 'list'] as const,\n list: (filter?: ExecutionsFilter) => [...executionKeys.lists(), filter] as const,\n details: () => [...executionKeys.all, 'detail'] as const,\n detail: (id: string) => [...executionKeys.details(), id] as const,\n metrics: () => [...executionKeys.all, 'metrics'] as const,\n};\n\nfunction matchesSearch(execution: ExecutionRecord, needle: string): boolean {\n return (\n execution.id.toLowerCase().includes(needle) ||\n (execution.agentId ?? '').toLowerCase().includes(needle) ||\n (execution.appId ?? '').toLowerCase().includes(needle) ||\n execution.input.toLowerCase().includes(needle)\n );\n}\n\nexport function useExecutions(filter?: ExecutionsFilter): PaginatedQueryResult<ExecutionRecord[]> {\n const workspaceId = useWorkspaceId();\n const search = filter?.search?.trim().toLowerCase() ?? '';\n const statuses = filter?.status;\n const singleStatus = statuses?.length === 1 ? statuses[0] : undefined;\n const statusKey = statuses?.join(',') ?? '';\n const { agentId, appId, conversationId, type } = filter ?? {};\n\n const variables = useMemo(\n () => ({\n filters: {\n workspaceId,\n status: singleStatus,\n agentId,\n appId,\n conversationId,\n type,\n },\n }),\n [workspaceId, singleStatus, agentId, appId, conversationId, type]\n );\n\n const select = useCallback(\n (rows: ExecutionRecord[]): ExecutionRecord[] => {\n const wanted = statusKey ? new Set(statusKey.split(',')) : undefined;\n const narrowed =\n // A single status is already applied server-side.\n wanted && wanted.size > 1 ? rows.filter((row) => wanted.has(row.status)) : rows;\n return search ? narrowed.filter((row) => matchesSearch(row, search)) : narrowed;\n },\n [search, statusKey]\n );\n\n return useWorkspacePaginatedQuery<ListExecutionsQuery, ExecutionRecord, ExecutionRecord[]>({\n document: ListExecutionsDocument,\n variables,\n pageSize: LIST_LIMIT,\n extractRows: (data) => data?.listExecutions ?? NO_EXECUTIONS,\n select,\n fallback: NO_EXECUTIONS,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load executions',\n });\n}\n\nexport function useExecution(executionId: string | undefined): QueryResult<ExecutionRecord | null> {\n const variables = useMemo(() => ({ id: executionId ?? '' }), [executionId]);\n\n return useWorkspaceQuery<GetExecutionQuery, ExecutionRecord | null>({\n document: GetExecutionDocument,\n variables,\n select: (data) => data?.getExecution ?? null,\n fallback: null,\n enabled: Boolean(executionId),\n errorMessage: 'Failed to load execution',\n });\n}\n\n/**\n * Token/cost metrics for the workspace, optionally narrowed to an agent, app or\n * date window. Returns `null` when the service has nothing recorded yet.\n */\nexport function useExecutionMetrics(\n filter?: ExecutionMetricsFilter\n): QueryResult<ExecutionMetricsRecord | null> {\n const workspaceId = useWorkspaceId();\n const { agentId, appId, startDate, endDate } = filter ?? {};\n\n const variables = useMemo(\n () => ({ filter: { workspaceId, agentId, appId, startDate, endDate } }),\n [workspaceId, agentId, appId, startDate, endDate]\n );\n\n return useWorkspaceQuery<GetExecutionMetricsQuery, ExecutionMetricsRecord | null>({\n document: GetExecutionMetricsDocument,\n variables,\n select: (data) => data?.getExecutionMetrics ?? null,\n fallback: null,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load execution metrics',\n });\n}\n\nexport interface ExecutionRollup {\n total: number;\n succeeded: number;\n failed: number;\n successRate: number;\n avgDurationMs: number;\n totalCost: number;\n totalTokens: number;\n}\n\n/**\n * Rolls a list of executions up into the headline numbers shown above the table.\n * Derived purely from the rows that were actually loaded — no server aggregate\n * exists for this, so callers must label it as such.\n */\nexport function summariseExecutions(executions: readonly ExecutionRecord[]): ExecutionRollup {\n const total = executions.length;\n let succeeded = 0;\n let failed = 0;\n let durationSum = 0;\n let durationCount = 0;\n let totalCost = 0;\n let totalTokens = 0;\n\n for (const execution of executions) {\n if (SUCCESS_STATUSES.has(execution.status)) succeeded += 1;\n if (execution.status === 'FAILED' || execution.status === 'TIMEOUT') failed += 1;\n if (typeof execution.duration === 'number') {\n durationSum += execution.duration;\n durationCount += 1;\n }\n totalCost += execution.cost ?? 0;\n totalTokens += execution.tokensUsed ?? 0;\n }\n\n return {\n total,\n succeeded,\n failed,\n successRate: total > 0 ? succeeded / total : 0,\n avgDurationMs: durationCount > 0 ? durationSum / durationCount : 0,\n totalCost,\n totalTokens,\n };\n}\n\nexport function useCreateExecution() {\n return useWorkspaceMutation<CreateExecutionMutation, CreateExecutionVariables, ExecutionRecord>({\n document: CreateExecutionDocument,\n variables: ({ input }) => ({ input: buildMutationInput(input, CREATE_EXECUTION_FIELDS) }),\n select: (data) => data?.createExecution,\n errorMessage: 'Failed to start execution',\n });\n}\n\nexport function useUpdateExecutionStatus() {\n return useWorkspaceMutation<\n UpdateExecutionStatusMutation,\n UpdateExecutionStatusVariables,\n ExecutionRecord\n >({\n document: UpdateExecutionStatusDocument,\n variables: ({ id, status, output, error }) => ({\n id,\n input: {\n status,\n output,\n // The subgraph takes the failure as a message plus a JSON detail blob\n // (UpdateExecutionStatusInput); pass the caller's object through whole.\n errorMessage: typeof error?.message === 'string' ? error.message : undefined,\n errorDetails: error,\n },\n }),\n select: (data) => data?.updateExecutionStatus,\n errorMessage: 'Failed to update execution status',\n });\n}\n"],"mappings":";;;;;AAqCA,IAAMA,IAAa,KAqDbC,IAA0BC,EAA+B;CAC7D,SAAS;CACT,OAAO;CACP,gBAAgB;CAChB,OAAO;CACP,UAAU;CACV,MAAM;CACN,aAAa;AACf,CAAC,GAUKC,oBAAmB,IAAI,IAAI,CAAC,WAAW,CAAC,GAExCC,IAAmC,CAAC;AAW1C,SAASC,EAAc,GAA4B,GAAyB;CAC1E,OACEC,EAAU,GAAG,YAAY,CAAC,CAAC,SAASC,CAAM,MACzCD,EAAU,WAAW,GAAA,CAAI,YAAY,CAAC,CAAC,SAASC,CAAM,MACtDD,EAAU,SAAS,GAAA,CAAI,YAAY,CAAC,CAAC,SAASC,CAAM,KACrDD,EAAU,MAAM,YAAY,CAAC,CAAC,SAASC,CAAM;AAEjD;AAEA,SAAgBC,EAAc,GAAoE;CAChG,IAAMC,IAAcC,EAAe,GAC7BC,IAASC,GAAQ,QAAQ,KAAK,CAAC,CAAC,YAAY,KAAK,IACjDC,IAAWD,GAAQ,QACnBE,IAAeD,GAAU,WAAW,IAAIA,EAAS,KAAK,KAAA,GACtDE,IAAYF,GAAU,KAAK,GAAG,KAAK,IACnC,EAAE,YAAS,UAAO,mBAAgB,YAASD,KAAU,CAAC,GAEtDI,IAAYC,SACT,EACL,SAAS;EACP;EACA,QAAQH;EACR;EACA;EACA;EACA;CACF,EACF,IACA;EAACL;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AAcC,IAAgB;EACjE;EACA;CACF;AACF;AAEA,SAAgBG,IAAqB;CACnC,OAAOC,EAAyF;EAC9F,UAAUC;EACV,YAAY,EAAE,gBAAa,EAAE,OAAOC,EAAmBC,GAAO/C,CAAuB,EAAE;EACvF,SAAS,MAAS6B,GAAM;EACxB,cAAc;CAChB,CAAC;AACH"}
@@ -1,6 +1,6 @@
1
1
  import { ForkInstalledPackageInput, InstallPackageInput, UpdateInstalledPackageInput } from '../../generated/wspace-types';
2
2
  import { GraphQLInput } from './internal/mutationInput';
3
- import { QueryResult } from './internal/workspaceGateway';
3
+ import { PaginatedQueryResult, QueryResult } from './internal/workspaceGateway';
4
4
  export interface StorePackageRecord {
5
5
  id: string;
6
6
  slug: string;
@@ -69,10 +69,10 @@ export declare const storeKeys: {
69
69
  installedList: () => readonly ["store", "installed", "list"];
70
70
  installedDetail: (id: string) => readonly ["store", "installed", "detail", string];
71
71
  };
72
- export declare function useStorePackages(filter?: StoreFilter): QueryResult<StorePackageRecord[]>;
72
+ export declare function useStorePackages(filter?: StoreFilter): PaginatedQueryResult<StorePackageRecord[]>;
73
73
  /** Store packages are addressed by slug in the UI, so this resolves by slug. */
74
74
  export declare function useStorePackage(slug: string | undefined): QueryResult<StorePackageRecord | null>;
75
- export declare function useInstalledPackages(): QueryResult<InstalledPackageRecord[]>;
75
+ export declare function useInstalledPackages(): PaginatedQueryResult<InstalledPackageRecord[]>;
76
76
  export declare function useInstalledPackage(packageId: string | undefined): QueryResult<InstalledPackageRecord | null>;
77
77
  /**
78
78
  * Installed packages whose store listing now publishes a different version.