Skip to content

Commit 5febc92

Browse files
committed
Refactor chatbot configurations to use optional chaining for supported_options and models access, ensuring robustness when these properties are undefined
1 parent 04671ae commit 5febc92

12 files changed

Lines changed: 38 additions & 73 deletions

File tree

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export const ai_studio: Chatbot = {
112112

113113
if (
114114
options.includes('disable-thinking') &&
115-
supported_options['disable-thinking']
115+
supported_options?.['disable-thinking']
116116
) {
117117
if (thinking_toggle.getAttribute('aria-checked') == 'true') {
118118
thinking_toggle.click()
@@ -123,13 +123,13 @@ export const ai_studio: Chatbot = {
123123
}
124124
}
125125

126-
if (options.includes('hide-panel') && supported_options['hide-panel']) {
126+
if (options.includes('hide-panel') && supported_options?.['hide-panel']) {
127127
sessionStorage.setItem('should-hide-panel', 'true')
128128
}
129129

130130
if (
131131
options.includes('temporary-chat') &&
132-
supported_options['temporary-chat']
132+
supported_options?.['temporary-chat']
133133
) {
134134
const temp_toggle = document.querySelector(
135135
'ms-incognito-mode-toggle > button'
@@ -146,7 +146,7 @@ export const ai_studio: Chatbot = {
146146
}
147147
}
148148

149-
if (supported_options['grounding-with-google-search']) {
149+
if (supported_options?.['grounding-with-google-search']) {
150150
const grounding_button = document.querySelector(
151151
'div[data-test-id="searchAsAToolTooltip"] button'
152152
) as HTMLElement
@@ -164,7 +164,7 @@ export const ai_studio: Chatbot = {
164164
}
165165
}
166166

167-
if (options.includes('url-context') && supported_options['url-context']) {
167+
if (options.includes('url-context') && supported_options?.['url-context']) {
168168
const url_context_button = document.querySelector(
169169
'div[data-test-id="browseAsAToolTooltip"] button'
170170
) as HTMLElement

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const chatgpt: Chatbot = {
4242
if (!options) return
4343
const supported_options = CHATBOTS['ChatGPT'].supported_options
4444
for (const option of options) {
45-
if (option == 'temporary' && supported_options['temporary']) {
45+
if (option == 'temporary' && supported_options?.['temporary']) {
4646
const buttons = document.querySelectorAll('button')
4747
let found = false
4848
for (const item of Array.from(buttons)) {
@@ -73,7 +73,7 @@ export const chatgpt: Chatbot = {
7373
// Don't show alert because temporary mode doesn't work in projects (url override)
7474
})
7575
}
76-
} else if (option == 'thinking' && supported_options['thinking']) {
76+
} else if (option == 'thinking' && supported_options?.['thinking']) {
7777
const plus_button = document.querySelector(
7878
'button[data-testid="composer-plus-btn"]'
7979
) as HTMLButtonElement

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const claude: Chatbot = {
7575
const supported_options = CHATBOTS['Claude'].supported_options
7676
if (
7777
options.includes('incognito-chat') &&
78-
supported_options['incognito-chat']
78+
supported_options?.['incognito-chat']
7979
) {
8080
const incognito_button_path = document.querySelector(
8181
'path[d="M6.99951 8.66672C7.5518 8.66672 7.99951 9.11443 7.99951 9.66672C7.9993 10.2188 7.55166 10.6667 6.99951 10.6667C6.44736 10.6667 5.99973 10.2188 5.99951 9.66672C5.99951 9.11443 6.44723 8.66672 6.99951 8.66672Z"]'

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ export const deepseek: Chatbot = {
6969

7070
await new Promise((r) => requestAnimationFrame(r))
7171

72-
const supported_options = CHATBOTS.DeepSeek.supported_options || {}
72+
const supported_options = CHATBOTS.DeepSeek.supported_options
7373
for (const option of options) {
74-
if (option === 'deep-think' && supported_options['deep-think']) {
74+
if (option === 'deep-think' && supported_options?.['deep-think']) {
7575
deep_think_button.click()
76-
} else if (option === 'search' && supported_options.search) {
76+
} else if (option === 'search' && supported_options?.search) {
7777
search_button.click()
7878
}
7979
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const doubao: Chatbot = {
6060
await new Promise((r) => requestAnimationFrame(r))
6161
const supported_options = CHATBOTS['Doubao'].supported_options
6262
for (const option of options) {
63-
if (option == 'deep-thinking' && supported_options['deep-thinking']) {
63+
if (option == 'deep-thinking' && supported_options?.['deep-thinking']) {
6464
const deep_thinking_button_2 = document.querySelector(
6565
'div[data-testid="chat_input"] input[data-testid="upload-file-input"] + button'
6666
) as HTMLButtonElement

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const gemini: Chatbot = {
2020
})
2121
},
2222
set_model: async (model?: string) => {
23-
if (model && model in CHATBOTS['Gemini'].models) {
23+
if (model && CHATBOTS['Gemini'].models && model in CHATBOTS['Gemini'].models) {
2424
const model_selector_trigger = document.querySelector(
2525
'bard-mode-switcher button'
2626
) as HTMLButtonElement
@@ -67,7 +67,7 @@ export const gemini: Chatbot = {
6767
const supported_options = CHATBOTS['Gemini'].supported_options
6868
if (
6969
options.includes('temporary-chat') &&
70-
supported_options['temporary-chat']
70+
supported_options?.['temporary-chat']
7171
) {
7272
const temp_chat_button_selector =
7373
'button[data-test-id="temp-chat-button"]'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const grok: Chatbot = {
2323
if (!options) return
2424
const supported_options = CHATBOTS['Grok'].supported_options
2525
for (const option of options) {
26-
if (option == 'private' && supported_options['private']) {
26+
if (option == 'private' && supported_options?.['private']) {
2727
const private_link = document.querySelector(
2828
'a[href="/c#private"]'
2929
) as HTMLAnchorElement

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const qwen: Chatbot = {
1717
if (
1818
model_selector_button &&
1919
model_selector_button.textContent &&
20-
Object.values(CHATBOTS['Qwen'].models)
20+
Object.values(CHATBOTS['Qwen'].models ?? {})
2121
.map((model) => model.label)
2222
.includes(model_selector_button.textContent.trim())
2323
) {
@@ -85,7 +85,7 @@ export const qwen: Chatbot = {
8585
if (!options) return
8686
const supported_options = CHATBOTS['Qwen'].supported_options
8787
for (const option of options) {
88-
if (option == 'thinking' && supported_options['thinking']) {
88+
if (option == 'thinking' && supported_options?.['thinking']) {
8989
const buttons = document.querySelectorAll(
9090
'.chat-message-input button.chat-input-feature-btn'
9191
) as NodeListOf<HTMLButtonElement>
@@ -94,7 +94,7 @@ export const qwen: Chatbot = {
9494
button.click()
9595
}
9696
}
97-
} else if (option == 'search' && supported_options['search']) {
97+
} else if (option == 'search' && supported_options?.['search']) {
9898
const search_button = document.querySelector(
9999
'button.websearch_button'
100100
) as HTMLButtonElement
@@ -106,7 +106,7 @@ export const qwen: Chatbot = {
106106
return
107107
}
108108
search_button.click()
109-
} else if (option == 'temporary' && supported_options['temporary']) {
109+
} else if (option == 'temporary' && supported_options?.['temporary']) {
110110
const model_selector_button = document.querySelector(
111111
'button#model-selector-0-button'
112112
) as HTMLElement

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const yuanbao: Chatbot = {
5555
if (!options) return
5656
const supported_options = CHATBOTS['Yuanbao'].supported_options
5757

58-
if (supported_options['deep-think']) {
58+
if (supported_options?.['deep-think']) {
5959
const deep_think_button = document.querySelector(
6060
'button[dt-button-id="deep_think"]'
6161
) as HTMLButtonElement
@@ -73,7 +73,7 @@ export const yuanbao: Chatbot = {
7373
}
7474
}
7575

76-
if (supported_options['search']) {
76+
if (supported_options?.['search']) {
7777
const search_button = document.querySelector(
7878
'button[dt-button-id="online_search"]'
7979
) as HTMLButtonElement

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

Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ type Chatbot = {
88
supports_thinking_budget?: boolean
99
supports_url_override?: boolean
1010
url_override_label?: string
11-
default_system_instructions: string
11+
default_system_instructions?: string
1212
default_top_p?: number
13-
supported_options: {
13+
supported_options?: {
1414
[option: string]: string
1515
}
16-
models: {
16+
models?: {
1717
[model: string]: {
1818
label: string
1919
disabled_options?: string[]
@@ -65,29 +65,24 @@ export const CHATBOTS = {
6565
url: 'https://chatgpt.com/',
6666
supports_url_override: true,
6767
url_override_label: 'Project URL',
68-
default_system_instructions: '',
6968
supported_options: {
7069
temporary: 'Temporary',
7170
thinking: 'Thinking (free plans)'
72-
},
73-
models: {}
71+
}
7472
} as Chatbot,
7573
Claude: {
7674
url: 'https://claude.ai/new',
77-
default_system_instructions: '',
7875
supported_options: {
7976
'incognito-chat': 'Incognito chat'
8077
},
8178
models: {
8279
'sonnet-4-5': { label: 'Sonnet 4.5' },
8380
'haiku-4-5': { label: 'Haiku 4.5' },
84-
'opus-4-1': { label: 'Opus 4.1' }
81+
'opus-4-5': { label: 'Opus 4.5' }
8582
}
8683
} as Chatbot,
8784
Copilot: {
8885
url: 'https://copilot.microsoft.com/',
89-
default_system_instructions: '',
90-
supported_options: {},
9186
models: {
9287
'quick-response': { label: 'Quick response' },
9388
'think-deeper': { label: 'Think Deeper' },
@@ -98,29 +93,22 @@ export const CHATBOTS = {
9893
} as Chatbot,
9994
DeepSeek: {
10095
url: 'https://chat.deepseek.com/',
101-
default_system_instructions: '',
102-
supported_options: { 'deep-think': 'DeepThink', search: 'Search' },
103-
models: {}
96+
supported_options: { 'deep-think': 'DeepThink', search: 'Search' }
10497
} as Chatbot,
10598
Doubao: {
10699
url: 'https://www.doubao.com/chat/',
107-
default_system_instructions: '',
108-
supported_options: { 'deep-thinking': 'Deep Thinking' },
109-
models: {}
100+
supported_options: { 'deep-thinking': 'Deep Thinking' }
110101
} as Chatbot,
111102
Gemini: {
112103
url: 'https://gemini.google.com/app',
113104
supported_options: { 'temporary-chat': 'Temporary chat' },
114-
default_system_instructions: '',
115105
models: {
116106
fast: { label: 'Fast' },
117107
thinking: { label: 'Thinking' }
118108
}
119109
} as Chatbot,
120110
'GitHub Copilot': {
121111
url: 'https://github.com/copilot',
122-
default_system_instructions: '',
123-
supported_options: {},
124112
models: {
125113
'gpt-5-mini': { label: 'GPT-5 mini' },
126114
'o3-mini': { label: 'o3-mini' },
@@ -140,14 +128,10 @@ export const CHATBOTS = {
140128
} as Chatbot,
141129
HuggingChat: {
142130
url: 'https://huggingface.co/chat/',
143-
supports_user_provided_model: true,
144-
default_system_instructions: '',
145-
supported_options: {},
146-
models: {}
131+
supports_user_provided_model: true
147132
} as Chatbot,
148133
Grok: {
149134
url: 'https://grok.com/',
150-
default_system_instructions: '',
151135
supported_options: { private: 'Private' },
152136
models: {
153137
auto: { label: 'Auto' },
@@ -158,25 +142,17 @@ export const CHATBOTS = {
158142
}
159143
} as Chatbot,
160144
Kimi: {
161-
url: 'https://www.kimi.com/',
162-
default_system_instructions: '',
163-
supported_options: {},
164-
models: {}
145+
url: 'https://www.kimi.com/'
165146
} as Chatbot,
166147
Minimax: {
167-
url: 'https://agent.minimax.io/',
168-
default_system_instructions: '',
169-
supported_options: {},
170-
models: {}
148+
url: 'https://agent.minimax.io/'
171149
} as Chatbot,
172150
Mistral: {
173151
url: 'https://chat.mistral.ai/chat',
174-
default_system_instructions: '',
175152
supported_options: {
176153
incognito: 'Incognito mode',
177154
think: 'Think'
178-
},
179-
models: {}
155+
}
180156
} as Chatbot,
181157
// Not supported until they fix code blocks in copied chat responses
182158
// Meta: {
@@ -199,9 +175,7 @@ export const CHATBOTS = {
199175
supports_user_provided_model: true,
200176
supports_user_provided_port: true,
201177
default_system_instructions: "You're a helpful coding assistant.",
202-
supported_options: {},
203-
default_top_p: 0.9,
204-
models: {}
178+
default_top_p: 0.9
205179
} as Chatbot,
206180
OpenRouter: {
207181
url: 'https://openrouter.ai/chat',
@@ -212,22 +186,18 @@ export const CHATBOTS = {
212186
supported_options: {
213187
'disable-reasoning': 'Disable reasoning (for hybrid models)'
214188
},
215-
default_top_p: 1,
216-
models: {}
189+
default_top_p: 1
217190
} as Chatbot,
218191
Perplexity: {
219192
url: 'https://www.perplexity.ai/',
220193
supports_url_override: true,
221194
url_override_label: 'Space URL',
222-
default_system_instructions: '',
223195
supported_options: {
224196
search: 'Search'
225-
},
226-
models: {}
197+
}
227198
} as Chatbot,
228199
Qwen: {
229200
url: 'https://chat.qwen.ai/',
230-
default_system_instructions: '',
231201
supported_options: {
232202
thinking: 'Thinking',
233203
search: 'Search',
@@ -246,8 +216,6 @@ export const CHATBOTS = {
246216
} as Chatbot,
247217
Together: {
248218
url: 'https://chat.together.ai/',
249-
default_system_instructions: '',
250-
supported_options: {},
251219
models: {
252220
'deepseek-r1-0528': { label: 'DeepSeek R1 (0528)' },
253221
'deepseek-v3-0324': { label: 'DeepSeek V3 (0324)' },
@@ -261,7 +229,6 @@ export const CHATBOTS = {
261229
} as Chatbot,
262230
Yuanbao: {
263231
url: 'https://yuanbao.tencent.com/chat',
264-
default_system_instructions: '',
265232
supported_options: { 'deep-think': 'DeepThink', search: 'Search' },
266233
models: {
267234
deepseek: { label: 'DeepSeek' },
@@ -270,10 +237,8 @@ export const CHATBOTS = {
270237
} as Chatbot,
271238
'Z.AI': {
272239
url: 'https://chat.z.ai/',
273-
default_system_instructions: '',
274240
supported_options: {
275241
'deep-think': 'Deep Think'
276-
},
277-
models: {}
242+
}
278243
} as Chatbot,
279244
}

0 commit comments

Comments
 (0)