mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-19 14:41:24 +08:00
Compare commits
12 Commits
e3f8a6ac89
...
995b63d57e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
995b63d57e | ||
|
|
8ab375161d | ||
|
|
42260710d8 | ||
|
|
5e8646c6a5 | ||
|
|
7e93e8b9b2 | ||
|
|
08dabc6187 | ||
|
|
6b196f0107 | ||
|
|
047a581220 | ||
|
|
7c0ec2903a | ||
|
|
162bf43a0b | ||
|
|
2e9961f35a | ||
|
|
4a7986f041 |
@ -1,5 +1,5 @@
|
||||
diff --git a/dist/index.js b/dist/index.js
|
||||
index 51ce7e423934fb717cb90245cdfcdb3dae6780e6..0f7f7009e2f41a79a8669d38c8a44867bbff5e1f 100644
|
||||
index d004b415c5841a1969705823614f395265ea5a8a..6b1e0dad4610b0424393ecc12e9114723bbe316b 100644
|
||||
--- a/dist/index.js
|
||||
+++ b/dist/index.js
|
||||
@@ -474,7 +474,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
||||
@ -12,7 +12,7 @@ index 51ce7e423934fb717cb90245cdfcdb3dae6780e6..0f7f7009e2f41a79a8669d38c8a44867
|
||||
|
||||
// src/google-generative-ai-options.ts
|
||||
diff --git a/dist/index.mjs b/dist/index.mjs
|
||||
index f4b77e35c0cbfece85a3ef0d4f4e67aa6dde6271..8d2fecf8155a226006a0bde72b00b6036d4014b6 100644
|
||||
index 1780dd2391b7f42224a0b8048c723d2f81222c44..1f12ed14399d6902107ce9b435d7d8e6cc61e06b 100644
|
||||
--- a/dist/index.mjs
|
||||
+++ b/dist/index.mjs
|
||||
@@ -480,7 +480,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
||||
@ -24,3 +24,14 @@ index f4b77e35c0cbfece85a3ef0d4f4e67aa6dde6271..8d2fecf8155a226006a0bde72b00b603
|
||||
}
|
||||
|
||||
// src/google-generative-ai-options.ts
|
||||
@@ -1909,8 +1909,7 @@ function createGoogleGenerativeAI(options = {}) {
|
||||
}
|
||||
var google = createGoogleGenerativeAI();
|
||||
export {
|
||||
- VERSION,
|
||||
createGoogleGenerativeAI,
|
||||
- google
|
||||
+ google, VERSION
|
||||
};
|
||||
//# sourceMappingURL=index.mjs.map
|
||||
\ No newline at end of file
|
||||
@ -114,8 +114,8 @@
|
||||
"@ai-sdk/anthropic": "^2.0.49",
|
||||
"@ai-sdk/cerebras": "^1.0.31",
|
||||
"@ai-sdk/gateway": "^2.0.15",
|
||||
"@ai-sdk/google": "patch:@ai-sdk/google@npm%3A2.0.43#~/.yarn/patches/@ai-sdk-google-npm-2.0.43-689ed559b3.patch",
|
||||
"@ai-sdk/google-vertex": "^3.0.79",
|
||||
"@ai-sdk/google": "patch:@ai-sdk/google@npm%3A2.0.49#~/.yarn/patches/@ai-sdk-google-npm-2.0.49-84720f41bd.patch",
|
||||
"@ai-sdk/google-vertex": "^3.0.94",
|
||||
"@ai-sdk/huggingface": "^0.0.10",
|
||||
"@ai-sdk/mistral": "^2.0.24",
|
||||
"@ai-sdk/openai": "patch:@ai-sdk/openai@npm%3A2.0.85#~/.yarn/patches/@ai-sdk-openai-npm-2.0.85-27483d1d6a.patch",
|
||||
@ -416,7 +416,8 @@
|
||||
"@langchain/openai@npm:>=0.2.0 <0.7.0": "patch:@langchain/openai@npm%3A1.0.0#~/.yarn/patches/@langchain-openai-npm-1.0.0-474d0ad9d4.patch",
|
||||
"@ai-sdk/openai@npm:^2.0.42": "patch:@ai-sdk/openai@npm%3A2.0.85#~/.yarn/patches/@ai-sdk-openai-npm-2.0.85-27483d1d6a.patch",
|
||||
"@ai-sdk/google@npm:^2.0.40": "patch:@ai-sdk/google@npm%3A2.0.40#~/.yarn/patches/@ai-sdk-google-npm-2.0.40-47e0eeee83.patch",
|
||||
"@ai-sdk/openai-compatible@npm:^1.0.27": "patch:@ai-sdk/openai-compatible@npm%3A1.0.27#~/.yarn/patches/@ai-sdk-openai-compatible-npm-1.0.27-06f74278cf.patch"
|
||||
"@ai-sdk/openai-compatible@npm:^1.0.27": "patch:@ai-sdk/openai-compatible@npm%3A1.0.27#~/.yarn/patches/@ai-sdk-openai-compatible-npm-1.0.27-06f74278cf.patch",
|
||||
"@ai-sdk/google@npm:2.0.49": "patch:@ai-sdk/google@npm%3A2.0.49#~/.yarn/patches/@ai-sdk-google-npm-2.0.49-84720f41bd.patch"
|
||||
},
|
||||
"packageManager": "yarn@4.9.1",
|
||||
"lint-staged": {
|
||||
|
||||
@ -28,11 +28,16 @@ export class WindowService {
|
||||
private mainWindow: BrowserWindow | null = null
|
||||
private miniWindow: BrowserWindow | null = null
|
||||
private isPinnedMiniWindow: boolean = false
|
||||
//hacky-fix: store the focused status of mainWindow before miniWindow shows
|
||||
//to restore the focus status when miniWindow hides
|
||||
// hacky-fix: store the focused status of mainWindow before miniWindow shows
|
||||
// to restore the focus status when miniWindow hides
|
||||
private wasMainWindowFocused: boolean = false
|
||||
private lastRendererProcessCrashTime: number = 0
|
||||
|
||||
// 记录是否是 miniWindow 隐藏时调用了 app.hide()
|
||||
private appHiddenByMiniWindow: boolean = false
|
||||
// 记录当前主窗口 show 是否是为了“恢复 app 给 miniWindow 用”
|
||||
private isRestoringAppForMiniWindow: boolean = false
|
||||
|
||||
public static getInstance(): WindowService {
|
||||
if (!WindowService.instance) {
|
||||
WindowService.instance = new WindowService()
|
||||
@ -93,13 +98,13 @@ export class WindowService {
|
||||
|
||||
this.setupMainWindow(this.mainWindow, mainWindowState)
|
||||
|
||||
//preload miniWindow to resolve series of issues about miniWindow in Mac
|
||||
// preload miniWindow to resolve series of issues about miniWindow in Mac
|
||||
const enableQuickAssistant = configManager.getEnableQuickAssistant()
|
||||
if (enableQuickAssistant && !this.miniWindow) {
|
||||
this.miniWindow = this.createMiniWindow(true)
|
||||
}
|
||||
|
||||
//init the MinApp webviews' useragent
|
||||
// init the MinApp webviews' useragent
|
||||
initSessionUserAgent()
|
||||
|
||||
return this.mainWindow
|
||||
@ -194,28 +199,15 @@ export class WindowService {
|
||||
mainWindow.webContents.send(IpcChannel.FullscreenStatusChanged, false)
|
||||
})
|
||||
|
||||
// set the zoom factor again when the window is going to resize
|
||||
//
|
||||
// this is a workaround for the known bug that
|
||||
// the zoom factor is reset to cached value when window is resized after routing to other page
|
||||
// see: https://github.com/electron/electron/issues/10572
|
||||
//
|
||||
// and resize ipc
|
||||
//
|
||||
mainWindow.on('will-resize', () => {
|
||||
mainWindow.webContents.setZoomFactor(configManager.getZoomFactor())
|
||||
mainWindow.webContents.send(IpcChannel.Windows_Resize, mainWindow.getSize())
|
||||
})
|
||||
|
||||
// set the zoom factor again when the window is going to restore
|
||||
// minimize and restore will cause zoom reset
|
||||
mainWindow.on('restore', () => {
|
||||
mainWindow.webContents.setZoomFactor(configManager.getZoomFactor())
|
||||
})
|
||||
|
||||
// ARCH: as `will-resize` is only for Win & Mac,
|
||||
// linux has the same problem, use `resize` listener instead
|
||||
// but `resize` will fliker the ui
|
||||
if (isLinux) {
|
||||
mainWindow.on('resize', () => {
|
||||
mainWindow.webContents.setZoomFactor(configManager.getZoomFactor())
|
||||
@ -231,27 +223,7 @@ export class WindowService {
|
||||
mainWindow.webContents.send(IpcChannel.Windows_Resize, mainWindow.getSize())
|
||||
})
|
||||
|
||||
// 添加Escape键退出全屏的支持
|
||||
// mainWindow.webContents.on('before-input-event', (event, input) => {
|
||||
// // 当按下Escape键且窗口处于全屏状态时退出全屏
|
||||
// if (input.key === 'Escape' && !input.alt && !input.control && !input.meta && !input.shift) {
|
||||
// if (mainWindow.isFullScreen()) {
|
||||
// // 获取 shortcuts 配置
|
||||
// const shortcuts = configManager.getShortcuts()
|
||||
// const exitFullscreenShortcut = shortcuts.find((s) => s.key === 'exit_fullscreen')
|
||||
// if (exitFullscreenShortcut == undefined) {
|
||||
// mainWindow.setFullScreen(false)
|
||||
// return
|
||||
// }
|
||||
// if (exitFullscreenShortcut?.enabled) {
|
||||
// event.preventDefault()
|
||||
// mainWindow.setFullScreen(false)
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return
|
||||
// })
|
||||
// Escape 处理全屏的逻辑已注释
|
||||
}
|
||||
|
||||
private setupWebContentsHandlers(mainWindow: BrowserWindow) {
|
||||
@ -294,7 +266,9 @@ export class WindowService {
|
||||
const fileName = url.replace('http://file/', '')
|
||||
const storageDir = getFilesDir()
|
||||
const filePath = storageDir + '/' + fileName
|
||||
shell.openPath(filePath).catch((err) => logger.error('Failed to open file:', err))
|
||||
shell
|
||||
.openPath(filePath)
|
||||
.catch((err) => logger.error('Failed to open file:', err))
|
||||
} else {
|
||||
shell.openExternal(details.url)
|
||||
}
|
||||
@ -356,8 +330,6 @@ export class WindowService {
|
||||
|
||||
// 没有开启托盘,或者开启了托盘,但设置了直接关闭,应执行直接退出
|
||||
if (!isShowTray || (isShowTray && !isTrayOnClose)) {
|
||||
// 如果是Windows或Linux,直接退出
|
||||
// mac按照系统默认行为,不退出
|
||||
if (isWin || isLinux) {
|
||||
return app.quit()
|
||||
}
|
||||
@ -375,12 +347,12 @@ export class WindowService {
|
||||
|
||||
mainWindow.hide()
|
||||
|
||||
//for mac users, should hide dock icon if close to tray
|
||||
// for mac users, should hide dock icon if close to tray
|
||||
if (isMac && isTrayOnClose) {
|
||||
app.dock?.hide()
|
||||
|
||||
mainWindow.once('show', () => {
|
||||
//restore the window can hide by cmd+h when the window is shown again
|
||||
// restore the window can hide by cmd+h when the window is shown again
|
||||
// https://github.com/electron/electron/pull/47970
|
||||
app.dock?.show()
|
||||
})
|
||||
@ -392,6 +364,18 @@ export class WindowService {
|
||||
})
|
||||
|
||||
mainWindow.on('show', () => {
|
||||
// 无论什么原因 show,说明 app 已经不再是“被 miniWindow 隐藏”的状态
|
||||
this.appHiddenByMiniWindow = false
|
||||
|
||||
// 如果是为了从 app.hide() 恢复,仅仅为了 miniWindow,则不要让主窗口抢戏
|
||||
if (isMac && this.isRestoringAppForMiniWindow) {
|
||||
this.isRestoringAppForMiniWindow = false
|
||||
// 保持 Spotlight 一样的体验:只显示 miniWindow,把主窗口继续隐藏
|
||||
mainWindow.hide()
|
||||
return
|
||||
}
|
||||
|
||||
// 正常情况下:主窗口显示时隐藏 miniWindow
|
||||
if (this.miniWindow && !this.miniWindow.isDestroyed()) {
|
||||
this.miniWindow.hide()
|
||||
}
|
||||
@ -403,34 +387,20 @@ export class WindowService {
|
||||
this.miniWindow.hide()
|
||||
}
|
||||
|
||||
// 显式展示主窗口时,不再认为 app 是被 miniWindow 隐藏的
|
||||
this.appHiddenByMiniWindow = false
|
||||
this.isRestoringAppForMiniWindow = false
|
||||
|
||||
if (this.mainWindow && !this.mainWindow.isDestroyed()) {
|
||||
if (this.mainWindow.isMinimized()) {
|
||||
this.mainWindow.restore()
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* About setVisibleOnAllWorkspaces
|
||||
*
|
||||
* [macOS] Known Issue
|
||||
* setVisibleOnAllWorkspaces true/false will NOT bring window to current desktop in Mac (works fine with Windows)
|
||||
* AppleScript may be a solution, but it's not worth
|
||||
*
|
||||
* [Linux] Known Issue
|
||||
* setVisibleOnAllWorkspaces 在 Linux 环境下(特别是 KDE Wayland)会导致窗口进入"假弹出"状态
|
||||
* 因此在 Linux 环境下不执行这两行代码
|
||||
*/
|
||||
if (!isLinux) {
|
||||
this.mainWindow.setVisibleOnAllWorkspaces(true)
|
||||
}
|
||||
|
||||
/**
|
||||
* [macOS] After being closed in fullscreen, the fullscreen behavior will become strange when window shows again
|
||||
* So we need to set it to FALSE explicitly.
|
||||
* althougle other platforms don't have the issue, but it's a good practice to do so
|
||||
*
|
||||
* Check if window is visible to prevent interrupting fullscreen state when clicking dock icon
|
||||
*/
|
||||
if (this.mainWindow.isFullScreen() && !this.mainWindow.isVisible()) {
|
||||
this.mainWindow.setFullScreen(false)
|
||||
}
|
||||
@ -446,16 +416,12 @@ export class WindowService {
|
||||
}
|
||||
|
||||
public toggleMainWindow() {
|
||||
// should not toggle main window when in full screen
|
||||
// but if the main window is close to tray when it's in full screen, we can show it again
|
||||
// (it's a bug in macos, because we can close the window when it's in full screen, and the state will be remained)
|
||||
if (this.mainWindow?.isFullScreen() && this.mainWindow?.isVisible()) {
|
||||
return
|
||||
}
|
||||
|
||||
if (this.mainWindow && !this.mainWindow.isDestroyed() && this.mainWindow.isVisible()) {
|
||||
if (this.mainWindow.isFocused()) {
|
||||
// if tray is enabled, hide the main window, else do nothing
|
||||
if (configManager.getTray()) {
|
||||
this.mainWindow.hide()
|
||||
app.dock?.hide()
|
||||
@ -515,10 +481,10 @@ export class WindowService {
|
||||
|
||||
miniWindowState.manage(this.miniWindow)
|
||||
|
||||
//miniWindow should show in current desktop
|
||||
this.miniWindow?.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true })
|
||||
//make miniWindow always on top of fullscreen apps with level set
|
||||
//[mac] level higher than 'floating' will cover the pinyin input method
|
||||
// miniWindow should show in current desktop
|
||||
this.miniWindow.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true })
|
||||
// make miniWindow always on top of fullscreen apps with level set
|
||||
// [mac] level higher than 'floating' will cover the pinyin input method
|
||||
this.miniWindow.setAlwaysOnTop(true, 'floating')
|
||||
|
||||
this.miniWindow.on('ready-to-show', () => {
|
||||
@ -569,33 +535,35 @@ export class WindowService {
|
||||
this.wasMainWindowFocused = this.mainWindow?.isFocused() || false
|
||||
|
||||
// [Windows] hacky fix
|
||||
// the window is minimized only when in Windows platform
|
||||
// because it's a workaround for Windows, see `hideMiniWindow()`
|
||||
if (this.miniWindow?.isMinimized()) {
|
||||
// don't let the window being seen before we finish adjusting the position across screens
|
||||
this.miniWindow?.setOpacity(0)
|
||||
// DO NOT use `restore()` here, Electron has the bug with screens of different scale factor
|
||||
// We have to use `show()` here, then set the position and bounds
|
||||
this.miniWindow?.show()
|
||||
const wasMinimized = this.miniWindow.isMinimized()
|
||||
if (wasMinimized) {
|
||||
this.miniWindow.setOpacity(0)
|
||||
this.miniWindow.show()
|
||||
}
|
||||
|
||||
// [macOS] 如果之前是 miniWindow 隐藏时调用的 app.hide(),
|
||||
// 那么现在需要先把整个 app show 回来
|
||||
if (isMac && !this.miniWindow.isVisible()) {
|
||||
if (this.appHiddenByMiniWindow) {
|
||||
this.isRestoringAppForMiniWindow = true
|
||||
app.show()
|
||||
} else {
|
||||
this.isRestoringAppForMiniWindow = false
|
||||
}
|
||||
}
|
||||
|
||||
const miniWindowBounds = this.miniWindow.getBounds()
|
||||
|
||||
// Check if miniWindow is on the same screen as mouse cursor
|
||||
const cursorDisplay = screen.getDisplayNearestPoint(screen.getCursorScreenPoint())
|
||||
const miniWindowDisplay = screen.getDisplayNearestPoint(miniWindowBounds)
|
||||
|
||||
// Show the miniWindow on the cursor's screen center
|
||||
// If miniWindow is not on the same screen as cursor, move it to cursor's screen center
|
||||
if (cursorDisplay.id !== miniWindowDisplay.id) {
|
||||
const workArea = cursorDisplay.bounds
|
||||
|
||||
// use current window size to avoid the bug of Electron with screens of different scale factor
|
||||
const currentBounds = this.miniWindow.getBounds()
|
||||
const miniWindowWidth = currentBounds.width
|
||||
const miniWindowHeight = currentBounds.height
|
||||
|
||||
// move to the center of the cursor's screen
|
||||
const miniWindowX = Math.round(workArea.x + (workArea.width - miniWindowWidth) / 2)
|
||||
const miniWindowY = Math.round(workArea.y + (workArea.height - miniWindowHeight) / 2)
|
||||
|
||||
@ -608,8 +576,12 @@ export class WindowService {
|
||||
})
|
||||
}
|
||||
|
||||
this.miniWindow?.setOpacity(1)
|
||||
this.miniWindow?.show()
|
||||
if (wasMinimized || !this.miniWindow.isVisible()) {
|
||||
this.miniWindow.setOpacity(1)
|
||||
this.miniWindow.show()
|
||||
} else {
|
||||
this.miniWindow.focus()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@ -626,16 +598,18 @@ export class WindowService {
|
||||
return
|
||||
}
|
||||
|
||||
//[macOs/Windows] hacky fix
|
||||
// previous window(not self-app) should be focused again after miniWindow hide
|
||||
// this workaround is to make previous window focused again after miniWindow hide
|
||||
// 记录这次隐藏 miniWindow 时主窗口是否有焦点:
|
||||
// - true: 从主窗口唤起的 quick assistant,关闭时只隐藏 miniWindow
|
||||
// - false: 从其他 app 唤起,关闭时隐藏整个 app(mac 上通过 app.hide() 把焦点交回去)
|
||||
this.appHiddenByMiniWindow = !this.wasMainWindowFocused
|
||||
|
||||
if (isWin) {
|
||||
this.miniWindow.setOpacity(0) // don't show the minimizing animation
|
||||
this.miniWindow.setOpacity(0)
|
||||
this.miniWindow.minimize()
|
||||
return
|
||||
} else if (isMac) {
|
||||
this.miniWindow.hide()
|
||||
if (!this.wasMainWindowFocused) {
|
||||
if (this.appHiddenByMiniWindow) {
|
||||
app.hide()
|
||||
}
|
||||
return
|
||||
@ -657,7 +631,7 @@ export class WindowService {
|
||||
this.showMiniWindow()
|
||||
}
|
||||
|
||||
public setPinMiniWindow(isPinned) {
|
||||
public setPinMiniWindow(isPinned: boolean) {
|
||||
this.isPinnedMiniWindow = isPinned
|
||||
}
|
||||
|
||||
@ -681,4 +655,4 @@ export class WindowService {
|
||||
}
|
||||
}
|
||||
|
||||
export const windowService = WindowService.getInstance()
|
||||
export const windowService = WindowService.getInstance()
|
||||
@ -69,7 +69,7 @@ export abstract class OpenAIBaseClient<
|
||||
const sdk = await this.getSdkInstance()
|
||||
const response = (await sdk.request({
|
||||
method: 'post',
|
||||
path: '/images/generations',
|
||||
path: '/v1/images/generations',
|
||||
signal,
|
||||
body: {
|
||||
model,
|
||||
|
||||
@ -79,7 +79,7 @@ vi.mock('@renderer/services/AssistantService', () => ({
|
||||
import { getProviderByModel } from '@renderer/services/AssistantService'
|
||||
import type { Model, Provider } from '@renderer/types'
|
||||
import { formatApiHost } from '@renderer/utils/api'
|
||||
import { isCherryAIProvider, isPerplexityProvider } from '@renderer/utils/provider'
|
||||
import { isAzureOpenAIProvider, isCherryAIProvider, isPerplexityProvider } from '@renderer/utils/provider'
|
||||
|
||||
import { COPILOT_DEFAULT_HEADERS, COPILOT_EDITOR_VERSION, isCopilotResponsesModel } from '../constants'
|
||||
import { getActualProvider, providerToAiSdkConfig } from '../providerConfig'
|
||||
@ -133,6 +133,17 @@ const createPerplexityProvider = (): Provider => ({
|
||||
isSystem: false
|
||||
})
|
||||
|
||||
const createAzureProvider = (apiVersion: string): Provider => ({
|
||||
id: 'azure-openai',
|
||||
type: 'azure-openai',
|
||||
name: 'Azure OpenAI',
|
||||
apiKey: 'test-key',
|
||||
apiHost: 'https://example.openai.azure.com/openai',
|
||||
apiVersion,
|
||||
models: [],
|
||||
isSystem: true
|
||||
})
|
||||
|
||||
describe('Copilot responses routing', () => {
|
||||
beforeEach(() => {
|
||||
;(globalThis as any).window = {
|
||||
@ -504,3 +515,46 @@ describe('Stream options includeUsage configuration', () => {
|
||||
expect(config.providerId).toBe('github-copilot-openai-compatible')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Azure OpenAI traditional API routing', () => {
|
||||
beforeEach(() => {
|
||||
;(globalThis as any).window = {
|
||||
...(globalThis as any).window,
|
||||
keyv: createWindowKeyv()
|
||||
}
|
||||
mockGetState.mockReturnValue({
|
||||
settings: {
|
||||
openAI: {
|
||||
streamOptions: {
|
||||
includeUsage: undefined
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
vi.mocked(isAzureOpenAIProvider).mockImplementation((provider) => provider.type === 'azure-openai')
|
||||
})
|
||||
|
||||
it('uses deployment-based URLs when apiVersion is a date version', () => {
|
||||
const provider = createAzureProvider('2024-02-15-preview')
|
||||
const config = providerToAiSdkConfig(provider, createModel('gpt-4o', 'GPT-4o', provider.id))
|
||||
|
||||
expect(config.providerId).toBe('azure')
|
||||
expect(config.options.apiVersion).toBe('2024-02-15-preview')
|
||||
expect(config.options.useDeploymentBasedUrls).toBe(true)
|
||||
})
|
||||
|
||||
it('does not force deployment-based URLs for apiVersion v1/preview', () => {
|
||||
const v1Provider = createAzureProvider('v1')
|
||||
const v1Config = providerToAiSdkConfig(v1Provider, createModel('gpt-4o', 'GPT-4o', v1Provider.id))
|
||||
expect(v1Config.providerId).toBe('azure-responses')
|
||||
expect(v1Config.options.apiVersion).toBe('v1')
|
||||
expect(v1Config.options.useDeploymentBasedUrls).toBeUndefined()
|
||||
|
||||
const previewProvider = createAzureProvider('preview')
|
||||
const previewConfig = providerToAiSdkConfig(previewProvider, createModel('gpt-4o', 'GPT-4o', previewProvider.id))
|
||||
expect(previewConfig.providerId).toBe('azure-responses')
|
||||
expect(previewConfig.options.apiVersion).toBe('preview')
|
||||
expect(previewConfig.options.useDeploymentBasedUrls).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
@ -214,6 +214,15 @@ export function providerToAiSdkConfig(actualProvider: Provider, model: Model): A
|
||||
} else if (aiSdkProviderId === 'azure') {
|
||||
extraOptions.mode = 'chat'
|
||||
}
|
||||
if (isAzureOpenAIProvider(actualProvider)) {
|
||||
const apiVersion = actualProvider.apiVersion?.trim()
|
||||
if (apiVersion) {
|
||||
extraOptions.apiVersion = apiVersion
|
||||
if (!['preview', 'v1'].includes(apiVersion)) {
|
||||
extraOptions.useDeploymentBasedUrls = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// bedrock
|
||||
if (aiSdkProviderId === 'bedrock') {
|
||||
|
||||
@ -36,7 +36,7 @@ import {
|
||||
} from '@renderer/config/models'
|
||||
import { getStoreSetting } from '@renderer/hooks/useSettings'
|
||||
import { getAssistantSettings, getProviderByModel } from '@renderer/services/AssistantService'
|
||||
import type { Assistant, Model } from '@renderer/types'
|
||||
import type { Assistant, Model, ReasoningEffortOption } from '@renderer/types'
|
||||
import { EFFORT_RATIO, isSystemProvider, SystemProviderIds } from '@renderer/types'
|
||||
import type { OpenAIReasoningSummary } from '@renderer/types/aiCoreTypes'
|
||||
import type { ReasoningEffortOptionalParams } from '@renderer/types/sdk'
|
||||
@ -539,20 +539,25 @@ export function getAnthropicReasoningParams(
|
||||
return {}
|
||||
}
|
||||
|
||||
// type GoogleThinkingLevel = NonNullable<GoogleGenerativeAIProviderOptions['thinkingConfig']>['thinkingLevel']
|
||||
type GoogleThinkingLevel = NonNullable<GoogleGenerativeAIProviderOptions['thinkingConfig']>['thinkingLevel']
|
||||
|
||||
// function mapToGeminiThinkingLevel(reasoningEffort: ReasoningEffortOption): GoogelThinkingLevel {
|
||||
// switch (reasoningEffort) {
|
||||
// case 'low':
|
||||
// return 'low'
|
||||
// case 'medium':
|
||||
// return 'medium'
|
||||
// case 'high':
|
||||
// return 'high'
|
||||
// default:
|
||||
// return 'medium'
|
||||
// }
|
||||
// }
|
||||
function mapToGeminiThinkingLevel(reasoningEffort: ReasoningEffortOption): GoogleThinkingLevel {
|
||||
switch (reasoningEffort) {
|
||||
case 'default':
|
||||
return undefined
|
||||
case 'minimal':
|
||||
return 'minimal'
|
||||
case 'low':
|
||||
return 'low'
|
||||
case 'medium':
|
||||
return 'medium'
|
||||
case 'high':
|
||||
return 'high'
|
||||
default:
|
||||
logger.warn('Unknown thinking level for Gemini. Fallback to medium instead.', { reasoningEffort })
|
||||
return 'medium'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 Gemini 推理参数
|
||||
@ -585,15 +590,15 @@ export function getGeminiReasoningParams(
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: 很多中转还不支持
|
||||
// https://ai.google.dev/gemini-api/docs/gemini-3?thinking=high#new_api_features_in_gemini_3
|
||||
// if (isGemini3ThinkingTokenModel(model)) {
|
||||
// return {
|
||||
// thinkingConfig: {
|
||||
// thinkingLevel: mapToGeminiThinkingLevel(reasoningEffort)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
if (isGemini3ThinkingTokenModel(model)) {
|
||||
return {
|
||||
thinkingConfig: {
|
||||
includeThoughts: true,
|
||||
thinkingLevel: mapToGeminiThinkingLevel(reasoningEffort)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const effortRatio = EFFORT_RATIO[reasoningEffort]
|
||||
|
||||
|
||||
@ -695,15 +695,20 @@ describe('getThinkModelType - Comprehensive Coverage', () => {
|
||||
})
|
||||
|
||||
describe('Gemini models', () => {
|
||||
it('should return gemini for Flash models', () => {
|
||||
expect(getThinkModelType(createModel({ id: 'gemini-2.5-flash-latest' }))).toBe('gemini')
|
||||
expect(getThinkModelType(createModel({ id: 'gemini-flash-latest' }))).toBe('gemini')
|
||||
expect(getThinkModelType(createModel({ id: 'gemini-flash-lite-latest' }))).toBe('gemini')
|
||||
it('should return gemini2_flash for Flash models', () => {
|
||||
expect(getThinkModelType(createModel({ id: 'gemini-2.5-flash-latest' }))).toBe('gemini2_flash')
|
||||
})
|
||||
it('should return gemini3_flash for Gemini 3 Flash models', () => {
|
||||
expect(getThinkModelType(createModel({ id: 'gemini-3-flash-preview' }))).toBe('gemini3_flash')
|
||||
expect(getThinkModelType(createModel({ id: 'gemini-flash-latest' }))).toBe('gemini3_flash')
|
||||
})
|
||||
|
||||
it('should return gemini_pro for Pro models', () => {
|
||||
expect(getThinkModelType(createModel({ id: 'gemini-2.5-pro-latest' }))).toBe('gemini_pro')
|
||||
expect(getThinkModelType(createModel({ id: 'gemini-pro-latest' }))).toBe('gemini_pro')
|
||||
it('should return gemini2_pro for Gemini 2.5 Pro models', () => {
|
||||
expect(getThinkModelType(createModel({ id: 'gemini-2.5-pro-latest' }))).toBe('gemini2_pro')
|
||||
})
|
||||
it('should return gemini3_pro for Gemini 3 Pro models', () => {
|
||||
expect(getThinkModelType(createModel({ id: 'gemini-3-pro-preview' }))).toBe('gemini3_pro')
|
||||
expect(getThinkModelType(createModel({ id: 'gemini-pro-latest' }))).toBe('gemini3_pro')
|
||||
})
|
||||
})
|
||||
|
||||
@ -810,7 +815,7 @@ describe('getThinkModelType - Comprehensive Coverage', () => {
|
||||
name: 'gemini-2.5-flash-latest'
|
||||
})
|
||||
)
|
||||
).toBe('gemini')
|
||||
).toBe('gemini2_flash')
|
||||
})
|
||||
|
||||
it('should use id result when id matches', () => {
|
||||
@ -835,7 +840,7 @@ describe('getThinkModelType - Comprehensive Coverage', () => {
|
||||
|
||||
it('should handle case insensitivity correctly', () => {
|
||||
expect(getThinkModelType(createModel({ id: 'GPT-5.1' }))).toBe('gpt5_1')
|
||||
expect(getThinkModelType(createModel({ id: 'Gemini-2.5-Flash-Latest' }))).toBe('gemini')
|
||||
expect(getThinkModelType(createModel({ id: 'Gemini-2.5-Flash-Latest' }))).toBe('gemini2_flash')
|
||||
expect(getThinkModelType(createModel({ id: 'DeepSeek-V3.1' }))).toBe('deepseek_hybrid')
|
||||
})
|
||||
|
||||
@ -855,7 +860,7 @@ describe('getThinkModelType - Comprehensive Coverage', () => {
|
||||
it('should handle models with version suffixes', () => {
|
||||
expect(getThinkModelType(createModel({ id: 'gpt-5-preview-2024' }))).toBe('gpt5')
|
||||
expect(getThinkModelType(createModel({ id: 'o3-mini-2024' }))).toBe('o')
|
||||
expect(getThinkModelType(createModel({ id: 'gemini-2.5-flash-latest-001' }))).toBe('gemini')
|
||||
expect(getThinkModelType(createModel({ id: 'gemini-2.5-flash-latest-001' }))).toBe('gemini2_flash')
|
||||
})
|
||||
|
||||
it('should prioritize GPT-5.1 over GPT-5 detection', () => {
|
||||
@ -955,6 +960,14 @@ describe('Gemini Models', () => {
|
||||
group: ''
|
||||
})
|
||||
).toBe(true)
|
||||
expect(
|
||||
isSupportedThinkingTokenGeminiModel({
|
||||
id: 'gemini-3-flash-preview',
|
||||
name: '',
|
||||
provider: '',
|
||||
group: ''
|
||||
})
|
||||
).toBe(true)
|
||||
expect(
|
||||
isSupportedThinkingTokenGeminiModel({
|
||||
id: 'google/gemini-3-pro-preview',
|
||||
@ -996,6 +1009,31 @@ describe('Gemini Models', () => {
|
||||
group: ''
|
||||
})
|
||||
).toBe(true)
|
||||
// Version with date suffixes
|
||||
expect(
|
||||
isSupportedThinkingTokenGeminiModel({
|
||||
id: 'gemini-3-flash-preview-09-2025',
|
||||
name: '',
|
||||
provider: '',
|
||||
group: ''
|
||||
})
|
||||
).toBe(true)
|
||||
expect(
|
||||
isSupportedThinkingTokenGeminiModel({
|
||||
id: 'gemini-3-pro-preview-09-2025',
|
||||
name: '',
|
||||
provider: '',
|
||||
group: ''
|
||||
})
|
||||
).toBe(true)
|
||||
expect(
|
||||
isSupportedThinkingTokenGeminiModel({
|
||||
id: 'gemini-3-flash-exp-1234',
|
||||
name: '',
|
||||
provider: '',
|
||||
group: ''
|
||||
})
|
||||
).toBe(true)
|
||||
// Version with decimals
|
||||
expect(
|
||||
isSupportedThinkingTokenGeminiModel({
|
||||
@ -1015,7 +1053,8 @@ describe('Gemini Models', () => {
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('should return true for gemini-3 image models', () => {
|
||||
it('should return true for gemini-3-pro-image models only', () => {
|
||||
// Only gemini-3-pro-image models should return true
|
||||
expect(
|
||||
isSupportedThinkingTokenGeminiModel({
|
||||
id: 'gemini-3-pro-image-preview',
|
||||
@ -1024,6 +1063,17 @@ describe('Gemini Models', () => {
|
||||
group: ''
|
||||
})
|
||||
).toBe(true)
|
||||
expect(
|
||||
isSupportedThinkingTokenGeminiModel({
|
||||
id: 'gemini-3-pro-image',
|
||||
name: '',
|
||||
provider: '',
|
||||
group: ''
|
||||
})
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('should return false for other gemini-3 image models', () => {
|
||||
expect(
|
||||
isSupportedThinkingTokenGeminiModel({
|
||||
id: 'gemini-3.0-flash-image-preview',
|
||||
@ -1086,6 +1136,22 @@ describe('Gemini Models', () => {
|
||||
group: ''
|
||||
})
|
||||
).toBe(false)
|
||||
expect(
|
||||
isSupportedThinkingTokenGeminiModel({
|
||||
id: 'gemini-3-flash-preview-tts',
|
||||
name: '',
|
||||
provider: '',
|
||||
group: ''
|
||||
})
|
||||
).toBe(false)
|
||||
expect(
|
||||
isSupportedThinkingTokenGeminiModel({
|
||||
id: 'gemini-3-pro-tts',
|
||||
name: '',
|
||||
provider: '',
|
||||
group: ''
|
||||
})
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('should return false for older gemini models', () => {
|
||||
@ -1811,7 +1877,7 @@ describe('getModelSupportedReasoningEffortOptions', () => {
|
||||
|
||||
describe('Gemini models', () => {
|
||||
it('should return correct options for Gemini Flash models', () => {
|
||||
expect(getModelSupportedReasoningEffortOptions(createModel({ id: 'gemini-2.5-flash-latest' }))).toEqual([
|
||||
expect(getModelSupportedReasoningEffortOptions(createModel({ id: 'gemini-2.5-flash' }))).toEqual([
|
||||
'default',
|
||||
'none',
|
||||
'low',
|
||||
@ -1819,36 +1885,46 @@ describe('getModelSupportedReasoningEffortOptions', () => {
|
||||
'high',
|
||||
'auto'
|
||||
])
|
||||
expect(getModelSupportedReasoningEffortOptions(createModel({ id: 'gemini-flash-latest' }))).toEqual([
|
||||
expect(getModelSupportedReasoningEffortOptions(createModel({ id: 'gemini-3-flash-preview' }))).toEqual([
|
||||
'default',
|
||||
'none',
|
||||
'minimal',
|
||||
'low',
|
||||
'medium',
|
||||
'high',
|
||||
'auto'
|
||||
'high'
|
||||
])
|
||||
expect(getModelSupportedReasoningEffortOptions(createModel({ id: 'gemini-flash-latest' }))).toEqual([
|
||||
'default',
|
||||
'minimal',
|
||||
'low',
|
||||
'medium',
|
||||
'high'
|
||||
])
|
||||
})
|
||||
|
||||
it('should return correct options for Gemini Pro models', () => {
|
||||
expect(getModelSupportedReasoningEffortOptions(createModel({ id: 'gemini-2.5-pro-latest' }))).toEqual([
|
||||
expect(getModelSupportedReasoningEffortOptions(createModel({ id: 'gemini-2.5-pro' }))).toEqual([
|
||||
'default',
|
||||
'low',
|
||||
'medium',
|
||||
'high',
|
||||
'auto'
|
||||
])
|
||||
expect(getModelSupportedReasoningEffortOptions(createModel({ id: 'gemini-3-pro-preview' }))).toEqual([
|
||||
'default',
|
||||
'low',
|
||||
'high'
|
||||
])
|
||||
expect(getModelSupportedReasoningEffortOptions(createModel({ id: 'gemini-pro-latest' }))).toEqual([
|
||||
'default',
|
||||
'low',
|
||||
'medium',
|
||||
'high',
|
||||
'auto'
|
||||
'high'
|
||||
])
|
||||
})
|
||||
|
||||
it('should return correct options for Gemini 3 models', () => {
|
||||
expect(getModelSupportedReasoningEffortOptions(createModel({ id: 'gemini-3-flash' }))).toEqual([
|
||||
'default',
|
||||
'minimal',
|
||||
'low',
|
||||
'medium',
|
||||
'high'
|
||||
@ -1856,7 +1932,6 @@ describe('getModelSupportedReasoningEffortOptions', () => {
|
||||
expect(getModelSupportedReasoningEffortOptions(createModel({ id: 'gemini-3-pro-preview' }))).toEqual([
|
||||
'default',
|
||||
'low',
|
||||
'medium',
|
||||
'high'
|
||||
])
|
||||
})
|
||||
@ -2078,7 +2153,7 @@ describe('getModelSupportedReasoningEffortOptions', () => {
|
||||
|
||||
const geminiModel = createModel({ id: 'gemini-2.5-flash-latest' })
|
||||
const geminiResult = getModelSupportedReasoningEffortOptions(geminiModel)
|
||||
expect(geminiResult).toEqual(MODEL_SUPPORTED_OPTIONS.gemini)
|
||||
expect(geminiResult).toEqual(MODEL_SUPPORTED_OPTIONS.gemini2_flash)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -20,6 +20,8 @@ import {
|
||||
getModelSupportedVerbosity,
|
||||
groupQwenModels,
|
||||
isAnthropicModel,
|
||||
isGemini3FlashModel,
|
||||
isGemini3ProModel,
|
||||
isGeminiModel,
|
||||
isGemmaModel,
|
||||
isGenerateImageModels,
|
||||
@ -432,6 +434,101 @@ describe('model utils', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('isGemini3FlashModel', () => {
|
||||
it('detects gemini-3-flash model', () => {
|
||||
expect(isGemini3FlashModel(createModel({ id: 'gemini-3-flash' }))).toBe(true)
|
||||
})
|
||||
|
||||
it('detects gemini-3-flash-preview model', () => {
|
||||
expect(isGemini3FlashModel(createModel({ id: 'gemini-3-flash-preview' }))).toBe(true)
|
||||
})
|
||||
|
||||
it('detects gemini-3-flash with version suffixes', () => {
|
||||
expect(isGemini3FlashModel(createModel({ id: 'gemini-3-flash-latest' }))).toBe(true)
|
||||
expect(isGemini3FlashModel(createModel({ id: 'gemini-3-flash-preview-09-2025' }))).toBe(true)
|
||||
expect(isGemini3FlashModel(createModel({ id: 'gemini-3-flash-exp-1234' }))).toBe(true)
|
||||
})
|
||||
|
||||
it('detects gemini-flash-latest alias', () => {
|
||||
expect(isGemini3FlashModel(createModel({ id: 'gemini-flash-latest' }))).toBe(true)
|
||||
expect(isGemini3FlashModel(createModel({ id: 'Gemini-Flash-Latest' }))).toBe(true)
|
||||
})
|
||||
|
||||
it('detects gemini-3-flash with uppercase', () => {
|
||||
expect(isGemini3FlashModel(createModel({ id: 'Gemini-3-Flash' }))).toBe(true)
|
||||
expect(isGemini3FlashModel(createModel({ id: 'GEMINI-3-FLASH-PREVIEW' }))).toBe(true)
|
||||
})
|
||||
|
||||
it('excludes gemini-3-flash-image models', () => {
|
||||
expect(isGemini3FlashModel(createModel({ id: 'gemini-3-flash-image-preview' }))).toBe(false)
|
||||
expect(isGemini3FlashModel(createModel({ id: 'gemini-3-flash-image' }))).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false for non-flash gemini-3 models', () => {
|
||||
expect(isGemini3FlashModel(createModel({ id: 'gemini-3-pro' }))).toBe(false)
|
||||
expect(isGemini3FlashModel(createModel({ id: 'gemini-3-pro-preview' }))).toBe(false)
|
||||
expect(isGemini3FlashModel(createModel({ id: 'gemini-3-pro-image-preview' }))).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false for other gemini models', () => {
|
||||
expect(isGemini3FlashModel(createModel({ id: 'gemini-2-flash' }))).toBe(false)
|
||||
expect(isGemini3FlashModel(createModel({ id: 'gemini-2-flash-preview' }))).toBe(false)
|
||||
expect(isGemini3FlashModel(createModel({ id: 'gemini-2.5-flash-preview-09-2025' }))).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false for null/undefined models', () => {
|
||||
expect(isGemini3FlashModel(null)).toBe(false)
|
||||
expect(isGemini3FlashModel(undefined)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('isGemini3ProModel', () => {
|
||||
it('detects gemini-3-pro model', () => {
|
||||
expect(isGemini3ProModel(createModel({ id: 'gemini-3-pro' }))).toBe(true)
|
||||
})
|
||||
|
||||
it('detects gemini-3-pro-preview model', () => {
|
||||
expect(isGemini3ProModel(createModel({ id: 'gemini-3-pro-preview' }))).toBe(true)
|
||||
})
|
||||
|
||||
it('detects gemini-3-pro with version suffixes', () => {
|
||||
expect(isGemini3ProModel(createModel({ id: 'gemini-3-pro-latest' }))).toBe(true)
|
||||
expect(isGemini3ProModel(createModel({ id: 'gemini-3-pro-preview-09-2025' }))).toBe(true)
|
||||
expect(isGemini3ProModel(createModel({ id: 'gemini-3-pro-exp-1234' }))).toBe(true)
|
||||
})
|
||||
|
||||
it('detects gemini-pro-latest alias', () => {
|
||||
expect(isGemini3ProModel(createModel({ id: 'gemini-pro-latest' }))).toBe(true)
|
||||
expect(isGemini3ProModel(createModel({ id: 'Gemini-Pro-Latest' }))).toBe(true)
|
||||
})
|
||||
|
||||
it('detects gemini-3-pro with uppercase', () => {
|
||||
expect(isGemini3ProModel(createModel({ id: 'Gemini-3-Pro' }))).toBe(true)
|
||||
expect(isGemini3ProModel(createModel({ id: 'GEMINI-3-PRO-PREVIEW' }))).toBe(true)
|
||||
})
|
||||
|
||||
it('excludes gemini-3-pro-image models', () => {
|
||||
expect(isGemini3ProModel(createModel({ id: 'gemini-3-pro-image-preview' }))).toBe(false)
|
||||
expect(isGemini3ProModel(createModel({ id: 'gemini-3-pro-image' }))).toBe(false)
|
||||
expect(isGemini3ProModel(createModel({ id: 'gemini-3-pro-image-latest' }))).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false for non-pro gemini-3 models', () => {
|
||||
expect(isGemini3ProModel(createModel({ id: 'gemini-3-flash' }))).toBe(false)
|
||||
expect(isGemini3ProModel(createModel({ id: 'gemini-3-flash-preview' }))).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false for other gemini models', () => {
|
||||
expect(isGemini3ProModel(createModel({ id: 'gemini-2-pro' }))).toBe(false)
|
||||
expect(isGemini3ProModel(createModel({ id: 'gemini-2.5-pro-preview-09-2025' }))).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false for null/undefined models', () => {
|
||||
expect(isGemini3ProModel(null)).toBe(false)
|
||||
expect(isGemini3ProModel(undefined)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('isZhipuModel', () => {
|
||||
it('detects Zhipu models by provider', () => {
|
||||
expect(isZhipuModel(createModel({ provider: 'zhipu' }))).toBe(true)
|
||||
|
||||
@ -20,7 +20,7 @@ import {
|
||||
isOpenAIReasoningModel,
|
||||
isSupportedReasoningEffortOpenAIModel
|
||||
} from './openai'
|
||||
import { GEMINI_FLASH_MODEL_REGEX, isGemini3ThinkingTokenModel } from './utils'
|
||||
import { GEMINI_FLASH_MODEL_REGEX, isGemini3FlashModel, isGemini3ProModel } from './utils'
|
||||
import { isTextToImageModel } from './vision'
|
||||
|
||||
// Reasoning models
|
||||
@ -43,9 +43,10 @@ export const MODEL_SUPPORTED_REASONING_EFFORT = {
|
||||
gpt52pro: ['medium', 'high', 'xhigh'] as const,
|
||||
grok: ['low', 'high'] as const,
|
||||
grok4_fast: ['auto'] as const,
|
||||
gemini: ['low', 'medium', 'high', 'auto'] as const,
|
||||
gemini3: ['low', 'medium', 'high'] as const,
|
||||
gemini_pro: ['low', 'medium', 'high', 'auto'] as const,
|
||||
gemini2_flash: ['low', 'medium', 'high', 'auto'] as const,
|
||||
gemini2_pro: ['low', 'medium', 'high', 'auto'] as const,
|
||||
gemini3_flash: ['minimal', 'low', 'medium', 'high'] as const,
|
||||
gemini3_pro: ['low', 'high'] as const,
|
||||
qwen: ['low', 'medium', 'high'] as const,
|
||||
qwen_thinking: ['low', 'medium', 'high'] as const,
|
||||
doubao: ['auto', 'high'] as const,
|
||||
@ -73,9 +74,10 @@ export const MODEL_SUPPORTED_OPTIONS: ThinkingOptionConfig = {
|
||||
gpt52pro: ['default', ...MODEL_SUPPORTED_REASONING_EFFORT.gpt52pro] as const,
|
||||
grok: ['default', ...MODEL_SUPPORTED_REASONING_EFFORT.grok] as const,
|
||||
grok4_fast: ['default', 'none', ...MODEL_SUPPORTED_REASONING_EFFORT.grok4_fast] as const,
|
||||
gemini: ['default', 'none', ...MODEL_SUPPORTED_REASONING_EFFORT.gemini] as const,
|
||||
gemini_pro: ['default', ...MODEL_SUPPORTED_REASONING_EFFORT.gemini_pro] as const,
|
||||
gemini3: ['default', ...MODEL_SUPPORTED_REASONING_EFFORT.gemini3] as const,
|
||||
gemini2_flash: ['default', 'none', ...MODEL_SUPPORTED_REASONING_EFFORT.gemini2_flash] as const,
|
||||
gemini2_pro: ['default', ...MODEL_SUPPORTED_REASONING_EFFORT.gemini2_pro] as const,
|
||||
gemini3_flash: ['default', ...MODEL_SUPPORTED_REASONING_EFFORT.gemini3_flash] as const,
|
||||
gemini3_pro: ['default', ...MODEL_SUPPORTED_REASONING_EFFORT.gemini3_pro] as const,
|
||||
qwen: ['default', 'none', ...MODEL_SUPPORTED_REASONING_EFFORT.qwen] as const,
|
||||
qwen_thinking: ['default', ...MODEL_SUPPORTED_REASONING_EFFORT.qwen_thinking] as const,
|
||||
doubao: ['default', 'none', ...MODEL_SUPPORTED_REASONING_EFFORT.doubao] as const,
|
||||
@ -102,8 +104,7 @@ const _getThinkModelType = (model: Model): ThinkingModelType => {
|
||||
const modelId = getLowerBaseModelName(model.id)
|
||||
if (isOpenAIDeepResearchModel(model)) {
|
||||
return 'openai_deep_research'
|
||||
}
|
||||
if (isGPT51SeriesModel(model)) {
|
||||
} else if (isGPT51SeriesModel(model)) {
|
||||
if (modelId.includes('codex')) {
|
||||
thinkingModelType = 'gpt5_1_codex'
|
||||
if (isGPT51CodexMaxModel(model)) {
|
||||
@ -131,16 +132,18 @@ const _getThinkModelType = (model: Model): ThinkingModelType => {
|
||||
} else if (isGrok4FastReasoningModel(model)) {
|
||||
thinkingModelType = 'grok4_fast'
|
||||
} else if (isSupportedThinkingTokenGeminiModel(model)) {
|
||||
if (GEMINI_FLASH_MODEL_REGEX.test(model.id)) {
|
||||
thinkingModelType = 'gemini'
|
||||
if (isGemini3FlashModel(model)) {
|
||||
thinkingModelType = 'gemini3_flash'
|
||||
} else if (isGemini3ProModel(model)) {
|
||||
thinkingModelType = 'gemini3_pro'
|
||||
} else if (GEMINI_FLASH_MODEL_REGEX.test(model.id)) {
|
||||
thinkingModelType = 'gemini2_flash'
|
||||
} else {
|
||||
thinkingModelType = 'gemini_pro'
|
||||
thinkingModelType = 'gemini2_pro'
|
||||
}
|
||||
if (isGemini3ThinkingTokenModel(model)) {
|
||||
thinkingModelType = 'gemini3'
|
||||
}
|
||||
} else if (isSupportedReasoningEffortGrokModel(model)) thinkingModelType = 'grok'
|
||||
else if (isSupportedThinkingTokenQwenModel(model)) {
|
||||
} else if (isSupportedReasoningEffortGrokModel(model)) {
|
||||
thinkingModelType = 'grok'
|
||||
} else if (isSupportedThinkingTokenQwenModel(model)) {
|
||||
if (isQwenAlwaysThinkModel(model)) {
|
||||
thinkingModelType = 'qwen_thinking'
|
||||
}
|
||||
@ -153,11 +156,17 @@ const _getThinkModelType = (model: Model): ThinkingModelType => {
|
||||
} else {
|
||||
thinkingModelType = 'doubao_no_auto'
|
||||
}
|
||||
} else if (isSupportedThinkingTokenHunyuanModel(model)) thinkingModelType = 'hunyuan'
|
||||
else if (isSupportedReasoningEffortPerplexityModel(model)) thinkingModelType = 'perplexity'
|
||||
else if (isSupportedThinkingTokenZhipuModel(model)) thinkingModelType = 'zhipu'
|
||||
else if (isDeepSeekHybridInferenceModel(model)) thinkingModelType = 'deepseek_hybrid'
|
||||
else if (isSupportedThinkingTokenMiMoModel(model)) thinkingModelType = 'mimo'
|
||||
} else if (isSupportedThinkingTokenHunyuanModel(model)) {
|
||||
thinkingModelType = 'hunyuan'
|
||||
} else if (isSupportedReasoningEffortPerplexityModel(model)) {
|
||||
thinkingModelType = 'perplexity'
|
||||
} else if (isSupportedThinkingTokenZhipuModel(model)) {
|
||||
thinkingModelType = 'zhipu'
|
||||
} else if (isDeepSeekHybridInferenceModel(model)) {
|
||||
thinkingModelType = 'deepseek_hybrid'
|
||||
} else if (isSupportedThinkingTokenMiMoModel(model)) {
|
||||
thinkingModelType = 'mimo'
|
||||
}
|
||||
return thinkingModelType
|
||||
}
|
||||
|
||||
|
||||
@ -267,3 +267,43 @@ export const isGemini3ThinkingTokenModel = (model: Model) => {
|
||||
const modelId = getLowerBaseModelName(model.id)
|
||||
return isGemini3Model(model) && !modelId.includes('image')
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the model is a Gemini 3 Flash model
|
||||
* Matches: gemini-3-flash, gemini-3-flash-preview, gemini-3-flash-preview-09-2025, gemini-flash-latest (alias)
|
||||
* Excludes: gemini-3-flash-image-preview
|
||||
* @param model - The model to check
|
||||
* @returns true if the model is a Gemini 3 Flash model
|
||||
*/
|
||||
export const isGemini3FlashModel = (model: Model | undefined | null): boolean => {
|
||||
if (!model) {
|
||||
return false
|
||||
}
|
||||
const modelId = getLowerBaseModelName(model.id)
|
||||
// Check for gemini-flash-latest alias (currently points to gemini-3-flash, may change in future)
|
||||
if (modelId === 'gemini-flash-latest') {
|
||||
return true
|
||||
}
|
||||
// Check for gemini-3-flash with optional suffixes, excluding image variants
|
||||
return /gemini-3-flash(?!-image)(?:-[\w-]+)*$/i.test(modelId)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the model is a Gemini 3 Pro model
|
||||
* Matches: gemini-3-pro, gemini-3-pro-preview, gemini-3-pro-preview-09-2025, gemini-pro-latest (alias)
|
||||
* Excludes: gemini-3-pro-image-preview
|
||||
* @param model - The model to check
|
||||
* @returns true if the model is a Gemini 3 Pro model
|
||||
*/
|
||||
export const isGemini3ProModel = (model: Model | undefined | null): boolean => {
|
||||
if (!model) {
|
||||
return false
|
||||
}
|
||||
const modelId = getLowerBaseModelName(model.id)
|
||||
// Check for gemini-pro-latest alias (currently points to gemini-3-pro, may change in future)
|
||||
if (modelId === 'gemini-pro-latest') {
|
||||
return true
|
||||
}
|
||||
// Check for gemini-3-pro with optional suffixes, excluding image variants
|
||||
return /gemini-3-pro(?!-image)(?:-[\w-]+)*$/i.test(modelId)
|
||||
}
|
||||
|
||||
@ -560,7 +560,7 @@
|
||||
"medium": "斟酌",
|
||||
"medium_description": "中强度推理",
|
||||
"minimal": "微念",
|
||||
"minimal_description": "最小程度的思考",
|
||||
"minimal_description": "最小程度的推理",
|
||||
"off": "关闭",
|
||||
"off_description": "禁用推理",
|
||||
"xhigh": "穷究",
|
||||
|
||||
@ -36,7 +36,7 @@ const MessageAttachments: FC<Props> = ({ block }) => {
|
||||
fileList={[
|
||||
{
|
||||
uid: block.file.id,
|
||||
url: 'file://' + FileManager.getSafePath(block.file),
|
||||
url: 'file://' + FileManager.getFilePath(block.file),
|
||||
status: 'done' as const,
|
||||
name: FileManager.formatFileName(block.file),
|
||||
type: block.file.type,
|
||||
|
||||
@ -74,7 +74,9 @@ export function getDefaultTranslateAssistant(
|
||||
throw new Error('Unknown target language')
|
||||
}
|
||||
|
||||
const reasoningEffort = getModelSupportedReasoningEffortOptions(model)?.[0]
|
||||
const supportedOptions = getModelSupportedReasoningEffortOptions(model)
|
||||
// disable reasoning if it could be disabled, otherwise no configuration
|
||||
const reasoningEffort = supportedOptions?.includes('none') ? 'none' : 'default'
|
||||
const settings = {
|
||||
temperature: 0.7,
|
||||
reasoning_effort: reasoningEffort,
|
||||
|
||||
@ -94,9 +94,10 @@ const ThinkModelTypes = [
|
||||
'gpt52pro',
|
||||
'grok',
|
||||
'grok4_fast',
|
||||
'gemini',
|
||||
'gemini_pro',
|
||||
'gemini3',
|
||||
'gemini2_flash',
|
||||
'gemini2_pro',
|
||||
'gemini3_flash',
|
||||
'gemini3_pro',
|
||||
'qwen',
|
||||
'qwen_thinking',
|
||||
'doubao',
|
||||
|
||||
@ -3,7 +3,8 @@ import '@renderer/databases'
|
||||
import { ErrorBoundary } from '@renderer/components/ErrorBoundary'
|
||||
import { getToastUtilities } from '@renderer/components/TopView/toast'
|
||||
import { useSettings } from '@renderer/hooks/useSettings'
|
||||
import store, { persistor } from '@renderer/store'
|
||||
import store, { persistor, useAppDispatch } from '@renderer/store'
|
||||
import { setFilesPath } from '@renderer/store/runtime'
|
||||
import { useEffect } from 'react'
|
||||
import { Provider } from 'react-redux'
|
||||
import { PersistGate } from 'redux-persist/integration/react'
|
||||
@ -16,6 +17,14 @@ import HomeWindow from './home/HomeWindow'
|
||||
// Inner component that uses the hook after Redux is initialized
|
||||
function MiniWindowContent(): React.ReactElement {
|
||||
const { customCss } = useSettings()
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
// Initialize filesPath for mini window (same as useAppInit in main window)
|
||||
useEffect(() => {
|
||||
window.api.getAppInfo().then((info) => {
|
||||
dispatch(setFilesPath(info.filesPath))
|
||||
})
|
||||
}, [dispatch])
|
||||
|
||||
useEffect(() => {
|
||||
let customCssElement = document.getElementById('user-defined-custom-css') as HTMLStyleElement
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { loggerService } from '@logger'
|
||||
import { isMac } from '@renderer/config/constant'
|
||||
import { isGenerateImageModel, isVisionModel } from '@renderer/config/models'
|
||||
import { useTheme } from '@renderer/context/ThemeProvider'
|
||||
import { useAssistant } from '@renderer/hooks/useAssistant'
|
||||
import { useSettings } from '@renderer/hooks/useSettings'
|
||||
@ -7,12 +8,14 @@ import i18n from '@renderer/i18n'
|
||||
import { fetchChatCompletion } from '@renderer/services/ApiService'
|
||||
import { getDefaultTopic } from '@renderer/services/AssistantService'
|
||||
import { ConversationService } from '@renderer/services/ConversationService'
|
||||
import FileManager from '@renderer/services/FileManager'
|
||||
import { getAssistantMessage, getUserMessage } from '@renderer/services/MessagesService'
|
||||
import PasteService from '@renderer/services/PasteService'
|
||||
import store, { useAppSelector } from '@renderer/store'
|
||||
import { updateOneBlock, upsertManyBlocks, upsertOneBlock } from '@renderer/store/messageBlock'
|
||||
import { newMessagesActions, selectMessagesForTopic } from '@renderer/store/newMessage'
|
||||
import { cancelThrottledBlockUpdate, throttledBlockUpdate } from '@renderer/store/thunk/messageThunk'
|
||||
import type { Topic } from '@renderer/types'
|
||||
import type { FileMetadata, Topic } from '@renderer/types'
|
||||
import { ThemeMode } from '@renderer/types'
|
||||
import type { Chunk } from '@renderer/types/chunk'
|
||||
import { ChunkType } from '@renderer/types/chunk'
|
||||
@ -39,6 +42,7 @@ import type { FeatureMenusRef } from './components/FeatureMenus'
|
||||
import FeatureMenus from './components/FeatureMenus'
|
||||
import Footer from './components/Footer'
|
||||
import InputBar from './components/InputBar'
|
||||
import PastedFilesPreview from './components/PastedFilesPreview'
|
||||
|
||||
const logger = loggerService.withContext('HomeWindow')
|
||||
|
||||
@ -51,6 +55,7 @@ const HomeWindow: FC<{ draggable?: boolean }> = ({ draggable = true }) => {
|
||||
const [isFirstMessage, setIsFirstMessage] = useState(true)
|
||||
|
||||
const [userInputText, setUserInputText] = useState('')
|
||||
const [files, setFiles] = useState<FileMetadata[]>([])
|
||||
|
||||
const [clipboardText, setClipboardText] = useState('')
|
||||
const lastClipboardTextRef = useRef<string | null>(null)
|
||||
@ -73,6 +78,19 @@ const HomeWindow: FC<{ draggable?: boolean }> = ({ draggable = true }) => {
|
||||
const inputBarRef = useRef<HTMLDivElement>(null)
|
||||
const featureMenusRef = useRef<FeatureMenusRef>(null)
|
||||
|
||||
// 检查当前助手的模型是否支持图片(复用主窗口逻辑)
|
||||
const isVisionSupported = useMemo(() => isVisionModel(currentAssistant.model), [currentAssistant.model])
|
||||
const isGenerateImageSupported = useMemo(() => isGenerateImageModel(currentAssistant.model), [currentAssistant.model])
|
||||
const canAddImageFile = useMemo(
|
||||
() => isVisionSupported || isGenerateImageSupported,
|
||||
[isVisionSupported, isGenerateImageSupported]
|
||||
)
|
||||
|
||||
const supportedImageExts = useMemo(
|
||||
() => (canAddImageFile ? ['.png', '.jpg', '.jpeg', '.gif', '.bmp', '.webp'] : []),
|
||||
[canAddImageFile]
|
||||
)
|
||||
|
||||
const referenceText = useMemo(() => clipboardText || userInputText, [clipboardText, userInputText])
|
||||
|
||||
const userContent = useMemo(() => {
|
||||
@ -82,6 +100,8 @@ const HomeWindow: FC<{ draggable?: boolean }> = ({ draggable = true }) => {
|
||||
return userInputText.trim()
|
||||
}, [isFirstMessage, referenceText, userInputText])
|
||||
|
||||
const hasChatInput = useMemo(() => Boolean(userContent) || files.length > 0, [files.length, userContent])
|
||||
|
||||
useEffect(() => {
|
||||
i18n.changeLanguage(language || navigator.language || defaultLanguage)
|
||||
}, [language])
|
||||
@ -166,7 +186,7 @@ const HomeWindow: FC<{ draggable?: boolean }> = ({ draggable = true }) => {
|
||||
if (isLoading) return
|
||||
|
||||
e.preventDefault()
|
||||
if (userContent) {
|
||||
if (userContent || files.length > 0) {
|
||||
if (route === 'home') {
|
||||
featureMenusRef.current?.useFeature()
|
||||
} else {
|
||||
@ -213,6 +233,25 @@ const HomeWindow: FC<{ draggable?: boolean }> = ({ draggable = true }) => {
|
||||
setUserInputText(e.target.value)
|
||||
}
|
||||
|
||||
const handlePaste = useCallback(
|
||||
async (event: React.ClipboardEvent<HTMLInputElement>) => {
|
||||
// 复用 PasteService,根据 supportedImageExts 自动过滤不支持的文件类型
|
||||
// 当模型不支持图片时,supportedImageExts 为空数组,PasteService 会显示提示
|
||||
await PasteService.handlePaste(
|
||||
event.nativeEvent,
|
||||
supportedImageExts,
|
||||
setFiles,
|
||||
setUserInputText,
|
||||
false,
|
||||
undefined,
|
||||
userInputText,
|
||||
undefined,
|
||||
t
|
||||
)
|
||||
},
|
||||
[supportedImageExts, t, userInputText]
|
||||
)
|
||||
|
||||
const handleError = (error: Error) => {
|
||||
setIsLoading(false)
|
||||
setError(error.message)
|
||||
@ -220,17 +259,22 @@ const HomeWindow: FC<{ draggable?: boolean }> = ({ draggable = true }) => {
|
||||
|
||||
const handleSendMessage = useCallback(
|
||||
async (prompt?: string) => {
|
||||
if (isEmpty(userContent) || !currentTopic.current) {
|
||||
if ((isEmpty(userContent) && files.length === 0) || !currentTopic.current) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const topicId = currentTopic.current.id
|
||||
|
||||
const uploadedFiles = files.length ? await FileManager.uploadFiles(files) : []
|
||||
|
||||
const content = [prompt, userContent].filter(Boolean).join('\n\n') || undefined
|
||||
|
||||
const { message: userMessage, blocks } = getUserMessage({
|
||||
content: [prompt, userContent].filter(Boolean).join('\n\n'),
|
||||
content,
|
||||
assistant: currentAssistant,
|
||||
topic: currentTopic.current
|
||||
topic: currentTopic.current,
|
||||
files: uploadedFiles
|
||||
})
|
||||
|
||||
store.dispatch(newMessagesActions.addMessage({ topicId, message: userMessage }))
|
||||
@ -272,6 +316,7 @@ const HomeWindow: FC<{ draggable?: boolean }> = ({ draggable = true }) => {
|
||||
|
||||
setIsFirstMessage(false)
|
||||
setUserInputText('')
|
||||
setFiles([])
|
||||
|
||||
const newAssistant = cloneDeep(currentAssistant)
|
||||
if (!newAssistant.settings) {
|
||||
@ -452,9 +497,13 @@ const HomeWindow: FC<{ draggable?: boolean }> = ({ draggable = true }) => {
|
||||
currentAskId.current = ''
|
||||
}
|
||||
},
|
||||
[userContent, currentAssistant]
|
||||
[files, userContent, currentAssistant]
|
||||
)
|
||||
|
||||
const handleRemoveFile = useCallback((filePath: string) => {
|
||||
setFiles((prevFiles) => prevFiles.filter((file) => file.path !== filePath))
|
||||
}, [])
|
||||
|
||||
const handlePause = useCallback(() => {
|
||||
if (currentAskId.current) {
|
||||
abortCompletion(currentAskId.current)
|
||||
@ -546,8 +595,10 @@ const HomeWindow: FC<{ draggable?: boolean }> = ({ draggable = true }) => {
|
||||
loading={isLoading}
|
||||
handleKeyDown={handleKeyDown}
|
||||
handleChange={handleChange}
|
||||
handlePaste={handlePaste}
|
||||
ref={inputBarRef}
|
||||
/>
|
||||
<PastedFilesPreview files={files} onRemove={handleRemoveFile} />
|
||||
<Divider style={{ margin: '10px 0' }} />
|
||||
</>
|
||||
)}
|
||||
@ -590,8 +641,10 @@ const HomeWindow: FC<{ draggable?: boolean }> = ({ draggable = true }) => {
|
||||
loading={isLoading}
|
||||
handleKeyDown={handleKeyDown}
|
||||
handleChange={handleChange}
|
||||
handlePaste={handlePaste}
|
||||
ref={inputBarRef}
|
||||
/>
|
||||
<PastedFilesPreview files={files} onRemove={handleRemoveFile} />
|
||||
<Divider style={{ margin: '10px 0' }} />
|
||||
<ClipboardPreview referenceText={referenceText} clearClipboard={clearClipboard} t={t} />
|
||||
<Main>
|
||||
@ -599,6 +652,7 @@ const HomeWindow: FC<{ draggable?: boolean }> = ({ draggable = true }) => {
|
||||
setRoute={setRoute}
|
||||
onSendMessage={handleSendMessage}
|
||||
text={userContent}
|
||||
hasChatInput={hasChatInput}
|
||||
ref={featureMenusRef}
|
||||
/>
|
||||
</Main>
|
||||
|
||||
@ -11,6 +11,7 @@ interface FeatureMenusProps {
|
||||
text: string
|
||||
setRoute: Dispatch<SetStateAction<'translate' | 'summary' | 'chat' | 'explanation' | 'home'>>
|
||||
onSendMessage: (prompt?: string) => void
|
||||
hasChatInput: boolean
|
||||
}
|
||||
|
||||
export interface FeatureMenusRef {
|
||||
@ -23,6 +24,7 @@ export interface FeatureMenusRef {
|
||||
const FeatureMenus = ({
|
||||
ref,
|
||||
text,
|
||||
hasChatInput,
|
||||
setRoute,
|
||||
onSendMessage
|
||||
}: FeatureMenusProps & { ref?: React.RefObject<FeatureMenusRef | null> }) => {
|
||||
@ -36,7 +38,7 @@ const FeatureMenus = ({
|
||||
title: t('miniwindow.feature.chat'),
|
||||
active: true,
|
||||
onClick: () => {
|
||||
if (text) {
|
||||
if (hasChatInput) {
|
||||
setRoute('chat')
|
||||
onSendMessage()
|
||||
}
|
||||
@ -68,7 +70,7 @@ const FeatureMenus = ({
|
||||
}
|
||||
}
|
||||
],
|
||||
[onSendMessage, setRoute, t, text]
|
||||
[hasChatInput, onSendMessage, setRoute, t, text]
|
||||
)
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
|
||||
@ -14,6 +14,7 @@ interface InputBarProps {
|
||||
loading: boolean
|
||||
handleKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => void
|
||||
handleChange: (e: React.ChangeEvent<HTMLInputElement>) => void
|
||||
handlePaste: (e: React.ClipboardEvent<HTMLInputElement>) => void
|
||||
}
|
||||
|
||||
const InputBar = ({
|
||||
@ -23,7 +24,8 @@ const InputBar = ({
|
||||
placeholder,
|
||||
loading,
|
||||
handleKeyDown,
|
||||
handleChange
|
||||
handleChange,
|
||||
handlePaste
|
||||
}: InputBarProps & { ref?: React.RefObject<HTMLDivElement | null> }) => {
|
||||
const inputRef = useRef<InputRef>(null)
|
||||
const { setTimeoutTimer } = useTimer()
|
||||
@ -40,6 +42,7 @@ const InputBar = ({
|
||||
autoFocus
|
||||
onKeyDown={handleKeyDown}
|
||||
onChange={handleChange}
|
||||
onPaste={handlePaste}
|
||||
ref={inputRef}
|
||||
/>
|
||||
</InputWrapper>
|
||||
|
||||
@ -0,0 +1,82 @@
|
||||
import { CloseOutlined, FileImageOutlined, FileOutlined } from '@ant-design/icons'
|
||||
import type { FileMetadata } from '@renderer/types'
|
||||
import { FileTypes } from '@renderer/types'
|
||||
import { Tooltip } from 'antd'
|
||||
import type { FC } from 'react'
|
||||
import styled from 'styled-components'
|
||||
|
||||
interface PastedFilesPreviewProps {
|
||||
files: FileMetadata[]
|
||||
onRemove: (filePath: string) => void
|
||||
}
|
||||
|
||||
const PastedFilesPreview: FC<PastedFilesPreviewProps> = ({ files, onRemove }) => {
|
||||
if (!files.length) return null
|
||||
|
||||
return (
|
||||
<Container>
|
||||
{files.map((file) => (
|
||||
<FileChip key={file.path} className="nodrag">
|
||||
<IconWrapper>{file.type === FileTypes.IMAGE ? <FileImageOutlined /> : <FileOutlined />}</IconWrapper>
|
||||
<Tooltip title={file.name} placement="topLeft">
|
||||
<FileName>{file.name}</FileName>
|
||||
</Tooltip>
|
||||
<RemoveButton onClick={() => onRemove(file.path)}>
|
||||
<CloseOutlined />
|
||||
</RemoveButton>
|
||||
</FileChip>
|
||||
))}
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
|
||||
const Container = styled.div`
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin: 8px 0 2px;
|
||||
`
|
||||
|
||||
const FileChip = styled.div`
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 6px 10px;
|
||||
border-radius: 8px;
|
||||
background: var(--color-background-opacity);
|
||||
border: 1px solid var(--color-border);
|
||||
color: var(--color-text);
|
||||
max-width: 100%;
|
||||
`
|
||||
|
||||
const IconWrapper = styled.span`
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--color-text-secondary);
|
||||
`
|
||||
|
||||
const FileName = styled.span`
|
||||
font-size: 12px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 180px;
|
||||
`
|
||||
|
||||
const RemoveButton = styled.button`
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--color-text-secondary);
|
||||
cursor: pointer;
|
||||
padding: 2px;
|
||||
|
||||
&:hover {
|
||||
color: var(--color-text);
|
||||
}
|
||||
`
|
||||
|
||||
export default PastedFilesPreview
|
||||
@ -1,8 +1,15 @@
|
||||
import '@testing-library/jest-dom/vitest'
|
||||
|
||||
import { createRequire } from 'node:module'
|
||||
import { styleSheetSerializer } from 'jest-styled-components/serializer'
|
||||
import { expect, vi } from 'vitest'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const bufferModule = require('buffer')
|
||||
if (!bufferModule.SlowBuffer) {
|
||||
bufferModule.SlowBuffer = bufferModule.Buffer
|
||||
}
|
||||
|
||||
expect.addSnapshotSerializer(styleSheetSerializer)
|
||||
|
||||
// Mock LoggerService globally for renderer tests
|
||||
@ -48,3 +55,29 @@ vi.stubGlobal('api', {
|
||||
writeWithId: vi.fn().mockResolvedValue(undefined)
|
||||
}
|
||||
})
|
||||
|
||||
if (typeof globalThis.localStorage === 'undefined' || typeof (globalThis.localStorage as any).getItem !== 'function') {
|
||||
let store = new Map<string, string>()
|
||||
|
||||
const localStorageMock = {
|
||||
getItem: (key: string) => store.get(key) ?? null,
|
||||
setItem: (key: string, value: string) => {
|
||||
store.set(key, String(value))
|
||||
},
|
||||
removeItem: (key: string) => {
|
||||
store.delete(key)
|
||||
},
|
||||
clear: () => {
|
||||
store.clear()
|
||||
},
|
||||
key: (index: number) => Array.from(store.keys())[index] ?? null,
|
||||
get length() {
|
||||
return store.size
|
||||
}
|
||||
}
|
||||
|
||||
vi.stubGlobal('localStorage', localStorageMock)
|
||||
if (typeof window !== 'undefined') {
|
||||
Object.defineProperty(window, 'localStorage', { value: localStorageMock })
|
||||
}
|
||||
}
|
||||
|
||||
111
yarn.lock
111
yarn.lock
@ -102,6 +102,18 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@ai-sdk/anthropic@npm:2.0.56":
|
||||
version: 2.0.56
|
||||
resolution: "@ai-sdk/anthropic@npm:2.0.56"
|
||||
dependencies:
|
||||
"@ai-sdk/provider": "npm:2.0.0"
|
||||
"@ai-sdk/provider-utils": "npm:3.0.19"
|
||||
peerDependencies:
|
||||
zod: ^3.25.76 || ^4.1.8
|
||||
checksum: 10c0/f2b6029c92443f831a2d124420e805d057668003067b1f677a4292d02f27aa3ad533374ea996d77ede7746a42c46fb94a8f2d8c0e7758a4555ea18c8b532052c
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@ai-sdk/azure@npm:^2.0.87":
|
||||
version: 2.0.87
|
||||
resolution: "@ai-sdk/azure@npm:2.0.87"
|
||||
@ -166,42 +178,42 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@ai-sdk/google-vertex@npm:^3.0.79":
|
||||
version: 3.0.79
|
||||
resolution: "@ai-sdk/google-vertex@npm:3.0.79"
|
||||
"@ai-sdk/google-vertex@npm:^3.0.94":
|
||||
version: 3.0.94
|
||||
resolution: "@ai-sdk/google-vertex@npm:3.0.94"
|
||||
dependencies:
|
||||
"@ai-sdk/anthropic": "npm:2.0.49"
|
||||
"@ai-sdk/google": "npm:2.0.43"
|
||||
"@ai-sdk/anthropic": "npm:2.0.56"
|
||||
"@ai-sdk/google": "npm:2.0.49"
|
||||
"@ai-sdk/provider": "npm:2.0.0"
|
||||
"@ai-sdk/provider-utils": "npm:3.0.17"
|
||||
google-auth-library: "npm:^9.15.0"
|
||||
"@ai-sdk/provider-utils": "npm:3.0.19"
|
||||
google-auth-library: "npm:^10.5.0"
|
||||
peerDependencies:
|
||||
zod: ^3.25.76 || ^4.1.8
|
||||
checksum: 10c0/a86949b8d4a855409acdf7dc8d93ad9ea8ccf2bc3849acbe1ecbe4d6d66f06bcb5242f0df8eea24214e78732618b71ec8a019cbbeab16366f9ad3c860c5d8d30
|
||||
checksum: 10c0/68e2ee9e6525a5e43f90304980e64bf2a4227fd3ce74a7bf17e5ace094ea1bca8f8f18a8cc332a492fee4b912568a768f7479a4eed8148b84e7de1adf4104ad0
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@ai-sdk/google@npm:2.0.43":
|
||||
version: 2.0.43
|
||||
resolution: "@ai-sdk/google@npm:2.0.43"
|
||||
"@ai-sdk/google@npm:2.0.49":
|
||||
version: 2.0.49
|
||||
resolution: "@ai-sdk/google@npm:2.0.49"
|
||||
dependencies:
|
||||
"@ai-sdk/provider": "npm:2.0.0"
|
||||
"@ai-sdk/provider-utils": "npm:3.0.17"
|
||||
"@ai-sdk/provider-utils": "npm:3.0.19"
|
||||
peerDependencies:
|
||||
zod: ^3.25.76 || ^4.1.8
|
||||
checksum: 10c0/5a421a9746cf8cbdf3bb7fb49426453a4fe0e354ea55a0123e628afb7acf9bb19959d512c0f8e6d7dbefbfa7e1cef4502fc146149007258a8eeb57743ac5e9e5
|
||||
checksum: 10c0/f3f8acfcd956edc7d807d22963d5eff0f765418f1f2c7d18615955ccdfcebb4d43cc26ce1f712c6a53572f1d8becc0773311b77b1f1bf1af87d675c5f017d5a4
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@ai-sdk/google@patch:@ai-sdk/google@npm%3A2.0.43#~/.yarn/patches/@ai-sdk-google-npm-2.0.43-689ed559b3.patch":
|
||||
version: 2.0.43
|
||||
resolution: "@ai-sdk/google@patch:@ai-sdk/google@npm%3A2.0.43#~/.yarn/patches/@ai-sdk-google-npm-2.0.43-689ed559b3.patch::version=2.0.43&hash=4dde1e"
|
||||
"@ai-sdk/google@patch:@ai-sdk/google@npm%3A2.0.49#~/.yarn/patches/@ai-sdk-google-npm-2.0.49-84720f41bd.patch":
|
||||
version: 2.0.49
|
||||
resolution: "@ai-sdk/google@patch:@ai-sdk/google@npm%3A2.0.49#~/.yarn/patches/@ai-sdk-google-npm-2.0.49-84720f41bd.patch::version=2.0.49&hash=406c25"
|
||||
dependencies:
|
||||
"@ai-sdk/provider": "npm:2.0.0"
|
||||
"@ai-sdk/provider-utils": "npm:3.0.17"
|
||||
"@ai-sdk/provider-utils": "npm:3.0.19"
|
||||
peerDependencies:
|
||||
zod: ^3.25.76 || ^4.1.8
|
||||
checksum: 10c0/4cfd17e9c47f2b742d8a0b1ca3532b4dc48753088363b74b01a042f63652174fa9a3fbf655a23f823974c673121dffbd2d192bb0c1bf158da4e2bf498fc76527
|
||||
checksum: 10c0/8d4d881583c2301dce8a4e3066af2ba7d99b30520b6219811f90271c93bf8a07dc23e752fa25ffd0e72c6ec56e97d40d32e04072a362accf7d01a745a2d2a352
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -10051,8 +10063,8 @@ __metadata:
|
||||
"@ai-sdk/anthropic": "npm:^2.0.49"
|
||||
"@ai-sdk/cerebras": "npm:^1.0.31"
|
||||
"@ai-sdk/gateway": "npm:^2.0.15"
|
||||
"@ai-sdk/google": "patch:@ai-sdk/google@npm%3A2.0.43#~/.yarn/patches/@ai-sdk-google-npm-2.0.43-689ed559b3.patch"
|
||||
"@ai-sdk/google-vertex": "npm:^3.0.79"
|
||||
"@ai-sdk/google": "patch:@ai-sdk/google@npm%3A2.0.49#~/.yarn/patches/@ai-sdk-google-npm-2.0.49-84720f41bd.patch"
|
||||
"@ai-sdk/google-vertex": "npm:^3.0.94"
|
||||
"@ai-sdk/huggingface": "npm:^0.0.10"
|
||||
"@ai-sdk/mistral": "npm:^2.0.24"
|
||||
"@ai-sdk/openai": "patch:@ai-sdk/openai@npm%3A2.0.85#~/.yarn/patches/@ai-sdk-openai-npm-2.0.85-27483d1d6a.patch"
|
||||
@ -15499,6 +15511,18 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"gaxios@npm:^7.0.0":
|
||||
version: 7.1.3
|
||||
resolution: "gaxios@npm:7.1.3"
|
||||
dependencies:
|
||||
extend: "npm:^3.0.2"
|
||||
https-proxy-agent: "npm:^7.0.1"
|
||||
node-fetch: "npm:^3.3.2"
|
||||
rimraf: "npm:^5.0.1"
|
||||
checksum: 10c0/a4a1cdf9a392c0c22e9734a40dca5a77a2903f505b939a50f1e68e312458b1289b7993d2f72d011426e89657cae77a3aa9fc62fb140e8ba90a1faa31fdbde4d2
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"gcp-metadata@npm:^6.1.0":
|
||||
version: 6.1.1
|
||||
resolution: "gcp-metadata@npm:6.1.1"
|
||||
@ -15510,6 +15534,17 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"gcp-metadata@npm:^8.0.0":
|
||||
version: 8.1.2
|
||||
resolution: "gcp-metadata@npm:8.1.2"
|
||||
dependencies:
|
||||
gaxios: "npm:^7.0.0"
|
||||
google-logging-utils: "npm:^1.0.0"
|
||||
json-bigint: "npm:^1.0.0"
|
||||
checksum: 10c0/15a61231a9410dc11c2828d2c9fdc8b0a939f1af746195c44edc6f2ffea0acab52cef3a7b9828069a36fd5d68bda730f7328a415fe42a01258f6e249dfba6908
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"gensync@npm:^1.0.0-beta.2":
|
||||
version: 1.0.0-beta.2
|
||||
resolution: "gensync@npm:1.0.0-beta.2"
|
||||
@ -15733,7 +15768,22 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"google-auth-library@npm:^9.14.2, google-auth-library@npm:^9.15.0, google-auth-library@npm:^9.15.1, google-auth-library@npm:^9.4.2":
|
||||
"google-auth-library@npm:^10.5.0":
|
||||
version: 10.5.0
|
||||
resolution: "google-auth-library@npm:10.5.0"
|
||||
dependencies:
|
||||
base64-js: "npm:^1.3.0"
|
||||
ecdsa-sig-formatter: "npm:^1.0.11"
|
||||
gaxios: "npm:^7.0.0"
|
||||
gcp-metadata: "npm:^8.0.0"
|
||||
google-logging-utils: "npm:^1.0.0"
|
||||
gtoken: "npm:^8.0.0"
|
||||
jws: "npm:^4.0.0"
|
||||
checksum: 10c0/49d3931d20b1f4a4d075216bf5518e2b3396dcf441a8f1952611cf3b6080afb1261c3d32009609047ee4a1cc545269a74b4957e6bba9cce840581df309c4b145
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"google-auth-library@npm:^9.14.2, google-auth-library@npm:^9.15.1, google-auth-library@npm:^9.4.2":
|
||||
version: 9.15.1
|
||||
resolution: "google-auth-library@npm:9.15.1"
|
||||
dependencies:
|
||||
@ -15754,6 +15804,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"google-logging-utils@npm:^1.0.0":
|
||||
version: 1.1.3
|
||||
resolution: "google-logging-utils@npm:1.1.3"
|
||||
checksum: 10c0/e65201c7e96543bd1423b9324013736646b9eed60941e0bfa47b9bfd146d2f09cf3df1c99ca60b7d80a726075263ead049ee72de53372cb8458c3bc55c2c1e59
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"gopd@npm:^1.0.1, gopd@npm:^1.2.0":
|
||||
version: 1.2.0
|
||||
resolution: "gopd@npm:1.2.0"
|
||||
@ -15842,6 +15899,16 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"gtoken@npm:^8.0.0":
|
||||
version: 8.0.0
|
||||
resolution: "gtoken@npm:8.0.0"
|
||||
dependencies:
|
||||
gaxios: "npm:^7.0.0"
|
||||
jws: "npm:^4.0.0"
|
||||
checksum: 10c0/058538e5bbe081d30ada5f1fd34d3a8194357c2e6ecbf7c8a98daeefbf13f7e06c15649c7dace6a1d4cc3bc6dc5483bd484d6d7adc5852021896d7c05c439f37
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"hachure-fill@npm:^0.5.2":
|
||||
version: 0.5.2
|
||||
resolution: "hachure-fill@npm:0.5.2"
|
||||
@ -22778,7 +22845,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"rimraf@npm:^5.0.10":
|
||||
"rimraf@npm:^5.0.1, rimraf@npm:^5.0.10":
|
||||
version: 5.0.10
|
||||
resolution: "rimraf@npm:5.0.10"
|
||||
dependencies:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user