@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.cjs
CHANGED
|
@@ -34,6 +34,7 @@ __export(src_exports, {
|
|
|
34
34
|
APP_MAX_HEIGHT: () => APP_MAX_HEIGHT,
|
|
35
35
|
APP_MIN_HEIGHT: () => APP_MIN_HEIGHT,
|
|
36
36
|
ASK_USER_TOOL_NAME: () => ASK_USER_TOOL_NAME,
|
|
37
|
+
ATTACHMENT_BOUNDS: () => ATTACHMENT_BOUNDS,
|
|
37
38
|
AgentChat: () => AgentChat,
|
|
38
39
|
AgentComposer: () => AgentComposer,
|
|
39
40
|
AgentLabelsProvider: () => AgentLabelsProvider,
|
|
@@ -95,13 +96,17 @@ __export(src_exports, {
|
|
|
95
96
|
MemorySkillStore: () => import_agent_web8.MemorySkillStore,
|
|
96
97
|
MemoryStore: () => import_agent_web8.MemoryStore,
|
|
97
98
|
MessageList: () => MessageList,
|
|
99
|
+
MicError: () => MicError,
|
|
98
100
|
ModelLoadBar: () => ModelLoadBar,
|
|
99
101
|
PlanView: () => PlanView,
|
|
100
102
|
QUESTION_TIMEOUT_MS: () => QUESTION_TIMEOUT_MS,
|
|
101
103
|
QuestionPrompt: () => QuestionPrompt,
|
|
104
|
+
RECORDING_DEFAULT_MAX_MS: () => RECORDING_DEFAULT_MAX_MS,
|
|
105
|
+
RECORDING_TYPES: () => RECORDING_TYPES,
|
|
102
106
|
SandboxedFrame: () => SandboxedFrame,
|
|
103
107
|
SessionBusyError: () => import_agent_web8.SessionBusyError,
|
|
104
108
|
SourceView: () => SourceView,
|
|
109
|
+
SpeechOutputError: () => SpeechOutputError,
|
|
105
110
|
StepList: () => StepList,
|
|
106
111
|
SubagentRow: () => SubagentRow,
|
|
107
112
|
SubagentTree: () => SubagentTree,
|
|
@@ -128,7 +133,12 @@ __export(src_exports, {
|
|
|
128
133
|
askUserOutputKept: () => askUserOutputKept,
|
|
129
134
|
askUserWith: () => askUserWith,
|
|
130
135
|
attachmentKindOf: () => attachmentKindOf,
|
|
136
|
+
attachmentOverLimit: () => attachmentOverLimit,
|
|
131
137
|
attachmentRefusal: () => attachmentRefusal,
|
|
138
|
+
attachmentTransformOf: () => attachmentTransformOf,
|
|
139
|
+
attachmentsText: () => attachmentsText,
|
|
140
|
+
audioExtensionOf: () => audioExtensionOf,
|
|
141
|
+
audioTypeOf: () => audioTypeOf,
|
|
132
142
|
buildMcpAppDocument: () => buildMcpAppDocument,
|
|
133
143
|
buildMcpAppSandboxShell: () => buildMcpAppSandboxShell,
|
|
134
144
|
buildSandboxedDocument: () => buildSandboxedDocument,
|
|
@@ -137,9 +147,12 @@ __export(src_exports, {
|
|
|
137
147
|
clampFrameHeight: () => clampFrameHeight,
|
|
138
148
|
createAgent: () => import_agent_web8.createAgent,
|
|
139
149
|
createApprovalQueue: () => createApprovalQueue,
|
|
150
|
+
createAudioSpeaker: () => createAudioSpeaker,
|
|
151
|
+
createBrowserSpeaker: () => createBrowserSpeaker,
|
|
140
152
|
createFileTools: () => import_agent_web8.createFileTools,
|
|
141
153
|
createInitialAgentState: () => createInitialAgentState,
|
|
142
154
|
createQuestionQueue: () => createQuestionQueue,
|
|
155
|
+
createRecordingRecognizer: () => createRecordingRecognizer,
|
|
143
156
|
createRunControl: () => import_agent_web8.createRunControl,
|
|
144
157
|
createSubagentTool: () => import_agent_web8.createSubagentTool,
|
|
145
158
|
createWebLLMEngine: () => createWebLLMEngine,
|
|
@@ -159,10 +172,12 @@ __export(src_exports, {
|
|
|
159
172
|
filterCommands: () => filterCommands,
|
|
160
173
|
followsAfterResize: () => followsAfterResize,
|
|
161
174
|
followsAfterScroll: () => followsAfterScroll,
|
|
175
|
+
formatClock: () => formatClock,
|
|
162
176
|
formatCountdown: () => formatCountdown,
|
|
163
177
|
formatElapsed: () => formatElapsed,
|
|
164
178
|
grantedAppCsp: () => grantedAppCsp,
|
|
165
179
|
imageExtensionOf: () => imageExtensionOf,
|
|
180
|
+
imageSizeOf: () => imageSizeOf,
|
|
166
181
|
isMcpAppSandboxMessage: () => isMcpAppSandboxMessage,
|
|
167
182
|
isWebGPUAvailable: () => import_agent_web8.isWebGPUAvailable,
|
|
168
183
|
lessonsOf: () => lessonsOf,
|
|
@@ -180,24 +195,35 @@ __export(src_exports, {
|
|
|
180
195
|
menuSections: () => menuSections,
|
|
181
196
|
mergeChatRecord: () => mergeChatRecord,
|
|
182
197
|
mergeLabels: () => mergeLabels,
|
|
198
|
+
messageOverLimit: () => messageOverLimit,
|
|
199
|
+
micProblemOf: () => micProblemOf,
|
|
200
|
+
micProblemText: () => micProblemText,
|
|
183
201
|
newChatId: () => newChatId,
|
|
184
202
|
noticesOf: () => noticesOf,
|
|
185
203
|
onStorageChange: () => import_agent_web8.onStorageChange,
|
|
186
204
|
parseSkillMarkdown: () => import_agent_web8.parseSkillMarkdown,
|
|
187
205
|
parseSlash: () => parseSlash,
|
|
188
206
|
pendingApprovalsOf: () => pendingApprovalsOf,
|
|
207
|
+
pickRecordingType: () => pickRecordingType,
|
|
189
208
|
postStorageChange: () => import_agent_web8.postStorageChange,
|
|
190
209
|
preloadWebLLMModel: () => import_agent_web8.preloadWebLLMModel,
|
|
191
210
|
questionChoiceOf: () => questionChoiceOf,
|
|
192
211
|
questionOtherOf: () => questionOtherOf,
|
|
193
212
|
questionTimeoutOf: () => questionTimeoutOf,
|
|
213
|
+
recordingSupported: () => recordingSupported,
|
|
194
214
|
resolveAppDownload: () => resolveAppDownload,
|
|
195
215
|
sandboxTokens: () => sandboxTokens,
|
|
196
216
|
sandboxedCsp: () => sandboxedCsp,
|
|
197
217
|
saveAppFile: () => saveAppFile,
|
|
198
218
|
saveChat: () => saveChat,
|
|
199
219
|
serveSubagentWorker: () => import_agent_web8.serveSubagentWorker,
|
|
220
|
+
settleAudioDuration: () => settleAudioDuration,
|
|
221
|
+
speakableText: () => speakableText,
|
|
222
|
+
speechSynthesisSupported: () => speechSynthesisSupported,
|
|
223
|
+
splitForSpeech: () => splitForSpeech,
|
|
224
|
+
startRecording: () => startRecording,
|
|
200
225
|
steerIntent: () => steerIntent,
|
|
226
|
+
stopTracks: () => stopTracks,
|
|
201
227
|
subagentTree: () => subagentTree,
|
|
202
228
|
supportsImages: () => import_agent_web8.supportsImages,
|
|
203
229
|
supportsPdf: () => import_agent_web8.supportsPdf,
|
|
@@ -207,6 +233,7 @@ __export(src_exports, {
|
|
|
207
233
|
usageLine: () => usageLine,
|
|
208
234
|
useAgent: () => useAgent,
|
|
209
235
|
useAgentContext: () => useAgentContext,
|
|
236
|
+
useAudioRecorder: () => useAudioRecorder,
|
|
210
237
|
useChatHistory: () => useChatHistory,
|
|
211
238
|
useCredentials: () => useCredentials,
|
|
212
239
|
useFollowScroll: () => useFollowScroll,
|
|
@@ -214,9 +241,14 @@ __export(src_exports, {
|
|
|
214
241
|
useLocalModel: () => useLocalModel,
|
|
215
242
|
useMcpAppHost: () => useMcpAppHost,
|
|
216
243
|
useOptionalAgentContext: () => useOptionalAgentContext,
|
|
244
|
+
useReadAloud: () => useReadAloud,
|
|
217
245
|
useSpeechToText: () => useSpeechToText,
|
|
246
|
+
useSpeechVoices: () => useSpeechVoices,
|
|
218
247
|
useVirtualFiles: () => useVirtualFiles,
|
|
219
248
|
useWebLLMModel: () => useWebLLMModel,
|
|
249
|
+
voiceFor: () => voiceFor,
|
|
250
|
+
voiceMessageName: () => voiceMessageName,
|
|
251
|
+
voicesOf: () => voicesOf,
|
|
220
252
|
watchSession: () => import_agent_web8.watchSession,
|
|
221
253
|
webSearchOf: () => webSearchOf,
|
|
222
254
|
withAttachments: () => withAttachments,
|
|
@@ -667,6 +699,13 @@ var mediaOf = (event, withStep) => ({
|
|
|
667
699
|
mediaType: event.mediaType,
|
|
668
700
|
bytes: event.bytes,
|
|
669
701
|
model: event.model,
|
|
702
|
+
...event.references ? {
|
|
703
|
+
references: {
|
|
704
|
+
used: event.references.used === true,
|
|
705
|
+
count: event.references.count,
|
|
706
|
+
paths: [...event.references.paths]
|
|
707
|
+
}
|
|
708
|
+
} : {},
|
|
670
709
|
...withStep && event.step ? { stepId: event.step.id } : {}
|
|
671
710
|
});
|
|
672
711
|
var addApp = (state, event, by) => {
|
|
@@ -1770,7 +1809,8 @@ var useAgent = (config, options = {}) => {
|
|
|
1770
1809
|
let began = false;
|
|
1771
1810
|
const shownGoal = runOptions?.label ?? goal;
|
|
1772
1811
|
dispatch({ type: "status", status: "running" });
|
|
1773
|
-
|
|
1812
|
+
const shownAtAll = Boolean(shownGoal.trim() || runOptions?.attachments?.length);
|
|
1813
|
+
if (shownAtAll) {
|
|
1774
1814
|
dispatch({
|
|
1775
1815
|
type: "submitted",
|
|
1776
1816
|
goal: shownGoal,
|
|
@@ -1790,14 +1830,16 @@ var useAgent = (config, options = {}) => {
|
|
|
1790
1830
|
startedRef.current = true;
|
|
1791
1831
|
began = true;
|
|
1792
1832
|
}
|
|
1793
|
-
const shown = start && runOptions?.label ? { ...event, goal: runOptions.label } : event;
|
|
1833
|
+
const shown = start && runOptions?.label !== void 0 ? { ...event, goal: runOptions.label } : event;
|
|
1794
1834
|
dispatch({
|
|
1795
1835
|
type: "event",
|
|
1796
1836
|
event: shown,
|
|
1797
1837
|
maxEvents: optionsRef.current.maxEvents,
|
|
1798
1838
|
at: Date.now(),
|
|
1799
1839
|
// What the user sent waits with the run: shown as queued meanwhile.
|
|
1800
|
-
...event.type === "session.busy" &&
|
|
1840
|
+
...event.type === "session.busy" && shownAtAll ? {
|
|
1841
|
+
goal: shownGoal.trim() || (runOptions?.attachments ?? []).map((a) => a.name).join(", ")
|
|
1842
|
+
} : {},
|
|
1801
1843
|
...start && runOptions?.attachments?.length ? { attachments: runOptions.attachments } : {}
|
|
1802
1844
|
});
|
|
1803
1845
|
try {
|
|
@@ -2164,8 +2206,17 @@ var ChatHistoryStore = class {
|
|
|
2164
2206
|
await this.write((store) => store.clear(), { op: "clear" });
|
|
2165
2207
|
}
|
|
2166
2208
|
};
|
|
2167
|
-
var
|
|
2168
|
-
|
|
2209
|
+
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(", ");
|
|
2210
|
+
var oneLine = (text2) => (text2 ?? "").replace(/\s+/g, " ").trim();
|
|
2211
|
+
var chatTitle = (messages, texts = {}) => {
|
|
2212
|
+
const at = messages.findIndex((m) => m.role === "user");
|
|
2213
|
+
const user = at >= 0 ? messages[at] : void 0;
|
|
2214
|
+
let first = oneLine(user?.content);
|
|
2215
|
+
if (!first && user?.attachments?.length) {
|
|
2216
|
+
const answer = messages.slice(at + 1).find((m) => m.role === "assistant");
|
|
2217
|
+
const heard = answer?.transcripts?.find((t) => t.source === "attachment")?.text;
|
|
2218
|
+
first = oneLine(heard) || oneLine(attachmentsText(user.attachments, texts));
|
|
2219
|
+
}
|
|
2169
2220
|
if (!first) return "New chat";
|
|
2170
2221
|
return first.length > 60 ? `${first.slice(0, 59)}\u2026` : first;
|
|
2171
2222
|
};
|
|
@@ -2197,7 +2248,7 @@ var renumber = (own, after) => {
|
|
|
2197
2248
|
return own.map((m) => ({ ...m, id: `msg-${next += 1}` }));
|
|
2198
2249
|
};
|
|
2199
2250
|
var unchangedSince = (messages, base2) => base2 !== void 0 && messages.length === base2.known.size && messages.every((m) => base2.known.has(m));
|
|
2200
|
-
var mergeChatRecord = (view, stored, base2) => {
|
|
2251
|
+
var mergeChatRecord = (view, stored, base2, texts) => {
|
|
2201
2252
|
const local = view.messages.filter((m) => !m.remote);
|
|
2202
2253
|
if (!stored || base2 && stored.updatedAt <= base2.updatedAt) {
|
|
2203
2254
|
return { record: { ...view, messages: local }, merged: false };
|
|
@@ -2208,7 +2259,7 @@ var mergeChatRecord = (view, stored, base2) => {
|
|
|
2208
2259
|
record: {
|
|
2209
2260
|
...view,
|
|
2210
2261
|
createdAt: stored.createdAt,
|
|
2211
|
-
title: chatTitle(messages),
|
|
2262
|
+
title: chatTitle(messages, texts),
|
|
2212
2263
|
messages,
|
|
2213
2264
|
totalUsage: sumUsage(
|
|
2214
2265
|
stored.totalUsage,
|
|
@@ -2218,10 +2269,10 @@ var mergeChatRecord = (view, stored, base2) => {
|
|
|
2218
2269
|
merged: true
|
|
2219
2270
|
};
|
|
2220
2271
|
};
|
|
2221
|
-
var saveChat = async (store, view, base2) => {
|
|
2272
|
+
var saveChat = async (store, view, base2, texts) => {
|
|
2222
2273
|
let merged = false;
|
|
2223
2274
|
const record = await store.putMerged(view.id, (stored) => {
|
|
2224
|
-
const out = mergeChatRecord(view, stored, base2);
|
|
2275
|
+
const out = mergeChatRecord(view, stored, base2, texts);
|
|
2225
2276
|
merged = out.merged;
|
|
2226
2277
|
return out.record;
|
|
2227
2278
|
});
|
|
@@ -2229,6 +2280,8 @@ var saveChat = async (store, view, base2) => {
|
|
|
2229
2280
|
};
|
|
2230
2281
|
var useChatHistory = (agent, options = {}) => {
|
|
2231
2282
|
const enabled = options.enabled !== false;
|
|
2283
|
+
const textsRef = (0, import_react2.useRef)(options.labels);
|
|
2284
|
+
textsRef.current = options.labels;
|
|
2232
2285
|
const store = (0, import_react2.useMemo)(() => options.store ?? new ChatHistoryStore(), [options.store]);
|
|
2233
2286
|
const [chats, setChats] = (0, import_react2.useState)([]);
|
|
2234
2287
|
const [loading, setLoading] = (0, import_react2.useState)(enabled);
|
|
@@ -2322,14 +2375,14 @@ var useChatHistory = (agent, options = {}) => {
|
|
|
2322
2375
|
createdRef.current.set(sessionId, createdAt);
|
|
2323
2376
|
const view = {
|
|
2324
2377
|
id: sessionId,
|
|
2325
|
-
title: chatTitle(messages),
|
|
2378
|
+
title: chatTitle(messages, textsRef.current),
|
|
2326
2379
|
createdAt,
|
|
2327
2380
|
updatedAt: now,
|
|
2328
2381
|
messages,
|
|
2329
2382
|
totalUsage
|
|
2330
2383
|
};
|
|
2331
2384
|
void (async () => {
|
|
2332
|
-
const { record, merged } = await saveChat(store, view, base2);
|
|
2385
|
+
const { record, merged } = await saveChat(store, view, base2, textsRef.current);
|
|
2333
2386
|
baseRef.current = {
|
|
2334
2387
|
id: sessionId,
|
|
2335
2388
|
known: new Set(merged ? record.messages : messages),
|
|
@@ -2423,13 +2476,18 @@ var browserRecognizer = () => {
|
|
|
2423
2476
|
var useSpeechToText = (options = {}) => {
|
|
2424
2477
|
const optionsRef = (0, import_react4.useRef)(options);
|
|
2425
2478
|
optionsRef.current = options;
|
|
2426
|
-
const
|
|
2479
|
+
const own = options.createRecognizer;
|
|
2480
|
+
const factory = (0, import_react4.useMemo)(() => own ?? browserRecognizer(), [own]);
|
|
2427
2481
|
const [listening, setListening] = (0, import_react4.useState)(false);
|
|
2428
2482
|
const [interim, setInterim] = (0, import_react4.useState)("");
|
|
2429
2483
|
const [error, setError] = (0, import_react4.useState)();
|
|
2484
|
+
const [errorMessage, setErrorMessage] = (0, import_react4.useState)();
|
|
2485
|
+
const [finishing, setFinishing] = (0, import_react4.useState)(false);
|
|
2430
2486
|
const recRef = (0, import_react4.useRef)(void 0);
|
|
2431
2487
|
const stop = (0, import_react4.useCallback)(() => {
|
|
2432
|
-
recRef.current
|
|
2488
|
+
if (!recRef.current) return;
|
|
2489
|
+
setFinishing(true);
|
|
2490
|
+
recRef.current.stop();
|
|
2433
2491
|
}, []);
|
|
2434
2492
|
const start = (0, import_react4.useCallback)(() => {
|
|
2435
2493
|
if (!factory || recRef.current) return;
|
|
@@ -2447,15 +2505,22 @@ var useSpeechToText = (options = {}) => {
|
|
|
2447
2505
|
setInterim(pending);
|
|
2448
2506
|
};
|
|
2449
2507
|
rec.onerror = (ev) => {
|
|
2450
|
-
if (ev.error && ev.error !== "no-speech" && ev.error !== "aborted")
|
|
2508
|
+
if (ev.error && ev.error !== "no-speech" && ev.error !== "aborted") {
|
|
2509
|
+
setError(ev.error);
|
|
2510
|
+
setErrorMessage(ev.message);
|
|
2511
|
+
}
|
|
2451
2512
|
};
|
|
2452
2513
|
rec.onend = () => {
|
|
2514
|
+
if (recRef.current !== rec) return;
|
|
2453
2515
|
recRef.current = void 0;
|
|
2454
2516
|
setListening(false);
|
|
2517
|
+
setFinishing(false);
|
|
2455
2518
|
setInterim("");
|
|
2456
2519
|
};
|
|
2457
2520
|
recRef.current = rec;
|
|
2458
2521
|
setError(void 0);
|
|
2522
|
+
setErrorMessage(void 0);
|
|
2523
|
+
setFinishing(false);
|
|
2459
2524
|
try {
|
|
2460
2525
|
rec.start();
|
|
2461
2526
|
setListening(true);
|
|
@@ -2464,20 +2529,763 @@ var useSpeechToText = (options = {}) => {
|
|
|
2464
2529
|
setError(err instanceof Error ? err.message : String(err));
|
|
2465
2530
|
}
|
|
2466
2531
|
}, [factory]);
|
|
2467
|
-
(0, import_react4.useEffect)(
|
|
2532
|
+
(0, import_react4.useEffect)(
|
|
2533
|
+
() => () => {
|
|
2534
|
+
const rec = recRef.current;
|
|
2535
|
+
recRef.current = void 0;
|
|
2536
|
+
rec?.abort?.();
|
|
2537
|
+
},
|
|
2538
|
+
[factory]
|
|
2539
|
+
);
|
|
2468
2540
|
return {
|
|
2469
2541
|
supported: Boolean(factory),
|
|
2470
2542
|
listening,
|
|
2543
|
+
finishing,
|
|
2471
2544
|
interim,
|
|
2472
2545
|
error,
|
|
2546
|
+
errorMessage,
|
|
2473
2547
|
start,
|
|
2474
2548
|
stop,
|
|
2475
2549
|
toggle: () => recRef.current ? stop() : start()
|
|
2476
2550
|
};
|
|
2477
2551
|
};
|
|
2478
2552
|
|
|
2479
|
-
// src/hooks/use-
|
|
2553
|
+
// src/hooks/use-audio-recorder.ts
|
|
2480
2554
|
var import_react5 = require("react");
|
|
2555
|
+
|
|
2556
|
+
// src/voice/record.ts
|
|
2557
|
+
var MicError = class extends Error {
|
|
2558
|
+
code;
|
|
2559
|
+
constructor(code, message = code) {
|
|
2560
|
+
super(message);
|
|
2561
|
+
this.name = "MicError";
|
|
2562
|
+
this.code = code;
|
|
2563
|
+
}
|
|
2564
|
+
};
|
|
2565
|
+
var RECORDING_DEFAULT_MAX_MS = 5 * 60 * 1e3;
|
|
2566
|
+
var RECORDING_TYPES = [
|
|
2567
|
+
"audio/webm;codecs=opus",
|
|
2568
|
+
"audio/webm",
|
|
2569
|
+
"audio/mp4",
|
|
2570
|
+
"audio/ogg;codecs=opus",
|
|
2571
|
+
"audio/ogg"
|
|
2572
|
+
];
|
|
2573
|
+
var pickRecordingType = (isTypeSupported) => {
|
|
2574
|
+
if (!isTypeSupported) return void 0;
|
|
2575
|
+
for (const type of RECORDING_TYPES) {
|
|
2576
|
+
try {
|
|
2577
|
+
if (isTypeSupported(type)) return type;
|
|
2578
|
+
} catch {
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
2581
|
+
return void 0;
|
|
2582
|
+
};
|
|
2583
|
+
var audioTypeOf = (type) => {
|
|
2584
|
+
const base2 = (type ?? "").toLowerCase().split(";")[0].trim();
|
|
2585
|
+
if (/^(audio|video)\/(mp4|x-m4a|m4a|aac-mp4)$/.test(base2)) return "audio/mp4";
|
|
2586
|
+
if (/^(audio|video)\/webm$/.test(base2)) return "audio/webm";
|
|
2587
|
+
if (base2 === "audio/ogg" || base2 === "application/ogg") return "audio/ogg";
|
|
2588
|
+
if (base2 === "audio/wav" || base2 === "audio/x-wav" || base2 === "audio/wave") return "audio/wav";
|
|
2589
|
+
if (base2 === "audio/mpeg" || base2 === "audio/mp3") return "audio/mpeg";
|
|
2590
|
+
if (base2 === "audio/aac") return "audio/aac";
|
|
2591
|
+
return "audio/webm";
|
|
2592
|
+
};
|
|
2593
|
+
var audioExtensionOf = (type) => ({
|
|
2594
|
+
"audio/mp4": "m4a",
|
|
2595
|
+
"audio/ogg": "ogg",
|
|
2596
|
+
"audio/wav": "wav",
|
|
2597
|
+
"audio/mpeg": "mp3",
|
|
2598
|
+
"audio/aac": "aac"
|
|
2599
|
+
})[audioTypeOf(type)] ?? "webm";
|
|
2600
|
+
var micProblemOf = (err) => {
|
|
2601
|
+
if (err instanceof MicError) return err.code;
|
|
2602
|
+
const name = err && typeof err === "object" ? String(err.name) : "";
|
|
2603
|
+
if (name === "NotAllowedError" || name === "SecurityError" || name === "PermissionDeniedError")
|
|
2604
|
+
return "not-allowed";
|
|
2605
|
+
if (name === "NotFoundError" || name === "OverconstrainedError" || name === "DevicesNotFoundError")
|
|
2606
|
+
return "audio-capture";
|
|
2607
|
+
if (name === "NotReadableError" || name === "TrackStartError" || name === "AbortError")
|
|
2608
|
+
return "busy";
|
|
2609
|
+
if (name === "NotSupportedError" || name === "TypeError") return "unsupported";
|
|
2610
|
+
return "failed";
|
|
2611
|
+
};
|
|
2612
|
+
var defaults = (deps) => {
|
|
2613
|
+
const g = globalThis;
|
|
2614
|
+
const devices = g.navigator?.mediaDevices;
|
|
2615
|
+
return {
|
|
2616
|
+
getUserMedia: deps.getUserMedia ?? (devices?.getUserMedia ? devices.getUserMedia.bind(devices) : void 0),
|
|
2617
|
+
MediaRecorder: deps.MediaRecorder ?? g.MediaRecorder,
|
|
2618
|
+
now: deps.now ?? Date.now
|
|
2619
|
+
};
|
|
2620
|
+
};
|
|
2621
|
+
var recordingSupported = (deps = {}) => {
|
|
2622
|
+
const d = defaults(deps);
|
|
2623
|
+
return Boolean(d.getUserMedia && d.MediaRecorder);
|
|
2624
|
+
};
|
|
2625
|
+
var stopTracks = (stream) => {
|
|
2626
|
+
for (const track of stream?.getTracks() ?? []) {
|
|
2627
|
+
try {
|
|
2628
|
+
track.stop();
|
|
2629
|
+
} catch {
|
|
2630
|
+
}
|
|
2631
|
+
}
|
|
2632
|
+
};
|
|
2633
|
+
var startRecording = async (options = {}) => {
|
|
2634
|
+
const d = defaults(options);
|
|
2635
|
+
if (!d.getUserMedia || !d.MediaRecorder) throw new MicError("unsupported");
|
|
2636
|
+
let stream;
|
|
2637
|
+
try {
|
|
2638
|
+
stream = await d.getUserMedia({ audio: true });
|
|
2639
|
+
} catch (err) {
|
|
2640
|
+
throw new MicError(micProblemOf(err));
|
|
2641
|
+
}
|
|
2642
|
+
let recorder;
|
|
2643
|
+
try {
|
|
2644
|
+
const type = pickRecordingType(d.MediaRecorder.isTypeSupported?.bind(d.MediaRecorder));
|
|
2645
|
+
recorder = new d.MediaRecorder(stream, type ? { mimeType: type } : void 0);
|
|
2646
|
+
} catch (err) {
|
|
2647
|
+
stopTracks(stream);
|
|
2648
|
+
throw new MicError(micProblemOf(err) === "failed" ? "unsupported" : micProblemOf(err));
|
|
2649
|
+
}
|
|
2650
|
+
const startedAt = d.now();
|
|
2651
|
+
const chunks = [];
|
|
2652
|
+
let cancelled = false;
|
|
2653
|
+
let failure;
|
|
2654
|
+
let settle = () => {
|
|
2655
|
+
};
|
|
2656
|
+
const ended = new Promise((resolve) => settle = resolve);
|
|
2657
|
+
let finish;
|
|
2658
|
+
let fail;
|
|
2659
|
+
const result = new Promise((resolve, reject) => {
|
|
2660
|
+
finish = resolve;
|
|
2661
|
+
fail = reject;
|
|
2662
|
+
});
|
|
2663
|
+
result.catch(() => {
|
|
2664
|
+
});
|
|
2665
|
+
let limit;
|
|
2666
|
+
const end = () => {
|
|
2667
|
+
stopTracks(stream);
|
|
2668
|
+
clearTimeout(limit);
|
|
2669
|
+
settle();
|
|
2670
|
+
};
|
|
2671
|
+
recorder.ondataavailable = (event) => {
|
|
2672
|
+
if (event.data && event.data.size > 0) chunks.push(event.data);
|
|
2673
|
+
};
|
|
2674
|
+
recorder.onerror = () => {
|
|
2675
|
+
failure = new MicError("failed");
|
|
2676
|
+
end();
|
|
2677
|
+
fail?.(failure);
|
|
2678
|
+
};
|
|
2679
|
+
recorder.onstop = () => {
|
|
2680
|
+
end();
|
|
2681
|
+
if (cancelled) return fail?.(new MicError("failed", "cancelled"));
|
|
2682
|
+
if (failure) return fail?.(failure);
|
|
2683
|
+
const mediaType = audioTypeOf(recorder.mimeType || chunks[0]?.type);
|
|
2684
|
+
finish?.({
|
|
2685
|
+
blob: new Blob(chunks, { type: mediaType }),
|
|
2686
|
+
mediaType,
|
|
2687
|
+
durationMs: Math.max(0, d.now() - startedAt)
|
|
2688
|
+
});
|
|
2689
|
+
};
|
|
2690
|
+
const stopRecorder = () => {
|
|
2691
|
+
try {
|
|
2692
|
+
if (recorder.state !== "inactive") recorder.stop();
|
|
2693
|
+
else recorder.onstop?.();
|
|
2694
|
+
} catch {
|
|
2695
|
+
recorder.onstop?.();
|
|
2696
|
+
}
|
|
2697
|
+
};
|
|
2698
|
+
const maxMs = options.maxMs ?? RECORDING_DEFAULT_MAX_MS;
|
|
2699
|
+
limit = setTimeout(() => {
|
|
2700
|
+
stopRecorder();
|
|
2701
|
+
options.onLimit?.();
|
|
2702
|
+
}, maxMs);
|
|
2703
|
+
try {
|
|
2704
|
+
recorder.start(1e3);
|
|
2705
|
+
} catch (err) {
|
|
2706
|
+
end();
|
|
2707
|
+
throw new MicError(micProblemOf(err) === "failed" ? "unsupported" : micProblemOf(err));
|
|
2708
|
+
}
|
|
2709
|
+
return {
|
|
2710
|
+
startedAt,
|
|
2711
|
+
ended,
|
|
2712
|
+
stop: () => {
|
|
2713
|
+
stopRecorder();
|
|
2714
|
+
return result;
|
|
2715
|
+
},
|
|
2716
|
+
cancel: () => {
|
|
2717
|
+
cancelled = true;
|
|
2718
|
+
chunks.length = 0;
|
|
2719
|
+
stopRecorder();
|
|
2720
|
+
end();
|
|
2721
|
+
}
|
|
2722
|
+
};
|
|
2723
|
+
};
|
|
2724
|
+
|
|
2725
|
+
// src/hooks/use-audio-recorder.ts
|
|
2726
|
+
var useAudioRecorder = (options = {}) => {
|
|
2727
|
+
const opts = (0, import_react5.useRef)(options);
|
|
2728
|
+
opts.current = options;
|
|
2729
|
+
const [state, setState] = (0, import_react5.useState)("idle");
|
|
2730
|
+
const [elapsedMs, setElapsed] = (0, import_react5.useState)(0);
|
|
2731
|
+
const [error, setError] = (0, import_react5.useState)();
|
|
2732
|
+
const [limited, setLimited] = (0, import_react5.useState)();
|
|
2733
|
+
const rec = (0, import_react5.useRef)(void 0);
|
|
2734
|
+
const pending = (0, import_react5.useRef)(false);
|
|
2735
|
+
const gone = (0, import_react5.useRef)(false);
|
|
2736
|
+
(0, import_react5.useEffect)(() => {
|
|
2737
|
+
if (state !== "recording") return;
|
|
2738
|
+
const at = rec.current?.startedAt ?? Date.now();
|
|
2739
|
+
const now = opts.current.now ?? Date.now;
|
|
2740
|
+
setElapsed(Math.max(0, now() - at));
|
|
2741
|
+
const id = setInterval(() => setElapsed(Math.max(0, now() - at)), 250);
|
|
2742
|
+
return () => clearInterval(id);
|
|
2743
|
+
}, [state]);
|
|
2744
|
+
const start = (0, import_react5.useCallback)(async () => {
|
|
2745
|
+
if (rec.current || pending.current) return;
|
|
2746
|
+
pending.current = true;
|
|
2747
|
+
setError(void 0);
|
|
2748
|
+
setLimited(void 0);
|
|
2749
|
+
setState("starting");
|
|
2750
|
+
try {
|
|
2751
|
+
const started = await startRecording({
|
|
2752
|
+
...opts.current,
|
|
2753
|
+
onLimit: () => {
|
|
2754
|
+
const r = rec.current;
|
|
2755
|
+
rec.current = void 0;
|
|
2756
|
+
setState("stopping");
|
|
2757
|
+
void r?.stop().then(
|
|
2758
|
+
(audio) => !gone.current && setLimited(audio),
|
|
2759
|
+
() => void 0
|
|
2760
|
+
).finally(() => !gone.current && setState("idle"));
|
|
2761
|
+
}
|
|
2762
|
+
});
|
|
2763
|
+
if (gone.current) return started.cancel();
|
|
2764
|
+
rec.current = started;
|
|
2765
|
+
setState("recording");
|
|
2766
|
+
} catch (err) {
|
|
2767
|
+
if (!gone.current) {
|
|
2768
|
+
setError(micProblemOf(err));
|
|
2769
|
+
setState("idle");
|
|
2770
|
+
}
|
|
2771
|
+
} finally {
|
|
2772
|
+
pending.current = false;
|
|
2773
|
+
}
|
|
2774
|
+
}, []);
|
|
2775
|
+
const stop = (0, import_react5.useCallback)(async () => {
|
|
2776
|
+
const r = rec.current;
|
|
2777
|
+
if (!r) return void 0;
|
|
2778
|
+
rec.current = void 0;
|
|
2779
|
+
setState("stopping");
|
|
2780
|
+
try {
|
|
2781
|
+
return await r.stop();
|
|
2782
|
+
} catch {
|
|
2783
|
+
return void 0;
|
|
2784
|
+
} finally {
|
|
2785
|
+
if (!gone.current) setState("idle");
|
|
2786
|
+
}
|
|
2787
|
+
}, []);
|
|
2788
|
+
const cancel = (0, import_react5.useCallback)(() => {
|
|
2789
|
+
const r = rec.current;
|
|
2790
|
+
rec.current = void 0;
|
|
2791
|
+
r?.cancel();
|
|
2792
|
+
setLimited(void 0);
|
|
2793
|
+
setState("idle");
|
|
2794
|
+
}, []);
|
|
2795
|
+
(0, import_react5.useEffect)(() => {
|
|
2796
|
+
gone.current = false;
|
|
2797
|
+
return () => {
|
|
2798
|
+
gone.current = true;
|
|
2799
|
+
rec.current?.cancel();
|
|
2800
|
+
rec.current = void 0;
|
|
2801
|
+
};
|
|
2802
|
+
}, []);
|
|
2803
|
+
return {
|
|
2804
|
+
supported: recordingSupported(options),
|
|
2805
|
+
state,
|
|
2806
|
+
elapsedMs,
|
|
2807
|
+
error,
|
|
2808
|
+
limited,
|
|
2809
|
+
start,
|
|
2810
|
+
stop,
|
|
2811
|
+
cancel,
|
|
2812
|
+
clear: () => {
|
|
2813
|
+
setLimited(void 0);
|
|
2814
|
+
setError(void 0);
|
|
2815
|
+
}
|
|
2816
|
+
};
|
|
2817
|
+
};
|
|
2818
|
+
|
|
2819
|
+
// src/hooks/use-read-aloud.ts
|
|
2820
|
+
var import_react6 = require("react");
|
|
2821
|
+
var useReadAloud = (speak, lang) => {
|
|
2822
|
+
const [current, setCurrent] = (0, import_react6.useState)();
|
|
2823
|
+
const [state, setState] = (0, import_react6.useState)();
|
|
2824
|
+
const [failed, setFailed] = (0, import_react6.useState)();
|
|
2825
|
+
const playback = (0, import_react6.useRef)(void 0);
|
|
2826
|
+
const langRef = (0, import_react6.useRef)(lang);
|
|
2827
|
+
langRef.current = lang;
|
|
2828
|
+
const stop = (0, import_react6.useCallback)(() => {
|
|
2829
|
+
const now = playback.current;
|
|
2830
|
+
playback.current = void 0;
|
|
2831
|
+
now?.handle.stop();
|
|
2832
|
+
setCurrent(void 0);
|
|
2833
|
+
setState(void 0);
|
|
2834
|
+
}, []);
|
|
2835
|
+
const start = (0, import_react6.useCallback)(
|
|
2836
|
+
(id, text2) => {
|
|
2837
|
+
if (!speak) return;
|
|
2838
|
+
stop();
|
|
2839
|
+
setFailed(void 0);
|
|
2840
|
+
setCurrent(id);
|
|
2841
|
+
setState("loading");
|
|
2842
|
+
const mine = { id, handle: void 0 };
|
|
2843
|
+
playback.current = mine;
|
|
2844
|
+
let handle;
|
|
2845
|
+
try {
|
|
2846
|
+
handle = speak(text2, {
|
|
2847
|
+
lang: langRef.current,
|
|
2848
|
+
onState: (s) => {
|
|
2849
|
+
if (playback.current === mine) setState(s);
|
|
2850
|
+
}
|
|
2851
|
+
});
|
|
2852
|
+
} catch (err) {
|
|
2853
|
+
playback.current = void 0;
|
|
2854
|
+
setCurrent(void 0);
|
|
2855
|
+
setState(void 0);
|
|
2856
|
+
const own = err instanceof Error && err.name !== "SpeechOutputError";
|
|
2857
|
+
setFailed({ id, ...own && err.message ? { message: err.message } : {} });
|
|
2858
|
+
return;
|
|
2859
|
+
}
|
|
2860
|
+
mine.handle = handle;
|
|
2861
|
+
handle.done.then(
|
|
2862
|
+
() => {
|
|
2863
|
+
if (playback.current !== mine) return;
|
|
2864
|
+
playback.current = void 0;
|
|
2865
|
+
setCurrent(void 0);
|
|
2866
|
+
setState(void 0);
|
|
2867
|
+
},
|
|
2868
|
+
(err) => {
|
|
2869
|
+
if (playback.current !== mine) return;
|
|
2870
|
+
playback.current = void 0;
|
|
2871
|
+
setCurrent(void 0);
|
|
2872
|
+
setState(void 0);
|
|
2873
|
+
const own = err instanceof Error && err.name !== "SpeechOutputError";
|
|
2874
|
+
setFailed({ id, ...own && err.message ? { message: err.message } : {} });
|
|
2875
|
+
}
|
|
2876
|
+
);
|
|
2877
|
+
},
|
|
2878
|
+
[speak, stop]
|
|
2879
|
+
);
|
|
2880
|
+
(0, import_react6.useEffect)(() => stop, [speak, stop]);
|
|
2881
|
+
return {
|
|
2882
|
+
current,
|
|
2883
|
+
state,
|
|
2884
|
+
failed,
|
|
2885
|
+
start,
|
|
2886
|
+
pause: () => playback.current?.handle.pause(),
|
|
2887
|
+
resume: () => playback.current?.handle.resume(),
|
|
2888
|
+
stop
|
|
2889
|
+
};
|
|
2890
|
+
};
|
|
2891
|
+
|
|
2892
|
+
// src/hooks/use-speech-voices.ts
|
|
2893
|
+
var import_react7 = require("react");
|
|
2894
|
+
var useSpeechVoices = () => {
|
|
2895
|
+
const synth = typeof globalThis !== "undefined" ? globalThis.speechSynthesis : void 0;
|
|
2896
|
+
const read = () => {
|
|
2897
|
+
try {
|
|
2898
|
+
return (synth?.getVoices() ?? []).map((v) => ({
|
|
2899
|
+
voiceURI: v.voiceURI,
|
|
2900
|
+
name: v.name,
|
|
2901
|
+
lang: v.lang,
|
|
2902
|
+
localService: v.localService,
|
|
2903
|
+
default: v.default
|
|
2904
|
+
}));
|
|
2905
|
+
} catch {
|
|
2906
|
+
return [];
|
|
2907
|
+
}
|
|
2908
|
+
};
|
|
2909
|
+
const [voices, setVoices] = (0, import_react7.useState)(read);
|
|
2910
|
+
(0, import_react7.useEffect)(() => {
|
|
2911
|
+
if (!synth) return;
|
|
2912
|
+
const update = () => setVoices(read());
|
|
2913
|
+
update();
|
|
2914
|
+
synth.addEventListener?.("voiceschanged", update);
|
|
2915
|
+
return () => synth.removeEventListener?.("voiceschanged", update);
|
|
2916
|
+
}, [synth]);
|
|
2917
|
+
return voices;
|
|
2918
|
+
};
|
|
2919
|
+
|
|
2920
|
+
// src/voice/recognizer.ts
|
|
2921
|
+
var createRecordingRecognizer = (options) => () => {
|
|
2922
|
+
let recording;
|
|
2923
|
+
let starting;
|
|
2924
|
+
let stopAsked = false;
|
|
2925
|
+
let aborted = false;
|
|
2926
|
+
let ended = false;
|
|
2927
|
+
const controller = new AbortController();
|
|
2928
|
+
const rec = {
|
|
2929
|
+
lang: "",
|
|
2930
|
+
continuous: true,
|
|
2931
|
+
interimResults: false,
|
|
2932
|
+
onresult: null,
|
|
2933
|
+
onerror: null,
|
|
2934
|
+
onend: null,
|
|
2935
|
+
start() {
|
|
2936
|
+
if (starting) return;
|
|
2937
|
+
starting = (async () => {
|
|
2938
|
+
try {
|
|
2939
|
+
recording = await startRecording({
|
|
2940
|
+
...options,
|
|
2941
|
+
maxMs: options.maxMs,
|
|
2942
|
+
onLimit: () => rec.stop()
|
|
2943
|
+
});
|
|
2944
|
+
} catch (err) {
|
|
2945
|
+
if (!aborted) rec.onerror?.({ error: micProblemOf(err) });
|
|
2946
|
+
return finish();
|
|
2947
|
+
}
|
|
2948
|
+
if (aborted) {
|
|
2949
|
+
recording.cancel();
|
|
2950
|
+
return finish();
|
|
2951
|
+
}
|
|
2952
|
+
if (stopAsked) void transcribeNow();
|
|
2953
|
+
})();
|
|
2954
|
+
},
|
|
2955
|
+
stop() {
|
|
2956
|
+
if (stopAsked || ended) return;
|
|
2957
|
+
stopAsked = true;
|
|
2958
|
+
if (recording) void transcribeNow();
|
|
2959
|
+
},
|
|
2960
|
+
abort() {
|
|
2961
|
+
if (ended) return;
|
|
2962
|
+
aborted = true;
|
|
2963
|
+
controller.abort();
|
|
2964
|
+
recording?.cancel();
|
|
2965
|
+
if (!starting || recording) finish();
|
|
2966
|
+
}
|
|
2967
|
+
};
|
|
2968
|
+
const finish = () => {
|
|
2969
|
+
if (ended) return;
|
|
2970
|
+
ended = true;
|
|
2971
|
+
rec.onend?.();
|
|
2972
|
+
};
|
|
2973
|
+
let transcribing = false;
|
|
2974
|
+
const transcribeNow = async () => {
|
|
2975
|
+
if (transcribing || !recording) return;
|
|
2976
|
+
transcribing = true;
|
|
2977
|
+
let audio;
|
|
2978
|
+
try {
|
|
2979
|
+
audio = await recording.stop();
|
|
2980
|
+
} catch (err) {
|
|
2981
|
+
if (!aborted) rec.onerror?.({ error: micProblemOf(err) });
|
|
2982
|
+
return finish();
|
|
2983
|
+
}
|
|
2984
|
+
if (aborted) return finish();
|
|
2985
|
+
if (audio.blob.size === 0) return finish();
|
|
2986
|
+
try {
|
|
2987
|
+
const text2 = (await options.transcribe(audio, { lang: rec.lang, signal: controller.signal })).replace(/\s+/g, " ").trim();
|
|
2988
|
+
if (!aborted && text2)
|
|
2989
|
+
rec.onresult?.({
|
|
2990
|
+
resultIndex: 0,
|
|
2991
|
+
results: [{ isFinal: true, 0: { transcript: text2 } }]
|
|
2992
|
+
});
|
|
2993
|
+
} catch (err) {
|
|
2994
|
+
if (!aborted)
|
|
2995
|
+
rec.onerror?.({
|
|
2996
|
+
error: "transcription",
|
|
2997
|
+
message: err instanceof Error ? err.message : String(err)
|
|
2998
|
+
});
|
|
2999
|
+
}
|
|
3000
|
+
finish();
|
|
3001
|
+
};
|
|
3002
|
+
return rec;
|
|
3003
|
+
};
|
|
3004
|
+
|
|
3005
|
+
// src/voice/speak.ts
|
|
3006
|
+
var SpeechOutputError = class extends Error {
|
|
3007
|
+
code;
|
|
3008
|
+
constructor(code) {
|
|
3009
|
+
super(code);
|
|
3010
|
+
this.name = "SpeechOutputError";
|
|
3011
|
+
this.code = code;
|
|
3012
|
+
}
|
|
3013
|
+
};
|
|
3014
|
+
var asOutputError = (err) => err instanceof SpeechOutputError ? err : new SpeechOutputError(
|
|
3015
|
+
err && typeof err === "object" && "name" in err ? String(err.name) : "playback-failed"
|
|
3016
|
+
);
|
|
3017
|
+
var speakableText = (markdown, options = {}) => {
|
|
3018
|
+
const out = [];
|
|
3019
|
+
const lines = markdown.replace(/\r\n?/g, "\n").split("\n");
|
|
3020
|
+
let fence;
|
|
3021
|
+
let fenceSaid = false;
|
|
3022
|
+
for (const raw of lines) {
|
|
3023
|
+
const line = raw.trimEnd();
|
|
3024
|
+
const opener = /^\s*(`{3,}|~{3,})/.exec(line);
|
|
3025
|
+
if (fence !== void 0) {
|
|
3026
|
+
if (opener && opener[1][0] === fence[0] && opener[1].length >= fence.length) fence = void 0;
|
|
3027
|
+
continue;
|
|
3028
|
+
}
|
|
3029
|
+
if (opener) {
|
|
3030
|
+
fence = opener[1];
|
|
3031
|
+
if (options.code && !fenceSaid) out.push(options.code);
|
|
3032
|
+
fenceSaid = true;
|
|
3033
|
+
continue;
|
|
3034
|
+
}
|
|
3035
|
+
fenceSaid = false;
|
|
3036
|
+
if (/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/.test(line)) continue;
|
|
3037
|
+
if (/^\s*([-*_])\s*(\1\s*){2,}$/.test(line)) continue;
|
|
3038
|
+
let text2 = line.replace(/^\s{0,3}#{1,6}\s+/, "").replace(/^\s*>\s?/, "").replace(/^\s*(?:[-*+]|\d+[.)])\s+(\[[ xX]\]\s+)?/, "");
|
|
3039
|
+
if (/^\s*\|.*\|\s*$/.test(text2))
|
|
3040
|
+
text2 = text2.replace(/^\s*\||\|\s*$/g, "").split("|").map((c) => c.trim()).filter(Boolean).join(", ");
|
|
3041
|
+
text2 = text2.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();
|
|
3042
|
+
if (!text2) continue;
|
|
3043
|
+
out.push(/[.!?…:;。!?]$/.test(text2) ? text2 : `${text2}.`);
|
|
3044
|
+
}
|
|
3045
|
+
return out.join(" ").trim();
|
|
3046
|
+
};
|
|
3047
|
+
var hostOf = (url) => {
|
|
3048
|
+
try {
|
|
3049
|
+
return new URL(url).hostname.replace(/^www\./, "");
|
|
3050
|
+
} catch {
|
|
3051
|
+
return "";
|
|
3052
|
+
}
|
|
3053
|
+
};
|
|
3054
|
+
var splitForSpeech = (text2, max = 220) => {
|
|
3055
|
+
const pieces = [];
|
|
3056
|
+
let rest = text2.trim();
|
|
3057
|
+
while (rest.length > max) {
|
|
3058
|
+
const window2 = rest.slice(0, max + 1);
|
|
3059
|
+
let cut = -1;
|
|
3060
|
+
for (const m of window2.matchAll(/[.!?…。!?;:](\s|$)/g))
|
|
3061
|
+
if (m.index !== void 0 && m.index + 1 <= max) cut = m.index + 1;
|
|
3062
|
+
if (cut < max / 3) cut = window2.lastIndexOf(" ");
|
|
3063
|
+
if (cut <= 0) cut = max;
|
|
3064
|
+
pieces.push(rest.slice(0, cut).trim());
|
|
3065
|
+
rest = rest.slice(cut).trim();
|
|
3066
|
+
}
|
|
3067
|
+
if (rest) pieces.push(rest);
|
|
3068
|
+
return pieces;
|
|
3069
|
+
};
|
|
3070
|
+
var voiceFor = (voices, lang, preferred) => {
|
|
3071
|
+
if (preferred) {
|
|
3072
|
+
const chosen = voices.find((v) => v.voiceURI === preferred);
|
|
3073
|
+
if (chosen) return chosen;
|
|
3074
|
+
}
|
|
3075
|
+
if (!lang) return void 0;
|
|
3076
|
+
const norm = (l) => l.toLowerCase().replace(/_/g, "-");
|
|
3077
|
+
const want = norm(lang);
|
|
3078
|
+
const base2 = want.split("-")[0];
|
|
3079
|
+
const rank = (v) => [v.localService ? 1 : 0, v.default ? 1 : 0];
|
|
3080
|
+
const best = (list) => [...list].sort((a, b) => {
|
|
3081
|
+
const ra = rank(a);
|
|
3082
|
+
const rb = rank(b);
|
|
3083
|
+
return rb[0] - ra[0] || rb[1] - ra[1] || a.name.localeCompare(b.name);
|
|
3084
|
+
})[0];
|
|
3085
|
+
const exact = voices.filter((v) => norm(v.lang) === want);
|
|
3086
|
+
if (exact.length) return best(exact);
|
|
3087
|
+
const same = voices.filter((v) => norm(v.lang).split("-")[0] === base2);
|
|
3088
|
+
return same.length ? best(same) : void 0;
|
|
3089
|
+
};
|
|
3090
|
+
var voicesOf = (voices, lang) => {
|
|
3091
|
+
if (!lang) return [...voices];
|
|
3092
|
+
const base2 = lang.toLowerCase().split(/[-_]/)[0];
|
|
3093
|
+
return voices.filter((v) => v.lang.toLowerCase().split(/[-_]/)[0] === base2);
|
|
3094
|
+
};
|
|
3095
|
+
var speechSynthesisSupported = () => typeof globalThis !== "undefined" && "speechSynthesis" in globalThis && typeof globalThis.SpeechSynthesisUtterance === "function";
|
|
3096
|
+
var createBrowserSpeaker = (options = {}) => (text2, { lang, onState }) => {
|
|
3097
|
+
const synth = options.synth ?? globalThis.speechSynthesis;
|
|
3098
|
+
const make = options.createUtterance ?? ((t) => new globalThis.SpeechSynthesisUtterance(t));
|
|
3099
|
+
const voice = voiceFor(synth.getVoices(), lang, options.voice);
|
|
3100
|
+
let settle;
|
|
3101
|
+
let fail;
|
|
3102
|
+
const done = new Promise((resolve, reject) => {
|
|
3103
|
+
settle = resolve;
|
|
3104
|
+
fail = reject;
|
|
3105
|
+
});
|
|
3106
|
+
done.catch(() => {
|
|
3107
|
+
});
|
|
3108
|
+
let over = false;
|
|
3109
|
+
const end = (err) => {
|
|
3110
|
+
if (over) return;
|
|
3111
|
+
over = true;
|
|
3112
|
+
if (err) fail(err);
|
|
3113
|
+
else settle();
|
|
3114
|
+
};
|
|
3115
|
+
const pieces = splitForSpeech(text2);
|
|
3116
|
+
synth.cancel();
|
|
3117
|
+
if (pieces.length === 0) {
|
|
3118
|
+
end();
|
|
3119
|
+
return { pause() {
|
|
3120
|
+
}, resume() {
|
|
3121
|
+
}, stop() {
|
|
3122
|
+
}, done };
|
|
3123
|
+
}
|
|
3124
|
+
let started = false;
|
|
3125
|
+
pieces.forEach((piece, i) => {
|
|
3126
|
+
const u = make(piece);
|
|
3127
|
+
u.lang = voice?.lang ?? lang ?? "";
|
|
3128
|
+
try {
|
|
3129
|
+
u.voice = voice ?? null;
|
|
3130
|
+
} catch {
|
|
3131
|
+
}
|
|
3132
|
+
u.rate = options.rate ?? 1;
|
|
3133
|
+
u.onstart = () => {
|
|
3134
|
+
if (!started && !over) onState("playing");
|
|
3135
|
+
started = true;
|
|
3136
|
+
};
|
|
3137
|
+
u.onend = () => {
|
|
3138
|
+
if (i === pieces.length - 1) end();
|
|
3139
|
+
};
|
|
3140
|
+
u.onerror = (event) => {
|
|
3141
|
+
if (event.error === "interrupted" || event.error === "canceled") end();
|
|
3142
|
+
else end(new SpeechOutputError(event.error || "synthesis-failed"));
|
|
3143
|
+
};
|
|
3144
|
+
synth.speak(u);
|
|
3145
|
+
});
|
|
3146
|
+
onState("loading");
|
|
3147
|
+
return {
|
|
3148
|
+
pause: () => {
|
|
3149
|
+
if (over) return;
|
|
3150
|
+
synth.pause();
|
|
3151
|
+
onState("paused");
|
|
3152
|
+
},
|
|
3153
|
+
resume: () => {
|
|
3154
|
+
if (over) return;
|
|
3155
|
+
synth.resume();
|
|
3156
|
+
onState("playing");
|
|
3157
|
+
},
|
|
3158
|
+
stop: () => {
|
|
3159
|
+
if (over) return;
|
|
3160
|
+
synth.cancel();
|
|
3161
|
+
end();
|
|
3162
|
+
},
|
|
3163
|
+
done
|
|
3164
|
+
};
|
|
3165
|
+
};
|
|
3166
|
+
var silence = () => {
|
|
3167
|
+
const samples = 16;
|
|
3168
|
+
const view = new DataView(new ArrayBuffer(44 + samples * 2));
|
|
3169
|
+
const text2 = (at, s) => {
|
|
3170
|
+
for (let i = 0; i < s.length; i++) view.setUint8(at + i, s.charCodeAt(i));
|
|
3171
|
+
};
|
|
3172
|
+
text2(0, "RIFF");
|
|
3173
|
+
view.setUint32(4, 36 + samples * 2, true);
|
|
3174
|
+
text2(8, "WAVEfmt ");
|
|
3175
|
+
view.setUint32(16, 16, true);
|
|
3176
|
+
view.setUint16(20, 1, true);
|
|
3177
|
+
view.setUint16(22, 1, true);
|
|
3178
|
+
view.setUint32(24, 8e3, true);
|
|
3179
|
+
view.setUint32(28, 16e3, true);
|
|
3180
|
+
view.setUint16(32, 2, true);
|
|
3181
|
+
view.setUint16(34, 16, true);
|
|
3182
|
+
text2(36, "data");
|
|
3183
|
+
view.setUint32(40, samples * 2, true);
|
|
3184
|
+
return new Blob([view.buffer], { type: "audio/wav" });
|
|
3185
|
+
};
|
|
3186
|
+
var createAudioSpeaker = (options) => (text2, { lang, onState }) => {
|
|
3187
|
+
const urls = options.objectUrl ?? {
|
|
3188
|
+
create: (b) => URL.createObjectURL(b),
|
|
3189
|
+
revoke: (u) => URL.revokeObjectURL(u)
|
|
3190
|
+
};
|
|
3191
|
+
const audio = options.createAudio?.() ?? new Audio();
|
|
3192
|
+
const controller = new AbortController();
|
|
3193
|
+
const pieces = splitForSpeech(text2, options.maxChars ?? 2e3);
|
|
3194
|
+
let settle;
|
|
3195
|
+
let fail;
|
|
3196
|
+
const done = new Promise((resolve, reject) => {
|
|
3197
|
+
settle = resolve;
|
|
3198
|
+
fail = reject;
|
|
3199
|
+
});
|
|
3200
|
+
done.catch(() => {
|
|
3201
|
+
});
|
|
3202
|
+
let over = false;
|
|
3203
|
+
let paused = false;
|
|
3204
|
+
let current;
|
|
3205
|
+
const made = /* @__PURE__ */ new Map();
|
|
3206
|
+
const make = (i) => {
|
|
3207
|
+
if (!made.has(i)) {
|
|
3208
|
+
const p = options.synthesize(pieces[i], { lang, signal: controller.signal });
|
|
3209
|
+
p.catch(() => {
|
|
3210
|
+
});
|
|
3211
|
+
made.set(i, p);
|
|
3212
|
+
}
|
|
3213
|
+
return made.get(i);
|
|
3214
|
+
};
|
|
3215
|
+
const release = () => {
|
|
3216
|
+
if (current) urls.revoke(current);
|
|
3217
|
+
current = void 0;
|
|
3218
|
+
};
|
|
3219
|
+
const end = (err) => {
|
|
3220
|
+
if (over) return;
|
|
3221
|
+
over = true;
|
|
3222
|
+
controller.abort();
|
|
3223
|
+
audio.pause();
|
|
3224
|
+
audio.onended = null;
|
|
3225
|
+
audio.onerror = null;
|
|
3226
|
+
release();
|
|
3227
|
+
if (err) fail(err);
|
|
3228
|
+
else settle();
|
|
3229
|
+
};
|
|
3230
|
+
const playFrom = async (i) => {
|
|
3231
|
+
if (over) return;
|
|
3232
|
+
if (i >= pieces.length) return end();
|
|
3233
|
+
onState(i === 0 || !current ? "loading" : "playing");
|
|
3234
|
+
let blob;
|
|
3235
|
+
try {
|
|
3236
|
+
blob = await make(i);
|
|
3237
|
+
} catch (err) {
|
|
3238
|
+
return end(err instanceof Error ? err : new Error(String(err)));
|
|
3239
|
+
}
|
|
3240
|
+
if (over) return;
|
|
3241
|
+
if (i + 1 < pieces.length) make(i + 1);
|
|
3242
|
+
release();
|
|
3243
|
+
current = urls.create(blob);
|
|
3244
|
+
audio.src = current;
|
|
3245
|
+
audio.onended = () => void playFrom(i + 1);
|
|
3246
|
+
audio.onerror = () => end(new SpeechOutputError("playback-failed"));
|
|
3247
|
+
if (paused) return onState("paused");
|
|
3248
|
+
try {
|
|
3249
|
+
await audio.play();
|
|
3250
|
+
if (!over) onState("playing");
|
|
3251
|
+
} catch (err) {
|
|
3252
|
+
end(asOutputError(err));
|
|
3253
|
+
}
|
|
3254
|
+
};
|
|
3255
|
+
if (pieces.length === 0) end();
|
|
3256
|
+
else {
|
|
3257
|
+
if (options.unlock !== false) {
|
|
3258
|
+
current = urls.create(silence());
|
|
3259
|
+
audio.src = current;
|
|
3260
|
+
audio.play().catch(() => {
|
|
3261
|
+
});
|
|
3262
|
+
}
|
|
3263
|
+
void playFrom(0);
|
|
3264
|
+
}
|
|
3265
|
+
return {
|
|
3266
|
+
pause: () => {
|
|
3267
|
+
if (over) return;
|
|
3268
|
+
paused = true;
|
|
3269
|
+
audio.pause();
|
|
3270
|
+
onState("paused");
|
|
3271
|
+
},
|
|
3272
|
+
resume: () => {
|
|
3273
|
+
if (over || !paused) return;
|
|
3274
|
+
paused = false;
|
|
3275
|
+
if (current)
|
|
3276
|
+
audio.play().then(
|
|
3277
|
+
() => !over && onState("playing"),
|
|
3278
|
+
(err) => end(asOutputError(err))
|
|
3279
|
+
);
|
|
3280
|
+
else onState("loading");
|
|
3281
|
+
},
|
|
3282
|
+
stop: () => end(),
|
|
3283
|
+
done
|
|
3284
|
+
};
|
|
3285
|
+
};
|
|
3286
|
+
|
|
3287
|
+
// src/hooks/use-credentials.ts
|
|
3288
|
+
var import_react8 = require("react");
|
|
2481
3289
|
var core5 = __toESM(require("@dudko.dev/agent-web"), 1);
|
|
2482
3290
|
var import_agent_web3 = require("@dudko.dev/agent-web");
|
|
2483
3291
|
var storeDbName = (store) => {
|
|
@@ -2485,10 +3293,10 @@ var storeDbName = (store) => {
|
|
|
2485
3293
|
return typeof name === "string" && name ? name : void 0;
|
|
2486
3294
|
};
|
|
2487
3295
|
var useCredentials = (store) => {
|
|
2488
|
-
const resolved = (0,
|
|
2489
|
-
const [version, setVersion] = (0,
|
|
3296
|
+
const resolved = (0, import_react8.useMemo)(() => store ?? new import_agent_web3.VaultCredentialStore(), [store]);
|
|
3297
|
+
const [version, setVersion] = (0, import_react8.useState)(0);
|
|
2490
3298
|
const dbName = storeDbName(resolved);
|
|
2491
|
-
(0,
|
|
3299
|
+
(0, import_react8.useEffect)(() => {
|
|
2492
3300
|
return followOtherTabs(
|
|
2493
3301
|
core5,
|
|
2494
3302
|
dbName,
|
|
@@ -2496,21 +3304,21 @@ var useCredentials = (store) => {
|
|
|
2496
3304
|
() => setVersion((v) => v + 1)
|
|
2497
3305
|
);
|
|
2498
3306
|
}, [dbName]);
|
|
2499
|
-
const setKey = (0,
|
|
3307
|
+
const setKey = (0, import_react8.useCallback)(
|
|
2500
3308
|
async (ref, key) => {
|
|
2501
3309
|
await resolved.setApiKey(ref, key);
|
|
2502
3310
|
setVersion((v) => v + 1);
|
|
2503
3311
|
},
|
|
2504
3312
|
[resolved]
|
|
2505
3313
|
);
|
|
2506
|
-
const removeKey = (0,
|
|
3314
|
+
const removeKey = (0, import_react8.useCallback)(
|
|
2507
3315
|
async (ref) => {
|
|
2508
3316
|
await resolved.deleteApiKey(ref);
|
|
2509
3317
|
setVersion((v) => v + 1);
|
|
2510
3318
|
},
|
|
2511
3319
|
[resolved]
|
|
2512
3320
|
);
|
|
2513
|
-
const hasKey = (0,
|
|
3321
|
+
const hasKey = (0, import_react8.useCallback)(
|
|
2514
3322
|
async (ref) => await resolved.getApiKey(ref) !== void 0,
|
|
2515
3323
|
[resolved]
|
|
2516
3324
|
);
|
|
@@ -2521,21 +3329,21 @@ var useCredentials = (store) => {
|
|
|
2521
3329
|
var import_agent_web4 = require("@dudko.dev/agent-web");
|
|
2522
3330
|
|
|
2523
3331
|
// src/hooks/use-local-model.ts
|
|
2524
|
-
var
|
|
3332
|
+
var import_react9 = require("react");
|
|
2525
3333
|
var keyOf = (id, tokens) => tokens ? `${id}@${tokens}` : id;
|
|
2526
3334
|
var useLocalModel = (modelId, engine, options) => {
|
|
2527
|
-
const [loaded, setLoaded] = (0,
|
|
2528
|
-
const [pending, setPending] = (0,
|
|
2529
|
-
const [failure, setFailure] = (0,
|
|
2530
|
-
const engineRef = (0,
|
|
3335
|
+
const [loaded, setLoaded] = (0, import_react9.useState)(void 0);
|
|
3336
|
+
const [pending, setPending] = (0, import_react9.useState)();
|
|
3337
|
+
const [failure, setFailure] = (0, import_react9.useState)();
|
|
3338
|
+
const engineRef = (0, import_react9.useRef)(engine);
|
|
2531
3339
|
engineRef.current = engine;
|
|
2532
|
-
const loadedRef = (0,
|
|
2533
|
-
const inflightRef = (0,
|
|
3340
|
+
const loadedRef = (0, import_react9.useRef)(void 0);
|
|
3341
|
+
const inflightRef = (0, import_react9.useRef)(
|
|
2534
3342
|
void 0
|
|
2535
3343
|
);
|
|
2536
3344
|
const windowTokens = options?.contextWindowTokens;
|
|
2537
3345
|
const key = keyOf(modelId, windowTokens);
|
|
2538
|
-
const seqRef = (0,
|
|
3346
|
+
const seqRef = (0, import_react9.useRef)(0);
|
|
2539
3347
|
const setHeld = (next) => {
|
|
2540
3348
|
loadedRef.current = next;
|
|
2541
3349
|
setLoaded(next);
|
|
@@ -2546,7 +3354,7 @@ var useLocalModel = (modelId, engine, options) => {
|
|
|
2546
3354
|
} catch {
|
|
2547
3355
|
}
|
|
2548
3356
|
};
|
|
2549
|
-
const load = (0,
|
|
3357
|
+
const load = (0, import_react9.useCallback)(() => {
|
|
2550
3358
|
const id = modelId;
|
|
2551
3359
|
if (loadedRef.current?.key === key) return Promise.resolve(loadedRef.current.model);
|
|
2552
3360
|
if (inflightRef.current?.key === key) return inflightRef.current.promise;
|
|
@@ -2598,7 +3406,7 @@ var useLocalModel = (modelId, engine, options) => {
|
|
|
2598
3406
|
inflightRef.current = { key, promise };
|
|
2599
3407
|
return promise;
|
|
2600
3408
|
}, [modelId, key]);
|
|
2601
|
-
const unload = (0,
|
|
3409
|
+
const unload = (0, import_react9.useCallback)(async () => {
|
|
2602
3410
|
seqRef.current++;
|
|
2603
3411
|
inflightRef.current = void 0;
|
|
2604
3412
|
setPending(void 0);
|
|
@@ -2660,7 +3468,7 @@ var createWebLLMEngine = (options) => {
|
|
|
2660
3468
|
};
|
|
2661
3469
|
|
|
2662
3470
|
// src/labels.tsx
|
|
2663
|
-
var
|
|
3471
|
+
var import_react10 = require("react");
|
|
2664
3472
|
|
|
2665
3473
|
// src/composer.ts
|
|
2666
3474
|
var parseSlash = (text2) => {
|
|
@@ -2695,7 +3503,8 @@ var attachmentKindOf = (mediaType, name) => {
|
|
|
2695
3503
|
};
|
|
2696
3504
|
var withAttachments = (text2, files) => {
|
|
2697
3505
|
const texts = files.filter((f) => f.kind === "text" && f.text !== void 0);
|
|
2698
|
-
|
|
3506
|
+
const saved = files.filter((f) => f.kind !== "text" && f.path);
|
|
3507
|
+
if (texts.length === 0 && saved.length === 0) return text2;
|
|
2699
3508
|
const blocks = texts.map((f) => {
|
|
2700
3509
|
const body = f.text;
|
|
2701
3510
|
const fence = body.includes("```") ? "~~~" : "```";
|
|
@@ -2705,10 +3514,46 @@ ${fence}
|
|
|
2705
3514
|
${body}
|
|
2706
3515
|
${fence}`;
|
|
2707
3516
|
});
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
3517
|
+
const kind = (f) => f.kind === "image" ? "picture" : f.kind === "pdf" ? "PDF" : "file";
|
|
3518
|
+
const lines = saved.map(
|
|
3519
|
+
(f) => `- ${kind(f)} "${f.name.replace(/["\s]+/g, " ").trim()}" (also saved as ${f.path})`
|
|
3520
|
+
);
|
|
3521
|
+
return [
|
|
3522
|
+
text2,
|
|
3523
|
+
...blocks.length ? [`Attached file(s):
|
|
3524
|
+
${blocks.join("\n\n")}`] : [],
|
|
3525
|
+
...lines.length ? [`Also attached:
|
|
3526
|
+
${lines.join("\n")}`] : []
|
|
3527
|
+
].join("\n\n");
|
|
3528
|
+
};
|
|
3529
|
+
var ATTACHMENT_BOUNDS = {
|
|
3530
|
+
maxBytes: 20 * 1024 * 1024,
|
|
3531
|
+
// The largest JPEGs a phone writes (a 200 MP shot: ~20-40 MB) pass, and a long PDF with its
|
|
3532
|
+
// pictures; past this it is read into memory for nothing the model would get.
|
|
3533
|
+
maxSourceBytes: 50 * 1024 * 1024,
|
|
3534
|
+
// The largest phone sensor (200 MP: 16320 × 12240) passes, ~800 MB decoded; past this is a
|
|
3535
|
+
// scan, a render or a decompression bomb (a PNG of a few KB can declare 30000 × 30000 px).
|
|
3536
|
+
imageMaxSourcePixels: 2e8,
|
|
3537
|
+
// Under what the providers take in one request (Anthropic: 100 pictures, 32 MB; OpenAI: 50 MB).
|
|
3538
|
+
maxImages: 20,
|
|
3539
|
+
maxTotalBytes: 20 * 1024 * 1024
|
|
3540
|
+
};
|
|
3541
|
+
var attachmentTransformOf = (input) => input.converts ? "convert" : input.kind === "image" && input.imageMaxDimension !== false && input.mediaType !== "image/gif" && input.mediaType !== "image/svg+xml" ? "downscale" : "none";
|
|
3542
|
+
var attachmentOverLimit = (file, stage, transform, bounds) => {
|
|
3543
|
+
if (stage === "original" && transform !== "none") {
|
|
3544
|
+
const sourceBytes = Math.max(bounds.maxSourceBytes, bounds.maxBytes);
|
|
3545
|
+
if (file.bytes > sourceBytes) return { bound: "bytes", limit: sourceBytes };
|
|
3546
|
+
if (transform === "downscale" && file.pixels !== void 0 && file.pixels > bounds.imageMaxSourcePixels)
|
|
3547
|
+
return { bound: "pixels", limit: bounds.imageMaxSourcePixels };
|
|
3548
|
+
return void 0;
|
|
3549
|
+
}
|
|
3550
|
+
return file.bytes > bounds.maxBytes ? { bound: "bytes", limit: bounds.maxBytes } : void 0;
|
|
3551
|
+
};
|
|
3552
|
+
var messageOverLimit = (inMessage, next, bounds) => {
|
|
3553
|
+
if (next.kind === "image" && inMessage.filter((a) => a.kind === "image").length >= bounds.maxImages)
|
|
3554
|
+
return "images";
|
|
3555
|
+
const total = inMessage.reduce((n, a) => n + a.bytes, 0);
|
|
3556
|
+
return total + next.bytes > bounds.maxTotalBytes ? "bytes" : void 0;
|
|
2712
3557
|
};
|
|
2713
3558
|
var attachmentRefusal = (kind, caps, canConvertPdf = false) => {
|
|
2714
3559
|
if (kind === "text" || !caps) return void 0;
|
|
@@ -2789,6 +3634,27 @@ var noticesOf = (state, texts = {}) => {
|
|
|
2789
3634
|
}
|
|
2790
3635
|
return out;
|
|
2791
3636
|
};
|
|
3637
|
+
var formatClock = (ms) => {
|
|
3638
|
+
const s = Math.max(0, Math.floor(ms / 1e3));
|
|
3639
|
+
const two = (n) => String(n).padStart(2, "0");
|
|
3640
|
+
const h = Math.floor(s / 3600);
|
|
3641
|
+
const m = Math.floor(s % 3600 / 60);
|
|
3642
|
+
return h > 0 ? `${h}:${two(m)}:${two(s % 60)}` : `${m}:${two(s % 60)}`;
|
|
3643
|
+
};
|
|
3644
|
+
var micProblemText = (code, message, labels) => {
|
|
3645
|
+
if (code === "not-allowed" || code === "service-not-allowed") return labels.micDenied;
|
|
3646
|
+
if (code === "audio-capture") return labels.micMissing;
|
|
3647
|
+
if (code === "busy") return labels.micBusy;
|
|
3648
|
+
if (code === "unsupported") return labels.micUnsupported;
|
|
3649
|
+
if (message) return message;
|
|
3650
|
+
return code && code !== "transcription" && code !== "failed" ? `${labels.dictationFailed} (${code})` : labels.dictationFailed;
|
|
3651
|
+
};
|
|
3652
|
+
var voiceMessageName = (at, extension) => {
|
|
3653
|
+
const two = (n) => String(n).padStart(2, "0");
|
|
3654
|
+
return `voice-${at.getFullYear()}-${two(at.getMonth() + 1)}-${two(at.getDate())}-${two(
|
|
3655
|
+
at.getHours()
|
|
3656
|
+
)}${two(at.getMinutes())}${two(at.getSeconds())}.${extension}`;
|
|
3657
|
+
};
|
|
2792
3658
|
|
|
2793
3659
|
// src/labels.tsx
|
|
2794
3660
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -2845,6 +3711,19 @@ var defaultLabels = {
|
|
|
2845
3711
|
dictateTitle: "Dictate \u2014 speech to text in the browser",
|
|
2846
3712
|
stopDictation: "Stop dictation",
|
|
2847
3713
|
microphone: "Microphone",
|
|
3714
|
+
transcribing: "Transcribing\u2026",
|
|
3715
|
+
micDenied: "The microphone is blocked for this site. Allow it in the browser's site settings (the icon beside the address), then try again.",
|
|
3716
|
+
micMissing: "No microphone was found on this device.",
|
|
3717
|
+
micBusy: "The microphone is in use by another app.",
|
|
3718
|
+
micUnsupported: "This browser cannot record audio on this page.",
|
|
3719
|
+
dictationFailed: "Dictation did not work.",
|
|
3720
|
+
recordVoiceMessage: "Record a voice message",
|
|
3721
|
+
voiceMessage: "Voice message",
|
|
3722
|
+
audioDuration: (clock) => clock,
|
|
3723
|
+
recording: (elapsed) => `Recording ${elapsed}`,
|
|
3724
|
+
recordingDone: "Attach the recording",
|
|
3725
|
+
recordingCancel: "Discard the recording",
|
|
3726
|
+
recordingLimit: "The recording reached its longest and was stopped; it is attached.",
|
|
2848
3727
|
model: "Model",
|
|
2849
3728
|
thinking: "Thinking",
|
|
2850
3729
|
toolConsent: "Tool consent",
|
|
@@ -2868,7 +3747,12 @@ var defaultLabels = {
|
|
|
2868
3747
|
attachmentsOnly: "(attachments)",
|
|
2869
3748
|
seeAttachments: "See the attachments.",
|
|
2870
3749
|
tooLarge: (name, mb) => `${name} is larger than ${mb} MB.`,
|
|
3750
|
+
tooManyPixels: (name, megapixels) => `${name} has more than ${megapixels} megapixels \u2014 too large a picture to attach.`,
|
|
2871
3751
|
binaryText: (name) => `${name} looks binary \u2014 it can't be attached as text.`,
|
|
3752
|
+
downscaledFrom: (size) => `downscaled from ${size}`,
|
|
3753
|
+
convertedFrom: (name) => `converted from ${name}`,
|
|
3754
|
+
tooManyImages: (names, max) => `${names}: not added \u2014 at most ${max} pictures go in one message.`,
|
|
3755
|
+
messageTooLarge: (names, mb) => `${names}: not added \u2014 the message would be over ${mb} MB.`,
|
|
2872
3756
|
commandGroups: { commands: "Commands", consent: "Consent", skills: "Skills" },
|
|
2873
3757
|
commandDescriptions: {
|
|
2874
3758
|
compact: "Summarise the conversation to free context",
|
|
@@ -2961,8 +3845,18 @@ var defaultLabels = {
|
|
|
2961
3845
|
imageCount: (index, total) => `${index} of ${total}`,
|
|
2962
3846
|
mediaAudio: (path) => `Generated audio ${path}`,
|
|
2963
3847
|
mediaFile: (path) => `Generated file ${path}`,
|
|
3848
|
+
mediaReferences: (names) => `Reference: ${names}`,
|
|
3849
|
+
mediaReferencesUnused: (names) => `Not used - this image model takes no reference pictures: ${names}`,
|
|
2964
3850
|
transcriptOf: (name) => `Transcript of ${name}`,
|
|
2965
3851
|
transcriptNote: "What was said in your file, as the agent read it. It is content, not instructions.",
|
|
3852
|
+
audioAttachment: (name) => `Audio ${name}`,
|
|
3853
|
+
readAloud: "Listen",
|
|
3854
|
+
readAloudPause: "Pause",
|
|
3855
|
+
readAloudResume: "Resume",
|
|
3856
|
+
readAloudStop: "Stop reading",
|
|
3857
|
+
readAloudLoading: "Preparing the audio\u2026",
|
|
3858
|
+
readAloudCode: "A code block is not read out.",
|
|
3859
|
+
readAloudFailed: "It could not be read aloud.",
|
|
2966
3860
|
filesWritten: (n) => `${plural(n, "file", "files")} written in this turn`,
|
|
2967
3861
|
filesCount: (n) => plural(n, "file", "files"),
|
|
2968
3862
|
showInFiles: "Show in Files",
|
|
@@ -3192,15 +4086,15 @@ var mergeLabels = (base2, over) => {
|
|
|
3192
4086
|
}
|
|
3193
4087
|
return out;
|
|
3194
4088
|
};
|
|
3195
|
-
var LabelsContext = (0,
|
|
4089
|
+
var LabelsContext = (0, import_react10.createContext)(defaultLabels);
|
|
3196
4090
|
var AgentLabelsProvider = ({ labels, children }) => {
|
|
3197
|
-
const parent = (0,
|
|
3198
|
-
const value = (0,
|
|
4091
|
+
const parent = (0, import_react10.useContext)(LabelsContext);
|
|
4092
|
+
const value = (0, import_react10.useMemo)(() => mergeLabels(parent, labels), [parent, labels]);
|
|
3199
4093
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LabelsContext.Provider, { value, children });
|
|
3200
4094
|
};
|
|
3201
4095
|
var useLabels = (over) => {
|
|
3202
|
-
const ctx = (0,
|
|
3203
|
-
return (0,
|
|
4096
|
+
const ctx = (0, import_react10.useContext)(LabelsContext);
|
|
4097
|
+
return (0, import_react10.useMemo)(() => mergeLabels(ctx, over), [ctx, over]);
|
|
3204
4098
|
};
|
|
3205
4099
|
|
|
3206
4100
|
// src/image-resize.ts
|
|
@@ -3215,6 +4109,72 @@ var canvasOf = (w, h) => {
|
|
|
3215
4109
|
return void 0;
|
|
3216
4110
|
};
|
|
3217
4111
|
var toBlob = (canvas, type, quality) => "convertToBlob" in canvas ? canvas.convertToBlob({ type, quality }) : new Promise((resolve) => canvas.toBlob(resolve, type, quality));
|
|
4112
|
+
var WINDOW = 64 * 1024;
|
|
4113
|
+
var SOF = /* @__PURE__ */ new Set([192, 193, 194, 195, 197, 198, 199, 201, 202, 203, 205, 206, 207]);
|
|
4114
|
+
var imageSizeOf = async (file) => {
|
|
4115
|
+
let at = 0;
|
|
4116
|
+
let buf = new Uint8Array(0);
|
|
4117
|
+
const read = async (start, length) => {
|
|
4118
|
+
if (start < 0 || start + length > file.size) return void 0;
|
|
4119
|
+
if (start < at || start + length > at + buf.length) {
|
|
4120
|
+
at = start;
|
|
4121
|
+
buf = new Uint8Array(
|
|
4122
|
+
await file.slice(start, Math.min(file.size, start + Math.max(WINDOW, length))).arrayBuffer()
|
|
4123
|
+
);
|
|
4124
|
+
}
|
|
4125
|
+
return buf.subarray(start - at, start - at + length);
|
|
4126
|
+
};
|
|
4127
|
+
const sized = (width, height) => width > 0 && height > 0 ? { width, height } : void 0;
|
|
4128
|
+
try {
|
|
4129
|
+
const head = await read(0, 30);
|
|
4130
|
+
if (!head) return void 0;
|
|
4131
|
+
const u16be = (b, i) => b[i] << 8 | b[i + 1];
|
|
4132
|
+
const u32be = (b, i) => u16be(b, i) * 65536 + u16be(b, i + 2);
|
|
4133
|
+
const ascii = (b, i, n) => String.fromCharCode(...Array.from(b.subarray(i, i + n)));
|
|
4134
|
+
if (ascii(head, 1, 3) === "PNG" && head[0] === 137 && ascii(head, 12, 4) === "IHDR")
|
|
4135
|
+
return sized(u32be(head, 16), u32be(head, 20));
|
|
4136
|
+
if (ascii(head, 0, 4) === "RIFF" && ascii(head, 8, 4) === "WEBP") {
|
|
4137
|
+
const chunk = ascii(head, 12, 4);
|
|
4138
|
+
const u16le = (i) => head[i] | head[i + 1] << 8;
|
|
4139
|
+
const u24le = (i) => u16le(i) | head[i + 2] << 16;
|
|
4140
|
+
if (chunk === "VP8X") return sized(u24le(24) + 1, u24le(27) + 1);
|
|
4141
|
+
if (chunk === "VP8L" && head[20] === 47) {
|
|
4142
|
+
const bits = (u16le(21) | u16le(23) << 16) >>> 0;
|
|
4143
|
+
return sized((bits & 16383) + 1, (bits >>> 14 & 16383) + 1);
|
|
4144
|
+
}
|
|
4145
|
+
if (chunk === "VP8 " && head[23] === 157 && head[24] === 1 && head[25] === 42)
|
|
4146
|
+
return sized(u16le(26) & 16383, u16le(28) & 16383);
|
|
4147
|
+
return void 0;
|
|
4148
|
+
}
|
|
4149
|
+
if (head[0] === 255 && head[1] === 216) {
|
|
4150
|
+
let p = 2;
|
|
4151
|
+
for (let segments = 0; segments < 4096; segments++) {
|
|
4152
|
+
const m = await read(p, 4);
|
|
4153
|
+
if (!m || m[0] !== 255) return void 0;
|
|
4154
|
+
const marker = m[1];
|
|
4155
|
+
if (marker === 255) {
|
|
4156
|
+
p += 1;
|
|
4157
|
+
continue;
|
|
4158
|
+
}
|
|
4159
|
+
if (marker === 1 || marker >= 208 && marker <= 216) {
|
|
4160
|
+
p += 2;
|
|
4161
|
+
continue;
|
|
4162
|
+
}
|
|
4163
|
+
if (marker === 217 || marker === 218) return void 0;
|
|
4164
|
+
const length = u16be(m, 2);
|
|
4165
|
+
if (length < 2) return void 0;
|
|
4166
|
+
if (SOF.has(marker)) {
|
|
4167
|
+
const frame = await read(p + 4, 5);
|
|
4168
|
+
return frame ? sized(u16be(frame, 3), u16be(frame, 1)) : void 0;
|
|
4169
|
+
}
|
|
4170
|
+
p += 2 + length;
|
|
4171
|
+
}
|
|
4172
|
+
}
|
|
4173
|
+
return void 0;
|
|
4174
|
+
} catch {
|
|
4175
|
+
return void 0;
|
|
4176
|
+
}
|
|
4177
|
+
};
|
|
3218
4178
|
var downscaleImage = async (file, opts = {}) => {
|
|
3219
4179
|
const maxDimension = opts.maxDimension ?? 1568;
|
|
3220
4180
|
const maxPixels = opts.maxPixels ?? 115e4;
|
|
@@ -3253,19 +4213,19 @@ var downscaleImage = async (file, opts = {}) => {
|
|
|
3253
4213
|
};
|
|
3254
4214
|
|
|
3255
4215
|
// src/context.tsx
|
|
3256
|
-
var
|
|
4216
|
+
var import_react11 = require("react");
|
|
3257
4217
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
3258
|
-
var AgentContext = (0,
|
|
4218
|
+
var AgentContext = (0, import_react11.createContext)(null);
|
|
3259
4219
|
var AgentProvider = ({ config, children, ...options }) => {
|
|
3260
4220
|
const agent = useAgent(config, options);
|
|
3261
4221
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AgentContext.Provider, { value: agent, children });
|
|
3262
4222
|
};
|
|
3263
4223
|
var useAgentContext = () => {
|
|
3264
|
-
const ctx = (0,
|
|
4224
|
+
const ctx = (0, import_react11.useContext)(AgentContext);
|
|
3265
4225
|
if (!ctx) throw new Error("useAgentContext must be used within an <AgentProvider>");
|
|
3266
4226
|
return ctx;
|
|
3267
4227
|
};
|
|
3268
|
-
var useOptionalAgentContext = () => (0,
|
|
4228
|
+
var useOptionalAgentContext = () => (0, import_react11.useContext)(AgentContext);
|
|
3269
4229
|
|
|
3270
4230
|
// src/elicitation.ts
|
|
3271
4231
|
var titled = (options) => options.map((o) => ({ value: o.const, label: o.title || o.const }));
|
|
@@ -3472,11 +4432,11 @@ var formatCountdown = (ms) => {
|
|
|
3472
4432
|
};
|
|
3473
4433
|
|
|
3474
4434
|
// src/components/AgentChat.tsx
|
|
3475
|
-
var
|
|
4435
|
+
var import_react25 = require("react");
|
|
3476
4436
|
var import_react_dom2 = require("react-dom");
|
|
3477
4437
|
|
|
3478
4438
|
// src/hooks/use-follow-scroll.ts
|
|
3479
|
-
var
|
|
4439
|
+
var import_react12 = require("react");
|
|
3480
4440
|
|
|
3481
4441
|
// src/follow-scroll.ts
|
|
3482
4442
|
var FOLLOW_REJOIN_PX = 80;
|
|
@@ -3493,7 +4453,7 @@ var followsAfterScroll = (following, before, now) => {
|
|
|
3493
4453
|
var followsAfterResize = (following, before, now) => following && !(now.clientHeight === before.clientHeight && now.scrollHeight >= before.scrollHeight && now.scrollTop < reach(before) - FOLLOW_LEAVE_PX);
|
|
3494
4454
|
|
|
3495
4455
|
// src/hooks/use-follow-scroll.ts
|
|
3496
|
-
var useIsoLayoutEffect = typeof window === "undefined" ?
|
|
4456
|
+
var useIsoLayoutEffect = typeof window === "undefined" ? import_react12.useEffect : import_react12.useLayoutEffect;
|
|
3497
4457
|
var measure = (el) => ({
|
|
3498
4458
|
scrollTop: el.scrollTop,
|
|
3499
4459
|
scrollHeight: el.scrollHeight,
|
|
@@ -3515,12 +4475,12 @@ var anchorOf = (el) => {
|
|
|
3515
4475
|
return marks.length ? { marks, top: el.scrollTop } : void 0;
|
|
3516
4476
|
};
|
|
3517
4477
|
var useFollowScroll = (ref, turn, live = true) => {
|
|
3518
|
-
const following = (0,
|
|
3519
|
-
const last = (0,
|
|
3520
|
-
const anchor = (0,
|
|
3521
|
-
const settle = (0,
|
|
4478
|
+
const following = (0, import_react12.useRef)(true);
|
|
4479
|
+
const last = (0, import_react12.useRef)(void 0);
|
|
4480
|
+
const anchor = (0, import_react12.useRef)(void 0);
|
|
4481
|
+
const settle = (0, import_react12.useRef)(() => {
|
|
3522
4482
|
});
|
|
3523
|
-
const arriving = (0,
|
|
4483
|
+
const arriving = (0, import_react12.useRef)(live);
|
|
3524
4484
|
arriving.current = live;
|
|
3525
4485
|
useIsoLayoutEffect(() => {
|
|
3526
4486
|
const el = ref.current;
|
|
@@ -3593,7 +4553,7 @@ var useFollowScroll = (ref, turn, live = true) => {
|
|
|
3593
4553
|
};
|
|
3594
4554
|
|
|
3595
4555
|
// src/hooks/use-mcp-app-host.ts
|
|
3596
|
-
var
|
|
4556
|
+
var import_react13 = require("react");
|
|
3597
4557
|
|
|
3598
4558
|
// src/mcp-app.ts
|
|
3599
4559
|
var import_agent_web5 = require("@dudko.dev/agent-web");
|
|
@@ -4459,27 +5419,27 @@ var useMcpAppHost = ({
|
|
|
4459
5419
|
sampling = false,
|
|
4460
5420
|
sample: sampleFn
|
|
4461
5421
|
}) => {
|
|
4462
|
-
const [requests, setRequests] = (0,
|
|
4463
|
-
const [draft, setDraft] = (0,
|
|
4464
|
-
const waiting = (0,
|
|
5422
|
+
const [requests, setRequests] = (0, import_react13.useState)([]);
|
|
5423
|
+
const [draft, setDraft] = (0, import_react13.useState)();
|
|
5424
|
+
const waiting = (0, import_react13.useRef)(
|
|
4465
5425
|
/* @__PURE__ */ new Map()
|
|
4466
5426
|
);
|
|
4467
|
-
const samplingAllowed = (0,
|
|
4468
|
-
const sampleRef = (0,
|
|
5427
|
+
const samplingAllowed = (0, import_react13.useRef)(/* @__PURE__ */ new Set());
|
|
5428
|
+
const sampleRef = (0, import_react13.useRef)(sampleFn);
|
|
4469
5429
|
sampleRef.current = sampleFn;
|
|
4470
|
-
const [gated, setGated] = (0,
|
|
4471
|
-
const connectionRef = (0,
|
|
5430
|
+
const [gated, setGated] = (0, import_react13.useState)({});
|
|
5431
|
+
const connectionRef = (0, import_react13.useRef)(connection);
|
|
4472
5432
|
connectionRef.current = connection;
|
|
4473
|
-
const approveRef = (0,
|
|
5433
|
+
const approveRef = (0, import_react13.useRef)(approve);
|
|
4474
5434
|
approveRef.current = approve;
|
|
4475
|
-
(0,
|
|
5435
|
+
(0, import_react13.useEffect)(
|
|
4476
5436
|
() => () => {
|
|
4477
5437
|
for (const { resolve } of waiting.current.values()) resolve(false);
|
|
4478
5438
|
waiting.current.clear();
|
|
4479
5439
|
},
|
|
4480
5440
|
[]
|
|
4481
5441
|
);
|
|
4482
|
-
const ask = (0,
|
|
5442
|
+
const ask = (0, import_react13.useCallback)(
|
|
4483
5443
|
(request, signal, extra = {}) => {
|
|
4484
5444
|
for (const w of waiting.current.values()) {
|
|
4485
5445
|
if (w.request.appId === request.appId) {
|
|
@@ -4504,7 +5464,7 @@ var useMcpAppHost = ({
|
|
|
4504
5464
|
},
|
|
4505
5465
|
[]
|
|
4506
5466
|
);
|
|
4507
|
-
const answer = (0,
|
|
5467
|
+
const answer = (0, import_react13.useCallback)((id, accept, options) => {
|
|
4508
5468
|
const w = waiting.current.get(id);
|
|
4509
5469
|
if (!w) return;
|
|
4510
5470
|
if (accept && w.request.kind === "link" && w.request.link) {
|
|
@@ -4530,16 +5490,16 @@ var useMcpAppHost = ({
|
|
|
4530
5490
|
}
|
|
4531
5491
|
w.resolve(accept);
|
|
4532
5492
|
}, []);
|
|
4533
|
-
const read = (0,
|
|
5493
|
+
const read = (0, import_react13.useCallback)((app, signal) => {
|
|
4534
5494
|
const c = connectionRef.current;
|
|
4535
5495
|
if (!c) return Promise.reject(new Error(`no connection to the server \u201C${app.server}\u201D`));
|
|
4536
5496
|
return c.readUiResource(app.server, app.resourceUri, signal ? { signal } : void 0);
|
|
4537
5497
|
}, []);
|
|
4538
|
-
const tool = (0,
|
|
5498
|
+
const tool = (0, import_react13.useCallback)(
|
|
4539
5499
|
(app) => connectionRef.current?.appTool(app.server, app.toolName),
|
|
4540
5500
|
[]
|
|
4541
5501
|
);
|
|
4542
|
-
const callTool = (0,
|
|
5502
|
+
const callTool = (0, import_react13.useCallback)(
|
|
4543
5503
|
async (app, name, args, signal) => {
|
|
4544
5504
|
const c = connectionRef.current;
|
|
4545
5505
|
if (!c) throw refused(`The server \u201C${app.server}\u201D is not connected`);
|
|
@@ -4576,15 +5536,15 @@ var useMcpAppHost = ({
|
|
|
4576
5536
|
},
|
|
4577
5537
|
[]
|
|
4578
5538
|
);
|
|
4579
|
-
const openLink = (0,
|
|
5539
|
+
const openLink = (0, import_react13.useCallback)(
|
|
4580
5540
|
(app, link, signal) => ask({ appId: app.id, server: app.server, kind: "link", link }, signal),
|
|
4581
5541
|
[ask]
|
|
4582
5542
|
);
|
|
4583
|
-
const message = (0,
|
|
5543
|
+
const message = (0, import_react13.useCallback)(
|
|
4584
5544
|
(app, text2, signal) => ask({ appId: app.id, server: app.server, kind: "message", text: text2 }, signal),
|
|
4585
5545
|
[ask]
|
|
4586
5546
|
);
|
|
4587
|
-
const downloadFile2 = (0,
|
|
5547
|
+
const downloadFile2 = (0, import_react13.useCallback)(
|
|
4588
5548
|
async (app, file, signal) => {
|
|
4589
5549
|
const c = connectionRef.current;
|
|
4590
5550
|
if (file.kind === "link" && !c) throw refused(`The server \u201C${app.server}\u201D is not connected`);
|
|
@@ -4607,7 +5567,7 @@ var useMcpAppHost = ({
|
|
|
4607
5567
|
},
|
|
4608
5568
|
[ask]
|
|
4609
5569
|
);
|
|
4610
|
-
const sample = (0,
|
|
5570
|
+
const sample = (0, import_react13.useCallback)(
|
|
4611
5571
|
async (app, params, signal) => {
|
|
4612
5572
|
const fn = sampleRef.current;
|
|
4613
5573
|
if (!fn) throw refused("This host cannot answer sampling requests");
|
|
@@ -4628,19 +5588,19 @@ var useMcpAppHost = ({
|
|
|
4628
5588
|
},
|
|
4629
5589
|
[ask]
|
|
4630
5590
|
);
|
|
4631
|
-
const pendingAppServers = (0,
|
|
5591
|
+
const pendingAppServers = (0, import_react13.useMemo)(
|
|
4632
5592
|
() => new Set(
|
|
4633
5593
|
approvals.filter((a) => a.app && a.status === "pending").map((a) => `${a.app.server}\0${a.app.resourceUri}`)
|
|
4634
5594
|
),
|
|
4635
5595
|
[approvals]
|
|
4636
5596
|
);
|
|
4637
|
-
const isWaiting = (0,
|
|
5597
|
+
const isWaiting = (0, import_react13.useCallback)(
|
|
4638
5598
|
(app) => requests.some((r) => r.appId === app.id) || Boolean(gated[app.id]) && pendingAppServers.has(`${app.server}\0${app.resourceUri}`),
|
|
4639
5599
|
[requests, gated, pendingAppServers]
|
|
4640
5600
|
);
|
|
4641
5601
|
const sandboxUrl = sandbox?.url;
|
|
4642
5602
|
const sandboxTimeout = sandbox?.timeoutMs;
|
|
4643
|
-
const sandboxSetting = (0,
|
|
5603
|
+
const sandboxSetting = (0, import_react13.useMemo)(
|
|
4644
5604
|
() => sandboxUrl === void 0 ? void 0 : {
|
|
4645
5605
|
url: sandboxUrl,
|
|
4646
5606
|
...sandboxTimeout !== void 0 ? { timeoutMs: sandboxTimeout } : {}
|
|
@@ -4648,7 +5608,7 @@ var useMcpAppHost = ({
|
|
|
4648
5608
|
[sandboxUrl, sandboxTimeout]
|
|
4649
5609
|
);
|
|
4650
5610
|
const samplingOn = sampling && Boolean(sampleFn);
|
|
4651
|
-
return (0,
|
|
5611
|
+
return (0, import_react13.useMemo)(
|
|
4652
5612
|
() => ({
|
|
4653
5613
|
connected: Boolean(connection),
|
|
4654
5614
|
read,
|
|
@@ -4737,6 +5697,13 @@ var MicIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.j
|
|
|
4737
5697
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("rect", { x: "9", y: "3", width: "6", height: "11", rx: "3" }),
|
|
4738
5698
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M5 11a7 7 0 0 0 14 0M12 18v3" })
|
|
4739
5699
|
] });
|
|
5700
|
+
var WaveIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { ...base(size), className, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M4 10v4M8 6v12M12 3v18M16 7v10M20 10v4" }) });
|
|
5701
|
+
var SpeakerIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("svg", { ...base(size), className, children: [
|
|
5702
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M4 9h4l5-4v14l-5-4H4Z" }),
|
|
5703
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M16.5 8.5a5 5 0 0 1 0 7M19 6a8.5 8.5 0 0 1 0 12" })
|
|
5704
|
+
] });
|
|
5705
|
+
var PauseIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { ...base(size), className, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M9 5v14M15 5v14" }) });
|
|
5706
|
+
var PlayIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { ...base(size), className, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M7 4.5v15l12-7.5Z" }) });
|
|
4740
5707
|
var BoltIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { ...base(size), className, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M13 2 4 14h7l-1 8 9-12h-7Z" }) });
|
|
4741
5708
|
var EyeIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("svg", { ...base(size), className, children: [
|
|
4742
5709
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12Z" }),
|
|
@@ -4931,11 +5898,11 @@ var AppRequestPrompt = ({
|
|
|
4931
5898
|
};
|
|
4932
5899
|
|
|
4933
5900
|
// src/components/McpAppFrame.tsx
|
|
4934
|
-
var
|
|
5901
|
+
var import_react14 = require("react");
|
|
4935
5902
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
4936
5903
|
var HOST_INFO = { name: "@dudko.dev/agent-web-react", version: "1" };
|
|
4937
5904
|
var MAX_LISTED_CALLS = 12;
|
|
4938
|
-
var useIsoLayoutEffect2 = typeof window === "undefined" ?
|
|
5905
|
+
var useIsoLayoutEffect2 = typeof window === "undefined" ? import_react14.useEffect : import_react14.useLayoutEffect;
|
|
4939
5906
|
var userActivation = () => typeof navigator === "undefined" ? void 0 : navigator.userActivation?.isActive;
|
|
4940
5907
|
var silentSandboxes = /* @__PURE__ */ new Set();
|
|
4941
5908
|
var warned = /* @__PURE__ */ new Set();
|
|
@@ -4968,36 +5935,36 @@ var McpAppFrame = ({
|
|
|
4968
5935
|
className
|
|
4969
5936
|
}) => {
|
|
4970
5937
|
const L = useLabels(labels);
|
|
4971
|
-
const [collapsed, setCollapsed] = (0,
|
|
4972
|
-
const [menu, setMenu] = (0,
|
|
4973
|
-
const [reload, setReload] = (0,
|
|
4974
|
-
const [loaded, setLoaded] = (0,
|
|
4975
|
-
const [height, setHeight] = (0,
|
|
4976
|
-
const [calls, setCalls] = (0,
|
|
4977
|
-
const [fallback, setFallback] = (0,
|
|
4978
|
-
const [broken, setBroken] = (0,
|
|
4979
|
-
const [onOrigin, setOnOrigin] = (0,
|
|
4980
|
-
const shellLoaded = (0,
|
|
4981
|
-
const [mode, setMode] = (0,
|
|
4982
|
-
const modeRef = (0,
|
|
4983
|
-
const [holder, setHolder] = (0,
|
|
4984
|
-
const [fullRect, setFullRect] = (0,
|
|
4985
|
-
const leaveRef = (0,
|
|
4986
|
-
const rootRef = (0,
|
|
4987
|
-
const exitRef = (0,
|
|
4988
|
-
const allowFullscreenRef = (0,
|
|
5938
|
+
const [collapsed, setCollapsed] = (0, import_react14.useState)(defaultCollapsed);
|
|
5939
|
+
const [menu, setMenu] = (0, import_react14.useState)(false);
|
|
5940
|
+
const [reload, setReload] = (0, import_react14.useState)(0);
|
|
5941
|
+
const [loaded, setLoaded] = (0, import_react14.useState)();
|
|
5942
|
+
const [height, setHeight] = (0, import_react14.useState)(APP_DEFAULT_HEIGHT);
|
|
5943
|
+
const [calls, setCalls] = (0, import_react14.useState)([]);
|
|
5944
|
+
const [fallback, setFallback] = (0, import_react14.useState)();
|
|
5945
|
+
const [broken, setBroken] = (0, import_react14.useState)(false);
|
|
5946
|
+
const [onOrigin, setOnOrigin] = (0, import_react14.useState)(false);
|
|
5947
|
+
const shellLoaded = (0, import_react14.useRef)(void 0);
|
|
5948
|
+
const [mode, setMode] = (0, import_react14.useState)("inline");
|
|
5949
|
+
const modeRef = (0, import_react14.useRef)("inline");
|
|
5950
|
+
const [holder, setHolder] = (0, import_react14.useState)(0);
|
|
5951
|
+
const [fullRect, setFullRect] = (0, import_react14.useState)();
|
|
5952
|
+
const leaveRef = (0, import_react14.useRef)(void 0);
|
|
5953
|
+
const rootRef = (0, import_react14.useRef)(null);
|
|
5954
|
+
const exitRef = (0, import_react14.useRef)(null);
|
|
5955
|
+
const allowFullscreenRef = (0, import_react14.useRef)(allowFullscreen);
|
|
4989
5956
|
allowFullscreenRef.current = allowFullscreen;
|
|
4990
|
-
const iframeRef = (0,
|
|
4991
|
-
const bridgeRef = (0,
|
|
4992
|
-
const menuRef = (0,
|
|
4993
|
-
const themeRef = (0,
|
|
5957
|
+
const iframeRef = (0, import_react14.useRef)(null);
|
|
5958
|
+
const bridgeRef = (0, import_react14.useRef)(void 0);
|
|
5959
|
+
const menuRef = (0, import_react14.useRef)(null);
|
|
5960
|
+
const themeRef = (0, import_react14.useRef)(theme);
|
|
4994
5961
|
themeRef.current = theme;
|
|
4995
|
-
const hostRef = (0,
|
|
5962
|
+
const hostRef = (0, import_react14.useRef)(host);
|
|
4996
5963
|
hostRef.current = host;
|
|
4997
|
-
const appRef = (0,
|
|
5964
|
+
const appRef = (0, import_react14.useRef)(app);
|
|
4998
5965
|
appRef.current = app;
|
|
4999
5966
|
const live = !collapsed;
|
|
5000
|
-
(0,
|
|
5967
|
+
(0, import_react14.useEffect)(() => {
|
|
5001
5968
|
if (!live) return;
|
|
5002
5969
|
if (!hostRef.current.connected) {
|
|
5003
5970
|
setLoaded({ unavailable: true });
|
|
@@ -5020,7 +5987,7 @@ var McpAppFrame = ({
|
|
|
5020
5987
|
const resource = loaded && "resource" in loaded ? loaded.resource : void 0;
|
|
5021
5988
|
const sandboxUrl = host.sandbox?.url;
|
|
5022
5989
|
const timeoutMs = host.sandbox?.timeoutMs ?? MCP_APP_SANDBOX_TIMEOUT_MS;
|
|
5023
|
-
const placement = (0,
|
|
5990
|
+
const placement = (0, import_react14.useMemo)(() => {
|
|
5024
5991
|
if (!resource) return void 0;
|
|
5025
5992
|
if (sandboxUrl === void 0) return { mode: "opaque" };
|
|
5026
5993
|
if (fallback) return { mode: "opaque", reason: fallback };
|
|
@@ -5031,11 +5998,11 @@ var McpAppFrame = ({
|
|
|
5031
5998
|
if (!url) return { mode: "opaque", reason: "too-many-origins" };
|
|
5032
5999
|
return { mode: "origin", origin: target.origin, url };
|
|
5033
6000
|
}, [resource, sandboxUrl, fallback, app.server, reload]);
|
|
5034
|
-
const doc = (0,
|
|
6001
|
+
const doc = (0, import_react14.useMemo)(
|
|
5035
6002
|
() => !resource || !placement ? void 0 : placement.mode === "origin" ? buildMcpAppSandboxShell(placement.url) : buildMcpAppDocument(resource.html, resource.csp),
|
|
5036
6003
|
[resource, placement]
|
|
5037
6004
|
);
|
|
5038
|
-
(0,
|
|
6005
|
+
(0, import_react14.useEffect)(() => {
|
|
5039
6006
|
const reason = placement?.mode === "opaque" ? placement.reason : void 0;
|
|
5040
6007
|
if (reason && reason !== "no-answer" && sandboxUrl !== void 0) {
|
|
5041
6008
|
warnOnce(
|
|
@@ -5044,7 +6011,7 @@ var McpAppFrame = ({
|
|
|
5044
6011
|
);
|
|
5045
6012
|
}
|
|
5046
6013
|
}, [placement, sandboxUrl]);
|
|
5047
|
-
(0,
|
|
6014
|
+
(0, import_react14.useEffect)(() => {
|
|
5048
6015
|
const frame = iframeRef.current;
|
|
5049
6016
|
if (!live || !resource || !frame || !placement || broken) return;
|
|
5050
6017
|
const abort = new AbortController();
|
|
@@ -5189,7 +6156,7 @@ var McpAppFrame = ({
|
|
|
5189
6156
|
}, [live, resource, reload, variant, app.id, placement, broken, timeoutMs]);
|
|
5190
6157
|
const fullscreen = mode === "fullscreen" && live && !broken;
|
|
5191
6158
|
const waitingNow = host.isWaiting(app);
|
|
5192
|
-
(0,
|
|
6159
|
+
(0, import_react14.useEffect)(() => {
|
|
5193
6160
|
if (fullscreen && waitingNow) leaveRef.current?.();
|
|
5194
6161
|
}, [fullscreen, waitingNow]);
|
|
5195
6162
|
useIsoLayoutEffect2(() => {
|
|
@@ -5224,7 +6191,7 @@ var McpAppFrame = ({
|
|
|
5224
6191
|
ro?.disconnect();
|
|
5225
6192
|
};
|
|
5226
6193
|
}, [fullscreen]);
|
|
5227
|
-
(0,
|
|
6194
|
+
(0, import_react14.useEffect)(() => {
|
|
5228
6195
|
if (!fullscreen) return;
|
|
5229
6196
|
const before = document.activeElement;
|
|
5230
6197
|
exitRef.current?.focus();
|
|
@@ -5241,10 +6208,10 @@ var McpAppFrame = ({
|
|
|
5241
6208
|
if (frame && (before === frame || document.activeElement === document.body)) frame.focus();
|
|
5242
6209
|
};
|
|
5243
6210
|
}, [fullscreen]);
|
|
5244
|
-
(0,
|
|
6211
|
+
(0, import_react14.useEffect)(() => {
|
|
5245
6212
|
if (theme) bridgeRef.current?.updateContext({ theme });
|
|
5246
6213
|
}, [theme]);
|
|
5247
|
-
(0,
|
|
6214
|
+
(0, import_react14.useEffect)(() => {
|
|
5248
6215
|
if (!menu) return;
|
|
5249
6216
|
const close = (e) => {
|
|
5250
6217
|
if (e instanceof KeyboardEvent ? e.key === "Escape" : !menuRef.current?.contains(e.target)) {
|
|
@@ -5549,7 +6516,7 @@ var McpAppLine = ({ app, note, action, onAction, labels, className }) => {
|
|
|
5549
6516
|
};
|
|
5550
6517
|
|
|
5551
6518
|
// src/components/AgentComposer.tsx
|
|
5552
|
-
var
|
|
6519
|
+
var import_react15 = require("react");
|
|
5553
6520
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
5554
6521
|
var thinkingDefaults = (l) => [
|
|
5555
6522
|
{ id: "off", label: l.thinkingLevels.off },
|
|
@@ -5561,7 +6528,7 @@ var thinkingDefaults = (l) => [
|
|
|
5561
6528
|
var MODES = ["autopilot", "ask-writes", "ask-all", "read-only"];
|
|
5562
6529
|
var ModeIcon = ({ mode }) => mode === "autopilot" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(BoltIcon, { size: 14 }) : mode === "read-only" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(EyeIcon, { size: 14 }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ShieldIcon, { size: 14 });
|
|
5563
6530
|
var useMenuKeys = (open, menuRef, chipRef, close) => {
|
|
5564
|
-
(0,
|
|
6531
|
+
(0, import_react15.useEffect)(() => {
|
|
5565
6532
|
if (!open) return;
|
|
5566
6533
|
const menu = menuRef.current;
|
|
5567
6534
|
const rows = menu ? [...menu.querySelectorAll('[role^="menuitem"]')] : [];
|
|
@@ -5589,9 +6556,9 @@ var useMenuKeys = (open, menuRef, chipRef, close) => {
|
|
|
5589
6556
|
};
|
|
5590
6557
|
var opensMenu = (key) => key === "ArrowDown" || key === "ArrowUp";
|
|
5591
6558
|
var attachSeq = 0;
|
|
5592
|
-
var useIsoLayoutEffect3 = typeof window === "undefined" ?
|
|
6559
|
+
var useIsoLayoutEffect3 = typeof window === "undefined" ? import_react15.useEffect : import_react15.useLayoutEffect;
|
|
5593
6560
|
var useMenuPlacement = (open, anchor, align) => {
|
|
5594
|
-
const [style, setStyle] = (0,
|
|
6561
|
+
const [style, setStyle] = (0, import_react15.useState)();
|
|
5595
6562
|
useIsoLayoutEffect3(() => {
|
|
5596
6563
|
if (!open) return;
|
|
5597
6564
|
const place = () => {
|
|
@@ -5652,6 +6619,7 @@ var AgentComposer = ({
|
|
|
5652
6619
|
files: vfs,
|
|
5653
6620
|
dropZone = "self",
|
|
5654
6621
|
speech = true,
|
|
6622
|
+
voiceMessage = false,
|
|
5655
6623
|
showTimer = true,
|
|
5656
6624
|
showAgents = true,
|
|
5657
6625
|
showApprovalMode = true,
|
|
@@ -5669,36 +6637,52 @@ var AgentComposer = ({
|
|
|
5669
6637
|
const L = useLabels(labelsOverride);
|
|
5670
6638
|
const MODE_CHIP = L.modes;
|
|
5671
6639
|
const DEFAULT_THINKING = thinkingDefaults(L);
|
|
5672
|
-
const [text2, setText] = (0,
|
|
5673
|
-
const [pending,
|
|
5674
|
-
const
|
|
5675
|
-
const
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
const
|
|
5680
|
-
const
|
|
5681
|
-
const
|
|
5682
|
-
const
|
|
5683
|
-
const
|
|
5684
|
-
const
|
|
5685
|
-
const
|
|
5686
|
-
const
|
|
5687
|
-
const
|
|
5688
|
-
(0,
|
|
6640
|
+
const [text2, setText] = (0, import_react15.useState)("");
|
|
6641
|
+
const [pending, setPendingState] = (0, import_react15.useState)([]);
|
|
6642
|
+
const pendingRef = (0, import_react15.useRef)([]);
|
|
6643
|
+
const setPending = (next) => {
|
|
6644
|
+
pendingRef.current = typeof next === "function" ? next(pendingRef.current) : next;
|
|
6645
|
+
setPendingState(pendingRef.current);
|
|
6646
|
+
};
|
|
6647
|
+
const [menu, setMenu] = (0, import_react15.useState)(void 0);
|
|
6648
|
+
const [active, setActive] = (0, import_react15.useState)(0);
|
|
6649
|
+
const [dismissed, setDismissed] = (0, import_react15.useState)(() => /* @__PURE__ */ new Set());
|
|
6650
|
+
const [attachError, setAttachError] = (0, import_react15.useState)();
|
|
6651
|
+
const [dragging, setDragging] = (0, import_react15.useState)(false);
|
|
6652
|
+
const rootRef = (0, import_react15.useRef)(null);
|
|
6653
|
+
const modelRef = (0, import_react15.useRef)(null);
|
|
6654
|
+
const modeRef = (0, import_react15.useRef)(null);
|
|
6655
|
+
const modelChipRef = (0, import_react15.useRef)(null);
|
|
6656
|
+
const modeChipRef = (0, import_react15.useRef)(null);
|
|
6657
|
+
const modelMenuRef = (0, import_react15.useRef)(null);
|
|
6658
|
+
const modeMenuRef = (0, import_react15.useRef)(null);
|
|
6659
|
+
const [dropRect, setDropRect] = (0, import_react15.useState)();
|
|
6660
|
+
const [compactBar, setCompactBar] = (0, import_react15.useState)(false);
|
|
6661
|
+
const [barWidth, setBarWidth] = (0, import_react15.useState)(0);
|
|
6662
|
+
(0, import_react15.useEffect)(() => {
|
|
5689
6663
|
const el = rootRef.current;
|
|
5690
6664
|
if (!el || typeof ResizeObserver === "undefined") return;
|
|
5691
|
-
const ro = new ResizeObserver(
|
|
5692
|
-
|
|
5693
|
-
|
|
6665
|
+
const ro = new ResizeObserver(() => {
|
|
6666
|
+
const width = el.getBoundingClientRect().width;
|
|
6667
|
+
setCompactBar(width < compactWidth);
|
|
6668
|
+
setBarWidth(Math.round(width));
|
|
6669
|
+
});
|
|
5694
6670
|
ro.observe(el);
|
|
5695
6671
|
return () => ro.disconnect();
|
|
5696
6672
|
}, [compactWidth]);
|
|
5697
|
-
const
|
|
5698
|
-
const
|
|
6673
|
+
const chipLabelRef = (0, import_react15.useRef)(null);
|
|
6674
|
+
const [chipShort, setChipShort] = (0, import_react15.useState)(false);
|
|
6675
|
+
(0, import_react15.useLayoutEffect)(() => setChipShort(false), [barWidth, model?.label, model?.shortLabel]);
|
|
6676
|
+
(0, import_react15.useLayoutEffect)(() => {
|
|
6677
|
+
const el = chipLabelRef.current;
|
|
6678
|
+
if (chipShort || !el || !model?.shortLabel) return;
|
|
6679
|
+
if (el.scrollWidth > el.clientWidth + 1) setChipShort(true);
|
|
6680
|
+
});
|
|
6681
|
+
const fileRef = (0, import_react15.useRef)(null);
|
|
6682
|
+
const inputRef = (0, import_react15.useRef)(null);
|
|
5699
6683
|
const draftId = draft?.id;
|
|
5700
6684
|
const draftText = draft?.text;
|
|
5701
|
-
(0,
|
|
6685
|
+
(0, import_react15.useEffect)(() => {
|
|
5702
6686
|
if (draftId === void 0 || !draftText) return;
|
|
5703
6687
|
setText((t) => t.trim() ? `${t.trimEnd()}
|
|
5704
6688
|
${draftText}` : draftText);
|
|
@@ -5712,13 +6696,20 @@ ${draftText}` : draftText);
|
|
|
5712
6696
|
const caps = agent.agent?.capabilities;
|
|
5713
6697
|
const stt = useSpeechToText({
|
|
5714
6698
|
lang: typeof speech === "object" ? speech.lang : void 0,
|
|
6699
|
+
createRecognizer: typeof speech === "object" ? speech.createRecognizer : void 0,
|
|
5715
6700
|
onFinal: (heard) => setText((t) => t.trim() ? `${t.trimEnd()} ${heard}` : heard)
|
|
5716
6701
|
});
|
|
5717
6702
|
const showMic = speech !== false && stt.supported;
|
|
5718
|
-
const
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
|
|
6703
|
+
const recorder = useAudioRecorder({
|
|
6704
|
+
maxMs: typeof voiceMessage === "object" ? voiceMessage.maxMs : void 0
|
|
6705
|
+
});
|
|
6706
|
+
const showVoice = voiceMessage !== false && attachments !== false && recorder.supported;
|
|
6707
|
+
const recordingOn = recorder.state !== "idle";
|
|
6708
|
+
const [voiceNote, setVoiceNote] = (0, import_react15.useState)();
|
|
6709
|
+
const [startedAt, setStartedAt] = (0, import_react15.useState)();
|
|
6710
|
+
const [now, setNow] = (0, import_react15.useState)(() => Date.now());
|
|
6711
|
+
const [lastElapsed, setLastElapsed] = (0, import_react15.useState)();
|
|
6712
|
+
(0, import_react15.useEffect)(() => {
|
|
5722
6713
|
if (!busy) {
|
|
5723
6714
|
if (startedAt !== void 0) setLastElapsed(Date.now() - startedAt);
|
|
5724
6715
|
setStartedAt(void 0);
|
|
@@ -5731,7 +6722,7 @@ ${draftText}` : draftText);
|
|
|
5731
6722
|
return () => clearInterval(id);
|
|
5732
6723
|
}, [busy]);
|
|
5733
6724
|
const elapsed = startedAt !== void 0 ? now - startedAt : lastElapsed;
|
|
5734
|
-
const allCommands = (0,
|
|
6725
|
+
const allCommands = (0, import_react15.useMemo)(() => {
|
|
5735
6726
|
const out = [];
|
|
5736
6727
|
if (builtinCommands) {
|
|
5737
6728
|
out.push(
|
|
@@ -5814,8 +6805,8 @@ ${draftText}` : draftText);
|
|
|
5814
6805
|
const closeMenu = () => setMenu(void 0);
|
|
5815
6806
|
const modelMenuKeys = useMenuKeys(menu === "model", modelMenuRef, modelChipRef, closeMenu);
|
|
5816
6807
|
const modeMenuKeys = useMenuKeys(menu === "mode", modeMenuRef, modeChipRef, closeMenu);
|
|
5817
|
-
(0,
|
|
5818
|
-
(0,
|
|
6808
|
+
(0, import_react15.useEffect)(() => setActive(0), [text2, menu]);
|
|
6809
|
+
(0, import_react15.useEffect)(() => {
|
|
5819
6810
|
if (!menu) return;
|
|
5820
6811
|
const onDown = (e) => {
|
|
5821
6812
|
if (!rootRef.current?.contains(e.target)) setMenu(void 0);
|
|
@@ -5835,17 +6826,44 @@ ${draftText}` : draftText);
|
|
|
5835
6826
|
void cmd.run?.(args);
|
|
5836
6827
|
};
|
|
5837
6828
|
const attachCfg = typeof attachments === "object" ? attachments : {};
|
|
5838
|
-
const
|
|
6829
|
+
const bounds = {
|
|
6830
|
+
maxBytes: attachCfg.maxBytes ?? ATTACHMENT_BOUNDS.maxBytes,
|
|
6831
|
+
maxSourceBytes: attachCfg.maxSourceBytes ?? ATTACHMENT_BOUNDS.maxSourceBytes,
|
|
6832
|
+
imageMaxSourcePixels: attachCfg.imageMaxSourcePixels ?? ATTACHMENT_BOUNDS.imageMaxSourcePixels,
|
|
6833
|
+
maxImages: attachCfg.maxImages ?? ATTACHMENT_BOUNDS.maxImages,
|
|
6834
|
+
maxTotalBytes: attachCfg.maxTotalBytes ?? ATTACHMENT_BOUNDS.maxTotalBytes
|
|
6835
|
+
};
|
|
5839
6836
|
const imageMax = attachCfg.imageMaxDimension ?? 1568;
|
|
6837
|
+
const overLimitText = (name, over) => over.bound === "pixels" ? L.tooManyPixels(name, Math.round(over.limit / 1e6)) : L.tooLarge(name, Math.round(over.limit / 1024 / 1024));
|
|
5840
6838
|
const addFiles = async (list) => {
|
|
5841
|
-
const added = [];
|
|
5842
6839
|
let problem;
|
|
6840
|
+
const noRoom = { images: [], bytes: [] };
|
|
6841
|
+
const add = (name, a) => {
|
|
6842
|
+
const full = messageOverLimit(pendingRef.current, a, bounds);
|
|
6843
|
+
if (full) noRoom[full].push(name);
|
|
6844
|
+
else setPending((cur) => [...cur, a]);
|
|
6845
|
+
};
|
|
5843
6846
|
for (const f of list) {
|
|
5844
6847
|
const mediaType = f.type || "application/octet-stream";
|
|
5845
6848
|
const name = f.name || `pasted-${Date.now()}.${mediaType.split("/")[1] ?? "bin"}`;
|
|
5846
6849
|
const kind = attachmentKindOf(mediaType, name);
|
|
5847
|
-
|
|
5848
|
-
|
|
6850
|
+
const refusal = attachmentRefusal(kind, caps);
|
|
6851
|
+
const converts = Boolean(convertFile && (refusal || kind === "pdf" && convert === "always"));
|
|
6852
|
+
const transform = attachmentTransformOf({
|
|
6853
|
+
kind,
|
|
6854
|
+
mediaType,
|
|
6855
|
+
imageMaxDimension: imageMax,
|
|
6856
|
+
converts
|
|
6857
|
+
});
|
|
6858
|
+
const size = transform === "downscale" ? await imageSizeOf(f) : void 0;
|
|
6859
|
+
const pixels = size && size.width * size.height;
|
|
6860
|
+
const over = attachmentOverLimit({ bytes: f.size, pixels }, "original", transform, bounds);
|
|
6861
|
+
if (over) {
|
|
6862
|
+
problem = overLimitText(name, over);
|
|
6863
|
+
continue;
|
|
6864
|
+
}
|
|
6865
|
+
if (kind === "image" && transform !== "convert" && messageOverLimit(pendingRef.current, { kind, bytes: 0 }, bounds) === "images") {
|
|
6866
|
+
noRoom.images.push(name);
|
|
5849
6867
|
continue;
|
|
5850
6868
|
}
|
|
5851
6869
|
try {
|
|
@@ -5856,22 +6874,26 @@ ${draftText}` : draftText);
|
|
|
5856
6874
|
problem = L.binaryText(name);
|
|
5857
6875
|
continue;
|
|
5858
6876
|
}
|
|
5859
|
-
|
|
6877
|
+
add(name, { id, name, kind, mediaType, text: content, bytes: f.size });
|
|
5860
6878
|
continue;
|
|
5861
6879
|
}
|
|
5862
|
-
|
|
5863
|
-
const wantConvert = convertFile && (refusal || kind === "pdf" && convert === "always");
|
|
5864
|
-
if (wantConvert && convertFile) {
|
|
6880
|
+
if (converts && convertFile) {
|
|
5865
6881
|
const converted = await convertFile(f);
|
|
5866
6882
|
if (converted) {
|
|
5867
|
-
|
|
6883
|
+
const bytes = new Blob([converted.text]).size;
|
|
6884
|
+
const sentOver2 = attachmentOverLimit({ bytes }, "sent", transform, bounds);
|
|
6885
|
+
if (sentOver2) {
|
|
6886
|
+
problem = overLimitText(name, sentOver2);
|
|
6887
|
+
continue;
|
|
6888
|
+
}
|
|
6889
|
+
add(name, {
|
|
5868
6890
|
id,
|
|
5869
6891
|
name: converted.name ?? `${name}.md`,
|
|
5870
6892
|
kind: "text",
|
|
5871
6893
|
mediaType: "text/markdown",
|
|
5872
6894
|
text: converted.text,
|
|
5873
|
-
bytes
|
|
5874
|
-
note:
|
|
6895
|
+
bytes,
|
|
6896
|
+
note: L.convertedFrom(name)
|
|
5875
6897
|
});
|
|
5876
6898
|
continue;
|
|
5877
6899
|
}
|
|
@@ -5880,27 +6902,75 @@ ${draftText}` : draftText);
|
|
|
5880
6902
|
problem = refusal;
|
|
5881
6903
|
continue;
|
|
5882
6904
|
}
|
|
5883
|
-
const blob =
|
|
6905
|
+
const blob = transform === "downscale" ? await downscaleImage(f, {
|
|
5884
6906
|
maxDimension: imageMax,
|
|
5885
6907
|
maxPixels: attachCfg.imageMaxPixels
|
|
5886
6908
|
}) : f;
|
|
5887
|
-
|
|
6909
|
+
const sentOver = attachmentOverLimit({ bytes: blob.size }, "sent", transform, bounds);
|
|
6910
|
+
if (sentOver) {
|
|
6911
|
+
problem = overLimitText(name, sentOver);
|
|
6912
|
+
continue;
|
|
6913
|
+
}
|
|
6914
|
+
add(name, {
|
|
5888
6915
|
id,
|
|
5889
6916
|
name,
|
|
5890
6917
|
kind,
|
|
5891
6918
|
mediaType: blob.type || mediaType,
|
|
5892
6919
|
dataUrl: await readDataUrl2(blob),
|
|
5893
6920
|
bytes: blob.size,
|
|
5894
|
-
...blob !== f ? { note:
|
|
6921
|
+
...blob !== f ? { note: L.downscaledFrom(L.bytes(f.size)) } : {}
|
|
5895
6922
|
});
|
|
5896
6923
|
} catch (err) {
|
|
5897
6924
|
problem = `${name}: ${err instanceof Error ? err.message : String(err)}`;
|
|
5898
6925
|
}
|
|
5899
6926
|
}
|
|
5900
|
-
|
|
5901
|
-
|
|
6927
|
+
const names = (list2) => list2.length > 3 ? `${list2.slice(0, 3).join(", ")}, \u2026` : list2.join(", ");
|
|
6928
|
+
const said = [
|
|
6929
|
+
problem,
|
|
6930
|
+
noRoom.images.length ? L.tooManyImages(names(noRoom.images), bounds.maxImages) : "",
|
|
6931
|
+
noRoom.bytes.length ? L.messageTooLarge(names(noRoom.bytes), Math.round(bounds.maxTotalBytes / 1024 / 1024)) : ""
|
|
6932
|
+
];
|
|
6933
|
+
setAttachError(said.filter(Boolean).join(" ") || void 0);
|
|
5902
6934
|
if (fileRef.current) fileRef.current.value = "";
|
|
5903
6935
|
};
|
|
6936
|
+
const addRecording = async (audio) => {
|
|
6937
|
+
if (audio.blob.size === 0) return;
|
|
6938
|
+
const name = voiceMessageName(/* @__PURE__ */ new Date(), audioExtensionOf(audio.mediaType));
|
|
6939
|
+
const over = attachmentOverLimit({ bytes: audio.blob.size }, "sent", "none", bounds);
|
|
6940
|
+
if (over) {
|
|
6941
|
+
setAttachError(overLimitText(L.voiceMessage, over));
|
|
6942
|
+
return;
|
|
6943
|
+
}
|
|
6944
|
+
const a = {
|
|
6945
|
+
id: `att-${attachSeq += 1}`,
|
|
6946
|
+
name,
|
|
6947
|
+
kind: "file",
|
|
6948
|
+
mediaType: audio.mediaType,
|
|
6949
|
+
dataUrl: await readDataUrl2(audio.blob),
|
|
6950
|
+
bytes: audio.blob.size,
|
|
6951
|
+
durationMs: audio.durationMs,
|
|
6952
|
+
note: L.audioDuration(formatClock(audio.durationMs))
|
|
6953
|
+
};
|
|
6954
|
+
if (messageOverLimit(pendingRef.current, a, bounds) === "bytes") {
|
|
6955
|
+
setAttachError(
|
|
6956
|
+
L.messageTooLarge(L.voiceMessage, Math.round(bounds.maxTotalBytes / 1024 / 1024))
|
|
6957
|
+
);
|
|
6958
|
+
return;
|
|
6959
|
+
}
|
|
6960
|
+
setPending((cur) => [...cur, a]);
|
|
6961
|
+
};
|
|
6962
|
+
const finishRecording = async () => {
|
|
6963
|
+
const audio = await recorder.stop();
|
|
6964
|
+
if (audio) await addRecording(audio);
|
|
6965
|
+
inputRef.current?.focus();
|
|
6966
|
+
};
|
|
6967
|
+
const limited = recorder.limited;
|
|
6968
|
+
(0, import_react15.useEffect)(() => {
|
|
6969
|
+
if (!limited) return;
|
|
6970
|
+
recorder.clear();
|
|
6971
|
+
setVoiceNote(L.recordingLimit);
|
|
6972
|
+
void addRecording(limited);
|
|
6973
|
+
}, [limited]);
|
|
5904
6974
|
const onPaste = (e) => {
|
|
5905
6975
|
if (attachments === false) return;
|
|
5906
6976
|
const pasted = Array.from(e.clipboardData?.files ?? []);
|
|
@@ -5908,9 +6978,9 @@ ${draftText}` : draftText);
|
|
|
5908
6978
|
e.preventDefault();
|
|
5909
6979
|
void addFiles(pasted);
|
|
5910
6980
|
};
|
|
5911
|
-
const addFilesRef = (0,
|
|
6981
|
+
const addFilesRef = (0, import_react15.useRef)(addFiles);
|
|
5912
6982
|
addFilesRef.current = addFiles;
|
|
5913
|
-
(0,
|
|
6983
|
+
(0, import_react15.useEffect)(() => {
|
|
5914
6984
|
if (attachments === false) return;
|
|
5915
6985
|
const target = dropZone === "window" ? globalThis.window : dropZone === "self" ? rootRef.current : dropZone.current;
|
|
5916
6986
|
if (!target) return;
|
|
@@ -6032,10 +7102,11 @@ ${draftText}` : draftText);
|
|
|
6032
7102
|
mediaType: a.mediaType,
|
|
6033
7103
|
size: a.bytes,
|
|
6034
7104
|
...a.kind === "image" && a.dataUrl ? { dataUrl: a.dataUrl } : {},
|
|
6035
|
-
...a.path ? { path: a.path } : {}
|
|
7105
|
+
...a.path ? { path: a.path } : {},
|
|
7106
|
+
...a.durationMs !== void 0 ? { durationMs: a.durationMs } : {}
|
|
6036
7107
|
}));
|
|
6037
7108
|
const full = withAttachments(goal || L.seeAttachments, items);
|
|
6038
|
-
const label = shown
|
|
7109
|
+
const label = shown;
|
|
6039
7110
|
void agent.run(full, {
|
|
6040
7111
|
...full !== label ? { label } : {},
|
|
6041
7112
|
images: items.filter((a) => a.kind === "image" && a.dataUrl).map(toModel),
|
|
@@ -6076,16 +7147,24 @@ ${draftText}` : draftText);
|
|
|
6076
7147
|
...attachError ? [{ id: `attach:${attachError}`, tone: "warn", text: attachError }] : [],
|
|
6077
7148
|
...stt.error ? [
|
|
6078
7149
|
{
|
|
6079
|
-
id: `stt:${stt.error}`,
|
|
7150
|
+
id: `stt:${stt.error}:${stt.errorMessage ?? ""}`,
|
|
7151
|
+
tone: "warn",
|
|
7152
|
+
text: micProblemText(stt.error, stt.errorMessage, L)
|
|
7153
|
+
}
|
|
7154
|
+
] : [],
|
|
7155
|
+
...recorder.error ? [
|
|
7156
|
+
{
|
|
7157
|
+
id: `rec:${recorder.error}`,
|
|
6080
7158
|
tone: "warn",
|
|
6081
|
-
text:
|
|
7159
|
+
text: micProblemText(recorder.error, void 0, L)
|
|
6082
7160
|
}
|
|
6083
|
-
] : []
|
|
7161
|
+
] : [],
|
|
7162
|
+
...voiceNote ? [{ id: `voice:${voiceNote}`, tone: "info", text: voiceNote }] : []
|
|
6084
7163
|
].filter((n) => !dismissed.has(n.id)) : [];
|
|
6085
7164
|
const runningAgents = agent.subagents.filter((s) => s.status === "running");
|
|
6086
7165
|
const thinkingOptions = thinking?.options ?? DEFAULT_THINKING;
|
|
6087
7166
|
const thinkingLabel = thinking ? thinkingOptions.find((o) => o.id === thinking.value)?.label ?? thinking.value : void 0;
|
|
6088
|
-
const canSend = ready && (text2.trim().length > 0 || pending.length > 0);
|
|
7167
|
+
const canSend = ready && !recordingOn && (text2.trim().length > 0 || pending.length > 0);
|
|
6089
7168
|
const canSteer = busy && steering && text2.trim().length > 0;
|
|
6090
7169
|
const queuedStrip = showQueued && (agent.queued.length > 0 || agent.undelivered.length > 0) ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "awr-queued", children: [
|
|
6091
7170
|
agent.queued.map((q) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "awr-queued__item", role: "status", children: [
|
|
@@ -6129,6 +7208,8 @@ ${draftText}` : draftText);
|
|
|
6129
7208
|
onClick: () => {
|
|
6130
7209
|
setDismissed((d) => new Set(d).add(n.id));
|
|
6131
7210
|
if (n.id.startsWith("attach:")) setAttachError(void 0);
|
|
7211
|
+
if (n.id.startsWith("rec:")) recorder.clear();
|
|
7212
|
+
if (n.id.startsWith("voice:")) setVoiceNote(void 0);
|
|
6132
7213
|
},
|
|
6133
7214
|
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(XIcon, { size: 14 })
|
|
6134
7215
|
}
|
|
@@ -6166,8 +7247,11 @@ ${draftText}` : draftText);
|
|
|
6166
7247
|
const remove = () => setPending((cur) => cur.filter((x) => x.id !== a.id));
|
|
6167
7248
|
if (renderAttachment) return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: renderAttachment(a, remove) }, a.id);
|
|
6168
7249
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "awr-chip awr-file", title: a.note ?? a.mediaType, children: [
|
|
6169
|
-
a.kind === "image" && a.dataUrl ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("img", { className: "awr-file__thumb", src: a.dataUrl, alt: a.name }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(FileIcon, { size: 14 }),
|
|
6170
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.
|
|
7250
|
+
a.kind === "image" && a.dataUrl ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("img", { className: "awr-file__thumb", src: a.dataUrl, alt: a.name }) : a.mediaType.startsWith("audio/") ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(WaveIcon, { size: 14 }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(FileIcon, { size: 14 }),
|
|
7251
|
+
a.note ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "awr-file__text", children: [
|
|
7252
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-file__name", children: a.name }),
|
|
7253
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-file__note", children: a.note })
|
|
7254
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-file__name", children: a.name }),
|
|
6171
7255
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
6172
7256
|
"button",
|
|
6173
7257
|
{
|
|
@@ -6180,6 +7264,33 @@ ${draftText}` : draftText);
|
|
|
6180
7264
|
)
|
|
6181
7265
|
] }, a.id);
|
|
6182
7266
|
}) }),
|
|
7267
|
+
showVoice && recordingOn && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "awr-recording", role: "status", "aria-live": "polite", children: [
|
|
7268
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-recording__dot", "aria-hidden": "true" }),
|
|
7269
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-recording__time", children: L.recording(formatClock(recorder.elapsedMs)) }),
|
|
7270
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
7271
|
+
"button",
|
|
7272
|
+
{
|
|
7273
|
+
type: "button",
|
|
7274
|
+
className: "awr-iconbtn",
|
|
7275
|
+
"aria-label": L.recordingCancel,
|
|
7276
|
+
title: L.recordingCancel,
|
|
7277
|
+
onClick: recorder.cancel,
|
|
7278
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(XIcon, { size: 16 })
|
|
7279
|
+
}
|
|
7280
|
+
),
|
|
7281
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
7282
|
+
"button",
|
|
7283
|
+
{
|
|
7284
|
+
type: "button",
|
|
7285
|
+
className: "awr-iconbtn awr-recording__done",
|
|
7286
|
+
"aria-label": L.recordingDone,
|
|
7287
|
+
title: L.recordingDone,
|
|
7288
|
+
onClick: () => void finishRecording(),
|
|
7289
|
+
disabled: recorder.state !== "recording",
|
|
7290
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CheckIcon, { size: 16 })
|
|
7291
|
+
}
|
|
7292
|
+
)
|
|
7293
|
+
] }),
|
|
6183
7294
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "awr-composer2__inputrow", children: [
|
|
6184
7295
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
6185
7296
|
"textarea",
|
|
@@ -6190,7 +7301,7 @@ ${draftText}` : draftText);
|
|
|
6190
7301
|
onChange: (e) => setText(e.target.value),
|
|
6191
7302
|
onKeyDown,
|
|
6192
7303
|
onPaste,
|
|
6193
|
-
placeholder: stt.listening ? L.listening : busy && steering ? L.placeholderBusy : placeholder ?? L.placeholder,
|
|
7304
|
+
placeholder: stt.finishing ? L.transcribing : stt.listening ? L.listening : busy && steering ? L.placeholderBusy : placeholder ?? L.placeholder,
|
|
6194
7305
|
disabled,
|
|
6195
7306
|
rows: 2,
|
|
6196
7307
|
"aria-label": L.message
|
|
@@ -6200,16 +7311,18 @@ ${draftText}` : draftText);
|
|
|
6200
7311
|
"button",
|
|
6201
7312
|
{
|
|
6202
7313
|
type: "button",
|
|
6203
|
-
className: `awr-iconbtn awr-mic${stt.listening ? " is-on" : ""}`,
|
|
7314
|
+
className: `awr-iconbtn awr-mic${stt.listening ? " is-on" : ""}${stt.finishing ? " is-busy" : ""}`,
|
|
6204
7315
|
"aria-label": stt.listening ? L.stopDictation : L.dictate,
|
|
7316
|
+
"aria-pressed": stt.listening,
|
|
6205
7317
|
title: stt.listening ? L.stopDictation : L.dictateTitle,
|
|
6206
7318
|
onClick: stt.toggle,
|
|
6207
|
-
disabled,
|
|
6208
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(MicIcon, { size: 18 })
|
|
7319
|
+
disabled: disabled || recordingOn || stt.finishing,
|
|
7320
|
+
children: stt.finishing ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SpinnerIcon, { size: 18 }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(MicIcon, { size: 18 })
|
|
6209
7321
|
}
|
|
6210
7322
|
)
|
|
6211
7323
|
] }),
|
|
6212
7324
|
stt.listening && stt.interim && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "awr-composer2__interim", children: stt.interim }),
|
|
7325
|
+
stt.finishing && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "awr-composer2__interim", role: "status", children: L.transcribing }),
|
|
6213
7326
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "awr-toolbar", children: [
|
|
6214
7327
|
attachments !== false && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
6215
7328
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
@@ -6224,6 +7337,22 @@ ${draftText}` : draftText);
|
|
|
6224
7337
|
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(PlusIcon, { size: 18 })
|
|
6225
7338
|
}
|
|
6226
7339
|
),
|
|
7340
|
+
showVoice && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
7341
|
+
"button",
|
|
7342
|
+
{
|
|
7343
|
+
type: "button",
|
|
7344
|
+
className: `awr-iconbtn awr-voicebtn${recordingOn ? " is-on" : ""}`,
|
|
7345
|
+
"aria-label": L.recordVoiceMessage,
|
|
7346
|
+
title: L.recordVoiceMessage,
|
|
7347
|
+
"aria-pressed": recordingOn,
|
|
7348
|
+
onClick: () => {
|
|
7349
|
+
setVoiceNote(void 0);
|
|
7350
|
+
void recorder.start();
|
|
7351
|
+
},
|
|
7352
|
+
disabled: disabled || recordingOn || stt.listening,
|
|
7353
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(WaveIcon, { size: 18 })
|
|
7354
|
+
}
|
|
7355
|
+
),
|
|
6227
7356
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
6228
7357
|
"input",
|
|
6229
7358
|
{
|
|
@@ -6248,7 +7377,7 @@ ${draftText}` : draftText);
|
|
|
6248
7377
|
}
|
|
6249
7378
|
),
|
|
6250
7379
|
toolbarExtra,
|
|
6251
|
-
showTimer && elapsed !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "awr-tchip", title: busy ? L.timerRunning : L.timerLast, children: [
|
|
7380
|
+
showTimer && elapsed !== void 0 && (busy || !compactBar) && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "awr-tchip", title: busy ? L.timerRunning : L.timerLast, children: [
|
|
6252
7381
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ClockIcon, { size: 14 }),
|
|
6253
7382
|
" ",
|
|
6254
7383
|
formatElapsed(elapsed)
|
|
@@ -6284,7 +7413,7 @@ ${draftText}` : draftText);
|
|
|
6284
7413
|
"aria-expanded": menu === "model",
|
|
6285
7414
|
title: [model?.label, thinkingLabel].filter(Boolean).join(" \xB7 "),
|
|
6286
7415
|
children: [
|
|
6287
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-tchip__label", children: model?.label
|
|
7416
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-tchip__label", ref: chipLabelRef, children: chipShort && model?.shortLabel || model?.label || L.model }),
|
|
6288
7417
|
thinkingLabel && !compactBar && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-tchip__sub", children: thinkingLabel })
|
|
6289
7418
|
]
|
|
6290
7419
|
}
|
|
@@ -6358,7 +7487,7 @@ ${draftText}` : draftText);
|
|
|
6358
7487
|
},
|
|
6359
7488
|
`s${i}`
|
|
6360
7489
|
);
|
|
6361
|
-
return runs[i - 1]?.section ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "awr-menu__section awr-menu__section--plain", children: rows }, `s${i}`) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
7490
|
+
return runs[i - 1]?.section ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "awr-menu__section awr-menu__section--plain", children: rows }, `s${i}`) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react15.Fragment, { children: rows }, `s${i}`);
|
|
6362
7491
|
})
|
|
6363
7492
|
] }) : null
|
|
6364
7493
|
]
|
|
@@ -6453,7 +7582,7 @@ ${draftText}` : draftText);
|
|
|
6453
7582
|
};
|
|
6454
7583
|
|
|
6455
7584
|
// src/components/ChatHistoryList.tsx
|
|
6456
|
-
var
|
|
7585
|
+
var import_react16 = require("react");
|
|
6457
7586
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
6458
7587
|
var defaultTime = (ms) => {
|
|
6459
7588
|
const d = new Date(ms);
|
|
@@ -6523,7 +7652,7 @@ var ChatHistoryList = ({
|
|
|
6523
7652
|
}
|
|
6524
7653
|
)
|
|
6525
7654
|
] }, c.id);
|
|
6526
|
-
return renderChat ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
7655
|
+
return renderChat ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react16.Fragment, { children: renderChat(c, active, row) }, c.id) : row;
|
|
6527
7656
|
}) })
|
|
6528
7657
|
] });
|
|
6529
7658
|
};
|
|
@@ -6689,7 +7818,7 @@ var ContextMeter = ({
|
|
|
6689
7818
|
};
|
|
6690
7819
|
|
|
6691
7820
|
// src/components/ElicitationPrompt.tsx
|
|
6692
|
-
var
|
|
7821
|
+
var import_react17 = require("react");
|
|
6693
7822
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
6694
7823
|
var reasonText = (outcome, L) => {
|
|
6695
7824
|
const reason = outcome.reason;
|
|
@@ -6699,8 +7828,8 @@ var reasonText = (outcome, L) => {
|
|
|
6699
7828
|
return reason || outcome.status;
|
|
6700
7829
|
};
|
|
6701
7830
|
var useNow = (active) => {
|
|
6702
|
-
const [now, setNow] = (0,
|
|
6703
|
-
(0,
|
|
7831
|
+
const [now, setNow] = (0, import_react17.useState)(() => Date.now());
|
|
7832
|
+
(0, import_react17.useEffect)(() => {
|
|
6704
7833
|
if (!active) return;
|
|
6705
7834
|
setNow(Date.now());
|
|
6706
7835
|
const timer = setInterval(() => setNow(Date.now()), 1e3);
|
|
@@ -6828,11 +7957,11 @@ var FieldControl = ({ field, id, value, issue, onChange, L }) => {
|
|
|
6828
7957
|
] });
|
|
6829
7958
|
};
|
|
6830
7959
|
var FormBody = ({ elicitation, answer, L }) => {
|
|
6831
|
-
const baseId = (0,
|
|
7960
|
+
const baseId = (0, import_react17.useId)();
|
|
6832
7961
|
const schema = elicitation.requestedSchema;
|
|
6833
7962
|
const fields = elicitationFields(schema);
|
|
6834
|
-
const [draft, setDraft] = (0,
|
|
6835
|
-
const [issues, setIssues] = (0,
|
|
7963
|
+
const [draft, setDraft] = (0, import_react17.useState)(() => elicitationInitialDraft(schema));
|
|
7964
|
+
const [issues, setIssues] = (0, import_react17.useState)(void 0);
|
|
6836
7965
|
const fieldId = (i) => `${baseId}-f${i}`;
|
|
6837
7966
|
const submit = (e) => {
|
|
6838
7967
|
e.preventDefault();
|
|
@@ -6887,7 +8016,7 @@ var FormBody = ({ elicitation, answer, L }) => {
|
|
|
6887
8016
|
};
|
|
6888
8017
|
var UrlBody = ({ elicitation, answer, L }) => {
|
|
6889
8018
|
const link = elicitationLink(elicitation.url);
|
|
6890
|
-
const [opened, setOpened] = (0,
|
|
8019
|
+
const [opened, setOpened] = (0, import_react17.useState)(false);
|
|
6891
8020
|
const open = () => {
|
|
6892
8021
|
if (!link.openable || typeof window === "undefined") return;
|
|
6893
8022
|
window.open(link.href, "_blank", "noopener,noreferrer");
|
|
@@ -6951,7 +8080,7 @@ var ElicitationPrompt = ({
|
|
|
6951
8080
|
className
|
|
6952
8081
|
}) => {
|
|
6953
8082
|
const L = useLabels(labels);
|
|
6954
|
-
const [dismissed, setDismissed] = (0,
|
|
8083
|
+
const [dismissed, setDismissed] = (0, import_react17.useState)(() => /* @__PURE__ */ new Set());
|
|
6955
8084
|
const automatic = showOutcomes ? (outcomes ?? []).filter(
|
|
6956
8085
|
(o) => o.automatic === true && o.status !== "pending" && !dismissed.has(o.id)
|
|
6957
8086
|
) : [];
|
|
@@ -7012,21 +8141,21 @@ var ElicitationPrompt = ({
|
|
|
7012
8141
|
};
|
|
7013
8142
|
|
|
7014
8143
|
// src/components/FilesPanel.tsx
|
|
7015
|
-
var
|
|
8144
|
+
var import_react19 = require("react");
|
|
7016
8145
|
|
|
7017
8146
|
// src/components/ImageViewer.tsx
|
|
7018
|
-
var
|
|
8147
|
+
var import_react18 = require("react");
|
|
7019
8148
|
var import_react_dom = require("react-dom");
|
|
7020
8149
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
7021
8150
|
var fileNameOf = (name) => name.split(/[\\/]/).filter(Boolean).pop() ?? name;
|
|
7022
8151
|
var SWIPE_PX = 48;
|
|
7023
8152
|
var ImageViewer = ({ images, index, onIndex, onClose, labels }) => {
|
|
7024
8153
|
const L = useLabels(labels);
|
|
7025
|
-
const rootRef = (0,
|
|
7026
|
-
const closeRef = (0,
|
|
7027
|
-
const imgRef = (0,
|
|
7028
|
-
const touch = (0,
|
|
7029
|
-
const [zoom, setZoom] = (0,
|
|
8154
|
+
const rootRef = (0, import_react18.useRef)(null);
|
|
8155
|
+
const closeRef = (0, import_react18.useRef)(null);
|
|
8156
|
+
const imgRef = (0, import_react18.useRef)(null);
|
|
8157
|
+
const touch = (0, import_react18.useRef)(void 0);
|
|
8158
|
+
const [zoom, setZoom] = (0, import_react18.useState)(void 0);
|
|
7030
8159
|
const count = images.length;
|
|
7031
8160
|
const at = Math.min(Math.max(index, 0), count - 1);
|
|
7032
8161
|
const image = images[at];
|
|
@@ -7035,7 +8164,7 @@ var ImageViewer = ({ images, index, onIndex, onClose, labels }) => {
|
|
|
7035
8164
|
setZoom(void 0);
|
|
7036
8165
|
onIndex((at + step + count) % count);
|
|
7037
8166
|
};
|
|
7038
|
-
(0,
|
|
8167
|
+
(0, import_react18.useEffect)(() => {
|
|
7039
8168
|
closeRef.current?.focus();
|
|
7040
8169
|
const root = document.documentElement;
|
|
7041
8170
|
const before = root.style.overflow;
|
|
@@ -7044,7 +8173,7 @@ var ImageViewer = ({ images, index, onIndex, onClose, labels }) => {
|
|
|
7044
8173
|
root.style.overflow = before;
|
|
7045
8174
|
};
|
|
7046
8175
|
}, []);
|
|
7047
|
-
const keys = (0,
|
|
8176
|
+
const keys = (0, import_react18.useRef)(() => {
|
|
7048
8177
|
});
|
|
7049
8178
|
keys.current = (e) => {
|
|
7050
8179
|
if (e.key === "Escape") {
|
|
@@ -7070,7 +8199,7 @@ var ImageViewer = ({ images, index, onIndex, onClose, labels }) => {
|
|
|
7070
8199
|
}
|
|
7071
8200
|
}
|
|
7072
8201
|
};
|
|
7073
|
-
(0,
|
|
8202
|
+
(0, import_react18.useEffect)(() => {
|
|
7074
8203
|
const onKey = (e) => keys.current(e);
|
|
7075
8204
|
document.addEventListener("keydown", onKey, true);
|
|
7076
8205
|
return () => document.removeEventListener("keydown", onKey, true);
|
|
@@ -7184,7 +8313,7 @@ var ImageViewer = ({ images, index, onIndex, onClose, labels }) => {
|
|
|
7184
8313
|
] })
|
|
7185
8314
|
] });
|
|
7186
8315
|
};
|
|
7187
|
-
var ImageViewerContext = (0,
|
|
8316
|
+
var ImageViewerContext = (0, import_react18.createContext)({ enabled: true });
|
|
7188
8317
|
var ImageViewerProvider = ({
|
|
7189
8318
|
enabled = true,
|
|
7190
8319
|
render,
|
|
@@ -7213,9 +8342,9 @@ var ImageThumb = ({
|
|
|
7213
8342
|
labels
|
|
7214
8343
|
}) => {
|
|
7215
8344
|
const L = useLabels(labels);
|
|
7216
|
-
const { enabled, render } = (0,
|
|
7217
|
-
const ref = (0,
|
|
7218
|
-
const [open, setOpen] = (0,
|
|
8345
|
+
const { enabled, render } = (0, import_react18.useContext)(ImageViewerContext);
|
|
8346
|
+
const ref = (0, import_react18.useRef)(null);
|
|
8347
|
+
const [open, setOpen] = (0, import_react18.useState)(void 0);
|
|
7219
8348
|
const img = /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("img", { className: imgClassName, src, alt });
|
|
7220
8349
|
if (!enabled) {
|
|
7221
8350
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("a", { className, href: src, target: "_blank", rel: "noopener noreferrer", title, children: img });
|
|
@@ -7277,9 +8406,9 @@ var FilesPanel = ({
|
|
|
7277
8406
|
}) => {
|
|
7278
8407
|
const L = useLabels(labels);
|
|
7279
8408
|
const fs = useVirtualFiles(vfs, prefix);
|
|
7280
|
-
const [preview, setPreview] = (0,
|
|
7281
|
-
const inputRef = (0,
|
|
7282
|
-
(0,
|
|
8409
|
+
const [preview, setPreview] = (0, import_react19.useState)();
|
|
8410
|
+
const inputRef = (0, import_react19.useRef)(null);
|
|
8411
|
+
(0, import_react19.useEffect)(() => {
|
|
7283
8412
|
if (preview && !fs.files.some((f) => f.path === preview.path)) setPreview(void 0);
|
|
7284
8413
|
}, [fs.files, preview]);
|
|
7285
8414
|
const open = async (f) => {
|
|
@@ -7380,7 +8509,7 @@ var FilesPanel = ({
|
|
|
7380
8509
|
},
|
|
7381
8510
|
f.path
|
|
7382
8511
|
);
|
|
7383
|
-
return renderFile ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
8512
|
+
return renderFile ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react19.Fragment, { children: renderFile(f, row) }, f.path) : row;
|
|
7384
8513
|
}) }),
|
|
7385
8514
|
preview && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "awr-filepreview", children: preview.kind === "image" ? (
|
|
7386
8515
|
// A click (Enter, Space) opens it over the chat, fitted to the screen.
|
|
@@ -7400,7 +8529,7 @@ var FilesPanel = ({
|
|
|
7400
8529
|
};
|
|
7401
8530
|
|
|
7402
8531
|
// src/components/FileChips.tsx
|
|
7403
|
-
var
|
|
8532
|
+
var import_react21 = require("react");
|
|
7404
8533
|
|
|
7405
8534
|
// src/file-kinds.ts
|
|
7406
8535
|
var import_agent_web6 = require("@dudko.dev/agent-web");
|
|
@@ -7421,7 +8550,7 @@ var fileKindOf = (path, mediaType) => {
|
|
|
7421
8550
|
var fileNameOf2 = (path) => path.split("/").filter(Boolean).pop() || "file";
|
|
7422
8551
|
|
|
7423
8552
|
// src/components/Media.tsx
|
|
7424
|
-
var
|
|
8553
|
+
var import_react20 = require("react");
|
|
7425
8554
|
var import_agent_web7 = require("@dudko.dev/agent-web");
|
|
7426
8555
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
7427
8556
|
var mediaFamilyOf = (mediaType) => {
|
|
@@ -7438,8 +8567,8 @@ var bytesOf = (content, encoding) => {
|
|
|
7438
8567
|
return bytes;
|
|
7439
8568
|
};
|
|
7440
8569
|
var useFileUrl = (files, path, mediaType) => {
|
|
7441
|
-
const [url, setUrl] = (0,
|
|
7442
|
-
(0,
|
|
8570
|
+
const [url, setUrl] = (0, import_react20.useState)(void 0);
|
|
8571
|
+
(0, import_react20.useEffect)(() => {
|
|
7443
8572
|
if (!files || !mediaType) return;
|
|
7444
8573
|
let made;
|
|
7445
8574
|
let gone = false;
|
|
@@ -7459,13 +8588,14 @@ var useFileUrl = (files, path, mediaType) => {
|
|
|
7459
8588
|
}, [files, path, mediaType]);
|
|
7460
8589
|
return url;
|
|
7461
8590
|
};
|
|
8591
|
+
var baseName = (path) => path.split(/[\\/]/).filter(Boolean).pop() ?? path;
|
|
7462
8592
|
var GeneratedMedia = ({ media, files, labels }) => {
|
|
7463
8593
|
const L = useLabels(labels);
|
|
7464
8594
|
const family = mediaFamilyOf(media.mediaType);
|
|
7465
8595
|
const type = family ? media.mediaType.toLowerCase().split(";")[0].trim() : void 0;
|
|
7466
8596
|
const url = useFileUrl(files, media.path, type);
|
|
7467
8597
|
if (url && family === "image") {
|
|
7468
|
-
|
|
8598
|
+
const thumb = /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
7469
8599
|
ImageThumb,
|
|
7470
8600
|
{
|
|
7471
8601
|
className: "awr-media awr-media--image",
|
|
@@ -7477,6 +8607,20 @@ var GeneratedMedia = ({ media, files, labels }) => {
|
|
|
7477
8607
|
labels
|
|
7478
8608
|
}
|
|
7479
8609
|
);
|
|
8610
|
+
const refs = media.references;
|
|
8611
|
+
if (!refs || refs.paths.length === 0) return thumb;
|
|
8612
|
+
const names = refs.paths.map(baseName).join(", ");
|
|
8613
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("span", { className: "awr-media-refs", children: [
|
|
8614
|
+
thumb,
|
|
8615
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
8616
|
+
"span",
|
|
8617
|
+
{
|
|
8618
|
+
className: `awr-media__refs${refs.used ? "" : " awr-media__refs--unused"}`,
|
|
8619
|
+
title: refs.paths.join("\n"),
|
|
8620
|
+
children: refs.used ? L.mediaReferences(names) : L.mediaReferencesUnused(names)
|
|
8621
|
+
}
|
|
8622
|
+
)
|
|
8623
|
+
] });
|
|
7480
8624
|
}
|
|
7481
8625
|
if (url && family === "audio") {
|
|
7482
8626
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "awr-media awr-media--audio", title: media.path, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
@@ -7608,14 +8752,14 @@ var SourceView = ({
|
|
|
7608
8752
|
const L = useLabels(labels);
|
|
7609
8753
|
const cut = text2.length > maxChars;
|
|
7610
8754
|
const shown = cut ? text2.slice(0, maxChars) : text2;
|
|
7611
|
-
const lines = (0,
|
|
8755
|
+
const lines = (0, import_react21.useMemo)(
|
|
7612
8756
|
() => linesOf(html ? tokenizeHtml(shown) : [{ kind: "text", text: shown }]),
|
|
7613
8757
|
[shown, html]
|
|
7614
8758
|
);
|
|
7615
8759
|
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
|
|
7616
8760
|
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("pre", { className: ["awr-source", className].filter(Boolean).join(" "), tabIndex: 0, children: lines.map((line, i) => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("span", { className: "awr-source__line", children: [
|
|
7617
8761
|
line.map(
|
|
7618
|
-
(t, k) => t.kind === "text" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
8762
|
+
(t, k) => t.kind === "text" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react21.Fragment, { children: t.text }, k) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: `awr-source__${t.kind}`, children: t.text }, k)
|
|
7619
8763
|
),
|
|
7620
8764
|
"\n"
|
|
7621
8765
|
] }, i)) }),
|
|
@@ -7623,16 +8767,16 @@ var SourceView = ({
|
|
|
7623
8767
|
] });
|
|
7624
8768
|
};
|
|
7625
8769
|
var HtmlPreview = ({ written, file, htmlPreview, previewChars, L }) => {
|
|
7626
|
-
const html = (0,
|
|
8770
|
+
const html = (0, import_react21.useMemo)(() => textOf(file), [file]);
|
|
7627
8771
|
const options = htmlPreview === false ? void 0 : htmlPreview;
|
|
7628
8772
|
const tooLarge = html.length > HTML_PREVIEW_MAX_CHARS;
|
|
7629
8773
|
const canFrame = Boolean(options) && !tooLarge;
|
|
7630
|
-
const [view, setView] = (0,
|
|
7631
|
-
const [tall, setTall] = (0,
|
|
8774
|
+
const [view, setView] = (0, import_react21.useState)(canFrame ? "preview" : "source");
|
|
8775
|
+
const [tall, setTall] = (0, import_react21.useState)(false);
|
|
7632
8776
|
const showing = canFrame ? view : "source";
|
|
7633
8777
|
const scripts = options?.scripts === true;
|
|
7634
8778
|
const height = options?.height ?? 300;
|
|
7635
|
-
const linked = (0,
|
|
8779
|
+
const linked = (0, import_react21.useMemo)(() => showing === "preview" ? linkedFilesOf(html) : [], [html, showing]);
|
|
7636
8780
|
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7637
8781
|
SandboxedFrame,
|
|
7638
8782
|
{
|
|
@@ -7745,14 +8889,14 @@ var TextPreview = ({
|
|
|
7745
8889
|
onClose,
|
|
7746
8890
|
L
|
|
7747
8891
|
}) => {
|
|
7748
|
-
const text2 = (0,
|
|
7749
|
-
const rendered = (0,
|
|
8892
|
+
const text2 = (0, import_react21.useMemo)(() => textOf(file), [file]);
|
|
8893
|
+
const rendered = (0, import_react21.useMemo)(
|
|
7750
8894
|
() => renderFileContent?.(written, text2.slice(0, previewChars)),
|
|
7751
8895
|
[renderFileContent, written, text2, previewChars]
|
|
7752
8896
|
);
|
|
7753
8897
|
const hasRendered = rendered !== void 0 && rendered !== null && rendered !== false;
|
|
7754
|
-
const [view, setView] = (0,
|
|
7755
|
-
const [all, setAll] = (0,
|
|
8898
|
+
const [view, setView] = (0, import_react21.useState)("rendered");
|
|
8899
|
+
const [all, setAll] = (0, import_react21.useState)(false);
|
|
7756
8900
|
const showing = hasRendered ? view : "source";
|
|
7757
8901
|
const long = text2.length > 1200 || text2.split("\n").length > 16;
|
|
7758
8902
|
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "awr-fileview", children: [
|
|
@@ -7794,11 +8938,11 @@ var FileChips = ({
|
|
|
7794
8938
|
}) => {
|
|
7795
8939
|
const L = useLabels(labels);
|
|
7796
8940
|
const live = useVirtualFiles(vfs);
|
|
7797
|
-
const [openPath, setOpenPath] = (0,
|
|
7798
|
-
const [file, setFile] = (0,
|
|
8941
|
+
const [openPath, setOpenPath] = (0, import_react21.useState)(defaultOpen);
|
|
8942
|
+
const [file, setFile] = (0, import_react21.useState)();
|
|
7799
8943
|
const open = written.find((f) => f.path === openPath);
|
|
7800
8944
|
const stamp = live.files.find((f) => f.path === openPath)?.updatedAt;
|
|
7801
|
-
(0,
|
|
8945
|
+
(0, import_react21.useEffect)(() => {
|
|
7802
8946
|
if (!vfs || !openPath) return setFile(void 0);
|
|
7803
8947
|
let gone = false;
|
|
7804
8948
|
vfs.read(openPath).then((f) => {
|
|
@@ -7921,14 +9065,14 @@ var FileChip = ({
|
|
|
7921
9065
|
};
|
|
7922
9066
|
|
|
7923
9067
|
// src/components/StepList.tsx
|
|
7924
|
-
var
|
|
9068
|
+
var import_react23 = require("react");
|
|
7925
9069
|
|
|
7926
9070
|
// src/components/SubagentTree.tsx
|
|
7927
|
-
var
|
|
9071
|
+
var import_react22 = require("react");
|
|
7928
9072
|
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
7929
9073
|
var useElapsed = (startedAt, running) => {
|
|
7930
|
-
const [now, setNow] = (0,
|
|
7931
|
-
(0,
|
|
9074
|
+
const [now, setNow] = (0, import_react22.useState)(void 0);
|
|
9075
|
+
(0, import_react22.useEffect)(() => {
|
|
7932
9076
|
if (!running || startedAt === void 0) return;
|
|
7933
9077
|
setNow(Date.now());
|
|
7934
9078
|
const timer = setInterval(() => setNow(Date.now()), 1e3);
|
|
@@ -8018,7 +9162,7 @@ var SubagentTree = ({
|
|
|
8018
9162
|
},
|
|
8019
9163
|
node.id
|
|
8020
9164
|
);
|
|
8021
|
-
return renderSubagent ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
9165
|
+
return renderSubagent ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react22.Fragment, { children: renderSubagent(node, row) }, node.id) : row;
|
|
8022
9166
|
})
|
|
8023
9167
|
}
|
|
8024
9168
|
);
|
|
@@ -8197,7 +9341,7 @@ var StepItem = ({
|
|
|
8197
9341
|
},
|
|
8198
9342
|
i
|
|
8199
9343
|
);
|
|
8200
|
-
return renderToolCall ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
9344
|
+
return renderToolCall ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react23.Fragment, { children: renderToolCall(call, row) }, i) : row;
|
|
8201
9345
|
}) }),
|
|
8202
9346
|
approvals.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("ul", { className: "awr-step__tools", children: approvals.map((a) => /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("li", { className: `awr-tool awr-tool__row awr-tool--approval-${a.status}`, children: [
|
|
8203
9347
|
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ShieldIcon, { size: 13, className: "awr-tool__icon" }),
|
|
@@ -8304,7 +9448,54 @@ var usageLine = (usage, durationMs) => {
|
|
|
8304
9448
|
if (durationMs !== void 0) parts.push(formatDuration(durationMs));
|
|
8305
9449
|
return parts.join(" \xB7 ");
|
|
8306
9450
|
};
|
|
8307
|
-
var
|
|
9451
|
+
var lengthOf = (ms) => typeof ms === "number" && Number.isFinite(ms) && ms >= 0 && ms < 864e5 ? ms : void 0;
|
|
9452
|
+
var settleAudioDuration = (el) => {
|
|
9453
|
+
if (el.duration !== Infinity) return;
|
|
9454
|
+
const back = () => {
|
|
9455
|
+
if (!Number.isFinite(el.duration)) return;
|
|
9456
|
+
el.removeEventListener("durationchange", back);
|
|
9457
|
+
el.removeEventListener("timeupdate", back);
|
|
9458
|
+
el.currentTime = 0;
|
|
9459
|
+
};
|
|
9460
|
+
el.addEventListener("durationchange", back);
|
|
9461
|
+
el.addEventListener("timeupdate", back);
|
|
9462
|
+
el.currentTime = Number.MAX_SAFE_INTEGER;
|
|
9463
|
+
};
|
|
9464
|
+
var AttachedAudio = ({
|
|
9465
|
+
attachment: a,
|
|
9466
|
+
files,
|
|
9467
|
+
labels
|
|
9468
|
+
}) => {
|
|
9469
|
+
const L = useLabels(labels);
|
|
9470
|
+
const type = a.mediaType.toLowerCase().split(";")[0].trim();
|
|
9471
|
+
const url = useFileUrl(files, a.path ?? "", files && a.path ? type : void 0);
|
|
9472
|
+
const length = lengthOf(a.durationMs);
|
|
9473
|
+
const said = length !== void 0 ? L.audioDuration(formatClock(length)) : void 0;
|
|
9474
|
+
return url ? /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("span", { className: "awr-media awr-media--audio awr-msg__audio", title: a.path ?? a.name, children: [
|
|
9475
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
9476
|
+
"audio",
|
|
9477
|
+
{
|
|
9478
|
+
className: "awr-media__audio",
|
|
9479
|
+
controls: true,
|
|
9480
|
+
preload: "metadata",
|
|
9481
|
+
src: url,
|
|
9482
|
+
"aria-label": said ? `${L.audioAttachment(a.name)} (${said})` : L.audioAttachment(a.name),
|
|
9483
|
+
onLoadedMetadata: (e) => settleAudioDuration(e.currentTarget)
|
|
9484
|
+
}
|
|
9485
|
+
),
|
|
9486
|
+
said && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "awr-msg__audiolen", "aria-hidden": "true", children: said })
|
|
9487
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("span", { className: "awr-chip awr-file", title: a.path ?? a.mediaType, children: [
|
|
9488
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(WaveIcon, { size: 13 }),
|
|
9489
|
+
" ",
|
|
9490
|
+
a.name,
|
|
9491
|
+
said ? ` \xB7 ${said}` : ""
|
|
9492
|
+
] });
|
|
9493
|
+
};
|
|
9494
|
+
var AttachmentView = ({
|
|
9495
|
+
attachment: a,
|
|
9496
|
+
files,
|
|
9497
|
+
labels
|
|
9498
|
+
}) => mediaFamilyOf(a.mediaType) === "audio" ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(AttachedAudio, { attachment: a, files, labels }) : a.dataUrl && a.mediaType.startsWith("image/") ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
8308
9499
|
ImageThumb,
|
|
8309
9500
|
{
|
|
8310
9501
|
src: a.dataUrl,
|
|
@@ -8367,10 +9558,12 @@ var MessageList = ({
|
|
|
8367
9558
|
showApps = true,
|
|
8368
9559
|
imageViewer = true,
|
|
8369
9560
|
renderImageViewer,
|
|
9561
|
+
readAloud,
|
|
8370
9562
|
labels,
|
|
8371
9563
|
className
|
|
8372
9564
|
}) => {
|
|
8373
9565
|
const L = useLabels(labels);
|
|
9566
|
+
const reader = useReadAloud(readAloud?.speak, readAloud?.lang);
|
|
8374
9567
|
if (messages.length === 0) {
|
|
8375
9568
|
return empty ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "awr-messages__empty", children: empty }) : null;
|
|
8376
9569
|
}
|
|
@@ -8466,7 +9659,24 @@ var MessageList = ({
|
|
|
8466
9659
|
labels
|
|
8467
9660
|
}
|
|
8468
9661
|
) : null,
|
|
8469
|
-
m.attachments?.length ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
9662
|
+
m.attachments?.length ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
9663
|
+
"div",
|
|
9664
|
+
{
|
|
9665
|
+
className: "awr-msg__attachments",
|
|
9666
|
+
role: "group",
|
|
9667
|
+
"aria-label": m.content.trim() ? L.attachments : attachmentsText(m.attachments, { voiceMessage: L.voiceMessage }),
|
|
9668
|
+
children: m.attachments.map((a, i) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "awr-msg__attachment", children: renderAttachment ? renderAttachment(a, m) : /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(AttachmentView, { attachment: a, files, labels }) }, i))
|
|
9669
|
+
}
|
|
9670
|
+
) : null,
|
|
9671
|
+
readAloud && m.role === "assistant" && m.content && !m.pending && !m.error && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
9672
|
+
ReadAloudControl,
|
|
9673
|
+
{
|
|
9674
|
+
id: m.id,
|
|
9675
|
+
text: () => readAloud.textOf ? readAloud.textOf(m) : speakableText(m.content, { code: L.readAloudCode }),
|
|
9676
|
+
reader,
|
|
9677
|
+
labels: L
|
|
9678
|
+
}
|
|
9679
|
+
),
|
|
8470
9680
|
m.role === "assistant" && usage && !m.pending && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "awr-msg__usage", title: L.usageTitle, children: usage })
|
|
8471
9681
|
] })
|
|
8472
9682
|
},
|
|
@@ -8475,6 +9685,78 @@ var MessageList = ({
|
|
|
8475
9685
|
return renderMessage ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { children: renderMessage(m, node) }, m.id) : node;
|
|
8476
9686
|
}) }) });
|
|
8477
9687
|
};
|
|
9688
|
+
var ReadAloudControl = ({
|
|
9689
|
+
id,
|
|
9690
|
+
text: text2,
|
|
9691
|
+
reader,
|
|
9692
|
+
labels: L
|
|
9693
|
+
}) => {
|
|
9694
|
+
const mine = reader.current === id;
|
|
9695
|
+
const failed = reader.failed?.id === id ? reader.failed : void 0;
|
|
9696
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "awr-readaloud", "data-state": mine ? reader.state : "idle", children: [
|
|
9697
|
+
!mine ? /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
9698
|
+
"button",
|
|
9699
|
+
{
|
|
9700
|
+
type: "button",
|
|
9701
|
+
className: "awr-linkbtn awr-readaloud__btn",
|
|
9702
|
+
onClick: () => reader.start(id, text2()),
|
|
9703
|
+
"aria-label": L.readAloud,
|
|
9704
|
+
children: [
|
|
9705
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SpeakerIcon, { size: 14 }),
|
|
9706
|
+
" ",
|
|
9707
|
+
L.readAloud
|
|
9708
|
+
]
|
|
9709
|
+
}
|
|
9710
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
|
|
9711
|
+
reader.state === "loading" ? /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("span", { className: "awr-readaloud__status", role: "status", children: [
|
|
9712
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SpinnerIcon, { size: 14 }),
|
|
9713
|
+
" ",
|
|
9714
|
+
L.readAloudLoading
|
|
9715
|
+
] }) : reader.state === "paused" ? /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
9716
|
+
"button",
|
|
9717
|
+
{
|
|
9718
|
+
type: "button",
|
|
9719
|
+
className: "awr-linkbtn awr-readaloud__btn",
|
|
9720
|
+
onClick: reader.resume,
|
|
9721
|
+
"aria-label": L.readAloudResume,
|
|
9722
|
+
children: [
|
|
9723
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(PlayIcon, { size: 14 }),
|
|
9724
|
+
" ",
|
|
9725
|
+
L.readAloudResume
|
|
9726
|
+
]
|
|
9727
|
+
}
|
|
9728
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
9729
|
+
"button",
|
|
9730
|
+
{
|
|
9731
|
+
type: "button",
|
|
9732
|
+
className: "awr-linkbtn awr-readaloud__btn",
|
|
9733
|
+
onClick: reader.pause,
|
|
9734
|
+
"aria-label": L.readAloudPause,
|
|
9735
|
+
children: [
|
|
9736
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(PauseIcon, { size: 14 }),
|
|
9737
|
+
" ",
|
|
9738
|
+
L.readAloudPause
|
|
9739
|
+
]
|
|
9740
|
+
}
|
|
9741
|
+
),
|
|
9742
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
9743
|
+
"button",
|
|
9744
|
+
{
|
|
9745
|
+
type: "button",
|
|
9746
|
+
className: "awr-linkbtn awr-readaloud__btn",
|
|
9747
|
+
onClick: reader.stop,
|
|
9748
|
+
"aria-label": L.readAloudStop,
|
|
9749
|
+
children: [
|
|
9750
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(StopIcon, { size: 14 }),
|
|
9751
|
+
" ",
|
|
9752
|
+
L.readAloudStop
|
|
9753
|
+
]
|
|
9754
|
+
}
|
|
9755
|
+
)
|
|
9756
|
+
] }),
|
|
9757
|
+
failed && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "awr-readaloud__error", role: "alert", children: failed.message ?? L.readAloudFailed })
|
|
9758
|
+
] });
|
|
9759
|
+
};
|
|
8478
9760
|
|
|
8479
9761
|
// src/components/ModelLoadBar.tsx
|
|
8480
9762
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
@@ -8493,11 +9775,11 @@ var ModelLoadBar = ({ load, className }) => {
|
|
|
8493
9775
|
};
|
|
8494
9776
|
|
|
8495
9777
|
// src/components/QuestionPrompt.tsx
|
|
8496
|
-
var
|
|
9778
|
+
var import_react24 = require("react");
|
|
8497
9779
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
8498
9780
|
var useNow2 = (active) => {
|
|
8499
|
-
const [now, setNow] = (0,
|
|
8500
|
-
(0,
|
|
9781
|
+
const [now, setNow] = (0, import_react24.useState)(() => Date.now());
|
|
9782
|
+
(0, import_react24.useEffect)(() => {
|
|
8501
9783
|
if (!active) return;
|
|
8502
9784
|
setNow(Date.now());
|
|
8503
9785
|
const timer = setInterval(() => setNow(Date.now()), 1e3);
|
|
@@ -8526,15 +9808,15 @@ var QuestionCard = ({
|
|
|
8526
9808
|
numberKeys,
|
|
8527
9809
|
L
|
|
8528
9810
|
}) => {
|
|
8529
|
-
const baseId = (0,
|
|
9811
|
+
const baseId = (0, import_react24.useId)();
|
|
8530
9812
|
const textId = `${baseId}-q`;
|
|
8531
9813
|
const otherId = `${baseId}-other`;
|
|
8532
|
-
const [picked, setPicked] = (0,
|
|
8533
|
-
const [otherOpen, setOtherOpen] = (0,
|
|
8534
|
-
const [otherText, setOtherText] = (0,
|
|
8535
|
-
const otherField = (0,
|
|
8536
|
-
const otherButton = (0,
|
|
8537
|
-
(0,
|
|
9814
|
+
const [picked, setPicked] = (0, import_react24.useState)([]);
|
|
9815
|
+
const [otherOpen, setOtherOpen] = (0, import_react24.useState)(false);
|
|
9816
|
+
const [otherText, setOtherText] = (0, import_react24.useState)("");
|
|
9817
|
+
const otherField = (0, import_react24.useRef)(null);
|
|
9818
|
+
const otherButton = (0, import_react24.useRef)(null);
|
|
9819
|
+
(0, import_react24.useEffect)(() => {
|
|
8538
9820
|
if (otherOpen) otherField.current?.focus();
|
|
8539
9821
|
}, [otherOpen]);
|
|
8540
9822
|
const helper = showHelper && q.subagent ? { ...q.subagent, ...view?.subagent } : void 0;
|
|
@@ -8665,7 +9947,7 @@ var QuestionCard = ({
|
|
|
8665
9947
|
);
|
|
8666
9948
|
};
|
|
8667
9949
|
var RemoteQuestion = ({ view, L }) => {
|
|
8668
|
-
const textId = `${(0,
|
|
9950
|
+
const textId = `${(0, import_react24.useId)()}-q`;
|
|
8669
9951
|
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
|
|
8670
9952
|
"section",
|
|
8671
9953
|
{
|
|
@@ -8702,7 +9984,7 @@ var QuestionPrompt = ({
|
|
|
8702
9984
|
className
|
|
8703
9985
|
}) => {
|
|
8704
9986
|
const L = useLabels(labels);
|
|
8705
|
-
const [dismissed, setDismissed] = (0,
|
|
9987
|
+
const [dismissed, setDismissed] = (0, import_react24.useState)(() => /* @__PURE__ */ new Set());
|
|
8706
9988
|
const automatic = showOutcomes ? (outcomes ?? []).filter(
|
|
8707
9989
|
(o) => o.automatic === true && o.status !== "pending" && o.status !== "stopped" && !dismissed.has(o.id)
|
|
8708
9990
|
) : [];
|
|
@@ -8959,10 +10241,10 @@ var UsageBadge = ({
|
|
|
8959
10241
|
var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
8960
10242
|
var usePrefersDark = () => {
|
|
8961
10243
|
const query = "(prefers-color-scheme: dark)";
|
|
8962
|
-
const [dark, setDark] = (0,
|
|
10244
|
+
const [dark, setDark] = (0, import_react25.useState)(
|
|
8963
10245
|
() => typeof matchMedia === "function" && matchMedia(query).matches
|
|
8964
10246
|
);
|
|
8965
|
-
(0,
|
|
10247
|
+
(0, import_react25.useEffect)(() => {
|
|
8966
10248
|
if (typeof matchMedia !== "function") return;
|
|
8967
10249
|
const mq = matchMedia(query);
|
|
8968
10250
|
const on = () => setDark(mq.matches);
|
|
@@ -9017,6 +10299,7 @@ var AgentChatInner = ({
|
|
|
9017
10299
|
renderContent,
|
|
9018
10300
|
renderMessage,
|
|
9019
10301
|
renderAttachment,
|
|
10302
|
+
readAloud,
|
|
9020
10303
|
renderToolCall,
|
|
9021
10304
|
renderSubagent,
|
|
9022
10305
|
renderMedia,
|
|
@@ -9052,17 +10335,19 @@ var AgentChatInner = ({
|
|
|
9052
10335
|
}
|
|
9053
10336
|
const L = useLabels();
|
|
9054
10337
|
const external = isHistoryHook(history) ? history : void 0;
|
|
9055
|
-
const [ownStore] = (0,
|
|
10338
|
+
const [ownStore] = (0, import_react25.useState)(
|
|
9056
10339
|
() => history instanceof ChatHistoryStore ? history : new ChatHistoryStore()
|
|
9057
10340
|
);
|
|
9058
10341
|
const own = useChatHistory(agent, {
|
|
9059
10342
|
store: ownStore,
|
|
9060
|
-
enabled: Boolean(history) && !external
|
|
10343
|
+
enabled: Boolean(history) && !external,
|
|
10344
|
+
// A chat begun by a voice message is titled in the chat's language.
|
|
10345
|
+
labels: { voiceMessage: L.voiceMessage }
|
|
9061
10346
|
});
|
|
9062
10347
|
const chats = history ? external ?? own : void 0;
|
|
9063
|
-
const rootRef = (0,
|
|
9064
|
-
const [narrow, setNarrow] = (0,
|
|
9065
|
-
(0,
|
|
10348
|
+
const rootRef = (0, import_react25.useRef)(null);
|
|
10349
|
+
const [narrow, setNarrow] = (0, import_react25.useState)(void 0);
|
|
10350
|
+
(0, import_react25.useEffect)(() => {
|
|
9066
10351
|
const el = rootRef.current;
|
|
9067
10352
|
if (!el || typeof ResizeObserver === "undefined") return setNarrow(false);
|
|
9068
10353
|
const measure2 = () => setNarrow(el.getBoundingClientRect().width < narrowWidth);
|
|
@@ -9071,9 +10356,9 @@ var AgentChatInner = ({
|
|
|
9071
10356
|
ro.observe(el);
|
|
9072
10357
|
return () => ro.disconnect();
|
|
9073
10358
|
}, [narrowWidth]);
|
|
9074
|
-
const [historyChoice, setHistoryOpen] = (0,
|
|
10359
|
+
const [historyChoice, setHistoryOpen] = (0, import_react25.useState)(defaultHistoryOpen);
|
|
9075
10360
|
const historyOpen = historyChoice ?? narrow === false;
|
|
9076
|
-
const [filesOpen, setFilesOpen] = (0,
|
|
10361
|
+
const [filesOpen, setFilesOpen] = (0, import_react25.useState)(defaultFilesOpen);
|
|
9077
10362
|
const toggleHistory = () => {
|
|
9078
10363
|
setHistoryOpen(!historyOpen);
|
|
9079
10364
|
if (narrow && !historyOpen) setFilesOpen(false);
|
|
@@ -9091,7 +10376,7 @@ var AgentChatInner = ({
|
|
|
9091
10376
|
setHistoryOpen(false);
|
|
9092
10377
|
setFilesOpen(false);
|
|
9093
10378
|
};
|
|
9094
|
-
(0,
|
|
10379
|
+
(0, import_react25.useEffect)(() => {
|
|
9095
10380
|
if (!overlayOpen) return;
|
|
9096
10381
|
const onKey = (e) => {
|
|
9097
10382
|
if (e.key !== "Escape" || e.defaultPrevented) return;
|
|
@@ -9101,7 +10386,7 @@ var AgentChatInner = ({
|
|
|
9101
10386
|
document.addEventListener("keydown", onKey);
|
|
9102
10387
|
return () => document.removeEventListener("keydown", onKey);
|
|
9103
10388
|
}, [overlayOpen]);
|
|
9104
|
-
const bodyRef = (0,
|
|
10389
|
+
const bodyRef = (0, import_react25.useRef)(null);
|
|
9105
10390
|
const appHost = useMcpAppHost({
|
|
9106
10391
|
connection: mcpApps,
|
|
9107
10392
|
approve: agent.approveAppToolCall,
|
|
@@ -9113,7 +10398,7 @@ var AgentChatInner = ({
|
|
|
9113
10398
|
});
|
|
9114
10399
|
const prefersDark = usePrefersDark();
|
|
9115
10400
|
const appTheme = theme === "auto" ? prefersDark ? "dark" : "light" : theme;
|
|
9116
|
-
const [panelApp, setPanelAppState] = (0,
|
|
10401
|
+
const [panelApp, setPanelAppState] = (0, import_react25.useState)();
|
|
9117
10402
|
const setPanelApp = (app) => {
|
|
9118
10403
|
setPanelAppState(app);
|
|
9119
10404
|
onAppPanel?.(app);
|
|
@@ -9127,7 +10412,7 @@ var AgentChatInner = ({
|
|
|
9127
10412
|
const panelAllowed = appPanel !== false && appPanel !== null;
|
|
9128
10413
|
const panelTarget = typeof appPanel === "object" && appPanel ? appPanel : void 0;
|
|
9129
10414
|
const asSheet = !panelTarget && (appPanel === "sheet" || Boolean(narrow));
|
|
9130
|
-
(0,
|
|
10415
|
+
(0, import_react25.useEffect)(() => {
|
|
9131
10416
|
if (panelApp && !agent.messages.some((m) => m.apps?.some((a) => a.id === panelApp.id))) {
|
|
9132
10417
|
setPanelAppState(void 0);
|
|
9133
10418
|
onAppPanel?.(void 0);
|
|
@@ -9167,7 +10452,7 @@ var AgentChatInner = ({
|
|
|
9167
10452
|
},
|
|
9168
10453
|
panelApp.id
|
|
9169
10454
|
) : null;
|
|
9170
|
-
const [compacting, setCompacting] = (0,
|
|
10455
|
+
const [compacting, setCompacting] = (0, import_react25.useState)(false);
|
|
9171
10456
|
const compact = () => {
|
|
9172
10457
|
setCompacting(true);
|
|
9173
10458
|
void agent.compact().finally(() => setCompacting(false));
|
|
@@ -9325,6 +10610,7 @@ var AgentChatInner = ({
|
|
|
9325
10610
|
renderContent,
|
|
9326
10611
|
renderMessage,
|
|
9327
10612
|
renderAttachment,
|
|
10613
|
+
readAloud,
|
|
9328
10614
|
renderToolCall,
|
|
9329
10615
|
showApps: appsOn,
|
|
9330
10616
|
renderApp: appsOn ? drawApp : void 0,
|
|
@@ -9500,7 +10786,7 @@ var LearnedSkills = ({
|
|
|
9500
10786
|
};
|
|
9501
10787
|
|
|
9502
10788
|
// src/components/Composer.tsx
|
|
9503
|
-
var
|
|
10789
|
+
var import_react26 = require("react");
|
|
9504
10790
|
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
9505
10791
|
var Composer = ({
|
|
9506
10792
|
onSubmit,
|
|
@@ -9510,7 +10796,7 @@ var Composer = ({
|
|
|
9510
10796
|
placeholder = "Ask the agent to do something\u2026",
|
|
9511
10797
|
className
|
|
9512
10798
|
}) => {
|
|
9513
|
-
const [text2, setText] = (0,
|
|
10799
|
+
const [text2, setText] = (0, import_react26.useState)("");
|
|
9514
10800
|
const submit = () => {
|
|
9515
10801
|
const value = text2.trim();
|
|
9516
10802
|
if (!value || busy || disabled) return;
|
|
@@ -9623,7 +10909,7 @@ var ApprovalModeSwitch = ({
|
|
|
9623
10909
|
);
|
|
9624
10910
|
|
|
9625
10911
|
// src/components/ApiKeyForm.tsx
|
|
9626
|
-
var
|
|
10912
|
+
var import_react27 = require("react");
|
|
9627
10913
|
var import_jsx_runtime27 = require("react/jsx-runtime");
|
|
9628
10914
|
var ApiKeyForm = ({
|
|
9629
10915
|
credentials,
|
|
@@ -9633,10 +10919,10 @@ var ApiKeyForm = ({
|
|
|
9633
10919
|
onChange,
|
|
9634
10920
|
className
|
|
9635
10921
|
}) => {
|
|
9636
|
-
const [value, setValue] = (0,
|
|
9637
|
-
const [present, setPresent] = (0,
|
|
9638
|
-
const [busy, setBusy] = (0,
|
|
9639
|
-
(0,
|
|
10922
|
+
const [value, setValue] = (0, import_react27.useState)("");
|
|
10923
|
+
const [present, setPresent] = (0, import_react27.useState)(false);
|
|
10924
|
+
const [busy, setBusy] = (0, import_react27.useState)(false);
|
|
10925
|
+
(0, import_react27.useEffect)(() => {
|
|
9640
10926
|
let active = true;
|
|
9641
10927
|
credentials.hasKey(credentialRef).then((has) => {
|
|
9642
10928
|
if (active) setPresent(has);
|
|
@@ -9727,6 +11013,7 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
9727
11013
|
APP_MAX_HEIGHT,
|
|
9728
11014
|
APP_MIN_HEIGHT,
|
|
9729
11015
|
ASK_USER_TOOL_NAME,
|
|
11016
|
+
ATTACHMENT_BOUNDS,
|
|
9730
11017
|
AgentChat,
|
|
9731
11018
|
AgentComposer,
|
|
9732
11019
|
AgentLabelsProvider,
|
|
@@ -9788,13 +11075,17 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
9788
11075
|
MemorySkillStore,
|
|
9789
11076
|
MemoryStore,
|
|
9790
11077
|
MessageList,
|
|
11078
|
+
MicError,
|
|
9791
11079
|
ModelLoadBar,
|
|
9792
11080
|
PlanView,
|
|
9793
11081
|
QUESTION_TIMEOUT_MS,
|
|
9794
11082
|
QuestionPrompt,
|
|
11083
|
+
RECORDING_DEFAULT_MAX_MS,
|
|
11084
|
+
RECORDING_TYPES,
|
|
9795
11085
|
SandboxedFrame,
|
|
9796
11086
|
SessionBusyError,
|
|
9797
11087
|
SourceView,
|
|
11088
|
+
SpeechOutputError,
|
|
9798
11089
|
StepList,
|
|
9799
11090
|
SubagentRow,
|
|
9800
11091
|
SubagentTree,
|
|
@@ -9821,7 +11112,12 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
9821
11112
|
askUserOutputKept,
|
|
9822
11113
|
askUserWith,
|
|
9823
11114
|
attachmentKindOf,
|
|
11115
|
+
attachmentOverLimit,
|
|
9824
11116
|
attachmentRefusal,
|
|
11117
|
+
attachmentTransformOf,
|
|
11118
|
+
attachmentsText,
|
|
11119
|
+
audioExtensionOf,
|
|
11120
|
+
audioTypeOf,
|
|
9825
11121
|
buildMcpAppDocument,
|
|
9826
11122
|
buildMcpAppSandboxShell,
|
|
9827
11123
|
buildSandboxedDocument,
|
|
@@ -9830,9 +11126,12 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
9830
11126
|
clampFrameHeight,
|
|
9831
11127
|
createAgent,
|
|
9832
11128
|
createApprovalQueue,
|
|
11129
|
+
createAudioSpeaker,
|
|
11130
|
+
createBrowserSpeaker,
|
|
9833
11131
|
createFileTools,
|
|
9834
11132
|
createInitialAgentState,
|
|
9835
11133
|
createQuestionQueue,
|
|
11134
|
+
createRecordingRecognizer,
|
|
9836
11135
|
createRunControl,
|
|
9837
11136
|
createSubagentTool,
|
|
9838
11137
|
createWebLLMEngine,
|
|
@@ -9852,10 +11151,12 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
9852
11151
|
filterCommands,
|
|
9853
11152
|
followsAfterResize,
|
|
9854
11153
|
followsAfterScroll,
|
|
11154
|
+
formatClock,
|
|
9855
11155
|
formatCountdown,
|
|
9856
11156
|
formatElapsed,
|
|
9857
11157
|
grantedAppCsp,
|
|
9858
11158
|
imageExtensionOf,
|
|
11159
|
+
imageSizeOf,
|
|
9859
11160
|
isMcpAppSandboxMessage,
|
|
9860
11161
|
isWebGPUAvailable,
|
|
9861
11162
|
lessonsOf,
|
|
@@ -9873,24 +11174,35 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
9873
11174
|
menuSections,
|
|
9874
11175
|
mergeChatRecord,
|
|
9875
11176
|
mergeLabels,
|
|
11177
|
+
messageOverLimit,
|
|
11178
|
+
micProblemOf,
|
|
11179
|
+
micProblemText,
|
|
9876
11180
|
newChatId,
|
|
9877
11181
|
noticesOf,
|
|
9878
11182
|
onStorageChange,
|
|
9879
11183
|
parseSkillMarkdown,
|
|
9880
11184
|
parseSlash,
|
|
9881
11185
|
pendingApprovalsOf,
|
|
11186
|
+
pickRecordingType,
|
|
9882
11187
|
postStorageChange,
|
|
9883
11188
|
preloadWebLLMModel,
|
|
9884
11189
|
questionChoiceOf,
|
|
9885
11190
|
questionOtherOf,
|
|
9886
11191
|
questionTimeoutOf,
|
|
11192
|
+
recordingSupported,
|
|
9887
11193
|
resolveAppDownload,
|
|
9888
11194
|
sandboxTokens,
|
|
9889
11195
|
sandboxedCsp,
|
|
9890
11196
|
saveAppFile,
|
|
9891
11197
|
saveChat,
|
|
9892
11198
|
serveSubagentWorker,
|
|
11199
|
+
settleAudioDuration,
|
|
11200
|
+
speakableText,
|
|
11201
|
+
speechSynthesisSupported,
|
|
11202
|
+
splitForSpeech,
|
|
11203
|
+
startRecording,
|
|
9893
11204
|
steerIntent,
|
|
11205
|
+
stopTracks,
|
|
9894
11206
|
subagentTree,
|
|
9895
11207
|
supportsImages,
|
|
9896
11208
|
supportsPdf,
|
|
@@ -9900,6 +11212,7 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
9900
11212
|
usageLine,
|
|
9901
11213
|
useAgent,
|
|
9902
11214
|
useAgentContext,
|
|
11215
|
+
useAudioRecorder,
|
|
9903
11216
|
useChatHistory,
|
|
9904
11217
|
useCredentials,
|
|
9905
11218
|
useFollowScroll,
|
|
@@ -9907,9 +11220,14 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
9907
11220
|
useLocalModel,
|
|
9908
11221
|
useMcpAppHost,
|
|
9909
11222
|
useOptionalAgentContext,
|
|
11223
|
+
useReadAloud,
|
|
9910
11224
|
useSpeechToText,
|
|
11225
|
+
useSpeechVoices,
|
|
9911
11226
|
useVirtualFiles,
|
|
9912
11227
|
useWebLLMModel,
|
|
11228
|
+
voiceFor,
|
|
11229
|
+
voiceMessageName,
|
|
11230
|
+
voicesOf,
|
|
9913
11231
|
watchSession,
|
|
9914
11232
|
webSearchOf,
|
|
9915
11233
|
withAttachments,
|