fi-glass 1.1.0
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/LICENSE +77 -0
- package/README.md +162 -0
- package/dist/agent/index.d.ts +399 -0
- package/dist/agent/index.js +1979 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/composer/index.d.ts +57 -0
- package/dist/composer/index.js +112 -0
- package/dist/composer/index.js.map +1 -0
- package/dist/conversation/index.d.ts +80 -0
- package/dist/conversation/index.js +207 -0
- package/dist/conversation/index.js.map +1 -0
- package/dist/glass-theme-D-leVuKb.d.ts +19 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +4316 -0
- package/dist/index.js.map +1 -0
- package/dist/messages/index.d.ts +213 -0
- package/dist/messages/index.js +337 -0
- package/dist/messages/index.js.map +1 -0
- package/dist/persona-selector/index.d.ts +54 -0
- package/dist/persona-selector/index.js +215 -0
- package/dist/persona-selector/index.js.map +1 -0
- package/dist/shell/index.d.ts +429 -0
- package/dist/shell/index.js +1566 -0
- package/dist/shell/index.js.map +1 -0
- package/dist/theme/index.d.ts +58 -0
- package/dist/theme/index.js +38 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/voice/index.d.ts +790 -0
- package/dist/voice/index.js +2591 -0
- package/dist/voice/index.js.map +1 -0
- package/package.json +85 -0
- package/src/theme/glass-chat-preset.ts +74 -0
- package/src/theme/glass-chat.css +217 -0
- package/src/theme/glass-theme.ts +26 -0
- package/src/theme/glass.css +27 -0
- package/src/theme/index.css +3 -0
- package/src/theme/index.ts +4 -0
- package/src/theme/tokens.css +13 -0
|
@@ -0,0 +1,1979 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// src/agent/icons.ts
|
|
4
|
+
import {
|
|
5
|
+
AlertTriangle,
|
|
6
|
+
BookOpen,
|
|
7
|
+
Bot,
|
|
8
|
+
ExternalLink,
|
|
9
|
+
FileText,
|
|
10
|
+
Globe,
|
|
11
|
+
ListChecks,
|
|
12
|
+
Receipt,
|
|
13
|
+
Search,
|
|
14
|
+
Terminal,
|
|
15
|
+
Wrench
|
|
16
|
+
} from "lucide-react";
|
|
17
|
+
|
|
18
|
+
// src/agent/toolClassify.ts
|
|
19
|
+
function classifyTool(name) {
|
|
20
|
+
const n = name.toLowerCase();
|
|
21
|
+
if (n.includes("search")) return "search";
|
|
22
|
+
if (n.includes("scrape") || n.includes("fetch") || n.includes("unlock")) return "scrape";
|
|
23
|
+
if (n.includes("browser")) return "browser";
|
|
24
|
+
if (n.includes("document") || n.includes("rag")) return "rag";
|
|
25
|
+
if (n === "bash" || n.endsWith("__bash")) return "bash";
|
|
26
|
+
if (n.includes("listmcp") || n.includes("listtool")) return "introspect";
|
|
27
|
+
return "generic";
|
|
28
|
+
}
|
|
29
|
+
function shortToolName(name) {
|
|
30
|
+
return name.replace(/^mcp__[^_]+__/, "");
|
|
31
|
+
}
|
|
32
|
+
function stepStatusKey(isError) {
|
|
33
|
+
if (isError === null) return "pending";
|
|
34
|
+
return isError ? "error" : "done";
|
|
35
|
+
}
|
|
36
|
+
function latestOpenToolIndex(steps) {
|
|
37
|
+
return steps.reduce(
|
|
38
|
+
(latest, step, index) => step.isError === null ? index : latest,
|
|
39
|
+
-1
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
function toolVisualStatus(step, index, latestOpenIndex, live) {
|
|
43
|
+
const raw = stepStatusKey(step.isError);
|
|
44
|
+
if (raw === "error") return "error";
|
|
45
|
+
if (raw === "done") return "done";
|
|
46
|
+
if (!live) return "done";
|
|
47
|
+
return index === latestOpenIndex ? "active" : "sent";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/agent/icons.ts
|
|
51
|
+
var defaultAgentIcons = {
|
|
52
|
+
plan: ListChecks,
|
|
53
|
+
warning: AlertTriangle,
|
|
54
|
+
bot: Bot,
|
|
55
|
+
sources: Receipt,
|
|
56
|
+
external: ExternalLink,
|
|
57
|
+
tools: {
|
|
58
|
+
search: Search,
|
|
59
|
+
scrape: FileText,
|
|
60
|
+
browser: Globe,
|
|
61
|
+
rag: BookOpen,
|
|
62
|
+
bash: Terminal,
|
|
63
|
+
introspect: ListChecks,
|
|
64
|
+
generic: Wrench
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
function resolveIcons(overrides) {
|
|
68
|
+
if (!overrides) return defaultAgentIcons;
|
|
69
|
+
return {
|
|
70
|
+
...defaultAgentIcons,
|
|
71
|
+
...overrides,
|
|
72
|
+
tools: { ...defaultAgentIcons.tools, ...overrides.tools ?? {} }
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function toolIcon(icons, name) {
|
|
76
|
+
return icons.tools[classifyTool(name)];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// src/agent/PlanChecklist.tsx
|
|
80
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
81
|
+
function PlanChecklist({
|
|
82
|
+
plan,
|
|
83
|
+
classNames,
|
|
84
|
+
icons,
|
|
85
|
+
renderGuardBanner
|
|
86
|
+
}) {
|
|
87
|
+
if (!plan || plan.steps.length === 0) return null;
|
|
88
|
+
const ic = resolveIcons(icons);
|
|
89
|
+
const PlanIcon = ic.plan;
|
|
90
|
+
const WarnIcon = ic.warning;
|
|
91
|
+
const card = classNames?.card ?? "";
|
|
92
|
+
const hint = classNames?.hint ?? "";
|
|
93
|
+
const done = plan.steps.filter((s) => s.status === "done").length;
|
|
94
|
+
const total = plan.steps.length;
|
|
95
|
+
const rejection = plan.rejection ?? null;
|
|
96
|
+
const matchedIndexes = new Set(rejection?.matched.map((m) => m.index) ?? []);
|
|
97
|
+
const outcome = plan.outcome ?? null;
|
|
98
|
+
const outcomeBadge = outcome === "completed" ? { label: "completed", tone: "border-emerald-500/30 bg-emerald-500/10 text-emerald-300" } : outcome === "failed" ? { label: "failed", tone: "border-red-500/30 bg-red-500/10 text-red-300" } : outcome === "cancelled" ? { label: "cancelled", tone: "border-zinc-500/30 bg-zinc-500/10 text-zinc-400" } : null;
|
|
99
|
+
const amended = plan.amended ?? null;
|
|
100
|
+
const amendedLabel = amended === "replan" ? "re-planned" : amended === "insert" ? "revised" : null;
|
|
101
|
+
return /* @__PURE__ */ jsxs("div", { className: `${card} mb-2 text-sm`.trim(), children: [
|
|
102
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2 text-zinc-300", children: [
|
|
103
|
+
/* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-2 font-medium", children: [
|
|
104
|
+
/* @__PURE__ */ jsx(PlanIcon, { className: "h-4 w-4 text-zinc-400", "aria-hidden": true }),
|
|
105
|
+
"plan",
|
|
106
|
+
amendedLabel && /* @__PURE__ */ jsx("span", { className: "rounded border border-amber-500/30 bg-amber-500/10 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-amber-300", children: amendedLabel }),
|
|
107
|
+
outcomeBadge && /* @__PURE__ */ jsx("span", { className: `rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide ${outcomeBadge.tone}`, children: outcomeBadge.label })
|
|
108
|
+
] }),
|
|
109
|
+
/* @__PURE__ */ jsxs("span", { className: `${hint} text-xs tabular-nums`.trim(), children: [
|
|
110
|
+
done,
|
|
111
|
+
" / ",
|
|
112
|
+
total
|
|
113
|
+
] })
|
|
114
|
+
] }),
|
|
115
|
+
rejection && (renderGuardBanner ? renderGuardBanner(rejection) : /* @__PURE__ */ jsxs("div", { className: "mt-2 flex items-start gap-2 rounded border border-amber-500/30 bg-amber-500/10 p-2 text-xs text-amber-200", children: [
|
|
116
|
+
/* @__PURE__ */ jsx(
|
|
117
|
+
WarnIcon,
|
|
118
|
+
{
|
|
119
|
+
className: "mt-0.5 h-3.5 w-3.5 shrink-0 text-amber-400",
|
|
120
|
+
"aria-hidden": true
|
|
121
|
+
}
|
|
122
|
+
),
|
|
123
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-0.5", children: [
|
|
124
|
+
/* @__PURE__ */ jsx("span", { className: "font-medium", children: "A guard blocked this plan" }),
|
|
125
|
+
/* @__PURE__ */ jsx("span", { className: "text-amber-200/80", children: rejection.reason }),
|
|
126
|
+
rejection.guard && /* @__PURE__ */ jsxs(
|
|
127
|
+
"span",
|
|
128
|
+
{
|
|
129
|
+
className: `${hint} text-[10px] uppercase tracking-wide text-amber-300/60`.trim(),
|
|
130
|
+
children: [
|
|
131
|
+
"guard: ",
|
|
132
|
+
rejection.guard
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
)
|
|
136
|
+
] })
|
|
137
|
+
] })),
|
|
138
|
+
/* @__PURE__ */ jsx("ol", { className: "mt-2 space-y-1.5", children: plan.steps.map((step, i) => {
|
|
139
|
+
const isRunning = step.status === "running";
|
|
140
|
+
const isPending2 = step.status === "pending";
|
|
141
|
+
const isDone = step.status === "done";
|
|
142
|
+
const isFailed = step.status === "failed";
|
|
143
|
+
const isCancelled = step.status === "cancelled";
|
|
144
|
+
const isRejected = matchedIndexes.has(i);
|
|
145
|
+
const labelTone = isRejected ? "text-amber-300 line-through decoration-amber-500/60" : isFailed ? "text-red-400" : isCancelled ? "text-zinc-500 line-through decoration-zinc-600" : isDone ? "text-zinc-300" : isRunning ? "text-zinc-100" : "text-zinc-500";
|
|
146
|
+
const railTone = isFailed ? "text-red-400" : isCancelled ? "text-zinc-500 bg-zinc-500" : isDone ? "text-emerald-400 bg-emerald-400" : isRunning ? "text-amber-300 bg-amber-300" : "text-zinc-600 bg-zinc-700";
|
|
147
|
+
return /* @__PURE__ */ jsxs("li", { className: "flex flex-col gap-0.5", children: [
|
|
148
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-xs", children: [
|
|
149
|
+
/* @__PURE__ */ jsx(
|
|
150
|
+
"span",
|
|
151
|
+
{
|
|
152
|
+
className: `h-5 w-1 shrink-0 rounded-full ${railTone} ${isRunning ? "shadow-[0_0_10px_rgb(251_191_36/0.45)]" : ""}`,
|
|
153
|
+
"aria-label": step.status
|
|
154
|
+
}
|
|
155
|
+
),
|
|
156
|
+
/* @__PURE__ */ jsx("span", { className: `flex-1 truncate ${labelTone}`, children: step.label }),
|
|
157
|
+
isPending2 && /* @__PURE__ */ jsx("span", { className: `${hint} text-[10px] uppercase tracking-wide`.trim(), children: "queued" }),
|
|
158
|
+
isRunning && /* @__PURE__ */ jsx("span", { className: "text-[10px] uppercase tracking-wide text-amber-300", children: "running" }),
|
|
159
|
+
isCancelled && /* @__PURE__ */ jsx("span", { className: `${hint} text-[10px] uppercase tracking-wide`.trim(), children: "cancelled" })
|
|
160
|
+
] }),
|
|
161
|
+
step.summary && isDone && /* @__PURE__ */ jsx("div", { className: `${hint} pl-5 font-mono text-[11px] text-zinc-500`.trim(), children: step.summary }),
|
|
162
|
+
step.error && isFailed && /* @__PURE__ */ jsx("div", { className: "pl-5 font-mono text-[11px] text-red-400/80", children: step.error }),
|
|
163
|
+
step.error && isCancelled && /* @__PURE__ */ jsx("div", { className: "pl-5 font-mono text-[11px] text-zinc-500", children: step.error }),
|
|
164
|
+
step.note && /* @__PURE__ */ jsxs("div", { className: "pl-5 text-[11px] italic text-zinc-400", children: [
|
|
165
|
+
"note: ",
|
|
166
|
+
step.note
|
|
167
|
+
] })
|
|
168
|
+
] }, i);
|
|
169
|
+
}) })
|
|
170
|
+
] });
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// src/agent/StepsPanel.tsx
|
|
174
|
+
import { useEffect, useState } from "react";
|
|
175
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
176
|
+
function StepsPanel({
|
|
177
|
+
steps,
|
|
178
|
+
status,
|
|
179
|
+
target,
|
|
180
|
+
classNames,
|
|
181
|
+
icons,
|
|
182
|
+
enableSlowBanner = true,
|
|
183
|
+
slowThresholdMs = 12e3
|
|
184
|
+
}) {
|
|
185
|
+
const ic = resolveIcons(icons);
|
|
186
|
+
const BotIcon = ic.bot;
|
|
187
|
+
const WarnIcon = ic.warning;
|
|
188
|
+
const card = classNames?.card ?? "";
|
|
189
|
+
const hint = classNames?.hint ?? "";
|
|
190
|
+
const live = status === "thinking" || status === "streaming";
|
|
191
|
+
const [openOverride, setOpenOverride] = useState(null);
|
|
192
|
+
const open = openOverride ?? live;
|
|
193
|
+
const [elapsed, setElapsed] = useState(0);
|
|
194
|
+
useEffect(() => {
|
|
195
|
+
if (!live || !enableSlowBanner) {
|
|
196
|
+
setElapsed(0);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const start = Date.now();
|
|
200
|
+
const t = setInterval(() => setElapsed(Date.now() - start), 500);
|
|
201
|
+
return () => clearInterval(t);
|
|
202
|
+
}, [live, enableSlowBanner]);
|
|
203
|
+
const showSlowBanner = live && enableSlowBanner && elapsed >= slowThresholdMs;
|
|
204
|
+
if (steps.length === 0 && status === "done") return null;
|
|
205
|
+
const shortTarget = target && target.length > 36 ? `${target.slice(0, 33).trim()}\u2026` : target;
|
|
206
|
+
const summary = status === "thinking" ? shortTarget ? `Unlocking ${shortTarget}\u2026` : "thinking\u2026" : status === "streaming" && steps.length === 0 ? "writing\u2026" : `${steps.length} ${steps.length === 1 ? "step" : "steps"}`;
|
|
207
|
+
const latestPendingIndex = live ? latestOpenToolIndex(steps) : -1;
|
|
208
|
+
return /* @__PURE__ */ jsxs2("div", { className: `${card} mb-2 text-sm`.trim(), children: [
|
|
209
|
+
/* @__PURE__ */ jsxs2(
|
|
210
|
+
"button",
|
|
211
|
+
{
|
|
212
|
+
type: "button",
|
|
213
|
+
onClick: () => setOpenOverride(!open),
|
|
214
|
+
className: "flex w-full items-center justify-between gap-2 text-left text-zinc-300 hover:text-zinc-100",
|
|
215
|
+
"aria-expanded": open,
|
|
216
|
+
children: [
|
|
217
|
+
/* @__PURE__ */ jsxs2("span", { className: "inline-flex items-center gap-2 font-medium", children: [
|
|
218
|
+
/* @__PURE__ */ jsx2(BotIcon, { className: "h-4 w-4 text-zinc-400", "aria-hidden": true }),
|
|
219
|
+
summary
|
|
220
|
+
] }),
|
|
221
|
+
/* @__PURE__ */ jsx2("span", { className: `${hint} text-xs`.trim(), children: open ? "hide" : "show" })
|
|
222
|
+
]
|
|
223
|
+
}
|
|
224
|
+
),
|
|
225
|
+
showSlowBanner && /* @__PURE__ */ jsxs2(
|
|
226
|
+
"div",
|
|
227
|
+
{
|
|
228
|
+
className: "mt-2 inline-flex items-start gap-2 rounded-lg border border-amber-700/40 bg-amber-950/20 p-2.5 text-xs text-amber-200",
|
|
229
|
+
role: "status",
|
|
230
|
+
children: [
|
|
231
|
+
/* @__PURE__ */ jsx2(
|
|
232
|
+
WarnIcon,
|
|
233
|
+
{
|
|
234
|
+
className: "h-3.5 w-3.5 shrink-0 mt-0.5 text-amber-400",
|
|
235
|
+
"aria-hidden": true
|
|
236
|
+
}
|
|
237
|
+
),
|
|
238
|
+
/* @__PURE__ */ jsx2("span", { children: "Still working. This can take a second." })
|
|
239
|
+
]
|
|
240
|
+
}
|
|
241
|
+
),
|
|
242
|
+
open && steps.length > 0 && /* @__PURE__ */ jsx2("ol", { className: "mt-2 space-y-1", children: steps.map((s, i) => {
|
|
243
|
+
const ToolIcon = toolIcon(ic, s.name);
|
|
244
|
+
const statusKey = toolVisualStatus(s, i, latestPendingIndex, live);
|
|
245
|
+
const errored = statusKey === "error";
|
|
246
|
+
const active = statusKey === "active";
|
|
247
|
+
return /* @__PURE__ */ jsxs2(
|
|
248
|
+
"li",
|
|
249
|
+
{
|
|
250
|
+
className: `flex items-center gap-2 font-mono text-xs ${errored ? "text-red-400" : "text-zinc-400"}`,
|
|
251
|
+
children: [
|
|
252
|
+
/* @__PURE__ */ jsx2(ToolIcon, { className: "h-3.5 w-3.5 shrink-0", "aria-hidden": true }),
|
|
253
|
+
/* @__PURE__ */ jsx2("span", { className: "truncate", children: shortToolName(s.name) }),
|
|
254
|
+
s.server && s.server !== "brightdata" && /* @__PURE__ */ jsxs2("span", { className: `${hint} text-[10px] uppercase`.trim(), children: [
|
|
255
|
+
"\xB7 ",
|
|
256
|
+
s.server
|
|
257
|
+
] }),
|
|
258
|
+
/* @__PURE__ */ jsx2(
|
|
259
|
+
"span",
|
|
260
|
+
{
|
|
261
|
+
className: `ml-auto rounded-full border px-1.5 py-0.5 text-[9px] uppercase tracking-wide ${active ? "border-amber-400/30 bg-amber-400/10 text-amber-300" : statusKey === "sent" ? "border-zinc-500/25 bg-zinc-500/10 text-zinc-400" : errored ? "border-red-400/30 bg-red-400/10 text-red-300" : "border-emerald-400/25 bg-emerald-400/10 text-emerald-300"}`,
|
|
262
|
+
"aria-label": statusKey,
|
|
263
|
+
children: statusKey
|
|
264
|
+
}
|
|
265
|
+
)
|
|
266
|
+
]
|
|
267
|
+
},
|
|
268
|
+
s.id ?? `${s.name}-${i}`
|
|
269
|
+
);
|
|
270
|
+
}) })
|
|
271
|
+
] });
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// src/agent/SourcesPanel.tsx
|
|
275
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
276
|
+
function splitSource(url) {
|
|
277
|
+
try {
|
|
278
|
+
const u = new URL(url);
|
|
279
|
+
const host = u.host.replace(/^www\./, "");
|
|
280
|
+
const rest = `${u.pathname}${u.search}${u.hash}`;
|
|
281
|
+
return { host, rest: rest === "/" ? "" : rest };
|
|
282
|
+
} catch {
|
|
283
|
+
return { host: url, rest: "" };
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
function SourcesPanel({
|
|
287
|
+
sources,
|
|
288
|
+
classNames,
|
|
289
|
+
icons,
|
|
290
|
+
label = "Sources"
|
|
291
|
+
}) {
|
|
292
|
+
if (sources.length === 0) return null;
|
|
293
|
+
const ic = resolveIcons(icons);
|
|
294
|
+
const SourcesIcon = ic.sources;
|
|
295
|
+
const ExternalIcon = ic.external;
|
|
296
|
+
const card = classNames?.card ?? "";
|
|
297
|
+
const hint = classNames?.hint ?? "";
|
|
298
|
+
const row = classNames?.sourceRow ?? "bg-zinc-500/10 hover:border-zinc-400/40 hover:bg-zinc-500/20";
|
|
299
|
+
return /* @__PURE__ */ jsxs3("div", { className: `${card} text-sm`.trim(), children: [
|
|
300
|
+
/* @__PURE__ */ jsxs3("h2", { className: "mb-3 inline-flex items-center gap-2 font-medium text-zinc-200", children: [
|
|
301
|
+
/* @__PURE__ */ jsx3(SourcesIcon, { className: "h-4 w-4 text-zinc-400", "aria-hidden": true }),
|
|
302
|
+
label,
|
|
303
|
+
/* @__PURE__ */ jsxs3("span", { className: `${hint} ml-1 text-xs tabular-nums`.trim(), children: [
|
|
304
|
+
"(",
|
|
305
|
+
sources.length,
|
|
306
|
+
")"
|
|
307
|
+
] })
|
|
308
|
+
] }),
|
|
309
|
+
/* @__PURE__ */ jsx3("ul", { className: "flex flex-col gap-1.5 text-sm", children: sources.map((u) => {
|
|
310
|
+
const { host, rest } = splitSource(u);
|
|
311
|
+
return /* @__PURE__ */ jsx3("li", { children: /* @__PURE__ */ jsxs3(
|
|
312
|
+
"a",
|
|
313
|
+
{
|
|
314
|
+
href: u,
|
|
315
|
+
target: "_blank",
|
|
316
|
+
rel: "noopener noreferrer",
|
|
317
|
+
className: `group flex items-center gap-2 rounded-lg border border-transparent px-3 py-2 transition ${row}`,
|
|
318
|
+
children: [
|
|
319
|
+
/* @__PURE__ */ jsxs3("span", { className: "truncate", children: [
|
|
320
|
+
/* @__PURE__ */ jsx3("span", { className: "font-semibold text-zinc-100", children: host }),
|
|
321
|
+
rest && /* @__PURE__ */ jsx3("span", { className: "ml-0.5 font-mono text-xs text-zinc-500", children: rest })
|
|
322
|
+
] }),
|
|
323
|
+
/* @__PURE__ */ jsx3(
|
|
324
|
+
ExternalIcon,
|
|
325
|
+
{
|
|
326
|
+
className: "ml-auto h-3.5 w-3.5 shrink-0 text-zinc-400 opacity-0 transition group-hover:opacity-100",
|
|
327
|
+
"aria-hidden": true
|
|
328
|
+
}
|
|
329
|
+
)
|
|
330
|
+
]
|
|
331
|
+
}
|
|
332
|
+
) }, u);
|
|
333
|
+
}) })
|
|
334
|
+
] });
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// src/agent/AgentPanel.tsx
|
|
338
|
+
import { Fragment, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
339
|
+
function AgentPanel({
|
|
340
|
+
turn,
|
|
341
|
+
target,
|
|
342
|
+
classNames,
|
|
343
|
+
icons,
|
|
344
|
+
enableSlowBanner,
|
|
345
|
+
slowThresholdMs,
|
|
346
|
+
renderSources,
|
|
347
|
+
renderGuardBanner
|
|
348
|
+
}) {
|
|
349
|
+
return /* @__PURE__ */ jsxs4(Fragment, { children: [
|
|
350
|
+
/* @__PURE__ */ jsx4(
|
|
351
|
+
PlanChecklist,
|
|
352
|
+
{
|
|
353
|
+
plan: turn.plan,
|
|
354
|
+
classNames,
|
|
355
|
+
icons,
|
|
356
|
+
renderGuardBanner
|
|
357
|
+
}
|
|
358
|
+
),
|
|
359
|
+
/* @__PURE__ */ jsx4(
|
|
360
|
+
StepsPanel,
|
|
361
|
+
{
|
|
362
|
+
steps: turn.steps,
|
|
363
|
+
status: turn.status,
|
|
364
|
+
target,
|
|
365
|
+
classNames,
|
|
366
|
+
icons,
|
|
367
|
+
enableSlowBanner,
|
|
368
|
+
slowThresholdMs
|
|
369
|
+
}
|
|
370
|
+
),
|
|
371
|
+
renderSources ? renderSources(turn.sources) : /* @__PURE__ */ jsx4(SourcesPanel, { sources: turn.sources, classNames, icons })
|
|
372
|
+
] });
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// src/agent/useAgentConversation.ts
|
|
376
|
+
import { useCallback, useEffect as useEffect2, useRef, useState as useState2 } from "react";
|
|
377
|
+
import {
|
|
378
|
+
makeUserMessage,
|
|
379
|
+
foldAssistantTurn
|
|
380
|
+
} from "@free-intelligence/core";
|
|
381
|
+
var DEFAULT_TURN_TIMEOUT_MS = 6e4;
|
|
382
|
+
function useAgentConversation(agent, options = {}) {
|
|
383
|
+
const {
|
|
384
|
+
conversationId,
|
|
385
|
+
initialMessages,
|
|
386
|
+
onMessagesChange,
|
|
387
|
+
turnTimeoutMs = DEFAULT_TURN_TIMEOUT_MS,
|
|
388
|
+
isAppHandledError
|
|
389
|
+
} = options;
|
|
390
|
+
const [messages, setMessages] = useState2(
|
|
391
|
+
initialMessages ?? []
|
|
392
|
+
);
|
|
393
|
+
const [turnError, setTurnError] = useState2(null);
|
|
394
|
+
const [timedOut, setTimedOut] = useState2(false);
|
|
395
|
+
const pending = useRef(false);
|
|
396
|
+
const agentRef = useRef(agent);
|
|
397
|
+
agentRef.current = agent;
|
|
398
|
+
const appHandledRef = useRef(isAppHandledError);
|
|
399
|
+
appHandledRef.current = isAppHandledError;
|
|
400
|
+
const lastSent = useRef(null);
|
|
401
|
+
const initialRef = useRef(initialMessages);
|
|
402
|
+
initialRef.current = initialMessages;
|
|
403
|
+
const skipPersist = useRef(true);
|
|
404
|
+
const mounted = useRef(false);
|
|
405
|
+
const revertOptimistic = useCallback(() => {
|
|
406
|
+
setMessages((prev) => {
|
|
407
|
+
const last = prev[prev.length - 1];
|
|
408
|
+
return last?.role === "user" ? prev.slice(0, -1) : prev;
|
|
409
|
+
});
|
|
410
|
+
}, []);
|
|
411
|
+
const send = useCallback(
|
|
412
|
+
(text) => {
|
|
413
|
+
const t = text.trim();
|
|
414
|
+
if (!t || agent.isStreaming) return;
|
|
415
|
+
lastSent.current = t;
|
|
416
|
+
setTurnError(null);
|
|
417
|
+
setTimedOut(false);
|
|
418
|
+
skipPersist.current = true;
|
|
419
|
+
setMessages((prev) => [...prev, makeUserMessage(t)]);
|
|
420
|
+
pending.current = true;
|
|
421
|
+
void agent.send(t);
|
|
422
|
+
},
|
|
423
|
+
[agent]
|
|
424
|
+
);
|
|
425
|
+
const retry = useCallback(() => {
|
|
426
|
+
if (lastSent.current) send(lastSent.current);
|
|
427
|
+
}, [send]);
|
|
428
|
+
const dismissError = useCallback(() => {
|
|
429
|
+
setTurnError(null);
|
|
430
|
+
setTimedOut(false);
|
|
431
|
+
}, []);
|
|
432
|
+
useEffect2(() => {
|
|
433
|
+
if (agent.isStreaming || !pending.current) return;
|
|
434
|
+
pending.current = false;
|
|
435
|
+
if (agent.turn.status === "error") {
|
|
436
|
+
revertOptimistic();
|
|
437
|
+
if (!appHandledRef.current?.(agent.turn)) {
|
|
438
|
+
setTurnError({
|
|
439
|
+
kind: "stream",
|
|
440
|
+
message: agent.turn.errorMessage || "La respuesta fall\xF3. Intenta de nuevo."
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
if (agent.turn.text) {
|
|
446
|
+
skipPersist.current = false;
|
|
447
|
+
setMessages((prev) => [...prev, foldAssistantTurn(agent.turn)]);
|
|
448
|
+
}
|
|
449
|
+
}, [agent.isStreaming, agent.turn, revertOptimistic]);
|
|
450
|
+
useEffect2(() => {
|
|
451
|
+
if (turnTimeoutMs <= 0) return;
|
|
452
|
+
if (!agent.isStreaming || !pending.current || timedOut) return;
|
|
453
|
+
const timer = setTimeout(() => {
|
|
454
|
+
pending.current = false;
|
|
455
|
+
agentRef.current.abort?.();
|
|
456
|
+
revertOptimistic();
|
|
457
|
+
setTimedOut(true);
|
|
458
|
+
setTurnError({
|
|
459
|
+
kind: "timeout",
|
|
460
|
+
message: "La respuesta tard\xF3 demasiado. Intenta de nuevo."
|
|
461
|
+
});
|
|
462
|
+
}, turnTimeoutMs);
|
|
463
|
+
return () => clearTimeout(timer);
|
|
464
|
+
}, [agent.isStreaming, agent.turn, timedOut, turnTimeoutMs, revertOptimistic]);
|
|
465
|
+
useEffect2(() => {
|
|
466
|
+
if (!mounted.current) {
|
|
467
|
+
mounted.current = true;
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
skipPersist.current = true;
|
|
471
|
+
pending.current = false;
|
|
472
|
+
setTurnError(null);
|
|
473
|
+
setTimedOut(false);
|
|
474
|
+
setMessages(initialRef.current ?? []);
|
|
475
|
+
agent.reset?.();
|
|
476
|
+
}, [conversationId]);
|
|
477
|
+
useEffect2(() => {
|
|
478
|
+
if (skipPersist.current) {
|
|
479
|
+
skipPersist.current = false;
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
onMessagesChange?.(messages);
|
|
483
|
+
}, [messages]);
|
|
484
|
+
const newConversation = useCallback(() => {
|
|
485
|
+
skipPersist.current = true;
|
|
486
|
+
setTurnError(null);
|
|
487
|
+
setTimedOut(false);
|
|
488
|
+
setMessages([]);
|
|
489
|
+
pending.current = false;
|
|
490
|
+
agent.reset?.();
|
|
491
|
+
}, [agent]);
|
|
492
|
+
return {
|
|
493
|
+
messages,
|
|
494
|
+
turn: agent.turn,
|
|
495
|
+
isStreaming: agent.isStreaming && !timedOut,
|
|
496
|
+
turnError,
|
|
497
|
+
send,
|
|
498
|
+
retry,
|
|
499
|
+
dismissError,
|
|
500
|
+
newConversation
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// src/agent/AgentConversationSurface.tsx
|
|
505
|
+
import { useCallback as useCallback9, useEffect as useEffect13, useRef as useRef9, useState as useState15 } from "react";
|
|
506
|
+
import { Send, Loader2 as Loader211 } from "lucide-react";
|
|
507
|
+
import { useStickToBottom } from "use-stick-to-bottom";
|
|
508
|
+
|
|
509
|
+
// src/composer/AutoResizeTextarea.tsx
|
|
510
|
+
import {
|
|
511
|
+
forwardRef,
|
|
512
|
+
useEffect as useEffect3,
|
|
513
|
+
useImperativeHandle,
|
|
514
|
+
useRef as useRef2,
|
|
515
|
+
useState as useState3
|
|
516
|
+
} from "react";
|
|
517
|
+
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
518
|
+
var AutoResizeTextarea = forwardRef(function AutoResizeTextarea2({
|
|
519
|
+
value,
|
|
520
|
+
onChange,
|
|
521
|
+
maxRows = 5,
|
|
522
|
+
showCounter = false,
|
|
523
|
+
maxLength,
|
|
524
|
+
wrapperClassName = "",
|
|
525
|
+
wrapperStyle,
|
|
526
|
+
className = "",
|
|
527
|
+
...props
|
|
528
|
+
}, ref) {
|
|
529
|
+
const textareaRef = useRef2(null);
|
|
530
|
+
useImperativeHandle(ref, () => textareaRef.current);
|
|
531
|
+
const [rows, setRows] = useState3(1);
|
|
532
|
+
useEffect3(() => {
|
|
533
|
+
if (!textareaRef.current) return;
|
|
534
|
+
const textarea = textareaRef.current;
|
|
535
|
+
textarea.rows = 1;
|
|
536
|
+
textarea.style.height = "auto";
|
|
537
|
+
const computed = window.getComputedStyle(textarea);
|
|
538
|
+
const parsed = parseFloat(computed.lineHeight);
|
|
539
|
+
const lineHeight = Number.isFinite(parsed) && parsed > 0 ? parsed : 20;
|
|
540
|
+
const newRows = Math.max(
|
|
541
|
+
1,
|
|
542
|
+
Math.min(Math.ceil(textarea.scrollHeight / lineHeight), maxRows)
|
|
543
|
+
);
|
|
544
|
+
setRows(newRows);
|
|
545
|
+
textarea.rows = newRows;
|
|
546
|
+
textarea.style.height = `${newRows * lineHeight}px`;
|
|
547
|
+
textarea.style.width = "100%";
|
|
548
|
+
}, [value, maxRows]);
|
|
549
|
+
const charCount = typeof value === "string" ? value.length : 0;
|
|
550
|
+
const isNearLimit = maxLength && charCount > maxLength * 0.9;
|
|
551
|
+
const isOverLimit = maxLength && charCount > maxLength;
|
|
552
|
+
return /* @__PURE__ */ jsxs5("div", { className: `relative ${wrapperClassName}`, style: wrapperStyle, children: [
|
|
553
|
+
/* @__PURE__ */ jsx5(
|
|
554
|
+
"textarea",
|
|
555
|
+
{
|
|
556
|
+
ref: textareaRef,
|
|
557
|
+
value,
|
|
558
|
+
onChange,
|
|
559
|
+
maxLength,
|
|
560
|
+
className: `
|
|
561
|
+
resize-none
|
|
562
|
+
${className}
|
|
563
|
+
`,
|
|
564
|
+
rows,
|
|
565
|
+
...props
|
|
566
|
+
}
|
|
567
|
+
),
|
|
568
|
+
showCounter && maxLength && /* @__PURE__ */ jsxs5("div", { className: isOverLimit ? "chat-char-counter-error" : isNearLimit ? "chat-char-counter-warning" : "chat-char-counter-ok", children: [
|
|
569
|
+
charCount,
|
|
570
|
+
"/",
|
|
571
|
+
maxLength
|
|
572
|
+
] })
|
|
573
|
+
] });
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
// src/composer/Composer.tsx
|
|
577
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
578
|
+
function Composer({
|
|
579
|
+
message,
|
|
580
|
+
loading = false,
|
|
581
|
+
placeholder = "Escribe tu mensaje...",
|
|
582
|
+
onMessageChange,
|
|
583
|
+
onSend,
|
|
584
|
+
maxRows = 5,
|
|
585
|
+
areaClassName,
|
|
586
|
+
wrapperClassName,
|
|
587
|
+
wrapperStyle,
|
|
588
|
+
textareaClassName,
|
|
589
|
+
textareaRef
|
|
590
|
+
}) {
|
|
591
|
+
const handleKeyDown = (e) => {
|
|
592
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
593
|
+
e.preventDefault();
|
|
594
|
+
onSend();
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
return /* @__PURE__ */ jsx6("div", { className: areaClassName, children: /* @__PURE__ */ jsx6(
|
|
598
|
+
AutoResizeTextarea,
|
|
599
|
+
{
|
|
600
|
+
ref: textareaRef,
|
|
601
|
+
value: message,
|
|
602
|
+
onChange: (e) => onMessageChange(e.target.value),
|
|
603
|
+
onKeyDown: handleKeyDown,
|
|
604
|
+
placeholder,
|
|
605
|
+
disabled: loading,
|
|
606
|
+
maxRows,
|
|
607
|
+
showCounter: false,
|
|
608
|
+
wrapperClassName,
|
|
609
|
+
wrapperStyle,
|
|
610
|
+
className: textareaClassName
|
|
611
|
+
}
|
|
612
|
+
) });
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// src/messages/styles.ts
|
|
616
|
+
var messageStyles = {
|
|
617
|
+
// Container
|
|
618
|
+
container: {
|
|
619
|
+
base: "space-y-0.5",
|
|
620
|
+
padding: "px-4"
|
|
621
|
+
},
|
|
622
|
+
// Message row
|
|
623
|
+
message: {
|
|
624
|
+
base: "group relative py-3 px-4 -mx-4 transition-colors duration-150",
|
|
625
|
+
user: "bg-transparent hover:bg-white/[0.02]",
|
|
626
|
+
assistant: "bg-white/[0.02] hover:bg-white/[0.04]",
|
|
627
|
+
borderRadius: "rounded-lg"
|
|
628
|
+
},
|
|
629
|
+
// Avatar
|
|
630
|
+
avatar: {
|
|
631
|
+
size: "w-6 h-6",
|
|
632
|
+
base: "rounded-md flex items-center justify-center text-[10px] font-semibold flex-shrink-0",
|
|
633
|
+
user: "bg-violet-600/80 text-white",
|
|
634
|
+
assistant: "bg-amber-500/80 text-slate-900"
|
|
635
|
+
},
|
|
636
|
+
// Meta (name + time)
|
|
637
|
+
meta: {
|
|
638
|
+
container: "flex items-baseline gap-2",
|
|
639
|
+
name: "text-[13px] font-medium text-slate-300",
|
|
640
|
+
time: "text-[11px] text-slate-500 tabular-nums"
|
|
641
|
+
},
|
|
642
|
+
// Content
|
|
643
|
+
content: {
|
|
644
|
+
base: "text-[14px] leading-relaxed",
|
|
645
|
+
user: "text-slate-200",
|
|
646
|
+
assistant: "text-slate-100",
|
|
647
|
+
indent: "pl-8"
|
|
648
|
+
// Align with avatar
|
|
649
|
+
},
|
|
650
|
+
// Actions toolbar
|
|
651
|
+
actions: {
|
|
652
|
+
container: `
|
|
653
|
+
absolute top-2 right-2
|
|
654
|
+
flex items-center gap-0.5
|
|
655
|
+
opacity-0 group-hover:opacity-100
|
|
656
|
+
transition-opacity duration-150
|
|
657
|
+
bg-slate-800/95 backdrop-blur-sm rounded-md p-0.5
|
|
658
|
+
border border-slate-700/50 shadow-lg
|
|
659
|
+
`,
|
|
660
|
+
button: {
|
|
661
|
+
base: "p-1 rounded transition-colors duration-150",
|
|
662
|
+
idle: "hover:bg-slate-700 text-slate-400 hover:text-slate-200",
|
|
663
|
+
active: "bg-emerald-500/20 text-emerald-400",
|
|
664
|
+
speaking: "bg-amber-500/20 text-amber-400"
|
|
665
|
+
},
|
|
666
|
+
icon: "w-3 h-3"
|
|
667
|
+
},
|
|
668
|
+
// Date divider
|
|
669
|
+
dateDivider: {
|
|
670
|
+
container: "my-4 flex items-center gap-3",
|
|
671
|
+
line: "flex-1 h-px bg-gradient-to-r from-transparent via-slate-700/30 to-transparent",
|
|
672
|
+
label: "px-3 py-1 text-[10px] text-slate-500 font-medium bg-slate-900/50 rounded-full"
|
|
673
|
+
},
|
|
674
|
+
// Typing indicator
|
|
675
|
+
typing: {
|
|
676
|
+
container: "flex items-center gap-2 px-4 py-2",
|
|
677
|
+
dot: "w-1.5 h-1.5 bg-amber-400/80 rounded-full",
|
|
678
|
+
animation: "animate-bounce"
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
var markdownStyles = {
|
|
682
|
+
p: "mb-3 last:mb-0",
|
|
683
|
+
strong: "font-semibold text-white",
|
|
684
|
+
em: "italic text-slate-300",
|
|
685
|
+
code: "px-1 py-0.5 bg-slate-800/80 rounded text-amber-300/90 font-mono text-[13px]",
|
|
686
|
+
pre: "my-3 p-3 bg-slate-900/80 rounded-lg border border-slate-700/30 overflow-x-auto text-[13px]",
|
|
687
|
+
ul: "my-2 ml-0.5 space-y-1.5",
|
|
688
|
+
ol: "my-2 ml-0.5 space-y-1.5 list-decimal list-inside",
|
|
689
|
+
li: "flex gap-1.5 text-slate-200",
|
|
690
|
+
bullet: "text-slate-500 select-none text-[10px] mt-1",
|
|
691
|
+
h1: "text-lg font-semibold text-white mt-4 mb-2",
|
|
692
|
+
h2: "text-base font-semibold text-white mt-3 mb-1.5",
|
|
693
|
+
h3: "text-sm font-semibold text-slate-100 mt-2 mb-1",
|
|
694
|
+
blockquote: "my-3 pl-3 border-l-2 border-slate-600/50 text-slate-400 italic text-[13px]",
|
|
695
|
+
link: "text-amber-400/90 hover:text-amber-300 underline underline-offset-2 transition-colors"
|
|
696
|
+
};
|
|
697
|
+
|
|
698
|
+
// src/messages/MessageContent.tsx
|
|
699
|
+
import { memo } from "react";
|
|
700
|
+
import ReactMarkdown from "react-markdown";
|
|
701
|
+
import remarkGfm from "remark-gfm";
|
|
702
|
+
|
|
703
|
+
// src/messages/normalizeStreamedMarkdown.ts
|
|
704
|
+
var FENCE_SPLIT = /(```[\s\S]*?(?:```|$))/;
|
|
705
|
+
var GLUED_HEADING = /([.!?:;,)\]"'»…])(#{1,6} )/g;
|
|
706
|
+
function normalizeStreamedMarkdown(content) {
|
|
707
|
+
if (!content.includes("#")) return content;
|
|
708
|
+
return content.split(FENCE_SPLIT).map(
|
|
709
|
+
(segment, i) => i % 2 === 1 ? segment : segment.replace(GLUED_HEADING, "$1\n\n$2")
|
|
710
|
+
).join("");
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// src/messages/CollapsibleText.tsx
|
|
714
|
+
import { useEffect as useEffect4, useId, useRef as useRef3, useState as useState4 } from "react";
|
|
715
|
+
import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
716
|
+
var OVERFLOW_TOLERANCE_PX = 16;
|
|
717
|
+
function CollapsibleText({
|
|
718
|
+
children,
|
|
719
|
+
maxHeight = 264,
|
|
720
|
+
fadeHeight = 48,
|
|
721
|
+
showMoreLabel = "Mostrar m\xE1s",
|
|
722
|
+
showLessLabel = "Mostrar menos",
|
|
723
|
+
className,
|
|
724
|
+
toggleClassName
|
|
725
|
+
}) {
|
|
726
|
+
const contentId = useId();
|
|
727
|
+
const contentRef = useRef3(null);
|
|
728
|
+
const [expanded, setExpanded] = useState4(false);
|
|
729
|
+
const [overflowing, setOverflowing] = useState4(false);
|
|
730
|
+
useEffect4(() => {
|
|
731
|
+
const el = contentRef.current;
|
|
732
|
+
if (!el) return;
|
|
733
|
+
const measure = () => setOverflowing(el.scrollHeight > maxHeight + OVERFLOW_TOLERANCE_PX);
|
|
734
|
+
measure();
|
|
735
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
736
|
+
const ro = new ResizeObserver(measure);
|
|
737
|
+
ro.observe(el);
|
|
738
|
+
return () => ro.disconnect();
|
|
739
|
+
}, [maxHeight]);
|
|
740
|
+
const clamped = overflowing && !expanded;
|
|
741
|
+
const mask = `linear-gradient(rgb(0,0,0) calc(100% - ${fadeHeight}px), transparent)`;
|
|
742
|
+
return /* @__PURE__ */ jsxs6("div", { className, children: [
|
|
743
|
+
/* @__PURE__ */ jsx7(
|
|
744
|
+
"div",
|
|
745
|
+
{
|
|
746
|
+
id: contentId,
|
|
747
|
+
ref: contentRef,
|
|
748
|
+
style: clamped ? {
|
|
749
|
+
maxHeight,
|
|
750
|
+
overflow: "hidden",
|
|
751
|
+
maskImage: mask,
|
|
752
|
+
WebkitMaskImage: mask
|
|
753
|
+
} : void 0,
|
|
754
|
+
children
|
|
755
|
+
}
|
|
756
|
+
),
|
|
757
|
+
overflowing && /* @__PURE__ */ jsx7(
|
|
758
|
+
"button",
|
|
759
|
+
{
|
|
760
|
+
type: "button",
|
|
761
|
+
"aria-expanded": expanded,
|
|
762
|
+
"aria-controls": contentId,
|
|
763
|
+
onClick: () => setExpanded((e) => !e),
|
|
764
|
+
className: toggleClassName,
|
|
765
|
+
style: toggleClassName ? void 0 : {
|
|
766
|
+
marginTop: "0.25rem",
|
|
767
|
+
padding: 0,
|
|
768
|
+
border: "none",
|
|
769
|
+
background: "transparent",
|
|
770
|
+
color: "#94a3b8",
|
|
771
|
+
fontSize: "0.8rem",
|
|
772
|
+
cursor: "pointer",
|
|
773
|
+
textDecoration: "underline",
|
|
774
|
+
textUnderlineOffset: 2
|
|
775
|
+
},
|
|
776
|
+
children: expanded ? showLessLabel : showMoreLabel
|
|
777
|
+
}
|
|
778
|
+
)
|
|
779
|
+
] });
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// src/messages/MessageContent.tsx
|
|
783
|
+
import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
784
|
+
var mdComponents = {
|
|
785
|
+
p: ({ children }) => /* @__PURE__ */ jsx8("p", { className: markdownStyles.p, children }),
|
|
786
|
+
strong: ({ children }) => /* @__PURE__ */ jsx8("strong", { className: markdownStyles.strong, children }),
|
|
787
|
+
em: ({ children }) => /* @__PURE__ */ jsx8("em", { className: markdownStyles.em, children }),
|
|
788
|
+
code: ({ children }) => /* @__PURE__ */ jsx8("code", { className: markdownStyles.code, children }),
|
|
789
|
+
pre: ({ children }) => /* @__PURE__ */ jsx8("pre", { className: markdownStyles.pre, children }),
|
|
790
|
+
ul: ({ children }) => /* @__PURE__ */ jsx8("ul", { className: markdownStyles.ul, children }),
|
|
791
|
+
ol: ({ children }) => /* @__PURE__ */ jsx8("ol", { className: markdownStyles.ol, children }),
|
|
792
|
+
li: ({ children }) => /* @__PURE__ */ jsxs7("li", { className: markdownStyles.li, children: [
|
|
793
|
+
/* @__PURE__ */ jsx8("span", { className: markdownStyles.bullet, children: "\u2022" }),
|
|
794
|
+
/* @__PURE__ */ jsx8("span", { className: "flex-1", children })
|
|
795
|
+
] }),
|
|
796
|
+
h1: ({ children }) => /* @__PURE__ */ jsx8("h1", { className: markdownStyles.h1, children }),
|
|
797
|
+
h2: ({ children }) => /* @__PURE__ */ jsx8("h2", { className: markdownStyles.h2, children }),
|
|
798
|
+
h3: ({ children }) => /* @__PURE__ */ jsx8("h3", { className: markdownStyles.h3, children }),
|
|
799
|
+
blockquote: ({ children }) => /* @__PURE__ */ jsx8("blockquote", { className: markdownStyles.blockquote, children }),
|
|
800
|
+
a: ({ href, children }) => /* @__PURE__ */ jsx8("a", { href, className: markdownStyles.link, target: "_blank", rel: "noopener noreferrer", children })
|
|
801
|
+
};
|
|
802
|
+
function defaultRenderMarkdown(content) {
|
|
803
|
+
return /* @__PURE__ */ jsx8(ReactMarkdown, { remarkPlugins: [remarkGfm], components: mdComponents, children: normalizeStreamedMarkdown(content) });
|
|
804
|
+
}
|
|
805
|
+
var MessageContent = memo(function MessageContent2({
|
|
806
|
+
isUser,
|
|
807
|
+
content,
|
|
808
|
+
isStreaming = false,
|
|
809
|
+
renderMarkdown = defaultRenderMarkdown,
|
|
810
|
+
collapsible = false,
|
|
811
|
+
collapsedMaxHeight,
|
|
812
|
+
showMoreLabel,
|
|
813
|
+
showLessLabel,
|
|
814
|
+
collapseToggleClassName
|
|
815
|
+
}) {
|
|
816
|
+
const { content: styles } = messageStyles;
|
|
817
|
+
const body = isUser ? (
|
|
818
|
+
// User: plain text, preserve whitespace
|
|
819
|
+
/* @__PURE__ */ jsx8("p", { className: "whitespace-pre-wrap", children: content })
|
|
820
|
+
) : (
|
|
821
|
+
// Assistant: markdown (overridable)
|
|
822
|
+
renderMarkdown(content)
|
|
823
|
+
);
|
|
824
|
+
return /* @__PURE__ */ jsxs7(
|
|
825
|
+
"div",
|
|
826
|
+
{
|
|
827
|
+
className: `${styles.base} ${isUser ? styles.user : styles.assistant} ${styles.indent}`,
|
|
828
|
+
children: [
|
|
829
|
+
collapsible && !isStreaming ? /* @__PURE__ */ jsx8(
|
|
830
|
+
CollapsibleText,
|
|
831
|
+
{
|
|
832
|
+
maxHeight: collapsedMaxHeight,
|
|
833
|
+
showMoreLabel,
|
|
834
|
+
showLessLabel,
|
|
835
|
+
toggleClassName: collapseToggleClassName,
|
|
836
|
+
children: body
|
|
837
|
+
}
|
|
838
|
+
) : body,
|
|
839
|
+
isStreaming && /* @__PURE__ */ jsx8("span", { className: "inline-block w-1.5 h-4 bg-amber-400/80 ml-0.5 animate-pulse rounded-sm" })
|
|
840
|
+
]
|
|
841
|
+
}
|
|
842
|
+
);
|
|
843
|
+
});
|
|
844
|
+
|
|
845
|
+
// src/messages/CopyButton.tsx
|
|
846
|
+
import { memo as memo2, useCallback as useCallback2, useState as useState5 } from "react";
|
|
847
|
+
import { Copy, Check } from "lucide-react";
|
|
848
|
+
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
849
|
+
var CopyButton = memo2(function CopyButton2({
|
|
850
|
+
content,
|
|
851
|
+
onError,
|
|
852
|
+
className,
|
|
853
|
+
idleClassName,
|
|
854
|
+
activeClassName,
|
|
855
|
+
iconClassName,
|
|
856
|
+
copyLabel = "Copiar",
|
|
857
|
+
copiedLabel = "Copiado",
|
|
858
|
+
resetMs = 2e3
|
|
859
|
+
}) {
|
|
860
|
+
const [copied, setCopied] = useState5(false);
|
|
861
|
+
const { actions } = messageStyles;
|
|
862
|
+
const base = className ?? actions.button.base;
|
|
863
|
+
const idle = idleClassName ?? actions.button.idle;
|
|
864
|
+
const active = activeClassName ?? actions.button.active;
|
|
865
|
+
const icon = iconClassName ?? actions.icon;
|
|
866
|
+
const handleCopy = useCallback2(async () => {
|
|
867
|
+
try {
|
|
868
|
+
await navigator.clipboard.writeText(content);
|
|
869
|
+
setCopied(true);
|
|
870
|
+
setTimeout(() => setCopied(false), resetMs);
|
|
871
|
+
} catch (err) {
|
|
872
|
+
onError?.(err);
|
|
873
|
+
}
|
|
874
|
+
}, [content, onError, resetMs]);
|
|
875
|
+
return /* @__PURE__ */ jsx9(
|
|
876
|
+
"button",
|
|
877
|
+
{
|
|
878
|
+
onClick: handleCopy,
|
|
879
|
+
className: `${base} ${copied ? active : idle}`,
|
|
880
|
+
title: copied ? copiedLabel : copyLabel,
|
|
881
|
+
"aria-label": copied ? copiedLabel : `${copyLabel} mensaje`,
|
|
882
|
+
children: copied ? /* @__PURE__ */ jsx9(Check, { className: icon }) : /* @__PURE__ */ jsx9(Copy, { className: icon })
|
|
883
|
+
}
|
|
884
|
+
);
|
|
885
|
+
});
|
|
886
|
+
|
|
887
|
+
// src/messages/MessageBubble.tsx
|
|
888
|
+
import { memo as memo3 } from "react";
|
|
889
|
+
import { jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
890
|
+
var MessageBubble = memo3(function MessageBubble2({
|
|
891
|
+
role,
|
|
892
|
+
children,
|
|
893
|
+
header,
|
|
894
|
+
reasoning,
|
|
895
|
+
badge,
|
|
896
|
+
actions,
|
|
897
|
+
className,
|
|
898
|
+
ariaLabel
|
|
899
|
+
}) {
|
|
900
|
+
const { message: styles } = messageStyles;
|
|
901
|
+
const isUser = role === "user";
|
|
902
|
+
return /* @__PURE__ */ jsxs8(
|
|
903
|
+
"article",
|
|
904
|
+
{
|
|
905
|
+
className: `fi-msg-appear ${styles.base} ${styles.borderRadius} ${isUser ? styles.user : styles.assistant} ${className || ""}`,
|
|
906
|
+
role: "article",
|
|
907
|
+
"aria-label": ariaLabel,
|
|
908
|
+
children: [
|
|
909
|
+
header && /* @__PURE__ */ jsx10("div", { className: "flex items-center gap-2 mb-1", children: header }),
|
|
910
|
+
reasoning && /* @__PURE__ */ jsx10("div", { className: "mt-3 mb-3", children: reasoning }),
|
|
911
|
+
children,
|
|
912
|
+
badge && /* @__PURE__ */ jsx10("div", { className: "mt-2", children: badge }),
|
|
913
|
+
actions
|
|
914
|
+
]
|
|
915
|
+
}
|
|
916
|
+
);
|
|
917
|
+
});
|
|
918
|
+
|
|
919
|
+
// src/messages/MessageList.tsx
|
|
920
|
+
import { jsx as jsx11, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
921
|
+
|
|
922
|
+
// src/voice/recording/RecordingButton.tsx
|
|
923
|
+
import { forwardRef as forwardRef2 } from "react";
|
|
924
|
+
import { Loader2 } from "lucide-react";
|
|
925
|
+
|
|
926
|
+
// src/voice/recording/types.ts
|
|
927
|
+
var BUTTON_SIZES = {
|
|
928
|
+
sm: {
|
|
929
|
+
button: "rec-btn-sm",
|
|
930
|
+
icon: "rec-icon-sm",
|
|
931
|
+
ring: "rec-ring-sm"
|
|
932
|
+
},
|
|
933
|
+
md: {
|
|
934
|
+
button: "rec-btn-md",
|
|
935
|
+
icon: "rec-icon-md",
|
|
936
|
+
ring: "rec-ring-md"
|
|
937
|
+
},
|
|
938
|
+
lg: {
|
|
939
|
+
button: "rec-btn-lg",
|
|
940
|
+
icon: "rec-icon-lg",
|
|
941
|
+
ring: "rec-ring-lg"
|
|
942
|
+
},
|
|
943
|
+
xl: {
|
|
944
|
+
button: "rec-btn-xl",
|
|
945
|
+
icon: "rec-icon-xl",
|
|
946
|
+
ring: "rec-ring-xl"
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
|
|
950
|
+
// src/voice/recording/RecordingButton.tsx
|
|
951
|
+
import { jsx as jsx12 } from "react/jsx-runtime";
|
|
952
|
+
var RecordingButton = forwardRef2(
|
|
953
|
+
function RecordingButton2({
|
|
954
|
+
size = "md",
|
|
955
|
+
bgColor,
|
|
956
|
+
icon: Icon,
|
|
957
|
+
iconSpin = false,
|
|
958
|
+
iconColor = "rec-icon-white",
|
|
959
|
+
disabled = false,
|
|
960
|
+
onClick,
|
|
961
|
+
ariaLabel,
|
|
962
|
+
className = "",
|
|
963
|
+
borderStyle = "",
|
|
964
|
+
animate = ""
|
|
965
|
+
}, ref) {
|
|
966
|
+
const sizeConfig = BUTTON_SIZES[size];
|
|
967
|
+
const DisplayIcon = iconSpin ? Loader2 : Icon;
|
|
968
|
+
return /* @__PURE__ */ jsx12(
|
|
969
|
+
"button",
|
|
970
|
+
{
|
|
971
|
+
ref,
|
|
972
|
+
onClick,
|
|
973
|
+
disabled,
|
|
974
|
+
"aria-label": ariaLabel,
|
|
975
|
+
className: `fi-recording-btn-base ${sizeConfig.button} ${bgColor} ${borderStyle} ${animate} ${disabled ? "rec-btn-disabled" : "rec-btn-enabled"} ${className}`,
|
|
976
|
+
children: /* @__PURE__ */ jsx12(
|
|
977
|
+
DisplayIcon,
|
|
978
|
+
{
|
|
979
|
+
className: `${sizeConfig.icon} ${iconColor} ${iconSpin ? "rec-icon-spin" : ""}`
|
|
980
|
+
}
|
|
981
|
+
)
|
|
982
|
+
}
|
|
983
|
+
);
|
|
984
|
+
}
|
|
985
|
+
);
|
|
986
|
+
|
|
987
|
+
// src/voice/recording/PulseRings.tsx
|
|
988
|
+
import { motion } from "framer-motion";
|
|
989
|
+
import { Fragment as Fragment2, jsx as jsx13, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
990
|
+
|
|
991
|
+
// src/voice/recording/RecordingTimer.tsx
|
|
992
|
+
import { motion as motion2 } from "framer-motion";
|
|
993
|
+
import { jsx as jsx14, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
994
|
+
|
|
995
|
+
// src/voice/recording/StatusText.tsx
|
|
996
|
+
import { Loader2 as Loader22 } from "lucide-react";
|
|
997
|
+
import { motion as motion3 } from "framer-motion";
|
|
998
|
+
import { jsx as jsx15, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
999
|
+
|
|
1000
|
+
// src/voice/VoiceMicButton.tsx
|
|
1001
|
+
import { Mic, Square, Loader2 as Loader23 } from "lucide-react";
|
|
1002
|
+
import { motion as motion4 } from "framer-motion";
|
|
1003
|
+
import { jsx as jsx16, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
1004
|
+
|
|
1005
|
+
// src/voice/SpeakButton.tsx
|
|
1006
|
+
import { Volume2, Loader2 as Loader24, Play } from "lucide-react";
|
|
1007
|
+
import { jsx as jsx17 } from "react/jsx-runtime";
|
|
1008
|
+
|
|
1009
|
+
// src/voice/useAudioPlayer.ts
|
|
1010
|
+
import { useEffect as useEffect5, useMemo, useRef as useRef4, useSyncExternalStore } from "react";
|
|
1011
|
+
|
|
1012
|
+
// src/voice/AudioPlayer.tsx
|
|
1013
|
+
import { Play as Play2, Pause, Square as Square2, Loader2 as Loader25, AlertCircle } from "lucide-react";
|
|
1014
|
+
import { useEffect as useEffect6 } from "react";
|
|
1015
|
+
import { jsx as jsx18, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
1016
|
+
|
|
1017
|
+
// src/voice/RichAudioPlayer.tsx
|
|
1018
|
+
import {
|
|
1019
|
+
Play as Play3,
|
|
1020
|
+
Pause as Pause2,
|
|
1021
|
+
Square as Square3,
|
|
1022
|
+
Loader2 as Loader26,
|
|
1023
|
+
AlertCircle as AlertCircle2,
|
|
1024
|
+
RotateCcw,
|
|
1025
|
+
RotateCw
|
|
1026
|
+
} from "lucide-react";
|
|
1027
|
+
import { useEffect as useEffect7 } from "react";
|
|
1028
|
+
import { jsx as jsx19, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
1029
|
+
|
|
1030
|
+
// src/voice/AudioVisualizer.tsx
|
|
1031
|
+
import { jsx as jsx20 } from "react/jsx-runtime";
|
|
1032
|
+
var MIN_BAR_PCT = 4;
|
|
1033
|
+
function normalizeLevels(levels) {
|
|
1034
|
+
return levels.map(
|
|
1035
|
+
(v) => !Number.isFinite(v) ? 0 : v < 0 ? 0 : v > 1 ? 1 : v
|
|
1036
|
+
);
|
|
1037
|
+
}
|
|
1038
|
+
function resampleLevels(levels, count) {
|
|
1039
|
+
if (count <= 0) return [];
|
|
1040
|
+
if (levels.length === 0) return new Array(count).fill(0);
|
|
1041
|
+
if (levels.length === count) return levels.slice();
|
|
1042
|
+
const out = [];
|
|
1043
|
+
for (let i = 0; i < count; i++) {
|
|
1044
|
+
const idx = Math.min(
|
|
1045
|
+
levels.length - 1,
|
|
1046
|
+
Math.floor(i / count * levels.length)
|
|
1047
|
+
);
|
|
1048
|
+
out.push(levels[idx]);
|
|
1049
|
+
}
|
|
1050
|
+
return out;
|
|
1051
|
+
}
|
|
1052
|
+
function AudioVisualizer({
|
|
1053
|
+
levels,
|
|
1054
|
+
variant = "bars",
|
|
1055
|
+
active = true,
|
|
1056
|
+
barCount,
|
|
1057
|
+
label = "Visualizador de nivel de audio",
|
|
1058
|
+
className,
|
|
1059
|
+
barClassName,
|
|
1060
|
+
color
|
|
1061
|
+
}) {
|
|
1062
|
+
const normalized = normalizeLevels(levels);
|
|
1063
|
+
if (variant === "pulse") {
|
|
1064
|
+
const peak = active && normalized.length ? Math.max(...normalized) : 0;
|
|
1065
|
+
const scale = 1 + peak;
|
|
1066
|
+
return /* @__PURE__ */ jsx20(
|
|
1067
|
+
"div",
|
|
1068
|
+
{
|
|
1069
|
+
role: "img",
|
|
1070
|
+
"aria-label": label,
|
|
1071
|
+
className,
|
|
1072
|
+
"data-fi-audio-visualizer": "pulse",
|
|
1073
|
+
"data-active": active ? "" : void 0,
|
|
1074
|
+
children: /* @__PURE__ */ jsx20(
|
|
1075
|
+
"span",
|
|
1076
|
+
{
|
|
1077
|
+
"data-fi-pulse-core": "",
|
|
1078
|
+
style: {
|
|
1079
|
+
display: "inline-block",
|
|
1080
|
+
transform: `scale(${scale})`,
|
|
1081
|
+
borderColor: color
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
)
|
|
1085
|
+
}
|
|
1086
|
+
);
|
|
1087
|
+
}
|
|
1088
|
+
const count = barCount && barCount > 0 ? barCount : normalized.length;
|
|
1089
|
+
const bars = resampleLevels(normalized, count);
|
|
1090
|
+
return /* @__PURE__ */ jsx20(
|
|
1091
|
+
"div",
|
|
1092
|
+
{
|
|
1093
|
+
role: "img",
|
|
1094
|
+
"aria-label": label,
|
|
1095
|
+
className,
|
|
1096
|
+
"data-fi-audio-visualizer": "bars",
|
|
1097
|
+
"data-active": active ? "" : void 0,
|
|
1098
|
+
style: { display: "inline-flex", alignItems: "flex-end" },
|
|
1099
|
+
children: bars.map((level, i) => {
|
|
1100
|
+
const pct = active ? Math.max(MIN_BAR_PCT, level * 100) : MIN_BAR_PCT;
|
|
1101
|
+
return /* @__PURE__ */ jsx20(
|
|
1102
|
+
"span",
|
|
1103
|
+
{
|
|
1104
|
+
"data-fi-audio-bar": "",
|
|
1105
|
+
className: barClassName,
|
|
1106
|
+
style: { height: `${pct}%`, backgroundColor: color }
|
|
1107
|
+
},
|
|
1108
|
+
i
|
|
1109
|
+
);
|
|
1110
|
+
})
|
|
1111
|
+
}
|
|
1112
|
+
);
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
// src/voice/ComposerMicSlot.tsx
|
|
1116
|
+
import { Mic as Mic2, MicOff, Square as Square4, Loader2 as Loader27 } from "lucide-react";
|
|
1117
|
+
import { jsx as jsx21 } from "react/jsx-runtime";
|
|
1118
|
+
var ICON = "w-4 h-4";
|
|
1119
|
+
var BTN = "p-2 disabled:opacity-40";
|
|
1120
|
+
function ComposerMicSlot({
|
|
1121
|
+
available = false,
|
|
1122
|
+
recording = false,
|
|
1123
|
+
busy = false,
|
|
1124
|
+
onStart,
|
|
1125
|
+
onStop,
|
|
1126
|
+
unavailableLabel = "Dictado por voz no disponible todav\xEDa",
|
|
1127
|
+
startLabel = "Iniciar dictado por voz",
|
|
1128
|
+
stopLabel = "Detener dictado por voz",
|
|
1129
|
+
busyLabel = "Transcribiendo\u2026",
|
|
1130
|
+
className,
|
|
1131
|
+
buttonClassName,
|
|
1132
|
+
iconClassName
|
|
1133
|
+
}) {
|
|
1134
|
+
const btnClass = buttonClassName ?? BTN;
|
|
1135
|
+
const iconClass = iconClassName ?? ICON;
|
|
1136
|
+
const disabled = !available || busy;
|
|
1137
|
+
const label = !available ? unavailableLabel : busy ? busyLabel : recording ? stopLabel : startLabel;
|
|
1138
|
+
const handleClick = () => {
|
|
1139
|
+
if (disabled) return;
|
|
1140
|
+
if (recording) onStop?.();
|
|
1141
|
+
else onStart?.();
|
|
1142
|
+
};
|
|
1143
|
+
const Icon = !available ? MicOff : busy ? Loader27 : recording ? Square4 : Mic2;
|
|
1144
|
+
return /* @__PURE__ */ jsx21("div", { className, "data-fi-mic-slot": "", "data-available": available ? "" : void 0, children: /* @__PURE__ */ jsx21(
|
|
1145
|
+
"button",
|
|
1146
|
+
{
|
|
1147
|
+
type: "button",
|
|
1148
|
+
onClick: handleClick,
|
|
1149
|
+
disabled,
|
|
1150
|
+
"aria-disabled": disabled,
|
|
1151
|
+
"aria-pressed": available ? recording : void 0,
|
|
1152
|
+
"aria-label": label,
|
|
1153
|
+
title: !available ? unavailableLabel : void 0,
|
|
1154
|
+
className: btnClass,
|
|
1155
|
+
children: /* @__PURE__ */ jsx21(
|
|
1156
|
+
Icon,
|
|
1157
|
+
{
|
|
1158
|
+
className: busy ? `${iconClass} animate-spin` : iconClass,
|
|
1159
|
+
"aria-hidden": true
|
|
1160
|
+
}
|
|
1161
|
+
)
|
|
1162
|
+
}
|
|
1163
|
+
) });
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
// src/voice/useVoice.ts
|
|
1167
|
+
import { useCallback as useCallback3, useRef as useRef5, useState as useState6 } from "react";
|
|
1168
|
+
|
|
1169
|
+
// src/voice/useDictation.ts
|
|
1170
|
+
import { useCallback as useCallback5, useState as useState9 } from "react";
|
|
1171
|
+
|
|
1172
|
+
// src/voice/useRecorder.ts
|
|
1173
|
+
import { useState as useState7, useRef as useRef6, useCallback as useCallback4 } from "react";
|
|
1174
|
+
|
|
1175
|
+
// src/voice/makeRecorder.ts
|
|
1176
|
+
async function makeRecorder(stream, onChunk, opts) {
|
|
1177
|
+
const timeSlice = opts?.timeSlice;
|
|
1178
|
+
const channels = opts?.channels ?? 1;
|
|
1179
|
+
const mod = await import("recordrtc");
|
|
1180
|
+
const RecordRTC = mod.default ?? mod;
|
|
1181
|
+
if (!RecordRTC) {
|
|
1182
|
+
throw new Error("[makeRecorder] RecordRTC library not available");
|
|
1183
|
+
}
|
|
1184
|
+
const mimeType = "audio/wav";
|
|
1185
|
+
let currentRecorder = null;
|
|
1186
|
+
let loopTimer = null;
|
|
1187
|
+
let isActive = false;
|
|
1188
|
+
const createRecorder = () => {
|
|
1189
|
+
return new RecordRTC(stream, {
|
|
1190
|
+
type: "audio",
|
|
1191
|
+
recorderType: RecordRTC.StereoAudioRecorder,
|
|
1192
|
+
mimeType,
|
|
1193
|
+
numberOfAudioChannels: channels,
|
|
1194
|
+
desiredSampRate: opts?.sampleRate ?? 16e3,
|
|
1195
|
+
disableLogs: true
|
|
1196
|
+
});
|
|
1197
|
+
};
|
|
1198
|
+
const startLoop = async () => {
|
|
1199
|
+
if (!isActive) return;
|
|
1200
|
+
currentRecorder = createRecorder();
|
|
1201
|
+
currentRecorder.startRecording();
|
|
1202
|
+
if (timeSlice && timeSlice > 0) {
|
|
1203
|
+
loopTimer = setTimeout(async () => {
|
|
1204
|
+
if (!currentRecorder || !isActive) return;
|
|
1205
|
+
currentRecorder.stopRecording(() => {
|
|
1206
|
+
if (!isActive) return;
|
|
1207
|
+
const blob = currentRecorder.getBlob();
|
|
1208
|
+
if (blob && blob.size > 0) {
|
|
1209
|
+
onChunk(blob);
|
|
1210
|
+
}
|
|
1211
|
+
if (isActive) {
|
|
1212
|
+
startLoop();
|
|
1213
|
+
}
|
|
1214
|
+
});
|
|
1215
|
+
}, timeSlice);
|
|
1216
|
+
}
|
|
1217
|
+
};
|
|
1218
|
+
return {
|
|
1219
|
+
start: () => {
|
|
1220
|
+
isActive = true;
|
|
1221
|
+
startLoop();
|
|
1222
|
+
},
|
|
1223
|
+
stop: () => new Promise((resolve) => {
|
|
1224
|
+
isActive = false;
|
|
1225
|
+
if (loopTimer) {
|
|
1226
|
+
clearTimeout(loopTimer);
|
|
1227
|
+
loopTimer = null;
|
|
1228
|
+
}
|
|
1229
|
+
if (currentRecorder) {
|
|
1230
|
+
currentRecorder.stopRecording(() => {
|
|
1231
|
+
const finalBlob = currentRecorder.getBlob();
|
|
1232
|
+
resolve(finalBlob);
|
|
1233
|
+
});
|
|
1234
|
+
} else {
|
|
1235
|
+
resolve(new Blob([], { type: mimeType }));
|
|
1236
|
+
}
|
|
1237
|
+
}),
|
|
1238
|
+
kind: "recordrtc"
|
|
1239
|
+
};
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
// src/voice/useRecorder.ts
|
|
1243
|
+
var log = {
|
|
1244
|
+
error: (_m, _meta) => {
|
|
1245
|
+
void _m;
|
|
1246
|
+
void _meta;
|
|
1247
|
+
},
|
|
1248
|
+
warn: (_m, _meta) => {
|
|
1249
|
+
void _m;
|
|
1250
|
+
void _meta;
|
|
1251
|
+
}
|
|
1252
|
+
};
|
|
1253
|
+
function useRecorder(config) {
|
|
1254
|
+
const {
|
|
1255
|
+
onChunk,
|
|
1256
|
+
onError,
|
|
1257
|
+
timeSlice = 3e3,
|
|
1258
|
+
sampleRate = 16e3,
|
|
1259
|
+
channels = 1,
|
|
1260
|
+
externalStream = null,
|
|
1261
|
+
deviceId = null
|
|
1262
|
+
} = config;
|
|
1263
|
+
const [isRecording, setIsRecording] = useState7(false);
|
|
1264
|
+
const [recordingTime, setRecordingTime] = useState7(0);
|
|
1265
|
+
const [fullAudioBlob, setFullAudioBlob] = useState7(null);
|
|
1266
|
+
const [fullAudioUrl, setFullAudioUrl] = useState7(null);
|
|
1267
|
+
const [currentStream, setCurrentStream] = useState7(null);
|
|
1268
|
+
const recorderRef = useRef6(null);
|
|
1269
|
+
const continuousRecorderRef = useRef6(null);
|
|
1270
|
+
const currentStreamRef = useRef6(null);
|
|
1271
|
+
const recordingTimerRef = useRef6(null);
|
|
1272
|
+
const fullAudioUrlRef = useRef6(null);
|
|
1273
|
+
const chunkNumberRef = useRef6(0);
|
|
1274
|
+
const startRecording = useCallback4(async () => {
|
|
1275
|
+
try {
|
|
1276
|
+
chunkNumberRef.current = 0;
|
|
1277
|
+
setRecordingTime(0);
|
|
1278
|
+
setFullAudioBlob(null);
|
|
1279
|
+
if (fullAudioUrlRef.current) {
|
|
1280
|
+
URL.revokeObjectURL(fullAudioUrlRef.current);
|
|
1281
|
+
fullAudioUrlRef.current = null;
|
|
1282
|
+
setFullAudioUrl(null);
|
|
1283
|
+
}
|
|
1284
|
+
let stream;
|
|
1285
|
+
if (externalStream) {
|
|
1286
|
+
stream = externalStream;
|
|
1287
|
+
} else {
|
|
1288
|
+
try {
|
|
1289
|
+
const timeoutMs = 15e3;
|
|
1290
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
1291
|
+
setTimeout(() => {
|
|
1292
|
+
reject(new Error(
|
|
1293
|
+
"Microphone permission timeout (15s). Check: 1) macOS System Preferences \u2192 Privacy \u2192 Microphone has your browser enabled, 2) Restart browser after granting permission"
|
|
1294
|
+
));
|
|
1295
|
+
}, timeoutMs);
|
|
1296
|
+
});
|
|
1297
|
+
const audioConstraints = deviceId ? { deviceId: { exact: deviceId } } : true;
|
|
1298
|
+
stream = await Promise.race([
|
|
1299
|
+
navigator.mediaDevices.getUserMedia({ audio: audioConstraints }),
|
|
1300
|
+
timeoutPromise
|
|
1301
|
+
]);
|
|
1302
|
+
} catch (micError) {
|
|
1303
|
+
log.error("Microphone access failed", { error: String(micError) });
|
|
1304
|
+
throw micError;
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
currentStreamRef.current = stream;
|
|
1308
|
+
setCurrentStream(stream);
|
|
1309
|
+
const chunkedRecorder = await makeRecorder(
|
|
1310
|
+
stream,
|
|
1311
|
+
async (blob) => {
|
|
1312
|
+
const chunkNumber = chunkNumberRef.current++;
|
|
1313
|
+
await onChunk(blob, chunkNumber);
|
|
1314
|
+
},
|
|
1315
|
+
{
|
|
1316
|
+
timeSlice,
|
|
1317
|
+
sampleRate,
|
|
1318
|
+
channels
|
|
1319
|
+
}
|
|
1320
|
+
);
|
|
1321
|
+
recorderRef.current = chunkedRecorder;
|
|
1322
|
+
chunkedRecorder.start();
|
|
1323
|
+
const continuousRecorder = await makeRecorder(
|
|
1324
|
+
stream,
|
|
1325
|
+
() => {
|
|
1326
|
+
},
|
|
1327
|
+
// Empty callback - blob comes from .stop() return value
|
|
1328
|
+
{
|
|
1329
|
+
// NO timeSlice = records continuously until stop()
|
|
1330
|
+
sampleRate,
|
|
1331
|
+
channels
|
|
1332
|
+
}
|
|
1333
|
+
);
|
|
1334
|
+
continuousRecorderRef.current = continuousRecorder;
|
|
1335
|
+
continuousRecorder.start();
|
|
1336
|
+
setIsRecording(true);
|
|
1337
|
+
recordingTimerRef.current = setInterval(() => {
|
|
1338
|
+
setRecordingTime((prev) => prev + 1);
|
|
1339
|
+
}, 1e3);
|
|
1340
|
+
} catch (err) {
|
|
1341
|
+
const errorMessage = err instanceof Error ? err.message : "No se pudo acceder al micr\xF3fono. Por favor, verifica los permisos.";
|
|
1342
|
+
log.error("Start failed", { error: String(err) });
|
|
1343
|
+
if (onError) {
|
|
1344
|
+
onError(errorMessage);
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
}, [onChunk, onError, timeSlice, sampleRate, channels, externalStream, deviceId]);
|
|
1348
|
+
const stopRecording = useCallback4(async () => {
|
|
1349
|
+
try {
|
|
1350
|
+
if (recordingTimerRef.current) {
|
|
1351
|
+
clearInterval(recordingTimerRef.current);
|
|
1352
|
+
recordingTimerRef.current = null;
|
|
1353
|
+
}
|
|
1354
|
+
setIsRecording(false);
|
|
1355
|
+
if (currentStreamRef.current) {
|
|
1356
|
+
currentStreamRef.current.getTracks().forEach((track) => {
|
|
1357
|
+
track.stop();
|
|
1358
|
+
});
|
|
1359
|
+
currentStreamRef.current = null;
|
|
1360
|
+
setCurrentStream(null);
|
|
1361
|
+
}
|
|
1362
|
+
let fullBlob = null;
|
|
1363
|
+
if (continuousRecorderRef.current) {
|
|
1364
|
+
try {
|
|
1365
|
+
fullBlob = await continuousRecorderRef.current.stop();
|
|
1366
|
+
if (fullBlob && fullBlob.size > 0) {
|
|
1367
|
+
if (fullAudioUrlRef.current) {
|
|
1368
|
+
URL.revokeObjectURL(fullAudioUrlRef.current);
|
|
1369
|
+
}
|
|
1370
|
+
const audioUrl = URL.createObjectURL(fullBlob);
|
|
1371
|
+
fullAudioUrlRef.current = audioUrl;
|
|
1372
|
+
setFullAudioUrl(audioUrl);
|
|
1373
|
+
setFullAudioBlob(fullBlob);
|
|
1374
|
+
}
|
|
1375
|
+
} catch (err) {
|
|
1376
|
+
log.warn("Continuous recorder stop error (non-critical)", { error: String(err) });
|
|
1377
|
+
}
|
|
1378
|
+
continuousRecorderRef.current = null;
|
|
1379
|
+
}
|
|
1380
|
+
if (recorderRef.current) {
|
|
1381
|
+
try {
|
|
1382
|
+
const lastChunk = await recorderRef.current.stop();
|
|
1383
|
+
if (lastChunk && lastChunk.size > 0) {
|
|
1384
|
+
const finalChunkNumber = chunkNumberRef.current++;
|
|
1385
|
+
try {
|
|
1386
|
+
const result = onChunk(lastChunk, finalChunkNumber);
|
|
1387
|
+
if (result instanceof Promise) {
|
|
1388
|
+
result.catch((err) => {
|
|
1389
|
+
log.error("Final chunk processing failed", { error: String(err) });
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
} catch (err) {
|
|
1393
|
+
log.error("Final chunk processing failed", { error: String(err) });
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
} catch (err) {
|
|
1397
|
+
log.warn("Chunked recorder stop error (non-critical)", { error: String(err) });
|
|
1398
|
+
}
|
|
1399
|
+
recorderRef.current = null;
|
|
1400
|
+
}
|
|
1401
|
+
return fullBlob;
|
|
1402
|
+
} catch (err) {
|
|
1403
|
+
log.error("Stop failed", { error: String(err) });
|
|
1404
|
+
if (currentStreamRef.current) {
|
|
1405
|
+
currentStreamRef.current.getTracks().forEach((track) => track.stop());
|
|
1406
|
+
currentStreamRef.current = null;
|
|
1407
|
+
setCurrentStream(null);
|
|
1408
|
+
}
|
|
1409
|
+
setIsRecording(false);
|
|
1410
|
+
if (onError) {
|
|
1411
|
+
onError(err instanceof Error ? err.message : "Error al detener grabaci\xF3n");
|
|
1412
|
+
}
|
|
1413
|
+
return null;
|
|
1414
|
+
}
|
|
1415
|
+
}, [onChunk, onError]);
|
|
1416
|
+
return {
|
|
1417
|
+
isRecording,
|
|
1418
|
+
recordingTime,
|
|
1419
|
+
currentStream,
|
|
1420
|
+
fullAudioBlob,
|
|
1421
|
+
fullAudioUrl,
|
|
1422
|
+
startRecording,
|
|
1423
|
+
stopRecording
|
|
1424
|
+
};
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
// src/voice/useAudioAnalysis.ts
|
|
1428
|
+
import { useState as useState8, useRef as useRef7, useEffect as useEffect8 } from "react";
|
|
1429
|
+
var AUDIO_CONFIG = { SILENCE_THRESHOLD: 2, AUDIO_GAIN: 2.5 };
|
|
1430
|
+
function frequencyDataToBands(data, bandCount, gain) {
|
|
1431
|
+
if (bandCount <= 0 || data.length === 0) return new Array(Math.max(0, bandCount)).fill(0);
|
|
1432
|
+
const usable = Math.floor(data.length * 0.75) || data.length;
|
|
1433
|
+
const sliceSize = Math.max(1, Math.floor(usable / bandCount));
|
|
1434
|
+
const bands = new Array(bandCount);
|
|
1435
|
+
for (let b = 0; b < bandCount; b++) {
|
|
1436
|
+
const start = b * sliceSize;
|
|
1437
|
+
let sum = 0;
|
|
1438
|
+
let n = 0;
|
|
1439
|
+
for (let i = start; i < start + sliceSize && i < usable; i++) {
|
|
1440
|
+
sum += data[i];
|
|
1441
|
+
n++;
|
|
1442
|
+
}
|
|
1443
|
+
const avg = n ? sum / n : 0;
|
|
1444
|
+
const scaled = avg / 255 * gain;
|
|
1445
|
+
bands[b] = scaled > 1 ? 1 : scaled < 0 ? 0 : scaled;
|
|
1446
|
+
}
|
|
1447
|
+
return bands;
|
|
1448
|
+
}
|
|
1449
|
+
function useAudioAnalysis(stream, config) {
|
|
1450
|
+
const {
|
|
1451
|
+
silenceThreshold = AUDIO_CONFIG.SILENCE_THRESHOLD,
|
|
1452
|
+
gain = AUDIO_CONFIG.AUDIO_GAIN,
|
|
1453
|
+
isActive,
|
|
1454
|
+
bandCount = 24
|
|
1455
|
+
} = config;
|
|
1456
|
+
const [audioLevel, setAudioLevel] = useState8(0);
|
|
1457
|
+
const [bands, setBands] = useState8([]);
|
|
1458
|
+
const analyserRef = useRef7(null);
|
|
1459
|
+
const audioContextRef = useRef7(null);
|
|
1460
|
+
const animationFrameRef = useRef7(null);
|
|
1461
|
+
const isSilent = audioLevel < silenceThreshold;
|
|
1462
|
+
useEffect8(() => {
|
|
1463
|
+
if (!stream || !isActive) {
|
|
1464
|
+
setAudioLevel(0);
|
|
1465
|
+
setBands([]);
|
|
1466
|
+
return;
|
|
1467
|
+
}
|
|
1468
|
+
const audioContext = new AudioContext();
|
|
1469
|
+
const analyser = audioContext.createAnalyser();
|
|
1470
|
+
const gainNode = audioContext.createGain();
|
|
1471
|
+
const source = audioContext.createMediaStreamSource(stream);
|
|
1472
|
+
gainNode.gain.value = gain;
|
|
1473
|
+
analyser.fftSize = 256;
|
|
1474
|
+
analyser.smoothingTimeConstant = 0.8;
|
|
1475
|
+
source.connect(gainNode);
|
|
1476
|
+
gainNode.connect(analyser);
|
|
1477
|
+
audioContextRef.current = audioContext;
|
|
1478
|
+
analyserRef.current = analyser;
|
|
1479
|
+
const dataArray = new Uint8Array(analyser.frequencyBinCount);
|
|
1480
|
+
const updateLevel = () => {
|
|
1481
|
+
if (!analyserRef.current) return;
|
|
1482
|
+
analyserRef.current.getByteFrequencyData(dataArray);
|
|
1483
|
+
const average = dataArray.reduce((a, b) => a + b, 0) / dataArray.length;
|
|
1484
|
+
setAudioLevel(average);
|
|
1485
|
+
setBands(frequencyDataToBands(dataArray, bandCount, gain));
|
|
1486
|
+
animationFrameRef.current = requestAnimationFrame(updateLevel);
|
|
1487
|
+
};
|
|
1488
|
+
updateLevel();
|
|
1489
|
+
return () => {
|
|
1490
|
+
if (animationFrameRef.current) {
|
|
1491
|
+
cancelAnimationFrame(animationFrameRef.current);
|
|
1492
|
+
}
|
|
1493
|
+
if (audioContextRef.current) {
|
|
1494
|
+
audioContextRef.current.close();
|
|
1495
|
+
}
|
|
1496
|
+
};
|
|
1497
|
+
}, [stream, isActive, gain, silenceThreshold, bandCount]);
|
|
1498
|
+
return { audioLevel, isSilent, bands };
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
// src/voice/useDictation.ts
|
|
1502
|
+
function useDictation(adapter, opts = {}) {
|
|
1503
|
+
const { timeSliceMs = 3e4, deviceId = null, onTranscriptUpdate, onError } = opts;
|
|
1504
|
+
const [liveTranscript, setLiveTranscript] = useState9("");
|
|
1505
|
+
const [isTranscribing, setIsTranscribing] = useState9(false);
|
|
1506
|
+
const handleChunk = useCallback5(
|
|
1507
|
+
async (blob, chunkNumber) => {
|
|
1508
|
+
if (!adapter?.transcribe) return;
|
|
1509
|
+
setIsTranscribing(true);
|
|
1510
|
+
try {
|
|
1511
|
+
const { text } = await adapter.transcribe(blob, { index: chunkNumber });
|
|
1512
|
+
if (text) {
|
|
1513
|
+
setLiveTranscript((prev) => {
|
|
1514
|
+
const updated = prev ? `${prev} ${text}` : text;
|
|
1515
|
+
onTranscriptUpdate?.(updated);
|
|
1516
|
+
return updated;
|
|
1517
|
+
});
|
|
1518
|
+
}
|
|
1519
|
+
} catch (err) {
|
|
1520
|
+
onError?.(err instanceof Error ? err.message : "transcription failed");
|
|
1521
|
+
} finally {
|
|
1522
|
+
setIsTranscribing(false);
|
|
1523
|
+
}
|
|
1524
|
+
},
|
|
1525
|
+
[adapter, onTranscriptUpdate, onError]
|
|
1526
|
+
);
|
|
1527
|
+
const { isRecording, recordingTime, currentStream, startRecording, stopRecording } = useRecorder({
|
|
1528
|
+
onChunk: handleChunk,
|
|
1529
|
+
onError,
|
|
1530
|
+
timeSlice: timeSliceMs,
|
|
1531
|
+
deviceId
|
|
1532
|
+
});
|
|
1533
|
+
const { audioLevel, isSilent, bands } = useAudioAnalysis(currentStream, {
|
|
1534
|
+
isActive: isRecording
|
|
1535
|
+
});
|
|
1536
|
+
const start = useCallback5(async () => {
|
|
1537
|
+
setLiveTranscript("");
|
|
1538
|
+
await startRecording();
|
|
1539
|
+
}, [startRecording]);
|
|
1540
|
+
const stop = useCallback5(async () => {
|
|
1541
|
+
await stopRecording();
|
|
1542
|
+
}, [stopRecording]);
|
|
1543
|
+
return {
|
|
1544
|
+
isRecording,
|
|
1545
|
+
recordingTime,
|
|
1546
|
+
audioLevel,
|
|
1547
|
+
isSilent,
|
|
1548
|
+
bands,
|
|
1549
|
+
liveTranscript,
|
|
1550
|
+
isTranscribing,
|
|
1551
|
+
startRecording: start,
|
|
1552
|
+
stopRecording: stop
|
|
1553
|
+
};
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
// src/voice/audioArtifact.ts
|
|
1557
|
+
var AUDIO_QUEUE_DEFAULTS = {
|
|
1558
|
+
maxItems: 10,
|
|
1559
|
+
maxBytes: 50 * 1024 * 1024,
|
|
1560
|
+
// 50 MB total queue
|
|
1561
|
+
maxBytesPerItem: 10 * 1024 * 1024
|
|
1562
|
+
// 10 MB per artifact
|
|
1563
|
+
};
|
|
1564
|
+
|
|
1565
|
+
// src/voice/useDurableRecording.ts
|
|
1566
|
+
import { useState as useState10, useRef as useRef8, useCallback as useCallback6, useEffect as useEffect9 } from "react";
|
|
1567
|
+
|
|
1568
|
+
// src/voice/useAudioQueue.ts
|
|
1569
|
+
import { useState as useState11, useEffect as useEffect10, useCallback as useCallback7 } from "react";
|
|
1570
|
+
|
|
1571
|
+
// src/voice/AudioQueuePanel.tsx
|
|
1572
|
+
import { useEffect as useEffect11, useState as useState13 } from "react";
|
|
1573
|
+
import { Loader2 as Loader29, Trash2 as Trash22, Info } from "lucide-react";
|
|
1574
|
+
|
|
1575
|
+
// src/voice/AudioQueueItem.tsx
|
|
1576
|
+
import { useState as useState12, useCallback as useCallback8 } from "react";
|
|
1577
|
+
import {
|
|
1578
|
+
Mic as Mic3,
|
|
1579
|
+
PauseCircle,
|
|
1580
|
+
CheckCircle2,
|
|
1581
|
+
CheckCheck,
|
|
1582
|
+
AlertCircle as AlertCircle3,
|
|
1583
|
+
Loader2 as Loader28,
|
|
1584
|
+
Play as Play4,
|
|
1585
|
+
RotateCcw as RotateCcw2,
|
|
1586
|
+
Trash2,
|
|
1587
|
+
FileAudio
|
|
1588
|
+
} from "lucide-react";
|
|
1589
|
+
import { jsx as jsx22, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
1590
|
+
|
|
1591
|
+
// src/voice/AudioQueuePanel.tsx
|
|
1592
|
+
import { jsx as jsx23, jsxs as jsxs17 } from "react/jsx-runtime";
|
|
1593
|
+
|
|
1594
|
+
// src/voice/AudioDraftPlayer.tsx
|
|
1595
|
+
import { useState as useState14, useEffect as useEffect12 } from "react";
|
|
1596
|
+
import { Play as Play5, Trash2 as Trash23, Loader2 as Loader210, RotateCcw as RotateCcw3, ArrowUp } from "lucide-react";
|
|
1597
|
+
import { jsx as jsx24, jsxs as jsxs18 } from "react/jsx-runtime";
|
|
1598
|
+
|
|
1599
|
+
// src/agent/ScrollToBottomButton.tsx
|
|
1600
|
+
import { ChevronDown } from "lucide-react";
|
|
1601
|
+
import { jsx as jsx25 } from "react/jsx-runtime";
|
|
1602
|
+
var placement = {
|
|
1603
|
+
position: "absolute",
|
|
1604
|
+
bottom: 12,
|
|
1605
|
+
left: "50%",
|
|
1606
|
+
transform: "translateX(-50%)"
|
|
1607
|
+
};
|
|
1608
|
+
var skin = {
|
|
1609
|
+
width: 32,
|
|
1610
|
+
height: 32,
|
|
1611
|
+
borderRadius: 9999,
|
|
1612
|
+
border: "1px solid rgba(255,255,255,0.15)",
|
|
1613
|
+
background: "rgba(15,23,42,0.85)",
|
|
1614
|
+
color: "#e2e8f0",
|
|
1615
|
+
display: "flex",
|
|
1616
|
+
alignItems: "center",
|
|
1617
|
+
justifyContent: "center",
|
|
1618
|
+
cursor: "pointer",
|
|
1619
|
+
backdropFilter: "blur(4px)",
|
|
1620
|
+
WebkitBackdropFilter: "blur(4px)",
|
|
1621
|
+
boxShadow: "0 2px 8px rgba(0,0,0,0.35)"
|
|
1622
|
+
};
|
|
1623
|
+
function ScrollToBottomButton({
|
|
1624
|
+
onClick,
|
|
1625
|
+
label = "Ir al final",
|
|
1626
|
+
className,
|
|
1627
|
+
iconClassName
|
|
1628
|
+
}) {
|
|
1629
|
+
return /* @__PURE__ */ jsx25(
|
|
1630
|
+
"button",
|
|
1631
|
+
{
|
|
1632
|
+
type: "button",
|
|
1633
|
+
onClick,
|
|
1634
|
+
"aria-label": label,
|
|
1635
|
+
className: className ? `fi-scroll-to-bottom ${className}` : "fi-scroll-to-bottom",
|
|
1636
|
+
style: className ? placement : { ...placement, ...skin },
|
|
1637
|
+
children: /* @__PURE__ */ jsx25(ChevronDown, { size: 16, className: iconClassName, "aria-hidden": true })
|
|
1638
|
+
}
|
|
1639
|
+
);
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
// src/agent/AgentConversationSurface.tsx
|
|
1643
|
+
import { jsx as jsx26, jsxs as jsxs19 } from "react/jsx-runtime";
|
|
1644
|
+
function AgentConversationSurface({
|
|
1645
|
+
conversation,
|
|
1646
|
+
composerPlaceholder,
|
|
1647
|
+
newChatLabel = "New chat",
|
|
1648
|
+
showNewChatButton = true,
|
|
1649
|
+
emptyState,
|
|
1650
|
+
aboveComposer,
|
|
1651
|
+
agentPanelProps,
|
|
1652
|
+
composerBoxClassName,
|
|
1653
|
+
composerAreaClassName,
|
|
1654
|
+
composerTextareaClassName,
|
|
1655
|
+
composerControlsClassName,
|
|
1656
|
+
showCopyAction = false,
|
|
1657
|
+
renderHeader,
|
|
1658
|
+
renderBadge,
|
|
1659
|
+
renderActions,
|
|
1660
|
+
messageBubbleClassName,
|
|
1661
|
+
voiceAdapter,
|
|
1662
|
+
micSlotClassName,
|
|
1663
|
+
micButtonClassName,
|
|
1664
|
+
onVoiceError,
|
|
1665
|
+
voiceVisualizerClassName,
|
|
1666
|
+
voiceVisualizerBarClassName,
|
|
1667
|
+
showSendButton = true,
|
|
1668
|
+
sendButtonClassName,
|
|
1669
|
+
sendButtonIconClassName,
|
|
1670
|
+
sendLabel = "Enviar mensaje",
|
|
1671
|
+
composerAppend,
|
|
1672
|
+
onComposerAppendConsumed,
|
|
1673
|
+
micSlotOverride,
|
|
1674
|
+
errorClassName,
|
|
1675
|
+
retryLabel = "Reintentar",
|
|
1676
|
+
dismissLabel = "Descartar",
|
|
1677
|
+
retryButtonClassName,
|
|
1678
|
+
dismissButtonClassName,
|
|
1679
|
+
autoScroll = true,
|
|
1680
|
+
scrollToBottomLabel = "Ir al final",
|
|
1681
|
+
scrollToBottomClassName,
|
|
1682
|
+
scrollToBottomIconClassName,
|
|
1683
|
+
collapseUserMessages = true,
|
|
1684
|
+
collapseMaxHeight,
|
|
1685
|
+
showMoreLabel,
|
|
1686
|
+
showLessLabel,
|
|
1687
|
+
collapseToggleClassName
|
|
1688
|
+
}) {
|
|
1689
|
+
const { messages, turn, isStreaming, turnError, send, retry, dismissError, newConversation } = conversation;
|
|
1690
|
+
const [input, setInput] = useState15("");
|
|
1691
|
+
const stick = useStickToBottom({ initial: "instant", resize: "smooth" });
|
|
1692
|
+
const inputRef = useRef9(null);
|
|
1693
|
+
const refocusComposer = useCallback9(() => {
|
|
1694
|
+
const el = inputRef.current;
|
|
1695
|
+
if (!el || el.disabled) return;
|
|
1696
|
+
const active = document.activeElement;
|
|
1697
|
+
const isOtherTextEntry = active instanceof HTMLElement && active !== el && (active.tagName === "INPUT" || active.tagName === "TEXTAREA" || active.isContentEditable);
|
|
1698
|
+
if (isOtherTextEntry) return;
|
|
1699
|
+
el.focus();
|
|
1700
|
+
}, []);
|
|
1701
|
+
useEffect13(() => {
|
|
1702
|
+
if (!composerAppend) return;
|
|
1703
|
+
setInput((prev) => prev ? `${prev} ${composerAppend}` : composerAppend);
|
|
1704
|
+
onComposerAppendConsumed?.();
|
|
1705
|
+
}, [composerAppend]);
|
|
1706
|
+
const micAvailable = typeof voiceAdapter?.transcribe === "function";
|
|
1707
|
+
const baseInputRef = useRef9("");
|
|
1708
|
+
const dictation = useDictation(voiceAdapter, {
|
|
1709
|
+
onTranscriptUpdate: (full) => {
|
|
1710
|
+
const base = baseInputRef.current;
|
|
1711
|
+
setInput(base ? `${base} ${full}` : full);
|
|
1712
|
+
},
|
|
1713
|
+
onError: onVoiceError
|
|
1714
|
+
});
|
|
1715
|
+
const startDictation = () => {
|
|
1716
|
+
baseInputRef.current = input;
|
|
1717
|
+
void dictation.startRecording();
|
|
1718
|
+
};
|
|
1719
|
+
const wasStreaming = useRef9(false);
|
|
1720
|
+
useEffect13(() => {
|
|
1721
|
+
if (wasStreaming.current && !isStreaming) refocusComposer();
|
|
1722
|
+
wasStreaming.current = isStreaming;
|
|
1723
|
+
}, [isStreaming, refocusComposer]);
|
|
1724
|
+
const wasTranscribing = useRef9(false);
|
|
1725
|
+
useEffect13(() => {
|
|
1726
|
+
if (wasTranscribing.current && !dictation.isTranscribing) refocusComposer();
|
|
1727
|
+
wasTranscribing.current = dictation.isTranscribing;
|
|
1728
|
+
}, [dictation.isTranscribing, refocusComposer]);
|
|
1729
|
+
const resolveBubbleClass = (message) => typeof messageBubbleClassName === "function" ? messageBubbleClassName(message) : messageBubbleClassName;
|
|
1730
|
+
const idle = messages.length === 0 && !isStreaming && turn.status === "thinking" && !turn.plan && turn.steps.length === 0 && !turn.text;
|
|
1731
|
+
const hasThread = messages.length > 0 || isStreaming;
|
|
1732
|
+
const onSend = () => {
|
|
1733
|
+
const t = input.trim();
|
|
1734
|
+
if (!t) return;
|
|
1735
|
+
setInput("");
|
|
1736
|
+
send(t);
|
|
1737
|
+
};
|
|
1738
|
+
const canSend = input.trim().length > 0 && !isStreaming;
|
|
1739
|
+
return (
|
|
1740
|
+
// B3-FIGLASS-15: the ROOT is full-width — the fluid cap (100% minus a 60px
|
|
1741
|
+
// gutter) lives on INNER content wrappers (transcript + composer), never on
|
|
1742
|
+
// the scroll container, so the scrollbar renders at the viewport edge like
|
|
1743
|
+
// ChatGPT/AURITY /chat instead of glued to the centered column.
|
|
1744
|
+
/* @__PURE__ */ jsxs19("div", { style: { display: "flex", flexDirection: "column", height: "100dvh" }, children: [
|
|
1745
|
+
/* @__PURE__ */ jsxs19("div", { style: { position: "relative", flex: 1, minHeight: 0, display: "flex", flexDirection: "column" }, children: [
|
|
1746
|
+
/* @__PURE__ */ jsx26(
|
|
1747
|
+
"div",
|
|
1748
|
+
{
|
|
1749
|
+
ref: autoScroll ? stick.scrollRef : void 0,
|
|
1750
|
+
style: { flex: 1, overflowY: "auto", padding: "1.25rem 1rem" },
|
|
1751
|
+
children: /* @__PURE__ */ jsxs19(
|
|
1752
|
+
"div",
|
|
1753
|
+
{
|
|
1754
|
+
ref: autoScroll ? stick.contentRef : void 0,
|
|
1755
|
+
style: { maxWidth: "calc(100% - 60px)", margin: "0 auto", width: "100%" },
|
|
1756
|
+
children: [
|
|
1757
|
+
idle ? emptyState : /* @__PURE__ */ jsxs19("div", { style: { display: "flex", flexDirection: "column", gap: "1rem" }, children: [
|
|
1758
|
+
messages.map((m, i) => /* @__PURE__ */ jsx26(
|
|
1759
|
+
MessageBubble,
|
|
1760
|
+
{
|
|
1761
|
+
role: m.role,
|
|
1762
|
+
header: renderHeader?.(m),
|
|
1763
|
+
badge: renderBadge?.(m),
|
|
1764
|
+
actions: renderActions?.(m) ?? (showCopyAction ? /* @__PURE__ */ jsx26(CopyButton, { content: m.content }) : void 0),
|
|
1765
|
+
className: resolveBubbleClass(m),
|
|
1766
|
+
children: /* @__PURE__ */ jsx26(
|
|
1767
|
+
MessageContent,
|
|
1768
|
+
{
|
|
1769
|
+
isUser: m.role === "user",
|
|
1770
|
+
content: m.content,
|
|
1771
|
+
collapsible: collapseUserMessages && m.role === "user",
|
|
1772
|
+
collapsedMaxHeight: collapseMaxHeight,
|
|
1773
|
+
showMoreLabel,
|
|
1774
|
+
showLessLabel,
|
|
1775
|
+
collapseToggleClassName
|
|
1776
|
+
}
|
|
1777
|
+
)
|
|
1778
|
+
},
|
|
1779
|
+
i
|
|
1780
|
+
)),
|
|
1781
|
+
isStreaming && /* @__PURE__ */ jsx26(AgentPanel, { turn, ...agentPanelProps }),
|
|
1782
|
+
isStreaming && turn.text && /* @__PURE__ */ jsx26(
|
|
1783
|
+
MessageBubble,
|
|
1784
|
+
{
|
|
1785
|
+
role: "assistant",
|
|
1786
|
+
className: resolveBubbleClass({
|
|
1787
|
+
role: "assistant",
|
|
1788
|
+
content: turn.text,
|
|
1789
|
+
timestamp: ""
|
|
1790
|
+
}),
|
|
1791
|
+
children: /* @__PURE__ */ jsx26(MessageContent, { isUser: false, content: turn.text, isStreaming: true })
|
|
1792
|
+
}
|
|
1793
|
+
)
|
|
1794
|
+
] }),
|
|
1795
|
+
turnError && /* @__PURE__ */ jsxs19(
|
|
1796
|
+
"div",
|
|
1797
|
+
{
|
|
1798
|
+
role: "alert",
|
|
1799
|
+
className: errorClassName,
|
|
1800
|
+
style: {
|
|
1801
|
+
marginTop: "1rem",
|
|
1802
|
+
padding: "0.75rem 1rem",
|
|
1803
|
+
borderRadius: 10,
|
|
1804
|
+
border: "1px solid rgba(248,113,113,0.35)",
|
|
1805
|
+
background: "rgba(248,113,113,0.08)",
|
|
1806
|
+
display: "flex",
|
|
1807
|
+
flexWrap: "wrap",
|
|
1808
|
+
alignItems: "center",
|
|
1809
|
+
gap: "0.75rem"
|
|
1810
|
+
},
|
|
1811
|
+
children: [
|
|
1812
|
+
/* @__PURE__ */ jsx26("span", { style: { color: "#fca5a5", fontSize: "0.85rem", flex: 1, minWidth: 0 }, children: turnError.message }),
|
|
1813
|
+
/* @__PURE__ */ jsx26(
|
|
1814
|
+
"button",
|
|
1815
|
+
{
|
|
1816
|
+
type: "button",
|
|
1817
|
+
onClick: retry,
|
|
1818
|
+
className: retryButtonClassName,
|
|
1819
|
+
style: retryButtonClassName ? void 0 : {
|
|
1820
|
+
padding: "0.35rem 0.75rem",
|
|
1821
|
+
borderRadius: 8,
|
|
1822
|
+
border: "1px solid rgba(255,255,255,0.2)",
|
|
1823
|
+
background: "transparent",
|
|
1824
|
+
color: "#e2e8f0",
|
|
1825
|
+
fontSize: "0.8rem",
|
|
1826
|
+
cursor: "pointer"
|
|
1827
|
+
},
|
|
1828
|
+
children: retryLabel
|
|
1829
|
+
}
|
|
1830
|
+
),
|
|
1831
|
+
/* @__PURE__ */ jsx26(
|
|
1832
|
+
"button",
|
|
1833
|
+
{
|
|
1834
|
+
type: "button",
|
|
1835
|
+
onClick: dismissError,
|
|
1836
|
+
className: dismissButtonClassName,
|
|
1837
|
+
style: dismissButtonClassName ? void 0 : {
|
|
1838
|
+
padding: "0.35rem 0.75rem",
|
|
1839
|
+
borderRadius: 8,
|
|
1840
|
+
border: "none",
|
|
1841
|
+
background: "transparent",
|
|
1842
|
+
color: "#94a3b8",
|
|
1843
|
+
fontSize: "0.8rem",
|
|
1844
|
+
cursor: "pointer"
|
|
1845
|
+
},
|
|
1846
|
+
children: dismissLabel
|
|
1847
|
+
}
|
|
1848
|
+
)
|
|
1849
|
+
]
|
|
1850
|
+
}
|
|
1851
|
+
)
|
|
1852
|
+
]
|
|
1853
|
+
}
|
|
1854
|
+
)
|
|
1855
|
+
}
|
|
1856
|
+
),
|
|
1857
|
+
autoScroll && !stick.isAtBottom && /* @__PURE__ */ jsx26(
|
|
1858
|
+
ScrollToBottomButton,
|
|
1859
|
+
{
|
|
1860
|
+
onClick: () => void stick.scrollToBottom(),
|
|
1861
|
+
label: scrollToBottomLabel,
|
|
1862
|
+
className: scrollToBottomClassName,
|
|
1863
|
+
iconClassName: scrollToBottomIconClassName
|
|
1864
|
+
}
|
|
1865
|
+
)
|
|
1866
|
+
] }),
|
|
1867
|
+
/* @__PURE__ */ jsx26("div", { style: { padding: "0.75rem 1rem 1.25rem", borderTop: "1px solid rgba(255,255,255,0.06)" }, children: /* @__PURE__ */ jsxs19("div", { style: { maxWidth: "calc(100% - 60px)", margin: "0 auto", width: "100%" }, children: [
|
|
1868
|
+
hasThread && showNewChatButton && /* @__PURE__ */ jsx26("div", { style: { display: "flex", justifyContent: "flex-end", marginBottom: "0.5rem" }, children: /* @__PURE__ */ jsx26(
|
|
1869
|
+
"button",
|
|
1870
|
+
{
|
|
1871
|
+
onClick: newConversation,
|
|
1872
|
+
disabled: isStreaming,
|
|
1873
|
+
style: {
|
|
1874
|
+
padding: "0.35rem 0.75rem",
|
|
1875
|
+
borderRadius: 8,
|
|
1876
|
+
border: "1px solid rgba(255,255,255,0.15)",
|
|
1877
|
+
background: "transparent",
|
|
1878
|
+
color: "#94a3b8",
|
|
1879
|
+
fontSize: "0.8rem",
|
|
1880
|
+
cursor: isStreaming ? "not-allowed" : "pointer",
|
|
1881
|
+
opacity: isStreaming ? 0.5 : 1
|
|
1882
|
+
},
|
|
1883
|
+
children: newChatLabel
|
|
1884
|
+
}
|
|
1885
|
+
) }),
|
|
1886
|
+
aboveComposer && /* @__PURE__ */ jsx26("div", { className: "fi-surface-above-composer", style: { marginBottom: "0.5rem" }, children: aboveComposer }),
|
|
1887
|
+
/* @__PURE__ */ jsxs19("div", { className: composerBoxClassName, children: [
|
|
1888
|
+
/* @__PURE__ */ jsx26(
|
|
1889
|
+
Composer,
|
|
1890
|
+
{
|
|
1891
|
+
message: input,
|
|
1892
|
+
loading: isStreaming,
|
|
1893
|
+
placeholder: composerPlaceholder,
|
|
1894
|
+
onMessageChange: setInput,
|
|
1895
|
+
onSend,
|
|
1896
|
+
areaClassName: composerAreaClassName,
|
|
1897
|
+
textareaClassName: composerTextareaClassName,
|
|
1898
|
+
wrapperStyle: { flex: "1 1 0%", minWidth: 0 },
|
|
1899
|
+
textareaRef: inputRef
|
|
1900
|
+
}
|
|
1901
|
+
),
|
|
1902
|
+
(showSendButton || micSlotOverride != null || micAvailable) && /* @__PURE__ */ jsxs19(
|
|
1903
|
+
"div",
|
|
1904
|
+
{
|
|
1905
|
+
className: composerControlsClassName,
|
|
1906
|
+
style: { display: "flex", alignItems: "center", justifyContent: "flex-end", gap: 8 },
|
|
1907
|
+
children: [
|
|
1908
|
+
micSlotOverride == null && micAvailable && dictation.isRecording && // Live equalizer: reacts to the mic's frequency bands so the user
|
|
1909
|
+
// sees they're being heard. Only mounted while recording, fed by the
|
|
1910
|
+
// analyser the dictation hook already runs — no extra Web Audio here.
|
|
1911
|
+
/* @__PURE__ */ jsx26(
|
|
1912
|
+
AudioVisualizer,
|
|
1913
|
+
{
|
|
1914
|
+
levels: dictation.bands,
|
|
1915
|
+
active: dictation.isRecording,
|
|
1916
|
+
variant: "bars",
|
|
1917
|
+
label: "Nivel del micr\xF3fono",
|
|
1918
|
+
className: voiceVisualizerClassName,
|
|
1919
|
+
barClassName: voiceVisualizerBarClassName
|
|
1920
|
+
}
|
|
1921
|
+
),
|
|
1922
|
+
micSlotOverride != null ? micSlotOverride : micAvailable && /* @__PURE__ */ jsx26(
|
|
1923
|
+
ComposerMicSlot,
|
|
1924
|
+
{
|
|
1925
|
+
available: true,
|
|
1926
|
+
recording: dictation.isRecording,
|
|
1927
|
+
busy: dictation.isTranscribing,
|
|
1928
|
+
onStart: startDictation,
|
|
1929
|
+
onStop: () => void dictation.stopRecording(),
|
|
1930
|
+
className: micSlotClassName,
|
|
1931
|
+
buttonClassName: micButtonClassName
|
|
1932
|
+
}
|
|
1933
|
+
),
|
|
1934
|
+
showSendButton && // Explicit send affordance (mirrors the shell/AURITY composer). Enter
|
|
1935
|
+
// still sends; this is the visible button. Disabled until there's
|
|
1936
|
+
// trimmed text and nothing is streaming.
|
|
1937
|
+
/* @__PURE__ */ jsx26(
|
|
1938
|
+
"button",
|
|
1939
|
+
{
|
|
1940
|
+
type: "button",
|
|
1941
|
+
onClick: onSend,
|
|
1942
|
+
disabled: !canSend,
|
|
1943
|
+
"aria-label": sendLabel,
|
|
1944
|
+
className: sendButtonClassName,
|
|
1945
|
+
children: isStreaming ? /* @__PURE__ */ jsx26(
|
|
1946
|
+
Loader211,
|
|
1947
|
+
{
|
|
1948
|
+
className: sendButtonIconClassName ? `${sendButtonIconClassName} animate-spin` : "animate-spin",
|
|
1949
|
+
"aria-hidden": true
|
|
1950
|
+
}
|
|
1951
|
+
) : /* @__PURE__ */ jsx26(Send, { className: sendButtonIconClassName, "aria-hidden": true })
|
|
1952
|
+
}
|
|
1953
|
+
)
|
|
1954
|
+
]
|
|
1955
|
+
}
|
|
1956
|
+
)
|
|
1957
|
+
] })
|
|
1958
|
+
] }) })
|
|
1959
|
+
] })
|
|
1960
|
+
);
|
|
1961
|
+
}
|
|
1962
|
+
export {
|
|
1963
|
+
AgentConversationSurface,
|
|
1964
|
+
AgentPanel,
|
|
1965
|
+
DEFAULT_TURN_TIMEOUT_MS,
|
|
1966
|
+
PlanChecklist,
|
|
1967
|
+
ScrollToBottomButton,
|
|
1968
|
+
SourcesPanel,
|
|
1969
|
+
StepsPanel,
|
|
1970
|
+
classifyTool,
|
|
1971
|
+
defaultAgentIcons,
|
|
1972
|
+
latestOpenToolIndex,
|
|
1973
|
+
resolveIcons,
|
|
1974
|
+
shortToolName,
|
|
1975
|
+
toolIcon,
|
|
1976
|
+
toolVisualStatus,
|
|
1977
|
+
useAgentConversation
|
|
1978
|
+
};
|
|
1979
|
+
//# sourceMappingURL=index.js.map
|