Skip to content
Merged
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
32 changes: 23 additions & 9 deletions web-app/src/services/providers/tauri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,91 +2,104 @@
* Tauri Providers Service - Desktop implementation
*/

import { models as providerModels } from 'token.js'
import { predefinedProviders } from '@/consts/providers'
import { EngineManager, SettingComponentProps } from '@janhq/core'
import { ModelCapabilities } from '@/types/models'
import { modelSettings } from '@/lib/predefined'
import { ExtensionManager } from '@/lib/extension'
import { fetch as fetchTauri } from '@tauri-apps/plugin-http'
import { DefaultProvidersService } from './default'

Check warning on line 12 in web-app/src/services/providers/tauri.ts

View workflow job for this annotation

GitHub Actions / coverage-check

5-12 lines are not covered with tests

export class TauriProvidersService extends DefaultProvidersService {
fetch(): typeof fetch {

Check warning on line 15 in web-app/src/services/providers/tauri.ts

View workflow job for this annotation

GitHub Actions / coverage-check

14-15 lines are not covered with tests
// Tauri implementation uses Tauri's fetch to avoid CORS issues
return fetchTauri as typeof fetch
}

Check warning on line 18 in web-app/src/services/providers/tauri.ts

View workflow job for this annotation

GitHub Actions / coverage-check

17-18 lines are not covered with tests

async getProviders(): Promise<ModelProvider[]> {
try {
const builtinProviders = predefinedProviders.map((provider) => {
let models = provider.models as Model[]
if (Object.keys(providerModels).includes(provider.provider)) {
const builtInModels = providerModels[
provider.provider as unknown as keyof typeof providerModels
].models as unknown as string[]

Check warning on line 27 in web-app/src/services/providers/tauri.ts

View workflow job for this annotation

GitHub Actions / coverage-check

20-27 lines are not covered with tests

if (Array.isArray(builtInModels))
models = builtInModels.map((model) => {
const modelManifest = models.find((e) => e.id === model)

Check warning on line 31 in web-app/src/services/providers/tauri.ts

View workflow job for this annotation

GitHub Actions / coverage-check

29-31 lines are not covered with tests
// TODO: Check chat_template for tool call support
const capabilities = [
ModelCapabilities.COMPLETION,

Check warning on line 34 in web-app/src/services/providers/tauri.ts

View workflow job for this annotation

GitHub Actions / coverage-check

33-34 lines are not covered with tests
(
providerModels[
provider.provider as unknown as keyof typeof providerModels
].supportsToolCalls as unknown as string[]
).includes(model)
? ModelCapabilities.TOOLS
: undefined,
].filter(Boolean) as string[]
return {
...(modelManifest ?? { id: model, name: model }),
capabilities,
} as Model
})
}

Check warning on line 48 in web-app/src/services/providers/tauri.ts

View workflow job for this annotation

GitHub Actions / coverage-check

36-48 lines are not covered with tests

return {
...provider,
models,
}
})

Check warning on line 54 in web-app/src/services/providers/tauri.ts

View workflow job for this annotation

GitHub Actions / coverage-check

50-54 lines are not covered with tests

const runtimeProviders: ModelProvider[] = []
for (const [providerName, value] of EngineManager.instance().engines) {
const models = (await value.list()) ?? []
const provider: ModelProvider = {
active: false,
persist: true,
provider: providerName,
base_url:
'inferenceUrl' in value
? (value.inferenceUrl as string).replace('/chat/completions', '')
: '',
settings: (await value.getSettings()).map((setting) => {
return {
key: setting.key,
title: setting.title,
description: setting.description,
controller_type: setting.controllerType as unknown,
controller_props: setting.controllerProps as unknown,
}
}) as ProviderSetting[],
models: await Promise.all(
models.map(
async (model) =>
({
async (model) => {
let capabilities: string[] = []

Check warning on line 79 in web-app/src/services/providers/tauri.ts

View workflow job for this annotation

GitHub Actions / coverage-check

56-79 lines are not covered with tests

// Check for capabilities
if ('capabilities' in model) {
capabilities = model.capabilities as string[]
} else {

Check warning on line 84 in web-app/src/services/providers/tauri.ts

View workflow job for this annotation

GitHub Actions / coverage-check

82-84 lines are not covered with tests
// Try to check tool support, but don't let failures block the model
try {
const toolSupported = await value.isToolSupported(model.id)
if (toolSupported) {
capabilities = [ModelCapabilities.TOOLS]
}
} catch (error) {
console.warn(`Failed to check tool support for model ${model.id}:`, error)
// Continue without tool capabilities if check fails
}
}

return {
id: model.id,
model: model.id,
name: model.name,
description: model.description,
capabilities:
'capabilities' in model
? (model.capabilities as string[])
: (await value.isToolSupported(model.id))
? [ModelCapabilities.TOOLS]
: [],
capabilities,
provider: providerName,
settings: Object.values(modelSettings).reduce(
(acc, setting) => {
Expand All @@ -105,7 +118,8 @@
},
{} as Record<string, ProviderSetting>
),
}) as Model
} as Model
}
)
),
}
Expand Down
Loading