Skip to content

Commit dfef234

Browse files
committed
Convert target constant to a string literal tuple and update references to use string literals
- simplify to ['WEB', 'API', 'CLI'] as const` ├── apps │ └── editor │ └── src │ └── views │ └── prompt │ ├── backend │ │ ├── message-handlers │ │ │ ├── handle-copy-prompt.ts │ │ │ ├── handle-preview-prompt.ts │ │ │ └── handle-template-quick-pick.ts │ │ └── prompt-view-provider.ts │ ├── frontend │ │ ├── Home │ │ │ └── Home.tsx │ │ ├── Main │ │ │ ├── Main.tsx │ │ │ └── MainView │ │ │ ├── MainView.tsx │ │ │ ├── components │ │ │ │ └── Header │ │ │ │ └── Header.tsx │ │ │ └── hooks │ │ │ ├── use-invocation-counts.ts │ │ │ ├── use-keyboard-shortcuts.ts │ │ │ └── use-last-choice-tooltip.ts │ │ ├── Prompt.tsx │ │ └── hooks │ │ └── use-prompt │ │ ├── hooks │ │ │ └── use-instructions.ts │ │ └── use-prompt.ts │ └── types │ └── messages.ts └── packages ├── shared │ └── src │ └── types │ └── target.ts └── ui └── src └── components └── editor └── common └── prompts └── PromptField ├── PromptField.stories.tsx ├── PromptField.tsx └── hooks └── use-keyboard-shortcuts.ts
1 parent 510f0ec commit dfef234

17 files changed

Lines changed: 108 additions & 129 deletions

File tree

‎apps/editor/src/views/prompt/backend/message-handlers/handle-copy-prompt.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { PromptViewProvider } from '@/views/prompt/backend/prompt-view-provider'
22
import * as vscode from 'vscode'
33
import { build_prompt_payload } from './utils/build-prompt-payload'
44
import { build_cli_prompt } from './utils/build-cli-prompt'
5-
import { TARGET } from '@shared/types/target'
65
import {
76
EDIT_FORMAT_INSTRUCTIONS_WHOLE,
87
EDIT_FORMAT_INSTRUCTIONS_TRUNCATED,
@@ -17,7 +16,7 @@ export const handle_copy_prompt = async (params: {
1716
}): Promise<void> => {
1817
let text = ''
1918

20-
if (params.prompt_view_provider.target === TARGET.CLI) {
19+
if (params.prompt_view_provider.target === 'CLI') {
2120
text = await build_cli_prompt({
2221
prompt_view_provider: params.prompt_view_provider
2322
})

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { PromptViewProvider } from '@/views/prompt/backend/prompt-view-provider'
22
import { build_prompt_payload } from './utils/build-prompt-payload'
33
import { build_cli_prompt } from './utils/build-cli-prompt'
4-
import { TARGET } from '@shared/types/target'
54
import {
65
EDIT_FORMAT_INSTRUCTIONS_WHOLE,
76
EDIT_FORMAT_INSTRUCTIONS_TRUNCATED,
@@ -28,7 +27,7 @@ export const handle_preview_prompt = async (params: {
2827

2928
let text = ''
3029

31-
if (params.prompt_view_provider.target == TARGET.CLI) {
30+
if (params.prompt_view_provider.target == 'CLI') {
3231
text = await build_cli_prompt({
3332
prompt_view_provider: params.prompt_view_provider
3433
})

‎apps/editor/src/views/prompt/backend/message-handlers/handle-template-quick-pick.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as vscode from 'vscode'
22
import { PromptViewProvider } from '@/views/prompt/backend/prompt-view-provider'
3-
import { TARGET } from '@shared/types/target'
43
import { get_last_used_template_key } from '@/constants/state-keys'
54
import { ApiPromptType, WebPromptType } from '@shared/types/prompt-types'
65
import { t } from '@/i18n'
@@ -15,7 +14,7 @@ export const handle_template_quick_pick = async (
1514
prompt_view_provider: PromptViewProvider
1615
): Promise<void> => {
1716
const prompt_type: WebPromptType | ApiPromptType | undefined =
18-
prompt_view_provider.target == TARGET.WEB
17+
prompt_view_provider.target == 'WEB'
1918
? prompt_view_provider.web_prompt_type
2019
: prompt_view_provider.api_prompt_type
2120

‎apps/editor/src/views/prompt/backend/prompt-view-provider.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ import {
110110
ConfigWebConfigurationFormat
111111
} from '@/utils/web-configuration-format-converters'
112112
import { CHATBOTS } from '@shared/constants/chatbots'
113-
import { TARGET, Target } from '@shared/types/target'
113+
import { Target } from '@shared/types/target'
114114
import {
115115
ApiPromptType,
116116
WebPromptType,
@@ -152,7 +152,7 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
152152
public edit_format: EditFormat
153153
public api_prompt_type: ApiPromptType
154154
public cli_prompt_type: CliPromptType
155-
public target: Target = TARGET.WEB
155+
public target: Target = 'WEB'
156156
public patch_repair_abort_controllers: {
157157
controller: AbortController
158158
file_path: string
@@ -188,9 +188,9 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
188188
}
189189

190190
public get prompt_type(): WebPromptType | ApiPromptType | CliPromptType {
191-
return this.target == TARGET.WEB
191+
return this.target == 'WEB'
192192
? this.web_prompt_type
193-
: this.target == TARGET.API
193+
: this.target == 'API'
194194
? this.api_prompt_type
195195
: this.cli_prompt_type
196196
}
@@ -317,7 +317,7 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
317317
this.extension_context.globalState.get<Target>(
318318
PROMPT_VIEW_TARGET_STATE_KEY
319319
) ??
320-
TARGET.WEB
320+
'WEB'
321321

322322
this.web_prompt_type =
323323
this.extension_context.workspaceState.get<WebPromptType>(

‎apps/editor/src/views/prompt/frontend/Home/Home.tsx‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { Tasks as UiTasks } from '@ui/components/editor/prompt/Tasks'
1313
import { use_tasks } from './hooks/use-tasks'
1414
import { use_has_scrolled_past_target_button } from './hooks/use-has-scrolled-past-mode-button'
1515
import { use_compacting } from '@shared/hooks'
16-
import { TARGET } from '@shared/types/target'
1716
import {
1817
ApiPromptType,
1918
WebPromptType,
@@ -187,7 +186,7 @@ export const Home: React.FC<Props> = (props) => {
187186
})}
188187
>
189188
<UiTargetButton
190-
label={TARGET.WEB}
189+
label="WEB"
191190
on_click={props.on_chatbots_click}
192191
is_compact
193192
hover_color={
@@ -196,7 +195,7 @@ export const Home: React.FC<Props> = (props) => {
196195
keycap_char={is_alt_pressed ? 'W' : undefined}
197196
/>
198197
<UiTargetButton
199-
label={TARGET.API}
198+
label="API"
200199
on_click={props.on_api_calls_click}
201200
is_compact
202201
hover_color={
@@ -205,7 +204,7 @@ export const Home: React.FC<Props> = (props) => {
205204
keycap_char={is_alt_pressed ? 'A' : undefined}
206205
/>
207206
<UiTargetButton
208-
label={TARGET.CLI}
207+
label="CLI"
209208
on_click={props.on_cli_calls_click}
210209
is_compact
211210
hover_color={
@@ -220,7 +219,7 @@ export const Home: React.FC<Props> = (props) => {
220219
const targets_section = (
221220
<div className={styles.inner__target} ref={target_ref}>
222221
<UiTargetButton
223-
label={TARGET.WEB}
222+
label="WEB"
224223
description={
225224
props.is_connected
226225
? t('home.target.web.description-connected')
@@ -231,14 +230,14 @@ export const Home: React.FC<Props> = (props) => {
231230
keycap_char={is_alt_pressed ? 'W' : undefined}
232231
/>
233232
<UiTargetButton
234-
label={TARGET.API}
233+
label="API"
235234
description={t('home.target.api.description')}
236235
on_click={props.on_api_calls_click}
237236
hover_color={props.api_prompt_type == 'edit-files' ? 'blue' : 'purple'}
238237
keycap_char={is_alt_pressed ? 'A' : undefined}
239238
/>
240239
<UiTargetButton
241-
label={TARGET.CLI}
240+
label="CLI"
242241
description={t('home.target.cli.description')}
243242
on_click={props.on_cli_calls_click}
244243
hover_color={props.cli_prompt_type == 'edit-files' ? 'blue' : 'purple'}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react'
22
import { MainView } from './MainView'
33
import { WebConfiguration } from '@shared/types/web-configuration'
44
import { EditFormat } from '@shared/types/edit-format'
5-
import { TARGET, Target } from '@shared/types/target'
5+
import { Target } from '@shared/types/target'
66
import {
77
ApiPromptType,
88
WebPromptType,
@@ -171,9 +171,9 @@ export const Main: React.FC<Props> = (props) => {
171171
}, [])
172172

173173
const current_prompt_type =
174-
props.target == TARGET.WEB
174+
props.target == 'WEB'
175175
? props.web_prompt_type
176-
: props.target == TARGET.API
176+
: props.target == 'API'
177177
? props.api_prompt_type
178178
: props.cli_prompt_type
179179

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

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Responses as UiResponses } from '@ui/components/editor/prompt/Responses
99
import { StatusBar as UiStatusBar } from '@ui/components/editor/prompt/StatusBar'
1010
import { ResponseHistoryItem } from '@shared/types/response-history-item'
1111
import { EditFormat } from '@shared/types/edit-format'
12-
import { TARGET, Target } from '@shared/types/target'
12+
import { Target } from '@shared/types/target'
1313
import {
1414
ApiPromptType,
1515
WebPromptType,
@@ -165,9 +165,9 @@ export const MainView: React.FC<Props> = (props) => {
165165
const [is_content_scrollable, set_is_content_scrollable] = useState(false)
166166

167167
const show_edit_format_selector =
168-
(props.target == TARGET.WEB && props.web_prompt_type == 'edit-files') ||
169-
(props.target == TARGET.API && props.api_prompt_type == 'edit-files') ||
170-
(props.target == TARGET.CLI && props.cli_prompt_type == 'edit-files')
168+
(props.target == 'WEB' && props.web_prompt_type == 'edit-files') ||
169+
(props.target == 'API' && props.api_prompt_type == 'edit-files') ||
170+
(props.target == 'CLI' && props.cli_prompt_type == 'edit-files')
171171

172172
const is_context_empty =
173173
show_edit_format_selector && props.selected_files.length == 0
@@ -177,23 +177,23 @@ export const MainView: React.FC<Props> = (props) => {
177177
}
178178

179179
const handle_submit = async () => {
180-
if (props.target == TARGET.WEB) {
180+
if (props.target == 'WEB') {
181181
props.initialize_chats({})
182-
} else if (props.target == TARGET.API) {
182+
} else if (props.target == 'API') {
183183
props.on_make_api_call(false)
184-
} else if (props.target == TARGET.CLI) {
184+
} else if (props.target == 'CLI') {
185185
props.on_invoke_headless_cli()
186186
}
187187
}
188188

189189
const handle_submit_with_control = async () => {
190-
if (props.target == TARGET.WEB) {
190+
if (props.target == 'WEB') {
191191
props.initialize_chats({
192192
show_quick_pick: true
193193
})
194-
} else if (props.target == TARGET.API) {
194+
} else if (props.target == 'API') {
195195
props.on_make_api_call(true)
196-
} else if (props.target == TARGET.CLI) {
196+
} else if (props.target == 'CLI') {
197197
props.on_invoke_headless_cli()
198198
}
199199
}
@@ -276,7 +276,7 @@ export const MainView: React.FC<Props> = (props) => {
276276
})
277277

278278
const is_api_warning_visible =
279-
props.target == TARGET.API &&
279+
props.target == 'API' &&
280280
!!props.setup_progress &&
281281
(!props.setup_progress.has_provider || props.api_configurations.length == 0)
282282

@@ -304,11 +304,11 @@ export const MainView: React.FC<Props> = (props) => {
304304
token_count={props.selected_files_token_count}
305305
files_count={props.selected_files.length}
306306
theme={
307-
props.target == TARGET.WEB
307+
props.target == 'WEB'
308308
? props.web_prompt_type == 'edit-files'
309309
? 'blue'
310310
: 'purple'
311-
: props.target == TARGET.API
311+
: props.target == 'API'
312312
? props.api_prompt_type == 'edit-files'
313313
? 'blue'
314314
: 'purple'
@@ -331,7 +331,7 @@ export const MainView: React.FC<Props> = (props) => {
331331
<UiSpacer height={is_landscape ? 6 : 2} />
332332

333333
<BrowserConnectionStatus
334-
is_visible={props.target == TARGET.WEB}
334+
is_visible={props.target == 'WEB'}
335335
is_connected={props.is_connected}
336336
is_closed={browser_connection.is_closed}
337337
on_close={browser_connection.handle_close}
@@ -367,9 +367,9 @@ export const MainView: React.FC<Props> = (props) => {
367367
)}
368368

369369
{props.response_history.length > 0 &&
370-
(props.target == TARGET.WEB
370+
(props.target == 'WEB'
371371
? props.web_prompt_type
372-
: props.target == TARGET.API
372+
: props.target == 'API'
373373
? props.api_prompt_type
374374
: props.cli_prompt_type) == 'edit-files' && (
375375
<UiResponses
@@ -396,7 +396,7 @@ export const MainView: React.FC<Props> = (props) => {
396396
<div className={styles.prompt}>
397397
<UiPromptField
398398
is_copy_only={
399-
props.target == TARGET.WEB &&
399+
props.target == 'WEB' &&
400400
(!props.is_connected || !props.web_configurations.length)
401401
}
402402
is_action_disabled={is_context_empty}
@@ -409,17 +409,17 @@ export const MainView: React.FC<Props> = (props) => {
409409
on_at_sign_click={props.on_at_sign_click}
410410
on_hash_sign_click={props.on_hash_sign_click}
411411
on_slash_click={props.on_slash_click}
412-
is_web_target={props.target == TARGET.WEB}
412+
is_web_target={props.target == 'WEB'}
413413
is_connected={props.is_connected}
414414
current_selection={props.current_selection}
415415
send_with_shift_enter={props.send_with_shift_enter}
416416
currently_open_file_text={props.currently_open_file_text}
417417
on_caret_position_change={props.on_caret_position_change}
418418
caret_position_to_set={props.caret_position_to_set}
419419
prompt_token_count={
420-
(props.target == TARGET.WEB
420+
(props.target == 'WEB'
421421
? props.web_prompt_type
422-
: props.target == TARGET.API
422+
: props.target == 'API'
423423
? props.api_prompt_type
424424
: props.cli_prompt_type) == 'edit-files'
425425
? props.edit_instructions_token_count
@@ -442,11 +442,11 @@ export const MainView: React.FC<Props> = (props) => {
442442
active_border_color={
443443
is_context_empty
444444
? 'yellow'
445-
: props.target == TARGET.WEB
445+
: props.target == 'WEB'
446446
? props.web_prompt_type == 'edit-files'
447447
? 'blue'
448448
: 'purple'
449-
: props.target == TARGET.API
449+
: props.target == 'API'
450450
? props.api_prompt_type == 'edit-files'
451451
? 'blue'
452452
: 'purple'
@@ -531,7 +531,7 @@ export const MainView: React.FC<Props> = (props) => {
531531

532532
const configurations_placeholder_above = (
533533
<>
534-
{props.target == TARGET.WEB && (
534+
{props.target == 'WEB' && (
535535
<>
536536
{!browser_connection.is_closed && (
537537
<>
@@ -566,7 +566,7 @@ export const MainView: React.FC<Props> = (props) => {
566566
)}
567567
</>
568568
)}
569-
{props.target == TARGET.API && (
569+
{props.target == 'API' && (
570570
<>
571571
{is_api_warning_visible && (
572572
<>
@@ -601,7 +601,7 @@ export const MainView: React.FC<Props> = (props) => {
601601
)}
602602
</>
603603
)}
604-
{props.target == TARGET.CLI && (
604+
{props.target == 'CLI' && (
605605
<>
606606
{props.response_history.length > 0 &&
607607
props.cli_prompt_type === 'edit-files' && (
@@ -623,7 +623,7 @@ export const MainView: React.FC<Props> = (props) => {
623623

624624
const configurations_placeholder_below = (
625625
<>
626-
{props.target == TARGET.WEB && !browser_connection.is_closed && (
626+
{props.target == 'WEB' && !browser_connection.is_closed && (
627627
<div style={{ visibility: 'hidden', pointerEvents: 'none' }}>
628628
{prompt_attachments}
629629
</div>
@@ -633,7 +633,7 @@ export const MainView: React.FC<Props> = (props) => {
633633

634634
const configurations_section = (
635635
<>
636-
{props.target == TARGET.WEB && (
636+
{props.target == 'WEB' && (
637637
<UiConfigurations
638638
configurations={web_configurations}
639639
empty_landscape_placeholder_above={configurations_placeholder_above}
@@ -674,7 +674,7 @@ export const MainView: React.FC<Props> = (props) => {
674674
/>
675675
)}
676676

677-
{props.target == TARGET.API && (
677+
{props.target == 'API' && (
678678
<UiConfigurations
679679
configurations={api_configurations_ui}
680680
on_configuration_click={props.on_api_configuration_click}
@@ -700,7 +700,7 @@ export const MainView: React.FC<Props> = (props) => {
700700
/>
701701
)}
702702

703-
{props.target == TARGET.CLI && <></>}
703+
{props.target == 'CLI' && <></>}
704704
</>
705705
)
706706

0 commit comments

Comments
 (0)