@dudko.dev/agent-web-react 0.0.38 → 0.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@ import {
11
11
  ArrowUpIcon,
12
12
  BoltIcon,
13
13
  BookIcon,
14
+ BookmarkIcon,
14
15
  BotIcon,
15
16
  BrainIcon,
16
17
  CheckIcon,
@@ -33,6 +34,8 @@ import {
33
34
  MoreIcon,
34
35
  NoNetworkIcon,
35
36
  PanelIcon,
37
+ PauseIcon,
38
+ PlayIcon,
36
39
  PlusIcon,
37
40
  QuestionIcon,
38
41
  ReloadIcon,
@@ -40,10 +43,12 @@ import {
40
43
  ShieldIcon,
41
44
  ShrinkIcon,
42
45
  SlashIcon,
46
+ SpeakerIcon,
43
47
  SpinnerIcon,
44
48
  StopIcon,
45
49
  TableIcon,
46
50
  ToolIcon,
51
+ WaveIcon,
47
52
  XIcon,
48
53
  errMessage,
49
54
  followOtherTabs,
@@ -52,8 +57,9 @@ import {
52
57
  formatTokens,
53
58
  imagesInOutput,
54
59
  previewValue,
60
+ remoteAnswerOf,
55
61
  webSearchOf
56
- } from "./chunk-G5GGIMD4.js";
62
+ } from "./chunk-V4JGQQRB.js";
57
63
  import {
58
64
  MCP_APP_POLICY_TOKEN_MAX_CHARS,
59
65
  MCP_APP_SANDBOX_PROXY_READY,
@@ -322,8 +328,15 @@ var resetRun = (state) => ({
322
328
  seq: state.seq,
323
329
  learned: state.learned,
324
330
  // An MCP App's request is the user's, not the run's: it waits across runs.
325
- approvals: state.approvals.filter((a) => a.app && a.status === "pending")
331
+ approvals: state.approvals.filter((a) => a.app && a.status === "pending"),
332
+ // So is what this tab sent to another tab's run, until that tab answers (a replay that opens
333
+ // with the run's start is not an answer).
334
+ queued: sentToOtherTab(state.queued)
326
335
  });
336
+ var sentToOtherTab = (queued) => queued.filter((q) => q.sentTo === "another-tab");
337
+ var sentEntryOf = (queued, text) => queued.findIndex(
338
+ (q) => q.sentTo === "another-tab" && (q.text === text || text.endsWith("\u2026") && q.text.length > text.length && q.text.startsWith(text.slice(0, -1)))
339
+ );
327
340
  var patchStep = (steps, id, fn) => steps.map((s) => s.id === id ? fn(s) : s);
328
341
  var withoutSkillBody = (a) => {
329
342
  if (!a.skill || a.skill.body === void 0) return a;
@@ -1072,14 +1085,17 @@ var applyEvent = (state, event, ctx) => {
1072
1085
  return fileDeleted(state, event.path);
1073
1086
  case "mcp.app":
1074
1087
  return ctx.remote ? state : addApp(state, event);
1075
- case "message.queued":
1076
- return state.queued.some((q) => q.id === event.id) ? state : {
1077
- ...state,
1078
- queued: [
1079
- ...state.queued,
1080
- { id: event.id, text: event.text, ...event.origin ? { origin: event.origin } : {} }
1081
- ]
1088
+ case "message.queued": {
1089
+ if (state.queued.some((q) => q.id === event.id)) return state;
1090
+ const entry = {
1091
+ id: event.id,
1092
+ text: event.text,
1093
+ ...event.origin ? { origin: event.origin } : {}
1082
1094
  };
1095
+ const mine = ctx.remote && event.origin === "another-tab" ? sentEntryOf(state.queued, event.text) : -1;
1096
+ if (mine < 0) return { ...state, queued: [...state.queued, entry] };
1097
+ return { ...state, queued: state.queued.map((q, i) => i === mine ? entry : q) };
1098
+ }
1083
1099
  case "message.delivered": {
1084
1100
  const anchor = event.at === "round" ? runningStepId(state.steps) : event.at === "step" ? state.steps[state.steps.length - 1]?.id : void 0;
1085
1101
  return {
@@ -1407,9 +1423,21 @@ var agentStateReducer = (state, action) => {
1407
1423
  case "undelivered":
1408
1424
  return {
1409
1425
  ...state,
1410
- queued: action.keepQueued ? state.queued : [],
1426
+ queued: action.keepQueued ? state.queued : sentToOtherTab(state.queued),
1411
1427
  undelivered: action.texts
1412
1428
  };
1429
+ case "remote-send":
1430
+ return state.queued.some((q) => q.id === action.id) ? state : {
1431
+ ...state,
1432
+ queued: [
1433
+ ...state.queued,
1434
+ { id: action.id, text: action.text, sentTo: "another-tab" }
1435
+ ]
1436
+ };
1437
+ case "remote-answer": {
1438
+ const queued = state.queued.filter((q) => q.id !== action.id);
1439
+ return action.answer === "refused" ? { ...state, queued, undelivered: [...state.undelivered, action.text] } : { ...state, queued };
1440
+ }
1413
1441
  case "load": {
1414
1442
  const maxSeq = action.messages.reduce((n, m) => {
1415
1443
  const k = Number(/^msg-(\d+)$/.exec(m.id)?.[1] ?? -1);
@@ -1589,7 +1617,8 @@ var useAgent = (config, options = {}) => {
1589
1617
  let began = false;
1590
1618
  const shownGoal = runOptions?.label ?? goal;
1591
1619
  dispatch({ type: "status", status: "running" });
1592
- if (shownGoal.trim()) {
1620
+ const shownAtAll = Boolean(shownGoal.trim() || runOptions?.attachments?.length);
1621
+ if (shownAtAll) {
1593
1622
  dispatch({
1594
1623
  type: "submitted",
1595
1624
  goal: shownGoal,
@@ -1609,14 +1638,16 @@ var useAgent = (config, options = {}) => {
1609
1638
  startedRef.current = true;
1610
1639
  began = true;
1611
1640
  }
1612
- const shown = start && runOptions?.label ? { ...event, goal: runOptions.label } : event;
1641
+ const shown = start && runOptions?.label !== void 0 ? { ...event, goal: runOptions.label } : event;
1613
1642
  dispatch({
1614
1643
  type: "event",
1615
1644
  event: shown,
1616
1645
  maxEvents: optionsRef.current.maxEvents,
1617
1646
  at: Date.now(),
1618
1647
  // What the user sent waits with the run: shown as queued meanwhile.
1619
- ...event.type === "session.busy" && shownGoal.trim() ? { goal: shownGoal } : {},
1648
+ ...event.type === "session.busy" && shownAtAll ? {
1649
+ goal: shownGoal.trim() || (runOptions?.attachments ?? []).map((a) => a.name).join(", ")
1650
+ } : {},
1620
1651
  ...start && runOptions?.attachments?.length ? { attachments: runOptions.attachments } : {}
1621
1652
  });
1622
1653
  try {
@@ -1660,18 +1691,16 @@ var useAgent = (config, options = {}) => {
1660
1691
  );
1661
1692
  runRef.current = run;
1662
1693
  const send = useCallback((text) => controlRef.current?.send(text) ?? false, []);
1694
+ const remoteSendsRef = useRef(0);
1663
1695
  const sendRemote = useCallback((text) => {
1664
1696
  const watch = watchRef.current;
1665
1697
  const clean = typeof text === "string" ? text.trim() : "";
1666
1698
  if (!watch?.state.running || !clean) return false;
1699
+ const id = `to-other-tab-${remoteSendsRef.current += 1}`;
1700
+ dispatch({ type: "remote-send", id, text: clean });
1667
1701
  void watch.send(clean).then((ok) => {
1668
- if (!ok) {
1669
- dispatch({
1670
- type: "undelivered",
1671
- texts: [...stateRef.current.undelivered, clean],
1672
- keepQueued: true
1673
- });
1674
- }
1702
+ const answer = remoteAnswerOf(ok, watchRef.current === watch);
1703
+ dispatch({ type: "remote-answer", id, text: clean, answer });
1675
1704
  });
1676
1705
  return true;
1677
1706
  }, []);
@@ -1983,8 +2012,17 @@ var ChatHistoryStore = class {
1983
2012
  await this.write((store) => store.clear(), { op: "clear" });
1984
2013
  }
1985
2014
  };
1986
- var chatTitle = (messages) => {
1987
- const first = messages.find((m) => m.role === "user")?.content.replace(/\s+/g, " ").trim();
2015
+ 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(", ");
2016
+ var oneLine = (text) => (text ?? "").replace(/\s+/g, " ").trim();
2017
+ var chatTitle = (messages, texts = {}) => {
2018
+ const at = messages.findIndex((m) => m.role === "user");
2019
+ const user = at >= 0 ? messages[at] : void 0;
2020
+ let first = oneLine(user?.content);
2021
+ if (!first && user?.attachments?.length) {
2022
+ const answer = messages.slice(at + 1).find((m) => m.role === "assistant");
2023
+ const heard = answer?.transcripts?.find((t) => t.source === "attachment")?.text;
2024
+ first = oneLine(heard) || oneLine(attachmentsText(user.attachments, texts));
2025
+ }
1988
2026
  if (!first) return "New chat";
1989
2027
  return first.length > 60 ? `${first.slice(0, 59)}\u2026` : first;
1990
2028
  };
@@ -2016,7 +2054,7 @@ var renumber = (own, after) => {
2016
2054
  return own.map((m) => ({ ...m, id: `msg-${next += 1}` }));
2017
2055
  };
2018
2056
  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) => {
2057
+ var mergeChatRecord = (view, stored, base, texts) => {
2020
2058
  const local = view.messages.filter((m) => !m.remote);
2021
2059
  if (!stored || base && stored.updatedAt <= base.updatedAt) {
2022
2060
  return { record: { ...view, messages: local }, merged: false };
@@ -2027,7 +2065,7 @@ var mergeChatRecord = (view, stored, base) => {
2027
2065
  record: {
2028
2066
  ...view,
2029
2067
  createdAt: stored.createdAt,
2030
- title: chatTitle(messages),
2068
+ title: chatTitle(messages, texts),
2031
2069
  messages,
2032
2070
  totalUsage: sumUsage(
2033
2071
  stored.totalUsage,
@@ -2037,10 +2075,10 @@ var mergeChatRecord = (view, stored, base) => {
2037
2075
  merged: true
2038
2076
  };
2039
2077
  };
2040
- var saveChat = async (store, view, base) => {
2078
+ var saveChat = async (store, view, base, texts) => {
2041
2079
  let merged = false;
2042
2080
  const record = await store.putMerged(view.id, (stored) => {
2043
- const out = mergeChatRecord(view, stored, base);
2081
+ const out = mergeChatRecord(view, stored, base, texts);
2044
2082
  merged = out.merged;
2045
2083
  return out.record;
2046
2084
  });
@@ -2048,6 +2086,8 @@ var saveChat = async (store, view, base) => {
2048
2086
  };
2049
2087
  var useChatHistory = (agent, options = {}) => {
2050
2088
  const enabled = options.enabled !== false;
2089
+ const textsRef = useRef2(options.labels);
2090
+ textsRef.current = options.labels;
2051
2091
  const store = useMemo(() => options.store ?? new ChatHistoryStore(), [options.store]);
2052
2092
  const [chats, setChats] = useState2([]);
2053
2093
  const [loading, setLoading] = useState2(enabled);
@@ -2141,14 +2181,14 @@ var useChatHistory = (agent, options = {}) => {
2141
2181
  createdRef.current.set(sessionId, createdAt);
2142
2182
  const view = {
2143
2183
  id: sessionId,
2144
- title: chatTitle(messages),
2184
+ title: chatTitle(messages, textsRef.current),
2145
2185
  createdAt,
2146
2186
  updatedAt: now,
2147
2187
  messages,
2148
2188
  totalUsage
2149
2189
  };
2150
2190
  void (async () => {
2151
- const { record, merged } = await saveChat(store, view, base);
2191
+ const { record, merged } = await saveChat(store, view, base, textsRef.current);
2152
2192
  baseRef.current = {
2153
2193
  id: sessionId,
2154
2194
  known: new Set(merged ? record.messages : messages),
@@ -2233,7 +2273,7 @@ var useVirtualFiles = (vfs, prefix = "/") => {
2233
2273
  };
2234
2274
 
2235
2275
  // src/hooks/use-speech-to-text.ts
2236
- import { useCallback as useCallback4, useEffect as useEffect4, useRef as useRef3, useState as useState4 } from "react";
2276
+ import { useCallback as useCallback4, useEffect as useEffect4, useMemo as useMemo2, useRef as useRef3, useState as useState4 } from "react";
2237
2277
  var browserRecognizer = () => {
2238
2278
  const g = globalThis;
2239
2279
  const Ctor = g.SpeechRecognition ?? g.webkitSpeechRecognition;
@@ -2242,13 +2282,18 @@ var browserRecognizer = () => {
2242
2282
  var useSpeechToText = (options = {}) => {
2243
2283
  const optionsRef = useRef3(options);
2244
2284
  optionsRef.current = options;
2245
- const factory = options.createRecognizer ?? browserRecognizer();
2285
+ const own = options.createRecognizer;
2286
+ const factory = useMemo2(() => own ?? browserRecognizer(), [own]);
2246
2287
  const [listening, setListening] = useState4(false);
2247
2288
  const [interim, setInterim] = useState4("");
2248
2289
  const [error, setError] = useState4();
2290
+ const [errorMessage, setErrorMessage] = useState4();
2291
+ const [finishing, setFinishing] = useState4(false);
2249
2292
  const recRef = useRef3(void 0);
2250
2293
  const stop = useCallback4(() => {
2251
- recRef.current?.stop();
2294
+ if (!recRef.current) return;
2295
+ setFinishing(true);
2296
+ recRef.current.stop();
2252
2297
  }, []);
2253
2298
  const start = useCallback4(() => {
2254
2299
  if (!factory || recRef.current) return;
@@ -2266,15 +2311,22 @@ var useSpeechToText = (options = {}) => {
2266
2311
  setInterim(pending);
2267
2312
  };
2268
2313
  rec.onerror = (ev) => {
2269
- if (ev.error && ev.error !== "no-speech" && ev.error !== "aborted") setError(ev.error);
2314
+ if (ev.error && ev.error !== "no-speech" && ev.error !== "aborted") {
2315
+ setError(ev.error);
2316
+ setErrorMessage(ev.message);
2317
+ }
2270
2318
  };
2271
2319
  rec.onend = () => {
2320
+ if (recRef.current !== rec) return;
2272
2321
  recRef.current = void 0;
2273
2322
  setListening(false);
2323
+ setFinishing(false);
2274
2324
  setInterim("");
2275
2325
  };
2276
2326
  recRef.current = rec;
2277
2327
  setError(void 0);
2328
+ setErrorMessage(void 0);
2329
+ setFinishing(false);
2278
2330
  try {
2279
2331
  rec.start();
2280
2332
  setListening(true);
@@ -2283,20 +2335,855 @@ var useSpeechToText = (options = {}) => {
2283
2335
  setError(err instanceof Error ? err.message : String(err));
2284
2336
  }
2285
2337
  }, [factory]);
2286
- useEffect4(() => () => recRef.current?.abort?.(), []);
2338
+ useEffect4(
2339
+ () => () => {
2340
+ const rec = recRef.current;
2341
+ recRef.current = void 0;
2342
+ rec?.abort?.();
2343
+ },
2344
+ [factory]
2345
+ );
2287
2346
  return {
2288
2347
  supported: Boolean(factory),
2289
2348
  listening,
2349
+ finishing,
2290
2350
  interim,
2291
2351
  error,
2352
+ errorMessage,
2292
2353
  start,
2293
2354
  stop,
2294
2355
  toggle: () => recRef.current ? stop() : start()
2295
2356
  };
2296
2357
  };
2297
2358
 
2359
+ // src/hooks/use-audio-recorder.ts
2360
+ import { useCallback as useCallback5, useEffect as useEffect5, useRef as useRef4, useState as useState5 } from "react";
2361
+
2362
+ // src/voice/record.ts
2363
+ var MicError = class extends Error {
2364
+ code;
2365
+ constructor(code, message = code) {
2366
+ super(message);
2367
+ this.name = "MicError";
2368
+ this.code = code;
2369
+ }
2370
+ };
2371
+ var RECORDING_DEFAULT_MAX_MS = 5 * 60 * 1e3;
2372
+ var RECORDING_TYPES = [
2373
+ "audio/webm;codecs=opus",
2374
+ "audio/webm",
2375
+ "audio/mp4",
2376
+ "audio/ogg;codecs=opus",
2377
+ "audio/ogg"
2378
+ ];
2379
+ var pickRecordingType = (isTypeSupported) => {
2380
+ if (!isTypeSupported) return void 0;
2381
+ for (const type of RECORDING_TYPES) {
2382
+ try {
2383
+ if (isTypeSupported(type)) return type;
2384
+ } catch {
2385
+ }
2386
+ }
2387
+ return void 0;
2388
+ };
2389
+ var audioTypeOf = (type) => {
2390
+ const base = (type ?? "").toLowerCase().split(";")[0].trim();
2391
+ if (/^(audio|video)\/(mp4|x-m4a|m4a|aac-mp4)$/.test(base)) return "audio/mp4";
2392
+ if (/^(audio|video)\/webm$/.test(base)) return "audio/webm";
2393
+ if (base === "audio/ogg" || base === "application/ogg") return "audio/ogg";
2394
+ if (base === "audio/wav" || base === "audio/x-wav" || base === "audio/wave") return "audio/wav";
2395
+ if (base === "audio/mpeg" || base === "audio/mp3") return "audio/mpeg";
2396
+ if (base === "audio/aac") return "audio/aac";
2397
+ return "audio/webm";
2398
+ };
2399
+ var audioExtensionOf = (type) => ({
2400
+ "audio/mp4": "m4a",
2401
+ "audio/ogg": "ogg",
2402
+ "audio/wav": "wav",
2403
+ "audio/mpeg": "mp3",
2404
+ "audio/aac": "aac"
2405
+ })[audioTypeOf(type)] ?? "webm";
2406
+ var micProblemOf = (err) => {
2407
+ if (err instanceof MicError) return err.code;
2408
+ const name = err && typeof err === "object" ? String(err.name) : "";
2409
+ if (name === "NotAllowedError" || name === "SecurityError" || name === "PermissionDeniedError")
2410
+ return "not-allowed";
2411
+ if (name === "NotFoundError" || name === "OverconstrainedError" || name === "DevicesNotFoundError")
2412
+ return "audio-capture";
2413
+ if (name === "NotReadableError" || name === "TrackStartError" || name === "AbortError")
2414
+ return "busy";
2415
+ if (name === "NotSupportedError" || name === "TypeError") return "unsupported";
2416
+ return "failed";
2417
+ };
2418
+ var defaults = (deps) => {
2419
+ const g = globalThis;
2420
+ const devices = g.navigator?.mediaDevices;
2421
+ return {
2422
+ getUserMedia: deps.getUserMedia ?? (devices?.getUserMedia ? devices.getUserMedia.bind(devices) : void 0),
2423
+ MediaRecorder: deps.MediaRecorder ?? g.MediaRecorder,
2424
+ now: deps.now ?? Date.now
2425
+ };
2426
+ };
2427
+ var recordingSupported = (deps = {}) => {
2428
+ const d = defaults(deps);
2429
+ return Boolean(d.getUserMedia && d.MediaRecorder);
2430
+ };
2431
+ var stopTracks = (stream) => {
2432
+ for (const track of stream?.getTracks() ?? []) {
2433
+ try {
2434
+ track.stop();
2435
+ } catch {
2436
+ }
2437
+ }
2438
+ };
2439
+ var startRecording = async (options = {}) => {
2440
+ const d = defaults(options);
2441
+ if (!d.getUserMedia || !d.MediaRecorder) throw new MicError("unsupported");
2442
+ let stream;
2443
+ try {
2444
+ stream = await d.getUserMedia({ audio: true });
2445
+ } catch (err) {
2446
+ throw new MicError(micProblemOf(err));
2447
+ }
2448
+ let recorder;
2449
+ try {
2450
+ const type = pickRecordingType(d.MediaRecorder.isTypeSupported?.bind(d.MediaRecorder));
2451
+ recorder = new d.MediaRecorder(stream, type ? { mimeType: type } : void 0);
2452
+ } catch (err) {
2453
+ stopTracks(stream);
2454
+ throw new MicError(micProblemOf(err) === "failed" ? "unsupported" : micProblemOf(err));
2455
+ }
2456
+ const startedAt = d.now();
2457
+ const chunks = [];
2458
+ let cancelled = false;
2459
+ let failure;
2460
+ let settle = () => {
2461
+ };
2462
+ const ended = new Promise((resolve) => settle = resolve);
2463
+ let finish;
2464
+ let fail;
2465
+ const result = new Promise((resolve, reject) => {
2466
+ finish = resolve;
2467
+ fail = reject;
2468
+ });
2469
+ result.catch(() => {
2470
+ });
2471
+ let limit;
2472
+ const end = () => {
2473
+ stopTracks(stream);
2474
+ clearTimeout(limit);
2475
+ settle();
2476
+ };
2477
+ recorder.ondataavailable = (event) => {
2478
+ if (event.data && event.data.size > 0) chunks.push(event.data);
2479
+ };
2480
+ recorder.onerror = () => {
2481
+ failure = new MicError("failed");
2482
+ end();
2483
+ fail?.(failure);
2484
+ };
2485
+ recorder.onstop = () => {
2486
+ end();
2487
+ if (cancelled) return fail?.(new MicError("failed", "cancelled"));
2488
+ if (failure) return fail?.(failure);
2489
+ const mediaType = audioTypeOf(recorder.mimeType || chunks[0]?.type);
2490
+ finish?.({
2491
+ blob: new Blob(chunks, { type: mediaType }),
2492
+ mediaType,
2493
+ durationMs: Math.max(0, d.now() - startedAt)
2494
+ });
2495
+ };
2496
+ const stopRecorder = () => {
2497
+ try {
2498
+ if (recorder.state !== "inactive") recorder.stop();
2499
+ else recorder.onstop?.();
2500
+ } catch {
2501
+ recorder.onstop?.();
2502
+ }
2503
+ };
2504
+ const maxMs = options.maxMs ?? RECORDING_DEFAULT_MAX_MS;
2505
+ limit = setTimeout(() => {
2506
+ stopRecorder();
2507
+ options.onLimit?.();
2508
+ }, maxMs);
2509
+ try {
2510
+ recorder.start(1e3);
2511
+ } catch (err) {
2512
+ end();
2513
+ throw new MicError(micProblemOf(err) === "failed" ? "unsupported" : micProblemOf(err));
2514
+ }
2515
+ return {
2516
+ startedAt,
2517
+ ended,
2518
+ stop: () => {
2519
+ stopRecorder();
2520
+ return result;
2521
+ },
2522
+ cancel: () => {
2523
+ cancelled = true;
2524
+ chunks.length = 0;
2525
+ stopRecorder();
2526
+ end();
2527
+ }
2528
+ };
2529
+ };
2530
+
2531
+ // src/hooks/use-audio-recorder.ts
2532
+ var useAudioRecorder = (options = {}) => {
2533
+ const opts = useRef4(options);
2534
+ opts.current = options;
2535
+ const [state, setState] = useState5("idle");
2536
+ const [elapsedMs, setElapsed] = useState5(0);
2537
+ const [error, setError] = useState5();
2538
+ const [limited, setLimited] = useState5();
2539
+ const rec = useRef4(void 0);
2540
+ const pending = useRef4(false);
2541
+ const gone = useRef4(false);
2542
+ useEffect5(() => {
2543
+ if (state !== "recording") return;
2544
+ const at = rec.current?.startedAt ?? Date.now();
2545
+ const now = opts.current.now ?? Date.now;
2546
+ setElapsed(Math.max(0, now() - at));
2547
+ const id = setInterval(() => setElapsed(Math.max(0, now() - at)), 250);
2548
+ return () => clearInterval(id);
2549
+ }, [state]);
2550
+ const start = useCallback5(async () => {
2551
+ if (rec.current || pending.current) return;
2552
+ pending.current = true;
2553
+ setError(void 0);
2554
+ setLimited(void 0);
2555
+ setState("starting");
2556
+ try {
2557
+ const started = await startRecording({
2558
+ ...opts.current,
2559
+ onLimit: () => {
2560
+ const r = rec.current;
2561
+ rec.current = void 0;
2562
+ setState("stopping");
2563
+ void r?.stop().then(
2564
+ (audio) => !gone.current && setLimited(audio),
2565
+ () => void 0
2566
+ ).finally(() => !gone.current && setState("idle"));
2567
+ }
2568
+ });
2569
+ if (gone.current) return started.cancel();
2570
+ rec.current = started;
2571
+ setState("recording");
2572
+ } catch (err) {
2573
+ if (!gone.current) {
2574
+ setError(micProblemOf(err));
2575
+ setState("idle");
2576
+ }
2577
+ } finally {
2578
+ pending.current = false;
2579
+ }
2580
+ }, []);
2581
+ const stop = useCallback5(async () => {
2582
+ const r = rec.current;
2583
+ if (!r) return void 0;
2584
+ rec.current = void 0;
2585
+ setState("stopping");
2586
+ try {
2587
+ return await r.stop();
2588
+ } catch {
2589
+ return void 0;
2590
+ } finally {
2591
+ if (!gone.current) setState("idle");
2592
+ }
2593
+ }, []);
2594
+ const cancel = useCallback5(() => {
2595
+ const r = rec.current;
2596
+ rec.current = void 0;
2597
+ r?.cancel();
2598
+ setLimited(void 0);
2599
+ setState("idle");
2600
+ }, []);
2601
+ useEffect5(() => {
2602
+ gone.current = false;
2603
+ return () => {
2604
+ gone.current = true;
2605
+ rec.current?.cancel();
2606
+ rec.current = void 0;
2607
+ };
2608
+ }, []);
2609
+ return {
2610
+ supported: recordingSupported(options),
2611
+ state,
2612
+ elapsedMs,
2613
+ error,
2614
+ limited,
2615
+ start,
2616
+ stop,
2617
+ cancel,
2618
+ clear: () => {
2619
+ setLimited(void 0);
2620
+ setError(void 0);
2621
+ }
2622
+ };
2623
+ };
2624
+
2625
+ // src/hooks/use-read-aloud.ts
2626
+ import { useCallback as useCallback6, useEffect as useEffect6, useRef as useRef5, useState as useState6 } from "react";
2627
+
2628
+ // src/voice/speak.ts
2629
+ var SpeechOutputError = class extends Error {
2630
+ code;
2631
+ constructor(code) {
2632
+ super(code);
2633
+ this.name = "SpeechOutputError";
2634
+ this.code = code;
2635
+ }
2636
+ };
2637
+ var asOutputError = (err) => err instanceof SpeechOutputError ? err : new SpeechOutputError(
2638
+ err && typeof err === "object" && "name" in err ? String(err.name) : "playback-failed"
2639
+ );
2640
+ var speakableText = (markdown, options = {}) => {
2641
+ const out = [];
2642
+ const lines = markdown.replace(/\r\n?/g, "\n").split("\n");
2643
+ let fence;
2644
+ let fenceSaid = false;
2645
+ for (const raw of lines) {
2646
+ const line = raw.trimEnd();
2647
+ const opener = /^\s*(`{3,}|~{3,})/.exec(line);
2648
+ if (fence !== void 0) {
2649
+ if (opener && opener[1][0] === fence[0] && opener[1].length >= fence.length) fence = void 0;
2650
+ continue;
2651
+ }
2652
+ if (opener) {
2653
+ fence = opener[1];
2654
+ if (options.code && !fenceSaid) out.push(options.code);
2655
+ fenceSaid = true;
2656
+ continue;
2657
+ }
2658
+ fenceSaid = false;
2659
+ if (/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/.test(line)) continue;
2660
+ if (/^\s*([-*_])\s*(\1\s*){2,}$/.test(line)) continue;
2661
+ let text = line.replace(/^\s{0,3}#{1,6}\s+/, "").replace(/^\s*>\s?/, "").replace(/^\s*(?:[-*+]|\d+[.)])\s+(\[[ xX]\]\s+)?/, "");
2662
+ if (/^\s*\|.*\|\s*$/.test(text))
2663
+ text = text.replace(/^\s*\||\|\s*$/g, "").split("|").map((c) => c.trim()).filter(Boolean).join(", ");
2664
+ 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();
2665
+ if (!text) continue;
2666
+ out.push(/[.!?…:;。!?]$/.test(text) ? text : `${text}.`);
2667
+ }
2668
+ return out.join(" ").trim();
2669
+ };
2670
+ var hostOf = (url) => {
2671
+ try {
2672
+ return new URL(url).hostname.replace(/^www\./, "");
2673
+ } catch {
2674
+ return "";
2675
+ }
2676
+ };
2677
+ var splitForSpeech = (text, max = 220) => {
2678
+ const pieces = [];
2679
+ let rest = text.trim();
2680
+ while (rest.length > max) {
2681
+ const window2 = rest.slice(0, max + 1);
2682
+ let cut = -1;
2683
+ for (const m of window2.matchAll(/[.!?…。!?;:](\s|$)/g))
2684
+ if (m.index !== void 0 && m.index + 1 <= max) cut = m.index + 1;
2685
+ if (cut < max / 3) cut = window2.lastIndexOf(" ");
2686
+ if (cut <= 0) cut = max;
2687
+ pieces.push(rest.slice(0, cut).trim());
2688
+ rest = rest.slice(cut).trim();
2689
+ }
2690
+ if (rest) pieces.push(rest);
2691
+ return pieces;
2692
+ };
2693
+ var SCRIPT_RANGES = [
2694
+ ["latin", /\p{Script=Latin}/u],
2695
+ ["cyrillic", /\p{Script=Cyrillic}/u],
2696
+ ["greek", /\p{Script=Greek}/u],
2697
+ ["arabic", /\p{Script=Arabic}/u],
2698
+ ["hebrew", /\p{Script=Hebrew}/u],
2699
+ ["kana", /[\p{Script=Hiragana}\p{Script=Katakana}]/u],
2700
+ ["han", /\p{Script=Han}/u],
2701
+ ["hangul", /\p{Script=Hangul}/u],
2702
+ ["devanagari", /\p{Script=Devanagari}/u],
2703
+ ["thai", /\p{Script=Thai}/u],
2704
+ ["georgian", /\p{Script=Georgian}/u],
2705
+ ["armenian", /\p{Script=Armenian}/u]
2706
+ ];
2707
+ var LANGUAGE_SCRIPT = {
2708
+ ru: "cyrillic",
2709
+ uk: "cyrillic",
2710
+ be: "cyrillic",
2711
+ bg: "cyrillic",
2712
+ sr: "cyrillic",
2713
+ mk: "cyrillic",
2714
+ kk: "cyrillic",
2715
+ ky: "cyrillic",
2716
+ tg: "cyrillic",
2717
+ mn: "cyrillic",
2718
+ el: "greek",
2719
+ ar: "arabic",
2720
+ fa: "arabic",
2721
+ ur: "arabic",
2722
+ he: "hebrew",
2723
+ yi: "hebrew",
2724
+ zh: "han",
2725
+ ja: "kana",
2726
+ ko: "hangul",
2727
+ hi: "devanagari",
2728
+ mr: "devanagari",
2729
+ ne: "devanagari",
2730
+ th: "thai",
2731
+ ka: "georgian",
2732
+ hy: "armenian"
2733
+ };
2734
+ var SCRIPT_DEFAULT = {
2735
+ latin: "en",
2736
+ cyrillic: "ru",
2737
+ greek: "el",
2738
+ arabic: "ar",
2739
+ hebrew: "he",
2740
+ han: "zh",
2741
+ kana: "ja",
2742
+ hangul: "ko",
2743
+ devanagari: "hi",
2744
+ thai: "th",
2745
+ georgian: "ka",
2746
+ armenian: "hy"
2747
+ };
2748
+ var scriptOfLanguage = (lang) => {
2749
+ const parts = lang.toLowerCase().replace(/_/g, "-").split("-");
2750
+ if (parts.includes("latn")) return "latin";
2751
+ if (parts.includes("cyrl")) return "cyrillic";
2752
+ return LANGUAGE_SCRIPT[parts[0]] ?? "latin";
2753
+ };
2754
+ var scriptOfText = (text) => {
2755
+ const counts = /* @__PURE__ */ new Map();
2756
+ for (const ch of text) {
2757
+ if (!/\p{L}/u.test(ch)) continue;
2758
+ const found = SCRIPT_RANGES.find(([, re]) => re.test(ch));
2759
+ if (!found) continue;
2760
+ counts.set(found[0], (counts.get(found[0]) ?? 0) + 1);
2761
+ }
2762
+ if (counts.has("kana")) {
2763
+ counts.set("kana", (counts.get("kana") ?? 0) + (counts.get("han") ?? 0));
2764
+ counts.delete("han");
2765
+ }
2766
+ let best;
2767
+ let most = 0;
2768
+ for (const [script, n] of counts)
2769
+ if (n > most) {
2770
+ best = script;
2771
+ most = n;
2772
+ }
2773
+ return best;
2774
+ };
2775
+ var languageOfText = (text, preferred = []) => {
2776
+ const mine = preferred.filter((l) => Boolean(l));
2777
+ const script = scriptOfText(text);
2778
+ if (!script) return mine[0];
2779
+ return mine.find((l) => scriptOfLanguage(l) === script) ?? SCRIPT_DEFAULT[script];
2780
+ };
2781
+ var voiceFor = (voices, lang, preferred) => {
2782
+ if (preferred) {
2783
+ const chosen = voices.find((v) => v.voiceURI === preferred);
2784
+ if (chosen && (!lang || scriptOfLanguage(chosen.lang) === scriptOfLanguage(lang))) return chosen;
2785
+ }
2786
+ if (!lang) return void 0;
2787
+ const norm = (l) => l.toLowerCase().replace(/_/g, "-");
2788
+ const want = norm(lang);
2789
+ const base = want.split("-")[0];
2790
+ const rank = (v) => [v.localService ? 1 : 0, v.default ? 1 : 0];
2791
+ const best = (list) => [...list].sort((a, b) => {
2792
+ const ra = rank(a);
2793
+ const rb = rank(b);
2794
+ return rb[0] - ra[0] || rb[1] - ra[1] || a.name.localeCompare(b.name);
2795
+ })[0];
2796
+ const exact = voices.filter((v) => norm(v.lang) === want);
2797
+ if (exact.length) return best(exact);
2798
+ const same = voices.filter((v) => norm(v.lang).split("-")[0] === base);
2799
+ return same.length ? best(same) : void 0;
2800
+ };
2801
+ var voicesOf = (voices, lang) => {
2802
+ if (!lang) return [...voices];
2803
+ const base = lang.toLowerCase().split(/[-_]/)[0];
2804
+ return voices.filter((v) => v.lang.toLowerCase().split(/[-_]/)[0] === base);
2805
+ };
2806
+ var speechSynthesisSupported = () => typeof globalThis !== "undefined" && "speechSynthesis" in globalThis && typeof globalThis.SpeechSynthesisUtterance === "function";
2807
+ var createBrowserSpeaker = (options = {}) => (text, { lang, onState }) => {
2808
+ const synth = options.synth ?? globalThis.speechSynthesis;
2809
+ const make = options.createUtterance ?? ((t) => new globalThis.SpeechSynthesisUtterance(t));
2810
+ const voice = voiceFor(synth.getVoices(), lang, options.voice);
2811
+ let settle;
2812
+ let fail;
2813
+ const done = new Promise((resolve, reject) => {
2814
+ settle = resolve;
2815
+ fail = reject;
2816
+ });
2817
+ done.catch(() => {
2818
+ });
2819
+ let over = false;
2820
+ const end = (err) => {
2821
+ if (over) return;
2822
+ over = true;
2823
+ if (err) fail(err);
2824
+ else settle();
2825
+ };
2826
+ const pieces = splitForSpeech(text);
2827
+ synth.cancel();
2828
+ if (pieces.length === 0) {
2829
+ end();
2830
+ return { pause() {
2831
+ }, resume() {
2832
+ }, stop() {
2833
+ }, done };
2834
+ }
2835
+ let started = false;
2836
+ pieces.forEach((piece, i) => {
2837
+ const u = make(piece);
2838
+ u.lang = voice?.lang ?? lang ?? "";
2839
+ try {
2840
+ u.voice = voice ?? null;
2841
+ } catch {
2842
+ }
2843
+ u.rate = options.rate ?? 1;
2844
+ u.onstart = () => {
2845
+ if (!started && !over) onState("playing");
2846
+ started = true;
2847
+ };
2848
+ u.onend = () => {
2849
+ if (i === pieces.length - 1) end();
2850
+ };
2851
+ u.onerror = (event) => {
2852
+ if (event.error === "interrupted" || event.error === "canceled") end();
2853
+ else end(new SpeechOutputError(event.error || "synthesis-failed"));
2854
+ };
2855
+ synth.speak(u);
2856
+ });
2857
+ onState("loading");
2858
+ return {
2859
+ pause: () => {
2860
+ if (over) return;
2861
+ synth.pause();
2862
+ onState("paused");
2863
+ },
2864
+ resume: () => {
2865
+ if (over) return;
2866
+ synth.resume();
2867
+ onState("playing");
2868
+ },
2869
+ stop: () => {
2870
+ if (over) return;
2871
+ synth.cancel();
2872
+ end();
2873
+ },
2874
+ done
2875
+ };
2876
+ };
2877
+ var silence = () => {
2878
+ const samples = 16;
2879
+ const view = new DataView(new ArrayBuffer(44 + samples * 2));
2880
+ const text = (at, s) => {
2881
+ for (let i = 0; i < s.length; i++) view.setUint8(at + i, s.charCodeAt(i));
2882
+ };
2883
+ text(0, "RIFF");
2884
+ view.setUint32(4, 36 + samples * 2, true);
2885
+ text(8, "WAVEfmt ");
2886
+ view.setUint32(16, 16, true);
2887
+ view.setUint16(20, 1, true);
2888
+ view.setUint16(22, 1, true);
2889
+ view.setUint32(24, 8e3, true);
2890
+ view.setUint32(28, 16e3, true);
2891
+ view.setUint16(32, 2, true);
2892
+ view.setUint16(34, 16, true);
2893
+ text(36, "data");
2894
+ view.setUint32(40, samples * 2, true);
2895
+ return new Blob([view.buffer], { type: "audio/wav" });
2896
+ };
2897
+ var createAudioSpeaker = (options) => (text, { lang, onState }) => {
2898
+ const urls = options.objectUrl ?? {
2899
+ create: (b) => URL.createObjectURL(b),
2900
+ revoke: (u) => URL.revokeObjectURL(u)
2901
+ };
2902
+ const audio = options.createAudio?.() ?? new Audio();
2903
+ const controller = new AbortController();
2904
+ const pieces = splitForSpeech(text, options.maxChars ?? 2e3);
2905
+ let settle;
2906
+ let fail;
2907
+ const done = new Promise((resolve, reject) => {
2908
+ settle = resolve;
2909
+ fail = reject;
2910
+ });
2911
+ done.catch(() => {
2912
+ });
2913
+ let over = false;
2914
+ let paused = false;
2915
+ let current;
2916
+ const made = /* @__PURE__ */ new Map();
2917
+ const make = (i) => {
2918
+ if (!made.has(i)) {
2919
+ const p = options.synthesize(pieces[i], { lang, signal: controller.signal });
2920
+ p.catch(() => {
2921
+ });
2922
+ made.set(i, p);
2923
+ }
2924
+ return made.get(i);
2925
+ };
2926
+ const release = () => {
2927
+ if (current) urls.revoke(current);
2928
+ current = void 0;
2929
+ };
2930
+ const end = (err) => {
2931
+ if (over) return;
2932
+ over = true;
2933
+ controller.abort();
2934
+ audio.pause();
2935
+ audio.onended = null;
2936
+ audio.onerror = null;
2937
+ release();
2938
+ if (err) fail(err);
2939
+ else settle();
2940
+ };
2941
+ const playFrom = async (i) => {
2942
+ if (over) return;
2943
+ if (i >= pieces.length) return end();
2944
+ onState(i === 0 || !current ? "loading" : "playing");
2945
+ let blob;
2946
+ try {
2947
+ blob = await make(i);
2948
+ } catch (err) {
2949
+ return end(err instanceof Error ? err : new Error(String(err)));
2950
+ }
2951
+ if (over) return;
2952
+ if (i + 1 < pieces.length) make(i + 1);
2953
+ release();
2954
+ current = urls.create(blob);
2955
+ audio.src = current;
2956
+ audio.onended = () => void playFrom(i + 1);
2957
+ audio.onerror = () => end(new SpeechOutputError("playback-failed"));
2958
+ if (paused) return onState("paused");
2959
+ try {
2960
+ await audio.play();
2961
+ if (!over) onState("playing");
2962
+ } catch (err) {
2963
+ end(asOutputError(err));
2964
+ }
2965
+ };
2966
+ if (pieces.length === 0) end();
2967
+ else {
2968
+ if (options.unlock !== false) {
2969
+ current = urls.create(silence());
2970
+ audio.src = current;
2971
+ audio.play().catch(() => {
2972
+ });
2973
+ }
2974
+ void playFrom(0);
2975
+ }
2976
+ return {
2977
+ pause: () => {
2978
+ if (over) return;
2979
+ paused = true;
2980
+ audio.pause();
2981
+ onState("paused");
2982
+ },
2983
+ resume: () => {
2984
+ if (over || !paused) return;
2985
+ paused = false;
2986
+ if (current)
2987
+ audio.play().then(
2988
+ () => !over && onState("playing"),
2989
+ (err) => end(asOutputError(err))
2990
+ );
2991
+ else onState("loading");
2992
+ },
2993
+ stop: () => end(),
2994
+ done
2995
+ };
2996
+ };
2997
+
2998
+ // src/hooks/use-read-aloud.ts
2999
+ var browserLanguages = () => typeof navigator !== "undefined" && Array.isArray(navigator.languages) ? navigator.languages : [];
3000
+ var useReadAloud = (speak, lang) => {
3001
+ const [current, setCurrent] = useState6();
3002
+ const [state, setState] = useState6();
3003
+ const [failed, setFailed] = useState6();
3004
+ const playback = useRef5(void 0);
3005
+ const langRef = useRef5(lang);
3006
+ langRef.current = lang;
3007
+ const stop = useCallback6(() => {
3008
+ const now = playback.current;
3009
+ playback.current = void 0;
3010
+ now?.handle.stop();
3011
+ setCurrent(void 0);
3012
+ setState(void 0);
3013
+ }, []);
3014
+ const start = useCallback6(
3015
+ (id, text) => {
3016
+ if (!speak) return;
3017
+ stop();
3018
+ setFailed(void 0);
3019
+ setCurrent(id);
3020
+ setState("loading");
3021
+ const mine = { id, handle: void 0 };
3022
+ playback.current = mine;
3023
+ let handle;
3024
+ try {
3025
+ handle = speak(text, {
3026
+ // The TEXT's language: a Russian answer in an English interface is read in Russian.
3027
+ lang: languageOfText(text, [langRef.current, ...browserLanguages()]),
3028
+ onState: (s) => {
3029
+ if (playback.current === mine) setState(s);
3030
+ }
3031
+ });
3032
+ } catch (err) {
3033
+ playback.current = void 0;
3034
+ setCurrent(void 0);
3035
+ setState(void 0);
3036
+ const own = err instanceof Error && err.name !== "SpeechOutputError";
3037
+ setFailed({ id, ...own && err.message ? { message: err.message } : {} });
3038
+ return;
3039
+ }
3040
+ mine.handle = handle;
3041
+ handle.done.then(
3042
+ () => {
3043
+ if (playback.current !== mine) return;
3044
+ playback.current = void 0;
3045
+ setCurrent(void 0);
3046
+ setState(void 0);
3047
+ },
3048
+ (err) => {
3049
+ if (playback.current !== mine) return;
3050
+ playback.current = void 0;
3051
+ setCurrent(void 0);
3052
+ setState(void 0);
3053
+ const own = err instanceof Error && err.name !== "SpeechOutputError";
3054
+ setFailed({ id, ...own && err.message ? { message: err.message } : {} });
3055
+ }
3056
+ );
3057
+ },
3058
+ [speak, stop]
3059
+ );
3060
+ useEffect6(() => stop, [speak, stop]);
3061
+ return {
3062
+ current,
3063
+ state,
3064
+ failed,
3065
+ start,
3066
+ pause: () => playback.current?.handle.pause(),
3067
+ resume: () => playback.current?.handle.resume(),
3068
+ stop
3069
+ };
3070
+ };
3071
+
3072
+ // src/hooks/use-speech-voices.ts
3073
+ import { useEffect as useEffect7, useState as useState7 } from "react";
3074
+ var useSpeechVoices = () => {
3075
+ const synth = typeof globalThis !== "undefined" ? globalThis.speechSynthesis : void 0;
3076
+ const read = () => {
3077
+ try {
3078
+ return (synth?.getVoices() ?? []).map((v) => ({
3079
+ voiceURI: v.voiceURI,
3080
+ name: v.name,
3081
+ lang: v.lang,
3082
+ localService: v.localService,
3083
+ default: v.default
3084
+ }));
3085
+ } catch {
3086
+ return [];
3087
+ }
3088
+ };
3089
+ const [voices, setVoices] = useState7(read);
3090
+ useEffect7(() => {
3091
+ if (!synth) return;
3092
+ const update = () => setVoices(read());
3093
+ update();
3094
+ synth.addEventListener?.("voiceschanged", update);
3095
+ return () => synth.removeEventListener?.("voiceschanged", update);
3096
+ }, [synth]);
3097
+ return voices;
3098
+ };
3099
+
3100
+ // src/voice/recognizer.ts
3101
+ var createRecordingRecognizer = (options) => () => {
3102
+ let recording;
3103
+ let starting;
3104
+ let stopAsked = false;
3105
+ let aborted = false;
3106
+ let ended = false;
3107
+ const controller = new AbortController();
3108
+ const rec = {
3109
+ lang: "",
3110
+ continuous: true,
3111
+ interimResults: false,
3112
+ onresult: null,
3113
+ onerror: null,
3114
+ onend: null,
3115
+ start() {
3116
+ if (starting) return;
3117
+ starting = (async () => {
3118
+ try {
3119
+ recording = await startRecording({
3120
+ ...options,
3121
+ maxMs: options.maxMs,
3122
+ onLimit: () => rec.stop()
3123
+ });
3124
+ } catch (err) {
3125
+ if (!aborted) rec.onerror?.({ error: micProblemOf(err) });
3126
+ return finish();
3127
+ }
3128
+ if (aborted) {
3129
+ recording.cancel();
3130
+ return finish();
3131
+ }
3132
+ if (stopAsked) void transcribeNow();
3133
+ })();
3134
+ },
3135
+ stop() {
3136
+ if (stopAsked || ended) return;
3137
+ stopAsked = true;
3138
+ if (recording) void transcribeNow();
3139
+ },
3140
+ abort() {
3141
+ if (ended) return;
3142
+ aborted = true;
3143
+ controller.abort();
3144
+ recording?.cancel();
3145
+ if (!starting || recording) finish();
3146
+ }
3147
+ };
3148
+ const finish = () => {
3149
+ if (ended) return;
3150
+ ended = true;
3151
+ rec.onend?.();
3152
+ };
3153
+ let transcribing = false;
3154
+ const transcribeNow = async () => {
3155
+ if (transcribing || !recording) return;
3156
+ transcribing = true;
3157
+ let audio;
3158
+ try {
3159
+ audio = await recording.stop();
3160
+ } catch (err) {
3161
+ if (!aborted) rec.onerror?.({ error: micProblemOf(err) });
3162
+ return finish();
3163
+ }
3164
+ if (aborted) return finish();
3165
+ if (audio.blob.size === 0) return finish();
3166
+ try {
3167
+ const text = (await options.transcribe(audio, { lang: rec.lang, signal: controller.signal })).replace(/\s+/g, " ").trim();
3168
+ if (!aborted && text)
3169
+ rec.onresult?.({
3170
+ resultIndex: 0,
3171
+ results: [{ isFinal: true, 0: { transcript: text } }]
3172
+ });
3173
+ } catch (err) {
3174
+ if (!aborted)
3175
+ rec.onerror?.({
3176
+ error: "transcription",
3177
+ message: err instanceof Error ? err.message : String(err)
3178
+ });
3179
+ }
3180
+ finish();
3181
+ };
3182
+ return rec;
3183
+ };
3184
+
2298
3185
  // src/hooks/use-credentials.ts
2299
- import { useCallback as useCallback5, useEffect as useEffect5, useMemo as useMemo2, useState as useState5 } from "react";
3186
+ import { useCallback as useCallback7, useEffect as useEffect8, useMemo as useMemo3, useState as useState8 } from "react";
2300
3187
  import * as core5 from "@dudko.dev/agent-web";
2301
3188
  import { VaultCredentialStore } from "@dudko.dev/agent-web";
2302
3189
  var storeDbName = (store) => {
@@ -2304,10 +3191,10 @@ var storeDbName = (store) => {
2304
3191
  return typeof name === "string" && name ? name : void 0;
2305
3192
  };
2306
3193
  var useCredentials = (store) => {
2307
- const resolved = useMemo2(() => store ?? new VaultCredentialStore(), [store]);
2308
- const [version, setVersion] = useState5(0);
3194
+ const resolved = useMemo3(() => store ?? new VaultCredentialStore(), [store]);
3195
+ const [version, setVersion] = useState8(0);
2309
3196
  const dbName = storeDbName(resolved);
2310
- useEffect5(() => {
3197
+ useEffect8(() => {
2311
3198
  return followOtherTabs(
2312
3199
  core5,
2313
3200
  dbName,
@@ -2315,21 +3202,21 @@ var useCredentials = (store) => {
2315
3202
  () => setVersion((v) => v + 1)
2316
3203
  );
2317
3204
  }, [dbName]);
2318
- const setKey = useCallback5(
3205
+ const setKey = useCallback7(
2319
3206
  async (ref, key) => {
2320
3207
  await resolved.setApiKey(ref, key);
2321
3208
  setVersion((v) => v + 1);
2322
3209
  },
2323
3210
  [resolved]
2324
3211
  );
2325
- const removeKey = useCallback5(
3212
+ const removeKey = useCallback7(
2326
3213
  async (ref) => {
2327
3214
  await resolved.deleteApiKey(ref);
2328
3215
  setVersion((v) => v + 1);
2329
3216
  },
2330
3217
  [resolved]
2331
3218
  );
2332
- const hasKey = useCallback5(
3219
+ const hasKey = useCallback7(
2333
3220
  async (ref) => await resolved.getApiKey(ref) !== void 0,
2334
3221
  [resolved]
2335
3222
  );
@@ -2346,21 +3233,21 @@ import {
2346
3233
  } from "@dudko.dev/agent-web";
2347
3234
 
2348
3235
  // src/hooks/use-local-model.ts
2349
- import { useCallback as useCallback6, useRef as useRef4, useState as useState6 } from "react";
3236
+ import { useCallback as useCallback8, useRef as useRef6, useState as useState9 } from "react";
2350
3237
  var keyOf = (id, tokens) => tokens ? `${id}@${tokens}` : id;
2351
3238
  var useLocalModel = (modelId, engine, options) => {
2352
- const [loaded, setLoaded] = useState6(void 0);
2353
- const [pending, setPending] = useState6();
2354
- const [failure, setFailure] = useState6();
2355
- const engineRef = useRef4(engine);
3239
+ const [loaded, setLoaded] = useState9(void 0);
3240
+ const [pending, setPending] = useState9();
3241
+ const [failure, setFailure] = useState9();
3242
+ const engineRef = useRef6(engine);
2356
3243
  engineRef.current = engine;
2357
- const loadedRef = useRef4(void 0);
2358
- const inflightRef = useRef4(
3244
+ const loadedRef = useRef6(void 0);
3245
+ const inflightRef = useRef6(
2359
3246
  void 0
2360
3247
  );
2361
3248
  const windowTokens = options?.contextWindowTokens;
2362
3249
  const key = keyOf(modelId, windowTokens);
2363
- const seqRef = useRef4(0);
3250
+ const seqRef = useRef6(0);
2364
3251
  const setHeld = (next) => {
2365
3252
  loadedRef.current = next;
2366
3253
  setLoaded(next);
@@ -2371,7 +3258,7 @@ var useLocalModel = (modelId, engine, options) => {
2371
3258
  } catch {
2372
3259
  }
2373
3260
  };
2374
- const load = useCallback6(() => {
3261
+ const load = useCallback8(() => {
2375
3262
  const id = modelId;
2376
3263
  if (loadedRef.current?.key === key) return Promise.resolve(loadedRef.current.model);
2377
3264
  if (inflightRef.current?.key === key) return inflightRef.current.promise;
@@ -2423,7 +3310,7 @@ var useLocalModel = (modelId, engine, options) => {
2423
3310
  inflightRef.current = { key, promise };
2424
3311
  return promise;
2425
3312
  }, [modelId, key]);
2426
- const unload = useCallback6(async () => {
3313
+ const unload = useCallback8(async () => {
2427
3314
  seqRef.current++;
2428
3315
  inflightRef.current = void 0;
2429
3316
  setPending(void 0);
@@ -2485,7 +3372,7 @@ var createWebLLMEngine = (options) => {
2485
3372
  };
2486
3373
 
2487
3374
  // src/labels.tsx
2488
- import { createContext, useContext, useMemo as useMemo3 } from "react";
3375
+ import { createContext, useContext, useMemo as useMemo4 } from "react";
2489
3376
 
2490
3377
  // src/composer.ts
2491
3378
  var parseSlash = (text) => {
@@ -2651,6 +3538,27 @@ var noticesOf = (state, texts = {}) => {
2651
3538
  }
2652
3539
  return out;
2653
3540
  };
3541
+ var formatClock = (ms) => {
3542
+ const s = Math.max(0, Math.floor(ms / 1e3));
3543
+ const two = (n) => String(n).padStart(2, "0");
3544
+ const h = Math.floor(s / 3600);
3545
+ const m = Math.floor(s % 3600 / 60);
3546
+ return h > 0 ? `${h}:${two(m)}:${two(s % 60)}` : `${m}:${two(s % 60)}`;
3547
+ };
3548
+ var micProblemText = (code, message, labels) => {
3549
+ if (code === "not-allowed" || code === "service-not-allowed") return labels.micDenied;
3550
+ if (code === "audio-capture") return labels.micMissing;
3551
+ if (code === "busy") return labels.micBusy;
3552
+ if (code === "unsupported") return labels.micUnsupported;
3553
+ if (message) return message;
3554
+ return code && code !== "transcription" && code !== "failed" ? `${labels.dictationFailed} (${code})` : labels.dictationFailed;
3555
+ };
3556
+ var voiceMessageName = (at, extension) => {
3557
+ const two = (n) => String(n).padStart(2, "0");
3558
+ return `voice-${at.getFullYear()}-${two(at.getMonth() + 1)}-${two(at.getDate())}-${two(
3559
+ at.getHours()
3560
+ )}${two(at.getMinutes())}${two(at.getSeconds())}.${extension}`;
3561
+ };
2654
3562
 
2655
3563
  // src/labels.tsx
2656
3564
  import { jsx } from "react/jsx-runtime";
@@ -2691,6 +3599,11 @@ var defaultLabels = {
2691
3599
  notebookForget: "Forget",
2692
3600
  notebookRevision: (n) => `revision ${n}`,
2693
3601
  notebookFrom: "from",
3602
+ memorySaved: "Remembered",
3603
+ memoryUpdated: "Memory updated",
3604
+ memoryForgotten: "Forgotten",
3605
+ memoryUndo: "Undo",
3606
+ memoryUndone: "Undone",
2694
3607
  placeholder: "Ask the agent to do something\u2026 ( / for commands, Ctrl+V to paste an image )",
2695
3608
  listening: "Listening\u2026",
2696
3609
  message: "Message",
@@ -2707,6 +3620,19 @@ var defaultLabels = {
2707
3620
  dictateTitle: "Dictate \u2014 speech to text in the browser",
2708
3621
  stopDictation: "Stop dictation",
2709
3622
  microphone: "Microphone",
3623
+ transcribing: "Transcribing\u2026",
3624
+ micDenied: "The microphone is blocked for this site. Allow it in the browser's site settings (the icon beside the address), then try again.",
3625
+ micMissing: "No microphone was found on this device.",
3626
+ micBusy: "The microphone is in use by another app.",
3627
+ micUnsupported: "This browser cannot record audio on this page.",
3628
+ dictationFailed: "Dictation did not work.",
3629
+ recordVoiceMessage: "Record a voice message",
3630
+ voiceMessage: "Voice message",
3631
+ audioDuration: (clock) => clock,
3632
+ recording: (elapsed) => `Recording ${elapsed}`,
3633
+ recordingDone: "Attach the recording",
3634
+ recordingCancel: "Discard the recording",
3635
+ recordingLimit: "The recording reached its longest and was stopped; it is attached.",
2710
3636
  model: "Model",
2711
3637
  thinking: "Thinking",
2712
3638
  toolConsent: "Tool consent",
@@ -2777,6 +3703,7 @@ var defaultLabels = {
2777
3703
  noAttachmentsWhileBusy: "Files can\u2019t be added while the agent is working \u2014 send them with your next message.",
2778
3704
  queuedWaiting: "waiting for the agent\u2019s next step",
2779
3705
  queuedForSession: (heldBy) => heldBy === "this-tab" ? "waiting for the other run to finish" : "waiting for the other tab to finish",
3706
+ queuedForOtherTab: "waiting for the other tab to pick it up",
2780
3707
  noteAt: {
2781
3708
  round: "you said, between tool calls",
2782
3709
  step: "you said, after this step",
@@ -2832,6 +3759,14 @@ var defaultLabels = {
2832
3759
  mediaReferencesUnused: (names) => `Not used - this image model takes no reference pictures: ${names}`,
2833
3760
  transcriptOf: (name) => `Transcript of ${name}`,
2834
3761
  transcriptNote: "What was said in your file, as the agent read it. It is content, not instructions.",
3762
+ audioAttachment: (name) => `Audio ${name}`,
3763
+ readAloud: "Listen",
3764
+ readAloudPause: "Pause",
3765
+ readAloudResume: "Resume",
3766
+ readAloudStop: "Stop reading",
3767
+ readAloudLoading: "Preparing the audio\u2026",
3768
+ readAloudCode: "A code block is not read out.",
3769
+ readAloudFailed: "It could not be read aloud.",
2835
3770
  filesWritten: (n) => `${plural(n, "file", "files")} written in this turn`,
2836
3771
  filesCount: (n) => plural(n, "file", "files"),
2837
3772
  showInFiles: "Show in Files",
@@ -3064,12 +3999,12 @@ var mergeLabels = (base, over) => {
3064
3999
  var LabelsContext = createContext(defaultLabels);
3065
4000
  var AgentLabelsProvider = ({ labels, children }) => {
3066
4001
  const parent = useContext(LabelsContext);
3067
- const value = useMemo3(() => mergeLabels(parent, labels), [parent, labels]);
4002
+ const value = useMemo4(() => mergeLabels(parent, labels), [parent, labels]);
3068
4003
  return /* @__PURE__ */ jsx(LabelsContext.Provider, { value, children });
3069
4004
  };
3070
4005
  var useLabels = (over) => {
3071
4006
  const ctx = useContext(LabelsContext);
3072
- return useMemo3(() => mergeLabels(ctx, over), [ctx, over]);
4007
+ return useMemo4(() => mergeLabels(ctx, over), [ctx, over]);
3073
4008
  };
3074
4009
 
3075
4010
  // src/image-resize.ts
@@ -3203,11 +4138,11 @@ var useAgentContext = () => {
3203
4138
  var useOptionalAgentContext = () => useContext2(AgentContext);
3204
4139
 
3205
4140
  // src/components/AgentChat.tsx
3206
- import { useEffect as useEffect17, useRef as useRef12, useState as useState17 } from "react";
4141
+ import { useEffect as useEffect20, useRef as useRef14, useState as useState20 } from "react";
3207
4142
  import { createPortal as createPortal2 } from "react-dom";
3208
4143
 
3209
4144
  // src/hooks/use-follow-scroll.ts
3210
- import { useEffect as useEffect6, useLayoutEffect, useRef as useRef5 } from "react";
4145
+ import { useEffect as useEffect9, useLayoutEffect, useRef as useRef7 } from "react";
3211
4146
 
3212
4147
  // src/follow-scroll.ts
3213
4148
  var FOLLOW_REJOIN_PX = 80;
@@ -3224,7 +4159,7 @@ var followsAfterScroll = (following, before, now) => {
3224
4159
  var followsAfterResize = (following, before, now) => following && !(now.clientHeight === before.clientHeight && now.scrollHeight >= before.scrollHeight && now.scrollTop < reach(before) - FOLLOW_LEAVE_PX);
3225
4160
 
3226
4161
  // src/hooks/use-follow-scroll.ts
3227
- var useIsoLayoutEffect = typeof window === "undefined" ? useEffect6 : useLayoutEffect;
4162
+ var useIsoLayoutEffect = typeof window === "undefined" ? useEffect9 : useLayoutEffect;
3228
4163
  var measure = (el) => ({
3229
4164
  scrollTop: el.scrollTop,
3230
4165
  scrollHeight: el.scrollHeight,
@@ -3246,12 +4181,12 @@ var anchorOf = (el) => {
3246
4181
  return marks.length ? { marks, top: el.scrollTop } : void 0;
3247
4182
  };
3248
4183
  var useFollowScroll = (ref, turn, live = true) => {
3249
- const following = useRef5(true);
3250
- const last = useRef5(void 0);
3251
- const anchor = useRef5(void 0);
3252
- const settle = useRef5(() => {
4184
+ const following = useRef7(true);
4185
+ const last = useRef7(void 0);
4186
+ const anchor = useRef7(void 0);
4187
+ const settle = useRef7(() => {
3253
4188
  });
3254
- const arriving = useRef5(live);
4189
+ const arriving = useRef7(live);
3255
4190
  arriving.current = live;
3256
4191
  useIsoLayoutEffect(() => {
3257
4192
  const el = ref.current;
@@ -3324,7 +4259,7 @@ var useFollowScroll = (ref, turn, live = true) => {
3324
4259
  };
3325
4260
 
3326
4261
  // src/hooks/use-mcp-app-host.ts
3327
- import { useCallback as useCallback7, useEffect as useEffect7, useMemo as useMemo4, useRef as useRef6, useState as useState7 } from "react";
4262
+ import { useCallback as useCallback9, useEffect as useEffect10, useMemo as useMemo5, useRef as useRef8, useState as useState10 } from "react";
3328
4263
 
3329
4264
  // src/mcp-app.ts
3330
4265
  import { mcpAppOrigin } from "@dudko.dev/agent-web";
@@ -4151,27 +5086,27 @@ var useMcpAppHost = ({
4151
5086
  sampling = false,
4152
5087
  sample: sampleFn
4153
5088
  }) => {
4154
- const [requests, setRequests] = useState7([]);
4155
- const [draft, setDraft] = useState7();
4156
- const waiting = useRef6(
5089
+ const [requests, setRequests] = useState10([]);
5090
+ const [draft, setDraft] = useState10();
5091
+ const waiting = useRef8(
4157
5092
  /* @__PURE__ */ new Map()
4158
5093
  );
4159
- const samplingAllowed = useRef6(/* @__PURE__ */ new Set());
4160
- const sampleRef = useRef6(sampleFn);
5094
+ const samplingAllowed = useRef8(/* @__PURE__ */ new Set());
5095
+ const sampleRef = useRef8(sampleFn);
4161
5096
  sampleRef.current = sampleFn;
4162
- const [gated, setGated] = useState7({});
4163
- const connectionRef = useRef6(connection);
5097
+ const [gated, setGated] = useState10({});
5098
+ const connectionRef = useRef8(connection);
4164
5099
  connectionRef.current = connection;
4165
- const approveRef = useRef6(approve);
5100
+ const approveRef = useRef8(approve);
4166
5101
  approveRef.current = approve;
4167
- useEffect7(
5102
+ useEffect10(
4168
5103
  () => () => {
4169
5104
  for (const { resolve } of waiting.current.values()) resolve(false);
4170
5105
  waiting.current.clear();
4171
5106
  },
4172
5107
  []
4173
5108
  );
4174
- const ask = useCallback7(
5109
+ const ask = useCallback9(
4175
5110
  (request, signal, extra = {}) => {
4176
5111
  for (const w of waiting.current.values()) {
4177
5112
  if (w.request.appId === request.appId) {
@@ -4196,7 +5131,7 @@ var useMcpAppHost = ({
4196
5131
  },
4197
5132
  []
4198
5133
  );
4199
- const answer = useCallback7((id, accept, options) => {
5134
+ const answer = useCallback9((id, accept, options) => {
4200
5135
  const w = waiting.current.get(id);
4201
5136
  if (!w) return;
4202
5137
  if (accept && w.request.kind === "link" && w.request.link) {
@@ -4222,16 +5157,16 @@ var useMcpAppHost = ({
4222
5157
  }
4223
5158
  w.resolve(accept);
4224
5159
  }, []);
4225
- const read = useCallback7((app, signal) => {
5160
+ const read = useCallback9((app, signal) => {
4226
5161
  const c = connectionRef.current;
4227
5162
  if (!c) return Promise.reject(new Error(`no connection to the server \u201C${app.server}\u201D`));
4228
5163
  return c.readUiResource(app.server, app.resourceUri, signal ? { signal } : void 0);
4229
5164
  }, []);
4230
- const tool = useCallback7(
5165
+ const tool = useCallback9(
4231
5166
  (app) => connectionRef.current?.appTool(app.server, app.toolName),
4232
5167
  []
4233
5168
  );
4234
- const callTool = useCallback7(
5169
+ const callTool = useCallback9(
4235
5170
  async (app, name, args, signal) => {
4236
5171
  const c = connectionRef.current;
4237
5172
  if (!c) throw refused(`The server \u201C${app.server}\u201D is not connected`);
@@ -4268,15 +5203,15 @@ var useMcpAppHost = ({
4268
5203
  },
4269
5204
  []
4270
5205
  );
4271
- const openLink = useCallback7(
5206
+ const openLink = useCallback9(
4272
5207
  (app, link, signal) => ask({ appId: app.id, server: app.server, kind: "link", link }, signal),
4273
5208
  [ask]
4274
5209
  );
4275
- const message = useCallback7(
5210
+ const message = useCallback9(
4276
5211
  (app, text, signal) => ask({ appId: app.id, server: app.server, kind: "message", text }, signal),
4277
5212
  [ask]
4278
5213
  );
4279
- const downloadFile2 = useCallback7(
5214
+ const downloadFile2 = useCallback9(
4280
5215
  async (app, file, signal) => {
4281
5216
  const c = connectionRef.current;
4282
5217
  if (file.kind === "link" && !c) throw refused(`The server \u201C${app.server}\u201D is not connected`);
@@ -4299,7 +5234,7 @@ var useMcpAppHost = ({
4299
5234
  },
4300
5235
  [ask]
4301
5236
  );
4302
- const sample = useCallback7(
5237
+ const sample = useCallback9(
4303
5238
  async (app, params, signal) => {
4304
5239
  const fn = sampleRef.current;
4305
5240
  if (!fn) throw refused("This host cannot answer sampling requests");
@@ -4320,19 +5255,19 @@ var useMcpAppHost = ({
4320
5255
  },
4321
5256
  [ask]
4322
5257
  );
4323
- const pendingAppServers = useMemo4(
5258
+ const pendingAppServers = useMemo5(
4324
5259
  () => new Set(
4325
5260
  approvals.filter((a) => a.app && a.status === "pending").map((a) => `${a.app.server}\0${a.app.resourceUri}`)
4326
5261
  ),
4327
5262
  [approvals]
4328
5263
  );
4329
- const isWaiting = useCallback7(
5264
+ const isWaiting = useCallback9(
4330
5265
  (app) => requests.some((r) => r.appId === app.id) || Boolean(gated[app.id]) && pendingAppServers.has(`${app.server}\0${app.resourceUri}`),
4331
5266
  [requests, gated, pendingAppServers]
4332
5267
  );
4333
5268
  const sandboxUrl = sandbox?.url;
4334
5269
  const sandboxTimeout = sandbox?.timeoutMs;
4335
- const sandboxSetting = useMemo4(
5270
+ const sandboxSetting = useMemo5(
4336
5271
  () => sandboxUrl === void 0 ? void 0 : {
4337
5272
  url: sandboxUrl,
4338
5273
  ...sandboxTimeout !== void 0 ? { timeoutMs: sandboxTimeout } : {}
@@ -4340,7 +5275,7 @@ var useMcpAppHost = ({
4340
5275
  [sandboxUrl, sandboxTimeout]
4341
5276
  );
4342
5277
  const samplingOn = sampling && Boolean(sampleFn);
4343
- return useMemo4(
5278
+ return useMemo5(
4344
5279
  () => ({
4345
5280
  connected: Boolean(connection),
4346
5281
  read,
@@ -4495,11 +5430,11 @@ var AppRequestPrompt = ({
4495
5430
  };
4496
5431
 
4497
5432
  // src/components/McpAppFrame.tsx
4498
- import { useEffect as useEffect8, useLayoutEffect as useLayoutEffect2, useMemo as useMemo5, useRef as useRef7, useState as useState8 } from "react";
5433
+ import { useEffect as useEffect11, useLayoutEffect as useLayoutEffect2, useMemo as useMemo6, useRef as useRef9, useState as useState11 } from "react";
4499
5434
  import { Fragment, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
4500
5435
  var HOST_INFO = { name: "@dudko.dev/agent-web-react", version: "1" };
4501
5436
  var MAX_LISTED_CALLS = 12;
4502
- var useIsoLayoutEffect2 = typeof window === "undefined" ? useEffect8 : useLayoutEffect2;
5437
+ var useIsoLayoutEffect2 = typeof window === "undefined" ? useEffect11 : useLayoutEffect2;
4503
5438
  var userActivation = () => typeof navigator === "undefined" ? void 0 : navigator.userActivation?.isActive;
4504
5439
  var silentSandboxes = /* @__PURE__ */ new Set();
4505
5440
  var warned = /* @__PURE__ */ new Set();
@@ -4532,36 +5467,36 @@ var McpAppFrame = ({
4532
5467
  className
4533
5468
  }) => {
4534
5469
  const L = useLabels(labels);
4535
- const [collapsed, setCollapsed] = useState8(defaultCollapsed);
4536
- const [menu, setMenu] = useState8(false);
4537
- const [reload, setReload] = useState8(0);
4538
- const [loaded, setLoaded] = useState8();
4539
- const [height, setHeight] = useState8(APP_DEFAULT_HEIGHT);
4540
- const [calls, setCalls] = useState8([]);
4541
- const [fallback, setFallback] = useState8();
4542
- const [broken, setBroken] = useState8(false);
4543
- const [onOrigin, setOnOrigin] = useState8(false);
4544
- const shellLoaded = useRef7(void 0);
4545
- const [mode, setMode] = useState8("inline");
4546
- const modeRef = useRef7("inline");
4547
- const [holder, setHolder] = useState8(0);
4548
- const [fullRect, setFullRect] = useState8();
4549
- const leaveRef = useRef7(void 0);
4550
- const rootRef = useRef7(null);
4551
- const exitRef = useRef7(null);
4552
- const allowFullscreenRef = useRef7(allowFullscreen);
5470
+ const [collapsed, setCollapsed] = useState11(defaultCollapsed);
5471
+ const [menu, setMenu] = useState11(false);
5472
+ const [reload, setReload] = useState11(0);
5473
+ const [loaded, setLoaded] = useState11();
5474
+ const [height, setHeight] = useState11(APP_DEFAULT_HEIGHT);
5475
+ const [calls, setCalls] = useState11([]);
5476
+ const [fallback, setFallback] = useState11();
5477
+ const [broken, setBroken] = useState11(false);
5478
+ const [onOrigin, setOnOrigin] = useState11(false);
5479
+ const shellLoaded = useRef9(void 0);
5480
+ const [mode, setMode] = useState11("inline");
5481
+ const modeRef = useRef9("inline");
5482
+ const [holder, setHolder] = useState11(0);
5483
+ const [fullRect, setFullRect] = useState11();
5484
+ const leaveRef = useRef9(void 0);
5485
+ const rootRef = useRef9(null);
5486
+ const exitRef = useRef9(null);
5487
+ const allowFullscreenRef = useRef9(allowFullscreen);
4553
5488
  allowFullscreenRef.current = allowFullscreen;
4554
- const iframeRef = useRef7(null);
4555
- const bridgeRef = useRef7(void 0);
4556
- const menuRef = useRef7(null);
4557
- const themeRef = useRef7(theme);
5489
+ const iframeRef = useRef9(null);
5490
+ const bridgeRef = useRef9(void 0);
5491
+ const menuRef = useRef9(null);
5492
+ const themeRef = useRef9(theme);
4558
5493
  themeRef.current = theme;
4559
- const hostRef = useRef7(host);
5494
+ const hostRef = useRef9(host);
4560
5495
  hostRef.current = host;
4561
- const appRef = useRef7(app);
5496
+ const appRef = useRef9(app);
4562
5497
  appRef.current = app;
4563
5498
  const live = !collapsed;
4564
- useEffect8(() => {
5499
+ useEffect11(() => {
4565
5500
  if (!live) return;
4566
5501
  if (!hostRef.current.connected) {
4567
5502
  setLoaded({ unavailable: true });
@@ -4584,7 +5519,7 @@ var McpAppFrame = ({
4584
5519
  const resource = loaded && "resource" in loaded ? loaded.resource : void 0;
4585
5520
  const sandboxUrl = host.sandbox?.url;
4586
5521
  const timeoutMs = host.sandbox?.timeoutMs ?? MCP_APP_SANDBOX_TIMEOUT_MS;
4587
- const placement = useMemo5(() => {
5522
+ const placement = useMemo6(() => {
4588
5523
  if (!resource) return void 0;
4589
5524
  if (sandboxUrl === void 0) return { mode: "opaque" };
4590
5525
  if (fallback) return { mode: "opaque", reason: fallback };
@@ -4595,11 +5530,11 @@ var McpAppFrame = ({
4595
5530
  if (!url) return { mode: "opaque", reason: "too-many-origins" };
4596
5531
  return { mode: "origin", origin: target.origin, url };
4597
5532
  }, [resource, sandboxUrl, fallback, app.server, reload]);
4598
- const doc = useMemo5(
5533
+ const doc = useMemo6(
4599
5534
  () => !resource || !placement ? void 0 : placement.mode === "origin" ? buildMcpAppSandboxShell(placement.url) : buildMcpAppDocument(resource.html, resource.csp),
4600
5535
  [resource, placement]
4601
5536
  );
4602
- useEffect8(() => {
5537
+ useEffect11(() => {
4603
5538
  const reason = placement?.mode === "opaque" ? placement.reason : void 0;
4604
5539
  if (reason && reason !== "no-answer" && sandboxUrl !== void 0) {
4605
5540
  warnOnce(
@@ -4608,7 +5543,7 @@ var McpAppFrame = ({
4608
5543
  );
4609
5544
  }
4610
5545
  }, [placement, sandboxUrl]);
4611
- useEffect8(() => {
5546
+ useEffect11(() => {
4612
5547
  const frame = iframeRef.current;
4613
5548
  if (!live || !resource || !frame || !placement || broken) return;
4614
5549
  const abort = new AbortController();
@@ -4753,7 +5688,7 @@ var McpAppFrame = ({
4753
5688
  }, [live, resource, reload, variant, app.id, placement, broken, timeoutMs]);
4754
5689
  const fullscreen = mode === "fullscreen" && live && !broken;
4755
5690
  const waitingNow = host.isWaiting(app);
4756
- useEffect8(() => {
5691
+ useEffect11(() => {
4757
5692
  if (fullscreen && waitingNow) leaveRef.current?.();
4758
5693
  }, [fullscreen, waitingNow]);
4759
5694
  useIsoLayoutEffect2(() => {
@@ -4788,7 +5723,7 @@ var McpAppFrame = ({
4788
5723
  ro?.disconnect();
4789
5724
  };
4790
5725
  }, [fullscreen]);
4791
- useEffect8(() => {
5726
+ useEffect11(() => {
4792
5727
  if (!fullscreen) return;
4793
5728
  const before = document.activeElement;
4794
5729
  exitRef.current?.focus();
@@ -4805,10 +5740,10 @@ var McpAppFrame = ({
4805
5740
  if (frame && (before === frame || document.activeElement === document.body)) frame.focus();
4806
5741
  };
4807
5742
  }, [fullscreen]);
4808
- useEffect8(() => {
5743
+ useEffect11(() => {
4809
5744
  if (theme) bridgeRef.current?.updateContext({ theme });
4810
5745
  }, [theme]);
4811
- useEffect8(() => {
5746
+ useEffect11(() => {
4812
5747
  if (!menu) return;
4813
5748
  const close = (e) => {
4814
5749
  if (e instanceof KeyboardEvent ? e.key === "Escape" : !menuRef.current?.contains(e.target)) {
@@ -5113,7 +6048,7 @@ var McpAppLine = ({ app, note, action, onAction, labels, className }) => {
5113
6048
  };
5114
6049
 
5115
6050
  // src/components/AgentComposer.tsx
5116
- import { Fragment as Fragment2, useEffect as useEffect9, useLayoutEffect as useLayoutEffect3, useMemo as useMemo6, useRef as useRef8, useState as useState9 } from "react";
6051
+ import { Fragment as Fragment2, useEffect as useEffect12, useLayoutEffect as useLayoutEffect3, useMemo as useMemo7, useRef as useRef10, useState as useState12 } from "react";
5117
6052
  import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
5118
6053
  var thinkingDefaults = (l) => [
5119
6054
  { id: "off", label: l.thinkingLevels.off },
@@ -5125,7 +6060,7 @@ var thinkingDefaults = (l) => [
5125
6060
  var MODES = ["autopilot", "ask-writes", "ask-all", "read-only"];
5126
6061
  var ModeIcon = ({ mode }) => mode === "autopilot" ? /* @__PURE__ */ jsx5(BoltIcon, { size: 14 }) : mode === "read-only" ? /* @__PURE__ */ jsx5(EyeIcon, { size: 14 }) : /* @__PURE__ */ jsx5(ShieldIcon, { size: 14 });
5127
6062
  var useMenuKeys = (open, menuRef, chipRef, close) => {
5128
- useEffect9(() => {
6063
+ useEffect12(() => {
5129
6064
  if (!open) return;
5130
6065
  const menu = menuRef.current;
5131
6066
  const rows = menu ? [...menu.querySelectorAll('[role^="menuitem"]')] : [];
@@ -5153,9 +6088,9 @@ var useMenuKeys = (open, menuRef, chipRef, close) => {
5153
6088
  };
5154
6089
  var opensMenu = (key) => key === "ArrowDown" || key === "ArrowUp";
5155
6090
  var attachSeq = 0;
5156
- var useIsoLayoutEffect3 = typeof window === "undefined" ? useEffect9 : useLayoutEffect3;
6091
+ var useIsoLayoutEffect3 = typeof window === "undefined" ? useEffect12 : useLayoutEffect3;
5157
6092
  var useMenuPlacement = (open, anchor, align) => {
5158
- const [style, setStyle] = useState9();
6093
+ const [style, setStyle] = useState12();
5159
6094
  useIsoLayoutEffect3(() => {
5160
6095
  if (!open) return;
5161
6096
  const place = () => {
@@ -5216,6 +6151,7 @@ var AgentComposer = ({
5216
6151
  files: vfs,
5217
6152
  dropZone = "self",
5218
6153
  speech = true,
6154
+ voiceMessage = false,
5219
6155
  showTimer = true,
5220
6156
  showAgents = true,
5221
6157
  showApprovalMode = true,
@@ -5233,41 +6169,52 @@ var AgentComposer = ({
5233
6169
  const L = useLabels(labelsOverride);
5234
6170
  const MODE_CHIP = L.modes;
5235
6171
  const DEFAULT_THINKING = thinkingDefaults(L);
5236
- const [text, setText] = useState9("");
5237
- const [pending, setPendingState] = useState9([]);
5238
- const pendingRef = useRef8([]);
6172
+ const [text, setText] = useState12("");
6173
+ const [pending, setPendingState] = useState12([]);
6174
+ const pendingRef = useRef10([]);
5239
6175
  const setPending = (next) => {
5240
6176
  pendingRef.current = typeof next === "function" ? next(pendingRef.current) : next;
5241
6177
  setPendingState(pendingRef.current);
5242
6178
  };
5243
- const [menu, setMenu] = useState9(void 0);
5244
- const [active, setActive] = useState9(0);
5245
- const [dismissed, setDismissed] = useState9(() => /* @__PURE__ */ new Set());
5246
- const [attachError, setAttachError] = useState9();
5247
- const [dragging, setDragging] = useState9(false);
5248
- const rootRef = useRef8(null);
5249
- const modelRef = useRef8(null);
5250
- const modeRef = useRef8(null);
5251
- const modelChipRef = useRef8(null);
5252
- const modeChipRef = useRef8(null);
5253
- const modelMenuRef = useRef8(null);
5254
- const modeMenuRef = useRef8(null);
5255
- const [dropRect, setDropRect] = useState9();
5256
- const [compactBar, setCompactBar] = useState9(false);
5257
- useEffect9(() => {
6179
+ const [menu, setMenu] = useState12(void 0);
6180
+ const [active, setActive] = useState12(0);
6181
+ const [dismissed, setDismissed] = useState12(() => /* @__PURE__ */ new Set());
6182
+ const [attachError, setAttachError] = useState12();
6183
+ const [dragging, setDragging] = useState12(false);
6184
+ const rootRef = useRef10(null);
6185
+ const modelRef = useRef10(null);
6186
+ const modeRef = useRef10(null);
6187
+ const modelChipRef = useRef10(null);
6188
+ const modeChipRef = useRef10(null);
6189
+ const modelMenuRef = useRef10(null);
6190
+ const modeMenuRef = useRef10(null);
6191
+ const [dropRect, setDropRect] = useState12();
6192
+ const [compactBar, setCompactBar] = useState12(false);
6193
+ const [barWidth, setBarWidth] = useState12(0);
6194
+ useEffect12(() => {
5258
6195
  const el = rootRef.current;
5259
6196
  if (!el || typeof ResizeObserver === "undefined") return;
5260
- const ro = new ResizeObserver(
5261
- () => setCompactBar(el.getBoundingClientRect().width < compactWidth)
5262
- );
6197
+ const ro = new ResizeObserver(() => {
6198
+ const width = el.getBoundingClientRect().width;
6199
+ setCompactBar(width < compactWidth);
6200
+ setBarWidth(Math.round(width));
6201
+ });
5263
6202
  ro.observe(el);
5264
6203
  return () => ro.disconnect();
5265
6204
  }, [compactWidth]);
5266
- const fileRef = useRef8(null);
5267
- const inputRef = useRef8(null);
6205
+ const chipLabelRef = useRef10(null);
6206
+ const [chipShort, setChipShort] = useState12(false);
6207
+ useLayoutEffect3(() => setChipShort(false), [barWidth, model?.label, model?.shortLabel]);
6208
+ useLayoutEffect3(() => {
6209
+ const el = chipLabelRef.current;
6210
+ if (chipShort || !el || !model?.shortLabel) return;
6211
+ if (el.scrollWidth > el.clientWidth + 1) setChipShort(true);
6212
+ });
6213
+ const fileRef = useRef10(null);
6214
+ const inputRef = useRef10(null);
5268
6215
  const draftId = draft?.id;
5269
6216
  const draftText = draft?.text;
5270
- useEffect9(() => {
6217
+ useEffect12(() => {
5271
6218
  if (draftId === void 0 || !draftText) return;
5272
6219
  setText((t) => t.trim() ? `${t.trimEnd()}
5273
6220
  ${draftText}` : draftText);
@@ -5281,13 +6228,20 @@ ${draftText}` : draftText);
5281
6228
  const caps = agent.agent?.capabilities;
5282
6229
  const stt = useSpeechToText({
5283
6230
  lang: typeof speech === "object" ? speech.lang : void 0,
6231
+ createRecognizer: typeof speech === "object" ? speech.createRecognizer : void 0,
5284
6232
  onFinal: (heard) => setText((t) => t.trim() ? `${t.trimEnd()} ${heard}` : heard)
5285
6233
  });
5286
6234
  const showMic = speech !== false && stt.supported;
5287
- const [startedAt, setStartedAt] = useState9();
5288
- const [now, setNow] = useState9(() => Date.now());
5289
- const [lastElapsed, setLastElapsed] = useState9();
5290
- useEffect9(() => {
6235
+ const recorder = useAudioRecorder({
6236
+ maxMs: typeof voiceMessage === "object" ? voiceMessage.maxMs : void 0
6237
+ });
6238
+ const showVoice = voiceMessage !== false && attachments !== false && recorder.supported;
6239
+ const recordingOn = recorder.state !== "idle";
6240
+ const [voiceNote, setVoiceNote] = useState12();
6241
+ const [startedAt, setStartedAt] = useState12();
6242
+ const [now, setNow] = useState12(() => Date.now());
6243
+ const [lastElapsed, setLastElapsed] = useState12();
6244
+ useEffect12(() => {
5291
6245
  if (!busy) {
5292
6246
  if (startedAt !== void 0) setLastElapsed(Date.now() - startedAt);
5293
6247
  setStartedAt(void 0);
@@ -5300,7 +6254,7 @@ ${draftText}` : draftText);
5300
6254
  return () => clearInterval(id);
5301
6255
  }, [busy]);
5302
6256
  const elapsed = startedAt !== void 0 ? now - startedAt : lastElapsed;
5303
- const allCommands = useMemo6(() => {
6257
+ const allCommands = useMemo7(() => {
5304
6258
  const out = [];
5305
6259
  if (builtinCommands) {
5306
6260
  out.push(
@@ -5383,8 +6337,8 @@ ${draftText}` : draftText);
5383
6337
  const closeMenu = () => setMenu(void 0);
5384
6338
  const modelMenuKeys = useMenuKeys(menu === "model", modelMenuRef, modelChipRef, closeMenu);
5385
6339
  const modeMenuKeys = useMenuKeys(menu === "mode", modeMenuRef, modeChipRef, closeMenu);
5386
- useEffect9(() => setActive(0), [text, menu]);
5387
- useEffect9(() => {
6340
+ useEffect12(() => setActive(0), [text, menu]);
6341
+ useEffect12(() => {
5388
6342
  if (!menu) return;
5389
6343
  const onDown = (e) => {
5390
6344
  if (!rootRef.current?.contains(e.target)) setMenu(void 0);
@@ -5511,6 +6465,44 @@ ${draftText}` : draftText);
5511
6465
  setAttachError(said.filter(Boolean).join(" ") || void 0);
5512
6466
  if (fileRef.current) fileRef.current.value = "";
5513
6467
  };
6468
+ const addRecording = async (audio) => {
6469
+ if (audio.blob.size === 0) return;
6470
+ const name = voiceMessageName(/* @__PURE__ */ new Date(), audioExtensionOf(audio.mediaType));
6471
+ const over = attachmentOverLimit({ bytes: audio.blob.size }, "sent", "none", bounds);
6472
+ if (over) {
6473
+ setAttachError(overLimitText(L.voiceMessage, over));
6474
+ return;
6475
+ }
6476
+ const a = {
6477
+ id: `att-${attachSeq += 1}`,
6478
+ name,
6479
+ kind: "file",
6480
+ mediaType: audio.mediaType,
6481
+ dataUrl: await readDataUrl2(audio.blob),
6482
+ bytes: audio.blob.size,
6483
+ durationMs: audio.durationMs,
6484
+ note: L.audioDuration(formatClock(audio.durationMs))
6485
+ };
6486
+ if (messageOverLimit(pendingRef.current, a, bounds) === "bytes") {
6487
+ setAttachError(
6488
+ L.messageTooLarge(L.voiceMessage, Math.round(bounds.maxTotalBytes / 1024 / 1024))
6489
+ );
6490
+ return;
6491
+ }
6492
+ setPending((cur) => [...cur, a]);
6493
+ };
6494
+ const finishRecording = async () => {
6495
+ const audio = await recorder.stop();
6496
+ if (audio) await addRecording(audio);
6497
+ inputRef.current?.focus();
6498
+ };
6499
+ const limited = recorder.limited;
6500
+ useEffect12(() => {
6501
+ if (!limited) return;
6502
+ recorder.clear();
6503
+ setVoiceNote(L.recordingLimit);
6504
+ void addRecording(limited);
6505
+ }, [limited]);
5514
6506
  const onPaste = (e) => {
5515
6507
  if (attachments === false) return;
5516
6508
  const pasted = Array.from(e.clipboardData?.files ?? []);
@@ -5518,9 +6510,9 @@ ${draftText}` : draftText);
5518
6510
  e.preventDefault();
5519
6511
  void addFiles(pasted);
5520
6512
  };
5521
- const addFilesRef = useRef8(addFiles);
6513
+ const addFilesRef = useRef10(addFiles);
5522
6514
  addFilesRef.current = addFiles;
5523
- useEffect9(() => {
6515
+ useEffect12(() => {
5524
6516
  if (attachments === false) return;
5525
6517
  const target = dropZone === "window" ? globalThis.window : dropZone === "self" ? rootRef.current : dropZone.current;
5526
6518
  if (!target) return;
@@ -5642,10 +6634,11 @@ ${draftText}` : draftText);
5642
6634
  mediaType: a.mediaType,
5643
6635
  size: a.bytes,
5644
6636
  ...a.kind === "image" && a.dataUrl ? { dataUrl: a.dataUrl } : {},
5645
- ...a.path ? { path: a.path } : {}
6637
+ ...a.path ? { path: a.path } : {},
6638
+ ...a.durationMs !== void 0 ? { durationMs: a.durationMs } : {}
5646
6639
  }));
5647
6640
  const full = withAttachments(goal || L.seeAttachments, items);
5648
- const label = shown || (items.length ? L.attachmentsOnly : "");
6641
+ const label = shown;
5649
6642
  void agent.run(full, {
5650
6643
  ...full !== label ? { label } : {},
5651
6644
  images: items.filter((a) => a.kind === "image" && a.dataUrl).map(toModel),
@@ -5686,23 +6679,31 @@ ${draftText}` : draftText);
5686
6679
  ...attachError ? [{ id: `attach:${attachError}`, tone: "warn", text: attachError }] : [],
5687
6680
  ...stt.error ? [
5688
6681
  {
5689
- id: `stt:${stt.error}`,
6682
+ id: `stt:${stt.error}:${stt.errorMessage ?? ""}`,
6683
+ tone: "warn",
6684
+ text: micProblemText(stt.error, stt.errorMessage, L)
6685
+ }
6686
+ ] : [],
6687
+ ...recorder.error ? [
6688
+ {
6689
+ id: `rec:${recorder.error}`,
5690
6690
  tone: "warn",
5691
- text: `${L.microphone}: ${stt.error}`
6691
+ text: micProblemText(recorder.error, void 0, L)
5692
6692
  }
5693
- ] : []
6693
+ ] : [],
6694
+ ...voiceNote ? [{ id: `voice:${voiceNote}`, tone: "info", text: voiceNote }] : []
5694
6695
  ].filter((n) => !dismissed.has(n.id)) : [];
5695
6696
  const runningAgents = agent.subagents.filter((s) => s.status === "running");
5696
6697
  const thinkingOptions = thinking?.options ?? DEFAULT_THINKING;
5697
6698
  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);
6699
+ const canSend = ready && !recordingOn && (text.trim().length > 0 || pending.length > 0);
5699
6700
  const canSteer = busy && steering && text.trim().length > 0;
5700
6701
  const queuedStrip = showQueued && (agent.queued.length > 0 || agent.undelivered.length > 0) ? /* @__PURE__ */ jsxs3("div", { className: "awr-queued", children: [
5701
6702
  agent.queued.map((q) => /* @__PURE__ */ jsxs3("div", { className: "awr-queued__item", role: "status", children: [
5702
6703
  /* @__PURE__ */ jsx5(ClockIcon, { size: 13, className: "awr-queued__icon" }),
5703
6704
  /* @__PURE__ */ jsx5("span", { className: "awr-queued__text", title: q.text, children: q.text }),
5704
6705
  q.origin === "another-tab" && /* @__PURE__ */ jsx5("span", { className: "awr-queued__origin", children: L.fromAnotherTab }),
5705
- /* @__PURE__ */ jsx5("span", { className: "awr-queued__state", children: q.session ? L.queuedForSession(q.session) : L.queuedWaiting })
6706
+ /* @__PURE__ */ jsx5("span", { className: "awr-queued__state", children: q.sentTo ? L.queuedForOtherTab : q.session ? L.queuedForSession(q.session) : L.queuedWaiting })
5706
6707
  ] }, q.id)),
5707
6708
  agent.undelivered.length > 0 && /* @__PURE__ */ jsxs3("div", { className: "awr-queued__item awr-queued__item--undelivered", role: "status", children: [
5708
6709
  /* @__PURE__ */ jsx5(AlertIcon, { size: 13, className: "awr-queued__icon" }),
@@ -5739,6 +6740,8 @@ ${draftText}` : draftText);
5739
6740
  onClick: () => {
5740
6741
  setDismissed((d) => new Set(d).add(n.id));
5741
6742
  if (n.id.startsWith("attach:")) setAttachError(void 0);
6743
+ if (n.id.startsWith("rec:")) recorder.clear();
6744
+ if (n.id.startsWith("voice:")) setVoiceNote(void 0);
5742
6745
  },
5743
6746
  children: /* @__PURE__ */ jsx5(XIcon, { size: 14 })
5744
6747
  }
@@ -5776,7 +6779,7 @@ ${draftText}` : draftText);
5776
6779
  const remove = () => setPending((cur) => cur.filter((x) => x.id !== a.id));
5777
6780
  if (renderAttachment) return /* @__PURE__ */ jsx5("span", { children: renderAttachment(a, remove) }, a.id);
5778
6781
  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 }),
6782
+ 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
6783
  a.note ? /* @__PURE__ */ jsxs3("span", { className: "awr-file__text", children: [
5781
6784
  /* @__PURE__ */ jsx5("span", { className: "awr-file__name", children: a.name }),
5782
6785
  /* @__PURE__ */ jsx5("span", { className: "awr-file__note", children: a.note })
@@ -5793,6 +6796,33 @@ ${draftText}` : draftText);
5793
6796
  )
5794
6797
  ] }, a.id);
5795
6798
  }) }),
6799
+ showVoice && recordingOn && /* @__PURE__ */ jsxs3("div", { className: "awr-recording", role: "status", "aria-live": "polite", children: [
6800
+ /* @__PURE__ */ jsx5("span", { className: "awr-recording__dot", "aria-hidden": "true" }),
6801
+ /* @__PURE__ */ jsx5("span", { className: "awr-recording__time", children: L.recording(formatClock(recorder.elapsedMs)) }),
6802
+ /* @__PURE__ */ jsx5(
6803
+ "button",
6804
+ {
6805
+ type: "button",
6806
+ className: "awr-iconbtn",
6807
+ "aria-label": L.recordingCancel,
6808
+ title: L.recordingCancel,
6809
+ onClick: recorder.cancel,
6810
+ children: /* @__PURE__ */ jsx5(XIcon, { size: 16 })
6811
+ }
6812
+ ),
6813
+ /* @__PURE__ */ jsx5(
6814
+ "button",
6815
+ {
6816
+ type: "button",
6817
+ className: "awr-iconbtn awr-recording__done",
6818
+ "aria-label": L.recordingDone,
6819
+ title: L.recordingDone,
6820
+ onClick: () => void finishRecording(),
6821
+ disabled: recorder.state !== "recording",
6822
+ children: /* @__PURE__ */ jsx5(CheckIcon, { size: 16 })
6823
+ }
6824
+ )
6825
+ ] }),
5796
6826
  /* @__PURE__ */ jsxs3("div", { className: "awr-composer2__inputrow", children: [
5797
6827
  /* @__PURE__ */ jsx5(
5798
6828
  "textarea",
@@ -5803,7 +6833,7 @@ ${draftText}` : draftText);
5803
6833
  onChange: (e) => setText(e.target.value),
5804
6834
  onKeyDown,
5805
6835
  onPaste,
5806
- placeholder: stt.listening ? L.listening : busy && steering ? L.placeholderBusy : placeholder ?? L.placeholder,
6836
+ placeholder: stt.finishing ? L.transcribing : stt.listening ? L.listening : busy && steering ? L.placeholderBusy : placeholder ?? L.placeholder,
5807
6837
  disabled,
5808
6838
  rows: 2,
5809
6839
  "aria-label": L.message
@@ -5813,16 +6843,18 @@ ${draftText}` : draftText);
5813
6843
  "button",
5814
6844
  {
5815
6845
  type: "button",
5816
- className: `awr-iconbtn awr-mic${stt.listening ? " is-on" : ""}`,
6846
+ className: `awr-iconbtn awr-mic${stt.listening ? " is-on" : ""}${stt.finishing ? " is-busy" : ""}`,
5817
6847
  "aria-label": stt.listening ? L.stopDictation : L.dictate,
6848
+ "aria-pressed": stt.listening,
5818
6849
  title: stt.listening ? L.stopDictation : L.dictateTitle,
5819
6850
  onClick: stt.toggle,
5820
- disabled,
5821
- children: /* @__PURE__ */ jsx5(MicIcon, { size: 18 })
6851
+ disabled: disabled || recordingOn || stt.finishing,
6852
+ children: stt.finishing ? /* @__PURE__ */ jsx5(SpinnerIcon, { size: 18 }) : /* @__PURE__ */ jsx5(MicIcon, { size: 18 })
5822
6853
  }
5823
6854
  )
5824
6855
  ] }),
5825
6856
  stt.listening && stt.interim && /* @__PURE__ */ jsx5("div", { className: "awr-composer2__interim", children: stt.interim }),
6857
+ stt.finishing && /* @__PURE__ */ jsx5("div", { className: "awr-composer2__interim", role: "status", children: L.transcribing }),
5826
6858
  /* @__PURE__ */ jsxs3("div", { className: "awr-toolbar", children: [
5827
6859
  attachments !== false && /* @__PURE__ */ jsxs3(Fragment3, { children: [
5828
6860
  /* @__PURE__ */ jsx5(
@@ -5837,6 +6869,22 @@ ${draftText}` : draftText);
5837
6869
  children: /* @__PURE__ */ jsx5(PlusIcon, { size: 18 })
5838
6870
  }
5839
6871
  ),
6872
+ showVoice && /* @__PURE__ */ jsx5(
6873
+ "button",
6874
+ {
6875
+ type: "button",
6876
+ className: `awr-iconbtn awr-voicebtn${recordingOn ? " is-on" : ""}`,
6877
+ "aria-label": L.recordVoiceMessage,
6878
+ title: L.recordVoiceMessage,
6879
+ "aria-pressed": recordingOn,
6880
+ onClick: () => {
6881
+ setVoiceNote(void 0);
6882
+ void recorder.start();
6883
+ },
6884
+ disabled: disabled || recordingOn || stt.listening,
6885
+ children: /* @__PURE__ */ jsx5(WaveIcon, { size: 18 })
6886
+ }
6887
+ ),
5840
6888
  /* @__PURE__ */ jsx5(
5841
6889
  "input",
5842
6890
  {
@@ -5861,7 +6909,7 @@ ${draftText}` : draftText);
5861
6909
  }
5862
6910
  ),
5863
6911
  toolbarExtra,
5864
- showTimer && elapsed !== void 0 && /* @__PURE__ */ jsxs3("span", { className: "awr-tchip", title: busy ? L.timerRunning : L.timerLast, children: [
6912
+ showTimer && elapsed !== void 0 && (busy || !compactBar) && /* @__PURE__ */ jsxs3("span", { className: "awr-tchip", title: busy ? L.timerRunning : L.timerLast, children: [
5865
6913
  /* @__PURE__ */ jsx5(ClockIcon, { size: 14 }),
5866
6914
  " ",
5867
6915
  formatElapsed(elapsed)
@@ -5897,7 +6945,7 @@ ${draftText}` : draftText);
5897
6945
  "aria-expanded": menu === "model",
5898
6946
  title: [model?.label, thinkingLabel].filter(Boolean).join(" \xB7 "),
5899
6947
  children: [
5900
- /* @__PURE__ */ jsx5("span", { className: "awr-tchip__label", children: model?.label ?? L.model }),
6948
+ /* @__PURE__ */ jsx5("span", { className: "awr-tchip__label", ref: chipLabelRef, children: chipShort && model?.shortLabel || model?.label || L.model }),
5901
6949
  thinkingLabel && !compactBar && /* @__PURE__ */ jsx5("span", { className: "awr-tchip__sub", children: thinkingLabel })
5902
6950
  ]
5903
6951
  }
@@ -6220,7 +7268,7 @@ var ContextMeter = ({
6220
7268
  };
6221
7269
 
6222
7270
  // src/components/ElicitationPrompt.tsx
6223
- import { useEffect as useEffect10, useId, useState as useState10 } from "react";
7271
+ import { useEffect as useEffect13, useId, useState as useState13 } from "react";
6224
7272
  import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
6225
7273
  var reasonText = (outcome, L) => {
6226
7274
  const reason = outcome.reason;
@@ -6230,8 +7278,8 @@ var reasonText = (outcome, L) => {
6230
7278
  return reason || outcome.status;
6231
7279
  };
6232
7280
  var useNow = (active) => {
6233
- const [now, setNow] = useState10(() => Date.now());
6234
- useEffect10(() => {
7281
+ const [now, setNow] = useState13(() => Date.now());
7282
+ useEffect13(() => {
6235
7283
  if (!active) return;
6236
7284
  setNow(Date.now());
6237
7285
  const timer = setInterval(() => setNow(Date.now()), 1e3);
@@ -6362,8 +7410,8 @@ var FormBody = ({ elicitation, answer, L }) => {
6362
7410
  const baseId = useId();
6363
7411
  const schema = elicitation.requestedSchema;
6364
7412
  const fields = elicitationFields(schema);
6365
- const [draft, setDraft] = useState10(() => elicitationInitialDraft(schema));
6366
- const [issues, setIssues] = useState10(void 0);
7413
+ const [draft, setDraft] = useState13(() => elicitationInitialDraft(schema));
7414
+ const [issues, setIssues] = useState13(void 0);
6367
7415
  const fieldId = (i) => `${baseId}-f${i}`;
6368
7416
  const submit = (e) => {
6369
7417
  e.preventDefault();
@@ -6418,7 +7466,7 @@ var FormBody = ({ elicitation, answer, L }) => {
6418
7466
  };
6419
7467
  var UrlBody = ({ elicitation, answer, L }) => {
6420
7468
  const link = elicitationLink(elicitation.url);
6421
- const [opened, setOpened] = useState10(false);
7469
+ const [opened, setOpened] = useState13(false);
6422
7470
  const open = () => {
6423
7471
  if (!link.openable || typeof window === "undefined") return;
6424
7472
  window.open(link.href, "_blank", "noopener,noreferrer");
@@ -6482,7 +7530,7 @@ var ElicitationPrompt = ({
6482
7530
  className
6483
7531
  }) => {
6484
7532
  const L = useLabels(labels);
6485
- const [dismissed, setDismissed] = useState10(() => /* @__PURE__ */ new Set());
7533
+ const [dismissed, setDismissed] = useState13(() => /* @__PURE__ */ new Set());
6486
7534
  const automatic = showOutcomes ? (outcomes ?? []).filter(
6487
7535
  (o) => o.automatic === true && o.status !== "pending" && !dismissed.has(o.id)
6488
7536
  ) : [];
@@ -6543,21 +7591,21 @@ var ElicitationPrompt = ({
6543
7591
  };
6544
7592
 
6545
7593
  // src/components/FilesPanel.tsx
6546
- import { Fragment as Fragment6, useEffect as useEffect12, useRef as useRef10, useState as useState12 } from "react";
7594
+ import { Fragment as Fragment6, useEffect as useEffect15, useRef as useRef12, useState as useState15 } from "react";
6547
7595
 
6548
7596
  // src/components/ImageViewer.tsx
6549
- import { createContext as createContext3, useContext as useContext3, useEffect as useEffect11, useRef as useRef9, useState as useState11 } from "react";
7597
+ import { createContext as createContext3, useContext as useContext3, useEffect as useEffect14, useRef as useRef11, useState as useState14 } from "react";
6550
7598
  import { createPortal } from "react-dom";
6551
7599
  import { Fragment as Fragment5, jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
6552
7600
  var fileNameOf = (name) => name.split(/[\\/]/).filter(Boolean).pop() ?? name;
6553
7601
  var SWIPE_PX = 48;
6554
7602
  var ImageViewer = ({ images, index, onIndex, onClose, labels }) => {
6555
7603
  const L = useLabels(labels);
6556
- const rootRef = useRef9(null);
6557
- const closeRef = useRef9(null);
6558
- const imgRef = useRef9(null);
6559
- const touch = useRef9(void 0);
6560
- const [zoom, setZoom] = useState11(void 0);
7604
+ const rootRef = useRef11(null);
7605
+ const closeRef = useRef11(null);
7606
+ const imgRef = useRef11(null);
7607
+ const touch = useRef11(void 0);
7608
+ const [zoom, setZoom] = useState14(void 0);
6561
7609
  const count = images.length;
6562
7610
  const at = Math.min(Math.max(index, 0), count - 1);
6563
7611
  const image = images[at];
@@ -6566,7 +7614,7 @@ var ImageViewer = ({ images, index, onIndex, onClose, labels }) => {
6566
7614
  setZoom(void 0);
6567
7615
  onIndex((at + step + count) % count);
6568
7616
  };
6569
- useEffect11(() => {
7617
+ useEffect14(() => {
6570
7618
  closeRef.current?.focus();
6571
7619
  const root = document.documentElement;
6572
7620
  const before = root.style.overflow;
@@ -6575,7 +7623,7 @@ var ImageViewer = ({ images, index, onIndex, onClose, labels }) => {
6575
7623
  root.style.overflow = before;
6576
7624
  };
6577
7625
  }, []);
6578
- const keys = useRef9(() => {
7626
+ const keys = useRef11(() => {
6579
7627
  });
6580
7628
  keys.current = (e) => {
6581
7629
  if (e.key === "Escape") {
@@ -6601,7 +7649,7 @@ var ImageViewer = ({ images, index, onIndex, onClose, labels }) => {
6601
7649
  }
6602
7650
  }
6603
7651
  };
6604
- useEffect11(() => {
7652
+ useEffect14(() => {
6605
7653
  const onKey = (e) => keys.current(e);
6606
7654
  document.addEventListener("keydown", onKey, true);
6607
7655
  return () => document.removeEventListener("keydown", onKey, true);
@@ -6745,8 +7793,8 @@ var ImageThumb = ({
6745
7793
  }) => {
6746
7794
  const L = useLabels(labels);
6747
7795
  const { enabled, render } = useContext3(ImageViewerContext);
6748
- const ref = useRef9(null);
6749
- const [open, setOpen] = useState11(void 0);
7796
+ const ref = useRef11(null);
7797
+ const [open, setOpen] = useState14(void 0);
6750
7798
  const img = /* @__PURE__ */ jsx9("img", { className: imgClassName, src, alt });
6751
7799
  if (!enabled) {
6752
7800
  return /* @__PURE__ */ jsx9("a", { className, href: src, target: "_blank", rel: "noopener noreferrer", title, children: img });
@@ -6808,9 +7856,9 @@ var FilesPanel = ({
6808
7856
  }) => {
6809
7857
  const L = useLabels(labels);
6810
7858
  const fs = useVirtualFiles(vfs, prefix);
6811
- const [preview, setPreview] = useState12();
6812
- const inputRef = useRef10(null);
6813
- useEffect12(() => {
7859
+ const [preview, setPreview] = useState15();
7860
+ const inputRef = useRef12(null);
7861
+ useEffect15(() => {
6814
7862
  if (preview && !fs.files.some((f) => f.path === preview.path)) setPreview(void 0);
6815
7863
  }, [fs.files, preview]);
6816
7864
  const open = async (f) => {
@@ -6931,7 +7979,7 @@ var FilesPanel = ({
6931
7979
  };
6932
7980
 
6933
7981
  // src/components/FileChips.tsx
6934
- import { Fragment as Fragment8, useEffect as useEffect14, useMemo as useMemo7, useState as useState14 } from "react";
7982
+ import { Fragment as Fragment8, useEffect as useEffect17, useMemo as useMemo8, useState as useState17 } from "react";
6935
7983
 
6936
7984
  // src/file-kinds.ts
6937
7985
  import { MEDIA_IMAGE_TYPES, isTextMime } from "@dudko.dev/agent-web";
@@ -6952,7 +8000,7 @@ var fileKindOf = (path, mediaType) => {
6952
8000
  var fileNameOf2 = (path) => path.split("/").filter(Boolean).pop() || "file";
6953
8001
 
6954
8002
  // src/components/Media.tsx
6955
- import { useEffect as useEffect13, useState as useState13 } from "react";
8003
+ import { useEffect as useEffect16, useState as useState16 } from "react";
6956
8004
  import { MEDIA_AUDIO_TYPES, MEDIA_IMAGE_TYPES as MEDIA_IMAGE_TYPES2 } from "@dudko.dev/agent-web";
6957
8005
  import { jsx as jsx11, jsxs as jsxs9 } from "react/jsx-runtime";
6958
8006
  var mediaFamilyOf = (mediaType) => {
@@ -6969,8 +8017,8 @@ var bytesOf = (content, encoding) => {
6969
8017
  return bytes;
6970
8018
  };
6971
8019
  var useFileUrl = (files, path, mediaType) => {
6972
- const [url, setUrl] = useState13(void 0);
6973
- useEffect13(() => {
8020
+ const [url, setUrl] = useState16(void 0);
8021
+ useEffect16(() => {
6974
8022
  if (!files || !mediaType) return;
6975
8023
  let made;
6976
8024
  let gone = false;
@@ -7154,7 +8202,7 @@ var SourceView = ({
7154
8202
  const L = useLabels(labels);
7155
8203
  const cut = text.length > maxChars;
7156
8204
  const shown = cut ? text.slice(0, maxChars) : text;
7157
- const lines = useMemo7(
8205
+ const lines = useMemo8(
7158
8206
  () => linesOf(html ? tokenizeHtml(shown) : [{ kind: "text", text: shown }]),
7159
8207
  [shown, html]
7160
8208
  );
@@ -7169,16 +8217,16 @@ var SourceView = ({
7169
8217
  ] });
7170
8218
  };
7171
8219
  var HtmlPreview = ({ written, file, htmlPreview, previewChars, L }) => {
7172
- const html = useMemo7(() => textOf(file), [file]);
8220
+ const html = useMemo8(() => textOf(file), [file]);
7173
8221
  const options = htmlPreview === false ? void 0 : htmlPreview;
7174
8222
  const tooLarge = html.length > HTML_PREVIEW_MAX_CHARS;
7175
8223
  const canFrame = Boolean(options) && !tooLarge;
7176
- const [view, setView] = useState14(canFrame ? "preview" : "source");
7177
- const [tall, setTall] = useState14(false);
8224
+ const [view, setView] = useState17(canFrame ? "preview" : "source");
8225
+ const [tall, setTall] = useState17(false);
7178
8226
  const showing = canFrame ? view : "source";
7179
8227
  const scripts = options?.scripts === true;
7180
8228
  const height = options?.height ?? 300;
7181
- const linked = useMemo7(() => showing === "preview" ? linkedFilesOf(html) : [], [html, showing]);
8229
+ const linked = useMemo8(() => showing === "preview" ? linkedFilesOf(html) : [], [html, showing]);
7182
8230
  return /* @__PURE__ */ jsx13(
7183
8231
  SandboxedFrame,
7184
8232
  {
@@ -7291,14 +8339,14 @@ var TextPreview = ({
7291
8339
  onClose,
7292
8340
  L
7293
8341
  }) => {
7294
- const text = useMemo7(() => textOf(file), [file]);
7295
- const rendered = useMemo7(
8342
+ const text = useMemo8(() => textOf(file), [file]);
8343
+ const rendered = useMemo8(
7296
8344
  () => renderFileContent?.(written, text.slice(0, previewChars)),
7297
8345
  [renderFileContent, written, text, previewChars]
7298
8346
  );
7299
8347
  const hasRendered = rendered !== void 0 && rendered !== null && rendered !== false;
7300
- const [view, setView] = useState14("rendered");
7301
- const [all, setAll] = useState14(false);
8348
+ const [view, setView] = useState17("rendered");
8349
+ const [all, setAll] = useState17(false);
7302
8350
  const showing = hasRendered ? view : "source";
7303
8351
  const long = text.length > 1200 || text.split("\n").length > 16;
7304
8352
  return /* @__PURE__ */ jsxs11("div", { className: "awr-fileview", children: [
@@ -7340,11 +8388,11 @@ var FileChips = ({
7340
8388
  }) => {
7341
8389
  const L = useLabels(labels);
7342
8390
  const live = useVirtualFiles(vfs);
7343
- const [openPath, setOpenPath] = useState14(defaultOpen);
7344
- const [file, setFile] = useState14();
8391
+ const [openPath, setOpenPath] = useState17(defaultOpen);
8392
+ const [file, setFile] = useState17();
7345
8393
  const open = written.find((f) => f.path === openPath);
7346
8394
  const stamp = live.files.find((f) => f.path === openPath)?.updatedAt;
7347
- useEffect14(() => {
8395
+ useEffect17(() => {
7348
8396
  if (!vfs || !openPath) return setFile(void 0);
7349
8397
  let gone = false;
7350
8398
  vfs.read(openPath).then((f) => {
@@ -7470,11 +8518,11 @@ var FileChip = ({
7470
8518
  import { Fragment as Fragment11 } from "react";
7471
8519
 
7472
8520
  // src/components/SubagentTree.tsx
7473
- import { Fragment as Fragment10, useEffect as useEffect15, useState as useState15 } from "react";
8521
+ import { Fragment as Fragment10, useEffect as useEffect18, useState as useState18 } from "react";
7474
8522
  import { jsx as jsx14, jsxs as jsxs12 } from "react/jsx-runtime";
7475
8523
  var useElapsed = (startedAt, running) => {
7476
- const [now, setNow] = useState15(void 0);
7477
- useEffect15(() => {
8524
+ const [now, setNow] = useState18(void 0);
8525
+ useEffect18(() => {
7478
8526
  if (!running || startedAt === void 0) return;
7479
8527
  setNow(Date.now());
7480
8528
  const timer = setInterval(() => setNow(Date.now()), 1e3);
@@ -7839,7 +8887,7 @@ var StepList = ({
7839
8887
  };
7840
8888
 
7841
8889
  // src/components/MessageList.tsx
7842
- import { jsx as jsx16, jsxs as jsxs14 } from "react/jsx-runtime";
8890
+ import { Fragment as Fragment12, jsx as jsx16, jsxs as jsxs14 } from "react/jsx-runtime";
7843
8891
  var usageLine = (usage, durationMs) => {
7844
8892
  const parts = [];
7845
8893
  if (usage && usage.totalTokens > 0) {
@@ -7850,7 +8898,54 @@ var usageLine = (usage, durationMs) => {
7850
8898
  if (durationMs !== void 0) parts.push(formatDuration(durationMs));
7851
8899
  return parts.join(" \xB7 ");
7852
8900
  };
7853
- var AttachmentView = ({ attachment: a }) => a.dataUrl && a.mediaType.startsWith("image/") ? /* @__PURE__ */ jsx16(
8901
+ var lengthOf = (ms) => typeof ms === "number" && Number.isFinite(ms) && ms >= 0 && ms < 864e5 ? ms : void 0;
8902
+ var settleAudioDuration = (el) => {
8903
+ if (el.duration !== Infinity) return;
8904
+ const back = () => {
8905
+ if (!Number.isFinite(el.duration)) return;
8906
+ el.removeEventListener("durationchange", back);
8907
+ el.removeEventListener("timeupdate", back);
8908
+ el.currentTime = 0;
8909
+ };
8910
+ el.addEventListener("durationchange", back);
8911
+ el.addEventListener("timeupdate", back);
8912
+ el.currentTime = Number.MAX_SAFE_INTEGER;
8913
+ };
8914
+ var AttachedAudio = ({
8915
+ attachment: a,
8916
+ files,
8917
+ labels
8918
+ }) => {
8919
+ const L = useLabels(labels);
8920
+ const type = a.mediaType.toLowerCase().split(";")[0].trim();
8921
+ const url = useFileUrl(files, a.path ?? "", files && a.path ? type : void 0);
8922
+ const length = lengthOf(a.durationMs);
8923
+ const said = length !== void 0 ? L.audioDuration(formatClock(length)) : void 0;
8924
+ return url ? /* @__PURE__ */ jsxs14("span", { className: "awr-media awr-media--audio awr-msg__audio", title: a.path ?? a.name, children: [
8925
+ /* @__PURE__ */ jsx16(
8926
+ "audio",
8927
+ {
8928
+ className: "awr-media__audio",
8929
+ controls: true,
8930
+ preload: "metadata",
8931
+ src: url,
8932
+ "aria-label": said ? `${L.audioAttachment(a.name)} (${said})` : L.audioAttachment(a.name),
8933
+ onLoadedMetadata: (e) => settleAudioDuration(e.currentTarget)
8934
+ }
8935
+ ),
8936
+ said && /* @__PURE__ */ jsx16("span", { className: "awr-msg__audiolen", "aria-hidden": "true", children: said })
8937
+ ] }) : /* @__PURE__ */ jsxs14("span", { className: "awr-chip awr-file", title: a.path ?? a.mediaType, children: [
8938
+ /* @__PURE__ */ jsx16(WaveIcon, { size: 13 }),
8939
+ " ",
8940
+ a.name,
8941
+ said ? ` \xB7 ${said}` : ""
8942
+ ] });
8943
+ };
8944
+ var AttachmentView = ({
8945
+ attachment: a,
8946
+ files,
8947
+ labels
8948
+ }) => mediaFamilyOf(a.mediaType) === "audio" ? /* @__PURE__ */ jsx16(AttachedAudio, { attachment: a, files, labels }) : a.dataUrl && a.mediaType.startsWith("image/") ? /* @__PURE__ */ jsx16(
7854
8949
  ImageThumb,
7855
8950
  {
7856
8951
  src: a.dataUrl,
@@ -7864,6 +8959,12 @@ var AttachmentView = ({ attachment: a }) => a.dataUrl && a.mediaType.startsWith(
7864
8959
  " ",
7865
8960
  a.name
7866
8961
  ] });
8962
+ var toolCardsOf = (m, render) => (m.steps ?? []).flatMap(
8963
+ (step, s) => step.toolCalls.flatMap((call, c) => {
8964
+ const node = render(call, m);
8965
+ return node === null || node === void 0 || node === false ? [] : [{ key: `${s}:${c}`, node }];
8966
+ })
8967
+ );
7867
8968
  var toolCallCount = (m) => (m.steps ?? []).reduce((n, s) => n + s.toolCalls.length, 0);
7868
8969
  var activitySummary = (m, showToolCalls, showLearned, showTiers, showFileChips, L, showApps = false) => {
7869
8970
  const steps = m.steps ?? [];
@@ -7909,14 +9010,18 @@ var MessageList = ({
7909
9010
  renderMessage,
7910
9011
  renderAttachment,
7911
9012
  renderToolCall,
9013
+ renderToolCard,
9014
+ showToolCards = true,
7912
9015
  renderApp,
7913
9016
  showApps = true,
7914
9017
  imageViewer = true,
7915
9018
  renderImageViewer,
9019
+ readAloud,
7916
9020
  labels,
7917
9021
  className
7918
9022
  }) => {
7919
9023
  const L = useLabels(labels);
9024
+ const reader = useReadAloud(readAloud?.speak, readAloud?.lang);
7920
9025
  if (messages.length === 0) {
7921
9026
  return empty ? /* @__PURE__ */ jsx16("div", { className: "awr-messages__empty", children: empty }) : null;
7922
9027
  }
@@ -7924,6 +9029,7 @@ var MessageList = ({
7924
9029
  const steps = m.steps ?? [];
7925
9030
  const hasActivity = showActivity && (steps.length > 0 || (m.subagents?.length ?? 0) > 0 || m.pending && !!liveExtra);
7926
9031
  const usage = showUsage ? usageLine(m.usage, m.durationMs) : "";
9032
+ const cards = showToolCards && renderToolCard && m.role === "assistant" ? toolCardsOf(m, renderToolCard) : [];
7927
9033
  const node = /* @__PURE__ */ jsx16(
7928
9034
  "div",
7929
9035
  {
@@ -7990,12 +9096,22 @@ var MessageList = ({
7990
9096
  /* @__PURE__ */ jsx16("p", { className: "awr-thought__text", children: m.reasoning.trim() })
7991
9097
  ] })
7992
9098
  ] }),
9099
+ cards.length > 0 && /* @__PURE__ */ jsx16("div", { className: "awr-msg__cards", children: cards.map((card) => /* @__PURE__ */ jsx16("div", { className: "awr-msg__card", children: card.node }, card.key)) }),
7993
9100
  showApps && renderApp && m.role === "assistant" && m.apps?.length ? /* @__PURE__ */ jsx16("div", { className: "awr-msg__apps", children: m.apps.map((app) => /* @__PURE__ */ jsx16("div", { className: "awr-msg__app", children: renderApp(app, m) }, app.id)) }) : null,
7994
9101
  showMedia && m.transcripts?.length ? /* @__PURE__ */ jsx16("div", { className: "awr-msg__transcripts", children: m.transcripts.map((t, i) => /* @__PURE__ */ jsx16(TranscriptBlock, { transcript: t, labels }, i)) }) : null,
7995
9102
  (m.content || m.pending || !m.attachments?.length) && /* @__PURE__ */ jsxs14("div", { className: "awr-msg__bubble", children: [
7996
9103
  m.content ? renderContent ? renderContent(m) : m.content : m.stopped && !m.pending ? /* @__PURE__ */ jsx16("span", { className: "awr-msg__stopped", children: L.answerStopped }) : null,
7997
9104
  m.pending && !m.content && /* @__PURE__ */ jsx16(SpinnerIcon, { size: 14, className: "awr-msg__pending" })
7998
9105
  ] }),
9106
+ readAloud && m.role === "assistant" && m.content && !m.pending && !m.error && /* @__PURE__ */ jsx16(
9107
+ ReadAloudControl,
9108
+ {
9109
+ id: m.id,
9110
+ text: () => readAloud.textOf ? readAloud.textOf(m) : speakableText(m.content, { code: L.readAloudCode }),
9111
+ reader,
9112
+ labels: L
9113
+ }
9114
+ ),
7999
9115
  showMedia && m.media?.length ? /* @__PURE__ */ jsx16("div", { className: "awr-msg__media", children: m.media.map((item, i) => {
8000
9116
  const built = /* @__PURE__ */ jsx16(GeneratedMedia, { media: item, files, labels }, i);
8001
9117
  return renderMedia ? /* @__PURE__ */ jsx16("span", { className: "awr-msg__mediaitem", children: renderMedia(item, m, built) }, i) : built;
@@ -8012,7 +9128,15 @@ var MessageList = ({
8012
9128
  labels
8013
9129
  }
8014
9130
  ) : null,
8015
- m.attachments?.length ? /* @__PURE__ */ jsx16("div", { className: "awr-msg__attachments", "aria-label": L.attachments, children: m.attachments.map((a, i) => /* @__PURE__ */ jsx16("span", { className: "awr-msg__attachment", children: renderAttachment ? renderAttachment(a, m) : /* @__PURE__ */ jsx16(AttachmentView, { attachment: a }) }, i)) }) : null,
9131
+ m.attachments?.length ? /* @__PURE__ */ jsx16(
9132
+ "div",
9133
+ {
9134
+ className: "awr-msg__attachments",
9135
+ role: "group",
9136
+ "aria-label": m.content.trim() ? L.attachments : attachmentsText(m.attachments, { voiceMessage: L.voiceMessage }),
9137
+ 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))
9138
+ }
9139
+ ) : null,
8016
9140
  m.role === "assistant" && usage && !m.pending && /* @__PURE__ */ jsx16("div", { className: "awr-msg__usage", title: L.usageTitle, children: usage })
8017
9141
  ] })
8018
9142
  },
@@ -8021,6 +9145,78 @@ var MessageList = ({
8021
9145
  return renderMessage ? /* @__PURE__ */ jsx16("div", { children: renderMessage(m, node) }, m.id) : node;
8022
9146
  }) }) });
8023
9147
  };
9148
+ var ReadAloudControl = ({
9149
+ id,
9150
+ text,
9151
+ reader,
9152
+ labels: L
9153
+ }) => {
9154
+ const mine = reader.current === id;
9155
+ const failed = reader.failed?.id === id ? reader.failed : void 0;
9156
+ return /* @__PURE__ */ jsxs14("div", { className: "awr-readaloud", "data-state": mine ? reader.state : "idle", children: [
9157
+ !mine ? /* @__PURE__ */ jsxs14(
9158
+ "button",
9159
+ {
9160
+ type: "button",
9161
+ className: "awr-linkbtn awr-readaloud__btn",
9162
+ onClick: () => reader.start(id, text()),
9163
+ "aria-label": L.readAloud,
9164
+ children: [
9165
+ /* @__PURE__ */ jsx16(SpeakerIcon, { size: 14 }),
9166
+ " ",
9167
+ L.readAloud
9168
+ ]
9169
+ }
9170
+ ) : /* @__PURE__ */ jsxs14(Fragment12, { children: [
9171
+ reader.state === "loading" ? /* @__PURE__ */ jsxs14("span", { className: "awr-readaloud__status", role: "status", children: [
9172
+ /* @__PURE__ */ jsx16(SpinnerIcon, { size: 14 }),
9173
+ " ",
9174
+ L.readAloudLoading
9175
+ ] }) : reader.state === "paused" ? /* @__PURE__ */ jsxs14(
9176
+ "button",
9177
+ {
9178
+ type: "button",
9179
+ className: "awr-linkbtn awr-readaloud__btn",
9180
+ onClick: reader.resume,
9181
+ "aria-label": L.readAloudResume,
9182
+ children: [
9183
+ /* @__PURE__ */ jsx16(PlayIcon, { size: 14 }),
9184
+ " ",
9185
+ L.readAloudResume
9186
+ ]
9187
+ }
9188
+ ) : /* @__PURE__ */ jsxs14(
9189
+ "button",
9190
+ {
9191
+ type: "button",
9192
+ className: "awr-linkbtn awr-readaloud__btn",
9193
+ onClick: reader.pause,
9194
+ "aria-label": L.readAloudPause,
9195
+ children: [
9196
+ /* @__PURE__ */ jsx16(PauseIcon, { size: 14 }),
9197
+ " ",
9198
+ L.readAloudPause
9199
+ ]
9200
+ }
9201
+ ),
9202
+ /* @__PURE__ */ jsxs14(
9203
+ "button",
9204
+ {
9205
+ type: "button",
9206
+ className: "awr-linkbtn awr-readaloud__btn",
9207
+ onClick: reader.stop,
9208
+ "aria-label": L.readAloudStop,
9209
+ children: [
9210
+ /* @__PURE__ */ jsx16(StopIcon, { size: 14 }),
9211
+ " ",
9212
+ L.readAloudStop
9213
+ ]
9214
+ }
9215
+ )
9216
+ ] }),
9217
+ failed && /* @__PURE__ */ jsx16("span", { className: "awr-readaloud__error", role: "alert", children: failed.message ?? L.readAloudFailed })
9218
+ ] });
9219
+ };
8024
9220
 
8025
9221
  // src/components/ModelLoadBar.tsx
8026
9222
  import { jsx as jsx17, jsxs as jsxs15 } from "react/jsx-runtime";
@@ -8039,11 +9235,11 @@ var ModelLoadBar = ({ load, className }) => {
8039
9235
  };
8040
9236
 
8041
9237
  // src/components/QuestionPrompt.tsx
8042
- import { useEffect as useEffect16, useId as useId2, useRef as useRef11, useState as useState16 } from "react";
9238
+ import { useEffect as useEffect19, useId as useId2, useRef as useRef13, useState as useState19 } from "react";
8043
9239
  import { jsx as jsx18, jsxs as jsxs16 } from "react/jsx-runtime";
8044
9240
  var useNow2 = (active) => {
8045
- const [now, setNow] = useState16(() => Date.now());
8046
- useEffect16(() => {
9241
+ const [now, setNow] = useState19(() => Date.now());
9242
+ useEffect19(() => {
8047
9243
  if (!active) return;
8048
9244
  setNow(Date.now());
8049
9245
  const timer = setInterval(() => setNow(Date.now()), 1e3);
@@ -8075,12 +9271,12 @@ var QuestionCard = ({
8075
9271
  const baseId = useId2();
8076
9272
  const textId = `${baseId}-q`;
8077
9273
  const otherId = `${baseId}-other`;
8078
- const [picked, setPicked] = useState16([]);
8079
- const [otherOpen, setOtherOpen] = useState16(false);
8080
- const [otherText, setOtherText] = useState16("");
8081
- const otherField = useRef11(null);
8082
- const otherButton = useRef11(null);
8083
- useEffect16(() => {
9274
+ const [picked, setPicked] = useState19([]);
9275
+ const [otherOpen, setOtherOpen] = useState19(false);
9276
+ const [otherText, setOtherText] = useState19("");
9277
+ const otherField = useRef13(null);
9278
+ const otherButton = useRef13(null);
9279
+ useEffect19(() => {
8084
9280
  if (otherOpen) otherField.current?.focus();
8085
9281
  }, [otherOpen]);
8086
9282
  const helper = showHelper && q.subagent ? { ...q.subagent, ...view?.subagent } : void 0;
@@ -8248,7 +9444,7 @@ var QuestionPrompt = ({
8248
9444
  className
8249
9445
  }) => {
8250
9446
  const L = useLabels(labels);
8251
- const [dismissed, setDismissed] = useState16(() => /* @__PURE__ */ new Set());
9447
+ const [dismissed, setDismissed] = useState19(() => /* @__PURE__ */ new Set());
8252
9448
  const automatic = showOutcomes ? (outcomes ?? []).filter(
8253
9449
  (o) => o.automatic === true && o.status !== "pending" && o.status !== "stopped" && !dismissed.has(o.id)
8254
9450
  ) : [];
@@ -8502,13 +9698,13 @@ var UsageBadge = ({
8502
9698
  };
8503
9699
 
8504
9700
  // src/components/AgentChat.tsx
8505
- import { Fragment as Fragment12, jsx as jsx20, jsxs as jsxs19 } from "react/jsx-runtime";
9701
+ import { Fragment as Fragment13, jsx as jsx20, jsxs as jsxs19 } from "react/jsx-runtime";
8506
9702
  var usePrefersDark = () => {
8507
9703
  const query = "(prefers-color-scheme: dark)";
8508
- const [dark, setDark] = useState17(
9704
+ const [dark, setDark] = useState20(
8509
9705
  () => typeof matchMedia === "function" && matchMedia(query).matches
8510
9706
  );
8511
- useEffect17(() => {
9707
+ useEffect20(() => {
8512
9708
  if (typeof matchMedia !== "function") return;
8513
9709
  const mq = matchMedia(query);
8514
9710
  const on = () => setDark(mq.matches);
@@ -8563,7 +9759,10 @@ var AgentChatInner = ({
8563
9759
  renderContent,
8564
9760
  renderMessage,
8565
9761
  renderAttachment,
9762
+ readAloud,
8566
9763
  renderToolCall,
9764
+ renderToolCard,
9765
+ showToolCards = true,
8567
9766
  renderSubagent,
8568
9767
  renderMedia,
8569
9768
  renderFile,
@@ -8598,17 +9797,19 @@ var AgentChatInner = ({
8598
9797
  }
8599
9798
  const L = useLabels();
8600
9799
  const external = isHistoryHook(history) ? history : void 0;
8601
- const [ownStore] = useState17(
9800
+ const [ownStore] = useState20(
8602
9801
  () => history instanceof ChatHistoryStore ? history : new ChatHistoryStore()
8603
9802
  );
8604
9803
  const own = useChatHistory(agent, {
8605
9804
  store: ownStore,
8606
- enabled: Boolean(history) && !external
9805
+ enabled: Boolean(history) && !external,
9806
+ // A chat begun by a voice message is titled in the chat's language.
9807
+ labels: { voiceMessage: L.voiceMessage }
8607
9808
  });
8608
9809
  const chats = history ? external ?? own : void 0;
8609
- const rootRef = useRef12(null);
8610
- const [narrow, setNarrow] = useState17(void 0);
8611
- useEffect17(() => {
9810
+ const rootRef = useRef14(null);
9811
+ const [narrow, setNarrow] = useState20(void 0);
9812
+ useEffect20(() => {
8612
9813
  const el = rootRef.current;
8613
9814
  if (!el || typeof ResizeObserver === "undefined") return setNarrow(false);
8614
9815
  const measure2 = () => setNarrow(el.getBoundingClientRect().width < narrowWidth);
@@ -8617,9 +9818,9 @@ var AgentChatInner = ({
8617
9818
  ro.observe(el);
8618
9819
  return () => ro.disconnect();
8619
9820
  }, [narrowWidth]);
8620
- const [historyChoice, setHistoryOpen] = useState17(defaultHistoryOpen);
9821
+ const [historyChoice, setHistoryOpen] = useState20(defaultHistoryOpen);
8621
9822
  const historyOpen = historyChoice ?? narrow === false;
8622
- const [filesOpen, setFilesOpen] = useState17(defaultFilesOpen);
9823
+ const [filesOpen, setFilesOpen] = useState20(defaultFilesOpen);
8623
9824
  const toggleHistory = () => {
8624
9825
  setHistoryOpen(!historyOpen);
8625
9826
  if (narrow && !historyOpen) setFilesOpen(false);
@@ -8637,7 +9838,7 @@ var AgentChatInner = ({
8637
9838
  setHistoryOpen(false);
8638
9839
  setFilesOpen(false);
8639
9840
  };
8640
- useEffect17(() => {
9841
+ useEffect20(() => {
8641
9842
  if (!overlayOpen) return;
8642
9843
  const onKey = (e) => {
8643
9844
  if (e.key !== "Escape" || e.defaultPrevented) return;
@@ -8647,7 +9848,7 @@ var AgentChatInner = ({
8647
9848
  document.addEventListener("keydown", onKey);
8648
9849
  return () => document.removeEventListener("keydown", onKey);
8649
9850
  }, [overlayOpen]);
8650
- const bodyRef = useRef12(null);
9851
+ const bodyRef = useRef14(null);
8651
9852
  const appHost = useMcpAppHost({
8652
9853
  connection: mcpApps,
8653
9854
  approve: agent.approveAppToolCall,
@@ -8659,7 +9860,7 @@ var AgentChatInner = ({
8659
9860
  });
8660
9861
  const prefersDark = usePrefersDark();
8661
9862
  const appTheme = theme === "auto" ? prefersDark ? "dark" : "light" : theme;
8662
- const [panelApp, setPanelAppState] = useState17();
9863
+ const [panelApp, setPanelAppState] = useState20();
8663
9864
  const setPanelApp = (app) => {
8664
9865
  setPanelAppState(app);
8665
9866
  onAppPanel?.(app);
@@ -8673,7 +9874,7 @@ var AgentChatInner = ({
8673
9874
  const panelAllowed = appPanel !== false && appPanel !== null;
8674
9875
  const panelTarget = typeof appPanel === "object" && appPanel ? appPanel : void 0;
8675
9876
  const asSheet = !panelTarget && (appPanel === "sheet" || Boolean(narrow));
8676
- useEffect17(() => {
9877
+ useEffect20(() => {
8677
9878
  if (panelApp && !agent.messages.some((m) => m.apps?.some((a) => a.id === panelApp.id))) {
8678
9879
  setPanelAppState(void 0);
8679
9880
  onAppPanel?.(void 0);
@@ -8713,7 +9914,7 @@ var AgentChatInner = ({
8713
9914
  },
8714
9915
  panelApp.id
8715
9916
  ) : null;
8716
- const [compacting, setCompacting] = useState17(false);
9917
+ const [compacting, setCompacting] = useState20(false);
8717
9918
  const compact = () => {
8718
9919
  setCompacting(true);
8719
9920
  void agent.compact().finally(() => setCompacting(false));
@@ -8735,7 +9936,7 @@ var AgentChatInner = ({
8735
9936
  const showReplan = agent.replan && agent.replan.mode !== "continue";
8736
9937
  const replanFailedEarly = showReplanFailed && agent.replan?.failed === true && agent.steps.length === 0;
8737
9938
  const earlyDecisions = showDecisions ? agent.decisions ?? [] : [];
8738
- const liveExtra = agent.planThought.trim() || showReplan || replanFailedEarly || earlyDecisions.length > 0 ? /* @__PURE__ */ jsxs19(Fragment12, { children: [
9939
+ const liveExtra = agent.planThought.trim() || showReplan || replanFailedEarly || earlyDecisions.length > 0 ? /* @__PURE__ */ jsxs19(Fragment13, { children: [
8739
9940
  agent.planThought.trim() && /* @__PURE__ */ jsxs19("details", { className: "awr-activity__plan", children: [
8740
9941
  /* @__PURE__ */ jsx20("summary", { children: L.planned }),
8741
9942
  /* @__PURE__ */ jsx20("p", { className: "awr-activity__thought", children: agent.planThought })
@@ -8871,7 +10072,10 @@ var AgentChatInner = ({
8871
10072
  renderContent,
8872
10073
  renderMessage,
8873
10074
  renderAttachment,
10075
+ readAloud,
8874
10076
  renderToolCall,
10077
+ renderToolCard,
10078
+ showToolCards,
8875
10079
  showApps: appsOn,
8876
10080
  renderApp: appsOn ? drawApp : void 0,
8877
10081
  imageViewer,
@@ -8962,7 +10166,7 @@ var AgentChatInner = ({
8962
10166
  ),
8963
10167
  panelTarget
8964
10168
  )
8965
- ) : asSheet ? /* @__PURE__ */ jsxs19(Fragment12, { children: [
10169
+ ) : asSheet ? /* @__PURE__ */ jsxs19(Fragment13, { children: [
8966
10170
  /* @__PURE__ */ jsx20("div", { className: "awr-sheet__scrim", onClick: () => setPanelApp(void 0) }),
8967
10171
  /* @__PURE__ */ jsxs19(
8968
10172
  "aside",
@@ -9045,9 +10249,59 @@ var LearnedSkills = ({
9045
10249
  ] });
9046
10250
  };
9047
10251
 
9048
- // src/components/Composer.tsx
9049
- import { useState as useState18 } from "react";
10252
+ // src/components/MemoryCard.tsx
10253
+ import { useState as useState21 } from "react";
9050
10254
  import { jsx as jsx22, jsxs as jsxs21 } from "react/jsx-runtime";
10255
+ var MemoryCard = ({
10256
+ kind,
10257
+ text,
10258
+ onUndo,
10259
+ undone = false,
10260
+ problem,
10261
+ labels,
10262
+ className
10263
+ }) => {
10264
+ const L = useLabels(labels);
10265
+ const [busy, setBusy] = useState21(false);
10266
+ const label = kind === "saved" ? L.memorySaved : kind === "updated" ? L.memoryUpdated : L.memoryForgotten;
10267
+ const undo = () => {
10268
+ if (!onUndo || busy) return;
10269
+ setBusy(true);
10270
+ void Promise.resolve().then(onUndo).catch(() => {
10271
+ }).finally(() => setBusy(false));
10272
+ };
10273
+ return /* @__PURE__ */ jsxs21(
10274
+ "div",
10275
+ {
10276
+ className: ["awr-memory", `awr-memory--${kind}`, undone ? "is-undone" : "", className].filter(Boolean).join(" "),
10277
+ "data-memory": kind,
10278
+ children: [
10279
+ /* @__PURE__ */ jsx22(BookmarkIcon, { size: 14, className: "awr-memory__icon" }),
10280
+ /* @__PURE__ */ jsxs21("div", { className: "awr-memory__body", children: [
10281
+ /* @__PURE__ */ jsx22("span", { className: "awr-memory__label", children: label }),
10282
+ /* @__PURE__ */ jsx22("span", { className: "awr-memory__text", children: text }),
10283
+ problem && /* @__PURE__ */ jsx22("span", { className: "awr-memory__problem", role: "alert", children: problem })
10284
+ ] }),
10285
+ undone ? /* @__PURE__ */ jsx22("span", { className: "awr-memory__undone", children: L.memoryUndone }) : onUndo ? /* @__PURE__ */ jsx22(
10286
+ "button",
10287
+ {
10288
+ type: "button",
10289
+ className: "awr-memory__undo",
10290
+ disabled: busy,
10291
+ "aria-busy": busy,
10292
+ "aria-label": `${L.memoryUndo}: ${text}`,
10293
+ onClick: undo,
10294
+ children: L.memoryUndo
10295
+ }
10296
+ ) : null
10297
+ ]
10298
+ }
10299
+ );
10300
+ };
10301
+
10302
+ // src/components/Composer.tsx
10303
+ import { useState as useState22 } from "react";
10304
+ import { jsx as jsx23, jsxs as jsxs22 } from "react/jsx-runtime";
9051
10305
  var Composer = ({
9052
10306
  onSubmit,
9053
10307
  busy = false,
@@ -9056,7 +10310,7 @@ var Composer = ({
9056
10310
  placeholder = "Ask the agent to do something\u2026",
9057
10311
  className
9058
10312
  }) => {
9059
- const [text, setText] = useState18("");
10313
+ const [text, setText] = useState22("");
9060
10314
  const submit = () => {
9061
10315
  const value = text.trim();
9062
10316
  if (!value || busy || disabled) return;
@@ -9069,7 +10323,7 @@ var Composer = ({
9069
10323
  submit();
9070
10324
  }
9071
10325
  };
9072
- return /* @__PURE__ */ jsxs21(
10326
+ return /* @__PURE__ */ jsxs22(
9073
10327
  "form",
9074
10328
  {
9075
10329
  className: ["awr-composer", className].filter(Boolean).join(" "),
@@ -9078,7 +10332,7 @@ var Composer = ({
9078
10332
  submit();
9079
10333
  },
9080
10334
  children: [
9081
- /* @__PURE__ */ jsx22(
10335
+ /* @__PURE__ */ jsx23(
9082
10336
  "textarea",
9083
10337
  {
9084
10338
  className: "awr-composer__input",
@@ -9090,23 +10344,23 @@ var Composer = ({
9090
10344
  rows: 1
9091
10345
  }
9092
10346
  ),
9093
- busy ? /* @__PURE__ */ jsx22(
10347
+ busy ? /* @__PURE__ */ jsx23(
9094
10348
  "button",
9095
10349
  {
9096
10350
  type: "button",
9097
10351
  className: "awr-composer__btn awr-composer__btn--stop",
9098
10352
  onClick: onStop,
9099
10353
  "aria-label": "Stop",
9100
- children: /* @__PURE__ */ jsx22(StopIcon, { size: 18 })
10354
+ children: /* @__PURE__ */ jsx23(StopIcon, { size: 18 })
9101
10355
  }
9102
- ) : /* @__PURE__ */ jsx22(
10356
+ ) : /* @__PURE__ */ jsx23(
9103
10357
  "button",
9104
10358
  {
9105
10359
  type: "submit",
9106
10360
  className: "awr-composer__btn",
9107
10361
  disabled: disabled || !text.trim(),
9108
10362
  "aria-label": "Send",
9109
- children: disabled ? /* @__PURE__ */ jsx22(SpinnerIcon, { size: 18 }) : /* @__PURE__ */ jsx22(SendIcon, { size: 18 })
10363
+ children: disabled ? /* @__PURE__ */ jsx23(SpinnerIcon, { size: 18 }) : /* @__PURE__ */ jsx23(SendIcon, { size: 18 })
9110
10364
  }
9111
10365
  )
9112
10366
  ]
@@ -9115,17 +10369,17 @@ var Composer = ({
9115
10369
  };
9116
10370
 
9117
10371
  // src/components/PlanView.tsx
9118
- import { jsx as jsx23, jsxs as jsxs22 } from "react/jsx-runtime";
10372
+ import { jsx as jsx24, jsxs as jsxs23 } from "react/jsx-runtime";
9119
10373
  var PlanView = ({ plan, showThought = true, className }) => {
9120
10374
  if (!plan.steps.length && !plan.thought) return null;
9121
- return /* @__PURE__ */ jsxs22("div", { className: ["awr-plan", className].filter(Boolean).join(" "), children: [
9122
- showThought && plan.thought.trim() && /* @__PURE__ */ jsx23("p", { className: "awr-plan__thought", children: plan.thought }),
9123
- plan.steps.length > 0 && /* @__PURE__ */ jsx23("ol", { className: "awr-plan__steps", children: plan.steps.map((step) => /* @__PURE__ */ jsx23("li", { className: "awr-plan__step", children: step.description }, step.id)) })
10375
+ return /* @__PURE__ */ jsxs23("div", { className: ["awr-plan", className].filter(Boolean).join(" "), children: [
10376
+ showThought && plan.thought.trim() && /* @__PURE__ */ jsx24("p", { className: "awr-plan__thought", children: plan.thought }),
10377
+ plan.steps.length > 0 && /* @__PURE__ */ jsx24("ol", { className: "awr-plan__steps", children: plan.steps.map((step) => /* @__PURE__ */ jsx24("li", { className: "awr-plan__step", children: step.description }, step.id)) })
9124
10378
  ] });
9125
10379
  };
9126
10380
 
9127
10381
  // src/components/ApprovalModeSwitch.tsx
9128
- import { jsx as jsx24 } from "react/jsx-runtime";
10382
+ import { jsx as jsx25 } from "react/jsx-runtime";
9129
10383
  var DEFAULT_LABELS = {
9130
10384
  autopilot: "Autopilot",
9131
10385
  "ask-writes": "Ask before changes",
@@ -9145,13 +10399,13 @@ var ApprovalModeSwitch = ({
9145
10399
  labels,
9146
10400
  disabled,
9147
10401
  className
9148
- }) => /* @__PURE__ */ jsx24(
10402
+ }) => /* @__PURE__ */ jsx25(
9149
10403
  "div",
9150
10404
  {
9151
10405
  className: ["awr-modeswitch", className].filter(Boolean).join(" "),
9152
10406
  role: "radiogroup",
9153
10407
  "aria-label": "Tool consent",
9154
- children: modes.map((m) => /* @__PURE__ */ jsx24(
10408
+ children: modes.map((m) => /* @__PURE__ */ jsx25(
9155
10409
  "button",
9156
10410
  {
9157
10411
  type: "button",
@@ -9169,8 +10423,8 @@ var ApprovalModeSwitch = ({
9169
10423
  );
9170
10424
 
9171
10425
  // src/components/ApiKeyForm.tsx
9172
- import { useEffect as useEffect18, useState as useState19 } from "react";
9173
- import { jsx as jsx25, jsxs as jsxs23 } from "react/jsx-runtime";
10426
+ import { useEffect as useEffect21, useState as useState23 } from "react";
10427
+ import { jsx as jsx26, jsxs as jsxs24 } from "react/jsx-runtime";
9174
10428
  var ApiKeyForm = ({
9175
10429
  credentials,
9176
10430
  credentialRef,
@@ -9179,10 +10433,10 @@ var ApiKeyForm = ({
9179
10433
  onChange,
9180
10434
  className
9181
10435
  }) => {
9182
- const [value, setValue] = useState19("");
9183
- const [present, setPresent] = useState19(false);
9184
- const [busy, setBusy] = useState19(false);
9185
- useEffect18(() => {
10436
+ const [value, setValue] = useState23("");
10437
+ const [present, setPresent] = useState23(false);
10438
+ const [busy, setBusy] = useState23(false);
10439
+ useEffect21(() => {
9186
10440
  let active = true;
9187
10441
  credentials.hasKey(credentialRef).then((has) => {
9188
10442
  if (active) setPresent(has);
@@ -9214,16 +10468,16 @@ var ApiKeyForm = ({
9214
10468
  setBusy(false);
9215
10469
  }
9216
10470
  };
9217
- return /* @__PURE__ */ jsxs23("div", { className: ["awr-keyform", className].filter(Boolean).join(" "), children: [
9218
- /* @__PURE__ */ jsxs23("label", { className: "awr-keyform__label", children: [
10471
+ return /* @__PURE__ */ jsxs24("div", { className: ["awr-keyform", className].filter(Boolean).join(" "), children: [
10472
+ /* @__PURE__ */ jsxs24("label", { className: "awr-keyform__label", children: [
9219
10473
  label,
9220
- present && /* @__PURE__ */ jsxs23("span", { className: "awr-keyform__saved", children: [
9221
- /* @__PURE__ */ jsx25(CheckIcon, { size: 12 }),
10474
+ present && /* @__PURE__ */ jsxs24("span", { className: "awr-keyform__saved", children: [
10475
+ /* @__PURE__ */ jsx26(CheckIcon, { size: 12 }),
9222
10476
  " stored, encrypted"
9223
10477
  ] })
9224
10478
  ] }),
9225
- /* @__PURE__ */ jsxs23("div", { className: "awr-keyform__row", children: [
9226
- /* @__PURE__ */ jsx25(
10479
+ /* @__PURE__ */ jsxs24("div", { className: "awr-keyform__row", children: [
10480
+ /* @__PURE__ */ jsx26(
9227
10481
  "input",
9228
10482
  {
9229
10483
  className: "awr-keyform__input",
@@ -9241,7 +10495,7 @@ var ApiKeyForm = ({
9241
10495
  disabled: busy
9242
10496
  }
9243
10497
  ),
9244
- /* @__PURE__ */ jsx25(
10498
+ /* @__PURE__ */ jsx26(
9245
10499
  "button",
9246
10500
  {
9247
10501
  type: "button",
@@ -9251,7 +10505,7 @@ var ApiKeyForm = ({
9251
10505
  children: "Save"
9252
10506
  }
9253
10507
  ),
9254
- present && /* @__PURE__ */ jsx25(
10508
+ present && /* @__PURE__ */ jsx26(
9255
10509
  "button",
9256
10510
  {
9257
10511
  type: "button",
@@ -9360,17 +10614,22 @@ export {
9360
10614
  McpAppLine,
9361
10615
  McpAppRpcError,
9362
10616
  McpAppSandboxLink,
10617
+ MemoryCard,
9363
10618
  MemoryCredentialStore,
9364
10619
  MemorySkillStore,
9365
10620
  MemoryStore,
9366
10621
  MessageList,
10622
+ MicError,
9367
10623
  ModelLoadBar,
9368
10624
  PlanView,
9369
10625
  QUESTION_TIMEOUT_MS,
9370
10626
  QuestionPrompt,
10627
+ RECORDING_DEFAULT_MAX_MS,
10628
+ RECORDING_TYPES,
9371
10629
  SandboxedFrame,
9372
10630
  SessionBusyError,
9373
10631
  SourceView,
10632
+ SpeechOutputError,
9374
10633
  StepList,
9375
10634
  SubagentRow,
9376
10635
  SubagentTree,
@@ -9400,6 +10659,9 @@ export {
9400
10659
  attachmentOverLimit,
9401
10660
  attachmentRefusal,
9402
10661
  attachmentTransformOf,
10662
+ attachmentsText,
10663
+ audioExtensionOf,
10664
+ audioTypeOf,
9403
10665
  buildMcpAppDocument,
9404
10666
  buildMcpAppSandboxShell,
9405
10667
  buildSandboxedDocument,
@@ -9408,9 +10670,12 @@ export {
9408
10670
  clampFrameHeight,
9409
10671
  createAgent2 as createAgent,
9410
10672
  createApprovalQueue,
10673
+ createAudioSpeaker,
10674
+ createBrowserSpeaker,
9411
10675
  createFileTools,
9412
10676
  createInitialAgentState,
9413
10677
  createQuestionQueue,
10678
+ createRecordingRecognizer,
9414
10679
  createRunControl2 as createRunControl,
9415
10680
  createSubagentTool,
9416
10681
  createWebLLMEngine,
@@ -9430,6 +10695,7 @@ export {
9430
10695
  filterCommands,
9431
10696
  followsAfterResize,
9432
10697
  followsAfterScroll,
10698
+ formatClock,
9433
10699
  formatCountdown,
9434
10700
  formatElapsed,
9435
10701
  grantedAppCsp,
@@ -9437,6 +10703,7 @@ export {
9437
10703
  imageSizeOf,
9438
10704
  isMcpAppSandboxMessage,
9439
10705
  isWebGPUAvailable2 as isWebGPUAvailable,
10706
+ languageOfText,
9440
10707
  lessonsOf,
9441
10708
  linkedFilesOf,
9442
10709
  loadSkillFromUrl,
@@ -9453,24 +10720,36 @@ export {
9453
10720
  mergeChatRecord,
9454
10721
  mergeLabels,
9455
10722
  messageOverLimit,
10723
+ micProblemOf,
10724
+ micProblemText,
9456
10725
  newChatId,
9457
10726
  noticesOf,
9458
10727
  onStorageChange,
9459
10728
  parseSkillMarkdown,
9460
10729
  parseSlash,
9461
10730
  pendingApprovalsOf,
10731
+ pickRecordingType,
9462
10732
  postStorageChange2 as postStorageChange,
9463
10733
  preloadWebLLMModel2 as preloadWebLLMModel,
9464
10734
  questionChoiceOf,
9465
10735
  questionOtherOf,
9466
10736
  questionTimeoutOf,
10737
+ recordingSupported,
9467
10738
  resolveAppDownload,
9468
10739
  sandboxTokens,
9469
10740
  sandboxedCsp,
9470
10741
  saveAppFile,
9471
10742
  saveChat,
10743
+ scriptOfLanguage,
10744
+ scriptOfText,
9472
10745
  serveSubagentWorker,
10746
+ settleAudioDuration,
10747
+ speakableText,
10748
+ speechSynthesisSupported,
10749
+ splitForSpeech,
10750
+ startRecording,
9473
10751
  steerIntent,
10752
+ stopTracks,
9474
10753
  subagentTree,
9475
10754
  supportsImages,
9476
10755
  supportsPdf,
@@ -9480,6 +10759,7 @@ export {
9480
10759
  usageLine,
9481
10760
  useAgent,
9482
10761
  useAgentContext,
10762
+ useAudioRecorder,
9483
10763
  useChatHistory,
9484
10764
  useCredentials,
9485
10765
  useFollowScroll,
@@ -9487,9 +10767,14 @@ export {
9487
10767
  useLocalModel,
9488
10768
  useMcpAppHost,
9489
10769
  useOptionalAgentContext,
10770
+ useReadAloud,
9490
10771
  useSpeechToText,
10772
+ useSpeechVoices,
9491
10773
  useVirtualFiles,
9492
10774
  useWebLLMModel,
10775
+ voiceFor,
10776
+ voiceMessageName,
10777
+ voicesOf,
9493
10778
  watchSession2 as watchSession,
9494
10779
  webSearchOf,
9495
10780
  withAttachments,