feat(kol): add selection-based AI optimize for prompt editor
Trigger an AI optimize panel from a text selection in the KOL prompt editor, accept a user instruction, and stream a preview before replacing the selected fragment. Extend the shared editor AI assist panel with boundary-aware placement so it can be hosted inside scoped surfaces, and update the backend optimize prompt to honor the user instruction. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -115,8 +115,13 @@ func BuildKolAssistUserPrompt(req AssistRequest) (string, error) {
|
||||
}
|
||||
schemaJSON = string(payload)
|
||||
}
|
||||
instruction := strings.TrimSpace(req.Description)
|
||||
if instruction == "" {
|
||||
instruction = "Make the prompt clearer, more complete, and easier for another AI to follow."
|
||||
}
|
||||
return fmt.Sprintf(
|
||||
"Optimize the following prompt. Keep variable placeholders intact. Current schema: %s\n\nPROMPT:\n%s",
|
||||
"Optimize the following prompt according to the instruction. Keep variable placeholders intact.\n\nInstruction:\n%s\n\nCurrent schema: %s\n\nPROMPT:\n%s",
|
||||
instruction,
|
||||
schemaJSON,
|
||||
req.CurrentContent,
|
||||
), nil
|
||||
|
||||
@@ -72,6 +72,20 @@ func TestParseKolAssistResponseSupportsStringVariables(t *testing.T) {
|
||||
require.Equal(t, "城市", result.Schema.Variables[0].Key)
|
||||
}
|
||||
|
||||
func TestBuildKolAssistUserPromptIncludesOptimizeInstruction(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
prompt, err := BuildKolAssistUserPrompt(AssistRequest{
|
||||
Mode: kolAssistModeOptimize,
|
||||
Description: "让表达更清晰,但保留变量",
|
||||
CurrentContent: "围绕 {{城市}} 写一段内容",
|
||||
})
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, prompt, "Instruction:\n让表达更清晰,但保留变量")
|
||||
require.Contains(t, prompt, "PROMPT:\n围绕 {{城市}} 写一段内容")
|
||||
}
|
||||
|
||||
func TestExtractKolAssistContentFromPartialJSON(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user