@burdenoff/microfe-botmanor 2026.1119.3 → 2026.1120.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/botlit/components/DescribeBotDialog.d.ts +11 -0
- package/dist/botlit/components/DescribeBotDialog.js +354 -0
- package/dist/botlit/components/DescribeBotDialog.js.map +1 -0
- package/dist/botlit/components/KnowledgeSearchPanel.d.ts +10 -0
- package/dist/botlit/components/KnowledgeSearchPanel.js +103 -0
- package/dist/botlit/components/KnowledgeSearchPanel.js.map +1 -0
- package/dist/botlit/components/KnowledgeSourceImportPanel.js +88 -51
- package/dist/botlit/components/KnowledgeSourceImportPanel.js.map +1 -1
- package/dist/botlit/hooks/useBotCopilot.d.ts +95 -0
- package/dist/botlit/hooks/useBotCopilot.js +167 -0
- package/dist/botlit/hooks/useBotCopilot.js.map +1 -0
- package/dist/botlit/pages/AgentBuilderPage.js +110 -103
- package/dist/botlit/pages/AgentBuilderPage.js.map +1 -1
- package/dist/botlit/pages/BotDetailPage.js +297 -286
- package/dist/botlit/pages/BotDetailPage.js.map +1 -1
- package/dist/botlit/pages/KnowledgeBaseDetailPage.js +307 -302
- package/dist/botlit/pages/KnowledgeBaseDetailPage.js.map +1 -1
- package/dist/botlit/utils/knowledgeImportStatus.js +2 -7
- package/dist/botlit/utils/knowledgeImportStatus.js.map +1 -1
- package/package.json +1 -1
|
@@ -6,111 +6,148 @@ import { Button as i } from "./Button.js";
|
|
|
6
6
|
import { useRef as a, useState as o } from "react";
|
|
7
7
|
import { jsx as s, jsxs as c } from "react/jsx-runtime";
|
|
8
8
|
// src/botlit/components/KnowledgeSourceImportPanel.tsx
|
|
9
|
-
var l = {
|
|
9
|
+
var l = ".txt,.md,.markdown,.csv,.tsv,.json,.html,.htm,.xml,.yaml,.yml,.log", u = 245760, d = {
|
|
10
10
|
info: "text-text-secondary",
|
|
11
11
|
success: "text-status-success-text",
|
|
12
12
|
warning: "text-status-warning-text",
|
|
13
13
|
error: "text-status-error-text"
|
|
14
14
|
};
|
|
15
|
-
function
|
|
15
|
+
function f({ knowledgeBaseId: e }) {
|
|
16
16
|
let { workspaceId: n, currentUser: r } = t();
|
|
17
|
-
return /* @__PURE__ */ s(
|
|
17
|
+
return /* @__PURE__ */ s(p, { knowledgeBaseId: e }, `${n}:${r?.id}:${e}`);
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
let
|
|
19
|
+
function p({ knowledgeBaseId: t }) {
|
|
20
|
+
let f = e(t), [p, m] = o("website"), [h, g] = o(""), [_, v] = o(""), [y, b] = o(""), [x, S] = o(""), C = a(null), w = a(null), T = async (e) => {
|
|
21
|
+
if (v(""), S(""), !e) return;
|
|
22
|
+
if (e.size > u) {
|
|
23
|
+
b(`${e.name} is larger than 240 KiB. Split it into smaller files.`);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
let t = await e.text();
|
|
27
|
+
!t.trim() || t.includes("\0") ? b(`${e.name} has no readable text. Upload a plain-text file such as .txt, .md or .csv.`) : (v(t), S(e.name), h.trim() || g(e.name), b(""));
|
|
28
|
+
};
|
|
21
29
|
return /* @__PURE__ */ c("section", {
|
|
22
30
|
className: "space-y-4 rounded-lg border border-border-default p-5",
|
|
23
31
|
children: [
|
|
24
32
|
/* @__PURE__ */ s("h2", {
|
|
25
33
|
className: "text-lg font-semibold",
|
|
26
|
-
children: "
|
|
34
|
+
children: "Add knowledge"
|
|
27
35
|
}),
|
|
28
36
|
/* @__PURE__ */ s("p", {
|
|
29
37
|
className: "text-sm text-text-secondary",
|
|
30
|
-
children: "
|
|
38
|
+
children: "Upload a text file, paste text or import a public web page. BotManor captures each source in the background, splits it into chunks and embeds them; progress appears below. Course content uses the BuildMyIQ course import."
|
|
31
39
|
}),
|
|
32
40
|
/* @__PURE__ */ c("label", {
|
|
33
41
|
className: "grid gap-2 text-sm",
|
|
34
42
|
children: ["Source type", /* @__PURE__ */ c("select", {
|
|
35
43
|
className: "h-10 rounded-md border border-border-default bg-bg-surface px-3",
|
|
36
|
-
value:
|
|
37
|
-
disabled:
|
|
44
|
+
value: p,
|
|
45
|
+
disabled: f.queue.isPending,
|
|
38
46
|
onChange: (e) => {
|
|
39
|
-
|
|
47
|
+
m(e.target.value), v(""), S("");
|
|
40
48
|
},
|
|
41
|
-
children: [
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
children: [
|
|
50
|
+
/* @__PURE__ */ s("option", {
|
|
51
|
+
value: "website",
|
|
52
|
+
children: "Public website page"
|
|
53
|
+
}),
|
|
54
|
+
/* @__PURE__ */ s("option", {
|
|
55
|
+
value: "text",
|
|
56
|
+
children: "Text or Markdown"
|
|
57
|
+
}),
|
|
58
|
+
/* @__PURE__ */ s("option", {
|
|
59
|
+
value: "file",
|
|
60
|
+
children: "Upload a text file"
|
|
61
|
+
})
|
|
62
|
+
]
|
|
48
63
|
})]
|
|
49
64
|
}),
|
|
50
65
|
/* @__PURE__ */ c("label", {
|
|
51
66
|
className: "grid gap-2 text-sm",
|
|
52
67
|
children: ["Title", /* @__PURE__ */ s("input", {
|
|
53
68
|
className: "h-10 rounded-md border border-border-default bg-bg-surface px-3",
|
|
54
|
-
value:
|
|
69
|
+
value: h,
|
|
55
70
|
maxLength: 255,
|
|
56
|
-
disabled:
|
|
57
|
-
onChange: (e) =>
|
|
71
|
+
disabled: f.queue.isPending,
|
|
72
|
+
onChange: (e) => g(e.target.value)
|
|
58
73
|
})]
|
|
59
74
|
}),
|
|
60
|
-
/* @__PURE__ */ c("label", {
|
|
75
|
+
p === "file" ? /* @__PURE__ */ c("label", {
|
|
76
|
+
className: "grid gap-2 text-sm",
|
|
77
|
+
children: [
|
|
78
|
+
"Document",
|
|
79
|
+
/* @__PURE__ */ s("input", {
|
|
80
|
+
ref: w,
|
|
81
|
+
type: "file",
|
|
82
|
+
accept: l,
|
|
83
|
+
className: "text-sm",
|
|
84
|
+
disabled: f.queue.isPending,
|
|
85
|
+
onChange: (e) => void T(e.target.files?.[0])
|
|
86
|
+
}),
|
|
87
|
+
x && /* @__PURE__ */ c("span", {
|
|
88
|
+
className: "text-text-secondary",
|
|
89
|
+
children: [
|
|
90
|
+
x,
|
|
91
|
+
" · ",
|
|
92
|
+
new TextEncoder().encode(_).length.toLocaleString(),
|
|
93
|
+
" bytes ready"
|
|
94
|
+
]
|
|
95
|
+
})
|
|
96
|
+
]
|
|
97
|
+
}) : /* @__PURE__ */ c("label", {
|
|
61
98
|
className: "grid gap-2 text-sm",
|
|
62
|
-
children: [
|
|
99
|
+
children: [p === "website" ? "Exact public HTTPS page" : "Source text", /* @__PURE__ */ s("textarea", {
|
|
63
100
|
className: "rounded-md border border-border-default bg-bg-surface p-3",
|
|
64
|
-
rows:
|
|
65
|
-
value:
|
|
66
|
-
disabled:
|
|
67
|
-
onChange: (e) =>
|
|
101
|
+
rows: p === "website" ? 2 : 6,
|
|
102
|
+
value: _,
|
|
103
|
+
disabled: f.queue.isPending,
|
|
104
|
+
onChange: (e) => v(e.target.value)
|
|
68
105
|
})]
|
|
69
106
|
}),
|
|
70
107
|
/* @__PURE__ */ s("p", {
|
|
71
108
|
className: "text-sm text-text-secondary",
|
|
72
|
-
children: "Website imports capture one static page without signing in. Cross-origin redirects and embedded documents are rejected. Text
|
|
109
|
+
children: "Website imports capture one static page without signing in. Cross-origin redirects and embedded documents are rejected. Text and uploaded files must fit within 240 KiB; split larger sources. Uploads accept plain-text formats (.txt, .md, .csv, .json, .html and similar); convert PDF or Office files to text first."
|
|
73
110
|
}),
|
|
74
111
|
/* @__PURE__ */ s(i, {
|
|
75
|
-
disabled: !
|
|
76
|
-
isLoading:
|
|
112
|
+
disabled: !h.trim() || !_.trim(),
|
|
113
|
+
isLoading: f.queue.isPending,
|
|
77
114
|
onClick: async () => {
|
|
78
|
-
if (
|
|
79
|
-
|
|
115
|
+
if (p !== "website" && new TextEncoder().encode(_).length > u || p === "website" && _.length > 2048) {
|
|
116
|
+
b("The source is too large. Split it into smaller sources.");
|
|
80
117
|
return;
|
|
81
118
|
}
|
|
82
119
|
let e = JSON.stringify([
|
|
83
|
-
d,
|
|
84
120
|
p,
|
|
85
|
-
h
|
|
121
|
+
h,
|
|
122
|
+
_
|
|
86
123
|
]);
|
|
87
|
-
|
|
124
|
+
C.current?.fingerprint !== e && (C.current = {
|
|
88
125
|
id: crypto.randomUUID(),
|
|
89
126
|
fingerprint: e
|
|
90
127
|
});
|
|
91
128
|
try {
|
|
92
|
-
await
|
|
93
|
-
clientRequestId:
|
|
94
|
-
title:
|
|
95
|
-
...
|
|
96
|
-
}),
|
|
129
|
+
await f.queue.mutateAsync({
|
|
130
|
+
clientRequestId: C.current.id,
|
|
131
|
+
title: h,
|
|
132
|
+
...p === "website" ? { sourceUrl: _.trim() } : { content: _ }
|
|
133
|
+
}), C.current = null, v(""), S(""), w.current && (w.current.value = ""), b("Source queued. Its progress will appear below.");
|
|
97
134
|
} catch (e) {
|
|
98
|
-
|
|
135
|
+
b(n(e, "Admission could not be confirmed. Retry the same source to reuse its request ID. Check the source, embedding configuration and management permission."));
|
|
99
136
|
}
|
|
100
137
|
},
|
|
101
138
|
children: "Queue import"
|
|
102
139
|
}),
|
|
103
|
-
|
|
140
|
+
y && /* @__PURE__ */ s("p", {
|
|
104
141
|
role: "status",
|
|
105
|
-
children:
|
|
142
|
+
children: y
|
|
106
143
|
}),
|
|
107
|
-
|
|
144
|
+
f.imports.isError ? /* @__PURE__ */ s("p", {
|
|
108
145
|
role: "alert",
|
|
109
146
|
children: "Imports could not be loaded. Knowledge management permission is required."
|
|
110
|
-
}) :
|
|
147
|
+
}) : f.imports.isPending ? /* @__PURE__ */ s("p", {
|
|
111
148
|
role: "status",
|
|
112
149
|
children: "Loading imports…"
|
|
113
|
-
}) :
|
|
150
|
+
}) : f.imports.data?.map((e) => {
|
|
114
151
|
let t = r(e);
|
|
115
152
|
return /* @__PURE__ */ c("div", {
|
|
116
153
|
className: "flex items-start justify-between gap-3 text-sm",
|
|
@@ -120,7 +157,7 @@ function d({ knowledgeBaseId: t }) {
|
|
|
120
157
|
e.title,
|
|
121
158
|
" · ",
|
|
122
159
|
/* @__PURE__ */ s("span", {
|
|
123
|
-
className:
|
|
160
|
+
className: d[t.tone],
|
|
124
161
|
children: t.label
|
|
125
162
|
})
|
|
126
163
|
] }), t.detail && /* @__PURE__ */ s("span", {
|
|
@@ -130,12 +167,12 @@ function d({ knowledgeBaseId: t }) {
|
|
|
130
167
|
})]
|
|
131
168
|
}), e.status === "BLOCKED" && /* @__PURE__ */ s(i, {
|
|
132
169
|
variant: "outline",
|
|
133
|
-
isLoading:
|
|
170
|
+
isLoading: f.retry.isPending,
|
|
134
171
|
onClick: async () => {
|
|
135
172
|
try {
|
|
136
|
-
await
|
|
173
|
+
await f.retry.mutateAsync(e.id), b("Import recovery queued.");
|
|
137
174
|
} catch (e) {
|
|
138
|
-
|
|
175
|
+
b(n(e, "Recovery failed. The embedding profile must still match the original import."));
|
|
139
176
|
}
|
|
140
177
|
},
|
|
141
178
|
children: "Retry import"
|
|
@@ -144,12 +181,12 @@ function d({ knowledgeBaseId: t }) {
|
|
|
144
181
|
}),
|
|
145
182
|
/* @__PURE__ */ s(i, {
|
|
146
183
|
variant: "outline",
|
|
147
|
-
onClick: () => void
|
|
184
|
+
onClick: () => void f.imports.refetch(),
|
|
148
185
|
children: "Refresh imports"
|
|
149
186
|
})
|
|
150
187
|
]
|
|
151
188
|
});
|
|
152
189
|
}
|
|
153
|
-
export {
|
|
190
|
+
export { f as KnowledgeSourceImportPanel };
|
|
154
191
|
|
|
155
192
|
//# sourceMappingURL=KnowledgeSourceImportPanel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnowledgeSourceImportPanel.js","names":["TONE_CLASS","KnowledgeSourceImportPanel","useBotlit","ScopedImportPanel","workspaceId","currentUser","knowledgeBaseId","sources","useKnowledgeSourceImports","kind","setKind","useState","title","setTitle","value","setValue","message","setMessage","pending","useRef","event","Button","fingerprint","error","graphqlErrorMessage","status","knowledgeImportStatus","row"],"sources":["../../../src/botlit/components/KnowledgeSourceImportPanel.tsx"],"sourcesContent":["import { useRef, useState } from 'react';\nimport { useKnowledgeSourceImports } from '../hooks/useKnowledgeSourceImports';\nimport { useBotlit } from '../providers/BotlitProvider';\nimport { graphqlErrorMessage } from '../utils/errors';\nimport { knowledgeImportStatus } from '../utils/knowledgeImportStatus';\nimport { Button } from './Button';\n\nconst TONE_CLASS = {\n info: 'text-text-secondary',\n success: 'text-status-success-text',\n warning: 'text-status-warning-text',\n error: 'text-status-error-text',\n} as const;\n\nexport function KnowledgeSourceImportPanel({ knowledgeBaseId }: { knowledgeBaseId: string }) {\n const { workspaceId, currentUser } = useBotlit();\n return (\n <ScopedImportPanel\n key={`${workspaceId}:${currentUser?.id}:${knowledgeBaseId}`}\n knowledgeBaseId={knowledgeBaseId}\n />\n );\n}\nfunction ScopedImportPanel({ knowledgeBaseId }: { knowledgeBaseId: string }) {\n const sources = useKnowledgeSourceImports(knowledgeBaseId);\n const [kind, setKind] = useState('website'),\n [title, setTitle] = useState(''),\n [value, setValue] = useState(''),\n [message, setMessage] = useState('');\n const pending = useRef<{ id: string; fingerprint: string } | null>(null);\n return (\n <section className=\"space-y-4 rounded-lg border border-border-default p-5\">\n <h2 className=\"text-lg font-semibold\">Import website or text knowledge</h2>\n <p className=\"text-sm text-text-secondary\">\n Fluidgrids captures each source and checkpoints embedding batches. Course content uses the\n BuildMyIQ course import. Use a new knowledge base for the first managed import.\n </p>\n <label className=\"grid gap-2 text-sm\">\n Source type\n <select\n className=\"h-10 rounded-md border border-border-default bg-bg-surface px-3\"\n value={kind}\n disabled={sources.queue.isPending}\n onChange={(event) => {\n setKind(event.target.value);\n setValue('');\n }}\n >\n <option value=\"website\">Public website page</option>\n <option value=\"text\">Text or Markdown</option>\n </select>\n </label>\n <label className=\"grid gap-2 text-sm\">\n Title\n <input\n className=\"h-10 rounded-md border border-border-default bg-bg-surface px-3\"\n value={title}\n maxLength={255}\n disabled={sources.queue.isPending}\n onChange={(event) => setTitle(event.target.value)}\n />\n </label>\n <label className=\"grid gap-2 text-sm\">\n {kind === 'website' ? 'Exact public HTTPS page' : 'Source text'}\n <textarea\n className=\"rounded-md border border-border-default bg-bg-surface p-3\"\n rows={kind === 'website' ? 2 : 6}\n value={value}\n disabled={sources.queue.isPending}\n onChange={(event) => setValue(event.target.value)}\n />\n </label>\n <p className=\"text-sm text-text-secondary\">\n Website imports capture one static page without signing in. Cross-origin redirects and\n embedded documents are rejected. Text sources must fit within 240 KiB; split larger sources.\n </p>\n <Button\n disabled={!title.trim() || !value.trim()}\n isLoading={sources.queue.isPending}\n onClick={async () => {\n if (\n (kind === 'text' && new TextEncoder().encode(value).length > 245760) ||\n (kind === 'website' && value.length > 2048)\n ) {\n setMessage('The source is too large. Split it into smaller sources.');\n return;\n }\n const fingerprint = JSON.stringify([kind, title, value]);\n if (pending.current?.fingerprint !== fingerprint)\n pending.current = { id: crypto.randomUUID(), fingerprint };\n try {\n await sources.queue.mutateAsync({\n clientRequestId: pending.current.id,\n title,\n ...(kind === 'website' ? { sourceUrl: value.trim() } : { content: value }),\n });\n pending.current = null;\n setValue('');\n setMessage('Source queued. Its progress will appear below.');\n } catch (error) {\n setMessage(\n graphqlErrorMessage(\n error,\n 'Admission could not be confirmed. Retry the same source to reuse its request ID. Check the source, embedding configuration and management permission.'\n )\n );\n }\n }}\n >\n Queue import\n </Button>\n {message && <p role=\"status\">{message}</p>}\n {sources.imports.isError ? (\n <p role=\"alert\">\n Imports could not be loaded. Knowledge management permission is required.\n </p>\n ) : sources.imports.isPending ? (\n <p role=\"status\">Loading imports…</p>\n ) : (\n sources.imports.data?.map((row) => {\n const status = knowledgeImportStatus(row);\n return (\n <div key={row.id} className=\"flex items-start justify-between gap-3 text-sm\">\n <div className=\"grid gap-1\">\n <span>\n {row.title} · <span className={TONE_CLASS[status.tone]}>{status.label}</span>\n </span>\n {status.detail && (\n <span\n role={\n status.tone === 'error' || status.tone === 'warning' ? 'alert' : undefined\n }\n className=\"text-text-secondary\"\n >\n {status.detail}\n </span>\n )}\n </div>\n {row.status === 'BLOCKED' && (\n <Button\n variant=\"outline\"\n isLoading={sources.retry.isPending}\n onClick={async () => {\n try {\n await sources.retry.mutateAsync(row.id);\n setMessage('Import recovery queued.');\n } catch (error) {\n setMessage(\n graphqlErrorMessage(\n error,\n 'Recovery failed. The embedding profile must still match the original import.'\n )\n );\n }\n }}\n >\n Retry import\n </Button>\n )}\n </div>\n );\n })\n )}\n <Button variant=\"outline\" onClick={() => void sources.imports.refetch()}>\n Refresh imports\n </Button>\n </section>\n );\n}\n"],"mappings":";;;;;;;;AAOA,IAAMA,IAAa;CACjB,MAAM;CACN,SAAS;CACT,SAAS;CACT,OAAO;AACT;AAEA,SAAgBC,EAA2B,EAAE,sBAAgD;CAC3F,IAAM,EAAE,gBAAa,mBAAgBC,EAAU;CAC/C,OACE,kBAACC,GAAD,EAEmB,mBAClB,GAFM,GAAGC,EAAY,GAAGC,GAAa,GAAG,GAAGC,GAE3C;AAEL;AACA,SAASH,EAAkB,EAAE,sBAAgD;CAC3E,IAAMI,IAAUC,EAA0BF,CAAe,GACnD,CAACG,GAAMC,KAAWC,EAAS,SAAS,GACxC,CAACC,GAAOC,KAAYF,EAAS,EAAE,GAC/B,CAACG,GAAOC,KAAYJ,EAAS,EAAE,GAC/B,CAACK,GAASC,KAAcN,EAAS,EAAE,GAC/BO,IAAUC,EAAmD,IAAI;CACvE,OACE,kBAAC,WAAD;EAAS,WAAU;EAAnB,UAAA;GACE,kBAAC,MAAD;IAAI,WAAU;IAAwB,UAAA;GAAoC,CAAA;GAC1E,kBAAC,KAAD;IAAG,WAAU;IAA8B,UAAA;GAGxC,CAAA;GACH,kBAAC,SAAD;IAAO,WAAU;IAAjB,UAAA,CAAsC,eAEpC,kBAAC,UAAD;KACE,WAAU;KACV,OAAOV;KACP,UAAUF,EAAQ,MAAM;KACxB,WAAW,MAA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AAKd,EAAQ,QAAQ,QAAQ;IAAG,UAAA;GAEjE,CAAA;EACD;;AAEb"}
|
|
1
|
+
{"version":3,"file":"KnowledgeSourceImportPanel.js","names":["TEXT_FILE_TYPES","TEXT_SOURCE_LIMIT_BYTES","TONE_CLASS","KnowledgeSourceImportPanel","useBotlit","ScopedImportPanel","workspaceId","currentUser","knowledgeBaseId","sources","useKnowledgeSourceImports","kind","setKind","useState","title","setTitle","value","setValue","message","setMessage","fileName","setFileName","pending","useRef","fileInput","readFile","file","text","event","Button","fingerprint","error","graphqlErrorMessage","status","knowledgeImportStatus","row"],"sources":["../../../src/botlit/components/KnowledgeSourceImportPanel.tsx"],"sourcesContent":["import { useRef, useState } from 'react';\nimport { useKnowledgeSourceImports } from '../hooks/useKnowledgeSourceImports';\nimport { useBotlit } from '../providers/BotlitProvider';\nimport { graphqlErrorMessage } from '../utils/errors';\nimport { knowledgeImportStatus } from '../utils/knowledgeImportStatus';\nimport { Button } from './Button';\n\n/** Text formats a browser can read as-is. Binary formats (PDF, Office) need server extraction, which general knowledge bases do not have. */\nconst TEXT_FILE_TYPES = '.txt,.md,.markdown,.csv,.tsv,.json,.html,.htm,.xml,.yaml,.yml,.log';\nconst TEXT_SOURCE_LIMIT_BYTES = 245760;\n\nconst TONE_CLASS = {\n info: 'text-text-secondary',\n success: 'text-status-success-text',\n warning: 'text-status-warning-text',\n error: 'text-status-error-text',\n} as const;\n\nexport function KnowledgeSourceImportPanel({ knowledgeBaseId }: { knowledgeBaseId: string }) {\n const { workspaceId, currentUser } = useBotlit();\n return (\n <ScopedImportPanel\n key={`${workspaceId}:${currentUser?.id}:${knowledgeBaseId}`}\n knowledgeBaseId={knowledgeBaseId}\n />\n );\n}\nfunction ScopedImportPanel({ knowledgeBaseId }: { knowledgeBaseId: string }) {\n const sources = useKnowledgeSourceImports(knowledgeBaseId);\n const [kind, setKind] = useState('website'),\n [title, setTitle] = useState(''),\n [value, setValue] = useState(''),\n [message, setMessage] = useState(''),\n [fileName, setFileName] = useState('');\n const pending = useRef<{ id: string; fingerprint: string } | null>(null);\n const fileInput = useRef<HTMLInputElement>(null);\n const readFile = async (file: File | undefined) => {\n setValue('');\n setFileName('');\n if (!file) return;\n if (file.size > TEXT_SOURCE_LIMIT_BYTES) {\n setMessage(`${file.name} is larger than 240 KiB. Split it into smaller files.`);\n return;\n }\n const text = await file.text();\n if (!text.trim() || text.includes('\\0')) {\n setMessage(\n `${file.name} has no readable text. Upload a plain-text file such as .txt, .md or .csv.`\n );\n return;\n }\n setValue(text);\n setFileName(file.name);\n if (!title.trim()) setTitle(file.name);\n setMessage('');\n };\n return (\n <section className=\"space-y-4 rounded-lg border border-border-default p-5\">\n <h2 className=\"text-lg font-semibold\">Add knowledge</h2>\n <p className=\"text-sm text-text-secondary\">\n Upload a text file, paste text or import a public web page. BotManor captures each source in\n the background, splits it into chunks and embeds them; progress appears below. Course\n content uses the BuildMyIQ course import.\n </p>\n <label className=\"grid gap-2 text-sm\">\n Source type\n <select\n className=\"h-10 rounded-md border border-border-default bg-bg-surface px-3\"\n value={kind}\n disabled={sources.queue.isPending}\n onChange={(event) => {\n setKind(event.target.value);\n setValue('');\n setFileName('');\n }}\n >\n <option value=\"website\">Public website page</option>\n <option value=\"text\">Text or Markdown</option>\n <option value=\"file\">Upload a text file</option>\n </select>\n </label>\n <label className=\"grid gap-2 text-sm\">\n Title\n <input\n className=\"h-10 rounded-md border border-border-default bg-bg-surface px-3\"\n value={title}\n maxLength={255}\n disabled={sources.queue.isPending}\n onChange={(event) => setTitle(event.target.value)}\n />\n </label>\n {kind === 'file' ? (\n <label className=\"grid gap-2 text-sm\">\n Document\n <input\n ref={fileInput}\n type=\"file\"\n accept={TEXT_FILE_TYPES}\n className=\"text-sm\"\n disabled={sources.queue.isPending}\n onChange={(event) => void readFile(event.target.files?.[0])}\n />\n {fileName && (\n <span className=\"text-text-secondary\">\n {fileName} · {new TextEncoder().encode(value).length.toLocaleString()} bytes ready\n </span>\n )}\n </label>\n ) : (\n <label className=\"grid gap-2 text-sm\">\n {kind === 'website' ? 'Exact public HTTPS page' : 'Source text'}\n <textarea\n className=\"rounded-md border border-border-default bg-bg-surface p-3\"\n rows={kind === 'website' ? 2 : 6}\n value={value}\n disabled={sources.queue.isPending}\n onChange={(event) => setValue(event.target.value)}\n />\n </label>\n )}\n <p className=\"text-sm text-text-secondary\">\n Website imports capture one static page without signing in. Cross-origin redirects and\n embedded documents are rejected. Text and uploaded files must fit within 240 KiB; split\n larger sources. Uploads accept plain-text formats (.txt, .md, .csv, .json, .html and\n similar); convert PDF or Office files to text first.\n </p>\n <Button\n disabled={!title.trim() || !value.trim()}\n isLoading={sources.queue.isPending}\n onClick={async () => {\n if (\n (kind !== 'website' &&\n new TextEncoder().encode(value).length > TEXT_SOURCE_LIMIT_BYTES) ||\n (kind === 'website' && value.length > 2048)\n ) {\n setMessage('The source is too large. Split it into smaller sources.');\n return;\n }\n const fingerprint = JSON.stringify([kind, title, value]);\n if (pending.current?.fingerprint !== fingerprint)\n pending.current = { id: crypto.randomUUID(), fingerprint };\n try {\n await sources.queue.mutateAsync({\n clientRequestId: pending.current.id,\n title,\n ...(kind === 'website' ? { sourceUrl: value.trim() } : { content: value }),\n });\n pending.current = null;\n setValue('');\n setFileName('');\n if (fileInput.current) fileInput.current.value = '';\n setMessage('Source queued. Its progress will appear below.');\n } catch (error) {\n setMessage(\n graphqlErrorMessage(\n error,\n 'Admission could not be confirmed. Retry the same source to reuse its request ID. Check the source, embedding configuration and management permission.'\n )\n );\n }\n }}\n >\n Queue import\n </Button>\n {message && <p role=\"status\">{message}</p>}\n {sources.imports.isError ? (\n <p role=\"alert\">\n Imports could not be loaded. Knowledge management permission is required.\n </p>\n ) : sources.imports.isPending ? (\n <p role=\"status\">Loading imports…</p>\n ) : (\n sources.imports.data?.map((row) => {\n const status = knowledgeImportStatus(row);\n return (\n <div key={row.id} className=\"flex items-start justify-between gap-3 text-sm\">\n <div className=\"grid gap-1\">\n <span>\n {row.title} · <span className={TONE_CLASS[status.tone]}>{status.label}</span>\n </span>\n {status.detail && (\n <span\n role={\n status.tone === 'error' || status.tone === 'warning' ? 'alert' : undefined\n }\n className=\"text-text-secondary\"\n >\n {status.detail}\n </span>\n )}\n </div>\n {row.status === 'BLOCKED' && (\n <Button\n variant=\"outline\"\n isLoading={sources.retry.isPending}\n onClick={async () => {\n try {\n await sources.retry.mutateAsync(row.id);\n setMessage('Import recovery queued.');\n } catch (error) {\n setMessage(\n graphqlErrorMessage(\n error,\n 'Recovery failed. The embedding profile must still match the original import.'\n )\n );\n }\n }}\n >\n Retry import\n </Button>\n )}\n </div>\n );\n })\n )}\n <Button variant=\"outline\" onClick={() => void sources.imports.refetch()}>\n Refresh imports\n </Button>\n </section>\n );\n}\n"],"mappings":";;;;;;;;AAQA,IAAMA,IAAkB,sEAClBC,IAA0B,QAE1BC,IAAa;CACjB,MAAM;CACN,SAAS;CACT,SAAS;CACT,OAAO;AACT;AAEA,SAAgBC,EAA2B,EAAE,sBAAgD;CAC3F,IAAM,EAAE,gBAAa,mBAAgBC,EAAU;CAC/C,OACE,kBAACC,GAAD,EAEmB,mBAClB,GAFM,GAAGC,EAAY,GAAGC,GAAa,GAAG,GAAGC,GAE3C;AAEL;AACA,SAASH,EAAkB,EAAE,sBAAgD;CAC3E,IAAMI,IAAUC,EAA0BF,CAAe,GACnD,CAACG,GAAMC,KAAWC,EAAS,SAAS,GACxC,CAACC,GAAOC,KAAYF,EAAS,EAAE,GAC/B,CAACG,GAAOC,KAAYJ,EAAS,EAAE,GAC/B,CAACK,GAASC,KAAcN,EAAS,EAAE,GACnC,CAACO,GAAUC,KAAeR,EAAS,EAAE,GACjCS,IAAUC,EAAmD,IAAI,GACjEC,IAAYD,EAAyB,IAAI,GACzCE,IAAW,OAAO,MAA2B;EAGjD,IAFAR,EAAS,EAAE,GACXI,EAAY,EAAE,GACV,CAACK,GAAM;EACX,IAAIA,EAAK,OAAOzB,GAAyB;GACvC,EAAW,GAAGyB,EAAK,KAAK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" (BOFF-15360, BL-UC-21)
|
|
3
|
+
* @module botlit/hooks
|
|
4
|
+
*
|
|
5
|
+
* `draftBotFromDescription` turns one sentence into a reviewable plan and
|
|
6
|
+
* writes nothing; it is metered as AI credits. `createBotFromDraft` /
|
|
7
|
+
* `createAgentsFromDraft` create only what the person accepted, as DRAFT
|
|
8
|
+
* entities, in one transaction. Drafting is cancellable: the request is
|
|
9
|
+
* aborted and its answer discarded.
|
|
10
|
+
*/
|
|
11
|
+
export type BotDraftScope = 'BOT' | 'AGENTS';
|
|
12
|
+
export type DraftAgentType = 'ASSISTANT' | 'AUTOMATION' | 'ANALYST' | 'SPECIALIST';
|
|
13
|
+
export type DraftRoutingStrategy = 'SINGLE' | 'ROUND_ROBIN' | 'INTELLIGENT';
|
|
14
|
+
export interface BotDraftApp {
|
|
15
|
+
name: string;
|
|
16
|
+
description: string | null;
|
|
17
|
+
type: DraftAgentType;
|
|
18
|
+
routingStrategy: DraftRoutingStrategy;
|
|
19
|
+
welcomeMessage: string | null;
|
|
20
|
+
fallbackMessage: string | null;
|
|
21
|
+
}
|
|
22
|
+
export interface BotDraftAgent {
|
|
23
|
+
key: string;
|
|
24
|
+
name: string;
|
|
25
|
+
description: string | null;
|
|
26
|
+
type: DraftAgentType;
|
|
27
|
+
systemPrompt: string;
|
|
28
|
+
temperature: number | null;
|
|
29
|
+
knowledgeBaseIds: string[];
|
|
30
|
+
templateId: string | null;
|
|
31
|
+
}
|
|
32
|
+
export interface BotDraftLink {
|
|
33
|
+
agentKey: string;
|
|
34
|
+
priority: number;
|
|
35
|
+
isDefault: boolean;
|
|
36
|
+
intentPatterns: string[];
|
|
37
|
+
triggerKeywords: string[];
|
|
38
|
+
fallbackAgentKey: string | null;
|
|
39
|
+
}
|
|
40
|
+
export interface BotDraftKnowledgeBase {
|
|
41
|
+
knowledgeBaseId: string;
|
|
42
|
+
name: string;
|
|
43
|
+
reason: string;
|
|
44
|
+
agentKeys: string[];
|
|
45
|
+
}
|
|
46
|
+
export interface BotDraft {
|
|
47
|
+
draftId: string;
|
|
48
|
+
scope: BotDraftScope;
|
|
49
|
+
description: string;
|
|
50
|
+
llmModelId: string;
|
|
51
|
+
model: string;
|
|
52
|
+
template: {
|
|
53
|
+
id: string;
|
|
54
|
+
name: string;
|
|
55
|
+
kind: string;
|
|
56
|
+
} | null;
|
|
57
|
+
app: BotDraftApp | null;
|
|
58
|
+
agents: BotDraftAgent[];
|
|
59
|
+
links: BotDraftLink[];
|
|
60
|
+
knowledgeBases: BotDraftKnowledgeBase[];
|
|
61
|
+
notes: string | null;
|
|
62
|
+
inputTokens: number;
|
|
63
|
+
outputTokens: number;
|
|
64
|
+
aiCredits: number | null;
|
|
65
|
+
}
|
|
66
|
+
export interface CreatedDraft {
|
|
67
|
+
app: {
|
|
68
|
+
id: string;
|
|
69
|
+
name: string;
|
|
70
|
+
} | null;
|
|
71
|
+
agents: Array<{
|
|
72
|
+
id: string;
|
|
73
|
+
name: string;
|
|
74
|
+
}>;
|
|
75
|
+
}
|
|
76
|
+
export interface DraftRequest {
|
|
77
|
+
description: string;
|
|
78
|
+
llmModelId: string;
|
|
79
|
+
scope: BotDraftScope;
|
|
80
|
+
}
|
|
81
|
+
/** Draft from a sentence. `cancel` aborts the request; nothing was written, so nothing is left behind. */
|
|
82
|
+
export declare function useDraftBot(): {
|
|
83
|
+
readonly draft: (request: DraftRequest) => Promise<BotDraft | null>;
|
|
84
|
+
readonly cancel: () => void;
|
|
85
|
+
readonly loading: boolean;
|
|
86
|
+
readonly workspaceId: string | undefined;
|
|
87
|
+
};
|
|
88
|
+
export interface CreateFromDraftInput {
|
|
89
|
+
draft: BotDraft;
|
|
90
|
+
app: BotDraftApp | null;
|
|
91
|
+
agents: BotDraftAgent[];
|
|
92
|
+
links: BotDraftLink[];
|
|
93
|
+
}
|
|
94
|
+
/** Create the reviewed draft as DRAFT entities. */
|
|
95
|
+
export declare function useCreateFromDraft(scope: BotDraftScope): readonly [(input: CreateFromDraftInput) => Promise<CreatedDraft>, import('./internal/workspaceGateway').MutationState<CreatedDraft>];
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { useWorkspaceClient as e, useWorkspaceId as t, useWorkspaceMutation as n } from "./internal/workspaceGateway.js";
|
|
2
|
+
import { useCallback as r, useEffect as i, useRef as a, useState as o } from "react";
|
|
3
|
+
import { gql as s } from "@apollo/client";
|
|
4
|
+
// src/botlit/hooks/useBotCopilot.ts
|
|
5
|
+
var c = s`
|
|
6
|
+
mutation draftBotFromDescription($input: DraftBotFromDescriptionInput!) {
|
|
7
|
+
draftBotFromDescription(input: $input) {
|
|
8
|
+
draftId
|
|
9
|
+
scope
|
|
10
|
+
description
|
|
11
|
+
llmModelId
|
|
12
|
+
model
|
|
13
|
+
template {
|
|
14
|
+
id
|
|
15
|
+
name
|
|
16
|
+
kind
|
|
17
|
+
}
|
|
18
|
+
app {
|
|
19
|
+
name
|
|
20
|
+
description
|
|
21
|
+
type
|
|
22
|
+
routingStrategy
|
|
23
|
+
welcomeMessage
|
|
24
|
+
fallbackMessage
|
|
25
|
+
}
|
|
26
|
+
agents {
|
|
27
|
+
key
|
|
28
|
+
name
|
|
29
|
+
description
|
|
30
|
+
type
|
|
31
|
+
systemPrompt
|
|
32
|
+
temperature
|
|
33
|
+
knowledgeBaseIds
|
|
34
|
+
templateId
|
|
35
|
+
}
|
|
36
|
+
links {
|
|
37
|
+
agentKey
|
|
38
|
+
priority
|
|
39
|
+
isDefault
|
|
40
|
+
intentPatterns
|
|
41
|
+
triggerKeywords
|
|
42
|
+
fallbackAgentKey
|
|
43
|
+
}
|
|
44
|
+
knowledgeBases {
|
|
45
|
+
knowledgeBaseId
|
|
46
|
+
name
|
|
47
|
+
reason
|
|
48
|
+
agentKeys
|
|
49
|
+
}
|
|
50
|
+
notes
|
|
51
|
+
inputTokens
|
|
52
|
+
outputTokens
|
|
53
|
+
aiCredits
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
`, l = s`
|
|
57
|
+
mutation createBotFromDraft($input: CreateBotFromDraftInput!) {
|
|
58
|
+
createBotFromDraft(input: $input) {
|
|
59
|
+
app {
|
|
60
|
+
id
|
|
61
|
+
name
|
|
62
|
+
}
|
|
63
|
+
agents {
|
|
64
|
+
id
|
|
65
|
+
name
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
`, u = s`
|
|
70
|
+
mutation createAgentsFromDraft($input: CreateAgentsFromDraftInput!) {
|
|
71
|
+
createAgentsFromDraft(input: $input) {
|
|
72
|
+
app {
|
|
73
|
+
id
|
|
74
|
+
name
|
|
75
|
+
}
|
|
76
|
+
agents {
|
|
77
|
+
id
|
|
78
|
+
name
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
`;
|
|
83
|
+
function d(e, t) {
|
|
84
|
+
return e instanceof Error ? e : Error(t);
|
|
85
|
+
}
|
|
86
|
+
function f() {
|
|
87
|
+
let n = e(), s = t(), l = a(null), [u, f] = o(!1), p = r(() => {
|
|
88
|
+
l.current?.abort(), l.current = null, f(!1);
|
|
89
|
+
}, []);
|
|
90
|
+
return i(() => p, [p, s]), {
|
|
91
|
+
draft: r(async (e) => {
|
|
92
|
+
l.current?.abort();
|
|
93
|
+
let t = new AbortController();
|
|
94
|
+
l.current = t, f(!0);
|
|
95
|
+
try {
|
|
96
|
+
let r = await n.mutate({
|
|
97
|
+
mutation: c,
|
|
98
|
+
variables: { input: {
|
|
99
|
+
...e,
|
|
100
|
+
workspaceId: s
|
|
101
|
+
} },
|
|
102
|
+
context: { fetchOptions: { signal: t.signal } }
|
|
103
|
+
});
|
|
104
|
+
if (t.signal.aborted) return null;
|
|
105
|
+
let i = r.error;
|
|
106
|
+
if (i != null) throw d(i, "Failed to draft the bot");
|
|
107
|
+
let a = r.data?.draftBotFromDescription;
|
|
108
|
+
if (!a) throw Error("Failed to draft the bot");
|
|
109
|
+
return a;
|
|
110
|
+
} catch (e) {
|
|
111
|
+
if (t.signal.aborted) return null;
|
|
112
|
+
throw d(e, "Failed to draft the bot");
|
|
113
|
+
} finally {
|
|
114
|
+
l.current === t && (l.current = null, f(!1));
|
|
115
|
+
}
|
|
116
|
+
}, [n, s]),
|
|
117
|
+
cancel: p,
|
|
118
|
+
loading: u,
|
|
119
|
+
workspaceId: s
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
var p = (e) => ({
|
|
123
|
+
key: e.key,
|
|
124
|
+
name: e.name.trim(),
|
|
125
|
+
description: e.description?.trim() || null,
|
|
126
|
+
type: e.type,
|
|
127
|
+
systemPrompt: e.systemPrompt.trim(),
|
|
128
|
+
temperature: e.temperature,
|
|
129
|
+
knowledgeBaseIds: e.knowledgeBaseIds,
|
|
130
|
+
templateId: e.templateId
|
|
131
|
+
});
|
|
132
|
+
function m(e) {
|
|
133
|
+
let r = t();
|
|
134
|
+
return n({
|
|
135
|
+
document: e === "BOT" ? l : u,
|
|
136
|
+
variables: ({ draft: t, app: n, agents: i, links: a }) => {
|
|
137
|
+
let o = {
|
|
138
|
+
workspaceId: r,
|
|
139
|
+
draftId: t.draftId,
|
|
140
|
+
description: t.description,
|
|
141
|
+
llmModelId: t.llmModelId,
|
|
142
|
+
templateId: t.template?.id ?? null,
|
|
143
|
+
agents: i.map(p)
|
|
144
|
+
};
|
|
145
|
+
return { input: e === "BOT" && n ? {
|
|
146
|
+
...o,
|
|
147
|
+
app: {
|
|
148
|
+
name: n.name.trim(),
|
|
149
|
+
description: n.description?.trim() || null,
|
|
150
|
+
type: n.type,
|
|
151
|
+
routingStrategy: i.length > 1 ? n.routingStrategy : "SINGLE",
|
|
152
|
+
welcomeMessage: n.welcomeMessage?.trim() || null,
|
|
153
|
+
fallbackMessage: n.fallbackMessage?.trim() || null
|
|
154
|
+
},
|
|
155
|
+
links: a.filter((e) => i.some((t) => t.key === e.agentKey)).map((e) => ({
|
|
156
|
+
...e,
|
|
157
|
+
fallbackAgentKey: e.fallbackAgentKey && i.some((t) => t.key === e.fallbackAgentKey) ? e.fallbackAgentKey : null
|
|
158
|
+
}))
|
|
159
|
+
} : o };
|
|
160
|
+
},
|
|
161
|
+
select: (t) => (e === "BOT" ? t?.createBotFromDraft : t?.createAgentsFromDraft) ?? void 0,
|
|
162
|
+
errorMessage: e === "BOT" ? "Failed to create the draft bot" : "Failed to create the draft agents"
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
export { m as useCreateFromDraft, f as useDraftBot };
|
|
166
|
+
|
|
167
|
+
//# sourceMappingURL=useBotCopilot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBotCopilot.js","names":["DRAFT_DOCUMENT","CREATE_BOT_DOCUMENT","CREATE_AGENTS_DOCUMENT","errorOf","value","fallback","useDraftBot","client","useWorkspaceClient","workspaceId","useWorkspaceId","controller","useRef","loading","setLoading","useState","cancel","useCallback","useEffect","current","result","request","operationError","data","error","agentInput","agent","useCreateFromDraft","useWorkspaceMutation","scope","base","draft","agents","app","links","link"],"sources":["../../../src/botlit/hooks/useBotCopilot.ts"],"sourcesContent":["/**\n * Copilot \"Describe your bot\" (BOFF-15360, BL-UC-21)\n * @module botlit/hooks\n *\n * `draftBotFromDescription` turns one sentence into a reviewable plan and\n * writes nothing; it is metered as AI credits. `createBotFromDraft` /\n * `createAgentsFromDraft` create only what the person accepted, as DRAFT\n * entities, in one transaction. Drafting is cancellable: the request is\n * aborted and its answer discarded.\n */\n\nimport { gql } from '@apollo/client';\nimport { useCallback, useEffect, useRef, useState } from 'react';\n\nimport {\n useWorkspaceClient,\n useWorkspaceId,\n useWorkspaceMutation,\n} from './internal/workspaceGateway';\n\nexport type BotDraftScope = 'BOT' | 'AGENTS';\nexport type DraftAgentType = 'ASSISTANT' | 'AUTOMATION' | 'ANALYST' | 'SPECIALIST';\nexport type DraftRoutingStrategy = 'SINGLE' | 'ROUND_ROBIN' | 'INTELLIGENT';\n\nexport interface BotDraftApp {\n name: string;\n description: string | null;\n type: DraftAgentType;\n routingStrategy: DraftRoutingStrategy;\n welcomeMessage: string | null;\n fallbackMessage: string | null;\n}\n\nexport interface BotDraftAgent {\n key: string;\n name: string;\n description: string | null;\n type: DraftAgentType;\n systemPrompt: string;\n temperature: number | null;\n knowledgeBaseIds: string[];\n templateId: string | null;\n}\n\nexport interface BotDraftLink {\n agentKey: string;\n priority: number;\n isDefault: boolean;\n intentPatterns: string[];\n triggerKeywords: string[];\n fallbackAgentKey: string | null;\n}\n\nexport interface BotDraftKnowledgeBase {\n knowledgeBaseId: string;\n name: string;\n reason: string;\n agentKeys: string[];\n}\n\nexport interface BotDraft {\n draftId: string;\n scope: BotDraftScope;\n description: string;\n llmModelId: string;\n model: string;\n template: { id: string; name: string; kind: string } | null;\n app: BotDraftApp | null;\n agents: BotDraftAgent[];\n links: BotDraftLink[];\n knowledgeBases: BotDraftKnowledgeBase[];\n notes: string | null;\n inputTokens: number;\n outputTokens: number;\n aiCredits: number | null;\n}\n\nexport interface CreatedDraft {\n app: { id: string; name: string } | null;\n agents: Array<{ id: string; name: string }>;\n}\n\nconst DRAFT_DOCUMENT = gql`\n mutation draftBotFromDescription($input: DraftBotFromDescriptionInput!) {\n draftBotFromDescription(input: $input) {\n draftId\n scope\n description\n llmModelId\n model\n template {\n id\n name\n kind\n }\n app {\n name\n description\n type\n routingStrategy\n welcomeMessage\n fallbackMessage\n }\n agents {\n key\n name\n description\n type\n systemPrompt\n temperature\n knowledgeBaseIds\n templateId\n }\n links {\n agentKey\n priority\n isDefault\n intentPatterns\n triggerKeywords\n fallbackAgentKey\n }\n knowledgeBases {\n knowledgeBaseId\n name\n reason\n agentKeys\n }\n notes\n inputTokens\n outputTokens\n aiCredits\n }\n }\n`;\n\nconst CREATE_BOT_DOCUMENT = gql`\n mutation createBotFromDraft($input: CreateBotFromDraftInput!) {\n createBotFromDraft(input: $input) {\n app {\n id\n name\n }\n agents {\n id\n name\n }\n }\n }\n`;\n\nconst CREATE_AGENTS_DOCUMENT = gql`\n mutation createAgentsFromDraft($input: CreateAgentsFromDraftInput!) {\n createAgentsFromDraft(input: $input) {\n app {\n id\n name\n }\n agents {\n id\n name\n }\n }\n }\n`;\n\nexport interface DraftRequest {\n description: string;\n llmModelId: string;\n scope: BotDraftScope;\n}\n\nfunction errorOf(value: unknown, fallback: string): Error {\n if (value instanceof Error) return value;\n return new Error(fallback);\n}\n\n/** Draft from a sentence. `cancel` aborts the request; nothing was written, so nothing is left behind. */\nexport function useDraftBot() {\n const client = useWorkspaceClient();\n const workspaceId = useWorkspaceId();\n const controller = useRef<AbortController | null>(null);\n const [loading, setLoading] = useState(false);\n\n const cancel = useCallback(() => {\n controller.current?.abort();\n controller.current = null;\n setLoading(false);\n }, []);\n\n // A draft belongs to the workspace it was asked in: switching workspace (or\n // unmounting) abandons an in-flight draft instead of letting it land later.\n useEffect(() => cancel, [cancel, workspaceId]);\n\n const draft = useCallback(\n async (request: DraftRequest): Promise<BotDraft | null> => {\n controller.current?.abort();\n const current = new AbortController();\n controller.current = current;\n setLoading(true);\n try {\n const result = await client.mutate<{ draftBotFromDescription?: BotDraft | null }>({\n mutation: DRAFT_DOCUMENT,\n variables: { input: { ...request, workspaceId } },\n context: { fetchOptions: { signal: current.signal } },\n });\n if (current.signal.aborted) return null;\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) throw errorOf(operationError, 'Failed to draft the bot');\n const data = result.data?.draftBotFromDescription;\n if (!data) throw new Error('Failed to draft the bot');\n return data;\n } catch (error: unknown) {\n if (current.signal.aborted) return null;\n throw errorOf(error, 'Failed to draft the bot');\n } finally {\n if (controller.current === current) {\n controller.current = null;\n setLoading(false);\n }\n }\n },\n [client, workspaceId]\n );\n\n return { draft, cancel, loading, workspaceId } as const;\n}\n\nexport interface CreateFromDraftInput {\n draft: BotDraft;\n app: BotDraftApp | null;\n agents: BotDraftAgent[];\n links: BotDraftLink[];\n}\n\nconst agentInput = (agent: BotDraftAgent) => ({\n key: agent.key,\n name: agent.name.trim(),\n description: agent.description?.trim() || null,\n type: agent.type,\n systemPrompt: agent.systemPrompt.trim(),\n temperature: agent.temperature,\n knowledgeBaseIds: agent.knowledgeBaseIds,\n templateId: agent.templateId,\n});\n\n/** Create the reviewed draft as DRAFT entities. */\nexport function useCreateFromDraft(scope: BotDraftScope) {\n const workspaceId = useWorkspaceId();\n return useWorkspaceMutation<\n {\n createBotFromDraft?: CreatedDraft | null;\n createAgentsFromDraft?: CreatedDraft | null;\n },\n CreateFromDraftInput,\n CreatedDraft\n >({\n document: scope === 'BOT' ? CREATE_BOT_DOCUMENT : CREATE_AGENTS_DOCUMENT,\n variables: ({ draft, app, agents, links }) => {\n const base = {\n workspaceId,\n draftId: draft.draftId,\n description: draft.description,\n llmModelId: draft.llmModelId,\n templateId: draft.template?.id ?? null,\n agents: agents.map(agentInput),\n };\n return {\n input:\n scope === 'BOT' && app\n ? {\n ...base,\n app: {\n name: app.name.trim(),\n description: app.description?.trim() || null,\n type: app.type,\n routingStrategy: agents.length > 1 ? app.routingStrategy : 'SINGLE',\n welcomeMessage: app.welcomeMessage?.trim() || null,\n fallbackMessage: app.fallbackMessage?.trim() || null,\n },\n links: links\n .filter((link) => agents.some((agent) => agent.key === link.agentKey))\n .map((link) => ({\n ...link,\n fallbackAgentKey:\n link.fallbackAgentKey &&\n agents.some((agent) => agent.key === link.fallbackAgentKey)\n ? link.fallbackAgentKey\n : null,\n })),\n }\n : base,\n };\n },\n select: (data) =>\n (scope === 'BOT' ? data?.createBotFromDraft : data?.createAgentsFromDraft) ?? undefined,\n errorMessage:\n scope === 'BOT' ? 'Failed to create the draft bot' : 'Failed to create the draft agents',\n });\n}\n"],"mappings":";;;;AAkFA,IAAMA,IAAiB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDpBC,IAAsB,CAAG;;;;;;;;;;;;;GAezBC,IAAyB,CAAG;;;;;;;;;;;;;;AAqBlC,SAASC,EAAQ,GAAgB,GAAyB;CAExD,OADIC,aAAiB,QAAcA,IACxB,MAAMC,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