@@ -14,7 +14,7 @@ import { DEFAULT_PORT, SECURITY_TOKENS } from '@shared/constants/websocket'
1414import { dictionary } from '@shared/constants/dictionary'
1515import { Logger } from '@shared/utils/logger'
1616import { WebConfiguration } from '@shared/types/web-configuration'
17- import { ConfigPresetFormat } from '@/views/panel/backend/utils/preset -format-converters'
17+ import { ConfigWebConfigurationFormat } from '@/views/panel/backend/utils/web-configuration -format-converters'
1818import { LAST_SELECTED_BROWSER_ID_STATE_KEY } from '@/constants/state-keys'
1919import { ApplyChatResponseCommandArgs } from '@/commands/apply-chat-response-command/response-processor'
2020import { WebPromptType } from '@shared/types/prompt-types'
@@ -342,27 +342,25 @@ export class WebSocketManager {
342342 } )
343343 }
344344
345- public async initialize_chats ( params : {
346- chats : Array < {
347- text : string
348- web_configuration_name : string
349- raw_instructions ?: string
350- edit_format ?: string
351- prompt_type ?: WebPromptType
352- } >
353- web_configurations_config_key : string
345+ public async initialize_chat ( params : {
346+ text : string
347+ web_configuration_name : string
348+ raw_instructions ?: string
349+ edit_format ?: string
350+ prompt_type ?: WebPromptType
351+ invocation_count : number
354352 } ) : Promise < boolean > {
355353 if ( ! this . has_connected_browsers ) {
356354 throw new Error ( 'Does not have connected browsers.' )
357355 }
358356
359357 const config = vscode . workspace . getConfiguration ( 'codeWebChat' )
360- const web_chat_presets =
361- config . get < ConfigPresetFormat [ ] > ( params . web_configurations_config_key ) ?? [ ]
358+ const web_configurations =
359+ config . get < ConfigWebConfigurationFormat [ ] > ( 'webConfigurations' ) ?? [ ]
362360 const gemini_user_id = config . get < number | null > ( 'geminiUserId' )
363361 const ai_studio_user_id = config . get < number | null > ( 'aiStudioUserId' )
364362 const reuse_last_tab =
365- params . chats . length > 1
363+ params . invocation_count > 1
366364 ? false
367365 : config . get < boolean > ( 'reuseLastTab' , false )
368366
@@ -371,96 +369,95 @@ export class WebSocketManager {
371369 return false
372370 }
373371
374- for ( const chat of params . chats ) {
375- const preset = web_chat_presets . find ( ( p ) => p . name == chat . web_configuration_name )
376- if ( ! preset ) {
377- continue
378- }
372+ const web_configuration = web_configurations . find ( ( p ) => p . name == params . web_configuration_name )
373+ if ( ! web_configuration ) {
374+ return false
375+ }
379376
380- const chatbot = CHATBOTS [ preset . chatbot as keyof typeof CHATBOTS ]
381- let url : string
382- if ( preset . chatbot == 'AI Studio' ) {
383- let base_url = chatbot . url
384- if ( ai_studio_user_id !== null && ai_studio_user_id !== undefined ) {
385- base_url = base_url . replace (
386- 'https://aistudio.google.com/' ,
387- `https://aistudio.google.com/u/${ ai_studio_user_id } /`
388- )
389- }
390- if ( preset . model ) {
391- url = `${ base_url } ?model=${ preset . model } `
392- } else {
393- url = base_url
394- }
395- } else if ( preset . chatbot == 'Open WebUI' ) {
396- if ( preset . port ) {
397- url = `http://localhost:${ preset . port } /`
398- } else {
399- url = 'http://openwebui/'
400- }
401- } else if ( preset . chatbot == 'Arena' ) {
402- if ( preset . model ) {
403- url = `https://arena.ai/?mode=direct&model=${ preset . model } `
377+ const chatbot = CHATBOTS [ web_configuration . chatbot as keyof typeof CHATBOTS ]
378+ let url : string
379+ if ( web_configuration . chatbot == 'AI Studio' ) {
380+ let base_url = chatbot . url
381+ if ( ai_studio_user_id !== null && ai_studio_user_id !== undefined ) {
382+ base_url = base_url . replace (
383+ 'https://aistudio.google.com/' ,
384+ `https://aistudio.google.com/u/${ ai_studio_user_id } /`
385+ )
386+ }
387+ if ( web_configuration . model ) {
388+ url = `${ base_url } ?model=${ web_configuration . model } `
389+ } else {
390+ url = base_url
391+ }
392+ } else if ( web_configuration . chatbot == 'Open WebUI' ) {
393+ if ( web_configuration . port ) {
394+ url = `http://localhost:${ web_configuration . port } /`
395+ } else {
396+ url = 'http://openwebui/'
397+ }
398+ } else if ( web_configuration . chatbot == 'Arena' ) {
399+ if ( web_configuration . model ) {
400+ url = `https://arena.ai/?mode=direct&model=${ web_configuration . model } `
401+ } else {
402+ url = chatbot . url
403+ }
404+ } else if ( web_configuration . chatbot == 'Gemini' && gemini_user_id ) {
405+ url = `https://gemini.google.com/u/${ gemini_user_id } /app`
406+ } else if ( chatbot . supports_url_override && web_configuration . newUrl ) {
407+ try {
408+ const original_domain = new URL ( chatbot . url ) . hostname
409+ const new_domain = new URL ( web_configuration . newUrl ) . hostname
410+ if ( original_domain == new_domain ) {
411+ url = web_configuration . newUrl
404412 } else {
405413 url = chatbot . url
406- }
407- } else if ( preset . chatbot == 'Gemini' && gemini_user_id ) {
408- url = `https://gemini.google.com/u/${ gemini_user_id } /app`
409- } else if ( chatbot . supports_url_override && preset . newUrl ) {
410- try {
411- const original_domain = new URL ( chatbot . url ) . hostname
412- const new_domain = new URL ( preset . newUrl ) . hostname
413- if ( original_domain == new_domain ) {
414- url = preset . newUrl
415- } else {
416- url = chatbot . url
417- vscode . window . showWarningMessage (
418- dictionary . warning_message . URL_OVERRIDE_DIFFERENT_DOMAIN (
419- preset . name !
420- )
414+ vscode . window . showWarningMessage (
415+ dictionary . warning_message . URL_OVERRIDE_DIFFERENT_DOMAIN (
416+ web_configuration . name !
421417 )
422- }
423- } catch ( error ) {
424- url = chatbot . url
418+ )
425419 }
426- } else {
420+ } catch ( error ) {
427421 url = chatbot . url
428422 }
423+ } else {
424+ url = chatbot . url
425+ }
429426
430- const message : InitializeChatMessage = {
431- action : 'initialize-chat' ,
432- text : chat . text ,
433- url,
434- model : preset . model ,
435- temperature : preset . temperature ,
436- target_browser_id,
437- top_p : preset . topP ,
438- thinking_budget : preset . thinkingBudget ,
439- reasoning_effort : preset . reasoningEffort ,
440- system_instructions : preset . systemInstructions ,
441- options : preset . options ,
442- client_id : this . client_id || 0 , // 0 is a temporary fallback and should be removed few weeks from 28.03.25
443- raw_instructions : chat . raw_instructions ,
444- edit_format : chat . edit_format ,
445- prompt_type : chat . prompt_type ,
446- reuse_last_tab
447- }
427+ const message : InitializeChatMessage = {
428+ action : 'initialize-chat' ,
429+ text : params . text ,
430+ url,
431+ model : web_configuration . model ,
432+ temperature : web_configuration . temperature ,
433+ target_browser_id,
434+ top_p : web_configuration . topP ,
435+ thinking_budget : web_configuration . thinkingBudget ,
436+ reasoning_effort : web_configuration . reasoningEffort ,
437+ system_instructions : web_configuration . systemInstructions ,
438+ options : web_configuration . options ,
439+ client_id : this . client_id || 0 , // 0 is a temporary fallback and should be removed few weeks from 28.03.25
440+ raw_instructions : params . raw_instructions ,
441+ edit_format : params . edit_format ,
442+ prompt_type : params . prompt_type ,
443+ reuse_last_tab,
444+ invocation_count : params . invocation_count
445+ }
448446
449- Logger . info ( {
450- function_name : 'initialize_chats ' ,
451- message : 'Sending initialize chat message' ,
452- data : message
453- } )
447+ Logger . info ( {
448+ function_name : 'initialize_chat ' ,
449+ message : 'Sending initialize chat message' ,
450+ data : message
451+ } )
454452
455- this . client ?. send ( JSON . stringify ( message ) )
456- }
453+ this . client ?. send ( JSON . stringify ( message ) )
457454
458455 return true
459456 }
460457
461- public async preview_preset ( params : {
458+ public async preview_web_configuration ( params : {
462459 instruction : string
463- preset : WebConfiguration
460+ web_configuration : WebConfiguration
464461 raw_instructions : string
465462 prompt_type ?: WebPromptType
466463 } ) : Promise < boolean > {
@@ -478,50 +475,50 @@ export class WebSocketManager {
478475 const ai_studio_user_id = config . get < number | null > ( 'aiStudioUserId' )
479476 const reuse_last_tab = config . get < boolean > ( 'reuseLastTab' , false )
480477
481- const chatbot = CHATBOTS [ params . preset . chatbot as keyof typeof CHATBOTS ]
478+ const chatbot = CHATBOTS [ params . web_configuration . chatbot as keyof typeof CHATBOTS ]
482479 let url : string
483- if ( params . preset . chatbot == 'AI Studio' ) {
480+ if ( params . web_configuration . chatbot == 'AI Studio' ) {
484481 let base_url = chatbot . url
485482 if ( ai_studio_user_id !== null && ai_studio_user_id !== undefined ) {
486483 base_url = base_url . replace (
487484 'https://aistudio.google.com/' ,
488485 `https://aistudio.google.com/u/${ ai_studio_user_id } /`
489486 )
490487 }
491- if ( params . preset . model ) {
492- url = `${ base_url } ?model=${ params . preset . model } `
488+ if ( params . web_configuration . model ) {
489+ url = `${ base_url } ?model=${ params . web_configuration . model } `
493490 } else {
494491 url = base_url
495492 }
496- } else if ( params . preset . chatbot == 'Open WebUI' ) {
497- if ( params . preset . port ) {
498- url = `http://localhost:${ params . preset . port } /`
493+ } else if ( params . web_configuration . chatbot == 'Open WebUI' ) {
494+ if ( params . web_configuration . port ) {
495+ url = `http://localhost:${ params . web_configuration . port } /`
499496 } else {
500497 url = 'http://openwebui/'
501498 }
502- } else if ( params . preset . chatbot == 'Arena' ) {
503- if ( params . preset . model ) {
504- url = `https://arena.ai/?mode=direct&model=${ params . preset . model } `
499+ } else if ( params . web_configuration . chatbot == 'Arena' ) {
500+ if ( params . web_configuration . model ) {
501+ url = `https://arena.ai/?mode=direct&model=${ params . web_configuration . model } `
505502 } else {
506503 url = chatbot . url
507504 }
508505 } else if (
509- params . preset . chatbot == 'Gemini' &&
506+ params . web_configuration . chatbot == 'Gemini' &&
510507 gemini_user_number !== undefined &&
511508 gemini_user_number !== null
512509 ) {
513510 url = `https://gemini.google.com/u/${ gemini_user_number } `
514- } else if ( chatbot . supports_url_override && params . preset . new_url ) {
511+ } else if ( chatbot . supports_url_override && params . web_configuration . new_url ) {
515512 try {
516513 const original_domain = new URL ( chatbot . url ) . hostname
517- const new_domain = new URL ( params . preset . new_url ) . hostname
514+ const new_domain = new URL ( params . web_configuration . new_url ) . hostname
518515 if ( original_domain == new_domain ) {
519- url = params . preset . new_url
516+ url = params . web_configuration . new_url
520517 } else {
521518 url = chatbot . url
522519 vscode . window . showWarningMessage (
523520 dictionary . warning_message . URL_OVERRIDE_DIFFERENT_DOMAIN (
524- params . preset . name !
521+ params . web_configuration . name !
525522 )
526523 )
527524 }
@@ -536,23 +533,23 @@ export class WebSocketManager {
536533 action : 'initialize-chat' ,
537534 text : params . instruction ,
538535 url,
539- model : params . preset . model ,
540- temperature : params . preset . temperature ,
536+ model : params . web_configuration . model ,
537+ temperature : params . web_configuration . temperature ,
541538 target_browser_id,
542- top_p : params . preset . top_p ,
543- thinking_budget : params . preset . thinking_budget ,
544- reasoning_effort : params . preset . reasoning_effort ,
545- system_instructions : params . preset . system_instructions ,
546- options : params . preset . options ,
539+ top_p : params . web_configuration . top_p ,
540+ thinking_budget : params . web_configuration . thinking_budget ,
541+ reasoning_effort : params . web_configuration . reasoning_effort ,
542+ system_instructions : params . web_configuration . system_instructions ,
543+ options : params . web_configuration . options ,
547544 client_id : this . client_id || 0 , // 0 is a temporary fallback and should be removed few weeks from 28.03.25
548545 raw_instructions : params . raw_instructions ,
549546 prompt_type : params . prompt_type ,
550547 reuse_last_tab
551548 }
552549
553550 Logger . info ( {
554- function_name : 'preview_preset ' ,
555- message : 'Sending preview preset message' ,
551+ function_name : 'preview_web_configuration ' ,
552+ message : 'Sending preview web configuration message' ,
556553 data : message
557554 } )
558555
0 commit comments