@smartspace/chat-ui 1.14.4-dev.02ba73a → 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 +224 -134
- package/dist/index.js +716 -49
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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
|
-
import { useQuery, queryOptions, useQueryClient, useMutation
|
|
8
|
+
import { useQuery, queryOptions, useQueryClient, useMutation } from '@tanstack/react-query';
|
|
9
9
|
import { toast } from 'sonner';
|
|
10
10
|
import { ChatZod } from '@smartspace/api-client';
|
|
11
11
|
import { z } from 'zod';
|
|
@@ -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';
|
|
@@ -600,9 +600,14 @@ var useThread = ({
|
|
|
600
600
|
};
|
|
601
601
|
var useThreadIsRunning = (workspaceId, threadId) => {
|
|
602
602
|
const queryClient = useQueryClient();
|
|
603
|
+
const service = useChatService();
|
|
603
604
|
const { data: detailThread } = useQuery({
|
|
604
|
-
|
|
605
|
-
|
|
605
|
+
...threadDetailOptions({
|
|
606
|
+
service,
|
|
607
|
+
workspaceId: workspaceId ?? "",
|
|
608
|
+
threadId: threadId ?? ""
|
|
609
|
+
}),
|
|
610
|
+
enabled: false
|
|
606
611
|
});
|
|
607
612
|
const listThread = workspaceId && threadId ? getThreadPlaceholderFromListCache(queryClient, workspaceId, threadId) : void 0;
|
|
608
613
|
const { data: optimistic } = useQuery({
|
|
@@ -837,6 +842,37 @@ function useMessages(threadId) {
|
|
|
837
842
|
});
|
|
838
843
|
}
|
|
839
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
|
+
|
|
840
876
|
// ../../node_modules/.pnpm/@milkdown+exception@7.20.0/node_modules/@milkdown/exception/lib/index.js
|
|
841
877
|
var ErrorCode = /* @__PURE__ */ (function(ErrorCode2) {
|
|
842
878
|
ErrorCode2["docTypeError"] = "docTypeError";
|
|
@@ -970,6 +1006,75 @@ var autolink = $prose(() => {
|
|
|
970
1006
|
}
|
|
971
1007
|
});
|
|
972
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
|
+
}
|
|
973
1078
|
|
|
974
1079
|
// src/shared/markdown/extensions/fileTag.ts
|
|
975
1080
|
var fileTag = $node("fileTag", () => ({
|
|
@@ -1879,7 +1984,7 @@ function EditorInner({
|
|
|
1879
1984
|
} catch {
|
|
1880
1985
|
}
|
|
1881
1986
|
});
|
|
1882
|
-
}).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);
|
|
1883
1988
|
},
|
|
1884
1989
|
[isEditable]
|
|
1885
1990
|
);
|
|
@@ -2089,6 +2194,25 @@ function EditorInner({
|
|
|
2089
2194
|
return value ?? "";
|
|
2090
2195
|
}
|
|
2091
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
|
+
},
|
|
2092
2216
|
clear: () => {
|
|
2093
2217
|
const view = viewRef.current;
|
|
2094
2218
|
if (!view) return;
|
|
@@ -2432,6 +2556,327 @@ var MarkdownEditor = forwardRef((props, ref) => {
|
|
|
2432
2556
|
return /* @__PURE__ */ jsx(MilkdownProvider, { children: /* @__PURE__ */ jsx(EditorInner, { ...props, editorHandleRef: ref }) });
|
|
2433
2557
|
});
|
|
2434
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
|
+
}
|
|
2435
2880
|
function useFlowRunVariables(flowRunId) {
|
|
2436
2881
|
const service = useChatService();
|
|
2437
2882
|
return useQuery({
|
|
@@ -3737,6 +4182,58 @@ var ChatVariablesForm = forwardRef(({ workspace, threadId, setVariables }, ref)
|
|
|
3737
4182
|
) }) })
|
|
3738
4183
|
] });
|
|
3739
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
|
+
}
|
|
3740
4237
|
|
|
3741
4238
|
// src/domains/workspaces/queryKeys.ts
|
|
3742
4239
|
var workspaceKeys = {
|
|
@@ -3969,6 +4466,40 @@ function MessageComposer(_props = {}) {
|
|
|
3969
4466
|
cancelReset();
|
|
3970
4467
|
}
|
|
3971
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]);
|
|
3972
4503
|
useEffect(() => {
|
|
3973
4504
|
if (typeof window === "undefined") return;
|
|
3974
4505
|
window.__ssDownloadFile = (id) => getFileBlobUrl(id);
|
|
@@ -4088,6 +4619,7 @@ function MessageComposer(_props = {}) {
|
|
|
4088
4619
|
const latestText = editorRef.current?.getMarkdown() ?? newMessage;
|
|
4089
4620
|
const sent = handleSendMessage(latestText, uploadedAttachments);
|
|
4090
4621
|
if (!sent) return;
|
|
4622
|
+
stopDictation();
|
|
4091
4623
|
handleClearAttachments();
|
|
4092
4624
|
setEditorKey((k) => k + 1);
|
|
4093
4625
|
};
|
|
@@ -4194,7 +4726,7 @@ function MessageComposer(_props = {}) {
|
|
|
4194
4726
|
/* @__PURE__ */ jsx("div", { className: "max-h-[400px] w-full overflow-y-auto", children: /* @__PURE__ */ jsx(
|
|
4195
4727
|
MarkdownEditor,
|
|
4196
4728
|
{
|
|
4197
|
-
ref:
|
|
4729
|
+
ref: attachEditor,
|
|
4198
4730
|
value: newMessage,
|
|
4199
4731
|
onChange: (md) => setNewMessage(md),
|
|
4200
4732
|
onKeyDown: handleComposerKeyDown,
|
|
@@ -4211,10 +4743,18 @@ function MessageComposer(_props = {}) {
|
|
|
4211
4743
|
},
|
|
4212
4744
|
`composer-md-${editorKey}`
|
|
4213
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] }),
|
|
4214
4754
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2 px-3 pb-3", children: [
|
|
4215
4755
|
/* @__PURE__ */ jsxs("div", { className: "ss-composer__actions flex min-w-0 flex-1 items-center gap-1", children: [
|
|
4216
4756
|
supportsFiles && /* @__PURE__ */ jsx(
|
|
4217
|
-
|
|
4757
|
+
IconButton2,
|
|
4218
4758
|
{
|
|
4219
4759
|
type: "button",
|
|
4220
4760
|
onClick: handlePickFilesClick,
|
|
@@ -4235,19 +4775,39 @@ function MessageComposer(_props = {}) {
|
|
|
4235
4775
|
)
|
|
4236
4776
|
] }),
|
|
4237
4777
|
/* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-1.5", children: [
|
|
4238
|
-
/* @__PURE__ */ jsx(
|
|
4239
|
-
|
|
4778
|
+
dictation.available ? /* @__PURE__ */ jsx(
|
|
4779
|
+
DictationButton,
|
|
4240
4780
|
{
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
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
|
|
4247
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
|
+
)
|
|
4248
4808
|
),
|
|
4249
4809
|
canStop ? /* @__PURE__ */ jsx(
|
|
4250
|
-
|
|
4810
|
+
IconButton2,
|
|
4251
4811
|
{
|
|
4252
4812
|
onClick: handleStopRun,
|
|
4253
4813
|
className: "chat-send h-8 w-8 rounded-full",
|
|
@@ -4261,7 +4821,7 @@ function MessageComposer(_props = {}) {
|
|
|
4261
4821
|
)
|
|
4262
4822
|
}
|
|
4263
4823
|
) : /* @__PURE__ */ jsx(
|
|
4264
|
-
|
|
4824
|
+
IconButton2,
|
|
4265
4825
|
{
|
|
4266
4826
|
onClick: handleSendMessageAndClear,
|
|
4267
4827
|
className: `chat-send h-8 w-8 rounded-full ${sendDisabled ? "cursor-not-allowed" : ""}`,
|
|
@@ -4290,7 +4850,7 @@ function MessageComposer(_props = {}) {
|
|
|
4290
4850
|
},
|
|
4291
4851
|
children: /* @__PURE__ */ jsxs("div", { className: "relative h-full w-full bg-background border shadow-lg", children: [
|
|
4292
4852
|
/* @__PURE__ */ jsx(
|
|
4293
|
-
|
|
4853
|
+
IconButton2,
|
|
4294
4854
|
{
|
|
4295
4855
|
type: "button",
|
|
4296
4856
|
size: "small",
|
|
@@ -4308,7 +4868,7 @@ function MessageComposer(_props = {}) {
|
|
|
4308
4868
|
/* @__PURE__ */ jsx("div", { className: "flex-1 p-4", children: /* @__PURE__ */ jsx(
|
|
4309
4869
|
MarkdownEditor,
|
|
4310
4870
|
{
|
|
4311
|
-
ref:
|
|
4871
|
+
ref: attachEditor,
|
|
4312
4872
|
value: newMessage,
|
|
4313
4873
|
onChange: (md) => setNewMessage(md),
|
|
4314
4874
|
onKeyDown: handleComposerKeyDown,
|
|
@@ -4323,10 +4883,18 @@ function MessageComposer(_props = {}) {
|
|
|
4323
4883
|
},
|
|
4324
4884
|
`composer-md-${editorKey}`
|
|
4325
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
|
+
),
|
|
4326
4894
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 px-3 py-2 border-t bg-background", children: [
|
|
4327
4895
|
/* @__PURE__ */ jsx("div", { className: "flex-1" }),
|
|
4328
4896
|
supportsFiles && /* @__PURE__ */ jsx(
|
|
4329
|
-
|
|
4897
|
+
IconButton2,
|
|
4330
4898
|
{
|
|
4331
4899
|
type: "button",
|
|
4332
4900
|
onClick: handlePickFilesClick,
|
|
@@ -4341,8 +4909,19 @@ function MessageComposer(_props = {}) {
|
|
|
4341
4909
|
)
|
|
4342
4910
|
}
|
|
4343
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
|
+
),
|
|
4344
4923
|
canStop ? /* @__PURE__ */ jsx(
|
|
4345
|
-
|
|
4924
|
+
IconButton2,
|
|
4346
4925
|
{
|
|
4347
4926
|
onClick: handleStopRun,
|
|
4348
4927
|
className: "chat-send h-9 w-9 rounded-full",
|
|
@@ -4356,7 +4935,7 @@ function MessageComposer(_props = {}) {
|
|
|
4356
4935
|
)
|
|
4357
4936
|
}
|
|
4358
4937
|
) : /* @__PURE__ */ jsx(
|
|
4359
|
-
|
|
4938
|
+
IconButton2,
|
|
4360
4939
|
{
|
|
4361
4940
|
onClick: handleSendMessageAndClear,
|
|
4362
4941
|
className: `chat-send h-9 w-9 rounded-full ${sendDisabled ? "cursor-not-allowed" : ""}`,
|
|
@@ -19048,7 +19627,20 @@ var ERROR_CODE_TEXT = {
|
|
|
19048
19627
|
"llm.content_policy": "\u26A0\uFE0F **The response was blocked by a content filter**\n\nPlease rephrase your request.",
|
|
19049
19628
|
"llm.schema_validation": "\u26A0\uFE0F **The model returned an invalid response**\n\nPlease try again.",
|
|
19050
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.",
|
|
19051
|
-
"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."
|
|
19052
19644
|
};
|
|
19053
19645
|
var STATUS_CODE_TEXT = {
|
|
19054
19646
|
408: ERROR_CODE_TEXT["llm.timeout"],
|
|
@@ -19070,6 +19662,34 @@ var getMessageErrorText = (error) => {
|
|
|
19070
19662
|
}
|
|
19071
19663
|
return STATUS_CODE_TEXT[error.code] ?? GENERIC_ERROR_TEXT;
|
|
19072
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
|
+
};
|
|
19073
19693
|
var FileInfoSchema = z.object({
|
|
19074
19694
|
id: z.string(),
|
|
19075
19695
|
name: z.string()
|
|
@@ -19113,7 +19733,8 @@ var MessageErrorMessageSchema = z.object({
|
|
|
19113
19733
|
error_code: z.string().nullish(),
|
|
19114
19734
|
message: z.string().nullish(),
|
|
19115
19735
|
data: z.string().nullish(),
|
|
19116
|
-
blockId: z.string().nullish()
|
|
19736
|
+
blockId: z.string().nullish(),
|
|
19737
|
+
traceId: z.string().nullish()
|
|
19117
19738
|
});
|
|
19118
19739
|
var MessageSchema = z.object({
|
|
19119
19740
|
id: z.string().nullish(),
|
|
@@ -19961,6 +20582,34 @@ var MessageBubble = (props) => {
|
|
|
19961
20582
|
/* @__PURE__ */ jsx("div", { className: "mt-1.5", children: metaRow })
|
|
19962
20583
|
] });
|
|
19963
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
|
+
}
|
|
19964
20613
|
var ThinkingSection = ({ status }) => /* @__PURE__ */ jsxs(
|
|
19965
20614
|
"div",
|
|
19966
20615
|
{
|
|
@@ -20045,14 +20694,14 @@ var MessageItem = ({
|
|
|
20045
20694
|
const { data: workspace } = useWorkspace(workspaceId);
|
|
20046
20695
|
const chatbotName = getChatbotName(workspace?.name);
|
|
20047
20696
|
const { addInputToMessageMutation } = useAddInputToMessage();
|
|
20048
|
-
const onSubmitUserForm = (messageId) => (name, value) => {
|
|
20697
|
+
const onSubmitUserForm = (messageId, channels = {}) => (name, value) => {
|
|
20049
20698
|
if (!threadId || !messageId) return;
|
|
20050
20699
|
addInputToMessageMutation.mutate({
|
|
20051
20700
|
threadId,
|
|
20052
20701
|
messageId,
|
|
20053
20702
|
name,
|
|
20054
20703
|
value,
|
|
20055
|
-
channels
|
|
20704
|
+
channels
|
|
20056
20705
|
});
|
|
20057
20706
|
};
|
|
20058
20707
|
const safeTime = (d) => {
|
|
@@ -20183,7 +20832,7 @@ var MessageItem = ({
|
|
|
20183
20832
|
userOutput: v.value && typeof v.value === "object" ? v.value : null,
|
|
20184
20833
|
chatbotName,
|
|
20185
20834
|
userInput: userInput?.value,
|
|
20186
|
-
onSubmitUserForm: onSubmitUserForm(message.id ?? "")
|
|
20835
|
+
onSubmitUserForm: onSubmitUserForm(message.id ?? "", v.channels)
|
|
20187
20836
|
},
|
|
20188
20837
|
`user-${message.id ?? "msg"}-${keyCounter++}`
|
|
20189
20838
|
)
|
|
@@ -20248,22 +20897,26 @@ var MessageItem = ({
|
|
|
20248
20897
|
);
|
|
20249
20898
|
}
|
|
20250
20899
|
(message.errors ?? []).forEach((error, errorIndex) => {
|
|
20900
|
+
const key = `error-${message.id ?? "msg"}-${errorIndex}-${error.errorCode ?? error.code}`;
|
|
20901
|
+
const detail = getMessageErrorDetail(error);
|
|
20251
20902
|
bubbles.push(
|
|
20252
|
-
/* @__PURE__ */
|
|
20253
|
-
|
|
20254
|
-
|
|
20255
|
-
|
|
20256
|
-
|
|
20257
|
-
|
|
20258
|
-
|
|
20259
|
-
|
|
20260
|
-
|
|
20261
|
-
|
|
20262
|
-
|
|
20263
|
-
|
|
20264
|
-
|
|
20265
|
-
|
|
20266
|
-
|
|
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)
|
|
20267
20920
|
);
|
|
20268
20921
|
});
|
|
20269
20922
|
return bubbles;
|
|
@@ -20379,6 +21032,7 @@ function MessageList({
|
|
|
20379
21032
|
] }) });
|
|
20380
21033
|
}
|
|
20381
21034
|
if (safeMessages.length === 0 && !hadMessagesBefore) {
|
|
21035
|
+
const descriptionParagraphs = (activeWorkspace?.summary ?? "").split(/\n+/).map((paragraph2) => paragraph2.trim()).filter(Boolean);
|
|
20382
21036
|
return (
|
|
20383
21037
|
// A new thread opens the way the design does: the greeting and the
|
|
20384
21038
|
// composer travel together as one narrower block centred in the canvas.
|
|
@@ -20391,6 +21045,14 @@ function MessageList({
|
|
|
20391
21045
|
"data-ss-layer": "message-list",
|
|
20392
21046
|
children: /* @__PURE__ */ jsxs("div", { className: "mx-auto mb-6 w-full max-w-2xl px-4 text-center", children: [
|
|
20393
21047
|
/* @__PURE__ */ jsx("h2", { className: "text-2xl font-semibold text-foreground", children: "What\u2019s on the agenda today?" }),
|
|
21048
|
+
descriptionParagraphs.length > 0 && /* @__PURE__ */ jsx(
|
|
21049
|
+
"div",
|
|
21050
|
+
{
|
|
21051
|
+
className: "mx-auto mt-2 max-w-lg space-y-1.5 text-sm text-muted-foreground",
|
|
21052
|
+
"data-ss-layer": "workspace-description",
|
|
21053
|
+
children: descriptionParagraphs.map((paragraph2, index) => /* @__PURE__ */ jsx("p", { children: paragraph2 }, index))
|
|
21054
|
+
}
|
|
21055
|
+
),
|
|
20394
21056
|
activeWorkspace?.firstPrompt && /* @__PURE__ */ jsx("div", { className: "chat-prose mt-3 text-center", children: /* @__PURE__ */ jsx(MessageMarkdown, { value: activeWorkspace.firstPrompt }) })
|
|
20395
21057
|
] })
|
|
20396
21058
|
}
|
|
@@ -20509,6 +21171,11 @@ function MessageListSkeleton() {
|
|
|
20509
21171
|
i
|
|
20510
21172
|
)) });
|
|
20511
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
|
|
20512
21179
|
var {
|
|
20513
21180
|
messageThreadsThreadMessagesIdMessagesResponse: messagesResponseSchema
|
|
20514
21181
|
} = ChatZod;
|
|
@@ -20535,6 +21202,7 @@ function mapMessageValueDtoToModel(dto) {
|
|
|
20535
21202
|
createdByUserId: dto.createdByUserId ?? void 0
|
|
20536
21203
|
};
|
|
20537
21204
|
}
|
|
21205
|
+
var mapMessageValuesDtoToModels = (dtos) => dtos.filter((dto) => isMember(MessageValueType, dto.type)).map(mapMessageValueDtoToModel);
|
|
20538
21206
|
function mapMessageErrorDtoToModel(dto) {
|
|
20539
21207
|
const { error_code, ...rest } = dto;
|
|
20540
21208
|
return {
|
|
@@ -20552,7 +21220,7 @@ function mapMessageDtoToModel(dto) {
|
|
|
20552
21220
|
createdByUserId: dto.createdByUserId ?? void 0,
|
|
20553
21221
|
messageThreadId: dto.messageThreadId ?? void 0,
|
|
20554
21222
|
errors: dto.errors?.map(mapMessageErrorDtoToModel) ?? void 0,
|
|
20555
|
-
values: dto.values
|
|
21223
|
+
values: dto.values && mapMessageValuesDtoToModels(dto.values)
|
|
20556
21224
|
};
|
|
20557
21225
|
}
|
|
20558
21226
|
function mapMessagesDtoToModels(dto) {
|
|
@@ -20668,8 +21336,7 @@ var mapWorkspacesDtoToModels = (arr) => arr.map(mapWorkspaceDtoToModel);
|
|
|
20668
21336
|
function getChatApiBaseUrl() {
|
|
20669
21337
|
try {
|
|
20670
21338
|
const w = window;
|
|
20671
|
-
const
|
|
20672
|
-
const cfg = w?.ssconfig?.Chat_Api_Uri ?? env2?.VITE_CHAT_API_URI;
|
|
21339
|
+
const cfg = w?.ssconfig?.Chat_Api_Uri;
|
|
20673
21340
|
return typeof cfg === "string" && cfg.trim() ? cfg.trim() : "";
|
|
20674
21341
|
} catch {
|
|
20675
21342
|
return "";
|
|
@@ -20682,6 +21349,6 @@ function getUserPhotoUrl(userId) {
|
|
|
20682
21349
|
return `${base2}/users/${userId}/photo`;
|
|
20683
21350
|
}
|
|
20684
21351
|
|
|
20685
|
-
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 };
|
|
20686
21353
|
//# sourceMappingURL=index.js.map
|
|
20687
21354
|
//# sourceMappingURL=index.js.map
|