@burdenoff/microfe-botmanor 2026.1119.3 → 2026.1119.4
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/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/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { BotDraftScope, CreatedDraft } from '../hooks/useBotCopilot';
|
|
3
|
+
interface DescribeBotDialogProps {
|
|
4
|
+
scope: BotDraftScope;
|
|
5
|
+
/** Receives what was created (every entity is DRAFT). */
|
|
6
|
+
onCreated: (created: CreatedDraft) => void;
|
|
7
|
+
/** Called instead of an inline message when the plan's bot limit is reached. */
|
|
8
|
+
onQuotaExhausted?: () => void;
|
|
9
|
+
}
|
|
10
|
+
export declare const DescribeBotDialog: FC<DescribeBotDialogProps>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { Badge as e } from "./Badge.js";
|
|
2
|
+
import { Button as t } from "./Button.js";
|
|
3
|
+
import { Card as n, CardContent as r, CardDescription as ee, CardHeader as te, CardTitle as i } from "./Card.js";
|
|
4
|
+
import { FormField as a, Input as o, Textarea as s } from "./Input.js";
|
|
5
|
+
import { useCreateFromDraft as c, useDraftBot as l } from "../hooks/useBotCopilot.js";
|
|
6
|
+
import { useLLMModels as ne, useLLMProviders as re } from "../hooks/useLLMProviders.js";
|
|
7
|
+
import { configuredAnswerModels as ie } from "../utils/embedding-models.js";
|
|
8
|
+
import "../utils/agentSettings.js";
|
|
9
|
+
import { useEffect as u, useMemo as d, useState as f } from "react";
|
|
10
|
+
import { ResponsiveDialog as p, ResponsiveDialogContent as m, ResponsiveDialogDescription as h, ResponsiveDialogFooter as g, ResponsiveDialogHeader as ae, ResponsiveDialogTitle as oe } from "@burdenoff/fe-libs/ui";
|
|
11
|
+
import { Fragment as _, jsx as v, jsxs as y } from "react/jsx-runtime";
|
|
12
|
+
import { isQuotaExhaustedError as b } from "@burdenoff/fe-libs/shared/utils";
|
|
13
|
+
import { Sparkles as x, WandSparkles as se } from "lucide-react";
|
|
14
|
+
import { toast as ce } from "sonner";
|
|
15
|
+
// src/botlit/components/DescribeBotDialog.tsx
|
|
16
|
+
var S = 10, C = 1e3, le = "flex h-10 w-full rounded-md border border-border-default bg-bg-surface px-3 py-2 text-sm";
|
|
17
|
+
function w(e) {
|
|
18
|
+
return {
|
|
19
|
+
app: e.app ? { ...e.app } : null,
|
|
20
|
+
agents: e.agents.map((e) => ({
|
|
21
|
+
...e,
|
|
22
|
+
include: !0
|
|
23
|
+
}))
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function T(e, t) {
|
|
27
|
+
return e instanceof Error && e.message ? e.message : t;
|
|
28
|
+
}
|
|
29
|
+
var E = ({ scope: E, onCreated: ue, onQuotaExhausted: D }) => {
|
|
30
|
+
let O = E === "BOT" ? "bot" : "agent", [de, k] = f(!1), [A, fe] = f(""), [j, M] = f(""), [N, P] = f(null), [F, I] = f(null), [L, R] = f(null), z = ne(), B = re(), V = d(() => ie(z.data ?? [], B.data ?? []), [z.data, B.data]), H = V.some((e) => e.id === j) ? j : V[0]?.id || "", U = l(), [pe, W] = c(E), G = A.trim(), K = G.length > 0 && G.length < S ? `Write at least ${S} characters.` : G.length > C ? `Use at most ${C} characters.` : void 0, q = F?.agents.filter((e) => e.include) ?? [], J = () => {
|
|
31
|
+
U.cancel(), P(null), I(null), R(null);
|
|
32
|
+
};
|
|
33
|
+
u(() => {
|
|
34
|
+
M(""), P(null), I(null), R(null);
|
|
35
|
+
}, [U.workspaceId]);
|
|
36
|
+
let Y = z.error ?? B.error, X = z.loading || B.loading, Z = () => {
|
|
37
|
+
J(), k(!1);
|
|
38
|
+
}, me = async () => {
|
|
39
|
+
R(null);
|
|
40
|
+
try {
|
|
41
|
+
let e = await U.draft({
|
|
42
|
+
description: G,
|
|
43
|
+
llmModelId: H,
|
|
44
|
+
scope: E
|
|
45
|
+
});
|
|
46
|
+
if (!e) return;
|
|
47
|
+
P(e), I(w(e));
|
|
48
|
+
} catch (e) {
|
|
49
|
+
R(b(e) ? "This workspace has no AI credits left for the copilot. The Free plan does not include AI-assisted creation; Pro does." : T(e, `Could not draft the ${O}.`));
|
|
50
|
+
}
|
|
51
|
+
}, he = async () => {
|
|
52
|
+
if (!N || !F) return;
|
|
53
|
+
R(null);
|
|
54
|
+
let e = q.map(({ include: e, ...t }) => t);
|
|
55
|
+
try {
|
|
56
|
+
let t = await pe({
|
|
57
|
+
draft: N,
|
|
58
|
+
app: F.app,
|
|
59
|
+
agents: e,
|
|
60
|
+
links: N.links
|
|
61
|
+
});
|
|
62
|
+
ce.success(E === "BOT" ? `Draft bot "${t.app?.name ?? ""}" created with ${t.agents.length} draft agent(s)` : `${t.agents.length} draft agent(s) created`), Z(), ue(t);
|
|
63
|
+
} catch (e) {
|
|
64
|
+
if (D && b(e)) {
|
|
65
|
+
Z(), D();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
R(T(e, `Could not create the draft ${O}.`));
|
|
69
|
+
}
|
|
70
|
+
}, Q = (e, t) => I((n) => n && {
|
|
71
|
+
...n,
|
|
72
|
+
agents: n.agents.map((n) => n.key === e ? {
|
|
73
|
+
...n,
|
|
74
|
+
...t
|
|
75
|
+
} : n)
|
|
76
|
+
}), ge = (e, t, n) => {
|
|
77
|
+
let r = F?.agents.find((t) => t.key === e);
|
|
78
|
+
r && Q(e, { knowledgeBaseIds: n ? [.../* @__PURE__ */ new Set([...r.knowledgeBaseIds, t])] : r.knowledgeBaseIds.filter((e) => e !== t) });
|
|
79
|
+
}, $ = F?.app?.name.trim() ?? "", _e = q.length > 0 && q.every((e) => {
|
|
80
|
+
let t = e.name.trim();
|
|
81
|
+
return t.length > 0 && t.length <= 100 && e.systemPrompt.trim().length > 0;
|
|
82
|
+
}) && (E === "AGENTS" || $.length > 0 && $.length <= 100);
|
|
83
|
+
return /* @__PURE__ */ y(_, { children: [/* @__PURE__ */ y(n, {
|
|
84
|
+
className: "max-w-2xl",
|
|
85
|
+
children: [/* @__PURE__ */ y(te, { children: [/* @__PURE__ */ y(i, {
|
|
86
|
+
className: "flex items-center gap-2",
|
|
87
|
+
children: [
|
|
88
|
+
/* @__PURE__ */ v(se, {
|
|
89
|
+
size: 18,
|
|
90
|
+
"aria-hidden": "true"
|
|
91
|
+
}),
|
|
92
|
+
"Describe your ",
|
|
93
|
+
O
|
|
94
|
+
]
|
|
95
|
+
}), /* @__PURE__ */ y(ee, { children: [
|
|
96
|
+
"Write one sentence and the copilot drafts",
|
|
97
|
+
" ",
|
|
98
|
+
E === "BOT" ? "a bot with its agents" : "agents",
|
|
99
|
+
" for you to review. Nothing goes live until you publish it. Uses AI credits."
|
|
100
|
+
] })] }), /* @__PURE__ */ v(r, { children: /* @__PURE__ */ y(t, {
|
|
101
|
+
leftIcon: /* @__PURE__ */ v(x, { size: 16 }),
|
|
102
|
+
onClick: () => k(!0),
|
|
103
|
+
children: ["Describe your ", O]
|
|
104
|
+
}) })]
|
|
105
|
+
}), /* @__PURE__ */ v(p, {
|
|
106
|
+
open: de,
|
|
107
|
+
onOpenChange: (e) => e ? k(!0) : Z(),
|
|
108
|
+
children: /* @__PURE__ */ y(m, {
|
|
109
|
+
className: "max-h-[90vh] overflow-y-auto sm:max-w-3xl",
|
|
110
|
+
children: [
|
|
111
|
+
/* @__PURE__ */ y(ae, { children: [/* @__PURE__ */ y(oe, { children: ["Describe your ", O] }), /* @__PURE__ */ v(h, { children: F ? "Review the draft. Edit or untick anything you do not want. Everything is created as a draft." : "One sentence is enough, for example: \"A bot that answers HR policy questions from our handbook and escalates payroll to a human.\"" })] }),
|
|
112
|
+
!F && /* @__PURE__ */ y("div", {
|
|
113
|
+
className: "space-y-4",
|
|
114
|
+
children: [
|
|
115
|
+
/* @__PURE__ */ v(a, {
|
|
116
|
+
label: "Description",
|
|
117
|
+
htmlFor: "copilot-description",
|
|
118
|
+
required: !0,
|
|
119
|
+
error: K,
|
|
120
|
+
description: `${G.length}/${C}`,
|
|
121
|
+
children: /* @__PURE__ */ v(s, {
|
|
122
|
+
id: "copilot-description",
|
|
123
|
+
rows: 3,
|
|
124
|
+
value: A,
|
|
125
|
+
disabled: U.loading,
|
|
126
|
+
"aria-invalid": K ? !0 : void 0,
|
|
127
|
+
onChange: (e) => fe(e.target.value)
|
|
128
|
+
})
|
|
129
|
+
}),
|
|
130
|
+
/* @__PURE__ */ v(a, {
|
|
131
|
+
label: "Model",
|
|
132
|
+
htmlFor: "copilot-model",
|
|
133
|
+
required: !0,
|
|
134
|
+
description: "A model registered in this workspace drafts the bot, and the drafted agents use it.",
|
|
135
|
+
children: /* @__PURE__ */ y("select", {
|
|
136
|
+
id: "copilot-model",
|
|
137
|
+
className: le,
|
|
138
|
+
value: H,
|
|
139
|
+
disabled: U.loading || z.loading || B.loading,
|
|
140
|
+
onChange: (e) => M(e.target.value),
|
|
141
|
+
children: [V.length === 0 && /* @__PURE__ */ v("option", {
|
|
142
|
+
value: "",
|
|
143
|
+
children: X ? "Loading models…" : Y ? "Models could not be loaded" : "No model registered yet"
|
|
144
|
+
}), V.map((e) => /* @__PURE__ */ y("option", {
|
|
145
|
+
value: e.id,
|
|
146
|
+
children: [
|
|
147
|
+
e.name,
|
|
148
|
+
" (",
|
|
149
|
+
e.modelId,
|
|
150
|
+
")"
|
|
151
|
+
]
|
|
152
|
+
}, e.id))]
|
|
153
|
+
})
|
|
154
|
+
}),
|
|
155
|
+
Y && !X && /* @__PURE__ */ y("div", {
|
|
156
|
+
role: "alert",
|
|
157
|
+
className: "flex items-center gap-2 text-sm text-status-error-text",
|
|
158
|
+
children: ["The models in this workspace could not be loaded.", /* @__PURE__ */ v(t, {
|
|
159
|
+
type: "button",
|
|
160
|
+
variant: "outline",
|
|
161
|
+
size: "sm",
|
|
162
|
+
onClick: () => {
|
|
163
|
+
z.refetch(), B.refetch();
|
|
164
|
+
},
|
|
165
|
+
children: "Retry"
|
|
166
|
+
})]
|
|
167
|
+
}),
|
|
168
|
+
U.loading && /* @__PURE__ */ v("p", {
|
|
169
|
+
role: "status",
|
|
170
|
+
className: "text-sm text-text-secondary",
|
|
171
|
+
children: "Drafting… this can take up to a minute. Cancel at any time; nothing is created."
|
|
172
|
+
})
|
|
173
|
+
]
|
|
174
|
+
}),
|
|
175
|
+
F && N && /* @__PURE__ */ y("div", {
|
|
176
|
+
className: "space-y-5",
|
|
177
|
+
children: [
|
|
178
|
+
/* @__PURE__ */ y("div", {
|
|
179
|
+
className: "flex flex-wrap items-center gap-2 text-xs text-text-secondary",
|
|
180
|
+
children: [
|
|
181
|
+
N.template && /* @__PURE__ */ y(e, {
|
|
182
|
+
variant: "secondary",
|
|
183
|
+
children: ["Started from template: ", N.template.name]
|
|
184
|
+
}),
|
|
185
|
+
/* @__PURE__ */ y(e, {
|
|
186
|
+
variant: "outline",
|
|
187
|
+
children: ["Model: ", N.model]
|
|
188
|
+
}),
|
|
189
|
+
/* @__PURE__ */ v(e, {
|
|
190
|
+
variant: "outline",
|
|
191
|
+
children: N.aiCredits == null ? "AI credits: not recorded" : `${N.aiCredits} AI credits used`
|
|
192
|
+
})
|
|
193
|
+
]
|
|
194
|
+
}),
|
|
195
|
+
N.notes && /* @__PURE__ */ v("p", {
|
|
196
|
+
className: "rounded-md border border-border-subtle p-3 text-sm",
|
|
197
|
+
children: N.notes
|
|
198
|
+
}),
|
|
199
|
+
F.app && /* @__PURE__ */ y("fieldset", {
|
|
200
|
+
className: "space-y-3 rounded-lg border border-border-subtle p-4",
|
|
201
|
+
children: [
|
|
202
|
+
/* @__PURE__ */ v("legend", {
|
|
203
|
+
className: "px-1 text-sm font-medium",
|
|
204
|
+
children: "Bot (draft)"
|
|
205
|
+
}),
|
|
206
|
+
/* @__PURE__ */ v(a, {
|
|
207
|
+
label: "Name",
|
|
208
|
+
htmlFor: "copilot-app-name",
|
|
209
|
+
required: !0,
|
|
210
|
+
children: /* @__PURE__ */ v(o, {
|
|
211
|
+
id: "copilot-app-name",
|
|
212
|
+
maxLength: 100,
|
|
213
|
+
value: F.app.name,
|
|
214
|
+
onChange: (e) => I({
|
|
215
|
+
...F,
|
|
216
|
+
app: {
|
|
217
|
+
...F.app,
|
|
218
|
+
name: e.target.value
|
|
219
|
+
}
|
|
220
|
+
})
|
|
221
|
+
})
|
|
222
|
+
}),
|
|
223
|
+
/* @__PURE__ */ v(a, {
|
|
224
|
+
label: "Welcome message",
|
|
225
|
+
htmlFor: "copilot-app-welcome",
|
|
226
|
+
children: /* @__PURE__ */ v(o, {
|
|
227
|
+
id: "copilot-app-welcome",
|
|
228
|
+
value: F.app.welcomeMessage ?? "",
|
|
229
|
+
onChange: (e) => I({
|
|
230
|
+
...F,
|
|
231
|
+
app: {
|
|
232
|
+
...F.app,
|
|
233
|
+
welcomeMessage: e.target.value
|
|
234
|
+
}
|
|
235
|
+
})
|
|
236
|
+
})
|
|
237
|
+
}),
|
|
238
|
+
/* @__PURE__ */ y("p", {
|
|
239
|
+
className: "text-xs text-text-secondary",
|
|
240
|
+
children: [
|
|
241
|
+
"Routing: ",
|
|
242
|
+
q.length > 1 ? F.app.routingStrategy : "SINGLE",
|
|
243
|
+
F.app.description ? ` · ${F.app.description}` : ""
|
|
244
|
+
]
|
|
245
|
+
})
|
|
246
|
+
]
|
|
247
|
+
}),
|
|
248
|
+
F.agents.map((e) => {
|
|
249
|
+
let t = N.links.find((t) => t.agentKey === e.key), n = N.knowledgeBases.filter((t) => t.agentKeys.includes(e.key));
|
|
250
|
+
return /* @__PURE__ */ y("fieldset", {
|
|
251
|
+
className: "space-y-3 rounded-lg border border-border-subtle p-4",
|
|
252
|
+
children: [/* @__PURE__ */ v("legend", {
|
|
253
|
+
className: "px-1 text-sm font-medium",
|
|
254
|
+
children: /* @__PURE__ */ y("label", {
|
|
255
|
+
className: "flex items-center gap-2",
|
|
256
|
+
children: [
|
|
257
|
+
/* @__PURE__ */ v("input", {
|
|
258
|
+
type: "checkbox",
|
|
259
|
+
checked: e.include,
|
|
260
|
+
onChange: (t) => Q(e.key, { include: t.target.checked })
|
|
261
|
+
}),
|
|
262
|
+
"Agent (draft): ",
|
|
263
|
+
e.name
|
|
264
|
+
]
|
|
265
|
+
})
|
|
266
|
+
}), e.include && /* @__PURE__ */ y(_, { children: [
|
|
267
|
+
/* @__PURE__ */ v(a, {
|
|
268
|
+
label: "Name",
|
|
269
|
+
htmlFor: `copilot-agent-${e.key}-name`,
|
|
270
|
+
required: !0,
|
|
271
|
+
children: /* @__PURE__ */ v(o, {
|
|
272
|
+
id: `copilot-agent-${e.key}-name`,
|
|
273
|
+
maxLength: 100,
|
|
274
|
+
value: e.name,
|
|
275
|
+
onChange: (t) => Q(e.key, { name: t.target.value })
|
|
276
|
+
})
|
|
277
|
+
}),
|
|
278
|
+
/* @__PURE__ */ v(a, {
|
|
279
|
+
label: "System prompt",
|
|
280
|
+
htmlFor: `copilot-agent-${e.key}-prompt`,
|
|
281
|
+
required: !0,
|
|
282
|
+
children: /* @__PURE__ */ v(s, {
|
|
283
|
+
id: `copilot-agent-${e.key}-prompt`,
|
|
284
|
+
rows: 6,
|
|
285
|
+
value: e.systemPrompt,
|
|
286
|
+
onChange: (t) => Q(e.key, { systemPrompt: t.target.value })
|
|
287
|
+
})
|
|
288
|
+
}),
|
|
289
|
+
n.length > 0 && /* @__PURE__ */ y("div", {
|
|
290
|
+
className: "space-y-1",
|
|
291
|
+
children: [/* @__PURE__ */ v("p", {
|
|
292
|
+
className: "text-sm font-medium",
|
|
293
|
+
children: "Suggested knowledge bases"
|
|
294
|
+
}), n.map((t) => /* @__PURE__ */ y("label", {
|
|
295
|
+
className: "flex items-start gap-2 text-sm",
|
|
296
|
+
children: [/* @__PURE__ */ v("input", {
|
|
297
|
+
type: "checkbox",
|
|
298
|
+
className: "mt-1",
|
|
299
|
+
checked: e.knowledgeBaseIds.includes(t.knowledgeBaseId),
|
|
300
|
+
onChange: (n) => ge(e.key, t.knowledgeBaseId, n.target.checked)
|
|
301
|
+
}), /* @__PURE__ */ y("span", { children: [t.name, t.reason && /* @__PURE__ */ v("span", {
|
|
302
|
+
className: "block text-xs text-text-secondary",
|
|
303
|
+
children: t.reason
|
|
304
|
+
})] })]
|
|
305
|
+
}, t.knowledgeBaseId))]
|
|
306
|
+
}),
|
|
307
|
+
E === "BOT" && t && /* @__PURE__ */ y("p", {
|
|
308
|
+
className: "text-xs text-text-secondary",
|
|
309
|
+
children: [
|
|
310
|
+
"Routing: priority ",
|
|
311
|
+
t.priority,
|
|
312
|
+
t.isDefault ? " · default agent" : "",
|
|
313
|
+
t.intentPatterns.length > 0 ? ` · intents: ${t.intentPatterns.join(", ")}` : "",
|
|
314
|
+
t.triggerKeywords.length > 0 ? ` · keywords: ${t.triggerKeywords.join(", ")}` : ""
|
|
315
|
+
]
|
|
316
|
+
})
|
|
317
|
+
] })]
|
|
318
|
+
}, e.key);
|
|
319
|
+
})
|
|
320
|
+
]
|
|
321
|
+
}),
|
|
322
|
+
L && /* @__PURE__ */ v("p", {
|
|
323
|
+
role: "alert",
|
|
324
|
+
className: "text-sm text-status-error-text",
|
|
325
|
+
children: L
|
|
326
|
+
}),
|
|
327
|
+
/* @__PURE__ */ v(g, { children: F ? /* @__PURE__ */ y(_, { children: [/* @__PURE__ */ v(t, {
|
|
328
|
+
variant: "outline",
|
|
329
|
+
onClick: J,
|
|
330
|
+
disabled: W.loading,
|
|
331
|
+
children: "Discard draft"
|
|
332
|
+
}), /* @__PURE__ */ v(t, {
|
|
333
|
+
isLoading: W.loading,
|
|
334
|
+
disabled: !_e || W.loading,
|
|
335
|
+
onClick: () => void he(),
|
|
336
|
+
children: "Create drafts"
|
|
337
|
+
})] }) : /* @__PURE__ */ y(_, { children: [/* @__PURE__ */ v(t, {
|
|
338
|
+
variant: "outline",
|
|
339
|
+
onClick: U.loading ? U.cancel : Z,
|
|
340
|
+
children: U.loading ? "Cancel drafting" : "Close"
|
|
341
|
+
}), /* @__PURE__ */ y(t, {
|
|
342
|
+
leftIcon: /* @__PURE__ */ v(x, { size: 16 }),
|
|
343
|
+
isLoading: U.loading,
|
|
344
|
+
disabled: U.loading || !H || G.length < S || G.length > C,
|
|
345
|
+
onClick: () => void me(),
|
|
346
|
+
children: ["Draft ", O]
|
|
347
|
+
})] }) })
|
|
348
|
+
]
|
|
349
|
+
})
|
|
350
|
+
})] });
|
|
351
|
+
};
|
|
352
|
+
export { E as DescribeBotDialog };
|
|
353
|
+
|
|
354
|
+
//# sourceMappingURL=DescribeBotDialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DescribeBotDialog.js","names":["_Fragment","Textarea","Textarea$1","Fragment$1","DESCRIPTION_MIN","DESCRIPTION_MAX","SELECT_CLASS","reviewFrom","draft","agent","errorText","error","fallback","DescribeBotDialog","noun","scope","open","setOpen","useState","description","setDescription","modelId","setModelId","setDraft","review","setReview","setError","models","useLLMModels","providers","useLLMProviders","answerModels","useMemo","configuredAnswerModels","chosenModel","model","drafting","useDraftBot","createDrafts","createState","useCreateFromDraft","trimmed","descriptionError","included","reset","catalogError","catalogLoading","close","runDraft","result","draftError","isQuotaExhaustedError","create","agents","_include","created","toast","onCreated","createError","onQuotaExhausted","updateAgent","current","key","patch","toggleKnowledgeBase","entry","agentKey","on","kbId","id","appName","canCreate","name","Card","CardHeader","CardTitle","WandSparkles","CardDescription","CardContent","Button","Sparkles","ResponsiveDialog","next","ResponsiveDialogContent","ResponsiveDialogHeader","ResponsiveDialogTitle","ResponsiveDialogDescription","FormField","event","Badge","Input","link","suggestions","kb","ResponsiveDialogFooter"],"sources":["../../../src/botlit/components/DescribeBotDialog.tsx"],"sourcesContent":["/**\n * Copilot \"Describe your bot\" (BOFF-15360, ABOUT §9, BL-UC-21)\n * @module botlit/components\n *\n * One sentence → a reviewable draft: the bot (on the bot create page), its\n * agents, routing links, the model and knowledge-base suggestions, started\n * from a workspace template when one fits. The draft is shown for review and\n * editing; nothing exists until the person clicks \"Create drafts\", and even\n * then every entity is a DRAFT that goes live only when it is published.\n * Drafting can be cancelled at any time and leaves nothing behind. It is\n * metered as AI credits on the workspace plan.\n */\n\nimport { useEffect, useMemo, useState, type FC } from 'react';\nimport { Sparkles, WandSparkles } from 'lucide-react';\nimport { toast } from 'sonner';\nimport { isQuotaExhaustedError } from '@burdenoff/fe-libs/shared/utils';\nimport {\n ResponsiveDialog,\n ResponsiveDialogContent,\n ResponsiveDialogDescription,\n ResponsiveDialogFooter,\n ResponsiveDialogHeader,\n ResponsiveDialogTitle,\n} from '@burdenoff/fe-libs/ui';\n\nimport { Badge } from './Badge';\nimport { Button } from './Button';\nimport { Card, CardContent, CardDescription, CardHeader, CardTitle } from './Card';\nimport { FormField, Input, Textarea } from './Input';\nimport {\n useCreateFromDraft,\n useDraftBot,\n type BotDraft,\n type BotDraftAgent,\n type BotDraftApp,\n type BotDraftScope,\n type CreatedDraft,\n} from '../hooks/useBotCopilot';\nimport { useLLMModels, useLLMProviders } from '../hooks/useLLMProviders';\nimport { configuredAnswerModels } from '../utils/embedding-models';\nimport { AGENT_NAME_MAX_LENGTH } from '../utils/agentSettings';\nimport { BOT_NAME_MAX_LENGTH } from '../utils/botIdentity';\n\nconst DESCRIPTION_MIN = 10;\nconst DESCRIPTION_MAX = 1000;\nconst SELECT_CLASS =\n 'flex h-10 w-full rounded-md border border-border-default bg-bg-surface px-3 py-2 text-sm';\n\ninterface DescribeBotDialogProps {\n scope: BotDraftScope;\n /** Receives what was created (every entity is DRAFT). */\n onCreated: (created: CreatedDraft) => void;\n /** Called instead of an inline message when the plan's bot limit is reached. */\n onQuotaExhausted?: () => void;\n}\n\ninterface ReviewState {\n app: BotDraftApp | null;\n agents: Array<BotDraftAgent & { include: boolean }>;\n}\n\nfunction reviewFrom(draft: BotDraft): ReviewState {\n return {\n app: draft.app ? { ...draft.app } : null,\n agents: draft.agents.map((agent) => ({ ...agent, include: true })),\n };\n}\n\nfunction errorText(error: unknown, fallback: string): string {\n return error instanceof Error && error.message ? error.message : fallback;\n}\n\nexport const DescribeBotDialog: FC<DescribeBotDialogProps> = ({\n scope,\n onCreated,\n onQuotaExhausted,\n}) => {\n const noun = scope === 'BOT' ? 'bot' : 'agent';\n const [open, setOpen] = useState(false);\n const [description, setDescription] = useState('');\n const [modelId, setModelId] = useState('');\n const [draft, setDraft] = useState<BotDraft | null>(null);\n const [review, setReview] = useState<ReviewState | null>(null);\n const [error, setError] = useState<string | null>(null);\n\n const models = useLLMModels();\n const providers = useLLMProviders();\n const answerModels = useMemo(\n () => configuredAnswerModels(models.data ?? [], providers.data ?? []),\n [models.data, providers.data]\n );\n // A selection only counts while it is still one of this workspace's models.\n const chosenModel = answerModels.some((model) => model.id === modelId)\n ? modelId\n : answerModels[0]?.id || '';\n\n const drafting = useDraftBot();\n const [createDrafts, createState] = useCreateFromDraft(scope);\n\n const trimmed = description.trim();\n const descriptionError =\n trimmed.length > 0 && trimmed.length < DESCRIPTION_MIN\n ? `Write at least ${DESCRIPTION_MIN} characters.`\n : trimmed.length > DESCRIPTION_MAX\n ? `Use at most ${DESCRIPTION_MAX} characters.`\n : undefined;\n const included = review?.agents.filter((agent) => agent.include) ?? [];\n\n const reset = () => {\n drafting.cancel();\n setDraft(null);\n setReview(null);\n setError(null);\n };\n\n // A draft from another workspace must never be created in this one.\n useEffect(() => {\n setModelId('');\n setDraft(null);\n setReview(null);\n setError(null);\n }, [drafting.workspaceId]);\n\n const catalogError = models.error ?? providers.error;\n const catalogLoading = models.loading || providers.loading;\n\n const close = () => {\n reset();\n setOpen(false);\n };\n\n const runDraft = async () => {\n setError(null);\n try {\n const result = await drafting.draft({ description: trimmed, llmModelId: chosenModel, scope });\n if (!result) return; // cancelled\n setDraft(result);\n setReview(reviewFrom(result));\n } catch (draftError: unknown) {\n setError(\n isQuotaExhaustedError(draftError)\n ? 'This workspace has no AI credits left for the copilot. The Free plan does not include AI-assisted creation; Pro does.'\n : errorText(draftError, `Could not draft the ${noun}.`)\n );\n }\n };\n\n const create = async () => {\n if (!draft || !review) return;\n setError(null);\n const agents = included.map(({ include: _include, ...agent }) => agent);\n try {\n const created = await createDrafts({ draft, app: review.app, agents, links: draft.links });\n toast.success(\n scope === 'BOT'\n ? `Draft bot \"${created.app?.name ?? ''}\" created with ${created.agents.length} draft agent(s)`\n : `${created.agents.length} draft agent(s) created`\n );\n close();\n onCreated(created);\n } catch (createError: unknown) {\n if (onQuotaExhausted && isQuotaExhaustedError(createError)) {\n close();\n onQuotaExhausted();\n return;\n }\n setError(errorText(createError, `Could not create the draft ${noun}.`));\n }\n };\n\n const updateAgent = (key: string, patch: Partial<BotDraftAgent & { include: boolean }>) =>\n setReview((current) =>\n current\n ? {\n ...current,\n agents: current.agents.map((agent) =>\n agent.key === key ? { ...agent, ...patch } : agent\n ),\n }\n : current\n );\n\n const toggleKnowledgeBase = (agentKey: string, kbId: string, on: boolean) => {\n const agent = review?.agents.find((entry) => entry.key === agentKey);\n if (!agent) return;\n updateAgent(agentKey, {\n knowledgeBaseIds: on\n ? [...new Set([...agent.knowledgeBaseIds, kbId])]\n : agent.knowledgeBaseIds.filter((id) => id !== kbId),\n });\n };\n\n const appName = review?.app?.name.trim() ?? '';\n const canCreate =\n included.length > 0 &&\n included.every((agent) => {\n const name = agent.name.trim();\n return (\n name.length > 0 &&\n name.length <= AGENT_NAME_MAX_LENGTH &&\n agent.systemPrompt.trim().length > 0\n );\n }) &&\n (scope === 'AGENTS' || (appName.length > 0 && appName.length <= BOT_NAME_MAX_LENGTH));\n\n return (\n <>\n <Card className=\"max-w-2xl\">\n <CardHeader>\n <CardTitle className=\"flex items-center gap-2\">\n <WandSparkles size={18} aria-hidden=\"true\" />\n Describe your {noun}\n </CardTitle>\n <CardDescription>\n Write one sentence and the copilot drafts{' '}\n {scope === 'BOT' ? 'a bot with its agents' : 'agents'} for you to review. Nothing goes\n live until you publish it. Uses AI credits.\n </CardDescription>\n </CardHeader>\n <CardContent>\n <Button leftIcon={<Sparkles size={16} />} onClick={() => setOpen(true)}>\n Describe your {noun}\n </Button>\n </CardContent>\n </Card>\n\n <ResponsiveDialog open={open} onOpenChange={(next) => (next ? setOpen(true) : close())}>\n <ResponsiveDialogContent className=\"max-h-[90vh] overflow-y-auto sm:max-w-3xl\">\n <ResponsiveDialogHeader>\n <ResponsiveDialogTitle>Describe your {noun}</ResponsiveDialogTitle>\n <ResponsiveDialogDescription>\n {review\n ? 'Review the draft. Edit or untick anything you do not want. Everything is created as a draft.'\n : 'One sentence is enough, for example: \"A bot that answers HR policy questions from our handbook and escalates payroll to a human.\"'}\n </ResponsiveDialogDescription>\n </ResponsiveDialogHeader>\n\n {!review && (\n <div className=\"space-y-4\">\n <FormField\n label=\"Description\"\n htmlFor=\"copilot-description\"\n required\n error={descriptionError}\n description={`${trimmed.length}/${DESCRIPTION_MAX}`}\n >\n <Textarea\n id=\"copilot-description\"\n rows={3}\n value={description}\n disabled={drafting.loading}\n aria-invalid={descriptionError ? true : undefined}\n onChange={(event) => setDescription(event.target.value)}\n />\n </FormField>\n <FormField\n label=\"Model\"\n htmlFor=\"copilot-model\"\n required\n description=\"A model registered in this workspace drafts the bot, and the drafted agents use it.\"\n >\n <select\n id=\"copilot-model\"\n className={SELECT_CLASS}\n value={chosenModel}\n disabled={drafting.loading || models.loading || providers.loading}\n onChange={(event) => setModelId(event.target.value)}\n >\n {answerModels.length === 0 && (\n <option value=\"\">\n {catalogLoading\n ? 'Loading models…'\n : catalogError\n ? 'Models could not be loaded'\n : 'No model registered yet'}\n </option>\n )}\n {answerModels.map((model) => (\n <option key={model.id} value={model.id}>\n {model.name} ({model.modelId})\n </option>\n ))}\n </select>\n </FormField>\n {catalogError && !catalogLoading && (\n <div\n role=\"alert\"\n className=\"flex items-center gap-2 text-sm text-status-error-text\"\n >\n The models in this workspace could not be loaded.\n <Button\n type=\"button\"\n variant=\"outline\"\n size=\"sm\"\n onClick={() => {\n void models.refetch();\n void providers.refetch();\n }}\n >\n Retry\n </Button>\n </div>\n )}\n {drafting.loading && (\n <p role=\"status\" className=\"text-sm text-text-secondary\">\n Drafting… this can take up to a minute. Cancel at any time; nothing is created.\n </p>\n )}\n </div>\n )}\n\n {review && draft && (\n <div className=\"space-y-5\">\n <div className=\"flex flex-wrap items-center gap-2 text-xs text-text-secondary\">\n {draft.template && (\n <Badge variant=\"secondary\">Started from template: {draft.template.name}</Badge>\n )}\n <Badge variant=\"outline\">Model: {draft.model}</Badge>\n <Badge variant=\"outline\">\n {draft.aiCredits != null\n ? `${draft.aiCredits} AI credits used`\n : 'AI credits: not recorded'}\n </Badge>\n </div>\n {draft.notes && (\n <p className=\"rounded-md border border-border-subtle p-3 text-sm\">{draft.notes}</p>\n )}\n\n {review.app && (\n <fieldset className=\"space-y-3 rounded-lg border border-border-subtle p-4\">\n <legend className=\"px-1 text-sm font-medium\">Bot (draft)</legend>\n <FormField label=\"Name\" htmlFor=\"copilot-app-name\" required>\n <Input\n id=\"copilot-app-name\"\n maxLength={BOT_NAME_MAX_LENGTH}\n value={review.app.name}\n onChange={(event) =>\n setReview({ ...review, app: { ...review.app!, name: event.target.value } })\n }\n />\n </FormField>\n <FormField label=\"Welcome message\" htmlFor=\"copilot-app-welcome\">\n <Input\n id=\"copilot-app-welcome\"\n value={review.app.welcomeMessage ?? ''}\n onChange={(event) =>\n setReview({\n ...review,\n app: { ...review.app!, welcomeMessage: event.target.value },\n })\n }\n />\n </FormField>\n <p className=\"text-xs text-text-secondary\">\n Routing: {included.length > 1 ? review.app.routingStrategy : 'SINGLE'}\n {review.app.description ? ` · ${review.app.description}` : ''}\n </p>\n </fieldset>\n )}\n\n {review.agents.map((agent) => {\n const link = draft.links.find((entry) => entry.agentKey === agent.key);\n const suggestions = draft.knowledgeBases.filter((kb) =>\n kb.agentKeys.includes(agent.key)\n );\n return (\n <fieldset\n key={agent.key}\n className=\"space-y-3 rounded-lg border border-border-subtle p-4\"\n >\n <legend className=\"px-1 text-sm font-medium\">\n <label className=\"flex items-center gap-2\">\n <input\n type=\"checkbox\"\n checked={agent.include}\n onChange={(event) =>\n updateAgent(agent.key, { include: event.target.checked })\n }\n />\n Agent (draft): {agent.name}\n </label>\n </legend>\n {agent.include && (\n <>\n <FormField\n label=\"Name\"\n htmlFor={`copilot-agent-${agent.key}-name`}\n required\n >\n <Input\n id={`copilot-agent-${agent.key}-name`}\n maxLength={AGENT_NAME_MAX_LENGTH}\n value={agent.name}\n onChange={(event) =>\n updateAgent(agent.key, { name: event.target.value })\n }\n />\n </FormField>\n <FormField\n label=\"System prompt\"\n htmlFor={`copilot-agent-${agent.key}-prompt`}\n required\n >\n <Textarea\n id={`copilot-agent-${agent.key}-prompt`}\n rows={6}\n value={agent.systemPrompt}\n onChange={(event) =>\n updateAgent(agent.key, { systemPrompt: event.target.value })\n }\n />\n </FormField>\n {suggestions.length > 0 && (\n <div className=\"space-y-1\">\n <p className=\"text-sm font-medium\">Suggested knowledge bases</p>\n {suggestions.map((kb) => (\n <label\n key={kb.knowledgeBaseId}\n className=\"flex items-start gap-2 text-sm\"\n >\n <input\n type=\"checkbox\"\n className=\"mt-1\"\n checked={agent.knowledgeBaseIds.includes(kb.knowledgeBaseId)}\n onChange={(event) =>\n toggleKnowledgeBase(\n agent.key,\n kb.knowledgeBaseId,\n event.target.checked\n )\n }\n />\n <span>\n {kb.name}\n {kb.reason && (\n <span className=\"block text-xs text-text-secondary\">\n {kb.reason}\n </span>\n )}\n </span>\n </label>\n ))}\n </div>\n )}\n {scope === 'BOT' && link && (\n <p className=\"text-xs text-text-secondary\">\n Routing: priority {link.priority}\n {link.isDefault ? ' · default agent' : ''}\n {link.intentPatterns.length > 0\n ? ` · intents: ${link.intentPatterns.join(', ')}`\n : ''}\n {link.triggerKeywords.length > 0\n ? ` · keywords: ${link.triggerKeywords.join(', ')}`\n : ''}\n </p>\n )}\n </>\n )}\n </fieldset>\n );\n })}\n </div>\n )}\n\n {error && (\n <p role=\"alert\" className=\"text-sm text-status-error-text\">\n {error}\n </p>\n )}\n\n <ResponsiveDialogFooter>\n {!review ? (\n <>\n <Button variant=\"outline\" onClick={drafting.loading ? drafting.cancel : close}>\n {drafting.loading ? 'Cancel drafting' : 'Close'}\n </Button>\n <Button\n leftIcon={<Sparkles size={16} />}\n isLoading={drafting.loading}\n disabled={\n drafting.loading ||\n !chosenModel ||\n trimmed.length < DESCRIPTION_MIN ||\n trimmed.length > DESCRIPTION_MAX\n }\n onClick={() => void runDraft()}\n >\n Draft {noun}\n </Button>\n </>\n ) : (\n <>\n <Button variant=\"outline\" onClick={reset} disabled={createState.loading}>\n Discard draft\n </Button>\n <Button\n isLoading={createState.loading}\n disabled={!canCreate || createState.loading}\n onClick={() => void create()}\n >\n Create drafts\n </Button>\n </>\n )}\n </ResponsiveDialogFooter>\n </ResponsiveDialogContent>\n </ResponsiveDialog>\n </>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;AA4CA,IAAMI,IAAkB,IAClBC,IAAkB,KAClBC,KACJ;AAeF,SAASC,EAAW,GAA8B;CAChD,OAAO;EACL,KAAKC,EAAM,MAAM,EAAE,GAAGA,EAAM,IAAI,IAAI;EACpC,QAAQA,EAAM,OAAO,KAAK,OAAW;GAAE,GAAGC;GAAO,SAAS;EAAK,EAAE;CACnE;AACF;AAEA,SAASC,EAAU,GAAgB,GAA0B;CAC3D,OAAOC,aAAiB,SAASA,EAAM,UAAUA,EAAM,UAAUC;AACnE;AAEA,IAAaC,KAAiD,EAC5D,UACA,eACA,0BACI;CACJ,IAAMC,IAAOC,MAAU,QAAQ,QAAQ,SACjC,CAACC,IAA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,kBAAC2C,GAAD;KACE,UAAU,kBAACC,GAAD,EAAU,MAAM,GAAK,CAAA;KAC/B,WAAW5C,EAAS;KACpB,UACEA,EAAS,WACT,CAACF,KACDO,EAAQ,SAASrC,KACjBqC,EAAQ,SAASpC;KAEnB,eAAe,KAAK2C,GAAS;KAT/B,UAAA,CAUC,UACQlC,CACD;IACR,CAAA,CAAA,EAAA,CAAA,EAekB,CAAA;GACD;;CACT,CAAA,CAClB,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copilot "Describe your bot" (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>];
|