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 | 59 | // Add Vertex AI specific parameters if using Vertex AI |
| 60 | 60 | if (extension_settings.caption.multimodal_api === 'vertexai') { |
| 61 | 61 | requestBody.vertexai_auth_mode = oai_settings.vertexai_auth_mode; |
| 62 | - requestBody.vertexai_project_id = oai_settings.vertexai_project_id; | |
| 63 | 62 | requestBody.vertexai_region = oai_settings.vertexai_region; |
| 64 | 63 | } |
| 65 | 64 | |
| @@ -185,7 +184,7 @@ function throwIfInvalidModel(useReverseProxy) { | ||
| 185 | 184 | if (!secret_state[SECRET_KEYS.VERTEXAI_SERVICE_ACCOUNT]) { |
| 186 | 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 | 187 | if (!oai_settingssecret_state[SECRET_KEYS.vertexai_project_idVERTEXAI_PROJECT_ID]) { |
| 189 | 188 | throw new Error('Project ID is required for Vertex AI Full mode.'); |
| 190 | 189 | } |
| 191 | 190 | if (!oai_settings.vertexai_region) { |
| @@ -235,7 +235,6 @@ const sensitiveFields = [ | ||
| 235 | 235 | 'custom_include_body', |
| 236 | 236 | 'custom_exclude_body', |
| 237 | 237 | 'custom_include_headers', |
| 238 | - 'vertexai_project_id', | |
| 239 | 238 | 'vertexai_region', |
| 240 | 239 | ]; |
| 241 | 240 | |
| @@ -309,7 +308,6 @@ export const settingsToUpdate = { | ||
| 309 | 308 | claude_use_sysprompt: ['#claude_use_sysprompt', 'claude_use_sysprompt', true, false], |
| 310 | 309 | use_makersuite_sysprompt: ['#use_makersuite_sysprompt', 'use_makersuite_sysprompt', true, false], |
| 311 | 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 | 311 | vertexai_region: ['#vertexai_region', 'vertexai_region', false, true], |
| 314 | 312 | use_alt_scale: ['#use_alt_scale', 'use_alt_scale', true, true], |
| 315 | 313 | squash_system_messages: ['#squash_system_messages', 'squash_system_messages', true, false], |
| @@ -393,7 +391,6 @@ const default_settings = { | ||
| 393 | 391 | claude_use_sysprompt: false, |
| 394 | 392 | use_makersuite_sysprompt: true, |
| 395 | 393 | vertexai_auth_mode: 'express', |
| 396 | - vertexai_project_id: '', | |
| 397 | 394 | vertexai_region: 'us-central1', |
| 398 | 395 | use_alt_scale: false, |
| 399 | 396 | squash_system_messages: false, |
| @@ -480,7 +477,6 @@ const oai_settings = { | ||
| 480 | 477 | claude_use_sysprompt: false, |
| 481 | 478 | use_makersuite_sysprompt: true, |
| 482 | 479 | vertexai_auth_mode: 'express', |
| 483 | - vertexai_project_id: '', | |
| 484 | 480 | vertexai_region: 'us-central1', |
| 485 | 481 | use_alt_scale: false, |
| 486 | 482 | squash_system_messages: false, |
| @@ -2201,7 +2197,6 @@ async function sendOpenAIRequest(type, messages, signal) { | ||
| 2201 | 2197 | generate_data['use_makersuite_sysprompt'] = oai_settings.use_makersuite_sysprompt; |
| 2202 | 2198 | if (isVertexAI) { |
| 2203 | 2199 | generate_data['vertexai_auth_mode'] = oai_settings.vertexai_auth_mode; |
| 2204 | - generate_data['vertexai_project_id'] = oai_settings.vertexai_project_id; | |
| 2205 | 2200 | generate_data['vertexai_region'] = oai_settings.vertexai_region; |
| 2206 | 2201 | } |
| 2207 | 2202 | } |
| @@ -3444,7 +3439,6 @@ function loadOpenAISettings(data, settings) { | ||
| 3444 | 3439 | if (settings.claude_use_sysprompt !== undefined) oai_settings.claude_use_sysprompt = !!settings.claude_use_sysprompt; |
| 3445 | 3440 | if (settings.use_makersuite_sysprompt !== undefined) oai_settings.use_makersuite_sysprompt = !!settings.use_makersuite_sysprompt; |
| 3446 | 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 | 3442 | if (settings.vertexai_region !== undefined) oai_settings.vertexai_region = settings.vertexai_region; |
| 3449 | 3443 | if (settings.use_alt_scale !== undefined) { oai_settings.use_alt_scale = !!settings.use_alt_scale; updateScaleForm(); } |
| 3450 | 3444 | $('#stream_toggle').prop('checked', oai_settings.stream_openai); |
| @@ -3502,7 +3496,8 @@ function loadOpenAISettings(data, settings) { | ||
| 3502 | 3496 | $('#claude_use_sysprompt').prop('checked', oai_settings.claude_use_sysprompt); |
| 3503 | 3497 | $('#use_makersuite_sysprompt').prop('checked', oai_settings.use_makersuite_sysprompt); |
| 3504 | 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 | 3501 | $('#vertexai_region').val(oai_settings.vertexai_region); |
| 3507 | 3502 | // Don't display Service Account JSON in textarea - it's stored in backend secrets |
| 3508 | 3503 | $('#vertexai_service_account_json').val(''); |
| @@ -3830,7 +3825,6 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) { | ||
| 3830 | 3825 | claude_use_sysprompt: settings.claude_use_sysprompt, |
| 3831 | 3826 | use_makersuite_sysprompt: settings.use_makersuite_sysprompt, |
| 3832 | 3827 | vertexai_auth_mode: settings.vertexai_auth_mode, |
| 3833 | - vertexai_project_id: settings.vertexai_project_id, | |
| 3834 | 3828 | vertexai_region: settings.vertexai_region, |
| 3835 | 3829 | use_alt_scale: settings.use_alt_scale, |
| 3836 | 3830 | squash_system_messages: settings.squash_system_messages, |
| @@ -5021,11 +5015,20 @@ async function onConnectButtonClick(e) { | ||
| 5021 | 5015 | } |
| 5022 | 5016 | } else { |
| 5023 | 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 | 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 | 5032 | // Check if service account JSON is saved in backend |
| 5030 | 5033 | if (!secret_state[SECRET_KEYS.VERTEXAI_SERVICE_ACCOUNT]) { |
| 5031 | 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 | 6131 | $('#model_google_select').on('change', onModelChange); |
| 6129 | 6132 | $('#model_vertexai_select').on('change', onModelChange); |
| 6130 | 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 | 6134 | $('#vertexai_region').on('input', function () { |
| 6136 | 6135 | oai_settings.vertexai_region = String($(this).val()); |
| 6137 | 6136 | saveSettingsDebounced(); |
| @@ -44,6 +44,7 @@ export const SECRET_KEYS = { | ||
| 44 | 44 | SERPER: 'api_key_serper', |
| 45 | 45 | FALAI: 'api_key_falai', |
| 46 | 46 | XAI: 'api_key_xai', |
| 47 | + VERTEXAI_PROJECT_ID: 'vertexai_project_id', | |
| 47 | 48 | VERTEXAI_SERVICE_ACCOUNT: 'vertexai_service_account_json', |
| 48 | 49 | }; |
| 49 | 50 | |
| @@ -527,7 +527,12 @@ async function sendMakerSuiteRequest(request, response) { | ||
| 527 | 527 | url = `${apiUrl.toString().replace(/\/$/, '')}/v1/publishers/google/models/${model}:${responseType}?key=${keyParam}${stream ? '&alt=sse' : ''}`; |
| 528 | 528 | } else if (authType === 'full') { |
| 529 | 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 | 536 | const region = request.body.vertexai_region || 'us-central1'; |
| 532 | 537 | // Handle global region differently - no region prefix in hostname |
| 533 | 538 | if (region === 'global') { |
| @@ -133,7 +133,11 @@ router.post('/caption-image', async (request, response) => { | ||
| 133 | 133 | url = `${apiUrl.origin}/v1/publishers/google/models/${model}:generateContent?key=${keyParam}`; |
| 134 | 134 | } else if (authType === 'full') { |
| 135 | 135 | // Full mode: use project-specific URL with Authorization header |
| 136 | 136 | const projectId = readSecret(request.bodyuser.vertexai_project_id ||directories, 'your-project-id'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 | 141 | const region = request.body.vertexai_region || 'us-central1'; |
| 138 | 142 | // Handle global region differently - no region prefix in hostname |
| 139 | 143 | if (region === 'global') { |
| @@ -54,6 +54,7 @@ export const SECRET_KEYS = { | ||
| 54 | 54 | DEEPSEEK: 'api_key_deepseek', |
| 55 | 55 | SERPER: 'api_key_serper', |
| 56 | 56 | XAI: 'api_key_xai', |
| 57 | + VERTEXAI_PROJECT_ID: 'vertexai_project_id', | |
| 57 | 58 | VERTEXAI_SERVICE_ACCOUNT: 'vertexai_service_account_json', |
| 58 | 59 | }; |
| 59 | 60 | |