Skip to content

Commit 66fea9b

Browse files
committed
Apply a default system instruction for coding assistance when none is specified, and refactor the preset editing UI to use collapsible fieldsets and improve field presentation
1 parent 1b344ef commit 66fea9b

12 files changed

Lines changed: 196 additions & 90 deletions

File tree

‎packages/browser/src/content-scripts/send-prompt-content-script/chatbots/ai-studio.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { CHATBOTS } from '@shared/constants/chatbots'
33
import { show_response_ready_notification } from '../utils/show-response-ready-notification'
44
import { add_apply_response_button } from '../utils/add-apply-response-button'
55
import { report_initialization_error } from '../utils/report-initialization-error'
6+
import { default_system_instructions } from '../constants/default-system-instructions'
67

78
export const ai_studio: Chatbot = {
89
wait_until_ready: async () => {
@@ -30,8 +31,8 @@ export const ai_studio: Chatbot = {
3031
})
3132
},
3233
enter_system_instructions: async (chat) => {
33-
const system_instructions = chat.system_instructions
34-
if (!system_instructions) return
34+
const system_instructions =
35+
chat.system_instructions || default_system_instructions
3536
await open_panel()
3637
const system_instructions_button = document.querySelector(
3738
'button[data-test-system-instructions-card]'

‎packages/browser/src/content-scripts/send-prompt-content-script/chatbots/open-webui.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
observe_for_responses
55
} from '../utils/add-apply-response-button'
66
import { report_initialization_error } from '../utils/report-initialization-error'
7+
import { default_system_instructions } from '../constants/default-system-instructions'
78

89
export const open_webui: Chatbot = {
910
wait_until_ready: async () => {
@@ -23,7 +24,8 @@ export const open_webui: Chatbot = {
2324
await new Promise((resolve) => setTimeout(resolve, 500))
2425
},
2526
enter_system_instructions: async (chat) => {
26-
const system_instructions = chat.system_instructions
27+
const system_instructions =
28+
chat.system_instructions || default_system_instructions
2729
if (!system_instructions) return
2830
const controls_button = document.querySelector(
2931
'button[aria-label="Controls"]'

‎packages/browser/src/content-scripts/send-prompt-content-script/chatbots/openrouter.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
observe_for_responses
55
} from '../utils/add-apply-response-button'
66
import { report_initialization_error } from '../utils/report-initialization-error'
7+
import { default_system_instructions } from '../constants/default-system-instructions'
78

89
const show_options_modal = async (function_name: string) => {
910
const options_button = Array.from(
@@ -58,7 +59,8 @@ export const openrouter: Chatbot = {
5859
await new Promise((resolve) => setTimeout(resolve, 500))
5960
},
6061
enter_system_instructions: async (chat) => {
61-
const system_instructions = chat.system_instructions
62+
const system_instructions =
63+
chat.system_instructions || default_system_instructions
6264
if (!system_instructions) return
6365
if (!(await show_options_modal('enter_system_instructions'))) return
6466
const textarea = document.querySelector(
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const default_system_instructions = "You're a helpful coding assistant."

‎packages/ui/src/components/editor/panel/Field/Field.module.scss‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
display: flex;
33
flex-direction: column;
44
gap: 4px;
5-
padding: 0 12px;
65

76
&__label {
87
font-size: 12px;

‎packages/ui/src/components/editor/panel/Field/Field.tsx‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ type Props = {
55
html_for?: string
66
info?: React.ReactNode
77
children?: React.ReactNode
8-
title?: string
98
}
109

1110
export const Field: React.FC<Props> = (props) => {
1211
return (
13-
<div className={styles.field} title={props.title}>
14-
<label htmlFor={props.html_for} className={styles.field__label}>
15-
{props.label}
16-
</label>
12+
<div className={styles.field}>
13+
{props.label && (
14+
<label htmlFor={props.html_for} className={styles.field__label}>
15+
{props.label}
16+
</label>
17+
)}
1718
{props.children}
1819
{props.info && <div className={styles.field__info}>{props.info}</div>}
1920
</div>
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
.fieldset {
22
display: flex;
33
flex-direction: column;
4+
border: 1px solid var(--cwc-border-color-dimmed);
5+
border-radius: 10px;
46

57
&__label {
6-
padding: 8px 12px 4px;
8+
padding: 8px 12px 8px 12px;
79
font-size: 11px;
810
font-weight: 600;
9-
color: var(--vscode-descriptionForeground);
11+
color: var(--cwc-text-color-dimmed);
1012
text-transform: uppercase;
11-
}
12-
13-
&__header {
14-
height: var(--list-item-height);
15-
padding: 0 12px;
1613
display: flex;
17-
justify-content: space-between;
1814
align-items: center;
19-
cursor: pointer;
15+
gap: 4px;
2016

21-
&:hover {
22-
background-color: var(--vscode-list-hoverBackground);
17+
&--interactive {
18+
cursor: pointer;
2319
}
2420

2521
&__left {
@@ -33,5 +29,6 @@
3329
display: flex;
3430
flex-direction: column;
3531
gap: 8px;
32+
padding: 2px 12px 12px 12px;
3633
}
3734
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { useState } from 'react'
2+
import { Fieldset } from './Fieldset'
3+
import { Field } from '../Field'
4+
5+
export default {
6+
component: Fieldset
7+
}
8+
9+
export const Default = () => (
10+
<div style={{ width: '300px' }}>
11+
<Fieldset label="General Settings">
12+
<Field label="Name">
13+
<div
14+
style={{
15+
height: '24px',
16+
border: '1px solid var(--vscode-input-border)',
17+
background: 'var(--vscode-input-background)'
18+
}}
19+
/>
20+
</Field>
21+
<Field label="Description">
22+
<div
23+
style={{
24+
height: '24px',
25+
border: '1px solid var(--vscode-input-border)',
26+
background: 'var(--vscode-input-background)'
27+
}}
28+
/>
29+
</Field>
30+
</Fieldset>
31+
</div>
32+
)
33+
34+
export const Collapsible = () => {
35+
const [is_collapsed, set_is_collapsed] = useState(false)
36+
37+
return (
38+
<div style={{ width: '300px' }}>
39+
<Fieldset
40+
label="Advanced Settings"
41+
is_collapsed={is_collapsed}
42+
on_toggle_collapsed={() => set_is_collapsed(!is_collapsed)}
43+
>
44+
<Field label="API Key">
45+
<div
46+
style={{
47+
height: '24px',
48+
border: '1px solid var(--vscode-input-border)',
49+
background: 'var(--vscode-input-background)'
50+
}}
51+
/>
52+
</Field>
53+
<Field label="Secret">
54+
<div
55+
style={{
56+
height: '24px',
57+
border: '1px solid var(--vscode-input-border)',
58+
background: 'var(--vscode-input-background)'
59+
}}
60+
/>
61+
</Field>
62+
</Fieldset>
63+
</div>
64+
)
65+
}
66+
67+
export const CollapsedByDefault = () => {
68+
const [is_collapsed, set_is_collapsed] = useState(true)
69+
70+
return (
71+
<div style={{ width: '300px' }}>
72+
<Fieldset
73+
label="Experimental Features"
74+
is_collapsed={is_collapsed}
75+
on_toggle_collapsed={() => set_is_collapsed(!is_collapsed)}
76+
>
77+
<div style={{ padding: '8px', fontSize: '12px' }}>
78+
These features are experimental and may change.
79+
</div>
80+
</Fieldset>
81+
</div>
82+
)
83+
}

‎packages/ui/src/components/editor/panel/Fieldset/Fieldset.tsx‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@ export const Fieldset: React.FC<Props> = ({
1818
return (
1919
<div className={styles.fieldset}>
2020
<div
21-
className={styles.fieldset__header}
21+
className={cn(
22+
styles.fieldset__label,
23+
styles['fieldset__label--interactive']
24+
)}
2225
onClick={on_toggle_collapsed}
2326
role="button"
2427
>
25-
<div className={styles.fieldset__header__left}>
26-
<span
27-
className={cn('codicon', {
28-
'codicon-chevron-down': !is_collapsed,
29-
'codicon-chevron-right': is_collapsed
30-
})}
31-
/>
32-
<span>{label}</span>
33-
</div>
28+
<span>{label}</span>
29+
<span
30+
className={cn('codicon', {
31+
'codicon-chevron-down': !is_collapsed,
32+
'codicon-chevron-right': is_collapsed
33+
})}
34+
/>
3435
</div>
3536
{!is_collapsed && (
3637
<div className={styles.fieldset__content}>{children}</div>

‎packages/vscode/src/views/panel/backend/message-handlers/handle-update-preset.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const handle_update_preset = async (
3939

4040
const are_presets_equal = (a: Preset, b: Preset): boolean => {
4141
return (
42-
(a.name == b.name || !b.name) &&
42+
a.name == b.name &&
4343
a.chatbot == b.chatbot &&
4444
a.prompt_prefix == b.prompt_prefix &&
4545
a.prompt_suffix == b.prompt_suffix &&

0 commit comments

Comments
 (0)