@burdenoff/microfe-botmanor 2026.1120.5 → 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,104 +1,228 @@
1
- import { PageLayout as e } from "../components/PageLayout.js";
2
- import { Button as t } from "../components/Button.js";
3
- import { useAgent as n, useAgents as r } from "../hooks/useAgents.js";
4
- import { useBotlit as i } from "../providers/BotlitProvider.js";
5
- import { useState as a } from "react";
6
- import { Fragment as o, jsx as s, jsxs as c } from "react/jsx-runtime";
7
- import { useParams as l } from "react-router";
8
- import { WorkflowAssistantPanel as u } from "@burdenoff/fe-libs/shared/assistant";
1
+ import { useTr as e } from "../../shared/hooks/useTr.js";
2
+ import { PageLayout as t } from "../components/PageLayout.js";
3
+ import { Button as n } from "../components/Button.js";
4
+ import { useAgent as r } from "../hooks/useAgents.js";
5
+ import { useChatAssistants as i, useDeleteMyAssistantConversation as a, useMyAssistantConversations as o, useMyAssistantRetention as s } from "../hooks/useAssistantChat.js";
6
+ import { useBotlit as c } from "../providers/BotlitProvider.js";
7
+ import { assistantAvailability as l, searchesKnowledge as u } from "../utils/assistantAvailability.js";
8
+ import { confirmAction as d } from "../utils/confirmAction.js";
9
+ import { useState as f } from "react";
10
+ import { Fragment as p, jsx as m, jsxs as h } from "react/jsx-runtime";
11
+ import { useParams as g } from "react-router";
12
+ import { toast as _ } from "sonner";
13
+ import { WorkflowAssistantPanel as v } from "@burdenoff/fe-libs/shared/assistant";
9
14
  // src/botlit/pages/ChatPage.tsx
10
- function d() {
11
- let { workspaceId: e, currentUser: t } = i();
12
- return /* @__PURE__ */ s(f, {}, `${e}:${t?.id}`);
15
+ function y() {
16
+ let { workspaceId: e, currentUser: t } = c();
17
+ return /* @__PURE__ */ m(x, {}, `${e}:${t?.id}`);
13
18
  }
14
- function f() {
15
- let { agentId: n } = l(), { currentUser: u, workspaceId: d, authToken: f, navigateTo: p } = i(), h = r(), [g, _] = a(""), v = n ?? g, y = h.data?.find((e) => e.id === v && e.status === "ACTIVE");
16
- return /* @__PURE__ */ s(e, {
17
- title: y ? `Chat with ${y.name}` : "AI Chat",
18
- description: "Ask questions grounded in your assistant’s knowledge. Your conversation is saved securely.",
19
- children: /* @__PURE__ */ s("div", {
19
+ function b(e, t) {
20
+ switch (t) {
21
+ case "inactive": return e("botlit.chat.unavailable.inactive", "it is not active");
22
+ case "noModel": return e("botlit.chat.unavailable.noModel", "it has no model");
23
+ case "courseTutor": return e("botlit.chat.unavailable.courseTutor", "it is a course assistant, which answers learners in its course chat");
24
+ }
25
+ }
26
+ function x() {
27
+ let r = e(), { agentId: a } = g(), { currentUser: o, workspaceId: s, authToken: u, navigateTo: d } = c(), _ = i(), [v, y] = f(""), x = a ?? v, w = _.data ?? [], E = w.find((e) => e.id === x), D = w.filter((e) => l(e).available), O = w.filter((e) => !l(e).available);
28
+ return /* @__PURE__ */ m(t, {
29
+ title: E ? r("botlit.chat.titleWithAgent", "Chat with {{name}}", { name: E.name }) : r("botlit.chat.title", "AI Chat"),
30
+ description: r("botlit.chat.description", "Ask an assistant questions about its knowledge. Your conversations are saved to your account."),
31
+ children: /* @__PURE__ */ m("div", {
20
32
  className: "mx-auto flex w-full max-w-4xl flex-col gap-4 p-4",
21
- children: !u?.id || !d ? /* @__PURE__ */ s("p", { children: "Sign in and choose a workspace to use an assistant." }) : h.loading ? /* @__PURE__ */ s("p", {
33
+ children: !o?.id || !s ? /* @__PURE__ */ m("p", { children: r("botlit.chat.signIn", "Sign in and choose a workspace to use an assistant.") }) : _.loading ? /* @__PURE__ */ m("p", {
22
34
  role: "status",
23
- children: "Loading assistants…"
24
- }) : h.error ? /* @__PURE__ */ c("div", {
35
+ children: r("botlit.chat.loadingAssistants", "Loading assistants…")
36
+ }) : _.error ? /* @__PURE__ */ h("div", {
25
37
  role: "alert",
26
- children: [/* @__PURE__ */ s("p", { children: "Assistants could not be loaded. Check your access and try again." }), /* @__PURE__ */ s(t, {
27
- variant: "outline",
28
- onClick: () => void h.refetch(),
29
- children: "Reload assistants"
30
- })]
31
- }) : /* @__PURE__ */ c(o, { children: [!n && /* @__PURE__ */ c("label", {
32
- className: "grid gap-2 text-sm font-medium",
33
- children: ["Assistant", /* @__PURE__ */ c("select", {
34
- className: "h-10 rounded-md border border-border-default bg-bg-surface px-3",
35
- value: g,
36
- onChange: (e) => _(e.target.value),
37
- children: [/* @__PURE__ */ s("option", {
38
- value: "",
39
- children: "Choose an assistant"
40
- }), h.data?.filter((e) => e.status === "ACTIVE").map((e) => /* @__PURE__ */ s("option", {
41
- value: e.id,
42
- children: e.name
43
- }, e.id))]
44
- })]
45
- }), y ? /* @__PURE__ */ s(m, {
46
- agentId: y.id,
47
- agentName: y.name,
48
- ownerId: u.id,
49
- workspaceId: d,
50
- authToken: f,
51
- onNavigate: p
52
- }, y.id) : /* @__PURE__ */ c("div", {
53
- className: "space-y-2",
54
- children: [/* @__PURE__ */ s("p", { children: v ? "This assistant is not live, so it cannot hold a saved conversation yet. Activate it, or test it first." : "Choose an assistant to begin." }), v && h.data?.some((e) => e.id === v) && /* @__PURE__ */ s(t, {
38
+ children: [/* @__PURE__ */ m("p", { children: r("botlit.chat.assistantsError", "Assistants could not be loaded. Check your access and try again.") }), /* @__PURE__ */ m(n, {
55
39
  variant: "outline",
56
- onClick: () => p(`agents/${v}/test`),
57
- children: "Test this agent"
40
+ onClick: () => void _.refetch(),
41
+ children: r("botlit.chat.reloadAssistants", "Reload assistants")
58
42
  })]
59
- })] })
43
+ }) : /* @__PURE__ */ h(p, { children: [
44
+ !a && /* @__PURE__ */ h("label", {
45
+ className: "grid gap-2 text-sm font-medium",
46
+ children: [r("botlit.chat.assistantLabel", "Assistant"), /* @__PURE__ */ h("select", {
47
+ className: "h-10 rounded-md border border-border-default bg-bg-surface px-3",
48
+ value: v,
49
+ onChange: (e) => y(e.target.value),
50
+ children: [
51
+ /* @__PURE__ */ m("option", {
52
+ value: "",
53
+ children: r("botlit.chat.choose", "Choose an assistant")
54
+ }),
55
+ D.map((e) => /* @__PURE__ */ m("option", {
56
+ value: e.id,
57
+ children: e.name
58
+ }, e.id)),
59
+ O.length > 0 && /* @__PURE__ */ m("optgroup", {
60
+ label: r("botlit.chat.unavailableGroup", "Not available for saved chats"),
61
+ children: O.map((e) => {
62
+ let t = l(e);
63
+ return /* @__PURE__ */ m("option", {
64
+ value: e.id,
65
+ children: t.available ? e.name : r("botlit.chat.unavailableOption", "{{name}} ({{reason}})", {
66
+ name: e.name,
67
+ reason: b(r, t.reason)
68
+ })
69
+ }, e.id);
70
+ })
71
+ })
72
+ ]
73
+ })]
74
+ }),
75
+ E ? /* @__PURE__ */ m(C, {
76
+ agent: E,
77
+ ownerId: o.id,
78
+ workspaceId: s,
79
+ authToken: u,
80
+ onNavigate: d
81
+ }, E.id) : x ? /* @__PURE__ */ m(S, {
82
+ agentId: x,
83
+ onNavigate: d
84
+ }) : /* @__PURE__ */ m("p", { children: D.length > 0 ? r("botlit.chat.chooseToBegin", "Choose an assistant to begin.") : r("botlit.chat.noneAvailable", "No assistant is set up for saved chats yet. Open an agent and connect it on its Assistant setup tab.") }),
85
+ /* @__PURE__ */ m(T, {})
86
+ ] })
60
87
  })
61
88
  });
62
89
  }
63
- function p(e) {
64
- let t = e?.knowledgeAccess;
65
- return !!(t && typeof t == "object");
66
- }
67
- function m({ agentId: e, agentName: r, ownerId: i, workspaceId: a, authToken: o, onNavigate: l }) {
68
- let d = n(e);
69
- return d.loading && !d.data ? /* @__PURE__ */ s("p", {
90
+ function S({ agentId: t, onNavigate: i }) {
91
+ let a = e(), o = r(t);
92
+ return o.loading && !o.data ? /* @__PURE__ */ m("p", {
70
93
  role: "status",
71
- children: "Loading assistant…"
72
- }) : d.data ? p(d.data.metadata) ? /* @__PURE__ */ c("div", {
94
+ children: a("botlit.chat.loadingAssistant", "Loading assistant…")
95
+ }) : o.error ? /* @__PURE__ */ h("div", {
96
+ role: "alert",
97
+ className: "space-y-2",
98
+ children: [/* @__PURE__ */ m("p", { children: a("botlit.chat.assistantLoadError", "This assistant could not be loaded.") }), /* @__PURE__ */ m(n, {
99
+ variant: "outline",
100
+ size: "sm",
101
+ onClick: () => void o.refetch(),
102
+ children: a("botlit.common.retry", "Retry")
103
+ })]
104
+ }) : o.data ? /* @__PURE__ */ h("div", {
105
+ className: "space-y-2",
106
+ children: [/* @__PURE__ */ m("p", { children: a("botlit.chat.notLive", "This assistant is not live, so it cannot hold a saved conversation yet. Activate it, or test it first.") }), /* @__PURE__ */ m(n, {
107
+ variant: "outline",
108
+ onClick: () => i(`agents/${t}/test`),
109
+ children: a("botlit.chat.testAgent", "Test this agent")
110
+ })]
111
+ }) : /* @__PURE__ */ m("p", {
112
+ role: "alert",
113
+ children: a("botlit.chat.assistantNotFound", "This assistant could not be found.")
114
+ });
115
+ }
116
+ function C({ agent: t, ownerId: r, workspaceId: i, authToken: a, onNavigate: o }) {
117
+ let s = e(), [c, d] = f(0), p = l(t);
118
+ if (!p.available) return /* @__PURE__ */ h("div", {
73
119
  role: "status",
74
120
  className: "space-y-3",
75
- children: [/* @__PURE__ */ c("p", { children: [r, " is a course assistant. It answers learners in its course chat, not in AI Chat."] }), /* @__PURE__ */ s(t, {
76
- variant: "outline",
77
- onClick: () => l(`agents/${e}`),
78
- children: "Open agent"
121
+ children: [/* @__PURE__ */ m("p", { children: s("botlit.chat.cannotUse", "{{name}} cannot be used for saved chats: {{reason}}.", {
122
+ name: t.name,
123
+ reason: b(s, p.reason)
124
+ }) }), /* @__PURE__ */ h("div", {
125
+ className: "flex flex-wrap gap-2",
126
+ children: [/* @__PURE__ */ m(n, {
127
+ variant: "outline",
128
+ onClick: () => o(`agents/${t.id}`),
129
+ children: s("botlit.chat.openAgent", "Open the agent")
130
+ }), p.reason !== "courseTutor" && /* @__PURE__ */ m(n, {
131
+ onClick: () => o(`agents/${t.id}/test`),
132
+ children: s("botlit.chat.testAgent", "Test this agent")
133
+ })]
79
134
  })]
80
- }) : /* @__PURE__ */ s(u, {
81
- target: {
82
- kind: "botmanor",
83
- agentId: e
84
- },
85
- context: {
86
- workspaceId: a,
87
- authContext: { accessToken: o }
88
- },
89
- ownerId: i,
90
- title: r,
91
- description: "Answers from this assistant’s configured knowledge."
92
- }) : /* @__PURE__ */ c("div", {
135
+ });
136
+ let g = u(t);
137
+ return /* @__PURE__ */ h("div", {
138
+ className: "space-y-4",
139
+ children: [
140
+ !g && /* @__PURE__ */ m("p", {
141
+ role: "note",
142
+ className: "rounded-md border border-border-default bg-bg-surface p-3 text-sm",
143
+ children: s("botlit.chat.noKnowledge", "{{name}} does not search any knowledge, so its answers come from the model alone and are not grounded in your sources.", { name: t.name })
144
+ }),
145
+ /* @__PURE__ */ m(v, {
146
+ target: {
147
+ kind: "botmanor",
148
+ agentId: t.id
149
+ },
150
+ context: {
151
+ workspaceId: i,
152
+ authContext: { accessToken: a }
153
+ },
154
+ ownerId: r,
155
+ title: t.name,
156
+ description: g ? s("botlit.chat.panelGrounded", "Answers come from this assistant’s knowledge. When nothing relevant is found, it says so.") : s("botlit.chat.panelUngrounded", "Answers come from the model alone.")
157
+ }, c),
158
+ /* @__PURE__ */ m(w, {
159
+ agentId: t.id,
160
+ onDeleted: () => d((e) => e + 1)
161
+ })
162
+ ]
163
+ });
164
+ }
165
+ function w({ agentId: t, onDeleted: r }) {
166
+ let i = e(), s = o(t), { remove: c, deletingId: l } = a(), u = async (e) => {
167
+ if (await d({
168
+ title: i("botlit.chat.delete.title", "Delete conversation?"),
169
+ message: i("botlit.chat.delete.confirm", "The conversation and its answers are removed from your history. This cannot be undone."),
170
+ confirmLabel: i("botlit.common.delete", "Delete"),
171
+ cancelLabel: i("botlit.common.cancel", "Cancel")
172
+ })) try {
173
+ await c(e), _.success(i("botlit.chat.delete.success", "Conversation deleted")), r(), await s.refetch();
174
+ } catch {
175
+ _.error(i("botlit.chat.delete.error", "The conversation could not be deleted. Try again."));
176
+ }
177
+ };
178
+ return s.loading && s.data.length === 0 ? null : s.error ? /* @__PURE__ */ h("div", {
93
179
  role: "alert",
94
- className: "space-y-2",
95
- children: [/* @__PURE__ */ s("p", { children: "This assistant could not be loaded. Check your access and try again." }), /* @__PURE__ */ s(t, {
180
+ className: "space-y-2 text-sm",
181
+ children: [/* @__PURE__ */ m("p", { children: i("botlit.chat.conversations.error", "Your saved conversations could not be loaded.") }), /* @__PURE__ */ m(n, {
96
182
  variant: "outline",
97
- onClick: () => void d.refetch(),
98
- children: "Retry"
183
+ size: "sm",
184
+ onClick: () => void s.refetch(),
185
+ children: i("botlit.common.retry", "Retry")
186
+ })]
187
+ }) : s.data.length === 0 ? null : /* @__PURE__ */ h("section", {
188
+ "aria-labelledby": "botmanor-chat-history",
189
+ className: "space-y-2",
190
+ children: [/* @__PURE__ */ m("h2", {
191
+ id: "botmanor-chat-history",
192
+ className: "text-sm font-semibold",
193
+ children: i("botlit.chat.conversations.title", "Your saved conversations")
194
+ }), /* @__PURE__ */ m("ul", {
195
+ className: "divide-y divide-border-default rounded-md border border-border-default",
196
+ children: s.data.map((e) => /* @__PURE__ */ h("li", {
197
+ className: "flex items-center justify-between gap-2 p-2 text-sm",
198
+ children: [/* @__PURE__ */ m("span", { children: i("botlit.chat.conversations.started", "Started {{when}}", { when: E(e.createdAt) }) }), /* @__PURE__ */ m(n, {
199
+ variant: "outline",
200
+ size: "sm",
201
+ isLoading: l === e.clientConversationId,
202
+ onClick: () => void u(e.clientConversationId),
203
+ children: i("botlit.common.delete", "Delete")
204
+ })]
205
+ }, e.clientConversationId))
99
206
  })]
100
207
  });
101
208
  }
102
- export { d as ChatPage };
209
+ function T() {
210
+ let t = e(), n = s(), r = n.data;
211
+ return /* @__PURE__ */ h("aside", {
212
+ className: "space-y-1 text-sm text-text-secondary",
213
+ "aria-label": t("botlit.chat.privacy.label", "About your saved conversations"),
214
+ children: [/* @__PURE__ */ m("p", { children: t("botlit.chat.privacy.stored", "Your messages and the assistant’s answers are saved to your history, after any masking your workspace’s data policies apply. Only you can read them. Workspace administrators see each run’s tokens, cost and model on the Executions page, never its messages.") }), /* @__PURE__ */ m("p", { children: n.error ? t("botlit.chat.privacy.retentionUnknown", "The retention period could not be loaded.") : r === void 0 ? t("botlit.chat.privacy.retentionLoading", "Checking how long conversations are kept…") : r === null ? t("botlit.chat.privacy.keptUntilDeleted", "Conversations are kept until you delete them or the workspace is closed.") : t("botlit.chat.privacy.keptDays", "Conversations are deleted automatically after {{days}} days, or sooner when you delete them.", { days: r }) })]
215
+ });
216
+ }
217
+ function E(e) {
218
+ let t = new Date(e);
219
+ if (Number.isNaN(t.getTime())) return e;
220
+ let n = typeof document < "u" && document.documentElement.lang ? document.documentElement.lang : void 0;
221
+ return new Intl.DateTimeFormat(n, {
222
+ dateStyle: "medium",
223
+ timeStyle: "short"
224
+ }).format(t);
225
+ }
226
+ export { y as ChatPage };
103
227
 
104
228
  //# sourceMappingURL=ChatPage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ChatPage.js","names":["_Fragment","Fragment$1","ChatPage","useBotlit","ScopedChatPage","workspaceId","currentUser","useParams","agents","useAgents","chosen","setChosen","useState","selectedId","agentId","selected","agent","PageLayout","Button","event","SelectedAssistant","navigateTo","isCourseTutor","access","metadata","detail","useAgent","agentName","onNavigate","WorkflowAssistantPanel","authToken"],"sources":["../../../src/botlit/pages/ChatPage.tsx"],"sourcesContent":["/** Authenticated Botmanor agent chat with canonical, owner-scoped workflow history. */\nimport { useState } from 'react';\nimport { useParams } from 'react-router';\nimport { WorkflowAssistantPanel } from '@burdenoff/fe-libs/shared/assistant';\nimport { PageLayout } from '../components/PageLayout';\nimport { Button } from '../components/Button';\nimport { useAgent, useAgents } from '../hooks/useAgents';\nimport { useBotlit } from '../providers/BotlitProvider';\n\nexport function ChatPage() {\n const { workspaceId, currentUser } = useBotlit();\n return <ScopedChatPage key={`${workspaceId}:${currentUser?.id}`} />;\n}\n\nfunction ScopedChatPage() {\n const { agentId } = useParams();\n const { currentUser, workspaceId, authToken, navigateTo } = useBotlit();\n const agents = useAgents();\n const [chosen, setChosen] = useState('');\n const selectedId = agentId ?? chosen;\n const selected = agents.data?.find(\n (agent) => agent.id === selectedId && agent.status === 'ACTIVE'\n );\n return (\n <PageLayout\n title={selected ? `Chat with ${selected.name}` : 'AI Chat'}\n description=\"Ask questions grounded in your assistant’s knowledge. Your conversation is saved securely.\"\n >\n <div className=\"mx-auto flex w-full max-w-4xl flex-col gap-4 p-4\">\n {!currentUser?.id || !workspaceId ? (\n <p>Sign in and choose a workspace to use an assistant.</p>\n ) : agents.loading ? (\n <p role=\"status\">Loading assistants…</p>\n ) : agents.error ? (\n <div role=\"alert\">\n <p>Assistants could not be loaded. Check your access and try again.</p>\n <Button variant=\"outline\" onClick={() => void agents.refetch()}>\n Reload assistants\n </Button>\n </div>\n ) : (\n <>\n {!agentId && (\n <label className=\"grid gap-2 text-sm font-medium\">\n Assistant\n <select\n className=\"h-10 rounded-md border border-border-default bg-bg-surface px-3\"\n value={chosen}\n onChange={(event) => setChosen(event.target.value)}\n >\n <option value=\"\">Choose an assistant</option>\n {agents.data\n ?.filter((agent) => agent.status === 'ACTIVE')\n .map((agent) => (\n <option key={agent.id} value={agent.id}>\n {agent.name}\n </option>\n ))}\n </select>\n </label>\n )}\n {selected ? (\n // Keyed by agent so a newly chosen assistant is always read fresh.\n <SelectedAssistant\n key={selected.id}\n agentId={selected.id}\n agentName={selected.name}\n ownerId={currentUser.id}\n workspaceId={workspaceId}\n authToken={authToken}\n onNavigate={navigateTo}\n />\n ) : (\n <div className=\"space-y-2\">\n <p>\n {selectedId\n ? 'This assistant is not live, so it cannot hold a saved conversation yet. Activate it, or test it first.'\n : 'Choose an assistant to begin.'}\n </p>\n {selectedId && agents.data?.some((agent) => agent.id === selectedId) && (\n <Button variant=\"outline\" onClick={() => navigateTo(`agents/${selectedId}/test`)}>\n Test this agent\n </Button>\n )}\n </div>\n )}\n </>\n )}\n </div>\n </PageLayout>\n );\n}\n\n/** True when the agent is a private course tutor, which answers only in its course chat. */\nfunction isCourseTutor(metadata: Record<string, unknown> | null | undefined): boolean {\n const access = metadata?.knowledgeAccess;\n return Boolean(access && typeof access === 'object');\n}\n\n/**\n * One chosen assistant. Saved chats run through the agent's managed answer\n * workflow when \"Assistant setup\" configured one, and with direct inference\n * otherwise (BOFF-15360) — every active workspace agent can chat. Only a\n * course tutor is kept to its course chat.\n */\nfunction SelectedAssistant({\n agentId,\n agentName,\n ownerId,\n workspaceId,\n authToken,\n onNavigate,\n}: {\n agentId: string;\n agentName: string;\n ownerId: string;\n workspaceId: string;\n authToken?: string;\n onNavigate: (path: string) => void;\n}) {\n const detail = useAgent(agentId);\n if (detail.loading && !detail.data) return <p role=\"status\">Loading assistant…</p>;\n if (!detail.data) {\n return (\n <div role=\"alert\" className=\"space-y-2\">\n <p>This assistant could not be loaded. Check your access and try again.</p>\n <Button variant=\"outline\" onClick={() => void detail.refetch()}>\n Retry\n </Button>\n </div>\n );\n }\n if (isCourseTutor(detail.data.metadata)) {\n return (\n <div role=\"status\" className=\"space-y-3\">\n <p>\n {agentName} is a course assistant. It answers learners in its course chat, not in AI Chat.\n </p>\n <Button variant=\"outline\" onClick={() => onNavigate(`agents/${agentId}`)}>\n Open agent\n </Button>\n </div>\n );\n }\n return (\n <WorkflowAssistantPanel\n target={{ kind: 'botmanor', agentId }}\n context={{ workspaceId, authContext: { accessToken: authToken } }}\n ownerId={ownerId}\n title={agentName}\n description=\"Answers from this assistant’s configured knowledge.\"\n />\n );\n}\n"],"mappings":";;;;;;;;;AASA,SAAgBE,IAAW;CACzB,IAAM,EAAE,gBAAa,mBAAgBC,EAAU;CAC/C,OAAO,kBAACC,GAAD,CAA2D,GAAtC,GAAGC,EAAY,GAAGC,GAAa,IAAO;AACpE;AAEA,SAASF,IAAiB;CACxB,IAAM,EAAE,eAAYG,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,CACL;;AAwBX"}
1
+ {"version":3,"file":"ChatPage.js","names":["_Fragment","Fragment$1","ChatPage","useBotlit","ScopedChatPage","workspaceId","currentUser","unavailableReason","reason","t","useTr","useParams","assistants","useChatAssistants","chosen","setChosen","useState","selectedId","agentId","rows","selected","agent","runnable","assistantAvailability","unavailable","PageLayout","Button","event","availability","SelectedAssistant","navigateTo","InactiveAssistant","PrivacyNotice","detail","useAgent","onNavigate","panelKey","setPanelKey","hasKnowledge","searchesKnowledge","WorkflowAssistantPanel","authToken","MyConversations","key","conversations","useMyAssistantConversations","useDeleteMyAssistantConversation","handleDelete","confirmAction","remove","clientConversationId","toast","onDeleted","formatConversationTime","conversation","deletingId","retention","useMyAssistantRetention","days","date","iso","locale"],"sources":["../../../src/botlit/pages/ChatPage.tsx"],"sourcesContent":["/** Authenticated Botmanor agent chat with canonical, owner-scoped workflow history. */\nimport { useState } from 'react';\nimport { useParams } from 'react-router';\nimport { toast } from 'sonner';\nimport { WorkflowAssistantPanel } from '@burdenoff/fe-libs/shared/assistant';\nimport { useTr } from '../../shared/hooks/useTr';\nimport { PageLayout } from '../components/PageLayout';\nimport { Button } from '../components/Button';\nimport { useAgent } from '../hooks/useAgents';\nimport {\n useChatAssistants,\n useDeleteMyAssistantConversation,\n useMyAssistantConversations,\n useMyAssistantRetention,\n type ChatAssistantRecord,\n} from '../hooks/useAssistantChat';\nimport { useBotlit } from '../providers/BotlitProvider';\nimport {\n assistantAvailability,\n searchesKnowledge,\n type AssistantUnavailableReason,\n} from '../utils/assistantAvailability';\nimport { confirmAction } from '../utils/confirmAction';\n\ntype Translate = ReturnType<typeof useTr>;\n\nexport function ChatPage() {\n const { workspaceId, currentUser } = useBotlit();\n return <ScopedChatPage key={`${workspaceId}:${currentUser?.id}`} />;\n}\n\n/** Why an agent cannot hold a saved chat, in words the user can act on. */\nfunction unavailableReason(t: Translate, reason: AssistantUnavailableReason): string {\n switch (reason) {\n case 'inactive':\n return t('botlit.chat.unavailable.inactive', 'it is not active');\n case 'noModel':\n return t('botlit.chat.unavailable.noModel', 'it has no model');\n case 'courseTutor':\n return t(\n 'botlit.chat.unavailable.courseTutor',\n 'it is a course assistant, which answers learners in its course chat'\n );\n }\n}\n\nfunction ScopedChatPage() {\n const t = useTr();\n const { agentId } = useParams();\n const { currentUser, workspaceId, authToken, navigateTo } = useBotlit();\n const assistants = useChatAssistants();\n const [chosen, setChosen] = useState('');\n const selectedId = agentId ?? chosen;\n const rows = assistants.data ?? [];\n const selected = rows.find((agent) => agent.id === selectedId);\n const runnable = rows.filter((agent) => assistantAvailability(agent).available);\n const unavailable = rows.filter((agent) => !assistantAvailability(agent).available);\n\n return (\n <PageLayout\n title={\n selected\n ? t('botlit.chat.titleWithAgent', 'Chat with {{name}}', { name: selected.name })\n : t('botlit.chat.title', 'AI Chat')\n }\n description={t(\n 'botlit.chat.description',\n 'Ask an assistant questions about its knowledge. Your conversations are saved to your account.'\n )}\n >\n <div className=\"mx-auto flex w-full max-w-4xl flex-col gap-4 p-4\">\n {!currentUser?.id || !workspaceId ? (\n <p>{t('botlit.chat.signIn', 'Sign in and choose a workspace to use an assistant.')}</p>\n ) : assistants.loading ? (\n <p role=\"status\">{t('botlit.chat.loadingAssistants', 'Loading assistants…')}</p>\n ) : assistants.error ? (\n <div role=\"alert\">\n <p>\n {t(\n 'botlit.chat.assistantsError',\n 'Assistants could not be loaded. Check your access and try again.'\n )}\n </p>\n <Button variant=\"outline\" onClick={() => void assistants.refetch()}>\n {t('botlit.chat.reloadAssistants', 'Reload assistants')}\n </Button>\n </div>\n ) : (\n <>\n {!agentId && (\n <label className=\"grid gap-2 text-sm font-medium\">\n {t('botlit.chat.assistantLabel', 'Assistant')}\n <select\n className=\"h-10 rounded-md border border-border-default bg-bg-surface px-3\"\n value={chosen}\n onChange={(event) => setChosen(event.target.value)}\n >\n <option value=\"\">{t('botlit.chat.choose', 'Choose an assistant')}</option>\n {runnable.map((agent) => (\n <option key={agent.id} value={agent.id}>\n {agent.name}\n </option>\n ))}\n {unavailable.length > 0 && (\n <optgroup\n label={t('botlit.chat.unavailableGroup', 'Not available for saved chats')}\n >\n {unavailable.map((agent) => {\n const availability = assistantAvailability(agent);\n return (\n <option key={agent.id} value={agent.id}>\n {availability.available\n ? agent.name\n : t('botlit.chat.unavailableOption', '{{name}} ({{reason}})', {\n name: agent.name,\n reason: unavailableReason(t, availability.reason),\n })}\n </option>\n );\n })}\n </optgroup>\n )}\n </select>\n </label>\n )}\n {selected ? (\n <SelectedAssistant\n key={selected.id}\n agent={selected}\n ownerId={currentUser.id}\n workspaceId={workspaceId}\n authToken={authToken}\n onNavigate={navigateTo}\n />\n ) : selectedId ? (\n <InactiveAssistant agentId={selectedId} onNavigate={navigateTo} />\n ) : (\n <p>\n {runnable.length > 0\n ? t('botlit.chat.chooseToBegin', 'Choose an assistant to begin.')\n : t(\n 'botlit.chat.noneAvailable',\n 'No assistant is set up for saved chats yet. Open an agent and connect it on its Assistant setup tab.'\n )}\n </p>\n )}\n <PrivacyNotice />\n </>\n )}\n </div>\n </PageLayout>\n );\n}\n\n/** An agent named in the URL that is not ACTIVE (or not readable). */\nfunction InactiveAssistant({\n agentId,\n onNavigate,\n}: {\n agentId: string;\n onNavigate: (path: string) => void;\n}) {\n const t = useTr();\n const detail = useAgent(agentId);\n if (detail.loading && !detail.data) {\n return <p role=\"status\">{t('botlit.chat.loadingAssistant', 'Loading assistant…')}</p>;\n }\n if (detail.error) {\n return (\n <div role=\"alert\" className=\"space-y-2\">\n <p>{t('botlit.chat.assistantLoadError', 'This assistant could not be loaded.')}</p>\n <Button variant=\"outline\" size=\"sm\" onClick={() => void detail.refetch()}>\n {t('botlit.common.retry', 'Retry')}\n </Button>\n </div>\n );\n }\n if (!detail.data) {\n return (\n <p role=\"alert\">{t('botlit.chat.assistantNotFound', 'This assistant could not be found.')}</p>\n );\n }\n return (\n <div className=\"space-y-2\">\n <p>\n {t(\n 'botlit.chat.notLive',\n 'This assistant is not live, so it cannot hold a saved conversation yet. Activate it, or test it first.'\n )}\n </p>\n <Button variant=\"outline\" onClick={() => onNavigate(`agents/${agentId}/test`)}>\n {t('botlit.chat.testAgent', 'Test this agent')}\n </Button>\n </div>\n );\n}\n\n/**\n * One chosen assistant. Saved chats run through the agent's managed answer\n * workflow when Assistant setup configured one, and with direct inference\n * otherwise (BOFF-15360). An agent that cannot run here gets the reason\n * instead of a chat that would be refused.\n */\nfunction SelectedAssistant({\n agent,\n ownerId,\n workspaceId,\n authToken,\n onNavigate,\n}: {\n agent: ChatAssistantRecord;\n ownerId: string;\n workspaceId: string;\n authToken?: string;\n onNavigate: (path: string) => void;\n}) {\n const t = useTr();\n // Remounts the panel after a conversation is deleted, so it reloads history.\n const [panelKey, setPanelKey] = useState(0);\n const availability = assistantAvailability(agent);\n if (!availability.available) {\n return (\n <div role=\"status\" className=\"space-y-3\">\n <p>\n {t('botlit.chat.cannotUse', '{{name}} cannot be used for saved chats: {{reason}}.', {\n name: agent.name,\n reason: unavailableReason(t, availability.reason),\n })}\n </p>\n <div className=\"flex flex-wrap gap-2\">\n <Button variant=\"outline\" onClick={() => onNavigate(`agents/${agent.id}`)}>\n {t('botlit.chat.openAgent', 'Open the agent')}\n </Button>\n {availability.reason !== 'courseTutor' && (\n <Button onClick={() => onNavigate(`agents/${agent.id}/test`)}>\n {t('botlit.chat.testAgent', 'Test this agent')}\n </Button>\n )}\n </div>\n </div>\n );\n }\n // Only an assistant that retrieves (RAG) answers from its knowledge.\n const hasKnowledge = searchesKnowledge(agent);\n return (\n <div className=\"space-y-4\">\n {!hasKnowledge && (\n <p\n role=\"note\"\n className=\"rounded-md border border-border-default bg-bg-surface p-3 text-sm\"\n >\n {t(\n 'botlit.chat.noKnowledge',\n '{{name}} does not search any knowledge, so its answers come from the model alone and are not grounded in your sources.',\n { name: agent.name }\n )}\n </p>\n )}\n <WorkflowAssistantPanel\n key={panelKey}\n target={{ kind: 'botmanor', agentId: agent.id }}\n context={{ workspaceId, authContext: { accessToken: authToken } }}\n ownerId={ownerId}\n title={agent.name}\n description={\n hasKnowledge\n ? t(\n 'botlit.chat.panelGrounded',\n 'Answers come from this assistant’s knowledge. When nothing relevant is found, it says so.'\n )\n : t('botlit.chat.panelUngrounded', 'Answers come from the model alone.')\n }\n />\n <MyConversations agentId={agent.id} onDeleted={() => setPanelKey((key) => key + 1)} />\n </div>\n );\n}\n\n/** The caller's saved conversations with this assistant, each deletable. */\nfunction MyConversations({ agentId, onDeleted }: { agentId: string; onDeleted: () => void }) {\n const t = useTr();\n const conversations = useMyAssistantConversations(agentId);\n const { remove, deletingId } = useDeleteMyAssistantConversation();\n\n const handleDelete = async (clientConversationId: string) => {\n const confirmed = await confirmAction({\n title: t('botlit.chat.delete.title', 'Delete conversation?'),\n message: t(\n 'botlit.chat.delete.confirm',\n 'The conversation and its answers are removed from your history. This cannot be undone.'\n ),\n confirmLabel: t('botlit.common.delete', 'Delete'),\n cancelLabel: t('botlit.common.cancel', 'Cancel'),\n });\n if (!confirmed) return;\n try {\n await remove(clientConversationId);\n toast.success(t('botlit.chat.delete.success', 'Conversation deleted'));\n onDeleted();\n await conversations.refetch();\n } catch {\n toast.error(\n t('botlit.chat.delete.error', 'The conversation could not be deleted. Try again.')\n );\n }\n };\n\n if (conversations.loading && conversations.data.length === 0) return null;\n if (conversations.error) {\n return (\n <div role=\"alert\" className=\"space-y-2 text-sm\">\n <p>\n {t('botlit.chat.conversations.error', 'Your saved conversations could not be loaded.')}\n </p>\n <Button variant=\"outline\" size=\"sm\" onClick={() => void conversations.refetch()}>\n {t('botlit.common.retry', 'Retry')}\n </Button>\n </div>\n );\n }\n if (conversations.data.length === 0) return null;\n return (\n <section aria-labelledby=\"botmanor-chat-history\" className=\"space-y-2\">\n <h2 id=\"botmanor-chat-history\" className=\"text-sm font-semibold\">\n {t('botlit.chat.conversations.title', 'Your saved conversations')}\n </h2>\n <ul className=\"divide-y divide-border-default rounded-md border border-border-default\">\n {conversations.data.map((conversation) => (\n <li\n key={conversation.clientConversationId}\n className=\"flex items-center justify-between gap-2 p-2 text-sm\"\n >\n <span>\n {t('botlit.chat.conversations.started', 'Started {{when}}', {\n when: formatConversationTime(conversation.createdAt),\n })}\n </span>\n <Button\n variant=\"outline\"\n size=\"sm\"\n isLoading={deletingId === conversation.clientConversationId}\n onClick={() => void handleDelete(conversation.clientConversationId)}\n >\n {t('botlit.common.delete', 'Delete')}\n </Button>\n </li>\n ))}\n </ul>\n </section>\n );\n}\n\n/** What is stored, who can read it and for how long (BOFF-12699). */\nfunction PrivacyNotice() {\n const t = useTr();\n const retention = useMyAssistantRetention();\n const days = retention.data;\n return (\n <aside\n className=\"space-y-1 text-sm text-text-secondary\"\n aria-label={t('botlit.chat.privacy.label', 'About your saved conversations')}\n >\n <p>\n {t(\n 'botlit.chat.privacy.stored',\n 'Your messages and the assistant’s answers are saved to your history, after any masking your workspace’s data policies apply. Only you can read them. Workspace administrators see each run’s tokens, cost and model on the Executions page, never its messages.'\n )}\n </p>\n <p>\n {retention.error\n ? t('botlit.chat.privacy.retentionUnknown', 'The retention period could not be loaded.')\n : days === undefined\n ? t('botlit.chat.privacy.retentionLoading', 'Checking how long conversations are kept…')\n : days === null\n ? t(\n 'botlit.chat.privacy.keptUntilDeleted',\n 'Conversations are kept until you delete them or the workspace is closed.'\n )\n : t(\n 'botlit.chat.privacy.keptDays',\n 'Conversations are deleted automatically after {{days}} days, or sooner when you delete them.',\n { days }\n )}\n </p>\n </aside>\n );\n}\n\n/** A conversation's start time in the viewer's locale (no English-only relative wording). */\nfunction formatConversationTime(iso: string): string {\n const date = new Date(iso);\n if (Number.isNaN(date.getTime())) return iso;\n const locale =\n typeof document !== 'undefined' && document.documentElement.lang\n ? document.documentElement.lang\n : undefined;\n return new Intl.DateTimeFormat(locale, { dateStyle: 'medium', timeStyle: 'short' }).format(date);\n}\n"],"mappings":";;;;;;;;;;;;;;AA0BA,SAAgBE,IAAW;CACzB,IAAM,EAAE,gBAAa,mBAAgBC,EAAU;CAC/C,OAAO,kBAACC,GAAD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;EACV,cAAY,EAAE,6BAA6B,gCAAgC;EAF7E,UAAA,CAIE,kBAAC,KAAD,EAAA,UACG,EACC,8BACA,iQACF,EACC,CAAA,GACH,kBAAC,KAAD,EAAA,UACGA,EAAU,QACP,EAAE,wCAAwC,2CAA2C,IACrFE,MAAS,KAAA,IACP,EAAE,wCAAwC,2CAA2C,IACrFA,MAAS,OACP,EACE,wCACA,0EACF,IACA,EACE,gCACA,gGACA,EAAE,QAAK,CACT,EACP,CAAA,CACE;;AAEX;AAGA,SAASL,EAAuB,GAAqB;CACnD,IAAMM,IAAO,IAAI,KAAKC,CAAG;CACzB,IAAI,OAAO,MAAMD,EAAK,QAAQ,CAAC,GAAG,OAAOC;CACzC,IAAMC,IACJ,OAAO,WAAa,OAAe,SAAS,gBAAgB,OACxD,SAAS,gBAAgB,OACzB,KAAA;CACN,OAAO,IAAI,KAAK,eAAeA,GAAQ;EAAE,WAAW;EAAU,WAAW;CAAQ,CAAC,CAAC,CAAC,OAAOF,CAAI;AACjG"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Which agents a saved AI Chat can use (BOFF-12696).
3
+ *
4
+ * A saved chat runs on the private generation path of wspace-botmanor-svc,
5
+ * through the agent's managed workflow when Assistant setup configured one and
6
+ * with direct inference otherwise; a workspace member's turn runs the agent's
7
+ * tools (BOFF-15360). That path refuses an agent that is not ACTIVE or has no
8
+ * model, and keeps a course tutor (`metadata.knowledgeAccess`) to its course
9
+ * chat. The rules below mirror those server checks so the page can say why an
10
+ * agent cannot be used before a turn fails.
11
+ */
12
+ export type AssistantUnavailableReason = 'inactive' | 'noModel' | 'courseTutor';
13
+ export interface AssistantCandidate {
14
+ status?: string | null;
15
+ llmModelId?: string | null;
16
+ capabilities?: readonly string[] | null;
17
+ knowledgeBaseIds?: readonly string[] | null;
18
+ metadata?: unknown;
19
+ }
20
+ export type AssistantAvailability = {
21
+ available: true;
22
+ } | {
23
+ available: false;
24
+ reason: AssistantUnavailableReason;
25
+ };
26
+ /** True when the agent is a private course tutor, which answers only in its course chat. */
27
+ export declare function isCourseTutor(metadata: unknown): boolean;
28
+ /**
29
+ * True when the agent's answers are held to its knowledge: it has knowledge
30
+ * attached and the RAG capability, the same rule the server uses to answer
31
+ * with the no-match message instead of the model (BOFF-12698).
32
+ */
33
+ export declare function searchesKnowledge(agent: AssistantCandidate): boolean;
34
+ export declare function assistantAvailability(agent: AssistantCandidate): AssistantAvailability;
@@ -0,0 +1,24 @@
1
+ // src/botlit/utils/assistantAvailability.ts
2
+ function e(e) {
3
+ if (!e || typeof e != "object" || Array.isArray(e)) return !1;
4
+ let t = e.knowledgeAccess;
5
+ return !!(t && typeof t == "object");
6
+ }
7
+ function t(e) {
8
+ return (e.knowledgeBaseIds?.length ?? 0) > 0 && (e.capabilities ?? []).includes("RAG");
9
+ }
10
+ function n(t) {
11
+ return t.status === "ACTIVE" ? e(t.metadata) ? {
12
+ available: !1,
13
+ reason: "courseTutor"
14
+ } : t.llmModelId ? { available: !0 } : {
15
+ available: !1,
16
+ reason: "noModel"
17
+ } : {
18
+ available: !1,
19
+ reason: "inactive"
20
+ };
21
+ }
22
+ export { n as assistantAvailability, e as isCourseTutor, t as searchesKnowledge };
23
+
24
+ //# sourceMappingURL=assistantAvailability.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assistantAvailability.js","names":["isCourseTutor","metadata","access","searchesKnowledge","agent","assistantAvailability"],"sources":["../../../src/botlit/utils/assistantAvailability.ts"],"sourcesContent":["/**\n * Which agents a saved AI Chat can use (BOFF-12696).\n *\n * A saved chat runs on the private generation path of wspace-botmanor-svc,\n * through the agent's managed workflow when Assistant setup configured one and\n * with direct inference otherwise; a workspace member's turn runs the agent's\n * tools (BOFF-15360). That path refuses an agent that is not ACTIVE or has no\n * model, and keeps a course tutor (`metadata.knowledgeAccess`) to its course\n * chat. The rules below mirror those server checks so the page can say why an\n * agent cannot be used before a turn fails.\n */\n\nexport type AssistantUnavailableReason = 'inactive' | 'noModel' | 'courseTutor';\n\nexport interface AssistantCandidate {\n status?: string | null;\n llmModelId?: string | null;\n capabilities?: readonly string[] | null;\n knowledgeBaseIds?: readonly string[] | null;\n metadata?: unknown;\n}\n\nexport type AssistantAvailability =\n { available: true } | { available: false; reason: AssistantUnavailableReason };\n\n/** True when the agent is a private course tutor, which answers only in its course chat. */\nexport function isCourseTutor(metadata: unknown): boolean {\n if (!metadata || typeof metadata !== 'object' || Array.isArray(metadata)) return false;\n const access = (metadata as Record<string, unknown>).knowledgeAccess;\n return Boolean(access && typeof access === 'object');\n}\n\n/**\n * True when the agent's answers are held to its knowledge: it has knowledge\n * attached and the RAG capability, the same rule the server uses to answer\n * with the no-match message instead of the model (BOFF-12698).\n */\nexport function searchesKnowledge(agent: AssistantCandidate): boolean {\n return (agent.knowledgeBaseIds?.length ?? 0) > 0 && (agent.capabilities ?? []).includes('RAG');\n}\n\nexport function assistantAvailability(agent: AssistantCandidate): AssistantAvailability {\n if (agent.status !== 'ACTIVE') return { available: false, reason: 'inactive' };\n if (isCourseTutor(agent.metadata)) return { available: false, reason: 'courseTutor' };\n if (!agent.llmModelId) return { available: false, reason: 'noModel' };\n return { available: true };\n}\n"],"mappings":";AA0BA,SAAgBA,EAAc,GAA4B;CACxD,IAAI,CAACC,KAAY,OAAOA,KAAa,YAAY,MAAM,QAAQA,CAAQ,GAAG,OAAO;CACjF,IAAMC,IAAUD,EAAqC;CACrD,OAAO,GAAQC,KAAU,OAAOA,KAAW;AAC7C;AAOA,SAAgBC,EAAkB,GAAoC;CACpE,QAAQC,EAAM,kBAAkB,UAAU,KAAK,MAAMA,EAAM,gBAAgB,CAAC,EAAA,CAAG,SAAS,KAAK;AAC/F;AAEA,SAAgBC,EAAsB,GAAkD;CAItF,OAHID,EAAM,WAAW,WACjBJ,EAAcI,EAAM,QAAQ,IAAU;EAAE,WAAW;EAAO,QAAQ;CAAc,IAC/EA,EAAM,aACJ,EAAE,WAAW,GAAK,IADK;EAAE,WAAW;EAAO,QAAQ;CAAU,IAF9B;EAAE,WAAW;EAAO,QAAQ;CAAW;AAI/E"}