Skip to content

Commit faf5d49

Browse files
committed
Refactor HuggingChat integration by renaming it from "Hugging Chat" to "HuggingChat," enabling model selection, and updating related configurations and UI elements
1 parent 0d94c03 commit faf5d49

7 files changed

Lines changed: 96 additions & 15 deletions

File tree

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

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,82 @@ export const hugging_chat: Chatbot = {
1212
wait_until_ready: async () => {
1313
await new Promise((resolve) => setTimeout(resolve, 500))
1414
},
15+
set_model: async (model?: string) => {
16+
if (!model) return
17+
18+
const model_picker_button = document.querySelector(
19+
'form + div > a'
20+
) as HTMLAnchorElement
21+
if (!model_picker_button) {
22+
report_initialization_error({
23+
function_name: 'hugging_chat.set_model',
24+
log_message: 'Model picker button not found',
25+
alert_message: InitializationError.UNABLE_TO_SET_MODEL
26+
})
27+
return
28+
}
29+
30+
model_picker_button.click()
31+
await new Promise((r) => requestAnimationFrame(r))
32+
33+
const dialog = await new Promise<Element | null>((resolve) => {
34+
const check = () => {
35+
const el = document.querySelector('div[role="dialog"]')
36+
if (el) {
37+
resolve(el)
38+
} else {
39+
setTimeout(check, 100)
40+
}
41+
}
42+
check()
43+
})
44+
45+
if (!dialog) {
46+
report_initialization_error({
47+
function_name: 'hugging_chat.set_model',
48+
log_message: 'Model picker dialog not found',
49+
alert_message: InitializationError.UNABLE_TO_SET_MODEL
50+
})
51+
return
52+
}
53+
54+
const model_button = dialog.querySelector(
55+
`button[data-model-id="${model}"]`
56+
) as HTMLButtonElement
57+
58+
if (!model_button) {
59+
report_initialization_error({
60+
function_name: 'hugging_chat.set_model',
61+
log_message: `Model button for "${model}" not found`,
62+
alert_message: InitializationError.UNABLE_TO_SET_MODEL
63+
})
64+
65+
const close_button = dialog.querySelector('button') as HTMLButtonElement
66+
if (close_button) {
67+
close_button.click()
68+
}
69+
return
70+
}
71+
72+
model_button.click()
73+
await new Promise((r) => requestAnimationFrame(r))
74+
75+
const activate_button = dialog.querySelector(
76+
'button[name="Activate model"]'
77+
) as HTMLButtonElement
78+
79+
if (!activate_button) {
80+
report_initialization_error({
81+
function_name: 'hugging_chat.set_model',
82+
log_message: 'Activate model button not found',
83+
alert_message: InitializationError.UNABLE_TO_SET_MODEL
84+
})
85+
return
86+
}
87+
88+
activate_button.click()
89+
await new Promise((resolve) => setTimeout(resolve, 500))
90+
},
1591
inject_apply_response_button: (
1692
client_id: number,
1793
raw_instructions?: string,
@@ -43,7 +119,7 @@ export const hugging_chat: Chatbot = {
43119
}
44120

45121
observe_for_responses({
46-
chatbot_name: 'Hugging Chat',
122+
chatbot_name: 'HuggingChat',
47123
is_generating: () =>
48124
!!document.querySelector('button.stop-generating-btn'),
49125
footer_selector: 'div[data-message-role="assistant"] > div:nth-child(3)',

‎packages/shared/src/constants/chatbots.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,12 @@ export const CHATBOTS = {
191191
'claude-opus-4': { label: 'Claude Opus 4' }
192192
}
193193
},
194-
'Hugging Chat': {
194+
HuggingChat: {
195195
url: 'https://huggingface.co/chat/',
196196
supports_custom_temperature: false,
197197
supports_custom_top_p: false,
198198
supports_system_instructions: false,
199-
supports_user_provided_model: false,
199+
supports_user_provided_model: true,
200200
supports_user_provided_port: false,
201201
supports_reasoning_effort: false,
202202
supports_thinking_budget: false,

‎packages/shared/src/constants/dictionary.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ export const dictionary = {
3838
NO_DEFAULT_INTELLIGENT_UPDATE_CONFIGURATION:
3939
'No default "Intelligent Update" configuration found. Please set one as default in the settings.',
4040
NO_EDIT_CONTEXT_CONFIGURATIONS_FOUND:
41-
'No "Edit Context" configurations found. Please add one in the settings.'
41+
'No "Edit Context" configurations found. Please add one in the settings.',
42+
PRESET_PREVIEW_SENT_TO_BROWSER:
43+
'Preset preview sent to the connected browser.'
4244
},
4345

4446
warning_message: {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const chatbot_to_icon: Record<keyof typeof CHATBOTS, Icon.Variant> = {
1717
Gemini: 'GEMINI',
1818
'GitHub Copilot': 'GITHUB_COPILOT',
1919
Grok: 'GROK',
20-
'Hugging Chat': 'HUGGING_CHAT',
20+
HuggingChat: 'HUGGING_CHAT',
2121
Kimi: 'KIMI',
2222
Mistral: 'MISTRAL',
2323
// Meta: 'META',

‎packages/vscode/package.json‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@
638638
},
639639
{
640640
"name": "(16)",
641-
"chatbot": "Hugging Chat"
641+
"chatbot": "HuggingChat"
642642
},
643643
{
644644
"name": "(17)",
@@ -669,7 +669,7 @@
669669
"Gemini",
670670
"GitHub Copilot",
671671
"Grok",
672-
"Hugging Chat",
672+
"HuggingChat",
673673
"Kimi",
674674
"Perplexity",
675675
"Mistral",
@@ -823,7 +823,7 @@
823823
},
824824
{
825825
"name": "(16)",
826-
"chatbot": "Hugging Chat"
826+
"chatbot": "HuggingChat"
827827
},
828828
{
829829
"name": "(17)",
@@ -854,7 +854,7 @@
854854
"Gemini",
855855
"GitHub Copilot",
856856
"Grok",
857-
"Hugging Chat",
857+
"HuggingChat",
858858
"Kimi",
859859
"Perplexity",
860860
"Mistral",
@@ -1008,7 +1008,7 @@
10081008
},
10091009
{
10101010
"name": "(16)",
1011-
"chatbot": "Hugging Chat"
1011+
"chatbot": "HuggingChat"
10121012
},
10131013
{
10141014
"name": "(17)",
@@ -1039,7 +1039,7 @@
10391039
"Gemini",
10401040
"GitHub Copilot",
10411041
"Grok",
1042-
"Hugging Chat",
1042+
"HuggingChat",
10431043
"Kimi",
10441044
"Perplexity",
10451045
"Mistral",
@@ -1163,7 +1163,7 @@
11631163
},
11641164
{
11651165
"name": "(16)",
1166-
"chatbot": "Hugging Chat"
1166+
"chatbot": "HuggingChat"
11671167
},
11681168
{
11691169
"name": "(17)",
@@ -1194,7 +1194,7 @@
11941194
"Gemini",
11951195
"GitHub Copilot",
11961196
"Grok",
1197-
"Hugging Chat",
1197+
"HuggingChat",
11981198
"Kimi",
11991199
"Perplexity",
12001200
"Mistral",

‎packages/vscode/src/services/websocket-manager.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ export class WebSocketManager {
331331
instruction: string
332332
preset: Preset
333333
raw_instructions: string
334+
mode: any
334335
}): Promise<void> {
335336
if (!this.has_connected_browsers) {
336337
throw new Error('Does not have connected browsers.')
@@ -369,7 +370,8 @@ export class WebSocketManager {
369370
system_instructions: params.preset.system_instructions,
370371
options: params.preset.options,
371372
client_id: this.client_id || 0, // 0 is a temporary fallback and should be removed few weeks from 28.03.25
372-
raw_instructions: params.raw_instructions
373+
raw_instructions: params.raw_instructions,
374+
mode: params.mode
373375
}
374376

375377
Logger.info({

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,10 @@ export const handle_preview_preset = async (
160160
provider.websocket_server_instance.preview_preset({
161161
instruction: text_to_send,
162162
preset: preset_for_preview,
163+
mode: provider.web_mode,
163164
raw_instructions: current_instructions
164165
})
165166
vscode.window.showInformationMessage(
166-
'Preset preview sent to the connected browser.'
167+
dictionary.information_message.PRESET_PREVIEW_SENT_TO_BROWSER
167168
)
168169
}

0 commit comments

Comments
 (0)