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.
Files changed (52) hide show
  1. package/dist/assets/buildWorker-BZlya278.js +687 -0
  2. package/dist/assets/index-Cj-ERpBu.css +1 -0
  3. package/dist/assets/index-DD7vzp4U.js +364 -0
  4. package/dist/assets/{worker-D8p1JlHW.js → worker-1oQYaz-F.js} +251 -251
  5. package/dist/assets/worker-BfgPD8zR.js +125 -0
  6. package/dist/assets/{worker-k7HZ3t-V.js → worker-CoJaqtpi.js} +12 -12
  7. package/dist/index.html +2 -2
  8. package/dist/ot.js +180 -2
  9. package/dist/server/createServer.js +281 -0
  10. package/dist/server/index.js +6 -269
  11. package/package.json +14 -3
  12. package/src/client/CodeEditor/getOrCreateEditor.tsx +0 -14
  13. package/src/client/VZCodeContext/chatSessionHelpers.ts +17 -0
  14. package/src/client/VZCodeContext/useAIChatSession.ts +325 -0
  15. package/src/client/VZCodeContext/useVZCodeState.ts +23 -279
  16. package/src/client/VZSidebar/AIChatWrapper.tsx +85 -0
  17. package/src/client/VZSidebar/VisualEditor/VisualEditor.tsx +95 -208
  18. package/src/client/VZSidebar/VisualEditor/colorUtils.ts +39 -0
  19. package/src/client/VZSidebar/VisualEditor/status.ts +2 -40
  20. package/src/client/VZSidebar/VisualEditor/updateConfig.ts +10 -1
  21. package/src/client/VZSidebar/VisualEditor/utils.ts +49 -65
  22. package/src/client/VZSidebar/index.tsx +2 -2
  23. package/src/client/definitionJumpListeners.ts +47 -0
  24. package/src/client/useKeyboardShortcuts.ts +23 -28
  25. package/src/client/useOpenDirectories.ts +0 -1
  26. package/src/llm-streaming-server/README.md +5 -3
  27. package/src/llm-streaming-ui/README.md +44 -42
  28. package/src/llm-streaming-ui/components/ChatInput.tsx +6 -19
  29. package/src/llm-streaming-ui/components/DiffView.tsx +6 -24
  30. package/src/llm-streaming-ui/components/FileEditingIndicator.tsx +1 -1
  31. package/src/llm-streaming-ui/components/Message.tsx +11 -27
  32. package/src/llm-streaming-ui/components/MessageList.tsx +15 -29
  33. package/src/llm-streaming-ui/components/Spinner.scss +37 -0
  34. package/src/llm-streaming-ui/components/Spinner.tsx +59 -0
  35. package/src/llm-streaming-ui/components/bootstrap.ts +16 -0
  36. package/src/llm-streaming-ui/components/icons.tsx +68 -0
  37. package/src/llm-streaming-ui/components/index.tsx +34 -30
  38. package/src/llm-streaming-ui/index.ts +13 -0
  39. package/src/llm-streaming-ui/props.ts +137 -0
  40. package/src/ot.ts +221 -4
  41. package/src/server/createServer.ts +413 -0
  42. package/src/server/index.ts +8 -333
  43. package/dist/assets/buildWorker-DylWm2VX.js +0 -687
  44. package/dist/assets/index-Dyt9tpmu.css +0 -1
  45. package/dist/assets/index-nL6to42p.js +0 -364
  46. package/dist/assets/worker-b9bkZkXK.js +0 -116
  47. package/src/client/AIAssist/AIAssistCodeMirrorKeyMap.ts +0 -42
  48. package/src/client/AIAssist/generateFilesContext.ts +0 -25
  49. package/src/client/AIAssist/index.ts +0 -2
  50. package/src/client/CodeEditor/InteractiveWidgets/highlightWidgets.ts +0 -79
  51. /package/src/{client → llm-streaming-ui}/hooks/useAutoScroll.ts +0 -0
  52. /package/src/{client → llm-streaming-ui}/utils/scrollUtils.ts +0 -0
@@ -0,0 +1,85 @@
1
+ import { useCallback, useContext } from 'react';
2
+ import { getFileId } from '@vizhub/viz-utils';
3
+ import { AIChat } from '../../llm-streaming-ui';
4
+ import { VZCodeContext } from '../VZCodeContext';
5
+ import {
6
+ enableAskMode,
7
+ enableDiffView,
8
+ enableVoiceInput,
9
+ } from '../featureFlags';
10
+
11
+ /**
12
+ * Bridges VZCode's context into the standalone `AIChat` component.
13
+ *
14
+ * `AIChat` (from `llm-streaming-ui`) is fully controlled and reads no
15
+ * application state. This wrapper supplies the chat state, callbacks,
16
+ * feature flags, and file-link handling from `VZCodeContext`.
17
+ */
18
+ export const AIChatWrapper = () => {
19
+ const {
20
+ content,
21
+ aiChatFocused,
22
+ aiChatMode,
23
+ aiChatMessage,
24
+ currentChatId,
25
+ selectedChatId,
26
+ setSelectedChatId,
27
+ aiErrorMessage,
28
+ setAIChatMode,
29
+ getStoredAIPrompt,
30
+ setAIChatMessage,
31
+ handleSendMessage,
32
+ setAIErrorMessage,
33
+ navigateMessageHistoryUp,
34
+ navigateMessageHistoryDown,
35
+ resetMessageHistoryNavigation,
36
+ enableMinimalEditFlow,
37
+ additionalWidgets,
38
+ openTab,
39
+ setIsAIChatOpen,
40
+ } = useContext(VZCodeContext);
41
+
42
+ // Open a file referenced by a link inside a diff.
43
+ const handleOpenFile = useCallback(
44
+ (fileName: string) => {
45
+ if (!content) return;
46
+ const fileId = getFileId(content, fileName);
47
+ if (fileId) {
48
+ openTab({ fileId, isTransient: false });
49
+ setIsAIChatOpen(false);
50
+ }
51
+ },
52
+ [content, openTab, setIsAIChatOpen],
53
+ );
54
+
55
+ return (
56
+ <AIChat
57
+ content={content}
58
+ aiChatFocused={aiChatFocused}
59
+ aiChatMode={aiChatMode}
60
+ setAIChatMode={setAIChatMode}
61
+ aiChatMessage={aiChatMessage}
62
+ setAIChatMessage={setAIChatMessage}
63
+ aiErrorMessage={aiErrorMessage}
64
+ setAIErrorMessage={setAIErrorMessage}
65
+ currentChatId={currentChatId}
66
+ selectedChatId={selectedChatId}
67
+ setSelectedChatId={setSelectedChatId}
68
+ handleSendMessage={handleSendMessage}
69
+ navigateMessageHistoryUp={navigateMessageHistoryUp}
70
+ navigateMessageHistoryDown={
71
+ navigateMessageHistoryDown
72
+ }
73
+ resetMessageHistoryNavigation={
74
+ resetMessageHistoryNavigation
75
+ }
76
+ getStoredAIPrompt={getStoredAIPrompt}
77
+ onOpenFile={handleOpenFile}
78
+ additionalWidgets={additionalWidgets}
79
+ enableDiffView={enableDiffView}
80
+ enableAskMode={enableAskMode}
81
+ enableVoiceInput={enableVoiceInput}
82
+ enableMinimalEditFlow={enableMinimalEditFlow}
83
+ />
84
+ );
85
+ };
@@ -9,7 +9,11 @@ import { VZCodeContext } from '../../VZCodeContext';
9
9
  import { VizContent, VizFileId } from '@vizhub/viz-types';
10
10
  import { VisualEditorConfigEntry } from '../../../types';
11
11
  import { EmptyState } from '../EmptyState';
12
- import { color, hcl, HCLColor, rgb } from 'd3-color';
12
+ import {
13
+ toHclChannels,
14
+ coerceChannelNumber,
15
+ hclChannelsToHex,
16
+ } from './colorUtils';
13
17
  import { CONFIG_FILE_NAME } from './constants';
14
18
  import { getVisualEditorEmptyReason } from './status';
15
19
  import { updateVisualEditorProperty } from './updateConfig';
@@ -59,95 +63,61 @@ export const VisualEditor = () => {
59
63
  }
60
64
  }, [configFileId, files]);
61
65
 
66
+ // All controls share one optimistic state + ShareDB write path.
67
+ const setWidgetValue = useCallback(
68
+ (
69
+ property: string,
70
+ value: number | boolean | string,
71
+ extraLocalValues: Record<string, number> = {},
72
+ ) => {
73
+ setLocalValues((prev) => ({
74
+ ...prev,
75
+ [property]: value,
76
+ ...extraLocalValues,
77
+ }));
78
+ submitOperation((document: VizContent) =>
79
+ updateVisualEditorProperty(
80
+ document,
81
+ configFileId,
82
+ property,
83
+ value,
84
+ ),
85
+ );
86
+ },
87
+ [configFileId, submitOperation],
88
+ );
89
+
62
90
  const onSliderChange = useCallback(
63
91
  (property: string) =>
64
- (event: React.ChangeEvent<HTMLInputElement>) => {
65
- const newValue = parseFloat(
66
- event.currentTarget.value,
67
- );
68
-
69
- // Update local state immediately for responsive UI
70
- setLocalValues((prev) => ({
71
- ...prev,
72
- [property]: newValue,
73
- }));
74
-
75
- submitOperation((document: VizContent) =>
76
- updateVisualEditorProperty(
77
- document,
78
- configFileId,
79
- property,
80
- newValue,
81
- ),
82
- );
83
- },
84
- [configFileId, submitOperation],
92
+ (event: React.ChangeEvent<HTMLInputElement>) =>
93
+ setWidgetValue(
94
+ property,
95
+ parseFloat(event.currentTarget.value),
96
+ ),
97
+ [setWidgetValue],
85
98
  );
86
99
 
87
100
  const onCheckboxChange = useCallback(
88
101
  (property: string) =>
89
- (event: React.ChangeEvent<HTMLInputElement>) => {
90
- const newValue = event.currentTarget.checked;
91
-
92
- // Update local state immediately for responsive UI
93
- setLocalValues((prev) => ({
94
- ...prev,
95
- [property]: newValue,
96
- }));
97
-
98
- submitOperation((document: VizContent) =>
99
- updateVisualEditorProperty(
100
- document,
101
- configFileId,
102
- property,
103
- newValue,
104
- ),
105
- );
106
- },
107
- [configFileId, submitOperation],
102
+ (event: React.ChangeEvent<HTMLInputElement>) =>
103
+ setWidgetValue(
104
+ property,
105
+ event.currentTarget.checked,
106
+ ),
107
+ [setWidgetValue],
108
108
  );
109
109
 
110
110
  const onTextInputChange = useCallback(
111
111
  (property: string) =>
112
- (event: React.ChangeEvent<HTMLInputElement>) => {
113
- const newValue = event.currentTarget.value;
114
-
115
- // Update local state immediately for responsive UI
116
- setLocalValues((prev) => ({
117
- ...prev,
118
- [property]: newValue,
119
- }));
120
-
121
- submitOperation((document: VizContent) =>
122
- updateVisualEditorProperty(
123
- document,
124
- configFileId,
125
- property,
126
- newValue,
127
- ),
128
- );
129
- },
130
- [configFileId, submitOperation],
112
+ (event: React.ChangeEvent<HTMLInputElement>) =>
113
+ setWidgetValue(property, event.currentTarget.value),
114
+ [setWidgetValue],
131
115
  );
132
116
 
133
117
  const onDropdownChange = useCallback(
134
- (property: string, newValue: string) => {
135
- // Update local state immediately for responsive UI
136
- setLocalValues((prev) => ({
137
- ...prev,
138
- [property]: newValue,
139
- }));
140
-
141
- submitOperation((document: VizContent) =>
142
- updateVisualEditorProperty(
143
- document,
144
- configFileId,
145
- property,
146
- newValue,
147
- ),
148
- );
149
- },
150
- [configFileId, submitOperation],
118
+ (property: string, value: string) =>
119
+ setWidgetValue(property, value),
120
+ [setWidgetValue],
151
121
  );
152
122
 
153
123
  // Custom dropdown handlers
@@ -203,74 +173,30 @@ export const VisualEditor = () => {
203
173
  getNestedProperty<string>(configData, property) ??
204
174
  '#000000';
205
175
 
206
- // Convert current hex to LCH
207
- let hclFromRGB: HCLColor;
208
- try {
209
- const rgbColor = rgb(currentHex);
210
- hclFromRGB = hcl(rgbColor);
211
- } catch {
212
- // Fallback to black if conversion fails
213
- hclFromRGB = hcl('black');
214
- }
215
-
216
- const hclArray: number[] = [
217
- (localValues[`${property}_h`] as number) ??
218
- hclFromRGB.h,
219
- (localValues[`${property}_c`] as number) ??
220
- hclFromRGB.c,
221
- (localValues[`${property}_l`] as number) ??
222
- hclFromRGB.l,
223
- ];
224
-
225
- // Update the specific LCH component
226
- const newhcl = [...hclArray];
227
- if (lchComponent === 'h') newhcl[0] = newValue;
228
- else if (lchComponent === 'c') newhcl[1] = newValue;
229
- else if (lchComponent === 'l') newhcl[2] = newValue;
230
-
231
- // Convert back to hex
232
- let newHex;
233
- try {
234
- const newColor = hcl(
235
- newhcl[0],
236
- newhcl[1],
237
- newhcl[2],
238
- );
239
-
240
- if (newColor.displayable()) {
241
- newHex = newColor.formatHex();
242
- } else {
243
- newHex = currentHex;
244
- }
245
- } catch {
246
- // Fallback to current color if conversion fails
247
- newHex = currentHex;
248
- }
249
-
250
- // Update local state for responsive UI
251
- setLocalValues((prev) => ({
252
- ...prev,
253
- [property]: newHex,
254
- [`${property}_h`]: newhcl[0],
255
- [`${property}_c`]: newhcl[1],
256
- [`${property}_l`]: newhcl[2],
257
- }));
258
-
259
- submitOperation((document: VizContent) =>
260
- updateVisualEditorProperty(
261
- document,
262
- configFileId,
263
- property,
264
- newHex,
265
- ),
176
+ const base = toHclChannels(currentHex);
177
+ const channels = {
178
+ h:
179
+ (localValues[`${property}_h`] as number) ??
180
+ base.h,
181
+ c:
182
+ (localValues[`${property}_c`] as number) ??
183
+ base.c,
184
+ l:
185
+ (localValues[`${property}_l`] as number) ??
186
+ base.l,
187
+ };
188
+ channels[lchComponent] = newValue;
189
+ const newHex = hclChannelsToHex(
190
+ channels,
191
+ currentHex,
266
192
  );
193
+ setWidgetValue(property, newHex, {
194
+ [`${property}_h`]: channels.h,
195
+ [`${property}_c`]: channels.c,
196
+ [`${property}_l`]: channels.l,
197
+ });
267
198
  },
268
- [
269
- configData,
270
- configFileId,
271
- submitOperation,
272
- localValues,
273
- ],
199
+ [configData, setWidgetValue, localValues],
274
200
  );
275
201
 
276
202
  const visualEditorWidgets: VisualEditorConfigEntry[] =
@@ -288,52 +214,19 @@ export const VisualEditor = () => {
288
214
  [key: string]: number | boolean | string;
289
215
  } = {};
290
216
  visualEditorWidgets.forEach((widget) => {
291
- if (widget.type === 'slider') {
292
- newLocalValues[widget.property] = getNestedProperty(
293
- configData,
294
- widget.property,
295
- );
296
- } else if (widget.type === 'checkbox') {
297
- newLocalValues[widget.property] = getNestedProperty(
298
- configData,
299
- widget.property,
300
- );
301
- } else if (widget.type === 'textInput') {
302
- newLocalValues[widget.property] = getNestedProperty(
303
- configData,
304
- widget.property,
305
- );
306
- } else if (widget.type === 'dropdown') {
307
- newLocalValues[widget.property] = getNestedProperty(
308
- configData,
309
- widget.property,
310
- );
311
- } else if (widget.type === 'color') {
312
- newLocalValues[widget.property] = getNestedProperty(
313
- configData,
314
- widget.property,
315
- );
316
-
317
- // Convert hex to LCH for internal state
318
- const hexColor = getNestedProperty<string>(
319
- configData,
320
- widget.property,
321
- );
322
-
323
- if (hexColor) {
324
- try {
325
- const rgbColor = color(hexColor);
326
- const lch = hcl(rgbColor);
327
- newLocalValues[`${widget.property}_h`] = lch.h;
328
- newLocalValues[`${widget.property}_c`] = lch.c;
329
- newLocalValues[`${widget.property}_l`] = lch.l;
330
- } catch {
331
- // Fallback values if conversion fails
332
- newLocalValues[`${widget.property}_l`] = 0;
333
- newLocalValues[`${widget.property}_c`] = 0;
334
- newLocalValues[`${widget.property}_h`] = 0;
335
- }
336
- }
217
+ const value = getNestedProperty<
218
+ string | number | boolean
219
+ >(configData, widget.property);
220
+ if (value !== undefined)
221
+ newLocalValues[widget.property] = value;
222
+ if (
223
+ widget.type === 'color' &&
224
+ typeof value === 'string'
225
+ ) {
226
+ const channels = toHclChannels(value);
227
+ newLocalValues[`${widget.property}_h`] = channels.h;
228
+ newLocalValues[`${widget.property}_c`] = channels.c;
229
+ newLocalValues[`${widget.property}_l`] = channels.l;
337
230
  }
338
231
  });
339
232
  setLocalValues(newLocalValues);
@@ -484,25 +377,19 @@ export const VisualEditor = () => {
484
377
  ) ??
485
378
  '#000000';
486
379
 
487
- // Convert hex to LCH for slider values
488
- let hclColor;
489
- try {
490
- const rgbColor = color(currentHex);
491
- hclColor = hcl(rgbColor);
492
- } catch {
493
- hclColor = hcl('black');
494
- }
495
-
496
- // Use local LCH values if available, otherwise convert from hex
497
- const currentH =
498
- localValues[`${widgetConfig.property}_h`] ??
499
- hclColor.h;
500
- const currentC =
501
- localValues[`${widgetConfig.property}_c`] ??
502
- hclColor.c;
503
- const currentL =
504
- localValues[`${widgetConfig.property}_l`] ??
505
- hclColor.l;
380
+ const channels = toHclChannels(currentHex);
381
+ const currentH = coerceChannelNumber(
382
+ localValues[`${widgetConfig.property}_h`],
383
+ channels.h,
384
+ );
385
+ const currentC = coerceChannelNumber(
386
+ localValues[`${widgetConfig.property}_c`],
387
+ channels.c,
388
+ );
389
+ const currentL = coerceChannelNumber(
390
+ localValues[`${widgetConfig.property}_l`],
391
+ channels.l,
392
+ );
506
393
 
507
394
  return (
508
395
  <ColorWidget
@@ -0,0 +1,39 @@
1
+ import { color, hcl } from 'd3-color';
2
+
3
+ export type HclChannels = {
4
+ h: number;
5
+ c: number;
6
+ l: number;
7
+ };
8
+
9
+ export function toHclChannels(value: string): HclChannels {
10
+ const parsed = color(value);
11
+ const result = parsed ? hcl(parsed) : hcl('black');
12
+ return {
13
+ h: Number.isFinite(result.h) ? result.h : 0,
14
+ c: Number.isFinite(result.c) ? result.c : 0,
15
+ l: Number.isFinite(result.l) ? result.l : 0,
16
+ };
17
+ }
18
+
19
+ /**
20
+ * Coerces a widget value to a finite number, falling back when
21
+ * the stored value is not numeric (widget values may be strings or
22
+ * booleans for other widget types).
23
+ */
24
+ export function coerceChannelNumber(
25
+ value: unknown,
26
+ fallback: number,
27
+ ): number {
28
+ return typeof value === 'number' && Number.isFinite(value)
29
+ ? value
30
+ : fallback;
31
+ }
32
+
33
+ export function hclChannelsToHex(
34
+ channels: HclChannels,
35
+ fallback: string,
36
+ ): string {
37
+ const next = hcl(channels.h, channels.c, channels.l);
38
+ return next.displayable() ? next.formatHex() : fallback;
39
+ }
@@ -1,11 +1,6 @@
1
1
  import { color } from 'd3-color';
2
2
  import type { VisualEditorEmptyReason } from '../../../types';
3
-
4
- const UNSAFE_PATH_SEGMENTS = new Set([
5
- '__proto__',
6
- 'constructor',
7
- 'prototype',
8
- ]);
3
+ import { getEditablePropertyValue } from './utils';
9
4
 
10
5
  const isRecord = (
11
6
  value: unknown,
@@ -14,39 +9,6 @@ const isRecord = (
14
9
  typeof value === 'object' &&
15
10
  !Array.isArray(value);
16
11
 
17
- /**
18
- * Resolve only own properties of plain JSON objects, using the same dot-path
19
- * semantics as setNestedProperty. Missing values, arrays in the path and
20
- * dangerous keys are not editable targets.
21
- */
22
- function editableValueAt(
23
- config: Record<string, unknown>,
24
- path: string,
25
- ): { found: boolean; value: unknown } {
26
- const segments = path.split('.');
27
- if (
28
- segments.some(
29
- (segment) =>
30
- !segment || UNSAFE_PATH_SEGMENTS.has(segment),
31
- )
32
- ) {
33
- return { found: false, value: undefined };
34
- }
35
-
36
- let value: unknown = config;
37
- for (const segment of segments) {
38
- if (
39
- !isRecord(value) ||
40
- !Object.prototype.hasOwnProperty.call(value, segment)
41
- ) {
42
- return { found: false, value: undefined };
43
- }
44
- value = value[segment];
45
- }
46
-
47
- return { found: true, value };
48
- }
49
-
50
12
  /** Pure classifier shared by the visual editor and host integration tests. */
51
13
  export function getVisualEditorEmptyReason(
52
14
  configText: string | null,
@@ -82,7 +44,7 @@ export function getVisualEditorEmptyReason(
82
44
  return 'invalid-widgets';
83
45
  }
84
46
 
85
- const { found, value } = editableValueAt(
47
+ const { found, value } = getEditablePropertyValue(
86
48
  config,
87
49
  widget.property,
88
50
  );
@@ -2,7 +2,10 @@ import type {
2
2
  VizContent,
3
3
  VizFileId,
4
4
  } from '@vizhub/viz-types';
5
- import { setNestedProperty } from './utils';
5
+ import {
6
+ setNestedProperty,
7
+ getEditablePropertyValue,
8
+ } from './utils';
6
9
 
7
10
  /**
8
11
  * Apply a widget edit against the LATEST ShareDB document, not a stale React
@@ -29,6 +32,12 @@ export function updateVisualEditorProperty(
29
32
  Array.isArray(currentConfig)
30
33
  )
31
34
  return document;
35
+ // A widget may become stale after a concurrent config edit. Never recreate
36
+ // a removed property or change the structure of its parent object.
37
+ if (
38
+ !getEditablePropertyValue(currentConfig, property).found
39
+ )
40
+ return document;
32
41
  let updated: Record<string, unknown>;
33
42
  try {
34
43
  updated = setNestedProperty(