Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
85 changes: 84 additions & 1 deletion packages/types/src/__tests__/provider-settings.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,87 @@
import { getApiProtocol } from "../provider-settings.js"
import { getApiProtocol, providerSettingsSchema } from "../provider-settings.js"

describe("Ollama Settings Schema", () => {
it("should accept valid ollamaRequestTimeout", () => {
const result = providerSettingsSchema.safeParse({
ollamaRequestTimeout: 3600000,
})
expect(result.success).toBe(true)
})

it("should reject ollamaRequestTimeout below minimum", () => {
const result = providerSettingsSchema.safeParse({
ollamaRequestTimeout: 500,
})
expect(result.success).toBe(false)
})

it("should reject ollamaRequestTimeout above maximum", () => {
const result = providerSettingsSchema.safeParse({
ollamaRequestTimeout: 8000000,
})
expect(result.success).toBe(false)
})

it("should accept valid ollamaModelDiscoveryTimeout", () => {
const result = providerSettingsSchema.safeParse({
ollamaModelDiscoveryTimeout: 10000,
})
expect(result.success).toBe(true)
})

it("should reject ollamaModelDiscoveryTimeout above maximum", () => {
const result = providerSettingsSchema.safeParse({
ollamaModelDiscoveryTimeout: 700000,
})
expect(result.success).toBe(false)
})

it("should accept valid ollamaMaxRetries", () => {
const result = providerSettingsSchema.safeParse({
ollamaMaxRetries: 3,
})
expect(result.success).toBe(true)
})

it("should reject ollamaMaxRetries above maximum", () => {
const result = providerSettingsSchema.safeParse({
ollamaMaxRetries: 15,
})
expect(result.success).toBe(false)
})

it("should accept valid ollamaRetryDelay", () => {
const result = providerSettingsSchema.safeParse({
ollamaRetryDelay: 2000,
})
expect(result.success).toBe(true)
})

it("should reject ollamaRetryDelay below minimum", () => {
const result = providerSettingsSchema.safeParse({
ollamaRetryDelay: 50,
})
expect(result.success).toBe(false)
})

it("should accept ollamaEnableLogging boolean", () => {
const result = providerSettingsSchema.safeParse({
ollamaEnableLogging: true,
})
expect(result.success).toBe(true)
})

it("should accept all optional fields together", () => {
const result = providerSettingsSchema.safeParse({
ollamaRequestTimeout: 3600000,
ollamaModelDiscoveryTimeout: 10000,
ollamaMaxRetries: 2,
ollamaRetryDelay: 1000,
ollamaEnableLogging: true,
})
expect(result.success).toBe(true)
})
})

describe("getApiProtocol", () => {
describe("Anthropic-style providers", () => {
Expand Down
5 changes: 5 additions & 0 deletions packages/types/src/provider-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ const ollamaSchema = baseProviderSettingsSchema.extend({
ollamaBaseUrl: z.string().optional(),
ollamaApiKey: z.string().optional(),
ollamaNumCtx: z.number().int().min(128).optional(),
ollamaRequestTimeout: z.number().int().min(1000).max(7200000).optional(),
ollamaModelDiscoveryTimeout: z.number().int().min(1000).max(600000).optional(),
ollamaMaxRetries: z.number().int().min(0).max(10).optional(),
ollamaRetryDelay: z.number().int().min(100).max(10000).optional(),
ollamaEnableLogging: z.boolean().optional(),
})

const vsCodeLmSchema = baseProviderSettingsSchema.extend({
Expand Down
20 changes: 20 additions & 0 deletions packages/types/src/vscode-extension-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export interface ExtensionMessage {
| "routerModels"
| "openAiModels"
| "ollamaModels"
| "ollamaConnectionTestResult"
| "ollamaModelsRefreshResult"
| "lmStudioModels"
| "vsCodeLmModels"
| "vsCodeLmApiAvailable"
Expand Down Expand Up @@ -136,6 +138,20 @@ export interface ExtensionMessage {
routerModels?: RouterModels
openAiModels?: string[]
ollamaModels?: ModelRecord
ollamaModelsWithTools?: Array<{
name: string
contextWindow: number
size?: number
quantizationLevel?: string
family?: string
supportsImages: boolean
modelInfo: ModelRecord[string]
}>
modelsWithoutTools?: string[]
message?: string
messageCode?: string
messageParams?: Record<string, string>
durationMs?: number
lmStudioModels?: ModelRecord
vsCodeLmModels?: { vendor?: string; family?: string; version?: string; id?: string }[]
mcpServers?: McpServer[]
Expand Down Expand Up @@ -435,6 +451,8 @@ export interface WebviewMessage {
| "requestRouterModels"
| "requestOpenAiModels"
| "requestOllamaModels"
| "testOllamaConnection"
| "refreshOllamaModels"
| "requestLmStudioModels"
| "requestRooModels"
| "requestRooCreditBalance"
Expand Down Expand Up @@ -629,6 +647,8 @@ export interface WebviewMessage {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
settings?: any
url?: string // For openExternal
ollamaBaseUrl?: string // For testOllamaConnection and refreshOllamaModels - allows passing current value from UI
ollamaApiKey?: string // For testOllamaConnection and refreshOllamaModels - allows passing current value from UI
mpItem?: MarketplaceItem
mpInstallOptions?: InstallMarketplaceItemOptions
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
Loading