refactor: separate mode and support prompts

- Rename customPrompts to customModePrompts for mode-specific prompts
- Add new customSupportPrompts type for support action prompts
- Update types to be more specific (CustomModePrompts and CustomSupportPrompts)
- Fix all related tests and component implementations
This commit is contained in:
sam hoang
2025-01-24 01:46:33 +07:00
parent 085d42873c
commit f86e96d157
13 changed files with 119 additions and 99 deletions

View File

@@ -162,7 +162,7 @@ describe("SYSTEM_PROMPT", () => {
undefined, // diffStrategy
undefined, // browserViewportSize
defaultModeSlug, // mode
undefined, // customPrompts
undefined, // customModePrompts
undefined, // customModes
)
@@ -178,7 +178,7 @@ describe("SYSTEM_PROMPT", () => {
undefined, // diffStrategy
"1280x800", // browserViewportSize
defaultModeSlug, // mode
undefined, // customPrompts
undefined, // customModePrompts
undefined, // customModes
)
@@ -196,7 +196,7 @@ describe("SYSTEM_PROMPT", () => {
undefined, // diffStrategy
undefined, // browserViewportSize
defaultModeSlug, // mode
undefined, // customPrompts
undefined, // customModePrompts
undefined, // customModes
)
@@ -212,7 +212,7 @@ describe("SYSTEM_PROMPT", () => {
undefined, // diffStrategy
undefined, // browserViewportSize
defaultModeSlug, // mode
undefined, // customPrompts
undefined, // customModePrompts
undefined, // customModes
)
@@ -228,7 +228,7 @@ describe("SYSTEM_PROMPT", () => {
undefined, // diffStrategy
"900x600", // different viewport size
defaultModeSlug, // mode
undefined, // customPrompts
undefined, // customModePrompts
undefined, // customModes
)
@@ -244,7 +244,7 @@ describe("SYSTEM_PROMPT", () => {
new SearchReplaceDiffStrategy(), // Use actual diff strategy from the codebase
undefined, // browserViewportSize
defaultModeSlug, // mode
undefined, // customPrompts
undefined, // customModePrompts
undefined, // customModes
undefined, // globalCustomInstructions
undefined, // preferredLanguage
@@ -264,7 +264,7 @@ describe("SYSTEM_PROMPT", () => {
new SearchReplaceDiffStrategy(), // Use actual diff strategy from the codebase
undefined, // browserViewportSize
defaultModeSlug, // mode
undefined, // customPrompts
undefined, // customModePrompts
undefined, // customModes
undefined, // globalCustomInstructions
undefined, // preferredLanguage
@@ -284,7 +284,7 @@ describe("SYSTEM_PROMPT", () => {
new SearchReplaceDiffStrategy(), // Use actual diff strategy from the codebase
undefined, // browserViewportSize
defaultModeSlug, // mode
undefined, // customPrompts
undefined, // customModePrompts
undefined, // customModes
undefined, // globalCustomInstructions
undefined, // preferredLanguage
@@ -304,7 +304,7 @@ describe("SYSTEM_PROMPT", () => {
undefined, // diffStrategy
undefined, // browserViewportSize
defaultModeSlug, // mode
undefined, // customPrompts
undefined, // customModePrompts
undefined, // customModes
undefined, // globalCustomInstructions
"Spanish", // preferredLanguage
@@ -334,7 +334,7 @@ describe("SYSTEM_PROMPT", () => {
undefined, // diffStrategy
undefined, // browserViewportSize
"custom-mode", // mode
undefined, // customPrompts
undefined, // customModePrompts
customModes, // customModes
"Global instructions", // globalCustomInstructions
)
@@ -351,7 +351,7 @@ describe("SYSTEM_PROMPT", () => {
})
it("should use promptComponent roleDefinition when available", async () => {
const customPrompts = {
const customModePrompts = {
[defaultModeSlug]: {
roleDefinition: "Custom prompt role definition",
customInstructions: "Custom prompt instructions",
@@ -366,7 +366,7 @@ describe("SYSTEM_PROMPT", () => {
undefined,
undefined,
defaultModeSlug,
customPrompts,
customModePrompts,
undefined,
)
@@ -377,7 +377,7 @@ describe("SYSTEM_PROMPT", () => {
})
it("should fallback to modeConfig roleDefinition when promptComponent has no roleDefinition", async () => {
const customPrompts = {
const customModePrompts = {
[defaultModeSlug]: {
customInstructions: "Custom prompt instructions",
// No roleDefinition provided
@@ -392,7 +392,7 @@ describe("SYSTEM_PROMPT", () => {
undefined,
undefined,
defaultModeSlug,
customPrompts,
customModePrompts,
undefined,
)
@@ -432,7 +432,7 @@ describe("addCustomInstructions", () => {
undefined, // diffStrategy
undefined, // browserViewportSize
"architect", // mode
undefined, // customPrompts
undefined, // customModePrompts
undefined, // customModes
)
@@ -448,7 +448,7 @@ describe("addCustomInstructions", () => {
undefined, // diffStrategy
undefined, // browserViewportSize
"ask", // mode
undefined, // customPrompts
undefined, // customModePrompts
undefined, // customModes
)

View File

@@ -1,7 +1,7 @@
import {
Mode,
modes,
CustomPrompts,
CustomModePrompts,
PromptComponent,
getRoleDefinition,
defaultModeSlug,
@@ -97,7 +97,7 @@ export const SYSTEM_PROMPT = async (
diffStrategy?: DiffStrategy,
browserViewportSize?: string,
mode: Mode = defaultModeSlug,
customPrompts?: CustomPrompts,
customModePrompts?: CustomModePrompts,
customModes?: ModeConfig[],
globalCustomInstructions?: string,
preferredLanguage?: string,
@@ -115,7 +115,7 @@ export const SYSTEM_PROMPT = async (
}
// Check if it's a custom mode
const promptComponent = getPromptComponent(customPrompts?.[mode])
const promptComponent = getPromptComponent(customModePrompts?.[mode])
// Get full mode config from custom modes or fall back to built-in modes
const currentMode = getModeBySlug(mode, customModes) || modes.find((m) => m.slug === mode) || modes[0]