@dudko.dev/agent-web-react 0.0.38 → 0.0.39
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/README.md +7 -0
- package/dist/{chunk-G5GGIMD4.js → chunk-RJM7JCWI.js} +12 -1
- package/dist/chunk-RJM7JCWI.js.map +1 -0
- package/dist/{elicitation-BgSf-xzh.d.cts → elicitation-DdzjMut9.d.cts} +2 -0
- package/dist/{elicitation-BgSf-xzh.d.ts → elicitation-DdzjMut9.d.ts} +2 -0
- package/dist/index.cjs +1372 -245
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +493 -15
- package/dist/index.d.ts +493 -15
- package/dist/index.js +1328 -231
- package/dist/index.js.map +1 -1
- package/dist/mcp.d.cts +2 -2
- package/dist/mcp.d.ts +2 -2
- package/dist/pipeline.cjs.map +1 -1
- package/dist/pipeline.js +1 -1
- package/dist/styles.css +90 -0
- package/package.json +3 -3
- package/dist/chunk-G5GGIMD4.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -33,6 +33,8 @@ import {
|
|
|
33
33
|
MoreIcon,
|
|
34
34
|
NoNetworkIcon,
|
|
35
35
|
PanelIcon,
|
|
36
|
+
PauseIcon,
|
|
37
|
+
PlayIcon,
|
|
36
38
|
PlusIcon,
|
|
37
39
|
QuestionIcon,
|
|
38
40
|
ReloadIcon,
|
|
@@ -40,10 +42,12 @@ import {
|
|
|
40
42
|
ShieldIcon,
|
|
41
43
|
ShrinkIcon,
|
|
42
44
|
SlashIcon,
|
|
45
|
+
SpeakerIcon,
|
|
43
46
|
SpinnerIcon,
|
|
44
47
|
StopIcon,
|
|
45
48
|
TableIcon,
|
|
46
49
|
ToolIcon,
|
|
50
|
+
WaveIcon,
|
|
47
51
|
XIcon,
|
|
48
52
|
errMessage,
|
|
49
53
|
followOtherTabs,
|
|
@@ -53,7 +57,7 @@ import {
|
|
|
53
57
|
imagesInOutput,
|
|
54
58
|
previewValue,
|
|
55
59
|
webSearchOf
|
|
56
|
-
} from "./chunk-
|
|
60
|
+
} from "./chunk-RJM7JCWI.js";
|
|
57
61
|
import {
|
|
58
62
|
MCP_APP_POLICY_TOKEN_MAX_CHARS,
|
|
59
63
|
MCP_APP_SANDBOX_PROXY_READY,
|
|
@@ -1589,7 +1593,8 @@ var useAgent = (config, options = {}) => {
|
|
|
1589
1593
|
let began = false;
|
|
1590
1594
|
const shownGoal = runOptions?.label ?? goal;
|
|
1591
1595
|
dispatch({ type: "status", status: "running" });
|
|
1592
|
-
|
|
1596
|
+
const shownAtAll = Boolean(shownGoal.trim() || runOptions?.attachments?.length);
|
|
1597
|
+
if (shownAtAll) {
|
|
1593
1598
|
dispatch({
|
|
1594
1599
|
type: "submitted",
|
|
1595
1600
|
goal: shownGoal,
|
|
@@ -1609,14 +1614,16 @@ var useAgent = (config, options = {}) => {
|
|
|
1609
1614
|
startedRef.current = true;
|
|
1610
1615
|
began = true;
|
|
1611
1616
|
}
|
|
1612
|
-
const shown = start && runOptions?.label ? { ...event, goal: runOptions.label } : event;
|
|
1617
|
+
const shown = start && runOptions?.label !== void 0 ? { ...event, goal: runOptions.label } : event;
|
|
1613
1618
|
dispatch({
|
|
1614
1619
|
type: "event",
|
|
1615
1620
|
event: shown,
|
|
1616
1621
|
maxEvents: optionsRef.current.maxEvents,
|
|
1617
1622
|
at: Date.now(),
|
|
1618
1623
|
// What the user sent waits with the run: shown as queued meanwhile.
|
|
1619
|
-
...event.type === "session.busy" &&
|
|
1624
|
+
...event.type === "session.busy" && shownAtAll ? {
|
|
1625
|
+
goal: shownGoal.trim() || (runOptions?.attachments ?? []).map((a) => a.name).join(", ")
|
|
1626
|
+
} : {},
|
|
1620
1627
|
...start && runOptions?.attachments?.length ? { attachments: runOptions.attachments } : {}
|
|
1621
1628
|
});
|
|
1622
1629
|
try {
|
|
@@ -1983,8 +1990,17 @@ var ChatHistoryStore = class {
|
|
|
1983
1990
|
await this.write((store) => store.clear(), { op: "clear" });
|
|
1984
1991
|
}
|
|
1985
1992
|
};
|
|
1986
|
-
var
|
|
1987
|
-
|
|
1993
|
+
var attachmentsText = (attachments, texts = {}) => attachments.length > 0 && attachments.every((a) => a.mediaType.toLowerCase().startsWith("audio/")) ? texts.voiceMessage ?? "Voice message" : attachments.map((a) => a.name).join(", ");
|
|
1994
|
+
var oneLine = (text) => (text ?? "").replace(/\s+/g, " ").trim();
|
|
1995
|
+
var chatTitle = (messages, texts = {}) => {
|
|
1996
|
+
const at = messages.findIndex((m) => m.role === "user");
|
|
1997
|
+
const user = at >= 0 ? messages[at] : void 0;
|
|
1998
|
+
let first = oneLine(user?.content);
|
|
1999
|
+
if (!first && user?.attachments?.length) {
|
|
2000
|
+
const answer = messages.slice(at + 1).find((m) => m.role === "assistant");
|
|
2001
|
+
const heard = answer?.transcripts?.find((t) => t.source === "attachment")?.text;
|
|
2002
|
+
first = oneLine(heard) || oneLine(attachmentsText(user.attachments, texts));
|
|
2003
|
+
}
|
|
1988
2004
|
if (!first) return "New chat";
|
|
1989
2005
|
return first.length > 60 ? `${first.slice(0, 59)}\u2026` : first;
|
|
1990
2006
|
};
|
|
@@ -2016,7 +2032,7 @@ var renumber = (own, after) => {
|
|
|
2016
2032
|
return own.map((m) => ({ ...m, id: `msg-${next += 1}` }));
|
|
2017
2033
|
};
|
|
2018
2034
|
var unchangedSince = (messages, base) => base !== void 0 && messages.length === base.known.size && messages.every((m) => base.known.has(m));
|
|
2019
|
-
var mergeChatRecord = (view, stored, base) => {
|
|
2035
|
+
var mergeChatRecord = (view, stored, base, texts) => {
|
|
2020
2036
|
const local = view.messages.filter((m) => !m.remote);
|
|
2021
2037
|
if (!stored || base && stored.updatedAt <= base.updatedAt) {
|
|
2022
2038
|
return { record: { ...view, messages: local }, merged: false };
|
|
@@ -2027,7 +2043,7 @@ var mergeChatRecord = (view, stored, base) => {
|
|
|
2027
2043
|
record: {
|
|
2028
2044
|
...view,
|
|
2029
2045
|
createdAt: stored.createdAt,
|
|
2030
|
-
title: chatTitle(messages),
|
|
2046
|
+
title: chatTitle(messages, texts),
|
|
2031
2047
|
messages,
|
|
2032
2048
|
totalUsage: sumUsage(
|
|
2033
2049
|
stored.totalUsage,
|
|
@@ -2037,10 +2053,10 @@ var mergeChatRecord = (view, stored, base) => {
|
|
|
2037
2053
|
merged: true
|
|
2038
2054
|
};
|
|
2039
2055
|
};
|
|
2040
|
-
var saveChat = async (store, view, base) => {
|
|
2056
|
+
var saveChat = async (store, view, base, texts) => {
|
|
2041
2057
|
let merged = false;
|
|
2042
2058
|
const record = await store.putMerged(view.id, (stored) => {
|
|
2043
|
-
const out = mergeChatRecord(view, stored, base);
|
|
2059
|
+
const out = mergeChatRecord(view, stored, base, texts);
|
|
2044
2060
|
merged = out.merged;
|
|
2045
2061
|
return out.record;
|
|
2046
2062
|
});
|
|
@@ -2048,6 +2064,8 @@ var saveChat = async (store, view, base) => {
|
|
|
2048
2064
|
};
|
|
2049
2065
|
var useChatHistory = (agent, options = {}) => {
|
|
2050
2066
|
const enabled = options.enabled !== false;
|
|
2067
|
+
const textsRef = useRef2(options.labels);
|
|
2068
|
+
textsRef.current = options.labels;
|
|
2051
2069
|
const store = useMemo(() => options.store ?? new ChatHistoryStore(), [options.store]);
|
|
2052
2070
|
const [chats, setChats] = useState2([]);
|
|
2053
2071
|
const [loading, setLoading] = useState2(enabled);
|
|
@@ -2141,14 +2159,14 @@ var useChatHistory = (agent, options = {}) => {
|
|
|
2141
2159
|
createdRef.current.set(sessionId, createdAt);
|
|
2142
2160
|
const view = {
|
|
2143
2161
|
id: sessionId,
|
|
2144
|
-
title: chatTitle(messages),
|
|
2162
|
+
title: chatTitle(messages, textsRef.current),
|
|
2145
2163
|
createdAt,
|
|
2146
2164
|
updatedAt: now,
|
|
2147
2165
|
messages,
|
|
2148
2166
|
totalUsage
|
|
2149
2167
|
};
|
|
2150
2168
|
void (async () => {
|
|
2151
|
-
const { record, merged } = await saveChat(store, view, base);
|
|
2169
|
+
const { record, merged } = await saveChat(store, view, base, textsRef.current);
|
|
2152
2170
|
baseRef.current = {
|
|
2153
2171
|
id: sessionId,
|
|
2154
2172
|
known: new Set(merged ? record.messages : messages),
|
|
@@ -2233,7 +2251,7 @@ var useVirtualFiles = (vfs, prefix = "/") => {
|
|
|
2233
2251
|
};
|
|
2234
2252
|
|
|
2235
2253
|
// src/hooks/use-speech-to-text.ts
|
|
2236
|
-
import { useCallback as useCallback4, useEffect as useEffect4, useRef as useRef3, useState as useState4 } from "react";
|
|
2254
|
+
import { useCallback as useCallback4, useEffect as useEffect4, useMemo as useMemo2, useRef as useRef3, useState as useState4 } from "react";
|
|
2237
2255
|
var browserRecognizer = () => {
|
|
2238
2256
|
const g = globalThis;
|
|
2239
2257
|
const Ctor = g.SpeechRecognition ?? g.webkitSpeechRecognition;
|
|
@@ -2242,13 +2260,18 @@ var browserRecognizer = () => {
|
|
|
2242
2260
|
var useSpeechToText = (options = {}) => {
|
|
2243
2261
|
const optionsRef = useRef3(options);
|
|
2244
2262
|
optionsRef.current = options;
|
|
2245
|
-
const
|
|
2263
|
+
const own = options.createRecognizer;
|
|
2264
|
+
const factory = useMemo2(() => own ?? browserRecognizer(), [own]);
|
|
2246
2265
|
const [listening, setListening] = useState4(false);
|
|
2247
2266
|
const [interim, setInterim] = useState4("");
|
|
2248
2267
|
const [error, setError] = useState4();
|
|
2268
|
+
const [errorMessage, setErrorMessage] = useState4();
|
|
2269
|
+
const [finishing, setFinishing] = useState4(false);
|
|
2249
2270
|
const recRef = useRef3(void 0);
|
|
2250
2271
|
const stop = useCallback4(() => {
|
|
2251
|
-
recRef.current
|
|
2272
|
+
if (!recRef.current) return;
|
|
2273
|
+
setFinishing(true);
|
|
2274
|
+
recRef.current.stop();
|
|
2252
2275
|
}, []);
|
|
2253
2276
|
const start = useCallback4(() => {
|
|
2254
2277
|
if (!factory || recRef.current) return;
|
|
@@ -2266,15 +2289,22 @@ var useSpeechToText = (options = {}) => {
|
|
|
2266
2289
|
setInterim(pending);
|
|
2267
2290
|
};
|
|
2268
2291
|
rec.onerror = (ev) => {
|
|
2269
|
-
if (ev.error && ev.error !== "no-speech" && ev.error !== "aborted")
|
|
2292
|
+
if (ev.error && ev.error !== "no-speech" && ev.error !== "aborted") {
|
|
2293
|
+
setError(ev.error);
|
|
2294
|
+
setErrorMessage(ev.message);
|
|
2295
|
+
}
|
|
2270
2296
|
};
|
|
2271
2297
|
rec.onend = () => {
|
|
2298
|
+
if (recRef.current !== rec) return;
|
|
2272
2299
|
recRef.current = void 0;
|
|
2273
2300
|
setListening(false);
|
|
2301
|
+
setFinishing(false);
|
|
2274
2302
|
setInterim("");
|
|
2275
2303
|
};
|
|
2276
2304
|
recRef.current = rec;
|
|
2277
2305
|
setError(void 0);
|
|
2306
|
+
setErrorMessage(void 0);
|
|
2307
|
+
setFinishing(false);
|
|
2278
2308
|
try {
|
|
2279
2309
|
rec.start();
|
|
2280
2310
|
setListening(true);
|
|
@@ -2283,20 +2313,763 @@ var useSpeechToText = (options = {}) => {
|
|
|
2283
2313
|
setError(err instanceof Error ? err.message : String(err));
|
|
2284
2314
|
}
|
|
2285
2315
|
}, [factory]);
|
|
2286
|
-
useEffect4(
|
|
2316
|
+
useEffect4(
|
|
2317
|
+
() => () => {
|
|
2318
|
+
const rec = recRef.current;
|
|
2319
|
+
recRef.current = void 0;
|
|
2320
|
+
rec?.abort?.();
|
|
2321
|
+
},
|
|
2322
|
+
[factory]
|
|
2323
|
+
);
|
|
2287
2324
|
return {
|
|
2288
2325
|
supported: Boolean(factory),
|
|
2289
2326
|
listening,
|
|
2327
|
+
finishing,
|
|
2290
2328
|
interim,
|
|
2291
2329
|
error,
|
|
2330
|
+
errorMessage,
|
|
2292
2331
|
start,
|
|
2293
2332
|
stop,
|
|
2294
2333
|
toggle: () => recRef.current ? stop() : start()
|
|
2295
2334
|
};
|
|
2296
2335
|
};
|
|
2297
2336
|
|
|
2337
|
+
// src/hooks/use-audio-recorder.ts
|
|
2338
|
+
import { useCallback as useCallback5, useEffect as useEffect5, useRef as useRef4, useState as useState5 } from "react";
|
|
2339
|
+
|
|
2340
|
+
// src/voice/record.ts
|
|
2341
|
+
var MicError = class extends Error {
|
|
2342
|
+
code;
|
|
2343
|
+
constructor(code, message = code) {
|
|
2344
|
+
super(message);
|
|
2345
|
+
this.name = "MicError";
|
|
2346
|
+
this.code = code;
|
|
2347
|
+
}
|
|
2348
|
+
};
|
|
2349
|
+
var RECORDING_DEFAULT_MAX_MS = 5 * 60 * 1e3;
|
|
2350
|
+
var RECORDING_TYPES = [
|
|
2351
|
+
"audio/webm;codecs=opus",
|
|
2352
|
+
"audio/webm",
|
|
2353
|
+
"audio/mp4",
|
|
2354
|
+
"audio/ogg;codecs=opus",
|
|
2355
|
+
"audio/ogg"
|
|
2356
|
+
];
|
|
2357
|
+
var pickRecordingType = (isTypeSupported) => {
|
|
2358
|
+
if (!isTypeSupported) return void 0;
|
|
2359
|
+
for (const type of RECORDING_TYPES) {
|
|
2360
|
+
try {
|
|
2361
|
+
if (isTypeSupported(type)) return type;
|
|
2362
|
+
} catch {
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
return void 0;
|
|
2366
|
+
};
|
|
2367
|
+
var audioTypeOf = (type) => {
|
|
2368
|
+
const base = (type ?? "").toLowerCase().split(";")[0].trim();
|
|
2369
|
+
if (/^(audio|video)\/(mp4|x-m4a|m4a|aac-mp4)$/.test(base)) return "audio/mp4";
|
|
2370
|
+
if (/^(audio|video)\/webm$/.test(base)) return "audio/webm";
|
|
2371
|
+
if (base === "audio/ogg" || base === "application/ogg") return "audio/ogg";
|
|
2372
|
+
if (base === "audio/wav" || base === "audio/x-wav" || base === "audio/wave") return "audio/wav";
|
|
2373
|
+
if (base === "audio/mpeg" || base === "audio/mp3") return "audio/mpeg";
|
|
2374
|
+
if (base === "audio/aac") return "audio/aac";
|
|
2375
|
+
return "audio/webm";
|
|
2376
|
+
};
|
|
2377
|
+
var audioExtensionOf = (type) => ({
|
|
2378
|
+
"audio/mp4": "m4a",
|
|
2379
|
+
"audio/ogg": "ogg",
|
|
2380
|
+
"audio/wav": "wav",
|
|
2381
|
+
"audio/mpeg": "mp3",
|
|
2382
|
+
"audio/aac": "aac"
|
|
2383
|
+
})[audioTypeOf(type)] ?? "webm";
|
|
2384
|
+
var micProblemOf = (err) => {
|
|
2385
|
+
if (err instanceof MicError) return err.code;
|
|
2386
|
+
const name = err && typeof err === "object" ? String(err.name) : "";
|
|
2387
|
+
if (name === "NotAllowedError" || name === "SecurityError" || name === "PermissionDeniedError")
|
|
2388
|
+
return "not-allowed";
|
|
2389
|
+
if (name === "NotFoundError" || name === "OverconstrainedError" || name === "DevicesNotFoundError")
|
|
2390
|
+
return "audio-capture";
|
|
2391
|
+
if (name === "NotReadableError" || name === "TrackStartError" || name === "AbortError")
|
|
2392
|
+
return "busy";
|
|
2393
|
+
if (name === "NotSupportedError" || name === "TypeError") return "unsupported";
|
|
2394
|
+
return "failed";
|
|
2395
|
+
};
|
|
2396
|
+
var defaults = (deps) => {
|
|
2397
|
+
const g = globalThis;
|
|
2398
|
+
const devices = g.navigator?.mediaDevices;
|
|
2399
|
+
return {
|
|
2400
|
+
getUserMedia: deps.getUserMedia ?? (devices?.getUserMedia ? devices.getUserMedia.bind(devices) : void 0),
|
|
2401
|
+
MediaRecorder: deps.MediaRecorder ?? g.MediaRecorder,
|
|
2402
|
+
now: deps.now ?? Date.now
|
|
2403
|
+
};
|
|
2404
|
+
};
|
|
2405
|
+
var recordingSupported = (deps = {}) => {
|
|
2406
|
+
const d = defaults(deps);
|
|
2407
|
+
return Boolean(d.getUserMedia && d.MediaRecorder);
|
|
2408
|
+
};
|
|
2409
|
+
var stopTracks = (stream) => {
|
|
2410
|
+
for (const track of stream?.getTracks() ?? []) {
|
|
2411
|
+
try {
|
|
2412
|
+
track.stop();
|
|
2413
|
+
} catch {
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
};
|
|
2417
|
+
var startRecording = async (options = {}) => {
|
|
2418
|
+
const d = defaults(options);
|
|
2419
|
+
if (!d.getUserMedia || !d.MediaRecorder) throw new MicError("unsupported");
|
|
2420
|
+
let stream;
|
|
2421
|
+
try {
|
|
2422
|
+
stream = await d.getUserMedia({ audio: true });
|
|
2423
|
+
} catch (err) {
|
|
2424
|
+
throw new MicError(micProblemOf(err));
|
|
2425
|
+
}
|
|
2426
|
+
let recorder;
|
|
2427
|
+
try {
|
|
2428
|
+
const type = pickRecordingType(d.MediaRecorder.isTypeSupported?.bind(d.MediaRecorder));
|
|
2429
|
+
recorder = new d.MediaRecorder(stream, type ? { mimeType: type } : void 0);
|
|
2430
|
+
} catch (err) {
|
|
2431
|
+
stopTracks(stream);
|
|
2432
|
+
throw new MicError(micProblemOf(err) === "failed" ? "unsupported" : micProblemOf(err));
|
|
2433
|
+
}
|
|
2434
|
+
const startedAt = d.now();
|
|
2435
|
+
const chunks = [];
|
|
2436
|
+
let cancelled = false;
|
|
2437
|
+
let failure;
|
|
2438
|
+
let settle = () => {
|
|
2439
|
+
};
|
|
2440
|
+
const ended = new Promise((resolve) => settle = resolve);
|
|
2441
|
+
let finish;
|
|
2442
|
+
let fail;
|
|
2443
|
+
const result = new Promise((resolve, reject) => {
|
|
2444
|
+
finish = resolve;
|
|
2445
|
+
fail = reject;
|
|
2446
|
+
});
|
|
2447
|
+
result.catch(() => {
|
|
2448
|
+
});
|
|
2449
|
+
let limit;
|
|
2450
|
+
const end = () => {
|
|
2451
|
+
stopTracks(stream);
|
|
2452
|
+
clearTimeout(limit);
|
|
2453
|
+
settle();
|
|
2454
|
+
};
|
|
2455
|
+
recorder.ondataavailable = (event) => {
|
|
2456
|
+
if (event.data && event.data.size > 0) chunks.push(event.data);
|
|
2457
|
+
};
|
|
2458
|
+
recorder.onerror = () => {
|
|
2459
|
+
failure = new MicError("failed");
|
|
2460
|
+
end();
|
|
2461
|
+
fail?.(failure);
|
|
2462
|
+
};
|
|
2463
|
+
recorder.onstop = () => {
|
|
2464
|
+
end();
|
|
2465
|
+
if (cancelled) return fail?.(new MicError("failed", "cancelled"));
|
|
2466
|
+
if (failure) return fail?.(failure);
|
|
2467
|
+
const mediaType = audioTypeOf(recorder.mimeType || chunks[0]?.type);
|
|
2468
|
+
finish?.({
|
|
2469
|
+
blob: new Blob(chunks, { type: mediaType }),
|
|
2470
|
+
mediaType,
|
|
2471
|
+
durationMs: Math.max(0, d.now() - startedAt)
|
|
2472
|
+
});
|
|
2473
|
+
};
|
|
2474
|
+
const stopRecorder = () => {
|
|
2475
|
+
try {
|
|
2476
|
+
if (recorder.state !== "inactive") recorder.stop();
|
|
2477
|
+
else recorder.onstop?.();
|
|
2478
|
+
} catch {
|
|
2479
|
+
recorder.onstop?.();
|
|
2480
|
+
}
|
|
2481
|
+
};
|
|
2482
|
+
const maxMs = options.maxMs ?? RECORDING_DEFAULT_MAX_MS;
|
|
2483
|
+
limit = setTimeout(() => {
|
|
2484
|
+
stopRecorder();
|
|
2485
|
+
options.onLimit?.();
|
|
2486
|
+
}, maxMs);
|
|
2487
|
+
try {
|
|
2488
|
+
recorder.start(1e3);
|
|
2489
|
+
} catch (err) {
|
|
2490
|
+
end();
|
|
2491
|
+
throw new MicError(micProblemOf(err) === "failed" ? "unsupported" : micProblemOf(err));
|
|
2492
|
+
}
|
|
2493
|
+
return {
|
|
2494
|
+
startedAt,
|
|
2495
|
+
ended,
|
|
2496
|
+
stop: () => {
|
|
2497
|
+
stopRecorder();
|
|
2498
|
+
return result;
|
|
2499
|
+
},
|
|
2500
|
+
cancel: () => {
|
|
2501
|
+
cancelled = true;
|
|
2502
|
+
chunks.length = 0;
|
|
2503
|
+
stopRecorder();
|
|
2504
|
+
end();
|
|
2505
|
+
}
|
|
2506
|
+
};
|
|
2507
|
+
};
|
|
2508
|
+
|
|
2509
|
+
// src/hooks/use-audio-recorder.ts
|
|
2510
|
+
var useAudioRecorder = (options = {}) => {
|
|
2511
|
+
const opts = useRef4(options);
|
|
2512
|
+
opts.current = options;
|
|
2513
|
+
const [state, setState] = useState5("idle");
|
|
2514
|
+
const [elapsedMs, setElapsed] = useState5(0);
|
|
2515
|
+
const [error, setError] = useState5();
|
|
2516
|
+
const [limited, setLimited] = useState5();
|
|
2517
|
+
const rec = useRef4(void 0);
|
|
2518
|
+
const pending = useRef4(false);
|
|
2519
|
+
const gone = useRef4(false);
|
|
2520
|
+
useEffect5(() => {
|
|
2521
|
+
if (state !== "recording") return;
|
|
2522
|
+
const at = rec.current?.startedAt ?? Date.now();
|
|
2523
|
+
const now = opts.current.now ?? Date.now;
|
|
2524
|
+
setElapsed(Math.max(0, now() - at));
|
|
2525
|
+
const id = setInterval(() => setElapsed(Math.max(0, now() - at)), 250);
|
|
2526
|
+
return () => clearInterval(id);
|
|
2527
|
+
}, [state]);
|
|
2528
|
+
const start = useCallback5(async () => {
|
|
2529
|
+
if (rec.current || pending.current) return;
|
|
2530
|
+
pending.current = true;
|
|
2531
|
+
setError(void 0);
|
|
2532
|
+
setLimited(void 0);
|
|
2533
|
+
setState("starting");
|
|
2534
|
+
try {
|
|
2535
|
+
const started = await startRecording({
|
|
2536
|
+
...opts.current,
|
|
2537
|
+
onLimit: () => {
|
|
2538
|
+
const r = rec.current;
|
|
2539
|
+
rec.current = void 0;
|
|
2540
|
+
setState("stopping");
|
|
2541
|
+
void r?.stop().then(
|
|
2542
|
+
(audio) => !gone.current && setLimited(audio),
|
|
2543
|
+
() => void 0
|
|
2544
|
+
).finally(() => !gone.current && setState("idle"));
|
|
2545
|
+
}
|
|
2546
|
+
});
|
|
2547
|
+
if (gone.current) return started.cancel();
|
|
2548
|
+
rec.current = started;
|
|
2549
|
+
setState("recording");
|
|
2550
|
+
} catch (err) {
|
|
2551
|
+
if (!gone.current) {
|
|
2552
|
+
setError(micProblemOf(err));
|
|
2553
|
+
setState("idle");
|
|
2554
|
+
}
|
|
2555
|
+
} finally {
|
|
2556
|
+
pending.current = false;
|
|
2557
|
+
}
|
|
2558
|
+
}, []);
|
|
2559
|
+
const stop = useCallback5(async () => {
|
|
2560
|
+
const r = rec.current;
|
|
2561
|
+
if (!r) return void 0;
|
|
2562
|
+
rec.current = void 0;
|
|
2563
|
+
setState("stopping");
|
|
2564
|
+
try {
|
|
2565
|
+
return await r.stop();
|
|
2566
|
+
} catch {
|
|
2567
|
+
return void 0;
|
|
2568
|
+
} finally {
|
|
2569
|
+
if (!gone.current) setState("idle");
|
|
2570
|
+
}
|
|
2571
|
+
}, []);
|
|
2572
|
+
const cancel = useCallback5(() => {
|
|
2573
|
+
const r = rec.current;
|
|
2574
|
+
rec.current = void 0;
|
|
2575
|
+
r?.cancel();
|
|
2576
|
+
setLimited(void 0);
|
|
2577
|
+
setState("idle");
|
|
2578
|
+
}, []);
|
|
2579
|
+
useEffect5(() => {
|
|
2580
|
+
gone.current = false;
|
|
2581
|
+
return () => {
|
|
2582
|
+
gone.current = true;
|
|
2583
|
+
rec.current?.cancel();
|
|
2584
|
+
rec.current = void 0;
|
|
2585
|
+
};
|
|
2586
|
+
}, []);
|
|
2587
|
+
return {
|
|
2588
|
+
supported: recordingSupported(options),
|
|
2589
|
+
state,
|
|
2590
|
+
elapsedMs,
|
|
2591
|
+
error,
|
|
2592
|
+
limited,
|
|
2593
|
+
start,
|
|
2594
|
+
stop,
|
|
2595
|
+
cancel,
|
|
2596
|
+
clear: () => {
|
|
2597
|
+
setLimited(void 0);
|
|
2598
|
+
setError(void 0);
|
|
2599
|
+
}
|
|
2600
|
+
};
|
|
2601
|
+
};
|
|
2602
|
+
|
|
2603
|
+
// src/hooks/use-read-aloud.ts
|
|
2604
|
+
import { useCallback as useCallback6, useEffect as useEffect6, useRef as useRef5, useState as useState6 } from "react";
|
|
2605
|
+
var useReadAloud = (speak, lang) => {
|
|
2606
|
+
const [current, setCurrent] = useState6();
|
|
2607
|
+
const [state, setState] = useState6();
|
|
2608
|
+
const [failed, setFailed] = useState6();
|
|
2609
|
+
const playback = useRef5(void 0);
|
|
2610
|
+
const langRef = useRef5(lang);
|
|
2611
|
+
langRef.current = lang;
|
|
2612
|
+
const stop = useCallback6(() => {
|
|
2613
|
+
const now = playback.current;
|
|
2614
|
+
playback.current = void 0;
|
|
2615
|
+
now?.handle.stop();
|
|
2616
|
+
setCurrent(void 0);
|
|
2617
|
+
setState(void 0);
|
|
2618
|
+
}, []);
|
|
2619
|
+
const start = useCallback6(
|
|
2620
|
+
(id, text) => {
|
|
2621
|
+
if (!speak) return;
|
|
2622
|
+
stop();
|
|
2623
|
+
setFailed(void 0);
|
|
2624
|
+
setCurrent(id);
|
|
2625
|
+
setState("loading");
|
|
2626
|
+
const mine = { id, handle: void 0 };
|
|
2627
|
+
playback.current = mine;
|
|
2628
|
+
let handle;
|
|
2629
|
+
try {
|
|
2630
|
+
handle = speak(text, {
|
|
2631
|
+
lang: langRef.current,
|
|
2632
|
+
onState: (s) => {
|
|
2633
|
+
if (playback.current === mine) setState(s);
|
|
2634
|
+
}
|
|
2635
|
+
});
|
|
2636
|
+
} catch (err) {
|
|
2637
|
+
playback.current = void 0;
|
|
2638
|
+
setCurrent(void 0);
|
|
2639
|
+
setState(void 0);
|
|
2640
|
+
const own = err instanceof Error && err.name !== "SpeechOutputError";
|
|
2641
|
+
setFailed({ id, ...own && err.message ? { message: err.message } : {} });
|
|
2642
|
+
return;
|
|
2643
|
+
}
|
|
2644
|
+
mine.handle = handle;
|
|
2645
|
+
handle.done.then(
|
|
2646
|
+
() => {
|
|
2647
|
+
if (playback.current !== mine) return;
|
|
2648
|
+
playback.current = void 0;
|
|
2649
|
+
setCurrent(void 0);
|
|
2650
|
+
setState(void 0);
|
|
2651
|
+
},
|
|
2652
|
+
(err) => {
|
|
2653
|
+
if (playback.current !== mine) return;
|
|
2654
|
+
playback.current = void 0;
|
|
2655
|
+
setCurrent(void 0);
|
|
2656
|
+
setState(void 0);
|
|
2657
|
+
const own = err instanceof Error && err.name !== "SpeechOutputError";
|
|
2658
|
+
setFailed({ id, ...own && err.message ? { message: err.message } : {} });
|
|
2659
|
+
}
|
|
2660
|
+
);
|
|
2661
|
+
},
|
|
2662
|
+
[speak, stop]
|
|
2663
|
+
);
|
|
2664
|
+
useEffect6(() => stop, [speak, stop]);
|
|
2665
|
+
return {
|
|
2666
|
+
current,
|
|
2667
|
+
state,
|
|
2668
|
+
failed,
|
|
2669
|
+
start,
|
|
2670
|
+
pause: () => playback.current?.handle.pause(),
|
|
2671
|
+
resume: () => playback.current?.handle.resume(),
|
|
2672
|
+
stop
|
|
2673
|
+
};
|
|
2674
|
+
};
|
|
2675
|
+
|
|
2676
|
+
// src/hooks/use-speech-voices.ts
|
|
2677
|
+
import { useEffect as useEffect7, useState as useState7 } from "react";
|
|
2678
|
+
var useSpeechVoices = () => {
|
|
2679
|
+
const synth = typeof globalThis !== "undefined" ? globalThis.speechSynthesis : void 0;
|
|
2680
|
+
const read = () => {
|
|
2681
|
+
try {
|
|
2682
|
+
return (synth?.getVoices() ?? []).map((v) => ({
|
|
2683
|
+
voiceURI: v.voiceURI,
|
|
2684
|
+
name: v.name,
|
|
2685
|
+
lang: v.lang,
|
|
2686
|
+
localService: v.localService,
|
|
2687
|
+
default: v.default
|
|
2688
|
+
}));
|
|
2689
|
+
} catch {
|
|
2690
|
+
return [];
|
|
2691
|
+
}
|
|
2692
|
+
};
|
|
2693
|
+
const [voices, setVoices] = useState7(read);
|
|
2694
|
+
useEffect7(() => {
|
|
2695
|
+
if (!synth) return;
|
|
2696
|
+
const update = () => setVoices(read());
|
|
2697
|
+
update();
|
|
2698
|
+
synth.addEventListener?.("voiceschanged", update);
|
|
2699
|
+
return () => synth.removeEventListener?.("voiceschanged", update);
|
|
2700
|
+
}, [synth]);
|
|
2701
|
+
return voices;
|
|
2702
|
+
};
|
|
2703
|
+
|
|
2704
|
+
// src/voice/recognizer.ts
|
|
2705
|
+
var createRecordingRecognizer = (options) => () => {
|
|
2706
|
+
let recording;
|
|
2707
|
+
let starting;
|
|
2708
|
+
let stopAsked = false;
|
|
2709
|
+
let aborted = false;
|
|
2710
|
+
let ended = false;
|
|
2711
|
+
const controller = new AbortController();
|
|
2712
|
+
const rec = {
|
|
2713
|
+
lang: "",
|
|
2714
|
+
continuous: true,
|
|
2715
|
+
interimResults: false,
|
|
2716
|
+
onresult: null,
|
|
2717
|
+
onerror: null,
|
|
2718
|
+
onend: null,
|
|
2719
|
+
start() {
|
|
2720
|
+
if (starting) return;
|
|
2721
|
+
starting = (async () => {
|
|
2722
|
+
try {
|
|
2723
|
+
recording = await startRecording({
|
|
2724
|
+
...options,
|
|
2725
|
+
maxMs: options.maxMs,
|
|
2726
|
+
onLimit: () => rec.stop()
|
|
2727
|
+
});
|
|
2728
|
+
} catch (err) {
|
|
2729
|
+
if (!aborted) rec.onerror?.({ error: micProblemOf(err) });
|
|
2730
|
+
return finish();
|
|
2731
|
+
}
|
|
2732
|
+
if (aborted) {
|
|
2733
|
+
recording.cancel();
|
|
2734
|
+
return finish();
|
|
2735
|
+
}
|
|
2736
|
+
if (stopAsked) void transcribeNow();
|
|
2737
|
+
})();
|
|
2738
|
+
},
|
|
2739
|
+
stop() {
|
|
2740
|
+
if (stopAsked || ended) return;
|
|
2741
|
+
stopAsked = true;
|
|
2742
|
+
if (recording) void transcribeNow();
|
|
2743
|
+
},
|
|
2744
|
+
abort() {
|
|
2745
|
+
if (ended) return;
|
|
2746
|
+
aborted = true;
|
|
2747
|
+
controller.abort();
|
|
2748
|
+
recording?.cancel();
|
|
2749
|
+
if (!starting || recording) finish();
|
|
2750
|
+
}
|
|
2751
|
+
};
|
|
2752
|
+
const finish = () => {
|
|
2753
|
+
if (ended) return;
|
|
2754
|
+
ended = true;
|
|
2755
|
+
rec.onend?.();
|
|
2756
|
+
};
|
|
2757
|
+
let transcribing = false;
|
|
2758
|
+
const transcribeNow = async () => {
|
|
2759
|
+
if (transcribing || !recording) return;
|
|
2760
|
+
transcribing = true;
|
|
2761
|
+
let audio;
|
|
2762
|
+
try {
|
|
2763
|
+
audio = await recording.stop();
|
|
2764
|
+
} catch (err) {
|
|
2765
|
+
if (!aborted) rec.onerror?.({ error: micProblemOf(err) });
|
|
2766
|
+
return finish();
|
|
2767
|
+
}
|
|
2768
|
+
if (aborted) return finish();
|
|
2769
|
+
if (audio.blob.size === 0) return finish();
|
|
2770
|
+
try {
|
|
2771
|
+
const text = (await options.transcribe(audio, { lang: rec.lang, signal: controller.signal })).replace(/\s+/g, " ").trim();
|
|
2772
|
+
if (!aborted && text)
|
|
2773
|
+
rec.onresult?.({
|
|
2774
|
+
resultIndex: 0,
|
|
2775
|
+
results: [{ isFinal: true, 0: { transcript: text } }]
|
|
2776
|
+
});
|
|
2777
|
+
} catch (err) {
|
|
2778
|
+
if (!aborted)
|
|
2779
|
+
rec.onerror?.({
|
|
2780
|
+
error: "transcription",
|
|
2781
|
+
message: err instanceof Error ? err.message : String(err)
|
|
2782
|
+
});
|
|
2783
|
+
}
|
|
2784
|
+
finish();
|
|
2785
|
+
};
|
|
2786
|
+
return rec;
|
|
2787
|
+
};
|
|
2788
|
+
|
|
2789
|
+
// src/voice/speak.ts
|
|
2790
|
+
var SpeechOutputError = class extends Error {
|
|
2791
|
+
code;
|
|
2792
|
+
constructor(code) {
|
|
2793
|
+
super(code);
|
|
2794
|
+
this.name = "SpeechOutputError";
|
|
2795
|
+
this.code = code;
|
|
2796
|
+
}
|
|
2797
|
+
};
|
|
2798
|
+
var asOutputError = (err) => err instanceof SpeechOutputError ? err : new SpeechOutputError(
|
|
2799
|
+
err && typeof err === "object" && "name" in err ? String(err.name) : "playback-failed"
|
|
2800
|
+
);
|
|
2801
|
+
var speakableText = (markdown, options = {}) => {
|
|
2802
|
+
const out = [];
|
|
2803
|
+
const lines = markdown.replace(/\r\n?/g, "\n").split("\n");
|
|
2804
|
+
let fence;
|
|
2805
|
+
let fenceSaid = false;
|
|
2806
|
+
for (const raw of lines) {
|
|
2807
|
+
const line = raw.trimEnd();
|
|
2808
|
+
const opener = /^\s*(`{3,}|~{3,})/.exec(line);
|
|
2809
|
+
if (fence !== void 0) {
|
|
2810
|
+
if (opener && opener[1][0] === fence[0] && opener[1].length >= fence.length) fence = void 0;
|
|
2811
|
+
continue;
|
|
2812
|
+
}
|
|
2813
|
+
if (opener) {
|
|
2814
|
+
fence = opener[1];
|
|
2815
|
+
if (options.code && !fenceSaid) out.push(options.code);
|
|
2816
|
+
fenceSaid = true;
|
|
2817
|
+
continue;
|
|
2818
|
+
}
|
|
2819
|
+
fenceSaid = false;
|
|
2820
|
+
if (/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/.test(line)) continue;
|
|
2821
|
+
if (/^\s*([-*_])\s*(\1\s*){2,}$/.test(line)) continue;
|
|
2822
|
+
let text = line.replace(/^\s{0,3}#{1,6}\s+/, "").replace(/^\s*>\s?/, "").replace(/^\s*(?:[-*+]|\d+[.)])\s+(\[[ xX]\]\s+)?/, "");
|
|
2823
|
+
if (/^\s*\|.*\|\s*$/.test(text))
|
|
2824
|
+
text = text.replace(/^\s*\||\|\s*$/g, "").split("|").map((c) => c.trim()).filter(Boolean).join(", ");
|
|
2825
|
+
text = text.replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/\[([^\]]+)\]\([^)]*\)/g, "$1").replace(/<(https?:\/\/[^>\s]+)>/g, (_m, url) => hostOf(url)).replace(/\bhttps?:\/\/[^\s)]+/g, (url) => hostOf(url)).replace(/`+([^`]*)`+/g, "$1").replace(/(\*\*|__)(.+?)\1/g, "$2").replace(/(^|[^\w*])[*_]([^*_\s][^*_]*?)[*_](?=[^\w*]|$)/g, "$1$2").replace(/~~(.+?)~~/g, "$1").replace(/<\/?[a-z][^>]*>/gi, "").replace(/[*_#`~>|]/g, " ").replace(/\s+/g, " ").trim();
|
|
2826
|
+
if (!text) continue;
|
|
2827
|
+
out.push(/[.!?…:;。!?]$/.test(text) ? text : `${text}.`);
|
|
2828
|
+
}
|
|
2829
|
+
return out.join(" ").trim();
|
|
2830
|
+
};
|
|
2831
|
+
var hostOf = (url) => {
|
|
2832
|
+
try {
|
|
2833
|
+
return new URL(url).hostname.replace(/^www\./, "");
|
|
2834
|
+
} catch {
|
|
2835
|
+
return "";
|
|
2836
|
+
}
|
|
2837
|
+
};
|
|
2838
|
+
var splitForSpeech = (text, max = 220) => {
|
|
2839
|
+
const pieces = [];
|
|
2840
|
+
let rest = text.trim();
|
|
2841
|
+
while (rest.length > max) {
|
|
2842
|
+
const window2 = rest.slice(0, max + 1);
|
|
2843
|
+
let cut = -1;
|
|
2844
|
+
for (const m of window2.matchAll(/[.!?…。!?;:](\s|$)/g))
|
|
2845
|
+
if (m.index !== void 0 && m.index + 1 <= max) cut = m.index + 1;
|
|
2846
|
+
if (cut < max / 3) cut = window2.lastIndexOf(" ");
|
|
2847
|
+
if (cut <= 0) cut = max;
|
|
2848
|
+
pieces.push(rest.slice(0, cut).trim());
|
|
2849
|
+
rest = rest.slice(cut).trim();
|
|
2850
|
+
}
|
|
2851
|
+
if (rest) pieces.push(rest);
|
|
2852
|
+
return pieces;
|
|
2853
|
+
};
|
|
2854
|
+
var voiceFor = (voices, lang, preferred) => {
|
|
2855
|
+
if (preferred) {
|
|
2856
|
+
const chosen = voices.find((v) => v.voiceURI === preferred);
|
|
2857
|
+
if (chosen) return chosen;
|
|
2858
|
+
}
|
|
2859
|
+
if (!lang) return void 0;
|
|
2860
|
+
const norm = (l) => l.toLowerCase().replace(/_/g, "-");
|
|
2861
|
+
const want = norm(lang);
|
|
2862
|
+
const base = want.split("-")[0];
|
|
2863
|
+
const rank = (v) => [v.localService ? 1 : 0, v.default ? 1 : 0];
|
|
2864
|
+
const best = (list) => [...list].sort((a, b) => {
|
|
2865
|
+
const ra = rank(a);
|
|
2866
|
+
const rb = rank(b);
|
|
2867
|
+
return rb[0] - ra[0] || rb[1] - ra[1] || a.name.localeCompare(b.name);
|
|
2868
|
+
})[0];
|
|
2869
|
+
const exact = voices.filter((v) => norm(v.lang) === want);
|
|
2870
|
+
if (exact.length) return best(exact);
|
|
2871
|
+
const same = voices.filter((v) => norm(v.lang).split("-")[0] === base);
|
|
2872
|
+
return same.length ? best(same) : void 0;
|
|
2873
|
+
};
|
|
2874
|
+
var voicesOf = (voices, lang) => {
|
|
2875
|
+
if (!lang) return [...voices];
|
|
2876
|
+
const base = lang.toLowerCase().split(/[-_]/)[0];
|
|
2877
|
+
return voices.filter((v) => v.lang.toLowerCase().split(/[-_]/)[0] === base);
|
|
2878
|
+
};
|
|
2879
|
+
var speechSynthesisSupported = () => typeof globalThis !== "undefined" && "speechSynthesis" in globalThis && typeof globalThis.SpeechSynthesisUtterance === "function";
|
|
2880
|
+
var createBrowserSpeaker = (options = {}) => (text, { lang, onState }) => {
|
|
2881
|
+
const synth = options.synth ?? globalThis.speechSynthesis;
|
|
2882
|
+
const make = options.createUtterance ?? ((t) => new globalThis.SpeechSynthesisUtterance(t));
|
|
2883
|
+
const voice = voiceFor(synth.getVoices(), lang, options.voice);
|
|
2884
|
+
let settle;
|
|
2885
|
+
let fail;
|
|
2886
|
+
const done = new Promise((resolve, reject) => {
|
|
2887
|
+
settle = resolve;
|
|
2888
|
+
fail = reject;
|
|
2889
|
+
});
|
|
2890
|
+
done.catch(() => {
|
|
2891
|
+
});
|
|
2892
|
+
let over = false;
|
|
2893
|
+
const end = (err) => {
|
|
2894
|
+
if (over) return;
|
|
2895
|
+
over = true;
|
|
2896
|
+
if (err) fail(err);
|
|
2897
|
+
else settle();
|
|
2898
|
+
};
|
|
2899
|
+
const pieces = splitForSpeech(text);
|
|
2900
|
+
synth.cancel();
|
|
2901
|
+
if (pieces.length === 0) {
|
|
2902
|
+
end();
|
|
2903
|
+
return { pause() {
|
|
2904
|
+
}, resume() {
|
|
2905
|
+
}, stop() {
|
|
2906
|
+
}, done };
|
|
2907
|
+
}
|
|
2908
|
+
let started = false;
|
|
2909
|
+
pieces.forEach((piece, i) => {
|
|
2910
|
+
const u = make(piece);
|
|
2911
|
+
u.lang = voice?.lang ?? lang ?? "";
|
|
2912
|
+
try {
|
|
2913
|
+
u.voice = voice ?? null;
|
|
2914
|
+
} catch {
|
|
2915
|
+
}
|
|
2916
|
+
u.rate = options.rate ?? 1;
|
|
2917
|
+
u.onstart = () => {
|
|
2918
|
+
if (!started && !over) onState("playing");
|
|
2919
|
+
started = true;
|
|
2920
|
+
};
|
|
2921
|
+
u.onend = () => {
|
|
2922
|
+
if (i === pieces.length - 1) end();
|
|
2923
|
+
};
|
|
2924
|
+
u.onerror = (event) => {
|
|
2925
|
+
if (event.error === "interrupted" || event.error === "canceled") end();
|
|
2926
|
+
else end(new SpeechOutputError(event.error || "synthesis-failed"));
|
|
2927
|
+
};
|
|
2928
|
+
synth.speak(u);
|
|
2929
|
+
});
|
|
2930
|
+
onState("loading");
|
|
2931
|
+
return {
|
|
2932
|
+
pause: () => {
|
|
2933
|
+
if (over) return;
|
|
2934
|
+
synth.pause();
|
|
2935
|
+
onState("paused");
|
|
2936
|
+
},
|
|
2937
|
+
resume: () => {
|
|
2938
|
+
if (over) return;
|
|
2939
|
+
synth.resume();
|
|
2940
|
+
onState("playing");
|
|
2941
|
+
},
|
|
2942
|
+
stop: () => {
|
|
2943
|
+
if (over) return;
|
|
2944
|
+
synth.cancel();
|
|
2945
|
+
end();
|
|
2946
|
+
},
|
|
2947
|
+
done
|
|
2948
|
+
};
|
|
2949
|
+
};
|
|
2950
|
+
var silence = () => {
|
|
2951
|
+
const samples = 16;
|
|
2952
|
+
const view = new DataView(new ArrayBuffer(44 + samples * 2));
|
|
2953
|
+
const text = (at, s) => {
|
|
2954
|
+
for (let i = 0; i < s.length; i++) view.setUint8(at + i, s.charCodeAt(i));
|
|
2955
|
+
};
|
|
2956
|
+
text(0, "RIFF");
|
|
2957
|
+
view.setUint32(4, 36 + samples * 2, true);
|
|
2958
|
+
text(8, "WAVEfmt ");
|
|
2959
|
+
view.setUint32(16, 16, true);
|
|
2960
|
+
view.setUint16(20, 1, true);
|
|
2961
|
+
view.setUint16(22, 1, true);
|
|
2962
|
+
view.setUint32(24, 8e3, true);
|
|
2963
|
+
view.setUint32(28, 16e3, true);
|
|
2964
|
+
view.setUint16(32, 2, true);
|
|
2965
|
+
view.setUint16(34, 16, true);
|
|
2966
|
+
text(36, "data");
|
|
2967
|
+
view.setUint32(40, samples * 2, true);
|
|
2968
|
+
return new Blob([view.buffer], { type: "audio/wav" });
|
|
2969
|
+
};
|
|
2970
|
+
var createAudioSpeaker = (options) => (text, { lang, onState }) => {
|
|
2971
|
+
const urls = options.objectUrl ?? {
|
|
2972
|
+
create: (b) => URL.createObjectURL(b),
|
|
2973
|
+
revoke: (u) => URL.revokeObjectURL(u)
|
|
2974
|
+
};
|
|
2975
|
+
const audio = options.createAudio?.() ?? new Audio();
|
|
2976
|
+
const controller = new AbortController();
|
|
2977
|
+
const pieces = splitForSpeech(text, options.maxChars ?? 2e3);
|
|
2978
|
+
let settle;
|
|
2979
|
+
let fail;
|
|
2980
|
+
const done = new Promise((resolve, reject) => {
|
|
2981
|
+
settle = resolve;
|
|
2982
|
+
fail = reject;
|
|
2983
|
+
});
|
|
2984
|
+
done.catch(() => {
|
|
2985
|
+
});
|
|
2986
|
+
let over = false;
|
|
2987
|
+
let paused = false;
|
|
2988
|
+
let current;
|
|
2989
|
+
const made = /* @__PURE__ */ new Map();
|
|
2990
|
+
const make = (i) => {
|
|
2991
|
+
if (!made.has(i)) {
|
|
2992
|
+
const p = options.synthesize(pieces[i], { lang, signal: controller.signal });
|
|
2993
|
+
p.catch(() => {
|
|
2994
|
+
});
|
|
2995
|
+
made.set(i, p);
|
|
2996
|
+
}
|
|
2997
|
+
return made.get(i);
|
|
2998
|
+
};
|
|
2999
|
+
const release = () => {
|
|
3000
|
+
if (current) urls.revoke(current);
|
|
3001
|
+
current = void 0;
|
|
3002
|
+
};
|
|
3003
|
+
const end = (err) => {
|
|
3004
|
+
if (over) return;
|
|
3005
|
+
over = true;
|
|
3006
|
+
controller.abort();
|
|
3007
|
+
audio.pause();
|
|
3008
|
+
audio.onended = null;
|
|
3009
|
+
audio.onerror = null;
|
|
3010
|
+
release();
|
|
3011
|
+
if (err) fail(err);
|
|
3012
|
+
else settle();
|
|
3013
|
+
};
|
|
3014
|
+
const playFrom = async (i) => {
|
|
3015
|
+
if (over) return;
|
|
3016
|
+
if (i >= pieces.length) return end();
|
|
3017
|
+
onState(i === 0 || !current ? "loading" : "playing");
|
|
3018
|
+
let blob;
|
|
3019
|
+
try {
|
|
3020
|
+
blob = await make(i);
|
|
3021
|
+
} catch (err) {
|
|
3022
|
+
return end(err instanceof Error ? err : new Error(String(err)));
|
|
3023
|
+
}
|
|
3024
|
+
if (over) return;
|
|
3025
|
+
if (i + 1 < pieces.length) make(i + 1);
|
|
3026
|
+
release();
|
|
3027
|
+
current = urls.create(blob);
|
|
3028
|
+
audio.src = current;
|
|
3029
|
+
audio.onended = () => void playFrom(i + 1);
|
|
3030
|
+
audio.onerror = () => end(new SpeechOutputError("playback-failed"));
|
|
3031
|
+
if (paused) return onState("paused");
|
|
3032
|
+
try {
|
|
3033
|
+
await audio.play();
|
|
3034
|
+
if (!over) onState("playing");
|
|
3035
|
+
} catch (err) {
|
|
3036
|
+
end(asOutputError(err));
|
|
3037
|
+
}
|
|
3038
|
+
};
|
|
3039
|
+
if (pieces.length === 0) end();
|
|
3040
|
+
else {
|
|
3041
|
+
if (options.unlock !== false) {
|
|
3042
|
+
current = urls.create(silence());
|
|
3043
|
+
audio.src = current;
|
|
3044
|
+
audio.play().catch(() => {
|
|
3045
|
+
});
|
|
3046
|
+
}
|
|
3047
|
+
void playFrom(0);
|
|
3048
|
+
}
|
|
3049
|
+
return {
|
|
3050
|
+
pause: () => {
|
|
3051
|
+
if (over) return;
|
|
3052
|
+
paused = true;
|
|
3053
|
+
audio.pause();
|
|
3054
|
+
onState("paused");
|
|
3055
|
+
},
|
|
3056
|
+
resume: () => {
|
|
3057
|
+
if (over || !paused) return;
|
|
3058
|
+
paused = false;
|
|
3059
|
+
if (current)
|
|
3060
|
+
audio.play().then(
|
|
3061
|
+
() => !over && onState("playing"),
|
|
3062
|
+
(err) => end(asOutputError(err))
|
|
3063
|
+
);
|
|
3064
|
+
else onState("loading");
|
|
3065
|
+
},
|
|
3066
|
+
stop: () => end(),
|
|
3067
|
+
done
|
|
3068
|
+
};
|
|
3069
|
+
};
|
|
3070
|
+
|
|
2298
3071
|
// src/hooks/use-credentials.ts
|
|
2299
|
-
import { useCallback as
|
|
3072
|
+
import { useCallback as useCallback7, useEffect as useEffect8, useMemo as useMemo3, useState as useState8 } from "react";
|
|
2300
3073
|
import * as core5 from "@dudko.dev/agent-web";
|
|
2301
3074
|
import { VaultCredentialStore } from "@dudko.dev/agent-web";
|
|
2302
3075
|
var storeDbName = (store) => {
|
|
@@ -2304,10 +3077,10 @@ var storeDbName = (store) => {
|
|
|
2304
3077
|
return typeof name === "string" && name ? name : void 0;
|
|
2305
3078
|
};
|
|
2306
3079
|
var useCredentials = (store) => {
|
|
2307
|
-
const resolved =
|
|
2308
|
-
const [version, setVersion] =
|
|
3080
|
+
const resolved = useMemo3(() => store ?? new VaultCredentialStore(), [store]);
|
|
3081
|
+
const [version, setVersion] = useState8(0);
|
|
2309
3082
|
const dbName = storeDbName(resolved);
|
|
2310
|
-
|
|
3083
|
+
useEffect8(() => {
|
|
2311
3084
|
return followOtherTabs(
|
|
2312
3085
|
core5,
|
|
2313
3086
|
dbName,
|
|
@@ -2315,21 +3088,21 @@ var useCredentials = (store) => {
|
|
|
2315
3088
|
() => setVersion((v) => v + 1)
|
|
2316
3089
|
);
|
|
2317
3090
|
}, [dbName]);
|
|
2318
|
-
const setKey =
|
|
3091
|
+
const setKey = useCallback7(
|
|
2319
3092
|
async (ref, key) => {
|
|
2320
3093
|
await resolved.setApiKey(ref, key);
|
|
2321
3094
|
setVersion((v) => v + 1);
|
|
2322
3095
|
},
|
|
2323
3096
|
[resolved]
|
|
2324
3097
|
);
|
|
2325
|
-
const removeKey =
|
|
3098
|
+
const removeKey = useCallback7(
|
|
2326
3099
|
async (ref) => {
|
|
2327
3100
|
await resolved.deleteApiKey(ref);
|
|
2328
3101
|
setVersion((v) => v + 1);
|
|
2329
3102
|
},
|
|
2330
3103
|
[resolved]
|
|
2331
3104
|
);
|
|
2332
|
-
const hasKey =
|
|
3105
|
+
const hasKey = useCallback7(
|
|
2333
3106
|
async (ref) => await resolved.getApiKey(ref) !== void 0,
|
|
2334
3107
|
[resolved]
|
|
2335
3108
|
);
|
|
@@ -2346,21 +3119,21 @@ import {
|
|
|
2346
3119
|
} from "@dudko.dev/agent-web";
|
|
2347
3120
|
|
|
2348
3121
|
// src/hooks/use-local-model.ts
|
|
2349
|
-
import { useCallback as
|
|
3122
|
+
import { useCallback as useCallback8, useRef as useRef6, useState as useState9 } from "react";
|
|
2350
3123
|
var keyOf = (id, tokens) => tokens ? `${id}@${tokens}` : id;
|
|
2351
3124
|
var useLocalModel = (modelId, engine, options) => {
|
|
2352
|
-
const [loaded, setLoaded] =
|
|
2353
|
-
const [pending, setPending] =
|
|
2354
|
-
const [failure, setFailure] =
|
|
2355
|
-
const engineRef =
|
|
3125
|
+
const [loaded, setLoaded] = useState9(void 0);
|
|
3126
|
+
const [pending, setPending] = useState9();
|
|
3127
|
+
const [failure, setFailure] = useState9();
|
|
3128
|
+
const engineRef = useRef6(engine);
|
|
2356
3129
|
engineRef.current = engine;
|
|
2357
|
-
const loadedRef =
|
|
2358
|
-
const inflightRef =
|
|
3130
|
+
const loadedRef = useRef6(void 0);
|
|
3131
|
+
const inflightRef = useRef6(
|
|
2359
3132
|
void 0
|
|
2360
3133
|
);
|
|
2361
3134
|
const windowTokens = options?.contextWindowTokens;
|
|
2362
3135
|
const key = keyOf(modelId, windowTokens);
|
|
2363
|
-
const seqRef =
|
|
3136
|
+
const seqRef = useRef6(0);
|
|
2364
3137
|
const setHeld = (next) => {
|
|
2365
3138
|
loadedRef.current = next;
|
|
2366
3139
|
setLoaded(next);
|
|
@@ -2371,7 +3144,7 @@ var useLocalModel = (modelId, engine, options) => {
|
|
|
2371
3144
|
} catch {
|
|
2372
3145
|
}
|
|
2373
3146
|
};
|
|
2374
|
-
const load =
|
|
3147
|
+
const load = useCallback8(() => {
|
|
2375
3148
|
const id = modelId;
|
|
2376
3149
|
if (loadedRef.current?.key === key) return Promise.resolve(loadedRef.current.model);
|
|
2377
3150
|
if (inflightRef.current?.key === key) return inflightRef.current.promise;
|
|
@@ -2423,7 +3196,7 @@ var useLocalModel = (modelId, engine, options) => {
|
|
|
2423
3196
|
inflightRef.current = { key, promise };
|
|
2424
3197
|
return promise;
|
|
2425
3198
|
}, [modelId, key]);
|
|
2426
|
-
const unload =
|
|
3199
|
+
const unload = useCallback8(async () => {
|
|
2427
3200
|
seqRef.current++;
|
|
2428
3201
|
inflightRef.current = void 0;
|
|
2429
3202
|
setPending(void 0);
|
|
@@ -2485,7 +3258,7 @@ var createWebLLMEngine = (options) => {
|
|
|
2485
3258
|
};
|
|
2486
3259
|
|
|
2487
3260
|
// src/labels.tsx
|
|
2488
|
-
import { createContext, useContext, useMemo as
|
|
3261
|
+
import { createContext, useContext, useMemo as useMemo4 } from "react";
|
|
2489
3262
|
|
|
2490
3263
|
// src/composer.ts
|
|
2491
3264
|
var parseSlash = (text) => {
|
|
@@ -2651,6 +3424,27 @@ var noticesOf = (state, texts = {}) => {
|
|
|
2651
3424
|
}
|
|
2652
3425
|
return out;
|
|
2653
3426
|
};
|
|
3427
|
+
var formatClock = (ms) => {
|
|
3428
|
+
const s = Math.max(0, Math.floor(ms / 1e3));
|
|
3429
|
+
const two = (n) => String(n).padStart(2, "0");
|
|
3430
|
+
const h = Math.floor(s / 3600);
|
|
3431
|
+
const m = Math.floor(s % 3600 / 60);
|
|
3432
|
+
return h > 0 ? `${h}:${two(m)}:${two(s % 60)}` : `${m}:${two(s % 60)}`;
|
|
3433
|
+
};
|
|
3434
|
+
var micProblemText = (code, message, labels) => {
|
|
3435
|
+
if (code === "not-allowed" || code === "service-not-allowed") return labels.micDenied;
|
|
3436
|
+
if (code === "audio-capture") return labels.micMissing;
|
|
3437
|
+
if (code === "busy") return labels.micBusy;
|
|
3438
|
+
if (code === "unsupported") return labels.micUnsupported;
|
|
3439
|
+
if (message) return message;
|
|
3440
|
+
return code && code !== "transcription" && code !== "failed" ? `${labels.dictationFailed} (${code})` : labels.dictationFailed;
|
|
3441
|
+
};
|
|
3442
|
+
var voiceMessageName = (at, extension) => {
|
|
3443
|
+
const two = (n) => String(n).padStart(2, "0");
|
|
3444
|
+
return `voice-${at.getFullYear()}-${two(at.getMonth() + 1)}-${two(at.getDate())}-${two(
|
|
3445
|
+
at.getHours()
|
|
3446
|
+
)}${two(at.getMinutes())}${two(at.getSeconds())}.${extension}`;
|
|
3447
|
+
};
|
|
2654
3448
|
|
|
2655
3449
|
// src/labels.tsx
|
|
2656
3450
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -2707,6 +3501,19 @@ var defaultLabels = {
|
|
|
2707
3501
|
dictateTitle: "Dictate \u2014 speech to text in the browser",
|
|
2708
3502
|
stopDictation: "Stop dictation",
|
|
2709
3503
|
microphone: "Microphone",
|
|
3504
|
+
transcribing: "Transcribing\u2026",
|
|
3505
|
+
micDenied: "The microphone is blocked for this site. Allow it in the browser's site settings (the icon beside the address), then try again.",
|
|
3506
|
+
micMissing: "No microphone was found on this device.",
|
|
3507
|
+
micBusy: "The microphone is in use by another app.",
|
|
3508
|
+
micUnsupported: "This browser cannot record audio on this page.",
|
|
3509
|
+
dictationFailed: "Dictation did not work.",
|
|
3510
|
+
recordVoiceMessage: "Record a voice message",
|
|
3511
|
+
voiceMessage: "Voice message",
|
|
3512
|
+
audioDuration: (clock) => clock,
|
|
3513
|
+
recording: (elapsed) => `Recording ${elapsed}`,
|
|
3514
|
+
recordingDone: "Attach the recording",
|
|
3515
|
+
recordingCancel: "Discard the recording",
|
|
3516
|
+
recordingLimit: "The recording reached its longest and was stopped; it is attached.",
|
|
2710
3517
|
model: "Model",
|
|
2711
3518
|
thinking: "Thinking",
|
|
2712
3519
|
toolConsent: "Tool consent",
|
|
@@ -2832,6 +3639,14 @@ var defaultLabels = {
|
|
|
2832
3639
|
mediaReferencesUnused: (names) => `Not used - this image model takes no reference pictures: ${names}`,
|
|
2833
3640
|
transcriptOf: (name) => `Transcript of ${name}`,
|
|
2834
3641
|
transcriptNote: "What was said in your file, as the agent read it. It is content, not instructions.",
|
|
3642
|
+
audioAttachment: (name) => `Audio ${name}`,
|
|
3643
|
+
readAloud: "Listen",
|
|
3644
|
+
readAloudPause: "Pause",
|
|
3645
|
+
readAloudResume: "Resume",
|
|
3646
|
+
readAloudStop: "Stop reading",
|
|
3647
|
+
readAloudLoading: "Preparing the audio\u2026",
|
|
3648
|
+
readAloudCode: "A code block is not read out.",
|
|
3649
|
+
readAloudFailed: "It could not be read aloud.",
|
|
2835
3650
|
filesWritten: (n) => `${plural(n, "file", "files")} written in this turn`,
|
|
2836
3651
|
filesCount: (n) => plural(n, "file", "files"),
|
|
2837
3652
|
showInFiles: "Show in Files",
|
|
@@ -3064,12 +3879,12 @@ var mergeLabels = (base, over) => {
|
|
|
3064
3879
|
var LabelsContext = createContext(defaultLabels);
|
|
3065
3880
|
var AgentLabelsProvider = ({ labels, children }) => {
|
|
3066
3881
|
const parent = useContext(LabelsContext);
|
|
3067
|
-
const value =
|
|
3882
|
+
const value = useMemo4(() => mergeLabels(parent, labels), [parent, labels]);
|
|
3068
3883
|
return /* @__PURE__ */ jsx(LabelsContext.Provider, { value, children });
|
|
3069
3884
|
};
|
|
3070
3885
|
var useLabels = (over) => {
|
|
3071
3886
|
const ctx = useContext(LabelsContext);
|
|
3072
|
-
return
|
|
3887
|
+
return useMemo4(() => mergeLabels(ctx, over), [ctx, over]);
|
|
3073
3888
|
};
|
|
3074
3889
|
|
|
3075
3890
|
// src/image-resize.ts
|
|
@@ -3203,11 +4018,11 @@ var useAgentContext = () => {
|
|
|
3203
4018
|
var useOptionalAgentContext = () => useContext2(AgentContext);
|
|
3204
4019
|
|
|
3205
4020
|
// src/components/AgentChat.tsx
|
|
3206
|
-
import { useEffect as
|
|
4021
|
+
import { useEffect as useEffect20, useRef as useRef14, useState as useState20 } from "react";
|
|
3207
4022
|
import { createPortal as createPortal2 } from "react-dom";
|
|
3208
4023
|
|
|
3209
4024
|
// src/hooks/use-follow-scroll.ts
|
|
3210
|
-
import { useEffect as
|
|
4025
|
+
import { useEffect as useEffect9, useLayoutEffect, useRef as useRef7 } from "react";
|
|
3211
4026
|
|
|
3212
4027
|
// src/follow-scroll.ts
|
|
3213
4028
|
var FOLLOW_REJOIN_PX = 80;
|
|
@@ -3224,7 +4039,7 @@ var followsAfterScroll = (following, before, now) => {
|
|
|
3224
4039
|
var followsAfterResize = (following, before, now) => following && !(now.clientHeight === before.clientHeight && now.scrollHeight >= before.scrollHeight && now.scrollTop < reach(before) - FOLLOW_LEAVE_PX);
|
|
3225
4040
|
|
|
3226
4041
|
// src/hooks/use-follow-scroll.ts
|
|
3227
|
-
var useIsoLayoutEffect = typeof window === "undefined" ?
|
|
4042
|
+
var useIsoLayoutEffect = typeof window === "undefined" ? useEffect9 : useLayoutEffect;
|
|
3228
4043
|
var measure = (el) => ({
|
|
3229
4044
|
scrollTop: el.scrollTop,
|
|
3230
4045
|
scrollHeight: el.scrollHeight,
|
|
@@ -3246,12 +4061,12 @@ var anchorOf = (el) => {
|
|
|
3246
4061
|
return marks.length ? { marks, top: el.scrollTop } : void 0;
|
|
3247
4062
|
};
|
|
3248
4063
|
var useFollowScroll = (ref, turn, live = true) => {
|
|
3249
|
-
const following =
|
|
3250
|
-
const last =
|
|
3251
|
-
const anchor =
|
|
3252
|
-
const settle =
|
|
4064
|
+
const following = useRef7(true);
|
|
4065
|
+
const last = useRef7(void 0);
|
|
4066
|
+
const anchor = useRef7(void 0);
|
|
4067
|
+
const settle = useRef7(() => {
|
|
3253
4068
|
});
|
|
3254
|
-
const arriving =
|
|
4069
|
+
const arriving = useRef7(live);
|
|
3255
4070
|
arriving.current = live;
|
|
3256
4071
|
useIsoLayoutEffect(() => {
|
|
3257
4072
|
const el = ref.current;
|
|
@@ -3324,7 +4139,7 @@ var useFollowScroll = (ref, turn, live = true) => {
|
|
|
3324
4139
|
};
|
|
3325
4140
|
|
|
3326
4141
|
// src/hooks/use-mcp-app-host.ts
|
|
3327
|
-
import { useCallback as
|
|
4142
|
+
import { useCallback as useCallback9, useEffect as useEffect10, useMemo as useMemo5, useRef as useRef8, useState as useState10 } from "react";
|
|
3328
4143
|
|
|
3329
4144
|
// src/mcp-app.ts
|
|
3330
4145
|
import { mcpAppOrigin } from "@dudko.dev/agent-web";
|
|
@@ -4151,27 +4966,27 @@ var useMcpAppHost = ({
|
|
|
4151
4966
|
sampling = false,
|
|
4152
4967
|
sample: sampleFn
|
|
4153
4968
|
}) => {
|
|
4154
|
-
const [requests, setRequests] =
|
|
4155
|
-
const [draft, setDraft] =
|
|
4156
|
-
const waiting =
|
|
4969
|
+
const [requests, setRequests] = useState10([]);
|
|
4970
|
+
const [draft, setDraft] = useState10();
|
|
4971
|
+
const waiting = useRef8(
|
|
4157
4972
|
/* @__PURE__ */ new Map()
|
|
4158
4973
|
);
|
|
4159
|
-
const samplingAllowed =
|
|
4160
|
-
const sampleRef =
|
|
4974
|
+
const samplingAllowed = useRef8(/* @__PURE__ */ new Set());
|
|
4975
|
+
const sampleRef = useRef8(sampleFn);
|
|
4161
4976
|
sampleRef.current = sampleFn;
|
|
4162
|
-
const [gated, setGated] =
|
|
4163
|
-
const connectionRef =
|
|
4977
|
+
const [gated, setGated] = useState10({});
|
|
4978
|
+
const connectionRef = useRef8(connection);
|
|
4164
4979
|
connectionRef.current = connection;
|
|
4165
|
-
const approveRef =
|
|
4980
|
+
const approveRef = useRef8(approve);
|
|
4166
4981
|
approveRef.current = approve;
|
|
4167
|
-
|
|
4982
|
+
useEffect10(
|
|
4168
4983
|
() => () => {
|
|
4169
4984
|
for (const { resolve } of waiting.current.values()) resolve(false);
|
|
4170
4985
|
waiting.current.clear();
|
|
4171
4986
|
},
|
|
4172
4987
|
[]
|
|
4173
4988
|
);
|
|
4174
|
-
const ask =
|
|
4989
|
+
const ask = useCallback9(
|
|
4175
4990
|
(request, signal, extra = {}) => {
|
|
4176
4991
|
for (const w of waiting.current.values()) {
|
|
4177
4992
|
if (w.request.appId === request.appId) {
|
|
@@ -4196,7 +5011,7 @@ var useMcpAppHost = ({
|
|
|
4196
5011
|
},
|
|
4197
5012
|
[]
|
|
4198
5013
|
);
|
|
4199
|
-
const answer =
|
|
5014
|
+
const answer = useCallback9((id, accept, options) => {
|
|
4200
5015
|
const w = waiting.current.get(id);
|
|
4201
5016
|
if (!w) return;
|
|
4202
5017
|
if (accept && w.request.kind === "link" && w.request.link) {
|
|
@@ -4222,16 +5037,16 @@ var useMcpAppHost = ({
|
|
|
4222
5037
|
}
|
|
4223
5038
|
w.resolve(accept);
|
|
4224
5039
|
}, []);
|
|
4225
|
-
const read =
|
|
5040
|
+
const read = useCallback9((app, signal) => {
|
|
4226
5041
|
const c = connectionRef.current;
|
|
4227
5042
|
if (!c) return Promise.reject(new Error(`no connection to the server \u201C${app.server}\u201D`));
|
|
4228
5043
|
return c.readUiResource(app.server, app.resourceUri, signal ? { signal } : void 0);
|
|
4229
5044
|
}, []);
|
|
4230
|
-
const tool =
|
|
5045
|
+
const tool = useCallback9(
|
|
4231
5046
|
(app) => connectionRef.current?.appTool(app.server, app.toolName),
|
|
4232
5047
|
[]
|
|
4233
5048
|
);
|
|
4234
|
-
const callTool =
|
|
5049
|
+
const callTool = useCallback9(
|
|
4235
5050
|
async (app, name, args, signal) => {
|
|
4236
5051
|
const c = connectionRef.current;
|
|
4237
5052
|
if (!c) throw refused(`The server \u201C${app.server}\u201D is not connected`);
|
|
@@ -4268,15 +5083,15 @@ var useMcpAppHost = ({
|
|
|
4268
5083
|
},
|
|
4269
5084
|
[]
|
|
4270
5085
|
);
|
|
4271
|
-
const openLink =
|
|
5086
|
+
const openLink = useCallback9(
|
|
4272
5087
|
(app, link, signal) => ask({ appId: app.id, server: app.server, kind: "link", link }, signal),
|
|
4273
5088
|
[ask]
|
|
4274
5089
|
);
|
|
4275
|
-
const message =
|
|
5090
|
+
const message = useCallback9(
|
|
4276
5091
|
(app, text, signal) => ask({ appId: app.id, server: app.server, kind: "message", text }, signal),
|
|
4277
5092
|
[ask]
|
|
4278
5093
|
);
|
|
4279
|
-
const downloadFile2 =
|
|
5094
|
+
const downloadFile2 = useCallback9(
|
|
4280
5095
|
async (app, file, signal) => {
|
|
4281
5096
|
const c = connectionRef.current;
|
|
4282
5097
|
if (file.kind === "link" && !c) throw refused(`The server \u201C${app.server}\u201D is not connected`);
|
|
@@ -4299,7 +5114,7 @@ var useMcpAppHost = ({
|
|
|
4299
5114
|
},
|
|
4300
5115
|
[ask]
|
|
4301
5116
|
);
|
|
4302
|
-
const sample =
|
|
5117
|
+
const sample = useCallback9(
|
|
4303
5118
|
async (app, params, signal) => {
|
|
4304
5119
|
const fn = sampleRef.current;
|
|
4305
5120
|
if (!fn) throw refused("This host cannot answer sampling requests");
|
|
@@ -4320,19 +5135,19 @@ var useMcpAppHost = ({
|
|
|
4320
5135
|
},
|
|
4321
5136
|
[ask]
|
|
4322
5137
|
);
|
|
4323
|
-
const pendingAppServers =
|
|
5138
|
+
const pendingAppServers = useMemo5(
|
|
4324
5139
|
() => new Set(
|
|
4325
5140
|
approvals.filter((a) => a.app && a.status === "pending").map((a) => `${a.app.server}\0${a.app.resourceUri}`)
|
|
4326
5141
|
),
|
|
4327
5142
|
[approvals]
|
|
4328
5143
|
);
|
|
4329
|
-
const isWaiting =
|
|
5144
|
+
const isWaiting = useCallback9(
|
|
4330
5145
|
(app) => requests.some((r) => r.appId === app.id) || Boolean(gated[app.id]) && pendingAppServers.has(`${app.server}\0${app.resourceUri}`),
|
|
4331
5146
|
[requests, gated, pendingAppServers]
|
|
4332
5147
|
);
|
|
4333
5148
|
const sandboxUrl = sandbox?.url;
|
|
4334
5149
|
const sandboxTimeout = sandbox?.timeoutMs;
|
|
4335
|
-
const sandboxSetting =
|
|
5150
|
+
const sandboxSetting = useMemo5(
|
|
4336
5151
|
() => sandboxUrl === void 0 ? void 0 : {
|
|
4337
5152
|
url: sandboxUrl,
|
|
4338
5153
|
...sandboxTimeout !== void 0 ? { timeoutMs: sandboxTimeout } : {}
|
|
@@ -4340,7 +5155,7 @@ var useMcpAppHost = ({
|
|
|
4340
5155
|
[sandboxUrl, sandboxTimeout]
|
|
4341
5156
|
);
|
|
4342
5157
|
const samplingOn = sampling && Boolean(sampleFn);
|
|
4343
|
-
return
|
|
5158
|
+
return useMemo5(
|
|
4344
5159
|
() => ({
|
|
4345
5160
|
connected: Boolean(connection),
|
|
4346
5161
|
read,
|
|
@@ -4495,11 +5310,11 @@ var AppRequestPrompt = ({
|
|
|
4495
5310
|
};
|
|
4496
5311
|
|
|
4497
5312
|
// src/components/McpAppFrame.tsx
|
|
4498
|
-
import { useEffect as
|
|
5313
|
+
import { useEffect as useEffect11, useLayoutEffect as useLayoutEffect2, useMemo as useMemo6, useRef as useRef9, useState as useState11 } from "react";
|
|
4499
5314
|
import { Fragment, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
4500
5315
|
var HOST_INFO = { name: "@dudko.dev/agent-web-react", version: "1" };
|
|
4501
5316
|
var MAX_LISTED_CALLS = 12;
|
|
4502
|
-
var useIsoLayoutEffect2 = typeof window === "undefined" ?
|
|
5317
|
+
var useIsoLayoutEffect2 = typeof window === "undefined" ? useEffect11 : useLayoutEffect2;
|
|
4503
5318
|
var userActivation = () => typeof navigator === "undefined" ? void 0 : navigator.userActivation?.isActive;
|
|
4504
5319
|
var silentSandboxes = /* @__PURE__ */ new Set();
|
|
4505
5320
|
var warned = /* @__PURE__ */ new Set();
|
|
@@ -4532,36 +5347,36 @@ var McpAppFrame = ({
|
|
|
4532
5347
|
className
|
|
4533
5348
|
}) => {
|
|
4534
5349
|
const L = useLabels(labels);
|
|
4535
|
-
const [collapsed, setCollapsed] =
|
|
4536
|
-
const [menu, setMenu] =
|
|
4537
|
-
const [reload, setReload] =
|
|
4538
|
-
const [loaded, setLoaded] =
|
|
4539
|
-
const [height, setHeight] =
|
|
4540
|
-
const [calls, setCalls] =
|
|
4541
|
-
const [fallback, setFallback] =
|
|
4542
|
-
const [broken, setBroken] =
|
|
4543
|
-
const [onOrigin, setOnOrigin] =
|
|
4544
|
-
const shellLoaded =
|
|
4545
|
-
const [mode, setMode] =
|
|
4546
|
-
const modeRef =
|
|
4547
|
-
const [holder, setHolder] =
|
|
4548
|
-
const [fullRect, setFullRect] =
|
|
4549
|
-
const leaveRef =
|
|
4550
|
-
const rootRef =
|
|
4551
|
-
const exitRef =
|
|
4552
|
-
const allowFullscreenRef =
|
|
5350
|
+
const [collapsed, setCollapsed] = useState11(defaultCollapsed);
|
|
5351
|
+
const [menu, setMenu] = useState11(false);
|
|
5352
|
+
const [reload, setReload] = useState11(0);
|
|
5353
|
+
const [loaded, setLoaded] = useState11();
|
|
5354
|
+
const [height, setHeight] = useState11(APP_DEFAULT_HEIGHT);
|
|
5355
|
+
const [calls, setCalls] = useState11([]);
|
|
5356
|
+
const [fallback, setFallback] = useState11();
|
|
5357
|
+
const [broken, setBroken] = useState11(false);
|
|
5358
|
+
const [onOrigin, setOnOrigin] = useState11(false);
|
|
5359
|
+
const shellLoaded = useRef9(void 0);
|
|
5360
|
+
const [mode, setMode] = useState11("inline");
|
|
5361
|
+
const modeRef = useRef9("inline");
|
|
5362
|
+
const [holder, setHolder] = useState11(0);
|
|
5363
|
+
const [fullRect, setFullRect] = useState11();
|
|
5364
|
+
const leaveRef = useRef9(void 0);
|
|
5365
|
+
const rootRef = useRef9(null);
|
|
5366
|
+
const exitRef = useRef9(null);
|
|
5367
|
+
const allowFullscreenRef = useRef9(allowFullscreen);
|
|
4553
5368
|
allowFullscreenRef.current = allowFullscreen;
|
|
4554
|
-
const iframeRef =
|
|
4555
|
-
const bridgeRef =
|
|
4556
|
-
const menuRef =
|
|
4557
|
-
const themeRef =
|
|
5369
|
+
const iframeRef = useRef9(null);
|
|
5370
|
+
const bridgeRef = useRef9(void 0);
|
|
5371
|
+
const menuRef = useRef9(null);
|
|
5372
|
+
const themeRef = useRef9(theme);
|
|
4558
5373
|
themeRef.current = theme;
|
|
4559
|
-
const hostRef =
|
|
5374
|
+
const hostRef = useRef9(host);
|
|
4560
5375
|
hostRef.current = host;
|
|
4561
|
-
const appRef =
|
|
5376
|
+
const appRef = useRef9(app);
|
|
4562
5377
|
appRef.current = app;
|
|
4563
5378
|
const live = !collapsed;
|
|
4564
|
-
|
|
5379
|
+
useEffect11(() => {
|
|
4565
5380
|
if (!live) return;
|
|
4566
5381
|
if (!hostRef.current.connected) {
|
|
4567
5382
|
setLoaded({ unavailable: true });
|
|
@@ -4584,7 +5399,7 @@ var McpAppFrame = ({
|
|
|
4584
5399
|
const resource = loaded && "resource" in loaded ? loaded.resource : void 0;
|
|
4585
5400
|
const sandboxUrl = host.sandbox?.url;
|
|
4586
5401
|
const timeoutMs = host.sandbox?.timeoutMs ?? MCP_APP_SANDBOX_TIMEOUT_MS;
|
|
4587
|
-
const placement =
|
|
5402
|
+
const placement = useMemo6(() => {
|
|
4588
5403
|
if (!resource) return void 0;
|
|
4589
5404
|
if (sandboxUrl === void 0) return { mode: "opaque" };
|
|
4590
5405
|
if (fallback) return { mode: "opaque", reason: fallback };
|
|
@@ -4595,11 +5410,11 @@ var McpAppFrame = ({
|
|
|
4595
5410
|
if (!url) return { mode: "opaque", reason: "too-many-origins" };
|
|
4596
5411
|
return { mode: "origin", origin: target.origin, url };
|
|
4597
5412
|
}, [resource, sandboxUrl, fallback, app.server, reload]);
|
|
4598
|
-
const doc =
|
|
5413
|
+
const doc = useMemo6(
|
|
4599
5414
|
() => !resource || !placement ? void 0 : placement.mode === "origin" ? buildMcpAppSandboxShell(placement.url) : buildMcpAppDocument(resource.html, resource.csp),
|
|
4600
5415
|
[resource, placement]
|
|
4601
5416
|
);
|
|
4602
|
-
|
|
5417
|
+
useEffect11(() => {
|
|
4603
5418
|
const reason = placement?.mode === "opaque" ? placement.reason : void 0;
|
|
4604
5419
|
if (reason && reason !== "no-answer" && sandboxUrl !== void 0) {
|
|
4605
5420
|
warnOnce(
|
|
@@ -4608,7 +5423,7 @@ var McpAppFrame = ({
|
|
|
4608
5423
|
);
|
|
4609
5424
|
}
|
|
4610
5425
|
}, [placement, sandboxUrl]);
|
|
4611
|
-
|
|
5426
|
+
useEffect11(() => {
|
|
4612
5427
|
const frame = iframeRef.current;
|
|
4613
5428
|
if (!live || !resource || !frame || !placement || broken) return;
|
|
4614
5429
|
const abort = new AbortController();
|
|
@@ -4753,7 +5568,7 @@ var McpAppFrame = ({
|
|
|
4753
5568
|
}, [live, resource, reload, variant, app.id, placement, broken, timeoutMs]);
|
|
4754
5569
|
const fullscreen = mode === "fullscreen" && live && !broken;
|
|
4755
5570
|
const waitingNow = host.isWaiting(app);
|
|
4756
|
-
|
|
5571
|
+
useEffect11(() => {
|
|
4757
5572
|
if (fullscreen && waitingNow) leaveRef.current?.();
|
|
4758
5573
|
}, [fullscreen, waitingNow]);
|
|
4759
5574
|
useIsoLayoutEffect2(() => {
|
|
@@ -4788,7 +5603,7 @@ var McpAppFrame = ({
|
|
|
4788
5603
|
ro?.disconnect();
|
|
4789
5604
|
};
|
|
4790
5605
|
}, [fullscreen]);
|
|
4791
|
-
|
|
5606
|
+
useEffect11(() => {
|
|
4792
5607
|
if (!fullscreen) return;
|
|
4793
5608
|
const before = document.activeElement;
|
|
4794
5609
|
exitRef.current?.focus();
|
|
@@ -4805,10 +5620,10 @@ var McpAppFrame = ({
|
|
|
4805
5620
|
if (frame && (before === frame || document.activeElement === document.body)) frame.focus();
|
|
4806
5621
|
};
|
|
4807
5622
|
}, [fullscreen]);
|
|
4808
|
-
|
|
5623
|
+
useEffect11(() => {
|
|
4809
5624
|
if (theme) bridgeRef.current?.updateContext({ theme });
|
|
4810
5625
|
}, [theme]);
|
|
4811
|
-
|
|
5626
|
+
useEffect11(() => {
|
|
4812
5627
|
if (!menu) return;
|
|
4813
5628
|
const close = (e) => {
|
|
4814
5629
|
if (e instanceof KeyboardEvent ? e.key === "Escape" : !menuRef.current?.contains(e.target)) {
|
|
@@ -5113,7 +5928,7 @@ var McpAppLine = ({ app, note, action, onAction, labels, className }) => {
|
|
|
5113
5928
|
};
|
|
5114
5929
|
|
|
5115
5930
|
// src/components/AgentComposer.tsx
|
|
5116
|
-
import { Fragment as Fragment2, useEffect as
|
|
5931
|
+
import { Fragment as Fragment2, useEffect as useEffect12, useLayoutEffect as useLayoutEffect3, useMemo as useMemo7, useRef as useRef10, useState as useState12 } from "react";
|
|
5117
5932
|
import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
5118
5933
|
var thinkingDefaults = (l) => [
|
|
5119
5934
|
{ id: "off", label: l.thinkingLevels.off },
|
|
@@ -5125,7 +5940,7 @@ var thinkingDefaults = (l) => [
|
|
|
5125
5940
|
var MODES = ["autopilot", "ask-writes", "ask-all", "read-only"];
|
|
5126
5941
|
var ModeIcon = ({ mode }) => mode === "autopilot" ? /* @__PURE__ */ jsx5(BoltIcon, { size: 14 }) : mode === "read-only" ? /* @__PURE__ */ jsx5(EyeIcon, { size: 14 }) : /* @__PURE__ */ jsx5(ShieldIcon, { size: 14 });
|
|
5127
5942
|
var useMenuKeys = (open, menuRef, chipRef, close) => {
|
|
5128
|
-
|
|
5943
|
+
useEffect12(() => {
|
|
5129
5944
|
if (!open) return;
|
|
5130
5945
|
const menu = menuRef.current;
|
|
5131
5946
|
const rows = menu ? [...menu.querySelectorAll('[role^="menuitem"]')] : [];
|
|
@@ -5153,9 +5968,9 @@ var useMenuKeys = (open, menuRef, chipRef, close) => {
|
|
|
5153
5968
|
};
|
|
5154
5969
|
var opensMenu = (key) => key === "ArrowDown" || key === "ArrowUp";
|
|
5155
5970
|
var attachSeq = 0;
|
|
5156
|
-
var useIsoLayoutEffect3 = typeof window === "undefined" ?
|
|
5971
|
+
var useIsoLayoutEffect3 = typeof window === "undefined" ? useEffect12 : useLayoutEffect3;
|
|
5157
5972
|
var useMenuPlacement = (open, anchor, align) => {
|
|
5158
|
-
const [style, setStyle] =
|
|
5973
|
+
const [style, setStyle] = useState12();
|
|
5159
5974
|
useIsoLayoutEffect3(() => {
|
|
5160
5975
|
if (!open) return;
|
|
5161
5976
|
const place = () => {
|
|
@@ -5216,6 +6031,7 @@ var AgentComposer = ({
|
|
|
5216
6031
|
files: vfs,
|
|
5217
6032
|
dropZone = "self",
|
|
5218
6033
|
speech = true,
|
|
6034
|
+
voiceMessage = false,
|
|
5219
6035
|
showTimer = true,
|
|
5220
6036
|
showAgents = true,
|
|
5221
6037
|
showApprovalMode = true,
|
|
@@ -5233,41 +6049,52 @@ var AgentComposer = ({
|
|
|
5233
6049
|
const L = useLabels(labelsOverride);
|
|
5234
6050
|
const MODE_CHIP = L.modes;
|
|
5235
6051
|
const DEFAULT_THINKING = thinkingDefaults(L);
|
|
5236
|
-
const [text, setText] =
|
|
5237
|
-
const [pending, setPendingState] =
|
|
5238
|
-
const pendingRef =
|
|
6052
|
+
const [text, setText] = useState12("");
|
|
6053
|
+
const [pending, setPendingState] = useState12([]);
|
|
6054
|
+
const pendingRef = useRef10([]);
|
|
5239
6055
|
const setPending = (next) => {
|
|
5240
6056
|
pendingRef.current = typeof next === "function" ? next(pendingRef.current) : next;
|
|
5241
6057
|
setPendingState(pendingRef.current);
|
|
5242
6058
|
};
|
|
5243
|
-
const [menu, setMenu] =
|
|
5244
|
-
const [active, setActive] =
|
|
5245
|
-
const [dismissed, setDismissed] =
|
|
5246
|
-
const [attachError, setAttachError] =
|
|
5247
|
-
const [dragging, setDragging] =
|
|
5248
|
-
const rootRef =
|
|
5249
|
-
const modelRef =
|
|
5250
|
-
const modeRef =
|
|
5251
|
-
const modelChipRef =
|
|
5252
|
-
const modeChipRef =
|
|
5253
|
-
const modelMenuRef =
|
|
5254
|
-
const modeMenuRef =
|
|
5255
|
-
const [dropRect, setDropRect] =
|
|
5256
|
-
const [compactBar, setCompactBar] =
|
|
5257
|
-
|
|
6059
|
+
const [menu, setMenu] = useState12(void 0);
|
|
6060
|
+
const [active, setActive] = useState12(0);
|
|
6061
|
+
const [dismissed, setDismissed] = useState12(() => /* @__PURE__ */ new Set());
|
|
6062
|
+
const [attachError, setAttachError] = useState12();
|
|
6063
|
+
const [dragging, setDragging] = useState12(false);
|
|
6064
|
+
const rootRef = useRef10(null);
|
|
6065
|
+
const modelRef = useRef10(null);
|
|
6066
|
+
const modeRef = useRef10(null);
|
|
6067
|
+
const modelChipRef = useRef10(null);
|
|
6068
|
+
const modeChipRef = useRef10(null);
|
|
6069
|
+
const modelMenuRef = useRef10(null);
|
|
6070
|
+
const modeMenuRef = useRef10(null);
|
|
6071
|
+
const [dropRect, setDropRect] = useState12();
|
|
6072
|
+
const [compactBar, setCompactBar] = useState12(false);
|
|
6073
|
+
const [barWidth, setBarWidth] = useState12(0);
|
|
6074
|
+
useEffect12(() => {
|
|
5258
6075
|
const el = rootRef.current;
|
|
5259
6076
|
if (!el || typeof ResizeObserver === "undefined") return;
|
|
5260
|
-
const ro = new ResizeObserver(
|
|
5261
|
-
|
|
5262
|
-
|
|
6077
|
+
const ro = new ResizeObserver(() => {
|
|
6078
|
+
const width = el.getBoundingClientRect().width;
|
|
6079
|
+
setCompactBar(width < compactWidth);
|
|
6080
|
+
setBarWidth(Math.round(width));
|
|
6081
|
+
});
|
|
5263
6082
|
ro.observe(el);
|
|
5264
6083
|
return () => ro.disconnect();
|
|
5265
6084
|
}, [compactWidth]);
|
|
5266
|
-
const
|
|
5267
|
-
const
|
|
6085
|
+
const chipLabelRef = useRef10(null);
|
|
6086
|
+
const [chipShort, setChipShort] = useState12(false);
|
|
6087
|
+
useLayoutEffect3(() => setChipShort(false), [barWidth, model?.label, model?.shortLabel]);
|
|
6088
|
+
useLayoutEffect3(() => {
|
|
6089
|
+
const el = chipLabelRef.current;
|
|
6090
|
+
if (chipShort || !el || !model?.shortLabel) return;
|
|
6091
|
+
if (el.scrollWidth > el.clientWidth + 1) setChipShort(true);
|
|
6092
|
+
});
|
|
6093
|
+
const fileRef = useRef10(null);
|
|
6094
|
+
const inputRef = useRef10(null);
|
|
5268
6095
|
const draftId = draft?.id;
|
|
5269
6096
|
const draftText = draft?.text;
|
|
5270
|
-
|
|
6097
|
+
useEffect12(() => {
|
|
5271
6098
|
if (draftId === void 0 || !draftText) return;
|
|
5272
6099
|
setText((t) => t.trim() ? `${t.trimEnd()}
|
|
5273
6100
|
${draftText}` : draftText);
|
|
@@ -5281,13 +6108,20 @@ ${draftText}` : draftText);
|
|
|
5281
6108
|
const caps = agent.agent?.capabilities;
|
|
5282
6109
|
const stt = useSpeechToText({
|
|
5283
6110
|
lang: typeof speech === "object" ? speech.lang : void 0,
|
|
6111
|
+
createRecognizer: typeof speech === "object" ? speech.createRecognizer : void 0,
|
|
5284
6112
|
onFinal: (heard) => setText((t) => t.trim() ? `${t.trimEnd()} ${heard}` : heard)
|
|
5285
6113
|
});
|
|
5286
6114
|
const showMic = speech !== false && stt.supported;
|
|
5287
|
-
const
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
6115
|
+
const recorder = useAudioRecorder({
|
|
6116
|
+
maxMs: typeof voiceMessage === "object" ? voiceMessage.maxMs : void 0
|
|
6117
|
+
});
|
|
6118
|
+
const showVoice = voiceMessage !== false && attachments !== false && recorder.supported;
|
|
6119
|
+
const recordingOn = recorder.state !== "idle";
|
|
6120
|
+
const [voiceNote, setVoiceNote] = useState12();
|
|
6121
|
+
const [startedAt, setStartedAt] = useState12();
|
|
6122
|
+
const [now, setNow] = useState12(() => Date.now());
|
|
6123
|
+
const [lastElapsed, setLastElapsed] = useState12();
|
|
6124
|
+
useEffect12(() => {
|
|
5291
6125
|
if (!busy) {
|
|
5292
6126
|
if (startedAt !== void 0) setLastElapsed(Date.now() - startedAt);
|
|
5293
6127
|
setStartedAt(void 0);
|
|
@@ -5300,7 +6134,7 @@ ${draftText}` : draftText);
|
|
|
5300
6134
|
return () => clearInterval(id);
|
|
5301
6135
|
}, [busy]);
|
|
5302
6136
|
const elapsed = startedAt !== void 0 ? now - startedAt : lastElapsed;
|
|
5303
|
-
const allCommands =
|
|
6137
|
+
const allCommands = useMemo7(() => {
|
|
5304
6138
|
const out = [];
|
|
5305
6139
|
if (builtinCommands) {
|
|
5306
6140
|
out.push(
|
|
@@ -5383,8 +6217,8 @@ ${draftText}` : draftText);
|
|
|
5383
6217
|
const closeMenu = () => setMenu(void 0);
|
|
5384
6218
|
const modelMenuKeys = useMenuKeys(menu === "model", modelMenuRef, modelChipRef, closeMenu);
|
|
5385
6219
|
const modeMenuKeys = useMenuKeys(menu === "mode", modeMenuRef, modeChipRef, closeMenu);
|
|
5386
|
-
|
|
5387
|
-
|
|
6220
|
+
useEffect12(() => setActive(0), [text, menu]);
|
|
6221
|
+
useEffect12(() => {
|
|
5388
6222
|
if (!menu) return;
|
|
5389
6223
|
const onDown = (e) => {
|
|
5390
6224
|
if (!rootRef.current?.contains(e.target)) setMenu(void 0);
|
|
@@ -5511,6 +6345,44 @@ ${draftText}` : draftText);
|
|
|
5511
6345
|
setAttachError(said.filter(Boolean).join(" ") || void 0);
|
|
5512
6346
|
if (fileRef.current) fileRef.current.value = "";
|
|
5513
6347
|
};
|
|
6348
|
+
const addRecording = async (audio) => {
|
|
6349
|
+
if (audio.blob.size === 0) return;
|
|
6350
|
+
const name = voiceMessageName(/* @__PURE__ */ new Date(), audioExtensionOf(audio.mediaType));
|
|
6351
|
+
const over = attachmentOverLimit({ bytes: audio.blob.size }, "sent", "none", bounds);
|
|
6352
|
+
if (over) {
|
|
6353
|
+
setAttachError(overLimitText(L.voiceMessage, over));
|
|
6354
|
+
return;
|
|
6355
|
+
}
|
|
6356
|
+
const a = {
|
|
6357
|
+
id: `att-${attachSeq += 1}`,
|
|
6358
|
+
name,
|
|
6359
|
+
kind: "file",
|
|
6360
|
+
mediaType: audio.mediaType,
|
|
6361
|
+
dataUrl: await readDataUrl2(audio.blob),
|
|
6362
|
+
bytes: audio.blob.size,
|
|
6363
|
+
durationMs: audio.durationMs,
|
|
6364
|
+
note: L.audioDuration(formatClock(audio.durationMs))
|
|
6365
|
+
};
|
|
6366
|
+
if (messageOverLimit(pendingRef.current, a, bounds) === "bytes") {
|
|
6367
|
+
setAttachError(
|
|
6368
|
+
L.messageTooLarge(L.voiceMessage, Math.round(bounds.maxTotalBytes / 1024 / 1024))
|
|
6369
|
+
);
|
|
6370
|
+
return;
|
|
6371
|
+
}
|
|
6372
|
+
setPending((cur) => [...cur, a]);
|
|
6373
|
+
};
|
|
6374
|
+
const finishRecording = async () => {
|
|
6375
|
+
const audio = await recorder.stop();
|
|
6376
|
+
if (audio) await addRecording(audio);
|
|
6377
|
+
inputRef.current?.focus();
|
|
6378
|
+
};
|
|
6379
|
+
const limited = recorder.limited;
|
|
6380
|
+
useEffect12(() => {
|
|
6381
|
+
if (!limited) return;
|
|
6382
|
+
recorder.clear();
|
|
6383
|
+
setVoiceNote(L.recordingLimit);
|
|
6384
|
+
void addRecording(limited);
|
|
6385
|
+
}, [limited]);
|
|
5514
6386
|
const onPaste = (e) => {
|
|
5515
6387
|
if (attachments === false) return;
|
|
5516
6388
|
const pasted = Array.from(e.clipboardData?.files ?? []);
|
|
@@ -5518,9 +6390,9 @@ ${draftText}` : draftText);
|
|
|
5518
6390
|
e.preventDefault();
|
|
5519
6391
|
void addFiles(pasted);
|
|
5520
6392
|
};
|
|
5521
|
-
const addFilesRef =
|
|
6393
|
+
const addFilesRef = useRef10(addFiles);
|
|
5522
6394
|
addFilesRef.current = addFiles;
|
|
5523
|
-
|
|
6395
|
+
useEffect12(() => {
|
|
5524
6396
|
if (attachments === false) return;
|
|
5525
6397
|
const target = dropZone === "window" ? globalThis.window : dropZone === "self" ? rootRef.current : dropZone.current;
|
|
5526
6398
|
if (!target) return;
|
|
@@ -5642,10 +6514,11 @@ ${draftText}` : draftText);
|
|
|
5642
6514
|
mediaType: a.mediaType,
|
|
5643
6515
|
size: a.bytes,
|
|
5644
6516
|
...a.kind === "image" && a.dataUrl ? { dataUrl: a.dataUrl } : {},
|
|
5645
|
-
...a.path ? { path: a.path } : {}
|
|
6517
|
+
...a.path ? { path: a.path } : {},
|
|
6518
|
+
...a.durationMs !== void 0 ? { durationMs: a.durationMs } : {}
|
|
5646
6519
|
}));
|
|
5647
6520
|
const full = withAttachments(goal || L.seeAttachments, items);
|
|
5648
|
-
const label = shown
|
|
6521
|
+
const label = shown;
|
|
5649
6522
|
void agent.run(full, {
|
|
5650
6523
|
...full !== label ? { label } : {},
|
|
5651
6524
|
images: items.filter((a) => a.kind === "image" && a.dataUrl).map(toModel),
|
|
@@ -5686,16 +6559,24 @@ ${draftText}` : draftText);
|
|
|
5686
6559
|
...attachError ? [{ id: `attach:${attachError}`, tone: "warn", text: attachError }] : [],
|
|
5687
6560
|
...stt.error ? [
|
|
5688
6561
|
{
|
|
5689
|
-
id: `stt:${stt.error}`,
|
|
6562
|
+
id: `stt:${stt.error}:${stt.errorMessage ?? ""}`,
|
|
5690
6563
|
tone: "warn",
|
|
5691
|
-
text:
|
|
6564
|
+
text: micProblemText(stt.error, stt.errorMessage, L)
|
|
5692
6565
|
}
|
|
5693
|
-
] : []
|
|
6566
|
+
] : [],
|
|
6567
|
+
...recorder.error ? [
|
|
6568
|
+
{
|
|
6569
|
+
id: `rec:${recorder.error}`,
|
|
6570
|
+
tone: "warn",
|
|
6571
|
+
text: micProblemText(recorder.error, void 0, L)
|
|
6572
|
+
}
|
|
6573
|
+
] : [],
|
|
6574
|
+
...voiceNote ? [{ id: `voice:${voiceNote}`, tone: "info", text: voiceNote }] : []
|
|
5694
6575
|
].filter((n) => !dismissed.has(n.id)) : [];
|
|
5695
6576
|
const runningAgents = agent.subagents.filter((s) => s.status === "running");
|
|
5696
6577
|
const thinkingOptions = thinking?.options ?? DEFAULT_THINKING;
|
|
5697
6578
|
const thinkingLabel = thinking ? thinkingOptions.find((o) => o.id === thinking.value)?.label ?? thinking.value : void 0;
|
|
5698
|
-
const canSend = ready && (text.trim().length > 0 || pending.length > 0);
|
|
6579
|
+
const canSend = ready && !recordingOn && (text.trim().length > 0 || pending.length > 0);
|
|
5699
6580
|
const canSteer = busy && steering && text.trim().length > 0;
|
|
5700
6581
|
const queuedStrip = showQueued && (agent.queued.length > 0 || agent.undelivered.length > 0) ? /* @__PURE__ */ jsxs3("div", { className: "awr-queued", children: [
|
|
5701
6582
|
agent.queued.map((q) => /* @__PURE__ */ jsxs3("div", { className: "awr-queued__item", role: "status", children: [
|
|
@@ -5739,6 +6620,8 @@ ${draftText}` : draftText);
|
|
|
5739
6620
|
onClick: () => {
|
|
5740
6621
|
setDismissed((d) => new Set(d).add(n.id));
|
|
5741
6622
|
if (n.id.startsWith("attach:")) setAttachError(void 0);
|
|
6623
|
+
if (n.id.startsWith("rec:")) recorder.clear();
|
|
6624
|
+
if (n.id.startsWith("voice:")) setVoiceNote(void 0);
|
|
5742
6625
|
},
|
|
5743
6626
|
children: /* @__PURE__ */ jsx5(XIcon, { size: 14 })
|
|
5744
6627
|
}
|
|
@@ -5776,7 +6659,7 @@ ${draftText}` : draftText);
|
|
|
5776
6659
|
const remove = () => setPending((cur) => cur.filter((x) => x.id !== a.id));
|
|
5777
6660
|
if (renderAttachment) return /* @__PURE__ */ jsx5("span", { children: renderAttachment(a, remove) }, a.id);
|
|
5778
6661
|
return /* @__PURE__ */ jsxs3("span", { className: "awr-chip awr-file", title: a.note ?? a.mediaType, children: [
|
|
5779
|
-
a.kind === "image" && a.dataUrl ? /* @__PURE__ */ jsx5("img", { className: "awr-file__thumb", src: a.dataUrl, alt: a.name }) : /* @__PURE__ */ jsx5(FileIcon, { size: 14 }),
|
|
6662
|
+
a.kind === "image" && a.dataUrl ? /* @__PURE__ */ jsx5("img", { className: "awr-file__thumb", src: a.dataUrl, alt: a.name }) : a.mediaType.startsWith("audio/") ? /* @__PURE__ */ jsx5(WaveIcon, { size: 14 }) : /* @__PURE__ */ jsx5(FileIcon, { size: 14 }),
|
|
5780
6663
|
a.note ? /* @__PURE__ */ jsxs3("span", { className: "awr-file__text", children: [
|
|
5781
6664
|
/* @__PURE__ */ jsx5("span", { className: "awr-file__name", children: a.name }),
|
|
5782
6665
|
/* @__PURE__ */ jsx5("span", { className: "awr-file__note", children: a.note })
|
|
@@ -5793,6 +6676,33 @@ ${draftText}` : draftText);
|
|
|
5793
6676
|
)
|
|
5794
6677
|
] }, a.id);
|
|
5795
6678
|
}) }),
|
|
6679
|
+
showVoice && recordingOn && /* @__PURE__ */ jsxs3("div", { className: "awr-recording", role: "status", "aria-live": "polite", children: [
|
|
6680
|
+
/* @__PURE__ */ jsx5("span", { className: "awr-recording__dot", "aria-hidden": "true" }),
|
|
6681
|
+
/* @__PURE__ */ jsx5("span", { className: "awr-recording__time", children: L.recording(formatClock(recorder.elapsedMs)) }),
|
|
6682
|
+
/* @__PURE__ */ jsx5(
|
|
6683
|
+
"button",
|
|
6684
|
+
{
|
|
6685
|
+
type: "button",
|
|
6686
|
+
className: "awr-iconbtn",
|
|
6687
|
+
"aria-label": L.recordingCancel,
|
|
6688
|
+
title: L.recordingCancel,
|
|
6689
|
+
onClick: recorder.cancel,
|
|
6690
|
+
children: /* @__PURE__ */ jsx5(XIcon, { size: 16 })
|
|
6691
|
+
}
|
|
6692
|
+
),
|
|
6693
|
+
/* @__PURE__ */ jsx5(
|
|
6694
|
+
"button",
|
|
6695
|
+
{
|
|
6696
|
+
type: "button",
|
|
6697
|
+
className: "awr-iconbtn awr-recording__done",
|
|
6698
|
+
"aria-label": L.recordingDone,
|
|
6699
|
+
title: L.recordingDone,
|
|
6700
|
+
onClick: () => void finishRecording(),
|
|
6701
|
+
disabled: recorder.state !== "recording",
|
|
6702
|
+
children: /* @__PURE__ */ jsx5(CheckIcon, { size: 16 })
|
|
6703
|
+
}
|
|
6704
|
+
)
|
|
6705
|
+
] }),
|
|
5796
6706
|
/* @__PURE__ */ jsxs3("div", { className: "awr-composer2__inputrow", children: [
|
|
5797
6707
|
/* @__PURE__ */ jsx5(
|
|
5798
6708
|
"textarea",
|
|
@@ -5803,7 +6713,7 @@ ${draftText}` : draftText);
|
|
|
5803
6713
|
onChange: (e) => setText(e.target.value),
|
|
5804
6714
|
onKeyDown,
|
|
5805
6715
|
onPaste,
|
|
5806
|
-
placeholder: stt.listening ? L.listening : busy && steering ? L.placeholderBusy : placeholder ?? L.placeholder,
|
|
6716
|
+
placeholder: stt.finishing ? L.transcribing : stt.listening ? L.listening : busy && steering ? L.placeholderBusy : placeholder ?? L.placeholder,
|
|
5807
6717
|
disabled,
|
|
5808
6718
|
rows: 2,
|
|
5809
6719
|
"aria-label": L.message
|
|
@@ -5813,16 +6723,18 @@ ${draftText}` : draftText);
|
|
|
5813
6723
|
"button",
|
|
5814
6724
|
{
|
|
5815
6725
|
type: "button",
|
|
5816
|
-
className: `awr-iconbtn awr-mic${stt.listening ? " is-on" : ""}`,
|
|
6726
|
+
className: `awr-iconbtn awr-mic${stt.listening ? " is-on" : ""}${stt.finishing ? " is-busy" : ""}`,
|
|
5817
6727
|
"aria-label": stt.listening ? L.stopDictation : L.dictate,
|
|
6728
|
+
"aria-pressed": stt.listening,
|
|
5818
6729
|
title: stt.listening ? L.stopDictation : L.dictateTitle,
|
|
5819
6730
|
onClick: stt.toggle,
|
|
5820
|
-
disabled,
|
|
5821
|
-
children: /* @__PURE__ */ jsx5(MicIcon, { size: 18 })
|
|
6731
|
+
disabled: disabled || recordingOn || stt.finishing,
|
|
6732
|
+
children: stt.finishing ? /* @__PURE__ */ jsx5(SpinnerIcon, { size: 18 }) : /* @__PURE__ */ jsx5(MicIcon, { size: 18 })
|
|
5822
6733
|
}
|
|
5823
6734
|
)
|
|
5824
6735
|
] }),
|
|
5825
6736
|
stt.listening && stt.interim && /* @__PURE__ */ jsx5("div", { className: "awr-composer2__interim", children: stt.interim }),
|
|
6737
|
+
stt.finishing && /* @__PURE__ */ jsx5("div", { className: "awr-composer2__interim", role: "status", children: L.transcribing }),
|
|
5826
6738
|
/* @__PURE__ */ jsxs3("div", { className: "awr-toolbar", children: [
|
|
5827
6739
|
attachments !== false && /* @__PURE__ */ jsxs3(Fragment3, { children: [
|
|
5828
6740
|
/* @__PURE__ */ jsx5(
|
|
@@ -5837,6 +6749,22 @@ ${draftText}` : draftText);
|
|
|
5837
6749
|
children: /* @__PURE__ */ jsx5(PlusIcon, { size: 18 })
|
|
5838
6750
|
}
|
|
5839
6751
|
),
|
|
6752
|
+
showVoice && /* @__PURE__ */ jsx5(
|
|
6753
|
+
"button",
|
|
6754
|
+
{
|
|
6755
|
+
type: "button",
|
|
6756
|
+
className: `awr-iconbtn awr-voicebtn${recordingOn ? " is-on" : ""}`,
|
|
6757
|
+
"aria-label": L.recordVoiceMessage,
|
|
6758
|
+
title: L.recordVoiceMessage,
|
|
6759
|
+
"aria-pressed": recordingOn,
|
|
6760
|
+
onClick: () => {
|
|
6761
|
+
setVoiceNote(void 0);
|
|
6762
|
+
void recorder.start();
|
|
6763
|
+
},
|
|
6764
|
+
disabled: disabled || recordingOn || stt.listening,
|
|
6765
|
+
children: /* @__PURE__ */ jsx5(WaveIcon, { size: 18 })
|
|
6766
|
+
}
|
|
6767
|
+
),
|
|
5840
6768
|
/* @__PURE__ */ jsx5(
|
|
5841
6769
|
"input",
|
|
5842
6770
|
{
|
|
@@ -5861,7 +6789,7 @@ ${draftText}` : draftText);
|
|
|
5861
6789
|
}
|
|
5862
6790
|
),
|
|
5863
6791
|
toolbarExtra,
|
|
5864
|
-
showTimer && elapsed !== void 0 && /* @__PURE__ */ jsxs3("span", { className: "awr-tchip", title: busy ? L.timerRunning : L.timerLast, children: [
|
|
6792
|
+
showTimer && elapsed !== void 0 && (busy || !compactBar) && /* @__PURE__ */ jsxs3("span", { className: "awr-tchip", title: busy ? L.timerRunning : L.timerLast, children: [
|
|
5865
6793
|
/* @__PURE__ */ jsx5(ClockIcon, { size: 14 }),
|
|
5866
6794
|
" ",
|
|
5867
6795
|
formatElapsed(elapsed)
|
|
@@ -5897,7 +6825,7 @@ ${draftText}` : draftText);
|
|
|
5897
6825
|
"aria-expanded": menu === "model",
|
|
5898
6826
|
title: [model?.label, thinkingLabel].filter(Boolean).join(" \xB7 "),
|
|
5899
6827
|
children: [
|
|
5900
|
-
/* @__PURE__ */ jsx5("span", { className: "awr-tchip__label", children: model?.label
|
|
6828
|
+
/* @__PURE__ */ jsx5("span", { className: "awr-tchip__label", ref: chipLabelRef, children: chipShort && model?.shortLabel || model?.label || L.model }),
|
|
5901
6829
|
thinkingLabel && !compactBar && /* @__PURE__ */ jsx5("span", { className: "awr-tchip__sub", children: thinkingLabel })
|
|
5902
6830
|
]
|
|
5903
6831
|
}
|
|
@@ -6220,7 +7148,7 @@ var ContextMeter = ({
|
|
|
6220
7148
|
};
|
|
6221
7149
|
|
|
6222
7150
|
// src/components/ElicitationPrompt.tsx
|
|
6223
|
-
import { useEffect as
|
|
7151
|
+
import { useEffect as useEffect13, useId, useState as useState13 } from "react";
|
|
6224
7152
|
import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
6225
7153
|
var reasonText = (outcome, L) => {
|
|
6226
7154
|
const reason = outcome.reason;
|
|
@@ -6230,8 +7158,8 @@ var reasonText = (outcome, L) => {
|
|
|
6230
7158
|
return reason || outcome.status;
|
|
6231
7159
|
};
|
|
6232
7160
|
var useNow = (active) => {
|
|
6233
|
-
const [now, setNow] =
|
|
6234
|
-
|
|
7161
|
+
const [now, setNow] = useState13(() => Date.now());
|
|
7162
|
+
useEffect13(() => {
|
|
6235
7163
|
if (!active) return;
|
|
6236
7164
|
setNow(Date.now());
|
|
6237
7165
|
const timer = setInterval(() => setNow(Date.now()), 1e3);
|
|
@@ -6362,8 +7290,8 @@ var FormBody = ({ elicitation, answer, L }) => {
|
|
|
6362
7290
|
const baseId = useId();
|
|
6363
7291
|
const schema = elicitation.requestedSchema;
|
|
6364
7292
|
const fields = elicitationFields(schema);
|
|
6365
|
-
const [draft, setDraft] =
|
|
6366
|
-
const [issues, setIssues] =
|
|
7293
|
+
const [draft, setDraft] = useState13(() => elicitationInitialDraft(schema));
|
|
7294
|
+
const [issues, setIssues] = useState13(void 0);
|
|
6367
7295
|
const fieldId = (i) => `${baseId}-f${i}`;
|
|
6368
7296
|
const submit = (e) => {
|
|
6369
7297
|
e.preventDefault();
|
|
@@ -6418,7 +7346,7 @@ var FormBody = ({ elicitation, answer, L }) => {
|
|
|
6418
7346
|
};
|
|
6419
7347
|
var UrlBody = ({ elicitation, answer, L }) => {
|
|
6420
7348
|
const link = elicitationLink(elicitation.url);
|
|
6421
|
-
const [opened, setOpened] =
|
|
7349
|
+
const [opened, setOpened] = useState13(false);
|
|
6422
7350
|
const open = () => {
|
|
6423
7351
|
if (!link.openable || typeof window === "undefined") return;
|
|
6424
7352
|
window.open(link.href, "_blank", "noopener,noreferrer");
|
|
@@ -6482,7 +7410,7 @@ var ElicitationPrompt = ({
|
|
|
6482
7410
|
className
|
|
6483
7411
|
}) => {
|
|
6484
7412
|
const L = useLabels(labels);
|
|
6485
|
-
const [dismissed, setDismissed] =
|
|
7413
|
+
const [dismissed, setDismissed] = useState13(() => /* @__PURE__ */ new Set());
|
|
6486
7414
|
const automatic = showOutcomes ? (outcomes ?? []).filter(
|
|
6487
7415
|
(o) => o.automatic === true && o.status !== "pending" && !dismissed.has(o.id)
|
|
6488
7416
|
) : [];
|
|
@@ -6543,21 +7471,21 @@ var ElicitationPrompt = ({
|
|
|
6543
7471
|
};
|
|
6544
7472
|
|
|
6545
7473
|
// src/components/FilesPanel.tsx
|
|
6546
|
-
import { Fragment as Fragment6, useEffect as
|
|
7474
|
+
import { Fragment as Fragment6, useEffect as useEffect15, useRef as useRef12, useState as useState15 } from "react";
|
|
6547
7475
|
|
|
6548
7476
|
// src/components/ImageViewer.tsx
|
|
6549
|
-
import { createContext as createContext3, useContext as useContext3, useEffect as
|
|
7477
|
+
import { createContext as createContext3, useContext as useContext3, useEffect as useEffect14, useRef as useRef11, useState as useState14 } from "react";
|
|
6550
7478
|
import { createPortal } from "react-dom";
|
|
6551
7479
|
import { Fragment as Fragment5, jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
6552
7480
|
var fileNameOf = (name) => name.split(/[\\/]/).filter(Boolean).pop() ?? name;
|
|
6553
7481
|
var SWIPE_PX = 48;
|
|
6554
7482
|
var ImageViewer = ({ images, index, onIndex, onClose, labels }) => {
|
|
6555
7483
|
const L = useLabels(labels);
|
|
6556
|
-
const rootRef =
|
|
6557
|
-
const closeRef =
|
|
6558
|
-
const imgRef =
|
|
6559
|
-
const touch =
|
|
6560
|
-
const [zoom, setZoom] =
|
|
7484
|
+
const rootRef = useRef11(null);
|
|
7485
|
+
const closeRef = useRef11(null);
|
|
7486
|
+
const imgRef = useRef11(null);
|
|
7487
|
+
const touch = useRef11(void 0);
|
|
7488
|
+
const [zoom, setZoom] = useState14(void 0);
|
|
6561
7489
|
const count = images.length;
|
|
6562
7490
|
const at = Math.min(Math.max(index, 0), count - 1);
|
|
6563
7491
|
const image = images[at];
|
|
@@ -6566,7 +7494,7 @@ var ImageViewer = ({ images, index, onIndex, onClose, labels }) => {
|
|
|
6566
7494
|
setZoom(void 0);
|
|
6567
7495
|
onIndex((at + step + count) % count);
|
|
6568
7496
|
};
|
|
6569
|
-
|
|
7497
|
+
useEffect14(() => {
|
|
6570
7498
|
closeRef.current?.focus();
|
|
6571
7499
|
const root = document.documentElement;
|
|
6572
7500
|
const before = root.style.overflow;
|
|
@@ -6575,7 +7503,7 @@ var ImageViewer = ({ images, index, onIndex, onClose, labels }) => {
|
|
|
6575
7503
|
root.style.overflow = before;
|
|
6576
7504
|
};
|
|
6577
7505
|
}, []);
|
|
6578
|
-
const keys =
|
|
7506
|
+
const keys = useRef11(() => {
|
|
6579
7507
|
});
|
|
6580
7508
|
keys.current = (e) => {
|
|
6581
7509
|
if (e.key === "Escape") {
|
|
@@ -6601,7 +7529,7 @@ var ImageViewer = ({ images, index, onIndex, onClose, labels }) => {
|
|
|
6601
7529
|
}
|
|
6602
7530
|
}
|
|
6603
7531
|
};
|
|
6604
|
-
|
|
7532
|
+
useEffect14(() => {
|
|
6605
7533
|
const onKey = (e) => keys.current(e);
|
|
6606
7534
|
document.addEventListener("keydown", onKey, true);
|
|
6607
7535
|
return () => document.removeEventListener("keydown", onKey, true);
|
|
@@ -6745,8 +7673,8 @@ var ImageThumb = ({
|
|
|
6745
7673
|
}) => {
|
|
6746
7674
|
const L = useLabels(labels);
|
|
6747
7675
|
const { enabled, render } = useContext3(ImageViewerContext);
|
|
6748
|
-
const ref =
|
|
6749
|
-
const [open, setOpen] =
|
|
7676
|
+
const ref = useRef11(null);
|
|
7677
|
+
const [open, setOpen] = useState14(void 0);
|
|
6750
7678
|
const img = /* @__PURE__ */ jsx9("img", { className: imgClassName, src, alt });
|
|
6751
7679
|
if (!enabled) {
|
|
6752
7680
|
return /* @__PURE__ */ jsx9("a", { className, href: src, target: "_blank", rel: "noopener noreferrer", title, children: img });
|
|
@@ -6808,9 +7736,9 @@ var FilesPanel = ({
|
|
|
6808
7736
|
}) => {
|
|
6809
7737
|
const L = useLabels(labels);
|
|
6810
7738
|
const fs = useVirtualFiles(vfs, prefix);
|
|
6811
|
-
const [preview, setPreview] =
|
|
6812
|
-
const inputRef =
|
|
6813
|
-
|
|
7739
|
+
const [preview, setPreview] = useState15();
|
|
7740
|
+
const inputRef = useRef12(null);
|
|
7741
|
+
useEffect15(() => {
|
|
6814
7742
|
if (preview && !fs.files.some((f) => f.path === preview.path)) setPreview(void 0);
|
|
6815
7743
|
}, [fs.files, preview]);
|
|
6816
7744
|
const open = async (f) => {
|
|
@@ -6931,7 +7859,7 @@ var FilesPanel = ({
|
|
|
6931
7859
|
};
|
|
6932
7860
|
|
|
6933
7861
|
// src/components/FileChips.tsx
|
|
6934
|
-
import { Fragment as Fragment8, useEffect as
|
|
7862
|
+
import { Fragment as Fragment8, useEffect as useEffect17, useMemo as useMemo8, useState as useState17 } from "react";
|
|
6935
7863
|
|
|
6936
7864
|
// src/file-kinds.ts
|
|
6937
7865
|
import { MEDIA_IMAGE_TYPES, isTextMime } from "@dudko.dev/agent-web";
|
|
@@ -6952,7 +7880,7 @@ var fileKindOf = (path, mediaType) => {
|
|
|
6952
7880
|
var fileNameOf2 = (path) => path.split("/").filter(Boolean).pop() || "file";
|
|
6953
7881
|
|
|
6954
7882
|
// src/components/Media.tsx
|
|
6955
|
-
import { useEffect as
|
|
7883
|
+
import { useEffect as useEffect16, useState as useState16 } from "react";
|
|
6956
7884
|
import { MEDIA_AUDIO_TYPES, MEDIA_IMAGE_TYPES as MEDIA_IMAGE_TYPES2 } from "@dudko.dev/agent-web";
|
|
6957
7885
|
import { jsx as jsx11, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
6958
7886
|
var mediaFamilyOf = (mediaType) => {
|
|
@@ -6969,8 +7897,8 @@ var bytesOf = (content, encoding) => {
|
|
|
6969
7897
|
return bytes;
|
|
6970
7898
|
};
|
|
6971
7899
|
var useFileUrl = (files, path, mediaType) => {
|
|
6972
|
-
const [url, setUrl] =
|
|
6973
|
-
|
|
7900
|
+
const [url, setUrl] = useState16(void 0);
|
|
7901
|
+
useEffect16(() => {
|
|
6974
7902
|
if (!files || !mediaType) return;
|
|
6975
7903
|
let made;
|
|
6976
7904
|
let gone = false;
|
|
@@ -7154,7 +8082,7 @@ var SourceView = ({
|
|
|
7154
8082
|
const L = useLabels(labels);
|
|
7155
8083
|
const cut = text.length > maxChars;
|
|
7156
8084
|
const shown = cut ? text.slice(0, maxChars) : text;
|
|
7157
|
-
const lines =
|
|
8085
|
+
const lines = useMemo8(
|
|
7158
8086
|
() => linesOf(html ? tokenizeHtml(shown) : [{ kind: "text", text: shown }]),
|
|
7159
8087
|
[shown, html]
|
|
7160
8088
|
);
|
|
@@ -7169,16 +8097,16 @@ var SourceView = ({
|
|
|
7169
8097
|
] });
|
|
7170
8098
|
};
|
|
7171
8099
|
var HtmlPreview = ({ written, file, htmlPreview, previewChars, L }) => {
|
|
7172
|
-
const html =
|
|
8100
|
+
const html = useMemo8(() => textOf(file), [file]);
|
|
7173
8101
|
const options = htmlPreview === false ? void 0 : htmlPreview;
|
|
7174
8102
|
const tooLarge = html.length > HTML_PREVIEW_MAX_CHARS;
|
|
7175
8103
|
const canFrame = Boolean(options) && !tooLarge;
|
|
7176
|
-
const [view, setView] =
|
|
7177
|
-
const [tall, setTall] =
|
|
8104
|
+
const [view, setView] = useState17(canFrame ? "preview" : "source");
|
|
8105
|
+
const [tall, setTall] = useState17(false);
|
|
7178
8106
|
const showing = canFrame ? view : "source";
|
|
7179
8107
|
const scripts = options?.scripts === true;
|
|
7180
8108
|
const height = options?.height ?? 300;
|
|
7181
|
-
const linked =
|
|
8109
|
+
const linked = useMemo8(() => showing === "preview" ? linkedFilesOf(html) : [], [html, showing]);
|
|
7182
8110
|
return /* @__PURE__ */ jsx13(
|
|
7183
8111
|
SandboxedFrame,
|
|
7184
8112
|
{
|
|
@@ -7291,14 +8219,14 @@ var TextPreview = ({
|
|
|
7291
8219
|
onClose,
|
|
7292
8220
|
L
|
|
7293
8221
|
}) => {
|
|
7294
|
-
const text =
|
|
7295
|
-
const rendered =
|
|
8222
|
+
const text = useMemo8(() => textOf(file), [file]);
|
|
8223
|
+
const rendered = useMemo8(
|
|
7296
8224
|
() => renderFileContent?.(written, text.slice(0, previewChars)),
|
|
7297
8225
|
[renderFileContent, written, text, previewChars]
|
|
7298
8226
|
);
|
|
7299
8227
|
const hasRendered = rendered !== void 0 && rendered !== null && rendered !== false;
|
|
7300
|
-
const [view, setView] =
|
|
7301
|
-
const [all, setAll] =
|
|
8228
|
+
const [view, setView] = useState17("rendered");
|
|
8229
|
+
const [all, setAll] = useState17(false);
|
|
7302
8230
|
const showing = hasRendered ? view : "source";
|
|
7303
8231
|
const long = text.length > 1200 || text.split("\n").length > 16;
|
|
7304
8232
|
return /* @__PURE__ */ jsxs11("div", { className: "awr-fileview", children: [
|
|
@@ -7340,11 +8268,11 @@ var FileChips = ({
|
|
|
7340
8268
|
}) => {
|
|
7341
8269
|
const L = useLabels(labels);
|
|
7342
8270
|
const live = useVirtualFiles(vfs);
|
|
7343
|
-
const [openPath, setOpenPath] =
|
|
7344
|
-
const [file, setFile] =
|
|
8271
|
+
const [openPath, setOpenPath] = useState17(defaultOpen);
|
|
8272
|
+
const [file, setFile] = useState17();
|
|
7345
8273
|
const open = written.find((f) => f.path === openPath);
|
|
7346
8274
|
const stamp = live.files.find((f) => f.path === openPath)?.updatedAt;
|
|
7347
|
-
|
|
8275
|
+
useEffect17(() => {
|
|
7348
8276
|
if (!vfs || !openPath) return setFile(void 0);
|
|
7349
8277
|
let gone = false;
|
|
7350
8278
|
vfs.read(openPath).then((f) => {
|
|
@@ -7470,11 +8398,11 @@ var FileChip = ({
|
|
|
7470
8398
|
import { Fragment as Fragment11 } from "react";
|
|
7471
8399
|
|
|
7472
8400
|
// src/components/SubagentTree.tsx
|
|
7473
|
-
import { Fragment as Fragment10, useEffect as
|
|
8401
|
+
import { Fragment as Fragment10, useEffect as useEffect18, useState as useState18 } from "react";
|
|
7474
8402
|
import { jsx as jsx14, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
7475
8403
|
var useElapsed = (startedAt, running) => {
|
|
7476
|
-
const [now, setNow] =
|
|
7477
|
-
|
|
8404
|
+
const [now, setNow] = useState18(void 0);
|
|
8405
|
+
useEffect18(() => {
|
|
7478
8406
|
if (!running || startedAt === void 0) return;
|
|
7479
8407
|
setNow(Date.now());
|
|
7480
8408
|
const timer = setInterval(() => setNow(Date.now()), 1e3);
|
|
@@ -7839,7 +8767,7 @@ var StepList = ({
|
|
|
7839
8767
|
};
|
|
7840
8768
|
|
|
7841
8769
|
// src/components/MessageList.tsx
|
|
7842
|
-
import { jsx as jsx16, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
8770
|
+
import { Fragment as Fragment12, jsx as jsx16, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
7843
8771
|
var usageLine = (usage, durationMs) => {
|
|
7844
8772
|
const parts = [];
|
|
7845
8773
|
if (usage && usage.totalTokens > 0) {
|
|
@@ -7850,7 +8778,54 @@ var usageLine = (usage, durationMs) => {
|
|
|
7850
8778
|
if (durationMs !== void 0) parts.push(formatDuration(durationMs));
|
|
7851
8779
|
return parts.join(" \xB7 ");
|
|
7852
8780
|
};
|
|
7853
|
-
var
|
|
8781
|
+
var lengthOf = (ms) => typeof ms === "number" && Number.isFinite(ms) && ms >= 0 && ms < 864e5 ? ms : void 0;
|
|
8782
|
+
var settleAudioDuration = (el) => {
|
|
8783
|
+
if (el.duration !== Infinity) return;
|
|
8784
|
+
const back = () => {
|
|
8785
|
+
if (!Number.isFinite(el.duration)) return;
|
|
8786
|
+
el.removeEventListener("durationchange", back);
|
|
8787
|
+
el.removeEventListener("timeupdate", back);
|
|
8788
|
+
el.currentTime = 0;
|
|
8789
|
+
};
|
|
8790
|
+
el.addEventListener("durationchange", back);
|
|
8791
|
+
el.addEventListener("timeupdate", back);
|
|
8792
|
+
el.currentTime = Number.MAX_SAFE_INTEGER;
|
|
8793
|
+
};
|
|
8794
|
+
var AttachedAudio = ({
|
|
8795
|
+
attachment: a,
|
|
8796
|
+
files,
|
|
8797
|
+
labels
|
|
8798
|
+
}) => {
|
|
8799
|
+
const L = useLabels(labels);
|
|
8800
|
+
const type = a.mediaType.toLowerCase().split(";")[0].trim();
|
|
8801
|
+
const url = useFileUrl(files, a.path ?? "", files && a.path ? type : void 0);
|
|
8802
|
+
const length = lengthOf(a.durationMs);
|
|
8803
|
+
const said = length !== void 0 ? L.audioDuration(formatClock(length)) : void 0;
|
|
8804
|
+
return url ? /* @__PURE__ */ jsxs14("span", { className: "awr-media awr-media--audio awr-msg__audio", title: a.path ?? a.name, children: [
|
|
8805
|
+
/* @__PURE__ */ jsx16(
|
|
8806
|
+
"audio",
|
|
8807
|
+
{
|
|
8808
|
+
className: "awr-media__audio",
|
|
8809
|
+
controls: true,
|
|
8810
|
+
preload: "metadata",
|
|
8811
|
+
src: url,
|
|
8812
|
+
"aria-label": said ? `${L.audioAttachment(a.name)} (${said})` : L.audioAttachment(a.name),
|
|
8813
|
+
onLoadedMetadata: (e) => settleAudioDuration(e.currentTarget)
|
|
8814
|
+
}
|
|
8815
|
+
),
|
|
8816
|
+
said && /* @__PURE__ */ jsx16("span", { className: "awr-msg__audiolen", "aria-hidden": "true", children: said })
|
|
8817
|
+
] }) : /* @__PURE__ */ jsxs14("span", { className: "awr-chip awr-file", title: a.path ?? a.mediaType, children: [
|
|
8818
|
+
/* @__PURE__ */ jsx16(WaveIcon, { size: 13 }),
|
|
8819
|
+
" ",
|
|
8820
|
+
a.name,
|
|
8821
|
+
said ? ` \xB7 ${said}` : ""
|
|
8822
|
+
] });
|
|
8823
|
+
};
|
|
8824
|
+
var AttachmentView = ({
|
|
8825
|
+
attachment: a,
|
|
8826
|
+
files,
|
|
8827
|
+
labels
|
|
8828
|
+
}) => mediaFamilyOf(a.mediaType) === "audio" ? /* @__PURE__ */ jsx16(AttachedAudio, { attachment: a, files, labels }) : a.dataUrl && a.mediaType.startsWith("image/") ? /* @__PURE__ */ jsx16(
|
|
7854
8829
|
ImageThumb,
|
|
7855
8830
|
{
|
|
7856
8831
|
src: a.dataUrl,
|
|
@@ -7913,10 +8888,12 @@ var MessageList = ({
|
|
|
7913
8888
|
showApps = true,
|
|
7914
8889
|
imageViewer = true,
|
|
7915
8890
|
renderImageViewer,
|
|
8891
|
+
readAloud,
|
|
7916
8892
|
labels,
|
|
7917
8893
|
className
|
|
7918
8894
|
}) => {
|
|
7919
8895
|
const L = useLabels(labels);
|
|
8896
|
+
const reader = useReadAloud(readAloud?.speak, readAloud?.lang);
|
|
7920
8897
|
if (messages.length === 0) {
|
|
7921
8898
|
return empty ? /* @__PURE__ */ jsx16("div", { className: "awr-messages__empty", children: empty }) : null;
|
|
7922
8899
|
}
|
|
@@ -8012,7 +8989,24 @@ var MessageList = ({
|
|
|
8012
8989
|
labels
|
|
8013
8990
|
}
|
|
8014
8991
|
) : null,
|
|
8015
|
-
m.attachments?.length ? /* @__PURE__ */ jsx16(
|
|
8992
|
+
m.attachments?.length ? /* @__PURE__ */ jsx16(
|
|
8993
|
+
"div",
|
|
8994
|
+
{
|
|
8995
|
+
className: "awr-msg__attachments",
|
|
8996
|
+
role: "group",
|
|
8997
|
+
"aria-label": m.content.trim() ? L.attachments : attachmentsText(m.attachments, { voiceMessage: L.voiceMessage }),
|
|
8998
|
+
children: m.attachments.map((a, i) => /* @__PURE__ */ jsx16("span", { className: "awr-msg__attachment", children: renderAttachment ? renderAttachment(a, m) : /* @__PURE__ */ jsx16(AttachmentView, { attachment: a, files, labels }) }, i))
|
|
8999
|
+
}
|
|
9000
|
+
) : null,
|
|
9001
|
+
readAloud && m.role === "assistant" && m.content && !m.pending && !m.error && /* @__PURE__ */ jsx16(
|
|
9002
|
+
ReadAloudControl,
|
|
9003
|
+
{
|
|
9004
|
+
id: m.id,
|
|
9005
|
+
text: () => readAloud.textOf ? readAloud.textOf(m) : speakableText(m.content, { code: L.readAloudCode }),
|
|
9006
|
+
reader,
|
|
9007
|
+
labels: L
|
|
9008
|
+
}
|
|
9009
|
+
),
|
|
8016
9010
|
m.role === "assistant" && usage && !m.pending && /* @__PURE__ */ jsx16("div", { className: "awr-msg__usage", title: L.usageTitle, children: usage })
|
|
8017
9011
|
] })
|
|
8018
9012
|
},
|
|
@@ -8021,6 +9015,78 @@ var MessageList = ({
|
|
|
8021
9015
|
return renderMessage ? /* @__PURE__ */ jsx16("div", { children: renderMessage(m, node) }, m.id) : node;
|
|
8022
9016
|
}) }) });
|
|
8023
9017
|
};
|
|
9018
|
+
var ReadAloudControl = ({
|
|
9019
|
+
id,
|
|
9020
|
+
text,
|
|
9021
|
+
reader,
|
|
9022
|
+
labels: L
|
|
9023
|
+
}) => {
|
|
9024
|
+
const mine = reader.current === id;
|
|
9025
|
+
const failed = reader.failed?.id === id ? reader.failed : void 0;
|
|
9026
|
+
return /* @__PURE__ */ jsxs14("div", { className: "awr-readaloud", "data-state": mine ? reader.state : "idle", children: [
|
|
9027
|
+
!mine ? /* @__PURE__ */ jsxs14(
|
|
9028
|
+
"button",
|
|
9029
|
+
{
|
|
9030
|
+
type: "button",
|
|
9031
|
+
className: "awr-linkbtn awr-readaloud__btn",
|
|
9032
|
+
onClick: () => reader.start(id, text()),
|
|
9033
|
+
"aria-label": L.readAloud,
|
|
9034
|
+
children: [
|
|
9035
|
+
/* @__PURE__ */ jsx16(SpeakerIcon, { size: 14 }),
|
|
9036
|
+
" ",
|
|
9037
|
+
L.readAloud
|
|
9038
|
+
]
|
|
9039
|
+
}
|
|
9040
|
+
) : /* @__PURE__ */ jsxs14(Fragment12, { children: [
|
|
9041
|
+
reader.state === "loading" ? /* @__PURE__ */ jsxs14("span", { className: "awr-readaloud__status", role: "status", children: [
|
|
9042
|
+
/* @__PURE__ */ jsx16(SpinnerIcon, { size: 14 }),
|
|
9043
|
+
" ",
|
|
9044
|
+
L.readAloudLoading
|
|
9045
|
+
] }) : reader.state === "paused" ? /* @__PURE__ */ jsxs14(
|
|
9046
|
+
"button",
|
|
9047
|
+
{
|
|
9048
|
+
type: "button",
|
|
9049
|
+
className: "awr-linkbtn awr-readaloud__btn",
|
|
9050
|
+
onClick: reader.resume,
|
|
9051
|
+
"aria-label": L.readAloudResume,
|
|
9052
|
+
children: [
|
|
9053
|
+
/* @__PURE__ */ jsx16(PlayIcon, { size: 14 }),
|
|
9054
|
+
" ",
|
|
9055
|
+
L.readAloudResume
|
|
9056
|
+
]
|
|
9057
|
+
}
|
|
9058
|
+
) : /* @__PURE__ */ jsxs14(
|
|
9059
|
+
"button",
|
|
9060
|
+
{
|
|
9061
|
+
type: "button",
|
|
9062
|
+
className: "awr-linkbtn awr-readaloud__btn",
|
|
9063
|
+
onClick: reader.pause,
|
|
9064
|
+
"aria-label": L.readAloudPause,
|
|
9065
|
+
children: [
|
|
9066
|
+
/* @__PURE__ */ jsx16(PauseIcon, { size: 14 }),
|
|
9067
|
+
" ",
|
|
9068
|
+
L.readAloudPause
|
|
9069
|
+
]
|
|
9070
|
+
}
|
|
9071
|
+
),
|
|
9072
|
+
/* @__PURE__ */ jsxs14(
|
|
9073
|
+
"button",
|
|
9074
|
+
{
|
|
9075
|
+
type: "button",
|
|
9076
|
+
className: "awr-linkbtn awr-readaloud__btn",
|
|
9077
|
+
onClick: reader.stop,
|
|
9078
|
+
"aria-label": L.readAloudStop,
|
|
9079
|
+
children: [
|
|
9080
|
+
/* @__PURE__ */ jsx16(StopIcon, { size: 14 }),
|
|
9081
|
+
" ",
|
|
9082
|
+
L.readAloudStop
|
|
9083
|
+
]
|
|
9084
|
+
}
|
|
9085
|
+
)
|
|
9086
|
+
] }),
|
|
9087
|
+
failed && /* @__PURE__ */ jsx16("span", { className: "awr-readaloud__error", role: "alert", children: failed.message ?? L.readAloudFailed })
|
|
9088
|
+
] });
|
|
9089
|
+
};
|
|
8024
9090
|
|
|
8025
9091
|
// src/components/ModelLoadBar.tsx
|
|
8026
9092
|
import { jsx as jsx17, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
@@ -8039,11 +9105,11 @@ var ModelLoadBar = ({ load, className }) => {
|
|
|
8039
9105
|
};
|
|
8040
9106
|
|
|
8041
9107
|
// src/components/QuestionPrompt.tsx
|
|
8042
|
-
import { useEffect as
|
|
9108
|
+
import { useEffect as useEffect19, useId as useId2, useRef as useRef13, useState as useState19 } from "react";
|
|
8043
9109
|
import { jsx as jsx18, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
8044
9110
|
var useNow2 = (active) => {
|
|
8045
|
-
const [now, setNow] =
|
|
8046
|
-
|
|
9111
|
+
const [now, setNow] = useState19(() => Date.now());
|
|
9112
|
+
useEffect19(() => {
|
|
8047
9113
|
if (!active) return;
|
|
8048
9114
|
setNow(Date.now());
|
|
8049
9115
|
const timer = setInterval(() => setNow(Date.now()), 1e3);
|
|
@@ -8075,12 +9141,12 @@ var QuestionCard = ({
|
|
|
8075
9141
|
const baseId = useId2();
|
|
8076
9142
|
const textId = `${baseId}-q`;
|
|
8077
9143
|
const otherId = `${baseId}-other`;
|
|
8078
|
-
const [picked, setPicked] =
|
|
8079
|
-
const [otherOpen, setOtherOpen] =
|
|
8080
|
-
const [otherText, setOtherText] =
|
|
8081
|
-
const otherField =
|
|
8082
|
-
const otherButton =
|
|
8083
|
-
|
|
9144
|
+
const [picked, setPicked] = useState19([]);
|
|
9145
|
+
const [otherOpen, setOtherOpen] = useState19(false);
|
|
9146
|
+
const [otherText, setOtherText] = useState19("");
|
|
9147
|
+
const otherField = useRef13(null);
|
|
9148
|
+
const otherButton = useRef13(null);
|
|
9149
|
+
useEffect19(() => {
|
|
8084
9150
|
if (otherOpen) otherField.current?.focus();
|
|
8085
9151
|
}, [otherOpen]);
|
|
8086
9152
|
const helper = showHelper && q.subagent ? { ...q.subagent, ...view?.subagent } : void 0;
|
|
@@ -8248,7 +9314,7 @@ var QuestionPrompt = ({
|
|
|
8248
9314
|
className
|
|
8249
9315
|
}) => {
|
|
8250
9316
|
const L = useLabels(labels);
|
|
8251
|
-
const [dismissed, setDismissed] =
|
|
9317
|
+
const [dismissed, setDismissed] = useState19(() => /* @__PURE__ */ new Set());
|
|
8252
9318
|
const automatic = showOutcomes ? (outcomes ?? []).filter(
|
|
8253
9319
|
(o) => o.automatic === true && o.status !== "pending" && o.status !== "stopped" && !dismissed.has(o.id)
|
|
8254
9320
|
) : [];
|
|
@@ -8502,13 +9568,13 @@ var UsageBadge = ({
|
|
|
8502
9568
|
};
|
|
8503
9569
|
|
|
8504
9570
|
// src/components/AgentChat.tsx
|
|
8505
|
-
import { Fragment as
|
|
9571
|
+
import { Fragment as Fragment13, jsx as jsx20, jsxs as jsxs19 } from "react/jsx-runtime";
|
|
8506
9572
|
var usePrefersDark = () => {
|
|
8507
9573
|
const query = "(prefers-color-scheme: dark)";
|
|
8508
|
-
const [dark, setDark] =
|
|
9574
|
+
const [dark, setDark] = useState20(
|
|
8509
9575
|
() => typeof matchMedia === "function" && matchMedia(query).matches
|
|
8510
9576
|
);
|
|
8511
|
-
|
|
9577
|
+
useEffect20(() => {
|
|
8512
9578
|
if (typeof matchMedia !== "function") return;
|
|
8513
9579
|
const mq = matchMedia(query);
|
|
8514
9580
|
const on = () => setDark(mq.matches);
|
|
@@ -8563,6 +9629,7 @@ var AgentChatInner = ({
|
|
|
8563
9629
|
renderContent,
|
|
8564
9630
|
renderMessage,
|
|
8565
9631
|
renderAttachment,
|
|
9632
|
+
readAloud,
|
|
8566
9633
|
renderToolCall,
|
|
8567
9634
|
renderSubagent,
|
|
8568
9635
|
renderMedia,
|
|
@@ -8598,17 +9665,19 @@ var AgentChatInner = ({
|
|
|
8598
9665
|
}
|
|
8599
9666
|
const L = useLabels();
|
|
8600
9667
|
const external = isHistoryHook(history) ? history : void 0;
|
|
8601
|
-
const [ownStore] =
|
|
9668
|
+
const [ownStore] = useState20(
|
|
8602
9669
|
() => history instanceof ChatHistoryStore ? history : new ChatHistoryStore()
|
|
8603
9670
|
);
|
|
8604
9671
|
const own = useChatHistory(agent, {
|
|
8605
9672
|
store: ownStore,
|
|
8606
|
-
enabled: Boolean(history) && !external
|
|
9673
|
+
enabled: Boolean(history) && !external,
|
|
9674
|
+
// A chat begun by a voice message is titled in the chat's language.
|
|
9675
|
+
labels: { voiceMessage: L.voiceMessage }
|
|
8607
9676
|
});
|
|
8608
9677
|
const chats = history ? external ?? own : void 0;
|
|
8609
|
-
const rootRef =
|
|
8610
|
-
const [narrow, setNarrow] =
|
|
8611
|
-
|
|
9678
|
+
const rootRef = useRef14(null);
|
|
9679
|
+
const [narrow, setNarrow] = useState20(void 0);
|
|
9680
|
+
useEffect20(() => {
|
|
8612
9681
|
const el = rootRef.current;
|
|
8613
9682
|
if (!el || typeof ResizeObserver === "undefined") return setNarrow(false);
|
|
8614
9683
|
const measure2 = () => setNarrow(el.getBoundingClientRect().width < narrowWidth);
|
|
@@ -8617,9 +9686,9 @@ var AgentChatInner = ({
|
|
|
8617
9686
|
ro.observe(el);
|
|
8618
9687
|
return () => ro.disconnect();
|
|
8619
9688
|
}, [narrowWidth]);
|
|
8620
|
-
const [historyChoice, setHistoryOpen] =
|
|
9689
|
+
const [historyChoice, setHistoryOpen] = useState20(defaultHistoryOpen);
|
|
8621
9690
|
const historyOpen = historyChoice ?? narrow === false;
|
|
8622
|
-
const [filesOpen, setFilesOpen] =
|
|
9691
|
+
const [filesOpen, setFilesOpen] = useState20(defaultFilesOpen);
|
|
8623
9692
|
const toggleHistory = () => {
|
|
8624
9693
|
setHistoryOpen(!historyOpen);
|
|
8625
9694
|
if (narrow && !historyOpen) setFilesOpen(false);
|
|
@@ -8637,7 +9706,7 @@ var AgentChatInner = ({
|
|
|
8637
9706
|
setHistoryOpen(false);
|
|
8638
9707
|
setFilesOpen(false);
|
|
8639
9708
|
};
|
|
8640
|
-
|
|
9709
|
+
useEffect20(() => {
|
|
8641
9710
|
if (!overlayOpen) return;
|
|
8642
9711
|
const onKey = (e) => {
|
|
8643
9712
|
if (e.key !== "Escape" || e.defaultPrevented) return;
|
|
@@ -8647,7 +9716,7 @@ var AgentChatInner = ({
|
|
|
8647
9716
|
document.addEventListener("keydown", onKey);
|
|
8648
9717
|
return () => document.removeEventListener("keydown", onKey);
|
|
8649
9718
|
}, [overlayOpen]);
|
|
8650
|
-
const bodyRef =
|
|
9719
|
+
const bodyRef = useRef14(null);
|
|
8651
9720
|
const appHost = useMcpAppHost({
|
|
8652
9721
|
connection: mcpApps,
|
|
8653
9722
|
approve: agent.approveAppToolCall,
|
|
@@ -8659,7 +9728,7 @@ var AgentChatInner = ({
|
|
|
8659
9728
|
});
|
|
8660
9729
|
const prefersDark = usePrefersDark();
|
|
8661
9730
|
const appTheme = theme === "auto" ? prefersDark ? "dark" : "light" : theme;
|
|
8662
|
-
const [panelApp, setPanelAppState] =
|
|
9731
|
+
const [panelApp, setPanelAppState] = useState20();
|
|
8663
9732
|
const setPanelApp = (app) => {
|
|
8664
9733
|
setPanelAppState(app);
|
|
8665
9734
|
onAppPanel?.(app);
|
|
@@ -8673,7 +9742,7 @@ var AgentChatInner = ({
|
|
|
8673
9742
|
const panelAllowed = appPanel !== false && appPanel !== null;
|
|
8674
9743
|
const panelTarget = typeof appPanel === "object" && appPanel ? appPanel : void 0;
|
|
8675
9744
|
const asSheet = !panelTarget && (appPanel === "sheet" || Boolean(narrow));
|
|
8676
|
-
|
|
9745
|
+
useEffect20(() => {
|
|
8677
9746
|
if (panelApp && !agent.messages.some((m) => m.apps?.some((a) => a.id === panelApp.id))) {
|
|
8678
9747
|
setPanelAppState(void 0);
|
|
8679
9748
|
onAppPanel?.(void 0);
|
|
@@ -8713,7 +9782,7 @@ var AgentChatInner = ({
|
|
|
8713
9782
|
},
|
|
8714
9783
|
panelApp.id
|
|
8715
9784
|
) : null;
|
|
8716
|
-
const [compacting, setCompacting] =
|
|
9785
|
+
const [compacting, setCompacting] = useState20(false);
|
|
8717
9786
|
const compact = () => {
|
|
8718
9787
|
setCompacting(true);
|
|
8719
9788
|
void agent.compact().finally(() => setCompacting(false));
|
|
@@ -8735,7 +9804,7 @@ var AgentChatInner = ({
|
|
|
8735
9804
|
const showReplan = agent.replan && agent.replan.mode !== "continue";
|
|
8736
9805
|
const replanFailedEarly = showReplanFailed && agent.replan?.failed === true && agent.steps.length === 0;
|
|
8737
9806
|
const earlyDecisions = showDecisions ? agent.decisions ?? [] : [];
|
|
8738
|
-
const liveExtra = agent.planThought.trim() || showReplan || replanFailedEarly || earlyDecisions.length > 0 ? /* @__PURE__ */ jsxs19(
|
|
9807
|
+
const liveExtra = agent.planThought.trim() || showReplan || replanFailedEarly || earlyDecisions.length > 0 ? /* @__PURE__ */ jsxs19(Fragment13, { children: [
|
|
8739
9808
|
agent.planThought.trim() && /* @__PURE__ */ jsxs19("details", { className: "awr-activity__plan", children: [
|
|
8740
9809
|
/* @__PURE__ */ jsx20("summary", { children: L.planned }),
|
|
8741
9810
|
/* @__PURE__ */ jsx20("p", { className: "awr-activity__thought", children: agent.planThought })
|
|
@@ -8871,6 +9940,7 @@ var AgentChatInner = ({
|
|
|
8871
9940
|
renderContent,
|
|
8872
9941
|
renderMessage,
|
|
8873
9942
|
renderAttachment,
|
|
9943
|
+
readAloud,
|
|
8874
9944
|
renderToolCall,
|
|
8875
9945
|
showApps: appsOn,
|
|
8876
9946
|
renderApp: appsOn ? drawApp : void 0,
|
|
@@ -8962,7 +10032,7 @@ var AgentChatInner = ({
|
|
|
8962
10032
|
),
|
|
8963
10033
|
panelTarget
|
|
8964
10034
|
)
|
|
8965
|
-
) : asSheet ? /* @__PURE__ */ jsxs19(
|
|
10035
|
+
) : asSheet ? /* @__PURE__ */ jsxs19(Fragment13, { children: [
|
|
8966
10036
|
/* @__PURE__ */ jsx20("div", { className: "awr-sheet__scrim", onClick: () => setPanelApp(void 0) }),
|
|
8967
10037
|
/* @__PURE__ */ jsxs19(
|
|
8968
10038
|
"aside",
|
|
@@ -9046,7 +10116,7 @@ var LearnedSkills = ({
|
|
|
9046
10116
|
};
|
|
9047
10117
|
|
|
9048
10118
|
// src/components/Composer.tsx
|
|
9049
|
-
import { useState as
|
|
10119
|
+
import { useState as useState21 } from "react";
|
|
9050
10120
|
import { jsx as jsx22, jsxs as jsxs21 } from "react/jsx-runtime";
|
|
9051
10121
|
var Composer = ({
|
|
9052
10122
|
onSubmit,
|
|
@@ -9056,7 +10126,7 @@ var Composer = ({
|
|
|
9056
10126
|
placeholder = "Ask the agent to do something\u2026",
|
|
9057
10127
|
className
|
|
9058
10128
|
}) => {
|
|
9059
|
-
const [text, setText] =
|
|
10129
|
+
const [text, setText] = useState21("");
|
|
9060
10130
|
const submit = () => {
|
|
9061
10131
|
const value = text.trim();
|
|
9062
10132
|
if (!value || busy || disabled) return;
|
|
@@ -9169,7 +10239,7 @@ var ApprovalModeSwitch = ({
|
|
|
9169
10239
|
);
|
|
9170
10240
|
|
|
9171
10241
|
// src/components/ApiKeyForm.tsx
|
|
9172
|
-
import { useEffect as
|
|
10242
|
+
import { useEffect as useEffect21, useState as useState22 } from "react";
|
|
9173
10243
|
import { jsx as jsx25, jsxs as jsxs23 } from "react/jsx-runtime";
|
|
9174
10244
|
var ApiKeyForm = ({
|
|
9175
10245
|
credentials,
|
|
@@ -9179,10 +10249,10 @@ var ApiKeyForm = ({
|
|
|
9179
10249
|
onChange,
|
|
9180
10250
|
className
|
|
9181
10251
|
}) => {
|
|
9182
|
-
const [value, setValue] =
|
|
9183
|
-
const [present, setPresent] =
|
|
9184
|
-
const [busy, setBusy] =
|
|
9185
|
-
|
|
10252
|
+
const [value, setValue] = useState22("");
|
|
10253
|
+
const [present, setPresent] = useState22(false);
|
|
10254
|
+
const [busy, setBusy] = useState22(false);
|
|
10255
|
+
useEffect21(() => {
|
|
9186
10256
|
let active = true;
|
|
9187
10257
|
credentials.hasKey(credentialRef).then((has) => {
|
|
9188
10258
|
if (active) setPresent(has);
|
|
@@ -9364,13 +10434,17 @@ export {
|
|
|
9364
10434
|
MemorySkillStore,
|
|
9365
10435
|
MemoryStore,
|
|
9366
10436
|
MessageList,
|
|
10437
|
+
MicError,
|
|
9367
10438
|
ModelLoadBar,
|
|
9368
10439
|
PlanView,
|
|
9369
10440
|
QUESTION_TIMEOUT_MS,
|
|
9370
10441
|
QuestionPrompt,
|
|
10442
|
+
RECORDING_DEFAULT_MAX_MS,
|
|
10443
|
+
RECORDING_TYPES,
|
|
9371
10444
|
SandboxedFrame,
|
|
9372
10445
|
SessionBusyError,
|
|
9373
10446
|
SourceView,
|
|
10447
|
+
SpeechOutputError,
|
|
9374
10448
|
StepList,
|
|
9375
10449
|
SubagentRow,
|
|
9376
10450
|
SubagentTree,
|
|
@@ -9400,6 +10474,9 @@ export {
|
|
|
9400
10474
|
attachmentOverLimit,
|
|
9401
10475
|
attachmentRefusal,
|
|
9402
10476
|
attachmentTransformOf,
|
|
10477
|
+
attachmentsText,
|
|
10478
|
+
audioExtensionOf,
|
|
10479
|
+
audioTypeOf,
|
|
9403
10480
|
buildMcpAppDocument,
|
|
9404
10481
|
buildMcpAppSandboxShell,
|
|
9405
10482
|
buildSandboxedDocument,
|
|
@@ -9408,9 +10485,12 @@ export {
|
|
|
9408
10485
|
clampFrameHeight,
|
|
9409
10486
|
createAgent2 as createAgent,
|
|
9410
10487
|
createApprovalQueue,
|
|
10488
|
+
createAudioSpeaker,
|
|
10489
|
+
createBrowserSpeaker,
|
|
9411
10490
|
createFileTools,
|
|
9412
10491
|
createInitialAgentState,
|
|
9413
10492
|
createQuestionQueue,
|
|
10493
|
+
createRecordingRecognizer,
|
|
9414
10494
|
createRunControl2 as createRunControl,
|
|
9415
10495
|
createSubagentTool,
|
|
9416
10496
|
createWebLLMEngine,
|
|
@@ -9430,6 +10510,7 @@ export {
|
|
|
9430
10510
|
filterCommands,
|
|
9431
10511
|
followsAfterResize,
|
|
9432
10512
|
followsAfterScroll,
|
|
10513
|
+
formatClock,
|
|
9433
10514
|
formatCountdown,
|
|
9434
10515
|
formatElapsed,
|
|
9435
10516
|
grantedAppCsp,
|
|
@@ -9453,24 +10534,34 @@ export {
|
|
|
9453
10534
|
mergeChatRecord,
|
|
9454
10535
|
mergeLabels,
|
|
9455
10536
|
messageOverLimit,
|
|
10537
|
+
micProblemOf,
|
|
10538
|
+
micProblemText,
|
|
9456
10539
|
newChatId,
|
|
9457
10540
|
noticesOf,
|
|
9458
10541
|
onStorageChange,
|
|
9459
10542
|
parseSkillMarkdown,
|
|
9460
10543
|
parseSlash,
|
|
9461
10544
|
pendingApprovalsOf,
|
|
10545
|
+
pickRecordingType,
|
|
9462
10546
|
postStorageChange2 as postStorageChange,
|
|
9463
10547
|
preloadWebLLMModel2 as preloadWebLLMModel,
|
|
9464
10548
|
questionChoiceOf,
|
|
9465
10549
|
questionOtherOf,
|
|
9466
10550
|
questionTimeoutOf,
|
|
10551
|
+
recordingSupported,
|
|
9467
10552
|
resolveAppDownload,
|
|
9468
10553
|
sandboxTokens,
|
|
9469
10554
|
sandboxedCsp,
|
|
9470
10555
|
saveAppFile,
|
|
9471
10556
|
saveChat,
|
|
9472
10557
|
serveSubagentWorker,
|
|
10558
|
+
settleAudioDuration,
|
|
10559
|
+
speakableText,
|
|
10560
|
+
speechSynthesisSupported,
|
|
10561
|
+
splitForSpeech,
|
|
10562
|
+
startRecording,
|
|
9473
10563
|
steerIntent,
|
|
10564
|
+
stopTracks,
|
|
9474
10565
|
subagentTree,
|
|
9475
10566
|
supportsImages,
|
|
9476
10567
|
supportsPdf,
|
|
@@ -9480,6 +10571,7 @@ export {
|
|
|
9480
10571
|
usageLine,
|
|
9481
10572
|
useAgent,
|
|
9482
10573
|
useAgentContext,
|
|
10574
|
+
useAudioRecorder,
|
|
9483
10575
|
useChatHistory,
|
|
9484
10576
|
useCredentials,
|
|
9485
10577
|
useFollowScroll,
|
|
@@ -9487,9 +10579,14 @@ export {
|
|
|
9487
10579
|
useLocalModel,
|
|
9488
10580
|
useMcpAppHost,
|
|
9489
10581
|
useOptionalAgentContext,
|
|
10582
|
+
useReadAloud,
|
|
9490
10583
|
useSpeechToText,
|
|
10584
|
+
useSpeechVoices,
|
|
9491
10585
|
useVirtualFiles,
|
|
9492
10586
|
useWebLLMModel,
|
|
10587
|
+
voiceFor,
|
|
10588
|
+
voiceMessageName,
|
|
10589
|
+
voicesOf,
|
|
9493
10590
|
watchSession2 as watchSession,
|
|
9494
10591
|
webSearchOf,
|
|
9495
10592
|
withAttachments,
|