vzcode 2.34.0 → 2.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/buildWorker-BZlya278.js +687 -0
- package/dist/assets/index-Cj-ERpBu.css +1 -0
- package/dist/assets/index-DD7vzp4U.js +364 -0
- package/dist/assets/{worker-D8p1JlHW.js → worker-1oQYaz-F.js} +251 -251
- package/dist/assets/worker-BfgPD8zR.js +125 -0
- package/dist/assets/{worker-k7HZ3t-V.js → worker-CoJaqtpi.js} +12 -12
- package/dist/index.html +2 -2
- package/dist/ot.js +180 -2
- package/dist/server/createServer.js +281 -0
- package/dist/server/index.js +6 -269
- package/package.json +14 -3
- package/src/client/CodeEditor/getOrCreateEditor.tsx +0 -14
- package/src/client/VZCodeContext/chatSessionHelpers.ts +17 -0
- package/src/client/VZCodeContext/useAIChatSession.ts +325 -0
- package/src/client/VZCodeContext/useVZCodeState.ts +23 -279
- package/src/client/VZSidebar/AIChatWrapper.tsx +85 -0
- package/src/client/VZSidebar/VisualEditor/VisualEditor.tsx +95 -208
- package/src/client/VZSidebar/VisualEditor/colorUtils.ts +39 -0
- package/src/client/VZSidebar/VisualEditor/status.ts +2 -40
- package/src/client/VZSidebar/VisualEditor/updateConfig.ts +10 -1
- package/src/client/VZSidebar/VisualEditor/utils.ts +49 -65
- package/src/client/VZSidebar/index.tsx +2 -2
- package/src/client/definitionJumpListeners.ts +47 -0
- package/src/client/useKeyboardShortcuts.ts +23 -28
- package/src/client/useOpenDirectories.ts +0 -1
- package/src/llm-streaming-server/README.md +5 -3
- package/src/llm-streaming-ui/README.md +44 -42
- package/src/llm-streaming-ui/components/ChatInput.tsx +6 -19
- package/src/llm-streaming-ui/components/DiffView.tsx +6 -24
- package/src/llm-streaming-ui/components/FileEditingIndicator.tsx +1 -1
- package/src/llm-streaming-ui/components/Message.tsx +11 -27
- package/src/llm-streaming-ui/components/MessageList.tsx +15 -29
- package/src/llm-streaming-ui/components/Spinner.scss +37 -0
- package/src/llm-streaming-ui/components/Spinner.tsx +59 -0
- package/src/llm-streaming-ui/components/bootstrap.ts +16 -0
- package/src/llm-streaming-ui/components/icons.tsx +68 -0
- package/src/llm-streaming-ui/components/index.tsx +34 -30
- package/src/llm-streaming-ui/index.ts +13 -0
- package/src/llm-streaming-ui/props.ts +137 -0
- package/src/ot.ts +221 -4
- package/src/server/createServer.ts +413 -0
- package/src/server/index.ts +8 -333
- package/dist/assets/buildWorker-DylWm2VX.js +0 -687
- package/dist/assets/index-Dyt9tpmu.css +0 -1
- package/dist/assets/index-nL6to42p.js +0 -364
- package/dist/assets/worker-b9bkZkXK.js +0 -116
- package/src/client/AIAssist/AIAssistCodeMirrorKeyMap.ts +0 -42
- package/src/client/AIAssist/generateFilesContext.ts +0 -25
- package/src/client/AIAssist/index.ts +0 -2
- package/src/client/CodeEditor/InteractiveWidgets/highlightWidgets.ts +0 -79
- /package/src/{client → llm-streaming-ui}/hooks/useAutoScroll.ts +0 -0
- /package/src/{client → llm-streaming-ui}/utils/scrollUtils.ts +0 -0
|
@@ -1,31 +1,10 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
useMemo,
|
|
3
|
-
useContext,
|
|
4
|
-
forwardRef,
|
|
5
|
-
} from 'react';
|
|
1
|
+
import React, { useMemo, forwardRef } from 'react';
|
|
6
2
|
import { timestampToDate } from '@vizhub/viz-utils';
|
|
7
3
|
import Markdown from 'react-markdown';
|
|
8
4
|
import remarkGfm from 'remark-gfm';
|
|
9
|
-
import { StreamingEvent } from '../../types.js';
|
|
10
5
|
import { IndividualFileDiff } from './IndividualFileDiff';
|
|
11
|
-
import { VZCodeContext } from '../../client/VZCodeContext';
|
|
12
6
|
import { DiffView, DiffViewRef } from './DiffView';
|
|
13
|
-
import {
|
|
14
|
-
import { enableDiffView } from '../../client/featureFlags';
|
|
15
|
-
|
|
16
|
-
interface MessageProps {
|
|
17
|
-
id: string;
|
|
18
|
-
role: 'user' | 'assistant';
|
|
19
|
-
content?: string; // For non-streaming messages
|
|
20
|
-
timestamp: number;
|
|
21
|
-
events?: StreamingEvent[]; // For streaming messages
|
|
22
|
-
isActive?: boolean; // Is this the currently streaming message?
|
|
23
|
-
chatId?: string;
|
|
24
|
-
showAdditionalWidgets?: boolean;
|
|
25
|
-
isStreaming?: boolean;
|
|
26
|
-
diffData?: UnifiedFilesDiff;
|
|
27
|
-
model?: string; // The LLM model used for this message (assistant only)
|
|
28
|
-
}
|
|
7
|
+
import type { MessageProps } from '../props';
|
|
29
8
|
|
|
30
9
|
export const Message = forwardRef<
|
|
31
10
|
DiffViewRef,
|
|
@@ -45,12 +24,13 @@ export const Message = forwardRef<
|
|
|
45
24
|
isStreaming = false,
|
|
46
25
|
diffData,
|
|
47
26
|
model,
|
|
27
|
+
additionalWidgets,
|
|
28
|
+
handleSendMessage,
|
|
29
|
+
enableDiffView = true,
|
|
30
|
+
onOpenFile,
|
|
48
31
|
},
|
|
49
32
|
ref,
|
|
50
33
|
) => {
|
|
51
|
-
const { additionalWidgets, handleSendMessage } =
|
|
52
|
-
useContext(VZCodeContext);
|
|
53
|
-
|
|
54
34
|
// Memoize date formatting to avoid repeated computation
|
|
55
35
|
const formattedTime = useMemo(() => {
|
|
56
36
|
return timestampToDate(timestamp).toLocaleTimeString(
|
|
@@ -86,7 +66,11 @@ export const Message = forwardRef<
|
|
|
86
66
|
{enableDiffView &&
|
|
87
67
|
diffData &&
|
|
88
68
|
Object.keys(diffData).length > 0 && (
|
|
89
|
-
<DiffView
|
|
69
|
+
<DiffView
|
|
70
|
+
diffData={diffData}
|
|
71
|
+
ref={ref}
|
|
72
|
+
onOpenFile={onOpenFile}
|
|
73
|
+
/>
|
|
90
74
|
)}
|
|
91
75
|
|
|
92
76
|
{/* Render events in order for streaming messages */}
|
|
@@ -1,49 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useRef,
|
|
3
|
-
useEffect,
|
|
4
|
-
memo,
|
|
5
|
-
useState,
|
|
6
|
-
useContext,
|
|
7
|
-
} from 'react';
|
|
1
|
+
import { useRef, useEffect, memo, useState } from 'react';
|
|
8
2
|
import { Message } from './Message';
|
|
9
3
|
import { TypingIndicator } from './TypingIndicator';
|
|
10
4
|
import { ThinkingScratchpad } from './ThinkingScratchpad';
|
|
11
5
|
import { AIEditingStatusIndicator } from './FileEditingIndicator';
|
|
12
|
-
import { VizChatMessage } from '@vizhub/viz-types';
|
|
13
6
|
import { ExtendedVizChatMessage } from '../../types.js';
|
|
14
7
|
import { DiffViewRef } from './DiffView.js';
|
|
15
|
-
import {
|
|
8
|
+
import type { MessageListProps } from '../props';
|
|
16
9
|
|
|
17
10
|
const MessageListComponent = ({
|
|
18
11
|
messages,
|
|
19
12
|
isLoading,
|
|
20
|
-
chatId,
|
|
21
|
-
aiScratchpad,
|
|
22
|
-
currentStatus,
|
|
23
|
-
model,
|
|
13
|
+
chatId,
|
|
14
|
+
aiScratchpad,
|
|
15
|
+
currentStatus,
|
|
16
|
+
model,
|
|
24
17
|
onNewEvent,
|
|
25
18
|
onJumpToLatest,
|
|
26
19
|
beforeRender,
|
|
27
20
|
afterRender,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
currentStatus?: string; // Add current status to the type
|
|
34
|
-
model?: string; // Add model to the type
|
|
35
|
-
onNewEvent: (targetElement?: HTMLElement) => void;
|
|
36
|
-
onJumpToLatest: (targetElement?: HTMLElement) => void;
|
|
37
|
-
beforeRender: () => number;
|
|
38
|
-
afterRender: (prevScrollHeight: number) => void;
|
|
39
|
-
}) => {
|
|
21
|
+
additionalWidgets,
|
|
22
|
+
handleSendMessage,
|
|
23
|
+
enableDiffView,
|
|
24
|
+
onOpenFile,
|
|
25
|
+
}: MessageListProps) => {
|
|
40
26
|
const messagesEndRef = useRef<HTMLDivElement>(null);
|
|
41
27
|
const diffViewRef = useRef<DiffViewRef>(null);
|
|
42
28
|
|
|
43
|
-
// Get additional widgets from context
|
|
44
|
-
const { additionalWidgets, handleSendMessage } =
|
|
45
|
-
useContext(VZCodeContext);
|
|
46
|
-
|
|
47
29
|
// Track previous loading state to detect when AI generation completes
|
|
48
30
|
const [prevIsLoading, setPrevIsLoading] =
|
|
49
31
|
useState(isLoading);
|
|
@@ -197,6 +179,10 @@ const MessageListComponent = ({
|
|
|
197
179
|
model={
|
|
198
180
|
msg.role === 'assistant' ? model : undefined
|
|
199
181
|
}
|
|
182
|
+
additionalWidgets={additionalWidgets}
|
|
183
|
+
handleSendMessage={handleSendMessage}
|
|
184
|
+
enableDiffView={enableDiffView}
|
|
185
|
+
onOpenFile={onOpenFile}
|
|
200
186
|
ref={
|
|
201
187
|
isLastMessage && (msg as any).diffData
|
|
202
188
|
? diffViewRef
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
.vh-spinner {
|
|
2
|
+
display: flex;
|
|
3
|
+
height: 100%;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
align-items: center;
|
|
6
|
+
justify-content: center;
|
|
7
|
+
overflow: hidden;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/* Fade in after a delay */
|
|
11
|
+
.vh-spinner.fade-in svg {
|
|
12
|
+
animation: 1s linear 0s normal forwards 1
|
|
13
|
+
llm-spinner-fadein;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@keyframes llm-spinner-fadein {
|
|
17
|
+
0% {
|
|
18
|
+
opacity: 0;
|
|
19
|
+
}
|
|
20
|
+
50% {
|
|
21
|
+
opacity: 0;
|
|
22
|
+
}
|
|
23
|
+
100% {
|
|
24
|
+
opacity: 1;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* Infinite rotation */
|
|
29
|
+
.vh-spinner-dots {
|
|
30
|
+
animation: llm-spinner-rotate 3s linear infinite;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@keyframes llm-spinner-rotate {
|
|
34
|
+
to {
|
|
35
|
+
transform: rotate(360deg);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// From https://github.com/vizhub-core/vizhub/commit/6ca078935b9771dc6e05a6065bcfd522a4724dcf
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import './Spinner.scss';
|
|
4
|
+
|
|
5
|
+
// Hardcoded dot positions to avoid runtime computation.
|
|
6
|
+
const dots = [
|
|
7
|
+
{ x: 40, y: 0, r: 4 },
|
|
8
|
+
{ x: 28.28, y: 28.28, r: 4.85 },
|
|
9
|
+
{ x: 0, y: 40, r: 5.71 },
|
|
10
|
+
{ x: -28.29, y: 28.28, r: 6.57 },
|
|
11
|
+
{ x: -40, y: 0, r: 7.42 },
|
|
12
|
+
{ x: -28.29, y: -28.29, r: 8.28 },
|
|
13
|
+
{ x: -0.01, y: -40, r: 9.14 },
|
|
14
|
+
{ x: 28.28, y: -28.29, r: 10 },
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
export const Spinner = ({
|
|
18
|
+
height = 40,
|
|
19
|
+
fill = 'currentcolor',
|
|
20
|
+
fadeIn = true,
|
|
21
|
+
}: {
|
|
22
|
+
height?: number;
|
|
23
|
+
fill?: string;
|
|
24
|
+
fadeIn?: boolean;
|
|
25
|
+
}) => {
|
|
26
|
+
const [show, setShow] = useState(false);
|
|
27
|
+
|
|
28
|
+
// Avoid SSR of all the SVG elements.
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
setShow(true);
|
|
31
|
+
}, []);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
show && (
|
|
35
|
+
<div
|
|
36
|
+
className={`vh-spinner${fadeIn ? ' fade-in' : ''}`}
|
|
37
|
+
>
|
|
38
|
+
<svg
|
|
39
|
+
height={height}
|
|
40
|
+
viewBox="0 0 100 100"
|
|
41
|
+
style={{ opacity: 1 }}
|
|
42
|
+
>
|
|
43
|
+
<g transform="translate(50, 50)" fill={fill}>
|
|
44
|
+
<g className="vh-spinner-dots">
|
|
45
|
+
{dots.map(({ x, y, r }, i) => (
|
|
46
|
+
<circle
|
|
47
|
+
key={i}
|
|
48
|
+
cx={x}
|
|
49
|
+
cy={y}
|
|
50
|
+
r={r}
|
|
51
|
+
></circle>
|
|
52
|
+
))}
|
|
53
|
+
</g>
|
|
54
|
+
</g>
|
|
55
|
+
</svg>
|
|
56
|
+
</div>
|
|
57
|
+
)
|
|
58
|
+
);
|
|
59
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// A central place where the LLM streaming UI imports what it needs from
|
|
2
|
+
// react-bootstrap. This strange-looking way of importing makes it work
|
|
3
|
+
// with Vite's SSR build: otherwise we get
|
|
4
|
+
// `Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import`.
|
|
5
|
+
import Form from 'react-bootstrap/cjs/Form.js';
|
|
6
|
+
import Button from 'react-bootstrap/cjs/Button.js';
|
|
7
|
+
import ButtonGroup from 'react-bootstrap/cjs/ButtonGroup.js';
|
|
8
|
+
import ToggleButton from 'react-bootstrap/cjs/ToggleButton.js';
|
|
9
|
+
|
|
10
|
+
// Pull in custom CSS from vizhub-ui.
|
|
11
|
+
import 'vizhub-ui/dist/vizhub-ui.css';
|
|
12
|
+
|
|
13
|
+
// Pull in Bootstrap Icons CSS.
|
|
14
|
+
import 'bootstrap-icons/font/bootstrap-icons.css';
|
|
15
|
+
|
|
16
|
+
export { Form, Button, ButtonGroup, ToggleButton };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-contained presentational icons used by the LLM streaming UI.
|
|
3
|
+
*
|
|
4
|
+
* These are intentionally duplicated (rather than imported from a host
|
|
5
|
+
* application) so the components stay usable as a standalone library.
|
|
6
|
+
* Hosts can override them via the `icons` prop where supported.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const MicSVG = () => (
|
|
10
|
+
<svg
|
|
11
|
+
fill="#000000"
|
|
12
|
+
height="24"
|
|
13
|
+
width="24"
|
|
14
|
+
stroke="currentColor"
|
|
15
|
+
version="1.1"
|
|
16
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
17
|
+
viewBox="0 0 512 512"
|
|
18
|
+
enableBackground="new 0 0 512 512"
|
|
19
|
+
>
|
|
20
|
+
<g>
|
|
21
|
+
<g>
|
|
22
|
+
<path
|
|
23
|
+
fill="currentColor"
|
|
24
|
+
d="m439.5,236c0-11.3-9.1-20.4-20.4-20.4s-20.4,9.1-20.4,20.4c0,70-64,126.9-142.7,126.9-78.7,0-142.7-56.9-142.7-126.9 0-11.3-9.1-20.4-20.4-20.4s-20.4,9.1-20.4,20.4c0,86.2 71.5,157.4 163.1,166.7v57.5h-23.6c-11.3,0-20.4,9.1-20.4,20.4 0,11.3 9.1,20.4 20.4,20.4h88c11.3,0 20.4-9.1 20.4-20.4 0-11.3-9.1-20.4-20.4-20.4h-23.6v-57.5c91.6-9.3 163.1-80.5 163.1-166.7z"
|
|
25
|
+
/>
|
|
26
|
+
<path
|
|
27
|
+
fill="currentColor"
|
|
28
|
+
d="m256,323.5c51,0 92.3-41.3 92.3-92.3v-127.9c0-51-41.3-92.3-92.3-92.3s-92.3,41.3-92.3,92.3v127.9c0,51 41.3,92.3 92.3,92.3zm-52.3-220.2c0-28.8 23.5-52.3 52.3-52.3s52.3,23.5 52.3,52.3v127.9c0,28.8-23.5,52.3-52.3,52.3s-52.3-23.5-52.3-52.3v-127.9z"
|
|
29
|
+
/>
|
|
30
|
+
</g>
|
|
31
|
+
</g>
|
|
32
|
+
</svg>
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
export const MicOffSVG = () => (
|
|
36
|
+
<svg
|
|
37
|
+
fill="#000000"
|
|
38
|
+
height="24"
|
|
39
|
+
width="24"
|
|
40
|
+
stroke="currentColor"
|
|
41
|
+
version="1.1"
|
|
42
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
43
|
+
viewBox="0 0 512 512"
|
|
44
|
+
enableBackground="new 0 0 512 512"
|
|
45
|
+
>
|
|
46
|
+
<g>
|
|
47
|
+
<g>
|
|
48
|
+
<path
|
|
49
|
+
fill="currentColor"
|
|
50
|
+
d="m439.5,236c0-11.3-9.1-20.4-20.4-20.4s-20.4,9.1-20.4,20.4c0,70-64,126.9-142.7,126.9-78.7,0-142.7-56.9-142.7-126.9 0-11.3-9.1-20.4-20.4-20.4s-20.4,9.1-20.4,20.4c0,86.2 71.5,157.4 163.1,166.7v57.5h-23.6c-11.3,0-20.4,9.1-20.4,20.4 0,11.3 9.1,20.4 20.4,20.4h88c11.3,0 20.4-9.1 20.4-20.4 0-11.3-9.1-20.4-20.4-20.4h-23.6v-57.5c91.6-9.3 163.1-80.5 163.1-166.7z"
|
|
51
|
+
/>
|
|
52
|
+
<path
|
|
53
|
+
fill="currentColor"
|
|
54
|
+
d="m256,323.5c51,0 92.3-41.3 92.3-92.3v-127.9c0-51-41.3-92.3-92.3-92.3s-92.3,41.3-92.3,92.3v127.9c0,51 41.3,92.3 92.3,92.3zm-52.3-220.2c0-28.8 23.5-52.3 52.3-52.3s52.3,23.5 52.3,52.3v127.9c0,28.8-23.5,52.3-52.3,52.3s-52.3-23.5-52.3-52.3v-127.9z"
|
|
55
|
+
/>
|
|
56
|
+
<line
|
|
57
|
+
x1="100"
|
|
58
|
+
y1="100"
|
|
59
|
+
x2="412"
|
|
60
|
+
y2="412"
|
|
61
|
+
stroke="currentColor"
|
|
62
|
+
strokeWidth="40"
|
|
63
|
+
strokeLinecap="round"
|
|
64
|
+
/>
|
|
65
|
+
</g>
|
|
66
|
+
</g>
|
|
67
|
+
</svg>
|
|
68
|
+
);
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useContext,
|
|
3
|
-
useMemo,
|
|
4
|
-
useEffect,
|
|
5
|
-
useCallback,
|
|
6
|
-
} from 'react';
|
|
7
|
-
import { VZCodeContext } from '../../client/VZCodeContext';
|
|
1
|
+
import { useMemo, useEffect, useCallback } from 'react';
|
|
8
2
|
import { MessageList } from './MessageList';
|
|
9
3
|
import { ChatInput } from './ChatInput';
|
|
10
4
|
import { ExtendedVizChat } from '../../types.js';
|
|
11
|
-
import { useAutoScroll } from '
|
|
5
|
+
import { useAutoScroll } from '../hooks/useAutoScroll';
|
|
12
6
|
import { JumpToLatestButton } from './JumpToLatestButton';
|
|
7
|
+
import type { AIChatProps } from '../props';
|
|
13
8
|
import './styles.scss';
|
|
14
9
|
|
|
15
10
|
const DEBUG = false;
|
|
@@ -47,27 +42,30 @@ const ChatList = ({
|
|
|
47
42
|
);
|
|
48
43
|
};
|
|
49
44
|
|
|
50
|
-
export const AIChat = (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
45
|
+
export const AIChat = ({
|
|
46
|
+
aiChatFocused,
|
|
47
|
+
content,
|
|
48
|
+
aiChatMode,
|
|
49
|
+
aiChatMessage,
|
|
50
|
+
currentChatId,
|
|
51
|
+
selectedChatId,
|
|
52
|
+
setSelectedChatId,
|
|
53
|
+
aiErrorMessage,
|
|
54
|
+
setAIChatMode,
|
|
55
|
+
getStoredAIPrompt,
|
|
56
|
+
setAIChatMessage,
|
|
57
|
+
handleSendMessage,
|
|
58
|
+
setAIErrorMessage,
|
|
59
|
+
navigateMessageHistoryUp,
|
|
60
|
+
navigateMessageHistoryDown,
|
|
61
|
+
resetMessageHistoryNavigation,
|
|
62
|
+
enableMinimalEditFlow = false,
|
|
63
|
+
additionalWidgets,
|
|
64
|
+
enableDiffView = true,
|
|
65
|
+
enableAskMode = false,
|
|
66
|
+
enableVoiceInput = false,
|
|
67
|
+
onOpenFile,
|
|
68
|
+
}: AIChatProps) => {
|
|
71
69
|
// Use the new simplified auto-scroll hook
|
|
72
70
|
const {
|
|
73
71
|
containerRef: messagesContainerRef,
|
|
@@ -336,6 +334,10 @@ export const AIChat = () => {
|
|
|
336
334
|
onJumpToLatest={onJumpToLatest}
|
|
337
335
|
beforeRender={beforeRender}
|
|
338
336
|
afterRender={afterRender}
|
|
337
|
+
additionalWidgets={additionalWidgets}
|
|
338
|
+
handleSendMessage={handleSendMessage}
|
|
339
|
+
enableDiffView={enableDiffView}
|
|
340
|
+
onOpenFile={onOpenFile}
|
|
339
341
|
/>
|
|
340
342
|
)}
|
|
341
343
|
{aiErrorMessage && (
|
|
@@ -369,9 +371,11 @@ export const AIChat = () => {
|
|
|
369
371
|
aiChatMessage={aiChatMessage}
|
|
370
372
|
setAIChatMessage={setAIChatMessage}
|
|
371
373
|
onSendMessage={handleSendMessageWithSelection}
|
|
372
|
-
focused={aiChatFocused}
|
|
374
|
+
focused={aiChatFocused ?? false}
|
|
373
375
|
aiChatMode={aiChatMode}
|
|
374
376
|
setAIChatMode={setAIChatMode}
|
|
377
|
+
enableAskMode={enableAskMode}
|
|
378
|
+
enableVoiceInput={enableVoiceInput}
|
|
375
379
|
navigateMessageHistoryUp={
|
|
376
380
|
navigateMessageHistoryUp
|
|
377
381
|
}
|
|
@@ -32,3 +32,16 @@ export { ChatInput } from './components/ChatInput.js';
|
|
|
32
32
|
|
|
33
33
|
// Custom hooks
|
|
34
34
|
export { useSpeechRecognition } from './components/useSpeechRecognition.js';
|
|
35
|
+
export { useAutoScroll } from './hooks/useAutoScroll.js';
|
|
36
|
+
|
|
37
|
+
// Public prop types
|
|
38
|
+
export type {
|
|
39
|
+
AIChatProps,
|
|
40
|
+
AIChatMode,
|
|
41
|
+
AdditionalWidgets,
|
|
42
|
+
ChatInputProps,
|
|
43
|
+
DiffViewProps,
|
|
44
|
+
HandleSendMessage,
|
|
45
|
+
MessageListProps,
|
|
46
|
+
MessageProps,
|
|
47
|
+
} from './props.js';
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
VizContent,
|
|
4
|
+
VizChatMessage,
|
|
5
|
+
} from '@vizhub/viz-types';
|
|
6
|
+
|
|
7
|
+
/** Chat mode: ask a question, or request an edit. */
|
|
8
|
+
export type AIChatMode = 'ask' | 'edit';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Sends a chat message. Optionally accepts an explicit message to send
|
|
12
|
+
* (used by suggested prompts) and extra request options.
|
|
13
|
+
*/
|
|
14
|
+
export type HandleSendMessage = (
|
|
15
|
+
messageToSend?: string,
|
|
16
|
+
options?: Record<string, string>,
|
|
17
|
+
) => Promise<unknown>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Host-provided renderer for extra widgets shown on completed AI
|
|
21
|
+
* messages (e.g. VizHub's "open visualization" actions).
|
|
22
|
+
*/
|
|
23
|
+
export type AdditionalWidgets = (props: {
|
|
24
|
+
messageId: string;
|
|
25
|
+
chatId: string;
|
|
26
|
+
handleSendMessage?: HandleSendMessage;
|
|
27
|
+
}) => ReactNode;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Props for the main `AIChat` component.
|
|
31
|
+
*
|
|
32
|
+
* The component is fully controlled: it owns no application state and
|
|
33
|
+
* reads nothing from VZCode context. Wrap it with `AIChatWrapper` to
|
|
34
|
+
* bind these props to a host application's state.
|
|
35
|
+
*/
|
|
36
|
+
export interface AIChatProps {
|
|
37
|
+
/** ShareDB content, used to read chats and resolve file links. */
|
|
38
|
+
content: VizContent | null;
|
|
39
|
+
/** Whether the chat input should steal focus. */
|
|
40
|
+
aiChatFocused?: boolean;
|
|
41
|
+
aiChatMode: AIChatMode;
|
|
42
|
+
setAIChatMode: (mode: AIChatMode) => void;
|
|
43
|
+
aiChatMessage: string;
|
|
44
|
+
setAIChatMessage: (message: string) => void;
|
|
45
|
+
aiErrorMessage: string | null;
|
|
46
|
+
setAIErrorMessage: (error: string | null) => void;
|
|
47
|
+
/** The chat currently being written to. */
|
|
48
|
+
currentChatId: string;
|
|
49
|
+
/** The chat selected for display (may be null). */
|
|
50
|
+
selectedChatId: string | null;
|
|
51
|
+
setSelectedChatId: (chatId: string | null) => void;
|
|
52
|
+
handleSendMessage: HandleSendMessage;
|
|
53
|
+
navigateMessageHistoryUp: () => void;
|
|
54
|
+
navigateMessageHistoryDown: () => void;
|
|
55
|
+
resetMessageHistoryNavigation: () => void;
|
|
56
|
+
/**
|
|
57
|
+
* Used to restore a prompt after a fork (e.g. VizHub). Returning null
|
|
58
|
+
* means there is nothing to restore.
|
|
59
|
+
*/
|
|
60
|
+
getStoredAIPrompt?: () => {
|
|
61
|
+
prompt: string;
|
|
62
|
+
modelName: string;
|
|
63
|
+
} | null;
|
|
64
|
+
/** Called with a file name when a file link in a diff is clicked. */
|
|
65
|
+
onOpenFile?: (fileName: string) => void;
|
|
66
|
+
/** Extra widgets rendered on completed AI messages. */
|
|
67
|
+
additionalWidgets?: AdditionalWidgets;
|
|
68
|
+
/** Show the diff view for file edits. */
|
|
69
|
+
enableDiffView?: boolean;
|
|
70
|
+
/** Show the ask/edit mode toggle in the input. */
|
|
71
|
+
enableAskMode?: boolean;
|
|
72
|
+
/** Show the voice input microphone button. */
|
|
73
|
+
enableVoiceInput?: boolean;
|
|
74
|
+
/** Whether the minimal AI edit flow is enabled. */
|
|
75
|
+
enableMinimalEditFlow?: boolean;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Props for the chat input field. */
|
|
79
|
+
export interface ChatInputProps {
|
|
80
|
+
aiChatMessage: string;
|
|
81
|
+
setAIChatMessage: (message: string) => void;
|
|
82
|
+
onSendMessage: () => void;
|
|
83
|
+
focused: boolean;
|
|
84
|
+
aiChatMode: AIChatMode;
|
|
85
|
+
setAIChatMode: (mode: AIChatMode) => void;
|
|
86
|
+
navigateMessageHistoryUp: () => void;
|
|
87
|
+
navigateMessageHistoryDown: () => void;
|
|
88
|
+
resetMessageHistoryNavigation: () => void;
|
|
89
|
+
/** Show the ask/edit mode toggle. */
|
|
90
|
+
enableAskMode?: boolean;
|
|
91
|
+
/** Show the voice input microphone button. */
|
|
92
|
+
enableVoiceInput?: boolean;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Props for the unified diff view. */
|
|
96
|
+
export interface DiffViewProps {
|
|
97
|
+
diffData: import('../utils/fileDiff').UnifiedFilesDiff;
|
|
98
|
+
/** Called with a file name when the user clicks it in the diff. */
|
|
99
|
+
onOpenFile?: (fileName: string) => void;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Props for the scrollable message list. */
|
|
103
|
+
export interface MessageListProps {
|
|
104
|
+
messages: VizChatMessage[];
|
|
105
|
+
isLoading: boolean;
|
|
106
|
+
chatId?: string;
|
|
107
|
+
aiScratchpad?: string;
|
|
108
|
+
currentStatus?: string;
|
|
109
|
+
model?: string;
|
|
110
|
+
onNewEvent: (targetElement?: HTMLElement) => void;
|
|
111
|
+
onJumpToLatest: (targetElement?: HTMLElement) => void;
|
|
112
|
+
beforeRender: () => number;
|
|
113
|
+
afterRender: (prevScrollHeight: number) => void;
|
|
114
|
+
additionalWidgets?: AdditionalWidgets;
|
|
115
|
+
handleSendMessage?: HandleSendMessage;
|
|
116
|
+
enableDiffView?: boolean;
|
|
117
|
+
onOpenFile?: (fileName: string) => void;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Props for a single chat message. */
|
|
121
|
+
export interface MessageProps {
|
|
122
|
+
id: string;
|
|
123
|
+
role: 'user' | 'assistant';
|
|
124
|
+
content?: string;
|
|
125
|
+
timestamp: number;
|
|
126
|
+
events?: import('../types.js').StreamingEvent[];
|
|
127
|
+
isActive?: boolean;
|
|
128
|
+
chatId?: string;
|
|
129
|
+
showAdditionalWidgets?: boolean;
|
|
130
|
+
isStreaming?: boolean;
|
|
131
|
+
diffData?: import('../utils/fileDiff').UnifiedFilesDiff;
|
|
132
|
+
model?: string;
|
|
133
|
+
additionalWidgets?: AdditionalWidgets;
|
|
134
|
+
handleSendMessage?: HandleSendMessage;
|
|
135
|
+
enableDiffView?: boolean;
|
|
136
|
+
onOpenFile?: (fileName: string) => void;
|
|
137
|
+
}
|