Skip to content

Commit 41e39c2

Browse files
committed
Implement the context size warning threshold setting in the settings view and refactor the Input component into a common UI component
1 parent bda1944 commit 41e39c2

17 files changed

Lines changed: 161 additions & 24 deletions

File tree

packages/ui/src/components/editor/panel/Input/Input.module.scss renamed to packages/ui/src/components/editor/common/Input/Input.module.scss

File renamed without changes.

packages/ui/src/components/editor/panel/Input/Input.stories.tsx renamed to packages/ui/src/components/editor/common/Input/Input.stories.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,15 @@ export const WithValue = () => {
2424
/>
2525
)
2626
}
27+
export const WithMaxWidth = () => {
28+
const [value, set_value] = useState('')
29+
30+
return (
31+
<Input
32+
value={value}
33+
onChange={set_value}
34+
placeholder="Max width is 200px"
35+
max_width={200}
36+
/>
37+
)
38+
}

packages/ui/src/components/editor/panel/Input/Input.tsx renamed to packages/ui/src/components/editor/common/Input/Input.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,23 @@ type Props = {
44
type?: string
55
value: string
66
placeholder?: string
7+
max_width?: number
78
onChange: (value: string) => void
89
}
910

1011
export const Input: React.FC<Props> = (props) => {
12+
const style = props.max_width
13+
? { maxWidth: `${props.max_width}px` }
14+
: undefined
15+
1116
return (
1217
<input
1318
type={props.type || 'text'}
1419
value={props.value}
1520
onChange={(e) => props.onChange(e.target.value)}
1621
className={styles.input}
1722
placeholder={props.placeholder}
23+
style={style}
1824
/>
1925
)
2026
}

packages/ui/src/components/editor/panel/Input/index.ts renamed to packages/ui/src/components/editor/common/Input/index.ts

File renamed without changes.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
}
1313

1414
.bar {
15-
width: 100%;
15+
flex: 1;
1616
height: 3px;
1717
background-color: var(--vscode-dropdown-border);
1818
border-radius: var(--border-radius-999px);

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { FC } from 'react'
21
import styles from './ContextUtilisation.module.scss'
32
import cn from 'classnames'
43

@@ -7,27 +6,16 @@ type Props = {
76
context_size_warning_threshold: number
87
}
98

10-
const format_number = (num: number): string => {
11-
if (num < 1000) {
12-
return num.toLocaleString()
13-
}
14-
return `${Math.floor(num / 1000)}k`
15-
}
16-
17-
export const ContextUtilisation: FC<Props> = (props) => {
18-
const { current_context_size, context_size_warning_threshold } = props
9+
export const ContextUtilisation: React.FC<Props> = (props) => {
1910
const is_above_threshold =
20-
current_context_size > context_size_warning_threshold
11+
props.current_context_size > props.context_size_warning_threshold
2112
const progress = Math.min(
22-
(current_context_size / context_size_warning_threshold) * 100,
13+
(props.current_context_size / props.context_size_warning_threshold) * 100,
2314
100
2415
)
2516

2617
return (
2718
<div className={styles.container}>
28-
<span className={styles.label}>
29-
{format_number(current_context_size)}
30-
</span>
3119
<div className={styles.bar}>
3220
<div
3321
className={cn(styles.bar__progress, {
@@ -36,8 +24,14 @@ export const ContextUtilisation: FC<Props> = (props) => {
3624
style={{ width: `${progress}%` }}
3725
/>
3826
</div>
39-
<span className={styles.label}>
40-
{format_number(context_size_warning_threshold)}
27+
<span
28+
className={styles.label}
29+
title="Selecting more than set threshold will show warning"
30+
>
31+
{props.current_context_size > 0
32+
? `~${props.current_context_size}`
33+
: '0'}
34+
/{props.context_size_warning_threshold} tokens in context
4135
</span>
4236
</div>
4337
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useState } from 'react'
22
import { Field } from './Field'
3-
import { Input } from '../Input'
3+
import { Input } from '../../common/Input'
44
import { Checkbox } from '../Checkbox'
55

66
export default {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const Presets: React.FC<Presets.Props> = (props) => {
102102
return (
103103
<div className={styles.container}>
104104
<div className={styles['my-presets']}>
105-
<div className={styles['my-presets__left']}>{'MY CHAT PRESETS'}</div>
105+
<div className={styles['my-presets__left']}>MY PRESETS</div>
106106
<IconButton codicon_icon="add" on_click={props.on_create_preset} />
107107
</div>
108108

‎packages/vscode/src/views/panel/backend/panel-provider.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ export class ViewProvider implements vscode.WebviewViewProvider {
694694
private _send_context_size_warning_threshold() {
695695
if (!this._webview_view) return
696696
const config = vscode.workspace.getConfiguration('codeWebChat')
697-
const threshold = config.get<number>('contextSizeWarningThreshold')!
697+
const threshold = config.get<number>('contextSizeWarningThreshold', 60000)
698698
this.send_message({
699699
command: 'CONTEXT_SIZE_WARNING_THRESHOLD',
700700
threshold
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as vscode from 'vscode'
2+
import { SettingsProvider } from '@/views/settings/backend/settings-provider'
3+
4+
export const handle_get_context_size_warning_threshold = async (
5+
provider: SettingsProvider
6+
): Promise<void> => {
7+
const config = vscode.workspace.getConfiguration('codeWebChat')
8+
const threshold = config.get<number>('contextSizeWarningThreshold')
9+
if (threshold === undefined) {
10+
// Should not happen if default is set in package.json
11+
return
12+
}
13+
provider.postMessage({
14+
command: 'CONTEXT_SIZE_WARNING_THRESHOLD',
15+
threshold
16+
})
17+
}

0 commit comments

Comments
 (0)