@djangocfg/ui-tools 2.1.334 → 2.1.336
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -2
- package/dist/ChatRoot-IIYQEWUU.mjs +5 -0
- package/dist/ChatRoot-IIYQEWUU.mjs.map +1 -0
- package/dist/ChatRoot-PNNGQCYF.css +7 -0
- package/dist/ChatRoot-PNNGQCYF.css.map +1 -0
- package/dist/ChatRoot-UUKTYM4N.cjs +14 -0
- package/dist/ChatRoot-UUKTYM4N.cjs.map +1 -0
- package/dist/{CronScheduler.client-3O3VU4CI.mjs → CronScheduler.client-DLMXCPAJ.mjs} +4 -4
- package/dist/{CronScheduler.client-3O3VU4CI.mjs.map → CronScheduler.client-DLMXCPAJ.mjs.map} +1 -1
- package/dist/{CronScheduler.client-A4GO6YBY.cjs → CronScheduler.client-WEJF4PWQ.cjs} +14 -14
- package/dist/{CronScheduler.client-A4GO6YBY.cjs.map → CronScheduler.client-WEJF4PWQ.cjs.map} +1 -1
- package/dist/{DocsLayout-XLDB6CJ2.cjs → DocsLayout-N5ZJZPBY.cjs} +200 -199
- package/dist/DocsLayout-N5ZJZPBY.cjs.map +1 -0
- package/dist/{DocsLayout-CTJINVBM.mjs → DocsLayout-VFPPNKSQ.mjs} +7 -6
- package/dist/DocsLayout-VFPPNKSQ.mjs.map +1 -0
- package/dist/JsonSchemaForm-DD7CLRIG.cjs +13 -0
- package/dist/{JsonSchemaForm-OSPUUUHM.cjs.map → JsonSchemaForm-DD7CLRIG.cjs.map} +1 -1
- package/dist/JsonSchemaForm-XKUIVELK.mjs +4 -0
- package/dist/{JsonSchemaForm-TSLX2GRO.mjs.map → JsonSchemaForm-XKUIVELK.mjs.map} +1 -1
- package/dist/JsonTree-55625VVH.mjs +5 -0
- package/dist/{JsonTree-F27RMYSI.cjs.map → JsonTree-55625VVH.mjs.map} +1 -1
- package/dist/JsonTree-DCM5QGWF.cjs +11 -0
- package/dist/{JsonTree-QTJYSHCV.mjs.map → JsonTree-DCM5QGWF.cjs.map} +1 -1
- package/dist/{LottiePlayer.client-6WVWDO75.cjs → LottiePlayer.client-2S7ISJ2S.cjs} +6 -6
- package/dist/{LottiePlayer.client-6WVWDO75.cjs.map → LottiePlayer.client-2S7ISJ2S.cjs.map} +1 -1
- package/dist/{LottiePlayer.client-B4I6WNZM.mjs → LottiePlayer.client-5LDSSJWS.mjs} +4 -4
- package/dist/{LottiePlayer.client-B4I6WNZM.mjs.map → LottiePlayer.client-5LDSSJWS.mjs.map} +1 -1
- package/dist/{MapContainer-RYG4HPH4.cjs → MapContainer-76YL2JXL.cjs} +8 -8
- package/dist/{MapContainer-RYG4HPH4.cjs.map → MapContainer-76YL2JXL.cjs.map} +1 -1
- package/dist/{MapContainer-GXQLP5WY.mjs → MapContainer-7HXBI3OH.mjs} +3 -3
- package/dist/{MapContainer-GXQLP5WY.mjs.map → MapContainer-7HXBI3OH.mjs.map} +1 -1
- package/dist/{Mermaid.client-SXRRI2YW.mjs → Mermaid.client-NL4SVR7F.mjs} +4 -4
- package/dist/{Mermaid.client-SXRRI2YW.mjs.map → Mermaid.client-NL4SVR7F.mjs.map} +1 -1
- package/dist/{Mermaid.client-W76R5AKJ.cjs → Mermaid.client-NNTI6DFX.cjs} +26 -26
- package/dist/{Mermaid.client-W76R5AKJ.cjs.map → Mermaid.client-NNTI6DFX.cjs.map} +1 -1
- package/dist/Player-BRV7XTWR.mjs +4 -0
- package/dist/{Player-M3GC3VPE.mjs.map → Player-BRV7XTWR.mjs.map} +1 -1
- package/dist/Player-PM7F7DD7.cjs +13 -0
- package/dist/{Player-ZL2X5LGG.cjs.map → Player-PM7F7DD7.cjs.map} +1 -1
- package/dist/{PrettyCode.client-RPDIE5CH.cjs → PrettyCode.client-KOHDVPPN.cjs} +13 -13
- package/dist/{PrettyCode.client-RPDIE5CH.cjs.map → PrettyCode.client-KOHDVPPN.cjs.map} +1 -1
- package/dist/{PrettyCode.client-SPMTQEG4.mjs → PrettyCode.client-ZGYGKE7G.mjs} +4 -4
- package/dist/{PrettyCode.client-SPMTQEG4.mjs.map → PrettyCode.client-ZGYGKE7G.mjs.map} +1 -1
- package/dist/TreeRoot-N72OYKXU.cjs +19 -0
- package/dist/{TreeRoot-A3J65L6F.mjs.map → TreeRoot-N72OYKXU.cjs.map} +1 -1
- package/dist/TreeRoot-VGAIXCUA.mjs +4 -0
- package/dist/{TreeRoot-DSK5JILT.cjs.map → TreeRoot-VGAIXCUA.mjs.map} +1 -1
- package/dist/chunk-2ZLKZ5VR.mjs +631 -0
- package/dist/chunk-2ZLKZ5VR.mjs.map +1 -0
- package/dist/{chunk-LFWQ36LJ.mjs → chunk-5G5YBFS6.mjs} +4 -4
- package/dist/{chunk-LFWQ36LJ.mjs.map → chunk-5G5YBFS6.mjs.map} +1 -1
- package/dist/{chunk-IHAY6FO6.cjs → chunk-5I5QNGUG.cjs} +17 -17
- package/dist/{chunk-IHAY6FO6.cjs.map → chunk-5I5QNGUG.cjs.map} +1 -1
- package/dist/{chunk-F2CMIIOH.cjs → chunk-76NNDZH6.cjs} +42 -42
- package/dist/{chunk-F2CMIIOH.cjs.map → chunk-76NNDZH6.cjs.map} +1 -1
- package/dist/chunk-B5AWZOHJ.cjs +649 -0
- package/dist/chunk-B5AWZOHJ.cjs.map +1 -0
- package/dist/{chunk-KR6B3LVY.mjs → chunk-B6IR5KSC.mjs} +3 -3
- package/dist/{chunk-KR6B3LVY.mjs.map → chunk-B6IR5KSC.mjs.map} +1 -1
- package/dist/{chunk-5LBDYFWH.mjs → chunk-C6GXVH5J.mjs} +3 -3
- package/dist/{chunk-5LBDYFWH.mjs.map → chunk-C6GXVH5J.mjs.map} +1 -1
- package/dist/{chunk-4IW7GZFQ.cjs → chunk-FEN5S772.cjs} +74 -48
- package/dist/chunk-FEN5S772.cjs.map +1 -0
- package/dist/{chunk-2SMCH62O.cjs → chunk-FP2RLYQZ.cjs} +11 -11
- package/dist/{chunk-2SMCH62O.cjs.map → chunk-FP2RLYQZ.cjs.map} +1 -1
- package/dist/{chunk-MOME6KYD.mjs → chunk-G5IEC7SR.mjs} +3 -3
- package/dist/{chunk-MOME6KYD.mjs.map → chunk-G5IEC7SR.mjs.map} +1 -1
- package/dist/{chunk-EXGXUK2N.mjs → chunk-GYIO7W7M.mjs} +41 -15
- package/dist/chunk-GYIO7W7M.mjs.map +1 -0
- package/dist/{chunk-3Z3A7FHA.cjs → chunk-IEEAENLX.cjs} +48 -48
- package/dist/{chunk-3Z3A7FHA.cjs.map → chunk-IEEAENLX.cjs.map} +1 -1
- package/dist/{chunk-DFTVB66S.cjs → chunk-KNDLV4PI.cjs} +85 -85
- package/dist/{chunk-DFTVB66S.cjs.map → chunk-KNDLV4PI.cjs.map} +1 -1
- package/dist/{chunk-SSUOENAZ.mjs → chunk-KNEQRUBA.mjs} +3 -3
- package/dist/{chunk-SSUOENAZ.mjs.map → chunk-KNEQRUBA.mjs.map} +1 -1
- package/dist/chunk-KRETIZU6.mjs +2218 -0
- package/dist/chunk-KRETIZU6.mjs.map +1 -0
- package/dist/{chunk-CGILA3WO.mjs → chunk-N2XQF2OL.mjs} +5 -3
- package/dist/{chunk-CGILA3WO.mjs.map → chunk-N2XQF2OL.mjs.map} +1 -1
- package/dist/{chunk-EUADAUBQ.mjs → chunk-N4MZYNR4.mjs} +4 -4
- package/dist/{chunk-EUADAUBQ.mjs.map → chunk-N4MZYNR4.mjs.map} +1 -1
- package/dist/chunk-NRXYYO5V.cjs +2257 -0
- package/dist/chunk-NRXYYO5V.cjs.map +1 -0
- package/dist/{chunk-GGKGH5PM.mjs → chunk-OBRSGM64.mjs} +4 -4
- package/dist/{chunk-GGKGH5PM.mjs.map → chunk-OBRSGM64.mjs.map} +1 -1
- package/dist/{chunk-6JTB2X72.mjs → chunk-ODO4GMW7.mjs} +3 -3
- package/dist/{chunk-6JTB2X72.mjs.map → chunk-ODO4GMW7.mjs.map} +1 -1
- package/dist/{chunk-WGEGR3DF.cjs → chunk-OLISEQHS.cjs} +5 -2
- package/dist/{chunk-WGEGR3DF.cjs.map → chunk-OLISEQHS.cjs.map} +1 -1
- package/dist/{chunk-PZKAH7WQ.mjs → chunk-PVAX67JG.mjs} +3 -3
- package/dist/{chunk-PZKAH7WQ.mjs.map → chunk-PVAX67JG.mjs.map} +1 -1
- package/dist/{chunk-PRPG2T2E.cjs → chunk-QJ6GTUCO.cjs} +6 -6
- package/dist/{chunk-PRPG2T2E.cjs.map → chunk-QJ6GTUCO.cjs.map} +1 -1
- package/dist/chunk-QW4RBGHN.cjs +961 -0
- package/dist/chunk-QW4RBGHN.cjs.map +1 -0
- package/dist/{chunk-33AMWFBZ.cjs → chunk-SGP7V2UW.cjs} +15 -15
- package/dist/{chunk-33AMWFBZ.cjs.map → chunk-SGP7V2UW.cjs.map} +1 -1
- package/dist/{chunk-FX2QFYWF.mjs → chunk-VWQ5WOIL.mjs} +3 -3
- package/dist/{chunk-FX2QFYWF.mjs.map → chunk-VWQ5WOIL.mjs.map} +1 -1
- package/dist/{chunk-ZLQHUZDU.cjs → chunk-YDPDTOSP.cjs} +139 -139
- package/dist/{chunk-ZLQHUZDU.cjs.map → chunk-YDPDTOSP.cjs.map} +1 -1
- package/dist/{chunk-77HQWEQ6.cjs → chunk-YW5IVWHQ.cjs} +33 -33
- package/dist/{chunk-77HQWEQ6.cjs.map → chunk-YW5IVWHQ.cjs.map} +1 -1
- package/dist/{chunk-YXBOAGIM.cjs → chunk-YXZ6GU7H.cjs} +7 -7
- package/dist/{chunk-YXBOAGIM.cjs.map → chunk-YXZ6GU7H.cjs.map} +1 -1
- package/dist/{chunk-62Y65TGK.mjs → chunk-ZUFTH5IR.mjs} +8 -631
- package/dist/chunk-ZUFTH5IR.mjs.map +1 -0
- package/dist/components-EHOGXATG.cjs +22 -0
- package/dist/{components-5UXYNAKR.cjs.map → components-EHOGXATG.cjs.map} +1 -1
- package/dist/components-MQ6DR7TX.cjs +26 -0
- package/dist/{components-CFXOEVPN.mjs.map → components-MQ6DR7TX.cjs.map} +1 -1
- package/dist/components-XRX7QGLB.mjs +5 -0
- package/dist/{components-WYEZL5TE.cjs.map → components-XRX7QGLB.mjs.map} +1 -1
- package/dist/components-YATKRWLH.mjs +5 -0
- package/dist/{components-ZAGG2PBO.mjs.map → components-YATKRWLH.mjs.map} +1 -1
- package/dist/file-icon/index.cjs +6 -6
- package/dist/file-icon/index.mjs +1 -1
- package/dist/index.cjs +735 -215
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +972 -39
- package/dist/index.d.ts +972 -39
- package/dist/index.mjs +387 -31
- package/dist/index.mjs.map +1 -1
- package/dist/tree/index.cjs +38 -38
- package/dist/tree/index.d.cts +2 -2
- package/dist/tree/index.d.ts +2 -2
- package/dist/tree/index.mjs +3 -3
- package/package.json +6 -6
- package/src/index.ts +5 -0
- package/src/stories/index.ts +3 -1
- package/src/tools/Chat/Chat.story.tsx +1006 -0
- package/src/tools/Chat/README.md +528 -0
- package/src/tools/Chat/components/Attachments.tsx +192 -0
- package/src/tools/Chat/components/ChatRoot.tsx +201 -0
- package/src/tools/Chat/components/Composer.tsx +134 -0
- package/src/tools/Chat/components/EmptyState.tsx +47 -0
- package/src/tools/Chat/components/ErrorBanner.tsx +47 -0
- package/src/tools/Chat/components/JumpToLatest.tsx +30 -0
- package/src/tools/Chat/components/MessageActions.tsx +72 -0
- package/src/tools/Chat/components/MessageBubble.tsx +228 -0
- package/src/tools/Chat/components/MessageList.tsx +82 -0
- package/src/tools/Chat/components/Sources.tsx +55 -0
- package/src/tools/Chat/components/StreamingIndicator.tsx +29 -0
- package/src/tools/Chat/components/ToolCalls.tsx +172 -0
- package/src/tools/Chat/components/index.ts +24 -0
- package/src/tools/Chat/config.ts +55 -0
- package/src/tools/Chat/context/ChatProvider.tsx +122 -0
- package/src/tools/Chat/context/index.ts +9 -0
- package/src/tools/Chat/core/audio/audioBus.ts +172 -0
- package/src/tools/Chat/core/audio/index.ts +8 -0
- package/src/tools/Chat/core/audio/preferences.ts +68 -0
- package/src/tools/Chat/core/audio/types.ts +49 -0
- package/src/tools/Chat/core/ids.ts +16 -0
- package/src/tools/Chat/core/index.ts +5 -0
- package/src/tools/Chat/core/markdown.ts +56 -0
- package/src/tools/Chat/core/payload-dispatch.ts +54 -0
- package/src/tools/Chat/core/persona.ts +35 -0
- package/src/tools/Chat/core/reducer.ts +335 -0
- package/src/tools/Chat/core/transport/http.ts +167 -0
- package/src/tools/Chat/core/transport/index.ts +13 -0
- package/src/tools/Chat/core/transport/mock.ts +134 -0
- package/src/tools/Chat/core/transport/sse.ts +116 -0
- package/src/tools/Chat/core/transport/types.ts +24 -0
- package/src/tools/Chat/hooks/index.ts +26 -0
- package/src/tools/Chat/hooks/useChat.ts +440 -0
- package/src/tools/Chat/hooks/useChatAudio.ts +191 -0
- package/src/tools/Chat/hooks/useChatComposer.ts +227 -0
- package/src/tools/Chat/hooks/useChatHistory.ts +59 -0
- package/src/tools/Chat/hooks/useChatLayout.ts +111 -0
- package/src/tools/Chat/hooks/useChatLightbox.ts +34 -0
- package/src/tools/Chat/hooks/useChatScroll.ts +132 -0
- package/src/tools/Chat/index.ts +158 -0
- package/src/tools/Chat/lazy.tsx +14 -0
- package/src/tools/Chat/types.ts +237 -0
- package/src/tools/Chat/utils/collectImageAttachments.ts +13 -0
- package/src/tools/JsonForm/JsonSchemaForm.tsx +32 -1
- package/src/tools/Map/README.md +384 -0
- package/dist/DocsLayout-CTJINVBM.mjs.map +0 -1
- package/dist/DocsLayout-XLDB6CJ2.cjs.map +0 -1
- package/dist/JsonSchemaForm-OSPUUUHM.cjs +0 -13
- package/dist/JsonSchemaForm-TSLX2GRO.mjs +0 -4
- package/dist/JsonTree-F27RMYSI.cjs +0 -11
- package/dist/JsonTree-QTJYSHCV.mjs +0 -5
- package/dist/Player-M3GC3VPE.mjs +0 -4
- package/dist/Player-ZL2X5LGG.cjs +0 -13
- package/dist/TreeRoot-A3J65L6F.mjs +0 -4
- package/dist/TreeRoot-DSK5JILT.cjs +0 -19
- package/dist/chunk-4IW7GZFQ.cjs.map +0 -1
- package/dist/chunk-62Y65TGK.mjs.map +0 -1
- package/dist/chunk-EXGXUK2N.mjs.map +0 -1
- package/dist/chunk-TKSFZHCG.cjs +0 -1597
- package/dist/chunk-TKSFZHCG.cjs.map +0 -1
- package/dist/components-5UXYNAKR.cjs +0 -22
- package/dist/components-CFXOEVPN.mjs +0 -5
- package/dist/components-WYEZL5TE.cjs +0 -26
- package/dist/components-ZAGG2PBO.mjs +0 -5
|
@@ -0,0 +1,2257 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkB5AWZOHJ_cjs = require('./chunk-B5AWZOHJ.cjs');
|
|
4
|
+
var chunkOLISEQHS_cjs = require('./chunk-OLISEQHS.cjs');
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var lib = require('@djangocfg/ui-core/lib');
|
|
7
|
+
var hooks = require('@djangocfg/ui-core/hooks');
|
|
8
|
+
var zustand = require('zustand');
|
|
9
|
+
var middleware = require('zustand/middleware');
|
|
10
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
11
|
+
var lucideReact = require('lucide-react');
|
|
12
|
+
var components = require('@djangocfg/ui-core/components');
|
|
13
|
+
|
|
14
|
+
// src/tools/Chat/types.ts
|
|
15
|
+
var DEFAULT_LABELS = {
|
|
16
|
+
send: "Send",
|
|
17
|
+
cancel: "Stop",
|
|
18
|
+
copy: "Copy",
|
|
19
|
+
regenerate: "Regenerate",
|
|
20
|
+
edit: "Edit",
|
|
21
|
+
delete: "Delete",
|
|
22
|
+
retry: "Retry",
|
|
23
|
+
newChat: "New chat",
|
|
24
|
+
loadMore: "Load more",
|
|
25
|
+
jumpToLatest: "Jump to latest",
|
|
26
|
+
attach: "Attach files",
|
|
27
|
+
voice: "Voice input",
|
|
28
|
+
errorGeneric: "Something went wrong",
|
|
29
|
+
cancelledSuffix: "[cancelled]"
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// src/tools/Chat/config.ts
|
|
33
|
+
var STORAGE_KEYS = {
|
|
34
|
+
mode: "djc-chat-mode",
|
|
35
|
+
sidebarWidth: "djc-chat-sidebar-width",
|
|
36
|
+
composerHistory: "djc-chat-composer-history"
|
|
37
|
+
};
|
|
38
|
+
var CSS_VARS = {
|
|
39
|
+
reserve: "--djc-chat-reserve"
|
|
40
|
+
};
|
|
41
|
+
var DEFAULT_Z_INDEX = 9e3;
|
|
42
|
+
var LIMITS = {
|
|
43
|
+
/** Max characters per single message. */
|
|
44
|
+
messageMaxLength: 8e3,
|
|
45
|
+
/** Max attachments per message. */
|
|
46
|
+
attachmentsMax: 10,
|
|
47
|
+
/** Composer history slots. */
|
|
48
|
+
composerHistorySize: 50,
|
|
49
|
+
/** Coalesce stream tokens within this window before dispatching. */
|
|
50
|
+
streamCoalesceMs: 16,
|
|
51
|
+
/** Default history page size. */
|
|
52
|
+
pageSize: 50,
|
|
53
|
+
/** Virtualize list when >= this many messages (host-controlled threshold). */
|
|
54
|
+
virtualizeThreshold: 50,
|
|
55
|
+
/** SSE idle timeout. */
|
|
56
|
+
sseIdleMs: 45e3
|
|
57
|
+
};
|
|
58
|
+
var DEFAULT_SIDEBAR = {
|
|
59
|
+
width: 420,
|
|
60
|
+
min: 320,
|
|
61
|
+
max: 720
|
|
62
|
+
};
|
|
63
|
+
var HOTKEYS = {
|
|
64
|
+
send: "mod+enter",
|
|
65
|
+
cancel: "esc",
|
|
66
|
+
newChat: "mod+shift+n",
|
|
67
|
+
toggleOpen: "mod+/",
|
|
68
|
+
focusComposer: "mod+l"
|
|
69
|
+
};
|
|
70
|
+
var CHAT_EVENT_NAME = "djc:chat:send";
|
|
71
|
+
|
|
72
|
+
// src/tools/Chat/core/reducer.ts
|
|
73
|
+
var initialState = {
|
|
74
|
+
sessionId: null,
|
|
75
|
+
messages: [],
|
|
76
|
+
isLoading: false,
|
|
77
|
+
isStreaming: false,
|
|
78
|
+
isLoadingMore: false,
|
|
79
|
+
hasMore: true,
|
|
80
|
+
oldestCursor: null,
|
|
81
|
+
error: null
|
|
82
|
+
};
|
|
83
|
+
function updateLastStreaming(messages, patch) {
|
|
84
|
+
const idx = findLastStreamingIndex(messages);
|
|
85
|
+
if (idx === -1) return messages;
|
|
86
|
+
const next = messages.slice();
|
|
87
|
+
next[idx] = patch(messages[idx]);
|
|
88
|
+
return next;
|
|
89
|
+
}
|
|
90
|
+
chunkOLISEQHS_cjs.__name(updateLastStreaming, "updateLastStreaming");
|
|
91
|
+
function findLastStreamingIndex(messages) {
|
|
92
|
+
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
93
|
+
if (messages[i].isStreaming) return i;
|
|
94
|
+
}
|
|
95
|
+
return -1;
|
|
96
|
+
}
|
|
97
|
+
chunkOLISEQHS_cjs.__name(findLastStreamingIndex, "findLastStreamingIndex");
|
|
98
|
+
function patchMessageById(messages, id, patch) {
|
|
99
|
+
const idx = messages.findIndex((m) => m.id === id);
|
|
100
|
+
if (idx === -1) return messages;
|
|
101
|
+
const next = messages.slice();
|
|
102
|
+
next[idx] = patch(messages[idx]);
|
|
103
|
+
return next;
|
|
104
|
+
}
|
|
105
|
+
chunkOLISEQHS_cjs.__name(patchMessageById, "patchMessageById");
|
|
106
|
+
function reducer(state, action) {
|
|
107
|
+
switch (action.type) {
|
|
108
|
+
case "SESSION_SET":
|
|
109
|
+
return {
|
|
110
|
+
...state,
|
|
111
|
+
sessionId: action.sessionId,
|
|
112
|
+
messages: action.messages ?? state.messages,
|
|
113
|
+
hasMore: action.hasMore ?? state.hasMore,
|
|
114
|
+
oldestCursor: action.cursor ?? state.oldestCursor,
|
|
115
|
+
error: null
|
|
116
|
+
};
|
|
117
|
+
case "HISTORY_LOAD_START":
|
|
118
|
+
return { ...state, isLoading: true, error: null };
|
|
119
|
+
case "HISTORY_LOAD_DONE":
|
|
120
|
+
return {
|
|
121
|
+
...state,
|
|
122
|
+
isLoading: false,
|
|
123
|
+
messages: action.messages,
|
|
124
|
+
hasMore: action.hasMore,
|
|
125
|
+
oldestCursor: action.cursor
|
|
126
|
+
};
|
|
127
|
+
case "HISTORY_MORE_START":
|
|
128
|
+
return { ...state, isLoadingMore: true };
|
|
129
|
+
case "HISTORY_MORE_DONE":
|
|
130
|
+
return {
|
|
131
|
+
...state,
|
|
132
|
+
isLoadingMore: false,
|
|
133
|
+
// Older messages prepend to the top.
|
|
134
|
+
messages: [...action.messages, ...state.messages],
|
|
135
|
+
hasMore: action.hasMore,
|
|
136
|
+
oldestCursor: action.cursor
|
|
137
|
+
};
|
|
138
|
+
case "MESSAGE_USER_ADD":
|
|
139
|
+
return {
|
|
140
|
+
...state,
|
|
141
|
+
messages: [...state.messages, action.message],
|
|
142
|
+
error: null
|
|
143
|
+
};
|
|
144
|
+
case "STREAM_START": {
|
|
145
|
+
if (state.isStreaming) {
|
|
146
|
+
if (typeof console !== "undefined") {
|
|
147
|
+
console.warn("[chat] STREAM_START while already streaming, ignoring");
|
|
148
|
+
}
|
|
149
|
+
return state;
|
|
150
|
+
}
|
|
151
|
+
const placeholder = {
|
|
152
|
+
id: action.id,
|
|
153
|
+
role: "assistant",
|
|
154
|
+
content: "",
|
|
155
|
+
createdAt: action.createdAt ?? Date.now(),
|
|
156
|
+
isStreaming: true
|
|
157
|
+
};
|
|
158
|
+
return {
|
|
159
|
+
...state,
|
|
160
|
+
isStreaming: true,
|
|
161
|
+
messages: [...state.messages, placeholder]
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
case "STREAM_CHUNK": {
|
|
165
|
+
const messages = updateLastStreaming(state.messages, (m) => ({
|
|
166
|
+
...m,
|
|
167
|
+
content: m.content + action.delta
|
|
168
|
+
}));
|
|
169
|
+
return { ...state, messages };
|
|
170
|
+
}
|
|
171
|
+
case "STREAM_TOOL_ACTIVITY": {
|
|
172
|
+
const messages = updateLastStreaming(state.messages, (m) => ({
|
|
173
|
+
...m,
|
|
174
|
+
toolActivity: action.tool
|
|
175
|
+
}));
|
|
176
|
+
return { ...state, messages };
|
|
177
|
+
}
|
|
178
|
+
case "TOOL_CALL_START": {
|
|
179
|
+
const messages = patchMessageById(state.messages, action.messageId, (m) => ({
|
|
180
|
+
...m,
|
|
181
|
+
toolCalls: [...m.toolCalls ?? [], action.toolCall]
|
|
182
|
+
}));
|
|
183
|
+
return { ...state, messages };
|
|
184
|
+
}
|
|
185
|
+
case "TOOL_CALL_DELTA": {
|
|
186
|
+
const messages = patchMessageById(state.messages, action.messageId, (m) => {
|
|
187
|
+
if (!m.toolCalls) return m;
|
|
188
|
+
return {
|
|
189
|
+
...m,
|
|
190
|
+
toolCalls: m.toolCalls.map(
|
|
191
|
+
(tc) => tc.id === action.toolId ? { ...tc, streamingText: (tc.streamingText ?? "") + action.delta } : tc
|
|
192
|
+
)
|
|
193
|
+
};
|
|
194
|
+
});
|
|
195
|
+
return { ...state, messages };
|
|
196
|
+
}
|
|
197
|
+
case "TOOL_CALL_END": {
|
|
198
|
+
const messages = patchMessageById(state.messages, action.messageId, (m) => {
|
|
199
|
+
if (!m.toolCalls) return m;
|
|
200
|
+
return {
|
|
201
|
+
...m,
|
|
202
|
+
toolCalls: m.toolCalls.map(
|
|
203
|
+
(tc) => tc.id === action.toolId ? {
|
|
204
|
+
...tc,
|
|
205
|
+
output: action.output,
|
|
206
|
+
status: action.status,
|
|
207
|
+
streamingText: void 0,
|
|
208
|
+
endedAt: Date.now()
|
|
209
|
+
} : tc
|
|
210
|
+
)
|
|
211
|
+
};
|
|
212
|
+
});
|
|
213
|
+
return { ...state, messages };
|
|
214
|
+
}
|
|
215
|
+
case "STREAM_DONE": {
|
|
216
|
+
const messages = patchMessageById(state.messages, action.id, (m) => ({
|
|
217
|
+
...m,
|
|
218
|
+
isStreaming: false,
|
|
219
|
+
tokensIn: action.tokensIn ?? m.tokensIn,
|
|
220
|
+
tokensOut: action.tokensOut ?? m.tokensOut,
|
|
221
|
+
sources: action.sources ?? m.sources
|
|
222
|
+
}));
|
|
223
|
+
return { ...state, isStreaming: false, messages };
|
|
224
|
+
}
|
|
225
|
+
case "STREAM_CANCELLED": {
|
|
226
|
+
const suffix = action.label ?? "[cancelled]";
|
|
227
|
+
const messages = patchMessageById(state.messages, action.id, (m) => ({
|
|
228
|
+
...m,
|
|
229
|
+
isStreaming: false,
|
|
230
|
+
content: action.partialText + (action.partialText ? `
|
|
231
|
+
|
|
232
|
+
_${suffix}_` : `_${suffix}_`)
|
|
233
|
+
}));
|
|
234
|
+
return { ...state, isStreaming: false, messages };
|
|
235
|
+
}
|
|
236
|
+
case "STREAM_ERROR": {
|
|
237
|
+
const messages = action.id ? patchMessageById(state.messages, action.id, (m) => ({
|
|
238
|
+
...m,
|
|
239
|
+
isStreaming: false,
|
|
240
|
+
isError: true
|
|
241
|
+
})) : state.messages;
|
|
242
|
+
return { ...state, isStreaming: false, error: action.message, messages };
|
|
243
|
+
}
|
|
244
|
+
case "MESSAGE_EDIT": {
|
|
245
|
+
const messages = patchMessageById(state.messages, action.id, (m) => ({
|
|
246
|
+
...m,
|
|
247
|
+
content: action.content,
|
|
248
|
+
version: (m.version ?? 0) + 1
|
|
249
|
+
}));
|
|
250
|
+
return { ...state, messages };
|
|
251
|
+
}
|
|
252
|
+
case "MESSAGE_DELETE":
|
|
253
|
+
return {
|
|
254
|
+
...state,
|
|
255
|
+
messages: state.messages.filter((m) => m.id !== action.id)
|
|
256
|
+
};
|
|
257
|
+
case "MESSAGES_CLEAR":
|
|
258
|
+
return {
|
|
259
|
+
...state,
|
|
260
|
+
messages: [],
|
|
261
|
+
isStreaming: false,
|
|
262
|
+
error: null
|
|
263
|
+
};
|
|
264
|
+
case "ERROR_SET":
|
|
265
|
+
return { ...state, error: action.error };
|
|
266
|
+
case "ATTACHMENT_PROGRESS": {
|
|
267
|
+
const messages = patchMessageById(state.messages, action.messageId, (m) => {
|
|
268
|
+
if (!m.attachments) return m;
|
|
269
|
+
return {
|
|
270
|
+
...m,
|
|
271
|
+
attachments: m.attachments.map(
|
|
272
|
+
(a) => a.id === action.attachmentId ? {
|
|
273
|
+
...a,
|
|
274
|
+
progress: action.progress ?? a.progress,
|
|
275
|
+
status: action.status ?? a.status
|
|
276
|
+
} : a
|
|
277
|
+
)
|
|
278
|
+
};
|
|
279
|
+
});
|
|
280
|
+
return { ...state, messages };
|
|
281
|
+
}
|
|
282
|
+
default: {
|
|
283
|
+
return state;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
chunkOLISEQHS_cjs.__name(reducer, "reducer");
|
|
288
|
+
|
|
289
|
+
// src/tools/Chat/core/ids.ts
|
|
290
|
+
var counter = 0;
|
|
291
|
+
function createId(prefix = "m") {
|
|
292
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
293
|
+
return `${prefix}_${crypto.randomUUID()}`;
|
|
294
|
+
}
|
|
295
|
+
counter += 1;
|
|
296
|
+
return `${prefix}_${Date.now().toString(36)}_${counter.toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
|
|
297
|
+
}
|
|
298
|
+
chunkOLISEQHS_cjs.__name(createId, "createId");
|
|
299
|
+
|
|
300
|
+
// src/tools/Chat/core/markdown.ts
|
|
301
|
+
function createTokenBuffer(onFlush, windowMs = LIMITS.streamCoalesceMs) {
|
|
302
|
+
let pending = "";
|
|
303
|
+
let timer = null;
|
|
304
|
+
let closed = false;
|
|
305
|
+
const flush = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => {
|
|
306
|
+
if (timer) {
|
|
307
|
+
clearTimeout(timer);
|
|
308
|
+
timer = null;
|
|
309
|
+
}
|
|
310
|
+
if (pending) {
|
|
311
|
+
const out = pending;
|
|
312
|
+
pending = "";
|
|
313
|
+
onFlush(out);
|
|
314
|
+
}
|
|
315
|
+
}, "flush");
|
|
316
|
+
return {
|
|
317
|
+
push(delta) {
|
|
318
|
+
if (closed || !delta) return;
|
|
319
|
+
pending += delta;
|
|
320
|
+
if (windowMs <= 0) {
|
|
321
|
+
flush();
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (timer === null) {
|
|
325
|
+
timer = setTimeout(flush, windowMs);
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
flush,
|
|
329
|
+
close() {
|
|
330
|
+
closed = true;
|
|
331
|
+
flush();
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
chunkOLISEQHS_cjs.__name(createTokenBuffer, "createTokenBuffer");
|
|
336
|
+
|
|
337
|
+
// src/tools/Chat/hooks/useChat.ts
|
|
338
|
+
function useChat(config) {
|
|
339
|
+
const [state, dispatch] = react.useReducer(reducer, initialState);
|
|
340
|
+
const stateRef = react.useRef(state);
|
|
341
|
+
stateRef.current = state;
|
|
342
|
+
const abortRef = react.useRef(null);
|
|
343
|
+
const lastErrorRef = react.useRef(null);
|
|
344
|
+
const initRef = react.useRef(false);
|
|
345
|
+
const streamingMsgIdRef = react.useRef(null);
|
|
346
|
+
const { transport, autoCreateSession = true, streaming = true, pageSize = LIMITS.pageSize } = config;
|
|
347
|
+
react.useEffect(() => {
|
|
348
|
+
if (initRef.current) return;
|
|
349
|
+
initRef.current = true;
|
|
350
|
+
let cancelled = false;
|
|
351
|
+
const run = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(async () => {
|
|
352
|
+
try {
|
|
353
|
+
if (config.initialSessionId) {
|
|
354
|
+
dispatch({
|
|
355
|
+
type: "SESSION_SET",
|
|
356
|
+
sessionId: config.initialSessionId
|
|
357
|
+
});
|
|
358
|
+
dispatch({ type: "HISTORY_LOAD_START" });
|
|
359
|
+
const page = await transport.loadHistory(config.initialSessionId, null, pageSize);
|
|
360
|
+
if (cancelled) return;
|
|
361
|
+
dispatch({
|
|
362
|
+
type: "HISTORY_LOAD_DONE",
|
|
363
|
+
messages: page.messages,
|
|
364
|
+
hasMore: page.hasMore,
|
|
365
|
+
cursor: page.nextCursor
|
|
366
|
+
});
|
|
367
|
+
} else if (autoCreateSession) {
|
|
368
|
+
const info = await transport.createSession({ metadata: config.metadata });
|
|
369
|
+
if (cancelled) return;
|
|
370
|
+
dispatch({
|
|
371
|
+
type: "SESSION_SET",
|
|
372
|
+
sessionId: info.sessionId,
|
|
373
|
+
messages: info.messages ?? [],
|
|
374
|
+
hasMore: info.hasMore ?? false,
|
|
375
|
+
cursor: info.cursor ?? null
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
} catch (err) {
|
|
379
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
380
|
+
lastErrorRef.current = e;
|
|
381
|
+
dispatch({ type: "ERROR_SET", error: e.message });
|
|
382
|
+
config.onError?.(e);
|
|
383
|
+
}
|
|
384
|
+
}, "run");
|
|
385
|
+
void run();
|
|
386
|
+
return () => {
|
|
387
|
+
cancelled = true;
|
|
388
|
+
};
|
|
389
|
+
}, []);
|
|
390
|
+
const consumeStream = react.useCallback(
|
|
391
|
+
async (sessionId, content, attachments) => {
|
|
392
|
+
const ctrl = new AbortController();
|
|
393
|
+
abortRef.current = ctrl;
|
|
394
|
+
const assistantId = createId("a");
|
|
395
|
+
streamingMsgIdRef.current = assistantId;
|
|
396
|
+
dispatch({ type: "STREAM_START", id: assistantId });
|
|
397
|
+
config.onStreamStart?.(assistantId);
|
|
398
|
+
const tokenBuffer = createTokenBuffer(
|
|
399
|
+
(delta) => dispatch({ type: "STREAM_CHUNK", delta })
|
|
400
|
+
);
|
|
401
|
+
try {
|
|
402
|
+
const iterator = transport.stream(sessionId, content, {
|
|
403
|
+
signal: ctrl.signal,
|
|
404
|
+
attachments,
|
|
405
|
+
metadata: config.metadata
|
|
406
|
+
});
|
|
407
|
+
for await (const ev of iterator) {
|
|
408
|
+
if (ctrl.signal.aborted) break;
|
|
409
|
+
handleEvent(ev);
|
|
410
|
+
}
|
|
411
|
+
tokenBuffer.flush();
|
|
412
|
+
if (stateRef.current.isStreaming) {
|
|
413
|
+
dispatch({ type: "STREAM_DONE", id: assistantId });
|
|
414
|
+
}
|
|
415
|
+
const finalMsg = stateRef.current.messages.find((m) => m.id === assistantId);
|
|
416
|
+
if (finalMsg) config.onMessageEnd?.(finalMsg);
|
|
417
|
+
} catch (err) {
|
|
418
|
+
tokenBuffer.close();
|
|
419
|
+
if (ctrl.signal.aborted) {
|
|
420
|
+
const partial = stateRef.current.messages.find((m) => m.id === assistantId)?.content ?? "";
|
|
421
|
+
dispatch({ type: "STREAM_CANCELLED", id: assistantId, partialText: partial });
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
425
|
+
lastErrorRef.current = e;
|
|
426
|
+
dispatch({ type: "STREAM_ERROR", id: assistantId, message: e.message });
|
|
427
|
+
config.onError?.(e);
|
|
428
|
+
} finally {
|
|
429
|
+
tokenBuffer.close();
|
|
430
|
+
if (abortRef.current === ctrl) abortRef.current = null;
|
|
431
|
+
streamingMsgIdRef.current = null;
|
|
432
|
+
}
|
|
433
|
+
function handleEvent(ev) {
|
|
434
|
+
switch (ev.type) {
|
|
435
|
+
case "message_start":
|
|
436
|
+
ev.messageId;
|
|
437
|
+
return;
|
|
438
|
+
case "chunk":
|
|
439
|
+
tokenBuffer.push(ev.delta);
|
|
440
|
+
return;
|
|
441
|
+
case "tool_activity":
|
|
442
|
+
tokenBuffer.flush();
|
|
443
|
+
dispatch({ type: "STREAM_TOOL_ACTIVITY", tool: ev.tool });
|
|
444
|
+
return;
|
|
445
|
+
case "tool_call_start": {
|
|
446
|
+
tokenBuffer.flush();
|
|
447
|
+
const toolCall = {
|
|
448
|
+
id: ev.toolId,
|
|
449
|
+
name: ev.name,
|
|
450
|
+
input: ev.input,
|
|
451
|
+
status: "running",
|
|
452
|
+
startedAt: Date.now(),
|
|
453
|
+
sourceHostname: ev.sourceHostname
|
|
454
|
+
};
|
|
455
|
+
dispatch({
|
|
456
|
+
type: "TOOL_CALL_START",
|
|
457
|
+
messageId: assistantId,
|
|
458
|
+
toolCall
|
|
459
|
+
});
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
case "tool_call_delta":
|
|
463
|
+
dispatch({
|
|
464
|
+
type: "TOOL_CALL_DELTA",
|
|
465
|
+
messageId: assistantId,
|
|
466
|
+
toolId: ev.toolId,
|
|
467
|
+
delta: ev.delta
|
|
468
|
+
});
|
|
469
|
+
return;
|
|
470
|
+
case "tool_call_end":
|
|
471
|
+
dispatch({
|
|
472
|
+
type: "TOOL_CALL_END",
|
|
473
|
+
messageId: assistantId,
|
|
474
|
+
toolId: ev.toolId,
|
|
475
|
+
output: ev.output,
|
|
476
|
+
status: ev.status
|
|
477
|
+
});
|
|
478
|
+
return;
|
|
479
|
+
case "message_end":
|
|
480
|
+
tokenBuffer.flush();
|
|
481
|
+
dispatch({
|
|
482
|
+
type: "STREAM_DONE",
|
|
483
|
+
id: assistantId,
|
|
484
|
+
tokensIn: ev.tokensIn,
|
|
485
|
+
tokensOut: ev.tokensOut,
|
|
486
|
+
sources: ev.sources
|
|
487
|
+
});
|
|
488
|
+
return;
|
|
489
|
+
case "error":
|
|
490
|
+
tokenBuffer.flush();
|
|
491
|
+
dispatch({
|
|
492
|
+
type: "STREAM_ERROR",
|
|
493
|
+
id: assistantId,
|
|
494
|
+
message: ev.message
|
|
495
|
+
});
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
chunkOLISEQHS_cjs.__name(handleEvent, "handleEvent");
|
|
500
|
+
},
|
|
501
|
+
[transport, config]
|
|
502
|
+
);
|
|
503
|
+
const consumeBuffered = react.useCallback(
|
|
504
|
+
async (sessionId, content, attachments) => {
|
|
505
|
+
const ctrl = new AbortController();
|
|
506
|
+
abortRef.current = ctrl;
|
|
507
|
+
try {
|
|
508
|
+
const reply = await transport.send(sessionId, content, {
|
|
509
|
+
signal: ctrl.signal,
|
|
510
|
+
attachments,
|
|
511
|
+
metadata: config.metadata
|
|
512
|
+
});
|
|
513
|
+
const placeholderId = createId("a");
|
|
514
|
+
dispatch({ type: "STREAM_START", id: placeholderId });
|
|
515
|
+
config.onStreamStart?.(placeholderId);
|
|
516
|
+
dispatch({ type: "STREAM_CHUNK", delta: reply.content });
|
|
517
|
+
dispatch({ type: "STREAM_DONE", id: placeholderId });
|
|
518
|
+
config.onMessageEnd?.(reply);
|
|
519
|
+
} catch (err) {
|
|
520
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
521
|
+
lastErrorRef.current = e;
|
|
522
|
+
dispatch({ type: "STREAM_ERROR", message: e.message });
|
|
523
|
+
config.onError?.(e);
|
|
524
|
+
} finally {
|
|
525
|
+
if (abortRef.current === ctrl) abortRef.current = null;
|
|
526
|
+
}
|
|
527
|
+
},
|
|
528
|
+
[transport, config]
|
|
529
|
+
);
|
|
530
|
+
const sendMessage = react.useCallback(
|
|
531
|
+
async (content, attachments) => {
|
|
532
|
+
const sessionId = stateRef.current.sessionId;
|
|
533
|
+
if (!sessionId) {
|
|
534
|
+
const e = new Error("No active session");
|
|
535
|
+
lastErrorRef.current = e;
|
|
536
|
+
dispatch({ type: "ERROR_SET", error: e.message });
|
|
537
|
+
config.onError?.(e);
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
if (!content.trim() && !(attachments && attachments.length > 0)) return;
|
|
541
|
+
if (stateRef.current.isStreaming) return;
|
|
542
|
+
const userMsg = {
|
|
543
|
+
id: createId("u"),
|
|
544
|
+
role: "user",
|
|
545
|
+
content,
|
|
546
|
+
createdAt: Date.now(),
|
|
547
|
+
attachments,
|
|
548
|
+
sender: config.userPersona
|
|
549
|
+
};
|
|
550
|
+
dispatch({ type: "MESSAGE_USER_ADD", message: userMsg });
|
|
551
|
+
config.onMessageSent?.(userMsg);
|
|
552
|
+
if (streaming) {
|
|
553
|
+
await consumeStream(sessionId, content, attachments);
|
|
554
|
+
} else {
|
|
555
|
+
await consumeBuffered(sessionId, content, attachments);
|
|
556
|
+
}
|
|
557
|
+
},
|
|
558
|
+
[streaming, consumeStream, consumeBuffered, config]
|
|
559
|
+
);
|
|
560
|
+
const cancelStream = react.useCallback(() => {
|
|
561
|
+
abortRef.current?.abort();
|
|
562
|
+
}, []);
|
|
563
|
+
const regenerate = react.useCallback(
|
|
564
|
+
async (messageId) => {
|
|
565
|
+
const messages = stateRef.current.messages;
|
|
566
|
+
let targetUserIdx = -1;
|
|
567
|
+
if (messageId) {
|
|
568
|
+
const idx = messages.findIndex((m) => m.id === messageId);
|
|
569
|
+
if (idx !== -1) {
|
|
570
|
+
targetUserIdx = messages[idx].role === "user" ? idx : findPreviousUserIndex(messages, idx);
|
|
571
|
+
}
|
|
572
|
+
} else {
|
|
573
|
+
targetUserIdx = findLastUserIndex(messages);
|
|
574
|
+
}
|
|
575
|
+
if (targetUserIdx === -1) return;
|
|
576
|
+
const userMsg = messages[targetUserIdx];
|
|
577
|
+
for (let i = messages.length - 1; i > targetUserIdx; i -= 1) {
|
|
578
|
+
dispatch({ type: "MESSAGE_DELETE", id: messages[i].id });
|
|
579
|
+
}
|
|
580
|
+
const sessionId = stateRef.current.sessionId;
|
|
581
|
+
if (!sessionId) return;
|
|
582
|
+
if (streaming) {
|
|
583
|
+
await consumeStream(sessionId, userMsg.content, userMsg.attachments);
|
|
584
|
+
} else {
|
|
585
|
+
await consumeBuffered(sessionId, userMsg.content, userMsg.attachments);
|
|
586
|
+
}
|
|
587
|
+
},
|
|
588
|
+
[streaming, consumeStream, consumeBuffered]
|
|
589
|
+
);
|
|
590
|
+
const editMessage = react.useCallback(
|
|
591
|
+
async (id, content) => {
|
|
592
|
+
dispatch({ type: "MESSAGE_EDIT", id, content });
|
|
593
|
+
const msg = stateRef.current.messages.find((m) => m.id === id);
|
|
594
|
+
if (msg?.role === "user") {
|
|
595
|
+
await regenerate(id);
|
|
596
|
+
}
|
|
597
|
+
},
|
|
598
|
+
[regenerate]
|
|
599
|
+
);
|
|
600
|
+
const deleteMessage = react.useCallback((id) => {
|
|
601
|
+
dispatch({ type: "MESSAGE_DELETE", id });
|
|
602
|
+
}, []);
|
|
603
|
+
const clearMessages = react.useCallback(() => {
|
|
604
|
+
abortRef.current?.abort();
|
|
605
|
+
dispatch({ type: "MESSAGES_CLEAR" });
|
|
606
|
+
}, []);
|
|
607
|
+
const loadMore = react.useCallback(async () => {
|
|
608
|
+
const sessionId = stateRef.current.sessionId;
|
|
609
|
+
if (!sessionId) return;
|
|
610
|
+
if (stateRef.current.isLoadingMore || !stateRef.current.hasMore) return;
|
|
611
|
+
dispatch({ type: "HISTORY_MORE_START" });
|
|
612
|
+
try {
|
|
613
|
+
const page = await transport.loadHistory(
|
|
614
|
+
sessionId,
|
|
615
|
+
stateRef.current.oldestCursor,
|
|
616
|
+
pageSize
|
|
617
|
+
);
|
|
618
|
+
dispatch({
|
|
619
|
+
type: "HISTORY_MORE_DONE",
|
|
620
|
+
messages: page.messages,
|
|
621
|
+
hasMore: page.hasMore,
|
|
622
|
+
cursor: page.nextCursor
|
|
623
|
+
});
|
|
624
|
+
} catch (err) {
|
|
625
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
626
|
+
lastErrorRef.current = e;
|
|
627
|
+
dispatch({ type: "ERROR_SET", error: e.message });
|
|
628
|
+
config.onError?.(e);
|
|
629
|
+
}
|
|
630
|
+
}, [transport, pageSize, config]);
|
|
631
|
+
const newSession = react.useCallback(async () => {
|
|
632
|
+
abortRef.current?.abort();
|
|
633
|
+
const previous = stateRef.current.sessionId;
|
|
634
|
+
if (previous) {
|
|
635
|
+
try {
|
|
636
|
+
await transport.closeSession(previous);
|
|
637
|
+
} catch {
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
dispatch({ type: "MESSAGES_CLEAR" });
|
|
641
|
+
try {
|
|
642
|
+
const info = await transport.createSession({ metadata: config.metadata });
|
|
643
|
+
dispatch({
|
|
644
|
+
type: "SESSION_SET",
|
|
645
|
+
sessionId: info.sessionId,
|
|
646
|
+
messages: info.messages ?? [],
|
|
647
|
+
hasMore: info.hasMore ?? false,
|
|
648
|
+
cursor: info.cursor ?? null
|
|
649
|
+
});
|
|
650
|
+
} catch (err) {
|
|
651
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
652
|
+
lastErrorRef.current = e;
|
|
653
|
+
dispatch({ type: "ERROR_SET", error: e.message });
|
|
654
|
+
config.onError?.(e);
|
|
655
|
+
}
|
|
656
|
+
}, [transport, config]);
|
|
657
|
+
return {
|
|
658
|
+
...state,
|
|
659
|
+
sendMessage,
|
|
660
|
+
cancelStream,
|
|
661
|
+
regenerate,
|
|
662
|
+
editMessage,
|
|
663
|
+
deleteMessage,
|
|
664
|
+
clearMessages,
|
|
665
|
+
loadMore,
|
|
666
|
+
newSession,
|
|
667
|
+
lastError: lastErrorRef.current
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
chunkOLISEQHS_cjs.__name(useChat, "useChat");
|
|
671
|
+
function findLastUserIndex(messages) {
|
|
672
|
+
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
673
|
+
if (messages[i].role === "user") return i;
|
|
674
|
+
}
|
|
675
|
+
return -1;
|
|
676
|
+
}
|
|
677
|
+
chunkOLISEQHS_cjs.__name(findLastUserIndex, "findLastUserIndex");
|
|
678
|
+
function findPreviousUserIndex(messages, from) {
|
|
679
|
+
for (let i = from - 1; i >= 0; i -= 1) {
|
|
680
|
+
if (messages[i].role === "user") return i;
|
|
681
|
+
}
|
|
682
|
+
return -1;
|
|
683
|
+
}
|
|
684
|
+
chunkOLISEQHS_cjs.__name(findPreviousUserIndex, "findPreviousUserIndex");
|
|
685
|
+
var DEFAULT_MOBILE_QUERY = "(max-width: 640px)";
|
|
686
|
+
function useChatLayout(config = {}) {
|
|
687
|
+
const {
|
|
688
|
+
defaultMode = "closed",
|
|
689
|
+
storageKey = STORAGE_KEYS.mode,
|
|
690
|
+
sidebarStorageKey = STORAGE_KEYS.sidebarWidth,
|
|
691
|
+
reserveCssVar = CSS_VARS.reserve,
|
|
692
|
+
defaultSidebarWidth = DEFAULT_SIDEBAR.width,
|
|
693
|
+
minSidebarWidth = DEFAULT_SIDEBAR.min,
|
|
694
|
+
maxSidebarWidth = DEFAULT_SIDEBAR.max,
|
|
695
|
+
mobileQuery = DEFAULT_MOBILE_QUERY
|
|
696
|
+
} = config;
|
|
697
|
+
const [mode, setMode] = hooks.useLocalStorage(storageKey, defaultMode);
|
|
698
|
+
const [sidebarWidthRaw, setSidebarWidthRaw] = hooks.useLocalStorage(
|
|
699
|
+
sidebarStorageKey,
|
|
700
|
+
defaultSidebarWidth
|
|
701
|
+
);
|
|
702
|
+
const isMobile = hooks.useMediaQuery(mobileQuery);
|
|
703
|
+
const setSidebarWidth = react.useCallback(
|
|
704
|
+
(w) => {
|
|
705
|
+
const clamped = Math.max(minSidebarWidth, Math.min(maxSidebarWidth, w));
|
|
706
|
+
setSidebarWidthRaw(clamped);
|
|
707
|
+
},
|
|
708
|
+
[setSidebarWidthRaw, minSidebarWidth, maxSidebarWidth]
|
|
709
|
+
);
|
|
710
|
+
const [previousOpenMode, setPreviousOpenMode] = react.useState(
|
|
711
|
+
mode === "closed" ? "embedded" : mode
|
|
712
|
+
);
|
|
713
|
+
react.useEffect(() => {
|
|
714
|
+
if (mode !== "closed") setPreviousOpenMode(mode);
|
|
715
|
+
}, [mode]);
|
|
716
|
+
const open = react.useCallback(() => {
|
|
717
|
+
setMode(previousOpenMode === "closed" ? "embedded" : previousOpenMode);
|
|
718
|
+
}, [setMode, previousOpenMode]);
|
|
719
|
+
const close = react.useCallback(() => setMode("closed"), [setMode]);
|
|
720
|
+
const toggle = react.useCallback(() => {
|
|
721
|
+
setMode(mode === "closed" ? previousOpenMode : "closed");
|
|
722
|
+
}, [setMode, mode, previousOpenMode]);
|
|
723
|
+
const effectiveMode = react.useMemo(() => {
|
|
724
|
+
if (mode === "closed") return "closed";
|
|
725
|
+
if (isMobile && (mode === "sidebar" || mode === "floating")) return "fullscreen";
|
|
726
|
+
return mode;
|
|
727
|
+
}, [mode, isMobile]);
|
|
728
|
+
react.useEffect(() => {
|
|
729
|
+
if (typeof document === "undefined") return;
|
|
730
|
+
const root = document.documentElement;
|
|
731
|
+
if (effectiveMode === "sidebar") {
|
|
732
|
+
root.style.setProperty(reserveCssVar, `${sidebarWidthRaw}px`);
|
|
733
|
+
} else {
|
|
734
|
+
root.style.removeProperty(reserveCssVar);
|
|
735
|
+
}
|
|
736
|
+
return () => {
|
|
737
|
+
root.style.removeProperty(reserveCssVar);
|
|
738
|
+
};
|
|
739
|
+
}, [effectiveMode, sidebarWidthRaw, reserveCssVar]);
|
|
740
|
+
return {
|
|
741
|
+
mode,
|
|
742
|
+
setMode,
|
|
743
|
+
open,
|
|
744
|
+
close,
|
|
745
|
+
toggle,
|
|
746
|
+
sidebarWidth: sidebarWidthRaw,
|
|
747
|
+
setSidebarWidth,
|
|
748
|
+
isMobile,
|
|
749
|
+
effectiveMode
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
chunkOLISEQHS_cjs.__name(useChatLayout, "useChatLayout");
|
|
753
|
+
|
|
754
|
+
// src/tools/Chat/core/audio/audioBus.ts
|
|
755
|
+
var unlocked = false;
|
|
756
|
+
var unlockListeners = /* @__PURE__ */ new Set();
|
|
757
|
+
function setUnlocked(value) {
|
|
758
|
+
if (unlocked === value) return;
|
|
759
|
+
unlocked = value;
|
|
760
|
+
for (const cb of unlockListeners) cb(value);
|
|
761
|
+
}
|
|
762
|
+
chunkOLISEQHS_cjs.__name(setUnlocked, "setUnlocked");
|
|
763
|
+
function createAudioBus(options) {
|
|
764
|
+
if (typeof window === "undefined") {
|
|
765
|
+
return noopBus();
|
|
766
|
+
}
|
|
767
|
+
let sounds = options.sounds;
|
|
768
|
+
const cache = /* @__PURE__ */ new Map();
|
|
769
|
+
const getOrCreate = /* @__PURE__ */ chunkOLISEQHS_cjs.__name((url) => {
|
|
770
|
+
const hit = cache.get(url);
|
|
771
|
+
if (hit) return hit;
|
|
772
|
+
const el = new Audio(url);
|
|
773
|
+
el.preload = "auto";
|
|
774
|
+
el.crossOrigin = "anonymous";
|
|
775
|
+
cache.set(url, el);
|
|
776
|
+
return el;
|
|
777
|
+
}, "getOrCreate");
|
|
778
|
+
const resolveUrl = /* @__PURE__ */ chunkOLISEQHS_cjs.__name((event) => {
|
|
779
|
+
const v = sounds[event];
|
|
780
|
+
if (!v) return null;
|
|
781
|
+
return v;
|
|
782
|
+
}, "resolveUrl");
|
|
783
|
+
const play = /* @__PURE__ */ chunkOLISEQHS_cjs.__name((event) => {
|
|
784
|
+
if (options.getMuted()) return;
|
|
785
|
+
if (!options.isEnabled(event)) return;
|
|
786
|
+
const url = resolveUrl(event);
|
|
787
|
+
if (!url) return;
|
|
788
|
+
getOrCreate(url);
|
|
789
|
+
const fresh = new Audio(url);
|
|
790
|
+
fresh.preload = "auto";
|
|
791
|
+
fresh.volume = options.getVolume();
|
|
792
|
+
const p = fresh.play();
|
|
793
|
+
if (p && typeof p.catch === "function") {
|
|
794
|
+
p.catch(() => {
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
}, "play");
|
|
798
|
+
const preload = /* @__PURE__ */ chunkOLISEQHS_cjs.__name((event) => {
|
|
799
|
+
const url = resolveUrl(event);
|
|
800
|
+
if (!url) return;
|
|
801
|
+
const el = getOrCreate(url);
|
|
802
|
+
try {
|
|
803
|
+
el.load();
|
|
804
|
+
} catch {
|
|
805
|
+
}
|
|
806
|
+
}, "preload");
|
|
807
|
+
const unlock = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => {
|
|
808
|
+
if (unlocked) return;
|
|
809
|
+
for (const el of cache.values()) {
|
|
810
|
+
const wasMuted = el.muted;
|
|
811
|
+
el.muted = true;
|
|
812
|
+
const p = el.play();
|
|
813
|
+
if (p && typeof p.then === "function") {
|
|
814
|
+
p.then(() => {
|
|
815
|
+
el.pause();
|
|
816
|
+
el.currentTime = 0;
|
|
817
|
+
el.muted = wasMuted;
|
|
818
|
+
}).catch(() => {
|
|
819
|
+
el.muted = wasMuted;
|
|
820
|
+
});
|
|
821
|
+
} else {
|
|
822
|
+
el.pause();
|
|
823
|
+
el.muted = wasMuted;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
setUnlocked(true);
|
|
827
|
+
}, "unlock");
|
|
828
|
+
return {
|
|
829
|
+
play,
|
|
830
|
+
preload,
|
|
831
|
+
unlock,
|
|
832
|
+
isUnlocked: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => unlocked, "isUnlocked"),
|
|
833
|
+
subscribeUnlock(cb) {
|
|
834
|
+
unlockListeners.add(cb);
|
|
835
|
+
return () => unlockListeners.delete(cb);
|
|
836
|
+
},
|
|
837
|
+
setSounds(next) {
|
|
838
|
+
sounds = next;
|
|
839
|
+
},
|
|
840
|
+
dispose() {
|
|
841
|
+
cache.clear();
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
chunkOLISEQHS_cjs.__name(createAudioBus, "createAudioBus");
|
|
846
|
+
function noopBus() {
|
|
847
|
+
return {
|
|
848
|
+
play: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => void 0, "play"),
|
|
849
|
+
preload: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => void 0, "preload"),
|
|
850
|
+
unlock: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => void 0, "unlock"),
|
|
851
|
+
isUnlocked: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => false, "isUnlocked"),
|
|
852
|
+
subscribeUnlock: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => () => void 0, "subscribeUnlock"),
|
|
853
|
+
setSounds: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => void 0, "setSounds"),
|
|
854
|
+
dispose: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => void 0, "dispose")
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
chunkOLISEQHS_cjs.__name(noopBus, "noopBus");
|
|
858
|
+
var STORAGE_KEY = "djangocfg-chat-audio:prefs";
|
|
859
|
+
var clamp01 = /* @__PURE__ */ chunkOLISEQHS_cjs.__name((v) => {
|
|
860
|
+
if (!Number.isFinite(v)) return 1;
|
|
861
|
+
return v < 0 ? 0 : v > 1 ? 1 : v;
|
|
862
|
+
}, "clamp01");
|
|
863
|
+
var useChatAudioPrefs = zustand.create()(
|
|
864
|
+
middleware.persist(
|
|
865
|
+
(set) => ({
|
|
866
|
+
volume: 1,
|
|
867
|
+
muted: false,
|
|
868
|
+
enabled: {},
|
|
869
|
+
setVolume: /* @__PURE__ */ chunkOLISEQHS_cjs.__name((v) => set({ volume: clamp01(v) }), "setVolume"),
|
|
870
|
+
setMuted: /* @__PURE__ */ chunkOLISEQHS_cjs.__name((m) => set({ muted: !!m }), "setMuted"),
|
|
871
|
+
setEventEnabled: /* @__PURE__ */ chunkOLISEQHS_cjs.__name((event, enabled) => set((s) => ({ enabled: { ...s.enabled, [event]: enabled } })), "setEventEnabled")
|
|
872
|
+
}),
|
|
873
|
+
{
|
|
874
|
+
name: STORAGE_KEY,
|
|
875
|
+
storage: middleware.createJSONStorage(() => {
|
|
876
|
+
if (typeof window === "undefined") {
|
|
877
|
+
return {
|
|
878
|
+
getItem: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => null, "getItem"),
|
|
879
|
+
setItem: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => void 0, "setItem"),
|
|
880
|
+
removeItem: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => void 0, "removeItem")
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
return window.localStorage;
|
|
884
|
+
}),
|
|
885
|
+
partialize: /* @__PURE__ */ chunkOLISEQHS_cjs.__name((s) => ({ volume: s.volume, muted: s.muted, enabled: s.enabled }), "partialize"),
|
|
886
|
+
version: 1
|
|
887
|
+
}
|
|
888
|
+
)
|
|
889
|
+
);
|
|
890
|
+
|
|
891
|
+
// src/tools/Chat/hooks/useChatAudio.ts
|
|
892
|
+
var ALL_EVENTS = [
|
|
893
|
+
"messageSent",
|
|
894
|
+
"messageReceived",
|
|
895
|
+
"streamStart",
|
|
896
|
+
"error",
|
|
897
|
+
"mention",
|
|
898
|
+
"notification"
|
|
899
|
+
];
|
|
900
|
+
function readReducedMotion() {
|
|
901
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return false;
|
|
902
|
+
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
903
|
+
}
|
|
904
|
+
chunkOLISEQHS_cjs.__name(readReducedMotion, "readReducedMotion");
|
|
905
|
+
function readReducedData() {
|
|
906
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return false;
|
|
907
|
+
return window.matchMedia("(prefers-reduced-data: reduce)").matches;
|
|
908
|
+
}
|
|
909
|
+
chunkOLISEQHS_cjs.__name(readReducedData, "readReducedData");
|
|
910
|
+
function readVisibilityHidden() {
|
|
911
|
+
if (typeof document === "undefined") return false;
|
|
912
|
+
return document.visibilityState === "hidden";
|
|
913
|
+
}
|
|
914
|
+
chunkOLISEQHS_cjs.__name(readVisibilityHidden, "readVisibilityHidden");
|
|
915
|
+
function useChatAudio(config = {}) {
|
|
916
|
+
const {
|
|
917
|
+
sounds = {},
|
|
918
|
+
volume: volumeOverride,
|
|
919
|
+
muted: mutedOverride,
|
|
920
|
+
shouldPlay,
|
|
921
|
+
respectReducedMotion = true,
|
|
922
|
+
respectReducedData = true,
|
|
923
|
+
muteWhenHidden = true
|
|
924
|
+
} = config;
|
|
925
|
+
const volume = useChatAudioPrefs((s) => volumeOverride != null ? volumeOverride : s.volume);
|
|
926
|
+
const mutedPersisted = useChatAudioPrefs((s) => s.muted);
|
|
927
|
+
const muted = mutedOverride != null ? mutedOverride : mutedPersisted;
|
|
928
|
+
const enabledMap = useChatAudioPrefs((s) => s.enabled);
|
|
929
|
+
const setVolumePref = useChatAudioPrefs((s) => s.setVolume);
|
|
930
|
+
const setMutedPref = useChatAudioPrefs((s) => s.setMuted);
|
|
931
|
+
const setEventEnabledPref = useChatAudioPrefs((s) => s.setEventEnabled);
|
|
932
|
+
const volumeRef = react.useRef(volume);
|
|
933
|
+
volumeRef.current = volume;
|
|
934
|
+
const mutedRef = react.useRef(muted);
|
|
935
|
+
mutedRef.current = muted;
|
|
936
|
+
const enabledRef = react.useRef(enabledMap);
|
|
937
|
+
enabledRef.current = enabledMap;
|
|
938
|
+
const reducedMotionRef = react.useRef(readReducedMotion());
|
|
939
|
+
const reducedDataRef = react.useRef(readReducedData());
|
|
940
|
+
const hiddenRef = react.useRef(readVisibilityHidden());
|
|
941
|
+
const shouldPlayRef = react.useRef(shouldPlay);
|
|
942
|
+
shouldPlayRef.current = shouldPlay;
|
|
943
|
+
react.useEffect(() => {
|
|
944
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return;
|
|
945
|
+
const mqMotion = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
946
|
+
const mqData = window.matchMedia("(prefers-reduced-data: reduce)");
|
|
947
|
+
const onMotion = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => {
|
|
948
|
+
reducedMotionRef.current = mqMotion.matches;
|
|
949
|
+
}, "onMotion");
|
|
950
|
+
const onData = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => {
|
|
951
|
+
reducedDataRef.current = mqData.matches;
|
|
952
|
+
}, "onData");
|
|
953
|
+
mqMotion.addEventListener("change", onMotion);
|
|
954
|
+
mqData.addEventListener("change", onData);
|
|
955
|
+
return () => {
|
|
956
|
+
mqMotion.removeEventListener("change", onMotion);
|
|
957
|
+
mqData.removeEventListener("change", onData);
|
|
958
|
+
};
|
|
959
|
+
}, []);
|
|
960
|
+
react.useEffect(() => {
|
|
961
|
+
if (!muteWhenHidden || typeof document === "undefined") return;
|
|
962
|
+
const onVis = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => {
|
|
963
|
+
hiddenRef.current = document.visibilityState === "hidden";
|
|
964
|
+
}, "onVis");
|
|
965
|
+
document.addEventListener("visibilitychange", onVis);
|
|
966
|
+
return () => document.removeEventListener("visibilitychange", onVis);
|
|
967
|
+
}, [muteWhenHidden]);
|
|
968
|
+
const busRef = react.useRef(null);
|
|
969
|
+
if (busRef.current === null) {
|
|
970
|
+
busRef.current = createAudioBus({
|
|
971
|
+
sounds,
|
|
972
|
+
getVolume: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => volumeRef.current, "getVolume"),
|
|
973
|
+
getMuted: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => effectiveMuted(), "getMuted"),
|
|
974
|
+
isEnabled: /* @__PURE__ */ chunkOLISEQHS_cjs.__name((event) => isEnabledImpl(event), "isEnabled")
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
function effectiveMuted() {
|
|
978
|
+
if (mutedRef.current) return true;
|
|
979
|
+
if (muteWhenHidden && hiddenRef.current) return true;
|
|
980
|
+
if (respectReducedMotion && reducedMotionRef.current) return true;
|
|
981
|
+
if (respectReducedData && reducedDataRef.current) return true;
|
|
982
|
+
return false;
|
|
983
|
+
}
|
|
984
|
+
chunkOLISEQHS_cjs.__name(effectiveMuted, "effectiveMuted");
|
|
985
|
+
function isEnabledImpl(event) {
|
|
986
|
+
if (shouldPlayRef.current && shouldPlayRef.current(event) === false) return false;
|
|
987
|
+
const flag = enabledRef.current[event];
|
|
988
|
+
if (flag === false) return false;
|
|
989
|
+
return true;
|
|
990
|
+
}
|
|
991
|
+
chunkOLISEQHS_cjs.__name(isEnabledImpl, "isEnabledImpl");
|
|
992
|
+
react.useEffect(() => {
|
|
993
|
+
busRef.current?.setSounds(sounds);
|
|
994
|
+
}, [sounds]);
|
|
995
|
+
react.useEffect(() => {
|
|
996
|
+
const bus = busRef.current;
|
|
997
|
+
if (!bus) return;
|
|
998
|
+
for (const event of ALL_EVENTS) {
|
|
999
|
+
bus.preload(event);
|
|
1000
|
+
}
|
|
1001
|
+
}, [sounds]);
|
|
1002
|
+
react.useEffect(() => {
|
|
1003
|
+
const bus = busRef.current;
|
|
1004
|
+
return () => {
|
|
1005
|
+
bus?.dispose();
|
|
1006
|
+
};
|
|
1007
|
+
}, []);
|
|
1008
|
+
const isUnlocked = react.useSyncExternalStore(
|
|
1009
|
+
react.useCallback((cb) => busRef.current?.subscribeUnlock(cb) ?? (() => void 0), []),
|
|
1010
|
+
() => busRef.current?.isUnlocked() ?? false,
|
|
1011
|
+
() => false
|
|
1012
|
+
);
|
|
1013
|
+
const play = react.useCallback((event) => {
|
|
1014
|
+
busRef.current?.play(event);
|
|
1015
|
+
}, []);
|
|
1016
|
+
const preload = react.useCallback((event) => {
|
|
1017
|
+
busRef.current?.preload(event);
|
|
1018
|
+
}, []);
|
|
1019
|
+
const unlock = react.useCallback(() => {
|
|
1020
|
+
busRef.current?.unlock();
|
|
1021
|
+
}, []);
|
|
1022
|
+
const isEventEnabled = react.useCallback(
|
|
1023
|
+
(event) => isEnabledImpl(event),
|
|
1024
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1025
|
+
[]
|
|
1026
|
+
);
|
|
1027
|
+
const api = react.useMemo(
|
|
1028
|
+
() => ({
|
|
1029
|
+
play,
|
|
1030
|
+
preload,
|
|
1031
|
+
unlock,
|
|
1032
|
+
isUnlocked,
|
|
1033
|
+
muted,
|
|
1034
|
+
setMuted: /* @__PURE__ */ chunkOLISEQHS_cjs.__name((m) => setMutedPref(m), "setMuted"),
|
|
1035
|
+
volume,
|
|
1036
|
+
setVolume: /* @__PURE__ */ chunkOLISEQHS_cjs.__name((v) => setVolumePref(v), "setVolume"),
|
|
1037
|
+
isEventEnabled,
|
|
1038
|
+
setEventEnabled: /* @__PURE__ */ chunkOLISEQHS_cjs.__name((event, enabled) => setEventEnabledPref(event, enabled), "setEventEnabled")
|
|
1039
|
+
}),
|
|
1040
|
+
[play, preload, unlock, isUnlocked, muted, volume, isEventEnabled, setMutedPref, setVolumePref, setEventEnabledPref]
|
|
1041
|
+
);
|
|
1042
|
+
return api;
|
|
1043
|
+
}
|
|
1044
|
+
chunkOLISEQHS_cjs.__name(useChatAudio, "useChatAudio");
|
|
1045
|
+
var Ctx = react.createContext(null);
|
|
1046
|
+
function ChatProvider({
|
|
1047
|
+
transport,
|
|
1048
|
+
config = {},
|
|
1049
|
+
initialSessionId,
|
|
1050
|
+
autoCreateSession,
|
|
1051
|
+
streaming,
|
|
1052
|
+
audio,
|
|
1053
|
+
children
|
|
1054
|
+
}) {
|
|
1055
|
+
const audioApi = useChatAudio(audio ?? {});
|
|
1056
|
+
const audioRef = react.useRef(audioApi);
|
|
1057
|
+
audioRef.current = audioApi;
|
|
1058
|
+
const onMessageSent = react.useCallback(() => audioRef.current.play("messageSent"), []);
|
|
1059
|
+
const onMessageEnd = react.useCallback(() => audioRef.current.play("messageReceived"), []);
|
|
1060
|
+
const onStreamStart = react.useCallback(() => audioRef.current.play("streamStart"), []);
|
|
1061
|
+
const onError = react.useCallback(() => audioRef.current.play("error"), []);
|
|
1062
|
+
const chat = useChat({
|
|
1063
|
+
transport,
|
|
1064
|
+
initialSessionId,
|
|
1065
|
+
autoCreateSession,
|
|
1066
|
+
streaming,
|
|
1067
|
+
metadata: {
|
|
1068
|
+
locale: config.locale ?? config.prefs?.locale,
|
|
1069
|
+
slug: config.slug
|
|
1070
|
+
},
|
|
1071
|
+
userPersona: config.user,
|
|
1072
|
+
onMessageSent,
|
|
1073
|
+
onMessageEnd,
|
|
1074
|
+
onStreamStart,
|
|
1075
|
+
onError
|
|
1076
|
+
});
|
|
1077
|
+
const layout = useChatLayout({ defaultMode: "embedded" });
|
|
1078
|
+
const rootRef = react.useRef(null);
|
|
1079
|
+
react.useEffect(() => {
|
|
1080
|
+
if (audioApi.isUnlocked) return;
|
|
1081
|
+
const root = rootRef.current;
|
|
1082
|
+
if (!root) return;
|
|
1083
|
+
const handler = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => {
|
|
1084
|
+
audioApi.unlock();
|
|
1085
|
+
}, "handler");
|
|
1086
|
+
root.addEventListener("pointerdown", handler, { once: true, capture: true });
|
|
1087
|
+
root.addEventListener("keydown", handler, { once: true, capture: true });
|
|
1088
|
+
return () => {
|
|
1089
|
+
root.removeEventListener("pointerdown", handler, { capture: true });
|
|
1090
|
+
root.removeEventListener("keydown", handler, { capture: true });
|
|
1091
|
+
};
|
|
1092
|
+
}, [audioApi]);
|
|
1093
|
+
const labels = react.useMemo(
|
|
1094
|
+
() => ({ ...DEFAULT_LABELS, ...config.labels ?? {} }),
|
|
1095
|
+
[config.labels]
|
|
1096
|
+
);
|
|
1097
|
+
const value = react.useMemo(
|
|
1098
|
+
() => ({ ...chat, layout, config, labels, audio: audioApi }),
|
|
1099
|
+
[chat, layout, config, labels, audioApi]
|
|
1100
|
+
);
|
|
1101
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Ctx.Provider, { value, children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: rootRef, style: { display: "contents" }, children }) });
|
|
1102
|
+
}
|
|
1103
|
+
chunkOLISEQHS_cjs.__name(ChatProvider, "ChatProvider");
|
|
1104
|
+
function useChatContext() {
|
|
1105
|
+
const v = react.useContext(Ctx);
|
|
1106
|
+
if (!v) throw new Error("useChatContext must be used inside <ChatProvider>");
|
|
1107
|
+
return v;
|
|
1108
|
+
}
|
|
1109
|
+
chunkOLISEQHS_cjs.__name(useChatContext, "useChatContext");
|
|
1110
|
+
function useChatContextOptional() {
|
|
1111
|
+
return react.useContext(Ctx);
|
|
1112
|
+
}
|
|
1113
|
+
chunkOLISEQHS_cjs.__name(useChatContextOptional, "useChatContextOptional");
|
|
1114
|
+
var MAX_TEXTAREA_HEIGHT = 240;
|
|
1115
|
+
function useChatComposer(options) {
|
|
1116
|
+
const {
|
|
1117
|
+
onSubmit,
|
|
1118
|
+
initialValue = "",
|
|
1119
|
+
maxLength = LIMITS.messageMaxLength,
|
|
1120
|
+
maxAttachments = LIMITS.attachmentsMax,
|
|
1121
|
+
disabled = false,
|
|
1122
|
+
submitOn = "enter",
|
|
1123
|
+
history = { enabled: true, size: LIMITS.composerHistorySize },
|
|
1124
|
+
onPasteFiles
|
|
1125
|
+
} = options;
|
|
1126
|
+
const [value, setValueState] = react.useState(initialValue);
|
|
1127
|
+
const [attachments, setAttachments] = react.useState([]);
|
|
1128
|
+
const [isSubmitting, setIsSubmitting] = react.useState(false);
|
|
1129
|
+
const textareaRef = react.useRef(null);
|
|
1130
|
+
const historyRef = react.useRef({ items: [], index: -1 });
|
|
1131
|
+
const setValue = react.useCallback(
|
|
1132
|
+
(next) => {
|
|
1133
|
+
setValueState(next.length > maxLength ? next.slice(0, maxLength) : next);
|
|
1134
|
+
},
|
|
1135
|
+
[maxLength]
|
|
1136
|
+
);
|
|
1137
|
+
react.useEffect(() => {
|
|
1138
|
+
const el = textareaRef.current;
|
|
1139
|
+
if (!el) return;
|
|
1140
|
+
el.style.height = "auto";
|
|
1141
|
+
el.style.height = `${Math.min(el.scrollHeight, MAX_TEXTAREA_HEIGHT)}px`;
|
|
1142
|
+
}, [value]);
|
|
1143
|
+
const reset = react.useCallback(() => {
|
|
1144
|
+
setValueState("");
|
|
1145
|
+
setAttachments([]);
|
|
1146
|
+
historyRef.current.index = -1;
|
|
1147
|
+
}, []);
|
|
1148
|
+
const focus = react.useCallback(() => {
|
|
1149
|
+
requestAnimationFrame(() => textareaRef.current?.focus());
|
|
1150
|
+
}, []);
|
|
1151
|
+
const submit = react.useCallback(async () => {
|
|
1152
|
+
const trimmed = value.trim();
|
|
1153
|
+
if (!trimmed && attachments.length === 0 || isSubmitting || disabled) return;
|
|
1154
|
+
setIsSubmitting(true);
|
|
1155
|
+
try {
|
|
1156
|
+
if (history.enabled !== false && trimmed) {
|
|
1157
|
+
const buf = historyRef.current.items;
|
|
1158
|
+
if (buf[buf.length - 1] !== trimmed) {
|
|
1159
|
+
buf.push(trimmed);
|
|
1160
|
+
if (buf.length > (history.size ?? LIMITS.composerHistorySize)) buf.shift();
|
|
1161
|
+
}
|
|
1162
|
+
historyRef.current.index = -1;
|
|
1163
|
+
}
|
|
1164
|
+
const snapshot = [...attachments];
|
|
1165
|
+
const text = value;
|
|
1166
|
+
reset();
|
|
1167
|
+
await onSubmit(text, snapshot);
|
|
1168
|
+
} finally {
|
|
1169
|
+
setIsSubmitting(false);
|
|
1170
|
+
}
|
|
1171
|
+
}, [value, attachments, isSubmitting, disabled, history, onSubmit, reset]);
|
|
1172
|
+
const addAttachment = react.useCallback(
|
|
1173
|
+
(a) => {
|
|
1174
|
+
setAttachments((prev) => {
|
|
1175
|
+
if (prev.some((p) => p.id === a.id)) {
|
|
1176
|
+
return prev.map((p) => p.id === a.id ? a : p);
|
|
1177
|
+
}
|
|
1178
|
+
if (prev.length >= maxAttachments) return prev;
|
|
1179
|
+
return [...prev, a];
|
|
1180
|
+
});
|
|
1181
|
+
},
|
|
1182
|
+
[maxAttachments]
|
|
1183
|
+
);
|
|
1184
|
+
const removeAttachment = react.useCallback((id) => {
|
|
1185
|
+
setAttachments((prev) => prev.filter((a) => a.id !== id));
|
|
1186
|
+
}, []);
|
|
1187
|
+
const recallPrevious = react.useCallback(() => {
|
|
1188
|
+
const { items } = historyRef.current;
|
|
1189
|
+
if (!items.length) return;
|
|
1190
|
+
const next = historyRef.current.index < 0 ? items.length - 1 : Math.max(0, historyRef.current.index - 1);
|
|
1191
|
+
historyRef.current.index = next;
|
|
1192
|
+
setValueState(items[next]);
|
|
1193
|
+
}, []);
|
|
1194
|
+
const recallNext = react.useCallback(() => {
|
|
1195
|
+
const { items } = historyRef.current;
|
|
1196
|
+
if (!items.length || historyRef.current.index < 0) return;
|
|
1197
|
+
const next = historyRef.current.index + 1;
|
|
1198
|
+
if (next >= items.length) {
|
|
1199
|
+
historyRef.current.index = -1;
|
|
1200
|
+
setValueState("");
|
|
1201
|
+
return;
|
|
1202
|
+
}
|
|
1203
|
+
historyRef.current.index = next;
|
|
1204
|
+
setValueState(items[next]);
|
|
1205
|
+
}, []);
|
|
1206
|
+
const onChange = react.useCallback(
|
|
1207
|
+
(e) => {
|
|
1208
|
+
setValue(e.target.value);
|
|
1209
|
+
},
|
|
1210
|
+
[setValue]
|
|
1211
|
+
);
|
|
1212
|
+
const onKeyDown = react.useCallback(
|
|
1213
|
+
(e) => {
|
|
1214
|
+
if (e.key === "Enter") {
|
|
1215
|
+
const isCmd = e.metaKey || e.ctrlKey;
|
|
1216
|
+
const shouldSend = submitOn === "cmd+enter" ? isCmd : !e.shiftKey;
|
|
1217
|
+
if (shouldSend) {
|
|
1218
|
+
e.preventDefault();
|
|
1219
|
+
void submit();
|
|
1220
|
+
}
|
|
1221
|
+
return;
|
|
1222
|
+
}
|
|
1223
|
+
if (history.enabled !== false && value === "" && attachments.length === 0) {
|
|
1224
|
+
if (e.key === "ArrowUp") {
|
|
1225
|
+
e.preventDefault();
|
|
1226
|
+
recallPrevious();
|
|
1227
|
+
} else if (e.key === "ArrowDown" && historyRef.current.index >= 0) {
|
|
1228
|
+
e.preventDefault();
|
|
1229
|
+
recallNext();
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
},
|
|
1233
|
+
[submitOn, submit, history, value, attachments.length, recallPrevious, recallNext]
|
|
1234
|
+
);
|
|
1235
|
+
const onPaste = react.useCallback(
|
|
1236
|
+
(e) => {
|
|
1237
|
+
const files = Array.from(e.clipboardData?.files ?? []);
|
|
1238
|
+
if (files.length && onPasteFiles) {
|
|
1239
|
+
e.preventDefault();
|
|
1240
|
+
onPasteFiles(files);
|
|
1241
|
+
}
|
|
1242
|
+
},
|
|
1243
|
+
[onPasteFiles]
|
|
1244
|
+
);
|
|
1245
|
+
const canSubmit = !disabled && !isSubmitting && (value.trim().length > 0 || attachments.length > 0);
|
|
1246
|
+
return {
|
|
1247
|
+
value,
|
|
1248
|
+
setValue,
|
|
1249
|
+
attachments,
|
|
1250
|
+
addAttachment,
|
|
1251
|
+
removeAttachment,
|
|
1252
|
+
isSubmitting,
|
|
1253
|
+
canSubmit,
|
|
1254
|
+
submit,
|
|
1255
|
+
reset,
|
|
1256
|
+
focus,
|
|
1257
|
+
textareaRef,
|
|
1258
|
+
textareaProps: {
|
|
1259
|
+
ref: textareaRef,
|
|
1260
|
+
value,
|
|
1261
|
+
disabled,
|
|
1262
|
+
onChange,
|
|
1263
|
+
onKeyDown,
|
|
1264
|
+
onPaste
|
|
1265
|
+
},
|
|
1266
|
+
recallPrevious,
|
|
1267
|
+
recallNext
|
|
1268
|
+
};
|
|
1269
|
+
}
|
|
1270
|
+
chunkOLISEQHS_cjs.__name(useChatComposer, "useChatComposer");
|
|
1271
|
+
function useChatScroll(options) {
|
|
1272
|
+
const {
|
|
1273
|
+
containerRef,
|
|
1274
|
+
bottomRef,
|
|
1275
|
+
isStreaming = false,
|
|
1276
|
+
bottomThresholdPx = 80,
|
|
1277
|
+
messagesCount = 0
|
|
1278
|
+
} = options;
|
|
1279
|
+
const [isAtBottom, setIsAtBottom] = react.useState(true);
|
|
1280
|
+
const [unreadCount, setUnreadCount] = react.useState(0);
|
|
1281
|
+
const lastCountRef = react.useRef(messagesCount);
|
|
1282
|
+
const stickyRef = react.useRef(true);
|
|
1283
|
+
const wasStreamingRef = react.useRef(isStreaming);
|
|
1284
|
+
const scrollToBottom = react.useCallback(
|
|
1285
|
+
(smooth = false) => {
|
|
1286
|
+
const el = containerRef.current;
|
|
1287
|
+
if (!el) return;
|
|
1288
|
+
el.scrollTo({
|
|
1289
|
+
top: el.scrollHeight,
|
|
1290
|
+
behavior: smooth ? "smooth" : "auto"
|
|
1291
|
+
});
|
|
1292
|
+
stickyRef.current = true;
|
|
1293
|
+
setIsAtBottom(true);
|
|
1294
|
+
setUnreadCount(0);
|
|
1295
|
+
},
|
|
1296
|
+
[containerRef]
|
|
1297
|
+
);
|
|
1298
|
+
const resetUnread = react.useCallback(() => setUnreadCount(0), []);
|
|
1299
|
+
react.useEffect(() => {
|
|
1300
|
+
const el = containerRef.current;
|
|
1301
|
+
if (!el) return;
|
|
1302
|
+
const onScroll = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => {
|
|
1303
|
+
const distance = el.scrollHeight - el.scrollTop - el.clientHeight;
|
|
1304
|
+
const atBottom = distance <= bottomThresholdPx;
|
|
1305
|
+
stickyRef.current = atBottom;
|
|
1306
|
+
setIsAtBottom(atBottom);
|
|
1307
|
+
if (atBottom) setUnreadCount(0);
|
|
1308
|
+
}, "onScroll");
|
|
1309
|
+
onScroll();
|
|
1310
|
+
el.addEventListener("scroll", onScroll, { passive: true });
|
|
1311
|
+
return () => {
|
|
1312
|
+
el.removeEventListener("scroll", onScroll);
|
|
1313
|
+
};
|
|
1314
|
+
}, [containerRef, bottomThresholdPx]);
|
|
1315
|
+
react.useEffect(() => {
|
|
1316
|
+
const el = containerRef.current;
|
|
1317
|
+
if (!el) return;
|
|
1318
|
+
if (isStreaming) {
|
|
1319
|
+
wasStreamingRef.current = true;
|
|
1320
|
+
if (!stickyRef.current) return;
|
|
1321
|
+
let raf = 0;
|
|
1322
|
+
const tick = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => {
|
|
1323
|
+
if (!stickyRef.current) return;
|
|
1324
|
+
el.scrollTop = el.scrollHeight;
|
|
1325
|
+
raf = requestAnimationFrame(tick);
|
|
1326
|
+
}, "tick");
|
|
1327
|
+
raf = requestAnimationFrame(tick);
|
|
1328
|
+
return () => cancelAnimationFrame(raf);
|
|
1329
|
+
}
|
|
1330
|
+
if (wasStreamingRef.current && stickyRef.current) {
|
|
1331
|
+
wasStreamingRef.current = false;
|
|
1332
|
+
let raf1 = 0;
|
|
1333
|
+
let raf2 = 0;
|
|
1334
|
+
raf1 = requestAnimationFrame(() => {
|
|
1335
|
+
el.scrollTop = el.scrollHeight;
|
|
1336
|
+
raf2 = requestAnimationFrame(() => {
|
|
1337
|
+
el.scrollTop = el.scrollHeight;
|
|
1338
|
+
});
|
|
1339
|
+
});
|
|
1340
|
+
return () => {
|
|
1341
|
+
cancelAnimationFrame(raf1);
|
|
1342
|
+
cancelAnimationFrame(raf2);
|
|
1343
|
+
};
|
|
1344
|
+
}
|
|
1345
|
+
wasStreamingRef.current = false;
|
|
1346
|
+
return;
|
|
1347
|
+
}, [containerRef, isStreaming]);
|
|
1348
|
+
react.useEffect(() => {
|
|
1349
|
+
if (messagesCount > lastCountRef.current) {
|
|
1350
|
+
if (stickyRef.current) {
|
|
1351
|
+
const el = containerRef.current;
|
|
1352
|
+
if (el) el.scrollTop = el.scrollHeight;
|
|
1353
|
+
} else {
|
|
1354
|
+
setUnreadCount((n) => n + (messagesCount - lastCountRef.current));
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
lastCountRef.current = messagesCount;
|
|
1358
|
+
}, [containerRef, messagesCount]);
|
|
1359
|
+
react.useEffect(() => {
|
|
1360
|
+
}, [bottomRef]);
|
|
1361
|
+
return { isAtBottom, unreadCount, scrollToBottom, resetUnread };
|
|
1362
|
+
}
|
|
1363
|
+
chunkOLISEQHS_cjs.__name(useChatScroll, "useChatScroll");
|
|
1364
|
+
function useChatHistory(options) {
|
|
1365
|
+
const { enabled = true, containerRef, topSentinelRef, hasMore, isLoadingMore, loadMore } = options;
|
|
1366
|
+
const heightBeforeRef = react.useRef(null);
|
|
1367
|
+
react.useEffect(() => {
|
|
1368
|
+
if (heightBeforeRef.current == null) return;
|
|
1369
|
+
const el = containerRef.current;
|
|
1370
|
+
if (!el) {
|
|
1371
|
+
heightBeforeRef.current = null;
|
|
1372
|
+
return;
|
|
1373
|
+
}
|
|
1374
|
+
if (!isLoadingMore) {
|
|
1375
|
+
const delta = el.scrollHeight - heightBeforeRef.current;
|
|
1376
|
+
if (delta > 0) {
|
|
1377
|
+
el.scrollTop += delta;
|
|
1378
|
+
}
|
|
1379
|
+
heightBeforeRef.current = null;
|
|
1380
|
+
}
|
|
1381
|
+
}, [containerRef, isLoadingMore]);
|
|
1382
|
+
react.useEffect(() => {
|
|
1383
|
+
if (!enabled || !hasMore) return;
|
|
1384
|
+
const sentinel = topSentinelRef.current;
|
|
1385
|
+
const root = containerRef.current;
|
|
1386
|
+
if (!sentinel || !root) return;
|
|
1387
|
+
const observer = new IntersectionObserver(
|
|
1388
|
+
(entries) => {
|
|
1389
|
+
const entry = entries[0];
|
|
1390
|
+
if (!entry?.isIntersecting) return;
|
|
1391
|
+
if (isLoadingMore) return;
|
|
1392
|
+
const el = containerRef.current;
|
|
1393
|
+
if (el) heightBeforeRef.current = el.scrollHeight;
|
|
1394
|
+
void loadMore();
|
|
1395
|
+
},
|
|
1396
|
+
{ root, threshold: 0, rootMargin: "200px 0px 0px 0px" }
|
|
1397
|
+
);
|
|
1398
|
+
observer.observe(sentinel);
|
|
1399
|
+
return () => observer.disconnect();
|
|
1400
|
+
}, [enabled, hasMore, isLoadingMore, containerRef, topSentinelRef, loadMore]);
|
|
1401
|
+
}
|
|
1402
|
+
chunkOLISEQHS_cjs.__name(useChatHistory, "useChatHistory");
|
|
1403
|
+
function AttachmentsGrid({
|
|
1404
|
+
attachments,
|
|
1405
|
+
maxVisible,
|
|
1406
|
+
onClick,
|
|
1407
|
+
onRemove,
|
|
1408
|
+
isInComposer = false,
|
|
1409
|
+
layout = "wrap",
|
|
1410
|
+
className
|
|
1411
|
+
}) {
|
|
1412
|
+
if (!attachments?.length) return null;
|
|
1413
|
+
const visible = maxVisible ? attachments.slice(0, maxVisible) : attachments;
|
|
1414
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1415
|
+
"div",
|
|
1416
|
+
{
|
|
1417
|
+
className: lib.cn(
|
|
1418
|
+
layout === "grid" ? "grid grid-cols-3 gap-2" : "flex flex-wrap gap-2",
|
|
1419
|
+
className
|
|
1420
|
+
),
|
|
1421
|
+
children: visible.map((a) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1422
|
+
AttachmentTile,
|
|
1423
|
+
{
|
|
1424
|
+
attachment: a,
|
|
1425
|
+
isInComposer,
|
|
1426
|
+
onClick: onClick ? () => onClick(a) : void 0,
|
|
1427
|
+
onRemove: onRemove ? () => onRemove(a) : void 0
|
|
1428
|
+
},
|
|
1429
|
+
a.id
|
|
1430
|
+
))
|
|
1431
|
+
}
|
|
1432
|
+
);
|
|
1433
|
+
}
|
|
1434
|
+
chunkOLISEQHS_cjs.__name(AttachmentsGrid, "AttachmentsGrid");
|
|
1435
|
+
function AttachmentsList({
|
|
1436
|
+
attachments,
|
|
1437
|
+
maxVisible,
|
|
1438
|
+
onClick,
|
|
1439
|
+
onRemove,
|
|
1440
|
+
renderers,
|
|
1441
|
+
isInComposer = false,
|
|
1442
|
+
className
|
|
1443
|
+
}) {
|
|
1444
|
+
if (!attachments?.length) return null;
|
|
1445
|
+
const visible = maxVisible ? attachments.slice(0, maxVisible) : attachments;
|
|
1446
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: lib.cn("flex w-full flex-col gap-2", className), children: visible.map((a) => {
|
|
1447
|
+
const renderer = renderers?.[a.type] ?? renderers?.default;
|
|
1448
|
+
const args = {
|
|
1449
|
+
attachment: a,
|
|
1450
|
+
isInComposer,
|
|
1451
|
+
onClick: onClick ? () => onClick(a) : void 0,
|
|
1452
|
+
onRemove: onRemove ? () => onRemove(a) : void 0
|
|
1453
|
+
};
|
|
1454
|
+
if (renderer) {
|
|
1455
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative w-full min-w-0", children: [
|
|
1456
|
+
renderer(args),
|
|
1457
|
+
args.onRemove ? /* @__PURE__ */ jsxRuntime.jsx(RemoveBtn, { onRemove: args.onRemove }) : null
|
|
1458
|
+
] }, a.id);
|
|
1459
|
+
}
|
|
1460
|
+
return /* @__PURE__ */ jsxRuntime.jsx(AttachmentTile, { ...args }, a.id);
|
|
1461
|
+
}) });
|
|
1462
|
+
}
|
|
1463
|
+
chunkOLISEQHS_cjs.__name(AttachmentsList, "AttachmentsList");
|
|
1464
|
+
function Attachments(props) {
|
|
1465
|
+
const { renderers, layout, ...rest } = props;
|
|
1466
|
+
if (renderers) {
|
|
1467
|
+
return /* @__PURE__ */ jsxRuntime.jsx(AttachmentsList, { ...rest, renderers });
|
|
1468
|
+
}
|
|
1469
|
+
return /* @__PURE__ */ jsxRuntime.jsx(AttachmentsGrid, { ...rest, layout: layout === "grid" ? "grid" : "wrap" });
|
|
1470
|
+
}
|
|
1471
|
+
chunkOLISEQHS_cjs.__name(Attachments, "Attachments");
|
|
1472
|
+
function AttachmentTile({ attachment, onClick, onRemove }) {
|
|
1473
|
+
const isImage = attachment.type === "image";
|
|
1474
|
+
const isUploading = attachment.status === "uploading";
|
|
1475
|
+
const inner = isImage ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1476
|
+
"img",
|
|
1477
|
+
{
|
|
1478
|
+
src: attachment.thumbnailUrl ?? attachment.url,
|
|
1479
|
+
alt: attachment.name ?? "attachment",
|
|
1480
|
+
className: "h-16 w-16 rounded-md object-cover",
|
|
1481
|
+
loading: "lazy"
|
|
1482
|
+
}
|
|
1483
|
+
) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex max-w-44 items-center gap-2 rounded-md border border-border bg-background/60 px-2 py-1.5 text-xs", children: [
|
|
1484
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.File, { "aria-hidden": true, className: "size-4 shrink-0 text-muted-foreground" }),
|
|
1485
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: attachment.name ?? "file" })
|
|
1486
|
+
] });
|
|
1487
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
|
|
1488
|
+
onClick ? /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick, className: "block", children: inner }) : inner,
|
|
1489
|
+
isUploading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pointer-events-none absolute inset-0 flex items-center justify-center rounded-md bg-background/70 text-[10px] font-medium", children: attachment.progress != null ? `${Math.round(attachment.progress * 100)}%` : "\u2026" }) : null,
|
|
1490
|
+
onRemove ? /* @__PURE__ */ jsxRuntime.jsx(RemoveBtn, { onRemove }) : null
|
|
1491
|
+
] });
|
|
1492
|
+
}
|
|
1493
|
+
chunkOLISEQHS_cjs.__name(AttachmentTile, "AttachmentTile");
|
|
1494
|
+
function RemoveBtn({ onRemove }) {
|
|
1495
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1496
|
+
"button",
|
|
1497
|
+
{
|
|
1498
|
+
type: "button",
|
|
1499
|
+
"aria-label": "Remove attachment",
|
|
1500
|
+
onClick: onRemove,
|
|
1501
|
+
className: "absolute -right-1.5 -top-1.5 grid h-4 w-4 place-items-center rounded-full border border-border bg-background text-muted-foreground hover:bg-destructive hover:text-destructive-foreground",
|
|
1502
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { "aria-hidden": true, className: "size-2.5" })
|
|
1503
|
+
}
|
|
1504
|
+
);
|
|
1505
|
+
}
|
|
1506
|
+
chunkOLISEQHS_cjs.__name(RemoveBtn, "RemoveBtn");
|
|
1507
|
+
var Composer = react.forwardRef(/* @__PURE__ */ chunkOLISEQHS_cjs.__name(function Composer2({
|
|
1508
|
+
composer,
|
|
1509
|
+
placeholder = "Type a message...",
|
|
1510
|
+
disabled,
|
|
1511
|
+
showAttachmentButton = false,
|
|
1512
|
+
onPickFiles,
|
|
1513
|
+
toolbarStart,
|
|
1514
|
+
toolbarEnd,
|
|
1515
|
+
attachmentTray,
|
|
1516
|
+
className,
|
|
1517
|
+
textareaClassName,
|
|
1518
|
+
isStreaming: isStreamingProp,
|
|
1519
|
+
onCancel: onCancelProp
|
|
1520
|
+
}, ref) {
|
|
1521
|
+
const ctx = useChatContextOptional();
|
|
1522
|
+
const isStreaming = isStreamingProp ?? ctx?.isStreaming ?? false;
|
|
1523
|
+
const onCancel = onCancelProp ?? ctx?.cancelStream;
|
|
1524
|
+
const isDisabled = disabled ?? isStreaming;
|
|
1525
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1526
|
+
"div",
|
|
1527
|
+
{
|
|
1528
|
+
ref,
|
|
1529
|
+
className: lib.cn(
|
|
1530
|
+
"border-t border-border bg-background/95 px-2.5 pt-2 pb-[max(0.5rem,env(safe-area-inset-bottom))]",
|
|
1531
|
+
className
|
|
1532
|
+
),
|
|
1533
|
+
children: [
|
|
1534
|
+
composer.attachments.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mb-1.5", children: attachmentTray ?? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1535
|
+
Attachments,
|
|
1536
|
+
{
|
|
1537
|
+
attachments: composer.attachments,
|
|
1538
|
+
onRemove: (a) => composer.removeAttachment(a.id)
|
|
1539
|
+
}
|
|
1540
|
+
) }) : null,
|
|
1541
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-end gap-1.5 [&>:not(textarea)]:shrink-0 [&>:not(textarea)]:h-9", children: [
|
|
1542
|
+
showAttachmentButton ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1543
|
+
components.Button,
|
|
1544
|
+
{
|
|
1545
|
+
type: "button",
|
|
1546
|
+
variant: "ghost",
|
|
1547
|
+
size: "icon",
|
|
1548
|
+
onClick: onPickFiles,
|
|
1549
|
+
"aria-label": "Attach files",
|
|
1550
|
+
disabled: isDisabled,
|
|
1551
|
+
className: "h-9 w-9",
|
|
1552
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Paperclip, { "aria-hidden": true, className: "size-4" })
|
|
1553
|
+
}
|
|
1554
|
+
) : null,
|
|
1555
|
+
toolbarStart,
|
|
1556
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1557
|
+
components.Textarea,
|
|
1558
|
+
{
|
|
1559
|
+
...composer.textareaProps,
|
|
1560
|
+
rows: 1,
|
|
1561
|
+
placeholder,
|
|
1562
|
+
"aria-label": placeholder,
|
|
1563
|
+
"aria-multiline": "true",
|
|
1564
|
+
disabled: isDisabled,
|
|
1565
|
+
className: lib.cn(
|
|
1566
|
+
"min-h-9 max-h-60 flex-1 resize-none rounded-2xl px-3.5 py-2 text-base sm:text-sm",
|
|
1567
|
+
textareaClassName
|
|
1568
|
+
)
|
|
1569
|
+
}
|
|
1570
|
+
),
|
|
1571
|
+
toolbarEnd,
|
|
1572
|
+
isStreaming ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1573
|
+
components.Button,
|
|
1574
|
+
{
|
|
1575
|
+
type: "button",
|
|
1576
|
+
variant: "secondary",
|
|
1577
|
+
size: "icon",
|
|
1578
|
+
onClick: onCancel,
|
|
1579
|
+
"aria-label": "Stop",
|
|
1580
|
+
"aria-keyshortcuts": "Escape",
|
|
1581
|
+
className: "h-9 w-9",
|
|
1582
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Square, { "aria-hidden": true, className: "size-3.5" })
|
|
1583
|
+
}
|
|
1584
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
1585
|
+
components.Button,
|
|
1586
|
+
{
|
|
1587
|
+
type: "button",
|
|
1588
|
+
size: "icon",
|
|
1589
|
+
onClick: () => void composer.submit(),
|
|
1590
|
+
disabled: !composer.canSubmit,
|
|
1591
|
+
"aria-label": "Send",
|
|
1592
|
+
"aria-keyshortcuts": "Enter",
|
|
1593
|
+
className: "h-9 w-9",
|
|
1594
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Send, { "aria-hidden": true, className: "size-4" })
|
|
1595
|
+
}
|
|
1596
|
+
)
|
|
1597
|
+
] })
|
|
1598
|
+
]
|
|
1599
|
+
}
|
|
1600
|
+
);
|
|
1601
|
+
}, "Composer"));
|
|
1602
|
+
function EmptyState({
|
|
1603
|
+
greeting,
|
|
1604
|
+
description,
|
|
1605
|
+
suggestions,
|
|
1606
|
+
onPickSuggestion,
|
|
1607
|
+
className
|
|
1608
|
+
}) {
|
|
1609
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: lib.cn("flex flex-col items-center gap-3 px-4 py-12 text-center", className), children: [
|
|
1610
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid size-10 place-items-center rounded-full bg-muted", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Sparkles, { "aria-hidden": true, className: "size-5 text-muted-foreground" }) }),
|
|
1611
|
+
greeting ? /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-base font-semibold", children: greeting }) : null,
|
|
1612
|
+
description ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "max-w-md text-sm text-muted-foreground", children: description }) : null,
|
|
1613
|
+
suggestions?.length ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-2 grid w-full max-w-md grid-cols-1 gap-2 sm:grid-cols-2", children: suggestions.map((s) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1614
|
+
"button",
|
|
1615
|
+
{
|
|
1616
|
+
type: "button",
|
|
1617
|
+
onClick: () => onPickSuggestion?.(s.prompt),
|
|
1618
|
+
className: "rounded-lg border border-border bg-background/60 px-3 py-2 text-left text-xs hover:bg-accent",
|
|
1619
|
+
children: s.label
|
|
1620
|
+
},
|
|
1621
|
+
s.prompt
|
|
1622
|
+
)) }) : null
|
|
1623
|
+
] });
|
|
1624
|
+
}
|
|
1625
|
+
chunkOLISEQHS_cjs.__name(EmptyState, "EmptyState");
|
|
1626
|
+
function ErrorBanner({ error, onDismiss, onRetry, className }) {
|
|
1627
|
+
if (!error) return null;
|
|
1628
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1629
|
+
"div",
|
|
1630
|
+
{
|
|
1631
|
+
role: "alert",
|
|
1632
|
+
className: lib.cn(
|
|
1633
|
+
"mx-2.5 my-2 flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",
|
|
1634
|
+
className
|
|
1635
|
+
),
|
|
1636
|
+
children: [
|
|
1637
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.AlertCircle, { "aria-hidden": true, className: "mt-0.5 size-3.5 shrink-0" }),
|
|
1638
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "min-w-0 flex-1 break-words", children: error }),
|
|
1639
|
+
onRetry ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1640
|
+
"button",
|
|
1641
|
+
{
|
|
1642
|
+
type: "button",
|
|
1643
|
+
onClick: onRetry,
|
|
1644
|
+
className: "inline-flex items-center gap-1 rounded px-1.5 py-0.5 hover:bg-destructive/15",
|
|
1645
|
+
children: [
|
|
1646
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.RefreshCw, { "aria-hidden": true, className: "size-3" }),
|
|
1647
|
+
" Retry"
|
|
1648
|
+
]
|
|
1649
|
+
}
|
|
1650
|
+
) : null,
|
|
1651
|
+
onDismiss ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1652
|
+
"button",
|
|
1653
|
+
{
|
|
1654
|
+
type: "button",
|
|
1655
|
+
"aria-label": "Dismiss",
|
|
1656
|
+
onClick: onDismiss,
|
|
1657
|
+
className: "rounded p-0.5 hover:bg-destructive/15",
|
|
1658
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { "aria-hidden": true, className: "size-3" })
|
|
1659
|
+
}
|
|
1660
|
+
) : null
|
|
1661
|
+
]
|
|
1662
|
+
}
|
|
1663
|
+
);
|
|
1664
|
+
}
|
|
1665
|
+
chunkOLISEQHS_cjs.__name(ErrorBanner, "ErrorBanner");
|
|
1666
|
+
function JumpToLatest({ visible, unreadCount = 0, onClick, className }) {
|
|
1667
|
+
if (!visible) return null;
|
|
1668
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1669
|
+
"button",
|
|
1670
|
+
{
|
|
1671
|
+
type: "button",
|
|
1672
|
+
onClick,
|
|
1673
|
+
"aria-live": "polite",
|
|
1674
|
+
className: lib.cn(
|
|
1675
|
+
"pointer-events-auto inline-flex items-center gap-1.5 rounded-full border border-border bg-background px-3 py-1 text-xs shadow-md hover:bg-accent",
|
|
1676
|
+
className
|
|
1677
|
+
),
|
|
1678
|
+
children: [
|
|
1679
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowDown, { "aria-hidden": true, className: "size-3.5" }),
|
|
1680
|
+
unreadCount > 0 ? `${unreadCount} new` : "Jump to latest"
|
|
1681
|
+
]
|
|
1682
|
+
}
|
|
1683
|
+
);
|
|
1684
|
+
}
|
|
1685
|
+
chunkOLISEQHS_cjs.__name(JumpToLatest, "JumpToLatest");
|
|
1686
|
+
|
|
1687
|
+
// src/tools/Chat/core/persona.ts
|
|
1688
|
+
var FALLBACK_USER = { name: "You", initials: "You" };
|
|
1689
|
+
var FALLBACK_ASSISTANT = { name: "AI", initials: "AI" };
|
|
1690
|
+
function resolvePersona(message, user, assistant) {
|
|
1691
|
+
if (message.sender) return message.sender;
|
|
1692
|
+
if (message.role === "user") return user ?? FALLBACK_USER;
|
|
1693
|
+
if (message.role === "assistant") return assistant ?? FALLBACK_ASSISTANT;
|
|
1694
|
+
return { name: message.role };
|
|
1695
|
+
}
|
|
1696
|
+
chunkOLISEQHS_cjs.__name(resolvePersona, "resolvePersona");
|
|
1697
|
+
function deriveInitials(persona, role) {
|
|
1698
|
+
if (persona.initials) return persona.initials;
|
|
1699
|
+
if (persona.name) {
|
|
1700
|
+
const parts = persona.name.trim().split(/\s+/);
|
|
1701
|
+
if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase();
|
|
1702
|
+
return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();
|
|
1703
|
+
}
|
|
1704
|
+
if (role === "user") return "You";
|
|
1705
|
+
if (role === "assistant") return "AI";
|
|
1706
|
+
return "?";
|
|
1707
|
+
}
|
|
1708
|
+
chunkOLISEQHS_cjs.__name(deriveInitials, "deriveInitials");
|
|
1709
|
+
function StreamingIndicator({ variant = "dots", label, className }) {
|
|
1710
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1711
|
+
"span",
|
|
1712
|
+
{
|
|
1713
|
+
className: lib.cn("inline-flex items-center gap-1.5 text-xs text-muted-foreground", className),
|
|
1714
|
+
"aria-live": "off",
|
|
1715
|
+
children: [
|
|
1716
|
+
variant === "dots" ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "inline-flex gap-0.5", "aria-hidden": true, children: [
|
|
1717
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "size-1 animate-bounce rounded-full bg-current [animation-delay:-0.2s]" }),
|
|
1718
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "size-1 animate-bounce rounded-full bg-current [animation-delay:-0.1s]" }),
|
|
1719
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "size-1 animate-bounce rounded-full bg-current" })
|
|
1720
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "inline-block size-1.5 animate-pulse rounded-full bg-current", "aria-hidden": true }),
|
|
1721
|
+
label ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "italic", children: label }) : null
|
|
1722
|
+
]
|
|
1723
|
+
}
|
|
1724
|
+
);
|
|
1725
|
+
}
|
|
1726
|
+
chunkOLISEQHS_cjs.__name(StreamingIndicator, "StreamingIndicator");
|
|
1727
|
+
function Sources({ sources, layout = "inline", maxVisible, onClick, className }) {
|
|
1728
|
+
if (!sources?.length) return null;
|
|
1729
|
+
const visible = maxVisible ? sources.slice(0, maxVisible) : sources;
|
|
1730
|
+
const remaining = maxVisible ? Math.max(0, sources.length - maxVisible) : 0;
|
|
1731
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1732
|
+
"div",
|
|
1733
|
+
{
|
|
1734
|
+
className: lib.cn(
|
|
1735
|
+
"mt-2 flex flex-wrap gap-1.5",
|
|
1736
|
+
layout === "grid" && "grid grid-cols-2",
|
|
1737
|
+
className
|
|
1738
|
+
),
|
|
1739
|
+
children: [
|
|
1740
|
+
visible.map((s, i) => {
|
|
1741
|
+
const handle = onClick ? () => onClick(s) : void 0;
|
|
1742
|
+
const Tag = handle ? "button" : "a";
|
|
1743
|
+
const props = handle ? { type: "button", onClick: handle } : { href: s.url, target: "_blank", rel: "noopener noreferrer" };
|
|
1744
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1745
|
+
Tag,
|
|
1746
|
+
{
|
|
1747
|
+
...props,
|
|
1748
|
+
className: "inline-flex max-w-full items-center gap-1 rounded-md border border-border bg-background/60 px-2 py-1 text-xs text-foreground/80 hover:bg-accent hover:text-foreground",
|
|
1749
|
+
title: s.snippet ?? s.title,
|
|
1750
|
+
children: [
|
|
1751
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: s.title || s.url }),
|
|
1752
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.ExternalLink, { "aria-hidden": true, className: "size-3 shrink-0 opacity-60" })
|
|
1753
|
+
]
|
|
1754
|
+
},
|
|
1755
|
+
`${s.url}-${i}`
|
|
1756
|
+
);
|
|
1757
|
+
}),
|
|
1758
|
+
remaining > 0 ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "inline-flex items-center rounded-md border border-dashed border-border px-2 py-1 text-xs text-muted-foreground", children: [
|
|
1759
|
+
"+",
|
|
1760
|
+
remaining
|
|
1761
|
+
] }) : null
|
|
1762
|
+
]
|
|
1763
|
+
}
|
|
1764
|
+
);
|
|
1765
|
+
}
|
|
1766
|
+
chunkOLISEQHS_cjs.__name(Sources, "Sources");
|
|
1767
|
+
function ToolCalls({
|
|
1768
|
+
calls,
|
|
1769
|
+
defaultExpanded = false,
|
|
1770
|
+
expandWhileStreaming = true,
|
|
1771
|
+
renderInput,
|
|
1772
|
+
renderOutput,
|
|
1773
|
+
renderStreaming,
|
|
1774
|
+
renderPayload,
|
|
1775
|
+
className
|
|
1776
|
+
}) {
|
|
1777
|
+
if (!calls?.length) return null;
|
|
1778
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: lib.cn("mt-2 space-y-1.5", className), children: calls.map((call) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1779
|
+
ToolCallItem,
|
|
1780
|
+
{
|
|
1781
|
+
call,
|
|
1782
|
+
defaultExpanded,
|
|
1783
|
+
expandWhileStreaming,
|
|
1784
|
+
renderInput,
|
|
1785
|
+
renderOutput,
|
|
1786
|
+
renderStreaming,
|
|
1787
|
+
renderPayload
|
|
1788
|
+
},
|
|
1789
|
+
call.id
|
|
1790
|
+
)) });
|
|
1791
|
+
}
|
|
1792
|
+
chunkOLISEQHS_cjs.__name(ToolCalls, "ToolCalls");
|
|
1793
|
+
function ToolCallItem({
|
|
1794
|
+
call,
|
|
1795
|
+
defaultExpanded,
|
|
1796
|
+
expandWhileStreaming,
|
|
1797
|
+
renderInput,
|
|
1798
|
+
renderOutput,
|
|
1799
|
+
renderStreaming,
|
|
1800
|
+
renderPayload
|
|
1801
|
+
}) {
|
|
1802
|
+
const isRunning = call.status === "running";
|
|
1803
|
+
const initialOpen = defaultExpanded || expandWhileStreaming && isRunning;
|
|
1804
|
+
const [open, setOpen] = react.useState(initialOpen);
|
|
1805
|
+
const userToggledRef = react.useRef(false);
|
|
1806
|
+
const wasRunningRef = react.useRef(isRunning);
|
|
1807
|
+
react.useEffect(() => {
|
|
1808
|
+
if (wasRunningRef.current && !isRunning) {
|
|
1809
|
+
if (!userToggledRef.current && !defaultExpanded) {
|
|
1810
|
+
setOpen(false);
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
wasRunningRef.current = isRunning;
|
|
1814
|
+
}, [isRunning, defaultExpanded]);
|
|
1815
|
+
const handleToggle = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => {
|
|
1816
|
+
userToggledRef.current = true;
|
|
1817
|
+
setOpen((v) => !v);
|
|
1818
|
+
}, "handleToggle");
|
|
1819
|
+
const Icon = open ? lucideReact.ChevronDown : lucideReact.ChevronRight;
|
|
1820
|
+
const statusColor = call.status === "success" ? "text-emerald-500" : call.status === "error" ? "text-destructive" : call.status === "cancelled" ? "text-muted-foreground" : "text-amber-500";
|
|
1821
|
+
const renderValue = /* @__PURE__ */ chunkOLISEQHS_cjs.__name((value, kind) => {
|
|
1822
|
+
if (kind === "input" && renderInput) return renderInput(value, call);
|
|
1823
|
+
if (kind === "output" && renderOutput) return renderOutput(value, call);
|
|
1824
|
+
if (kind === "streaming" && renderStreaming)
|
|
1825
|
+
return renderStreaming(typeof value === "string" ? value : String(value), call);
|
|
1826
|
+
if (renderPayload) return renderPayload(value, kind, call);
|
|
1827
|
+
return /* @__PURE__ */ jsxRuntime.jsx(DefaultPayload, { value, kind });
|
|
1828
|
+
}, "renderValue");
|
|
1829
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "overflow-hidden rounded-md border border-border bg-muted/30", children: [
|
|
1830
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1831
|
+
"button",
|
|
1832
|
+
{
|
|
1833
|
+
type: "button",
|
|
1834
|
+
onClick: handleToggle,
|
|
1835
|
+
"aria-expanded": open,
|
|
1836
|
+
className: "flex w-full items-center gap-2 px-2 py-1.5 text-left text-xs hover:bg-muted/60",
|
|
1837
|
+
children: [
|
|
1838
|
+
/* @__PURE__ */ jsxRuntime.jsx(Icon, { "aria-hidden": true, className: "size-3 shrink-0 text-muted-foreground" }),
|
|
1839
|
+
isRunning ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { "aria-hidden": true, className: "size-3 shrink-0 animate-spin text-amber-500" }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: lib.cn("size-2 shrink-0 rounded-full", statusColor.replace("text-", "bg-")) }),
|
|
1840
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-mono text-foreground", children: call.name }),
|
|
1841
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: lib.cn("ml-auto", statusColor), children: call.status })
|
|
1842
|
+
]
|
|
1843
|
+
}
|
|
1844
|
+
),
|
|
1845
|
+
open ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1 border-t border-border px-2 py-1.5 text-[11px]", children: [
|
|
1846
|
+
call.input != null ? renderValue(call.input, "input") : null,
|
|
1847
|
+
call.streamingText != null ? renderValue(call.streamingText, "streaming") : call.output !== void 0 ? renderValue(call.output, "output") : null
|
|
1848
|
+
] }) : null
|
|
1849
|
+
] });
|
|
1850
|
+
}
|
|
1851
|
+
chunkOLISEQHS_cjs.__name(ToolCallItem, "ToolCallItem");
|
|
1852
|
+
function DefaultPayload({ value, kind }) {
|
|
1853
|
+
const isStreamingOrString = kind === "streaming" || typeof value === "string";
|
|
1854
|
+
const muted = kind === "input";
|
|
1855
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1856
|
+
"pre",
|
|
1857
|
+
{
|
|
1858
|
+
className: lib.cn(
|
|
1859
|
+
"overflow-auto rounded bg-background/60 p-1.5 font-mono",
|
|
1860
|
+
kind === "input" ? "max-h-32" : "max-h-48",
|
|
1861
|
+
muted ? "text-muted-foreground" : "text-foreground/90"
|
|
1862
|
+
),
|
|
1863
|
+
children: isStreamingOrString ? String(value) : safeStringify(value)
|
|
1864
|
+
}
|
|
1865
|
+
);
|
|
1866
|
+
}
|
|
1867
|
+
chunkOLISEQHS_cjs.__name(DefaultPayload, "DefaultPayload");
|
|
1868
|
+
function safeStringify(value) {
|
|
1869
|
+
try {
|
|
1870
|
+
return JSON.stringify(value, null, 2);
|
|
1871
|
+
} catch {
|
|
1872
|
+
return String(value);
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
chunkOLISEQHS_cjs.__name(safeStringify, "safeStringify");
|
|
1876
|
+
function MessageActions({
|
|
1877
|
+
role,
|
|
1878
|
+
onCopy,
|
|
1879
|
+
onRegenerate,
|
|
1880
|
+
onEdit,
|
|
1881
|
+
onDelete,
|
|
1882
|
+
hideOn,
|
|
1883
|
+
className
|
|
1884
|
+
}) {
|
|
1885
|
+
if (hideOn?.includes(role)) return null;
|
|
1886
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1887
|
+
"div",
|
|
1888
|
+
{
|
|
1889
|
+
className: lib.cn(
|
|
1890
|
+
"mt-1 flex items-center gap-0.5 opacity-0 transition-opacity group-hover/msg:opacity-100 focus-within:opacity-100",
|
|
1891
|
+
className
|
|
1892
|
+
),
|
|
1893
|
+
children: [
|
|
1894
|
+
onCopy ? /* @__PURE__ */ jsxRuntime.jsx(ActionButton, { onClick: onCopy, label: "Copy", icon: lucideReact.Copy }) : null,
|
|
1895
|
+
onRegenerate && role === "assistant" ? /* @__PURE__ */ jsxRuntime.jsx(ActionButton, { onClick: onRegenerate, label: "Regenerate", icon: lucideReact.RefreshCw }) : null,
|
|
1896
|
+
onEdit && role === "user" ? /* @__PURE__ */ jsxRuntime.jsx(ActionButton, { onClick: onEdit, label: "Edit", icon: lucideReact.Pencil }) : null,
|
|
1897
|
+
onDelete ? /* @__PURE__ */ jsxRuntime.jsx(ActionButton, { onClick: onDelete, label: "Delete", icon: lucideReact.Trash, destructive: true }) : null
|
|
1898
|
+
]
|
|
1899
|
+
}
|
|
1900
|
+
);
|
|
1901
|
+
}
|
|
1902
|
+
chunkOLISEQHS_cjs.__name(MessageActions, "MessageActions");
|
|
1903
|
+
function ActionButton({
|
|
1904
|
+
onClick,
|
|
1905
|
+
label,
|
|
1906
|
+
icon: Icon,
|
|
1907
|
+
destructive
|
|
1908
|
+
}) {
|
|
1909
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1910
|
+
"button",
|
|
1911
|
+
{
|
|
1912
|
+
type: "button",
|
|
1913
|
+
onClick,
|
|
1914
|
+
"aria-label": label,
|
|
1915
|
+
className: lib.cn(
|
|
1916
|
+
"rounded p-1 text-muted-foreground hover:bg-accent hover:text-foreground",
|
|
1917
|
+
destructive && "hover:bg-destructive/15 hover:text-destructive"
|
|
1918
|
+
),
|
|
1919
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Icon, { "aria-hidden": true, className: "size-3" })
|
|
1920
|
+
}
|
|
1921
|
+
);
|
|
1922
|
+
}
|
|
1923
|
+
chunkOLISEQHS_cjs.__name(ActionButton, "ActionButton");
|
|
1924
|
+
var MessageBubbleInner = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({
|
|
1925
|
+
message,
|
|
1926
|
+
isUser: isUserProp,
|
|
1927
|
+
showAvatar = true,
|
|
1928
|
+
avatarSrc,
|
|
1929
|
+
avatarFallback,
|
|
1930
|
+
user,
|
|
1931
|
+
assistant,
|
|
1932
|
+
showTimestamp = false,
|
|
1933
|
+
showActions = true,
|
|
1934
|
+
isCompact = false,
|
|
1935
|
+
className,
|
|
1936
|
+
beforeContent,
|
|
1937
|
+
afterContent,
|
|
1938
|
+
toolCallsRenderer,
|
|
1939
|
+
toolCallsProps,
|
|
1940
|
+
sourcesRenderer,
|
|
1941
|
+
attachmentsRenderer,
|
|
1942
|
+
attachmentRenderers,
|
|
1943
|
+
onAttachmentOpen,
|
|
1944
|
+
onCopy,
|
|
1945
|
+
onRegenerate,
|
|
1946
|
+
onEdit,
|
|
1947
|
+
onDelete
|
|
1948
|
+
}) => {
|
|
1949
|
+
const isUser = isUserProp ?? message.role === "user";
|
|
1950
|
+
const isStreaming = !!message.isStreaming;
|
|
1951
|
+
const isErr = !!message.isError;
|
|
1952
|
+
const ctx = useChatContextOptional();
|
|
1953
|
+
const persona = resolvePersona(
|
|
1954
|
+
message,
|
|
1955
|
+
user ?? ctx?.config.user,
|
|
1956
|
+
assistant ?? ctx?.config.assistant
|
|
1957
|
+
);
|
|
1958
|
+
const initials = deriveInitials(persona, message.role);
|
|
1959
|
+
const personaName = persona.name ?? (isUser ? "You" : "Assistant");
|
|
1960
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1961
|
+
"div",
|
|
1962
|
+
{
|
|
1963
|
+
role: "article",
|
|
1964
|
+
"aria-label": `${personaName} said: ${message.content.slice(0, 80)}`,
|
|
1965
|
+
"aria-busy": isStreaming || void 0,
|
|
1966
|
+
"data-role": message.role,
|
|
1967
|
+
className: lib.cn(
|
|
1968
|
+
"group/msg flex gap-2.5 px-2.5 py-2",
|
|
1969
|
+
isUser ? "flex-row-reverse" : "flex-row",
|
|
1970
|
+
className
|
|
1971
|
+
),
|
|
1972
|
+
children: [
|
|
1973
|
+
showAvatar ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1974
|
+
components.Avatar,
|
|
1975
|
+
{
|
|
1976
|
+
className: "size-7 shrink-0",
|
|
1977
|
+
title: persona.description ?? personaName,
|
|
1978
|
+
children: [
|
|
1979
|
+
avatarSrc || persona.avatarUrl ? /* @__PURE__ */ jsxRuntime.jsx(components.AvatarImage, { src: avatarSrc ?? persona.avatarUrl, alt: personaName }) : null,
|
|
1980
|
+
/* @__PURE__ */ jsxRuntime.jsx(components.AvatarFallback, { className: "text-[10px]", children: avatarFallback ?? initials })
|
|
1981
|
+
]
|
|
1982
|
+
}
|
|
1983
|
+
) : null,
|
|
1984
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: lib.cn("min-w-0 flex-1", isUser && "flex flex-col items-end"), children: [
|
|
1985
|
+
beforeContent,
|
|
1986
|
+
message.attachments?.length ? attachmentsRenderer ? attachmentsRenderer(message.attachments) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mb-1.5 w-full", children: attachmentRenderers ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1987
|
+
AttachmentsList,
|
|
1988
|
+
{
|
|
1989
|
+
attachments: message.attachments,
|
|
1990
|
+
renderers: attachmentRenderers,
|
|
1991
|
+
onClick: onAttachmentOpen,
|
|
1992
|
+
className: isUser ? "items-end" : void 0
|
|
1993
|
+
}
|
|
1994
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
1995
|
+
AttachmentsGrid,
|
|
1996
|
+
{
|
|
1997
|
+
attachments: message.attachments,
|
|
1998
|
+
onClick: onAttachmentOpen,
|
|
1999
|
+
className: isUser ? "justify-end" : void 0
|
|
2000
|
+
}
|
|
2001
|
+
) }) : null,
|
|
2002
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2003
|
+
"div",
|
|
2004
|
+
{
|
|
2005
|
+
className: lib.cn(
|
|
2006
|
+
"inline-block max-w-full rounded-2xl px-3.5 py-2 text-sm",
|
|
2007
|
+
isUser ? "bg-primary text-primary-foreground rounded-tr-md" : isErr ? "bg-destructive/10 text-destructive rounded-tl-md border border-destructive/30" : "bg-muted text-foreground rounded-tl-md"
|
|
2008
|
+
),
|
|
2009
|
+
children: [
|
|
2010
|
+
isStreaming && message.toolActivity ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mb-1.5", children: /* @__PURE__ */ jsxRuntime.jsx(StreamingIndicator, { label: message.toolActivity }) }) : null,
|
|
2011
|
+
message.content || !isStreaming ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
2012
|
+
chunkB5AWZOHJ_cjs.MarkdownMessage,
|
|
2013
|
+
{
|
|
2014
|
+
content: message.content || (isErr ? "*Failed to generate a response.*" : ""),
|
|
2015
|
+
isUser,
|
|
2016
|
+
isCompact,
|
|
2017
|
+
plainText: isStreaming
|
|
2018
|
+
}
|
|
2019
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(StreamingIndicator, {})
|
|
2020
|
+
]
|
|
2021
|
+
}
|
|
2022
|
+
),
|
|
2023
|
+
message.toolCalls?.length ? toolCallsRenderer ? toolCallsRenderer(message.toolCalls) : /* @__PURE__ */ jsxRuntime.jsx(ToolCalls, { calls: message.toolCalls, ...toolCallsProps }) : null,
|
|
2024
|
+
message.sources?.length && !isStreaming ? sourcesRenderer ? sourcesRenderer(message.sources) : /* @__PURE__ */ jsxRuntime.jsx(Sources, { sources: message.sources }) : null,
|
|
2025
|
+
showActions && !isStreaming ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
2026
|
+
MessageActions,
|
|
2027
|
+
{
|
|
2028
|
+
role: message.role,
|
|
2029
|
+
onCopy,
|
|
2030
|
+
onRegenerate,
|
|
2031
|
+
onEdit,
|
|
2032
|
+
onDelete
|
|
2033
|
+
}
|
|
2034
|
+
) : null,
|
|
2035
|
+
showTimestamp ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 text-[10px] text-muted-foreground", children: new Date(message.createdAt).toLocaleTimeString() }) : null,
|
|
2036
|
+
afterContent
|
|
2037
|
+
] })
|
|
2038
|
+
]
|
|
2039
|
+
}
|
|
2040
|
+
);
|
|
2041
|
+
}, "MessageBubbleInner");
|
|
2042
|
+
var MessageBubble = react.memo(MessageBubbleInner, (prev, next) => {
|
|
2043
|
+
const a = prev.message;
|
|
2044
|
+
const b = next.message;
|
|
2045
|
+
return a.id === b.id && a.content === b.content && a.isStreaming === b.isStreaming && a.isError === b.isError && (a.version ?? 0) === (b.version ?? 0) && a.toolActivity === b.toolActivity && a.toolCalls === b.toolCalls && a.sources === b.sources && a.attachments === b.attachments;
|
|
2046
|
+
});
|
|
2047
|
+
MessageBubble.displayName = "MessageBubble";
|
|
2048
|
+
var MessageList = react.forwardRef(/* @__PURE__ */ chunkOLISEQHS_cjs.__name(function MessageList2({
|
|
2049
|
+
messages: messagesProp,
|
|
2050
|
+
renderItem,
|
|
2051
|
+
renderEmpty,
|
|
2052
|
+
isLoadingMore: isLoadingMoreProp,
|
|
2053
|
+
topSentinelRef,
|
|
2054
|
+
bottomRef,
|
|
2055
|
+
className,
|
|
2056
|
+
itemClassName
|
|
2057
|
+
}, ref) {
|
|
2058
|
+
const ctx = useChatContextOptional();
|
|
2059
|
+
const messages = messagesProp ?? ctx?.messages ?? [];
|
|
2060
|
+
const isLoadingMore = isLoadingMoreProp ?? ctx?.isLoadingMore ?? false;
|
|
2061
|
+
const defaultRenderItem = react.useCallback(
|
|
2062
|
+
(m) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: itemClassName, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2063
|
+
MessageBubble,
|
|
2064
|
+
{
|
|
2065
|
+
message: m,
|
|
2066
|
+
onCopy: () => copy(m.content),
|
|
2067
|
+
onRegenerate: ctx ? () => void ctx.regenerate(m.id) : void 0,
|
|
2068
|
+
onDelete: ctx ? () => ctx.deleteMessage(m.id) : void 0
|
|
2069
|
+
}
|
|
2070
|
+
) }, m.id),
|
|
2071
|
+
[itemClassName, ctx]
|
|
2072
|
+
);
|
|
2073
|
+
const itemRenderer = renderItem ?? defaultRenderItem;
|
|
2074
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2075
|
+
"div",
|
|
2076
|
+
{
|
|
2077
|
+
ref,
|
|
2078
|
+
role: "log",
|
|
2079
|
+
"aria-live": "polite",
|
|
2080
|
+
"aria-atomic": "false",
|
|
2081
|
+
className: lib.cn("flex-1 overflow-y-auto", className),
|
|
2082
|
+
children: [
|
|
2083
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { ref: topSentinelRef, "aria-hidden": true }),
|
|
2084
|
+
isLoadingMore ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-2", children: /* @__PURE__ */ jsxRuntime.jsx(components.Spinner, { className: "size-4 text-muted-foreground" }) }) : null,
|
|
2085
|
+
messages.length === 0 ? renderEmpty?.() ?? null : messages.map((m, i) => itemRenderer(m, i)),
|
|
2086
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { ref: bottomRef, "aria-hidden": true })
|
|
2087
|
+
]
|
|
2088
|
+
}
|
|
2089
|
+
);
|
|
2090
|
+
}, "MessageList"));
|
|
2091
|
+
function copy(text) {
|
|
2092
|
+
if (typeof navigator !== "undefined" && navigator.clipboard) {
|
|
2093
|
+
void navigator.clipboard.writeText(text);
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
chunkOLISEQHS_cjs.__name(copy, "copy");
|
|
2097
|
+
function ChatRoot(props) {
|
|
2098
|
+
const { transport, config, initialSessionId, autoCreateSession, streaming, audio, className, ...slots } = props;
|
|
2099
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2100
|
+
ChatProvider,
|
|
2101
|
+
{
|
|
2102
|
+
transport,
|
|
2103
|
+
config,
|
|
2104
|
+
initialSessionId,
|
|
2105
|
+
autoCreateSession,
|
|
2106
|
+
streaming,
|
|
2107
|
+
audio,
|
|
2108
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ChatRootShell, { className, slots })
|
|
2109
|
+
}
|
|
2110
|
+
);
|
|
2111
|
+
}
|
|
2112
|
+
chunkOLISEQHS_cjs.__name(ChatRoot, "ChatRoot");
|
|
2113
|
+
function ChatRootShell({ className, slots }) {
|
|
2114
|
+
const chat = useChatContext();
|
|
2115
|
+
const composer = useChatComposer({
|
|
2116
|
+
onSubmit: /* @__PURE__ */ chunkOLISEQHS_cjs.__name((content, attachments) => chat.sendMessage(content, attachments), "onSubmit"),
|
|
2117
|
+
disabled: chat.isStreaming
|
|
2118
|
+
});
|
|
2119
|
+
const containerRef = react.useRef(null);
|
|
2120
|
+
const bottomRef = react.useRef(null);
|
|
2121
|
+
const topRef = react.useRef(null);
|
|
2122
|
+
const scroll = useChatScroll({
|
|
2123
|
+
containerRef,
|
|
2124
|
+
bottomRef,
|
|
2125
|
+
isStreaming: chat.isStreaming,
|
|
2126
|
+
messagesCount: chat.messages.length
|
|
2127
|
+
});
|
|
2128
|
+
useChatHistory({
|
|
2129
|
+
containerRef,
|
|
2130
|
+
topSentinelRef: topRef,
|
|
2131
|
+
hasMore: chat.hasMore,
|
|
2132
|
+
isLoadingMore: chat.isLoadingMore,
|
|
2133
|
+
loadMore: chat.loadMore
|
|
2134
|
+
});
|
|
2135
|
+
const greeting = chat.config.greeting ?? "How can I help?";
|
|
2136
|
+
const description = chat.config.description;
|
|
2137
|
+
const suggestions = chat.config.suggestions;
|
|
2138
|
+
const headerNode = slots.renderHeader ? slots.renderHeader(chat) : slots.header;
|
|
2139
|
+
const emptyNode = slots.empty ?? (slots.renderEmpty ? slots.renderEmpty({ setValue: composer.setValue, focus: composer.focus }) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
2140
|
+
EmptyState,
|
|
2141
|
+
{
|
|
2142
|
+
greeting,
|
|
2143
|
+
description,
|
|
2144
|
+
suggestions,
|
|
2145
|
+
onPickSuggestion: (prompt) => {
|
|
2146
|
+
composer.setValue(prompt);
|
|
2147
|
+
composer.focus();
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
));
|
|
2151
|
+
const renderItem = slots.renderMessage ?? ((m) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2152
|
+
MessageBubble,
|
|
2153
|
+
{
|
|
2154
|
+
message: m,
|
|
2155
|
+
toolCallsProps: slots.toolCallsProps,
|
|
2156
|
+
attachmentRenderers: slots.attachmentRenderers,
|
|
2157
|
+
onAttachmentOpen: slots.onAttachmentOpen,
|
|
2158
|
+
onCopy: () => copy2(m.content),
|
|
2159
|
+
onRegenerate: () => void chat.regenerate(m.id),
|
|
2160
|
+
onDelete: () => chat.deleteMessage(m.id)
|
|
2161
|
+
},
|
|
2162
|
+
m.id
|
|
2163
|
+
));
|
|
2164
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: lib.cn("relative flex h-full min-h-0 flex-col overflow-hidden", className), children: [
|
|
2165
|
+
slots.banner ?? null,
|
|
2166
|
+
headerNode ?? null,
|
|
2167
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative flex min-h-0 flex-1 flex-col", children: [
|
|
2168
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2169
|
+
ErrorBanner,
|
|
2170
|
+
{
|
|
2171
|
+
error: chat.error,
|
|
2172
|
+
onDismiss: chat.error ? () => chat.clearMessages() : void 0,
|
|
2173
|
+
onRetry: chat.error ? () => void chat.regenerate() : void 0
|
|
2174
|
+
}
|
|
2175
|
+
),
|
|
2176
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2177
|
+
MessageList,
|
|
2178
|
+
{
|
|
2179
|
+
ref: containerRef,
|
|
2180
|
+
topSentinelRef: topRef,
|
|
2181
|
+
bottomRef,
|
|
2182
|
+
renderItem,
|
|
2183
|
+
renderEmpty: () => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: emptyNode })
|
|
2184
|
+
}
|
|
2185
|
+
),
|
|
2186
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "pointer-events-none absolute inset-x-0 bottom-2 flex justify-center", children: slots.jumpToLatest ?? /* @__PURE__ */ jsxRuntime.jsx(
|
|
2187
|
+
JumpToLatest,
|
|
2188
|
+
{
|
|
2189
|
+
visible: !scroll.isAtBottom,
|
|
2190
|
+
unreadCount: scroll.unreadCount,
|
|
2191
|
+
onClick: () => scroll.scrollToBottom(true)
|
|
2192
|
+
}
|
|
2193
|
+
) })
|
|
2194
|
+
] }),
|
|
2195
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2196
|
+
Composer,
|
|
2197
|
+
{
|
|
2198
|
+
composer,
|
|
2199
|
+
placeholder: chat.config.placeholder,
|
|
2200
|
+
showAttachmentButton: slots.showAttachmentButton,
|
|
2201
|
+
onPickFiles: slots.onPickFiles,
|
|
2202
|
+
toolbarStart: slots.composerToolbarStart,
|
|
2203
|
+
toolbarEnd: slots.composerToolbarEnd,
|
|
2204
|
+
attachmentTray: slots.composerAttachmentTray
|
|
2205
|
+
}
|
|
2206
|
+
),
|
|
2207
|
+
slots.footer ?? null
|
|
2208
|
+
] });
|
|
2209
|
+
}
|
|
2210
|
+
chunkOLISEQHS_cjs.__name(ChatRootShell, "ChatRootShell");
|
|
2211
|
+
function copy2(text) {
|
|
2212
|
+
if (typeof navigator !== "undefined" && navigator.clipboard) {
|
|
2213
|
+
void navigator.clipboard.writeText(text);
|
|
2214
|
+
}
|
|
2215
|
+
}
|
|
2216
|
+
chunkOLISEQHS_cjs.__name(copy2, "copy");
|
|
2217
|
+
|
|
2218
|
+
exports.Attachments = Attachments;
|
|
2219
|
+
exports.AttachmentsGrid = AttachmentsGrid;
|
|
2220
|
+
exports.AttachmentsList = AttachmentsList;
|
|
2221
|
+
exports.CHAT_EVENT_NAME = CHAT_EVENT_NAME;
|
|
2222
|
+
exports.CSS_VARS = CSS_VARS;
|
|
2223
|
+
exports.ChatProvider = ChatProvider;
|
|
2224
|
+
exports.ChatRoot = ChatRoot;
|
|
2225
|
+
exports.Composer = Composer;
|
|
2226
|
+
exports.DEFAULT_LABELS = DEFAULT_LABELS;
|
|
2227
|
+
exports.DEFAULT_SIDEBAR = DEFAULT_SIDEBAR;
|
|
2228
|
+
exports.DEFAULT_Z_INDEX = DEFAULT_Z_INDEX;
|
|
2229
|
+
exports.EmptyState = EmptyState;
|
|
2230
|
+
exports.ErrorBanner = ErrorBanner;
|
|
2231
|
+
exports.HOTKEYS = HOTKEYS;
|
|
2232
|
+
exports.JumpToLatest = JumpToLatest;
|
|
2233
|
+
exports.LIMITS = LIMITS;
|
|
2234
|
+
exports.MessageActions = MessageActions;
|
|
2235
|
+
exports.MessageBubble = MessageBubble;
|
|
2236
|
+
exports.MessageList = MessageList;
|
|
2237
|
+
exports.STORAGE_KEYS = STORAGE_KEYS;
|
|
2238
|
+
exports.Sources = Sources;
|
|
2239
|
+
exports.StreamingIndicator = StreamingIndicator;
|
|
2240
|
+
exports.ToolCalls = ToolCalls;
|
|
2241
|
+
exports.createId = createId;
|
|
2242
|
+
exports.createTokenBuffer = createTokenBuffer;
|
|
2243
|
+
exports.deriveInitials = deriveInitials;
|
|
2244
|
+
exports.initialState = initialState;
|
|
2245
|
+
exports.reducer = reducer;
|
|
2246
|
+
exports.resolvePersona = resolvePersona;
|
|
2247
|
+
exports.useChat = useChat;
|
|
2248
|
+
exports.useChatAudio = useChatAudio;
|
|
2249
|
+
exports.useChatAudioPrefs = useChatAudioPrefs;
|
|
2250
|
+
exports.useChatComposer = useChatComposer;
|
|
2251
|
+
exports.useChatContext = useChatContext;
|
|
2252
|
+
exports.useChatContextOptional = useChatContextOptional;
|
|
2253
|
+
exports.useChatHistory = useChatHistory;
|
|
2254
|
+
exports.useChatLayout = useChatLayout;
|
|
2255
|
+
exports.useChatScroll = useChatScroll;
|
|
2256
|
+
//# sourceMappingURL=chunk-NRXYYO5V.cjs.map
|
|
2257
|
+
//# sourceMappingURL=chunk-NRXYYO5V.cjs.map
|