Skip to content

Commit 3d7d462

Browse files
committed
Make web configuration name and chatbot fields required
- on chatbot, make 'name' and 'chatbot' required properties and skip redundant checks and Non-Null Assertion Operator ├── apps │ ├── browser │ │ └── src │ │ ├── background │ │ │ └── message-handler.ts │ │ └── content-scripts │ │ └── send-prompt-content-script │ │ ├── chatbots │ │ │ ├── ai-studio.ts │ │ │ ├── open-webui.ts │ │ │ └── openrouter.ts │ │ ├── send-prompt-content-script.ts │ │ └── types │ │ └── chatbot.ts │ └── editor │ ├── package.json │ └── src │ ├── commands │ │ └── code-at-cursor-command │ │ └── utils │ │ └── perform-code-at-cursor.ts │ ├── extension.ts │ ├── migrations │ │ └── migrate-edit-context-to-edit-files-system-instructions.ts │ ├── services │ │ └── websocket-manager.ts │ ├── types │ │ └── web-configuration.ts │ ├── utils │ │ ├── changes-integration │ │ │ └── diff-processor │ │ │ └── test-cases │ │ │ └── generic-6 │ │ │ ├── diff.txt │ │ │ ├── expected.txt │ │ │ └── original.txt │ │ ├── prompt-builder.ts │ │ └── web-configuration-format-converters.ts │ └── views │ ├── prompt │ │ ├── backend │ │ │ └── message-handlers │ │ │ ├── handle-autofill.ts │ │ │ ├── handle-copy-prompt.ts │ │ │ ├── handle-make-api-call.ts │ │ │ ├── handle-preview-prompt.ts │ │ │ └── handle-preview-web-configuration.ts │ │ └── frontend │ │ └── Main │ │ └── Main.tsx │ ├── settings │ │ ├── backend │ │ │ ├── message-handlers │ │ │ │ ├── handle-get-edit-files-system-instructions.ts │ │ │ │ └── handle-update-edit-files-system-instructions.ts │ │ │ └── settings-view-provider.ts │ │ ├── frontend │ │ │ ├── Home │ │ │ │ └── Home.tsx │ │ │ ├── Settings.tsx │ │ │ └── hooks │ │ │ └── use-settings.ts │ │ └── types │ │ └── messages.ts │ └── shared │ ├── actions │ │ └── web │ │ ├── create.ts │ │ └── update.ts │ └── forms │ └── EditWebConfigurationForm │ └── EditWebConfigurationForm.tsx └── packages └── shared └── src ├── constants │ └── chatbots.ts └── types └── websocket-message.ts
1 parent c25c81e commit 3d7d462

6 files changed

Lines changed: 84 additions & 94 deletions

File tree

‎apps/editor/src/services/websocket-manager.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ export class WebSocketManager {
438438
url = chatbot.url
439439
vscode.window.showWarningMessage(
440440
t('service.websocket-manager.url-override-different-domain', {
441-
preset_name: web_configuration.name!
441+
preset_name: web_configuration.name
442442
})
443443
)
444444
}
@@ -544,7 +544,7 @@ export class WebSocketManager {
544544
url = chatbot.url
545545
vscode.window.showWarningMessage(
546546
t('service.websocket-manager.url-override-different-domain', {
547-
preset_name: params.web_configuration.name!
547+
preset_name: params.web_configuration.name
548548
})
549549
)
550550
}

‎apps/editor/src/types/web-configuration.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { CHATBOTS } from "@shared/constants/chatbots"
22

33
export type WebConfiguration = {
4-
name?: string
5-
chatbot?: keyof typeof CHATBOTS
4+
name: string
5+
chatbot: keyof typeof CHATBOTS
66
model?: string
77
reasoning_effort?: string
88
system_instructions?: string

‎apps/editor/src/utils/web-configuration-format-converters.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { CHATBOTS } from '@shared/constants/chatbots'
22
import { WebConfiguration } from '@/types/web-configuration'
33

44
export type ConfigWebConfigurationFormat = {
5-
name?: string
6-
chatbot?: keyof typeof CHATBOTS
5+
name: string
6+
chatbot: keyof typeof CHATBOTS
77
model?: string
88
reasoningEffort?: string
99
systemInstructions?: string
@@ -18,7 +18,7 @@ export const config_web_configuration_to_ui_format = (
1818
): WebConfiguration => {
1919
return {
2020
name: config_web_configuration.name,
21-
chatbot: config_web_configuration.chatbot,
21+
chatbot: config_web_configuration.chatbot as keyof typeof CHATBOTS,
2222
model: config_web_configuration.model,
2323
reasoning_effort: config_web_configuration.reasoningEffort,
2424
system_instructions: config_web_configuration.systemInstructions,
@@ -33,7 +33,7 @@ export const ui_web_configuration_to_config_format = (
3333
web_configuration: WebConfiguration
3434
): ConfigWebConfigurationFormat => {
3535
return {
36-
name: web_configuration.name || undefined,
36+
name: web_configuration.name,
3737
chatbot: web_configuration.chatbot,
3838
model: web_configuration.model,
3939
reasoningEffort: web_configuration.reasoning_effort,

‎apps/editor/src/views/settings/frontend/Settings.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export const Settings = () => {
258258
on_add_web_configuration={settings_hook.handle_add_web_configuration}
259259
on_edit_web_configuration={(id) => {
260260
const config = settings_hook.web_configurations?.find(
261-
(c, index) => (c.name ?? `unnamed-${index}`) === id
261+
(c) => c.name == id
262262
)
263263
if (config) {
264264
set_updating_web_configuration(config)

‎apps/editor/src/views/shared/actions/web/update.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const update = async (params: {
3535
vscode.window.showErrorMessage(
3636
t('common.error.could-not-update-item-not-found', {
3737
item_type: 'chatbot',
38-
name: params.updating_web_configuration.name!
38+
name: params.updating_web_configuration.name
3939
})
4040
)
4141
return { success: false, has_changes: false }

‎apps/editor/src/views/shared/forms/EditWebConfigurationForm/EditWebConfigurationForm.tsx‎

Lines changed: 74 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ export const EditWebConfigurationForm: React.FC<Props> = (props) => {
4141
props.web_configuration.options || []
4242
)
4343

44-
const chatbot_config = chatbot ? CHATBOTS[chatbot] : undefined
45-
const models = useMemo(() => chatbot_config?.models || {}, [chatbot_config])
44+
const chatbot_config = CHATBOTS[chatbot]
45+
const models = useMemo(() => chatbot_config.models || {}, [chatbot_config])
4646
const model_info = useMemo(
4747
() =>
48-
model && chatbot_config?.models
48+
model && chatbot_config.models
4949
? chatbot_config.models[model]
5050
: undefined,
5151
[model, chatbot_config]
@@ -59,7 +59,6 @@ export const EditWebConfigurationForm: React.FC<Props> = (props) => {
5959
}, [model_info])
6060

6161
useEffect(() => {
62-
if (!chatbot) return
6362
const chatbot_config = CHATBOTS[chatbot]
6463

6564
if (new_url && chatbot_config.url_override_disabled_options) {
@@ -72,33 +71,27 @@ export const EditWebConfigurationForm: React.FC<Props> = (props) => {
7271
}, [chatbot, new_url])
7372

7473
const supports_reasoning_effort =
75-
chatbot_config?.supports_reasoning_effort ||
74+
chatbot_config.supports_reasoning_effort ||
7675
!!model_info?.supported_reasoning_efforts
7776
const supports_system_instructions =
78-
chatbot_config?.supports_system_instructions
79-
const supports_port = chatbot_config?.supports_user_provided_port
80-
const supports_url_override = chatbot_config?.supports_url_override
77+
chatbot_config.supports_system_instructions
78+
const supports_port = chatbot_config.supports_user_provided_port
79+
const supports_url_override = chatbot_config.supports_url_override
8180
const supports_user_provided_model =
82-
chatbot_config?.supports_user_provided_model
81+
chatbot_config.supports_user_provided_model
8382

8483
useEffect(() => {
85-
if (chatbot) {
86-
props.on_update({
87-
name,
88-
chatbot,
89-
...(reasoning_effort ? { reasoning_effort } : {}),
90-
...(model ? { model } : {}),
91-
...(system_instructions ? { system_instructions } : {}),
92-
...(port !== undefined ? { port } : {}),
93-
...(new_url ? { new_url } : {}),
94-
...(options.length ? { options } : {}),
95-
is_pinned: props.web_configuration.is_pinned
96-
})
97-
} else {
98-
props.on_update({
99-
name
100-
})
101-
}
84+
props.on_update({
85+
name,
86+
chatbot,
87+
...(reasoning_effort ? { reasoning_effort } : {}),
88+
...(model ? { model } : {}),
89+
...(system_instructions ? { system_instructions } : {}),
90+
...(port !== undefined ? { port } : {}),
91+
...(new_url ? { new_url } : {}),
92+
...(options.length ? { options } : {}),
93+
is_pinned: props.web_configuration.is_pinned
94+
})
10295
}, [
10396
name,
10497
reasoning_effort,
@@ -149,7 +142,7 @@ export const EditWebConfigurationForm: React.FC<Props> = (props) => {
149142

150143
const supported_reasoning_efforts = useMemo(() => {
151144
return (
152-
chatbot_config?.supported_reasoning_efforts ||
145+
chatbot_config.supported_reasoning_efforts ||
153146
model_info?.supported_reasoning_efforts ||
154147
[]
155148
)
@@ -167,20 +160,18 @@ export const EditWebConfigurationForm: React.FC<Props> = (props) => {
167160
<UiScrollable top_shadow>
168161
<div className={styles.form}>
169162
<UiFieldset>
170-
{chatbot && (
171-
<UiField
172-
label={t('edit-web-configuration-form.chatbot')}
173-
html_for="chatbot"
174-
>
175-
<UiQuickPickButton
176-
label={chatbot}
177-
onClick={(e) => {
178-
e.stopPropagation()
179-
props.pick_chatbot(chatbot)
180-
}}
181-
/>
182-
</UiField>
183-
)}
163+
<UiField
164+
label={t('edit-web-configuration-form.chatbot')}
165+
html_for="chatbot"
166+
>
167+
<UiQuickPickButton
168+
label={chatbot}
169+
onClick={(e) => {
170+
e.stopPropagation()
171+
props.pick_chatbot(chatbot)
172+
}}
173+
/>
174+
</UiField>
184175

185176
{(Object.keys(models).length > 0 || chatbot == 'OpenRouter') && (
186177
<UiField
@@ -272,7 +263,7 @@ export const EditWebConfigurationForm: React.FC<Props> = (props) => {
272263
<UiInput
273264
id="name"
274265
type="text"
275-
value={name && /^\(\d+\)$/.test(name) ? '' : name!}
266+
value={name && /^\(\d+\)$/.test(name) ? '' : name}
276267
on_change={set_name}
277268
placeholder={
278269
chatbot ||
@@ -312,7 +303,7 @@ export const EditWebConfigurationForm: React.FC<Props> = (props) => {
312303
{supports_url_override && (
313304
<UiField
314305
label={
315-
chatbot_config?.url_override_label ||
306+
chatbot_config.url_override_label ||
316307
t('edit-web-configuration-form.url-override')
317308
}
318309
html_for="new-url"
@@ -346,49 +337,48 @@ export const EditWebConfigurationForm: React.FC<Props> = (props) => {
346337
)}
347338
</UiFieldset>
348339

349-
{chatbot &&
350-
Object.keys(chatbot_config?.supported_options || {}).length > 0 && (
351-
<UiFieldset label={t('edit-web-configuration-form.options')}>
352-
<div className={styles.options}>
353-
{Object.entries(chatbot_config!.supported_options!).map(
354-
([key, label]) => {
355-
const is_disabled_by_url_override =
356-
!!new_url &&
357-
chatbot_config!.url_override_disabled_options?.includes(
358-
key
359-
)
360-
361-
if (model_info?.disabled_options?.includes(key)) {
362-
return null
363-
}
364-
365-
return (
366-
<UiPresetOption
367-
key={key}
368-
label={label as string}
369-
checked={options.includes(key)}
370-
on_change={() => handle_option_toggle(key)}
371-
disabled={is_disabled_by_url_override}
372-
disabled_reason={
373-
is_disabled_by_url_override
374-
? t(
375-
'edit-web-configuration-form.options.disabled-reason'
376-
).replace(
377-
'{label}',
378-
chatbot_config!.url_override_label ||
379-
t(
380-
'edit-web-configuration-form.options.custom-url'
381-
)
382-
)
383-
: undefined
384-
}
385-
/>
340+
{Object.keys(chatbot_config.supported_options || {}).length > 0 && (
341+
<UiFieldset label={t('edit-web-configuration-form.options')}>
342+
<div className={styles.options}>
343+
{Object.entries(chatbot_config.supported_options!).map(
344+
([key, label]) => {
345+
const is_disabled_by_url_override =
346+
!!new_url &&
347+
chatbot_config.url_override_disabled_options?.includes(
348+
key
386349
)
350+
351+
if (model_info?.disabled_options?.includes(key)) {
352+
return null
387353
}
388-
)}
389-
</div>
390-
</UiFieldset>
391-
)}
354+
355+
return (
356+
<UiPresetOption
357+
key={key}
358+
label={label as string}
359+
checked={options.includes(key)}
360+
on_change={() => handle_option_toggle(key)}
361+
disabled={is_disabled_by_url_override}
362+
disabled_reason={
363+
is_disabled_by_url_override
364+
? t(
365+
'edit-web-configuration-form.options.disabled-reason'
366+
).replace(
367+
'{label}',
368+
chatbot_config.url_override_label ||
369+
t(
370+
'edit-web-configuration-form.options.custom-url'
371+
)
372+
)
373+
: undefined
374+
}
375+
/>
376+
)
377+
}
378+
)}
379+
</div>
380+
</UiFieldset>
381+
)}
392382
</div>
393383
</UiScrollable>
394384
)

0 commit comments

Comments
 (0)