vzcode 3.1.0 → 3.3.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/README.md +185 -40
- package/dist/assets/App-C9mRI7eH.js +387 -0
- package/dist/assets/App-CxiKy3Rs.css +1 -0
- package/dist/assets/bindings_wasm_bg-IWNG_AjZ.wasm +0 -0
- package/dist/assets/buildWorker-N5tFTOqM.js +794 -0
- package/dist/assets/index-COLyIkCc.js +43 -0
- package/dist/assets/index-CZT-v4sH.css +1 -0
- package/dist/assets/rolldown-runtime-COiEfhsA.js +1 -0
- package/dist/assets/worker-BpV7Ustv.js +223 -0
- package/dist/assets/worker-CLeezw6h.js +458 -0
- package/dist/assets/worker-DaSIYBQX.js +327 -0
- package/dist/cli.js +170 -99
- package/dist/index.html +3 -2
- package/dist/server/accessControl.js +104 -0
- package/dist/server/computeInitialDocument.js +4 -1
- package/dist/server/createServer.js +356 -104
- package/dist/server/index.js +4 -3
- package/dist/server/workspaceSecurity.js +115 -0
- package/dist/server/workspaceSync.js +141 -0
- package/package.json +74 -72
- package/src/cli.ts +203 -182
- package/src/client/App/index.tsx +2 -0
- package/src/client/App/usePending.ts +3 -1
- package/src/client/CodeEditor/style.scss +18 -11
- package/src/client/RunCodeWidget/index.tsx +1 -0
- package/src/client/TabList/Tab.tsx +13 -5
- package/src/client/TabList/style.scss +32 -5
- package/src/client/VZCodeContext/types.ts +6 -0
- package/src/client/VZCodeContext/useVZCodeState.ts +2 -0
- package/src/client/VZResizer/styles.scss +1 -1
- package/src/client/VZSidebar/AIChatWrapper.tsx +2 -0
- package/src/client/VZSidebar/DeleteConfirmationModal.tsx +1 -1
- package/src/client/VZSidebar/Item.tsx +8 -4
- package/src/client/VZSidebar/VisualEditor/CheckboxWidget.tsx +22 -30
- package/src/client/VZSidebar/VisualEditor/ColorWidget.tsx +198 -126
- package/src/client/VZSidebar/VisualEditor/DropdownWidget.tsx +25 -67
- package/src/client/VZSidebar/VisualEditor/PropertySection.tsx +41 -0
- package/src/client/VZSidebar/VisualEditor/SegmentedWidget.tsx +34 -0
- package/src/client/VZSidebar/VisualEditor/SliderWidget.tsx +60 -12
- package/src/client/VZSidebar/VisualEditor/VisualEditor.tsx +31 -393
- package/src/client/VZSidebar/VisualEditor/VisualEditorControls.tsx +478 -0
- package/src/client/VZSidebar/VisualEditor/colorUtils.ts +12 -0
- package/src/client/VZSidebar/VisualEditor/status.ts +47 -0
- package/src/client/VZSidebar/VisualEditor/updateConfig.ts +51 -24
- package/src/client/VZSidebar/VisualEditor/utils.ts +1 -1
- package/src/client/VZSidebar/index.tsx +55 -23
- package/src/client/VZSidebar/styles.scss +426 -6
- package/src/client/WorkspaceConflictBanner.tsx +120 -0
- package/src/client/index.ts +2 -0
- package/src/client/main.jsx +54 -12
- package/src/client/ui.scss +156 -4
- package/src/client/ui.tsx +1 -1
- package/src/llm-streaming-server/README.md +4 -16
- package/src/llm-streaming-ui/README.md +41 -2
- package/src/llm-streaming-ui/components/ChatInput.tsx +65 -13
- package/src/llm-streaming-ui/components/index.tsx +2 -0
- package/src/llm-streaming-ui/components/styles.scss +46 -0
- package/src/llm-streaming-ui/hooks/useAutoScroll.ts +1 -1
- package/src/llm-streaming-ui/index.ts +1 -0
- package/src/llm-streaming-ui/props.ts +26 -2
- package/src/server/accessControl.ts +151 -0
- package/src/server/computeInitialDocument.ts +6 -2
- package/src/server/createServer.ts +487 -138
- package/src/server/index.ts +4 -5
- package/src/server/workspaceSecurity.ts +160 -0
- package/src/server/workspaceSync.ts +203 -0
- package/src/types.ts +29 -27
- package/dist/assets/bindings_wasm_bg-9w8E-TmY.wasm +0 -0
- package/dist/assets/buildWorker-BZlya278.js +0 -687
- package/dist/assets/index-5qf102c2.css +0 -1
- package/dist/assets/index-dSJDl5x9.js +0 -356
- package/dist/assets/worker-1oQYaz-F.js +0 -342
- package/dist/assets/worker-BfgPD8zR.js +0 -125
- package/dist/assets/worker-CoJaqtpi.js +0 -436
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { useContext, useState } from 'react';
|
|
2
|
+
import { VZCodeContext } from './VZCodeContext';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Standalone-only conflict resolution. Embedded hosts can provide their
|
|
6
|
+
* own affordance for external file conflicts.
|
|
7
|
+
*/
|
|
8
|
+
export const WorkspaceConflictBanner = () => {
|
|
9
|
+
const { content } = useContext(VZCodeContext);
|
|
10
|
+
const conflicts: string[] =
|
|
11
|
+
(
|
|
12
|
+
content as unknown as {
|
|
13
|
+
workspaceConflicts?: string[];
|
|
14
|
+
} | null
|
|
15
|
+
)?.workspaceConflicts ?? [];
|
|
16
|
+
const [busy, setBusy] = useState<string | null>(null);
|
|
17
|
+
const [error, setError] = useState<string | null>(null);
|
|
18
|
+
|
|
19
|
+
if (!conflicts.length) return null;
|
|
20
|
+
|
|
21
|
+
const resolve = async (
|
|
22
|
+
name: string,
|
|
23
|
+
choice: 'disk' | 'editor',
|
|
24
|
+
) => {
|
|
25
|
+
if (
|
|
26
|
+
choice === 'editor' &&
|
|
27
|
+
!window.confirm(
|
|
28
|
+
'Overwrite the external disk changes for "' +
|
|
29
|
+
name +
|
|
30
|
+
'" with the editor version?',
|
|
31
|
+
)
|
|
32
|
+
) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
setBusy(name);
|
|
36
|
+
setError(null);
|
|
37
|
+
try {
|
|
38
|
+
const response = await fetch(
|
|
39
|
+
'/workspace-conflicts/resolve',
|
|
40
|
+
{
|
|
41
|
+
method: 'POST',
|
|
42
|
+
credentials: 'same-origin',
|
|
43
|
+
headers: {
|
|
44
|
+
'Content-Type': 'application/json',
|
|
45
|
+
},
|
|
46
|
+
body: JSON.stringify({ name, choice }),
|
|
47
|
+
},
|
|
48
|
+
);
|
|
49
|
+
if (!response.ok) {
|
|
50
|
+
const body = await response
|
|
51
|
+
.json()
|
|
52
|
+
.catch(() => ({}));
|
|
53
|
+
throw new Error(
|
|
54
|
+
body.error || 'Unable to resolve conflict',
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
} catch (caught: any) {
|
|
58
|
+
setError(caught.message ?? String(caught));
|
|
59
|
+
} finally {
|
|
60
|
+
setBusy(null);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<aside
|
|
66
|
+
role="alert"
|
|
67
|
+
aria-live="polite"
|
|
68
|
+
style={{
|
|
69
|
+
position: 'fixed',
|
|
70
|
+
top: 8,
|
|
71
|
+
left: '50%',
|
|
72
|
+
transform: 'translateX(-50%)',
|
|
73
|
+
zIndex: 10000,
|
|
74
|
+
maxHeight: '45vh',
|
|
75
|
+
overflowY: 'auto',
|
|
76
|
+
maxWidth: 'min(600px, 95vw)',
|
|
77
|
+
padding: 14,
|
|
78
|
+
borderRadius: 8,
|
|
79
|
+
background: '#fff4dc',
|
|
80
|
+
color: '#3a2a12',
|
|
81
|
+
border: '1px solid #d6a341',
|
|
82
|
+
boxShadow: '0 4px 20px #0003',
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
<strong>External filesystem conflict</strong>
|
|
86
|
+
<p>
|
|
87
|
+
Changes were made to these files outside VZCode
|
|
88
|
+
while there were unsaved editor changes. Autosave is
|
|
89
|
+
paused to prevent data loss.
|
|
90
|
+
</p>
|
|
91
|
+
{conflicts.map((name) => (
|
|
92
|
+
<div
|
|
93
|
+
key={name}
|
|
94
|
+
style={{
|
|
95
|
+
display: 'flex',
|
|
96
|
+
flexWrap: 'wrap',
|
|
97
|
+
alignItems: 'center',
|
|
98
|
+
gap: 8,
|
|
99
|
+
marginBottom: 8,
|
|
100
|
+
}}
|
|
101
|
+
>
|
|
102
|
+
<code>{name}</code>
|
|
103
|
+
<button
|
|
104
|
+
disabled={busy !== null}
|
|
105
|
+
onClick={() => void resolve(name, 'disk')}
|
|
106
|
+
>
|
|
107
|
+
Load disk version
|
|
108
|
+
</button>
|
|
109
|
+
<button
|
|
110
|
+
disabled={busy !== null}
|
|
111
|
+
onClick={() => void resolve(name, 'editor')}
|
|
112
|
+
>
|
|
113
|
+
Overwrite disk with editor
|
|
114
|
+
</button>
|
|
115
|
+
</div>
|
|
116
|
+
))}
|
|
117
|
+
{error ? <p>{error}</p> : null}
|
|
118
|
+
</aside>
|
|
119
|
+
);
|
|
120
|
+
};
|
package/src/client/index.ts
CHANGED
|
@@ -6,6 +6,8 @@ export {
|
|
|
6
6
|
VZCodeContext,
|
|
7
7
|
} from './VZCodeContext';
|
|
8
8
|
export { VZSidebar } from './VZSidebar';
|
|
9
|
+
export { VisualEditorControls } from './VZSidebar/VisualEditor/VisualEditorControls';
|
|
10
|
+
export type { VisualEditorControlsProps } from './VZSidebar/VisualEditor/VisualEditorControls';
|
|
9
11
|
export { VZSettings } from './VZSettings';
|
|
10
12
|
export { VZKeyboardShortcutsDoc } from './VZKeyboardShortcutsDoc';
|
|
11
13
|
export { VZResizer } from './VZResizer';
|
package/src/client/main.jsx
CHANGED
|
@@ -1,33 +1,75 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import * as ReactDOM from 'react-dom/client';
|
|
3
|
-
import App from './App';
|
|
4
3
|
import './standalone.scss';
|
|
5
4
|
import { BrowserRouter } from 'react-router-dom';
|
|
6
5
|
|
|
7
|
-
// Global error handler
|
|
8
|
-
// These can occur when CodeMirror instances are created but not yet
|
|
9
|
-
// attached to the DOM, or when presence indicators try to render
|
|
10
|
-
// on offscreen editor instances.
|
|
6
|
+
// Global error handler for a known, non-fatal CodeMirror DOM error.
|
|
11
7
|
window.addEventListener('error', (event) => {
|
|
12
|
-
// Check if this is the specific CodeMirror posFromDOM/posAtDOM error
|
|
13
8
|
if (
|
|
14
9
|
event.error instanceof RangeError &&
|
|
15
10
|
event.error.message.includes(
|
|
16
11
|
'Trying to find position for a DOM position outside of the document',
|
|
17
12
|
)
|
|
18
13
|
) {
|
|
19
|
-
// Log the error for debugging purposes
|
|
20
14
|
console.log(
|
|
21
15
|
'Suppressed CodeMirror DOM position error:',
|
|
22
16
|
event.error,
|
|
23
17
|
);
|
|
24
|
-
// Prevent the error from being logged to console by returning true
|
|
25
18
|
return true;
|
|
26
19
|
}
|
|
27
20
|
});
|
|
28
21
|
|
|
29
|
-
ReactDOM.createRoot(
|
|
30
|
-
|
|
31
|
-
<App />
|
|
32
|
-
</BrowserRouter>,
|
|
22
|
+
const root = ReactDOM.createRoot(
|
|
23
|
+
document.getElementById('root'),
|
|
33
24
|
);
|
|
25
|
+
|
|
26
|
+
async function start() {
|
|
27
|
+
// The capability token is in the URL fragment, never sent in HTTP
|
|
28
|
+
// requests or referrers. Exchange it for an HttpOnly session cookie.
|
|
29
|
+
const fragment = new URLSearchParams(
|
|
30
|
+
window.location.hash.slice(1),
|
|
31
|
+
);
|
|
32
|
+
const token = fragment.get('vzcode-token');
|
|
33
|
+
if (token) {
|
|
34
|
+
const response = await fetch('/auth/session', {
|
|
35
|
+
method: 'POST',
|
|
36
|
+
headers: { Authorization: 'Bearer ' + token },
|
|
37
|
+
credentials: 'same-origin',
|
|
38
|
+
});
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
throw new Error('Invalid VZCode access link.');
|
|
41
|
+
}
|
|
42
|
+
// Remove the sensitive fragment from browser history.
|
|
43
|
+
window.history.replaceState(
|
|
44
|
+
null,
|
|
45
|
+
'',
|
|
46
|
+
window.location.pathname + window.location.search,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const status = await fetch('/auth/status', {
|
|
51
|
+
credentials: 'same-origin',
|
|
52
|
+
cache: 'no-store',
|
|
53
|
+
});
|
|
54
|
+
if (!status.ok) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
'Authorization required. Open the private URL printed by the VZCode CLI.',
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
// App creates its WebSocket at module initialization; it must load
|
|
60
|
+
// only after the session cookie has been established.
|
|
61
|
+
const { default: App } = await import('./App');
|
|
62
|
+
root.render(
|
|
63
|
+
<BrowserRouter>
|
|
64
|
+
<App />
|
|
65
|
+
</BrowserRouter>,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
start().catch((error) => {
|
|
70
|
+
console.error('VZCode authentication failed:', error);
|
|
71
|
+
const message = document.createElement('p');
|
|
72
|
+
message.style.padding = '2rem';
|
|
73
|
+
message.textContent = error.message;
|
|
74
|
+
document.getElementById('root').replaceChildren(message);
|
|
75
|
+
});
|
package/src/client/ui.scss
CHANGED
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
--vz-color-neutral-02: #202e46;
|
|
19
19
|
--vz-color-neutral-03: #576786;
|
|
20
20
|
--vz-color-neutral-04: #bdc7dc;
|
|
21
|
-
--vz-color-action-01: #
|
|
22
|
-
--vz-color-action-02: #
|
|
21
|
+
--vz-color-action-01: #0366d6;
|
|
22
|
+
--vz-color-action-02: #0256c2;
|
|
23
23
|
--vz-color-action-03: #e0e8ff;
|
|
24
24
|
--vz-color-warning-01: #eb1c69;
|
|
25
25
|
--vz-color-warning-02: #ffeff2;
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
--vz-color-primary-04: var(--vz-color-action-03);
|
|
37
37
|
--vz-color-success-03: #36bb4a;
|
|
38
38
|
--vz-color-success-04: #d7f6dc;
|
|
39
|
-
--vz-color-danger-03: #
|
|
40
|
-
--vz-color-danger-04: #
|
|
39
|
+
--vz-color-danger-03: #f0353d;
|
|
40
|
+
--vz-color-danger-04: #fff1f2;
|
|
41
41
|
--vz-font-body: Inter, sans-serif;
|
|
42
42
|
--vz-font-heading: Poppins, sans-serif;
|
|
43
43
|
}
|
|
@@ -322,3 +322,155 @@
|
|
|
322
322
|
opacity: 1;
|
|
323
323
|
visibility: visible;
|
|
324
324
|
}
|
|
325
|
+
|
|
326
|
+
/* AI Studio design contract for VZCode controls.
|
|
327
|
+
* The code editor's dark surface and syntax highlighting remain unchanged.
|
|
328
|
+
* Dialogs are portaled to body, so modal selectors cannot rely on .app. */
|
|
329
|
+
:is(.app, .vz-sidebar) .vz-icon-button {
|
|
330
|
+
appearance: none;
|
|
331
|
+
display: inline-flex;
|
|
332
|
+
align-items: center;
|
|
333
|
+
justify-content: center;
|
|
334
|
+
min-width: 32px;
|
|
335
|
+
min-height: 32px;
|
|
336
|
+
padding: 4px;
|
|
337
|
+
border: 0;
|
|
338
|
+
border-radius: 6px;
|
|
339
|
+
background: transparent;
|
|
340
|
+
color: var(--vz-color-neutral-04);
|
|
341
|
+
font: inherit;
|
|
342
|
+
text-decoration: none;
|
|
343
|
+
cursor: pointer;
|
|
344
|
+
transition:
|
|
345
|
+
background-color 0.15s ease,
|
|
346
|
+
color 0.15s ease;
|
|
347
|
+
}
|
|
348
|
+
:is(.app, .vz-sidebar) .vz-icon-button:hover {
|
|
349
|
+
background: var(--vz-color-hover-dark);
|
|
350
|
+
}
|
|
351
|
+
:is(.app, .vz-sidebar) .vz-icon-button:active {
|
|
352
|
+
background: var(--vz-color-active-dark);
|
|
353
|
+
}
|
|
354
|
+
:is(.app, .vz-sidebar)
|
|
355
|
+
.vz-icon-button[aria-pressed='true'] {
|
|
356
|
+
background: rgba(3, 102, 214, 0.3);
|
|
357
|
+
color: #fff;
|
|
358
|
+
}
|
|
359
|
+
:is(.app, .vz-sidebar)
|
|
360
|
+
.vz-icon-button[aria-pressed='true']:hover {
|
|
361
|
+
background: rgba(3, 102, 214, 0.42);
|
|
362
|
+
}
|
|
363
|
+
:is(.app, .vz-sidebar) .vz-icon-button:focus-visible {
|
|
364
|
+
outline: 2px solid var(--vz-color-action-01);
|
|
365
|
+
outline-offset: 2px;
|
|
366
|
+
}
|
|
367
|
+
.vz-ui-button {
|
|
368
|
+
min-height: 36px;
|
|
369
|
+
gap: 8px;
|
|
370
|
+
padding: 8px 16px;
|
|
371
|
+
border-radius: 6px;
|
|
372
|
+
background: #f5f5f5;
|
|
373
|
+
color: #262626;
|
|
374
|
+
font:
|
|
375
|
+
500 14px/1.25 Inter,
|
|
376
|
+
sans-serif;
|
|
377
|
+
transition:
|
|
378
|
+
background-color 0.15s ease,
|
|
379
|
+
border-color 0.15s ease,
|
|
380
|
+
color 0.15s ease;
|
|
381
|
+
}
|
|
382
|
+
.vz-ui-button:hover:not(:disabled) {
|
|
383
|
+
filter: none;
|
|
384
|
+
background: #e5e5e5;
|
|
385
|
+
}
|
|
386
|
+
.vz-ui-button--primary {
|
|
387
|
+
background: #0366d6;
|
|
388
|
+
color: #fff;
|
|
389
|
+
}
|
|
390
|
+
.vz-ui-button--primary:hover:not(:disabled) {
|
|
391
|
+
background: #0256c2;
|
|
392
|
+
}
|
|
393
|
+
.vz-ui-button--danger {
|
|
394
|
+
background: #f0353d;
|
|
395
|
+
color: #fff;
|
|
396
|
+
}
|
|
397
|
+
.vz-ui-button--danger:hover:not(:disabled) {
|
|
398
|
+
background: #d62e35;
|
|
399
|
+
}
|
|
400
|
+
.vz-ui-button--outline-secondary {
|
|
401
|
+
background: #fff;
|
|
402
|
+
border-color: #e5e5e5;
|
|
403
|
+
color: #262626;
|
|
404
|
+
}
|
|
405
|
+
.vz-ui-button--outline-secondary:hover:not(:disabled) {
|
|
406
|
+
background: #f5f5f5;
|
|
407
|
+
}
|
|
408
|
+
.vz-ui-button--outline-primary {
|
|
409
|
+
background: transparent;
|
|
410
|
+
border-color: #0366d6;
|
|
411
|
+
color: #0366d6;
|
|
412
|
+
}
|
|
413
|
+
.vz-ui-button--outline-primary:hover:not(:disabled) {
|
|
414
|
+
background: #e9f1fc;
|
|
415
|
+
color: #0256c2;
|
|
416
|
+
}
|
|
417
|
+
.vz-ui-button--sm {
|
|
418
|
+
min-height: 32px;
|
|
419
|
+
padding: 6px 12px;
|
|
420
|
+
font-size: 12px;
|
|
421
|
+
}
|
|
422
|
+
.vz-ui-button:focus-visible,
|
|
423
|
+
.vz-ui-control:focus-visible,
|
|
424
|
+
.vz-ui-select:focus-visible,
|
|
425
|
+
.vz-ui-close:focus-visible {
|
|
426
|
+
outline: 2px solid #0366d6;
|
|
427
|
+
outline-offset: 2px;
|
|
428
|
+
}
|
|
429
|
+
.vz-ui-modal {
|
|
430
|
+
border-radius: 10px;
|
|
431
|
+
}
|
|
432
|
+
.vz-ui-close {
|
|
433
|
+
border-radius: 6px;
|
|
434
|
+
}
|
|
435
|
+
.vz-ui-close:hover {
|
|
436
|
+
background: #f5f5f5;
|
|
437
|
+
color: #262626;
|
|
438
|
+
}
|
|
439
|
+
.vz-ui-control,
|
|
440
|
+
.vz-ui-select {
|
|
441
|
+
border-radius: 6px;
|
|
442
|
+
background: #fff;
|
|
443
|
+
padding: 8px 12px;
|
|
444
|
+
}
|
|
445
|
+
.vz-ui-control:focus,
|
|
446
|
+
.vz-ui-select:focus {
|
|
447
|
+
border-color: #0366d6;
|
|
448
|
+
}
|
|
449
|
+
.vz-ui-label {
|
|
450
|
+
font-size: 14px;
|
|
451
|
+
}
|
|
452
|
+
.vz-ui-control,
|
|
453
|
+
.vz-ui-select {
|
|
454
|
+
font-size: 14px;
|
|
455
|
+
}
|
|
456
|
+
@media (pointer: coarse) {
|
|
457
|
+
.vz-ui-control,
|
|
458
|
+
.vz-ui-select {
|
|
459
|
+
font-size: 16px;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
@media (pointer: coarse) {
|
|
463
|
+
:is(.app, .vz-sidebar) .vz-icon-button {
|
|
464
|
+
min-width: 44px;
|
|
465
|
+
min-height: 44px;
|
|
466
|
+
}
|
|
467
|
+
.vz-ui-button {
|
|
468
|
+
min-height: 44px;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
@media (prefers-reduced-motion: reduce) {
|
|
472
|
+
:is(.app, .vz-sidebar) .vz-icon-button,
|
|
473
|
+
.vz-ui-button {
|
|
474
|
+
transition: none;
|
|
475
|
+
}
|
|
476
|
+
}
|
package/src/client/ui.tsx
CHANGED
|
@@ -300,7 +300,7 @@ export const OverlayTrigger = ({
|
|
|
300
300
|
<span
|
|
301
301
|
ref={anchor}
|
|
302
302
|
className="vz-ui-tooltip-anchor"
|
|
303
|
-
|
|
303
|
+
// Nested interactive elements own keyboard focus; avoid an extra tab stop.
|
|
304
304
|
onPointerEnter={update}
|
|
305
305
|
onPointerLeave={() => setPosition(null)}
|
|
306
306
|
onFocus={update}
|
|
@@ -4,7 +4,7 @@ Server-side library for streaming LLM responses with ShareDB integration.
|
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
This
|
|
7
|
+
This is an internal VZCode module that provides server-side functionality for:
|
|
8
8
|
|
|
9
9
|
- **LLM Streaming**: Creating and managing streaming LLM functions with OpenAI/OpenRouter
|
|
10
10
|
- **AI Code Editing**: Performing AI-assisted code transformations and edits
|
|
@@ -12,9 +12,10 @@ This module is being extracted from VZCode's AI chat functionality to become a s
|
|
|
12
12
|
- **Request Validation**: Validating incoming AI chat requests
|
|
13
13
|
- **Error Handling**: Handling errors gracefully in streaming contexts
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Status
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
The module is used by VZCode's AI chat handler. It still depends on VZCode
|
|
18
|
+
types and utilities, and is not published as a standalone package.
|
|
18
19
|
|
|
19
20
|
## Files
|
|
20
21
|
|
|
@@ -35,19 +36,6 @@ Declared in `package.json`:
|
|
|
35
36
|
- `editcodewithai` - Code editing utilities
|
|
36
37
|
- VZCode utilities: `../types.js`, `../ot.js`, `../randomId.js`, etc.
|
|
37
38
|
|
|
38
|
-
## Future Plans
|
|
39
|
-
|
|
40
|
-
This module will eventually be:
|
|
41
|
-
|
|
42
|
-
1. Decoupled from VZCode-specific types and utilities
|
|
43
|
-
2. Published as `@vizhub/llm-streaming-server` on npm
|
|
44
|
-
3. Made framework-agnostic (can work with Express, Fastify, etc.)
|
|
45
|
-
4. Fully documented with usage examples
|
|
46
|
-
|
|
47
|
-
This module is being extracted into a standalone package
|
|
48
|
-
(`@vizhub/llm-streaming-server`). Follow the conventions in
|
|
49
|
-
`../llm-streaming-ui/README.md` when contributing.
|
|
50
|
-
|
|
51
39
|
## Usage (Current)
|
|
52
40
|
|
|
53
41
|
Currently, this module is imported by `src/server/aiChatHandler/index.ts`:
|
|
@@ -99,7 +99,46 @@ See `AIChatProps` in `props.ts` for the full contract.
|
|
|
99
99
|
- Add or update tests when changing behavior
|
|
100
100
|
- Document new props and side effects
|
|
101
101
|
|
|
102
|
+
## Host-owned microphone integration
|
|
103
|
+
|
|
104
|
+
A host can pass `renderChatVoiceInput` to `VZCodeProvider`. VZCode renders its
|
|
105
|
+
returned element in the chat composer footer, immediately before Send. The host
|
|
106
|
+
owns the microphone implementation, recording state, speech-to-text, any cleanup,
|
|
107
|
+
and cancellation. VZCode never starts its built-in speech-recognition engine
|
|
108
|
+
from the host control; `enableVoiceInput` remains a separate legacy option.
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
<VZCodeProvider
|
|
112
|
+
// ...other provider props
|
|
113
|
+
renderChatVoiceInput={({
|
|
114
|
+
value,
|
|
115
|
+
onChange,
|
|
116
|
+
onBusyChange,
|
|
117
|
+
onPreviewChange,
|
|
118
|
+
}) => (
|
|
119
|
+
<MyAppVoiceButton
|
|
120
|
+
value={value}
|
|
121
|
+
onCommitDraft={onChange}
|
|
122
|
+
onBusyChange={onBusyChange}
|
|
123
|
+
onPreviewChange={onPreviewChange}
|
|
124
|
+
/>
|
|
125
|
+
)}
|
|
126
|
+
/>
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The renderer must return a component rather than directly calling hooks. Its
|
|
130
|
+
`value` is the **complete committed draft**. Call `onChange(nextFullDraft)`
|
|
131
|
+
only when dictation has finished; this must never submit the chat message.
|
|
132
|
+
Call `onPreviewChange(fullDraftPreview)` to display optional interim text,
|
|
133
|
+
and `onPreviewChange(null)` to clear it. Call `onBusyChange(true)` before
|
|
134
|
+
starting microphone work, including permission and transcript processing; while
|
|
135
|
+
busy, VZCode makes its textarea read-only and blocks Send and Enter. Always
|
|
136
|
+
call `onBusyChange(false)` on completion, cancellation, errors, and teardown.
|
|
137
|
+
Without a renderer, the existing chat composer behavior is preserved.
|
|
138
|
+
|
|
102
139
|
## Theming
|
|
103
140
|
|
|
104
|
-
The components
|
|
105
|
-
|
|
141
|
+
The components use scoped CSS custom properties with VZCode defaults, so they
|
|
142
|
+
can render without a host UI framework. When embedding them, hosts can override
|
|
143
|
+
the `--vz-color-*` properties on the chat container. The styles do not inject
|
|
144
|
+
Bootstrap or VizHub UI CSS.
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
useRef,
|
|
3
3
|
useEffect,
|
|
4
4
|
useCallback,
|
|
5
|
+
useState,
|
|
5
6
|
memo,
|
|
6
7
|
} from 'react';
|
|
7
8
|
import { useSpeechRecognition } from './useSpeechRecognition';
|
|
@@ -57,8 +58,42 @@ const ChatInputComponent = ({
|
|
|
57
58
|
resetMessageHistoryNavigation,
|
|
58
59
|
enableAskMode = false,
|
|
59
60
|
enableVoiceInput = false,
|
|
61
|
+
renderChatVoiceInput,
|
|
60
62
|
}: ChatInputProps) => {
|
|
61
63
|
const inputRef = useRef<HTMLTextAreaElement>(null);
|
|
64
|
+
const [hostVoiceBusy, setHostVoiceBusy] = useState(false);
|
|
65
|
+
const [hostVoicePreview, setHostVoicePreview] = useState<
|
|
66
|
+
string | null
|
|
67
|
+
>(null);
|
|
68
|
+
const isHostVoiceBusy =
|
|
69
|
+
!!renderChatVoiceInput && hostVoiceBusy;
|
|
70
|
+
const canSend =
|
|
71
|
+
!isHostVoiceBusy && !!aiChatMessage.trim();
|
|
72
|
+
const displayValue =
|
|
73
|
+
isHostVoiceBusy && hostVoicePreview !== null
|
|
74
|
+
? hostVoicePreview
|
|
75
|
+
: aiChatMessage;
|
|
76
|
+
|
|
77
|
+
const handleHostDraftChange = useCallback(
|
|
78
|
+
(value: string) => {
|
|
79
|
+
setAIChatMessage(value);
|
|
80
|
+
resetMessageHistoryNavigation();
|
|
81
|
+
},
|
|
82
|
+
[setAIChatMessage, resetMessageHistoryNavigation],
|
|
83
|
+
);
|
|
84
|
+
const handleHostBusyChange = useCallback(
|
|
85
|
+
(busy: boolean) => {
|
|
86
|
+
setHostVoiceBusy(busy);
|
|
87
|
+
if (!busy) setHostVoicePreview(null);
|
|
88
|
+
},
|
|
89
|
+
[],
|
|
90
|
+
);
|
|
91
|
+
const handleHostPreviewChange = useCallback(
|
|
92
|
+
(preview: string | null) => {
|
|
93
|
+
setHostVoicePreview(preview);
|
|
94
|
+
},
|
|
95
|
+
[],
|
|
96
|
+
);
|
|
62
97
|
|
|
63
98
|
// Speech recognition is created lazily on first toggle, so simply
|
|
64
99
|
// mounting this hook does not touch any browser media APIs.
|
|
@@ -79,7 +114,7 @@ const ChatInputComponent = ({
|
|
|
79
114
|
(event: React.KeyboardEvent) => {
|
|
80
115
|
if (event.key === 'Enter' && !event.shiftKey) {
|
|
81
116
|
event.preventDefault();
|
|
82
|
-
onSendMessage();
|
|
117
|
+
if (canSend) onSendMessage();
|
|
83
118
|
} else if (event.key === 'Enter' && event.shiftKey) {
|
|
84
119
|
// Shift+Enter should add a newline, not trigger run code
|
|
85
120
|
// We prevent the event from bubbling up to the global keyboard handler
|
|
@@ -119,26 +154,33 @@ const ChatInputComponent = ({
|
|
|
119
154
|
},
|
|
120
155
|
[
|
|
121
156
|
onSendMessage,
|
|
157
|
+
canSend,
|
|
122
158
|
navigateMessageHistoryUp,
|
|
123
159
|
navigateMessageHistoryDown,
|
|
124
160
|
],
|
|
125
161
|
);
|
|
126
162
|
|
|
127
163
|
const handleSendClick = useCallback(() => {
|
|
164
|
+
if (!canSend) return;
|
|
128
165
|
// If speech recognition is active, stop it
|
|
129
166
|
if (isSpeaking) {
|
|
130
167
|
stopSpeaking();
|
|
131
168
|
}
|
|
132
169
|
onSendMessage();
|
|
133
|
-
}, [onSendMessage, isSpeaking, stopSpeaking]);
|
|
170
|
+
}, [onSendMessage, isSpeaking, stopSpeaking, canSend]);
|
|
134
171
|
|
|
135
172
|
const handleChange = useCallback(
|
|
136
173
|
(event: React.ChangeEvent<HTMLTextAreaElement>) => {
|
|
174
|
+
if (isHostVoiceBusy) return;
|
|
137
175
|
setAIChatMessage(event.target.value);
|
|
138
176
|
// Reset history navigation when user starts typing
|
|
139
177
|
resetMessageHistoryNavigation();
|
|
140
178
|
},
|
|
141
|
-
[
|
|
179
|
+
[
|
|
180
|
+
setAIChatMessage,
|
|
181
|
+
resetMessageHistoryNavigation,
|
|
182
|
+
isHostVoiceBusy,
|
|
183
|
+
],
|
|
142
184
|
);
|
|
143
185
|
|
|
144
186
|
return (
|
|
@@ -178,7 +220,8 @@ const ChatInputComponent = ({
|
|
|
178
220
|
<div className="ai-chat-input-group">
|
|
179
221
|
<textarea
|
|
180
222
|
rows={10}
|
|
181
|
-
value={
|
|
223
|
+
value={displayValue}
|
|
224
|
+
readOnly={isHostVoiceBusy}
|
|
182
225
|
onChange={handleChange}
|
|
183
226
|
onKeyDown={handleKeyDown}
|
|
184
227
|
ref={inputRef}
|
|
@@ -192,20 +235,29 @@ const ChatInputComponent = ({
|
|
|
192
235
|
/>
|
|
193
236
|
<div className="ai-chat-input-footer">
|
|
194
237
|
<span className="ai-chat-hint">
|
|
195
|
-
{aiChatMessage
|
|
238
|
+
{aiChatMessage && !isHostVoiceBusy
|
|
239
|
+
? 'Press Enter to send'
|
|
240
|
+
: ''}
|
|
196
241
|
</span>
|
|
197
242
|
<div style={{ display: 'flex', gap: '8px' }}>
|
|
198
|
-
{
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
243
|
+
{renderChatVoiceInput
|
|
244
|
+
? renderChatVoiceInput({
|
|
245
|
+
value: aiChatMessage,
|
|
246
|
+
onChange: handleHostDraftChange,
|
|
247
|
+
onBusyChange: handleHostBusyChange,
|
|
248
|
+
onPreviewChange: handleHostPreviewChange,
|
|
249
|
+
})
|
|
250
|
+
: enableVoiceInput && (
|
|
251
|
+
<VoiceInputButton
|
|
252
|
+
isSpeaking={isSpeaking}
|
|
253
|
+
onToggle={toggleSpeechRecognition}
|
|
254
|
+
/>
|
|
255
|
+
)}
|
|
204
256
|
<button
|
|
205
257
|
type="button"
|
|
206
258
|
onClick={handleSendClick}
|
|
207
|
-
disabled={!
|
|
208
|
-
className={`ai-chat-send-button vz-chat-button ${
|
|
259
|
+
disabled={!canSend}
|
|
260
|
+
className={`ai-chat-send-button vz-chat-button ${canSend ? 'vz-chat-button--primary' : 'vz-chat-button--outline-secondary'}`}
|
|
209
261
|
aria-label="Send message"
|
|
210
262
|
title="Send message (Enter)"
|
|
211
263
|
>
|
|
@@ -64,6 +64,7 @@ export const AIChat = ({
|
|
|
64
64
|
enableDiffView = true,
|
|
65
65
|
enableAskMode = false,
|
|
66
66
|
enableVoiceInput = false,
|
|
67
|
+
renderChatVoiceInput,
|
|
67
68
|
onOpenFile,
|
|
68
69
|
}: AIChatProps) => {
|
|
69
70
|
// Use the new simplified auto-scroll hook
|
|
@@ -376,6 +377,7 @@ export const AIChat = ({
|
|
|
376
377
|
setAIChatMode={setAIChatMode}
|
|
377
378
|
enableAskMode={enableAskMode}
|
|
378
379
|
enableVoiceInput={enableVoiceInput}
|
|
380
|
+
renderChatVoiceInput={renderChatVoiceInput}
|
|
379
381
|
navigateMessageHistoryUp={
|
|
380
382
|
navigateMessageHistoryUp
|
|
381
383
|
}
|