Skip to content

Conversation

narengogi
Copy link
Collaborator

No description provided.

@narengogi narengogi marked this pull request as draft September 17, 2025 12:59
Copy link
Contributor

matter-code-review bot commented Sep 17, 2025

Code Quality

Description

Summary By MatterAI MatterAI logo

🔄 What Changed

  • Removed a redundant blank line in src/providers/google-vertex-ai/api.ts.

🔍 Impact of the Change

  • No functional impact; purely a cosmetic cleanup for code readability.

📁 Total Files Changed

  • src/providers/google-vertex-ai/api.ts: Removed one blank line.

🧪 Test Added

  • N/A

🔒Security Vulnerabilities

  • N/A

Motivation

N/A

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)

How Has This Been Tested?

  • Unit Tests
  • Integration Tests
  • Manual Testing

Screenshots (if applicable)

N/A

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Related Issues

N/A

Tanka Poem ♫

A blank line removed,
Code now breathes, a cleaner sight.
No function altered,
Just tidiness, a quiet grace,
Science finds beauty in space. ✨

Sequence Diagram

N/A
Loading

Copy link
Contributor

@matter-code-review matter-code-review bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code cleanup and minor improvements in Vertex AI API implementation

Comment on lines 2 to 10
constructor(
message: string,
public status: number = 500,
public cause?: Error
) {
super(message);
this.name = 'GatewayError';
this.status = status;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛 Bug Fix

Issue: Redundant assignment of status property in constructor
Fix: Remove redundant assignment since it's already initialized in parameter
Impact: Cleaner code, no functional change

Suggested change
constructor(
message: string,
public status: number = 500,
public cause?: Error
) {
super(message);
this.name = 'GatewayError';
this.status = status;
}
constructor(
message: string,
public status: number = 500,
public cause?: Error
) {
super(message);
this.name = 'GatewayError';
}

}),
{
status: 500,
status: error instanceof GatewayError ? error.status : 500,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Code Refactor

Issue: Hardcoded error status code
Fix: Use status from GatewayError if available, otherwise default to 500
Impact: More accurate error status propagation

Suggested change
status: error instanceof GatewayError ? error.status : 500,
status: error instanceof GatewayError ? error.status : 500,

import { getModelAndProvider, getAccessToken, getBucketAndFile } from './utils';

const getApiVersion = (provider: string, inputModel: string) => {
const getApiVersion = (provider: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Code Refactor

Issue: Unused parameter inputModel in getApiVersion function
Fix: Remove unused parameter
Impact: Cleaner function signature

Suggested change
const getApiVersion = (provider: string) => {
const getApiVersion = (provider: string) => {

} = providerOptions;
let projectId = inputProjectId;
if (vertexServiceAccountJson && vertexServiceAccountJson.project_id) {
if (vertexServiceAccountJson?.project_id) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Code Refactor

Issue: Unnecessary explicit check for nested property
Fix: Use optional chaining for cleaner code
Impact: More concise and readable code

Suggested change
if (vertexServiceAccountJson?.project_id) {
if (vertexServiceAccountJson?.project_id) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved: Previous suggestion was for optional chaining which is not needed as the code already handles null case correctly


const { provider } = getModelAndProvider(inputModel as string);
let routeVersion = getApiVersion(provider, inputModel as string);
const routeVersion = getApiVersion(provider);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Code Refactor

Issue: Unused parameter in function call
Fix: Remove unused inputModel parameter
Impact: Cleaner function call

Suggested change
const routeVersion = getApiVersion(provider);
const routeVersion = getApiVersion(provider);


const url = new URL(gatewayRequestURL);
const searchParams = url.searchParams;
const searchParams = new URLSearchParams(url.search);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Code Refactor

Issue: Inconsistent URL search params initialization
Fix: Use new URLSearchParams(url.search) for consistency
Impact: More consistent code pattern

Suggested change
const searchParams = new URLSearchParams(url.search);
const searchParams = new URLSearchParams(url.search);

Comment on lines +143 to +144
default:
return '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Code Refactor

Issue: Missing default case in switch statement
Fix: Add default case returning empty string
Impact: Prevents potential undefined returns

Suggested change
default:
return '';
default:
return '';

Comment on lines +148 to +150
if (!inputModel) {
throw new GatewayError('Model is required', 400);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security Issue Fix

Issue: Missing model validation could lead to unexpected behavior
Fix: Add explicit model validation with GatewayError
Impact: Prevents processing requests without required model parameter

Suggested change
if (!inputModel) {
throw new GatewayError('Model is required', 400);
}
if (!inputModel) {
throw new GatewayError('Model is required', 400);
}

} else if (mappedFn === 'messagesCountTokens') {
return `${projectRoute}/publishers/${provider}/models/count-tokens:rawPredict`;
}
return `${projectRoute}/publishers/${provider}/models/${model}:rawPredict`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Code Refactor

Issue: Missing default return in switch statement
Fix: Add default return for rawPredict endpoint
Impact: Ensures consistent return value

Suggested change
return `${projectRoute}/publishers/${provider}/models/${model}:rawPredict`;
return `${projectRoute}/publishers/${provider}/models/${model}:rawPredict`;

@narengogi narengogi marked this pull request as ready for review September 17, 2025 13:48
Copy link
Contributor

Code cleanup and image edit endpoint support added across multiple providers

Copy link
Contributor

Minor cleanup in Vertex AI API header construction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant