feat(composer): carry reference image names and submit on Enter

Propagate an optional imageName through the agent content pipeline
(frontend types → API → domain → prompt building) so reference images
render with their name instead of a bare "image" label.

Also switch PromptComposer to submit on plain Enter (Shift+Enter for
newline, IME-safe) and add a submitDisabled guard wired from the canvas
and home composers.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-08 08:41:15 +08:00
parent 398dec422d
commit 3c5006e2f3
11 changed files with 34 additions and 7 deletions
+1
View File
@@ -306,6 +306,7 @@ export type AgentContent =
| {
type: "image";
imageUrl: string;
imageName?: string;
imageWidth?: number;
imageHeight?: number;
};
@@ -190,6 +190,7 @@ export const CanvasAgentComposer = forwardRef<PromptComposerHandle, CanvasAgentC
onAnnotationPreviewChange={onAnnotationPreviewChange}
onPasteFile={onUploadFile}
onSubmit={onSubmit}
submitDisabled={generating || !canSubmit}
/>
{previewSlot}
<div className="assistant-composer-toolbar">
@@ -632,6 +632,7 @@ export const PromptComposer = forwardRef<
onAnnotationPreviewChange?: (preview: AnnotationPreviewRequest | null) => void;
onPasteFile?: (file: File | null) => void | Promise<void>;
onSubmit?: () => void;
submitDisabled?: boolean;
}
>(function PromptComposer(
{
@@ -648,7 +649,8 @@ export const PromptComposer = forwardRef<
onAnnotationsChange,
onAnnotationPreviewChange,
onPasteFile,
onSubmit
onSubmit,
submitDisabled = false
},
ref
) {
@@ -883,7 +885,8 @@ export const PromptComposer = forwardRef<
}
return {
type: "image",
imageUrl: part.reference.publicUrl
imageUrl: part.reference.publicUrl,
imageName: part.reference.name
};
})
.filter((part): part is AgentContent => Boolean(part));
@@ -1067,9 +1070,10 @@ export const PromptComposer = forwardRef<
}
}
}
if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {
const isComposing = event.nativeEvent.isComposing || event.keyCode === 229;
if (event.key === "Enter" && !event.shiftKey && !isComposing) {
event.preventDefault();
onSubmit?.();
if (!submitDisabled) onSubmit?.();
}
}}
onPaste={handlePaste}
@@ -5393,18 +5393,22 @@ function agentContentsToDisplayText(contents: AgentContent[]) {
return contents
.map((content, index) => {
if (content.type === "text") return content.text;
return `参考图 ${index + 1}image):${content.imageUrl}`;
return `参考图 ${index + 1}${agentContentImageName(content)}):${content.imageUrl}`;
})
.filter((item) => item.trim())
.join("\n\n");
}
function agentContentImageName(content: Extract<AgentContent, { type: "image" }>) {
return content.imageName?.replace(/\s+/g, " ").trim() || "image";
}
function imageGeneratorSubmittedPrompt(contents: AgentContent[]) {
return cleanImageGeneratorPrompt(
contents
.map((content, index) => {
if (content.type === "text" && !isSettingsTextSource(content.textSource)) return content.text;
if (content.type === "image") return `参考图 ${index + 1}${content.imageUrl}`;
if (content.type === "image") return `参考图 ${index + 1}${agentContentImageName(content)}${content.imageUrl}`;
return "";
})
.filter((item) => item.trim())
+1
View File
@@ -736,6 +736,7 @@ export function HomePage() {
onReferenceRemoved={handleReferenceRemoved}
onPasteFile={attachImage}
onSubmit={() => createProject()}
submitDisabled={loading || !canSubmitPrompt}
/>
<div className="prompt-actions">
<input ref={fileInputRef} type="file" accept="image/*" hidden onChange={(event) => void attachImage(event.target.files?.[0] ?? null)} />