@smartspace/chat-ui 1.14.4-dev.3850792 → 1.14.4-dev.3afc264
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 -142
- package/dist/index.js +1583 -604
- 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,
|
|
4
|
-
import * as
|
|
5
|
-
import { createContext, forwardRef, useImperativeHandle, useRef, useState, useEffect, useMemo, useCallback, useContext, useSyncExternalStore } from 'react';
|
|
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
|
+
import * as React9 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,14 +17,13 @@ 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';
|
|
24
24
|
import { withJsonFormsControlProps, withJsonFormsLayoutProps, JsonForms, ResolvedJsonFormsDispatch } from '@jsonforms/react';
|
|
25
25
|
import { rankWith, uiTypeIs, createAjv } from '@jsonforms/core';
|
|
26
26
|
import { vanillaRenderers, vanillaCells } from '@jsonforms/vanilla-renderers';
|
|
27
|
-
import { FormControl, InputLabel, Select, MenuItem, useTheme, Box, Skeleton as Skeleton$1 } from '@mui/material';
|
|
28
27
|
import 'ace-builds/src-noconflict/ace';
|
|
29
28
|
import 'ace-builds/src-noconflict/ext-language_tools';
|
|
30
29
|
import 'ace-builds/src-noconflict/mode-json';
|
|
@@ -48,15 +47,16 @@ import vertexaiIcon from '@lobehub/icons-static-svg/icons/vertexai-color.svg';
|
|
|
48
47
|
import xaiIcon from '@lobehub/icons-static-svg/icons/xai.svg';
|
|
49
48
|
import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area';
|
|
50
49
|
import ReactMarkdown, { defaultUrlTransform } from 'react-markdown';
|
|
51
|
-
import
|
|
50
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
51
|
+
import { cva } from 'class-variance-authority';
|
|
52
52
|
import { clsx } from 'clsx';
|
|
53
53
|
import { twMerge } from 'tailwind-merge';
|
|
54
|
+
import MuiSkeleton from '@mui/material/Skeleton';
|
|
54
55
|
import dayjs from 'dayjs';
|
|
55
56
|
import advancedFormat from 'dayjs/plugin/advancedFormat';
|
|
56
57
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
57
58
|
import utc from 'dayjs/plugin/utc';
|
|
58
|
-
import {
|
|
59
|
-
import { cva } from 'class-variance-authority';
|
|
59
|
+
import { useTheme, Box, Skeleton as Skeleton$1 } from '@mui/material';
|
|
60
60
|
|
|
61
61
|
var __defProp = Object.defineProperty;
|
|
62
62
|
var __export = (target, all5) => {
|
|
@@ -115,8 +115,7 @@ var filesKeys = {
|
|
|
115
115
|
mutation: {
|
|
116
116
|
upload: (scope) => [...filesKeys.mutations(), "upload", { scope }],
|
|
117
117
|
download: (fileId) => [...filesKeys.mutations(), "download", { fileId }],
|
|
118
|
-
downloadBlob: (fileId) => [...filesKeys.mutations(), "downloadBlob", { fileId }]
|
|
119
|
-
downloadByUri: (uri) => [...filesKeys.mutations(), "downloadByUri", { uri }]
|
|
118
|
+
downloadBlob: (fileId) => [...filesKeys.mutations(), "downloadBlob", { fileId }]
|
|
120
119
|
}
|
|
121
120
|
};
|
|
122
121
|
|
|
@@ -163,20 +162,6 @@ var useFileMutations = (scope) => {
|
|
|
163
162
|
},
|
|
164
163
|
onError: () => toast.error("Failed to download file")
|
|
165
164
|
});
|
|
166
|
-
const downloadFileByUriMutation = useMutation({
|
|
167
|
-
mutationFn: async ({
|
|
168
|
-
name,
|
|
169
|
-
sourceUri
|
|
170
|
-
}) => {
|
|
171
|
-
const uri = await service.getFileDownloadUrl(sourceUri);
|
|
172
|
-
if (!uri) throw new Error("No download URL");
|
|
173
|
-
const response = await fetch(uri);
|
|
174
|
-
const blob = await response.blob();
|
|
175
|
-
saveFile(blob, name);
|
|
176
|
-
return blob;
|
|
177
|
-
},
|
|
178
|
-
onError: () => toast.error("Failed to download file")
|
|
179
|
-
});
|
|
180
165
|
const fileStates = (files) => files.map((file) => ({
|
|
181
166
|
name: file.name,
|
|
182
167
|
progress: fileProgress[file.name] ?? 0,
|
|
@@ -200,7 +185,6 @@ var useFileMutations = (scope) => {
|
|
|
200
185
|
return {
|
|
201
186
|
uploadFilesMutation,
|
|
202
187
|
downloadFileMutation,
|
|
203
|
-
downloadFileByUriMutation,
|
|
204
188
|
getFileBlobUrl,
|
|
205
189
|
fileProgress,
|
|
206
190
|
uploadedFiles,
|
|
@@ -365,6 +349,19 @@ var MessageValueType = /* @__PURE__ */ ((MessageValueType2) => {
|
|
|
365
349
|
MessageValueType2["INPUT"] = "Input";
|
|
366
350
|
return MessageValueType2;
|
|
367
351
|
})(MessageValueType || {});
|
|
352
|
+
var MessageResponseSourceType = /* @__PURE__ */ ((MessageResponseSourceType2) => {
|
|
353
|
+
MessageResponseSourceType2["BlobInternal"] = "BlobInternal";
|
|
354
|
+
MessageResponseSourceType2["WebExternal"] = "WebExternal";
|
|
355
|
+
MessageResponseSourceType2["File"] = "File";
|
|
356
|
+
MessageResponseSourceType2["URL"] = "URL";
|
|
357
|
+
return MessageResponseSourceType2;
|
|
358
|
+
})(MessageResponseSourceType || {});
|
|
359
|
+
var MessageAttribution = /* @__PURE__ */ ((MessageAttribution2) => {
|
|
360
|
+
MessageAttribution2["Supported"] = "supported";
|
|
361
|
+
MessageAttribution2["Partial"] = "partial";
|
|
362
|
+
MessageAttribution2["Unsupported"] = "unsupported";
|
|
363
|
+
return MessageAttribution2;
|
|
364
|
+
})(MessageAttribution || {});
|
|
368
365
|
|
|
369
366
|
// src/domains/threads/queryKeys.ts
|
|
370
367
|
var THREAD_LIST_PAGE_SIZE = 30;
|
|
@@ -543,7 +540,10 @@ var threadDetailOptions = ({
|
|
|
543
540
|
queryKey: threadsKeys.detail(workspaceId, threadId),
|
|
544
541
|
queryFn: () => service.fetchThread(workspaceId, threadId),
|
|
545
542
|
refetchOnWindowFocus: false,
|
|
546
|
-
staleTime: 6e4
|
|
543
|
+
staleTime: 6e4,
|
|
544
|
+
// The route loader has just tried and failed. Retrying on mount delays
|
|
545
|
+
// the inline error by several seconds; the user has Try again.
|
|
546
|
+
retryOnMount: false
|
|
547
547
|
});
|
|
548
548
|
function getThreadPlaceholderFromListCache(queryClient, workspaceId, threadId) {
|
|
549
549
|
const entries = queryClient.getQueriesData({
|
|
@@ -587,9 +587,14 @@ var useThread = ({
|
|
|
587
587
|
};
|
|
588
588
|
var useThreadIsRunning = (workspaceId, threadId) => {
|
|
589
589
|
const queryClient = useQueryClient();
|
|
590
|
+
const service = useChatService();
|
|
590
591
|
const { data: detailThread } = useQuery({
|
|
591
|
-
|
|
592
|
-
|
|
592
|
+
...threadDetailOptions({
|
|
593
|
+
service,
|
|
594
|
+
workspaceId: workspaceId ?? "",
|
|
595
|
+
threadId: threadId ?? ""
|
|
596
|
+
}),
|
|
597
|
+
enabled: false
|
|
593
598
|
});
|
|
594
599
|
const listThread = workspaceId && threadId ? getThreadPlaceholderFromListCache(queryClient, workspaceId, threadId) : void 0;
|
|
595
600
|
const { data: optimistic } = useQuery({
|
|
@@ -824,6 +829,37 @@ function useMessages(threadId) {
|
|
|
824
829
|
});
|
|
825
830
|
}
|
|
826
831
|
|
|
832
|
+
// src/domains/speech/queryKeys.ts
|
|
833
|
+
var speechKeys = {
|
|
834
|
+
all: ["speech"],
|
|
835
|
+
config: () => [...speechKeys.all, "config"]
|
|
836
|
+
};
|
|
837
|
+
|
|
838
|
+
// src/domains/speech/queries.ts
|
|
839
|
+
var unavailable = { enabled: false, defaultLocale: "en-US" };
|
|
840
|
+
var isNotFound = (error) => error?.type === "NotFound" || error?.response?.status === 404;
|
|
841
|
+
function useSpeechConfig() {
|
|
842
|
+
const service = useChatService();
|
|
843
|
+
const supported = !!service.getSpeechConfig && !!service.getSpeechToken;
|
|
844
|
+
return useQuery({
|
|
845
|
+
...queryOptions({
|
|
846
|
+
queryKey: speechKeys.config(),
|
|
847
|
+
queryFn: async () => {
|
|
848
|
+
try {
|
|
849
|
+
return await service.getSpeechConfig?.() ?? unavailable;
|
|
850
|
+
} catch (error) {
|
|
851
|
+
if (isNotFound(error)) return unavailable;
|
|
852
|
+
throw error;
|
|
853
|
+
}
|
|
854
|
+
},
|
|
855
|
+
staleTime: Infinity,
|
|
856
|
+
retry: (failureCount) => failureCount < 2,
|
|
857
|
+
retryDelay: 1e3
|
|
858
|
+
}),
|
|
859
|
+
enabled: supported
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
|
|
827
863
|
// ../../node_modules/.pnpm/@milkdown+exception@7.20.0/node_modules/@milkdown/exception/lib/index.js
|
|
828
864
|
var ErrorCode = /* @__PURE__ */ (function(ErrorCode2) {
|
|
829
865
|
ErrorCode2["docTypeError"] = "docTypeError";
|
|
@@ -957,6 +993,75 @@ var autolink = $prose(() => {
|
|
|
957
993
|
}
|
|
958
994
|
});
|
|
959
995
|
});
|
|
996
|
+
var dictationGhostKey = new PluginKey("dictationGhost");
|
|
997
|
+
function buildDecorations2(state, text6) {
|
|
998
|
+
const doc = state.doc;
|
|
999
|
+
const from = state.selection.head;
|
|
1000
|
+
const before = from > 0 ? doc.textBetween(from - 1, from, " ") : "";
|
|
1001
|
+
const display = before !== "" && !/\s/.test(before) ? ` ${text6}` : text6;
|
|
1002
|
+
const widget = Decoration.widget(
|
|
1003
|
+
from,
|
|
1004
|
+
() => {
|
|
1005
|
+
const span = document.createElement("span");
|
|
1006
|
+
span.className = "md-editor__dictation-ghost";
|
|
1007
|
+
span.setAttribute("aria-hidden", "true");
|
|
1008
|
+
span.appendChild(document.createTextNode(display));
|
|
1009
|
+
const dots = document.createElement("span");
|
|
1010
|
+
dots.className = "md-editor__dictation-dots";
|
|
1011
|
+
for (let i = 0; i < 3; i += 1)
|
|
1012
|
+
dots.appendChild(document.createElement("span"));
|
|
1013
|
+
span.appendChild(dots);
|
|
1014
|
+
return span;
|
|
1015
|
+
},
|
|
1016
|
+
{
|
|
1017
|
+
// Render after the caret so typing still lands where the user expects.
|
|
1018
|
+
side: 1,
|
|
1019
|
+
// Keyed by content so ProseMirror reuses the node between renders instead
|
|
1020
|
+
// of tearing it down on every interim result.
|
|
1021
|
+
key: `dictation-ghost:${display}`
|
|
1022
|
+
}
|
|
1023
|
+
);
|
|
1024
|
+
const decorations = [widget];
|
|
1025
|
+
const $head = state.selection.$head;
|
|
1026
|
+
if ($head.depth > 0) {
|
|
1027
|
+
decorations.push(
|
|
1028
|
+
Decoration.node($head.before(), $head.after(), {
|
|
1029
|
+
class: "md-editor__has-dictation-ghost"
|
|
1030
|
+
})
|
|
1031
|
+
);
|
|
1032
|
+
}
|
|
1033
|
+
return DecorationSet.create(doc, decorations);
|
|
1034
|
+
}
|
|
1035
|
+
var dictationGhost = $prose(() => {
|
|
1036
|
+
return new Plugin({
|
|
1037
|
+
key: dictationGhostKey,
|
|
1038
|
+
state: {
|
|
1039
|
+
init: () => "",
|
|
1040
|
+
apply(tr, previous2) {
|
|
1041
|
+
const meta = tr.getMeta(dictationGhostKey);
|
|
1042
|
+
if (meta) return meta.text;
|
|
1043
|
+
if (tr.docChanged || tr.selectionSet) return "";
|
|
1044
|
+
return previous2;
|
|
1045
|
+
}
|
|
1046
|
+
},
|
|
1047
|
+
props: {
|
|
1048
|
+
decorations(state) {
|
|
1049
|
+
const text6 = dictationGhostKey.getState(state) ?? "";
|
|
1050
|
+
if (!text6) return DecorationSet.empty;
|
|
1051
|
+
return buildDecorations2(state, text6);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
});
|
|
1055
|
+
});
|
|
1056
|
+
function setDictationGhost(view, text6) {
|
|
1057
|
+
const current = dictationGhostKey.getState(view.state) ?? "";
|
|
1058
|
+
if (current === text6) return;
|
|
1059
|
+
const tr = view.state.tr.setMeta(dictationGhostKey, {
|
|
1060
|
+
text: text6
|
|
1061
|
+
});
|
|
1062
|
+
tr.setMeta("addToHistory", false);
|
|
1063
|
+
view.dispatch(tr);
|
|
1064
|
+
}
|
|
960
1065
|
|
|
961
1066
|
// src/shared/markdown/extensions/fileTag.ts
|
|
962
1067
|
var fileTag = $node("fileTag", () => ({
|
|
@@ -1866,7 +1971,7 @@ function EditorInner({
|
|
|
1866
1971
|
} catch {
|
|
1867
1972
|
}
|
|
1868
1973
|
});
|
|
1869
|
-
}).use(commonmark).use(history).use(clipboard).use(listener).use(autolink).use(fileTag).use(ssImageNode).use(ssImageView).use(htmlPreviewView).use(enableMentions ? mention : fileTag);
|
|
1974
|
+
}).use(commonmark).use(history).use(clipboard).use(listener).use(autolink).use(dictationGhost).use(fileTag).use(ssImageNode).use(ssImageView).use(htmlPreviewView).use(enableMentions ? mention : fileTag);
|
|
1870
1975
|
},
|
|
1871
1976
|
[isEditable]
|
|
1872
1977
|
);
|
|
@@ -2076,6 +2181,25 @@ function EditorInner({
|
|
|
2076
2181
|
return value ?? "";
|
|
2077
2182
|
}
|
|
2078
2183
|
},
|
|
2184
|
+
insertText: (text6) => {
|
|
2185
|
+
const view = viewRef.current;
|
|
2186
|
+
if (!view || !isEditable || !text6) return;
|
|
2187
|
+
try {
|
|
2188
|
+
const { from } = view.state.selection;
|
|
2189
|
+
const before = from > 0 ? view.state.doc.textBetween(from - 1, from, " ") : "";
|
|
2190
|
+
const needsSpace = before !== "" && !/\s/.test(before);
|
|
2191
|
+
insertTextAtSelection(view, (needsSpace ? " " : "") + text6);
|
|
2192
|
+
} catch {
|
|
2193
|
+
}
|
|
2194
|
+
},
|
|
2195
|
+
setDictationGhost: (text6) => {
|
|
2196
|
+
const view = viewRef.current;
|
|
2197
|
+
if (!view || !isEditable) return;
|
|
2198
|
+
try {
|
|
2199
|
+
setDictationGhost(view, text6);
|
|
2200
|
+
} catch {
|
|
2201
|
+
}
|
|
2202
|
+
},
|
|
2079
2203
|
clear: () => {
|
|
2080
2204
|
const view = viewRef.current;
|
|
2081
2205
|
if (!view) return;
|
|
@@ -2419,6 +2543,327 @@ var MarkdownEditor = forwardRef((props, ref) => {
|
|
|
2419
2543
|
return /* @__PURE__ */ jsx(MilkdownProvider, { children: /* @__PURE__ */ jsx(EditorInner, { ...props, editorHandleRef: ref }) });
|
|
2420
2544
|
});
|
|
2421
2545
|
MarkdownEditor.displayName = "MarkdownEditor";
|
|
2546
|
+
var TOKEN_EXPIRY_MARGIN_MS = 15e3;
|
|
2547
|
+
var noLevelMonitor = () => void 0;
|
|
2548
|
+
var SILENCE_HINT_MS = 6e3;
|
|
2549
|
+
var SILENCE_LEVEL = 3;
|
|
2550
|
+
function monitorInputLevel(stream, onSilent, onSound) {
|
|
2551
|
+
let context;
|
|
2552
|
+
let source;
|
|
2553
|
+
let analyser;
|
|
2554
|
+
try {
|
|
2555
|
+
context = new AudioContext();
|
|
2556
|
+
source = context.createMediaStreamSource(stream);
|
|
2557
|
+
analyser = context.createAnalyser();
|
|
2558
|
+
analyser.fftSize = 512;
|
|
2559
|
+
source.connect(analyser);
|
|
2560
|
+
} catch {
|
|
2561
|
+
return () => void 0;
|
|
2562
|
+
}
|
|
2563
|
+
if (context.state === "suspended")
|
|
2564
|
+
void context.resume().catch(() => void 0);
|
|
2565
|
+
const samples = new Uint8Array(analyser.fftSize);
|
|
2566
|
+
let lastSound = Date.now();
|
|
2567
|
+
let silent = false;
|
|
2568
|
+
let stopped = false;
|
|
2569
|
+
const poll = window.setInterval(() => {
|
|
2570
|
+
if (context.state !== "running") return;
|
|
2571
|
+
analyser.getByteTimeDomainData(samples);
|
|
2572
|
+
let peak = 0;
|
|
2573
|
+
for (const sample of samples) peak = Math.max(peak, Math.abs(sample - 128));
|
|
2574
|
+
if (peak > SILENCE_LEVEL) {
|
|
2575
|
+
lastSound = Date.now();
|
|
2576
|
+
if (silent) {
|
|
2577
|
+
silent = false;
|
|
2578
|
+
onSound();
|
|
2579
|
+
}
|
|
2580
|
+
} else if (!silent && Date.now() - lastSound > SILENCE_HINT_MS) {
|
|
2581
|
+
silent = true;
|
|
2582
|
+
onSilent();
|
|
2583
|
+
}
|
|
2584
|
+
}, 250);
|
|
2585
|
+
return () => {
|
|
2586
|
+
if (stopped) return;
|
|
2587
|
+
stopped = true;
|
|
2588
|
+
window.clearInterval(poll);
|
|
2589
|
+
try {
|
|
2590
|
+
source.disconnect();
|
|
2591
|
+
void context.close().catch(() => void 0);
|
|
2592
|
+
} catch {
|
|
2593
|
+
}
|
|
2594
|
+
};
|
|
2595
|
+
}
|
|
2596
|
+
var STALE_TOKEN_FLOOR_MS = 6e4;
|
|
2597
|
+
function kickOff(fn) {
|
|
2598
|
+
let promise;
|
|
2599
|
+
try {
|
|
2600
|
+
promise = Promise.resolve(fn());
|
|
2601
|
+
} catch (e) {
|
|
2602
|
+
promise = Promise.reject(e);
|
|
2603
|
+
}
|
|
2604
|
+
promise.catch(() => void 0);
|
|
2605
|
+
return promise;
|
|
2606
|
+
}
|
|
2607
|
+
var isSupported = () => typeof window !== "undefined" && window.isSecureContext && !!navigator.mediaDevices?.getUserMedia;
|
|
2608
|
+
function classifyTokenFailure(error) {
|
|
2609
|
+
const code3 = error?.code;
|
|
2610
|
+
if (code3 === "speech.identity_misconfigured" || code3 === "SP500")
|
|
2611
|
+
return "unavailable";
|
|
2612
|
+
if (error?.type === "NotFound") {
|
|
2613
|
+
return "unavailable";
|
|
2614
|
+
}
|
|
2615
|
+
return "unavailable-temporarily";
|
|
2616
|
+
}
|
|
2617
|
+
function useDictation({
|
|
2618
|
+
region,
|
|
2619
|
+
locale,
|
|
2620
|
+
getToken,
|
|
2621
|
+
onPhrase,
|
|
2622
|
+
onInterim,
|
|
2623
|
+
maxDurationMs = 18e4,
|
|
2624
|
+
idleTimeoutMs = 2e4
|
|
2625
|
+
}) {
|
|
2626
|
+
const [state, setState] = useState("idle");
|
|
2627
|
+
const [error, setError] = useState(null);
|
|
2628
|
+
const [deviceLabel, setDeviceLabel] = useState("");
|
|
2629
|
+
const [silent, setSilent] = useState(false);
|
|
2630
|
+
const sessionRef = useRef(null);
|
|
2631
|
+
const generationRef = useRef(0);
|
|
2632
|
+
const onPhraseRef = useRef(onPhrase);
|
|
2633
|
+
const onInterimRef = useRef(onInterim);
|
|
2634
|
+
useEffect(() => {
|
|
2635
|
+
onPhraseRef.current = onPhrase;
|
|
2636
|
+
onInterimRef.current = onInterim;
|
|
2637
|
+
});
|
|
2638
|
+
const clearInterim = useCallback(() => onInterimRef.current?.(""), []);
|
|
2639
|
+
const supported = isSupported();
|
|
2640
|
+
const available = supported && !!region && !!getToken;
|
|
2641
|
+
useEffect(() => {
|
|
2642
|
+
if (!available) return;
|
|
2643
|
+
const nav = navigator;
|
|
2644
|
+
if (nav.connection?.saveData) return;
|
|
2645
|
+
const warm = () => void kickOff(() => import('microsoft-cognitiveservices-speech-sdk'));
|
|
2646
|
+
if (typeof window.requestIdleCallback === "function") {
|
|
2647
|
+
const id2 = window.requestIdleCallback(warm, { timeout: 2e3 });
|
|
2648
|
+
return () => window.cancelIdleCallback(id2);
|
|
2649
|
+
}
|
|
2650
|
+
const id = window.setTimeout(warm, 1500);
|
|
2651
|
+
return () => window.clearTimeout(id);
|
|
2652
|
+
}, [available]);
|
|
2653
|
+
const stop = useCallback(() => {
|
|
2654
|
+
generationRef.current += 1;
|
|
2655
|
+
const session = sessionRef.current;
|
|
2656
|
+
sessionRef.current = null;
|
|
2657
|
+
clearInterim();
|
|
2658
|
+
setState("idle");
|
|
2659
|
+
setSilent(false);
|
|
2660
|
+
setDeviceLabel("");
|
|
2661
|
+
if (!session) return;
|
|
2662
|
+
window.clearTimeout(session.timers.idle);
|
|
2663
|
+
window.clearTimeout(session.timers.max);
|
|
2664
|
+
session.stopLevelMonitor();
|
|
2665
|
+
session.stream.getTracks().forEach((t) => t.stop());
|
|
2666
|
+
session.recognizer.stopContinuousRecognitionAsync(
|
|
2667
|
+
() => session.recognizer.close(),
|
|
2668
|
+
() => session.recognizer.close()
|
|
2669
|
+
);
|
|
2670
|
+
}, [clearInterim]);
|
|
2671
|
+
const start = useCallback(async () => {
|
|
2672
|
+
if (!available || sessionRef.current) return;
|
|
2673
|
+
const generation = ++generationRef.current;
|
|
2674
|
+
const superseded = () => generationRef.current !== generation;
|
|
2675
|
+
setError(null);
|
|
2676
|
+
setSilent(false);
|
|
2677
|
+
setState("starting");
|
|
2678
|
+
const streamPromise = kickOff(
|
|
2679
|
+
() => navigator.mediaDevices.getUserMedia({
|
|
2680
|
+
audio: {
|
|
2681
|
+
echoCancellation: true,
|
|
2682
|
+
noiseSuppression: true,
|
|
2683
|
+
autoGainControl: true
|
|
2684
|
+
}
|
|
2685
|
+
})
|
|
2686
|
+
);
|
|
2687
|
+
const tokenPromise = kickOff(getToken);
|
|
2688
|
+
const sdkPromise = kickOff(
|
|
2689
|
+
() => import('microsoft-cognitiveservices-speech-sdk')
|
|
2690
|
+
);
|
|
2691
|
+
let stream;
|
|
2692
|
+
try {
|
|
2693
|
+
stream = await streamPromise;
|
|
2694
|
+
} catch (e) {
|
|
2695
|
+
if (superseded()) return;
|
|
2696
|
+
const name = e?.name;
|
|
2697
|
+
setError(
|
|
2698
|
+
name === "NotAllowedError" || name === "SecurityError" ? "permission-denied" : name === "NotFoundError" || name === "OverconstrainedError" ? "no-microphone" : "unknown"
|
|
2699
|
+
);
|
|
2700
|
+
setState("idle");
|
|
2701
|
+
return;
|
|
2702
|
+
}
|
|
2703
|
+
if (superseded()) {
|
|
2704
|
+
stream.getTracks().forEach((t) => t.stop());
|
|
2705
|
+
return;
|
|
2706
|
+
}
|
|
2707
|
+
let token;
|
|
2708
|
+
try {
|
|
2709
|
+
token = await tokenPromise;
|
|
2710
|
+
if (Date.parse(token.expiresOn) - Date.now() < STALE_TOKEN_FLOOR_MS) {
|
|
2711
|
+
token = await getToken();
|
|
2712
|
+
}
|
|
2713
|
+
} catch (e) {
|
|
2714
|
+
stream.getTracks().forEach((t) => t.stop());
|
|
2715
|
+
if (superseded()) return;
|
|
2716
|
+
setError(classifyTokenFailure(e));
|
|
2717
|
+
setState("idle");
|
|
2718
|
+
return;
|
|
2719
|
+
}
|
|
2720
|
+
if (superseded()) {
|
|
2721
|
+
stream.getTracks().forEach((t) => t.stop());
|
|
2722
|
+
return;
|
|
2723
|
+
}
|
|
2724
|
+
let recognizer = null;
|
|
2725
|
+
let published = null;
|
|
2726
|
+
try {
|
|
2727
|
+
const sdk = await sdkPromise;
|
|
2728
|
+
if (superseded()) {
|
|
2729
|
+
stream.getTracks().forEach((t) => t.stop());
|
|
2730
|
+
return;
|
|
2731
|
+
}
|
|
2732
|
+
const speechConfig = sdk.SpeechConfig.fromAuthorizationToken(
|
|
2733
|
+
token.token,
|
|
2734
|
+
region
|
|
2735
|
+
);
|
|
2736
|
+
speechConfig.speechRecognitionLanguage = locale;
|
|
2737
|
+
speechConfig.setProfanity(sdk.ProfanityOption.Raw);
|
|
2738
|
+
speechConfig.setProperty(
|
|
2739
|
+
sdk.PropertyId.Speech_SegmentationSilenceTimeoutMs,
|
|
2740
|
+
"700"
|
|
2741
|
+
);
|
|
2742
|
+
recognizer = new sdk.SpeechRecognizer(
|
|
2743
|
+
speechConfig,
|
|
2744
|
+
sdk.AudioConfig.fromStreamInput(stream)
|
|
2745
|
+
);
|
|
2746
|
+
const untilExpiry = Date.parse(token.expiresOn) - Date.now() - TOKEN_EXPIRY_MARGIN_MS;
|
|
2747
|
+
const sessionCapMs = Number.isFinite(untilExpiry) && untilExpiry > 0 ? Math.min(maxDurationMs, untilExpiry) : maxDurationMs;
|
|
2748
|
+
const session = {
|
|
2749
|
+
recognizer,
|
|
2750
|
+
stream,
|
|
2751
|
+
timers: {},
|
|
2752
|
+
stopLevelMonitor: noLevelMonitor
|
|
2753
|
+
};
|
|
2754
|
+
const armIdle = () => {
|
|
2755
|
+
window.clearTimeout(session.timers.idle);
|
|
2756
|
+
session.timers.idle = window.setTimeout(stop, idleTimeoutMs);
|
|
2757
|
+
};
|
|
2758
|
+
const isLive = () => sessionRef.current === session;
|
|
2759
|
+
sessionRef.current = session;
|
|
2760
|
+
published = session;
|
|
2761
|
+
const goLive = () => {
|
|
2762
|
+
if (!isLive()) return;
|
|
2763
|
+
session.timers.max ??= window.setTimeout(stop, sessionCapMs);
|
|
2764
|
+
if (session.stopLevelMonitor === noLevelMonitor) {
|
|
2765
|
+
try {
|
|
2766
|
+
setDeviceLabel(stream.getAudioTracks()[0]?.label ?? "");
|
|
2767
|
+
session.stopLevelMonitor = monitorInputLevel(
|
|
2768
|
+
stream,
|
|
2769
|
+
() => {
|
|
2770
|
+
if (isLive()) setSilent(true);
|
|
2771
|
+
},
|
|
2772
|
+
() => {
|
|
2773
|
+
if (isLive()) setSilent(false);
|
|
2774
|
+
}
|
|
2775
|
+
);
|
|
2776
|
+
} catch {
|
|
2777
|
+
session.stopLevelMonitor = noLevelMonitor;
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2780
|
+
armIdle();
|
|
2781
|
+
setState("listening");
|
|
2782
|
+
};
|
|
2783
|
+
recognizer.sessionStarted = () => goLive();
|
|
2784
|
+
recognizer.recognizing = (_sender, event) => {
|
|
2785
|
+
if (!isLive()) return;
|
|
2786
|
+
onInterimRef.current?.(event.result.text ?? "");
|
|
2787
|
+
armIdle();
|
|
2788
|
+
};
|
|
2789
|
+
recognizer.recognized = (_sender, event) => {
|
|
2790
|
+
if (!isLive()) return;
|
|
2791
|
+
const text6 = event.result.text?.trim();
|
|
2792
|
+
clearInterim();
|
|
2793
|
+
if (event.result.reason === sdk.ResultReason.RecognizedSpeech && text6) {
|
|
2794
|
+
onPhraseRef.current(text6);
|
|
2795
|
+
}
|
|
2796
|
+
armIdle();
|
|
2797
|
+
};
|
|
2798
|
+
recognizer.canceled = (_sender, event) => {
|
|
2799
|
+
if (!isLive()) return;
|
|
2800
|
+
if (event.reason === sdk.CancellationReason.Error) {
|
|
2801
|
+
console.warn("[dictation] cancelled, errorCode:", event.errorCode);
|
|
2802
|
+
setError(
|
|
2803
|
+
event.errorCode === sdk.CancellationErrorCode.ConnectionFailure ? "network" : event.errorCode === sdk.CancellationErrorCode.AuthenticationFailure ? "unavailable-temporarily" : "unknown"
|
|
2804
|
+
);
|
|
2805
|
+
}
|
|
2806
|
+
stop();
|
|
2807
|
+
};
|
|
2808
|
+
recognizer.sessionStopped = () => {
|
|
2809
|
+
if (isLive()) stop();
|
|
2810
|
+
};
|
|
2811
|
+
try {
|
|
2812
|
+
const connection = sdk.Connection.fromRecognizer(recognizer);
|
|
2813
|
+
connection.connected = () => goLive();
|
|
2814
|
+
connection.openConnection();
|
|
2815
|
+
} catch {
|
|
2816
|
+
}
|
|
2817
|
+
await new Promise(
|
|
2818
|
+
(resolve, reject) => session.recognizer.startContinuousRecognitionAsync(resolve, reject)
|
|
2819
|
+
);
|
|
2820
|
+
goLive();
|
|
2821
|
+
} catch (e) {
|
|
2822
|
+
stream.getTracks().forEach((t) => t.stop());
|
|
2823
|
+
try {
|
|
2824
|
+
recognizer?.close();
|
|
2825
|
+
} catch {
|
|
2826
|
+
}
|
|
2827
|
+
if (published) {
|
|
2828
|
+
window.clearTimeout(published.timers.idle);
|
|
2829
|
+
window.clearTimeout(published.timers.max);
|
|
2830
|
+
published.stopLevelMonitor();
|
|
2831
|
+
if (sessionRef.current === published) sessionRef.current = null;
|
|
2832
|
+
}
|
|
2833
|
+
if (superseded()) return;
|
|
2834
|
+
console.warn("[dictation] failed to start:", e);
|
|
2835
|
+
setError((prev) => prev ?? "unavailable-temporarily");
|
|
2836
|
+
setState("idle");
|
|
2837
|
+
}
|
|
2838
|
+
}, [
|
|
2839
|
+
available,
|
|
2840
|
+
clearInterim,
|
|
2841
|
+
getToken,
|
|
2842
|
+
idleTimeoutMs,
|
|
2843
|
+
locale,
|
|
2844
|
+
maxDurationMs,
|
|
2845
|
+
region,
|
|
2846
|
+
stop
|
|
2847
|
+
]);
|
|
2848
|
+
useEffect(() => stop, [stop]);
|
|
2849
|
+
const toggle = useCallback(() => {
|
|
2850
|
+
if (state === "idle") void start();
|
|
2851
|
+
else stop();
|
|
2852
|
+
}, [start, state, stop]);
|
|
2853
|
+
return {
|
|
2854
|
+
supported,
|
|
2855
|
+
available,
|
|
2856
|
+
state,
|
|
2857
|
+
error,
|
|
2858
|
+
/** Name of the microphone in use, once a session is live. May be ''. */
|
|
2859
|
+
deviceLabel,
|
|
2860
|
+
/** Listening, but the microphone has produced no sound for a while. */
|
|
2861
|
+
silent,
|
|
2862
|
+
start,
|
|
2863
|
+
stop,
|
|
2864
|
+
toggle
|
|
2865
|
+
};
|
|
2866
|
+
}
|
|
2422
2867
|
function useFlowRunVariables(flowRunId) {
|
|
2423
2868
|
const service = useChatService();
|
|
2424
2869
|
return useQuery({
|
|
@@ -2430,6 +2875,31 @@ function useFlowRunVariables(flowRunId) {
|
|
|
2430
2875
|
enabled: !!flowRunId
|
|
2431
2876
|
});
|
|
2432
2877
|
}
|
|
2878
|
+
|
|
2879
|
+
// src/chat-variables/renders/fieldStyles.ts
|
|
2880
|
+
var scaleFor = (surface) => surface === "form" ? "comfortable" : "dense";
|
|
2881
|
+
var fieldLabelClass = (scale) => `block truncate font-medium text-muted-foreground ${scale === "dense" ? "mb-1 text-xs" : "mb-1.5 text-sm"}`;
|
|
2882
|
+
var CONTROL_BASE = "rounded-md border bg-background text-foreground transition-colors placeholder:text-muted-foreground ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-60";
|
|
2883
|
+
var borderClass = (hasError) => hasError ? "border-destructive" : "border-input";
|
|
2884
|
+
var fieldControlClass = (scale, hasError) => `w-full ${CONTROL_BASE} ${borderClass(hasError)} ${scale === "dense" ? "px-2.5 py-1.5 text-xs" : "px-3 py-2 text-sm"}`;
|
|
2885
|
+
var fieldTriggerClass = (scale, hasError) => `w-full ${CONTROL_BASE} ${borderClass(
|
|
2886
|
+
hasError
|
|
2887
|
+
)} flex items-center justify-between gap-2 text-left ${scale === "dense" ? "h-8 px-2.5 text-xs" : "h-10 px-3 text-sm"}`;
|
|
2888
|
+
var fieldNumberClass = (scale, hasError) => `${CONTROL_BASE} ${borderClass(hasError)} tabular-nums ${scale === "dense" ? "h-8 w-20 px-2 text-xs" : "h-10 w-24 px-2.5 text-sm"}`;
|
|
2889
|
+
var fieldHintClass = "mt-1 text-xs text-muted-foreground";
|
|
2890
|
+
var fieldErrorClass = "mt-1 text-xs text-destructive";
|
|
2891
|
+
var fieldRowClass = "flex items-center justify-between gap-3";
|
|
2892
|
+
var fieldRowLabelClass = (scale) => `min-w-0 flex-1 truncate font-medium text-muted-foreground ${scale === "dense" ? "text-xs" : "text-sm"}`;
|
|
2893
|
+
var pillClass = (opts) => `flex h-8 shrink-0 items-center gap-1.5 rounded-full border px-2.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary ${opts.active ? "border-primary/30 bg-primary/10 text-primary" : "border-border/70 bg-transparent text-muted-foreground hover:bg-secondary"} ${opts.hasError ? "border-destructive text-destructive" : ""} ${opts.disabled ? "cursor-not-allowed opacity-60" : ""}`;
|
|
2894
|
+
var pillLabelClass = "max-w-[9rem] truncate";
|
|
2895
|
+
var pillValueClass = "max-w-[9rem] truncate text-foreground";
|
|
2896
|
+
var switchTrackClass = (on, disabled) => `peer inline-flex h-6 w-11 shrink-0 items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background ${on ? "bg-primary" : "bg-input"} ${disabled ? "cursor-not-allowed opacity-50" : "cursor-pointer"}`;
|
|
2897
|
+
var switchThumbClass = (on) => `pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform ${on ? "translate-x-5" : "translate-x-0"}`;
|
|
2898
|
+
var POPOVER_WIDTH_PX = 288;
|
|
2899
|
+
var POPOVER_MAX_HEIGHT_PX = 288;
|
|
2900
|
+
var popoverClass = "flex flex-col overflow-hidden rounded-xl border border-border bg-popover shadow-lg";
|
|
2901
|
+
var popoverRowClass = "flex w-full items-center gap-2.5 px-3 py-2 text-left transition-colors hover:bg-secondary/60";
|
|
2902
|
+
var popoverHeadingClass = "text-[10px] font-semibold uppercase tracking-wide text-muted-foreground";
|
|
2433
2903
|
function iconFor(label) {
|
|
2434
2904
|
const name = (label ?? "").toLowerCase();
|
|
2435
2905
|
if (/search|web|browse|internet/.test(name)) return Globe;
|
|
@@ -2445,7 +2915,8 @@ var BooleanRenderer = ({
|
|
|
2445
2915
|
errors,
|
|
2446
2916
|
uischema,
|
|
2447
2917
|
visible,
|
|
2448
|
-
enabled
|
|
2918
|
+
enabled,
|
|
2919
|
+
config
|
|
2449
2920
|
}) => {
|
|
2450
2921
|
const onToggle = useCallback(() => {
|
|
2451
2922
|
handleChange(path2, !data);
|
|
@@ -2456,13 +2927,17 @@ var BooleanRenderer = ({
|
|
|
2456
2927
|
const hasError = !!errors && errors.length > 0;
|
|
2457
2928
|
const isChecked = Boolean(data);
|
|
2458
2929
|
const Icon = iconFor(label);
|
|
2930
|
+
const surface = (config ?? {}).surface ?? "form";
|
|
2931
|
+
const scale = scaleFor(surface);
|
|
2459
2932
|
const tooltip = [label, description, hasError ? errors : null].filter(Boolean).join(" \u2014 ");
|
|
2460
|
-
|
|
2933
|
+
const toggle = /* @__PURE__ */ jsx(
|
|
2461
2934
|
"button",
|
|
2462
2935
|
{
|
|
2463
2936
|
id: `toggle-${path2}`,
|
|
2464
2937
|
type: "button",
|
|
2465
|
-
"
|
|
2938
|
+
role: surface === "bar" ? void 0 : "switch",
|
|
2939
|
+
"aria-pressed": surface === "bar" ? isChecked : void 0,
|
|
2940
|
+
"aria-checked": surface === "bar" ? void 0 : isChecked,
|
|
2466
2941
|
"aria-label": label,
|
|
2467
2942
|
title: tooltip || void 0,
|
|
2468
2943
|
onClick: onToggle,
|
|
@@ -2472,16 +2947,28 @@ var BooleanRenderer = ({
|
|
|
2472
2947
|
e.currentTarget.blur();
|
|
2473
2948
|
}
|
|
2474
2949
|
},
|
|
2475
|
-
className:
|
|
2476
|
-
|
|
2950
|
+
className: surface === "bar" ? `boolean-switch ${pillClass({
|
|
2951
|
+
active: isChecked,
|
|
2952
|
+
hasError,
|
|
2953
|
+
disabled: isDisabled
|
|
2954
|
+
})}` : switchTrackClass(isChecked, isDisabled),
|
|
2955
|
+
children: surface === "bar" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2477
2956
|
/* @__PURE__ */ jsx(Icon, { className: "h-3.5 w-3.5 shrink-0" }),
|
|
2478
2957
|
label && // Desktop-first: the app and the package each ship a full Tailwind
|
|
2479
|
-
// build, so a base `hidden` can out-order `sm:inline`.
|
|
2480
|
-
// is the form that survives both cascades.
|
|
2481
|
-
/* @__PURE__ */ jsx("span", { className:
|
|
2482
|
-
]
|
|
2958
|
+
// build, so a base `hidden` can out-order `sm:inline`.
|
|
2959
|
+
// `max-sm:hidden` is the form that survives both cascades.
|
|
2960
|
+
/* @__PURE__ */ jsx("span", { className: `inline ${pillLabelClass} max-sm:hidden`, children: label })
|
|
2961
|
+
] }) : /* @__PURE__ */ jsx("span", { className: switchThumbClass(isChecked) })
|
|
2483
2962
|
}
|
|
2484
2963
|
);
|
|
2964
|
+
if (surface === "bar") return toggle;
|
|
2965
|
+
return /* @__PURE__ */ jsxs("div", { className: "ss-jsonforms-field ss-jsonforms-boolean", children: [
|
|
2966
|
+
/* @__PURE__ */ jsxs("div", { className: fieldRowClass, children: [
|
|
2967
|
+
/* @__PURE__ */ jsx("label", { htmlFor: `toggle-${path2}`, className: fieldRowLabelClass(scale), children: label }),
|
|
2968
|
+
toggle
|
|
2969
|
+
] }),
|
|
2970
|
+
hasError && /* @__PURE__ */ jsx("div", { className: fieldErrorClass, children: errors })
|
|
2971
|
+
] });
|
|
2485
2972
|
};
|
|
2486
2973
|
var booleanRendererTester = rankWith(40, (uischema, schema) => {
|
|
2487
2974
|
if (uischema.type !== "Control") return false;
|
|
@@ -2491,6 +2978,104 @@ var booleanRendererTester = rankWith(40, (uischema, schema) => {
|
|
|
2491
2978
|
return fieldSchema?.type === "boolean";
|
|
2492
2979
|
});
|
|
2493
2980
|
var BooleanRendererControl = withJsonFormsControlProps(BooleanRenderer);
|
|
2981
|
+
var GAP_PX = 8;
|
|
2982
|
+
var MIN_TRIGGER_WIDTH_PX = 224;
|
|
2983
|
+
var MIN_PANEL_HEIGHT_PX = 180;
|
|
2984
|
+
var NestedPopoverContext = React9__default.createContext(null);
|
|
2985
|
+
function useAnchoredPopover({
|
|
2986
|
+
trigger,
|
|
2987
|
+
popover,
|
|
2988
|
+
width,
|
|
2989
|
+
maxHeight,
|
|
2990
|
+
role,
|
|
2991
|
+
label
|
|
2992
|
+
}) {
|
|
2993
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
2994
|
+
const parentRegistry = useContext(NestedPopoverContext);
|
|
2995
|
+
const descendants = useRef(/* @__PURE__ */ new Set());
|
|
2996
|
+
const close = useCallback(() => setIsOpen(false), []);
|
|
2997
|
+
const toggle = useCallback(() => setIsOpen((open) => !open), []);
|
|
2998
|
+
const registry = useMemo(
|
|
2999
|
+
() => ({
|
|
3000
|
+
register: (el) => {
|
|
3001
|
+
descendants.current.add(el);
|
|
3002
|
+
parentRegistry?.register(el);
|
|
3003
|
+
},
|
|
3004
|
+
unregister: (el) => {
|
|
3005
|
+
descendants.current.delete(el);
|
|
3006
|
+
parentRegistry?.unregister(el);
|
|
3007
|
+
}
|
|
3008
|
+
}),
|
|
3009
|
+
[parentRegistry]
|
|
3010
|
+
);
|
|
3011
|
+
useEffect(() => {
|
|
3012
|
+
if (!isOpen || !parentRegistry) return;
|
|
3013
|
+
const el = popover.current;
|
|
3014
|
+
if (!el) return;
|
|
3015
|
+
parentRegistry.register(el);
|
|
3016
|
+
return () => parentRegistry.unregister(el);
|
|
3017
|
+
}, [isOpen, parentRegistry, popover]);
|
|
3018
|
+
useEffect(() => {
|
|
3019
|
+
if (!isOpen) return;
|
|
3020
|
+
const onPointerDown = (event) => {
|
|
3021
|
+
const target = event.target;
|
|
3022
|
+
if (trigger.current?.contains(target)) return;
|
|
3023
|
+
if (popover.current?.contains(target)) return;
|
|
3024
|
+
for (const el of descendants.current) {
|
|
3025
|
+
if (el.contains(target)) return;
|
|
3026
|
+
}
|
|
3027
|
+
close();
|
|
3028
|
+
};
|
|
3029
|
+
const onKeyDown = (event) => {
|
|
3030
|
+
if (event.key === "Escape") close();
|
|
3031
|
+
};
|
|
3032
|
+
document.addEventListener("mousedown", onPointerDown);
|
|
3033
|
+
document.addEventListener("keydown", onKeyDown);
|
|
3034
|
+
window.addEventListener("resize", close);
|
|
3035
|
+
return () => {
|
|
3036
|
+
document.removeEventListener("mousedown", onPointerDown);
|
|
3037
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
3038
|
+
window.removeEventListener("resize", close);
|
|
3039
|
+
};
|
|
3040
|
+
}, [isOpen, close, trigger, popover]);
|
|
3041
|
+
const renderPopover = (children2) => {
|
|
3042
|
+
if (!isOpen) return null;
|
|
3043
|
+
const anchor = trigger.current?.getBoundingClientRect();
|
|
3044
|
+
if (!anchor) return null;
|
|
3045
|
+
const panelWidth = width === "trigger" ? Math.max(anchor.width, MIN_TRIGGER_WIDTH_PX) : width;
|
|
3046
|
+
const spaceAbove = anchor.top - GAP_PX * 2;
|
|
3047
|
+
const spaceBelow = window.innerHeight - anchor.bottom - GAP_PX * 2;
|
|
3048
|
+
const openAbove = spaceAbove >= MIN_PANEL_HEIGHT_PX || spaceAbove >= spaceBelow;
|
|
3049
|
+
const panelMaxHeight = Math.max(
|
|
3050
|
+
0,
|
|
3051
|
+
Math.min(maxHeight, openAbove ? spaceAbove : spaceBelow)
|
|
3052
|
+
);
|
|
3053
|
+
return createPortal(
|
|
3054
|
+
/* @__PURE__ */ jsx(
|
|
3055
|
+
"div",
|
|
3056
|
+
{
|
|
3057
|
+
ref: popover,
|
|
3058
|
+
role,
|
|
3059
|
+
"aria-label": label,
|
|
3060
|
+
className: `fixed z-50 ${popoverClass}`,
|
|
3061
|
+
style: {
|
|
3062
|
+
width: panelWidth,
|
|
3063
|
+
maxWidth: `calc(100vw - ${GAP_PX * 4}px)`,
|
|
3064
|
+
left: Math.max(
|
|
3065
|
+
GAP_PX,
|
|
3066
|
+
Math.min(anchor.left, window.innerWidth - panelWidth - GAP_PX)
|
|
3067
|
+
),
|
|
3068
|
+
...openAbove ? { bottom: window.innerHeight - anchor.top + GAP_PX } : { top: anchor.bottom + GAP_PX },
|
|
3069
|
+
maxHeight: panelMaxHeight
|
|
3070
|
+
},
|
|
3071
|
+
children: /* @__PURE__ */ jsx(NestedPopoverContext.Provider, { value: registry, children: children2 })
|
|
3072
|
+
}
|
|
3073
|
+
),
|
|
3074
|
+
document.body
|
|
3075
|
+
);
|
|
3076
|
+
};
|
|
3077
|
+
return { isOpen, close, toggle, renderPopover };
|
|
3078
|
+
}
|
|
2494
3079
|
function hasConst(x) {
|
|
2495
3080
|
return !!x && typeof x === "object" && "const" in x;
|
|
2496
3081
|
}
|
|
@@ -2529,185 +3114,109 @@ var DropdownRenderer = ({
|
|
|
2529
3114
|
label,
|
|
2530
3115
|
description,
|
|
2531
3116
|
errors,
|
|
2532
|
-
|
|
3117
|
+
config,
|
|
3118
|
+
uischema,
|
|
3119
|
+
visible
|
|
2533
3120
|
}) => {
|
|
3121
|
+
const triggerRef = useRef(null);
|
|
3122
|
+
const listRef = useRef(null);
|
|
3123
|
+
const surface = (config ?? {}).surface ?? "form";
|
|
3124
|
+
const scale = scaleFor(surface);
|
|
3125
|
+
const { isOpen, close, toggle, renderPopover } = useAnchoredPopover({
|
|
3126
|
+
trigger: triggerRef,
|
|
3127
|
+
popover: listRef,
|
|
3128
|
+
// A select's list lines up with its own control.
|
|
3129
|
+
width: "trigger",
|
|
3130
|
+
maxHeight: POPOVER_MAX_HEIGHT_PX,
|
|
3131
|
+
role: "listbox",
|
|
3132
|
+
label: label || "Options"
|
|
3133
|
+
});
|
|
2534
3134
|
const options = toOptions(schema);
|
|
2535
|
-
const
|
|
2536
|
-
(
|
|
2537
|
-
handleChange(path2,
|
|
3135
|
+
const select = useCallback(
|
|
3136
|
+
(value) => {
|
|
3137
|
+
handleChange(path2, value);
|
|
3138
|
+
close();
|
|
2538
3139
|
},
|
|
2539
|
-
[handleChange, path2]
|
|
3140
|
+
[handleChange, path2, close]
|
|
2540
3141
|
);
|
|
2541
|
-
|
|
3142
|
+
if (!visible) return null;
|
|
2542
3143
|
const readOnly = uischema?.access === "Read";
|
|
2543
3144
|
const isDisabled = !enabled || readOnly;
|
|
2544
|
-
|
|
2545
|
-
|
|
3145
|
+
const hasError = !!errors;
|
|
3146
|
+
const selected = options.find((option) => option.const === data);
|
|
3147
|
+
const valueText = selected ? selected.title ?? String(selected.const) : data != null && data !== "" ? String(data) : "";
|
|
3148
|
+
const triggerId = `${path2}-trigger`;
|
|
3149
|
+
const isBar = surface === "bar";
|
|
3150
|
+
const placeholder = `Select ${(label || "value").toLowerCase()}\u2026`;
|
|
3151
|
+
const trigger = /* @__PURE__ */ jsxs(
|
|
3152
|
+
"button",
|
|
2546
3153
|
{
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
error: !!errors,
|
|
3154
|
+
id: triggerId,
|
|
3155
|
+
ref: triggerRef,
|
|
3156
|
+
type: "button",
|
|
2551
3157
|
disabled: isDisabled,
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
3158
|
+
onClick: toggle,
|
|
3159
|
+
"aria-haspopup": "listbox",
|
|
3160
|
+
"aria-expanded": isOpen,
|
|
3161
|
+
"aria-label": label,
|
|
3162
|
+
title: [label, valueText, hasError ? errors : null].filter(Boolean).join(" \u2014 ") || void 0,
|
|
3163
|
+
className: isBar ? `ss-jsonforms-select-trigger ${pillClass({
|
|
3164
|
+
active: isOpen,
|
|
3165
|
+
hasError,
|
|
3166
|
+
disabled: isDisabled
|
|
3167
|
+
})}` : `ss-jsonforms-select-trigger ${fieldTriggerClass(scale, hasError)}`,
|
|
2556
3168
|
children: [
|
|
3169
|
+
isBar && label && /* @__PURE__ */ jsx("span", { className: `inline ${pillLabelClass} max-sm:hidden`, children: label }),
|
|
2557
3170
|
/* @__PURE__ */ jsx(
|
|
2558
|
-
|
|
3171
|
+
"span",
|
|
2559
3172
|
{
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
color: "#6b7280",
|
|
2563
|
-
fontSize: "0.875rem",
|
|
2564
|
-
fontWeight: 500,
|
|
2565
|
-
"&.Mui-focused": {
|
|
2566
|
-
color: "#6366f1"
|
|
2567
|
-
},
|
|
2568
|
-
"&.Mui-error": {
|
|
2569
|
-
color: "#ef4444"
|
|
2570
|
-
}
|
|
2571
|
-
},
|
|
2572
|
-
children: label
|
|
3173
|
+
className: isBar ? pillValueClass : `min-w-0 flex-1 truncate ${valueText ? "" : "text-muted-foreground"}`,
|
|
3174
|
+
children: valueText || (isBar ? "\u2014" : placeholder)
|
|
2573
3175
|
}
|
|
2574
3176
|
),
|
|
2575
3177
|
/* @__PURE__ */ jsx(
|
|
2576
|
-
|
|
3178
|
+
ChevronDown,
|
|
2577
3179
|
{
|
|
2578
|
-
|
|
2579
|
-
value: displayValue,
|
|
2580
|
-
onChange: handleSelectionChange,
|
|
2581
|
-
label,
|
|
2582
|
-
sx: {
|
|
2583
|
-
"& .MuiOutlinedInput-root": {
|
|
2584
|
-
backgroundColor: "#fafafa",
|
|
2585
|
-
borderRadius: "8px",
|
|
2586
|
-
transition: "all 0.2s ease-in-out",
|
|
2587
|
-
height: "40px",
|
|
2588
|
-
// Same height as model dropdown
|
|
2589
|
-
"& fieldset": {
|
|
2590
|
-
borderColor: "#e5e7eb",
|
|
2591
|
-
borderWidth: "1px"
|
|
2592
|
-
},
|
|
2593
|
-
"&:hover": {
|
|
2594
|
-
backgroundColor: "#ffffff",
|
|
2595
|
-
"& fieldset": {
|
|
2596
|
-
borderColor: "#9ca3af"
|
|
2597
|
-
}
|
|
2598
|
-
},
|
|
2599
|
-
"&.Mui-focused": {
|
|
2600
|
-
backgroundColor: "#ffffff",
|
|
2601
|
-
"& fieldset": {
|
|
2602
|
-
borderColor: "#6366f1",
|
|
2603
|
-
borderWidth: "2px"
|
|
2604
|
-
}
|
|
2605
|
-
},
|
|
2606
|
-
"&.Mui-error": {
|
|
2607
|
-
"& fieldset": {
|
|
2608
|
-
borderColor: "#ef4444"
|
|
2609
|
-
}
|
|
2610
|
-
}
|
|
2611
|
-
},
|
|
2612
|
-
"& .MuiSelect-select": {
|
|
2613
|
-
backgroundColor: "#fafafa",
|
|
2614
|
-
borderRadius: "8px",
|
|
2615
|
-
transition: "all 0.2s ease-in-out",
|
|
2616
|
-
height: "40px",
|
|
2617
|
-
display: "flex",
|
|
2618
|
-
alignItems: "center",
|
|
2619
|
-
paddingRight: "32px !important",
|
|
2620
|
-
"&:hover": {
|
|
2621
|
-
backgroundColor: "#ffffff"
|
|
2622
|
-
},
|
|
2623
|
-
"&.Mui-focused": {
|
|
2624
|
-
backgroundColor: "#ffffff"
|
|
2625
|
-
}
|
|
2626
|
-
},
|
|
2627
|
-
"& .MuiOutlinedInput-notchedOutline": {
|
|
2628
|
-
borderColor: "#e5e7eb",
|
|
2629
|
-
borderWidth: "1px",
|
|
2630
|
-
borderRadius: "8px"
|
|
2631
|
-
},
|
|
2632
|
-
"&:hover .MuiOutlinedInput-notchedOutline": {
|
|
2633
|
-
borderColor: "#9ca3af"
|
|
2634
|
-
},
|
|
2635
|
-
"&.Mui-focused .MuiOutlinedInput-notchedOutline": {
|
|
2636
|
-
borderColor: "#6366f1",
|
|
2637
|
-
borderWidth: "2px"
|
|
2638
|
-
},
|
|
2639
|
-
"&.Mui-error .MuiOutlinedInput-notchedOutline": {
|
|
2640
|
-
borderColor: "#ef4444"
|
|
2641
|
-
},
|
|
2642
|
-
"& .MuiSelect-icon": {
|
|
2643
|
-
color: "#9ca3af",
|
|
2644
|
-
"&:hover": {
|
|
2645
|
-
color: "#6b7280"
|
|
2646
|
-
}
|
|
2647
|
-
}
|
|
2648
|
-
},
|
|
2649
|
-
MenuProps: {
|
|
2650
|
-
PaperProps: {
|
|
2651
|
-
sx: {
|
|
2652
|
-
borderRadius: "8px",
|
|
2653
|
-
boxShadow: "0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)",
|
|
2654
|
-
border: "1px solid #e5e7eb",
|
|
2655
|
-
marginTop: "4px",
|
|
2656
|
-
maxHeight: "280px"
|
|
2657
|
-
}
|
|
2658
|
-
},
|
|
2659
|
-
MenuListProps: {
|
|
2660
|
-
sx: {
|
|
2661
|
-
padding: 0
|
|
2662
|
-
}
|
|
2663
|
-
}
|
|
2664
|
-
},
|
|
2665
|
-
children: options.map((option, index) => {
|
|
2666
|
-
const raw2 = option.const;
|
|
2667
|
-
const key = typeof raw2 === "string" || typeof raw2 === "number" ? String(raw2) : String(index);
|
|
2668
|
-
const value = typeof raw2 === "string" || typeof raw2 === "number" ? raw2 : String(raw2 ?? index);
|
|
2669
|
-
return /* @__PURE__ */ jsx(
|
|
2670
|
-
MenuItem,
|
|
2671
|
-
{
|
|
2672
|
-
value,
|
|
2673
|
-
sx: {
|
|
2674
|
-
padding: "12px 16px",
|
|
2675
|
-
fontSize: "0.875rem",
|
|
2676
|
-
borderBottom: "1px solid #f3f4f6",
|
|
2677
|
-
"&:last-child": {
|
|
2678
|
-
borderBottom: "none"
|
|
2679
|
-
},
|
|
2680
|
-
"&:hover": {
|
|
2681
|
-
backgroundColor: "#f8fafc"
|
|
2682
|
-
},
|
|
2683
|
-
"&.Mui-selected": {
|
|
2684
|
-
backgroundColor: "#eff6ff",
|
|
2685
|
-
"&:hover": {
|
|
2686
|
-
backgroundColor: "#dbeafe"
|
|
2687
|
-
}
|
|
2688
|
-
}
|
|
2689
|
-
},
|
|
2690
|
-
children: option.title ?? String(raw2)
|
|
2691
|
-
},
|
|
2692
|
-
key
|
|
2693
|
-
);
|
|
2694
|
-
})
|
|
2695
|
-
}
|
|
2696
|
-
),
|
|
2697
|
-
(description || errors) && /* @__PURE__ */ jsx(
|
|
2698
|
-
"div",
|
|
2699
|
-
{
|
|
2700
|
-
style: {
|
|
2701
|
-
fontSize: "0.75rem",
|
|
2702
|
-
marginTop: "4px",
|
|
2703
|
-
color: errors ? "#ef4444" : "#6b7280"
|
|
2704
|
-
},
|
|
2705
|
-
children: errors || description
|
|
3180
|
+
className: `shrink-0 opacity-50 ${isBar ? "h-3 w-3" : "h-4 w-4"}`
|
|
2706
3181
|
}
|
|
2707
3182
|
)
|
|
2708
3183
|
]
|
|
2709
3184
|
}
|
|
2710
3185
|
);
|
|
3186
|
+
return /* @__PURE__ */ jsxs("div", { className: "ss-jsonforms-field ss-jsonforms-select compact-field", children: [
|
|
3187
|
+
!isBar && label && /* @__PURE__ */ jsx("label", { htmlFor: triggerId, className: fieldLabelClass(scale), children: label }),
|
|
3188
|
+
trigger,
|
|
3189
|
+
!isBar && (errors || description) && /* @__PURE__ */ jsx("div", { className: errors ? fieldErrorClass : fieldHintClass, children: errors || description }),
|
|
3190
|
+
renderPopover(
|
|
3191
|
+
/* @__PURE__ */ jsxs("div", { className: "min-h-0 overflow-y-auto py-1", children: [
|
|
3192
|
+
options.length === 0 && /* @__PURE__ */ jsx("p", { className: "px-3 py-6 text-center text-xs text-muted-foreground", children: "No options available" }),
|
|
3193
|
+
options.map((option, index) => {
|
|
3194
|
+
const active = option.const === data;
|
|
3195
|
+
const text6 = option.title ?? String(option.const);
|
|
3196
|
+
return /* @__PURE__ */ jsxs(
|
|
3197
|
+
"button",
|
|
3198
|
+
{
|
|
3199
|
+
type: "button",
|
|
3200
|
+
role: "option",
|
|
3201
|
+
"aria-selected": active,
|
|
3202
|
+
onClick: () => select(option.const),
|
|
3203
|
+
className: popoverRowClass,
|
|
3204
|
+
children: [
|
|
3205
|
+
/* @__PURE__ */ jsx(
|
|
3206
|
+
Check,
|
|
3207
|
+
{
|
|
3208
|
+
className: `h-3.5 w-3.5 shrink-0 ${active ? "text-primary" : "opacity-0"}`
|
|
3209
|
+
}
|
|
3210
|
+
),
|
|
3211
|
+
/* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate text-sm text-foreground", children: text6 })
|
|
3212
|
+
]
|
|
3213
|
+
},
|
|
3214
|
+
typeof option.const === "string" || typeof option.const === "number" ? String(option.const) : `option-${index}`
|
|
3215
|
+
);
|
|
3216
|
+
})
|
|
3217
|
+
] })
|
|
3218
|
+
)
|
|
3219
|
+
] });
|
|
2711
3220
|
};
|
|
2712
3221
|
var dropdownRendererTester = rankWith(
|
|
2713
3222
|
90,
|
|
@@ -2725,8 +3234,8 @@ var dropdownRendererTester = rankWith(
|
|
|
2725
3234
|
return false;
|
|
2726
3235
|
}
|
|
2727
3236
|
const hasDropdownOptions = !!(fieldSchema.oneOf || fieldSchema.anyOf || fieldSchema.enum && Array.isArray(fieldSchema.enum));
|
|
2728
|
-
const
|
|
2729
|
-
return hasDropdownOptions && !
|
|
3237
|
+
const isModelSelector2 = typeof fieldSchema === "object" && fieldSchema && fieldSchema["x-model-selector"] === true || fieldSchema.title === "ModelId" || fieldSchema.format === "uuid";
|
|
3238
|
+
return hasDropdownOptions && !isModelSelector2;
|
|
2730
3239
|
}
|
|
2731
3240
|
);
|
|
2732
3241
|
var DropdownRendererControl = withJsonFormsControlProps(DropdownRenderer);
|
|
@@ -2761,7 +3270,8 @@ var JsonEditorRenderer = ({
|
|
|
2761
3270
|
uischema,
|
|
2762
3271
|
visible,
|
|
2763
3272
|
enabled,
|
|
2764
|
-
required
|
|
3273
|
+
required,
|
|
3274
|
+
config
|
|
2765
3275
|
}) => {
|
|
2766
3276
|
const [jsonValue, setJsonValue] = useState("");
|
|
2767
3277
|
const [displayedParseError, setDisplayedParseError] = useState(
|
|
@@ -2815,43 +3325,19 @@ var JsonEditorRenderer = ({
|
|
|
2815
3325
|
}
|
|
2816
3326
|
const readOnly = uischema?.access === "Read";
|
|
2817
3327
|
const isDisabled = !enabled || readOnly;
|
|
3328
|
+
const scale = scaleFor(
|
|
3329
|
+
(config ?? {}).surface ?? "form"
|
|
3330
|
+
);
|
|
2818
3331
|
return /* @__PURE__ */ jsxs("div", { style: { marginBottom: "1rem" }, children: [
|
|
2819
|
-
label && /* @__PURE__ */ jsxs(
|
|
2820
|
-
|
|
2821
|
-
{
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
color: "#475569",
|
|
2825
|
-
fontSize: "0.875rem",
|
|
2826
|
-
fontWeight: 500,
|
|
2827
|
-
marginBottom: "0.375rem"
|
|
2828
|
-
},
|
|
2829
|
-
children: [
|
|
2830
|
-
label,
|
|
2831
|
-
required && /* @__PURE__ */ jsx("span", { style: { color: "#ef4444", marginLeft: "0.25rem" }, children: "*" })
|
|
2832
|
-
]
|
|
2833
|
-
}
|
|
2834
|
-
),
|
|
2835
|
-
description && /* @__PURE__ */ jsx(
|
|
2836
|
-
"div",
|
|
2837
|
-
{
|
|
2838
|
-
style: {
|
|
2839
|
-
color: "#6b7280",
|
|
2840
|
-
fontSize: "0.75rem",
|
|
2841
|
-
marginBottom: "0.5rem"
|
|
2842
|
-
},
|
|
2843
|
-
children: description
|
|
2844
|
-
}
|
|
2845
|
-
),
|
|
3332
|
+
label && /* @__PURE__ */ jsxs("label", { className: fieldLabelClass(scale), children: [
|
|
3333
|
+
label,
|
|
3334
|
+
required && /* @__PURE__ */ jsx("span", { className: "ml-1 text-destructive", children: "*" })
|
|
3335
|
+
] }),
|
|
3336
|
+
description && /* @__PURE__ */ jsx("div", { className: fieldHintClass, children: description }),
|
|
2846
3337
|
/* @__PURE__ */ jsx(
|
|
2847
3338
|
"div",
|
|
2848
3339
|
{
|
|
2849
|
-
|
|
2850
|
-
border: errors || displayedParseError ? "1px solid #ef4444" : "1px solid #d1d5db",
|
|
2851
|
-
borderRadius: "6px",
|
|
2852
|
-
overflow: "hidden",
|
|
2853
|
-
opacity: isDisabled ? 0.6 : 1
|
|
2854
|
-
},
|
|
3340
|
+
className: `overflow-hidden rounded-md border ${errors || displayedParseError ? "border-destructive" : "border-input"} ${isDisabled ? "opacity-60" : ""}`,
|
|
2855
3341
|
children: /* @__PURE__ */ jsx(
|
|
2856
3342
|
AceEditor,
|
|
2857
3343
|
{
|
|
@@ -2884,28 +3370,8 @@ var JsonEditorRenderer = ({
|
|
|
2884
3370
|
)
|
|
2885
3371
|
}
|
|
2886
3372
|
),
|
|
2887
|
-
displayedParseError && /* @__PURE__ */ jsx(
|
|
2888
|
-
|
|
2889
|
-
{
|
|
2890
|
-
style: {
|
|
2891
|
-
color: "#ef4444",
|
|
2892
|
-
fontSize: "0.75rem",
|
|
2893
|
-
marginTop: "0.25rem"
|
|
2894
|
-
},
|
|
2895
|
-
children: displayedParseError
|
|
2896
|
-
}
|
|
2897
|
-
),
|
|
2898
|
-
errors && /* @__PURE__ */ jsx(
|
|
2899
|
-
"div",
|
|
2900
|
-
{
|
|
2901
|
-
style: {
|
|
2902
|
-
color: "#ef4444",
|
|
2903
|
-
fontSize: "0.75rem",
|
|
2904
|
-
marginTop: "0.25rem"
|
|
2905
|
-
},
|
|
2906
|
-
children: errors
|
|
2907
|
-
}
|
|
2908
|
-
)
|
|
3373
|
+
displayedParseError && /* @__PURE__ */ jsx("div", { className: fieldErrorClass, children: displayedParseError }),
|
|
3374
|
+
errors && /* @__PURE__ */ jsx("div", { className: fieldErrorClass, children: errors })
|
|
2909
3375
|
] });
|
|
2910
3376
|
};
|
|
2911
3377
|
var jsonEditorTester = rankWith(
|
|
@@ -2996,14 +3462,31 @@ var ModelIdRenderer = ({
|
|
|
2996
3462
|
description,
|
|
2997
3463
|
errors,
|
|
2998
3464
|
uischema,
|
|
2999
|
-
visible
|
|
3465
|
+
visible,
|
|
3466
|
+
config
|
|
3000
3467
|
}) => {
|
|
3001
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
3002
3468
|
const [searchValue, setSearchValue] = useState("");
|
|
3003
3469
|
const [debouncedSearchValue, setDebouncedSearchValue] = useState("");
|
|
3004
|
-
const
|
|
3470
|
+
const triggerRef = useRef(null);
|
|
3005
3471
|
const menuRef = useRef(null);
|
|
3006
3472
|
const searchRef = useRef(null);
|
|
3473
|
+
const surface = (config ?? {}).surface ?? "bar";
|
|
3474
|
+
const scale = scaleFor(surface);
|
|
3475
|
+
const isBar = surface === "bar";
|
|
3476
|
+
const {
|
|
3477
|
+
isOpen,
|
|
3478
|
+
close: closeMenu,
|
|
3479
|
+
toggle,
|
|
3480
|
+
renderPopover
|
|
3481
|
+
} = useAnchoredPopover({
|
|
3482
|
+
trigger: triggerRef,
|
|
3483
|
+
popover: menuRef,
|
|
3484
|
+
// Wide enough for a provider glyph, a model name and its id underneath.
|
|
3485
|
+
width: POPOVER_WIDTH_PX,
|
|
3486
|
+
maxHeight: POPOVER_MAX_HEIGHT_PX,
|
|
3487
|
+
role: "listbox",
|
|
3488
|
+
label: "Models"
|
|
3489
|
+
});
|
|
3007
3490
|
const debounceTimerRef = useRef(
|
|
3008
3491
|
void 0
|
|
3009
3492
|
);
|
|
@@ -3042,35 +3525,13 @@ var ModelIdRenderer = ({
|
|
|
3042
3525
|
handleChange(path2, model.id);
|
|
3043
3526
|
setSearchValue("");
|
|
3044
3527
|
setDebouncedSearchValue("");
|
|
3045
|
-
|
|
3528
|
+
closeMenu();
|
|
3046
3529
|
},
|
|
3047
|
-
[handleChange, path2]
|
|
3530
|
+
[handleChange, path2, closeMenu]
|
|
3048
3531
|
);
|
|
3049
|
-
const close = useCallback(() => {
|
|
3050
|
-
setIsOpen(false);
|
|
3051
|
-
setSearchValue("");
|
|
3052
|
-
}, []);
|
|
3053
3532
|
useEffect(() => {
|
|
3054
|
-
if (!isOpen)
|
|
3055
|
-
|
|
3056
|
-
const target = event.target;
|
|
3057
|
-
if (containerRef.current && !containerRef.current.contains(target) && !(menuRef.current && menuRef.current.contains(target))) {
|
|
3058
|
-
close();
|
|
3059
|
-
}
|
|
3060
|
-
};
|
|
3061
|
-
const onKeyDown = (event) => {
|
|
3062
|
-
if (event.key === "Escape") close();
|
|
3063
|
-
};
|
|
3064
|
-
const onResize = () => close();
|
|
3065
|
-
document.addEventListener("mousedown", onPointerDown);
|
|
3066
|
-
document.addEventListener("keydown", onKeyDown);
|
|
3067
|
-
window.addEventListener("resize", onResize);
|
|
3068
|
-
return () => {
|
|
3069
|
-
document.removeEventListener("mousedown", onPointerDown);
|
|
3070
|
-
document.removeEventListener("keydown", onKeyDown);
|
|
3071
|
-
window.removeEventListener("resize", onResize);
|
|
3072
|
-
};
|
|
3073
|
-
}, [isOpen, close]);
|
|
3533
|
+
if (!isOpen) setSearchValue("");
|
|
3534
|
+
}, [isOpen]);
|
|
3074
3535
|
useEffect(() => {
|
|
3075
3536
|
if (isOpen) searchRef.current?.focus();
|
|
3076
3537
|
}, [isOpen]);
|
|
@@ -3079,53 +3540,58 @@ var ModelIdRenderer = ({
|
|
|
3079
3540
|
const isDisabled = !enabled || readOnly;
|
|
3080
3541
|
const hasError = !!errors && errors.length > 0;
|
|
3081
3542
|
const selectedName = selectedModel ? selectedModel.displayName || selectedModel.name || "" : "";
|
|
3082
|
-
const triggerText = selectedName ||
|
|
3543
|
+
const triggerText = selectedName || "Select model";
|
|
3083
3544
|
const iconSrc = getModelIcon(selectedModel);
|
|
3084
3545
|
const tooltip = [selectedName || label, description, hasError ? errors : null].filter(Boolean).join(" \u2014 ");
|
|
3085
|
-
const
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3546
|
+
const triggerLabel = !label || label === "ModelId" ? "Model" : label;
|
|
3547
|
+
const trigger = /* @__PURE__ */ jsxs(
|
|
3548
|
+
"button",
|
|
3549
|
+
{
|
|
3550
|
+
ref: triggerRef,
|
|
3551
|
+
id: `${path2}-trigger`,
|
|
3552
|
+
type: "button",
|
|
3553
|
+
onClick: toggle,
|
|
3554
|
+
disabled: isDisabled,
|
|
3555
|
+
"aria-expanded": isOpen,
|
|
3556
|
+
"aria-haspopup": "listbox",
|
|
3557
|
+
"aria-label": triggerLabel,
|
|
3558
|
+
title: tooltip || void 0,
|
|
3559
|
+
className: isBar ? pillClass({ active: isOpen, hasError, disabled: isDisabled }) : fieldTriggerClass(scale, hasError),
|
|
3560
|
+
children: [
|
|
3561
|
+
iconSrc ? /* @__PURE__ */ jsx(
|
|
3562
|
+
"img",
|
|
3563
|
+
{
|
|
3564
|
+
src: iconSrc,
|
|
3565
|
+
alt: "",
|
|
3566
|
+
className: "h-3.5 w-3.5 shrink-0 object-contain"
|
|
3567
|
+
}
|
|
3568
|
+
) : /* @__PURE__ */ jsx(Cpu, { className: "h-3.5 w-3.5 shrink-0" }),
|
|
3569
|
+
/* @__PURE__ */ jsx(
|
|
3570
|
+
"span",
|
|
3571
|
+
{
|
|
3572
|
+
className: isBar ? `inline ${pillValueClass} max-sm:hidden` : "min-w-0 flex-1 truncate",
|
|
3573
|
+
children: triggerText
|
|
3574
|
+
}
|
|
3575
|
+
),
|
|
3576
|
+
/* @__PURE__ */ jsx(
|
|
3577
|
+
ChevronDown,
|
|
3578
|
+
{
|
|
3579
|
+
className: `shrink-0 opacity-60 ${isBar ? "h-3 w-3" : "h-4 w-4"}`
|
|
3580
|
+
}
|
|
3581
|
+
)
|
|
3582
|
+
]
|
|
3583
|
+
}
|
|
3584
|
+
);
|
|
3585
|
+
return /* @__PURE__ */ jsxs(
|
|
3586
|
+
"div",
|
|
3587
|
+
{
|
|
3588
|
+
className: isBar ? "ss-jsonforms-field ss-jsonforms-model relative shrink-0" : "ss-jsonforms-field ss-jsonforms-model compact-field",
|
|
3589
|
+
children: [
|
|
3590
|
+
!isBar && /* @__PURE__ */ jsx("label", { htmlFor: `${path2}-trigger`, className: fieldLabelClass(scale), children: triggerLabel }),
|
|
3591
|
+
trigger,
|
|
3592
|
+
renderPopover(
|
|
3593
|
+
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3594
|
+
/* @__PURE__ */ jsx("div", { className: "shrink-0 border-b border-border p-2", children: /* @__PURE__ */ jsx(
|
|
3129
3595
|
"input",
|
|
3130
3596
|
{
|
|
3131
3597
|
ref: searchRef,
|
|
@@ -3137,7 +3603,7 @@ var ModelIdRenderer = ({
|
|
|
3137
3603
|
className: "h-8 w-full rounded-md border border-border bg-background px-2 text-xs text-foreground outline-none placeholder:text-muted-foreground focus:border-primary/40"
|
|
3138
3604
|
}
|
|
3139
3605
|
) }),
|
|
3140
|
-
/* @__PURE__ */ jsxs("div", { className: "
|
|
3606
|
+
/* @__PURE__ */ jsxs("div", { className: "min-h-0 overflow-y-auto", children: [
|
|
3141
3607
|
isLoading && listModels.length === 0 && /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center py-6", children: /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin text-primary" }) }),
|
|
3142
3608
|
!isLoading && listModels.length === 0 && /* @__PURE__ */ jsx("p", { className: "px-3 py-6 text-center text-xs text-muted-foreground", children: searchValue ? "No models found" : "No models available" }),
|
|
3143
3609
|
listModels.map((model) => {
|
|
@@ -3150,7 +3616,7 @@ var ModelIdRenderer = ({
|
|
|
3150
3616
|
role: "option",
|
|
3151
3617
|
"aria-selected": active,
|
|
3152
3618
|
onClick: () => handleSelect(model),
|
|
3153
|
-
className:
|
|
3619
|
+
className: popoverRowClass,
|
|
3154
3620
|
children: [
|
|
3155
3621
|
/* @__PURE__ */ jsx(
|
|
3156
3622
|
Check,
|
|
@@ -3176,12 +3642,11 @@ var ModelIdRenderer = ({
|
|
|
3176
3642
|
);
|
|
3177
3643
|
})
|
|
3178
3644
|
] })
|
|
3179
|
-
]
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
] });
|
|
3645
|
+
] })
|
|
3646
|
+
)
|
|
3647
|
+
]
|
|
3648
|
+
}
|
|
3649
|
+
);
|
|
3185
3650
|
};
|
|
3186
3651
|
var modelIdRendererTester = rankWith(
|
|
3187
3652
|
100,
|
|
@@ -3216,6 +3681,7 @@ var NumberRenderer = ({
|
|
|
3216
3681
|
uischema,
|
|
3217
3682
|
visible,
|
|
3218
3683
|
enabled,
|
|
3684
|
+
config,
|
|
3219
3685
|
required
|
|
3220
3686
|
}) => {
|
|
3221
3687
|
const isInteger = schema?.type === "integer";
|
|
@@ -3244,40 +3710,58 @@ var NumberRenderer = ({
|
|
|
3244
3710
|
const max = fieldSchema?.maximum;
|
|
3245
3711
|
const step = isInteger ? 1 : fieldSchema?.multipleOf ?? "any";
|
|
3246
3712
|
const tooltip = [label, description, hasError ? errors : null].filter(Boolean).join(" \u2014 ");
|
|
3247
|
-
|
|
3248
|
-
|
|
3713
|
+
const surface = (config ?? {}).surface ?? "form";
|
|
3714
|
+
const scale = scaleFor(surface);
|
|
3715
|
+
const input = /* @__PURE__ */ jsx(
|
|
3716
|
+
"input",
|
|
3249
3717
|
{
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
label,
|
|
3260
|
-
required && /* @__PURE__ */ jsx("span", { className: "ml-1 text-destructive", children: "*" })
|
|
3261
|
-
]
|
|
3262
|
-
}
|
|
3263
|
-
),
|
|
3264
|
-
/* @__PURE__ */ jsx(
|
|
3265
|
-
"input",
|
|
3266
|
-
{
|
|
3267
|
-
id: `number-${path2}`,
|
|
3268
|
-
type: "number",
|
|
3269
|
-
value: data ?? "",
|
|
3270
|
-
onChange: handleInputChange,
|
|
3271
|
-
disabled: isDisabled,
|
|
3272
|
-
min,
|
|
3273
|
-
max,
|
|
3274
|
-
step,
|
|
3275
|
-
className: "w-14 border-0 bg-transparent p-0 text-xs font-medium tabular-nums text-foreground outline-none disabled:cursor-not-allowed"
|
|
3276
|
-
}
|
|
3277
|
-
)
|
|
3278
|
-
]
|
|
3718
|
+
id: `number-${path2}`,
|
|
3719
|
+
type: "number",
|
|
3720
|
+
value: data ?? "",
|
|
3721
|
+
onChange: handleInputChange,
|
|
3722
|
+
disabled: isDisabled,
|
|
3723
|
+
min,
|
|
3724
|
+
max,
|
|
3725
|
+
step,
|
|
3726
|
+
className: surface === "bar" ? "w-14 border-0 bg-transparent p-0 text-xs font-medium tabular-nums text-foreground outline-none disabled:cursor-not-allowed" : fieldNumberClass(scale, hasError)
|
|
3279
3727
|
}
|
|
3280
3728
|
);
|
|
3729
|
+
if (surface === "bar") {
|
|
3730
|
+
return /* @__PURE__ */ jsxs(
|
|
3731
|
+
"div",
|
|
3732
|
+
{
|
|
3733
|
+
className: `ss-jsonforms-field ss-jsonforms-number ${pillClass({
|
|
3734
|
+
hasError,
|
|
3735
|
+
disabled: isDisabled
|
|
3736
|
+
})}`,
|
|
3737
|
+
title: tooltip || void 0,
|
|
3738
|
+
children: [
|
|
3739
|
+
label && /* @__PURE__ */ jsxs(
|
|
3740
|
+
"label",
|
|
3741
|
+
{
|
|
3742
|
+
htmlFor: `number-${path2}`,
|
|
3743
|
+
className: `${pillLabelClass} whitespace-nowrap ${hasError ? "text-destructive" : "text-muted-foreground"}`,
|
|
3744
|
+
children: [
|
|
3745
|
+
label,
|
|
3746
|
+
required && /* @__PURE__ */ jsx("span", { className: "ml-1 text-destructive", children: "*" })
|
|
3747
|
+
]
|
|
3748
|
+
}
|
|
3749
|
+
),
|
|
3750
|
+
input
|
|
3751
|
+
]
|
|
3752
|
+
}
|
|
3753
|
+
);
|
|
3754
|
+
}
|
|
3755
|
+
return /* @__PURE__ */ jsxs("div", { className: "ss-jsonforms-field ss-jsonforms-number", children: [
|
|
3756
|
+
/* @__PURE__ */ jsxs("div", { className: fieldRowClass, children: [
|
|
3757
|
+
/* @__PURE__ */ jsxs("label", { htmlFor: `number-${path2}`, className: fieldRowLabelClass(scale), children: [
|
|
3758
|
+
label,
|
|
3759
|
+
required && /* @__PURE__ */ jsx("span", { className: "ml-1 text-destructive", children: "*" })
|
|
3760
|
+
] }),
|
|
3761
|
+
input
|
|
3762
|
+
] }),
|
|
3763
|
+
hasError && /* @__PURE__ */ jsx("div", { className: fieldErrorClass, children: errors })
|
|
3764
|
+
] });
|
|
3281
3765
|
};
|
|
3282
3766
|
var numberRendererTester = rankWith(
|
|
3283
3767
|
40,
|
|
@@ -3293,6 +3777,14 @@ var numberRendererTester = rankWith(
|
|
|
3293
3777
|
}
|
|
3294
3778
|
);
|
|
3295
3779
|
var NumberRendererControl = withJsonFormsControlProps(NumberRenderer);
|
|
3780
|
+
var SCALE = {
|
|
3781
|
+
comfortable: { lineHeight: 20, padding: 8 },
|
|
3782
|
+
dense: { lineHeight: 16, padding: 6 }
|
|
3783
|
+
};
|
|
3784
|
+
var rowsToPx = (rows, scale) => rows * scale.lineHeight + scale.padding * 2 + 2;
|
|
3785
|
+
var MAX_VIEWPORT_SHARE = 0.5;
|
|
3786
|
+
var DEFAULT_MIN_ROWS = 3;
|
|
3787
|
+
var DEFAULT_MAX_ROWS = 9;
|
|
3296
3788
|
var TextareaRenderer = ({
|
|
3297
3789
|
data,
|
|
3298
3790
|
handleChange,
|
|
@@ -3304,28 +3796,49 @@ var TextareaRenderer = ({
|
|
|
3304
3796
|
uischema,
|
|
3305
3797
|
visible,
|
|
3306
3798
|
enabled,
|
|
3307
|
-
required
|
|
3799
|
+
required,
|
|
3800
|
+
config
|
|
3308
3801
|
}) => {
|
|
3309
3802
|
const textareaRef = useRef(null);
|
|
3803
|
+
const textareaOptions = schema["ui:textarea"] ?? {};
|
|
3804
|
+
const formConfig = config ?? {};
|
|
3805
|
+
const scaleName = scaleFor(formConfig.surface ?? "form");
|
|
3806
|
+
const scale = SCALE[scaleName];
|
|
3807
|
+
const minRows = textareaOptions.minRows ?? formConfig.minRows ?? DEFAULT_MIN_ROWS;
|
|
3808
|
+
const maxRows = Math.max(
|
|
3809
|
+
minRows,
|
|
3810
|
+
textareaOptions.maxRows ?? formConfig.maxRows ?? DEFAULT_MAX_ROWS
|
|
3811
|
+
);
|
|
3812
|
+
const minHeight = rowsToPx(minRows, scale);
|
|
3813
|
+
const maxHeight = rowsToPx(maxRows, scale);
|
|
3814
|
+
const [viewportCap, setViewportCap] = useState(
|
|
3815
|
+
() => typeof window === "undefined" ? Number.POSITIVE_INFINITY : Math.round(window.innerHeight * MAX_VIEWPORT_SHARE)
|
|
3816
|
+
);
|
|
3817
|
+
const ceiling = Math.max(minHeight, Math.min(maxHeight, viewportCap));
|
|
3310
3818
|
const autoResize = useCallback(() => {
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
}
|
|
3320
|
-
}, []);
|
|
3819
|
+
const el = textareaRef.current;
|
|
3820
|
+
if (!el) return;
|
|
3821
|
+
el.style.height = "auto";
|
|
3822
|
+
el.style.height = `${Math.min(
|
|
3823
|
+
Math.max(el.scrollHeight, minHeight),
|
|
3824
|
+
ceiling
|
|
3825
|
+
)}px`;
|
|
3826
|
+
}, [minHeight, ceiling]);
|
|
3321
3827
|
useEffect(() => {
|
|
3322
3828
|
autoResize();
|
|
3323
3829
|
}, [data, autoResize]);
|
|
3830
|
+
useEffect(() => {
|
|
3831
|
+
const onResize = () => {
|
|
3832
|
+
setViewportCap(Math.round(window.innerHeight * MAX_VIEWPORT_SHARE));
|
|
3833
|
+
autoResize();
|
|
3834
|
+
};
|
|
3835
|
+
window.addEventListener("resize", onResize);
|
|
3836
|
+
return () => window.removeEventListener("resize", onResize);
|
|
3837
|
+
}, [autoResize]);
|
|
3324
3838
|
const handleInputChange = useCallback(
|
|
3325
3839
|
(event) => {
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
setTimeout(autoResize, 0);
|
|
3840
|
+
handleChange(path2, event.target.value);
|
|
3841
|
+
autoResize();
|
|
3329
3842
|
},
|
|
3330
3843
|
[handleChange, path2, autoResize]
|
|
3331
3844
|
);
|
|
@@ -3335,89 +3848,34 @@ var TextareaRenderer = ({
|
|
|
3335
3848
|
const readOnly = uischema?.access === "Read";
|
|
3336
3849
|
const isDisabled = !enabled || readOnly;
|
|
3337
3850
|
const hasError = errors && errors.length > 0;
|
|
3338
|
-
const textareaOptions = schema["ui:textarea"] ?? {};
|
|
3339
3851
|
const placeholder = textareaOptions.placeholder || schema?.description || `Enter ${label?.toLowerCase() || "text"}...`;
|
|
3340
|
-
const minRows = textareaOptions.minRows || 3;
|
|
3341
3852
|
return /* @__PURE__ */ jsxs("div", { className: "ss-jsonforms-field ss-jsonforms-textarea", children: [
|
|
3342
|
-
label && /* @__PURE__ */ jsxs(
|
|
3343
|
-
|
|
3344
|
-
{
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
color: hasError ? "#ef4444" : "#475569",
|
|
3348
|
-
fontSize: "0.875rem",
|
|
3349
|
-
fontWeight: 500,
|
|
3350
|
-
marginBottom: "0.375rem"
|
|
3351
|
-
},
|
|
3352
|
-
children: [
|
|
3353
|
-
label,
|
|
3354
|
-
required && /* @__PURE__ */ jsx("span", { style: { color: "#ef4444", marginLeft: "0.25rem" }, children: "*" })
|
|
3355
|
-
]
|
|
3356
|
-
}
|
|
3357
|
-
),
|
|
3358
|
-
description && /* @__PURE__ */ jsx(
|
|
3359
|
-
"div",
|
|
3360
|
-
{
|
|
3361
|
-
style: {
|
|
3362
|
-
color: "#6b7280",
|
|
3363
|
-
fontSize: "0.75rem",
|
|
3364
|
-
marginBottom: "0.5rem"
|
|
3365
|
-
},
|
|
3366
|
-
children: description
|
|
3367
|
-
}
|
|
3368
|
-
),
|
|
3853
|
+
label && /* @__PURE__ */ jsxs("label", { htmlFor: path2, className: fieldLabelClass(scaleName), children: [
|
|
3854
|
+
label,
|
|
3855
|
+
required && /* @__PURE__ */ jsx("span", { className: "ml-1 text-destructive", children: "*" })
|
|
3856
|
+
] }),
|
|
3857
|
+
description && /* @__PURE__ */ jsx("div", { className: fieldHintClass, children: description }),
|
|
3369
3858
|
/* @__PURE__ */ jsx(
|
|
3370
3859
|
"textarea",
|
|
3371
3860
|
{
|
|
3861
|
+
id: path2,
|
|
3372
3862
|
ref: textareaRef,
|
|
3373
3863
|
value: data || "",
|
|
3374
3864
|
onChange: handleInputChange,
|
|
3375
3865
|
placeholder,
|
|
3376
3866
|
disabled: isDisabled,
|
|
3377
3867
|
rows: minRows,
|
|
3868
|
+
className: `resize-y ${fieldControlClass(scaleName, !!hasError)}`,
|
|
3378
3869
|
style: {
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
padding: "0.75rem",
|
|
3384
|
-
border: hasError ? "2px solid #ef4444" : "1px solid #d1d5db",
|
|
3385
|
-
borderRadius: "6px",
|
|
3386
|
-
fontSize: "16px",
|
|
3387
|
-
lineHeight: "1.5",
|
|
3388
|
-
fontFamily: "inherit",
|
|
3389
|
-
backgroundColor: isDisabled ? "#f9fafb" : "#ffffff",
|
|
3390
|
-
color: isDisabled ? "#9ca3af" : "#111827",
|
|
3391
|
-
outline: "none",
|
|
3392
|
-
transition: "border-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out",
|
|
3393
|
-
boxShadow: hasError ? "0 0 0 1px #ef4444" : "none",
|
|
3870
|
+
minHeight: `${minHeight}px`,
|
|
3871
|
+
maxHeight: `${ceiling}px`,
|
|
3872
|
+
// iOS zooms a focused control under 16px; the design's fields are
|
|
3873
|
+
// 14px, so opt out of the adjustment rather than the design.
|
|
3394
3874
|
WebkitTextSizeAdjust: "100%"
|
|
3395
|
-
},
|
|
3396
|
-
onFocus: (e) => {
|
|
3397
|
-
if (!hasError) {
|
|
3398
|
-
e.target.style.borderColor = "#6366f1";
|
|
3399
|
-
e.target.style.boxShadow = "0 0 0 1px #6366f1";
|
|
3400
|
-
}
|
|
3401
|
-
},
|
|
3402
|
-
onBlur: (e) => {
|
|
3403
|
-
if (!hasError) {
|
|
3404
|
-
e.target.style.borderColor = "#d1d5db";
|
|
3405
|
-
e.target.style.boxShadow = "none";
|
|
3406
|
-
}
|
|
3407
3875
|
}
|
|
3408
3876
|
}
|
|
3409
3877
|
),
|
|
3410
|
-
hasError && /* @__PURE__ */ jsx(
|
|
3411
|
-
"div",
|
|
3412
|
-
{
|
|
3413
|
-
style: {
|
|
3414
|
-
color: "#ef4444",
|
|
3415
|
-
fontSize: "0.75rem",
|
|
3416
|
-
marginTop: "0.25rem"
|
|
3417
|
-
},
|
|
3418
|
-
children: errors
|
|
3419
|
-
}
|
|
3420
|
-
)
|
|
3878
|
+
hasError && /* @__PURE__ */ jsx("div", { className: fieldErrorClass, children: errors })
|
|
3421
3879
|
] });
|
|
3422
3880
|
};
|
|
3423
3881
|
var textareaRendererTester = rankWith(
|
|
@@ -3469,14 +3927,31 @@ var renderers = [
|
|
|
3469
3927
|
];
|
|
3470
3928
|
|
|
3471
3929
|
// src/chat-variables/VariablesForm.vm.ts
|
|
3930
|
+
var MAX_INLINE_VARIABLES = 3;
|
|
3931
|
+
var isModelSelector = (schema) => schema.title === "ModelId" || schema["x-model-selector"] === true;
|
|
3932
|
+
function rowLayout(controls) {
|
|
3933
|
+
const innerRow = {
|
|
3934
|
+
type: "HorizontalLayout",
|
|
3935
|
+
elements: controls,
|
|
3936
|
+
options: { gap: "12px", alignItems: "flex-start" }
|
|
3937
|
+
};
|
|
3938
|
+
const ui = {
|
|
3939
|
+
type: "VerticalLayout",
|
|
3940
|
+
elements: [innerRow]
|
|
3941
|
+
};
|
|
3942
|
+
return ui;
|
|
3943
|
+
}
|
|
3472
3944
|
function buildSimpleSchemaAndUi(vars, threadVars, useDefaults) {
|
|
3473
3945
|
const names = Object.keys(vars || {});
|
|
3474
3946
|
const properties2 = {};
|
|
3475
3947
|
const controls = [];
|
|
3948
|
+
const inlineOnly = [];
|
|
3476
3949
|
const initialData = {};
|
|
3950
|
+
const $defs = {};
|
|
3477
3951
|
for (const name of names) {
|
|
3478
3952
|
const cfg = vars?.[name] || {};
|
|
3479
|
-
const s2 = cfg.schema || {};
|
|
3953
|
+
const { $defs: varDefs, ...s2 } = cfg.schema || {};
|
|
3954
|
+
if (varDefs) Object.assign($defs, varDefs);
|
|
3480
3955
|
properties2[name] = s2;
|
|
3481
3956
|
const hasServerKey = threadVars !== void 0 && Object.prototype.hasOwnProperty.call(threadVars, name);
|
|
3482
3957
|
const val = hasServerKey ? threadVars?.[name] : useDefaults ? s2.default : void 0;
|
|
@@ -3490,18 +3965,24 @@ function buildSimpleSchemaAndUi(vars, threadVars, useDefaults) {
|
|
|
3490
3965
|
control.enabled = false;
|
|
3491
3966
|
}
|
|
3492
3967
|
controls.push(control);
|
|
3968
|
+
if (isModelSelector(properties2[name])) inlineOnly.push(control);
|
|
3493
3969
|
}
|
|
3494
3970
|
const schema = { type: "object", properties: properties2 };
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3971
|
+
if (Object.keys($defs).length > 0) schema.$defs = $defs;
|
|
3972
|
+
if (controls.length <= MAX_INLINE_VARIABLES) {
|
|
3973
|
+
return {
|
|
3974
|
+
schema,
|
|
3975
|
+
inlineControls: controls,
|
|
3976
|
+
overflowControls: [],
|
|
3977
|
+
initialData
|
|
3978
|
+
};
|
|
3979
|
+
}
|
|
3980
|
+
return {
|
|
3981
|
+
schema,
|
|
3982
|
+
inlineControls: inlineOnly,
|
|
3983
|
+
overflowControls: controls.filter((c) => !inlineOnly.includes(c)),
|
|
3984
|
+
initialData
|
|
3503
3985
|
};
|
|
3504
|
-
return { schema, uiSchema: ui, initialData };
|
|
3505
3986
|
}
|
|
3506
3987
|
function useChatVariablesFormVm({
|
|
3507
3988
|
workspace,
|
|
@@ -3516,26 +3997,26 @@ function useChatVariablesFormVm({
|
|
|
3516
3997
|
const { mutate: updateVariableMutation } = useUpdateFlowRunVariable();
|
|
3517
3998
|
const querySettled = !isLoading && (threadVars !== void 0 || isError);
|
|
3518
3999
|
const shouldUseDefaults = isError || threadVars && Object.keys(threadVars).length === 0;
|
|
3519
|
-
const built =
|
|
4000
|
+
const built = React9.useMemo(() => {
|
|
3520
4001
|
return buildSimpleSchemaAndUi(
|
|
3521
4002
|
workspace.variables,
|
|
3522
4003
|
threadVars,
|
|
3523
4004
|
shouldUseDefaults ?? false
|
|
3524
4005
|
);
|
|
3525
4006
|
}, [workspace.variables, threadVars, shouldUseDefaults]);
|
|
3526
|
-
const [data, setData] =
|
|
3527
|
-
|
|
4007
|
+
const [data, setData] = React9.useState(null);
|
|
4008
|
+
React9.useEffect(() => {
|
|
3528
4009
|
if (querySettled) {
|
|
3529
4010
|
setData(built.initialData);
|
|
3530
4011
|
setVariables(built.initialData);
|
|
3531
4012
|
}
|
|
3532
4013
|
}, [querySettled, built.initialData, setVariables]);
|
|
3533
|
-
const ajv =
|
|
3534
|
-
const prevRef =
|
|
3535
|
-
|
|
4014
|
+
const ajv = React9.useMemo(() => createAjv({ useDefaults: false }), []);
|
|
4015
|
+
const prevRef = React9.useRef(null);
|
|
4016
|
+
React9.useEffect(() => {
|
|
3536
4017
|
prevRef.current = data;
|
|
3537
4018
|
}, [data]);
|
|
3538
|
-
const onChange =
|
|
4019
|
+
const onChange = React9.useCallback(
|
|
3539
4020
|
({ data: next2 }) => {
|
|
3540
4021
|
if (prevRef.current && !isDraftThreadId(threadId)) {
|
|
3541
4022
|
const keys2 = Object.keys(workspace.variables || {});
|
|
@@ -3556,29 +4037,96 @@ function useChatVariablesFormVm({
|
|
|
3556
4037
|
},
|
|
3557
4038
|
[workspace.variables, setVariables, updateVariableMutation, threadId]
|
|
3558
4039
|
);
|
|
3559
|
-
const
|
|
4040
|
+
const barConfig = React9.useMemo(
|
|
3560
4041
|
() => ({
|
|
3561
4042
|
restrict: true,
|
|
3562
4043
|
trim: false,
|
|
3563
4044
|
showUnfocusedDescription: true,
|
|
3564
|
-
hideRequiredAsterisk: true
|
|
4045
|
+
hideRequiredAsterisk: true,
|
|
4046
|
+
surface: "bar",
|
|
4047
|
+
minRows: 1,
|
|
4048
|
+
maxRows: 6
|
|
3565
4049
|
}),
|
|
3566
4050
|
[]
|
|
3567
4051
|
);
|
|
4052
|
+
const panelConfig = React9.useMemo(
|
|
4053
|
+
() => ({ ...barConfig, surface: "panel" }),
|
|
4054
|
+
[barConfig]
|
|
4055
|
+
);
|
|
4056
|
+
const inlineUiSchema = React9.useMemo(
|
|
4057
|
+
() => built.inlineControls.length ? rowLayout(built.inlineControls) : null,
|
|
4058
|
+
[built.inlineControls]
|
|
4059
|
+
);
|
|
4060
|
+
const overflowUiSchema = React9.useMemo(
|
|
4061
|
+
() => built.overflowControls.length ? rowLayout(built.overflowControls) : null,
|
|
4062
|
+
[built.overflowControls]
|
|
4063
|
+
);
|
|
3568
4064
|
return {
|
|
3569
4065
|
schema: built.schema,
|
|
3570
|
-
|
|
4066
|
+
inlineUiSchema,
|
|
4067
|
+
overflowUiSchema,
|
|
4068
|
+
overflowCount: built.overflowControls.length,
|
|
3571
4069
|
data,
|
|
3572
4070
|
renderers,
|
|
3573
4071
|
cells,
|
|
3574
4072
|
ajv,
|
|
3575
4073
|
onChange,
|
|
3576
|
-
|
|
4074
|
+
barConfig,
|
|
4075
|
+
panelConfig,
|
|
3577
4076
|
isLoading,
|
|
3578
4077
|
isReady: querySettled,
|
|
3579
4078
|
isHydrated: data !== null
|
|
3580
4079
|
};
|
|
3581
4080
|
}
|
|
4081
|
+
function VariablesOverflowPanel({ count, children: children2 }) {
|
|
4082
|
+
const triggerRef = useRef(null);
|
|
4083
|
+
const panelRef = useRef(null);
|
|
4084
|
+
const { isOpen, close, toggle, renderPopover } = useAnchoredPopover({
|
|
4085
|
+
trigger: triggerRef,
|
|
4086
|
+
popover: panelRef,
|
|
4087
|
+
width: POPOVER_WIDTH_PX,
|
|
4088
|
+
maxHeight: POPOVER_MAX_HEIGHT_PX,
|
|
4089
|
+
role: "dialog",
|
|
4090
|
+
label: "Workspace variables"
|
|
4091
|
+
});
|
|
4092
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4093
|
+
/* @__PURE__ */ jsxs(
|
|
4094
|
+
"button",
|
|
4095
|
+
{
|
|
4096
|
+
ref: triggerRef,
|
|
4097
|
+
type: "button",
|
|
4098
|
+
onClick: toggle,
|
|
4099
|
+
"aria-expanded": isOpen,
|
|
4100
|
+
"aria-haspopup": "dialog",
|
|
4101
|
+
"aria-label": `Variables (${count})`,
|
|
4102
|
+
className: `flex h-8 shrink-0 items-center gap-1.5 rounded-full border px-2.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary ${isOpen ? "border-primary/30 bg-primary/10 text-primary" : "border-border/70 bg-transparent text-muted-foreground hover:bg-secondary"}`,
|
|
4103
|
+
children: [
|
|
4104
|
+
/* @__PURE__ */ jsx(SlidersHorizontal, { className: "h-3.5 w-3.5 shrink-0" }),
|
|
4105
|
+
/* @__PURE__ */ jsx("span", { className: "inline max-sm:hidden", children: "Variables" }),
|
|
4106
|
+
/* @__PURE__ */ jsx("span", { className: "rounded-full bg-secondary px-1.5 text-[10px] leading-4 tabular-nums", children: count })
|
|
4107
|
+
]
|
|
4108
|
+
}
|
|
4109
|
+
),
|
|
4110
|
+
renderPopover(
|
|
4111
|
+
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4112
|
+
/* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center justify-between border-b border-border px-3 py-2", children: [
|
|
4113
|
+
/* @__PURE__ */ jsx("span", { className: popoverHeadingClass, children: "Variables" }),
|
|
4114
|
+
/* @__PURE__ */ jsx(
|
|
4115
|
+
"button",
|
|
4116
|
+
{
|
|
4117
|
+
type: "button",
|
|
4118
|
+
onClick: close,
|
|
4119
|
+
"aria-label": "Close variables",
|
|
4120
|
+
className: "inline-flex h-5 w-5 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-secondary hover:text-foreground",
|
|
4121
|
+
children: /* @__PURE__ */ jsx(X, { className: "h-3.5 w-3.5" })
|
|
4122
|
+
}
|
|
4123
|
+
)
|
|
4124
|
+
] }),
|
|
4125
|
+
/* @__PURE__ */ jsx("div", { className: "ss-variables-panel min-h-0 overflow-y-auto p-3", children: children2 })
|
|
4126
|
+
] })
|
|
4127
|
+
)
|
|
4128
|
+
] });
|
|
4129
|
+
}
|
|
3582
4130
|
var ChatVariablesForm = forwardRef(({ workspace, threadId, setVariables }, ref) => {
|
|
3583
4131
|
const vm = useChatVariablesFormVm({ workspace, threadId, setVariables });
|
|
3584
4132
|
useImperativeHandle(ref, () => ({
|
|
@@ -3594,20 +4142,85 @@ var ChatVariablesForm = forwardRef(({ workspace, threadId, setVariables }, ref)
|
|
|
3594
4142
|
if (!vm.isHydrated) {
|
|
3595
4143
|
return /* @__PURE__ */ jsx("div", { className: "flex justify-center items-center w-full h-8", children: /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin text-primary" }) });
|
|
3596
4144
|
}
|
|
3597
|
-
|
|
3598
|
-
|
|
4145
|
+
const formProps = {
|
|
4146
|
+
schema: vm.schema,
|
|
4147
|
+
data: vm.data,
|
|
4148
|
+
renderers: vm.renderers,
|
|
4149
|
+
cells: vm.cells,
|
|
4150
|
+
ajv: vm.ajv,
|
|
4151
|
+
onChange: vm.onChange
|
|
4152
|
+
};
|
|
4153
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex w-full min-w-0 items-center gap-1", children: [
|
|
4154
|
+
vm.inlineUiSchema && /* @__PURE__ */ jsx("div", { className: "min-w-0 jsonforms-compact", children: /* @__PURE__ */ jsx(
|
|
4155
|
+
JsonForms,
|
|
4156
|
+
{
|
|
4157
|
+
...formProps,
|
|
4158
|
+
uischema: vm.inlineUiSchema,
|
|
4159
|
+
config: vm.barConfig
|
|
4160
|
+
}
|
|
4161
|
+
) }),
|
|
4162
|
+
vm.overflowUiSchema && /* @__PURE__ */ jsx(VariablesOverflowPanel, { count: vm.overflowCount, children: /* @__PURE__ */ jsx("div", { className: "jsonforms-compact", children: /* @__PURE__ */ jsx(
|
|
4163
|
+
JsonForms,
|
|
4164
|
+
{
|
|
4165
|
+
...formProps,
|
|
4166
|
+
uischema: vm.overflowUiSchema,
|
|
4167
|
+
config: vm.panelConfig
|
|
4168
|
+
}
|
|
4169
|
+
) }) })
|
|
4170
|
+
] });
|
|
4171
|
+
});
|
|
4172
|
+
var dictationErrorMessages = {
|
|
4173
|
+
"permission-denied": "Microphone access is blocked \u2014 allow it in your browser settings and try again",
|
|
4174
|
+
"no-microphone": "No microphone was found",
|
|
4175
|
+
network: "Could not reach the speech service \u2014 try again",
|
|
4176
|
+
"unavailable-temporarily": "Dictation is starting up \u2014 try again in a moment",
|
|
4177
|
+
unavailable: "Dictation is not available on this workspace",
|
|
4178
|
+
unknown: "Dictation stopped unexpectedly \u2014 try again"
|
|
4179
|
+
};
|
|
4180
|
+
function DictationButton({
|
|
4181
|
+
state,
|
|
4182
|
+
error,
|
|
4183
|
+
disabled,
|
|
4184
|
+
onToggle,
|
|
4185
|
+
deviceLabel,
|
|
4186
|
+
size = "sm"
|
|
4187
|
+
}) {
|
|
4188
|
+
const listening = state === "listening";
|
|
4189
|
+
const starting = state === "starting";
|
|
4190
|
+
const label = listening ? "Stop dictation" : "Dictate a message";
|
|
4191
|
+
const hint = listening && deviceLabel ? `${label} \u2014 ${deviceLabel}` : label;
|
|
4192
|
+
const dims = size === "sm" ? "h-8 w-8" : "h-9 w-9";
|
|
4193
|
+
const icon = size === "sm" ? "h-4 w-4" : "h-5 w-5";
|
|
4194
|
+
return /* @__PURE__ */ jsxs(
|
|
4195
|
+
IconButton2,
|
|
3599
4196
|
{
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
4197
|
+
type: "button",
|
|
4198
|
+
onClick: onToggle,
|
|
4199
|
+
disabled,
|
|
4200
|
+
"aria-pressed": listening,
|
|
4201
|
+
"aria-label": label,
|
|
4202
|
+
title: error ? dictationErrorMessages[error] : hint,
|
|
4203
|
+
className: `relative ${dims} rounded-full transition-colors ${listening ? "bg-destructive text-destructive-foreground hover:bg-destructive/90" : "text-muted-foreground hover:bg-secondary"}`,
|
|
4204
|
+
children: [
|
|
4205
|
+
starting && /* @__PURE__ */ jsx(
|
|
4206
|
+
"span",
|
|
4207
|
+
{
|
|
4208
|
+
"aria-hidden": "true",
|
|
4209
|
+
className: "absolute inset-0 animate-spin rounded-full border-2 border-transparent border-t-current opacity-70"
|
|
4210
|
+
}
|
|
4211
|
+
),
|
|
4212
|
+
listening && /* @__PURE__ */ jsx(
|
|
4213
|
+
"span",
|
|
4214
|
+
{
|
|
4215
|
+
"aria-hidden": "true",
|
|
4216
|
+
className: "absolute inset-0 animate-ping rounded-full bg-destructive/30"
|
|
4217
|
+
}
|
|
4218
|
+
),
|
|
4219
|
+
listening ? /* @__PURE__ */ jsx(Square, { className: `relative ${icon} fill-current` }) : /* @__PURE__ */ jsx(Mic, { className: `relative ${icon}` })
|
|
4220
|
+
]
|
|
3608
4221
|
}
|
|
3609
|
-
)
|
|
3610
|
-
}
|
|
4222
|
+
);
|
|
4223
|
+
}
|
|
3611
4224
|
|
|
3612
4225
|
// src/domains/workspaces/queryKeys.ts
|
|
3613
4226
|
var workspaceKeys = {
|
|
@@ -3626,7 +4239,10 @@ var workspaceDetailOptions = ({
|
|
|
3626
4239
|
}) => queryOptions({
|
|
3627
4240
|
queryKey: workspaceKeys.byId(workspaceId),
|
|
3628
4241
|
queryFn: () => service.fetchWorkspace(workspaceId),
|
|
3629
|
-
staleTime: 3e4
|
|
4242
|
+
staleTime: 3e4,
|
|
4243
|
+
// The route loader has just tried and failed. Retrying on mount delays
|
|
4244
|
+
// the header's error by several seconds.
|
|
4245
|
+
retryOnMount: false
|
|
3630
4246
|
});
|
|
3631
4247
|
function useWorkspace(workspaceId) {
|
|
3632
4248
|
const service = useChatService();
|
|
@@ -3674,6 +4290,8 @@ function useMessageComposerVm(props = {}) {
|
|
|
3674
4290
|
const isRunning = useThreadIsRunning(workspaceId, threadId);
|
|
3675
4291
|
const isUploadingFiles = props.isUploadingFiles ?? false;
|
|
3676
4292
|
const sendMessage = useSendMessage();
|
|
4293
|
+
const currentThreadId = useRef(threadId);
|
|
4294
|
+
currentThreadId.current = threadId;
|
|
3677
4295
|
const sendDisabled = useMemo(() => {
|
|
3678
4296
|
const nothingToSend = !newMessage.trim() && !props.hasAttachments;
|
|
3679
4297
|
const flowBlocked = isRunning || sendMessage.isPending;
|
|
@@ -3685,18 +4303,27 @@ function useMessageComposerVm(props = {}) {
|
|
|
3685
4303
|
newMessage,
|
|
3686
4304
|
props.hasAttachments
|
|
3687
4305
|
]);
|
|
3688
|
-
const internalSend = (text6, files) => {
|
|
4306
|
+
const internalSend = (text6, files, onFailed) => {
|
|
3689
4307
|
if (!workspaceId || !threadId) return;
|
|
3690
4308
|
const trimmed = text6.trim();
|
|
3691
4309
|
const contentList = trimmed ? [{ text: trimmed, image: void 0 }] : void 0;
|
|
3692
4310
|
const vars = variables && Object.keys(variables).length > 0 ? variables : void 0;
|
|
3693
|
-
sendMessage.mutate(
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
4311
|
+
sendMessage.mutate(
|
|
4312
|
+
{
|
|
4313
|
+
workspaceId,
|
|
4314
|
+
threadId,
|
|
4315
|
+
contentList,
|
|
4316
|
+
files,
|
|
4317
|
+
variables: vars
|
|
4318
|
+
},
|
|
4319
|
+
// The composer stays mounted across threads: a send that fails after
|
|
4320
|
+
// the user moved to another thread must not put its text in that one.
|
|
4321
|
+
{
|
|
4322
|
+
onError: () => {
|
|
4323
|
+
if (currentThreadId.current === threadId) onFailed?.();
|
|
4324
|
+
}
|
|
4325
|
+
}
|
|
4326
|
+
);
|
|
3700
4327
|
setNewMessage("");
|
|
3701
4328
|
};
|
|
3702
4329
|
const canSend = (text6, files) => {
|
|
@@ -3705,9 +4332,9 @@ function useMessageComposerVm(props = {}) {
|
|
|
3705
4332
|
const flowBlocked = isRunning || sendMessage.isPending;
|
|
3706
4333
|
return !(isUploadingFiles || flowBlocked || nothingToSend);
|
|
3707
4334
|
};
|
|
3708
|
-
const handleSendMessage = (text6, files) => {
|
|
4335
|
+
const handleSendMessage = (text6, files, onFailed) => {
|
|
3709
4336
|
if (!canSend(text6, files)) return false;
|
|
3710
|
-
internalSend(text6, files);
|
|
4337
|
+
internalSend(text6, files, onFailed);
|
|
3711
4338
|
return true;
|
|
3712
4339
|
};
|
|
3713
4340
|
return {
|
|
@@ -3840,6 +4467,40 @@ function MessageComposer(_props = {}) {
|
|
|
3840
4467
|
cancelReset();
|
|
3841
4468
|
}
|
|
3842
4469
|
}, [isSending, cancelAccepted, cancelErrored, cancelReset]);
|
|
4470
|
+
const attachEditor = useCallback(
|
|
4471
|
+
(handle2) => {
|
|
4472
|
+
if (handle2) editorRef.current = handle2;
|
|
4473
|
+
},
|
|
4474
|
+
// Both flags matter: the portal mounts on `isMobile && isFullscreen`, and
|
|
4475
|
+
// nothing resets isFullscreen when the breakpoint flips, so crossing it
|
|
4476
|
+
// while fullscreen would unmount the portal editor without re-attaching the
|
|
4477
|
+
// inline one — leaving a destroyed handle and silently swallowing phrases.
|
|
4478
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4479
|
+
[isFullscreen, isMobile]
|
|
4480
|
+
);
|
|
4481
|
+
const { data: speechConfig, isFetching: speechConfigLoading } = useSpeechConfig();
|
|
4482
|
+
const getSpeechToken = useMemo(
|
|
4483
|
+
() => chatService.getSpeechToken?.bind(chatService),
|
|
4484
|
+
[chatService]
|
|
4485
|
+
);
|
|
4486
|
+
const dictation = useDictation({
|
|
4487
|
+
region: speechConfig?.enabled ? speechConfig.region : null,
|
|
4488
|
+
locale: speechConfig?.defaultLocale ?? "en-US",
|
|
4489
|
+
getToken: getSpeechToken,
|
|
4490
|
+
// Final phrases become real text; provisional ones render as greyed ghost
|
|
4491
|
+
// text at the caret and never enter the document.
|
|
4492
|
+
onPhrase: (text6) => editorRef.current?.insertText(`${text6} `),
|
|
4493
|
+
onInterim: (text6) => editorRef.current?.setDictationGhost(text6)
|
|
4494
|
+
});
|
|
4495
|
+
const { stop: stopDictation } = dictation;
|
|
4496
|
+
const dictationUnavailableReason = speechConfigLoading ? "Checking whether dictation is available" : dictation.supported ? "Dictation is not enabled for this workspace" : "Dictation is not available in this browser";
|
|
4497
|
+
const handleDictationToggle = () => {
|
|
4498
|
+
if (dictation.state === "idle") editorRef.current?.focus();
|
|
4499
|
+
dictation.toggle();
|
|
4500
|
+
};
|
|
4501
|
+
useEffect(() => {
|
|
4502
|
+
if (disabled) stopDictation();
|
|
4503
|
+
}, [disabled, stopDictation]);
|
|
3843
4504
|
useEffect(() => {
|
|
3844
4505
|
if (typeof window === "undefined") return;
|
|
3845
4506
|
window.__ssDownloadFile = (id) => getFileBlobUrl(id);
|
|
@@ -3957,8 +4618,18 @@ function MessageComposer(_props = {}) {
|
|
|
3957
4618
|
}, [editorKey]);
|
|
3958
4619
|
const handleSendMessageAndClear = () => {
|
|
3959
4620
|
const latestText = editorRef.current?.getMarkdown() ?? newMessage;
|
|
3960
|
-
const
|
|
4621
|
+
const restoreText = () => {
|
|
4622
|
+
if ((editorRef.current?.getMarkdown() ?? "").trim()) return;
|
|
4623
|
+
setNewMessage(latestText);
|
|
4624
|
+
setEditorKey((k) => k + 1);
|
|
4625
|
+
};
|
|
4626
|
+
const sent = handleSendMessage(
|
|
4627
|
+
latestText,
|
|
4628
|
+
uploadedAttachments,
|
|
4629
|
+
restoreText
|
|
4630
|
+
);
|
|
3961
4631
|
if (!sent) return;
|
|
4632
|
+
stopDictation();
|
|
3962
4633
|
handleClearAttachments();
|
|
3963
4634
|
setEditorKey((k) => k + 1);
|
|
3964
4635
|
};
|
|
@@ -4065,7 +4736,7 @@ function MessageComposer(_props = {}) {
|
|
|
4065
4736
|
/* @__PURE__ */ jsx("div", { className: "max-h-[400px] w-full overflow-y-auto", children: /* @__PURE__ */ jsx(
|
|
4066
4737
|
MarkdownEditor,
|
|
4067
4738
|
{
|
|
4068
|
-
ref:
|
|
4739
|
+
ref: attachEditor,
|
|
4069
4740
|
value: newMessage,
|
|
4070
4741
|
onChange: (md) => setNewMessage(md),
|
|
4071
4742
|
onKeyDown: handleComposerKeyDown,
|
|
@@ -4078,14 +4749,22 @@ function MessageComposer(_props = {}) {
|
|
|
4078
4749
|
disabled,
|
|
4079
4750
|
placeholder: "What would you like to do?",
|
|
4080
4751
|
className: "md-editor--bare px-5 pb-3 pt-4 text-sm",
|
|
4081
|
-
minHeight:
|
|
4752
|
+
minHeight: 24
|
|
4082
4753
|
},
|
|
4083
4754
|
`composer-md-${editorKey}`
|
|
4084
4755
|
) }),
|
|
4756
|
+
/* @__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" : "" }),
|
|
4757
|
+
dictation.state === "listening" && dictation.silent && /* @__PURE__ */ jsxs("div", { className: "px-5 pb-1 text-xs text-muted-foreground", children: [
|
|
4758
|
+
"Not hearing anything from",
|
|
4759
|
+
" ",
|
|
4760
|
+
dictation.deviceLabel || "your microphone",
|
|
4761
|
+
"."
|
|
4762
|
+
] }),
|
|
4763
|
+
dictation.error && /* @__PURE__ */ jsx("div", { role: "alert", className: "px-5 pb-1 text-xs text-destructive", children: dictationErrorMessages[dictation.error] }),
|
|
4085
4764
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2 px-3 pb-3", children: [
|
|
4086
4765
|
/* @__PURE__ */ jsxs("div", { className: "ss-composer__actions flex min-w-0 flex-1 items-center gap-1", children: [
|
|
4087
4766
|
supportsFiles && /* @__PURE__ */ jsx(
|
|
4088
|
-
|
|
4767
|
+
IconButton2,
|
|
4089
4768
|
{
|
|
4090
4769
|
type: "button",
|
|
4091
4770
|
onClick: handlePickFilesClick,
|
|
@@ -4106,19 +4785,39 @@ function MessageComposer(_props = {}) {
|
|
|
4106
4785
|
)
|
|
4107
4786
|
] }),
|
|
4108
4787
|
/* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-1.5", children: [
|
|
4109
|
-
/* @__PURE__ */ jsx(
|
|
4110
|
-
|
|
4788
|
+
dictation.available ? /* @__PURE__ */ jsx(
|
|
4789
|
+
DictationButton,
|
|
4111
4790
|
{
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
children: /* @__PURE__ */ jsx(Mic, { className: "h-4 w-4" })
|
|
4791
|
+
state: dictation.state,
|
|
4792
|
+
error: dictation.error,
|
|
4793
|
+
disabled,
|
|
4794
|
+
onToggle: handleDictationToggle,
|
|
4795
|
+
deviceLabel: dictation.deviceLabel
|
|
4118
4796
|
}
|
|
4797
|
+
) : (
|
|
4798
|
+
// A disabled button receives no pointer events, so its own
|
|
4799
|
+
// `title` never renders a tooltip. The wrapper is what the user
|
|
4800
|
+
// actually hovers.
|
|
4801
|
+
/* @__PURE__ */ jsx(
|
|
4802
|
+
"span",
|
|
4803
|
+
{
|
|
4804
|
+
title: dictationUnavailableReason,
|
|
4805
|
+
className: "inline-flex cursor-not-allowed",
|
|
4806
|
+
children: /* @__PURE__ */ jsx(
|
|
4807
|
+
IconButton2,
|
|
4808
|
+
{
|
|
4809
|
+
type: "button",
|
|
4810
|
+
disabled: true,
|
|
4811
|
+
"aria-label": `Dictate a message. ${dictationUnavailableReason}`,
|
|
4812
|
+
className: "h-8 w-8 rounded-full text-muted-foreground",
|
|
4813
|
+
children: /* @__PURE__ */ jsx(Mic, { className: "h-4 w-4" })
|
|
4814
|
+
}
|
|
4815
|
+
)
|
|
4816
|
+
}
|
|
4817
|
+
)
|
|
4119
4818
|
),
|
|
4120
4819
|
canStop ? /* @__PURE__ */ jsx(
|
|
4121
|
-
|
|
4820
|
+
IconButton2,
|
|
4122
4821
|
{
|
|
4123
4822
|
onClick: handleStopRun,
|
|
4124
4823
|
className: "chat-send h-8 w-8 rounded-full",
|
|
@@ -4132,7 +4831,7 @@ function MessageComposer(_props = {}) {
|
|
|
4132
4831
|
)
|
|
4133
4832
|
}
|
|
4134
4833
|
) : /* @__PURE__ */ jsx(
|
|
4135
|
-
|
|
4834
|
+
IconButton2,
|
|
4136
4835
|
{
|
|
4137
4836
|
onClick: handleSendMessageAndClear,
|
|
4138
4837
|
className: `chat-send h-8 w-8 rounded-full ${sendDisabled ? "cursor-not-allowed" : ""}`,
|
|
@@ -4161,7 +4860,7 @@ function MessageComposer(_props = {}) {
|
|
|
4161
4860
|
},
|
|
4162
4861
|
children: /* @__PURE__ */ jsxs("div", { className: "relative h-full w-full bg-background border shadow-lg", children: [
|
|
4163
4862
|
/* @__PURE__ */ jsx(
|
|
4164
|
-
|
|
4863
|
+
IconButton2,
|
|
4165
4864
|
{
|
|
4166
4865
|
type: "button",
|
|
4167
4866
|
size: "small",
|
|
@@ -4179,7 +4878,7 @@ function MessageComposer(_props = {}) {
|
|
|
4179
4878
|
/* @__PURE__ */ jsx("div", { className: "flex-1 p-4", children: /* @__PURE__ */ jsx(
|
|
4180
4879
|
MarkdownEditor,
|
|
4181
4880
|
{
|
|
4182
|
-
ref:
|
|
4881
|
+
ref: attachEditor,
|
|
4183
4882
|
value: newMessage,
|
|
4184
4883
|
onChange: (md) => setNewMessage(md),
|
|
4185
4884
|
onKeyDown: handleComposerKeyDown,
|
|
@@ -4194,10 +4893,18 @@ function MessageComposer(_props = {}) {
|
|
|
4194
4893
|
},
|
|
4195
4894
|
`composer-md-${editorKey}`
|
|
4196
4895
|
) }),
|
|
4896
|
+
dictation.error && /* @__PURE__ */ jsx(
|
|
4897
|
+
"div",
|
|
4898
|
+
{
|
|
4899
|
+
"aria-hidden": "true",
|
|
4900
|
+
className: "px-4 pb-1 text-xs text-destructive",
|
|
4901
|
+
children: dictationErrorMessages[dictation.error]
|
|
4902
|
+
}
|
|
4903
|
+
),
|
|
4197
4904
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 px-3 py-2 border-t bg-background", children: [
|
|
4198
4905
|
/* @__PURE__ */ jsx("div", { className: "flex-1" }),
|
|
4199
4906
|
supportsFiles && /* @__PURE__ */ jsx(
|
|
4200
|
-
|
|
4907
|
+
IconButton2,
|
|
4201
4908
|
{
|
|
4202
4909
|
type: "button",
|
|
4203
4910
|
onClick: handlePickFilesClick,
|
|
@@ -4212,8 +4919,19 @@ function MessageComposer(_props = {}) {
|
|
|
4212
4919
|
)
|
|
4213
4920
|
}
|
|
4214
4921
|
),
|
|
4922
|
+
dictation.available && /* @__PURE__ */ jsx(
|
|
4923
|
+
DictationButton,
|
|
4924
|
+
{
|
|
4925
|
+
size: "md",
|
|
4926
|
+
state: dictation.state,
|
|
4927
|
+
error: dictation.error,
|
|
4928
|
+
disabled,
|
|
4929
|
+
onToggle: handleDictationToggle,
|
|
4930
|
+
deviceLabel: dictation.deviceLabel
|
|
4931
|
+
}
|
|
4932
|
+
),
|
|
4215
4933
|
canStop ? /* @__PURE__ */ jsx(
|
|
4216
|
-
|
|
4934
|
+
IconButton2,
|
|
4217
4935
|
{
|
|
4218
4936
|
onClick: handleStopRun,
|
|
4219
4937
|
className: "chat-send h-9 w-9 rounded-full",
|
|
@@ -4227,7 +4945,7 @@ function MessageComposer(_props = {}) {
|
|
|
4227
4945
|
)
|
|
4228
4946
|
}
|
|
4229
4947
|
) : /* @__PURE__ */ jsx(
|
|
4230
|
-
|
|
4948
|
+
IconButton2,
|
|
4231
4949
|
{
|
|
4232
4950
|
onClick: handleSendMessageAndClear,
|
|
4233
4951
|
className: `chat-send h-9 w-9 rounded-full ${sendDisabled ? "cursor-not-allowed" : ""}`,
|
|
@@ -18891,6 +19609,45 @@ function MessageMarkdown({ value, className }) {
|
|
|
18891
19609
|
function cn(...inputs) {
|
|
18892
19610
|
return twMerge(clsx(inputs));
|
|
18893
19611
|
}
|
|
19612
|
+
var buttonVariants = cva(
|
|
19613
|
+
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
|
|
19614
|
+
{
|
|
19615
|
+
variants: {
|
|
19616
|
+
variant: {
|
|
19617
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
19618
|
+
destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
|
19619
|
+
outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
|
19620
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
19621
|
+
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
19622
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
19623
|
+
},
|
|
19624
|
+
size: {
|
|
19625
|
+
default: "h-10 px-4 py-2",
|
|
19626
|
+
sm: "h-9 rounded-md px-3",
|
|
19627
|
+
lg: "h-11 rounded-md px-8",
|
|
19628
|
+
icon: "h-10 w-10"
|
|
19629
|
+
}
|
|
19630
|
+
},
|
|
19631
|
+
defaultVariants: {
|
|
19632
|
+
variant: "default",
|
|
19633
|
+
size: "default"
|
|
19634
|
+
}
|
|
19635
|
+
}
|
|
19636
|
+
);
|
|
19637
|
+
var Button = React9.forwardRef(
|
|
19638
|
+
({ className, variant, size, asChild = false, ...props }, ref) => {
|
|
19639
|
+
const Comp = asChild ? Slot : "button";
|
|
19640
|
+
return /* @__PURE__ */ jsx(
|
|
19641
|
+
Comp,
|
|
19642
|
+
{
|
|
19643
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
19644
|
+
ref,
|
|
19645
|
+
...props
|
|
19646
|
+
}
|
|
19647
|
+
);
|
|
19648
|
+
}
|
|
19649
|
+
);
|
|
19650
|
+
Button.displayName = "Button";
|
|
18894
19651
|
function Skeleton({ className, ...props }) {
|
|
18895
19652
|
return /* @__PURE__ */ jsx(
|
|
18896
19653
|
MuiSkeleton,
|
|
@@ -18912,20 +19669,40 @@ var ERROR_CODE_TEXT = {
|
|
|
18912
19669
|
"llm.timeout": "\u26A0\uFE0F **The model took too long to respond**\n\nPlease try again. If this keeps happening, try a shorter question.",
|
|
18913
19670
|
"llm.transient_connection": "\u26A0\uFE0F **The connection to the model was interrupted**\n\nThis is usually temporary. Please try again.",
|
|
18914
19671
|
"llm.upstream_error": "\u26A0\uFE0F **The model provider had a problem**\n\nPlease try again in a moment.",
|
|
18915
|
-
"llm.auth": "\u26A0\uFE0F **The model connection isn't authorised**\n\nAn administrator needs to check the model configuration.",
|
|
18916
19672
|
"llm.not_found": "\u26A0\uFE0F **The model or deployment could not be found**\n\nAn administrator needs to check the model configuration.",
|
|
18917
19673
|
"llm.invalid_request": "\u26A0\uFE0F **The request was rejected by the model provider**\n\nPlease try rephrasing your message.",
|
|
18918
19674
|
"llm.context_window": "\u26A0\uFE0F **This conversation is too long for the model**\n\nPlease start a new thread, or ask a shorter question.",
|
|
18919
19675
|
"llm.content_policy": "\u26A0\uFE0F **The response was blocked by a content filter**\n\nPlease rephrase your request.",
|
|
18920
19676
|
"llm.schema_validation": "\u26A0\uFE0F **The model returned an invalid response**\n\nPlease try again.",
|
|
18921
19677
|
"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.",
|
|
18922
|
-
"llm.
|
|
19678
|
+
"llm.auth_failed": "\u26A0\uFE0F **The model connection isn't authorised**\n\nAn administrator needs to check the model configuration.",
|
|
19679
|
+
"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.",
|
|
19680
|
+
"embeddings.model_not_found": "\u26A0\uFE0F **The model or deployment could not be found**\n\nAn administrator needs to check the model configuration.",
|
|
19681
|
+
// The app API's names for losing the AI API before or part-way through a reply.
|
|
19682
|
+
"ai_api.unavailable": "\u26A0\uFE0F **The connection to the model was interrupted**\n\nThis is usually temporary. Please try again.",
|
|
19683
|
+
"ai_api.stream_broken": "\u26A0\uFE0F **The connection to the model was interrupted**\n\nThis is usually temporary. Please try again.",
|
|
19684
|
+
// Managed secrets. A secret's failure arrives as a 404 or 400, which the
|
|
19685
|
+
// status table below would read as a missing model or a generic error.
|
|
19686
|
+
"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.",
|
|
19687
|
+
"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.",
|
|
19688
|
+
"secret.user_mismatch": "\u26A0\uFE0F **A credential couldn't be loaded**\n\nAn administrator needs to check this flow's secrets.",
|
|
19689
|
+
"secret.run_required": "\u26A0\uFE0F **A credential couldn't be loaded**\n\nAn administrator needs to check this flow's secrets.",
|
|
19690
|
+
"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."
|
|
19691
|
+
};
|
|
19692
|
+
var LEGACY_CODE_TEXT = {
|
|
19693
|
+
"llm.auth": ERROR_CODE_TEXT["llm.auth_failed"],
|
|
19694
|
+
"llm.unknown": GENERIC_ERROR_TEXT,
|
|
19695
|
+
MS404: ERROR_CODE_TEXT["secret.not_found"]
|
|
19696
|
+
};
|
|
19697
|
+
var CODE_TEXT = {
|
|
19698
|
+
...LEGACY_CODE_TEXT,
|
|
19699
|
+
...ERROR_CODE_TEXT
|
|
18923
19700
|
};
|
|
18924
19701
|
var STATUS_CODE_TEXT = {
|
|
18925
19702
|
408: ERROR_CODE_TEXT["llm.timeout"],
|
|
18926
19703
|
429: ERROR_CODE_TEXT["llm.rate_limit"],
|
|
18927
|
-
401: ERROR_CODE_TEXT["llm.
|
|
18928
|
-
403: ERROR_CODE_TEXT["llm.
|
|
19704
|
+
401: ERROR_CODE_TEXT["llm.auth_failed"],
|
|
19705
|
+
403: ERROR_CODE_TEXT["llm.auth_failed"],
|
|
18929
19706
|
404: ERROR_CODE_TEXT["llm.not_found"],
|
|
18930
19707
|
500: ERROR_CODE_TEXT["llm.upstream_error"],
|
|
18931
19708
|
502: ERROR_CODE_TEXT["llm.upstream_error"],
|
|
@@ -18936,11 +19713,117 @@ var getMessageErrorText = (error) => {
|
|
|
18936
19713
|
if (typeof error === "number") {
|
|
18937
19714
|
return STATUS_CODE_TEXT[error] ?? GENERIC_ERROR_TEXT;
|
|
18938
19715
|
}
|
|
18939
|
-
|
|
18940
|
-
|
|
19716
|
+
const codeText = error.errorCode ? CODE_TEXT[error.errorCode] : void 0;
|
|
19717
|
+
if (codeText) {
|
|
19718
|
+
return codeText;
|
|
19719
|
+
}
|
|
19720
|
+
if (error.errorCode && !error.errorCode.startsWith("llm.")) {
|
|
19721
|
+
return GENERIC_ERROR_TEXT;
|
|
18941
19722
|
}
|
|
18942
19723
|
return STATUS_CODE_TEXT[error.code] ?? GENERIC_ERROR_TEXT;
|
|
18943
19724
|
};
|
|
19725
|
+
function extractProviderErrorDetail(raw2) {
|
|
19726
|
+
const start = raw2.indexOf("{");
|
|
19727
|
+
if (start === -1) return null;
|
|
19728
|
+
let parsed;
|
|
19729
|
+
try {
|
|
19730
|
+
parsed = JSON.parse(raw2.slice(start));
|
|
19731
|
+
} catch {
|
|
19732
|
+
return null;
|
|
19733
|
+
}
|
|
19734
|
+
if (typeof parsed !== "object" || parsed === null) return null;
|
|
19735
|
+
const record = parsed;
|
|
19736
|
+
const inner = typeof record.error === "object" && record.error !== null ? record.error : record;
|
|
19737
|
+
if (typeof inner.message !== "string") return null;
|
|
19738
|
+
return {
|
|
19739
|
+
message: inner.message,
|
|
19740
|
+
param: typeof inner.param === "string" ? inner.param : void 0
|
|
19741
|
+
};
|
|
19742
|
+
}
|
|
19743
|
+
var getMessageErrorDetail = (error) => {
|
|
19744
|
+
if (typeof error === "number" || !error.message) {
|
|
19745
|
+
return null;
|
|
19746
|
+
}
|
|
19747
|
+
const detail = extractProviderErrorDetail(error.message);
|
|
19748
|
+
if (!detail) {
|
|
19749
|
+
return error.message;
|
|
19750
|
+
}
|
|
19751
|
+
return detail.param ? `${detail.message} (param: ${detail.param})` : detail.message;
|
|
19752
|
+
};
|
|
19753
|
+
var FileInfoSchema = z.object({
|
|
19754
|
+
id: z.string(),
|
|
19755
|
+
name: z.string()
|
|
19756
|
+
});
|
|
19757
|
+
z.object({
|
|
19758
|
+
workspaceId: z.string().optional(),
|
|
19759
|
+
threadId: z.string().optional()
|
|
19760
|
+
});
|
|
19761
|
+
|
|
19762
|
+
// src/domains/messages/schemas.ts
|
|
19763
|
+
var MessageResponseSourceSchema = z.object({
|
|
19764
|
+
index: z.number(),
|
|
19765
|
+
datasetItemId: z.string().optional(),
|
|
19766
|
+
containerItemId: z.string().nullish(),
|
|
19767
|
+
flowRunId: z.string().optional(),
|
|
19768
|
+
file: FileInfoSchema.nullish(),
|
|
19769
|
+
url: z.string().nullish(),
|
|
19770
|
+
sourceType: z.nativeEnum(MessageResponseSourceType),
|
|
19771
|
+
// WS3c citation grounding (additive; absent on older responses).
|
|
19772
|
+
uri: z.string().nullish(),
|
|
19773
|
+
citedText: z.string().nullish(),
|
|
19774
|
+
attribution: z.nativeEnum(MessageAttribution).nullish(),
|
|
19775
|
+
// Where the cited item lives at its source (SharePoint web link, HubSpot record page).
|
|
19776
|
+
// Distinct from `url` (the source *is* that URL): this rides File sources so the card
|
|
19777
|
+
// can offer "open at source" beside the download of our copy. Absent when unknown.
|
|
19778
|
+
webUrl: z.string().nullish()
|
|
19779
|
+
});
|
|
19780
|
+
var MessageResponseSchema = z.object({
|
|
19781
|
+
content: z.string(),
|
|
19782
|
+
messageId: z.string(),
|
|
19783
|
+
sources: z.array(MessageResponseSourceSchema).nullish(),
|
|
19784
|
+
isReplying: z.boolean().nullish().default(false),
|
|
19785
|
+
requestedJsonSchema: z.string().nullish()
|
|
19786
|
+
});
|
|
19787
|
+
var MessageErrorMessageSchema = z.object({
|
|
19788
|
+
code: z.number(),
|
|
19789
|
+
// Stable machine-readable category (e.g. "llm.rate_limit"). Accept both
|
|
19790
|
+
// spellings: app-api serialises camelCase, the ai-api origin field is
|
|
19791
|
+
// snake_case — the mapper coalesces them.
|
|
19792
|
+
errorCode: z.string().nullish(),
|
|
19793
|
+
error_code: z.string().nullish(),
|
|
19794
|
+
message: z.string().nullish(),
|
|
19795
|
+
data: z.string().nullish(),
|
|
19796
|
+
blockId: z.string().nullish(),
|
|
19797
|
+
traceId: z.string().nullish()
|
|
19798
|
+
});
|
|
19799
|
+
var MessageSchema = z.object({
|
|
19800
|
+
id: z.string().nullish(),
|
|
19801
|
+
createdAt: DateFromApi,
|
|
19802
|
+
createdBy: z.string().nullish(),
|
|
19803
|
+
hasComments: z.boolean().default(false),
|
|
19804
|
+
createdByUserId: z.string().nullish(),
|
|
19805
|
+
messageThreadId: z.string().nullish(),
|
|
19806
|
+
errors: z.array(MessageErrorMessageSchema).nullish(),
|
|
19807
|
+
values: z.array(
|
|
19808
|
+
z.object({
|
|
19809
|
+
id: z.string(),
|
|
19810
|
+
name: z.string(),
|
|
19811
|
+
type: z.nativeEnum(MessageValueType),
|
|
19812
|
+
value: z.any(),
|
|
19813
|
+
// Can be string (for Output), array (for Input), or object (for Variables)
|
|
19814
|
+
channels: z.record(z.string(), z.number()),
|
|
19815
|
+
createdAt: DateFromApi,
|
|
19816
|
+
createdBy: z.string(),
|
|
19817
|
+
createdByUserId: z.string().nullish()
|
|
19818
|
+
})
|
|
19819
|
+
).nullish(),
|
|
19820
|
+
optimistic: z.boolean().optional().default(false)
|
|
19821
|
+
});
|
|
19822
|
+
z.object({
|
|
19823
|
+
text: z.string().nullish(),
|
|
19824
|
+
image: FileInfoSchema.nullish()
|
|
19825
|
+
});
|
|
19826
|
+
z.array(MessageSchema);
|
|
18944
19827
|
|
|
18945
19828
|
// src/domains/messages/statuses.ts
|
|
18946
19829
|
var asRecord = (value) => {
|
|
@@ -18978,7 +19861,7 @@ var RETRY_REASON_TEXT = {
|
|
|
18978
19861
|
"llm.rate_limit": "the model is busy",
|
|
18979
19862
|
"llm.timeout": "the model took too long",
|
|
18980
19863
|
"llm.transient_connection": "the connection dropped",
|
|
18981
|
-
"llm.
|
|
19864
|
+
"llm.upstream_error": "the model provider had a problem"
|
|
18982
19865
|
};
|
|
18983
19866
|
var getRetryStatusText = (status) => {
|
|
18984
19867
|
const reason = status.errorCode ? RETRY_REASON_TEXT[status.errorCode] : void 0;
|
|
@@ -19059,45 +19942,6 @@ function parseDateTime(date, customFormat) {
|
|
|
19059
19942
|
function parseDateTimeHuman(date) {
|
|
19060
19943
|
return dayjs.utc(date).local().fromNow();
|
|
19061
19944
|
}
|
|
19062
|
-
var buttonVariants = cva(
|
|
19063
|
-
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
|
|
19064
|
-
{
|
|
19065
|
-
variants: {
|
|
19066
|
-
variant: {
|
|
19067
|
-
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
19068
|
-
destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
|
19069
|
-
outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
|
19070
|
-
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
19071
|
-
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
19072
|
-
link: "text-primary underline-offset-4 hover:underline"
|
|
19073
|
-
},
|
|
19074
|
-
size: {
|
|
19075
|
-
default: "h-10 px-4 py-2",
|
|
19076
|
-
sm: "h-9 rounded-md px-3",
|
|
19077
|
-
lg: "h-11 rounded-md px-8",
|
|
19078
|
-
icon: "h-10 w-10"
|
|
19079
|
-
}
|
|
19080
|
-
},
|
|
19081
|
-
defaultVariants: {
|
|
19082
|
-
variant: "default",
|
|
19083
|
-
size: "default"
|
|
19084
|
-
}
|
|
19085
|
-
}
|
|
19086
|
-
);
|
|
19087
|
-
var Button = React8.forwardRef(
|
|
19088
|
-
({ className, variant, size, asChild = false, ...props }, ref) => {
|
|
19089
|
-
const Comp = asChild ? Slot : "button";
|
|
19090
|
-
return /* @__PURE__ */ jsx(
|
|
19091
|
-
Comp,
|
|
19092
|
-
{
|
|
19093
|
-
className: cn(buttonVariants({ variant, size, className })),
|
|
19094
|
-
ref,
|
|
19095
|
-
...props
|
|
19096
|
-
}
|
|
19097
|
-
);
|
|
19098
|
-
}
|
|
19099
|
-
);
|
|
19100
|
-
Button.displayName = "Button";
|
|
19101
19945
|
|
|
19102
19946
|
// src/messages/smartCopy.ts
|
|
19103
19947
|
async function copyMessageRich(container, markdown) {
|
|
@@ -19547,6 +20391,7 @@ function ChatMessageSources({
|
|
|
19547
20391
|
/* @__PURE__ */ jsx(SectionLabel, { children: "Files" }),
|
|
19548
20392
|
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1.5", children: fileSources.map((source) => {
|
|
19549
20393
|
const Icon = getFileIcon3(source.file.name);
|
|
20394
|
+
const sourceHref = source.webUrl ? getSafeUrl(source.webUrl) : null;
|
|
19550
20395
|
if (!openIndexes.has(source.index)) {
|
|
19551
20396
|
return /* @__PURE__ */ jsxs(
|
|
19552
20397
|
"button",
|
|
@@ -19595,19 +20440,36 @@ function ChatMessageSources({
|
|
|
19595
20440
|
)
|
|
19596
20441
|
] }),
|
|
19597
20442
|
/* @__PURE__ */ jsx(CitedQuote, { text: source.citedText }),
|
|
19598
|
-
/* @__PURE__ */ jsxs(
|
|
19599
|
-
|
|
19600
|
-
|
|
19601
|
-
|
|
19602
|
-
|
|
19603
|
-
|
|
19604
|
-
|
|
19605
|
-
|
|
19606
|
-
|
|
19607
|
-
|
|
19608
|
-
|
|
19609
|
-
|
|
19610
|
-
|
|
20443
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-1.5", children: [
|
|
20444
|
+
sourceHref && /* @__PURE__ */ jsxs(
|
|
20445
|
+
"a",
|
|
20446
|
+
{
|
|
20447
|
+
href: sourceHref,
|
|
20448
|
+
target: "_blank",
|
|
20449
|
+
rel: "noreferrer",
|
|
20450
|
+
title: source.webUrl ?? void 0,
|
|
20451
|
+
className: "inline-flex w-fit items-center gap-1 rounded-md border border-border/60 px-2 py-1 text-xs font-medium text-foreground no-underline transition-colors hover:bg-muted/40",
|
|
20452
|
+
children: [
|
|
20453
|
+
/* @__PURE__ */ jsx(ExternalLink, { className: "h-3 w-3" }),
|
|
20454
|
+
"Open in ",
|
|
20455
|
+
getHost(sourceHref)
|
|
20456
|
+
]
|
|
20457
|
+
}
|
|
20458
|
+
),
|
|
20459
|
+
/* @__PURE__ */ jsxs(
|
|
20460
|
+
"button",
|
|
20461
|
+
{
|
|
20462
|
+
type: "button",
|
|
20463
|
+
onClick: () => downloadFileMutation.mutate(source.file),
|
|
20464
|
+
disabled: downloadFileMutation.isPending,
|
|
20465
|
+
className: "inline-flex w-fit items-center gap-1 rounded-md border border-border/60 px-2 py-1 text-xs font-medium text-foreground transition-colors hover:bg-muted/40 disabled:cursor-not-allowed disabled:opacity-50",
|
|
20466
|
+
children: [
|
|
20467
|
+
/* @__PURE__ */ jsx(Download, { className: "h-3 w-3" }),
|
|
20468
|
+
"Download"
|
|
20469
|
+
]
|
|
20470
|
+
}
|
|
20471
|
+
)
|
|
20472
|
+
] })
|
|
19611
20473
|
]
|
|
19612
20474
|
},
|
|
19613
20475
|
`${source.file.id}-${source.index}`
|
|
@@ -19617,6 +20479,7 @@ function ChatMessageSources({
|
|
|
19617
20479
|
] })
|
|
19618
20480
|
] });
|
|
19619
20481
|
}
|
|
20482
|
+
var USER_FORM_CONFIG = { surface: "form", minRows: 6, maxRows: 20 };
|
|
19620
20483
|
var REVEAL_ON_HOVER = "opacity-100 focus-visible:opacity-100 [@media(hover:hover)]:opacity-0 [@media(hover:hover)]:group-hover:opacity-100";
|
|
19621
20484
|
var MessageBubble = (props) => {
|
|
19622
20485
|
const {
|
|
@@ -19670,7 +20533,7 @@ var MessageBubble = (props) => {
|
|
|
19670
20533
|
);
|
|
19671
20534
|
})
|
|
19672
20535
|
] }),
|
|
19673
|
-
showForm && /* @__PURE__ */ jsxs("div", { className: "mt-4 border-t border-border pt-4", children: [
|
|
20536
|
+
showForm && /* @__PURE__ */ jsxs("div", { className: "ss-chat-message__user-form mt-4 border-t border-border pt-4", children: [
|
|
19674
20537
|
/* @__PURE__ */ jsx(
|
|
19675
20538
|
JsonForms,
|
|
19676
20539
|
{
|
|
@@ -19679,6 +20542,7 @@ var MessageBubble = (props) => {
|
|
|
19679
20542
|
renderers,
|
|
19680
20543
|
cells,
|
|
19681
20544
|
readonly: userInput !== void 0,
|
|
20545
|
+
config: USER_FORM_CONFIG,
|
|
19682
20546
|
onChange: ({ data, errors }) => {
|
|
19683
20547
|
setResponseFormData(data);
|
|
19684
20548
|
setResponseFormValid(!errors?.length);
|
|
@@ -19739,6 +20603,53 @@ var MessageBubble = (props) => {
|
|
|
19739
20603
|
/* @__PURE__ */ jsx("div", { className: "mt-1.5", children: metaRow })
|
|
19740
20604
|
] });
|
|
19741
20605
|
};
|
|
20606
|
+
function MessageErrorDetails({
|
|
20607
|
+
detail,
|
|
20608
|
+
traceId
|
|
20609
|
+
}) {
|
|
20610
|
+
const [expanded, setExpanded] = useState(false);
|
|
20611
|
+
return /* @__PURE__ */ jsxs("div", { className: "mt-1", children: [
|
|
20612
|
+
/* @__PURE__ */ jsxs(
|
|
20613
|
+
"button",
|
|
20614
|
+
{
|
|
20615
|
+
type: "button",
|
|
20616
|
+
onClick: () => setExpanded((prev) => !prev),
|
|
20617
|
+
"aria-expanded": expanded,
|
|
20618
|
+
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",
|
|
20619
|
+
children: [
|
|
20620
|
+
expanded ? /* @__PURE__ */ jsx(ChevronDown, { className: "h-3 w-3 shrink-0" }) : /* @__PURE__ */ jsx(ChevronRight, { className: "h-3 w-3 shrink-0" }),
|
|
20621
|
+
expanded ? "Hide details" : "Show details"
|
|
20622
|
+
]
|
|
20623
|
+
}
|
|
20624
|
+
),
|
|
20625
|
+
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: [
|
|
20626
|
+
detail,
|
|
20627
|
+
traceId && /* @__PURE__ */ jsxs("div", { className: detail ? "mt-1.5" : void 0, children: [
|
|
20628
|
+
"Reference: ",
|
|
20629
|
+
traceId
|
|
20630
|
+
] })
|
|
20631
|
+
] })
|
|
20632
|
+
] });
|
|
20633
|
+
}
|
|
20634
|
+
function MessageReasoning({ text: text6 }) {
|
|
20635
|
+
const [expanded, setExpanded] = useState(false);
|
|
20636
|
+
return /* @__PURE__ */ jsxs("div", { className: "mb-1", children: [
|
|
20637
|
+
/* @__PURE__ */ jsxs(
|
|
20638
|
+
"button",
|
|
20639
|
+
{
|
|
20640
|
+
type: "button",
|
|
20641
|
+
onClick: () => setExpanded((prev) => !prev),
|
|
20642
|
+
"aria-expanded": expanded,
|
|
20643
|
+
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",
|
|
20644
|
+
children: [
|
|
20645
|
+
expanded ? /* @__PURE__ */ jsx(ChevronDown, { className: "h-3 w-3 shrink-0" }) : /* @__PURE__ */ jsx(ChevronRight, { className: "h-3 w-3 shrink-0" }),
|
|
20646
|
+
expanded ? "Hide reasoning" : "Show reasoning"
|
|
20647
|
+
]
|
|
20648
|
+
}
|
|
20649
|
+
),
|
|
20650
|
+
expanded && /* @__PURE__ */ jsx("div", { className: "mt-1.5 rounded-md bg-secondary/60 p-2 text-[13px] text-muted-foreground", children: /* @__PURE__ */ jsx(MessageMarkdown, { value: text6 }) })
|
|
20651
|
+
] });
|
|
20652
|
+
}
|
|
19742
20653
|
var ThinkingSection = ({ status }) => /* @__PURE__ */ jsxs(
|
|
19743
20654
|
"div",
|
|
19744
20655
|
{
|
|
@@ -19811,6 +20722,10 @@ function coerceSources(x) {
|
|
|
19811
20722
|
if (!Array.isArray(x)) return [];
|
|
19812
20723
|
return x.filter(isMessageResponseSource);
|
|
19813
20724
|
}
|
|
20725
|
+
var ENVELOPE_KEYS = Object.keys(MessageResponseSchema.shape);
|
|
20726
|
+
function isResponseEnvelope(keys2) {
|
|
20727
|
+
return keys2.length > 0 && keys2.every((key) => ENVELOPE_KEYS.includes(key));
|
|
20728
|
+
}
|
|
19814
20729
|
var MessageItem = ({
|
|
19815
20730
|
message,
|
|
19816
20731
|
isLive = false
|
|
@@ -19819,14 +20734,14 @@ var MessageItem = ({
|
|
|
19819
20734
|
const { data: workspace } = useWorkspace(workspaceId);
|
|
19820
20735
|
const chatbotName = getChatbotName(workspace?.name);
|
|
19821
20736
|
const { addInputToMessageMutation } = useAddInputToMessage();
|
|
19822
|
-
const onSubmitUserForm = (messageId) => (name, value) => {
|
|
20737
|
+
const onSubmitUserForm = (messageId, channels = {}) => (name, value) => {
|
|
19823
20738
|
if (!threadId || !messageId) return;
|
|
19824
20739
|
addInputToMessageMutation.mutate({
|
|
19825
20740
|
threadId,
|
|
19826
20741
|
messageId,
|
|
19827
20742
|
name,
|
|
19828
20743
|
value,
|
|
19829
|
-
channels
|
|
20744
|
+
channels
|
|
19830
20745
|
});
|
|
19831
20746
|
};
|
|
19832
20747
|
const safeTime = (d) => {
|
|
@@ -19858,10 +20773,16 @@ var MessageItem = ({
|
|
|
19858
20773
|
let keyCounter = 0;
|
|
19859
20774
|
let lastStatusText = null;
|
|
19860
20775
|
let hasOutputContent = false;
|
|
20776
|
+
let firstOutputIndex = null;
|
|
20777
|
+
const markOutput = () => {
|
|
20778
|
+
if (firstOutputIndex === null) firstOutputIndex = bubbles.length;
|
|
20779
|
+
hasOutputContent = true;
|
|
20780
|
+
};
|
|
20781
|
+
const reasoningTexts = [];
|
|
19861
20782
|
const groupHasAnything = () => groupContent.length > 0 || groupFiles.length > 0 || groupSources.length > 0;
|
|
19862
20783
|
const flush = (nextType) => {
|
|
19863
20784
|
if (groupHasAnything()) {
|
|
19864
|
-
if (groupType === "Output" /* OUTPUT */)
|
|
20785
|
+
if (groupType === "Output" /* OUTPUT */) markOutput();
|
|
19865
20786
|
bubbles.push(
|
|
19866
20787
|
/* @__PURE__ */ jsx(
|
|
19867
20788
|
MessageBubble,
|
|
@@ -19918,9 +20839,16 @@ var MessageItem = ({
|
|
|
19918
20839
|
});
|
|
19919
20840
|
} else if (name === "response" && typeof v.value === "object" && v.value !== null && !Array.isArray(v.value)) {
|
|
19920
20841
|
const resp = v.value;
|
|
19921
|
-
const
|
|
19922
|
-
|
|
19923
|
-
|
|
20842
|
+
const keys2 = Object.keys(resp);
|
|
20843
|
+
const isEnvelope = isResponseEnvelope(keys2);
|
|
20844
|
+
if ("sources" in resp && (isEnvelope || "text" in resp || "image" in resp)) {
|
|
20845
|
+
groupSources = coerceSources(resp.sources);
|
|
20846
|
+
}
|
|
20847
|
+
if (isEnvelope) {
|
|
20848
|
+
pushContent(groupContent, resp.content);
|
|
20849
|
+
} else if (keys2.length > 0) {
|
|
20850
|
+
pushContent(groupContent, resp);
|
|
20851
|
+
}
|
|
19924
20852
|
} else {
|
|
19925
20853
|
pushContent(groupContent, v.value);
|
|
19926
20854
|
}
|
|
@@ -19950,7 +20878,7 @@ var MessageItem = ({
|
|
|
19950
20878
|
userOutput: v.value && typeof v.value === "object" ? v.value : null,
|
|
19951
20879
|
chatbotName,
|
|
19952
20880
|
userInput: userInput?.value,
|
|
19953
|
-
onSubmitUserForm: onSubmitUserForm(message.id ?? "")
|
|
20881
|
+
onSubmitUserForm: onSubmitUserForm(message.id ?? "", v.channels)
|
|
19954
20882
|
},
|
|
19955
20883
|
`user-${message.id ?? "msg"}-${keyCounter++}`
|
|
19956
20884
|
)
|
|
@@ -19964,6 +20892,12 @@ var MessageItem = ({
|
|
|
19964
20892
|
groupOpen = true;
|
|
19965
20893
|
break;
|
|
19966
20894
|
}
|
|
20895
|
+
case "reasoning": {
|
|
20896
|
+
if (typeof v.value === "string" && v.value.trim() !== "") {
|
|
20897
|
+
reasoningTexts.push(v.value);
|
|
20898
|
+
}
|
|
20899
|
+
continue;
|
|
20900
|
+
}
|
|
19967
20901
|
case "sources": {
|
|
19968
20902
|
groupSources = coerceSources(v.value);
|
|
19969
20903
|
if (groupSources.length > 0) groupOpen = true;
|
|
@@ -19981,7 +20915,7 @@ var MessageItem = ({
|
|
|
19981
20915
|
lastCreatedByUserId = v.createdByUserId;
|
|
19982
20916
|
}
|
|
19983
20917
|
if (groupOpen && groupHasAnything()) {
|
|
19984
|
-
if (groupType === "Output" /* OUTPUT */)
|
|
20918
|
+
if (groupType === "Output" /* OUTPUT */) markOutput();
|
|
19985
20919
|
bubbles.push(
|
|
19986
20920
|
/* @__PURE__ */ jsx(
|
|
19987
20921
|
MessageBubble,
|
|
@@ -20002,6 +20936,19 @@ var MessageItem = ({
|
|
|
20002
20936
|
)
|
|
20003
20937
|
);
|
|
20004
20938
|
}
|
|
20939
|
+
if (reasoningTexts.length > 0) {
|
|
20940
|
+
bubbles.splice(
|
|
20941
|
+
firstOutputIndex ?? bubbles.length,
|
|
20942
|
+
0,
|
|
20943
|
+
/* @__PURE__ */ jsx(
|
|
20944
|
+
MessageReasoning,
|
|
20945
|
+
{
|
|
20946
|
+
text: reasoningTexts.join("\n\n")
|
|
20947
|
+
},
|
|
20948
|
+
`reasoning-${message.id ?? "msg"}`
|
|
20949
|
+
)
|
|
20950
|
+
);
|
|
20951
|
+
}
|
|
20005
20952
|
const showThinking = isLive && (lastStatusText !== null || !hasOutputContent);
|
|
20006
20953
|
if (showThinking) {
|
|
20007
20954
|
bubbles.push(
|
|
@@ -20015,22 +20962,26 @@ var MessageItem = ({
|
|
|
20015
20962
|
);
|
|
20016
20963
|
}
|
|
20017
20964
|
(message.errors ?? []).forEach((error, errorIndex) => {
|
|
20965
|
+
const key = `error-${message.id ?? "msg"}-${errorIndex}-${error.errorCode ?? error.code}`;
|
|
20966
|
+
const detail = getMessageErrorDetail(error);
|
|
20018
20967
|
bubbles.push(
|
|
20019
|
-
/* @__PURE__ */
|
|
20020
|
-
|
|
20021
|
-
|
|
20022
|
-
|
|
20023
|
-
|
|
20024
|
-
|
|
20025
|
-
|
|
20026
|
-
|
|
20027
|
-
|
|
20028
|
-
|
|
20029
|
-
|
|
20030
|
-
|
|
20031
|
-
|
|
20032
|
-
|
|
20033
|
-
|
|
20968
|
+
/* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
20969
|
+
/* @__PURE__ */ jsx(
|
|
20970
|
+
MessageBubble,
|
|
20971
|
+
{
|
|
20972
|
+
createdBy: chatbotName,
|
|
20973
|
+
createdAt: message.createdAt,
|
|
20974
|
+
type: "Output" /* OUTPUT */,
|
|
20975
|
+
content: [{ text: getMessageErrorText(error) }],
|
|
20976
|
+
files: [],
|
|
20977
|
+
sources: [],
|
|
20978
|
+
chatbotName,
|
|
20979
|
+
userOutput: null,
|
|
20980
|
+
userInput: null
|
|
20981
|
+
}
|
|
20982
|
+
),
|
|
20983
|
+
(detail || error.traceId) && /* @__PURE__ */ jsx(MessageErrorDetails, { detail, traceId: error.traceId })
|
|
20984
|
+
] }, key)
|
|
20034
20985
|
);
|
|
20035
20986
|
});
|
|
20036
20987
|
return bubbles;
|
|
@@ -20056,14 +21007,16 @@ function MessageList({
|
|
|
20056
21007
|
data: thread,
|
|
20057
21008
|
isPending: threadPending,
|
|
20058
21009
|
isFetching: threadFetching,
|
|
20059
|
-
error: threadError
|
|
21010
|
+
error: threadError,
|
|
21011
|
+
refetch: refetchThread
|
|
20060
21012
|
} = useThread({ workspaceId, threadId });
|
|
20061
21013
|
const isRunning = useThreadIsRunning(workspaceId, threadId);
|
|
20062
21014
|
const {
|
|
20063
21015
|
data: messages,
|
|
20064
21016
|
isPending: messagesPending,
|
|
20065
21017
|
isFetching: messagesFetching,
|
|
20066
|
-
error: messagesError
|
|
21018
|
+
error: messagesError,
|
|
21019
|
+
refetch: refetchMessages
|
|
20067
21020
|
} = useMessages(threadId);
|
|
20068
21021
|
const hostBg = applyHostBackgroundOverride ? "chat-main" : "";
|
|
20069
21022
|
const scrollToBottom = useCallback((behavior = "auto") => {
|
|
@@ -20142,10 +21095,23 @@ function MessageList({
|
|
|
20142
21095
|
messagesError && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-destructive", children: [
|
|
20143
21096
|
/* @__PURE__ */ jsx(AlertTriangle, { className: "h-4 w-4" }),
|
|
20144
21097
|
/* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: "Failed to load messages" })
|
|
20145
|
-
] })
|
|
21098
|
+
] }),
|
|
21099
|
+
/* @__PURE__ */ jsx(
|
|
21100
|
+
Button,
|
|
21101
|
+
{
|
|
21102
|
+
size: "sm",
|
|
21103
|
+
variant: "outline",
|
|
21104
|
+
onClick: () => {
|
|
21105
|
+
if (threadError) void refetchThread();
|
|
21106
|
+
if (messagesError) void refetchMessages();
|
|
21107
|
+
},
|
|
21108
|
+
children: "Try again"
|
|
21109
|
+
}
|
|
21110
|
+
)
|
|
20146
21111
|
] }) });
|
|
20147
21112
|
}
|
|
20148
21113
|
if (safeMessages.length === 0 && !hadMessagesBefore) {
|
|
21114
|
+
const descriptionParagraphs = (activeWorkspace?.summary ?? "").split(/\n+/).map((paragraph2) => paragraph2.trim()).filter(Boolean);
|
|
20149
21115
|
return (
|
|
20150
21116
|
// A new thread opens the way the design does: the greeting and the
|
|
20151
21117
|
// composer travel together as one narrower block centred in the canvas.
|
|
@@ -20158,6 +21124,14 @@ function MessageList({
|
|
|
20158
21124
|
"data-ss-layer": "message-list",
|
|
20159
21125
|
children: /* @__PURE__ */ jsxs("div", { className: "mx-auto mb-6 w-full max-w-2xl px-4 text-center", children: [
|
|
20160
21126
|
/* @__PURE__ */ jsx("h2", { className: "text-2xl font-semibold text-foreground", children: "What\u2019s on the agenda today?" }),
|
|
21127
|
+
descriptionParagraphs.length > 0 && /* @__PURE__ */ jsx(
|
|
21128
|
+
"div",
|
|
21129
|
+
{
|
|
21130
|
+
className: "mx-auto mt-2 max-w-lg space-y-1.5 text-sm text-muted-foreground",
|
|
21131
|
+
"data-ss-layer": "workspace-description",
|
|
21132
|
+
children: descriptionParagraphs.map((paragraph2, index) => /* @__PURE__ */ jsx("p", { children: paragraph2 }, index))
|
|
21133
|
+
}
|
|
21134
|
+
),
|
|
20161
21135
|
activeWorkspace?.firstPrompt && /* @__PURE__ */ jsx("div", { className: "chat-prose mt-3 text-center", children: /* @__PURE__ */ jsx(MessageMarkdown, { value: activeWorkspace.firstPrompt }) })
|
|
20162
21136
|
] })
|
|
20163
21137
|
}
|
|
@@ -20276,6 +21250,11 @@ function MessageListSkeleton() {
|
|
|
20276
21250
|
i
|
|
20277
21251
|
)) });
|
|
20278
21252
|
}
|
|
21253
|
+
|
|
21254
|
+
// src/shared/utils/enums.ts
|
|
21255
|
+
var isMember = (e, value) => Object.values(e).includes(value);
|
|
21256
|
+
|
|
21257
|
+
// src/domains/messages/mapper.ts
|
|
20279
21258
|
var {
|
|
20280
21259
|
messageThreadsThreadMessagesIdMessagesResponse: messagesResponseSchema
|
|
20281
21260
|
} = ChatZod;
|
|
@@ -20302,6 +21281,7 @@ function mapMessageValueDtoToModel(dto) {
|
|
|
20302
21281
|
createdByUserId: dto.createdByUserId ?? void 0
|
|
20303
21282
|
};
|
|
20304
21283
|
}
|
|
21284
|
+
var mapMessageValuesDtoToModels = (dtos) => dtos.filter((dto) => isMember(MessageValueType, dto.type)).map(mapMessageValueDtoToModel);
|
|
20305
21285
|
function mapMessageErrorDtoToModel(dto) {
|
|
20306
21286
|
const { error_code, ...rest } = dto;
|
|
20307
21287
|
return {
|
|
@@ -20319,7 +21299,7 @@ function mapMessageDtoToModel(dto) {
|
|
|
20319
21299
|
createdByUserId: dto.createdByUserId ?? void 0,
|
|
20320
21300
|
messageThreadId: dto.messageThreadId ?? void 0,
|
|
20321
21301
|
errors: dto.errors?.map(mapMessageErrorDtoToModel) ?? void 0,
|
|
20322
|
-
values: dto.values
|
|
21302
|
+
values: dto.values && mapMessageValuesDtoToModels(dto.values)
|
|
20323
21303
|
};
|
|
20324
21304
|
}
|
|
20325
21305
|
function mapMessagesDtoToModels(dto) {
|
|
@@ -20435,8 +21415,7 @@ var mapWorkspacesDtoToModels = (arr) => arr.map(mapWorkspaceDtoToModel);
|
|
|
20435
21415
|
function getChatApiBaseUrl() {
|
|
20436
21416
|
try {
|
|
20437
21417
|
const w = window;
|
|
20438
|
-
const
|
|
20439
|
-
const cfg = w?.ssconfig?.Chat_Api_Uri ?? env2?.VITE_CHAT_API_URI;
|
|
21418
|
+
const cfg = w?.ssconfig?.Chat_Api_Uri;
|
|
20440
21419
|
return typeof cfg === "string" && cfg.trim() ? cfg.trim() : "";
|
|
20441
21420
|
} catch {
|
|
20442
21421
|
return "";
|
|
@@ -20449,6 +21428,6 @@ function getUserPhotoUrl(userId) {
|
|
|
20449
21428
|
return `${base2}/users/${userId}/photo`;
|
|
20450
21429
|
}
|
|
20451
21430
|
|
|
20452
|
-
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 };
|
|
21431
|
+
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 };
|
|
20453
21432
|
//# sourceMappingURL=index.js.map
|
|
20454
21433
|
//# sourceMappingURL=index.js.map
|