Skip to content

Commit 506724f

Browse files
committed
Refactor instruction state to support multiple tabs per prompt type and update the PromptField UI to handle tab management
1 parent 321f3c8 commit 506724f

29 files changed

Lines changed: 1713 additions & 950 deletions

‎apps/editor/src/constants/state-keys.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ export const WEB_MODE_STATE_KEY = 'web-mode'
3535
export const API_MODE_STATE_KEY = 'api-mode'
3636
export const PANEL_MODE_STATE_KEY = 'panel-mode'
3737

38-
export const INSTRUCTIONS_EDIT_CONTEXT_STATE_KEY = 'instructions-edit-context'
39-
export const INSTRUCTIONS_ASK_STATE_KEY = 'instructions-ask'
40-
export const INSTRUCTIONS_NO_CONTEXT_STATE_KEY = 'instructions-no-context'
38+
export const INSTRUCTIONS_EDIT_CONTEXT_STATE_KEY = 'instructions-edit-context1'
39+
export const INSTRUCTIONS_ASK_STATE_KEY = 'instructions-ask1'
40+
export const INSTRUCTIONS_NO_CONTEXT_STATE_KEY = 'instructions-no-context1'
4141
export const INSTRUCTIONS_CODE_AT_CURSOR_STATE_KEY =
42-
'instructions-code-at-cursor'
43-
export const INSTRUCTIONS_PRUNE_CONTEXT_STATE_KEY = 'instructions-prune-context'
42+
'instructions-code-at-cursor1'
43+
export const INSTRUCTIONS_PRUNE_CONTEXT_STATE_KEY =
44+
'instructions-prune-context1'
4445

4546
export const ARE_TASKS_COLLAPSED_STATE_KEY = 'are-tasks-collapsed'
4647
export const IS_TIMELINE_COLLAPSED_STATE_KEY = 'is-timeline-collapsed'

‎apps/editor/src/views/panel/backend/message-handlers/handle-at-sign-quick-pick/handle-at-sign-quick-pick.ts‎

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -271,23 +271,7 @@ export const handle_at_sign_quick_pick = async (
271271
return
272272
}
273273

274-
let current_text = ''
275-
276-
const prompt_type =
277-
panel_provider.mode == MODE.WEB
278-
? panel_provider.web_prompt_type
279-
: panel_provider.api_prompt_type
280-
if (prompt_type == 'ask-about-context') {
281-
current_text = panel_provider.ask_about_context_instructions
282-
} else if (prompt_type == 'edit-context') {
283-
current_text = panel_provider.edit_context_instructions
284-
} else if (prompt_type == 'no-context') {
285-
current_text = panel_provider.no_context_instructions
286-
} else if (prompt_type == 'code-at-cursor') {
287-
current_text = panel_provider.code_at_cursor_instructions
288-
} else if (prompt_type == 'prune-context') {
289-
current_text = panel_provider.prune_context_instructions
290-
}
274+
const current_text = panel_provider.current_instruction
291275

292276
const is_after_at_sign = current_text
293277
.slice(0, panel_provider.caret_position)

‎apps/editor/src/views/panel/backend/message-handlers/handle-code-at-cursor.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ export const handle_code_at_cursor = async (
252252
const api_providers_manager = new ModelProvidersManager(
253253
panel_provider.context
254254
)
255-
const completion_instructions = panel_provider.code_at_cursor_instructions
255+
const completion_instructions =
256+
panel_provider.current_code_at_cursor_instruction
256257

257258
const config_result = await get_code_at_cursor_config(
258259
api_providers_manager,

‎apps/editor/src/views/panel/backend/message-handlers/handle-hash-sign-quick-pick/handle-hash-sign-quick-pick.ts‎

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -179,23 +179,7 @@ export const handle_hash_sign_quick_pick = async (
179179
return
180180
}
181181

182-
let current_text = ''
183-
184-
const prompt_type =
185-
panel_provider.mode == MODE.WEB
186-
? panel_provider.web_prompt_type
187-
: panel_provider.api_prompt_type
188-
if (prompt_type == 'ask-about-context') {
189-
current_text = panel_provider.ask_about_context_instructions
190-
} else if (prompt_type == 'edit-context') {
191-
current_text = panel_provider.edit_context_instructions
192-
} else if (prompt_type == 'no-context') {
193-
current_text = panel_provider.no_context_instructions
194-
} else if (prompt_type == 'code-at-cursor') {
195-
current_text = panel_provider.code_at_cursor_instructions
196-
} else if (prompt_type == 'prune-context') {
197-
current_text = panel_provider.prune_context_instructions
198-
}
182+
const current_text = panel_provider.current_instruction
199183

200184
const is_after_hash_sign = current_text
201185
.slice(0, panel_provider.caret_position)

‎apps/editor/src/views/panel/backend/message-handlers/handle-preview-preset.ts‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,7 @@ export const handle_preview_preset = async (
3737
const active_path = active_editor?.document.uri.fsPath
3838

3939
let text_to_send: string
40-
let current_instructions = ''
41-
if (panel_provider.web_prompt_type == 'ask-about-context') {
42-
current_instructions = panel_provider.ask_about_context_instructions
43-
} else if (panel_provider.web_prompt_type == 'edit-context') {
44-
current_instructions = panel_provider.edit_context_instructions
45-
} else if (panel_provider.web_prompt_type == 'no-context') {
46-
current_instructions = panel_provider.no_context_instructions
47-
} else if (panel_provider.web_prompt_type == 'code-at-cursor') {
48-
current_instructions = panel_provider.code_at_cursor_instructions
49-
}
40+
const current_instructions = panel_provider.current_instruction
5041

5142
if (panel_provider.web_prompt_type == 'code-at-cursor' && active_editor) {
5243
const document = active_editor.document

‎apps/editor/src/views/panel/backend/message-handlers/handle-save-instructions.ts‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { PanelProvider } from '@/views/panel/backend/panel-provider'
2-
import { SaveInstructionsMessage } from '@/views/panel/types/messages'
2+
import {
3+
SaveInstructionsMessage,
4+
InstructionsState
5+
} from '@/views/panel/types/messages'
36
import {
47
INSTRUCTIONS_ASK_STATE_KEY,
58
INSTRUCTIONS_CODE_AT_CURSOR_STATE_KEY,
@@ -12,37 +15,38 @@ export const handle_save_instructions = async (
1215
panel_provider: PanelProvider,
1316
message: SaveInstructionsMessage
1417
): Promise<void> => {
15-
const { prompt_type, instruction } = message
18+
const { prompt_type, instruction } = message as any
19+
const instruction_state = instruction as InstructionsState
1620

1721
if (prompt_type == 'ask-about-context') {
18-
panel_provider.ask_about_context_instructions = instruction
22+
panel_provider.ask_about_context_instructions = instruction_state
1923
await panel_provider.context.workspaceState.update(
2024
INSTRUCTIONS_ASK_STATE_KEY,
21-
instruction
25+
instruction_state
2226
)
2327
} else if (prompt_type == 'edit-context') {
24-
panel_provider.edit_context_instructions = instruction
28+
panel_provider.edit_context_instructions = instruction_state
2529
await panel_provider.context.workspaceState.update(
2630
INSTRUCTIONS_EDIT_CONTEXT_STATE_KEY,
27-
instruction
31+
instruction_state
2832
)
2933
} else if (prompt_type == 'no-context') {
30-
panel_provider.no_context_instructions = instruction
34+
panel_provider.no_context_instructions = instruction_state
3135
await panel_provider.context.workspaceState.update(
3236
INSTRUCTIONS_NO_CONTEXT_STATE_KEY,
33-
instruction
37+
instruction_state
3438
)
3539
} else if (prompt_type == 'code-at-cursor') {
36-
panel_provider.code_at_cursor_instructions = instruction
40+
panel_provider.code_at_cursor_instructions = instruction_state
3741
await panel_provider.context.workspaceState.update(
3842
INSTRUCTIONS_CODE_AT_CURSOR_STATE_KEY,
39-
instruction
43+
instruction_state
4044
)
4145
} else if (prompt_type == 'prune-context') {
42-
panel_provider.prune_context_instructions = instruction
46+
panel_provider.prune_context_instructions = instruction_state
4347
await panel_provider.context.workspaceState.update(
4448
INSTRUCTIONS_PRUNE_CONTEXT_STATE_KEY,
45-
instruction
49+
instruction_state
4650
)
4751
} else {
4852
return

‎apps/editor/src/views/panel/backend/message-handlers/handle-send-to-browser.ts‎

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,9 @@ export const handle_send_to_browser = async (params: {
4848
return
4949
}
5050

51-
let current_instructions = ''
5251
const is_in_code_completions_mode =
5352
params.panel_provider.web_prompt_type == 'code-at-cursor'
54-
55-
if (is_in_code_completions_mode) {
56-
current_instructions = params.panel_provider.code_at_cursor_instructions
57-
} else {
58-
if (params.panel_provider.web_prompt_type == 'ask-about-context') {
59-
current_instructions =
60-
params.panel_provider.ask_about_context_instructions
61-
} else if (params.panel_provider.web_prompt_type == 'edit-context') {
62-
current_instructions = params.panel_provider.edit_context_instructions
63-
} else if (params.panel_provider.web_prompt_type == 'no-context') {
64-
current_instructions = params.panel_provider.no_context_instructions
65-
} else if (params.panel_provider.web_prompt_type == 'prune-context') {
66-
current_instructions = params.panel_provider.prune_context_instructions
67-
}
68-
}
53+
const current_instructions = params.panel_provider.current_instruction
6954

7055
const active_editor = vscode.window.activeTextEditor
7156

@@ -114,11 +99,7 @@ export const handle_send_to_browser = async (params: {
11499
const text_after_cursor = document.getText(
115100
new vscode.Range(position, document.positionAt(document.getText().length))
116101
)
117-
118-
const completion_instructions =
119-
params.panel_provider.code_at_cursor_instructions
120-
121-
let processed_completion_instructions = completion_instructions
102+
let processed_completion_instructions = current_instructions
122103
let skill_definitions = ''
123104

124105
if (processed_completion_instructions.includes('#Selection')) {
@@ -574,15 +555,30 @@ async function resolve_presets(params: {
574555

575556
let current_instructions = ''
576557
if (params.panel_provider.web_prompt_type == 'code-at-cursor') {
577-
current_instructions = params.panel_provider.code_at_cursor_instructions
558+
current_instructions =
559+
params.panel_provider.code_at_cursor_instructions.instructions[
560+
params.panel_provider.code_at_cursor_instructions.active_index
561+
] || ''
578562
} else if (params.panel_provider.web_prompt_type == 'ask-about-context') {
579-
current_instructions = params.panel_provider.ask_about_context_instructions
563+
current_instructions =
564+
params.panel_provider.ask_about_context_instructions.instructions[
565+
params.panel_provider.ask_about_context_instructions.active_index
566+
] || ''
580567
} else if (params.panel_provider.web_prompt_type == 'edit-context') {
581-
current_instructions = params.panel_provider.edit_context_instructions
568+
current_instructions =
569+
params.panel_provider.edit_context_instructions.instructions[
570+
params.panel_provider.edit_context_instructions.active_index
571+
] || ''
582572
} else if (params.panel_provider.web_prompt_type == 'no-context') {
583-
current_instructions = params.panel_provider.no_context_instructions
573+
current_instructions =
574+
params.panel_provider.no_context_instructions.instructions[
575+
params.panel_provider.no_context_instructions.active_index
576+
] || ''
584577
} else if (params.panel_provider.web_prompt_type == 'prune-context') {
585-
current_instructions = params.panel_provider.prune_context_instructions
578+
current_instructions =
579+
params.panel_provider.prune_context_instructions.instructions[
580+
params.panel_provider.prune_context_instructions.active_index
581+
] || ''
586582
}
587583

588584
const get_is_preset_disabled = (preset: ConfigPresetFormat) =>

0 commit comments

Comments
 (0)