@smartspace/chat-ui 1.14.4-dev.1cf56dc → 1.14.4-dev.2306243
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +219 -134
- package/dist/index.js +696 -43
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import MuiButton from '@mui/material/Button';
|
|
2
|
-
import
|
|
3
|
-
import { Loader2, ChevronDown, Check, Cpu, SlidersHorizontal, X, Globe, Zap,
|
|
2
|
+
import IconButton2 from '@mui/material/IconButton';
|
|
3
|
+
import { Loader2, ChevronDown, Check, Cpu, SlidersHorizontal, X, Globe, Zap, Square, Mic, Paperclip, Send, Minimize2, AlertTriangle, FileImage, FileVideo, FileAudio, FileArchive, FileCode, FileSpreadsheet, Presentation, FileText, ChevronRight, ChevronUp, ExternalLink, Download, ShieldAlert, Copy } from 'lucide-react';
|
|
4
4
|
import * as React9 from 'react';
|
|
5
|
-
import React9__default, { createContext, forwardRef, useImperativeHandle, useRef, useState, useEffect, useMemo, useCallback, useContext, useSyncExternalStore } from 'react';
|
|
5
|
+
import React9__default, { createContext, forwardRef, useImperativeHandle, useRef, useState, useEffect, useMemo, useCallback, useContext, useSyncExternalStore, Fragment as Fragment$1 } from 'react';
|
|
6
6
|
import { createPortal } from 'react-dom';
|
|
7
7
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
8
8
|
import { useQuery, queryOptions, useQueryClient, useMutation } from '@tanstack/react-query';
|
|
@@ -17,7 +17,7 @@ import { codeBlockSchema, commonmark } from '@milkdown/preset-commonmark';
|
|
|
17
17
|
import { Slice, NodeType } from '@milkdown/prose/model';
|
|
18
18
|
import { MilkdownProvider, useEditor, Milkdown } from '@milkdown/react';
|
|
19
19
|
import { PluginKey, Plugin } from '@milkdown/prose/state';
|
|
20
|
-
import {
|
|
20
|
+
import { DecorationSet, Decoration } from '@milkdown/prose/view';
|
|
21
21
|
import 'crypto';
|
|
22
22
|
import '@milkdown/prose';
|
|
23
23
|
import '@milkdown/prose/inputrules';
|
|
@@ -842,6 +842,37 @@ function useMessages(threadId) {
|
|
|
842
842
|
});
|
|
843
843
|
}
|
|
844
844
|
|
|
845
|
+
// src/domains/speech/queryKeys.ts
|
|
846
|
+
var speechKeys = {
|
|
847
|
+
all: ["speech"],
|
|
848
|
+
config: () => [...speechKeys.all, "config"]
|
|
849
|
+
};
|
|
850
|
+
|
|
851
|
+
// src/domains/speech/queries.ts
|
|
852
|
+
var unavailable = { enabled: false, defaultLocale: "en-US" };
|
|
853
|
+
var isNotFound = (error) => error?.type === "NotFound" || error?.response?.status === 404;
|
|
854
|
+
function useSpeechConfig() {
|
|
855
|
+
const service = useChatService();
|
|
856
|
+
const supported = !!service.getSpeechConfig && !!service.getSpeechToken;
|
|
857
|
+
return useQuery({
|
|
858
|
+
...queryOptions({
|
|
859
|
+
queryKey: speechKeys.config(),
|
|
860
|
+
queryFn: async () => {
|
|
861
|
+
try {
|
|
862
|
+
return await service.getSpeechConfig?.() ?? unavailable;
|
|
863
|
+
} catch (error) {
|
|
864
|
+
if (isNotFound(error)) return unavailable;
|
|
865
|
+
throw error;
|
|
866
|
+
}
|
|
867
|
+
},
|
|
868
|
+
staleTime: Infinity,
|
|
869
|
+
retry: (failureCount) => failureCount < 2,
|
|
870
|
+
retryDelay: 1e3
|
|
871
|
+
}),
|
|
872
|
+
enabled: supported
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
|
|
845
876
|
// ../../node_modules/.pnpm/@milkdown+exception@7.20.0/node_modules/@milkdown/exception/lib/index.js
|
|
846
877
|
var ErrorCode = /* @__PURE__ */ (function(ErrorCode2) {
|
|
847
878
|
ErrorCode2["docTypeError"] = "docTypeError";
|
|
@@ -975,6 +1006,75 @@ var autolink = $prose(() => {
|
|
|
975
1006
|
}
|
|
976
1007
|
});
|
|
977
1008
|
});
|
|
1009
|
+
var dictationGhostKey = new PluginKey("dictationGhost");
|
|
1010
|
+
function buildDecorations2(state, text6) {
|
|
1011
|
+
const doc = state.doc;
|
|
1012
|
+
const from = state.selection.head;
|
|
1013
|
+
const before = from > 0 ? doc.textBetween(from - 1, from, " ") : "";
|
|
1014
|
+
const display = before !== "" && !/\s/.test(before) ? ` ${text6}` : text6;
|
|
1015
|
+
const widget = Decoration.widget(
|
|
1016
|
+
from,
|
|
1017
|
+
() => {
|
|
1018
|
+
const span = document.createElement("span");
|
|
1019
|
+
span.className = "md-editor__dictation-ghost";
|
|
1020
|
+
span.setAttribute("aria-hidden", "true");
|
|
1021
|
+
span.appendChild(document.createTextNode(display));
|
|
1022
|
+
const dots = document.createElement("span");
|
|
1023
|
+
dots.className = "md-editor__dictation-dots";
|
|
1024
|
+
for (let i = 0; i < 3; i += 1)
|
|
1025
|
+
dots.appendChild(document.createElement("span"));
|
|
1026
|
+
span.appendChild(dots);
|
|
1027
|
+
return span;
|
|
1028
|
+
},
|
|
1029
|
+
{
|
|
1030
|
+
// Render after the caret so typing still lands where the user expects.
|
|
1031
|
+
side: 1,
|
|
1032
|
+
// Keyed by content so ProseMirror reuses the node between renders instead
|
|
1033
|
+
// of tearing it down on every interim result.
|
|
1034
|
+
key: `dictation-ghost:${display}`
|
|
1035
|
+
}
|
|
1036
|
+
);
|
|
1037
|
+
const decorations = [widget];
|
|
1038
|
+
const $head = state.selection.$head;
|
|
1039
|
+
if ($head.depth > 0) {
|
|
1040
|
+
decorations.push(
|
|
1041
|
+
Decoration.node($head.before(), $head.after(), {
|
|
1042
|
+
class: "md-editor__has-dictation-ghost"
|
|
1043
|
+
})
|
|
1044
|
+
);
|
|
1045
|
+
}
|
|
1046
|
+
return DecorationSet.create(doc, decorations);
|
|
1047
|
+
}
|
|
1048
|
+
var dictationGhost = $prose(() => {
|
|
1049
|
+
return new Plugin({
|
|
1050
|
+
key: dictationGhostKey,
|
|
1051
|
+
state: {
|
|
1052
|
+
init: () => "",
|
|
1053
|
+
apply(tr, previous2) {
|
|
1054
|
+
const meta = tr.getMeta(dictationGhostKey);
|
|
1055
|
+
if (meta) return meta.text;
|
|
1056
|
+
if (tr.docChanged || tr.selectionSet) return "";
|
|
1057
|
+
return previous2;
|
|
1058
|
+
}
|
|
1059
|
+
},
|
|
1060
|
+
props: {
|
|
1061
|
+
decorations(state) {
|
|
1062
|
+
const text6 = dictationGhostKey.getState(state) ?? "";
|
|
1063
|
+
if (!text6) return DecorationSet.empty;
|
|
1064
|
+
return buildDecorations2(state, text6);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
});
|
|
1068
|
+
});
|
|
1069
|
+
function setDictationGhost(view, text6) {
|
|
1070
|
+
const current = dictationGhostKey.getState(view.state) ?? "";
|
|
1071
|
+
if (current === text6) return;
|
|
1072
|
+
const tr = view.state.tr.setMeta(dictationGhostKey, {
|
|
1073
|
+
text: text6
|
|
1074
|
+
});
|
|
1075
|
+
tr.setMeta("addToHistory", false);
|
|
1076
|
+
view.dispatch(tr);
|
|
1077
|
+
}
|
|
978
1078
|
|
|
979
1079
|
// src/shared/markdown/extensions/fileTag.ts
|
|
980
1080
|
var fileTag = $node("fileTag", () => ({
|
|
@@ -1884,7 +1984,7 @@ function EditorInner({
|
|
|
1884
1984
|
} catch {
|
|
1885
1985
|
}
|
|
1886
1986
|
});
|
|
1887
|
-
}).use(commonmark).use(history).use(clipboard).use(listener).use(autolink).use(fileTag).use(ssImageNode).use(ssImageView).use(htmlPreviewView).use(enableMentions ? mention : fileTag);
|
|
1987
|
+
}).use(commonmark).use(history).use(clipboard).use(listener).use(autolink).use(dictationGhost).use(fileTag).use(ssImageNode).use(ssImageView).use(htmlPreviewView).use(enableMentions ? mention : fileTag);
|
|
1888
1988
|
},
|
|
1889
1989
|
[isEditable]
|
|
1890
1990
|
);
|
|
@@ -2094,6 +2194,25 @@ function EditorInner({
|
|
|
2094
2194
|
return value ?? "";
|
|
2095
2195
|
}
|
|
2096
2196
|
},
|
|
2197
|
+
insertText: (text6) => {
|
|
2198
|
+
const view = viewRef.current;
|
|
2199
|
+
if (!view || !isEditable || !text6) return;
|
|
2200
|
+
try {
|
|
2201
|
+
const { from } = view.state.selection;
|
|
2202
|
+
const before = from > 0 ? view.state.doc.textBetween(from - 1, from, " ") : "";
|
|
2203
|
+
const needsSpace = before !== "" && !/\s/.test(before);
|
|
2204
|
+
insertTextAtSelection(view, (needsSpace ? " " : "") + text6);
|
|
2205
|
+
} catch {
|
|
2206
|
+
}
|
|
2207
|
+
},
|
|
2208
|
+
setDictationGhost: (text6) => {
|
|
2209
|
+
const view = viewRef.current;
|
|
2210
|
+
if (!view || !isEditable) return;
|
|
2211
|
+
try {
|
|
2212
|
+
setDictationGhost(view, text6);
|
|
2213
|
+
} catch {
|
|
2214
|
+
}
|
|
2215
|
+
},
|
|
2097
2216
|
clear: () => {
|
|
2098
2217
|
const view = viewRef.current;
|
|
2099
2218
|
if (!view) return;
|
|
@@ -2437,6 +2556,327 @@ var MarkdownEditor = forwardRef((props, ref) => {
|
|
|
2437
2556
|
return /* @__PURE__ */ jsx(MilkdownProvider, { children: /* @__PURE__ */ jsx(EditorInner, { ...props, editorHandleRef: ref }) });
|
|
2438
2557
|
});
|
|
2439
2558
|
MarkdownEditor.displayName = "MarkdownEditor";
|
|
2559
|
+
var TOKEN_EXPIRY_MARGIN_MS = 15e3;
|
|
2560
|
+
var noLevelMonitor = () => void 0;
|
|
2561
|
+
var SILENCE_HINT_MS = 6e3;
|
|
2562
|
+
var SILENCE_LEVEL = 3;
|
|
2563
|
+
function monitorInputLevel(stream, onSilent, onSound) {
|
|
2564
|
+
let context;
|
|
2565
|
+
let source;
|
|
2566
|
+
let analyser;
|
|
2567
|
+
try {
|
|
2568
|
+
context = new AudioContext();
|
|
2569
|
+
source = context.createMediaStreamSource(stream);
|
|
2570
|
+
analyser = context.createAnalyser();
|
|
2571
|
+
analyser.fftSize = 512;
|
|
2572
|
+
source.connect(analyser);
|
|
2573
|
+
} catch {
|
|
2574
|
+
return () => void 0;
|
|
2575
|
+
}
|
|
2576
|
+
if (context.state === "suspended")
|
|
2577
|
+
void context.resume().catch(() => void 0);
|
|
2578
|
+
const samples = new Uint8Array(analyser.fftSize);
|
|
2579
|
+
let lastSound = Date.now();
|
|
2580
|
+
let silent = false;
|
|
2581
|
+
let stopped = false;
|
|
2582
|
+
const poll = window.setInterval(() => {
|
|
2583
|
+
if (context.state !== "running") return;
|
|
2584
|
+
analyser.getByteTimeDomainData(samples);
|
|
2585
|
+
let peak = 0;
|
|
2586
|
+
for (const sample of samples) peak = Math.max(peak, Math.abs(sample - 128));
|
|
2587
|
+
if (peak > SILENCE_LEVEL) {
|
|
2588
|
+
lastSound = Date.now();
|
|
2589
|
+
if (silent) {
|
|
2590
|
+
silent = false;
|
|
2591
|
+
onSound();
|
|
2592
|
+
}
|
|
2593
|
+
} else if (!silent && Date.now() - lastSound > SILENCE_HINT_MS) {
|
|
2594
|
+
silent = true;
|
|
2595
|
+
onSilent();
|
|
2596
|
+
}
|
|
2597
|
+
}, 250);
|
|
2598
|
+
return () => {
|
|
2599
|
+
if (stopped) return;
|
|
2600
|
+
stopped = true;
|
|
2601
|
+
window.clearInterval(poll);
|
|
2602
|
+
try {
|
|
2603
|
+
source.disconnect();
|
|
2604
|
+
void context.close().catch(() => void 0);
|
|
2605
|
+
} catch {
|
|
2606
|
+
}
|
|
2607
|
+
};
|
|
2608
|
+
}
|
|
2609
|
+
var STALE_TOKEN_FLOOR_MS = 6e4;
|
|
2610
|
+
function kickOff(fn) {
|
|
2611
|
+
let promise;
|
|
2612
|
+
try {
|
|
2613
|
+
promise = Promise.resolve(fn());
|
|
2614
|
+
} catch (e) {
|
|
2615
|
+
promise = Promise.reject(e);
|
|
2616
|
+
}
|
|
2617
|
+
promise.catch(() => void 0);
|
|
2618
|
+
return promise;
|
|
2619
|
+
}
|
|
2620
|
+
var isSupported = () => typeof window !== "undefined" && window.isSecureContext && !!navigator.mediaDevices?.getUserMedia;
|
|
2621
|
+
function classifyTokenFailure(error) {
|
|
2622
|
+
const code3 = error?.code;
|
|
2623
|
+
if (code3 === "speech.identity_misconfigured" || code3 === "SP500")
|
|
2624
|
+
return "unavailable";
|
|
2625
|
+
if (error?.type === "NotFound") {
|
|
2626
|
+
return "unavailable";
|
|
2627
|
+
}
|
|
2628
|
+
return "unavailable-temporarily";
|
|
2629
|
+
}
|
|
2630
|
+
function useDictation({
|
|
2631
|
+
region,
|
|
2632
|
+
locale,
|
|
2633
|
+
getToken,
|
|
2634
|
+
onPhrase,
|
|
2635
|
+
onInterim,
|
|
2636
|
+
maxDurationMs = 18e4,
|
|
2637
|
+
idleTimeoutMs = 2e4
|
|
2638
|
+
}) {
|
|
2639
|
+
const [state, setState] = useState("idle");
|
|
2640
|
+
const [error, setError] = useState(null);
|
|
2641
|
+
const [deviceLabel, setDeviceLabel] = useState("");
|
|
2642
|
+
const [silent, setSilent] = useState(false);
|
|
2643
|
+
const sessionRef = useRef(null);
|
|
2644
|
+
const generationRef = useRef(0);
|
|
2645
|
+
const onPhraseRef = useRef(onPhrase);
|
|
2646
|
+
const onInterimRef = useRef(onInterim);
|
|
2647
|
+
useEffect(() => {
|
|
2648
|
+
onPhraseRef.current = onPhrase;
|
|
2649
|
+
onInterimRef.current = onInterim;
|
|
2650
|
+
});
|
|
2651
|
+
const clearInterim = useCallback(() => onInterimRef.current?.(""), []);
|
|
2652
|
+
const supported = isSupported();
|
|
2653
|
+
const available = supported && !!region && !!getToken;
|
|
2654
|
+
useEffect(() => {
|
|
2655
|
+
if (!available) return;
|
|
2656
|
+
const nav = navigator;
|
|
2657
|
+
if (nav.connection?.saveData) return;
|
|
2658
|
+
const warm = () => void kickOff(() => import('microsoft-cognitiveservices-speech-sdk'));
|
|
2659
|
+
if (typeof window.requestIdleCallback === "function") {
|
|
2660
|
+
const id2 = window.requestIdleCallback(warm, { timeout: 2e3 });
|
|
2661
|
+
return () => window.cancelIdleCallback(id2);
|
|
2662
|
+
}
|
|
2663
|
+
const id = window.setTimeout(warm, 1500);
|
|
2664
|
+
return () => window.clearTimeout(id);
|
|
2665
|
+
}, [available]);
|
|
2666
|
+
const stop = useCallback(() => {
|
|
2667
|
+
generationRef.current += 1;
|
|
2668
|
+
const session = sessionRef.current;
|
|
2669
|
+
sessionRef.current = null;
|
|
2670
|
+
clearInterim();
|
|
2671
|
+
setState("idle");
|
|
2672
|
+
setSilent(false);
|
|
2673
|
+
setDeviceLabel("");
|
|
2674
|
+
if (!session) return;
|
|
2675
|
+
window.clearTimeout(session.timers.idle);
|
|
2676
|
+
window.clearTimeout(session.timers.max);
|
|
2677
|
+
session.stopLevelMonitor();
|
|
2678
|
+
session.stream.getTracks().forEach((t) => t.stop());
|
|
2679
|
+
session.recognizer.stopContinuousRecognitionAsync(
|
|
2680
|
+
() => session.recognizer.close(),
|
|
2681
|
+
() => session.recognizer.close()
|
|
2682
|
+
);
|
|
2683
|
+
}, [clearInterim]);
|
|
2684
|
+
const start = useCallback(async () => {
|
|
2685
|
+
if (!available || sessionRef.current) return;
|
|
2686
|
+
const generation = ++generationRef.current;
|
|
2687
|
+
const superseded = () => generationRef.current !== generation;
|
|
2688
|
+
setError(null);
|
|
2689
|
+
setSilent(false);
|
|
2690
|
+
setState("starting");
|
|
2691
|
+
const streamPromise = kickOff(
|
|
2692
|
+
() => navigator.mediaDevices.getUserMedia({
|
|
2693
|
+
audio: {
|
|
2694
|
+
echoCancellation: true,
|
|
2695
|
+
noiseSuppression: true,
|
|
2696
|
+
autoGainControl: true
|
|
2697
|
+
}
|
|
2698
|
+
})
|
|
2699
|
+
);
|
|
2700
|
+
const tokenPromise = kickOff(getToken);
|
|
2701
|
+
const sdkPromise = kickOff(
|
|
2702
|
+
() => import('microsoft-cognitiveservices-speech-sdk')
|
|
2703
|
+
);
|
|
2704
|
+
let stream;
|
|
2705
|
+
try {
|
|
2706
|
+
stream = await streamPromise;
|
|
2707
|
+
} catch (e) {
|
|
2708
|
+
if (superseded()) return;
|
|
2709
|
+
const name = e?.name;
|
|
2710
|
+
setError(
|
|
2711
|
+
name === "NotAllowedError" || name === "SecurityError" ? "permission-denied" : name === "NotFoundError" || name === "OverconstrainedError" ? "no-microphone" : "unknown"
|
|
2712
|
+
);
|
|
2713
|
+
setState("idle");
|
|
2714
|
+
return;
|
|
2715
|
+
}
|
|
2716
|
+
if (superseded()) {
|
|
2717
|
+
stream.getTracks().forEach((t) => t.stop());
|
|
2718
|
+
return;
|
|
2719
|
+
}
|
|
2720
|
+
let token;
|
|
2721
|
+
try {
|
|
2722
|
+
token = await tokenPromise;
|
|
2723
|
+
if (Date.parse(token.expiresOn) - Date.now() < STALE_TOKEN_FLOOR_MS) {
|
|
2724
|
+
token = await getToken();
|
|
2725
|
+
}
|
|
2726
|
+
} catch (e) {
|
|
2727
|
+
stream.getTracks().forEach((t) => t.stop());
|
|
2728
|
+
if (superseded()) return;
|
|
2729
|
+
setError(classifyTokenFailure(e));
|
|
2730
|
+
setState("idle");
|
|
2731
|
+
return;
|
|
2732
|
+
}
|
|
2733
|
+
if (superseded()) {
|
|
2734
|
+
stream.getTracks().forEach((t) => t.stop());
|
|
2735
|
+
return;
|
|
2736
|
+
}
|
|
2737
|
+
let recognizer = null;
|
|
2738
|
+
let published = null;
|
|
2739
|
+
try {
|
|
2740
|
+
const sdk = await sdkPromise;
|
|
2741
|
+
if (superseded()) {
|
|
2742
|
+
stream.getTracks().forEach((t) => t.stop());
|
|
2743
|
+
return;
|
|
2744
|
+
}
|
|
2745
|
+
const speechConfig = sdk.SpeechConfig.fromAuthorizationToken(
|
|
2746
|
+
token.token,
|
|
2747
|
+
region
|
|
2748
|
+
);
|
|
2749
|
+
speechConfig.speechRecognitionLanguage = locale;
|
|
2750
|
+
speechConfig.setProfanity(sdk.ProfanityOption.Raw);
|
|
2751
|
+
speechConfig.setProperty(
|
|
2752
|
+
sdk.PropertyId.Speech_SegmentationSilenceTimeoutMs,
|
|
2753
|
+
"700"
|
|
2754
|
+
);
|
|
2755
|
+
recognizer = new sdk.SpeechRecognizer(
|
|
2756
|
+
speechConfig,
|
|
2757
|
+
sdk.AudioConfig.fromStreamInput(stream)
|
|
2758
|
+
);
|
|
2759
|
+
const untilExpiry = Date.parse(token.expiresOn) - Date.now() - TOKEN_EXPIRY_MARGIN_MS;
|
|
2760
|
+
const sessionCapMs = Number.isFinite(untilExpiry) && untilExpiry > 0 ? Math.min(maxDurationMs, untilExpiry) : maxDurationMs;
|
|
2761
|
+
const session = {
|
|
2762
|
+
recognizer,
|
|
2763
|
+
stream,
|
|
2764
|
+
timers: {},
|
|
2765
|
+
stopLevelMonitor: noLevelMonitor
|
|
2766
|
+
};
|
|
2767
|
+
const armIdle = () => {
|
|
2768
|
+
window.clearTimeout(session.timers.idle);
|
|
2769
|
+
session.timers.idle = window.setTimeout(stop, idleTimeoutMs);
|
|
2770
|
+
};
|
|
2771
|
+
const isLive = () => sessionRef.current === session;
|
|
2772
|
+
sessionRef.current = session;
|
|
2773
|
+
published = session;
|
|
2774
|
+
const goLive = () => {
|
|
2775
|
+
if (!isLive()) return;
|
|
2776
|
+
session.timers.max ??= window.setTimeout(stop, sessionCapMs);
|
|
2777
|
+
if (session.stopLevelMonitor === noLevelMonitor) {
|
|
2778
|
+
try {
|
|
2779
|
+
setDeviceLabel(stream.getAudioTracks()[0]?.label ?? "");
|
|
2780
|
+
session.stopLevelMonitor = monitorInputLevel(
|
|
2781
|
+
stream,
|
|
2782
|
+
() => {
|
|
2783
|
+
if (isLive()) setSilent(true);
|
|
2784
|
+
},
|
|
2785
|
+
() => {
|
|
2786
|
+
if (isLive()) setSilent(false);
|
|
2787
|
+
}
|
|
2788
|
+
);
|
|
2789
|
+
} catch {
|
|
2790
|
+
session.stopLevelMonitor = noLevelMonitor;
|
|
2791
|
+
}
|
|
2792
|
+
}
|
|
2793
|
+
armIdle();
|
|
2794
|
+
setState("listening");
|
|
2795
|
+
};
|
|
2796
|
+
recognizer.sessionStarted = () => goLive();
|
|
2797
|
+
recognizer.recognizing = (_sender, event) => {
|
|
2798
|
+
if (!isLive()) return;
|
|
2799
|
+
onInterimRef.current?.(event.result.text ?? "");
|
|
2800
|
+
armIdle();
|
|
2801
|
+
};
|
|
2802
|
+
recognizer.recognized = (_sender, event) => {
|
|
2803
|
+
if (!isLive()) return;
|
|
2804
|
+
const text6 = event.result.text?.trim();
|
|
2805
|
+
clearInterim();
|
|
2806
|
+
if (event.result.reason === sdk.ResultReason.RecognizedSpeech && text6) {
|
|
2807
|
+
onPhraseRef.current(text6);
|
|
2808
|
+
}
|
|
2809
|
+
armIdle();
|
|
2810
|
+
};
|
|
2811
|
+
recognizer.canceled = (_sender, event) => {
|
|
2812
|
+
if (!isLive()) return;
|
|
2813
|
+
if (event.reason === sdk.CancellationReason.Error) {
|
|
2814
|
+
console.warn("[dictation] cancelled, errorCode:", event.errorCode);
|
|
2815
|
+
setError(
|
|
2816
|
+
event.errorCode === sdk.CancellationErrorCode.ConnectionFailure ? "network" : event.errorCode === sdk.CancellationErrorCode.AuthenticationFailure ? "unavailable-temporarily" : "unknown"
|
|
2817
|
+
);
|
|
2818
|
+
}
|
|
2819
|
+
stop();
|
|
2820
|
+
};
|
|
2821
|
+
recognizer.sessionStopped = () => {
|
|
2822
|
+
if (isLive()) stop();
|
|
2823
|
+
};
|
|
2824
|
+
try {
|
|
2825
|
+
const connection = sdk.Connection.fromRecognizer(recognizer);
|
|
2826
|
+
connection.connected = () => goLive();
|
|
2827
|
+
connection.openConnection();
|
|
2828
|
+
} catch {
|
|
2829
|
+
}
|
|
2830
|
+
await new Promise(
|
|
2831
|
+
(resolve, reject) => session.recognizer.startContinuousRecognitionAsync(resolve, reject)
|
|
2832
|
+
);
|
|
2833
|
+
goLive();
|
|
2834
|
+
} catch (e) {
|
|
2835
|
+
stream.getTracks().forEach((t) => t.stop());
|
|
2836
|
+
try {
|
|
2837
|
+
recognizer?.close();
|
|
2838
|
+
} catch {
|
|
2839
|
+
}
|
|
2840
|
+
if (published) {
|
|
2841
|
+
window.clearTimeout(published.timers.idle);
|
|
2842
|
+
window.clearTimeout(published.timers.max);
|
|
2843
|
+
published.stopLevelMonitor();
|
|
2844
|
+
if (sessionRef.current === published) sessionRef.current = null;
|
|
2845
|
+
}
|
|
2846
|
+
if (superseded()) return;
|
|
2847
|
+
console.warn("[dictation] failed to start:", e);
|
|
2848
|
+
setError((prev) => prev ?? "unavailable-temporarily");
|
|
2849
|
+
setState("idle");
|
|
2850
|
+
}
|
|
2851
|
+
}, [
|
|
2852
|
+
available,
|
|
2853
|
+
clearInterim,
|
|
2854
|
+
getToken,
|
|
2855
|
+
idleTimeoutMs,
|
|
2856
|
+
locale,
|
|
2857
|
+
maxDurationMs,
|
|
2858
|
+
region,
|
|
2859
|
+
stop
|
|
2860
|
+
]);
|
|
2861
|
+
useEffect(() => stop, [stop]);
|
|
2862
|
+
const toggle = useCallback(() => {
|
|
2863
|
+
if (state === "idle") void start();
|
|
2864
|
+
else stop();
|
|
2865
|
+
}, [start, state, stop]);
|
|
2866
|
+
return {
|
|
2867
|
+
supported,
|
|
2868
|
+
available,
|
|
2869
|
+
state,
|
|
2870
|
+
error,
|
|
2871
|
+
/** Name of the microphone in use, once a session is live. May be ''. */
|
|
2872
|
+
deviceLabel,
|
|
2873
|
+
/** Listening, but the microphone has produced no sound for a while. */
|
|
2874
|
+
silent,
|
|
2875
|
+
start,
|
|
2876
|
+
stop,
|
|
2877
|
+
toggle
|
|
2878
|
+
};
|
|
2879
|
+
}
|
|
2440
2880
|
function useFlowRunVariables(flowRunId) {
|
|
2441
2881
|
const service = useChatService();
|
|
2442
2882
|
return useQuery({
|
|
@@ -3742,6 +4182,58 @@ var ChatVariablesForm = forwardRef(({ workspace, threadId, setVariables }, ref)
|
|
|
3742
4182
|
) }) })
|
|
3743
4183
|
] });
|
|
3744
4184
|
});
|
|
4185
|
+
var dictationErrorMessages = {
|
|
4186
|
+
"permission-denied": "Microphone access is blocked \u2014 allow it in your browser settings and try again",
|
|
4187
|
+
"no-microphone": "No microphone was found",
|
|
4188
|
+
network: "Could not reach the speech service \u2014 try again",
|
|
4189
|
+
"unavailable-temporarily": "Dictation is starting up \u2014 try again in a moment",
|
|
4190
|
+
unavailable: "Dictation is not available on this workspace",
|
|
4191
|
+
unknown: "Dictation stopped unexpectedly \u2014 try again"
|
|
4192
|
+
};
|
|
4193
|
+
function DictationButton({
|
|
4194
|
+
state,
|
|
4195
|
+
error,
|
|
4196
|
+
disabled,
|
|
4197
|
+
onToggle,
|
|
4198
|
+
deviceLabel,
|
|
4199
|
+
size = "sm"
|
|
4200
|
+
}) {
|
|
4201
|
+
const listening = state === "listening";
|
|
4202
|
+
const starting = state === "starting";
|
|
4203
|
+
const label = listening ? "Stop dictation" : "Dictate a message";
|
|
4204
|
+
const hint = listening && deviceLabel ? `${label} \u2014 ${deviceLabel}` : label;
|
|
4205
|
+
const dims = size === "sm" ? "h-8 w-8" : "h-9 w-9";
|
|
4206
|
+
const icon = size === "sm" ? "h-4 w-4" : "h-5 w-5";
|
|
4207
|
+
return /* @__PURE__ */ jsxs(
|
|
4208
|
+
IconButton2,
|
|
4209
|
+
{
|
|
4210
|
+
type: "button",
|
|
4211
|
+
onClick: onToggle,
|
|
4212
|
+
disabled,
|
|
4213
|
+
"aria-pressed": listening,
|
|
4214
|
+
"aria-label": label,
|
|
4215
|
+
title: error ? dictationErrorMessages[error] : hint,
|
|
4216
|
+
className: `relative ${dims} rounded-full transition-colors ${listening ? "bg-destructive text-destructive-foreground hover:bg-destructive/90" : "text-muted-foreground hover:bg-secondary"}`,
|
|
4217
|
+
children: [
|
|
4218
|
+
starting && /* @__PURE__ */ jsx(
|
|
4219
|
+
"span",
|
|
4220
|
+
{
|
|
4221
|
+
"aria-hidden": "true",
|
|
4222
|
+
className: "absolute inset-0 animate-spin rounded-full border-2 border-transparent border-t-current opacity-70"
|
|
4223
|
+
}
|
|
4224
|
+
),
|
|
4225
|
+
listening && /* @__PURE__ */ jsx(
|
|
4226
|
+
"span",
|
|
4227
|
+
{
|
|
4228
|
+
"aria-hidden": "true",
|
|
4229
|
+
className: "absolute inset-0 animate-ping rounded-full bg-destructive/30"
|
|
4230
|
+
}
|
|
4231
|
+
),
|
|
4232
|
+
listening ? /* @__PURE__ */ jsx(Square, { className: `relative ${icon} fill-current` }) : /* @__PURE__ */ jsx(Mic, { className: `relative ${icon}` })
|
|
4233
|
+
]
|
|
4234
|
+
}
|
|
4235
|
+
);
|
|
4236
|
+
}
|
|
3745
4237
|
|
|
3746
4238
|
// src/domains/workspaces/queryKeys.ts
|
|
3747
4239
|
var workspaceKeys = {
|
|
@@ -3974,6 +4466,40 @@ function MessageComposer(_props = {}) {
|
|
|
3974
4466
|
cancelReset();
|
|
3975
4467
|
}
|
|
3976
4468
|
}, [isSending, cancelAccepted, cancelErrored, cancelReset]);
|
|
4469
|
+
const attachEditor = useCallback(
|
|
4470
|
+
(handle2) => {
|
|
4471
|
+
if (handle2) editorRef.current = handle2;
|
|
4472
|
+
},
|
|
4473
|
+
// Both flags matter: the portal mounts on `isMobile && isFullscreen`, and
|
|
4474
|
+
// nothing resets isFullscreen when the breakpoint flips, so crossing it
|
|
4475
|
+
// while fullscreen would unmount the portal editor without re-attaching the
|
|
4476
|
+
// inline one — leaving a destroyed handle and silently swallowing phrases.
|
|
4477
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4478
|
+
[isFullscreen, isMobile]
|
|
4479
|
+
);
|
|
4480
|
+
const { data: speechConfig, isFetching: speechConfigLoading } = useSpeechConfig();
|
|
4481
|
+
const getSpeechToken = useMemo(
|
|
4482
|
+
() => chatService.getSpeechToken?.bind(chatService),
|
|
4483
|
+
[chatService]
|
|
4484
|
+
);
|
|
4485
|
+
const dictation = useDictation({
|
|
4486
|
+
region: speechConfig?.enabled ? speechConfig.region : null,
|
|
4487
|
+
locale: speechConfig?.defaultLocale ?? "en-US",
|
|
4488
|
+
getToken: getSpeechToken,
|
|
4489
|
+
// Final phrases become real text; provisional ones render as greyed ghost
|
|
4490
|
+
// text at the caret and never enter the document.
|
|
4491
|
+
onPhrase: (text6) => editorRef.current?.insertText(`${text6} `),
|
|
4492
|
+
onInterim: (text6) => editorRef.current?.setDictationGhost(text6)
|
|
4493
|
+
});
|
|
4494
|
+
const { stop: stopDictation } = dictation;
|
|
4495
|
+
const dictationUnavailableReason = speechConfigLoading ? "Checking whether dictation is available" : dictation.supported ? "Dictation is not enabled for this workspace" : "Dictation is not available in this browser";
|
|
4496
|
+
const handleDictationToggle = () => {
|
|
4497
|
+
if (dictation.state === "idle") editorRef.current?.focus();
|
|
4498
|
+
dictation.toggle();
|
|
4499
|
+
};
|
|
4500
|
+
useEffect(() => {
|
|
4501
|
+
if (disabled) stopDictation();
|
|
4502
|
+
}, [disabled, stopDictation]);
|
|
3977
4503
|
useEffect(() => {
|
|
3978
4504
|
if (typeof window === "undefined") return;
|
|
3979
4505
|
window.__ssDownloadFile = (id) => getFileBlobUrl(id);
|
|
@@ -4093,6 +4619,7 @@ function MessageComposer(_props = {}) {
|
|
|
4093
4619
|
const latestText = editorRef.current?.getMarkdown() ?? newMessage;
|
|
4094
4620
|
const sent = handleSendMessage(latestText, uploadedAttachments);
|
|
4095
4621
|
if (!sent) return;
|
|
4622
|
+
stopDictation();
|
|
4096
4623
|
handleClearAttachments();
|
|
4097
4624
|
setEditorKey((k) => k + 1);
|
|
4098
4625
|
};
|
|
@@ -4199,7 +4726,7 @@ function MessageComposer(_props = {}) {
|
|
|
4199
4726
|
/* @__PURE__ */ jsx("div", { className: "max-h-[400px] w-full overflow-y-auto", children: /* @__PURE__ */ jsx(
|
|
4200
4727
|
MarkdownEditor,
|
|
4201
4728
|
{
|
|
4202
|
-
ref:
|
|
4729
|
+
ref: attachEditor,
|
|
4203
4730
|
value: newMessage,
|
|
4204
4731
|
onChange: (md) => setNewMessage(md),
|
|
4205
4732
|
onKeyDown: handleComposerKeyDown,
|
|
@@ -4216,10 +4743,18 @@ function MessageComposer(_props = {}) {
|
|
|
4216
4743
|
},
|
|
4217
4744
|
`composer-md-${editorKey}`
|
|
4218
4745
|
) }),
|
|
4746
|
+
/* @__PURE__ */ jsx("div", { role: "status", className: "sr-only", children: dictation.state === "listening" ? dictation.silent ? `Listening, but not hearing anything from ${dictation.deviceLabel || "your microphone"}` : "Listening" : dictation.state === "starting" ? "Starting dictation" : "" }),
|
|
4747
|
+
dictation.state === "listening" && dictation.silent && /* @__PURE__ */ jsxs("div", { className: "px-5 pb-1 text-xs text-muted-foreground", children: [
|
|
4748
|
+
"Not hearing anything from",
|
|
4749
|
+
" ",
|
|
4750
|
+
dictation.deviceLabel || "your microphone",
|
|
4751
|
+
"."
|
|
4752
|
+
] }),
|
|
4753
|
+
dictation.error && /* @__PURE__ */ jsx("div", { role: "alert", className: "px-5 pb-1 text-xs text-destructive", children: dictationErrorMessages[dictation.error] }),
|
|
4219
4754
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2 px-3 pb-3", children: [
|
|
4220
4755
|
/* @__PURE__ */ jsxs("div", { className: "ss-composer__actions flex min-w-0 flex-1 items-center gap-1", children: [
|
|
4221
4756
|
supportsFiles && /* @__PURE__ */ jsx(
|
|
4222
|
-
|
|
4757
|
+
IconButton2,
|
|
4223
4758
|
{
|
|
4224
4759
|
type: "button",
|
|
4225
4760
|
onClick: handlePickFilesClick,
|
|
@@ -4240,19 +4775,39 @@ function MessageComposer(_props = {}) {
|
|
|
4240
4775
|
)
|
|
4241
4776
|
] }),
|
|
4242
4777
|
/* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-1.5", children: [
|
|
4243
|
-
/* @__PURE__ */ jsx(
|
|
4244
|
-
|
|
4778
|
+
dictation.available ? /* @__PURE__ */ jsx(
|
|
4779
|
+
DictationButton,
|
|
4245
4780
|
{
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
children: /* @__PURE__ */ jsx(Mic, { className: "h-4 w-4" })
|
|
4781
|
+
state: dictation.state,
|
|
4782
|
+
error: dictation.error,
|
|
4783
|
+
disabled,
|
|
4784
|
+
onToggle: handleDictationToggle,
|
|
4785
|
+
deviceLabel: dictation.deviceLabel
|
|
4252
4786
|
}
|
|
4787
|
+
) : (
|
|
4788
|
+
// A disabled button receives no pointer events, so its own
|
|
4789
|
+
// `title` never renders a tooltip. The wrapper is what the user
|
|
4790
|
+
// actually hovers.
|
|
4791
|
+
/* @__PURE__ */ jsx(
|
|
4792
|
+
"span",
|
|
4793
|
+
{
|
|
4794
|
+
title: dictationUnavailableReason,
|
|
4795
|
+
className: "inline-flex cursor-not-allowed",
|
|
4796
|
+
children: /* @__PURE__ */ jsx(
|
|
4797
|
+
IconButton2,
|
|
4798
|
+
{
|
|
4799
|
+
type: "button",
|
|
4800
|
+
disabled: true,
|
|
4801
|
+
"aria-label": `Dictate a message. ${dictationUnavailableReason}`,
|
|
4802
|
+
className: "h-8 w-8 rounded-full text-muted-foreground",
|
|
4803
|
+
children: /* @__PURE__ */ jsx(Mic, { className: "h-4 w-4" })
|
|
4804
|
+
}
|
|
4805
|
+
)
|
|
4806
|
+
}
|
|
4807
|
+
)
|
|
4253
4808
|
),
|
|
4254
4809
|
canStop ? /* @__PURE__ */ jsx(
|
|
4255
|
-
|
|
4810
|
+
IconButton2,
|
|
4256
4811
|
{
|
|
4257
4812
|
onClick: handleStopRun,
|
|
4258
4813
|
className: "chat-send h-8 w-8 rounded-full",
|
|
@@ -4266,7 +4821,7 @@ function MessageComposer(_props = {}) {
|
|
|
4266
4821
|
)
|
|
4267
4822
|
}
|
|
4268
4823
|
) : /* @__PURE__ */ jsx(
|
|
4269
|
-
|
|
4824
|
+
IconButton2,
|
|
4270
4825
|
{
|
|
4271
4826
|
onClick: handleSendMessageAndClear,
|
|
4272
4827
|
className: `chat-send h-8 w-8 rounded-full ${sendDisabled ? "cursor-not-allowed" : ""}`,
|
|
@@ -4295,7 +4850,7 @@ function MessageComposer(_props = {}) {
|
|
|
4295
4850
|
},
|
|
4296
4851
|
children: /* @__PURE__ */ jsxs("div", { className: "relative h-full w-full bg-background border shadow-lg", children: [
|
|
4297
4852
|
/* @__PURE__ */ jsx(
|
|
4298
|
-
|
|
4853
|
+
IconButton2,
|
|
4299
4854
|
{
|
|
4300
4855
|
type: "button",
|
|
4301
4856
|
size: "small",
|
|
@@ -4313,7 +4868,7 @@ function MessageComposer(_props = {}) {
|
|
|
4313
4868
|
/* @__PURE__ */ jsx("div", { className: "flex-1 p-4", children: /* @__PURE__ */ jsx(
|
|
4314
4869
|
MarkdownEditor,
|
|
4315
4870
|
{
|
|
4316
|
-
ref:
|
|
4871
|
+
ref: attachEditor,
|
|
4317
4872
|
value: newMessage,
|
|
4318
4873
|
onChange: (md) => setNewMessage(md),
|
|
4319
4874
|
onKeyDown: handleComposerKeyDown,
|
|
@@ -4328,10 +4883,18 @@ function MessageComposer(_props = {}) {
|
|
|
4328
4883
|
},
|
|
4329
4884
|
`composer-md-${editorKey}`
|
|
4330
4885
|
) }),
|
|
4886
|
+
dictation.error && /* @__PURE__ */ jsx(
|
|
4887
|
+
"div",
|
|
4888
|
+
{
|
|
4889
|
+
"aria-hidden": "true",
|
|
4890
|
+
className: "px-4 pb-1 text-xs text-destructive",
|
|
4891
|
+
children: dictationErrorMessages[dictation.error]
|
|
4892
|
+
}
|
|
4893
|
+
),
|
|
4331
4894
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 px-3 py-2 border-t bg-background", children: [
|
|
4332
4895
|
/* @__PURE__ */ jsx("div", { className: "flex-1" }),
|
|
4333
4896
|
supportsFiles && /* @__PURE__ */ jsx(
|
|
4334
|
-
|
|
4897
|
+
IconButton2,
|
|
4335
4898
|
{
|
|
4336
4899
|
type: "button",
|
|
4337
4900
|
onClick: handlePickFilesClick,
|
|
@@ -4346,8 +4909,19 @@ function MessageComposer(_props = {}) {
|
|
|
4346
4909
|
)
|
|
4347
4910
|
}
|
|
4348
4911
|
),
|
|
4912
|
+
dictation.available && /* @__PURE__ */ jsx(
|
|
4913
|
+
DictationButton,
|
|
4914
|
+
{
|
|
4915
|
+
size: "md",
|
|
4916
|
+
state: dictation.state,
|
|
4917
|
+
error: dictation.error,
|
|
4918
|
+
disabled,
|
|
4919
|
+
onToggle: handleDictationToggle,
|
|
4920
|
+
deviceLabel: dictation.deviceLabel
|
|
4921
|
+
}
|
|
4922
|
+
),
|
|
4349
4923
|
canStop ? /* @__PURE__ */ jsx(
|
|
4350
|
-
|
|
4924
|
+
IconButton2,
|
|
4351
4925
|
{
|
|
4352
4926
|
onClick: handleStopRun,
|
|
4353
4927
|
className: "chat-send h-9 w-9 rounded-full",
|
|
@@ -4361,7 +4935,7 @@ function MessageComposer(_props = {}) {
|
|
|
4361
4935
|
)
|
|
4362
4936
|
}
|
|
4363
4937
|
) : /* @__PURE__ */ jsx(
|
|
4364
|
-
|
|
4938
|
+
IconButton2,
|
|
4365
4939
|
{
|
|
4366
4940
|
onClick: handleSendMessageAndClear,
|
|
4367
4941
|
className: `chat-send h-9 w-9 rounded-full ${sendDisabled ? "cursor-not-allowed" : ""}`,
|
|
@@ -19053,7 +19627,20 @@ var ERROR_CODE_TEXT = {
|
|
|
19053
19627
|
"llm.content_policy": "\u26A0\uFE0F **The response was blocked by a content filter**\n\nPlease rephrase your request.",
|
|
19054
19628
|
"llm.schema_validation": "\u26A0\uFE0F **The model returned an invalid response**\n\nPlease try again.",
|
|
19055
19629
|
"llm.unsupported_modality": "\u26A0\uFE0F **This model can't read images**\n\nSwitch to a vision-capable model, or remove the attachment and describe it instead.",
|
|
19056
|
-
"llm.unknown": GENERIC_ERROR_TEXT
|
|
19630
|
+
"llm.unknown": GENERIC_ERROR_TEXT,
|
|
19631
|
+
// The AI API's current names for the two above; older messages stored those.
|
|
19632
|
+
"llm.auth_failed": "\u26A0\uFE0F **The model connection isn't authorised**\n\nAn administrator needs to check the model configuration.",
|
|
19633
|
+
"llm.provider_error": GENERIC_ERROR_TEXT,
|
|
19634
|
+
"llm.unsupported_tools": "\u26A0\uFE0F **This model can't use tools**\n\nAn administrator needs to choose a model that supports tools for this step.",
|
|
19635
|
+
// Managed secrets. A secret's failure arrives as a 404 or 400, which the
|
|
19636
|
+
// status table below would read as a missing model or a generic error.
|
|
19637
|
+
"secret.user_value_not_set": "\u26A0\uFE0F **Your own key for this isn't set**\n\nThis step uses a credential each person sets for themselves, and none is set for you yet. Ask an administrator to add it.",
|
|
19638
|
+
"secret.run_has_no_user": "\u26A0\uFE0F **This step needs a signed-in user**\n\nIt uses a person's own credential, so it can't run when no one started the run.",
|
|
19639
|
+
"secret.user_mismatch": "\u26A0\uFE0F **A credential couldn't be loaded**\n\nAn administrator needs to check this flow's secrets.",
|
|
19640
|
+
"secret.run_required": "\u26A0\uFE0F **A credential couldn't be loaded**\n\nAn administrator needs to check this flow's secrets.",
|
|
19641
|
+
"secret.not_found": "\u26A0\uFE0F **A secret this flow uses doesn't exist**\n\nAn administrator needs to add it, or point the flow at another one.",
|
|
19642
|
+
// The API's name for secret.not_found before it was renamed; older messages stored it.
|
|
19643
|
+
MS404: "\u26A0\uFE0F **A secret this flow uses doesn't exist**\n\nAn administrator needs to add it, or point the flow at another one."
|
|
19057
19644
|
};
|
|
19058
19645
|
var STATUS_CODE_TEXT = {
|
|
19059
19646
|
408: ERROR_CODE_TEXT["llm.timeout"],
|
|
@@ -19075,6 +19662,34 @@ var getMessageErrorText = (error) => {
|
|
|
19075
19662
|
}
|
|
19076
19663
|
return STATUS_CODE_TEXT[error.code] ?? GENERIC_ERROR_TEXT;
|
|
19077
19664
|
};
|
|
19665
|
+
function extractProviderErrorDetail(raw2) {
|
|
19666
|
+
const start = raw2.indexOf("{");
|
|
19667
|
+
if (start === -1) return null;
|
|
19668
|
+
let parsed;
|
|
19669
|
+
try {
|
|
19670
|
+
parsed = JSON.parse(raw2.slice(start));
|
|
19671
|
+
} catch {
|
|
19672
|
+
return null;
|
|
19673
|
+
}
|
|
19674
|
+
if (typeof parsed !== "object" || parsed === null) return null;
|
|
19675
|
+
const record = parsed;
|
|
19676
|
+
const inner = typeof record.error === "object" && record.error !== null ? record.error : record;
|
|
19677
|
+
if (typeof inner.message !== "string") return null;
|
|
19678
|
+
return {
|
|
19679
|
+
message: inner.message,
|
|
19680
|
+
param: typeof inner.param === "string" ? inner.param : void 0
|
|
19681
|
+
};
|
|
19682
|
+
}
|
|
19683
|
+
var getMessageErrorDetail = (error) => {
|
|
19684
|
+
if (typeof error === "number" || !error.message) {
|
|
19685
|
+
return null;
|
|
19686
|
+
}
|
|
19687
|
+
const detail = extractProviderErrorDetail(error.message);
|
|
19688
|
+
if (!detail) {
|
|
19689
|
+
return error.message;
|
|
19690
|
+
}
|
|
19691
|
+
return detail.param ? `${detail.message} (param: ${detail.param})` : detail.message;
|
|
19692
|
+
};
|
|
19078
19693
|
var FileInfoSchema = z.object({
|
|
19079
19694
|
id: z.string(),
|
|
19080
19695
|
name: z.string()
|
|
@@ -19118,7 +19733,8 @@ var MessageErrorMessageSchema = z.object({
|
|
|
19118
19733
|
error_code: z.string().nullish(),
|
|
19119
19734
|
message: z.string().nullish(),
|
|
19120
19735
|
data: z.string().nullish(),
|
|
19121
|
-
blockId: z.string().nullish()
|
|
19736
|
+
blockId: z.string().nullish(),
|
|
19737
|
+
traceId: z.string().nullish()
|
|
19122
19738
|
});
|
|
19123
19739
|
var MessageSchema = z.object({
|
|
19124
19740
|
id: z.string().nullish(),
|
|
@@ -19966,6 +20582,34 @@ var MessageBubble = (props) => {
|
|
|
19966
20582
|
/* @__PURE__ */ jsx("div", { className: "mt-1.5", children: metaRow })
|
|
19967
20583
|
] });
|
|
19968
20584
|
};
|
|
20585
|
+
function MessageErrorDetails({
|
|
20586
|
+
detail,
|
|
20587
|
+
traceId
|
|
20588
|
+
}) {
|
|
20589
|
+
const [expanded, setExpanded] = useState(false);
|
|
20590
|
+
return /* @__PURE__ */ jsxs("div", { className: "mt-1", children: [
|
|
20591
|
+
/* @__PURE__ */ jsxs(
|
|
20592
|
+
"button",
|
|
20593
|
+
{
|
|
20594
|
+
type: "button",
|
|
20595
|
+
onClick: () => setExpanded((prev) => !prev),
|
|
20596
|
+
"aria-expanded": expanded,
|
|
20597
|
+
className: "m-0 inline-flex w-auto cursor-pointer appearance-none items-center gap-1 border-0 bg-transparent p-0 text-[11px] font-medium leading-none text-muted-foreground hover:text-foreground",
|
|
20598
|
+
children: [
|
|
20599
|
+
expanded ? /* @__PURE__ */ jsx(ChevronDown, { className: "h-3 w-3 shrink-0" }) : /* @__PURE__ */ jsx(ChevronRight, { className: "h-3 w-3 shrink-0" }),
|
|
20600
|
+
expanded ? "Hide details" : "Show details"
|
|
20601
|
+
]
|
|
20602
|
+
}
|
|
20603
|
+
),
|
|
20604
|
+
expanded && /* @__PURE__ */ jsxs("div", { className: "mt-1.5 whitespace-pre-wrap break-words rounded-md bg-secondary/60 p-2 font-mono text-[11px] leading-relaxed text-muted-foreground", children: [
|
|
20605
|
+
detail,
|
|
20606
|
+
traceId && /* @__PURE__ */ jsxs("div", { className: detail ? "mt-1.5" : void 0, children: [
|
|
20607
|
+
"Reference: ",
|
|
20608
|
+
traceId
|
|
20609
|
+
] })
|
|
20610
|
+
] })
|
|
20611
|
+
] });
|
|
20612
|
+
}
|
|
19969
20613
|
var ThinkingSection = ({ status }) => /* @__PURE__ */ jsxs(
|
|
19970
20614
|
"div",
|
|
19971
20615
|
{
|
|
@@ -20253,22 +20897,26 @@ var MessageItem = ({
|
|
|
20253
20897
|
);
|
|
20254
20898
|
}
|
|
20255
20899
|
(message.errors ?? []).forEach((error, errorIndex) => {
|
|
20900
|
+
const key = `error-${message.id ?? "msg"}-${errorIndex}-${error.errorCode ?? error.code}`;
|
|
20901
|
+
const detail = getMessageErrorDetail(error);
|
|
20256
20902
|
bubbles.push(
|
|
20257
|
-
/* @__PURE__ */
|
|
20258
|
-
|
|
20259
|
-
|
|
20260
|
-
|
|
20261
|
-
|
|
20262
|
-
|
|
20263
|
-
|
|
20264
|
-
|
|
20265
|
-
|
|
20266
|
-
|
|
20267
|
-
|
|
20268
|
-
|
|
20269
|
-
|
|
20270
|
-
|
|
20271
|
-
|
|
20903
|
+
/* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
20904
|
+
/* @__PURE__ */ jsx(
|
|
20905
|
+
MessageBubble,
|
|
20906
|
+
{
|
|
20907
|
+
createdBy: chatbotName,
|
|
20908
|
+
createdAt: message.createdAt,
|
|
20909
|
+
type: "Output" /* OUTPUT */,
|
|
20910
|
+
content: [{ text: getMessageErrorText(error) }],
|
|
20911
|
+
files: [],
|
|
20912
|
+
sources: [],
|
|
20913
|
+
chatbotName,
|
|
20914
|
+
userOutput: null,
|
|
20915
|
+
userInput: null
|
|
20916
|
+
}
|
|
20917
|
+
),
|
|
20918
|
+
(detail || error.traceId) && /* @__PURE__ */ jsx(MessageErrorDetails, { detail, traceId: error.traceId })
|
|
20919
|
+
] }, key)
|
|
20272
20920
|
);
|
|
20273
20921
|
});
|
|
20274
20922
|
return bubbles;
|
|
@@ -20523,6 +21171,11 @@ function MessageListSkeleton() {
|
|
|
20523
21171
|
i
|
|
20524
21172
|
)) });
|
|
20525
21173
|
}
|
|
21174
|
+
|
|
21175
|
+
// src/shared/utils/enums.ts
|
|
21176
|
+
var isMember = (e, value) => Object.values(e).includes(value);
|
|
21177
|
+
|
|
21178
|
+
// src/domains/messages/mapper.ts
|
|
20526
21179
|
var {
|
|
20527
21180
|
messageThreadsThreadMessagesIdMessagesResponse: messagesResponseSchema
|
|
20528
21181
|
} = ChatZod;
|
|
@@ -20549,6 +21202,7 @@ function mapMessageValueDtoToModel(dto) {
|
|
|
20549
21202
|
createdByUserId: dto.createdByUserId ?? void 0
|
|
20550
21203
|
};
|
|
20551
21204
|
}
|
|
21205
|
+
var mapMessageValuesDtoToModels = (dtos) => dtos.filter((dto) => isMember(MessageValueType, dto.type)).map(mapMessageValueDtoToModel);
|
|
20552
21206
|
function mapMessageErrorDtoToModel(dto) {
|
|
20553
21207
|
const { error_code, ...rest } = dto;
|
|
20554
21208
|
return {
|
|
@@ -20566,7 +21220,7 @@ function mapMessageDtoToModel(dto) {
|
|
|
20566
21220
|
createdByUserId: dto.createdByUserId ?? void 0,
|
|
20567
21221
|
messageThreadId: dto.messageThreadId ?? void 0,
|
|
20568
21222
|
errors: dto.errors?.map(mapMessageErrorDtoToModel) ?? void 0,
|
|
20569
|
-
values: dto.values
|
|
21223
|
+
values: dto.values && mapMessageValuesDtoToModels(dto.values)
|
|
20570
21224
|
};
|
|
20571
21225
|
}
|
|
20572
21226
|
function mapMessagesDtoToModels(dto) {
|
|
@@ -20682,8 +21336,7 @@ var mapWorkspacesDtoToModels = (arr) => arr.map(mapWorkspaceDtoToModel);
|
|
|
20682
21336
|
function getChatApiBaseUrl() {
|
|
20683
21337
|
try {
|
|
20684
21338
|
const w = window;
|
|
20685
|
-
const
|
|
20686
|
-
const cfg = w?.ssconfig?.Chat_Api_Uri ?? env2?.VITE_CHAT_API_URI;
|
|
21339
|
+
const cfg = w?.ssconfig?.Chat_Api_Uri;
|
|
20687
21340
|
return typeof cfg === "string" && cfg.trim() ? cfg.trim() : "";
|
|
20688
21341
|
} catch {
|
|
20689
21342
|
return "";
|
|
@@ -20696,6 +21349,6 @@ function getUserPhotoUrl(userId) {
|
|
|
20696
21349
|
return `${base2}/users/${userId}/photo`;
|
|
20697
21350
|
}
|
|
20698
21351
|
|
|
20699
|
-
export { ChatProvider, ChatVariablesForm, DRAFT_THREAD_PREFIX, DateFromApi, MarkdownEditor, MessageComposer, MessageList, MessageListSkeleton, MessageMarkdown, MessageValueType, NEW_THREAD_ID, THREAD_LIST_PAGE_SIZE, applyDeltaToMessage, applyThreadToCache, createDraftThreadId, createThreadId, downloadFileBlobOptions, filesKeys, flowRunsKeys, getMessageErrorText, getModelIcon, getRetryStatusText, getThreadPlaceholderFromListCache, getUserPhotoUrl, invalidateWorkspaceThreadLists, isDraftThreadId, mapFileInfoDtoToModel, mapMentionUserDtoToModel, mapMessageDtoToModel, mapMessageErrorDtoToModel, mapMessageValueDtoToModel, mapMessagesDtoToModels, mapSignalRThreadSummaryToModel, mapThreadDtoToModel, mapThreadsResponseDtoToModel, mapWorkspaceDtoToModel, mapWorkspacesDtoToModels, markDraftThreadId, messagesKeys, messagesListOptions, messagesMutationsKeys, modelsKeys, parseDateTime, parseDateTimeHuman, parseRetryStatus, randomUUID, setThreadOptimisticRunning, setThreadRunningInLists, taggableUsersOptions, threadDetailOptions, threadsKeys, unmarkDraftThreadId, useAddInputToMessage, useChatContext, useChatIdentity, useChatService, useDownloadFileBlobQuery, useFileMutations, useFlowRunVariables, useIsDraftThreadId, useMessages, useModels, useSendMessage, useTaggableWorkspaceUsers, useThread, useThreadIsRunning, useUpdateFlowRunVariable, useWorkspace, utcDate, workspaceDetailOptions, workspaceKeys };
|
|
21352
|
+
export { ChatProvider, ChatVariablesForm, DRAFT_THREAD_PREFIX, DateFromApi, DictationButton, MarkdownEditor, MessageComposer, MessageList, MessageListSkeleton, MessageMarkdown, MessageValueType, NEW_THREAD_ID, THREAD_LIST_PAGE_SIZE, applyDeltaToMessage, applyThreadToCache, createDraftThreadId, createThreadId, downloadFileBlobOptions, filesKeys, flowRunsKeys, getMessageErrorDetail, getMessageErrorText, getModelIcon, getRetryStatusText, getThreadPlaceholderFromListCache, getUserPhotoUrl, invalidateWorkspaceThreadLists, isDraftThreadId, mapFileInfoDtoToModel, mapMentionUserDtoToModel, mapMessageDtoToModel, mapMessageErrorDtoToModel, mapMessageValueDtoToModel, mapMessageValuesDtoToModels, mapMessagesDtoToModels, mapSignalRThreadSummaryToModel, mapThreadDtoToModel, mapThreadsResponseDtoToModel, mapWorkspaceDtoToModel, mapWorkspacesDtoToModels, markDraftThreadId, messagesKeys, messagesListOptions, messagesMutationsKeys, modelsKeys, parseDateTime, parseDateTimeHuman, parseRetryStatus, randomUUID, setThreadOptimisticRunning, setThreadRunningInLists, speechKeys, taggableUsersOptions, threadDetailOptions, threadsKeys, unmarkDraftThreadId, useAddInputToMessage, useChatContext, useChatIdentity, useChatService, useDictation, useDownloadFileBlobQuery, useFileMutations, useFlowRunVariables, useIsDraftThreadId, useMessages, useModels, useSendMessage, useSpeechConfig, useTaggableWorkspaceUsers, useThread, useThreadIsRunning, useUpdateFlowRunVariable, useWorkspace, utcDate, workspaceDetailOptions, workspaceKeys };
|
|
20700
21353
|
//# sourceMappingURL=index.js.map
|
|
20701
21354
|
//# sourceMappingURL=index.js.map
|