Removed direct references to 'vertexai_project_id' from openai.js and related files, ensuring it is now managed through backend secrets for enhanced security.
| @@ -59,7 +59,6 @@ export async function getMultimodalCaption(base64Img, prompt) { | |||
| 59 | // Add Vertex AI specific parameters if using Vertex AI | 59 | // Add Vertex AI specific parameters if using Vertex AI |
| 60 | if (extension_settings.caption.multimodal_api === 'vertexai') { | 60 | if (extension_settings.caption.multimodal_api === 'vertexai') { |
| 61 | requestBody.vertexai_auth_mode = oai_settings.vertexai_auth_mode; | 61 | requestBody.vertexai_auth_mode = oai_settings.vertexai_auth_mode; |
| 62 | requestBody.vertexai_project_id = oai_settings.vertexai_project_id; | ||
| 63 | requestBody.vertexai_region = oai_settings.vertexai_region; | 62 | requestBody.vertexai_region = oai_settings.vertexai_region; |
| 64 | } | 63 | } |
| 65 | 64 | ||
| @@ -185,7 +184,7 @@ function throwIfInvalidModel(useReverseProxy) { | |||
| 185 | if (!secret_state[SECRET_KEYS.VERTEXAI_SERVICE_ACCOUNT]) { | 184 | if (!secret_state[SECRET_KEYS.VERTEXAI_SERVICE_ACCOUNT]) { |
| 186 | throw new Error('Service Account JSON is required for Vertex AI Full mode. Please validate and save your Service Account JSON.'); | 185 | throw new Error('Service Account JSON is required for Vertex AI Full mode. Please validate and save your Service Account JSON.'); |
| 187 | } | 186 | } |
| 188 | if (!oai_settings.vertexai_project_id) { | 187 | if (!secret_state[SECRET_KEYS.VERTEXAI_PROJECT_ID]) { |
| 189 | throw new Error('Project ID is required for Vertex AI Full mode.'); | 188 | throw new Error('Project ID is required for Vertex AI Full mode.'); |
| 190 | } | 189 | } |
| 191 | if (!oai_settings.vertexai_region) { | 190 | if (!oai_settings.vertexai_region) { |
| @@ -235,7 +235,6 @@ const sensitiveFields = [ | |||
| 235 | 'custom_include_body', | 235 | 'custom_include_body', |
| 236 | 'custom_exclude_body', | 236 | 'custom_exclude_body', |
| 237 | 'custom_include_headers', | 237 | 'custom_include_headers', |
| 238 | 'vertexai_project_id', | ||
| 239 | 'vertexai_region', | 238 | 'vertexai_region', |
| 240 | ]; | 239 | ]; |
| 241 | 240 | ||
| @@ -309,7 +308,6 @@ export const settingsToUpdate = { | |||
| 309 | claude_use_sysprompt: ['#claude_use_sysprompt', 'claude_use_sysprompt', true, false], | 308 | claude_use_sysprompt: ['#claude_use_sysprompt', 'claude_use_sysprompt', true, false], |
| 310 | use_makersuite_sysprompt: ['#use_makersuite_sysprompt', 'use_makersuite_sysprompt', true, false], | 309 | use_makersuite_sysprompt: ['#use_makersuite_sysprompt', 'use_makersuite_sysprompt', true, false], |
| 311 | vertexai_auth_mode: ['#vertexai_auth_mode', 'vertexai_auth_mode', false, true], | 310 | vertexai_auth_mode: ['#vertexai_auth_mode', 'vertexai_auth_mode', false, true], |
| 312 | vertexai_project_id: ['#vertexai_project_id', 'vertexai_project_id', false, true], | ||
| 313 | vertexai_region: ['#vertexai_region', 'vertexai_region', false, true], | 311 | vertexai_region: ['#vertexai_region', 'vertexai_region', false, true], |
| 314 | use_alt_scale: ['#use_alt_scale', 'use_alt_scale', true, true], | 312 | use_alt_scale: ['#use_alt_scale', 'use_alt_scale', true, true], |
| 315 | squash_system_messages: ['#squash_system_messages', 'squash_system_messages', true, false], | 313 | squash_system_messages: ['#squash_system_messages', 'squash_system_messages', true, false], |
| @@ -393,7 +391,6 @@ const default_settings = { | |||
| 393 | claude_use_sysprompt: false, | 391 | claude_use_sysprompt: false, |
| 394 | use_makersuite_sysprompt: true, | 392 | use_makersuite_sysprompt: true, |
| 395 | vertexai_auth_mode: 'express', | 393 | vertexai_auth_mode: 'express', |
| 396 | vertexai_project_id: '', | ||
| 397 | vertexai_region: 'us-central1', | 394 | vertexai_region: 'us-central1', |
| 398 | use_alt_scale: false, | 395 | use_alt_scale: false, |
| 399 | squash_system_messages: false, | 396 | squash_system_messages: false, |
| @@ -480,7 +477,6 @@ const oai_settings = { | |||
| 480 | claude_use_sysprompt: false, | 477 | claude_use_sysprompt: false, |
| 481 | use_makersuite_sysprompt: true, | 478 | use_makersuite_sysprompt: true, |
| 482 | vertexai_auth_mode: 'express', | 479 | vertexai_auth_mode: 'express', |
| 483 | vertexai_project_id: '', | ||
| 484 | vertexai_region: 'us-central1', | 480 | vertexai_region: 'us-central1', |
| 485 | use_alt_scale: false, | 481 | use_alt_scale: false, |
| 486 | squash_system_messages: false, | 482 | squash_system_messages: false, |
| @@ -2201,7 +2197,6 @@ async function sendOpenAIRequest(type, messages, signal) { | |||
| 2201 | generate_data['use_makersuite_sysprompt'] = oai_settings.use_makersuite_sysprompt; | 2197 | generate_data['use_makersuite_sysprompt'] = oai_settings.use_makersuite_sysprompt; |
| 2202 | if (isVertexAI) { | 2198 | if (isVertexAI) { |
| 2203 | generate_data['vertexai_auth_mode'] = oai_settings.vertexai_auth_mode; | 2199 | generate_data['vertexai_auth_mode'] = oai_settings.vertexai_auth_mode; |
| 2204 | generate_data['vertexai_project_id'] = oai_settings.vertexai_project_id; | ||
| 2205 | generate_data['vertexai_region'] = oai_settings.vertexai_region; | 2200 | generate_data['vertexai_region'] = oai_settings.vertexai_region; |
| 2206 | } | 2201 | } |
| 2207 | } | 2202 | } |
| @@ -3444,7 +3439,6 @@ function loadOpenAISettings(data, settings) { | |||
| 3444 | if (settings.claude_use_sysprompt !== undefined) oai_settings.claude_use_sysprompt = !!settings.claude_use_sysprompt; | 3439 | if (settings.claude_use_sysprompt !== undefined) oai_settings.claude_use_sysprompt = !!settings.claude_use_sysprompt; |
| 3445 | if (settings.use_makersuite_sysprompt !== undefined) oai_settings.use_makersuite_sysprompt = !!settings.use_makersuite_sysprompt; | 3440 | if (settings.use_makersuite_sysprompt !== undefined) oai_settings.use_makersuite_sysprompt = !!settings.use_makersuite_sysprompt; |
| 3446 | if (settings.vertexai_auth_mode !== undefined) oai_settings.vertexai_auth_mode = settings.vertexai_auth_mode; | 3441 | if (settings.vertexai_auth_mode !== undefined) oai_settings.vertexai_auth_mode = settings.vertexai_auth_mode; |
| 3447 | if (settings.vertexai_project_id !== undefined) oai_settings.vertexai_project_id = settings.vertexai_project_id; | ||
| 3448 | if (settings.vertexai_region !== undefined) oai_settings.vertexai_region = settings.vertexai_region; | 3442 | if (settings.vertexai_region !== undefined) oai_settings.vertexai_region = settings.vertexai_region; |
| 3449 | if (settings.use_alt_scale !== undefined) { oai_settings.use_alt_scale = !!settings.use_alt_scale; updateScaleForm(); } | 3443 | if (settings.use_alt_scale !== undefined) { oai_settings.use_alt_scale = !!settings.use_alt_scale; updateScaleForm(); } |
| 3450 | $('#stream_toggle').prop('checked', oai_settings.stream_openai); | 3444 | $('#stream_toggle').prop('checked', oai_settings.stream_openai); |
| @@ -3502,7 +3496,8 @@ function loadOpenAISettings(data, settings) { | |||
| 3502 | $('#claude_use_sysprompt').prop('checked', oai_settings.claude_use_sysprompt); | 3496 | $('#claude_use_sysprompt').prop('checked', oai_settings.claude_use_sysprompt); |
| 3503 | $('#use_makersuite_sysprompt').prop('checked', oai_settings.use_makersuite_sysprompt); | 3497 | $('#use_makersuite_sysprompt').prop('checked', oai_settings.use_makersuite_sysprompt); |
| 3504 | $('#vertexai_auth_mode').val(oai_settings.vertexai_auth_mode); | 3498 | $('#vertexai_auth_mode').val(oai_settings.vertexai_auth_mode); |
| 3505 | $('#vertexai_project_id').val(oai_settings.vertexai_project_id); | 3499 | // Don't display Project ID in input - it's stored in backend secrets |
| 3500 | $('#vertexai_project_id').val(''); | ||
| 3506 | $('#vertexai_region').val(oai_settings.vertexai_region); | 3501 | $('#vertexai_region').val(oai_settings.vertexai_region); |
| 3507 | // Don't display Service Account JSON in textarea - it's stored in backend secrets | 3502 | // Don't display Service Account JSON in textarea - it's stored in backend secrets |
| 3508 | $('#vertexai_service_account_json').val(''); | 3503 | $('#vertexai_service_account_json').val(''); |
| @@ -3830,7 +3825,6 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) { | |||
| 3830 | claude_use_sysprompt: settings.claude_use_sysprompt, | 3825 | claude_use_sysprompt: settings.claude_use_sysprompt, |
| 3831 | use_makersuite_sysprompt: settings.use_makersuite_sysprompt, | 3826 | use_makersuite_sysprompt: settings.use_makersuite_sysprompt, |
| 3832 | vertexai_auth_mode: settings.vertexai_auth_mode, | 3827 | vertexai_auth_mode: settings.vertexai_auth_mode, |
| 3833 | vertexai_project_id: settings.vertexai_project_id, | ||
| 3834 | vertexai_region: settings.vertexai_region, | 3828 | vertexai_region: settings.vertexai_region, |
| 3835 | use_alt_scale: settings.use_alt_scale, | 3829 | use_alt_scale: settings.use_alt_scale, |
| 3836 | squash_system_messages: settings.squash_system_messages, | 3830 | squash_system_messages: settings.squash_system_messages, |
| @@ -5021,11 +5015,20 @@ async function onConnectButtonClick(e) { | |||
| 5021 | } | 5015 | } |
| 5022 | } else { | 5016 | } else { |
| 5023 | // Full version - use service account | 5017 | // Full version - use service account |
| 5024 | if (!oai_settings.vertexai_project_id.trim()) { | 5018 | // Check if we have a saved project ID, otherwise use the input value |
| 5025 | toastr.error('Project ID is required for Vertex AI full version'); | 5019 | const savedProjectId = secret_state[SECRET_KEYS.VERTEXAI_PROJECT_ID]; |
| 5020 | const inputProjectId = String($('#vertexai_project_id').val()).trim(); | ||
| 5021 | |||
| 5022 | if (!savedProjectId && !inputProjectId) { | ||
| 5023 | toastr.error(t`Project ID is required for Vertex AI full version`); | ||
| 5026 | return; | 5024 | return; |
| 5027 | } | 5025 | } |
| 5028 | 5026 | ||
| 5027 | // Save project ID to secrets if we have an input value | ||
| 5028 | if (inputProjectId.length) { | ||
| 5029 | await writeSecret(SECRET_KEYS.VERTEXAI_PROJECT_ID, inputProjectId); | ||
| 5030 | } | ||
| 5031 | |||
| 5029 | // Check if service account JSON is saved in backend | 5032 | // Check if service account JSON is saved in backend |
| 5030 | if (!secret_state[SECRET_KEYS.VERTEXAI_SERVICE_ACCOUNT]) { | 5033 | if (!secret_state[SECRET_KEYS.VERTEXAI_SERVICE_ACCOUNT]) { |
| 5031 | toastr.error('Service Account JSON is required for Vertex AI full version. Please validate and save your Service Account JSON.'); | 5034 | toastr.error('Service Account JSON is required for Vertex AI full version. Please validate and save your Service Account JSON.'); |
| @@ -6128,10 +6131,6 @@ export function initOpenAI() { | |||
| 6128 | $('#model_google_select').on('change', onModelChange); | 6131 | $('#model_google_select').on('change', onModelChange); |
| 6129 | $('#model_vertexai_select').on('change', onModelChange); | 6132 | $('#model_vertexai_select').on('change', onModelChange); |
| 6130 | $('#vertexai_auth_mode').on('change', onVertexAIAuthModeChange); | 6133 | $('#vertexai_auth_mode').on('change', onVertexAIAuthModeChange); |
| 6131 | $('#vertexai_project_id').on('input', function () { | ||
| 6132 | oai_settings.vertexai_project_id = String($(this).val()); | ||
| 6133 | saveSettingsDebounced(); | ||
| 6134 | }); | ||
| 6135 | $('#vertexai_region').on('input', function () { | 6134 | $('#vertexai_region').on('input', function () { |
| 6136 | oai_settings.vertexai_region = String($(this).val()); | 6135 | oai_settings.vertexai_region = String($(this).val()); |
| 6137 | saveSettingsDebounced(); | 6136 | saveSettingsDebounced(); |
| @@ -44,6 +44,7 @@ export const SECRET_KEYS = { | |||
| 44 | SERPER: 'api_key_serper', | 44 | SERPER: 'api_key_serper', |
| 45 | FALAI: 'api_key_falai', | 45 | FALAI: 'api_key_falai', |
| 46 | XAI: 'api_key_xai', | 46 | XAI: 'api_key_xai', |
| 47 | VERTEXAI_PROJECT_ID: 'vertexai_project_id', | ||
| 47 | VERTEXAI_SERVICE_ACCOUNT: 'vertexai_service_account_json', | 48 | VERTEXAI_SERVICE_ACCOUNT: 'vertexai_service_account_json', |
| 48 | }; | 49 | }; |
| 49 | 50 | ||
| @@ -527,7 +527,12 @@ async function sendMakerSuiteRequest(request, response) { | |||
| 527 | url = `${apiUrl.toString().replace(/\/$/, '')}/v1/publishers/google/models/${model}:${responseType}?key=${keyParam}${stream ? '&alt=sse' : ''}`; | 527 | url = `${apiUrl.toString().replace(/\/$/, '')}/v1/publishers/google/models/${model}:${responseType}?key=${keyParam}${stream ? '&alt=sse' : ''}`; |
| 528 | } else if (authType === 'full') { | 528 | } else if (authType === 'full') { |
| 529 | // For Full mode (service account authentication), use project-specific URL | 529 | // For Full mode (service account authentication), use project-specific URL |
| 530 | const projectId = request.body.vertexai_project_id || 'your-project-id'; | 530 | // Only use project ID from secrets |
| 531 | const projectId = readSecret(request.user.directories, SECRET_KEYS.VERTEXAI_PROJECT_ID); | ||
| 532 | if (!projectId) { | ||
| 533 | console.warn('Vertex AI project ID is missing.'); | ||
| 534 | return response.status(400).send({ error: true }); | ||
| 535 | } | ||
| 531 | const region = request.body.vertexai_region || 'us-central1'; | 536 | const region = request.body.vertexai_region || 'us-central1'; |
| 532 | // Handle global region differently - no region prefix in hostname | 537 | // Handle global region differently - no region prefix in hostname |
| 533 | if (region === 'global') { | 538 | if (region === 'global') { |
| @@ -133,7 +133,11 @@ router.post('/caption-image', async (request, response) => { | |||
| 133 | url = `${apiUrl.origin}/v1/publishers/google/models/${model}:generateContent?key=${keyParam}`; | 133 | url = `${apiUrl.origin}/v1/publishers/google/models/${model}:generateContent?key=${keyParam}`; |
| 134 | } else if (authType === 'full') { | 134 | } else if (authType === 'full') { |
| 135 | // Full mode: use project-specific URL with Authorization header | 135 | // Full mode: use project-specific URL with Authorization header |
| 136 | const projectId = request.body.vertexai_project_id || 'your-project-id'; | 136 | const projectId = readSecret(request.user.directories, SECRET_KEYS.VERTEXAI_PROJECT_ID); |
| 137 | if (!projectId) { | ||
| 138 | console.warn('Vertex AI project ID is missing.'); | ||
| 139 | return response.status(400).send({ error: true }); | ||
| 140 | } | ||
| 137 | const region = request.body.vertexai_region || 'us-central1'; | 141 | const region = request.body.vertexai_region || 'us-central1'; |
| 138 | // Handle global region differently - no region prefix in hostname | 142 | // Handle global region differently - no region prefix in hostname |
| 139 | if (region === 'global') { | 143 | if (region === 'global') { |
| @@ -54,6 +54,7 @@ export const SECRET_KEYS = { | |||
| 54 | DEEPSEEK: 'api_key_deepseek', | 54 | DEEPSEEK: 'api_key_deepseek', |
| 55 | SERPER: 'api_key_serper', | 55 | SERPER: 'api_key_serper', |
| 56 | XAI: 'api_key_xai', | 56 | XAI: 'api_key_xai', |
| 57 | VERTEXAI_PROJECT_ID: 'vertexai_project_id', | ||
| 57 | VERTEXAI_SERVICE_ACCOUNT: 'vertexai_service_account_json', | 58 | VERTEXAI_SERVICE_ACCOUNT: 'vertexai_service_account_json', |
| 58 | }; | 59 | }; |
| 59 | 60 | ||