Skip to content

Commit fd5f8dc

Browse files
committed
Add Gemini 3 Flash model to Perplexity, refactor API manager for race condition handling, and adjust UI styling for prompt field and API manager modal
1 parent 16b8c9a commit fd5f8dc

6 files changed

Lines changed: 32 additions & 41 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ export const CHATBOTS = {
192192
label: 'Gemini 3 Pro',
193193
disabled_options: ['with-reasoning']
194194
},
195+
'gemini-3-flash': {
196+
label: 'Gemini 3 Flash'
197+
},
195198
'grok-4.1': { label: 'Grok 4.1' },
196199
'kimi-k2-thinking': {
197200
label: 'Kimi K2 Thinking',

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@
237237

238238
.footer {
239239
display: flex;
240-
gap: 4px;
241240
padding: 6px 10px 6px 6px;
242241
justify-content: space-between;
243242
position: relative;
@@ -274,21 +273,22 @@
274273
flex: 1;
275274
display: flex;
276275
align-items: center;
277-
gap: 10px;
276+
justify-content: flex-end;
277+
gap: 8px;
278278
pointer-events: none;
279279

280280
&__edit-format {
281281
flex: 1;
282282
display: flex;
283283
align-items: center;
284284
justify-content: flex-end;
285-
gap: 4px;
286285

287286
&__button {
288287
font-size: 11px;
289288
pointer-events: all;
290289
position: relative;
291290
color: var(--vscode-foreground);
291+
padding: 0 2px;
292292

293293
&__spacer {
294294
visibility: hidden;

‎packages/ui/src/components/editor/panel/modals/ApiManagerModal/ApiManagerModal.module.scss‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
height: 100%;
77
display: flex;
88
align-items: flex-end;
9-
justify-content: center;
9+
justify-content: flex-end;
1010
padding: 0 12px 48px 12px;
1111
pointer-events: none;
1212
}
@@ -73,6 +73,8 @@
7373
background-color: var(--vscode-quickInput-background);
7474
border: 1px solid var(--vscode-widget-border);
7575
box-shadow: 0 0 8px 2px var(--vscode-widget-shadow);
76+
width: 100%;
77+
max-width: 260px;
7678
}
7779

7880
.requests-container {

‎packages/ui/src/components/editor/settings/Item/Item.stories.tsx‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,14 @@ type Story = StoryObj<typeof Item>
2525
export const Default: Story = {
2626
args: {
2727
title: 'Model Provider',
28-
description: 'Select the model provider to use for this configuration.',
29-
slot: <div>slot</div>
28+
description: 'Select the model provider to use for this configuration.'
3029
}
3130
}
3231

3332
export const SlotBelow: Story = {
3433
args: {
3534
title: 'API Key',
3635
description:
37-
'Enter your API key for the selected model provider. It will be stored securely.',
38-
slot: <div>slot</div>,
39-
slot_placement: 'below'
36+
'Enter your API key for the selected model provider. It will be stored securely.'
4037
}
4138
}

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ import { Logger } from '@shared/utils/logger'
66

77
export class ApiManager {
88
private cancel_token_sources: Map<string, CancelTokenSource> = new Map()
9+
private next_allowed_finish_time = 0
910

1011
constructor(private panel_provider: PanelProvider) {}
1112

1213
public async get(params: {
1314
endpoint_url: string
1415
api_key?: string
1516
body: any
17+
request_id?: string
1618
}): Promise<{ response: string; thoughts?: string } | null> {
17-
const request_id = randomUUID()
19+
const request_id = params.request_id || randomUUID()
1820
const cancel_token_source = axios.CancelToken.source()
1921
this.cancel_token_sources.set(request_id, cancel_token_source)
2022

@@ -51,25 +53,34 @@ export class ApiManager {
5153
} catch (error) {
5254
if (axios.isCancel(error)) {
5355
Logger.info({
54-
function_name: 'make_api_call',
56+
function_name: 'get',
5557
message: 'API call cancelled by user'
5658
})
5759
throw error // Re-throw cancellation error to be handled by caller
5860
}
5961

6062
Logger.error({
61-
function_name: 'make_api_call',
63+
function_name: 'get',
6264
message: 'API call error',
6365
data: error
6466
})
65-
// Error messages are shown by make_api_request, so no need to show one here.
6667
return null
6768
} finally {
6869
this.panel_provider.send_message({
6970
command: 'HIDE_API_MANAGER_PROGRESS',
7071
id: request_id
7172
})
7273
this.cancel_token_sources.delete(request_id)
74+
75+
// Prevent race conditions of the applyChatResponse command when invoked in short successions
76+
const now = Date.now()
77+
const wait_until = Math.max(now, this.next_allowed_finish_time)
78+
const delay = wait_until - now
79+
this.next_allowed_finish_time = wait_until + 500
80+
81+
if (delay > 0) {
82+
await new Promise((resolve) => setTimeout(resolve, delay))
83+
}
7384
}
7485
}
7586

‎packages/vscode/src/views/panel/backend/message-handlers/handle-code-completion.ts‎

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as vscode from 'vscode'
22
import axios from 'axios'
3-
import { make_api_request } from '@/utils/make-api-request'
43
import { code_completion_instructions_for_panel } from '@/constants/instructions'
54
import { FilesCollector } from '@/utils/files-collector'
65
import {
@@ -15,6 +14,7 @@ import { PanelProvider } from '@/views/panel/backend/panel-provider'
1514
import { CodeCompletionMessage } from '@/views/panel/types/messages'
1615
import { apply_reasoning_effort } from '@/utils/apply-reasoning-effort'
1716
import { dictionary } from '@shared/constants/dictionary'
17+
import { randomUUID } from 'crypto'
1818

1919
const get_code_completion_config = async (
2020
api_providers_manager: ModelProvidersManager,
@@ -211,7 +211,7 @@ const perform_code_completion = async (params: {
211211
show_quick_pick?: boolean
212212
completion_instructions?: string
213213
config_id?: string
214-
panel_provider?: PanelProvider
214+
panel_provider: PanelProvider
215215
}): Promise<void> => {
216216
const api_providers_manager = new ModelProvidersManager(params.context)
217217

@@ -296,7 +296,7 @@ const perform_code_completion = async (params: {
296296
)
297297
return
298298
}
299-
const cancel_token_source = axios.CancelToken.source()
299+
const request_id = randomUUID()
300300
const document = editor.document
301301
const position = editor.selection.active
302302

@@ -357,37 +357,19 @@ const perform_code_completion = async (params: {
357357
const cursor_listener = vscode.window.onDidChangeTextEditorSelection(
358358
(e) => {
359359
if (e.textEditor === editor) {
360-
cancel_token_source.cancel(
361-
'User moved the cursor, cancelling request.'
362-
)
360+
params.panel_provider.api_manager.cancel_api_call(request_id)
363361
}
364362
}
365363
)
366364

367365
let response_for_apply: string | undefined
368366

369-
if (params.panel_provider) {
370-
params.panel_provider.api_call_cancel_token_source = cancel_token_source
371-
params.panel_provider.send_message({
372-
command: 'SHOW_PROGRESS',
373-
title: `${dictionary.api_call.WAITING_FOR_RESPONSE}...`
374-
})
375-
}
376-
377367
try {
378-
const result = await make_api_request({
368+
const result = await params.panel_provider.api_manager.get({
379369
endpoint_url,
380370
api_key: provider.api_key,
381371
body,
382-
cancellation_token: cancel_token_source.token,
383-
on_thinking_chunk: () => {
384-
if (params.panel_provider) {
385-
params.panel_provider.send_message({
386-
command: 'SHOW_PROGRESS',
387-
title: `${dictionary.api_call.THINKING}...`
388-
})
389-
}
390-
}
372+
request_id
391373
})
392374

393375
if (result) {
@@ -406,10 +388,6 @@ const perform_code_completion = async (params: {
406388
dictionary.error_message.CODE_COMPLETION_ERROR
407389
)
408390
} finally {
409-
if (params.panel_provider) {
410-
params.panel_provider.send_message({ command: 'HIDE_PROGRESS' })
411-
params.panel_provider.api_call_cancel_token_source = null
412-
}
413391
cursor_listener.dispose()
414392
}
415393

0 commit comments

Comments
 (0)