Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions packages/types/src/provider-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ const vertexSchema = apiModelIdProviderModelSchema.extend({
vertexJsonCredentials: z.string().optional(),
vertexProjectId: z.string().optional(),
vertexRegion: z.string().optional(),
enableUrlContext: z.boolean().optional(),
enableGrounding: z.boolean().optional(),
vertex1MContext: z.boolean().optional(), // Enable 'context-1m-2025-08-07' beta for 1M context window.
})

Expand Down Expand Up @@ -273,8 +271,6 @@ const lmStudioSchema = baseProviderSettingsSchema.extend({
const geminiSchema = apiModelIdProviderModelSchema.extend({
geminiApiKey: z.string().optional(),
googleGeminiBaseUrl: z.string().optional(),
enableUrlContext: z.boolean().optional(),
enableGrounding: z.boolean().optional(),
})

const geminiCliSchema = apiModelIdProviderModelSchema.extend({
Expand Down
37 changes: 2 additions & 35 deletions src/api/providers/__tests__/gemini-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ describe("GeminiHandler backend support", () => {
it("createMessage uses AI SDK tools format", async () => {
const options = {
apiProvider: "gemini",
enableUrlContext: true,
enableGrounding: true,
} as ApiHandlerOptions
const handler = new GeminiHandler(options)

Expand All @@ -50,36 +48,9 @@ describe("GeminiHandler backend support", () => {
)
})

it("completePrompt passes tools when URL context and grounding enabled", async () => {
it("completePrompt generates text without tools", async () => {
const options = {
apiProvider: "gemini",
enableUrlContext: true,
enableGrounding: true,
} as ApiHandlerOptions
const handler = new GeminiHandler(options)

mockGenerateText.mockResolvedValue({
text: "ok",
providerMetadata: {},
})

const res = await handler.completePrompt("hi")
expect(res).toBe("ok")

// Verify generateText was called with tools
expect(mockGenerateText).toHaveBeenCalledWith(
expect.objectContaining({
prompt: "hi",
tools: expect.any(Object),
}),
)
})

it("completePrompt passes config overrides without tools when URL context and grounding disabled", async () => {
const options = {
apiProvider: "gemini",
enableUrlContext: false,
enableGrounding: false,
} as ApiHandlerOptions
const handler = new GeminiHandler(options)

Expand All @@ -100,7 +71,6 @@ describe("GeminiHandler backend support", () => {
it("should handle grounding metadata extraction failure gracefully", async () => {
const options = {
apiProvider: "gemini",
enableGrounding: true,
} as ApiHandlerOptions
const handler = new GeminiHandler(options)

Expand Down Expand Up @@ -134,7 +104,6 @@ describe("GeminiHandler backend support", () => {
it("should handle malformed grounding metadata", async () => {
const options = {
apiProvider: "gemini",
enableGrounding: true,
} as ApiHandlerOptions
const handler = new GeminiHandler(options)

Expand Down Expand Up @@ -181,11 +150,9 @@ describe("GeminiHandler backend support", () => {
}
})

it("should handle API errors when tools are enabled", async () => {
it("should handle API errors", async () => {
const options = {
apiProvider: "gemini",
enableUrlContext: true,
enableGrounding: true,
} as ApiHandlerOptions
const handler = new GeminiHandler(options)

Expand Down
61 changes: 1 addition & 60 deletions src/api/providers/__tests__/vertex.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@ vitest.mock("vscode", () => ({}))

// Mock the createVertex function from @ai-sdk/google-vertex
const mockCreateVertex = vitest.fn()
const mockGoogleSearchTool = vitest.fn()
const mockUrlContextTool = vitest.fn()

vitest.mock("@ai-sdk/google-vertex", () => ({
createVertex: (...args: unknown[]) => {
mockCreateVertex(...args)
const provider = Object.assign((modelId: string) => ({ modelId }), {
tools: {
googleSearch: mockGoogleSearchTool,
urlContext: mockUrlContextTool,
},
tools: {},
})
return provider
},
Expand Down Expand Up @@ -48,8 +43,6 @@ describe("VertexHandler", () => {
mockStreamText.mockClear()
mockGenerateText.mockClear()
mockCreateVertex.mockClear()
mockGoogleSearchTool.mockClear()
mockUrlContextTool.mockClear()

handler = new VertexHandler({
apiModelId: "gemini-1.5-pro-001",
Expand Down Expand Up @@ -241,58 +234,6 @@ describe("VertexHandler", () => {
const result = await handler.completePrompt("Test prompt")
expect(result).toBe("")
})

it("should add Google Search tool when grounding is enabled", async () => {
const handlerWithGrounding = new VertexHandler({
apiModelId: "gemini-1.5-pro-001",
vertexProjectId: "test-project",
vertexRegion: "us-central1",
enableGrounding: true,
})

mockGenerateText.mockResolvedValue({
text: "Search result",
providerMetadata: {},
})
mockGoogleSearchTool.mockReturnValue({ type: "googleSearch" })

await handlerWithGrounding.completePrompt("Search query")

expect(mockGoogleSearchTool).toHaveBeenCalledWith({})
expect(mockGenerateText).toHaveBeenCalledWith(
expect.objectContaining({
tools: expect.objectContaining({
google_search: { type: "googleSearch" },
}),
}),
)
})

it("should add URL Context tool when enabled", async () => {
const handlerWithUrlContext = new VertexHandler({
apiModelId: "gemini-1.5-pro-001",
vertexProjectId: "test-project",
vertexRegion: "us-central1",
enableUrlContext: true,
})

mockGenerateText.mockResolvedValue({
text: "URL context result",
providerMetadata: {},
})
mockUrlContextTool.mockReturnValue({ type: "urlContext" })

await handlerWithUrlContext.completePrompt("Fetch URL")

expect(mockUrlContextTool).toHaveBeenCalledWith({})
expect(mockGenerateText).toHaveBeenCalledWith(
expect.objectContaining({
tools: expect.objectContaining({
url_context: { type: "urlContext" },
}),
}),
)
})
})

describe("getModel", () => {
Expand Down
15 changes: 0 additions & 15 deletions src/api/providers/gemini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,20 +286,6 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
const { id: modelId, info } = this.getModel()

try {
// Build tools for grounding - cast to any to bypass strict typing
// Google provider tools have a different shape than standard ToolSet
const tools: Record<string, any> = {}

// Add URL context tool if enabled
if (this.options.enableUrlContext) {
tools.url_context = this.provider.tools.urlContext({})
}

// Add Google Search grounding tool if enabled
if (this.options.enableGrounding) {
tools.google_search = this.provider.tools.googleSearch({})
}

const supportsTemperature = info.supportsTemperature !== false
const temperatureConfig: number | undefined = supportsTemperature
? (this.options.modelTemperature ?? info.defaultTemperature ?? 1)
Expand All @@ -309,7 +295,6 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
model: this.provider(modelId),
prompt,
temperature: temperatureConfig,
...(Object.keys(tools).length > 0 && { tools: tools as ToolSet }),
})

let text = result.text ?? ""
Expand Down
15 changes: 0 additions & 15 deletions src/api/providers/vertex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,20 +303,6 @@ export class VertexHandler extends BaseProvider implements SingleCompletionHandl
const { id: modelId, info } = this.getModel()

try {
// Build tools for grounding - cast to any to bypass strict typing
// Google provider tools have a different shape than standard ToolSet
const tools: Record<string, any> = {}

// Add URL context tool if enabled
if (this.options.enableUrlContext) {
tools.url_context = this.provider.tools.urlContext({})
}

// Add Google Search grounding tool if enabled
if (this.options.enableGrounding) {
tools.google_search = this.provider.tools.googleSearch({})
}

const supportsTemperature = info.supportsTemperature !== false
const temperatureConfig: number | undefined = supportsTemperature
? (this.options.modelTemperature ?? info.defaultTemperature ?? 1)
Expand All @@ -326,7 +312,6 @@ export class VertexHandler extends BaseProvider implements SingleCompletionHandl
model: this.provider(modelId),
prompt,
temperature: temperatureConfig,
...(Object.keys(tools).length > 0 && { tools: tools as ToolSet }),
})

let text = result.text ?? ""
Expand Down
1 change: 0 additions & 1 deletion src/core/task/__tests__/grounding-sources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ describe("Task grounding sources handling", () => {
mockApiConfiguration = {
apiProvider: "gemini",
geminiApiKey: "test-key",
enableGrounding: true,
} as ProviderSettings
})

Expand Down
12 changes: 2 additions & 10 deletions webview-ui/src/components/settings/ApiOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -601,19 +601,11 @@ const ApiOptions = ({
)}

{selectedProvider === "vertex" && (
<Vertex
apiConfiguration={apiConfiguration}
setApiConfigurationField={setApiConfigurationField}
simplifySettings={fromWelcomeView}
/>
<Vertex apiConfiguration={apiConfiguration} setApiConfigurationField={setApiConfigurationField} />
)}

{selectedProvider === "gemini" && (
<Gemini
apiConfiguration={apiConfiguration}
setApiConfigurationField={setApiConfigurationField}
simplifySettings={fromWelcomeView}
/>
<Gemini apiConfiguration={apiConfiguration} setApiConfigurationField={setApiConfigurationField} />
)}

{selectedProvider === "openai" && (
Expand Down
28 changes: 1 addition & 27 deletions webview-ui/src/components/settings/providers/Gemini.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import { inputEventTransform } from "../transforms"
type GeminiProps = {
apiConfiguration: ProviderSettings
setApiConfigurationField: (field: keyof ProviderSettings, value: ProviderSettings[keyof ProviderSettings]) => void
simplifySettings?: boolean
}

export const Gemini = ({ apiConfiguration, setApiConfigurationField, simplifySettings }: GeminiProps) => {
export const Gemini = ({ apiConfiguration, setApiConfigurationField }: GeminiProps) => {
const { t } = useAppTranslation()

const [googleGeminiBaseUrlSelected, setGoogleGeminiBaseUrlSelected] = useState(
Expand Down Expand Up @@ -73,31 +72,6 @@ export const Gemini = ({ apiConfiguration, setApiConfigurationField, simplifySet
className="w-full mt-1"
/>
)}

{!simplifySettings && (
<>
<Checkbox
className="mt-6"
data-testid="checkbox-url-context"
checked={!!apiConfiguration.enableUrlContext}
onChange={(checked: boolean) => setApiConfigurationField("enableUrlContext", checked)}>
{t("settings:providers.geminiParameters.urlContext.title")}
</Checkbox>
<div className="text-sm text-vscode-descriptionForeground mb-3 mt-1.5">
{t("settings:providers.geminiParameters.urlContext.description")}
</div>

<Checkbox
data-testid="checkbox-grounding-search"
checked={!!apiConfiguration.enableGrounding}
onChange={(checked: boolean) => setApiConfigurationField("enableGrounding", checked)}>
{t("settings:providers.geminiParameters.groundingSearch.title")}
</Checkbox>
<div className="text-sm text-vscode-descriptionForeground mb-3 mt-1.5">
{t("settings:providers.geminiParameters.groundingSearch.description")}
</div>
</>
)}
</div>
</>
)
Expand Down
27 changes: 1 addition & 26 deletions webview-ui/src/components/settings/providers/Vertex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import { inputEventTransform } from "../transforms"
type VertexProps = {
apiConfiguration: ProviderSettings
setApiConfigurationField: (field: keyof ProviderSettings, value: ProviderSettings[keyof ProviderSettings]) => void
simplifySettings?: boolean
}

export const Vertex = ({ apiConfiguration, setApiConfigurationField, simplifySettings }: VertexProps) => {
export const Vertex = ({ apiConfiguration, setApiConfigurationField }: VertexProps) => {
const { t } = useAppTranslation()

// Check if the selected model supports 1M context (supported Claude 4 models)
Expand Down Expand Up @@ -116,30 +115,6 @@ export const Vertex = ({ apiConfiguration, setApiConfigurationField, simplifySet
</div>
</div>
)}

{!simplifySettings && apiConfiguration.apiModelId?.startsWith("gemini") && (
<div className="mt-6">
<Checkbox
data-testid="checkbox-url-context"
checked={!!apiConfiguration.enableUrlContext}
onChange={(checked: boolean) => setApiConfigurationField("enableUrlContext", checked)}>
{t("settings:providers.geminiParameters.urlContext.title")}
</Checkbox>
<div className="text-sm text-vscode-descriptionForeground mb-3 mt-1.5">
{t("settings:providers.geminiParameters.urlContext.description")}
</div>

<Checkbox
data-testid="checkbox-grounding-search"
checked={!!apiConfiguration.enableGrounding}
onChange={(checked: boolean) => setApiConfigurationField("enableGrounding", checked)}>
{t("settings:providers.geminiParameters.groundingSearch.title")}
</Checkbox>
<div className="text-sm text-vscode-descriptionForeground mb-3 mt-1.5">
{t("settings:providers.geminiParameters.groundingSearch.description")}
</div>
</div>
)}
</>
)
}
Loading
Loading