@dudko.dev/agent-web-react 0.0.38 → 0.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -4
- package/dist/{chunk-G5GGIMD4.js → chunk-V4JGQQRB.js} +16 -1
- package/dist/chunk-V4JGQQRB.js.map +1 -0
- package/dist/{elicitation-BgSf-xzh.d.cts → elicitation-IpjGRDD-.d.cts} +11 -0
- package/dist/{elicitation-BgSf-xzh.d.ts → elicitation-IpjGRDD-.d.ts} +11 -0
- package/dist/index.cjs +1604 -285
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +598 -17
- package/dist/index.d.ts +598 -17
- package/dist/index.js +1556 -271
- 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 +183 -3
- package/package.json +2 -2
- package/dist/chunk-G5GGIMD4.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -92,17 +92,22 @@ __export(src_exports, {
|
|
|
92
92
|
McpAppLine: () => McpAppLine,
|
|
93
93
|
McpAppRpcError: () => McpAppRpcError,
|
|
94
94
|
McpAppSandboxLink: () => McpAppSandboxLink,
|
|
95
|
+
MemoryCard: () => MemoryCard,
|
|
95
96
|
MemoryCredentialStore: () => import_agent_web8.MemoryCredentialStore,
|
|
96
97
|
MemorySkillStore: () => import_agent_web8.MemorySkillStore,
|
|
97
98
|
MemoryStore: () => import_agent_web8.MemoryStore,
|
|
98
99
|
MessageList: () => MessageList,
|
|
100
|
+
MicError: () => MicError,
|
|
99
101
|
ModelLoadBar: () => ModelLoadBar,
|
|
100
102
|
PlanView: () => PlanView,
|
|
101
103
|
QUESTION_TIMEOUT_MS: () => QUESTION_TIMEOUT_MS,
|
|
102
104
|
QuestionPrompt: () => QuestionPrompt,
|
|
105
|
+
RECORDING_DEFAULT_MAX_MS: () => RECORDING_DEFAULT_MAX_MS,
|
|
106
|
+
RECORDING_TYPES: () => RECORDING_TYPES,
|
|
103
107
|
SandboxedFrame: () => SandboxedFrame,
|
|
104
108
|
SessionBusyError: () => import_agent_web8.SessionBusyError,
|
|
105
109
|
SourceView: () => SourceView,
|
|
110
|
+
SpeechOutputError: () => SpeechOutputError,
|
|
106
111
|
StepList: () => StepList,
|
|
107
112
|
SubagentRow: () => SubagentRow,
|
|
108
113
|
SubagentTree: () => SubagentTree,
|
|
@@ -132,6 +137,9 @@ __export(src_exports, {
|
|
|
132
137
|
attachmentOverLimit: () => attachmentOverLimit,
|
|
133
138
|
attachmentRefusal: () => attachmentRefusal,
|
|
134
139
|
attachmentTransformOf: () => attachmentTransformOf,
|
|
140
|
+
attachmentsText: () => attachmentsText,
|
|
141
|
+
audioExtensionOf: () => audioExtensionOf,
|
|
142
|
+
audioTypeOf: () => audioTypeOf,
|
|
135
143
|
buildMcpAppDocument: () => buildMcpAppDocument,
|
|
136
144
|
buildMcpAppSandboxShell: () => buildMcpAppSandboxShell,
|
|
137
145
|
buildSandboxedDocument: () => buildSandboxedDocument,
|
|
@@ -140,9 +148,12 @@ __export(src_exports, {
|
|
|
140
148
|
clampFrameHeight: () => clampFrameHeight,
|
|
141
149
|
createAgent: () => import_agent_web8.createAgent,
|
|
142
150
|
createApprovalQueue: () => createApprovalQueue,
|
|
151
|
+
createAudioSpeaker: () => createAudioSpeaker,
|
|
152
|
+
createBrowserSpeaker: () => createBrowserSpeaker,
|
|
143
153
|
createFileTools: () => import_agent_web8.createFileTools,
|
|
144
154
|
createInitialAgentState: () => createInitialAgentState,
|
|
145
155
|
createQuestionQueue: () => createQuestionQueue,
|
|
156
|
+
createRecordingRecognizer: () => createRecordingRecognizer,
|
|
146
157
|
createRunControl: () => import_agent_web8.createRunControl,
|
|
147
158
|
createSubagentTool: () => import_agent_web8.createSubagentTool,
|
|
148
159
|
createWebLLMEngine: () => createWebLLMEngine,
|
|
@@ -162,6 +173,7 @@ __export(src_exports, {
|
|
|
162
173
|
filterCommands: () => filterCommands,
|
|
163
174
|
followsAfterResize: () => followsAfterResize,
|
|
164
175
|
followsAfterScroll: () => followsAfterScroll,
|
|
176
|
+
formatClock: () => formatClock,
|
|
165
177
|
formatCountdown: () => formatCountdown,
|
|
166
178
|
formatElapsed: () => formatElapsed,
|
|
167
179
|
grantedAppCsp: () => grantedAppCsp,
|
|
@@ -169,6 +181,7 @@ __export(src_exports, {
|
|
|
169
181
|
imageSizeOf: () => imageSizeOf,
|
|
170
182
|
isMcpAppSandboxMessage: () => isMcpAppSandboxMessage,
|
|
171
183
|
isWebGPUAvailable: () => import_agent_web8.isWebGPUAvailable,
|
|
184
|
+
languageOfText: () => languageOfText,
|
|
172
185
|
lessonsOf: () => lessonsOf,
|
|
173
186
|
linkedFilesOf: () => linkedFilesOf,
|
|
174
187
|
loadSkillFromUrl: () => import_agent_web8.loadSkillFromUrl,
|
|
@@ -185,24 +198,36 @@ __export(src_exports, {
|
|
|
185
198
|
mergeChatRecord: () => mergeChatRecord,
|
|
186
199
|
mergeLabels: () => mergeLabels,
|
|
187
200
|
messageOverLimit: () => messageOverLimit,
|
|
201
|
+
micProblemOf: () => micProblemOf,
|
|
202
|
+
micProblemText: () => micProblemText,
|
|
188
203
|
newChatId: () => newChatId,
|
|
189
204
|
noticesOf: () => noticesOf,
|
|
190
205
|
onStorageChange: () => import_agent_web8.onStorageChange,
|
|
191
206
|
parseSkillMarkdown: () => import_agent_web8.parseSkillMarkdown,
|
|
192
207
|
parseSlash: () => parseSlash,
|
|
193
208
|
pendingApprovalsOf: () => pendingApprovalsOf,
|
|
209
|
+
pickRecordingType: () => pickRecordingType,
|
|
194
210
|
postStorageChange: () => import_agent_web8.postStorageChange,
|
|
195
211
|
preloadWebLLMModel: () => import_agent_web8.preloadWebLLMModel,
|
|
196
212
|
questionChoiceOf: () => questionChoiceOf,
|
|
197
213
|
questionOtherOf: () => questionOtherOf,
|
|
198
214
|
questionTimeoutOf: () => questionTimeoutOf,
|
|
215
|
+
recordingSupported: () => recordingSupported,
|
|
199
216
|
resolveAppDownload: () => resolveAppDownload,
|
|
200
217
|
sandboxTokens: () => sandboxTokens,
|
|
201
218
|
sandboxedCsp: () => sandboxedCsp,
|
|
202
219
|
saveAppFile: () => saveAppFile,
|
|
203
220
|
saveChat: () => saveChat,
|
|
221
|
+
scriptOfLanguage: () => scriptOfLanguage,
|
|
222
|
+
scriptOfText: () => scriptOfText,
|
|
204
223
|
serveSubagentWorker: () => import_agent_web8.serveSubagentWorker,
|
|
224
|
+
settleAudioDuration: () => settleAudioDuration,
|
|
225
|
+
speakableText: () => speakableText,
|
|
226
|
+
speechSynthesisSupported: () => speechSynthesisSupported,
|
|
227
|
+
splitForSpeech: () => splitForSpeech,
|
|
228
|
+
startRecording: () => startRecording,
|
|
205
229
|
steerIntent: () => steerIntent,
|
|
230
|
+
stopTracks: () => stopTracks,
|
|
206
231
|
subagentTree: () => subagentTree,
|
|
207
232
|
supportsImages: () => import_agent_web8.supportsImages,
|
|
208
233
|
supportsPdf: () => import_agent_web8.supportsPdf,
|
|
@@ -212,6 +237,7 @@ __export(src_exports, {
|
|
|
212
237
|
usageLine: () => usageLine,
|
|
213
238
|
useAgent: () => useAgent,
|
|
214
239
|
useAgentContext: () => useAgentContext,
|
|
240
|
+
useAudioRecorder: () => useAudioRecorder,
|
|
215
241
|
useChatHistory: () => useChatHistory,
|
|
216
242
|
useCredentials: () => useCredentials,
|
|
217
243
|
useFollowScroll: () => useFollowScroll,
|
|
@@ -219,9 +245,14 @@ __export(src_exports, {
|
|
|
219
245
|
useLocalModel: () => useLocalModel,
|
|
220
246
|
useMcpAppHost: () => useMcpAppHost,
|
|
221
247
|
useOptionalAgentContext: () => useOptionalAgentContext,
|
|
248
|
+
useReadAloud: () => useReadAloud,
|
|
222
249
|
useSpeechToText: () => useSpeechToText,
|
|
250
|
+
useSpeechVoices: () => useSpeechVoices,
|
|
223
251
|
useVirtualFiles: () => useVirtualFiles,
|
|
224
252
|
useWebLLMModel: () => useWebLLMModel,
|
|
253
|
+
voiceFor: () => voiceFor,
|
|
254
|
+
voiceMessageName: () => voiceMessageName,
|
|
255
|
+
voicesOf: () => voicesOf,
|
|
225
256
|
watchSession: () => import_agent_web8.watchSession,
|
|
226
257
|
webSearchOf: () => webSearchOf,
|
|
227
258
|
withAttachments: () => withAttachments,
|
|
@@ -485,8 +516,15 @@ var resetRun = (state) => ({
|
|
|
485
516
|
seq: state.seq,
|
|
486
517
|
learned: state.learned,
|
|
487
518
|
// An MCP App's request is the user's, not the run's: it waits across runs.
|
|
488
|
-
approvals: state.approvals.filter((a) => a.app && a.status === "pending")
|
|
519
|
+
approvals: state.approvals.filter((a) => a.app && a.status === "pending"),
|
|
520
|
+
// So is what this tab sent to another tab's run, until that tab answers (a replay that opens
|
|
521
|
+
// with the run's start is not an answer).
|
|
522
|
+
queued: sentToOtherTab(state.queued)
|
|
489
523
|
});
|
|
524
|
+
var sentToOtherTab = (queued) => queued.filter((q) => q.sentTo === "another-tab");
|
|
525
|
+
var sentEntryOf = (queued, text2) => queued.findIndex(
|
|
526
|
+
(q) => q.sentTo === "another-tab" && (q.text === text2 || text2.endsWith("\u2026") && q.text.length > text2.length && q.text.startsWith(text2.slice(0, -1)))
|
|
527
|
+
);
|
|
490
528
|
var patchStep = (steps, id, fn) => steps.map((s) => s.id === id ? fn(s) : s);
|
|
491
529
|
var withoutSkillBody = (a) => {
|
|
492
530
|
if (!a.skill || a.skill.body === void 0) return a;
|
|
@@ -1235,14 +1273,17 @@ var applyEvent = (state, event, ctx) => {
|
|
|
1235
1273
|
return fileDeleted(state, event.path);
|
|
1236
1274
|
case "mcp.app":
|
|
1237
1275
|
return ctx.remote ? state : addApp(state, event);
|
|
1238
|
-
case "message.queued":
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
]
|
|
1276
|
+
case "message.queued": {
|
|
1277
|
+
if (state.queued.some((q) => q.id === event.id)) return state;
|
|
1278
|
+
const entry = {
|
|
1279
|
+
id: event.id,
|
|
1280
|
+
text: event.text,
|
|
1281
|
+
...event.origin ? { origin: event.origin } : {}
|
|
1245
1282
|
};
|
|
1283
|
+
const mine = ctx.remote && event.origin === "another-tab" ? sentEntryOf(state.queued, event.text) : -1;
|
|
1284
|
+
if (mine < 0) return { ...state, queued: [...state.queued, entry] };
|
|
1285
|
+
return { ...state, queued: state.queued.map((q, i) => i === mine ? entry : q) };
|
|
1286
|
+
}
|
|
1246
1287
|
case "message.delivered": {
|
|
1247
1288
|
const anchor = event.at === "round" ? runningStepId(state.steps) : event.at === "step" ? state.steps[state.steps.length - 1]?.id : void 0;
|
|
1248
1289
|
return {
|
|
@@ -1570,9 +1611,21 @@ var agentStateReducer = (state, action) => {
|
|
|
1570
1611
|
case "undelivered":
|
|
1571
1612
|
return {
|
|
1572
1613
|
...state,
|
|
1573
|
-
queued: action.keepQueued ? state.queued :
|
|
1614
|
+
queued: action.keepQueued ? state.queued : sentToOtherTab(state.queued),
|
|
1574
1615
|
undelivered: action.texts
|
|
1575
1616
|
};
|
|
1617
|
+
case "remote-send":
|
|
1618
|
+
return state.queued.some((q) => q.id === action.id) ? state : {
|
|
1619
|
+
...state,
|
|
1620
|
+
queued: [
|
|
1621
|
+
...state.queued,
|
|
1622
|
+
{ id: action.id, text: action.text, sentTo: "another-tab" }
|
|
1623
|
+
]
|
|
1624
|
+
};
|
|
1625
|
+
case "remote-answer": {
|
|
1626
|
+
const queued = state.queued.filter((q) => q.id !== action.id);
|
|
1627
|
+
return action.answer === "refused" ? { ...state, queued, undelivered: [...state.undelivered, action.text] } : { ...state, queued };
|
|
1628
|
+
}
|
|
1576
1629
|
case "load": {
|
|
1577
1630
|
const maxSeq = action.messages.reduce((n, m) => {
|
|
1578
1631
|
const k = Number(/^msg-(\d+)$/.exec(m.id)?.[1] ?? -1);
|
|
@@ -1621,6 +1674,7 @@ var followOtherTabs = (core6, dbName, accept, settle, ms = 100) => {
|
|
|
1621
1674
|
later.cancel();
|
|
1622
1675
|
};
|
|
1623
1676
|
};
|
|
1677
|
+
var remoteAnswerOf = (ok, stillWatching) => ok ? "taken" : stillWatching ? "refused" : "unknown";
|
|
1624
1678
|
|
|
1625
1679
|
// src/hooks/use-agent.ts
|
|
1626
1680
|
var dbNameOf = (store) => {
|
|
@@ -1782,7 +1836,8 @@ var useAgent = (config, options = {}) => {
|
|
|
1782
1836
|
let began = false;
|
|
1783
1837
|
const shownGoal = runOptions?.label ?? goal;
|
|
1784
1838
|
dispatch({ type: "status", status: "running" });
|
|
1785
|
-
|
|
1839
|
+
const shownAtAll = Boolean(shownGoal.trim() || runOptions?.attachments?.length);
|
|
1840
|
+
if (shownAtAll) {
|
|
1786
1841
|
dispatch({
|
|
1787
1842
|
type: "submitted",
|
|
1788
1843
|
goal: shownGoal,
|
|
@@ -1802,14 +1857,16 @@ var useAgent = (config, options = {}) => {
|
|
|
1802
1857
|
startedRef.current = true;
|
|
1803
1858
|
began = true;
|
|
1804
1859
|
}
|
|
1805
|
-
const shown = start && runOptions?.label ? { ...event, goal: runOptions.label } : event;
|
|
1860
|
+
const shown = start && runOptions?.label !== void 0 ? { ...event, goal: runOptions.label } : event;
|
|
1806
1861
|
dispatch({
|
|
1807
1862
|
type: "event",
|
|
1808
1863
|
event: shown,
|
|
1809
1864
|
maxEvents: optionsRef.current.maxEvents,
|
|
1810
1865
|
at: Date.now(),
|
|
1811
1866
|
// What the user sent waits with the run: shown as queued meanwhile.
|
|
1812
|
-
...event.type === "session.busy" &&
|
|
1867
|
+
...event.type === "session.busy" && shownAtAll ? {
|
|
1868
|
+
goal: shownGoal.trim() || (runOptions?.attachments ?? []).map((a) => a.name).join(", ")
|
|
1869
|
+
} : {},
|
|
1813
1870
|
...start && runOptions?.attachments?.length ? { attachments: runOptions.attachments } : {}
|
|
1814
1871
|
});
|
|
1815
1872
|
try {
|
|
@@ -1853,18 +1910,16 @@ var useAgent = (config, options = {}) => {
|
|
|
1853
1910
|
);
|
|
1854
1911
|
runRef.current = run;
|
|
1855
1912
|
const send = (0, import_react.useCallback)((text2) => controlRef.current?.send(text2) ?? false, []);
|
|
1913
|
+
const remoteSendsRef = (0, import_react.useRef)(0);
|
|
1856
1914
|
const sendRemote = (0, import_react.useCallback)((text2) => {
|
|
1857
1915
|
const watch = watchRef.current;
|
|
1858
1916
|
const clean = typeof text2 === "string" ? text2.trim() : "";
|
|
1859
1917
|
if (!watch?.state.running || !clean) return false;
|
|
1918
|
+
const id = `to-other-tab-${remoteSendsRef.current += 1}`;
|
|
1919
|
+
dispatch({ type: "remote-send", id, text: clean });
|
|
1860
1920
|
void watch.send(clean).then((ok) => {
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
type: "undelivered",
|
|
1864
|
-
texts: [...stateRef.current.undelivered, clean],
|
|
1865
|
-
keepQueued: true
|
|
1866
|
-
});
|
|
1867
|
-
}
|
|
1921
|
+
const answer = remoteAnswerOf(ok, watchRef.current === watch);
|
|
1922
|
+
dispatch({ type: "remote-answer", id, text: clean, answer });
|
|
1868
1923
|
});
|
|
1869
1924
|
return true;
|
|
1870
1925
|
}, []);
|
|
@@ -2176,8 +2231,17 @@ var ChatHistoryStore = class {
|
|
|
2176
2231
|
await this.write((store) => store.clear(), { op: "clear" });
|
|
2177
2232
|
}
|
|
2178
2233
|
};
|
|
2179
|
-
var
|
|
2180
|
-
|
|
2234
|
+
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(", ");
|
|
2235
|
+
var oneLine = (text2) => (text2 ?? "").replace(/\s+/g, " ").trim();
|
|
2236
|
+
var chatTitle = (messages, texts = {}) => {
|
|
2237
|
+
const at = messages.findIndex((m) => m.role === "user");
|
|
2238
|
+
const user = at >= 0 ? messages[at] : void 0;
|
|
2239
|
+
let first = oneLine(user?.content);
|
|
2240
|
+
if (!first && user?.attachments?.length) {
|
|
2241
|
+
const answer = messages.slice(at + 1).find((m) => m.role === "assistant");
|
|
2242
|
+
const heard = answer?.transcripts?.find((t) => t.source === "attachment")?.text;
|
|
2243
|
+
first = oneLine(heard) || oneLine(attachmentsText(user.attachments, texts));
|
|
2244
|
+
}
|
|
2181
2245
|
if (!first) return "New chat";
|
|
2182
2246
|
return first.length > 60 ? `${first.slice(0, 59)}\u2026` : first;
|
|
2183
2247
|
};
|
|
@@ -2209,7 +2273,7 @@ var renumber = (own, after) => {
|
|
|
2209
2273
|
return own.map((m) => ({ ...m, id: `msg-${next += 1}` }));
|
|
2210
2274
|
};
|
|
2211
2275
|
var unchangedSince = (messages, base2) => base2 !== void 0 && messages.length === base2.known.size && messages.every((m) => base2.known.has(m));
|
|
2212
|
-
var mergeChatRecord = (view, stored, base2) => {
|
|
2276
|
+
var mergeChatRecord = (view, stored, base2, texts) => {
|
|
2213
2277
|
const local = view.messages.filter((m) => !m.remote);
|
|
2214
2278
|
if (!stored || base2 && stored.updatedAt <= base2.updatedAt) {
|
|
2215
2279
|
return { record: { ...view, messages: local }, merged: false };
|
|
@@ -2220,7 +2284,7 @@ var mergeChatRecord = (view, stored, base2) => {
|
|
|
2220
2284
|
record: {
|
|
2221
2285
|
...view,
|
|
2222
2286
|
createdAt: stored.createdAt,
|
|
2223
|
-
title: chatTitle(messages),
|
|
2287
|
+
title: chatTitle(messages, texts),
|
|
2224
2288
|
messages,
|
|
2225
2289
|
totalUsage: sumUsage(
|
|
2226
2290
|
stored.totalUsage,
|
|
@@ -2230,10 +2294,10 @@ var mergeChatRecord = (view, stored, base2) => {
|
|
|
2230
2294
|
merged: true
|
|
2231
2295
|
};
|
|
2232
2296
|
};
|
|
2233
|
-
var saveChat = async (store, view, base2) => {
|
|
2297
|
+
var saveChat = async (store, view, base2, texts) => {
|
|
2234
2298
|
let merged = false;
|
|
2235
2299
|
const record = await store.putMerged(view.id, (stored) => {
|
|
2236
|
-
const out = mergeChatRecord(view, stored, base2);
|
|
2300
|
+
const out = mergeChatRecord(view, stored, base2, texts);
|
|
2237
2301
|
merged = out.merged;
|
|
2238
2302
|
return out.record;
|
|
2239
2303
|
});
|
|
@@ -2241,6 +2305,8 @@ var saveChat = async (store, view, base2) => {
|
|
|
2241
2305
|
};
|
|
2242
2306
|
var useChatHistory = (agent, options = {}) => {
|
|
2243
2307
|
const enabled = options.enabled !== false;
|
|
2308
|
+
const textsRef = (0, import_react2.useRef)(options.labels);
|
|
2309
|
+
textsRef.current = options.labels;
|
|
2244
2310
|
const store = (0, import_react2.useMemo)(() => options.store ?? new ChatHistoryStore(), [options.store]);
|
|
2245
2311
|
const [chats, setChats] = (0, import_react2.useState)([]);
|
|
2246
2312
|
const [loading, setLoading] = (0, import_react2.useState)(enabled);
|
|
@@ -2334,14 +2400,14 @@ var useChatHistory = (agent, options = {}) => {
|
|
|
2334
2400
|
createdRef.current.set(sessionId, createdAt);
|
|
2335
2401
|
const view = {
|
|
2336
2402
|
id: sessionId,
|
|
2337
|
-
title: chatTitle(messages),
|
|
2403
|
+
title: chatTitle(messages, textsRef.current),
|
|
2338
2404
|
createdAt,
|
|
2339
2405
|
updatedAt: now,
|
|
2340
2406
|
messages,
|
|
2341
2407
|
totalUsage
|
|
2342
2408
|
};
|
|
2343
2409
|
void (async () => {
|
|
2344
|
-
const { record, merged } = await saveChat(store, view, base2);
|
|
2410
|
+
const { record, merged } = await saveChat(store, view, base2, textsRef.current);
|
|
2345
2411
|
baseRef.current = {
|
|
2346
2412
|
id: sessionId,
|
|
2347
2413
|
known: new Set(merged ? record.messages : messages),
|
|
@@ -2435,13 +2501,18 @@ var browserRecognizer = () => {
|
|
|
2435
2501
|
var useSpeechToText = (options = {}) => {
|
|
2436
2502
|
const optionsRef = (0, import_react4.useRef)(options);
|
|
2437
2503
|
optionsRef.current = options;
|
|
2438
|
-
const
|
|
2504
|
+
const own = options.createRecognizer;
|
|
2505
|
+
const factory = (0, import_react4.useMemo)(() => own ?? browserRecognizer(), [own]);
|
|
2439
2506
|
const [listening, setListening] = (0, import_react4.useState)(false);
|
|
2440
2507
|
const [interim, setInterim] = (0, import_react4.useState)("");
|
|
2441
2508
|
const [error, setError] = (0, import_react4.useState)();
|
|
2509
|
+
const [errorMessage, setErrorMessage] = (0, import_react4.useState)();
|
|
2510
|
+
const [finishing, setFinishing] = (0, import_react4.useState)(false);
|
|
2442
2511
|
const recRef = (0, import_react4.useRef)(void 0);
|
|
2443
2512
|
const stop = (0, import_react4.useCallback)(() => {
|
|
2444
|
-
recRef.current
|
|
2513
|
+
if (!recRef.current) return;
|
|
2514
|
+
setFinishing(true);
|
|
2515
|
+
recRef.current.stop();
|
|
2445
2516
|
}, []);
|
|
2446
2517
|
const start = (0, import_react4.useCallback)(() => {
|
|
2447
2518
|
if (!factory || recRef.current) return;
|
|
@@ -2459,15 +2530,22 @@ var useSpeechToText = (options = {}) => {
|
|
|
2459
2530
|
setInterim(pending);
|
|
2460
2531
|
};
|
|
2461
2532
|
rec.onerror = (ev) => {
|
|
2462
|
-
if (ev.error && ev.error !== "no-speech" && ev.error !== "aborted")
|
|
2533
|
+
if (ev.error && ev.error !== "no-speech" && ev.error !== "aborted") {
|
|
2534
|
+
setError(ev.error);
|
|
2535
|
+
setErrorMessage(ev.message);
|
|
2536
|
+
}
|
|
2463
2537
|
};
|
|
2464
2538
|
rec.onend = () => {
|
|
2539
|
+
if (recRef.current !== rec) return;
|
|
2465
2540
|
recRef.current = void 0;
|
|
2466
2541
|
setListening(false);
|
|
2542
|
+
setFinishing(false);
|
|
2467
2543
|
setInterim("");
|
|
2468
2544
|
};
|
|
2469
2545
|
recRef.current = rec;
|
|
2470
2546
|
setError(void 0);
|
|
2547
|
+
setErrorMessage(void 0);
|
|
2548
|
+
setFinishing(false);
|
|
2471
2549
|
try {
|
|
2472
2550
|
rec.start();
|
|
2473
2551
|
setListening(true);
|
|
@@ -2476,20 +2554,855 @@ var useSpeechToText = (options = {}) => {
|
|
|
2476
2554
|
setError(err instanceof Error ? err.message : String(err));
|
|
2477
2555
|
}
|
|
2478
2556
|
}, [factory]);
|
|
2479
|
-
(0, import_react4.useEffect)(
|
|
2557
|
+
(0, import_react4.useEffect)(
|
|
2558
|
+
() => () => {
|
|
2559
|
+
const rec = recRef.current;
|
|
2560
|
+
recRef.current = void 0;
|
|
2561
|
+
rec?.abort?.();
|
|
2562
|
+
},
|
|
2563
|
+
[factory]
|
|
2564
|
+
);
|
|
2480
2565
|
return {
|
|
2481
2566
|
supported: Boolean(factory),
|
|
2482
2567
|
listening,
|
|
2568
|
+
finishing,
|
|
2483
2569
|
interim,
|
|
2484
2570
|
error,
|
|
2571
|
+
errorMessage,
|
|
2485
2572
|
start,
|
|
2486
2573
|
stop,
|
|
2487
2574
|
toggle: () => recRef.current ? stop() : start()
|
|
2488
2575
|
};
|
|
2489
2576
|
};
|
|
2490
2577
|
|
|
2491
|
-
// src/hooks/use-
|
|
2578
|
+
// src/hooks/use-audio-recorder.ts
|
|
2492
2579
|
var import_react5 = require("react");
|
|
2580
|
+
|
|
2581
|
+
// src/voice/record.ts
|
|
2582
|
+
var MicError = class extends Error {
|
|
2583
|
+
code;
|
|
2584
|
+
constructor(code, message = code) {
|
|
2585
|
+
super(message);
|
|
2586
|
+
this.name = "MicError";
|
|
2587
|
+
this.code = code;
|
|
2588
|
+
}
|
|
2589
|
+
};
|
|
2590
|
+
var RECORDING_DEFAULT_MAX_MS = 5 * 60 * 1e3;
|
|
2591
|
+
var RECORDING_TYPES = [
|
|
2592
|
+
"audio/webm;codecs=opus",
|
|
2593
|
+
"audio/webm",
|
|
2594
|
+
"audio/mp4",
|
|
2595
|
+
"audio/ogg;codecs=opus",
|
|
2596
|
+
"audio/ogg"
|
|
2597
|
+
];
|
|
2598
|
+
var pickRecordingType = (isTypeSupported) => {
|
|
2599
|
+
if (!isTypeSupported) return void 0;
|
|
2600
|
+
for (const type of RECORDING_TYPES) {
|
|
2601
|
+
try {
|
|
2602
|
+
if (isTypeSupported(type)) return type;
|
|
2603
|
+
} catch {
|
|
2604
|
+
}
|
|
2605
|
+
}
|
|
2606
|
+
return void 0;
|
|
2607
|
+
};
|
|
2608
|
+
var audioTypeOf = (type) => {
|
|
2609
|
+
const base2 = (type ?? "").toLowerCase().split(";")[0].trim();
|
|
2610
|
+
if (/^(audio|video)\/(mp4|x-m4a|m4a|aac-mp4)$/.test(base2)) return "audio/mp4";
|
|
2611
|
+
if (/^(audio|video)\/webm$/.test(base2)) return "audio/webm";
|
|
2612
|
+
if (base2 === "audio/ogg" || base2 === "application/ogg") return "audio/ogg";
|
|
2613
|
+
if (base2 === "audio/wav" || base2 === "audio/x-wav" || base2 === "audio/wave") return "audio/wav";
|
|
2614
|
+
if (base2 === "audio/mpeg" || base2 === "audio/mp3") return "audio/mpeg";
|
|
2615
|
+
if (base2 === "audio/aac") return "audio/aac";
|
|
2616
|
+
return "audio/webm";
|
|
2617
|
+
};
|
|
2618
|
+
var audioExtensionOf = (type) => ({
|
|
2619
|
+
"audio/mp4": "m4a",
|
|
2620
|
+
"audio/ogg": "ogg",
|
|
2621
|
+
"audio/wav": "wav",
|
|
2622
|
+
"audio/mpeg": "mp3",
|
|
2623
|
+
"audio/aac": "aac"
|
|
2624
|
+
})[audioTypeOf(type)] ?? "webm";
|
|
2625
|
+
var micProblemOf = (err) => {
|
|
2626
|
+
if (err instanceof MicError) return err.code;
|
|
2627
|
+
const name = err && typeof err === "object" ? String(err.name) : "";
|
|
2628
|
+
if (name === "NotAllowedError" || name === "SecurityError" || name === "PermissionDeniedError")
|
|
2629
|
+
return "not-allowed";
|
|
2630
|
+
if (name === "NotFoundError" || name === "OverconstrainedError" || name === "DevicesNotFoundError")
|
|
2631
|
+
return "audio-capture";
|
|
2632
|
+
if (name === "NotReadableError" || name === "TrackStartError" || name === "AbortError")
|
|
2633
|
+
return "busy";
|
|
2634
|
+
if (name === "NotSupportedError" || name === "TypeError") return "unsupported";
|
|
2635
|
+
return "failed";
|
|
2636
|
+
};
|
|
2637
|
+
var defaults = (deps) => {
|
|
2638
|
+
const g = globalThis;
|
|
2639
|
+
const devices = g.navigator?.mediaDevices;
|
|
2640
|
+
return {
|
|
2641
|
+
getUserMedia: deps.getUserMedia ?? (devices?.getUserMedia ? devices.getUserMedia.bind(devices) : void 0),
|
|
2642
|
+
MediaRecorder: deps.MediaRecorder ?? g.MediaRecorder,
|
|
2643
|
+
now: deps.now ?? Date.now
|
|
2644
|
+
};
|
|
2645
|
+
};
|
|
2646
|
+
var recordingSupported = (deps = {}) => {
|
|
2647
|
+
const d = defaults(deps);
|
|
2648
|
+
return Boolean(d.getUserMedia && d.MediaRecorder);
|
|
2649
|
+
};
|
|
2650
|
+
var stopTracks = (stream) => {
|
|
2651
|
+
for (const track of stream?.getTracks() ?? []) {
|
|
2652
|
+
try {
|
|
2653
|
+
track.stop();
|
|
2654
|
+
} catch {
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2657
|
+
};
|
|
2658
|
+
var startRecording = async (options = {}) => {
|
|
2659
|
+
const d = defaults(options);
|
|
2660
|
+
if (!d.getUserMedia || !d.MediaRecorder) throw new MicError("unsupported");
|
|
2661
|
+
let stream;
|
|
2662
|
+
try {
|
|
2663
|
+
stream = await d.getUserMedia({ audio: true });
|
|
2664
|
+
} catch (err) {
|
|
2665
|
+
throw new MicError(micProblemOf(err));
|
|
2666
|
+
}
|
|
2667
|
+
let recorder;
|
|
2668
|
+
try {
|
|
2669
|
+
const type = pickRecordingType(d.MediaRecorder.isTypeSupported?.bind(d.MediaRecorder));
|
|
2670
|
+
recorder = new d.MediaRecorder(stream, type ? { mimeType: type } : void 0);
|
|
2671
|
+
} catch (err) {
|
|
2672
|
+
stopTracks(stream);
|
|
2673
|
+
throw new MicError(micProblemOf(err) === "failed" ? "unsupported" : micProblemOf(err));
|
|
2674
|
+
}
|
|
2675
|
+
const startedAt = d.now();
|
|
2676
|
+
const chunks = [];
|
|
2677
|
+
let cancelled = false;
|
|
2678
|
+
let failure;
|
|
2679
|
+
let settle = () => {
|
|
2680
|
+
};
|
|
2681
|
+
const ended = new Promise((resolve) => settle = resolve);
|
|
2682
|
+
let finish;
|
|
2683
|
+
let fail;
|
|
2684
|
+
const result = new Promise((resolve, reject) => {
|
|
2685
|
+
finish = resolve;
|
|
2686
|
+
fail = reject;
|
|
2687
|
+
});
|
|
2688
|
+
result.catch(() => {
|
|
2689
|
+
});
|
|
2690
|
+
let limit;
|
|
2691
|
+
const end = () => {
|
|
2692
|
+
stopTracks(stream);
|
|
2693
|
+
clearTimeout(limit);
|
|
2694
|
+
settle();
|
|
2695
|
+
};
|
|
2696
|
+
recorder.ondataavailable = (event) => {
|
|
2697
|
+
if (event.data && event.data.size > 0) chunks.push(event.data);
|
|
2698
|
+
};
|
|
2699
|
+
recorder.onerror = () => {
|
|
2700
|
+
failure = new MicError("failed");
|
|
2701
|
+
end();
|
|
2702
|
+
fail?.(failure);
|
|
2703
|
+
};
|
|
2704
|
+
recorder.onstop = () => {
|
|
2705
|
+
end();
|
|
2706
|
+
if (cancelled) return fail?.(new MicError("failed", "cancelled"));
|
|
2707
|
+
if (failure) return fail?.(failure);
|
|
2708
|
+
const mediaType = audioTypeOf(recorder.mimeType || chunks[0]?.type);
|
|
2709
|
+
finish?.({
|
|
2710
|
+
blob: new Blob(chunks, { type: mediaType }),
|
|
2711
|
+
mediaType,
|
|
2712
|
+
durationMs: Math.max(0, d.now() - startedAt)
|
|
2713
|
+
});
|
|
2714
|
+
};
|
|
2715
|
+
const stopRecorder = () => {
|
|
2716
|
+
try {
|
|
2717
|
+
if (recorder.state !== "inactive") recorder.stop();
|
|
2718
|
+
else recorder.onstop?.();
|
|
2719
|
+
} catch {
|
|
2720
|
+
recorder.onstop?.();
|
|
2721
|
+
}
|
|
2722
|
+
};
|
|
2723
|
+
const maxMs = options.maxMs ?? RECORDING_DEFAULT_MAX_MS;
|
|
2724
|
+
limit = setTimeout(() => {
|
|
2725
|
+
stopRecorder();
|
|
2726
|
+
options.onLimit?.();
|
|
2727
|
+
}, maxMs);
|
|
2728
|
+
try {
|
|
2729
|
+
recorder.start(1e3);
|
|
2730
|
+
} catch (err) {
|
|
2731
|
+
end();
|
|
2732
|
+
throw new MicError(micProblemOf(err) === "failed" ? "unsupported" : micProblemOf(err));
|
|
2733
|
+
}
|
|
2734
|
+
return {
|
|
2735
|
+
startedAt,
|
|
2736
|
+
ended,
|
|
2737
|
+
stop: () => {
|
|
2738
|
+
stopRecorder();
|
|
2739
|
+
return result;
|
|
2740
|
+
},
|
|
2741
|
+
cancel: () => {
|
|
2742
|
+
cancelled = true;
|
|
2743
|
+
chunks.length = 0;
|
|
2744
|
+
stopRecorder();
|
|
2745
|
+
end();
|
|
2746
|
+
}
|
|
2747
|
+
};
|
|
2748
|
+
};
|
|
2749
|
+
|
|
2750
|
+
// src/hooks/use-audio-recorder.ts
|
|
2751
|
+
var useAudioRecorder = (options = {}) => {
|
|
2752
|
+
const opts = (0, import_react5.useRef)(options);
|
|
2753
|
+
opts.current = options;
|
|
2754
|
+
const [state, setState] = (0, import_react5.useState)("idle");
|
|
2755
|
+
const [elapsedMs, setElapsed] = (0, import_react5.useState)(0);
|
|
2756
|
+
const [error, setError] = (0, import_react5.useState)();
|
|
2757
|
+
const [limited, setLimited] = (0, import_react5.useState)();
|
|
2758
|
+
const rec = (0, import_react5.useRef)(void 0);
|
|
2759
|
+
const pending = (0, import_react5.useRef)(false);
|
|
2760
|
+
const gone = (0, import_react5.useRef)(false);
|
|
2761
|
+
(0, import_react5.useEffect)(() => {
|
|
2762
|
+
if (state !== "recording") return;
|
|
2763
|
+
const at = rec.current?.startedAt ?? Date.now();
|
|
2764
|
+
const now = opts.current.now ?? Date.now;
|
|
2765
|
+
setElapsed(Math.max(0, now() - at));
|
|
2766
|
+
const id = setInterval(() => setElapsed(Math.max(0, now() - at)), 250);
|
|
2767
|
+
return () => clearInterval(id);
|
|
2768
|
+
}, [state]);
|
|
2769
|
+
const start = (0, import_react5.useCallback)(async () => {
|
|
2770
|
+
if (rec.current || pending.current) return;
|
|
2771
|
+
pending.current = true;
|
|
2772
|
+
setError(void 0);
|
|
2773
|
+
setLimited(void 0);
|
|
2774
|
+
setState("starting");
|
|
2775
|
+
try {
|
|
2776
|
+
const started = await startRecording({
|
|
2777
|
+
...opts.current,
|
|
2778
|
+
onLimit: () => {
|
|
2779
|
+
const r = rec.current;
|
|
2780
|
+
rec.current = void 0;
|
|
2781
|
+
setState("stopping");
|
|
2782
|
+
void r?.stop().then(
|
|
2783
|
+
(audio) => !gone.current && setLimited(audio),
|
|
2784
|
+
() => void 0
|
|
2785
|
+
).finally(() => !gone.current && setState("idle"));
|
|
2786
|
+
}
|
|
2787
|
+
});
|
|
2788
|
+
if (gone.current) return started.cancel();
|
|
2789
|
+
rec.current = started;
|
|
2790
|
+
setState("recording");
|
|
2791
|
+
} catch (err) {
|
|
2792
|
+
if (!gone.current) {
|
|
2793
|
+
setError(micProblemOf(err));
|
|
2794
|
+
setState("idle");
|
|
2795
|
+
}
|
|
2796
|
+
} finally {
|
|
2797
|
+
pending.current = false;
|
|
2798
|
+
}
|
|
2799
|
+
}, []);
|
|
2800
|
+
const stop = (0, import_react5.useCallback)(async () => {
|
|
2801
|
+
const r = rec.current;
|
|
2802
|
+
if (!r) return void 0;
|
|
2803
|
+
rec.current = void 0;
|
|
2804
|
+
setState("stopping");
|
|
2805
|
+
try {
|
|
2806
|
+
return await r.stop();
|
|
2807
|
+
} catch {
|
|
2808
|
+
return void 0;
|
|
2809
|
+
} finally {
|
|
2810
|
+
if (!gone.current) setState("idle");
|
|
2811
|
+
}
|
|
2812
|
+
}, []);
|
|
2813
|
+
const cancel = (0, import_react5.useCallback)(() => {
|
|
2814
|
+
const r = rec.current;
|
|
2815
|
+
rec.current = void 0;
|
|
2816
|
+
r?.cancel();
|
|
2817
|
+
setLimited(void 0);
|
|
2818
|
+
setState("idle");
|
|
2819
|
+
}, []);
|
|
2820
|
+
(0, import_react5.useEffect)(() => {
|
|
2821
|
+
gone.current = false;
|
|
2822
|
+
return () => {
|
|
2823
|
+
gone.current = true;
|
|
2824
|
+
rec.current?.cancel();
|
|
2825
|
+
rec.current = void 0;
|
|
2826
|
+
};
|
|
2827
|
+
}, []);
|
|
2828
|
+
return {
|
|
2829
|
+
supported: recordingSupported(options),
|
|
2830
|
+
state,
|
|
2831
|
+
elapsedMs,
|
|
2832
|
+
error,
|
|
2833
|
+
limited,
|
|
2834
|
+
start,
|
|
2835
|
+
stop,
|
|
2836
|
+
cancel,
|
|
2837
|
+
clear: () => {
|
|
2838
|
+
setLimited(void 0);
|
|
2839
|
+
setError(void 0);
|
|
2840
|
+
}
|
|
2841
|
+
};
|
|
2842
|
+
};
|
|
2843
|
+
|
|
2844
|
+
// src/hooks/use-read-aloud.ts
|
|
2845
|
+
var import_react6 = require("react");
|
|
2846
|
+
|
|
2847
|
+
// src/voice/speak.ts
|
|
2848
|
+
var SpeechOutputError = class extends Error {
|
|
2849
|
+
code;
|
|
2850
|
+
constructor(code) {
|
|
2851
|
+
super(code);
|
|
2852
|
+
this.name = "SpeechOutputError";
|
|
2853
|
+
this.code = code;
|
|
2854
|
+
}
|
|
2855
|
+
};
|
|
2856
|
+
var asOutputError = (err) => err instanceof SpeechOutputError ? err : new SpeechOutputError(
|
|
2857
|
+
err && typeof err === "object" && "name" in err ? String(err.name) : "playback-failed"
|
|
2858
|
+
);
|
|
2859
|
+
var speakableText = (markdown, options = {}) => {
|
|
2860
|
+
const out = [];
|
|
2861
|
+
const lines = markdown.replace(/\r\n?/g, "\n").split("\n");
|
|
2862
|
+
let fence;
|
|
2863
|
+
let fenceSaid = false;
|
|
2864
|
+
for (const raw of lines) {
|
|
2865
|
+
const line = raw.trimEnd();
|
|
2866
|
+
const opener = /^\s*(`{3,}|~{3,})/.exec(line);
|
|
2867
|
+
if (fence !== void 0) {
|
|
2868
|
+
if (opener && opener[1][0] === fence[0] && opener[1].length >= fence.length) fence = void 0;
|
|
2869
|
+
continue;
|
|
2870
|
+
}
|
|
2871
|
+
if (opener) {
|
|
2872
|
+
fence = opener[1];
|
|
2873
|
+
if (options.code && !fenceSaid) out.push(options.code);
|
|
2874
|
+
fenceSaid = true;
|
|
2875
|
+
continue;
|
|
2876
|
+
}
|
|
2877
|
+
fenceSaid = false;
|
|
2878
|
+
if (/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/.test(line)) continue;
|
|
2879
|
+
if (/^\s*([-*_])\s*(\1\s*){2,}$/.test(line)) continue;
|
|
2880
|
+
let text2 = line.replace(/^\s{0,3}#{1,6}\s+/, "").replace(/^\s*>\s?/, "").replace(/^\s*(?:[-*+]|\d+[.)])\s+(\[[ xX]\]\s+)?/, "");
|
|
2881
|
+
if (/^\s*\|.*\|\s*$/.test(text2))
|
|
2882
|
+
text2 = text2.replace(/^\s*\||\|\s*$/g, "").split("|").map((c) => c.trim()).filter(Boolean).join(", ");
|
|
2883
|
+
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();
|
|
2884
|
+
if (!text2) continue;
|
|
2885
|
+
out.push(/[.!?…:;。!?]$/.test(text2) ? text2 : `${text2}.`);
|
|
2886
|
+
}
|
|
2887
|
+
return out.join(" ").trim();
|
|
2888
|
+
};
|
|
2889
|
+
var hostOf = (url) => {
|
|
2890
|
+
try {
|
|
2891
|
+
return new URL(url).hostname.replace(/^www\./, "");
|
|
2892
|
+
} catch {
|
|
2893
|
+
return "";
|
|
2894
|
+
}
|
|
2895
|
+
};
|
|
2896
|
+
var splitForSpeech = (text2, max = 220) => {
|
|
2897
|
+
const pieces = [];
|
|
2898
|
+
let rest = text2.trim();
|
|
2899
|
+
while (rest.length > max) {
|
|
2900
|
+
const window2 = rest.slice(0, max + 1);
|
|
2901
|
+
let cut = -1;
|
|
2902
|
+
for (const m of window2.matchAll(/[.!?…。!?;:](\s|$)/g))
|
|
2903
|
+
if (m.index !== void 0 && m.index + 1 <= max) cut = m.index + 1;
|
|
2904
|
+
if (cut < max / 3) cut = window2.lastIndexOf(" ");
|
|
2905
|
+
if (cut <= 0) cut = max;
|
|
2906
|
+
pieces.push(rest.slice(0, cut).trim());
|
|
2907
|
+
rest = rest.slice(cut).trim();
|
|
2908
|
+
}
|
|
2909
|
+
if (rest) pieces.push(rest);
|
|
2910
|
+
return pieces;
|
|
2911
|
+
};
|
|
2912
|
+
var SCRIPT_RANGES = [
|
|
2913
|
+
["latin", /\p{Script=Latin}/u],
|
|
2914
|
+
["cyrillic", /\p{Script=Cyrillic}/u],
|
|
2915
|
+
["greek", /\p{Script=Greek}/u],
|
|
2916
|
+
["arabic", /\p{Script=Arabic}/u],
|
|
2917
|
+
["hebrew", /\p{Script=Hebrew}/u],
|
|
2918
|
+
["kana", /[\p{Script=Hiragana}\p{Script=Katakana}]/u],
|
|
2919
|
+
["han", /\p{Script=Han}/u],
|
|
2920
|
+
["hangul", /\p{Script=Hangul}/u],
|
|
2921
|
+
["devanagari", /\p{Script=Devanagari}/u],
|
|
2922
|
+
["thai", /\p{Script=Thai}/u],
|
|
2923
|
+
["georgian", /\p{Script=Georgian}/u],
|
|
2924
|
+
["armenian", /\p{Script=Armenian}/u]
|
|
2925
|
+
];
|
|
2926
|
+
var LANGUAGE_SCRIPT = {
|
|
2927
|
+
ru: "cyrillic",
|
|
2928
|
+
uk: "cyrillic",
|
|
2929
|
+
be: "cyrillic",
|
|
2930
|
+
bg: "cyrillic",
|
|
2931
|
+
sr: "cyrillic",
|
|
2932
|
+
mk: "cyrillic",
|
|
2933
|
+
kk: "cyrillic",
|
|
2934
|
+
ky: "cyrillic",
|
|
2935
|
+
tg: "cyrillic",
|
|
2936
|
+
mn: "cyrillic",
|
|
2937
|
+
el: "greek",
|
|
2938
|
+
ar: "arabic",
|
|
2939
|
+
fa: "arabic",
|
|
2940
|
+
ur: "arabic",
|
|
2941
|
+
he: "hebrew",
|
|
2942
|
+
yi: "hebrew",
|
|
2943
|
+
zh: "han",
|
|
2944
|
+
ja: "kana",
|
|
2945
|
+
ko: "hangul",
|
|
2946
|
+
hi: "devanagari",
|
|
2947
|
+
mr: "devanagari",
|
|
2948
|
+
ne: "devanagari",
|
|
2949
|
+
th: "thai",
|
|
2950
|
+
ka: "georgian",
|
|
2951
|
+
hy: "armenian"
|
|
2952
|
+
};
|
|
2953
|
+
var SCRIPT_DEFAULT = {
|
|
2954
|
+
latin: "en",
|
|
2955
|
+
cyrillic: "ru",
|
|
2956
|
+
greek: "el",
|
|
2957
|
+
arabic: "ar",
|
|
2958
|
+
hebrew: "he",
|
|
2959
|
+
han: "zh",
|
|
2960
|
+
kana: "ja",
|
|
2961
|
+
hangul: "ko",
|
|
2962
|
+
devanagari: "hi",
|
|
2963
|
+
thai: "th",
|
|
2964
|
+
georgian: "ka",
|
|
2965
|
+
armenian: "hy"
|
|
2966
|
+
};
|
|
2967
|
+
var scriptOfLanguage = (lang) => {
|
|
2968
|
+
const parts = lang.toLowerCase().replace(/_/g, "-").split("-");
|
|
2969
|
+
if (parts.includes("latn")) return "latin";
|
|
2970
|
+
if (parts.includes("cyrl")) return "cyrillic";
|
|
2971
|
+
return LANGUAGE_SCRIPT[parts[0]] ?? "latin";
|
|
2972
|
+
};
|
|
2973
|
+
var scriptOfText = (text2) => {
|
|
2974
|
+
const counts = /* @__PURE__ */ new Map();
|
|
2975
|
+
for (const ch of text2) {
|
|
2976
|
+
if (!/\p{L}/u.test(ch)) continue;
|
|
2977
|
+
const found = SCRIPT_RANGES.find(([, re]) => re.test(ch));
|
|
2978
|
+
if (!found) continue;
|
|
2979
|
+
counts.set(found[0], (counts.get(found[0]) ?? 0) + 1);
|
|
2980
|
+
}
|
|
2981
|
+
if (counts.has("kana")) {
|
|
2982
|
+
counts.set("kana", (counts.get("kana") ?? 0) + (counts.get("han") ?? 0));
|
|
2983
|
+
counts.delete("han");
|
|
2984
|
+
}
|
|
2985
|
+
let best;
|
|
2986
|
+
let most = 0;
|
|
2987
|
+
for (const [script, n] of counts)
|
|
2988
|
+
if (n > most) {
|
|
2989
|
+
best = script;
|
|
2990
|
+
most = n;
|
|
2991
|
+
}
|
|
2992
|
+
return best;
|
|
2993
|
+
};
|
|
2994
|
+
var languageOfText = (text2, preferred = []) => {
|
|
2995
|
+
const mine = preferred.filter((l) => Boolean(l));
|
|
2996
|
+
const script = scriptOfText(text2);
|
|
2997
|
+
if (!script) return mine[0];
|
|
2998
|
+
return mine.find((l) => scriptOfLanguage(l) === script) ?? SCRIPT_DEFAULT[script];
|
|
2999
|
+
};
|
|
3000
|
+
var voiceFor = (voices, lang, preferred) => {
|
|
3001
|
+
if (preferred) {
|
|
3002
|
+
const chosen = voices.find((v) => v.voiceURI === preferred);
|
|
3003
|
+
if (chosen && (!lang || scriptOfLanguage(chosen.lang) === scriptOfLanguage(lang))) return chosen;
|
|
3004
|
+
}
|
|
3005
|
+
if (!lang) return void 0;
|
|
3006
|
+
const norm = (l) => l.toLowerCase().replace(/_/g, "-");
|
|
3007
|
+
const want = norm(lang);
|
|
3008
|
+
const base2 = want.split("-")[0];
|
|
3009
|
+
const rank = (v) => [v.localService ? 1 : 0, v.default ? 1 : 0];
|
|
3010
|
+
const best = (list) => [...list].sort((a, b) => {
|
|
3011
|
+
const ra = rank(a);
|
|
3012
|
+
const rb = rank(b);
|
|
3013
|
+
return rb[0] - ra[0] || rb[1] - ra[1] || a.name.localeCompare(b.name);
|
|
3014
|
+
})[0];
|
|
3015
|
+
const exact = voices.filter((v) => norm(v.lang) === want);
|
|
3016
|
+
if (exact.length) return best(exact);
|
|
3017
|
+
const same = voices.filter((v) => norm(v.lang).split("-")[0] === base2);
|
|
3018
|
+
return same.length ? best(same) : void 0;
|
|
3019
|
+
};
|
|
3020
|
+
var voicesOf = (voices, lang) => {
|
|
3021
|
+
if (!lang) return [...voices];
|
|
3022
|
+
const base2 = lang.toLowerCase().split(/[-_]/)[0];
|
|
3023
|
+
return voices.filter((v) => v.lang.toLowerCase().split(/[-_]/)[0] === base2);
|
|
3024
|
+
};
|
|
3025
|
+
var speechSynthesisSupported = () => typeof globalThis !== "undefined" && "speechSynthesis" in globalThis && typeof globalThis.SpeechSynthesisUtterance === "function";
|
|
3026
|
+
var createBrowserSpeaker = (options = {}) => (text2, { lang, onState }) => {
|
|
3027
|
+
const synth = options.synth ?? globalThis.speechSynthesis;
|
|
3028
|
+
const make = options.createUtterance ?? ((t) => new globalThis.SpeechSynthesisUtterance(t));
|
|
3029
|
+
const voice = voiceFor(synth.getVoices(), lang, options.voice);
|
|
3030
|
+
let settle;
|
|
3031
|
+
let fail;
|
|
3032
|
+
const done = new Promise((resolve, reject) => {
|
|
3033
|
+
settle = resolve;
|
|
3034
|
+
fail = reject;
|
|
3035
|
+
});
|
|
3036
|
+
done.catch(() => {
|
|
3037
|
+
});
|
|
3038
|
+
let over = false;
|
|
3039
|
+
const end = (err) => {
|
|
3040
|
+
if (over) return;
|
|
3041
|
+
over = true;
|
|
3042
|
+
if (err) fail(err);
|
|
3043
|
+
else settle();
|
|
3044
|
+
};
|
|
3045
|
+
const pieces = splitForSpeech(text2);
|
|
3046
|
+
synth.cancel();
|
|
3047
|
+
if (pieces.length === 0) {
|
|
3048
|
+
end();
|
|
3049
|
+
return { pause() {
|
|
3050
|
+
}, resume() {
|
|
3051
|
+
}, stop() {
|
|
3052
|
+
}, done };
|
|
3053
|
+
}
|
|
3054
|
+
let started = false;
|
|
3055
|
+
pieces.forEach((piece, i) => {
|
|
3056
|
+
const u = make(piece);
|
|
3057
|
+
u.lang = voice?.lang ?? lang ?? "";
|
|
3058
|
+
try {
|
|
3059
|
+
u.voice = voice ?? null;
|
|
3060
|
+
} catch {
|
|
3061
|
+
}
|
|
3062
|
+
u.rate = options.rate ?? 1;
|
|
3063
|
+
u.onstart = () => {
|
|
3064
|
+
if (!started && !over) onState("playing");
|
|
3065
|
+
started = true;
|
|
3066
|
+
};
|
|
3067
|
+
u.onend = () => {
|
|
3068
|
+
if (i === pieces.length - 1) end();
|
|
3069
|
+
};
|
|
3070
|
+
u.onerror = (event) => {
|
|
3071
|
+
if (event.error === "interrupted" || event.error === "canceled") end();
|
|
3072
|
+
else end(new SpeechOutputError(event.error || "synthesis-failed"));
|
|
3073
|
+
};
|
|
3074
|
+
synth.speak(u);
|
|
3075
|
+
});
|
|
3076
|
+
onState("loading");
|
|
3077
|
+
return {
|
|
3078
|
+
pause: () => {
|
|
3079
|
+
if (over) return;
|
|
3080
|
+
synth.pause();
|
|
3081
|
+
onState("paused");
|
|
3082
|
+
},
|
|
3083
|
+
resume: () => {
|
|
3084
|
+
if (over) return;
|
|
3085
|
+
synth.resume();
|
|
3086
|
+
onState("playing");
|
|
3087
|
+
},
|
|
3088
|
+
stop: () => {
|
|
3089
|
+
if (over) return;
|
|
3090
|
+
synth.cancel();
|
|
3091
|
+
end();
|
|
3092
|
+
},
|
|
3093
|
+
done
|
|
3094
|
+
};
|
|
3095
|
+
};
|
|
3096
|
+
var silence = () => {
|
|
3097
|
+
const samples = 16;
|
|
3098
|
+
const view = new DataView(new ArrayBuffer(44 + samples * 2));
|
|
3099
|
+
const text2 = (at, s) => {
|
|
3100
|
+
for (let i = 0; i < s.length; i++) view.setUint8(at + i, s.charCodeAt(i));
|
|
3101
|
+
};
|
|
3102
|
+
text2(0, "RIFF");
|
|
3103
|
+
view.setUint32(4, 36 + samples * 2, true);
|
|
3104
|
+
text2(8, "WAVEfmt ");
|
|
3105
|
+
view.setUint32(16, 16, true);
|
|
3106
|
+
view.setUint16(20, 1, true);
|
|
3107
|
+
view.setUint16(22, 1, true);
|
|
3108
|
+
view.setUint32(24, 8e3, true);
|
|
3109
|
+
view.setUint32(28, 16e3, true);
|
|
3110
|
+
view.setUint16(32, 2, true);
|
|
3111
|
+
view.setUint16(34, 16, true);
|
|
3112
|
+
text2(36, "data");
|
|
3113
|
+
view.setUint32(40, samples * 2, true);
|
|
3114
|
+
return new Blob([view.buffer], { type: "audio/wav" });
|
|
3115
|
+
};
|
|
3116
|
+
var createAudioSpeaker = (options) => (text2, { lang, onState }) => {
|
|
3117
|
+
const urls = options.objectUrl ?? {
|
|
3118
|
+
create: (b) => URL.createObjectURL(b),
|
|
3119
|
+
revoke: (u) => URL.revokeObjectURL(u)
|
|
3120
|
+
};
|
|
3121
|
+
const audio = options.createAudio?.() ?? new Audio();
|
|
3122
|
+
const controller = new AbortController();
|
|
3123
|
+
const pieces = splitForSpeech(text2, options.maxChars ?? 2e3);
|
|
3124
|
+
let settle;
|
|
3125
|
+
let fail;
|
|
3126
|
+
const done = new Promise((resolve, reject) => {
|
|
3127
|
+
settle = resolve;
|
|
3128
|
+
fail = reject;
|
|
3129
|
+
});
|
|
3130
|
+
done.catch(() => {
|
|
3131
|
+
});
|
|
3132
|
+
let over = false;
|
|
3133
|
+
let paused = false;
|
|
3134
|
+
let current;
|
|
3135
|
+
const made = /* @__PURE__ */ new Map();
|
|
3136
|
+
const make = (i) => {
|
|
3137
|
+
if (!made.has(i)) {
|
|
3138
|
+
const p = options.synthesize(pieces[i], { lang, signal: controller.signal });
|
|
3139
|
+
p.catch(() => {
|
|
3140
|
+
});
|
|
3141
|
+
made.set(i, p);
|
|
3142
|
+
}
|
|
3143
|
+
return made.get(i);
|
|
3144
|
+
};
|
|
3145
|
+
const release = () => {
|
|
3146
|
+
if (current) urls.revoke(current);
|
|
3147
|
+
current = void 0;
|
|
3148
|
+
};
|
|
3149
|
+
const end = (err) => {
|
|
3150
|
+
if (over) return;
|
|
3151
|
+
over = true;
|
|
3152
|
+
controller.abort();
|
|
3153
|
+
audio.pause();
|
|
3154
|
+
audio.onended = null;
|
|
3155
|
+
audio.onerror = null;
|
|
3156
|
+
release();
|
|
3157
|
+
if (err) fail(err);
|
|
3158
|
+
else settle();
|
|
3159
|
+
};
|
|
3160
|
+
const playFrom = async (i) => {
|
|
3161
|
+
if (over) return;
|
|
3162
|
+
if (i >= pieces.length) return end();
|
|
3163
|
+
onState(i === 0 || !current ? "loading" : "playing");
|
|
3164
|
+
let blob;
|
|
3165
|
+
try {
|
|
3166
|
+
blob = await make(i);
|
|
3167
|
+
} catch (err) {
|
|
3168
|
+
return end(err instanceof Error ? err : new Error(String(err)));
|
|
3169
|
+
}
|
|
3170
|
+
if (over) return;
|
|
3171
|
+
if (i + 1 < pieces.length) make(i + 1);
|
|
3172
|
+
release();
|
|
3173
|
+
current = urls.create(blob);
|
|
3174
|
+
audio.src = current;
|
|
3175
|
+
audio.onended = () => void playFrom(i + 1);
|
|
3176
|
+
audio.onerror = () => end(new SpeechOutputError("playback-failed"));
|
|
3177
|
+
if (paused) return onState("paused");
|
|
3178
|
+
try {
|
|
3179
|
+
await audio.play();
|
|
3180
|
+
if (!over) onState("playing");
|
|
3181
|
+
} catch (err) {
|
|
3182
|
+
end(asOutputError(err));
|
|
3183
|
+
}
|
|
3184
|
+
};
|
|
3185
|
+
if (pieces.length === 0) end();
|
|
3186
|
+
else {
|
|
3187
|
+
if (options.unlock !== false) {
|
|
3188
|
+
current = urls.create(silence());
|
|
3189
|
+
audio.src = current;
|
|
3190
|
+
audio.play().catch(() => {
|
|
3191
|
+
});
|
|
3192
|
+
}
|
|
3193
|
+
void playFrom(0);
|
|
3194
|
+
}
|
|
3195
|
+
return {
|
|
3196
|
+
pause: () => {
|
|
3197
|
+
if (over) return;
|
|
3198
|
+
paused = true;
|
|
3199
|
+
audio.pause();
|
|
3200
|
+
onState("paused");
|
|
3201
|
+
},
|
|
3202
|
+
resume: () => {
|
|
3203
|
+
if (over || !paused) return;
|
|
3204
|
+
paused = false;
|
|
3205
|
+
if (current)
|
|
3206
|
+
audio.play().then(
|
|
3207
|
+
() => !over && onState("playing"),
|
|
3208
|
+
(err) => end(asOutputError(err))
|
|
3209
|
+
);
|
|
3210
|
+
else onState("loading");
|
|
3211
|
+
},
|
|
3212
|
+
stop: () => end(),
|
|
3213
|
+
done
|
|
3214
|
+
};
|
|
3215
|
+
};
|
|
3216
|
+
|
|
3217
|
+
// src/hooks/use-read-aloud.ts
|
|
3218
|
+
var browserLanguages = () => typeof navigator !== "undefined" && Array.isArray(navigator.languages) ? navigator.languages : [];
|
|
3219
|
+
var useReadAloud = (speak, lang) => {
|
|
3220
|
+
const [current, setCurrent] = (0, import_react6.useState)();
|
|
3221
|
+
const [state, setState] = (0, import_react6.useState)();
|
|
3222
|
+
const [failed, setFailed] = (0, import_react6.useState)();
|
|
3223
|
+
const playback = (0, import_react6.useRef)(void 0);
|
|
3224
|
+
const langRef = (0, import_react6.useRef)(lang);
|
|
3225
|
+
langRef.current = lang;
|
|
3226
|
+
const stop = (0, import_react6.useCallback)(() => {
|
|
3227
|
+
const now = playback.current;
|
|
3228
|
+
playback.current = void 0;
|
|
3229
|
+
now?.handle.stop();
|
|
3230
|
+
setCurrent(void 0);
|
|
3231
|
+
setState(void 0);
|
|
3232
|
+
}, []);
|
|
3233
|
+
const start = (0, import_react6.useCallback)(
|
|
3234
|
+
(id, text2) => {
|
|
3235
|
+
if (!speak) return;
|
|
3236
|
+
stop();
|
|
3237
|
+
setFailed(void 0);
|
|
3238
|
+
setCurrent(id);
|
|
3239
|
+
setState("loading");
|
|
3240
|
+
const mine = { id, handle: void 0 };
|
|
3241
|
+
playback.current = mine;
|
|
3242
|
+
let handle;
|
|
3243
|
+
try {
|
|
3244
|
+
handle = speak(text2, {
|
|
3245
|
+
// The TEXT's language: a Russian answer in an English interface is read in Russian.
|
|
3246
|
+
lang: languageOfText(text2, [langRef.current, ...browserLanguages()]),
|
|
3247
|
+
onState: (s) => {
|
|
3248
|
+
if (playback.current === mine) setState(s);
|
|
3249
|
+
}
|
|
3250
|
+
});
|
|
3251
|
+
} catch (err) {
|
|
3252
|
+
playback.current = void 0;
|
|
3253
|
+
setCurrent(void 0);
|
|
3254
|
+
setState(void 0);
|
|
3255
|
+
const own = err instanceof Error && err.name !== "SpeechOutputError";
|
|
3256
|
+
setFailed({ id, ...own && err.message ? { message: err.message } : {} });
|
|
3257
|
+
return;
|
|
3258
|
+
}
|
|
3259
|
+
mine.handle = handle;
|
|
3260
|
+
handle.done.then(
|
|
3261
|
+
() => {
|
|
3262
|
+
if (playback.current !== mine) return;
|
|
3263
|
+
playback.current = void 0;
|
|
3264
|
+
setCurrent(void 0);
|
|
3265
|
+
setState(void 0);
|
|
3266
|
+
},
|
|
3267
|
+
(err) => {
|
|
3268
|
+
if (playback.current !== mine) return;
|
|
3269
|
+
playback.current = void 0;
|
|
3270
|
+
setCurrent(void 0);
|
|
3271
|
+
setState(void 0);
|
|
3272
|
+
const own = err instanceof Error && err.name !== "SpeechOutputError";
|
|
3273
|
+
setFailed({ id, ...own && err.message ? { message: err.message } : {} });
|
|
3274
|
+
}
|
|
3275
|
+
);
|
|
3276
|
+
},
|
|
3277
|
+
[speak, stop]
|
|
3278
|
+
);
|
|
3279
|
+
(0, import_react6.useEffect)(() => stop, [speak, stop]);
|
|
3280
|
+
return {
|
|
3281
|
+
current,
|
|
3282
|
+
state,
|
|
3283
|
+
failed,
|
|
3284
|
+
start,
|
|
3285
|
+
pause: () => playback.current?.handle.pause(),
|
|
3286
|
+
resume: () => playback.current?.handle.resume(),
|
|
3287
|
+
stop
|
|
3288
|
+
};
|
|
3289
|
+
};
|
|
3290
|
+
|
|
3291
|
+
// src/hooks/use-speech-voices.ts
|
|
3292
|
+
var import_react7 = require("react");
|
|
3293
|
+
var useSpeechVoices = () => {
|
|
3294
|
+
const synth = typeof globalThis !== "undefined" ? globalThis.speechSynthesis : void 0;
|
|
3295
|
+
const read = () => {
|
|
3296
|
+
try {
|
|
3297
|
+
return (synth?.getVoices() ?? []).map((v) => ({
|
|
3298
|
+
voiceURI: v.voiceURI,
|
|
3299
|
+
name: v.name,
|
|
3300
|
+
lang: v.lang,
|
|
3301
|
+
localService: v.localService,
|
|
3302
|
+
default: v.default
|
|
3303
|
+
}));
|
|
3304
|
+
} catch {
|
|
3305
|
+
return [];
|
|
3306
|
+
}
|
|
3307
|
+
};
|
|
3308
|
+
const [voices, setVoices] = (0, import_react7.useState)(read);
|
|
3309
|
+
(0, import_react7.useEffect)(() => {
|
|
3310
|
+
if (!synth) return;
|
|
3311
|
+
const update = () => setVoices(read());
|
|
3312
|
+
update();
|
|
3313
|
+
synth.addEventListener?.("voiceschanged", update);
|
|
3314
|
+
return () => synth.removeEventListener?.("voiceschanged", update);
|
|
3315
|
+
}, [synth]);
|
|
3316
|
+
return voices;
|
|
3317
|
+
};
|
|
3318
|
+
|
|
3319
|
+
// src/voice/recognizer.ts
|
|
3320
|
+
var createRecordingRecognizer = (options) => () => {
|
|
3321
|
+
let recording;
|
|
3322
|
+
let starting;
|
|
3323
|
+
let stopAsked = false;
|
|
3324
|
+
let aborted = false;
|
|
3325
|
+
let ended = false;
|
|
3326
|
+
const controller = new AbortController();
|
|
3327
|
+
const rec = {
|
|
3328
|
+
lang: "",
|
|
3329
|
+
continuous: true,
|
|
3330
|
+
interimResults: false,
|
|
3331
|
+
onresult: null,
|
|
3332
|
+
onerror: null,
|
|
3333
|
+
onend: null,
|
|
3334
|
+
start() {
|
|
3335
|
+
if (starting) return;
|
|
3336
|
+
starting = (async () => {
|
|
3337
|
+
try {
|
|
3338
|
+
recording = await startRecording({
|
|
3339
|
+
...options,
|
|
3340
|
+
maxMs: options.maxMs,
|
|
3341
|
+
onLimit: () => rec.stop()
|
|
3342
|
+
});
|
|
3343
|
+
} catch (err) {
|
|
3344
|
+
if (!aborted) rec.onerror?.({ error: micProblemOf(err) });
|
|
3345
|
+
return finish();
|
|
3346
|
+
}
|
|
3347
|
+
if (aborted) {
|
|
3348
|
+
recording.cancel();
|
|
3349
|
+
return finish();
|
|
3350
|
+
}
|
|
3351
|
+
if (stopAsked) void transcribeNow();
|
|
3352
|
+
})();
|
|
3353
|
+
},
|
|
3354
|
+
stop() {
|
|
3355
|
+
if (stopAsked || ended) return;
|
|
3356
|
+
stopAsked = true;
|
|
3357
|
+
if (recording) void transcribeNow();
|
|
3358
|
+
},
|
|
3359
|
+
abort() {
|
|
3360
|
+
if (ended) return;
|
|
3361
|
+
aborted = true;
|
|
3362
|
+
controller.abort();
|
|
3363
|
+
recording?.cancel();
|
|
3364
|
+
if (!starting || recording) finish();
|
|
3365
|
+
}
|
|
3366
|
+
};
|
|
3367
|
+
const finish = () => {
|
|
3368
|
+
if (ended) return;
|
|
3369
|
+
ended = true;
|
|
3370
|
+
rec.onend?.();
|
|
3371
|
+
};
|
|
3372
|
+
let transcribing = false;
|
|
3373
|
+
const transcribeNow = async () => {
|
|
3374
|
+
if (transcribing || !recording) return;
|
|
3375
|
+
transcribing = true;
|
|
3376
|
+
let audio;
|
|
3377
|
+
try {
|
|
3378
|
+
audio = await recording.stop();
|
|
3379
|
+
} catch (err) {
|
|
3380
|
+
if (!aborted) rec.onerror?.({ error: micProblemOf(err) });
|
|
3381
|
+
return finish();
|
|
3382
|
+
}
|
|
3383
|
+
if (aborted) return finish();
|
|
3384
|
+
if (audio.blob.size === 0) return finish();
|
|
3385
|
+
try {
|
|
3386
|
+
const text2 = (await options.transcribe(audio, { lang: rec.lang, signal: controller.signal })).replace(/\s+/g, " ").trim();
|
|
3387
|
+
if (!aborted && text2)
|
|
3388
|
+
rec.onresult?.({
|
|
3389
|
+
resultIndex: 0,
|
|
3390
|
+
results: [{ isFinal: true, 0: { transcript: text2 } }]
|
|
3391
|
+
});
|
|
3392
|
+
} catch (err) {
|
|
3393
|
+
if (!aborted)
|
|
3394
|
+
rec.onerror?.({
|
|
3395
|
+
error: "transcription",
|
|
3396
|
+
message: err instanceof Error ? err.message : String(err)
|
|
3397
|
+
});
|
|
3398
|
+
}
|
|
3399
|
+
finish();
|
|
3400
|
+
};
|
|
3401
|
+
return rec;
|
|
3402
|
+
};
|
|
3403
|
+
|
|
3404
|
+
// src/hooks/use-credentials.ts
|
|
3405
|
+
var import_react8 = require("react");
|
|
2493
3406
|
var core5 = __toESM(require("@dudko.dev/agent-web"), 1);
|
|
2494
3407
|
var import_agent_web3 = require("@dudko.dev/agent-web");
|
|
2495
3408
|
var storeDbName = (store) => {
|
|
@@ -2497,10 +3410,10 @@ var storeDbName = (store) => {
|
|
|
2497
3410
|
return typeof name === "string" && name ? name : void 0;
|
|
2498
3411
|
};
|
|
2499
3412
|
var useCredentials = (store) => {
|
|
2500
|
-
const resolved = (0,
|
|
2501
|
-
const [version, setVersion] = (0,
|
|
3413
|
+
const resolved = (0, import_react8.useMemo)(() => store ?? new import_agent_web3.VaultCredentialStore(), [store]);
|
|
3414
|
+
const [version, setVersion] = (0, import_react8.useState)(0);
|
|
2502
3415
|
const dbName = storeDbName(resolved);
|
|
2503
|
-
(0,
|
|
3416
|
+
(0, import_react8.useEffect)(() => {
|
|
2504
3417
|
return followOtherTabs(
|
|
2505
3418
|
core5,
|
|
2506
3419
|
dbName,
|
|
@@ -2508,21 +3421,21 @@ var useCredentials = (store) => {
|
|
|
2508
3421
|
() => setVersion((v) => v + 1)
|
|
2509
3422
|
);
|
|
2510
3423
|
}, [dbName]);
|
|
2511
|
-
const setKey = (0,
|
|
3424
|
+
const setKey = (0, import_react8.useCallback)(
|
|
2512
3425
|
async (ref, key) => {
|
|
2513
3426
|
await resolved.setApiKey(ref, key);
|
|
2514
3427
|
setVersion((v) => v + 1);
|
|
2515
3428
|
},
|
|
2516
3429
|
[resolved]
|
|
2517
3430
|
);
|
|
2518
|
-
const removeKey = (0,
|
|
3431
|
+
const removeKey = (0, import_react8.useCallback)(
|
|
2519
3432
|
async (ref) => {
|
|
2520
3433
|
await resolved.deleteApiKey(ref);
|
|
2521
3434
|
setVersion((v) => v + 1);
|
|
2522
3435
|
},
|
|
2523
3436
|
[resolved]
|
|
2524
3437
|
);
|
|
2525
|
-
const hasKey = (0,
|
|
3438
|
+
const hasKey = (0, import_react8.useCallback)(
|
|
2526
3439
|
async (ref) => await resolved.getApiKey(ref) !== void 0,
|
|
2527
3440
|
[resolved]
|
|
2528
3441
|
);
|
|
@@ -2533,21 +3446,21 @@ var useCredentials = (store) => {
|
|
|
2533
3446
|
var import_agent_web4 = require("@dudko.dev/agent-web");
|
|
2534
3447
|
|
|
2535
3448
|
// src/hooks/use-local-model.ts
|
|
2536
|
-
var
|
|
3449
|
+
var import_react9 = require("react");
|
|
2537
3450
|
var keyOf = (id, tokens) => tokens ? `${id}@${tokens}` : id;
|
|
2538
3451
|
var useLocalModel = (modelId, engine, options) => {
|
|
2539
|
-
const [loaded, setLoaded] = (0,
|
|
2540
|
-
const [pending, setPending] = (0,
|
|
2541
|
-
const [failure, setFailure] = (0,
|
|
2542
|
-
const engineRef = (0,
|
|
3452
|
+
const [loaded, setLoaded] = (0, import_react9.useState)(void 0);
|
|
3453
|
+
const [pending, setPending] = (0, import_react9.useState)();
|
|
3454
|
+
const [failure, setFailure] = (0, import_react9.useState)();
|
|
3455
|
+
const engineRef = (0, import_react9.useRef)(engine);
|
|
2543
3456
|
engineRef.current = engine;
|
|
2544
|
-
const loadedRef = (0,
|
|
2545
|
-
const inflightRef = (0,
|
|
3457
|
+
const loadedRef = (0, import_react9.useRef)(void 0);
|
|
3458
|
+
const inflightRef = (0, import_react9.useRef)(
|
|
2546
3459
|
void 0
|
|
2547
3460
|
);
|
|
2548
3461
|
const windowTokens = options?.contextWindowTokens;
|
|
2549
3462
|
const key = keyOf(modelId, windowTokens);
|
|
2550
|
-
const seqRef = (0,
|
|
3463
|
+
const seqRef = (0, import_react9.useRef)(0);
|
|
2551
3464
|
const setHeld = (next) => {
|
|
2552
3465
|
loadedRef.current = next;
|
|
2553
3466
|
setLoaded(next);
|
|
@@ -2558,7 +3471,7 @@ var useLocalModel = (modelId, engine, options) => {
|
|
|
2558
3471
|
} catch {
|
|
2559
3472
|
}
|
|
2560
3473
|
};
|
|
2561
|
-
const load = (0,
|
|
3474
|
+
const load = (0, import_react9.useCallback)(() => {
|
|
2562
3475
|
const id = modelId;
|
|
2563
3476
|
if (loadedRef.current?.key === key) return Promise.resolve(loadedRef.current.model);
|
|
2564
3477
|
if (inflightRef.current?.key === key) return inflightRef.current.promise;
|
|
@@ -2610,7 +3523,7 @@ var useLocalModel = (modelId, engine, options) => {
|
|
|
2610
3523
|
inflightRef.current = { key, promise };
|
|
2611
3524
|
return promise;
|
|
2612
3525
|
}, [modelId, key]);
|
|
2613
|
-
const unload = (0,
|
|
3526
|
+
const unload = (0, import_react9.useCallback)(async () => {
|
|
2614
3527
|
seqRef.current++;
|
|
2615
3528
|
inflightRef.current = void 0;
|
|
2616
3529
|
setPending(void 0);
|
|
@@ -2672,7 +3585,7 @@ var createWebLLMEngine = (options) => {
|
|
|
2672
3585
|
};
|
|
2673
3586
|
|
|
2674
3587
|
// src/labels.tsx
|
|
2675
|
-
var
|
|
3588
|
+
var import_react10 = require("react");
|
|
2676
3589
|
|
|
2677
3590
|
// src/composer.ts
|
|
2678
3591
|
var parseSlash = (text2) => {
|
|
@@ -2838,6 +3751,27 @@ var noticesOf = (state, texts = {}) => {
|
|
|
2838
3751
|
}
|
|
2839
3752
|
return out;
|
|
2840
3753
|
};
|
|
3754
|
+
var formatClock = (ms) => {
|
|
3755
|
+
const s = Math.max(0, Math.floor(ms / 1e3));
|
|
3756
|
+
const two = (n) => String(n).padStart(2, "0");
|
|
3757
|
+
const h = Math.floor(s / 3600);
|
|
3758
|
+
const m = Math.floor(s % 3600 / 60);
|
|
3759
|
+
return h > 0 ? `${h}:${two(m)}:${two(s % 60)}` : `${m}:${two(s % 60)}`;
|
|
3760
|
+
};
|
|
3761
|
+
var micProblemText = (code, message, labels) => {
|
|
3762
|
+
if (code === "not-allowed" || code === "service-not-allowed") return labels.micDenied;
|
|
3763
|
+
if (code === "audio-capture") return labels.micMissing;
|
|
3764
|
+
if (code === "busy") return labels.micBusy;
|
|
3765
|
+
if (code === "unsupported") return labels.micUnsupported;
|
|
3766
|
+
if (message) return message;
|
|
3767
|
+
return code && code !== "transcription" && code !== "failed" ? `${labels.dictationFailed} (${code})` : labels.dictationFailed;
|
|
3768
|
+
};
|
|
3769
|
+
var voiceMessageName = (at, extension) => {
|
|
3770
|
+
const two = (n) => String(n).padStart(2, "0");
|
|
3771
|
+
return `voice-${at.getFullYear()}-${two(at.getMonth() + 1)}-${two(at.getDate())}-${two(
|
|
3772
|
+
at.getHours()
|
|
3773
|
+
)}${two(at.getMinutes())}${two(at.getSeconds())}.${extension}`;
|
|
3774
|
+
};
|
|
2841
3775
|
|
|
2842
3776
|
// src/labels.tsx
|
|
2843
3777
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -2878,6 +3812,11 @@ var defaultLabels = {
|
|
|
2878
3812
|
notebookForget: "Forget",
|
|
2879
3813
|
notebookRevision: (n) => `revision ${n}`,
|
|
2880
3814
|
notebookFrom: "from",
|
|
3815
|
+
memorySaved: "Remembered",
|
|
3816
|
+
memoryUpdated: "Memory updated",
|
|
3817
|
+
memoryForgotten: "Forgotten",
|
|
3818
|
+
memoryUndo: "Undo",
|
|
3819
|
+
memoryUndone: "Undone",
|
|
2881
3820
|
placeholder: "Ask the agent to do something\u2026 ( / for commands, Ctrl+V to paste an image )",
|
|
2882
3821
|
listening: "Listening\u2026",
|
|
2883
3822
|
message: "Message",
|
|
@@ -2894,6 +3833,19 @@ var defaultLabels = {
|
|
|
2894
3833
|
dictateTitle: "Dictate \u2014 speech to text in the browser",
|
|
2895
3834
|
stopDictation: "Stop dictation",
|
|
2896
3835
|
microphone: "Microphone",
|
|
3836
|
+
transcribing: "Transcribing\u2026",
|
|
3837
|
+
micDenied: "The microphone is blocked for this site. Allow it in the browser's site settings (the icon beside the address), then try again.",
|
|
3838
|
+
micMissing: "No microphone was found on this device.",
|
|
3839
|
+
micBusy: "The microphone is in use by another app.",
|
|
3840
|
+
micUnsupported: "This browser cannot record audio on this page.",
|
|
3841
|
+
dictationFailed: "Dictation did not work.",
|
|
3842
|
+
recordVoiceMessage: "Record a voice message",
|
|
3843
|
+
voiceMessage: "Voice message",
|
|
3844
|
+
audioDuration: (clock) => clock,
|
|
3845
|
+
recording: (elapsed) => `Recording ${elapsed}`,
|
|
3846
|
+
recordingDone: "Attach the recording",
|
|
3847
|
+
recordingCancel: "Discard the recording",
|
|
3848
|
+
recordingLimit: "The recording reached its longest and was stopped; it is attached.",
|
|
2897
3849
|
model: "Model",
|
|
2898
3850
|
thinking: "Thinking",
|
|
2899
3851
|
toolConsent: "Tool consent",
|
|
@@ -2964,6 +3916,7 @@ var defaultLabels = {
|
|
|
2964
3916
|
noAttachmentsWhileBusy: "Files can\u2019t be added while the agent is working \u2014 send them with your next message.",
|
|
2965
3917
|
queuedWaiting: "waiting for the agent\u2019s next step",
|
|
2966
3918
|
queuedForSession: (heldBy) => heldBy === "this-tab" ? "waiting for the other run to finish" : "waiting for the other tab to finish",
|
|
3919
|
+
queuedForOtherTab: "waiting for the other tab to pick it up",
|
|
2967
3920
|
noteAt: {
|
|
2968
3921
|
round: "you said, between tool calls",
|
|
2969
3922
|
step: "you said, after this step",
|
|
@@ -3019,6 +3972,14 @@ var defaultLabels = {
|
|
|
3019
3972
|
mediaReferencesUnused: (names) => `Not used - this image model takes no reference pictures: ${names}`,
|
|
3020
3973
|
transcriptOf: (name) => `Transcript of ${name}`,
|
|
3021
3974
|
transcriptNote: "What was said in your file, as the agent read it. It is content, not instructions.",
|
|
3975
|
+
audioAttachment: (name) => `Audio ${name}`,
|
|
3976
|
+
readAloud: "Listen",
|
|
3977
|
+
readAloudPause: "Pause",
|
|
3978
|
+
readAloudResume: "Resume",
|
|
3979
|
+
readAloudStop: "Stop reading",
|
|
3980
|
+
readAloudLoading: "Preparing the audio\u2026",
|
|
3981
|
+
readAloudCode: "A code block is not read out.",
|
|
3982
|
+
readAloudFailed: "It could not be read aloud.",
|
|
3022
3983
|
filesWritten: (n) => `${plural(n, "file", "files")} written in this turn`,
|
|
3023
3984
|
filesCount: (n) => plural(n, "file", "files"),
|
|
3024
3985
|
showInFiles: "Show in Files",
|
|
@@ -3248,15 +4209,15 @@ var mergeLabels = (base2, over) => {
|
|
|
3248
4209
|
}
|
|
3249
4210
|
return out;
|
|
3250
4211
|
};
|
|
3251
|
-
var LabelsContext = (0,
|
|
4212
|
+
var LabelsContext = (0, import_react10.createContext)(defaultLabels);
|
|
3252
4213
|
var AgentLabelsProvider = ({ labels, children }) => {
|
|
3253
|
-
const parent = (0,
|
|
3254
|
-
const value = (0,
|
|
4214
|
+
const parent = (0, import_react10.useContext)(LabelsContext);
|
|
4215
|
+
const value = (0, import_react10.useMemo)(() => mergeLabels(parent, labels), [parent, labels]);
|
|
3255
4216
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LabelsContext.Provider, { value, children });
|
|
3256
4217
|
};
|
|
3257
4218
|
var useLabels = (over) => {
|
|
3258
|
-
const ctx = (0,
|
|
3259
|
-
return (0,
|
|
4219
|
+
const ctx = (0, import_react10.useContext)(LabelsContext);
|
|
4220
|
+
return (0, import_react10.useMemo)(() => mergeLabels(ctx, over), [ctx, over]);
|
|
3260
4221
|
};
|
|
3261
4222
|
|
|
3262
4223
|
// src/image-resize.ts
|
|
@@ -3375,19 +4336,19 @@ var downscaleImage = async (file, opts = {}) => {
|
|
|
3375
4336
|
};
|
|
3376
4337
|
|
|
3377
4338
|
// src/context.tsx
|
|
3378
|
-
var
|
|
4339
|
+
var import_react11 = require("react");
|
|
3379
4340
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
3380
|
-
var AgentContext = (0,
|
|
4341
|
+
var AgentContext = (0, import_react11.createContext)(null);
|
|
3381
4342
|
var AgentProvider = ({ config, children, ...options }) => {
|
|
3382
4343
|
const agent = useAgent(config, options);
|
|
3383
4344
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AgentContext.Provider, { value: agent, children });
|
|
3384
4345
|
};
|
|
3385
4346
|
var useAgentContext = () => {
|
|
3386
|
-
const ctx = (0,
|
|
4347
|
+
const ctx = (0, import_react11.useContext)(AgentContext);
|
|
3387
4348
|
if (!ctx) throw new Error("useAgentContext must be used within an <AgentProvider>");
|
|
3388
4349
|
return ctx;
|
|
3389
4350
|
};
|
|
3390
|
-
var useOptionalAgentContext = () => (0,
|
|
4351
|
+
var useOptionalAgentContext = () => (0, import_react11.useContext)(AgentContext);
|
|
3391
4352
|
|
|
3392
4353
|
// src/elicitation.ts
|
|
3393
4354
|
var titled = (options) => options.map((o) => ({ value: o.const, label: o.title || o.const }));
|
|
@@ -3594,11 +4555,11 @@ var formatCountdown = (ms) => {
|
|
|
3594
4555
|
};
|
|
3595
4556
|
|
|
3596
4557
|
// src/components/AgentChat.tsx
|
|
3597
|
-
var
|
|
4558
|
+
var import_react25 = require("react");
|
|
3598
4559
|
var import_react_dom2 = require("react-dom");
|
|
3599
4560
|
|
|
3600
4561
|
// src/hooks/use-follow-scroll.ts
|
|
3601
|
-
var
|
|
4562
|
+
var import_react12 = require("react");
|
|
3602
4563
|
|
|
3603
4564
|
// src/follow-scroll.ts
|
|
3604
4565
|
var FOLLOW_REJOIN_PX = 80;
|
|
@@ -3615,7 +4576,7 @@ var followsAfterScroll = (following, before, now) => {
|
|
|
3615
4576
|
var followsAfterResize = (following, before, now) => following && !(now.clientHeight === before.clientHeight && now.scrollHeight >= before.scrollHeight && now.scrollTop < reach(before) - FOLLOW_LEAVE_PX);
|
|
3616
4577
|
|
|
3617
4578
|
// src/hooks/use-follow-scroll.ts
|
|
3618
|
-
var useIsoLayoutEffect = typeof window === "undefined" ?
|
|
4579
|
+
var useIsoLayoutEffect = typeof window === "undefined" ? import_react12.useEffect : import_react12.useLayoutEffect;
|
|
3619
4580
|
var measure = (el) => ({
|
|
3620
4581
|
scrollTop: el.scrollTop,
|
|
3621
4582
|
scrollHeight: el.scrollHeight,
|
|
@@ -3637,12 +4598,12 @@ var anchorOf = (el) => {
|
|
|
3637
4598
|
return marks.length ? { marks, top: el.scrollTop } : void 0;
|
|
3638
4599
|
};
|
|
3639
4600
|
var useFollowScroll = (ref, turn, live = true) => {
|
|
3640
|
-
const following = (0,
|
|
3641
|
-
const last = (0,
|
|
3642
|
-
const anchor = (0,
|
|
3643
|
-
const settle = (0,
|
|
4601
|
+
const following = (0, import_react12.useRef)(true);
|
|
4602
|
+
const last = (0, import_react12.useRef)(void 0);
|
|
4603
|
+
const anchor = (0, import_react12.useRef)(void 0);
|
|
4604
|
+
const settle = (0, import_react12.useRef)(() => {
|
|
3644
4605
|
});
|
|
3645
|
-
const arriving = (0,
|
|
4606
|
+
const arriving = (0, import_react12.useRef)(live);
|
|
3646
4607
|
arriving.current = live;
|
|
3647
4608
|
useIsoLayoutEffect(() => {
|
|
3648
4609
|
const el = ref.current;
|
|
@@ -3715,7 +4676,7 @@ var useFollowScroll = (ref, turn, live = true) => {
|
|
|
3715
4676
|
};
|
|
3716
4677
|
|
|
3717
4678
|
// src/hooks/use-mcp-app-host.ts
|
|
3718
|
-
var
|
|
4679
|
+
var import_react13 = require("react");
|
|
3719
4680
|
|
|
3720
4681
|
// src/mcp-app.ts
|
|
3721
4682
|
var import_agent_web5 = require("@dudko.dev/agent-web");
|
|
@@ -4581,27 +5542,27 @@ var useMcpAppHost = ({
|
|
|
4581
5542
|
sampling = false,
|
|
4582
5543
|
sample: sampleFn
|
|
4583
5544
|
}) => {
|
|
4584
|
-
const [requests, setRequests] = (0,
|
|
4585
|
-
const [draft, setDraft] = (0,
|
|
4586
|
-
const waiting = (0,
|
|
5545
|
+
const [requests, setRequests] = (0, import_react13.useState)([]);
|
|
5546
|
+
const [draft, setDraft] = (0, import_react13.useState)();
|
|
5547
|
+
const waiting = (0, import_react13.useRef)(
|
|
4587
5548
|
/* @__PURE__ */ new Map()
|
|
4588
5549
|
);
|
|
4589
|
-
const samplingAllowed = (0,
|
|
4590
|
-
const sampleRef = (0,
|
|
5550
|
+
const samplingAllowed = (0, import_react13.useRef)(/* @__PURE__ */ new Set());
|
|
5551
|
+
const sampleRef = (0, import_react13.useRef)(sampleFn);
|
|
4591
5552
|
sampleRef.current = sampleFn;
|
|
4592
|
-
const [gated, setGated] = (0,
|
|
4593
|
-
const connectionRef = (0,
|
|
5553
|
+
const [gated, setGated] = (0, import_react13.useState)({});
|
|
5554
|
+
const connectionRef = (0, import_react13.useRef)(connection);
|
|
4594
5555
|
connectionRef.current = connection;
|
|
4595
|
-
const approveRef = (0,
|
|
5556
|
+
const approveRef = (0, import_react13.useRef)(approve);
|
|
4596
5557
|
approveRef.current = approve;
|
|
4597
|
-
(0,
|
|
5558
|
+
(0, import_react13.useEffect)(
|
|
4598
5559
|
() => () => {
|
|
4599
5560
|
for (const { resolve } of waiting.current.values()) resolve(false);
|
|
4600
5561
|
waiting.current.clear();
|
|
4601
5562
|
},
|
|
4602
5563
|
[]
|
|
4603
5564
|
);
|
|
4604
|
-
const ask = (0,
|
|
5565
|
+
const ask = (0, import_react13.useCallback)(
|
|
4605
5566
|
(request, signal, extra = {}) => {
|
|
4606
5567
|
for (const w of waiting.current.values()) {
|
|
4607
5568
|
if (w.request.appId === request.appId) {
|
|
@@ -4626,7 +5587,7 @@ var useMcpAppHost = ({
|
|
|
4626
5587
|
},
|
|
4627
5588
|
[]
|
|
4628
5589
|
);
|
|
4629
|
-
const answer = (0,
|
|
5590
|
+
const answer = (0, import_react13.useCallback)((id, accept, options) => {
|
|
4630
5591
|
const w = waiting.current.get(id);
|
|
4631
5592
|
if (!w) return;
|
|
4632
5593
|
if (accept && w.request.kind === "link" && w.request.link) {
|
|
@@ -4652,16 +5613,16 @@ var useMcpAppHost = ({
|
|
|
4652
5613
|
}
|
|
4653
5614
|
w.resolve(accept);
|
|
4654
5615
|
}, []);
|
|
4655
|
-
const read = (0,
|
|
5616
|
+
const read = (0, import_react13.useCallback)((app, signal) => {
|
|
4656
5617
|
const c = connectionRef.current;
|
|
4657
5618
|
if (!c) return Promise.reject(new Error(`no connection to the server \u201C${app.server}\u201D`));
|
|
4658
5619
|
return c.readUiResource(app.server, app.resourceUri, signal ? { signal } : void 0);
|
|
4659
5620
|
}, []);
|
|
4660
|
-
const tool = (0,
|
|
5621
|
+
const tool = (0, import_react13.useCallback)(
|
|
4661
5622
|
(app) => connectionRef.current?.appTool(app.server, app.toolName),
|
|
4662
5623
|
[]
|
|
4663
5624
|
);
|
|
4664
|
-
const callTool = (0,
|
|
5625
|
+
const callTool = (0, import_react13.useCallback)(
|
|
4665
5626
|
async (app, name, args, signal) => {
|
|
4666
5627
|
const c = connectionRef.current;
|
|
4667
5628
|
if (!c) throw refused(`The server \u201C${app.server}\u201D is not connected`);
|
|
@@ -4698,15 +5659,15 @@ var useMcpAppHost = ({
|
|
|
4698
5659
|
},
|
|
4699
5660
|
[]
|
|
4700
5661
|
);
|
|
4701
|
-
const openLink = (0,
|
|
5662
|
+
const openLink = (0, import_react13.useCallback)(
|
|
4702
5663
|
(app, link, signal) => ask({ appId: app.id, server: app.server, kind: "link", link }, signal),
|
|
4703
5664
|
[ask]
|
|
4704
5665
|
);
|
|
4705
|
-
const message = (0,
|
|
5666
|
+
const message = (0, import_react13.useCallback)(
|
|
4706
5667
|
(app, text2, signal) => ask({ appId: app.id, server: app.server, kind: "message", text: text2 }, signal),
|
|
4707
5668
|
[ask]
|
|
4708
5669
|
);
|
|
4709
|
-
const downloadFile2 = (0,
|
|
5670
|
+
const downloadFile2 = (0, import_react13.useCallback)(
|
|
4710
5671
|
async (app, file, signal) => {
|
|
4711
5672
|
const c = connectionRef.current;
|
|
4712
5673
|
if (file.kind === "link" && !c) throw refused(`The server \u201C${app.server}\u201D is not connected`);
|
|
@@ -4729,7 +5690,7 @@ var useMcpAppHost = ({
|
|
|
4729
5690
|
},
|
|
4730
5691
|
[ask]
|
|
4731
5692
|
);
|
|
4732
|
-
const sample = (0,
|
|
5693
|
+
const sample = (0, import_react13.useCallback)(
|
|
4733
5694
|
async (app, params, signal) => {
|
|
4734
5695
|
const fn = sampleRef.current;
|
|
4735
5696
|
if (!fn) throw refused("This host cannot answer sampling requests");
|
|
@@ -4750,19 +5711,19 @@ var useMcpAppHost = ({
|
|
|
4750
5711
|
},
|
|
4751
5712
|
[ask]
|
|
4752
5713
|
);
|
|
4753
|
-
const pendingAppServers = (0,
|
|
5714
|
+
const pendingAppServers = (0, import_react13.useMemo)(
|
|
4754
5715
|
() => new Set(
|
|
4755
5716
|
approvals.filter((a) => a.app && a.status === "pending").map((a) => `${a.app.server}\0${a.app.resourceUri}`)
|
|
4756
5717
|
),
|
|
4757
5718
|
[approvals]
|
|
4758
5719
|
);
|
|
4759
|
-
const isWaiting = (0,
|
|
5720
|
+
const isWaiting = (0, import_react13.useCallback)(
|
|
4760
5721
|
(app) => requests.some((r) => r.appId === app.id) || Boolean(gated[app.id]) && pendingAppServers.has(`${app.server}\0${app.resourceUri}`),
|
|
4761
5722
|
[requests, gated, pendingAppServers]
|
|
4762
5723
|
);
|
|
4763
5724
|
const sandboxUrl = sandbox?.url;
|
|
4764
5725
|
const sandboxTimeout = sandbox?.timeoutMs;
|
|
4765
|
-
const sandboxSetting = (0,
|
|
5726
|
+
const sandboxSetting = (0, import_react13.useMemo)(
|
|
4766
5727
|
() => sandboxUrl === void 0 ? void 0 : {
|
|
4767
5728
|
url: sandboxUrl,
|
|
4768
5729
|
...sandboxTimeout !== void 0 ? { timeoutMs: sandboxTimeout } : {}
|
|
@@ -4770,7 +5731,7 @@ var useMcpAppHost = ({
|
|
|
4770
5731
|
[sandboxUrl, sandboxTimeout]
|
|
4771
5732
|
);
|
|
4772
5733
|
const samplingOn = sampling && Boolean(sampleFn);
|
|
4773
|
-
return (0,
|
|
5734
|
+
return (0, import_react13.useMemo)(
|
|
4774
5735
|
() => ({
|
|
4775
5736
|
connected: Boolean(connection),
|
|
4776
5737
|
read,
|
|
@@ -4859,6 +5820,13 @@ var MicIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.j
|
|
|
4859
5820
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("rect", { x: "9", y: "3", width: "6", height: "11", rx: "3" }),
|
|
4860
5821
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M5 11a7 7 0 0 0 14 0M12 18v3" })
|
|
4861
5822
|
] });
|
|
5823
|
+
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" }) });
|
|
5824
|
+
var SpeakerIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("svg", { ...base(size), className, children: [
|
|
5825
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M4 9h4l5-4v14l-5-4H4Z" }),
|
|
5826
|
+
/* @__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" })
|
|
5827
|
+
] });
|
|
5828
|
+
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" }) });
|
|
5829
|
+
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" }) });
|
|
4862
5830
|
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" }) });
|
|
4863
5831
|
var EyeIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("svg", { ...base(size), className, children: [
|
|
4864
5832
|
/* @__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" }),
|
|
@@ -4877,6 +5845,7 @@ var BookIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.
|
|
|
4877
5845
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M4 5a2 2 0 0 1 2-2h13v16H6a2 2 0 0 0-2 2Z" }),
|
|
4878
5846
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M4 19V5M9 7h6" })
|
|
4879
5847
|
] });
|
|
5848
|
+
var BookmarkIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { ...base(size), className, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M6 3h12v18l-6-4-6 4Z" }) });
|
|
4880
5849
|
var GlobeIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("svg", { ...base(size), className, children: [
|
|
4881
5850
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "12", cy: "12", r: "9" }),
|
|
4882
5851
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M3 12h18M12 3c3 3.2 3 14.8 0 18M12 3c-3 3.2-3 14.8 0 18" })
|
|
@@ -5053,11 +6022,11 @@ var AppRequestPrompt = ({
|
|
|
5053
6022
|
};
|
|
5054
6023
|
|
|
5055
6024
|
// src/components/McpAppFrame.tsx
|
|
5056
|
-
var
|
|
6025
|
+
var import_react14 = require("react");
|
|
5057
6026
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
5058
6027
|
var HOST_INFO = { name: "@dudko.dev/agent-web-react", version: "1" };
|
|
5059
6028
|
var MAX_LISTED_CALLS = 12;
|
|
5060
|
-
var useIsoLayoutEffect2 = typeof window === "undefined" ?
|
|
6029
|
+
var useIsoLayoutEffect2 = typeof window === "undefined" ? import_react14.useEffect : import_react14.useLayoutEffect;
|
|
5061
6030
|
var userActivation = () => typeof navigator === "undefined" ? void 0 : navigator.userActivation?.isActive;
|
|
5062
6031
|
var silentSandboxes = /* @__PURE__ */ new Set();
|
|
5063
6032
|
var warned = /* @__PURE__ */ new Set();
|
|
@@ -5090,36 +6059,36 @@ var McpAppFrame = ({
|
|
|
5090
6059
|
className
|
|
5091
6060
|
}) => {
|
|
5092
6061
|
const L = useLabels(labels);
|
|
5093
|
-
const [collapsed, setCollapsed] = (0,
|
|
5094
|
-
const [menu, setMenu] = (0,
|
|
5095
|
-
const [reload, setReload] = (0,
|
|
5096
|
-
const [loaded, setLoaded] = (0,
|
|
5097
|
-
const [height, setHeight] = (0,
|
|
5098
|
-
const [calls, setCalls] = (0,
|
|
5099
|
-
const [fallback, setFallback] = (0,
|
|
5100
|
-
const [broken, setBroken] = (0,
|
|
5101
|
-
const [onOrigin, setOnOrigin] = (0,
|
|
5102
|
-
const shellLoaded = (0,
|
|
5103
|
-
const [mode, setMode] = (0,
|
|
5104
|
-
const modeRef = (0,
|
|
5105
|
-
const [holder, setHolder] = (0,
|
|
5106
|
-
const [fullRect, setFullRect] = (0,
|
|
5107
|
-
const leaveRef = (0,
|
|
5108
|
-
const rootRef = (0,
|
|
5109
|
-
const exitRef = (0,
|
|
5110
|
-
const allowFullscreenRef = (0,
|
|
6062
|
+
const [collapsed, setCollapsed] = (0, import_react14.useState)(defaultCollapsed);
|
|
6063
|
+
const [menu, setMenu] = (0, import_react14.useState)(false);
|
|
6064
|
+
const [reload, setReload] = (0, import_react14.useState)(0);
|
|
6065
|
+
const [loaded, setLoaded] = (0, import_react14.useState)();
|
|
6066
|
+
const [height, setHeight] = (0, import_react14.useState)(APP_DEFAULT_HEIGHT);
|
|
6067
|
+
const [calls, setCalls] = (0, import_react14.useState)([]);
|
|
6068
|
+
const [fallback, setFallback] = (0, import_react14.useState)();
|
|
6069
|
+
const [broken, setBroken] = (0, import_react14.useState)(false);
|
|
6070
|
+
const [onOrigin, setOnOrigin] = (0, import_react14.useState)(false);
|
|
6071
|
+
const shellLoaded = (0, import_react14.useRef)(void 0);
|
|
6072
|
+
const [mode, setMode] = (0, import_react14.useState)("inline");
|
|
6073
|
+
const modeRef = (0, import_react14.useRef)("inline");
|
|
6074
|
+
const [holder, setHolder] = (0, import_react14.useState)(0);
|
|
6075
|
+
const [fullRect, setFullRect] = (0, import_react14.useState)();
|
|
6076
|
+
const leaveRef = (0, import_react14.useRef)(void 0);
|
|
6077
|
+
const rootRef = (0, import_react14.useRef)(null);
|
|
6078
|
+
const exitRef = (0, import_react14.useRef)(null);
|
|
6079
|
+
const allowFullscreenRef = (0, import_react14.useRef)(allowFullscreen);
|
|
5111
6080
|
allowFullscreenRef.current = allowFullscreen;
|
|
5112
|
-
const iframeRef = (0,
|
|
5113
|
-
const bridgeRef = (0,
|
|
5114
|
-
const menuRef = (0,
|
|
5115
|
-
const themeRef = (0,
|
|
6081
|
+
const iframeRef = (0, import_react14.useRef)(null);
|
|
6082
|
+
const bridgeRef = (0, import_react14.useRef)(void 0);
|
|
6083
|
+
const menuRef = (0, import_react14.useRef)(null);
|
|
6084
|
+
const themeRef = (0, import_react14.useRef)(theme);
|
|
5116
6085
|
themeRef.current = theme;
|
|
5117
|
-
const hostRef = (0,
|
|
6086
|
+
const hostRef = (0, import_react14.useRef)(host);
|
|
5118
6087
|
hostRef.current = host;
|
|
5119
|
-
const appRef = (0,
|
|
6088
|
+
const appRef = (0, import_react14.useRef)(app);
|
|
5120
6089
|
appRef.current = app;
|
|
5121
6090
|
const live = !collapsed;
|
|
5122
|
-
(0,
|
|
6091
|
+
(0, import_react14.useEffect)(() => {
|
|
5123
6092
|
if (!live) return;
|
|
5124
6093
|
if (!hostRef.current.connected) {
|
|
5125
6094
|
setLoaded({ unavailable: true });
|
|
@@ -5142,7 +6111,7 @@ var McpAppFrame = ({
|
|
|
5142
6111
|
const resource = loaded && "resource" in loaded ? loaded.resource : void 0;
|
|
5143
6112
|
const sandboxUrl = host.sandbox?.url;
|
|
5144
6113
|
const timeoutMs = host.sandbox?.timeoutMs ?? MCP_APP_SANDBOX_TIMEOUT_MS;
|
|
5145
|
-
const placement = (0,
|
|
6114
|
+
const placement = (0, import_react14.useMemo)(() => {
|
|
5146
6115
|
if (!resource) return void 0;
|
|
5147
6116
|
if (sandboxUrl === void 0) return { mode: "opaque" };
|
|
5148
6117
|
if (fallback) return { mode: "opaque", reason: fallback };
|
|
@@ -5153,11 +6122,11 @@ var McpAppFrame = ({
|
|
|
5153
6122
|
if (!url) return { mode: "opaque", reason: "too-many-origins" };
|
|
5154
6123
|
return { mode: "origin", origin: target.origin, url };
|
|
5155
6124
|
}, [resource, sandboxUrl, fallback, app.server, reload]);
|
|
5156
|
-
const doc = (0,
|
|
6125
|
+
const doc = (0, import_react14.useMemo)(
|
|
5157
6126
|
() => !resource || !placement ? void 0 : placement.mode === "origin" ? buildMcpAppSandboxShell(placement.url) : buildMcpAppDocument(resource.html, resource.csp),
|
|
5158
6127
|
[resource, placement]
|
|
5159
6128
|
);
|
|
5160
|
-
(0,
|
|
6129
|
+
(0, import_react14.useEffect)(() => {
|
|
5161
6130
|
const reason = placement?.mode === "opaque" ? placement.reason : void 0;
|
|
5162
6131
|
if (reason && reason !== "no-answer" && sandboxUrl !== void 0) {
|
|
5163
6132
|
warnOnce(
|
|
@@ -5166,7 +6135,7 @@ var McpAppFrame = ({
|
|
|
5166
6135
|
);
|
|
5167
6136
|
}
|
|
5168
6137
|
}, [placement, sandboxUrl]);
|
|
5169
|
-
(0,
|
|
6138
|
+
(0, import_react14.useEffect)(() => {
|
|
5170
6139
|
const frame = iframeRef.current;
|
|
5171
6140
|
if (!live || !resource || !frame || !placement || broken) return;
|
|
5172
6141
|
const abort = new AbortController();
|
|
@@ -5311,7 +6280,7 @@ var McpAppFrame = ({
|
|
|
5311
6280
|
}, [live, resource, reload, variant, app.id, placement, broken, timeoutMs]);
|
|
5312
6281
|
const fullscreen = mode === "fullscreen" && live && !broken;
|
|
5313
6282
|
const waitingNow = host.isWaiting(app);
|
|
5314
|
-
(0,
|
|
6283
|
+
(0, import_react14.useEffect)(() => {
|
|
5315
6284
|
if (fullscreen && waitingNow) leaveRef.current?.();
|
|
5316
6285
|
}, [fullscreen, waitingNow]);
|
|
5317
6286
|
useIsoLayoutEffect2(() => {
|
|
@@ -5346,7 +6315,7 @@ var McpAppFrame = ({
|
|
|
5346
6315
|
ro?.disconnect();
|
|
5347
6316
|
};
|
|
5348
6317
|
}, [fullscreen]);
|
|
5349
|
-
(0,
|
|
6318
|
+
(0, import_react14.useEffect)(() => {
|
|
5350
6319
|
if (!fullscreen) return;
|
|
5351
6320
|
const before = document.activeElement;
|
|
5352
6321
|
exitRef.current?.focus();
|
|
@@ -5363,10 +6332,10 @@ var McpAppFrame = ({
|
|
|
5363
6332
|
if (frame && (before === frame || document.activeElement === document.body)) frame.focus();
|
|
5364
6333
|
};
|
|
5365
6334
|
}, [fullscreen]);
|
|
5366
|
-
(0,
|
|
6335
|
+
(0, import_react14.useEffect)(() => {
|
|
5367
6336
|
if (theme) bridgeRef.current?.updateContext({ theme });
|
|
5368
6337
|
}, [theme]);
|
|
5369
|
-
(0,
|
|
6338
|
+
(0, import_react14.useEffect)(() => {
|
|
5370
6339
|
if (!menu) return;
|
|
5371
6340
|
const close = (e) => {
|
|
5372
6341
|
if (e instanceof KeyboardEvent ? e.key === "Escape" : !menuRef.current?.contains(e.target)) {
|
|
@@ -5671,7 +6640,7 @@ var McpAppLine = ({ app, note, action, onAction, labels, className }) => {
|
|
|
5671
6640
|
};
|
|
5672
6641
|
|
|
5673
6642
|
// src/components/AgentComposer.tsx
|
|
5674
|
-
var
|
|
6643
|
+
var import_react15 = require("react");
|
|
5675
6644
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
5676
6645
|
var thinkingDefaults = (l) => [
|
|
5677
6646
|
{ id: "off", label: l.thinkingLevels.off },
|
|
@@ -5683,7 +6652,7 @@ var thinkingDefaults = (l) => [
|
|
|
5683
6652
|
var MODES = ["autopilot", "ask-writes", "ask-all", "read-only"];
|
|
5684
6653
|
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 });
|
|
5685
6654
|
var useMenuKeys = (open, menuRef, chipRef, close) => {
|
|
5686
|
-
(0,
|
|
6655
|
+
(0, import_react15.useEffect)(() => {
|
|
5687
6656
|
if (!open) return;
|
|
5688
6657
|
const menu = menuRef.current;
|
|
5689
6658
|
const rows = menu ? [...menu.querySelectorAll('[role^="menuitem"]')] : [];
|
|
@@ -5711,9 +6680,9 @@ var useMenuKeys = (open, menuRef, chipRef, close) => {
|
|
|
5711
6680
|
};
|
|
5712
6681
|
var opensMenu = (key) => key === "ArrowDown" || key === "ArrowUp";
|
|
5713
6682
|
var attachSeq = 0;
|
|
5714
|
-
var useIsoLayoutEffect3 = typeof window === "undefined" ?
|
|
6683
|
+
var useIsoLayoutEffect3 = typeof window === "undefined" ? import_react15.useEffect : import_react15.useLayoutEffect;
|
|
5715
6684
|
var useMenuPlacement = (open, anchor, align) => {
|
|
5716
|
-
const [style, setStyle] = (0,
|
|
6685
|
+
const [style, setStyle] = (0, import_react15.useState)();
|
|
5717
6686
|
useIsoLayoutEffect3(() => {
|
|
5718
6687
|
if (!open) return;
|
|
5719
6688
|
const place = () => {
|
|
@@ -5774,6 +6743,7 @@ var AgentComposer = ({
|
|
|
5774
6743
|
files: vfs,
|
|
5775
6744
|
dropZone = "self",
|
|
5776
6745
|
speech = true,
|
|
6746
|
+
voiceMessage = false,
|
|
5777
6747
|
showTimer = true,
|
|
5778
6748
|
showAgents = true,
|
|
5779
6749
|
showApprovalMode = true,
|
|
@@ -5791,41 +6761,52 @@ var AgentComposer = ({
|
|
|
5791
6761
|
const L = useLabels(labelsOverride);
|
|
5792
6762
|
const MODE_CHIP = L.modes;
|
|
5793
6763
|
const DEFAULT_THINKING = thinkingDefaults(L);
|
|
5794
|
-
const [text2, setText] = (0,
|
|
5795
|
-
const [pending, setPendingState] = (0,
|
|
5796
|
-
const pendingRef = (0,
|
|
6764
|
+
const [text2, setText] = (0, import_react15.useState)("");
|
|
6765
|
+
const [pending, setPendingState] = (0, import_react15.useState)([]);
|
|
6766
|
+
const pendingRef = (0, import_react15.useRef)([]);
|
|
5797
6767
|
const setPending = (next) => {
|
|
5798
6768
|
pendingRef.current = typeof next === "function" ? next(pendingRef.current) : next;
|
|
5799
6769
|
setPendingState(pendingRef.current);
|
|
5800
6770
|
};
|
|
5801
|
-
const [menu, setMenu] = (0,
|
|
5802
|
-
const [active, setActive] = (0,
|
|
5803
|
-
const [dismissed, setDismissed] = (0,
|
|
5804
|
-
const [attachError, setAttachError] = (0,
|
|
5805
|
-
const [dragging, setDragging] = (0,
|
|
5806
|
-
const rootRef = (0,
|
|
5807
|
-
const modelRef = (0,
|
|
5808
|
-
const modeRef = (0,
|
|
5809
|
-
const modelChipRef = (0,
|
|
5810
|
-
const modeChipRef = (0,
|
|
5811
|
-
const modelMenuRef = (0,
|
|
5812
|
-
const modeMenuRef = (0,
|
|
5813
|
-
const [dropRect, setDropRect] = (0,
|
|
5814
|
-
const [compactBar, setCompactBar] = (0,
|
|
5815
|
-
(0,
|
|
6771
|
+
const [menu, setMenu] = (0, import_react15.useState)(void 0);
|
|
6772
|
+
const [active, setActive] = (0, import_react15.useState)(0);
|
|
6773
|
+
const [dismissed, setDismissed] = (0, import_react15.useState)(() => /* @__PURE__ */ new Set());
|
|
6774
|
+
const [attachError, setAttachError] = (0, import_react15.useState)();
|
|
6775
|
+
const [dragging, setDragging] = (0, import_react15.useState)(false);
|
|
6776
|
+
const rootRef = (0, import_react15.useRef)(null);
|
|
6777
|
+
const modelRef = (0, import_react15.useRef)(null);
|
|
6778
|
+
const modeRef = (0, import_react15.useRef)(null);
|
|
6779
|
+
const modelChipRef = (0, import_react15.useRef)(null);
|
|
6780
|
+
const modeChipRef = (0, import_react15.useRef)(null);
|
|
6781
|
+
const modelMenuRef = (0, import_react15.useRef)(null);
|
|
6782
|
+
const modeMenuRef = (0, import_react15.useRef)(null);
|
|
6783
|
+
const [dropRect, setDropRect] = (0, import_react15.useState)();
|
|
6784
|
+
const [compactBar, setCompactBar] = (0, import_react15.useState)(false);
|
|
6785
|
+
const [barWidth, setBarWidth] = (0, import_react15.useState)(0);
|
|
6786
|
+
(0, import_react15.useEffect)(() => {
|
|
5816
6787
|
const el = rootRef.current;
|
|
5817
6788
|
if (!el || typeof ResizeObserver === "undefined") return;
|
|
5818
|
-
const ro = new ResizeObserver(
|
|
5819
|
-
|
|
5820
|
-
|
|
6789
|
+
const ro = new ResizeObserver(() => {
|
|
6790
|
+
const width = el.getBoundingClientRect().width;
|
|
6791
|
+
setCompactBar(width < compactWidth);
|
|
6792
|
+
setBarWidth(Math.round(width));
|
|
6793
|
+
});
|
|
5821
6794
|
ro.observe(el);
|
|
5822
6795
|
return () => ro.disconnect();
|
|
5823
6796
|
}, [compactWidth]);
|
|
5824
|
-
const
|
|
5825
|
-
const
|
|
6797
|
+
const chipLabelRef = (0, import_react15.useRef)(null);
|
|
6798
|
+
const [chipShort, setChipShort] = (0, import_react15.useState)(false);
|
|
6799
|
+
(0, import_react15.useLayoutEffect)(() => setChipShort(false), [barWidth, model?.label, model?.shortLabel]);
|
|
6800
|
+
(0, import_react15.useLayoutEffect)(() => {
|
|
6801
|
+
const el = chipLabelRef.current;
|
|
6802
|
+
if (chipShort || !el || !model?.shortLabel) return;
|
|
6803
|
+
if (el.scrollWidth > el.clientWidth + 1) setChipShort(true);
|
|
6804
|
+
});
|
|
6805
|
+
const fileRef = (0, import_react15.useRef)(null);
|
|
6806
|
+
const inputRef = (0, import_react15.useRef)(null);
|
|
5826
6807
|
const draftId = draft?.id;
|
|
5827
6808
|
const draftText = draft?.text;
|
|
5828
|
-
(0,
|
|
6809
|
+
(0, import_react15.useEffect)(() => {
|
|
5829
6810
|
if (draftId === void 0 || !draftText) return;
|
|
5830
6811
|
setText((t) => t.trim() ? `${t.trimEnd()}
|
|
5831
6812
|
${draftText}` : draftText);
|
|
@@ -5839,13 +6820,20 @@ ${draftText}` : draftText);
|
|
|
5839
6820
|
const caps = agent.agent?.capabilities;
|
|
5840
6821
|
const stt = useSpeechToText({
|
|
5841
6822
|
lang: typeof speech === "object" ? speech.lang : void 0,
|
|
6823
|
+
createRecognizer: typeof speech === "object" ? speech.createRecognizer : void 0,
|
|
5842
6824
|
onFinal: (heard) => setText((t) => t.trim() ? `${t.trimEnd()} ${heard}` : heard)
|
|
5843
6825
|
});
|
|
5844
6826
|
const showMic = speech !== false && stt.supported;
|
|
5845
|
-
const
|
|
5846
|
-
|
|
5847
|
-
|
|
5848
|
-
|
|
6827
|
+
const recorder = useAudioRecorder({
|
|
6828
|
+
maxMs: typeof voiceMessage === "object" ? voiceMessage.maxMs : void 0
|
|
6829
|
+
});
|
|
6830
|
+
const showVoice = voiceMessage !== false && attachments !== false && recorder.supported;
|
|
6831
|
+
const recordingOn = recorder.state !== "idle";
|
|
6832
|
+
const [voiceNote, setVoiceNote] = (0, import_react15.useState)();
|
|
6833
|
+
const [startedAt, setStartedAt] = (0, import_react15.useState)();
|
|
6834
|
+
const [now, setNow] = (0, import_react15.useState)(() => Date.now());
|
|
6835
|
+
const [lastElapsed, setLastElapsed] = (0, import_react15.useState)();
|
|
6836
|
+
(0, import_react15.useEffect)(() => {
|
|
5849
6837
|
if (!busy) {
|
|
5850
6838
|
if (startedAt !== void 0) setLastElapsed(Date.now() - startedAt);
|
|
5851
6839
|
setStartedAt(void 0);
|
|
@@ -5858,7 +6846,7 @@ ${draftText}` : draftText);
|
|
|
5858
6846
|
return () => clearInterval(id);
|
|
5859
6847
|
}, [busy]);
|
|
5860
6848
|
const elapsed = startedAt !== void 0 ? now - startedAt : lastElapsed;
|
|
5861
|
-
const allCommands = (0,
|
|
6849
|
+
const allCommands = (0, import_react15.useMemo)(() => {
|
|
5862
6850
|
const out = [];
|
|
5863
6851
|
if (builtinCommands) {
|
|
5864
6852
|
out.push(
|
|
@@ -5941,8 +6929,8 @@ ${draftText}` : draftText);
|
|
|
5941
6929
|
const closeMenu = () => setMenu(void 0);
|
|
5942
6930
|
const modelMenuKeys = useMenuKeys(menu === "model", modelMenuRef, modelChipRef, closeMenu);
|
|
5943
6931
|
const modeMenuKeys = useMenuKeys(menu === "mode", modeMenuRef, modeChipRef, closeMenu);
|
|
5944
|
-
(0,
|
|
5945
|
-
(0,
|
|
6932
|
+
(0, import_react15.useEffect)(() => setActive(0), [text2, menu]);
|
|
6933
|
+
(0, import_react15.useEffect)(() => {
|
|
5946
6934
|
if (!menu) return;
|
|
5947
6935
|
const onDown = (e) => {
|
|
5948
6936
|
if (!rootRef.current?.contains(e.target)) setMenu(void 0);
|
|
@@ -6069,6 +7057,44 @@ ${draftText}` : draftText);
|
|
|
6069
7057
|
setAttachError(said.filter(Boolean).join(" ") || void 0);
|
|
6070
7058
|
if (fileRef.current) fileRef.current.value = "";
|
|
6071
7059
|
};
|
|
7060
|
+
const addRecording = async (audio) => {
|
|
7061
|
+
if (audio.blob.size === 0) return;
|
|
7062
|
+
const name = voiceMessageName(/* @__PURE__ */ new Date(), audioExtensionOf(audio.mediaType));
|
|
7063
|
+
const over = attachmentOverLimit({ bytes: audio.blob.size }, "sent", "none", bounds);
|
|
7064
|
+
if (over) {
|
|
7065
|
+
setAttachError(overLimitText(L.voiceMessage, over));
|
|
7066
|
+
return;
|
|
7067
|
+
}
|
|
7068
|
+
const a = {
|
|
7069
|
+
id: `att-${attachSeq += 1}`,
|
|
7070
|
+
name,
|
|
7071
|
+
kind: "file",
|
|
7072
|
+
mediaType: audio.mediaType,
|
|
7073
|
+
dataUrl: await readDataUrl2(audio.blob),
|
|
7074
|
+
bytes: audio.blob.size,
|
|
7075
|
+
durationMs: audio.durationMs,
|
|
7076
|
+
note: L.audioDuration(formatClock(audio.durationMs))
|
|
7077
|
+
};
|
|
7078
|
+
if (messageOverLimit(pendingRef.current, a, bounds) === "bytes") {
|
|
7079
|
+
setAttachError(
|
|
7080
|
+
L.messageTooLarge(L.voiceMessage, Math.round(bounds.maxTotalBytes / 1024 / 1024))
|
|
7081
|
+
);
|
|
7082
|
+
return;
|
|
7083
|
+
}
|
|
7084
|
+
setPending((cur) => [...cur, a]);
|
|
7085
|
+
};
|
|
7086
|
+
const finishRecording = async () => {
|
|
7087
|
+
const audio = await recorder.stop();
|
|
7088
|
+
if (audio) await addRecording(audio);
|
|
7089
|
+
inputRef.current?.focus();
|
|
7090
|
+
};
|
|
7091
|
+
const limited = recorder.limited;
|
|
7092
|
+
(0, import_react15.useEffect)(() => {
|
|
7093
|
+
if (!limited) return;
|
|
7094
|
+
recorder.clear();
|
|
7095
|
+
setVoiceNote(L.recordingLimit);
|
|
7096
|
+
void addRecording(limited);
|
|
7097
|
+
}, [limited]);
|
|
6072
7098
|
const onPaste = (e) => {
|
|
6073
7099
|
if (attachments === false) return;
|
|
6074
7100
|
const pasted = Array.from(e.clipboardData?.files ?? []);
|
|
@@ -6076,9 +7102,9 @@ ${draftText}` : draftText);
|
|
|
6076
7102
|
e.preventDefault();
|
|
6077
7103
|
void addFiles(pasted);
|
|
6078
7104
|
};
|
|
6079
|
-
const addFilesRef = (0,
|
|
7105
|
+
const addFilesRef = (0, import_react15.useRef)(addFiles);
|
|
6080
7106
|
addFilesRef.current = addFiles;
|
|
6081
|
-
(0,
|
|
7107
|
+
(0, import_react15.useEffect)(() => {
|
|
6082
7108
|
if (attachments === false) return;
|
|
6083
7109
|
const target = dropZone === "window" ? globalThis.window : dropZone === "self" ? rootRef.current : dropZone.current;
|
|
6084
7110
|
if (!target) return;
|
|
@@ -6200,10 +7226,11 @@ ${draftText}` : draftText);
|
|
|
6200
7226
|
mediaType: a.mediaType,
|
|
6201
7227
|
size: a.bytes,
|
|
6202
7228
|
...a.kind === "image" && a.dataUrl ? { dataUrl: a.dataUrl } : {},
|
|
6203
|
-
...a.path ? { path: a.path } : {}
|
|
7229
|
+
...a.path ? { path: a.path } : {},
|
|
7230
|
+
...a.durationMs !== void 0 ? { durationMs: a.durationMs } : {}
|
|
6204
7231
|
}));
|
|
6205
7232
|
const full = withAttachments(goal || L.seeAttachments, items);
|
|
6206
|
-
const label = shown
|
|
7233
|
+
const label = shown;
|
|
6207
7234
|
void agent.run(full, {
|
|
6208
7235
|
...full !== label ? { label } : {},
|
|
6209
7236
|
images: items.filter((a) => a.kind === "image" && a.dataUrl).map(toModel),
|
|
@@ -6244,23 +7271,31 @@ ${draftText}` : draftText);
|
|
|
6244
7271
|
...attachError ? [{ id: `attach:${attachError}`, tone: "warn", text: attachError }] : [],
|
|
6245
7272
|
...stt.error ? [
|
|
6246
7273
|
{
|
|
6247
|
-
id: `stt:${stt.error}`,
|
|
7274
|
+
id: `stt:${stt.error}:${stt.errorMessage ?? ""}`,
|
|
6248
7275
|
tone: "warn",
|
|
6249
|
-
text:
|
|
7276
|
+
text: micProblemText(stt.error, stt.errorMessage, L)
|
|
6250
7277
|
}
|
|
6251
|
-
] : []
|
|
7278
|
+
] : [],
|
|
7279
|
+
...recorder.error ? [
|
|
7280
|
+
{
|
|
7281
|
+
id: `rec:${recorder.error}`,
|
|
7282
|
+
tone: "warn",
|
|
7283
|
+
text: micProblemText(recorder.error, void 0, L)
|
|
7284
|
+
}
|
|
7285
|
+
] : [],
|
|
7286
|
+
...voiceNote ? [{ id: `voice:${voiceNote}`, tone: "info", text: voiceNote }] : []
|
|
6252
7287
|
].filter((n) => !dismissed.has(n.id)) : [];
|
|
6253
7288
|
const runningAgents = agent.subagents.filter((s) => s.status === "running");
|
|
6254
7289
|
const thinkingOptions = thinking?.options ?? DEFAULT_THINKING;
|
|
6255
7290
|
const thinkingLabel = thinking ? thinkingOptions.find((o) => o.id === thinking.value)?.label ?? thinking.value : void 0;
|
|
6256
|
-
const canSend = ready && (text2.trim().length > 0 || pending.length > 0);
|
|
7291
|
+
const canSend = ready && !recordingOn && (text2.trim().length > 0 || pending.length > 0);
|
|
6257
7292
|
const canSteer = busy && steering && text2.trim().length > 0;
|
|
6258
7293
|
const queuedStrip = showQueued && (agent.queued.length > 0 || agent.undelivered.length > 0) ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "awr-queued", children: [
|
|
6259
7294
|
agent.queued.map((q) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "awr-queued__item", role: "status", children: [
|
|
6260
7295
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ClockIcon, { size: 13, className: "awr-queued__icon" }),
|
|
6261
7296
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-queued__text", title: q.text, children: q.text }),
|
|
6262
7297
|
q.origin === "another-tab" && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-queued__origin", children: L.fromAnotherTab }),
|
|
6263
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-queued__state", children: q.session ? L.queuedForSession(q.session) : L.queuedWaiting })
|
|
7298
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-queued__state", children: q.sentTo ? L.queuedForOtherTab : q.session ? L.queuedForSession(q.session) : L.queuedWaiting })
|
|
6264
7299
|
] }, q.id)),
|
|
6265
7300
|
agent.undelivered.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "awr-queued__item awr-queued__item--undelivered", role: "status", children: [
|
|
6266
7301
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(AlertIcon, { size: 13, className: "awr-queued__icon" }),
|
|
@@ -6297,6 +7332,8 @@ ${draftText}` : draftText);
|
|
|
6297
7332
|
onClick: () => {
|
|
6298
7333
|
setDismissed((d) => new Set(d).add(n.id));
|
|
6299
7334
|
if (n.id.startsWith("attach:")) setAttachError(void 0);
|
|
7335
|
+
if (n.id.startsWith("rec:")) recorder.clear();
|
|
7336
|
+
if (n.id.startsWith("voice:")) setVoiceNote(void 0);
|
|
6300
7337
|
},
|
|
6301
7338
|
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(XIcon, { size: 14 })
|
|
6302
7339
|
}
|
|
@@ -6334,7 +7371,7 @@ ${draftText}` : draftText);
|
|
|
6334
7371
|
const remove = () => setPending((cur) => cur.filter((x) => x.id !== a.id));
|
|
6335
7372
|
if (renderAttachment) return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: renderAttachment(a, remove) }, a.id);
|
|
6336
7373
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "awr-chip awr-file", title: a.note ?? a.mediaType, children: [
|
|
6337
|
-
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 }),
|
|
7374
|
+
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 }),
|
|
6338
7375
|
a.note ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "awr-file__text", children: [
|
|
6339
7376
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-file__name", children: a.name }),
|
|
6340
7377
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-file__note", children: a.note })
|
|
@@ -6351,6 +7388,33 @@ ${draftText}` : draftText);
|
|
|
6351
7388
|
)
|
|
6352
7389
|
] }, a.id);
|
|
6353
7390
|
}) }),
|
|
7391
|
+
showVoice && recordingOn && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "awr-recording", role: "status", "aria-live": "polite", children: [
|
|
7392
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-recording__dot", "aria-hidden": "true" }),
|
|
7393
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-recording__time", children: L.recording(formatClock(recorder.elapsedMs)) }),
|
|
7394
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
7395
|
+
"button",
|
|
7396
|
+
{
|
|
7397
|
+
type: "button",
|
|
7398
|
+
className: "awr-iconbtn",
|
|
7399
|
+
"aria-label": L.recordingCancel,
|
|
7400
|
+
title: L.recordingCancel,
|
|
7401
|
+
onClick: recorder.cancel,
|
|
7402
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(XIcon, { size: 16 })
|
|
7403
|
+
}
|
|
7404
|
+
),
|
|
7405
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
7406
|
+
"button",
|
|
7407
|
+
{
|
|
7408
|
+
type: "button",
|
|
7409
|
+
className: "awr-iconbtn awr-recording__done",
|
|
7410
|
+
"aria-label": L.recordingDone,
|
|
7411
|
+
title: L.recordingDone,
|
|
7412
|
+
onClick: () => void finishRecording(),
|
|
7413
|
+
disabled: recorder.state !== "recording",
|
|
7414
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CheckIcon, { size: 16 })
|
|
7415
|
+
}
|
|
7416
|
+
)
|
|
7417
|
+
] }),
|
|
6354
7418
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "awr-composer2__inputrow", children: [
|
|
6355
7419
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
6356
7420
|
"textarea",
|
|
@@ -6361,7 +7425,7 @@ ${draftText}` : draftText);
|
|
|
6361
7425
|
onChange: (e) => setText(e.target.value),
|
|
6362
7426
|
onKeyDown,
|
|
6363
7427
|
onPaste,
|
|
6364
|
-
placeholder: stt.listening ? L.listening : busy && steering ? L.placeholderBusy : placeholder ?? L.placeholder,
|
|
7428
|
+
placeholder: stt.finishing ? L.transcribing : stt.listening ? L.listening : busy && steering ? L.placeholderBusy : placeholder ?? L.placeholder,
|
|
6365
7429
|
disabled,
|
|
6366
7430
|
rows: 2,
|
|
6367
7431
|
"aria-label": L.message
|
|
@@ -6371,16 +7435,18 @@ ${draftText}` : draftText);
|
|
|
6371
7435
|
"button",
|
|
6372
7436
|
{
|
|
6373
7437
|
type: "button",
|
|
6374
|
-
className: `awr-iconbtn awr-mic${stt.listening ? " is-on" : ""}`,
|
|
7438
|
+
className: `awr-iconbtn awr-mic${stt.listening ? " is-on" : ""}${stt.finishing ? " is-busy" : ""}`,
|
|
6375
7439
|
"aria-label": stt.listening ? L.stopDictation : L.dictate,
|
|
7440
|
+
"aria-pressed": stt.listening,
|
|
6376
7441
|
title: stt.listening ? L.stopDictation : L.dictateTitle,
|
|
6377
7442
|
onClick: stt.toggle,
|
|
6378
|
-
disabled,
|
|
6379
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(MicIcon, { size: 18 })
|
|
7443
|
+
disabled: disabled || recordingOn || stt.finishing,
|
|
7444
|
+
children: stt.finishing ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SpinnerIcon, { size: 18 }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(MicIcon, { size: 18 })
|
|
6380
7445
|
}
|
|
6381
7446
|
)
|
|
6382
7447
|
] }),
|
|
6383
7448
|
stt.listening && stt.interim && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "awr-composer2__interim", children: stt.interim }),
|
|
7449
|
+
stt.finishing && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "awr-composer2__interim", role: "status", children: L.transcribing }),
|
|
6384
7450
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "awr-toolbar", children: [
|
|
6385
7451
|
attachments !== false && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
6386
7452
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
@@ -6395,6 +7461,22 @@ ${draftText}` : draftText);
|
|
|
6395
7461
|
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(PlusIcon, { size: 18 })
|
|
6396
7462
|
}
|
|
6397
7463
|
),
|
|
7464
|
+
showVoice && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
7465
|
+
"button",
|
|
7466
|
+
{
|
|
7467
|
+
type: "button",
|
|
7468
|
+
className: `awr-iconbtn awr-voicebtn${recordingOn ? " is-on" : ""}`,
|
|
7469
|
+
"aria-label": L.recordVoiceMessage,
|
|
7470
|
+
title: L.recordVoiceMessage,
|
|
7471
|
+
"aria-pressed": recordingOn,
|
|
7472
|
+
onClick: () => {
|
|
7473
|
+
setVoiceNote(void 0);
|
|
7474
|
+
void recorder.start();
|
|
7475
|
+
},
|
|
7476
|
+
disabled: disabled || recordingOn || stt.listening,
|
|
7477
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(WaveIcon, { size: 18 })
|
|
7478
|
+
}
|
|
7479
|
+
),
|
|
6398
7480
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
6399
7481
|
"input",
|
|
6400
7482
|
{
|
|
@@ -6419,7 +7501,7 @@ ${draftText}` : draftText);
|
|
|
6419
7501
|
}
|
|
6420
7502
|
),
|
|
6421
7503
|
toolbarExtra,
|
|
6422
|
-
showTimer && elapsed !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "awr-tchip", title: busy ? L.timerRunning : L.timerLast, children: [
|
|
7504
|
+
showTimer && elapsed !== void 0 && (busy || !compactBar) && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "awr-tchip", title: busy ? L.timerRunning : L.timerLast, children: [
|
|
6423
7505
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ClockIcon, { size: 14 }),
|
|
6424
7506
|
" ",
|
|
6425
7507
|
formatElapsed(elapsed)
|
|
@@ -6455,7 +7537,7 @@ ${draftText}` : draftText);
|
|
|
6455
7537
|
"aria-expanded": menu === "model",
|
|
6456
7538
|
title: [model?.label, thinkingLabel].filter(Boolean).join(" \xB7 "),
|
|
6457
7539
|
children: [
|
|
6458
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-tchip__label", children: model?.label
|
|
7540
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-tchip__label", ref: chipLabelRef, children: chipShort && model?.shortLabel || model?.label || L.model }),
|
|
6459
7541
|
thinkingLabel && !compactBar && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-tchip__sub", children: thinkingLabel })
|
|
6460
7542
|
]
|
|
6461
7543
|
}
|
|
@@ -6529,7 +7611,7 @@ ${draftText}` : draftText);
|
|
|
6529
7611
|
},
|
|
6530
7612
|
`s${i}`
|
|
6531
7613
|
);
|
|
6532
|
-
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)(
|
|
7614
|
+
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}`);
|
|
6533
7615
|
})
|
|
6534
7616
|
] }) : null
|
|
6535
7617
|
]
|
|
@@ -6624,7 +7706,7 @@ ${draftText}` : draftText);
|
|
|
6624
7706
|
};
|
|
6625
7707
|
|
|
6626
7708
|
// src/components/ChatHistoryList.tsx
|
|
6627
|
-
var
|
|
7709
|
+
var import_react16 = require("react");
|
|
6628
7710
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
6629
7711
|
var defaultTime = (ms) => {
|
|
6630
7712
|
const d = new Date(ms);
|
|
@@ -6694,7 +7776,7 @@ var ChatHistoryList = ({
|
|
|
6694
7776
|
}
|
|
6695
7777
|
)
|
|
6696
7778
|
] }, c.id);
|
|
6697
|
-
return renderChat ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
7779
|
+
return renderChat ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react16.Fragment, { children: renderChat(c, active, row) }, c.id) : row;
|
|
6698
7780
|
}) })
|
|
6699
7781
|
] });
|
|
6700
7782
|
};
|
|
@@ -6860,7 +7942,7 @@ var ContextMeter = ({
|
|
|
6860
7942
|
};
|
|
6861
7943
|
|
|
6862
7944
|
// src/components/ElicitationPrompt.tsx
|
|
6863
|
-
var
|
|
7945
|
+
var import_react17 = require("react");
|
|
6864
7946
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
6865
7947
|
var reasonText = (outcome, L) => {
|
|
6866
7948
|
const reason = outcome.reason;
|
|
@@ -6870,8 +7952,8 @@ var reasonText = (outcome, L) => {
|
|
|
6870
7952
|
return reason || outcome.status;
|
|
6871
7953
|
};
|
|
6872
7954
|
var useNow = (active) => {
|
|
6873
|
-
const [now, setNow] = (0,
|
|
6874
|
-
(0,
|
|
7955
|
+
const [now, setNow] = (0, import_react17.useState)(() => Date.now());
|
|
7956
|
+
(0, import_react17.useEffect)(() => {
|
|
6875
7957
|
if (!active) return;
|
|
6876
7958
|
setNow(Date.now());
|
|
6877
7959
|
const timer = setInterval(() => setNow(Date.now()), 1e3);
|
|
@@ -6999,11 +8081,11 @@ var FieldControl = ({ field, id, value, issue, onChange, L }) => {
|
|
|
6999
8081
|
] });
|
|
7000
8082
|
};
|
|
7001
8083
|
var FormBody = ({ elicitation, answer, L }) => {
|
|
7002
|
-
const baseId = (0,
|
|
8084
|
+
const baseId = (0, import_react17.useId)();
|
|
7003
8085
|
const schema = elicitation.requestedSchema;
|
|
7004
8086
|
const fields = elicitationFields(schema);
|
|
7005
|
-
const [draft, setDraft] = (0,
|
|
7006
|
-
const [issues, setIssues] = (0,
|
|
8087
|
+
const [draft, setDraft] = (0, import_react17.useState)(() => elicitationInitialDraft(schema));
|
|
8088
|
+
const [issues, setIssues] = (0, import_react17.useState)(void 0);
|
|
7007
8089
|
const fieldId = (i) => `${baseId}-f${i}`;
|
|
7008
8090
|
const submit = (e) => {
|
|
7009
8091
|
e.preventDefault();
|
|
@@ -7058,7 +8140,7 @@ var FormBody = ({ elicitation, answer, L }) => {
|
|
|
7058
8140
|
};
|
|
7059
8141
|
var UrlBody = ({ elicitation, answer, L }) => {
|
|
7060
8142
|
const link = elicitationLink(elicitation.url);
|
|
7061
|
-
const [opened, setOpened] = (0,
|
|
8143
|
+
const [opened, setOpened] = (0, import_react17.useState)(false);
|
|
7062
8144
|
const open = () => {
|
|
7063
8145
|
if (!link.openable || typeof window === "undefined") return;
|
|
7064
8146
|
window.open(link.href, "_blank", "noopener,noreferrer");
|
|
@@ -7122,7 +8204,7 @@ var ElicitationPrompt = ({
|
|
|
7122
8204
|
className
|
|
7123
8205
|
}) => {
|
|
7124
8206
|
const L = useLabels(labels);
|
|
7125
|
-
const [dismissed, setDismissed] = (0,
|
|
8207
|
+
const [dismissed, setDismissed] = (0, import_react17.useState)(() => /* @__PURE__ */ new Set());
|
|
7126
8208
|
const automatic = showOutcomes ? (outcomes ?? []).filter(
|
|
7127
8209
|
(o) => o.automatic === true && o.status !== "pending" && !dismissed.has(o.id)
|
|
7128
8210
|
) : [];
|
|
@@ -7183,21 +8265,21 @@ var ElicitationPrompt = ({
|
|
|
7183
8265
|
};
|
|
7184
8266
|
|
|
7185
8267
|
// src/components/FilesPanel.tsx
|
|
7186
|
-
var
|
|
8268
|
+
var import_react19 = require("react");
|
|
7187
8269
|
|
|
7188
8270
|
// src/components/ImageViewer.tsx
|
|
7189
|
-
var
|
|
8271
|
+
var import_react18 = require("react");
|
|
7190
8272
|
var import_react_dom = require("react-dom");
|
|
7191
8273
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
7192
8274
|
var fileNameOf = (name) => name.split(/[\\/]/).filter(Boolean).pop() ?? name;
|
|
7193
8275
|
var SWIPE_PX = 48;
|
|
7194
8276
|
var ImageViewer = ({ images, index, onIndex, onClose, labels }) => {
|
|
7195
8277
|
const L = useLabels(labels);
|
|
7196
|
-
const rootRef = (0,
|
|
7197
|
-
const closeRef = (0,
|
|
7198
|
-
const imgRef = (0,
|
|
7199
|
-
const touch = (0,
|
|
7200
|
-
const [zoom, setZoom] = (0,
|
|
8278
|
+
const rootRef = (0, import_react18.useRef)(null);
|
|
8279
|
+
const closeRef = (0, import_react18.useRef)(null);
|
|
8280
|
+
const imgRef = (0, import_react18.useRef)(null);
|
|
8281
|
+
const touch = (0, import_react18.useRef)(void 0);
|
|
8282
|
+
const [zoom, setZoom] = (0, import_react18.useState)(void 0);
|
|
7201
8283
|
const count = images.length;
|
|
7202
8284
|
const at = Math.min(Math.max(index, 0), count - 1);
|
|
7203
8285
|
const image = images[at];
|
|
@@ -7206,7 +8288,7 @@ var ImageViewer = ({ images, index, onIndex, onClose, labels }) => {
|
|
|
7206
8288
|
setZoom(void 0);
|
|
7207
8289
|
onIndex((at + step + count) % count);
|
|
7208
8290
|
};
|
|
7209
|
-
(0,
|
|
8291
|
+
(0, import_react18.useEffect)(() => {
|
|
7210
8292
|
closeRef.current?.focus();
|
|
7211
8293
|
const root = document.documentElement;
|
|
7212
8294
|
const before = root.style.overflow;
|
|
@@ -7215,7 +8297,7 @@ var ImageViewer = ({ images, index, onIndex, onClose, labels }) => {
|
|
|
7215
8297
|
root.style.overflow = before;
|
|
7216
8298
|
};
|
|
7217
8299
|
}, []);
|
|
7218
|
-
const keys = (0,
|
|
8300
|
+
const keys = (0, import_react18.useRef)(() => {
|
|
7219
8301
|
});
|
|
7220
8302
|
keys.current = (e) => {
|
|
7221
8303
|
if (e.key === "Escape") {
|
|
@@ -7241,7 +8323,7 @@ var ImageViewer = ({ images, index, onIndex, onClose, labels }) => {
|
|
|
7241
8323
|
}
|
|
7242
8324
|
}
|
|
7243
8325
|
};
|
|
7244
|
-
(0,
|
|
8326
|
+
(0, import_react18.useEffect)(() => {
|
|
7245
8327
|
const onKey = (e) => keys.current(e);
|
|
7246
8328
|
document.addEventListener("keydown", onKey, true);
|
|
7247
8329
|
return () => document.removeEventListener("keydown", onKey, true);
|
|
@@ -7355,7 +8437,7 @@ var ImageViewer = ({ images, index, onIndex, onClose, labels }) => {
|
|
|
7355
8437
|
] })
|
|
7356
8438
|
] });
|
|
7357
8439
|
};
|
|
7358
|
-
var ImageViewerContext = (0,
|
|
8440
|
+
var ImageViewerContext = (0, import_react18.createContext)({ enabled: true });
|
|
7359
8441
|
var ImageViewerProvider = ({
|
|
7360
8442
|
enabled = true,
|
|
7361
8443
|
render,
|
|
@@ -7384,9 +8466,9 @@ var ImageThumb = ({
|
|
|
7384
8466
|
labels
|
|
7385
8467
|
}) => {
|
|
7386
8468
|
const L = useLabels(labels);
|
|
7387
|
-
const { enabled, render } = (0,
|
|
7388
|
-
const ref = (0,
|
|
7389
|
-
const [open, setOpen] = (0,
|
|
8469
|
+
const { enabled, render } = (0, import_react18.useContext)(ImageViewerContext);
|
|
8470
|
+
const ref = (0, import_react18.useRef)(null);
|
|
8471
|
+
const [open, setOpen] = (0, import_react18.useState)(void 0);
|
|
7390
8472
|
const img = /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("img", { className: imgClassName, src, alt });
|
|
7391
8473
|
if (!enabled) {
|
|
7392
8474
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("a", { className, href: src, target: "_blank", rel: "noopener noreferrer", title, children: img });
|
|
@@ -7448,9 +8530,9 @@ var FilesPanel = ({
|
|
|
7448
8530
|
}) => {
|
|
7449
8531
|
const L = useLabels(labels);
|
|
7450
8532
|
const fs = useVirtualFiles(vfs, prefix);
|
|
7451
|
-
const [preview, setPreview] = (0,
|
|
7452
|
-
const inputRef = (0,
|
|
7453
|
-
(0,
|
|
8533
|
+
const [preview, setPreview] = (0, import_react19.useState)();
|
|
8534
|
+
const inputRef = (0, import_react19.useRef)(null);
|
|
8535
|
+
(0, import_react19.useEffect)(() => {
|
|
7454
8536
|
if (preview && !fs.files.some((f) => f.path === preview.path)) setPreview(void 0);
|
|
7455
8537
|
}, [fs.files, preview]);
|
|
7456
8538
|
const open = async (f) => {
|
|
@@ -7551,7 +8633,7 @@ var FilesPanel = ({
|
|
|
7551
8633
|
},
|
|
7552
8634
|
f.path
|
|
7553
8635
|
);
|
|
7554
|
-
return renderFile ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
8636
|
+
return renderFile ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react19.Fragment, { children: renderFile(f, row) }, f.path) : row;
|
|
7555
8637
|
}) }),
|
|
7556
8638
|
preview && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "awr-filepreview", children: preview.kind === "image" ? (
|
|
7557
8639
|
// A click (Enter, Space) opens it over the chat, fitted to the screen.
|
|
@@ -7571,7 +8653,7 @@ var FilesPanel = ({
|
|
|
7571
8653
|
};
|
|
7572
8654
|
|
|
7573
8655
|
// src/components/FileChips.tsx
|
|
7574
|
-
var
|
|
8656
|
+
var import_react21 = require("react");
|
|
7575
8657
|
|
|
7576
8658
|
// src/file-kinds.ts
|
|
7577
8659
|
var import_agent_web6 = require("@dudko.dev/agent-web");
|
|
@@ -7592,7 +8674,7 @@ var fileKindOf = (path, mediaType) => {
|
|
|
7592
8674
|
var fileNameOf2 = (path) => path.split("/").filter(Boolean).pop() || "file";
|
|
7593
8675
|
|
|
7594
8676
|
// src/components/Media.tsx
|
|
7595
|
-
var
|
|
8677
|
+
var import_react20 = require("react");
|
|
7596
8678
|
var import_agent_web7 = require("@dudko.dev/agent-web");
|
|
7597
8679
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
7598
8680
|
var mediaFamilyOf = (mediaType) => {
|
|
@@ -7609,8 +8691,8 @@ var bytesOf = (content, encoding) => {
|
|
|
7609
8691
|
return bytes;
|
|
7610
8692
|
};
|
|
7611
8693
|
var useFileUrl = (files, path, mediaType) => {
|
|
7612
|
-
const [url, setUrl] = (0,
|
|
7613
|
-
(0,
|
|
8694
|
+
const [url, setUrl] = (0, import_react20.useState)(void 0);
|
|
8695
|
+
(0, import_react20.useEffect)(() => {
|
|
7614
8696
|
if (!files || !mediaType) return;
|
|
7615
8697
|
let made;
|
|
7616
8698
|
let gone = false;
|
|
@@ -7794,14 +8876,14 @@ var SourceView = ({
|
|
|
7794
8876
|
const L = useLabels(labels);
|
|
7795
8877
|
const cut = text2.length > maxChars;
|
|
7796
8878
|
const shown = cut ? text2.slice(0, maxChars) : text2;
|
|
7797
|
-
const lines = (0,
|
|
8879
|
+
const lines = (0, import_react21.useMemo)(
|
|
7798
8880
|
() => linesOf(html ? tokenizeHtml(shown) : [{ kind: "text", text: shown }]),
|
|
7799
8881
|
[shown, html]
|
|
7800
8882
|
);
|
|
7801
8883
|
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
|
|
7802
8884
|
/* @__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: [
|
|
7803
8885
|
line.map(
|
|
7804
|
-
(t, k) => t.kind === "text" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
8886
|
+
(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)
|
|
7805
8887
|
),
|
|
7806
8888
|
"\n"
|
|
7807
8889
|
] }, i)) }),
|
|
@@ -7809,16 +8891,16 @@ var SourceView = ({
|
|
|
7809
8891
|
] });
|
|
7810
8892
|
};
|
|
7811
8893
|
var HtmlPreview = ({ written, file, htmlPreview, previewChars, L }) => {
|
|
7812
|
-
const html = (0,
|
|
8894
|
+
const html = (0, import_react21.useMemo)(() => textOf(file), [file]);
|
|
7813
8895
|
const options = htmlPreview === false ? void 0 : htmlPreview;
|
|
7814
8896
|
const tooLarge = html.length > HTML_PREVIEW_MAX_CHARS;
|
|
7815
8897
|
const canFrame = Boolean(options) && !tooLarge;
|
|
7816
|
-
const [view, setView] = (0,
|
|
7817
|
-
const [tall, setTall] = (0,
|
|
8898
|
+
const [view, setView] = (0, import_react21.useState)(canFrame ? "preview" : "source");
|
|
8899
|
+
const [tall, setTall] = (0, import_react21.useState)(false);
|
|
7818
8900
|
const showing = canFrame ? view : "source";
|
|
7819
8901
|
const scripts = options?.scripts === true;
|
|
7820
8902
|
const height = options?.height ?? 300;
|
|
7821
|
-
const linked = (0,
|
|
8903
|
+
const linked = (0, import_react21.useMemo)(() => showing === "preview" ? linkedFilesOf(html) : [], [html, showing]);
|
|
7822
8904
|
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7823
8905
|
SandboxedFrame,
|
|
7824
8906
|
{
|
|
@@ -7931,14 +9013,14 @@ var TextPreview = ({
|
|
|
7931
9013
|
onClose,
|
|
7932
9014
|
L
|
|
7933
9015
|
}) => {
|
|
7934
|
-
const text2 = (0,
|
|
7935
|
-
const rendered = (0,
|
|
9016
|
+
const text2 = (0, import_react21.useMemo)(() => textOf(file), [file]);
|
|
9017
|
+
const rendered = (0, import_react21.useMemo)(
|
|
7936
9018
|
() => renderFileContent?.(written, text2.slice(0, previewChars)),
|
|
7937
9019
|
[renderFileContent, written, text2, previewChars]
|
|
7938
9020
|
);
|
|
7939
9021
|
const hasRendered = rendered !== void 0 && rendered !== null && rendered !== false;
|
|
7940
|
-
const [view, setView] = (0,
|
|
7941
|
-
const [all, setAll] = (0,
|
|
9022
|
+
const [view, setView] = (0, import_react21.useState)("rendered");
|
|
9023
|
+
const [all, setAll] = (0, import_react21.useState)(false);
|
|
7942
9024
|
const showing = hasRendered ? view : "source";
|
|
7943
9025
|
const long = text2.length > 1200 || text2.split("\n").length > 16;
|
|
7944
9026
|
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "awr-fileview", children: [
|
|
@@ -7980,11 +9062,11 @@ var FileChips = ({
|
|
|
7980
9062
|
}) => {
|
|
7981
9063
|
const L = useLabels(labels);
|
|
7982
9064
|
const live = useVirtualFiles(vfs);
|
|
7983
|
-
const [openPath, setOpenPath] = (0,
|
|
7984
|
-
const [file, setFile] = (0,
|
|
9065
|
+
const [openPath, setOpenPath] = (0, import_react21.useState)(defaultOpen);
|
|
9066
|
+
const [file, setFile] = (0, import_react21.useState)();
|
|
7985
9067
|
const open = written.find((f) => f.path === openPath);
|
|
7986
9068
|
const stamp = live.files.find((f) => f.path === openPath)?.updatedAt;
|
|
7987
|
-
(0,
|
|
9069
|
+
(0, import_react21.useEffect)(() => {
|
|
7988
9070
|
if (!vfs || !openPath) return setFile(void 0);
|
|
7989
9071
|
let gone = false;
|
|
7990
9072
|
vfs.read(openPath).then((f) => {
|
|
@@ -8107,14 +9189,14 @@ var FileChip = ({
|
|
|
8107
9189
|
};
|
|
8108
9190
|
|
|
8109
9191
|
// src/components/StepList.tsx
|
|
8110
|
-
var
|
|
9192
|
+
var import_react23 = require("react");
|
|
8111
9193
|
|
|
8112
9194
|
// src/components/SubagentTree.tsx
|
|
8113
|
-
var
|
|
9195
|
+
var import_react22 = require("react");
|
|
8114
9196
|
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
8115
9197
|
var useElapsed = (startedAt, running) => {
|
|
8116
|
-
const [now, setNow] = (0,
|
|
8117
|
-
(0,
|
|
9198
|
+
const [now, setNow] = (0, import_react22.useState)(void 0);
|
|
9199
|
+
(0, import_react22.useEffect)(() => {
|
|
8118
9200
|
if (!running || startedAt === void 0) return;
|
|
8119
9201
|
setNow(Date.now());
|
|
8120
9202
|
const timer = setInterval(() => setNow(Date.now()), 1e3);
|
|
@@ -8204,7 +9286,7 @@ var SubagentTree = ({
|
|
|
8204
9286
|
},
|
|
8205
9287
|
node.id
|
|
8206
9288
|
);
|
|
8207
|
-
return renderSubagent ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
9289
|
+
return renderSubagent ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react22.Fragment, { children: renderSubagent(node, row) }, node.id) : row;
|
|
8208
9290
|
})
|
|
8209
9291
|
}
|
|
8210
9292
|
);
|
|
@@ -8383,7 +9465,7 @@ var StepItem = ({
|
|
|
8383
9465
|
},
|
|
8384
9466
|
i
|
|
8385
9467
|
);
|
|
8386
|
-
return renderToolCall ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
9468
|
+
return renderToolCall ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react23.Fragment, { children: renderToolCall(call, row) }, i) : row;
|
|
8387
9469
|
}) }),
|
|
8388
9470
|
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: [
|
|
8389
9471
|
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ShieldIcon, { size: 13, className: "awr-tool__icon" }),
|
|
@@ -8490,7 +9572,54 @@ var usageLine = (usage, durationMs) => {
|
|
|
8490
9572
|
if (durationMs !== void 0) parts.push(formatDuration(durationMs));
|
|
8491
9573
|
return parts.join(" \xB7 ");
|
|
8492
9574
|
};
|
|
8493
|
-
var
|
|
9575
|
+
var lengthOf = (ms) => typeof ms === "number" && Number.isFinite(ms) && ms >= 0 && ms < 864e5 ? ms : void 0;
|
|
9576
|
+
var settleAudioDuration = (el) => {
|
|
9577
|
+
if (el.duration !== Infinity) return;
|
|
9578
|
+
const back = () => {
|
|
9579
|
+
if (!Number.isFinite(el.duration)) return;
|
|
9580
|
+
el.removeEventListener("durationchange", back);
|
|
9581
|
+
el.removeEventListener("timeupdate", back);
|
|
9582
|
+
el.currentTime = 0;
|
|
9583
|
+
};
|
|
9584
|
+
el.addEventListener("durationchange", back);
|
|
9585
|
+
el.addEventListener("timeupdate", back);
|
|
9586
|
+
el.currentTime = Number.MAX_SAFE_INTEGER;
|
|
9587
|
+
};
|
|
9588
|
+
var AttachedAudio = ({
|
|
9589
|
+
attachment: a,
|
|
9590
|
+
files,
|
|
9591
|
+
labels
|
|
9592
|
+
}) => {
|
|
9593
|
+
const L = useLabels(labels);
|
|
9594
|
+
const type = a.mediaType.toLowerCase().split(";")[0].trim();
|
|
9595
|
+
const url = useFileUrl(files, a.path ?? "", files && a.path ? type : void 0);
|
|
9596
|
+
const length = lengthOf(a.durationMs);
|
|
9597
|
+
const said = length !== void 0 ? L.audioDuration(formatClock(length)) : void 0;
|
|
9598
|
+
return url ? /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("span", { className: "awr-media awr-media--audio awr-msg__audio", title: a.path ?? a.name, children: [
|
|
9599
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
9600
|
+
"audio",
|
|
9601
|
+
{
|
|
9602
|
+
className: "awr-media__audio",
|
|
9603
|
+
controls: true,
|
|
9604
|
+
preload: "metadata",
|
|
9605
|
+
src: url,
|
|
9606
|
+
"aria-label": said ? `${L.audioAttachment(a.name)} (${said})` : L.audioAttachment(a.name),
|
|
9607
|
+
onLoadedMetadata: (e) => settleAudioDuration(e.currentTarget)
|
|
9608
|
+
}
|
|
9609
|
+
),
|
|
9610
|
+
said && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "awr-msg__audiolen", "aria-hidden": "true", children: said })
|
|
9611
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("span", { className: "awr-chip awr-file", title: a.path ?? a.mediaType, children: [
|
|
9612
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(WaveIcon, { size: 13 }),
|
|
9613
|
+
" ",
|
|
9614
|
+
a.name,
|
|
9615
|
+
said ? ` \xB7 ${said}` : ""
|
|
9616
|
+
] });
|
|
9617
|
+
};
|
|
9618
|
+
var AttachmentView = ({
|
|
9619
|
+
attachment: a,
|
|
9620
|
+
files,
|
|
9621
|
+
labels
|
|
9622
|
+
}) => 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)(
|
|
8494
9623
|
ImageThumb,
|
|
8495
9624
|
{
|
|
8496
9625
|
src: a.dataUrl,
|
|
@@ -8504,6 +9633,12 @@ var AttachmentView = ({ attachment: a }) => a.dataUrl && a.mediaType.startsWith(
|
|
|
8504
9633
|
" ",
|
|
8505
9634
|
a.name
|
|
8506
9635
|
] });
|
|
9636
|
+
var toolCardsOf = (m, render) => (m.steps ?? []).flatMap(
|
|
9637
|
+
(step, s) => step.toolCalls.flatMap((call, c) => {
|
|
9638
|
+
const node = render(call, m);
|
|
9639
|
+
return node === null || node === void 0 || node === false ? [] : [{ key: `${s}:${c}`, node }];
|
|
9640
|
+
})
|
|
9641
|
+
);
|
|
8507
9642
|
var toolCallCount = (m) => (m.steps ?? []).reduce((n, s) => n + s.toolCalls.length, 0);
|
|
8508
9643
|
var activitySummary = (m, showToolCalls, showLearned, showTiers, showFileChips, L, showApps = false) => {
|
|
8509
9644
|
const steps = m.steps ?? [];
|
|
@@ -8549,14 +9684,18 @@ var MessageList = ({
|
|
|
8549
9684
|
renderMessage,
|
|
8550
9685
|
renderAttachment,
|
|
8551
9686
|
renderToolCall,
|
|
9687
|
+
renderToolCard,
|
|
9688
|
+
showToolCards = true,
|
|
8552
9689
|
renderApp,
|
|
8553
9690
|
showApps = true,
|
|
8554
9691
|
imageViewer = true,
|
|
8555
9692
|
renderImageViewer,
|
|
9693
|
+
readAloud,
|
|
8556
9694
|
labels,
|
|
8557
9695
|
className
|
|
8558
9696
|
}) => {
|
|
8559
9697
|
const L = useLabels(labels);
|
|
9698
|
+
const reader = useReadAloud(readAloud?.speak, readAloud?.lang);
|
|
8560
9699
|
if (messages.length === 0) {
|
|
8561
9700
|
return empty ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "awr-messages__empty", children: empty }) : null;
|
|
8562
9701
|
}
|
|
@@ -8564,6 +9703,7 @@ var MessageList = ({
|
|
|
8564
9703
|
const steps = m.steps ?? [];
|
|
8565
9704
|
const hasActivity = showActivity && (steps.length > 0 || (m.subagents?.length ?? 0) > 0 || m.pending && !!liveExtra);
|
|
8566
9705
|
const usage = showUsage ? usageLine(m.usage, m.durationMs) : "";
|
|
9706
|
+
const cards = showToolCards && renderToolCard && m.role === "assistant" ? toolCardsOf(m, renderToolCard) : [];
|
|
8567
9707
|
const node = /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
8568
9708
|
"div",
|
|
8569
9709
|
{
|
|
@@ -8630,12 +9770,22 @@ var MessageList = ({
|
|
|
8630
9770
|
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("p", { className: "awr-thought__text", children: m.reasoning.trim() })
|
|
8631
9771
|
] })
|
|
8632
9772
|
] }),
|
|
9773
|
+
cards.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "awr-msg__cards", children: cards.map((card) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "awr-msg__card", children: card.node }, card.key)) }),
|
|
8633
9774
|
showApps && renderApp && m.role === "assistant" && m.apps?.length ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "awr-msg__apps", children: m.apps.map((app) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "awr-msg__app", children: renderApp(app, m) }, app.id)) }) : null,
|
|
8634
9775
|
showMedia && m.transcripts?.length ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "awr-msg__transcripts", children: m.transcripts.map((t, i) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(TranscriptBlock, { transcript: t, labels }, i)) }) : null,
|
|
8635
9776
|
(m.content || m.pending || !m.attachments?.length) && /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "awr-msg__bubble", children: [
|
|
8636
9777
|
m.content ? renderContent ? renderContent(m) : m.content : m.stopped && !m.pending ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "awr-msg__stopped", children: L.answerStopped }) : null,
|
|
8637
9778
|
m.pending && !m.content && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SpinnerIcon, { size: 14, className: "awr-msg__pending" })
|
|
8638
9779
|
] }),
|
|
9780
|
+
readAloud && m.role === "assistant" && m.content && !m.pending && !m.error && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
9781
|
+
ReadAloudControl,
|
|
9782
|
+
{
|
|
9783
|
+
id: m.id,
|
|
9784
|
+
text: () => readAloud.textOf ? readAloud.textOf(m) : speakableText(m.content, { code: L.readAloudCode }),
|
|
9785
|
+
reader,
|
|
9786
|
+
labels: L
|
|
9787
|
+
}
|
|
9788
|
+
),
|
|
8639
9789
|
showMedia && m.media?.length ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "awr-msg__media", children: m.media.map((item, i) => {
|
|
8640
9790
|
const built = /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(GeneratedMedia, { media: item, files, labels }, i);
|
|
8641
9791
|
return renderMedia ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "awr-msg__mediaitem", children: renderMedia(item, m, built) }, i) : built;
|
|
@@ -8652,7 +9802,15 @@ var MessageList = ({
|
|
|
8652
9802
|
labels
|
|
8653
9803
|
}
|
|
8654
9804
|
) : null,
|
|
8655
|
-
m.attachments?.length ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
9805
|
+
m.attachments?.length ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
9806
|
+
"div",
|
|
9807
|
+
{
|
|
9808
|
+
className: "awr-msg__attachments",
|
|
9809
|
+
role: "group",
|
|
9810
|
+
"aria-label": m.content.trim() ? L.attachments : attachmentsText(m.attachments, { voiceMessage: L.voiceMessage }),
|
|
9811
|
+
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))
|
|
9812
|
+
}
|
|
9813
|
+
) : null,
|
|
8656
9814
|
m.role === "assistant" && usage && !m.pending && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "awr-msg__usage", title: L.usageTitle, children: usage })
|
|
8657
9815
|
] })
|
|
8658
9816
|
},
|
|
@@ -8661,6 +9819,78 @@ var MessageList = ({
|
|
|
8661
9819
|
return renderMessage ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { children: renderMessage(m, node) }, m.id) : node;
|
|
8662
9820
|
}) }) });
|
|
8663
9821
|
};
|
|
9822
|
+
var ReadAloudControl = ({
|
|
9823
|
+
id,
|
|
9824
|
+
text: text2,
|
|
9825
|
+
reader,
|
|
9826
|
+
labels: L
|
|
9827
|
+
}) => {
|
|
9828
|
+
const mine = reader.current === id;
|
|
9829
|
+
const failed = reader.failed?.id === id ? reader.failed : void 0;
|
|
9830
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "awr-readaloud", "data-state": mine ? reader.state : "idle", children: [
|
|
9831
|
+
!mine ? /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
9832
|
+
"button",
|
|
9833
|
+
{
|
|
9834
|
+
type: "button",
|
|
9835
|
+
className: "awr-linkbtn awr-readaloud__btn",
|
|
9836
|
+
onClick: () => reader.start(id, text2()),
|
|
9837
|
+
"aria-label": L.readAloud,
|
|
9838
|
+
children: [
|
|
9839
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SpeakerIcon, { size: 14 }),
|
|
9840
|
+
" ",
|
|
9841
|
+
L.readAloud
|
|
9842
|
+
]
|
|
9843
|
+
}
|
|
9844
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
|
|
9845
|
+
reader.state === "loading" ? /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("span", { className: "awr-readaloud__status", role: "status", children: [
|
|
9846
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SpinnerIcon, { size: 14 }),
|
|
9847
|
+
" ",
|
|
9848
|
+
L.readAloudLoading
|
|
9849
|
+
] }) : reader.state === "paused" ? /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
9850
|
+
"button",
|
|
9851
|
+
{
|
|
9852
|
+
type: "button",
|
|
9853
|
+
className: "awr-linkbtn awr-readaloud__btn",
|
|
9854
|
+
onClick: reader.resume,
|
|
9855
|
+
"aria-label": L.readAloudResume,
|
|
9856
|
+
children: [
|
|
9857
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(PlayIcon, { size: 14 }),
|
|
9858
|
+
" ",
|
|
9859
|
+
L.readAloudResume
|
|
9860
|
+
]
|
|
9861
|
+
}
|
|
9862
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
9863
|
+
"button",
|
|
9864
|
+
{
|
|
9865
|
+
type: "button",
|
|
9866
|
+
className: "awr-linkbtn awr-readaloud__btn",
|
|
9867
|
+
onClick: reader.pause,
|
|
9868
|
+
"aria-label": L.readAloudPause,
|
|
9869
|
+
children: [
|
|
9870
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(PauseIcon, { size: 14 }),
|
|
9871
|
+
" ",
|
|
9872
|
+
L.readAloudPause
|
|
9873
|
+
]
|
|
9874
|
+
}
|
|
9875
|
+
),
|
|
9876
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
9877
|
+
"button",
|
|
9878
|
+
{
|
|
9879
|
+
type: "button",
|
|
9880
|
+
className: "awr-linkbtn awr-readaloud__btn",
|
|
9881
|
+
onClick: reader.stop,
|
|
9882
|
+
"aria-label": L.readAloudStop,
|
|
9883
|
+
children: [
|
|
9884
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(StopIcon, { size: 14 }),
|
|
9885
|
+
" ",
|
|
9886
|
+
L.readAloudStop
|
|
9887
|
+
]
|
|
9888
|
+
}
|
|
9889
|
+
)
|
|
9890
|
+
] }),
|
|
9891
|
+
failed && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "awr-readaloud__error", role: "alert", children: failed.message ?? L.readAloudFailed })
|
|
9892
|
+
] });
|
|
9893
|
+
};
|
|
8664
9894
|
|
|
8665
9895
|
// src/components/ModelLoadBar.tsx
|
|
8666
9896
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
@@ -8679,11 +9909,11 @@ var ModelLoadBar = ({ load, className }) => {
|
|
|
8679
9909
|
};
|
|
8680
9910
|
|
|
8681
9911
|
// src/components/QuestionPrompt.tsx
|
|
8682
|
-
var
|
|
9912
|
+
var import_react24 = require("react");
|
|
8683
9913
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
8684
9914
|
var useNow2 = (active) => {
|
|
8685
|
-
const [now, setNow] = (0,
|
|
8686
|
-
(0,
|
|
9915
|
+
const [now, setNow] = (0, import_react24.useState)(() => Date.now());
|
|
9916
|
+
(0, import_react24.useEffect)(() => {
|
|
8687
9917
|
if (!active) return;
|
|
8688
9918
|
setNow(Date.now());
|
|
8689
9919
|
const timer = setInterval(() => setNow(Date.now()), 1e3);
|
|
@@ -8712,15 +9942,15 @@ var QuestionCard = ({
|
|
|
8712
9942
|
numberKeys,
|
|
8713
9943
|
L
|
|
8714
9944
|
}) => {
|
|
8715
|
-
const baseId = (0,
|
|
9945
|
+
const baseId = (0, import_react24.useId)();
|
|
8716
9946
|
const textId = `${baseId}-q`;
|
|
8717
9947
|
const otherId = `${baseId}-other`;
|
|
8718
|
-
const [picked, setPicked] = (0,
|
|
8719
|
-
const [otherOpen, setOtherOpen] = (0,
|
|
8720
|
-
const [otherText, setOtherText] = (0,
|
|
8721
|
-
const otherField = (0,
|
|
8722
|
-
const otherButton = (0,
|
|
8723
|
-
(0,
|
|
9948
|
+
const [picked, setPicked] = (0, import_react24.useState)([]);
|
|
9949
|
+
const [otherOpen, setOtherOpen] = (0, import_react24.useState)(false);
|
|
9950
|
+
const [otherText, setOtherText] = (0, import_react24.useState)("");
|
|
9951
|
+
const otherField = (0, import_react24.useRef)(null);
|
|
9952
|
+
const otherButton = (0, import_react24.useRef)(null);
|
|
9953
|
+
(0, import_react24.useEffect)(() => {
|
|
8724
9954
|
if (otherOpen) otherField.current?.focus();
|
|
8725
9955
|
}, [otherOpen]);
|
|
8726
9956
|
const helper = showHelper && q.subagent ? { ...q.subagent, ...view?.subagent } : void 0;
|
|
@@ -8851,7 +10081,7 @@ var QuestionCard = ({
|
|
|
8851
10081
|
);
|
|
8852
10082
|
};
|
|
8853
10083
|
var RemoteQuestion = ({ view, L }) => {
|
|
8854
|
-
const textId = `${(0,
|
|
10084
|
+
const textId = `${(0, import_react24.useId)()}-q`;
|
|
8855
10085
|
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
|
|
8856
10086
|
"section",
|
|
8857
10087
|
{
|
|
@@ -8888,7 +10118,7 @@ var QuestionPrompt = ({
|
|
|
8888
10118
|
className
|
|
8889
10119
|
}) => {
|
|
8890
10120
|
const L = useLabels(labels);
|
|
8891
|
-
const [dismissed, setDismissed] = (0,
|
|
10121
|
+
const [dismissed, setDismissed] = (0, import_react24.useState)(() => /* @__PURE__ */ new Set());
|
|
8892
10122
|
const automatic = showOutcomes ? (outcomes ?? []).filter(
|
|
8893
10123
|
(o) => o.automatic === true && o.status !== "pending" && o.status !== "stopped" && !dismissed.has(o.id)
|
|
8894
10124
|
) : [];
|
|
@@ -9145,10 +10375,10 @@ var UsageBadge = ({
|
|
|
9145
10375
|
var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
9146
10376
|
var usePrefersDark = () => {
|
|
9147
10377
|
const query = "(prefers-color-scheme: dark)";
|
|
9148
|
-
const [dark, setDark] = (0,
|
|
10378
|
+
const [dark, setDark] = (0, import_react25.useState)(
|
|
9149
10379
|
() => typeof matchMedia === "function" && matchMedia(query).matches
|
|
9150
10380
|
);
|
|
9151
|
-
(0,
|
|
10381
|
+
(0, import_react25.useEffect)(() => {
|
|
9152
10382
|
if (typeof matchMedia !== "function") return;
|
|
9153
10383
|
const mq = matchMedia(query);
|
|
9154
10384
|
const on = () => setDark(mq.matches);
|
|
@@ -9203,7 +10433,10 @@ var AgentChatInner = ({
|
|
|
9203
10433
|
renderContent,
|
|
9204
10434
|
renderMessage,
|
|
9205
10435
|
renderAttachment,
|
|
10436
|
+
readAloud,
|
|
9206
10437
|
renderToolCall,
|
|
10438
|
+
renderToolCard,
|
|
10439
|
+
showToolCards = true,
|
|
9207
10440
|
renderSubagent,
|
|
9208
10441
|
renderMedia,
|
|
9209
10442
|
renderFile,
|
|
@@ -9238,17 +10471,19 @@ var AgentChatInner = ({
|
|
|
9238
10471
|
}
|
|
9239
10472
|
const L = useLabels();
|
|
9240
10473
|
const external = isHistoryHook(history) ? history : void 0;
|
|
9241
|
-
const [ownStore] = (0,
|
|
10474
|
+
const [ownStore] = (0, import_react25.useState)(
|
|
9242
10475
|
() => history instanceof ChatHistoryStore ? history : new ChatHistoryStore()
|
|
9243
10476
|
);
|
|
9244
10477
|
const own = useChatHistory(agent, {
|
|
9245
10478
|
store: ownStore,
|
|
9246
|
-
enabled: Boolean(history) && !external
|
|
10479
|
+
enabled: Boolean(history) && !external,
|
|
10480
|
+
// A chat begun by a voice message is titled in the chat's language.
|
|
10481
|
+
labels: { voiceMessage: L.voiceMessage }
|
|
9247
10482
|
});
|
|
9248
10483
|
const chats = history ? external ?? own : void 0;
|
|
9249
|
-
const rootRef = (0,
|
|
9250
|
-
const [narrow, setNarrow] = (0,
|
|
9251
|
-
(0,
|
|
10484
|
+
const rootRef = (0, import_react25.useRef)(null);
|
|
10485
|
+
const [narrow, setNarrow] = (0, import_react25.useState)(void 0);
|
|
10486
|
+
(0, import_react25.useEffect)(() => {
|
|
9252
10487
|
const el = rootRef.current;
|
|
9253
10488
|
if (!el || typeof ResizeObserver === "undefined") return setNarrow(false);
|
|
9254
10489
|
const measure2 = () => setNarrow(el.getBoundingClientRect().width < narrowWidth);
|
|
@@ -9257,9 +10492,9 @@ var AgentChatInner = ({
|
|
|
9257
10492
|
ro.observe(el);
|
|
9258
10493
|
return () => ro.disconnect();
|
|
9259
10494
|
}, [narrowWidth]);
|
|
9260
|
-
const [historyChoice, setHistoryOpen] = (0,
|
|
10495
|
+
const [historyChoice, setHistoryOpen] = (0, import_react25.useState)(defaultHistoryOpen);
|
|
9261
10496
|
const historyOpen = historyChoice ?? narrow === false;
|
|
9262
|
-
const [filesOpen, setFilesOpen] = (0,
|
|
10497
|
+
const [filesOpen, setFilesOpen] = (0, import_react25.useState)(defaultFilesOpen);
|
|
9263
10498
|
const toggleHistory = () => {
|
|
9264
10499
|
setHistoryOpen(!historyOpen);
|
|
9265
10500
|
if (narrow && !historyOpen) setFilesOpen(false);
|
|
@@ -9277,7 +10512,7 @@ var AgentChatInner = ({
|
|
|
9277
10512
|
setHistoryOpen(false);
|
|
9278
10513
|
setFilesOpen(false);
|
|
9279
10514
|
};
|
|
9280
|
-
(0,
|
|
10515
|
+
(0, import_react25.useEffect)(() => {
|
|
9281
10516
|
if (!overlayOpen) return;
|
|
9282
10517
|
const onKey = (e) => {
|
|
9283
10518
|
if (e.key !== "Escape" || e.defaultPrevented) return;
|
|
@@ -9287,7 +10522,7 @@ var AgentChatInner = ({
|
|
|
9287
10522
|
document.addEventListener("keydown", onKey);
|
|
9288
10523
|
return () => document.removeEventListener("keydown", onKey);
|
|
9289
10524
|
}, [overlayOpen]);
|
|
9290
|
-
const bodyRef = (0,
|
|
10525
|
+
const bodyRef = (0, import_react25.useRef)(null);
|
|
9291
10526
|
const appHost = useMcpAppHost({
|
|
9292
10527
|
connection: mcpApps,
|
|
9293
10528
|
approve: agent.approveAppToolCall,
|
|
@@ -9299,7 +10534,7 @@ var AgentChatInner = ({
|
|
|
9299
10534
|
});
|
|
9300
10535
|
const prefersDark = usePrefersDark();
|
|
9301
10536
|
const appTheme = theme === "auto" ? prefersDark ? "dark" : "light" : theme;
|
|
9302
|
-
const [panelApp, setPanelAppState] = (0,
|
|
10537
|
+
const [panelApp, setPanelAppState] = (0, import_react25.useState)();
|
|
9303
10538
|
const setPanelApp = (app) => {
|
|
9304
10539
|
setPanelAppState(app);
|
|
9305
10540
|
onAppPanel?.(app);
|
|
@@ -9313,7 +10548,7 @@ var AgentChatInner = ({
|
|
|
9313
10548
|
const panelAllowed = appPanel !== false && appPanel !== null;
|
|
9314
10549
|
const panelTarget = typeof appPanel === "object" && appPanel ? appPanel : void 0;
|
|
9315
10550
|
const asSheet = !panelTarget && (appPanel === "sheet" || Boolean(narrow));
|
|
9316
|
-
(0,
|
|
10551
|
+
(0, import_react25.useEffect)(() => {
|
|
9317
10552
|
if (panelApp && !agent.messages.some((m) => m.apps?.some((a) => a.id === panelApp.id))) {
|
|
9318
10553
|
setPanelAppState(void 0);
|
|
9319
10554
|
onAppPanel?.(void 0);
|
|
@@ -9353,7 +10588,7 @@ var AgentChatInner = ({
|
|
|
9353
10588
|
},
|
|
9354
10589
|
panelApp.id
|
|
9355
10590
|
) : null;
|
|
9356
|
-
const [compacting, setCompacting] = (0,
|
|
10591
|
+
const [compacting, setCompacting] = (0, import_react25.useState)(false);
|
|
9357
10592
|
const compact = () => {
|
|
9358
10593
|
setCompacting(true);
|
|
9359
10594
|
void agent.compact().finally(() => setCompacting(false));
|
|
@@ -9511,7 +10746,10 @@ var AgentChatInner = ({
|
|
|
9511
10746
|
renderContent,
|
|
9512
10747
|
renderMessage,
|
|
9513
10748
|
renderAttachment,
|
|
10749
|
+
readAloud,
|
|
9514
10750
|
renderToolCall,
|
|
10751
|
+
renderToolCard,
|
|
10752
|
+
showToolCards,
|
|
9515
10753
|
showApps: appsOn,
|
|
9516
10754
|
renderApp: appsOn ? drawApp : void 0,
|
|
9517
10755
|
imageViewer,
|
|
@@ -9685,9 +10923,59 @@ var LearnedSkills = ({
|
|
|
9685
10923
|
] });
|
|
9686
10924
|
};
|
|
9687
10925
|
|
|
9688
|
-
// src/components/
|
|
9689
|
-
var
|
|
10926
|
+
// src/components/MemoryCard.tsx
|
|
10927
|
+
var import_react26 = require("react");
|
|
9690
10928
|
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
10929
|
+
var MemoryCard = ({
|
|
10930
|
+
kind,
|
|
10931
|
+
text: text2,
|
|
10932
|
+
onUndo,
|
|
10933
|
+
undone = false,
|
|
10934
|
+
problem,
|
|
10935
|
+
labels,
|
|
10936
|
+
className
|
|
10937
|
+
}) => {
|
|
10938
|
+
const L = useLabels(labels);
|
|
10939
|
+
const [busy, setBusy] = (0, import_react26.useState)(false);
|
|
10940
|
+
const label = kind === "saved" ? L.memorySaved : kind === "updated" ? L.memoryUpdated : L.memoryForgotten;
|
|
10941
|
+
const undo = () => {
|
|
10942
|
+
if (!onUndo || busy) return;
|
|
10943
|
+
setBusy(true);
|
|
10944
|
+
void Promise.resolve().then(onUndo).catch(() => {
|
|
10945
|
+
}).finally(() => setBusy(false));
|
|
10946
|
+
};
|
|
10947
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
|
|
10948
|
+
"div",
|
|
10949
|
+
{
|
|
10950
|
+
className: ["awr-memory", `awr-memory--${kind}`, undone ? "is-undone" : "", className].filter(Boolean).join(" "),
|
|
10951
|
+
"data-memory": kind,
|
|
10952
|
+
children: [
|
|
10953
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(BookmarkIcon, { size: 14, className: "awr-memory__icon" }),
|
|
10954
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "awr-memory__body", children: [
|
|
10955
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)("span", { className: "awr-memory__label", children: label }),
|
|
10956
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)("span", { className: "awr-memory__text", children: text2 }),
|
|
10957
|
+
problem && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("span", { className: "awr-memory__problem", role: "alert", children: problem })
|
|
10958
|
+
] }),
|
|
10959
|
+
undone ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("span", { className: "awr-memory__undone", children: L.memoryUndone }) : onUndo ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
10960
|
+
"button",
|
|
10961
|
+
{
|
|
10962
|
+
type: "button",
|
|
10963
|
+
className: "awr-memory__undo",
|
|
10964
|
+
disabled: busy,
|
|
10965
|
+
"aria-busy": busy,
|
|
10966
|
+
"aria-label": `${L.memoryUndo}: ${text2}`,
|
|
10967
|
+
onClick: undo,
|
|
10968
|
+
children: L.memoryUndo
|
|
10969
|
+
}
|
|
10970
|
+
) : null
|
|
10971
|
+
]
|
|
10972
|
+
}
|
|
10973
|
+
);
|
|
10974
|
+
};
|
|
10975
|
+
|
|
10976
|
+
// src/components/Composer.tsx
|
|
10977
|
+
var import_react27 = require("react");
|
|
10978
|
+
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
9691
10979
|
var Composer = ({
|
|
9692
10980
|
onSubmit,
|
|
9693
10981
|
busy = false,
|
|
@@ -9696,7 +10984,7 @@ var Composer = ({
|
|
|
9696
10984
|
placeholder = "Ask the agent to do something\u2026",
|
|
9697
10985
|
className
|
|
9698
10986
|
}) => {
|
|
9699
|
-
const [text2, setText] = (0,
|
|
10987
|
+
const [text2, setText] = (0, import_react27.useState)("");
|
|
9700
10988
|
const submit = () => {
|
|
9701
10989
|
const value = text2.trim();
|
|
9702
10990
|
if (!value || busy || disabled) return;
|
|
@@ -9709,7 +10997,7 @@ var Composer = ({
|
|
|
9709
10997
|
submit();
|
|
9710
10998
|
}
|
|
9711
10999
|
};
|
|
9712
|
-
return /* @__PURE__ */ (0,
|
|
11000
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
|
|
9713
11001
|
"form",
|
|
9714
11002
|
{
|
|
9715
11003
|
className: ["awr-composer", className].filter(Boolean).join(" "),
|
|
@@ -9718,7 +11006,7 @@ var Composer = ({
|
|
|
9718
11006
|
submit();
|
|
9719
11007
|
},
|
|
9720
11008
|
children: [
|
|
9721
|
-
/* @__PURE__ */ (0,
|
|
11009
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
9722
11010
|
"textarea",
|
|
9723
11011
|
{
|
|
9724
11012
|
className: "awr-composer__input",
|
|
@@ -9730,23 +11018,23 @@ var Composer = ({
|
|
|
9730
11018
|
rows: 1
|
|
9731
11019
|
}
|
|
9732
11020
|
),
|
|
9733
|
-
busy ? /* @__PURE__ */ (0,
|
|
11021
|
+
busy ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
9734
11022
|
"button",
|
|
9735
11023
|
{
|
|
9736
11024
|
type: "button",
|
|
9737
11025
|
className: "awr-composer__btn awr-composer__btn--stop",
|
|
9738
11026
|
onClick: onStop,
|
|
9739
11027
|
"aria-label": "Stop",
|
|
9740
|
-
children: /* @__PURE__ */ (0,
|
|
11028
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(StopIcon, { size: 18 })
|
|
9741
11029
|
}
|
|
9742
|
-
) : /* @__PURE__ */ (0,
|
|
11030
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
9743
11031
|
"button",
|
|
9744
11032
|
{
|
|
9745
11033
|
type: "submit",
|
|
9746
11034
|
className: "awr-composer__btn",
|
|
9747
11035
|
disabled: disabled || !text2.trim(),
|
|
9748
11036
|
"aria-label": "Send",
|
|
9749
|
-
children: disabled ? /* @__PURE__ */ (0,
|
|
11037
|
+
children: disabled ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(SpinnerIcon, { size: 18 }) : /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(SendIcon, { size: 18 })
|
|
9750
11038
|
}
|
|
9751
11039
|
)
|
|
9752
11040
|
]
|
|
@@ -9755,17 +11043,17 @@ var Composer = ({
|
|
|
9755
11043
|
};
|
|
9756
11044
|
|
|
9757
11045
|
// src/components/PlanView.tsx
|
|
9758
|
-
var
|
|
11046
|
+
var import_jsx_runtime26 = require("react/jsx-runtime");
|
|
9759
11047
|
var PlanView = ({ plan, showThought = true, className }) => {
|
|
9760
11048
|
if (!plan.steps.length && !plan.thought) return null;
|
|
9761
|
-
return /* @__PURE__ */ (0,
|
|
9762
|
-
showThought && plan.thought.trim() && /* @__PURE__ */ (0,
|
|
9763
|
-
plan.steps.length > 0 && /* @__PURE__ */ (0,
|
|
11049
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: ["awr-plan", className].filter(Boolean).join(" "), children: [
|
|
11050
|
+
showThought && plan.thought.trim() && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("p", { className: "awr-plan__thought", children: plan.thought }),
|
|
11051
|
+
plan.steps.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("ol", { className: "awr-plan__steps", children: plan.steps.map((step) => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("li", { className: "awr-plan__step", children: step.description }, step.id)) })
|
|
9764
11052
|
] });
|
|
9765
11053
|
};
|
|
9766
11054
|
|
|
9767
11055
|
// src/components/ApprovalModeSwitch.tsx
|
|
9768
|
-
var
|
|
11056
|
+
var import_jsx_runtime27 = require("react/jsx-runtime");
|
|
9769
11057
|
var DEFAULT_LABELS = {
|
|
9770
11058
|
autopilot: "Autopilot",
|
|
9771
11059
|
"ask-writes": "Ask before changes",
|
|
@@ -9785,13 +11073,13 @@ var ApprovalModeSwitch = ({
|
|
|
9785
11073
|
labels,
|
|
9786
11074
|
disabled,
|
|
9787
11075
|
className
|
|
9788
|
-
}) => /* @__PURE__ */ (0,
|
|
11076
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
9789
11077
|
"div",
|
|
9790
11078
|
{
|
|
9791
11079
|
className: ["awr-modeswitch", className].filter(Boolean).join(" "),
|
|
9792
11080
|
role: "radiogroup",
|
|
9793
11081
|
"aria-label": "Tool consent",
|
|
9794
|
-
children: modes.map((m) => /* @__PURE__ */ (0,
|
|
11082
|
+
children: modes.map((m) => /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
9795
11083
|
"button",
|
|
9796
11084
|
{
|
|
9797
11085
|
type: "button",
|
|
@@ -9809,8 +11097,8 @@ var ApprovalModeSwitch = ({
|
|
|
9809
11097
|
);
|
|
9810
11098
|
|
|
9811
11099
|
// src/components/ApiKeyForm.tsx
|
|
9812
|
-
var
|
|
9813
|
-
var
|
|
11100
|
+
var import_react28 = require("react");
|
|
11101
|
+
var import_jsx_runtime28 = require("react/jsx-runtime");
|
|
9814
11102
|
var ApiKeyForm = ({
|
|
9815
11103
|
credentials,
|
|
9816
11104
|
credentialRef,
|
|
@@ -9819,10 +11107,10 @@ var ApiKeyForm = ({
|
|
|
9819
11107
|
onChange,
|
|
9820
11108
|
className
|
|
9821
11109
|
}) => {
|
|
9822
|
-
const [value, setValue] = (0,
|
|
9823
|
-
const [present, setPresent] = (0,
|
|
9824
|
-
const [busy, setBusy] = (0,
|
|
9825
|
-
(0,
|
|
11110
|
+
const [value, setValue] = (0, import_react28.useState)("");
|
|
11111
|
+
const [present, setPresent] = (0, import_react28.useState)(false);
|
|
11112
|
+
const [busy, setBusy] = (0, import_react28.useState)(false);
|
|
11113
|
+
(0, import_react28.useEffect)(() => {
|
|
9826
11114
|
let active = true;
|
|
9827
11115
|
credentials.hasKey(credentialRef).then((has) => {
|
|
9828
11116
|
if (active) setPresent(has);
|
|
@@ -9854,16 +11142,16 @@ var ApiKeyForm = ({
|
|
|
9854
11142
|
setBusy(false);
|
|
9855
11143
|
}
|
|
9856
11144
|
};
|
|
9857
|
-
return /* @__PURE__ */ (0,
|
|
9858
|
-
/* @__PURE__ */ (0,
|
|
11145
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: ["awr-keyform", className].filter(Boolean).join(" "), children: [
|
|
11146
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("label", { className: "awr-keyform__label", children: [
|
|
9859
11147
|
label,
|
|
9860
|
-
present && /* @__PURE__ */ (0,
|
|
9861
|
-
/* @__PURE__ */ (0,
|
|
11148
|
+
present && /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("span", { className: "awr-keyform__saved", children: [
|
|
11149
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)(CheckIcon, { size: 12 }),
|
|
9862
11150
|
" stored, encrypted"
|
|
9863
11151
|
] })
|
|
9864
11152
|
] }),
|
|
9865
|
-
/* @__PURE__ */ (0,
|
|
9866
|
-
/* @__PURE__ */ (0,
|
|
11153
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: "awr-keyform__row", children: [
|
|
11154
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
9867
11155
|
"input",
|
|
9868
11156
|
{
|
|
9869
11157
|
className: "awr-keyform__input",
|
|
@@ -9881,7 +11169,7 @@ var ApiKeyForm = ({
|
|
|
9881
11169
|
disabled: busy
|
|
9882
11170
|
}
|
|
9883
11171
|
),
|
|
9884
|
-
/* @__PURE__ */ (0,
|
|
11172
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
9885
11173
|
"button",
|
|
9886
11174
|
{
|
|
9887
11175
|
type: "button",
|
|
@@ -9891,7 +11179,7 @@ var ApiKeyForm = ({
|
|
|
9891
11179
|
children: "Save"
|
|
9892
11180
|
}
|
|
9893
11181
|
),
|
|
9894
|
-
present && /* @__PURE__ */ (0,
|
|
11182
|
+
present && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
9895
11183
|
"button",
|
|
9896
11184
|
{
|
|
9897
11185
|
type: "button",
|
|
@@ -9971,17 +11259,22 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
9971
11259
|
McpAppLine,
|
|
9972
11260
|
McpAppRpcError,
|
|
9973
11261
|
McpAppSandboxLink,
|
|
11262
|
+
MemoryCard,
|
|
9974
11263
|
MemoryCredentialStore,
|
|
9975
11264
|
MemorySkillStore,
|
|
9976
11265
|
MemoryStore,
|
|
9977
11266
|
MessageList,
|
|
11267
|
+
MicError,
|
|
9978
11268
|
ModelLoadBar,
|
|
9979
11269
|
PlanView,
|
|
9980
11270
|
QUESTION_TIMEOUT_MS,
|
|
9981
11271
|
QuestionPrompt,
|
|
11272
|
+
RECORDING_DEFAULT_MAX_MS,
|
|
11273
|
+
RECORDING_TYPES,
|
|
9982
11274
|
SandboxedFrame,
|
|
9983
11275
|
SessionBusyError,
|
|
9984
11276
|
SourceView,
|
|
11277
|
+
SpeechOutputError,
|
|
9985
11278
|
StepList,
|
|
9986
11279
|
SubagentRow,
|
|
9987
11280
|
SubagentTree,
|
|
@@ -10011,6 +11304,9 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
10011
11304
|
attachmentOverLimit,
|
|
10012
11305
|
attachmentRefusal,
|
|
10013
11306
|
attachmentTransformOf,
|
|
11307
|
+
attachmentsText,
|
|
11308
|
+
audioExtensionOf,
|
|
11309
|
+
audioTypeOf,
|
|
10014
11310
|
buildMcpAppDocument,
|
|
10015
11311
|
buildMcpAppSandboxShell,
|
|
10016
11312
|
buildSandboxedDocument,
|
|
@@ -10019,9 +11315,12 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
10019
11315
|
clampFrameHeight,
|
|
10020
11316
|
createAgent,
|
|
10021
11317
|
createApprovalQueue,
|
|
11318
|
+
createAudioSpeaker,
|
|
11319
|
+
createBrowserSpeaker,
|
|
10022
11320
|
createFileTools,
|
|
10023
11321
|
createInitialAgentState,
|
|
10024
11322
|
createQuestionQueue,
|
|
11323
|
+
createRecordingRecognizer,
|
|
10025
11324
|
createRunControl,
|
|
10026
11325
|
createSubagentTool,
|
|
10027
11326
|
createWebLLMEngine,
|
|
@@ -10041,6 +11340,7 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
10041
11340
|
filterCommands,
|
|
10042
11341
|
followsAfterResize,
|
|
10043
11342
|
followsAfterScroll,
|
|
11343
|
+
formatClock,
|
|
10044
11344
|
formatCountdown,
|
|
10045
11345
|
formatElapsed,
|
|
10046
11346
|
grantedAppCsp,
|
|
@@ -10048,6 +11348,7 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
10048
11348
|
imageSizeOf,
|
|
10049
11349
|
isMcpAppSandboxMessage,
|
|
10050
11350
|
isWebGPUAvailable,
|
|
11351
|
+
languageOfText,
|
|
10051
11352
|
lessonsOf,
|
|
10052
11353
|
linkedFilesOf,
|
|
10053
11354
|
loadSkillFromUrl,
|
|
@@ -10064,24 +11365,36 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
10064
11365
|
mergeChatRecord,
|
|
10065
11366
|
mergeLabels,
|
|
10066
11367
|
messageOverLimit,
|
|
11368
|
+
micProblemOf,
|
|
11369
|
+
micProblemText,
|
|
10067
11370
|
newChatId,
|
|
10068
11371
|
noticesOf,
|
|
10069
11372
|
onStorageChange,
|
|
10070
11373
|
parseSkillMarkdown,
|
|
10071
11374
|
parseSlash,
|
|
10072
11375
|
pendingApprovalsOf,
|
|
11376
|
+
pickRecordingType,
|
|
10073
11377
|
postStorageChange,
|
|
10074
11378
|
preloadWebLLMModel,
|
|
10075
11379
|
questionChoiceOf,
|
|
10076
11380
|
questionOtherOf,
|
|
10077
11381
|
questionTimeoutOf,
|
|
11382
|
+
recordingSupported,
|
|
10078
11383
|
resolveAppDownload,
|
|
10079
11384
|
sandboxTokens,
|
|
10080
11385
|
sandboxedCsp,
|
|
10081
11386
|
saveAppFile,
|
|
10082
11387
|
saveChat,
|
|
11388
|
+
scriptOfLanguage,
|
|
11389
|
+
scriptOfText,
|
|
10083
11390
|
serveSubagentWorker,
|
|
11391
|
+
settleAudioDuration,
|
|
11392
|
+
speakableText,
|
|
11393
|
+
speechSynthesisSupported,
|
|
11394
|
+
splitForSpeech,
|
|
11395
|
+
startRecording,
|
|
10084
11396
|
steerIntent,
|
|
11397
|
+
stopTracks,
|
|
10085
11398
|
subagentTree,
|
|
10086
11399
|
supportsImages,
|
|
10087
11400
|
supportsPdf,
|
|
@@ -10091,6 +11404,7 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
10091
11404
|
usageLine,
|
|
10092
11405
|
useAgent,
|
|
10093
11406
|
useAgentContext,
|
|
11407
|
+
useAudioRecorder,
|
|
10094
11408
|
useChatHistory,
|
|
10095
11409
|
useCredentials,
|
|
10096
11410
|
useFollowScroll,
|
|
@@ -10098,9 +11412,14 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
10098
11412
|
useLocalModel,
|
|
10099
11413
|
useMcpAppHost,
|
|
10100
11414
|
useOptionalAgentContext,
|
|
11415
|
+
useReadAloud,
|
|
10101
11416
|
useSpeechToText,
|
|
11417
|
+
useSpeechVoices,
|
|
10102
11418
|
useVirtualFiles,
|
|
10103
11419
|
useWebLLMModel,
|
|
11420
|
+
voiceFor,
|
|
11421
|
+
voiceMessageName,
|
|
11422
|
+
voicesOf,
|
|
10104
11423
|
watchSession,
|
|
10105
11424
|
webSearchOf,
|
|
10106
11425
|
withAttachments,
|