Skip to content

Commit 7e26cfb

Browse files
committed
Refactor tool configuration and model provider management to support in-place editing, deletion, and positional insertion
1 parent f6b9411 commit 7e26cfb

23 files changed

Lines changed: 861 additions & 504 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ Pair-programming using natural language instructions.
8383
**🛠️ Intelligent Update** \
8484
Integrate changes from malformed markdown code blocks.
8585

86-
**🛠️ Code Completions** \
87-
Get accurate code at cursor from state-of-the-art models.
88-
8986
**🛠️ Prune Context** \
9087
Remove irrelevant files from the current context selection.
9188

89+
**🛠️ Code Completions** \
90+
Get accurate code at cursor from state-of-the-art models.
91+
9292
**🛠️ Commit Messages** \
9393
Meaningful summaries of changes adhering to your style.
9494

‎apps/editor/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "gemini-coder",
33
"displayName": "Code Web Chat",
4-
"description": "CWC is a blazing fast AI coding with chatbots/APIs",
4+
"description": "CWC lets you connect VS Code with chatbots",
55
"version": "1.770.0",
66
"scripts": {
77
"build": "npx vsce package --no-dependencies",

‎apps/editor/src/views/panel/backend/message-handlers/handle-create-preset-group-or-separator.ts‎

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,51 @@ export const handle_create_preset_group_or_separator = async (
134134
let insertion_index: number | undefined
135135

136136
if (message.reference_index !== undefined) {
137-
const position_quick_pick = await vscode.window.showQuickPick(
138-
['Insert Above', 'Insert Below'],
139-
{
140-
placeHolder: 'Where to insert?'
137+
const position_quick_pick = await new Promise<string | undefined>(
138+
(resolve) => {
139+
const quick_pick = vscode.window.createQuickPick()
140+
quick_pick.items = [
141+
{ label: 'Insert above' },
142+
{ label: 'Insert below' }
143+
]
144+
quick_pick.title = 'Placement'
145+
quick_pick.placeholder = 'Where to insert?'
146+
quick_pick.buttons = [
147+
{
148+
iconPath: new vscode.ThemeIcon('close'),
149+
tooltip: 'Close'
150+
}
151+
]
152+
153+
let accepted = false
154+
const disposables: vscode.Disposable[] = []
155+
156+
disposables.push(
157+
quick_pick.onDidTriggerButton(() => {
158+
quick_pick.hide()
159+
}),
160+
quick_pick.onDidAccept(() => {
161+
accepted = true
162+
resolve(quick_pick.selectedItems[0]?.label)
163+
quick_pick.hide()
164+
}),
165+
quick_pick.onDidHide(() => {
166+
if (!accepted) resolve(undefined)
167+
disposables.forEach((d) => d.dispose())
168+
quick_pick.dispose()
169+
})
170+
)
171+
172+
quick_pick.show()
141173
}
142174
)
143175
if (!position_quick_pick) return
144176

145177
insertion_index =
146-
position_quick_pick === 'Insert Above'
178+
position_quick_pick == 'Insert above'
147179
? message.reference_index
148180
: message.reference_index + 1
149-
} else if (message.placement === 'top') {
181+
} else if (message.placement == 'top') {
150182
insertion_index = 0
151183
}
152184

‎apps/editor/src/views/panel/backend/panel-provider.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ import { CancelTokenSource } from 'axios'
114114
import { update_last_used_preset_or_group } from './message-handlers/update-last-used-preset-or-group'
115115
import { dictionary } from '@shared/constants/dictionary'
116116
import { DEFAULT_CONTEXT_SIZE_WARNING_THRESHOLD } from '@/constants/values'
117+
import { upsert_configuration } from '../../utils/upsert-configuration'
118+
import { delete_configuration } from '../../utils/delete-configuration'
117119

118120
export class PanelProvider implements vscode.WebviewViewProvider {
119121
private _webview_view: vscode.WebviewView | undefined
@@ -769,6 +771,30 @@ export class PanelProvider implements vscode.WebviewViewProvider {
769771
message.command == 'SAVE_PRUNE_CONTEXT_INSTRUCTIONS_PREFIX'
770772
) {
771773
await handle_save_prune_context_instructions_prefix(message.prefix)
774+
} else if (message.command == 'UPSERT_CONFIGURATION') {
775+
const tool_type_map: Record<string, string> = {
776+
'edit-context': 'edit-context',
777+
'code-at-cursor': 'code-completions',
778+
'prune-context': 'prune-context'
779+
}
780+
await upsert_configuration({
781+
context: this.context,
782+
tool_type: tool_type_map[message.tool_type] || message.tool_type,
783+
configuration_id: message.configuration_id,
784+
create_on_top: message.create_on_top,
785+
insertion_index: message.insertion_index
786+
})
787+
} else if (message.command == 'DELETE_CONFIGURATION') {
788+
const tool_type_map: Record<string, any> = {
789+
'edit-context': 'edit-context',
790+
'code-at-cursor': 'code-completions',
791+
'prune-context': 'prune-context'
792+
}
793+
await delete_configuration(
794+
this.context,
795+
message.configuration_id,
796+
tool_type_map[message.api_prompt_type] || message.api_prompt_type
797+
)
772798
} else if (message.command == 'OPEN_EXTERNAL_URL') {
773799
await handle_open_external_url(message)
774800
}

‎apps/editor/src/views/panel/frontend/Main/Main.tsx‎

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,14 @@ export const Main: React.FC<Props> = (props) => {
398398
})
399399
}
400400

401-
const handle_manage_configurations = () => {
401+
const handle_create_configuration = (params?: {
402+
create_on_top?: boolean
403+
insertion_index?: number
404+
}) => {
402405
post_message(props.vscode, {
403-
command: 'MANAGE_CONFIGURATIONS',
404-
api_prompt_type: props.api_prompt_type
406+
command: 'UPSERT_CONFIGURATION',
407+
tool_type: props.api_prompt_type,
408+
...params
405409
})
406410
}
407411

@@ -435,6 +439,24 @@ export const Main: React.FC<Props> = (props) => {
435439
}
436440
}
437441

442+
const handle_edit_configuration = (id: string) => {
443+
if (props.api_prompt_type) {
444+
post_message(props.vscode, {
445+
command: 'UPSERT_CONFIGURATION',
446+
tool_type: props.api_prompt_type,
447+
configuration_id: id
448+
})
449+
}
450+
}
451+
452+
const handle_delete_configuration = (id: string) => {
453+
post_message(props.vscode, {
454+
command: 'DELETE_CONFIGURATION',
455+
api_prompt_type: props.api_prompt_type,
456+
configuration_id: id
457+
})
458+
}
459+
438460
const handle_toggle_pinned_configuration = (id: string) => {
439461
if (props.api_prompt_type) {
440462
post_message(props.vscode, {
@@ -738,7 +760,9 @@ export const Main: React.FC<Props> = (props) => {
738760
on_configuration_click={handle_configuration_click}
739761
on_configurations_reorder={handle_configurations_reorder}
740762
on_toggle_pinned_configuration={handle_toggle_pinned_configuration}
741-
on_manage_configurations={handle_manage_configurations}
763+
on_edit_configuration={handle_edit_configuration}
764+
on_delete_configuration={handle_delete_configuration}
765+
on_create_configuration={handle_create_configuration}
742766
on_search_click={handle_search_click}
743767
on_at_sign_click={handle_at_sign_click}
744768
on_hash_sign_click={handle_hash_sign_click}

‎apps/editor/src/views/panel/frontend/Main/MainView/MainView.tsx‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ type Props = {
4545
reordered_configurations: UiConfigurations.Configuration[]
4646
) => void
4747
on_toggle_pinned_configuration: (id: string) => void
48-
on_manage_configurations: () => void
48+
on_edit_configuration: (id: string) => void
49+
on_delete_configuration: (id: string) => void
50+
on_create_configuration: (params?: {
51+
create_on_top?: boolean
52+
insertion_index?: number
53+
}) => void
4954
currently_open_file_path?: string
5055
current_selection?: SelectionState | null
5156
chat_history: string[]
@@ -322,8 +327,10 @@ export const MainView: React.FC<Props> = (props) => {
322327
on_configuration_click={props.on_configuration_click}
323328
on_reorder={props.on_configurations_reorder}
324329
on_toggle_pinned={props.on_toggle_pinned_configuration}
330+
on_edit={props.on_edit_configuration}
331+
on_delete={props.on_delete_configuration}
325332
selected_configuration_id={props.selected_configuration_id}
326-
on_manage_configurations={props.on_manage_configurations}
333+
on_create={props.on_create_configuration}
327334
is_collapsed={props.configurations_collapsed}
328335
on_toggle_collapsed={props.on_configurations_collapsed_change}
329336
/>

‎apps/editor/src/views/panel/types/messages.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,20 @@ export interface OpenExternalUrlMessage extends BaseMessage {
493493
url: string
494494
}
495495

496+
export interface UpsertConfigurationMessage extends BaseMessage {
497+
command: 'UPSERT_CONFIGURATION'
498+
tool_type: string
499+
configuration_id?: string
500+
create_on_top?: boolean
501+
insertion_index?: number
502+
}
503+
504+
export interface DeleteConfigurationMessage extends BaseMessage {
505+
command: 'DELETE_CONFIGURATION'
506+
api_prompt_type: ApiPromptType
507+
configuration_id: string
508+
}
509+
496510
export type FrontendMessage =
497511
| GetInstructionsMessage
498512
| SaveInstructionsMessage
@@ -580,6 +594,8 @@ export type FrontendMessage =
580594
| GetPruneContextInstructionsPrefixMessage
581595
| SavePruneContextInstructionsPrefixMessage
582596
| OpenExternalUrlMessage
597+
| UpsertConfigurationMessage
598+
| DeleteConfigurationMessage
583599

584600
// === FROM BACKEND TO FRONTEND ===
585601
export interface InstructionsMessage extends BaseMessage {
Lines changed: 2 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
import * as vscode from 'vscode'
21
import { SettingsProvider } from '@/views/settings/backend/settings-provider'
3-
import {
4-
ModelProvidersManager,
5-
get_tool_config_id,
6-
ToolConfig
7-
} from '@/services/model-providers-manager'
8-
import { dictionary } from '@shared/constants/dictionary'
2+
import { delete_configuration } from '../../../utils/delete-configuration'
93

104
export const handle_delete_configuration = async (
115
provider: SettingsProvider,
@@ -17,92 +11,5 @@ export const handle_delete_configuration = async (
1711
| 'commit-messages'
1812
| 'prune-context'
1913
): Promise<void> => {
20-
const providers_manager = new ModelProvidersManager(provider.context)
21-
22-
let get_configs: () => Promise<ToolConfig[]>
23-
let save_configs: (configs: ToolConfig[]) => Promise<void>
24-
let get_default_config: (() => Promise<ToolConfig | undefined>) | undefined
25-
let set_default_config:
26-
| ((config: ToolConfig | null) => Promise<void>)
27-
| undefined
28-
29-
switch (type) {
30-
case 'code-completions':
31-
get_configs = () => providers_manager.get_code_completions_tool_configs()
32-
save_configs = (c) =>
33-
providers_manager.save_code_completions_tool_configs(c)
34-
get_default_config = () =>
35-
providers_manager.get_default_code_completions_config()
36-
set_default_config = (c) =>
37-
providers_manager.set_default_code_completions_config(c)
38-
break
39-
case 'edit-context':
40-
get_configs = () => providers_manager.get_edit_context_tool_configs()
41-
save_configs = (c) => providers_manager.save_edit_context_tool_configs(c)
42-
break
43-
case 'intelligent-update':
44-
get_configs = () =>
45-
providers_manager.get_intelligent_update_tool_configs()
46-
save_configs = (c) =>
47-
providers_manager.save_intelligent_update_tool_configs(c)
48-
get_default_config = () =>
49-
providers_manager.get_default_intelligent_update_config()
50-
set_default_config = (c) =>
51-
providers_manager.set_default_intelligent_update_config(c)
52-
break
53-
case 'commit-messages':
54-
get_configs = () => providers_manager.get_commit_messages_tool_configs()
55-
save_configs = (c) =>
56-
providers_manager.save_commit_messages_tool_configs(c)
57-
get_default_config = () =>
58-
providers_manager.get_default_commit_messages_config()
59-
set_default_config = (c) =>
60-
providers_manager.set_default_commit_messages_config(c)
61-
break
62-
case 'prune-context':
63-
get_configs = () => providers_manager.get_prune_context_tool_configs()
64-
save_configs = (c) => providers_manager.save_prune_context_tool_configs(c)
65-
get_default_config = () =>
66-
providers_manager.get_default_prune_context_config()
67-
set_default_config = (c) =>
68-
providers_manager.set_default_prune_context_config(c)
69-
break
70-
}
71-
72-
const original_configs = await get_configs()
73-
const config_to_delete = original_configs.find(
74-
(c) => get_tool_config_id(c) === configuration_id
75-
)
76-
if (!config_to_delete) return
77-
78-
const confirmation = await vscode.window.showWarningMessage(
79-
dictionary.warning_message.PLEASE_CONFIRM,
80-
{
81-
modal: true,
82-
detail: dictionary.warning_message.CONFIRM_DELETE_CONFIGURATION(
83-
config_to_delete.model,
84-
config_to_delete.provider_name
85-
)
86-
},
87-
'Delete'
88-
)
89-
90-
if (confirmation != 'Delete') {
91-
return
92-
}
93-
94-
const updated_configs = original_configs.filter(
95-
(c) => get_tool_config_id(c) !== configuration_id
96-
)
97-
await save_configs(updated_configs)
98-
99-
if (get_default_config && set_default_config) {
100-
const original_default_config = await get_default_config()
101-
if (
102-
original_default_config &&
103-
get_tool_config_id(original_default_config) === configuration_id
104-
) {
105-
await set_default_config(null)
106-
}
107-
}
14+
await delete_configuration(provider.context, configuration_id, type)
10815
}

0 commit comments

Comments
 (0)