Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix empty submits and output area (#6794)

Shahmir Varqha76a8b4960292
diff --git a/frontend/src/components/editor/ai/ai-completion-editor.tsx b/frontend/src/components/editor/ai/ai-completion-editor.tsx
index f8eeb176ae..58c104fa2e 100644
--- a/frontend/src/components/editor/ai/ai-completion-editor.tsx
+++ b/frontend/src/components/editor/ai/ai-completion-editor.tsx
@@ -50,6 +50,7 @@ interface Props {
enabled: boolean;
triggerImmediately?: boolean;
runCell: () => void;
+ outputArea?: "above" | "below";
/**
* Children shown when there is no completion
*/
@@ -74,6 +75,7 @@ export const AiCompletionEditor: React.FC<Props> = ({
enabled,
triggerImmediately,
runCell,
+ outputArea,
children,
}) => {
const [showInputPrompt, setShowInputPrompt] = useState(false);
@@ -94,6 +96,7 @@ export const AiCompletionEditor: React.FC<Props> = ({
setCompletion,
setInput,
handleSubmit,
+ complete,
} = useCompletion({
api: runtimeManager.getAiURL("completion").toString(),
headers: runtimeManager.headers(),
@@ -128,7 +131,8 @@ export const AiCompletionEditor: React.FC<Props> = ({
const initialSubmit = useCallback(() => {
if (triggerImmediately && !isLoading && initialPrompt) {
- handleSubmit();
+ // Use complete to pass the prompt directly, else input might be empty
+ complete(initialPrompt);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [triggerImmediately]);
@@ -177,6 +181,27 @@ export const AiCompletionEditor: React.FC<Props> = ({
const showInput = enabled && (!triggerImmediately || showInputPrompt);
+ const completionBanner = (
+ <div
+ className={cn(
+ "w-full bg-(--cm-background) flex justify-center transition-all duration-300 ease-in-out overflow-hidden",
+ showCompletionBanner
+ ? "max-h-20 opacity-100 translate-y-0"
+ : "max-h-0 opacity-0 -translate-y-2",
+ )}
+ >
+ <CompletionBanner
+ status={isLoading ? "loading" : "generated"}
+ onAccept={handleAcceptCompletion}
+ onReject={handleDeclineCompletion}
+ showInputPrompt={showInputPrompt}
+ setShowInputPrompt={setShowInputPrompt}
+ runCell={runCell}
+ className="mt-4 mb-3 w-128"
+ />
+ </div>
+ );
+
return (
<div className={cn("flex flex-col w-full rounded-[inherit]", className)}>
<div
@@ -292,6 +317,7 @@ export const AiCompletionEditor: React.FC<Props> = ({
</>
)}
</div>
+ {outputArea === "above" && completionBanner}
{completion && enabled && (
<CodeMirrorMerge className="cm" theme={theme}>
<Original
@@ -308,24 +334,8 @@ export const AiCompletionEditor: React.FC<Props> = ({
</CodeMirrorMerge>
)}
{(!completion || !enabled) && children}
- <div
- className={cn(
- "w-full bg-(--cm-background) flex justify-center transition-all duration-300 ease-in-out overflow-hidden",
- showCompletionBanner
- ? "max-h-20 opacity-100 translate-y-0"
- : "max-h-0 opacity-0 -translate-y-2",
- )}
- >
- <CompletionBanner
- status={isLoading ? "loading" : "generated"}
- onAccept={handleAcceptCompletion}
- onReject={handleDeclineCompletion}
- showInputPrompt={showInputPrompt}
- setShowInputPrompt={setShowInputPrompt}
- runCell={runCell}
- className="mt-4 mb-3 w-128"
- />
- </div>
+ {/* By default, show the completion banner below the code */}
+ {(outputArea === "below" || !outputArea) && completionBanner}
</div>
);
};
diff --git a/frontend/src/components/editor/cell/code/cell-editor.tsx b/frontend/src/components/editor/cell/code/cell-editor.tsx
index b2ad540a91..daddecf26d 100644
--- a/frontend/src/components/editor/cell/code/cell-editor.tsx
+++ b/frontend/src/components/editor/cell/code/cell-editor.tsx
@@ -67,6 +67,7 @@ export interface CellEditorProps
// DOM node where the editorView will be mounted
editorViewParentRef?: React.RefObject<HTMLDivElement | null>;
showHiddenCode: (opts?: { focus?: boolean }) => void;
+ outputArea?: "above" | "below";
}
const CellEditorInternal = ({
@@ -88,6 +89,7 @@ const CellEditorInternal = ({
languageAdapter,
setLanguageAdapter,
showLanguageToggles = true,
+ outputArea,
}: CellEditorProps) => {
const [aiCompletionCell, setAiCompletionCell] = useAtom(aiCompletionCellAtom);
const deleteCell = useDeleteCellCallback();
@@ -435,6 +437,7 @@ const CellEditorInternal = ({
setAiCompletionCell(null);
})}
runCell={handleRunCell}
+ outputArea={outputArea}
>
<div className="relative w-full" {...navigationProps}>
{showHideButton && (
diff --git a/frontend/src/components/editor/notebook-cell.tsx b/frontend/src/components/editor/notebook-cell.tsx
index 6534578d8a..6ba56706eb 100644
--- a/frontend/src/components/editor/notebook-cell.tsx
+++ b/frontend/src/components/editor/notebook-cell.tsx
@@ -628,6 +628,7 @@ const EditableCellComponent = ({
showHiddenCode={showHiddenCode}
languageAdapter={languageAdapter}
setLanguageAdapter={setLanguageAdapter}
+ outputArea={cellOutput}
/>
<CellRightSideActions
className={cn(