@burdenoff/microfe-botmanor 2026.1118.6 → 2026.1118.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/botlit/components/AgentBindingsPanel.d.ts +4 -0
- package/dist/botlit/components/AgentBindingsPanel.js +305 -0
- package/dist/botlit/components/AgentBindingsPanel.js.map +1 -0
- package/dist/botlit/components/ChannelSelectorSheet.d.ts +9 -2
- package/dist/botlit/components/ChannelSelectorSheet.js.map +1 -1
- package/dist/botlit/hooks/index.d.ts +3 -1
- package/dist/botlit/hooks/index.js +14 -13
- package/dist/botlit/hooks/internal/globalWorkspaceScope.d.ts +15 -0
- package/dist/botlit/hooks/internal/globalWorkspaceScope.js +21 -0
- package/dist/botlit/hooks/internal/globalWorkspaceScope.js.map +1 -0
- package/dist/botlit/hooks/internal/workspaceGateway.d.ts +7 -0
- package/dist/botlit/hooks/internal/workspaceGateway.js +42 -22
- package/dist/botlit/hooks/internal/workspaceGateway.js.map +1 -1
- package/dist/botlit/hooks/useAgentBindings.d.ts +58 -0
- package/dist/botlit/hooks/useAgentBindings.js +87 -0
- package/dist/botlit/hooks/useAgentBindings.js.map +1 -0
- package/dist/botlit/hooks/useChannelSetup.d.ts +2 -1
- package/dist/botlit/hooks/useChannelSetup.js +61 -52
- package/dist/botlit/hooks/useChannelSetup.js.map +1 -1
- package/dist/botlit/hooks/useChannels.d.ts +9 -0
- package/dist/botlit/hooks/useChannels.js +83 -73
- package/dist/botlit/hooks/useChannels.js.map +1 -1
- package/dist/botlit/hooks/useUserPlatformConnection.js +98 -78
- package/dist/botlit/hooks/useUserPlatformConnection.js.map +1 -1
- package/dist/botlit/pages/AgentDetailPage.js +56 -55
- package/dist/botlit/pages/AgentDetailPage.js.map +1 -1
- package/dist/botlit/pages/BotChannelsTab.js +457 -242
- package/dist/botlit/pages/BotChannelsTab.js.map +1 -1
- package/dist/botlit/pages/PromptStudioPage.js +365 -175
- package/dist/botlit/pages/PromptStudioPage.js.map +1 -1
- package/dist/botlit/permissions/index.js +3 -3
- package/dist/botlit/permissions/useBotmanorPermissions.js +5 -2
- package/dist/botlit/permissions/useBotmanorPermissions.js.map +1 -1
- package/dist/botlit/utils/promptVariables.d.ts +6 -0
- package/dist/botlit/utils/promptVariables.js +20 -0
- package/dist/botlit/utils/promptVariables.js.map +1 -0
- package/dist/generated/wspace-operations.d.ts +314 -0
- package/dist/generated/wspace-operations.js +189 -101
- package/dist/generated/wspace-operations.js.map +1 -1
- package/dist/generated/wspace-types.d.ts +139 -0
- package/dist/generated/wspace-types.js +3 -1
- package/dist/generated/wspace-types.js.map +1 -1
- package/package.json +1 -1
|
@@ -58,10 +58,11 @@ function f(e) {
|
|
|
58
58
|
}
|
|
59
59
|
var p = [];
|
|
60
60
|
function m(e) {
|
|
61
|
-
let { document: t, variables: i, pageSize: s, enabled: l, errorMessage: f } = e, m = c(), h = d(e.select), g = d(e.extractRows), [_, v] = o([]), y = a([]), [b, x] = o(e.fallback), [S, C] = o(!1), [w, T] = o(!1), [E, D] = o(!0), [O, k] = o(), A = n((e) => {
|
|
61
|
+
let { document: t, variables: i, pageSize: s, enabled: l, errorMessage: f } = e, m = c(), h = d(e.select), g = d(e.extractRows), [_, v] = o([]), y = a([]), [b, x] = o(e.fallback), [S, C] = o(!1), [w, T] = o(!1), [E, D] = o(!0), [O, k] = o(), A = a(0), j = n((e) => {
|
|
62
62
|
y.current = e, v(e), x(h.current(e));
|
|
63
|
-
}, [h]),
|
|
64
|
-
n ?
|
|
63
|
+
}, [h]), M = n(async (e, n) => {
|
|
64
|
+
let r = n ? A.current : ++A.current, a = () => r === A.current;
|
|
65
|
+
n ? T(!0) : (C(!0), T(!1)), k(void 0);
|
|
65
66
|
try {
|
|
66
67
|
let r = await m.query({
|
|
67
68
|
query: t,
|
|
@@ -73,14 +74,16 @@ function m(e) {
|
|
|
73
74
|
}
|
|
74
75
|
},
|
|
75
76
|
fetchPolicy: "network-only"
|
|
76
|
-
})
|
|
77
|
-
if (a
|
|
78
|
-
let o =
|
|
79
|
-
|
|
77
|
+
});
|
|
78
|
+
if (!a()) return;
|
|
79
|
+
let o = r.error;
|
|
80
|
+
if (o != null) throw u(o, f);
|
|
81
|
+
let c = g.current(r.data ?? void 0) ?? [];
|
|
82
|
+
j(n ? [...y.current, ...c] : c), D(c.length < s);
|
|
80
83
|
} catch (e) {
|
|
81
|
-
k(u(e, f));
|
|
84
|
+
a() && k(u(e, f));
|
|
82
85
|
} finally {
|
|
83
|
-
n ? T(!1) : C(!1);
|
|
86
|
+
a() && (n ? T(!1) : C(!1));
|
|
84
87
|
}
|
|
85
88
|
}, [
|
|
86
89
|
m,
|
|
@@ -89,33 +92,50 @@ function m(e) {
|
|
|
89
92
|
s,
|
|
90
93
|
f,
|
|
91
94
|
g,
|
|
92
|
-
|
|
93
|
-
]),
|
|
94
|
-
l ? await
|
|
95
|
+
j
|
|
96
|
+
]), N = n(async () => {
|
|
97
|
+
l ? await M(0, !1) : (j(p), D(!0), k(void 0));
|
|
95
98
|
}, [
|
|
96
99
|
l,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
]),
|
|
100
|
-
l && !E && await
|
|
100
|
+
M,
|
|
101
|
+
j
|
|
102
|
+
]), P = n(async () => {
|
|
103
|
+
l && !E && await M(y.current.length, !0);
|
|
101
104
|
}, [
|
|
102
105
|
l,
|
|
103
106
|
E,
|
|
104
|
-
|
|
107
|
+
M
|
|
105
108
|
]);
|
|
106
109
|
return r(() => {
|
|
107
|
-
|
|
108
|
-
}, [
|
|
110
|
+
N();
|
|
111
|
+
}, [N]), {
|
|
109
112
|
data: b,
|
|
110
113
|
loading: S,
|
|
111
114
|
loadingMore: w,
|
|
112
115
|
hasMore: !E,
|
|
113
116
|
error: O,
|
|
114
|
-
refetch:
|
|
115
|
-
loadMore:
|
|
117
|
+
refetch: N,
|
|
118
|
+
loadMore: P
|
|
116
119
|
};
|
|
117
120
|
}
|
|
118
121
|
function h(e) {
|
|
122
|
+
let { data: t, loading: n, loadingMore: i, hasMore: a, error: o, refetch: s, loadMore: c } = m(e);
|
|
123
|
+
return r(() => {
|
|
124
|
+
a && !n && !i && !o && c();
|
|
125
|
+
}, [
|
|
126
|
+
a,
|
|
127
|
+
n,
|
|
128
|
+
i,
|
|
129
|
+
o,
|
|
130
|
+
c
|
|
131
|
+
]), {
|
|
132
|
+
data: t,
|
|
133
|
+
loading: n || i || a && !o,
|
|
134
|
+
error: o,
|
|
135
|
+
refetch: s
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function g(e) {
|
|
119
139
|
let { document: t, errorMessage: r } = e, i = c(), a = d(e.variables), s = d(e.select), [l, f] = o({
|
|
120
140
|
data: void 0,
|
|
121
141
|
loading: !1,
|
|
@@ -156,6 +176,6 @@ function h(e) {
|
|
|
156
176
|
a
|
|
157
177
|
]), l];
|
|
158
178
|
}
|
|
159
|
-
export { c as useWorkspaceClient, l as useWorkspaceId,
|
|
179
|
+
export { h as useWorkspaceAllPagesQuery, c as useWorkspaceClient, l as useWorkspaceId, g as useWorkspaceMutation, m as useWorkspacePaginatedQuery, f as useWorkspaceQuery };
|
|
160
180
|
|
|
161
181
|
//# sourceMappingURL=workspaceGateway.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspaceGateway.js","names":["useWorkspaceClient","useGatewayClient","useWorkspaceId","useBotlit","toError","message","extractGraphqlFailureMessage","cause","fallbackMessage","useLatest","ref","useRef","value","useLayoutEffect","useWorkspaceQuery","options","client","selectRef","fallbackRef","data","setData","useState","loading","setLoading","error","setError","refetch","useCallback","enabled","result","document","operationError","errorMessage","queryError","variables","useEffect","NO_ROWS","useWorkspacePaginatedQuery","extractRowsRef","rows","setRows","rowsRef","loadingMore","setLoadingMore","exhausted","setExhausted","replaceRows","next","fetchPage","append","pageSize","pageRows","loadMore","useWorkspaceMutation","variablesRef","state","setState","input","selected","mutationError","failure"],"sources":["../../../../src/botlit/hooks/internal/workspaceGateway.ts"],"sourcesContent":["/**\n * Workspace gateway hook primitives\n * @module botlit/hooks/internal\n *\n * Every BotManor hook talks to the workspace public gateway through the Apollo\n * client the shell installs (`useGatewayClient('workspace')`) — never through a\n * client of its own. These primitives capture the exact shape used by the\n * reference hooks (`useAgents`, `useBots`): `network-only` reads, an explicit\n * `Error` in state rather than a thrown promise, and a `refetch` the caller can\n * run after a mutation.\n */\n\nimport type { ApolloClient, DocumentNode } from '@apollo/client';\nimport { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';\nimport { useGatewayClient } from '@burdenoff/fe-libs/shared/graphql';\n\nimport { useBotlit } from '../../providers/BotlitProvider';\nimport { extractGraphqlFailureMessage } from '../../utils/errors';\n\nexport type WorkspaceClient = ApolloClient;\n\n/** Apollo client for the workspace gateway, provided by the host shell. */\nexport function useWorkspaceClient(): WorkspaceClient {\n return useGatewayClient('workspace');\n}\n\n/** Current workspace id from the BotManor context (undefined until the shell resolves it). */\nexport function useWorkspaceId(): string | undefined {\n return useBotlit().workspaceId;\n}\n\nexport interface QueryResult<T> {\n data: T;\n loading: boolean;\n /** Set only when the request FAILED. An empty `data` with no `error` means \"no records yet\". */\n error: Error | undefined;\n refetch: () => Promise<void>;\n}\n\nexport interface PaginatedQueryResult<T> extends QueryResult<T> {\n /** True while the next page is being appended. */\n loadingMore: boolean;\n /**\n * True when the most recent page came back full, i.e. another page may\n * exist. False before the first page resolves and once a short page\n * (or an empty one) marks the end of the list.\n */\n hasMore: boolean;\n /**\n * Fetches the next page (current row count as offset) and appends it.\n * No-op while a fetch is in flight or when `hasMore` is false.\n */\n loadMore: () => Promise<void>;\n}\n\nexport interface MutationState<T> {\n data: T | undefined;\n loading: boolean;\n error: Error | undefined;\n}\n\n/**\n * Normalises any mutation failure to an Error with the server's\n * user-actionable message where one exists.\n *\n * Apollo Client v4 does not reject with a plain Error: failures arrive as\n * `{ networkError }` / `{ graphQLErrors }` objects, and the batched fetch\n * layer attaches the structured GraphQL errors as `.errors` on the\n * networkError. `extractGraphqlFailureMessage` unwraps all of those; only\n * when nothing user-actionable is present do we fall back to the hook's\n * generic `errorMessage`.\n */\nfunction toError(cause: unknown, fallbackMessage: string): Error {\n const message = extractGraphqlFailureMessage(cause);\n if (message) {\n // Preserve the original rejection on the chain so error monitoring can\n // still reach the structured GraphQL errors (extensions.code, requestId…).\n return new Error(message, { cause });\n }\n if (cause instanceof Error) return cause;\n return new Error(fallbackMessage, { cause });\n}\n\n/** Keeps a mutable ref pointing at the latest value without re-running effects. */\nfunction useLatest<T>(value: T): { readonly current: T } {\n const ref = useRef(value);\n useLayoutEffect(() => {\n ref.current = value;\n }, [value]);\n return ref;\n}\n\nexport interface WorkspaceQueryOptions<TData, TResult> {\n /** Generated GraphQL document (see `src/generated/wspace-operations.ts`). */\n document: DocumentNode;\n /** Must be referentially stable — memoize at the call site. */\n variables: Record<string, unknown> | undefined;\n /** Projects the raw payload onto the record shape the UI consumes. */\n select: (data: TData | undefined) => TResult;\n /** Value held while disabled or before the first successful read. */\n fallback: TResult;\n /** When false the request is skipped (e.g. no workspace id / no entity id yet). */\n enabled: boolean;\n /** Used when the thrown value is not an Error. */\n errorMessage: string;\n}\n\n/**\n * Reads from the workspace gateway and keeps `{ data, loading, error, refetch }`\n * in sync. `error` is reserved for real failures so callers can tell an empty\n * collection apart from a failed request.\n */\nexport function useWorkspaceQuery<TData, TResult>(\n options: WorkspaceQueryOptions<TData, TResult>\n): QueryResult<TResult> {\n const { document, variables, enabled, errorMessage } = options;\n const client = useWorkspaceClient();\n const selectRef = useLatest(options.select);\n const fallbackRef = useLatest(options.fallback);\n\n const [data, setData] = useState<TResult>(options.fallback);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n\n const refetch = useCallback(async () => {\n if (!enabled) {\n setData(fallbackRef.current);\n setError(undefined);\n return;\n }\n\n setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<TData>({\n query: document,\n variables,\n fetchPolicy: 'network-only',\n });\n // Apollo v4 resolves (not rejects) with `result.error` set on GraphQL\n // errors — same handling as useWorkspaceMutation.\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw toError(operationError, errorMessage);\n }\n setData(selectRef.current(result.data ?? undefined));\n } catch (queryError) {\n setData(fallbackRef.current);\n setError(toError(queryError, errorMessage));\n } finally {\n setLoading(false);\n }\n // fallbackRef/selectRef are stable refs by construction\n }, [client, document, variables, enabled, errorMessage, fallbackRef, selectRef]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\n/** Shared empty page, so a disabled paginated query keeps one stable value. */\nconst NO_ROWS: never[] = [];\n\nexport interface WorkspacePaginatedQueryOptions<TData, TRow, TResult> {\n /** Generated GraphQL document (see `src/generated/wspace-operations.ts`). */\n document: DocumentNode;\n /**\n * Base variables (filters, ids, …) WITHOUT `pagination` — the hook adds\n * `{ limit: pageSize, offset }` per fetch. Must be referentially stable;\n * a new identity resets the accumulation back to page one.\n */\n variables: Record<string, unknown> | undefined;\n /** Page size for each fetch. */\n pageSize: number;\n /** Extracts the raw row list from a page payload; missing data yields []. */\n extractRows: (data: TData | undefined) => TRow[] | undefined;\n /** Projects the ACCUMULATED raw rows onto the record shape the UI consumes. */\n select: (rows: TRow[]) => TResult;\n /** Value held while disabled or before the first successful read. */\n fallback: TResult;\n /** When false the request is skipped (e.g. no workspace id yet). */\n enabled: boolean;\n /** Used when the thrown value is not an Error. */\n errorMessage: string;\n}\n\n/**\n * Offset-paginated variant of `useWorkspaceQuery` for unbounded lists.\n *\n * `refetch()` restarts at offset 0 and REPLACES the accumulated rows;\n * `loadMore()` fetches the next page and appends it. A page that returns\n * fewer rows than `pageSize` marks the list exhausted (`hasMore` false).\n * `select` runs over the accumulated raw rows, so client-side narrowing\n * (e.g. executions search) sees every loaded page, not just the last one.\n */\nexport function useWorkspacePaginatedQuery<TData, TRow, TResult>(\n options: WorkspacePaginatedQueryOptions<TData, TRow, TResult>\n): PaginatedQueryResult<TResult> {\n const { document, variables, pageSize, enabled, errorMessage } = options;\n const client = useWorkspaceClient();\n const selectRef = useLatest(options.select);\n const extractRowsRef = useLatest(options.extractRows);\n\n const [rows, setRows] = useState<TRow[]>([]);\n const rowsRef = useRef<TRow[]>([]);\n const [data, setData] = useState<TResult>(options.fallback);\n const [loading, setLoading] = useState(false);\n const [loadingMore, setLoadingMore] = useState(false);\n const [exhausted, setExhausted] = useState(true);\n const [error, setError] = useState<Error | undefined>();\n\n const replaceRows = useCallback(\n (next: TRow[]) => {\n rowsRef.current = next;\n setRows(next);\n setData(selectRef.current(next));\n },\n [selectRef]\n );\n\n const fetchPage = useCallback(\n async (offset: number, append: boolean) => {\n if (append) setLoadingMore(true);\n else setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<TData>({\n query: document,\n variables: { ...variables, pagination: { limit: pageSize, offset } },\n fetchPolicy: 'network-only',\n });\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw toError(operationError, errorMessage);\n }\n const pageRows = extractRowsRef.current(result.data ?? undefined) ?? [];\n replaceRows(append ? [...rowsRef.current, ...pageRows] : pageRows);\n setExhausted(pageRows.length < pageSize);\n } catch (queryError) {\n setError(toError(queryError, errorMessage));\n } finally {\n if (append) setLoadingMore(false);\n else setLoading(false);\n }\n },\n [client, document, variables, pageSize, errorMessage, extractRowsRef, replaceRows]\n );\n\n const refetch = useCallback(async () => {\n if (!enabled) {\n // The same empty list every time: a disabled query must not change state, or a\n // caller whose client identity changes per render would refetch forever.\n replaceRows(NO_ROWS);\n setExhausted(true);\n setError(undefined);\n return;\n }\n await fetchPage(0, false);\n }, [enabled, fetchPage, replaceRows]);\n\n const loadMore = useCallback(async () => {\n if (!enabled || exhausted) return;\n await fetchPage(rowsRef.current.length, true);\n }, [enabled, exhausted, fetchPage]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, loadingMore, hasMore: !exhausted, error, refetch, loadMore };\n}\n\nexport interface WorkspaceMutationOptions<TData, TInput, TResult> {\n /** Generated GraphQL document (see `src/generated/wspace-operations.ts`). */\n document: DocumentNode;\n /** Maps the caller's input onto GraphQL variables. */\n variables: (input: TInput) => Record<string, unknown>;\n /** Projects the raw payload onto the record shape the UI consumes. */\n select: (data: TData | undefined) => TResult | undefined;\n /** Thrown (and stored) when the payload is missing or the request fails. */\n errorMessage: string;\n}\n\n/**\n * Writes to the workspace gateway. Returns the `[mutate, state]` tuple used by\n * the reference hooks. `mutate` REJECTS on failure so callers cannot mistake a\n * failed write for a successful one.\n */\nexport function useWorkspaceMutation<TData, TInput, TResult>(\n options: WorkspaceMutationOptions<TData, TInput, TResult>\n): readonly [(input: TInput) => Promise<TResult>, MutationState<TResult>] {\n const { document, errorMessage } = options;\n const client = useWorkspaceClient();\n const variablesRef = useLatest(options.variables);\n const selectRef = useLatest(options.select);\n\n const [state, setState] = useState<MutationState<TResult>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const mutate = useCallback(\n async (input: TInput): Promise<TResult> => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<TData>({\n mutation: document,\n variables: variablesRef.current(input),\n });\n // Apollo v4 does not reject on GraphQL errors by default: the mutation\n // RESOLVES with `data` undefined and the failure on `result.error`\n // (CombinedGraphQLErrors / networkError). Surface it like a rejection\n // so callers see the server's field-level message, not the fallback.\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw toError(operationError, errorMessage);\n }\n const selected = selectRef.current(result.data ?? undefined);\n if (selected === undefined) {\n throw new Error(errorMessage);\n }\n setState({ data: selected, loading: false, error: undefined });\n return selected;\n } catch (mutationError) {\n const failure = toError(mutationError, errorMessage);\n setState({ data: undefined, loading: false, error: failure });\n throw failure;\n }\n },\n [client, document, errorMessage, selectRef, variablesRef]\n );\n\n return [mutate, state] as const;\n}\n"],"mappings":";;;;;AAsBA,SAAgBA,IAAsC;CACpD,OAAOC,EAAiB,WAAW;AACrC;AAGA,SAAgBC,IAAqC;CACnD,OAAOC,EAAU,CAAC,CAAC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AAkBF,EAA+B;GACvD,IAAIE,KAAkB,MACpB,MAAM3B,EAAQ2B,GAAgBC,CAAY;GAE5C,IAAM0B,IAAWzC,EAAU,QAAQY,EAAO,QAAQ,KAAA,CAAS;GAC3D,IAAI6B,MAAa,KAAA,GACf,MAAU,MAAM1B,CAAY;GAG9B,OADAwB,EAAS;IAAE,MAAME;IAAU,SAAS;IAAO,OAAO,KAAA;GAAU,CAAC,GACtDA;EACT,SAASC,GAAe;GACtB,IAAMC,IAAUxD,EAAQuD,GAAe3B,CAAY;GAEnD,MADAwB,EAAS;IAAE,MAAM,KAAA;IAAW,SAAS;IAAO,OAAOI;GAAQ,CAAC,GACtDA;EACR;CACF,GACA;EAAC5C;EAAQc;EAAUE;EAAcf;EAAWqC;CAAY,CAGlD,GAAQC,CAAK;AACvB"}
|
|
1
|
+
{"version":3,"file":"workspaceGateway.js","names":["useWorkspaceClient","useGatewayClient","useWorkspaceId","useBotlit","toError","message","extractGraphqlFailureMessage","cause","fallbackMessage","useLatest","ref","useRef","value","useLayoutEffect","useWorkspaceQuery","options","client","selectRef","fallbackRef","data","setData","useState","loading","setLoading","error","setError","refetch","useCallback","enabled","result","document","operationError","errorMessage","queryError","variables","useEffect","NO_ROWS","useWorkspacePaginatedQuery","extractRowsRef","rows","setRows","rowsRef","loadingMore","setLoadingMore","exhausted","setExhausted","generationRef","replaceRows","next","fetchPage","generation","append","isCurrent","pageSize","pageRows","loadMore","useWorkspaceAllPagesQuery","hasMore","useWorkspaceMutation","variablesRef","state","setState","input","selected","mutationError","failure"],"sources":["../../../../src/botlit/hooks/internal/workspaceGateway.ts"],"sourcesContent":["/**\n * Workspace gateway hook primitives\n * @module botlit/hooks/internal\n *\n * Every BotManor hook talks to the workspace public gateway through the Apollo\n * client the shell installs (`useGatewayClient('workspace')`) — never through a\n * client of its own. These primitives capture the exact shape used by the\n * reference hooks (`useAgents`, `useBots`): `network-only` reads, an explicit\n * `Error` in state rather than a thrown promise, and a `refetch` the caller can\n * run after a mutation.\n */\n\nimport type { ApolloClient, DocumentNode } from '@apollo/client';\nimport { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';\nimport { useGatewayClient } from '@burdenoff/fe-libs/shared/graphql';\n\nimport { useBotlit } from '../../providers/BotlitProvider';\nimport { extractGraphqlFailureMessage } from '../../utils/errors';\n\nexport type WorkspaceClient = ApolloClient;\n\n/** Apollo client for the workspace gateway, provided by the host shell. */\nexport function useWorkspaceClient(): WorkspaceClient {\n return useGatewayClient('workspace');\n}\n\n/** Current workspace id from the BotManor context (undefined until the shell resolves it). */\nexport function useWorkspaceId(): string | undefined {\n return useBotlit().workspaceId;\n}\n\nexport interface QueryResult<T> {\n data: T;\n loading: boolean;\n /** Set only when the request FAILED. An empty `data` with no `error` means \"no records yet\". */\n error: Error | undefined;\n refetch: () => Promise<void>;\n}\n\nexport interface PaginatedQueryResult<T> extends QueryResult<T> {\n /** True while the next page is being appended. */\n loadingMore: boolean;\n /**\n * True when the most recent page came back full, i.e. another page may\n * exist. False before the first page resolves and once a short page\n * (or an empty one) marks the end of the list.\n */\n hasMore: boolean;\n /**\n * Fetches the next page (current row count as offset) and appends it.\n * No-op while a fetch is in flight or when `hasMore` is false.\n */\n loadMore: () => Promise<void>;\n}\n\nexport interface MutationState<T> {\n data: T | undefined;\n loading: boolean;\n error: Error | undefined;\n}\n\n/**\n * Normalises any mutation failure to an Error with the server's\n * user-actionable message where one exists.\n *\n * Apollo Client v4 does not reject with a plain Error: failures arrive as\n * `{ networkError }` / `{ graphQLErrors }` objects, and the batched fetch\n * layer attaches the structured GraphQL errors as `.errors` on the\n * networkError. `extractGraphqlFailureMessage` unwraps all of those; only\n * when nothing user-actionable is present do we fall back to the hook's\n * generic `errorMessage`.\n */\nfunction toError(cause: unknown, fallbackMessage: string): Error {\n const message = extractGraphqlFailureMessage(cause);\n if (message) {\n // Preserve the original rejection on the chain so error monitoring can\n // still reach the structured GraphQL errors (extensions.code, requestId…).\n return new Error(message, { cause });\n }\n if (cause instanceof Error) return cause;\n return new Error(fallbackMessage, { cause });\n}\n\n/** Keeps a mutable ref pointing at the latest value without re-running effects. */\nfunction useLatest<T>(value: T): { readonly current: T } {\n const ref = useRef(value);\n useLayoutEffect(() => {\n ref.current = value;\n }, [value]);\n return ref;\n}\n\nexport interface WorkspaceQueryOptions<TData, TResult> {\n /** Generated GraphQL document (see `src/generated/wspace-operations.ts`). */\n document: DocumentNode;\n /** Must be referentially stable — memoize at the call site. */\n variables: Record<string, unknown> | undefined;\n /** Projects the raw payload onto the record shape the UI consumes. */\n select: (data: TData | undefined) => TResult;\n /** Value held while disabled or before the first successful read. */\n fallback: TResult;\n /** When false the request is skipped (e.g. no workspace id / no entity id yet). */\n enabled: boolean;\n /** Used when the thrown value is not an Error. */\n errorMessage: string;\n}\n\n/**\n * Reads from the workspace gateway and keeps `{ data, loading, error, refetch }`\n * in sync. `error` is reserved for real failures so callers can tell an empty\n * collection apart from a failed request.\n */\nexport function useWorkspaceQuery<TData, TResult>(\n options: WorkspaceQueryOptions<TData, TResult>\n): QueryResult<TResult> {\n const { document, variables, enabled, errorMessage } = options;\n const client = useWorkspaceClient();\n const selectRef = useLatest(options.select);\n const fallbackRef = useLatest(options.fallback);\n\n const [data, setData] = useState<TResult>(options.fallback);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n\n const refetch = useCallback(async () => {\n if (!enabled) {\n setData(fallbackRef.current);\n setError(undefined);\n return;\n }\n\n setLoading(true);\n setError(undefined);\n try {\n const result = await client.query<TData>({\n query: document,\n variables,\n fetchPolicy: 'network-only',\n });\n // Apollo v4 resolves (not rejects) with `result.error` set on GraphQL\n // errors — same handling as useWorkspaceMutation.\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw toError(operationError, errorMessage);\n }\n setData(selectRef.current(result.data ?? undefined));\n } catch (queryError) {\n setData(fallbackRef.current);\n setError(toError(queryError, errorMessage));\n } finally {\n setLoading(false);\n }\n // fallbackRef/selectRef are stable refs by construction\n }, [client, document, variables, enabled, errorMessage, fallbackRef, selectRef]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\n/** Shared empty page, so a disabled paginated query keeps one stable value. */\nconst NO_ROWS: never[] = [];\n\nexport interface WorkspacePaginatedQueryOptions<TData, TRow, TResult> {\n /** Generated GraphQL document (see `src/generated/wspace-operations.ts`). */\n document: DocumentNode;\n /**\n * Base variables (filters, ids, …) WITHOUT `pagination` — the hook adds\n * `{ limit: pageSize, offset }` per fetch. Must be referentially stable;\n * a new identity resets the accumulation back to page one.\n */\n variables: Record<string, unknown> | undefined;\n /** Page size for each fetch. */\n pageSize: number;\n /** Extracts the raw row list from a page payload; missing data yields []. */\n extractRows: (data: TData | undefined) => TRow[] | undefined;\n /** Projects the ACCUMULATED raw rows onto the record shape the UI consumes. */\n select: (rows: TRow[]) => TResult;\n /** Value held while disabled or before the first successful read. */\n fallback: TResult;\n /** When false the request is skipped (e.g. no workspace id yet). */\n enabled: boolean;\n /** Used when the thrown value is not an Error. */\n errorMessage: string;\n}\n\n/**\n * Offset-paginated variant of `useWorkspaceQuery` for unbounded lists.\n *\n * `refetch()` restarts at offset 0 and REPLACES the accumulated rows;\n * `loadMore()` fetches the next page and appends it. A page that returns\n * fewer rows than `pageSize` marks the list exhausted (`hasMore` false).\n * `select` runs over the accumulated raw rows, so client-side narrowing\n * (e.g. executions search) sees every loaded page, not just the last one.\n */\nexport function useWorkspacePaginatedQuery<TData, TRow, TResult>(\n options: WorkspacePaginatedQueryOptions<TData, TRow, TResult>\n): PaginatedQueryResult<TResult> {\n const { document, variables, pageSize, enabled, errorMessage } = options;\n const client = useWorkspaceClient();\n const selectRef = useLatest(options.select);\n const extractRowsRef = useLatest(options.extractRows);\n\n const [rows, setRows] = useState<TRow[]>([]);\n const rowsRef = useRef<TRow[]>([]);\n const [data, setData] = useState<TResult>(options.fallback);\n const [loading, setLoading] = useState(false);\n const [loadingMore, setLoadingMore] = useState(false);\n const [exhausted, setExhausted] = useState(true);\n const [error, setError] = useState<Error | undefined>();\n // Bumped by every page-one read: a page from a superseded read (e.g. a\n // workspace switch mid-paging) must not touch the newer read's state.\n const generationRef = useRef(0);\n\n const replaceRows = useCallback(\n (next: TRow[]) => {\n rowsRef.current = next;\n setRows(next);\n setData(selectRef.current(next));\n },\n [selectRef]\n );\n\n const fetchPage = useCallback(\n async (offset: number, append: boolean) => {\n const generation = append ? generationRef.current : ++generationRef.current;\n const isCurrent = () => generation === generationRef.current;\n if (append) setLoadingMore(true);\n else {\n setLoading(true);\n // A new page-one read supersedes any in-flight append; that append\n // no longer owns `loadingMore` and will not clear it.\n setLoadingMore(false);\n }\n setError(undefined);\n try {\n const result = await client.query<TData>({\n query: document,\n variables: { ...variables, pagination: { limit: pageSize, offset } },\n fetchPolicy: 'network-only',\n });\n if (!isCurrent()) return;\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw toError(operationError, errorMessage);\n }\n const pageRows = extractRowsRef.current(result.data ?? undefined) ?? [];\n replaceRows(append ? [...rowsRef.current, ...pageRows] : pageRows);\n setExhausted(pageRows.length < pageSize);\n } catch (queryError) {\n if (isCurrent()) setError(toError(queryError, errorMessage));\n } finally {\n // Only the current read owns the flags: a superseded append must not\n // clear a newer read's `loadingMore` (that would start a duplicate\n // append at the same offset).\n if (isCurrent()) {\n if (append) setLoadingMore(false);\n else setLoading(false);\n }\n }\n },\n [client, document, variables, pageSize, errorMessage, extractRowsRef, replaceRows]\n );\n\n const refetch = useCallback(async () => {\n if (!enabled) {\n // The same empty list every time: a disabled query must not change state, or a\n // caller whose client identity changes per render would refetch forever.\n replaceRows(NO_ROWS);\n setExhausted(true);\n setError(undefined);\n return;\n }\n await fetchPage(0, false);\n }, [enabled, fetchPage, replaceRows]);\n\n const loadMore = useCallback(async () => {\n if (!enabled || exhausted) return;\n await fetchPage(rowsRef.current.length, true);\n }, [enabled, exhausted, fetchPage]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, loadingMore, hasMore: !exhausted, error, refetch, loadMore };\n}\n\n/**\n * Every page of an offset-paginated list (BOFF-15360), for callers that must\n * see the whole list at once (pickers, \"already configured\" checks).\n * `loading` holds until the last page has arrived; a failed page stops paging\n * and sets `error`. `refetch` restarts from page one.\n */\nexport function useWorkspaceAllPagesQuery<TData, TRow, TResult>(\n options: WorkspacePaginatedQueryOptions<TData, TRow, TResult>\n): QueryResult<TResult> {\n const { data, loading, loadingMore, hasMore, error, refetch, loadMore } =\n useWorkspacePaginatedQuery(options);\n\n useEffect(() => {\n if (hasMore && !loading && !loadingMore && !error) void loadMore();\n }, [hasMore, loading, loadingMore, error, loadMore]);\n\n return { data, loading: loading || loadingMore || (hasMore && !error), error, refetch };\n}\n\nexport interface WorkspaceMutationOptions<TData, TInput, TResult> {\n /** Generated GraphQL document (see `src/generated/wspace-operations.ts`). */\n document: DocumentNode;\n /** Maps the caller's input onto GraphQL variables. */\n variables: (input: TInput) => Record<string, unknown>;\n /** Projects the raw payload onto the record shape the UI consumes. */\n select: (data: TData | undefined) => TResult | undefined;\n /** Thrown (and stored) when the payload is missing or the request fails. */\n errorMessage: string;\n}\n\n/**\n * Writes to the workspace gateway. Returns the `[mutate, state]` tuple used by\n * the reference hooks. `mutate` REJECTS on failure so callers cannot mistake a\n * failed write for a successful one.\n */\nexport function useWorkspaceMutation<TData, TInput, TResult>(\n options: WorkspaceMutationOptions<TData, TInput, TResult>\n): readonly [(input: TInput) => Promise<TResult>, MutationState<TResult>] {\n const { document, errorMessage } = options;\n const client = useWorkspaceClient();\n const variablesRef = useLatest(options.variables);\n const selectRef = useLatest(options.select);\n\n const [state, setState] = useState<MutationState<TResult>>({\n data: undefined,\n loading: false,\n error: undefined,\n });\n\n const mutate = useCallback(\n async (input: TInput): Promise<TResult> => {\n setState({ data: undefined, loading: true, error: undefined });\n try {\n const result = await client.mutate<TData>({\n mutation: document,\n variables: variablesRef.current(input),\n });\n // Apollo v4 does not reject on GraphQL errors by default: the mutation\n // RESOLVES with `data` undefined and the failure on `result.error`\n // (CombinedGraphQLErrors / networkError). Surface it like a rejection\n // so callers see the server's field-level message, not the fallback.\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) {\n throw toError(operationError, errorMessage);\n }\n const selected = selectRef.current(result.data ?? undefined);\n if (selected === undefined) {\n throw new Error(errorMessage);\n }\n setState({ data: selected, loading: false, error: undefined });\n return selected;\n } catch (mutationError) {\n const failure = toError(mutationError, errorMessage);\n setState({ data: undefined, loading: false, error: failure });\n throw failure;\n }\n },\n [client, document, errorMessage, selectRef, variablesRef]\n );\n\n return [mutate, state] as const;\n}\n"],"mappings":";;;;;AAsBA,SAAgBA,IAAsC;CACpD,OAAOC,EAAiB,WAAW;AACrC;AAGA,SAAgBC,IAAqC;CACnD,OAAOC,EAAU,CAAC,CAAC;AACrB;AA2CA,SAASC,EAAQ,GAAgB,GAAgC;CAC/D,IAAMC,IAAUC,EAA6BC,CAAK;CAOlD,OANIF,IAGS,MAAMA,GAAS,EAAE,SAAM,CAAC,IAEjCE,aAAiB,QAAcA,IACxB,MAAMC,GAAiB,EAAE,SAAM,CAAC;AAC7C;AAGA,SAASC,EAAa,GAAmC;CACvD,IAAMC,IAAMC,EAAOC,CAAK;CAIxB,OAHAC,QAAsB;EACpB,EAAI,UAAUD;CAChB,GAAG,CAACA,CAAK,CAAC,GACHF;AACT;AAsBA,SAAgBI,EACd,GACsB;CACtB,IAAM,EAAE,aAAU,cAAW,YAAS,oBAAiBC,GACjDC,IAAShB,EAAmB,GAC5BiB,IAAYR,EAAUM,EAAQ,MAAM,GACpCG,IAAcT,EAAUM,EAAQ,QAAQ,GAExC,CAACI,GAAMC,KAAWC,EAAkBN,EAAQ,QAAQ,GACpD,CAACO,GAASC,KAAcF,EAAS,EAAK,GACtC,CAACG,GAAOC,KAAYJ,EAA4B,GAEhDK,IAAUC,EAAY,YAAY;EACtC,IAAI,CAACC,GAEH,AADAR,EAAQF,EAAY,OAAO,GAC3BO,EAAS,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,MAAU,MAAM/B,CAAY;GAG9B,OADA6B,EAAS;IAAE,MAAME;IAAU,SAAS;IAAO,OAAO,KAAA;GAAU,CAAC,GACtDA;EACT,SAASC,GAAe;GACtB,IAAMC,IAAU7D,EAAQ4D,GAAehC,CAAY;GAEnD,MADA6B,EAAS;IAAE,MAAM,KAAA;IAAW,SAAS;IAAO,OAAOI;GAAQ,CAAC,GACtDA;EACR;CACF,GACA;EAACjD;EAAQc;EAAUE;EAAcf;EAAW0C;CAAY,CAGlD,GAAQC,CAAK;AACvB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { AgentBindingsFieldsFragment, GetPromptTemplateVersionsQuery, TestPromptTemplateMutation } from '../../generated/wspace-operations';
|
|
2
|
+
import { SavePromptTemplateVersionInput, SetAgentBindingsInput, TestPromptTemplateInput } from '../../generated/wspace-types';
|
|
3
|
+
import { QueryResult } from './internal/workspaceGateway';
|
|
4
|
+
export type AgentBindingsRecord = AgentBindingsFieldsFragment;
|
|
5
|
+
export type PromptTemplateTestRecord = TestPromptTemplateMutation['testPromptTemplate'];
|
|
6
|
+
export type PromptTemplateVersionRecord = NonNullable<GetPromptTemplateVersionsQuery['getPromptTemplate']>['versionHistory'][number];
|
|
7
|
+
export declare function useAgentBindings(agentId: string | undefined): QueryResult<AgentBindingsRecord | null>;
|
|
8
|
+
export declare function useSetAgentBindings(agentId: string): {
|
|
9
|
+
save: (input: SetAgentBindingsInput) => Promise<AgentBindingsFieldsFragment>;
|
|
10
|
+
loading: boolean;
|
|
11
|
+
error: Error | undefined;
|
|
12
|
+
};
|
|
13
|
+
export interface TestPromptTemplateVariables {
|
|
14
|
+
templateId: string;
|
|
15
|
+
input: TestPromptTemplateInput;
|
|
16
|
+
}
|
|
17
|
+
export declare function useTestPromptTemplate(): {
|
|
18
|
+
run: (input: TestPromptTemplateVariables) => Promise<{
|
|
19
|
+
renderedPrompt: string;
|
|
20
|
+
output: string;
|
|
21
|
+
model: string;
|
|
22
|
+
tokensUsed: number;
|
|
23
|
+
inputTokens: number | null;
|
|
24
|
+
outputTokens: number | null;
|
|
25
|
+
latencyMs: number;
|
|
26
|
+
}>;
|
|
27
|
+
loading: boolean;
|
|
28
|
+
};
|
|
29
|
+
export interface SavePromptTemplateVersionVariables {
|
|
30
|
+
templateId: string;
|
|
31
|
+
input: SavePromptTemplateVersionInput;
|
|
32
|
+
}
|
|
33
|
+
export declare function useSavePromptTemplateVersion(): {
|
|
34
|
+
save: (input: SavePromptTemplateVersionVariables) => Promise<{
|
|
35
|
+
id: string;
|
|
36
|
+
version: string;
|
|
37
|
+
revision: number;
|
|
38
|
+
templateText: string;
|
|
39
|
+
variables: Record<string, unknown>;
|
|
40
|
+
updatedAt: string;
|
|
41
|
+
versionHistory: Array<{
|
|
42
|
+
version: string;
|
|
43
|
+
revision: number;
|
|
44
|
+
templateText: string;
|
|
45
|
+
variables: Record<string, unknown>;
|
|
46
|
+
changelog: string | null;
|
|
47
|
+
savedAt: string;
|
|
48
|
+
savedById: string;
|
|
49
|
+
}>;
|
|
50
|
+
}>;
|
|
51
|
+
loading: boolean;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Earlier versions of one template. A response for a template that is no
|
|
55
|
+
* longer the requested one (the selection changed mid-flight) is discarded,
|
|
56
|
+
* so one prompt's history can never be shown, loaded or saved into another.
|
|
57
|
+
*/
|
|
58
|
+
export declare function usePromptTemplateVersions(templateId: string | undefined): QueryResult<PromptTemplateVersionRecord[]>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { GetAgentBindingsDocument as e, GetPromptTemplateVersionsDocument as t, SavePromptTemplateVersionDocument as n, SetAgentBindingsDocument as r, TestPromptTemplateDocument as i } from "../../generated/wspace-operations.js";
|
|
2
|
+
import { useWorkspaceId as a, useWorkspaceMutation as o, useWorkspaceQuery as s } from "./internal/workspaceGateway.js";
|
|
3
|
+
import { useEffect as c, useMemo as l } from "react";
|
|
4
|
+
// src/botlit/hooks/useAgentBindings.ts
|
|
5
|
+
function u(t) {
|
|
6
|
+
let n = a(), r = l(() => ({ agentId: t ?? "" }), [t]);
|
|
7
|
+
return s({
|
|
8
|
+
document: e,
|
|
9
|
+
variables: r,
|
|
10
|
+
select: (e) => e?.getAgentBindings ?? null,
|
|
11
|
+
fallback: null,
|
|
12
|
+
enabled: !!(n && t),
|
|
13
|
+
errorMessage: "Failed to load the agent bindings"
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function d(e) {
|
|
17
|
+
let [t, n] = o({
|
|
18
|
+
document: r,
|
|
19
|
+
variables: (t) => ({
|
|
20
|
+
agentId: e,
|
|
21
|
+
input: t
|
|
22
|
+
}),
|
|
23
|
+
select: (e) => e?.setAgentBindings,
|
|
24
|
+
errorMessage: "Failed to save the agent bindings"
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
save: t,
|
|
28
|
+
loading: n.loading,
|
|
29
|
+
error: n.error
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function f() {
|
|
33
|
+
let [e, t] = o({
|
|
34
|
+
document: i,
|
|
35
|
+
variables: ({ templateId: e, input: t }) => ({
|
|
36
|
+
id: e,
|
|
37
|
+
input: t
|
|
38
|
+
}),
|
|
39
|
+
select: (e) => e?.testPromptTemplate,
|
|
40
|
+
errorMessage: "Failed to run the prompt against the model"
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
run: e,
|
|
44
|
+
loading: t.loading
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function p() {
|
|
48
|
+
let [e, t] = o({
|
|
49
|
+
document: n,
|
|
50
|
+
variables: ({ templateId: e, input: t }) => ({
|
|
51
|
+
id: e,
|
|
52
|
+
input: t
|
|
53
|
+
}),
|
|
54
|
+
select: (e) => e?.savePromptTemplateVersion,
|
|
55
|
+
errorMessage: "Failed to save the prompt version"
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
save: e,
|
|
59
|
+
loading: t.loading
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
var m = [], h = {
|
|
63
|
+
templateId: null,
|
|
64
|
+
versions: m
|
|
65
|
+
};
|
|
66
|
+
function g(e) {
|
|
67
|
+
let n = l(() => ({ id: e ?? "" }), [e]), r = s({
|
|
68
|
+
document: t,
|
|
69
|
+
variables: n,
|
|
70
|
+
select: (e) => e?.getPromptTemplate ? {
|
|
71
|
+
templateId: e.getPromptTemplate.id,
|
|
72
|
+
versions: e.getPromptTemplate.versionHistory
|
|
73
|
+
} : h,
|
|
74
|
+
fallback: h,
|
|
75
|
+
enabled: !!e,
|
|
76
|
+
errorMessage: "Failed to load the prompt versions"
|
|
77
|
+
}), i = !!e && !r.loading && r.data.templateId !== null && r.data.templateId !== e, { refetch: a } = r;
|
|
78
|
+
return c(() => {
|
|
79
|
+
i && a();
|
|
80
|
+
}, [i, a]), {
|
|
81
|
+
...r,
|
|
82
|
+
data: r.data.templateId === e ? r.data.versions : m
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export { u as useAgentBindings, g as usePromptTemplateVersions, p as useSavePromptTemplateVersion, d as useSetAgentBindings, f as useTestPromptTemplate };
|
|
86
|
+
|
|
87
|
+
//# sourceMappingURL=useAgentBindings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAgentBindings.js","names":["useAgentBindings","workspaceId","useWorkspaceId","variables","useMemo","agentId","useWorkspaceQuery","GetAgentBindingsDocument","data","useSetAgentBindings","save","state","useWorkspaceMutation","SetAgentBindingsDocument","useTestPromptTemplate","run","TestPromptTemplateDocument","templateId","useSavePromptTemplateVersion","SavePromptTemplateVersionDocument","NO_VERSIONS","NO_TEMPLATE_VERSIONS","usePromptTemplateVersions","result","GetPromptTemplateVersionsDocument","stale","useEffect","refetch"],"sources":["../../../src/botlit/hooks/useAgentBindings.ts"],"sourcesContent":["/**\n * Agent Builder bindings + Prompt Studio hooks (BOFF-15360)\n * @module botlit/hooks\n *\n * Backed by `getAgentBindings` / `setAgentBindings` (the prompt template,\n * skills and retrieval profile attached to an agent) and the Prompt Studio\n * mutations `testPromptTemplate` / `savePromptTemplateVersion` on\n * wspace-botmanor-svc.\n */\n\nimport { useEffect, useMemo } from 'react';\nimport {\n GetAgentBindingsDocument,\n GetPromptTemplateVersionsDocument,\n SavePromptTemplateVersionDocument,\n SetAgentBindingsDocument,\n TestPromptTemplateDocument,\n type AgentBindingsFieldsFragment,\n type GetAgentBindingsQuery,\n type GetPromptTemplateVersionsQuery,\n type SavePromptTemplateVersionMutation,\n type SetAgentBindingsMutation,\n type TestPromptTemplateMutation,\n} from '../../generated/wspace-operations';\nimport type {\n SavePromptTemplateVersionInput,\n SetAgentBindingsInput,\n TestPromptTemplateInput,\n} from '../../generated/wspace-types';\nimport {\n useWorkspaceId,\n useWorkspaceMutation,\n useWorkspaceQuery,\n type QueryResult,\n} from './internal/workspaceGateway';\n\nexport type AgentBindingsRecord = AgentBindingsFieldsFragment;\nexport type PromptTemplateTestRecord = TestPromptTemplateMutation['testPromptTemplate'];\nexport type PromptTemplateVersionRecord = NonNullable<\n GetPromptTemplateVersionsQuery['getPromptTemplate']\n>['versionHistory'][number];\n\nexport function useAgentBindings(\n agentId: string | undefined\n): QueryResult<AgentBindingsRecord | null> {\n const workspaceId = useWorkspaceId();\n const variables = useMemo(() => ({ agentId: agentId ?? '' }), [agentId]);\n return useWorkspaceQuery<GetAgentBindingsQuery, AgentBindingsRecord | null>({\n document: GetAgentBindingsDocument,\n variables,\n select: (data) => data?.getAgentBindings ?? null,\n fallback: null,\n enabled: Boolean(workspaceId && agentId),\n errorMessage: 'Failed to load the agent bindings',\n });\n}\n\nexport function useSetAgentBindings(agentId: string) {\n const [save, state] = useWorkspaceMutation<\n SetAgentBindingsMutation,\n SetAgentBindingsInput,\n AgentBindingsRecord\n >({\n document: SetAgentBindingsDocument,\n variables: (input) => ({ agentId, input }),\n select: (data) => data?.setAgentBindings,\n errorMessage: 'Failed to save the agent bindings',\n });\n return { save, loading: state.loading, error: state.error };\n}\n\nexport interface TestPromptTemplateVariables {\n templateId: string;\n input: TestPromptTemplateInput;\n}\n\nexport function useTestPromptTemplate() {\n const [run, state] = useWorkspaceMutation<\n TestPromptTemplateMutation,\n TestPromptTemplateVariables,\n PromptTemplateTestRecord\n >({\n document: TestPromptTemplateDocument,\n variables: ({ templateId, input }) => ({ id: templateId, input }),\n select: (data) => data?.testPromptTemplate,\n errorMessage: 'Failed to run the prompt against the model',\n });\n return { run, loading: state.loading };\n}\n\nexport interface SavePromptTemplateVersionVariables {\n templateId: string;\n input: SavePromptTemplateVersionInput;\n}\n\nexport function useSavePromptTemplateVersion() {\n const [save, state] = useWorkspaceMutation<\n SavePromptTemplateVersionMutation,\n SavePromptTemplateVersionVariables,\n SavePromptTemplateVersionMutation['savePromptTemplateVersion']\n >({\n document: SavePromptTemplateVersionDocument,\n variables: ({ templateId, input }) => ({ id: templateId, input }),\n select: (data) => data?.savePromptTemplateVersion,\n errorMessage: 'Failed to save the prompt version',\n });\n return { save, loading: state.loading };\n}\n\nconst NO_VERSIONS: PromptTemplateVersionRecord[] = [];\n\ninterface PromptTemplateVersions {\n templateId: string | null;\n versions: PromptTemplateVersionRecord[];\n}\n\nconst NO_TEMPLATE_VERSIONS: PromptTemplateVersions = { templateId: null, versions: NO_VERSIONS };\n\n/**\n * Earlier versions of one template. A response for a template that is no\n * longer the requested one (the selection changed mid-flight) is discarded,\n * so one prompt's history can never be shown, loaded or saved into another.\n */\nexport function usePromptTemplateVersions(\n templateId: string | undefined\n): QueryResult<PromptTemplateVersionRecord[]> {\n const variables = useMemo(() => ({ id: templateId ?? '' }), [templateId]);\n const result = useWorkspaceQuery<GetPromptTemplateVersionsQuery, PromptTemplateVersions>({\n document: GetPromptTemplateVersionsDocument,\n variables,\n select: (data) =>\n data?.getPromptTemplate\n ? { templateId: data.getPromptTemplate.id, versions: data.getPromptTemplate.versionHistory }\n : NO_TEMPLATE_VERSIONS,\n fallback: NO_TEMPLATE_VERSIONS,\n enabled: Boolean(templateId),\n errorMessage: 'Failed to load the prompt versions',\n });\n // A stale response that landed last is replaced by a fresh read of the\n // selected template's history.\n const stale =\n Boolean(templateId) &&\n !result.loading &&\n result.data.templateId !== null &&\n result.data.templateId !== templateId;\n const { refetch } = result;\n useEffect(() => {\n if (stale) void refetch();\n }, [stale, refetch]);\n return {\n ...result,\n data: result.data.templateId === templateId ? result.data.versions : NO_VERSIONS,\n };\n}\n"],"mappings":";;;;AA0CA,SAAgBA,EACd,GACyC;CACzC,IAAMC,IAAcC,EAAe,GAC7BC,IAAYC,SAAe,EAAE,SAASC,KAAW,GAAG,IAAI,CAACA,CAAO,CAAC;CACvE,OAAOC,EAAqE;EAC1E,UAAUC;EACV;EACA,SAAS,MAASC,GAAM,oBAAoB;EAC5C,UAAU;EACV,SAAS,GAAQP,KAAeI;EAChC,cAAc;CAChB,CAAC;AACH;AAEA,SAAgBI,EAAoB,GAAiB;CACnD,IAAM,CAACC,GAAMC,KAASC,EAIpB;EACA,UAAUC;EACV,YAAY,OAAW;GAAE;GAAS;EAAM;EACxC,SAAS,MAASL,GAAM;EACxB,cAAc;CAChB,CAAC;CACD,OAAO;EAAE;EAAM,SAASG,EAAM;EAAS,OAAOA,EAAM;CAAM;AAC5D;AAOA,SAAgBG,IAAwB;CACtC,IAAM,CAACC,GAAKJ,KAASC,EAInB;EACA,UAAUI;EACV,YAAY,EAAE,eAAY,gBAAa;GAAE,IAAIC;GAAY;EAAM;EAC/D,SAAS,MAAST,GAAM;EACxB,cAAc;CAChB,CAAC;CACD,OAAO;EAAE;EAAK,SAASG,EAAM;CAAQ;AACvC;AAOA,SAAgBO,IAA+B;CAC7C,IAAM,CAACR,GAAMC,KAASC,EAIpB;EACA,UAAUO;EACV,YAAY,EAAE,eAAY,gBAAa;GAAE,IAAIF;GAAY;EAAM;EAC/D,SAAS,MAAST,GAAM;EACxB,cAAc;CAChB,CAAC;CACD,OAAO;EAAE;EAAM,SAASG,EAAM;CAAQ;AACxC;AAEA,IAAMS,IAA6C,CAAC,GAO9CC,IAA+C;CAAE,YAAY;CAAM,UAAUD;AAAY;AAO/F,SAAgBE,EACd,GAC4C;CAC5C,IAAMnB,IAAYC,SAAe,EAAE,IAAIa,KAAc,GAAG,IAAI,CAACA,CAAU,CAAC,GAClEM,IAASjB,EAA0E;EACvF,UAAUkB;EACV;EACA,SAAS,MACPhB,GAAM,oBACF;GAAE,YAAYA,EAAK,kBAAkB;GAAI,UAAUA,EAAK,kBAAkB;EAAe,IACzFa;EACN,UAAUA;EACV,SAAS,EAAQJ;EACjB,cAAc;CAChB,CAAC,GAGKQ,IACJ,EAAQR,KACR,CAACM,EAAO,WACRA,EAAO,KAAK,eAAe,QAC3BA,EAAO,KAAK,eAAeN,GACvB,EAAE,eAAYM;CAIpB,OAHAG,QAAgB;EACd,AAAID,KAAOE,EAAa;CAC1B,GAAG,CAACF,GAAOE,CAAO,CAAC,GACZ;EACL,GAAGJ;EACH,MAAMA,EAAO,KAAK,eAAeN,IAAaM,EAAO,KAAK,WAAWH;CACvE;AACF"}
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
*
|
|
12
12
|
* These hooks let the connector form create that channel with its credentials
|
|
13
13
|
* and the detail page show its inbound URL, all through the shell's global
|
|
14
|
-
* gateway client
|
|
14
|
+
* gateway client, scoped to the active workspace's organization (see
|
|
15
|
+
* `internal/globalWorkspaceScope`). The documents are written inline, like `GetChannels` in
|
|
15
16
|
* `useUserPlatformConnection`: `inboundWebhookUrl` / `inboundWorkspaceId` are
|
|
16
17
|
* newer than the checked-in `graphql/global.graphql`, which cannot be
|
|
17
18
|
* re-pulled while gateway introspection is disabled.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useBotlit as e } from "../providers/BotlitProvider.js";
|
|
2
2
|
import { extractGraphqlFailureMessage as t } from "../utils/errors.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { useWorkspaceScopedGlobalClient as n } from "./internal/globalWorkspaceScope.js";
|
|
4
|
+
import { useCallback as r, useEffect as i, useRef as a, useState as o } from "react";
|
|
5
|
+
import { gql as s } from "@apollo/client";
|
|
6
6
|
// src/botlit/hooks/useChannelSetup.ts
|
|
7
7
|
var c = {
|
|
8
8
|
SLACK: {
|
|
@@ -76,7 +76,7 @@ function f(e, t) {
|
|
|
76
76
|
function p() {
|
|
77
77
|
return e().organizationId || null;
|
|
78
78
|
}
|
|
79
|
-
var m =
|
|
79
|
+
var m = s`
|
|
80
80
|
query BotmanorInboundChannel($id: ID!) {
|
|
81
81
|
getChannel(id: $id) {
|
|
82
82
|
id
|
|
@@ -88,19 +88,19 @@ var m = o`
|
|
|
88
88
|
inboundWebhookUrl
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
-
`, h =
|
|
91
|
+
`, h = s`
|
|
92
92
|
mutation BotmanorCreateSetupChannel($input: CreateChannelInput!) {
|
|
93
93
|
createChannel(input: $input) {
|
|
94
94
|
id
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
`, g =
|
|
97
|
+
`, g = s`
|
|
98
98
|
mutation BotmanorCreateSetupConnection($input: CreateConnectionInput!) {
|
|
99
99
|
createConnection(input: $input) {
|
|
100
100
|
id
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
-
`, _ =
|
|
103
|
+
`, _ = s`
|
|
104
104
|
mutation BotmanorDeleteSetupChannel($id: ID!) {
|
|
105
105
|
deleteChannel(id: $id)
|
|
106
106
|
}
|
|
@@ -113,87 +113,96 @@ function y(e, t) {
|
|
|
113
113
|
let n = e.error;
|
|
114
114
|
if (n != null) throw v(n, t);
|
|
115
115
|
}
|
|
116
|
-
function b() {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
let n = ++f.current, r = () => n === f.current;
|
|
122
|
-
if (s(null), d(void 0), e) {
|
|
123
|
-
l(!0);
|
|
116
|
+
function b(e) {
|
|
117
|
+
let { client: t, context: s } = n(), [c, l] = o(null), [u, d] = o(!1), [f, p] = o(void 0), h = a(0), g = r(async () => {
|
|
118
|
+
let n = ++h.current, r = () => n === h.current;
|
|
119
|
+
if (l(null), p(void 0), e) {
|
|
120
|
+
d(!0);
|
|
124
121
|
try {
|
|
125
122
|
let n = await t.query({
|
|
126
123
|
query: m,
|
|
127
124
|
variables: { id: e },
|
|
128
|
-
fetchPolicy: "network-only"
|
|
125
|
+
fetchPolicy: "network-only",
|
|
126
|
+
context: s
|
|
129
127
|
});
|
|
130
|
-
y(n, "Failed to load the channel"), r() &&
|
|
128
|
+
y(n, "Failed to load the channel"), r() && l(n.data?.getChannel ?? null);
|
|
131
129
|
} catch (e) {
|
|
132
|
-
r() &&
|
|
130
|
+
r() && p(v(e, "Failed to load the channel"));
|
|
133
131
|
} finally {
|
|
134
|
-
r() &&
|
|
132
|
+
r() && d(!1);
|
|
135
133
|
}
|
|
136
134
|
}
|
|
137
|
-
}, [
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
135
|
+
}, [
|
|
136
|
+
e,
|
|
137
|
+
t,
|
|
138
|
+
s
|
|
139
|
+
]);
|
|
140
|
+
return i(() => {
|
|
141
|
+
g();
|
|
142
|
+
}, [g]), {
|
|
143
|
+
data: c,
|
|
144
|
+
loading: u,
|
|
145
|
+
error: f,
|
|
146
|
+
refetch: g
|
|
145
147
|
};
|
|
146
148
|
}
|
|
147
|
-
function
|
|
148
|
-
let e =
|
|
149
|
+
function x() {
|
|
150
|
+
let { client: e, context: t } = n(), [i, a] = o(!1), s = r(async (n) => {
|
|
149
151
|
y(await e.mutate({
|
|
150
152
|
mutation: _,
|
|
151
|
-
variables: { id:
|
|
153
|
+
variables: { id: n },
|
|
154
|
+
context: t
|
|
152
155
|
}), "Failed to delete the channel");
|
|
153
|
-
}, [e]);
|
|
156
|
+
}, [e, t]);
|
|
154
157
|
return {
|
|
155
|
-
provision:
|
|
156
|
-
|
|
158
|
+
provision: r(async ({ name: n, description: r, organizationId: i, definition: o, credentials: c }) => {
|
|
159
|
+
a(!0);
|
|
157
160
|
try {
|
|
158
|
-
let
|
|
161
|
+
let a;
|
|
159
162
|
try {
|
|
160
|
-
let
|
|
163
|
+
let s = await e.mutate({
|
|
161
164
|
mutation: h,
|
|
162
165
|
variables: { input: {
|
|
163
|
-
name:
|
|
164
|
-
description:
|
|
166
|
+
name: n,
|
|
167
|
+
description: r || void 0,
|
|
165
168
|
platform: o.platform,
|
|
166
169
|
channelType: "COMMUNICATION",
|
|
167
|
-
organizationId:
|
|
168
|
-
} }
|
|
170
|
+
organizationId: i
|
|
171
|
+
} },
|
|
172
|
+
context: t
|
|
169
173
|
});
|
|
170
|
-
y(
|
|
174
|
+
y(s, "Failed to create the channel"), a = s.data?.createChannel?.id;
|
|
171
175
|
} catch (e) {
|
|
172
176
|
throw v(e, "Failed to create the channel");
|
|
173
177
|
}
|
|
174
|
-
if (!
|
|
175
|
-
let
|
|
178
|
+
if (!a) throw Error("Failed to create the channel");
|
|
179
|
+
let l = Object.fromEntries(o.fields.map((e) => [e.key, c[e.key]?.trim() ?? ""]));
|
|
176
180
|
try {
|
|
177
181
|
y(await e.mutate({
|
|
178
182
|
mutation: g,
|
|
179
183
|
variables: { input: {
|
|
180
|
-
channelId:
|
|
184
|
+
channelId: a,
|
|
181
185
|
authType: o.authType,
|
|
182
|
-
credentials:
|
|
183
|
-
} }
|
|
186
|
+
credentials: l
|
|
187
|
+
} },
|
|
188
|
+
context: t
|
|
184
189
|
}), "Failed to save the channel credentials");
|
|
185
190
|
} catch (e) {
|
|
186
|
-
throw await
|
|
191
|
+
throw await s(a).catch(() => void 0), v(e, "Failed to save the channel credentials");
|
|
187
192
|
}
|
|
188
|
-
return
|
|
193
|
+
return a;
|
|
189
194
|
} finally {
|
|
190
|
-
|
|
195
|
+
a(!1);
|
|
191
196
|
}
|
|
192
|
-
}, [
|
|
193
|
-
|
|
194
|
-
|
|
197
|
+
}, [
|
|
198
|
+
e,
|
|
199
|
+
t,
|
|
200
|
+
s
|
|
201
|
+
]),
|
|
202
|
+
discard: s,
|
|
203
|
+
loading: i
|
|
195
204
|
};
|
|
196
205
|
}
|
|
197
|
-
export { c as PLATFORM_CREDENTIALS, u as connectorPlatform, d as generateSigningSecret, p as useActiveOrganizationId,
|
|
206
|
+
export { c as PLATFORM_CREDENTIALS, u as connectorPlatform, d as generateSigningSecret, p as useActiveOrganizationId, b as useInboundChannel, x as useProvisionChannel, f as validateCredentials };
|
|
198
207
|
|
|
199
208
|
//# sourceMappingURL=useChannelSetup.js.map
|