Skip to content

Commit 7a7c102

Browse files
committed
Display the selected preset or API configuration in the chat input submit button tooltip
1 parent b8a6e73 commit 7a7c102

4 files changed

Lines changed: 98 additions & 1 deletion

File tree

‎packages/browser/src/manifest.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"name": "Code Web Chat Connector",
55
"short_name": "CWC",
66
"description": "Connect your editor with free chatbots. Include websites in context.",
7-
"version": "1.47.0",
7+
"version": "1.48.0",
88
"homepage_url": "https://github.com/robertpiosik/CodeWebChat",
99
"icons": {
1010
"16": "icons/icon-16.png",

‎packages/ui/src/components/editor/ChatInput/ChatInput.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export type ChatInputProps = {
3232
on_caret_position_set?: () => void
3333
focus_key?: number
3434
focus_and_select_key?: number
35+
use_last_choice_button_title?: string
3536
}
3637

3738
export const ChatInput: React.FC<ChatInputProps> = (props) => {
@@ -271,6 +272,7 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
271272
<button
272273
className={styles.footer__right__button}
273274
onClick={handle_submit}
275+
title={props.use_last_choice_button_title}
274276
>
275277
<Icon variant="ENTER" />
276278
<span>{component_dictionary.use_last_choice}</span>

‎packages/vscode/src/views/panel/frontend/main/MainView/MainView.tsx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { IconButton } from '@ui/components/editor/IconButton/IconButton'
1919
import { Scrollable } from '@ui/components/editor/Scrollable'
2020
import { BrowserExtensionMessage as UiBrowserExtensionMessage } from '@ui/components/editor/BrowserExtensionMessage'
2121
import { ApiToolConfiguration } from '@/views/panel/types/messages'
22+
import { use_last_choice_button_title } from './hooks/use-last-choice-button-title'
2223

2324
type Props = {
2425
initialize_chats: (params: {
@@ -217,6 +218,14 @@ export const MainView: React.FC<Props> = (props) => {
217218
}
218219
}
219220

221+
const last_choice_button_title = use_last_choice_button_title({
222+
home_view_type: props.home_view_type,
223+
selected_preset_or_group_name: props.selected_preset_or_group_name,
224+
presets: props.presets,
225+
selected_configuration_index: props.selected_configuration_index,
226+
configurations: props.configurations
227+
})
228+
220229
return (
221230
<div ref={container_ref} className={styles.container}>
222231
<Scrollable>
@@ -297,6 +306,7 @@ export const MainView: React.FC<Props> = (props) => {
297306
on_caret_position_set={props.on_caret_position_set}
298307
focus_and_select_key={props.chat_input_focus_and_select_key}
299308
focus_key={props.chat_input_focus_key}
309+
use_last_choice_button_title={last_choice_button_title}
300310
/>
301311
</div>
302312

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { useMemo } from 'react'
2+
import {
3+
HOME_VIEW_TYPES,
4+
HomeViewType
5+
} from '@/views/panel/types/home-view-type'
6+
import { ApiToolConfiguration } from '@/views/panel/types/messages'
7+
import { CHATBOTS } from '@shared/constants/chatbots'
8+
import { Preset } from '@shared/types/preset'
9+
10+
export const use_last_choice_button_title = (params: {
11+
home_view_type: HomeViewType
12+
selected_preset_or_group_name?: string
13+
presets: Preset[]
14+
selected_configuration_index?: number
15+
configurations: ApiToolConfiguration[]
16+
}): string | undefined => {
17+
return useMemo(() => {
18+
if (params.home_view_type == HOME_VIEW_TYPES.WEB) {
19+
if (params.selected_preset_or_group_name) {
20+
if (params.selected_preset_or_group_name == 'Ungrouped') {
21+
return 'Ungrouped'
22+
} else {
23+
const preset = params.presets.find(
24+
(p) => p.name == params.selected_preset_or_group_name
25+
)
26+
if (preset) {
27+
const is_unnamed =
28+
!preset.name || /^\(\d+\)$/.test(preset.name.trim())
29+
let display_name: string
30+
if (preset.chatbot) {
31+
display_name = is_unnamed ? preset.chatbot : preset.name
32+
} else {
33+
display_name = is_unnamed ? 'Unnamed group' : preset.name
34+
}
35+
36+
const get_subtitle = (): string => {
37+
const { chatbot, model } = preset
38+
if (!chatbot) {
39+
return model || ''
40+
}
41+
const model_display_name = model
42+
? (CHATBOTS[chatbot].models as any)[model]?.label || model
43+
: null
44+
if (is_unnamed) {
45+
return model_display_name || ''
46+
}
47+
if (model_display_name) {
48+
return `${chatbot} · ${model_display_name}`
49+
}
50+
return chatbot
51+
}
52+
53+
const subtitle = get_subtitle()
54+
if (subtitle) {
55+
return `${display_name} (${subtitle})`
56+
} else {
57+
return display_name
58+
}
59+
}
60+
}
61+
}
62+
} else {
63+
// HOME_VIEW_TYPES.API
64+
if (params.selected_configuration_index !== undefined) {
65+
const configuration =
66+
params.configurations[params.selected_configuration_index]
67+
if (configuration) {
68+
const description_parts = [configuration.provider_name]
69+
if (configuration.reasoning_effort) {
70+
description_parts.push(`${configuration.reasoning_effort}`)
71+
}
72+
const description = description_parts.join(' · ')
73+
return `${configuration.model} (${description})`
74+
}
75+
}
76+
}
77+
return undefined
78+
}, [
79+
params.home_view_type,
80+
params.selected_preset_or_group_name,
81+
params.presets,
82+
params.selected_configuration_index,
83+
params.configurations
84+
])
85+
}

0 commit comments

Comments
 (0)