@dudko.dev/agent-web-react 0.0.37 → 0.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -3
- package/dist/{chunk-G5GGIMD4.js → chunk-RJM7JCWI.js} +12 -1
- package/dist/chunk-RJM7JCWI.js.map +1 -0
- package/dist/{elicitation-NV1_UPkJ.d.cts → elicitation-DdzjMut9.d.cts} +12 -0
- package/dist/{elicitation-NV1_UPkJ.d.ts → elicitation-DdzjMut9.d.ts} +12 -0
- package/dist/index.cjs +1585 -267
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +603 -17
- package/dist/index.d.ts +603 -17
- package/dist/index.js +1536 -253
- package/dist/index.js.map +1 -1
- package/dist/mcp.d.cts +2 -2
- package/dist/mcp.d.ts +2 -2
- package/dist/pipeline.cjs.map +1 -1
- package/dist/pipeline.js +1 -1
- package/dist/styles.css +120 -0
- package/package.json +3 -3
- package/dist/chunk-G5GGIMD4.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -33,6 +33,8 @@ import {
|
|
|
33
33
|
MoreIcon,
|
|
34
34
|
NoNetworkIcon,
|
|
35
35
|
PanelIcon,
|
|
36
|
+
PauseIcon,
|
|
37
|
+
PlayIcon,
|
|
36
38
|
PlusIcon,
|
|
37
39
|
QuestionIcon,
|
|
38
40
|
ReloadIcon,
|
|
@@ -40,10 +42,12 @@ import {
|
|
|
40
42
|
ShieldIcon,
|
|
41
43
|
ShrinkIcon,
|
|
42
44
|
SlashIcon,
|
|
45
|
+
SpeakerIcon,
|
|
43
46
|
SpinnerIcon,
|
|
44
47
|
StopIcon,
|
|
45
48
|
TableIcon,
|
|
46
49
|
ToolIcon,
|
|
50
|
+
WaveIcon,
|
|
47
51
|
XIcon,
|
|
48
52
|
errMessage,
|
|
49
53
|
followOtherTabs,
|
|
@@ -53,7 +57,7 @@ import {
|
|
|
53
57
|
imagesInOutput,
|
|
54
58
|
previewValue,
|
|
55
59
|
webSearchOf
|
|
56
|
-
} from "./chunk-
|
|
60
|
+
} from "./chunk-RJM7JCWI.js";
|
|
57
61
|
import {
|
|
58
62
|
MCP_APP_POLICY_TOKEN_MAX_CHARS,
|
|
59
63
|
MCP_APP_SANDBOX_PROXY_READY,
|
|
@@ -509,6 +513,13 @@ var mediaOf = (event, withStep) => ({
|
|
|
509
513
|
mediaType: event.mediaType,
|
|
510
514
|
bytes: event.bytes,
|
|
511
515
|
model: event.model,
|
|
516
|
+
...event.references ? {
|
|
517
|
+
references: {
|
|
518
|
+
used: event.references.used === true,
|
|
519
|
+
count: event.references.count,
|
|
520
|
+
paths: [...event.references.paths]
|
|
521
|
+
}
|
|
522
|
+
} : {},
|
|
512
523
|
...withStep && event.step ? { stepId: event.step.id } : {}
|
|
513
524
|
});
|
|
514
525
|
var addApp = (state, event, by) => {
|
|
@@ -1582,7 +1593,8 @@ var useAgent = (config, options = {}) => {
|
|
|
1582
1593
|
let began = false;
|
|
1583
1594
|
const shownGoal = runOptions?.label ?? goal;
|
|
1584
1595
|
dispatch({ type: "status", status: "running" });
|
|
1585
|
-
|
|
1596
|
+
const shownAtAll = Boolean(shownGoal.trim() || runOptions?.attachments?.length);
|
|
1597
|
+
if (shownAtAll) {
|
|
1586
1598
|
dispatch({
|
|
1587
1599
|
type: "submitted",
|
|
1588
1600
|
goal: shownGoal,
|
|
@@ -1602,14 +1614,16 @@ var useAgent = (config, options = {}) => {
|
|
|
1602
1614
|
startedRef.current = true;
|
|
1603
1615
|
began = true;
|
|
1604
1616
|
}
|
|
1605
|
-
const shown = start && runOptions?.label ? { ...event, goal: runOptions.label } : event;
|
|
1617
|
+
const shown = start && runOptions?.label !== void 0 ? { ...event, goal: runOptions.label } : event;
|
|
1606
1618
|
dispatch({
|
|
1607
1619
|
type: "event",
|
|
1608
1620
|
event: shown,
|
|
1609
1621
|
maxEvents: optionsRef.current.maxEvents,
|
|
1610
1622
|
at: Date.now(),
|
|
1611
1623
|
// What the user sent waits with the run: shown as queued meanwhile.
|
|
1612
|
-
...event.type === "session.busy" &&
|
|
1624
|
+
...event.type === "session.busy" && shownAtAll ? {
|
|
1625
|
+
goal: shownGoal.trim() || (runOptions?.attachments ?? []).map((a) => a.name).join(", ")
|
|
1626
|
+
} : {},
|
|
1613
1627
|
...start && runOptions?.attachments?.length ? { attachments: runOptions.attachments } : {}
|
|
1614
1628
|
});
|
|
1615
1629
|
try {
|
|
@@ -1976,8 +1990,17 @@ var ChatHistoryStore = class {
|
|
|
1976
1990
|
await this.write((store) => store.clear(), { op: "clear" });
|
|
1977
1991
|
}
|
|
1978
1992
|
};
|
|
1979
|
-
var
|
|
1980
|
-
|
|
1993
|
+
var attachmentsText = (attachments, texts = {}) => attachments.length > 0 && attachments.every((a) => a.mediaType.toLowerCase().startsWith("audio/")) ? texts.voiceMessage ?? "Voice message" : attachments.map((a) => a.name).join(", ");
|
|
1994
|
+
var oneLine = (text) => (text ?? "").replace(/\s+/g, " ").trim();
|
|
1995
|
+
var chatTitle = (messages, texts = {}) => {
|
|
1996
|
+
const at = messages.findIndex((m) => m.role === "user");
|
|
1997
|
+
const user = at >= 0 ? messages[at] : void 0;
|
|
1998
|
+
let first = oneLine(user?.content);
|
|
1999
|
+
if (!first && user?.attachments?.length) {
|
|
2000
|
+
const answer = messages.slice(at + 1).find((m) => m.role === "assistant");
|
|
2001
|
+
const heard = answer?.transcripts?.find((t) => t.source === "attachment")?.text;
|
|
2002
|
+
first = oneLine(heard) || oneLine(attachmentsText(user.attachments, texts));
|
|
2003
|
+
}
|
|
1981
2004
|
if (!first) return "New chat";
|
|
1982
2005
|
return first.length > 60 ? `${first.slice(0, 59)}\u2026` : first;
|
|
1983
2006
|
};
|
|
@@ -2009,7 +2032,7 @@ var renumber = (own, after) => {
|
|
|
2009
2032
|
return own.map((m) => ({ ...m, id: `msg-${next += 1}` }));
|
|
2010
2033
|
};
|
|
2011
2034
|
var unchangedSince = (messages, base) => base !== void 0 && messages.length === base.known.size && messages.every((m) => base.known.has(m));
|
|
2012
|
-
var mergeChatRecord = (view, stored, base) => {
|
|
2035
|
+
var mergeChatRecord = (view, stored, base, texts) => {
|
|
2013
2036
|
const local = view.messages.filter((m) => !m.remote);
|
|
2014
2037
|
if (!stored || base && stored.updatedAt <= base.updatedAt) {
|
|
2015
2038
|
return { record: { ...view, messages: local }, merged: false };
|
|
@@ -2020,7 +2043,7 @@ var mergeChatRecord = (view, stored, base) => {
|
|
|
2020
2043
|
record: {
|
|
2021
2044
|
...view,
|
|
2022
2045
|
createdAt: stored.createdAt,
|
|
2023
|
-
title: chatTitle(messages),
|
|
2046
|
+
title: chatTitle(messages, texts),
|
|
2024
2047
|
messages,
|
|
2025
2048
|
totalUsage: sumUsage(
|
|
2026
2049
|
stored.totalUsage,
|
|
@@ -2030,10 +2053,10 @@ var mergeChatRecord = (view, stored, base) => {
|
|
|
2030
2053
|
merged: true
|
|
2031
2054
|
};
|
|
2032
2055
|
};
|
|
2033
|
-
var saveChat = async (store, view, base) => {
|
|
2056
|
+
var saveChat = async (store, view, base, texts) => {
|
|
2034
2057
|
let merged = false;
|
|
2035
2058
|
const record = await store.putMerged(view.id, (stored) => {
|
|
2036
|
-
const out = mergeChatRecord(view, stored, base);
|
|
2059
|
+
const out = mergeChatRecord(view, stored, base, texts);
|
|
2037
2060
|
merged = out.merged;
|
|
2038
2061
|
return out.record;
|
|
2039
2062
|
});
|
|
@@ -2041,6 +2064,8 @@ var saveChat = async (store, view, base) => {
|
|
|
2041
2064
|
};
|
|
2042
2065
|
var useChatHistory = (agent, options = {}) => {
|
|
2043
2066
|
const enabled = options.enabled !== false;
|
|
2067
|
+
const textsRef = useRef2(options.labels);
|
|
2068
|
+
textsRef.current = options.labels;
|
|
2044
2069
|
const store = useMemo(() => options.store ?? new ChatHistoryStore(), [options.store]);
|
|
2045
2070
|
const [chats, setChats] = useState2([]);
|
|
2046
2071
|
const [loading, setLoading] = useState2(enabled);
|
|
@@ -2134,14 +2159,14 @@ var useChatHistory = (agent, options = {}) => {
|
|
|
2134
2159
|
createdRef.current.set(sessionId, createdAt);
|
|
2135
2160
|
const view = {
|
|
2136
2161
|
id: sessionId,
|
|
2137
|
-
title: chatTitle(messages),
|
|
2162
|
+
title: chatTitle(messages, textsRef.current),
|
|
2138
2163
|
createdAt,
|
|
2139
2164
|
updatedAt: now,
|
|
2140
2165
|
messages,
|
|
2141
2166
|
totalUsage
|
|
2142
2167
|
};
|
|
2143
2168
|
void (async () => {
|
|
2144
|
-
const { record, merged } = await saveChat(store, view, base);
|
|
2169
|
+
const { record, merged } = await saveChat(store, view, base, textsRef.current);
|
|
2145
2170
|
baseRef.current = {
|
|
2146
2171
|
id: sessionId,
|
|
2147
2172
|
known: new Set(merged ? record.messages : messages),
|
|
@@ -2226,7 +2251,7 @@ var useVirtualFiles = (vfs, prefix = "/") => {
|
|
|
2226
2251
|
};
|
|
2227
2252
|
|
|
2228
2253
|
// src/hooks/use-speech-to-text.ts
|
|
2229
|
-
import { useCallback as useCallback4, useEffect as useEffect4, useRef as useRef3, useState as useState4 } from "react";
|
|
2254
|
+
import { useCallback as useCallback4, useEffect as useEffect4, useMemo as useMemo2, useRef as useRef3, useState as useState4 } from "react";
|
|
2230
2255
|
var browserRecognizer = () => {
|
|
2231
2256
|
const g = globalThis;
|
|
2232
2257
|
const Ctor = g.SpeechRecognition ?? g.webkitSpeechRecognition;
|
|
@@ -2235,13 +2260,18 @@ var browserRecognizer = () => {
|
|
|
2235
2260
|
var useSpeechToText = (options = {}) => {
|
|
2236
2261
|
const optionsRef = useRef3(options);
|
|
2237
2262
|
optionsRef.current = options;
|
|
2238
|
-
const
|
|
2263
|
+
const own = options.createRecognizer;
|
|
2264
|
+
const factory = useMemo2(() => own ?? browserRecognizer(), [own]);
|
|
2239
2265
|
const [listening, setListening] = useState4(false);
|
|
2240
2266
|
const [interim, setInterim] = useState4("");
|
|
2241
2267
|
const [error, setError] = useState4();
|
|
2268
|
+
const [errorMessage, setErrorMessage] = useState4();
|
|
2269
|
+
const [finishing, setFinishing] = useState4(false);
|
|
2242
2270
|
const recRef = useRef3(void 0);
|
|
2243
2271
|
const stop = useCallback4(() => {
|
|
2244
|
-
recRef.current
|
|
2272
|
+
if (!recRef.current) return;
|
|
2273
|
+
setFinishing(true);
|
|
2274
|
+
recRef.current.stop();
|
|
2245
2275
|
}, []);
|
|
2246
2276
|
const start = useCallback4(() => {
|
|
2247
2277
|
if (!factory || recRef.current) return;
|
|
@@ -2259,15 +2289,22 @@ var useSpeechToText = (options = {}) => {
|
|
|
2259
2289
|
setInterim(pending);
|
|
2260
2290
|
};
|
|
2261
2291
|
rec.onerror = (ev) => {
|
|
2262
|
-
if (ev.error && ev.error !== "no-speech" && ev.error !== "aborted")
|
|
2292
|
+
if (ev.error && ev.error !== "no-speech" && ev.error !== "aborted") {
|
|
2293
|
+
setError(ev.error);
|
|
2294
|
+
setErrorMessage(ev.message);
|
|
2295
|
+
}
|
|
2263
2296
|
};
|
|
2264
2297
|
rec.onend = () => {
|
|
2298
|
+
if (recRef.current !== rec) return;
|
|
2265
2299
|
recRef.current = void 0;
|
|
2266
2300
|
setListening(false);
|
|
2301
|
+
setFinishing(false);
|
|
2267
2302
|
setInterim("");
|
|
2268
2303
|
};
|
|
2269
2304
|
recRef.current = rec;
|
|
2270
2305
|
setError(void 0);
|
|
2306
|
+
setErrorMessage(void 0);
|
|
2307
|
+
setFinishing(false);
|
|
2271
2308
|
try {
|
|
2272
2309
|
rec.start();
|
|
2273
2310
|
setListening(true);
|
|
@@ -2276,20 +2313,763 @@ var useSpeechToText = (options = {}) => {
|
|
|
2276
2313
|
setError(err instanceof Error ? err.message : String(err));
|
|
2277
2314
|
}
|
|
2278
2315
|
}, [factory]);
|
|
2279
|
-
useEffect4(
|
|
2316
|
+
useEffect4(
|
|
2317
|
+
() => () => {
|
|
2318
|
+
const rec = recRef.current;
|
|
2319
|
+
recRef.current = void 0;
|
|
2320
|
+
rec?.abort?.();
|
|
2321
|
+
},
|
|
2322
|
+
[factory]
|
|
2323
|
+
);
|
|
2280
2324
|
return {
|
|
2281
2325
|
supported: Boolean(factory),
|
|
2282
2326
|
listening,
|
|
2327
|
+
finishing,
|
|
2283
2328
|
interim,
|
|
2284
2329
|
error,
|
|
2330
|
+
errorMessage,
|
|
2285
2331
|
start,
|
|
2286
2332
|
stop,
|
|
2287
2333
|
toggle: () => recRef.current ? stop() : start()
|
|
2288
2334
|
};
|
|
2289
2335
|
};
|
|
2290
2336
|
|
|
2337
|
+
// src/hooks/use-audio-recorder.ts
|
|
2338
|
+
import { useCallback as useCallback5, useEffect as useEffect5, useRef as useRef4, useState as useState5 } from "react";
|
|
2339
|
+
|
|
2340
|
+
// src/voice/record.ts
|
|
2341
|
+
var MicError = class extends Error {
|
|
2342
|
+
code;
|
|
2343
|
+
constructor(code, message = code) {
|
|
2344
|
+
super(message);
|
|
2345
|
+
this.name = "MicError";
|
|
2346
|
+
this.code = code;
|
|
2347
|
+
}
|
|
2348
|
+
};
|
|
2349
|
+
var RECORDING_DEFAULT_MAX_MS = 5 * 60 * 1e3;
|
|
2350
|
+
var RECORDING_TYPES = [
|
|
2351
|
+
"audio/webm;codecs=opus",
|
|
2352
|
+
"audio/webm",
|
|
2353
|
+
"audio/mp4",
|
|
2354
|
+
"audio/ogg;codecs=opus",
|
|
2355
|
+
"audio/ogg"
|
|
2356
|
+
];
|
|
2357
|
+
var pickRecordingType = (isTypeSupported) => {
|
|
2358
|
+
if (!isTypeSupported) return void 0;
|
|
2359
|
+
for (const type of RECORDING_TYPES) {
|
|
2360
|
+
try {
|
|
2361
|
+
if (isTypeSupported(type)) return type;
|
|
2362
|
+
} catch {
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
return void 0;
|
|
2366
|
+
};
|
|
2367
|
+
var audioTypeOf = (type) => {
|
|
2368
|
+
const base = (type ?? "").toLowerCase().split(";")[0].trim();
|
|
2369
|
+
if (/^(audio|video)\/(mp4|x-m4a|m4a|aac-mp4)$/.test(base)) return "audio/mp4";
|
|
2370
|
+
if (/^(audio|video)\/webm$/.test(base)) return "audio/webm";
|
|
2371
|
+
if (base === "audio/ogg" || base === "application/ogg") return "audio/ogg";
|
|
2372
|
+
if (base === "audio/wav" || base === "audio/x-wav" || base === "audio/wave") return "audio/wav";
|
|
2373
|
+
if (base === "audio/mpeg" || base === "audio/mp3") return "audio/mpeg";
|
|
2374
|
+
if (base === "audio/aac") return "audio/aac";
|
|
2375
|
+
return "audio/webm";
|
|
2376
|
+
};
|
|
2377
|
+
var audioExtensionOf = (type) => ({
|
|
2378
|
+
"audio/mp4": "m4a",
|
|
2379
|
+
"audio/ogg": "ogg",
|
|
2380
|
+
"audio/wav": "wav",
|
|
2381
|
+
"audio/mpeg": "mp3",
|
|
2382
|
+
"audio/aac": "aac"
|
|
2383
|
+
})[audioTypeOf(type)] ?? "webm";
|
|
2384
|
+
var micProblemOf = (err) => {
|
|
2385
|
+
if (err instanceof MicError) return err.code;
|
|
2386
|
+
const name = err && typeof err === "object" ? String(err.name) : "";
|
|
2387
|
+
if (name === "NotAllowedError" || name === "SecurityError" || name === "PermissionDeniedError")
|
|
2388
|
+
return "not-allowed";
|
|
2389
|
+
if (name === "NotFoundError" || name === "OverconstrainedError" || name === "DevicesNotFoundError")
|
|
2390
|
+
return "audio-capture";
|
|
2391
|
+
if (name === "NotReadableError" || name === "TrackStartError" || name === "AbortError")
|
|
2392
|
+
return "busy";
|
|
2393
|
+
if (name === "NotSupportedError" || name === "TypeError") return "unsupported";
|
|
2394
|
+
return "failed";
|
|
2395
|
+
};
|
|
2396
|
+
var defaults = (deps) => {
|
|
2397
|
+
const g = globalThis;
|
|
2398
|
+
const devices = g.navigator?.mediaDevices;
|
|
2399
|
+
return {
|
|
2400
|
+
getUserMedia: deps.getUserMedia ?? (devices?.getUserMedia ? devices.getUserMedia.bind(devices) : void 0),
|
|
2401
|
+
MediaRecorder: deps.MediaRecorder ?? g.MediaRecorder,
|
|
2402
|
+
now: deps.now ?? Date.now
|
|
2403
|
+
};
|
|
2404
|
+
};
|
|
2405
|
+
var recordingSupported = (deps = {}) => {
|
|
2406
|
+
const d = defaults(deps);
|
|
2407
|
+
return Boolean(d.getUserMedia && d.MediaRecorder);
|
|
2408
|
+
};
|
|
2409
|
+
var stopTracks = (stream) => {
|
|
2410
|
+
for (const track of stream?.getTracks() ?? []) {
|
|
2411
|
+
try {
|
|
2412
|
+
track.stop();
|
|
2413
|
+
} catch {
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
};
|
|
2417
|
+
var startRecording = async (options = {}) => {
|
|
2418
|
+
const d = defaults(options);
|
|
2419
|
+
if (!d.getUserMedia || !d.MediaRecorder) throw new MicError("unsupported");
|
|
2420
|
+
let stream;
|
|
2421
|
+
try {
|
|
2422
|
+
stream = await d.getUserMedia({ audio: true });
|
|
2423
|
+
} catch (err) {
|
|
2424
|
+
throw new MicError(micProblemOf(err));
|
|
2425
|
+
}
|
|
2426
|
+
let recorder;
|
|
2427
|
+
try {
|
|
2428
|
+
const type = pickRecordingType(d.MediaRecorder.isTypeSupported?.bind(d.MediaRecorder));
|
|
2429
|
+
recorder = new d.MediaRecorder(stream, type ? { mimeType: type } : void 0);
|
|
2430
|
+
} catch (err) {
|
|
2431
|
+
stopTracks(stream);
|
|
2432
|
+
throw new MicError(micProblemOf(err) === "failed" ? "unsupported" : micProblemOf(err));
|
|
2433
|
+
}
|
|
2434
|
+
const startedAt = d.now();
|
|
2435
|
+
const chunks = [];
|
|
2436
|
+
let cancelled = false;
|
|
2437
|
+
let failure;
|
|
2438
|
+
let settle = () => {
|
|
2439
|
+
};
|
|
2440
|
+
const ended = new Promise((resolve) => settle = resolve);
|
|
2441
|
+
let finish;
|
|
2442
|
+
let fail;
|
|
2443
|
+
const result = new Promise((resolve, reject) => {
|
|
2444
|
+
finish = resolve;
|
|
2445
|
+
fail = reject;
|
|
2446
|
+
});
|
|
2447
|
+
result.catch(() => {
|
|
2448
|
+
});
|
|
2449
|
+
let limit;
|
|
2450
|
+
const end = () => {
|
|
2451
|
+
stopTracks(stream);
|
|
2452
|
+
clearTimeout(limit);
|
|
2453
|
+
settle();
|
|
2454
|
+
};
|
|
2455
|
+
recorder.ondataavailable = (event) => {
|
|
2456
|
+
if (event.data && event.data.size > 0) chunks.push(event.data);
|
|
2457
|
+
};
|
|
2458
|
+
recorder.onerror = () => {
|
|
2459
|
+
failure = new MicError("failed");
|
|
2460
|
+
end();
|
|
2461
|
+
fail?.(failure);
|
|
2462
|
+
};
|
|
2463
|
+
recorder.onstop = () => {
|
|
2464
|
+
end();
|
|
2465
|
+
if (cancelled) return fail?.(new MicError("failed", "cancelled"));
|
|
2466
|
+
if (failure) return fail?.(failure);
|
|
2467
|
+
const mediaType = audioTypeOf(recorder.mimeType || chunks[0]?.type);
|
|
2468
|
+
finish?.({
|
|
2469
|
+
blob: new Blob(chunks, { type: mediaType }),
|
|
2470
|
+
mediaType,
|
|
2471
|
+
durationMs: Math.max(0, d.now() - startedAt)
|
|
2472
|
+
});
|
|
2473
|
+
};
|
|
2474
|
+
const stopRecorder = () => {
|
|
2475
|
+
try {
|
|
2476
|
+
if (recorder.state !== "inactive") recorder.stop();
|
|
2477
|
+
else recorder.onstop?.();
|
|
2478
|
+
} catch {
|
|
2479
|
+
recorder.onstop?.();
|
|
2480
|
+
}
|
|
2481
|
+
};
|
|
2482
|
+
const maxMs = options.maxMs ?? RECORDING_DEFAULT_MAX_MS;
|
|
2483
|
+
limit = setTimeout(() => {
|
|
2484
|
+
stopRecorder();
|
|
2485
|
+
options.onLimit?.();
|
|
2486
|
+
}, maxMs);
|
|
2487
|
+
try {
|
|
2488
|
+
recorder.start(1e3);
|
|
2489
|
+
} catch (err) {
|
|
2490
|
+
end();
|
|
2491
|
+
throw new MicError(micProblemOf(err) === "failed" ? "unsupported" : micProblemOf(err));
|
|
2492
|
+
}
|
|
2493
|
+
return {
|
|
2494
|
+
startedAt,
|
|
2495
|
+
ended,
|
|
2496
|
+
stop: () => {
|
|
2497
|
+
stopRecorder();
|
|
2498
|
+
return result;
|
|
2499
|
+
},
|
|
2500
|
+
cancel: () => {
|
|
2501
|
+
cancelled = true;
|
|
2502
|
+
chunks.length = 0;
|
|
2503
|
+
stopRecorder();
|
|
2504
|
+
end();
|
|
2505
|
+
}
|
|
2506
|
+
};
|
|
2507
|
+
};
|
|
2508
|
+
|
|
2509
|
+
// src/hooks/use-audio-recorder.ts
|
|
2510
|
+
var useAudioRecorder = (options = {}) => {
|
|
2511
|
+
const opts = useRef4(options);
|
|
2512
|
+
opts.current = options;
|
|
2513
|
+
const [state, setState] = useState5("idle");
|
|
2514
|
+
const [elapsedMs, setElapsed] = useState5(0);
|
|
2515
|
+
const [error, setError] = useState5();
|
|
2516
|
+
const [limited, setLimited] = useState5();
|
|
2517
|
+
const rec = useRef4(void 0);
|
|
2518
|
+
const pending = useRef4(false);
|
|
2519
|
+
const gone = useRef4(false);
|
|
2520
|
+
useEffect5(() => {
|
|
2521
|
+
if (state !== "recording") return;
|
|
2522
|
+
const at = rec.current?.startedAt ?? Date.now();
|
|
2523
|
+
const now = opts.current.now ?? Date.now;
|
|
2524
|
+
setElapsed(Math.max(0, now() - at));
|
|
2525
|
+
const id = setInterval(() => setElapsed(Math.max(0, now() - at)), 250);
|
|
2526
|
+
return () => clearInterval(id);
|
|
2527
|
+
}, [state]);
|
|
2528
|
+
const start = useCallback5(async () => {
|
|
2529
|
+
if (rec.current || pending.current) return;
|
|
2530
|
+
pending.current = true;
|
|
2531
|
+
setError(void 0);
|
|
2532
|
+
setLimited(void 0);
|
|
2533
|
+
setState("starting");
|
|
2534
|
+
try {
|
|
2535
|
+
const started = await startRecording({
|
|
2536
|
+
...opts.current,
|
|
2537
|
+
onLimit: () => {
|
|
2538
|
+
const r = rec.current;
|
|
2539
|
+
rec.current = void 0;
|
|
2540
|
+
setState("stopping");
|
|
2541
|
+
void r?.stop().then(
|
|
2542
|
+
(audio) => !gone.current && setLimited(audio),
|
|
2543
|
+
() => void 0
|
|
2544
|
+
).finally(() => !gone.current && setState("idle"));
|
|
2545
|
+
}
|
|
2546
|
+
});
|
|
2547
|
+
if (gone.current) return started.cancel();
|
|
2548
|
+
rec.current = started;
|
|
2549
|
+
setState("recording");
|
|
2550
|
+
} catch (err) {
|
|
2551
|
+
if (!gone.current) {
|
|
2552
|
+
setError(micProblemOf(err));
|
|
2553
|
+
setState("idle");
|
|
2554
|
+
}
|
|
2555
|
+
} finally {
|
|
2556
|
+
pending.current = false;
|
|
2557
|
+
}
|
|
2558
|
+
}, []);
|
|
2559
|
+
const stop = useCallback5(async () => {
|
|
2560
|
+
const r = rec.current;
|
|
2561
|
+
if (!r) return void 0;
|
|
2562
|
+
rec.current = void 0;
|
|
2563
|
+
setState("stopping");
|
|
2564
|
+
try {
|
|
2565
|
+
return await r.stop();
|
|
2566
|
+
} catch {
|
|
2567
|
+
return void 0;
|
|
2568
|
+
} finally {
|
|
2569
|
+
if (!gone.current) setState("idle");
|
|
2570
|
+
}
|
|
2571
|
+
}, []);
|
|
2572
|
+
const cancel = useCallback5(() => {
|
|
2573
|
+
const r = rec.current;
|
|
2574
|
+
rec.current = void 0;
|
|
2575
|
+
r?.cancel();
|
|
2576
|
+
setLimited(void 0);
|
|
2577
|
+
setState("idle");
|
|
2578
|
+
}, []);
|
|
2579
|
+
useEffect5(() => {
|
|
2580
|
+
gone.current = false;
|
|
2581
|
+
return () => {
|
|
2582
|
+
gone.current = true;
|
|
2583
|
+
rec.current?.cancel();
|
|
2584
|
+
rec.current = void 0;
|
|
2585
|
+
};
|
|
2586
|
+
}, []);
|
|
2587
|
+
return {
|
|
2588
|
+
supported: recordingSupported(options),
|
|
2589
|
+
state,
|
|
2590
|
+
elapsedMs,
|
|
2591
|
+
error,
|
|
2592
|
+
limited,
|
|
2593
|
+
start,
|
|
2594
|
+
stop,
|
|
2595
|
+
cancel,
|
|
2596
|
+
clear: () => {
|
|
2597
|
+
setLimited(void 0);
|
|
2598
|
+
setError(void 0);
|
|
2599
|
+
}
|
|
2600
|
+
};
|
|
2601
|
+
};
|
|
2602
|
+
|
|
2603
|
+
// src/hooks/use-read-aloud.ts
|
|
2604
|
+
import { useCallback as useCallback6, useEffect as useEffect6, useRef as useRef5, useState as useState6 } from "react";
|
|
2605
|
+
var useReadAloud = (speak, lang) => {
|
|
2606
|
+
const [current, setCurrent] = useState6();
|
|
2607
|
+
const [state, setState] = useState6();
|
|
2608
|
+
const [failed, setFailed] = useState6();
|
|
2609
|
+
const playback = useRef5(void 0);
|
|
2610
|
+
const langRef = useRef5(lang);
|
|
2611
|
+
langRef.current = lang;
|
|
2612
|
+
const stop = useCallback6(() => {
|
|
2613
|
+
const now = playback.current;
|
|
2614
|
+
playback.current = void 0;
|
|
2615
|
+
now?.handle.stop();
|
|
2616
|
+
setCurrent(void 0);
|
|
2617
|
+
setState(void 0);
|
|
2618
|
+
}, []);
|
|
2619
|
+
const start = useCallback6(
|
|
2620
|
+
(id, text) => {
|
|
2621
|
+
if (!speak) return;
|
|
2622
|
+
stop();
|
|
2623
|
+
setFailed(void 0);
|
|
2624
|
+
setCurrent(id);
|
|
2625
|
+
setState("loading");
|
|
2626
|
+
const mine = { id, handle: void 0 };
|
|
2627
|
+
playback.current = mine;
|
|
2628
|
+
let handle;
|
|
2629
|
+
try {
|
|
2630
|
+
handle = speak(text, {
|
|
2631
|
+
lang: langRef.current,
|
|
2632
|
+
onState: (s) => {
|
|
2633
|
+
if (playback.current === mine) setState(s);
|
|
2634
|
+
}
|
|
2635
|
+
});
|
|
2636
|
+
} catch (err) {
|
|
2637
|
+
playback.current = void 0;
|
|
2638
|
+
setCurrent(void 0);
|
|
2639
|
+
setState(void 0);
|
|
2640
|
+
const own = err instanceof Error && err.name !== "SpeechOutputError";
|
|
2641
|
+
setFailed({ id, ...own && err.message ? { message: err.message } : {} });
|
|
2642
|
+
return;
|
|
2643
|
+
}
|
|
2644
|
+
mine.handle = handle;
|
|
2645
|
+
handle.done.then(
|
|
2646
|
+
() => {
|
|
2647
|
+
if (playback.current !== mine) return;
|
|
2648
|
+
playback.current = void 0;
|
|
2649
|
+
setCurrent(void 0);
|
|
2650
|
+
setState(void 0);
|
|
2651
|
+
},
|
|
2652
|
+
(err) => {
|
|
2653
|
+
if (playback.current !== mine) return;
|
|
2654
|
+
playback.current = void 0;
|
|
2655
|
+
setCurrent(void 0);
|
|
2656
|
+
setState(void 0);
|
|
2657
|
+
const own = err instanceof Error && err.name !== "SpeechOutputError";
|
|
2658
|
+
setFailed({ id, ...own && err.message ? { message: err.message } : {} });
|
|
2659
|
+
}
|
|
2660
|
+
);
|
|
2661
|
+
},
|
|
2662
|
+
[speak, stop]
|
|
2663
|
+
);
|
|
2664
|
+
useEffect6(() => stop, [speak, stop]);
|
|
2665
|
+
return {
|
|
2666
|
+
current,
|
|
2667
|
+
state,
|
|
2668
|
+
failed,
|
|
2669
|
+
start,
|
|
2670
|
+
pause: () => playback.current?.handle.pause(),
|
|
2671
|
+
resume: () => playback.current?.handle.resume(),
|
|
2672
|
+
stop
|
|
2673
|
+
};
|
|
2674
|
+
};
|
|
2675
|
+
|
|
2676
|
+
// src/hooks/use-speech-voices.ts
|
|
2677
|
+
import { useEffect as useEffect7, useState as useState7 } from "react";
|
|
2678
|
+
var useSpeechVoices = () => {
|
|
2679
|
+
const synth = typeof globalThis !== "undefined" ? globalThis.speechSynthesis : void 0;
|
|
2680
|
+
const read = () => {
|
|
2681
|
+
try {
|
|
2682
|
+
return (synth?.getVoices() ?? []).map((v) => ({
|
|
2683
|
+
voiceURI: v.voiceURI,
|
|
2684
|
+
name: v.name,
|
|
2685
|
+
lang: v.lang,
|
|
2686
|
+
localService: v.localService,
|
|
2687
|
+
default: v.default
|
|
2688
|
+
}));
|
|
2689
|
+
} catch {
|
|
2690
|
+
return [];
|
|
2691
|
+
}
|
|
2692
|
+
};
|
|
2693
|
+
const [voices, setVoices] = useState7(read);
|
|
2694
|
+
useEffect7(() => {
|
|
2695
|
+
if (!synth) return;
|
|
2696
|
+
const update = () => setVoices(read());
|
|
2697
|
+
update();
|
|
2698
|
+
synth.addEventListener?.("voiceschanged", update);
|
|
2699
|
+
return () => synth.removeEventListener?.("voiceschanged", update);
|
|
2700
|
+
}, [synth]);
|
|
2701
|
+
return voices;
|
|
2702
|
+
};
|
|
2703
|
+
|
|
2704
|
+
// src/voice/recognizer.ts
|
|
2705
|
+
var createRecordingRecognizer = (options) => () => {
|
|
2706
|
+
let recording;
|
|
2707
|
+
let starting;
|
|
2708
|
+
let stopAsked = false;
|
|
2709
|
+
let aborted = false;
|
|
2710
|
+
let ended = false;
|
|
2711
|
+
const controller = new AbortController();
|
|
2712
|
+
const rec = {
|
|
2713
|
+
lang: "",
|
|
2714
|
+
continuous: true,
|
|
2715
|
+
interimResults: false,
|
|
2716
|
+
onresult: null,
|
|
2717
|
+
onerror: null,
|
|
2718
|
+
onend: null,
|
|
2719
|
+
start() {
|
|
2720
|
+
if (starting) return;
|
|
2721
|
+
starting = (async () => {
|
|
2722
|
+
try {
|
|
2723
|
+
recording = await startRecording({
|
|
2724
|
+
...options,
|
|
2725
|
+
maxMs: options.maxMs,
|
|
2726
|
+
onLimit: () => rec.stop()
|
|
2727
|
+
});
|
|
2728
|
+
} catch (err) {
|
|
2729
|
+
if (!aborted) rec.onerror?.({ error: micProblemOf(err) });
|
|
2730
|
+
return finish();
|
|
2731
|
+
}
|
|
2732
|
+
if (aborted) {
|
|
2733
|
+
recording.cancel();
|
|
2734
|
+
return finish();
|
|
2735
|
+
}
|
|
2736
|
+
if (stopAsked) void transcribeNow();
|
|
2737
|
+
})();
|
|
2738
|
+
},
|
|
2739
|
+
stop() {
|
|
2740
|
+
if (stopAsked || ended) return;
|
|
2741
|
+
stopAsked = true;
|
|
2742
|
+
if (recording) void transcribeNow();
|
|
2743
|
+
},
|
|
2744
|
+
abort() {
|
|
2745
|
+
if (ended) return;
|
|
2746
|
+
aborted = true;
|
|
2747
|
+
controller.abort();
|
|
2748
|
+
recording?.cancel();
|
|
2749
|
+
if (!starting || recording) finish();
|
|
2750
|
+
}
|
|
2751
|
+
};
|
|
2752
|
+
const finish = () => {
|
|
2753
|
+
if (ended) return;
|
|
2754
|
+
ended = true;
|
|
2755
|
+
rec.onend?.();
|
|
2756
|
+
};
|
|
2757
|
+
let transcribing = false;
|
|
2758
|
+
const transcribeNow = async () => {
|
|
2759
|
+
if (transcribing || !recording) return;
|
|
2760
|
+
transcribing = true;
|
|
2761
|
+
let audio;
|
|
2762
|
+
try {
|
|
2763
|
+
audio = await recording.stop();
|
|
2764
|
+
} catch (err) {
|
|
2765
|
+
if (!aborted) rec.onerror?.({ error: micProblemOf(err) });
|
|
2766
|
+
return finish();
|
|
2767
|
+
}
|
|
2768
|
+
if (aborted) return finish();
|
|
2769
|
+
if (audio.blob.size === 0) return finish();
|
|
2770
|
+
try {
|
|
2771
|
+
const text = (await options.transcribe(audio, { lang: rec.lang, signal: controller.signal })).replace(/\s+/g, " ").trim();
|
|
2772
|
+
if (!aborted && text)
|
|
2773
|
+
rec.onresult?.({
|
|
2774
|
+
resultIndex: 0,
|
|
2775
|
+
results: [{ isFinal: true, 0: { transcript: text } }]
|
|
2776
|
+
});
|
|
2777
|
+
} catch (err) {
|
|
2778
|
+
if (!aborted)
|
|
2779
|
+
rec.onerror?.({
|
|
2780
|
+
error: "transcription",
|
|
2781
|
+
message: err instanceof Error ? err.message : String(err)
|
|
2782
|
+
});
|
|
2783
|
+
}
|
|
2784
|
+
finish();
|
|
2785
|
+
};
|
|
2786
|
+
return rec;
|
|
2787
|
+
};
|
|
2788
|
+
|
|
2789
|
+
// src/voice/speak.ts
|
|
2790
|
+
var SpeechOutputError = class extends Error {
|
|
2791
|
+
code;
|
|
2792
|
+
constructor(code) {
|
|
2793
|
+
super(code);
|
|
2794
|
+
this.name = "SpeechOutputError";
|
|
2795
|
+
this.code = code;
|
|
2796
|
+
}
|
|
2797
|
+
};
|
|
2798
|
+
var asOutputError = (err) => err instanceof SpeechOutputError ? err : new SpeechOutputError(
|
|
2799
|
+
err && typeof err === "object" && "name" in err ? String(err.name) : "playback-failed"
|
|
2800
|
+
);
|
|
2801
|
+
var speakableText = (markdown, options = {}) => {
|
|
2802
|
+
const out = [];
|
|
2803
|
+
const lines = markdown.replace(/\r\n?/g, "\n").split("\n");
|
|
2804
|
+
let fence;
|
|
2805
|
+
let fenceSaid = false;
|
|
2806
|
+
for (const raw of lines) {
|
|
2807
|
+
const line = raw.trimEnd();
|
|
2808
|
+
const opener = /^\s*(`{3,}|~{3,})/.exec(line);
|
|
2809
|
+
if (fence !== void 0) {
|
|
2810
|
+
if (opener && opener[1][0] === fence[0] && opener[1].length >= fence.length) fence = void 0;
|
|
2811
|
+
continue;
|
|
2812
|
+
}
|
|
2813
|
+
if (opener) {
|
|
2814
|
+
fence = opener[1];
|
|
2815
|
+
if (options.code && !fenceSaid) out.push(options.code);
|
|
2816
|
+
fenceSaid = true;
|
|
2817
|
+
continue;
|
|
2818
|
+
}
|
|
2819
|
+
fenceSaid = false;
|
|
2820
|
+
if (/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/.test(line)) continue;
|
|
2821
|
+
if (/^\s*([-*_])\s*(\1\s*){2,}$/.test(line)) continue;
|
|
2822
|
+
let text = line.replace(/^\s{0,3}#{1,6}\s+/, "").replace(/^\s*>\s?/, "").replace(/^\s*(?:[-*+]|\d+[.)])\s+(\[[ xX]\]\s+)?/, "");
|
|
2823
|
+
if (/^\s*\|.*\|\s*$/.test(text))
|
|
2824
|
+
text = text.replace(/^\s*\||\|\s*$/g, "").split("|").map((c) => c.trim()).filter(Boolean).join(", ");
|
|
2825
|
+
text = text.replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/\[([^\]]+)\]\([^)]*\)/g, "$1").replace(/<(https?:\/\/[^>\s]+)>/g, (_m, url) => hostOf(url)).replace(/\bhttps?:\/\/[^\s)]+/g, (url) => hostOf(url)).replace(/`+([^`]*)`+/g, "$1").replace(/(\*\*|__)(.+?)\1/g, "$2").replace(/(^|[^\w*])[*_]([^*_\s][^*_]*?)[*_](?=[^\w*]|$)/g, "$1$2").replace(/~~(.+?)~~/g, "$1").replace(/<\/?[a-z][^>]*>/gi, "").replace(/[*_#`~>|]/g, " ").replace(/\s+/g, " ").trim();
|
|
2826
|
+
if (!text) continue;
|
|
2827
|
+
out.push(/[.!?…:;。!?]$/.test(text) ? text : `${text}.`);
|
|
2828
|
+
}
|
|
2829
|
+
return out.join(" ").trim();
|
|
2830
|
+
};
|
|
2831
|
+
var hostOf = (url) => {
|
|
2832
|
+
try {
|
|
2833
|
+
return new URL(url).hostname.replace(/^www\./, "");
|
|
2834
|
+
} catch {
|
|
2835
|
+
return "";
|
|
2836
|
+
}
|
|
2837
|
+
};
|
|
2838
|
+
var splitForSpeech = (text, max = 220) => {
|
|
2839
|
+
const pieces = [];
|
|
2840
|
+
let rest = text.trim();
|
|
2841
|
+
while (rest.length > max) {
|
|
2842
|
+
const window2 = rest.slice(0, max + 1);
|
|
2843
|
+
let cut = -1;
|
|
2844
|
+
for (const m of window2.matchAll(/[.!?…。!?;:](\s|$)/g))
|
|
2845
|
+
if (m.index !== void 0 && m.index + 1 <= max) cut = m.index + 1;
|
|
2846
|
+
if (cut < max / 3) cut = window2.lastIndexOf(" ");
|
|
2847
|
+
if (cut <= 0) cut = max;
|
|
2848
|
+
pieces.push(rest.slice(0, cut).trim());
|
|
2849
|
+
rest = rest.slice(cut).trim();
|
|
2850
|
+
}
|
|
2851
|
+
if (rest) pieces.push(rest);
|
|
2852
|
+
return pieces;
|
|
2853
|
+
};
|
|
2854
|
+
var voiceFor = (voices, lang, preferred) => {
|
|
2855
|
+
if (preferred) {
|
|
2856
|
+
const chosen = voices.find((v) => v.voiceURI === preferred);
|
|
2857
|
+
if (chosen) return chosen;
|
|
2858
|
+
}
|
|
2859
|
+
if (!lang) return void 0;
|
|
2860
|
+
const norm = (l) => l.toLowerCase().replace(/_/g, "-");
|
|
2861
|
+
const want = norm(lang);
|
|
2862
|
+
const base = want.split("-")[0];
|
|
2863
|
+
const rank = (v) => [v.localService ? 1 : 0, v.default ? 1 : 0];
|
|
2864
|
+
const best = (list) => [...list].sort((a, b) => {
|
|
2865
|
+
const ra = rank(a);
|
|
2866
|
+
const rb = rank(b);
|
|
2867
|
+
return rb[0] - ra[0] || rb[1] - ra[1] || a.name.localeCompare(b.name);
|
|
2868
|
+
})[0];
|
|
2869
|
+
const exact = voices.filter((v) => norm(v.lang) === want);
|
|
2870
|
+
if (exact.length) return best(exact);
|
|
2871
|
+
const same = voices.filter((v) => norm(v.lang).split("-")[0] === base);
|
|
2872
|
+
return same.length ? best(same) : void 0;
|
|
2873
|
+
};
|
|
2874
|
+
var voicesOf = (voices, lang) => {
|
|
2875
|
+
if (!lang) return [...voices];
|
|
2876
|
+
const base = lang.toLowerCase().split(/[-_]/)[0];
|
|
2877
|
+
return voices.filter((v) => v.lang.toLowerCase().split(/[-_]/)[0] === base);
|
|
2878
|
+
};
|
|
2879
|
+
var speechSynthesisSupported = () => typeof globalThis !== "undefined" && "speechSynthesis" in globalThis && typeof globalThis.SpeechSynthesisUtterance === "function";
|
|
2880
|
+
var createBrowserSpeaker = (options = {}) => (text, { lang, onState }) => {
|
|
2881
|
+
const synth = options.synth ?? globalThis.speechSynthesis;
|
|
2882
|
+
const make = options.createUtterance ?? ((t) => new globalThis.SpeechSynthesisUtterance(t));
|
|
2883
|
+
const voice = voiceFor(synth.getVoices(), lang, options.voice);
|
|
2884
|
+
let settle;
|
|
2885
|
+
let fail;
|
|
2886
|
+
const done = new Promise((resolve, reject) => {
|
|
2887
|
+
settle = resolve;
|
|
2888
|
+
fail = reject;
|
|
2889
|
+
});
|
|
2890
|
+
done.catch(() => {
|
|
2891
|
+
});
|
|
2892
|
+
let over = false;
|
|
2893
|
+
const end = (err) => {
|
|
2894
|
+
if (over) return;
|
|
2895
|
+
over = true;
|
|
2896
|
+
if (err) fail(err);
|
|
2897
|
+
else settle();
|
|
2898
|
+
};
|
|
2899
|
+
const pieces = splitForSpeech(text);
|
|
2900
|
+
synth.cancel();
|
|
2901
|
+
if (pieces.length === 0) {
|
|
2902
|
+
end();
|
|
2903
|
+
return { pause() {
|
|
2904
|
+
}, resume() {
|
|
2905
|
+
}, stop() {
|
|
2906
|
+
}, done };
|
|
2907
|
+
}
|
|
2908
|
+
let started = false;
|
|
2909
|
+
pieces.forEach((piece, i) => {
|
|
2910
|
+
const u = make(piece);
|
|
2911
|
+
u.lang = voice?.lang ?? lang ?? "";
|
|
2912
|
+
try {
|
|
2913
|
+
u.voice = voice ?? null;
|
|
2914
|
+
} catch {
|
|
2915
|
+
}
|
|
2916
|
+
u.rate = options.rate ?? 1;
|
|
2917
|
+
u.onstart = () => {
|
|
2918
|
+
if (!started && !over) onState("playing");
|
|
2919
|
+
started = true;
|
|
2920
|
+
};
|
|
2921
|
+
u.onend = () => {
|
|
2922
|
+
if (i === pieces.length - 1) end();
|
|
2923
|
+
};
|
|
2924
|
+
u.onerror = (event) => {
|
|
2925
|
+
if (event.error === "interrupted" || event.error === "canceled") end();
|
|
2926
|
+
else end(new SpeechOutputError(event.error || "synthesis-failed"));
|
|
2927
|
+
};
|
|
2928
|
+
synth.speak(u);
|
|
2929
|
+
});
|
|
2930
|
+
onState("loading");
|
|
2931
|
+
return {
|
|
2932
|
+
pause: () => {
|
|
2933
|
+
if (over) return;
|
|
2934
|
+
synth.pause();
|
|
2935
|
+
onState("paused");
|
|
2936
|
+
},
|
|
2937
|
+
resume: () => {
|
|
2938
|
+
if (over) return;
|
|
2939
|
+
synth.resume();
|
|
2940
|
+
onState("playing");
|
|
2941
|
+
},
|
|
2942
|
+
stop: () => {
|
|
2943
|
+
if (over) return;
|
|
2944
|
+
synth.cancel();
|
|
2945
|
+
end();
|
|
2946
|
+
},
|
|
2947
|
+
done
|
|
2948
|
+
};
|
|
2949
|
+
};
|
|
2950
|
+
var silence = () => {
|
|
2951
|
+
const samples = 16;
|
|
2952
|
+
const view = new DataView(new ArrayBuffer(44 + samples * 2));
|
|
2953
|
+
const text = (at, s) => {
|
|
2954
|
+
for (let i = 0; i < s.length; i++) view.setUint8(at + i, s.charCodeAt(i));
|
|
2955
|
+
};
|
|
2956
|
+
text(0, "RIFF");
|
|
2957
|
+
view.setUint32(4, 36 + samples * 2, true);
|
|
2958
|
+
text(8, "WAVEfmt ");
|
|
2959
|
+
view.setUint32(16, 16, true);
|
|
2960
|
+
view.setUint16(20, 1, true);
|
|
2961
|
+
view.setUint16(22, 1, true);
|
|
2962
|
+
view.setUint32(24, 8e3, true);
|
|
2963
|
+
view.setUint32(28, 16e3, true);
|
|
2964
|
+
view.setUint16(32, 2, true);
|
|
2965
|
+
view.setUint16(34, 16, true);
|
|
2966
|
+
text(36, "data");
|
|
2967
|
+
view.setUint32(40, samples * 2, true);
|
|
2968
|
+
return new Blob([view.buffer], { type: "audio/wav" });
|
|
2969
|
+
};
|
|
2970
|
+
var createAudioSpeaker = (options) => (text, { lang, onState }) => {
|
|
2971
|
+
const urls = options.objectUrl ?? {
|
|
2972
|
+
create: (b) => URL.createObjectURL(b),
|
|
2973
|
+
revoke: (u) => URL.revokeObjectURL(u)
|
|
2974
|
+
};
|
|
2975
|
+
const audio = options.createAudio?.() ?? new Audio();
|
|
2976
|
+
const controller = new AbortController();
|
|
2977
|
+
const pieces = splitForSpeech(text, options.maxChars ?? 2e3);
|
|
2978
|
+
let settle;
|
|
2979
|
+
let fail;
|
|
2980
|
+
const done = new Promise((resolve, reject) => {
|
|
2981
|
+
settle = resolve;
|
|
2982
|
+
fail = reject;
|
|
2983
|
+
});
|
|
2984
|
+
done.catch(() => {
|
|
2985
|
+
});
|
|
2986
|
+
let over = false;
|
|
2987
|
+
let paused = false;
|
|
2988
|
+
let current;
|
|
2989
|
+
const made = /* @__PURE__ */ new Map();
|
|
2990
|
+
const make = (i) => {
|
|
2991
|
+
if (!made.has(i)) {
|
|
2992
|
+
const p = options.synthesize(pieces[i], { lang, signal: controller.signal });
|
|
2993
|
+
p.catch(() => {
|
|
2994
|
+
});
|
|
2995
|
+
made.set(i, p);
|
|
2996
|
+
}
|
|
2997
|
+
return made.get(i);
|
|
2998
|
+
};
|
|
2999
|
+
const release = () => {
|
|
3000
|
+
if (current) urls.revoke(current);
|
|
3001
|
+
current = void 0;
|
|
3002
|
+
};
|
|
3003
|
+
const end = (err) => {
|
|
3004
|
+
if (over) return;
|
|
3005
|
+
over = true;
|
|
3006
|
+
controller.abort();
|
|
3007
|
+
audio.pause();
|
|
3008
|
+
audio.onended = null;
|
|
3009
|
+
audio.onerror = null;
|
|
3010
|
+
release();
|
|
3011
|
+
if (err) fail(err);
|
|
3012
|
+
else settle();
|
|
3013
|
+
};
|
|
3014
|
+
const playFrom = async (i) => {
|
|
3015
|
+
if (over) return;
|
|
3016
|
+
if (i >= pieces.length) return end();
|
|
3017
|
+
onState(i === 0 || !current ? "loading" : "playing");
|
|
3018
|
+
let blob;
|
|
3019
|
+
try {
|
|
3020
|
+
blob = await make(i);
|
|
3021
|
+
} catch (err) {
|
|
3022
|
+
return end(err instanceof Error ? err : new Error(String(err)));
|
|
3023
|
+
}
|
|
3024
|
+
if (over) return;
|
|
3025
|
+
if (i + 1 < pieces.length) make(i + 1);
|
|
3026
|
+
release();
|
|
3027
|
+
current = urls.create(blob);
|
|
3028
|
+
audio.src = current;
|
|
3029
|
+
audio.onended = () => void playFrom(i + 1);
|
|
3030
|
+
audio.onerror = () => end(new SpeechOutputError("playback-failed"));
|
|
3031
|
+
if (paused) return onState("paused");
|
|
3032
|
+
try {
|
|
3033
|
+
await audio.play();
|
|
3034
|
+
if (!over) onState("playing");
|
|
3035
|
+
} catch (err) {
|
|
3036
|
+
end(asOutputError(err));
|
|
3037
|
+
}
|
|
3038
|
+
};
|
|
3039
|
+
if (pieces.length === 0) end();
|
|
3040
|
+
else {
|
|
3041
|
+
if (options.unlock !== false) {
|
|
3042
|
+
current = urls.create(silence());
|
|
3043
|
+
audio.src = current;
|
|
3044
|
+
audio.play().catch(() => {
|
|
3045
|
+
});
|
|
3046
|
+
}
|
|
3047
|
+
void playFrom(0);
|
|
3048
|
+
}
|
|
3049
|
+
return {
|
|
3050
|
+
pause: () => {
|
|
3051
|
+
if (over) return;
|
|
3052
|
+
paused = true;
|
|
3053
|
+
audio.pause();
|
|
3054
|
+
onState("paused");
|
|
3055
|
+
},
|
|
3056
|
+
resume: () => {
|
|
3057
|
+
if (over || !paused) return;
|
|
3058
|
+
paused = false;
|
|
3059
|
+
if (current)
|
|
3060
|
+
audio.play().then(
|
|
3061
|
+
() => !over && onState("playing"),
|
|
3062
|
+
(err) => end(asOutputError(err))
|
|
3063
|
+
);
|
|
3064
|
+
else onState("loading");
|
|
3065
|
+
},
|
|
3066
|
+
stop: () => end(),
|
|
3067
|
+
done
|
|
3068
|
+
};
|
|
3069
|
+
};
|
|
3070
|
+
|
|
2291
3071
|
// src/hooks/use-credentials.ts
|
|
2292
|
-
import { useCallback as
|
|
3072
|
+
import { useCallback as useCallback7, useEffect as useEffect8, useMemo as useMemo3, useState as useState8 } from "react";
|
|
2293
3073
|
import * as core5 from "@dudko.dev/agent-web";
|
|
2294
3074
|
import { VaultCredentialStore } from "@dudko.dev/agent-web";
|
|
2295
3075
|
var storeDbName = (store) => {
|
|
@@ -2297,10 +3077,10 @@ var storeDbName = (store) => {
|
|
|
2297
3077
|
return typeof name === "string" && name ? name : void 0;
|
|
2298
3078
|
};
|
|
2299
3079
|
var useCredentials = (store) => {
|
|
2300
|
-
const resolved =
|
|
2301
|
-
const [version, setVersion] =
|
|
3080
|
+
const resolved = useMemo3(() => store ?? new VaultCredentialStore(), [store]);
|
|
3081
|
+
const [version, setVersion] = useState8(0);
|
|
2302
3082
|
const dbName = storeDbName(resolved);
|
|
2303
|
-
|
|
3083
|
+
useEffect8(() => {
|
|
2304
3084
|
return followOtherTabs(
|
|
2305
3085
|
core5,
|
|
2306
3086
|
dbName,
|
|
@@ -2308,21 +3088,21 @@ var useCredentials = (store) => {
|
|
|
2308
3088
|
() => setVersion((v) => v + 1)
|
|
2309
3089
|
);
|
|
2310
3090
|
}, [dbName]);
|
|
2311
|
-
const setKey =
|
|
3091
|
+
const setKey = useCallback7(
|
|
2312
3092
|
async (ref, key) => {
|
|
2313
3093
|
await resolved.setApiKey(ref, key);
|
|
2314
3094
|
setVersion((v) => v + 1);
|
|
2315
3095
|
},
|
|
2316
3096
|
[resolved]
|
|
2317
3097
|
);
|
|
2318
|
-
const removeKey =
|
|
3098
|
+
const removeKey = useCallback7(
|
|
2319
3099
|
async (ref) => {
|
|
2320
3100
|
await resolved.deleteApiKey(ref);
|
|
2321
3101
|
setVersion((v) => v + 1);
|
|
2322
3102
|
},
|
|
2323
3103
|
[resolved]
|
|
2324
3104
|
);
|
|
2325
|
-
const hasKey =
|
|
3105
|
+
const hasKey = useCallback7(
|
|
2326
3106
|
async (ref) => await resolved.getApiKey(ref) !== void 0,
|
|
2327
3107
|
[resolved]
|
|
2328
3108
|
);
|
|
@@ -2339,21 +3119,21 @@ import {
|
|
|
2339
3119
|
} from "@dudko.dev/agent-web";
|
|
2340
3120
|
|
|
2341
3121
|
// src/hooks/use-local-model.ts
|
|
2342
|
-
import { useCallback as
|
|
3122
|
+
import { useCallback as useCallback8, useRef as useRef6, useState as useState9 } from "react";
|
|
2343
3123
|
var keyOf = (id, tokens) => tokens ? `${id}@${tokens}` : id;
|
|
2344
3124
|
var useLocalModel = (modelId, engine, options) => {
|
|
2345
|
-
const [loaded, setLoaded] =
|
|
2346
|
-
const [pending, setPending] =
|
|
2347
|
-
const [failure, setFailure] =
|
|
2348
|
-
const engineRef =
|
|
3125
|
+
const [loaded, setLoaded] = useState9(void 0);
|
|
3126
|
+
const [pending, setPending] = useState9();
|
|
3127
|
+
const [failure, setFailure] = useState9();
|
|
3128
|
+
const engineRef = useRef6(engine);
|
|
2349
3129
|
engineRef.current = engine;
|
|
2350
|
-
const loadedRef =
|
|
2351
|
-
const inflightRef =
|
|
3130
|
+
const loadedRef = useRef6(void 0);
|
|
3131
|
+
const inflightRef = useRef6(
|
|
2352
3132
|
void 0
|
|
2353
3133
|
);
|
|
2354
3134
|
const windowTokens = options?.contextWindowTokens;
|
|
2355
3135
|
const key = keyOf(modelId, windowTokens);
|
|
2356
|
-
const seqRef =
|
|
3136
|
+
const seqRef = useRef6(0);
|
|
2357
3137
|
const setHeld = (next) => {
|
|
2358
3138
|
loadedRef.current = next;
|
|
2359
3139
|
setLoaded(next);
|
|
@@ -2364,7 +3144,7 @@ var useLocalModel = (modelId, engine, options) => {
|
|
|
2364
3144
|
} catch {
|
|
2365
3145
|
}
|
|
2366
3146
|
};
|
|
2367
|
-
const load =
|
|
3147
|
+
const load = useCallback8(() => {
|
|
2368
3148
|
const id = modelId;
|
|
2369
3149
|
if (loadedRef.current?.key === key) return Promise.resolve(loadedRef.current.model);
|
|
2370
3150
|
if (inflightRef.current?.key === key) return inflightRef.current.promise;
|
|
@@ -2416,7 +3196,7 @@ var useLocalModel = (modelId, engine, options) => {
|
|
|
2416
3196
|
inflightRef.current = { key, promise };
|
|
2417
3197
|
return promise;
|
|
2418
3198
|
}, [modelId, key]);
|
|
2419
|
-
const unload =
|
|
3199
|
+
const unload = useCallback8(async () => {
|
|
2420
3200
|
seqRef.current++;
|
|
2421
3201
|
inflightRef.current = void 0;
|
|
2422
3202
|
setPending(void 0);
|
|
@@ -2478,7 +3258,7 @@ var createWebLLMEngine = (options) => {
|
|
|
2478
3258
|
};
|
|
2479
3259
|
|
|
2480
3260
|
// src/labels.tsx
|
|
2481
|
-
import { createContext, useContext, useMemo as
|
|
3261
|
+
import { createContext, useContext, useMemo as useMemo4 } from "react";
|
|
2482
3262
|
|
|
2483
3263
|
// src/composer.ts
|
|
2484
3264
|
var parseSlash = (text) => {
|
|
@@ -2513,7 +3293,8 @@ var attachmentKindOf = (mediaType, name) => {
|
|
|
2513
3293
|
};
|
|
2514
3294
|
var withAttachments = (text, files) => {
|
|
2515
3295
|
const texts = files.filter((f) => f.kind === "text" && f.text !== void 0);
|
|
2516
|
-
|
|
3296
|
+
const saved = files.filter((f) => f.kind !== "text" && f.path);
|
|
3297
|
+
if (texts.length === 0 && saved.length === 0) return text;
|
|
2517
3298
|
const blocks = texts.map((f) => {
|
|
2518
3299
|
const body = f.text;
|
|
2519
3300
|
const fence = body.includes("```") ? "~~~" : "```";
|
|
@@ -2523,10 +3304,46 @@ ${fence}
|
|
|
2523
3304
|
${body}
|
|
2524
3305
|
${fence}`;
|
|
2525
3306
|
});
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
3307
|
+
const kind = (f) => f.kind === "image" ? "picture" : f.kind === "pdf" ? "PDF" : "file";
|
|
3308
|
+
const lines = saved.map(
|
|
3309
|
+
(f) => `- ${kind(f)} "${f.name.replace(/["\s]+/g, " ").trim()}" (also saved as ${f.path})`
|
|
3310
|
+
);
|
|
3311
|
+
return [
|
|
3312
|
+
text,
|
|
3313
|
+
...blocks.length ? [`Attached file(s):
|
|
3314
|
+
${blocks.join("\n\n")}`] : [],
|
|
3315
|
+
...lines.length ? [`Also attached:
|
|
3316
|
+
${lines.join("\n")}`] : []
|
|
3317
|
+
].join("\n\n");
|
|
3318
|
+
};
|
|
3319
|
+
var ATTACHMENT_BOUNDS = {
|
|
3320
|
+
maxBytes: 20 * 1024 * 1024,
|
|
3321
|
+
// The largest JPEGs a phone writes (a 200 MP shot: ~20-40 MB) pass, and a long PDF with its
|
|
3322
|
+
// pictures; past this it is read into memory for nothing the model would get.
|
|
3323
|
+
maxSourceBytes: 50 * 1024 * 1024,
|
|
3324
|
+
// The largest phone sensor (200 MP: 16320 × 12240) passes, ~800 MB decoded; past this is a
|
|
3325
|
+
// scan, a render or a decompression bomb (a PNG of a few KB can declare 30000 × 30000 px).
|
|
3326
|
+
imageMaxSourcePixels: 2e8,
|
|
3327
|
+
// Under what the providers take in one request (Anthropic: 100 pictures, 32 MB; OpenAI: 50 MB).
|
|
3328
|
+
maxImages: 20,
|
|
3329
|
+
maxTotalBytes: 20 * 1024 * 1024
|
|
3330
|
+
};
|
|
3331
|
+
var attachmentTransformOf = (input) => input.converts ? "convert" : input.kind === "image" && input.imageMaxDimension !== false && input.mediaType !== "image/gif" && input.mediaType !== "image/svg+xml" ? "downscale" : "none";
|
|
3332
|
+
var attachmentOverLimit = (file, stage, transform, bounds) => {
|
|
3333
|
+
if (stage === "original" && transform !== "none") {
|
|
3334
|
+
const sourceBytes = Math.max(bounds.maxSourceBytes, bounds.maxBytes);
|
|
3335
|
+
if (file.bytes > sourceBytes) return { bound: "bytes", limit: sourceBytes };
|
|
3336
|
+
if (transform === "downscale" && file.pixels !== void 0 && file.pixels > bounds.imageMaxSourcePixels)
|
|
3337
|
+
return { bound: "pixels", limit: bounds.imageMaxSourcePixels };
|
|
3338
|
+
return void 0;
|
|
3339
|
+
}
|
|
3340
|
+
return file.bytes > bounds.maxBytes ? { bound: "bytes", limit: bounds.maxBytes } : void 0;
|
|
3341
|
+
};
|
|
3342
|
+
var messageOverLimit = (inMessage, next, bounds) => {
|
|
3343
|
+
if (next.kind === "image" && inMessage.filter((a) => a.kind === "image").length >= bounds.maxImages)
|
|
3344
|
+
return "images";
|
|
3345
|
+
const total = inMessage.reduce((n, a) => n + a.bytes, 0);
|
|
3346
|
+
return total + next.bytes > bounds.maxTotalBytes ? "bytes" : void 0;
|
|
2530
3347
|
};
|
|
2531
3348
|
var attachmentRefusal = (kind, caps, canConvertPdf = false) => {
|
|
2532
3349
|
if (kind === "text" || !caps) return void 0;
|
|
@@ -2607,6 +3424,27 @@ var noticesOf = (state, texts = {}) => {
|
|
|
2607
3424
|
}
|
|
2608
3425
|
return out;
|
|
2609
3426
|
};
|
|
3427
|
+
var formatClock = (ms) => {
|
|
3428
|
+
const s = Math.max(0, Math.floor(ms / 1e3));
|
|
3429
|
+
const two = (n) => String(n).padStart(2, "0");
|
|
3430
|
+
const h = Math.floor(s / 3600);
|
|
3431
|
+
const m = Math.floor(s % 3600 / 60);
|
|
3432
|
+
return h > 0 ? `${h}:${two(m)}:${two(s % 60)}` : `${m}:${two(s % 60)}`;
|
|
3433
|
+
};
|
|
3434
|
+
var micProblemText = (code, message, labels) => {
|
|
3435
|
+
if (code === "not-allowed" || code === "service-not-allowed") return labels.micDenied;
|
|
3436
|
+
if (code === "audio-capture") return labels.micMissing;
|
|
3437
|
+
if (code === "busy") return labels.micBusy;
|
|
3438
|
+
if (code === "unsupported") return labels.micUnsupported;
|
|
3439
|
+
if (message) return message;
|
|
3440
|
+
return code && code !== "transcription" && code !== "failed" ? `${labels.dictationFailed} (${code})` : labels.dictationFailed;
|
|
3441
|
+
};
|
|
3442
|
+
var voiceMessageName = (at, extension) => {
|
|
3443
|
+
const two = (n) => String(n).padStart(2, "0");
|
|
3444
|
+
return `voice-${at.getFullYear()}-${two(at.getMonth() + 1)}-${two(at.getDate())}-${two(
|
|
3445
|
+
at.getHours()
|
|
3446
|
+
)}${two(at.getMinutes())}${two(at.getSeconds())}.${extension}`;
|
|
3447
|
+
};
|
|
2610
3448
|
|
|
2611
3449
|
// src/labels.tsx
|
|
2612
3450
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -2663,6 +3501,19 @@ var defaultLabels = {
|
|
|
2663
3501
|
dictateTitle: "Dictate \u2014 speech to text in the browser",
|
|
2664
3502
|
stopDictation: "Stop dictation",
|
|
2665
3503
|
microphone: "Microphone",
|
|
3504
|
+
transcribing: "Transcribing\u2026",
|
|
3505
|
+
micDenied: "The microphone is blocked for this site. Allow it in the browser's site settings (the icon beside the address), then try again.",
|
|
3506
|
+
micMissing: "No microphone was found on this device.",
|
|
3507
|
+
micBusy: "The microphone is in use by another app.",
|
|
3508
|
+
micUnsupported: "This browser cannot record audio on this page.",
|
|
3509
|
+
dictationFailed: "Dictation did not work.",
|
|
3510
|
+
recordVoiceMessage: "Record a voice message",
|
|
3511
|
+
voiceMessage: "Voice message",
|
|
3512
|
+
audioDuration: (clock) => clock,
|
|
3513
|
+
recording: (elapsed) => `Recording ${elapsed}`,
|
|
3514
|
+
recordingDone: "Attach the recording",
|
|
3515
|
+
recordingCancel: "Discard the recording",
|
|
3516
|
+
recordingLimit: "The recording reached its longest and was stopped; it is attached.",
|
|
2666
3517
|
model: "Model",
|
|
2667
3518
|
thinking: "Thinking",
|
|
2668
3519
|
toolConsent: "Tool consent",
|
|
@@ -2686,7 +3537,12 @@ var defaultLabels = {
|
|
|
2686
3537
|
attachmentsOnly: "(attachments)",
|
|
2687
3538
|
seeAttachments: "See the attachments.",
|
|
2688
3539
|
tooLarge: (name, mb) => `${name} is larger than ${mb} MB.`,
|
|
3540
|
+
tooManyPixels: (name, megapixels) => `${name} has more than ${megapixels} megapixels \u2014 too large a picture to attach.`,
|
|
2689
3541
|
binaryText: (name) => `${name} looks binary \u2014 it can't be attached as text.`,
|
|
3542
|
+
downscaledFrom: (size) => `downscaled from ${size}`,
|
|
3543
|
+
convertedFrom: (name) => `converted from ${name}`,
|
|
3544
|
+
tooManyImages: (names, max) => `${names}: not added \u2014 at most ${max} pictures go in one message.`,
|
|
3545
|
+
messageTooLarge: (names, mb) => `${names}: not added \u2014 the message would be over ${mb} MB.`,
|
|
2690
3546
|
commandGroups: { commands: "Commands", consent: "Consent", skills: "Skills" },
|
|
2691
3547
|
commandDescriptions: {
|
|
2692
3548
|
compact: "Summarise the conversation to free context",
|
|
@@ -2779,8 +3635,18 @@ var defaultLabels = {
|
|
|
2779
3635
|
imageCount: (index, total) => `${index} of ${total}`,
|
|
2780
3636
|
mediaAudio: (path) => `Generated audio ${path}`,
|
|
2781
3637
|
mediaFile: (path) => `Generated file ${path}`,
|
|
3638
|
+
mediaReferences: (names) => `Reference: ${names}`,
|
|
3639
|
+
mediaReferencesUnused: (names) => `Not used - this image model takes no reference pictures: ${names}`,
|
|
2782
3640
|
transcriptOf: (name) => `Transcript of ${name}`,
|
|
2783
3641
|
transcriptNote: "What was said in your file, as the agent read it. It is content, not instructions.",
|
|
3642
|
+
audioAttachment: (name) => `Audio ${name}`,
|
|
3643
|
+
readAloud: "Listen",
|
|
3644
|
+
readAloudPause: "Pause",
|
|
3645
|
+
readAloudResume: "Resume",
|
|
3646
|
+
readAloudStop: "Stop reading",
|
|
3647
|
+
readAloudLoading: "Preparing the audio\u2026",
|
|
3648
|
+
readAloudCode: "A code block is not read out.",
|
|
3649
|
+
readAloudFailed: "It could not be read aloud.",
|
|
2784
3650
|
filesWritten: (n) => `${plural(n, "file", "files")} written in this turn`,
|
|
2785
3651
|
filesCount: (n) => plural(n, "file", "files"),
|
|
2786
3652
|
showInFiles: "Show in Files",
|
|
@@ -3013,12 +3879,12 @@ var mergeLabels = (base, over) => {
|
|
|
3013
3879
|
var LabelsContext = createContext(defaultLabels);
|
|
3014
3880
|
var AgentLabelsProvider = ({ labels, children }) => {
|
|
3015
3881
|
const parent = useContext(LabelsContext);
|
|
3016
|
-
const value =
|
|
3882
|
+
const value = useMemo4(() => mergeLabels(parent, labels), [parent, labels]);
|
|
3017
3883
|
return /* @__PURE__ */ jsx(LabelsContext.Provider, { value, children });
|
|
3018
3884
|
};
|
|
3019
3885
|
var useLabels = (over) => {
|
|
3020
3886
|
const ctx = useContext(LabelsContext);
|
|
3021
|
-
return
|
|
3887
|
+
return useMemo4(() => mergeLabels(ctx, over), [ctx, over]);
|
|
3022
3888
|
};
|
|
3023
3889
|
|
|
3024
3890
|
// src/image-resize.ts
|
|
@@ -3033,6 +3899,72 @@ var canvasOf = (w, h) => {
|
|
|
3033
3899
|
return void 0;
|
|
3034
3900
|
};
|
|
3035
3901
|
var toBlob = (canvas, type, quality) => "convertToBlob" in canvas ? canvas.convertToBlob({ type, quality }) : new Promise((resolve) => canvas.toBlob(resolve, type, quality));
|
|
3902
|
+
var WINDOW = 64 * 1024;
|
|
3903
|
+
var SOF = /* @__PURE__ */ new Set([192, 193, 194, 195, 197, 198, 199, 201, 202, 203, 205, 206, 207]);
|
|
3904
|
+
var imageSizeOf = async (file) => {
|
|
3905
|
+
let at = 0;
|
|
3906
|
+
let buf = new Uint8Array(0);
|
|
3907
|
+
const read = async (start, length) => {
|
|
3908
|
+
if (start < 0 || start + length > file.size) return void 0;
|
|
3909
|
+
if (start < at || start + length > at + buf.length) {
|
|
3910
|
+
at = start;
|
|
3911
|
+
buf = new Uint8Array(
|
|
3912
|
+
await file.slice(start, Math.min(file.size, start + Math.max(WINDOW, length))).arrayBuffer()
|
|
3913
|
+
);
|
|
3914
|
+
}
|
|
3915
|
+
return buf.subarray(start - at, start - at + length);
|
|
3916
|
+
};
|
|
3917
|
+
const sized = (width, height) => width > 0 && height > 0 ? { width, height } : void 0;
|
|
3918
|
+
try {
|
|
3919
|
+
const head = await read(0, 30);
|
|
3920
|
+
if (!head) return void 0;
|
|
3921
|
+
const u16be = (b, i) => b[i] << 8 | b[i + 1];
|
|
3922
|
+
const u32be = (b, i) => u16be(b, i) * 65536 + u16be(b, i + 2);
|
|
3923
|
+
const ascii = (b, i, n) => String.fromCharCode(...Array.from(b.subarray(i, i + n)));
|
|
3924
|
+
if (ascii(head, 1, 3) === "PNG" && head[0] === 137 && ascii(head, 12, 4) === "IHDR")
|
|
3925
|
+
return sized(u32be(head, 16), u32be(head, 20));
|
|
3926
|
+
if (ascii(head, 0, 4) === "RIFF" && ascii(head, 8, 4) === "WEBP") {
|
|
3927
|
+
const chunk = ascii(head, 12, 4);
|
|
3928
|
+
const u16le = (i) => head[i] | head[i + 1] << 8;
|
|
3929
|
+
const u24le = (i) => u16le(i) | head[i + 2] << 16;
|
|
3930
|
+
if (chunk === "VP8X") return sized(u24le(24) + 1, u24le(27) + 1);
|
|
3931
|
+
if (chunk === "VP8L" && head[20] === 47) {
|
|
3932
|
+
const bits = (u16le(21) | u16le(23) << 16) >>> 0;
|
|
3933
|
+
return sized((bits & 16383) + 1, (bits >>> 14 & 16383) + 1);
|
|
3934
|
+
}
|
|
3935
|
+
if (chunk === "VP8 " && head[23] === 157 && head[24] === 1 && head[25] === 42)
|
|
3936
|
+
return sized(u16le(26) & 16383, u16le(28) & 16383);
|
|
3937
|
+
return void 0;
|
|
3938
|
+
}
|
|
3939
|
+
if (head[0] === 255 && head[1] === 216) {
|
|
3940
|
+
let p = 2;
|
|
3941
|
+
for (let segments = 0; segments < 4096; segments++) {
|
|
3942
|
+
const m = await read(p, 4);
|
|
3943
|
+
if (!m || m[0] !== 255) return void 0;
|
|
3944
|
+
const marker = m[1];
|
|
3945
|
+
if (marker === 255) {
|
|
3946
|
+
p += 1;
|
|
3947
|
+
continue;
|
|
3948
|
+
}
|
|
3949
|
+
if (marker === 1 || marker >= 208 && marker <= 216) {
|
|
3950
|
+
p += 2;
|
|
3951
|
+
continue;
|
|
3952
|
+
}
|
|
3953
|
+
if (marker === 217 || marker === 218) return void 0;
|
|
3954
|
+
const length = u16be(m, 2);
|
|
3955
|
+
if (length < 2) return void 0;
|
|
3956
|
+
if (SOF.has(marker)) {
|
|
3957
|
+
const frame = await read(p + 4, 5);
|
|
3958
|
+
return frame ? sized(u16be(frame, 3), u16be(frame, 1)) : void 0;
|
|
3959
|
+
}
|
|
3960
|
+
p += 2 + length;
|
|
3961
|
+
}
|
|
3962
|
+
}
|
|
3963
|
+
return void 0;
|
|
3964
|
+
} catch {
|
|
3965
|
+
return void 0;
|
|
3966
|
+
}
|
|
3967
|
+
};
|
|
3036
3968
|
var downscaleImage = async (file, opts = {}) => {
|
|
3037
3969
|
const maxDimension = opts.maxDimension ?? 1568;
|
|
3038
3970
|
const maxPixels = opts.maxPixels ?? 115e4;
|
|
@@ -3086,11 +4018,11 @@ var useAgentContext = () => {
|
|
|
3086
4018
|
var useOptionalAgentContext = () => useContext2(AgentContext);
|
|
3087
4019
|
|
|
3088
4020
|
// src/components/AgentChat.tsx
|
|
3089
|
-
import { useEffect as
|
|
4021
|
+
import { useEffect as useEffect20, useRef as useRef14, useState as useState20 } from "react";
|
|
3090
4022
|
import { createPortal as createPortal2 } from "react-dom";
|
|
3091
4023
|
|
|
3092
4024
|
// src/hooks/use-follow-scroll.ts
|
|
3093
|
-
import { useEffect as
|
|
4025
|
+
import { useEffect as useEffect9, useLayoutEffect, useRef as useRef7 } from "react";
|
|
3094
4026
|
|
|
3095
4027
|
// src/follow-scroll.ts
|
|
3096
4028
|
var FOLLOW_REJOIN_PX = 80;
|
|
@@ -3107,7 +4039,7 @@ var followsAfterScroll = (following, before, now) => {
|
|
|
3107
4039
|
var followsAfterResize = (following, before, now) => following && !(now.clientHeight === before.clientHeight && now.scrollHeight >= before.scrollHeight && now.scrollTop < reach(before) - FOLLOW_LEAVE_PX);
|
|
3108
4040
|
|
|
3109
4041
|
// src/hooks/use-follow-scroll.ts
|
|
3110
|
-
var useIsoLayoutEffect = typeof window === "undefined" ?
|
|
4042
|
+
var useIsoLayoutEffect = typeof window === "undefined" ? useEffect9 : useLayoutEffect;
|
|
3111
4043
|
var measure = (el) => ({
|
|
3112
4044
|
scrollTop: el.scrollTop,
|
|
3113
4045
|
scrollHeight: el.scrollHeight,
|
|
@@ -3129,12 +4061,12 @@ var anchorOf = (el) => {
|
|
|
3129
4061
|
return marks.length ? { marks, top: el.scrollTop } : void 0;
|
|
3130
4062
|
};
|
|
3131
4063
|
var useFollowScroll = (ref, turn, live = true) => {
|
|
3132
|
-
const following =
|
|
3133
|
-
const last =
|
|
3134
|
-
const anchor =
|
|
3135
|
-
const settle =
|
|
4064
|
+
const following = useRef7(true);
|
|
4065
|
+
const last = useRef7(void 0);
|
|
4066
|
+
const anchor = useRef7(void 0);
|
|
4067
|
+
const settle = useRef7(() => {
|
|
3136
4068
|
});
|
|
3137
|
-
const arriving =
|
|
4069
|
+
const arriving = useRef7(live);
|
|
3138
4070
|
arriving.current = live;
|
|
3139
4071
|
useIsoLayoutEffect(() => {
|
|
3140
4072
|
const el = ref.current;
|
|
@@ -3207,7 +4139,7 @@ var useFollowScroll = (ref, turn, live = true) => {
|
|
|
3207
4139
|
};
|
|
3208
4140
|
|
|
3209
4141
|
// src/hooks/use-mcp-app-host.ts
|
|
3210
|
-
import { useCallback as
|
|
4142
|
+
import { useCallback as useCallback9, useEffect as useEffect10, useMemo as useMemo5, useRef as useRef8, useState as useState10 } from "react";
|
|
3211
4143
|
|
|
3212
4144
|
// src/mcp-app.ts
|
|
3213
4145
|
import { mcpAppOrigin } from "@dudko.dev/agent-web";
|
|
@@ -4034,27 +4966,27 @@ var useMcpAppHost = ({
|
|
|
4034
4966
|
sampling = false,
|
|
4035
4967
|
sample: sampleFn
|
|
4036
4968
|
}) => {
|
|
4037
|
-
const [requests, setRequests] =
|
|
4038
|
-
const [draft, setDraft] =
|
|
4039
|
-
const waiting =
|
|
4969
|
+
const [requests, setRequests] = useState10([]);
|
|
4970
|
+
const [draft, setDraft] = useState10();
|
|
4971
|
+
const waiting = useRef8(
|
|
4040
4972
|
/* @__PURE__ */ new Map()
|
|
4041
4973
|
);
|
|
4042
|
-
const samplingAllowed =
|
|
4043
|
-
const sampleRef =
|
|
4974
|
+
const samplingAllowed = useRef8(/* @__PURE__ */ new Set());
|
|
4975
|
+
const sampleRef = useRef8(sampleFn);
|
|
4044
4976
|
sampleRef.current = sampleFn;
|
|
4045
|
-
const [gated, setGated] =
|
|
4046
|
-
const connectionRef =
|
|
4977
|
+
const [gated, setGated] = useState10({});
|
|
4978
|
+
const connectionRef = useRef8(connection);
|
|
4047
4979
|
connectionRef.current = connection;
|
|
4048
|
-
const approveRef =
|
|
4980
|
+
const approveRef = useRef8(approve);
|
|
4049
4981
|
approveRef.current = approve;
|
|
4050
|
-
|
|
4982
|
+
useEffect10(
|
|
4051
4983
|
() => () => {
|
|
4052
4984
|
for (const { resolve } of waiting.current.values()) resolve(false);
|
|
4053
4985
|
waiting.current.clear();
|
|
4054
4986
|
},
|
|
4055
4987
|
[]
|
|
4056
4988
|
);
|
|
4057
|
-
const ask =
|
|
4989
|
+
const ask = useCallback9(
|
|
4058
4990
|
(request, signal, extra = {}) => {
|
|
4059
4991
|
for (const w of waiting.current.values()) {
|
|
4060
4992
|
if (w.request.appId === request.appId) {
|
|
@@ -4079,7 +5011,7 @@ var useMcpAppHost = ({
|
|
|
4079
5011
|
},
|
|
4080
5012
|
[]
|
|
4081
5013
|
);
|
|
4082
|
-
const answer =
|
|
5014
|
+
const answer = useCallback9((id, accept, options) => {
|
|
4083
5015
|
const w = waiting.current.get(id);
|
|
4084
5016
|
if (!w) return;
|
|
4085
5017
|
if (accept && w.request.kind === "link" && w.request.link) {
|
|
@@ -4105,16 +5037,16 @@ var useMcpAppHost = ({
|
|
|
4105
5037
|
}
|
|
4106
5038
|
w.resolve(accept);
|
|
4107
5039
|
}, []);
|
|
4108
|
-
const read =
|
|
5040
|
+
const read = useCallback9((app, signal) => {
|
|
4109
5041
|
const c = connectionRef.current;
|
|
4110
5042
|
if (!c) return Promise.reject(new Error(`no connection to the server \u201C${app.server}\u201D`));
|
|
4111
5043
|
return c.readUiResource(app.server, app.resourceUri, signal ? { signal } : void 0);
|
|
4112
5044
|
}, []);
|
|
4113
|
-
const tool =
|
|
5045
|
+
const tool = useCallback9(
|
|
4114
5046
|
(app) => connectionRef.current?.appTool(app.server, app.toolName),
|
|
4115
5047
|
[]
|
|
4116
5048
|
);
|
|
4117
|
-
const callTool =
|
|
5049
|
+
const callTool = useCallback9(
|
|
4118
5050
|
async (app, name, args, signal) => {
|
|
4119
5051
|
const c = connectionRef.current;
|
|
4120
5052
|
if (!c) throw refused(`The server \u201C${app.server}\u201D is not connected`);
|
|
@@ -4151,15 +5083,15 @@ var useMcpAppHost = ({
|
|
|
4151
5083
|
},
|
|
4152
5084
|
[]
|
|
4153
5085
|
);
|
|
4154
|
-
const openLink =
|
|
5086
|
+
const openLink = useCallback9(
|
|
4155
5087
|
(app, link, signal) => ask({ appId: app.id, server: app.server, kind: "link", link }, signal),
|
|
4156
5088
|
[ask]
|
|
4157
5089
|
);
|
|
4158
|
-
const message =
|
|
5090
|
+
const message = useCallback9(
|
|
4159
5091
|
(app, text, signal) => ask({ appId: app.id, server: app.server, kind: "message", text }, signal),
|
|
4160
5092
|
[ask]
|
|
4161
5093
|
);
|
|
4162
|
-
const downloadFile2 =
|
|
5094
|
+
const downloadFile2 = useCallback9(
|
|
4163
5095
|
async (app, file, signal) => {
|
|
4164
5096
|
const c = connectionRef.current;
|
|
4165
5097
|
if (file.kind === "link" && !c) throw refused(`The server \u201C${app.server}\u201D is not connected`);
|
|
@@ -4182,7 +5114,7 @@ var useMcpAppHost = ({
|
|
|
4182
5114
|
},
|
|
4183
5115
|
[ask]
|
|
4184
5116
|
);
|
|
4185
|
-
const sample =
|
|
5117
|
+
const sample = useCallback9(
|
|
4186
5118
|
async (app, params, signal) => {
|
|
4187
5119
|
const fn = sampleRef.current;
|
|
4188
5120
|
if (!fn) throw refused("This host cannot answer sampling requests");
|
|
@@ -4203,19 +5135,19 @@ var useMcpAppHost = ({
|
|
|
4203
5135
|
},
|
|
4204
5136
|
[ask]
|
|
4205
5137
|
);
|
|
4206
|
-
const pendingAppServers =
|
|
5138
|
+
const pendingAppServers = useMemo5(
|
|
4207
5139
|
() => new Set(
|
|
4208
5140
|
approvals.filter((a) => a.app && a.status === "pending").map((a) => `${a.app.server}\0${a.app.resourceUri}`)
|
|
4209
5141
|
),
|
|
4210
5142
|
[approvals]
|
|
4211
5143
|
);
|
|
4212
|
-
const isWaiting =
|
|
5144
|
+
const isWaiting = useCallback9(
|
|
4213
5145
|
(app) => requests.some((r) => r.appId === app.id) || Boolean(gated[app.id]) && pendingAppServers.has(`${app.server}\0${app.resourceUri}`),
|
|
4214
5146
|
[requests, gated, pendingAppServers]
|
|
4215
5147
|
);
|
|
4216
5148
|
const sandboxUrl = sandbox?.url;
|
|
4217
5149
|
const sandboxTimeout = sandbox?.timeoutMs;
|
|
4218
|
-
const sandboxSetting =
|
|
5150
|
+
const sandboxSetting = useMemo5(
|
|
4219
5151
|
() => sandboxUrl === void 0 ? void 0 : {
|
|
4220
5152
|
url: sandboxUrl,
|
|
4221
5153
|
...sandboxTimeout !== void 0 ? { timeoutMs: sandboxTimeout } : {}
|
|
@@ -4223,7 +5155,7 @@ var useMcpAppHost = ({
|
|
|
4223
5155
|
[sandboxUrl, sandboxTimeout]
|
|
4224
5156
|
);
|
|
4225
5157
|
const samplingOn = sampling && Boolean(sampleFn);
|
|
4226
|
-
return
|
|
5158
|
+
return useMemo5(
|
|
4227
5159
|
() => ({
|
|
4228
5160
|
connected: Boolean(connection),
|
|
4229
5161
|
read,
|
|
@@ -4378,11 +5310,11 @@ var AppRequestPrompt = ({
|
|
|
4378
5310
|
};
|
|
4379
5311
|
|
|
4380
5312
|
// src/components/McpAppFrame.tsx
|
|
4381
|
-
import { useEffect as
|
|
5313
|
+
import { useEffect as useEffect11, useLayoutEffect as useLayoutEffect2, useMemo as useMemo6, useRef as useRef9, useState as useState11 } from "react";
|
|
4382
5314
|
import { Fragment, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
4383
5315
|
var HOST_INFO = { name: "@dudko.dev/agent-web-react", version: "1" };
|
|
4384
5316
|
var MAX_LISTED_CALLS = 12;
|
|
4385
|
-
var useIsoLayoutEffect2 = typeof window === "undefined" ?
|
|
5317
|
+
var useIsoLayoutEffect2 = typeof window === "undefined" ? useEffect11 : useLayoutEffect2;
|
|
4386
5318
|
var userActivation = () => typeof navigator === "undefined" ? void 0 : navigator.userActivation?.isActive;
|
|
4387
5319
|
var silentSandboxes = /* @__PURE__ */ new Set();
|
|
4388
5320
|
var warned = /* @__PURE__ */ new Set();
|
|
@@ -4415,36 +5347,36 @@ var McpAppFrame = ({
|
|
|
4415
5347
|
className
|
|
4416
5348
|
}) => {
|
|
4417
5349
|
const L = useLabels(labels);
|
|
4418
|
-
const [collapsed, setCollapsed] =
|
|
4419
|
-
const [menu, setMenu] =
|
|
4420
|
-
const [reload, setReload] =
|
|
4421
|
-
const [loaded, setLoaded] =
|
|
4422
|
-
const [height, setHeight] =
|
|
4423
|
-
const [calls, setCalls] =
|
|
4424
|
-
const [fallback, setFallback] =
|
|
4425
|
-
const [broken, setBroken] =
|
|
4426
|
-
const [onOrigin, setOnOrigin] =
|
|
4427
|
-
const shellLoaded =
|
|
4428
|
-
const [mode, setMode] =
|
|
4429
|
-
const modeRef =
|
|
4430
|
-
const [holder, setHolder] =
|
|
4431
|
-
const [fullRect, setFullRect] =
|
|
4432
|
-
const leaveRef =
|
|
4433
|
-
const rootRef =
|
|
4434
|
-
const exitRef =
|
|
4435
|
-
const allowFullscreenRef =
|
|
5350
|
+
const [collapsed, setCollapsed] = useState11(defaultCollapsed);
|
|
5351
|
+
const [menu, setMenu] = useState11(false);
|
|
5352
|
+
const [reload, setReload] = useState11(0);
|
|
5353
|
+
const [loaded, setLoaded] = useState11();
|
|
5354
|
+
const [height, setHeight] = useState11(APP_DEFAULT_HEIGHT);
|
|
5355
|
+
const [calls, setCalls] = useState11([]);
|
|
5356
|
+
const [fallback, setFallback] = useState11();
|
|
5357
|
+
const [broken, setBroken] = useState11(false);
|
|
5358
|
+
const [onOrigin, setOnOrigin] = useState11(false);
|
|
5359
|
+
const shellLoaded = useRef9(void 0);
|
|
5360
|
+
const [mode, setMode] = useState11("inline");
|
|
5361
|
+
const modeRef = useRef9("inline");
|
|
5362
|
+
const [holder, setHolder] = useState11(0);
|
|
5363
|
+
const [fullRect, setFullRect] = useState11();
|
|
5364
|
+
const leaveRef = useRef9(void 0);
|
|
5365
|
+
const rootRef = useRef9(null);
|
|
5366
|
+
const exitRef = useRef9(null);
|
|
5367
|
+
const allowFullscreenRef = useRef9(allowFullscreen);
|
|
4436
5368
|
allowFullscreenRef.current = allowFullscreen;
|
|
4437
|
-
const iframeRef =
|
|
4438
|
-
const bridgeRef =
|
|
4439
|
-
const menuRef =
|
|
4440
|
-
const themeRef =
|
|
5369
|
+
const iframeRef = useRef9(null);
|
|
5370
|
+
const bridgeRef = useRef9(void 0);
|
|
5371
|
+
const menuRef = useRef9(null);
|
|
5372
|
+
const themeRef = useRef9(theme);
|
|
4441
5373
|
themeRef.current = theme;
|
|
4442
|
-
const hostRef =
|
|
5374
|
+
const hostRef = useRef9(host);
|
|
4443
5375
|
hostRef.current = host;
|
|
4444
|
-
const appRef =
|
|
5376
|
+
const appRef = useRef9(app);
|
|
4445
5377
|
appRef.current = app;
|
|
4446
5378
|
const live = !collapsed;
|
|
4447
|
-
|
|
5379
|
+
useEffect11(() => {
|
|
4448
5380
|
if (!live) return;
|
|
4449
5381
|
if (!hostRef.current.connected) {
|
|
4450
5382
|
setLoaded({ unavailable: true });
|
|
@@ -4467,7 +5399,7 @@ var McpAppFrame = ({
|
|
|
4467
5399
|
const resource = loaded && "resource" in loaded ? loaded.resource : void 0;
|
|
4468
5400
|
const sandboxUrl = host.sandbox?.url;
|
|
4469
5401
|
const timeoutMs = host.sandbox?.timeoutMs ?? MCP_APP_SANDBOX_TIMEOUT_MS;
|
|
4470
|
-
const placement =
|
|
5402
|
+
const placement = useMemo6(() => {
|
|
4471
5403
|
if (!resource) return void 0;
|
|
4472
5404
|
if (sandboxUrl === void 0) return { mode: "opaque" };
|
|
4473
5405
|
if (fallback) return { mode: "opaque", reason: fallback };
|
|
@@ -4478,11 +5410,11 @@ var McpAppFrame = ({
|
|
|
4478
5410
|
if (!url) return { mode: "opaque", reason: "too-many-origins" };
|
|
4479
5411
|
return { mode: "origin", origin: target.origin, url };
|
|
4480
5412
|
}, [resource, sandboxUrl, fallback, app.server, reload]);
|
|
4481
|
-
const doc =
|
|
5413
|
+
const doc = useMemo6(
|
|
4482
5414
|
() => !resource || !placement ? void 0 : placement.mode === "origin" ? buildMcpAppSandboxShell(placement.url) : buildMcpAppDocument(resource.html, resource.csp),
|
|
4483
5415
|
[resource, placement]
|
|
4484
5416
|
);
|
|
4485
|
-
|
|
5417
|
+
useEffect11(() => {
|
|
4486
5418
|
const reason = placement?.mode === "opaque" ? placement.reason : void 0;
|
|
4487
5419
|
if (reason && reason !== "no-answer" && sandboxUrl !== void 0) {
|
|
4488
5420
|
warnOnce(
|
|
@@ -4491,7 +5423,7 @@ var McpAppFrame = ({
|
|
|
4491
5423
|
);
|
|
4492
5424
|
}
|
|
4493
5425
|
}, [placement, sandboxUrl]);
|
|
4494
|
-
|
|
5426
|
+
useEffect11(() => {
|
|
4495
5427
|
const frame = iframeRef.current;
|
|
4496
5428
|
if (!live || !resource || !frame || !placement || broken) return;
|
|
4497
5429
|
const abort = new AbortController();
|
|
@@ -4636,7 +5568,7 @@ var McpAppFrame = ({
|
|
|
4636
5568
|
}, [live, resource, reload, variant, app.id, placement, broken, timeoutMs]);
|
|
4637
5569
|
const fullscreen = mode === "fullscreen" && live && !broken;
|
|
4638
5570
|
const waitingNow = host.isWaiting(app);
|
|
4639
|
-
|
|
5571
|
+
useEffect11(() => {
|
|
4640
5572
|
if (fullscreen && waitingNow) leaveRef.current?.();
|
|
4641
5573
|
}, [fullscreen, waitingNow]);
|
|
4642
5574
|
useIsoLayoutEffect2(() => {
|
|
@@ -4671,7 +5603,7 @@ var McpAppFrame = ({
|
|
|
4671
5603
|
ro?.disconnect();
|
|
4672
5604
|
};
|
|
4673
5605
|
}, [fullscreen]);
|
|
4674
|
-
|
|
5606
|
+
useEffect11(() => {
|
|
4675
5607
|
if (!fullscreen) return;
|
|
4676
5608
|
const before = document.activeElement;
|
|
4677
5609
|
exitRef.current?.focus();
|
|
@@ -4688,10 +5620,10 @@ var McpAppFrame = ({
|
|
|
4688
5620
|
if (frame && (before === frame || document.activeElement === document.body)) frame.focus();
|
|
4689
5621
|
};
|
|
4690
5622
|
}, [fullscreen]);
|
|
4691
|
-
|
|
5623
|
+
useEffect11(() => {
|
|
4692
5624
|
if (theme) bridgeRef.current?.updateContext({ theme });
|
|
4693
5625
|
}, [theme]);
|
|
4694
|
-
|
|
5626
|
+
useEffect11(() => {
|
|
4695
5627
|
if (!menu) return;
|
|
4696
5628
|
const close = (e) => {
|
|
4697
5629
|
if (e instanceof KeyboardEvent ? e.key === "Escape" : !menuRef.current?.contains(e.target)) {
|
|
@@ -4996,7 +5928,7 @@ var McpAppLine = ({ app, note, action, onAction, labels, className }) => {
|
|
|
4996
5928
|
};
|
|
4997
5929
|
|
|
4998
5930
|
// src/components/AgentComposer.tsx
|
|
4999
|
-
import { Fragment as Fragment2, useEffect as
|
|
5931
|
+
import { Fragment as Fragment2, useEffect as useEffect12, useLayoutEffect as useLayoutEffect3, useMemo as useMemo7, useRef as useRef10, useState as useState12 } from "react";
|
|
5000
5932
|
import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
5001
5933
|
var thinkingDefaults = (l) => [
|
|
5002
5934
|
{ id: "off", label: l.thinkingLevels.off },
|
|
@@ -5008,7 +5940,7 @@ var thinkingDefaults = (l) => [
|
|
|
5008
5940
|
var MODES = ["autopilot", "ask-writes", "ask-all", "read-only"];
|
|
5009
5941
|
var ModeIcon = ({ mode }) => mode === "autopilot" ? /* @__PURE__ */ jsx5(BoltIcon, { size: 14 }) : mode === "read-only" ? /* @__PURE__ */ jsx5(EyeIcon, { size: 14 }) : /* @__PURE__ */ jsx5(ShieldIcon, { size: 14 });
|
|
5010
5942
|
var useMenuKeys = (open, menuRef, chipRef, close) => {
|
|
5011
|
-
|
|
5943
|
+
useEffect12(() => {
|
|
5012
5944
|
if (!open) return;
|
|
5013
5945
|
const menu = menuRef.current;
|
|
5014
5946
|
const rows = menu ? [...menu.querySelectorAll('[role^="menuitem"]')] : [];
|
|
@@ -5036,9 +5968,9 @@ var useMenuKeys = (open, menuRef, chipRef, close) => {
|
|
|
5036
5968
|
};
|
|
5037
5969
|
var opensMenu = (key) => key === "ArrowDown" || key === "ArrowUp";
|
|
5038
5970
|
var attachSeq = 0;
|
|
5039
|
-
var useIsoLayoutEffect3 = typeof window === "undefined" ?
|
|
5971
|
+
var useIsoLayoutEffect3 = typeof window === "undefined" ? useEffect12 : useLayoutEffect3;
|
|
5040
5972
|
var useMenuPlacement = (open, anchor, align) => {
|
|
5041
|
-
const [style, setStyle] =
|
|
5973
|
+
const [style, setStyle] = useState12();
|
|
5042
5974
|
useIsoLayoutEffect3(() => {
|
|
5043
5975
|
if (!open) return;
|
|
5044
5976
|
const place = () => {
|
|
@@ -5099,6 +6031,7 @@ var AgentComposer = ({
|
|
|
5099
6031
|
files: vfs,
|
|
5100
6032
|
dropZone = "self",
|
|
5101
6033
|
speech = true,
|
|
6034
|
+
voiceMessage = false,
|
|
5102
6035
|
showTimer = true,
|
|
5103
6036
|
showAgents = true,
|
|
5104
6037
|
showApprovalMode = true,
|
|
@@ -5116,36 +6049,52 @@ var AgentComposer = ({
|
|
|
5116
6049
|
const L = useLabels(labelsOverride);
|
|
5117
6050
|
const MODE_CHIP = L.modes;
|
|
5118
6051
|
const DEFAULT_THINKING = thinkingDefaults(L);
|
|
5119
|
-
const [text, setText] =
|
|
5120
|
-
const [pending,
|
|
5121
|
-
const
|
|
5122
|
-
const
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
const
|
|
5127
|
-
const
|
|
5128
|
-
const
|
|
5129
|
-
const
|
|
5130
|
-
const
|
|
5131
|
-
const
|
|
5132
|
-
const
|
|
5133
|
-
const
|
|
5134
|
-
const
|
|
5135
|
-
|
|
6052
|
+
const [text, setText] = useState12("");
|
|
6053
|
+
const [pending, setPendingState] = useState12([]);
|
|
6054
|
+
const pendingRef = useRef10([]);
|
|
6055
|
+
const setPending = (next) => {
|
|
6056
|
+
pendingRef.current = typeof next === "function" ? next(pendingRef.current) : next;
|
|
6057
|
+
setPendingState(pendingRef.current);
|
|
6058
|
+
};
|
|
6059
|
+
const [menu, setMenu] = useState12(void 0);
|
|
6060
|
+
const [active, setActive] = useState12(0);
|
|
6061
|
+
const [dismissed, setDismissed] = useState12(() => /* @__PURE__ */ new Set());
|
|
6062
|
+
const [attachError, setAttachError] = useState12();
|
|
6063
|
+
const [dragging, setDragging] = useState12(false);
|
|
6064
|
+
const rootRef = useRef10(null);
|
|
6065
|
+
const modelRef = useRef10(null);
|
|
6066
|
+
const modeRef = useRef10(null);
|
|
6067
|
+
const modelChipRef = useRef10(null);
|
|
6068
|
+
const modeChipRef = useRef10(null);
|
|
6069
|
+
const modelMenuRef = useRef10(null);
|
|
6070
|
+
const modeMenuRef = useRef10(null);
|
|
6071
|
+
const [dropRect, setDropRect] = useState12();
|
|
6072
|
+
const [compactBar, setCompactBar] = useState12(false);
|
|
6073
|
+
const [barWidth, setBarWidth] = useState12(0);
|
|
6074
|
+
useEffect12(() => {
|
|
5136
6075
|
const el = rootRef.current;
|
|
5137
6076
|
if (!el || typeof ResizeObserver === "undefined") return;
|
|
5138
|
-
const ro = new ResizeObserver(
|
|
5139
|
-
|
|
5140
|
-
|
|
6077
|
+
const ro = new ResizeObserver(() => {
|
|
6078
|
+
const width = el.getBoundingClientRect().width;
|
|
6079
|
+
setCompactBar(width < compactWidth);
|
|
6080
|
+
setBarWidth(Math.round(width));
|
|
6081
|
+
});
|
|
5141
6082
|
ro.observe(el);
|
|
5142
6083
|
return () => ro.disconnect();
|
|
5143
6084
|
}, [compactWidth]);
|
|
5144
|
-
const
|
|
5145
|
-
const
|
|
6085
|
+
const chipLabelRef = useRef10(null);
|
|
6086
|
+
const [chipShort, setChipShort] = useState12(false);
|
|
6087
|
+
useLayoutEffect3(() => setChipShort(false), [barWidth, model?.label, model?.shortLabel]);
|
|
6088
|
+
useLayoutEffect3(() => {
|
|
6089
|
+
const el = chipLabelRef.current;
|
|
6090
|
+
if (chipShort || !el || !model?.shortLabel) return;
|
|
6091
|
+
if (el.scrollWidth > el.clientWidth + 1) setChipShort(true);
|
|
6092
|
+
});
|
|
6093
|
+
const fileRef = useRef10(null);
|
|
6094
|
+
const inputRef = useRef10(null);
|
|
5146
6095
|
const draftId = draft?.id;
|
|
5147
6096
|
const draftText = draft?.text;
|
|
5148
|
-
|
|
6097
|
+
useEffect12(() => {
|
|
5149
6098
|
if (draftId === void 0 || !draftText) return;
|
|
5150
6099
|
setText((t) => t.trim() ? `${t.trimEnd()}
|
|
5151
6100
|
${draftText}` : draftText);
|
|
@@ -5159,13 +6108,20 @@ ${draftText}` : draftText);
|
|
|
5159
6108
|
const caps = agent.agent?.capabilities;
|
|
5160
6109
|
const stt = useSpeechToText({
|
|
5161
6110
|
lang: typeof speech === "object" ? speech.lang : void 0,
|
|
6111
|
+
createRecognizer: typeof speech === "object" ? speech.createRecognizer : void 0,
|
|
5162
6112
|
onFinal: (heard) => setText((t) => t.trim() ? `${t.trimEnd()} ${heard}` : heard)
|
|
5163
6113
|
});
|
|
5164
6114
|
const showMic = speech !== false && stt.supported;
|
|
5165
|
-
const
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
|
|
6115
|
+
const recorder = useAudioRecorder({
|
|
6116
|
+
maxMs: typeof voiceMessage === "object" ? voiceMessage.maxMs : void 0
|
|
6117
|
+
});
|
|
6118
|
+
const showVoice = voiceMessage !== false && attachments !== false && recorder.supported;
|
|
6119
|
+
const recordingOn = recorder.state !== "idle";
|
|
6120
|
+
const [voiceNote, setVoiceNote] = useState12();
|
|
6121
|
+
const [startedAt, setStartedAt] = useState12();
|
|
6122
|
+
const [now, setNow] = useState12(() => Date.now());
|
|
6123
|
+
const [lastElapsed, setLastElapsed] = useState12();
|
|
6124
|
+
useEffect12(() => {
|
|
5169
6125
|
if (!busy) {
|
|
5170
6126
|
if (startedAt !== void 0) setLastElapsed(Date.now() - startedAt);
|
|
5171
6127
|
setStartedAt(void 0);
|
|
@@ -5178,7 +6134,7 @@ ${draftText}` : draftText);
|
|
|
5178
6134
|
return () => clearInterval(id);
|
|
5179
6135
|
}, [busy]);
|
|
5180
6136
|
const elapsed = startedAt !== void 0 ? now - startedAt : lastElapsed;
|
|
5181
|
-
const allCommands =
|
|
6137
|
+
const allCommands = useMemo7(() => {
|
|
5182
6138
|
const out = [];
|
|
5183
6139
|
if (builtinCommands) {
|
|
5184
6140
|
out.push(
|
|
@@ -5261,8 +6217,8 @@ ${draftText}` : draftText);
|
|
|
5261
6217
|
const closeMenu = () => setMenu(void 0);
|
|
5262
6218
|
const modelMenuKeys = useMenuKeys(menu === "model", modelMenuRef, modelChipRef, closeMenu);
|
|
5263
6219
|
const modeMenuKeys = useMenuKeys(menu === "mode", modeMenuRef, modeChipRef, closeMenu);
|
|
5264
|
-
|
|
5265
|
-
|
|
6220
|
+
useEffect12(() => setActive(0), [text, menu]);
|
|
6221
|
+
useEffect12(() => {
|
|
5266
6222
|
if (!menu) return;
|
|
5267
6223
|
const onDown = (e) => {
|
|
5268
6224
|
if (!rootRef.current?.contains(e.target)) setMenu(void 0);
|
|
@@ -5282,17 +6238,44 @@ ${draftText}` : draftText);
|
|
|
5282
6238
|
void cmd.run?.(args);
|
|
5283
6239
|
};
|
|
5284
6240
|
const attachCfg = typeof attachments === "object" ? attachments : {};
|
|
5285
|
-
const
|
|
6241
|
+
const bounds = {
|
|
6242
|
+
maxBytes: attachCfg.maxBytes ?? ATTACHMENT_BOUNDS.maxBytes,
|
|
6243
|
+
maxSourceBytes: attachCfg.maxSourceBytes ?? ATTACHMENT_BOUNDS.maxSourceBytes,
|
|
6244
|
+
imageMaxSourcePixels: attachCfg.imageMaxSourcePixels ?? ATTACHMENT_BOUNDS.imageMaxSourcePixels,
|
|
6245
|
+
maxImages: attachCfg.maxImages ?? ATTACHMENT_BOUNDS.maxImages,
|
|
6246
|
+
maxTotalBytes: attachCfg.maxTotalBytes ?? ATTACHMENT_BOUNDS.maxTotalBytes
|
|
6247
|
+
};
|
|
5286
6248
|
const imageMax = attachCfg.imageMaxDimension ?? 1568;
|
|
6249
|
+
const overLimitText = (name, over) => over.bound === "pixels" ? L.tooManyPixels(name, Math.round(over.limit / 1e6)) : L.tooLarge(name, Math.round(over.limit / 1024 / 1024));
|
|
5287
6250
|
const addFiles = async (list) => {
|
|
5288
|
-
const added = [];
|
|
5289
6251
|
let problem;
|
|
6252
|
+
const noRoom = { images: [], bytes: [] };
|
|
6253
|
+
const add = (name, a) => {
|
|
6254
|
+
const full = messageOverLimit(pendingRef.current, a, bounds);
|
|
6255
|
+
if (full) noRoom[full].push(name);
|
|
6256
|
+
else setPending((cur) => [...cur, a]);
|
|
6257
|
+
};
|
|
5290
6258
|
for (const f of list) {
|
|
5291
6259
|
const mediaType = f.type || "application/octet-stream";
|
|
5292
6260
|
const name = f.name || `pasted-${Date.now()}.${mediaType.split("/")[1] ?? "bin"}`;
|
|
5293
6261
|
const kind = attachmentKindOf(mediaType, name);
|
|
5294
|
-
|
|
5295
|
-
|
|
6262
|
+
const refusal = attachmentRefusal(kind, caps);
|
|
6263
|
+
const converts = Boolean(convertFile && (refusal || kind === "pdf" && convert === "always"));
|
|
6264
|
+
const transform = attachmentTransformOf({
|
|
6265
|
+
kind,
|
|
6266
|
+
mediaType,
|
|
6267
|
+
imageMaxDimension: imageMax,
|
|
6268
|
+
converts
|
|
6269
|
+
});
|
|
6270
|
+
const size = transform === "downscale" ? await imageSizeOf(f) : void 0;
|
|
6271
|
+
const pixels = size && size.width * size.height;
|
|
6272
|
+
const over = attachmentOverLimit({ bytes: f.size, pixels }, "original", transform, bounds);
|
|
6273
|
+
if (over) {
|
|
6274
|
+
problem = overLimitText(name, over);
|
|
6275
|
+
continue;
|
|
6276
|
+
}
|
|
6277
|
+
if (kind === "image" && transform !== "convert" && messageOverLimit(pendingRef.current, { kind, bytes: 0 }, bounds) === "images") {
|
|
6278
|
+
noRoom.images.push(name);
|
|
5296
6279
|
continue;
|
|
5297
6280
|
}
|
|
5298
6281
|
try {
|
|
@@ -5303,22 +6286,26 @@ ${draftText}` : draftText);
|
|
|
5303
6286
|
problem = L.binaryText(name);
|
|
5304
6287
|
continue;
|
|
5305
6288
|
}
|
|
5306
|
-
|
|
6289
|
+
add(name, { id, name, kind, mediaType, text: content, bytes: f.size });
|
|
5307
6290
|
continue;
|
|
5308
6291
|
}
|
|
5309
|
-
|
|
5310
|
-
const wantConvert = convertFile && (refusal || kind === "pdf" && convert === "always");
|
|
5311
|
-
if (wantConvert && convertFile) {
|
|
6292
|
+
if (converts && convertFile) {
|
|
5312
6293
|
const converted = await convertFile(f);
|
|
5313
6294
|
if (converted) {
|
|
5314
|
-
|
|
6295
|
+
const bytes = new Blob([converted.text]).size;
|
|
6296
|
+
const sentOver2 = attachmentOverLimit({ bytes }, "sent", transform, bounds);
|
|
6297
|
+
if (sentOver2) {
|
|
6298
|
+
problem = overLimitText(name, sentOver2);
|
|
6299
|
+
continue;
|
|
6300
|
+
}
|
|
6301
|
+
add(name, {
|
|
5315
6302
|
id,
|
|
5316
6303
|
name: converted.name ?? `${name}.md`,
|
|
5317
6304
|
kind: "text",
|
|
5318
6305
|
mediaType: "text/markdown",
|
|
5319
6306
|
text: converted.text,
|
|
5320
|
-
bytes
|
|
5321
|
-
note:
|
|
6307
|
+
bytes,
|
|
6308
|
+
note: L.convertedFrom(name)
|
|
5322
6309
|
});
|
|
5323
6310
|
continue;
|
|
5324
6311
|
}
|
|
@@ -5327,27 +6314,75 @@ ${draftText}` : draftText);
|
|
|
5327
6314
|
problem = refusal;
|
|
5328
6315
|
continue;
|
|
5329
6316
|
}
|
|
5330
|
-
const blob =
|
|
6317
|
+
const blob = transform === "downscale" ? await downscaleImage(f, {
|
|
5331
6318
|
maxDimension: imageMax,
|
|
5332
6319
|
maxPixels: attachCfg.imageMaxPixels
|
|
5333
6320
|
}) : f;
|
|
5334
|
-
|
|
6321
|
+
const sentOver = attachmentOverLimit({ bytes: blob.size }, "sent", transform, bounds);
|
|
6322
|
+
if (sentOver) {
|
|
6323
|
+
problem = overLimitText(name, sentOver);
|
|
6324
|
+
continue;
|
|
6325
|
+
}
|
|
6326
|
+
add(name, {
|
|
5335
6327
|
id,
|
|
5336
6328
|
name,
|
|
5337
6329
|
kind,
|
|
5338
6330
|
mediaType: blob.type || mediaType,
|
|
5339
6331
|
dataUrl: await readDataUrl2(blob),
|
|
5340
6332
|
bytes: blob.size,
|
|
5341
|
-
...blob !== f ? { note:
|
|
6333
|
+
...blob !== f ? { note: L.downscaledFrom(L.bytes(f.size)) } : {}
|
|
5342
6334
|
});
|
|
5343
6335
|
} catch (err) {
|
|
5344
6336
|
problem = `${name}: ${err instanceof Error ? err.message : String(err)}`;
|
|
5345
6337
|
}
|
|
5346
6338
|
}
|
|
5347
|
-
|
|
5348
|
-
|
|
6339
|
+
const names = (list2) => list2.length > 3 ? `${list2.slice(0, 3).join(", ")}, \u2026` : list2.join(", ");
|
|
6340
|
+
const said = [
|
|
6341
|
+
problem,
|
|
6342
|
+
noRoom.images.length ? L.tooManyImages(names(noRoom.images), bounds.maxImages) : "",
|
|
6343
|
+
noRoom.bytes.length ? L.messageTooLarge(names(noRoom.bytes), Math.round(bounds.maxTotalBytes / 1024 / 1024)) : ""
|
|
6344
|
+
];
|
|
6345
|
+
setAttachError(said.filter(Boolean).join(" ") || void 0);
|
|
5349
6346
|
if (fileRef.current) fileRef.current.value = "";
|
|
5350
6347
|
};
|
|
6348
|
+
const addRecording = async (audio) => {
|
|
6349
|
+
if (audio.blob.size === 0) return;
|
|
6350
|
+
const name = voiceMessageName(/* @__PURE__ */ new Date(), audioExtensionOf(audio.mediaType));
|
|
6351
|
+
const over = attachmentOverLimit({ bytes: audio.blob.size }, "sent", "none", bounds);
|
|
6352
|
+
if (over) {
|
|
6353
|
+
setAttachError(overLimitText(L.voiceMessage, over));
|
|
6354
|
+
return;
|
|
6355
|
+
}
|
|
6356
|
+
const a = {
|
|
6357
|
+
id: `att-${attachSeq += 1}`,
|
|
6358
|
+
name,
|
|
6359
|
+
kind: "file",
|
|
6360
|
+
mediaType: audio.mediaType,
|
|
6361
|
+
dataUrl: await readDataUrl2(audio.blob),
|
|
6362
|
+
bytes: audio.blob.size,
|
|
6363
|
+
durationMs: audio.durationMs,
|
|
6364
|
+
note: L.audioDuration(formatClock(audio.durationMs))
|
|
6365
|
+
};
|
|
6366
|
+
if (messageOverLimit(pendingRef.current, a, bounds) === "bytes") {
|
|
6367
|
+
setAttachError(
|
|
6368
|
+
L.messageTooLarge(L.voiceMessage, Math.round(bounds.maxTotalBytes / 1024 / 1024))
|
|
6369
|
+
);
|
|
6370
|
+
return;
|
|
6371
|
+
}
|
|
6372
|
+
setPending((cur) => [...cur, a]);
|
|
6373
|
+
};
|
|
6374
|
+
const finishRecording = async () => {
|
|
6375
|
+
const audio = await recorder.stop();
|
|
6376
|
+
if (audio) await addRecording(audio);
|
|
6377
|
+
inputRef.current?.focus();
|
|
6378
|
+
};
|
|
6379
|
+
const limited = recorder.limited;
|
|
6380
|
+
useEffect12(() => {
|
|
6381
|
+
if (!limited) return;
|
|
6382
|
+
recorder.clear();
|
|
6383
|
+
setVoiceNote(L.recordingLimit);
|
|
6384
|
+
void addRecording(limited);
|
|
6385
|
+
}, [limited]);
|
|
5351
6386
|
const onPaste = (e) => {
|
|
5352
6387
|
if (attachments === false) return;
|
|
5353
6388
|
const pasted = Array.from(e.clipboardData?.files ?? []);
|
|
@@ -5355,9 +6390,9 @@ ${draftText}` : draftText);
|
|
|
5355
6390
|
e.preventDefault();
|
|
5356
6391
|
void addFiles(pasted);
|
|
5357
6392
|
};
|
|
5358
|
-
const addFilesRef =
|
|
6393
|
+
const addFilesRef = useRef10(addFiles);
|
|
5359
6394
|
addFilesRef.current = addFiles;
|
|
5360
|
-
|
|
6395
|
+
useEffect12(() => {
|
|
5361
6396
|
if (attachments === false) return;
|
|
5362
6397
|
const target = dropZone === "window" ? globalThis.window : dropZone === "self" ? rootRef.current : dropZone.current;
|
|
5363
6398
|
if (!target) return;
|
|
@@ -5479,10 +6514,11 @@ ${draftText}` : draftText);
|
|
|
5479
6514
|
mediaType: a.mediaType,
|
|
5480
6515
|
size: a.bytes,
|
|
5481
6516
|
...a.kind === "image" && a.dataUrl ? { dataUrl: a.dataUrl } : {},
|
|
5482
|
-
...a.path ? { path: a.path } : {}
|
|
6517
|
+
...a.path ? { path: a.path } : {},
|
|
6518
|
+
...a.durationMs !== void 0 ? { durationMs: a.durationMs } : {}
|
|
5483
6519
|
}));
|
|
5484
6520
|
const full = withAttachments(goal || L.seeAttachments, items);
|
|
5485
|
-
const label = shown
|
|
6521
|
+
const label = shown;
|
|
5486
6522
|
void agent.run(full, {
|
|
5487
6523
|
...full !== label ? { label } : {},
|
|
5488
6524
|
images: items.filter((a) => a.kind === "image" && a.dataUrl).map(toModel),
|
|
@@ -5523,16 +6559,24 @@ ${draftText}` : draftText);
|
|
|
5523
6559
|
...attachError ? [{ id: `attach:${attachError}`, tone: "warn", text: attachError }] : [],
|
|
5524
6560
|
...stt.error ? [
|
|
5525
6561
|
{
|
|
5526
|
-
id: `stt:${stt.error}`,
|
|
6562
|
+
id: `stt:${stt.error}:${stt.errorMessage ?? ""}`,
|
|
5527
6563
|
tone: "warn",
|
|
5528
|
-
text:
|
|
6564
|
+
text: micProblemText(stt.error, stt.errorMessage, L)
|
|
5529
6565
|
}
|
|
5530
|
-
] : []
|
|
6566
|
+
] : [],
|
|
6567
|
+
...recorder.error ? [
|
|
6568
|
+
{
|
|
6569
|
+
id: `rec:${recorder.error}`,
|
|
6570
|
+
tone: "warn",
|
|
6571
|
+
text: micProblemText(recorder.error, void 0, L)
|
|
6572
|
+
}
|
|
6573
|
+
] : [],
|
|
6574
|
+
...voiceNote ? [{ id: `voice:${voiceNote}`, tone: "info", text: voiceNote }] : []
|
|
5531
6575
|
].filter((n) => !dismissed.has(n.id)) : [];
|
|
5532
6576
|
const runningAgents = agent.subagents.filter((s) => s.status === "running");
|
|
5533
6577
|
const thinkingOptions = thinking?.options ?? DEFAULT_THINKING;
|
|
5534
6578
|
const thinkingLabel = thinking ? thinkingOptions.find((o) => o.id === thinking.value)?.label ?? thinking.value : void 0;
|
|
5535
|
-
const canSend = ready && (text.trim().length > 0 || pending.length > 0);
|
|
6579
|
+
const canSend = ready && !recordingOn && (text.trim().length > 0 || pending.length > 0);
|
|
5536
6580
|
const canSteer = busy && steering && text.trim().length > 0;
|
|
5537
6581
|
const queuedStrip = showQueued && (agent.queued.length > 0 || agent.undelivered.length > 0) ? /* @__PURE__ */ jsxs3("div", { className: "awr-queued", children: [
|
|
5538
6582
|
agent.queued.map((q) => /* @__PURE__ */ jsxs3("div", { className: "awr-queued__item", role: "status", children: [
|
|
@@ -5576,6 +6620,8 @@ ${draftText}` : draftText);
|
|
|
5576
6620
|
onClick: () => {
|
|
5577
6621
|
setDismissed((d) => new Set(d).add(n.id));
|
|
5578
6622
|
if (n.id.startsWith("attach:")) setAttachError(void 0);
|
|
6623
|
+
if (n.id.startsWith("rec:")) recorder.clear();
|
|
6624
|
+
if (n.id.startsWith("voice:")) setVoiceNote(void 0);
|
|
5579
6625
|
},
|
|
5580
6626
|
children: /* @__PURE__ */ jsx5(XIcon, { size: 14 })
|
|
5581
6627
|
}
|
|
@@ -5613,8 +6659,11 @@ ${draftText}` : draftText);
|
|
|
5613
6659
|
const remove = () => setPending((cur) => cur.filter((x) => x.id !== a.id));
|
|
5614
6660
|
if (renderAttachment) return /* @__PURE__ */ jsx5("span", { children: renderAttachment(a, remove) }, a.id);
|
|
5615
6661
|
return /* @__PURE__ */ jsxs3("span", { className: "awr-chip awr-file", title: a.note ?? a.mediaType, children: [
|
|
5616
|
-
a.kind === "image" && a.dataUrl ? /* @__PURE__ */ jsx5("img", { className: "awr-file__thumb", src: a.dataUrl, alt: a.name }) : /* @__PURE__ */ jsx5(FileIcon, { size: 14 }),
|
|
5617
|
-
/* @__PURE__ */
|
|
6662
|
+
a.kind === "image" && a.dataUrl ? /* @__PURE__ */ jsx5("img", { className: "awr-file__thumb", src: a.dataUrl, alt: a.name }) : a.mediaType.startsWith("audio/") ? /* @__PURE__ */ jsx5(WaveIcon, { size: 14 }) : /* @__PURE__ */ jsx5(FileIcon, { size: 14 }),
|
|
6663
|
+
a.note ? /* @__PURE__ */ jsxs3("span", { className: "awr-file__text", children: [
|
|
6664
|
+
/* @__PURE__ */ jsx5("span", { className: "awr-file__name", children: a.name }),
|
|
6665
|
+
/* @__PURE__ */ jsx5("span", { className: "awr-file__note", children: a.note })
|
|
6666
|
+
] }) : /* @__PURE__ */ jsx5("span", { className: "awr-file__name", children: a.name }),
|
|
5618
6667
|
/* @__PURE__ */ jsx5(
|
|
5619
6668
|
"button",
|
|
5620
6669
|
{
|
|
@@ -5627,6 +6676,33 @@ ${draftText}` : draftText);
|
|
|
5627
6676
|
)
|
|
5628
6677
|
] }, a.id);
|
|
5629
6678
|
}) }),
|
|
6679
|
+
showVoice && recordingOn && /* @__PURE__ */ jsxs3("div", { className: "awr-recording", role: "status", "aria-live": "polite", children: [
|
|
6680
|
+
/* @__PURE__ */ jsx5("span", { className: "awr-recording__dot", "aria-hidden": "true" }),
|
|
6681
|
+
/* @__PURE__ */ jsx5("span", { className: "awr-recording__time", children: L.recording(formatClock(recorder.elapsedMs)) }),
|
|
6682
|
+
/* @__PURE__ */ jsx5(
|
|
6683
|
+
"button",
|
|
6684
|
+
{
|
|
6685
|
+
type: "button",
|
|
6686
|
+
className: "awr-iconbtn",
|
|
6687
|
+
"aria-label": L.recordingCancel,
|
|
6688
|
+
title: L.recordingCancel,
|
|
6689
|
+
onClick: recorder.cancel,
|
|
6690
|
+
children: /* @__PURE__ */ jsx5(XIcon, { size: 16 })
|
|
6691
|
+
}
|
|
6692
|
+
),
|
|
6693
|
+
/* @__PURE__ */ jsx5(
|
|
6694
|
+
"button",
|
|
6695
|
+
{
|
|
6696
|
+
type: "button",
|
|
6697
|
+
className: "awr-iconbtn awr-recording__done",
|
|
6698
|
+
"aria-label": L.recordingDone,
|
|
6699
|
+
title: L.recordingDone,
|
|
6700
|
+
onClick: () => void finishRecording(),
|
|
6701
|
+
disabled: recorder.state !== "recording",
|
|
6702
|
+
children: /* @__PURE__ */ jsx5(CheckIcon, { size: 16 })
|
|
6703
|
+
}
|
|
6704
|
+
)
|
|
6705
|
+
] }),
|
|
5630
6706
|
/* @__PURE__ */ jsxs3("div", { className: "awr-composer2__inputrow", children: [
|
|
5631
6707
|
/* @__PURE__ */ jsx5(
|
|
5632
6708
|
"textarea",
|
|
@@ -5637,7 +6713,7 @@ ${draftText}` : draftText);
|
|
|
5637
6713
|
onChange: (e) => setText(e.target.value),
|
|
5638
6714
|
onKeyDown,
|
|
5639
6715
|
onPaste,
|
|
5640
|
-
placeholder: stt.listening ? L.listening : busy && steering ? L.placeholderBusy : placeholder ?? L.placeholder,
|
|
6716
|
+
placeholder: stt.finishing ? L.transcribing : stt.listening ? L.listening : busy && steering ? L.placeholderBusy : placeholder ?? L.placeholder,
|
|
5641
6717
|
disabled,
|
|
5642
6718
|
rows: 2,
|
|
5643
6719
|
"aria-label": L.message
|
|
@@ -5647,16 +6723,18 @@ ${draftText}` : draftText);
|
|
|
5647
6723
|
"button",
|
|
5648
6724
|
{
|
|
5649
6725
|
type: "button",
|
|
5650
|
-
className: `awr-iconbtn awr-mic${stt.listening ? " is-on" : ""}`,
|
|
6726
|
+
className: `awr-iconbtn awr-mic${stt.listening ? " is-on" : ""}${stt.finishing ? " is-busy" : ""}`,
|
|
5651
6727
|
"aria-label": stt.listening ? L.stopDictation : L.dictate,
|
|
6728
|
+
"aria-pressed": stt.listening,
|
|
5652
6729
|
title: stt.listening ? L.stopDictation : L.dictateTitle,
|
|
5653
6730
|
onClick: stt.toggle,
|
|
5654
|
-
disabled,
|
|
5655
|
-
children: /* @__PURE__ */ jsx5(MicIcon, { size: 18 })
|
|
6731
|
+
disabled: disabled || recordingOn || stt.finishing,
|
|
6732
|
+
children: stt.finishing ? /* @__PURE__ */ jsx5(SpinnerIcon, { size: 18 }) : /* @__PURE__ */ jsx5(MicIcon, { size: 18 })
|
|
5656
6733
|
}
|
|
5657
6734
|
)
|
|
5658
6735
|
] }),
|
|
5659
6736
|
stt.listening && stt.interim && /* @__PURE__ */ jsx5("div", { className: "awr-composer2__interim", children: stt.interim }),
|
|
6737
|
+
stt.finishing && /* @__PURE__ */ jsx5("div", { className: "awr-composer2__interim", role: "status", children: L.transcribing }),
|
|
5660
6738
|
/* @__PURE__ */ jsxs3("div", { className: "awr-toolbar", children: [
|
|
5661
6739
|
attachments !== false && /* @__PURE__ */ jsxs3(Fragment3, { children: [
|
|
5662
6740
|
/* @__PURE__ */ jsx5(
|
|
@@ -5671,6 +6749,22 @@ ${draftText}` : draftText);
|
|
|
5671
6749
|
children: /* @__PURE__ */ jsx5(PlusIcon, { size: 18 })
|
|
5672
6750
|
}
|
|
5673
6751
|
),
|
|
6752
|
+
showVoice && /* @__PURE__ */ jsx5(
|
|
6753
|
+
"button",
|
|
6754
|
+
{
|
|
6755
|
+
type: "button",
|
|
6756
|
+
className: `awr-iconbtn awr-voicebtn${recordingOn ? " is-on" : ""}`,
|
|
6757
|
+
"aria-label": L.recordVoiceMessage,
|
|
6758
|
+
title: L.recordVoiceMessage,
|
|
6759
|
+
"aria-pressed": recordingOn,
|
|
6760
|
+
onClick: () => {
|
|
6761
|
+
setVoiceNote(void 0);
|
|
6762
|
+
void recorder.start();
|
|
6763
|
+
},
|
|
6764
|
+
disabled: disabled || recordingOn || stt.listening,
|
|
6765
|
+
children: /* @__PURE__ */ jsx5(WaveIcon, { size: 18 })
|
|
6766
|
+
}
|
|
6767
|
+
),
|
|
5674
6768
|
/* @__PURE__ */ jsx5(
|
|
5675
6769
|
"input",
|
|
5676
6770
|
{
|
|
@@ -5695,7 +6789,7 @@ ${draftText}` : draftText);
|
|
|
5695
6789
|
}
|
|
5696
6790
|
),
|
|
5697
6791
|
toolbarExtra,
|
|
5698
|
-
showTimer && elapsed !== void 0 && /* @__PURE__ */ jsxs3("span", { className: "awr-tchip", title: busy ? L.timerRunning : L.timerLast, children: [
|
|
6792
|
+
showTimer && elapsed !== void 0 && (busy || !compactBar) && /* @__PURE__ */ jsxs3("span", { className: "awr-tchip", title: busy ? L.timerRunning : L.timerLast, children: [
|
|
5699
6793
|
/* @__PURE__ */ jsx5(ClockIcon, { size: 14 }),
|
|
5700
6794
|
" ",
|
|
5701
6795
|
formatElapsed(elapsed)
|
|
@@ -5731,7 +6825,7 @@ ${draftText}` : draftText);
|
|
|
5731
6825
|
"aria-expanded": menu === "model",
|
|
5732
6826
|
title: [model?.label, thinkingLabel].filter(Boolean).join(" \xB7 "),
|
|
5733
6827
|
children: [
|
|
5734
|
-
/* @__PURE__ */ jsx5("span", { className: "awr-tchip__label", children: model?.label
|
|
6828
|
+
/* @__PURE__ */ jsx5("span", { className: "awr-tchip__label", ref: chipLabelRef, children: chipShort && model?.shortLabel || model?.label || L.model }),
|
|
5735
6829
|
thinkingLabel && !compactBar && /* @__PURE__ */ jsx5("span", { className: "awr-tchip__sub", children: thinkingLabel })
|
|
5736
6830
|
]
|
|
5737
6831
|
}
|
|
@@ -6054,7 +7148,7 @@ var ContextMeter = ({
|
|
|
6054
7148
|
};
|
|
6055
7149
|
|
|
6056
7150
|
// src/components/ElicitationPrompt.tsx
|
|
6057
|
-
import { useEffect as
|
|
7151
|
+
import { useEffect as useEffect13, useId, useState as useState13 } from "react";
|
|
6058
7152
|
import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
6059
7153
|
var reasonText = (outcome, L) => {
|
|
6060
7154
|
const reason = outcome.reason;
|
|
@@ -6064,8 +7158,8 @@ var reasonText = (outcome, L) => {
|
|
|
6064
7158
|
return reason || outcome.status;
|
|
6065
7159
|
};
|
|
6066
7160
|
var useNow = (active) => {
|
|
6067
|
-
const [now, setNow] =
|
|
6068
|
-
|
|
7161
|
+
const [now, setNow] = useState13(() => Date.now());
|
|
7162
|
+
useEffect13(() => {
|
|
6069
7163
|
if (!active) return;
|
|
6070
7164
|
setNow(Date.now());
|
|
6071
7165
|
const timer = setInterval(() => setNow(Date.now()), 1e3);
|
|
@@ -6196,8 +7290,8 @@ var FormBody = ({ elicitation, answer, L }) => {
|
|
|
6196
7290
|
const baseId = useId();
|
|
6197
7291
|
const schema = elicitation.requestedSchema;
|
|
6198
7292
|
const fields = elicitationFields(schema);
|
|
6199
|
-
const [draft, setDraft] =
|
|
6200
|
-
const [issues, setIssues] =
|
|
7293
|
+
const [draft, setDraft] = useState13(() => elicitationInitialDraft(schema));
|
|
7294
|
+
const [issues, setIssues] = useState13(void 0);
|
|
6201
7295
|
const fieldId = (i) => `${baseId}-f${i}`;
|
|
6202
7296
|
const submit = (e) => {
|
|
6203
7297
|
e.preventDefault();
|
|
@@ -6252,7 +7346,7 @@ var FormBody = ({ elicitation, answer, L }) => {
|
|
|
6252
7346
|
};
|
|
6253
7347
|
var UrlBody = ({ elicitation, answer, L }) => {
|
|
6254
7348
|
const link = elicitationLink(elicitation.url);
|
|
6255
|
-
const [opened, setOpened] =
|
|
7349
|
+
const [opened, setOpened] = useState13(false);
|
|
6256
7350
|
const open = () => {
|
|
6257
7351
|
if (!link.openable || typeof window === "undefined") return;
|
|
6258
7352
|
window.open(link.href, "_blank", "noopener,noreferrer");
|
|
@@ -6316,7 +7410,7 @@ var ElicitationPrompt = ({
|
|
|
6316
7410
|
className
|
|
6317
7411
|
}) => {
|
|
6318
7412
|
const L = useLabels(labels);
|
|
6319
|
-
const [dismissed, setDismissed] =
|
|
7413
|
+
const [dismissed, setDismissed] = useState13(() => /* @__PURE__ */ new Set());
|
|
6320
7414
|
const automatic = showOutcomes ? (outcomes ?? []).filter(
|
|
6321
7415
|
(o) => o.automatic === true && o.status !== "pending" && !dismissed.has(o.id)
|
|
6322
7416
|
) : [];
|
|
@@ -6377,21 +7471,21 @@ var ElicitationPrompt = ({
|
|
|
6377
7471
|
};
|
|
6378
7472
|
|
|
6379
7473
|
// src/components/FilesPanel.tsx
|
|
6380
|
-
import { Fragment as Fragment6, useEffect as
|
|
7474
|
+
import { Fragment as Fragment6, useEffect as useEffect15, useRef as useRef12, useState as useState15 } from "react";
|
|
6381
7475
|
|
|
6382
7476
|
// src/components/ImageViewer.tsx
|
|
6383
|
-
import { createContext as createContext3, useContext as useContext3, useEffect as
|
|
7477
|
+
import { createContext as createContext3, useContext as useContext3, useEffect as useEffect14, useRef as useRef11, useState as useState14 } from "react";
|
|
6384
7478
|
import { createPortal } from "react-dom";
|
|
6385
7479
|
import { Fragment as Fragment5, jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
6386
7480
|
var fileNameOf = (name) => name.split(/[\\/]/).filter(Boolean).pop() ?? name;
|
|
6387
7481
|
var SWIPE_PX = 48;
|
|
6388
7482
|
var ImageViewer = ({ images, index, onIndex, onClose, labels }) => {
|
|
6389
7483
|
const L = useLabels(labels);
|
|
6390
|
-
const rootRef =
|
|
6391
|
-
const closeRef =
|
|
6392
|
-
const imgRef =
|
|
6393
|
-
const touch =
|
|
6394
|
-
const [zoom, setZoom] =
|
|
7484
|
+
const rootRef = useRef11(null);
|
|
7485
|
+
const closeRef = useRef11(null);
|
|
7486
|
+
const imgRef = useRef11(null);
|
|
7487
|
+
const touch = useRef11(void 0);
|
|
7488
|
+
const [zoom, setZoom] = useState14(void 0);
|
|
6395
7489
|
const count = images.length;
|
|
6396
7490
|
const at = Math.min(Math.max(index, 0), count - 1);
|
|
6397
7491
|
const image = images[at];
|
|
@@ -6400,7 +7494,7 @@ var ImageViewer = ({ images, index, onIndex, onClose, labels }) => {
|
|
|
6400
7494
|
setZoom(void 0);
|
|
6401
7495
|
onIndex((at + step + count) % count);
|
|
6402
7496
|
};
|
|
6403
|
-
|
|
7497
|
+
useEffect14(() => {
|
|
6404
7498
|
closeRef.current?.focus();
|
|
6405
7499
|
const root = document.documentElement;
|
|
6406
7500
|
const before = root.style.overflow;
|
|
@@ -6409,7 +7503,7 @@ var ImageViewer = ({ images, index, onIndex, onClose, labels }) => {
|
|
|
6409
7503
|
root.style.overflow = before;
|
|
6410
7504
|
};
|
|
6411
7505
|
}, []);
|
|
6412
|
-
const keys =
|
|
7506
|
+
const keys = useRef11(() => {
|
|
6413
7507
|
});
|
|
6414
7508
|
keys.current = (e) => {
|
|
6415
7509
|
if (e.key === "Escape") {
|
|
@@ -6435,7 +7529,7 @@ var ImageViewer = ({ images, index, onIndex, onClose, labels }) => {
|
|
|
6435
7529
|
}
|
|
6436
7530
|
}
|
|
6437
7531
|
};
|
|
6438
|
-
|
|
7532
|
+
useEffect14(() => {
|
|
6439
7533
|
const onKey = (e) => keys.current(e);
|
|
6440
7534
|
document.addEventListener("keydown", onKey, true);
|
|
6441
7535
|
return () => document.removeEventListener("keydown", onKey, true);
|
|
@@ -6579,8 +7673,8 @@ var ImageThumb = ({
|
|
|
6579
7673
|
}) => {
|
|
6580
7674
|
const L = useLabels(labels);
|
|
6581
7675
|
const { enabled, render } = useContext3(ImageViewerContext);
|
|
6582
|
-
const ref =
|
|
6583
|
-
const [open, setOpen] =
|
|
7676
|
+
const ref = useRef11(null);
|
|
7677
|
+
const [open, setOpen] = useState14(void 0);
|
|
6584
7678
|
const img = /* @__PURE__ */ jsx9("img", { className: imgClassName, src, alt });
|
|
6585
7679
|
if (!enabled) {
|
|
6586
7680
|
return /* @__PURE__ */ jsx9("a", { className, href: src, target: "_blank", rel: "noopener noreferrer", title, children: img });
|
|
@@ -6642,9 +7736,9 @@ var FilesPanel = ({
|
|
|
6642
7736
|
}) => {
|
|
6643
7737
|
const L = useLabels(labels);
|
|
6644
7738
|
const fs = useVirtualFiles(vfs, prefix);
|
|
6645
|
-
const [preview, setPreview] =
|
|
6646
|
-
const inputRef =
|
|
6647
|
-
|
|
7739
|
+
const [preview, setPreview] = useState15();
|
|
7740
|
+
const inputRef = useRef12(null);
|
|
7741
|
+
useEffect15(() => {
|
|
6648
7742
|
if (preview && !fs.files.some((f) => f.path === preview.path)) setPreview(void 0);
|
|
6649
7743
|
}, [fs.files, preview]);
|
|
6650
7744
|
const open = async (f) => {
|
|
@@ -6765,7 +7859,7 @@ var FilesPanel = ({
|
|
|
6765
7859
|
};
|
|
6766
7860
|
|
|
6767
7861
|
// src/components/FileChips.tsx
|
|
6768
|
-
import { Fragment as Fragment8, useEffect as
|
|
7862
|
+
import { Fragment as Fragment8, useEffect as useEffect17, useMemo as useMemo8, useState as useState17 } from "react";
|
|
6769
7863
|
|
|
6770
7864
|
// src/file-kinds.ts
|
|
6771
7865
|
import { MEDIA_IMAGE_TYPES, isTextMime } from "@dudko.dev/agent-web";
|
|
@@ -6786,7 +7880,7 @@ var fileKindOf = (path, mediaType) => {
|
|
|
6786
7880
|
var fileNameOf2 = (path) => path.split("/").filter(Boolean).pop() || "file";
|
|
6787
7881
|
|
|
6788
7882
|
// src/components/Media.tsx
|
|
6789
|
-
import { useEffect as
|
|
7883
|
+
import { useEffect as useEffect16, useState as useState16 } from "react";
|
|
6790
7884
|
import { MEDIA_AUDIO_TYPES, MEDIA_IMAGE_TYPES as MEDIA_IMAGE_TYPES2 } from "@dudko.dev/agent-web";
|
|
6791
7885
|
import { jsx as jsx11, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
6792
7886
|
var mediaFamilyOf = (mediaType) => {
|
|
@@ -6803,8 +7897,8 @@ var bytesOf = (content, encoding) => {
|
|
|
6803
7897
|
return bytes;
|
|
6804
7898
|
};
|
|
6805
7899
|
var useFileUrl = (files, path, mediaType) => {
|
|
6806
|
-
const [url, setUrl] =
|
|
6807
|
-
|
|
7900
|
+
const [url, setUrl] = useState16(void 0);
|
|
7901
|
+
useEffect16(() => {
|
|
6808
7902
|
if (!files || !mediaType) return;
|
|
6809
7903
|
let made;
|
|
6810
7904
|
let gone = false;
|
|
@@ -6824,13 +7918,14 @@ var useFileUrl = (files, path, mediaType) => {
|
|
|
6824
7918
|
}, [files, path, mediaType]);
|
|
6825
7919
|
return url;
|
|
6826
7920
|
};
|
|
7921
|
+
var baseName = (path) => path.split(/[\\/]/).filter(Boolean).pop() ?? path;
|
|
6827
7922
|
var GeneratedMedia = ({ media, files, labels }) => {
|
|
6828
7923
|
const L = useLabels(labels);
|
|
6829
7924
|
const family = mediaFamilyOf(media.mediaType);
|
|
6830
7925
|
const type = family ? media.mediaType.toLowerCase().split(";")[0].trim() : void 0;
|
|
6831
7926
|
const url = useFileUrl(files, media.path, type);
|
|
6832
7927
|
if (url && family === "image") {
|
|
6833
|
-
|
|
7928
|
+
const thumb = /* @__PURE__ */ jsx11(
|
|
6834
7929
|
ImageThumb,
|
|
6835
7930
|
{
|
|
6836
7931
|
className: "awr-media awr-media--image",
|
|
@@ -6842,6 +7937,20 @@ var GeneratedMedia = ({ media, files, labels }) => {
|
|
|
6842
7937
|
labels
|
|
6843
7938
|
}
|
|
6844
7939
|
);
|
|
7940
|
+
const refs = media.references;
|
|
7941
|
+
if (!refs || refs.paths.length === 0) return thumb;
|
|
7942
|
+
const names = refs.paths.map(baseName).join(", ");
|
|
7943
|
+
return /* @__PURE__ */ jsxs9("span", { className: "awr-media-refs", children: [
|
|
7944
|
+
thumb,
|
|
7945
|
+
/* @__PURE__ */ jsx11(
|
|
7946
|
+
"span",
|
|
7947
|
+
{
|
|
7948
|
+
className: `awr-media__refs${refs.used ? "" : " awr-media__refs--unused"}`,
|
|
7949
|
+
title: refs.paths.join("\n"),
|
|
7950
|
+
children: refs.used ? L.mediaReferences(names) : L.mediaReferencesUnused(names)
|
|
7951
|
+
}
|
|
7952
|
+
)
|
|
7953
|
+
] });
|
|
6845
7954
|
}
|
|
6846
7955
|
if (url && family === "audio") {
|
|
6847
7956
|
return /* @__PURE__ */ jsx11("span", { className: "awr-media awr-media--audio", title: media.path, children: /* @__PURE__ */ jsx11(
|
|
@@ -6973,7 +8082,7 @@ var SourceView = ({
|
|
|
6973
8082
|
const L = useLabels(labels);
|
|
6974
8083
|
const cut = text.length > maxChars;
|
|
6975
8084
|
const shown = cut ? text.slice(0, maxChars) : text;
|
|
6976
|
-
const lines =
|
|
8085
|
+
const lines = useMemo8(
|
|
6977
8086
|
() => linesOf(html ? tokenizeHtml(shown) : [{ kind: "text", text: shown }]),
|
|
6978
8087
|
[shown, html]
|
|
6979
8088
|
);
|
|
@@ -6988,16 +8097,16 @@ var SourceView = ({
|
|
|
6988
8097
|
] });
|
|
6989
8098
|
};
|
|
6990
8099
|
var HtmlPreview = ({ written, file, htmlPreview, previewChars, L }) => {
|
|
6991
|
-
const html =
|
|
8100
|
+
const html = useMemo8(() => textOf(file), [file]);
|
|
6992
8101
|
const options = htmlPreview === false ? void 0 : htmlPreview;
|
|
6993
8102
|
const tooLarge = html.length > HTML_PREVIEW_MAX_CHARS;
|
|
6994
8103
|
const canFrame = Boolean(options) && !tooLarge;
|
|
6995
|
-
const [view, setView] =
|
|
6996
|
-
const [tall, setTall] =
|
|
8104
|
+
const [view, setView] = useState17(canFrame ? "preview" : "source");
|
|
8105
|
+
const [tall, setTall] = useState17(false);
|
|
6997
8106
|
const showing = canFrame ? view : "source";
|
|
6998
8107
|
const scripts = options?.scripts === true;
|
|
6999
8108
|
const height = options?.height ?? 300;
|
|
7000
|
-
const linked =
|
|
8109
|
+
const linked = useMemo8(() => showing === "preview" ? linkedFilesOf(html) : [], [html, showing]);
|
|
7001
8110
|
return /* @__PURE__ */ jsx13(
|
|
7002
8111
|
SandboxedFrame,
|
|
7003
8112
|
{
|
|
@@ -7110,14 +8219,14 @@ var TextPreview = ({
|
|
|
7110
8219
|
onClose,
|
|
7111
8220
|
L
|
|
7112
8221
|
}) => {
|
|
7113
|
-
const text =
|
|
7114
|
-
const rendered =
|
|
8222
|
+
const text = useMemo8(() => textOf(file), [file]);
|
|
8223
|
+
const rendered = useMemo8(
|
|
7115
8224
|
() => renderFileContent?.(written, text.slice(0, previewChars)),
|
|
7116
8225
|
[renderFileContent, written, text, previewChars]
|
|
7117
8226
|
);
|
|
7118
8227
|
const hasRendered = rendered !== void 0 && rendered !== null && rendered !== false;
|
|
7119
|
-
const [view, setView] =
|
|
7120
|
-
const [all, setAll] =
|
|
8228
|
+
const [view, setView] = useState17("rendered");
|
|
8229
|
+
const [all, setAll] = useState17(false);
|
|
7121
8230
|
const showing = hasRendered ? view : "source";
|
|
7122
8231
|
const long = text.length > 1200 || text.split("\n").length > 16;
|
|
7123
8232
|
return /* @__PURE__ */ jsxs11("div", { className: "awr-fileview", children: [
|
|
@@ -7159,11 +8268,11 @@ var FileChips = ({
|
|
|
7159
8268
|
}) => {
|
|
7160
8269
|
const L = useLabels(labels);
|
|
7161
8270
|
const live = useVirtualFiles(vfs);
|
|
7162
|
-
const [openPath, setOpenPath] =
|
|
7163
|
-
const [file, setFile] =
|
|
8271
|
+
const [openPath, setOpenPath] = useState17(defaultOpen);
|
|
8272
|
+
const [file, setFile] = useState17();
|
|
7164
8273
|
const open = written.find((f) => f.path === openPath);
|
|
7165
8274
|
const stamp = live.files.find((f) => f.path === openPath)?.updatedAt;
|
|
7166
|
-
|
|
8275
|
+
useEffect17(() => {
|
|
7167
8276
|
if (!vfs || !openPath) return setFile(void 0);
|
|
7168
8277
|
let gone = false;
|
|
7169
8278
|
vfs.read(openPath).then((f) => {
|
|
@@ -7289,11 +8398,11 @@ var FileChip = ({
|
|
|
7289
8398
|
import { Fragment as Fragment11 } from "react";
|
|
7290
8399
|
|
|
7291
8400
|
// src/components/SubagentTree.tsx
|
|
7292
|
-
import { Fragment as Fragment10, useEffect as
|
|
8401
|
+
import { Fragment as Fragment10, useEffect as useEffect18, useState as useState18 } from "react";
|
|
7293
8402
|
import { jsx as jsx14, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
7294
8403
|
var useElapsed = (startedAt, running) => {
|
|
7295
|
-
const [now, setNow] =
|
|
7296
|
-
|
|
8404
|
+
const [now, setNow] = useState18(void 0);
|
|
8405
|
+
useEffect18(() => {
|
|
7297
8406
|
if (!running || startedAt === void 0) return;
|
|
7298
8407
|
setNow(Date.now());
|
|
7299
8408
|
const timer = setInterval(() => setNow(Date.now()), 1e3);
|
|
@@ -7658,7 +8767,7 @@ var StepList = ({
|
|
|
7658
8767
|
};
|
|
7659
8768
|
|
|
7660
8769
|
// src/components/MessageList.tsx
|
|
7661
|
-
import { jsx as jsx16, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
8770
|
+
import { Fragment as Fragment12, jsx as jsx16, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
7662
8771
|
var usageLine = (usage, durationMs) => {
|
|
7663
8772
|
const parts = [];
|
|
7664
8773
|
if (usage && usage.totalTokens > 0) {
|
|
@@ -7669,7 +8778,54 @@ var usageLine = (usage, durationMs) => {
|
|
|
7669
8778
|
if (durationMs !== void 0) parts.push(formatDuration(durationMs));
|
|
7670
8779
|
return parts.join(" \xB7 ");
|
|
7671
8780
|
};
|
|
7672
|
-
var
|
|
8781
|
+
var lengthOf = (ms) => typeof ms === "number" && Number.isFinite(ms) && ms >= 0 && ms < 864e5 ? ms : void 0;
|
|
8782
|
+
var settleAudioDuration = (el) => {
|
|
8783
|
+
if (el.duration !== Infinity) return;
|
|
8784
|
+
const back = () => {
|
|
8785
|
+
if (!Number.isFinite(el.duration)) return;
|
|
8786
|
+
el.removeEventListener("durationchange", back);
|
|
8787
|
+
el.removeEventListener("timeupdate", back);
|
|
8788
|
+
el.currentTime = 0;
|
|
8789
|
+
};
|
|
8790
|
+
el.addEventListener("durationchange", back);
|
|
8791
|
+
el.addEventListener("timeupdate", back);
|
|
8792
|
+
el.currentTime = Number.MAX_SAFE_INTEGER;
|
|
8793
|
+
};
|
|
8794
|
+
var AttachedAudio = ({
|
|
8795
|
+
attachment: a,
|
|
8796
|
+
files,
|
|
8797
|
+
labels
|
|
8798
|
+
}) => {
|
|
8799
|
+
const L = useLabels(labels);
|
|
8800
|
+
const type = a.mediaType.toLowerCase().split(";")[0].trim();
|
|
8801
|
+
const url = useFileUrl(files, a.path ?? "", files && a.path ? type : void 0);
|
|
8802
|
+
const length = lengthOf(a.durationMs);
|
|
8803
|
+
const said = length !== void 0 ? L.audioDuration(formatClock(length)) : void 0;
|
|
8804
|
+
return url ? /* @__PURE__ */ jsxs14("span", { className: "awr-media awr-media--audio awr-msg__audio", title: a.path ?? a.name, children: [
|
|
8805
|
+
/* @__PURE__ */ jsx16(
|
|
8806
|
+
"audio",
|
|
8807
|
+
{
|
|
8808
|
+
className: "awr-media__audio",
|
|
8809
|
+
controls: true,
|
|
8810
|
+
preload: "metadata",
|
|
8811
|
+
src: url,
|
|
8812
|
+
"aria-label": said ? `${L.audioAttachment(a.name)} (${said})` : L.audioAttachment(a.name),
|
|
8813
|
+
onLoadedMetadata: (e) => settleAudioDuration(e.currentTarget)
|
|
8814
|
+
}
|
|
8815
|
+
),
|
|
8816
|
+
said && /* @__PURE__ */ jsx16("span", { className: "awr-msg__audiolen", "aria-hidden": "true", children: said })
|
|
8817
|
+
] }) : /* @__PURE__ */ jsxs14("span", { className: "awr-chip awr-file", title: a.path ?? a.mediaType, children: [
|
|
8818
|
+
/* @__PURE__ */ jsx16(WaveIcon, { size: 13 }),
|
|
8819
|
+
" ",
|
|
8820
|
+
a.name,
|
|
8821
|
+
said ? ` \xB7 ${said}` : ""
|
|
8822
|
+
] });
|
|
8823
|
+
};
|
|
8824
|
+
var AttachmentView = ({
|
|
8825
|
+
attachment: a,
|
|
8826
|
+
files,
|
|
8827
|
+
labels
|
|
8828
|
+
}) => mediaFamilyOf(a.mediaType) === "audio" ? /* @__PURE__ */ jsx16(AttachedAudio, { attachment: a, files, labels }) : a.dataUrl && a.mediaType.startsWith("image/") ? /* @__PURE__ */ jsx16(
|
|
7673
8829
|
ImageThumb,
|
|
7674
8830
|
{
|
|
7675
8831
|
src: a.dataUrl,
|
|
@@ -7732,10 +8888,12 @@ var MessageList = ({
|
|
|
7732
8888
|
showApps = true,
|
|
7733
8889
|
imageViewer = true,
|
|
7734
8890
|
renderImageViewer,
|
|
8891
|
+
readAloud,
|
|
7735
8892
|
labels,
|
|
7736
8893
|
className
|
|
7737
8894
|
}) => {
|
|
7738
8895
|
const L = useLabels(labels);
|
|
8896
|
+
const reader = useReadAloud(readAloud?.speak, readAloud?.lang);
|
|
7739
8897
|
if (messages.length === 0) {
|
|
7740
8898
|
return empty ? /* @__PURE__ */ jsx16("div", { className: "awr-messages__empty", children: empty }) : null;
|
|
7741
8899
|
}
|
|
@@ -7831,7 +8989,24 @@ var MessageList = ({
|
|
|
7831
8989
|
labels
|
|
7832
8990
|
}
|
|
7833
8991
|
) : null,
|
|
7834
|
-
m.attachments?.length ? /* @__PURE__ */ jsx16(
|
|
8992
|
+
m.attachments?.length ? /* @__PURE__ */ jsx16(
|
|
8993
|
+
"div",
|
|
8994
|
+
{
|
|
8995
|
+
className: "awr-msg__attachments",
|
|
8996
|
+
role: "group",
|
|
8997
|
+
"aria-label": m.content.trim() ? L.attachments : attachmentsText(m.attachments, { voiceMessage: L.voiceMessage }),
|
|
8998
|
+
children: m.attachments.map((a, i) => /* @__PURE__ */ jsx16("span", { className: "awr-msg__attachment", children: renderAttachment ? renderAttachment(a, m) : /* @__PURE__ */ jsx16(AttachmentView, { attachment: a, files, labels }) }, i))
|
|
8999
|
+
}
|
|
9000
|
+
) : null,
|
|
9001
|
+
readAloud && m.role === "assistant" && m.content && !m.pending && !m.error && /* @__PURE__ */ jsx16(
|
|
9002
|
+
ReadAloudControl,
|
|
9003
|
+
{
|
|
9004
|
+
id: m.id,
|
|
9005
|
+
text: () => readAloud.textOf ? readAloud.textOf(m) : speakableText(m.content, { code: L.readAloudCode }),
|
|
9006
|
+
reader,
|
|
9007
|
+
labels: L
|
|
9008
|
+
}
|
|
9009
|
+
),
|
|
7835
9010
|
m.role === "assistant" && usage && !m.pending && /* @__PURE__ */ jsx16("div", { className: "awr-msg__usage", title: L.usageTitle, children: usage })
|
|
7836
9011
|
] })
|
|
7837
9012
|
},
|
|
@@ -7840,6 +9015,78 @@ var MessageList = ({
|
|
|
7840
9015
|
return renderMessage ? /* @__PURE__ */ jsx16("div", { children: renderMessage(m, node) }, m.id) : node;
|
|
7841
9016
|
}) }) });
|
|
7842
9017
|
};
|
|
9018
|
+
var ReadAloudControl = ({
|
|
9019
|
+
id,
|
|
9020
|
+
text,
|
|
9021
|
+
reader,
|
|
9022
|
+
labels: L
|
|
9023
|
+
}) => {
|
|
9024
|
+
const mine = reader.current === id;
|
|
9025
|
+
const failed = reader.failed?.id === id ? reader.failed : void 0;
|
|
9026
|
+
return /* @__PURE__ */ jsxs14("div", { className: "awr-readaloud", "data-state": mine ? reader.state : "idle", children: [
|
|
9027
|
+
!mine ? /* @__PURE__ */ jsxs14(
|
|
9028
|
+
"button",
|
|
9029
|
+
{
|
|
9030
|
+
type: "button",
|
|
9031
|
+
className: "awr-linkbtn awr-readaloud__btn",
|
|
9032
|
+
onClick: () => reader.start(id, text()),
|
|
9033
|
+
"aria-label": L.readAloud,
|
|
9034
|
+
children: [
|
|
9035
|
+
/* @__PURE__ */ jsx16(SpeakerIcon, { size: 14 }),
|
|
9036
|
+
" ",
|
|
9037
|
+
L.readAloud
|
|
9038
|
+
]
|
|
9039
|
+
}
|
|
9040
|
+
) : /* @__PURE__ */ jsxs14(Fragment12, { children: [
|
|
9041
|
+
reader.state === "loading" ? /* @__PURE__ */ jsxs14("span", { className: "awr-readaloud__status", role: "status", children: [
|
|
9042
|
+
/* @__PURE__ */ jsx16(SpinnerIcon, { size: 14 }),
|
|
9043
|
+
" ",
|
|
9044
|
+
L.readAloudLoading
|
|
9045
|
+
] }) : reader.state === "paused" ? /* @__PURE__ */ jsxs14(
|
|
9046
|
+
"button",
|
|
9047
|
+
{
|
|
9048
|
+
type: "button",
|
|
9049
|
+
className: "awr-linkbtn awr-readaloud__btn",
|
|
9050
|
+
onClick: reader.resume,
|
|
9051
|
+
"aria-label": L.readAloudResume,
|
|
9052
|
+
children: [
|
|
9053
|
+
/* @__PURE__ */ jsx16(PlayIcon, { size: 14 }),
|
|
9054
|
+
" ",
|
|
9055
|
+
L.readAloudResume
|
|
9056
|
+
]
|
|
9057
|
+
}
|
|
9058
|
+
) : /* @__PURE__ */ jsxs14(
|
|
9059
|
+
"button",
|
|
9060
|
+
{
|
|
9061
|
+
type: "button",
|
|
9062
|
+
className: "awr-linkbtn awr-readaloud__btn",
|
|
9063
|
+
onClick: reader.pause,
|
|
9064
|
+
"aria-label": L.readAloudPause,
|
|
9065
|
+
children: [
|
|
9066
|
+
/* @__PURE__ */ jsx16(PauseIcon, { size: 14 }),
|
|
9067
|
+
" ",
|
|
9068
|
+
L.readAloudPause
|
|
9069
|
+
]
|
|
9070
|
+
}
|
|
9071
|
+
),
|
|
9072
|
+
/* @__PURE__ */ jsxs14(
|
|
9073
|
+
"button",
|
|
9074
|
+
{
|
|
9075
|
+
type: "button",
|
|
9076
|
+
className: "awr-linkbtn awr-readaloud__btn",
|
|
9077
|
+
onClick: reader.stop,
|
|
9078
|
+
"aria-label": L.readAloudStop,
|
|
9079
|
+
children: [
|
|
9080
|
+
/* @__PURE__ */ jsx16(StopIcon, { size: 14 }),
|
|
9081
|
+
" ",
|
|
9082
|
+
L.readAloudStop
|
|
9083
|
+
]
|
|
9084
|
+
}
|
|
9085
|
+
)
|
|
9086
|
+
] }),
|
|
9087
|
+
failed && /* @__PURE__ */ jsx16("span", { className: "awr-readaloud__error", role: "alert", children: failed.message ?? L.readAloudFailed })
|
|
9088
|
+
] });
|
|
9089
|
+
};
|
|
7843
9090
|
|
|
7844
9091
|
// src/components/ModelLoadBar.tsx
|
|
7845
9092
|
import { jsx as jsx17, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
@@ -7858,11 +9105,11 @@ var ModelLoadBar = ({ load, className }) => {
|
|
|
7858
9105
|
};
|
|
7859
9106
|
|
|
7860
9107
|
// src/components/QuestionPrompt.tsx
|
|
7861
|
-
import { useEffect as
|
|
9108
|
+
import { useEffect as useEffect19, useId as useId2, useRef as useRef13, useState as useState19 } from "react";
|
|
7862
9109
|
import { jsx as jsx18, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
7863
9110
|
var useNow2 = (active) => {
|
|
7864
|
-
const [now, setNow] =
|
|
7865
|
-
|
|
9111
|
+
const [now, setNow] = useState19(() => Date.now());
|
|
9112
|
+
useEffect19(() => {
|
|
7866
9113
|
if (!active) return;
|
|
7867
9114
|
setNow(Date.now());
|
|
7868
9115
|
const timer = setInterval(() => setNow(Date.now()), 1e3);
|
|
@@ -7894,12 +9141,12 @@ var QuestionCard = ({
|
|
|
7894
9141
|
const baseId = useId2();
|
|
7895
9142
|
const textId = `${baseId}-q`;
|
|
7896
9143
|
const otherId = `${baseId}-other`;
|
|
7897
|
-
const [picked, setPicked] =
|
|
7898
|
-
const [otherOpen, setOtherOpen] =
|
|
7899
|
-
const [otherText, setOtherText] =
|
|
7900
|
-
const otherField =
|
|
7901
|
-
const otherButton =
|
|
7902
|
-
|
|
9144
|
+
const [picked, setPicked] = useState19([]);
|
|
9145
|
+
const [otherOpen, setOtherOpen] = useState19(false);
|
|
9146
|
+
const [otherText, setOtherText] = useState19("");
|
|
9147
|
+
const otherField = useRef13(null);
|
|
9148
|
+
const otherButton = useRef13(null);
|
|
9149
|
+
useEffect19(() => {
|
|
7903
9150
|
if (otherOpen) otherField.current?.focus();
|
|
7904
9151
|
}, [otherOpen]);
|
|
7905
9152
|
const helper = showHelper && q.subagent ? { ...q.subagent, ...view?.subagent } : void 0;
|
|
@@ -8067,7 +9314,7 @@ var QuestionPrompt = ({
|
|
|
8067
9314
|
className
|
|
8068
9315
|
}) => {
|
|
8069
9316
|
const L = useLabels(labels);
|
|
8070
|
-
const [dismissed, setDismissed] =
|
|
9317
|
+
const [dismissed, setDismissed] = useState19(() => /* @__PURE__ */ new Set());
|
|
8071
9318
|
const automatic = showOutcomes ? (outcomes ?? []).filter(
|
|
8072
9319
|
(o) => o.automatic === true && o.status !== "pending" && o.status !== "stopped" && !dismissed.has(o.id)
|
|
8073
9320
|
) : [];
|
|
@@ -8321,13 +9568,13 @@ var UsageBadge = ({
|
|
|
8321
9568
|
};
|
|
8322
9569
|
|
|
8323
9570
|
// src/components/AgentChat.tsx
|
|
8324
|
-
import { Fragment as
|
|
9571
|
+
import { Fragment as Fragment13, jsx as jsx20, jsxs as jsxs19 } from "react/jsx-runtime";
|
|
8325
9572
|
var usePrefersDark = () => {
|
|
8326
9573
|
const query = "(prefers-color-scheme: dark)";
|
|
8327
|
-
const [dark, setDark] =
|
|
9574
|
+
const [dark, setDark] = useState20(
|
|
8328
9575
|
() => typeof matchMedia === "function" && matchMedia(query).matches
|
|
8329
9576
|
);
|
|
8330
|
-
|
|
9577
|
+
useEffect20(() => {
|
|
8331
9578
|
if (typeof matchMedia !== "function") return;
|
|
8332
9579
|
const mq = matchMedia(query);
|
|
8333
9580
|
const on = () => setDark(mq.matches);
|
|
@@ -8382,6 +9629,7 @@ var AgentChatInner = ({
|
|
|
8382
9629
|
renderContent,
|
|
8383
9630
|
renderMessage,
|
|
8384
9631
|
renderAttachment,
|
|
9632
|
+
readAloud,
|
|
8385
9633
|
renderToolCall,
|
|
8386
9634
|
renderSubagent,
|
|
8387
9635
|
renderMedia,
|
|
@@ -8417,17 +9665,19 @@ var AgentChatInner = ({
|
|
|
8417
9665
|
}
|
|
8418
9666
|
const L = useLabels();
|
|
8419
9667
|
const external = isHistoryHook(history) ? history : void 0;
|
|
8420
|
-
const [ownStore] =
|
|
9668
|
+
const [ownStore] = useState20(
|
|
8421
9669
|
() => history instanceof ChatHistoryStore ? history : new ChatHistoryStore()
|
|
8422
9670
|
);
|
|
8423
9671
|
const own = useChatHistory(agent, {
|
|
8424
9672
|
store: ownStore,
|
|
8425
|
-
enabled: Boolean(history) && !external
|
|
9673
|
+
enabled: Boolean(history) && !external,
|
|
9674
|
+
// A chat begun by a voice message is titled in the chat's language.
|
|
9675
|
+
labels: { voiceMessage: L.voiceMessage }
|
|
8426
9676
|
});
|
|
8427
9677
|
const chats = history ? external ?? own : void 0;
|
|
8428
|
-
const rootRef =
|
|
8429
|
-
const [narrow, setNarrow] =
|
|
8430
|
-
|
|
9678
|
+
const rootRef = useRef14(null);
|
|
9679
|
+
const [narrow, setNarrow] = useState20(void 0);
|
|
9680
|
+
useEffect20(() => {
|
|
8431
9681
|
const el = rootRef.current;
|
|
8432
9682
|
if (!el || typeof ResizeObserver === "undefined") return setNarrow(false);
|
|
8433
9683
|
const measure2 = () => setNarrow(el.getBoundingClientRect().width < narrowWidth);
|
|
@@ -8436,9 +9686,9 @@ var AgentChatInner = ({
|
|
|
8436
9686
|
ro.observe(el);
|
|
8437
9687
|
return () => ro.disconnect();
|
|
8438
9688
|
}, [narrowWidth]);
|
|
8439
|
-
const [historyChoice, setHistoryOpen] =
|
|
9689
|
+
const [historyChoice, setHistoryOpen] = useState20(defaultHistoryOpen);
|
|
8440
9690
|
const historyOpen = historyChoice ?? narrow === false;
|
|
8441
|
-
const [filesOpen, setFilesOpen] =
|
|
9691
|
+
const [filesOpen, setFilesOpen] = useState20(defaultFilesOpen);
|
|
8442
9692
|
const toggleHistory = () => {
|
|
8443
9693
|
setHistoryOpen(!historyOpen);
|
|
8444
9694
|
if (narrow && !historyOpen) setFilesOpen(false);
|
|
@@ -8456,7 +9706,7 @@ var AgentChatInner = ({
|
|
|
8456
9706
|
setHistoryOpen(false);
|
|
8457
9707
|
setFilesOpen(false);
|
|
8458
9708
|
};
|
|
8459
|
-
|
|
9709
|
+
useEffect20(() => {
|
|
8460
9710
|
if (!overlayOpen) return;
|
|
8461
9711
|
const onKey = (e) => {
|
|
8462
9712
|
if (e.key !== "Escape" || e.defaultPrevented) return;
|
|
@@ -8466,7 +9716,7 @@ var AgentChatInner = ({
|
|
|
8466
9716
|
document.addEventListener("keydown", onKey);
|
|
8467
9717
|
return () => document.removeEventListener("keydown", onKey);
|
|
8468
9718
|
}, [overlayOpen]);
|
|
8469
|
-
const bodyRef =
|
|
9719
|
+
const bodyRef = useRef14(null);
|
|
8470
9720
|
const appHost = useMcpAppHost({
|
|
8471
9721
|
connection: mcpApps,
|
|
8472
9722
|
approve: agent.approveAppToolCall,
|
|
@@ -8478,7 +9728,7 @@ var AgentChatInner = ({
|
|
|
8478
9728
|
});
|
|
8479
9729
|
const prefersDark = usePrefersDark();
|
|
8480
9730
|
const appTheme = theme === "auto" ? prefersDark ? "dark" : "light" : theme;
|
|
8481
|
-
const [panelApp, setPanelAppState] =
|
|
9731
|
+
const [panelApp, setPanelAppState] = useState20();
|
|
8482
9732
|
const setPanelApp = (app) => {
|
|
8483
9733
|
setPanelAppState(app);
|
|
8484
9734
|
onAppPanel?.(app);
|
|
@@ -8492,7 +9742,7 @@ var AgentChatInner = ({
|
|
|
8492
9742
|
const panelAllowed = appPanel !== false && appPanel !== null;
|
|
8493
9743
|
const panelTarget = typeof appPanel === "object" && appPanel ? appPanel : void 0;
|
|
8494
9744
|
const asSheet = !panelTarget && (appPanel === "sheet" || Boolean(narrow));
|
|
8495
|
-
|
|
9745
|
+
useEffect20(() => {
|
|
8496
9746
|
if (panelApp && !agent.messages.some((m) => m.apps?.some((a) => a.id === panelApp.id))) {
|
|
8497
9747
|
setPanelAppState(void 0);
|
|
8498
9748
|
onAppPanel?.(void 0);
|
|
@@ -8532,7 +9782,7 @@ var AgentChatInner = ({
|
|
|
8532
9782
|
},
|
|
8533
9783
|
panelApp.id
|
|
8534
9784
|
) : null;
|
|
8535
|
-
const [compacting, setCompacting] =
|
|
9785
|
+
const [compacting, setCompacting] = useState20(false);
|
|
8536
9786
|
const compact = () => {
|
|
8537
9787
|
setCompacting(true);
|
|
8538
9788
|
void agent.compact().finally(() => setCompacting(false));
|
|
@@ -8554,7 +9804,7 @@ var AgentChatInner = ({
|
|
|
8554
9804
|
const showReplan = agent.replan && agent.replan.mode !== "continue";
|
|
8555
9805
|
const replanFailedEarly = showReplanFailed && agent.replan?.failed === true && agent.steps.length === 0;
|
|
8556
9806
|
const earlyDecisions = showDecisions ? agent.decisions ?? [] : [];
|
|
8557
|
-
const liveExtra = agent.planThought.trim() || showReplan || replanFailedEarly || earlyDecisions.length > 0 ? /* @__PURE__ */ jsxs19(
|
|
9807
|
+
const liveExtra = agent.planThought.trim() || showReplan || replanFailedEarly || earlyDecisions.length > 0 ? /* @__PURE__ */ jsxs19(Fragment13, { children: [
|
|
8558
9808
|
agent.planThought.trim() && /* @__PURE__ */ jsxs19("details", { className: "awr-activity__plan", children: [
|
|
8559
9809
|
/* @__PURE__ */ jsx20("summary", { children: L.planned }),
|
|
8560
9810
|
/* @__PURE__ */ jsx20("p", { className: "awr-activity__thought", children: agent.planThought })
|
|
@@ -8690,6 +9940,7 @@ var AgentChatInner = ({
|
|
|
8690
9940
|
renderContent,
|
|
8691
9941
|
renderMessage,
|
|
8692
9942
|
renderAttachment,
|
|
9943
|
+
readAloud,
|
|
8693
9944
|
renderToolCall,
|
|
8694
9945
|
showApps: appsOn,
|
|
8695
9946
|
renderApp: appsOn ? drawApp : void 0,
|
|
@@ -8781,7 +10032,7 @@ var AgentChatInner = ({
|
|
|
8781
10032
|
),
|
|
8782
10033
|
panelTarget
|
|
8783
10034
|
)
|
|
8784
|
-
) : asSheet ? /* @__PURE__ */ jsxs19(
|
|
10035
|
+
) : asSheet ? /* @__PURE__ */ jsxs19(Fragment13, { children: [
|
|
8785
10036
|
/* @__PURE__ */ jsx20("div", { className: "awr-sheet__scrim", onClick: () => setPanelApp(void 0) }),
|
|
8786
10037
|
/* @__PURE__ */ jsxs19(
|
|
8787
10038
|
"aside",
|
|
@@ -8865,7 +10116,7 @@ var LearnedSkills = ({
|
|
|
8865
10116
|
};
|
|
8866
10117
|
|
|
8867
10118
|
// src/components/Composer.tsx
|
|
8868
|
-
import { useState as
|
|
10119
|
+
import { useState as useState21 } from "react";
|
|
8869
10120
|
import { jsx as jsx22, jsxs as jsxs21 } from "react/jsx-runtime";
|
|
8870
10121
|
var Composer = ({
|
|
8871
10122
|
onSubmit,
|
|
@@ -8875,7 +10126,7 @@ var Composer = ({
|
|
|
8875
10126
|
placeholder = "Ask the agent to do something\u2026",
|
|
8876
10127
|
className
|
|
8877
10128
|
}) => {
|
|
8878
|
-
const [text, setText] =
|
|
10129
|
+
const [text, setText] = useState21("");
|
|
8879
10130
|
const submit = () => {
|
|
8880
10131
|
const value = text.trim();
|
|
8881
10132
|
if (!value || busy || disabled) return;
|
|
@@ -8988,7 +10239,7 @@ var ApprovalModeSwitch = ({
|
|
|
8988
10239
|
);
|
|
8989
10240
|
|
|
8990
10241
|
// src/components/ApiKeyForm.tsx
|
|
8991
|
-
import { useEffect as
|
|
10242
|
+
import { useEffect as useEffect21, useState as useState22 } from "react";
|
|
8992
10243
|
import { jsx as jsx25, jsxs as jsxs23 } from "react/jsx-runtime";
|
|
8993
10244
|
var ApiKeyForm = ({
|
|
8994
10245
|
credentials,
|
|
@@ -8998,10 +10249,10 @@ var ApiKeyForm = ({
|
|
|
8998
10249
|
onChange,
|
|
8999
10250
|
className
|
|
9000
10251
|
}) => {
|
|
9001
|
-
const [value, setValue] =
|
|
9002
|
-
const [present, setPresent] =
|
|
9003
|
-
const [busy, setBusy] =
|
|
9004
|
-
|
|
10252
|
+
const [value, setValue] = useState22("");
|
|
10253
|
+
const [present, setPresent] = useState22(false);
|
|
10254
|
+
const [busy, setBusy] = useState22(false);
|
|
10255
|
+
useEffect21(() => {
|
|
9005
10256
|
let active = true;
|
|
9006
10257
|
credentials.hasKey(credentialRef).then((has) => {
|
|
9007
10258
|
if (active) setPresent(has);
|
|
@@ -9121,6 +10372,7 @@ export {
|
|
|
9121
10372
|
APP_MAX_HEIGHT,
|
|
9122
10373
|
APP_MIN_HEIGHT,
|
|
9123
10374
|
ASK_USER_TOOL_NAME,
|
|
10375
|
+
ATTACHMENT_BOUNDS,
|
|
9124
10376
|
AgentChat,
|
|
9125
10377
|
AgentComposer,
|
|
9126
10378
|
AgentLabelsProvider,
|
|
@@ -9182,13 +10434,17 @@ export {
|
|
|
9182
10434
|
MemorySkillStore,
|
|
9183
10435
|
MemoryStore,
|
|
9184
10436
|
MessageList,
|
|
10437
|
+
MicError,
|
|
9185
10438
|
ModelLoadBar,
|
|
9186
10439
|
PlanView,
|
|
9187
10440
|
QUESTION_TIMEOUT_MS,
|
|
9188
10441
|
QuestionPrompt,
|
|
10442
|
+
RECORDING_DEFAULT_MAX_MS,
|
|
10443
|
+
RECORDING_TYPES,
|
|
9189
10444
|
SandboxedFrame,
|
|
9190
10445
|
SessionBusyError,
|
|
9191
10446
|
SourceView,
|
|
10447
|
+
SpeechOutputError,
|
|
9192
10448
|
StepList,
|
|
9193
10449
|
SubagentRow,
|
|
9194
10450
|
SubagentTree,
|
|
@@ -9215,7 +10471,12 @@ export {
|
|
|
9215
10471
|
askUserOutputKept,
|
|
9216
10472
|
askUserWith,
|
|
9217
10473
|
attachmentKindOf,
|
|
10474
|
+
attachmentOverLimit,
|
|
9218
10475
|
attachmentRefusal,
|
|
10476
|
+
attachmentTransformOf,
|
|
10477
|
+
attachmentsText,
|
|
10478
|
+
audioExtensionOf,
|
|
10479
|
+
audioTypeOf,
|
|
9219
10480
|
buildMcpAppDocument,
|
|
9220
10481
|
buildMcpAppSandboxShell,
|
|
9221
10482
|
buildSandboxedDocument,
|
|
@@ -9224,9 +10485,12 @@ export {
|
|
|
9224
10485
|
clampFrameHeight,
|
|
9225
10486
|
createAgent2 as createAgent,
|
|
9226
10487
|
createApprovalQueue,
|
|
10488
|
+
createAudioSpeaker,
|
|
10489
|
+
createBrowserSpeaker,
|
|
9227
10490
|
createFileTools,
|
|
9228
10491
|
createInitialAgentState,
|
|
9229
10492
|
createQuestionQueue,
|
|
10493
|
+
createRecordingRecognizer,
|
|
9230
10494
|
createRunControl2 as createRunControl,
|
|
9231
10495
|
createSubagentTool,
|
|
9232
10496
|
createWebLLMEngine,
|
|
@@ -9246,10 +10510,12 @@ export {
|
|
|
9246
10510
|
filterCommands,
|
|
9247
10511
|
followsAfterResize,
|
|
9248
10512
|
followsAfterScroll,
|
|
10513
|
+
formatClock,
|
|
9249
10514
|
formatCountdown,
|
|
9250
10515
|
formatElapsed,
|
|
9251
10516
|
grantedAppCsp,
|
|
9252
10517
|
imageExtensionOf,
|
|
10518
|
+
imageSizeOf,
|
|
9253
10519
|
isMcpAppSandboxMessage,
|
|
9254
10520
|
isWebGPUAvailable2 as isWebGPUAvailable,
|
|
9255
10521
|
lessonsOf,
|
|
@@ -9267,24 +10533,35 @@ export {
|
|
|
9267
10533
|
menuSections,
|
|
9268
10534
|
mergeChatRecord,
|
|
9269
10535
|
mergeLabels,
|
|
10536
|
+
messageOverLimit,
|
|
10537
|
+
micProblemOf,
|
|
10538
|
+
micProblemText,
|
|
9270
10539
|
newChatId,
|
|
9271
10540
|
noticesOf,
|
|
9272
10541
|
onStorageChange,
|
|
9273
10542
|
parseSkillMarkdown,
|
|
9274
10543
|
parseSlash,
|
|
9275
10544
|
pendingApprovalsOf,
|
|
10545
|
+
pickRecordingType,
|
|
9276
10546
|
postStorageChange2 as postStorageChange,
|
|
9277
10547
|
preloadWebLLMModel2 as preloadWebLLMModel,
|
|
9278
10548
|
questionChoiceOf,
|
|
9279
10549
|
questionOtherOf,
|
|
9280
10550
|
questionTimeoutOf,
|
|
10551
|
+
recordingSupported,
|
|
9281
10552
|
resolveAppDownload,
|
|
9282
10553
|
sandboxTokens,
|
|
9283
10554
|
sandboxedCsp,
|
|
9284
10555
|
saveAppFile,
|
|
9285
10556
|
saveChat,
|
|
9286
10557
|
serveSubagentWorker,
|
|
10558
|
+
settleAudioDuration,
|
|
10559
|
+
speakableText,
|
|
10560
|
+
speechSynthesisSupported,
|
|
10561
|
+
splitForSpeech,
|
|
10562
|
+
startRecording,
|
|
9287
10563
|
steerIntent,
|
|
10564
|
+
stopTracks,
|
|
9288
10565
|
subagentTree,
|
|
9289
10566
|
supportsImages,
|
|
9290
10567
|
supportsPdf,
|
|
@@ -9294,6 +10571,7 @@ export {
|
|
|
9294
10571
|
usageLine,
|
|
9295
10572
|
useAgent,
|
|
9296
10573
|
useAgentContext,
|
|
10574
|
+
useAudioRecorder,
|
|
9297
10575
|
useChatHistory,
|
|
9298
10576
|
useCredentials,
|
|
9299
10577
|
useFollowScroll,
|
|
@@ -9301,9 +10579,14 @@ export {
|
|
|
9301
10579
|
useLocalModel,
|
|
9302
10580
|
useMcpAppHost,
|
|
9303
10581
|
useOptionalAgentContext,
|
|
10582
|
+
useReadAloud,
|
|
9304
10583
|
useSpeechToText,
|
|
10584
|
+
useSpeechVoices,
|
|
9305
10585
|
useVirtualFiles,
|
|
9306
10586
|
useWebLLMModel,
|
|
10587
|
+
voiceFor,
|
|
10588
|
+
voiceMessageName,
|
|
10589
|
+
voicesOf,
|
|
9307
10590
|
watchSession2 as watchSession,
|
|
9308
10591
|
webSearchOf,
|
|
9309
10592
|
withAttachments,
|