@burdenoff/microfe-botmanor 2026.1120.4 → 2026.1120.6

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.
@@ -0,0 +1,32 @@
1
+ import { ChatAssistantsQuery } from '../../generated/wspace-operations';
2
+ import { QueryResult } from './internal/workspaceGateway';
3
+ /** The product id saved BotManor agent chats are stored under. */
4
+ export declare const BOTMANOR_ASSISTANT_PRODUCT_ID = "botmanor";
5
+ export type ChatAssistantRecord = ChatAssistantsQuery['listBotmanorAgents'][number];
6
+ /**
7
+ * Every agent in the workspace, with the fields that decide whether a saved
8
+ * chat can use it. Not filtered by status, so an inactive agent still reaches
9
+ * the picker's "not available" group with its reason.
10
+ */
11
+ export declare function useChatAssistants(): QueryResult<ChatAssistantRecord[]>;
12
+ /**
13
+ * Days after which the caller's saved conversations are retired: a number,
14
+ * null when no period applies, or undefined until the server has answered.
15
+ * Undefined is never shown as "no period" (BOFF-12699).
16
+ */
17
+ export declare function useMyAssistantRetention(): QueryResult<number | null | undefined>;
18
+ export interface AssistantConversationSummary {
19
+ clientConversationId: string;
20
+ createdAt: string;
21
+ }
22
+ /**
23
+ * The caller's own saved conversations with one agent, newest first. Follows
24
+ * `nextCursor` until the last page, so older conversations can be deleted too.
25
+ */
26
+ export declare function useMyAssistantConversations(agentId: string | undefined): QueryResult<AssistantConversationSummary[]>;
27
+ /** Deletes one of the caller's saved conversations. Resolves only when the server confirmed it. */
28
+ export declare function useDeleteMyAssistantConversation(): {
29
+ remove: (clientConversationId: string) => Promise<void>;
30
+ deletingId: string | null;
31
+ error: Error | undefined;
32
+ };
@@ -0,0 +1,98 @@
1
+ import { ChatAssistantsDocument as e, MyAssistantConversationRetentionDocument as t, MyAssistantWorkflowConversationsDocument as n, RetireMyAssistantConversationDocument as r } from "../../generated/wspace-operations.js";
2
+ import { useWorkspaceAllPagesQuery as i, useWorkspaceClient as a, useWorkspaceId as o, useWorkspaceMutation as s, useWorkspaceQuery as c } from "./internal/workspaceGateway.js";
3
+ import { useCallback as l, useEffect as u, useMemo as d, useState as f } from "react";
4
+ // src/botlit/hooks/useAssistantChat.ts
5
+ var p = "botmanor", m = {}, h = 100, g = [];
6
+ function _() {
7
+ let t = o(), n = d(() => ({ filters: { workspaceId: t } }), [t]);
8
+ return i({
9
+ document: e,
10
+ variables: n,
11
+ pageSize: h,
12
+ extractRows: (e) => e?.listBotmanorAgents ?? [],
13
+ select: (e) => e,
14
+ fallback: g,
15
+ enabled: !!t,
16
+ errorMessage: "Failed to load assistants"
17
+ });
18
+ }
19
+ function v() {
20
+ let e = o();
21
+ return c({
22
+ document: t,
23
+ variables: m,
24
+ select: (e) => e ? e.myAssistantConversationRetention.conversationRetentionDays ?? null : void 0,
25
+ fallback: void 0,
26
+ enabled: !!e,
27
+ errorMessage: "Failed to load the conversation retention"
28
+ });
29
+ }
30
+ var y = [], b = 50;
31
+ function x(e) {
32
+ let t = o(), r = a(), i = !!(t && e), [s, c] = f(y), [d, p] = f(i), [m, h] = f(), g = l(async () => {
33
+ if (!i) c(y), h(void 0), p(!1);
34
+ else {
35
+ p(!0), h(void 0);
36
+ try {
37
+ let t = [], i = null;
38
+ for (let a = 0; a < b; a += 1) {
39
+ let a = await r.query({
40
+ query: n,
41
+ variables: {
42
+ agentId: e,
43
+ after: i
44
+ },
45
+ fetchPolicy: "network-only"
46
+ });
47
+ if (a.error) throw a.error;
48
+ let o = a.data?.myAssistantWorkflowConversations;
49
+ if (!o) throw Error("Failed to load your conversations");
50
+ if (t.push(...o.nodes), i = o.nextCursor ?? null, !i) break;
51
+ }
52
+ c(t);
53
+ } catch (e) {
54
+ h(e instanceof Error ? e : Error("Failed to load your conversations", { cause: e }));
55
+ } finally {
56
+ p(!1);
57
+ }
58
+ }
59
+ }, [
60
+ r,
61
+ i,
62
+ e
63
+ ]);
64
+ return u(() => {
65
+ g();
66
+ }, [g]), {
67
+ data: s,
68
+ loading: d,
69
+ error: m,
70
+ refetch: g
71
+ };
72
+ }
73
+ function S() {
74
+ let [e, t] = s({
75
+ document: r,
76
+ variables: (e) => ({
77
+ productId: p,
78
+ clientConversationId: e
79
+ }),
80
+ select: (e) => e?.retireMyGroundedAssistantConversation,
81
+ errorMessage: "Failed to delete the conversation"
82
+ }), [n, i] = f(null);
83
+ return {
84
+ remove: l(async (t) => {
85
+ i(t);
86
+ try {
87
+ if (!await e(t)) throw Error("Failed to delete the conversation");
88
+ } finally {
89
+ i(null);
90
+ }
91
+ }, [e]),
92
+ deletingId: n,
93
+ error: t.error
94
+ };
95
+ }
96
+ export { p as BOTMANOR_ASSISTANT_PRODUCT_ID, _ as useChatAssistants, S as useDeleteMyAssistantConversation, x as useMyAssistantConversations, v as useMyAssistantRetention };
97
+
98
+ //# sourceMappingURL=useAssistantChat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAssistantChat.js","names":["BOTMANOR_ASSISTANT_PRODUCT_ID","NO_VARIABLES","PAGE_SIZE","NO_ASSISTANTS","useChatAssistants","workspaceId","useWorkspaceId","variables","useMemo","useWorkspaceAllPagesQuery","ChatAssistantsDocument","data","rows","useMyAssistantRetention","useWorkspaceQuery","MyAssistantConversationRetentionDocument","NO_CONVERSATIONS","MAX_CONVERSATION_PAGES","useMyAssistantConversations","client","useWorkspaceClient","enabled","agentId","setData","useState","loading","setLoading","error","setError","refetch","useCallback","after","page","result","MyAssistantWorkflowConversationsDocument","connection","cause","useEffect","useDeleteMyAssistantConversation","retire","state","useWorkspaceMutation","RetireMyAssistantConversationDocument","deletingId","setDeletingId","clientConversationId"],"sources":["../../../src/botlit/hooks/useAssistantChat.ts"],"sourcesContent":["/**\n * AI Chat page hooks (BOFF-12695)\n * @module botlit/hooks\n *\n * The assistants a saved chat can use, the retention that applies to the\n * caller's saved conversations, and the caller's own conversations so they\n * can be deleted. Conversations are owner-scoped on the server: the caller\n * only ever sees and deletes their own.\n */\n\nimport { useCallback, useEffect, useMemo, useState } from 'react';\n\nimport {\n ChatAssistantsDocument,\n MyAssistantConversationRetentionDocument,\n MyAssistantWorkflowConversationsDocument,\n RetireMyAssistantConversationDocument,\n type ChatAssistantsQuery,\n type MyAssistantConversationRetentionQuery,\n type MyAssistantWorkflowConversationsQuery,\n type RetireMyAssistantConversationMutation,\n} from '../../generated/wspace-operations';\nimport {\n useWorkspaceAllPagesQuery,\n useWorkspaceClient,\n useWorkspaceId,\n useWorkspaceMutation,\n useWorkspaceQuery,\n type QueryResult,\n} from './internal/workspaceGateway';\n\n/** The product id saved BotManor agent chats are stored under. */\nexport const BOTMANOR_ASSISTANT_PRODUCT_ID = 'botmanor';\n\nconst NO_VARIABLES: Record<string, unknown> = {};\nconst PAGE_SIZE = 100;\n\nexport type ChatAssistantRecord = ChatAssistantsQuery['listBotmanorAgents'][number];\n\nconst NO_ASSISTANTS: ChatAssistantRecord[] = [];\n\n/**\n * Every agent in the workspace, with the fields that decide whether a saved\n * chat can use it. Not filtered by status, so an inactive agent still reaches\n * the picker's \"not available\" group with its reason.\n */\nexport function useChatAssistants(): QueryResult<ChatAssistantRecord[]> {\n const workspaceId = useWorkspaceId();\n const variables = useMemo(() => ({ filters: { workspaceId } }), [workspaceId]);\n return useWorkspaceAllPagesQuery<ChatAssistantsQuery, ChatAssistantRecord, ChatAssistantRecord[]>(\n {\n document: ChatAssistantsDocument,\n variables,\n pageSize: PAGE_SIZE,\n extractRows: (data) => data?.listBotmanorAgents ?? [],\n select: (rows) => rows,\n fallback: NO_ASSISTANTS,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load assistants',\n }\n );\n}\n\n/**\n * Days after which the caller's saved conversations are retired: a number,\n * null when no period applies, or undefined until the server has answered.\n * Undefined is never shown as \"no period\" (BOFF-12699).\n */\nexport function useMyAssistantRetention(): QueryResult<number | null | undefined> {\n const workspaceId = useWorkspaceId();\n return useWorkspaceQuery<MyAssistantConversationRetentionQuery, number | null | undefined>({\n document: MyAssistantConversationRetentionDocument,\n variables: NO_VARIABLES,\n select: (data) =>\n data ? (data.myAssistantConversationRetention.conversationRetentionDays ?? null) : undefined,\n fallback: undefined,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load the conversation retention',\n });\n}\n\nexport interface AssistantConversationSummary {\n clientConversationId: string;\n createdAt: string;\n}\n\nconst NO_CONVERSATIONS: AssistantConversationSummary[] = [];\n\n/** Upper bound on pages followed, so a misbehaving cursor cannot loop forever. */\nconst MAX_CONVERSATION_PAGES = 50;\n\n/**\n * The caller's own saved conversations with one agent, newest first. Follows\n * `nextCursor` until the last page, so older conversations can be deleted too.\n */\nexport function useMyAssistantConversations(\n agentId: string | undefined\n): QueryResult<AssistantConversationSummary[]> {\n const workspaceId = useWorkspaceId();\n const client = useWorkspaceClient();\n const enabled = Boolean(workspaceId && agentId);\n const [data, setData] = useState<AssistantConversationSummary[]>(NO_CONVERSATIONS);\n const [loading, setLoading] = useState(enabled);\n const [error, setError] = useState<Error | undefined>();\n\n const refetch = useCallback(async () => {\n if (!enabled) {\n setData(NO_CONVERSATIONS);\n setError(undefined);\n setLoading(false);\n return;\n }\n setLoading(true);\n setError(undefined);\n try {\n const rows: AssistantConversationSummary[] = [];\n let after: string | null = null;\n for (let page = 0; page < MAX_CONVERSATION_PAGES; page += 1) {\n const result: { data?: MyAssistantWorkflowConversationsQuery; error?: Error } =\n await client.query<MyAssistantWorkflowConversationsQuery>({\n query: MyAssistantWorkflowConversationsDocument,\n variables: { agentId, after },\n fetchPolicy: 'network-only',\n });\n if (result.error) throw result.error;\n const connection:\n MyAssistantWorkflowConversationsQuery['myAssistantWorkflowConversations'] | undefined =\n result.data?.myAssistantWorkflowConversations;\n if (!connection) throw new Error('Failed to load your conversations');\n rows.push(...connection.nodes);\n after = connection.nextCursor ?? null;\n if (!after) break;\n }\n setData(rows);\n } catch (cause) {\n setError(\n cause instanceof Error ? cause : new Error('Failed to load your conversations', { cause })\n );\n } finally {\n setLoading(false);\n }\n }, [client, enabled, agentId]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\n/** Deletes one of the caller's saved conversations. Resolves only when the server confirmed it. */\nexport function useDeleteMyAssistantConversation() {\n const [retire, state] = useWorkspaceMutation<\n RetireMyAssistantConversationMutation,\n string,\n boolean\n >({\n document: RetireMyAssistantConversationDocument,\n variables: (clientConversationId) => ({\n productId: BOTMANOR_ASSISTANT_PRODUCT_ID,\n clientConversationId,\n }),\n select: (data) => data?.retireMyGroundedAssistantConversation,\n errorMessage: 'Failed to delete the conversation',\n });\n const [deletingId, setDeletingId] = useState<string | null>(null);\n const remove = useCallback(\n async (clientConversationId: string) => {\n setDeletingId(clientConversationId);\n try {\n const deleted = await retire(clientConversationId);\n if (!deleted) throw new Error('Failed to delete the conversation');\n } finally {\n setDeletingId(null);\n }\n },\n [retire]\n );\n return { remove, deletingId, error: state.error };\n}\n"],"mappings":";;;;AAgCA,IAAaA,IAAgC,YAEvCC,IAAwC,CAAC,GACzCC,IAAY,KAIZC,IAAuC,CAAC;AAO9C,SAAgBC,IAAwD;CACtE,IAAMC,IAAcC,EAAe,GAC7BC,IAAYC,SAAe,EAAE,SAAS,EAAE,eAAY,EAAE,IAAI,CAACH,CAAW,CAAC;CAC7E,OAAOI,EACL;EACE,UAAUC;EACV;EACA,UAAUR;EACV,cAAc,MAASS,GAAM,sBAAsB,CAAC;EACpD,SAAS,MAASC;EAClB,UAAUT;EACV,SAAS,EAAQE;EACjB,cAAc;CAChB,CACF;AACF;AAOA,SAAgBQ,IAAkE;CAChF,IAAMR,IAAcC,EAAe;CACnC,OAAOQ,EAAoF;EACzF,UAAUC;EACV,WAAWd;EACX,SAAS,MACPU,IAAQA,EAAK,iCAAiC,6BAA6B,OAAQ,KAAA;EACrF,UAAU,KAAA;EACV,SAAS,EAAQN;EACjB,cAAc;CAChB,CAAC;AACH;AAOA,IAAMW,IAAmD,CAAC,GAGpDC,IAAyB;AAM/B,SAAgBC,EACd,GAC6C;CAC7C,IAAMb,IAAcC,EAAe,GAC7Ba,IAASC,EAAmB,GAC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KAAiBpB,EAAwB,IAAI;CAahE,OAAO;EAAE,QAZMM,EACb,OAAO,MAAiC;GACtC,EAAce,CAAoB;GAClC,IAAI;IAEF,IAAI,CAAC,MADiBN,EAAOM,CAAoB,GACnC,MAAU,MAAM,mCAAmC;GACnE,UAAU;IACR,EAAc,IAAI;GACpB;EACF,GACA,CAACN,CAAM,CAEA;EAAQ;EAAY,OAAOC,EAAM;CAAM;AAClD"}
@@ -1,9 +1,10 @@
1
- import { CreateExecutionDocument as e, GetExecutionDocument as t, ListExecutionsDocument as n } from "../../generated/wspace-operations.js";
2
- import { buildMutationInput as r, fieldsOf as i } from "./internal/mutationInput.js";
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";
1
+ import { GetExecutionDocument as e, ListExecutionsDocument as t } from "../../generated/wspace-operations.js";
2
+ import { fieldsOf as n } from "./internal/mutationInput.js";
3
+ import { useWorkspaceId as r, useWorkspacePaginatedQuery as i, useWorkspaceQuery as a } from "./internal/workspaceGateway.js";
4
+ import { useCallback as o, useMemo as s } from "react";
5
5
  // src/botlit/hooks/useExecutions.ts
6
- var d = 100, f = i({
6
+ var c = 100;
7
+ n({
7
8
  agentId: !0,
8
9
  appId: !0,
9
10
  conversationId: !0,
@@ -11,54 +12,55 @@ var d = 100, f = i({
11
12
  metadata: !0,
12
13
  type: !0,
13
14
  workspaceId: !0
14
- }), p = /* @__PURE__ */ new Set(["COMPLETED"]), m = [];
15
- function h(e, t) {
15
+ });
16
+ var l = /* @__PURE__ */ new Set(["COMPLETED"]), u = [];
17
+ function d(e, t) {
16
18
  return e.id.toLowerCase().includes(t) || (e.agentId ?? "").toLowerCase().includes(t) || (e.appId ?? "").toLowerCase().includes(t) || e.input.toLowerCase().includes(t);
17
19
  }
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,
20
+ function f(e) {
21
+ let n = r(), a = e?.search?.trim().toLowerCase() ?? "", l = e?.status, f = l?.length === 1 ? l[0] : void 0, p = l?.join(",") ?? "", { agentId: m, appId: h, conversationId: g, type: _ } = e ?? {}, v = s(() => ({ filters: {
22
+ workspaceId: n,
23
+ status: f,
24
+ agentId: m,
25
+ appId: h,
24
26
  conversationId: g,
25
27
  type: _
26
28
  } }), [
27
- t,
28
- o,
29
+ n,
29
30
  f,
30
- p,
31
+ m,
32
+ h,
31
33
  g,
32
34
  _
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]);
37
- return s({
38
- document: n,
35
+ ]), y = o((e) => {
36
+ let t = p ? new Set(p.split(",")) : void 0, n = t && t.size > 1 ? e.filter((e) => t.has(e.status)) : e;
37
+ return a ? n.filter((e) => d(e, a)) : n;
38
+ }, [a, p]);
39
+ return i({
40
+ document: t,
39
41
  variables: v,
40
- pageSize: d,
41
- extractRows: (e) => e?.listExecutions ?? m,
42
+ pageSize: c,
43
+ extractRows: (e) => e?.listExecutions ?? u,
42
44
  select: y,
43
- fallback: m,
44
- enabled: !!t,
45
+ fallback: u,
46
+ enabled: !!n,
45
47
  errorMessage: "Failed to load executions"
46
48
  });
47
49
  }
48
- function _(e) {
49
- let n = u(() => ({ id: e ?? "" }), [e]);
50
- return c({
51
- document: t,
50
+ function p(t) {
51
+ let n = s(() => ({ id: t ?? "" }), [t]);
52
+ return a({
53
+ document: e,
52
54
  variables: n,
53
55
  select: (e) => e?.getExecution ?? null,
54
56
  fallback: null,
55
- enabled: !!e,
57
+ enabled: !!t,
56
58
  errorMessage: "Failed to load execution"
57
59
  });
58
60
  }
59
- function v(e) {
61
+ function m(e) {
60
62
  let t = e.length, n = 0, r = 0, i = 0, a = 0, o = 0, s = 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;
63
+ for (let t of e) l.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;
62
64
  return {
63
65
  total: t,
64
66
  succeeded: n,
@@ -69,14 +71,6 @@ function v(e) {
69
71
  totalTokens: s
70
72
  };
71
73
  }
72
- function y() {
73
- return o({
74
- document: e,
75
- variables: ({ input: e }) => ({ input: r(e, f) }),
76
- select: (e) => e?.createExecution,
77
- errorMessage: "Failed to start execution"
78
- });
79
- }
80
- export { v as summariseExecutions, y as useCreateExecution, _ as useExecution, g as useExecutions };
74
+ export { m as summariseExecutions, p as useExecution, f as useExecutions };
81
75
 
82
76
  //# 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","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,S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B,CAAC;AACH;AA0CA,SAAgBG,EAAoB,GAAyD;CAC3F,IAAMC,IAAQC,EAAW,QACrBC,IAAY,GACZC,IAAS,GACTC,IAAc,GACdC,IAAgB,GAChBC,IAAY,GACZC,IAAc;CAElB,KAAK,IAAMrC,KAAa+B,GAQtB,AAPIlC,EAAiB,IAAIG,EAAU,MAAM,MAAG,KAAa,KACrDA,EAAU,WAAW,YAAYA,EAAU,WAAW,eAAW,KAAU,IAC3E,OAAOA,EAAU,YAAa,aAChC,KAAeA,EAAU,UACzB,KAAiB,IAEnB,KAAaA,EAAU,QAAQ,GAC/B,KAAeA,EAAU,cAAc;CAGzC,OAAO;EACL;EACA;EACA;EACA,aAAa8B,IAAQ,IAAIE,IAAYF,IAAQ;EAC7C,eAAeK,IAAgB,IAAID,IAAcC,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
+ {"version":3,"file":"useExecutions.js","names":["LIST_LIMIT","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"],"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;AAqDaC,EAA+B;CAC7D,SAAS;CACT,OAAO;CACP,gBAAgB;CAChB,OAAO;CACP,UAAU;CACV,MAAM;CACN,aAAa;AACf,CAAC;AAUD,IAAMC,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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IAAY,GACZC,IAAS,GACTC,IAAc,GACdC,IAAgB,GAChBC,IAAY,GACZC,IAAc;CAElB,KAAK,IAAMrC,KAAa+B,GAQtB,AAPIlC,EAAiB,IAAIG,EAAU,MAAM,MAAG,KAAa,KACrDA,EAAU,WAAW,YAAYA,EAAU,WAAW,eAAW,KAAU,IAC3E,OAAOA,EAAU,YAAa,aAChC,KAAeA,EAAU,UACzB,KAAiB,IAEnB,KAAaA,EAAU,QAAQ,GAC/B,KAAeA,EAAU,cAAc;CAGzC,OAAO;EACL;EACA;EACA;EACA,aAAa8B,IAAQ,IAAIE,IAAYF,IAAQ;EAC7C,eAAeK,IAAgB,IAAID,IAAcC,IAAgB;EACjE;EACA;CACF;AACF"}
@@ -0,0 +1,5 @@
1
+ export interface RerunExecutionResult {
2
+ id: string;
3
+ status: string;
4
+ }
5
+ export declare function useRerunExecution(): import('@tanstack/react-query').UseMutationResult<RerunExecutionResult, Error, string, unknown>;
@@ -0,0 +1,29 @@
1
+ import { graphqlErrorMessage as e } from "../utils/errors.js";
2
+ import { gql as t } from "@apollo/client";
3
+ import { useGatewayClient as n } from "@burdenoff/fe-libs/shared/graphql";
4
+ import { useMutation as r } from "@tanstack/react-query";
5
+ // src/botlit/hooks/useRerunExecution.ts
6
+ var i = t`
7
+ mutation RerunExecution($id: ID!) {
8
+ rerunExecution(id: $id) {
9
+ id
10
+ status
11
+ }
12
+ }
13
+ `;
14
+ function a() {
15
+ let t = n("workspace");
16
+ return r({ mutationFn: async (n) => {
17
+ let r = await t.mutate({
18
+ mutation: i,
19
+ variables: { id: n }
20
+ }), a = r.error;
21
+ if (a != null) throw Error(e(a, "Failed to re-run execution"));
22
+ let o = r.data?.rerunExecution;
23
+ if (!o) throw Error("Failed to re-run execution");
24
+ return o;
25
+ } });
26
+ }
27
+ export { a as useRerunExecution };
28
+
29
+ //# sourceMappingURL=useRerunExecution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRerunExecution.js","names":["RERUN_EXECUTION","useRerunExecution","client","useGatewayClient","useMutation","response","operationError","graphqlErrorMessage","created"],"sources":["../../../src/botlit/hooks/useRerunExecution.ts"],"sourcesContent":["/**\n * Run an execution again (BOFF-15360).\n *\n * `rerunExecution` copies the stored run's input, agent and bot into a new\n * PENDING execution, returns it at once and runs it in the background, so the\n * request stays well inside the gateway timeout. Creating a copy with\n * `createExecution` alone left the new run PENDING until the reaper marked it\n * ORPHANED, because nothing dispatched it.\n *\n * @module botlit/hooks/useRerunExecution\n */\nimport { gql } from '@apollo/client';\nimport { useMutation } from '@tanstack/react-query';\nimport { useGatewayClient } from '@burdenoff/fe-libs/shared/graphql';\nimport { graphqlErrorMessage } from '../utils/errors';\n\nconst RERUN_EXECUTION = gql`\n mutation RerunExecution($id: ID!) {\n rerunExecution(id: $id) {\n id\n status\n }\n }\n`;\n\nexport interface RerunExecutionResult {\n id: string;\n status: string;\n}\n\nexport function useRerunExecution() {\n const client = useGatewayClient('workspace');\n return useMutation({\n mutationFn: async (id: string): Promise<RerunExecutionResult> => {\n const response = await client.mutate<{ rerunExecution: RerunExecutionResult }>({\n mutation: RERUN_EXECUTION,\n variables: { id },\n });\n // Apollo v4 resolves (not rejects) with `error` set on GraphQL errors.\n const operationError = (response as { error?: unknown }).error;\n if (operationError != null)\n throw new Error(graphqlErrorMessage(operationError, 'Failed to re-run execution'));\n const created = response.data?.rerunExecution;\n if (!created) throw new Error('Failed to re-run execution');\n return created;\n },\n });\n}\n"],"mappings":";;;;;AAgBA,IAAMA,IAAkB,CAAG;;;;;;;;AAc3B,SAAgBC,IAAoB;CAClC,IAAMC,IAASC,EAAiB,WAAW;CAC3C,OAAOC,EAAY,EACjB,YAAY,OAAO,MAA8C;EAC/D,IAAMC,IAAW,MAAMH,EAAO,OAAiD;GAC7E,UAAUF;GACV,WAAW,EAAE,MAAG;EAClB,CAAC,GAEKM,IAAkBD,EAAiC;EACzD,IAAIC,KAAkB,MACpB,MAAU,MAAMC,EAAoBD,GAAgB,4BAA4B,CAAC;EACnF,IAAME,IAAUH,EAAS,MAAM;EAC/B,IAAI,CAACG,GAAS,MAAU,MAAM,4BAA4B;EAC1D,OAAOA;CACT,EACF,CAAC;AACH"}