@marimo-team/islands 0.26.1-dev108 → 0.26.1-dev112

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 (38) hide show
  1. package/dist/{ErrorBoundary-BW4TciqU.js → ErrorBoundary-pNKOBKXw.js} +1 -1
  2. package/dist/{chat-ui-Be9X-W22.js → chat-ui-C9NZA-bk.js} +3 -3
  3. package/dist/{code-visibility-BKmktPMd.js → code-visibility-B9s3Hl8z.js} +2 -2
  4. package/dist/{common-CSJAjJGa.js → common-Bn3jx0X6.js} +6 -4
  5. package/dist/{data-grid-overlay-editor-DTibdR4H.js → data-grid-overlay-editor-mxwwRaQy.js} +1 -1
  6. package/dist/{error-entries-23Z_1oDM.js → error-entries-1DC4BiYB.js} +166 -155
  7. package/dist/{feedback-button-CPu5SV3b.js → feedback-button-BrzbnRTT.js} +3 -3
  8. package/dist/{glide-data-editor-CC9_NDNi.js → glide-data-editor-Cnsv3NcI.js} +3 -3
  9. package/dist/{globals-BFlYTNoR.js → globals-BGqfFPx8.js} +1 -1
  10. package/dist/{html-to-image-Cw7o1IbE.js → html-to-image-CsvAOgd3.js} +1 -1
  11. package/dist/main.js +10 -10
  12. package/dist/{number-overlay-editor-qDcRKPE0.js → number-overlay-editor-DuSCOMTK.js} +1 -1
  13. package/dist/{process-output-DdBM0lmd.js → process-output-CtfJ_Gbp.js} +2 -2
  14. package/dist/{reveal-component-BE1xhtNc.js → reveal-component-DzmiQyN9.js} +2 -2
  15. package/dist/style.css +1 -1
  16. package/package.json +1 -1
  17. package/src/components/editor/__tests__/cell-renders.test.tsx +327 -1
  18. package/src/components/editor/ai/__tests__/completion-utils.test.ts +12 -20
  19. package/src/components/editor/ai/ai-completion-editor.tsx +391 -289
  20. package/src/components/editor/ai/completion-utils.ts +9 -7
  21. package/src/components/editor/cell/CellDeleteShoulder.tsx +82 -0
  22. package/src/components/editor/cell/DeleteButton.tsx +11 -2
  23. package/src/components/editor/cell/__tests__/CellDeleteShoulder.test.tsx +181 -0
  24. package/src/components/editor/cell/code/cell-editor.tsx +15 -25
  25. package/src/components/editor/chrome/panels/__tests__/logs-panel.test.tsx +26 -2
  26. package/src/components/editor/chrome/panels/logs-panel.tsx +27 -11
  27. package/src/components/editor/notebook-cell.tsx +20 -40
  28. package/src/core/ai/state.ts +6 -0
  29. package/src/core/cells/__tests__/cells.test.ts +34 -20
  30. package/src/core/cells/cell-log-chunks.ts +31 -0
  31. package/src/core/cells/cells.ts +10 -6
  32. package/src/core/codemirror/lsp/__tests__/log-messages.test.ts +1 -1
  33. package/src/core/codemirror/lsp/__tests__/transports.test.ts +1 -1
  34. package/src/core/islands/__tests__/bridge.test.ts +2 -5
  35. package/src/core/session/__tests__/useNotebookSession.hook.test.tsx +10 -1
  36. package/src/css/common.css +11 -0
  37. package/src/hooks/useFinePointer.ts +30 -0
  38. package/src/stories/log-viewer.stories.tsx +48 -44
@@ -1,6 +1,6 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
- import { useChat } from "@ai-sdk/react";
3
+ import { Chat } from "@ai-sdk/react";
4
4
  import { EditorView } from "@codemirror/view";
5
5
  import {
6
6
  CircleCheckIcon,
@@ -8,7 +8,14 @@ import {
8
8
  SparklesIcon,
9
9
  XIcon,
10
10
  } from "lucide-react";
11
- import React, { useCallback, useEffect, useId, useState } from "react";
11
+ import React, {
12
+ useEffect,
13
+ useId,
14
+ useLayoutEffect,
15
+ useRef,
16
+ useState,
17
+ } from "react";
18
+ import useEvent from "react-use-event-hook";
12
19
  import CodeMirrorMerge from "react-codemirror-merge";
13
20
  import { DefaultChatTransport } from "ai";
14
21
  import { Button } from "@/components/ui/button";
@@ -33,18 +40,18 @@ import {
33
40
  cellCompletionSchema,
34
41
  type CompletionUIMessage,
35
42
  } from "@/core/ai/completion-output";
36
- import { AI_SDK_UI_THROTTLE_MS } from "@/core/ai/constants";
37
43
  import { type AiCompletionCell, includeOtherCellsAtom } from "@/core/ai/state";
38
44
  import type { CellId } from "@/core/cells/ids";
39
45
  import { getCodes } from "@/core/codemirror/copilot/getCodes";
40
46
  import type { LanguageAdapterType } from "@/core/codemirror/language/types";
41
47
  import { selectAllText } from "@/core/codemirror/utils";
42
48
  import { useRuntimeManager } from "@/core/runtime/config";
49
+ import type { RuntimeManager } from "@/core/runtime/runtime";
43
50
  import type { AiCompletionRequest } from "@/core/network/types";
44
51
  import { useTheme } from "@/theme/useTheme";
45
52
  import { cn } from "@/utils/cn";
46
53
  import { prettyError } from "@/utils/errors";
47
- import { retryWithTimeout } from "@/utils/timeout";
54
+ import { focusCell } from "../navigation/focus-utils";
48
55
  import { PromptInput } from "./prompt-input";
49
56
  import {
50
57
  AcceptCompletionButton,
@@ -61,243 +68,358 @@ const Modified = CodeMirrorMerge.Modified;
61
68
  interface Props {
62
69
  cellId: CellId;
63
70
  aiCompletionCell: AiCompletionCell | null;
64
- className?: string;
65
71
  currentCode: string;
66
72
  currentLanguageAdapter: LanguageAdapterType | undefined;
67
73
  onChange: (code: string) => void;
68
- declineChange: () => void;
69
- acceptChange: (rightHandCode: string) => void;
74
+ close: () => void;
75
+ focusEditor: () => void;
70
76
  runCell: () => void;
71
77
  outputArea?: "above" | "below";
72
- /**
73
- * Children shown when there is no completion
74
- */
75
78
  children: React.ReactNode;
76
79
  }
77
80
 
78
81
  const baseExtensions = [customPythonLanguageSupport(), EditorView.lineWrapping];
79
82
 
80
- /**
81
- * Editor for AI completions that goes above a cell to modify it.
82
- *
83
- * This shows a left/right split with the original and modified code.
84
- */
85
83
  export const AiCompletionEditor: React.FC<Props> = ({
86
84
  cellId,
87
85
  aiCompletionCell,
88
- className,
89
- onChange,
90
- currentLanguageAdapter,
91
86
  currentCode,
92
- declineChange,
93
- acceptChange,
87
+ currentLanguageAdapter,
88
+ onChange,
89
+ close,
90
+ focusEditor,
94
91
  runCell,
95
- outputArea,
92
+ outputArea = "below",
96
93
  children,
97
94
  }) => {
98
- const [showInputPrompt, setShowInputPrompt] = useState(false);
99
-
100
- const [includeOtherCells, setIncludeOtherCells] = useAtom(
101
- includeOtherCellsAtom,
102
- );
103
- const includeOtherCellsCheckboxId = useId();
95
+ const stagedCell = useStagedAICell(cellId);
96
+ const previousCode =
97
+ stagedCell?.type === "update_cell" ? stagedCell.previousCode : undefined;
104
98
 
105
- const runtimeManager = useRuntimeManager();
106
-
107
- const {
108
- initialPrompt,
109
- triggerImmediately,
110
- cellId: aiCellId,
111
- } = aiCompletionCell ?? {};
112
- const enabled = aiCellId === cellId;
113
-
114
- const updatedCell = useStagedAICell(cellId);
115
- let previousCellCode: string | undefined;
116
- if (updatedCell?.type === "update_cell") {
117
- previousCellCode = updatedCell.previousCode;
118
- }
99
+ const [completion, setCompletion] = useState<string | null>(null);
100
+ const hasCompletion = completion !== null;
101
+ const [isLoading, setIsLoading] = useState(false);
102
+ const [showInputPrompt, setShowInputPrompt] = useState(false);
103
+ const request = useRef<Chat<CompletionUIMessage> | null>(null);
104
+ const chatId = useRef<string>(undefined);
105
+ const restoreFocus = useRef(false);
106
+ const inputRef = useRef<ReactCodeMirrorRef>(null);
119
107
 
120
- const [completion, setCompletion] = useState("");
121
- const [input, setInput] = useState(initialPrompt ?? "");
122
- const transport = React.useMemo(
123
- () =>
124
- new DefaultChatTransport<CompletionUIMessage>({
125
- api: runtimeManager.getAiURL("completion").toString(),
126
- headers: () => runtimeManager.headers(),
127
- prepareSendMessagesRequest: ({ body, id }) => ({
128
- body: { ...body, id },
129
- }),
130
- }),
131
- [runtimeManager],
132
- );
133
- const {
134
- sendMessage,
135
- stop: stopChat,
136
- status,
137
- } = useChat<CompletionUIMessage>({
138
- throttle: AI_SDK_UI_THROTTLE_MS,
139
- transport,
140
- onData: (part) => {
141
- if (part.type === CELL_COMPLETION_DATA_TYPE) {
142
- const completion = cellCompletionSchema.parse(part.data);
143
- setCompletion(completion.code.trimEnd());
144
- }
145
- },
146
- onError: (error) => {
147
- setCompletion("");
148
- toast({
149
- title: "Completion failed",
150
- description: prettyError(error),
151
- });
152
- },
153
- onFinish: ({ isAbort, isDisconnect, isError, finishReason }) => {
154
- if (isAbort || isDisconnect || isError || finishReason !== "stop") {
155
- setCompletion("");
108
+ useEffect(() => {
109
+ return () => {
110
+ const chat = request.current;
111
+ request.current = null;
112
+ void chat?.stop();
113
+ };
114
+ }, []);
115
+
116
+ const complete = useEvent(
117
+ async (
118
+ prompt: string,
119
+ includeOtherCells: boolean,
120
+ runtime: RuntimeManager,
121
+ ) => {
122
+ if (request.current) {
123
+ return;
156
124
  }
157
- },
158
- });
159
- const isLoading = status === "submitted" || status === "streaming";
160
-
161
- const stop = useCallback(() => {
162
- setCompletion("");
163
- void stopChat();
164
- }, [stopChat]);
165
-
166
- const complete = useCallback(
167
- async (prompt: string) => {
168
- await stopChat();
169
- setCompletion("");
170
125
 
171
126
  const body = {
172
- ...getAICompletionBody({ input: prompt }),
127
+ ...getAICompletionBody({
128
+ input: prompt,
129
+ includeOtherCode: includeOtherCells ? getCodes(currentCode) : "",
130
+ }),
173
131
  prompt,
174
- includeOtherCode: includeOtherCells ? getCodes(currentCode) : "",
175
132
  code: currentCode,
176
133
  language: currentLanguageAdapter ?? "python",
177
134
  } satisfies AiCompletionRequest;
178
135
 
179
- await sendMessage({ text: prompt }, { body });
136
+ // A request can finish while another cell owns the prompt.
137
+ const chat = new Chat<CompletionUIMessage>({
138
+ id: chatId.current,
139
+ transport: new DefaultChatTransport({
140
+ api: runtime.getAiURL("completion").toString(),
141
+ headers: () => runtime.headers(),
142
+ prepareSendMessagesRequest: ({ body, id }) => ({
143
+ body: { ...body, id },
144
+ }),
145
+ }),
146
+ onData: (part) => {
147
+ if (
148
+ request.current === chat &&
149
+ part.type === CELL_COMPLETION_DATA_TYPE
150
+ ) {
151
+ const completion = cellCompletionSchema.parse(part.data);
152
+ setCompletion(completion.code.trimEnd());
153
+ }
154
+ },
155
+ onError: (error) => {
156
+ if (request.current === chat) {
157
+ setCompletion(null);
158
+ toast({
159
+ title: "Completion failed",
160
+ description: prettyError(error),
161
+ });
162
+ }
163
+ },
164
+ onFinish: ({ isAbort, isDisconnect, isError, finishReason }) => {
165
+ if (
166
+ request.current === chat &&
167
+ (isAbort || isDisconnect || isError || finishReason !== "stop")
168
+ ) {
169
+ setCompletion(null);
170
+ }
171
+ },
172
+ });
173
+ chatId.current = chat.id;
174
+ request.current = chat;
175
+ setCompletion(null);
176
+ setIsLoading(true);
177
+
178
+ await chat.sendMessage({ text: prompt }, { body }).finally(() => {
179
+ if (request.current === chat) {
180
+ request.current = null;
181
+ setIsLoading(false);
182
+ }
183
+ });
180
184
  },
181
- [
182
- currentCode,
183
- currentLanguageAdapter,
184
- includeOtherCells,
185
- sendMessage,
186
- stopChat,
187
- ],
188
185
  );
189
186
 
190
- const handleSubmit = useCallback(() => {
191
- void complete(input);
192
- }, [complete, input]);
193
-
194
- const inputRef = React.useRef<ReactCodeMirrorRef>(null);
195
-
196
- const initialSubmit = useCallback(() => {
197
- if (triggerImmediately && !isLoading && initialPrompt) {
198
- // Use complete to pass the prompt directly, else input might be empty
199
- void complete(initialPrompt);
200
- }
201
- // oxlint-disable-next-line react-hooks/exhaustive-deps
202
- }, [triggerImmediately]);
187
+ const stop = () => {
188
+ const chat = request.current;
189
+ request.current = null;
190
+ setCompletion(null);
191
+ setIsLoading(false);
192
+ void chat?.stop();
193
+ };
203
194
 
204
- // Focus the input
205
- useEffect(() => {
206
- if (enabled) {
207
- retryWithTimeout(
208
- () => {
209
- const input = inputRef.current;
210
- if (input?.view) {
211
- input.view.focus();
212
- initialSubmit();
213
- return true;
214
- }
215
- return false;
216
- },
217
- { retries: 3, delay: 100, initialDelay: 100 },
218
- ); // Wait for animation to complete
195
+ const closeAndFocusEditor = () => {
196
+ restoreFocus.current = true;
197
+ close();
198
+ };
219
199
 
220
- selectAllText(inputRef.current?.view);
200
+ // Wait until the prompt leaves the DOM to restore focus.
201
+ useLayoutEffect(() => {
202
+ if (!aiCompletionCell && restoreFocus.current) {
203
+ restoreFocus.current = false;
204
+ if (previousCode !== undefined) {
205
+ focusCell(cellId);
206
+ } else {
207
+ focusEditor();
208
+ }
221
209
  }
222
- }, [enabled, initialSubmit]);
210
+ }, [aiCompletionCell, cellId, focusEditor, previousCode]);
223
211
 
224
- // Reset the input when the prompt changes
225
- useEffect(() => {
226
- if (enabled) {
227
- setInput(initialPrompt || "");
212
+ const handleAccept = () => {
213
+ if (!hasCompletion) {
214
+ return;
228
215
  }
229
- }, [enabled, initialPrompt, setInput]);
230
-
231
- const { theme } = useTheme();
232
-
233
- const handleAcceptCompletion = () => {
234
- acceptChange(completion);
235
- setCompletion("");
216
+ onChange(completion);
217
+ setCompletion(null);
218
+ closeAndFocusEditor();
236
219
  };
237
220
 
238
- // Reject discards the suggestion but keeps the prompt open for refinement.
239
- const handleDeclineCompletion = () => {
221
+ const showInput = Boolean(
222
+ aiCompletionCell &&
223
+ (!aiCompletionCell.triggerImmediately || showInputPrompt),
224
+ );
225
+ const handleReject = () => {
240
226
  stop();
241
227
  setShowInputPrompt(true);
242
- inputRef.current?.view?.focus();
228
+ if (showInput) {
229
+ inputRef.current?.view?.focus();
230
+ }
243
231
  };
244
232
 
245
- const showCompletionBanner =
246
- enabled && triggerImmediately && (completion || isLoading);
247
- // Set default output area to below if not specified
248
- outputArea = outputArea ?? "below";
249
-
250
- const showInput = enabled && (!triggerImmediately || showInputPrompt);
251
-
252
- const completionBanner = (
233
+ const comparison = renderCompletionComparison(
234
+ currentCode,
235
+ aiCompletionCell ? completion : null,
236
+ previousCode,
237
+ onChange,
238
+ );
239
+ const showBanner = hasCompletion || isLoading;
240
+ const completionBanner = aiCompletionCell?.triggerImmediately && (
253
241
  <div
254
242
  className={cn(
255
243
  "w-full bg-(--cm-background) flex justify-center transition-all duration-300 ease-in-out overflow-hidden",
256
- showCompletionBanner
244
+ showBanner
257
245
  ? "max-h-20 opacity-100 translate-y-0"
258
246
  : "max-h-0 opacity-0 -translate-y-2",
259
247
  )}
260
248
  >
261
- <CompletionBanner
262
- status={isLoading ? "loading" : "generated"}
263
- onAccept={handleAcceptCompletion}
264
- onReject={handleDeclineCompletion}
265
- showInputPrompt={showInputPrompt}
266
- setShowInputPrompt={setShowInputPrompt}
267
- runCell={runCell}
268
- className="mt-4 mb-3 w-lg"
269
- />
249
+ {showBanner && (
250
+ <CompletionBanner
251
+ status={isLoading ? "loading" : "generated"}
252
+ onAccept={handleAccept}
253
+ onReject={handleReject}
254
+ showInputPrompt={showInputPrompt}
255
+ setShowInputPrompt={setShowInputPrompt}
256
+ runCell={runCell}
257
+ className="mt-4 mb-3 w-lg"
258
+ />
259
+ )}
270
260
  </div>
271
261
  );
272
262
 
273
- const renderMergeEditor = (originalCode: string, modifiedCode: string) => {
274
- return (
275
- <CodeMirrorMerge className="cm" theme={theme}>
276
- <Original
277
- onChange={onChange}
278
- value={originalCode}
279
- extensions={baseExtensions}
280
- />
281
- <Modified
282
- value={modifiedCode}
283
- editable={false}
284
- readOnly={true}
285
- extensions={baseExtensions}
263
+ return (
264
+ <div
265
+ data-ai-input-open={showInput}
266
+ className="flex flex-col w-full rounded-[inherit]"
267
+ >
268
+ {aiCompletionCell && (
269
+ <AiCompletionPrompt
270
+ target={aiCompletionCell}
271
+ inputRef={inputRef}
272
+ showInput={showInput}
273
+ complete={complete}
274
+ hasCompletion={hasCompletion}
275
+ isLoading={isLoading}
276
+ stop={stop}
277
+ onAccept={handleAccept}
278
+ onReject={handleReject}
279
+ onClose={() => {
280
+ stop();
281
+ closeAndFocusEditor();
282
+ }}
283
+ runCell={runCell}
286
284
  />
287
- </CodeMirrorMerge>
285
+ )}
286
+ {outputArea === "above" && completionBanner}
287
+ {comparison}
288
+ <div hidden={comparison !== null}>{children}</div>
289
+ {outputArea === "below" && completionBanner}
290
+ </div>
291
+ );
292
+ };
293
+
294
+ function renderCompletionComparison(
295
+ currentCode: string,
296
+ proposal: string | null,
297
+ previousCode: string | undefined,
298
+ onChange: (code: string) => void,
299
+ ) {
300
+ if (proposal !== null) {
301
+ return (
302
+ <CompletionComparison
303
+ originalCode={currentCode}
304
+ modifiedCode={proposal}
305
+ onChange={onChange}
306
+ />
288
307
  );
289
- };
308
+ }
309
+ if (previousCode !== undefined) {
310
+ return (
311
+ <CompletionComparison
312
+ originalCode={previousCode}
313
+ modifiedCode={currentCode}
314
+ />
315
+ );
316
+ }
317
+ return null;
318
+ }
319
+
320
+ function CompletionComparison({
321
+ originalCode,
322
+ modifiedCode,
323
+ onChange,
324
+ }: {
325
+ originalCode: string;
326
+ modifiedCode: string;
327
+ onChange?: (code: string) => void;
328
+ }) {
329
+ const { theme } = useTheme();
330
+ return (
331
+ <CodeMirrorMerge className="cm" theme={theme}>
332
+ <Original
333
+ onChange={onChange}
334
+ editable={onChange !== undefined}
335
+ readOnly={onChange === undefined}
336
+ value={originalCode}
337
+ extensions={baseExtensions}
338
+ />
339
+ <Modified
340
+ value={modifiedCode}
341
+ editable={false}
342
+ readOnly={true}
343
+ extensions={baseExtensions}
344
+ />
345
+ </CodeMirrorMerge>
346
+ );
347
+ }
290
348
 
291
- const renderCompletionEditor = () => {
292
- if (completion && enabled) {
293
- return renderMergeEditor(currentCode, completion);
349
+ function AiCompletionPrompt({
350
+ target,
351
+ inputRef,
352
+ showInput,
353
+ complete,
354
+ hasCompletion,
355
+ isLoading,
356
+ stop,
357
+ onAccept: handleAcceptCompletion,
358
+ onReject: handleDeclineCompletion,
359
+ onClose,
360
+ runCell,
361
+ }: {
362
+ target: AiCompletionCell;
363
+ inputRef: React.RefObject<ReactCodeMirrorRef | null>;
364
+ showInput: boolean;
365
+ complete: (
366
+ prompt: string,
367
+ includeOtherCells: boolean,
368
+ runtime: RuntimeManager,
369
+ ) => Promise<void>;
370
+ hasCompletion: boolean;
371
+ isLoading: boolean;
372
+ stop: () => void;
373
+ onAccept: () => void;
374
+ onReject: () => void;
375
+ onClose: () => void;
376
+ runCell: () => void;
377
+ }) {
378
+ const [includeOtherCells, setIncludeOtherCells] = useAtom(
379
+ includeOtherCellsAtom,
380
+ );
381
+ const includeOtherCellsCheckboxId = useId();
382
+ const runtime = useRuntimeManager();
383
+ const [draft, setDraft] = useState<{
384
+ target: AiCompletionCell;
385
+ text: string;
386
+ }>();
387
+ const input =
388
+ draft?.target === target ? draft.text : (target.initialPrompt ?? "");
389
+ const setInput = useEvent((text: string) => setDraft({ target, text }));
390
+ const submit = useEvent((prompt: string) => {
391
+ void complete(prompt, includeOtherCells, runtime);
392
+ });
393
+
394
+ useEffect(() => {
395
+ const { initialPrompt, triggerImmediately } = target;
396
+ if (triggerImmediately && initialPrompt) {
397
+ const timer = setTimeout(() => submit(initialPrompt), 100);
398
+ return () => clearTimeout(timer);
294
399
  }
295
- // If there is no completion and there is previous cell code, it means there is an AI change to the cell.
296
- // And we want to render the previous cell code as the original
297
- if (!completion && previousCellCode) {
298
- return renderMergeEditor(previousCellCode, currentCode);
400
+ }, [target, submit]);
401
+
402
+ useEffect(() => {
403
+ const prompt = inputRef.current;
404
+ if (!showInput || prompt?.view?.hasFocus) {
405
+ return;
299
406
  }
300
- };
407
+ const timer = setTimeout(() => {
408
+ const view = inputRef.current?.view;
409
+ if (view && !view.hasFocus) {
410
+ view.focus();
411
+ selectAllText(view);
412
+ }
413
+ }, 100);
414
+ const cancel = () => clearTimeout(timer);
415
+ prompt?.editor?.addEventListener("focusin", cancel, { once: true });
416
+ return () => {
417
+ cancel();
418
+ prompt?.editor?.removeEventListener("focusin", cancel);
419
+ };
420
+ }, [target, showInput, inputRef]);
421
+
422
+ const handleSubmit = () => submit(input);
301
423
 
302
424
  const completionButtons = (
303
425
  <>
@@ -322,115 +444,95 @@ export const AiCompletionEditor: React.FC<Props> = ({
322
444
 
323
445
  return (
324
446
  <div
325
- data-ai-input-open={showInput}
326
- className={cn("flex flex-col w-full rounded-[inherit]", className)}
447
+ className={cn(
448
+ "flex items-center gap-2 px-3 transition-all rounded-[inherit] rounded-b-none duration-300",
449
+ showInput && "max-h-[400px] border-b min-h-11 visible",
450
+ !showInput && "max-h-0 min-h-0 invisible",
451
+ )}
327
452
  >
328
- <div
329
- className={cn(
330
- "flex items-center gap-2 px-3 transition-all rounded-[inherit] rounded-b-none duration-300",
331
- showInput && "max-h-[400px] border-b min-h-11 visible",
332
- !showInput && "max-h-0 min-h-0 invisible",
333
- )}
334
- >
335
- {enabled && (
336
- <>
337
- <SparklesIcon className="text-(--blue-10) shrink-0" size={16} />
338
- <PromptInput
339
- inputRef={inputRef}
340
- className="h-full my-0 py-2 flex items-center"
341
- onClose={() => {
342
- stop();
343
- declineChange();
344
- }}
345
- value={input}
346
- onChange={setInput}
347
- onSubmit={() => {
348
- if (!isLoading) {
349
- if (inputRef.current?.view) {
350
- storePrompt(inputRef.current.view);
351
- }
352
- handleSubmit();
353
- }
354
- }}
355
- onKeyDown={createAiCompletionOnKeydown({
356
- handleAcceptCompletion,
357
- handleDeclineCompletion,
358
- isLoading,
359
- hasCompletion: completion.trim().length > 0,
360
- })}
361
- />
362
-
363
- <div className="-mr-1.5 py-1.5">
364
- <div className="flex flex-row items-center justify-end gap-0.5">
365
- <SendButton
366
- isLoading={isLoading}
367
- onStop={stop}
368
- onSendClick={handleSubmit}
369
- isEmpty={!input.trim()}
370
- showStopLabel={true}
371
- />
372
- <AddContextButton
373
- handleAddContext={() => addContextCompletion(inputRef)}
374
- isLoading={isLoading}
375
- />
376
- <AIModelDropdown
377
- triggerClassName="h-7 text-xs"
378
- iconSize="small"
379
- forRole="edit"
380
- displayIconOnly={true}
381
- placeholder="Edit model"
382
- />
383
- </div>
384
- {completion && (
385
- <div className="mt-1 flex items-center gap-1">
386
- {completionButtons}
387
- </div>
388
- )}
389
- </div>
390
-
391
- <div className="h-full w-px bg-border mx-2" />
392
- <Tooltip content="Include code from other cells">
393
- <div className="flex flex-row items-start gap-1 overflow-hidden">
394
- <Checkbox
395
- data-testid="include-other-cells-checkbox"
396
- id={includeOtherCellsCheckboxId}
397
- checked={includeOtherCells}
398
- onCheckedChange={(checked) =>
399
- setIncludeOtherCells(Boolean(checked))
400
- }
401
- />
402
- <Label
403
- htmlFor={includeOtherCellsCheckboxId}
404
- className="text-muted-foreground text-xs whitespace-nowrap ellipsis"
405
- >
406
- All code
407
- </Label>
408
- </div>
409
- </Tooltip>
410
- <Button
411
- aria-label="Discard AI completion"
412
- data-testid="decline-completion-button"
413
- variant="text"
414
- size="icon"
415
- disabled={isLoading}
416
- onClick={() => {
417
- stop();
418
- declineChange();
419
- }}
420
- >
421
- <XIcon className="text-(--red-10)" size={16} />
422
- </Button>
423
- </>
453
+ <SparklesIcon className="text-(--blue-10) shrink-0" size={16} />
454
+ <PromptInput
455
+ inputRef={inputRef}
456
+ className="h-full my-0 py-2 flex items-center"
457
+ onClose={onClose}
458
+ value={input}
459
+ onChange={setInput}
460
+ onSubmit={() => {
461
+ if (!isLoading) {
462
+ if (inputRef.current?.view) {
463
+ storePrompt(inputRef.current.view);
464
+ }
465
+ handleSubmit();
466
+ }
467
+ }}
468
+ onKeyDown={createAiCompletionOnKeydown({
469
+ handleAcceptCompletion,
470
+ handleDeclineCompletion,
471
+ isLoading,
472
+ hasCompletion,
473
+ })}
474
+ />
475
+
476
+ <div className="-mr-1.5 py-1.5">
477
+ <div className="flex flex-row items-center justify-end gap-0.5">
478
+ <SendButton
479
+ isLoading={isLoading}
480
+ onStop={stop}
481
+ onSendClick={handleSubmit}
482
+ isEmpty={!input.trim()}
483
+ showStopLabel={true}
484
+ />
485
+ <AddContextButton
486
+ handleAddContext={() => addContextCompletion(inputRef)}
487
+ isLoading={isLoading}
488
+ />
489
+ <AIModelDropdown
490
+ triggerClassName="h-7 text-xs"
491
+ iconSize="small"
492
+ forRole="edit"
493
+ displayIconOnly={true}
494
+ placeholder="Edit model"
495
+ />
496
+ </div>
497
+ {hasCompletion && (
498
+ <div className="mt-1 flex items-center gap-1">
499
+ {completionButtons}
500
+ </div>
424
501
  )}
425
502
  </div>
426
- {outputArea === "above" && completionBanner}
427
- {renderCompletionEditor()}
428
- {(!completion || !enabled) && !previousCellCode && children}
429
- {/* By default, show the completion banner below the code */}
430
- {outputArea === "below" && completionBanner}
503
+
504
+ <div className="h-full w-px bg-border mx-2" />
505
+ <Tooltip content="Include code from other cells">
506
+ <div className="flex flex-row items-start gap-1 overflow-hidden">
507
+ <Checkbox
508
+ data-testid="include-other-cells-checkbox"
509
+ id={includeOtherCellsCheckboxId}
510
+ checked={includeOtherCells}
511
+ onCheckedChange={(checked) =>
512
+ setIncludeOtherCells(Boolean(checked))
513
+ }
514
+ />
515
+ <Label
516
+ htmlFor={includeOtherCellsCheckboxId}
517
+ className="text-muted-foreground text-xs whitespace-nowrap ellipsis"
518
+ >
519
+ All code
520
+ </Label>
521
+ </div>
522
+ </Tooltip>
523
+ <Button
524
+ aria-label="Discard AI completion"
525
+ data-testid="decline-completion-button"
526
+ variant="text"
527
+ size="icon"
528
+ disabled={isLoading}
529
+ onClick={onClose}
530
+ >
531
+ <XIcon className="text-(--red-10)" size={16} />
532
+ </Button>
431
533
  </div>
432
534
  );
433
- };
535
+ }
434
536
 
435
537
  interface CompletionBannerProps {
436
538
  status: "loading" | "generated";