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
226 changes: 212 additions & 14 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ tauri-plugin-dialog = "2.7.0"
tauri-plugin-fs = "2.5.0"
tauri-plugin-process = "2.3.1"
tauri-plugin-clipboard-manager = "2.3.2"
tauri-plugin-http = "2.5.9"
serde = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true }
Expand All @@ -47,7 +48,6 @@ sqlstmt = { path = "./src-crates/sqlstmt" }
kvdb = { path = "./src-crates/kvdb" }
backup = { path = "./src-crates/backup" }
proxy = { path = "./src-crates/proxy" }
reqwest = { path = "./src-crates/reqwest" }
client-store = { path = "./src-crates/client-store" }
dir = { path = "./src-crates/dir" }
whoami = "1.6.0"
Expand Down
9 changes: 9 additions & 0 deletions capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
"path": "**"
}
]
},
{
"identifier": "http:default",
"allow": [
{ "url": "https://*" },
{ "url": "https://*:*" },
{ "url": "http://*" },
{ "url": "http://*:*" }
]
Comment on lines +36 to +40
}
]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@tauri-apps/plugin-clipboard-manager": "^2.3.2",
"@tauri-apps/plugin-dialog": "^2.7.0",
"@tauri-apps/plugin-fs": "^2.5.0",
"@tauri-apps/plugin-http": "^2.5.9",
"@tauri-apps/plugin-opener": "^2.5.3",
"@tauri-apps/plugin-process": "^2.3.1",
"@tauri-apps/plugin-updater": "^2.10.1",
Expand Down
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 0 additions & 55 deletions src-tauri/http.rs

This file was deleted.

4 changes: 1 addition & 3 deletions src-tauri/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mod backup;
mod client;
mod database;
mod device;
mod http;
mod ipc;
mod keychain;
mod lifecycle;
Expand Down Expand Up @@ -42,6 +41,7 @@ fn main() {
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_fs::init())
.plugin(tauri_plugin_http::init())
.plugin(tauri_plugin_process::init())
.plugin(tauri_plugin_clipboard_manager::init())
.plugin(tauri_plugin_updater::Builder::new().build());
Expand All @@ -61,8 +61,6 @@ fn main() {
// Device
device::hostname,
device::font_families,
// HTTP
http::fetch,
// Keychain
keychain::set_password,
keychain::get_password,
Expand Down
13 changes: 10 additions & 3 deletions src-web/pages/database/ai/services.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createAnthropic } from '@ai-sdk/anthropic'
import { createGoogleGenerativeAI } from '@ai-sdk/google'
import { createOpenAICompatible } from '@ai-sdk/openai-compatible'
import { fetch as tauriFetch } from '@tauri-apps/plugin-http'
import {
ChatAddToolApproveResponseFunction,
ChatRequestOptions,
Expand Down Expand Up @@ -94,12 +95,17 @@ const createLanguageModel = (config: ProviderConfig, modelID: string): LanguageM
headers: {
'anthropic-dangerous-direct-browser-access': 'true',
'dangerouslyAllowBrowser': 'true'
}
},
fetch: tauriFetch
})
return anthropic(modelID)
}
case ProviderType.GoogleGemini: {
const googleGemini = createGoogleGenerativeAI({ apiKey: config.apiKey, baseURL })
const googleGemini = createGoogleGenerativeAI({
apiKey: config.apiKey,
baseURL,
fetch: tauriFetch
})
return googleGemini(modelID)
}
case ProviderType.DeepSeek:
Expand All @@ -115,7 +121,8 @@ const createLanguageModel = (config: ProviderConfig, modelID: string): LanguageM
const openai = createOpenAICompatible({
name: 'openai-compatible',
apiKey: config.apiKey,
baseURL: baseURL ?? defaultBaseURL(config.type)
baseURL: baseURL ?? defaultBaseURL(config.type),
fetch: tauriFetch
})
return openai(modelID)
}
Expand Down
14 changes: 10 additions & 4 deletions src-web/pages/settings/provider/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fetch as tauriFetch } from '@tauri-apps/plugin-http'
import z, { ZodType } from 'zod'
import { Http, ProviderConfig, ProviderModelConfig, ProviderType } from '../../../tauri'
import { ProviderConfig, ProviderModelConfig, ProviderType } from '../../../tauri'

export const defaultBaseURL = (type: ProviderType): string => {
return {
Expand Down Expand Up @@ -28,11 +29,11 @@ export const normalizeBaseURL = <T>(url: string, emptyFallback: T): string | T =

export const fetchModels = async (config: ProviderConfig): Promise<ProviderModelConfig[]> => {
const fetchJSON = async <T extends ZodType>(url: string, schema: T, headers?: Record<string, string>) => {
const res = await Http.fetch(url, { method: 'GET', headers })
const res = await tauriFetch(url, { method: 'GET', headers })
if (res.status !== 200) {
throw `StatusCode: ${res.status}\nFrom: ${url}`
}
const parsed = schema.safeParse(res.json())
const parsed = schema.safeParse(await res.json())
if (!parsed.success) {
const issue = parsed.error.issues[0]
const path = issue.path.length > 0 ? ` at '${issue.path.join('.')}'` : ''
Expand Down Expand Up @@ -101,7 +102,12 @@ export const fetchModels = async (config: ProviderConfig): Promise<ProviderModel
})
)
})
const headers = { 'x-api-key': config.apiKey, 'anthropic-version': '2023-06-01' }
const headers = {
'x-api-key': config.apiKey,
'anthropic-version': '2023-06-01',
'anthropic-dangerous-direct-browser-access': 'true',
'dangerouslyAllowBrowser': 'true'
}
Comment on lines +105 to +110
return fetchJSON(`${baseURL}/models`, schema, headers).then((json) => json.data)
}
case ProviderType.GoogleGemini: {
Expand Down
48 changes: 0 additions & 48 deletions src-web/tauri/http.ts

This file was deleted.

1 change: 0 additions & 1 deletion src-web/tauri/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ export * from './lifecycle'
export * from './keychain'
export * from './event'
export * from './backup'
export * from './http'
9 changes: 5 additions & 4 deletions src-web/utils/license.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getPassword, setPassword, deletePassword, Http } from '../tauri'
import { fetch as tauriFetch } from '@tauri-apps/plugin-http'
import { getPassword, setPassword, deletePassword } from '../tauri'

export interface License {
key: string
Expand Down Expand Up @@ -66,18 +67,18 @@ export class LicenseApi {
}
return new Promise(async (success, error) => {
try {
let res = await Http.fetch(url.toString(), {
let res = await tauriFetch(url.toString(), {
method: data.method,
headers: {
'Content-Type': 'application/json'
},
body
})
if (res.status !== 200) {
const rst: { message: string } = res.json()
const rst: { message: string } = await res.json()
return error(rst.message)
}
success(res.json())
success(await res.json())
} catch (err: any) {
error(err.toString())
}
Expand Down