vzcode 2.30.0 → 2.34.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/index.html CHANGED
@@ -20,7 +20,7 @@
20
20
  href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap"
21
21
  rel="stylesheet"
22
22
  />
23
- <script type="module" crossorigin src="/assets/index-CD0x02Rq.js"></script>
23
+ <script type="module" crossorigin src="/assets/index-nL6to42p.js"></script>
24
24
  <link rel="stylesheet" crossorigin href="/assets/index-Dyt9tpmu.css">
25
25
  </head>
26
26
  <body>
@@ -248,22 +248,50 @@ export const finalizeAIMessage = (shareDBDoc, chatId) => {
248
248
  shareDBDoc.submitOp(op);
249
249
  };
250
250
  /**
251
- * Adds diff data to the most recent AI message
251
+ * Adds diff data to a specific AI message by ID
252
+ * Phase 3 Fix: Use explicit message ID instead of assuming
253
+ * last message is AI, preventing bugs with rapid message sends
252
254
  */
253
- export const addDiffToAIMessage = (shareDBDoc, chatId, diffData, beforeCommitId) => {
255
+ export const addDiffToAIMessage = (shareDBDoc, chatId, diffData, beforeCommitId, // Commit ID before AI changes
256
+ messageId) => {
254
257
  const chat = shareDBDoc.data.chats[chatId];
258
+ if (!chat || !chat.messages) {
259
+ console.warn(`Chat ${chatId} not found or has no messages`);
260
+ return;
261
+ }
255
262
  const messages = [...chat.messages];
256
- // Find the most recent AI message
257
- const lastAIMessageIndex = messages.length - 1;
258
- if (lastAIMessageIndex >= 0 &&
259
- messages[lastAIMessageIndex].role === 'assistant') {
263
+ let targetMessageIndex = -1;
264
+ // Phase 3 Fix: Use explicit message ID if provided
265
+ if (messageId) {
266
+ targetMessageIndex = messages.findIndex((msg) => msg.id === messageId);
267
+ if (targetMessageIndex === -1 ||
268
+ messages[targetMessageIndex].role !== 'assistant') {
269
+ console.warn(`AI message with id ${messageId} not found in chat ${chatId}`);
270
+ return;
271
+ }
272
+ }
273
+ else {
274
+ // Fallback: Find the most recent AI message (safer than
275
+ // just assuming last message)
276
+ for (let i = messages.length - 1; i >= 0; i--) {
277
+ if (messages[i].role === 'assistant') {
278
+ targetMessageIndex = i;
279
+ break;
280
+ }
281
+ }
282
+ if (targetMessageIndex === -1) {
283
+ console.warn(`No AI message found in chat ${chatId}`);
284
+ return;
285
+ }
286
+ }
287
+ // Update the target message with diff data
288
+ if (targetMessageIndex >= 0) {
260
289
  const newMessage = {
261
- ...messages[lastAIMessageIndex],
290
+ ...messages[targetMessageIndex],
262
291
  diffData,
263
- ...(beforeCommitId && { beforeCommitId }), // Add beforeCommitId for VizHub integration
292
+ ...(beforeCommitId && { beforeCommitId }),
264
293
  };
265
- // Use type assertion to extend the message with diffData
266
- messages[lastAIMessageIndex] = newMessage;
294
+ messages[targetMessageIndex] = newMessage;
267
295
  const messageOp = diff(shareDBDoc.data, {
268
296
  ...shareDBDoc.data,
269
297
  chats: {
@@ -276,6 +304,8 @@ export const addDiffToAIMessage = (shareDBDoc, chatId, diffData, beforeCommitId)
276
304
  },
277
305
  });
278
306
  shareDBDoc.submitOp(messageOp);
307
+ DEBUG &&
308
+ console.log(`addDiffToAIMessage: Successfully added diff to message ${targetMessageIndex} in chat ${chatId}`);
279
309
  }
280
310
  };
281
311
  /**
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "vzcode",
3
- "version": "2.30.0",
3
+ "version": "2.34.0",
4
4
  "description": "Multiplayer code editor system",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
7
- "bin": "dist/cli.js",
7
+ "bin": {
8
+ "vzcode": "dist/cli.js"
9
+ },
8
10
  "files": [
9
11
  "dist/**",
10
12
  "src/**"
@@ -189,6 +189,7 @@ export const getOrCreateEditor = async ({
189
189
  rainbowBracketsEnabled = true,
190
190
  setIsAIChatOpen,
191
191
  setAIChatMessage,
192
+ enableBuiltInAIChat = true,
192
193
  }: {
193
194
  // TODO pass this in from the outside
194
195
  paneId?: PaneId;
@@ -226,6 +227,10 @@ export const getOrCreateEditor = async ({
226
227
  rainbowBracketsEnabled?: boolean; // New parameter type
227
228
  setIsAIChatOpen: (isAIChatOpen: boolean) => void;
228
229
  setAIChatMessage: (message: string) => void;
230
+ // When false, skip the "Implement the TODO" widget, which opens
231
+ // VZCode's built-in AI chat (hosts that own the AI entry point
232
+ // disable it).
233
+ enableBuiltInAIChat?: boolean;
229
234
  }): Promise<ExtendedEditorCacheValue> => {
230
235
  // Cache hit
231
236
 
@@ -580,7 +585,7 @@ export const getOrCreateEditor = async ({
580
585
  return todoPlugin;
581
586
  }
582
587
 
583
- if (enableToDoPlugin) {
588
+ if (enableToDoPlugin && enableBuiltInAIChat) {
584
589
  extensions.push(createToDoPlugin());
585
590
  }
586
591
  }
@@ -22,12 +22,14 @@ export const CodeEditor = ({
22
22
  customInteractRules,
23
23
  aiCopilotEndpoint,
24
24
  esLintSource,
25
+ enableBuiltInAIChat = true,
25
26
  }: {
26
27
  customInteractRules?: Array<InteractRule>;
27
28
  aiCopilotEndpoint?: string;
28
29
  esLintSource: (
29
30
  view: EditorView,
30
31
  ) => Promise<readonly Diagnostic[]>;
32
+ enableBuiltInAIChat?: boolean;
31
33
  }) => {
32
34
  const {
33
35
  activePane,
@@ -118,6 +120,7 @@ export const CodeEditor = ({
118
120
  esLintSource,
119
121
  setIsAIChatOpen,
120
122
  setAIChatMessage,
123
+ enableBuiltInAIChat,
121
124
  });
122
125
 
123
126
  if (isMounted) {
@@ -143,6 +146,7 @@ export const CodeEditor = ({
143
146
  esLintSource,
144
147
  setIsAIChatOpen,
145
148
  setAIChatMessage,
149
+ enableBuiltInAIChat,
146
150
  ]);
147
151
 
148
152
  // Every time the active file switches from one file to another,
@@ -1,4 +1,6 @@
1
1
  import {
2
+ VZInitialSidebarView,
3
+ VisualEditorEmptyReason,
2
4
  ItemId,
3
5
  LeafPane,
4
6
  Pane,
@@ -91,6 +93,10 @@ export type VZCodeContextValue = {
91
93
  setIsSearchOpen: (isSearchOpen: boolean) => void;
92
94
  setSearch: (pattern: string) => void;
93
95
 
96
+ /** Host-provided replacement for the built-in visual-editor empty states. */
97
+ renderVisualEditorEmptyState?: (
98
+ reason: VisualEditorEmptyReason,
99
+ ) => React.ReactNode;
94
100
  isVisualEditorOpen: boolean;
95
101
  setIsVisualEditorOpen: (
96
102
  isVisualEditorOpen: boolean,
@@ -226,6 +232,12 @@ export interface VZCodeProviderProps {
226
232
  docPresence: any;
227
233
  prettierWorker: Worker;
228
234
  initialUsername: Username;
235
+ /** Initial sidebar selection; defaults to VZCode's historical AI chat. */
236
+ initialSidebarView?: VZInitialSidebarView;
237
+ /** Optional host UI for a missing/invalid/unconfigured visual editor. */
238
+ renderVisualEditorEmptyState?: (
239
+ reason: VisualEditorEmptyReason,
240
+ ) => React.ReactNode;
229
241
  children: React.ReactNode;
230
242
  codeError?: string | null;
231
243
  connected?: boolean;
@@ -37,6 +37,8 @@ export const useVZCodeState = ({
37
37
  docPresence,
38
38
  prettierWorker,
39
39
  initialUsername,
40
+ initialSidebarView,
41
+ renderVisualEditorEmptyState,
40
42
  codeError = null,
41
43
  connected,
42
44
  pending,
@@ -101,7 +103,7 @@ export const useVZCodeState = ({
101
103
  // See https://react.dev/reference/react/useReducer
102
104
  const [state, dispatch] = useReducer(
103
105
  vzReducer,
104
- { defaultTheme, initialUsername },
106
+ { defaultTheme, initialUsername, initialSidebarView },
105
107
  createInitialState,
106
108
  );
107
109
 
@@ -541,6 +543,7 @@ export const useVZCodeState = ({
541
543
  activeChatId,
542
544
  aiChatMode,
543
545
  autoForkAndRetryAI,
546
+ onAIChatMessageSubmitted,
544
547
  DEBUG,
545
548
  setAIErrorMessage,
546
549
  ],
@@ -669,6 +672,7 @@ export const useVZCodeState = ({
669
672
  setSearchFocusedIndex,
670
673
  toggleSearchFocused,
671
674
 
675
+ renderVisualEditorEmptyState,
672
676
  isVisualEditorOpen,
673
677
  setIsVisualEditorOpen,
674
678
 
@@ -10,10 +10,25 @@ import { VoiceChatModal } from './VZSidebar/VoiceChatModal';
10
10
  // * The sidebar
11
11
  // * The settings modal
12
12
  // * The create file modal
13
- export const VZLeft = ({ enableUsernameField = true }) => {
13
+ //
14
+ // `enableAIChat` is forwarded to `VZSidebar` so a host can hide the
15
+ // "Edit with AI" sidebar button. `undefined` falls back to the
16
+ // compile-time feature flag.
17
+ export const VZLeft = ({
18
+ enableUsernameField = true,
19
+ enableAIChat,
20
+ aiChatButtonEvent,
21
+ }: {
22
+ enableUsernameField?: boolean;
23
+ enableAIChat?: boolean;
24
+ aiChatButtonEvent?: string;
25
+ } = {}) => {
14
26
  return (
15
27
  <div className="left">
16
- <VZSidebar />
28
+ <VZSidebar
29
+ enableAIChat={enableAIChat}
30
+ aiChatButtonEvent={aiChatButtonEvent}
31
+ />
17
32
  <VZSettings
18
33
  enableUsernameField={enableUsernameField}
19
34
  />
@@ -28,6 +28,7 @@ const PaneView = ({
28
28
  aiAssistClickOverride,
29
29
  aiCopilotEndpoint,
30
30
  esLintSource,
31
+ enableBuiltInAIChat,
31
32
  }) => {
32
33
  // This prevents the CodeEditor from rendering
33
34
  // during SSR.
@@ -67,6 +68,7 @@ const PaneView = ({
67
68
  customInteractRules={customInteractRules}
68
69
  aiCopilotEndpoint={aiCopilotEndpoint}
69
70
  esLintSource={esLintSource}
71
+ enableBuiltInAIChat={enableBuiltInAIChat}
70
72
  />
71
73
  );
72
74
  })()}
@@ -104,6 +106,8 @@ export const VZMiddle = ({
104
106
  aiCopilotEndpoint,
105
107
  customInteractRules,
106
108
  esLintSource,
109
+ enableAIChat = true,
110
+ aiChatButtonEvent,
107
111
  }: {
108
112
  enableAIAssist?: boolean;
109
113
  aiAssistEndpoint?: string;
@@ -115,7 +119,14 @@ export const VZMiddle = ({
115
119
  esLintSource: (
116
120
  view: EditorView,
117
121
  ) => Promise<readonly Diagnostic[]>;
122
+ enableAIChat?: boolean;
123
+ aiChatButtonEvent?: string;
118
124
  }) => {
125
+ // The built-in AI chat (including the TODO widget, which prefills a
126
+ // chat message) is only reachable when the feature is enabled and the
127
+ // host hasn't taken over the sidebar button with a custom event.
128
+ const enableBuiltInAIChat =
129
+ enableAIChat && !aiChatButtonEvent;
119
130
  const { codeEditorWidth } = useContext(
120
131
  SplitPaneResizeContext,
121
132
  );
@@ -152,6 +163,7 @@ export const VZMiddle = ({
152
163
  aiAssistClickOverride={aiAssistClickOverride}
153
164
  aiCopilotEndpoint={aiCopilotEndpoint}
154
165
  esLintSource={esLintSource}
166
+ enableBuiltInAIChat={enableBuiltInAIChat}
155
167
  />
156
168
  <CodeErrorOverlay
157
169
  errorMessage={errorMessage}